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
11c1c0b65c6949532970769144a92a59
Idempotent functions
Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1,<=2,<=...,<=*n*} is such function , that for any the formula *g*(*g*(*x*))<==<=*g*(*x*) holds. Let's denote as *f*(*k*)(*x*) the function *f* applied *k* times to the value *x*. More formally, *f*(1)(*x*)<==<=*f*(*x*), *f*(*k*)(*x*)<==<=*f*(*f*(*k*<=-<=1)(*x*)) for each *k*<=&gt;<=1. You are given some function . Your task is to find minimum positive integer *k* such that function *f*(*k*)(*x*) is idempotent. In the first line of the input there is a single integer *n* (1<=≤<=*n*<=≤<=200) — the size of function *f* domain. In the second line follow *f*(1),<=*f*(2),<=...,<=*f*(*n*) (1<=≤<=*f*(*i*)<=≤<=*n* for each 1<=≤<=*i*<=≤<=*n*), the values of a function. Output minimum *k* such that function *f*(*k*)(*x*) is idempotent. Sample Input 4 1 2 2 4 3 2 3 3 3 2 3 1 Sample Output 1 2 3
[ "N =int(input())\r\ninp =input().split()\r\nF =[0 for i in range(N)]\r\nfor i in range(N): F[i] =int(inp[i])-1\r\n\r\nans_small =[0 for i in range(N+1)]\r\nfor i in range(N):\r\n\tx =i\r\n\ty =i\r\n\tfor j in range(N):\r\n\t\tx =F[x]\r\n\t\ty =F[F[y]]\r\n\t\tif x == y:\r\n\t\t\tans_small[j+1] +=1\r\n\r\nans =-1\r\nfor i in range(1,N+1):\r\n\tif ans == -1:\r\n\t\tif ans_small[i] == N:\r\n\t\t\tans =i\r\n\r\n#dlhe\r\npw =[0 for i in range(500)]\r\nfor i in range(N):\r\n\tvis =[False for j in range(N)]\r\n\tvis[i] =True\r\n\tx =F[i]\r\n\twhile vis[x] == False:\r\n\t\tvis[x] =True\r\n\t\tx =F[x]\r\n\tvis2 =[False for j in range(N)]\r\n\tvis2[x] =True\r\n\tx =F[x]\r\n\twhile vis2[x] == False:\r\n\t\tvis2[x] =True\r\n\t\tx =F[x]\r\n\tc =0\r\n\tfor j in range(N):\r\n\t\tif vis2[j]: c +=1\r\n\tj =2\r\n\twhile j <= c:\r\n\t\tp =0\r\n\t\twhile c%j == 0:\r\n\t\t\tc //=j\r\n\t\t\tp +=1\r\n\t\tpw[j] =max(pw[j],p)\r\n\t\tj +=1\r\n\r\nif ans == -1:\r\n\tans =1\r\n\tfor i in range(1,500):\r\n\t\tfor j in range(pw[i]):\r\n\t\t\tans *=i\r\n\tans0 =ans\r\n\twhile ans <= N:\r\n\t\tans +=ans0\r\n\r\nprint(ans)", "def gcd(a,b):\r\n\tif b==0:\r\n\t\treturn a\r\n\treturn gcd(b,a%b)\r\ndef lcm(a,b):\r\n\tif a==0:\r\n\t\treturn b\r\n\tif b==0:\r\n\t\treturn a\r\n\treturn a*b//gcd(a,b)\r\nn=int(input())\r\nf=list(map(int,input().split()))\r\nfor i in range(n):\r\n\tf[i]-=1\r\nincyc=[0]*n\r\nfor v in range(n):\r\n\tu=v\r\n\tpok=0\r\n\tfor _ in range(n):\r\n\t\tu=f[u]\r\n\t\tif u==v:\r\n\t\t\tpok=1\r\n\t\t\tbreak \r\n\tif pok:\r\n\t\tincyc[v]=1\r\nqs=[0]*n\r\nfor v in range(n):\r\n\tif incyc[v]:\r\n\t\tcontinue\r\n\tu=v\r\n\tnow=0\r\n\tfor _ in range(n):\r\n\t\tu=f[u]\r\n\t\tnow+=1\r\n\t\tif incyc[u]:\r\n\t\t\tqs[v]=now\r\n\t\t\tbreak\r\nl=0\r\nma=0\r\nfor v in range(n):\r\n\tif incyc[v]:\r\n\t\tu=v\r\n\t\tnow=0\r\n\t\tfor _ in range(n):\r\n\t\t\tu=f[u]\r\n\t\t\tnow+=1\r\n\t\t\tif u==v:\r\n\t\t\t\tl=lcm(l,now)\r\n\t\t\t\tbreak\r\n\telse:\r\n\t\t# print(v,qs[v])\r\n\t\tma=max(ma,qs[v])\r\nx=(ma//l)*l\r\nwhile x<ma or x==0:\r\n\tx+=l\r\nprint(x)", "n=int(input())\na=list(map(int, input().split()))\n\nfor i in range(len(a)):\n a[i] = a[i]-1\n\ninstack=[False]*n\nprocessed=[False]*n\nloopl = []\ninloop = [False]*n\ndef dfs1(v):\n if (instack[v]):\n cl = 1\n t = a[v]\n inloop[v] = True\n while t != v:\n inloop[t] = True\n cl = cl+1\n t = a[t]\n loopl.append(cl)\n return\n if processed[v]:\n return\n\n processed[v] = True\n instack[v] = True\n dfs1(a[v])\n instack[v] = False\nfor i in range(n):\n dfs1(i)\nmaxdis = 0\nfor i in range(n):\n t = i\n cl = 0\n while not inloop[t]:\n cl += 1\n t = a[t]\n maxdis = max(maxdis, cl)\n\ndef gcd(a, b):\n if a == 0:\n return b\n return gcd(b%a, a)\ndef mkd(a, b):\n return (a*b)//gcd(a,b)\nmkl=1\nfor i in loopl:\n mkl = mkd(mkl, i)\nans = mkl\nwhile ans < maxdis:\n ans += mkl\nprint(ans)\n#print(inloop)\n#print(loopl)\n", "import sys\ninput = sys.stdin.readline\nfrom math import gcd\n\ndef lcm(a):\n result = 1\n for i in a:\n result = result*i//gcd(result, i)\n return result\n\ndef find_length(n, f, i):\n seen = set()\n j = i\n count = 0\n while j not in seen:\n seen.add(j)\n j = f[j]\n count += 1\n if j == i:\n return count, True\n else:\n count = 0\n while i != j:\n i = f[i]\n count += 1\n return count, False\n \n\nn = int(input())\nf = [0] + [int(i) for i in input().split()]\ncycle_lengths = []\nmax_spur_length = 0\nfor i in range(1, n + 1):\n length, is_cycle = find_length(n, f, i)\n if is_cycle:\n cycle_lengths.append(length)\n else:\n max_spur_length = max(length, max_spur_length)\ncycle_length_lcm = lcm(cycle_lengths)\nif cycle_length_lcm >= max_spur_length:\n print(cycle_length_lcm)\nelse:\n print(cycle_length_lcm*(1 + (max_spur_length - 1)//cycle_length_lcm))\n", "from math import gcd\r\nn = int(input())\r\nf = list(map(int,input().split()))\r\nvis = [0 for i in range(n)]\r\ncyc = [False for i in range(n)]\r\ndp = [0 for i in range(n)]\r\n\r\ndef dfs(u):\r\n if vis[u] == 2:\r\n return -1\r\n if vis[u] == 0:\r\n vis[u] = 1\r\n ret = dfs(f[u])\r\n vis[u] = 2\r\n return ret\r\n if vis[u] == 1:\r\n return u\r\n\r\ndef go(u):\r\n if dp[u] > 0:\r\n return dp[u]\r\n if cyc[u]:\r\n return 0\r\n dp[u] = go(f[u]) + 1\r\n return dp[u]\r\n\r\n\r\nfor i in range(n):\r\n f[i] -= 1\r\nans = 1\r\n\r\nfor i in range(n):\r\n u = dfs(i)\r\n if u == -1:\r\n continue\r\n cyc[u] = True\r\n v = f[u]\r\n w = 1\r\n while v != u:\r\n w += 1\r\n cyc[v] = True\r\n v = f[v]\r\n ans = ans * w // gcd(ans, w)\r\nmx = 1\r\nfor i in range(n):\r\n if dp[i] == 0 and not cyc[i]:\r\n mx = max(mx, go(i))\r\nprint((mx + ans - 1) // ans * ans)\r\n\r\n\r\n\r\n", "import math\ndef ciclos(arr, i):\n\td = {i:0}\n\tcnt = 1\n\twhile True:\n\t\ti = arr[i]-1\n\t\tif i in d:\n\t\t\treturn d[i],cnt-d[i]\n\t\t\n\t\td[i] = cnt\n\t\tcnt+=1\n\n\n\ndef\tmcm(a,b):\n\treturn (a*b//math.gcd(a,b))\n\t\nn = int(input())\na = [int(x) for x in input().split()]\n\nmax_offset = -float('inf')\nact_mcm = 1\naux_max = -float('inf')\n\nfor i in range(n):\n\toff, lon = ciclos(a,i)\n\taux = lon if (off==0) else lon*math.ceil(off/lon)\n\tmax_offset = max(max_offset,off)\n\taux_max = max(aux_max, aux)\n\tact_mcm = mcm(act_mcm,lon)\n\t\n\nprint(act_mcm*math.ceil(aux_max/act_mcm))", "from math import *\nfrom random import *\nfrom copy import *\nimport os\nimport sys\nimport fractions\n\nn = int(input())\nA = [0] + list(map(int, input().split()))\nX, Y = 0, 1\n\nfor i in range(1, n + 1):\n cnt = [-1] * (n + 1)\n now = i\n x = 0\n\n while cnt[now] == -1:\n cnt[now] = x\n now = A[now]\n x += 1\n\n y = x - cnt[now]\n x -= y\n X = max(X, x)\n Y = Y * y // fractions.gcd(Y, y)\n\nprint(max(Y, (X + Y - 1) // Y * Y))\n", "import sys\nimport fractions\nn = int(input())\nrefs = [0] * n\nused = [0] * n\nto = [int(x)-1 for x in input().split(' ')]\nfor i in to:\n refs[i] += 1\n\ntimes = []\nmax_a = 0\ndepth = [-1] * n\n\ndef dfs(u, d, depth):\n if depth[u] != -1:\n loop = d - depth[u]\n times.append(loop)\n global max_a\n if max_a < depth[u]:\n max_a = depth[u]\n return\n used[u] = True\n depth[u] = d\n return dfs(to[u], d+1, depth)\n\nfor i in range(n):\n if refs[i] == 0:\n depth = [-1] * n\n b = dfs(i, 0, depth)\n\nfor i in range(n):\n if not used[i]:\n depth = [-1] * n\n b = dfs(i, 0, depth)\n\n\nlcm = 1\nfor t in times:\n lcm = lcm * t // fractions.gcd(lcm, t)\n\nans = lcm\nwhile ans < max_a:\n ans += lcm\nprint(ans)\n\n\n\n", "import sys\n\nn = int(sys.stdin.readline())\na = list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))\n\npath_lens = []\ncycle_lens = []\nfor i, v in enumerate(a):\n\tcur = i\n\tvisited = []\n\twhile cur not in visited:\n\t\tvisited.append(cur)\n\t\tcur = a[cur]\n\tvisited.append(cur)\n\n\tpath_len = 0\n\tfor j, x in enumerate(visited):\n\t\tif x in visited[j+1:]:\n\t\t\tbreak\n\t\tpath_len += 1\n\tcycle_len = len(visited) - path_len - 1\n\n\tpath_lens.append(path_len)\n\tcycle_lens.append(cycle_len)\n\ndef gcd(a, b):\n\tif b == 0:\n\t\treturn a\n\telse:\n\t\treturn gcd(b, a % b)\n\nto_start = max(path_lens)\nlcm = 1\nfor i, v in enumerate(cycle_lens):\n\tlcm = lcm * v // gcd(lcm, v)\n\n# res = to_start\n# if lcm > 1:\n# \tres += lcm\n\nres = to_start\nif to_start % lcm > 0 or to_start == 0:\n\tres += lcm - to_start % lcm\nprint(res)\n", "import sys\r\n#sys.stdin = open('input.txt', 'r')\r\n#sys.stdout = open('output.txt', 'w')\r\n\r\ndef nod(a, b):\r\n\twhile b != 0:\r\n\t\ta, b = b, a % b\r\n\treturn a\r\ndef nok(a, b):\r\n\treturn a * b // nod(a, b)\r\n\r\nn = int(input())\r\na = [0] + list(map(int, input().split()))\r\nused = [False] * (n + 1)\r\nans = 1\r\nfor i in range(1, n + 1):\r\n\tt = i\r\n\tcnt = 0\r\n\twhile(1):\r\n\t\tt = a[t]\r\n\t\tcnt += 1\r\n\t\tif t == i:\r\n\t\t\tok = True\r\n\t\t\tbreak\r\n\t\tif cnt > n:\r\n\t\t\tok = False\r\n\t\t\tbreak\r\n\tif (ok):\r\n\t\tused[i] = True\r\n\t\tans = nok(ans, cnt)\r\ngl_ans = ans\r\nfor i in range(1, n + 1):\r\n\tif not used[i]:\r\n\t\tcnt = 0;\r\n\t\tt = i\r\n\t\twhile (1):\r\n\t\t\tif (used[t]):\r\n\t\t\t\tbreak\t\r\n\t\t\tt = a[t]\r\n\t\t\tcnt+=1\r\n\t\twhile (gl_ans < cnt):\r\n\t\t\tgl_ans += ans\r\nprint(gl_ans)", "n = int(input())\nf = list(map(int, input().split()))\nfor i in range(n):\n f[i] -= 1\n\ndef gcd(a, b):\n while (a != 0 and b != 0):\n a, b = b, a % b\n return a + b\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\nans = 1\nminn = 0\n\nfor i in range(n):\n vis = [False] * n\n cur = i\n st, pr = 0, 0\n while not vis[cur]:\n vis[cur] = True\n cur = f[cur]\n st += 1\n fs = cur\n cur = i\n while cur != fs:\n pr += 1\n cur = f[cur]\n minn = max(minn, pr)\n ans = lcm(ans, st - pr)\n\nprint(((max(0, minn - 1))// ans + 1) * ans)\n", "from random import randint\nfrom copy import deepcopy\n\nn = int(input())\na = list(map(int, input().split()))\nfor i in range(n):\n a[i] -= 1\n\ndef gen(n):\n a = []\n for i in range(n):\n a.append(randint(0, n - 1))\n return a\n\ndef stupid(a, v=False):\n n = len(a)\n init = [a[i] for i in range(n)]\n \n k = 1\n good = False\n while not good:\n good = True\n if v:\n print(a)\n for i in range(n):\n if a[a[i]] != a[i]:\n good = False\n if good:\n break\n k += 1\n b = [0 for i in range(n)]\n for i in range(n):\n b[i] = init[a[i]]\n\n a = [b[i] for i in range(n)]\n\n return k\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef get_lcm(a, b):\n return a * b // gcd(a, b)\n\ndef solve(a, v=False):\n n = len(a)\n d = [0 for i in range(n)]\n on_cycle = [False for i in range(n)]\n cycle_length = [0 for i in range(n)]\n until = [0 for i in range(n)]\n to_len = [0 for i in range(n)]\n\n for i in range(n):\n if a[i] == i:\n on_cycle[i] = True\n cycle_length[i] = 1\n continue\n cur = i\n cnt = 1\n for j in range(3 * n):\n cur = a[cur]\n cnt += cur == i\n on_cycle[i] = cnt > 1\n\n if on_cycle[i]:\n cur = i\n steps = 0\n for j in range(3 * n):\n cur = a[cur]\n steps += 1\n if cur == i:\n break\n cycle_length[i] = steps\n\n\n for i in range(n):\n if not on_cycle[i]:\n cur = i\n steps = 0\n for j in range(n + 1):\n cur = a[cur]\n steps += 1\n if on_cycle[cur]:\n break\n until[i] = steps\n to_len[i] = cycle_length[cur]\n\n if v:\n print('cycle', cycle_length)\n print('until', until)\n lcm = 1\n low = 0\n for i in range(n):\n if on_cycle[i]:\n lcm = get_lcm(lcm, cycle_length[i])\n else:\n low = max(low, until[i])\n continue\n to = to_len[i]\n p = until[i]\n \n if p % to:\n p = ((p // to) + 1) * to\n low = max(low, p)\n if v:\n print(i, p, to)\n ans = lcm\n while ans < low:\n ans += lcm\n return ans\n\nprint(solve(a))\nwhile False:\n a = gen(randint(1, 15))\n print(a)\n print(stupid(deepcopy(a)))\n print(solve(deepcopy(a)))\n assert(stupid(deepcopy(a)) == solve(deepcopy(a)))\n" ]
{"inputs": ["4\n1 2 2 4", "3\n2 3 3", "3\n2 3 1", "1\n1", "16\n1 4 13 9 11 16 14 6 5 12 7 8 15 2 3 10", "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "20\n11 14 2 10 17 5 9 6 18 3 17 7 4 15 17 1 4 14 10 11", "100\n46 7 63 48 75 82 85 90 65 23 36 96 96 29 76 67 26 2 72 76 18 30 48 98 100 61 55 74 18 28 36 89 4 65 94 48 53 19 66 77 91 35 94 97 19 45 82 56 11 23 24 51 62 85 25 11 68 19 57 92 53 31 36 28 70 36 62 78 19 10 12 35 46 74 31 79 15 98 15 80 24 59 98 96 92 1 92 16 13 73 99 100 76 52 52 40 85 54 49 89", "100\n61 41 85 52 22 82 98 25 60 35 67 78 65 69 55 86 34 91 92 36 24 2 26 15 76 99 4 95 79 31 13 16 100 83 21 90 73 32 19 33 77 40 72 62 88 43 84 14 10 9 46 70 23 45 42 96 94 38 97 58 47 93 59 51 57 7 27 74 1 30 64 3 63 49 50 54 5 37 48 11 81 44 12 17 75 71 89 39 56 20 6 8 53 28 80 66 29 87 18 68", "2\n1 2", "2\n1 1", "2\n2 2", "2\n2 1", "5\n2 1 2 3 4", "3\n2 1 2", "4\n2 1 2 3", "6\n2 1 2 3 4 5", "4\n2 3 1 1", "5\n2 3 1 1 4", "6\n2 3 1 1 4 5", "7\n2 3 1 1 4 5 6", "8\n2 3 1 1 4 5 6 7", "142\n131 32 130 139 5 11 36 2 39 92 111 91 8 14 65 82 90 72 140 80 26 124 97 15 43 77 58 132 21 68 31 45 6 69 70 79 141 27 125 78 93 88 115 104 17 55 86 28 56 117 121 136 12 59 85 95 74 18 87 22 106 112 60 119 81 66 52 14 25 127 29 103 24 48 126 30 120 107 51 47 133 129 96 138 113 37 64 114 53 73 108 62 1 123 63 57 142 76 16 4 35 54 19 110 42 116 7 10 118 9 71 49 75 23 89 99 3 137 38 98 61 128 102 13 122 33 50 94 100 105 109 134 40 20 135 46 34 41 83 67 44 84", "142\n34 88 88 88 88 88 131 53 88 130 131 88 88 130 88 131 53 130 130 34 88 88 131 130 53 88 88 34 131 130 88 131 130 34 130 53 53 34 53 34 130 34 88 88 130 88 131 130 34 53 88 34 53 88 130 53 34 53 88 131 130 34 88 88 130 88 130 130 131 131 130 53 131 130 131 130 53 34 131 34 88 53 88 53 34 130 88 88 130 53 130 34 131 130 53 131 130 88 130 131 53 130 34 130 88 53 88 88 53 88 34 131 88 131 130 53 130 130 53 130 88 88 131 53 88 53 53 34 53 130 131 130 34 131 34 53 130 88 34 34 53 34", "142\n25 46 7 30 112 34 76 5 130 122 7 132 54 82 139 97 79 112 79 79 112 43 25 50 118 112 87 11 51 30 90 56 119 46 9 81 5 103 78 18 49 37 43 129 124 90 109 6 31 50 90 20 79 99 130 31 131 62 50 84 5 34 6 41 79 112 9 30 141 114 34 11 46 92 97 30 95 112 24 24 74 121 65 31 127 28 140 30 79 90 9 10 56 88 9 65 128 79 56 37 109 37 30 95 37 105 3 102 120 18 28 90 107 29 128 137 59 62 62 77 34 43 26 5 99 97 44 130 115 130 130 47 83 53 77 80 131 79 28 98 10 52", "142\n138 102 2 111 17 64 25 11 3 90 118 120 46 33 131 87 119 9 72 141 62 116 44 136 81 122 93 106 123 62 35 17 98 49 46 124 32 67 93 90 91 99 36 46 138 5 52 73 139 2 11 97 6 9 47 56 134 134 112 90 94 55 97 98 118 37 109 31 132 58 95 98 76 76 63 7 110 28 133 50 46 136 115 57 113 55 4 96 63 66 9 52 107 17 95 78 95 118 69 105 18 10 52 94 29 36 113 86 132 39 77 42 113 116 135 93 136 39 48 119 124 35 10 133 138 45 78 107 132 130 49 28 73 85 135 4 119 38 78 116 108 125", "9\n7 3 8 9 9 3 5 3 2", "5\n2 1 4 5 3", "7\n2 3 4 5 6 7 6", "129\n2 1 4 5 3 7 8 9 10 6 12 13 14 15 16 17 11 19 20 21 22 23 24 25 26 27 28 18 30 31 32 33 34 35 36 37 38 39 40 41 29 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 42 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 59 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 78 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 101", "4\n2 3 4 1"], "outputs": ["1", "2", "3", "1", "105", "1", "7", "24", "14549535", "1", "1", "1", "2", "4", "2", "2", "4", "3", "3", "3", "6", "6", "137", "1", "8", "20", "6", "6", "6", "6469693230", "4"]}
UNKNOWN
PYTHON3
CODEFORCES
12
11e1871581824dfb08ec542251c5ca25
Travel Cards
In the evening Polycarp decided to analyze his today's travel expenses on public transport. The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus has no intermediate stops. So each of the buses continuously runs along the route from one stop to the other and back. There is at most one bus running between a pair of stops. Polycarp made *n* trips on buses. About each trip the stop where he started the trip and the the stop where he finished are known. The trips follow in the chronological order in Polycarp's notes. It is known that one trip on any bus costs *a* burles. In case when passenger makes a transshipment the cost of trip decreases to *b* burles (*b*<=&lt;<=*a*). A passenger makes a transshipment if the stop on which he boards the bus coincides with the stop where he left the previous bus. Obviously, the first trip can not be made with transshipment. For example, if Polycarp made three consecutive trips: "BerBank" "University", "University" "BerMall", "University" "BerBank", then he payed *a*<=+<=*b*<=+<=*a*<==<=2*a*<=+<=*b* burles. From the BerBank he arrived to the University, where he made transshipment to the other bus and departed to the BerMall. Then he walked to the University and returned to the BerBank by bus. Also Polycarp can buy no more than *k* travel cards. Each travel card costs *f* burles. The travel card for a single bus route makes free of charge any trip by this route (in both directions). Once purchased, a travel card can be used any number of times in any direction. What is the smallest amount of money Polycarp could have spent today if he can buy no more than *k* travel cards? The first line contains five integers *n*,<=*a*,<=*b*,<=*k*,<=*f* (1<=≤<=*n*<=≤<=300, 1<=≤<=*b*<=&lt;<=*a*<=≤<=100, 0<=≤<=*k*<=≤<=300, 1<=≤<=*f*<=≤<=1000) where: - *n* — the number of Polycarp trips, - *a* — the cost of a regualar single trip, - *b* — the cost of a trip after a transshipment, - *k* — the maximum number of travel cards Polycarp can buy, - *f* — the cost of a single travel card. The following *n* lines describe the trips in the chronological order. Each line contains exactly two different words separated by a single space — the name of the start stop and the name of the finish stop of the trip. All names consist of uppercase and lowercase English letters and have lengths between 1 to 20 letters inclusive. Uppercase and lowercase letters should be considered different. Print the smallest amount of money Polycarp could have spent today, if he can purchase no more than *k* travel cards. Sample Input 3 5 3 1 8 BerBank University University BerMall University BerBank 4 2 1 300 1000 a A A aa aa AA AA a Sample Output 11 5
[ "n, a, b, k, f = map(int, input().split())\r\n\r\nslov = dict()\r\ntemp = input().split()\r\nslov[frozenset(temp)] = a\r\n\r\nfor i in range(1, n):\r\n temp2 = input().split()\r\n try:\r\n if temp2[0] == temp[1]:\r\n slov[frozenset(temp2)] += b\r\n else:\r\n slov[frozenset(temp2)] += a\r\n except KeyError:\r\n if temp2[0] == temp[1]:\r\n slov[frozenset(temp2)] = b\r\n else:\r\n slov[frozenset(temp2)] = a\r\n temp = temp2\r\n\r\ncosts = sorted(list(slov.values()), reverse=True)\r\n\r\nfor i in range(min(k, len(costs))):\r\n if costs[i] > f:\r\n costs[i] = f\r\n else:\r\n break\r\n\r\nprint(sum(costs))", "n,a,b,k,f = map(int,input().split())\r\npoezd = {}\r\nsum = 0\r\nprev = \"\"\r\nfor i in range(n):\r\n ost =ost_key= input()\r\n ost_arr = ost.split()\r\n if ost not in poezd.keys():\r\n if ost_arr[1]+\" \"+ost_arr[0] in poezd.keys():\r\n ost_key = ost_arr[1]+\" \"+ost_arr[0]\r\n else:\r\n poezd[ost_key] = {\"a\":0,\"b\":0}\r\n if prev != ost.split()[0]:\r\n sum+=a\r\n poezd[ost_key][\"a\"]+=1\r\n else:\r\n sum+=b\r\n poezd[ost_key][\"b\"] += 1\r\n prev = ost.split()[1]\r\nsorted_cities = sorted(poezd.items(), key=lambda x: (x[1]['a'],x[1]['b']))\r\nsorted_cities.reverse()\r\nmin_sum = sum\r\nmin_arr = []\r\ncountofk = 0\r\nfor i in range(len(sorted_cities)):\r\n min_arr.append(sorted_cities[i][1]['a']*a+sorted_cities[i][1]['b']*b-f)\r\nmin_arr.sort()\r\nmin_arr.reverse()\r\nfor i in range(min(k,len(min_arr))):\r\n if min_sum-min_arr[i]<min_sum:\r\n min_sum-=min_arr[i]\r\n else:\r\n break\r\nprint(min_sum)\r\n", "def main():\n trips, reg, cheap, cards, card_cost = map(int, input().split())\n\n costs = []\n indexes = {}\n total = 0\n last = \"\"\n\n for i in range(trips):\n a, b = input().split()\n pair = (min(a, b), max(a, b))\n\n if pair in indexes:\n index = indexes[pair]\n else:\n costs.append(0)\n indexes[pair] = len(costs) - 1\n index = len(costs) - 1\n\n total += (cheap if a == last else reg)\n costs[index] += (cheap if a == last else reg)\n last = b\n\n costs = sorted(costs, reverse = True)\n\n for c in costs:\n if c < card_cost or cards <= 0:\n break\n total -= c\n total += card_cost\n cards -= 1\n\n print(total)\n\nmain()\n", "n, a ,b ,k ,f = map(int, input().split())\r\ndicts = dict()\r\nprev, res, ticket = \"\", 0, 0\r\nfor i in range(n):\r\n x, y = input().split()\r\n if x == prev:\r\n if (x, y) in dicts:\r\n dicts[(x, y)] += b\r\n elif (y, x) in dicts:\r\n dicts[(y, x)] += b\r\n else:\r\n dicts[(x,y)] = b\r\n else:\r\n if (x, y) in dicts:\r\n dicts[(x, y)] += a\r\n elif (y, x) in dicts:\r\n dicts[(y, x)] += a\r\n else:\r\n dicts[(x,y)] = a\r\n prev = y\r\nfor v in sorted(dicts.values(), reverse=True):\r\n if v > f and ticket < k:\r\n ticket += 1\r\n res += f\r\n else:\r\n res += v\r\nprint(res)", "n, a, b, k, f = [int(i) for i in input().split()]\nstops = dict()\nprev = \"\"\nans = 0\nfor i in range(n):\n x, y = [i for i in input().split()]\n price = a\n if x == prev:\n price = b\n prev = y\n p, q = (min(x,y), max(x,y))\n if (p, q) in stops:\n stops[(p,q)] += price\n else:\n stops[(p,q)] = price\n ans += price\nedge_cost = sorted([stops[key] for key in stops], reverse = True)\nfor i in edge_cost:\n if k > 0 and f < i:\n ans = ans - i + f\n else:\n break\n k -= 1\nprint(ans)\n\t \t \t \t \t\t\t \t \t \t \t \t" ]
{"inputs": ["3 5 3 1 8\nBerBank University\nUniversity BerMall\nUniversity BerBank", "4 2 1 300 1000\na A\nA aa\naa AA\nAA a", "2 2 1 0 1\naca BCBA\nBCBA aca", "2 2 1 2 1\nBDDB C\nC BDDB", "2 3 1 1 9\nbacAB aAdb\nbacAB aAdb", "2 3 1 4 6\nAaCdC CdD\naBACc CdD", "1 2 1 2 1\nC BA", "1 3 1 1 4\nbCCCC BC", "1 4 3 1 1\nC bC", "1 3 2 1 1\nBBC B", "3 2 1 5 1\nBCA cBBBd\ncBBBd CdC\nCdC bbdAb", "5 3 2 1 1\nC CB\nCB C\nC d\nCB d\nCB C", "3 3 1 0 1\ncbcC A\nA aA\nA cbcC", "3 3 1 4 3\nc CADC\nCADC ABaD\nABaD c", "8 2 1 11 1\ndacdD cdDAA\ncdDAA dacdD\ndacdD bcCA\nbcCA B\nDDAA B\nDDAA daC\nAbCAc B\ndacdD daC", "12 4 1 2 8\nDA b\nDA dC\ndC b\nb DA\nb dC\nDA b\ndC b\nb dC\ndC DA\nDA dC\nDA b\nb dC", "27 8 1 0 1\nBcd A\nA b\nb BcDc\ndc dbaC\ndbaC dcCB\nB d\nd BbAc\nCBC b\nDBDca d\ncAbb AA\nAA Ba\ncAccb DBDca\ncb DdaB\nAAcBc Ba\nBa dc\ndc DDCd\nbcBDA da\nbDD ADD\nAA b\nb cb\ncb CCBbd\nCCBbd bcDdb\nbcDdb ddc\nddc C\nC Adc\nAdc BbAc\nBbAc DD", "22 85 1 36 1\ncdAd cBbCa\ncBbCa abBBc\nabBBc dddb\ndddb BBDA\nBBDA abBBc\nabBBc ADCad\naDaC cdAd\ncdAd D\nD acCbD\nAd DB\nDB C\nACb ca\nca ACb\nACb D\nD BBDA\nBBDA d\nd C\nC A\nA B\nB Ad\nAd cDD\ncDD ACb", "8 8 2 4 5\naBBba C\nCc CcBd\nd C\ndD dDba\ndDba c\nCc d\nd dD\ndD dDba", "4 10 6 2 7\nbbCc c\nd Bdccd\nBdccd c\nc Bdccd", "10 3 2 6 2\nbCbA a\naDA Bba\nbCbA aDA\nBba caa\nbCbA Bba\ncaa aDA\naDA bCbA\nbCbA dBba\ndBba bCbA\ndBba a", "7 5 4 3 2\nDBBCa BdC\nCDBcb BdC\ncA BdC\nBD CDBcb\nBD BdC\nDDd cacD\nBdC cA", "9 10 5 4 3\nDcAaa caCBc\ncaCBc B\nB b\nb cdddb\ncdddb aDBAb\naDBAb B\nB aDBAb\naDBAb cdddb\ncdddb aDCda", "10 20 10 0 11\nudgbkX Xe\nXe udgbkX\nudgbkX Xe\nXe udgbkX\nudgbkX Xe\nXe udgbkX\nudgbkX Xe\nXe udgbkX\nudgbkX Xe\nXe udgbkX", "10 20 10 1 11\nkeJKdQ HS\nHS keJKdQ\nkeJKdQ HS\nHS keJKdQ\nkeJKdQ HS\nHS keJKdQ\nkeJKdQ HS\nHS keJKdQ\nkeJKdQ HS\nHS keJKdQ"], "outputs": ["11", "5", "3", "1", "6", "6", "1", "3", "1", "1", "3", "6", "7", "5", "7", "22", "111", "21", "32", "24", "18", "21", "27", "110", "11"]}
UNKNOWN
PYTHON3
CODEFORCES
5
1227949a1bf9ddb09337a57819e135a2
Exams
Vasiliy has an exam period which will continue for *n* days. He has to pass exams on *m* subjects. Subjects are numbered from 1 to *m*. About every day we know exam for which one of *m* subjects can be passed on that day. Perhaps, some day you can't pass any exam. It is not allowed to pass more than one exam on any day. On each day Vasiliy can either pass the exam of that day (it takes the whole day) or prepare all day for some exam or have a rest. About each subject Vasiliy know a number *a**i* — the number of days he should prepare to pass the exam number *i*. Vasiliy can switch subjects while preparing for exams, it is not necessary to prepare continuously during *a**i* days for the exam number *i*. He can mix the order of preparation for exams in any way. Your task is to determine the minimum number of days in which Vasiliy can pass all exams, or determine that it is impossible. Each exam should be passed exactly one time. The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of days in the exam period and the number of subjects. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (0<=≤<=*d**i*<=≤<=*m*), where *d**i* is the number of subject, the exam of which can be passed on the day number *i*. If *d**i* equals 0, it is not allowed to pass any exams on the day number *i*. The third line contains *m* positive integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=105), where *a**i* is the number of days that are needed to prepare before passing the exam on the subject *i*. Print one integer — the minimum number of days in which Vasiliy can pass all exams. If it is impossible, print -1. Sample Input 7 2 0 1 0 2 1 0 2 2 1 10 3 0 0 1 2 3 0 2 0 1 2 1 1 4 5 1 1 1 1 1 1 5 Sample Output 5 9 -1
[ "n,m = map(int,input().split())\nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\nsums = sum(B)+len(B)\nlast = [-1] * m\ncou = 0\nans = 0\nper = 0\nfor j in range(n):\n if A[j] == 0:\n cou +=1\n else:\n if last[A[j]-1] == -1:\n if j >= B[A[j]-1]: \n ans += 1\n last[A[j]-1] = 0 \n if ans == m:\n if (j+1) >= sums:\n per=1\n print(j+1)\n break \nif per == 0:\n print(-1)\n \n\n \t \t \t \t \t\t\t \t \t \t", "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(days):\n C = B[:]\n vis = set()\n s = []\n for i in range(days-1,-1,-1):\n if A[i] not in vis and A[i]!=0:\n vis.add(A[i])\n s.append(A[i])\n else:\n if not s:continue\n C[s[-1]-1]-=1\n if C[s[-1]-1]==0:\n s.pop()\n\n if sum(C)==0:return True\n return False\n\nN,M = map(int,input().split())\nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\nsu = sum(B)\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\n\nif 1<=l<=N:\n print(l)\nelif 1<=r<=N:\n print(r)\nelse:\n print(-1)\n", "import sys \r\ninput = sys.stdin.buffer.readline\r\n\r\ndef check(x, d, A):\r\n n = len(d)\r\n m = len(A)\r\n exam_days = [None for i in range(m+1)]\r\n for i in range(x):\r\n di = d[i]\r\n exam_days[di] = i\r\n L = []\r\n for i in range(1, m+1):\r\n if exam_days[i] is None:\r\n return False \r\n L.append([exam_days[i]+1, i])\r\n L.sort()\r\n total = sum(A)+m\r\n while len(L) > 0:\r\n di, i = L.pop()\r\n if di < total:\r\n return False\r\n total-=(A[i-1]+1)\r\n return True\r\ndef process(d, A):\r\n n = len(d)\r\n m = len(A)\r\n if check(n, d, A) is False:\r\n sys.stdout.write('-1\\n')\r\n return \r\n s = 0 \r\n e = n \r\n while s+1 < e:\r\n m = (s+e)//2 \r\n if not check(m, d, A):\r\n s, e = m, e \r\n else:\r\n s, e = s, m \r\n sys.stdout.write(f'{e}\\n')\r\n return\r\n\r\nn, m = [int(x) for x in input().split()]\r\nd = [int(x) for x in input().split()]\r\nA = [int(x) for x in input().split()]\r\nprocess(d, A)", "import sys\r\nfrom heapq import heappush, heappop\r\n \r\n# https://codeforces.com/problemset/problem/732/D\r\n \r\nparams = sys.stdin.readline().split(' ')\r\nn = int(params[0])\r\nm = int(params[1])\r\n \r\nd = [int(d) for d in sys.stdin.readline().split(' ')]\r\n \r\nexams = [int(e) for e in sys.stdin.readline().split(' ')]\r\n \r\n# Minimal time for doing exams and study\r\nminimal_time = sum(exams) + len(exams)\r\n \r\n \r\ndef isPossible(d, exams, max, m):\r\n \r\n # Set priority exams\r\n keys = {}\r\n for day in range(max):\r\n if d[day] != 0:\r\n keys[d[day]] = day\r\n \r\n if len(keys) < m :\r\n return False\r\n \r\n priority_queue = []\r\n for key in keys:\r\n heappush(priority_queue, (keys[key], key))\r\n \r\n # Check possibility\r\n possible = True\r\n \r\n time = 0\r\n \r\n while possible and len(priority_queue) > 0:\r\n # Take the exams\r\n exam = heappop(priority_queue)\r\n \r\n # Learning time \r\n learning_duration = exams[exam[1] - 1]\r\n \r\n # Add to the time + time for the exam\r\n time += learning_duration + 1\r\n \r\n # Check if it's always possible\r\n if time > exam[0] + 1 :\r\n possible = False\r\n \r\n return possible\r\n \r\n \r\nbestValue = -1\r\n \r\nif minimal_time > n:\r\n print(-1)\r\nelse :\r\n min = minimal_time\r\n max = n\r\n \r\n while min <= max :\r\n \r\n mid = min + ((max - min) // 2)\r\n \r\n possible = isPossible(d, exams, mid, m)\r\n \r\n # Too small number\r\n if not possible :\r\n min = mid + 1\r\n else :\r\n bestValue = mid\r\n max = mid - 1\r\n \r\n \r\n print(bestValue)", "n,m = map(int,input().split())\r\nA = list(map(int,input().split()))\r\nB = list(map(int,input().split()))\r\nsums = sum(B)+len(B)\r\nlast = [-1] * m\r\ncou = 0\r\nans = 0\r\nper = 0\r\nfor j in range(n):\r\n if A[j] == 0:\r\n cou +=1\r\n else:\r\n if last[A[j]-1] == -1:\r\n if j >= B[A[j]-1]:\r\n \r\n ans += 1\r\n last[A[j]-1] = 0\r\n if ans == m:\r\n if (j+1) >= sums:\r\n per=1\r\n print(j+1)\r\n break\r\nif per == 0:\r\n print(-1)\r\n \r\n", "import sys\r\nn, m = map(int, input().split())\r\ndi = list(map(int, input().split()))\r\nai = list(map(int, input().split()))\r\ncheck = [False] * m\r\ntemp = 0\r\nfor i in range(n):\r\n if di[i] == 0:\r\n continue\r\n else:\r\n if not check[di[i]-1]:\r\n if ai[di[i]-1] <= i:\r\n temp += 1\r\n check[di[i]-1] = True\r\n if temp==m:\r\n if i+1 >= (sum(ai)+m):\r\n print(i+1)\r\n sys.exit()\r\nprint(-1)", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef binary_search(c1, c2):\r\n c = (c1 + c2 + 1) // 2\r\n while abs(c1 - c2) > 1:\r\n c = (c1 + c2 + 1) // 2\r\n if ok(c):\r\n c2 = c\r\n else:\r\n c1 = c\r\n c = max(c - 1, 0)\r\n while not ok(c):\r\n c += 1\r\n return c\r\n\r\ndef ok(c):\r\n if c > n:\r\n return True\r\n x, y = [], [0] * (m + 1)\r\n for i in range(c, 0, -1):\r\n di = d[i]\r\n if not di:\r\n continue\r\n if not y[di]:\r\n x.append(di)\r\n y[di] = i\r\n if len(x) < m:\r\n return False\r\n s = 0\r\n for i in x[::-1]:\r\n s += a[i] + 1\r\n if s > y[i]:\r\n return False\r\n return True\r\n\r\nn, m = map(int, input().split())\r\nd = [0] + list(map(int, input().split()))\r\na = [0] + list(map(int, input().split()))\r\nif not ok(n):\r\n ans = -1\r\n print(ans)\r\n exit()\r\nans = binary_search(0, n + 1)\r\nprint(ans)" ]
{"inputs": ["7 2\n0 1 0 2 1 0 2\n2 1", "10 3\n0 0 1 2 3 0 2 0 1 2\n1 1 4", "5 1\n1 1 1 1 1\n5", "100 10\n1 1 6 6 6 2 5 7 6 5 3 7 10 10 8 9 7 6 9 2 6 7 8 6 7 5 2 5 10 1 10 1 8 10 2 9 7 1 6 8 3 10 9 4 4 8 8 6 6 1 5 5 6 5 6 6 6 9 4 7 5 4 6 6 1 1 2 1 8 10 6 2 1 7 2 1 8 10 9 2 7 3 1 5 10 2 8 10 10 10 8 9 5 4 6 10 8 9 6 6\n2 4 10 11 5 2 6 7 2 15", "1 1\n1\n1", "3 2\n0 0 0\n2 1", "4 2\n0 1 0 2\n1 1", "10 1\n0 1 0 0 0 0 0 0 0 1\n1", "5 1\n0 0 0 0 1\n1", "7 2\n0 0 0 0 0 1 2\n1 1", "10 3\n0 0 1 2 2 0 2 0 1 3\n1 1 4", "6 2\n1 1 1 1 1 2\n1 1", "6 2\n1 0 0 0 0 2\n1 1"], "outputs": ["5", "9", "-1", "74", "-1", "-1", "4", "2", "5", "7", "10", "6", "-1"]}
UNKNOWN
PYTHON3
CODEFORCES
7
1242b7a42964481d8e4bbc5e3d3435d6
Greenhouse Effect
Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated *n* plants in his greenhouse, of *m* different plant species numbered from 1 to *m*. His greenhouse is very narrow and can be viewed as an infinite line, with each plant occupying a single point on that line. Emuskald has discovered that each species thrives at a different temperature, so he wants to arrange *m*<=-<=1 borders that would divide the greenhouse into *m* sections numbered from 1 to *m* from left to right with each section housing a single species. He is free to place the borders, but in the end all of the *i*-th species plants must reside in *i*-th section from the left. Of course, it is not always possible to place the borders in such way, so Emuskald needs to replant some of his plants. He can remove each plant from its position and place it anywhere in the greenhouse (at any real coordinate) with no plant already in it. Since replanting is a lot of stress for the plants, help Emuskald find the minimum number of plants he has to replant to be able to place the borders. The first line of input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=5000, *n*<=≥<=*m*), the number of plants and the number of different species. Each of the following *n* lines contain two space-separated numbers: one integer number *s**i* (1<=≤<=*s**i*<=≤<=*m*), and one real number *x**i* (0<=≤<=*x**i*<=≤<=109), the species and position of the *i*-th plant. Each *x**i* will contain no more than 6 digits after the decimal point. It is guaranteed that all *x**i* are different; there is at least one plant of each species; the plants are given in order "from left to the right", that is in the ascending order of their *x**i* coordinates (*x**i*<=&lt;<=*x**i*<=+<=1,<=1<=≤<=*i*<=&lt;<=*n*). Output a single integer — the minimum number of plants to be replanted. Sample Input 3 2 2 1 1 2.0 1 3.100 3 3 1 5.0 2 5.5 3 6.0 6 3 1 14.284235 2 17.921382 1 20.328172 3 20.842331 1 25.790145 1 27.204125 Sample Output 1 0 2
[ "n, m = map(int, input().split())\nt = [int(input().split()[0]) for i in range(n)]\np = [0] * (m + 1)\nfor i in t: p[i] = max(p[1:i+1])+1\nprint(n - max(p))\n", "'''n, m, k = [int(x) for x in input().split()]\n\ntrees = tuple([int(x) for x in input().split()])\n\ncosts = []\nfor x in range(n):\n costs.append([0] + [int(x) for x in input().split()])\n\ndp = [[[float('inf') for z in range(m + 1)] for y in range(k + 1)] for x in range(n)]\n\nif trees[0] == 0:\n for k in range(len(dp[0][0])):\n dp[0][1][k] = cost[0][k]\nelse:\n dp[0][0][trees[0]] = cost[0][trees[0]]\n\nfor i in range(1, len(dp)):\n for j in range(1, len(dp[0])):\n for k in range(1, len(dp[0][0])):\n if trees\n for l in range(len(dp[0][0])):\n if k == l:\n dp[i][j][k] = dp[i - 1][j][k] + cost[i][k]\n else:\n dp[i][j][k] = dp[i - 1][j - 1][l] + cost[i][k]'''\n\n\n\nn, m = [int(x) for x in input().split()]\nplant = [int(input().split()[0]) for x in range(n)]\ndp = [1 for x in range(n)]\n\n\n\nfor i in range(len(plant)):\n for j in range(0, i):\n if plant[j] > plant[i]:\n continue\n dp[i] = max(dp[i], dp[j] + 1)\n#print(dp)\nprint(n - max(dp))\n\n\n\n\n\n'''for i in range(1, n):\n for k in range(plant[i], 0, -1):\n dp[plant[i]] = max(dp[plant[i]], 1 + dp[k])\nprint(n - max(dp) - 1)'''\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "from sys import stdin\r\nn,m=map(int,input().split())\r\ns=[list(map(float,stdin.readline().strip().split()))[::-1] for i in range(n)]\r\ns.sort()\r\ns1=[int(i[1]) for i in s]\r\ndp=[1 for i in range(n)]\r\nans=1\r\nfor i in range(n-2,-1,-1):\r\n for j in range(i+1,n):\r\n if s1[j]>=s1[i]:\r\n dp[i]=max(dp[i],1+dp[j])\r\n ans=max(dp[i],ans)\r\nprint(n-ans)\r\n", "import math\r\nimport sys\r\ninput=sys.stdin.readline\r\n#t=int(input())\r\nt=1\r\nfor _ in range(t):\r\n #n=int(input())\r\n n,m=map(int,input().split())\r\n #l=list(map(int,input().split()))\r\n l=[]\r\n for __ in range(n):\r\n s,x=map(float,input().split())\r\n l.append(int(s))\r\n dp=[0]*(n+1)\r\n for i in range(n):\r\n j=l[i]\r\n for j1 in range(j,-1,-1):\r\n dp[j]=max(dp[j],1+dp[j1])\r\n maxi=max(dp[:])\r\n print(n-maxi)\r\n ", "numbers, types = map(int, input().split())\r\n\r\nposition = [0] * (numbers)\r\nbinary_search_array = [1] * (numbers)\r\n\r\nfor i in range(numbers):\r\n position[i] = int(input().split()[0])\r\n\r\nmax_length = int(0)\r\n\r\nfor i in range(numbers):\r\n low = int(0)\r\n high = int(max_length)\r\n\r\n while (low < high):\r\n mid = int((low + high) / 2)\r\n if (binary_search_array[mid] <= position[i]):\r\n low = mid + 1\r\n else:\r\n high = mid\r\n\r\n binary_search_array[low] = position[i]\r\n if (low == max_length):\r\n max_length += 1\r\n\r\n\r\nprint(numbers - max_length)\r\n", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nimport math\r\nfrom heapq import heappush , heappop\r\nfrom collections import defaultdict,deque,Counter\r\nfrom bisect import *\r\n\r\nN,M = map(int, input().split())\r\nA = []\r\nfor _ in range(N):\r\n s,x = input().split()\r\n s = int(s)\r\n x = float(x)\r\n A.append((x,s))\r\nA.sort()\r\nA.append((A[-1][0]+1, M+1))\r\n\r\ndp = [0]*(N+1)\r\nfor i in range(N+1):\r\n x,s = A[i]\r\n for j in range(i):\r\n if A[j][1]<=s:\r\n dp[i] = max(dp[i], dp[j]+1)\r\n\r\nprint(N-dp[-1])\r\n\r\n", "#!/usr/bin/env python3\n# created : 2020. 12. 31. 23:59\n\nimport os\nfrom sys import stdin, stdout\nfrom collections import deque\nfrom bisect import bisect_left, bisect_right\n\nINF = int(1e9)\n\ndef solve(tc):\n n, m = map(int, stdin.readline().split())\n\n species = []\n for i in range(n):\n si, xi = stdin.readline().split()\n species.append(int(si))\n\n dp = [[INF for j in range(m+1)] for i in range(n+1)]\n dp[0][0] = 0\n\n for i in range(1, n+1):\n pk = species[i-1]\n if dp[i-1][pk]<INF:\n dp[i][pk] = dp[i-1][pk]\n \n for j in range(pk):\n if dp[i-1][j]<INF:\n dp[i][j] = dp[i-1][j] + 1\n dp[i][pk] = min(dp[i][pk], dp[i-1][j])\n \n for j in range(pk+1, m+1):\n if dp[i-1][j]<INF:\n dp[i][j] = dp[i-1][j] + 1\n \n ans = INF\n for j in range(m+1):\n ans = min(ans, dp[n][j])\n print(ans)\n\n\ntcs = 1\n# tcs = int(stdin.readline().strip())\ntc = 1\nwhile tc <= tcs:\n solve(tc)\n tc += 1\n", "def CeilIndex(A, l, r, key): \r\n \r\n while (r - l > 1): \r\n \r\n m = l + (r - l)//2\r\n if (A[m] > key): \r\n r = m \r\n else: \r\n l = m \r\n return r \r\n \r\ndef LongestIncreasingSubsequenceLength(A, size): \r\n \r\n # Add boundary case, \r\n # when array size is one \r\n \r\n tailTable = [0 for i in range(size + 1)] \r\n len = 0 # always points empty slot \r\n \r\n tailTable[0] = A[0] \r\n len = 1\r\n for i in range(1, size): \r\n \r\n if (A[i] < tailTable[0]): \r\n \r\n # new smallest value \r\n tailTable[0] = A[i] \r\n \r\n elif (A[i] >= tailTable[len-1]): \r\n \r\n # A[i] wants to extend \r\n # largest subsequence \r\n tailTable[len] = A[i] \r\n len+= 1\r\n \r\n else: \r\n # A[i] wants to be current \r\n # end candidate of an existing \r\n # subsequence. It will replace \r\n # ceil value in tailTable \r\n tailTable[CeilIndex(tailTable, -1, len-1, A[i])] = A[i] \r\n \r\n \r\n return len\r\n \r\n# driver code \r\narr = [] \r\nn,m=map(int,input().split())\r\nfor i in range(n) :\r\n a,b=map(float,input().split())\r\n arr.append(a)\r\n \r\nprint(n-LongestIncreasingSubsequenceLength(arr, n)) \r\n \r\n# This code is contributed \r\n# by Anant Agarwal. \r\n", "\r\nn,m = list(map(int,input().split()))\r\narr = []\r\nfor i in range(n):\r\n l = list(map(float,input().split()))\r\n arr.append(int(l[0]))\r\ndp = [1 for i in range(n)]\r\n\r\nfor i in range(1,n):\r\n for j in range(i):\r\n if arr[j]<=arr[i]:\r\n dp[i] = max(dp[i],dp[j]+1)\r\nprint(n-max(dp))", "from bisect import bisect_right\r\nn = int(input().split()[0])\r\nt = [int(input().split()[0]) for i in range(n)]\r\np, k = [], 0\r\nfor i in t:\r\n x = bisect_right(p, i)\r\n if x < k: p[x] = i\r\n else:\r\n p.append(i)\r\n k += 1\r\nprint(n - k)", "n, m = map(int, input().split())\r\nt = [int(input().split()[0]) for i in range(n)]\r\np = [0] * (m + 1)\r\nfor i, j in enumerate(t): p[j] = min(p[j], min(p[: j])) - 1\r\nprint(n + min(p))", "n, m = [int(x) for x in input().split()]\r\nd = [0 for i in range(m)]\r\nfor i in range(n):\r\n c, x = [x for x in input().split()]\r\n c = int(c)\r\n\r\n d[c-1] = max(d[:c])+1\r\nprint(n-max(d))\r\n \r\n", "def lis(arr):\r\n\tn = len(arr)\r\n \r\n\t# Declare the list (array) for LIS and\r\n\t# initialize LIS values for all indexes\r\n\tlis = [1]*n\r\n \r\n\t# Compute optimized LIS values in bottom up manner\r\n\tfor i in range (1 , n):\r\n\t\tfor j in range(0 , i):\r\n\t\t\tif arr[i] >= arr[j] and lis[i]< lis[j] + 1 :\r\n\t\t\t\tlis[i] = lis[j]+1\r\n \r\n\t# Initialize maximum to 0 to get\r\n\t# the maximum of all LIS\r\n\treturn max(len(lst)-max(lis),0)\r\n \r\na,b=map(int,input().strip().split())\r\nlst=[]\r\nfor i in range(a):\r\n\tx,y=map(float,input().strip().split())\r\n\tlst.append(x)\r\n \r\nprint(lis(lst))", "def f(arr):\r\n\tarr=[None]+arr\r\n\tdp=[0]*(len(arr))\r\n\tfor i in range(1,len(arr)):\r\n\t\tj=int(arr[i])\r\n\t\tfor k in range(int(j),0,-1):\r\n\t\t\tdp[j]=max(dp[j],1+dp[k])\r\n\treturn len(arr)-max(dp)-1\r\na,b=map(int,input().strip().split())\r\nlst=[]\r\nfor i in range(a):\r\n\tx,y=map(float,input().strip().split())\r\n\tlst.append(x)\r\n\r\nprint(f(lst))", "# -*- coding:utf-8 -*-\n\n\"\"\"\n\ncreated by shuangquan.huang at 1/10/20\n\nLIS\n\n\"\"\"\n\nimport collections\nimport time\nimport os\nimport sys\nimport bisect\nimport heapq\nfrom typing import List\n\n\ndef solve(N, M, A):\n \n bit = [0 for _ in range(N)]\n \n def add(index, val):\n while index < N:\n bit[index] = max(bit[index], val)\n index |= index + 1\n \n def query(index):\n s = 0\n while index >= 0:\n s = max(s, bit[index])\n index = (index & (index + 1)) - 1\n \n return s\n \n q = [(v, i) for i, v in enumerate(A)]\n q.sort()\n \n s = 0\n for v, i in q:\n t = query(i) + 1\n add(i, t)\n s = max(s, t)\n \n return N-s\n \n \n \n\n\nN, M = map(int, input().split())\nA = []\nfor i in range(N):\n x, y = input().split()\n A.append(int(x))\n\nprint(solve(N, M, A))", "n, m = input().split()\nvalues = []\nres = []\nfor _ in range(int(n)): values.append(int(input().split()[0]))\nfor _ in range(int(m) + 1): res.append(0)\nfor value in values:\n auxmin = min(res[:value])\n res[value] = min(auxmin, res[value]) - 1\nprint(int(n) + min(res))\n\n\n \t \t\t\t\t \t\t\t \t\t \t \t \t \t \t\t\t \t\t", "n=int(input().split()[0])\r\na=[]\r\nfor _ in range(n):\r\n a.append(int(input().split()[0]))\r\ndp=[0]*n\r\nfor i in range(n):\r\n dp[i]= 1\r\n for j in range(i):\r\n if a[j]<= a[i] and dp[j]>= dp[i]:\r\n dp[i]=dp[j]+1\r\nprint(n-max(dp))\r\n \r\n", "n, m=[int(x) for x in input().split()]\r\ns=[]\r\ndp=[1 for i in range(n)]\r\nfor i in range(n):\r\n a=input().split()\r\n s.append(int(a[0]))\r\nfor i in range(n):\r\n for j in range(i):\r\n if s[j]<=s[i]:\r\n dp[i]=max(dp[i], dp[j]+1)\r\nprint(n-max(dp))\r\n", "from collections import defaultdict\r\nn,m=map(int,input().split())\r\narr=[]\r\nfor _ in range(n):\r\n a,b=map(float,input().split())\r\n arr.append((a,b))\r\narr.sort(key=lambda x:(x[1]))\r\nres=[a for a,_ in arr]\r\ndp=defaultdict(int)\r\nfor i in range(n):\r\n dp[i]=1\r\n for j in range(i):\r\n if arr[j]<=arr[i]:\r\n dp[i]=max(dp[i],dp[j]+1)\r\np=max(dp.values())\r\nprint(n-p)", "n,m=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n x,y=map(float,input().split())\r\n a.append([y,int(x)])\r\n\r\na.sort()\r\ndp=[1 for i in range(n)]\r\nfor i in range(1,n):\r\n for j in range(i):\r\n if a[j][1]<=a[i][1]:\r\n dp[i]=max(dp[i],dp[j]+1)\r\n# print(a,dp)\r\nprint(n-max(dp))", "n, m = map(int, input().split())\nt = [int(input().split()[0]) for i in range(n)]\np = [0] * (m + 1)\nfor i, j in enumerate(t): p[j] = min(p[: j+1]) - 1\nprint(n + min(p))\n", "n,m=map(int,input().split())\r\nt=[int(input().split()[0])for i in range(n)]\r\np=[0]*(m+1)\r\nfor i in t:p[i]=max(p[1:i+1])+1\r\nprint(n-max(p))", "import bisect\r\nimport collections\r\nimport copy\r\nimport enum\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(3001)\r\n\r\ninput = sys.stdin.readline\r\n\r\nn,m = map(int,input().split())\r\nps = []\r\nfor _ in range(n):\r\n k,_ = input().split()\r\n k = int(k)\r\n ind = bisect.bisect_left(ps,k+1)\r\n if ind==len(ps):\r\n ps.append(k)\r\n else:\r\n ps[ind] = k\r\nprint(n-len(ps))\r\n\r\n\r\n", "n,m=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n\ta,b=input().split()\r\n\tl.append(int(a))\r\ndp=[1]*n\r\nfor i in range(1,n):\r\n\tfor j in range(0,i):\r\n\t\tif l[i]>=l[j]:\t\r\n\t\t\tdp[i]=max(dp[i],dp[j]+1)\r\nprint(n-max(dp))", "def solve(n, a):\n lis = [0] * n\n for i in range(0, n):\n for j in range(0, i):\n if a[i] >= a[j]:\n lis[i] = max(lis[i], lis[j] + 1)\n if lis[i] == 0:\n lis[i] = 1\n print(n - max(lis))\n\n\ndef main():\n inp = lambda: int(input().split()[0])\n n = inp()\n a = [inp() for _ in range(n)]\n solve(n, a)\n\n\nif __name__ == \"__main__\":\n main()\n\n", "# Basta encontrar la medida del mayor subarray que es no-decreciente.\n# Con cada inserción podemos aumentar este número en 1.\n\nn = int(input().split()[0])\na = []\nfor _ in range(n):\n a.append(int(input().split()[0]))\ndp = [0]*n\nfor i in range(n):\n dp[i] = 1\n for j in range(i):\n if a[j] <= a[i] and dp[j] >= dp[i]:\n dp[i] = dp[j] + 1\nprint(n - max(dp))\n\n\t\t \t \t \t \t \t \t\t \t \t\t\t\t", "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,x = input().split()\n s = int(s)\n x = float(x)\n A.append((x,s))\nA.sort()\nA.append((A[-1][0]+1, M+1))\n\ndp = [0]*(N+1)\nfor i in range(N+1):\n x,s = A[i]\n for j in range(i):\n if A[j][1]<=s:\n dp[i] = max(dp[i], dp[j]+1)\n\nprint(N-dp[-1])\n\n", "n, m = map(int, input().split())\r\ntype = [0]\r\nfor x in range(n):\r\n\ttype.append(int(input().split()[0]))\r\n\r\ndp = [[0] * (m + 1) for x in range(2)]\r\nfor i in range(1, n + 1):\r\n\tdp[i & 1][0] = 1e9\r\n\tfor j in range (1, m + 1):\r\n\t\tif type[i] == j:\r\n\t\t\tdp[i & 1][j] = dp[1 - (i & 1)][j]\r\n\t\telif type[i] > j:\r\n\t\t\tdp[i & 1][j] = 1 + dp[1 - (i & 1)][j]\r\n\t\telse:\r\n\t\t\tif j >= 1:\r\n\t\t\t\tdp[i & 1][j] = min(dp[i & 1][j - 1], 1 + dp[1 - (i & 1)][j])\r\n\t\t\telse:\r\n\t\t\t\tdp[i & 1][j] = dp[1 - (i & 1)][j]\r\nprint (dp[n & 1][m])" ]
{"inputs": ["3 2\n2 1\n1 2.0\n1 3.100", "3 3\n1 5.0\n2 5.5\n3 6.0", "6 3\n1 14.284235\n2 17.921382\n1 20.328172\n3 20.842331\n1 25.790145\n1 27.204125", "1 1\n1 0", "8 2\n1 0.000000\n1 1.000000\n1 2.000000\n2 2.000001\n1 999999997.000000\n2 999999998.000000\n2 999999999.999999\n2 1000000000.000000", "15 5\n4 6.039627\n2 7.255149\n2 14.469785\n2 15.108572\n4 22.570081\n5 26.642253\n5 32.129202\n5 44.288220\n5 53.231909\n5 60.548042\n4 62.386581\n2 77.828816\n1 87.998512\n3 96.163559\n2 99.412872", "10 7\n4 70882.412953\n1 100461.912159\n3 100813.254090\n7 121632.112636\n2 424085.529781\n6 510966.713362\n6 543441.105338\n7 680094.776949\n1 721404.212606\n5 838754.272757", "5 5\n5 0\n4 1\n3 2\n2 3\n1 4", "12 5\n2 0\n2 1\n3 2\n3 3\n3 4\n1 5\n5 6\n3 7\n3 8\n3 9\n4 999999999\n4 1000000000", "3 3\n2 0\n1 1\n3 2", "3 3\n3 0\n1 1\n2 2", "4 2\n1 10\n2 20\n1 30\n2 40", "20 10\n1 0.000000\n2 0.000001\n3 0.000002\n4 0.000003\n5 0.000004\n6 0.000005\n7 0.000006\n8 0.000007\n9 0.000008\n10 0.000009\n1 999999999.999990\n2 999999999.999991\n3 999999999.999992\n4 999999999.999993\n5 999999999.999994\n6 999999999.999995\n7 999999999.999996\n8 999999999.999997\n9 999999999.999998\n10 999999999.999999", "12 4\n3 0\n3 1\n3 2\n3 3\n3 4\n1 5\n1 6\n2 7\n4 8\n4 9\n2 10\n3 11", "16 2\n1 0\n1 1\n2 2\n2 3\n2 4\n2 5\n1 6\n1 7\n2 8\n2 9\n1 10\n1 11\n2 12\n2 13\n2 14\n2 15", "10 10\n1 100\n2 101\n3 102\n5 103\n9 1000\n8 10000\n6 100000\n7 1000000\n4 10000000\n10 100000000", "10 6\n5 50837.108162\n3 111993.624183\n1 207268.919250\n6 567963.419694\n1 621364.247371\n2 630118.065585\n1 642135.221942\n6 642673.884754\n5 647004.198361\n4 735196.102629", "20 2\n1 39277.770446\n1 131242.472574\n2 131745.437889\n1 261920.593789\n2 323611.256365\n1 341693.666730\n2 378611.498102\n2 568433.562368\n1 667757.789581\n1 674662.040626\n2 690065.099817\n2 724737.429934\n1 774858.513301\n2 783681.914774\n1 808327.402925\n2 867697.070403\n1 880911.396984\n1 929807.064277\n2 942269.265950\n1 999503.792481", "20 15\n6 8719.787178\n10 13066.663722\n15 58623.690996\n9 184321.819759\n3 227999.294560\n2 279836.330518\n9 282806.308675\n8 311056.507765\n1 312315.562927\n5 459200.373445\n14 563454.265947\n7 647364.984868\n13 679761.613732\n4 684192.647497\n1 733119.607626\n7 748637.778398\n12 828048.945890\n11 893690.736585\n8 965323.895167\n5 967641.708962", "15 3\n1 0\n2 1\n3 2\n1 3\n2 4\n3 5\n1 6\n2 7\n3 8\n1 9\n2 10\n3 11\n1 12\n2 13\n3 14", "10 2\n2 0\n2 1\n2 2\n2 3\n2 4\n1 5\n1 6\n1 7\n1 8\n1 9", "11 3\n2 0\n2 1\n2 2\n2 3\n2 4\n3 5\n1 6\n1 7\n1 8\n1 9\n1 10"], "outputs": ["1", "0", "2", "0", "1", "6", "5", "4", "2", "1", "1", "1", "9", "5", "4", "3", "6", "9", "15", "8", "5", "5"]}
UNKNOWN
PYTHON3
CODEFORCES
28
1265110d8fb5c19020abe0903ee7b295
LLPS
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=≤<= *p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k* <=≤<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba". String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| &gt; |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=&lt;<=|*x*|, *r*<=&lt;<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=&gt;<=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post". String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z". The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. Print the lexicographically largest palindromic subsequence of string *s*. Sample Input radar bowwowwow codeforces mississipp Sample Output rr wwwww s ssss
[ "from itertools import combinations\r\ndef get_subsequences(input_str):\r\n for length in range(1, len(input_str)+1):\r\n for elems in combinations(input_str, length):\r\n yield ''.join(elems)\r\nprint(sorted([s for s in get_subsequences(input()) if s[::-1] == s])[-1])", "from sys import *\r\nimport sys\r\nfrom math import *\r\nfrom collections import *\r\nimport string\r\nimport re\r\nfrom bisect import *\r\nfrom functools import reduce\r\nfrom itertools import permutations, combinations\r\n# import numpy as np\r\n# def arr(): return np.random.randint(1,50,5)\r\n \r\nt=stdin.readline\r\nR=range\r\np=stdout.write\r\nmod = int(1e9)+7\r\nMAX = 9223372036854775808\r\nlower = string.ascii_lowercase\r\nupper = string.ascii_uppercase\r\nnumbers = string.digits\r\n\r\ndef S(): return t().strip()\r\ndef I(): return int(t())\r\ndef GI(): return map(int, input().strip().split())\r\ndef GS(): return map(str, t().strip().split())\r\ndef IL(): return list(map(int, t().strip().split()))\r\ndef SL(): return list(map(str, t().strip().split()))\r\ndef mat(n): return [IL() for i in range(n)]\r\ndef sieve(n): return reduce(lambda r, x: r - set(range(x**2, n, x)) if x in r else r, \r\n range(2, int(n**0.5) + 1), set(range(2,n)))\r\ndef iSq(x): return (ceil(float(sqrt(x))) == floor(float(sqrt(x))))\r\ndef ispow2(x): return ((x!=0) and (x&(x-1))==0)\r\ndef d2b(n):return bin(n).replace(\"0b\", \"\")\r\ndef ls(x,y): return x<<y # adding '0' y bits from right and removing last y bits from left i.e floor(x/pow(2,y)) \r\ndef rs(x,y): return x<<y # adding '0' y bits from left and removing first y bits from right i.e x*pow(2,y) \r\ndef powof2(x): return 1<<x \r\n\r\ns=sorted(S())[::-1]\r\nprev = s[0]\r\nfor i in s:\r\n if prev==i: print(i,end='')\r\n else: break\r\n prev=i ", "# import sys\r\n# sys.stdin = open(\"test.in\",\"r\")\r\n# sys.stdout = open(\"test.out\",\"w\")\r\na=list(map(ord,input()))\r\nb=max(a)\r\nprint(chr(b)*a.count(b))\r\n\r\n", "st = input()\r\nl = [ i for i in st]\r\nl.sort()\r\nn = len(st)\r\n\r\nstc = l[n-1]\r\n\r\nn1 = l.index(l[n-1])\r\n\r\nn2 = n - n1\r\nif n2 == 0:\r\n print(stc)\r\n \r\nelse:\r\n print(stc * n2)\r\n ", "s = input()\r\nans = sorted(s)\r\nans = ans[::-1]\r\nres = \"\"\r\nif (ans.count(ans[0]) == 1):\r\n print(ans[0])\r\nelse:\r\n print(ans[0]*ans.count(ans[0]))\r\n", "from collections import Counter\r\nc = Counter(input())\r\na = sorted(c,key = lambda x:x[0],reverse=True)[0]\r\nprint(a * (c[a]))", "from collections import Counter \r\ndic={}\r\ns=str(input())\r\ndic=Counter(s)\r\nfor i in sorted(dic,reverse=True):\r\n\tx=dic[i]\r\n\tc=i\r\n\tbreak\r\nfor i in range(x):\r\n\tprint(c,end=\"\")\r\n\r\n\r\n\r\n", "def largestPalinSub(s): \r\n \r\n res = \"\" \r\n mx = s[0] \r\n \r\n # Find the largest character \r\n for i in range(1, len(s)): \r\n mx = max(mx, s[i]) \r\n \r\n # Append all occurrences of largest \r\n # character to the resultant string \r\n for i in range(0, len(s)): \r\n if s[i] == mx: \r\n res += s[i] \r\n \r\n return res \r\n \r\n# Driver Code \r\nif __name__ == \"__main__\": \r\n \r\n s = input()\r\n print(largestPalinSub(s))", "s=input()\r\nl=set(s)\r\nm=max(l)\r\nprint(s.count(m)*m)", "s = ''.join(sorted(list(input()), reverse=True))\r\n\r\nprint(s[:s.rfind(s[0]) + 1])\r\n", "# LLPS\r\ns = input()\r\nch_max = None\r\nfor ch in s:\r\n if ch_max is None:\r\n ch_max = ch\r\n num = 1\r\n elif ch > ch_max:\r\n ch_max = ch\r\n num = 1\r\n elif ch == ch_max:\r\n num += 1\r\nprint(ch_max * num)", "s=input()\r\nc=max(s)\r\nk=s.count(c)\r\nprint(c*k)\r\n ", "input_string = input()\ninput_list = list(input_string)\ninput_list.sort(reverse=True)\nhigh_value = input_list[0]\ncount = 0\nfor v in input_list:\n if v == high_value:\n count = count + 1\nprint(high_value*count)\n\n\n\n\n\n", "z=input();i=max(z)\r\nprint(z.count(i)*i)", "s=input()\r\ni=max(s)\r\nv=s.count(i)\r\nprint(v*i)", "import sys\n\ninp = input()\n# Time: O(nlogn)\n'''\nstring_sorted = sorted(inp)\nllps = \"\"\nllps += string_sorted[len(string_sorted)-1]\nfor i in reversed(range(len(string_sorted)-1)):\n\tif(llps[-1] == string_sorted[i]):\n\t\tllps+=string_sorted[i]\n'''\n\nfreqs = [0]*26\nfor letter in inp:\n\tdecimal = ord(letter) - ord('a')\n\tfreqs[decimal]+=1\ngreater = -1\nfor i in reversed(range(len(freqs))):\n\tif(freqs[i] != 0):\n\t\tgreater = i\n\t\tbreak\nchar = chr(ord('a')+greater)\nllps = char*freqs[greater]\n\nprint(llps)\n\t\n", "s=list(input())\r\nm=max(s)\r\nc=s.count(m)\r\nprint(m*c)", "S = [(X) for X in input()]\r\nS.sort()\r\nX = S[-1]\r\nfor i in range (S.count(X)):\r\n\tprint (X,end=\"\")", "s=str(input())\r\nl=[]\r\nfor i in s:\r\n if i not in l:\r\n l.append(i)\r\nl.sort()\r\nchar=l[len(l)-1]\r\nh=s.count(char)\r\nstring=\"\"\r\nfor i in range(h):\r\n string=string+char\r\nprint(string)", "from itertools import combinations as c\r\ns=input()\r\nl=[]\r\nfor i in range(1,len(s)+1):\r\n a=list(set(c(s,i)))\r\n for j in a:\r\n if j==j[::-1]:\r\n l.append(j)\r\nl.sort()\r\nprint(\"\".join(l[-1]))", "s=list(map(ord,input()))\r\nm=max(s)\r\nk=s.count(m)\r\n# print(m,k)\r\nprint(chr(m)*k)", "s=input().strip()\r\nres=[]\r\nmx=s[0]\r\nfor i in range(1,len(s)):\r\n\tmx=max(mx,s[i])\r\nfor i in range(len(s)):\r\n\tif s[i]==mx:\r\n\t\tres.append(s[i])\r\nprint(''.join(res))", "a = list(input().strip())\r\nk = max(a)\r\nans = k*a.count(k)\r\nprint (ans)", "def palindromic_subseq(word):\n largest_char = sorted(word)[-1] \n return largest_char * (word.count(largest_char))\n\nword = input()\nprint(palindromic_subseq(word))", "word = str(input())\r\n\r\nl = ''\r\nmax_ord = 0\r\nfor char in word:\r\n if ord(char) > max_ord:\r\n max_ord = ord(char)\r\n l = char\r\ncount_char = 0\r\nfor char in word:\r\n if char == l:\r\n count_char+=1\r\n\r\nprint(''.join([l for _ in range(count_char)]))", "s=input()\r\nmax='A'\r\ncnt=0;\r\nfor i in s:\r\n if(i>max):\r\n max=i\r\n cnt=1\r\n elif(i==max):\r\n cnt+=1\r\nsc=max*cnt\r\nprint(sc)", "ni=input()\r\nli=list(ni)\r\nli.sort()\r\nprint(li[-1]*(li.count(li[-1])))\r\n", "str1 = input()\r\nl1 = list(str1)\r\nstr_max = max(l1)\r\nstr2 = \"\"\r\nfor i in l1:\r\n if i == str_max:\r\n str2 += i\r\nprint(str2)", "z=input();k=max(z);print(k*z.count(k))\r\n", "t = ''\r\nans = ''\r\n\r\ndef rec(d, s):\r\n global t, ans\r\n if d == len(t):\r\n if s == s[::-1] and s > ans:\r\n ans = s \r\n else:\r\n rec(d + 1, s)\r\n rec(d + 1, s + t[d])\r\n\r\nt = input()\r\nrec(0, '')\r\nprint(ans)", "import math\r\nimport cmath\r\nimport string\r\n\r\nresult = list(string.ascii_lowercase)\r\nresult.sort(reverse = True)\r\n\r\n\r\ndef XOR(n): return [n, 1, n + 1, 0][n % 4]\r\ndef isprime(n): return (all([False for i in range(2,n) if n % i == 0 ]) and not n < 2)\r\n\r\ndef c(lis,l,r,e):\r\n ans = 0\r\n while l<= r :\r\n m = (l+r)//2 \r\n if lis[m] > e :\r\n r = m-1\r\n else :\r\n l = m+1 \r\n ans = l\r\n return ans\r\naa = []\r\ndef f(l,i,j,n,m):\r\n c = l[i][j]\r\n i1 = i \r\n j1 = j\r\n i2 = i \r\n j2 = j\r\n i3 = i \r\n j3 = j\r\n i4 = i \r\n j4 = j\r\n while i1 > 0 and j1 > 0 :\r\n i1-=1 \r\n j1-=1 \r\n c+=l[i1][j1]\r\n while i2 < n-1 and j2 < m-1 :\r\n i2+=1\r\n j2+=1 \r\n c+=l[i2][j2]\r\n while i3 > 0 and j3 < m-1 :\r\n i3-=1 \r\n j3+=1 \r\n c+=l[i3][j3]\r\n while i4 < n-1 and j4 > 0 :\r\n i4+=1 \r\n j4-=1 \r\n c+=l[i4][j4]\r\n\r\n return c \r\n \r\n\r\n\r\n# for _ in range(int(input())):\r\nss = input()\r\nfor i in result :\r\n if i in ss :\r\n e = i \r\n break \r\ni = ss.count(e)\r\nprint(e*i)", "s = input()\r\nk = max(s)\r\nfinal = s.count(k)*k\r\n\r\nprint(final)", "'''\nA. LLPS\n\nhttps://codeforces.com/problemset/problem/202/A\n'''\nfrom collections import Counter\n\ns = input()\nd = Counter(s)\n\nkeys = list(d.keys())\nkeys.sort(reverse=True)\nprint(keys[0]*d[keys[0]])", "from itertools import groupby\r\ns=input()\r\ns=''.join(sorted(s,reverse=True))\r\nfor i,j in groupby(s):\r\n print(i*len(list(j)))\r\n break\r\n", "st = input()\nmaxChar = 'a'\nfor char in st:\n if maxChar < char:\n maxChar = char\n\nprint(maxChar * st.count(maxChar))\n", "#202A\r\nimport math\r\ndef getSubSequence(string):\r\n if len(string) == 0 :\r\n return [\"\"]\r\n else:\r\n temp = getSubSequence(string[1:len(string)])\r\n result = [\"\"] * 2 * len(temp)\r\n j = 0\r\n for i in range(0,len(temp)):\r\n result[j] = temp[i]\r\n j+=1\r\n for i in range(0,len(temp)):\r\n result[j] = string[0] + temp[i]\r\n j+=1 \r\n return result\r\n\r\nwhile(True):\r\n inputstr = input()\r\n length = len(inputstr)\r\n if(length <= 10 and inputstr.islower()):\r\n break\r\n\r\narr = getSubSequence(inputstr)\r\narr.pop(0)\r\n# print(arr)\r\n\r\narrrev = []\r\nfor i in arr:\r\n templen = len(i)\r\n inputstrrev = \"\"\r\n for j in range(templen-1,-1,-1):\r\n inputstrrev+= i[j]\r\n arrrev.append(inputstrrev)\r\n# print(arrrev) \r\nfinal = []\r\nfor i,j in zip(arr,arrrev):\r\n if(i == j):\r\n final.append(i)\r\n# print(final) \r\ntemp = final[0]\r\nfinalstr = \"\"\r\nfor i in final:\r\n if(i >= temp):\r\n temp = i\r\n finalstr = temp\r\nprint(finalstr)", "word=input()\r\nx=word[0]\r\nfin=''\r\nfor i in range(1,len(word)):\r\n x=max(x,word[i])\r\nfor i in range(0,len(word)):\r\n if x==word[i]:\r\n fin+=x\r\nprint(fin)", "n = input()\r\nhighest = max(n)\r\ntmp = n.count(highest)\r\nprint(highest*tmp)\r\n", "s=input()\r\nn=len(s)\r\nl=list(s)\r\nl.sort(reverse=True)\r\n\r\nres=\"\"\r\nfor i in range(0,n):\r\n if l[0]==l[i]:\r\n res+=l[i]\r\n else:\r\n break\r\n \r\nprint(res)", "s = input()\r\nprint(max(list(s)) * s.count(max(list(s))))\r\n", "I = lambda: int(input())\r\nIL = lambda: list(map(int, input().split()))\r\n\r\ns = list(input())\r\nprint(max(s) * s.count(max(s)))", "def largestpalinsub(s):\r\n\r\n res = \"\"\r\n mx = s[0]\r\n\r\n for i in range(1 , len(s)):\r\n mx = max(mx,s[i])\r\n\r\n for i in range(len(s)):\r\n if s[i] == mx :\r\n res += mx\r\n return res\r\n\r\ns = input()\r\n\r\nprint(largestpalinsub(s))\r\n\r\n\r\n\r\n\r\n\r\n", "n = input()\r\nl=list(n)\r\na = max(l)\r\nprint(l.count(a)*a)", "#\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\ns = string()\r\nmax_letter = s[0]\r\ncount = 1\r\nfor i in s[1:]:\r\n if i > max_letter:\r\n max_letter, count = i, 1\r\n elif i == max_letter:\r\n count += 1\r\n\r\nprint(max_letter*count)\r\n", "y=input()\r\nprint( max(y)*y.count(max(y)) )\r\n", "s = input()\r\nm = 'a'\r\nfor c in s:\r\n if c > m:\r\n m = c\r\nprint(m * s.count(m))", "s=input()\r\nx=list(s)\r\nx.sort()\r\ny=list(set(x))\r\ny.sort()\r\nk=x.index(y[len(y)-1])\r\nprint(*x[k:],sep='')", "s = input()\r\nk = max(s)\r\nl = list(s)\r\nm = l.count(k)\r\nprint(k*m, sep = \"\")", "def binary(n):\n values = []\n while n != 0:\n values.append(n % 2)\n n = n // 2\n\n return values\n\ndef powerset(x):\n result = []\n for i in range(2**len(x)):\n bit = binary(i)\n result.append(\"\".join([x[i] for i in range(len(bit)) if bit[i] == 1]))\n\n return result\n\ns = input()\nsubstrings = powerset(list(s))\n\nmaxi = substrings[0]\n\nfor string in substrings:\n if string == string[::-1]:\n maxi = max(maxi, string)\n\n\nprint(maxi)\n \t \t \t\t\t \t \t \t\t \t\t \t \t \t\t\t\t", "b=sorted([ord(a) for a in list(str(input()))],reverse=True)\r\nl=len([i for i in b if i==max(b)])\r\nfor i in range(l):\r\n print(chr(max(b)),end='')", "#this is my program\ns=input()\ns=sorted(s)\nprint(s[-1]*s.count(s[-1]))\n\t \t\t\t\t \t \t \t \t \t \t\t\t\t \t\t \t \t", "s = input()\r\nl = []\r\nfor i in s:\r\n l.append(ord(i))\r\nk = max(l)\r\nprint(chr(k)*s.count(chr(k)))", "def process(S):\r\n m = max(S)\r\n answer = ''\r\n for c in S:\r\n if c==m:\r\n answer = (answer+m)\r\n return answer\r\n \r\nS = input()\r\nprint(process(S))", "s = list(input())\r\nx = max(s)\r\nprint(x*s.count(x))", "string=str(input())\nl=list(string)\ns=set(string)\nif(l==s):\n\tprint(max(l))\nmxe=\"\"\nmxc=0\nfor i in s:\n\tif(i>mxe):\n\t\tmxe=i\nans=mxe*l.count(mxe)\nprint(ans)\n\t\t\n\t\t\n\t \t\t\t\t \t \t \t\t\t\t\t \t", "t = input()\r\nfor i in 'zyxwvutsrqponmlkjihgfedcba':\r\n if i in t:\r\n print(i * t.count(i))\r\n break", "s=sorted(list(input()))\r\nprint((s[-1])*s.count(s[-1]))", "s = input()\r\nn = len(s)\r\n\r\ns = sorted(s)\r\n\r\nlast = s[-1]\r\ncount = 1\r\n\r\nfor i in range(n - 2, -1, -1):\r\n if last == s[i]:\r\n count += 1\r\n else:\r\n break\r\n\r\nprint(last * count)\r\n", "s = input()\r\nn = len(s)\r\nmx = s[0]\r\nres = \"\"\r\n# mx assign max ascii number char\r\nfor i in range(1, n):\r\n mx = max(mx, s[i])\r\n\r\n# if same as mx is exist then append it for make lexicographically largest palindromic subsequence\r\nfor i in range(0, n):\r\n if mx == s[i]:\r\n res += s[i]\r\n\r\nprint(res)\r\n", "# your code goes here\r\nc = input() ; m = max(c) ; print(m * c.count(m));", "from itertools import combinations\r\ns=input()\r\nw=''\r\nq=''\r\nt=''\r\nf=''\r\nfor i in range(len(s)):\r\n perm=combinations(s,(i+1))\r\n w=list(max(list(perm)))\r\n for j in w:\r\n q=q+str(j)\r\n\r\n for k in q:\r\n t=k+t\r\n if t==q and t>f:\r\n f=q\r\n t=''\r\n q=''\r\n\r\n\r\nprint(f)\r\n", "k=input()\r\ns=[]\r\nfor i in k:\r\n if i not in s:\r\n s.append(i)\r\ns.sort()\r\nw=s[-1]\r\ne=k.count(w)\r\nprint(w*e)", "lst = list(input())\r\n\r\n\r\nalphabets = 'abcdefghijklmnopqrstuvwxyz'\r\n\r\nalpha = list(alphabets)\r\n\r\ni = 25\r\nwhile i>-1:\r\n if alpha[i] in lst:\r\n break\r\n i -= 1\r\na = alpha[i]\r\ncount = 0\r\nfor j in lst:\r\n if a == j:\r\n count+=1\r\nprint(a*count)\r\n\r\n\r\n", "string = sorted(input())\r\n\r\nchar = string[-1]\r\ncnt = string.count(char)\r\nprint(char*cnt)", "from itertools import accumulate, product\r\n\r\nimport math\r\n\r\nR = lambda: map(int, input().split())\r\ns = input()\r\nres = ''\r\nfor m in product(range(2), repeat=len(s)):\r\n ts = ''.join(c if mi else '' for c, mi in zip(s, m))\r\n if ts == ts[::-1] and ts > res:\r\n res = ts\r\nprint(res)", "n=list(input())\r\nx=max(n)\r\nprint(n.count(x)*x)", "t=sorted(str(input()),reverse=True)\r\ni=0\r\nwhile i<len(t) and t[0]==t[i]:\r\n print(t[i],end='')\r\n i+=1", "s = input()\r\ns = sorted(s)\r\nprint(s[-1]*s.count(s[-1]))", "s=input()\r\np=sorted(s, reverse=True)\r\nfor i in p:\r\n if i==p[0]:\r\n print(i, end='')", "s = input()\r\nq = max(s)\r\nprint(q*s.count(q))\r\n", "n=input()\r\nt=max(n)\r\nprint(n.count(t)*t)\r\n\r\n", "s=input()\r\nmaxi=0\r\nmk=''\r\nfor i in s:\r\n if ord(i)>maxi:\r\n maxi=ord(i)\r\n mk=i\r\nk=0\r\nfor i in s:\r\n if i==mk:\r\n k+=1\r\n\r\nprint(mk*k)\r\n", "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nimport decimal\r\ninput=sys.stdin.readline\r\ns=input()\r\nn=len(s)\r\ns=s[:n-1]\r\nprint(max(s)*s.count(max(s)))", "def palin(s):\r\n if s == s[::-1]:\r\n return True\r\n else:\r\n return False\r\n\r\ndef substring(s, output, lis):\r\n if len(s) == 0:\r\n lis.append(output)\r\n return \r\n substring(s[1:], output + s[0], lis)\r\n substring(s[1:], output, lis)\r\n\r\ns = input()\r\nlis = []\r\nsubstring(s, '', lis)\r\nnew = []\r\nfor i in lis:\r\n if palin(i):\r\n new.append(i)\r\nnew.sort()\r\n# print(new)\r\nprint(new[-1])\r\n", "s=input()\r\nl={\"\"}\r\nfor i in s:\r\n q=set()\r\n for j in l:\r\n q.add(j+i)\r\n l|=q\r\nq=set()\r\nfor i in l:\r\n o=len(i)\r\n for j in range(o//2):\r\n if i[j]!=i[o-1-j]:\r\n q.add(i)\r\n break\r\nfor i in q:l.discard(i)\r\nprint(max(l))", "s = input()\r\nc = max(s)\r\nprint(c * s.count(max(s)))", "# cook your dish here\r\n#import sys\r\n#input=sys.stdin.readline\r\n #JAI SHREE RAM #HAR HAR MAHADEV #JAI BAJRANG BALI\r\nm=input()\r\nk=sorted(m)\r\na=m.count(k[-1])\r\nwhile a>0:\r\n print(k[-1],end='')\r\n a-=1\r\n \r\n", "def main():\n\tstring = input()\n\tstring = sorted(string)\n\tl = len(string)\n\tprint(string[l-1]*string.count(string[l-1]))\n\nif __name__ == '__main__':\n\tmain()", "#coding=utf-8\n'''\nCreated on 2016年7月11日\n\n@author: root\n'''\ns=input()\nl=list(s)\nl.sort()\ns=\"\".join(l)\ni=len(s)-1\nk=i\nans=s[i]\n#print(s[i])\ni=i-1\nwhile i>=0 and s[i]==s[k]:\n ans+=s[i]\n# print(s[i])\n i-=1\nprint(ans)\n\t \t\t \t\t \t\t\t \t\t \t\t\t\t \t", "w=input()\r\na=max(w);print(w.count(a)*a)\r\n", "n=input()\r\np=sorted(n)\r\nq=p.count(p[-1])\r\nprint(p[-1]*q)", "from collections import defaultdict\r\nn=input()\r\na=defaultdict(lambda:0)\r\nfor i in n:\r\n a[i]+=1\r\nx=list(a.keys())\r\nx.sort(reverse=True)\r\nprint(x[0]*a[x[0]])\r\n", "#LLPS\r\nstring = input()\r\nchar = string[0]\r\nfor i in range(len(string)-1):\r\n if(ord(char)<ord(string[i+1])):\r\n char = string[i+1]\r\n\r\nprint(char*string.count(char))\r\n\r\n\r\n", "s = input()\r\nmx = max(s)\r\nprint(mx*s.count(mx))", "s = ''.join(sorted(input()))[::-1]\r\nprint(''.join(i for i in s if i == s[0]))", "s=input(\"\")\r\nl=[]\r\nans=[]\r\nt=0\r\nc=0\r\nfor i in (s):\r\n \r\n l.append(ord(i))\r\nt=max(l)\r\nt=chr(t)\r\n#print(t)\r\nfor i in s:\r\n if t==i:\r\n c+=1\r\n # print(c)\r\n \r\nprint(t*c)\r\n \r\n\r\n", "st =sorted(input(),reverse=True);\r\nprint(st.count(st[0]) * st[0])", "s = sorted(input())\r\nmax = s[-1]\r\nt = s.count(max)\r\nprint(max * t)", "from math import *\r\ns=input()\r\nm=max(s)\r\nprint(s.count(m)*m)", "#Main idea\r\n#Note that if c is the lexicographically largest character of the string, then\r\n#the answer is just spamming c as much as possible\r\n\r\n#For fast I/O\r\nimport sys\r\ninput = lambda: sys.stdin.readline().strip()\r\n\r\ns = input()\r\nc = max(s)\r\nn = s.count(c)\r\nprint(c*n)\r\n", "s=input()\r\nk=list(set(s))\r\nk.sort()\r\nprint(k[-1]*s.count(k[-1]))\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Nov 20 09:15:20 2020\r\n\r\n\"\"\"\r\n\r\ninp_str = str(input())\r\np_str = ''\r\n\r\nwhile len(inp_str) > 0:\r\n \r\n max_let = max(inp_str)\r\n l_idx = None\r\n r_idx = None\r\n for i in range(len(inp_str)):\r\n if inp_str[i] == max_let:\r\n l_idx = i\r\n break\r\n for j in reversed(range(len(inp_str))):\r\n if inp_str[j] == max_let:\r\n r_idx = j\r\n break\r\n \r\n inp_str = inp_str[i+1:j]\r\n \r\n if i == j:\r\n if p_str == '':\r\n print(max_let)\r\n elif max_let >= p_str[-1]:\r\n print(p_str + max_let + p_str[-1::-1])\r\n else: \r\n print(p_str + p_str[-1::-1]) \r\n else:\r\n if p_str == '':\r\n p_str += max_let\r\n elif max_let >= p_str[-1]:\r\n p_str += max_let\r\n \r\n if len(inp_str) == 0:\r\n print(p_str + p_str[-1::-1])", "x=input();\nj=max(x);\nprint(x.count(j)*j)\n\t \t \t\t\t \t\t\t\t \t\t \t \t\t\t\t\t\t \t", "import sys\ninput = sys.stdin.readline\n\ns = input().rstrip()\nlen_s = len(s)\n\nmax_ = ''\nfor mask in range(1<<len_s):\n subseq = ''\n for i in range(len_s):\n if mask>>i&1:\n subseq += s[i]\n if subseq == subseq[::-1] and subseq > max_:\n max_ = subseq\nprint(max_)\n", "a = input()\r\nlist1 = []\r\ncount = 0\r\nfor i in a:\r\n list1 += [ord(i)]\r\n \r\nf = max(list1)\r\nb = a.count(chr(f))\r\nx = str(chr(f))*b\r\nprint(x)\r\n ", "s=str(input())\r\nc=max(s)\r\nprint(c*s.count(c))\r\n", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\ns = sorted(input().rstrip())\r\nprint(s[-1] * s.count(s[-1]))", "n = input()\r\nl = max(n)\r\nnum = n.count(l)\r\nprint(l*num)", "s = input()\r\na = [chr(i) for i in range(122,96,-1)]\r\nfor i in a:\r\n if s.count(i) > 0:\r\n print(i*s.count(i))\r\n break", "def get_all_subsequences(string): \r\n if len(string) == 0: \r\n return [''] \r\n \r\n first_char = string[0] \r\n remaining_subsequences = get_all_subsequences(string[1:]) \r\n current_subsequences = [] \r\n \r\n for subsequence in remaining_subsequences: \r\n current_subsequences.append(subsequence) \r\n current_subsequences.append(first_char + subsequence) \r\n \r\n return current_subsequences\r\nslist = get_all_subsequences(input())\r\ncounter = 1\r\nv = 0\r\nfor i in range(len(slist)):\r\n rs = slist[i][::-1]\r\n if slist[i] == rs and i != 1:\r\n for j in range(min(len(slist[i]),len(slist[counter]))):\r\n if ord(slist[i][j]) < ord(slist[counter][j]):\r\n break\r\n elif ord(slist[i][j]) > ord(slist[counter][j]):\r\n counter = i\r\n break\r\n elif ord(slist[i][j]) == ord(slist[counter][j]):\r\n v +=1\r\n if v == min(len(slist[i]),len(slist[counter])):\r\n if len(slist[i]) > len(slist[counter]):\r\n counter = i\r\n v = 0\r\nprint(slist[counter])", "word = sorted(list(input()), reverse=True)\r\nc = word.count(word[0])\r\nprint(word[0] * c)\r\n", "string=input()\r\nch=' '\r\nfor i in string:\r\n if ch==' ':\r\n ch=i\r\n elif ch<i:\r\n ch=i\r\nans=\"\"\r\nfor i in string:\r\n if ch==i:\r\n ans+=ch\r\nprint(ans)", "s = input()\r\nanswer = \"\"\r\nsmax = s[0]\r\nfor i in range(1,len(s)):\r\n if s[i] > smax:\r\n smax = s[i]\r\nfor i in s:\r\n if i == smax:\r\n answer += i \r\nprint(answer)\r\n", "\"\"\"\r\n\r\nAuthor : Preet Modh \r\n\r\n\"\"\"\r\nimport sys,os\r\nfrom difflib import SequenceMatcher\r\nfrom collections import Counter\r\nfrom bisect import bisect_left as bl,bisect_right as br\r\nfrom io import BytesIO, IOBase\r\nfrom itertools import accumulate\r\nimport math\r\n\r\n\"\"\" \r\n\r\n**All function calls:**\r\n\r\nLCSubstr(a,b): for Longest Common Substring\r\ngcd(x, y): greatest common divisor of x and y\r\nprime_factors(n): Number of prime factor of n\r\ndistinct_factors(n): list of distinct factors of n\r\nall_factors(n): list of all factors of n\r\nis_prime(n): checks if n is prime\r\nprime_list(n): all primes less than number of\r\nmodinv(a, m): modular inverse of a w.r.t. to m, works when a and m are coprime\r\nmake_nCr_mod()(n,r) value of ncr%mod\r\nbinarySearch(arr, l, r, x): binary search \r\nPrefixSum(arr): prefix sum array\r\nmemodict(f): Memoization decorator for a function taking a single argument\r\nmemoize(f): Memoization decorator for a function taking one or more arguments\r\n\r\n\"\"\"\r\n\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\n\r\ndef memodict(f):\r\n \"\"\" Memoization decorator for a function taking a single argument. \"\"\"\r\n class memodict(dict):\r\n def __missing__(self, key):\r\n ret = self[key] = f(key)\r\n return ret\r\n\r\n return memodict().__getitem__\r\n\r\n\r\ndef memoize(f):\r\n \"\"\" Memoization decorator for a function taking one or more arguments. \"\"\"\r\n class memodict(dict):\r\n def __getitem__(self, *key):\r\n return dict.__getitem__(self, key)\r\n\r\n def __missing__(self, key):\r\n ret = self[key] = f(*key)\r\n return ret\r\n\r\n return memodict().__getitem__\r\n\r\n\r\nLCSubstr = lambda a, b:SequenceMatcher(None, a, b).find_longest_match(0, len(a), 0, len(b))\r\n\"\"\" THIS IS FOR for Longest Common Substring \"\"\"\r\n\r\n\r\ndef gcd(x, y):\r\n \"\"\"greatest common divisor of x and y\"\"\"\r\n while y:\r\n x, y = y, x % y\r\n return x\r\n\r\n\r\ndef pollard_rho(n):\r\n \"\"\"returns a random factor of n\"\"\"\r\n if n & 1 == 0:\r\n return 2\r\n if n % 3 == 0:\r\n return 3\r\n\r\n s = ((n - 1) & (1 - n)).bit_length() - 1\r\n d = n >> s\r\n for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:\r\n p = pow(a, d, n)\r\n if p == 1 or p == n - 1 or a % n == 0:\r\n continue\r\n for _ in range(s):\r\n prev = p\r\n p = (p * p) % n\r\n if p == 1:\r\n return gcd(prev - 1, n)\r\n if p == n - 1:\r\n break\r\n else:\r\n for i in range(2, n):\r\n x, y = i, (i * i + 1) % n\r\n f = gcd(abs(x - y), n)\r\n while f == 1:\r\n x, y = (x * x + 1) % n, (y * y + 1) % n\r\n y = (y * y + 1) % n\r\n f = gcd(abs(x - y), n)\r\n if f != n:\r\n return f\r\n return n\r\n\r\n@memodict\r\ndef prime_factors(n):\r\n \"\"\"returns a Counter of the prime factorization of n\"\"\"\r\n if n <= 1:\r\n return Counter()\r\n f = pollard_rho(n)\r\n return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)\r\n\r\n\r\ndef distinct_factors(n):\r\n \"\"\"returns a list of all distinct factors of n\"\"\"\r\n factors = [1]\r\n for p, exp in prime_factors(n).items():\r\n factors += [p**i * factor for factor in factors for i in range(1, exp + 1)]\r\n return factors\r\n\r\n\r\ndef all_factors(n):\r\n \"\"\"returns a sorted list of all distinct factors of n\"\"\"\r\n small, large = [], []\r\n for i in range(1, int(n**0.5) + 1, 2 if n & 1 else 1):\r\n if not n % i:\r\n small.append(i)\r\n large.append(n // i)\r\n if small[-1] == large[-1]:\r\n large.pop()\r\n large.reverse()\r\n small.extend(large)\r\n return small\r\n\r\ndef is_prime(n):\r\n \"\"\"returns True if n is prime else False\"\"\"\r\n if n < 5 or n & 1 == 0 or n % 3 == 0:\r\n return 2 <= n <= 3\r\n s = ((n - 1) & (1 - n)).bit_length() - 1\r\n d = n >> s\r\n for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:\r\n p = pow(a, d, n)\r\n if p == 1 or p == n - 1 or a % n == 0:\r\n continue\r\n for _ in range(s):\r\n p = (p * p) % n\r\n if p == n - 1:\r\n break\r\n else:\r\n return False\r\n return True\r\n\r\ndef prime_sieve(n):\r\n \"\"\"returns a sieve of primes >= 5 and < n\"\"\"\r\n flag = n % 6 == 2\r\n sieve = bytearray((n // 3 + flag >> 3) + 1)\r\n for i in range(1, int(n**0.5) // 3 + 1):\r\n if not (sieve[i >> 3] >> (i & 7)) & 1:\r\n k = (3 * i + 1) | 1\r\n for j in range(k * k // 3, n // 3 + flag, 2 * k):\r\n sieve[j >> 3] |= 1 << (j & 7)\r\n for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):\r\n sieve[j >> 3] |= 1 << (j & 7)\r\n return sieve\r\n\r\n\r\ndef prime_list(n):\r\n \"\"\"returns a list of primes <= n\"\"\"\r\n res = []\r\n if n > 1:\r\n res.append(2)\r\n if n > 2:\r\n res.append(3)\r\n if n > 4:\r\n sieve = prime_sieve(n + 1)\r\n res.extend(3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not (sieve[i >> 3] >> (i & 7)) & 1)\r\n return res\r\n \r\n\r\n\r\n\r\ndef extended_gcd(a, b):\r\n \"\"\"returns gcd(a, b), s, r s.t. a * s + b * r == gcd(a, b)\"\"\"\r\n s, old_s = 0, 1\r\n r, old_r = b, a\r\n while r:\r\n q = old_r // r\r\n old_r, r = r, old_r - q * r\r\n old_s, s = s, old_s - q * s\r\n return old_r, old_s, (old_r - old_s * a) // b if b else 0\r\n\r\n\r\ndef modinv(a, m):\r\n \"\"\"returns the modular inverse of a w.r.t. to m, works when a and m are coprime\"\"\"\r\n g, x, _ = extended_gcd(a % m, m)\r\n return x % m if g == 1 else None\r\n\r\n\r\ndef make_nCr_mod(max_n=2 * 10**5, mod=10**9 + 7):\r\n max_n = min(max_n, mod - 1)\r\n\r\n fact, inv_fact = [0] * (max_n + 1), [0] * (max_n + 1)\r\n fact[0] = 1\r\n for i in range(max_n):\r\n fact[i + 1] = fact[i] * (i + 1) % mod\r\n\r\n inv_fact[-1] = pow(fact[-1], mod - 2, mod)\r\n for i in reversed(range(max_n)):\r\n inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod\r\n\r\n def nCr_mod(n, r):\r\n res = 1\r\n while n or r:\r\n a, b = n % mod, r % mod\r\n if a < b:\r\n return 0\r\n res = res * fact[a] % mod * inv_fact[b] % mod * inv_fact[a - b] % mod\r\n n //= mod\r\n r //= mod\r\n return res\r\n\r\n return nCr_mod\r\n \"\"\" \r\n To use:\r\n x=make_nCr_mod()\r\n print(x(n,r))\r\n \"\"\"\r\n\r\ndef binarySearch(arr, l, r, x):\r\n \r\n while l <= r:\r\n mid = l + (r - l) // 2\r\n if arr[mid] == x:\r\n return mid\r\n\r\n elif arr[mid] < x:\r\n l = mid + 1\r\n \r\n r = mid - 1\r\n \r\n return -1\r\n\r\n\r\n \r\ndef PrefixSum(arr):\r\n return list(accumulate(arr))\r\n \r\n \r\nclass inputs:\r\n #To handle different inputs\r\n def single(self):\r\n return int(input())\r\n def mul(self):\r\n return map(int,input().split())\r\n def list(self):\r\n return list(map(int,input().split()))\r\n\r\ninp=inputs()\r\n########################################################\r\n\r\n\r\n\r\n\r\n\r\ndef main():\r\n s=input()\r\n print(max(s)*(s.count(max(s))))\r\n\r\nif __name__ == \"__main__\":\r\n main()", "# A. LLPS\n\n# Solution - https://codeforces.com/contest/202/submission/14918834\nz = input()\nj = max(z)\nprint(z.count(j)*j)\n", "n=input()\r\na=[]\r\nfor i in n:\r\n a.append(i)\r\na.sort()\r\nm=max(a)\r\nprint(a.count(m)*m)", "lst = list(input())\r\nanswer = lst.count(max(lst)) * max(lst)\r\nprint(answer)", "t=input()\r\nmax='a'\r\nfor i in t:\r\n if i>max:\r\n max=i\r\ns=''\r\nfor i in t:\r\n if i==max:\r\n s=s+max\r\nprint(s)", "def llps(s):\r\n max_char = max(list(s))\r\n return ''.join([max_char] * s.count(max_char))\r\n\r\nprint(llps(input()))", "s = input()\r\n\r\nl = list(s)\r\n\r\nn = max(l)\r\n\r\ncount = 0\r\n\r\nfor i in range(0,len(l)):\r\n if l[i]==n:\r\n count = count + 1\r\n \r\nfor i in range(0,count):\r\n print(n,end='')", "a=input()\r\nw=sorted(a)\r\ne=w[-1]\r\ns=0\r\nfor i in a:\r\n if i in e:\r\n s+=1\r\nprint(s*e)\r\n", "import itertools\r\n\r\ndef Sub_Sequences(STR):\r\n combs=[]\r\n for l in range(1,len(STR)+1):\r\n combs.append(list(itertools.combinations(STR,l)))\r\n strings=[] \r\n for c in combs:\r\n strings.extend([''.join(i) for i in c])\r\n return strings\r\n\r\nsubs=[]\r\ninput_string=input()\r\nsubs=Sub_Sequences(input_string)\r\n\r\npals=[]\r\nfor i in subs:\r\n if i==i[::-1]:\r\n pals.append(i)\r\n\r\nsort=sorted(pals)\r\n\r\nprint(sort[len(sort)-1])\r\n\r\n", "s = input()\r\n\r\ncount = 1\r\nmax_char = s[0]\r\n\r\nfor i in range(1, len(s)):\r\n if ascii(s[i]) > ascii(max_char):\r\n max_char = s[i]\r\n count = 1\r\n elif s[i] == max_char:\r\n count += 1\r\n\r\nprint(max_char * count)\r\n", "import itertools as it\r\n\r\n\r\ns = input()\r\nb, p = [0] * len(s), set()\r\n\r\nwhile True:\r\n if b.count(0) == 0:\r\n break\r\n else:\r\n i = b.index(0)\r\n b[:i + 1] = [0] * i + [1]\r\n p.add(''.join(it.compress(s, b)))\r\n\r\nprint(max(filter(lambda s: s == s[::-1], p)))\r\n", "from itertools import combinations\ns = str(input())\ncom = []\nfor i in range(1,len(s) + 1):\n com.append(list(combinations(s,i)))\narr = [''.join(j) for i in com for j in i]\n\nn_arr = []\nfor i in arr:\n if i == i[::-1]:\n n_arr.append(i)\n\n\nprint(max(n_arr))\n\n\n", "from sys import stdin,stdout\r\nimport math,bisect\r\nfrom collections import Counter,deque,defaultdict\r\nL=lambda:list(map(int, stdin.readline().strip().split()))\r\nM=lambda:map(int, stdin.readline().strip().split())\r\nI=lambda:int(stdin.readline().strip())\r\nS=lambda:stdin.readline().strip()\r\nC=lambda:stdin.readline().strip().split()\r\ndef pr(a):return(\" \".join(list(map(str,a))))\r\n#_________________________________________________#\r\n\r\ndef solve():\r\n s = S()\r\n print(s.count(max(s))*max(s))\r\nfor _ in range(1):\r\n solve()\r\n\r\n", "word = input()\r\nprint(word.count(max(word))*max(word))", "s = list(input())\r\nmaximum_char = max(s)\r\nans = maximum_char * s.count(maximum_char)\r\nprint(ans)\r\n", "s= input()\r\nx= max(s)\r\nn= s.count(x)\r\nprint(n*x)", "from collections import Counter \r\nn=list(input())\r\ndict1=dict(Counter(n))\r\nlist1=list(dict1.keys())\r\nlist1.sort(reverse=True)\r\na=list1[0]\r\nprint(a*dict1[a])\r\n", "def makePalindromic(s, duplicateLast):\n if duplicateLast:\n return s+s[::-1]\n else:\n return s + s[-2::-1]\n\ndef findLargest(inp):\n maxLetter = max(inp)\n return maxLetter, inp.index(maxLetter), inp.rindex(maxLetter)\n \ndef findSequence(inp):\n seq = \"\"\n while 1:\n if inp==\"\": return makePalindromic(seq, True)\n l, mi, ma = findLargest(inp)\n if seq==\"\" or l>=seq[-1]:\n seq += l\n if mi==ma: return makePalindromic(seq, False)\n inp = inp[mi+1:ma]\n else:\n return makePalindromic(seq, True)\n\ninp = input()\nprint(findSequence(inp))\n\n \t\t\t\t \t\t \t \t\t\t \t\t\t \t\t \t", "from sys import stdin\r\n\r\ndef sol(s):\r\n m = max(s)\r\n return m * s.count(m)\r\n\r\nstring = stdin.readline().strip()\r\nprint(sol(string))", "message = input()\r\nprint(max(message) * message.count(max(message)))", "s=input()\r\na=sorted(s)\r\n#print(a)\r\ne=''\r\nfor i in range(1,len(a)):\r\n if(a[i-1]==a[i]):\r\n e+=a[i-1]\r\n else:\r\n e=''\r\nprint(e+a[-1])\r\n", "def solve(s):\r\n ans = \"\"\r\n s1 = sorted(s)\r\n while len(s) > 0:\r\n index = s.find(s1[-1])\r\n if index == -1:\r\n break\r\n ans = ans + s1[-1]\r\n s = s[index+1:]\r\n return ans\r\ns = input()\r\nprint(solve(s))", "s = input()\nsub = ''\nlargest = 0\nl = len(s)\nfor i in range(l):\n ascVal = ord(s[i])\n if (ascVal > largest):\n largest = ascVal\n\nlargest = chr(largest)\n\nfor i in range(l):\n if s[i] == largest:\n sub = sub + largest\n\nprint(sub)\n", "def largest_alphabet(a, n) :\r\n maxi = 'A'\r\n for i in range(n) :\r\n if (a[i] > maxi):\r\n maxi = a[i]\r\n return maxi\r\n\r\nstrin=input(\"\")\r\nsize=len(strin)\r\nz=largest_alphabet(strin,size)\r\nfor i in strin:\r\n if(i == z):\r\n print(z,end='')\r\n", "#!/usr/bin/python3.5\r\ns=input()\r\nk=max(s)\r\nprint(s.count(k)*k)", "string = input()\r\ndic = {}\r\nfor str in string:\r\n if str not in dic:\r\n dic[str] = 0\r\n dic[str]+=1\r\n\r\nans = 'a'\r\nfor key in dic:\r\n if key>ans:\r\n ans = key\r\n\r\nprint(ans*dic[ans])", "s = input('')\r\nlargest = 'a'\r\nans = []\r\n\r\nfor c in s:\r\n if ord(c) > ord(largest):\r\n largest = c\r\n\r\nfor c in s:\r\n if c == largest:\r\n ans.append(c)\r\n\r\nprint(''.join(ans))", "s = input()\r\np = sorted(set(s))[-1]\r\nprint(s.count(p)*p)", "a = str(input())\nb = max(a)\nA = []\nfor i in range(len(a)):\n if a[i] == b:\n A.append(b)\n\nprint(''.join(A))\n\t \t\t\t \t \t \t\t \t\t\t\t \t\t\t\t\t \t \t", "string = input()\r\nm = max(string)\r\nprint(m * string.count(m))", "s=input()\r\nar=[ ]\r\nans=''\r\nfor i in range(0,len(s)):\r\n ar.append(ord(s[i]))\r\nk=max(ar)\r\nfor i in range(0,len(s)):\r\n if(ord(s[i])==max(ar)):\r\n ans+=s[i]\r\nprint(ans)", "#5\n# answer = list(map(int, input().split()))\n# n, m, count = answer[0], answer[1], 0\n\n# for a in range(1000):\n# for b in range(1000):\n# if a*a + b == n and a + b*b == m:\n# count +=1\n# print(count)\n\n\nanswer = list(input())\ndict = {}\nfor i in answer:\n dict[i] = answer.count(i)\nmax_letter = sorted(dict)\nfinal = max_letter[-1]*dict[max_letter[-1]]\n\nprint(final)", "import itertools\r\ns=input()\r\ncombs=[]\r\nl=[]\r\nfor i in range(len(s)+1):\r\n combs.append(list(itertools.combinations(s,i)))\r\n for c in combs:\r\n for t in c:\r\n l.append(''.join(t))\r\nl1=[]\r\nfor i in l:\r\n if i==i[::-1]:\r\n l1.append(i)\r\ns1=set(l1)\r\nl1=list(s1)\r\nl1.sort()\r\nprint(l1[-1])\r\n", "s=input();x=max(s);print(s.count(x)*x)", "s = input()\r\nans = max(s)\r\nprint(s.count(ans)*ans)", "s=input()\nmx=s[0]\nres=\"\"\nfor i in s:\n mx=max(mx,i)\nfor i in s:\n if mx==i:\n res+=i\nprint(res)", "import sys\r\n\r\ninput = lambda: sys.stdin.readline().strip()\r\n\r\ns = input()\r\n\r\nres = ''\r\nfor mask in range(1, 1 << len(s)):\r\n cur = []\r\n for i in range(len(s)):\r\n if mask & (1 << i):\r\n cur.append(s[i])\r\n cur = ''.join(cur)\r\n if cur == cur[::-1] and cur > res:\r\n res = cur\r\n\r\nprint(res)", "def llps(s):\r\n h = s[0]\r\n for letter in s[1:]:\r\n if letter > h:\r\n h = letter\r\n newString = ''\r\n for i in range(s.count(h)):\r\n newString += h\r\n \r\n return newString\r\n \r\n \r\nif __name__ == \"__main__\":\r\n print(llps(input()))", "\r\n\r\nans = \"\"\r\n\r\ns = input()\r\n\r\ndef isPalindrome(s):\r\n return( s[:len(s)//2] == s[ (len(s)+1)//2 : ] )\r\n\r\nfor i in range( 1, pow(2,len(s)) ):\r\n\r\n check = \"\"\r\n\r\n for j in range( len(s) ):\r\n\r\n if i&(pow(2,j)):\r\n check += s[j]\r\n\r\n if isPalindrome( check ):\r\n\r\n if ans == \"\":\r\n ans = check\r\n else:\r\n ans = max( ans, check )\r\n\r\nprint(ans)\r\n", "string = input()\r\nsubstrings = []\r\n\r\ndef generate_substrings(string, idx, chars):\r\n if idx >= len(string):\r\n substrings.append(\"\".join(chars[:]))\r\n else:\r\n chars.append(string[idx])\r\n generate_substrings(string, idx+1, chars)\r\n chars.pop()\r\n generate_substrings(string, idx+1, chars)\r\n\r\ngenerate_substrings(string, 0, [])\r\n\r\nllps = \"\"\r\n\r\nfor substring in substrings:\r\n if substring == substring[::-1] and llps < substring:\r\n llps = substring\r\n\r\nprint(llps)", "s = input()\r\nlargest = max(s)\r\ncount = s.count(largest)\r\nprint(largest * count)", "s = input()\nn = len(s)\nl = []\nfor i in range(1,2**n):\n t,j,p = i,0,[]\n while(t > 0):\n if(t&1):\n p.append(s[j])\n j += 1\n t >>= 1\n if(p == p[::-1] and l < p):\n l = p\nprint(*l,sep=\"\")\n\t \t\t\t \t\t\t\t \t \t\t\t\t\t \t", "# Anuneet Anand\n\ns = input()\nn = len(s)\n\nT = []\nfor i in range(2**n):\n\tb = bin(i)[2:]\n\tb = (n-len(b))*\"0\"+b\n\tt = \"\"\n\tfor i in range(n):\n\t\tif int(b[i]):\n\t\t\tt+=s[i]\n\tif t == t[::-1]:\n\t\tT.append(t)\n\nT.sort(reverse=True)\nprint(T[0])", "a = input()\r\n\r\nmax = 0\r\nfor i in a:\r\n if(ord(i) > max):\r\n max = ord(i)\r\nk = chr(max)\r\nz = 0\r\nfor i in a:\r\n if i == k:\r\n z += 1\r\nfor i in range(z):\r\n print(k, end='')\r\n", "s=input()\r\n \r\nstart=max(s)\r\n \r\nx=s.count(start)\r\n \r\nfor i in range(x):\r\n print(start,end=\"\")", "\r\ndef LLPS(s):\r\n res = \"\"\r\n mx = s[0]\r\n for i in range(1, len(s)):\r\n mx = max(mx, s[i])\r\n for i in range(0, len(s)):\r\n if s[i] == mx:\r\n res += s[i]\r\n return res\r\ns = input()\r\nprint(LLPS(s))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "from string import ascii_lowercase\r\n\r\n\r\ndef main():\r\n string = input()\r\n\r\n answer_string = \"\"\r\n for test_character in reversed(ascii_lowercase):\r\n if test_character in string:\r\n answer_string = test_character * string.count(test_character)\r\n break\r\n\r\n print(answer_string)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "s = input()\nprint(max(s) * s.count(max(s)))", "import math,sys,collections,bisect\n\n\ndef natural(n):\n\treturn n*(n+1)//2\n\ndef binarysearch(l,r,n,k):\n\tif l<=r:\n\t\tmid = (l+r)//2\n\t\tif mid*n<=k:\n\t\t\treturn binarysearch(mid+1,r,n,k)\n\t\treturn binarysearch(l,mid-1,n,k)\n\treturn r\n\n\ndef rec(s,i,st,m):\n\tif i == len(s):\n\t\tif st == st[::-1]:\n\t\t\tm[0] = max(m[0],st)\n\t\treturn\n\trec(s,i+1,st,m)\n\trec(s,i+1,st+s[i],m)\n\ndef solve():\n\n\ts = input()\n\tm = ['']\n\trec(s,0,'',m)\n\tprint(m[0])\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n# number of test cases\n\n\n#t = int(input())\nt = 1\nfor i in range(t):\n\tsolve()\n\n\n\n\n\n\n\n\n\n", "v = input()\nx = ''.join(sorted(v))\nc = x.count(x[-1])\nprint(x[-1] * c)\n", "s=input()\r\nz=\"a\"\r\nfor x in s:\r\n if x>z:\r\n z=x\r\nc=0\r\nfor x in s:\r\n if x==z:\r\n c+=1\r\nprint(z*c) ", "a=list(input())\r\nb=a.count(max(a))\r\n[print(max(a),end='') for x in range(b)]", "s = ''.join(sorted(input(), reverse=True))\r\n\r\nprint(s[:s.rfind(s[0]) + 1])\r\n", "def LLPS():\r\n a=input()\r\n maxx = max(a)\r\n c = a.count(maxx)\r\n print(maxx*c)\r\nLLPS()\r\n", "from itertools import combinations\r\ns = input()\r\narr = []\r\nfor i in range(len(s)+1) :\r\n k = combinations(s,i)\r\n for j in list(k) :\r\n ls = \"\".join(j)\r\n s2 = ls[::-1]\r\n if s2 == ls :\r\n arr.append(s2)\r\narr.sort()\r\nprint(arr[len(arr)-1])", "l=[]\r\n\r\ns=input()\r\ns=sorted(s)\r\nfor i in range(len(s)):\r\n if(s[len(s)-1]==s[i]):\r\n l.append(s[i])\r\n\r\n # print(s[i])\r\nprint(*l ,sep='')\r\n", "n = input()\r\na = max(n)\r\nprint(n.count(a)*a)", "from collections import Counter\r\nx=input()\r\ncheck=[ord(i) for i in x]\r\nmax_ch=max(check)\r\nd=dict(Counter(x))\r\nprint(chr(max_ch)*d[chr(max_ch)])\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# palindrome check(kaibun・回文) -- START --\ndef isPalindrome(s):\n l1=list(s)\n l2=l1[::-1]\n\n if l1==l2:\n return True\n return False\n# palindrome check(kaibun・回文) --- END ---\n\ndef main():\n s=S()\n ans=[]\n\n n=len(s)\n for i in range(1<<n):\n x=''\n for j in range(n):\n if i&(1<<j):\n x+=s[j]\n if isPalindrome(x):\n ans.append(x)\n\n ans.sort()\n # print(ans)\n return ans[-1]\n\n# main()\nprint(main())\n", "s = input()\r\nrel = \"\"\r\nmaximum = s[0]\r\nfor x in s:\r\n if maximum < x:\r\n maximum = x\r\nfor x in s:\r\n if x == maximum:\r\n rel = rel + x\r\nprint(rel)", "s = input()\r\nc = max(s)\r\nprint(c * s.count(c))", "#input\r\n\r\ns=str(input())\r\n\r\n\r\n\r\n#variables\r\nm='a'\r\n\r\n\r\n\r\n#main\r\n\r\nfor i in range(len(s)):\r\n\tm=max(m,s[i])\r\n\r\nprint(m*s.count(m))", "\r\nstring = input()\r\nn = len(string)\r\nsubset = []\r\n\r\nans = \"\"\r\ndef search(k):\r\n global ans\r\n if (k == n):\r\n subs = \"\"\r\n for c in subset:\r\n subs += string[c]\r\n\r\n if (subs > ans and subs == subs[::-1]):\r\n ans = subs\r\n\r\n else:\r\n search(k + 1)\r\n subset.append(k)\r\n search(k + 1)\r\n subset.pop()\r\n\r\nsearch(0)\r\nprint(ans)\r\n", "s=input()\r\nl=sorted(list(s))\r\nel=l[-1]\r\nprint(el*(l.count(el)))", "from itertools import combinations\r\n\r\nstring = input()\r\n\r\nlst = list()\r\n\r\nfor i in range(1, len(string) + 1):\r\n for v in combinations(string, i):\r\n if ''.join(v) == ''.join(reversed(v)):\r\n lst.append(''.join(v))\r\n\r\nlst.sort()\r\n\r\nprint(lst[-1])\r\n", "x=sorted(input())\r\nprint(str(x[-1])*x.count(x[-1]))", "l=list(map(str,input().strip()))\nl.sort(reverse=True)\nn=l.count(l[0])\nprint(l[0]*n)\n\t \t \t\t \t\t\t\t \t\t\t \t \t", "s = input()\r\nascii = [ord(x) for x in s]\r\nascii.sort(reverse=True)\r\nmx=[x for x in ascii if x==max(ascii)]\r\nprint(''.join([chr(x) for x in mx]))", "s = list(input())\r\n\r\ns.sort()\r\n\r\nprint(s[-1]*s.count(s[-1]))", "s = input()\r\nc = max(s)\r\nfor i in range(len(s)):\r\n if c == s[i]:\r\n print(c, end = \"\")\r\n", "import sys\n\ninp = input()\nstring_sorted = sorted(inp)\nllps = \"\"\nllps += string_sorted[len(string_sorted)-1]\nfor i in reversed(range(len(string_sorted)-1)):\n\tif(llps[-1] == string_sorted[i]):\n\t\tllps+=string_sorted[i]\nprint(llps)\n\t\n", "s, c = input(), 'a'\r\nfor x in s: c = max(c, x)\r\nfor x in s:\r\n if x == c: print(x, end = \"\")", "# https://codeforces.com/contest/202/problem/A\n\ndef LCS(s1, s2, n, m):\n dp = [[\"\" for _ in range(m + 1)] for _ in range(n + 1)]\n s = sorted(s1)\n for i in range(1, n + 1):\n for j in range(1, m + 1):\n if j == 0:\n dp[i][j] = 0\n elif s1[i - 1] == s2[j - 1] and s1[i - 1] == s[n - 1]:\n dp[i][j] = dp[i - 1][j - 1] + s1[i - 1]\n else:\n dp[i][j] = max(dp[i - 1][j], dp[i][j - 1], key=len)\n\n # print(dp)\n return dp[n][m]\n\n\nA = input()\nprint(LCS(A, A[::-1], len(A), len(A)))\n", "a =[]\r\ns = input()\r\na += s\r\na.sort(reverse=True)\r\ni = 0\r\nwhile i < len(a) and a[i] == a[0]:\r\n print(a[i], end='')\r\n i += 1\r\n", "# Rishabh Rao (https://github.com/rishabhrao)\r\n\r\nimport sys\r\nMOD = 1000000007\r\ndef inp(): return sys.stdin.readline().strip()\r\ndef ii(): return int(inp())\r\ndef iis(): return [int(i) for i in inp().split()]\r\n\r\n\r\ns = sorted(list(inp()), reverse=True)\r\nprint(s[0] * s.count(s[0]))\r\n", "n = input()\r\nprint(max(list(n))*n.count(max(list(n))))", "import sys\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ninp = sys.stdin.readline\r\ndef input(): return inp().strip()\r\ndef 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\ndef toNum(s):\r\n return ord(s) - ord('a')\r\n\r\ndef toString(s):\r\n return chr(s+ord('a'))\r\ndef solve():\r\n s =input()\r\n \r\n space = [0]*26\r\n \r\n for i in s:\r\n space[toNum(i)]+=1\r\n \r\n for i in range(25,-1,-1):\r\n curr = space[i]\r\n if curr > 0:\r\n print(toString(i)*curr) \r\n break\r\n\r\n\r\ndef main():\r\n solve()\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "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 s = sorted(list(input()), reverse=True)\n for i in range(len(s)):\n if s[i] != s[0]:\n break\n print(s[i], end='')\n print()\n\n\nif __name__ == '__main__':\n main()\n\n\t \t \t\t\t \t\t \t \t \t \t \t \t\t \t", "s=list(input())\r\ns.sort()\r\ni=s.index(max(s))\r\nprint(\"\".join(s[i:]))", "from bisect import bisect_right as br\r\nimport sys\r\nfrom collections import *\r\nfrom math import *\r\nimport re\r\ndef sieve(n):\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*p,n+1,p):\r\n prime[i]=False\r\n p+=1\r\n c=0\r\n for i in range(2,n):\r\n if prime[i]:\r\n #print(i)\r\n c+=1\r\n return c\r\n\r\ndef iseven(n):return[False,True][0 if n%2 else 1]\r\ndef inp_arr():return list(map(int,input().split()))\r\ndef inp():return map(int,input().split())\r\ndef lcm(a,b):return (a*b)/gcd(a,b)\r\nmax_int = sys.maxsize\r\nmod = 10**9+7\r\n\r\ns=input()\r\nprint(max(s)*s.count(max(s)))", "S =input()\r\nl = max(S)\r\nprint(l * S.count(l))", "import collections\nword = collections.Counter(input())\nprint(max(word)*word[max(word)])\n", "\r\ns = input()\r\nmx, r = max(s), ''\r\nfor e in s:\r\n if e == mx:\r\n r += e\r\nprint(r)", "string = input()\r\nstring = [c for c in string]\r\nprint(max(string) * string.count(max(string)))", "f=lambda:map(int,input().split())\r\ns=input()\r\na=max(set(s))\r\nprint(a*s.count(a))", "s=input()\n\nstart=max(s)\n\nx=s.count(start)\n\nfor i in range(x):\n print(start,end=\"\")\n", "l=input()\r\nu=set(l)\r\nu=list(u)\r\nu=sorted(u)\r\nk=len(u)\r\nfor i in l:\r\n if(i==u[k-1]):\r\n print(i,end='')", "from itertools import combinations\r\n\r\nline = input()\r\nallcombin = []\r\n\r\nfor c in range(len(line)):\r\n\tfor item in combinations(line, c+1):\r\n\t\tallcombin.append(''.join([str(x) for x in item]))\r\n\r\nallcombin.sort()\r\nallcombin = allcombin[::-1]\r\nfor item in allcombin:\r\n\tif item == item[::-1]:\r\n\t\tprint(item)\r\n\t\texit()\r\n\r\n\t\r\n", "s = input()\r\nx = s.count(max(s))\r\nprint(max(s)*x)", "inStr = input()\r\nlargest = max(inStr)\r\nc = inStr.count(largest)\r\nprint(c*largest)", "a=input()\r\nb=sorted(a)\r\nc=a.count(b[-1])\r\nprint(b[-1]*c)", "s = str(input())\r\na = [i for i in s]\r\na.sort(reverse=True)\r\nprint(str(a[0]) * a.count(a[0]))", "n=input()\r\nans=n[0]\r\nres=''\r\nfor i in range(1,len(n)):\r\n ans=max(ans,n[i])\r\nfor i in n:\r\n if ans==i:\r\n res+=i\r\nprint(res)", "u=input();c=max(u);print(u.count(c)*c)\r\n", "s = input()\r\nfor c in 'abcdefghijklmnopqrstuvwxyz'[::-1]:\r\n if c in s:\r\n print(c * s.count(c))\r\n break", "s=input()\r\nk=s.count(max(s))\r\nprint(max(s)*k)\r\n", "s=list(input())\ns.sort()\nk=s[-1]\nprint(k*s.count(k))\n \t \t\t\t \t \t \t\t \t\t\t \t \t\t\t", "def bitmask(n, s):\n n = list(bin(n)[2:].zfill(len(s)))\n # print (n)\n return ''.join(s[i] for i in range(len(s)) if n[i] == '1')\ndef is_palindrome(s):\n return s == s[::-1]\n\ns = input()\narray = []\nfor i in range(2 ** len(s)):\n s1 = bitmask(i, s)\n if is_palindrome(s1):\n array.append(s1)\narray.sort(reverse=True)\nprint (array[0])", "n = input()\r\ni = max(n)\r\nprint(n.count(i)*i)", "s=input();print(s.count(max(s))*max(s))\r\n", "query = input()\r\nmx = query[0]\r\nfor i in range(len(query)):\r\n mx = max(mx, query[i]) \r\nresult = ''\r\nfor i in range(len(query)):\r\n if mx == query[i]:\r\n result = result + query[i]\r\nprint(result)", "st = input()\r\nc = max(st)\r\nn = st.count(c)\r\ns = \"\"\r\nfor i in range(n):\r\n s += c\r\nprint(s)", "s = input()\r\na = max(s)\r\nb = s.count(a)\r\nprint(b*a)", "def get_seq(seq, out=\"\"):\r\n\tif len(seq) == 0:\r\n\t\tres.append(out)\r\n\t\treturn 0\r\n\r\n\tget_seq(seq[1:], out)\r\n\tget_seq(seq[1:], out+seq[0])\r\n\r\nres = []\r\ns = input()\r\nget_seq(s)\r\npalindrome = [x for x in res if x == x[::-1]]\r\nprint(sorted(palindrome,reverse=True)[0])", "s=input()\r\np=max(s)\r\nprint(s.count(p)*p)", "n=input()\r\nprint(n.count(max(n))*max(n))", "s=input()\r\nt=0\r\nfor i in range(len(s)):\r\n if ord(s[i])>t:\r\n t=ord(s[i])\r\n\r\ng=chr(t)\r\nprint(s.count(g)*g)", "from collections import Counter\r\nS = list(input())\r\nF = Counter(S)\r\nX = set(S)\r\nfor c in 'abcdefghijklmnopqrstuvwxyz'[::-1]:\r\n if (c in X): print(c*max(1,F[c])); break", "d = {}\r\nfor el in input():\r\n if el in d: d[el] += 1\r\n else: d[el] = 1\r\nm = max(d.keys())\r\nprint(d[m] * m)", "a = str(input())\r\nmax = a[0]\r\nfor i in range(1, len(a)):\r\n if a[i] > max:\r\n max = a[i]\r\nprint(max * a.count(max))", "s = input()\r\nk = max(s)\r\nprint(k*(s.count(k)))", "s=input()\r\nt=max(s)\r\nprint(t*s.count(t))", "s=input()\nr= '' \nm = s[0]\nfor i in range(1, len(s)):\n\tm = max(m, s[i]) \nfor i in range(0, len(s)):\n\tif s[i] == m:\n\t\tr += s[i] \nprint(r)\t\t\n\t\t \t \t \t \t \t \t \t \t\t\t", "l=input()\r\nl=list(l)\r\nl.sort()\r\nk=l.count(l[-1])\r\nfor i in range(k):\r\n print(l[-1],end=\"\")", "s=input()\r\ns=sorted(s)\r\nn=len(s)\r\nstart=0\r\nend=n-1\r\ntarget=s[-1]\r\nwhile(start<=end):\r\n mid=start+(end-start)//2\r\n if s[mid]==target:\r\n res=mid\r\n end=mid-1\r\n \r\n else:\r\n start=mid+1\r\n \r\nst=target*(n-res)\r\nprint(st)", "def fun(s):\r\n mx=s[0]\r\n res=\"\"\r\n for i in range(1,len(s)):\r\n mx=max(s[i],mx)\r\n for i in range(len(s)):\r\n if(s[i]==mx):\r\n res=res+s[i]\r\n return res\r\ns=input()\r\nh=fun(s)\r\nprint(h) ", "r = input()\r\nmax_count = 0\r\namount = 0\r\nsize = len(r)\r\nfor i in range(size):\r\n if ord(r[i]) > max_count:\r\n max_count = ord(r[i])\r\nfor i in range(size):\r\n if chr(max_count) == r[i]:\r\n amount+=1\r\nans = chr(max_count)*amount\r\nprint(ans)", "from itertools import chain, combinations\n\ndef powerset(iterable):\n xs = list(iterable)\n return chain.from_iterable(combinations(xs,n) for n in range(len(xs)+1))\n\nR=\"\"\nS=input()\nfor s in powerset(S):\n t = ''.join(s)\n u = ''.join(reversed(s))\n if t==u and t>R:\n R = t\nprint(R)\n\n", "st = list(input())\r\nst.sort(reverse=True)\r\nprint(st[0],end='')\r\nprev =st[0]\r\nfor i in range(1,len(st)):\r\n # print(st[:x+1],st[x+1:2*x+2])\r\n if(prev == st[i]):\r\n print(st[i],end='')\r\n else:\r\n break;\r\n prev=st[i]\r\n \r\n \r\n\t", "s = input()\r\nm = max(s)\r\nc = s.count(m)\r\nprint(c*m)", "from itertools import combinations\r\nx = input()\r\nperms = []\r\nfor i in range(1, len(x)+1):\r\n for c in combinations(x, i):\r\n perms.append(\"\".join(c))\r\nperms =list(set(perms))\r\nperms = list(set(perms))\r\nperms\r\nans = []\r\nfor word in perms:\r\n if word == word[::-1]:\r\n ans.append(word)\r\nlis =[]\r\nfor w in list(ans) :\r\n flag = 0 \r\n for i in range(len(w)-1):\r\n if (ord(w[i]) > ord(w[i+1])):\r\n flag = 1\r\n break\r\n if flag == 0:\r\n lis.append(w)\r\nlis.sort(reverse=True)\r\nprint(lis[0])\r\n", "S=input()\r\nhash={}\r\nfor a in S:\r\n hash[a]=hash.get(a,0)+1\r\nmx=\"a\"\r\nc=0\r\nalpha=\"abcdefghijklmnopqrstuvwxyz\"\r\nalpha=list(reversed(alpha))\r\nfor a in alpha:\r\n if a in hash:\r\n c=hash[a]\r\n mx=a\r\n break\r\nprint(mx*c)", "from itertools import combinations\r\ns = list(input())\r\nli =[]\r\nc =1\r\nwhile c<=len(s):\r\n comb = combinations(s, c)\r\n for i in list(comb):\r\n b=''\r\n for j in range(len(i)):\r\n b+=i[j]\r\n if b==b[::-1]:\r\n li.append(b)\r\n c+=1\r\nprint(max(li))\r\n\r\n", "def largest_palin_sub(string_to_process):\r\n result = \"\"\r\n maximum = string_to_process[0]\r\n for i in range(1, len(string_to_process)):\r\n maximum = max(maximum, string_to_process[i])\r\n for i in range(0, len(string_to_process)):\r\n if string_to_process[i] == maximum:\r\n result += string_to_process[i]\r\n return result\r\n\r\n\r\nprint(largest_palin_sub(input()))\r\n", "s=input()\r\nc=max(s)\r\nprint(s.count(c)*c)", "q=input()\r\nm=\"\"\r\nfor i in q:\r\n if(i>m):\r\n m=i\r\no=q.count(m)\r\nprint(m*o)", "s=input()\r\nx=max(s)\r\nn=s.count(x)\r\nprint(x*n)", "s = str(input())\r\nchar, freq = s[0], 1\r\nfor j in range(1, len(s)):\r\n if ord(s[j]) > ord(char):\r\n char, freq = s[j], 1\r\n elif ord(s[j]) == ord(char):\r\n freq += 1\r\nprint(char * freq)\r\n", "word = list(input())\r\nmaxLetter = max(word)\r\nmaxCount = word.count(maxLetter)\r\nfor i in range(maxCount):\r\n\tprint(maxLetter, end = \"\")", "l=list(map(ord,input()))\r\nprint(chr(max(l))*l.count(max(l)))", "n=input()\r\nn=list(n)\r\nl=n[0]\r\nfor i in range(0,len(n)):\r\n if n[i]>l:\r\n l=n[i]\r\ns=\"\"\r\nfor i in range(len(n)):\r\n if n[i]==l:\r\n s=s+n[i]\r\nprint(s)\r\n", "s = input()\r\nmax_value = -1\r\nfor x in s:\r\n if ord(x) > max_value:\r\n max_value = ord(x)\r\ngreatest = chr(max_value)\r\nsequence = ''\r\nfor x in s:\r\n if x == greatest:\r\n sequence += x\r\nprint(sequence)", "s = input()\r\nc = sorted(s)[-1]\r\nprint(c * s.count(c))\r\n", "s = input()\r\n\r\ns = sorted(s)\r\nmylist = []\r\n\r\ncheck = s[-1]\r\n\r\nfor i in s[::-1]:\r\n if i == check:\r\n mylist.append(i)\r\n\r\n\r\ndone = \"\".join(mylist)\r\nprint(done)\r\n", "d = sorted(list(input()), reverse=True)\r\nfor i in range(len(d)):\r\n if d[i] == d[0]:\r\n print(d[i],end='')\r\n else:\r\n break", "z=input();k=max(z)\r\nprint(k*z.count(k))", "# LUOGU_RID: 93795993\nstring = input()\r\ns = list(string)\r\nlargest = max(s)\r\ncnt = 0\r\nfor x in s:\r\n if x == largest:\r\n cnt += 1\r\n\r\nfor x in range(cnt):\r\n print(largest, end='')\r\n", "def num(data, ch):\r\n for i in range(len(data)):\r\n if str(data[i][0]) == str(ch):\r\n return i\r\n\r\n\r\nabc = \"abcdefghijklmnopqrstuvwxyz\"\r\ndata = list(zip(abc))\r\na = input()\r\nm = -1\r\nfor i in a:\r\n if num(data, i) > m:\r\n m = num(data, i)\r\n b = a.count(i)\r\n c = i\r\nprint(c*b)\r\n\r\n", "s=input()\r\nvar=max(s)\r\n#print(var)\r\nc=0\r\nfor i in range(len(s)):\r\n if s[i]==var:\r\n c+=1\r\nprint(var*c)", "x=input()\r\n\r\na=max(x)\r\n\r\nprint(x.count(a)*a)\r\n", "a=input()\r\ns=0\r\nfor i in a:\r\n if max(a) in i:\r\n s+=1\r\nfor k in range(s):\r\n print(max(a),sep='',end='')", "\r\nstrList =list(str(input()))\r\n\r\nstrList.sort()\r\nx = strList.count(strList[len(strList)-1])\r\nprint(strList[len(strList)-1]*x)", "text = input()\nbiggest = text[0]\namount = 1\nfor character in text[1:]:\n if character == biggest:\n amount += 1\n elif character > biggest:\n biggest = character\n amount = 1\nprint(''.join([biggest] * amount))\n", "s = str(input())\r\nl = \"\"\r\nans = 0\r\nfor i in range(len(s)):\r\n if l == \"\":\r\n l = s[i]\r\n else:\r\n if l < s[i]:\r\n l = s[i]\r\nprint(l*(s.count(l)))", "a=input()\r\nprint(max(a)*a.count(max(a)))", "def take(s, i, mask):\r\n if i == len(s):\r\n return [\"\".join([s[i] for i in range(len(s)) if mask[i]])]\r\n mask[i] = 0\r\n ans = take(s, i + 1, mask)\r\n mask[i] = 1\r\n return ans + take(s, i + 1, mask)\r\n\r\n\r\ns = list(input())\r\n\r\nwords = list(set(take(s, 0, [0] * len(s))))\r\n\r\npalindroms = []\r\n\r\nfor word in words:\r\n for i in range(len(word)):\r\n if word[i] != word[len(word) - i - 1]:\r\n break\r\n\r\n else:\r\n palindroms.append(word)\r\n\r\nprint(max(palindroms))\r\n", "if __name__ == \"__main__\":\r\n s = input()\r\n lst = [i for i in s]\r\n c = lst.count(max(lst))\r\n print(max(lst) * c)\r\n\r\n", "# ░░░░░░░░░░░░░░░░░░░░░░░░░░░░╔═══╗╔╗╔═══╦═══╗\r\n# ░░░░░░░░░░░░░░░░░░░░░░░░░░░░║╔═╗╠╝║║╔═╗║╔═╗║\r\n# ╔══╦═╗╔══╦═╗╔╗░╔╦╗╔╦══╦╗╔╦══╬╝╔╝╠╗║║║║║╠╝╔╝║\r\n# ║╔╗║╔╗╣╔╗║╔╗╣║░║║╚╝║╔╗║║║║══╬╗╚╗║║║║║║║║░║╔╝\r\n# ║╔╗║║║║╚╝║║║║╚═╝║║║║╚╝║╚╝╠══║╚═╝╠╝╚╣╚═╝║░║║░\r\n# ╚╝╚╩╝╚╩══╩╝╚╩═╗╔╩╩╩╩══╩══╩══╩═══╩══╩═══╝░╚╝░\r\n# ░░░░░░░░░░░░╔═╝║░░░░░░░░░░░░░░░░░░░░░░░░░░░░\r\n# ░░░░░░░░░░░░╚══╝░░░░░░░░░░░░░░░░░░░░░░░░░░░░\r\n\r\na=input()\r\n\r\nb=max(a)\r\n\r\nprint(a.count(b)*b)", "import sys\nimport time\nfrom pprint import pprint\nfrom sys import stderr\nfrom itertools import combinations\n\nINF = 10 ** 18 + 3\nEPS = 1e-10\nMAX_CACHE = 10 ** 9\n\n\n# Decorators\ndef time_it(function, output=stderr):\n def wrapped(*args, **kwargs):\n start = time.time()\n res = function(*args, **kwargs)\n elapsed_time = time.time() - start\n print('\"%s\" took %f ms' % (function.__name__, elapsed_time * 1000),\n file=output)\n return res\n\n return wrapped\n\n\n@time_it\ndef main():\n s = input()\n vars = (comb for l in range(1, len(s) + 1) for comb in combinations(s, l) if comb[::-1] == comb)\n print(\"\".join(max(vars)))\n\n\ndef set_input(file):\n global input\n input = lambda: file.readline().strip()\n\n\ndef set_output(file):\n global print\n local_print = print\n\n def print(*args, **kwargs):\n kwargs[\"file\"] = kwargs.get(\"file\", file)\n return local_print(*args, **kwargs)\n\n\nif __name__ == '__main__':\n set_input(open(\"input.txt\", \"r\") if \"MINE\" in sys.argv else sys.stdin)\n set_output(sys.stdout)\n main()\n", "letters = 'abcdefghijklmnopqrstuvwxyz'\r\n\r\ns = input()\r\n\r\nres = -1\r\nfor char in s:\r\n index = letters.index(char)\r\n res = max(res,index)\r\n\r\ncount = s.count(letters[res])\r\n\r\nprint(letters[res]*count)\r\n", "a = input()\r\ns = a[0]\r\nfor i in a:\r\n if i > s:\r\n s = i\r\nfor j in a:\r\n if j == s:\r\n print(j, end = '')", "n=input();print(max(n)*(n.count(max(n))))", "s = input()\r\ns = list(s)\r\ns.sort()\r\nc = s[-1]\r\nn = s.count(c)\r\nprint(c*n)", "s=input()\r\nk=max(s)\r\nprint(k*s.count(k))", "string = input()\r\nstring = list(string)\r\nletters = list(\"abcdefghijklmnopqrstuvwxyz\")\r\nletter_values = {}\r\nn = 0\r\nmax_value = 0\r\nlex_largest_letter = None\r\nreps = 0\r\nLLPS = None\r\n\r\n# apply a value to each letter\r\nfor letter in letters:\r\n n += 1\r\n letter_values[letter] = n\r\n\r\n# revisar cada letra en la lista string y seleccionar la de mayor valor:\r\nfor letter in string:\r\n\r\n if letter_values[letter] > max_value:\r\n max_value = letter_values[letter]\r\n lex_largest_letter = letter\r\n\r\n else:\r\n pass\r\n\r\n# how many times does the lexicograficaly largest letter repeat in the string\r\nfor letter in string:\r\n\r\n if lex_largest_letter == letter:\r\n reps += 1\r\n# create a string made with the lex_largest_letter\r\nLLPS = lex_largest_letter*reps\r\n\r\n# there is a problem though, if the first letter of the original string is already\r\n# the lex_largest_letter and does not repeat, then if we make a polindrome made\r\n# only with the same letter it will not\r\nprint(LLPS)\r\n", "s = input()\r\ns = sorted(s)\r\nmx = max(s)\r\n# print(s)\r\nprint(mx*s.count(mx))", "i = input()\r\nlet = max(i)\r\nprint(let * i.count(let))\r\n", "s = input()\r\nanswer = None\r\nn = len(s)\r\nfor i in range(2 ** n):\r\n subs = ''\r\n for j in range(n):\r\n if i & (2 ** j):\r\n subs += s[j]\r\n if subs == subs[::-1] and (answer is None or subs > answer):\r\n answer = subs\r\nprint(answer)\r\n", "x=input()\nfor e in range(122,96,-1):\n if chr(e) in x:\n ch=chr(e);\n break;\nans=\"\"\nfor i in x:\n if i==ch:\n ans+=i;\nprint(ans)\n # TODO: write code...\n \t\t\t \t\t \t \t \t \t\t \t\t\t\t \t", "#!/usr/bin/env/python\r\n# -*- coding: utf-8 -*-\r\ns = list(input())\r\ncnt = [0] * 26\r\nfor c in s:\r\n cnt[ord(c) - ord('a')] += 1\r\nfor i in range(25, -1, -1):\r\n if cnt[i]:\r\n print(chr(ord('a') + i) * cnt[i])\r\n break", "# a= int(input())\r\n# for i in range(a):\r\n# x = int(input())\r\n# y = list(map(int,input().split(\" \")))\r\n# ans = 0\r\n# for w in range(2,2*x):\r\n# count = [0]*(101)\r\n# pairs = 0\r\n# for j in y:\r\n# if (w-j>0) and count[w-j]!=0:\r\n# pairs+=1\r\n# count[w-j]-=1\r\n# else:\r\n# count[j]+=1 \r\n# ans = max(ans, pairs)\r\n# print(ans)\r\n\r\n\r\n\r\n\r\na= input()\r\ncache = [0]*26\r\n\r\nfor i in a:cache[(25-(ord(\"z\")-ord(i)))]+=1\r\n\r\nfor i in range(len(cache)-1,-1,-1):\r\n if cache[i]>0:\r\n print(chr(97+i)*cache[i])\r\n break\r\n", "ins = input()\r\nmx = max(ins)\r\nprint(mx * ins.count(mx))", "w = str(input())\r\ni = max(w)\r\nprint(i*w.count(i))", "x=input()\r\nl=[i for i in x]\r\nl.sort()\r\nprint(l[-1]*(x.count(l[-1])))", "string=input()\r\nmaximum=''\r\n# print(maximum)\r\n\r\nclass Solution:\r\n def solver(self,string):\r\n maximum=''\r\n def dfs(i,curr):\r\n nonlocal maximum\r\n # print(curr)\r\n if i>=len(string):\r\n if curr==curr[::-1] and curr>maximum:\r\n maximum=curr\r\n return\r\n \r\n \r\n if curr==curr[::-1] and curr>maximum:\r\n maximum=curr\r\n for idx in range(i,len(string)):\r\n copy=curr[:]\r\n copy+=string[idx]\r\n # print(copy)\r\n dfs(idx+1,copy)\r\n dfs(idx+1,curr)\r\n for i in range(len(string)):\r\n dfs(i+1,string[i])\r\n return maximum\r\nnum=Solution()\r\nprint(num.solver(string))\r\n\r\n ", "#!/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 S = wtf[0]\r\n d = dict()\r\n for s in S:\r\n \tif not s in d:\r\n \t\td[s] = 1\r\n \telse:\r\n \t\td[s] += 1\r\n kd = sorted(d, reverse=True)\r\n ans = kd[0]*d[kd[0]]\r\n print(ans)", "word = input()\r\nch = max(x for x in word)\r\nprint(ch * word.count(ch))", "s=str(input())\r\ns1=\"\"\r\nfor char in s:\r\n if s1==\"\" or char>s1[0]:\r\n s1=char\r\n elif char==s1[0]:\r\n s1+=char\r\nprint(s1)", "s=input()\r\ns = sorted(s, reverse=True)\r\nprint(s[0]*(s.count(s[0])))", "s=list(input())\r\nr=[]\r\ni=0\r\nwhile(i<len(s)):\r\n\tk=ord(s[i])\r\n\tm=[s[i]]\r\n\tfor j in range(i+1,len(s)):\r\n\t\tif(ord(s[j])>=k):\r\n\t\t\tm.append(s[j])\r\n\tr.append(\"\".join(m))\r\n\ti=i+1\r\np=[]\r\nfor j in range(len(r)):\r\n\tz=list(r[j])\r\n\tz=z[::-1]\r\n\tif(r[j]==\"\".join(z)):\r\n\t\tp.append(r[j])\r\nprint(max(p))", "w = sorted(input())\r\nprint(''.join(w[w.index(w[-1]):]))", "word = list(input())\nnum = 0\nc = ['z','y','x','w','v','u','t','s', 'r', 'q', 'p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a']\ncc = ' '\nfor i in c:\n if num < word.count(i) and word.count(i) != 0:\n num = word.count(i)\n cc = i\n break\nprint(cc*num)\n \t \t \t\t \t\t\t\t \t \t \t\t \t", "x=input();a=max(x);print(x.count(a)*a)\r\n", "s = input()\r\nm = max(s)\r\n\r\nfor i in range(len(s)):\r\n if m == s[i]:\r\n print(s[i], end='')", "import io\r\nimport os\r\nimport sys\r\nfrom collections import Counter\r\n# Reinitialize the Input function\r\n# to take input from the Byte Like \r\n# objects\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\n\r\n#read n \r\nstring = list(map(str,input().decode().strip()))\r\n\r\nans=''\r\nmax=string[0]\r\nfor i in string:\r\n if i > max:\r\n max = i\r\nfor i in string:\r\n if i == max:\r\n ans+=i\r\n\r\nprint(ans)\r\n\r\n\r\n", "s=input()\r\nfor i in range(122,96,-1):\r\n if chr(i) in s:\r\n c=s.count(chr(i))\r\n break\r\nprint(chr(i)*c)", "word = input()\r\nmaxx = word[0]\r\ncount = 1\r\nfor i in range(1,len(word)):\r\n if ord(word[i])>ord(maxx):\r\n maxx = word[i]\r\n count=1\r\n elif ord(word[i]) == ord(maxx):\r\n count+=1\r\nprint(maxx*count)", "s=input()\r\nk=0\r\nt=0\r\nfor i in range(len(s)):\r\n if ord(s[i])>k:\r\n k=ord(s[i])\r\n t=s[i]\r\nprint(str(t)*s.count(chr(k)))\r\n", "s = [i for i in input()]\r\nMax = max(s)\r\nprint(Max * s.count(Max))", "s=input()\r\ndicti={}\r\nfor i in s:\r\n if i in dicti:\r\n dicti[i]+=1\r\n else:\r\n dicti[i]=1\r\nitem=sorted(dicti.keys(),reverse=True)[0]\r\np=dicti[item]\r\nfor j in range(p):\r\n print(item,end=\"\")\r\n", "s = input()\nif s == \"\":\n print(\"\")\na = s[0]\nfor i in s:\n if i > a:\n a = i\nfor i in s:\n if i == a:\n print(i, end=\"\")\nprint(\"\")\n\t \t\t\t \t\t\t\t \t\t \t\t \t\t \t", "s=str(input())\r\nx=sorted(s)\r\nl=len(x)\r\ny=x[l-1]\r\nx=s.count(y)\r\nfor i in range(x):\r\n print(y,end=\"\")", "z=input()\r\nj=max(z)\r\nprint(z.count(j)*j)\r\n\r\n", "s=input()\r\nstart=122\r\nwhile start>=97:\r\n\tchar = chr(start)\r\n\ttemp=0\r\n\tfor i in s:\r\n\t\tif i==char:\r\n\t\t\ttemp+=1\r\n\tstart-=1\r\n\tif temp>=1:\r\n\t\tstring=char*temp\r\n\t\tbreak\t\r\nprint(string)\r\n", "sen=sorted(input())\r\nprint(sen[-1]*sen.count(sen[-1]))", "def lexi(a, b):\r\n for i in range(min(len(a), len(b))):\r\n if ord(a[i]) > ord(b[i]):\r\n return 1\r\n elif ord(a[i]) < ord(b[i]):\r\n return -1\r\n \r\n if len(a) > len(b):\r\n return 1\r\n if len(b) > len(a):\r\n return -1\r\n return 0\r\n\r\ndef isPalin(s):\r\n for i in range(len(s) // 2):\r\n if s[i] != s[len(s) - 1 -i]: return False\r\n return True\r\n\r\n\r\n\r\ns = input()\r\n\r\ncurS = ''\r\nfor c in range(2 ** len(s)):\r\n x = bin(c)[2:]\r\n x = '0' * (len(s) - len(x)) + x\r\n \r\n newS = ''\r\n for asc in range(len(x)):\r\n if x[asc] == '1':\r\n newS += s[asc]\r\n if isPalin(newS) and lexi(newS, curS) == 1:\r\n curS = newS\r\n \r\nprint(curS) \r\n ", "def solve(s):\r\n s=sorted(s)\r\n return s[len(s)-1]*s.count(s[len(s)-1])\r\n \r\ns = input()\r\nprint(solve(s))\r\n\r\n", "'''\r\nCodeforces Problem 202A\r\nLLPS\r\n\r\nAuthor: Sarmitha V D 21PT27\r\nDate: 04/01/2022 Wednesday\r\n'''\r\n\r\ndef genAllSubsequence(input_str, output_str, myList):\r\n if (len(input_str)==0):\r\n myList.append(output_str)\r\n return\r\n genAllSubsequence(input_str[1:], output_str+input_str[0], myList)\r\n genAllSubsequence(input_str[1:], output_str, myList)\r\n\r\noutput_str = \"\"\r\nmyList = []\r\nmyList1 = []\r\ninput_str = input()\r\nfor i in input_str:\r\n if i not in myList:\r\n myList.append(i)\r\nf = max(myList)\r\nmyList = []\r\ngenAllSubsequence(input_str, output_str, myList)\r\nmyList.remove(\"\")\r\nmyList = [i for i in myList if i[0]==f]\r\nfor i in myList:\r\n if (list(i)==list(reversed(i))) and (i not in myList1):\r\n myList1.append(i)\r\nprint(max(myList1))", "from itertools import combinations\r\n\r\ndef isPalindrome(str):\r\n\tif str == str[::-1]: return True\r\n\telse: return False\r\n\r\ndef getPalindromes(str):\r\n\tpaliList = set()\r\n\tfor r in range(1, len(str) + 1):\r\n\t\tfor c in combinations(str, r):\r\n\t\t\taux = ''.join(c)\r\n\t\t\tif isPalindrome(aux):\r\n\t\t\t\tpaliList.add(aux)\r\n\treturn sorted(paliList)\r\n\r\nif __name__ == '__main__':\r\n\tstr = input()\r\n\tprint(max(getPalindromes(str)))", "s =list(input())\r\ns.sort()\r\nc = s.count(s[-1])\r\nprint(s[-1]*c)", "v=input()\r\nc=max(v);print(v.count(c)*c)\r\n", "s = input()\r\ns = ''.join(sorted(s))\r\nmax = s[len(s)-1]\r\nprint(max*(s.count(max)))", "s=input()\r\np=''\r\nk=max(s)\r\nfor i in range(len(s)):\r\n if(s[i]==k):\r\n p+=s[i]\r\n i+=1\r\nprint(p)", "l=list(map(str,input().strip()))\r\nl.sort(reverse=True)\r\nn=l.count(l[0])\r\nprint(l[0]*n)", "s = input()\r\n\r\nval = max(s)\r\n\r\nans = \"\"\r\n\r\nfor index in range(len(s)):\r\n if s[index] == val:\r\n ans += s[index]\r\n \r\nprint(ans)", "import sys\n#input = sys.stdin.readline #-----------------------------------(enable it if using first 4 functions else dont)\n#input is a string\n############ ---- Input Functions ---- ############\n#input.split() is a list\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\ndef get_int():\n\treturn int(sys.stdin.readline())\n\ndef get_string():\n\treturn sys.stdin.readline().strip()\n\n#n = get_int()\n#final_result = []\n#for i in range(n):\n#\tword = get_string()\n#\tfinal_result.append(word)\n #['5 5', '10 1', '2 3', '0 0', '17 2', '1000000000 1000000000'] This is final_result\n#xx=[]\n#for i in range(n):\n# xx.append(list(map(int,final_result[i].split())))\n \n\n\n\ns = sys.stdin.readline()\n\nx ='a'\nfor i in range(len(s)):\n if s[i] >x:\n x=s[i]\n\n# x is largest character of the string\n\nn =0\n\nfor i in range(len(s)):\n if s[i] ==x:\n n+=1\n\nprint( n*x)", "s=input()\r\nk=0\r\nfor i in range(len(s)):\r\n\tif ord(s[i])>k:\r\n\t\tk=ord(s[i])\r\nprint(chr(k)*s.count(chr(k)))", "n = list(input())\r\nn.sort() \r\nprint(n[-1]*n.count(n[-1]))", "s=input()\r\ns=sorted(s)[::-1]\r\nfor i in range(1,len(s)):\r\n if s[i] != s[i-1]:\r\n break\r\n print(s[0],end='')\r\nprint(s[0])\r\n", "def solution(s):\r\n s.sort()\r\n res = ''\r\n\r\n for i in range(len(s)-1, -1, -1):\r\n if s[i] == s[-1]: res += s[-1]\r\n else: break\r\n\r\n return res\r\n\r\nstring = [c for c in input()]\r\nprint(solution(string))\r\n\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Dec 27 16:47:12 2022\r\n\r\n@author: 21pt10\r\n\"\"\"\r\n\r\nstr1=input()\r\nlst = list(str1)\r\nchar = max(lst)\r\nc=0\r\nfor i in lst:\r\n if char==i:\r\n c+=1\r\nprint(char*c)", "s = input()\nc = max(s)\nres = c * s.count(c)\nprint(res)\n", "#202A\r\nl=list(input())\r\nl.sort()\r\nc=\"\"\r\ns=l[-1]\r\nfor i in range(len(l)):\r\n if l[i]==s:\r\n c+=l[i]\r\nprint(c)\r\n", "from collections import defaultdict\r\n\r\nInput = input()\r\nDict = defaultdict(int)\r\nfor i in Input:\r\n Dict[i] += 1\r\nMAX = max(Dict.keys())\r\nprint(MAX * Dict[MAX])\r\n", "s = input().lower()\r\na = []\r\nfor j in s:\r\n a.append(j)\r\n\r\na.sort()\r\nprint(a.count(a[-1]) * a[-1])", "s = input()\r\nn = len(s)\r\n\r\nans = ''\r\nfor i in range(2 ** n):\r\n m = bin(i)[2:].zfill(n)\r\n p = ''\r\n for j in range(n):\r\n p += s[j] * int(m[j])\r\n if p == p[::-1]:\r\n ans = max(ans, p)\r\n\r\nprint(ans)\r\n", "st = input()\r\ns = set(st)\r\nma = 0\r\nfor i in s:\r\n if ord(i) > ma:\r\n ma = ord(i)\r\nfor i in range(len(st)):\r\n if ord(st[i]) == ma:\r\n print(st[i], end = \"\")", "s = input()\r\n\r\n# sort the string in descending lexicographical order\r\nsorted_string = sorted(s, reverse=True)\r\n# largest string is always at the beginning of list\r\nlargest = sorted_string[0]\r\n\r\nfor i in range(len(sorted_string)):\r\n\t# print the character if it is equal to largest\r\n\tif sorted_string[i] == largest:\r\n\t\tprint(largest, end='')", "import itertools as it\nn=input()\nli=[]\nfor i in range(len(n)+1): \n li.append(list(set(it.combinations(n,i))))\nres=[]\nfor i in li:\n for j in i:\n if j==j[::-1]:\n res.append(j)\n#print(res)\nres=list(sorted(res,reverse=True))\nrs=''.join(res[0])\nprint(rs)\n\t \t \t\t \t \t \t\t\t \t\t\t", "s = input()\r\nl = set(s)\r\nprint(max(l) * s.count(max(l)))", "\r\nx=input()\r\na=max(x)\r\nc=x.count(a)\r\nprint(a*c)", "from collections import Counter\n\ns = input()\nunic = dict(Counter(s))\nm = max(unic)\nprint(m * unic[m])\n", "s = input()\r\nmaxn = max(s)\r\nfor i in s:\r\n if i == maxn:\r\n print(i,end=\"\")\r\nprint(\"\")", "y=input()\r\nk=max(y);print(y.count(k)*k)\r\n", "prev = ''\r\nfor i in sorted(list(input()))[::-1]:\r\n if prev == '':\r\n print(i, end = '')\r\n elif prev != i:\r\n break\r\n else:\r\n print(i, end = '')\r\n prev = i\r\n'''\r\nx = 5, k = 1\r\n12 11 10 -- a\r\n0 1 2 -- r(sort)\r\n2 2 2 -- c(sort)\r\nd = 6 == (sum(c)) - ������ ���� (����)\r\n���� sum(r) / k >= d:\r\n ����� d ����������� ���� ������ �� r (� �����������) -- for �������\r\n�����\r\n �������� �������� ����� ������ ������� x (������� ������ ������ ����)\r\n \r\n14 14 14\r\n\r\n4 4 4\r\n\r\n0 2 4\r\n0 1 0\r\n0 0 0\r\n'''", "s = input()\r\nlis = list(set(list(s)))\r\nr = max(lis)\r\nprint(s.count(r)*r)", "s = input()\ns = list(sorted(s))\nj = s[-1]\nfor i in s[::-1]:\n\tif i==j:\n\t\tprint(i, end='')\n\telse:\n\t\tbreak\n\t\t \t \t \t \t\t\t\t \t \t\t\t\t", "z=input();q=max(z);print(z.count(q)*q)", "ans=\"\"\r\ns=input()\r\na='1'\r\nfor ch in s:\r\n a=max(ch,a)\r\nfor ch in s:\r\n if ch==a:\r\n ans+=ch\r\nprint(ans)\r\n", "s = sorted(input())\r\nprint(s[-1]*s.count(s[-1]))", "from sys import stdin, stdout\r\n\r\nS = list(stdin.readline().strip())\r\n\r\nS.sort()\r\nX = \"\"\r\nj = -1 \r\nwhile(abs(j)<=len(S)):\r\n if j==-1:\r\n X+=S[j]\r\n else:\r\n if S[j]==X[-1]:\r\n X+=S[j]\r\n else:\r\n break\r\n j-=1\r\n \r\nstdout.write(f\"{X}\\n\")", "s = input()\r\nprint(s.count(max(s))*max(s))", "a = input()\r\nprint( max(a) * a.count(max(a)))\r\n", "s=str(input())\r\nl=[]\r\nl[:0]=s\r\np=sorted(l)\r\nk=l.count(p[len(l)-1])\r\nprint(p[len(l)-1]*k)", "import string\nfrom bisect import bisect, bisect_left, bisect_right\nfrom collections import Counter, defaultdict, deque\nfrom functools import cache, lru_cache\nfrom math import *\nfrom sys import stdin, stdout\n\ninput = stdin.readline\n\nMOD = 10**9+7\n\n\ndef add(a, b):\n return a+b-MOD if a+b > MOD else a+b\n\n\ndef sub(a, b):\n return a-b+MOD if a-b < 0 else a-b\n\n\ndef inp():\n return(int(input()))\n\n\ndef inlt():\n return(list(map(int, input().split())))\n\n\ndef floatl():\n return(list(map(float, input().split())))\n\n\ndef insr():\n s = input()\n return(list(s[:len(s) - 1]))\n\n\ndef ins():\n s = input()\n return s[:len(s) - 1]\n\n\ndef invr():\n return(map(int, input().split()))\n\n\ndef print_arr(arr):\n for v in arr:\n print(v, end=' ')\n print()\n\n\nt = 1\n# t = inp()\nfor _ in range(t):\n count = Counter(ins())\n ch = max(count)\n print(ch*count[ch])\n", "def main():\n from collections import defaultdict\n m = defaultdict(int)\n for c in input():\n m[c] += 1\n i = sorted(list(m.keys()))[-1]\n return i * m[i]\nprint(main())\n", "s,m=input(),{}\r\nfor i in range(len(s)):m[s[i]]=m.get(s[i],0)+1\r\nm=sorted(m.items())\r\nc,n=list(m)[-1][0],list(m)[-1][1]\r\nfor i in range(n):print(c,end='')\r\n", "s=list(input())\r\ns.sort()\r\nfor i in range(s.count(s[-1])):\r\n print(s[-1],end=\"\")", "ans=[]\r\ndef fun(s,ind,lst):\r\n global ans\r\n if(ind>=len(s)):\r\n if(lst==lst[::-1]):\r\n ans.append(list(lst))\r\n return\r\n lst.append(s[ind])\r\n fun(s,ind+1,lst)\r\n lst.pop()\r\n fun(s,ind+1,lst)\r\ns=input()\r\nfun(s,0,[])\r\nans.sort()\r\nprint(\"\".join(ans[-1]))\r\n\r\n", "strr=input()\r\ncount=0\r\nmax_char=max(strr) \r\nfor i in strr:\r\n if i==max_char:\r\n count=count+1\r\nprint(max_char*count)", "s = input()\r\nprint(str(max(s)) * s.count(max(s)))", "s=input()\r\nmaxs=max(s)\r\nprint(maxs*s.count(maxs))", "while True:\r\n try:\r\n s = input()[:10]\r\n max=s[0]\r\n count=1\r\n for i in range(1,len(s)):\r\n if s[i]>max:\r\n max=s[i]\r\n count=1\r\n elif s[i]==max:\r\n count+=1\r\n for i in range(count):\r\n print(max,end='')\r\n print(\"\\n\")\r\n except:\r\n break", "s=str(input())\r\nl=list(s)\r\nn=set(l)\r\nm=max(n)\r\nfor i in range(0,l.count(m)):\r\n print(m,end=\"\")", "n=input()\r\nprint(max(n)*n.count(max(n)))", "string = input()\r\ncurr = 'a'\r\ncount = 0\r\n\r\nfor i in string:\r\n if i > curr:\r\n curr = i \r\n \r\nfor i in string:\r\n if i == curr:\r\n count += 1\r\n \r\nprint(curr * count)", "s=input()\r\nz=max(s)\r\nprint(s.count(z)*z)", "l = list(input())\r\nll = max(l)\r\nprint(ll * l.count(ll))\r\n", "s=str(input())\r\nc=max(s)\r\ncnt=s.count(c)\r\nprint(c*cnt)", "a = input()\r\nb = [ord(x) for x in a]\r\nc = max(b)\r\nd = b.count(c)\r\nprint(chr(c) * d)", "a=input()\r\nl_a=len(a)\r\nmaxx='a'\r\nfor i in range(1, 2**l_a):\r\n bi=bin(i)[2:]\r\n new=''\r\n st='0'*(l_a-len(bi))+bi\r\n for j in range(l_a):\r\n if st[j]=='1':\r\n new+=a[j]\r\n if new==new[::-1] and new>maxx:\r\n maxx=new\r\nprint(maxx)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Apr 2 19:56:34 2020\r\n\r\n@author: roastedcoder\r\n\r\nThis is for CodeForces\r\n\"\"\"\r\nmod = 1000000007\r\nssi = lambda : map(int,input().split())\r\n\r\n# RoastedCoder\r\n\r\ns = input()\r\nl = [0]*26\r\nfor i in range(len(s)):\r\n l[ord(s[i])-97] += 1\r\n \r\nfor i in range(25,-1,-1):\r\n if(l[i] >= 1):\r\n print(chr(i+97)*l[i])\r\n break", "#loser707\r\ns=list(input())\r\norder=[]\r\nfor i in s:\r\n order.append(ord(i))\r\nfor x,y in zip(s,order):\r\n if y==max(order):\r\n c=s.count(x)\r\n print(x*c)\r\n break", "\r\nfrom math import *\r\n\r\n\r\ns=input();n=len(s);\r\nc=val=0;\r\nfor i in s:\r\n if(ord(i)>val):val=ord(i);c=1;\r\n elif(ord(i)==val):c+=1;\r\nprint(chr(val)*c);", "from collections import Counter as C\na = C(input())\nmx = max(a.keys())\nt = [mx]*a[mx]\nprint(''.join(t))\n'''\nw = int(input())\nc = 0\nfor _ in range(w):\n a = sum(map(int,input().split()))\n c+=int(a>1)\nprint(c)\n'''\n", "if __name__ == '__main__':\r\n s = input()\r\n mx = max(s)\r\n print(mx*s.count(mx))", "string = input()\nletters_dict = {}\nfor i in range(len(string)):\n\tletters_dict[string[i]] = letters_dict.get(string[i], 0) + 1\nfor char in \"abcdefghijklmnopqrstuvwxyz\"[::-1]:\n\tif(letters_dict.get(char, 0) >= 1):\n\t\tprint(char*letters_dict[char])\n\t\texit()", "s = input()\r\ni = max(s)\r\nprint((s.count(i)) * i)", "i=input();j=max(i);print(i.count(j)*j)", "nithin=input()\r\ncode=max(nithin)\r\nprint(nithin.count(code)*code)", "s=list(input())\r\ns.sort()\r\nfor i in range(len(s)-1,-1,-1):\r\n if s[i]==s[-1]:\r\n print(s[-1],end=\"\")\r\n else:\r\n break", "s=input()\r\nl=list(s)\r\nl.sort()\r\nc=s.count(l[-1])\r\nprint(l[-1]*c)", "s=input()\r\na=max(s)\r\nprint(a*s.count(a))", "w=input()\r\nz=max(w)\r\nprint(z*w.count(z))", "y=input()\r\nk=max(y);print(k*y.count(k))\r\n", "s=list(input())\r\ns.sort()\r\nk=s[-1]\r\nprint(k*s.count(k))", "string = input()\r\nlargest = string[0]\r\nfor char in string:\r\n if char > largest:\r\n largest = char\r\n\r\nprint(largest*string.count(largest))\r\n", "a=input()\r\nc=max(a)\r\nprint(c*a.count(c))", "n = input()\r\nq = max(n)\r\ns = 0\r\nfor i in n:\r\n if i in q:\r\n s += 1\r\nprint(q*s)\r\n", "s = input()\r\na = max(s)\r\nprint(a*s.count(a))", "s = input()\r\nz = []\r\n\r\nfor i in range(len(s)):\r\n z.append(s[i])\r\n\r\nx = max(z)\r\ncount = 0\r\nfor i in range(len(s)):\r\n if(s[i]==x):\r\n count+=1\r\nwhile(count):\r\n print(x,end=\"\")\r\n count-=1\r\n", "s = input()\r\n\r\nt = 0\r\nl = '0'\r\n\r\nfor c in s:\r\n if c > l:\r\n l = c\r\n t = 1\r\n elif c == l:\r\n t += 1\r\n\r\nprint(l * t)", "y=input()\r\nk=max(y)\r\nprint(k*y.count(k))\r\n", "s = input()\r\na = 0\r\ndic = {}\r\nfor i in s:\r\n\ta = max(a, ord(i))\r\n\tdic[i] = dic.get(i, 0) + 1\r\nprint(chr(a) * dic[chr(a)])\r\n", "from collections import Counter\r\n\r\nc = Counter(input())\r\nks = list(sorted(c.keys(), reverse = True))\r\nprint(ks[0] * c[ks[0]])", "s = input()\r\nc = s[0]\r\np = 1\r\nfor i in range(1, len(s)):\r\n if s[i] == c:\r\n p += 1\r\n elif s[i] > c:\r\n p = 1\r\n c = s[i]\r\nprint(c * p)\r\n", "v=input();a=max(v)\r\nprint(v.count(a)*a)\r\n", "#q1\r\n'''\r\nfor _ in range(int(input())):\r\n l=list(map(int,input().split()))\r\n\r\n x=l[1]\r\n y=l[2]\r\n z=l[2]\r\n\r\n print(x,y,z)\r\n''' \r\n#q2\r\n'''\r\nfor _ in range(int(input())):\r\n\r\n x,n,m=map(int,input().split())\r\n \r\n while(x>20 and n>0 and x > x//2+10):\r\n x=x//2+10\r\n n-=1\r\n\r\n if(x <= m*10):\r\n print(\"YES \")\r\n else:\r\n print(\"NO \")\r\n'''\r\n\r\n#q3 \r\n'''\r\ndef swap(s,j,mi):\r\n l=list(s)\r\n temp=l[j]\r\n l[j]=l[mi]\r\n l[mi]=temp\r\n\r\n s=''.join(l)\r\n\r\n return s\r\n\r\nfor _ in range(int(input())):\r\n\r\n s,t=input().split()\r\n\r\n k=0\r\n for i in range(len(s)):\r\n if ord(s[i]) < ord(t[i]):\r\n k=1\r\n break\r\n\r\n elif ord(s[i]) == ord(t[i]):\r\n continue\r\n\r\n else:\r\n mi=i\r\n for j in range(i+1,len(s)):\r\n if ord(s[j]) < ord(t[mi]):\r\n s=swap(s,j,mi)\r\n k=1\r\n break\r\n break\r\n if k==1:\r\n print(s)\r\n\r\n else:\r\n print('---')\r\n\r\n'''\r\n\r\n#q4\r\n'''\r\nimport math\r\n\r\ndef lcm(n):\r\n p=n\r\n t=int(math.sqrt(n))+1\r\n l=[0]*n\r\n l[0]=1\r\n \r\n while n%2 == 0:\r\n if n//2==2:\r\n l[2-1]+=1\r\n else:\r\n l[2-1]+=1\r\n l[(n//2)-1]+=1\r\n n=n//2\r\n\r\n for i in range(3,t):\r\n while n%i==0:\r\n\r\n if n//i==i:\r\n l[i-1]+=1\r\n else:\r\n l[i-1]+=1\r\n l[(n//i)-1]+=1\r\n \r\n n=n//i\r\n\r\n print(l)\r\n d=set()\r\n for i in range(p):\r\n# print('1')\r\n if l[i]!=0:\r\n d.add(pow((i+1),l[i]))\r\n# print('2')\r\n\r\n print(d)\r\n return list(d)\r\n \r\nn=int(input())\r\n\r\nf=lcm(n)\r\nprint(f)\r\n\r\nif len(f)==1 or len(f)==2:\r\n print('1',n)\r\n\r\nelse:\r\n t1=f[1]\r\n t2=f[2]\r\n k=min(t1,t2)\r\n for i in range(3,len(f)):\r\n if t1==k:\r\n t1*=k\r\n else:\r\n t2*=k\r\n k=min(t1,t2)\r\n\r\n print(t1,t2)\r\n \r\n''' \r\n \r\n#q5\r\n'''\r\nfor _ in range(int(input())):\r\n\r\n string=input()\r\n i=0\r\n de=0\r\n z=[]\r\n \r\n while i<len(string)-2:\r\n\r\n if string[i:i+5]==\"twone\":\r\n de+=1\r\n z.append(i+2)\r\n i+=5\r\n\r\n elif string[i:i+3]==\"one\":\r\n de+=1\r\n z.append(i+1)\r\n i+=3\r\n\r\n elif string[i:i+3]==\"two\":\r\n de+=1\r\n z.append(i+1)\r\n i+=3 \r\n \r\n else:\r\n i+=1\r\n\r\n print(de)\r\n for i in range(len(z)):\r\n print(z[i]+1,end=\" \")\r\n\r\n print()\r\n''' \r\n\r\n#string modification ****\r\n'''\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n\r\n string=input()\r\n\r\n l=list(string)\r\n \r\n for k in range(n):\r\n first=n-k\r\n\r\n for i in range(first):\r\n second=i+k\r\n\r\n l[i:second+1:1]=l[second:i-1:-1]\r\n print(l)\r\n\r\n print(l)\r\n\r\n'''\r\n\r\n#remove adjacent\r\n'''\r\nn=int(input())\r\n\r\nstring=input()\r\nl=list(string)\r\n#print(l)\r\nde=0\r\n\r\nwhile(1):\r\n q=l\r\n a=[]\r\n t=0\r\n \r\n for i in range(1,len(l)):\r\n a.append(ord(q[i])-ord(q[i-1]))\r\n \r\n if((1 in a) or (-1 in a)) :\r\n for i in range(len(a)):\r\n if a[i]==-1:\r\n l.pop(i-t)\r\n t+=1\r\n de+=1\r\n# print(l)\r\n\r\n elif a[i]==1:\r\n l.pop(i+1-t)\r\n t+=1\r\n de+=1\r\n# print(l)\r\n\r\n print(l)\r\n \r\n else:\r\n break\r\nprint(de)\r\n''' \r\n\r\n\r\n#Yet Another Counting Problem\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\ndef solve(r,lcm,b):\r\n\r\n no_of_term=r//lcm\r\n product=no_of_term*lcm\r\n\r\n tot=r\r\n\r\n if product!=0:\r\n\r\n tot-=min(b,(r-product+1))\r\n tot-=(no_of_term-1)*b\r\n \r\n return tot-min(r,b-1)\r\n\r\nfor _ in range(int(input())):\r\n\r\n a,b,q=map(int,input().split())\r\n if a>b:\r\n a,b=b,a\r\n \r\n gc=gcd(a,b)\r\n product=a*b\r\n lcm=product//gc\r\n \r\n for i in range(q):\r\n l,r=map(int,input().split())\r\n\r\n ans1=solve(r,lcm,b)\r\n if l>=b:\r\n ans2=solve(l-1,lcm,b)\r\n ans=ans1-ans2\r\n else:\r\n ans=ans1\r\n \r\n print(ans,end=\" \")\r\n print()\r\n'''\r\n\r\n#number game\r\n'''\r\nimport math\r\n\r\nimport math\r\n\r\nf='FastestFinger'\r\na='Ashishgup'\r\ndef prime(n):\r\n \r\n r=int(math.sqrt(n))+1\r\n \r\n if n%2==0 and n!=2:\r\n return False\r\n\r\n for i in range(3,r):\r\n if n % i ==0:\r\n return False\r\n \r\n return True\r\n \r\ndef solve(n):\r\n\r\n if n==0 :\r\n return\r\n elif n==1:\r\n return f\r\n \r\n dp=[]\r\n dp.append(0)\r\n \r\n \r\nfor _ in range(int(input())):\r\n\r\n n=int(input())\r\n if prime(n) and n>1:\r\n print(\"Ashishgup\")\r\n else:\r\n print(solve(n))\r\n\r\n'''\r\n\r\n#Ciel and Flowers\r\n'''\r\nl=list(map(int,input().split()))\r\nt=list(l)\r\n\r\nsu1=0\r\n\r\nfor i in range(3):\r\n su1+=int(l[i]/3)\r\n l[i]=l[i]%3\r\n \r\nif min(l)!=0: \r\n su1+=min(l)\r\n\r\nq=min(t)\r\nsu2=q\r\n\r\nfor i in range(3):\r\n t[i]-=q\r\n\r\nfor i in range(3):\r\n su2+=int(t[i]/3)\r\n \r\nprint(max(su2,su1))\r\n'''\r\n\r\n\r\n#Count Subrectangles\r\n'''\r\ndef row(n,m,k,c):\r\n\r\n l=[]\r\n for i in range(n):\r\n su=0\r\n for j in range(k):\r\n su+=c[i][j]\r\n l.append(su)\r\n\r\n for i in range(): \r\n\r\nn,m,k=map(int,input().split())\r\n\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\n\r\nc=[[0 for i in range(m)]for j in range(n)]\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n c[i][j]=a[i]*b[j]\r\n\r\nrow(n,m,k,c)\r\n\r\n''' \r\n\r\n#Ciel and Flowers\r\n'''\r\na,b,c=map(int,input().split())\r\n\r\nans1=a//3+b//3+c//3\r\nans2=ans3=0\r\n\r\nif a>0 and b>0 and c>0:\r\n a-=1\r\n b-=1\r\n c-=1\r\n\r\n ans2=a//3+b//3+c//3\r\n\r\n ans2+=1\r\n\r\nif a>0 and b>0 and c>0 :\r\n a-=1\r\n b-=1\r\n c-=1\r\n\r\n ans3=a//3+b//3+c//3\r\n\r\n ans3+=2\r\n\r\nprint(max(ans1,ans2,ans3))\r\n''' \r\n\r\n#Way Too Long Words\r\n'''\r\nfor _ in range(int(input())):\r\n\r\n s=input()\r\n ans=\"\"\r\n \r\n if len(s)>10:\r\n t=str(len(s)-2)\r\n ans+=s[0]+t+s[len(s)-1]\r\n\r\n else:\r\n ans+=s\r\n\r\n print(ans)\r\n'''\r\n\r\n#Progress Bar\r\n'''\r\nn,k,t=map(int,input().split())\r\n\r\na1=n*k\r\n\r\na2=t*a1/100\r\n\r\na3=int(a2/k)\r\n\r\ns=int(a2-a3*k)\r\n\r\nif s>0:\r\n for i in range(n):\r\n if i<a3:\r\n print(k,end=\" \")\r\n elif i==a3:\r\n print(s,end=\" \")\r\n else:\r\n print('0',end=\" \")\r\n\r\nelse:\r\n for i in range(n):\r\n if i<a3:\r\n print(k,end=\" \")\r\n\r\n else:\r\n print('0',end=\" \")\r\n \r\n'''\r\n\r\n# Required Remainder\r\n'''\r\nfor _ in range(int(input())):\r\n\r\n x,y,n=map(int,input().split())\r\n t1=n//x\r\n t2=t1*x\r\n# print(t1,t2)\r\n \r\n if y==0:\r\n print(t2)\r\n else:\r\n a=x-y\r\n \r\n if y+t2<=n:\r\n print(y+t2)\r\n else:\r\n print(t2-a)\r\n''' \r\n \r\n'''\r\nt1=12345//7\r\nprint(t1)\r\nt2=t1*7\r\nprint(t2)\r\n'''\r\n\r\n# Multiply by 2, divide by 6\r\n'''\r\nimport math\r\n\r\ndef factoriation(n):\r\n k=int(math.sqrt(n))+1\r\n \r\n l=[0]*k\r\n\r\n t=0\r\n l[0]=0\r\n l[1]=0\r\n \r\n \r\n while n%2==0:\r\n t+=1\r\n n=n//2\r\n \r\n l[2]=t\r\n\r\n for i in range(3,k):\r\n t=0\r\n while n%i==0:\r\n t+=1\r\n n=n//i\r\n l[i]=t\r\n \r\n if n==1:\r\n return l\r\n else:\r\n return [0,0,0,0]\r\n \r\n return l\r\n\r\nfor _ in range(int(input())):\r\n\r\n n=int(input())\r\n\r\n if n==6:\r\n print('1')\r\n\r\n elif n==3:\r\n print('2')\r\n\r\n elif n==1:\r\n print('0')\r\n \r\n elif n>=9:\r\n l=factoriation(n)\r\n\r\n if l[3] >= l[2] and l[3]!=0:\r\n ans=-1\r\n ans=l[2]\r\n l[3]=l[3]-l[2]\r\n l[2]=0\r\n\r\n ans+=l[3]*2\r\n\r\n print(ans)\r\n \r\n else:\r\n print('-1')\r\n\r\n else:\r\n print('-1')\r\n\r\n'''\r\n\r\n# Move Brackets\r\n'''\r\nfor _ in range(int(input())):\r\n\r\n n=int(input())\r\n\r\n string=input()\r\n\r\n ans=0\r\n x2=0\r\n \r\n for i in range(n):\r\n if string[i]==')':\r\n if x2==0:\r\n ans+=1\r\n else:\r\n x2-=1\r\n\r\n elif string[i]==\"(\":\r\n x2+=1\r\n\r\n print(ans)\r\n''' \r\n\r\n#Petya and Strings\r\n'''\r\nstring1=input().lower()\r\nstring2=input().lower()\r\n\r\nfor i in range(len(string1)):\r\n\r\n if string1[i] > string2[i]:\r\n print('1')\r\n break\r\n elif string1[i] < string2[i] :\r\n print('-1')\r\n break\r\n \r\n else:\r\n if i==len(string1)-1:\r\n print('0')\r\n break\r\n else:\r\n continue\r\n'''\r\n\r\n#Helpful maths\r\n'''\r\nstring=input()\r\nli=list(string.split(\"+\"))\r\nl=[0]*3\r\n\r\nli.sort()\r\n\r\nfor i in range(len(li)):\r\n if i!=len(li)-1:\r\n print(li[i]+'+',end=\"\")\r\n else:\r\n print(li[i])\r\n'''\r\n\r\n#word capitalisation\r\n'''\r\nstring=input()\r\n\r\nif ord(string[0])>96:\r\n print(chr(ord(string[0])-32)+string[1:])\r\n\r\nelse:\r\n print(string)\r\n'''\r\n\r\n#Boy or Girl\r\n'''\r\nstring=input()\r\n\r\nl=[0]*26\r\n\r\nfor i in range(len(string)):\r\n l[ord(string[i])-97]+=1\r\n\r\nk=0\r\nfor i in range(26):\r\n if l[i]>0:\r\n k+=1\r\n\r\nif k%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')\r\n'''\r\n\r\n#Translation\r\n'''\r\ns=input()\r\nt=input()\r\n\r\nk=\"\"\r\n\r\nfor i in range(len(s)-1,-1,-1):\r\n k+=s[i]\r\n\r\nif k==t:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n'''\r\n\r\n#Word\r\n'''\r\nstring=input()\r\nlower=0\r\nupper=0\r\n\r\n\r\nfor i in range(len(string)):\r\n if ord(string[i])>96:\r\n lower+=1\r\n\r\n else:\r\n upper+=1\r\n\r\nif upper>lower:\r\n print(string.upper())\r\n\r\nelse:\r\n print(string.lower())\r\n \r\n'''\r\n\r\n# Anton and Danik\r\n'''\r\nn=int(input())\r\n\r\nstring=input()\r\n\r\nA=0\r\nD=0\r\n\r\nfor i in range(n):\r\n if string[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\n\r\nelse:\r\n print(\"Friendship\")\r\n'''\r\n\r\n#Football\r\n'''\r\nstring=input()\r\na=b=0\r\n\r\nfor i in range(len(string)):\r\n\r\n if string[i]=='0':\r\n a+=1\r\n b=0\r\n\r\n else:\r\n b+=1\r\n a=0\r\n\r\n if a==7 or b==7:\r\n t=1\r\n break\r\n\r\n else:\r\n t=0\r\n\r\nif t==1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n'''\r\n\r\n#Dubstep\r\n'''\r\nstring=input()\r\ns=\"\"\r\ni=0\r\nwhile i<len(string)-2:\r\n\r\n if string[i]==\"W\" and string[i+1]==\"U\" and string[i+2]==\"B\":\r\n i+=3\r\n s+=\" \"\r\n\r\n else:\r\n s+=string[i]\r\n i+=1\r\n\r\nif i>=len(string): \r\n print(' '.join(s.split()))\r\n \r\nelse:\r\n s+=string[i]\r\n i+=1\r\n \r\n if i>=len(string):\r\n print(' '.join(s.split()))\r\n else:\r\n s+=string[i]\r\n print(' '.join(s.split()))\r\n'''\r\n\r\n#Two_gram\r\n'''\r\nn=int(input())\r\nstring=input()\r\n\r\nres=0\r\n\r\nfor i in range(len(string)-1):\r\n cur=0\r\n for j in range(i,len(string)-1):\r\n\r\n if string[i]==string[j] and string[i+1]==string[j+1]:\r\n cur+=1\r\n\r\n if res < cur:\r\n\r\n res=cur\r\n ans=string[i]+string[i+1]\r\n\r\nprint(ans)\r\n'''\r\n\r\n#Even But Not Even\r\n'''\r\nfor _ in range(int(input())):\r\n\r\n n=int(input())\r\n string=input()\r\n l=list(string)\r\n su=0\r\n \r\n for i in range(len(string)-1,-1,-1):\r\n su+=int(l[i])\r\n if l[i]==\"0\":\r\n l.pop(i)\r\n# print(su)\r\n if su%2!=0:\r\n if int(string)%2==0:\r\n for i in range(len(l)-1,-1,-1):\r\n if int(l[i])%2==0:\r\n l.pop(i)\r\n else:\r\n break\r\n for i in range(len(l)-2,-1,-1):\r\n if int(l[i])%2!=0:\r\n l.pop(i)\r\n break\r\n \r\n if len(l)>1: \r\n print(''.join(i for i in l))\r\n\r\n else:\r\n print('-1')\r\n \r\n else:\r\n# print(l)\r\n for i in range(len(l)-2,-1,-1):\r\n if int(l[i])%2!=0:\r\n l.pop(i)\r\n break\r\n\r\n if len(l)>2:\r\n print(''.join(i for i in l))\r\n elif len(l)==2 and int(l[0])%2!=0:\r\n print(''.join(i for i in l))\r\n else:\r\n print('-1')\r\n\r\n else:\r\n# print(su)\r\n if int(string)%2!=0:\r\n print(''.join(i for i in l))\r\n else:\r\n for i in range(len(l)-1,-1,-1):\r\n if int(l[i])%2==0:\r\n l.pop(i)\r\n else:\r\n break\r\n if len(l)>1:\r\n print(''.join(i for i in l))\r\n else:\r\n print('-1')\r\n\r\n'''\r\n\r\n# Delete from the Left\r\n'''\r\ns=input()\r\nt=input()\r\nq=0\r\n\r\n\r\ni1=len(t)-1\r\ni2=len(s)-1\r\n \r\nwhile i1>=0 and i2>=0:\r\n if s[i2]==t[i1]:\r\n q+=1\r\n i1-=1\r\n i2-=1\r\n \r\n else:\r\n break\r\n\r\n\r\nsu1=len(s)-q\r\n#print(su1,q)\r\nsu2=len(t)-q\r\nprint(su1+su2)\r\n\r\n'''\r\n\r\n#Important exam\r\n'''\r\nn,m=map(int,input().split())\r\nk=[]\r\n \r\nfor i in range(n):\r\n string=input()\r\n l=list(string)\r\n k.append(l)\r\n\r\nq=list(map(int,input().split()))\r\nsu=0\r\n\r\nfor i in range(m):\r\n t1=t2=t3=t4=t5=0\r\n\r\n for j in range(n):\r\n if k[j][i]==\"A\":\r\n t1+=1\r\n\r\n elif k[j][i]==\"B\":\r\n t2+=1\r\n\r\n elif k[j][i]==\"C\":\r\n t3+=1\r\n\r\n elif k[j][i]==\"D\":\r\n t4+=1\r\n\r\n else:\r\n t5+=1\r\n\r\n a=max(t1,t2,t3,t4,t5)\r\n su+=a*q[i]\r\n\r\nprint(su)\r\n \r\n'''\r\n\r\n# Letters Rearranging\r\n'''\r\nfor _ in range(int(input())):\r\n\r\n string=input()\r\n t=1\r\n j=0\r\n \r\n for i in range(len(string)-1):\r\n if string[i] == string[i+1]:\r\n t+=1\r\n else:\r\n j=i+1\r\n break\r\n\r\n if t==len(string):\r\n print('-1')\r\n \r\n else:\r\n k=0\r\n for i in range(len(string)//2):\r\n if string[i]==string[len(string)-1-i]:\r\n k+=2\r\n\r\n if len(string)%2==0 and k==len(string):\r\n l=list(string)\r\n l[0],l[j]=l[j],l[0]\r\n print(''.join(i for i in l))\r\n\r\n elif len(string)%2==1 and k==len(string)-1:\r\n l=list(string)\r\n l[0],l[j]=l[j],l[0]\r\n print(''.join(i for i in l))\r\n\r\n else:\r\n print(string)\r\n'''\r\n\r\n#Romaji\r\n'''\r\nstring=input()\r\nt=0\r\n\r\nif string[len(string)-1]=='n' or string[len(string)-1]=='a' or string[len(string)-1]=='e' or string[len(string)-1]=='i' or string[len(string)-1]=='o' or string[len(string)-1]=='u':\r\n t=1\r\n for i in range(0,len(string)-1):\r\n\r\n if (string[i]!='n' or string[i]!='a' or string[i]!='e' or string[i]!='i' or string[i]!='o' or string[i]!='u') and (string[i+1]=='a' or string[i+1]=='e' or string[i+1]=='i' or string[i+1]=='o' or string[i+1]=='u'):\r\n t=1\r\n \r\n elif (string[i]=='a' or string[i]=='e' or string[i]=='i' or string[i]=='o' or string[i]=='u') and string[i+1]=='a' or string[i+1]=='e' or string[i+1]=='i' or string[i+1]=='o' or string[i+1]=='u':\r\n t=1\r\n \r\n elif string[i]=='n':\r\n t=1\r\n\r\n elif string[i]=='a' or string[i]=='e' or string[i]=='i' or string[i]=='o' or string[i]=='u':\r\n t=1\r\n \r\n else:\r\n t=0\r\n break\r\n\r\nelse:\r\n t=0\r\n \r\nif t==0:\r\n print('NO')\r\nelse:\r\n print(\"YES\")\r\n\r\n'''\r\n\r\n#String Task\r\n'''\r\nstring=input().lower()\r\n\r\nl=['a','e','i','o','u','y']\r\nk=list(string)\r\ni=0\r\n\r\nwhile i <len(k):\r\n if k[i] in l:\r\n k.pop(i)\r\n else:\r\n i+=1\r\n \r\nfor i in range(len(k)):\r\n \r\n print('.'+k[i],end=\"\")\r\n'''\r\n\r\n#chat room\r\n'''\r\nstring=input().lower()\r\n\r\nif len(string)<5:\r\n print(\"NO\")\r\nelse:\r\n l=['h','e','l','l','o']\r\n k=list(string)\r\n i=0\r\n \r\n while i<len(k):\r\n if k[i]==l[0]:\r\n l.pop(0)\r\n i+=1\r\n\r\n else:\r\n i+=1\r\n\r\n if len(l)==0:\r\n break\r\n\r\n if len(l)==0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n'''\r\n\r\n#cAPS lOCK\r\n'''\r\nstring=input()\r\n\r\na1=a=b=0\r\nl=list(string)\r\n\r\nif ord(l[0])<91:\r\n a1+=1\r\nelse:\r\n a1=0\r\n \r\nfor i in range(1,len(string)):\r\n\r\n if ord(l[i])<91:\r\n b+=1\r\n\r\nif a1==0 and b==len(l)-1:\r\n for i in range(len(l)):\r\n if i==0:\r\n print(chr(ord(l[i])-32),end=\"\")\r\n else:\r\n print(chr(ord(l[i])+32),end=\"\")\r\n \r\nelif a1==1 and b==len(l)-1:\r\n for i in range(len(l)):\r\n print(chr(ord(l[i])+32),end=\"\")\r\n\r\nelse:\r\n print(string)\r\n \r\n'''\r\n\r\n#Lecture\r\n'''\r\nn,m=map(int,input().split())\r\nq1=[]\r\nq2=[]\r\n\r\nfor i in range(m):\r\n a,b=input().split()\r\n q1.append(a)\r\n q2.append(b)\r\n\r\nk=input()\r\n\r\nl=list(k.split())\r\n\r\nfor i in range(n):\r\n\r\n a=q1.index(l[i])\r\n if len(q1[a]) > len(q2[a]):\r\n print(q2[a],end=\" \")\r\n else:\r\n print(q1[a],end=\" \")\r\n'''\r\n\r\n# Football\r\n'''\r\nl=[1,0]\r\n\r\nt=int(input())\r\nstring=input()\r\n\r\nfor i in range(1,t):\r\n\r\n n=input()\r\n if n==string:\r\n l[0]+=1\r\n else:\r\n j=n\r\n l[1]+=1\r\n\r\nif l[0]>l[1]:\r\n print(string)\r\n\r\nelse:\r\n print(j)\r\n'''\r\n\r\n#Pangram\r\n'''\r\nn=int(input())\r\n\r\nstring=input().lower()\r\nl=[0]*26\r\n\r\nif n>=26:\r\n \r\n for i in range(n):\r\n l[ord(string[i])-97]+=1\r\n\r\n if min(l)!=0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\nelse:\r\n print(\"NO\")\r\n'''\r\n\r\n#Amusing Joke\r\n'''\r\ns1=input().lower()\r\ns2=input().lower()\r\n\r\nstring=input().lower()\r\nl=[0]*26\r\n\r\nfor i in range(len(s1)):\r\n l[ord(s1[i])-97]+=1\r\n\r\nfor i in range(len(s2)):\r\n l[ord(s2[i])-97]+=1\r\n\r\nt=0\r\n\r\n\r\nfor i in range(len(string)):\r\n\r\n if l[ord(string[i])-97]!=0:\r\n# print(string[i],l[ord(string[i])-97])\r\n l[ord(string[i])-97]-=1\r\n\r\n else:\r\n t=1\r\n break\r\n\r\nif t==1:\r\n \r\n print(\"NO\")\r\n \r\nelif t==0 and max(l)==0:\r\n print(\"YES\")\r\n\r\nelse:\r\n print(\"NO\")\r\n\r\n'''\r\n\r\n#Night at the Museum\r\n'''\r\nstring=input()\r\n\r\nsu=min(ord(string[0])-97 - 0 , 26 - ord(string[0])+97 -0)\r\n\r\nfor i in range(1,len(string)):\r\n if string[i-1]>string[i]:\r\n su+=min(abs( (ord(string[i])-97) - (ord(string[i-1])-97 ) ), abs(26+ (ord(string[i])-97 ) - (ord(string[i-1])-97) ))\r\n else:\r\n su+=min(abs( (ord(string[i])-97) - (ord(string[i-1])-97 ) ), abs(26- (ord(string[i])-97 ) +(ord(string[i-1])-97) ))\r\n\r\nprint(su)\r\n'''\r\n\r\n#Cards\r\n'''\r\nn=int(input())\r\n\r\nstring=input()\r\nl=[0]*26\r\nq=[]\r\n\r\n\r\nfor i in range(n):\r\n l[ord(string[i])-97]+=1\r\n\r\nwhile max(l)!=0:\r\n if l[13]>=2 and l[8]>=1 and l[4]>=1:\r\n q.append(9)\r\n l[13]-=2\r\n l[8]-=1\r\n l[4]-=1\r\n\r\n elif l[4]>=1 and l[8]>=1 and l[6]>=1 and l[7]>=1 and l[19]>=1:\r\n q.append(8)\r\n l[4]-=1\r\n l[8]-=1\r\n l[6]-=1\r\n l[7]-=1\r\n l[19]-=1\r\n\r\n elif l[18]>=1 and l[4]>=2 and l[21]>=1 and l[13]>=1:\r\n q.append(7)\r\n l[18]-=1\r\n l[4]-=2\r\n l[21]-=1\r\n l[13]-=1\r\n\r\n elif l[18]>=1 and l[8]>=1 and l[23]>=1 :\r\n q.append(6)\r\n l[18]-=1\r\n l[8]-=1\r\n l[23]-=1\r\n\r\n elif l[5]>=1 and l[8]>=1 and l[21]>=1 and l[4]>=1:\r\n q.append(5)\r\n l[5]-=1\r\n l[8]-=1\r\n l[21]-=1\r\n l[4]-=1\r\n\r\n elif l[5]>=1 and l[14]>=1 and l[20]>=1 and l[17]>=1:\r\n q.append(4)\r\n l[5]-=1\r\n l[14]-=1\r\n l[20]-=1\r\n l[17]-=1\r\n \r\n elif l[19]>=1 and l[7]>=1 and l[17]>=1 and l[4]>=2:\r\n q.append(3)\r\n l[19]-=1\r\n l[7]-=1\r\n l[17]-=1\r\n l[4]-=2\r\n\r\n elif l[19]>=1 and l[22]>=1 and l[14]>=1:\r\n q.append(2)\r\n l[19]-=1\r\n l[22]-=1\r\n l[14]-=1\r\n\r\n elif l[14]>=1 and l[13]>=1 and l[14]>=1:\r\n q.append(1)\r\n l[14]-=1\r\n l[13]-=1\r\n l[4]-=1\r\n\r\n else:\r\n q.append(0)\r\n l[25]-=1\r\n l[4]-=1\r\n l[17]-=1\r\n l[14]-=1\r\n \r\n\r\nq=sorted(q,reverse=True)\r\nfor i in range(len(q)):\r\n print(q[i],end=\" \")\r\n\r\n''' \r\n\r\n#Telephone Number\r\n'''\r\nfor _ in range(int(input())):\r\n\r\n n=int(input())\r\n\r\n string=input()\r\n a=n-11\r\n t=0\r\n \r\n if a<0:\r\n t=1\r\n \r\n elif a==0 and string[0]!=\"8\":\r\n t=1\r\n \r\n else:\r\n l=list(string)\r\n\r\n while l[0]!='8':\r\n if a==0 and l[0]!=8:\r\n t=1\r\n break\r\n \r\n l.pop(0)\r\n a-=1\r\n\r\n if t==1:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n'''\r\n\r\n#LLPS\r\n\r\ndef subs(s):\r\n\r\n sub=[[]]\r\n\r\n for i in s:\r\n sub+=[lst + [i] for lst in sub]\r\n\r\n return sub\r\n\r\n \r\nstring=input()\r\n\r\nf=subs(list(string))\r\n\r\nq=[]\r\n\r\nfor i in range(len(f)):\r\n t=0\r\n for j in range(len(f[i])//2):\r\n \r\n if f[i][j]!=f[i][len(f[i])-j-1]:\r\n t=1\r\n break\r\n if t!=1:\r\n q.append(f[i])\r\n\r\nmax=q[0]\r\nfor i in range(1,len(q)):\r\n if max < q[i]:\r\n max=q[i]\r\n\r\nprint(''.join(i for i in max))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "s=input()\r\nl=list(s)\r\nl.sort()\r\na=l.count(l[-1])\r\nz=l[-1]*a\r\nprint(z)", "v=input();b=max(v)\r\nprint(v.count(b)*b)\r\n", "s=list(input());d={};m=max(s)\r\nfor i in s:\r\n\tif i in d:d[i]+=1\r\n\telse:d[i]=1\r\nprint(m*d[m])", "z=input();j=max(z)\r\nprint(j*z.count(j))\r\n", "s=input()\r\nd={}\r\n\r\nfor i in s:\r\n\tif ord(i) not in d:\r\n\t\td[ord(i)]=1\r\n\telse:\r\n\t\td[ord(i)]+=1\r\nm=max(d.keys())\r\nprint(chr(m)*d[m])", "y=input()\r\na=max(y);print(y.count(a)*a)\r\n", "import itertools\r\nstring=input()\r\ncombs = []\r\nfor l in range(1,len(string)+1):\r\n combs.append(list(itertools.combinations(string, l)))\r\nl1=[]\r\nfor i in combs:\r\n for j in i:\r\n temp=\"\"\r\n for k in j:\r\n temp+=k\r\n l1.append(temp)\r\nl1=list(set(l1))\r\nl2=[]\r\nfor i in l1:\r\n if i == i[::-1]:\r\n l2.append(i)\r\n \r\nprint(max(l2))", "s = sorted(input())\nc = s[-1]\ni = len(s) - 1\nv = s.count(c)\nwhile v:\n print(c, end='')\n v -= 1\n\n", "def main_function():\r\n s = input()\r\n max_val = s[0]\r\n counter = 0\r\n for i in s:\r\n if max_val == i:\r\n counter += 1\r\n if max_val < i:\r\n max_val = i\r\n counter = 1\r\n return max_val * counter\r\n\r\n\r\n\r\nprint(main_function())", "s = input()\r\nc= 'a'\r\nfor i in range(len(s)):\r\n if s[i] > c:\r\n c = s[i]\r\nh = 0\r\nfor i in range(len(s)):\r\n if s[i] == c:\r\n h += 1\r\nfor i in range(h):\r\n print(c, end='')\r\n ", "s = input()\r\nss = sorted(s)\r\n\r\nt = ss.index(max(ss))\r\nprint(''.join(ss[t:]))\r\n", "#rOkY\r\n#FuCk\r\n\r\n################################## kOpAl #####################################\r\n\r\n\r\ns=str(input())\r\nl=len(s)\r\nx=\"\".join(sorted(s))\r\nc=x[l-1]\r\nfor i in range(0,len(s),1):\r\n if(x[i]==c):\r\n print(x[i],end='')\r\nprint()\r\n", "s = input()\r\nans = 0\r\nfor i in s:\r\n if ord(i) > ans:\r\n ans = ord(i)\r\nprint(chr(ans) * s.count(chr(ans)))", "s = list(input())\r\na = max(s)\r\nb = s.count(a)\r\nprint(a*b)", "a = input()\r\nb = {}\r\nfor i in range(len(a)):\r\n if a[i] not in b:\r\n b[a[i]] = 1\r\n else:\r\n b[a[i]]+=1\r\no = 'a'\r\nfor i in b:\r\n if o<i:\r\n o = i\r\nprint(b[o]*o)", "from collections import *\r\nfrom sys import *\r\ninp=stdin.readline\r\nout=print\r\ns=inp()\r\nans=0\r\nfor i in s:\r\n if ord(i)>ans:\r\n ans=ord(i)\r\nsco=Counter(s)\r\nans1=sco[chr(ans)]\r\nout(chr(ans)*ans1)", "def llps(s):\r\n h = s[0]\r\n for letter in s[1:]:\r\n if letter > h:\r\n h = letter\r\n return ''.join(letter for letter in s if letter == h)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n print(llps(input()))", "n = input()\r\nm = \"\"\r\nfor i in n : \r\n if i > m : \r\n m = i\r\n continue\r\n if i in m : \r\n m = m + i\r\n \r\nprint(m) ", "s = input()\r\ndict = {}\r\nfor i in s:\r\n if i in dict:\r\n dict[i]+=1\r\n else:\r\n dict[i]=1\r\nx = max(dict)\r\nn = dict[x]\r\nfor i in range(n):\r\n print(x,end='')\r\nprint()\r\n", "s = input()\r\nmx = ''\r\n\r\nfor i in s:\r\n if i > mx:\r\n mx = i\r\n\r\nd = s.count(mx,0,len(s))\r\n\r\nfor _ in range(1, d + 1):\r\n print(mx, end = '')\r\n", "s=input()\nl=list(s)\nl.sort(reverse=True)\nn1=l[0]\nn2=l.count(n1)\nfor i in range(n2):\n print(l[i],end='')\n\n\t\t \t\t\t \t\t \t\t\t\t\t \t\t\t\t \t", "s = input()\r\nm = \"\"\r\nmi = 0\r\nn = len(s)\r\nfor i in range(n):\r\n if s[i] > m:\r\n m = s[i]\r\n mi = i\r\ncount = 1\r\nfor j in range(mi+1, n):\r\n if s[j] == m:\r\n count += 1\r\nprint(m * count)", "str = input()\r\nmax = 'a'\r\nfor char in str:\r\n if char > max:\r\n max = char\r\ncount = 0\r\n#print(max)\r\nfor char in str:\r\n if char == max:\r\n count+=1\r\nprint(max*count)", "str=input()\r\nmax='a'\r\nfor i in str:\r\n if max<i:\r\n max=i\r\nL=[max for i in range(0,str.count(max))]\r\nstr1=''.join(j for j in L)\r\nprint(str1)\r\n", "#hello this is my program\nn=input()\nz=max(n)\nprint(z*n.count(z))\n\t \t\t\t\t \t\t\t \t\t\t \t \t \t\t\t\t\t\t", "s=input()\r\ns=sorted(s)\r\nc=s.count(s[len(s)-1])\r\ns1=s[len(s)-c]*c\r\nprint(s1)", "from collections import Counter\r\ns = input()\r\nm = Counter(s)\r\nletter = max(m.keys())\r\nprint(letter*m[letter])", "import sys\r\nimport math\r\nimport bisect\r\nimport heapq\r\nimport string\r\nfrom collections import defaultdict,Counter,deque\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\n\r\n1\r\n1 2 | 2 1\r\n1 2 3 | \r\n\r\n1 2 3 4 | 1 3 2 4\r\n'''\r\n\r\n# sys.stdin = open(\"backforth.in\", \"r\")\r\n# sys.stdout = open(\"backforth.out\", \"w\")\r\ninput = sys.stdin.readline\r\n\r\ndef dist(c1, c2):\r\n return abs(c1[0] - c2[0]) + abs(c1[1] - c2[1])\r\n\r\ndef solve():\r\n s = I().strip()\r\n c = Counter(s)\r\n\r\n # best = ''\r\n # for letter in string.ascii_lowercase:\r\n # if letter > best and c[letter] & 1:\r\n # best = letter\r\n\r\n # ans = deque([letter] * c[letter])\r\n\r\n ans = []\r\n for letter in string.ascii_lowercase[::-1]:\r\n if letter in c:\r\n ans = [letter] * c[letter]\r\n break\r\n\r\n WNS(ans)\r\n \r\n\r\nsolve()", "s=input()\r\nz=' '\r\nfor i in s:\r\n if ord(i)>ord(z):\r\n z=i\r\nprint(z*s.count(z)) ", "s = input()\r\nfor ch in list('zyxwvutsrqponmlkjihgfedcba'):\r\n cnt = s.count(ch)\r\n if cnt > 0:\r\n print(ch*cnt)\r\n break\r\n\r\n", "s=input()\r\nl=sorted(s,reverse=True)\r\nprint(l[0]*l.count(l[0]))\r\n", "#nums = list(map(int, input().split()))\r\nfrom collections import Counter\r\ns = input()\r\nfreq = Counter(s)\r\ns = list(s)\r\ns.sort()\r\n\r\nprint(freq[s[-1]]*s[-1])\r\n\r\n", "s = input()\r\ndef largestPalinSub(s):\r\n \r\n res = \"\"\r\n mx = s[0]\r\n \r\n for i in range(1, len(s)):\r\n mx = max(mx, s[i])\r\n \r\n for i in range(0, len(s)):\r\n if s[i] == mx:\r\n res += s[i]\r\n \r\n return res\r\nprint(largestPalinSub(s))", "s = input()\r\n\r\nif len(s)==0:\r\n print()\r\nelse:\r\n d = [0] * 26\r\n for c in s:\r\n d[ord(c)-97] += 1\r\n\r\n for i in range(25,-1,-1):\r\n if d[i] > 0:\r\n print(chr(i+97) * d[i])\r\n break", "s = input()\n\nhigh = '1'\n\nfor c in s: \n if ord(c) >ord(high): \n high = c\n\nres = ''\n\nfor c in s: \n if c == high: \n res += c\nprint(res)\n", "import itertools\n\ndef is_palindrome(string):\n for i in range(len(string)//2):\n if string[i] != string[~i]:\n return False\n return True\n\nlargest = \"\"\nstring = [s for s in input()]\n\nfor arr in itertools.product([True, False], repeat=len(string)):\n s = [a for a, b in zip(string, arr) if b]\n s = \"\".join(s)\n if is_palindrome(s):\n largest = max(s, largest)\n\nprint(largest)\n\n\t\t \t \t \t\t \t \t \t\t\t\t\t", "s = str(input())\r\nns = sorted(s)\r\nl = ns[-1]\r\nc = list(s).count(l)\r\nprint(l * c)", "import sys\r\nimport itertools\r\n# sys.stdin = open(\"/home/leon/local/projects/cpp trky lessons/hackerrank/algorithms/codeforces/temp.txt\")\r\n\r\ns = input()\r\nans = ''\r\nfor i in range(len(s)+1):\r\n\tfor j in itertools.combinations(s, i):\r\n\t\tif ''.join(j)==''.join(reversed(j)) and ''.join(j) > ans:\r\n\t\t\tans = ''.join(j)\r\n\r\nprint(ans)", "import sys\r\ndef input(): return sys.stdin.readline().strip()\r\ndef getints(): return map(int,sys.stdin.readline().strip().split())\r\n\r\ns = list(input())\r\nm = max(s)\r\nprint(m*s.count(m))", "s = list(input())\r\na = list(set(s))\r\nanss = []\r\nfor i in range(len(a)):\r\n anss.append(a[i]*s.count(a[i]))\r\nprint(max(anss))", "from itertools import combinations\nstring = input()\ncombs = []\nanswers = []\nfor i in range(1, len(string)+1):\n combs.append(list(combinations(string, i)))\nfor i in range(len(combs)-1, -1, -1):\n for j in range(len(combs[i])-1, -1, -1):\n palindromestring = ''.join(combs[i][j])\n if palindromestring==palindromestring[::-1]:\n answers.append(palindromestring)\nanswers.sort()\nprint(answers[-1])", "z=input()\r\nprint(z.count(max(z))*max(z))", "s = input()\r\nalphabet='abcdefghijklmnopqrstuvwxyz'\r\na = alphabet[::-1]\r\nfor i in a:\r\n if(s.count(i)>0):\r\n print(i*s.count(i))\r\n break\r\n ", "s = input()\r\n\r\nquant = [0] * 26\r\n\r\nfor i in range(len(s)):\r\n quant[ord(s[i])-97] += 1\r\n \r\nres = \"\"\r\nfor i in range(25, -1, -1):\r\n if quant[i] > 0:\r\n res = chr(i + 97) * quant[i] \r\n break\r\nprint(res)", "y=input();k=max(y);print(k*y.count(k))\r\n", "n=list(input())\r\nn.sort()\r\nprint(n[-1]*n.count(n[-1]))", "y=input()\r\na=max(y)\r\nprint(y.count(a)*a)\r\n", "from itertools import combinations\r\ns = str(input())\r\nans = []\r\n\r\nfor i in range(1,len(s)+1):\r\n a = combinations(s,i)\r\n for j in a:\r\n y = ''.join(j)\r\n ans.append(y)\r\nans_list = list(set(ans))\r\nans = []\r\nfor word in ans_list:\r\n if word == word[::-1]:\r\n ans.append(word) \r\nlis =[]\r\nfor w in list(ans) :\r\n flag = 0 \r\n for i in range(len(w)-1):\r\n if (ord(w[i]) > ord(w[i+1])):\r\n flag = 1\r\n break\r\n if flag == 0:\r\n lis.append(w)\r\nlis.sort(reverse=True)\r\nprint(lis[0])", "s=input()\r\na=[]\r\nfor i in s:\r\n a.append(i)\r\na.sort()\r\nf=''\r\nfor i in range(len(s)-2,-1,-1):\r\n if a[i]==a[i+1]:\r\n f+=a[i]\r\n else:\r\n break\r\nf+=a[len(s)-1]\r\nprint(f)\r\n", "s = input()\n\nl = list(s) #convert the given string into a list of characters \nk = [] \nfor i in l: #converts the characters into ascii values and appends to a list\n k.append(ord(i))\n\n#print(k)\n#print(chr(max(k)))\na = l.count(chr(max(k)))\n\np = [] #finding the character corresponding to the maximum ascii value\nif chr(max(k)) in l:\n p.append(chr(max(k)))\n\n\n#print(p)\n\nwhile(a>0):\n print(chr(max(k)),end=\"\")\n a = a-1\n\n\n", "string = input()\r\nb = max(string) # highest letter\r\n# print(b)\r\nc = \"\" # frequency of highest letter\r\nfor i in string:\r\n if i == b:\r\n c = c + i\r\nprint(c)\r\n\r\n", "from collections import Counter\r\ns = list(input())\r\ndic = Counter(s)\r\nl = sorted([(k, v) for k, v in dic.items()])\r\nprint(l[-1][0] * l[-1][1])\r\n\r\n", "s=sorted(input())\r\ns.reverse()\r\n#print(s[0],end='')\r\nfor i in range(len(s)):\r\n\tif s[0]==s[i]:\r\n\t\tprint(s[0],end='')\r\n", "\"\"\"\n\thttps://codeforces.com/problemset/problem/202/A\n\tInput\n\t\ts\tString consisting of lowercase english letters only\n\tOutput\n\t\t\tLexicographically largest palindromic subsequence\n\"\"\"\n\ns = list(input())\n\n# 1 - get all distinct letters\nletters = sorted(set(s))\n\nmax_letter = letters[-1]\n\nprint(max_letter * s.count(max_letter))", "n=input()\r\ns=list(n)\r\ns.sort()\r\ns1=max(set(s))\r\ncount=0\r\nfor i in s:\r\n if s1==i:\r\n count=count+1\r\n \r\nprint(count*s1) ", "s=input()\r\nx=max(s)\r\nprint(x*s.count(x))\r\n", "def palindrome(string):\r\n l = 0\r\n r = len(string) -1 \r\n\r\n while l <= r:\r\n if string[l] is not string[r]:\r\n return False\r\n \r\n l+=1\r\n r-=1\r\n \r\n return True\r\n\r\ndef pal_subseq(s):\r\n if len(s) is 0:\r\n return ['']\r\n\r\n smallerOutput = pal_subseq(s[1:])\r\n new = smallerOutput.copy()\r\n for i in range(len(smallerOutput)):\r\n newWord = s[0] + smallerOutput[i]\r\n if palindrome(newWord):\r\n new.append(newWord)\r\n \r\n return new\r\n\r\ns = str(input())\r\nx = pal_subseq(s)\r\n\r\nif len(x) is 0:\r\n print()\r\n\r\nelif len(x) is 1:\r\n print(x[0])\r\nelse:\r\n x.sort()\r\n print(x[len(x)-1])", "n=input() \r\nn=sorted(n)\r\nfor i in n:\r\n if i==n[-1]:\r\n print(i,end='')", "n=input()\r\ns=set(n)\r\nk=max(s)\r\nprint(k*n.count(k))", "s=sorted(input())\r\nprint(s[len(s)-1]*s.count(s[len(s)-1]))", "x = input()\r\nx = list(x)\r\nx.sort()\r\nz = max(x)\r\ny = x.count(z)\r\nres = (z * y)\r\nprint(res)\r\n\r\n", "s = list(input())\r\ns.sort()\r\na = s.count(s[-1])\r\n\r\nprint(s[-1]*a)", "c = input() ; print(max(c) * c.count(max(c)));", "word = input() \r\nresult = \"\"\r\nmaxStr = word[0]\r\nfor i in range(1, len(word)):\r\n maxStr = max(maxStr, word[i])\r\nfor i in range(len(word)):\r\n if word[i] == maxStr:\r\n result += word[i]\r\nprint(result)", "a = sorted(input())\r\nprint(a[-1]*a.count(a[-1]))", "x=list(input())\r\nm=max(x)\r\nprint(m*x.count(m))\r\n", "d = {x:0 for x in range(26)}\r\ns = input()\r\nfor i in s:\r\n d[ord(i) - ord('a')] += 1\r\nfor i in range(26):\r\n if d[i]!=0:\r\n cntr = d[i]\r\n c = chr(ord('a') + i)\r\nfor i in range(cntr):\r\n print(c,end='')\r\n", "string = input()\r\n\r\nmyList = [0] * 26\r\n\r\nfor char in string:\r\n myList[ord(char) - 97] += 1\r\n\r\nresult = \"\"\r\n\r\nfor i in range(25, -1, -1):\r\n if myList[i] != 0:\r\n for j in range(myList[i]):\r\n result += chr(i + 97)\r\n break\r\n\r\nprint(result)", "s=input()\r\nst_arr = []\r\nfor i in range(len(s)-1,-1,-1):\r\n for j in range(len(st_arr)):\r\n st_arr.append(s[i]+st_arr[j])\r\n st_arr.append(s[i])\r\nl=[]\r\nfor i in st_arr:\r\n if i==i[::-1]:\r\n l.append(i)\r\nprint(max(l))", "s= str(input())\r\nans= ''\r\nfor i in s:\r\n ans= max(ans,i)\r\nprint(s.count(ans) *ans)", "s=input()\r\ns=s.lower()\r\nm=max(s)\r\nprint(m*s.count(m))", "strs = input()\nstr1 = max(strs)\nnum = strs.count(str1)\nfor i in range(num):\n print(str1,end = \"\")\n\n \t \t \t \t \t\t \t\t\t\t \t\t\t \t", "substring =[\"\"]\r\ntempstring = []\r\ns = input()\r\na = len(s)\r\nfor i in range(a):\r\n tempstring = [z+s[i] for z in substring]\r\n substring = substring + tempstring\r\n tempstring.clear()\r\ndel substring[0]\r\n\r\npalindrome = []\r\nscore = []\r\nfor i in substring:\r\n if i == i[::-1]:\r\n palindrome.append(i)\r\n\r\nfor i in palindrome:\r\n y = 0\r\n for x in range(len(i)):\r\n y = y + (ord(i[x])-96)*(26**(9-x))\r\n score.append(y)\r\nprint(palindrome[score.index(max(score))])\r\n", "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\ns = input()\r\nvar = s[0]\r\nc = l.index(s[0])\r\n\r\nfor i in range(1,len(s)):\r\n if(l.index(s[i])>c):\r\n c=l.index(s[i])\r\n var = s[i]\r\nx = s.count(var)\r\nfor i in range(x):\r\n print(var,end=\"\")\r\n \r\n ", "def isPalindrom(c):\r\n rep = True\r\n for k in range(len(c)//2+1):\r\n if c[k] != c[len(c)-1-k]:\r\n rep = False\r\n return(rep)\r\n\r\ndef isBigger(c1,c2):\r\n rep = True\r\n for k in range(len(c1)):\r\n if len(c2)<k+1:\r\n break\r\n elif c1[k] < c2[k]:\r\n rep = False\r\n break\r\n elif c1[k] > c2[k]:\r\n break\r\n elif k==len(c1)-1:\r\n if len(c2) > len(c1):\r\n rep = False\r\n return(rep)\r\n\r\n\r\ndef sousChainesLen(k,c):\r\n l = []\r\n if k==1:\r\n for i in range(len(c)):\r\n l+=[c[i]]\r\n #print(\"salut1\")\r\n return(l)\r\n elif k == len(c):\r\n #\"print(\"salut2\")\r\n return([c])\r\n else:\r\n l1 = sousChainesLen(k-1, c[1::])\r\n for i in range(len(l1)):\r\n l+= [c[0]+l1[i]]\r\n l1 = sousChainesLen(k, c[1::])\r\n for i in range(len(l1)):\r\n l+= [l1[i]]\r\n return(l)\r\n \r\ndef sousChaines(c):\r\n l=[]\r\n for k in range(len(c)):\r\n l+=sousChainesLen(k+1,c)\r\n return(l)\r\n \r\ndef Rep(c): #Objectif: renvoyer la plus grosses sous chaine de c qui est un palindrome.\r\n rep = c[0]\r\n l = sousChaines(c)\r\n for k in range(len(l)):\r\n #print(\"wsh\")\r\n #if isPalindrom(l[k]): print(\"PAL EXISTE\")\r\n #if isBigger(l[k], rep): print(\"BIG EST LAAAAAAAAAAAA\")\r\n #print(l[k])\r\n if isPalindrom(l[k]) and isBigger(l[k],rep):\r\n #print(\"salut\")\r\n rep = l[k]\r\n return(rep)\r\n\r\n\r\n#rep = sousChaines('salut')\r\n#for k in range(len(rep)):\r\n# print(rep[k])\r\n\r\nprint(Rep(input()))\r\n#print(isBigger(\"rr\",\"r\"))\r\n#print(isBigger(\"r\",\"rr\"))", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Nov 20 09:15:20 2020\r\n\r\n\"\"\"\r\n\r\ninp_str = str(input())\r\np_str = ''\r\n\r\nmax_let = max(inp_str)\r\nlet_count = inp_str.count(max_let)\r\n\r\nprint(max_let*let_count)", "# import os\n# os.chdir(\"C:/Users/gerchik/Dropbox/courses/algorithms/codeforces\")\n# os.chdir(\"/Users/daniilgerchik/Library/CloudStorage/Dropbox/courses/algorithms/codeforces\")\n# from collections import Counter, defaultdict # deque\nfrom sys import stdin\n\n# int(stdin.readline().rstrip())\n# list(map(int, stdin.readline().rstrip().split()))\n# stdin = open(\"input.txt\")\ndef get_solution():\n # stdin = open(\"input.txt\")\n # n, H = map(int, stdin.readline().rstrip().split())\n s = list(stdin.readline().rstrip())\n \n max_s = max(s)\n res = max_s * len([1 for el in s if el == max_s])\n print(res)\n \n\nt = 1#int(stdin.readline().rstrip())\nfor _ in range(t):\n get_solution()\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "def array(arr, struc):\r\n return (list(map(struc, arr.split())))\r\n\r\n\r\ns = input()\r\nmx = s[0]\r\n\r\nfor i in range(len(s)):\r\n if s[i] > mx:\r\n mx = s[i]\r\n\r\nt = [i for i, v in enumerate(s) if s[i] == mx]\r\n\r\nprint(mx*len(t))\r\n", "def main():\r\n a = input()\r\n len_a = len(a)\r\n al = [0] * 27\r\n \r\n for i in range(len_a):\r\n al[ord(a[i]) - 96] += 1\r\n \r\n for i in range(26, 0, -1):\r\n if al[i] > 0:\r\n print(chr(96 + i) * al[i], end='')\r\n break\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "s = input()\r\nres = \"\"\r\nmac = s[0]\r\nfor i in range(1, len(s)):\r\n mac = max(mac, s[i]) \r\nfor i in range(len(s)):\r\n if(mac == s[i]):\r\n res += s[i]\r\nprint(res)", "from collections import Counter\r\n\r\nif __name__ == \"__main__\":\r\n string = input()\r\n letter_count = Counter(string)\r\n last_letter = sorted(letter_count)[-1]\r\n print(last_letter*letter_count[last_letter])", "s1=list(input())\r\ns1.sort()\r\nprint(\"\".join(s1[s1.index(max(s1)):]))", "s=input()\r\nll=list(s)\r\nl=set(s)\r\nl=list(l)\r\nl.sort()\r\nprint(l[len(l)-1]*ll.count(l[len(l)-1]))", "from itertools import combinations\r\ns = list(input())\r\npalindrome = []\r\nfor i in range(1, len(s) + 1):\r\n comb = list(combinations(s,i))\r\n for j in comb:\r\n sub = \"\".join(j)\r\n if sub == sub[::-1]:\r\n palindrome.append(sub)\r\npalindrome.sort()\r\nprint(palindrome[-1])\r\n", "str1 = input()\r\nstr2 = sorted(str1,reverse=True)\r\nc = str2.count(str2[0])\r\nprint(str2[0]*c)\r\n\r\n\r\n\r\n\r\n", "s=input()\r\nc=max(s)\r\n#print(s.count(c)*c)\r\nprint(s.count(c)*c)", "from itertools import combinations as comb\r\ndef sub(a):\r\n b = set()\r\n for i in range(1, len(a) + 1):\r\n for c in comb(a, i):\r\n b.add(c)\r\n return b\r\na = list(sorted(sub(input())))\r\nout = []\r\nfor i in a:\r\n b = \"\".join(list(i))\r\n if b == b[::-1]:\r\n out.append(b)\r\nprint(out[-1])", "a = input()\r\nt = ord(a[0])\r\nt1 = a[0]\r\n\r\nfor i in range(1,len(a)):\r\n\tif t<ord(a[i]):\r\n\t\tt1 = a[i]\r\n\t\tt = ord(a[i])\r\nr = a.count(t1)\r\nprint(r*t1)", "n=input()\r\ns=sorted(n,reverse=True)\r\nprint(s.count(s[0])*s[0])", "z=input()\nj=max(z)\nprint(z.count(j)*j)\n", "s=input()\r\ns1=\"abcdefghijklmnopqrstuvwxyz\"\r\nfor i in range(25,-1,-1) :\r\n if s.count(s1[i])>0 :\r\n print(s1[i]*s.count(s1[i]))\r\n exit()\r\n \r\n", "s = input()\r\nmx = -1\r\nfor i in s:\r\n mx = max(mx, ord(i))\r\nprint(chr(mx) * s.count(chr(mx)))\r\n", "s=list(input())\r\ns.sort()\r\nc=s.count(s[-1])\r\nprint(c*s[-1])", "n=input()\r\nt=list(set(n))\r\nt.sort()\r\n#print(t)\r\nans=t[-1]\r\ncnt=n.count(ans)\r\n\r\nprint(ans*cnt)", "s = input()\r\n\r\nm = max(s)\r\n\r\nt = s.count(m)\r\n\r\nprint(m * t)", "def solve(s):\n s = sorted(s)\n return s[-1]*s.count(s[-1])\n\n\ndef main():\n s = input()\n print(solve(s))\n\n\nmain()\n", "#!/usr/bin/env python\r\n\r\nz = input()\r\nj = max(z)\r\nprint(z.count(j) * j)\r\n", "z=input()\nfor i in range(122,96,-1):\n if chr(i) in z:\n print(chr(i)*z.count(chr(i)))\n break\n\t \t\t\t\t\t \t \t \t\t \t \t \t\t\t", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Mar 14 22:38:53 2022\r\n\r\n@author: Anika\r\n\"\"\"\r\n\r\nstring = list(input())\r\n\r\nprint(max(string)*string.count(max(string)))", "s = input()\r\nz = max(s)\r\nprint(z*s.count(z))", "s1 = [str(i) for i in input()]\ns2 = \"\"\n\ns1.sort()\nkey = s1[-1]\n\nfor i in s1[-1::-1] :\n if i == key :\n s2 += key\n else :\n break\n\nprint(s2)\n", "s = input()\r\nx = s[0]\r\nfor i in range(len(s)):\r\n if s[i] > x:\r\n x = s[i]\r\nc = 0\r\nfor i in range(len(s)):\r\n if s[i] == x:\r\n c += 1\r\nprint(x * c)", "s = input()\r\nli = list(s)\r\nli.sort(reverse = True)\r\nres = li[0]\r\nfor i in range(0,len(s)-1):\r\n if li[i] == li[i+1]:\r\n res = res + li[i]\r\n else:\r\n break\r\nprint(res)", "s=input()\r\nm1=s[0]\r\nfor i in range(1,len(s)):\r\n m1=max(s[i],m1)\r\n\r\nx=\"\"\r\nfor i in s:\r\n if i==m1:\r\n x+=i\r\nprint(x)", "a = input()\r\nmax1 = -1\r\nb = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',\r\n 'x', 'y', 'z']\r\ne = 0\r\nfor i in range(len(a)):\r\n d = b.index(a[i])\r\n if d > max1:\r\n e = 1\r\n max1 = d\r\n elif d == max1:\r\n e += 1\r\nprint(b[max1] * e)", "# Lexicographically Largest Palindromic Subsequence\r\n\r\nif __name__ == '__main__':\r\n inpstr = input()\r\n largeChar = ord('a') - 1\r\n counter = 0\r\n for i in inpstr:\r\n if largeChar < ord(i):\r\n largeChar = ord(i)\r\n counter = 1\r\n elif largeChar == ord(i):\r\n counter += 1\r\n largeChar = chr(largeChar) * counter \r\n print(largeChar)", "s = list(input())\r\ns.sort()\r\n \r\nprint(s[len(s)-1]*s.count(s[len(s)-1]))", "s=sorted(input())\r\nprint(\"\".join(s[s.index(s[-1]):]))", "n = input()\r\nprint(max(n)*(n.count(str(max(n)))))", "s=str(input())\nx=sorted(s)\nl=len(x)\ny=x[l-1]\nx=s.count(y)\nfor i in range(x):\n print(y,end=\"\")\n \t \t\t \t\t \t\t\t \t \t\t\t\t\t\t \t\t\t \t \t", "a = input()\r\nb = max(a)\r\nprint(a.count(b) * b)\r\n", "s = input()\r\nn = len(s)\r\nmask = 0\r\ntemp = []\r\n\r\n\r\ndef palindrome(s):\r\n for i in range(0, len(s)//2):\r\n if s[i] != s[len(s)-i-1]:\r\n return False\r\n break\r\n return True\r\n\r\n\r\nwhile mask < (1 << n):\r\n temps = ''\r\n for i in range(n):\r\n if mask & (1 << i):\r\n temps += s[i]\r\n\r\n if palindrome(temps):\r\n temp.append(temps)\r\n mask += 1\r\n\r\ntemp.sort(reverse=True)\r\nprint(temp[0])\r\n", "def read_string():\n return input()\n\n\ndef lex_greater(s: str, t: str):\n n = len(s)\n m = len(t)\n i = 0\n j = 0\n\n while i < n and j < m:\n if s[i] == t[j]:\n i = i+1\n j = j+1\n else:\n return s[i] > t[j]\n return n > m\n\n\ndef lnpp(s: str):\n l = all_subsequence(s)\n lex_max = ''\n for seq in l:\n seq = ''.join(seq)\n if is_palindrome(seq) and lex_greater(seq, lex_max):\n lex_max = seq\n return lex_max\n\n\ndef all_subsequence(s: str) -> list:\n n = len(s)\n a = [0]*n\n res = []\n\n def f(n):\n if n > -1:\n a[n] = 0\n f(n - 1)\n a[n] = 1\n f(n - 1)\n else:\n substr = []\n for index, el in enumerate(a):\n if el == 1:\n substr.append(s[index])\n res.append(substr)\n\n f(n-1)\n return res\n\n\ndef is_palindrome(s: str):\n n = len(s)\n for i in range(n):\n if s[i] != s[n-i-1]:\n return False\n return True\n\n\ns = read_string()\nprint(lnpp(s))\n", "from sys import stdout\n\ns = sorted(input())\nlc = s[-1]\nwhile s and s[-1] == lc:\n\tstdout.write(s.pop())\nprint()\n", "string = input()\r\nprint(max(string) * string.count(max(string)))\r\n", "from itertools import combinations\r\ns=str(input())\r\nl=len(s)\r\nsub=list(s)\r\npali=list()\r\nfor i in range(2,l):\r\n com=combinations(s,i)\r\n for j in list(com):\r\n ts=''\r\n for k in j:\r\n ts=ts+k\r\n sub.append(ts)\r\n\r\nsub.append(s)\r\n\r\nfor k in sub:\r\n if k==k[::-1]:\r\n pali.append(k)\r\n\r\nprint(max(pali))\r\n\r\n\r\n\r\n\r\n", "#LLPS\r\ns = [str(x) for x in input()]\r\nd = max(s)\r\no =''\r\nfor i in s:\r\n if i ==d:\r\n o = o+i\r\nprint(o)", "word = list(input())\r\n\r\nword.sort(reverse=True)\r\n\r\nfirst_letter = word[0]\r\n\r\nfor letter in word:\r\n if letter != first_letter:\r\n break\r\n print(letter, end=\"\")\r\n", "l=list(input())\r\na=max(l)\r\nb=l.count(a)\r\nprint(a*b)\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nSpyder Editor\r\n\r\nThis is a temporary script file.\r\n\"\"\"\r\nn=input()\r\ns=list(n)\r\ns.sort()\r\ns1=max(set(s))\r\ncount=0\r\nfor i in s:\r\n if s1==i:\r\n count=count+1\r\n \r\nprint(count*s1) ", "s=input()\r\nx=max(s)\r\nprint(s.count(x)*x)", "s = input()\nfor i in range(25,-1,-1):\n if s.count(chr(ord(\"a\")+i)) > 0:\n break\nch = chr(ord(\"a\")+i)\nprint(ch*s.count(ch))\n", "from collections import Counter\r\ns = input()\r\nN = len(s)\r\nstart = max(list(s))\r\nt = Counter(s)[start]\r\nprint(t*start)", "s=input()\nk=max(s)\nn=s.count(k)\nprint(k*n)\n", "largest = None\nfor char in input():\n if largest == None or char > largest[0]:\n largest = char\n elif char == largest[0]:\n largest += char\n\nprint(largest)\n\t\t\t \t\t\t\t\t\t \t \t \t \t \t \t\t\t \t", "s = input()\r\na = [0] * 26\r\nfor x in s:\r\n a[ord(x)-ord('a')] += 1\r\n\r\nfor i in reversed(range(26)):\r\n if a[i] != 0:\r\n break\r\n\r\nc = chr(ord('a') + i)\r\nprint(c * s.count(c))\r\n", "s = input()\r\nmainLetter = 'a'\r\nalphabet = 'abcdefghijklmnopqrstuvwxyz'\r\nfor i in list(alphabet):\r\n if i in s:\r\n mainLetter = i\r\ncount = ''\r\nfor i in list(s):\r\n if i == mainLetter:\r\n count += mainLetter\r\nprint(count)\r\n\r\n", "s = input()\r\na = 'z'\r\nwhile s.count(a) == 0:\r\n a = chr(ord(a) - 1)\r\nprint(a * s.count(a))", "List = list(input())\r\nprint(max(List) * List.count(max(List)))", "str = input()\r\nres = \"\"\r\nmx = str[0]\r\nfor i in range(1, len(str)):\r\n mx = max(mx, str[i])\r\nfor i in range(0, len(str)):\r\n if str[i] == mx:\r\n res += str[i]\r\nprint(res)", "from random import randint\r\nfrom itertools import combinations\r\ndef pal(stri):\r\n a=stri[::-1]\r\n if(a==stri):\r\n return True\r\ns=input()\r\ndef all_subsequences(s):\r\n out = set()\r\n for r in range(1, len(s) + 1):\r\n for c in combinations(s, r):\r\n out.add(''.join(c))\r\n return sorted(out)\r\nlst = all_subsequences(s)\r\n\r\nans=\" \"\r\nfor i in lst:\r\n if(pal(i)):\r\n if(ans<=i):\r\n ans=i\r\nprint(ans)\r\n \r\n\t\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n", "def readln(): return tuple(map(int, input().split()))\n\ncnt = 0\nval = 'a'\nfor _ in list(input()):\n if _ == val:\n cnt += 1\n elif _ > val:\n val = _\n cnt = 1\nprint(val * cnt)\n", "n=input()\r\nif len(n)<=10:\r\n pass\r\nelse:\r\n while(len(n)>10):\r\n n=input(\"\")\r\na=n[0] \r\nfor i in range (len(n)):\r\n if a < n[i]:\r\n a=n[i]\r\n \r\n \r\ny=n.count(a)\r\nfor i in range (y):\r\n print(a,end=\"\")", "count = 0\r\nchar = \"a\"\r\nfor i in input():\r\n if i > char:\r\n char = i\r\n count = 0\r\n if char == i:\r\n count += 1\r\nprint(char * count)\r\n", "s = input()\r\nr = [ch for ch in s]\r\nmaxL = max(r)\r\nprint(maxL * s.count(maxL))", "str=input()\r\ncm=str[0]\r\nst=''\r\nfor i in str:\r\n if((i)>(cm)):\r\n cm=i\r\n st=''\r\n if(i==cm):\r\n st=st+cm\r\nprint(st) ", "s = input()\r\nc = ord('z')\r\nfor i in range(c, c-26, -1):\r\n if chr(i) in s:\r\n print(s.count(chr(i))*chr(i))\r\n break\r\n", "from sys import stdin, setrecursionlimit, stdout\r\n#setrecursionlimit(1000000)\r\nfrom collections import deque\r\nfrom math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin\r\ndef ii(): return int(stdin.readline())\r\ndef fi(): return float(stdin.readline())\r\ndef mi(): return map(int, stdin.readline().split())\r\ndef fmi(): return map(float, stdin.readline().split())\r\ndef li(): return list(mi())\r\ndef si(): return stdin.readline().rstrip()\r\ndef lsi(): return list(si())\r\n#mod=1000000007\r\nres=['Yes', 'No']\r\n############# CODE STARTS HERE #############\r\nfib=[1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025, 20365011074, 32951280099, 53316291173, 86267571272, 139583862445, 225851433717, 365435296162, 591286729879, 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842, 10610209857723, 17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994, 190392490709135, 308061521170129, 498454011879264, 806515533049393, 1304969544928657, 2111485077978050, 3416454622906707, 5527939700884757, 8944394323791464, 14472334024676221]\r\n\r\n\r\ntest_case=1\r\nwhile test_case:\r\n test_case-=1\r\n\r\n\r\n\r\n a=lsi()\r\n x=max(a)\r\n print(x*a.count(x))", "s=input()\r\nn=len(s)\r\nl=\"\"\r\no=0\r\nfor i in range(n):\r\n if ord(s[i])>o:\r\n o=ord(s[i])\r\n l=s[i]\r\na=s.count(l)\r\nprint(l*a)", "string = input()\nn = len(string)\nmask = (1<<n) - 1\nans = string[0]\n\ndef getString(mask,string):\n temp = \"\"\n for i in range(len(string)):\n if mask & 1<<i:\n temp+=string[i]\n return temp[::-1]\n\nwhile mask:\n temp = getString(mask,string)\n if temp==temp[::-1] and temp > ans:\n ans = temp\n mask-=1\nprint(ans)", "s=input();print(max(s)*s.count(max(s)))\r\n", "# 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)\nMOD = \"1000000007\"\ndx = [-1, 0, 1, 0]\ndy = [ 0, 1, 0, -1]\n############################ SOLUTION IS COMING ###############################\ndef is_pal(s):\n l = len(s)\n for i in range(l // 2):\n if s[i] != s[l - i - 1]:\n return False\n return True\n\ns = input()\nend = (1 << len(s))\nres = \"\"\nfor i in range(1, end):\n tmp = \"\"\n for j in range(len(s)):\n if (1 << j) & i:\n tmp += s[j]\n if is_pal(tmp):\n res = max(res, tmp)\n\nprint(res)\n", "z = input()\r\nj = max(z)\r\nprint(z.count(j)*j)", "import sys\r\nimport math\r\nimport bisect\r\nimport itertools\r\nimport random\r\n\r\n\r\ndef main():\r\n s = input()\r\n A = []\r\n for c in s:\r\n if c == max(s):\r\n A.append(c)\r\n print(''.join(A))\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "s = input()\r\nn = len(s)\r\n\r\npals = []\r\n\r\nfor i in range(1, 2**n):\r\n \r\n strings = str(bin(i))[2:]\r\n strings = (n-len(strings))*'0'+strings\r\n \r\n tru_str = ''.join([x for x,y in zip(s, strings) if y=='1'])\r\n if tru_str == tru_str[::-1]:\r\n pals.append(tru_str)\r\n \r\nprint(sorted(pals, reverse=True)[0])", "import sys\r\ninput = sys.stdin.readline\r\n\r\nclass Solution:\r\n def LLPS(self, s):\r\n s = sorted(list(s))\r\n \r\n last = s.index(s[-1])\r\n return \"\".join(s[last:])\r\n \r\nsol = Solution()\r\ns = input()\r\nprint(sol.LLPS(s))\r\n", "s=input()\r\nsc=sorted(list(s))[-1]\r\nn=s.count(sc)\r\nprint(sc*n)", "s=input()\r\nl=[]\r\nfor i in s:\r\n l.append(i)\r\nl.sort(reverse=True)\r\nprint(l[0]*s.count(l[0]))\r\n", "x = input()\r\nfor i in range(122, 96, -1):\r\n if chr(i) in x:\r\n ch = chr(i)\r\n break\r\n\r\nans = \"\"\r\nfor i in x:\r\n if i == ch:\r\n ans += i\r\nprint(ans)", "s = input()\r\ns = sorted(s)\r\nlo = s[-1]\r\ni = -1\r\nwhile i >= -len(s) and s[i] == lo:\r\n print(s[i],end=\"\")\r\n i -= 1\r\n", "s = input()\r\nmax = 'a'\r\nfor x in s:\r\n if( x > max):\r\n max = x\r\n\r\ncount = 0\r\n\r\nfor x in s:\r\n if(max == x):\r\n count += 1\r\n\r\n\r\nwhile count != 0:\r\n print(max, end='')\r\n count -= 1", "k=input();\nm=max(k);\nprint(k.count(m)*m)\n\t \t \t\t \t\t \t\t \t\t \t\t \t \t \t", "ans = \"\"\r\ns = input()\r\nfor m in range(1 << len(s)):\r\n f = \"\".join([s[i] for i in range(len(s)) if m & (1 << i)])\r\n if f == f[::-1]:\r\n ans = max(ans,f)\r\nprint(ans)", "s = input()\r\ns = sorted(s)\r\nl = s[-1]\r\nz = 0\r\nfor i in s:\r\n if i == l:\r\n z += 1\r\nfor i in range(z):\r\n print(l, end='')\r\n", "n=input()\r\na=list(n)\r\nl=[]\r\nfor i in range(len(a)):\r\n l.append(ord(a[i]))\r\n k=max(l)\r\nm=l.count(k)\r\nprint(chr(k)*m)", "str = input().lower()\r\narr = []\r\nfor j in str:\r\n arr.append(j)\r\n\r\narr.sort()\r\nprint(arr.count(arr[-1])*arr[-1])", "s = input()\nc = max(s)\nprint(c * s.count(c))\n", "string = input()\r\nstring = list(string)\r\nstring = sorted(string, reverse= True)\r\n\r\ncount = 0\r\n\r\nbig_string = string[0]\r\n\r\nfor x in string:\r\n if x == big_string:\r\n count+=1\r\n if x!= big_string:\r\n break\r\n\r\nprint(big_string*count)", "chaine=str(input())\r\ndef palin(mot):\r\n g=mot[0]\r\n for i in range(len(mot)):\r\n if g < mot[i]:\r\n g=mot[i]\r\n n=0\r\n while mot[n] != g:\r\n n=n+1\r\n L=[g]\r\n for i in range(n+1,len(mot)):\r\n if mot[i]==g:\r\n L.append(g)\r\n MOT=\"\"\r\n for x in L:\r\n MOT=MOT+x\r\n return(MOT)\r\nprint(palin(str(chaine)))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "def func(A, v, index,x):\r\n x.append(v.copy())\r\n for i in range(index, len(A)):\r\n v.append(A[i]) #include the curr index element\r\n func(A, v, i + 1,x)\r\n v.pop(-1) #exclude the curr index element\r\n\r\n return x\r\n\r\na=list(input())\r\ni=0\r\nv=[]\r\nx=[]\r\ny=func(a,v,i,x)\r\nz=[]\r\nfor i in y:\r\n if i==i[::-1]:\r\n z.append(\"\".join(i))\r\nprint(max(z))", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sun Jan 1 14:27:42 2023\r\n\r\n@author: DELL\r\n\"\"\"\r\n\r\ndef largestPalinSub(s):\r\n \r\n res = \"\"\r\n mx = s[0]\r\n \r\n for i in range(1, len(s)):\r\n mx = max(mx, s[i])\r\n \r\n for i in range(0, len(s)):\r\n if s[i] == mx:\r\n res += s[i]\r\n \r\n return res\r\n\r\ns = input()\r\nprint(largestPalinSub(s))", "s=input()\r\ns1=set(s)\r\nmax1=0\r\nch=\"\"\r\nfor i in s1:\r\n if ord(i)>max1:\r\n max1=ord(i)\r\n ch=i\r\n\r\ncount=s.count(ch)\r\nprint(ch*count)", "x=input()\r\nm=max(x)\r\nfor i in x:\r\n if i==m:\r\n print(i,end='')\r\n", "string = input()\r\nd = {}\r\n\r\nfor i in string:\r\n d[i] = d.get(i, 0) + 1\r\nprint(max(d)*d[max(d)])", "st=input()\r\nmaxi=max(st)\r\nprint(st.count(maxi)*maxi)", "from itertools import combinations\r\n\r\n\r\ndef check_palindrome(seq):\r\n return seq == seq[::-1]\r\n\r\n\r\ns = input().strip()\r\nsubs = set(''.join(j) for i in range(1, len(s) + 1) for j in combinations(s, i))\r\npalindrome_subs = tuple(filter(check_palindrome, subs))\r\nprint(sorted(palindrome_subs)[-1])\r\n", "# Author: S Mahesh Raju\r\n# Username: maheshraju2020\r\n# Date: 31/08/2020\r\nfrom sys import stdin, stdout, setrecursionlimit\r\nfrom math import gcd, ceil, sqrt\r\nfrom collections import Counter, deque\r\nfrom bisect import bisect_left, bisect_right\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\nsetrecursionlimit(100000)\r\nmod = 1000000007\r\n\r\ns = is1()\r\nprint(max(s) * s.count(max(s)))\r\n", "s = input()\r\n\r\nmax_char = \"\"\r\nfor char in s:\r\n if char > max_char:\r\n max_char = char\r\n\r\nprint(max_char * (s.count(max_char)))\r\n", "s = input()\nmax_c = max(s)\nprint(max_c * s.count(max_c))\n", "a=list(input())\r\nd={}\r\nfor i in a:\r\n d[i]=d.get(i,0)+1\r\nd=sorted(d.items(),key=lambda k:(k[0]),reverse=True)\r\nprint(d[0][0]*d[0][1])\r\n", "from collections import Counter\r\ns = input()\r\nh = Counter(s)\r\nprint(max(s)*h[max(s)])", "s = ''.join(sorted(input()))\r\nprint(s[s.find(s[-1]):])", "import time\nimport collections\n\nclass Time_test:\n def __enter__(self):\n self.enter_time = time.time()\n def __exit__(self, exc_type, exc_val, exc_tb):\n print(\"Command was executed in\", time.time()-self.enter_time)\n\nipt = input()\nm = []\nfor i in range(2**len(ipt)):\n tmp = bin(i)[2:]\n tmp = (len(ipt)-len(tmp))*'0' + tmp\n subs = []\n for i, val in enumerate(tmp):\n if val == '1':\n subs.append(ipt[i])\n if subs[:len(subs)//2] == subs[len(subs)//2+len(subs)%2:] and subs > m:\n m = subs\n\nprint(*m, sep='')\n", "s = input()\r\nprint(max(s)*s.count(max(s)))", "def isSymmetric(string):\r\n return string == string[::-1]\r\n\r\n\r\nlistak = []\r\nword = input()\r\nfor i in range(1 << len(word)):\r\n result = \"\"\r\n for index in range(len(word)):\r\n if i & (1 << index):\r\n result += word[index]\r\n if isSymmetric(result) and result != \"\":\r\n listak.append(result)\r\nprint(sorted(listak).pop())\r\n", "t = input()\r\n\r\n\r\nmaximum = max(t)\r\n\r\n\r\nfor i in range(len(t)):\r\n if maximum == t[i]:\r\n print(maximum, end = \"\")\r\n\r\n\r\n", "a=str(input())\r\na=sorted(a,reverse=True)\r\nk=0\r\ni=1\r\nprint(a[0],end='')\r\n\r\nwhile k==0 and i<len(a):\r\n if a[i]==a[i-1]:\r\n print(a[i],end='')\r\n i=i+1\r\n else:\r\n k=1", "s = input()\r\nprint(s.count(max(s)) * max(s))\r\n", "\r\n\r\n\r\ns=input();\r\ncnt=0;\r\nch=\"-1\";\r\nval=-1;\r\nfor i in range(len(s)):\r\n\tif(ord(s[i])==val):cnt+=1;\r\n\telif(ord(s[i])>val):\r\n\t\tch=s[i];\r\n\t\tval=ord(s[i]);\r\n\t\tcnt=1;\r\nprint(ch*cnt);\r\n\r\n", "word = sorted(list(map(str,input().strip())))\r\na = len(word)\r\nb = word.count(word[a-1])\r\nfor i in range(b):\r\n print(word[a-1], end =\"\")\r\n ", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Dec 27 16:40:10 2022\r\n\r\n@author: 21pt15\r\n\"\"\"\r\n\r\nstring_list = list(input())\r\nstring_list.sort(reverse = True)\r\nprint(string_list[0]*string_list.count(string_list[0]))\r\n", "# -*- coding: utf-8 -*-\n\"\"\"Untitled0.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1T1Rhmb_iDQtLLUVxN1TTBfC-9hXKimd8\n\"\"\"\n\ns=input()\np=s[0]\nans=\"\"\nfor i in range(len(s)):\n if(s[i]>p):\n p=s[i]\nfor i in range(len(s)):\n if(p==s[i]):\n ans+=s[i]\nprint(ans)", "s = input()\r\nc = max(s)\r\nprint(s.count(c)*c)", "s=input().strip()\r\na=[0]*26\r\nfor i in s:\r\n a[ord(i)-ord('a')]+=1\r\ni=25\r\nwhile a[i]==0:\r\n i-=1\r\nfor j in range(a[i]):\r\n print(chr(i+ord('a')),end='')", "v=input();c=max(v);print(v.count(c)*c)\r\n", "'''\r\n# Submitted By M7moud Ala3rj\r\nDon't Copy This Code, CopyRight . [email protected] © 2022-2023 :)\r\n'''\r\n# Problem Name = \"LLPS\"\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 palindrome(word):\r\n if len(word)%2==0:\r\n return word[:len(word)//2]==word[len(word)//2:]\r\n else:\r\n return word[:len(word)//2]==word[len(word)//2+1:]\r\n\r\ndef Solve():\r\n s = input().strip()\r\n z = max(s)\r\n print(z*s.count(z))\r\n\r\nif __name__ == \"__main__\":\r\n # for t in range(int(input())):\r\n Solve()", "s=input()\r\nprint(s.count(max(s))*max(s))\r\n", "str = input()\r\ny = []\r\nx = []\r\nfor i in range(len(str)):\r\n x.append(str[i])\r\n x.sort(reverse=True)\r\nfor i in range(len(x)):\r\n if x[0] == x[i]:\r\n y.append(x[i])\r\nz = \"\".join(y)\r\nprint(z)", "word = input()\r\n\r\nf = [0] * 26\r\nfor w in word:\r\n f[ord(w)-ord('a')] += 1\r\n \r\nfor i in range(25, -1, -1):\r\n if f[i] != 0:\r\n ans = chr(97+i) * f[i]\r\n break\r\n\r\nprint(ans)", "n = input()\r\nl = sorted(n)\r\ne = l[-1]\r\nx = l.count(e)\r\nprint(e* x)", "s = input()\r\nl = []\r\nfor i in range(len(s)):\r\n l.append(s[i])\r\nl.sort(reverse = True)\r\na = l[0]\r\nq = l.count(a)\r\nw = \"\"\r\nfor i in range(q):\r\n w += a\r\nprint(w)", "s = input()\r\nch = max(s)\r\nprint(ch * s.count(ch))", "y=input();k=max(y)\r\nprint(y.count(k)*k)\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\n\r\n\r\nn=list(input())\r\ns=list(set(n))\r\n\r\ns.sort()\r\nl=n.count(s[-1])\r\n\r\nh=[]\r\n\r\nfor i in range(l):\r\n h.append(s[-1])\r\n\r\nprint(\"\".join(h))\r\n", "from itertools import combinations\ndef ispal(s):\n l = len(s)\n if l <=1 : return True\n for i in range(l//2):\n if s[i] != s[l-i-1]:\n return False\n return True\n\ns = input()\nans = []\nl = len(s)\nfor i in range(1 , l + 1):\n for j in combinations(s,i):\n if(ispal(j)):\n ans.append(''.join(j))\nans.sort(reverse=True)\nprint(ans[0])\n\n \t\t\t\t \t\t\t \t\t\t \t\t \t\t\t \t \t", "s = input()\r\nmax = 0\r\nfor i in s:\r\n if(ord(i) > max):\r\n max = ord(i)\r\np = chr(max)\r\nz = 0\r\nfor i in s:\r\n if i == p:\r\n z += 1\r\nfor i in range(z):\r\n print(p, end='')", "a = input()\r\nprint(max(a) * a.count(max(a)))", "word = list(input())\r\n\r\nmaxi = max(word)\r\npointer = 0\r\nfor i in range(len(word)):\r\n if maxi == word[i]:\r\n pointer += 1\r\n\r\nprint(maxi * pointer)", "import sys\r\n# sys.stdin=open('Python\\input.txt','r')\r\n# sys.stdout=open('Python\\output.txt','w')\r\n\r\ndef solve(s,n):\r\n t=''\r\n for i in range((1<<n)):\r\n l=''\r\n for j in range(n):\r\n if (i&(1<<j)):\r\n l+=s[j]\r\n if (l==l[::-1]) and (l>t):\r\n t=str(l)\r\n print(t)\r\n\r\ns=input()\r\nsolve(s,len(s))\r\n", "Input = list(input())\r\nprint(max(Input)* Input.count(max(Input)))\r\n", "s=input()\r\nc=max(s)\r\nprint(c*s.count(c))\r\n", "y=input();a=max(y);print(y.count(a)*a)\r\n", "a = input()\r\nal = len(a)\r\nnew = []\r\nnew.append(a[0])\r\nnewl = 0\r\nfor i in range(1,al):\r\n while(newl!=-1):\r\n if(ord(a[i])>ord(new[newl])):\r\n new.pop()\r\n newl = newl-1\r\n else: \r\n break\r\n new.append(a[i]) \r\n newl+=1\r\nfirst = 0\r\nend = newl\r\nwhile(first<end):\r\n if(new[first]!=new[end]):\r\n new.pop()\r\n end= end-1\r\n else:\r\n first = first+1\r\n end = end-1\r\nfor i in new:\r\n print(i,end=\"\")", "s = list(input())\r\na = max(s)\r\nprint(a * s.count(a))", "a = input()\r\nmass = [i for i in a]\r\nmass.sort()\r\nprint(mass[-1] * mass.count(mass[-1]))", "S =sorted(input())\r\nl = S[-1]\r\nprint(l * S.count(l))", "from collections import Counter\r\ns=input()\r\nnew=[i for i in s]\r\nfreq=dict(Counter(new))\r\nchange=list(sorted(freq.items(),key=lambda x:x[0],reverse=True))\r\nprint(change[0][0]*change[0][1])", "string = input()\r\nalll = [] \r\nfor i in string : \r\n s =\"\"\r\n for j in string : \r\n if i == j :\r\n s += j \r\n alll.append(s) \r\nprint(sorted(alll)[-1])", "\r\ndef solve():\r\n #n = int(input())\r\n s = list(input())\r\n d = {}\r\n maxx = 'a'\r\n for v in s:\r\n d[v] = d.get(v, 0) + 1\r\n if v > maxx:\r\n maxx = v\r\n print(\"\".join([maxx]*d[maxx]))\r\n\r\n\r\n\r\nimport math\r\nfrom collections import defaultdict\r\nt = 1\r\nfor _ in range(t):\r\n solve()\r\n\r\n", "s=input()\r\nx=max(s)*s.count(max(s))\r\nprint(x)", "import sys\r\n# sys.stdin = open('input.txt','r')\r\n# sys.stdout = open('output.txt','w')\r\ninput = lambda:sys.stdin.readline().strip()\r\nli = lambda:list(map(int,input().split()))\r\ns = input()\r\ndef ispalindrome(t):\r\n\treturn t==t[::-1]\r\nl =[]\r\ndef generate(s,t,i):\r\n\tif i==len(s):\r\n\t\tif ispalindrome(t):\r\n\t\t\tl.append(t)\r\n\t\treturn\r\n\tgenerate(s,t+s[i],i+1)\r\n\tgenerate(s,t,i+1)\r\ngenerate(s,\"\",0)\r\nprint(max(l))", "s=input(); m=max(s); print(s.count(m)*m)\r\n", "\r\ns = input()\r\nMax = max(s)\r\nprint(Max * s.count(Max))\r\n\r\n# UBCF\r\n# CodeForcesian\r\n# ♥\r\n# بی لعل لبت وصف شکر نتوان کرد", "def main():\n str_ = input().lower()\n\n last_in_the_alphabet = ''\n\n for char in str_:\n if char > last_in_the_alphabet:\n last_in_the_alphabet = char\n\n return last_in_the_alphabet * str_.count(last_in_the_alphabet)\n\n\nif __name__ == '__main__':\n print(main())\n", "def solve():\r\n s = list(input())\r\n s.sort()\r\n \r\n print(s[-1] * s.count(s[-1]))\r\n \r\n \r\nif __name__ == \"__main__\":\r\n solve()\r\n ", "#!/usr/bin/python3.5\r\ns=input()\r\nl=list(s)\r\nl.sort()\r\nk=l[-1]\r\nfor i in l[::-1]:\r\n if i!=k:\r\n break\r\n else:\r\n print(k,end='')", "n = input()\r\nans = \"\"\r\ns =max(n)\r\nfor i in n:\r\n if(i==s): ans += s\r\n\r\nprint(ans)\r\n", "s=input()\r\nl=sorted(s,reverse=True)\r\nct=l.count(l[0])\r\nprint(l[0]*ct)", "a = input()\r\nmx = a[0]\r\nfor i in a:\r\n if i > mx:\r\n mx = i\r\nprint( \"\".join([a[i] for i, letter in enumerate(a) if letter == mx]))", "s = input()\r\nmax_value = -1\r\nsequence = ''\r\nfor x in s:\r\n if ord(x) > max_value:\r\n max_value = ord(x)\r\n sequence = ''\r\n sequence += x\r\n elif ord(x) == max_value:\r\n sequence += x\r\nprint(sequence)", "s=list(input());d={};t=max(s)\r\nfor i in s:\r\n\tif i in d:d[i]+=1\r\n\telse:d[i]=1\r\nprint(t*d[t])", "#\"Lexicographically Largest Palindromic Subsequence\"\r\nfrom itertools import combinations\r\nfrom collections import deque\r\ns=input()\r\nif s.count(s[0])==len(s):\r\n print(s)\r\nelse:\r\n lexicographically_list=deque()\r\n for i in range(1,len(s)):\r\n for j in list(combinations(s,i)):\r\n if j==j[::-1]:\r\n lexicographically_list.append(j)\r\n print(\"\".join(sorted(lexicographically_list)[-1]))", "s = input()\r\ne = sorted(s)[-1]\r\nw = s.count(e)*e\r\nprint(w)", "# from dust i have come, dust i will be\n\ns = input()\nn = len(s)\nmx = max(s)\n\nfor i in range(n):\n if mx == s[i]:\n print(s[i], end='')\n", "k=input();print(max(k)*k.count(max(k)))", "s = input()\r\nd = {}\r\nfor i in s:\r\n if ord(i) not in d:\r\n d[ord(i)] = 0\r\n d[ord(i)] += 1\r\nx = max(d.keys())\r\ny = d[x]\r\nprint(chr(max(d.keys()))*y)", "'''\ndef check(a,b): #x is lexicographically larger than string y\n t1 = len(a)\n t2 = len(b)\n if t1 > t2 and a.find(b)!=-1:\n return True\n for r in range(min(t1,t2)):\n if a[:r+1] == b[:r+1] and ord(a[r+1]) > ord(b[r+1]):\n #print(r)\n return True\n return False\nprint(check(\"radar\",\"rr\"))\n'''\ns = input()\nyy = max(s)\nprint(s.count(yy)*yy)", "import sys\r\nsys.setrecursionlimit(10**4)\r\ns = input()\r\nn = len(s)\r\nans = ''\r\ndef recurse(idx, prev):\r\n global ans\r\n if idx==n and prev==prev[::-1]:\r\n #print(prev)\r\n ans = max(ans,prev)\r\n if idx>=n:\r\n return\r\n recurse(idx+1,prev)\r\n recurse(idx+1,prev+s[idx])\r\nrecurse(0,\"\") \r\nprint(ans)", "t=sorted(str(input()),reverse=True)\r\nl,r=0,len(t)-1\r\nwhile l+1<r:\r\n s=(l+r)//2\r\n if t[s]!=t[0]:\r\n r=s\r\n else:\r\n l=s\r\nif t[r]==t[0]:\r\n print(t[0]*(r+1))\r\nelse:\r\n print(t[0]*(l+1))", "s=input()\r\nn=len(s)\r\nout=[]\r\ndef pali(s):\r\n n=len(s)\r\n if n%2==0:\r\n if s[:n//2][::-1]==s[n//2:]:\r\n return True\r\n else:\r\n if s[:n//2][::-1]==s[n//2+1:]:\r\n return True\r\n return False\r\nfor i in range(2**n):\r\n w=''\r\n for j in range(n):\r\n if i&(1<<j):\r\n w+=s[j]\r\n if pali(w):\r\n out.append(w)\r\nout.sort()\r\nprint(out[-1])", "s=input()\r\nm=max(s)\r\nprint(m*s.count(m))", "s = input()\nsub = ''\nlargest = 0\nfor i in range(len(s)):\n ascVal = ord(s[i])\n if (ascVal > largest):\n largest = ascVal\n\nlargest = chr(largest)\n\nfor i in range(len(s)):\n if s[i] == largest:\n sub = sub + largest\n\nprint(sub)\n", "import sys, threading, heapq, math\r\nfrom collections import defaultdict, Counter\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef main():\r\n s = input().strip()\r\n stack = []\r\n for char in s:\r\n while stack and stack[-1] < char:\r\n stack.pop()\r\n stack.append(char)\r\n res = ''.join(stack)\r\n ptr = len(res)\r\n while res != res[::-1]:\r\n ptr -= 1\r\n res = res[:ptr]\r\n print(res)\r\nmain()\r\n \r\n# threading.stack_size(1 << 27)\r\n# sys.setrecursionlimit(1 << 30)\r\n# main_thread = threading.Thread(target=main)\r\n# main_thread.start()\r\n# main_thread.join()\r\n ", "from collections import Counter\r\n\r\ncount = Counter(input())\r\nmx = max(count)\r\nprint(count[mx] * mx)", "s = input()\r\nans = [0]*26\r\nfor i in s:\r\n ans[ord(i) - ord('a')] += 1\r\nfor i in range(25, -1, -1):\r\n if ans[i] != 0:\r\n print(chr(ord('a') + i)*ans[i])\r\n break\r\n", "from itertools import combinations\r\nif __name__ == '__main__':\r\n s = input()\r\n res = ()\r\n\r\n for i in range(len(s)):\r\n for x in combinations(s, i + 1):\r\n # print(\"x = \", x)\r\n if res < x and x == x[::-1]:\r\n res = x\r\n # print(res)\r\n\r\n print(''.join(res))\r\n", "from sys import stdin,stdout\r\ndef solve():\r\n s = stdin.readline()\r\n maxele = s[0]\r\n for ele in s:\r\n if ele > maxele:\r\n maxele = ele\r\n ans = \"\"\r\n for ele in s:\r\n if ele == maxele:\r\n ans += maxele\r\n return ans\r\n\r\n\r\nstdout.write(str(solve())+\"\\n\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\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 llps_str(string):\r\n \r\n sorted_string = sorted(string)\r\n last_index = len(sorted_string)-1\r\n largest_letter = sorted_string[last_index]\r\n \r\n counter = sorted_string.count(largest_letter)\r\n \r\n return largest_letter*counter\r\n \r\n \r\n \r\nstr = input()\r\nprint(llps_str(str))\r\n", "var = input()\r\nmy_list = list(var)\r\nmy_list.sort()\r\nmy_char = my_list[len(my_list)-1]\r\nvar_new = \"\"\r\nfor i in my_list:\r\n if i == my_char:\r\n var_new += i\r\nprint(var_new)\r\n\r\n ", "s=input()\r\nl=[0]*26\r\nfor i in s:\r\n l[ord(i)-ord('a')]+=1 \r\nm=0\r\nfor i in range(26):\r\n if l[i]!=0:\r\n m=i \r\nprint(chr(ord('a')+m)*l[m])", "n=input()\r\nlst=[]\r\nfor i in n:\r\n lst.append(i)\r\nlst.sort()\r\nprint(lst[-1]*lst.count(lst[-1]))\r\n", "ss=str(input())\r\nx=sorted(ss)\r\nl=len(x)\r\ny=x[l-1]\r\nx=ss.count(y)\r\nfor i in range(x):\r\n print(y,end=\"\")", "a = input()\nmaximum = max(a)\nprint(a.count(maximum) * maximum)\n", "import sys \r\n# sys.stdin = open('input.txt', 'r') \r\n# sys.stdout = open('output.txt', 'w') \r\n \r\n\r\n\r\n# T = int(input())\r\n# for t in range(T):\r\n# n,c = map(int,input().split())\r\nst = input()\r\na = max(st)\r\nprint(a*st.count(a))\r\n\r\n\r\n\r\n", "s = input()\r\ncmax = max(s)\r\nprint(cmax * s.count(cmax))\r\n\r\n\"\"\"\r\n//////////////////////////////////////////\r\n// //\r\n// Implemented by brownfox2k6 //\r\n// //\r\n//////////////////////////////////////////\r\n\"\"\"", "s = input()\r\n\r\nfor i in range(122,96,-1):\r\n if chr(i) in s:\r\n print(s.count(chr(i))*chr(i))\r\n break", "s = input()\r\nn = len(s)\r\nmx = max(s)\r\n\r\nfor i in range(n):\r\n if mx == s[i]:\r\n print(s[i], end='')", "word =input()\r\nres =\"\"\r\nmaxStr = word[0]\r\nfor i in range(0,len(word)):\r\n maxStr=max(maxStr,word[i])\r\nfor i in range (0,len(word)):\r\n if(maxStr == word[i]):\r\n res+=word[i]\r\nprint(res)", "v=input()\r\nc=max(v)\r\nprint(v.count(c)*c)\r\n", "s = input()\r\nprint(max(s) * (s. count(max(s))))\r\n", "def substr(s):\r\n m = max(s)\r\n res = \"\"\r\n for i in range(0, len(s)):\r\n if s[i] == m:\r\n res += s[i]\r\n return res\r\n\r\nif __name__ == \"__main__\":\r\n print(substr(input()))", "a=list(map(ord,input()))\r\nm=max(a)\r\ncount=a.count(m)\r\nprint(chr(m)*count)", "word = input()\r\nasc_word = ''.join(sorted(word))\r\ni = len(word)-1\r\nch = asc_word[-1]\r\nwhile asc_word[i] == ch and i>=0:\r\n i-=1\r\nprint(asc_word[i+1:])", "a = sorted(list(input()))\r\nprint(a[-1] * a.count(a[-1]))\r\n", "s=input()\r\nl=len(s)\r\nans=\"\"\r\ndef okay(string):\r\n\t#print(string,end=\" \")\r\n\tl=len(string)\r\n\tfor i in range(l//2):\r\n\t\tif string[i]!=string[l-i-1]:\r\n\t#\t\tprint(False)\r\n\t\t\treturn False\r\n#\tprint(True)\r\n\treturn True\r\nfor i in range(1<<l):\r\n\tx=\"\"\r\n\tfor b in range(l):\r\n\t\tif i&(1<<b)>0:\r\n\t\t\tx+=s[b]\r\n\tif okay(x):\r\n\t\tif x>ans:\r\n\t\t\tans=x\r\nprint(ans)", "s = input()\r\n\r\nl = [i for i in s]\r\nl.sort()\r\na = l[len(l)-1]\r\nprint(a*(l.count(a)))\r\n \r\n", "# import sys\r\n# sys.stdin=open(\"input.in\",'r')\r\n# sys.stdout=open(\"output4.out\",'w')\r\ns=input()\r\nl=list(map(ord,s))\r\nm=max(l)\r\nc=l.count(m)\r\nprint(chr(m)*c)", "s = input()\r\nx = max(s)\r\n# print(x)\r\n\r\ncnt = s.count(x)\r\n\r\n# print(cnt)\r\n\r\nfor i in range(cnt):\r\n print(x,end=\"\")", "v=input();c=max(v)\r\nprint(v.count(c)*c)\r\n", "s=input()\r\nr=sorted(s)\r\nprint(r[-1]*r.count(r[-1]))", "print((a:=max(b:=input()))*b.count(a))\r\n", "x = input().strip()\r\na = max(x)\r\nprint(a * (x.count(a)))\r\n\r\n\r\n", "#https://codeforces.com/problemset/problem/202/A\r\n\r\ndef solution(s):\r\n res = \"\"\r\n mx = s[0]\r\n for i in range(1, len(s)):\r\n mx = max(mx, s[i])\r\n for i in range(0, len(s)):\r\n if s[i] == mx:\r\n res += s[i]\r\n print(res)\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n palindrome = str(input())\r\n solution(palindrome)", "\r\nstring = input()\r\n\r\nm = \"\"\r\nfor i in string:\r\n if i > m:\r\n m = i\r\n\r\nfor i in string:\r\n if i == m:\r\n print(i, end=\"\")\r\n\r\n", "s = input()\r\ntemp = sorted(s)\r\nd = {}\r\nfor i in s:\r\n if i in d:\r\n d[i]+=1\r\n else:\r\n d[i] = 1\r\nele = temp[-1]\r\noccurence = d[ele]\r\nprint(ele*occurence)", "from collections import Counter\nstring = str(input())\ncnt = dict(Counter(string))\nkeys = list(cnt.keys())\nkeys.sort(reverse=True)\nprint(keys[0] * cnt[keys[0]])\n", "s=str(input())\r\nk=max(s)\r\ng=s.count(k)\r\nprint(k*g)", "from math import sqrt\r\n\r\n\r\ndef generate_subsequences(s, memo=[]):\r\n if len(s) == 1:\r\n memo.append(s)\r\n return [s]\r\n else:\r\n first_letter = s[0]\r\n smaller_subs = generate_subsequences(s[1:]).copy()\r\n for subs in smaller_subs:\r\n memo.append(first_letter + subs)\r\n memo.append(first_letter)\r\n\r\n return memo\r\n\r\n\r\ndef llps(s):\r\n s_subseq = generate_subsequences(s)\r\n max_subseq = ''\r\n for s in s_subseq:\r\n if s > max_subseq and s == s[::-1]:\r\n max_subseq = s\r\n\r\n return max_subseq\r\n\r\n\r\ndef main():\r\n s = input()\r\n print(llps(s))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "s=input()\r\nmx=max(s)\r\ncnt=s.count(mx)\r\nprint(mx*cnt)", "import sys\r\n\r\ndef main():\r\n s = sys.stdin.read().strip()\r\n return max(s)*s.count(max(s))\r\n\r\nprint(main())\r\n", "a=input()\r\nm=\"\"\r\nma=max(a)\r\nfor i in range(len(a)):\r\n if a[i]==ma:\r\n m+=a[i]\r\nprint(m)", "#----Kuzlyaev-Nikita-Codeforces-----\r\n#------------03.04.2020-------------\r\n\r\nalph=\"abcdefghijklmnopqrstuvwxyz\"\r\n\r\n#-----------------------------------\r\n\r\ns=str(input())\r\nm=\"\"\r\nfor i in range(len(s)):\r\n m=max(m,s[i])\r\nprint(m*s.count(m))", "s = input()\r\nM = sorted(list(s))[-1]\r\nans = \"\"\r\nfor c in s:\r\n if c == M:\r\n ans += M\r\nprint(ans)\r\n", "x=input()\r\nprint(max(x)*x.count(max(x)))", "word = str(input())\r\ndictionary = dict()\r\nfor i in word:\r\n dictionary[i] = i*(word.count(i))\r\nsort = sorted(dictionary)\r\nprint(dictionary[sort[-1]])", "numInput = input()\nres = \"\"\nres += numInput[0]\nfor i in range(1, len(numInput)):\n if res[0] > numInput[i]:\n continue\n if res[0] < numInput[i]:\n res = numInput[i]\n else:\n res += numInput[i]\nprint(res)\n \n \t\t \t\t\t \t\t\t\t \t\t \t \t\t\t\t\t", "S=list(input())\r\nA=list(set(S))\r\nA.sort(reverse=True)\r\nprint(A[0]*S.count(A[0]))", "you_d=input()\nlenth=len(you_d)\np=sorted(you_d, reverse=True)\nif p[0] == p[int(lenth)-1]:\n\tprint(you_d)\nelse:\n\tb=[]\n\t[b.append(x) for x in p if x not in b]\n\tno_sec=b[1]\n\tc=p.index(no_sec)\n\thereyouare=p[0:c]\n\tprint(''.join(hereyouare))\n", "\r\n\r\n\r\na = input()\r\ns=0\r\n\r\nfor j in a:\r\n if ord(j)-96 > s:\r\n s=ord(j)-96\r\n\r\n\r\n\r\n\r\nprint( chr(s+96)*a.count(chr(s+96)) )\r\n \r\n", "s = input()\r\na = [0] * 26\r\nfor c in s:\r\n a[ord(c) - ord('a')] += 1\r\n\r\ni = len(a) - 1\r\nwhile a[i] == 0:\r\n i -= 1\r\n\r\nprint(chr(i + ord('a')) * a[i])", "a = input()\r\nb = sorted(a);\r\ncount = 0;\r\nfor i in range(len(b) - 1, -1, -1):\r\n if b[i] == b[-1]:\r\n count += 1\r\nprint(b[-1] * count)", "v=input()\r\na=max(v);print(v.count(a)*a)\r\n", "def Filter(a, n):\r\n j = 0\r\n ans = []\r\n while n > 0:\r\n last_bit = n & 1\r\n if last_bit:\r\n ans.append(a[j])\r\n j += 1\r\n n = n >> 1\r\n return ans\r\n\r\n\r\ndef subs(a):\r\n ultimate = []\r\n for i in range(1 << len(a)):\r\n ultimate.append(Filter(a, i))\r\n return ultimate\r\n\r\n\r\ndef size(ch): return sum([ord(i) for i in ch])\r\n\r\n\r\ns = input()\r\nres = []\r\nfor i in subs(s):\r\n if len(set(i)) == 1:\r\n res.append(i)\r\nres.sort()\r\nprint(\"\".join(res[-1]))", "s = input ()\r\nS = sorted (s)\r\nc = 0\r\nfor i in range (len (S)):\r\n if S[i] == S[-1]:\r\n c += 1\r\nfor i in range (c):\r\n print (S[-1], end=\"\")\r\n", "s=input()\r\n#s=s.lower()\r\nm=max(s)\r\nprint(m* s.count(m))", "s = input()\r\nn = len(s)\r\nx = []\r\nfor i in range(1 << n):\r\n bit = bin(i)[2:].zfill(n)\r\n s2 = \"\"\r\n for j in range(n):\r\n if bit[j] == \"1\":\r\n s2 += s[j]\r\n if s2 == s2[::-1]:\r\n x.append(s2)\r\nprint(max(x))", "def main():\n s = [c for c in input()]\n s.sort(reverse=True)\n i = next(index for index in range(len(s) - 1, -1, -1) if s[index] == s[0])\n s_sorted = ''.join(s)\n print(s_sorted[:(i + 1)])\n\n\nif __name__ == '__main__':\n main()\n", "s = input()\r\nc = s[0]\r\nsz = len(s)\r\nmx = 0\r\n\r\nfor i in range(sz):\r\n if c < s[i]:\r\n c = s[i]\r\n mx = 1\r\n elif c == s[i]:\r\n mx += 1\r\n\r\nfor i in range(mx):\r\n print(c, end=\"\")\r\nprint()\r\n", "s = input()\r\nlc = s[0]\r\nfor i in s:\r\n if i>lc:\r\n lc = i\r\nc = 0\r\nfor i in s:\r\n if lc == i:\r\n c += 1\r\nprint(lc*c)", "s = input()\r\nmax_char = max(s)\r\nprint(max_char * s.count(max_char))", "s=input()\r\nch=[0]*26\r\ni=j=len(s)\r\nc=''\r\n\r\nwhile i:\r\n i=i-1\r\n j=ord(s[i])-ord('a')\r\n ch[j]=ch[j]+1\r\n\r\ni=26\r\n\r\nwhile i:\r\n i=i-1\r\n \r\n if ch[i]:\r\n c=chr(i+ord('a'))\r\n while ch[i]:\r\n ch[i]=ch[i]-1\r\n print(c,end=\"\")\r\n break", "s=input()\r\nmax=0\r\nfor i in range(len(s)):\r\n if ord(s[i])>max:\r\n max=ord(s[i])\r\n else:\r\n max=max\r\nprint(chr(max)*s.count(chr(max))) ", "a = input()\r\na = list(a)\r\nx=a.count(max(a))\r\nprint(max(a)*x)\r\n", "s=input()\r\nm=max(s)\r\nc=s.count(m)\r\nprint(m*c)", "n=''.join(sorted(input())[::-1])\nprint(n[0]*n.count(n[0]))\n", "a = input()\r\nans = 0\r\nfor i in a:\r\n if ans<ord(i): ans = ord(i);x=i\r\nprint(x*(a.count(x)))\r\n", "s=str(input())\r\n#s1=set(s)\r\nfor i in range(s.count(max(s))):\r\n\tprint(max(s),end=\"\")", "st = input();\r\n\r\nbigger = '';\r\nfor i in range(len(st)):\r\n if(st[i] >= bigger):\r\n bigger = st[i];\r\n \r\n \r\nfor i in st:\r\n if i == bigger:\r\n print(i, end=\"\");\r\n", "#https://codeforces.com/problemset/problem/202/A\nv=input()\nm=max(v)\nprint(m*(v.count(m)))\n\n", "s=input()\r\nl=[]\r\nfor i in s:\r\n\tif ord(i) not in l:\r\n\t\tl.append(ord(i))\r\nc=chr(max(l))\r\nprint(c*s.count(c))\r\n\t\r\n\r\n\t\t\r\n\r\n\t\t\t\r\n\t\t\r\n\r\n\r\n\r\n \r\n\r\n\r\n \r\n", "name=input()\r\nm=1\r\nfor i in range(len(name)):\r\n if ord(name[i])>m:m=ord(name[i])\r\nx=0\r\nc=''\r\nfor i in range(len(name)):\r\n if ord(name[i])==m:\r\n c=name[i]\r\n x+=1\r\nprint(c*x)", "n=input()\r\nx=[]\r\nfor i in range(0,len(n)):\r\n x.append(n[i])\r\nc=max(x)\r\ny=0\r\nfor i in range(0,len(n)):\r\n if x[i]==c:\r\n print(c,end='')\r\n else:\r\n continue\r\n", "s = input()\r\n\r\nmx = \"\"\r\ncount = 1\r\nfor char in s:\r\n if char > mx:\r\n mx = char\r\n count = 1\r\n elif char == mx:\r\n count += 1\r\nprint(mx * count)\r\n\r\n", "s = input()\r\nL = [x for x in s]\r\nfrom collections import Counter\r\nX = Counter(L)\r\nprint(max(s)*(X[max(s)]))", "#Leemos la cadena\ns = input()\n#Iniciamos la lista de los carácteres de la cadena\ncharacters = []\n\n#Agregamos los caracteres a la lista\nfor char in s:\n characters.append(char)\n\n#Ordenamos los caracteres\ncharacters.sort()\n\n#Obtenemos el último caracter, es decir, el mayor lexicograficalmente xd\nchar = characters[-1]\nsolution = \"\"\n\n#Dependiendo de cuantas veces se repita en el arreglo, armamos la respuesta\nfor i in range(len(characters) - 1, -1, -1):\n if (characters[i] == char): solution += char\n\nprint(solution)\n", "def largest_palindromic_substr(s):\r\n ans = \"\"\r\n max_val = s[0]\r\n for i in range(1, len(s)):\r\n max_val = max(max_val, s[i])\r\n for i in range(0, len(s)):\r\n if s[i] == max_val:\r\n ans += s[i]\r\n return ans\r\n\r\ns = input()\r\nprint(largest_palindromic_substr(s))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "from collections import Counter\r\ns=input()\r\nx=Counter(s)\r\nfor i in reversed(sorted (x)) :\r\n print((i*x[i]))\r\n break", "'''input\r\nmississipp\r\n\r\n\r\n'''\r\n\r\ns = input()\r\ndic = {}\r\nfor l in s:\r\n\tif l in dic:\r\n\t\tdic[l] += l\r\n\telse:\r\n\t\tdic[l] = l\r\nans = 'a'\r\nfor key in dic:\r\n\tans = max(ans, key)\r\nprint(dic[ans])", "from collections import defaultdict\r\nn=input()\r\nprint(max(n)*n.count(max(n)))\r\n", "t=input();c=max(t);print(t.count(c)*c)\r\n", "def solution(l1):\r\n l1.sort()\r\n l1.reverse()\r\n c_out=\"\"\r\n for x in l1:\r\n if x==l1[0]:\r\n c_out+=x\r\n return c_out\r\ndef answer():\r\n l1 = list(input())\r\n print(solution(l1))\r\nanswer()", "s=input();c=max(s)\r\nprint(s.count(c)*c)", "ss=input()\r\nans=\"a\"\r\nfor i in ss:\r\n if i>ans:\r\n ans=i\r\nprint(ans*ss.count(ans))", "s=input()\r\nm=0\r\nfor z in s:\r\n m=max(m,ord(z))\r\ny=s.count(chr(m))\r\nprint(chr(m)*y)", "s = input()\r\nalphabetArr = []\r\nfor i in range(26):\r\n alphabetArr.append(0);\r\nfor ch in s:\r\n alphabetArr[ord(ch)-ord('a')]+=1\r\n\r\nans=0\r\n\r\nfor i in range(26):\r\n if(alphabetArr[i]!=0):\r\n ans=i\r\n\r\nansChar = chr(ans+ord('a'))\r\n\r\nprint(ansChar*alphabetArr[ans])", "s = list(input())\r\ns.sort()\r\na = \"\"\r\nif s.count(s[-1])<=1:\r\n print(s[-1])\r\nelse:\r\n s = s[len(s)-s.count(s[-1]):]\r\n for i in range(len(s)):\r\n a = a+s[i]\r\n print(a)\r\n ", "from itertools import chain, combinations\r\n\r\ns = list(input())\r\npalindromes = []\r\nfor subs in list(chain.from_iterable(combinations(s, r) for r in range(len(s)+1))):\r\n if subs == subs[::-1]:\r\n palindromes.append(subs)\r\nprint(sorted([''.join(palindrome) for palindrome in palindromes], reverse= True)[0])", "s=input()\r\nd={}\r\nfor i in s:\r\n d[i]=d.get(i,0)+1\r\nd=sorted(d.items())\r\ns=d[-1][0]\r\nprint(d[-1][0]*d[-1][1])", "dash=input()\r\nlex=sorted([i for i in dash])[-1]\r\nprint(lex*dash.count(lex))", "def solution(s):\r\n s=sorted(s,reverse=True)\r\n n=len(s)\r\n ans=s[0]\r\n for i in range(1,n):\r\n if(s[i-1]==s[i]):\r\n ans+=(s[i])\r\n else:\r\n return ans\r\n return ans\r\n\r\ns=input()\r\nprint(solution(s))\r\n", "try:\r\n s=list(input())\r\n s.sort(reverse=True)\r\n print(s[0]*s.count(s[0]))\r\n\r\nexcept:\r\n pass", "s=input()\r\nch=(max(s))\r\nt=s.count(ch)\r\n\r\nfor i in range (t):\r\n print(ch,end='')\r\n", "s = input()\r\nmx = ''\r\nfor i in range(len(s)):\r\n mx = max(mx, s[i])\r\nfor i in range(len(s)):\r\n if s[i] == mx:\r\n print(s[i], end='')\r\n", "def palind(s):\r\n return s[:(len(s) + 1) // 2] == s[len(s) // 2:]\r\ns = [i for i in input()]\r\nmaxx = ''\r\nfor mask in range(1 << len(s)):\r\n s2 = [s[i] for i in range(len(s)) if mask & (1 << i)]\r\n if palind(s2) and ''.join(s2) > maxx:\r\n maxx = ''.join(s2)\r\nprint(maxx)", "s = list(map(str, input()))\r\nans =max(s)\r\nprint(ans*s.count(ans))\r\n", "from collections import Counter\r\nF = Counter(list(input()))\r\nfor c in 'abcdefghijklmnopqrstuvwxyz'[::-1]:\r\n if (0 < F[c]): print(c*max(1,F[c])); break", "n = input()\r\nk = [ord(i) for i in n]\r\nprint(chr(max(k)) * n.count(chr(max(k))))", "input_string = input()\r\n\r\n# Cari karakter terbesar berdasarkan nilai ASCII\r\nlargest_char = max(input_string, key=ord)\r\n\r\n# Filter hanya karakter terbesar dari input\r\n# filtered_chars = filter(lambda x: x == largest_char, input_string)\r\n\r\n# Gabungkan karakter-karakter terbesar menjadi satu string\r\nresult = \"\".join(filter(lambda x: x == largest_char, input_string))\r\n\r\nprint(result)\r\n", "# 202A, LLPS\r\n# input - string\r\n# find all substring palindroms that i can make (order must be kept)\r\n# compare palindroms - > return biggiest palindrom as output (by string comparation p1 > p2)\r\n \r\ns = list(input())\r\nprint(max(s) * s.count(max(s)))\r\n\r\n'''\r\n# get all substrings of string\r\nS = [s[i: j] for i in range(len(s)) for j in range(i + 1, len(s) + 1)]\r\nprint(S)\r\n# check if palindrom:\r\nP = []\r\nfor sub in S:\r\n match = True\r\n if len(sub) % 2 == 1:\r\n # print(sub, len(sub) // 2)\r\n for i in range(len(sub) // 2):\r\n # print('first, last: ', sub[i], sub[-i])\r\n if sub[i] != sub[-i - 1]:\r\n match = False\r\n break\r\n else:\r\n match = False\r\n if match == True:\r\n P.append(sub)\r\n\r\nprint(P)\r\n'''", "a = input();d ={}\r\nfor i in a :\r\n try :d[i]+=1\r\n except :d[i]=1\r\nm = 0 ; a='a';b=0\r\nfor i,j in d.items():\r\n if ord(i)>=ord(a) :\r\n a=i ; m=j\r\nprint(a*m)", "st = input()\r\nmaxChar = 'A'\r\nfor char in st:\r\n if (char > maxChar):\r\n maxChar = char\r\n\r\n\r\nprint(maxChar * st.count(maxChar))", "import io, os, sys\r\n\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\n\r\ndef solve():\r\n s = input().strip().decode()\r\n ms = max(s)\r\n s = s[s.index(ms):]\r\n cand = [s[0], '']\r\n for i in range(1, len(s)):\r\n tmp = []\r\n for c in cand:\r\n tmp.append(c)\r\n tmp.append(c + s[i])\r\n cand = tmp\r\n cand = [c for c in cand if c == c[::-1]]\r\n sys.stdout.write(f'{max(cand)}\\n')\r\n\r\n \r\n\r\n\r\nif __name__ == '__main__':\r\n solve()\r\n", "s = input()\r\n\r\nalphabet_dict = {}\r\nfor i in range(26):\r\n letter = chr(ord('a') + i)\r\n number = i + 1\r\n alphabet_dict[letter] = number\r\n\r\n\r\nlett = \"a\"\r\nfor i in s:\r\n if alphabet_dict[i] > alphabet_dict[lett]:\r\n lett = i\r\n\r\nss = \"\"\r\nfor i in s:\r\n if i == lett:\r\n ss += i\r\n\r\nprint(ss)", "arr = input()\ni = sorted(arr, reverse= True, key= lambda x: ord(x))[0]\nprint(i * arr.count(i))", "s = input()\r\nm = max(s)\r\nc = s.count(m)\r\nfor i in range(c):\r\n print(m,end=\"\")", "import collections\r\nimport math\r\nsums = lambda n: int(n * (n + 1) / 2) # sum from 1 to n\r\nsumsqur = lambda n: int( (n) * (n + 1) * (2*n +1)/6) # sum square from 1 to n\r\n\r\ndef im(): return map(int, input().split())\r\ndef il(): return list(map(int, input().split()))\r\ndef ii(): return int(input())\r\n\r\n# \"abcdefghijklmnopqrstuvwxyz\"\r\n\r\ndef isPalindrom(a):\r\n return True if a[::-1] == a else False\r\n\r\ndef solve():\r\n s=input()\r\n m=max(s)\r\n print(m * s.count(m))\r\n\r\n\r\nif __name__ == '__main__':\r\n #for i in range(ii()):\r\n solve()\r\n", "# cook your dish here\r\nn=input()\r\nx=[ ch for ch in n]\r\nx.sort()\r\nprint(x[len(x)-1]*(x.count(x[len(x)-1])))", "s = input()\r\ni= max(s)\r\nprint(s.count(i)*i)\r\n \r\n ", "# import sys\r\n# sys.stdin=open(\"input.in\",\"r\")\r\ns=input()\r\nc=max(s)\r\nprint(s.count(c)*c)", "s = input()\r\nc = max(s)\r\nfor x in s:\r\n if x == c:\r\n print(c,end='')\r\n", "def llps(a):\r\n max=ord(a[0])\r\n count=0\r\n for i in range(len(a)):\r\n c=ord(a[i])\r\n if c>max:\r\n max=c\r\n count=0\r\n \r\n if c==max:\r\n count=count+1\r\n\r\n print(chr(max)*count)\r\n\r\n\r\na=input('')\r\nllps(list(a))\r\n#print(a)\r\n\r\n \r\n \r\n \r\n\r\n ", "# cook your dish here\r\ns = input()\r\nchars = dict()\r\nmax_ch = ''\r\nfor ch in s:\r\n if ch in chars:\r\n chars[ch] += 1\r\n else:\r\n chars[ch] = 1\r\n max_ch = max(max_ch, ch)\r\n\r\nans = \"\"\r\nfor i in range(chars[max_ch]):\r\n ans += max_ch\r\nprint(ans)" ]
{"inputs": ["radar", "bowwowwow", "codeforces", "mississipp", "tourist", "romka", "helloworld", "zzzzzzzazz", "testcase", "hahahahaha", "abbbbbbbbb", "zaz", "aza", "dcbaedcba", "abcdeabcd", "edcbabcde", "aaaaaaaaab", "testzzzzzz", "zzzzzzwait", "rrrrrqponm", "zzyzyy", "aababb", "zanzibar", "hhgfedcbaa", "aabcdefghh", "aruaru", "uraura", "aru", "aburvabur", "ura", "eurottat", "referee", "joking", "seriously", "sets", "test", "klmgameklm", "dfkjafdkdd", "zzzzzzzzzz", "aaaaaaaaaa", "buzz", "b", "y", "yy", "zz", "bb", "aa", "a", "z", "zz", "zzazazzzaz", "hellhellhe", "hellohello", "refer"], "outputs": ["rr", "wwwww", "s", "ssss", "u", "r", "w", "zzzzzzzzz", "tt", "hhhhh", "bbbbbbbbb", "zz", "z", "e", "e", "ee", "b", "zzzzzz", "zzzzzz", "rrrrr", "zzz", "bbb", "zz", "hh", "hh", "uu", "uu", "u", "v", "u", "u", "rr", "o", "y", "t", "tt", "mmm", "kk", "zzzzzzzzzz", "aaaaaaaaaa", "zz", "b", "y", "yy", "zz", "bb", "aa", "a", "z", "zz", "zzzzzzz", "llll", "oo", "rr"]}
UNKNOWN
PYTHON3
CODEFORCES
713
127271f32b49adfdbf73c1c5f1ee489a
Turn the Rectangles
There are $n$ rectangles in a row. You can either turn each rectangle by $90$ degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles. Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such). The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of rectangles. Each of the next $n$ lines contains two integers $w_i$ and $h_i$ ($1 \leq w_i, h_i \leq 10^9$) — the width and the height of the $i$-th rectangle. Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO". You can print each letter in any case (upper or lower). Sample Input 3 3 4 4 6 3 5 2 3 4 5 5 Sample Output YES NO
[ "import sys\r\n\r\nprev = sys.maxsize\r\nflag = True\r\n\r\nfor _ in range(int(input())):\r\n w, h = map(int, input().split())\r\n if prev >= max(w, h):\r\n prev = max(w, h)\r\n elif prev >= min(w, h):\r\n prev = min(w, h)\r\n else:\r\n flag = False\r\n break\r\n\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "from math import inf\n\nn = int(input())\nres, prv = True, inf\nfor _ in range(n):\n w, h = sorted(int(i) for i in input().split())\n res &= prv >= w\n prv = h if prv >= h else w\nres = \"YES\" if res else \"NO\"\nprint(res)\n", "n = int(input())\n\nrect = []\nfor i in range(n): \n w, h, = map(int, input().split())\n rect.append([w, h])\n\nrect[0][1] = max(rect[0][1], rect[0][0])\nfor i in range(1,n): \n if rect[i][1] <= rect[i-1][1]: \n if rect[i][0] <= rect[i-1][1] and rect[i][0] > rect[i][1]: \n rect[i][1] = rect[i][0]\n elif rect[i][1] > rect[i-1][1]: \n if rect[i][0] <= rect[i-1][1]: \n rect[i][1] = rect[i][0]\n else: \n print(\"NO\")\n exit()\nprint(\"YES\")\n", "n = int(input())\r\nprev = 2000000000\r\nans = True\r\nfor i in range(n):\r\n line = input().split()\r\n a = int(line[0])\r\n b = int(line[1])\r\n if a>prev and b>prev:\r\n ans = False\r\n elif a<=prev and b<=prev:\r\n prev = max(a, b)\r\n elif a<=prev:\r\n prev = a\r\n else:\r\n prev = b\r\n\r\nif ans:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "t=int(input())\r\nh2=999999999999\r\nfor i in range(t):\r\n w,h=map(int,input().split())\r\n if max(w,h)>h2:\r\n if min(w,h)>h2:\r\n print('NO')\r\n exit()\r\n else:\r\n h2=min(w,h)\r\n else:\r\n h2=max(w,h)\r\nprint('YES')", "n = int(input())\r\nw, h = map(int, input().split())\r\ns = max(w, h)\r\nfor i in range(n - 1):\r\n w, h = map(int, input().split())\r\n if max(w, h) <= s:\r\n s = max(w, h)\r\n elif min(w, h) <= s:\r\n s = min(w, h)\r\n else:\r\n print(\"NO\")\r\n exit(0)\r\nprint(\"YES\")\r\n", "num_tests = int(input())\r\na, b = map(int, input().split())\r\nanswer = []\r\nanswer.append(max(a, b))\r\nfor i in range(num_tests - 1):\r\n two = list(map(int, input().split()))\r\n if min(two) <= answer[-1]:\r\n answer.append(max([i for i in two if i <= answer[-1]]))\r\n else:\r\n print('NO')\r\n break\r\nif len(answer) == num_tests:\r\n print('YES')\r\n", "n=int(input())\r\na=[]\r\nfor i in range(n):\r\n a.append([int(x) for x in input().split()])\r\nif n==1:\r\n print('YES')\r\nelse:\r\n res=max(a[0][0],a[0][1])\r\n check=1\r\n for i in range(1,n):\r\n if max(a[i][0],a[i][1])<=res:\r\n res=max(a[i][0],a[i][1])\r\n else:\r\n if min(a[i][0],a[i][1])<=res:\r\n res=min(a[i][0],a[i][1])\r\n else:\r\n check=0\r\n break\r\n if check==1:\r\n print('YES')\r\n else:\r\n print('NO')", "n = int(input())\r\n\r\n[l, b] = [int(x) for x in input().split(' ')]\r\nprev = max(l, b)\r\nfor i in range(n-1):\r\n\t[l, b] = [int(x) for x in input().split(' ')]\r\n\tif( min(l, b) > prev):\r\n\t\tprint(\"NO\")\r\n\t\texit()\r\n\telif l <= prev and b <= prev:\r\n\t\tprev = max(l, b)\r\n\telse:\r\n\t\tprev = min(l, b)\r\n\r\nprint(\"YES\")", "n=int(input())\r\na,b=map(int,input().split())\r\nm=max(a,b)\r\nfor _ in range(n-1):\r\n a,b=map(int,input().split())\r\n a,b=max(a,b),min(a,b)\r\n if a<=m:\r\n m=int(a)\r\n elif b<=m:\r\n m=int(b)\r\n else:\r\n print('NO')\r\n exit()\r\n break\r\nprint('YES')", "n = int(input())\r\nwh = []\r\nfor _ in range(n):\r\n w, h = map(int, input().split())\r\n wh.append([w, h])\r\n\r\nH = max(wh[0])\r\nfor i in range(1, n):\r\n M = max(wh[i])\r\n m = min(wh[i])\r\n if M <= H:\r\n H = M\r\n elif m <= H:\r\n H = m\r\n else:\r\n print(\"NO\")\r\n exit()\r\n\r\nprint(\"YES\")", "n=int(input())\nw,h=map(int,input().split())\ntemp_height=max(w,h)\nflag=1\nfor i in range(n-1):\n temp=0\n w,h=map(int,input().split())\n if w<=h:\n if h<=temp_height:\n temp_height=h\n temp=1\n elif w<=temp_height:\n temp_height=w\n temp=1\n if w>h:\n if w<=temp_height:\n temp_height=w\n temp=1\n elif h<=temp_height:\n temp_height=h\n temp=1\n if temp==0:\n flag=0\n break\nif flag==0:\n print(\"NO\")\nelse:\n print(\"YES\")", "'''\r\nAsk what parent(s)? (qr-1, qg-1?,qg)\r\nAsk when filled?\r\n\r\nif parents not filled by pour, return 0\r\n\r\n 1\r\n 1 1\r\n\r\n\r\n7\r\n3\r\n1\r\n5050\r\n15\r\n1\r\n100000009\r\n33\r\n17\r\n1000000000\r\n99\r\n50\r\n1000000000\r\n99\r\n82\r\n1000000000\r\n67\r\n22\r\n6\r\n3\r\n1\r\n'''\r\nimport sys, io, os\r\nimport math\r\nimport bisect\r\nimport heapq\r\nimport string\r\nimport re\r\nfrom decimal import *\r\nfrom collections import defaultdict,Counter,deque\r\ninput = sys.stdin.readline\r\nsys.setrecursionlimit(100000) \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\ndef WSNOPRINT(out):\r\n return ''.join(map(str, out))\r\n\r\n\r\n'''\r\n'''\r\ndef index(a, x):\r\n 'Locate the leftmost value exactly equal to x'\r\n i = bisect_left(a, x)\r\n if i != len(a) and a[i] == x:\r\n return i\r\n raise ValueError\r\n\r\ndef find_lt(a, x):\r\n 'Find rightmost value less than x'\r\n i = bisect_left(a, x)\r\n if i:\r\n return a[i-1]\r\n raise ValueError\r\n\r\ndef find_le(a, x):\r\n 'Find rightmost value less than or equal to x'\r\n i = bisect_right(a, x)\r\n if i:\r\n return a[i-1]\r\n raise ValueError\r\n\r\ndef find_gt(a, x):\r\n 'Find leftmost value greater than x'\r\n i = bisect_right(a, x)\r\n if i != len(a):\r\n return a[i]\r\n raise ValueError\r\n\r\ndef find_ge(a, x):\r\n 'Find leftmost item greater than or equal to x'\r\n i = bisect_left(a, x)\r\n if i != len(a):\r\n return a[i]\r\n raise ValueError\r\n\r\n\"\"\"\r\n\"\"\"\r\ndef solve():\r\n x = math.inf\r\n for _ in range(II()):\r\n w, h = MII()\r\n mx = max(w,h)\r\n mn = min(w,h)\r\n if mx <= x:\r\n x = mx\r\n elif mn <= x:\r\n x = mn\r\n else:\r\n print('NO')\r\n return\r\n print('YES')\r\n\r\ndef main():\r\n solve()\r\n\r\nmain()\r\n", "n = int(input())\r\nlst =[]\r\nfor i in range(n):\r\n a,b = map(int,input().split())\r\n lst.append([a,b])\r\nnum = 0x3f3f3f3f\r\nposs= True\r\nfor i in range(n):\r\n a,b = lst[i][0],lst[i][1]\r\n if num>=max(a,b):\r\n num = max(a,b)\r\n elif num>=a:\r\n num = a\r\n elif num>=b:\r\n num=b\r\n else:\r\n poss = False\r\nif poss:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=int(input())\r\na=[tuple(map(int,input().split())) for _ in range(n)]\r\na[0]=max(*a[0])\r\nfor i in range(1,n):\r\n\tx,y=sorted(a[i])\r\n\tif y<=a[i-1]:a[i]=y\r\n\telse:a[i]=x\r\nif a==sorted(a,reverse=True):print('YES')\r\nelse:print('NO')", "a = int(input())\nw, h = map(int, input().split())\n\nk = max(w, h)\nb = True\nfor i in range(a-1):\n w1, h1 = map(int, input().split())\n maxi = max(w1, h1)\n mini = min(w1, h1)\n\n if b:\n if maxi <= k:\n k = maxi\n elif mini <=k:\n k = mini\n else:\n b = False\n\n\nif b:\n print('YES')\nelse:\n print('NO')", "from functools import lru_cache\r\nlru_cache(maxsize=None)\r\n\r\nt=int(input())\r\nl=[]\r\ntemp=0\r\na,b=map(int,input().split())\r\nc=max(a,b)\r\nfor _ in range(t-1):\r\n a,b=map(int,input().split())\r\n l.append([a,b])\r\nfor a,b in l:\r\n if min(a,b)<=c:\r\n if max(a,b)<=c:\r\n c=max(a,b)\r\n elif a<=c:\r\n c=a\r\n else:\r\n c=b\r\n \r\n else:\r\n temp=1\r\n break\r\nprint(\"YES\") if temp==0 else print(\"NO\")", "d=[]\r\ne=[]\r\na=int(input())\r\nfor i in range(a):\r\n b,c=list(map(int,input().split()))\r\n d+=[[b,c]]\r\nf=min(d[-1][0],d[-1][1])\r\ng=max(d[0][0],d[0][1])\r\nc=True\r\nfor j in range(a-2,-1,-1):\r\n if min(d[j][0],d[j][1])>=f: f=min(d[j][0],d[j][1])\r\n elif max(d[j][0],d[j][1])>=f: f=max(d[j][0],d[j][1])\r\n else:\r\n c=False\r\n break\r\nif c:print(\"YES\")\r\nelse: print(\"NO\")\r\n\r\n\r\n\r\n", "def solve():\r\n n=int(input()) # Read n as input\r\n x=10**9 # Assign x to maximum value\r\n for _ in range(n): # Loop through n rectangles\r\n w,h=sorted(map(int,input().split())) # Read w and h and sort them\r\n if h<=x: # Height of n rectangles should be in non-ascending order\r\n x=h # save height to x\r\n elif w<=x: # if height is larger than x, check if width is smaller than x\r\n x=w # save new height to x\r\n else:\r\n print('NO') # non-ascending order of rectangle heights is not possible.\r\n return\r\n print('YES')\r\n\r\nsolve()", "import sys\r\n\r\ninput = sys.stdin.buffer.readline\r\nn = int(input())\r\na = [list(map(int, input().split())) for i in range(n)]\r\nc = max(a[0])\r\n\r\nfor i in range(1, n):\r\n if c >= max(a[i]):\r\n c = max(a[i])\r\n elif c >= min(a[i]):\r\n c = min(a[i])\r\n else:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")", "import sys\r\n\r\nn = int(input())\r\na, b = map(int, input().split())\r\nupper = max(a,b)\r\nfor _ in range(1, n):\r\n a, b = map(int, input().split())\r\n up = max(a,b)\r\n lo = min(a,b)\r\n if upper >= up:\r\n upper = up\r\n elif upper >= lo:\r\n upper = lo\r\n else:\r\n print('NO')\r\n sys.exit(0)\r\nprint('YES')\r\n\r\n", "n = int(input())\r\na = []\r\n\r\nfor i in range(n):\r\n w, h = map(int, input().split())\r\n a.append([w, h])\r\n\r\na.reverse()\r\n\r\nlst = 0\r\nfor i in range(n):\r\n if a[i][0] > a[i][1]:\r\n a[i][0], a[i][1] = a[i][1], a[i][0]\r\n \r\n if a[i][0] >= lst:\r\n lst = a[i][0]\r\n elif a[i][1] >= lst:\r\n lst = a[i][1]\r\n else:\r\n print(\"NO\")\r\n exit()\r\n\r\nprint(\"YES\")", "n = int(input()) # Number of rectangles\r\nprev_height = float('inf') # Initialize previous height as positive infinity\r\n\r\nfor _ in range(n):\r\n w, h = map(int, input().split()) # Width and height of the rectangle\r\n if max(w, h) <= prev_height: # Compare max of width and height with previous height\r\n prev_height = max(w, h) # Update previous height with max of width and height\r\n elif min(w, h) <= prev_height: # Compare min of width and height with previous height\r\n prev_height = min(w, h) # Update previous height with min of width and height\r\n else:\r\n print(\"NO\") # If neither condition is met, it is not possible to arrange rectangles in non-ascending height order\r\n exit(0)\r\n\r\nprint(\"YES\") ", "t=int(input())\r\ntt=t\r\nprevH=0\r\nans=True\r\nfor i in range(t):\r\n t1=list(map(int,input().split()))\r\n x=t1[0]\r\n y=t1[1]\r\n if(i==0):\r\n prevH=max(x,y)\r\n continue\r\n if x<=prevH and y<=prevH:\r\n prevH=max(x,y)\r\n else:\r\n if x>prevH and y>prevH:\r\n ans=False\r\n break\r\n if x<=prevH:\r\n prevH=x\r\n else:\r\n prevH=y\r\nif ans:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "# Problem Link: https://codeforces.com/problemset/problem/1008/B\r\n# Problem Status:\r\n# -------------- Separator --------------\r\ndef getMin(X_, Y_):\r\n if X_ <= Y_:\r\n return X_\r\n else:\r\n return Y_\r\n\r\n\r\ndef getMax(X_, Y_):\r\n if X_ >= Y_:\r\n return X_\r\n else:\r\n return Y_\r\n\r\n\r\n# -------------- Separator --------------\r\nN = int(input())\r\nflag = True\r\ntemp = -1\r\nwhile N:\r\n N -= 1\r\n X, Y = list(map(int, input().split()))\r\n if temp == -1:\r\n temp = getMax(X, Y)\r\n else:\r\n if temp >= getMax(X, Y) and temp >= getMin(X, Y):\r\n temp = getMax(X, Y)\r\n elif temp >= getMin(X, Y):\r\n temp = getMin(X, Y)\r\n else:\r\n print(\"NO\")\r\n flag = False\r\n break\r\nif flag:\r\n print(\"YES\")\r\n\r\n\r\n# -------------- Separator --------------\r\n", "n=int(input())\r\na=[max(map(int,input().split()))]\r\nf=True\r\nfor i in range(1,n):\r\n b=list(map(int,input().split()))\r\n if max(b)<=a[-1]:\r\n a.append(max(b))\r\n elif min(b)<=a[-1]:\r\n a.append(min(b))\r\n else:\r\n f=False\r\nif f:\r\n print('YES')\r\nelse:\r\n print('NO')", "n=int(input())\r\n_h=0\r\nna='YES'\r\nfor i in range(n):\r\n w,h= map(int, input().split())\r\n if _h==0:\r\n _h=max(w,h)\r\n if w>_h and h>_h:\r\n na='NO'\r\n break\r\n elif max(w,h)<=_h:\r\n _h= max(w,h)\r\n elif min(w,h)<=_h:\r\n _h= min(w,h)\r\nprint(na)", "n = int(input())\r\nflag = True\r\nph = 10e9\r\nfor _ in range(n):\r\n h, w = map(int, input().split())\r\n if ph >= max(h, w):\r\n ph = max(h, w)\r\n elif ph >= min(h, w):\r\n ph = min(h, w)\r\n else:\r\n flag = False\r\n break\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nq = 10**10\r\nfl = True\r\nfor i in range(n):\r\n w, h = map(int,input().split())\r\n if max(w, h) <= q:\r\n q = max(w,h)\r\n else:\r\n if min(w,h) <= q:\r\n q = min(w,h)\r\n else:\r\n fl = False\r\n break\r\nif fl:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "t = int(input())\r\nrecs = []\r\nfor i in range(t):\r\n l = list(map(int, input().split()))\r\n l.sort()\r\n if i != 0:\r\n if recs[i-1] < l[1]:\r\n recs.append(l[0])\r\n else:\r\n recs.append(l[1])\r\n else:\r\n recs.append(l[1])\r\n\r\nsortedd = True\r\nfor i in range(t-1):\r\n if recs[i] < recs[i+1]:\r\n sortedd = False\r\nif sortedd:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def main():\r\n n = int(input())\r\n w = []\r\n for i in range(n):\r\n h, l = map(int, input().split())\r\n w.append([h, l])\r\n w[0][0] = max(w[0])\r\n ch = True\r\n for i in range(1, n):\r\n if max(w[i]) > w[i-1][0]:\r\n if min(w[i]) > w[i-1][0]:\r\n ch = False\r\n break\r\n else:\r\n w[i][0] = min(w[i])\r\n else:\r\n w[i][0] = max(w[i])\r\n if ch:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\nmain()\r\n", "\"\"\"\nhttps://codeforces.com/problemset/problem/1008/B\n\"\"\"\n\nrectangles = [[int(x) for x in input().split()] for _ in range(int(input()))]\n\na, b = rectangles[0]\nm = a\nif a < b:\n rectangles[0] = [b, a]\n m = b\npossible = True\nfor i, (a, b) in enumerate(rectangles[1:], 1):\n if max(a, b) <= m:\n rectangles[i] = [max(a, b), min(a, b)]\n m = max(a, b)\n elif min(a, b) <= m:\n rectangles[i] = [min(a, b), max(a, b)]\n m = min(a, b)\n else:\n possible = False\n break\nif possible:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "class pair:\r\n def __init__(self,w,h):\r\n self.w=w\r\n self.h=h\r\n\r\nn=int(input())\r\na=[pair]*n\r\n\r\nfor i in range(n):\r\n w,h=map(int,input().split())\r\n a[i]=pair(w,h)\r\n\r\ncurr=min(a[n-1].w,a[n-1].h)\r\nfor i in range(n-2,-1,-1):\r\n if max(a[i].w,a[i].h)<curr:\r\n print('NO')\r\n exit(0)\r\n\r\n if min(a[i].w,a[i].h)>=curr:\r\n curr=min(a[i].w,a[i].h)\r\n else:\r\n curr=max(a[i].w,a[i].h)\r\n\r\nprint('YES')", "\r\n\r\ndef solve():\r\n for i in range(int(input())):\r\n w, h = map(int, input().split())\r\n if i == 0:\r\n previous_height = max(w,h)\r\n continue\r\n if max(w,h) <= previous_height:\r\n previous_height = max(w,h)\r\n elif min(w,h) <= previous_height:\r\n previous_height = min(w,h)\r\n else:\r\n print(\"NO\")\r\n return\r\n print(\"YES\")\r\n \r\nsolve()\r\n" ]
{"inputs": ["3\n3 4\n4 6\n3 5", "2\n3 4\n5 5", "10\n4 3\n1 1\n6 5\n4 5\n2 4\n9 5\n7 9\n9 2\n4 10\n10 1", "10\n241724251 76314740\n80658193 177743680\n213953908 406274173\n485639518 859188055\n103578427 56645210\n611931853 374099541\n916667853 408945969\n677773241 808703176\n575586508 440395988\n450102404 244301685", "10\n706794178 103578427\n431808055 641644550\n715688799 406274173\n767234853 345348548\n241724251 408945969\n808703176 213953908\n185314264 16672343\n553496707 152702033\n105991807 76314740\n61409204 244301685", "1\n1 1", "4\n10 10\n8 8\n8 15\n9 9", "4\n10 10\n8 8\n8 9\n9 9", "3\n3 4\n4 5\n5 5", "3\n10 10\n5 5\n10 10", "3\n5 5\n4 6\n5 5", "3\n5 7\n3 9\n8 10", "3\n10 10\n1 1\n2 2", "3\n3 5\n1 2\n3 4", "3\n4 8\n6 25\n12 12", "3\n3 5\n4 10\n6 6", "3\n200 200\n300 20\n50 50", "3\n5 3\n6 4\n5 5", "4\n5 5\n4 6\n4 4\n5 5", "3\n10 10\n1 100\n20 20", "4\n1 3\n2 4\n3 5\n4 6", "3\n1 60\n70 55\n56 80", "3\n5 6\n5 7\n6 8", "3\n6 6\n5 7\n6 6"], "outputs": ["YES", "NO", "NO", "NO", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO"]}
UNKNOWN
PYTHON3
CODEFORCES
34
12785439f019574c6379b2557b4c2af2
Love Triangle
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*. We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth. The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes. The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO». You can output any letter in lower case or in upper case. Sample Input 5 2 4 5 1 3 5 5 5 5 5 1 Sample Output YES NO
[ "n = int(input())\r\nf = [int(i) for i in input().split()]\r\nD = {}\r\nfor i in range(1, n + 1):\r\n D[i] = f[i - 1]\r\nres = 'NO'\r\nfor ver in D.keys():\r\n chel = ver\r\n for _ in range(3):\r\n ver = D[ver]\r\n if ver == chel:\r\n res = 'YES'\r\nprint(res)", "n = int(input())\narrf = [0]\narr2 = [int(x) for x in input().split(' ')]\narrf.extend(arr2)\n\nmemo = []\nfor i in range(1, n+1):\n if i not in memo:\n j = arrf[i]\n k = arrf[j]\n if arrf[k] == i:\n print(\"YES\")\n break\n memo.append(i)\n memo.append(j)\n memo.append(k)\n else:\n continue\nelse:\n print(\"NO\")\n \t\t \t\t\t\t \t\t\t \t \t \t\t\t \t \t \t", "from sys import stdin\r\n\r\ndef decide(dct):\r\n for i in dct.keys():\r\n if dct[dct[dct[i]]] == i:\r\n return 'YES'\r\n return 'NO'\r\n\r\n\r\ndef main():\r\n planes = int(stdin.readline().strip())\r\n edges = stdin.readline().strip().split()\r\n dct = {}\r\n for i in range(1, planes+1):\r\n dct[i] = int(edges[i-1])\r\n result = decide(dct)\r\n print(result)\r\nmain()", "import sys\r\n#sys.stdin = open(\"input.txt\", \"r\")\r\n\r\nn = int(input())\r\nli = list(map(int, input().split()))\r\nli.insert(0,0)\r\n# print(li)\r\nres = 0\r\nfor i in range(1,n):\r\n if i == li[li[li[i]]]:\r\n res = 1\r\n break\r\nif res == 1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\narr = [0]\narr += list(map(int,input().split()))\nflag = False\nfor i in range(1,n):\n temp_arr = [i]\n current = arr[i]\n for j in range(3):\n temp_arr.append(current)\n current = arr[current] \n if temp_arr[0] == temp_arr[3]:\n print(\"YES\")\n flag = True\n break\nif not flag:\n print(\"NO\")\n \n\n \t\t \t \t\t\t \t\t \t \t \t\t \t \t\t\t\t", "n=int(input())\r\nf=[int(f) for f in input().split()]\r\ntriangle=0\r\nfor i in range(0,len(f)-1):\r\n f1=f[i]\r\n f2=f[f1-1]\r\n f3=f[f2-1]\r\n if f[f3-1]==f[i]:\r\n triangle+=1\r\n break\r\n\r\nprint(\"YES\") if triangle>0 else print(\"NO\")", "n = int(input())\r\ncheck = 0\r\nplane = list(map(int, input().split(\" \")))\r\nplane = [plane[i]-1 for i in range(0, n)]\r\nfor i in range(0, n):\r\n if plane[plane[plane[i]]] == i: \r\n check = 1\r\nelse:\r\n print(\"YES\" if check else \"NO\")", "n=int(input())\r\nflag=False\r\nfn=list(map(int,input().split()))\r\n\r\nfor i in range(0,n):\r\n \r\n x=fn[i] #1 likes 8\r\n y=fn[fn[i]-1] #8 likes 10\r\n z=fn[fn[fn[i]-1]-1] #10 likes 1\r\n \r\n \r\n if(z==i+1):\r\n print(\"YES\")\r\n flag=True\r\n break\r\n\r\nif(flag==False):\r\n print(\"NO\")\r\n", "n = int(input())\r\np = list(map(int, input().split()))\r\np = [ (p[i] - 1) for i in range (n)]\r\nfor i in range(n):\r\n if p[p[p[i]]] == i:\r\n print(\"YES\")\r\n break\r\n if i == n - 1:\r\n print(\"NO\")\r\n ", "n=int(input())\r\nr=0\r\na=[int(i)for i in input().split()]\r\nfor i in range(n):\r\n g=a[a[i]-1]\r\n h=a[g-1]\r\n if h-1==i:\r\n r=1\r\nif r==1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=int(input())\narr=list(map(int,input().split(' ')[:n]))\n\nif n<3:\n print(\"NO\")\n\nelse:\n for i in range(n):\n if arr[arr[arr[i-1]-1]-1]==i:\n print(\"YES\")\n exit()\n print(\"NO\")\n\t\t\t \t \t \t \t\t \t \t\t", "n = int(input())\r\n\r\narr = list(map(int, input().split()))\r\n\r\n_set = set(arr)\r\n\r\nlove_tri = False\r\n\r\nif n > 2 and len(_set) > 2:\r\n for index, num in enumerate(arr):\r\n A = num\r\n B = index+1\r\n if B in _set:\r\n C = arr.index(B)+1\r\n if C in _set:\r\n if arr.index(C)+1 == A:\r\n love_tri = True\r\n break\r\nif love_tri:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "# trees = [int(x) for x in input().split()]\ndef make_tri(a,ind):\n ind2 = a[ind]\n ind3 = a[ind2]\n if a[ind3] ==ind:\n # print(a)\n # print(ind,ind2,ind3)\n return True\n else:\n return False\nn = int(input())\na= [int(x)-1 for x in input().split()]\ntri = False\nfor ind in range(len(a)):\n tri = make_tri(a,ind)\n if tri:\n break\nif tri:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\nfor i in range (n):\r\n arr[i] = arr[i] - 1\r\nflag = 0\r\nfor i in range(len(arr)):\r\n if (arr[arr[arr[i]]] == i):\r\n flag = 1\r\n break\r\nif flag == 1:\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\") \r\n ", "a=int(input())\r\nb=list(map(int,input().split()))\r\nd={}\r\nfor i in range(len(b)):\r\n \r\n d[i+1]=b[i]\r\nf=0\r\n\r\n\r\nfor key,value in d.items():\r\n if value in d:\r\n if d[value] in d:\r\n if d[d[value]]==key:\r\n print(\"YES\")\r\n f=1\r\n break\r\nif f!=1:\r\n print(\"NO\")\r\n\r\n \r\n ", "n = int(input())\r\nf = [0] + [int(i) for i in input().split()]\r\n\r\nfound = False\r\n\r\nfor i in range(1, n + 1):\r\n if f[f[f[i]]] == i:\r\n found = True\r\n\r\nresult = 'YES' if found else 'NO'\r\nprint(result)\r\n", "def find_love_triangle(n, preferences):\r\n for i in range(n):\r\n a = i\r\n b = preferences[a] - 1 # Subtract 1 to match 0-based indexing\r\n c = preferences[b] - 1\r\n\r\n if preferences[c] - 1 == a:\r\n return \"YES\"\r\n\r\n return \"NO\"\r\n\r\n# Read input\r\nn = int(input())\r\npreferences = list(map(int, input().split()))\r\n\r\n# Check for love triangle and print the result\r\nresult = find_love_triangle(n, preferences)\r\nprint(result)\r\n", "from sys import stdin\r\n \r\nrd = stdin.readline\r\n\r\nn = int(rd())\r\nf = list(map(int, rd().split()))\r\n\r\nres = 0\r\n\r\nfor i in range(n):\r\n\r\n if f[f[f[i] - 1] - 1] == i + 1:\r\n\r\n print(\"YES\")\r\n break\r\n\r\nelse:\r\n print(\"NO\")\r\n", "def fn(arr,n):\n for i in range(1,n):\n if arr[arr[arr[i]]] == i:\n return True\n return False\n\n# test_cases = int(input())\n# for cases in range(test_cases):\n# arr = list(map(int, input().split()))\n# if fn(arr):\n# print(\"YES\") \n# else:\n# print(\"NO\")\nn = int(input())\narr = list(map(int, input().split()))\narr.insert(0,0)\n# arr = [0,2,4,5,1,3]\n# n = len(arr)\nif fn(arr,n+1):\n print(\"YES\")\nelse:\n print(\"NO\")", "import sys\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nfor i in range(n):\r\n a=l[i]\r\n b=l[a-1]\r\n if a==b:\r\n continue\r\n else:\r\n c=l[b-1]\r\n if i==c-1:\r\n print(\"YES\")\r\n sys.exit()\r\n else:\r\n continue\r\nelse:\r\n print(\"NO\")", "def has_love_triangle(n, likes):\r\n for i in range(n):\r\n a = i + 1 # Plane numbers are 1-indexed\r\n b = likes[i]\r\n c = likes[b - 1]\r\n\r\n if likes[c - 1] == a:\r\n return \"YES\" # Found a love triangle\r\n \r\n return \"NO\" # No love triangle found\r\n\r\n# Read input\r\nn = int(input())\r\nlikes = list(map(int, input().split()))\r\n\r\n# Check if there is a love triangle\r\nresult = has_love_triangle(n, likes)\r\nprint(result)\r\n", "n = int(input())\r\nf=input().split()\r\nfor i in range(n):\r\n f[i]=int(f[i])\r\nfor i in range(1,n+1):\r\n if(f[f[f[i-1]-1]-1]==i):\r\n print('YES')\r\n break\r\n elif(i==(n-1) and f[f[f[i-1]-1]-1]!=i):\r\n print('NO')\r\n", "n = int(input())\r\nf = [int(x) for x in input().split()]\r\n\r\ni = 0\r\nis_not_love_tri = True\r\nwhile i < n:\r\n\r\n if f[f[f[i-1]-1]-1] == i:\r\n is_not_love_tri = False\r\n i = i +1\r\n\r\nif is_not_love_tri == False:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n ", "n=int(input())\r\nL=[0]+list(map(int,input().split()))\r\n \r\nif any(L[L[L[x]]]==x for x in L[1:]) : print('YES')\r\nelse : print('NO')\r\n", "t=int(input())\r\na=[int(x) for x in input().split()]\r\na=[0]+a\r\ncheck=0\r\nfor i in range(1,len(a)):\r\n if a[a[a[i]]]==i:\r\n check=1 \r\n break \r\nif check==0:\r\n print('NO')\r\nelse: \r\n print('YES')", "import math\r\ndef I(): return int(input())\r\ndef II(): return map(int, input().split())\r\ndef IL(): return list(map(int, input().split()))\r\ndef SIL(): return sorted(map(int, input().split()))\r\nfrom collections import defaultdict\r\nfrom collections import Counter\r\n\r\ndef solve():\r\n n = I()\r\n a = IL()\r\n for index in range(n):\r\n check = a[a[index]-1]\r\n if index+1 == a[check-1]:\r\n print(\"Yes\")\r\n break\r\n else:\r\n print(\"NO\")\r\n\r\n\r\n\r\nT = 1\r\nfor ___ in range(T):\r\n solve()\r\n\r\n\r\n", "n=int(input())\r\nt=input().split(' ')\r\nres=\"NO\"\r\nfor i in t:\r\n i=int(i) \r\n if int(t[int(t[int(t[i-1])-1])-1])==int(i):\r\n res=(\"YES\")\r\n break\r\n \r\nprint(res)", "def find_love_triangle(n, planes):\r\n for i in range(n):\r\n a = i\r\n b = planes[i] - 1 # Adjust for 0-based indexing\r\n c = planes[b] - 1 # Adjust for 0-based indexing\r\n \r\n if planes[c] - 1 == a:\r\n return \"YES\"\r\n \r\n return \"NO\"\r\n\r\n# Input\r\nn = int(input())\r\nplanes = list(map(int, input().split()))\r\n\r\n# Output\r\nresult = find_love_triangle(n, planes)\r\nprint(result)\r\n", "n=int(input())\nf=list(map(int, input().split(\" \")))\nf.insert(0,0) #0 at f(0)\nfor i in range(1,n+1):\n x=f[i]\n y=f[x]\n if f[y]==i:\n print(\"yes\")\n break\nelse:\n print(\"no\")\n\t \t\t\t\t\t\t \t \t\t\t\t \t\t\t \t \t\t\t", "a = int(input())\r\nb = list(map(int,input().split()))\r\nfor i in range(a):\r\n if b[b[b[b[i]-1]-1]-1]==b[i]:\r\n print(\"YES\")\r\n break\r\n else:\r\n pass\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\ndef find(arr, curr):\r\n a = [curr]\r\n a.append(arr[a[-1] - 1])\r\n a.append(arr[a[-1] - 1])\r\n a.append(arr[a[-1] - 1])\r\n if a[0] == a[-1]:\r\n a.pop(-1)\r\n s = set(a)\r\n if len(s) == 3:\r\n return True\r\n return False\r\n\r\nans = \"NO\"\r\n\r\nfor i in arr:\r\n if find(arr, i):\r\n ans = \"YES\"\r\n break\r\nprint(ans)", "def loveTriangle():\n num_of_planes = int(input())\n array_of_planes = list(map(int, input().split(\" \")))\n love_triangle = \"NO\"\n\n # A plane can't like itself\n # The plane [i] like the plane f of i\n # If A -> B and B -> C and C -> A we have a love triangle\n\n # 2 4 5 1 3 ----> 2[i] likes 4[fi] and 4[i] likes 1[fi] finally 1[i] likes 2[fi]\n array_of_planes.insert(0, 0)\n for i in range(1, len(array_of_planes)):\n current = array_of_planes[i]\n # likes_plane = array_of_planes[current]\n\n a = i\n b = array_of_planes[a]\n c = array_of_planes[b]\n\n if (a == array_of_planes[c]):\n love_triangle = \"YES\"\n\n print(love_triangle)\n\n\nloveTriangle()\n \t \t\t\t\t \t\t \t\t\t\t\t \t \t \t", "n = int(input())\r\nf = list(map(int, input().split()))\r\nlover = {}\r\nfor i in range(n):\r\n lover[i + 1] = f[i]\r\nvalid = False\r\nfor i in range(n):\r\n c = i\r\n for j in range(3):\r\n c = f[c - 1]\r\n if c == i:\r\n valid = True\r\n break\r\n \r\nprint(\"YES\" if valid else \"NO\")\r\n ", "t=int(input())\r\nans=\"NO\"\r\nlst=list(map(int,input().strip().split()))\r\nfor i in range(t):\r\n a=i\r\n alikes=lst[a]-1\r\n b=alikes\r\n blikes=lst[b]-1\r\n c=blikes\r\n clikes=lst[c]-1\r\n if(a==clikes):\r\n ans='YES'\r\n break\r\nprint(ans) \r\n ", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Jul 1 10:38:44 2021\r\n\r\n@author: nagan\r\n\"\"\"\r\n\r\nn = int(input())\r\nf = input().split()\r\nf = [int(i) for i in f]\r\nans = \"NO\"\r\nfor i in range(n):\r\n ini = f[i]\r\n nex = f[ini - 1]\r\n if f[nex - 1] == i + 1:\r\n ans = \"YES\"\r\n break\r\nprint(ans)", "import math\r\n\r\n\r\ndef get():\r\n return list(map(int, input().split()))\r\n\r\n\r\ndef intput():\r\n return int(input())\r\ndef main():\r\n st=intput()\r\n arr=[0]+get()\r\n ans=\"NO\"\r\n for i in range(1,st+1):\r\n\r\n\r\n if (arr[arr[arr[i]]]==i):\r\n ans=\"YES\"\r\n break\r\n print(ans)\r\n\r\n\r\n\r\n\r\n\r\n\r\nmain()\r\n", "n = int(input())\r\ns = list(map(int, input().split()))\r\nans = \"NO\"\r\n\r\nfor i in s:\r\n if s[s[s[i - 1] - 1] - 1] == i:\r\n ans = \"YES\"\r\n\r\nprint(ans)", "n=int(input())\r\ns,bl=[int(i) for i in input().split()],False\r\nfor index,value in enumerate(s):\r\n a,b=value,s[value-1]\r\n c=s[b-1]\r\n if c-1==index:bl=True;break\r\n else:bl=False\r\nif bl:print(\"YES\")\r\nelse:print(\"NO\")", "n = int(input())\na= list(map(int, input().split()))\na.insert(0,0)\nres = 0\nfor i in range(1,n):\n if i ==a[a[a[i]]]:\n res = 1\n break\nif res == 1:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t \t \t\t \t\t\t \t\t\t\t \t \t\t\t \t\t\t", "n = int(input())\r\nx = list(map(int,input().split()))\r\nfor i in range(n):\r\n\tif i == x[x[x[i]-1]-1]-1:\r\n\t\tprint('YES')\r\n\t\tbreak\r\nelse:\r\n\tprint('NO')", "n = int(input())\r\nd = {i+1: j for i, j in enumerate(map(int, input().split()))}\r\nprint(['NO', 'YES'][any([d[d[d[i]]] == i for i in range(1, n+1)])])", "\ndef main():\n n = int(input())\n f = [0] + [int(i) for i in input().split()]\n\n yes = False\n for i in range(1, n):\n\n first = i\n second = f[i]\n third = f[f[second]]\n \n if(first == third):\n yes = True\n break\n \n if(yes):\n print(\"YES\")\n else:\n print(\"NO\")\n\n\nmain()\n \t \t \t\t\t\t\t \t\t\t\t\t \t \t \t\t", "def what_is_love(n, crushes):\r\n for i in range(1, n + 1):\r\n j = crushes[i - 1]\r\n k = crushes[j - 1]\r\n if i == crushes[k - 1]:\r\n return True\r\n return False\r\n\r\nn = int(input())\r\ncrushes = list(map(int, input().split()))\r\n\r\nif what_is_love(n, crushes):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\nf = [int(x) for x in input().split()]\nans = 0\nfor val in f:\n if val <= n and val != f.index(val) + 1:\n if f[val - 1] <= n and f[val - 1] != f.index(f[val - 1]) + 1:\n if f[f[val - 1] - 1] == f.index(val) + 1:\n ans = 1\nif ans == 1:\n print(\"YES\")\nelse:\n print(\"NO\")\n\t\t \t \t \t\t\t \t \t\t\t \t\t \t \t", "n=int(input())\r\narr=[0]+list(map(int,input().split()))\r\n\r\nfor x in arr[1:]:\r\n if arr[arr[arr[x]]]==x:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nl=list(map(int,input().split()))\r\nfor i in range(len(l)):\r\n q=l[l[i]-1]\r\n w=l[q-1]\r\n if w==i+1:\r\n print('YES')\r\n break\r\n if i==len(l)-1:\r\n print('NO')\r\n", "x= input()\r\nf1=input()\r\nf2=f1.split()\r\nf = [int(x) for x in f2 ]\r\n\r\ndef my_func(F):\r\n for i in range(len(F)):\r\n if i+1 == F[F[F[i]-1]-1]:\r\n print('YES')\r\n return\r\n print('NO')\r\n\r\n \r\nmy_func(f)", "m=int(input())\ne=list(map(int,input().split()))\nfor i in range(m):\n h=i+1\n r=e[h-1]\n p=e[r-1]\n if e[p-1]==h:\n print(\"YES\")\n exit(0)\nprint(\"NO\")\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\narr = list(map(int, input().split()))\r\n\r\nfor i in range(n):\r\n # check love triangle\r\n cur_lover_index = arr[i] - 1\r\n next_lover_index = arr[cur_lover_index] - 1 \r\n final_lover_index = arr[next_lover_index] - 1 \r\n\r\n if (cur_lover_index != next_lover_index and next_lover_index != final_lover_index and i != next_lover_index):\r\n if (final_lover_index == i):\r\n print(\"YES\")\r\n exit(0)\r\nprint(\"NO\")", "n = int(input())\narr = [int(_) for _ in input().split()]\n\nl = []\nx = []\nflag = 0\n\nfor j in range(n):\n\n l.append(arr[j])\n l.append(arr[arr[j]-1])\n l.append(arr[arr[arr[j]-1]-1])\n l.append(arr[arr[arr[arr[j] - 1] - 1]-1])\n x.append(l)\n l = []\n\nfor _ in x:\n if _[0] == _[-1] and len(set(_)) == 3:\n flag = 1\n break\n\n else:\n flag = 0\n\nif flag == 1:\n print('YES')\n\nelse:\n print('NO')\n\n\n", "from collections import deque\r\nn = int(input())\r\npare = list(map(int, input().split()))\r\ntrg = deque()\r\nslv = dict()\r\n\r\nfor i in range (1, n+1):\r\n slv[i] = pare[i-1]\r\n\r\nfor j in range (1, n+1):\r\n trg.append(slv[j])\r\n prm = trg.popleft()\r\n for y in range (2):\r\n trg.append(slv[prm])\r\n prm = trg.popleft()\r\n \r\n if prm == j:\r\n print ('YES')\r\n break\r\nelse:\r\n print ('NO')\r\n ", "n = int(input())\r\nf = [0] + list(map(int, input().split()))\r\n\r\ndef tri():\r\n for i in range(1, n+1):\r\n if f[f[f[i]]] == i:\r\n print('YES')\r\n return\r\n print('NO')\r\n return\r\n\r\ntri()", "numPlanes = input()\r\nplaneLoves = [int(plane) - 1 for plane in list(input().split())]\r\nmessage = \"NO\"\r\nfor planeLove in planeLoves:\r\n if planeLove == planeLoves[planeLoves[planeLoves[planeLove]]]:\r\n message = \"YES\"\r\nprint(message)", "\n\nn = int(input())\np = input().split()\nfor i in range(n):\n p[i] = int(p[i])\n\nfor i in range(n):\n if i == p[p[p[i-1]-1]-1]:\n print(\"YES\")\n break\n if i == n-1:\n print(\"NO\")\n\n\n", "N=int(input())\nL=list(map(int,input().split()))\nf='NO'\nfor i in range(N):\n v=L[i]-1\n v=L[v]-1\n v=L[v]-1\n if v==i:f='YES'\nprint(f)", "# No Collaboration\n\n#numOfPlanes = 5\n\n#planeList = [2, 4, 5, 1, 3]\n\nnumOfPlanes = int(input())\n\nplaneList = [int(x) for x in input().split()]\n\ni = 0\ntemp = 0\n\nwhile i < numOfPlanes:\n f = planeList[i]\n s = planeList[f-1]\n t = planeList[s-1]\n if t-1 == i:\n print(\"YES\")\n temp = 1\n break\n i += 1\n\nif temp == 0:\n print(\"NO\")\n\n\t \t \t\t \t \t\t \t\t \t\t \t \t \t\t \t\t", "a = int(input())\r\nb = list(map(int,input().split()))\r\nfor i in range(a):\r\n b[i] = b[i]-1\r\ncount = 0\r\nfor i in b:\r\n if i == b[b[b[i]]]:\r\n count += 1\r\nif count > 0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "used = set()\r\ndef dfs(u):\r\n ans = 'NO'\r\n p = [u]\r\n while len(p) > 0:\r\n v = p.pop()\r\n if v not in used:\r\n used.add(v)\r\n if G[G[G[v]]] == v:\r\n ans = 'YES'\r\n break\r\n return ans\r\n\r\nn = int(input())\r\nf = list(map(int, input().split()))\r\nG = {}\r\nfor i in range(len(f)):\r\n G[i+1] = f[i]\r\nans = 'NO'\r\nfor x in G:\r\n if dfs(x) == 'YES':\r\n ans = 'YES'\r\nprint(ans)\r\n", "n = int(input())\nsecuence = list(map(int, input().split()))\nsecuence = dict(enumerate(secuence, 1))\npairA = 1\nfind = False\nfor _ in range(n):\n pairB = secuence[pairA]\n pairC = secuence[pairB]\n if pairA != pairB != pairC:\n if pairA == secuence[pairC]:\n print('YES')\n find = True\n break\n pairA += 1\nif not find:\n print('NO')\n \t\t \t \t \t \t \t \t \t\t \t\t \t\t", "n = int(input())\r\na = [int(x) for x in input().split()]\r\nlook = True\r\nfor i in range(n):\r\n s = a[i] - 1\r\n ns = a[s] - 1\r\n if i != ns and a[ns] - 1 == i:\r\n look = False\r\n break\r\nif look:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n", "import sys\r\n\r\n# sys.stdout = open('./output.txt', 'w')\r\n# sys.stdin = open('./input.txt', 'r')\r\n\r\ninput = sys.stdin.readline\r\noutput = sys.stdout.writelines\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\nn = inp()\r\npos = inlt()\r\n\r\ndef fun():\r\n exists = 0\r\n for idx, l in enumerate(pos):\r\n\r\n n_ = l\r\n nn = pos[n_-1]\r\n nnn = pos[nn-1]\r\n\r\n if nnn == idx+1:\r\n exists = 1\r\n\r\n return exists\r\n\r\nif fun():\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "n = int(input())\r\nlove = list(map(int, input().split(\" \")))\r\nfor i in range(n):\r\n a = i\r\n b = love[a]\r\n c = love[b-1]\r\n d = love[c-1]\r\n if a==d-1:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\nf=list(map(int,input().split()))\r\nflag=0\r\nfor i in range (n):\r\n a=f[i]\r\n b=f[a-1]\r\n c=f[b-1]\r\n if(c-1==i):\r\n print(\"YES\")\r\n flag=1\r\n break\r\nif(flag==0):\r\n print(\"NO\")\r\n ", "from collections import defaultdict, deque\r\nimport sys\r\ninput = lambda : sys.stdin.readline().strip()\r\n##############################################################################\r\nn = int(input())\r\na = list(map(int,input().split()))\r\ncount = 'NO'\r\nfor i in a:\r\n if a[a[a[i-1]-1]-1] == i:\r\n count = 'YES'\r\n break\r\nprint('YES' if count == 'YES' else 'NO')\r\n", "n = int(input())\r\nf = [int(x)-1 for x in input().split()]\r\nfor i in range(n):\r\n if f[f[f[i]]] == i:\r\n print('YES')\r\n break\r\nelse:\r\n print('NO')", "n = int(input())\r\nc=1\r\nstr1 = input()\r\nlistNum = []\r\nlistNum[:0] = str1.split(\" \")\r\ndictKV = {}\r\nfor x in range(1, n+1):\r\n dictKV[x] = int(listNum[x-1])\r\n# print(dictKV)\r\nfor key, value in dictKV.items():\r\n x = dictKV[value]\r\n y = dictKV[x]\r\n if(y == key):\r\n c=2\r\n print(\"YES\")\r\n exit()\r\n \r\nif (c == 1):\r\n print(\"NO\")", "\nn = int(input())\ngrid = list(map(int, input().split()))\n\n\nlt = False\nclosed = [False] * n\nfor i in range(n):\n if closed[i] == False:\n closed[i] = True\n clist = [i]\n nxt = grid[i] - 1\n while True:\n if closed[nxt] == False:\n closed[nxt] = True\n clist.append(nxt)\n nxt = grid[nxt] - 1\n else:\n if len(clist) > 2 and clist[-3] == nxt:\n lt = True\n break\n if lt:\n break\n\nif lt:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t \t \t\t \t \t \t\t\t\t \t\t\t", "# Style Guide for Python Code\n# https://www.python.org/dev/peps/pep-0008/\n\nplanes = int(input())\n\nf = [int(x)-1 for x in input().split()]\n\nhas_triangle = False\nfor i in range(planes):\n if f[f[f[i]]] == i:\n has_triangle = True\n break\n\nif has_triangle == False:\n print(\"NO\")\nelse:\n print(\"YES\")\n\n\n", "n = int(input())\r\ngraphs = [int(i) for i in input().split()]\r\nfor i in range(n):\r\n key = graphs[i]\r\n for j in range(3):\r\n key = graphs[key-1]\r\n if key == graphs[i]:\r\n print(\"YES\")\r\n break\r\n elif i == n-1:\r\n print(\"NO\")\r\n else:\r\n continue", "n = int(input())\r\ns = input().split()\r\nd = {}\r\nfor i in range(1,n+1):\r\n d[i] = int(s[i-1])\r\nfor u in range(1, n+1):\r\n x = d[u]\r\n y = d[x]\r\n if d[y] == u:\r\n print(\"YES\")\r\n break\r\n\r\nelse:\r\n print(\"NO\")\r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nd={i: 0 for i in range(1,n+1) }\r\n\r\nfor i in range(1,n+1):\r\n d[i]=l[i-1]\r\nf=0\r\nfor i in range(1,n+1):\r\n if d[d[d[i]]]==i:\r\n print(\"YES\")\r\n f=1\r\n break\r\nif f==0:\r\n print(\"NO\")", "from collections import defaultdict\r\n\r\n\r\nn=int(input())\r\nlst=list(map(int,input().split()))\r\nd=defaultdict(int)\r\nfor i in range(len(lst)):\r\n d[i+1]=lst[i]\r\n\r\n# seen=set()\r\n# def dfs(node,seen):\r\n# if node in seen:\r\n# return True\r\n# seen.add(node)\r\n# dfs(d[node],seen)\r\n# return False\r\nfound=False\r\n# for node in d:\r\n# seen=set()\r\n# if dfs(node,seen):\r\n# found=True\r\n# break\r\nfor node in d:\r\n if d[d[d[node]]]==node:\r\n found=True\r\n break\r\n \r\nif found:\r\n print('YES')\r\nelse:\r\n print('NO') \r\n\r\n", "import sys\n\nn = int(input())\ncase_ = input().split(\" \")\nplanes = [int(i) for i in case_]\ndicc = {}\n\nfor i, f in enumerate(planes):\n dicc[i+1] = f\n # Check if all the involved numbers are in the dicc\n if (i+1) in dicc and f in dicc and dicc[f] in dicc:\n # Check for a love triangle\n novio, novia, mosa = i+1, f, dicc[f]\n if dicc[novio] == novia and dicc[novia] == mosa and dicc[mosa] == novio:\n print(\"YES\")\n sys.exit()\nprint(\"NO\")\n \t\t \t \t \t\t\t \t \t \t \t \t", "\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 = (get_list ())\r\nfor i in range (n):\r\n current = i + 1\r\n tmp = ar [current - 1]\r\n tmp1= ar [tmp - 1]\r\n if (ar [ tmp1 - 1] == current):\r\n print (\"YES\")\r\n break\r\n elif i == n-1:\r\n print (\"NO\")\r\n", "n_elementos = int(input())\nlista = list(map(int, input().split(' ')))\n#cria lista de dist com 1 posição a mais que o numero de elementos para poder manter identidade entre index e posição\nlista_pares = [ [] for x in range(n_elementos+1)]\n\ndef add_lista(v1, v2, lista):\n\tlista_pares[v1+1].append(v2)\n\ndef dfs(index):\n\tglobal lista_pares\n\treturn lista_pares[index][0]\n\ndef dfs_vetor(index, lista):\n\treturn lista[index]\n\n#monta listas de distribuição\nfor x in range (0,len(lista)):\n\tadd_lista(x,lista[x], lista_pares)\n\ncount=0\nfor x in range (1, n_elementos+1):\n\tif x == dfs(dfs(dfs(x))):\n\t\tprint('YES')\n\t\tcount+=1\n\t\tbreak\nif count==0:\n\tprint('NO')", "\r\nn=int(input())\r\nf=[0]\r\nf=f+list(map(int,input().split()))\r\na=0\r\nfor i in range(1,n+1):\r\n\tif f[f[f[i]]]==i:\r\n\t\ta=1\r\n\t\tbreak\r\nif a==1:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "n=int(input())\r\nf=[int(i) for i in input().split()]\r\nd={}\r\nfor j in range(n):\r\n d[j+1]=f[j]\r\nflag=0\r\nfor k in range(n):\r\n n1=f[k]\r\n n2=d[n1]\r\n l1=[k+1,n1,n2]\r\n if len(set(l1))==3:\r\n if d[n2]==k+1:\r\n flag=1\r\n print(\"YES\")\r\n break\r\nif flag==0:\r\n print(\"NO\")", "n = int(input())\r\nplanes = list(map(int, input().split()))\r\nlike = {}\r\nfor i in range(1, n+1):\r\n like[i] = planes[i-1]\r\nfound = False\r\nfor i in range(1, n+1):\r\n if like[like[like[i]]] == i:\r\n found = True\r\nif found:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\na=list(map(int,input().split()))\r\nfor i in range(n):\r\n a[i]-=1\r\nfl=0\r\n#print(a)\r\nfor i in range(n):\r\n j=a[a[i]]\r\n k=0\r\n #print(j)\r\n while j!=a[i] and k<n:\r\n j1=a[j]\r\n j=j1\r\n k+=1\r\n #print(k)\r\n if k==2:\r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\")", "n=int(input())\r\nlst=list(map(int,input().split()))\r\nfor i in range(n):\r\n flag=0\r\n a=lst[i]\r\n b=lst[a-1]\r\n c=lst[b-1]\r\n d=lst[c-1]\r\n if a==d:\r\n flag=1\r\n break\r\nif(flag):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "no_of_planes = int(input())\r\nwho_loves_who = list(map(int, input().split()))\r\n\r\ndef has_love_triangle():\r\n for i in range(no_of_planes):\r\n b = who_loves_who[i - 1]\r\n c = who_loves_who[b - 1]\r\n if who_loves_who[c - 1] == i:\r\n return True\r\n return False\r\n\r\nif has_love_triangle():\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n:int = int(input())\r\nlike:list[int] = list(map(int, input().split()))\r\ncheck = False\r\nfor i in range(n):\r\n if like[like[like[i] - 1] - 1] - 1 == i:\r\n check = True\r\n break\r\nif check:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\n\r\n\r\nf = list(map(int,input().split()))\r\n\r\n#\r\n# /\\\r\n# / \\\r\n#/____\\\r\ngg=False;\r\n\r\nfor i in range(len(f)):\r\n\tj = f[i]-1;\r\n\tif i== (f[ f[j]-1 ]-1) and not(i+1==f[j] or f[j] == f[f[j]-1]):\r\n\t\t#print(i)\r\n\t\tgg=True;break;\r\n\r\nif gg is True:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\r\n\r\n\r\n\t", "class Solution:\r\n def loveTriangle(self, array, n):\r\n # TODO write an algorithm here\r\n \"\"\"\r\n Time complexity: O(n)\r\n space complexity: O(1)\r\n \"\"\"\r\n graph = {}\r\n for i in range(n):\r\n graph[i+1] = array[i]\r\n \r\n for key in graph:\r\n start = key\r\n temp = []\r\n temp.append(start)\r\n for i in range(3):\r\n temp.append(graph[start])\r\n start = graph[start]\r\n if temp[-1] == temp[0]:\r\n return \"YES\"\r\n return \"NO\"\r\n \r\n \r\nif __name__ == \"__main__\":\r\n solution = Solution()\r\n n = int(input())\r\n array = list(map(int, input().split()))\r\n \r\n print(solution.loveTriangle(array, n))", "n=int(input())\r\na=list(map(int,input().split()))\r\nindex=[]\r\nfor i in a:\r\n check_with=a.index(i)+1\r\n temp=a[i-1]\r\n check_for=a[temp-1]\r\n if check_for==check_with:\r\n print(\"YES\")\r\n break\r\n else:\r\n continue\r\nelse:\r\n print(\"NO\")", "\"\"\"\r\ngraph = 2,4,5,1,3\r\nВ первом примере самолету 2 нравится самолет 4,\r\nсамолету 4 нравится самолет 1, а самолету 1 нравится самолет 2, поэтому это любовный треугольник.\r\n\r\ngraph[2-1] = 4\r\ngraph[4-1] = 1\r\ngraph[1-1] = 2\r\n\r\ni = 2\r\ngraph[i-1] = 4\r\ngraph[4-1] = 1\r\ngraph[1-1] = i\r\n\r\ni = 2\r\ngraph[i-1] = 4\r\ngraph[graph[i-1]-1] = 1\r\ngraph[graph[graph[i-1]-1]-1] = i - если такое усл вып, то YES\r\n \r\n\"\"\"\r\n\r\nn = int(input())\r\nv = [int (x) for x in input().split()]\r\n\r\ncounter = 0\r\nans = 0\r\nwhile counter < n:\r\n if v[v[v[counter - 1] -1] -1] == counter:\r\n ans = 1\r\n break\r\n counter += 1\r\n\r\nif ans:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") ", "n=int(input())\r\na=list(map(int,input().split()))\r\nfor i in range(len(a)):\r\n\tf1=a[i]\r\n\tf2=a[f1-1]\r\n\tf3=a[f2-1]\r\n\tif f3-1==i:\r\n\t\tprint(\"YES\")\r\n\t\tbreak\r\nelse:\r\n\tprint(\"NO\")", "n = int(input())\r\nff = list(map(int, input().split()))\r\nflag = 1\r\nfor i in range(n):\r\n tri = []\r\n k = ff[i]\r\n while k not in tri or len(tri) < 3:\r\n tri.append(k)\r\n k = ff[k - 1]\r\n if len(tri) < 3:\r\n continue\r\n if ff[tri[2] - 1] == ff[i]:\r\n print(\"YES\")\r\n flag = 0\r\n break\r\n\r\nif flag:\r\n print(\"NO\") \r\n\r\n", "def main():\r\n n = int(input())\r\n a = input().split(\" \")\r\n a = [int(x) for x in a]\r\n\r\n for i in range(n):\r\n if i == a[a[a[i] - 1] - 1] - 1:\r\n print(\"YES\")\r\n return\r\n print(\"NO\")\r\n\r\nmain()", "n = int(input())\r\nlst = list(map(int, input().split()))\r\n\r\nfor x in range(n):\r\n if x == lst[lst[lst[x]-1]-1]-1:\r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\")\r\n\r\n\r\n", "#\n# Joseph Matsushita\n# Problem C\n#\n\nn = int(input())\n\nlikes = list(map(int, input().split()))\n\ntriangle = False\nfor i in range(n):\n if likes[likes[likes[i]-1]-1]-1 == i:\n triangle = True\n break\n\nif triangle:\n print(\"YES\")\nelse:\n print(\"NO\")\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\nans=\"NO\"\r\nfor i in l:\r\n print\r\n if l[l[l[i-1]-1]-1]==i:\r\n ans=\"YES\"\r\n else:\r\n None\r\nprint(ans)", "def find(x,b,times = 1):\r\n global founded\r\n if ds[x] == b and times==3:\r\n return True\r\n if x in founded or times>3: return False\r\n founded.append(x)\r\n return find(ds[x],b,times+1)\r\n\r\n\r\nn = int(input())\r\nds = [0]\r\nlove = list(map(int,input().split()))\r\nfor i in love:\r\n ds.append(i)\r\n\r\nfor i in range(1,n+1):\r\n founded = []\r\n answer = False\r\n if find(i,i):\r\n answer = True\r\n break\r\n \r\nif answer: print('YES')\r\nelse: print('NO')\r\n\r\n\r\n", "from sys import stdin\r\n\r\nn = int(stdin.readline())\r\na = list(map(int, stdin.readline().split()))\r\nres = 'NO'\r\nfor idx, val in enumerate(a):\r\n if a[a[val-1]-1] == idx+1:\r\n res = 'YES'\r\n break\r\n\r\nprint(res)\r\n", "n = int(input())\nf = list(map(int, input().split()))\n\ncan = False\nfor i in range(n):\n a = i+1\n b = f[i]\n c = f[b-1]\n if (a == f[c-1]):\n can = True\n break\n\nif (can):\n print(\"YES\")\nelse:\n print(\"NO\")", "a = int(input())\r\nx = input()\r\nx = x.split(\" \")\r\nx = list(map(int, x))\r\n\r\ndic = {}\r\noutput = 'NO'\r\nfor i in x:\r\n if(i not in dic.keys()):\r\n dic[i] = x[i - 1]\r\n\r\nfor i in dic.keys():\r\n if(dic[dic[dic[i]]] == i):\r\n output = 'YES'\r\n break\r\nprint(output)", "def love(f,g):\r\n if g==3:\r\n return(f)\r\n else:\r\n return(love(a[f],g+1))\r\nn=int(input())\r\nt=0\r\na=[0,*map(int,input().split())]\r\nfor i in range(1,n):\r\n if love(i,0)==i:\r\n t=1\r\nif t==1:\r\n print(\"YES\")\r\nelse: print(\"NO\")", "n = int(input())\nloves = [-1 for _ in range(n)]\nloved_by = [[] for _ in range(n)]\nadj_list = [int(i) for i in input().split()]\n\nfor idx, i in enumerate(adj_list):\n loves[idx] = i - 1\n loved_by[i - 1].append(idx)\n\nans = 'NO'\nfor idx, loved_one in enumerate(loves):\n for lover in loved_by[idx]:\n if loves[loved_one] == lover:\n ans = 'YES'\n break\n if ans == 'YES':\n break\n\nprint(ans)\n\n\n", "n = int(input())\r\nf = list(map(int, input().split()))\r\nhere = 'NO'\r\nfor i in range(n):\r\n if f[f[f[i]-1]-1]-1 == i:\r\n here = 'YES'\r\n break\r\nprint(here)\r\n", "n1 = int(input())\r\nx = input().split()\r\nlist1 = []\r\nfor i in x:\r\n list1.append(int(i))\r\n\r\nk1 = 0 \r\nb1 = False\r\nwhile b1==False:\r\n starti = k1+1\r\n first_likes_this = list1[k1]\r\n second_likes_this = list1[first_likes_this-1]\r\n third_likes_this = list1[second_likes_this-1]\r\n if third_likes_this == starti:\r\n print(\"YES\")\r\n break\r\n else:\r\n k1+=1\r\n if k1==len(list1):\r\n print(\"NO\")\r\n break\r\n ", "import sys\r\nn = int(sys.stdin.readline())\r\n\r\nA = list(map(int, sys.stdin.readline().split()))\r\na = 0\r\n\r\nfor i in range(n):\r\n if A[A[A[i]-1]-1] == i + 1:\r\n a = 1\r\n\r\nif a == 0:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "class Solution:\r\n\tdef __init__(self):\r\n\t\tpass\r\n\r\n\t@staticmethod\r\n\tdef decrease(x):\r\n\t\treturn x - 1\r\n\r\n\tdef solve(self):\r\n\t\tn = int(input())\r\n\t\tplanes = list(map(int, input().split()))\r\n\t\tplanes = list(map(self.decrease, planes))\r\n\t\tvisited = [False for i in range(n)]\r\n\t\ti = 0\r\n\t\tresult = False\r\n\r\n\t\twhile i <= n - 1:\r\n\t\t\tif not visited[i]:\r\n\t\t\t\tvisited[i] = True\r\n\t\t\t\tif planes[planes[planes[i]]] == i:\r\n\t\t\t\t\tresult = True\r\n\t\t\t\t\tbreak\r\n\t\t\t\telse:\r\n\t\t\t\t\tvisited[planes[i]] = True\r\n\t\t\t\t\tvisited[planes[planes[i]]] = True\r\n\r\n\t\t\ti += 1\r\n\r\n\t\tif result:\r\n\t\t\tprint(\"YES\")\r\n\t\telse:\r\n\t\t\tprint(\"NO\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tsol = Solution()\r\n\tsol.solve()\r\n", "n = int(input())\r\nlove_list = list(map(int, input().split()))\r\n\r\n\r\nfor i in range(1, n + 1):\r\n seen = [love_list[i - 1]]\r\n indexes = [i]\r\n for _ in range(2):\r\n indexes.append(seen[-1])\r\n seen.append(love_list[seen[-1] - 1])\r\n\r\n if [seen[2], seen[0], seen[1]] == indexes:\r\n print(\"YES\")\r\n break\r\n\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\nl = list(map(int,input().split()))\r\nl = l[:n]\r\nc = 0\r\nfor i in range(0,n):\r\n if l[(l[(l[i]-1)]-1)] == i+1 :\r\n c = c + 1\r\nif c :\r\n print(\"yes\")\r\nelse:\r\n print(\"No\")", "def has_love_triangle(n, likes):\r\n for i in range(1, n + 1):\r\n j = likes[i - 1]\r\n k = likes[j - 1]\r\n if i == likes[k - 1]:\r\n return True\r\n return False\r\n\r\n# Read input\r\nn = int(input())\r\nlikes = list(map(int, input().split()))\r\n\r\n# Check if there is a love triangle\r\nif has_love_triangle(n, likes):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\na = list(map(int,input().split()))\r\nfor i in range(n):\r\n s = [i]\r\n for j in range(3):\r\n i = a[i] - 1\r\n s.append(i)\r\n if s[0] == s[3]:\r\n print('yes')\r\n break\r\nelse:\r\n print('no')\r\n", "n = int(input())\r\nm = list(map(int, input().split()))\r\n\r\ndef isLoveTriangle():\r\n for i in range(len(m)):\r\n loved1 = m[i]\r\n loved2 = m[loved1 - 1]\r\n loved3 = m[loved2 - 1]\r\n\r\n if loved3 - 1 == i:\r\n return \"YES\"\r\n\r\n return \"NO\"\r\n\r\nprint(isLoveTriangle())", "n, s = int(input()), 'NO'\r\nf = list(map(int, input().split(' ')))\r\nfor i in range(1, n):\r\n if i == f[f[f[i] - 1] - 1] - 1:\r\n s = 'YES'\r\nprint(s)", "def hasTriangle(graph):\n has_triangle = False\n for i in graph:\n a = graph[i]\n b = graph.get(a, -1)\n c = graph.get(b, -1)\n if c == i:\n has_triangle = True\n break\n\n return has_triangle\n\ndef createGraph(arr):\n graph = {}\n for i in arr:\n graph[i] = arr[i - 1]\n return graph\n\nif __name__ == '__main__':\n n = int(input())\n arr = [int(i) for i in input().split(' ')]\n graph = createGraph(arr)\n if hasTriangle(graph):\n print('YES')\n else:\n print('NO')\n", "n= int(input())\nconexion=[int(x)-1 for x in input().split()]\n\nfor i in range(n):\n x=i\n y=conexion[x]\n z=conexion[y]\n if conexion[z]==x:\n print('YES')\n exit()\nprint('NO')\n\t \t \t \t\t\t \t", "n=int(input())\r\nf=list(map(int,input().split()))\r\ncount=0\r\nfor x in f:\r\n count+=1\r\n y=f.index(x)\r\n y+=1\r\n z=f[x-1]\r\n w=f[z-1]\r\n love_tri={y:x,x:z,z:w} \r\n if(w==y and x!=y and y!=z and z!=x ):\r\n print(\"YES\")\r\n break\r\nif(count==n):\r\n print(\"NO\") ", "plane = int(input())\nf = list(map(int, input().split()))\nfor p in range(plane):\n if p == f[f[f[p]-1]-1]-1:\n print('YES')\n exit()\nprint('NO')", "\r\n## GACP IN LAB ASS 1 \r\n\r\n## LOVE TRIANGLE 939A codeforces\r\n# 13 Sep \r\n \r\nn = int(input())\r\na = [0] + list(map(int, input().split()))\r\n\r\nflag = 0\r\nfor i in range(1, n + 1):\r\n if a[a[a[i]]] == i:\r\n flag = 1\r\n break\r\n\r\nif flag == 1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n", "n=int(input(''))\r\nc=0\r\nl=list(map(int,input().split()))\r\nfor i in range(len(l)):\r\n if l[l[l[i]-1]-1]==i+1:\r\n c+=1\r\nif c>0:\r\n print('YES')\r\nelse:\r\n print(\"NO\")", "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\n'''\r\n\r\nfound = False\r\nfor i in range(n):\r\n cur = i\r\n for j in range(3):\r\n cur = a[cur]\r\n if j == 2 and cur == i:\r\n found=True\r\n break\r\n if found:\r\n break\r\n\r\n'''\r\nmod = 10**9+7\r\nn=II()\r\nfound = False\r\na=LII()\r\nfor i in range(n):\r\n if a[a[a[a[i]-1]-1]-1] == a[i]:\r\n found=True\r\n break\r\nprint(\"YES\" if found else \"NO\")", "n = int(input())\n\narr = [0] + list(map(int, input().split()))\n\ndef love_triangle():\n for i in range(1, n):\n if arr[arr[arr[i]]] == i:\n return 1\n\n\nif love_triangle() == 1:\n print(\"YES\")\n\nelse:\n print(\"NO\")\n\t\t\t \t\t\t \t\t \t \t\t \t \t \t \t\t \t", "def process(A):\r\n n = len(A)\r\n for i in range(n):\r\n a = i+1\r\n b = A[i]\r\n c = A[b-1]\r\n a2 = A[c-1]\r\n if a==a2:\r\n return 'YES'\r\n return 'NO'\r\n \r\n\r\nn = int(input())\r\nA = [int(x) for x in input().split()]\r\nprint(process(A))", "# Rishabh Rao (https://github.com/rishabhrao)\r\n\r\nimport sys\r\nMOD = 1000000007\r\ndef inp(): return sys.stdin.readline().strip()\r\ndef ii(): return int(inp())\r\ndef iis(): return [int(i) for i in inp().split()]\r\n\r\n\r\ndef solve():\r\n n = ii()\r\n graph = {i + 1: el for i, el in enumerate(iis())}\r\n for k, v in graph.items():\r\n if graph[v] != k and graph[graph[v]] == k:\r\n return True\r\n return False\r\n\r\n\r\nprint(\"YES\" if solve() else \"NO\")\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\nans = \"NO\"\r\nfor i in range(n):\r\n if i + 1 == a[a[a[i]-1]-1]:\r\n ans = \"YES\"\r\n break\r\nprint(ans)", "#----------------------------\n# Matheus de Souza Oliveira |\n# RA: 203407 |\n#----------------------------\n\nn = int(input())\nlikes = list(map(int, input().split()))\nisLoveTriangle = False\n\nfor index in range(n):\n b = likes[index] - 1\n c = likes[b] - 1\n\n if index == likes[c] - 1:\n isLoveTriangle = True\n break\n \nif isLoveTriangle:\n print(\"YES\")\n\nelse: \n print(\"NO\")\n\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\nlst.insert(0,0)\r\ncnt=0\r\nfor i in range(1,n+1):\r\n if lst[lst[lst[i]]]==i:\r\n cnt+=1\r\nif cnt:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "m = int(input())\nn = input().split(\" \")\ndic = {}\nflag = 0\nfor i in range(m):\n dic[i + 1] = int(n[i])\nfor i in range(1, m + 1):\n if dic[dic[dic[i]]] == i:\n flag = 1\n break\nif flag == 1:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t\t \t \t\t \t\t\t\t\t\t \t \t\t \t\t\t\t\t", "def main():\r\n list = []\r\n num_planes = int(input())\r\n planes = input().split()\r\n for i in range(num_planes):\r\n list.append(int(planes[i]))\r\n\r\n found_tri = False\r\n for i in range(num_planes):\r\n if found_tri == False:\r\n start_plane = list[i] - 1\r\n if list[list[(list[start_plane]) - 1] - 1]-1 == start_plane:\r\n print(\"YES\")\r\n found_tri = True\r\n\r\n if found_tri == False:\r\n print(\"NO\")\r\n\r\n\r\nif __name__ == '__main__':\r\n main()", "n=int(input())\r\nplane={}\r\nx=list(map(int,input().split()))\r\n\r\nfor i in range(n):\r\n x[i]=x[i]-1\r\nflag=0\r\nfor i in range(n):\r\n if x[x[x[i]]]==i:\r\n print(\"YES\")\r\n flag=1\r\n break\r\n\r\nif flag==0:\r\n print(\"NO\")", "def love_triangle():\r\n a=int(input())\r\n b=list(map(int,input().split()))\r\n for i in range(len(b)-1):\r\n x=b[i]\r\n y=b[x-1]\r\n z=b[y-1]\r\n if b[z-1]==x:\r\n print('YES')\r\n break\r\n else:print('NO')\r\nlove_triangle()", "r,n,f=['NO'],int(input()),[0]+[int(i)for i in input().split()]\r\nr+=['YES'for i in range(1,n + 1)if f[f[f[i]]]==i]\r\nprint(r[-1])", "n = int(input())\n\nnums = [0]\n\nnums_input = [int(x) for x in input().split()]\nfor i in nums_input:\n nums.append(i)\n\n\nstate = False\n\nfor i in range(1,n+1):\n if nums[nums[nums[i]]] == i:\n state = True\n\nif state:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t\t \t \t \t\t \t \t\t \t \t\t \t", "x = int(input())\ni = input().split()\ni = [int(i) for i in i]\n\nfor a in range(x):\n t = i[a]\n y = i[t - 1]\n u = i[y - 1]\n o = i[u - 1]\n if t == o:\n print(\"YES\")\n exit()\nprint(\"NO\")\n\n\t \t\t\t\t\t \t\t\t \t \t \t\t\t\t\t\t", "def love_triangle():\n triangle = False\n person_num = 0\n for i in given_people:\n third_wheel = int(given_people[int(i)])\n if person_num == int(given_people[third_wheel]):\n triangle = True\n person_num += 1\n if triangle:\n print(\"YES\")\n else:\n print(\"NO\")\n\n\n# Number of people\npeople_num = int(input())\ngiven_people = input().split()\n\nfor j in range(people_num):\n given_people[j] = int(given_people[j]) - 1\n\nlove_triangle()\n \t \t \t\t\t\t\t \t\t \t \t \t \t", "n = int(input())\r\nf = list(map(int, input().split()))\r\nlove = False\r\nfor el in f:\r\n a = f[el - 1]\r\n b = f[a - 1]\r\n c = f[b - 1]\r\n if c == el:\r\n love = True\r\n break\r\nif love:\r\n print('YES')\r\nelse:\r\n print('NO')", "n = int(input())\r\n\r\nanswer = False\r\nf = [int(_) for _ in input().split()]\r\nfor i in range(1, n + 1):\r\n k = i\r\n for j in range(3):\r\n k = f[k-1]\r\n if k == i:\r\n answer = True\r\n break\r\nprint(\"YES\" if answer else \"NO\")\r\n", "def main():\r\n n = int(input())\r\n graph = {}\r\n nodes = list(map(int, input().split()))\r\n # for i, node in enumerate(nodes):\r\n # graph[i+1] = node\r\n solve(nodes)\r\n\r\n\r\ndef solve(nodes):\r\n for i in range(len(nodes)):\r\n a = i\r\n b = nodes[a] - 1\r\n c = nodes[b] - 1\r\n d = nodes[c]\r\n\r\n if d == a+1:\r\n print(\"YES\")\r\n return\r\n print(\"NO\")\r\n\r\nmain()", "n = int(input())\r\nf_arr = list(map(int, input().split()))\r\nf_arr.insert(0, 0)\r\nyes = False\r\nfor i in range(1, n + 1):\r\n if f_arr[f_arr[f_arr[i]]] == i:\r\n print(\"YES\")\r\n yes = True\r\n break\r\n\r\nif not yes:\r\n print('NO')\r\n", "import sys\n\n#input functions\nreadint = lambda: int(sys.stdin.readline())\nreadints = lambda: map(int,sys.stdin.readline().split())\nreadar = lambda: list(map(int,sys.stdin.readline().split()))\nflush = lambda: sys.stdout.flush()\n\nn = readint()\nar = readar()\nans = \"NO\"\nfor i in range(n):\n a = ar[i]\n b = ar[ar[i]-1]\n c = ar[ar[ar[i]-1]-1]\n if ar[c-1] == a and ar[a-1] == b and ar[b-1] == c:\n ans = \"YES\"\n break\nprint(ans)\n\n \t \t \t \t\t \t\t \t \t\t \t \t", "n = int(input())\r\nA = list([int(x) for x in input().split()])\r\ni = 0\r\nwhile i < len(A):\r\n num1 = A[i]\r\n num2 = A[num1 - 1]\r\n num3 = A[num2 - 1]\r\n if A[num3 - 1] == num1:\r\n print('Yes')\r\n exit()\r\n i += 1\r\nelse:\r\n print('No')", "#Problema E\n\nn = int(input())\nv=input()\nv=v.split()\nfor i in range (len(v)):\n v[i] = int(v[i])\nverdadeiro = 0\nfor i in range (len(v)):\n b = v[i]\n c = v[b-1]\n a = v[c-1]\n #print(b,c,a)\n if (a == i+1):\n verdadeiro = 1\nif (verdadeiro ==1):\n print(\"YES\")\nelse:\n print(\"NO\")\n\t \t \t\t \t \t\t \t\t \t \t\t \t\t \t\t", "\r\ndef main():\r\n\tn = int(input())\r\n\ta = [int(x) - 1 for x in input().split()]\r\n\tfor i in range(n):\r\n\t\tif a[a[a[i]]] == i:\r\n\t\t\tprint(\"YES\")\r\n\t\t\treturn\r\n\tprint(\"NO\")\r\n\r\nif __name__ == '__main__':\r\n\tmain()", "l = int(input())\r\nl = [int(i)-1 for i in input().split()]\r\nfor i in l:\r\n if l[l[l[i]]] == i:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")", "from collections import defaultdict\r\n\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nd = defaultdict(int)\r\nfor i in range(n):\r\n d[i+1] = a[i]\r\n# print(d)\r\nfor i in range(n):\r\n if d[d[d[i+1]]] == i+1:\r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\")", "n=int(input())\r\ntab=input().split()\r\nfor i in range(n):\r\n tab[i]=int(tab[i])\r\nfor i in tab:\r\n if tab[tab[tab[i-1]-1]-1]==i:\r\n print(\"YES\")\r\n exit(0)\r\nprint(\"NO\")", "from sys import stdin as sin, stdout as sout\r\n\r\n\r\ndef get_ints():\r\n return list(map(int, sin.readline().strip().split()))\r\n\r\n\r\ndef get_int():\r\n return int(sin.readline().strip())\r\n\r\n\r\ndef get_string():\r\n return sin.readline().strip()\r\n\r\n\r\ndef get_float():\r\n return float(sin.readline().strip)\r\n\r\n\r\ndef get_floats():\r\n return list(map(float, sin.readline().strip().split()))\r\n\r\n\r\ndef main():\r\n n = get_int()\r\n lst = get_ints()\r\n for i in range(n):\r\n a = i + 1\r\n for _ in range(3):\r\n a = lst[a-1]\r\n if a == i + 1:\r\n print('YES')\r\n return\r\n print('NO')\r\n\r\n\r\n\r\ndef solve():\r\n pass\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n = int(input())\narr = list(map(int, input().split()))\n\ni = 0\nwhile i < n:\n if arr[arr[arr[i - 1] - 1] - 1] == i:\n print('YES')\n exit(0)\n i += 1\nprint('NO')\n\t \t \t\t \t \t \t\t\t \t\t\t \t", "class Solution:\r\n def love_triangle(self, n, planes):\r\n planes = [p - 1 for p in planes]\r\n for i in range(n):\r\n # i likes planes[i]\r\n first_plane = i\r\n second_plane = planes[first_plane]\r\n third_plane = planes[second_plane]\r\n last_plane = planes[third_plane]\r\n if first_plane == last_plane:\r\n return \"YES\"\r\n return \"NO\"\r\n\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n planes = list(map(int, input().split()))\r\n ob = Solution()\r\n print(ob.love_triangle(n, planes))", "def solve():\r\n n = int(input())\r\n a = list(map(int,input().split()))\r\n for i in range(n):\r\n x = a[i]\r\n y = a[x-1]\r\n z = a[y-1]\r\n if len(set([x,y,z])) == 3 and a[z - 1] == x:\r\n return 'YES'\r\n return 'NO'\r\nprint(solve())", "n = int(input())\na = [0] + list(map(int, input().split()))\nfor i in range(1, n + 1):\n if a[a[a[i]]] == i:\n print(\"YES\")\n exit()\nprint(\"NO\")\n#a[1] = 2\n#a[2] = 4\n#a[4] = 1\n", "from sys import stdin, stdout\r\n\r\n\r\ndef dfs(v, mas, path):\r\n if len(path) == 3:\r\n return True\r\n if path[-1] != mas[v]:\r\n dfs(mas[v], mas, path+[mas[v]])\r\n return False\r\n\r\n\r\ndef solve():\r\n n = int(stdin.readline())\r\n mas = [int(s)-1 for s in stdin.readline().split()]\r\n for i in range(n):\r\n if mas[mas[mas[i]]] == i:\r\n print('YES')\r\n break\r\n else:\r\n print('NO')\r\n\r\n\r\nif __name__ == '__main__':\r\n solve()\r\n", "n = int(input())\narr = list(map(int, input().split()))\nr = \"NO\"\nfor i in range (len(arr)):\n if arr[arr[arr[i]-1]-1] == i+1:\n r = \"YES\"\n break\nprint(r)\n\n\t\t\t\t \t \t\t\t \t\t \t \t\t\t\t \t \t\t", "def poisk(ver, k):\r\n global res\r\n if k == 3:\r\n if chel == ver:\r\n res = 'YES'\r\n return\r\n poisk(D[ver], k + 1)\r\n\r\nn = int(input())\r\nf = [int(i) for i in input().split()]\r\nD = {}\r\nfor i in range(1, n + 1):\r\n D[i] = f[i - 1]\r\nres = 'NO'\r\nfor chel in D.keys():\r\n poisk(chel, 0)\r\nprint(res)", "n = int(input())\r\narr = [0]\r\n\r\na = [int(x) for x in input().split()]\r\n\r\narr += a\r\ndone = 0\r\nfor i in range(1, n + 1):\r\n if arr[arr[arr[i]]] == i:\r\n print(\"YES\")\r\n done = 1\r\n break\r\nif not done:\r\n print(\"NO\")\r\n \r\n", "x=int(input())\r\ny=list(map(int,input().split()))\r\nc=0\r\nfor i in range(x):\r\n if i==(y[y[y[i]-1]-1]-1):\r\n print(\"YES\")\r\n c=1\r\n break\r\nif c==0:\r\n print(\"NO\")", "x = int(input())\r\narr = [*map(int, input().split())]\r\nnew = [i-1 for i in arr]\r\nfor i in range(x):\r\n if new[new[new[i]]] == i:\r\n print(\"YES\")\r\n exit(0)\r\nprint(\"NO\")", "n=int(input())\r\nif n>=2 and n<=5000:\r\n\tA=list(map(int,input().split()))\r\n\tls=[]\r\n\ti=1\r\n\tcnt=1\r\n\tls.append(1)\r\n\tfor i in range(n):\r\n\t\tif A[A[A[i]-1]-1]-1==i:\r\n\t\t\tprint(\"YES\")\r\n\t\t\tcnt=0\r\n\t\t\tbreak\r\n\tif cnt:\r\n\t\tprint(\"NO\")\r\n\t\t\t", "n = int(input())\r\nl = [int(x) for x in input().split(' ')]\r\nswitch = 0\r\n\r\n\r\nfor i in range (len(l)):\r\n p1 = i+1\r\n p2 = l[i]\r\n p3 = l[l[i]-1]\r\n p4 = l[p3-1]\r\n if p4 == p1:\r\n switch = 1\r\n\r\nif switch == 1:\r\n print (\"YES\")\r\nelse:\r\n print (\"NO\")", "import math\r\n\r\ndef list_str(l, char):\r\n output_str = \"\"\r\n for i in range(len(l) - 1):\r\n output_str += str(l[i]) + char\r\n output_str += str(l[len(l) - 1])\r\n return output_str\r\n\r\n\r\ndef str_list(s, char):\r\n output_list = []\r\n intermediate = \"\"\r\n for i in range(len(s)):\r\n if s[i] != char:\r\n intermediate += s[i]\r\n if i == len(s) - 1:\r\n output_list.append(int(intermediate))\r\n else:\r\n if intermediate:\r\n output_list.append(int(intermediate))\r\n intermediate = \"\"\r\n return output_list\r\n\r\n\r\ndef merge_sort(l):\r\n def merge(l1, l2):\r\n i, j = 0, 0\r\n output_list = []\r\n while i < len(l1) and j < len(l2):\r\n if l1[i] > l2[j]:\r\n output_list.append(l1[i])\r\n i += 1\r\n else:\r\n output_list.append(l2[j])\r\n j += 1\r\n if i == len(l1):\r\n output_list += l2[j:]\r\n elif j == len(l2):\r\n output_list += l1[i:]\r\n return output_list\r\n\r\n def sort(l):\r\n if len(l) < 2:\r\n return l\r\n else:\r\n mid = len(l) // 2\r\n left = sort(l[:mid])\r\n right = sort(l[mid:])\r\n return merge(left, right)\r\n return sort(l)\r\n\r\n\r\n\r\ndef quicksort(l):\r\n def partition(l, start, end):\r\n i = start\r\n ind_pivot = end\r\n for j in range(start, end):\r\n if l[j] >= l[ind_pivot]:\r\n l[j], l[i] = l[i], l[j]\r\n i += 1\r\n l[ind_pivot], l[i] = l[i], l[ind_pivot]\r\n return i\r\n\r\n\r\n def quick_sort(l, start, end):\r\n if len(l) < 2:\r\n return l\r\n elif start < end:\r\n p = partition(l, start, end)\r\n quick_sort(l, start, p - 1)\r\n quick_sort(l, p + 1, end)\r\n quick_sort(l, 0, len(l) - 1)\r\n return l\r\n\r\n# k = [ 2,4,3,2,1,2,3,4,5,6,5,4,3,2]\r\n# quicksort(k)\r\n# print(k)\r\n\r\n\r\ndef collector_recursive(l):\r\n output_list = []\r\n def colec(l, start, end, cl):\r\n if start > end:\r\n return cl\r\n else:\r\n cl.append(f\"{l[start][1]} {l[end][1]}\")\r\n return colec(l, start + 1, end - 1, cl)\r\n return colec(l, 0, len(l) - 1, output_list)\r\n\r\n\r\n\r\n\r\n\r\n\r\ndef main_function():\r\n output_list = []\r\n #test_cases = range(int(input()))\r\n #for test_case in test_cases:\r\n n = input()\r\n l = str_list(input(), \" \")\r\n for i in range(len(l)):\r\n x = i + 1\r\n if l[l[l[i]-1]-1]-1 == i:\r\n return \"YES\"\r\n return \"NO\"\r\n\r\n\r\nprint(main_function())\r\n", "def love_triangle():\n n = int(input())\n f = [int(f) for f in input().split()]\n\n for i in range(n):\n if(f[f[f[i]-1]-1]-1 == i):\n return 'YES'\n return 'NO'\n \n\nprint(love_triangle())\n\t\t\t\t\t\t\t \t\t\t\t\t \t \t \t \t\t\t \t", "from sys import stdin\r\n\r\nfrom collections import defaultdict\r\n\r\n\r\ndef readarray(typ):\r\n return list(map(typ, stdin.readline().split()))\r\n\r\ndef solve():\r\n\r\n n = int(input())\r\n arr = readarray(int)\r\n\r\n\r\n graph = defaultdict(list)\r\n\r\n for node in range(1, n+1):\r\n graph[node].append(arr[node-1])\r\n \r\n \r\n for node in range(1, n+1):\r\n for neigh in graph[node]:\r\n for neigh2 in graph[neigh]:\r\n if node in graph[neigh2]:\r\n print('YES')\r\n return\r\n \r\n print('NO')\r\n\r\n\r\n\r\nsolve()\r\n\r\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\nans = 'NO'\r\nfor i in range(n):\r\n if arr[arr[arr[i] - 1] - 1] - 1 == i:\r\n ans = 'YES'\r\n break\r\nprint(ans)\r\n", "a=int(input())\r\nl=list(map(int,input().split()))\r\nans='NO'\r\nfor i in range(len(l)):\r\n if i+1==l[l[l[i]-1]-1]:\r\n ans='YES'\r\nprint(ans)", "\"\"\" @esllam \"\"\"\r\n\r\ndef main():\r\n n = int(fin())\r\n *f, = [0, *map(int, fin().split())]\r\n for i in range(1, n+1):\r\n if f[f[f[i]]] == i: return fout(\"YES\")\r\n fout(\"NO\")\r\n\r\n# FastIO\r\nfrom sys import stdin, stdout\r\ntry: input, output = open(\"input.in\", \"r\"), stdout\r\nexcept: input, output = stdin, stdout\r\ndef fin(): return input.readline().strip(\"\\r\\n\")\r\ndef fout(s): return output.write(str(s)+\"\\n\")\r\nif __name__ == \"__main__\":\r\n t = 1 or int(fin())\r\n for i in range(t): main()\r\n", "n = int(input())\r\na = list(map(int,input().split()))\r\nfor i in a:\r\n\tif a[a[a[i-1]-1]-1] == i:\r\n\t\tprint('YES')\r\n\t\tbreak\r\nelse:\r\n\tprint('NO')", "input()\r\na=list(map(int, input().split()))\r\nprint('YNEOS'[1-any([i==a[a[a[i]-1]-1]-1 for i in range(len(a))])::2])", "a = int(input())\n\ns = [int(x) - 1 for x in input().split()]\n\nlinks = {}\n\nfor i in range(len(s)):\n\tlinks[i] = s[i]\n\ndef check(links, i = 0):\n\tchecker = True\n\n\tfor i in range(len(links)):\n\t\tif links[links[links[i]]] == i and links[i] != i:\n\t\t\tchecker = False\n\n\tif checker == False:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\")\n\n\n\ncheck(links)\n", "n = int(input())\r\nf = [int(x) for x in input().split()]\r\na = []\r\nfor i in range(n):\r\n b = i+1\r\n c = f[i]\r\n d = f[c-1]\r\n e = f[d-1]\r\n if e == b:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")", "count = int(input())\r\nplanes = list(map(lambda x: int(x), input().split(' ')))\r\nfoundLoveTri = False\r\n\r\n\r\ndef follow(a): # 2 4 5 1 3\r\n b = planes[a - 1]\r\n c = planes[b - 1]\r\n return planes[c - 1] == a\r\n\r\n\r\nfor pl in planes:\r\n if follow(pl):\r\n foundLoveTri = True\r\n print('YES')\r\n break\r\n\r\nif not foundLoveTri:\r\n print('NO')\r\n", "n=int(input())\r\nf=list(map(int,input().split()))\r\nc=0\r\nfor i in range(n):\r\n if(f[f[f[i]-1]-1]-1==i):\r\n c=1\r\n break\r\nif(c==1):\r\n print('YES')\r\nelse:\r\n print('NO')", "from sys import stdin, stdout \r\n\r\nn = int(stdin.readline())\r\nf = list(map(int, [0]+stdin.readline().split(' ')))\r\nfor k in range(1,n+1):\r\n a = f[k]\r\n b = f[a]\r\n if f[b]==k and len(list({k,a,b}))==3:\r\n stdout.write('YES')\r\n break\r\nelse:\r\n stdout.write('NO')", "n = int(input())\r\nnums = list(map(int, input().split()))\r\n\r\ncheck = False\r\nfor i in range(n):\r\n curr = nums[i]\r\n for _ in range(3):\r\n curr = nums[curr - 1]\r\n if curr == nums[i]:\r\n print(\"YES\")\r\n break\r\nelse:\r\n\r\n print(\"NO\")", "n = int(input())\r\nf = list(map(int, input().split()))\r\n\r\na = [0]\r\n\r\nfor j in range(1, n+1):\r\n a.append(f[j-1])\r\n\r\nfl = 0\r\nfor i in range(1, n+1):\r\n if a[a[a[i]]] == i:\r\n print('YES')\r\n fl = 1\r\n break\r\n\r\nif fl == 0:\r\n print('NO')", "from sys import stdin\r\ninp = stdin.readline\r\n\r\nn = int(inp())\r\narr = [int(x) for x in inp().split()]\r\ndone = 0\r\n\r\nfor i in range(n):\r\n if arr[arr[arr[i]-1]-1] == i + 1:\r\n print(\"YES\")\r\n done = 1\r\n break\r\n\r\nif not done:\r\n print(\"NO\")\r\n", "n,f=int(input()),[0]+[int(i)for i in input().split()]\r\nprint((['NO']+['YES'for i in range(1,n+1)if f[f[f[i]]]==i])[-1])", "from sys import stdin\r\ninput = stdin.buffer.readline\r\n\r\ndef solve() :\r\n\r\n n = int(input())\r\n love = list(map(int , input().split()))\r\n\r\n for i in range(n) :\r\n iteration = 2\r\n cur = love[i] - 1\r\n\r\n while iteration > 0 and i != cur :\r\n iteration -= 1\r\n cur = love[cur] - 1\r\n\r\n if iteration == 0 and i == cur :\r\n return True\r\n\r\n return False\r\n\r\n\r\nprint('Yes' if solve() else 'no')", "n = int(input())\r\na = list(map(int, input().split()))\r\nfor i in range(n):\r\n if a[a[a[i]-1]-1] == i+1:\r\n print('Yes')\r\n break\r\nelse: print('No')", "def loveTriangle():\n n = int(input())\n f = list(map(int, input().split(' ')))\n\n for j in range(1, n):\n if(f[f[f[j-1]-1]-1] == j):\n return \"YES\"\n\n return \"NO\"\n\nif __name__ == \"__main__\":\n print(loveTriangle())\n\n\t\t \t\t\t\t \t\t\t\t \t\t\t\t \t\t \t\t \t", "#%% 939a Love triangle\r\n\r\ninput()\r\nlove = {i:x for i,x in enumerate(map(int,input().split()),1)}\r\nf = lambda v: love[v]\r\nprint('YNEOS'[True not in {f(f(f(v))) == v for v in love.values()}::2])\r\n ", "n=int(input())\nf=list(map(int,input().split(' ')))\nf.insert(0, 0)\nfound=False\nfor i in range(1, n+1):\n y=f[i]\n z=f[y]\n if f[z]==i:\n print(\"YES\")\n break\nelse:\n print(\"NO\")\n \t\t \t\t\t\t\t \t\t\t \t\t \t \t\t\t", "z = int(input())\r\nk = list(map(int,input().split()))\r\nfor i in range(z):\r\n\tif i == k[k[k[i]-1]-1]-1:\r\n\t\tprint('YES')\r\n\t\tbreak\r\nelse:\r\n\tprint('NO')", "n = int(input())\nplanes = [int(x) for x in input().split()]\nplanes.insert(0, -1)\nfor i in range(1, n+1):\n if planes[planes[planes[i]]] == i:\n print(\"YES\")\n break\nelse:\n print(\"NO\")\n\n\t \t\t\t\t \t \t \t\t \t \t\t \t\t\t \t", "n = int(input())\r\na = [0] + [int(i) for i in input().split()]\r\n\r\n\r\nfor i in range(1, n + 1):\r\n cnt = a[i]\r\n for k in range(2):\r\n cnt = a[cnt]\r\n if cnt == i:\r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\")", "n = int(input())\r\nnums = [int(i) for i in input().split()]\r\n\r\nans = False\r\nfor i in range(n):\r\n if(nums[nums[nums[i] - 1] - 1] == i + 1):\r\n ans = True\r\n break\r\n\r\nif(ans):\r\n print('YES')\r\nelse:\r\n print('NO')", "i, loves = int(input()), list(map(lambda x: int(x) - 1, input().split()))\nfor ind in range(i):\n if loves[loves[loves[ind]]] == ind:\n print(\"YES\")\n exit(0)\nprint(\"NO\")\n \t \t\t \t \t \t\t\t \t \t\t \t", "n = int(input())\r\nf = [int(x) - 1 for x in input().split()]\r\nfor i in range(n):\r\n if f[ f[ f[i] ] ] == i:\r\n print(\"YES\")\r\n exit(0)\r\n\r\nprint(\"NO\")", "n=int(input())\nf=input().split()\nprinted=False\nfor i in range(n):\n f[i]=int(f[i])-1\nfor i in range(n):\n if f[f[f[i]]]==i:\n print(\"YES\")\n printed=True\n break\nif not printed:\n print(\"NO\")\n\t \t\t\t\t\t \t \t\t \t\t\t \t\t \t \t\t", "n = eval(input())\nlist_input = list(map(lambda x:int(x),input().split()))\ndict_all = {}\nflag = False\nfor i in range(1,n+1):\n dict_all[i] = list_input[i-1] \nfor i in range(1,n+1):\n t1,t2,t3 = 0,0,0\n t1 = dict_all[i]\n t2 = dict_all[t1]\n t3 = dict_all[t2]\n if t3 == i: \n flag = True\n break\nif flag : print('YES')\nelse : print('NO')\n\t\t\t\t\t\t \t\t\t\t\t \t\t \t \t\t", "def get(f): return f(input().strip())\ndef gets(f): return [*map(f, input().split())]\n\n\nn = get(int)\nf = gets(lambda s: int(s) - 1)\nfor i in range(n):\n if f[f[f[i]]] == i:\n print('YES')\n break\nelse:\n print('NO')\n", "n = int(input())\r\nf = list(map(int,input().split()))\r\ntriangle = False \r\nfor i in range(n):\r\n if i == f[f[f[i] - 1] - 1] - 1:\r\n triangle = True \r\nif triangle:\r\n print(\"YES\")\r\nelse:\r\n print('NO')", "n = int(input())\r\nx = list(map(int,input().split()))\r\ns = set(x)\r\nfor i in range(n):\r\n if x[x[x[x[i]-1]-1]-1]==x[i]:\r\n print(\"YES\")\r\n break\r\n else:\r\n pass\r\nelse:\r\n print(\"NO\")\r\n", "#!/usr/bin/env python3\r\n\r\nimport math\r\n\r\ndef test_case(casen):\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n\r\n for i in range(n):\r\n a[i] -= 1\r\n\r\n for i in range(n):\r\n if a[a[a[i]]] == i:\r\n return \"YES\"\r\n return \"NO\"\r\n\r\ndef main():\r\n print(test_case(0))\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n = int(input())\r\nlst = list(map(int, input().split()))\r\n\r\nfor x in lst:\r\n y = lst[x-1]\r\n z = lst[y-1]\r\n t = lst[z-1]\r\n if t == x and x != z: \r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")", "n = int(input())\n\ndata = input().split(\" \")\ndata = list(map(int,data))\n\nfound = False\n\nfor i in range(n):\n if (i+1 == data[data[data[i]-1]-1]):\n found = True\n\nif (found):\n print(\"YES\")\nelse:\n print(\"NO\")\n\t\t \t\t \t\t\t \t\t\t \t \t\t\t\t", "a = int(input())\r\nb = list(map(int,input().split()))\r\ndict1 = {}\r\nfor i in range (len(b)):\r\n dict1[i+1] = b[i]\r\nout = \"NO\"\r\nfor i in range (len(b)):\r\n a = dict1[i+1]\r\n b = dict1[a]\r\n c = dict1[b]\r\n if c == i+1:\r\n out = \"YES\"\r\n break\r\nprint(out)\r\n", "\r\nfrom collections import defaultdict\r\n\r\nn = int(input())\r\n\r\n\r\nnums = [ int(x) for x in input().split()]\r\n\r\nloves = {}\r\n\r\nfor i in range(n):\r\n loves[i+1] = nums [i] \r\n\r\n# print(str(loves))\r\n\r\nfor one, other in loves.items():\r\n start = one\r\n # print(f\"one= {one} other={other}\")\r\n for i in range(2):\r\n one,other = other, loves[other]\r\n if other == start:\r\n print('YES')\r\n exit()\r\n\r\nprint('NO')\r\n\r\n\r\n\r\n\r\n# if g.isCyclic() == 1:\r\n# # print \"Graph has a cycle\"\r\n# print(\"YES\")\r\n# else:\r\n# # print \"Graph has no cycle\"\r\n# print(\"NO\")\r\n \r\n# Thanks to Divyanshu Mehta for contributing this code", "\nn = int(input())\ni = input()\n\ni = i.split(' ')\nx = []\nfor j in range(len(i)):\n x.append(int(i[j]))\n\n\ndef dothis():\n for i in range(len(x)):\n nextIdx = x[i] - 1\n next = x[nextIdx] - 1\n again = x[next]\n\n if (again == i+1):\n print(\"YES\")\n return\n print(\"NO\")\n\n\ndothis()\n\n\t \t \t \t\t\t \t \t \t\t\t \t", "n = int(input())\r\na = [int(c) for c in input().split()]\r\nfor i in range(n):\r\n x = a[a[i]-1]\r\n if a[i] == x:\r\n break\r\n else:\r\n y = a[a[a[i]-1]-1]\r\n if a[a[i]-1] == y:\r\n break\r\n else:\r\n if i+1 == a[a[a[i]-1]-1]:\r\n print('YES')\r\n break\r\nelse:\r\n print('NO')", "a=int(input())\r\nl=list(map(int,input().split()))\r\nfor i in range(a):\r\n if l[l[l[i]-1]-1]==i+1:print(\"YES\");exit()\r\nprint(\"NO\")\r\n", "n = int(input())\r\nf = list(map(int, input().split()))\r\na = []\r\na.append(0)\r\nh = True\r\nfor j in range(1, n+1):\r\n a.append(f[j-1])\r\nfor i in range(1, n+1):\r\n l = a[a[i]]\r\n if a[l] == i:\r\n print('YES')\r\n h = False\r\n break\r\n\r\nif h:\r\n print('NO')", "def has_love_triangle(n, planes):\r\n for i in range(n):\r\n a = i\r\n b = planes[i] - 1 # Subtract 1 to convert to 0-based indexing\r\n c = planes[b] - 1\r\n\r\n if planes[c] - 1 == a:\r\n return \"YES\"\r\n \r\n return \"NO\"\r\n\r\n# Read input\r\nn = int(input())\r\nplanes = list(map(int, input().split()))\r\n\r\n# Check for love triangle\r\nresult = has_love_triangle(n, planes)\r\nprint(result)", "n=int(input())\r\nline=input()\r\nl=line.split()\r\nst=0\r\nfor j in range(0,len(l)):\r\n b=int(l[j])-1\r\n c=int(l[b])-1\r\n m=int(l[c])-1\r\n if m==j:\r\n print(\"YES\")\r\n st=1\r\n break\r\n \r\nif st==0:\r\n print(\"NO\")", "t=int(input(\"\"))\r\nf=list(map(int,input(\"\").split()))\r\nok=False\r\nfor i in range (len(f)):\r\n A=i+1\r\n B=f[i]\r\n C=f[f[i]-1]\r\n D=f[f[f[i]-1]-1]\r\n if C!=A and C!=B and B!=A and D==A:\r\n ok=True\r\nif ok:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nl = list(map(int,input().split()))\r\n\r\nfor _ in range(0,n):\r\n t = m = l[_]\r\n for i in range(3):\r\n m = l[m-1]\r\n \r\n if m == t:\r\n print(\"YES\")\r\n break\r\n\r\n\r\nif m != t:\r\n print(\"NO\")\r\n \r\n ", "t = int(input())\r\ninp = list(map(int,input().split()))\r\nfor i in range(t):\r\n if inp[inp[inp[inp[i]-1]-1]-1] == inp[i]:\r\n print(\"YES\")\r\n break\r\n else:\r\n continue\r\nelse:\r\n print(\"NO\")", "n = int(input())\nf = [int(x)-1 for x in input().split(\" \")]\ndef love():\n for i in range(n):\n if f[f[f[i]]]==i:\n return \"YES\"\n return \"NO\"\nprint(love())", "import re\n\nin1 = int(input())\nin2 = [int(x)-1 for x in re.split(\"\\\\s\", input())]\n\nfound = False\nfor x in range(len(in2)):\n y1 = in2[x]\n y2 = in2[y1]\n y3 = in2[y2]\n y4 = in2[y3]\n if y1 == y4 and y1 != y2:\n found = True\n break\n\nif found:\n print(\"YES\")\nelse:\n print(\"NO\")\n\t \t \t\t\t \t\t \t\t \t\t\t\t\t\t \t", "n = int(input())\r\ndata = [int(i) - 1 for i in input().split(' ')]\r\n\r\nanswer = ['No', 'Yes']\r\nflag = False\r\nfor i in range(n):\r\n if data[data[data[i]]] == i:\r\n flag = True\r\n break\r\nprint(answer[int(flag)])", "x=int(input())\ny=list(map(int,input().split()))\n \nfor i in y:\n\tif y[y[y[i-1]-1]-1]==i:\n\t\tprint('YES')\n\t\texit()\nprint('NO')\n \t \t \t \t\t\t \t \t\t \t \t\t\t \t \t", "def II():return int(input())\r\ndef MI():return map(int, input().split())\r\ndef LI():return list(map(int, input().split()))\r\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\r\ndef SI():return input()\r\ndef LSI():return list(input())\r\ndef LSI_():return [i for i in input().split()]\r\n\r\n\r\ndef main():\r\n length = II()\r\n arr = LI()\r\n for indx in range(length):\r\n if indx == arr[indx] - 1:\r\n continue\r\n\r\n ele = arr[indx]\r\n\r\n i = 0\r\n while i < 3:\r\n if ele == arr[ele - 1]:\r\n break\r\n\r\n ele = arr[ele-1]\r\n i += 1\r\n\r\n\r\n\r\n if i == 3 and ele == arr[indx]:\r\n\r\n print('YES')\r\n return\r\n print('NO')\r\n\r\nmain()\r\n", "n=int(input());o=0\r\na=list(map(int,input().split()))\r\nfor i in range(n):\r\n p=a[a[i]-1]\r\n l=a[p-1]\r\n if a[l-1]==a[i] and p-1!=i:\r\n o=1\r\n break\r\n \r\nif o==1:\r\n print('Yes')\r\nelse:\r\n print('No')\r\n", "\n\nn = int(input())\n\nl=input().split()\nl = [ int (l[i]) for i in range (n)]\ndone = False\nfor i in range (n) :\n if l[l[l[i]-1]-1]-1== i :\n print (\"YES\")\n done = True\n break\nif not done:\n print(\"NO\")", "if __name__ == '__main__':\r\n n = int(input())\r\n a = list(map(int, input().strip().split()))\r\n a = [0] + a\r\n suc = 0\r\n for i in range(1, n + 1):\r\n if a[a[a[i]]] == i:\r\n print(\"YES\")\r\n suc = 1\r\n break\r\n if suc == 0:\r\n print(\"NO\")", "n = int(input())\r\narr = [0] + list(map(int, input().split()))\r\nflag = False\r\nfor i in range(1, n+1):\r\n if arr[arr[arr[i]]] == i:\r\n flag = True\r\n break\r\n\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "import os.path\r\nfrom math import gcd, floor, ceil\r\nfrom collections import *\r\nimport sys\r\nmod = 1000000007\r\nINF = float('inf')\r\n\r\ndef st(): return list(sys.stdin.readline().strip())\r\ndef li(): return list(map(int, sys.stdin.readline().split()))\r\ndef lis(): return list(map(str, sys.stdin.readline().split()))\r\ndef mp(): return map(int, sys.stdin.readline().split())\r\ndef inp(): return int(input())\r\ndef pr(n): return sys.stdout.write(str(n)+\"\\n\")\r\ndef prl(n): return sys.stdout.write(str(n)+\" \")\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\nmod = 1000000007\r\nINF = float('inf')\r\nY = \"YES\"\r\nN = \"NO\"\r\n\r\ndef solve():\r\n n = inp()\r\n likes = li()\r\n likes = [i-1 for i in likes]\r\n\r\n for i in range(n):\r\n if likes[likes[likes[i]]]==i:\r\n print(Y)\r\n return\r\n\r\n print(N)\r\n \r\n\r\nfor test in range(1):\r\n solve()\r\n", "n = int(input()) \r\n\r\nf = list(map(int, input().rstrip().split()))\r\n\r\nyesNo = 2\r\nfor i in range(n):\r\n f1 = f[i]\r\n f2 = f[f1-1]\r\n f3 = f[f2-1]\r\n \r\n# print(f1, f2, f3)\r\n if f[i] == f[f3-1]:\r\n print(\"YES\")\r\n yesNo = 1\r\n break\r\n\r\nif yesNo==2:\r\n print(\"NO\") ", "n = int(input())\r\nA = list(map(int, input().split()))\r\nfor i in range(n):\r\n A[i] = A[i] - 1\r\n\r\nfor x in A:\r\n y = A[x]\r\n z = A[y]\r\n if A[z] == x:\r\n print(\"YES\")\r\n exit(0)\r\n\r\nprint('NO')", "n=int(input())\r\nl=list(map(int,input().split()))\r\nk=1\r\nfor i in range(n):\r\n if l[l[l[i]-1]-1]-1==i:\r\n print(\"YES\")\r\n k=0\r\n break\r\nif k:\r\n print(\"NO\")", "N = int(input())\nF = list(map(lambda x: int(x) - 1, input().split()))\nok = True\nfor i, f in enumerate(F):\n cur = i\n for j in range(3):\n cur = F[cur]\n if cur == i:\n ok = False\n break\nprint(\"yes\" if not ok else \"no\")\n", "n=int(input())\r\ntest=False\r\nl=[1,*map(int,input().split())]\r\nfor i in range (1,n):\r\n if l[l[l[i]]]==i : print(\"YES\");exit(0)\r\nprint(\"NO\")", "n, f = int(input()), [0] + list(map(int, input().split()))\r\nfor i in range(1, len(f)):\r\n if f[f[f[f[i]]]] == f[i]:\r\n print('YES')\r\n break\r\nelse: print('NO')\r\n \r\n", "from pprint import pprint\n\n\nclass UrAnIdiotError(Exception):\n pass\n\nn = int(input())\n\n\nlikes = list(map(int, input().split())) #the i'th person likes likes[i]\n\n\nfor i, lover1 in enumerate(likes):\n \n # i loves lover1\n\n # lover1 loves lover2\n lover2 = likes[lover1-1]\n\n # lover2 loves lover3\n lover3 = likes[lover2-1]\n \n # if the person lover2 loves is the original lover (i) output \"Yes\"\n if lover3 == i+1:\n print(\"YES\")\n break\n\nelse:\n print(\"NO\")\n", "n = int(input())\r\nll=list(map(int,input().split()))\r\nll.insert(0,0)\r\nfor i in ll[1:]:\r\n if ll[ll[ll[i]]]==i:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")\r\n\r\n", "repeticoes = int(input(\"\"))\nlista = []\na = False\nfor i in range(repeticoes):\n lista.append(i + 1)\n\nnumero = [x for x in input(\"\").split(\" \")]\n\nfor i in numero:\n j = numero[int(i) - 1]\n k = numero[int(j) - 1]\n if (i != j and j != k):\n if (numero[int(k) - 1] == i):\n a = True\n print(\"YES\")\n break\n\nif (a == False):\n print(\"NO\")\n \t \t \t\t\t \t\t\t\t\t \t \t \t\t", "# Collaborated with No One\nnumPlanes = int(input())\nplanes = list(map(int,input().split()))\ncurrentPosition = 0\nflag = True\nfor i in range(0,numPlanes):\n # Get value at index\n currIndexValue = planes[i]\n # Get value of the currentIndex's value\n nextIndexValue = planes[currIndexValue-1]\n # Get value of nextIndexValue\n lastIndexValue = planes[nextIndexValue-1]\n # If the value of the last index matches the index we're on then we have a triangle\n if(lastIndexValue-1 == i):\n print(\"YES\")\n flag = False\n break\nif(flag):\n print(\"NO\")\n\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())\na = list(map(int, input().split()))\nplanes_likes = {}\n\nres = \"NO\"\n\nfor i in range(n):\n planes_likes[i+1] = a[i]\n\nfor i in planes_likes:\n if planes_likes[planes_likes[planes_likes[i]]] == i:\n res = \"YES\"\n break\n\nprint(res)\n \t \t \t\t\t\t\t\t \t\t\t \t\t \t\t \t \t\t", "import sys\r\n\r\ndef love_triangle(arr):\r\n love_dict = {k+1:v for k,v in enumerate(arr)}\r\n\r\n for key, val in love_dict.items():\r\n if val in love_dict.keys():\r\n if love_dict[val] in love_dict.keys() and love_dict[love_dict[val]] == key:\r\n return 'YES'\r\n return \"NO\"\r\n\r\narray = [[int(i) for i in line.split()] for line in sys.stdin.readlines()][1]\r\n\r\nprint(love_triangle(array))\r\n", "'''\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\nf = [0] + list(map(int, input().split()))\r\nans = \"NO\"\r\nfor i in range(1, n + 1):\r\n if i ^ f[i] and f[f[f[i]]] == i:\r\n ans = \"YES\"\r\n break\r\nprint(ans)'''\r\n\r\n\r\nn=int(input())\r\nnums=list(map(int,input().split()))\r\nans=0\r\nfor i in range(n):\r\n if nums[i]-1 in nums and nums[nums[i-1]-1]-1 in nums and nums[nums[nums[i-1]-1]-1]==i:\r\n ans+=1\r\n break\r\nif ans>0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\ns=list(map(int,input().split()))\r\nf={i:k for i,k in zip(range(1,n+1),s)}\r\nfor i in range(1,n+1):\r\n if i==f[f[f[i]]]:\r\n print(\"YES\")\r\n import sys\r\n sys.exit(0)\r\nprint(\"NO\")\r\n \r\n ", "x = int(input())\r\ny = [None]*(x+1)\r\na = input().split(\" \")\r\nfor i in range(len(a)):\r\n y[i+1] = int(a[i])\r\nfor i in range(1,x+1):\r\n if y[y[y[i]]]==i:\r\n print(\"Yes\")\r\n break\r\nelse:print(\"NO\")", "n = int(input())\r\nplanes = list(map(int, input().split()))\r\nlike = {}\r\nfor i in range(1, n+1):\r\n like[i] = planes[i-1]\r\n\r\nflag = False \r\nfor i in range(1, n+1):\r\n temp = []\r\n visited = []\r\n q = [i]\r\n # print(i)\r\n while q:\r\n curr = q.pop()\r\n if curr not in visited:\r\n temp.append(curr)\r\n q.append(like[curr])\r\n visited.append(curr)\r\n # print(temp)\r\n if len(temp) == 3:\r\n if like[temp[-1]] == temp[0]:\r\n flag = True\r\n break\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n ", "n=int(input())\r\nt=[int(w) for w in input().split()]\r\nq=0\r\nfor i in range(n):\r\n\tx=i\r\n\ta=t[x]-1\r\n\ty=a\r\n\tb=t[y]-1\r\n\tz=b\r\n\tc=t[z]-1\r\n\tif c==x:\r\n\t\tprint('yes'.upper())\r\n\t\tq=1\r\n\t\tbreak\r\nif q==0:\r\n\tprint('NO')", "n = int(input())\r\nf = [int(i) for i in input().split(' ')]\r\nf.insert(0, 0)\r\nflag = 0\r\nfor i in range(1, n+1):\r\n if f[i]==f[f[f[f[i]]]]:\r\n print(\"Yes\")\r\n flag = 1\r\n break\r\nif flag ==0:\r\n print('No')", "n = int(input())\r\nlst = [int(i) for i in input().split()]\r\n\r\nfor i in range(n):\r\n if lst[lst[lst[i]-1]-1] == i+1:\r\n print('YES')\r\n exit(0)\r\n\r\nprint('NO')\r\n", "n = int(input())\r\nls = list(map(int, input().split()))\r\nlove = {}\r\nfor i in range(n):\r\n love[i+1] = ls[i]\r\nflag = False\r\nfor i in love:\r\n if love[love[love[i]]] == i:\r\n flag = True\r\n break\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n\r\n", "def solve():\n numTestes = int(input())\n listPlanos = list(map(int, input().split()))\n cont = 1;dictDados = {}\n solve = False;tam = len(listPlanos)+1\n while(cont < tam):\n dictDados[cont] = listPlanos[cont-1] \n cont = cont+1 \n #print(dictDados)\n for indexDict in dictDados:\n dado = dictDados[indexDict]\n dadoTri = dictDados[dictDados[dado]]\n if( dadoTri == indexDict ):\n print('YES')\n solve = True\n break\n if(solve == False):\n print('NO')\n\n\n\n \nsolve()\n\n\n \t\t \t \t \t\t\t \t \t\t \t \t \t\t\t", "n = int(input())\r\nf = [int(item)-1 for item in input().split()]\r\n\r\nflag = False\r\n\r\nfor i in range(0, n):\r\n if f[f[f[i]]] == i:\r\n flag = not flag\r\n break\r\n\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "N = int(input())\n\nrel = [int(i)-1 for i in input().split(' ')]\nassert len(rel) == N\n\ndef check():\n for i, r in enumerate(rel):\n if rel[r] != i and rel[rel[r]] == i:\n return True\n return False\n\nprint('yes' if check() else 'no')\n\n\n \t\t \t\t\t\t \t \t \t \t \t \t \t \t \t", "n = int(input())#converts input to int\r\nplanes = list(map(int, input().split())) #read the liking relationship and stores them seperately in a list\r\nflag = 0\r\nfor i in range(1, n + 1): #for any variable i in range of 1 and n\r\n if planes[planes[planes[i - 1]-1]-1] == i:\r\n flag = 1\r\nif flag == 1:\r\n print ('YES')\r\nelse:\r\n print ('NO')", "def main():\r\n input()\r\n planes_list = list(map(int, input().split()))\r\n relations = {i: planes_list[i-1] for i in planes_list}\r\n for plane in relations:\r\n current = relations[plane]\r\n if relations[relations[current]] == plane:\r\n print(\"YES\")\r\n return 0\r\n print(\"NO\")\r\n\r\n\r\nmain()\r\n", "import sys\ninp = sys.stdin.readlines()\nn = int(inp.pop(0).replace('\\n',''))\n\nline = inp.pop(0).replace('\\n','').split()\nclist = [-1]\nfor i in range(n):\n num = int(line[i])\n clist.append(num)\n\nfor i in range(1,n+1):\n if clist[clist[clist[i]]] == i:\n print('YES')\n sys.exit()\nprint('NO')\n\t\t\t\t\t\t\t \t\t\t \t \t\t\t \t \t\t\t", "#for _ in range(int(input())):\r\nn=int(input())\r\n # n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nz=0\r\nfor i in range(n):\r\n if(a[a[a[i]-1]-1]==i+1):\r\n print(\"YES\")\r\n z=1\r\n break\r\nif(z==0):\r\n print(\"NO\")", "n = int(input())\r\nnamdvili_siyvaruli = list(map(int, input().split()))\r\n\r\nfor i in range(n):\r\n x = namdvili_siyvaruli[i]\r\n y = namdvili_siyvaruli[x - 1]\r\n if y != i + 1 and namdvili_siyvaruli[y - 1] == i + 1:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")", "\nimport sys\n\n\nif __name__ == '__main__':\n n = int(sys.stdin.readline().strip())\n mass = list(map(int, sys.stdin.readline().strip().split()))\n cycle = False\n\n #Формирование списка смежности\n adj = [[] for i in range(n+1)]\n for v, u in enumerate(mass):\n adj[v+1].append(u)\n\n\n #Идем по всем вершинам\n for i in range(1, n+1):\n v = i\n #Смотрим еще 2 вершины\n for _ in range(3):\n u = adj[v][0]\n v = u\n else:\n if v == i:\n cycle = True\n\n\n #Вывод ответа\n if cycle:\n print('YES')\n else:\n print('NO')\n\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\n\r\nfor i in range(len(li)):\r\n if li[li[li[i] - 1] - 1] == i + 1:\r\n exit(print(\"YES\"))\r\nprint(\"NO\")", "n=int(input())\r\ntab=list(map(int,input().split(\" \")))\r\ni=0\r\nresult=\"NO\"\r\nwhile(i<len(tab)):\r\n a=tab[i]\r\n b=tab[a-1]\r\n if(tab[b-1]-1==i):\r\n result=\"YES\"\r\n break\r\n i+=1\r\nprint(result)\r\n", "import math\r\nn=int(input())\r\n#n,m = map(int, input().strip().split(' '))\r\nlst = list(map(int, input().strip().split(' ')))\r\nf=0\r\nfor j in range(n):\r\n p1=lst[j]\r\n p2=lst[p1-1]\r\n p3=lst[p2-1]\r\n if p3==j+1 and p2!=j+1:\r\n f=1\r\n print('YES')\r\n break\r\nif f==0:\r\n print('NO')", "import sys\r\n\r\ndef main():\r\n _, *l = (int(i) - 1 for i in sys.stdin.read().strip().split())\r\n for i,j in enumerate(l):\r\n if l[l[j]] == i: return 'YES'\r\n return 'NO'\r\n\r\nprint(main())", "m = int(input())\r\ne = list(map(int, input().split()))\r\ne.insert(0,0)\r\ns = 0\r\nfor i in range(1,m):\r\n if i == e[e[e[i]]]:\r\n s = 1\r\n break\r\nif s == 1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "input()\nplaneLikes = map(int, input().split())\nplaneLikes = list(planeLikes)\n\n\nplaneA = 0\nwhile planeA < len(planeLikes):\n # getthe plane planeA likes, if that plane likes planeA, then we have a triangle\n planeB = planeLikes[planeA]\n planeC = planeLikes[planeB - 1]\n\n if planeLikes[planeC - 1] == planeA + 1:\n print(\"YES\")\n exit()\n planeA += 1\n\nprint(\"NO\")\n\n \t\t \t \t \t \t\t\t \t\t\t \t \t \t", "n_elementos = int(input())\nlista = list(map(int, input().split(' ')))\ndef dfs_vetor(index, lista):\n\treturn lista[index]\ncount=0\nfor index in range (0, n_elementos):\n\tif dfs_vetor(dfs_vetor(dfs_vetor(index, lista)-1,lista)-1,lista) == index+1:\n\t\tprint('YES')\n\t\tcount+=1\n\t\tbreak\nif count==0:\n\tprint('NO')", "length = int(input())\r\nvalues = list(map(int, input().split()))\r\nflag = False\r\nfor i in range(length):\r\n start = i + 1\r\n curr = values[i]\r\n for j in range(1, 3):\r\n curr = values[curr-1]\r\n if curr == start:\r\n flag = True\r\n break\r\n else:\r\n continue\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\narr = [0]+list(map(int,input().split()))\r\n\r\nfor i in range(1,n+1) :\r\n if i==arr[arr[arr[i]]] :\r\n print(\"YES\")\r\n break\r\nif i==n :\r\n print(\"NO\")\r\n", "n = int(input())\r\nf = list(map(int,input().split()))\r\n\r\nflag = 0\r\nfor i in range(n):\r\n a = f[i]\r\n b = f[a-1]\r\n c = f[b-1]\r\n if c-1 == i:\r\n flag = 1\r\n break\r\n\r\nif flag == 1:\r\n print('YES')\r\nelse:\r\n print('NO')", "n=int(input())\r\nl=list(map(int,input().split()))\r\nm=True\r\nfor i in range(n):\r\n k=[]\r\n k.append(l[i]-1)\r\n k.append(l[k[len(k)-1]]-1)\r\n if l[k[len(k)-1]]-1==i:\r\n print(\"YES\")\r\n m=False\r\n break\r\nif m:\r\n print(\"NO\")\r\n \r\n", "n = int(input())\r\nf = list(map(int, input().split()))\r\nfor i in range(n):\r\n if f[f[f[i] - 1] - 1] == i + 1:\r\n print('YES')\r\n break\r\nelse:\r\n print('NO')", "n = int(input())\r\na = list(map(int,input().split()))\r\ncount = 'NO'\r\nfor i in a:\r\n if a[a[a[i-1]-1]-1] == i:\r\n count = 'YES'\r\n break\r\nprint(count)\r\n", "n = int(input())\nadj = [0] + list(map(int, input().split()))\n\nhas_trngl = False\nfor v in range(1, n+1):\n a = v\n b = adj[a]\n c = adj[b]\n if adj[c] == a:\n has_trngl = True\n\nprint(\"YES\" if has_trngl else \"NO\")\n\n\n\n\t \t \t\t \t \t\t\t \t\t\t \t \t \t \t\t", "a = int(input())\r\nl = list(map(int, input().split()))\r\nl.insert(0,0)\r\nr = 0\r\nfor i in range(1,a):\r\n if i == l[l[l[i]]]:\r\n r = 1\r\n break\r\nif r == 1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\nl=list(map(int,input().strip().split()))\r\ncount=1\r\nfor i in range(n):\r\n a=l[i]\r\n b=l[a-1]\r\n c=l[b-1]\r\n if c-1==i:\r\n print(\"YES\")\r\n count=0\r\n break\r\nif count==1:\r\n print(\"NO\")", "n=int(input())\r\na=list(map(int,input().split()))\r\nj=False\r\nfor i in range(0,n):\r\n\tx=a[i]\r\n\ty=a[x-1]\r\n\tz=a[y-1]\r\n\tif ((i+1)==z):\r\n\t\tj=True\r\n\t\tbreak\r\nif j:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "if __name__ == '__main__':\n n = int(input())\n f = list(map(int, input().split()))\n verifica = False\n\n for i in range(n):\n if f[f[f[i]-1]-1] == i + 1 and not verifica:\n print('YES')\n verifica = True\n\n if not verifica:\n print('NO')\n \t\t \t \t \t \t \t \t \t\t \t", "n = int(input())\nadj = [[] for _ in range(n + 1)]\nlikes = [int(x) for x in input().split()]\n\nfor i in range(1, n + 1):\n adj[i].append(likes[i - 1])\n\nvisited = [0] * (n + 1)\ncycled = False\npred = [-1] * (n + 1)\n\ndef dfs(v):\n global cycled, cycled_pair\n visited[v] = 1 \n for u in adj[v]:\n if u == pred[v]:\n continue\n if visited[u] == 1:\n cycled = True\n cycled_pair = (v, u)\n elif not visited[u]:\n pred[u] = v\n dfs(u)\n visited[v] = 2 \n\nfor v in range(1, n+1):\n if not visited[v]:\n dfs(v)\n\nnum_cycle = 1\nif cycled:\n v, u = cycled_pair\n x = v\n while x != u:\n x = pred[x]\n num_cycle += 1\n \nif num_cycle == 3:\n print('YES')\nelse:\n print('NO')\n \t \t \t\t \t \t \t\t \t\t \t\t \t\t", "t = int(input())\r\n\r\n\r\ndef love_triangle(n, arr):\r\n relation = {}\r\n\r\n for i in arr:\r\n relation[i] = arr[i - 1]\r\n\r\n for i in relation:\r\n temp = i\r\n if relation[relation[relation[i]]] == temp:\r\n return \"YES\"\r\n return \"NO\"\r\n\r\n\r\nplanes = list(map(int, input().split()))\r\nprint(love_triangle(t, planes))\r\n", "n=int(input());l=list(map(int,input().split()))\r\nfor i in range(n):\r\n\tif l[l[l[i]-1]-1]==i+1:\r\n\t\tprint('Yes');break\r\nelse:\r\n\tprint('nO')", "n = int(input())\r\na = [0]\r\nlah = [int(p) for p in input().split()]\r\na.extend(lah)\r\ncond = False\r\nfor i in range(1, len(lah)):\r\n if i == a[a[a[i]]]:\r\n cond = True\r\n break\r\nif cond:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\nflag=\"NO\"\r\nl=list(map(int,input().split()))\r\nfor i in range(n):\r\n\tif l[l[l[i]-1]-1]==i+1:\r\n\t\tflag=\"YES\"\r\nprint(flag)\r\n", "n = int(input())\nfis = list(map(int, input().split()))\nf = 0\nfor i in range(n):\n\tc = 0\n\tt = i\n\twhile c < 3:\n\t\tt = fis[t] - 1\n\t\tc += 1\n\tif t == i:\n\t\tprint(\"YES\")\n\t\tf = 1\n\t\tbreak\nif f == 0:\n\tprint(\"NO\")\n", "n = int(input())\nvs = [int(x) for x in input().split()]\n\nresult = \"NO\"\nfor i in range(n):\n if vs[vs[vs[i]-1]-1] == i+1:\n result = \"YES\"\n break\nprint(result)\n \t \t\t \t\t \t \t \t \t\t\t\t \t\t", "n = int(input())\r\nf = list(map(int, input().split()))\r\nf = [f[i]-1 for i in range(len(f))]\r\nr = [i for i in range(n)]\r\nlove = False\r\nfor i in range(n):\r\n if f[f[f[i]]]==i:\r\n love=True\r\n break\r\nprint('YES' if love else 'NO')\r\n", "\r\ndef a(n, s):\r\n for i in range(len(s)):\r\n if s[s[s[i] - 1]-1] - 1 == i:\r\n\r\n return \"YES\"\r\n\r\n return \"NO\"\r\n\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n s =[int(i) for i in input().split()]\r\n print(a(n, s))", "input()\r\na = [1] + list(map(int, input().split()))\r\nprint('YES' if any(a[a[x]] == a.index(x) for x in a) else 'NO')\r\n", "n = int(input())\r\nf = False\r\na = list(map(int, input().split()))\r\nfor i in range(n):\r\n if a[a[a[i] - 1] - 1] == i + 1:\r\n f = True\r\nif f:\r\n print('YES')\r\nelse:\r\n print('NO')", "n = int(input())\r\nL = list( map(int, input().split()) )\r\n\r\nflag = False\r\nfor i in range(n):\r\n loves = L[i]\r\n lloves = L[loves-1]\r\n llloves = L[lloves-1]\r\n if llloves == (i+1):\r\n print(\"YES\")\r\n flag = True\r\n break\r\nif flag == False:\r\n print(\"NO\")\r\n", "n, lst, res = int(input()), [1] + list(map(int, input().split())), \"NO\"\r\nfor i in range(1, n + 1):\r\n if lst[lst[lst[i]]] == i: \r\n res = \"YES\"\r\n break\r\nprint(res)", "# -*- coding: utf-8 -*-\n\nn = int(input())\n\nplanes = [int(x) for x in input().split(' ')]\nplanes.insert(0, None)\n\nans = \"NO\"\n\nfor i in range(1, n):\n a_likes = planes[i]\n b_likes = planes[a_likes]\n c_likes = planes[b_likes]\n \n if i == c_likes:\n ans = \"YES\"\n break\n\nprint(ans)\n\n\t \t \t \t \t \t \t\t \t \t\t \t", "n = int(input())\r\nf = [0] + list(map(int, input().split()))\r\nfor i in range(1, len(f)):\r\n first = f[i]\r\n second = f[f[i]]\r\n third = f[f[f[i]]]\r\n if f[first] == second and f[second] == third and f[third] == first:\r\n print('YES')\r\n break\r\nelse:\r\n print('NO')\r\n \r\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\n\r\nlove_tri = False\r\n\r\nfor i in range(n):\r\n a = i+1\r\n b = arr[i]\r\n c = arr[b-1]\r\n\r\n if arr[c-1] == a:\r\n print('YES')\r\n love_tri = True\r\n break\r\n\r\nif not love_tri:\r\n print('NO')\r\n", "a=int(input())\r\nb=list(map(int,input().split()))\r\nb.reverse()\r\nb.append(0)\r\nb.reverse()\r\nk=0\r\nfor i in range(1,a+1):\r\n if b[b[b[i]]]==i:\r\n k=1\r\n break\r\nif k:\r\n print('yes')\r\nelse:\r\n print('no')\r\n", "# from dust i have come dust i will be\n\nn=int(input())\nx=list(map(int,input().split()))\n\nfor i in range(n):\n a=i+1\n b=x[a-1]\n c=x[b-1]\n\n if x[c-1]==a:\n print(\"YES\")\n exit(0)\n\nprint(\"NO\")\n", "def main():\r\n global g\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n for i in range(n):\r\n a[i] -= 1\r\n ok = False\r\n for i in range(n):\r\n for j in range(n):\r\n if i != n and a[a[j]] == i and a[i] == j:\r\n ok = True\r\n if ok:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n return None\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "def solution():\n n=int(input())\n planes = list(map(int, input().strip().split()))[:n]\n for i in range(len(planes)):\n a=planes[i]\n b=planes[a-1]\n c=planes[b-1]\n if a == planes[c-1]:\n print(\"YES\")\n break\n else:\n print('NO')\n \nsolution()\n \t\t \t\t\t \t\t\t\t \t \t \t\t \t\t\t \t", "n, flag = int(input()), 0\r\nnums = list(map(int, input().split()))\r\nnums = [nums[i]-1 for i in range(n)]\r\nfor i in range(n):\r\n if nums[nums[nums[i]]] == i: flag = 1\r\nprint(\"YES\" if flag else \"NO\")", "n = int(input())\r\nf = list(map(int, input().split()))\r\ni = 0\r\nans = 'NO'\r\nwhile i < n - 1:\r\n\tif f[f[f[i]-1]-1] == i+1:\r\n\t\tans = 'YES'\r\n\t\tbreak\r\n\ti += 1\r\nprint(ans)", "n = int(input())\r\na = [0 for i in range(n+1)]\r\ns = input().split()\r\nfor i in range(1,n+1):\r\n a[i] = int(s[i-1])\r\nans = False\r\nfor i in range(1,n+1):\r\n if i == a[a[a[i]]]:\r\n ans = True\r\n break\r\nprint('YES' if ans else 'NO')", "n = int(input())\r\n\r\narray = list(map(int, input().split()))\r\n\r\nflag = 0\r\n\r\nfor i in range(n):\r\n if (array[array[array[i] - 1] - 1] - 1 == i):\r\n flag = 1\r\n break\r\n \r\nif flag == 1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "\r\nfrom re import I\r\n\r\n\r\nn = int( input() )\r\nplanes = list( map(int, input().split()) )\r\n\r\nfor i in range(n):\r\n start = i \r\n next = planes[i] - 1\r\n \r\n if start == next:\r\n continue\r\n\r\n end = planes[next] - 1\r\n \r\n if next == end:\r\n continue\r\n\r\n final = planes[end] - 1\r\n \r\n if start == final:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")\r\n\r\n", "a=int(input())\r\ngraph={x:[] for x in range(1,a+1)}\r\ndef addedges(x,y):\r\n graph[x].append(y)\r\nb=list(map(int,input().split()))\r\nct=1\r\nfor i in b:\r\n addedges(ct,i)\r\n ct+=1\r\ndef soln():\r\n global graph\r\n for i in graph:\r\n if i==graph[graph[graph[i][0]][0]][0] and i!=graph[graph[i][0]][0]:\r\n return \"YES\"\r\n return \"NO\"\r\nprint(soln())", "n = int(input())\np = [int(x) - 1 for x in input().split()]\nfor i in range(n):\n if p[p[p[i]]] == i:\n print(\"YES\")\n break\nelse:\n print(\"NO\")\n", "lenn = int(input())\r\nlist1 = list(map(int,input().split()))\r\noutput = 'NO'\r\nfor i in range(1,lenn+1):\r\n if list1[list1[list1[i-1]-1]-1]==i:\r\n output = ('YES')\r\n break\r\nprint(output)", "import sys\nfrom collections import defaultdict\n\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split()))\n\nclass Graph:\n\n def __init__(self):\n self.graph = defaultdict(list)\n self.path = 0\n\n def addEdge(self, u, v):\n self.graph[u].append(v)\n \n def DFSUtil(self, v, visited, start):\n visited.append(v)\n\n for neighbour in self.graph[v]:\n if len(visited) == 3 and neighbour == visited[0]:\n # print('neighbour',neighbour, 'visited', visited, 'v', v)\n sys.stdout.write('YES')\n sys.exit()\n\n if neighbour not in visited:\n self.DFSUtil(neighbour, visited, start)\n \n def DFS(self, v):\n start = v\n visited = list()\n self.DFSUtil(v, visited, start)\n\n\nplanes = int(sys.stdin.readline().strip())\nliked_planes = get_list()\nG = Graph()\n\nfor plane, liked_plane in enumerate(liked_planes, start=1):\n G.addEdge(plane, liked_plane)\n\nfor i in range(1, planes+1):\n G.DFS(i)\n\nsys.stdout.write('NO')\n \t \t \t\t\t \t\t \t\t\t\t\t \t\t \t \t\t\t", "t = int(input())\nelements = list(map(int,(input().split())))\n\nhash_table = {}\nfor i,num in enumerate(elements):\n hash_table[i+1]=num\nans = False\n\nfor key in hash_table:\n if key == hash_table[hash_table[hash_table[key]]]:\n ans= True\n break\n \nif ans:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t\t \t\t\t \t\t \t\t \t\t \t \t\t \t", "a=int(input());l=list(map(int,input().split()))\r\nfor i in range(a):\r\n if l[l[l[i]-1]-1]==i+1:print(\"YES\");exit()\r\nprint(\"NO\")\n# Sat Apr 08 2023 20:03:49 GMT+0300 (Moscow Standard Time)\n", "n=int(input())\r\nnums=list(map(int,input().split()))\r\nans=0\r\nfor i in range(n):\r\n if nums[i]-1 in nums and nums[nums[i-1]-1]-1 in nums and nums[nums[nums[i-1]-1]-1]==i:\r\n ans+=1\r\n break\r\nif ans>0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") ", "n=int(input())\r\na=list(map(int,input().split(' ')))\r\nk=0\r\nfor i in range(n):\r\n\tif a[a[i]-1]!=i+1 and a[a[a[i]-1]-1]==i+1:\r\n\t\tk=1\r\nif k>0:\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "n = int(input())\r\narr = list(map(int,input().split()))\r\n\r\ndef loveTriangle(idx, seen):\r\n if idx in seen:\r\n if len(seen) == 3:\r\n return idx\r\n return -1\r\n return loveTriangle(arr[idx-1], seen | set([idx]))\r\n\r\nisTrue = False\r\nfor i in range(1,n+1):\r\n if i == loveTriangle(arr[i-1],set([i])):\r\n isTrue = True\r\n break\r\n\r\nif isTrue:\r\n print('YES')\r\nelse:\r\n print('NO')", "def love_triangle(n, p):\r\n for i in range(n):\r\n a = i + 1\r\n b = p[a] \r\n c = p[b] \r\n if p[c] == a: \r\n return \"YES\" \r\n return \"NO\" \r\n\r\n\r\nn = int(input())\r\np = [0] + list(map(int, input().split())) \r\n\r\n\r\nresult = love_triangle(n, p)\r\nprint(result)\r\n", "input();a=list(map(int,input().split()));b=\"NO\"\r\nfor i in range(len(a)):\r\n if a[a[a[i]-1]-1]==i+1:b=\"YES\";break\r\nprint(b)", "def triangle(aviones):\r\n pociciones=[]\r\n for n in range(len(aviones)):\r\n pociciones.append(n)\r\n guardar=n\r\n for n in range(3):\r\n guardar=aviones[guardar]-1\r\n pociciones.append(guardar)\r\n if pociciones[0]==pociciones[3] and pociciones[1]!=pociciones[3]:\r\n return \"YES\"\r\n pociciones=[]\r\n return \"NO\"\r\n\r\n\r\ndef main():\r\n casos=int(input())\r\n aviones=[int(x) for x in input().split()]\r\n print(triangle(aviones))\r\nmain()\r\n", "# Referência:\r\n# https://codeforces.com/problemset/problem/939/A\r\n# https://codeforces.com/blog/entry/57892\r\n\r\nn = int(input())\r\nlove = list(map(int, input().split()))\r\n\r\nans = \"NO\"\r\nfor i in range(n):\r\n first_love = love[love[i]-1]\r\n second_love = love[first_love-1]\r\n\r\n if second_love == i + 1:\r\n ans = \"YES\"\r\n break\r\n\r\nprint(ans)", "n = int(input())\r\n\r\nd = {}\r\n\r\nfor i, v in enumerate(list(map(int, input().split()))):\r\n d[i+1] = v\r\n\r\n\r\nans = False\r\n\r\nfor i in range(1, n+1):\r\n start = i\r\n tmp = i\r\n for _ in range(3):\r\n v = d[tmp]\r\n tmp = v\r\n\r\n if tmp == start:\r\n ans = True\r\n break\r\n\r\n\r\nprint(\"YES\" if ans else \"NO\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "def has_love_triangle(n, planes):\r\n for i in range(n):\r\n x = planes[i]\r\n y = planes[x - 1] \r\n z = planes[y - 1] \r\n if z == i + 1: \r\n return \"YES\"\r\n return \"NO\"\r\n\r\nn = int(input())\r\nplanes = list(map(int, input().split()))\r\n\r\nres = has_love_triangle(n, planes)\r\nprint(res)", "n=int(input())\nl=list(map(int, input().split()))\ncount=0\nfor i in range(n):\n a=l[i]-1\n b=l[a]-1\n c=l[b]-1\n if i!=l[i] and i==c:\n count=1\n break\nif count==1:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n\n\n\t\t\t\t\t \t\t \t \t\t \t \t\t \t \t\t\t \t", "def f(a, b):\r\n return [b[i - 1] for i in a]\r\n\r\nn = int(input())\r\nc = [int(i) for i in input().split()]\r\na = f(c, f(c, c))\r\nr = False\r\nfor i in range(n):\r\n r = r or i + 1 == a[i]\r\nprint(r * 'YES' + (1 - r) * 'NO')", "n = int(input())\r\n\r\na = list(map(int, input().split()))\r\n\r\na.insert(0,0)\r\n\r\nres = 0\r\n\r\nfor i in range(1,n):\r\n \r\n if i == a[a[a[i]]]:\r\n \r\n res = 1\r\n \r\n break\r\n \r\nif res == 1:\r\n \r\n print(\"YES\")\r\n \r\nelse:\r\n \r\n print(\"NO\")", "n = int(input())\r\narr = [int(x) for x in input().split()]\r\ncheck = False\r\nfor i in range(n):\r\n if arr[(arr[(arr[i]-1)]-1)] == i + 1:\r\n print(\"YES\")\r\n check = True\r\n break\r\nif check == False:\r\n print(\"NO\") \r\n \r\n \r\n", "n = int(input())\r\np = list(map(int, input().split()))\r\n# p = [3, 1, 2, 4, 5]\r\np = [p[i] - 1 for i in range(n)]\r\nlove = 0\r\n\r\nfor i in range(n):\r\n if p[p[p[i]]] == i: # p[p[3]] .. p[2] .. 1\r\n love = 1\r\n break\r\nprint(\"YES\") if love == 1 else print('NO')", "n = input()\nl = input().split(\" \")\nl = [int(elem) -1 for elem in l]\nfor i in range(len(l)):\n if l[l[l[i]]] == i:\n print(\"YES\")\n break\n if i == len(l) -1:\n print(\"NO\")", "a=int(input())\r\nb=input().split()\r\nb=list(map(int,b))\r\nl=[[] for c in range(a)]\r\nfor c in range(a):\r\n l[b[c]-1].append(c)\r\ni=0\r\nfor c in range(a):\r\n if b[b[c]-1]-1 in l[c]:\r\n print(\"YES\")\r\n \r\n i+=1\r\n break\r\nif i==0:\r\n print(\"NO\")", "from collections import deque\n\nn = int(input())\nlst = [[] for _ in range(n+1)]\n\ns = list(map(int, input().split()))\nfor i in range(len(s)):\n lst[i+1].append(s[i])\n \nvisited = [0] * (n+1)\npred = [-1] * (n+1)\nnext_ = [-1] * (n+1)\nans = 'NO'\n\ndef dfs(v):\n global ans\n visited[v] = 1\n \n for x in lst[v]:\n if visited[x] == 1:\n if pred[v] == next_[x]:\n ans = 'YES'\n \n if visited[x] == 0:\n pred[x] = v\n next_[v] = x\n dfs(x)\n \n visited[v] = 2\n\nfor x in range(1, len(visited)):\n if visited[i] == 0:\n dfs(x)\n \nprint(ans)\n \t\t \t\t \t\t \t \t\t \t \t \t", "n=int(input())\r\nf=list(map(int,input().split()))\r\nt=0\r\nfor i in range(n):\r\n if f[f[f[i]-1]-1]==i+1:\r\n print('YES')\r\n t=0\r\n break\r\n else:\r\n t=1\r\nif t!=0:\r\n print('NO') \r\n", "n = int(input())\r\nlove_list = list(map(int, input().split()))\r\n\r\n\r\nfor i in range(n):\r\n if love_list[love_list[love_list[i] - 1] - 1] == i + 1:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\nm = list(map(int, input().split()))\r\nA = [m[i]-1 for i in range(n)]\r\nnone = True\r\nfor j in range(n):\r\n if A[A[A[j]]] == j:\r\n print(\"YES\")\r\n none = False\r\n break\r\nif none:\r\n print(\"NO\")", "def kesava(n,l):\r\n for i in range(n):\r\n if i+1==l[l[l[i]-1]-1]:\r\n return \"YES\"\r\n return \"NO\"\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nprint(kesava(n,l))", "t= int(input()) \r\nl=list(map(int,(input().split())))\r\n\r\nfound=False\r\nfor i in range(len(l)):\r\n \r\n start=l[i]-1\r\n count=0\r\n \r\n while count<2:\r\n \r\n start=l[start]-1\r\n count+=1\r\n if start==i:\r\n found=True\r\n print(\"YES\")\r\n break\r\n \r\nif not found:\r\n print(\"NO\")\r\n ", "n=int(input())\r\na=list(map(int,input().strip().split()))\r\nc=0\r\nfor i in a:\r\n if i==a[a[i-1]-1]:\r\n continue\r\n if i==a[a[a[i-1]-1]-1]:\r\n c=1\r\nif c==1:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n ", "while 1:\r\n try:\r\n n=int(input())\r\n st=list(map(int,input().split()))\r\n st.insert(0,0)\r\n f=0\r\n for i in range(1,len(st)):\r\n if i==st[st[st[i]]]:\r\n print(\"yes\")\r\n f=1\r\n break\r\n if f==0:\r\n print(\"no\")\r\n \r\n except:\r\n break", "start_node = None\n\ndef dfs(v, depth):\n visited[v] = True\n for u in graph[v]:\n if depth == 2:\n if u == start_node:\n return True\n elif not visited[u]:\n if dfs(u, depth + 1):\n return True\n visited[v] = False\n return False\n\nn = int(input())\nf = list(map(int, input().split()))\ngraph = [[] for _ in range(n+1)]\nvisited = [False]*(n+1)\n\nfor i in range(n):\n graph[i+1].append(f[i])\n\nfor i in range(1, n+1):\n start_node = i\n if dfs(i, 0):\n print(\"YES\")\n break\nelse:\n print(\"NO\")\n\n\t\t\t\t \t\t \t \t\t \t\t\t\t \t \t \t", "def process():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n \r\n if n == 2:\r\n print('NO')\r\n return\r\n \r\n likes = dict()\r\n for i, v in enumerate(arr):\r\n likes[i + 1] = v\r\n \r\n for i in range(1, n + 1):\r\n if likes[likes[likes[i]]] == i:\r\n print(\"YES\")\r\n return\r\n \r\n print(\"NO\")\r\n \r\nprocess()", "n = int(input())\r\nf = [int(x) for x in input().split()]\r\ndef find(n, f):\r\n for i in range(n):\r\n\r\n if f[f[f[i - 1] - 1] - 1] == i:\r\n return True\r\n\r\nif find(n, f):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nplanes = list(map(int, input().split()))\r\nfor i in range(n):\r\n x = i + 1\r\n y = planes[i]\r\n z = planes[y - 1]\r\n if planes[z - 1] == x:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\ndata = list(map(int, input().split()))\r\n\r\nflag = False\r\nfor i in range(n):\r\n a = data[i] - 1\r\n b = data[a] - 1\r\n c = data[b] - 1\r\n if i == c and i != b:\r\n flag = True\r\n break\r\n\r\nprint(\"YES\" if flag else \"NO\")", "def solve():\n for i in range(1, n+1):\n if (arr[arr[arr[i]]]==i):\n return \"YES\"\n return 'NO'\n\nn=int(input())\narr=[0] + [int(x) for x in input().split()]\nprint(solve())\n\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\narr=list(map(int,input().split()))\r\nvis=[0]*(n)\r\nflag=0\r\nfor i,ele in enumerate(arr):\r\n if arr[arr[ele-1]-1]-1==i:\r\n print('YES')\r\n flag=1\r\n break\r\nif not flag:\r\n print('NO')\r\n ", "#Problem Set A: Collaborated with Rudransh Singh\n\nn = int(input())\n\na_list = list(map(int, input().split()))\n\n\ntemp_arr = []\nflag = False\n\nfor i in range(n):\n val = a_list[i]\n\n val1 = a_list[val - 1]\n\n val2 = a_list[val1 -1]\n\n if val2 - 1 == i:\n print(\"YES\")\n flag = True\n break\n\nif not flag:\n print(\"NO\")\n\t \t \t\t\t\t\t\t\t \t \t \t\t \t \t \t\t\t \t", "cases = int(input())\r\n\r\narr = list(map(int, input().split()))\r\n\r\narr = [i - 1 for i in arr]\r\n\r\nfor i in arr:\r\n one = arr[i]\r\n two = arr[one]\r\n three = arr[two]\r\n if three == i:\r\n print(\"YES\")\r\n exit()\r\n\r\nprint(\"NO\")\r\n", "n = int(input())\r\ns = list(map(int,input().split()))\r\nans = \"NO\"\r\nfor i in range(n):\r\n if s[s[s[i]-1]-1]-1==i:\r\n ans = \"YES\"\r\n break\r\n\r\nprint(ans) ", "x=int(input())\r\nlis=list(map(int,input().split()))\r\nan=False\r\nans=''\r\nfor i in lis:\r\n if lis[lis[lis[i-1]-1]-1]==i:\r\n ans=('YES')\r\n break\r\n else:\r\n ans='NO'\r\nif not an:\r\n print(ans)", "n = int(input())\r\nline = input()\r\na = [int(x) for x in line.split()]\r\nfound = False\r\nfor i in range(n):\r\n j = i - 1\r\n if (j == a[a[a[j] - 1] - 1] - 1):\r\n found = True\r\n \r\nif (found):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "t = int(input())\r\nl = list(map(int, input().split()))\r\n\r\nresult = \"NO\"\r\nfor i in range(len(l)):\r\n if l[l[l[i]-1]-1] == i + 1:\r\n result = \"YES\"\r\n break\r\n else:\r\n continue\r\n\r\nprint(result)\r\n", "# cook your dish here\r\nimport bisect \r\nn=int(input())\r\nA=[0]\r\nfor k in input().split():\r\n A.append(int(k))\r\n# s=input()\r\n\r\nfor k in range(1,n+1):\r\n if A[A[A[k]]]==k:\r\n print(\"YES\")\r\n break \r\nelse:\r\n print(\"NO\")\r\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=int(input())\na=list(map(int,input().split()));c=0\nfor i in range(n):\n if a[a[a[i]-1]-1]==i+1: \n c+=1\nprint(\"YES\"if c>=1 else \"NO\") \n", "x=int(input())\r\ns=[int(n)-1 for n in input().split()]\r\n \r\nfor n in range(x):\r\n\tif s[s[s[n]]]==n:\r\n\t\tprint('YES')\r\n\t\texit(0)\r\nprint('NO')", "# LUOGU_RID: 101738624\nn, *a = map(int, open(0).read().split())\r\na = [1] + a\r\nprint(any(a[a[a[x]]] == x for x in a) and 'YES' or 'NO')\r\n", "def main():\r\n has_a_triangle = False\r\n n = int(input())\r\n f = [int(i) - 1 for i in input().split()]\r\n for i in range(n):\r\n if f[f[f[i]]] == i:\r\n has_a_triangle = True\r\n break\r\n if has_a_triangle:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\nmain()", "from collections import deque\r\n\r\n\r\ndef checkTriangle(node: int, planes: list):\r\n '''Limited by 4 jumps'''\r\n\r\n distance = dict()\r\n distance[node] = 0\r\n toVisit = deque()\r\n toVisit.append(node)\r\n counter = 0\r\n \r\n while len(toVisit) > 0 and counter <= 4:\r\n s = toVisit.popleft()\r\n\r\n u = planes[s]\r\n\r\n if u in distance:\r\n if distance[s] - distance[u]== 2:\r\n return True\r\n else:\r\n distance[u] = distance[s] + 1\r\n toVisit.append(u)\r\n counter += 1\r\n return False\r\n\r\n \r\n\r\n\r\nif __name__ == \"__main__\":\r\n\r\n n = int(input())\r\n planes = list(map(int, input().split()))\r\n planes = list(map(lambda x: x -1, planes))\r\n loveTriangleFound = False\r\n\r\n for index, plane in enumerate(planes):\r\n if checkTriangle(index, planes):\r\n loveTriangleFound = True\r\n\r\n if loveTriangleFound:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "n = int(input())\r\ny = list(map(int,input().split()))\r\nfor i in range(n):\r\n if y[y[y[y[i]-1]-1]-1]==y[i]:\r\n print(\"YES\")\r\n break\r\n else:\r\n pass\r\nelse:\r\n print(\"NO\")", "# Karla Mondragón, A01025108\n# Love Triangle - Graphs Theory\n\nn=int(input())\nl=list(map(int,input().split()))\nflag=0\nfor i in range(n):\n first=l[i]\n second=l[first-1]\n third=l[second-1]\n if l[third-1]==first:\n flag=1\n break\nif flag:\n print(\"YES\")\nelse:\n print(\"NO\")\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\nf = list(map(int, input().split()))\r\ncnt = \"NO\"\r\nfor i in range(n):\r\n if f[f[f[i]-1]-1] == i+1:\r\n cnt = \"YES\"\r\nprint(cnt)", "n=int(input())\r\na=list(map(int,input().split()))\r\nprint('YES' if any(a[a[a[i]-1]-1]==i+1 for i in range(n)) else 'NO')", "a = int(input())\r\nb = list(map(int,input().split()))\r\nyes = \"\"\r\nfor i in range(len(b)-1):\r\n a = b[i]\r\n c = b.index(a)+1\r\n d = b[b[i]-1]\r\n e = b[d-1]\r\n if e == c:\r\n yes += \"yes\"\r\n\r\nif \"yes\" in yes:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n", "#Problem 939A from codeforces\n\ndef main():\n n = int(input())\n graph = [int(x) - 1 for x in input().split()]\n visited = [False for x in range(n)]\n lovet_flag = False\n for i in range(n):\n if not lovet_flag:\n if not visited[i]:\n visited[i] = True\n li = [-1, i]\n next_node = graph[i]\n while not visited[next_node]:\n visited[next_node] = True\n if graph[next_node] == li[0]:\n lovet_flag = True\n break\n li = [li[1], next_node]\n next_node = graph[next_node]\n\n if lovet_flag:\n print(\"YES\")\n\n else:\n print(\"NO\")\n\n\nif __name__ == \"__main__\":\n main()\n", "n=int(input())\r\na=list(map(int,input().split()))\r\na.insert(0,0) \r\nflag=0\r\nfor i in range(1,n+1):\r\n if(a[a[a[i]]]==i):\r\n flag=1\r\n print(\"YES\")\r\n break \r\nif(flag==0):\r\n print(\"NO\")", "n=int(input())\r\nf=list(map(int,input().split()))\r\n\r\nflag=0\r\nfor one in range(n):\r\n two=f[one]\r\n one+=1\r\n three=f[two-1]\r\n four=f[three-1]\r\n if((four==one) and (one!=two!=three)):\r\n print(\"YES\")\r\n flag=1\r\n break\r\n \r\nif(flag==0):\r\n print(\"NO\")", "n = int(input())\r\n\r\nA = [0] + list(map(int,input().split()))\r\n\r\ndef LoveTriangle(Arr):\r\n for i in range(1, len(A)):\r\n if A[A[A[i]]] == i:\r\n return \"YES\"\r\n return \"NO\"\r\n\r\nprint(LoveTriangle(A))\r\n\r\n#Vi på fløver i.\r\n#Flyver i kan lide A[i]\r\n#Flyver A[i] kan lide A[A[i]]\r\n#Flyver A[A[i]] kan lide flyver A[A[A[i]]]", "n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nsuccess = False\r\nfor i in range(n):\r\n loved = i\r\n for j in range(3):\r\n loved = arr[loved-1]\r\n if i == loved:\r\n success = True\r\n\r\nif success:\r\n print('YES')\r\nelse:\r\n print('NO')", "n=int(input())\r\ns=[int(i) for i in input().split()]\r\nbl=False\r\nfor index,value in enumerate(s):\r\n a=value\r\n b=s[value-1]\r\n c=s[b-1]\r\n if c-1==index:\r\n bl=True\r\n break\r\n else:\r\n bl=False\r\nif bl:print(\"YES\")\r\nelse:print(\"NO\")", "n = int(input())\r\narr = list(map(int, input().split()))\r\ncount =0\r\nfor i in range(0,n):\r\n a = arr[i]\r\n b = arr[a-1]\r\n c = arr[b-1]\r\n if i == c-1:\r\n print('YES')\r\n break\r\nelse:\r\n print('NO')", "n=int(input())\r\nc=0\r\na=list(map(int,input().split()))\r\nfor x in range(n):\r\n if a[a[a[x]-1]-1]==x+1 and c==0:\r\n print('YES')\r\n c=1\r\nif c==0:\r\n print('NO')", "def love_triangle(n, planes):\n for _ in range(n):\n x = planes[_] - 1\n y = planes[x] - 1\n if planes[y] - 1 == _:\n return \"YES\"\n return \"NO\"\n\nn = int(input())\nplanes = list(map(int, input().split()))\n\nresult = love_triangle(n, planes)\nprint(result)", "n = int(input())\r\narr = list(map(int, input().split()))\r\narr.insert(0, 0)\r\n# print(arr)\r\nb = False\r\nfor i in range(1, len(arr)):\r\n if arr[arr[arr[i]]] == i:\r\n b = True\r\n break\r\nif b:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def rec(v, f, start, path_len=0):\n\tif path_len == 3:\n\t\treturn start == v\n \n\treturn rec(f[v], f, start, path_len+1)\n \ndef solve(f):\n\tfor v in range(len(f)):\n\t\tif rec(v, f, v):\n\t\t\treturn 'YES'\n\t\n\treturn 'NO'\n \ninput()\nf = list(map(lambda x: int(x)-1, input().split()))\nprint(solve(f))\n \t \t \t\t \t\t \t\t\t\t \t", "input()\r\narr = list(map(int, input().split(\" \")))\r\n\r\nfor i in arr:\r\n if i == arr[arr[arr[i - 1] - 1]-1]:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nl = list(map(int,input().split()))\r\nf = False\r\nfor i in range(n):\r\n if l[l[l[i] - 1] - 1] == i + 1:\r\n f = True\r\n break\r\n\r\nprint('YES' if f else 'NO')", "n=int(input())\r\na=list(map(int,input().split()))\r\nans=\"no\"\r\nif n>2:\r\n for i in range(n):\r\n x=a[i]-1\r\n y=a[x]-1\r\n c=a[y]-1\r\n if i==c and y!=i:\r\n ans=\"yes\"\r\n break\r\nprint(ans)", "import bisect\r\nimport collections\r\nimport math\r\n\r\n\r\nn = int(input())\r\nf = [int(x)-1 for x in input().split()]\r\n\r\nfor i in range(n):\r\n if i == f[f[f[i]]]:\r\n print('YES')\r\n break\r\nelse:\r\n print('NO')\r\n\r\n\r\n", "n=int(input())\r\nL=[int(i) for i in input().split()]\r\nindex=0\r\nd={}\r\nfor i in L:\r\n index+=1\r\n d[index]=i \r\nx=1\r\nfor i in d:\r\n if(i==d[d[d[i]]]):\r\n print(\"YES\")\r\n x=0\r\n break \r\nif(x==1):\r\n print(\"NO\")", "# https://codeforces.com/problemset/problem/939/A\n\n# graphs\n\nn = int(input())\narr = list(map(int, input().split()))\nfor i in range(n):\n a = arr[i]\n b = arr[a - 1]\n c = arr[b - 1]\n if c - 1 == i and len(set([a, b, c])) == 3:\n print('YES')\n exit()\nprint('NO')\n", "n, f = int(input()), [int(i) for i in input().split()]\ndef triangle(i):\n return i == f[f[f[i] - 1] - 1] - 1\nres = \"YES\" if any(triangle(i) for i in range(n)) else \"NO\"\nprint(res)\n", "def func(a,n):\r\n for i in range(n):\r\n if(a[a[a[i]]] == i):\r\n return \"YES\"\r\n return \"NO\"\r\nn = int(input())\r\na = list(map(lambda a: a - 1, list(map(int,input().split(\" \")))))\r\nprint(func(a,n))\r\n\r\n", "n=int(input())\r\nf=[0]+list(map(int,input().split()))\r\nfor i in range(1,n):\r\n if f[f[f[i]]]==i:\r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\")", "def main(n,a):\r\n dict={}\r\n for i in range(n):\r\n if i+1 not in dict:\r\n dict[i+1]=a[i]\r\n \r\n for i in range(1,n+1):\r\n if dict[dict[dict[i]]]==i:\r\n return 'YES'\r\n return 'NO'\r\n \r\n \r\nn=int(input())\r\na=list(map(int,input().split()))\r\nprint(main(n,a))", "from collections import deque\nfrom sys import stdin, stdout\n\ninput = stdin.readline\nprint = stdout.write\n\nn = int(input())\nv = list(map(int, input().split(' ')))\ng = [[] for i in range(n+1)]\nfor i in range(0, n):\n g[i+1].append(v[i])\nused = [0]*(n+1)\npr = [0]*(n+1)\nflag = False\ndef dfs(g, used, u, pr):\n used[u]=1\n for to in g[u]:\n if used[to]==0:\n pr[to]=u\n dfs(g, used, to, pr)\n elif used[to]==1:\n if pr[pr[u]]==to:\n global flag\n flag=True\n used[u]=2\nfor i in range(1, n+1):\n if flag:\n break\n else:\n dfs(g, used, i, pr)\nprint('YES' if flag else 'NO')\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nf=0\r\nfor i in range(n):\r\n if(l[i]-1!=i and l[l[l[i]-1]-1]-1==i):\r\n f=1\r\n break\r\nif(f==1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nf = list(map(int, input().split()))\r\nfor i in range(n):\r\n if (i+1) == f[f[f[i]-1]-1]:\r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\")", "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\ta=[0]+read_ints()\n\tfor i in range(1, n+1):\n\t\tif a[a[a[i]]]==i:\n\t\t\tprint(\"YES\")\n\t\t\treturn\n\tprint(\"NO\")\n\nsolve()\n", "n = int(input())\nF = list(map(int, input().split()))\nF = [f-1 for f in F]\nfor a, b in enumerate(F):\n c = F[b]\n if F[c] == a:\n print('YES')\n exit()\nelse:\n print('NO')\n", "n = int(input())\r\ns = list(map(int, input().split()))\r\nfor i in range(n):\r\n if s[s[s[i]-1]-1] == i + 1:\r\n print('YES')\r\n exit()\r\nprint('NO')", "n = int(input())\r\nnl = list(map(int, input().split()))\r\n\r\ndic = {}\r\n\r\nfor i in range(n):\r\n dic[i+1] = nl[i]\r\n\r\n# print(dic)\r\nflag = False\r\nfor i in range(n):\r\n if dic.get(i+1, 0) != 0:\r\n x = dic.get(i+1)\r\n if dic.get(x, 0) != 0:\r\n y = dic.get(x)\r\n if dic.get(y, 0) != 0:\r\n if dic.get(y) == i+1:\r\n print('YES')\r\n flag = True\r\n break\r\n\r\nif not flag:\r\n print('NO')", "n = int(input())\r\na = list(map(int, input().split()))\r\nf = True\r\nfor i in range(n):\r\n if i + 1 == a[a[a[i] - 1]-1]:\r\n print(\"YES\")\r\n f = False\r\n break\r\nif f:print(\"NO\")", "n = int(input())\nm = list(map(int, input().split(\" \")))\na = \"NO\"\nfor i in range(n):\n if m[m[m[m[i] - 1] - 1] - 1] == m[i]:\n a = \"YES\"\nprint(a)\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nans=\"NO\"\r\nfor i in range(n): \r\n if l[l[l[i]-1]-1]-1==i:\r\n ans=\"YES\"\r\n break\r\nprint(ans)", "n = int(input())\r\na = list(map(int, input().split()))\r\ndata = [[] for _ in range(n)]\r\nfor i in range(n): data[i].append(a[i]-1)\r\n\r\nfor i in range(n):\r\n for j in data[i]:\r\n for l in data[j]:\r\n if i in data[l]:\r\n print(\"YES\")\r\n exit(0)\r\nprint(\"NO\")\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\nfor i in range(n):\r\n if a[a[a[a[i]-1]-1]-1] == a[i]:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\ncheck = 0\r\nlstPlanes = list(map(int, input().split()))\r\nlstPlanes = [lstPlanes[i]-1 for i in range(n)]\r\nfor i in range(n):\r\n if lstPlanes[lstPlanes[lstPlanes[i]]] == i: \r\n check = 1\r\nprint(\"YES\" if check else \"NO\")", "n = int(input())\r\nf = list(map(int,input().split()))\r\nf = list(map(lambda x: x - 1,f))\r\nfor i in range(len(f)):\r\n if f[f[f[i]]] == i:\r\n print(\"Yes\")\r\n break \r\nelse:\r\n print(\"No\")", "n = int(input())\r\narr = list(map(int,input().split()))\r\narr = [0]+arr\r\nfor i in range(1,n+1):\r\n if(arr[arr[arr[i]]]==i):\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")\r\n \r\n ", "############################ CUSTOMS ######################\n\nREADY_FOR_SUBMIT = True\n\ndef cust_print(stuff):\n if not READY_FOR_SUBMIT:\n print(stuff)\n else:\n pass\n\n\n############################ SOLUTION ######################\n\n# --- Global vars --- #\noutput = []\n\n\n# --- Algorithm --- #\ndef f(n, f):\n global output\n \n\n for i in range(n):\n e1 = f[i]\n e2 = f[e1 - 1]\n e3 = f[e2 - 1]\n\n p1 = f\"{i + 1} {e1}\"\n p2 = f\"{e1} {e2}\"\n p3 = f\"{e2} {e3}\"\n\n cust_print(\"---\")\n cust_print(f\"p1 : {p1}\")\n cust_print(f\"p2 : {p2}\")\n cust_print(f\"p3 : {p3}\")\n\n trig_set = {p1, p2, p3}\n\n if len(trig_set) == 3 and (i + 1) == e3:\n output.append(\"YES\")\n return\n else:\n pass\n\n output.append(\"NO\")\n\n\n# --- Run --- #\n\n# input and computation\nn = int(input())\nq = list(map(int, input().split()))\n\nf(n, q)\n\n\n# output\ncust_print(\"\\n---- Final output ----\\n\")\nprint(\"\\n\".join(output))", "import sys\r\nimport math\r\n\r\nint_inp = lambda: int(input())\r\nstr_inp = lambda: input().strip()\r\nflt_inp_list = lambda: list(map(float, input().strip().split()))\r\nint_inp_list = lambda: list(map(int, input().strip().split()))\r\nstr_inp_list = lambda: list(input().split())\r\n\r\n# sys.stdin = open(\"input.txt\", \"r\")\r\n\r\nt = int_inp()\r\nn = int_inp_list()\r\n\r\nfound = False\r\n\r\nfor i in range(len(n)):\r\n if n[n[n[i] - 1] - 1] - 1 == i:\r\n found = True\r\n break\r\n\r\nif found:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "\"\"\"\nSummary of Code:\n- checks every 3 pairs for a love triangle\n\nRuntime Complexity:\n- input => O(N)\n- search => O(3 * N)\n- total => O(N + 3N) => O(N)\n\nSpace Complexity:\n- O(N) for graph / relationship\n\nWhy the chosen algorithm work:\n- the runtime are O(N) and N = 5 * 10^3 which is smaller than\n 10^7 \n\"\"\"\nfrom sys import stdin\n\ndef main():\n input = stdin.readline\n n = int(input())\n F = [int(i)-1 for i in input().split()]\n for i in range(n):\n t = i\n for j in range(3):\n t = F[t]\n if t == i:\n print(\"YES\")\n exit()\n print(\"NO\")\n\n\nif __name__ == '__main__':\n main()\n \t\t \t \t\t\t \t\t \t\t\t\t\t \t \t\t\t", "n = int(input())\r\nlis = list(map(int,input().split()))\r\nfor i in range(n):\r\n x = lis[i]\r\n y = lis[x-1]\r\n z = lis[y-1]\r\n if z==i+1:\r\n print('YES')\r\n break\r\nelse:\r\n print('NO')", "n = int(input())\r\nf = list(map(int,input().split()))\r\nb = 1\r\nfor i in range(n):\r\n A = i\r\n B = f[i] - 1\r\n C = f[B] - 1\r\n res = f[C]-1 == A\r\n if res:\r\n print('YES')\r\n b = 0\r\n break\r\nif b:\r\n print('NO')", "\"\"\" @esllam \"\"\"\r\n\r\ndef main():\r\n n = int(fin())\r\n *a, = map(int, fin().split())\r\n graph = dict()\r\n for i in range(n): graph[i+1] = a[i]\r\n for i in graph:\r\n stack = list()\r\n stack.append(i)\r\n stack.append(graph[i])\r\n while len(stack) < 5 and stack[0] != stack[-1]:\r\n if stack[-1] in graph:\r\n stack.append(graph[stack[-1]])\r\n if stack[0] == stack[-1] and len(stack) == 4:\r\n return fout(\"YES\")\r\n fout(\"NO\")\r\n\r\n# FastIO\r\nfrom sys import stdin, stdout\r\ntry: input, output = open(\"input.in\", \"r\"), stdout\r\nexcept: input, output = stdin, stdout\r\ndef fin(): return input.readline().strip(\"\\r\\n\")\r\ndef fout(s): return output.write(str(s)+\"\\n\")\r\nif __name__ == \"__main__\":\r\n t = 1 or int(fin())\r\n for i in range(t): main()\r\n", "n = int(input())\r\nf = [int(i) for i in input().split()]\r\nfor i in range(n):\r\n if f[f[f[i] - 1]-1] == i+1:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\nnumber = [0]\ntemp = [int(x) for x in input().split(' ')]\nnumber.extend(temp)\ncheck = []\nfor i in range(1, n+1):\n if i not in check:\n j = number[i]\n k = number[j]\n if number[k] == i:\n print(\"YES\")\n break\n check.append(i)\n check.append(j)\n check.append(k)\n else:\n continue\nelse:\n print(\"NO\")\n \t \t \t\t \t \t \t \t", "import sys\nl = sys.stdin.readlines()\n\nn = int(l[0].replace('\\n',''))\nf = [int(x) for x in l[1].replace('\\n','').split()]\n\nfor i in range(n):\n if f[f[f[i]-1]-1]-1 == i:\n print('YES')\n exit()\nprint('NO')\n\n \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\nfor i in range(0,N):\r\n L[i]=L[i]-1\r\nflag=True\r\nfor i in range(0,N):\r\n a=L[i]\r\n b=L[a]\r\n c=L[b]\r\n if c==i:\r\n print(\"YES\")\r\n flag=False\r\n break\r\nif flag==True:\r\n print(\"NO\")", "\r\nimport sys\r\n\r\n\r\n# sys.stdin = open(\"input01.txt\")\r\n\r\n\r\ndef input():\r\n return sys.stdin.readline().strip('\\r\\n')\r\n\r\n\r\ndef print_arr(arr):\r\n sys.stdout.write(\"\\n\".join(map(str, arr)) + '\\n')\r\n\r\n\r\ndef print_matrix(matrix):\r\n strings = []\r\n for arr in matrix:\r\n strings.append(\"\".join(map(str, arr)))\r\n print_arr(strings)\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n planes = [*map(lambda x: int(x) - 1, input().split())]\r\n visited = [False] * n\r\n for i in range(n):\r\n if not visited[i]:\r\n count = 0\r\n current = i\r\n while count < 4:\r\n visited[current] = True\r\n current = planes[current]\r\n count += 1\r\n\r\n if planes[i] == current:\r\n print(\"YES\")\r\n return\r\n\r\n print(\"NO\")\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\no=0\r\nfor i in range(n):\r\n\tif a[a[a[i]-1]-1]==i+1:\r\n\t\tprint('YES')\r\n\t\to=1\r\n\t\tbreak\r\nif o==0:\r\n\tprint('NO')", "n = int(input())\r\nline = input()\r\nplanes = [int(x) for x in line.split()]\r\n\r\n\r\ndef love_triangle(planes):\r\n tuple_planes = [(i+1, n) for i,n in enumerate(planes)]\r\n\r\n for lover, loved in tuple_planes:\r\n first = (lover, loved)\r\n second = tuple_planes[loved-1]\r\n third = tuple_planes[second[-1]-1]\r\n # don't need to check first and second because we effectively are by following the triangle\r\n if third[-1] == first[0]:\r\n return True\r\n return False\r\n\r\nb = love_triangle(planes)\r\nif (b):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "input();f=[*map(int,input().split())];con=True\r\nfor i in f:\r\n if f[f[f[i-1]-1]-1]==i:print('YES');con=False;break\r\nif con:print('NO')", "n = int(input())\na = [0] + list(map(int, input().split()))\nb = [0] * (n + 1)\n\nfor i in range(1, n + 1):\n count = 1\n c = [False] * (n + 1)\n c[i] = True\n k = a[i]\n while c[k] == False:\n c[k] = True\n count += 1\n k = a[k]\n if count == 3 and k == i:\n print(\"YES\")\n exit(0)\n\nprint(\"NO\")", "def buildGraph(noPlanes, planesArray):\n if noPlanes < 3:\n return False\n for i in range(1, noPlanes):\n a = planesArray[i - 1]\n b = planesArray[a - 1]\n c = planesArray[b - 1]\n if c == i:\n return True\n return False\n\n\ndef main():\n noPlanes = int(input())\n planesArray = [int(x) for x in input().split()]\n print(\"YES\" if buildGraph(noPlanes, planesArray) else \"NO\")\n\n\nmain()\n \t \t\t \t \t \t \t \t\t\t \t \t", "import sys\ninput = sys.stdin.readline\n\nL = int(input())\nF = [0] + list(map(int, input().split()))\n\nfor i in range(1, L+1) :\n TA = i\n TB = F[TA]\n TC = F[TB]\n TD = F[TC]\n if TA != TB != TC and TD == TA :\n print(\"YES\")\n exit(0)\nprint(\"NO\")\n", "n = int(input())\ncons = [int(x) for x in input().split()]\n\ngraph = {}\n\nfor i in range(len(cons)):\n graph[i+1] = cons[i]\n\ntriangle = False\n\nfor node in graph:\n a = graph[node]\n b = graph[a]\n\n if node == graph[b] and node != a:\n triangle = True; break\n\nif triangle:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "n = int(input())\r\na = [int(i) for i in input().split()]\r\nbb = False\r\nfor i in range(n):\r\n if a[a[a[i]-1]-1]==i+1:\r\n bb = True\r\nif bb:\r\n print('YES')\r\nelse:\r\n print('NO')", "def _input(): return list(map(int, input().split()))\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n f = _input()\r\n for i in range(n):\r\n a = i\r\n b = f[a - 1]\r\n c = f[b - 1]\r\n if f[c - 1] == a and a != b != c: return 'YES'\r\n return 'NO'\r\n\r\n\r\nif __name__ == '__main__':\r\n print(main())\r\n", "n=int(input())\r\nf=[1,*map(int,input().split())]\r\nprint('YNEOS'[all(f[f[f[x]]]!=x for x in f)::2])", "z = int(input())\r\nl = list(map(int,input().split()))\r\nfor i in range(z):\r\n\tif i == l[l[l[i]-1]-1]-1:\r\n\t\tprint('YES')\r\n\t\tbreak\r\nelse:\r\n\tprint('NO')", "n = int(input())\narr = list(map(int, input().split()))\nans = \"NO\"\nfor i in range(n):\n res = arr[arr[arr[arr[i]-1]-1]-1]\n if res == arr[i]:\n ans = \"YES\"\n break\n\nprint(ans)\n", "# Tonatiuh\ndef triangle(array):\n initial = 0\n mid = 0\n final = 0\n while initial != len(array) - 1:\n mid = array[initial] -1\n final = array[mid] -1\n if array[final] - 1== initial:\n return \"YES\"\n initial += 1\n return \"NO\"\n\n# num planes\nn = int(input())\n# planes affection array\narray = list(map(int, input().strip().split()))[:n]\n\nprint(triangle(array))\n\t \t \t\t\t \t \t\t\t\t \t \t\t\t \t \t", "import sys\r\n \r\ndef get_int():\r\n return int(sys.stdin.readline().strip())\r\n \r\ndef get_ints():\r\n return map(int,sys.stdin.readline().strip().split())\r\n \r\ndef get_list():\r\n return list(map(int,sys.stdin.readline().strip().split()))\r\n \r\ndef get_string():\r\n return sys.stdin.readline().strip()\r\n\r\n\r\nn = get_int()\r\n\r\na = get_list()\r\n\r\ngraph = [a[i]-1 for i in range(n)]\r\n\r\nfor i in range(n):\r\n if graph[graph[graph[i]]]==i:\r\n print(\"YES\")\r\n exit()\r\n\r\nprint(\"NO\")\r\n", "# find parent\r\ndef solve(n, arr):\r\n\tfor i in range(n):\r\n\t\tif arr[arr[arr[i] - 1]-1] == i+1:\r\n\t\t\treturn 'YES'\r\n\treturn 'NO'\r\n\t\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\nprint(solve(n,arr))", "# Love Triangle(939A)\r\nn = int(input())\r\nnlist = list(map(int, input().split()))\r\nfor i in range(len(nlist)):\r\n if nlist[nlist[nlist[i-1]-1]-1] == i:\r\n out = \"YES\"\r\n break\r\n else:\r\n out = \"NO\"\r\n\r\nprint(out)\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\ns=False\r\nfor i in range(n):\r\n if a[a[a[i]-1]-1]==i+1:\r\n s=True\r\nif s :\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n_planes = int(input())\nlist_planes = list(map(int, input().split()))\nfor i in range(n_planes):\n if list_planes[list_planes[list_planes[i] - 1] - 1] == i + 1:\n print(\"YES\")\n break\nelse:\n print(\"NO\")\n \t\t \t\t \t\t \t\t\t \t \t\t", "cantidad_planos = int(input())\nplanos = list(map(int, input().split()))\nfor i in range(cantidad_planos):\n if planos[planos[planos[i] - 1] - 1] == i + 1:\n print(\"YES\")\n break\nelse:\n print(\"NO\")\n\n \t\t \t \t \t\t\t \t\t \t\t \t", "if __name__ == \"__main__\":\r\n n = int (input ())\r\n\r\n arr = list (map (int, input ().split ()))\r\n\r\n b = 0\r\n\r\n for i in range (n):\r\n arr[i] -= 1\r\n\r\n for i in range (n):\r\n if arr[arr[arr[i]]] == i:\r\n b = 1\r\n break\r\n\r\n if b:\r\n print (\"YES\", end = \"\")\r\n else:\r\n print (\"NO\", end = \"\")", "n = int(input())\r\n\r\nint_minus1 = lambda s: int(s) - 1\r\nfavourites = list(map(int_minus1, input().split()))\r\n\r\ndef check_triangles(favs):\r\n for i, fav in enumerate(favs):\r\n if favs[favs[fav]] == i:\r\n return True\r\n\r\n return False\r\n\r\nif check_triangles(favourites):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\na=list(map(int,input().split(' ')))\r\n\r\nfor i in range(n):\r\n a[i]-=1\r\n\r\n\r\n\r\nfor j in range(n):\r\n scnd=a[j]\r\n third=a[scnd]\r\n if a[third]==j:\r\n print('Yes')\r\n exit()\r\n\r\nprint('No')", "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 = [int(i)-1 for i in input().split()]\r\nflag = 0\r\nfor i in range (n):\r\n x = i\r\n y = a[i]\r\n z = a[y]\r\n zz = a[z]\r\n if x == zz:\r\n print(\"YES\")\r\n flag = 1\r\n break\r\nif flag == 0:\r\n print(\"NO\")", "#!/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 = int(wtf[0])\r\n F = list(map(int, wtf[1].split()))\r\n f = False\r\n for i in range(n):\r\n if F[F[F[i]-1]-1]-1 == i:\r\n f = True\r\n break\r\n print('YES' if f else 'NO')\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\nstatus = 0\r\nfor i in range(n):\r\n\tif i+1==a[a[a[i]-1]-1]:\r\n\t\tprint(\"YES\")\r\n\t\tstatus = 1\r\n\t\tbreak\r\nif status==0:\r\n\tprint(\"NO\")", "n = int(input())\r\nlikes = list(map(int, input().split()))\r\n\r\nfor i in range(n): \r\n b = likes[i] - 1 \r\n c = likes[b] - 1 \r\n\r\n if likes[c] - 1 == i: \r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")\r\n", "\"\"\"\nLove Triangle\nhttps://codeforces.com/contest/939/problem/A\n\"\"\"\n\nn = int(input())\nf = [int(x) for x in input().split()]\n\n\nvisited = set()\nfor i in range(n):\n if i in visited:\n continue\n visited.add(i)\n \n cycle = {}\n j = i\n idx = 0\n while j not in cycle:\n cycle[j] = idx\n visited.add(j)\n j = f[j] - 1\n idx += 1\n if idx - cycle[j] == 3:\n print('YES')\n break\nelse:\n print('NO')\n", "n = int(input())\r\na = list(map(int, input().split()))\r\nk = 0\r\nind = []\r\nfor i in range(n):\r\n ind.append(i+1)\r\nfor i in range(n):\r\n if a[ind[a[ind[a[i]-1]-1]-1]-1] == i+1:\r\n k = k + 1\r\nif k > 0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nl = ([int(x) for x in input().split()])\r\nans=\"NO\"\r\nfor i in l:\r\n if i<=n-1:\r\n if(l[i-1]<=n and l[i-1]!=i):\r\n if(l[l[i-1]-1]<=n and l[l[i-1]-1]!=l[i-1] and l[l[l[i-1]-1]-1]==i):\r\n ans=\"YES\"\r\nprint(ans)\r\n ", "n=int(input())\r\na=[0,*map(int,input().split())]\r\nt=0\r\nfor i in range(1,n):\r\n if a[a[a[i]]]==i:\r\n t=1\r\nif t==1:\r\n print(\"YES\")\r\nelse: print(\"NO\")", "n = int(input())\r\nfly = input().split()\r\n\r\nfor x in range(len(fly)):\r\n fly[x] = int(fly[x])\r\n\r\nc = 0\r\n\r\nfor i in range(len(fly)):\r\n if(fly[fly[fly[i] - 1] - 1] == i + 1):\r\n print(\"YES\")\r\n c = 1\r\n break\r\nif(c == 0):\r\n print(\"NO\")", "n=int(input())\r\np=list(map(int,input().split()))\r\nif len(p)<=2:\r\n print(\"NO\")\r\nelse:\r\n\r\n for i in range(0,len(p)):\r\n first=p[i]\r\n second=p[first-1]\r\n third=p[second-1]\r\n if p[first-1]==second and p[second-1]==third and p[third-1]==first:\r\n print(\"YES\")\r\n break\r\n else:\r\n continue\r\n else:\r\n print(\"NO\")", "n=int(input())\r\n*a,=map(int,input().split())\r\nx=1\r\nfor i in range(n):\r\n if a[a[a[i]-1]-1]-1==i:x=0\r\nprint(\"YNEOS\"[x::2])", "def cycle_detect(mat,x,v,re):\r\n v[x] = 1\r\n re[x] = 1\r\n # print(x)\r\n if v[mat[x]] == 0:\r\n if cycle_detect(mat,mat[x],v,re) == 1:\r\n # print(x,mat[x])\r\n if x != mat[mat[x]]:\r\n return 1\r\n # print(x,mat[mat[x]])\r\n if re[mat[x]] == 1 and x != mat[mat[x]] and mat[mat[mat[x]]] == x:\r\n # print(\"hi\")\r\n return 1\r\n return 0\r\ndef iscyclic(mat):\r\n n = len(mat)\r\n v = [0 for i in range(n)]\r\n re = [0 for i in range(n)]\r\n for i in range(0,n):\r\n if v[i] == 0:\r\n if cycle_detect(mat,i,v,re) == 1:\r\n # print(i)\r\n return 1\r\n return 0\r\nn = int(input())\r\nmat = {}\r\na = [int(j) for j in str(input()).split(' ')]\r\nfor i in range(0,len(a)):\r\n mat[i] = a[i]-1\r\nd = iscyclic(mat)\r\nif d == 1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\ndata = input()\r\ndata = data.split()\r\nfor i in range(len(data)):\r\n data[i] = int(data[i])\r\n\r\nis_triangle = False\r\nfor i in range(len(data)):\r\n next_1 = data[i] - 1\r\n \"\"\"data[data[i] - 1] - 1\"\"\"\r\n next_2 = data[next_1] - 1 \r\n \"\"\"data[data[data[i] -1] -1] -1\"\"\"\r\n next_3 = data[next_2] - 1\r\n if i == next_3:\r\n is_triangle = True\r\nif is_triangle == True:\r\n print('YES')\r\nelse:\r\n print('NO')", "while True:\r\n try:\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n except:\r\n break\r\n \r\n my_set = set(arr)\r\n\r\n if len(my_set) < 3:\r\n print(\"NO\")\r\n else:\r\n k = False\r\n for i in range(n):\r\n a = arr[i]\r\n b = arr[a-1]\r\n c = arr[b-1]\r\n if a != b and b != c and c != a and arr[c-1] == a:\r\n k = True\r\n print(\"YES\")\r\n break\r\n if not k:\r\n print(\"NO\")\r\n", "n = int(input(\"\"))\nA = list(map(int, input(\"\").split(\" \")))\nfound_path = False\n\nfor i in range(len(A)):\n next_step = A[i]\n next_next_step = A[next_step - 1]\n if (A[next_next_step - 1] - 1 == i):\n found_path = True\n break\n\nif found_path == True:\n print(\"YES\")\nelse: print(\"NO\")\n\t \t \t \t\t \t \t \t\t \t\t\t \t\t", "# Happy new year 2023 :)\r\n\r\nn = int(input())\r\nf = [int(x) for x in input().split()]\r\nf.insert(0, -1)\r\nfor i in range(1, n+1):\r\n if f[f[f[i]]] == i:\r\n print(\"yes\")\r\n break\r\nelse:\r\n print(\"no\")", "n = int(input())\nlist1 = list(map(int, input().split()))\np = 0\nfor i in range(n):\n if list1[list1[list1[i] - 1]-1]-1== i:\n if i == list1[list1[i] - 1]-1 or list1[i] - 1 == list1[list1[list1[i] - 1] - 1]-1:\n p = 0\n else:\n p = 1\n print('YES')\n break\nif p == 0:\n print('NO')\n\t\t\t\t \t \t \t \t\t \t \t\t\t \t\t \t\t", "n = int(input())\r\n\r\nnums = list(map(int, input().split()))\r\n\r\nres = \"NO\"\r\nfor num in nums:\r\n if nums[nums[nums[num - 1] -1] - 1] == num:\r\n res = \"YES\"\r\n break\r\nprint(res)\r\n", "n = int(input())\r\nsList = list(map(int,input().split()))\r\ndef triangle(n,sList):\r\n value = 0\r\n for i in sList:\r\n i = int(i)\r\n if sList[sList[sList[i-1]-1]-1] == i:\r\n value = 1\r\n break\r\n if value == 1:\r\n return \"YES\"\r\n else:\r\n return \"NO\"\r\nprint(triangle(n,sList))", "N = int(input())\r\nvalues = []\r\nfor i in input().split():\r\n values.append(int(i))\r\nc = 0\r\nfor i in range(N):\r\n if values[values[values[i]-1]-1]-1 == i:\r\n c = 1\r\nif c:\r\n print(\"yes\")\r\nelse:\r\n print(\"no\")", "def love_triangle():\n n = int(input())\n dict_love = {count+1 : i for count,i in enumerate(map(int, input().split()))}\n for love in dict_love:\n if(love == dict_love[dict_love[dict_love[love]]]):\n print('YES')\n return\n print('NO')\n\nlove_triangle()\n\n\n\t \t\t \t\t\t\t\t\t \t \t\t\t\t\t\t\t\t\t \t \t\t", "from collections import defaultdict, deque\r\nnumber_of_planes = int(input())\r\nplanes = [int(x) for x in input().split()]\r\n\r\nfound = False\r\n\r\nfor index, plane in enumerate(planes):\r\n a = int(plane)\r\n b = planes[a - 1]\r\n c = planes[b - 1]\r\n\r\n if a == planes[c - 1]:\r\n found = True\r\n\r\nprint(\"YES\" if found else \"NO\")\r\n", "n= int(input())\r\na= list(map(int,input().split()))\r\nc=0\r\nfor i in range(n):\r\n if i==a[a[a[i-1]-1]-1]:\r\n print(\"YES\")\r\n c=1\r\n break\r\nif c==0:\r\n print(\"NO\")", "def planes():\n \n n = int(input())\n\n love = False\n \n input_string = input()\n list = input_string.split()\n plane= [int(i) for i in list]\n plane = [plane[i]-1 for i in range(n)]\n \n for i in range(n):\n if (plane[plane[plane[i]]] == i): \n love = True\n \n if (love):\n print(\"Yes\")\n\n else:\n print(\"No\")\n\n\n\nplanes()\n \t \t \t \t \t \t \t\t \t \t\t\t\t \t \t\t", "def solve():\r\n n = int(input())\r\n li = list(map(int, input().split()))\r\n new = {}\r\n for i in range(n):\r\n if li[i] == li[li[li[li[i]-1]-1]-1]:\r\n print(\"YES\")\r\n return\r\n print(\"NO\")\r\n\r\n\r\nif __name__== \"__main__\":\r\n solve()", "from sys import stdin\r\n\r\ndef solve():\r\n a = int(stdin.readline())\r\n\r\n planes = list(map(int, stdin.readline().split()))\r\n\r\n for i in range(a):\r\n b = i + 1\r\n c = planes[i]\r\n d = planes[c - 1]\r\n\r\n if planes[d - 1] == b:\r\n print(\"YES\")\r\n return\r\n\r\n print(\"NO\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n solve()", "#\n# Joseph Matsushita\n# Problem C\n#\n# Time Complexity:\n# This program has a time complexity of O(n). It puts the input into a list\n# which takes O(n) time, and it runs a for loop that runs in O(n) time.\n#\n# Space Complexity:\n# This program requires O(n) space, to hold the list of who likes who.\n#\n# Argument:\n# It's probably possible to speed up the algorithm, but it does need to check\n# every node, so it won't be better than O(n). As it is, this is a quick way\n# to find a solution. Also note that this algorithm only really works for\n# love triangles: if it was looking for cycles bigger than 3, the algorithm\n# would run into issues (for example, if it was looking for a cycle of 4 nodes,\n# it could mistake two planes that like each other for a cycle.)\n#\n\nn = int(input())\n\nlikes = list(map(int, input().split()))\n\ntriangle = False\nfor i in range(n):\n if likes[likes[likes[i]-1]-1]-1 == i:\n triangle = True\n break\n\nif triangle:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t \t \t \t \t \t\t\t\t \t \t\t\t \t \t", "from sys import stdin\nfrom collections import deque,Counter,defaultdict\nimport sys\nimport math,os\nimport operator\nimport random\nfrom fractions import Fraction\nimport functools\nimport bisect\nimport itertools\nfrom heapq import *\nimport time\nimport random\nimport bisect\n\n\nn = int(input())\narr = list(map(int,input().split()))\nd = {i+1:None for i in range(10)}\nfor i in range(1,n+1):\n d[i] = arr[i-1]\nfor i in range(1,n+1):\n if d[d[d[i]]] == i:\n print(\"YES\")\n sys.exit()\nprint(\"NO\")\n\n\n\n\n\n\n'''\ndef su(a,b):\n tree = [39,22,17,13,9,9,8,5,8,6,3,2,7,2,6]\n n = 7\n a+=n\n b+=n\n s = 0\n while a<=b:\n if a%2 == 1:\n s+=tree[a]\n a+=1\n if b%2 == 0:\n s+=tree[b]\n b-=1\n a//=2\n b//=2\n return s\n\nprint(su(1,2))\n'''\n", "n = int(input())\r\nf = [int(x) for x in input().split()]\r\n\r\ni = 0\r\nwhile i < n:\r\n if f[f[f[i - 1] - 1] - 1] == i:\r\n print(\"YES\")\r\n exit(0)\r\n\r\n i += 1\r\n\r\nprint(\"NO\")", "n = int(input())\nplane = [int(i) for i in input().split()]\n\ndef loveTriangle():\n for i in range(n):\n if(i == plane[plane[plane[i]-1]-1]-1):\n return True\n return False\n\nif(loveTriangle()):\n print(\"YES\")\nelse:\n print(\"NO\")\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\nd = {}\r\nfor i in range(n):\r\n d[i+1] = a[i]\r\nf = 0\r\nfor i in range(n):\r\n # print(a[i], d[a[i]], d[d[a[i]]])\r\n if i+1 == d[d[a[i]]]:\r\n print(\"YES\")\r\n f = 1\r\n break\r\nif not f: print(\"NO\")", "def F(a: dict) -> bool:\r\n for i in a.keys():\r\n if a[a[a[i]]] == i:\r\n return True\r\n return False\r\n\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n a: list = list(map(int, input().strip().split()))\r\n d: dict = dict()\r\n for i in range(1, len(a) + 1):\r\n d[i] = a[i - 1]\r\n if F(d):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "# ALLAH IS THE GREATEST.\r\nF = int(input())\r\nn = list(map(int,input().split()))\r\n\r\nfor i in n:\r\n a = n[i-1]\r\n b = n[a-1]\r\n c = n[b-1]\r\n if c == i:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")\r\n", "def main():\r\n n = int(input())\r\n arr = list(map(int,input().split()))\r\n for i in range(n):\r\n if(arr[arr[arr[i]-1]-1]-1==i):\r\n print('Yes')\r\n return\r\n print('NO')\r\nmain()", "n=int(input())\r\nl=[1]+[int(x) for x in input().split()]\r\nflag=0\r\nfor i in range(1,n):\r\n if l[l[l[i]]]==i:\r\n flag=1\r\n break\r\nif(flag==1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\nl=list(map(int,input().split()))\r\nfor i in range(len(l)):\r\n if l[l[l[i]-1]-1]==i+1:\r\n print(\"YES\")\r\n break\r\nelse: print(\"NO\")", "import sys\n\ndef input_lines():\n\treturn list(map(str.strip, sys.stdin.readlines()))\n\ndef line_to_int_arr(line):\n\treturn list(map(int, line.split(\" \")))\n\ndef print_arr(arr):\n\tfor el in arr:\n\t\tprint(el, end= ' ')\n\tprint()\n\t\nlines = input_lines()\nn = int(lines[0])\narr = line_to_int_arr(lines[1])\n\nfor i in range(n):\n\tif arr[arr[arr[i] - 1] - 1] == i + 1:\n\t\tprint(\"YES\")\n\t\tbreak\nelse:\n\tprint(\"NO\")\n\t \t \t\t\t\t \t\t\t \t \t\t \t \t \t\t", "n = int(input())\r\nf = [1] + list(map(int,input().split()))\r\nfor i in range(1,n+1):\r\n if f[f[f[i]]] == i: \r\n print('Yes')\r\n break\r\nelse: print('No')", "n, f = int(input()), list(map(int, input().split()))\r\nprint('YES' if any(f[f[f[i] - 1] - 1] == i + 1 for i in range(n)) else 'NO')", "n = int(input())\r\n \r\nplanes = [0] + [int(x) for x in input().split()] + [0]\r\n\r\nprint(\"YES\") if sum([1 if planes[planes[planes[i]]]==i and planes[i]!=i else 0 for i in range(len(planes))]) >=3 else print(\"NO\")\r\n\r\n\r\n\r\n\r\n", "# цикл + счетчик 3\nn = int(input())\narr = list(map(int, input().split()))\narr.insert(0,0)\n\nactive = [False]*(n+1)\ntrio = False\n\nfor i in range(1, n+1):\n tmp = set()\n cur = i\n while cur not in tmp:\n tmp.add(cur)\n cur = arr[cur]\n if len(tmp) == 3 and i == cur:\n trio = True\n\nprint('YES' if trio else 'NO')\n \t\t\t \t \t\t\t\t \t\t\t\t\t \t\t \t \t", "\r\na = int(input())\r\nb = list(map(int,input().split()))\r\nc = []\r\nfor i in b:\r\n if b[b[b[i-1]-1]-1]==i:\r\n c.append(\"YES\")\r\nc.append(\"NO\")\r\n\r\nprint(c[0])", "def res():\n n = int(input())\n planes = list(map(int, input().strip().split()))[:n]\n for i in range(n):\n a = planes[i]\n b = planes[a-1]\n c = planes[b-1]\n if c == i+1:\n print(\"YES\")\n break\n\n else:\n print(\"NO\")\n\nres()\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\nL=list(map(int,input().split()))\r\n#print(L[0],L[L[L[L[0]-1]-1]-1])\r\nflage=0\r\nfor i in range(n):\r\n if L[i]==L[L[L[L[i]-1]-1]-1]:\r\n flage=1\r\n break\r\nif flage==1:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n \r\n", "n = int(input())\nplanes = dict(enumerate([int(i) for i in input().split()], start=1))\n\nfor p in planes:\n if planes[p] != p and planes[planes[planes[p]]] == p: \n print('YES')\n break\nelse:\n print('NO')\n \t \t \t \t\t\t \t\t \t\t\t \t\t\t \t", "n = int(input())\r\nnodes = list(map(int,input().split()))\r\ntriangle_found = 0\r\nfor i in range(len(nodes)):\r\n if nodes[nodes[nodes[i]-1]-1]-1 == i:\r\n triangle_found = 1\r\nif triangle_found:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "N = int(input())\r\n\r\nmatrix = []\r\nfor i in range(N):\r\n matrix.append([])\r\nvalues = []\r\nfor i in input().split():\r\n values.append(int(i))\r\n\r\nc = 0\r\n\r\nfor i in range(N):\r\n if values[values[values[i]-1]-1]-1 == i:\r\n c = 1\r\nif c:\r\n print(\"yes\")\r\nelse:\r\n print(\"no\")\r\n#\r\n# for i in range(N):\r\n# for j in values:\r\n# if i+1 == j:\r\n# matrix[i].append(1)\r\n# continue\r\n# matrix[i].append(0)\r\n#\r\n# for i in matrix:\r\n# print(i)\r\n#", "n = int(input())\n\nplanes = [int(x) for x in input().split(\" \")]\n\nfor i in range(len(planes)):\n if(planes[planes[planes[i]-1]-1] == i+1):\n print(\"YES\")\n exit()\nprint(\"NO\")\n\n\t\t \t \t \t \t \t\t\t \t\t \t", "def find_love_triangle(n, likes):\r\n likes = [i - 1 for i in likes] # Adjust to 0-based indexing\r\n \r\n for i in range(n):\r\n a = i\r\n b = likes[i]\r\n c = likes[b]\r\n \r\n if likes[c] == a:\r\n return \"YES\"\r\n \r\n return \"NO\"\r\n\r\n# Input\r\nn = int(input())\r\nlikes = list(map(int, input().split()))\r\n\r\n# Output\r\nresult = find_love_triangle(n, likes)\r\nprint(result)", "# problem Name : Love Triangle\r\n# problem Link : https://codeforces.com/problemset/problem/939/A\r\n# Input Operation\r\nimport sys\r\nn=int(sys.stdin.readline())\r\na=list(map(int,sys.stdin.readline().split()))\r\n# input Operation End\r\n# Solution Start\r\nout=0\r\nfor i in range(n):\r\n if a[a[a[i-1]-1]-1]==i:\r\n out=1\r\n break\r\nprint(\"YES\") if out==1 else print(\"NO\")\r\n", "# Emiliano Cabrera Ruiz\n\ndef checkTriangle(planes):\n for i in range(1,len(planes)):\n if(planes[planes[planes[i]]] == i):\n return \"YES\"\n\n return \"NO\"\n\ndef main():\n input()\n planes = list(map(int,input().split(\" \")))\n planes.insert(0,0)\n print(checkTriangle(planes))\n\nmain()\n \t \t\t \t \t\t \t\t \t \t\t \t\t\t\t\t \t\t", "n = int(input())\r\nplanes = list(map(int, input().split()))\r\n\r\ndef has_love_triangle():\r\n for i in range(n):\r\n a = i + 1\r\n b = planes[a - 1]\r\n c = planes[b - 1]\r\n if planes[c - 1] == a:\r\n return True\r\n return False\r\n\r\nif has_love_triangle():\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "\r\nn = int(input())\r\nf = list (map(int, input().split(' ')))\r\nf = [fi-1 for fi in f]\r\nexit_loop = False\r\n\r\nfor i,fi in enumerate (f):\r\n fj = f[fi] \r\n if fj != i and f[fj]==i:\r\n print ('YES')\r\n exit_loop=True\r\n break\r\n \r\nif not exit_loop:\r\n print ('NO')\r\n ", "inpt = int(input())\r\na = list(map(int, input().split()))\r\nb = ''\r\nfor i in range(inpt):\r\n if (i+1) == a[a[a[i]-1]-1]:\r\n b += 'YES'\r\n break\r\nif 'YES' in b:\r\n print('YES')\r\nelse:\r\n print('NO')", "a = int(input())\r\ns = [int(x)-1 for x in input().split()]\r\nlinks = {}\r\nfor i in range (len(s)):\r\n links[i]= s[i]\r\ndef check(links, i=0):\r\n checker = True\r\n for i in range (len(links)):\r\n if links[links[links[i]]] == i and links[i] != i:\r\n checker = False\r\n if checker == False:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\ncheck(links)\r\n", "n=int(input())\r\nm={i+1:j for i,j in enumerate(input().split(' '))}\r\ndef jopa(penis, govno):\r\n govno1 = penis[govno]\r\n govno2 = penis[int(govno1)]\r\n if int(penis[int(govno2)]) == int(govno):\r\n return 1\r\n else:\r\n return 0\r\nflag=0\r\nfor i in range(1,n+1):\r\n if jopa(m,i):\r\n flag=1\r\n break\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\nf=list(map(int,input().split()))\r\nans='NO'\r\nfor i in range(n):\r\n x=f[i]-1\r\n y=f[x]-1\r\n if f[y]==i+1:\r\n ans='YES'\r\n break\r\nprint(ans)", "aviones = int(input())\nlikes = input().split(\" \")\nsolved = False\nfor i in range(0, len(likes)):\n inicio = i\n actual = i\n for _ in range(0,3):\n actual = int(likes[actual]) - 1\n if actual == inicio:\n solved = True\n print(\"YES\")\n break\nif not solved:\n print(\"NO\")\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\nm = [[0] * n for i in range(n)]\r\nfor i in range(n):\r\n\tm[i][a[i] - 1] = 1\r\n\r\nfor i in range(n):\r\n\tfor j in range(n):\r\n\t\tif m[i][j] == 1 and i != j:\r\n\t\t\tfor x in range(len(m[j])):\r\n\t\t\t\tif m[j][x] == 1 and x != i:\r\n\t\t\t\t\tfor qq in range(n):\r\n\t\t\t\t\t\tif m[x][qq] == 1 and qq == i:\r\n\t\t\t\t\t\t\tprint('YES')\r\n\t\t\t\t\t\t\tquit()\r\n\r\nprint('NO')\r\n\r\n\r\n", "n = int(input()) \r\nf = list(map(int,input().split())) \r\nflag = 0 \r\nfor each in range (1,n+1):\r\n A = f[each-1] \r\n B = f[A-1] \r\n C = f[B-1] \r\n if( each == C ):\r\n flag=1 \r\n break\r\nif(flag==0):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\") \r\n ", "n = input()\r\nplanes = input().split()\r\nplanes = [int(m) for m in planes]\r\nc,v = 0,0\r\nfor ii in planes:\r\n c += 1\r\n t = planes[ii - 1] \r\n if planes[t - 1] == c:\r\n print('YES')\r\n v = 1\r\n break\r\nif v != 1:\r\n print(\"NO\")\r\n", "def has_love_triangle(n, planes):\r\n for i in range(n):\r\n a = i\r\n b = planes[i] - 1 # Subtract 1 to match 0-based indexing\r\n c = planes[b] - 1\r\n\r\n if planes[c] - 1 == a:\r\n return \"YES\"\r\n\r\n return \"NO\"\r\n\r\nap = int(input())\r\nred = list(map(int, input().split()))\r\n\r\nresult = has_love_triangle(ap, red)\r\nprint(result)\r\n", "def love_triangle(connections):\n for i in range(len(connections)):\n if connections[connections[connections[i-1]-1]-1] == i:\n print(\"YES\")\n return\n \n print(\"NO\")\n\nn = int(input())\nconnections = list(map(int, input().split()))\nlove_triangle(connections)\n\n\t\t \t\t\t\t \t \t \t\t \t \t \t\t\t\t \t \t", "def checker(arr, index, checkfor, depth=1):\r\n index -= 1\r\n if depth == 3:\r\n return arr[index] == checkfor\r\n else:\r\n return checker(arr, arr[index], checkfor, depth+1)\r\n\r\ninput()\r\ninp = input()\r\n# inp = \"2 4 5 1 3\"\r\narr = [int(e) for e in inp.split()]\r\n\r\nexists = False\r\nfor e in arr:\r\n if checker(arr, e, e):\r\n exists = True\r\nif exists:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\na='No'\r\ns = input()\r\nair = s.split()\r\nfor i in range(0,n):\r\n if int(air[int(air[int(air[i])-1])-1])==i+1:\r\n a = 'Yes'\r\n break\r\nprint(a)", "def planes():\n\n n = int(input())\n\n in_string = input()\n list = in_string.split()\n plane = [int(i) for i in list]\n\n plane = [plane[i] - 1 for i in range(n)]\n\n amor_real = False\n\n for i in range(n):\n if (plane[plane[plane[i]]] == i):\n amor_real = True\n\n if (amor_real):\n print(\"Yes\")\n\n else:\n print(\"No\")\n\n\nplanes()\n \t\t \t\t \t \t\t\t \t\t \t \t \t\t \t\t", "n = int(input())\nplanes = list(map(int, input().split()))\n\ndef has_love_triangle(planes):\n for i in range(len(planes)):\n j = planes[i] - 1\n k = planes[j] - 1\n if planes[k] - 1 == i:\n return True\n return False\n\nif has_love_triangle(planes):\n print(\"YES\")\nelse:\n print(\"NO\")\n\t\t \t\t\t\t \t\t \t\t \t \t\t\t \t\t \t\t", "n, p = int(input()), list(map(int, input().split()))\r\np = list(map(lambda v: v - 1, p))\r\n\r\n\r\ndef smartWalker():\r\n for i in range(n):\r\n cnt = 0\r\n pos = i\r\n while cnt < 3:\r\n pos = p[pos]\r\n cnt += 1\r\n if pos == i:\r\n return print('YES')\r\n\r\n print('NO')\r\n\r\n\r\nsmartWalker()\r\n", "n = int(input())\r\nf = list(map(int,input().strip().split()))\r\nfor i in range(n):\r\n if f[f[f[i]-1]-1] == i+1:\r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\")", "n = int(input())\r\n\r\nArray = list(map(lambda x: int(x)-1, input().split()))\r\n\r\nfor i in range(n):\r\n x=Array[i]\r\n y=Array[x]\r\n z=Array[y]\r\n if z==i:\r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\")", "n = int(input())\n\ninps = [int(n) for n in input().split()]\n\nadj = [[] for j in range(n)]\n\n\nfor inp in inps:\n adj[inp-1].append(inps[inp-1]-1)\n\n#print(adj)\n\nfor a, r in enumerate(adj):\n #print(1, a)\n for b in r:\n #print(2, b)\n for c in adj[b]:\n #print(3, c)\n if c == a:\n continue\n for d in adj[c]:\n #print(4, d)\n if d == a:\n print(\"YES\")\n exit()\n\nprint(\"NO\")\n\t\t \t \t \t\t \t \t\t\t \t \t\t \t\t\t", "\r\ndef triangle(dic, start):\r\n count = 0\r\n now = start\r\n while count < 3:\r\n now = dic[now]\r\n count += 1\r\n if now == start:\r\n return True\r\n else:\r\n return False\r\n \r\nn = int(input())\r\n\r\nf = [int(x) for x in input().split()]\r\ndic = {}\r\n\r\nfor i in range(n):\r\n dic[i+1] = f[i]\r\n\r\nfor i in range(1,n+1):\r\n if triangle(dic, i):\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"No\")\r\n", "a=int(input())\nb=input().split(\" \")\nb=[int(i) for i in b]\nflag=True\nfor i in range(a):\n c=b[i]-1\n d=b[c]-1\n if b[d]==i+1:\n print('YES')\n flag=False\n break\nif flag:\n print('NO')\n\t \t \t \t \t \t \t\t \t\t\t \t \t", "n = int(input())\r\nf = list(map(int,input().split()))\r\nm = False\r\nfor i in range(n):\r\n if f[f[f[i]-1]-1]-1 == i :\r\n m = True\r\nif m :\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\")\r\n", "i=input\nn=int(i())\nf=[1,*map(int,i().split())]\nprint('YNEOS'[all(f[f[f[x]]]!=x for x in f)::2])\n\t \t\t \t\t \t \t \t \t\t\t \t\t \t\t \t", "def love_triangle_exists(n, likes):\r\n for i in range(n):\r\n first = likes[i]\r\n second = likes[first - 1]\r\n third = likes[second - 1]\r\n\r\n if third == i + 1:\r\n return True\r\n\r\n return False\r\n\r\nn = int(input())\r\nlikes = list(map(int, input().split()))\r\n\r\nif love_triangle_exists(n, likes):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def love_triangle(n, preferences):\r\n for i in range(1, n + 1):\r\n j = preferences[i - 1]\r\n k = preferences[j - 1] if 1 <= j <= n else -1\r\n if k != -1 and preferences[k - 1] == i:\r\n return \"Yes\"\r\n return \"No\"\r\n\r\n\r\n\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\nresult = love_triangle(n, arr)\r\nprint(result)\r\n", "n = int(input())\nplanes = [int(i) for i in input().split()]\n\ndef cicle(n, collect):\n result = [n, collect[n-1], collect[collect[n-1]-1], collect[collect[collect[n-1]-1]-1]]\n if collect[collect[collect[n-1]-1]-1] == n:\n return True\n\n return False\n\n\ndef triangle():\n global planes\n for plane in planes:\n if(cicle(plane, planes)):\n return \"YES\"\n\n return \"NO\"\n\nprint(triangle())\n\t\t \t\t \t \t\t\t \t\t\t \t \t \t\t", "#Created By Minsol Jeong\ndef A1():\n\n num = int(input())\n planes = [int(x) for x in input().split()]\n\n x = planes[0]-1\n for i in range(1, len(planes)):\n y = planes[x]-1\n if (planes[y]== i):\n print('YES')\n return\n else:\n x = planes[i] -1\n\n\n print('NO')\n return\nif __name__=='__main__':\n A1()\n\t\t \t \t \t \t\t \t\t \t\t\t \t \t", "def main():\r\n\tn = int(input())\r\n\tplanes_love = list(int(x)-1 for x in input().split())\r\n\r\n\tfor i in range(n):\r\n\t\tback_lover3 = i\r\n\t\tback_lover2 = planes_love[back_lover3]\r\n\t\tback_lover1 = planes_love[back_lover2]\r\n\t\tcurrent_lover = planes_love[back_lover1]\r\n\r\n\t\tif current_lover == back_lover3:\r\n\t\t\tprint(\"YES\")\r\n\t\t\treturn\r\n\r\n\tprint(\"NO\")\r\n\r\nmain()", "n=int(input())\r\nl=list(map(int,input().split()))\r\nfor i in range (n):\r\n if l[l[l[i]-1]-1]-1==i:\r\n print(\"YES\")\r\n quit()\r\nprint(\"NO\")", "if __name__ == '__main__':\r\n n = int(input())\r\n map = [0]+list(map(int,input().split()))\r\n visited = set()\r\n flag = True\r\n for i in range(1,n+1):\r\n if map[map[map[i]]] == i:\r\n print('YES')\r\n flag = False\r\n break\r\n if flag:\r\n print('NO')", "def search_triangle(index, inc_list):\r\n b = inc_list[index] # a -> b\r\n c = inc_list[b] # b -> c\r\n if inc_list[c] == index: # c -> a?\r\n return True\r\n return False\r\n\r\n\r\ninput()\r\nincidence_list = [-1] + [int(i) for i in input().split()]\r\n\r\nfor i in range(1, len(incidence_list)):\r\n if search_triangle(i, incidence_list):\r\n print('YES')\r\n exit()\r\nprint('NO')\r\n", "def check_triangle(current_plane, likes, sequence):\r\n sequence.append(current_plane)\r\n if len(sequence) == 4:\r\n if sequence[0] == sequence[3]:\r\n return True\r\n else:\r\n return False\r\n else:\r\n return check_triangle(likes[current_plane - 1], likes, sequence)\r\n\r\ndef solve(planes, likes):\r\n for plane in likes:\r\n if check_triangle(plane, likes, []):\r\n print(\"YES\")\r\n return\r\n print(\"NO\")\r\n\r\nplanes = int(input())\r\nlikes = list(map(int, input().split()))\r\n\r\nsolve(planes, likes)", "n = int(input())\r\nj = list(map(int,input().split()))\r\nfor i in j:\r\n\tif j[j[j[i-1]-1]-1] == i:\r\n\t\tprint('YES')\r\n\t\texit()\r\nelse:\r\n\tprint('NO')" ]
{"inputs": ["5\n2 4 5 1 3", "5\n5 5 5 5 1", "3\n3 1 2", "10\n4 10 9 5 3 1 5 10 6 4", "10\n5 5 4 9 10 9 9 5 3 1", "100\n50 40 60 87 39 58 44 84 46 68 16 57 77 87 92 95 42 31 74 15 36 84 30 3 47 15 87 90 76 66 6 63 74 19 40 49 6 84 41 9 77 34 7 12 11 73 58 24 81 14 81 29 65 100 1 85 64 32 38 4 54 67 32 81 80 7 100 71 29 80 4 52 47 7 78 56 52 75 81 37 16 41 27 28 58 60 62 47 29 40 37 14 59 91 12 54 25 58 12 43", "100\n25 6 46 37 87 99 70 31 46 12 94 40 87 56 28 8 94 39 13 12 67 13 71 39 83 48 40 14 62 41 16 71 20 41 83 41 68 98 23 82 62 83 62 35 49 22 31 21 66 98 54 39 34 52 11 28 47 89 25 44 68 36 91 46 82 86 88 48 27 93 7 9 53 36 16 100 84 84 44 25 58 66 16 46 72 21 91 78 4 17 44 17 47 67 93 89 75 44 56 50", "2\n2 1", "3\n2 3 1", "5\n2 1 4 5 3", "5\n5 4 5 5 2"], "outputs": ["YES", "NO", "YES", "NO", "YES", "NO", "YES", "NO", "YES", "YES", "YES"]}
UNKNOWN
PYTHON3
CODEFORCES
490
1290054e6b5f04220016c64ece88f5db
Boy or Girl
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). Sample Input wjmzbmr xiaodao sevenkplus Sample Output CHAT WITH HER! IGNORE HIM! CHAT WITH HER!
[ "d=dict()\r\nn=input()\r\nfor ch in n:\r\n if(ch in d):\r\n d[ch]=d[ch]+1 \r\n else:\r\n d[ch]=0\r\ncount=len(d)\r\nif(count%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=input()\r\na=[]\r\nfor i in s:\r\n if i not in a:\r\n a.append(i)\r\nif len(a)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "\r\nx=input()\r\nc=0\r\nfor i,j in enumerate(x):\r\n if (j in x[:i]):\r\n continue\r\n c=c+1\r\n\r\nif c%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "u = set(input())\r\nif len(u)%2 == 0 or len(u) == 2:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "print(\"CHAT WITH HER!\" if len(list(set(input())))%2==0 else \"IGNORE HIM!\")", "txt = input()\r\ns=set()\r\nfor i in range(len(txt)):\r\n s.add(txt[i])\r\nif len(s) % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "palabra = input()\nlista = []\nfor letra in palabra:\n if letra not in lista:\n lista.append(letra)\nrta = len(lista)\nif rta%2 == 1:\n print(\"IGNORE HIM!\")\nelse:\n print(\"CHAT WITH HER!\")", "# Read the user name as a string\r\nuser_name = input()\r\n\r\n# Count the number of distinct characters in the user name\r\ndistinct_characters = set(user_name)\r\n\r\n# Check if the count is even or odd\r\nif len(distinct_characters) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "username = input()\r\nletter = list(set(username))\r\nif len(letter) % 2:\r\n print('IGNORE HIM!')\r\nelse:\r\n print('CHAT WITH HER!')", "a = input()\r\nn=0\r\nb=[]\r\nfor i in a:\r\n if i not in b:\r\n b.append(i)\r\nfor i in b:\r\n n+=1\r\nif n%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=list(input())\r\nr=len(set(s))\r\nif(r%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = set(input())\r\nprint(\"IGNORE HIM!\" if len(s) % 2 == 1 else \"CHAT WITH HER!\")", "x= input()\r\nc=[]\r\ncount1 =0\r\nfor i in x:\r\n if i not in c:\r\n c.append(i)\r\n count1 +=1\r\nif count1 % 2 ==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "def boyOrGirl(s):\r\n s1=\"\"\r\n for i in s:\r\n if i not in s1: \r\n s1+=i\r\n return \"IGNORE HIM!\" if len(s1)%2==1 else \"CHAT WITH HER!\"\r\n\r\n\r\ns1=input()\r\nprint(boyOrGirl(s1))", "nickname = input()\r\nnickname_set = set(nickname)\r\nunique_nickname_len = len(nickname_set)\r\nif unique_nickname_len % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n ", "name=str(input())\r\nL=[]\r\nfor i in name :\r\n if i not in L:\r\n L.append(i)\r\n\r\nif len(L)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "def catfish(s):\r\n alist=[]\r\n for d in s:\r\n if d not in alist:\r\n alist.append(d)\r\n if len(alist)%2==0:\r\n return True\r\n return False\r\ns=input()\r\nif catfish(s):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "letters = [*\"abcdefghijklmnopqrstuvwxyz\"]\r\ndistinct = 0\r\n\r\nname = input()\r\n\r\nfor i in name:\r\n if i in letters:\r\n letters.remove(i)\r\n distinct +=1\r\n\r\nif distinct % 2 ==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "word = input()\r\nds=set(word)\r\nif len(ds)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "userName = str(input())\r\nmemorized = []\r\nnumOfRealLetters = 0\r\nfor i in userName:\r\n if i in memorized:\r\n continue\r\n else:\r\n memorized.append(i)\r\n numOfRealLetters+=1\r\nprint(\"CHAT WITH HER!\" if numOfRealLetters%2 == 0 else \"IGNORE HIM!\")", "s=list(input())\r\nc=set(s)\r\nnum=len(c)\r\nif num % 2 ==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "string=input()\r\nnot_set=[]\r\nfor x in string:\r\n not_set.append(x)\r\nsetted=set(not_set)\r\nset_length=len(setted)\r\nif set_length%2!=0:\r\n print('IGNORE HIM!')\r\nif set_length%2==0:\r\n print( \"CHAT WITH HER!\")", "print('CHAT WITH HER!' if not len(set(input())) % 2 else 'IGNORE HIM!')\r\n", "user_name = input().lower()\r\nlist_letters = set(user_name)\r\n\r\nif len(list_letters) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "word=input().lower()\r\ndecision=\"\"\r\nfor i in word:\r\n if i not in decision:\r\n decision+=i\r\nif len(decision)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "word = input().lower()\r\ndecision = ''.join(set(word))\r\nif len(decision) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "n = input()\r\ncounter = 0\r\n\r\nfor i in n:\r\n if n.count(i) > 1:\r\n counter += (n.count(i) - 1)\r\n\r\nlength = len(set(n)) - counter\r\n\r\nif length % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n\r\n \r\n ", "str = input()\r\nls=[]\r\nfor i in str:\r\n if i not in ls:\r\n ls.append(i)\r\n else:\r\n continue\r\nif len(ls)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "x = input(\"\")\r\n\r\ncount = 0\r\nrepeat = 0\r\nfor i in range(0 , len(x)):\r\n for j in range(0,i):\r\n if x[j] == x[i]:\r\n repeat = 1\r\n break\r\n if repeat == 0:\r\n count = count + 1\r\n repeat = 0\r\n \r\n\r\nif count %2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=input()\r\nb=[]\r\nfor i in s:\r\n b.append(i)\r\nb=set(b)\r\nif len(b)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "bilo = []\r\nn = input()\r\ncount = 0\r\nfor i in n:\r\n if i not in bilo:\r\n bilo.append(i)\r\n count += 1\r\nif count % 2:\r\n print('IGNORE HIM!')\r\nelse:\r\n print('CHAT WITH HER!')\r\n", "name=input()\r\n# name is a string \r\n\r\nname_set= set()\r\n\r\nfor i in range(len(name)):\r\n name_set.add(name[i])\r\n\r\nlength=len(name_set)\r\nif length%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n\r\n \r\n\r\n", "n = input()\r\nlst = []\r\nfor i in range (len(n)):\r\n if n[i] in lst:\r\n pass\r\n else:\r\n lst += n[i]\r\n\r\nif len(lst) % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "s = {*input()}\nl = len(s)\nif (l % 2) > 0:\n print('IGNORE HIM!')\nelse:\n print('CHAT WITH HER!')\n", "s=str(input())\nlst=list(s)\nset1=set(lst)\nn=len(set1)\nif n%2==0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n", "# Python 3 program of the above approach\n\n# Program to count the number of\n# unique characters in a string\ndef cntDistinct(st):\n\n\t# Set to store unique characters\n\t# in the given string\n\ts = set([])\n\n\t# Loop to traverse the string\n\tfor i in range(len(st)):\n\n\t\t# Insert current character\n\t\t# into the set\n\t\ts.add(st[i])\n\n\t# Return Answer\n\treturn len(s)\n\n\nst = input()\nif(cntDistinct(st)%2==0): \n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n\n\t# This code is contributed by ukasp.\n\n", "s = input(\"\")\nunique = set()\nfor c in s:\n unique.add(c)\nif len(unique) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")", "str = input()\r\nunique_str = set(str)\r\nif len(unique_str)%2 != 0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "n = input()\r\na = ''.join(set(j for j in n))\r\nif len(n) <= 100 and len(a)%2 == 0:\r\n print( \"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "a = input() \r\na = sorted(a)\r\nresp = 1\r\nfor i in range(len(a) - 1): \r\n if a[i] != a[i + 1]:\r\n resp += 1\r\n\r\nif resp%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse :\r\n print(\"IGNORE HIM!\")\r\n \r\n", "string=list(input())\nnew_set = set(string)\nif (len(new_set)%2==0):\n\tprint(\"CHAT WITH HER!\")\nelse:\n\tprint(\"IGNORE HIM!\")\n\n\n", "p=input()\r\nj=(len(set(p)))\r\nif j%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "x = input()\r\nl = list()\r\nl[:] = x\r\nk = l.copy()\r\np = []\r\n\r\nfor i in range(0, len(l)):\r\n if (l[i] not in p):\r\n p.append(l[i])\r\n\r\n\r\nif len(p) % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')\r\n", "def gender(user):\n chars = set(user)\n if len(chars) %2 ==0:\n return 'CHAT WITH HER!'\n else:\n return 'IGNORE HIM!'\ntext = str(input())\nres = gender(text)\nprint(res)\n\n", "s=input()\r\nl=[]\r\nfor i in s :\r\n l.append(i)\r\nif(len(set(l))%2==0) :\r\n print('CHAT WITH HER!') \r\nelse:\r\n print('IGNORE HIM!') ", "n = str(input())\r\nunique_chars = set(n) \r\ncount = len(unique_chars)\r\nif(count % 2==0):\r\n print(\"CHAT WITH HER!\")\r\nelif(count % 2!=0): \r\n print(\"IGNORE HIM!\")", "s = input()\r\nd = set()\r\nfor i in range(len(s)):\r\n\td.add(s[i])\r\nif len(d) % 2 == 0:\r\n\tprint(\"CHAT WITH HER!\")\r\nelse:\r\n\tprint(\"IGNORE HIM!\")", "# Input: Read the user name as a string\r\nuser_name = input().strip()\r\n\r\n# Count the distinct characters in the user name\r\ndistinct_characters = len(set(user_name))\r\n\r\n# Determine the gender based on the count\r\nif distinct_characters % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "s = input()\r\nl = len(set(s))\r\n\r\nprint(\"IGNORE HIM!\" if l % 2 != 0 else \"CHAT WITH HER!\")", "str=input()\r\nnew=set(str)\r\nif(len(new)%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "name=str(input())\ndist_char=set(name)\nif len(dist_char)%2!=0:\n print(\"IGNORE HIM!\")\nelse:\n print(\"CHAT WITH HER!\")\n \t \t\t\t\t \t\t \t\t\t \t\t \t\t\t \t \t", "a=input()\r\nk=0\r\nbebra=0\r\nb=[]\r\nfor i in range(len(a)):\r\n if a[i] in b:\r\n bebra+=1\r\n else:\r\n k+=1\r\n b.append(a[i]) \r\nif k%2!=0:\r\n print('IGNORE HIM!')\r\nelse:\r\n print('CHAT WITH HER!')", "inp = str(input())\nk = set(inp)\nif len(k)%2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n", "name = input()\r\n# name is a string\r\n\r\nname_set = set()\r\n\r\nfor i in range(len(name)):\r\n name_set.add(name[i])\r\n\r\nlength = len(name_set)\r\nif length % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "name = input()\r\nunique_characters = set(name)\r\n\r\nif len(unique_characters) % 2 == 1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")\r\n", "def gender (username):\r\n username = set(username)\r\n if len(username) % 2 == 0:\r\n return \"CHAT WITH HER!\"\r\n else:\r\n return \"IGNORE HIM!\"\r\nprint(gender(input()))\r\n", "a=input()\r\nl=len(a)\r\nB=[]\r\nfor i in range(l):\r\n if a[i] not in B:\r\n B.append(a[i])\r\nif len(B)%2==1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "s = input()\r\ncounter = \"\"\r\nfor i in s:\r\n if i not in counter:\r\n counter += i\r\nif len(counter) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "n=input()\r\ns=len(n)\r\ns1=set(n)\r\ns2=len(s1)\r\nif s2%2!=0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")\r\n\r\n \r\n \r\n ", "s=input(\"\")\r\nx=list(s)\r\nl1=[]\r\nfor i in range(len(x)):\r\n if x[i] not in l1:\r\n l1.append(x[i])\r\nif len(l1)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "username = input ().lower()\ncontainer = []\nfor dt in username:\n\n if dt not in container:\n\n container .append(dt)\n\ntotalchar = len(container)\nif totalchar%2 == 0:\n\n print (\"CHAT WITH HER!\")\n\nelse:\n print (\"IGNORE HIM!\")\n\nquit()\n\n \t\t \t \t \t \t \t \t \t\t \t", "\r\nusername = input()\r\n\r\n\r\ndistinct_characters = set()\r\n\r\n\r\nfor char in username:\r\n distinct_characters.add(char)\r\n\r\n\r\nif len(distinct_characters) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "name=list(input())\r\nletter=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',\r\n 's','t','u','v','w','x','y','z']\r\nname.sort()\r\nm=0\r\nfor i in letter:\r\n if i in name:\r\n m+=1\r\nif m%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "uniq = []\r\nusername = list(input())\r\nfor x in username:\r\n if x not in uniq:\r\n uniq.append(x)\r\nif len(uniq)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "x=input()\r\ny=list(map(str,x))\r\nz=set(y)\r\n\r\nif len(z) % 2 ==0 :\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "print('CHAT WITH HER!' if len(set(input()))%2==0 else 'IGNORE HIM!')\r\n", "s=input()\r\nlist1=[]\r\nlist1.extend(s)\r\nlist1=set(list1)\r\na=len(list1)\r\nif a%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "ab=input()\r\nmn=[]\r\nfor i in ab:\r\n if i not in mn:\r\n mn.append(i)\r\nif len(mn)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "def main():\n n = input()\n info = [i for i in n]\n info = list(set(info))\n if (len(info) % 2 == 0):\n print('CHAT WITH HER!')\n else:\n print('IGNORE HIM!')\n #print(info)\n\nif __name__ == '__main__':\n main()\n", "input = input()\n\narray = []\n\nflag = 0\n\nfor i in input:\n flag = 0\n for j in array:\n if i == j:\n flag = 1\n\n if flag == 0:\n array.append(i)\n\n\nif len(array) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")", "nom = set(map(str,input()))\r\nn = len(nom)\r\nif(n%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "word = input()\r\narr = []\r\nfor letter in word:\r\n arr.append(letter)\r\n\r\nif len(set(arr)) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "a=input()\r\nc=set()\r\nfor b in a:\r\n c.add(b)\r\nd=len(c)\r\nif d %2 ==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "name=input()\r\ndis_chars=[]\r\nfor x in name:\r\n if x not in dis_chars:\r\n dis_chars.append(x)\r\nif len(dis_chars)%2==0:\r\n print(\"CHAT WITH HER!\") \r\nelse:\r\n print(\"IGNORE HIM!\") ", "user_name=input()\r\nchar=set(user_name)\r\nif len(char)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\") ", "word = str(input())\r\n\r\ntest = set(word)\r\n\r\nif(len(test) % 2 ==0):\r\n\tprint(\"CHAT WITH HER!\")\r\nelse:\r\n\tprint(\"IGNORE HIM!\")\r\n", "name = list(input())\r\ntotal = 0\r\ni = 0\r\nwhile 1:\r\n input_count = name.count(name[i])\r\n if input_count != 1:\r\n name.remove(name[i])\r\n else:\r\n total += 1\r\n i += 1\r\n if i == len(name):\r\n break\r\nif total % 2 == 1:\r\n print('IGNORE HIM!')\r\nelse:\r\n print('CHAT WITH HER!')", "user=str(input())\ntest_char=set(user)\nif len(test_char)%2!=0:\n print(\"IGNORE HIM!\")\nelse:\n print(\"CHAT WITH HER!\")\n \t\t\t\t \t \t \t \t\t\t\t \t \t\t\t \t", "#https://codeforces.com/problemset/problem/236/A\r\n\r\nname = str(input())\r\nname = set(name)\r\nx = 0\r\nfor i in name:\r\n x += 1\r\n\r\nx = x%2\r\n\r\nif x == 0:\r\n print(\"CHAT WITH HER!\") # famale = even\r\nelse:\r\n print(\"IGNORE HIM!\") # male = odd\r\n", "s = input()\r\ncount = 0\r\nlst = []\r\nfor ch in s:\r\n if ch in lst:\r\n count += 1\r\n lst.append(ch)\r\nans = len(s) - count\r\nif ans % 2 != 0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "c = [0 for i in range(26)]\r\ns = input()\r\nans = 0\r\nfor i in range(len(s)):\r\n c[ord(s[i]) - 97] = 1\r\nfor i in range(26):\r\n ans += c[i]\r\nif ans % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "x = str(input())\r\narr = list()\r\nfor i in x:\r\n if i not in arr:\r\n arr.append(i)\r\nif len(arr) % 2 == 1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "str1 = set(input())\r\nif not len(str1) % 2 :\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')\r\n\r\n", "s=input()\r\na=set(s)\r\nn=len(a)\r\nif n%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "inp1 = input()\r\nset1 = set(inp1)\r\nif len(set1)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "Str = input()\r\nStr = list(set(Str))\r\ncount = len(Str)\r\nif count % 2 != 0:\r\n print(\"IGNORE HIM!\")\r\nelif count % 2 == 0:\r\n print(\"CHAT WITH HER!\")", "u = input()\r\nn = []\r\nfor i in u:\r\n if i in n:\r\n continue\r\n n.append(i)\r\n\r\nif len(n) < 100:\r\n if len(n) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")\r\n", "#Boy or a girl\r\nusername=input()\r\nusername=dict.fromkeys(username)\r\n\r\nif len(username)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelif len(username)%2==1:\r\n print(\"IGNORE HIM!\")\r\n", "username = input()\r\ndistinctName = set(username)\r\nif len(distinctName) %2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "s=sorted(list(input()))\r\nn=len(s)\r\nx,a=0,0\r\nwhile x<n:\r\n\tsn=s.count(s[x])\r\n\tif sn>1:\r\n\t\tx+=sn\r\n\telse:\r\n\t\tx+=1\r\n\ta+=1\r\nif a%2==0:\r\n\tprint('CHAT WITH HER!')\r\nelse:\r\n\tprint('IGNORE HIM!')\r\n\r\n\r\n", "meno, uz_boli, tot = input().strip(), [], 0\r\n\r\nfor pismeno in meno:\r\n if pismeno not in uz_boli:\r\n uz_boli.append(pismeno)\r\n tot += 1\r\n\r\nif tot % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "print([\"CHAT WITH HER!\",\"IGNORE HIM!\"][len({*input()})%2])", "import sys\r\n\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 return input().strip()\r\n\r\n\r\ndef out(x):\r\n sys.stdout.write(str(x) + \"\\n\")\r\n\r\n\r\n# def main():\r\n# strings = []\r\n# for _ in range(2):\r\n# strings.append(insr())\r\n \r\n# strings = [i.lower() for i in strings]\r\n \r\n# if strings[0] == strings[1]:\r\n# out(0)\r\n\r\ndef remove_duplicates(string):\r\n ans = \"\"\r\n for s in string:\r\n if s in ans:\r\n continue\r\n else:\r\n ans += s\r\n return ans\r\n\r\ndef main():\r\n input_statement = insr()\r\n unique_str = remove_duplicates(input_statement)\r\n \r\n out(\"CHAT WITH HER!\" if len(unique_str) % 2 == 0 else \"IGNORE HIM!\")\r\n \r\n \r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "username=input()\r\nletterSet=set()\r\nfor letter in username:\r\n letterSet.add(letter)\r\ni = len(letterSet)\r\nif i%2 ==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "name = set(input())\r\na = len(name)\r\nif a % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "x = input().lower() \r\nl1 = []\r\n\r\nfor char in x:\r\n l1.append(char)\r\n\r\nx1 = ''.join(sorted(set(l1)))\r\n\r\nif len(x1) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "s=input()\r\nmp={}\r\nfor i in s:\r\n if i not in mp:\r\n mp[i]=1\r\n# print(len(mp))\r\nif not len(mp)%2:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "name = input()\r\nunique = []\r\nfor i in name:\r\n if i in unique:\r\n continue\r\n else:\r\n unique.append(i)\r\n\r\nif len(unique) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "name = input()\n\nunique_char = set()\n\nfor char in name:\n unique_char.add(char)\n\nif len(unique_char) % 2 == 0:\n print('CHAT WITH HER!')\nelse:\n print('IGNORE HIM!')", "name = input()\r\n\r\nl = list(name)\r\ns = set(l)\r\n\r\nprint(\"CHAT WITH HER!\") if len(s) % 2 == 0 else print(\"IGNORE HIM!\")", "x = input()\r\nk2=[]\r\nout = \"\"\r\nfor ele in x:\r\n if ele not in k2:\r\n k2.append(ele)\r\nfor i in range(0,len(k2)):\r\n out = out+k2[i]\r\n\r\nif len(out)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "s = input()#wjmzbmr\r\nnewS = \"\"\r\nfor i in range(0, len(s)):\r\n if s[i] not in newS:\r\n newS += s[i]\r\nif len(newS)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = input()\r\nl = []\r\nfor i in s:\r\n if i not in l:l.append(i)\r\nif len(l)%2 == 0:print('CHAT WITH HER!')\r\nelse:print('IGNORE HIM!')", "string=\"\"\nn=0\nwhile(1):\n string=input()\n n=len(string)\n if n<=100:\n break\nlist_=[]\nfor i in range(n):\n list_.append(string[i])\nx=len(set(list_))\n\nif x%2==0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n\n", "UsedLetters = ''\r\nfor letter in input():\r\n if UsedLetters.find(letter) == -1:\r\n UsedLetters += letter\r\n\r\nif len(UsedLetters) % 2 == 1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")\r\n", "ch=input()\r\nif len(set(ch))%2==0 :\r\n print ('CHAT WITH HER!')\r\nelse :\r\n print ('IGNORE HIM!')\r\n", "#Boy or Girl\r\na = list(input())\r\na_set_list = list(set(a))\r\nif len(a_set_list)%2 != 0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "a=input()\r\nb=set()\r\nfor i in a:\r\n b.add(i)\r\nif len(b)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse :\r\n print(\"IGNORE HIM!\")\r\n", "name = input()\r\nname_letter = set(name)\r\nprint(\"CHAT WITH HER!\" if len(name_letter) % 2 == 0 else \"IGNORE HIM!\")", "name_input=list(input())\r\nname=set(name_input)\r\n#print(name)\r\nif len(name)%2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "n = input()\r\nb = []\r\nfor i in range(len(n)):\r\n if n[i] not in b :\r\n b.append(n[i])\r\nif len(b) % 2 == 0 :\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "\r\ns = [ss for ss in input()]\r\n\r\nl =[]\r\nfor ss in s:\r\n if ss not in l:\r\n l.append(ss)\r\n\r\nif len(l)%2==1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "import sys\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\n# # your remaining code\r\n\r\n\r\na = input()\r\nk = {}\r\n\r\nfor i in a:\r\n\tk[i] = 1\r\n\r\nif len(k)%2==0:\r\n\tprint(\"CHAT WITH HER!\")\r\nelse :\r\n\tprint(\"IGNORE HIM!\")\r\n\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\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", "n = input()\r\n\r\n\r\ns = set()\r\nfor i in n:\r\n s.add(i)\r\ncount = len(s)\r\ncount = count % 2\r\n\r\nif count == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "n=input()\r\ndic={}\r\ncount=0\r\nfor i in range(len(n)):\r\n if n[i] not in dic.values():\r\n count+=1\r\n dic[i]=n[i]\r\nif count%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "\r\nstr = input()\r\n\r\narr = [char for char in str]\r\n\r\narr_result = []\r\n[arr_result.append(x) for x in str if x not in arr_result]\r\n\r\nif len(arr_result) % 2 == 0 : \r\n print(\"CHAT WITH HER!\")\r\n \r\nelse:\r\n print(\"IGNORE HIM!\")", "s = str(input())\r\ncount = 0\r\n\r\nw = 'abcdefghijklmnopqrstuvwxyz'\r\n\r\nfor letter in w:\r\n if letter in s:\r\n count += 1\r\n s = s.replace(w,'.')\r\n\r\nif count % 2 == 0:\r\n print('CHAT WITH HER!')\r\n\r\nelse:\r\n print('IGNORE HIM!')\r\n ", "def determine_gender(username):\r\n distinct_characters = set(username)\r\n if len(distinct_characters) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")\r\n\r\n# Read input\r\nusername = input().strip()\r\n\r\n# Call the function with the given username\r\ndetermine_gender(username)", "name = input()\r\n\r\nunique = \"\"\r\nfor i in name:\r\n if i not in unique:\r\n unique += i\r\n\r\nprint(\"CHAT WITH HER!\") if len(unique) % 2 == 0 else print(\"IGNORE HIM!\")", "name=input()\r\nwords=set()\r\nfor i in range(len(name)):\r\n words.add(name[i])\r\nif len(words)%2==0:\r\n print(\"CHAT WITH HER!\" )\r\nelse:\r\n print(\"IGNORE HIM!\" )\r\n \r\n\r\n ", "a = str(input())\r\nmydict = {}\r\nfor i in a:\r\n if i not in mydict.keys():\r\n mydict[i] = 1\r\n else:\r\n mydict[i] += 1\r\n\r\nif len(mydict) % 2 == 1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")\r\n ", "Nama = input()\r\nFoundChar = [Nama[0]]\r\n\r\nfor i in range(1, len(Nama)):\r\n if Nama[i] not in FoundChar:\r\n FoundChar.append(Nama[i])\r\n\r\nif len(FoundChar) % 2 == 1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "s=input()\r\nl=set(s)\r\nx=len(l)\r\nif x%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "print('CHAT WITH HER!' if len(set(input())) % 2 == 0 else 'IGNORE HIM!')", "\"\"\"\nThose days, many boys use beautiful girls' photos as avatars in forums. \nSo it is pretty hard to tell the gender of a user at the first glance. \nLast year, our hero went to a forum and had a nice chat with a beauty (he thought so). \nAfter that they talked very often and eventually they became a couple in the network.\n\nBut yesterday, he came to see \"her\" in the real world and found out \"she\" is actually a very strong man! \nOur hero is very sad and he is too tired to love again now.\nSo he came up with a way to recognize users' genders by their user names.\n\nThis is his method: if the number of distinct characters in one's user name is odd, then he is a male,\notherwise she is a female. \nYou are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.\n\nInput\nThe first line contains a non-empty string,\nthat contains only lowercase English letters — the user name. This string contains at most 100 letters.\n\nOutput\nIf it is a female by our hero's method, print \"CHAT WITH HER!\" (without the quotes),\notherwise, print \"IGNORE HIM!\" (without the quotes).\n\"\"\"\n\na = input() # string input\nchars_list = list(a) # transform input to a list of characters\n\nresult = set(chars_list) # get the unique elements\n\nif len(result) % 2 == 0: # check the odds \n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n\n# print(chars_list)\n# print(result)", "letters = set(input())\r\nc = len(letters)\r\nprint('CHAT WITH HER!') if c % 2 == 0 else print('IGNORE HIM!')", "a = input()\r\nc =''\r\nfor i in range(0,len(a)):\r\n if c.count(a[i]) == 0:\r\n c = c + a[i]\r\nif len(c) % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "word = input()\r\ndistinct_word = []\r\nfor i in word:\r\n if i in distinct_word:\r\n pass\r\n else:\r\n distinct_word.append(i)\r\nif len(distinct_word) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "string = input()\r\nstring1 = set(string)\r\n#print(string1)\r\nlength = len(string1)\r\nif(length % 2 == 0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "string=str(input())\r\nlist=[]\r\ns=0\r\nfor char in string:\r\n if char not in list:\r\n s+=1\r\n list.append(char)\r\nif s%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n ", "name = input()\r\nlength = len(\"\".join(list(set(name))))\r\nprint(\"CHAT WITH HER!\" if length % 2 == 0 else \"IGNORE HIM!\")", "# Read the user name\r\nuser_name = input()\r\n\r\n# Count the number of distinct characters in the user name\r\ndistinct_characters = len(set(user_name))\r\n\r\n# Check if the number of distinct characters is even\r\nif distinct_characters % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "def main():\n p = input()\n distinct = len(set([i for i in p]))\n if(distinct%2==0):\n print(\"CHAT WITH HER!\")\n else:\n print(\"IGNORE HIM!\")\n\nif __name__ == '__main__':\n main()\n", "# Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.\n\n# But yesterday, he came to see \"her\" in the real world and found out \"she\" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.\n\n# This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.\n# Input\n\n# The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.\n# Output\n\n# If it is a female by our hero's method, print \"CHAT WITH HER!\" (without the quotes), otherwise, print \"IGNORE HIM!\" (without the quotes).\n\n\nname = list(input())\ntemp = []\nfor i in name:\n if i in temp:\n pass\n else:\n temp.append(i)\n\nif len(temp) % 2 == 0:\n print('CHAT WITH HER!')\nelse:\n print('IGNORE HIM!')\n", "i=input()\r\nl=len(i)\r\nsi=sorted(i)\r\nfor x in range(l):\r\n if si[x]==si[x-1]:\r\n l-=1\r\nif l%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "import string\r\n\r\ns = input()\r\nn = len(s)\r\nres = 0\r\nb = [1]\r\na = b*n\r\nfor i in range(n):\r\n if a[i] == 1:\r\n res += a[i]\r\n a[i] = 0\r\n j = i+1\r\n while (j < n):\r\n if s[i] == s[j]:\r\n a[j] = 0\r\n j += 1\r\nif res % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')\r\n\r\n\r\n\r\n", "user_name=input()\r\ndistinct_characters=set(user_name)\r\nif len(distinct_characters)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "user_name = input()\r\nuserList = [i for a,i in enumerate(user_name) ]\r\nlist1 = []\r\ncount = 0\r\nfor i in range(len(userList)):\r\n if userList[i] in list1 :\r\n continue\r\n count +=1\r\n list1.append(userList[i])\r\nif count % 2 == 0 :\r\n print(\"CHAT WITH HER!\")\r\nelse :\r\n print(\"IGNORE HIM!\")", "a={s for s in input()}\r\nif len(a)%2==0: print('CHAT WITH HER!')\r\nelse: print('IGNORE HIM!')", "name = set(input())\r\nprint(\"CHAT WITH HER!\" if len(name) % 2 == 0 else \"IGNORE HIM!\")\r\n", "a=set(input())\r\nprint(['CHAT WITH HER!','IGNORE HIM!'][len(a)%2])", "n1 = input()\r\ni = 0\r\nj= 0\r\nresult = 0\r\nn = list()\r\nn2 = \"\"\r\nwhile j < len(n1):\r\n n.append(n1[j])\r\n j+=1\r\n\r\nn.sort()\r\n\r\nwhile i < len(n)-1:\r\n if n[i] != n[i+1]:\r\n n2=n2+n[i]\r\n i+=1\r\nn2=n2+n[len(n)-1]\r\n\r\nif len(n2)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "User_Name = input()\r\n\r\ndistinct = set(User_Name)\r\n\r\nlenght = len(distinct)\r\n\r\nif lenght % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=input()\r\np=set(s)\r\nd=len(p)\r\nif d%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "n=str(input())\r\nd_c=len(set(n))\r\nif d_c%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "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\ns=fgs()\r\ns=set(s)\r\nif len(s)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "chat = input()\r\nnew = ''\r\nfor a in chat:\r\n if a not in new:\r\n new += a\r\n else:\r\n continue\r\n\r\n\r\nif len(new) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelif len(new) % 2 != 0:\r\n print(\"IGNORE HIM!\")\r\n", "s = input()\r\ncheck = []; count = 0\r\nfor i in s:\r\n if i not in check:\r\n check.append(i)\r\n count += 1\r\nif count % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n exit()\r\nprint(\"IGNORE HIM!\")\r\n", "a=input()\r\nb=set(a)\r\nc=len(b)\r\nif(c%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "def Solution(word):\r\n new_word_list = list(set(word))\r\n if len(new_word_list)%2 != 0:\r\n return \"IGNORE HIM!\"\r\n else:\r\n return \"CHAT WITH HER!\"\r\n\r\n\r\nif __name__ == \"__main__\":\r\n word = input()\r\n print(Solution(word))\r\n", "def maleorfemale (username):\n username_set = set()\n for character in username:\n username_set.add(character)\n \n if len(username_set) % 2 == 0:\n print(\"CHAT WITH HER!\")\n else:\n print(\"IGNORE HIM!\")\n\n \n \nmaleorfemale(input(\"\"))\n\n\n \n\t\t\t \t \t\t\t \t \t\t\t \t \t", "username = str(input())\r\n\r\nunique_char_count = len(set(username))\r\n\r\nif unique_char_count %2 == 0 :\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n\r\n", "res = input()\r\ncount = len(set(res))\r\nif int(count) % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')\r\n", "# Read the user name from input\r\nuser_name = input()\r\n\r\n# Count the distinct characters in the user name\r\ndistinct_characters = len(set(user_name))\r\n\r\n# Determine the gender\r\nif distinct_characters % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "s = input()\r\nst = set()\r\nfor i in s:\r\n st.add(i)\r\nif len(st)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "username = input()\r\nword_array = [letter for letter in username]\r\ndef boy_or_girl(word_array):\r\n word_dict = {}\r\n for letter in word_array:\r\n word_dict[letter] = word_dict.get(letter,0) + 1\r\n if len(word_dict.keys()) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")\r\n \r\nboy_or_girl(word_array)\r\n ", "username = input()\r\n\r\nunique_letter_set = set()\r\nfor letter in username:\r\n unique_letter_set.add(letter)\r\n\r\nif len(unique_letter_set) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "name = input()\r\nusername=list(name)\r\nuser_set = set(username)\r\nif len(user_set)%2!=0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "w=input()\r\nk=len(w)\r\nl=''\r\nfor a in w:\r\n if a not in l:\r\n k= k+1-w.count(a)\r\n l+=a\r\nif k%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "import string\r\nA = []\r\nfor i in string.ascii_lowercase:\r\n A.append(i)\r\nn = input()\r\ncount = 0\r\nfor i in range(len(n)):\r\n for k in range(len(A)):\r\n if n[i] == A[k] and A[k] != \"secilmis\":\r\n count += 1\r\n A[k] = \"secilmis\"\r\nif count % 2 ==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "x = input()\r\nans=[]\r\nfor i in x:\r\n if i not in ans:\r\n ans.append(i)\r\n else:\r\n continue\r\nif len(ans)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "s = input()\r\na = []\r\nfor i in range(len(s)):\r\n if s[i] not in a:\r\n a.append(s[i])\r\nif len(a) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = input()\ns = list(s)\ns = set(s)\ns = list(s)\nx = len(s)\nif x%2==0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n", "string=input()\r\ns=set(string)\r\nln=len(s)\r\nif ln%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "word = input().lower()\r\nchars = []\r\nfor i in word:\r\n if i not in chars:\r\n chars.append(i)\r\n\r\nif len(chars) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = input()\nd = {}\nfor i in s:\n if i not in d:\n d[i] = None\n\n\nprint(\"CHAT WITH HER!\") if len(d) % 2 == 0 else print(\"IGNORE HIM!\")\n\t\t\t\t\t \t \t\t \t\t \t \t \t\t\t\t \t\t\t", "if len(set(input()))%2==0:print(\"CHAT WITH HER!\")\r\nelse:print(\"IGNORE HIM!\" )", "def isDistinct(username):\r\n distinct_chars = set(username)\r\n return len(distinct_chars)\r\n\r\nusername = input()\r\ndistinct_count = isDistinct(username)\r\n\r\nif distinct_count % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "n=input()\r\nn=list(n)\r\nf=''\r\nfor i in n:\r\n if i not in f:\r\n f+=i\r\nif len(f)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "name = input()\r\n\r\ncadena = []\r\n\r\nfor i in name:\r\n if i not in cadena:\r\n cadena.append(i)\r\n\r\nif len(cadena)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "string=list(input(\"\"))\r\nnew=''\r\nfor x in range(len(string)):\r\n if string[0:x].count(string[x])==0:\r\n new=new+string[x]\r\nnum=len(new)\r\nif num%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n ", "a=input()\r\nrepeat=[]\r\nnot_repeat=[]\r\nfor i in a:\r\n num=a.count(i,0,len(a))\r\n if num>1 and i not in repeat:\r\n repeat.append(i)\r\n if num==1:\r\n not_repeat.append(i)\r\n\r\nb=repeat+not_repeat\r\n\r\nif len(b) % 2 ==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "s = input()\r\nc = []\r\nfor i in range(len(s)):\r\n c.append(s[i])\r\n\r\nc = sorted(c)\r\ncnt = 0\r\nfor i in range(len(c)):\r\n if c[i] != c[i-1]:\r\n cnt+=1\r\n \r\nif cnt%2 == 0:\r\n print('CHAT WITH HER!')\r\n\r\nelse:\r\n print('IGNORE HIM!')\r\n ", "s = input()\r\nr = \"\".join(set(s))\r\nif len(r)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = set(input())\r\nprint(\"IGNORE HIM!\" if len(s) % 2 != 0 else \"CHAT WITH HER!\")\r\n", "name=input()\nl=list(name)\nx=len(l)\ndl=[]\nfor i in range(x):\n if (l[i] in dl)==False:\n dl.append(l[i])\nif len(dl)%2==1:\n print('IGNORE HIM!')\nelse:\n print('CHAT WITH HER!')\n\n", "username = input()\r\n\r\nletters = []\r\n\r\nfor letter in username:\r\n\r\n if letter not in letters:\r\n\r\n letters.append(letter)\r\n\r\nif len(letters) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n\r\nelse: print(\"IGNORE HIM!\")", "nickname = input()\nnickname = dict.fromkeys(nickname)\nif len(nickname) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")", "name = input()\r\n\r\ns = []\r\ncount = 0\r\n\r\nfor c in name:\r\n\tif c not in s:\r\n\t\ts.append(c)\r\n\t\tcount += 1\r\nif count % 2 == 0:\r\n\tprint(\"CHAT WITH HER!\")\r\nelse:\r\n\tprint(\"IGNORE HIM!\")", "s = input()\r\nst = ''\r\nfor a in s:\r\n if a not in st:\r\n st += a\r\nif len(st)%2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "username = input()\r\noutput = \"\"\r\n\r\nfor letter in username:\r\n if letter not in output:\r\n output+=letter\r\n\r\nif len(output) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "def solve():\r\n s, st = input(), set()\r\n st.update(list(s))\r\n print('CHAT WITH HER!' if len(st) % 2 == 0 else 'IGNORE HIM!')\r\n\r\n\r\n# t = int(input())\r\nt = 1\r\nwhile t:\r\n solve()\r\n t -= 1\r\n", "def boy_or_girl(s):\r\n convert = list(s)\r\n lst = []\r\n for char in convert:\r\n if char not in lst:\r\n lst.extend(char)\r\n else:\r\n continue\r\n n = len(lst)\r\n if n % 2 == 0:\r\n return 'CHAT WITH HER!'\r\n else:\r\n return 'IGNORE HIM!'\r\n\r\ndef main():\r\n s = input()\r\n result = boy_or_girl(s)\r\n print(result)\r\n\r\nif __name__ == \"__main__\":\r\n main()", "a = input()\r\na=set([*a])\r\nif len(a)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')\r\n ", "str=input()\r\n\r\ncharct=set()\r\nfor char in str:\r\n if char.isalpha():\r\n charct.add(char)\r\n else :\r\n continue \r\nif(len(charct)%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=set(input())\r\nprint('IGNORE HIM!'if len(s)%2!=0 else 'CHAT WITH HER!')", "user_name=input()\r\ndistinct_chars=set(user_name)\r\nif len(distinct_chars)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = input()\r\na = set(list(s))\r\nif len(a)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "inp = input()\r\n\r\ninp = set(inp)\r\n\r\nif len(inp) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = input()\r\n\r\nr = []\r\n\r\ncount = 0\r\n\r\nfor i in s:\r\n if count == 0:\r\n r.append(i)\r\n count += 1 \r\n if count >= 1:\r\n if i in r:\r\n continue\r\n else:\r\n r.append(i)\r\n count += 1 \r\nif count % 2 == 1:\r\n print('IGNORE HIM!')\r\nelse:\r\n print('CHAT WITH HER!')", "\r\n\"\"\"\r\nBoy or girl \r\n\r\n\"\"\"\r\nUser=input()\r\n\r\ns=dict.fromkeys(User)\r\n\r\n\r\nif len(s)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')\r\n \r\n", "dic={}\r\nfor i in range(26):\r\n dic[chr(ord(\"a\")+i)]=0\r\nfor i in input():\r\n dic[i]+=1\r\nn=0\r\nfor i in dic:\r\n n+=int(bool(dic[i]))\r\nif n%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "name =input()\r\ncount=len(name)\r\nhi=[]\r\nfor i in name :\r\n if name.count(i)!=1 and( i not in hi):\r\n hi.append(i)\r\n count=count-(name.count(i)-1)\r\nif count%2==0 or count==2:\r\n print(\"CHAT WITH HER!\")\r\nelse :\r\n print(\"IGNORE HIM!\")\r\n", "s=input()\r\ns=''.join(sorted(s))\r\n#print(s)\r\nc=1\r\nl=len(s)\r\nfor i in range(0,l-1):\r\n if s[i]!=s[i+1]:\r\n c+=1\r\nif c%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "if __name__ == '__main__':\r\n input_str = input()\r\n chars = []\r\n for i in range(len(input_str)):\r\n chars.append(input_str[i])\r\n chars = list(set(chars))\r\n if len(chars)%2 == 1:\r\n print(\"IGNORE HIM!\")\r\n else:\r\n print(\"CHAT WITH HER!\")\r\n", "distinct=[]\r\ninput_string=input()\r\nfor i in input_string:\r\n if i not in distinct:\r\n distinct.append(i)\r\n\r\nn=len(distinct)\r\nif n%2==0:\r\n print(\"CHAT WITH HER!\")\r\n\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "word=str(input())\r\nnew_word=set(word)\r\nif len(word)<=100:\r\n if len(new_word) % 2 == 0 :\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")", "a=input()\r\ne=[i for i in a]\r\nd=list(dict.fromkeys(e))\r\nc=len(d)\r\nif (c)%2!=0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")\r\n\r\n \r\n", "a=input()\r\nd={}\r\nfor i in a:\r\n if i not in d:\r\n d[i]=0\r\n d[i]+=1\r\nif len(d)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "\n\n\n\n\ns = input()\nst = set(s)\n\nif len(st) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse :\n print(\"IGNORE HIM!\")\n\n \n \t\t\t \t \t\t \t \t \t \t\t", "from collections import Counter\r\nfre = Counter(input())\r\nprint('CHAT WITH HER!' if len(fre.keys()) % 2 == 0 else 'IGNORE HIM!')", "str1=list(map(str,input()))\r\nstr1=set(str1)\r\nln1=len(str1)\r\nif ln1%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n \r\n", "def sumStr(s):\r\n st = set(s)\r\n if(len(st)%2==0):\r\n return \"CHAT WITH HER!\"\r\n else:\r\n return \"IGNORE HIM!\"\r\n \r\n \r\n \r\n \r\n\r\ns = input()\r\nprint(sumStr(s))", "str = input()\r\nli = []\r\nfor char in str:\r\n if char not in li:\r\n li.append(char)\r\n \r\nn = len(li)\r\nif n % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "string = str(input())\r\nset = \"\"\r\nfor i in string:\r\n\tif i not in set:\r\n\t\tset += i\r\nif len(set)%2 == 0:\r\n\tprint(\"CHAT WITH HER!\")\r\nelse:\r\n\tprint(\"IGNORE HIM!\")", "k = input()\r\np = set(k)\r\nif len(p)%2 ==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=set()\r\na=input()\r\nfor i in a:\r\n s.add(i)\r\nif len(s)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=input()\r\na=set()\r\nfor i in s: a.add(i)\r\nif len(a)%2==0: print(\"CHAT WITH HER!\")\r\nelse: print(\"IGNORE HIM!\")\r\n", "str = input()\r\ns = set()\r\nfor char in str:\r\n s.add(char)\r\nprint(\"CHAT WITH HER!\") if len(s) % 2 == 0 else print(\"IGNORE HIM!\")", "a=input()\r\na=set(a)\r\nb=len(a)\r\nif (b%2==1):\r\n\tprint(\"IGNORE HIM!\")\r\nelse:\r\n\tprint(\"CHAT WITH HER!\")", "from collections import defaultdict\nn = input()\nmap1 = defaultdict(int)\nfor i in n:\n map1[i] = 1\nif len(map1) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n", "user = input()\r\n\r\nunique_user = \"\"\r\nfor i in user:\r\n\tif i not in unique_user:\r\n\t\tunique_user+=i\r\nif len(unique_user)%2 == 1:\r\n\tprint(\"IGNORE HIM!\")\r\nelse:\r\n\tprint(\"CHAT WITH HER!\")", "\r\ninput_string = input()\r\nsorted_string = sorted(input_string)\r\ndistinct_chars = []\r\nfor char in sorted_string:\r\n if char not in distinct_chars:\r\n distinct_chars.append(char)\r\n\r\ncount_distinct_chars = len(distinct_chars)\r\nif count_distinct_chars % 2 == 0:\r\n result = \"CHAT WITH HER!\"\r\nelse:\r\n result = \"IGNORE HIM!\"\r\nprint(result)\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nSpyder Editor\r\n\r\nThis is a temporary script file.\r\n\"\"\"\r\n\r\nm = input()\r\ns = ''\r\nfor i in m:\r\n if i not in s:\r\n s += i\r\nq = len(s)\r\nif q % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelif q % 2 == 1:\r\n print('IGNORE HIM!')", "n = len(set(list(input(\"\"))))\nif n%2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")", "from collections import Counter\r\n\r\nprint(\"CHAT WITH HER!\" if len(Counter(input()))%2==0 else \"IGNORE HIM!\")", "a = input()\r\nb = set(a)\r\nb = len(b)\r\nif b%2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "word = input()\nword_c = set(word)\nif len(word_c) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n \t\t \t \t \t \t \t \t\t\t \t \t\t\t\t", "\r\ndef borg(usern):\r\n \r\n unique = []\r\n \r\n for i in range(len(usern)):\r\n if usern[i] not in unique:\r\n unique.append(usern[i])\r\n \r\n if len(unique) % 2 == 0:\r\n return ('CHAT WITH HER!')\r\n else: \r\n return ('IGNORE HIM!')\r\n \r\n \r\nusername = input()\r\n\r\nprint (borg(username))", "un=input()\r\nuns=set(un)\r\nif len(uns)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "name = set(input())\r\ncount = len(name)\r\nif count%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse :\r\n print(\"IGNORE HIM!\")\r\n", "x=input()\r\ny=set(x)\r\nz=len(y)\r\n\r\nif z%2==0:\r\n print(\"CHAT WITH HER!\")\r\n\r\nelse:\r\n print(\"IGNORE HIM!\")", "a = input()\r\nprint(\"CHAT WITH HER!\" if len(set(a)) % 2 == 0 else \"IGNORE HIM!\")\r\n", "username = input()\r\nusernameAfter = \"\"\r\n\r\nfor char in username:\r\n if char not in usernameAfter:\r\n usernameAfter = usernameAfter+char\r\n\r\nif (int(len(usernameAfter)) % 2) == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "me=input()\r\nb=[]\r\nfor i in range(0, len(me)):\r\n b.append(me[i])\r\na=set(b)\r\nz=list(a)\r\nif len(z)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "a = input()\r\nc = (len(set(a))%2==0)\r\nif c:\r\n\tprint(\"CHAT WITH HER!\")\r\nelse:\r\n\tprint(\"IGNORE HIM!\")", "n=str(input())\r\nn=set(n)\r\na=len(n)\r\nif a%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "a=input()\r\nc=len(a)\r\ns=\"\"\r\nfor i in a:\r\n if a.count(i)!=1:\r\n if i not in s:\r\n b=a.count(i)-1\r\n c-=b\r\n s+=i\r\nif c%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "s = input(\"\")\r\nunq = []\r\nfor x in s:\r\n if x not in unq:\r\n unq.append(x)\r\nif len(unq) %2 != 0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "import sys\r\n\r\ns = list(dict.fromkeys(list(sys.stdin.readline()[:-1])))\r\n\r\nif len(s) % 2 != 0:\r\n print('IGNORE HIM!')\r\nelse:\r\n print('CHAT WITH HER!')", "s=input()\r\nsper=set(s)\r\nif len(sper)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "name = input()\r\nnew_name = \"\"\r\nfor i in name:\r\n if i not in new_name:\r\n new_name = new_name + i\r\nif len(new_name)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "from collections import Counter\r\n\r\n\r\nvalue = input()\r\nif len(Counter(value).keys()) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = input()\r\n\r\nd = [0] * 26\r\nl = len(s)\r\nc = 0\r\n\r\nfor i in range(l):\r\n a = ord(s[i]) - ord('a')\r\n if d[a] == 0:\r\n d[a] = 1\r\n c += 1\r\n\r\nif c % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "if __name__ == '__main__':\r\n name = input()\r\n fname = ''\r\n for letter in name:\r\n if letter not in fname:\r\n fname = fname + letter\r\n number = len(fname)\r\n if number % 2 == 0:\r\n print('CHAT WITH HER!')\r\n else:\r\n print('IGNORE HIM!')\r\n", "def boyorGirl():\r\n name = input()\r\n distinctChar = \"\"\r\n for char in name:\r\n if char not in distinctChar:\r\n distinctChar = distinctChar + char\r\n if len(distinctChar) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")\r\n\r\nboyorGirl()", "n = input()\r\nres= set(n)\r\nif len(res) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "nick = str(input())\r\nnewWord = ''.join(set(nick))\r\n\r\nif len(newWord)%2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "def determine_gender(user_name):\r\n \"\"\"Determines the gender of a user by their user name according to the given method.\r\n\r\n Args:\r\n user_name: A string representing the user name.\r\n\r\n Returns:\r\n A string representing the gender of the user, either \"CHAT WITH HER!\" or\r\n \"IGNORE HIM!\".\r\n \"\"\"\r\n\r\n num_distinct_chars = len(set(user_name))\r\n if num_distinct_chars % 2 == 1:\r\n return \"IGNORE HIM!\"\r\n else:\r\n return \"CHAT WITH HER!\"\r\n\r\nuser_name = input()\r\nprint(determine_gender(user_name))", "t = input()\r\nl = []\r\n\r\nfor i in t:\r\n l.append(i)\r\n\r\nif len(set(t)) % 2 == 1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")\r\n", "# LUOGU_RID: 127399649\ns=len(set(input())) #去重来算出不同的字母\nif s%2==0: #判断奇数偶数\n print('CHAT WITH HER!') #输出Yes\nelse:\n print('IGNORE HIM!')", "s=input()\r\nl=\"\"\r\nc=0\r\nfor i in range(len(s)):\r\n if(s[i] not in l):\r\n if(s[i]!=' '):\r\n c+=1 \r\n l=l+s[i]\r\nif(c%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "print(\"CHAT WITH HER!\" if len(set(input().strip()))%2==0 else \"IGNORE HIM!\")", "s = input()\n\nprint(\"IGNORE HIM!\" if len(set(list(s))) % 2 == 1 else \"CHAT WITH HER!\")", "\r\ns=input()\r\nl=[]\r\nfor i in range(len(s)):\r\n l.append(s[i])\r\n a=l.count(s[i])\r\n if a>1:\r\n l.remove(s[i])\r\nb=len(l) \r\nif b%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelif b%2!=0:\r\n print(\"IGNORE HIM!\")", "user = set(input())\r\nprint(\"CHAT WITH HER!\") if len(user)%2 == 0 else print(\"IGNORE HIM!\")", "username = input()\n\nd = {i for i in username}\nif len(d) % 2 == 0:\n\tprint(\"CHAT WITH HER!\")\nelse:\n\tprint(\"IGNORE HIM!\")\n", "name = input()\ntext =\"\"\nfor i in name: \n if i not in text:\n text += i\n \nprint((\"IGNORE HIM!\",\"CHAT WITH HER!\")[len(text)%2 == 0])\n\t \t \t \t \t\t\t\t\t\t \t\t\t\t\t\t \t\t \t", "name=input()\r\nname_count=set(name)#集合中所有元素要求互不相同#\r\nif len(name_count)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "username=input()\r\n\r\ndistinct=[]\r\nexisting=0\r\nfor i in username:\r\n for j in distinct:\r\n if i==j:\r\n existing=1\r\n if(existing==0):\r\n distinct.append(i)\r\n existing=0 \r\nif(len(distinct)%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\") ", "x=input()\r\ny=[ ]\r\nfor i in range(len(x)):\r\n\t\tif x[i] in y:\r\n\t\t continue\r\n\t\telse:\r\n\t\t y.append(x[i])\r\na=len(y)\r\nif a%2==0:\r\n\t\t print(\"CHAT WITH HER!\")\r\nelse:\r\n\t\t print(\"IGNORE HIM!\")", "list1 = []\r\nname = input()\r\ndef check(a):\r\n res = False\r\n for b in list1:\r\n if b == a:\r\n res = True\r\n return res\r\n\r\nfor y in name:\r\n if check(y) == False:\r\n list1.append(y)\r\n\r\nif len(list1) % 2 ==0:\r\n print(\"CHAT WITH HER!\")\r\n\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = input()\r\nusernames = {x for x in s}\r\nn = len(usernames)\r\n\r\nif n % 2 == 1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "s=input()\r\nk2=\"\"\r\nfor ele in s:\r\n\tif ele not in k2:\r\n\t\tk2=k2+ele\r\n\r\nif(len(k2)%2==1):\r\n print(\"IGNORE HIM!\")\r\nelif(len(k2)%2==0):\r\n print(\"CHAT WITH HER!\")\r\n", "# Input\r\nusername = input()\r\n\r\n# Count distinct characters in the username\r\ndistinct_chars = set(username)\r\n\r\n# Check if the count of distinct characters is even or odd\r\nif len(distinct_chars) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "s=input()\r\nx=\"\"\r\nfor i in range (len(s)):\r\n if s[i] not in x :\r\n x=x+s[i]\r\nif len(x)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse :\r\n print(\"IGNORE HIM!\")\r\n", "name=input()\r\nnamel=list(name)\r\nif len(set(namel))%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s1=input()\r\nl1=[]\r\nfor i in s1:\r\n if i not in l1:\r\n l1.append(i)\r\nn=len(l1)\r\nif n%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "s=input()\r\nk=[]\r\nfor i in s:\r\n k.append(i)\r\nk=set(k)\r\na=len(k)\r\nif(a%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n\r\n \r\n \r\n\r\n \r\n ", "array_chars = list(input().lower())\r\nunique_chars = []\r\nfor i in range(0, len(array_chars)):\r\n if array_chars[i] not in unique_chars:\r\n unique_chars += array_chars[i]\r\n\r\nif len(unique_chars)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=input()\r\nsets=set(s)\r\nif len(sets)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "st=input(\"\")\r\nseen = set()\r\n\r\nfor letter in st:\r\n if letter not in seen:\r\n seen.add(letter)\r\n \r\ncou=len(seen)\r\nif(cou%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "x=str(input())\r\nl1=[]\r\nfor i in x:\r\n l1.append(i)\r\ns1=set(l1)\r\nl2=list(s1)\r\nif(len(l2)%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "N = input()\r\n\r\ndef xoaTrung(N):\r\n result = \"\"\r\n for i in N:\r\n if i not in result:\r\n result = result +i\r\n return result\r\n\r\nN_plus = xoaTrung(N)\r\n\r\nlen = len(N_plus)\r\n\r\nif len%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "list=[]\r\nstring=str(input())\r\nfor i in string:\r\n if i not in list:\r\n list.append(i)\r\nif len(list)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "a= input()\r\narr=[]\r\nfor i in a:\r\n if i not in arr:\r\n arr.append(i)\r\nif len(arr)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')\r\n ", "name = input()\r\ndistinct_char = len(set(name))\r\n\r\nif distinct_char % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "name = input()\r\ncharacters = 0\r\n\r\nfor code in range(ord('a'), ord('z') + 1):\r\n if name.find(chr(code)) != -1:\r\n characters += 1\r\n\r\nif characters % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "s=set(list(input()))\r\nprint(\"CHAT WITH HER!\" if len(s)%2==0 else \"IGNORE HIM!\")", "t=input()\r\ndis_char=set(t)\r\nif len(dis_char)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "x=str(input())\r\nn=0\r\nfor i in range(97,123):\r\n if chr(i) in x:\r\n n=n+1\r\nif n%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "string = input()\r\nfile = list()\r\nfor i in string:\r\n if i in file:\r\n continue\r\n else:\r\n file.append(i)\r\nprint(\"CHAT WITH HER!\" if len(file) % 2 == 0 else \"IGNORE HIM!\")", "a = input()\r\nb = []\r\n\r\nfor i in a:\r\n if i not in b:\r\n b.append(i)\r\n\r\nif len(b)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "str1 = input()\r\nstr2 = set(str1)\r\nx = len(str2)\r\nif x%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s1 = input()\r\nd1 = dict.fromkeys(s1)\r\nif len(d1)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "a = input()\r\nb = list(a)\r\n\r\nunique_b = []\r\n\r\nfor i in b:\r\n if i not in unique_b:\r\n unique_b.append(i)\r\n\r\nif (len(unique_b)%2) == 0 :\r\n print(\"CHAT WITH HER!\")\r\nelse :\r\n print(\"IGNORE HIM!\")\r\n\r\n", "s = input()\r\n\r\ns1 = \"\"\r\nfor i in s:\r\n isHad = False\r\n for j in s1:\r\n if i == j:\r\n isHad = True\r\n if isHad == False:\r\n s1 += i\r\n\r\nn = len(s1)\r\n\r\nif n % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "a = input()\r\n\r\nb = []\r\n\r\nfor i in range(len(a)):\r\n if a[i] in b:\r\n continue\r\n else:\r\n b += a[i]\r\n\r\nif len(b) % 2 == 1:\r\n print(\"IGNORE HIM!\")\r\nif len(b) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n\r\n", "user = input()\r\nres = len(set(user))\r\n\r\nif res%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "letter = input()\r\ncount = []\r\nfor i in range(0,len(letter)):\r\n if letter[i] not in count:\r\n count.append(letter[i])\r\n\r\nif(len(count)%2 == 0):\r\n print(\"CHAT WITH HER!\\n\")\r\nelse:\r\n print(\"IGNORE HIM!\\n\")\r\n ", "name = input()\ndistinct_char = ''\n\nfor c in name:\n\n if c not in distinct_char:\n distinct_char = distinct_char + c\n \ncount = len(distinct_char)\n\nif count%2==1:\n print('IGNORE HIM!')\nelse:\n print('CHAT WITH HER!')\n \t\t\t\t \t \t\t\t \t \t \t \t\t \t\t \t", "userName = input()\r\nnh = [0 for i in range(26)]\r\ncount = 0\r\nfor i in userName:\r\n key = ord(i) % 26\r\n if nh[key] == 0:\r\n nh[key] = 1\r\n count += 1\r\n \r\nprint(\"IGNORE HIM!\" if count % 2 else \"CHAT WITH HER!\")", "s = input()\r\ns = sorted(s)\r\nn = len(s)\r\nans = 1\r\nfor i in range(1,n):\r\n if(s[i] != s[i-1]):\r\n ans += 1\r\nif(ans & 1):\r\n print(\"IGNORE HIM!\")\r\nelse: \r\n print(\"CHAT WITH HER!\")", "a=input()\r\nk=[0]*len(a)\r\ncount=len(a)\r\nfor i in range(len(a)):\r\n for j in range(i+1,len(a)):\r\n if a[i]==a[j] and k[i]==0 and k[j]==0:\r\n count=count-1\r\n k[j]=1\r\nif count%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=input()\r\nb=[]\r\nfor i in s:\r\n b.append(i)\r\nc=set(b)\r\nif len(c)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "username = input()\r\nstr = \"\"\r\nk = 0\r\nfor item in username:\r\n if item not in str:\r\n k += 1\r\n str += item\r\nif k % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "word = input()\r\nlength = len(word)\r\ncharacter = []\r\ncount = 0\r\n\r\nfor i in range(length):\r\n if word[i] in character:\r\n continue\r\n else:\r\n character.append(word[i])\r\n count += 1\r\n# print(count)\r\nif count % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=input()\r\ns=list(s)\r\nnum=0\r\na=[]\r\nfor i in s:\r\n if s.count(i)>1:\r\n if i in a:\r\n pass\r\n else:\r\n num-=1\r\n a.append(i)\r\n elif s.count(i)<=1:\r\n num+=1\r\nif num%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "usr = input()\r\nchars = []\r\nfor i in usr:\r\n if i not in chars:\r\n chars.append(i)\r\nif len(chars) % 2 == 0: print(\"CHAT WITH HER!\")\r\nelse: print(\"IGNORE HIM!\")", "name = input().strip()\r\n\r\ndn = set(name)\r\ncount = len(dn)\r\n\r\nif count%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "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 s = SI()\r\n if len(set(s)) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")\r\n\r\nif __name__ == \"__main__\":\r\n main()", "s=input()\r\na=list(s.strip())\r\nb=set(a)\r\n\r\nif(len(b)%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "# Read the user name as a string\r\nuser_name = input()\r\n\r\n# Count the number of distinct characters in the user name\r\ndistinct_chars = set(user_name)\r\n\r\n# Determine the gender based on the count\r\nif len(distinct_chars) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "s=input()\ng=set(s)\na=len(g)\nif a%2==0:\n print('CHAT WITH HER!')\nelse:\n print('IGNORE HIM!')", "string = input()\r\nls = set()\r\nfor i in string:\r\n ls.add(i)\r\nif len(ls)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "name = input()\r\ncharacters = set(name)\r\nif len(characters) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "import sys\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\ns = input().rstrip()\r\nk = len(set(s))\r\nprint(\"CHAT WITH HER!\" if k % 2 == 0 else \"IGNORE HIM!\")", "a = input()\r\nb = set(list(a))\r\nif len(b)%2==0:\r\n\tprint(\"CHAT WITH HER!\")\r\nelse:\r\n\tprint(\"IGNORE HIM!\")", "s = input()\r\n\r\nuniqueS = set()\r\n\r\nfor i in s: uniqueS.add(i)\r\n\r\nprint(len(uniqueS) % 2 and \"IGNORE HIM!\" or \"CHAT WITH HER!\")", "freq = [0] * 123\r\ns = input()\r\nfor i in s:\r\n freq[ord(i)] += 1\r\nres = 0\r\nfor i in range(97, 123):\r\n if freq[i]:\r\n res += 1\r\n\r\nif res & 1:\r\n print('IGNORE HIM!')\r\nelse:\r\n print('CHAT WITH HER!')", "b = input()\r\nunique_chars = set(b)\r\n\r\nif len(unique_chars) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "a=input()\r\ndict={}\r\nfor i in a:\r\n dict[i]=dict.get(i,0)\r\nif len(dict)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "print('CHAT WITH HER!' if len(set(list(input()))) % 2 == 0 else 'IGNORE HIM!')", "x=input()\r\nll=list(dict.fromkeys(list(x)))\r\nif (len(ll)% 2) == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n\r\n", "s = input()\r\nk = set(s)\r\nif (len(k)%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "t=list(input())\r\nnew_t=set(t)\r\nif len(new_t)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "# URL: https://codeforces.com/problemset/problem/236/A\nprint(\"IGNORE HIM!\" if len(set(input())) % 2 == 1 else \"CHAT WITH HER!\")\n", "username = input()\r\nr = \"\"\r\nfor i in username:\r\n if i not in r:\r\n r += i\r\nl = len(r)\r\nif l%2 == 0:\r\n print(\"CHAT WITH HER!\") \r\nelse:\r\n print(\"IGNORE HIM!\")", "print(\"CHAT WITH HER!\" if len(set(str(input())))%2 ==0 else \"IGNORE HIM!\")", "str1=input()\r\na=0\r\nfor i in range(97,123):\r\n if str1.find(chr(i))!=-1:\r\n a+=1\r\nif a%2==1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "x = input()\r\nresult = ''\r\n\r\nfor char in x:\r\n if char not in result:\r\n result += char\r\n\r\nif len(result) % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "name_examination = set(input().lower())\r\ncount = 0\r\nfresh_str = ''.join(name_examination)\r\nif len(fresh_str) % 2 != 0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "inputStr = input()\r\ndistintChar = {}\r\nfor i in inputStr:\r\n if i in distintChar:\r\n distintChar[i] += 1\r\n else:\r\n distintChar[i] = 1\r\nif len(distintChar)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "a = input()\r\na = set(a)\r\nif(len(a)%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse: print(\"IGNORE HIM!\")", "a = set()\r\nx = input()\r\nfor i in x:\r\n a.add(i)\r\nif len(a) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "# Read the input username\r\nusername = input()\r\n\r\n# Count the number of distinct characters in the username\r\ndistinct_chars = set(username)\r\n\r\n# Determine the gender based on the count of distinct characters\r\ngender = \"CHAT WITH HER!\" if len(distinct_chars) % 2 == 0 else \"IGNORE HIM!\"\r\n\r\n# Print the result\r\nprint(gender)\r\n\r\n \r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n \r\n", "name = input()\r\nstring = name\r\nvisited = []\r\nfor letter in name:\r\n if letter not in visited:\r\n visited.append(letter)\r\nl=len(visited)\r\nif l%2!=0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "d = {}\r\nx = input('')\r\nfor i in x:\r\n if d.get(i) == None: d.update({i:1})\r\n else: d.update({i:d.get(i)+1})\r\ny = [p for p,q in d.items()]\r\nif len(y)%2==0: print('CHAT WITH HER!')\r\nelse: print('IGNORE HIM!')", "str1 = str(input())\r\n\r\ntestSet = {i for i in str1}\r\n\r\nif len(testSet) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "l = input()\r\nl = list(l)\r\nl = set(l)\r\nif len(l)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n ", "def determine_gender(username):\r\n distinct_characters = set(username)\r\n num_distinct_characters = len(distinct_characters)\r\n \r\n if num_distinct_characters % 2 == 0:\r\n return \"CHAT WITH HER!\"\r\n else:\r\n return \"IGNORE HIM!\"\r\n\r\n# Read the input\r\nusername = input().strip()\r\n\r\n# Determine and print the gender based on the user name\r\nprint(determine_gender(username))", "n = str(input())\r\nothers = ''\r\n\r\nfor i in n:\r\n if i not in others:\r\n others += i\r\n\r\nprint('CHAT WITH HER!' if len(others) % 2 == 0 else 'IGNORE HIM!')", "username=input()\r\nnew_string=\"\"\r\ncount=0\r\nfor i in username:\r\n if i not in new_string:\r\n count=count+1\r\n new_string=new_string+i\r\nif count%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n \r\n \r\n \r\n \r\n", "user_name = input()\n\ndistinctofChars = set(user_name)\n\nif len(distinctofChars) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n \t\t \t\t \t\t\t\t \t\t\t \t \t\t\t\t\t\t", "str_in = input()\r\ndictionary = set()\r\nfor i in str_in:\r\n dictionary.add(i)\r\nif len(dictionary)%2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "palabra=input()\ncaracteres = []\n\nfor i in range(len(palabra)):\n if palabra[i] not in caracteres:\n caracteres.append(palabra[i])\nif len(caracteres)%2==0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n \t \t\t \t \t \t\t \t \t \t\t \t\t\t \t", "from collections import Counter\r\n\r\nst = list(input())\r\ncount = Counter(st)\r\nif len(count) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "# Read the user name\r\nuser_name = input()\r\n\r\n# Count the number of distinct characters\r\ndistinct_characters = set(user_name)\r\n\r\n# Check if the count is odd or even and output the result accordingly\r\nif len(distinct_characters) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "# la complejidad es o(usuario), pues depende de la cantidad de caracteres que tenga el nombre del usuario\nusuario = input().strip()\n\nc = len(set(usuario))\n\n\nif c % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n\t\t\t \t \t\t\t\t\t\t \t \t \t \t \t\t\t\t", "name = input()\r\n\r\nx = len(name)\r\ny = 0\r\nchrt = []\r\n\r\nwhile x > 0:\r\n if not (name[y] in chrt):\r\n chrt.append(name[y])\r\n x -= 1\r\n y += 1\r\n\r\nif len(chrt) % 2 == 1:\r\n print (\"IGNORE HIM!\")\r\nelse:\r\n print (\"CHAT WITH HER!\")", "a=input()\r\nd=set()\r\nc=0\r\nfor i in a:\r\n if i not in d:\r\n c=c+1\r\n d.add(i)\r\n#print(c)\r\nif c%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:print(\"IGNORE HIM!\")", "if len(set(input())) % 2 == 0: print('CHAT WITH HER!')\r\nelse: print('IGNORE HIM!')", "str = input()\r\na = []\r\nfor i in range(0, 26):\r\n a.append(0)\r\nfor i in range(0, len(str)) :\r\n a[ord(str[i])-97]+=1\r\ncount = 0\r\nfor i in range(0, 26):\r\n if a[i] > 0 :\r\n count += 1\r\nif count%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse :\r\n print(\"IGNORE HIM!\")", "def string_to_char_list(input_string):\r\n char_list = []\r\n for char in input_string:\r\n char_list.append(char)\r\n return char_list\r\ndef count_unique_chars(char_list):\r\n unique_chars = set(char_list)\r\n return len(unique_chars)\r\ns = input()\r\nx = string_to_char_list(s)\r\nl = count_unique_chars(x)\r\nif l % 2 ==0 :\r\n print(\"CHAT WITH HER!\")\r\nelse :\r\n print(\"IGNORE HIM!\")\r\n\r\n\r\n\r\n'''\r\nimport os\r\nos.system(\"cls\")\r\n\r\nn = int(input())\r\ncounter = 0\r\nwhile n > 0:\r\n x = 0\r\n for _ in range(3):\r\n x += int(input())\r\n if x >= 2:\r\n counter += 1\r\n n -= 1\r\nprint(counter)\r\n'''\r\n'''\r\nn = int(input()) # Number of problems\r\ncount = 0 # Count of problems they will implement\r\n\r\nfor _ in range(n):\r\n petya, vasya, tonya = map(int, input().split())\r\n # Count how many friends are sure about the solution\r\n sure_count = petya + vasya + tonya\r\n if sure_count >= 2:\r\n count += 1\r\n\r\nprint(count)\r\n'''", "# l = [1,0,0,0,4,2,0,0,0,1,2,0,8,0,6,0,0,9,12]\r\n# print(len(l))\r\n# # def fun(l):\r\n# # \tnonzero = []\r\n# # \tzero = []\r\n# # \tfor i in l:\r\n# # \t\tif(i==0):\r\n# # \t\t\tzero.append(0)\r\n# # \t\telse:\r\n# # \t\t\tnonzero.append(i)\r\n# # \tnonzero.extend(zero)\r\n# # \treturn nonzero\r\n# # print(fun(l))\r\n\r\n# def opt_fun(l):\r\n# \ti = 0\r\n# \tj = 0\r\n# \tn = len(l)\r\n# \twhile(j<n):\r\n# \t\tif l[j]!=0:\r\n# \t\t\tl[i]=l[j]\r\n# \t\t\ti+=1\r\n# \t\tj+=1\r\n# \tk= i\r\n# \tz = j-i\t\r\n\r\n# \twhile(i<n):\r\n# \t\tl[i]=0\r\n# \t\ti+=1\r\n# \tnz = n-j-i\r\n# \tprint(nz)\r\n# \t# l[n-(k//2):]=l[(k-(k//2)):k]\r\n# \t# l[(k-(k//2)):k] = [0]*(k//2)\r\n\t\r\n\t\r\n\t\r\n\r\n\r\n\t\r\n\r\n# \treturn l\r\n# print(opt_fun(l))\r\n\r\n\r\n# l = input().split('+')\r\n# print(sum(l))\r\ns = input()\r\nif len(set(s))%2:print(\"IGNORE HIM!\")\r\nelse:print(\"CHAT WITH HER!\")", "arr = set(input())\r\nif len(arr)%2 == 0:\r\n\tprint(\"CHAT WITH HER!\")\r\nelse:\r\n\tprint(\"IGNORE HIM!\")\r\n", "# https://codeforces.com/problemset/problem/236/A\r\n\r\n# Time complexity: O(N) Linear time complexity\r\n# Space complexity: O(1) Constant space complexity\r\ndef solve(name):\r\n distinct_letters = set()\r\n for letter in name:\r\n distinct_letters.add(letter)\r\n\r\n if len(distinct_letters) % 2 == 0:\r\n return \"CHAT WITH HER!\"\r\n else:\r\n return \"IGNORE HIM!\"\r\n\r\nname = input()\r\nprint(solve(name))\r\n", "name = input()\r\nreal_name = set(name)\r\nif len(real_name) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "inp = input()\r\ndef split_string(s):\r\n return list(s)\r\ninp = split_string(inp)\r\nlist = []\r\nfor item in inp:\r\n if item not in list:\r\n list.append(item)\r\n \r\na = len(list)\r\nif a % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "s = input()\r\nn = set(s)\r\n#print(n)\r\nsuma = 0\r\nfor i in n:\r\n suma += 1\r\nif suma % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse: print(\"IGNORE HIM!\")", "user_name = str(input())\r\n\r\ndistinct = len(set(user_name))\r\n\r\nif (distinct%2 == 0): print(\"CHAT WITH HER!\")\r\nelse: print(\"IGNORE HIM!\")", "x=input()\r\nch=ord('a')\r\nc=0\r\nwhile(ch<=ord('z')):\r\n\tif chr(ch) in x:\r\n\t\tc+=1\r\n\tch+=1\r\n\t\r\nif(c%2==0):\r\n\tprint(\"CHAT WITH HER!\")\r\nelse:\r\n\tprint(\"IGNORE HIM!\")", "s = input()\r\ns1 = ''\r\nfor i in s:\r\n if i not in s1:\r\n s1+=i\r\n\r\nif len(s1)<100 and s1.islower():\r\n if len(s1)%2!=0:\r\n print('IGNORE HIM!')\r\n else:\r\n print('CHAT WITH HER!')", "name= input()\nnewName=''\nfor letter in name:\n if letter not in newName:\n newName+=letter\n else: continue\nif len(newName)%2==0: \n print('CHAT WITH HER!')\nelse:\n print(\"IGNORE HIM!\")\n\n \t \t\t\t\t\t\t \t\t\t\t \t \t\t\t\t \t\t", "inp = list(input())\ntrack = []\ncount = 0\nfor i in inp:\n if i not in track:\n track.append(i)\n count += 1\n\nif count%2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n", "user = input()\nlist = []\n\nfor i in range(len(user)):\n letter = user[i]\n if letter not in list:\n list.append(letter)\nif len(list) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")", "s = input()\ntrack = {}\ncount = 0\nfor c in s:\n if not c in track:\n track[c] = 1\n count += 1\nif count % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n", "\"\"\"\r\nCreated on Thu Nov 2 10:34:36 2023\r\n\r\n@author: Daksh\r\n\r\nQuestions: \r\n\"\"\"\r\n\r\nx = input(\"\")\r\nv = set(x)\r\nq = len(v)\r\nif q % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "def name():\r\n in_string = input()\r\n character_list = set()\r\n unique = 0\r\n\r\n for character in in_string:\r\n if character not in character_list :\r\n unique += 1\r\n character_list.add(character)\r\n\r\n print(\"CHAT WITH HER!\" if unique % 2 ==0 else \"IGNORE HIM!\")\r\n\r\nname()", "li=[i for i in input()]\r\nk=len(set(li))\r\nif k%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=input()\r\ns1=len(s)\r\nl=[]\r\nfor i in s:\r\n if(i not in l):\r\n l.append(i)\r\n else:\r\n continue\r\nif((len(l)%2)==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "\r\nword = input()\r\nlst1 = []\r\nfor i in word:\r\n if i not in lst1:\r\n lst1.append(i)\r\nif len(lst1) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "def findOut(username):\r\n if( len(set(username))%2 == 0):\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")\r\n\r\nif __name__ == \"__main__\":\r\n username = input()\r\n findOut(username)", "a = str(input())\r\na = set([e for e in a])\r\nif len(a) % 2:print('IGNORE HIM!')\r\nelse:print('CHAT WITH HER!')", "s=input()\r\nd={}\r\nt=''\r\nfor i in s:\r\n if i in d:\r\n d[i]+=1\r\n else:\r\n d[i]=1\r\nfor i in d:\r\n t+=i\r\nif len(t)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "a=input()\r\na=set(a)\r\na=list(a)\r\na=len(a)\r\nif a%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "string = list(input())\r\nnewList = []\r\nfor item in string:\r\n if(item not in newList):\r\n newList.append(item)\r\n\r\ncount = len(newList)\r\nif(count%2==1):\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "string =\"\"\nst = str(input())\r\nstri = set()\r\nfor i in st:\r\n stri.add(i)\r\nif (len(stri)%2==0):\n string += \"CHAT WITH HER!\"\nelse:\n string += \"IGNORE HIM!\"\nprint(string)\n", "s=input()\r\na=len(set(s))\r\nif(a%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "name=input()\r\nName=\"\"\r\nfor i in range(len(name)):\r\n if name[i] not in Name:\r\n Name+=name[i]\r\nif len(Name)%2!=0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "def 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))\r\ndef m():\r\n return(map(int,input().split()))\r\n\r\na = s()\r\n\r\nb = set()\r\nfor n in a:\r\n b.add(n)\r\n\r\nif len(b) % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "strInput = str(input())\r\nuniqueLetters = []\r\nfor i in range(len(strInput)):\r\n if strInput[i] in uniqueLetters:\r\n continue\r\n else:\r\n uniqueLetters.append(strInput[i])\r\nif len(uniqueLetters) % 2 == 0: print(\"CHAT WITH HER!\")\r\nelse: print(\"IGNORE HIM!\")", "c=input()\r\nz=len(set(c))\r\nif(z%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "username=input()\r\ndistinct_characters=len(set(username))\r\nif distinct_characters%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "a = input()\r\ndis = set(a)\r\nx = list(dis)\r\nif len(x) %2 == 0 :\r\n \r\n print('CHAT WITH HER!')\r\nelse : \r\n print('IGNORE HIM!')", "st = input()\r\ns = []\r\n\r\nfor i in st:\r\n if i in s:\r\n None\r\n else:\r\n s.append(i)\r\nif len(s) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=str(input())\r\nL=set(list(s))\r\nif len(L)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "s=input();\r\na=[];\r\nn=0;\r\nfor i in s:\r\n if(i not in a):\r\n a.append(i);\r\n n=n+1;\r\nif(n%2==0):\r\n print(\"CHAT WITH HER!\");\r\nelse:\r\n print(\"IGNORE HIM!\");", "# Read the user name\r\nuser_name = input()\r\n\r\n# Count the number of distinct characters\r\ndistinct_chars = len(set(user_name))\r\n\r\n# Check if the count is even or odd and print the result\r\nif distinct_chars % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "a = input()\r\nb = len(set(a))\r\nif b % 2 == 1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "a = str(input())\nx = len(a)\nl = 0\ns = 0\nfor i in range(x):\n v = a[i]\n for z in range(i+1):\n v1=a[z]\n if v1 != v:\n l = l+1\n if l == i:\n s = s+1\n l = 0\n else:\n l = 0\n s = s\nif s%2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n \n \n \n\n \n \n", "chars = input()\n\nprint(\n \"CHAT WITH HER!\" if len(set(chars)) % 2 == 0 else \"IGNORE HIM!\"\n)\n\n\n\n\n# NOTES\n# use set()", "# Input the username\r\nusername = input()\r\n\r\n# Calculate the number of distinct characters in the username\r\ndistinct_chars = set(username)\r\n\r\n# Check if the count of distinct characters is odd or even\r\nif len(distinct_chars) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "a=input()\r\nletter=[]\r\nfor i in a:\r\n if i not in letter:\r\n letter += [i]\r\n \r\nll=len(letter)\r\nif ll%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')\r\n", "s = str(input())\r\ndef check(s):\r\n unique = set(s)\r\n return len(unique)\r\nif check(s)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "a=input()\r\ns=set(a)\r\nb=len(s)\r\nif int(b)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=input()\r\nd=list(set(s))\r\nif len(d)%2==1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "x=str(input())\r\nnb=0\r\nch=''\r\nfor i in range (len(x)) :\r\n if ch.find(x[i])==-1 :\r\n nb=nb+1\r\n ch=ch+x[i]\r\nif nb%2==0:\r\n print('CHAT WITH HER!')\r\nelse :\r\n print('IGNORE HIM!')\r\n", "print(\"IGNORE HIM!\") if len(set(input())) % 2 else print(\"CHAT WITH HER!\")", "s=input()\r\na=set([])\r\nfor i in range(len(s)):\r\n a.add(s[i])\r\n\r\nif len(a)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "usr=str(input())\r\nusrname=[]\r\nif(len(usr)<=100):\r\n for ch in usr:\r\n usrname.append(ch)\r\n\r\n new_usrname=[]\r\n \r\n for i in usrname:\r\n if i not in new_usrname:\r\n new_usrname.append(i)\r\n \r\n if(len(new_usrname)%2==0):\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")", "s=input()\r\nsu=0\r\nd=len(s)\r\nfor i in range(d):\r\n if s[0:i].find(s[i])==-1:\r\n su=su+1\r\nif su%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "n = input()\r\nm = []\r\nfor i in n:\r\n if i not in m:\r\n m.append(i)\r\n\r\nif len(m) % 2 != 0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "s=input()\r\ns1=set({})\r\nfor i in s:\r\n s1.add(i)\r\nif len(s1)%2==0:print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "# Read input\r\nusername = input()\r\n\r\n# Count the number of distinct characters\r\ndistinct_characters = set(username)\r\n\r\n# Check if the number of distinct characters is odd\r\nif len(distinct_characters) % 2 == 1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")\r\n", "#gets username and finds the unique letters in the name\r\nusername = input()\r\nuniqueLetters = set(username)\r\n\r\n#prints message based on remainder when divided by 2 (checks if even or odd number)\r\nif len(uniqueLetters) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print('IGNORE HIM!')", "s = str(input())\nl = []\n\nfor i in s:\n if i in l:\n continue\n else:\n l.append(i)\n\nif((len(l)) % 2 == 0):\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n \t\t\t\t\t \t\t\t \t \t\t \t \t \t \t\t", "user = str(input())\r\nlist = [None]*len(user)\r\ni = 0\r\ncount = 0\r\nwhile i < len(user):\r\n if user[i] not in list:\r\n list[i] = user[i]\r\n count = count + 1\r\n i = i + 1\r\nif count % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "nombre_usuario = input()\ncaracteres_distintos = set(nombre_usuario)\n\nif len(caracteres_distintos) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n\n\t \t\t \t \t\t \t\t\t \t\t\t \t\t \t \t \t", "letters = []\r\ns = input()\r\ncount = 0\r\n\r\nfor i in range(len(s)):\r\n if s[i] not in letters:\r\n letters.append(s[i])\r\n else:\r\n pass\r\n\r\nif (len(letters) % 2 == 0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "result = \"\"\r\nusername = input()\r\nletters = set()\r\nnumOfCharacters = len(username)\r\nif 1 <= numOfCharacters and numOfCharacters <= 100:\r\n for letter in username:\r\n letters.add(letter)\r\n numOfCharacters = len(letters)\r\n if numOfCharacters % 2 == 0:\r\n result = \"CHAT WITH HER!\"\r\n else:\r\n result = \"IGNORE HIM!\"\r\nprint(f\"{result}\")", "input = list(input())\r\n\r\ninput = dict.fromkeys(input)\r\nsum = len(input)\r\n\r\nif sum % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "word = input()\r\nvisit = set()\r\nfor i in word:\r\n visit.add(i)\r\nif len(visit) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n\r\n", "s=input()\r\ns=s.replace('',' ')\r\ns=list(s.split())\r\nif len(set(s))%2==1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "s = set(input())\r\nif len (s) % 2== 0:\r\n print ('CHAT WITH HER!')\r\nelse:\r\n print ('IGNORE HIM!')\r\n", "# A. Boy or Girl\r\n\r\n\r\nusername = input()\r\ndistinctUsername = \"\"\r\nfor char in username:\r\n if char not in distinctUsername:\r\n distinctUsername += char\r\n\r\nif len(distinctUsername) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "username = input()\r\nletters = list(username)\r\n\r\ndistinct_characters = set(letters)\r\ncount = len(distinct_characters)\r\n\r\nif count % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "n = input()\r\nbetuk = [0]*26\r\nfor i in n:\r\n betuk[ord(i)-97] = 1\r\nres = 0\r\nfor i in betuk:\r\n res += i\r\nif res%2==0: \r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = input()\r\na = set(s)\r\nprint(\"CHAT WITH HER!\") if len(a)%2==0 else print(\"IGNORE HIM!\")", "nombre_usuario = input()\r\ncaracteres_unicos = set(nombre_usuario)\r\nif len(caracteres_unicos) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "w = input()\r\nlist = []\r\nfor i in w:\r\n if i not in list:\r\n list.append(i)\r\n else:\r\n continue\r\nif len(list)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "print(\"CHAT WITH HER!\" if len({x: 0 for x in list(input())})%2==0 else \"IGNORE HIM!\")", "x=input()\r\ny=set(x)\r\nif len(y)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "nick = input()\r\nletters = []\r\nfor leter in nick:\r\n if leter not in letters:\r\n letters.append(leter)\r\nif len(letters)%2:\r\n print('IGNORE HIM!')\r\nelse:\r\n print('CHAT WITH HER!')", "def main():\r\n s = input()\r\n str=set(s)\r\n if len(str)%2==0:\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")\r\nmain()", "a = input()\r\nda = []\r\nfor i in a:\r\n if i in a:\r\n if i not in da:\r\n da.append(i)\r\n\r\nif len(da) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse :\r\n print(\"IGNORE HIM!\")", "name = input()\r\nunique = set(name)\r\nif (len(unique)-1) % 2 == 0:\r\n print(\"IGNORE HIM!\")\r\nelse: print(\"CHAT WITH HER!\")", "S = input()\r\nArr = []\r\nArr.extend(S)\r\nArr = set(Arr)\r\nif len(Arr) % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "n1 = input()\r\ncount_dict = dict()\r\nresult = \"CHAT WITH HER!\"\r\nfor i in n1:\r\n count_dict[i] = count_dict.get(i, 0) + 1\r\nif len(count_dict.keys()) %2 != 0:\r\n result = \"IGNORE HIM!\"\r\n\r\nprint(result)", "print(\"CHAT WITH HER!\" if not len(set([i for i in input()]))&1 else \"IGNORE HIM!\")\r\n", "x=input()\r\ny = []\r\nfor i in x :\r\n if i not in y :\r\n y.append(i)\r\n else:\r\n continue\r\nif len(y)%2==0 :\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "borg = input()\r\nborg = \"\".join(set(borg))\r\nif len(borg) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=input(\"\")\r\nlst=[]\r\ncount=0\r\nfor i in s:\r\n if i not in lst:\r\n lst.append(i)\r\n count+=1\r\n\r\nif(count%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "# Input\r\nuser_name = input().strip()\r\n\r\n# Count the number of distinct characters using a set\r\ndistinct_characters = set(user_name)\r\n\r\n# Determine the gender based on the count\r\nif len(distinct_characters) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "str1 = input()\r\nl1 = list(str1)\r\n\r\ns1 = set(l1)\r\n\r\nif len(s1)%2 != 0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "user_name = input() # Read the user name as a string\r\ndistinct_characters = set(user_name) # Create a set of distinct characters\r\n\r\nif len(distinct_characters) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n\r\n", "a=input()\r\nb=set(a)\r\nif len(b)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "# Boy or Girl\r\n\r\ns = input()\r\n\r\ndis =[]\r\ndistinct_len = 0\r\nfor i in range(len(s)):\r\n if s[i] in dis:\r\n continue\r\n else:\r\n dis.append(s[i])\r\n distinct_len += 1 \r\n\r\nif distinct_len % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\") ", "string=input()\r\nli=[]\r\ncount=0\r\nfor _ in string:\r\n if _ not in li:\r\n li.append(_)\r\n\r\nif(len(li)%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n ", "v=0\r\ns=0\r\nz='A'\r\ny=0\r\np=0\r\nx = list(input())\r\nx.sort()\r\nfor i in range(len(x)):\r\n if x[i] == z:\r\n v += 1\r\n else :\r\n s = 0\r\n z = x[i]\r\np = int(len(x) - int(v))\r\ny = p\r\nif y % 2 != 0 :\r\n print(\"IGNORE HIM!\")\r\nelif y % 2 == 0 :\r\n print(\"CHAT WITH HER!\")\r\nelse :\r\n s = 0", "a=input()\r\nl=[x for x in a]\r\ns=set(l)\r\nif len(s)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "s = input()\r\nn = len(set(s))\r\nif(n%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "usuario=input()\r\n\r\nl=[]\r\nfor i in usuario:\r\n if i not in l:\r\n l.append(i)\r\n\r\nn=len(l)%2\r\nif n==0:\r\n print('CHAT WITH HER!')\r\n\r\nelse:\r\n print('IGNORE HIM!')\r\n", "\na = input()\n\n\ndef hello(str):\n\ttemp = []\n\tcount = 0\n\tfor x in a:\n\t\tif x in temp:\n\t\t\tpass\n\t\telse:\n\t\t\ttemp.append(x)\n\t\t\tcount = count + 1\n\t\n\tif count % 2 == 0:\n\t\tprint('CHAT WITH HER!')\n\telse:\n\t\tprint('IGNORE HIM!')\n\t\n\n\nhello(a)", "name = list(input())\r\narrChars = []\r\nfor i in name:\r\n if i not in arrChars:\r\n arrChars.append(i)\r\nif len(arrChars)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s=list(input())\r\nu = []\r\nfor item in s:\r\n if item not in u:\r\n u.append(item)\r\nif len(u)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "strs = input()\r\nnewstr=\"\"\r\nfor i in strs:\r\n if i not in newstr:\r\n newstr+=i\r\nif len(newstr) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n ", "user_name = input()\r\ndistinct_user_name = ''.join(set(user_name))\r\nif len(distinct_user_name)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "user = set(input())\r\nif len(user) % 2.0 == 0.0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "import sys\r\nclass FastReader:\r\n def __init__(self):\r\n self.br = sys.stdin\r\n self.st = []\r\n\r\n def next(self):\r\n while not self.st:\r\n try:\r\n self.st = next(self.br).strip().split()\r\n except EOFError:\r\n pass\r\n temp = self.st[0]\r\n self.st = self.st[1:]\r\n return temp\r\n\r\n def nextInt(self):\r\n return int(self.next())\r\n\r\n\r\nif __name__ == \"__main__\":\r\n sc = FastReader()\r\n\r\n s = sc.next()\r\n uniques = [False] * 26\r\n count = 0\r\n for c in s:\r\n index = ord(c) - 97\r\n if not uniques[index]:\r\n count += 1\r\n uniques[index] = True\r\n \r\n if count % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")\r\n \r\n", "\r\nx = input(\"\")\r\ny = []\r\nfor i in x:\r\n y.append(i)\r\n\r\nz = []\r\nz.append(y[0])\r\nfor j in range(0, len(y)):\r\n if y[j] not in z:\r\n z.append(y[j])\r\nif len(z) % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')\r\n\r\n\r\n", "a= input()\r\na = set(a)\r\nif len(a)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "def BoyOrGirl(a):\r\n a=set(a)\r\n if(len(a)%2==0):\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")\r\n \r\n\r\nif __name__==\"__main__\":\r\n a=list(input())\r\n BoyOrGirl(a)", "def main():\n username = input()\n unique_chars = set(username)\n number_of_unique_chars = len(unique_chars)\n if (number_of_unique_chars % 2 == 0):\n print(\"CHAT WITH HER!\")\n else:\n print(\"IGNORE HIM!\")\n\n\nif __name__ == '__main__':\n main()", "n= input()\r\n\r\nfor i in range(len(n)):\r\n dict1={}\r\n for j in n:\r\n if j not in dict1:\r\n dict1[j]=1\r\n else:\r\n dict1[j]+=1\r\n\r\nif len(dict1)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "a = set()\r\nb = input()\r\nfor i in b:\r\n a.add(i)\r\nif len(a)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "b = 0\r\na = (input())\r\nif 'q' in a:\r\n b += 1\r\nif 'w' in a:\r\n b += 1\r\nif 'e' in a:\r\n b += 1\r\nif 'r' in a:\r\n b += 1\r\nif 't' in a:\r\n b += 1\r\nif 'y' in a:\r\n b += 1\r\nif 'u' in a:\r\n b += 1\r\nif 'i' in a:\r\n b += 1\r\nif 'o' in a:\r\n b += 1\r\nif 'p' in a:\r\n b += 1\r\nif 'a' in a:\r\n b += 1\r\nif 's' in a:\r\n b += 1\r\nif 'd' in a:\r\n b += 1\r\nif 'f' in a:\r\n b += 1\r\nif 'g' in a:\r\n b += 1\r\nif 'h' in a:\r\n b += 1\r\nif 'j' in a:\r\n b += 1\r\nif 'k' in a:\r\n b += 1\r\nif 'l' in a:\r\n b += 1\r\nif 'z' in a:\r\n b += 1\r\nif 'x' in a:\r\n b += 1\r\nif 'c' in a:\r\n b += 1\r\nif 'v' in a:\r\n b += 1\r\nif 'b' in a:\r\n b += 1\r\nif 'n' in a:\r\n b += 1\r\nif 'm' in a:\r\n b += 1\r\nif b % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "x= str(input())\r\nsetx= set()\r\ni = 0\r\nlength =len(x)\r\nwhile (i < length):\r\n elment = x[i]\r\n i = 1+ i \r\n setx.add(elment)\r\n\r\nif len(setx)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "x=input()\r\nl=[]\r\nfor i in range(len(x)):\r\n if x[i] not in l:\r\n l.append(x[i])\r\n\r\nd=len(l)\r\nif(d%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "n = list(input())\r\n\r\noutput = []\r\n\r\nfor x in n:\r\n if x not in output:\r\n output.append(x)\r\n\r\nsex = ''\r\nif len(output)%2 == 0:\r\n sex = 'CHAT WITH HER!'\r\nelse:\r\n sex = 'IGNORE HIM!'\r\n \r\nprint(sex)", "userid=input()\narray=[]\nfor i in range(len(userid)):\n if userid[i] in array:\n continue\n else:\n array.append(userid[i])\nif len(array)%2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n\n", "name=input()\r\ndist_letter=''.join(set(name))\r\nans=''\r\nif(len(dist_letter)%2==0):\r\n ans='CHAT WITH HER!'\r\nelse:\r\n ans='IGNORE HIM!'\r\nprint(ans)\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Sep 22 13:31:26 2023\r\n\r\n@author: 25419\r\n\"\"\"\r\n\r\ns=set(input())\r\nif len(s)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:print('IGNORE HIM!')", "# -*- coding: utf-8 -*-\n\"\"\"Funny Forces Attempt Boy or girl\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1ACc0-lS8jHSfydnEY6q0Yncu5cV7TCkM\n\"\"\"\n\ne = set(input(\"\"))\nw = len(e)\nif w % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")", "name=input()\nnum=(set(name))\nc=(len(num))\nif c%2==0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n\n \t\t\t\t\t \t\t\t \t\t\t \t\t \t \t", "n = input()\r\n\r\na = set(n.lower())\r\n\r\nlength = len(a)\r\n\r\nif length%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "username = str(input())\r\ncharacters = set(username)\r\nif len(characters)%2!=0:\r\n print(\"IGNORE HIM!\")\r\nelif len(characters)%2==0:\r\n print(\"CHAT WITH HER!\")", "s=str(input())\r\nl=[i for i in s]\r\na=set(l)\r\nb=list(a)\r\nif len(b)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "a=input()\r\nb=set(a)\r\nk=len(b)\r\nif k%2==0:\r\n print ('CHAT WITH HER!')\r\nelse:\r\n print ('IGNORE HIM!')", "def solve(word):\r\n word = list(word)\r\n new_word = set(word)\r\n \r\n if len(new_word) % 2 == 1:\r\n print(\"IGNORE HIM!\")\r\n else:\r\n print(\"CHAT WITH HER!\")\r\n\r\ndef main():\r\n \r\n word = input().strip() # string values\r\n # Call the solve function\r\n solve(word)\r\n\r\nif __name__ == \"__main__\":\r\n main()", "txt = input()\r\nx = []\r\nfor char in txt:\r\n if char in txt:\r\n x.append(char)\r\n txt = txt.replace(char, \"\")\r\nif len(x) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "from sys import stdin\r\n#\r\ndef main():\r\n line = [x for x in stdin.readline().strip()]\r\n count = 0\r\n act = \"\"\r\n for i in range(len(line)):\r\n if line[i] not in act:\r\n count += 1\r\n act += line[i]\r\n if count % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")\r\nmain()", "s = input()\r\ncount = len(set([char for char in s]))\r\nif count % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "a = input()\r\nsom = 0\r\n\r\nfor i in range(len(a)):\r\n bo = True\r\n for j in range(i+1, len(a)):\r\n if a[i] == a[j]:\r\n bo = False\r\n if bo:\r\n som += 1\r\nif som % 2 != 0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")\r\n", "b=str(input())\r\nm=set(b)\r\nif len(m)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "# wjmzbmr\r\n# =========\r\n# CHAT WITH HER!\r\n\r\n# xiaodao\r\n# =========\r\n# IGNORE HIM!\r\n\r\na = input()\r\ni = len(set(x for x in a))\r\nif i % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "l = list([])\r\n\r\nfor i in range(0,26):\r\n l.append(0)\r\n\r\ndistinct = 0\r\n\r\ns = input()\r\n\r\nfor i in range(0, len(s)):\r\n l[ord(s[i])-97] = 1\r\n\r\nfor i in range(0, 26):\r\n if l[i] == 1:\r\n distinct += 1\r\n\r\nif distinct % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n\r\nelse:\r\n print(\"IGNORE HIM!\")", "#import math\r\nfrom collections import Counter\r\ndef solve(s):\r\n return \"CHAT WITH HER!\" if len(dict(Counter(s))) % 2 == 0 else \"IGNORE HIM!\"\r\n \r\n\r\n# T = int(input())\r\n# for i in range(T):\r\n#input()\r\n#s = list(map(int, input().split()))\r\nprint(solve(input()))\r\n\r\n", "s=str(input())\r\na=\"\"\r\nfor i in s:\r\n if i not in a:\r\n a+=i\r\nk=len(a)\r\nif (len(a)%2==0): \r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "un = set(input())\r\n\r\nif len(un)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n\r\n", "n = list(input().lower())\r\nm = {i for i in n}\r\nprint(\"CHAT WITH HER!\") if len(m) % 2 == 0 else print(\"IGNORE HIM!\")\r\n", "a=input()\nl=[i for i in a]\nl=set(l)\nif len(l)%2==0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'''\nl=[[1,2,3],[1,2,3],[1,2,3]]\nd=[[21,12,43],[11,21,30],[21,12,53]]\nf=[[0,0,0],[0,0,0],[0,0,0]]\nfor i in range(len(l)):\n for j in range(len(l[i])):\n print(l[i][j],end=' ')\n print()\nfor i in range(len(d)):\n for j in range(len(d[i])):\n print(d[i][j],end=' ')\n print()\nfor i in range(len(l)):\n for j in range(len(l[i])):\n f[i][j]=l[i][j]+d[i][j]\nfor i in range(len(f)):\n for j in range(len(f[i])):\n print(f[i][j],end=' ')\n print()\n'''\n\n \n \n \n", "s=input()\r\n\r\nc=len(set(s))\r\n\r\nif(c%2==1):\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")\r\n", "#male or female\ns = input()\nfrom collections import Counter\nc=Counter(s)\n#print(c.values())\nif len(c.keys()) % 2==0: #even= f\n print(\"CHAT WITH HER!\")\nelse:\n print('IGNORE HIM!')\n\t\t \t\t\t \t \t\t\t\t \t \t\t", "flag=1\r\ncount=0\r\ns=str(input())\r\nfor i in range(len(s)):\r\n for j in range(i+1,len(s)):\r\n if s[j]==s[i]:\r\n flag=0\r\n if flag==1:\r\n count=count+1\r\n flag=1\r\nif count%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "#!/usr/bin/env python\n# coding: utf-8\n\n# In[2]:\n\n\nname = input()\nnameset = set(name)\nif len(nameset)%2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n\n\n# In[ ]:\n\n\n\n\n", "s=input()\r\nc=0\r\nfor i in range(97,123):\r\n if s.count(chr(i))>=1:\r\n c+=1\r\n#print(c)\r\nif c%2==1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")\r\n", "s = input(\"\")\r\nL = []\r\ntemp = []\r\nfor i in s:\r\n L.append(i) \r\nL.sort()\r\nfor j in L:\r\n if j not in temp:\r\n temp.append(j)\r\n\r\n\r\nif len(temp)%2 != 0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "s=input()\r\nd={}\r\ncnt=0\r\nfor i in s:\r\n if i not in d:\r\n d[i]=0\r\n cnt+=1 \r\nif cnt%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "str = input()\r\nsett = set(str)\r\nm = len(sett)\r\nif(m&1) !=1:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "l=list(input())\r\ndl=[]\r\nfor i in l:\r\n if i not in dl:\r\n dl.append(i)\r\nif len(dl)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "\r\n\r\ns = input()\r\nmyset = set()\r\nfor char in s:\r\n myset.add(char)\r\n\r\nlength = len(myset)\r\nif length % 2 != 0:\r\n print(\"IGNORE HIM!\")\r\nelse: \r\n print(\"CHAT WITH HER!\")\r\n\r\n\r\n\r\n\r\n\r\n", "username = input()\nx = len(set(username))\n\nif x % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n \t\t \t \t\t \t \t\t \t\t\t", "n=input()\r\np=\"\"\r\nfor char in n:\r\n if char not in p:\r\n p+=char\r\nn=int(len(p))\r\nif n%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "import collections\r\nstring = str(input().lower())\r\nch_counts = collections.Counter(string)\r\ny = len(ch_counts)\r\nif y % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "x=input(\"\")\r\nx=set(x)\r\nif len(x)%2==1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")\r\n", "s = input()\r\nprint(\"CHAT WITH HER!\" if len(set(s))%2 == 0 else \"IGNORE HIM!\")", "d = set()\r\ns = input()\r\nfor i in s:\r\n d.add(i)\r\nif(len(d)%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = input()\r\ns = ''.join(sorted(s))\r\nl = len(s)\r\nans = 0\r\n\r\nfor i in range(1, l):\r\n if s[i] != s[i - 1]:\r\n ans += 1\r\n\r\nif ans % 2 == 1:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "#236A: Boy or Girl\r\naa236 = []\r\na236 = input()\r\nfor i in a236:\r\n aa236.append(i)\r\nsaa236 = set(aa236)\r\nif(len(saa236))%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "str1=input(\"\")\r\nl=[' ']\r\nfor i in str1:\r\n if i in l:\r\n continue\r\n l.append(i)\r\nn=len(l)-1\r\nif n%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = input()\nss = set(s)\nif len(ss)%2 == 0 :\n print('CHAT WITH HER!')\nelse :\n print('IGNORE HIM!')", "hs = input()\r\nhs = [*hs]\r\nchecked = []\r\ncontador = 0\r\n\r\nfor dato in hs:\r\n if dato not in checked:\r\n contador += 1\r\n checked.append(dato)\r\n \r\nif contador%2 != 0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "s = input()\r\nlst = []\r\nk = 0\r\nfor x in s:\r\n if x.lower() not in lst:\r\n k+=1\r\n lst.append(x.lower())\r\nif k%2:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "s=input()\r\na=set(s)\r\nc=0\r\nfor i in range(len(a)):\r\n c=c+1\r\nif c%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "# I'm The King Of Pirates\r\n\r\na = input()\r\nl = set(a)\r\n\r\nif len(l)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n\r\nelif len(l)%2 == 1 :\r\n print(\"IGNORE HIM!\")\r\n", "name = input(\"\")\r\nname_size = len(name)\r\nname_sort = sorted(name)\r\nfor i in range (len(name)-1):\r\n if name_sort[i] == name_sort[i+1]:\r\n name_size-=1\r\nif (name_size %2 ==0 ):\r\n print(\"CHAT WITH HER!\")\r\nelse: print(\"IGNORE HIM!\") ", "def determine_gender(username):\n distinct_characters = set(username)\n if len(distinct_characters) % 2 == 0:\n return \"CHAT WITH HER!\"\n else:\n return \"IGNORE HIM!\"\n\n# Read input\nusername = input()\n\n# Call the function\nresult = determine_gender(username)\n\n# Print the result\nprint(result)\n\n \t\t\t \t \t \t \t\t\t\t \t\t", "s=input() \r\nv=set(s) \r\nprint(\"CHAT WITH HER!\" if not len(v)%2 else \"IGNORE HIM!\") ", "user_name = input().strip() \r\n\r\nif 1 <= len(user_name) <= 100 and user_name.islower():\r\n if len(set(user_name)) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"Invalid input. The user name must be a non-empty string of lowercase English letters with a length between 1 and 100.\")\r\n", "name = input()\ncharacters = set()\ndistinct = 0\nfor char in name:\n if char not in characters:\n distinct += 1\n characters.add(char)\n\nif distinct % 2 == 0: print(\"CHAT WITH HER!\")\nelse: print(\"IGNORE HIM!\")", "#2300012302 张惠雯 \r\nname=input()\r\nset1=set()\r\nfor a in name:\r\n set1.add(a)\r\nnum=len(set1)\r\nif num%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "name = input()\r\nletters = [letter for letter in name]\r\nno_duplicate = list(dict.fromkeys(letters))\r\nif len(no_duplicate) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "str = input()\r\nstr = [i for i in str]\r\ndict = {}\r\nfor j in str:\r\n dict.update({j:str.count(j)})\r\n\r\nn = len(dict.keys())\r\nif n%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "import sys\r\n\r\ns = sys.stdin.readline().strip()\r\n\r\nif len(set(s)) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "s1=input()\r\nlst=list(s1)\r\nlist1=[]\r\nfor i in range(len(lst)):\r\n if lst[i] not in list1:\r\n list1.append(lst[i])\r\nif(len(list1)%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "name = input()\r\nhash = []\r\nfor ch in name:\r\n if ch not in hash:\r\n hash.append(ch)\r\nif len(hash)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "a = list(input())\nb = list(set(a))\nc = len(b)\n\nif c % 2 == 1:\n\tprint(\"IGNORE HIM!\")\nelse:\n\tprint(\"CHAT WITH HER!\")\n \t \t \t \t \t \t\t \t \t\t\t\t \t", "name = input()\r\nuniqueletters = {name}\r\nfor i in name:\r\n uniqueletters.add(i)\r\n\r\nuniqueletters.remove(name)\r\n\r\nif len(uniqueletters)%2:\r\n print('IGNORE HIM!')\r\nelse:\r\n print('CHAT WITH HER!')\r\n", "user_name = input().strip()\n\n# Count the number of distinct characters\ndistinct_characters = set(user_name)\n\n# Determine the gender based on the count of distinct characters\nif len(distinct_characters) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n", "import sys\r\nimport math\r\nimport bisect\r\ndef input(): return sys.stdin.readline().rstrip(\"\\r\\n\")\r\n \r\ndef main():\r\n #length = int(input())\r\n string = input()\r\n ans = 0\r\n #numbers = [*map(int, input().split())]\r\n print([\"CHAT WITH HER!\",\"IGNORE HIM!\"][len(set(string))%2])\r\n \r\n \r\nif __name__ == \"__main__\":\r\n main()", "username = input()\r\n\r\nname = \"\"\r\nfor letter in username:\r\n if not(letter in name):\r\n name += letter\r\n\r\nif len(name)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "inputString = input()\r\nletters = set(inputString)\r\nif len(letters) % 2 != 0:\r\n print('IGNORE HIM!')\r\nelse:\r\n print(\"CHAT WITH HER!\")", "n=input()\r\nk=''\r\nfor i in n:\r\n if i not in k:\r\n k=k+i\r\nif len(k)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "# 236A\tBoy or Girl\r\nl = list(input())\r\nk = []\r\ncount = 0\r\nfor i in l:\r\n if i not in k:\r\n k.append(i)\r\n count += 1\r\nif count%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = input()\r\nb = []\r\nfor r in s:\r\n if r in b:\r\n continue\r\n else:\r\n b.append(r)\r\n\r\nif len(b)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n \r\n", "username = input()\r\ndistinct_chars = len(set(username))\r\nif distinct_chars % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "'''미완'''\r\n\r\nword = list(input())\r\nword_copied = set(word)\r\n\r\nif len(word_copied)%2 == 0 :\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "a=input()\r\nlist1=[]\r\nfor i in a:\r\n if not (i in list1):\r\n list1.append(i)\r\nif len(list1)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "ch=input()\r\ns={ch[i] for i in range(len(ch))}\r\nif len(s)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "import sys\r\n\r\nstdin_fileno = sys.stdin\r\nx = ''\r\nfor line in sys.stdin:\r\n if line.rstrip() == 'q':\r\n break\r\n x += line\r\n \r\ninput = x\r\nunique_letters = []\r\nfor letter in input:\r\n dupe = False\r\n if len(unique_letters) == 0:\r\n unique_letters.append(letter)\r\n else:\r\n for character in unique_letters:\r\n if character == letter:\r\n dupe = True\r\n if not dupe:\r\n unique_letters.append(letter)\r\nunique_letters.pop()\r\n\r\nif len(unique_letters) % 2 == 0:\r\n output = 'CHAT WITH HER!'\r\nelse:\r\n output = 'IGNORE HIM!'\r\n\r\nstdout_fileno = sys.stdout\r\nstdout_fileno.write(output + '\\n')", "a = str(input())\r\ncheck = \"\"\r\nfor x in a:\r\n if x not in check:\r\n check += x\r\n\r\nif len(check) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "txt = input()\r\ns=set()\r\nfor char in txt:\r\n s.add(char)\r\nif len(s) % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "username = list(input())\r\nusername = list(set(username))\r\nif len(username)%2 == 1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "print([\"CHAT WITH HER!\", \"IGNORE HIM!\"][len(set(input())) % 2])", "s=str(input())\r\nmylist=[]\r\nfor i in s:\r\n if i not in mylist:\r\n mylist.append(i)\r\n\r\nif (len(mylist)%2)==0:\r\n print(\"CHAT WITH HER!\")\r\nelse :\r\n print(\"IGNORE HIM!\") ", "name = input()\r\n\r\nnameSet = set()\r\nfor char in name:\r\n\tnameSet.add(char)\r\n\t\r\nif len(nameSet) % 2 == 0:\r\n\tprint('CHAT WITH HER!')\r\nelse:\r\n\tprint('IGNORE HIM!')\r\n\t", "n=input()\r\na=[]\r\ncount=0\r\nfor i in range(len(n)):\r\n if n[i]not in a:\r\n a.append(n[i])\r\n count=count+1\r\nif count%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n \r\n", "from collections import defaultdict\r\n\r\nname = input()\r\nseen = {}\r\ncount = 0\r\nfor n in name:\r\n if n not in seen:\r\n seen[n] = 0\r\n count += 1\r\nprint(\"CHAT WITH HER!\" if len(seen) % 2 == 0 else \"IGNORE HIM!\")\r\n", "username = list(input())\r\ncount = len(set(username))\r\nif count % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "name=input()\r\nlength=len(name)\r\ncharacters=[]\r\ntemporary=[]\r\nt=0\r\nfor i in range(length):\r\n characters.append(name[i])\r\na=set(characters)\r\nfinal=len(a)\r\nif final %2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "line = input()\r\ni = 0\r\ndistinct = []\r\nfor j in line:\r\n if j not in distinct:\r\n distinct.append(j)\r\n \r\nif (len(distinct) % 2) == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')\r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n", "username = input()\r\nseen = set()\r\nresult = ''\r\nfor c in username:\r\n if c not in seen:\r\n seen.add(c)\r\n result += (c)\r\nprint(\"CHAT WITH HER!\" if len(result) % 2 == 0 else \"IGNORE HIM!\")\r\n", "user_name = input()\r\n\r\ndistinct = {}\r\nfor char in user_name:\r\n if char not in distinct:\r\n distinct[char] = 0\r\n else:\r\n distinct[char] += 1\r\n\r\n# print(distinct)\r\nrep = 0\r\ncount = 0\r\nfor val in distinct.values():\r\n if val == 0:\r\n count += 1\r\n else:\r\n rep +=1\r\n\r\nif (count + rep) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "# Read the input user name\r\nuser_name = input()\r\n\r\n# Count the number of distinct characters using a set\r\ndistinct_chars = set(user_name)\r\n\r\n# Check if the count is even or odd and print the result accordingly\r\nif len(distinct_chars) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "word = input()\r\ns = [] \r\nfor i in range(len(word)):\r\n if word[i] not in s:\r\n s.append(word[i])\r\n else:\r\n continue\r\nif len(s) % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')\r\n", "name = input()\r\nname_split_distn = set(list(name))\r\n\r\nif len(name_split_distn) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n \r\nelse:\r\n print(\"IGNORE HIM!\")", "s = input()\n\nif len(set(s)) & 1:\n\tprint(\"IGNORE HIM!\")\nelse:\n\tprint(\"CHAT WITH HER!\")\n", "def boy_or_girl(user_name):\r\n\tcharacters = ''\r\n\tfor letter in user_name:\r\n\t\tif letter not in characters:\r\n\t\t\tcharacters += letter\r\n\tif len(characters) % 2 == 0:\r\n\t\treturn 'CHAT WITH HER!'\r\n\telse:\r\n\t\treturn 'IGNORE HIM!'\r\n\t\r\nprint(boy_or_girl(input()))\r\n", "def main():\r\n in_string = input()\r\n char_set = set()\r\n unique_chars = 0\r\n \r\n for character in in_string:\r\n if not char_set.__contains__(character):\r\n unique_chars += 1\r\n char_set.add(character)\r\n \r\n print(\"CHAT WITH HER!\" if unique_chars % 2 == 0 else \"IGNORE HIM!\")\r\n \r\nif __name__ == \"__main__\":\r\n main()", "username = input()\r\nL1 = []\r\nL2 = []\r\nfor i in username:\r\n L1.append(i)\r\n\r\nfor i in L1:\r\n if i not in L2:\r\n L2.append(i)\r\n\r\ncount = len(L2)\r\n\r\nif count % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n ", "#The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.\r\nusername = input()\r\n\r\n#if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female\r\ndistinct_characters = []\r\n[distinct_characters.append(x)for x in username if x not in distinct_characters]\r\n\r\nif len(distinct_characters)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = input()\r\n\r\nfreq = [0] * 26\r\nfor ch in s:\r\n if ch.isalpha():\r\n ch = ch.lower()\r\n freq[ord(ch) - ord('a')] += 1\r\n\r\nc = sum(1 for count in freq if count > 0)\r\n\r\nif c % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "word = input()\r\nmy_list=[]\r\nfor i in word:\r\n if i not in my_list:\r\n my_list.append(i)\r\n else:\r\n continue\r\nif len(my_list)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "if __name__=='__main__':\r\n string = input()\r\n if len(set(string))%2==0:\r\n print('CHAT WITH HER!')\r\n else:\r\n print('IGNORE HIM!')", "s = input()\r\n\r\ncount = 0\r\nslst = []\r\n\r\nfor c in s:\r\n\tif c not in slst:\r\n\t\tslst.append(c)\r\n\t\tcount = count + 1\r\n\r\nif count % 2 == 0:\r\n\tprint(\"CHAT WITH HER!\")\r\nelse:\r\n\tprint(\"IGNORE HIM!\")", "# -*- coding: utf-8 -*-\n\"\"\"A. Boy or Girl.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1As7MbHYFOhi8eMcGihWR39YUpjP319n9\n\"\"\"\n\n# Read the user name\nuser_name = input()\n\n# Count the number of distinct characters in the user name\ndistinct_chars = set(user_name)\n\n# Check if the count of distinct characters is even or odd\nif len(distinct_chars) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")", "st=input()\r\nst=sorted(st)\r\nhset=set()\r\nk=0\r\nfor i in st:\r\n if(i not in hset):\r\n k+=1\r\n hset.add(i)\r\nif(k%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\") ", "n = input()\r\n\r\nrepeated = []\r\n\r\nfor i in n:\r\n if i not in repeated:\r\n repeated.append(i)\r\n \r\nprint(\"CHAT WITH HER!\") if len(repeated)%2==0 else print(\"IGNORE HIM!\")", "x=input()\r\nset1=set()\r\nfor i in x:\r\n set1.add(i)\r\n abc=set\r\nif len(set1)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n ", "usernameinput = input()\r\nnewarray = []\r\nfor i in usernameinput :\r\n if i not in newarray :\r\n newarray.append(i) \r\nif len(newarray) %2 ==0 :\r\n print(\"CHAT WITH HER!\")\r\nelse :\r\n print(\"IGNORE HIM!\")", "word = input()\r\n\r\nset_word = set(word) \r\nlist_word = (list(set_word))\r\n \r\nif (len(list_word)%2 == 0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "user_name = input()\r\nuser_name_list = list(user_name)\r\nnew_name = \"\"\r\nfor letter in user_name_list:\r\n if letter not in new_name:\r\n new_name += letter\r\n \r\nif len(new_name) % 2 == 0: \r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "chars = []\r\n\r\nusername = input()\r\ndistinct = 0\r\n\r\nfor x in username:\r\n if x not in chars:\r\n chars.append(x)\r\n distinct += 1\r\n\r\nif (distinct % 2):\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\") ", "num = len(set(input()))\r\noutput = 'CHAT WITH HER!' if num % 2 == 0 else 'IGNORE HIM!'\r\nprint(output)", "a = input()\r\narr=[]\r\n\r\nfor i in a:\r\n if i not in arr:\r\n arr.append(i)\r\n \r\nif len(arr)%2!=0: print(\"IGNORE HIM!\")\r\nelse: print(\"CHAT WITH HER!\")\r\n", "nickname = input()\r\nletters = [nickname[i] for i in range(len(nickname))]\r\nprint(\"CHAT WITH HER!\" if len(set(letters)) % 2 == 0 else \"IGNORE HIM!\")", "str1=input()\r\nset1=set(str1)\r\nif len(set1)%2==0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "list1=list(input())\r\nlist2=[]\r\ncounter=0\r\nfor i in list1:\r\n if i not in list2:\r\n list2.append(i)\r\n counter+=1\r\nif counter%2==0:\r\n print (\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "x=input()\r\ns=set()\r\n\r\nfor i in x:\r\n s.add(i)\r\n\r\nif(len(s)%2 != 0):\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "s = len(set(input()))\r\nprint('CHAT WITH HER!' if s % 2 == 0 else 'IGNORE HIM!') ", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Wed Sep 13 17:01:14 2023\n\n@author: huangxiaoyuan\n\"\"\"\n\na=input()\nif len(a)<=100:\n list=[]\n list1=[]\n for i in a:\n list.append(i)\n lidt1=set(list)\n k=len(lidt1)\n if k%2==0:\n print('CHAT WITH HER!')\n else:\n print('IGNORE HIM!')\n \n\n\n \n ", "username = input()\ncharacters = []\nfor i in range(len(username)):\n if username[i] not in characters:\n characters += username[i]\nif len(characters) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")", "def chat_or_ignore(gebruikersnaam):\r\n gebruikernaam_list = [klinker for klinker in gebruikersnaam]\r\n gebruikernaam_list = list(set(gebruikernaam_list))\r\n return \"CHAT WITH HER!\" if len(gebruikernaam_list)%2 == 0 else \"IGNORE HIM!\"\r\n\r\nprint(chat_or_ignore(input()))", "a = input()\ncount = []\n\nfor i in a:\n if i not in count:\n count.append(i)\n \nif len(count) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")", "name = {\"\"}\r\nhagu = input(\"\")\r\nfor i in hagu:\r\n name.add(i)\r\nname_length = len(hagu)\r\nlength = len(name) - 1\r\nif name_length <= 100:\r\n if length%2 == 1:\r\n print(\"IGNORE HIM!\")\r\n else: \r\n print(\"CHAT WITH HER!\")", "s = input()\r\nss = set(s) \r\nif (len(ss) % 2 == 0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "if(len({k:0 for k in input()})%2!=0):\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "x=input()\r\nn=0\r\n#\"w\", \"j\", \"m\", \"z\", \"b\", \"r\"\r\nx = dict.fromkeys(x)\r\n\r\nfor i in x:\r\n n+=1\r\n\r\nif n%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "# username check\r\nunique_chars = set() # create set\r\nusername = input()\r\nfor i in range(len(username)):\r\n unique_chars.add(username[i])\r\nif len(unique_chars)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n\r\n", "# -*- coding: utf-8 -*-\n\"\"\"Untitled10.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1Y76e7LeXWvCIjIdSAW7klJvgCVNmBhzq\n\"\"\"\n\ns = input()\nns = ''\nfor i in s:\n if i not in ns:\n ns += i\nif len(ns) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")", "t=input()\r\nt=set(t)\r\nk=len(t)\r\nif k%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = set(input())\r\ns = ''.join(s)\r\ne = s.index(s[-1])\r\nif (e+1) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "word=input()\r\nmy_list=[]\r\nfor i in word:\r\n if i not in my_list:\r\n my_list.append(i)\r\n else:\r\n continue\r\nif len(my_list)%2==0:\r\n print(\"CHAT WITH HER!\\n\")\r\nelse:\r\n print(\"IGNORE HIM!\\n\")", "string=input()\r\nli=[]\r\ncount=0\r\nfor _ in string:\r\n if _ not in li:\r\n li.append(_)\r\nfor i in li:\r\n count+=1\r\n\r\nif(count%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n ", "name = str(input())\r\n\r\nalfabet = 'abcdefghijklmnopqrstuvwxyz'\r\nletter_count = {\r\n letter : 0 for letter in alfabet\r\n}\r\n\r\nfor i in range(len(name)):\r\n letter_count[name[i]] +=1\r\n\r\na = 0\r\n\r\nfor i in alfabet:\r\n if (letter_count[i]) > 0:\r\n a += 1\r\n\r\nif a % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "s = input()\r\ns = [i for i in s]\r\ns = list(set(s))\r\nif len(s) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "name=input()\r\nlength=len(name)\r\nname=list(name)\r\nnum_distinct=0\r\ncount=0\r\nstored=[]\r\nfor i in name:\r\n if name.count(i)>1:\r\n if i in stored:\r\n pass\r\n else:\r\n num_distinct-=1\r\n stored.append(i)\r\n elif name.count(i)<=1:\r\n num_distinct+=1\r\nif num_distinct%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "def NumOfDistinctCharsInWord(Word):\r\n Lettersinword = list()\r\n for letter in Word:\r\n if letter not in Lettersinword:\r\n Lettersinword.append(letter)\r\n else:\r\n pass\r\n if len(Lettersinword)%2 ==0:\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")\r\nNumOfDistinctCharsInWord(input(\"\"))", "string = [*input()]\nchar = []\nfor i in string:\n if i not in char:\n char.append(i)\n\nif len(char) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n", "name = input()\r\ndistinct_char = ''.join(set(name))\r\nlength = len(distinct_char)\r\n\r\nif length%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "string = input()\n\nletters = set()\n\nfor x in string:\n letters.add(x)\n\nif len(letters) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")", "set_1 = set()\r\nset_1.update(input())\r\nif len(set_1)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "a=list(input())\r\ncount=0\r\nl=[]\r\nfor i in range(len(a)):\r\n if a[i] not in l:\r\n l.append(a[i])\r\n count+=1\r\nif (count%2==0):\r\n print(\"CHAT WITH HER!\")\r\nif (count%2!=0):\r\n print(\"IGNORE HIM!\")", "username = input()\r\ndistinct_letters = set(username)\r\namount_of_distinct_letters = len(distinct_letters)\r\n\r\nif amount_of_distinct_letters % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "palavra = input()\r\nletras_diferentes = []\r\n\r\nfor letra in palavra:\r\n if letra not in letras_diferentes:\r\n letras_diferentes.append(letra)\r\n\r\ncontagem = len(letras_diferentes)\r\n\r\nif contagem % 2 != 0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "str1=str(input())\r\nlist1=[]\r\nfor i in range(len(str1)):\r\n list1.append(str1[i])\r\nset1=set(list1)\r\nif len(set1)%2!=0:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "s = input()\r\nans = set()\r\nfor si in s:\r\n ans.add(si)\r\nprint(\"CHAT WITH HER!\" if len(ans) % 2 == 0 else \"IGNORE HIM!\") ", "s = input()\r\ns = set(s)\r\nprint(\"CHAT WITH HER!\" if len(s) % 2 == 0 else \"IGNORE HIM!\")", "name_to_process = input()\r\nname = set(name_to_process)\r\nif len(name) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "n=input()\r\ns=[\"+\"]\r\nfor i in n:\r\n if i not in s :\r\n s.append(i)\r\na=len(s)-1\r\nif a%2==0:\r\n print(\"CHAT WITH HER!\" )\r\nelse :\r\n print(\"IGNORE HIM!\")", "def determine_gender(username):\r\n distinct_characters = set(username)\r\n if len(distinct_characters) % 2 == 0:\r\n return \"CHAT WITH HER!\"\r\n else:\r\n return \"IGNORE HIM!\"\r\n\r\n# Read input\r\nusername = input()\r\n\r\n# Determine the gender and print the result\r\nresult = determine_gender(username)\r\nprint(result)", "n1=input().lower()\r\ndef count_distinct_letters(input_string):\r\n distinct_letters = set() # To store the distinct letters\r\n\r\n for letter in input_string:\r\n distinct_letters.add(letter)\r\n\r\n return len(distinct_letters) # Return the count of distinct letters\r\nu=count_distinct_letters(n1)\r\nif (u%2==0):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "def main():\r\n string = input() \r\n string = dict.fromkeys(string) \r\n\r\n if len(string) % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n else:\r\n print(\"IGNORE HIM!\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()", "inp = list(input())\r\ninp_dict = {}\r\ncount = 0\r\nfor i in range (0, len(inp)):\r\n inp_dict[inp[i]] = 0\r\nfor i in range (0, len(inp)):\r\n inp_dict[inp[i]] += 1\r\nfor x in inp_dict.values():\r\n count += 1\r\nif count % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")\r\n", "inp = input()\r\ns = set(inp)\r\nk = 0\r\nfor i in s:\r\n k+= 1\r\nif k%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "n = input()\r\nm = set()\r\nfor i in n:\r\n m.add(str(i))\r\nn = len(m)\r\nif n % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')", "username = input().strip()\r\nr = \"CHAT WITH HER!\" if len(set(username)) % 2 == 0 else \"IGNORE HIM!\"\r\nprint(r)", "s=input()\r\ny=[]\r\nfor x in s:\r\n if x not in y:\r\n y.append(x)\r\nif len(y)%2==0:\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "\r\nx = input(\"\")\r\nz = []\r\nz.append(x[0])\r\nfor j in range(0, len(x)):\r\n if x[j] not in z:\r\n z.append(x[j])\r\nif len(z) % 2 == 0:\r\n print('CHAT WITH HER!')\r\nelse:\r\n print('IGNORE HIM!')\r\n\r\n\r\n", "a = input()\r\na = set(a)\r\nif not (len(a)%2):\r\n print(\"CHAT WITH HER!\")\r\nelse:\r\n print(\"IGNORE HIM!\")", "x=input()\r\ncontainer=[]\r\nfor i in x :\r\n if i not in container:\r\n container.append(i)\r\nif len(''.join(container))%2==0 :\r\n print('CHAT WITH HER!') \r\nelse :\r\n print('IGNORE HIM!')", "username = input().lower()\r\nunique_chars = set(username)\r\nif len(unique_chars) % 2 == 1:\r\n print(\"IGNORE HIM!\")\r\nelse:\r\n print(\"CHAT WITH HER!\")", "t = set([*input()])\r\nprint(\"CHAT WITH HER!\" if len(t)%2==0 else \"IGNORE HIM!\")", "username = input()\r\narr = []\r\nlen1 = len(username)\r\n\r\nfor i in range(len1):\r\n if username[i] in arr:\r\n pass\r\n else:\r\n arr += username[i]\r\n\r\nlen_arr = len(arr)\r\nif len_arr % 2 == 0:\r\n print(\"CHAT WITH HER!\")\r\n\r\nelse:\r\n print(\"IGNORE HIM!\")" ]
{"inputs": ["wjmzbmr", "xiaodao", "sevenkplus", "pezu", "wnemlgppy", "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn", "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx", "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt", "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk", "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz", "tgcdptnkc", "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi", "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp", "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia", "fpellxwskyekoyvrfnuf", "xninyvkuvakfbs", "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak", "kmsk", "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz", "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq", "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm", "ppcpbnhwoizajrl", "sgubujztzwkzvztitssxxxwzanfmddfqvv", "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw", "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu", "ojjvpnkrxibyevxk", "wjweqcrqfuollfvfbiyriijovweg", "hkdbykboclchfdsuovvpknwqr", "stjvyfrfowopwfjdveduedqylerqugykyu", "rafcaanqytfclvfdegak", "xczn", "arcoaeozyeawbveoxpmafxxzdjldsielp", "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika", "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh", "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg", "udlpagtpq", "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy", "qagzrqjomdwhagkhrjahhxkieijyten", "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb", "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr", "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc", "lnpdosnceumubvk", "efrk", "temnownneghnrujforif", "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta", "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh", "gwntwbpj", "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim", "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd", "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx", "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks", "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx", "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc", "yzlzmesxdttfcztooypjztlgxwcr", "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc", "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq", "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj", "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom", "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo", "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh", "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa", "oh", "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri", "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp", "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp", "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo", "mnmbupgo", "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl", "yocxrzspinchmhtmqo", "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv", "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad", "ubvhyaebyxoghakajqrpqpctwbrfqzli", "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy", "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd", "acrzbavz", "drvzznznvrzskftnrhvvzxcalwutxmdza", "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws", "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff", "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu", "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw", "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy", "rhh", "zhdouqfmlkenjzdijxdfxnlegxeuvhelo", "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn", "urigreuzpxnej"], "outputs": ["CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!", "CHAT WITH HER!", "CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!", "IGNORE HIM!", "IGNORE HIM!", "IGNORE HIM!", "IGNORE HIM!", "IGNORE HIM!", "IGNORE HIM!", "IGNORE HIM!", "CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!", "CHAT WITH HER!", "IGNORE HIM!", "IGNORE HIM!", "CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!", "CHAT WITH HER!", "IGNORE HIM!", "IGNORE HIM!", "IGNORE HIM!", "CHAT WITH HER!", "CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!", "CHAT WITH HER!", "CHAT WITH HER!", "CHAT WITH HER!", "CHAT WITH HER!", "CHAT WITH HER!", "CHAT WITH HER!", "CHAT WITH HER!", "IGNORE HIM!", "IGNORE HIM!", "CHAT WITH HER!", "IGNORE HIM!", "IGNORE HIM!", "IGNORE HIM!", "IGNORE HIM!", "IGNORE HIM!", "CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!", "CHAT WITH HER!", "CHAT WITH HER!", "IGNORE HIM!", "IGNORE HIM!", "CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!", "CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!", "CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!", "CHAT WITH HER!", "CHAT WITH HER!", "IGNORE HIM!", "IGNORE HIM!", "CHAT WITH HER!", "CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!", "IGNORE HIM!", "IGNORE HIM!", "CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!", "CHAT WITH HER!", "CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!", "CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!", "CHAT WITH HER!"]}
UNKNOWN
PYTHON3
CODEFORCES
595
12ac6ee7b374eaba6ddb61a68ebddee3
Reberland Linguistics
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know linguistics very well. You learn a structure of Reberland language as foreign language. In this language words are constructed according to the following rules. First you need to choose the "root" of the word — some string which has more than 4 letters. Then several strings with the length 2 or 3 symbols are appended to this word. The only restriction — it is not allowed to append the same string twice in a row. All these strings are considered to be suffixes of the word (this time we use word "suffix" to describe a morpheme but not the few last characters of the string as you may used to). Here is one exercise that you have found in your task list. You are given the word *s*. Find all distinct strings with the length 2 or 3, which can be suffixes of this word according to the word constructing rules in Reberland language. Two strings are considered distinct if they have different length or there is a position in which corresponding characters do not match. Let's look at the example: the word *abacabaca* is given. This word can be obtained in the following ways: , where the root of the word is overlined, and suffixes are marked by "corners". Thus, the set of possible suffixes for this word is {*aca*,<=*ba*,<=*ca*}. The only line contains a string *s* (5<=≤<=|*s*|<=≤<=104) consisting of lowercase English letters. On the first line print integer *k* — a number of distinct possible suffixes. On the next *k* lines print suffixes. Print suffixes in lexicographical (alphabetical) order. Sample Input abacabaca abaca Sample Output 3 aca ba ca 0
[ "t = input()\r\ns, d = set(), set()\r\np = {(len(t), 2)}\r\n\r\nwhile p:\r\n m, x = p.pop()\r\n r = m + x\r\n\r\n for y in [x, 5 - x]:\r\n l = m - y\r\n q = (l, y)\r\n\r\n if q in d or l < 5 or t[l:m] == t[m:r]: continue\r\n s.add(t[l:m])\r\n\r\n d.add(q)\r\n p.add(q)\r\n\r\nprint(len(s))\r\nprint('\\n'.join(sorted(s)))", "s = input()\r\nn = len(s)\r\ns += '0000000000'\r\ndp = [[0] * 2 for i in range(n + 5)]\r\ndp[n] = [1, 1]\r\nres = set()\r\nfor i in range(n - 1, 4, -1):\r\n if i + 2 <= n and ((dp[i + 2][0] and s[i: i + 2] != s[i + 2: i + 4]) or dp[i + 2][1]):\r\n res.add(s[i: i + 2])\r\n dp[i][0] = 1\r\n if i + 3 <= n and ((dp[i + 3][1] and s[i: i + 3] != s[i + 3: i + 6]) or dp[i + 3][0]):\r\n res.add(s[i: i + 3])\r\n dp[i][1] = 1\r\nprint(len(res))\r\nfor ss in sorted(res):\r\n print(ss)", "s = input()\nn = len(s)\nres = set()\n\nfrom collections import defaultdict\n\ntwo = [\"$\", \"\", \"$\"]\nthr = [\"$\", \"\", \"$\"]\n\nworks = lambda w, i : (two[i] != \"$\" and w != two[i]) or (thr[i] != \"$\" and w != thr[i])\n\ni = n - 2\nwhile i > 4:\n ntwo = s[i: i + 2]\n if works(ntwo, 1):\n res.add(ntwo)\n else:\n ntwo = \"$\" \n\n if (i <= n - 3):\n nthr = s[i: i + 3]\n if works(nthr, 2):\n res.add(nthr)\n else:\n nthr = \"$\"\n else:\n nthr = \"$\"\n\n two = [ntwo] + two[0:2]\n thr = [nthr] + thr[0:2]\n i -= 1\n\nres = list(res)\nres.sort()\n\nprint(len(res))\nfor word in res:\n print(word)", "P,s=print,input();stk,d,z=[(len(s),0)],set(),set()\r\nwhile stk:\r\n i,j=stk.pop();r=i+j\r\n for j in (2,3):\r\n l=i-j;k=(l,j)\r\n if k not in d and l>=5 and s[l:i]!=s[i:r]:\r\n z.add(s[l:i]);d.add(k);stk+=[k]\r\nP(len(z)),P('\\n'.join(sorted(z)))", "a=input()\r\nn=len(a)\r\nsufiks = set()\r\nsuf_lens = [0] * (n+1)\r\nsuf_lens[n] = 3\r\ndef main(i, len_suf):\r\n if (suf_lens[i] & len_suf - 1 and a[i : i + len_suf] != a[i-len_suf:i]) or suf_lens[i] & 4 - len_suf :\r\n sufiks.add(a[i-len_suf : i])\r\n suf_lens[i - len_suf] |= len_suf - 1\r\n\r\nfor i in range(n, 6, -1):\r\n main(i, 2)\r\n if i > 7: main(i, 3)\r\n\r\nprint (len(sufiks))\r\nfor i in sorted(sufiks):\r\n print (i)\r\n", "'''\r\nCreated on May 1, 2016\r\nGmail : [email protected]\r\n@author: Md. Rezwanul Haque\r\n'''\r\nfrom sys import *\r\nsetrecursionlimit(20000)\r\nd = {}\r\nt = set()\r\ns = input()+' '\r\ndef gen(l,ll):\r\n if(l,ll) in t:\r\n return\r\n t.add((l,ll))\r\n if (l>6):\r\n d[s[l-2:l]] = 1\r\n if(s[l-2:l]!= s[l:ll]):\r\n gen(l-2, l)\r\n if (l>7):\r\n d[s[l-3:l]] = 1\r\n if(s[l-3:l]!=s[l:ll]):\r\n gen(l-3,l)\r\ngen(len(s)-1, len(s))\r\nprint(len(d))\r\nfor k in sorted(d):\r\n print(k)", "\nif __name__ == '__main__':\n\n\n word = input()\n\n suffixes = set()\n possible = set()\n my_set = set()\n not_poss = set()\n\n possible.add((len(word), 2))\n\n while possible:\n tam, x = possible.pop()\n a = tam + x\n for i in [x, 5 - x]:\n root = tam - i\n new_pos = (root, i)\n\n if root < 5 or new_pos in my_set or (word[root:tam] == word[tam:a]):\n not_poss.add(word[root:tam])\n else:\n suffixes.add(word[root:tam])\n possible.add(new_pos)\n my_set.add(new_pos)\n\n suffixes_alph = sorted(suffixes)\n\n print(len(suffixes))\n for i in suffixes_alph:\n print(i)\n", "d = set()\ns = input()[5:]\nn = len(s)\ns += \"0000\"\n\ntwos = [False] * (n + 3)\nthrees = [False] * (n + 3)\ntwos[n] = threes[n] = True\n\ndef do(i, num, same, other):\n after = i + num\n if not same[after] and not other[after]:\n return None, same\n\n cut = s[i:i+num]\n if cut == s[i+num:i+2*num] and not other[after]:\n return None, same\n\n same[i] = True\n return cut, same\n\n\nfor i in range(n - 2, -1, -1):\n cut, twos = do(i, 2, twos, threes)\n if cut is not None:\n d.add(cut)\n\n cut, threes = do(i, 3, threes, twos)\n if cut is not None:\n d.add(cut)\n\nl = sorted(d)\nprint(len(l))\nfor i in l:\n print(i)\n", "import sys\nsys.stderr = sys.stdout\n\nfrom collections import deque\n\n\ndef suffixes(s):\n T = set()\n V = set()\n D = deque()\n D.append((len(s), ''))\n while D:\n k, p = D.pop()\n if k >= 7:\n t = s[k-2:k]\n if t != p:\n T.add(t)\n v = (k-2, t)\n if v not in V:\n V.add(v)\n D.append(v)\n if k >= 8:\n t = s[k-3:k]\n if t != p:\n T.add(t)\n v = (k-3, t)\n if v not in V:\n V.add(v)\n D.append(v)\n return sorted(T)\n\n\ndef main():\n s = input()\n T = suffixes(s)\n print(len(T))\n if T:\n print('\\n'.join(T))\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", "s = (input())\r\nn = len(s)\r\nx = set()\r\n\r\na = [[0 for i in range(2)] for j in range(n + 5)]\r\nb = [0 for i in range(n + 5)]\r\n\r\nb[n] = 1\r\na[n][0] = 1\r\na[n][1] = 1\r\n\r\nfor i in range(n - 1, 4, -1):\r\n if b[i + 2]:\r\n if a[i + 2][0] and (s[i:i + 2] != s[i + 2:i + 4]):\r\n b[i] = 1\r\n a[i][0] = 1\r\n if a[i + 2][1]:\r\n b[i] = 1\r\n a[i][0] = 1\r\n if b[i]:\r\n x.add(s[i:i + 2])\r\n if b[i + 3]:\r\n if a[i + 3][1] and (s[i:i + 3] != s[i + 3:i + 6]):\r\n b[i] = 1\r\n a[i][1] = 1\r\n if a[i + 3][0]:\r\n b[i] = 1\r\n a[i][1] = 1\r\n if b[i]:\r\n x.add(s[i:i + 3])\r\n\r\nx = sorted(list(x))\r\nprint(len(x))\r\nfor i in x:\r\n print(i)\r\n", "import sys\r\n\r\nvalue = input()\r\nif (len(value) < 7):\r\n print(0)\r\n sys.exit(0)\r\n\r\nres = set()\r\npossible = {}\r\npossible[len(value)] = set([2])\r\nif (len(value) > 7):\r\n possible[len(value)].add(3)\r\npossibleLen = [2, 3]\r\n\r\nfor i in reversed(range(7, len(value) + 1)):\r\n possibleVal = possible.get(i, set())\r\n for length in possibleVal:\r\n nextI = i - length\r\n val = value[nextI:i]\r\n res.add(val)\r\n for posLen in possibleLen:\r\n if (nextI >= 5 + posLen and value[nextI - posLen:nextI] != val):\r\n setNextI = possible.setdefault(nextI, set())\r\n setNextI.add(posLen)\r\n\r\nprint(len(res))\r\nfor val in sorted(res):\r\n print(val)", "import sys\r\ninput = sys.stdin.readline\r\nfrom collections import *\r\n\r\ns = input()[:-1]\r\nn = len(s)\r\ndp = [[False]*2 for _ in range(n+1)]\r\ndp[n][0] = True\r\ndp[n][1] = True\r\ndp[n-2][0] = True\r\ndp[n-3][1] = True\r\n\r\nfor i in range(n-4, -1, -1):\r\n if (dp[i+2][0] and i+4<=n and s[i:i+2]!=s[i+2:i+4]) or dp[i+2][1]:\r\n dp[i][0] = True\r\n \r\n if dp[i+3][0] or (dp[i+3][1] and i+6<=n and s[i:i+3]!=s[i+3:i+6]):\r\n dp[i][1] = True\r\n \r\nans = set()\r\n\r\nfor i in range(5, n):\r\n if i+2<=n and dp[i][0]:\r\n ans.add(s[i:i+2])\r\n \r\n if i+3<=n and dp[i][1]:\r\n ans.add(s[i:i+3])\r\n\r\nans = list(ans)\r\nans.sort()\r\nprint(len(ans))\r\n\r\nfor ans_i in ans:\r\n print(ans_i)", "import sys\nsys.setrecursionlimit(20000)\n\nin_str = input()\nin_str = in_str[5:] + ' '\n\nn = len(in_str)\n\nvalid_ = set()\ncounted_ = set()\n\ndef count(x,y):\n if (x,y) in counted_:\n return\n counted_.add((x,y))\n if x > 1:\n if in_str[x:y] != in_str[x-2:x]:\n valid_.add(in_str[x-2:x])\n count(x-2,x)\n if x > 2:\n if in_str[x:y] != in_str[x-3:x]:\n valid_.add(in_str[x-3:x])\n count(x-3,x)\ncount(n-1,n)\n\nprint(len(valid_))\nfor elem in sorted(list(valid_)):\n print(elem)\n\n\n", "st=input()\r\nn=len(st)\r\nposs=[[False,False] for i in range(n)]\r\nposs[n-2][0]=True\r\nposs[n-3][1]=True\r\nfor i in range(n-4,-1,-1):\r\n if poss[i+2][0] and st[i:i+2]!=st[i+2:i+4]:\r\n poss[i][0]=True\r\n if poss[i+2][1]:\r\n poss[i][0]=True\r\n if poss[i+3][1]and st[i:i+3]!=st[i+3:i+6]:\r\n poss[i][1]=True\r\n if poss[i+3][0]:\r\n poss[i][1]=True\r\nd=set()\r\nfor i in range(5,n):\r\n if poss[i][0]:\r\n d.add(st[i:i+2])\r\n if poss[i][1]:\r\n d.add(st[i:i+3])\r\nprint(len(d))\r\nfor i in sorted(d):\r\n print(i)\r\n", "def main():\n s = input()[5:]\n n = len(s)\n if n < 2:\n print(0)\n return\n res2, res3 = set(), set()\n dp2 = [False] * (n + 1)\n dp3 = [False] * (n + 1)\n dp2[-1] = dp3[-1] = True\n for i in range(n, 1, -1):\n if dp3[i] or dp2[i] and s[i - 2:i] != s[i:i + 2]:\n res2.add(s[i - 2:i])\n dp2[i - 2] = True\n if dp2[i] or dp3[i] and s[i - 3:i] != s[i:i + 3]:\n res3.add(s[i - 3:i])\n dp3[i - 3] = True\n res3.discard(s[i - 3:i])\n res3.update(res2)\n print(len(res3))\n for s in sorted(res3):\n print(s)\n\n\nif __name__ == '__main__':\n main()\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\ns = input()[:-1]\r\nn = len(s)\r\ndp = [[False]*2 for _ in range(n)]\r\ndp[n-2][0] = True\r\ndp[n-3][1] = True\r\n\r\nfor i in range(n-4, -1, -1):\r\n dp[i][0] = (dp[i+2][0] and s[i:i+2]!=s[i+2:i+4]) or dp[i+2][1]\r\n dp[i][1] = dp[i+3][0] or (dp[i+3][1] and s[i:i+3]!=s[i+3:i+6])\r\n\r\nans = set()\r\n\r\nfor i in range(5, n):\r\n if dp[i][0]:\r\n ans.add(s[i:i+2])\r\n \r\n if dp[i][1]:\r\n ans.add(s[i:i+3])\r\n \r\nans = list(ans)\r\nans.sort()\r\nprint(len(ans))\r\n\r\nfor ans_i in ans:\r\n print(ans_i)", "a = input()\r\nn = len(a)\r\n\r\ndp = [0] * (n + 1)\r\ndp[n] = 3\r\nresset = set()\r\n\r\ndef chk(i, w):\r\n if dp[i] & 4 - w or (dp[i] & w - 1 and a[i:i + w] != a[i - w:i]):\r\n resset.add(a[i - w:i])\r\n dp[i - w] |= w - 1\r\n\r\n\r\nfor i in range(n, 6, -1):\r\n chk(i, 2)\r\n if i > 7:\r\n chk(i, 3)\r\n\r\nprint(len(resset))\r\nfor i in sorted(resset):\r\n print(i)", "Q,s=print,input();sx,d,z=[(len(s),0)],set(),set()\r\nwhile sx:\r\n i,j=sx.pop();r=i+j\r\n for j in (2,3):\r\n l=i-j;k=(l,j)\r\n if k not in d and l>=5 and s[l:i]!=s[i:r]:\r\n z.add(s[l:i]);d.add(k);sx+=[k]\r\nQ(len(z)),Q('\\n'.join(sorted(z)))", "\r\ns = input()[5:][::-1]\r\nn = len(s)\r\n\r\nmu = set()\r\ncan2 = [0]*(n+1)\r\ncan3 = [0]*(n+1)\r\nif n >= 2:\r\n mu.add(s[0:2][::-1])\r\n can2[2] = 1\r\nif n >= 3:\r\n mu.add(s[0:3][::-1])\r\n can3[3] = 1\r\nif n >= 4 and s[0:2] != s[2:4]:\r\n mu.add(s[2:4][::-1])\r\n can2[4] = 1\r\nif n >= 5:\r\n mu.add(s[2:5][::-1])\r\n mu.add(s[3:5][::-1])\r\n can2[5] = 1\r\n can3[5] = 1\r\n \r\nfor i in range(6, n+1):\r\n if can2[i-3]:\r\n mu.add(s[i-3:i][::-1])\r\n can3[i] = 1\r\n if can2[i-2]:\r\n \r\n if s[i-2:i] != s[i-4:i-2]:\r\n mu.add(s[i-2:i][::-1])\r\n can2[i] = 1 \r\n if can3[i-2]:\r\n mu.add(s[i-2:i][::-1])\r\n can2[i] = 1\r\n if can3[i-3]:\r\n if s[i-3:i] != s[i-6:i-3]:\r\n mu.add(s[i-3:i][::-1])\r\n can3[i] = 1\r\nprint(len(mu))\r\nprint('\\n'.join(sorted(list(mu))))", "a = input()\r\nn = len(a)\r\ndp = [0] * (n + 1)\r\ndp[n] = 3\r\nans = set()\r\n\r\n\r\ndef check(i, w):\r\n if dp[i] & 4 - w or (dp[i] & w - 1 and a[i:i + w] != a[i - w:i]):\r\n ans.add(a[i - w:i])\r\n dp[i - w] |= w - 1\r\n\r\n\r\nfor i in range(n, 6, -1):\r\n check(i, 2)\r\n if i > 7:\r\n check(i, 3)\r\n\r\n\r\nprint(len(ans))\r\nfor i in sorted(ans):\r\n print(i)# 1689951640.8472278", "s = input()\r\ndp = [[0, 0] for i in range(10005)]\r\nres = set()\r\ni = len(s) - 1\r\nwhile i >= 5:\r\n\tif i + 2 == len(s):\r\n\t\tdp[i][0] = 1\r\n\t\tres.add(s[i:i+2])\r\n\t\ti = i - 1\r\n\t\tcontinue\r\n\tif i + 3 == len(s):\r\n\t\tdp[i][1] = 1\r\n\t\tres.add(s[i:i+3])\r\n\t\ti = i - 1\r\n\t\tcontinue\r\n\tif dp[i+2][1] or (dp[i+2][0] and s[i:i+2] != s[i+2:i+4]):\r\n\t\tdp[i][0] = 1\r\n\t\tres.add(s[i:i+2])\r\n\tif dp[i+3][0] or (dp[i+3][1] and s[i:i+3] != s[i+3:i+6]):\r\n\t\tdp[i][1] = 1\r\n\t\tres.add(s[i:i+3])\r\n\ti = i - 1\r\nprint(len(res))\r\nprint('\\n'.join(sorted(res)))\r\n", "'''\r\n给定字符串,求所有“词根长度>4,从末尾开始往前、长度为2或3、相邻不重复的子串后缀”。\r\n相当于用水壶盖从后往前圈饺子皮,每次可选尺寸为2或3的盖子,连续两个饺子皮相同时停止。\r\n'''\r\nP,s=print,input();stk,d,z=[(len(s),0)],set(),set()\r\nwhile stk:\r\n i,jr=stk.pop();r=i+jr\r\n for jl in (2,3):\r\n l=i-jl;k=(l,jl)\r\n if k not in d and l>=5 and s[l:i]!=s[i:r]:\r\n z.add(s[l:i]);d.add(k);stk+=[k]\r\nP(len(z)),P('\\n'.join(sorted(z)))" ]
{"inputs": ["abacabaca", "abaca", "gzqgchv", "iosdwvzerqfi", "oawtxikrpvfuzugjweki", "abcdexyzzzz", "affviytdmexpwfqplpyrlniprbdphrcwlboacoqec", "lmnxtobrknqjvnzwadpccrlvisxyqbxxmghvl", "tbdbdpkluawodlrwldjgplbiylrhuywkhafbkiuoppzsjxwbaqqiwagprqtoauowtaexrhbmctcxwpmplkyjnpwukzwqrqpv", "caqmjjtwmqxytcsawfufvlofqcqdwnyvywvbbhmpzqwqqxieptiaguwvqdrdftccsglgfezrzhstjcxdknftpyslyqdmkwdolwbusyrgyndqllgesktvgarpfkiglxgtcfepclqhgfbfmkymsszrtynlxbosmrvntsqwccdtahkpnelwiqn", "prntaxhysjfcfmrjngdsitlguahtpnwgbaxptubgpwcfxqehrulbxfcjssgocqncscduvyvarvwxzvmjoatnqfsvsilubexmwugedtzavyamqjqtkxzuslielibjnvkpvyrbndehsqcaqzcrmomqqwskwcypgqoawxdutnxmeivnfpzwvxiyscbfnloqjhjacsfnkfmbhgzpujrqdbaemjsqphokkiplblbflvadcyykcqrdohfasstobwrobslaofbasylwiizrpozvhtwyxtzl", "gvtgnjyfvnuhagulgmjlqzpvxsygmikofsnvkuplnkxeibnicygpvfvtebppadpdnrxjodxdhxqceaulbfxogwrigstsjudhkgwkhseuwngbppisuzvhzzxxbaggfngmevksbrntpprxvcczlalutdzhwmzbalkqmykmodacjrmwhwugyhwlrbnqxsznldmaxpndwmovcolowxhj", "topqexoicgzjmssuxnswdhpwbsqwfhhziwqibjgeepcvouhjezlomobgireaxaceppoxfxvkwlvgwtjoiplihbpsdhczddwfvcbxqqmqtveaunshmobdlkmmfyajjlkhxnvfmibtbbqswrhcfwytrccgtnlztkddrevkfovunuxtzhhhnorecyfgmlqcwjfjtqegxagfiuqtpjpqlwiefofpatxuqxvikyynncsueynmigieototnbcwxavlbgeqao", "lcrjhbybgamwetyrppxmvvxiyufdkcotwhmptefkqxjhrknjdponulsynpkgszhbkeinpnjdonjfwzbsaweqwlsvuijauwezfydktfljxgclpxpknhygdqyiapvzudyyqomgnsrdhhxhsrdfrwnxdolkmwmw", "hzobjysjhbebobkoror", "safgmgpzljarfswowdxqhuhypxcmiddyvehjtnlflzknznrukdsbatxoytzxkqngopeipbythhbhfkvlcdxwqrxumbtbgiosjnbeorkzsrfarqofsrcwsfpyheaszjpkjysrcxbzebkxzovdchhososo", "glaoyryxrgsysy", "aaaaaxyxxxx", "aaaaax", "aaaaaxx", "aaaaaaa", "aaaaaxxx", "aaaaayxx", "aaaaaxyz", "aaaaaxyxy", "aaaxyyxyy", "aaaaaxxxxxx", "aaaaaxxxxx", "aaaaaxyzxyxy", "aaaaadddgggg", "abcdeabzzzzzzzz", "bbbbbccaaaaaa", "xxxxxababc", "dddddaabbbbbb", "xxxxxababe", "aaaaababaaaaaaaaaaaa"], "outputs": ["3\naca\nba\nca", "0", "1\nhv", "9\ner\nerq\nfi\nqfi\nrq\nvz\nvze\nze\nzer", "25\neki\nfu\nfuz\ngj\ngjw\nik\nikr\njw\njwe\nki\nkr\nkrp\npv\npvf\nrp\nrpv\nug\nugj\nuz\nuzu\nvf\nvfu\nwe\nzu\nzug", "5\nxyz\nyz\nyzz\nzz\nzzz", "67\nac\naco\nbd\nbdp\nbo\nboa\nco\ncoq\ncw\ncwl\ndm\ndme\ndp\ndph\nec\nex\nexp\nfq\nfqp\nhr\nhrc\nip\nipr\nlb\nlbo\nln\nlni\nlp\nlpy\nme\nmex\nni\nnip\noa\noac\noq\nph\nphr\npl\nplp\npr\nprb\npw\npwf\npy\npyr\nqec\nqp\nqpl\nrb\nrbd\nrc\nrcw\nrl\nrln\ntd\ntdm\nwf\nwfq\nwl\nwlb\nxp\nxpw\nyr\nyrl\nyt\nytd", "59\nad\nadp\nbr\nbrk\nbx\nbxx\ncc\nccr\ncr\ncrl\ndp\ndpc\ngh\nhvl\nis\nisx\njv\njvn\nkn\nknq\nlv\nlvi\nmg\nmgh\nnq\nnqj\nnz\nnzw\nob\nobr\npc\npcc\nqb\nqbx\nqj\nqjv\nrk\nrkn\nrl\nrlv\nsx\nsxy\nvi\nvis\nvl\nvn\nvnz\nwa\nwad\nxm\nxmg\nxx\nxxm\nxy\nxyq\nyq\nyqb\nzw\nzwa", "170\nae\naex\naf\nafb\nag\nagp\naq\naqq\nau\nauo\naw\nawo\nba\nbaq\nbi\nbiy\nbk\nbki\nbm\nbmc\nct\nctc\ncx\ncxw\ndj\ndjg\ndl\ndlr\nex\nexr\nfb\nfbk\ngp\ngpl\ngpr\nha\nhaf\nhb\nhbm\nhu\nhuy\niu\niuo\niw\niwa\niy\niyl\njg\njgp\njn\njnp\njx\njxw\nkh\nkha\nki\nkiu\nkl\nklu\nky\nkyj\nkz\nkzw\nlb\nlbi\nld\nldj\nlk\nlky\nlr\nlrh\nlrw\nlu\nlua\nmc\nmct\nmp\nmpl\nnp\nnpw\noa\noau\nod\nodl\nop\nopp\now\nowt\npk\npkl\npl\nplb\nplk\npm\npmp\npp\nppz\npr\nprq\npv\npw\npwu\npz\npzs\nqi\nqiw\nqpv\nqq\nqqi\nqr\nqrq\nqt\nq...", "323\nag\nagu\nah\nahk\nar\narp\naw\nawf\nbb\nbbh\nbf\nbfm\nbh\nbhm\nbo\nbos\nbu\nbus\ncc\nccd\nccs\ncd\ncdt\ncf\ncfe\ncl\nclq\ncq\ncqd\ncs\ncsa\ncsg\ncx\ncxd\ndf\ndft\ndk\ndkn\ndm\ndmk\ndo\ndol\ndq\ndql\ndr\ndrd\ndt\ndta\ndw\ndwn\nel\nelw\nep\nepc\nept\nes\nesk\nez\nezr\nfb\nfbf\nfe\nfep\nfez\nfk\nfki\nfm\nfmk\nfq\nfqc\nft\nftc\nftp\nfu\nfuf\nfv\nfvl\nga\ngar\nge\nges\ngf\ngfb\ngfe\ngl\nglg\nglx\ngt\ngtc\ngu\nguw\ngy\ngyn\nhg\nhgf\nhk\nhkp\nhm\nhmp\nhs\nhst\nia\niag\nie\niep\nig\nigl\niqn\njc\njcx\njt\njtw...", "505\nac\nacs\nad\nadc\nae\naem\nah\naht\nam\namq\nao\naof\naq\naqz\nar\narv\nas\nass\nasy\nat\natn\nav\navy\naw\nawx\nax\naxp\nba\nbae\nbas\nbax\nbe\nbex\nbf\nbfl\nbfn\nbg\nbgp\nbh\nbhg\nbj\nbjn\nbl\nblb\nbn\nbnd\nbs\nbsl\nbw\nbwr\nbx\nbxf\nca\ncaq\ncb\ncbf\ncd\ncdu\ncf\ncfm\ncfx\ncj\ncjs\ncq\ncqn\ncqr\ncr\ncrm\ncs\ncsc\ncsf\ncy\ncyp\ncyy\ndb\ndba\ndc\ndcy\nde\ndeh\ndo\ndoh\nds\ndsi\ndt\ndtz\ndu\ndut\nduv\ned\nedt\neh\nehr\nehs\nei\neiv\nel\neli\nem\nemj\nex\nexm\nfa\nfas\nfb\nfba\nfc\nfcf\nfcj\nfl\nflv\nf...", "375\nac\nacj\nad\nadp\nag\nagg\nagu\nal\nalk\nalu\nau\naul\nax\naxp\nba\nbag\nbal\nbf\nbfx\nbn\nbni\nbnq\nbp\nbpp\nbr\nbrn\ncc\nccz\nce\ncea\ncj\ncjr\nco\ncol\ncy\ncyg\ncz\nczl\nda\ndac\ndh\ndhk\ndhx\ndm\ndma\ndn\ndnr\ndp\ndpd\ndw\ndwm\ndx\ndxd\ndz\ndzh\nea\neau\neb\nebp\nei\neib\neu\neuw\nev\nevk\nfn\nfng\nfs\nfsn\nfv\nfvn\nfvt\nfx\nfxo\ngb\ngbp\ngf\ngfn\ngg\nggf\ngm\ngme\ngmi\ngmj\ngp\ngpv\ngs\ngst\ngu\ngul\ngw\ngwk\ngwr\ngy\ngyh\nha\nhag\nhj\nhk\nhkg\nhs\nhse\nhw\nhwl\nhwm\nhwu\nhx\nhxq\nhz\nhzz\nib\nib...", "462\nac\nace\nag\nagf\naj\najj\nao\nat\natx\nau\naun\nav\navl\nax\naxa\nbb\nbbq\nbc\nbcw\nbd\nbdl\nbg\nbge\nbgi\nbj\nbjg\nbp\nbps\nbq\nbqs\nbs\nbsq\nbt\nbtb\nbx\nbxq\ncb\ncbx\ncc\nccg\nce\ncep\ncf\ncfw\ncg\ncgt\ncgz\ncs\ncsu\ncv\ncvo\ncw\ncwj\ncwx\ncy\ncyf\ncz\nczd\ndd\nddr\nddw\ndh\ndhc\ndhp\ndl\ndlk\ndr\ndre\ndw\ndwf\nea\neau\neax\nec\necy\nee\neep\nef\nefo\neg\negx\neo\neot\nep\nepc\nepp\neq\nev\nevk\ney\neyn\nez\nezl\nfg\nfgm\nfh\nfhh\nfi\nfiu\nfj\nfjt\nfm\nfmi\nfo\nfof\nfov\nfp\nfpa\nfv\nfvc\nfw\nfwy\n...", "276\nam\namw\nap\napv\nau\nauw\naw\nawe\nbg\nbga\nbk\nbke\nbs\nbsa\nby\nbyb\ncl\nclp\nco\ncot\ndf\ndfr\ndh\ndhh\ndk\ndkc\ndkt\ndo\ndol\ndon\ndp\ndpo\ndq\ndqy\ndy\ndyy\nef\nefk\nei\nein\neq\neqw\net\nety\nez\nezf\nfd\nfdk\nfk\nfkq\nfl\nflj\nfr\nfrw\nfw\nfwz\nfy\nfyd\nga\ngam\ngc\ngcl\ngd\ngdq\ngn\ngns\ngs\ngsz\nhb\nhbk\nhh\nhhx\nhm\nhmp\nhr\nhrk\nhs\nhsr\nhx\nhxh\nhy\nhyg\nia\niap\nij\nija\nin\ninp\niy\niyu\nja\njau\njd\njdo\njdp\njf\njfw\njh\njhr\njx\njxg\nkc\nkco\nke\nkei\nkg\nkgs\nkm\nkmw\nkn\nknh\nknj\n...", "20\nbe\nbeb\nbko\nbo\nbob\neb\nebo\nhb\nhbe\njh\njhb\nko\nkor\nob\nor\nror\nsj\nsjh\nys\nysj", "274\nar\narf\narq\nas\nasz\nat\natx\nba\nbat\nbe\nbeo\nbg\nbgi\nbh\nbhf\nbk\nbkx\nbt\nbtb\nby\nbyt\nbz\nbze\ncd\ncdx\nch\nchh\ncm\ncmi\ncw\ncws\ncx\ncxb\ndc\ndch\ndd\nddy\nds\ndsb\ndx\ndxq\ndxw\ndy\ndyv\nea\neas\neb\nebk\neh\nehj\nei\neip\neo\neor\nfa\nfar\nfk\nfkv\nfl\nflz\nfp\nfpy\nfs\nfsr\nfsw\ngi\ngio\ngo\ngop\ngp\ngpz\nhb\nhbh\nhe\nhea\nhf\nhfk\nhh\nhhb\nhj\nhjt\nhos\nhu\nhuh\nhy\nhyp\nid\nidd\nio\nios\nip\nipb\nja\njar\njn\njnb\njp\njpk\njt\njtn\njy\njys\nkd\nkds\nkj\nkjy\nkn\nknz\nkq\nkqn\nkv\nkvl\n...", "10\ngs\ngsy\nrgs\nry\nryx\nsy\nxr\nysy\nyx\nyxr", "5\nxx\nxxx\nxyx\nyx\nyxx", "0", "1\nxx", "1\naa", "2\nxx\nxxx", "2\nxx\nyxx", "2\nxyz\nyz", "2\nxy\nyxy", "3\nxyy\nyx\nyy", "2\nxx\nxxx", "2\nxx\nxxx", "5\nxy\nyxy\nyzx\nzx\nzxy", "6\ndd\nddg\ndg\ndgg\ngg\nggg", "5\nab\nabz\nbz\nzz\nzzz", "4\naa\naaa\nca\ncca", "5\nab\naba\nabc\nba\nbc", "4\naab\nab\nbb\nbbb", "5\nab\naba\nabe\nba\nbe", "6\naa\naaa\nab\nba\nbaa\nbab"]}
UNKNOWN
PYTHON3
CODEFORCES
22
12be6f6b6f79389b9d1b141176a2b327
Unordered Subsequence
The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered. A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value. If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length *k* of the shortest such subsequence. Then output *k* integers from the range [1..*n*] — indexes of the elements of this subsequence. If there are several solutions, output any of them. Sample Input 5 67 499 600 42 23 3 1 2 3 3 2 3 1 Sample Output 3 1 3 5 0 3 1 2 3
[ "N = int(input())\r\nA = list(map(int,input().split()))\r\n\r\nB = [(A[0],1)]\r\nprev = A[0]\r\nfor i in range(N-1):\r\n if A[i+1]!=prev:\r\n B.append((A[i+1],i+2))\r\n prev = A[i+1]\r\n\r\nans = 0\r\nfor i in range(len(B)-2):\r\n if B[i][0]<B[i+1][0] and B[i+1][0]>B[i+2][0]:\r\n ans = (B[i][1],B[i+1][1],B[i+2][1])\r\n break\r\n elif B[i][0]>B[i+1][0] and B[i+1][0]<B[i+2][0]:\r\n ans = (B[i][1],B[i+1][1],B[i+2][1])\r\n break\r\n\r\nif ans==0:\r\n print(ans)\r\nelse:\r\n print(3)\r\n print(*ans)", "import itertools\r\nimport math\r\nimport time\r\nfrom builtins import input\r\nfrom math import gcd as gcd\r\nimport sys\r\nimport queue\r\nimport itertools\r\nimport collections\r\nfrom heapq import heappop, heappush\r\nimport random\r\nimport os\r\nfrom random import randint\r\nimport decimal\r\n\r\n# from sys import stdin, stdout\r\n# input, print = stdin.readline, stdout.write\r\n\r\ndecimal.getcontext().prec = 18\r\n\r\n\r\ndef solve():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n\r\n # saving not value but indexes\r\n pref_min = [0 for i in range(n)]\r\n suff_min = [n - 1 for i in range(n)]\r\n\r\n pref_max = [0 for i in range(n)]\r\n suff_max = [n - 1 for i in range(n)]\r\n\r\n for i in range(1, n):\r\n pref_max[i] = pref_max[i - 1]\r\n pref_min[i] = pref_min[i - 1]\r\n\r\n if a[i] > a[pref_max[i]]:\r\n pref_max[i] = i\r\n if a[i] < a[pref_min[i]]:\r\n pref_min[i] = i\r\n\r\n for i in range(n - 2, -1, -1):\r\n suff_max[i] = suff_max[i + 1]\r\n suff_min[i] = suff_min[i + 1]\r\n\r\n if a[i] > a[suff_max[i]]:\r\n suff_max[i] = i\r\n if a[i] < a[suff_min[i]]:\r\n suff_min[i] = i\r\n\r\n for i in range(1, n - 1):\r\n if a[pref_min[i - 1]] < a[i] > a[suff_min[i + 1]]:\r\n print(3)\r\n print(pref_min[i - 1] + 1, i + 1, suff_min[i + 1] + 1)\r\n return\r\n\r\n if a[pref_max[i - 1]] > a[i] < a[suff_max[i + 1]]:\r\n print(3)\r\n print(pref_max[i - 1] + 1, i + 1, suff_max[i + 1] + 1)\r\n return\r\n\r\n print(0)\r\n\r\n\r\nif __name__ == '__main__':\r\n multi_test = 0\r\n\r\n if multi_test == 1:\r\n t = int(sys.stdin.readline())\r\n for _ in range(t):\r\n solve()\r\n else:\r\n solve()\r\n", "from sys import stdin\n\n\nN = int(stdin.readline())\ndata = [int(w) for w in stdin.readline().split()]\n\n# low , high, low\ndp = [N - 1] * N\nfor i in range(N - 1, 0, -1):\n if data[i - 1] < data[dp[i]]:\n dp[i - 1] = i\n else:\n dp[i - 1] = dp[i]\n\nlow = 0\nfor i in range(1, N - 1):\n if data[i] > data[low] and data[i] > data[dp[i + 1]]:\n print(3)\n print(low + 1, i + 1, dp[i + 1] + 1)\n exit(0)\n if data[i] < data[low]:\n low = i\n\n# high, low, high\ndp = [N - 1] * N\nfor i in range(N - 1, 0, -1):\n if data[i - 1] > data[dp[i]]:\n dp[i - 1] = i\n else:\n dp[i - 1] = dp[i]\n\nhigh = 0\nfor i in range(1, N - 1):\n if data[i] < data[high] and data[i] < data[dp[i + 1]]:\n print(3)\n print(high + 1, i + 1, dp[i + 1] + 1)\n exit(0)\n if data[i] > data[high]:\n high = i\nprint(0)\n\n", "from sys import stdin,stdout\r\nfrom collections import Counter\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=lst()\r\n b=[a[0]]\r\n for i in range(1,n):\r\n if a[i]==b[-1]:continue\r\n else:b+=[a[i]]\r\n ans=[]\r\n for i in range(1,len(b)-1):\r\n if b[i-1]<b[i]>b[i+1] or b[i-1]>b[i]<b[i+1]:\r\n ans+=[b[i-1],b[i],b[i+1]]\r\n break\r\n if len(ans)!=3:\r\n print(0)\r\n continue\r\n p=0\r\n x=[]\r\n # print(ans)\r\n for i in range(n):\r\n if a[i]==ans[p]:\r\n p+=1\r\n x+=[i+1]\r\n if p>=3:break\r\n if p==3:\r\n print(3)\r\n print(*x)\r\n else:print(0)", "def main():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n p1, p2 = True, True\r\n for i in range(1, n):\r\n if a[i] > a[i - 1]:\r\n p1 = False\r\n if a[i] < a[i - 1]:\r\n p2 = False\r\n if not (p1 or p2):\r\n print(\"3\")\r\n print(1, i, i + 1)\r\n return\r\n print(\"0\")\r\n\r\nif __name__ == \"__main__\":\r\n main()# 1690811174.1351662", "n=int(input())\r\na=list(map(int,input().split()))\r\nfor i in range(2,n):\r\n if (a[i]-a[i-1])*(a[i-1]-a[0])<0:\r\n print(3,1,i,i+1)\r\n exit()\r\nprint(0)", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nmil, mal = list(a), list(a)\r\nfor i in range(1, n):\r\n mil[i] = min(mil[i], mil[i - 1])\r\nfor i in range(1, n):\r\n mal[i] = max(mal[i], mal[i - 1])\r\nmir, mar = list(a), list(a)\r\nfor i in range(n - 2, -1, -1):\r\n mir[i] = min(mir[i], mir[i + 1])\r\nfor i in range(n - 2, -1, -1):\r\n mar[i] = max(mar[i], mar[i + 1])\r\nans = []\r\nfor i in range(1, n - 1):\r\n ai = a[i]\r\n if mil[i - 1] < ai > mir[i + 1]:\r\n for j in range(i):\r\n if a[j] < ai:\r\n x = j + 1\r\n break\r\n for j in range(n - 1, i, -1):\r\n if a[j] < ai:\r\n y = j + 1\r\n break\r\n ans = [x, i + 1, y]\r\n break\r\n if mal[i - 1] > ai < mar[i + 1]:\r\n for j in range(i):\r\n if a[j] > ai:\r\n x = j + 1\r\n break\r\n for j in range(n - 1, i, -1):\r\n if a[j] > ai:\r\n y = j + 1\r\n break\r\n ans = [x, i + 1, y]\r\n break\r\nk = len(ans)\r\nprint(k)\r\nif not k:\r\n exit()\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\na = list(map(int, input().split()))\r\n\r\nleft_min = [(a[0], 0)] + [(10**9, -1)] * n\r\nright_min = [(10**9, -1)] * (n - 1) + [(a[-1], n - 1)]\r\nleft_max = [(a[0], 0)] + [(-10**9, -1)] * n\r\nright_max = [(-10**9, -1)] * (n - 1) + [(a[-1], n - 1)]\r\n\r\nfor i in range(1, n):\r\n left_min[i] = min(left_min[i - 1], (a[i], i))\r\n left_max[i] = max(left_max[i - 1], (a[i], i))\r\n\r\nfor i in range(n - 2, -1, -1):\r\n right_min[i] = min(right_min[i + 1], (a[i], i))\r\n right_max[i] = max(right_max[i + 1], (a[i], i))\r\n\r\nfor i in range(1, n - 1):\r\n if left_min[i - 1][0] < a[i] > right_min[i + 1][0]:\r\n print(3)\r\n print(left_min[i - 1][1] + 1, i + 1, right_min[i + 1][1] + 1)\r\n exit()\r\n if left_max[i - 1][0] > a[i] < right_max[i + 1][0]:\r\n print(3)\r\n print(left_max[i - 1][1] + 1, i + 1, right_max[i + 1][1] + 1)\r\n exit()\r\n\r\nprint(0)\r\n", "n=int(input())\r\nA=list(map(int,input().split()))\r\nminimal=A[0]\r\nimin=0\r\nmaximal=A[0]\r\nimax=0\r\ni=1\r\nd=False\r\nwhile i<n and not d:\r\n if imax<imin<i and minimal<A[i]:\r\n print(3)\r\n D=[imin+1,imax+1,i+1]\r\n D.sort()\r\n \r\n print(' '.join(map(str,D)))\r\n d=True\r\n if imin<imax<i and maximal>A[i]:\r\n print(3)\r\n D=[imin+1,imax+1,i+1]\r\n D.sort()\r\n \r\n print(' '.join(map(str,D)))\r\n d=True\r\n if A[i]>maximal:\r\n maximal=A[i]\r\n imax=i\r\n if A[i]<minimal:\r\n minimal=A[i]\r\n imin=i\r\n i+=1\r\nif not d: print(0)", "n = int(input())\r\narray = list(map(int, input().split()))\r\nmaxx = array[0]\r\nminn = array[0]\r\npositionMin = 0\r\npositionMax = 0\r\nfor i in range(n):\r\n if positionMax < positionMin:\r\n if (array[i] > minn) & (array[i] > minn):\r\n print(3)\r\n print(positionMax + 1, positionMin + 1, i + 1)\r\n break\r\n if positionMax > positionMin:\r\n if (array[i] < maxx) & (array[i] < maxx):\r\n print(3)\r\n print(positionMin + 1, positionMax + 1, i + 1)\r\n break\r\n if array[i] < minn:\r\n minn = array[i]\r\n positionMin = i\r\n if array[i] > maxx:\r\n maxx = array[i]\r\n positionMax = i\r\n if i == n - 1:\r\n print(0)", "num = int(input())\r\nc = input().split()\r\nfor i in range(num):\r\n c[i] = int(c[i])\r\nk = 0\r\nlisthl = []\r\nif num < 3:\r\n print(0)\r\n k = 1\r\nelse:\r\n for i in range(1,num):\r\n if c[i] > c[i-1]:\r\n listhl.append(\"h\")\r\n elif c[i-1] > c[i]:\r\n listhl.append(\"l\")\r\n else:\r\n listhl.append(\"s\")\r\n if listhl.count(\"h\") > 0 and listhl.count(\"l\") > 0:\r\n print(\"3\")\r\n a = listhl.index(\"h\")\r\n b = listhl.index(\"l\")\r\n if a > b:\r\n print(b+1,a+1,a+2)\r\n else:\r\n print(a+1,b+1,b+2)\r\n else:\r\n print(0)\r\n \r\n \r\n \r\n \r\n \r\n\r\n", "# LUOGU_RID: 111117503\nfrom sys import stdin \ninput = stdin.readline \n\nn = int(input()) \nlst = [0] + list(map(int,input().split()))\n\nfor i in range(2, n) : \n if (lst[i + 1] > lst[i] and lst[i] < lst[1]) or (lst[i + 1] < lst[i] and lst[i] > lst[1]) : \n print(3) \n print(1, i, i + 1) \n exit() \n\nprint(0)\n", "from sys import stdin, stdout, setrecursionlimit\r\ninput = stdin.readline\r\n# import string\r\n# characters = string.ascii_lowercase\r\n# digits = string.digits\r\n# setrecursionlimit(int(1e6))\r\n# dir = [-1,0,1,0,-1]\r\n# moves = 'NESW'\r\ninf = float('inf')\r\nfrom functools import cmp_to_key\r\nfrom collections import defaultdict as dd\r\nfrom collections import Counter, deque\r\nfrom heapq import *\r\nimport math\r\nfrom math import floor, ceil, sqrt\r\ndef geti(): return map(int, input().strip().split())\r\ndef getl(): return list(map(int, input().strip().split()))\r\ndef getis(): return map(str, input().strip().split())\r\ndef getls(): return list(map(str, input().strip().split()))\r\ndef gets(): return input().strip()\r\ndef geta(): return int(input())\r\ndef print_s(s): stdout.write(s+'\\n')\r\n\r\ndef solve():\r\n n = geta()\r\n a = getl()\r\n mini = 0\r\n maxi = 0\r\n min_so_far = [-1]*n\r\n max_so_far = [-1]*n\r\n min_so_far[-1] = n-1\r\n max_so_far[-1] = n-1\r\n for i in range(n-2, -1, -1):\r\n if a[i] < a[min_so_far[i+1]]:\r\n min_so_far[i] = i\r\n else:\r\n min_so_far[i] = min_so_far[i+1]\r\n if a[i] > a[max_so_far[i+1]]:\r\n max_so_far[i] = i\r\n else:\r\n max_so_far[i] = max_so_far[i+1]\r\n\r\n for i in range(1, n-1):\r\n if a[i] > a[mini] and a[i] > a[max_so_far[i+1]]:\r\n print(3)\r\n print(mini+1, i+1, max_so_far[i+1]+1)\r\n return\r\n elif a[i] < a[maxi] and a[i] < a[min_so_far[i+1]]:\r\n print(3)\r\n print(maxi+1, i+1, min_so_far[i+1]+1)\r\n return\r\n if a[mini] > a[i]:\r\n mini = i\r\n if a[maxi] < a[i]:\r\n maxi = i\r\n print(0)\r\n return\r\n\r\n\r\nif __name__=='__main__':\r\n solve()\r\n", "n=int(input())\r\nA=list(map(int,input().split()))\r\n\r\nB=[]\r\n\r\nfor i in range(n):\r\n if i>0 and A[i]==A[i-1]:\r\n continue\r\n B.append((A[i],i))\r\n\r\n\r\nfor i in range(len(B)-2):\r\n x,i1=B[i]\r\n y,i2=B[i+1]\r\n z,i3=B[i+2]\r\n\r\n if x<y and y>z:\r\n print(3)\r\n print(i1+1,i2+1,i3+1)\r\n exit()\r\n\r\n if x>y and y<z:\r\n print(3)\r\n print(i1+1,i2+1,i3+1)\r\n exit()\r\n\r\nprint(0)\r\n", "\n\n\n# n = int(input())\n# array = [int(x) for x in input().split(' ')]\n\n\ninput()\nt = list(map(int, input().split()))\nfor i in range(2, len(t)):\n if (t[i] - t[i - 1]) * (t[i - 1] - t[0]) < 0:\n print(3, 1, i, i + 1)\n exit()\nprint(0)\n\n \n", "n = int(input())\r\n\r\nl = input()\r\nl = [int(i) for i in l.split()]\r\nr = 0\r\nd = []\r\nx = []\r\nfor i in range(n-1) :\r\n if l[i]!=l[i+1]:\r\n d.append(l[i])\r\n x.append(i+1)\r\n\r\nd.append(l[-1])\r\nx.append(n)\r\n\r\na,b,c = 0 , 0 , 0 \r\nfor i in range(0 , len(d)-2):\r\n if d[i]>d[i+1] and d[i+1]<d[i+2]:\r\n print(3)\r\n print(x[i] , x[i+1] , x[i+2])\r\n r = 1\r\n break\r\n elif d[i]<d[i+1] and d[i+1]>d[i+2]:\r\n print(3)\r\n print(x[i] , x[i+1] , x[i+2])\r\n r = 1 ; break\r\nif r==0:\r\n print(0)\r\n", "input()\r\nt = list(map(int, input().split()))\r\nfor i in range(2, len(t)):\r\n if (t[i] - t[i - 1]) * (t[i - 1] - t[0]) < 0:\r\n print(3, 1, i, i + 1)\r\n exit()\r\nprint(0)\r\n", "s = input().split()\r\nn = int(s[0])\r\ns1 = input().split()\r\na = []\r\nfor i in range(1, n + 1) :\r\n a.append(int(s1[i - 1]))\r\nflag = 1\r\nfor i in range(2, n) :\r\n if (((a[i] > a[i - 1]) and (a[i - 1] < a[0])) or ((a[i] < a[i - 1]) and (a[i -1] > a[0]))) :\r\n print(3)\r\n print(1, i, i + 1)\r\n flag = 0\r\n break\r\nif (flag == 1) :\r\n print(0)", "t = 1\r\nwhile t:\r\n t -= 1\r\n q = int(input())\r\n b = list(map(int, input().split()))\r\n prev = -1\r\n flag = 0\r\n sa = []\r\n k = 0\r\n for i in b:\r\n if i != prev:\r\n sa.append([i, k])\r\n prev = i\r\n k += 1\r\n \r\n for i in range(1, len(sa) - 1):\r\n\r\n if sa[i - 1][0] < sa[i][0] and sa[i + 1][0] < sa[i][0]:\r\n print('3')\r\n print(sa[i - 1][1] + 1, sa[i][1] + 1, sa[i + 1][1] + 1)\r\n flag = 1\r\n break\r\n if sa[i - 1][0] > sa[i][0] and sa[i + 1][0] > sa[i][0]:\r\n print('3')\r\n print(sa[i - 1][1] + 1, sa[i][1] + 1, sa[i + 1][1] + 1)\r\n flag = 1\r\n break\r\n if not flag:\r\n print('0')\r\n", "import sys\r\ninput = sys.stdin.readline\r\nn = int(input())\r\nls = list(map(int,input().split()))\r\nl1 = ls.copy()\r\nl1.sort()\r\nfor i in range(n) :\r\n if ls[i] != l1[i] :\r\n break\r\nelse :\r\n print(0)\r\n exit()\r\nl1.reverse()\r\nfor i in range(n) :\r\n if ls[i] != l1[i] :\r\n break\r\nelse :\r\n print(0)\r\n exit()\r\nj = 1\r\nwhile j+1 < n and ((ls[j] >= ls[0] and ls[j+1] >= ls[j]) or (ls[j] <= ls[0] and ls[j+1] <= ls[j])) :\r\n j += 1\r\nprint(3)\r\nprint(1,j+1,j+2)" ]
{"inputs": ["3\n3 1 2", "1\n-895376", "2\n166442 61629", "3\n-771740 -255752 -300809", "4\n-227347 -573134 -671045 11011", "5\n834472 -373089 441294 -633071 -957672", "2\n7 8"], "outputs": ["3\n1 2 3", "0", "0", "3\n1 2 3", "3\n2 3 4", "3\n1 2 3", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
20
12d93ca6906e39940b5ee321de7f9ae7
Postcards and photos
Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not carry in his hands objects of two different types. In other words, Polycarpus can't carry both postcards and photos simultaneously. Sometimes he goes to the closet and puts the objects there, thus leaving his hands free. Polycarpus must put all the postcards and photos to the closet. He cannot skip objects. What minimum number of times he should visit the closet if he cannot carry more than 5 items? The only line of the input data contains a non-empty string consisting of letters "С" and "P" whose length does not exceed 100 characters. If the *i*-th character in the string is the letter "С", that means that the *i*-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if the *i*-th character is the letter "P", than the *i*-th object on the wall is a photo. Print the only number — the minimum number of times Polycarpus has to visit the closet. Sample Input CPCPCPC CCCCCCPPPPPP CCCCCCPPCPPPPPPPPPP CCCCCCCCCC Sample Output 7 4 6 2
[ "import sys\r\nimport math\r\n\r\ns=str(input())\r\nc,p,cona=0,0,0\r\nfor i in range(len(s)):\r\n if(s[i]=='C'):\r\n c+=1\r\n if(p!=0):\r\n cona+=p//5\r\n if(p%5!=0): cona+=1\r\n p=0\r\n else:\r\n p+=1\r\n if(c!=0):\r\n cona+=c//5\r\n if (c%5!=0): cona+=1\r\n c=0\r\nif(c!=0 or p!=0):\r\n cona+=c//5+p//5\r\n if(c%5!=0 or p%5!=0): cona+=1\r\nprint(cona)\r\n\r\n\r\n", "import sys\r\nfrom math import sqrt, log, log2, ceil, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial\r\nfrom copy import copy, deepcopy\r\nfrom sys import exit, stdin, stdout\r\nfrom collections import Counter, defaultdict, deque\r\nfrom itertools import permutations\r\nimport heapq\r\nfrom bisect import bisect_left \r\nfrom bisect import bisect_right\r\n# sys.setrecursionlimit(100000000)\r\nmod = 1000000007\r\niinp = lambda: int(sys.stdin.readline())\r\ninp = lambda: sys.stdin.readline().strip()\r\nstrl = lambda: list(inp().strip().split(\" \"))\r\nintl = lambda: list(map(int, inp().split(\" \")))\r\nmint = lambda: map(int, inp().split())\r\nflol = lambda: list(map(float, inp().split(\" \")))\r\nflush = lambda: stdout.flush()\r\n# ========================================================Functions====================================================\r\ndef solve():\r\n s=inp()\r\n s1=[s[0]]\r\n c=0\r\n for i in range(1,len(s)):\r\n if len(s1)==0:\r\n s1.append(s[i])\r\n else:\r\n if s1[-1]!=s[i]:\r\n c+=1\r\n # print(\"#2\")\r\n s1.clear()\r\n s1.append(s[i])\r\n else:\r\n s1.append(s[i])\r\n if len(s1)==5:\r\n # print(\"#3\")\r\n c+=1\r\n s1.clear()\r\n if s1:\r\n c+=1\r\n print(c)\r\n return\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n# ========================================================Main Code=====================================================\r\n# t=iinp()\r\nt=1\r\nfor _ in range(t):\r\n solve()", "s = input()\r\nvisit, c = 1, 1\r\nfor i in range(len(s)):\r\n if i + 1 <= len(s) - 1:\r\n if s[i] != s[i+1] or c == 5:\r\n visit += 1\r\n c = 1\r\n elif s[i] == s[i+1]:\r\n c += 1\r\nprint(visit)", "import math\ns=input()\n\nc=0\nn=len(s)\ni=0\np=s[0]\nans=0\nwhile(i<n):\n if(s[i]==p):\n c+=1\n else:\n ans+=math.ceil(c/5)\n p=s[i]\n c=1\n i+=1\nans+=math.ceil(c/5)\nprint(ans)\n", "C, P, ans = 0, 0, 0 \r\n\r\nS = input()\r\n\r\nfor i, q in enumerate(S):\r\n if q == 'C':\r\n if P != 0:\r\n ans += 1\r\n C = 1\r\n P = 0\r\n else:\r\n if C < 5: C += 1\r\n else:\r\n C = 1\r\n ans += 1\r\n else:\r\n if C != 0:\r\n ans += 1\r\n P = 1\r\n C = 0\r\n else:\r\n if P < 5: P += 1\r\n else:\r\n P = 1\r\n ans += 1\r\nif C != 0 or P != 0: ans += 1\r\nprint(ans) ", "s=input().strip()\r\ncount=0\r\ni=0\r\nwhile i<len(s):\r\n j=0\r\n while j<5 and i+j<len(s) and s[i]==s[i+j]:\r\n j+=1\r\n i+=j\r\n count+=1 \r\nprint(count)", "st = input()\r\ncon = 1\r\nans = 1\r\npre = st[0]\r\nfor i in range(1, len(st)):\r\n if pre == st[i] and con <5:\r\n con+=1\r\n else:\r\n con = 1\r\n ans+=1\r\n pre = st[i]\r\nprint(ans)", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\ndata = input().rstrip()\r\ndata = '?' + data\r\n\r\ncnt = 0\r\nnow = 0\r\nfor i in range(1, len(data)):\r\n if data[i - 1] != data[i]:\r\n now = 1\r\n cnt += 1\r\n else:\r\n now += 1\r\n\r\n if now > 5:\r\n now = 1\r\n cnt += 1\r\n\r\n\r\nprint(cnt)", "s=input()+'0';k=len(s);t,p=1,0\r\nfor i in range(k-1):\r\n if s[i]==s[i+1]:t+=1\r\n else:p-=-t//5;t=1\r\nprint(p)", "s=input()\r\ncnt=0\r\nres=0\r\nfor i in range(len(s)):\r\n if s[i]==s[i-1]:\r\n cnt+=1\r\n else:\r\n res=res+((cnt+4)//5)\r\n cnt=1\r\nres+=(cnt+4)//5\r\nprint(res)", "objects = input()\r\ncards = 0 \r\nphotos = 0 \r\nmoves = 0 \r\nfor obj in objects:\r\n if photos == 5 or cards == 5:\r\n moves+=1\r\n photos,cards = 0,0\r\n if obj == 'C': \r\n if photos > 0: \r\n moves += 1\r\n photos = 0\r\n cards += 1\r\n elif obj == 'P': \r\n if cards > 0: \r\n moves += 1\r\n cards = 0\r\n photos += 1\r\nif cards > 0 or photos > 0:\r\n moves += 1\r\nprint(moves) ", "def main():\n s = input()\n l, a = [], '*'\n for i, b in enumerate(s):\n if a != b:\n a = b\n l.append(i)\n l.append(len(s))\n res = sum((j - i + 4) // 5 for i, j in zip(l, l[1:]))\n print(res)\n\n\nif __name__ == '__main__':\n main()\n", "s=input()\r\nn=len(s)\r\nsub=s[0]\r\nc=1\r\nfor i in range(n-1):\r\n if s[i+1]!=sub[-1] or len(sub)>=5:\r\n sub=s[i+1]\r\n c+=1\r\n elif s[i+1]==sub[-1] and len(sub)<6:\r\n sub+=s[i+1]\r\nprint(c)\r\n", "t = input()\r\ns, count1, count2 = \"\", 0, 0\r\nfor elem in t:\r\n if elem == s:\r\n count1 += 1\r\n else:\r\n count2 += 1\r\n count1 = 0\r\n if count1 == 5:\r\n count2 += 1\r\n count1 = 0\r\n s = elem\r\nprint(count2)\r\n", "s = input().strip()\ncount = 1\nprevious = s[0]\nloads = 1\nfor ch in s[1:]:\n if ch != previous or count == 5:\n loads += 1\n count = 1\n previous = ch\n else:\n count += 1\nprint(loads)\n", "line = input()\r\ncount = 0\r\ncurr = 0\r\nfor i in range(0, len(line)-1):\r\n\tif line[i] != line[i+1] or curr == 4:\r\n\t\tcurr = 0\r\n\t\tcount += 1\r\n\t\t# i-=1\r\n\telse:\r\n\t\tcurr += 1\r\n\r\nif curr != 5:\r\n\tcount+=1\r\nprint(count)", "s = input()\r\np = 1; m = 1\r\nfor i in range(0, len(s)-1):\r\n if s[i] == s[i+1]:\r\n if (p == 5):\r\n p = 0\r\n m +=1\r\n p +=1\r\n else:\r\n p = 1\r\n m +=1\r\nprint(m)\r\n\r\n \r\n \r\n", "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\n#write your code here\r\nc = [\"C\"*i for i in range(1,6)]\r\np = [\"P\"*i for i in range(1,6)]\r\nc = c[::-1]\r\np = p[::-1]\r\ns = input()\r\nans = 0\r\n\r\ni = 0\r\n\r\nwhile s.count('C') != 0 or s.count('P')!=0:\r\n for i in c:\r\n if i in s:\r\n ans = ans+s.count(i)\r\n s = s.replace(i,\"*\")\r\n for i in p:\r\n if i in s:\r\n ans = ans+s.count(i)\r\n s = s.replace(i,\"*\")\r\n\r\n\r\n\r\nprint(ans)\r\n \r\n \r\n\r\n\r\nif(path.exists('input.txt')):\r\n sys.stdin.close()\r\n sys.stdout.close()", "s = input()\r\ncnt = 0\r\nwhile s:\r\n i = 0\r\n while i < min(5, len(s)):\r\n if s[i] == s[0]:\r\n i += 1\r\n else:\r\n break\r\n cnt += 1\r\n s = s[i:]\r\nprint(cnt)", "t = input()\r\nx=\"\"\r\ni=0\r\ns=0\r\nfor a in t:\r\n if a==x:\r\n i+=1\r\n else:\r\n s+=1\r\n i=0\r\n if i==5:\r\n s+=1\r\n i=0\r\n x=a\r\nprint(s) ", "s = input()\r\ncol = 0\r\nwhile len(s)>0:\r\n flag = True\r\n inHand=s[0]\r\n hand=4\r\n s=s[1:]\r\n col = col + 1\r\n while hand>0 and len(s)>0 and flag==True:\r\n if inHand==s[0]:\r\n s = s[1:]\r\n hand=hand-1\r\n else:\r\n flag=False\r\nprint(col)\r\n", "objects = input()\n\nprev = None\nsame_counter = None\ntotal_moves = 0\nfor obj in objects:\n if obj != prev:\n same_counter = 1\n prev = obj\n total_moves += 1\n else:\n if same_counter == 5:\n same_counter = 1\n total_moves += 1\n else:\n same_counter += 1\nprint(total_moves)\n", "data = list(input())\r\nresult = 1\r\ncnt = 1\r\n\r\nfor i in range(1,len(data)):\r\n if data[i]!=data[i-1]:\r\n result += 1\r\n cnt = 1\r\n else:\r\n if cnt==5:\r\n result += 1\r\n cnt = 1\r\n else:\r\n cnt += 1\r\n\r\nprint(result)", "import os,sys\r\nfrom io import BytesIO, IOBase\r\n\r\nfrom collections import deque, Counter,defaultdict as dft\r\nfrom heapq import heappop ,heappush\r\nfrom math import log,sqrt,factorial,cos,tan,sin,radians,log2,ceil,floor\r\nfrom bisect import bisect,bisect_left,bisect_right\r\nfrom decimal import *\r\nimport sys,threading\r\nfrom itertools import permutations, combinations\r\nfrom copy import deepcopy\r\ninput = sys.stdin.readline\r\n\r\n\r\nii = lambda: int(input())\r\nsi = lambda: input().rstrip()\r\nmp = lambda: map(int, input().split())\r\nms= lambda: map(str,input().strip().split(\" \"))\r\nml = lambda: list(mp())\r\nmf = lambda: map(float, input().split())\r\n\r\n\r\nalphs = \"abcdefghijklmnopqrstuvwxyz\"\r\n\r\n\r\n# stuff you should look for\r\n\t# int overflow, array bounds\r\n\t# special cases (n=1?)\r\n\t# do smth instead of nothing and stay organized\r\n\t# WRITE STUFF DOWN\r\n\t# DON'T GET STUCK ON ONE APPROACH\r\n\r\n#\r\n\r\ndef solve():\r\n s=input()\r\n res=0\r\n curr=0\r\n pre='*'\r\n for c in s:\r\n if c!=pre:\r\n if curr:\r\n res+=1\r\n curr=1\r\n else:\r\n curr+=1\r\n res+=curr//5\r\n curr%=5\r\n pre=c\r\n if curr:\r\n res+=1 \r\n print(res)\r\n \r\n \r\n \r\n \r\n\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\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\nif sys.version_info[0] < 3:\r\n sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)\r\nelse:\r\n sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\n \r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n \r\n# endregion\r\n \r\n \r\nif __name__ == \"__main__\":\r\n tc=1\r\n #tc = ii()\r\n for i in range(tc):\r\n \tsolve()\r\n \t", "s = input()\r\ncol = 0\r\nwhile len(s)>0:\r\n inHand=s[0]\r\n hand=4\r\n s=s[1:]\r\n col = col + 1\r\n while hand>0 and len(s)>0:\r\n if inHand==s[0]:\r\n s = s[1:]\r\n hand=hand-1\r\n else:\r\n break\r\nprint(col)", "s = input()\r\ncarried_item = 1\r\ntime = 1\r\nfor i in range(1, len(s)):\r\n if s[i] == s[i-1] and carried_item < 5:\r\n carried_item += 1\r\n else:\r\n time += 1\r\n carried_item = 1\r\nprint(time)\r\n", "z = input()\r\nz += 'O'\r\ns = 0\r\np = 0\r\nfor i in range(len(z)-1):\r\n if s <= 5:\r\n if z[i] == z[i+1]:\r\n s += 1.5\r\n else:\r\n p += 1\r\n s = 0\r\n else:\r\n p += 1\r\n s = 0\r\nprint(p)", "s = input()\r\nn = len(s)\r\ntotal = 0\r\ni = 0\r\nwhile i < (len(s)):\r\n ch = s[i]\r\n totcarry = 0\r\n while i<len(s) and s[i]==ch and totcarry<5:\r\n totcarry+=1\r\n i+=1\r\n total+=1\r\nprint(total)\r\n\r\n", "a=input()\r\nx=a[0]\r\nr=j=0\r\nfor c in a:\r\n if c!=x or j==5:\r\n x=c;j=0;r+=1\r\n j+=1\r\nprint(r+1)\r\n ", "s = input()\r\nc = 1; ans = 1\r\nfor i in range(1,len(s)):\r\n if(s[i]==s[i-1]):\r\n c+=1\r\n if(c>5):\r\n c = 1\r\n ans+=1\r\n else:\r\n c = 1\r\n ans+=1\r\nprint(ans)\r\n \r\n ", "a=input()\nx=a[0]\nr=j=0\nfor c in a:\n if c!=x or j==5:\n x=c;j=0;r+=1\n j+=1\nprint(r+1)\n \n \t \t \t\t\t \t \t\t \t \t \t \t", "prev = ''\n\nh = 0\n\nn = 0\n\nfor ch in input():\n\n if ch != prev or h == 5:\n\n h = 1\n\n n += 1\n\n else:\n\n h += 1\n\n prev = ch\n\nprint(n)", "a=input()\r\nx=0\r\ns=[]\r\nwhile x!=len(a):\r\n s1=0\r\n while x!=len(a) and a[x]=='C':\r\n s1+=1\r\n x+=1\r\n s.append(s1)\r\n s1=0\r\n while x!=len(a) and a[x]=='P':\r\n s1+=1\r\n x+=1\r\n s.append(s1)\r\nans=0\r\nfor x in range(len(s)):\r\n if s[x]!=0:\r\n if s[x]%5==0:\r\n ans+=s[x]//5\r\n else:\r\n ans+=(s[x]//5)+1\r\nprint(ans)\r\n", "data = list(input())\r\n\r\ncnt = 0\r\nseq = 0\r\nformer = 0\r\nfor ch in data:\r\n if former!=ch:\r\n seq = 1\r\n cnt += 1\r\n former = ch\r\n else:\r\n if seq==5:\r\n cnt += 1\r\n seq = 1\r\n else:\r\n seq += 1\r\n\r\nprint(cnt)", "from math import ceil \r\ns = input() \r\np = [] \r\nc = [] \r\nC, P = 0, 0\r\nfor i in range(len(s)): \r\n if s[i] == \"C\": \r\n p.append(P)\r\n P = 0 \r\n C += 1\r\n else : \r\n c.append(C) \r\n C = 0 \r\n P += 1\r\n if i == len(s) - 1 : \r\n if s[i] == \"C\" : c.append(C) \r\n else : p.append(P) \r\nprint(sum(ceil(i/5) for i in c) + sum(ceil(i/5) for i in p))", "s=input()\r\ncurrent = None\r\ncount = 0\r\nk = 0\r\nfor c in s:\r\n if c!=current:\r\n current=c\r\n count+=1\r\n k=1\r\n elif k == 5:\r\n k=1\r\n count+=1\r\n else:\r\n k+=1\r\nprint(count)", "str = input();\r\nn = len(str);\r\ncount = 0;\r\nhand = [];\r\nfor i in range(0, n):\r\n if hand.__len__() == 0:\r\n hand.append(str[i]);\r\n elif str[i] == hand[-1] and hand.__len__() < 5:\r\n hand.append(str[i]);\r\n else:\r\n count = count + 1;\r\n hand = [str[i]];\r\nprint (count + (hand.__len__() != 0))\r\n \r\n \r\n", "s = input()\r\n\r\nct = 0\r\n\r\ntemp = s[0]\r\n\r\nfor char in s[1:]:\r\n if temp[-1] == char and len(temp) < 5:\r\n temp += char\r\n else:\r\n ct += 1\r\n temp = char\r\nprint(ct+1)\r\n\r\n\r\n", "s = list(input())\nm = ''\nkl = 1\nfor i in s:\n if len(m) != 0:\n if m[-1] != i or len(m) == 5:\n kl += 1\n m = i\n else:\n m += i\n else:\n m += i\nprint(kl)\n \n", "objects = input()\r\n\r\nprev = 'P' if objects[0] == 'C' else 'C'\r\n\r\nans = 0\r\ncnt = 0\r\nfor e in objects:\r\n if e == prev and cnt < 4:\r\n cnt += 1\r\n else:\r\n ans += 1\r\n cnt = 0\r\n\r\n prev = e\r\n\r\nprint(ans)\r\n", "s=input();x=s[0];a=b=0\r\nfor i in s:\r\n\tif i!=x or b==5: x=i;b=0;a+=1\r\n\tb+=1\r\nprint(a+1)", "data = list(input())\r\ndata.append('X')\r\ncnt = 0\r\nseq = 1\r\nfor i in range(1,len(data)):\r\n if data[i]==data[i-1]:\r\n seq+=1\r\n else:\r\n cnt += (seq-1)//5 + 1\r\n seq = 1\r\nprint(cnt)", "import math\r\n\r\ns = input()\r\ncnt, ans = 1, 1\r\nfor i in range(1, len(s)):\r\n if s[i] == s[i - 1] and cnt < 5:\r\n cnt += 1\r\n else:\r\n cnt = 1\r\n ans += 1\r\n\r\nprint(ans)", "s=str(input())\r\nnum=1\r\ncount=0\r\nt=s[0]\r\nl=len(s)\r\nfor i in range(1,l):\r\n if t==s[i]:\r\n count+=1\r\n if count==5:\r\n num+=1\r\n count=0\r\n else:\r\n t=s[i]\r\n num+=1\r\n count=0\r\nprint(num)", "s = list(input())\r\ntotal = 1\r\ncounter = 0\r\nfor i in range(len(s) - 1):\r\n if s[i] != s[i + 1]:\r\n total += 1\r\n counter = 0\r\n elif s[i] == s[i + 1]:\r\n if counter < 4:\r\n counter += 1\r\n else:\r\n total += 1\r\n counter = 0\r\n\r\nprint(total)", "\r\n# -*- coding: utf-8 -*-\r\n# @Date : 2019-01-23 11:45:12\r\n# @Author : raj lath ([email protected])\r\n# @Link : link\r\n# @Version : 1.0.0\r\n\r\nfrom sys import stdin\r\n\r\nmax_val=int(10e12)\r\nmin_val=int(-10e12)\r\n\r\ndef read_int() : return int(stdin.readline())\r\ndef read_ints() : return [int(x) for x in stdin.readline().split()]\r\ndef read_str() : return input()\r\ndef read_strs() : return [x for x in stdin.readline().split()]\r\n\r\n\r\nins = [x for x in input()]\r\nturns = 0\r\ndone = 0\r\nwhile ins:\r\n curr = ins.pop()\r\n if len(ins) > 0:\r\n if curr == ins[-1]:\r\n done += 1\r\n if done == 5:\r\n turns += 1\r\n done = 0\r\n else:\r\n turns += 1\r\n done = 0\r\n else:\r\n turns += 1\r\nprint(turns)\r\n", "import math\r\nl=list(input())\r\nk=1\r\nans=0\r\nfor i in range(len(l)-1):\r\n if l[i]==l[i+1]:\r\n k+=1\r\n else:\r\n ans+=math.ceil(k/5)\r\n k=1\r\nans+=math.ceil(k/5)\r\nprint(ans)", "input_string = input()\r\nfinal_result, current_count = 0, 1\r\n\r\nfor i in range(1, len(input_string)):\r\n if input_string[i] == input_string[i - 1]:\r\n current_count += 1\r\n else:\r\n final_result += (current_count + 4) // 5\r\n current_count = 1\r\n\r\nfinal_result += (current_count + 4) // 5\r\nprint(final_result)\r\n", "daf = list(input())\r\n\r\ncount = 0\r\ncurrent = 'X'\r\nnum_current = 0\r\n\r\nfor x in daf:\r\n if num_current >= 5:\r\n count += 1\r\n current = 'X'\r\n num_current = 0\r\n if current == 'X':\r\n current = x\r\n num_current += 1\r\n elif current == x:\r\n num_current += 1\r\n else:\r\n count += 1\r\n num_current = 1\r\n current = x\r\n '''\r\n print('count', count)\r\n print('num_current', num_current)\r\n print('current', current)\r\n print()\r\n ''' \r\n\r\nprint(count + 1)\r\n \r\n", "\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\n\r\ns = input()[:-1]\r\nc, d = 0, 0\r\ned = ''\r\nfor i in range(len(s)):\r\n if s[i] == ed:\r\n d += 1\r\n if d == 5:\r\n c += 1\r\n d = 0\r\n else:\r\n c += 1\r\n d = 0\r\n ed = s[i]\r\nprint(c)\r\n", "n = input()\r\nt = 0\r\np = ''\r\nm = 0\r\nfor c in n:\r\n if p == '':\r\n p = c\r\n m += 1\r\n elif p != c or m == 5:\r\n m = 1\r\n p = c\r\n t += 1\r\n elif p == c:\r\n m += 1\r\nprint(t + 1)\r\n", "stena= input ()\r\nj=''\r\nfor i in stena:\r\n if j=='':\r\n j=i\r\n vruke=1\r\n pohodov=1\r\n else:\r\n if vruke==0:\r\n pohodov+=1\r\n if i==j:\r\n vruke+=1\r\n # print (vruke,' ',i,' ',j,' ',pohodov)\r\n else:\r\n if vruke!=0:\r\n pohodov+=1\r\n vruke=1\r\n j=i\r\n# print (vruke,' ',i,' ',j,' ',pohodov)\r\n if vruke==5:\r\n vruke=0\r\n# print (vruke,' ',i,' ',j,' ',pohodov)\r\nprint (pohodov)\r\n", "string = input()\r\ntotal = 0\r\np = 0\r\nc = 0 \r\n\r\nfor i in string:\r\n if i == 'C':\r\n if p > 0:\r\n total += 1\r\n p = 0\r\n if c == 5:\r\n total += 1\r\n c = 0\r\n c += 1\r\n else:\r\n if c > 0:\r\n total += 1\r\n c = 0\r\n if p == 5:\r\n total += 1\r\n p = 0\r\n p += 1\r\n\r\nprint(total + 1)", "l = input()\r\na = l[0]\r\ns = j = 0\r\nfor i in l:\r\n if i != a or j==5:\r\n a=i\r\n j=0\r\n s+=1\r\n j+=1\r\nprint(s+1)", "string = input()\r\nfor i in range(5, 0, -1):\r\n string = string.replace('C' * i, 'x')\r\n string = string.replace('P' * i, 'y')\r\nprint(len(string))", "s = input()\n\nk, p = 0, 0\nfor i in range(1, len(s)):\n\tk += 1\n\tif s[i] != s[i-1]:\n\t\tk = 0\n\t\tp += 1\n\telif k == 5:\n\t\tk = 0\n\t\tp += 1\nprint(p + 1)\n", "def main():\n s = input()\n\n photos_count = 0\n cards_count = 0\n n_closet_visites = 0\n\n for c in s:\n if c == 'P':\n if cards_count > 0:\n n_closet_visites += 1\n cards_count = 0\n photos_count = 1\n else:\n photos_count += 1\n\n if photos_count == 5:\n n_closet_visites += 1\n photos_count = 0\n elif c == 'C':\n if photos_count > 0:\n n_closet_visites += 1\n photos_count = 0\n cards_count = 1\n else:\n cards_count += 1\n\n if cards_count == 5:\n n_closet_visites += 1\n cards_count = 0\n\n if photos_count > 0 or cards_count > 0:\n n_closet_visites += 1\n photos_count = 0\n cards_count = 0\n\n print(n_closet_visites)\n\n\nif __name__ == '__main__':\n main()\n", "a = list(input())\r\nsum = 0\r\nwhile len(a) != 0:\r\n s = a[0]\r\n t = 0\r\n while len(a) > 0 and a[0] == s:\r\n a.pop(0)\r\n t += 1\r\n if t == 5:\r\n break\r\n sum += 1\r\nprint(sum)\r\n", "s=input()\nli=[]\nc=1\nfor i in range(1,len(s)):\n if s[i-1]==s[i]:\n c+=1\n else:\n if c<=5:\n li.append(1)\n elif c%5==0:\n li.append(c//5)\n else:\n li.append((c//5)+1)\n c=1\nif c<=5:\n li.append(1)\nelif c%5==0:\n li.append(c//5)\nelse:\n li.append((c//5)+1)\nprint(sum(li))\n", "s = str(input())\r\nX = []\r\ncur = s[0]\r\ncnt = 0\r\nfor c in s:\r\n if c == cur:\r\n cnt += 1\r\n else:\r\n X.append(cnt)\r\n cur = c\r\n cnt = 1\r\nelse:\r\n X.append(cnt)\r\nans = 0\r\nfor x in X:\r\n ans += (x+4)//5\r\nprint(ans)\r\n", "l = input()\r\nm = 0\r\nn = 0\r\nfor i in range(1, len(l)):\r\n\tm += 1\r\n\tif l[i] != l[i-1]:\r\n\t\tm = 0\r\n\t\tn += 1\r\n\telif m == 5:\r\n\t\tm = 0\r\n\t\tn += 1\r\nprint(n+1)", "from math import ceil as u\r\ns=input();c=s.split('P');p=s.split('C');k=0\r\nfor i in c:\r\n\tif i!='':k+=u(len(i)/5) \r\nfor i in p:\r\n\tif i!='':k+=u(len(i)/5)\t\r\nprint(k)", "st = input()\ntrips = 0\nindex = 0\nwhile index < len(st):\n if index == (len(st) - 1):\n trips += 1\n index += 1\n else:\n index2 = index\n while index2 < len(st) and (index2 - index) < 5 and st[index2] == st[index]:\n index2 += 1\n trips += 1\n index += (index2 - index)\nprint(trips)\n \t \t \t \t \t \t \t\t\t\t \t\t\t", "s=input()\r\nprint(sum([(len(x)+4)//5 for x in s.split('P')+s.split('C')]))\r\n", "s = input()\r\nans=0\r\ncnt=1\r\n\r\nfor i in range(1, len(s)):\r\n if s[i]==s[i-1]:\r\n cnt+=1\r\n \r\n else:\r\n ans += (cnt+4)//5\r\n cnt=1\r\n \r\nans += (cnt+4)//5\r\nprint(ans)", "s=input()\r\nk=0\r\nans=0\r\nfor i in range(len(s)-1):\r\n if s[i]==s[i+1]:\r\n k+=1\r\n if k==5:\r\n k=0\r\n ans+=1\r\n else:\r\n ans+=1\r\n k=0\r\nprint(ans+1)\r\n\r\n", "# https://codeforces.com/problemset/problem/137/A\n# 900\nimport math\n\ncc = None\nn = 0\no = 0\nfor c in input()+\".\":\n if cc is None:\n cc = c\n\n if cc != c:\n cc = c\n o += math.ceil(n / 5)\n n = 1\n continue\n \n n += 1\n\n\nprint(o)", "list_str = input()\r\nc = list_str[0]\r\ncnt=0\r\nlist_res=[]\r\nfor i in list_str:\r\n if i==c and cnt<5:\r\n cnt+=1\r\n else:\r\n c = i\r\n cnt = 1\r\n list_res.append(cnt)\r\nif cnt>0:\r\n list_res.append(cnt)\r\nprint(len(list_res))", "s = list(input())\r\ntarg = s[0]\r\nans=0\r\nwhile s:\r\n #print(s)\r\n #print(targ)\r\n i=1\r\n while len(s) and s[0]==targ and i<=5:\r\n s.remove(targ)\r\n i+=1\r\n \r\n ans+=1\r\n if len(s):targ=s[0]\r\nprint(ans)", "from itertools import groupby\nv = input()\ng = groupby(v)\nc = 0\nfor i in g:\n c += 0 - (- len(list(i[1])) // 5)\nprint(c)\n", "s = input()\r\nnew = s[0]\r\nlis = []\r\ni = 1\r\nwhile i<len(s):\r\n if s[i] == new[-1]:\r\n new+= s[i]\r\n i+=1\r\n else:\r\n lis.append(new)\r\n new = s[i]\r\n i+=1\r\nlis.append(new)\r\nc=0\r\nfor i in lis:\r\n if len(i)%5==0:\r\n c += len(i)//5\r\n else:\r\n c+= len(i)//5 +1\r\nprint(c)\r\n\r\n\r\n \r\n", "s=input()\r\np=0\r\nk=1\r\nfor i in range(len(s)-1):\r\n\tp+=1\r\n\tif s[i+1]!=s[i] or p==5:\r\n\t\tk+=1\r\n\t\tp=0\r\nprint(k)", "s = input()\ncnt = 1\nans = 1\nprev = s[0]\nfor j in range(1, len(s)):\n if s[j] == prev and cnt < 5:\n cnt += 1\n elif s[j] != prev or cnt == 5:\n ans += 1\n cnt = 1\n prev = s[j]\nprint(ans)\n", "s = input()\r\n\r\np = s[0]\r\nt = 0\r\nc = 0\r\nfor i in s:\r\n\tif i != p or c == 5:\r\n\t\tt += 1\r\n\t\tc = 0\r\n\tc += 1\r\n\tp = i\r\n\r\nprint(t + 1)", "from itertools import groupby\r\nfrom math import ceil\r\nprint(sum(ceil(len(tuple(i[1])) / 5)for i in groupby(input())))\r\n", "from sys import stdin, stdout\r\n\r\nans = 0\r\ns = stdin.readline().strip()\r\ncnt = 0\r\n\r\nwhile len(s):\r\n ans += 1\r\n if s[:5].count(s[0]) == len(s[:5]):\r\n s = s[5:]\r\n else:\r\n for i in range(1, len(s)):\r\n if s[i] != s[i - 1]:\r\n s = s[i:]\r\n break\r\n \r\nstdout.write(str(ans))", "import math\r\n\r\ns = input()\r\nans = 0\r\ni = 0\r\nwhile i < len(s):\r\n letter = s[i]\r\n cnt = 0\r\n while i < len(s) and s[i] == letter:\r\n i += 1\r\n cnt += 1\r\n ans += math.ceil(cnt / 5)\r\n\r\nprint(ans)", "x=input()\r\n\r\ncounter=1\r\ndlina=1\r\nfor i in range(1,len(x)):\r\n if x[i]==x[i-1]:\r\n dlina+=1\r\n if dlina==6:\r\n counter+=1\r\n dlina=1\r\n else:\r\n dlina=1\r\n counter+=1\r\nprint(counter)", "s = input()\r\nans = [1]\r\nfor i in range(1,len(s)):\r\n if s[i] != s[i-1]:\r\n ans += [1]\r\n else:\r\n ans[-1] += 1\r\nans2 = [ans[i] // 5 + int(ans[i] % 5 != 0) for i in range(len(ans))]\r\nprint(sum(ans2))\r\n", "a = input()\r\nans = 0\r\ni = 0\r\nwhile i < len(a):\r\n j = i + 1\r\n while j < len(a) and a[j] == a[i] and j - i < 5: j+=1\r\n ans+=1\r\n i = j\r\nprint(ans)", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ns = list(input().rstrip())\r\nc = 0\r\nl = s[0]\r\nans = 0\r\nfor i in s:\r\n if i ^ l:\r\n ans += c // 5 + min(c % 5, 1)\r\n l = i\r\n c = 0\r\n c += 1\r\nans += c // 5 + min(c % 5, 1)\r\nprint(ans)", "a=input()\r\n\r\n\r\nimport math\r\n\r\np=0\r\n\r\n\r\n\r\ns=''\r\nt=0\r\n\r\nfor k in range(len(a)):\r\n if k==0:\r\n if a[k]=='C':\r\n s='C'\r\n t+=1\r\n else:\r\n s='P'\r\n t+=1\r\n else:\r\n\r\n if a[k]==s:\r\n t+=1\r\n else:\r\n\r\n p+=math.ceil(t/5)\r\n t=1\r\n if s=='C':\r\n s='P'\r\n else:\r\n s='C'\r\n\r\np+=math.ceil(t/5)\r\nprint(p)\r\n \r\n", "X = input()\r\nCount, i = 0, 0\r\nwhile i < len(X):\r\n temp, S = X[i], 0\r\n while i < len(X) and X[i] == temp and S != 5:\r\n i, S = i + 1, S + 1\r\n Count += 1\r\nprint(Count)\r\n\r\n# UB_CodeForces\r\n# Advice: Never ever give up\r\n# Location: Behind my desk in the midnight\r\n# Caption: I Got a cold\r\n", "s=input()\r\nc=0\r\nans=0\r\nold=\"\"\r\nfor i in s:\r\n\tif i==old:\r\n\t\tc+=1\r\n\tif c>=5 or i!=old:\r\n\t\tans+=1\r\n\t\tc=0\r\n\told=i\r\nprint(ans)", "s=input()\r\nprint(sum([(len(l)+4)//5for l in s.split('P')+s.split('C')]))", "l = input()\r\na = l[0]\r\nans = 0\r\ncounter = 0\r\nfor i in l:\r\n if i != a or counter == 5:\r\n a = i\r\n counter = 0\r\n ans += 1\r\n counter += 1\r\nprint(ans + 1)\r\n", "L = input()\r\nh = 1\r\nn = 0\r\nfor i in range(1,len(L)):\r\n if h > 4:\r\n h = 1\r\n n = n + 1\r\n elif h!= 0 and L[i-1] == \"C\" and L[i] == \"C\":\r\n h = h + 1\r\n elif h!= 0 and L[i-1] == \"P\" and L[i] == \"P\":\r\n h = h + 1\r\n elif h!= 0 and L[i-1] == \"C\" and L[i] == \"P\":\r\n h = 1\r\n n = n + 1\r\n elif h!= 0 and L[i-1] == \"P\" and L[i] == \"C\":\r\n h = 1\r\n n = n + 1\r\n else:\r\n print(\"hi\")\r\nprint(n+1)", "a=list(input())\r\nr=a[0]\r\ncount=1\r\ni=0\r\nfor j in a:\r\n if i==5 or j!=r: \r\n count+=1; i=1; r=j\r\n else: i+=1\r\nprint(count)\r\n", "s = input()\nl = len(s)\np = s[0]\nnow = 0\ncnt = 0\nfor i in range(l):\n if now == 0:\n now = 1\n p = s[i]\n\n elif s[i] == p:\n now += 1\n if now == 5:\n now = 0\n cnt += 1\n else:\n now = 1\n p = s[i]\n cnt += 1\n\nif now > 0: cnt += 1\nprint(cnt)\n\n", "s = input()\nvisit_times = 0\n\ns += '0'\n\ni = 0\nj = 0\nwhile i < len(s) - 1:\n j += 1\n if j == 5 or s[i] != s[i + 1]:\n visit_times += 1\n j = 0\n i += 1\n\nprint(visit_times)\n", "def file():\r\n import sys\r\n sys.stdin = open('input.txt','r')\r\n sys.stdout = open('output.txt','w')\r\n\r\ndef solve():\r\n i,sub,li=0,'',[]\r\n while i<len(s)-1:\r\n if s[i]==s[i+1]:\r\n sub+=s[i]\r\n if len(sub)==4:\r\n sub+=sub[-1]\r\n li.append(sub)\r\n sub='';i+=1\r\n else:\r\n if sub:\r\n sub+=sub[-1]\r\n li.append(sub);sub=''\r\n else:li.append(s[i])\r\n i+=1\r\n print(len(li))\r\n \r\n\r\n\r\nif __name__=='__main__':\r\n\r\n # file()\r\n s=input()+'0'\r\n solve()\r\n\r\n\r\n\r\n", "str = input()\r\ncount = result = 1\r\nfor i in range(int(len(str) - 1)):\r\n if str[i] == str[i + 1] and count < 5:\r\n count += 1\r\n else:\r\n count = 1\r\n result += 1\r\nprint(result)", "from itertools import groupby\r\n\r\nprint(sum(-(-len(list(g))//5) for _, g in groupby(input())))", "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\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\n\r\nprint(sum([math.ceil(len(list(j))/5) for i,j in groupby(input())])) ", "st = input()\r\nn = len(st)\r\nc1=0\r\np1=0\r\nans=0\r\nfor i in range (n) :\r\n if (st[i] == 'C' ) :\r\n if p1!=0 :\r\n ans+=1\r\n p1=0\r\n if c1>=5 :\r\n c1=0\r\n ans+=1\r\n c1+=1\r\n else :\r\n if c1!=0 :\r\n ans+=1\r\n c1=0\r\n if p1>=5 :\r\n p1=0\r\n ans+=1\r\n p1+=1\r\nif p1!=0 or c1!=0 :\r\n ans+=1\r\nprint(ans)\r\n ", "s=input()\r\ncounter=0\r\nanswer=1\r\nfor i in range(len(s)-1):\r\n if s[i]!=s[i+1]:\r\n counter=0\r\n answer+=1\r\n else:\r\n counter+=1\r\n if counter==5:\r\n answer+=1\r\n counter=0\r\nprint(answer)", "import sys\r\nimport math\r\nimport bisect\r\n\r\ndef main():\r\n s = input()\r\n n = len(s)\r\n ans = []\r\n A = []\r\n for i in range(n):\r\n A.append(s[i])\r\n if i == n - 1 or s[i+1] != s[i] or len(A) == 5:\r\n ans.append(A.copy())\r\n A.clear()\r\n print(len(ans))\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "\"\"\"https://codeforces.com/contest/137/problem/A\"\"\"\r\nstroka = input()\r\nvisits,number = 1,0\r\nif stroka is False:\r\n print(0)\r\nfor i in range(len(stroka)-1):\r\n if stroka[i] == stroka[i+1]:\r\n number +=1\r\n if number == 5:\r\n visits +=1\r\n number = 0\r\n else:\r\n number= 0\r\n visits+=1\r\nprint(visits)\r\n", "s = input()\r\nprint(sum([(len(i)+4) // 5 for i in (s.split('C') + s.split('P'))]))\r\n", "s = input()\r\ncount = 0\r\nk = 0\r\n\r\nfor i in range(len(s) - 1):\r\n k +=1\r\n if s[i] != s[i+1]:\r\n count +=1\r\n k = 0\r\n\r\n elif k == 5 :\r\n k = 0\r\n count +=1\r\n\r\nprint(count +1)", "res, demc, demp, s, c, p = 0, 0, 0, input() + '#', [], []\r\nfor x in range(len(s) - 1):\r\n if s[x] == 'C':\r\n if s[x + 1] != s[x]: c, demc = c + [demc + 1], 0\r\n else: demc += 1\r\n else:\r\n if s[x + 1] != s[x]: p, demp = p + [demp + 1], 0\r\n else: demp += 1\r\nfor x in c:\r\n if x % 5 == 0: res += x // 5\r\n else: res += x // 5 + 1\r\nfor x in p:\r\n if x % 5 == 0: res += x // 5\r\n else: res += x // 5 + 1\r\nprint(res)", "n = input()\r\ny = len(n)\r\nrook = 0\r\ncount = 0\r\nu = 'K'\r\nfor i in range(y):\r\n if rook > 5:\r\n rook = 1\r\n count +=1\r\n elif u != n[i]:\r\n count+=1\r\n rook = 1\r\n rook+=1\r\n u = n[i]\r\nprint(count)", "def main():\r\n s = list(input())\r\n\r\n sol = 0\r\n i = 0\r\n while True:\r\n j = i + 1\r\n while (j < len(s) and j < i + 5) and (s[i] == s[j]):\r\n j += 1\r\n sol += 1\r\n i = j\r\n\r\n if i == len(s):\r\n break\r\n\r\n print(sol)\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n\r\n\r\n\r\n\r\n", "c = 1\r\ncarry = ''\r\n\r\nfor e in input():\r\n if carry=='CCCCC' or carry=='PPPPP':\r\n carry = ''\r\n c = c+1\r\n\r\n if carry=='' or carry[0]==e:\r\n carry = carry+e\r\n else:\r\n carry = e\r\n c = c+1\r\n\r\nprint(c)", "s=list(input())\r\nc=0\r\nc1=0\r\nc2=\"\"\r\n\r\nfor i in s:\r\n\tif i==c2:\r\n\t\tc1+=1\r\n\tif c1>=5 or i!=c2:\r\n\t\tc+=1\r\n\t\tc1=0\r\n\tc2=i\r\n\t# else:\r\n\t\t# c1+=\"D\"\r\n\t# if i==\"P\":\r\n\t\t# c2+=\"P\"\r\nprint(c)", "s=input()\r\np=\"w\"\r\nk=0\r\nk1=1\r\nfor x in s :\r\n if x!=p :\r\n k+=1\r\n k1=1\r\n p=x\r\n else :\r\n k1+=1\r\n if k1==6 :\r\n k+=1\r\n k1=1\r\n p=x\r\nprint(k)", "letters = input()\r\n\r\nnum, res = 1, 0\r\nfor i in range(0, len(letters) - 1):\r\n if letters[i] == letters[i + 1] and num < 5:\r\n num += 1\r\n else:\r\n res += 1\r\n num = 1\r\n\r\n\r\nprint(res + 1)\r\n", "def solve(s):\n tot = 1\n count = 1\n i = 1\n while i < len(s):\n if s[i] == s[i-1]:\n if count == 5:\n count = 1\n tot += 1\n else:\n count += 1\n else:\n count = 1\n tot+=1\n i+=1\n return tot\n \n\n \n\n\ndef main() :\n s = input()\n # n = int(input())\n # arr = list(map(int, input().split(' ')))\n # s = input()\n # res=''\n # arr = []\n # for _ in range(n):\n # i = input().split(' ')\n # arr.append(i)\n print(solve(s))\nmain()\n", "u = input()\r\nlst = []\r\nchr = u[0]\r\ns = \"\"\r\ni=0\r\ntrips = 0\r\nwhile i < len(u):\r\n if u[i]!=chr:\r\n lst.append(s)\r\n chr = u[i]\r\n i-=1\r\n s = \"\" \r\n else:\r\n s += u[i]\r\n i+=1\r\nlst.append(s)\r\nfor j in lst:\r\n if len(j)%5 == 0:\r\n trips += len(j)//5\r\n else:\r\n trips += len(j)//5+1\r\nprint(trips)\r\n", "# m, n = map(lambda v: int(v), input().split())\r\n# n = int(input())\r\n\r\na = list(input())\r\n\r\nc,s = 0,a[0]\r\nfor i in a[1:]:\r\n if len(s)>0 and i!=s[-1]:\r\n c+=1\r\n s=i\r\n elif len(s)==4:\r\n c+=1\r\n s=\"\"\r\n else: s+=i\r\n\r\nif len(s)>0: c+=1\r\n\r\nprint(c)", "import math\r\nn = input()\r\ndef length(s):\r\n res = []\r\n counter = 1\r\n for i in range(1, len(s)):\r\n if s[i - 1] == s[i]:\r\n counter += 1\r\n else:\r\n res.append(counter)\r\n counter = 1\r\n res.append(counter)\r\n return res\r\nsol = length(n)\r\nfor i in range(len(sol)):\r\n sol[i] = math.ceil(sol[i] / 5)\r\nprint(sum(sol))\r\n\r\n", "from itertools import groupby\r\ndef splitter(text):\r\n return (', '.join(''.join(group) for key, group in groupby(text))).split(', ')\r\n\r\n# def splitter(text):\r\n# group = text[0]\r\n# prevletter = text[0]\r\n# finalist = []\r\n# text = [char for char in text]\r\n# for i in range(1, len(text) - 1):\r\n# print(prevletter)\r\n# print(group)\r\n# print(prevletter)\r\n# if text[i] == prevletter:\r\n# group = group.join(text[i])\r\n# prevletter = text[i]\r\n# if text[i] != prevletter:\r\n# finalist.append(group)\r\n# prevletter = text[i]\r\n# group = \"\"\r\n\r\n print(finalist)\r\n return finalist\r\n\r\n\r\ndef roundto1(num):\r\n if num.is_integer() == True:\r\n return int(num)\r\n else:\r\n return int(num) + 1\r\n\r\nstring = input()\r\nsplitstring = splitter(string)\r\nvalue = 0\r\ntempval = 0\r\n\r\nfor i in range(len(splitstring)):\r\n tempval = len(splitstring[i]) / 5\r\n value += roundto1(tempval)\r\n\r\nprint(value)\r\n", "wall = input()\nn = len(wall)\navailable = 4\nkind = wall[0]\ntimes = 1\nfor i in range(1, n):\n if available == 0 or wall[i] != kind:\n available = 4\n times += 1\n kind = wall[i]\n else:\n available -= 1\nprint(times)\n", "s = input()\r\nans = 1\r\nf = 1\r\nfor i in range(1, len(s)):\r\n if s[i] != s[i - 1]:\r\n f = 1\r\n ans += 1\r\n else:\r\n f += 1\r\n if f == 6:\r\n f = 1\r\n ans += 1\r\nprint(ans)\r\n", "str = input()\r\ncnt = 0\r\nwhile len(str)!=0:\r\n x = str.find('P' if str[0]=='C' else 'C')\r\n str = str[min(x if x!=-1 else 6, 5, len(str)):]\r\n cnt+=1\r\nprint(cnt)", "s=input()\r\nc=0\r\nt=0\r\nold=\"\"\r\nfor i in s:\r\n\tif i==old:\r\n\t\tc+=1\r\n\tif c>=5 or i!=old:\r\n\t\tt+=1\r\n\t\tc=0\r\n\told=i\r\nprint(t)", "s = input()\r\nlast = s[0]\r\nres = 0\r\ncount = 0\r\nfor c in s:\r\n if c!=last or count==5:\r\n res+=1\r\n count=1\r\n else:\r\n count+=1\r\n last=c\r\nif count>0:\r\n res+=1\r\nprint(res)", "read=input()\r\n\r\ncounter=0\r\nmaxI=0\r\n#print( read[i],read[i-1],maxI,i)\r\nfor i in range(len(read)-1):\r\n if maxI==0:\r\n counter+=1 \r\n if maxI==4 or read[i]!=read[i+1]:\r\n maxI=0\r\n else:\r\n maxI+=1\r\n \r\ni=len(read)-1\r\n\r\nif read[i]!=read[i-1]:\r\n counter+=1\r\nelif maxI==0:\r\n counter+=1\r\n \r\nprint(counter)\r\n \r\n", "__author__ = 'Esfandiar'\ns = input()\nt = 0\nres = 1\nb = s[0]\nfor i in s:\n if i == 'C':\n if t < 5 and i == b:\n t+=1\n else:\n res+=1\n t = 1\n b = 'C'\n else:\n if t < 5 and i == b:\n t+=1\n else:\n res+=1\n t = 1\n b = 'P'\nprint(res)", "s = str(input())\r\ni=0\r\ncount = 0\r\nwhile len(s)>0:\r\n if s[0]=='C':\r\n temp = s.lstrip('C')\r\n if len(s)-len(temp)>5:\r\n s = s[5:]\r\n else:\r\n s = temp\r\n count = count+1\r\n else:\r\n temp = s.lstrip('P')\r\n if len(s)-len(temp)>5:\r\n s = s[5:]\r\n else:\r\n s = temp\r\n count = count+1\r\nprint(count)", "import math\r\nl = list(map(str, input()))\r\nt = 0\r\nwhile len(l) != 0:\r\n c = 0\r\n b = l[0]\r\n x = 1\r\n while True:\r\n if x == len(l):\r\n t += math.ceil(x / 5)\r\n l = []\r\n break\r\n elif b == l[x]:\r\n x += 1\r\n else:\r\n t += math.ceil(x/5)\r\n l = l[x:]\r\n break\r\nprint(t)", "data = list(input())\r\ndata.append('X')\r\nresult = 0\r\n\r\ncnt = 1\r\nfor i in range(1,len(data)):\r\n if data[i]==data[i-1]:\r\n cnt += 1\r\n else:\r\n result += (cnt-1)//5 + 1\r\n cnt = 1\r\n\r\nprint(result)", "s=input()\r\nc=[]\r\nans=0\r\nfor i in s:\r\n if len(c)==0:\r\n c.append(i)\r\n elif len(c)!=0 and i==\"C\" and c[-1]==\"P\":\r\n ans=ans+1\r\n c=[]\r\n c.append(i)\r\n elif len(c)!=0 and i==\"P\" and c[-1]==\"C\":\r\n ans=ans+1\r\n c=[]\r\n c.append(i)\r\n else:\r\n if len(c)==5:\r\n c=[]\r\n c.append(i)\r\n ans=ans+1\r\n else:\r\n c.append(i)\r\nprint(ans+1)\r\n \r\n \r\n\r\n ", "s = input()\nres, cur = 0, 1\nfor i in range(1, len(s)):\n if s[i] != s[i - 1] or cur == 5:\n res += 1\n cur = 0\n cur += 1\nres += cur > 0\nprint(res)\n", "t = input()\r\n# print(len(t))\r\ncount = 1\r\nr = 1\r\nflag = 0\r\nfor i in range(1,len(t)):\r\n\r\n\tif t[i] == t[i-1]:\r\n\t\tr = r + 1\r\n\tif r > 5 or t[i] != t[i-1]:\r\n\t\tr = 1\r\n\t\tcount = count + 1\r\n\t\tcontinue\r\n\r\nprint(count)", "def f():\r\n s=input()\r\n count=1\r\n temp=1\r\n for i in range(1,len(s)):\r\n if(s[i]==s[i-1] and temp<5):\r\n temp+=1\r\n continue\r\n else:\r\n count+=1\r\n temp=1\r\n print(count)\r\nf()", "string = input()\nnum_times = 0\ncounter = 0\nprev = string[0]\nfor char in string:\n\tif(char == prev and counter < 5):\n\t\tcounter += 1\n\telif(char == prev and counter >= 5):\n\t\tcounter = 1\n\t\tnum_times += 1\n\telif(char != prev):\n\t\tcounter = 1\n\t\tnum_times += 1\n\t\tprev = char\nnum_times += 1\nprint(num_times)", "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\ns = get_string()\r\nprev = s[0]\r\ncapacity = 0\r\nvisit = 0\r\nfor i in range(len(s)):\r\n if s[i] == prev:\r\n capacity += 1\r\n if capacity == 5:\r\n #print('capacity: ',capacity)\r\n visit += 1\r\n capacity = 0\r\n if i+1 < len(s): \r\n prev = s[i+1]\r\n else:\r\n break\r\n else:\r\n prev = s[i]\r\n visit += 1\r\n #print('capacity: ',capacity)\r\n capacity = 1\r\nif capacity > 0:\r\n #print('capacity: ',capacity)\r\n print(visit+1)\r\nelse:\r\n print(visit)", "str_in = input()\nmax_to_carry = 5\nres = 0\nn_carry = 1\ni = 1\nwhile i < len(str_in):\n if n_carry < max_to_carry:\n if str_in[i] == str_in[i-1]:\n n_carry = n_carry + 1\n i = i + 1\n continue\n \n res = res + 1\n n_carry = 1\n i = i + 1\n \nif n_carry > 0:\n res = res + 1\n\nprint(res)\n \t\t\t \t \t\t\t \t\t \t \t\t \t \t\t", "def next_pos(wall, start):\r\n distance = 0\r\n end = len(wall) - 1\r\n for i in range(start, end):\r\n if distance == 5:\r\n return i\r\n\r\n if wall[i] != wall[i + 1]:\r\n return i + 1\r\n\r\n distance += 1\r\n\r\n if distance == 5:\r\n return i\r\n\r\n return len(wall)\r\n\r\n\r\ndef main():\r\n wall = input()\r\n trips = 0\r\n\r\n current = 0\r\n while True:\r\n if current == len(wall):\r\n break\r\n\r\n current = next_pos(wall, current)\r\n trips += 1\r\n\r\n print(trips)\r\n\r\nmain()\r\n", "x=input()\r\nz=[]\r\np,c=0,0\r\nfor i in x:\r\n if i==\"P\":\r\n if c!=0:\r\n z.append([\"C\",c])\r\n c=0\r\n p+=1\r\n else:\r\n if p!=0:\r\n z.append([\"P\",p])\r\n p=0\r\n c+=1\r\nif p!=0:\r\n z.append([\"P\",p])\r\nelif c!=0:\r\n z.append([\"C\",c])\r\nk=0\r\nfor i in z:\r\n if i[1]%5==0:\r\n k+=i[1]//5\r\n else:\r\n k+=i[1]//5+1\r\nprint(k)", "s=input()\r\nn=len(s)\r\nv=0\r\nhand=1\r\na_type=(s[0]=='C')\r\nfor i in range(1,n):\r\n if(s[i]=='C'):\r\n c_type=1\r\n else:\r\n c_type=0\r\n if(c_type==a_type):\r\n if(hand<5):\r\n hand+=1\r\n else:\r\n v+=1\r\n hand=1\r\n else:\r\n a_type=c_type\r\n v+=1\r\n hand=1\r\nprint(v+1)\r\n", "n = input()\r\nif n[-1] ==\"P\":\r\n n = n+'C'\r\nelse: \r\n n = n +\"P\"\r\ncount = 0 \r\ncounter_c , counter_b = 0 , 0\r\nfor idx , value in enumerate(n[:-1]) : \r\n if value == \"C\":\r\n counter_c += 1 \r\n if counter_c == 5 : \r\n count +=1 \r\n counter_c = 0\r\n elif n[idx+1] ==\"P\" :\r\n count += 1\r\n counter_c = 0\r\n else :\r\n if value == \"P\":\r\n counter_b += 1 \r\n if counter_b == 5 : \r\n count +=1 \r\n counter_b = 0\r\n elif n[idx+1] ==\"C\":\r\n count += 1\r\n counter_b = 0\r\n \r\nprint(count) \r\n" ]
{"inputs": ["CPCPCPC", "CCCCCCPPPPPP", "CCCCCCPPCPPPPPPPPPP", "CCCCCCCCCC", "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC", "CPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCPCP", "CCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPPCCCCCCPPPPPP", "P", "C", "PC", "PPPPP", "PPPP", "CCCCCCCCCC", "CP", "CPCCPCPPPC", "PPCPCCPCPPCCPPPPPPCP", "PCPCCPCPPCCPCPCCPPPPPCPCPCPCCC", "CCPPPPPCPCCPPPCCPPCPCCPCPPCPPCCCPPCPPPCC", "CPPCCCCCCPCCCCPCCPCPPPCPCCCCCCCPCCPPCCCPCCCCCPPCCC", "PPCCCCPPCCPPPCCCCPPPPPCPPPCPPPCCCPCCCPCPPPCPCCCPCCPPCCPPPPPC", "PPCPPCCCCCPCCCPCCPCCCCPPPCCCCPCPCCPCPCPCPPPPCCPPPPPPPCPCPPPCPCPCPCPPPC", "CCPCPPPPCPPPPCCCCPCCPCPCCPPCPCCCPPCCCCPCCCPCPCCPPPCPPPCPCPPPPPCPCCPCCPPCCCPCPPPC", "CCPPCPCPCPPCCCPCPPPCCCCCPCPPCCCPPCPCPPPPCPPCPPPPCCCPCCPCPPPCPCPPCCCPCCCCCCPCCCCPCCPPPPCCPP", "PPCPPPPCCCCPPPPCPPPPPPPPCPCPPCCPPPPPPPPCPPPPCCCCPPPPCPPCPCPPPCCPPCPPCCCPCPPCCCCCCPCPCPCPPCPCPCPPPCCC", "CCPCCCPPCPPCPCCCPCPPCPPCPPCCCCCCCPCPPCPCCPCCPCPCPCCCPCCCPPPCCPCCPPCCCCCPPPPCPCPPCPCPCCPCPPP", "PCPCPPPPCPCPPPCPPCCCPCPCPCPPCPPPPCCPPPCPPPCPPPPCCPPCCCPCCPCCCCPCCPCPPCPCCCPCPPCP", "PCCPPCCCPPCPPCC", "CCCPPPPPPCCCCPCCPCCCCCCPCCCPPPCPC", "CPPCCPPCCPPPCCCPPPPCPPPPPPPCCPCPCCPPPPCCCPPCCPCCPPCCCPCCPCPPPPCCPP", "CCCCCPPPCCPCPCCPPPPCPCCCPCPPCPCPPPPPCCPCPCPC", "PPPPPPPPPCPCP", "PPPCPCPCCCPPCPCCPPPPCCCPCCP", "PCPCCPCPPPPPPCPCCPCPCPCCPPPCPCPCPPCPPCCPCPCCCPCCCPPCPCPCCPCPPPPCCCCCCPPCCPCCCCCPCCCCPPPCPCCCCCPCPCP", "PCCPCPPCCCCCPCCCPCCCPPCCCCCPPPCCPPPPPPPPCPPPCCPPCPPCPCP", "CPCPCCPPPPCCPPCPPCPPCCCCCCPCCPPPCPPCPCCCCCCPCPCCCCCPCCCCCCPCCPPCCP", "PPCCCCCCPP", "CCCCCCCCCCCCPPCCCCPP", "PPPPPPPPPPPCCCCCCCCCCCCCCCCCCP", "PPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCPPPPCCCC", "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCPPPC", "CCCCCCCCCPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCCCCCCCCCCCCPPPPPCC", "CCCCCCCCCCCCCCCCCCCCCCCCCPPPCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC", "CCCCCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCPPPPPPPCCPPP", "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCCCCCCCCCCCCCCCPPPPPPPPPPPPPPPPPPP", "PPPPPPPPPPPPPPPPPPPPPPPCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCPPPPPCCCPPPPCCCCCPCC"], "outputs": ["7", "4", "6", "2", "20", "100", "28", "1", "1", "2", "1", "1", "2", "2", "7", "12", "20", "21", "23", "26", "39", "43", "47", "49", "53", "47", "8", "15", "31", "25", "6", "15", "59", "26", "35", "4", "6", "8", "10", "12", "13", "15", "18", "19", "23"]}
UNKNOWN
PYTHON3
CODEFORCES
133
13056962b3f1cb803ad09d79e4bde485
Primes on Interval
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors. Consider positive integers *a*, *a*<=+<=1, ..., *b* (*a*<=≤<=*b*). You want to find the minimum integer *l* (1<=≤<=*l*<=≤<=*b*<=-<=*a*<=+<=1) such that for any integer *x* (*a*<=≤<=*x*<=≤<=*b*<=-<=*l*<=+<=1) among *l* integers *x*, *x*<=+<=1, ..., *x*<=+<=*l*<=-<=1 there are at least *k* prime numbers. Find and print the required minimum *l*. If no value *l* meets the described limitations, print -1. A single line contains three space-separated integers *a*,<=*b*,<=*k* (1<=≤<=*a*,<=*b*,<=*k*<=≤<=106; *a*<=≤<=*b*). In a single line print a single integer — the required minimum *l*. If there's no solution, print -1. Sample Input 2 4 2 6 13 1 1 4 3 Sample Output 3 4 -1
[ "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\na,b,k = map(int, input().split())\r\nps = [1]*(b+1)\r\nps[0]=ps[1]=0\r\nfor i in range(2,b+1):\r\n if ps[i]==0:continue\r\n for j in range(i+i,b+1,i):\r\n ps[j] = 0\r\n\r\nA = []\r\nfor i in range(a,b+1):\r\n if ps[i]:\r\n A.append(1)\r\n else:\r\n A.append(0)\r\nif sum(A)<k:\r\n exit(print(-1))\r\n \r\ndef check(m):\r\n t = sum(A[:m])\r\n if t<k:return False\r\n \r\n for i in range(m,len(A)):\r\n t-=A[i-m]\r\n t+=A[i]\r\n if t<k:return False\r\n return True\r\n\r\nl,r=k-1,len(A)+1\r\nwhile l+1<r:\r\n m = (l+r)//2\r\n if check(m):\r\n r = m\r\n else:\r\n l = m\r\nprint(r)\r\n\r\n", "\r\nif __name__ == \"__main__\":\r\n a, b, k = map(int, input().split())\r\n primes = [a-1]\r\n vis = [False] * (b+1)\r\n\r\n for i in range(2, b+1):\r\n if not vis[i]:\r\n if i >= a: primes.append(i)\r\n for j in range(i*i, b+1, i):\r\n vis[j] = True\r\n primes.append(b+1)\r\n # print(primes)\r\n m = len(primes)\r\n if m - 2 < k:\r\n print(-1)\r\n else:\r\n ans = 0\r\n for i in range(k, m):\r\n ans = max(ans, primes[i] - primes[i-k])\r\n print(ans)", "# Function to check if a number is prime\ndef is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n return False\n i = 5\n while i * i <= num:\n if num % i == 0 or num % (i + 2) == 0:\n return False\n i += 6\n return True\n\n# Function to find all prime numbers in a range\ndef find_primes_in_range(a, b):\n primes = []\n for num in range(max(2, a), b + 1):\n if is_prime(num):\n primes.append(num)\n return primes\n\n# Function to calculate the minimum 'l'\ndef calculate_minimum_l(a, b, k):\n primes_in_range = find_primes_in_range(a, b)\n \n if len(primes_in_range) >= k:\n l = primes_in_range[k - 1] - a + 1\n for i in range(len(primes_in_range) - k):\n l = max(l, primes_in_range[i + k] - (primes_in_range[i] + 1) + 1)\n l = max(l, b + 1 - primes_in_range[len(primes_in_range) - k])\n return l\n else:\n return -1\n\n# Input\na, b, k = map(int, input().split())\n\n# Calculate and print the minimum 'l'\nresult = calculate_minimum_l(a, b, k)\nprint(result)\n\t\t\t\t\t\t \t \t\t \t \t \t \t \t \t", "a, b, k = [int(i) for i in input().split(\" \")]\nprimes = [True] * (b + 1)\nprimes[0] = False\nprimes[1] = False\n\nfor i in range(2, len(primes)):\n if primes[i]:\n for j in range(i * 2, len(primes), i):\n primes[j] = False\n\ndef accept(l):\n count = 0\n for x in range(a, a + l): # [a, a+l)\n if primes[x]:\n count += 1\n # first l\n if count < k:\n return False\n for x in range(a + l, b + 1): # [a+l, b]\n if primes[x - l]:\n count -= 1\n if primes[x]:\n count += 1\n if count < k:\n return False\n return True\n\nanswer = False\nlow = 1\nhigh = b - a + 1\nif not accept(high):\n print(-1)\nelse:\n while low < high:\n mid = low + (high - low) // 2\n if accept(mid):\n high = mid\n else:\n low = mid + 1\n print(low)\n\n", "R = lambda: map(int, input().split())\r\na, b, k = R()\r\npms = [0, 0] + [1] * b\r\nfor i in range(2, b + 1):\r\n if pms[i]:\r\n for j in range(i * 2, b + 1, i):\r\n pms[j] = 0\r\nfor i in range(1, b + 1):\r\n pms[i] += pms[i - 1]\r\nj = a\r\ncnts = [-1] * (b + 1)\r\nfor i in range(a, b + 1):\r\n while j < b + 1 and pms[j] - pms[i - 1] < k:\r\n j += 1\r\n if j < b + 1:\r\n cnts[i] = j - i + 1\r\nif cnts[a] == -1:\r\n print(-1)\r\nelse:\r\n res = cnts[a]\r\n for i in range(a, b + 1):\r\n res = max(res, cnts[i])\r\n if cnts[i] == -1:\r\n res = max(res, b - i + 2)\r\n print(res)", "# Problem: C. Primes on Interval\r\n# Contest: Codeforces - Codeforces Round 147 (Div. 2)\r\n# URL: https://codeforces.com/contest/237/problem/C\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\nPROBLEM = \"\"\"https://codeforces.com/contest/237/problem/C\r\n\r\n输入 a b k,范围 [1,1e6],a≤b。\r\n请找到最短的 L,使得对于任意 a≤x≤b-L+1 都满足:在 x,x+1,...,x+L-1 中至少有 k 个质数。\r\n输出 L。如果 L 不存在,输出 -1。\r\n输入 2 4 2\r\n输出 3\r\n\r\n输入 6 13 1\r\n输出 4\r\n\r\n输入 1 4 3\r\n输出 -1\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\nclass PrimeTable:\r\n def __init__(self, n: int) -> None:\r\n self.n = n\r\n self.primes = primes = [] # 所有n以内的质数\r\n self.min_div = min_div = [0] * (n + 1) # md[i]代表i的最小(质)因子\r\n min_div[1] = 1\r\n\r\n # 欧拉筛O(n),顺便求出min_div\r\n for i in range(2, n + 1):\r\n if not min_div[i]:\r\n primes.append(i)\r\n min_div[i] = i\r\n for p in primes:\r\n if i * p > n: break\r\n min_div[i * p] = p\r\n if i % p == 0:\r\n break\r\n\r\n # # 埃氏筛O(nlgn),由于切片的原因,仅标记质数的场景下比线性筛表现更好。\r\n # is_primes = [1] * (n + 1)\r\n # is_primes[0] = is_primes[1] = 0 # 0和1不是质数\r\n # for i in range(2, int((n + 1) ** 0.5) + 1):\r\n # if is_primes[i]:\r\n # is_primes[i * i::i] = [0] * ((n - 1 - i * i) // i + 1)\r\n # self.primes = [i for i, v in enumerate(is_primes)]\r\n\r\n def is_prime(self, x: int):\r\n \"\"\"检测是否是质数,最坏是O(sqrt(x)\"\"\"\r\n if x < 3: return x == 2\r\n if x <= self.n: return self.min_div[x] == x\r\n for i in range(2, int(x ** 0.5) + 1):\r\n if x % i == 0: return False\r\n return True\r\n\r\n def prime_factorization(self, x: int):\r\n \"\"\"分解质因数,复杂度\r\n 1. 若x>n则需要从2模拟到sqrt(x),如果中间x降到n以下则走2;最坏情况,不含低于n的因数,则需要开方复杂度\r\n 2. 否则x质因数的个数,那么最多就是O(lgx)\"\"\"\r\n n, min_div = self.n, self.min_div\r\n for p in range(2, int(x ** 0.5) + 1):\r\n if x <= n: break\r\n if x % p == 0:\r\n cnt = 0\r\n while x % p == 0: cnt += 1; x //= p\r\n yield p, cnt\r\n while 1 < x <= n:\r\n p, cnt = min_div[x], 0\r\n while x % p == 0: cnt += 1; x //= p\r\n yield p, cnt\r\n if x >= n and x > 1:\r\n yield x, 1\r\n\r\n def get_factors(self, x: int):\r\n \"\"\"求x的所有因数,包括1和x\"\"\"\r\n factors = [1]\r\n for p, b in self.prime_factorization(x):\r\n n = len(factors)\r\n for j in range(1, b + 1):\r\n for d in factors[:n]:\r\n factors.append(d * (p ** j))\r\n return factors\r\n\r\n def mr_is_prime(self, x):\r\n \"\"\"\r\n Miller-Rabin 检测. 检测x是否是质数,置信度: 1 - (1/4)^k. 复杂度k*log^3\r\n 但是longlong以内可以用k==3或7的代价,换取100%置信度\r\n https://zhuanlan.zhihu.com/p/349360074\r\n \"\"\"\r\n if x < 3 or x % 2 == 0:\r\n return x == 2\r\n if x % 3 == 0:\r\n return x == 3\r\n\r\n u, t = x - 1, 0\r\n while not u & 1:\r\n u >>= 1\r\n t += 1\r\n ud = (2, 325, 9375, 28178, 450775, 9780504, 1795265022) # long long 返回用这个7个数检测100%正确\r\n # ud = (2, 7, 61) # int 返回用这3个数检测100%正确\r\n # for _ in range(k):\r\n # a = random.randint(2, x - 2)\r\n for a in ud:\r\n v = pow(a, u, x)\r\n if v == 1 or v == x - 1 or v == 0:\r\n continue\r\n for j in range(1, t + 1):\r\n v = v * v % x\r\n if v == x - 1 and j != t:\r\n v = 1\r\n break\r\n if v == 1:\r\n return False\r\n if v != 1:\r\n return False\r\n return True\r\n\r\n\r\nprimes = PrimeTable(10 ** 6).primes\r\nn = len(primes)\r\n\"\"\"\r\n2 4 2 \r\n2 3 4\r\n\r\n\"\"\"\r\n\r\n\r\n# ms\r\ndef solve():\r\n a, b, k = RI()\r\n s = bisect_left(primes, a)\r\n e = bisect_right(primes, b)\r\n ans = -1\r\n p = e - k\r\n if p >= 0 and primes[p] >= a:\r\n ans = b - primes[p]+1\r\n j = s\r\n for i in range(s, e):\r\n if i - j + 1 > k:\r\n a = primes[j] + 1\r\n j += 1\r\n if i - j + 1 == k:\r\n ans = max(ans, primes[i] - a + 1)\r\n\r\n print(ans)\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=1000010\r\nbs=[1]*(n+100)\r\nprimes=list()\r\nis_prime=[0]*n\r\n\r\ndef sieve(upper_bound):\r\n bs[0],bs[1]=0,0\r\n for i in range(2,upper_bound+1):\r\n if bs[i]:\r\n for j in range(i*i,upper_bound+1,i):\r\n bs[j]=0\r\n primes.append(i)\r\n is_prime[i]=1\r\n\r\na,b,k=[int(x) for x in input().split()]\r\nsieve(n)\r\nfor i in range(1,n):is_prime[i]+=is_prime[i-1]\r\nl,r=1,b-a+1\r\nans=-1\r\nwhile(l<=r):\r\n mid=(l+r)//2\r\n flag=0\r\n for i in range(a,b-mid+2):\r\n if is_prime[i+mid-1]-is_prime[i-1]<k:flag=1; break\r\n if flag:l=mid+1\r\n else:r=mid-1; ans=mid\r\nprint(ans)", "a, b, k = map(int, input().split())\r\nisprime = [True] * (1000001)\r\nisprime[0] = isprime[1] = False\r\nprimes = []\r\nfor i in range(2,1000001):\r\n if isprime[i]:\r\n primes.append(i)\r\n for p in primes:\r\n if p * i > 1000000:break \r\n isprime[p * i] = False \r\n if i % p == 0:break \r\ndef check(length):\r\n l = r = a\r\n cnt = 0\r\n while r <= b:\r\n if isprime[r]:\r\n cnt += 1\r\n if r - l + 1 == length:\r\n if cnt < k:\r\n return False \r\n if isprime[l]:\r\n cnt -= 1\r\n l += 1\r\n r += 1\r\n return True \r\nl = 1\r\nr = b - a + 1\r\nwhile l <= r:\r\n mid = (l + r) // 2\r\n if check(mid):\r\n r = mid - 1\r\n else:\r\n l = mid + 1\r\nif l == b - a + 2:\r\n print(-1)\r\nelse:\r\n print(l)", "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nimport decimal\r\ninput=sys.stdin.readline\r\na,b,k=(int(i) for i in input().split())\r\nl=[1 for i in range(b+1)]\r\ni=2\r\nl[0],l[1]=0,0\r\nwhile(i*i<=b):\r\n if(l[i]==1):\r\n for j in range(i*i,b+1,i):\r\n l[j]=0\r\n i+=1\r\npref=[l[0]]\r\nfor i in range(1,b+1):\r\n pref.append(pref[i-1]+l[i])\r\nlo=1\r\nhi=b-a+2\r\nwhile(lo<hi):\r\n mid=(lo+hi)//2\r\n c=1\r\n for i in range(a,b-mid+2):\r\n if(pref[i+mid-1]-pref[i-1]<k):\r\n c=0\r\n break\r\n if(c==1):\r\n hi=mid\r\n else:\r\n lo=mid+1\r\nif(lo==b-a+2):\r\n print(-1)\r\nelse:\r\n print(lo)", "# https://www.acwing.com/blog/content/34755/\r\n\r\nst = [0] * (1000011)\r\nprimes = [0] * (1000011)\r\n\r\ndef init(n:int):\r\n st[1] = True\r\n cnt = 0\r\n for i in range(2, n + 1):\r\n if st[i] == False:\r\n primes[cnt] = i\r\n cnt += 1\r\n j = 0\r\n while i <= n / primes[j]:\r\n st[i * primes[j]] = True\r\n if i % primes[j] == 0:\r\n break\r\n j += 1\r\n\r\ndef solve():\r\n n, m, k = map(int, input().split())\r\n \r\n init(m + 10)\r\n \r\n tmp = 0;\r\n for i in range(n, m + 1):\r\n if st[i] == False: tmp += 1\r\n \r\n if tmp < k: print(-1)\r\n else:\r\n res, tmp = 0, st[n] == False\r\n j = n + 1\r\n for i in range(n, m + 1):\r\n while tmp<k and j<=m:\r\n if st[j] == False: tmp += 1\r\n j += 1\r\n \r\n if tmp < k:\r\n res = max(res, j - i + 1)\r\n break\r\n \r\n res = max(res, j - i)\r\n if st[i] == False: tmp -= 1\r\n if j > m: break\r\n \r\n print(res)\r\n \r\n\r\ndef main():\r\n solve()\r\n\r\nif __name__ == '__main__':\r\n main()", "import math\r\nimport sys\r\nimport time\r\nfrom bisect import bisect_left, bisect_right\r\nfrom collections import Counter, deque, defaultdict\r\nfrom itertools import permutations\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\n\r\nn = int(1e6)\r\nisnp = [1] * (n + 1)\r\nisnp[0] = 0\r\nisnp[1] = 0\r\nfor i in range(2, n + 1):\r\n if isnp[i]:\r\n j = i * i\r\n while j <= n:\r\n isnp[j] = 0\r\n j += i\r\nfor i in range(1,n + 1):\r\n isnp[i] += isnp[i - 1]\r\na,b,k = mi()\r\nl,r = 1,b - a + 2\r\nwhile l < r:\r\n mid = (l + r) // 2\r\n for i in range(a,b - mid + 2):\r\n if isnp[i + mid - 1] - isnp[i - 1] < k:\r\n break\r\n else:\r\n r = mid\r\n continue\r\n l = mid + 1\r\nprint(-1 if l > b - a + 1 else l)\r\n", "import collections\r\nimport queue\r\nfrom sys import stdin, stdout\r\n\r\ninput_int = lambda: int(stdin.readline())\r\ninput_1D_int = lambda: [int(x) for x in stdin.readline().split()]\r\ninput_2D_int = lambda n: [input_1D_int() for _ in range(n)]\r\ninput_string = lambda: stdin.readline().strip()\r\ninput_1D_string = lambda: [str(x) for x in stdin.readline().split()]\r\ninput_2D_string = lambda n: [input_1D_string() for _ in range(n)]\r\npr = lambda args, sep: stdout.write(sep.join(map(str, args)) + '\\n')\r\nchars, oo = 'abcdefghijklmnopqrstuvwxyz', int(1e18)\r\nMAX = 1000000 + 10\r\nis_prime = [True] * MAX\r\nspf = list(range(MAX))\r\n\r\n\r\ndef sieve():\r\n is_prime[0] = is_prime[1] = False\r\n for i in range(2, int(MAX ** 0.5) + 1):\r\n if is_prime[i]:\r\n for j in range(i * i, MAX, i): is_prime[j] = False\r\n for i in range(2, MAX): spf[i] = i\r\n for i in range(4, MAX, 2): spf[i] = 2\r\n for i in range(3, int(MAX ** 0.5) + 1):\r\n if spf[i] == i:\r\n for j in range(i * i, MAX, i):\r\n if spf[j] == j: spf[j] = i\r\n\r\n\r\nsieve()\r\nprefix = [0] * MAX\r\nfor i in range(1, MAX): prefix[i] = prefix[i - 1] + is_prime[i]\r\na, b, k = input_1D_int()\r\ndef can(target):\r\n for x in range(a, b - target + 2):\r\n if prefix[x + target - 1] - prefix[x - 1] < k:\r\n return 0\r\n return 1\r\nl, r, best = 1, b - a + 1, -1\r\nwhile l <= r:\r\n mid = (l + r) // 2\r\n if can(mid):\r\n best = mid\r\n r = mid - 1\r\n else:\r\n l = mid + 1\r\nprint(best if best != -1 else -1)\r\n", "def get_primes(n):\r\n sieve = [True] * n\r\n for i in range(3, int(n**0.5) + 1, 2):\r\n if sieve[i]:\r\n sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)\r\n return [2] + [i for i in range(3,n,2) if sieve[i]]\r\n\r\nprimes = get_primes(10**6 + 1)\r\nis_prime = [False] * (10**6 + 1)\r\nfor x in primes:\r\n is_prime[x] = True\r\n\r\na, b, k = [int(x) for x in input().split()]\r\n\r\ndef works(l):\r\n curr = 0\r\n for x in range(l):\r\n curr += int(is_prime[a+x])\r\n # print(f\"[start] {a} to {a+l-1} = {curr}\")\r\n if curr < k:\r\n return False\r\n for x in range(l, b-a+1):\r\n curr += int(is_prime[a+x])\r\n curr -= int(is_prime[a+x-l])\r\n # print(f\"{a+x} to {a+x+l-1} = {curr}\")\r\n if curr < k:\r\n return False\r\n return True\r\n\r\nlo = 1\r\nhi = b-a+1\r\nif works(lo):\r\n print(lo)\r\nelif not works(hi):\r\n print(-1)\r\nelse:\r\n while lo < hi - 1:\r\n mid = (lo + hi) // 2\r\n if works(mid):\r\n hi = mid\r\n else:\r\n lo = mid\r\n print(hi)", "def isprime(a):\r\n if a < 2:\r\n return False\r\n if a == 2:\r\n return True\r\n for h in range(2, int(a ** (0.5))+ 1):\r\n if a % h == 0:\r\n return False\r\n return True\r\n\r\n#print(isprime(103))\r\na, b, k = map(int, input().split())\r\n#a,b,k = 579857, 857749, 9\r\narr=[]\r\nfor g in range(a, b + 1):\r\n if isprime(g):\r\n arr += [g]\r\n#print(len(arr), arr)\r\ncheck = a\r\nptr1 = -1\r\nptr2 = 0\r\ncount = 0\r\nn = len(arr)\r\nmaxm= 0\r\nif n < k:\r\n print(-1)\r\nelse:\r\n while ptr2 < n:\r\n count += 1\r\n if count >= k:\r\n if count == k:\r\n maxm = max(maxm, arr[ptr2] - check + 1)\r\n maxm = max(maxm, arr[ptr2] - check)\r\n ptr1 += 1\r\n check = arr[ptr1]\r\n ptr2 += 1\r\n if arr[-1] < b:\r\n maxm = max(maxm, b- check + 1)\r\n print(maxm)\r\n ", "\r\nimport sys\r\n\r\n\r\nclass FastIO:\r\n def __init__(self):\r\n return\r\n\r\n @staticmethod\r\n def read_str():\r\n return sys.stdin.readline().rstrip()\r\n\r\n @staticmethod\r\n def read_int():\r\n return int(sys.stdin.readline().rstrip())\r\n\r\n @staticmethod\r\n def read_list_ints():\r\n return list(map(int, sys.stdin.readline().rstrip().split()))\r\n\r\n @staticmethod\r\n def st(x):\r\n return print(x)\r\n\r\n @staticmethod\r\n def lst(x):\r\n return print(*x)\r\n\r\n @staticmethod\r\n def max(a, b):\r\n return a if a > b else b\r\n\r\n\r\nclass NumberTheory:\r\n def __init__(self):\r\n return\r\n\r\n @staticmethod\r\n def sieve_of_eratosthenes(n): # 埃拉托色尼筛选法,返回小于等于n的素数\r\n primes = [True] * (n + 1) # 范围0到n的列表\r\n p = 2 # 这是最小的素数\r\n while p * p <= n: # 一直筛到sqrt(n)就行了\r\n if primes[p]: # 如果没被筛,一定是素数\r\n for i in range(p * 2, n + 1, p): # 筛掉它的倍数即可\r\n primes[i] = False\r\n p += 1\r\n primes = [\r\n element for element in range(\r\n 2, n + 1) if primes[element]] # 得到所有小于等于n的素数\r\n return primes\r\n\r\n\r\nclass Solution:\r\n def __init__(self):\r\n return\r\n\r\n @staticmethod\r\n def main(ac=FastIO()):\r\n a, b, k = ac.read_list_ints()\r\n primes = NumberTheory().sieve_of_eratosthenes(b)\r\n primes = [num for num in primes if a <= num <= b]\r\n m = len(primes)\r\n if m < k:\r\n ac.st(-1)\r\n return\r\n\r\n cnt = [b - a + 2] * (b - a + 1)\r\n i = 0\r\n for x in range(a, b + 1):\r\n while i < m and primes[i] < x:\r\n i += 1\r\n if i + k - 1 >= m:\r\n break\r\n cnt[x - a] = primes[i + k - 1] - x + 1\r\n if x > a:\r\n cnt[x - a] = ac.max(cnt[x - a], cnt[x - a - 1])\r\n for length in range(1, b - a + 2):\r\n if cnt[b - length + 1 - a] <= length:\r\n ac.st(length)\r\n break\r\n return\r\n\r\n\r\nSolution().main()\r\n", "'''\r\n【灵茶の试炼】\r\nhttps://docs.qq.com/sheet/DWGFoRGVZRmxNaXFz\r\n\r\nhttps://codeforces.com/contest/237/problem/C\r\n\r\n输入 a b k,范围 [1,1e6],a≤b。\r\n请找到最短的 L,使得对于任意 a≤x≤b-L+1 都满足:在 x,x+1,...,x+L-1 中至少有 k 个质数。\r\n输出 L。如果 L 不存在,输出 -1。\r\n\r\n输入 2 4 2\r\n输出 3\r\n\r\n输入 6 13 1\r\n输出 4\r\n\r\n输入 1 4 3\r\n输出 -1\r\n'''\r\nfrom itertools import accumulate\r\n\r\n\r\nMX = 10**6+1\r\nprimes = []\r\nis_prime = [1]*MX\r\nfor i in range(2, MX):\r\n if is_prime[i]:\r\n primes.append(i)\r\n for j in range(i*i, MX, i):\r\n is_prime[j] = 0\r\nis_prime[0] = 0\r\nis_prime[1] = 0\r\nis_prime = list(accumulate(is_prime, initial=0))\r\n\r\n\r\ndef _n():\r\n return int(input())\r\n\r\n\r\ndef _nA():\r\n return list(map(int, input().split()))\r\n\r\n\r\ndef _nS():\r\n return input().split()\r\n\r\n\r\n# def solve():\r\n# a, b, k = _nA()\r\n\r\n# def check(mid):\r\n# for x in range(a, b+1-mid+1):\r\n# if is_prime[x+mid]-is_prime[x] < k:\r\n# return False\r\n# return True\r\n# l, r = 0, int(1e6)\r\n# while l < r:\r\n# mid = (l+r)//2\r\n# if check(mid):\r\n# r = mid\r\n# else:\r\n# l = mid+1\r\n# if check(l) and b-l+1 >= a:\r\n# print(l)\r\n# else:\r\n# print(-1)\r\ndef solve():\r\n a, b, k = _nA()\r\n r = a\r\n ret = 0\r\n for i in range(a, b+1):\r\n while r <= b and is_prime[r+1]-is_prime[i] < k:\r\n r += 1\r\n ret = max(ret, r-i+1)\r\n if r > b:\r\n break\r\n print(-1 if ret > b-a+1 else ret)\r\n\r\n\r\nsolve()\r\n", "# 线性筛\r\na, b, k = map(int, input().split())\r\nMs = 10 ** 6 + 1\r\nps = [0] * Ms\r\nS = [0] * Ms\r\nfor i in range(2, Ms):\r\n if ps[i] == 0:\r\n S[i] = 1\r\n for j in range(i, Ms, i):\r\n ps[j] = 1\r\nfor i in range(1, Ms):\r\n S[i] += S[i - 1]\r\nleft = 0\r\nright = b - a + 1\r\n\r\n\r\ndef check(L):\r\n for i in range(a, b - L + 2):\r\n if S[i + L - 1] - S[i - 1] < k:\r\n return False\r\n return True\r\n\r\n\r\nwhile left <= right:\r\n mid = (left + right) // 2\r\n if check(mid):\r\n right = mid - 1\r\n else:\r\n left = mid + 1\r\nif left > b - a + 1:\r\n print(-1)\r\nelse:\r\n print(left)\r\n", "from sys import stdin\r\n\r\n\r\ndef count_prime(n):\r\n prim[0] = prim[1] = 0\r\n for i in range(2, n + 1):\r\n if prim[i]:\r\n for j in range(i * 2, n + 1, i):\r\n prim[j] = 0\r\n\r\n for i in range(1, n + 1):\r\n prim[i] += prim[i - 1]\r\n\r\n\r\na, b, k = map(int, stdin.readline().split())\r\nprim, be, en, ans = [1] * (10 ** 6 + 1), 1, b - a + 1, -1\r\ncount_prime(10 ** 6)\r\n\r\nwhile be <= en:\r\n md = (be + en) >> 1\r\n for i in range(a + md - 1, b + 1):\r\n num = prim[i] - prim[i - md]\r\n if num < k:\r\n be = md + 1\r\n break\r\n else:\r\n ans = md\r\n en = md - 1\r\n\r\nprint(ans)\r\n", "a,b,k=list(map(int,input().split(' ')))\r\nPRIMES=[]\r\n# M=10**6+1\r\nM=b+1\r\nf=[1]*M\r\nj=-1\r\nfor i in range(2,M):\r\n if f[i]==1:\r\n PRIMES.append(i)\r\n if j==-1 and i>=a:\r\n j=len(PRIMES)-1\r\n for p in PRIMES:\r\n if i*p>=M: break\r\n f[i*p]=0\r\n if i%p==0: break\r\nli=PRIMES[j:]\r\nn=len(li)\r\n# print(PRIMES)\r\n# print(li)\r\nif n<k:\r\n print(-1)\r\nelse:\r\n ans=li[k-1]-a+1\r\n for t in range(k,n):\r\n ans=max(ans,li[t]-li[t-k])\r\n ans=max(b-li[-k]+1,ans)\r\n print(ans)", "from operator import not_\nimport sys\ninput = sys.stdin.readline\na,b,k = map(int,input().split())\nnot_prime = [False] * (b+2)\nprimes = []\nnot_prime[1] = True\nfor i in range(2,b+2):\n if not not_prime[i]:\n primes.append(i)\n for j in range(b+1):\n if i * primes[j] > b:\n break\n not_prime[i * primes[j]] = True\n if i % primes[j] == 0:\n break\nr = a-1\nprime_cnt = 0\ndef move_right():\n global r, prime_cnt\n r += 1\n prime_cnt += 0 if not_prime[r] else 1\nmove_right()\nans = b+1\nfor i in range(a,b+1):\n while r<=b and prime_cnt<k:\n move_right()\n if r<=b:\n ans = min(ans, b-i+1)\n else:\n break\n prime_cnt -= 0 if not_prime[i] else 1\n move_right()\nif ans == b+1:\n ans = -1\nprint(ans)\n", "a,b,k=list(map(int,input().split()))\r\nc=[1]*b\r\nc[0]=0\r\nfor i in range(1,b):\r\n if c[i]:\r\n for j in range(2*i+1,b,i+1):\r\n c[j]=0\r\nl=-1\r\ni,j=a-1,a-2\r\nx=0\r\nm=b+1\r\nwhile j<b:\r\n if x<k:\r\n j+=1\r\n if j<b:\r\n x+=c[j]\r\n elif x==k:\r\n m=i\r\n l=max(l,j-i+1)\r\n x-=c[i]\r\n i+=1\r\nl=max(l,b-m)\r\nprint(l)", "a, b, k = map(int, input().split())\r\n# L <= b - a + 1\r\n\r\nmx = 2000000\r\n# 先预处理[1,2e6]这段内的所有质数\r\nprime = [True] * (mx + 1)\r\nprime[1] = False\r\n\r\nfor i in range(2, mx + 1):\r\n if not prime[i]: continue\r\n\r\n for j in range(i * i, mx + 1, i):\r\n prime[j] = False\r\n\r\ntot = [0]\r\nfor i in range(1, mx + 1):\r\n tot.append(tot[-1] + int(prime[i]))\r\n\r\n\r\n# L为v时,是否满足\r\ndef check(v):\r\n \r\n for x in range(a, b - v + 1 + 1):\r\n # [x, x + v - 1]内有多少个质数?\r\n cnt = tot[x + v - 1] - tot[x - 1]\r\n if cnt < k: return False\r\n\r\n return True\r\n\r\nl, r = 1, b - a + 1\r\nwhile l < r:\r\n mid = (l + r) // 2\r\n if not check(mid):\r\n l = mid + 1\r\n else:\r\n r = mid\r\n\r\nif check(l):\r\n print(l)\r\nelse:\r\n print(-1)", "N = 10**6+5\r\nvis = [False] * N \r\ns = [0] * N\r\nprimes = []\r\ndef init():\r\n for i in range(2, N):\r\n if not vis[i]:\r\n primes.append(i)\r\n \r\n j = 0\r\n while primes[j] <= (N-1) // i:\r\n vis[i * primes[j]] = True \r\n if i % primes[j] == 0: break\r\n j += 1\r\n \r\n for i in range(2, N):\r\n s[i] = s[i-1] + (vis[i] == False)\r\n\r\ndef check(mid):\r\n for i in range(a, b-mid+2):\r\n if s[i+mid-1] - s[i-1] < k: return False\r\n return True\r\n\r\nif __name__ == \"__main__\":\r\n a, b, k = map(int, input().split())\r\n init()\r\n\r\n l = 1\r\n r = b - a + 1\r\n\r\n while l < r:\r\n mid = l + r >> 1\r\n if check(mid): r = mid\r\n else: l = mid + 1\r\n if check(l): print(l)\r\n else: print(-1)", "def solve() -> None:\r\n a, b, k = list(map(int, input().split()))\r\n\r\n # 1. 求a - b之间的质数列表\r\n factor = [1] * (b + 1)\r\n primes = [a - 1] # 哨兵\r\n for i in range(2, b + 1):\r\n if factor[i] != 1: continue\r\n if i >= a:\r\n primes.append(i)\r\n for j in range(i, b + 1, i):\r\n factor[j] = i\r\n\r\n # print(primes)\r\n if len(primes) < k + 1:\r\n print(-1)\r\n return\r\n ans, p = b - a + 1, 0\r\n for l in range(len(primes) - k):\r\n r = l + k # l - r有k + 1个质数\r\n # 2. x的范围为a - primes[l + 1], 可使得从x到primes[r]之间有k个质数\r\n # 3. primes[l + 1] = b - L + 1, L = b - primes[l + 1] + 1\r\n # 4. 从primes[l]到primes[l + 1]的范围的数,要满足有k个点的最小L为:primes[r] - primes[l]\r\n p = max(p, primes[r] - primes[l])\r\n ans = min(ans, max(b - primes[l + 1] + 1, p))\r\n print(ans)\r\n\r\n\r\n# for _ in range(int(input())):\r\nsolve()\r\n\r\n", "from sys import stdin,stdout\r\nnmbr = lambda: int(stdin.readline())\r\nlst = lambda: list(map(int,stdin.readline().split()))\r\nN=10**6+6\r\nprimes=[1]*N\r\np=2\r\nwhile p*p<=N:\r\n if primes[p]:\r\n for j in range(p*p,N,p):\r\n primes[j]=0\r\n p+=1\r\nprimes[1]=primes[0]=0\r\ndef fn(x):\r\n for i in range(n-x+1):\r\n ones=aa[i+x-1]-(aa[i-1] if i>=1 else 0)\r\n if ones<k:return False\r\n return True\r\nfor _ in range(1):#nmbr()):\r\n a,b,k=lst()\r\n n=b-a+1\r\n l=1;r=b-a+1\r\n aa=[0]*(b-a+1)\r\n c=0\r\n for i in range(a,b+1):\r\n aa[c]=primes[i]+aa[max(0,c-1)]\r\n c+=1\r\n # print(aa)\r\n while l<=r:\r\n mid=(l+r)>>1\r\n # print(mid,fn(mid))\r\n if fn(mid)==False:l=mid+1\r\n else:r=mid-1\r\n print(l if l<=n else -1)", "if __name__ == \"__main__\":\r\n a, b, k = map(int, input().split())\r\n primes, pid = [], [0] * (10**6 + 1)\r\n primes.append(a - 1)\r\n pid[0] = pid[1] = -1\r\n for i in range(2, b + 1):\r\n if pid[i] == 0:\r\n if i >= a:\r\n primes.append(i)\r\n pid[i] = len(primes)\r\n for j in range(i * i, b + 1, i):\r\n pid[j] = -1\r\n primes.append(b + 1)\r\n if len(primes) - 2 < k:\r\n print(-1)\r\n else:\r\n ans = 0\r\n for i in range(k, len(primes)):\r\n ans = max(ans, primes[i] - primes[i-k])\r\n print(ans)\r\n", "'''\r\n【灵茶の试炼】\r\nhttps://docs.qq.com/sheet/DWGFoRGVZRmxNaXFz\r\n\r\nhttps://codeforces.com/contest/237/problem/C\r\n\r\n输入 a b k,范围 [1,1e6],a≤b。\r\n请找到最短的 L,使得对于任意 a≤x≤b-L+1 都满足:在 x,x+1,...,x+L-1 中至少有 k 个质数。\r\n输出 L。如果 L 不存在,输出 -1。\r\n\r\n输入 2 4 2\r\n输出 3\r\n\r\n输入 6 13 1\r\n输出 4\r\n\r\n输入 1 4 3\r\n输出 -1\r\n'''\r\nfrom itertools import accumulate\r\n\r\n\r\nMX = 10**6+1\r\nprimes = []\r\nis_prime = [1]*MX\r\nfor i in range(2, MX):\r\n if is_prime[i]:\r\n primes.append(i)\r\n for j in range(i*i, MX, i):\r\n is_prime[j] = 0\r\nis_prime[0] = 0\r\nis_prime[1] = 0\r\nis_prime = list(accumulate(is_prime, initial=0))\r\n\r\n\r\ndef _n():\r\n return int(input())\r\n\r\n\r\ndef _nA():\r\n return list(map(int, input().split()))\r\n\r\n\r\ndef _nS():\r\n return input().split()\r\n\r\n\r\ndef solve():\r\n a, b, k = _nA()\r\n\r\n def check(mid):\r\n\r\n for x in range(a, b+1-mid+1):\r\n if is_prime[x+mid]-is_prime[x] < k:\r\n return False\r\n return True\r\n\r\n l, r = 0, int(1e6)\r\n while l < r:\r\n mid = (l+r)//2\r\n if check(mid):\r\n r = mid\r\n else:\r\n l = mid+1\r\n if check(l) and b-l+1 >= a:\r\n print(l)\r\n else:\r\n print(-1)\r\n\r\n\r\nsolve()\r\n" ]
{"inputs": ["2 4 2", "6 13 1", "1 4 3", "5 8 2", "8 10 3", "1 5 2", "6 8 3", "21 29 2", "17 27 3", "1 1000000 10000", "690059 708971 10000", "12357 534133 2", "838069 936843 3", "339554 696485 4", "225912 522197 5", "404430 864261 6", "689973 807140 7", "177146 548389 8", "579857 857749 9", "35648 527231 10", "2 1000000 10000", "1 999999 9999", "5 5 10", "11 11 6", "4 4 95", "1 1000000 1000000", "1 1000000 78498", "1 1000000 78499", "3459 94738 1", "1 1000000 1", "1 1000000 78498", "1 1000000 78497", "1 1000000 78490", "1000 10000 13", "100000 1000000 7821", "20 1000000 40000", "1000 900000 50000", "10000 1000000 60000", "9999 99999 8000", "50 150 20", "999953 999953 1", "999953 999953 2", "999931 999953 2", "999906 999984 4", "999940 999983 3", "1 1 1", "1 1 1000000", "1 2 1", "1 3 1", "1 3 2", "1 4 2", "1 5 2", "1 5 3", "2 5 2", "3 5 1"], "outputs": ["3", "4", "-1", "4", "-1", "3", "-1", "9", "11", "137970", "-1", "138", "142", "168", "190", "236", "236", "240", "300", "280", "137970", "137958", "-1", "-1", "-1", "-1", "999999", "-1", "72", "114", "999999", "999998", "999978", "168", "108426", "539580", "659334", "793662", "86572", "100", "1", "-1", "23", "52", "26", "-1", "-1", "2", "2", "3", "3", "3", "5", "3", "2"]}
UNKNOWN
PYTHON3
CODEFORCES
27
1334299b4247da2d1bdae5974c6fcb0f
Red and Blue Balls
User ainta has a stack of *n* red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack. - While the top ball inside the stack is red, pop the ball from the top of the stack. - Then replace the blue ball on the top with a red ball. - And finally push some blue balls to the stack until the stack has total of *n* balls inside. If there are no blue balls inside the stack, ainta can't apply this operation. Given the initial state of the stack, ainta wants to know the maximum number of operations he can repeatedly apply. The first line contains an integer *n* (1<=≤<=*n*<=≤<=50) — the number of balls inside the stack. The second line contains a string *s* (|*s*|<==<=*n*) describing the initial state of the stack. The *i*-th character of the string *s* denotes the color of the *i*-th ball (we'll number the balls from top to bottom of the stack). If the character is "R", the color is red. If the character is "B", the color is blue. Print the maximum number of operations ainta can repeatedly apply. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Sample Input 3 RBR 4 RBBR 5 RBBRR Sample Output 2 6 6
[ "input()\r\ncolor = input()\r\noperations = 0\r\nfor i in range(0, len(color)):\r\n if 'B' in color[i]:\r\n operations += pow(2, i)\r\nprint(operations)\r\n", "inp=int(input())\r\nballs=input()\r\ntms=1\r\nans=0\r\nfor i in range(inp):\r\n\tif balls[i]=='B':\r\n\t\tans+=tms\r\n\ttms*=2\r\nprint(ans)", "size = int(input())\r\nstack = list(input())\r\n\r\nres = 0\r\nfor i in range(size):\r\n if stack[i] == 'B':\r\n res += 2 ** i\r\nprint(res)", "n = int(input())\r\nstr = input()\r\nnum = 0\r\nfor i in range(len(str)):\r\n if str[i] == 'B':\r\n num = num + pow(2,i)\r\nprint(num)", "n=int(input())\r\nS=input()\r\nan = 0\r\nfor i in range(len(S)):\r\n if S[i] == 'B':\r\n an += 2**i\r\nprint(an) ", "# https://codeforces.com/problemset/problem/399/B\n# B. Red and Blue Balls\n\nn = int(input())\ninput_str = input()\ncount_op = 0\n\ncount = 0\nfor c in input_str:\n if c == 'B':\n count_op += 2 ** count\n count += 1\nprint(count_op)\n", "n = int(input())\r\ns = input()\r\n\r\nops = 2**n - 1\r\n\r\nfor i in range(n):\r\n if s[i] == 'R':\r\n ops -= 2**i\r\n\r\nprint(ops)\r\n", "size = int(input())\r\nstack = list(input())\r\n\r\nprint(sum([2 ** i for i in range(size) if stack[i] == 'B']))", "n = int(input())\r\ns = input()\r\nt = '_'.join(s)\r\nw = t.split(sep = '_')\r\na = 0\r\nif w.count('B') == 0:\r\n print('0')\r\nelse :\r\n b = w.count('B')\r\n for i in range(b):\r\n c = w.index('B')\r\n a += 2**c\r\n w[c] = 'R'\r\n \r\n print(a)\r\n", "n = int(input())\r\ns = input()\r\n\r\nprint(sum(map(lambda i: (2 ** i) * (s[i] == 'B'), range(n))))\r\n", "n = int(input())\r\nstr = input()\r\nif(n==1):\r\n if(str=='R'):\r\n print('0')\r\n else:\r\n print('1')\r\nelse:\r\n sum = 0\r\n i = 0\r\n while(i<=n-1):\r\n if(str[i]=='B'):\r\n sum+=pow(2,i)\r\n i+=1\r\n print(sum)", "n = int(input())\r\ns = list(input())\r\nc = 0\r\nfor i in range(n):\r\n if s[i]=='B':\r\n c = c + 2**i\r\nprint(c)", "input()\r\nprint(int(input()[::-1].translate(str.maketrans('RB', '01')), 2))\r\n# print(int(input()[::-1].replace('R', '0').replace('B', '1'), 2))\r\n# print(int(''.join(list(map(lambda x: '0' if x == 'R' else '1', input()[::-1]))), 2))\r\n", "n = input()\r\ns = input()\r\nnum = [0 if letter =='R' else 1 for letter in s]\r\nprint(int(''.join(map(str,num[::-1])),2))", "n = int(input());print(int(input()[::-1].replace('R', '0').replace('B', '1'), 2))\r\n", "import math,string,itertools,fractions,heapq,collections,re,array,bisect\nfrom itertools import chain, dropwhile, permutations, combinations\nfrom collections import defaultdict\n\n\ndef main(n,s):\n if 'B' not in s:\n print(0)\n return\n b = s.count(\"B\")\n r = s.count(\"R\")\n op = {}\n op[0] = 1\n op[1] = 2\n op[2] = 4\n op[3] = 1 + op[2] + op[1] + op[0]\n op[3] = 8\n op[4] = 1 + op[3] + op[2] + op[1] + op[0]\n op[4] = 16\n ans = 0\n for i,x in enumerate(s):\n if x==\"B\":\n ans += 2**i\n print(ans)\n\n\ndef main_input(info=0):\n #n,p,k = map(int,input().split())\n #t = [(int(x)-1,i+1) for i,x in enumerate(input().split())]\n #l,r = list(range(n)), list(range(n))\n #for i in range(n):\n # l[i],r[i] = map(int,input().split())\n# t = [map(int,input().split()) for x in range(n)]\n n = int(input())\n s = input()\n main(n,s)\n\nif __name__ == \"__main__\":\n main_input()\n", "n=int(input())\ndef f(x): \n if x=='R': return '1' \n else: return '0'\nprint(2**n-1-int(\"\".join([f(c) for c in reversed(input())]),base=2))", "import re\n\nn = int(input())\ns = map(lambda x: 1 if x == \"B\" else 0, list(input()))\nprint(sum([el * 2 ** i for i, el in enumerate(s)]))\n", "n = int(input())\r\ns = input()\r\nres = 0\r\nfor i in range(n):\r\n if s[i] == 'B':\r\n res += 2**i\r\nprint(res)\r\n", "print(2 ** int(input()) - int(''.join(list(map(lambda x: '1' if x == 'R' else '0', input()[::-1]))), 2) - 1)\r\n", "n = int(input())\ns = input()\ntot = 0\nfor i, ball in enumerate(s):\n if ball == 'B':\n tot += (1 << i)\nprint(tot)\n\n", "n = int(input())\r\ns = input()\r\nprint( int(((s[::-1].replace('R', '0')).replace('B', '1')), base = 2))\r\n", "n=int(input())\r\nB=input()\r\nans=0\r\nfor i in range(n-1,-1,-1):\r\n ans=ans*2+int(B[i]=='B')\r\nprint(ans)\r\n", "n = int(input())\r\nstack = list(input())\r\ni = 0\r\nresult = 0\r\nwhile i<n:\r\n if stack[i] == 'B':\r\n result += 2**(i)\r\n i += 1\r\nprint(result)", "def solve(stack):\r\n return sum([2 ** i for i, c in enumerate(stack) if c == 'B'])\r\n\r\n\r\ndef main():\r\n _ = int(input())\r\n stack = input()\r\n print(solve(stack))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n = input()\r\ns = input()\r\nansw = 0\r\nk = 0\r\nfor i in range(len(s)):\r\n if s[i] == \"B\":\r\n answ+=2**i\r\nprint(answ)", "n=int(input())\r\ns=input()\r\nnew=[]\r\nfor ele in s:\r\n if ele=='R':\r\n new.append(0)\r\n else:\r\n new.append(1)\r\nans=0\r\nfor i in range(n):\r\n if new[i]==1:\r\n element=new[i]*(2**i)\r\n ans+=element\r\nprint(ans)", "n = int(input())\ns = input()\ncount = 0\n\nfor i in range(n):\n if s[i] == 'B':\n count += 2 ** i\nprint(count)", "n = int(input())\r\nstring = input()\r\nsum = 0\r\nfor i in range(len(string)):\r\n\tif string[i]==\"B\":\r\n\t\tsum+=2**i\r\nprint(sum)\r\n", "\n\nn=int(input())\nstrlist=list(input())\nsum=0\nfor i in range(n):\n if strlist[i]=='B':\n sum+=2**i\n\nprint(sum)\n", "\r\n\r\n\r\nn = int(input())\r\ns = input()\r\n\r\ncount = 0\r\nfor i in range(n):\r\n if s[i] == 'B':\r\n count+=2**i\r\n\r\nprint(count)", "length_stack = int(input())\r\nstack = input()\r\n\r\nsum = 0\r\n\r\nfor i in range(length_stack):\r\n if stack[i] == 'B':\r\n sum += pow(2, i)\r\n\r\nprint(sum)", "input()\r\nprint(int(input().replace('R', '0').replace('B', '1')[::-1], 2))", "n = int(input())\nrb = input()\nres = 0\ndef b_to_dec(rb):\n c = 0\n res = 0\n for i in rb:\n if i == 'B':\n res += 2**c * 1\n c += 1\n return res\n\nres = b_to_dec(rb)\n\nprint(res)\n", "def balls(s, n):\r\n result = 0\r\n step = [(1 << i) for i in range(51)]\r\n for j in range(n):\r\n if s[j] == 'B':\r\n result += step[j]\r\n return result\r\n\r\n\r\nm = int(input())\r\nt = input()\r\nprint(balls(t, m))\r\n", "n = int(input())\ns = list(input())\n\nnumberOfOp = 0\nfor i in range(n):\n if s[i] == \"B\":\n numberOfOp = numberOfOp + 2**i\n\nprint(numberOfOp)\n", "numberOfBalls = int(input())\r\nballs = input()\r\nindecesOfBlueBalls = []\r\nfor k in range(len(balls)):\r\n\tif balls[k] == 'B':\r\n\t\tindecesOfBlueBalls.append(k)\r\n\r\nneedToSum = []\r\n\r\nfor k in range(len(indecesOfBlueBalls)):\r\n\tneedToSum.append(2**indecesOfBlueBalls[k])\r\n\r\nprint(sum(needToSum))", "n, b = input(), input().replace('R', '0').replace('B', '1')\r\nprint(int(b[:: -1], 2))", "if __name__ == \"__main__\":\n n = int(input())\n balls = str(input())\n ans = sum(2 ** i for i in range(n) if balls[i] == 'B')\n print(ans)", "n = int(input())\r\ns = input().strip()\r\nop_cnt = 0\r\nfor i in range(n):\r\n if s[i] == 'B':\r\n op_cnt += 2 ** i\r\nprint(op_cnt)\r\n", "# KALAM\nn = int(input());s = input();\nA = 0\nfor i in range(len(s)):\n if(s[i] == 'B'):\n A += 2 ** i\nprint(A)\n", "n = int(input())\r\ns = list(input())\r\ncount = 0\r\nans = [1]\r\nfor i in range(50):\r\n ans.append(sum(ans) + 1)\r\n# print(ans)\r\nfor i in range(n):\r\n char = s[i]\r\n if char == 'B':\r\n count += ans[i]\r\nprint(count)\r\n# while 'B' in s:\r\n# if s[0] == 'B':\r\n# count += 1\r\n# s[0] = 'R'\r\n# else:\r\n# x = s.index('B')\r\n# for i in range(x):\r\n# s[i] = 'B'\r\n# s[x] = 'R'\r\n# count += 1\r\n# print(''.join(s))\r\n", "length, string = int(input()), input()\r\nprint(sum([2 ** i if string[i] == \"B\" else 0 for i in range(len(string))]))\r\n", "input()\nprint(int(''.join(\"0\" if c == \"R\" else \"1\" for c in input()[::-1]), 2))", "n = int(input())\r\ns = input()\r\nans = 0\r\nb = [0] * 50\r\nb[0] = 1\r\nfor i in range(50):\r\n b[i] = 2 * b[i - 1] + 1\r\n#print(b)\r\nfor i in range(n):\r\n if (s[i] == 'B'):\r\n ans += 1\r\n if (i > 0):\r\n ans += b[i - 1]\r\nprint(ans)", "def main():\n\tn = int(input())\n\t_array = list(input())\n\tans = 0\n\tfor _ in range(len(_array)):\n\t\tif _array[_] == 'B':\n\t\t\tans += 2 ** _\n\tprint(ans)\n\nif __name__ == '__main__':\n\tmain()", "n = int(input())\r\ns = input()\r\nres = 0\r\npow2 = [(1<<i) for i in range(51)]\r\nfor i in range(n):\r\n if (s[i] == 'B'):\r\n res += pow2[i]\r\nprint(res)\r\n", "n=int(input())\n\n\ns=input()\narr=[0]*n\nrecord=[-1]*(n+1)\n\n\ndef rec(n):\n if record[n]!=-1:\n return record[n]\n else:\n l=0\n for i in range(0,n):\n l+=rec(i)\n record[n]=l+1\n return record[n]\n\nrecord[0]=1\n\n\ntotal=0\nfor i in range(len(s)):\n if s[i]=='B':\n total+=rec(i)\n\nprint(total)\n", "n = int(input())\r\ns = list(input())\r\no = 0\r\n#s.reverse()\r\n\r\n# while s.count(\"B\") > 0:\r\n# while s[-1] == \"R\":\r\n# s.pop()\r\n# s[-1] = \"R\"\r\n# while len(s) < n:\r\n# s.append(\"B\")\r\n# o += 1\r\n# print(s)\r\n\r\ntry:\r\n index = s.index(\"B\")\r\n o += pow(2, index)\r\n while True:\r\n index = s.index(\"B\", index + 1)\r\n o += pow(2, index)\r\nexcept:\r\n print(o)\r\n ", "s = input()\r\n#s = \"5\"\r\nn = int(s)\r\n\r\ns = input()\r\n#s = \"RBBRR\"\r\nx = s\r\n\r\nans = 0\r\nfor i in range(0, n):\r\n if x[i] == 'B':\r\n ans += 1 << i\r\n \r\nprint(ans)", "n = int(input())\r\ns = str(input())\r\nsu = 0\r\nj = 0\r\na = -1\r\nfor i in range(n):\r\n if s[i] == 'R':\r\n a = 1\r\n else:\r\n a = 0\r\n su += a*pow(2,j)\r\n j += 1\r\nprint(pow(2,j)-1-su)\r\n\r\n", "input()\r\ncolor = input()\r\noperations=0\r\nfor i in range(0,len(color)):\r\n if 'B' in color[i]:\r\n operations += pow(2,i)\r\nprint(operations)", "n = int(input())\nst = input()\nst = st[-1::-1]\nst = st.replace('R', '0')\nst = st.replace('B', '1')\nprint(int(st, 2))", "n, s = int(input()), input()\r\nprint(sum(2 ** i for i in range(n) if s[i] == 'B'))", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Feb 4 17:30:28 2020\r\n\r\n@author: DeLL\r\n\"\"\"\r\n\r\nn=int(input())\r\ns=input()\r\n\r\nans=0\r\nfor i in range(len(s)):\r\n if s[i] =='B':\r\n ans+=2**i\r\n \r\nprint(ans)", "def operation(l):\r\n try:\r\n ind = l.index('B')\r\n if ind == 0:\r\n b_counter = 0\r\n while l[b_counter] != 'R':\r\n l[b_counter] = 'R'\r\n b_counter += 1\r\n if b_counter == len(l):\r\n break\r\n return 2**b_counter - 1 + operation(l)\r\n else:\r\n for c in range(ind):\r\n l[c] = 'B'\r\n l[ind] = 'R'\r\n return 1 + operation(l)\r\n except:\r\n return 0\r\n\r\nn = int(input())\r\ns = input()\r\nstack = list(s)\r\nprint(operation(stack))\r\n", "n = int(input())\r\ns = input()\r\nans = 0\r\nfor i in range(len(s)):\r\n ch = s[i]\r\n if ch == 'B':\r\n ans |= 1 << i\r\nprint(ans)", "def do():\n n = int(input())\n stack = [s for s in input()][::-1]\n b = stack.count(\"B\")\n res = 0\n while b > 0:\n while stack and stack[-1] == \"R\":\n stack.pop()\n stack[-1] = \"R\"\n b -= 1\n if len(stack) < n:\n res += (1 << (n - len(stack))) - 1\n stack += [\"R\"] * (n - len(stack))\n res += 1\n\n\n return res\n\n\n\n\nprint(do())\n", "input()\r\nprint(int(''.join(list(map(lambda x: '0' if x == 'R' else '1', input()[::-1]))), 2))\r\n", "n = int(input())\r\nword = str(input())\r\nres = 0\r\nfor i in range(len(word)):\r\n if word[i] == 'B':\r\n res |= 1 << i\r\nprint(res)\r\n", "# http://codeforces.com/problemset/problem/399/B\r\n\r\n\r\nimport sys\r\n\r\n\r\ndef main():\r\n n = int(sys.stdin.readline())\r\n s = sys.stdin.readline().rstrip()\r\n res = 0\r\n for i, c in enumerate(s):\r\n if c == 'B':\r\n res |= 1 << i\r\n print(res)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()", "n=int(input())\r\ns=input()\r\nans=0\r\ncount=count1=0\r\nw=0\r\nfor i in range(n):\r\n if(s[i]=='R'):\r\n if(w==0):\r\n ans+=2**count - 2**(count-count1)\r\n count1=0\r\n w=1\r\n else:\r\n w=0\r\n count1+=1\r\n count+=1\r\nif(s[-1]=='B'):\r\n ans+=2**count - 2**(count-count1)\r\nprint(ans)\r\n\r\n\r\n", "n = int(input())\r\ns = ''.join(\"1\" if c == \"R\" else \"0\" for c in input()[::-1])\r\nd = int(s, 2)\r\nprint((1 << n) - 1 - d)", "n = int(input())\r\ns = input().split()[0]\r\nres = 0\r\nfor i in range(len(s)):\r\n if s[i] == 'B':\r\n res += 2**i\r\nprint(res)\r\n" ]
{"inputs": ["3\nRBR", "4\nRBBR", "5\nRBBRR", "5\nRBRBR", "10\nRRBRRBBRRR", "10\nBRBRRRRRRR", "10\nBRRRRRRRRR", "20\nBRBRRRRRRRRRRRRRRRRR", "30\nRRBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "50\nBRRRBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "20\nRRRBRBBBBBRRRRRRRRRR", "20\nRRBRBBBBBRRRRRRRRRRR", "1\nR", "1\nB", "2\nRR", "2\nBR", "50\nRRRRRRRRRRBBBBBBRRBBRRRBRRBBBRRRRRRRRRRRRRRRRRRRRR", "50\nRBRRRRRBRBRRBBBBBBRRRBRRRRRBBBRRBRRRRRBBBRRRRRRRRR", "48\nRBRBRRRRBRBRRBRRRRRRRBBBRRBRBRRRBBRRRRRRRRRRRRRR", "30\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "50\nRRBBBBBBBBBBBBBBBBRBRRBBBRBBRBBBRRBRBBBBBRBBRBBRBR", "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "19\nRRRRRBRRBRRRRBRBBBB", "32\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBR", "3\nBBB", "3\nBBR", "3\nBRB", "3\nBRR", "3\nRBB", "3\nRBR", "3\nRRB", "3\nRRR", "2\nRB", "2\nBB"], "outputs": ["2", "6", "6", "10", "100", "5", "1", "5", "1073741820", "1125899906842609", "1000", "500", "0", "1", "0", "1", "479001600", "1929382195842", "13235135754", "0", "402373705727996", "1125899906842623", "500000", "2147483647", "7", "3", "5", "1", "6", "2", "4", "0", "2", "3"]}
UNKNOWN
PYTHON3
CODEFORCES
64
13448478d4e49c8e2d1caa3ff518b3c1
Valera and Antique Items
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him. Unfortunately, Valera has only *v* units of money. Help him to determine which of the *n* sellers he can make a deal with. The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has. Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space-separated integers *s**i*1,<=*s**i*2,<=...,<=*s**ik**i* (104<=≤<=*s**ij*<=≤<=106) — the current prices of the items of the *i*-th seller. In the first line, print integer *p* — the number of sellers with who Valera can make a deal. In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. Sample Input 3 50000 1 40000 2 20000 60000 3 10000 70000 190000 3 50000 1 50000 3 100000 120000 110000 3 120000 110000 120000 Sample Output 3 1 2 3 0
[ "a,b=map(int,input().split());k=[]\r\nfor i in range(1,a+1):\r\n\tc,*d=map(int,input().split())\r\n\tif min(d)<b:k+=[i]\r\nprint(len(k),\"\\n\",*k)\r\n\r\n\r\n\r\n", "t,v=map(int,input().split())\r\nans=[]\r\nfor i in range(1,t+1):\r\n a=list(map(int,input().split()))\r\n if(min(a[1:])<v):\r\n ans.append(i)\r\n\r\nprint(len(ans))\r\nfor i in range(len(ans)):\r\n print(ans[i],end=\" \")\r\n", "# python 3\n\nnum_sellers, money = list(map(int, input().split()))\nseller_antiques = list()\nfor idx in range(num_sellers):\n seller_antiques.append(list(map(int, input().split()))[1:])\n# print(seller_antiques)\ndeals = list()\nfor idx in range(num_sellers):\n seller_antiques[idx].sort()\n if money > seller_antiques[idx][0]:\n deals.append(idx+1)\ndeals_len = len(deals)\nprint(deals_len)\nif deals_len > 0:\n print(' '.join(list(map(str, deals))))\n", "n , v = input().split()\r\nn , v = int(n), int(v)\r\nst = set()\r\nfor i in range(n):\r\n m = i+1 \r\n lt = [int(x) for x in input().split()]\r\n #print(lt)\r\n for p in lt[1:]:\r\n if p<v:\r\n \r\n st.add(m)\r\n#print(st)\r\nprint(len(st))\r\nif len(st)!=0:\r\n print(*st)", "import sys\r\n\r\nn, v = [int(x) for x in (sys.stdin.readline()).split()]\r\n\r\nresult = []\r\nfor i in range(n): \r\n if(min([int(x) for x in ((sys.stdin.readline()).split())[1:]]) < v):\r\n result.append(str(i + 1))\r\n \r\nif not result:\r\n print(0)\r\nelse:\r\n print(len(result))\r\n print(\" \".join(result))\r\n ", "n,v=map(int,input().split())\r\nAns=[]\r\nfor i in range(n):\r\n L=list(map(int,input().split()))\r\n x=min(L[1:])\r\n if(x<v):\r\n Ans.append(i)\r\nprint(len(Ans))\r\nfor item in Ans:\r\n print(item+1,end=\" \")\r\n", "n,v = list(map(int,input().split()))\r\nans = []\r\nfor i in range(1,n+1):\r\n row = list(map(int,input().split()))\r\n k = row[0]\r\n items = sorted(row[1:])\r\n if items[0] < v:\r\n ans.append(i)\r\nprint(len(ans))\r\nprint(*ans)", "n, v = map(int, input().split())\nans = list()\nfor j in range(n):\n l = list(map(int, input().split()))\n for i in range(1, l[0]+1):\n if l[i] < v:\n ans.append(j+1)\n break\nprint(len(ans))\nprint(*ans)", "n, v = tuple(map(int, input().split()))\n\n\nresults = []\nfor i in range(n):\n k = list(map(int, input().split()))\n if min(k[1:]) < v:\n results.append(i + 1)\n\nprint(len(results))\nprint(*results)", "n, v = map(int, input().split())\r\nans = []\r\nfor i in range(n):\r\n k = [int(i)for i in input().split()]\r\n if min(k[1::]) < v:\r\n ans.append(i+1)\r\nprint(len(ans))\r\nprint(*ans)", "n,s=map(int,input().split())\r\nS=[]\r\nk=0\r\nfor i in range(n) :\r\n l=list(map(int,input().split()))\r\n for j in range(1,l[0]+1) :\r\n if l[j]<s :\r\n k=k+1\r\n S.append(str(i+1))\r\n break\r\nprint(k)\r\nprint(' '.join(S))\r\n\r\n\r\n \r\n", "# import sys\r\n# sys.stdin = open(\"#input.txt\", \"r\")\r\nn,v = map(int, input().split())\r\n\r\nls = []\r\nfor i in range(n):\r\n\tif v > min(list(map(int,input().split()))[1:]):\r\n\t\tls += [i+1]\r\nprint(len(ls))\r\nprint(*ls)", "[n,v] = list(map(int,input().split()))\r\n\r\ncount = 0\r\nans = []\r\n\r\nfor i in range(n):\r\n lis = list(map(int,input().split()))\r\n l = lis[0]\r\n flag = 0\r\n \r\n for j in range(1,l+1):\r\n if lis[j]<v:\r\n count+=1\r\n flag = 1\r\n break\r\n if flag == 1:\r\n ans.append(i+1)\r\n\r\nif count == 0:\r\n print(count)\r\nelse:\r\n print(count)\r\n print(*ans, sep = \" \")", "n, m = map(int, input().split())\r\nx = list()\r\nt = 0\r\nfor i in range(n):\r\n y = list(map(int, input().split()))\r\n \r\n for p in y[1:]:\r\n if m > p:\r\n t += 1\r\n x.append(str(i + 1))\r\n break\r\n \r\nprint(t)\r\nprint(\" \".join(x))", "n, v = map(int, input().split())\ntmp = []\nfor i in range(n):\n\ta = input().split()\n\tfor j in a[1:]:\n\t\tif(v > int(j)):\n\t\t\ttmp.append(i+1)\n\t\t\tbreak\nif(len(tmp)>0):\n\tprint(str(len(tmp))+' '+str(tmp)[1:-1].replace(',','').replace(\"'\",''))\nelse:\n\tprint('0')", "n, v = map(int, input().split())\r\ndealers = []\r\nfor i in range(1, n+1):\r\n dealer = list(map(int, input().split()))\r\n for prices in dealer[1:]:\r\n if v>prices:\r\n dealers.append(i)\r\n break\r\n\r\n\r\nprint(len(dealers))\r\nprint(*dealers)\r\n", "#1 _Habibolloh_\r\n#2 I_am_Naruto\r\n#3 mr.itmo\r\n#4 Cyber_Snake\r\n#5 ___Hafizullo___\r\n#6 Habib_2010 \r\nn, v = map(int, input().split())\r\nans = []\r\nfor i in range(n):\r\n *a, = map(int, input().split())\r\n a = a[1:]\r\n if min(a) < v:\r\n ans += [i + 1]\r\nprint(len(ans))\r\nprint(*ans)\r\n", "n, v = map(int, input().split())\r\nl = []\r\nd = {}\r\ncnt = 0\r\nfor i in range(1, n+1):\r\n l.append(list(map(int, input().split())))\r\n d[i] = min(l[i-1][1:])\r\n if d[i] < v:\r\n cnt +=1 \r\nprint(cnt)\r\nfor i in sorted(d):\r\n if d[i] < v:\r\n print(i, end = ' ')", "X = list (map (int, input ().split (' ')))\nM = []\n\nfor I in range (0, X [0]):\n\n Y = list (map (int, input ().split (' ')))\n Z = min (Y [1 : ])\n\n if X [1] > Z:\n\n M.append (str (I + 1))\n\nprint (len (M))\nprint (' '.join (M))\n", "n, v = map(int, input().split())\r\nq = []\r\nfor i in range(n):\r\n k = list(map(int, input().split()))\r\n for j in range(1, k[0] + 1):\r\n if k[j] < v:\r\n q.append(i + 1)\r\n break\r\nprint(len(q))\r\nprint(*q)\r\n", "n,v=list(map(int,input().split()))\r\ncount=0\r\nb=[]\r\ni=1\r\nwhile i<=n:\r\n a=list(map(int,input().split()))\r\n a.remove(a[0])\r\n if v>min(a):\r\n count+=1\r\n b.append(i)\r\n i+=1\r\nif count>0:\r\n print(count)\r\n for x in b:\r\n print(x,end=' ')\r\nelse:\r\n print(0)", "from collections import defaultdict\r\nd = {}\r\nt,v = map(int,input().split())\r\nk=1\r\nfor _ in range(t):\r\n vals= list(map(int,input().split()))\r\n vals.remove(vals[0])\r\n for val in vals:\r\n d.setdefault(k,[]).append(val)\r\n k+=1\r\ncount =0\r\nans =[]\r\n\r\nfor i in range(1,t+1):\r\n if v >min(d[i]):\r\n count+=1\r\n ans.append(i)\r\nprint(count)\r\nprint(*ans)", "n, v = [int(i) for i in input().split()]\r\nc = 0\r\na = ''\r\nfor i in range(n):\r\n s = [int(i) for i in input().split()]\r\n if v > min(s[1:]):\r\n c += 1\r\n a+=str(i + 1) + ' '\r\nprint(c)\r\nprint(a)", "def f():\r\n n,v=list(map(int,input().split(\" \")))\r\n ans=[]\r\n for i in range(n):\r\n temp=list(map(int,input().split(\" \")))\r\n ans.append(temp)\r\n count=0\r\n res=[]\r\n for i in range(len(ans)):\r\n for j in range(1,len(ans[i])):\r\n if v>ans[i][j]:\r\n count=count+1\r\n res.append(i+1)\r\n break\r\n \r\n print(count)\r\n print(*res)\r\nf()\r\n", "n, v = map(int, input().split())\r\ns = []\r\nfor i in range(n):\r\n if v > min(map(int, input().split()[1: ])):\r\n s.append(str(i + 1))\r\nprint(len(s))\r\nprint(' '.join(s))", "n, v = map(int, input().split())\r\nsell = []\r\nfor j in range(n):\r\n s = input().split()\r\n k = int(s[0])\r\n x = []\r\n for i in range(k):\r\n x.append(int(s[i+1]))\r\n for i in range(k):\r\n if(v > x[i]):\r\n sell.append(j+1)\r\n break\r\nprint(len(sell))\r\nfor i in sell:\r\n print(i, end = ' ')", "n,v=map(int,input().split())\r\na=[i+1 for i in range(n) if min(map(int,input().split()[1:]))<v]\r\nprint(len(a))\r\nprint(*a)", "ans = {}\r\nn, v = map(int, input().split())\r\n\r\nfor i in range(n):\r\n seller = list(map(int, input().split()))\r\n for j in range(1, seller[0] + 1):\r\n if v > seller[j]:\r\n ans[i + 1] = 1\r\n\r\nprint(len(ans))\r\nprint(*ans.keys())", "n, v = (int(i) for i in input().split())\np, c = 0, []\nfor j in range(n):\n _, *v_ = (int(i) for i in input().split())\n if any(i < v for i in v_):\n p += 1\n c.append(j+1)\nprint(p)\nprint(' '.join((str(i) for i in sorted(c))))", "a,b= input().split()\r\n\r\na=int(a)\r\nb=int(b)\r\nla=[]\r\nfor i in range(a):\r\n li=list(map(int, input().split()))\r\n l=li[1:]\r\n s=li[0]\r\n j=min(l)\r\n if j<b:\r\n la.append(i+1)\r\n\r\nif la==[]:\r\n print(0)\r\nelse:\r\n print(len(la))\r\n for i in la:\r\n print(i, end= \" \")", "a=list(map(int,input().split()))\r\nb=[list(filter(lambda x:x<a[1],list(map(int,input().split()[1:]))))for i in range(a[0])]\r\nc=[j+1 for j in range(len(b))if b[j]]\r\nprint(len(c))\r\nprint(' '.join(map(str,c)))\r\n", "import sys\r\ninput = sys.stdin.readline \r\n\r\n\r\nn, v = map(int, input().split())\r\nans =[]\r\nfor i in range(n):\r\n l = list(map(int, input().split()))\r\n l = l[1:]\r\n if(min(l) < v):\r\n ans.append(i + 1)\r\nprint(len(ans))\r\nprint(*ans)", "n,v = map(int,input().split())\r\nans = []\r\nfor i in range(n):\r\n s,*arr = map(int,input().split())\r\n for j in arr:\r\n if j < v:\r\n ans.append(i+1)\r\n break\r\nif len(ans) == 0:\r\n print(0)\r\nelse:\r\n print(len(ans))\r\n print(*sorted(ans))", "n, v = map(int, input().split())\nres = []\nfor i in range(n):\n a = list(map(int, input().split()))\n if v > sorted(a[1:])[0]:\n res.append(i + 1)\nprint(len(res))\nif len(res) > 0:\n print(\" \".join(map(str, res)))\n", "min = 0\r\nlst = []\r\njjj = 0\r\ntotally = 0\r\nfl = []\r\ntry:\r\n S = list(map(int, input().split()))\r\n N = S[0]\r\n total = S[1]\r\n for _ in range(N):\r\n A = list(map(int, input().split()))\r\n for i in range(len(A)):\r\n if i == 0:\r\n continue\r\n else:\r\n if i == 1:\r\n min = A[i]\r\n else:\r\n if min > A[i]:\r\n min = A[i]\r\n lst.append(min)\r\n abc = lst.copy()\r\n lst.sort()\r\n for i in lst:\r\n if i < total:\r\n totally += 1\r\n fl.append(abc.index(i))\r\n else:\r\n break\r\n print(totally)\r\n fl.sort()\r\n for i in fl:\r\n print(i+1, end=\" \")\r\nexcept:\r\n pass\r\n", "a= list(map(int, input().split()))\r\nn,v=a[0],a[1]\r\nb=[]\r\nfor i in range(n):\r\n c= list(map(int, input().split()))\r\n b.append(c)\r\nfor i in range(n):\r\n b[i]=sorted(b[i])\r\ncount=0\r\nr=''\r\nfor i in range(n):\r\n if v>b[i][1]:\r\n count+=1\r\n r=r+str(i+1)+' '\r\nprint(count)\r\nprint(r)", "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,m=map(int,input().split())\r\nans=[]\r\nfor i in range(n):\r\n data=list(map(int,input().split()))\r\n data.sort()\r\n if data[1]<m:\r\n ans.append(i+1)\r\nprint(len(ans))\r\nprint(' '.join(map(str,ans)))\r\n", "n,v=map(int,input().split())\r\np=0\r\nk=[]\r\nfor z in range(n):\r\n l=list(map(int,input().split()))\r\n l.pop(0)\r\n l=sorted(l)\r\n if v>l[0]:\r\n p+=1\r\n k.append(z+1)\r\nprint(p)\r\nprint(*k)", "n,v=map(int,input().split());y=[]\r\nfor i in range(1,n+1):\r\n x=[int(x) for x in input().split()]\r\n x.sort()\r\n if x[1]<v:\r\n y.append(i)\r\nprint(len(y))\r\nprint(*y)", "n, v = map(int, input().split())\r\nl = []\r\nfor cont in range(0, n):\r\n l.append(list(map(int, input().split()))[1:])\r\nris = []\r\nfor cont in range(0, len(l)):\r\n for pr in l[cont]:\r\n if v > pr:\r\n ris.append(str(cont+1))\r\n break\r\nprint(len(ris))\r\nprint(' '.join(ris))", "jumlah,uang = map(int , input().split())\r\nlista = []\r\nfor z in range (1,jumlah+1):\r\n x = list(map(int , input().split()))\r\n x.sort()\r\n if x[1] < uang:\r\n lista.append(z)\r\njumlah = len(lista)\r\nprint(jumlah)\r\nif jumlah != 0:\r\n for zz in lista:\r\n print(zz,end=\" \")\r\n \r\n", "n,v = map(int,input().split())\nans = []\nfor i in range(n):\n c,*l = map(int,input().split())\n if min(l) < v :\n ans.append(i+1)\nprint(len(ans),'\\n',*ans)\n", "n,k=map(int,input().split())\r\nans=[]\r\nfor i in range(n):\r\n if min(list(map(int,input().split()))[1:])<k:\r\n ans.append(i+1)\r\nprint(len(ans))\r\nprint(*ans)", "from sys import stdin, stdout\n\nn, money = map(int, stdin.readline().strip().split())\noks = []\nfor i in range(n):\n ls = list(map(int, stdin.readline().strip().split()))\n ls = ls[1:]\n flag = False\n for j in ls:\n if j < money:\n flag = True\n break\n if flag:\n oks.append(i+1)\n\nstdout.write(\"%d\\n\" % len(oks))\nfor i in range(len(oks)):\n stdout.write(\"%d\" % oks[i])\n if i != len(oks)-1:\n stdout.write(\" \")\nif len(oks) != 0:\n stdout.write(\"\\n\")\n\n\t\t \t \t\t\t\t\t \t \t\t\t\t \t\t\t", "n,v=map(int,input().split())\nsumi = 0\nls=[]\nfor i in range(n):\n\tli=list(map(int,input().split()))\n\tfor j in range(1,len(li)):\n\t\tif(v > li[j]):\n\t\t\tsumi =sumi + 1\n\t\t\tls.append(i+1)\n\t\t\tbreak\nprint(sumi)\nif(sumi!=0):\n\tprint(' '.join(map(str, ls))) ", "sellers,money=map(int,input().split(' '))\r\nlist1=[]\r\ncounts=0\r\nlist2=[]\r\nindex=0\r\nfor i in range(sellers):\r\n array1=list(map(int,input().split(' ')))\r\n list1.append(array1)\r\nfor n in range(len(list1)):\r\n count=0\r\n for m in range(1,len(list1[n])):\r\n if money>list1[n][m]:\r\n count=1\r\n if count==1:\r\n counts+=1\r\n index=n+1\r\n list2.append(index)\r\nprint(counts)\r\nfor f in list2:\r\n print(f,end=' ')\r\n ", "z = []\r\nz[0:] = map(int, input().split())\r\nw = []\r\ny = []\r\ncount = 0\r\nfor i in range(z[0]):\r\n w[0:] = map(int, input().split())\r\n y.append(w[:])\r\nnewlist = []\r\nindexlist = []\r\nfor i in range(z[0]):\r\n if z[1] > min(y[i][1:]):\r\n newlist.append(min(y[i][1:]))\r\n indexlist.append(i+1)\r\n count += 1\r\nprint(count)\r\nnewlist.sort()\r\nnewlist.reverse()\r\n\r\noop = []\r\nfor i in indexlist:\r\n print(i,end =\" \")\r\n", "n,b=map(int,input().split())\r\nlia=[]\r\nfor i in range(1,n+1):\r\n\tlis=list(map(int,input().split()))\r\n\tfor k in range(1,len(lis)):\r\n\t\tif b>lis[k]:\r\n\t\t\tlia.append(i)\r\n\t\t\tbreak\r\nprint(len(lia))\r\nfor i in lia:\r\n\tprint(i,end=\" \")", "n,m=map(int,input().split())\r\ns=[] \r\nfor i in range(n):\r\n si=list(map(int,input().split()))\r\n pri=si[1:]\r\n pri.sort()\r\n t=(si[0],pri)\r\n s.append(t)\r\nse=[]\r\nfor k in range(1,n+1):\r\n i=s[k-1]\r\n ob,pr=i[0],i[1]\r\n if pr[0]<m:\r\n se.append(k)\r\nprint(len(se))\r\nprint(*se)", "n,m = map(int, input().split())\r\ncnt = 0\r\na = []\r\nfor i in range(n):\r\n s = list(map(int, input().split()))\r\n s.pop(0)\r\n if min(s) < m:\r\n cnt += 1\r\n a.append(str(i + 1))\r\nprint(cnt)\r\nprint(\" \".join(a))", "ns,m=map(int,input().split())\r\nc=0\r\nv=[]\r\nfor i in range(ns):\r\n l=[int(i) for i in input().split()]\r\n l.pop(0)\r\n l.sort()\r\n for k in l:\r\n if(k<m):\r\n c=c+1\r\n v.append(i+1)\r\n break\r\nif(c==0):\r\n print(\"0\")\r\nelse:\r\n print(c)\r\n for i in v:\r\n print(i,end=\" \") ", "n,v=map(int,input().split())\r\nu=[]\r\nr=0\r\nfor i in range(n):\r\n l=list(map(int,input().split()))\r\n e=min(l[1:])\r\n if(e<v):\r\n r=r+1\r\n u.append(i+1)\r\nprint(r)\r\nprint(*u)", "n, current = map(int, input().split())\r\nans = []\r\nfor i in range(1, n+1, 1):\r\n array = list(map(int, input().split()))\r\n array = array[1:]\r\n flag = False\r\n for j in array:\r\n if j < current:\r\n flag = True\r\n break\r\n if flag:\r\n ans.append(i)\r\n\r\nprint(len(ans))\r\nfor i in ans:\r\n print(i, \"\", end = \"\")", "n, m = input().split(); n = int(n); m = int(m)\nl = []; c = 1\nfor i in range(n):\n t = input().split()\n for s in range(1, len(t)):\n if m > int(t[s]):\n l.append(c)\n break\n c += 1\nprint(len(l))\nl.sort()\nfor i in l:\n print(i, end=\" \")\nprint()\n", "n,v = map(int,input().split())\r\nans = []\r\nfor i in range(1,1+n):\r\n list_1 = list(map(int,input().split()))\r\n count = 0\r\n for j in range(1,list_1[0]+1):\r\n if list_1[j] < v:\r\n ans.append(i)\r\n break\r\nprint(len(ans))\r\nfor y in ans:\r\n print(y,end=\" \")\r\n \r\n \r\n", "n,m=input().split(\" \")\r\nn=int(n)\r\nm=int(m)\r\nc=[]\r\nd=0\r\ne=[]\r\nfor i in range(n):\r\n c.append([])\r\n a=input().split(\" \")\r\n for j in range(int(a[0])+1):\r\n c[i].append(int(a[j]))\r\n \r\nfor i in range(n):\r\n d=0\r\n for j in range(1,len(c[i])):\r\n if c[i][j]<m:\r\n d+=1\r\n break\r\n if d==1:\r\n e.append(i+1)\r\nprint(len(e))\r\nfor i in range(len(e)):\r\n print(e[i],end=' ')", "# -*- coding: utf-8 -*-\r\n# @Author: SyedAli\r\n# @Date: 2019-05-26 02:49:20\r\n# @Last Modified by: SyedAli\r\n# @Last Modified time: 2019-05-26 03:04:22\r\nn, v = map(int, input().split())\r\nans = []\r\nfor i in range(n):\r\n a = list(map(int, input().split()))[1:]\r\n if v > min(a):\r\n ans.append(i + 1)\r\nprint(len(ans))\r\nprint(*ans)", "n,v = map(int, input().split())\r\nres = []\r\nfor i in range(n):\r\n l = list(map(int, input().split()))\r\n k = l[0]\r\n l = l[1:]\r\n\r\n if v > min(l):\r\n res.append(i+1)\r\n\r\n\r\nprint(len(res))\r\nif len(res) > 0:\r\n print(\" \".join(map(str, res)))\r\n", "n, v = map(int, input().split())\nnl = []\nfor a in range(n):\n lst = [int(x) for x in input().split()]\n if v > min(lst[1:]):\n nl.append(a + 1)\nprint(len(nl))\nprint(*nl)\n\t \t\t \t \t \t\t\t \t \t\t\t\t\t \t \t \t\t", "n, v = map(int , input().split())\r\n \r\ndeals = [] \r\na = []\r\nfor i in range(n):\r\n s = list(int (x) for x in input().split())\r\n s.remove(s[0])\r\n if min(s) < v:\r\n deals.append(min(s))\r\n a.append(str(i+1))\r\n\r\n\r\nprint(len(deals))\r\np = ' '.join(a)\r\nprint(p)\r\n", "n, v = map(int, input().split())\r\nl = list()\r\nfor i in range(n):\r\n ks = list(map(int, input().split()))\r\n k = int(ks[0])\r\n mi = min(ks[1:])\r\n if mi < v:\r\n l.append(i + 1)\r\n\r\nl.sort()\r\nprint(len(l))\r\nfor i in range(len(l)):\r\n print(l[i], end=\" \")\r\n", "n,v=map(int,input().split())\r\na=list()\r\nb=list()\r\nfor i in range(n):\r\n a.append([int(i) for i in input().split()])\r\ny=0\r\nfor i in range(n):\r\n for j in range(1,len(a[i])):\r\n if(a[i][j]<v):\r\n y+=1\r\n b.append(i)\r\n break\r\nprint(y)\r\nfor i in range(len(b)):\r\n print(b[i]+1,end=' ')", "n, m = map(int, input().split())\r\nd = []\r\nds = 0\r\nfor i in range(n):\r\n L = list(map(int, input().split()))\r\n del L[0]\r\n if m > min(L):\r\n ds += 1\r\n d += [i+1]\r\nprint(ds)\r\nif len(d) == 0:\r\n print()\r\nelse:\r\n for i in d[:-1]:\r\n print(i, end=' ')\r\n print(d[-1])\r\n", "# Description of the problem can be found at http://codeforces.com/problemset/problem/441/A\r\n\r\nn, m = map(int, input().split())\r\n\r\nl_s = list()\r\nt = 0\r\n\r\nfor i in range(n):\r\n l_i = list(map(int, input().split()))\r\n \r\n for p in l_i[1:]:\r\n if m > p:\r\n t += 1\r\n l_s.append(str(i + 1))\r\n break\r\n \r\nprint(t)\r\nprint(\" \".join(l_s))", "n,m=[int(i) for i in input().split()]\r\nl=[]\r\nfor i in range(n):\r\n flag=0\r\n a=[int(i) for i in input().split()]\r\n for j in range(1,len(a)):\r\n if(a[j]<m):\r\n flag=1\r\n break\r\n if(flag==1):\r\n l.append(i+1)\r\nprint(len(l))\r\nprint(*sorted(l))", "#n - sellers\r\n#v- money he has\r\nn,v=input().split()\r\nn,v=int(n),int(v)\r\ndeal_s=[]\r\nfor i in range(1,n+1):\r\n #0th is item no \r\n seller_i = list(map(int, input().split()))\r\n for j in seller_i[1:]:\r\n if(v>int(j)):\r\n deal_s.append(i)\r\n break\r\n\r\nprint(len(deal_s))\r\nfor k in range(0,len(deal_s)):\r\n print(deal_s[k],end=\" \")", "traders, deposit = list(map(int, input().split()))\r\nnumber_of_traders = []\r\nfor trader_id in range(1, traders+1):\r\n \r\n _, *costs = list(map(int, input().split()))\r\n if any([cost for cost in costs if deposit > cost]):\r\n number_of_traders.append(trader_id)\r\n \r\nnumber_of_traders = set(number_of_traders)\r\nnumber_of_traders = sorted(list(number_of_traders))\r\n \r\nprint(len(number_of_traders))\r\nprint(*(number_of_traders))", "a,b=map(int,input().split())\r\nL1=[]\r\nfor k in range(a):\r\n L=list(map(int,input().split()))\r\n m=min(L[1::])\r\n if(b>m):\r\n L1+=[str(k+1)]\r\nprint(len(L1))\r\nprint(\" \".join(L1))\r\n", "n,v = map(int,input().split())\r\nl = []\r\nfor i in range(1,n+1):\r\n a = list(map(int,input().split()))\r\n if min(a[1:])<v:\r\n l.append(i)\r\n\r\nprint(len(l))\r\nif len(l)!=0:\r\n print(' '.join(map(str,l)))\r\n", "n,v = map(int, input().split())\r\nsellers=[]\r\nfor i in range(n):\r\n x = list(map(int, input().split()))\r\n for j in range(x[0]):\r\n if x[j+1] < v:\r\n sellers.append(i)\r\n break\r\nprint(len(sellers))\r\nfor i in sellers:\r\n print(str(i+1), end=\" \")\r\n ", "temp = input()\r\ntemp = temp.split()\r\nsellers = int(temp[0])\r\nmoney = int(temp[1])\r\norder = []\r\nfor x in range(sellers):\r\n temp = input()\r\n temp = temp.split()\r\n temp = [int(z) for z in temp]\r\n for y in temp[1:]:\r\n if money>y:\r\n order.append(x+1)\r\n break\r\nif len(order)==0:\r\n print('0')\r\nelse:\r\n print(len(order))\r\n for x in order:\r\n print(x, end=' ')", "p, v = map(int, input().split())\r\nans = []\r\nfor i in range(p):\r\n d = list(map(int, input().split()))\r\n d.pop(0)\r\n if min(d) < v:\r\n ans.append(i + 1)\r\nprint(len(ans))\r\nprint(*ans)\r\n", "a = [int(a) for a in input().split()]\r\nn,k = a[0],a[1]\r\nl=[]\r\nfor i in range(n):\r\n a = [int(a) for a in input().split()][1:]\r\n if any(1 if s<k else 0 for s in a):\r\n l.append(i+1)\r\nprint(len(l))\r\nprint(' '.join([str(a) for a in sorted(l)]))", "from xmlrpc.client import FastMarshaller\r\n\r\n\r\nn, v = map(int, input().split())\r\nans = []\r\nfor i in range(n):\r\n flag = False\r\n a = list(map(int, input().split()))\r\n a.pop(0)\r\n for j in range(len(a)):\r\n if a[j] < v:\r\n flag = True\r\n break\r\n if flag:\r\n ans.append(i+1)\r\n pass\r\nprint(len(ans))\r\nfor i in ans:\r\n print(i, end=' ')\r\nprint()", "n,money=list(map(int,input().split()))\r\nprices=[]\r\nsell=[]\r\nfor j in range(n):\r\n ll=list(map(int,input().split()))\r\n prices.append(ll[1:])\r\ngg=0\r\nfor i in prices:\r\n gg+=1\r\n for k in i:\r\n if k<money:\r\n sell.append(gg)\r\n break\r\nseller=list(set(sell))\r\nseller.sort()\r\nprint(len(seller))\r\nfor h in seller:\r\n print(h,end=\" \")\r\n", "#in the name of god\r\n#CodeForces,Problemset\r\nn,v=[int(i) for i in input().split()]\r\nans=[]\r\nfor i in range(1,n+1):\r\n s=[int(i) for i in input().split()][1:]\r\n for j in s:\r\n if v>j:\r\n ans.append(str(i))\r\n break\r\nprint(len(ans))\r\nprint(' '.join(ans))", "n,v=map(int,input().split())\r\ncount=0\r\nlis=[]\r\nfor i in range(n):\r\n\tk=list(map(int,input().split()))\r\n\tdel k[0]\r\n\tfor el in k:\r\n\t\tif el<v:\r\n\t\t\tlis.append((i+1))\r\n\t\t\tcount+=1\r\n\t\t\tbreak\r\nprint(count)\r\nfor i in lis:\r\n\tprint(i,end=' ')", "n,v=list(map(int,input().split()))\r\nl=[]\r\nfor x in range(n):\r\n l.append(list(map(int,input().split())))\r\n\r\ns=[]\r\nfor x in l:\r\n if min(x[1:])<v:\r\n s.append(l.index(x)+1)\r\nprint(len(s))\r\nfor x in s:\r\n print(x,end=' ')\r\n", "# coding: utf-8\nn, v = [int(i) for i in input().split()]\nans = []\nfor i in range(1,n+1):\n s = [int(i) for i in input().split()][1:]\n for j in s:\n if v > j:\n ans.append(str(i))\n break\nprint(len(ans))\nprint(' '.join(ans))\n", "def solve(arr, n, k):\n res = []\n for i,v in enumerate(arr):\n for j in v[1:]:\n if k > j:\n res.append(i+1)\n break\n \n print(len(res))\n print(*res)\n\n\ndef main():\n n,k = list(map(int, input().split(\" \")))\n # n = int(input())\n # a = list(map(int, input().split(\" \")))\n # b = list(map(int, input().split(\" \")))\n arr = []\n for i in range(n):\n arr.append(list(map(int, input().split(\" \"))))\n solve(arr,n,k)\n\n\nmain()\n", "n,v=map(int,input().split())\r\na=[]\r\nc=0\r\nfor i in range(0,n):\r\n l=list(map(int,input().split()))\r\n l.remove(l[0])\r\n minl=min(l)\r\n if(minl<v):\r\n a.append(i+1)\r\n c=c+1\r\nprint(c)\r\nfor i in a:\r\n print(i, end=\" \")\r\n \r\n \r\n \r\n", "a,b=map(int,input().split())\r\nl=[]\r\nz=0\r\nfor i in [0]*a:\r\n d=sorted(map(int,input().split()))[1:]\r\n z+=1\r\n if b>d[0]:\r\n l.append(z)\r\nprint(len(l),'\\n',*sorted(l))", "s = input().split()\r\n(n,v) = (int(i) for i in s)\r\nres = []\r\ncs = 0\r\nfor i in range(n):\r\n\ts = input().split()\r\n\ts = [int(j) for j in s]\r\n\tfor j in range(1,s[0]+1):\r\n\t\tif(s[j] < v):\r\n\t\t\tcs += 1\r\n\t\t\tres.append(i+1)\r\n\t\t\tbreak\r\nprint(cs)\r\nfor i in range(cs):\r\n\tprint(res[i],end = ' ')\r\n", "n, v = map(int, input().split())\r\nres, a = 0, []\r\nfor u in range(n):\r\n lst, mi = list(map(int, input().split())), 1000000000000\r\n for x in range(1, len(lst)): mi = min(mi, lst[x])\r\n if mi < v: a.append(u + 1)\r\nprint(len(a))\r\nprint(*a)", "n, v = map(int, input().split())\r\ndeal_sellers = []\r\n\r\nfor i in range(n):\r\n ki, *prices = map(int, input().split())\r\n min_price = min(prices)\r\n \r\n if v > min_price:\r\n deal_sellers.append(i + 1)\r\n\r\nprint(len(deal_sellers))\r\nprint(*deal_sellers)\r\n", "n, v = map(int, input().split())\r\n\r\nbuys = []\r\n\r\nfor i in range(n):\r\n k, *prices = map(int, input().split())\r\n for p in prices:\r\n if p<v:\r\n buys.append(i+1)\r\n break\r\n\r\nprint(len(buys))\r\nif buys:\r\n print(*buys, sep=' ')", "n,v=map(int,input().split())\r\nl=[]\r\nc=0\r\nfor i in range(n):\r\n arr=[int(i) for i in input().split()]\r\n arr.sort()\r\n if arr[1]<v:\r\n c=c+1\r\n l.append(i+1)\r\nprint(c)\r\nprint(*l)\r\n", "n, v = map(int, input().split())\r\n\r\nsellers_with_deal = []\r\nfor i in range(n):\r\n ki, *items = map(int, input().split())\r\n \r\n for item in items:\r\n if item < v:\r\n sellers_with_deal.append(i + 1)\r\n break\r\n\r\nprint(len(sellers_with_deal))\r\nif len(sellers_with_deal) > 0:\r\n print(\" \".join(map(str, sellers_with_deal)))\r\n", "n,v=map(int,input().split())\r\nx=[]\r\nc=0\r\nfor u in range(n):\r\n l=list(map(int,input().split()))\r\n a=l[0]\r\n l=l[1:]\r\n m=min(l)\r\n if(m<v):\r\n x.append(u+1)\r\n c=c+1\r\nif(c==0):\r\n print(0)\r\nelse:\r\n print(c)\r\n print(*x)\r\n", "string = input()\r\nnumbers = string.split(\" \")\r\nn = int(numbers[0])\r\nv = int(numbers[1])\r\nprices = []\r\nfor x in range(n):\r\n string = input()\r\n numbers = string.split(\" \")\r\n z = int(numbers[0])\r\n del numbers[0]\r\n for y in range(z):\r\n numbers[y] = int(numbers[y])\r\n prices.append(numbers)\r\nsellers = []\r\nfor x in range(n):\r\n y = prices[x]\r\n if v > min(y):\r\n sellers.append(str(x + 1))\r\nprint(len(sellers))\r\nprint(\" \".join(sellers))", "#!/usr/bin/python3.4\n\nn, val = map(int, input().split())\na = []\nfor i in range(1, n + 1):\n arr = list(map(int, input().split()))[1:]\n for cost in arr:\n if cost < val:\n a.append(i)\n break\nprint(len(a))\nprint(\" \".join([str(i) for i in a]))", "n, v = map(int, input().split())\r\nans = []\r\nfor i in range(n):\r\n ll = list(map(int, input().split()))\r\n ll.sort()\r\n if ll[1] < v:\r\n ans.append(i+1)\r\nprint(len(ans))\r\nprint(*ans)\r\n", "[n, v] = list(map(int, input().split(\" \")))\nresult = []\nfor i in range(n):\n t = list(map(int, input().split(\" \")))\n t.pop(0)\n if min(t) < v:\n result.append(i+1)\nprint(len(result))\nprint(*result)\n", "num, limit = map(int, input().split())\r\nl = []\r\nfor i in range(num):\r\n li = list(map(int, input().split()))\r\n if limit > min(li[1:]):\r\n l.append(i + 1)\r\nprint(len(l))\r\nprint(' '.join(map(str, l)))\r\n", "n, m = [*map(int, input().split())]\r\nans = []\r\nfor i in range(n):\r\n a = [*filter(lambda x : x < 0, map(lambda x : int(x) - m, input().split()[1:]))]\r\n if len(a) > 0:\r\n ans.append(i + 1)\r\nprint(len(ans))\r\nfor i in ans:\r\n print(i, end = \" \")\r\nprint()\r\n", "def main():\n n, v = map(int, input().split())\n out = []\n for i in range(n):\n s = list(map(int, input().split()))\n s = s[1:]\n if min(s) < v:\n out.append(i + 1)\n\n print(len(out))\n print(' '.join(str(x) for x in out))\n\nmain()\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Apr 2 19:56:34 2020\r\n\r\n@author: roastedcoder\r\n\r\nThis is for CodeForces\r\n\"\"\"\r\nmod = 1000000007\r\nssi = lambda : map(int,input().split())\r\n\r\n# RoastedCoder\r\n\r\nn,v = ssi()\r\na = []\r\nfor _ in range(n):\r\n s = list(ssi())\r\n k = s[0]\r\n s = s[1:]\r\n s.sort()\r\n if(s[0]<v):\r\n a.append(_+1)\r\nprint(len(a))\r\nfor _ in range(len(a)):\r\n print(a[_],end = ' ')", "l=list(map(int,input().rstrip().split()))\nn=l[0]\nv=l[1]\nres=0\nl2=[]\nfor i in range(n):\n l1=list(map(int,input().rstrip().split()))\n if v>min(l1[1:]):\n res+=1\n l2.append(i+1)\nprint(res)\nfor x in l2:\n print(x,end=\" \")\n \t \t\t \t\t\t \t\t \t\t\t \t\t\t\t", "n,v=[int(i) for i in input().split()]\r\nans=[]\r\nal=0\r\nfor j in range(n):\r\n l=[int(k) for k in input().split()]\r\n l.pop(0)\r\n if min(l)<v:\r\n ans.append(j+1)\r\n al+=1\r\nprint(al)\r\nprint(*ans,sep=\" \")", "#codeforces441A\r\ngi = lambda : list(map(int,input().strip().split()))\r\nn,m = gi()\r\nans = []\r\nfor k in range(n):\r\n\tl = gi()[1:]\r\n\tl.sort()\r\n\tif l[0] < m:\r\n\t\tans.append(k+1)\r\nprint(len(ans))\r\nprint(\" \".join(map(str, ans)))", "n,v=map(int,input().split())\r\nsellers=[]\r\nfor i in range(1,n+1):\r\n if(v>min(list(map(int,input().split()))[1:])):\r\n sellers.append(i)\r\nprint(len(sellers))\r\nfor i in range(len(sellers)):\r\n print(sellers[i],end=\" \")\r\n", "n, v = [int(i) for i in input().split()]\r\nres = []\r\nfor i in range(n):\r\n k, *lst = [int(i) for i in input().split()]\r\n for j in lst:\r\n if j < v:\r\n res.append(str(i + 1))\r\n break\r\nprint(len(res))\r\nprint(\" \".join(res))\r\n", "I=lambda:map(int,input().split());n,v=I();l=[]\r\nfor i in range(n):\r\n k,*s=I()\r\n s.sort()\r\n if v>s[0]:l.append(i+1)\r\nprint(len(l),\"\\n\",*l)", "n,t=map(int,input().split())\r\ncounter=0\r\nposb=[]\r\nfor i in range(n):\r\n s=list(map(int,input().split()))\r\n for j in range(1,len(s)):\r\n if t>s[j] and (i+1) not in posb:\r\n counter+=1\r\n posb.append(i+1)\r\nposb.sort()\r\nprint(counter)\r\nfor i in posb:\r\n print(i, end=' ')\r\n", "X = list(map(int, input().split()))\r\nSellers = list()\r\nfor i in range(X[0]):\r\n Y = list(map(int, input().split()))\r\n for j in range(1, len(Y)):\r\n if Y[j] < X[1]:\r\n Sellers.append(i + 1)\r\n break\r\nprint(len(Sellers))\r\nprint(*Sellers)\r\n", "n,m = map(int,input().split())\r\nans=0\r\nan=[]\r\nfor i in range(n):\r\n lis = list(map(int,input().split()))\r\n if min(lis[1:])<m:\r\n ans+=1\r\n an.append(i+1)\r\nprint(ans)\r\nprint(*an)", "n,c=input().split()\r\nn=int(n)\r\nc=int(c)\r\nl1=[]\r\nfor i in range(n):\r\n l1.append([int(i) for i in input().split()])\r\nl2=[]\r\nfor i in l1:\r\n l2.append(i[1:])\r\nl3=[]\r\nfor i in range(len(l2)):\r\n for j in range(len(l2[i])):\r\n if(l2[i][j]<c):\r\n l3.append(i+1)\r\n break\r\nprint(len(l3))\r\nfor i in l3:\r\n print(i,end=\" \")", "if __name__ == \"__main__\":\n n, v = tuple(map(int, input().split()))\n sellers = list()\n\n for i in range(n):\n l = list(map(int, input().split()))\n k = l[0]\n s = l[1:]\n\n for sk in s:\n if sk < v:\n sellers.append(i + 1)\n break\n\n print(len(sellers))\n print(' '.join(map(str, sellers)))", "n,v=map(int,input().split())\r\nl=[]\r\ncount=0\r\nfor i in range(n):\r\n m=min(list(map(int,input().split()))[1:])\r\n count+=1\r\n if v>m:\r\n l.append(count)\r\nprint(len(l))\r\nprint(*l)", "n,m=map(int,input().split())\r\nans=[]\r\nfor i in range(n):\r\n lst=list(map(int,input().split()))\r\n if m>min(lst[1:]):\r\n ans.append(i+1)\r\nprint(len(ans))\r\nprint(*ans)", "input_arg = [int(i) for i in input().split()]\r\nsellers_num, money = input_arg[0], input_arg[1]\r\nsellers = []\r\nfor i in range(sellers_num):\r\n sellers.append([int(i) for i in input().split()[1:]])\r\nans, ans_sellers = 0, ''\r\nfor i in range(sellers_num):\r\n for j in range(len(sellers[i])):\r\n if money > sellers[i][j]:\r\n ans += 1\r\n ans_sellers += str(i+1) + ' '\r\n break\r\nprint(ans)\r\nprint(ans_sellers[:-1])\r\n", "n,v = [int(i) for i in input().split()]\r\ncount = 0\r\nans = []\r\narr = []\r\nfor _ in range(n):\r\n lst = [int(i) for i in input().split()]\r\n arr.append(lst)\r\n\r\nfor i in range(len(arr)):\r\n for j in range(1,len(arr[i])):\r\n if arr[i][j]<v:\r\n count+=1\r\n ans.append(i+1)\r\n break\r\nans.sort()\r\nprint(count)\r\nfor i in ans:\r\n print(i,end=\" \")", "n,k=map(int,input().split())\r\nlist2=[]\r\nfor i in range(1,n+1):\r\n list1=list(map(int,input().split()))\r\n m=list1[0]\r\n list1=list1[1:]\r\n s=min(list1)\r\n if(s<k):\r\n list2.append(i)\r\nlist2.sort()\r\nprint(len(list2))\r\nprint(*list2)", "#!C:/Python34/python.exe\n\n\nimport itertools as ittls\nfrom collections import Counter\n\ndef inputarray(func = int):\n return map(func, input().split())\n\ndef glen(s):\n return sum(1 for _ in s)\n\n#--------------\n#--------------\n\n\nN, v = map(int, input().split())\n\nres = []\n\nfor i in range(N):\n A = map(lambda x: int(x) < v, input().split())\n B = Counter(ittls.islice(A, 1, None))\n\n if True in B:\n res.append(i)\n\n\nprint(len(res))\nans = ''\nfor i in res:\n ans = ans + str(i + 1) + ' '\nprint(ans)\n", "n, v = map(int, input().split())\r\n\r\ntotal = 0\r\nlist1 = []\r\n\r\nfor i in range(n):\r\n a = list(map(int, input().split()))\r\n a.pop(0)\r\n a.sort()\r\n if v > a[0]:\r\n total += 1\r\n list1.append(i + 1)\r\n \r\nprint (total)\r\n\r\nfor i in range(len(list1)):\r\n print (list1[i], end = ' ')\r\n", "from sys import stdin,stdout\r\n\r\ndata =list(map(int,list(stdin.readline().split(' '))))\r\n\r\nvendors,dinero = data[0],data[1]\r\n\r\ntotal = 0\r\nresultado = list()\r\n\r\nfor n in range(vendors):\r\n\r\n currvendor =list(map(int,list(stdin.readline().split(' '))))\r\n\r\n for m in range(currvendor[0]):\r\n if currvendor[m+1] <dinero:\r\n total +=1\r\n resultado.append(n+1)\r\n break\r\n\r\nprint(total)\r\nresultado = map(str,resultado)\r\nprint(' '.join(resultado))\r\n", "n, v=map(int, input().split())\r\nm=[]\r\na=[]\r\nfor i in range(n):\r\n a.append(input().split())\r\n for j in a[i][1:]:\r\n if int(j) < v:\r\n m.append(i+1)\r\n break\r\nif len(m) ==0:\r\n print(0)\r\nelse: \r\n print(len(m))\r\n for i in m:\r\n print(int(i), end=' ') ", "n , s = map(int,input().split())\r\nq = []\r\nfor i in range(n):\r\n\tk , *si = list(map(int,input().split()))\r\n\tif min(si)<s:q.append(i+1)\r\nprint(len(q))\r\nif len(q)>0:\r\n\tprint(*q)\t", "n, v = map(int, input().split())\r\nsellers = []\r\nfor i in range(n):\r\n k = list(map(int, input().split()))\r\n for j in range(1, len(k)):\r\n if k[j] < v:\r\n sellers.append(i+1)\r\n break\r\nprint(len(sellers))\r\nprint(*sellers)", "def main():\n (n, v) = map(int, input().split(' '))\n r = []\n for i in range(n):\n if v > min(list(map(int, input().split(' ')[1:]))):\n r.append(str(i + 1))\n print(len(r))\n if len(r) > 0:\n print(' '.join(r))\nmain()\n", "n, v = map(int, input().split(sep = ' '))\nl = []\nfor i in range(n):\n k = input().split(sep = ' ')\n a = int(k[0])\n l.append(k[1:a+1])\nm = []\nfor i in l:\n for j in i:\n if int(j) < v:\n m.append(l.index(i) + 1)\n break\nif m.__len__() == 0:\n print(0)\nelse:\n print(m.__len__())\n for i in m:\n print(i, end = \" \")", "n,m=map(int,input().split())\r\np=0\r\nt=\"\"\r\nfor i in range(n):\r\n\tl=list(map(int,input().split()))\r\n\tl=l[1:]\r\n\tl.sort()\r\n\t\r\n\tif l[0]<m:\r\n\t\tp+=1\r\n\t\tt+=str(i+1)+\" \"\r\n\r\n\tl=[]\r\n\t\r\n\r\n\r\n\r\n\r\nprint(p)\r\nprint(t)", "a,d,c=list(map(int,input().split())),0,'';b=[a[1]+1]\r\nfor i in range(a[0]):b.append(min((list(map(int,input().split())))[1:]))\r\nfor i in range(len(b)):\r\n if b[i]<a[1]:d+=1;c+=str(i)+' '\r\nprint(d,'\\n'+c)", "n,v=map(int,input().split(\" \"))\na=list()\nfor i in range(0,n):\n\tl=list(map(int,input().split(\" \")))\n\tb=l[1:]\n\tb.sort()\n\tif(b[0]<v):\n\t\ta.append(i+1)\na.sort()\nprint(len(a))\nif(len(a)>0):\n\tprint(*a)\n\n", "from sys import stdin, stdout\r\n\r\nn,v=map(int,input().split())\r\n\r\narr=[]\r\nar=[]\r\ncount=0\r\nfor __ in range(n):\r\n arr.append(list(map(int,input().split())))\r\nfor i in range(n):\r\n for j in range(1,arr[i][0]+1):\r\n if(v>arr[i][j]):\r\n count+=1\r\n ar.append(i+1)\r\n break\r\nprint(count)\r\nfor i in range(len(ar)):\r\n stdout.write(str(ar[i])+\" \")", "n, v = map(int, input().split())\r\nbid = []\r\nfor i in range(n):\r\n s = list(map(int, input().split()))[1:]\r\n if v > min(s):\r\n bid.append(i + 1)\r\nprint(len(bid))\r\nfor i in bid:\r\n print(i, end=' ')\r\n", "n, m = map(int, input().split())\r\nb = []\r\nfor temp in range(n):\r\n a = list(map(int, input().split()))\r\n y = 1\r\n while y < len(a):\r\n if m > a[y]:\r\n b.append(temp + 1)\r\n break\r\n y += 1\r\nprint(len(b))\r\nprint(*b)", "a=[]\r\na=input().split()\r\nn=int(a[0])\r\nv=int(a[1])\r\ns=[]\r\nfor i in range(0,n):\r\n s.append([int(j) for j in input().split()])\r\nk=[]\r\nfor i in range(0,n):\r\n k.append(s[i][0])\r\n temp=s[i][0]\r\n del s[i][0]\r\nd=[]\r\nfor i in range(0,n):\r\n flag=0\r\n for j in range(0,k[i]):\r\n if(s[i][j]<v):\r\n flag=1\r\n if flag==1:\r\n d.append(i+1)\r\n\r\nd.sort()\r\nprint(len(d))\r\nfor i in range(0,len(d)):\r\n print(d[i],end=' ')\r\n \r\n", "n, v = list(map(int, input().split()))\r\nans = 0\r\nnumbers = []\r\nfor i in range(n):\r\n temp = list(map(int, input().split()))\r\n if v > min(temp[1:]):\r\n ans += 1\r\n numbers.append(i+1)\r\nprint(ans)\r\nfor i in numbers:\r\n print(i, end=\" \")", "R = lambda:list(map(int,input().split()))\r\nn,v = R()\r\nk = []\r\nfor i in range(n):\r\n\th,*l = R()\r\n\tfor j in l:\r\n\t\tif j<v: \r\n\t\t\tk.append(i+1)\r\n\t\t\tbreak\r\nif len(k)==0:print(0)\r\nelse:\r\n\tprint(len(k))\r\n\tprint(*(k))", "r = lambda: map(int, input().split())\r\nn, v = r()\r\na = [str(i+1) for i in range(n) if v > min(list(r())[1:])]\r\nprint(len(a))\r\nprint(\" \".join(a))", "#-------------Program-------------\r\n#----KuzlyaevNikita-Codeforces----\r\n#---------------------------------\r\n\r\nn,v=map(int,input().split())\r\narray=[]\r\nfor i in range(n):\r\n s=list(map(int,input().split()))\r\n k=s[0];del(s[0])\r\n for j in range(k):\r\n if s[j]+1<=v:\r\n array.append(i)\r\n break\r\nprint(len(array))\r\narray.sort()\r\nfor i in range(len(array)):\r\n print(array[i]+1,end=' ')", "n, v = map(int, input().split())\r\nres = []\r\nfor i in range(1, n+1):\r\n li = list(map(int, input().split()))\r\n if min(li[1:])<v:\r\n res.append(i)\r\nres.sort()\r\nif len(res)==0:\r\n print(0)\r\nelse:\r\n print(len(res))\r\n print(\" \".join(map(str, res)))", "n, v = map(int, input().split())\r\nres = []\r\n\r\nfor i in range(n):\r\n lst = list(map(int, input().split()))\r\n\r\n lst_min = min(lst[1:])\r\n\r\n if lst_min < v:\r\n res.append(i+1)\r\n\r\nres.sort()\r\nprint(len(res))\r\nprint(*res)", "n,v=map(int, input().split())\r\ncont=0\r\nres=[]\r\nfor i in range(n):\r\n items=list(map(int, input().split()))\r\n ni=items.pop(0)\r\n for j in range(ni):\r\n if items[j]<v:\r\n cont+=1\r\n res.append(i+1)\r\n break\r\nprint(cont)\r\nprint(\" \".join(map(str, res)))", "n, v = map(int, input().split())\r\nq = []\r\nfor i in range(n):\r\n if v > min(map(int, input().split()[1:])):\r\n q += [str(i+1)]\r\nprint(len(q))\r\nprint(\" \".join(q))", "k, m = map(int, input().split())\n\nli = []\nfor i in range(k):\n li.append([int(i) for i in input().split()][1:])\n\nr = set()\nfor i in range(k):\n for j in li[i]:\n if m > j:\n r.add(i + 1)\n\nprint(len(r))\nprint(*r)\n", "s = input().split()\nn = int(s[0])\nv_money = int(s[1])\nlist = []\nfor i in range(n):\n line = input().split()\n status = False\n for l in range(len(line)-1):\n if (v_money>int(line[l+1])):\n status = True\n if(status):\n list.append(i+1)\nif not list:\n print(0)\nelse:\n print(len(list))\n for i in list:\n print(i, end=\" \")\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\np=[]\r\nfor i in range(n):\r\n\tl=input().split(\" \")\r\n\tl=[int(x) for x in l]\r\n\tl1=l[0]\r\n\tl2=l[1:]\r\n\tfor num in l2:\r\n\t\tif num <m:\r\n\t\t\tp.append(i)\r\n\t\t\tbreak\r\nprint(len(p))\r\nfor i in p:\r\n print(i+1,end=' ')", "n, v = [int(x) for x in input().split()]\r\nans = []\r\nfor i in range(n):\r\n x= min(int(x) for x in input().split()[1:])\r\n if x<v:\r\n ans.append(str(i+1))\r\nprint(len(ans))\r\nprint(' '.join(ans))", "n,m=map(int,input().split());b=[]\r\nfor i in range(n):\r\n\ta=list(map(int,input().split()))[1:]\r\n\tif min(a)<m:b.append(i+1)\r\nprint(len(b))\r\nprint(*b)", "n,v=map(int,input().split())\r\nk=0\r\nb=[]\r\nfor i in range(n):\r\n a=list(map(int,input().split()))\r\n g=a.pop(0)\r\n if min(a)<v:\r\n k+=1\r\n b.append(i+1)\r\nprint(k)\r\nprint(*b)", "n, v = map(int,input().split())\r\nvanz = []\r\ni = 1\r\nwhile (i<=n):\r\n l = list(map(int,input().split()))\r\n if v > min(l[1:]):\r\n vanz.append(i)\r\n i += 1\r\nprint(len(vanz))\r\nfor el in vanz:\r\n print(el, end = ' ' )\r\n", "(n, v) = map(int, input().split(' '))\npotential_deal_with_sellers = []\nfor i in range(n):\n a = list(map(int, input().split(' ')))\n number_of_items = a[0]\n items = a[1:]\n for item in items:\n if item < v:\n potential_deal_with_sellers.append(i + 1)\n break\n\nif len(potential_deal_with_sellers) > 0:\n print(len(potential_deal_with_sellers))\n print(*potential_deal_with_sellers)\nelse:\n print(0)", "n,v=list(map(int,input().split()))\r\nl=[]\r\nfor i in range(n):\r\n l.append(list(map(int,input().split())))\r\nm=[]\r\nfor i in range(n):\r\n if v>min(l[i][1:len(l[i])]):\r\n m.append(i+1)\r\nif len(m)>0:\r\n print(len(m))\r\n for i in range(len(m)-1):\r\n print(m[i],end=' ')\r\n print(m[len(m)-1])\r\nelse:\r\n print(0)", "#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-29 22:52:48\nLastEditTime: 2021-11-29 22:57:43\nDescription: Valera and Antique Items\nFilePath: CF441A.py\n'''\n\n\ndef func():\n n, v = map(int, input().strip().split())\n deal = []\n for i in range(n):\n k, *s = map(int, input().strip().split())\n if v > min(s):\n deal.append(str(i + 1))\n \n print(len(deal))\n print(\" \".join(deal))\n\n\nif __name__ == '__main__':\n func()\n", "n, v = map(int, input().split())\nnl, cnt = [], 0\nfor a in range(n):\n lst = [int(x) for x in input().split()]\n if v > min(lst[1:]):\n nl.append(a + 1)\n cnt += 1\nprint(cnt)\nprint(*nl)\n\t \t\t\t \t\t \t\t\t \t\t\t\t\t\t \t \t \t", "n, v = map(int, input().split())\r\nans = []\r\nfor i in range(n):\r\n a = list(map(int, input().split()))[1:]\r\n if v > min(a):\r\n ans.append(i + 1)\r\nprint(len(ans))\r\nprint(*ans)\r\n", "n, v = map(int, input().split())\r\nnl = []\r\nfor a in range(n):\r\n lst = [int(x) for x in input().split()]\r\n k = lst[0]\r\n del lst[0]\r\n for i in range(k):\r\n if v > lst[i]:\r\n if (a + 1) not in nl:\r\n nl.append(a + 1)\r\nprint(len(nl))\r\nprint(*nl)", "n, v = [int(x) for x in input().split()]\nres= []\nfor i in range(n):\n\tnums = [int(x) for x in input().split()][1:]\n\tm = min(nums)\n\tif m < v: res.append(str(i+1))\nprint(len(res))\nprint(\" \".join(res))", "n,v=[int(x) for x in input().split()]\r\ncount=0\r\nans=[]\r\nfor i in range(n):\r\n price=[int(x) for x in input().split()]\r\n for j in range(1,price[0]+1):\r\n if price[j]<v:\r\n count+=1\r\n ans.append(i+1)\r\n break\r\nprint(count)\r\nfor i in ans:\r\n print(i,end=\" \")\r\n", "t, m = [int(x) for x in input().split()]\r\nd = []\r\n\r\nfor i in range(t):\r\n if min([int(x) for x in input().split()][1:]) < m:\r\n d.append(str(i+1))\r\n\r\nprint(len(d))\r\nprint(' '.join(d))\r\n", "cases, money = map(int, input().split())\r\nans = 0\r\nsellers = []\r\nfor i in range(1, cases+1):\r\n arr = list(map(int, input().split()))\r\n if min(arr[1:]) < money:\r\n ans += 1\r\n sellers.append(i)\r\nprint(ans)\r\nprint(*sellers)\r\n", "N, V = map(int, input().split(' '))\r\n\r\nL = []\r\n\r\nfor i in range(N):\r\n now = list(map(int, input().split(' ')))\r\n for j in range(1, len(now)):\r\n if (now[j] < V):\r\n L.append(str(i + 1))\r\n break\r\n\r\nprint(len(L))\r\n\r\nprint(' '.join(L))\r\n", "n, v = map(int, input().split())\r\nans = []\r\nfor i in range(n):\r\n s = list(map(int, input().split()))[1:]\r\n mn = min(s)\r\n if mn < v:\r\n ans.append(i + 1)\r\nprint(len(ans))\r\nprint(*ans, sep=' ')", "n, v = map(int,input().split())\r\n\r\nans = []\r\n\r\nfor i in range(n):\r\n arr = list(map(int,input().split()))\r\n arr = arr[1:]\r\n if min(arr)<v:\r\n ans.append(i+1)\r\nprint(len(ans))\r\nprint(*ans)", "def solve(n, v, arr):\r\n res = []\r\n for j in range(n):\r\n for i in range(len(arr[j])-1):\r\n if arr[j][i+1] < v:\r\n res.append(str(j+1))\r\n break\r\n return res, len(res)\r\n\r\nn, v = map(int, input().split())\r\narr = []\r\nfor i in range(n):\r\n temp = list(map(int, input().split()))\r\n arr.append(temp)\r\nres, l = solve(n, v, arr)\r\nprint(l)\r\nif len(res) != 0:\r\n for i in range(l):\r\n print(res[i], end=\" \")", "n,s=[int(x) for x in input().split()]\r\narr=[]\r\nfor i in range(n):\r\n x,*l=input().split()\r\n for j in range(int(x)):\r\n if int(l[j])<s:\r\n arr.append(i)\r\n break\r\nprint(len(arr))\r\nfor i in range(len(arr)):\r\n arr[i]+=1\r\nprint(*arr)", "n,v = list(map(int,input().split()))\r\n\r\nres=[]\r\n\r\nfor i in range(n):\r\n l=list(map(int,input().split()))\r\n \r\n t=list(filter(lambda x: x<v,l[1:]))\r\n \r\n if t!=[]:\r\n res.append(i+1)\r\n \r\nprint(len(res))\r\nres.sort()\r\nprint(*res)\r\n ", "\r\ninp = lambda: map(int, input().split())\r\nn, v = inp()\r\na = [str(i+1) for i in range(n) if v > min(list(inp())[1:])]\r\nprint(len(a))\r\nprint(\" \".join(a))", "n, d = input().split()\nn = int (n)\nd = int (d)\n#n = int(input())\n#h = list(map(int, input().split()))\n#g = list(map(int, input().split()))\n#x1, y1, x2, y2 =map(int,input().split())\n#n = int(input())\n# = [\"\"]*n\ns = 0\nt = \"\"\nfor i in range(n):\n h = list(map(int, input().split()))\n h = sorted(h)\n if (h[1] < d):\n s+= 1\n t += str(i+1)+\" \"\n\nprint(s)\nif (s != 0):\n print(t)\n\n", "n,v = map(int,input().split())\r\nl = []\r\nwhile n>0:\r\n li = list(map(int,input().split()))\r\n l.append(li)\r\n n-=1\r\ncnt = 0\r\ns = ''\r\nfor i in range(len(l)):\r\n for j in range(1,l[i][0]+1):\r\n if l[i][j]<v:\r\n cnt+=1\r\n s += str(i+1) + ' '\r\n break\r\n else:\r\n pass\r\nprint(cnt)\r\nprint(s)\r\n", "n, p = map(int,input().split())\r\nt = []\r\nfor x in range(n):\r\n l = list(map(int,input().split()))\r\n l.pop(0)\r\n if min(l) < p:\r\n t.append(x+1)\r\n\r\nprint(len(t))\r\nprint(' '.join([str(elem)for elem in t]))", "#n = int(input())\r\nn, m = map(int, input().split()) \r\n#s = input()\r\na = []\r\nfor j in range(n):\r\n c = list(map(int, input().split()))\r\n for i in range(c[0]):\r\n if c[i + 1] < m:\r\n a.append(j + 1)\r\n break\r\nprint(len(a))\r\nprint(*a)", "n, v = (int(i) for i in input().split())\r\nc = 0\r\na = []\r\nfor i in range(n):\r\n l = [int(i) for i in input().split()]\r\n if v > min(l[1:]):\r\n c += 1\r\n a.append(i + 1)\r\nprint(c)\r\nif c > 0:\r\n print(\" \".join(str(s) for s in a))", "n,v = map(int,input().split(' '))\r\nres = []\r\n\r\nfor i in range(n):\r\n arr = [int(i) for i in input().split(' ')]\r\n for j in range(1,arr[0]+1):\r\n if(arr[j] < v):\r\n res.append(i+1)\r\n break\r\n\r\nprint(len(res))\r\nfor i in res:\r\n print(i, end=' ')\r\n", "n,m=map(int,input().split())\r\nc=0\r\np=[]\r\nfor i in range(1,n+1):\r\n l=list(map(int,input().split()))\r\n l=sorted(l)\r\n if(l[1]<m):\r\n p.append(i)\r\nprint(len(p))\r\nprint(*p)\r\n ", "n, v = [int(i) for i in input(). split()]\r\ns = [[] for i in range(50)]\r\nq = []\r\np = 0\r\nfor i in range(n):\r\n s[i] = [int(x) for x in input(). split()]\r\n s[i].pop(0)\r\n if min(s[i]) < v:\r\n p += 1\r\n q.append(i + 1)\r\nprint(p)\r\nprint(*q)", "n,v = map(int,input().split())\r\nans = []\r\nfor i in range(n):\r\n p = list(map(int,input().split()))[1:]\r\n if min(p)<v:\r\n ans.append(i+1)\r\n\r\nprint(len(ans))\r\nprint(*ans)\r\n", "n,v=map(int,input().split())\r\np=[i+1 for i in range(n)if min(map(int,input().split()[1:]))<v]\r\nprint(len(p))\r\nprint(*p)", "n,v = map(int,input().split())\r\nl1 = []\r\ncount = 0\r\nfor i in range(n):\r\n l = list(map(int,input().split()))\r\n l.sort()\r\n if l[1]<v:\r\n count+=1\r\n l1.append(i+1)\r\nprint(count)\r\nfor ele in l1:\r\n print(ele,end = \" \")\r\n", "n, m = map(int, input().split())\r\nb = [i + 1 for i in range(n) if min(tuple(map(int, input().split()))[1:]) < m]\r\nprint(len(b), *b)\r\n", "n,v=map(int, input().split())\r\nl=[]\r\nfor i in range(n):\r\n a=[]\r\n a=list(map(int, input().split()))\r\n l.append(a)\r\nnew=[]\r\nfor i in l:\r\n for j in range(i[0]):\r\n if i[j+1]<v:\r\n new.append(l.index(i))\r\n break\r\nprint(len(new))\r\nif len(new)!=0:\r\n for i in new:\r\n print(i+1,end=\" \")\r\n print(\"\")\r\n ", "n, v = [int(x) for x in input().split()]\nans = []\nfor i in range(n):\n\tx = min(int(x) for x in input().split()[1:])\n\tif x < v:\n\t\tans.append(str(i + 1))\nprint(len(ans))\nprint(' '.join(ans))\n", "n,v=[int(x) for x in input().split()] \r\ni=1\r\nb=[]\r\nsum1=0\r\nwhile(i<=n):\r\n arr=[int(x) for x in input().split()]\r\n flag=False\r\n for j in range(1,arr[0]+1):\r\n if arr[j]<v:\r\n flag=True\r\n \r\n if(flag):\r\n sum1=sum1+1\r\n b.append(i)\r\n i=i+1\r\nprint(sum1)\r\nfor k in b:\r\n print(k,end=\" \")", "n, v = map(int, input().split())\ncount = 0\nslist = []\nfor i in range(n):\n _, *l = map(int, input().split())\n for j in l:\n if v > j:\n slist.append(i+1)\n count += 1\n break\nprint(count)\nfor x in slist:\n print(x, end=' ')\n \t\t \t \t\t\t\t \t \t \t \t\t\t\t \t\t \t", "n, v = map(int, input().split())\ncontact = []\nfor slr in range(n):\n\tslr_val = [int(x) for x in input().split()]\n\tfor i in range(1, slr_val[0] + 1):\n\t\tif slr_val[i] < v:\n\t\t\tcontact.append(slr + 1)\n\t\t\tbreak\nprint(len(contact))\nif len(contact): print(*contact)\n \t \t\t \t\t\t \t \t \t\t \t \t\t", "n,v = map(int, input().split())\r\n\r\ncan = []\r\n\r\n\r\nfor i in range(1,n+1):\r\n prices = list(map(int, input().split()))\r\n prices = prices[1:]\r\n for j in prices:\r\n if j < v:\r\n can.append(str(i))\r\n break\r\n\r\nprint(len(can))\r\nif len(can) > 0:\r\n print(*can)\r\n", "\n\ndef inpNum(): return int(input())\ndef inpNums(): return map(int,input().split())\ndef inpList(): return list(map(int,input().split()))\ndef inpMatrix(rows): return [list(map(int, input().split())) for _ in range(rows)]\n\n\n\n\nn,v = inpNums()\ns = []\nm = inpMatrix(n)\nfor i in range(n):\n for j in m[i][1:]:\n if j<v:\n s.append(i+1)\n break\nprint(len(s))\nprint(*s)", "n,v = map(int, input().split())\r\nc = 0\r\np = []\r\nfor i in range(n):\r\n L = input().split()\r\n mi = 1000000\r\n for j in range(1,int(L[0])+1):\r\n if int(L[j]) < mi:\r\n mi = int(L[j])\r\n if mi < v:\r\n c += 1\r\n p.append(i+1)\r\nprint(c)\r\nif c > 0:\r\n print(*p,sep=' ')", "s = input().split()\r\na = int(s[0])\r\nb = int(s[1])\r\nmat=[]\r\nfor i in range(a):\r\n sk = input().split()\r\n n = list(sk[1::])\r\n for j in range(len(n)):\r\n n[j]=int(n[j])\r\n if n[j]<b:\r\n if not i+1 in mat:\r\n mat.append(i+1)\r\n break\r\nmat=sorted(mat)\r\nif len(mat)==0:\r\n print(0)\r\nelse:\r\n print(len(mat))\r\n for i in mat:\r\n print(i,end=' ')\r\n", "n,v = map(int, input().split())\na=[]\ncount=0\nfor i in range(1,n+1):\n k=list(map(int, input().split()))\n s=k[1:]\n x=sorted(s)\n if x[0]<v:\n count+=1 \n a.append(str(i))\nprint(count)\nprint(\" \".join(a))", "s = input().split()\r\nn, v = int(s[0]), int(s[1])\r\np = 0\r\nans = []\r\nfor i in range(n):\r\n s = input().split()\r\n k = int(s[0])\r\n for j in range(k):\r\n if int(s[j + 1]) < v:\r\n p = p + 1\r\n ans.append(i + 1)\r\n break\r\nprint(p)\r\nprint(*ans, sep = ' ')", "n, v = [int(x) for x in input().split(' ')]\r\nans = []\r\nfor i in range(n):\r\n ks = [int(x) for x in input().split(' ')]\r\n if v > min(ks[1:]):\r\n ans.append(i + 1)\r\nprint(len(ans))\r\nprint(*ans)", "n,v=list(map(int,input().split()))\r\nc=0\r\nb=[]\r\nfor i in range(n):\r\n\ts=list(map(int,input().split()))\r\n\tk=s[0]\r\n\ts=s[1:]\r\n\tfor j in range(len(s)):\r\n\t\tif s[j]<v:\r\n\t\t\tc+=1\r\n\t\t\tb.append(i+1)\r\n\t\t\tbreak\r\nif c==0:\r\n\tprint(0)\r\nelse:\r\n\tprint(c)\r\n\tprint(*b)", "st=[int(i) for i in input().split(\" \")]\r\nn=st[0]\r\nv=st[1]\r\nb=[]\r\nk=0\r\na=[]\r\nfor i in range(n):\r\n k=0\r\n a=[int(n) for n in input().split()]\r\n a=a[1:]\r\n for j in range(len(a)):\r\n if a[j]<v:\r\n k+=1\r\n if k>0:\r\n b.append(i+1)\r\nprint(len(b))\r\nif len(b)!=0:\r\n for i in range(len(b)):\r\n print(b[i],sep=\" \",end=\" \")\r\n", "a, b = map(int, input().split())\r\nx = 0\r\nh = []\r\nfor i in range(0, a):\r\n d = list(map(int, input().split()))\r\n for l in range(1, d[0] + 1):\r\n if d[l] < b:\r\n x += 1\r\n h.append(i + 1)\r\n break\r\n\r\nprint(x)\r\nprint(*h)", "n, v = map(int, input().split())\r\nsellers = []\r\n\r\nfor i in range(n):\r\n k, *prices = map(int, input().split())\r\n min_price = min(prices)\r\n \r\n if min_price < v:\r\n sellers.append(i + 1)\r\n\r\nprint(len(sellers))\r\nif len(sellers) > 0:\r\n print(*sellers)\r\nelse:\r\n print()\r\n", "n,v = map(int,input().split())\r\nout = []\r\nfor i in range(n):\r\n items = list(map(int,input().split()))\r\n k = items[0]\r\n items = sorted(items[1:])\r\n if items[0]<v:\r\n out.append(i+1)\r\nprint(len(out))\r\nprint(*out)", "n,v=map(int,input().split())\r\nans=0\r\nansl=[]\r\nfor i in range(n):\r\n p=list(map(int,input().split()))\r\n ele=min(p[1:])\r\n if ele<v:\r\n ans+=1\r\n ansl.append(i+1)\r\nprint(ans)\r\nprint(*ansl)", "n,v=map(int,input().split())\r\norder=[]\r\nfor i in range(n):\r\n a=list(map(int,input().split()))\r\n a.pop(0)\r\n for j in a:\r\n if j<v:\r\n order.append(i+1)\r\n break\r\nprint(len(order))\r\nfor i in order:print(i,end=\" \")\r\n", "m , sum = map(int,input().split())\r\noutput = []\r\nfor i in range(m):\r\n if min(tuple(map(int,input().split()))[1:])<sum:\r\n output.append(i+1)\r\nif len(output)>0:\r\n print(len(output))\r\n print(*output)\r\nelse:\r\n print(0)", "line = [int(i) for i in str(input()).split()]\r\nsellers = []\r\nfor i in range(line[0]):\r\n linei = [int(i) for i in str(input()).split()[1:] if line[1]>int(i)]\r\n if len(linei)>0:\r\n sellers.append(i+1)\r\n\r\nprint(len(sellers))\r\nprint(\" \".join([str(i) for i in sellers]))", "n, v= map(int, input().split())\r\n\r\nar=[]\r\n\r\nfor i in range(n):\r\n ar.append(list(map(int, input().split())))\r\n\r\nbuyers=[]\r\nfor i in range(n):\r\n for j in range(1, len(ar[i])):\r\n if ar[i][j] < v:\r\n buyers.append(i+1)\r\n break\r\n\r\nprint(len(buyers))\r\nprint(*buyers)", "import sys, collections, math, itertools, random\r\nINF = sys.maxsize\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef get_array(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef input(): return sys.stdin.readline().strip()\r\nmod = 1000000007\r\n\r\nn,s = get_ints()\r\nans = []\r\nfor i in range(n):\r\n arr = get_array()\r\n mn = min(arr[1:])\r\n if s > mn:\r\n ans.append(i+1)\r\nprint(len(ans))\r\nprint(*ans)", "val = [int(n) for n in input().split()]\r\nn = val[0]\r\ns = val[1]\r\nselectedVendors = []\r\nfor i in range(n):\r\n vendor = [int(n) for n in input().split()]\r\n items = vendor[0]\r\n for j in range(1,items+1):\r\n if vendor[j] < s: \r\n selectedVendors.append(i+1)\r\n break\r\nprint(len(selectedVendors))\r\nrawSelectedVendors = \"\"\r\nfor vendor in selectedVendors:\r\n rawSelectedVendors += str(vendor) + \" \"\r\nprint(rawSelectedVendors)", "n , max = [int(x) for x in input().split()]\r\nnew = []\r\nfor _ in range(n):\r\n li = [int(x) for x in input().split()]\r\n new.append([li[0] , sorted(li[1:])])\r\n#print(new)\r\noutput = 0\r\noutputlist = \"\"\r\nfor _ in range(n):\r\n if new[_][1][0] < max:\r\n output += 1\r\n outputlist += str(_+1) + \" \"\r\nprint(output)\r\nprint(outputlist)", "n,p=[int(i) for i in input().split()]\r\nc=0\r\nz=[]\r\nfor i in range(n):\r\n a=[int(i) for i in input().split()]\r\n v=a[1:]\r\n if p>min(v):\r\n c+=1\r\n z.append(i+1)\r\nprint(c)\r\nif len(z)>0:\r\n for i in z:\r\n print(i,end=\" \")", "def logic(n,arr):\r\n pass\r\n\r\n\r\ndef main():\r\n n, k = map(int, input().split())\r\n res = []\r\n for i in range(n):\r\n arr = sorted(list(map(int, input().split()))[1:])\r\n if arr[0] < k:\r\n res.append(i+1)\r\n print(len(res))\r\n print(*res)\r\n\r\n\r\n \r\n\r\nif __name__ == \"__main__\":\r\n main()", "n,v=map(int,input().split())\r\nc=0\r\no=[]\r\nfor i in range(n):\r\n a=list(map(int,input().split()))\r\n for j in range(1,a[0]+1):\r\n if(a[j]<v):\r\n c+=1\r\n o.append(i+1)\r\n break\r\nprint(c)\r\nfor k in o:\r\n print(k,end=\" \")", "[n, v] = input().split()\r\narr = []\r\nv = int(v)\r\nfor i in range(int(n)):\r\n a = input().split()\r\n a.pop(0)\r\n for el in a:\r\n if int(el) < v:\r\n arr.append(i+1)\r\n break\r\nprint(len(arr))\r\nfor el in arr:\r\n print(el,end=\" \")\r\n", "n,p_=map(int,input().split())\r\narray=[]\r\nfor i in range(n):\r\n array.append(list(map(int, input().split())))\r\nc=0\r\na=[]\r\nfor j in range(n):\r\n for k in range(array[j][0]):\r\n if p_>array[j][k+1]:\r\n c+=1\r\n a.append(j+1)\r\n break\r\nprint(c)\r\nfor l in range(1,c+1):\r\n print(a[l-1],end=\" \")", "#A. Valera and Antique Items\r\nn,v = [int(x) for x in input().split()]\r\nitems = []\r\nfor _ in range(n):\r\n item = [int(x) for x in input().split()]\r\n items += [item]\r\n\r\nsell_idx = []\r\n\r\nfor i in range(len(items)):\r\n for j in range(len(items[i])):\r\n if j == 0:continue\r\n if items[i][j] < v:\r\n sell_idx.append(i+1)\r\n break\r\n\r\nprint(len(sell_idx))\r\nprint(\" \".join([str(x) for x in sell_idx])) ", "v,m=map(int,input().split())\r\nans=[]\r\nfor i in range(v):\r\n aa=sorted(list(map(int,input().split()))[1:])\r\n if aa[0]<m: ans.append(i+1)\r\nprint(len(ans))\r\nprint(*ans)", "array=list(map(int, input(). strip(). split()))\r\nn = array[0]\r\nv = array[1]\r\nseller = []\r\nfor i in range(n) :\r\n s = list(map(int, input(). strip(). split()))\r\n seller.append(s)\r\n\r\n\r\ns_no = []\r\nfor i in seller:\r\n for j in i[1:] :\r\n if j < v :\r\n s_no.append(seller.index(i) + 1)\r\n break\r\nprint(len(s_no))\r\nprint(*s_no)", "n, v = map(int, input().split())\r\nsellers = []\r\ncount=0\r\nfor j in range(n):\r\n l = [int(x) for x in input().split()]\r\n for i in range(1, l[0]+1):\r\n if(v>l[i]):\r\n sellers.append(j+1)\r\n count+=1\r\n break\r\nprint(count)\r\nfor x in sellers:\r\n print(x, end = \" \")\r\n \r\n", "n, v = map(int, input().split())\r\nbids = list()\r\nprice = list()\r\nfor i in range(n):\r\n p = list(map(int, input().split()))\r\n p.pop(0)\r\n if v > min(p):\r\n bids.append(i + 1)\r\n\r\nprint(len(bids))\r\nprint(*bids)\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\nn, v = map(int, input().split())\r\nd = []\r\nc = 0\r\nfor _ in range(n):\r\n w = list(map(int, input().split()))\r\n a = w[0]\r\n b = sorted(w[1:])\r\n c += 1\r\n if b[0] < v:\r\n d.append(c)\r\nprint(len(d))\r\nprint(*sorted(d))", "n,v=map(int,input().split())\r\ncnt=0\r\nans=[]\r\n\r\nfor i in range(1,n+1):\r\n arr=list(map(int,input().split()))\r\n smallest=10**7\r\n for j in range(1,arr[0]+1):\r\n if arr[j]<smallest:\r\n smallest=arr[j]\r\n\r\n if v>smallest:\r\n cnt+=1\r\n ans.append(i)\r\nprint(cnt)\r\n\r\nfor i in ans:\r\n print(i,end=' ')\r\n\r\n", "n, m = map(int, input().split())\nb = []\nfor i in range(n):\n if min(list(map(int, input().split()))[1:]) < m:\n b.append(i + 1)\nif len(b) == 0: print(0)\nelse: print(len(b), '\\n', *b)\n ", "n, v = map(int, input().split())\r\nprice = []\r\nfor _ in range(n):\r\n b = list(map(int, input().split()))\r\n price.append(b[1:])\r\n\r\ncount, op = 0, []\r\nfor i in price:\r\n for j in i:\r\n if j<v:\r\n count += 1\r\n op.append(price.index(i)+1)\r\n break\r\nprint(count)\r\nfor k in op:\r\n print(k, end=\" \")", "n, v = map(int,input().split())\r\ns = 0\r\nindex = ''\r\nfor i in range(n):\r\n seller = list(map(int,input().split()))\r\n for j in range(1,1 + seller[0]):\r\n if seller[j] < v :\r\n s += 1\r\n index += str(i+1) + ' '\r\n break\r\nprint(s)\r\nprint(index[:-1])", "n, m = [int(i) for i in input().split()]\r\nans = []\r\nfor i in range(n):\r\n if any(m > int(k) for k in input().split()[1:]):\r\n ans.append(i + 1)\r\nprint(len(ans))\r\nprint(*ans)\r\n", "# LUOGU_RID: 101569367\n(n, v), *t = [[*map(int, s.split())] for s in open(0)]\r\nans = [i + 1 for i in range(n) if min(t[i][1:]) < v]\r\nprint(len(ans))\r\nprint(*ans)", "n,v=map(int,input().split())\r\nz=[]\r\nfor i in range(n):\r\n l=list(map(int,input().split()))\r\n for j in range(1,len(l)):\r\n if l[j]<v:\r\n z.append(i+1)\r\n break\r\nif len(z)==0:\r\n print(0)\r\nelse:\r\n print(len(z))\r\n print(*z)", "n,v=map(int,input().split())\r\nmat=[];arr=[]\r\nfor i in range(n):\r\n mat.append(list(map(int,input().split())))\r\nfor i in range(len(mat)):\r\n for j in range(1,mat[i][0]+1):\r\n if mat[i][j]<v:\r\n arr.append(i+1)\r\n break\r\nprint(len(arr))\r\nfor i in arr:\r\n print(i,end=\" \")", "n,v = map(int,input().split())\nl1 = []\nfor i in range(n):\n\tk = list(map(int,input().split()))\n\tif min(k[1:]) < v:\n\t\tl1.append(i+1)\n\nprint(len(l1))\nprint(*l1)\n\n", "def main():\r\n s=input()\r\n s=s.split()\r\n n=int(s[0])\r\n v=int(s[1])\r\n arr=[]\r\n aa=1\r\n while(n):\r\n s=input()\r\n s=s.split()\r\n x=int(s[0])\r\n c=1\r\n while(c<len(s)):\r\n if(int(s[c])<v):\r\n arr.append(aa)\r\n break\r\n c+=1\r\n n-=1\r\n aa+=1\r\n print(len(arr))\r\n s=\"\"\r\n for i in arr:\r\n s+=str(i)\r\n s+=' '\r\n print(s)\r\nif __name__ == '__main__':main()\r\n\r\n\r\n\r\n", "n,v = map(int,input().split())\r\ns = [i for i in range(1,n + 1)if v > min(map(int,input().split()[1:]))]\r\nprint(len(s))\r\nprint(*s)", "n , v = map(int, input().split())\r\nb = list()\r\nfor i in range(n):\r\n a = list(map(int, input().split()))\r\n x = a[0]\r\n c = 0\r\n a.remove(a[0])\r\n for j in range(len(a)):\r\n if(v>a[j]):\r\n b.append(i+1)\r\n c = 1\r\n break\r\n else:\r\n c = 0\r\nlength = len(b)\r\nif(length == 0):\r\n print(\"0\")\r\nelse:\r\n print(length)\r\n print(*b)\r\n \r\n\r\n", "from collections import defaultdict\r\nfrom operator import inv\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inps():\r\n return(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\nn, p = invr()\r\nsellers = []\r\nfor i in range(n):\r\n items = inlt()\r\n sellers.append(items[1:])\r\n\r\n#print(sellers)\r\nans = []\r\ncount = 0\r\n\r\nfor idx, seller in enumerate(sellers):\r\n for price in seller:\r\n if price < p:\r\n ans.append(str(idx+1))\r\n count += 1\r\n break\r\n\r\nprint(count)\r\nprint(\" \".join(ans))", "n,v=map(int,input().split())\r\nm=[]\r\nfor i in range(n):\r\n l=list(map(int,input().split()))\r\n l=l[1:]\r\n for j in l:\r\n if(j<v):\r\n m.append(i+1)\r\n break\r\nm.sort()\r\nprint(len(m))\r\nprint(\" \".join(str(x) for x in m))\r\n \r\n\r\n \r\n", "\"\"\"Problem: http://codeforces.com/problemset/problem/441/A\"\"\"\r\n\r\nn, v = list(map(int, input().strip().split(\" \")))\r\n\r\nsellers = list()\r\n\r\nfor i in range(0, n):\r\n\r\n\titems = list(map(int, input().strip().split(\" \")))[1:]\r\n\r\n\tfor item in items:\r\n\t\tif item < v:\r\n\t\t\tsellers.append(i + 1)\r\n\t\t\tbreak\r\n\r\n\r\nnumber_sellers = len(sellers)\r\n\r\nprint(number_sellers)\r\n\r\nif number_sellers > 0:\r\n\tprint(*sellers, sep=\" \")", "n,m=map(int,input().split())\r\ns=set()\r\nfor x in range(n):\r\n l=[int(v) for v in input().split()]\r\n for i in l[1:]:\r\n if m>i:\r\n s.add(x+1)\r\nl1=sorted(list(s))\r\nif len(l1)>=1:\r\n print(len(l1))\r\n for i in l1:\r\n print(i,end=\" \")\r\nelse: print(0) \r\n \r\n", "import sys\ninput = sys.stdin.readline\n\nn, v = map(int, input().split())\nans = []\nfor i in range(n):\n prices = list(map(int, input().split()))\n if v > min(prices[1:]):\n ans.append(i+1)\n\nprint(len(ans))\nprint(*sorted(ans))\n", "n,v = map(int,input().split())\nl = []\nfor i in range(n):\n ll = input().split()\n ll.pop(0)\n l.append(list(map(int,ll)))\ncount = 0\nans = []\nfor i in range(n):\n if any(x<v for x in l[i]):\n count= count+1 \n ans.append(i+1)\nif count == 0:\n print(count)\nelse:\n print(count)\n for i in range(len(ans)):\n print(ans[i],end=' ')\n", "a = (int(x) for x in input().split())\r\np = next(a)\r\nv = next(a)\r\nres = []\r\n\r\nfor i in range(1, p+1):\r\n if len([x for x in (int(a) for a in input().split()[1:]) if x < v]) >= 1: res.append(str(i))\r\n\r\nprint(len(res), '\\n', ' '.join(res))\r\n", "n,w = map(int,input().split())\r\ns = 0\r\nset_ = []\r\nfor i in range(n):\r\n a = list(map(int,input().split()))\r\n for j in range(1,len(a)):\r\n if (w > a[j]):\r\n set_.append(i+1)\r\n s = s + 1\r\n break\r\nprint(s)\r\nprint(*set_)", "nof,budget = map(int,input().split())\r\ns = [str(i+1) for i in range(nof) if budget > min(list(map(int,input().split()))[1:])]\r\nprint(len(s))\r\nprint(\" \".join(s))\r\n", "n, v = (int(i) for i in input().split())\r\nresults = []\r\nfor i in range(n):\r\n data = [int(j) for j in input().split()]\r\n if min(data[1:]) < v:\r\n results.append(i + 1)\r\nprint(len(results))\r\nif len(results) > 0:\r\n print(\" \".join(str(s) for s in results))", "n, v = map(int, input().split())\r\nk = [str(i+1) for i in range(n) if [x for x in list(map(int, input().split()))[1:] if x < v]]\r\nprint(len(k))\r\nprint(' '.join(k))\r\n", "from sys import stdin\r\n\r\ndef main():\r\n '''\r\n Name KevinSS\r\n Code: A. Valera and Antique Items\r\n '''\r\n inp = stdin\r\n n, v = map(int, inp.readline().strip().split())\r\n dicti = dict()\r\n sellers = list()\r\n \r\n for i in range(1,n+1):\r\n a = str(i)\r\n Items = [int(x) for x in inp.readline().strip().split()]\r\n dicti[a] = Items\r\n \r\n for i in range(1,n+1):\r\n flag = False\r\n for j in range(1,len(dicti[str(i)])):\r\n if (dicti[str(i)][j] < v) and flag == False:\r\n sellers.append(str(i))\r\n flag = True\r\n print(len(sellers))\r\n print(' '.join(sellers))\r\n\r\n \r\n\r\n \r\nmain()\r\n", "n,v=map(int,input().split())\r\nans=[]\r\nfor i in range(n):\r\n a=list(map(int,input().split()))\r\n a=a[1:]\r\n if min(a)<v:\r\n ans.append(i+1)\r\nif len(ans)==0:\r\n print(0)\r\nelse:\r\n print(len(ans))\r\n print(*ans)", "n , k = map(int , input().split())\r\nans = []\r\nr = lambda : list(map(int, input().split()))\r\nfor x in range(n):\r\n seller , *prices = r()\r\n if any(i<k for i in prices): ans.append(x+1)\r\n\r\n\r\nprint(len(ans))\r\nprint(*ans)", "n,m = map(int,input().split())\r\ns = [i+1 for i in range(n) if(min(list(map(int,input().split()[1:])))<m)]\r\n\t\t\r\nprint(len(s))\r\nprint(*s)\r\n", "if __name__ == '__main__':\r\n\tn, v = [int(i) for i in input().split()]\r\n\tsellerList = []\r\n\tfor i in range(0, n):\r\n\t\tsellerList.append([int(i) for i in input().split()])\r\n\r\n\tsellerDealList = []\r\n\tfor i, j in enumerate(sellerList):\r\n\t\tif v > min(j[1:]): sellerDealList.append(str(i + 1))\r\n\r\n\tprint(f'{len(sellerDealList):d}\\n{\" \".join(sellerDealList):s}')", "from sys import stdin,stdout\r\nfrom collections import deque\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\ndef solve():\r\n n,v=mp()\r\n ans=[]\r\n for i in range(1,n+1):\r\n l=li()\r\n if min(l[1:])<v:\r\n ans.append(i)\r\n print(len(ans))\r\n print(*sorted(ans))\r\n \r\n\r\nfor _ in range(1):\r\n solve()\r\n", "n,t=map(int,input().split())\r\ncount=0\r\nposb=[]\r\nfor i in range(n):\r\n s=list(map(int,input().split()))\r\n for j in range(1,len(s)):\r\n if t>s[j] and (i+1) not in posb:\r\n count+=1\r\n posb.append(i+1)\r\nposb.sort()\r\nprint(count)\r\nfor i in posb:\r\n print(i, end=' ')\r\n", "\r\nn, v = map(int, input().split())\r\ncount = 0\r\nres = []\r\n\r\ndef f(a):\r\n for k in a:\r\n if v > k:\r\n return True\r\n return False\r\n\r\nfor i in range(n):\r\n a = list(map(int, input().split(' ')))\r\n a.pop(0)\r\n if f(a):\r\n count += 1\r\n res.append(i+1)\r\n \r\nprint(count)\r\nprint( ' '.join(str(e) for e in res) )\r\n", "n,v = map(int,input().split())\r\na = []; k = 0; p=0\r\nfor i in range(n):\r\n b = list(map(int,input().split()))\r\n del(b[0]); b.sort()\r\n for j in range(len(b)):\r\n if b[j] < v: \r\n p += 1\r\n else:\r\n break\r\n if p > 0:\r\n k += p; a.append(i+1); p = 0\r\nif len(a) == 0:\r\n print(0,\"\\n\")\r\nelse:\r\n print(len(a))\r\n print(*a)", "n,v = list(map(int,input().split()))\r\nsellers = []\r\nfor i in range(n):\r\n auctions = list(map(int,input().split()))\r\n k = auctions[0]\r\n for j in range(k):\r\n if(v > auctions[1+j]):\r\n sellers.append(str(i+1))\r\n break\r\nprint(len(sellers))\r\nprint(' '.join(sellers))\r\n", "n, k = map(int, input().split())\n\nr = []\nfor i in range(n):\n m, *ls = list(map(int, input().split()))\n for l in ls:\n if l < k:\n r.append(i + 1)\n break\n\nprint(len(r))\nprint(' '.join(map(str, r)))\n", "n,v = map(int,input().split())\r\ncnt=0\r\nt=[]\r\nnum=0\r\nfor i in range(n):\r\n arr=list(map(int,input().split()))\r\n x = arr.pop(0)\r\n s = min(arr)\r\n num+=1\r\n if s<v:\r\n t.append(num)\r\n cnt+=1\r\nprint(cnt)\r\nif cnt>0:\r\n for i in range(len(t)):\r\n print(t[i],end=\" \")\r\n", "'''\r\nCreated on ١٠‏/١٢‏/٢٠١٤\r\n\r\n@author: mohamed265\r\n'''\r\nt = input().split()\r\nn = int (t[0])\r\nmo = int(t[1])\r\nlis = []\r\nfor i in range(n):\r\n t = input().split()\r\n flag = False\r\n for j in range(int(t[0])):\r\n if mo > int(t[j + 1]):\r\n flag = True\r\n if flag:\r\n lis.append(i + 1)\r\n # print(i+1,end = ' ')\r\nprint(len(lis))\r\nfor i in range(len(lis)):\r\n print(lis[i] , end=' ')\r\n", "n,v = map(int,input().split())\r\nl =[]\r\nseller=[]\r\nc=0\r\nfor item in range(n):\r\n l1 = list(map(int,input().split()))\r\n l1.remove(l1[0])\r\n l.append(l1)\r\n\r\n\r\nfor index,item in enumerate(l):\r\n for itemm in item:\r\n if(v>itemm):\r\n c+=1\r\n seller.append(index)\r\n break\r\nseller.sort()\r\nprint(c)\r\nfor item in seller:\r\n print(item+1,end=\" \")\r\n \r\n\r\n# a= list(map(int,input().split()))\r\n# count=0\r\n# if(item+k <=5):\r\n# count+=1\r\n# print(count//3)\r\n ", "x,y=map(int,input().split())\r\np=[]\r\nk=0\r\nfor i in range(x):\r\n t=list(map(int,input().split()))\r\n t=min(t[1:])\r\n if y>t:\r\n k+=1\r\n p.append(i+1)\r\nprint(k)\r\nprint(*p)", "n, v = map(int, input().split())\r\nd = []\r\nsn = 1\r\nwhile n:\r\n n -= 1\r\n temp = list(map(int, input().split()))\r\n if v > min(temp[1:]):\r\n d.append(sn)\r\n sn += 1\r\nprint(len(d))\r\nif len(d) != 0:\r\n print(*d)\r\n###### thanking telegram for solutions ######\r\n'''__________ ____ ___ _____________ __.___\r\n\\______ \\ | \\/ _____/ |/ _| |\r\n | _/ | /\\_____ \\| < | |\r\n | | \\ | / / \\ | \\| |\r\n |____|_ /______/ /_______ /____|__ \\___|\r\n'''\r\n", "n, v = map(int, input().split())\nmatrix = []\nfor _ in range(n):\n matrix.append(list(map(int, input().split())))\n\ncount = 0\nresult = []\nfor i, row in enumerate(matrix):\n for cell in row[1:]:\n if cell < v:\n count += 1\n result.append(i+1) \n break\n\nprint(count)\nprint(*result)", "n, m = map(int, input().split())\nb = []\nfor i in range(n):\n if min(list(map(int, input().split()))[1:]) < m:\n b.append(i + 1)\nprint(len(b), '\\n', *b)", "n,k=map(int,input().split())\r\nz=[]\r\ncount=0\r\nfor i in range(1,n+1):\r\n\tl=list(map(int,input().split()))\r\n\tfor j in range(1,l[0]+1):\r\n\t\tif l[j]<k:\r\n\t\t\tz.append(i)\r\n\t\t\tbreak\r\nprint(len(z))\r\nif len(z)>0:\r\n\tprint(*z)\t\t\t", "n,v=map(int,input().split())\r\nt=[]\r\nk=[]\r\nfor i in range(n):\r\n l=list(map(int,input().split()))\r\n if v>min(l[1:]):\r\n k.append(i+1)\r\n\r\nprint(len(k))\r\nk.sort()\r\nfor i in range(len(k)):\r\n if i==(len(k)-1):\r\n print(k[i])\r\n else:\r\n print(k[i],end=' ')", "import sys\nn, v = map(int, sys.stdin.readline().split())\nans = []\nfor i in range(1,n+1):\n alist = list(map(int, sys.stdin.readline().split()))\n if min(alist[1:]) < v:\n ans.append(i)\nprint(len(ans))\nif ans:\n print(' '.join(str(i) for i in ans))\n", "data = input().split()\nN, V = int(data[0]), int(data[1])\n\nsellers = [None] * N\nfor i in range(N):\n tmp = input().split()\n sellers[i] = list(map(int, tmp))\n\ndeal_sellers = []\nfor i in range(N):\n current_seller = sellers[i]\n if any(V > e for e in current_seller[1:]):\n deal_sellers.append(i+1)\n\nprint(len(deal_sellers))\nprint(\" \".join(map(str ,sorted(deal_sellers))))\n", "n, q = map(int, input().split())\n\ndealers = []\nans = 0\nfor i in range(n):\n arr = list(map(int, input().split()))\n minValue = min(arr[1:])\n if minValue < q:\n dealers.append(i+1)\n ans += 1\nprint(ans)\nprint(*dealers)\n", "n,v = map(int,input().split())\r\npos = []\r\nfor i in range(n):\r\n s = list(map(int,input().split()))\r\n k = s[0]\r\n del s[0]\r\n for j in range(k):\r\n if v > s[j]:\r\n pos.append(i+1)\r\n break\r\n else:\r\n continue\r\nprint(len(pos))\r\nif len(pos) != 0:\r\n print(\" \".join(map(str,pos)))\r\n", "n,v=list(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 range(1,x[0]+1):\r\n if x[j]<v:\r\n a.append(i+1)\r\n break\r\nprint(len(a))\r\nprint(*a)", "n, v = map(int, input().split())\n\nq = [str(i + 1) for i in range(n) if v > min(map(int, input().split()[1:]))]\n\nprint(len(q))\n\nprint(\" \".join(q))\n\n\n\n# Made By Mostafa_Khaled", "n,v=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n l.append(list(map(int,input().split()))[1:])\r\nris=[]\r\nfor cont in range(len(l)):\r\n for i in l[cont]:\r\n if v > i:\r\n ris.append(str(cont+1))\r\n break\r\nprint(len(ris))\r\nprint(' '.join(ris))\r\n", "n, v = map(int, input().split())\r\nres = []\r\nfor i in range(n):\r\n s = list(map(int, input().split()))\r\n s.pop(0)\r\n if any(x < v for x in s):\r\n res.append(i + 1)\r\nprint(len(res))\r\nprint(' '.join(map(str, res)))", "#!/usr/bin/env python3\r\n#! -*- coding: utf-8 -*-\r\n\r\n\r\ndef main():\r\n\tn, v = map(int, input().split())\r\n\tres = []\r\n\tfor i in range(n):\r\n\t\tcosts = [int(i) for i in input().split()][1:]\r\n\t\tcosts.sort()\r\n\t\tif costs[0] < v:\r\n\t\t\tres.append(i + 1)\r\n\tprint(len(res))\r\n\tprint(*res)\r\n\r\n\r\nif __name__ == '__main__':\r\n\tmain()", "n, m = map(int, input().split())\r\n\r\nans = []\r\ncount = 0\r\n\r\nfor i in range(n):\r\n l = list(map(int, input().split()))\r\n sno = l[0]\r\n l = l[1:]\r\n l.sort()\r\n if l[0] < m:\r\n count += 1\r\n ans.append(i+1)\r\n\r\nprint(count)\r\nif count > 0:\r\n print(*ans)\r\n\r\n", "import sys\r\ninpu = sys.stdin.readline\r\nprin = sys.stdout.write\r\nn, v = map(int, inpu().split())\r\nans = []\r\ncount = 0\r\nfor i in range(n) :\r\n h = min(list(map(int, inpu().split(' ')))[1:])\r\n if v > h :\r\n count += 1\r\n ans.append(i + 1)\r\nprin(str(count) + '\\n')\r\nprin(' '.join(map(str, ans)) + '\\n')", "x,y=map(int,input().split())\r\ns=0\r\nlist=[]\r\nfor i in range(1,x+1):\r\n z=[int(k) for k in input().split()]\r\n for j in range(1,len(z),1):\r\n if (z[j]<y):\r\n s=s+1\r\n list.append(i)\r\n break\r\nprint(s)\r\nfor i in list:\r\n print(i)", "n,k = map(int,input().split())\r\nb=[]\r\nfor i in range(n):\r\n a=list(map(int,input().split()))\r\n a=sorted(a[1:])\r\n if a[0]<k:\r\n b.append(i+1)\r\nprint(len(b))\r\nprint(*b)\r\n", "n, v = map(int, input().split())\r\nanswer = []\r\n\r\nfor i in range(n):\r\n a = list(map(int, input().split()))[1:]\r\n if v > min(a):\r\n answer.append(i + 1)\r\n\r\nprint(len(answer))\r\nprint(*answer)\r\n", "n,v = map(int, input().split())\r\ns=\"\"\r\nc=0\r\nfor i in range(n):\r\n k = list(map(int,input().split()))\r\n for j in range(1,k[0]+1):\r\n if(v>k[j]):\r\n s+=str(i+1)+\" \"\r\n c+=1\r\n break\r\nprint(c)\r\nif(c!=0):\r\n print(s[:len(s)-1])", "import sys\r\nn,v=[int(i) for i in input().split(\" \")]\r\nsumma=0\r\ns=\"\"\r\nfor i in range(n):\r\n a=[int(i) for i in input().split(\" \")]\r\n if min(a[1:])<v:\r\n summa+=1\r\n if s==\"\":\r\n s=str(i+1)\r\n else:\r\n s=s+\" \"+str(i+1)\r\nprint(summa)\r\nprint(s)\r\n", "n,v=map(int,input().split())\r\nans=[]\r\nfor i in range(n):\r\n l1=list(map(int,input().split()))\r\n for item in l1[1:]:\r\n if item<v:\r\n ans.append(i+1)\r\n break\r\nprint(len(ans))\r\nprint(' '.join(str(x) for x in ans))", "enteros = input()\n#n es número de vendedores\n#v cantidad de dinero de Valera\nn, v = enteros.split()\nn = int(n)\nv = int(v)\n#print(\"n\", n, \"v\", v)\nresultado = []\nfor i in range(1, n+1):\n #print(\"i =\", i)\n datos = input().split()\n for j in datos[1:]:\n if v > int(j):\n resultado.append(i)\n break\n #print(datos[1])\nprint(len(resultado))\nordenados = sorted(resultado)\nstr_ordenados = [str(x) for x in ordenados]\nprint(\" \".join(str_ordenados))\n", "# -*- coding: utf-8 -*-\r\n\r\nimport math\r\nimport collections\r\nimport bisect\r\nimport heapq\r\nimport time\r\nimport random\r\nimport itertools\r\nimport sys\r\n\r\n\"\"\"\r\ncreated by shhuan at 2017/11/24 20:29\r\n\r\n\"\"\"\r\n\r\n\r\nN, K = map(int, input().split())\r\n\r\nans = []\r\nfor i in range(N):\r\n a = [int(x) for x in input().split()]\r\n\r\n if any(K > v for v in a[1:]):\r\n ans.append(i+1)\r\n\r\nprint(len(ans))\r\nif ans:\r\n print(\" \".join(map(str, ans)))", "n, v = map(int, input().split())\r\nans = []\r\n\r\nfor i in range(n):\r\n tmp = list(map(int, input().split()))\r\n if min(tmp[1:]) + 1 <= v:\r\n ans.append(i + 1)\r\n\r\nprint(len(ans))\r\nprint(*ans)", "n,v = list(map(int, input().split()))\r\n\r\nans=[]\r\n\r\nfor i in range(n):\r\n\tarr = list(map(int, input().split()))\r\n\tarr.sort()\r\n\tif v>arr[1]:\r\n\t\tans.append(i+1)\r\n\r\nprint(len(ans))\r\nfor i in ans:\r\n\tprint(i, end=' ')", "n, money = map(int, input().split())\r\nprices_list = dict()\r\nfor index in range(n):\r\n list_ = list(map(int, input().split()))\r\n dealer, prices = list_[0], list_[1:]\r\n if index + 1 not in prices_list:\r\n prices_list[index + 1] = min(prices)\r\n else:\r\n prices_list[index + 1] = min(prices[dealer], min(prices))\r\n\r\nfinal = []\r\nfor dealer, price in prices_list.items():\r\n if price < money:\r\n final.append(dealer)\r\n\r\nprint(len(final))\r\nfinal.sort()\r\nprint(*final)", "NUMBER_OR_SELLERS, VALERA_BUDGET = [int(x) for x in str(input()).split()]\r\n\r\nresult = {}\r\nfor i in range(NUMBER_OR_SELLERS):\r\n input_items = input().split()\r\n for x in input_items[1:]:\r\n if int(x) < VALERA_BUDGET:\r\n result[i + 1] = 1\r\n\r\nprint(len(result))\r\nfor i in result:\r\n print(i, end=\" \")\r\n", "n, v = map(int, input().split())\r\nsellers = []\r\nfor i in range(n):\r\n l = list(map(int, input().split()))\r\n if min(l[1:]) < v:\r\n sellers.append(i+1)\r\nprint(len(sellers))\r\nprint(' '.join(map(str, sellers)))\r\n", "n, k = map(int,input().split())\r\nans = []\r\ncount = 0\r\nfor i in range(n):\r\n a = list(map(int,input().split()))\r\n if min(a[1:]) < k:\r\n count += 1\r\n ans.append(i+1)\r\nprint(count)\r\nif count > 0:\r\n sep = \" \"\r\n print(sep.join(list(map(str,ans))))\r\n", "s=[]\r\nn,m=map(int,input().split())\r\nfor q in range(n):\r\n\ta,*l=map(int,input().split())\r\n\tif min(l)<m:s.append(q+1)\r\nprint(len(s))\r\nprint(*s)", "\r\nn, v = map(int, input().split())\r\nDict = {}\r\nList = []\r\nfor i in range(1, n + 1):\r\n s = list(map(int, input().split()))\r\n Dict[i] = list(sorted(s[1:]))\r\nfor i in range(1, n + 1):\r\n if Dict[i][0] < v:\r\n List.append(i)\r\nprint(len(List))\r\nprint(*List)\r\n\r\n# CodeForcesian\r\n# ♥\r\n# Lifan\r\n", "a=list(map(int,input().strip().split()))\r\nn=a[0]\r\nv=a[1]\r\nb=[]\r\nc=[]\r\nfor i in range(0,n):\r\n d=list(map(int,input().strip().split()))\r\n e=0\r\n for j in range(1,d[0]+1):\r\n if(d[j]<v):\r\n e=e+1\r\n if(e>0):\r\n c.append(i+1)\r\nprint(len(c))\r\nfor i in c:\r\n print(i,end=' ')\r\n \r\n", "n,k=map(int,input().split())\r\nkol=0\r\nmas=[]\r\nfor i in range(n):\r\n a=list(map(int,input().split()))\r\n a=a[1::]\r\n mi=min(a)\r\n if mi<k:\r\n kol+=1\r\n mas.append(i+1)\r\nprint(kol)\r\nprint(*mas)", "n, v = map(int, input().split())\r\nsellers = [list(map(int, input().split())) for i in range(n)]\r\n\r\nres_amount, res_sellers = 0, []\r\n\r\nfor i, p in enumerate(sellers):\r\n if min(p[1:]) < v:\r\n res_amount += 1\r\n res_sellers.append(i+1)\r\n\r\nprint(res_amount)\r\nprint(*res_sellers)", "n, v = map(int, input().strip().split())\nc = []\nfor i in range(n):\n\tarr = list(map(int, input().strip().split()))\n\tif v > min(arr[1:]):\n\t\tc.append(i+1)\nprint(len(c))\nprint(*c)", "n,v = map(int, input().split())\r\nkol=0\r\nsaller=[]\r\nfor i in range(n):\r\n mas=list(map(int, input().split()))\r\n for j in mas[1:]:\r\n if v>j:\r\n saller.append(i+1)\r\n kol+=1\r\n break\r\n\r\nprint(kol)\r\nfor i in saller:\r\n print(i,end=' ')", "def count(arr, value):\r\n c = 0\r\n for ai in arr:\r\n if ai < value:\r\n c += 1\r\n return c\r\n\r\nn, v = list(map(int, input().split()))\r\nsellers = []\r\nfor _ in range(n):\r\n prices = list(map(int, input().split()))[1:]\r\n prices.sort()\r\n sellers.append(prices)\r\n\r\noutbid = []\r\nfor i, prices in enumerate(sellers):\r\n if count(prices, v) > 0:\r\n outbid.append(i+1)\r\nseller_count = len(outbid)\r\nprint(seller_count)\r\nif seller_count > 0:\r\n for out in outbid:\r\n print(out, end=\" \")\r\nelse:\r\n print()\r\n", "n,v=map(int,input().split())\r\nl1=[]\r\nfor i in range(n):\r\n\tl=list(map(int,input().split()))\r\n\tfor j in l[1:]:\r\n\t\tif j<v:\r\n\t\t\tif i+1 not in l1:\r\n\t\t\t\tl1.append(i+1)\r\nprint(len(l1))\r\nprint(*l1)", "n,m=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n x=list(map(int,input().rstrip().rsplit()))\r\n l.append(x)\r\n\r\nfor i in l:\r\n i.pop(0)\r\n\r\n\r\nlt = []\r\nfor i in range(len(l)):\r\n if(min(l[i])<m):\r\n lt.append(i+1)\r\n\r\nprint(len(lt))\r\nprint(*lt)\r\n", "def check(g):\r\n for x in g:\r\n if x < 0:\r\n return True\r\n else:\r\n return False\r\n \r\ndef applyall(d):\r\n k = []\r\n global v\r\n for x in d:\r\n y = x-v\r\n k.append(y)\r\n return k\r\n \r\n\r\n[n,v] = [int(x) for x in input().split(\" \")]\r\nl = []\r\n\r\nfor i in range(n):\r\n temp = [int(x) for x in input().split(\" \")]\r\n l.append(temp)\r\n \r\ncounter = 0\r\ndealers = []\r\n\r\nfor i in range(len(l)):\r\n temp = applyall(l[i][1:])\r\n if check(temp):\r\n dealers.append(i+1)\r\n \r\nprint(len(dealers))\r\nfor x in dealers:\r\n print(x,end=\" \")\r\n\r\n \r\n \r\n ", "n,v = [int(x) for x in input().split()]\r\ns = []\r\nfor i in range(1,n+1):\r\n l = [int(x) for x in input().split()]\r\n if min(l[1:]) < v: s.append(i)\r\nprint(len(s))\r\nprint(*s)\r\n", "from itertools import islice\n\nn, v = (int(i) for i in input().split())\nres = [i + 1 for i in range(n) if any(v > int(k) for k in islice(input().split(), 1, None))]\nprint(len(res))\nprint(*res)\n", "n,v= map(int,input().split())\r\nc=0\r\nc1=[]\r\n\r\nfor i in range(n):\r\n k=list(map(int,input().split()))\r\n for j in range(1,len(k)):\r\n \r\n if k[j]<v:\r\n c+=1\r\n c1.append(i+1)\r\n break\r\n \r\nprint(c)\r\nprint(*c1)\r\n \r\n", "n,v=map(int,input().split())\ns=0\nl=[]\nfor i in range(n):\n a=[int(k) for k in input().split()]\n for j in range(1,len(a)):\n if v>a[j]:\n s+=1\n l.append(i+1)\n break\n\nprint(s)\nfor i in l:\n print(i,end=' ')\n\n\n", "n, v = (int(x) for x in input().split())\nans = []\nfor i in range(n):\n arr = [int(x) for x in input().split()]\n for j in arr[1:]:\n if j < v:\n ans.append(i + 1)\n break\nprint(len(ans))\nprint(' '.join([str(s) for s in ans]))\n", "buff = list(map(int, input().split()))\r\nn = buff[0]\r\nmoney = buff[1]\r\narr = []\r\nlst = []\r\nflag = 1\r\ncount = 0\r\nfor i in range(n):\r\n arr.append(list(map(int, input().split())))\r\n flag = 1\r\n \r\n for j in arr[i]:\r\n if j < money and flag and arr[i][0] != j:\r\n lst.append(i+1)\r\n flag = 0\r\n count += 1\r\n\r\nstrs = \"\"\r\nfor i in lst:\r\n strs += str(i)\r\n strs += \" \"\r\n \r\nprint(count)\r\nprint(strs)", "n,v=map(int,input().split())\ncnt=0\nfi=[]\nfor i in range(n):\n\tb=list(map(int,input().split()))\n\tif(min(b[1:])<v):\n\t\tfi.append(i+1)\nprint(len(fi))\nfi.sort()\nprint(*fi)" ]
{"inputs": ["3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "2 100001\n1 895737\n1 541571", "1 1000000\n1 1000000", "1 1000000\n1 561774", "3 1000000\n5 1000000 568832 1000000 1000000 1000000\n13 1000000 1000000 1000000 596527 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n20 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000", "3 999999\n7 1000000 1000000 1000000 999999 1000000 999999 1000000\n6 999999 1000000 999999 1000000 999999 999999\n7 999999 1000000 1000000 999999 1000000 1000000 1000000", "3 999999\n22 1000000 1000000 999999 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 999999 1000000 1000000 1000000 352800 999999 1000000\n14 999999 999999 999999 999999 999999 1000000 999999 999999 999999 999999 702638 999999 1000000 999999\n5 999999 1000000 1000000 999999 363236", "1 50001\n1 50000"], "outputs": ["3\n1 2 3", "0", "0", "0", "1\n1", "2\n1 2", "0", "3\n1 2 3", "1\n1"]}
UNKNOWN
PYTHON3
CODEFORCES
294
134adde1602a65ae3022bdcfbb7f3925
Life Without Zeros
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros? For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation. But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. Sample Input 101 102 105 106 Sample Output YES NO
[ "a = (input())\nb = (input())\n\nres = int(a)+int(b)\na = a.replace(\"0\",'')\nb = b.replace(\"0\",'')\nres = str(res)\nres = res.replace(\"0\",'')\nres = int(res)\n\na = int(a)\nb = int(b)\n\nif res == (a+b):\n print(\"YES\")\nelse:\n print(\"NO\")\n\n\n\n\n", "num1=int(input())\r\nnum2=int(input())\r\nresult=num1+num2\r\na=str(num1).replace(\"0\",\"\")\r\nb=str(num2).replace(\"0\",\"\")\r\nc=str(result).replace(\"0\",\"\")\r\nif int(a)+int(b)==int(c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input().strip())\r\nm = int(input().strip())\r\nc = str(n+m)\r\nn = str(n)\r\nm = str(m)\r\ncc = mm = nn = []\r\njn = ''\r\njm = ''\r\njc = ''\r\nfor i in c:\r\n if i != '0':\r\n jc = jc + i\r\nfor i in m:\r\n if i != '0':\r\n jm = jm + i\r\nfor i in n :\r\n if i != '0':\r\n jn = jn + i\r\nif int(jn) + int(jm) == int(jc):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a = input()\r\nb = input()\r\nc = int(a) + int(b)\r\n\r\ndef rz( n ):\r\n n = str(n)\r\n ret = \"\"\r\n for i in n:\r\n if i != \"0\":\r\n ret += i\r\n return ( ret )\r\n\r\nif int( rz(a) ) + int( rz(b) ) == int( rz(c) ):\r\n print( \"YES\" )\r\nelse:\r\n print( \"NO\" )\r\n", "'''input\n105\n106\n'''\na = input()\nb = input()\nc = int(a) + int(b)\n\na1 = int(\"\".join(a.split('0')))\nb1 = int(\"\".join(b.split('0')))\nc1 = int(\"\".join(str(c).split('0')))\n\n\nif c1 == a1 + b1:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n\n\n", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\nc=str(c)\r\n\r\n# print(a,b,c)\r\n\r\na0=a.count('0')\r\nb0=b.count('0')\r\nc0=c.count('0')\r\n\r\na=a.replace('0','',a0)\r\nb=b.replace('0','',b0)\r\nc=c.replace('0','',c0)\r\n\r\n# print(a,b,c)\r\n\r\n\r\nif int(a)+int(b)==int(c):\r\n print('YES')\r\nelse: \r\n print('NO')\r\n", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\na1=list(a)\r\nb1=list(b)\r\nc1=list(str(c))\r\nwhile '0' in a1:\r\n a1.remove('0')\r\nwhile '0' in b1:\r\n b1.remove('0')\r\nwhile '0' in c1:\r\n c1.remove('0')\r\na2=''.join(a1)\r\nb2=''.join(b1)\r\nc3=''.join(c1)\r\nc2=int(a2)+int(b2)\r\nif(int(c3)==c2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "# n, m = map(int, input().split())\na = input()\nb = input()\nc = int(a) + int(b)\na = a.replace(\"0\", \"\")\nb = b.replace(\"0\", \"\")\nc = str(c).replace(\"0\", \"\")\nif int(a) + int(b) == int(c):\n print(\"YES\")\nelse:\n print(\"NO\")", "a = input()\r\nb = input()\r\na1 = int(a.replace(\"0\",\"\"))\r\nb1 = int(b.replace(\"0\", \"\"))\r\nc = int(str(int(a)+int(b)).replace(\"0\",\"\"))\r\nif a1+b1==c:print(\"YES\")\r\nelse:print(\"NO\")", "def solve():\r\n a = int(input())\r\n b = int(input())\r\n c = a+b\r\n\r\n a = str(a)\r\n a = a.replace('0','')\r\n b = str(b)\r\n b = b.replace('0','')\r\n c = str(c)\r\n c = c.replace('0','')\r\n\r\n a = int(a)\r\n b = int(b)\r\n c = int(c)\r\n \r\n if(a+b==c):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\nt=1\r\n#t=int(input())\r\nfor _ in range(t):\r\n solve()", "a = int(input())\r\nb = int(input())\r\na_bez_0 = a\r\nb_bez_0 = b\r\ns_bez_0 = a + b # summa bez 0\r\nsumma = a + b\r\ni = -1\r\ni2 = -1\r\ni3 = -1\r\nlastA = 0\r\nlastB = 0\r\nlastS = 0\r\nwhile a > 0:\r\n lastA = a % 10 # posl cifra\r\n if lastA == 0:\r\n a_bez_0 = int(str(a_bez_0)[:i] + str(a_bez_0)[i + 1:]) # virezaem 0 cherez stroku\r\n i = i - 1\r\n a = a // 10 #chislo bez posl cifri\r\nwhile b > 0:\r\n lastB = b % 10\r\n if lastB == 0:\r\n b_bez_0 = int(str(b_bez_0)[:i2] + str(b_bez_0)[i2 + 1:])\r\n i2 = i2 - 1\r\n b = b // 10\r\nwhile summa > 0:\r\n lastS = summa % 10\r\n if lastS == 0:\r\n s_bez_0 = int(str(s_bez_0)[:i3] + str(s_bez_0)[i3 + 1:])\r\n i3 = i3 - 1\r\n summa = summa // 10\r\nif a_bez_0 + b_bez_0 == s_bez_0:\r\n print('YES')\r\nelse:\r\n print('NO')", "import sys,math\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\na = input()\r\nb = input()\r\nc = str(int(a)+int(b))\r\nan,bn,cn=\"\",\"\",\"\"\r\nfor x in a:\r\n if x!='0':\r\n an += x\r\nfor x in b:\r\n if x!='0':\r\n bn += x\r\nfor x in c:\r\n if x!='0':\r\n cn += x\r\nif int(an)+int(bn)==int(cn):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "str1=input()\r\nstr2=input()\r\neq1=int(str1)+int(str2)\r\neq1=str(eq1)\r\nwz1=str1.replace(\"0\",\"\")\r\nwz2=str2.replace(\"0\",\"\")\r\neq2=eq1.replace(\"0\",\"\")\r\nb=int(wz1)+int(wz2)\r\na=int(eq2)\r\nif a==b:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import sys, os\r\nfrom collections import defaultdict\r\nfrom math import gcd, sqrt\r\ninput = sys.stdin.readline\r\nread = lambda: list(map(int, input().strip().split()))\r\n\r\n\r\ndef main():\r\n a, b = [int(input()) for i in range(2)]; c = a+b\r\n a, b, c = [int(str(i).replace(\"0\", \"\")) for i in [a, b, c]]\r\n if a+b == c:print(\"YES\")\r\n else:print(\"NO\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n\r\n\r\n\r\n\"\"\"\r\n\r\n\r\nl = n-a+1\r\n\r\na*l + (l*(l+1))//2\r\n\r\n\r\n\r\n\r\n\r\n\r\n\"\"\"", "a=input()\nb=input()\nc=int(a)+int(b)\nx=str(c)\nfor i in a:\n if i=='0':\n a=a.replace(i,'')\nfor i in b:\n if i == '0':\n b=b.replace(i,'')\nfor i in x:\n if i == '0':\n x=x.replace(i,'')\nif int(a)+int(b)==int(x):\n print('YES')\nelse:print('NO')\n \t \t \t \t\t \t \t\t \t \t\t\t\t", "# code.py\r\n\r\na = input()\r\nb = input()\r\n\r\nc = str(int(a) + int(b))\r\n\r\nap = \"\"\r\nbp = \"\"\r\ncp = \"\"\r\nfor i in range(len(a)):\r\n\tif (a[i] != \"0\"):\r\n\t\tap += a[i]\r\nfor i in range(len(b)):\r\n\tif (b[i] != \"0\"):\r\n\t\tbp += b[i]\r\nfor i in range(len(c)):\r\n\tif (c[i] != \"0\"):\r\n\t\tcp += c[i]\r\n\r\nif (int(ap) + int(bp) == int(cp)):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\r\n\r\n\r\n\t\t\r\n\r\n\r\n\r\n\r\n", "a=int(input())\r\nb=int(input())\r\nt=lambda x:int(str(x).replace(\"0\",\"\"))\r\nprint([\"NO\",\"YES\"][t(a)+t(b)==t(a+b)])", "def remove(n):\r\n s=str(n)\r\n l=list(s)\r\n k=[]\r\n for chr in l:\r\n if chr!='0':\r\n k.append(chr)\r\n x=''.join(k)\r\n return int(x)\r\na=int(input())\r\nb=int(input())\r\nc=a+b\r\nr,t=remove(a),remove(b)\r\nif r+t==remove(c):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a=int(input())\r\nb=int(input())\r\nx=int(str(a).replace('0', '')) + int(str(b).replace('0', ''))\r\ny=int(str(a+b).replace('0', ''))\r\nif x==y:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "li_chi = []\nli_str = []\nfor i in range(2):\n li_chi.append(int(input()))\n\nli_chi.append(sum(li_chi))\n\nfor el in li_chi:\n copy = list(str(el))\n for i in range(copy.count('0')):\n copy.remove('0')\n li_str.append(int(''.join(copy)))\n\nif li_str[0] + li_str[1] == li_str[2]:\n print('YES')\nelse:\n print('NO')\n", "def remove_z(x):\r\n res = 0\r\n ten = 10\r\n while x > 0:\r\n rem = x % 10\r\n if rem:\r\n res += rem*ten\r\n ten *= 10\r\n x = x // 10\r\n return res\r\n\r\ndef solve(a, b):\r\n res = a + b\r\n a = remove_z(a)\r\n b = remove_z(b)\r\n res = remove_z(res)\r\n if res == a + b:\r\n return \"YES\"\r\n return \"NO\"\r\n\r\na = int(input())\r\nb = int(input())\r\nprint(solve(a, b))", "number1 = input()\r\nnumber2 = input()\r\nsummon = str(int(number1) + int(number2))\r\nnumber1 = number1.replace(\"0\", \"\")\r\nnumber2 = number2.replace(\"0\", \"\")\r\nsummon = summon.replace(\"0\",\"\")\r\nif int(number1) + int(number2) == int(summon):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n", "def main():\r\n a = input()\r\n b = input()\r\n c = str(int(a)+int(b))\r\n a1 = int(a.replace('0', ''))\r\n b1 = int(b.replace('0', ''))\r\n c1 = int(c.replace('0', ''))\r\n\r\n if a1 + b1 == c1:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "\r\na = int(input())\r\nb = int(input())\r\n\r\nc = a + b\r\n\r\ndef cal(a1): \r\n a0 = 0\r\n exp = 0\r\n while a1 > 0:\r\n x = a1 % 10\r\n if x != 0:\r\n a0 += x*10**exp\r\n exp += 1 \r\n a1 //= 10\r\n return a0\r\n\r\nif cal(a) + cal(b) == cal(c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\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=int(input())\r\nb=int(input())\r\nc=a+b\r\nm=n=p=\"\"\r\nfor i in str(a):\r\n if int(i)!=0:\r\n m+=i\r\nfor i in str(b):\r\n if int(i)!=0:\r\n n+=i\r\nfor i in str(c):\r\n if int(i)!=0:\r\n p+=i \r\nm=int(m)\r\nn=int(n)\r\nd=m+n\r\nif int(p)==d:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def daoso (n):\r\n tong = 0\r\n while(n!=0):\r\n le = n%10\r\n tong = tong*10+le\r\n n=n//10\r\n return (tong)\r\ndef rmzero(n):\r\n new = 0\r\n count = 0\r\n while (n!=0):\r\n res = n%10\r\n n = n//10\r\n if res != 0:\r\n new = new*10 + res\r\n new = daoso(new)\r\n return new\r\na = int(input())\r\nb = int(input())\r\nif rmzero(a+b) == (rmzero(a)+rmzero(b)):\r\n print('YES')\r\nelse:\r\n print('NO')", "def clean(num):\r\n orig = list(str(num))\r\n new=[]\r\n for i in orig:\r\n if i != '0':\r\n new.append(i)\r\n return int(\"\".join(new))\r\n \r\na=int(input())\r\nb=int(input())\r\nnum1=clean(a)\r\nnum2=clean(b)\r\nres =clean(a+b)\r\nif num1+num2 == res:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n\r\n\r\n\r\n", "a=int(input())\r\nb=int(input())\r\n\r\nc=str(a+b)\r\n\r\na_new=str(a).replace('0','')\r\n\r\n\r\nb_new=str(b).replace('0','')\r\n\r\nc_new=c.replace('0','')\r\n\r\nif int(a_new)+int(b_new)==int(c_new):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def check_zero(a,b):\r\n sum_check=a+b\r\n str_a,str_b,str_sum=str(a),str(b),str(sum_check)\r\n if (int(str_a.replace(\"0\",\"\"))+int(str_b.replace(\"0\",\"\")))==int(str_sum.replace(\"0\",\"\")):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\na=int(input())\r\nb=int(input())\r\ncheck_zero(a,b)", "def without_zero(n):\r\n num = \"\"\r\n for i in n:\r\n if i != '0':\r\n num = num + i\r\n return num\r\n\r\n\r\na = input()\r\nb = input()\r\nif int(without_zero(str(int(a) + int(b)))) == int(without_zero(a)) + int(without_zero(b)):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "import math\r\n\r\ndef flip(temp):\r\n y = 0\r\n while temp != 0:\r\n y *= 10\r\n r = temp % 10\r\n y += r\r\n temp = int(temp/10)\r\n return y\r\n \r\ndef remove_zero(a):\r\n y = 0\r\n while a != 0:\r\n y *= 10\r\n r = a % 10\r\n if r == 0: y /= 10\r\n y += r\r\n a = int(a/10)\r\n return flip(int(y))\r\n \r\n\r\na = int(input())\r\nb = int(input())\r\nc = a + b\r\n\r\na1 = remove_zero(a)\r\nb1 = remove_zero(b)\r\nc1 = remove_zero(c)\r\n# print(a1, b1, c1)\r\nif (a1 + b1 == c1): print(\"YES\")\r\nelse: print(\"NO\")\r\n\r\n", "a = int(input())\r\nb = int(input())\r\n\r\nc = a + b \r\na_0 = \"\"\r\nb_0 = \"\"\r\nc_0 = \"\"\r\nfor i in str(a):\r\n if str(i) != \"0\":\r\n a_0+=i \r\nfor i in str(b):\r\n if str(i) != \"0\":\r\n b_0+=i \r\nfor i in str(c):\r\n if str(i) != \"0\":\r\n c_0+=i \r\nif int(a_0) + int(b_0) == int(c_0):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\na = a.replace(\"0\",\"\")\r\nb = b.replace(\"0\",\"\")\r\nc = str(c).replace(\"0\",\"\")\r\nif(int(a)+int(b)==int(c)):print(\"YES\")\r\nelse:print(\"NO\")", "s1 = input()\r\ns2 = input()\r\ns3 = str(int(s1) + int(s2))\r\ns1 = \"\".join(i for i in s1 if i!=\"0\")\r\ns2 = \"\".join(i for i in s2 if i!=\"0\")\r\nif(int(s1)+int(s2)==int(\"\".join(i for i in s3 if i!=\"0\"))):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n1 = input()\nn2 = input()\nres = str(int(n1)+int(n2))\nn1z = n1.replace('0','')\nn2z = n2.replace('0','')\nresz = res.replace('0','')\nif str(int(n1z) + int(n2z)) == resz:\n print('YES')\nelse :\n print('NO')\n# ans = 'YES'\n# for i in range(len(n1)-1):\n# if n1[i]== '0' or n2[i]=='0':\n# if n1[i]=='0' and n2[i] == '0':\n# if int(n1[i+1]) + int(n2[i+1]) >9:\n# ans = 'NO'\n# else:\n# ans = 'NO'\n# if n1[-1] == '0' :\n# if n2[-1] !='0':\n# ans = 'NO'\n# if n2[-1] == '0' :\n# if n1[-1] !='0':\n# ans = 'NO'\n# print(ans)\n\n\n", "a = input()\r\nb = input()\r\nc = int(a) + int(b)\r\ncStr = str(c)\r\naList = []\r\nbList = []\r\ncList = []\r\na1 = \"\"\r\nb1 = \"\"\r\nc1 = \"\"\r\nfor i in range(len(a)):\r\n if a[i] != '0':\r\n aList.append(a[i])\r\nfor i in range(len(b)):\r\n if b[i] != '0':\r\n bList.append(b[i])\r\nfor i in range(len(cStr)):\r\n if cStr[i] != '0':\r\n cList.append(cStr[i])\r\n\r\n\r\nfor i in range(len(aList)):\r\n a1 += aList[i]\r\na1 = int(a1)\r\nfor i in range(len(bList)):\r\n b1 += bList[i]\r\nb1 = int(b1)\r\nfor i in range(len(cList)):\r\n c1 += cList[i]\r\nc1 = int(c1)\r\n \r\nif a1 + b1 == c1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\nb=input()\nc=int(a)+int(b)\nd=int(a.replace('0',''))+int(b.replace('0',''))\ne=str(c)\nf=int(e.replace('0',''))\nif(d==f):\n print(\"YES\")\nelse:\n print(\"NO\")\n\t\t\t\t\t\t \t\t\t\t\t \t \t\t\t \t\t\t \t", "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\ta = input()\r\n\tb = input()\r\n\r\n\ts1 = str(int(a) + int(b))\r\n\ts1 = s1.replace('0', '')\r\n\ta = a.replace('0', '')\r\n\tb = b.replace('0', '')\r\n\r\n\ts2 = str(int(a) + int(b))\r\n\r\n\tif s1 == s2:\r\n\t\tprint('YES')\r\n\telse:\r\n\t\tprint('NO')\r\n\r\n\t\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", "a = int(input())\r\nb = int(input())\r\nc = a + b \r\na1 = \"\".join([i for i in str(a) if i != \"0\"])\r\nb1 = \"\".join([i for i in str(b) if i != \"0\"])\r\nc1 = \"\".join([i for i in str(c) if i != \"0\"])\r\n\r\nif (int(a1) + int(b1)) == int(c1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def RemoveZero(txt):\r\n res=\"\"\r\n for i in range(len(txt)):\r\n if txt[i]!='0':\r\n res=res+txt[i]\r\n return res \r\n\r\ntxt1=input()\r\ntxt2=input()\r\n\r\nr1=int(txt1)+int(txt2)\r\n\r\n\r\n\r\nif RemoveZero(str(r1))==str(int(RemoveZero(txt1))+int(RemoveZero(txt2))):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n\r\n", "x1 = input()\r\nx2 = input()\r\n\r\ns1 = ''\r\ns2 = ''\r\ns3 = ''\r\n\r\nfor i in x1 :\r\n if i == '0':\r\n continue\r\n else:\r\n s1 += i\r\n\r\nfor i in x2 :\r\n if i == '0':\r\n continue\r\n else:\r\n s2 += i\r\n\r\nans1 = int(x1) + int(x2)\r\nans2 = int(s1) + int(s2)\r\nfor i in str(ans1) :\r\n if i == '0':\r\n continue\r\n else:\r\n s3 += i\r\n#print(s3)\r\n#print(ans1)\r\n#print(ans2)\r\n\r\nif int(s3) == ans2 :\r\n print('YES')\r\nelse:\r\n print('NO')", "a=input()\r\nb=input()\r\nc=str(int(a)+int(b))\r\n\r\ndef rz(x):\r\n z=\"\"\r\n for i in x:\r\n if i!='0':\r\n z+=i\r\n return int(z)\r\n\r\nif rz(a)+rz(b)==rz(c): print(\"YES\")\r\nelse: print(\"NO\")", "def RemoveZERO(x):\r\n x=str(x)\r\n\r\n s=''\r\n for i in range(len(x)):\r\n if(x[i] is not '0'):\r\n s=s+x[i]\r\n s=int(s)\r\n return s\r\na=int(input())\r\nb=int(input())\r\nc=a+b\r\nd=RemoveZERO(a)\r\ne=RemoveZERO(b)\r\nc=RemoveZERO(c)\r\nif(c==d+e):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a= int(input())\r\nb= int(input())\r\nres= a+b\r\nstr_a= str(a).replace('0', '')\r\nstr_b= str(b).replace('0', '')\r\nstr_res= str(res).replace('0', '')\r\n\r\nprint('YES' if int(str_a)+int(str_b)== int(str_res) else 'NO')", "a = input()\r\nb = input()\r\nif str(int(a.replace('0','')) + int(b.replace('0' , ''))) == str(str(int(a) + int(b)).replace('0','')):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\nm = int(input())\n\ndef trim_zero(x):\n temp = str(x)\n return int(''.join(i for i in temp if i != '0'))\n\nif trim_zero(n) + trim_zero(m) == trim_zero(n+m):\n print('YES')\nelse:\n print('NO')\n", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\naa=a.replace('0','')\r\nbb=b.replace('0','')\r\ncc=int(aa)+int(bb)\r\nif cc==int(str(c).replace('0','')):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nnumbers = [a, b, c]\r\ni = 0\r\n\r\nwhile i < 3:\r\n digit = numbers[i]\r\n position = 1\r\n new_number = 0\r\n while digit > 0:\r\n last_digit = digit % 10\r\n if last_digit != 0:\r\n new_number = last_digit * position + new_number\r\n position *= 10\r\n digit = digit // 10\r\n numbers[i] = new_number\r\n i += 1\r\nif numbers[0] + numbers[1] == numbers[2]:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def removezeros(string):\r\n new = \"\"\r\n for i in string:\r\n if i != \"0\":\r\n new+=i\r\n return new\r\n\r\nfirst,second = input(),input()\r\nc = str(int(first)+int(second))\r\n\r\nfirst = removezeros(first)\r\nsecond = removezeros(second)\r\nc = removezeros(c)\r\n\r\nif int(first)+int(second) == int(c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "# #214A\r\n# def countRoot(n,m):\r\n# count = 0\r\n# a = 0\r\n# while((a**2)<=n and a<=m):\r\n# b = n-(a**2)\r\n# if(a+(b**2)==m):\r\n# count = count + 1\r\n# a = a + 1\r\n# return count\r\n#\r\n# n,m = map(int,input().split())\r\n# ans = countRoot(n,m)\r\n# print(ans)\r\n\r\n#75A\r\ndef removeZeros(n):\r\n ans = 0\r\n i = 0\r\n while(n!=0):\r\n digit = n%10\r\n if(digit!=0):\r\n ans = ans + digit * (10 ** i)\r\n i = i + 1\r\n n=n//10\r\n return ans\r\n\r\na = int(input())\r\nb = int(input())\r\nc = a+b\r\ntemp = removeZeros(a)+removeZeros(b)\r\nif(temp==removeZeros(c)):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\nA=''\r\nB=''\r\nC=''\r\nfor i in str(a):\r\n if i!='0':\r\n A=A+i\r\nfor i in str(b):\r\n if i!='0':\r\n B=B+i\r\nfor i in str(c):\r\n if i!='0':\r\n C=C+i\r\nif int(A)+int(B)==int(C):\r\n print('YES')\r\nelse:\r\n print('NO')", "a = input()\r\nb = input()\r\nsum = int(a) + int(b)\r\n\r\na_non_zero = ''\r\nb_non_zero = ''\r\nsum_non_zero = ''\r\n\r\nfor x in a: \r\n if int(x) != 0: a_non_zero+=x\r\nfor x in b:\r\n if int(x) != 0: b_non_zero+=x\r\nfor x in str(sum): \r\n if x!=\"0\": sum_non_zero+=x\r\n\r\n#print(a_non_zero, \"---\", b_non_zero, \"---\", sum_non_zero)\r\n\r\nif (int(a)+int(b)==sum and int(a_non_zero) + int(b_non_zero)==int(sum_non_zero)): print(\"YES\")\r\nelse: print(\"NO\")", "def ans_func(num):\r\n num_list = []\r\n while num > 0:\r\n if num % 10:\r\n num_list.append(num % 10)\r\n num //= 10\r\n num_list.reverse()\r\n return int(\"\".join(map(str, num_list)))\r\n\r\n\r\na, b = int(input()), int(input())\r\n\r\nprint(\"YES\" if ans_func(a) + ans_func(b) == ans_func(a + b) else \"NO\")\r\n", "def removeZeros(x):\r\n number_without_zeros = 0\r\n i = 0\r\n while(x > 0):\r\n remainder = x % 10\r\n if(remainder != 0):\r\n number_without_zeros = number_without_zeros + remainder * (10 ** i)\r\n i += 1\r\n x //= 10\r\n return number_without_zeros\r\n\r\ndef lifeWithoutZeros(a, b):\r\n if (removeZeros(a + b) == removeZeros(a) + removeZeros(b)):\r\n return True\r\n return False\r\n\r\na = int(input())\r\nb = int(input())\r\nif(lifeWithoutZeros(a,b)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "num1 = input()\r\nnum2 = input()\r\nres1 = \"\".join(list(filter(lambda x : x != \"0\",str(int(num1) + int(num2)))))\r\n\r\nnum1 = list(filter(lambda x : x != \"0\",num1))\r\nnum2 = list(filter(lambda x : x != \"0\",num2))\r\nres2 = str(int(\"\".join(num1)) + int(\"\".join(num2)))\r\n\r\nprint(\"YES\" if res1 == res2 else \"NO\")", "def zeroder(x):\r\n x = str(x)\r\n a =''\r\n for i in x:\r\n if i != \"0\": a += i\r\n return int(a)\r\n\r\na = int(input())\r\nb = int(input())\r\nif zeroder(a+b) == zeroder(a)+zeroder(b): print(\"YES\")\r\nelse: print(\"NO\")", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\n\r\n\r\ndef digit(n):\r\n digits = []\r\n while n > 0:\r\n if n % 10 != 0:\r\n digits.append(n % 10)\r\n n = n // 10\r\n return digits\r\n\r\n\r\ndigits1 = digit(a)\r\ndigits1.reverse()\r\ndigits2 = digit(b)\r\ndigits2.reverse()\r\ndigits3 = digit(c)\r\ndigits3.reverse()\r\n\r\nnumber1 = int(''.join(map(str, digits1)))\r\nnumber2 = int(''.join(map(str, digits2)))\r\nnumber3 = int(''.join(map(str, digits3)))\r\n\r\nif number1 + number2 == number3:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "from sys import stdin\r\nfrom xml.sax.handler import EntityResolver\r\n\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):\r\n M = []\r\n for _ in range(n):\r\n row = readarray(int)\r\n assert len(row) == n\r\n M.append(row)\r\n return M\r\n\r\ndef remove_zero(s):\r\n s_ = ''\r\n s = str(s)\r\n for i in s:\r\n if i != '0':\r\n s_ += i\r\n return int(s_)\r\n \r\n \r\ndef solve():\r\n A = readint()\r\n B = readint()\r\n C = A + B\r\n if remove_zero(C) == remove_zero(A) + remove_zero(B):\r\n print('YES')\r\n else:\r\n print('NO')\r\n\r\n \r\n \r\n \r\n\r\nif __name__ == \"__main__\":\r\n T = 1#readint()\r\n for _ in range(T):\r\n solve()\r\n", "int1 = int(input())\r\nint2 = int(input())\r\na1 = str(int1)\r\na2 = str(int2)\r\nSum = (int1 + int2)\r\nstr1 = str(Sum)\r\nAnswer1 = str1.replace(\"0\",\"\")\r\nadd1 = a1.replace(\"0\",\"\")\r\nadd2 = a2.replace(\"0\",\"\")\r\nAnswer2 = str(int(add1)+int(add2))\r\n\r\n\r\nif Answer1 == Answer2:\r\n print(\"YES\")\r\nif Answer1 != Answer2:\r\n print(\"NO\")\r\n", "a = int(input())\nb = int(input())\nc = a + b\nlista = [a, b, c]\n\nfor i in range(3):\n aux = ''\n for c in str(lista[i]):\n if c != '0':\n aux += c\n lista[i] = aux\nif int(lista[0]) + int(lista[1]) == int(lista[2]):\n print('YES')\nelse:\n print('NO')\n\n\n\t\t\t \t \t \t\t\t\t\t\t\t \t\t\t\t\t\t\t \t\t", "m = int(input())\r\nn = int(input())\r\n\r\ndef del_zeros(a):\r\n res = 0\r\n sub = 0\r\n while a>=10:\r\n if a%10 == 0:\r\n pass\r\n else:\r\n res = (a %10)*(10**sub) + res\r\n sub+=1\r\n a = a // 10\r\n res = a*(10**sub)+res\r\n return res\r\n\r\nif del_zeros(m) + del_zeros(n) == del_zeros(m+n):\r\n print('YES')\r\nelse:\r\n print('NO')", "n=input()\r\nm=input()\r\nn1=\"\"\r\nm1=\"\"\r\nval=int(n)+int(m)\r\nval3=\"\"\r\nval=str(val)\r\nfor i in range(len(val)):\r\n if val[i]!='0':\r\n val3+=val[i]\r\nfor i in range(len(n)):\r\n if n[i]!='0':\r\n n1+=n[i]\r\nfor i in range(len(m)):\r\n if m[i]!='0':\r\n m1+=m[i]\r\nval2=int(n1)+int(m1)\r\nval2=str(val2)\r\nif val3==val2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def remove_zeros(num):\r\n num_arr = [d for d in str(num)]\r\n filtered_arr = list(filter(lambda x: (x != '0'), num_arr))\r\n return int(''.join(filtered_arr))\r\n \r\na = int(input())\r\nb = int(input())\r\n\r\nsum1 = a + b\r\n\r\nsum2 = remove_zeros(a) + remove_zeros(b)\r\n\r\nprint(\"YES\" if (sum2 == remove_zeros(sum1)) else \"NO\")\r\n\r\n", "s1 = input()\ns2 = input()\n\ns3 = str(int(s1) + int(s2))\n\ns1 = s1.replace('0', '')\ns2 = s2.replace('0', '')\ns3 = s3.replace('0', '')\n\nif int(s1) + int(s2) == int(s3):\n print('YES')\nelse:\n print('NO')\n \t \t \t \t\t \t\t \t\t\t \t \t\t", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\n\r\nitoga=0\r\nitogb=0\r\nitogc=0\r\n\r\nia=1\r\nib=1\r\nic=1\r\nwhile a>0:\r\n a0=a%10 #Выделяем последнюю цифру\r\n if a0!=0: #Если последняя цифра НЕ равна нулю, выполняется:\r\n itoga=itoga+a0*ia #Здесь будет итоговая цифра без нулей. К итогу прибавляем последнюю, умноженную на единицу, десяток, сотню и т.д.\r\n ia=ia*10 #С каждым действием выводит единицу, десяток, сотню и т.д.(см. выше)\r\n a=a//10 #Убирает последнюю цифру из числа, чтоб перейти к следующей\r\n\r\nwhile b>0:\r\n b0=b%10\r\n if b0!=0:\r\n itogb=itogb+b0*ib\r\n ib=ib*10\r\n b=b//10\r\n\r\nwhile c>0:\r\n c0=c%10\r\n if c0!=0:\r\n itogc=itogc+c0*ic\r\n ic=ic*10\r\n c=c//10\r\n\r\nif itoga+itogb==itogc:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a=input()\r\nb=input()\r\nc=str(int(a)+int(b))\r\nx=a.replace(\"0\",\"\")\r\ny=b.replace(\"0\",\"\")\r\nz=c.replace(\"0\",\"\")\r\nX=int(x)+int(y)\r\nif X==int(z):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "rem = lambda a : int( str( a ).replace( '0' , '' ) )\r\na = int( input( ) )\r\nb = int( input( ) )\r\nif rem( a ) + rem( b ) == rem( a + b ) :\r\n print( \"YES\" )\r\nelse :\r\n print( \"NO\" )", "x = input()\r\ny = input()\r\n\r\nc = int(x) + int(y)\r\nc = str(c)\r\nc = int(c.replace('0', ''))\r\nx1, y1 = x, y\r\n\r\nx1 = int(x1.replace('0', ''))\r\ny1 = int(y1.replace('0', ''))\r\nc1 = int(x1 + y1)\r\n\r\nif c == c1:\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "def remove_zero_digit(n):\r\n number = 0\r\n i = 0\r\n while n > 0:\r\n if n % 10 == 0:\r\n n //= 10\r\n continue\r\n number = ((n % 10) * 10**i) + number\r\n i += 1\r\n n = n // 10\r\n return number\r\n\r\n\r\na = int(input())\r\nb = int(input())\r\n\r\nresult = a + b\r\n\r\nif remove_zero_digit(a) + remove_zero_digit(b) == remove_zero_digit(result):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n", "a, b = input(), input()\n\ns = int(a) + int(b)\n\na = a.replace('0', '')\nb = b.replace('0', '')\ns = str(s)\ns = s.replace('0', '')\nprint('YES' if int(s) == int(a) + int(b) else 'NO')\n", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nad = int(str(a).replace('0', ''))\r\nbd = int(str(b).replace('0', ''))\r\ncd = int(str(c).replace('0', ''))\r\nif ad + bd == cd:\r\n print('YES')\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nal = []\r\nbl = []\r\ncl = []\r\nwhile a > 0:\r\n x = a % 10\r\n if x == 0:\r\n a = str(a)\r\n a = a[::-1]\r\n a = a.replace('0', '', 1)\r\n a = a[::-1]\r\n a = int(a)\r\n else:\r\n x = str(x)\r\n al.append(x)\r\n a = a // 10\r\n\r\nal.reverse()\r\na_u = int(''.join(al))\r\n\r\nwhile b > 0:\r\n y = b % 10\r\n if y == 0:\r\n b = str(b)\r\n b = b[::-1]\r\n b = b.replace('0', '', 1)\r\n b = b[::-1]\r\n b = int(b)\r\n else:\r\n y = str(y)\r\n bl.append(y)\r\n b = b // 10\r\n\r\nbl.reverse()\r\nb_u = int(''.join(bl))\r\n\r\nwhile c > 0:\r\n z = c % 10\r\n if z == 0:\r\n c = str(c)\r\n c = c[::-1]\r\n c = c.replace('0', '', 1)\r\n c = c[::-1]\r\n c = int(c)\r\n else:\r\n z = str(z)\r\n cl.append(z)\r\n c = c // 10\r\n\r\ncl.reverse()\r\nc_u = int(''.join(cl))\r\n\r\nif a_u + b_u == c_u:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "def remove_zero(n):\r\n current = 0\r\n power = 0\r\n while (n>0):\r\n remainder = n % 10\r\n if remainder != 0:\r\n current = remainder * (10**power) + current\r\n power = power +1\r\n n = n//10\r\n \r\n return current\r\n\r\na = int(input()) \r\nb = int(input()) \r\nc = a + b\r\n\r\nremove_a = remove_zero(a)\r\nremove_b = remove_zero(b)\r\nremove_c = remove_zero(c)\r\n\r\nprint (\"YES\" if remove_c == (remove_a + remove_b) else \"NO\")", "n1 = int(input()) # 101\r\nn2 = int(input()) # 102\r\ns = n1 + n2 # 203\r\n\r\nd = \"\" #\"11\"\r\na = \"\" #\"12\" \r\nll = \"\" #\"23\"\r\n\r\nn11 = str(n1) #\"101\"\r\nn22 = str(n2) #\"102\"\r\ns33 = str(s) #\"203\"\r\n\r\nfor i in n11 : \r\n if i ==\"0\" : \r\n continue \r\n else : \r\n d += i \r\nfor k in n22 : \r\n if k ==\"0\" : \r\n continue \r\n else : \r\n a += k \r\nfor z in s33 : \r\n if z ==\"0\" : \r\n continue \r\n else : \r\n ll += z \r\n\r\nd = int(d) #11\r\na = int(a) #12\r\nzzz =str( d + a ) #\"23\" \r\nif zzz == ll : #\"23\" == \"23\" \r\n print(\"YES\")\r\nelse : \r\n print(\"NO\")\r\n\r\n ", "import re\r\nx = input()\r\ny = input()\r\nz = int(x)+int(y)\r\n\r\na = re.findall('[^0]',x)\r\nb = re.findall('[^0]',y)\r\nc = re.findall('[^0]',str(z))\r\n\r\nansa =''\r\nfor i in range(len(a)):\r\n\tansa = ansa + a[i]\r\nansb = ''\r\nfor i in range(len(b)):\r\n\tansb = ansb + b[i]\r\n\r\nansc = ''\r\nfor i in range(len(c)):\r\n\tansc = ansc + c[i]\r\n\r\nif (int(ansa)+int(ansb))==int(ansc):\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')\t\r\n", "def reverse(number):\r\n reverse_number = 0\r\n while (number != 0):\r\n reverse_number = reverse_number * 10 + number % 10\r\n number = (number - number % 10) / 10\r\n return int(reverse_number)\r\n\r\ndef delete_zeroes(number):\r\n ans = 0\r\n while (number != 0):\r\n if (number % 10 == 0):\r\n number = number / 10\r\n else:\r\n ans = ans * 10 + number % 10\r\n number = (number - number % 10) /10\r\n return (int(reverse(ans)))\r\n\r\na = int(input())\r\nb = int(input())\r\nc = a + b\r\nnew_a = delete_zeroes(a)\r\nnew_b = delete_zeroes(b)\r\nnew_c = delete_zeroes(c)\r\nif (new_a + new_b == new_c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n\r\n\r\n", "a,b=input(),input()\r\nc=int(a)+int(b);x=[];y=[];z=[]\r\nfor i in a:\r\n if i!='0':\r\n x.append(i)\r\nfor i in b:\r\n if i!='0':\r\n y.append(i)\r\nfor i in str(c):\r\n if i != '0':\r\n z.append(i)\r\nx=''.join(x); y = ''.join(y);z=''.join(z)\r\nd=int(x)+int(y)\r\nif int(z)==d:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "a = int(input())\r\nb = int(input())\r\nc = a+b\r\n\r\n\r\n\r\nac=(''.join([i for i in str(a) if i != \"0\"]))\r\nbc=(''.join([i for i in str(b) if i != \"0\"]))\r\ncc=(''.join([i for i in str(c) if i != \"0\"]))\r\n\r\nprint(\"YES\")if int(ac)+int(bc)==int(cc)else print(\"NO\")\r\n \r\n\r\n", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nawo = ''\r\nbwo = ''\r\ncwo = ''\r\nastr = str(a)\r\nbstr = str(b)\r\ncstr = str(c)\r\nfor i in range(len(astr)):\r\n if astr[i] != '0':\r\n awo += astr[i]\r\nfor i in range(len(bstr)):\r\n if bstr[i] != '0':\r\n bwo += bstr[i]\r\nfor i in range(len(cstr)):\r\n if cstr[i] != '0':\r\n cwo += cstr[i]\r\naiwo = int(awo)\r\nbiwo = int(bwo)\r\nciwo = int(cwo)\r\nprint('YES' if c == a + b and aiwo + biwo == ciwo else 'NO')\r\n", "a = input().strip()\r\nb = input().strip()\r\n\r\naa = a.replace('0', '')\r\nbb = b.replace('0', '')\r\n\r\nif int(str(int(a) + int(b)).replace('0', '')) == int(aa) + int(bb):\r\n print('YES')\r\nelse:\r\n print('NO')", "\"\"\"\r\n@auther:Abdallah_Gaber \r\n\"\"\"\r\nn1 = input()\r\nn2 = input()\r\nsum_n = int(n1) + int(n2)\r\nsum_n = str(sum_n)\r\n\r\nnum1 = n1.split('0')\r\nnum2 = n2.split('0')\r\nsum_num = sum_n.split('0')\r\n\r\nnew1 =int(''.join(num1))\r\nnew2 = int(''.join(num2))\r\nsum_new = int(''.join(sum_num))\r\nif new1 + new2 == sum_new:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = input()\r\nb = input()\r\nc = str(int(a) + int(b))\r\n\r\n\r\ndef remove_0(x):\r\n xx = \"\"\r\n for i in x:\r\n if i != '0':\r\n xx += i\r\n return int(xx)\r\n\r\n\r\nif remove_0(a) + remove_0(b) == remove_0(c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a, b = input(), input()\r\na, b, s = (int(x.replace('0', '')) for x in [a, b, str(int(a) + int(b))])\r\nprint('YES' if a + b == s else 'NO')\r\n\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\na = input()\r\nb = input()\r\nsum = str(int(a) + int(b))\r\na1 = a.replace('0','')\r\nb1 = b.replace('0','')\r\nsum1 = sum.replace('0','')\r\nprint('YES') if int(a1)+int(b1)==int(sum1) else print('NO')", "\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\ndef solve():\r\n a, = map(int, input().split())\r\n b, = map(int, input().split())\r\n\r\n print('YES' if int(str(a + b).replace('0', '')) == int(str(a).replace('0', '')) + int(str(b).replace('0', '')) else 'NO')\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nsolve()", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\nfa=''\r\nfb=''\r\nfc=''\r\nfor i in str(c):\r\n if int(i)!=0:\r\n fc+=i\r\nfor i in a:\r\n if int(i)!=0:\r\n fa+=i\r\nfor i in b:\r\n if int(i)!=0:\r\n fb+=i\r\na=int(a)\r\nb=int(b)\r\nfa=int(fa)\r\nfb=int(fb)\r\nfc=int(fc)\r\nif fa+fb==fc:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\nc_ans=str(c)\r\nc_ans=int(c_ans.replace(\"0\",\"\"))\r\na_ans=int(a.replace(\"0\",\"\"))\r\nb_ans=int(b.replace(\"0\",\"\"))\r\nif a_ans+b_ans==c_ans:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\n\r\na=str(a)\r\nb=str(b)\r\nc=str(c)\r\n\r\nc=c.replace(\"0\",\"\")\r\na=a.replace(\"0\",\"\")\r\nb=b.replace(\"0\",\"\")\r\n\r\nd=int(a)+int(b)\r\nd=str(d)\r\n\r\n# print(c,d)\r\nif c==d:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\t\r\n\r\n\r\n\r\n\r\n", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\nu=str(c)\r\nd=\"\"\r\nm=\"\"\r\ny=\"\"\r\nfor i in a:\r\n if i !=\"0\":\r\n d+=i\r\nfor i in b :\r\n if i !=\"0\":\r\n m+=i \r\nz=int(d)+int(m) \r\no=str(z)\r\nfor i in u:\r\n if i !=\"0\":\r\n y+=i\r\nif o==y:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") ", "a,b=input(),input()\r\nprint(\"YES\" if int(a.replace(\"0\",\"\"))+int(b.replace(\"0\",\"\"))==int(str(int(a)+int(b)).replace(\"0\",\"\")) else \"NO\")", "first = input()\r\nsecond = input()\r\n\r\n\r\ndmr = int(first) + int(second)\r\n\r\nf = \"\"\r\ns = \"\"\r\n\r\nfor i in first:\r\n\tif i== '0':\r\n\t\tcontinue\r\n\tf += i\r\n\r\n\r\nfor i in second:\r\n\tif i== '0':\r\n\t\tcontinue\r\n\ts += i\r\n \r\nd = \"\"\r\nfor i in str(dmr):\r\n\tif i== '0':\r\n\t\tcontinue\r\n\td += i\r\nif d == str(int(f) + int(s)):\r\n\tprint(\"YES\")\r\nelse:\r\n print(\"NO\")", "n1=int(input())\r\nn2=int(input())\r\nsum=n1+n2\r\nsum=str(sum)\r\nn1=str(n1)\r\nn2=str(n2)\r\nc=(n1.replace('0',''))\r\nv=(n2.replace('0',''))\r\nt=(sum.replace('0',''))\r\nif int(c)+int(v)==int(t):\r\n print('YES')\r\nelse:\r\n print('NO')", "a = int(input())\r\nb = int(input())\r\nc = a +b\r\nnewa, newb, newc = str(a), str(b), str(c)\r\nidx = 0\r\nwhile True:\r\n if idx == len(newa):\r\n break\r\n if newa[idx] == '0':\r\n newa = newa[:idx] + newa[idx+1:]\r\n else:\r\n idx+= 1\r\nidx = 0\r\nwhile True:\r\n if idx == len(newb):\r\n break\r\n if newb[idx] == '0':\r\n newb = newb[:idx] + newb[idx+1:]\r\n else:\r\n idx+= 1\r\nidx = 0\r\nwhile True:\r\n if idx == len(newc):\r\n break\r\n if newc[idx] == '0':\r\n newc = newc[:idx] + newc[idx+1:]\r\n else:\r\n idx+= 1\r\nif int(newa) + int(newb) == int(newc):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "#\\\\\\\r\na=input()\r\nb=input()\r\nx1,x2='',''\r\nx3=str(int(a)+int(b))\r\nx4=''\r\nfor i in range(len(a)):\r\n if a[i]!='0':\r\n x1+=a[i]\r\nfor i in range(len(b)):\r\n if b[i]!='0':\r\n x2+=b[i]\r\nif '0' in x3:\r\n for i in range(len(x3)):\r\n if x3[i]!='0':\r\n x4+=x3[i]\r\n if int(x1)+int(x2)==int(x4):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n if int(x1)+int(x2)==int(x3):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n#\\\\\\\r\n\r\n", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\na = str(a).replace(\"0\", \"\")\r\nb = str(b).replace(\"0\", \"\")\r\nc = str(c).replace(\"0\", \"\")\r\nif int(a) + int(b) == int(c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = input()\r\nm = input()\r\nn_ = ''\r\nm_ = ''\r\nr_ = ''\r\nr = str(int(n) + int(m))\r\n\r\nfor i in n :\r\n if i == \"0\" :\r\n continue\r\n else :\r\n n_ += i\r\nfor i in m :\r\n if i == \"0\" :\r\n continue\r\n else :\r\n m_ += i\r\nfor i in r :\r\n if i == \"0\" :\r\n continue\r\n else :\r\n r_ += i\r\n\r\nif int(m_) + int(n_) == int(r_):\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\")", "numone=input()\r\nnumtwo=input() \r\nres_with_zero=int(numone)+int(numtwo)\r\nnum1=str(numone).replace('0','')\r\nnum2=str(numtwo).replace('0','')\r\nres_without_zero=eval(num1+'+'+num2)\r\nres_with_zero=str(res_with_zero).replace('0','')\r\nprint('YES' if int(res_with_zero)==int(res_without_zero) else 'NO') ", "a=input()\nb=input()\nc=str(int(a)+int(b))\np=\"\"\nq=\"\"\nr=\"\"\np=p.join(a.split('0'))\nq=q.join(b.split('0'))\nr=r.join(c.split('0'))\nif(int(r)==int(p)+int(q)):\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n", "x = int(input())\r\ny = int(input())\r\nz = x + y\r\nr = 1\r\nk = 0\r\ni = 0\r\nn = [x, y, z]\r\nwhile i < 3:\r\n if n[i] == 0:\r\n n[i] = k\r\n k = 0\r\n i += 1\r\n r = 1\r\n if i < 3:\r\n while n[i] > 0:\r\n l = n[i] % 10\r\n if l != 0:\r\n n[i] = n[i] // 10\r\n k = k + r * l\r\n r = r * 10\r\n if l == 0:\r\n n[i] = n[i] // 10\r\nif n[0] + n[1] == n[2]:\r\n print('YES')\r\nelse:\r\n print('NO')", "x = (input())\r\ny = (input())\r\n\r\nans = int(x) + int(y)\r\nnewX = \"\"\r\nnewY = \"\"\r\nfor i in range(len(x)):\r\n if(x[i] != '0'):\r\n newX += x[i]\r\n\r\nfor i in range(len(y)):\r\n if(y[i] != '0'):\r\n newY += y[i] \r\n\r\nnewAns = \"\"\r\nans = str(ans)\r\nfor i in range(len(ans)):\r\n if(ans[i] != '0'):\r\n newAns += ans[i] \r\n\r\nif(int(newX)+int(newY) == int(newAns)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") ", "def solve():\r\n a = (input())\r\n b = (input())\r\n c = str(int(a) + int(b))\r\n a1 = ''\r\n b1 = ''\r\n c1 = ''\r\n for i in a:\r\n if i != '0':\r\n a1 += i\r\n for i in b:\r\n if i != '0':\r\n b1 += i\r\n for i in c:\r\n if i != '0':\r\n c1 += i\r\n if int(a1) + int(b1) == int(c1):\r\n print('YES')\r\n else:\r\n print('NO')\r\n\r\n\r\nfor _ in range(1):\r\n solve()\r\n", "n1 = int(input())\nn2 = int(input())\ns1 = n1+n2\nn1 = str(n1)\nn2 = str(n2)\ns1 = str(s1)\nn1 = n1.replace('0' , '')\nn2 = n2.replace('0' , '')\ns1 = s1.replace('0' , '')\nn1 = int(n1)\nn2 = int(n2)\nif n1 + n2 == int(s1):\n print(\"YES\")\nelse:\n print(\"NO\")\n \t \t \t\t\t\t\t\t \t \t \t \t\t", "i = input\r\na = i()\r\nb = i()\r\nc = str(int(a) + int(b))\r\na = a.replace('0', '')\r\nb = b.replace('0', '')\r\nc = c.replace('0', '')\r\nprint('YES' if int(a) + int(b) == int(c) else 'NO')", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\nw=a.translate({ord(i): None for i in '0'})\r\nx=b.translate({ord(i): None for i in '0'})\r\ny=str(c).translate({ord(i): None for i in '0'})\r\nd=int((w))+int(x)\r\nif int(y)==d:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\nm=int(input())\nans=n+m\nn1=list(str(n))\nm1=list(str(m))\n\nans1=list(str(ans))\na=''\nb=''\nc=''\n\nfor i in n1:\n\tif i!='0':\n\t\ta+=i\nfor i in m1:\n\tif i!='0':\n\t\tb+=i \n\nfor i in ans1:\n\tif i!='0':\n\t\tc+=i\n\nc=int(c)\na=int(a)\nb=int(b)\n\nan=a+b\n\nif an==c:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")", "a = int(input()); b = int(input())\r\nd = a+b\r\na = str(a); b = str(b)\r\na = a.replace('0', ''); b= b.replace('0','')\r\nc = str(d)\r\nc = c.replace('0', '')\r\n\r\n#print(a, b, c)\r\nif str(int(a)+int(b))==c: print(\"YES\")\r\nelse: print(\"NO\")\r\n", "def removezero(s):\r\n s=str(s)\r\n new=''\r\n for i in s:\r\n if i!='0':\r\n new=new+i\r\n return(int(new))\r\n \r\nn=int(input())\r\nk=int(input())\r\nif removezero(n)+removezero(k)==removezero(n+k):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "\r\ns1, s2 = input(), input()\r\nres = str(int(s1) + int(s2))\r\nif int(s1.replace('0', '')) + int(s2.replace('0', '')) == int(res.replace('0', '')):\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "def cambiar(cam):\r\n c = \"\"\r\n for i in cam:\r\n if i != \"0\":\r\n c+=i\r\n return c\r\n\r\na = input()\r\nb = input()\r\nc = int(a)\r\nd = int(b)\r\nr1 = c+d\r\ncc = int(cambiar(a))\r\ncb = int(cambiar(b))\r\nr1 = int(cambiar(str(r1)))\r\nr2 = cc+cb\r\nif r1 == r2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = input()\r\nb = input()\r\nsum = int(a) + int(b)\r\nsum = str(sum)\r\nc = \"\"\r\nfor i in a:\r\n if i != '0':\r\n c += i\r\nd = \"\"\r\nfor i in b:\r\n if i != '0':\r\n d += i\r\ne = \"\"\r\nfor i in sum:\r\n if i != '0':\r\n e += i\r\nc = int(c)\r\nd = int(d)\r\ne = int(e)\r\nif c + d == e:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = int(input())\r\nb = int(input())\r\n\r\nd = a + b\r\n\r\na = str(a)\r\nb = str(b)\r\nd = str(d)\r\na = a.replace(\"0\", \"\")\r\nb = b.replace(\"0\", \"\")\r\nd = d.replace(\"0\", \"\")\r\n\r\n\r\nif int(a) + int(b) == int(d):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=str(input())\r\nb=str(input())\r\nc=str(int(a)+int(b))\r\nc=c.replace(\"0\",\"\")\r\na=a.replace(\"0\",\"\")\r\nb=b.replace(\"0\",\"\")\r\np=int(a)+int(b)\r\nif p==int(c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = input()\r\nm = input()\r\n\r\nn1 = n.replace('0', '')\r\nm1 = m.replace('0', '')\r\n\r\n# print(n1, m1)\r\n\r\nn2 = int(n)\r\nm2 = int(m)\r\nn11 = int(n1)\r\nm11 = int(m1)\r\n\r\nin_sum = str(n2 + m2)\r\nz_sum = str(n11 + m11)\r\n\r\n# print(in_sum, z_sum)\r\n\r\nif in_sum.replace('0', '') == z_sum:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "one = input()\ntwo = input()\nvalue = str(int(one) + int(two))\nif int(one.replace('0', '')) + int(two.replace('0','')) == int(value.replace('0','')):\n print('YES')\nelse:\n print(\"NO\")", "a=input('')\r\nb=input('')\r\nq=0\r\nl=0\r\nt=[]\r\nk=[]\r\nu=0\r\nn=0\r\np=0\r\nf=0\r\nh=[]\r\njp=0\r\new=0\r\nm=0\r\nd=int(a)+int(b)\r\nfor i in range(len(a)):\r\n if(not(a[q]=='0')):\r\n t.append(int(a[q]))\r\n q=q+1\r\nfor j in range(len(b)):\r\n if(not(b[l]=='0')):\r\n k.append(int(b[l]))\r\n l=l+1\r\n1,1\r\n1,2\r\nw=len(k)\r\ns=len(t)\r\nfor x in range(len(t)):\r\n n=n+(t[s-1]*(10**(p)))\r\n p=p+1\r\n s=s-1\r\nfor y in range(len(k)):\r\n f=f+(k[w-1]*(10**(u)))\r\n u=u+1\r\n w=w-1\r\nr=str(d)\r\nfor xl in range(len(r)):\r\n if(not(r[jp]=='0')):\r\n h.append(int(r[jp]))\r\n jp=jp+1\r\nc=len(h)\r\nfor sutt in range(len(h)):\r\n m=m+(h[c-1]*(10**(ew)))\r\n ew=ew+1\r\n c=c-1\r\nif(m==n+f):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n\r\n\r\n\r\n\r\n \r\n", "n1 = int(input())\nn2 = int(input())\ns = n1 + n2\nn12 = int(str(n1).replace('0', ''))\nn22 = int(str(n2).replace('0', ''))\ns2 = int(str(s).replace('0',''))\nif n12 + n22 == s2:\n print('YES')\nelse:\n print('NO')", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\nif int(str(a).replace('0','')) + int(str(b).replace('0','')) == int(str(c).replace('0','')) : \r\n print('YES')\r\nelse :\r\n print('NO')", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nst = str(a) + \"+\" + str(b) + \"=\" + str(c)\r\nst1 = list(st)\r\nfor i in range(0, st1.count(str(0))):\r\n st1.remove(str(0))\r\nst1 = \"\".join(st1)\r\nst1 = st1.split(\"+\")\r\na = int(st1[0])\r\nst1 = st1[1].split(\"=\")\r\nb = int(st1[0])\r\nc = int(st1[1])\r\ncheck = bool(a + b == c)\r\nif a + b == c:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b \r\ndef hello():\r\n first=\"\"\r\n for i in str(a):\r\n if i!=\"0\":first=first+i \r\n second=\"\"\r\n for i in str(b):\r\n if i!=\"0\":second=second+i\r\n third=\"\"\r\n for i in str(c):\r\n if i!=\"0\":third=third+i\r\n if int(first)+int(second)==int(third):\r\n return \"YES\"\r\n else:\r\n return \"NO\"\r\nprint(hello())", "a = input()\r\nb = input()\r\nc = str(int(a)+int(b)).replace(\"0\", \"\")\r\nd = int(a.replace(\"0\", \"\"))+int(b.replace(\"0\", \"\"))\r\nif int(c) == d:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = input()\r\nb = input()\r\nc = int(''.join(str(int(a) + int(b)).split('0')))\r\nz = int(''.join(a.split('0'))) + int(''.join(b.split('0')))\r\nif c == z:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a = input()\r\nb = input()\r\nc = int(a) + int(b)\r\n\r\nnew_a = int(str(a).replace('0', ''))\r\nnew_b = int(str(b).replace('0', ''))\r\nnew_c = int(str(c).replace('0', ''))\r\n\r\nprint(\"YES\" if new_a + new_b == new_c else \"NO\")", "x=input()\r\ny=input()\r\nz=str(int(x)+int(y))\r\nif \"0\" in x or \"0\" in y or \"0\" in z:\r\n a=x.replace(\"0\",\"\")\r\n b=y.replace(\"0\",\"\")\r\n c=z.replace(\"0\",\"\")\r\n bh=str(int(a)+int(b))\r\n if bh==c:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n", "a,b=input(),input()\r\nprint((\"NO\",\"YES\")[str(int(a)+int(b)).replace(\"0\",\"\")==str(int(a.replace(\"0\",\"\"))+int(b.replace(\"0\",\"\")))])", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nnew_a = new_b = new_c = ''\r\nfor i in str(a):\r\n if i!='0':\r\n new_a += i\r\nfor i in str(b):\r\n if i!='0':\r\n new_b += i\r\nfor i in str(c):\r\n if i!='0':\r\n new_c += i\r\nif int(new_a) + int(new_b) == int(new_c):\r\n print('YES')\r\nelse:\r\n print('NO')", "aa = input()\r\nbb = input()\r\na = int(aa.replace('0', ''))\r\nb = int(bb.replace('0', ''))\r\nc = int(str(int(aa) + int(bb)).replace('0', ''))\r\nif a + b == c:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\nb = input()\r\nc = int(a) + int(b)\r\nnew_a = ''\r\nnew_b = ''\r\nnew_c = ''\r\n\r\nfor char in a:\r\n if char != '0':\r\n new_a += char\r\nfor char in b:\r\n if char != '0':\r\n new_b += char\r\nfor char in str(c):\r\n if char != '0':\r\n new_c += char\r\nif int(new_a) + int(new_b) == int(new_c):\r\n print('YES')\r\nelse:\r\n print('NO')", "a = int(input())\r\nb = int(input())\r\nwithz = a+b\r\nres = \"\"\r\nfor cur in str(withz):\r\n if cur!=\"0\":\r\n res += cur\r\n\r\na1 = \"\"\r\nb1 = \"\"\r\nfor cur in str(a):\r\n if cur!=\"0\":\r\n a1 += cur\r\n\r\nfor cur in str(b):\r\n if cur!=\"0\":\r\n b1 += cur\r\n\r\nprint(\"YES\" if int(res) == int(a1)+int(b1) else \"NO\")", "def main():\n first, second = input(), input()\n sumWithZero = int(first) + int(second)\n first = [char for char in list(first) if char != '0']\n second = [char for char in list(second) if char != '0']\n firstRes = [char for char in list(str(sumWithZero)) if char != '0']\n\n if (int(''.join(first)) + int(''.join(second))) == int(''.join(firstRes)):\n print(\"YES\")\n else:\n print(\"NO\")\n\n\nif __name__ == '__main__':\n main()\n", "def remove_zeros(n):\n\tnum = 0\n\twhile n!=0:\n\t\tremainder = n%10\n\t\tif remainder == 0:\n\t\t\tn //= 10\n\t\t\tcontinue\n\t\tnum = num*10 + remainder\n\t\tn //= 10\n\t\n\treverse = 0\n\twhile num!=0:\n\t\tdigit = num%10\n\t\treverse = reverse*10 + digit\n\t\tnum //=10\n\treturn reverse\t\n\n\n\na = int(input())\nb = int(input())\n\nsum_before_removing = a+b\n\na = remove_zeros(a)\nb = remove_zeros(b)\nsum_after_removing = remove_zeros(sum_before_removing)\nif a+b == sum_after_removing:\n\tprint('YES')\nelse:\n\tprint('NO')", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\na=int(str(a).replace(\"0\",\"\"))\r\nb=int(str(b).replace(\"0\",\"\"))\r\nif a+b==int(str(c).replace(\"0\",\"\")):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n1 = int(input())\r\nn2 = int(input())\r\nsum = n1+n2\r\ns1= str(n1).replace(\"0\",\"\")\r\ns2 = str(n2).replace(\"0\",\"\")\r\nsum1 = str(sum).replace(\"0\",\"\")\r\nprint(\"YES\" if int(s1) + int(s2) == int(sum1) else \"NO\")", "from sys import stdin, stdout\r\na = stdin.readline().strip()\r\nb = stdin.readline().strip()\r\nsum_1 = int(a)+int(b)\r\nnum_1 = 0\r\nnum_2 = 0\r\nfor j in a:\r\n if j=='0':\r\n pass\r\n else:\r\n num_1=(num_1*10 + int(j))\r\nfor j in b:\r\n if j=='0':\r\n pass\r\n else:\r\n num_2 = (num_2*10 + int(j))\r\nsum_2 = num_1 + num_2\r\nsum_3 = str(sum_1)\r\nnew_num = 0\r\nfor j in sum_3:\r\n if j=='0':\r\n pass\r\n else:\r\n new_num = (new_num*10 + int(j))\r\n# print(new_num, sum_2)\r\nif new_num==sum_2:\r\n stdout.write(\"YES\")\r\nelse:\r\n stdout.write(\"NO\")\r\n", "a=input()\r\nb=input()\r\nsum=list(str(int(a)+int(b)))\r\na,b=list(a),list(b)\r\nfor i in range(a.count('0')):\r\n a.remove('0')\r\nfor i in range(b.count('0')):\r\n b.remove('0')\r\nfor i in range(sum.count('0')):\r\n sum.remove('0')\r\na=''.join(a)\r\nb=''.join(b)\r\nsum=''.join(sum)\r\nif int(a)+int(b)==int(sum):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "first_num = input ()\r\nsecond_num = input ()\r\ntotal = str (int (first_num) + int (second_num))\r\n\r\nfirst_list = []\r\nsecond_list = []\r\nthird_list = []\r\n\r\nlength = len (first_num)\r\nnumber = first_num\r\nindex = 0\r\n\r\nwhile (length > 0):\r\n first_list.append(number [index])\r\n index += 1\r\n length -= 1\r\n if ('0' in first_list):\r\n first_list.remove ('0')\r\nfirst_list = int (''.join (map (str, first_list)))\r\n\r\n\r\nlength = len (second_num)\r\nnumber = second_num\r\nindex = 0\r\n\r\nwhile (length > 0):\r\n second_list.append (number [index])\r\n index += 1\r\n length -= 1\r\n if ('0' in second_list):\r\n second_list.remove ('0')\r\nsecond_list = int (''.join (map (str, second_list)))\r\n\r\nlength = len (total)\r\nnumber = total\r\nindex = 0\r\n\r\nwhile (length > 0):\r\n third_list.append (number [index])\r\n index += 1\r\n length -= 1\r\n if ('0' in third_list):\r\n third_list.remove ('0')\r\nthird_list = int (''.join (map (str, third_list)))\r\n\r\nif (first_list + second_list == third_list):\r\n print ('YES')\r\nelse: \r\n print ('NO')", "n=int(input())\r\nm=int(input())\r\ns=m+n\r\ns=str(s)\r\nm=str(m)\r\nn=str(n)\r\ns=s.replace('0','')\r\nm=m.replace('0','')\r\nn=n.replace('0','')\r\ns=int(s)\r\nm=int(m)\r\nn=int(n)\r\nif s==(m+n):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\r\nb=input()\r\nc=str(int(a)+int(b))\r\n\r\nm=\"\"\r\nn=\"\"\r\nr=\"\"\r\nfor i in range(len(a)):\r\n if a[i]!=\"0\":\r\n m=m+a[i]\r\nfor i in range(len(b)):\r\n if b[i]!=\"0\":\r\n n=n+b[i]\r\nfor i in range(len(c)):\r\n if c[i]!=\"0\":\r\n r=r+c[i]\r\nif int(m)+int(n)==int(r):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\nb = input()\r\nc = str(int(a)+int(b))\r\nca = a.replace('0', '')\r\ncb = b.replace('0', '')\r\ncc = c.replace('0', '')\r\nmore_c = str(int(ca)+ int(cb))\r\nif(more_c == cc):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "# import sys\r\n# sys.stdin = open('input.txt', 'r') \r\n# sys.stdout = open('output.txt', 'w')\r\n\r\na = input()\r\nb = input()\r\n\r\nc = int(a)+int(b)\r\ncc = \"\"\r\n\r\nfor i in str(c):\r\n\tif i!='0':\r\n\t\tcc+=i\r\n\r\nd = \"\"\r\nfor i in a:\r\n\tif i!='0':\r\n\t\td+=i\r\ne = \"\"\r\nfor i in b:\r\n\tif i!='0':\r\n\t\te+=i\r\n\r\nf = str(int(d)+int(e))\r\n\r\nif cc==f:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "san1 = int(input())\r\nsan2 = int(input())\r\nres = san1+san2\r\nresult1 = ''\r\nresult2 = ''\r\nresult3 = ''\r\nfor i in str(san1):\r\n if i !='0':\r\n result1+=i\r\nfor i in str(san2):\r\n if i !='0':\r\n result2+=i\r\nfor i in str(res):\r\n if i !='0':\r\n result3+=i\r\nres2 = int(result1)+int(result2)\r\nif res2 == int(result3):\r\n print('YES')\r\nelse:\r\n print('NO')", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nra, rb, rc = 0, 0, 0\r\nwhile a:\r\n if a%10 != 0:\r\n ra = 10 * ra + a%10\r\n a //= 10\r\nwhile b:\r\n if b%10 != 0:\r\n rb = 10 * rb + b%10\r\n b //= 10\r\nwhile c:\r\n if c%10 != 0:\r\n rc = 10 * rc + c%10\r\n c //= 10\r\nif int(str(rc)[::-1]) == int(str(ra)[::-1]) + int(str(rb)[::-1]):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\na = input()\r\nb = input()\r\nsum = int(a) + int(b)\r\na1 = ''\r\nb1 = ''\r\nsum1 = ''\r\nfor i in a: \r\n if i!='0': a1+=i\r\nfor i in b: \r\n if i!='0': b1+=i \r\nfor i in str(sum):\r\n if i!='0': sum1+=i\r\nprint('YES') if int(a1)+int(b1)==int(sum1) else print('NO')", "def st(a):\r\n s=str(a)\r\n k=''\r\n for i in s:\r\n if i=='0':\r\n continue\r\n k+=i\r\n return int(k)\r\ndef solve():\r\n a=int(input())\r\n b=int(input())\r\n s=a+b\r\n if(st(a+b)==st(a)+st(b)):\r\n print('YES')\r\n else:\r\n print('NO')\r\nif __name__=='__main__':\r\n solve()", "x = int(input())\r\ny = int(input())\r\nR = x + y\r\nx1 = str(x).replace(\"0\",\"\")\r\ny1 = str(y).replace(\"0\",\"\")\r\nR1 = int(x1) + int(y1)\r\n\r\nif R1 == int(str(R).replace(\"0\",\"\")):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = int(input())\r\nb = int(input())\r\nans = a+b\r\nnew_ans = \"\"\r\nfor i in str(ans):\r\n if (i != '0'):\r\n new_ans += i\r\nnew_a = \"\"\r\nfor i in str(a):\r\n if (i != '0'):\r\n new_a += i\r\nnew_b = \"\"\r\nfor i in str(b):\r\n if (i != '0'):\r\n new_b += i\r\nnew_a,new_b = int(new_a),int(new_b)\r\nans1 = new_a+new_b\r\nif (int(new_ans) == ans1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=input()\nb=input()\ns=int(a)+int(b)\na=a.replace('0','')\nb=b.replace('0','')\nc=int(a)+int(b)\n\ns=str(s)\ns=s.replace('0','')\ns=int(s)\nif c==s:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")", "a=int(input())\r\nb=int(input()) \r\n\r\nc=a+b\r\n\r\nk=int(str(a).replace(\"0\",\"\"))\r\nb=int(str(b).replace(\"0\",\"\"))\r\n\r\nr=k+b\r\n \r\nif int(str(c).replace(\"0\",\"\"))==r:\r\n print(\"YES\")\r\n\r\nelse:\r\n print(\"NO\")\r\n \r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n\r\n \r\n\r\n\r\n\r\n \r\n", "\r\ndef solve(s1: int, s2: int) -> str:\r\n sum1 = int(s1) + int(s2)\r\n d = str(sum1)\r\n ans = d.replace('0','')\r\n x = s1.replace('0','')\r\n y = s2.replace('0','')\r\n final = int(x)+int(y)\r\n return ('YES' if final == int(ans) else 'NO')\r\n\r\n\r\ns1 = input()\r\ns2 = input()\r\nprint(solve(s1, s2))", "\r\n\r\n# https://codeforces.com/contest/75/problem/A\r\na = int(input())\r\nb = int(input())\r\nc = a + b\r\n\r\nstra = str(a)\r\nstrb = str(b)\r\nstrc = str(c)\r\n\r\na0 = stra.replace('0', '')\r\nb0 = strb.replace('0', '')\r\nc0 = strc.replace('0', '')\r\n\r\ncA = int(a0) + int(b0)\r\nc0 = int(c0)\r\n\r\nif (c0 == cA):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "# https://codeforces.com/problemset/problem/75/A\n\na = input()\nb = input()\nresult_one = str(int(a) + int(b))\na = a.replace(\"0\", \"\")\nb = b.replace(\"0\", \"\")\nresult_two = str(int(a) + int(b))\n\nif result_one.replace(\"0\", \"\") == result_two:\n print(\"YES\")\nelse:\n print(\"NO\")", "a,b=input(),input()\r\nprint(\"YES\"if str(int(a)+int(b)).replace(\"0\",\"\")==str(int(a.replace(\"0\",\"\"))+int(b.replace(\"0\",\"\"))) else \"NO\")\r\n", "n1 = int(input())\nn2 = int(input())\nsum = n1 + n2\nn1 , n2 , sum = str(n1) , str(n2) , str(sum)\nn1 =n1.replace(\"0\",\"\")\nn2 = n2.replace(\"0\", \"\")\nsum = sum.replace(\"0\", \"\")\nn1 , n2 , sum = int(n1) , int(n2) , int(sum)\nsum1 = (n1) + n2\nif sum1 == sum :\n print(\"YES\")\nelse:\n print(\"NO\")\n \t\t\t \t\t \t \t \t \t \t\t \t \t\t", "a, b = input(), input()\nf = lambda y: int(''.join(x for x in y if x != '0'))\nprint('YES' if f(a) + f(b) == f(str(int(a) + int(b))) else 'NO')", "a = str(input())\r\nb = str(input())\r\nc = str(int(a)+int(b))\r\ni = 0\r\naa = ''\r\nbb = ''\r\ncc = ''\r\ni = 0\r\nwhile i < len(a):\r\n if a[i]=='0':\r\n i+=1\r\n else :\r\n aa = aa + a[i]\r\n i+=1\r\ni = 0\r\nwhile i < len(b):\r\n if b[i]=='0':\r\n i+=1\r\n else :\r\n bb = bb + b[i]\r\n i+=1\r\ni = 0\r\nwhile i < len(c):\r\n if c[i]=='0':\r\n i+=1\r\n else :\r\n cc = cc + c[i]\r\n i+=1\r\nif int(aa)+int(bb)==int(cc):\r\n print('YES')\r\nelse :\r\n print('NO')", "a = int(input())\r\nb = int(input())\r\ns1 = a+b\r\nwa = ''\r\nfor c in str(a):\r\n if c!='0':\r\n wa+=c\r\nwb = \"\" \r\nfor c in str(b):\r\n if c!='0':\r\n wb+=c\r\n\r\ns2 = \"\" \r\nfor c in str(s1):\r\n if c!='0':\r\n s2+=c \r\nif (int(wa)+int(wb))==int(s2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = input()\r\nm = input()\r\ns = str(int(n) + int(m))\r\nn = [i for i in n if i != \"0\"]\r\nm = [i for i in m if i != \"0\"]\r\ns = [i for i in s if i != \"0\"]\r\n\r\n\r\nif int(\"\".join(n)) + int(\"\".join(m)) == int(\"\".join(s)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "num1_str = input()\r\nnum2_str = input()\r\n\r\nold_value = \"\".join(str(int(num1_str) + int(num2_str)).split(\"0\"))\r\nnew_value = int(\"\".join(num1_str.split(\"0\"))) + int(\"\".join(num2_str.split(\"0\")))\r\n\r\nif int(old_value) == new_value:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def removeZeros(n):\r\n\tans = 0\r\n\tbase = 1\r\n\t\r\n\twhile (n > 0):\r\n\t\tdigit = n % 10\r\n\t\tif (digit != 0):\r\n\t\t\tans += digit * base\r\n\t\t\tbase *= 10\r\n\t\tn //= 10\r\n\t\t\r\n\treturn ans\r\n\r\na = int(input())\r\nb = int(input())\r\ns = a + b\r\n\r\nnew_a = removeZeros(a)\r\nnew_b = removeZeros(b)\r\nnew_s = removeZeros(s)\r\nif (new_a + new_b == new_s):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "a=str(input())\r\nb=str(input())\r\nc1=int(a)+int(b)\r\ns=str(c1)\r\na=a.replace(\"0\",\"\")\r\nb=b.replace(\"0\",\"\")\r\ns=s.replace(\"0\",\"\")\r\nif((int(a)+int(b))==int(s)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def handle(s):\r\n s = ''.join(filter(lambda x: x != '0', s))\r\n if len(s) == 0:\r\n s = '0'\r\n return s\r\n\r\n\r\nif __name__ == '__main__':\r\n a, b = input(), input()\r\n c = str(int(a) + int(b))\r\n \r\n a = handle(a)\r\n b = handle(b)\r\n new_c = int(handle(c))\r\n ans = int(a) + int(b)\r\n\r\n if ans == new_c:\r\n print('YES')\r\n else:\r\n print('NO')", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\na=str(a)\r\nb=str(b)\r\nc=str(c)\r\na1=\"\"\r\nb1=\"\"\r\nc12=\"\"\r\nfor i in range(len(a)):\r\n if a[i]!=\"0\":\r\n a1+=a[i]\r\nfor i in range(len(b)):\r\n if b[i]!=\"0\":\r\n b1+=b[i]\r\nfor i in range(len(c)):\r\n if c[i]!=\"0\":\r\n c12+=c[i]\r\nc1=int(a1)+int(b1)\r\nif int(c12)==c1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\r\nb=input()\r\nc=str(int(a)+int(b))\r\n\r\na=a.replace(\"0\",\"\")\r\nb=b.replace(\"0\",\"\")\r\nc=c.replace(\"0\",\"\")\r\nk=str(int(a)+int(b))\r\n#print(k,c)\r\n\r\nprint(\"YES\" if (c==k) else \"NO\")\r\n", "a = input()\r\nb = input()\r\nres = int(a)+int(b)\r\na = a.replace('0','')\r\nb = b.replace('0','')\r\nnewres = int(a)+int(b)\r\n#print(res,newres)\r\nif(int(str(res).replace('0',''))==newres):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def lifewithoutzeroes():\r\n num1=str(input())\r\n num2=str(input())\r\n sum1=str(int(int(num1)+int(num2)))\r\n num11=''\r\n num22=''\r\n sum11=''\r\n i=0\r\n while i<len(num1) or i<len(num2) or i<len(sum1):\r\n if i<len(num1) and num1[i]!='0': \r\n num11=num11+num1[i]\r\n if i<len(num2) and num2[i]!='0':\r\n num22=num22+num2[i]\r\n if i<len(sum1) and sum1[i]!='0':\r\n sum11=sum11+sum1[i]\r\n i=i+1\r\n if str(int(num11)+int(num22))==sum11:\r\n return 'YES'\r\n else:\r\n return 'NO'\r\nprint(lifewithoutzeroes())", "num1 = input()\r\nnum2 = input()\r\n\r\nif(int(num1.replace('0',''))+int(num2.replace('0','')) == int(str((int(num1)+int(num2))).replace('0',''))):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\na1=str(a)\r\nb1=str(b)\r\nc1=str(c)\r\na2=[]\r\nb2=[]\r\nc2=[]\r\na3=0\r\nb3=0\r\nc3=0\r\nfor i in range(len(a1)):\r\n if a1[i]!=\"0\":\r\n s=int(a1[i])\r\n a2=a2+[s]\r\nfor i in range(len(b1)):\r\n if b1[i]!=\"0\":\r\n s=int(b1[i])\r\n b2=b2+[s]\r\nfor i in range(len(c1)):\r\n if c1[i]!=\"0\":\r\n s=int(c1[i])\r\n c2=c2+[s]\r\nst1=len(a2)-1\r\nfor i in range(len(a2)):\r\n a3=a3+a2[i]*(10**st1)\r\n st1=st1-1\r\nst2=len(b2)-1\r\nfor i in range(len(b2)):\r\n b3=b3+b2[i]*(10**st2)\r\n st2=st2-1\r\nst3=len(c2)-1\r\nfor i in range(len(c2)):\r\n c3=c3+c2[i]*(10**st3)\r\n st3=st3-1\r\nif c3==(a3+b3):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n", "a = str(input())\r\nb = str(input())\r\nc = str(int(a) + int(b))\r\n\r\na1 = ''\r\nb1 = ''\r\nc1 = ''\r\n\r\nfor i in a : \r\n if(i == '0'):\r\n continue\r\n else:\r\n a1 += i\r\n\r\nfor j in b : \r\n if(j == '0'):\r\n continue\r\n else:\r\n b1 += j\r\n\r\n\r\nfor l in c : \r\n if(l == '0'):\r\n continue\r\n else:\r\n c1 += l\r\n\r\n\r\nif(int(a1) + int(b1) == int(c1)):\r\n print('YES')\r\nelse:\r\n print('NO')", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\na = list(map(int, list(str(a))))\r\nb = list(map(int, list(str(b))))\r\nc = list(map(int, list(str(c))))\r\na = list(filter(lambda x: x != 0, a))\r\nb = list(filter(lambda x: x != 0, b))\r\nc = list(filter(lambda x: x != 0, c))\r\ns1 = int(''.join(map(str, a)))\r\ns2 = int(''.join(map(str, b)))\r\ns3 = int(''.join(map(str, c)))\r\nif s1 + s2 == s3:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\na2 = ''\r\nb2 = ''\r\nc2 = ''\r\na1, b1 = a, b\r\nwhile a > 0:\r\n if a % 10 != 0:\r\n a2 += str(a % 10)\r\n a = a // 10\r\nwhile b > 0:\r\n if b % 10 != 0:\r\n b2 += str(b % 10)\r\n b = b // 10\r\nwhile c > 0:\r\n if c % 10 != 0:\r\n c2 += str(c % 10)\r\n c = c // 10\r\nc1 = int(b2[::-1]) + int(a2[::-1])\r\nif int(c2[::-1]) == c1:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "x = input(); y = input()\r\nSum = int(x) + int(y)\r\nif int(str(Sum).replace('0','')) == int(x.replace('0','')) + int(y.replace('0','')):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = int(input())\r\nb = int(input())\r\nc = a+b\r\nc = str(c)\r\nc1 = c.replace('0','')\r\nc1 = int(c1)\r\nif a > 0 and b > 0:\r\n a = str(a)\r\n b = str(b)\r\n a = a.replace('0','')\r\n b = b.replace('0','')\r\n a = int(a)\r\n b = int(b)\r\n if a+b == c1:\r\n print('YES')\r\n else:\r\n print('NO')\r\n", "a = int(input())\r\nb = int(input())\r\nprint(\"YES\" if eval(f\"{a} + {b} == {a+b}\".replace(\"0\", \"\")) else \"NO\")", "\r\ndef getAns(oldstring):\r\n string = ''\r\n for i in oldstring:\r\n if i != '0':\r\n string = string + i\r\n return string\r\n\r\nstr1 = input()\r\nstr2 = input()\r\n\r\nnewstr1 = getAns(str1)\r\nnewstr2 = getAns(str2)\r\n\r\nsum1 = int(newstr1) + int(newstr2)\r\n\r\nsum2 = int(str1) + int(str2)\r\n\r\nsum2 = getAns(str(sum2))\r\n\r\nif (sum1 == int(sum2)):\r\n print('YES')\r\nelse:\r\n print('NO')", "a=input()\r\nb=input()\r\na1=int(a.replace(\"0\",\"\"))\r\nb1=int(b.replace(\"0\",\"\"))\r\nc=int(a)+int(b)\r\nc1=str(c)\r\nc1=int(c1.replace(\"0\",\"\"))\r\nif a1+b1==c1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\nb = input()\r\n\r\nc = a.replace('0','')\r\nd = b.replace('0','')\r\n\r\n#print (a,b,c,d)\r\ne = str(int(a) + int(b))\r\n#e = e + ''\r\ne = e.replace('0','')\r\nf = str(int(c) + int(d))\r\nif e == f:\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\")", "a = input()\r\nb = input()\r\nc = str(int(a) + int(b))\r\nalist = []\r\nblist = []\r\nclist = []\r\nfor i in range(len(a)):\r\n if a[i] != \"0\":\r\n alist.append(a[i])\r\nfor i in range(len(b)):\r\n if b[i] != \"0\":\r\n blist.append(b[i])\r\nfor i in range(len(c)):\r\n if c[i] != \"0\":\r\n clist.append(c[i])\r\nnewa = \"\".join(alist)\r\nnewb = \"\".join(blist)\r\nnewc = \"\".join(clist)\r\nif int(newa) + int(newb) == int(newc):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\ng=a.replace('0','')\r\nh=b.replace('0','')\r\ni=str(c).replace('0','')\r\nif int(g)+int(h)==int(i):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def countDigit(n):\r\n count = 0\r\n output = 1\r\n while(n > 0):\r\n d = n % 10\r\n n //= 10\r\n if d != 0:\r\n count = count + d * output\r\n output *= 10\r\n return count\r\na = int(input())\r\nb = int(input())\r\nif countDigit(a) + countDigit(b) == countDigit(a + b):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\nb = input()\r\nc = int(a) + int(b)\r\n\r\ndef remove_zero(x):\r\n refactored_x = \"\"\r\n for i in x:\r\n if int(i) != 0:\r\n refactored_x += i\r\n return int(refactored_x)\r\n\r\n\r\nif remove_zero(str(c)) == remove_zero(a) + remove_zero(b):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "\r\ninput1 = input()\r\ninput2 = input()\r\na = str(int(input1)+int(input2))\r\ninput0 = \"\"\r\ninput3 = \"\"\r\nfor i in range(len(input1)):\r\n if input1[i] != \"0\":\r\n input0 += input1[i]\r\nfor k in range(len(input2)):\r\n if input2[k] != \"0\":\r\n input3 += input2[k]\r\na1 = \"\"\r\nfor j in a:\r\n if j != \"0\":\r\n a1 += j\r\nif (int(input0)+int(input3))==int(a1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\nb = input()\nc = str(int(a) + int(b))\na2 = int(\"\".join(a.split(\"0\")))\nb2 = int(\"\".join(b.split(\"0\")))\nc2 = int(\"\".join(c.split(\"0\")))\nprint([\"NO\", \"YES\"][a2 + b2 == c2])\n", "a = input()\r\nb = input()\r\n\r\ns1 = ''\r\ns2 = ''\r\n\r\nfor i in a:\r\n if i!='0': s1 += i\r\nfor j in b:\r\n if j!='0': s2 += j\r\n\r\nc = int(a) + int(b)\r\ns3 = ''\r\nfor k in str(c):\r\n if k!='0': s3 += k\r\n\r\nif int(s3) == int(s1) + int(s2): print('YES')\r\nelse: print('NO')", "def no_zeros(s) :\r\n new_s = []\r\n for c in s :\r\n if c != \"0\" :\r\n new_s.append(c)\r\n return \"\".join(new_s)\r\n\r\na = input()\r\nb = input()\r\n\r\nc = str(int(a) + int(b))\r\n\r\na = no_zeros(a)\r\nb = no_zeros(b)\r\nc = no_zeros(c)\r\n\r\nif int(a) + int(b) == int(c) :\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\")", "def remove_zeros(x):\r\n new_x = 0\r\n ten = 1\r\n while x:\r\n digit = x%10\r\n x //= 10\r\n if digit:\r\n new_x += digit*ten\r\n ten *= 10\r\n return new_x\r\n\r\na = int(input())\r\nb = int(input())\r\nc = a+b\r\n\r\nif remove_zeros(a) + remove_zeros(b) == remove_zeros(c): \r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = int(input())\nb = int(input())\nc = a + b\n\ndef convert(num: int) -> int:\n sum = 0\n pow = 1\n while num > 0:\n if num % 10 > 0:\n sum += num % 10 * pow\n pow *= 10\n num //= 10\n return sum\n \nif convert(a) + convert(b) == convert(c):\n print(\"YES\")\nelse:\n print(\"NO\")\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 = a + b\r\ndegree = 0 # степени числа\r\na_no_zero = 0\r\nwhile a > 0:\r\n last = a % 10\r\n if last != 0:\r\n last = last * 10**degree\r\n a_no_zero = a_no_zero + last\r\n degree += 1\r\n a //= 10\r\n\r\ndegree = 0\r\nb_no_zero = 0\r\nwhile b > 0:\r\n last = b % 10\r\n if last != 0:\r\n last = last * 10**degree\r\n b_no_zero = b_no_zero + last\r\n degree += 1\r\n b //= 10\r\ndegree = 0\r\nc_no_zero = 0\r\nwhile c > 0:\r\n last = c % 10\r\n if last != 0:\r\n last = last * 10**degree\r\n c_no_zero = c_no_zero + last\r\n degree += 1\r\n c //= 10\r\n\r\nif a_no_zero + b_no_zero == c_no_zero:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "\r\nn1 = input()\r\nb2 = input()\r\n\r\na= int(n1)\r\nb=int(b2)\r\n\r\nwith_zeros=a+b\r\n\r\nn1=n1.replace(\"0\",\"\")\r\nb2=b2.replace(\"0\",\"\")\r\n\r\na1= int(n1)\r\nb1=int(b2)\r\nwithout_zeros=a1+b1\r\n\r\nwithout_zeros=str(with_zeros)\r\nwithout_zeros=without_zeros.replace(\"0\",\"\")\r\nwithout_zeros=int(without_zeros)\r\n\r\n\r\nif without_zeros==a1+b1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "\r\n\r\n# Read integers a and b from input\r\na = int(input().strip())\r\nb = int(input().strip())\r\n\r\n# Calculate the sum c\r\nc = a + b\r\n\r\n# Remove zeros from a, b, and c\r\na_no_zeros = int(str(a).replace('0', ''))\r\nb_no_zeros = int(str(b).replace('0', ''))\r\nc_no_zeros = int(str(c).replace('0', ''))\r\n\r\n# Recalculate the sum c without zeros in a and b\r\nc_calculated = a_no_zeros + b_no_zeros\r\n\r\n# Check if the recalculated c is equal to the original c\r\nif c_no_zeros == c_calculated:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\nx=str (a)\r\nx=x.replace(\"0\",'',x.count('0'))\r\ny=str (b)\r\ny=y.replace(\"0\",'',y.count('0'))\r\nx=int(x)\r\ny=int(y)\r\nv=x+y\r\nz=str (c)\r\nz=z.replace(\"0\",'',z.count('0'))\r\nz=int(z)\r\nif z==v:\r\n print(\"YES\")\r\nelse: \r\n print(\"NO\")\r\n\r\n", "a = input()\nb = input()\nnew_a, new_b = '', ''\nfor i in a:\n if i != '0': new_a += i\nfor i in b:\n if i != '0': new_b += i\ns = str(int(a) + int(b))\nsum = ''\nfor i in s:\n if i != '0': sum += i\nnew_sum = str(int(new_a) + int(new_b))\nif sum == new_sum: print(\"YES\")\nelse: print(\"NO\")\n\t\t\t\t \t\t\t \t \t \t\t \t \t\t\t\t", "a = input()\r\nb = input()\r\nx = \"\"\r\ny = \"\"\r\ne = \"\"\r\nd = \"\"\r\ng = \"\"\r\nh = \"\"\r\nz = str(int(a)+int(b))\r\nfor i in z:\r\n if i=='0':\r\n g+=i\r\n else:\r\n h+=i\r\nfor i in a:\r\n if i=='0':\r\n x+=i\r\n else:\r\n y+=i\r\n \r\nfor i in b:\r\n if i=='0':\r\n e+=i\r\n else:\r\n d+=i\r\nif str(int(y)+int(d))==h:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def removeZero(a):\n num = 0\n while a != 0:\n n = a % 10\n if n != 0:\n num = num * 10 + n\n a //= 10\n return num\n\ndef reverse(num):\n rev = 0\n while num != 0:\n rev = rev * 10 + (num % 10)\n num //= 10\n return rev\n\n#----main----#\na, b = int(input()), int(input())\ns = a + b\nsum = reverse(removeZero(s))\nnew_sum = reverse(removeZero(a)) + reverse(removeZero(b))\nif sum == new_sum: print(\"YES\")\nelse: print(\"NO\")\n \t \t\t\t \t\t\t\t \t \t\t\t\t \t \t\t \t\t \t\t", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nSpyder Editor\r\n\r\nThis is a temporary script file.\r\n\"\"\"\r\nfirst=input()\r\nsecond=input()\r\nres=int(first)+int(second)\r\nsum1=str(res)\r\nfirst1=\"\"\r\nsecond1=\"\"\r\nsum2=\"\"\r\nfor i in range(len(first)):\r\n if first[i]!='0':\r\n first1+=first[i]\r\nfor i in range(len(second)):\r\n if second[i]!='0':\r\n second1+=second[i] \r\nfor i in range(len(sum1)):\r\n if sum1[i]!='0':\r\n sum2+=sum1[i] \r\n\r\n\r\nif int(first1)+int(second1)==int(sum2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=int(input())\r\nb=int(input())\r\nc=\"\"\r\nd=\"\"\r\ne=\"\"\r\nfor i in str(a):\r\n if i!=\"0\":\r\n c=c+i\r\nfor i in str(b):\r\n if i!=\"0\":\r\n d=d+i\r\nfor i in str(a+b):\r\n if i!=\"0\":\r\n e=e+i\r\nif int(e)==int(c)+int(d):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "import sys\r\n\r\ntext = sys.stdin.readlines()\r\n\r\na = text[0]\r\nb = text[1]\r\nresult1 = int(a.replace('0','')) + int(b.replace('0',''))\r\nresult2 = int(str(int(a) + int(b)).replace('0',''))\r\n\r\nprint('YES' if result1 == result2 else 'NO')", "a = input()\r\nb = input()\r\n\r\nif (str(int(a.replace(\"0\", \"\")) + int(b.replace(\"0\", \"\"))) == (str(int(a) + int(b))).replace(\"0\", \"\")):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "\r\n\r\nm = int(input())\r\nn = int(input())\r\n\r\n\r\nres = m + n \r\n\r\nm = str(m).replace(\"0\", \"\")\r\nn = str(n).replace(\"0\", \"\")\r\n\r\nres = int(str(res).replace(\"0\", \"\"))\r\nif res == int(m) + int(n) :\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\")", "a = input()\r\nb = input()\r\nc = int(a) + int(b)\r\nif '0' in a:\r\n\ta1 = a.replace('0','')\r\nelse:\r\n\ta1 = a\r\nif '0' in b:\r\n\tb1 = b.replace('0', '')\r\nelse:\r\n\tb1 = b\r\nif '0' in str(c):\r\n\tc1 = str(c).replace('0', '')\r\nelse:\r\n\tc1 = c\r\nif int(c1) == int(a1) + int(b1):\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')\r\n\r\n\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\np=str(a)\r\np=p.replace('0','')\r\nq=str(b)\r\nq=q.replace('0','')\r\np=int(p)\r\nq=int(q)\r\nr=p+q\r\ns=str(c)\r\ns=s.replace('0','')\r\ns=int(s)\r\nif r==s:\r\n print('YES')\r\nelse:\r\n print('NO')", "\n\na = input()\nb = input()\na1 = a.replace('0', '')\nb1 = b.replace('0', '')\nif int(str(int(a)+int(b)).replace('0','')) == int(a1)+int(b1):\n print('YES')\nelse:\n print('NO')\n", "a=input()\r\nb=input()\r\nfake=str(int(a)+int(b))\r\n\r\na=a.replace(\"0\",\"\")\r\n\r\nb=b.replace(\"0\",\"\")\r\n\r\nfake=fake.replace(\"0\",\"\")\r\n\r\nif int(a)+int(b)==int(fake):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=int(input())\r\nb=int(input())\r\nsum=a+b\r\nnum1_0=''\r\nnum2_0=''\r\nsum_0=''\r\nsum=str(sum)\r\na=str(a)\r\nb=str(b)\r\nfor i in a:\r\n if i=='0':\r\n continue\r\n else:\r\n num1_0+=i\r\nfor i in b:\r\n if i=='0':\r\n continue\r\n else:\r\n num2_0+=i \r\nfor i in sum:\r\n if i=='0':\r\n continue\r\n else:\r\n sum_0+=i \r\nif(int(num1_0)+int(num2_0)==int(sum_0)):\r\n print(\"YES\") \r\nelse:\r\n print(\"NO\") ", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\nnumbers=[a,b,c]\r\ni=0\r\nwhile i<3:\r\n chislo=numbers[i]\r\n razryad=1\r\n new_number=0\r\n while chislo>0:\r\n x1=chislo%10\r\n if x1!=0:\r\n new_number=razryad*x1+new_number\r\n razryad *=10\r\n chislo=chislo//10\r\n numbers[i]=new_number\r\n i +=1\r\nif numbers[0]+numbers[1]==numbers[2]:\r\n print('YES')\r\nelse:\r\n print('NO')", "a=input()\r\nb=input()\r\ns=int(a)+int(b)\r\ns=str(s)\r\ns=s.replace('0','')\r\na=a.replace('0','')\r\nb=b.replace('0','')\r\ns1=str(int(a)+int(b))\r\nif (s1 == s):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "A=input()\r\nB=input()\r\nans1=int(A)+int(B)\r\nans1=str(ans1)\r\nans1=ans1.replace(\"0\",\"\")\r\n\r\nA=A.replace(\"0\",\"\")\r\nB=B.replace(\"0\",\"\")\r\n\r\nans2=int(A)+int(B)\r\n\r\nif(int(ans1)==ans2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\nb = input()\nc = int(a) + int(b)\ncc = str(c).replace('0', '')\na2 = a.replace('0', '')\nb2 = b.replace('0', '')\nc2 = int(a2) + int(b2)\nif cc == str(c2):\n print('YES')\nelse:\n print('NO')\n\t \t \t \t\t\t \t\t \t\t \t\t\t \t\t", "def clean(n): return int('0' + str(n).replace(\"0\",''))\r\n\r\na, b = int(input()), int(input())\r\nc = a + b\r\nac, bc, cc = clean(a), clean(b), clean(c)\r\nprint([\"NO\",\"YES\"][ac+bc==cc])", "a = input()\r\nb = input()\r\nc = str(int(a) + int(b))\r\nr_c = c.replace('0','')\r\nr_a = a.replace('0','')\r\nr_b = b.replace('0','')\r\nans_c = str(int(r_a) + int(r_b))\r\nif(ans_c == r_c):\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')\r\n\r\n\r\n", "a=input()\r\nb=input()\r\n\r\nc=str(int(a)+int(b))\r\n\r\na_new=a.replace('0','')\r\n\r\n\r\nb_new=b.replace('0','')\r\n\r\nc_new=c.replace('0','')\r\n\r\nif int(a_new)+int(b_new)==int(c_new):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\nswz = a + b\r\na = str(a).split('0')\r\na = int(''.join(a))\r\nb = str(b).split('0')\r\nb = int(''.join(b))\r\nsnwz = str(swz).split('0')\r\nsnwz = int(''.join(snwz))\r\nif a + b == snwz:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n", "def tachso (x):\r\n a = 0\r\n k = 1\r\n somoi = 0\r\n while x > 0:\r\n a = x % 10\r\n if a == 0:\r\n x //= 10\r\n continue\r\n somoi += a*k\r\n x //= 10\r\n k *= 10\r\n return somoi\r\na = int(input())\r\nb = int(input())\r\nc = a + b\r\nif tachso(a) + tachso(b) == tachso(c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\ns=str(c)\r\nif '0' in a:\r\n a=a.replace('0','')\r\nif '0' in b:\r\n b=b.replace('0', '')\r\nif '0' in s:\r\n s=s.replace('0', '')\r\n c=int(s)\r\nif int(a)+int(b)==c:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\r\nb=input()\r\nz=str(int(a)+int(b))\r\na=\"\".join(a.replace(\"0\",\"\"))\r\nb=\"\".join(b.replace(\"0\",\"\"))\r\nz=\"\".join(z.replace(\"0\",\"\"))\r\nif(int(a)+int(b)==int(z)):\r\n print('YES')\r\nelse:\r\n print(\"NO\")", "s = str(input())\r\ns1 = str(input())\r\nsumm = int(s) + int(s1)\r\nsumx = str(summ).replace(\"0\",\"\")\r\nsx = s.replace(\"0\",\"\")\r\nsx1 = s1.replace(\"0\",\"\")\r\nif int(sx) + int(sx1) == int(sumx):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "from sys import stdin as inp\n\na = inp.readline()[:-1]\nb = inp.readline()[:-1]\n\nc = int(a) + int(b)\n\nA = ''\nB = ''\nC = ''\n\nfor ch in a:\n if ch != '0':\n A += ch\n\nfor ch in b:\n if ch != '0':\n B += ch\n\nfor ch in str(c):\n if ch != '0':\n C += ch\n\n\nA = int(A)\nB = int(B)\nC = int(C)\n\nif A + B == C:\n print(\"YES\")\nelse:\n print(\"NO\")", "a=input()\r\nb=input()\r\nif str(int(a)+int(b)).replace(\"0\",\"\")==str(int(a.replace(\"0\",\"\"))+int(b.replace(\"0\",\"\"))):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "num1 = input()\nnum2 = input()\n\nsumNumber = int(num1) + int(num2)\nstrSum = str(sumNumber)\n\nnum1 = num1.replace(\"0\",\"\")\nnum2 = num2.replace(\"0\",\"\")\nstrSum = strSum.replace(\"0\",\"\")\n\nif strSum == str((int(num1)+int(num2))): print(\"YES\")\nelse: print(\"NO\")\n\n\n\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\nfrom collections import defaultdict,deque\r\nimport sys\r\nfrom bisect import bisect_right as b_r\r\nfrom bisect import bisect_left as b_l\r\nfrom os import path\r\nfrom heapq import *\r\n\r\n\r\nmod=1000000007\r\nINT_MAX = sys.maxsize-1\r\nINT_MIN = -sys.maxsize\r\n\r\n\r\n\r\n# if(path.exists('inputt.txt')):\r\n# sys.stdin = open('inputt.txt','r')\r\n# sys.stdout = open('output.txt','w')\r\n# else:\r\n# # input=sys.stdin.readline\r\n# pass\r\n\r\n\r\ndef myyy__answer():\r\n a=input()\r\n b=input()\r\n\r\n c=int(a)+int(b)\r\n # print(c)\r\n\r\n d=\"\".join([i for i in a if(i!=\"0\")])\r\n e=\"\".join([i for i in b if(i!=\"0\")])\r\n f=\"\".join([i for i in str(c) if(i!=\"0\")])\r\n\r\n # print(d,e,f)\r\n\r\n if(int(d)+int(e)==int(f)):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\n\r\n \r\n\r\n \r\n \r\n\r\nif __name__ == \"__main__\":\r\n # for _ in range(int(input())):\r\n # print(myyy__answer())\r\n myyy__answer()", "a = int(input())\r\nb = int(input())\r\nstr_a = str(a).replace('0','')\r\nstr_b = str(b).replace('0','')\r\nsumm = a+b\r\nstr_summ = str(summ).replace('0','')\r\nif int(str_a)+int(str_b)==int(str_summ):\r\n print('YES')\r\nelse:\r\n print('NO')", "a=(input())\r\nb=(input())\r\nc=int(a)+int(b)\r\nc=str(c)\r\nc=list(c)\r\nwhile('0' in c):\r\n c.remove('0')\r\n\r\nc2=''\r\nfor i in range(len(c)):\r\n c2+=c[i]\r\n\r\nc2=int(c2)\r\n\r\n\r\n\r\na1=list(a)\r\nb1=list(b)\r\nwhile('0' in a1):\r\n a1.remove('0')\r\n\r\nwhile('0' in b1):\r\n b1.remove('0')\r\n\r\nans1,ans2='',''\r\nfor i in range(len(a1)):\r\n ans1+=a1[i]\r\n\r\nfor i in range(len(b1)):\r\n ans2+=b1[i]\r\n\r\nans1=int(ans1)\r\nans2=int(ans2)\r\nc1=ans1+ans2\r\n\r\nif(c1==c2):\r\n print(\"YES\")\r\n\r\nelse:\r\n print(\"NO\")\r\n\r\n", "a=str(input())\r\nb=str(input())\r\nc=str(int(a)+int(b))\r\nif int(a.replace('0',''))+int(b.replace('0',''))==int(c.replace('0','')):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a = int(input());b = int(input());m = str(a).replace('0','');n = str(b).replace('0','');x = int(m)+int(n);y = str(a+b).replace('0','');x = int(x);y = int(y)\r\nif x == y:\r\n print('YES')\r\nelse:\r\n print('NO') ", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\na=str (a)\r\na=a.replace(\"0\",'',a.count('0'))\r\nb=str (b)\r\nb=b.replace(\"0\",'',b.count('0'))\r\na=int(a)\r\nb=int(b)\r\nv=a+b\r\nc=str (c)\r\nc=c.replace(\"0\",'',c.count('0'))\r\nc=int(c)\r\nif c==v:\r\n print(\"YES\")\r\nelse: \r\n print(\"NO\")\r\n", "s1 = input()\ns2 = input()\ns3 = str(int(s1) + int(s2))\n\np = \"\".join(c1 for c1 in s1 if c1 != '0')\nq = \"\".join(c2 for c2 in s2 if c2 != '0')\nr = \"\".join(c3 for c3 in s3 if c3 != '0')\n\nif (int(p) + int(q)) == int(r):\n print(\"YES\")\nelse:\n print(\"NO\")\n\n", "a = input()\nb = input()\nc1 = int(a) + int(b)\na = filter(lambda x:x!='0',a)\nb = filter(lambda x:x!='0',b)\nc1 = filter(lambda x:x!='0',str(c1))\nc2 = int(''.join(a)) + int(''.join(b))\nif(c2 == int(''.join(c1))):\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")", "n = (input())\r\nm = (input())\r\nk = int(n) + int(m)\r\np = str(k)\r\nn1=n.replace('0', '')\r\np1 = p.replace('0', '')\r\nm1 = m.replace('0', '')\r\n\r\nif(int(n1) + int(m1) == int(p1)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\nx=[i for i in list(str(c)) if i!='0']\r\nx=int(''.join(x))\r\n\r\naa=[i for i in list(a) if i!='0']\r\nbb=[i for i in list(b) if i!='0']\r\ncc=int(''.join(aa))+int(''.join(bb))\r\nxx=int(''.join(list(str(cc))))\r\n\r\nprint(\"YES\" if x==xx else \"NO\")\r\n\r\n", "s1 = input().strip()\ns2 = input().strip()\nprint(['YES', 'NO'][str(eval(s1.replace('0', '') + '+' + s2.replace('0', ''))) != str(int(s1)+int(s2)).replace('0', '')])\n", "num1 = input()\r\nnum2 = input()\r\nnum3 = int(num1) + int(num2)\r\ntemp1, temp2, temp3 = '', '', ''\r\nfor i in num1:\r\n\tif i != '0':\r\n\t\ttemp1 += i\r\nfor j in num2:\r\n\tif j != '0':\r\n\t\ttemp2 += j\r\nfor k in str(num3):\r\n\tif k!='0':\r\n\t\ttemp3 += k\r\n\r\nif int(temp3) == int(temp1) + int(temp2):\r\n\tprint(\"YES\")\r\nelse: print(\"NO\")", "o1=input()\r\no2=input()\r\no3=str(int(o1)+int(o2))\r\na=\"\"\r\nb=\"\"\r\nc=\"\"\r\nfor i in range(len(o1)):\r\n if o1[i]!=\"0\":\r\n a+=o1[i]\r\nfor i in range(len(o2)):\r\n if o2[i]!=\"0\":\r\n b+=o2[i]\r\nfor i in range(len(o3)):\r\n if o3[i]!=\"0\":\r\n c+=o3[i]\r\no1=int(o1)\r\no2=int(o2)\r\no3=int(o3)\r\na=int(a)\r\nb=int(b)\r\nc=int(c)\r\nif a+b==c:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a, b = int(input()), int(input())\r\na_str = ''\r\nb_str = ''\r\nsumm_str = ''\r\nsumm = a + b\r\nwhile b > 0:\r\n if b % 10 != 0:\r\n last = b % 10\r\n b_str = b_str + str(last)\r\n b //= 10\r\nwhile a > 0:\r\n if a % 10 != 0:\r\n last1 = a % 10\r\n a_str = a_str + str(last1)\r\n a //= 10\r\nwhile summ > 0:\r\n if summ % 10 != 0:\r\n last2 = summ % 10\r\n summ_str = summ_str + str(last2)\r\n summ //= 10\r\n\r\na_str = a_str[::-1]\r\nb_str = b_str[::-1]\r\nsumm_str = summ_str[::-1]\r\nif int(a_str) + int(b_str) == int(summ_str):\r\n print('YES')\r\nelse:\r\n print('NO')", "def rz(N):\r\n return int(\"\".join(str(N).split(\"0\")))\r\n\r\nA = int(input())\r\nB = int(input())\r\nC = A+B\r\nif rz(A)+rz(B)==rz(C):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = int(input())\r\nb = int(input())\r\nc = a+b\r\n\r\na2 = int(str(a).replace('0',''))\r\nb2 = int(str(b).replace('0',''))\r\nc2 = int(str(c).replace('0',''))\r\n\r\nif a2+b2 == c2:\r\n print('YES')\r\nelse:\r\n print('NO')", "# -*- 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\na=int(input())\nb=int(input())\nc=a+b\ndef nonzer(n):\n l1=str(n)\n l1=list(l1)\n i=0\n while i<len(l1):\n if l1[i]==\"0\":\n l1.pop(i)\n else:\n i=i+1\n str1=\"\"\n for x in l1:\n str1=str1+x\n m=int(str1)\n return(m)\nif nonzer(a)+nonzer(b)==nonzer(c):\n print(\"YES\")\nelse:\n print(\"NO\")", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Wed Sep 27 09:51:56 2023\r\n\r\n@author: lakne\r\n\"\"\"\r\n\r\na = int(input())\r\nb = int(input())\r\nc = a + b\r\n\r\na_string = str(a)\r\nb_string = str(b)\r\nc_string = str(c)\r\na_mod = a\r\nb_mod = b\r\nc_mod = c\r\n\r\nif '0' in a_string:\r\n a_mod = a_string.replace('0', '')\r\n a_mod = int(a_mod)\r\nif '0' in b_string:\r\n b_mod = b_string.replace('0', '')\r\n b_mod = int(b_mod)\r\nif '0' in c_string:\r\n c_mod = c_string.replace('0', '')\r\n c_mod = int(c_mod)\r\n\r\nif a_mod + b_mod == c_mod:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n ", "a = int(input())\nb = int(input())\nc = a+b\nd = int(str(a).replace('0', '')) + int(str(b).replace('0', ''))\nif int(str(c).replace('0', '')) == d:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "firstNumber = input()\r\nsecondNumber = input()\r\nsumWithZero = int(firstNumber) + int(secondNumber)\r\nfirstNumber = firstNumber.replace(\"0\",'')\r\nsecondNumber = secondNumber.replace(\"0\",'')\r\nsumWithZero = str(sumWithZero).replace(\"0\",'')\r\nsumWithoutZero = str(int(firstNumber) + int(secondNumber))\r\nif sumWithZero == sumWithoutZero:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = int(input()) \r\nb = int(input()) \r\nc = a + b \r\nc_szero =\"\" \r\na_szero =\"\"\r\nb_szero =\"\" \r\nfor i in str(c) : \r\n if i == \"0\" : \r\n continue\r\n else : \r\n c_szero+= i \r\nfor i in str(a) : \r\n if i == \"0\" : \r\n continue\r\n else : \r\n a_szero+= i\r\nfor i in str(b) : \r\n if i == \"0\" : \r\n continue\r\n else : \r\n b_szero+= i \r\nif int(a_szero) + int(b_szero) != int(c_szero) :\r\n print(\"NO\")\r\nelse : \r\n print(\"YES\")\r\n", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\n\r\nd = str(a).replace('0', '')\r\ne = str(b).replace('0', '')\r\nf = str(c).replace('0', '')\r\n\r\nif int(d) + int(e) == int(f):\r\n print('YES')\r\nelse:\r\n print('NO')", "def reverse(number):\r\n reverse_number = 0\r\n while (number != 0):\r\n reverse_number = reverse_number * 10 + number % 10\r\n number = (number - number % 10) / 10\r\n return int(reverse_number)\r\n\r\ndef delete_zeroes(number):\r\n ans = 0\r\n while (number != 0):\r\n if (number % 10 == 0):\r\n number = number / 10\r\n else:\r\n ans = ans * 10 + number % 10\r\n number = (number - number % 10) /10\r\n return (int(reverse(ans)))\r\n\r\ndef solve(number1, number2):\r\n number3 = number1 + number2\r\n new_number1 = delete_zeroes(number1)\r\n new_number2 = delete_zeroes(number2)\r\n new_number3 = delete_zeroes(number3)\r\n if (new_number1 + new_number2 == new_number3):\r\n return 1\r\n return 0\r\n\r\na = int(input())\r\nb = int(input())\r\nif (solve(a, b) == True):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n\r\n\r\n", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\ns=str(c)\r\nd=int(\"\".join(a.split(\"0\")))\r\ne=int(\"\".join(b.split(\"0\")))\r\nf=int(\"\".join(s.split(\"0\")))\r\nprint(\"YNEOS\"[d+e!=f::2])", "a = int(input())\r\nb = int(input())\r\ndef bo0(x):\r\n so = 0\r\n i = 0\r\n while(True):\r\n if(x in range (10)):\r\n return so + x*(10 ** i)\r\n so = so + (x % 10)*(10**i)\r\n if (x % 10 != 0):\r\n i += 1 \r\n if (x % 10 == 0):\r\n i == i\r\n x = x // 10\r\n return(so)\r\na1 = bo0(a)\r\nb1 = bo0(b)\r\nc1 = bo0(a+b)\r\nif (a1 + b1 == c1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") ", "x=input()\r\ny=input()\r\nz=int(x)+int(y)\r\nx1=''\r\ny1=''\r\ni=0\r\nz=str(z)\r\nz1=''\r\nwhile i<len(x):\r\n if not x[i]=='0':\r\n x1=x1+x[i]\r\n i+=1\r\ni=0 \r\nwhile i<len(y):\r\n if not y[i]=='0':\r\n y1=y1+y[i]\r\n i+=1\r\ni=0\r\nwhile i<len(z):\r\n if not z[i]=='0':\r\n z1=z1+z[i]\r\n i+=1\r\nx2=int(x1);y2=int(y1);z2=int(z1)\r\nif x2+y2==z2:\r\n print('YES')\r\nelse:\r\n print(\"NO\")\r\n\r\n", "a=input()\r\nb=input()\r\n\r\ne=list(a)\r\nf=list(b)\r\n\r\nc=int(a)+int(b)\r\nd=a.count('0')\r\ng=b.count('0')\r\nh=str(c)\r\nx=list(h)\r\ny=x.count('0')\r\n\r\nif(d!=0):\r\n for i in range(d):\r\n e.remove('0')\r\n\r\nif(g!=0):\r\n for i in range(g):\r\n f.remove('0')\r\n\r\nif(y!=0):\r\n for i in range(y):\r\n x.remove('0')\r\n\r\n\r\nA=''.join(e)\r\nB=''.join(f)\r\nC=''.join(x)\r\n\r\n\r\nif((int(A)+int(B))==int(C)):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a = input()\nb = input()\nc = str(int(a) + int(b))\na = int(''.join(a.split('0')))\nb = int(''.join(b.split('0')))\nc = int(''.join(c.split('0')))\nprint('YES' if a + b == c else 'NO')\n", "a=input()\r\nb=input()\r\ns=int(a)+int(b)\r\na=a.replace('0','')\r\nb=b.replace('0','')\r\ns2=int(a)+int(b)\r\ns1=int(str(s).replace('0',''))\r\nprint('NYOE S'[s1==s2::2])", "a=int(input())\r\nb=int(input())\r\n\r\nc=a+b\r\n\r\nlenA=len(str((a)))\r\nlenB=len(str((b)))\r\nlenC=len(str((c)))\r\naStr=''\r\nbStr=''\r\ncStr=''\r\n\r\nwhile lenA>0:\r\n e=a%10\r\n if e!=0:\r\n aStr=aStr+str(e)\r\n a=a//10\r\n lenA-=1\r\na=int(aStr[::-1])\r\n\r\nwhile lenB>0:\r\n q=b%10\r\n if q!=0:\r\n bStr=bStr+str(q)\r\n b=b//10\r\n lenB-=1\r\nb=int(bStr[::-1])\r\n\r\nwhile lenC>0:\r\n w=c%10\r\n if w!=0:\r\n cStr=cStr+str(w)\r\n c=c//10\r\n lenC-=1\r\nc=int(cStr[::-1])\r\n\r\nif c==a+b:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n\r\n", "a = (input())\r\nb = (input())\r\nc = int(a)+int(b)\r\nx = int(a.replace(\"0\",\"\"))\r\ny = int(b.replace(\"0\",\"\"))\r\nz = x+y\r\nc1 = int(str(c).replace(\"0\",\"\"))\r\nif c1 == z:\r\n print(\"YES\")\r\nelse: print(\"NO\")\r\n", "a=int(input())\r\nb=int(input())\r\nprint(\"NYOE S\"[(int(str(a+b).replace('0',''))==int(str(a).replace('0',''))+int(str(b).replace('0','')))::2])", "a=int(input())\r\nb=int(input())\r\nc=str(a+b)\r\na=str(a)\r\nb=str(b)\r\nz=''\r\nx=''\r\nv=''\r\nfor i in c:\r\n if i!='0':\r\n z+=i\r\nfor i in a:\r\n if i!='0':\r\n x+=i\r\nfor i in b:\r\n if i!='0':\r\n v+=i\r\nz=int(z)\r\nx=int(x)\r\nv=int(v)\r\nif x+v==z:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a = input()\r\naas = ''.join(a.split('0'))\r\n\r\nb = input()\r\nbbs = ''.join(b.split('0'))\r\n\r\nsum = str(int(a) + int(b)).split('0')\r\nsumm=''.join(sum)\r\n\r\nif (int(aas) + int(bbs)) == int(summ):\r\n print(\"YES\")\r\nelse:print(\"NO\")", "num1 = input()\r\nnum2 = input()\r\nsum1 = int(num1) + int(num2)\r\nsum1 = str(sum1)\r\n\r\nn1 = num1.replace('0', '')\r\nn2 = num2.replace('0', '')\r\ns1 = sum1.replace('0', '')\r\n\r\nif(int(s1)==(int(n1)+int(n2))):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=int(input())\r\nx=int(input())\r\ne=str(n+x).replace('0','')\r\nf=str(n).replace('0','')\r\nx=str(x).replace('0','')\r\nif int(e)== int(f)+int(x):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def no_zeros(n):\r\n c = 0\r\n m = 1\r\n while(n>0):\r\n if(n%10!=0):\r\n c += (n%10)*m\r\n m*=10\r\n n //= 10\r\n return c\r\na = int(input())\r\nb = int(input())\r\nc = a+b\r\nif(no_zeros(a)+no_zeros(b)==no_zeros(c)):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "y1 = int(input())\r\nx1 = int(input())\r\ny = str(y1)\r\nx = str(x1)\r\nz = x1 + y1\r\nplus = str(z)\r\nj = ''\r\nh = ''\r\nk = ''\r\nfor i in y:\r\n if i != '0':\r\n j += i\r\nfor i in x:\r\n if i != '0':\r\n h += i\r\nfor i in plus:\r\n if i != '0':\r\n k += i\r\n \r\nif int(j) + int(h) == int(k):\r\n print('YES')\r\nelse:\r\n print('NO')", "a = int(input())\r\nb = int(input())\r\nc = a + b \r\ncategory = 1\r\na1, b1,c1 = 0, 0, 0 \r\nlst = [a,b,c]\r\nlst1 = [a1,b1,c1]\r\ni =0 \r\nwhile i < len(lst):\r\n while lst[i] > 0:\r\n last = lst[i] % 10\r\n if last != 0:\r\n lst1[i] +=last * category\r\n category *= 10 \r\n lst[i] //= 10\r\n i += 1\r\n category = 1\r\nif lst1[0] + lst1[1] == lst1[2]:\r\n print('YES')\r\nelse:\r\n print('NO')", "a=input()\r\nb=input()\r\nc=int(a) + int(b)\r\na=a.replace('0','')\r\nb=b.replace('0','')\r\nif int(a)+int(b) == int(str(c).replace('0','')):\r\n print('YES')\r\nelse:\r\n print('NO')", "a = input()\r\nb = input()\r\nanswer = int(a)+int(b)\r\na = a.replace('0','')\r\nb = b.replace('0','')\r\nanswer = int(str(answer).replace('0',''))\r\nprint( \"YES\" if answer==int(a)+int(b) else \"NO\")\r\n", "n1 = input()\r\nn2 = input()\r\n\r\naux1 = n1.replace('0','')\r\naux2 = n2.replace('0','')\r\n\r\nif str(int(aux1) + int(aux2)) == str(int(n1) + int(n2)).replace('0', ''):\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')\r\n", "a=input()\r\nb=input()\r\ns=str(int(a)+int(b))\r\nlsta=list(a)\r\nlstb=list(b)\r\nlsts=list(s)\r\nnza=list(filter(lambda c:c!='0',lsta))\r\nnzb=list(filter(lambda c:c!='0',lstb))\r\nfs=list(filter(lambda c:c!='0',lsts))\r\nstra=\"\".join(nza)\r\nstrb=\"\".join(nzb)\r\nstrs=\"\".join(fs)\r\nnzs=int(stra)+int(strb)\r\nif(int(strs)==nzs):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s1 = input()\r\ns2 = input()\r\nsum1 = int(s1) + int(s2)\r\nd = str(sum1)\r\nans = d.replace('0','')\r\nx = s1.replace('0','')\r\ny = s2.replace('0','')\r\nfinal = int(x)+int(y)\r\nprint ('YES' if final == int(ans) else 'NO')\r\n\r\n", "def rem(s):\n st = ''\n for e in s:\n if e != '0':\n st += e\n return int(st)\n\nastr=input()\nbstr=input()\n\nif rem(str(int(astr)+int(bstr))) == rem(astr)+rem(bstr):\n print (\"YES\")\nelse:\n print (\"NO\")\n", "a=input()\r\nb=input()\r\ns=str(int(a)+int(b))\r\na=a.replace('0','')\r\nb=b.replace('0','')\r\ns=s.replace('0','')\r\nif int(a)+int(b)==int(s):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a = int(input())\r\nb = int(input())\r\n\r\ns = f'{a} + {b} == {a + b}'\r\ns = s.replace('0', '')\r\n\r\nif eval(s):\r\n print('YES')\r\nelse:\r\n print('NO')", "a=input()\r\nb=input()\r\nc=list(str(int(a)+int(b)))\r\na=list(a)\r\nb=list(b)\r\nj=\"\"\r\nk=\"\"\r\nl=\"\"\r\nfor i in a:\r\n\tif i!=\"0\":\r\n\t\tj=j+i\r\nfor i in b:\r\n\tif i!=\"0\":\r\n\t\tk=k+i\r\nfor i in c:\r\n\tif i!=\"0\":\r\n\t\tl=l+i\r\nif int(j)+int(k)==int(l):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "x=int(input())\r\ny=int(input())\r\nk=x+y\r\na=str(x).replace(\"0\",\"\")\r\nb=str(y).replace(\"0\",\"\")\r\no=str(k).replace(\"0\",\"\")\r\na=int(a)\r\nb=int(b)\r\no=int(o)\r\nif a+b==o:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\r\n", "a = int(input())\r\nb = int(input())\r\n\r\nsum = a+b\r\n\r\nsum = list(str(sum))\r\n\r\nwhile '0' in sum:\r\n sum.remove('0')\r\n\r\nsum = int(\"\".join(sum))\r\n\r\na = list(str(a))\r\nb = list(str(b))\r\n\r\nwhile '0' in a:\r\n a.remove('0')\r\nwhile '0' in b:\r\n b.remove('0')\r\na = int(''.join(a))\r\nb = int(''.join(b))\r\n\r\nif a+b == sum:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\na1=str(a)\r\nb1=str(b)\r\nc1=str(c)\r\na2=\"\"\r\nb2=\"\"\r\nc2=\"\"\r\nfor i in a1:\r\n if i!=\"0\":\r\n a2=a2+i\r\nfor i in b1:\r\n if i!=\"0\":\r\n b2=b2+i\r\nfor i in c1:\r\n if i!=\"0\":\r\n c2=c2+i\r\na2=int(a2)\r\nb2=int(b2)\r\nc2=int(c2)\r\nif c2==b2+a2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = input()\r\nb = input()\r\n\r\nA = a.replace('0', '')\r\nB = b.replace('0', '')\r\n\r\na = int(a)\r\nb = int(b)\r\nA = int(A)\r\nB = int(B)\r\n\r\nc = a + b\r\nC = int(str(c).replace('0', ''))\r\n\r\nif C == A + B:\r\n print('YES')\r\nelse:\r\n print('NO')", "def removeZeros(n):\r\n m, ten = 0, 1\r\n while n > 0:\r\n if n % 10 != 0:\r\n m = (n % 10) * ten + m\r\n ten *= 10\r\n n //= 10\r\n return m\r\n\r\na, b = int(input()), int(input())\r\nc = a + b\r\nprint('YES' if removeZeros(a) + removeZeros(b) == removeZeros(c) else 'NO')", "a = input()\r\nb = input()\r\n\r\na_no_zeros = a.replace(\"0\", \"\")\r\nb_no_zeros = b.replace(\"0\", \"\")\r\n\r\nadd = str(int(a) + int(b))\r\nadd_no_zeros = str(int(a_no_zeros) + int(b_no_zeros))\r\n\r\nif(add_no_zeros == add.replace(\"0\", \"\")):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s1 = input()\r\ns2 = input()\r\nt1 = s1.replace('0','')\r\nt2 = s2.replace('0','')\r\ns = str(int(s1)+int(s2)).replace('0','')\r\nif int(t1)+int(t2) == int(s):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "x = input()\r\ny = input()\r\nz = str(int(x)+int(y)).replace('0','')\r\nzz = int(z)\r\nxz=int(x.replace('0',''))\r\nyz=int(y.replace('0',''))\r\nzzz=xz+yz\r\nif zz==zzz:\r\n print('YES')\r\nelse:\r\n print('NO')", "num1 = int(input())\nnum2 = int(input())\n\ndef eraseZeros(num) :\n return int(''.join([i for i in str(num) if i != '0']))\n\nadd = num1 + num2\nerasedZeros_sum = eraseZeros(num1) + eraseZeros(num2) \n\nif eraseZeros(add) == erasedZeros_sum :\n print(\"YES\")\nelse :\n print(\"NO\")\n", "\r\ndef without_zeros(n):\r\n st = str(n)\r\n res = \"\"\r\n for i in range(len(st)):\r\n if st[i]!='0':\r\n res+=st[i]\r\n return int(res)\r\n\r\na = int(input())\r\nb = int(input())\r\nc = a+b\r\na1 = without_zeros(a)\r\nb1 = without_zeros(b)\r\nc1 = a1+b1\r\nif c1 == without_zeros(c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "f=lambda x:int(''.join(list(str(x).split('0'))))\r\na,b=int(input()),int(input())\r\nprint('YNEOS'[f(a)+f(b)!=f(a+b)::2])", "a,b=input(),input()\r\nf,g,x=\"\",\"\",\"\"\r\nfor i in a:\r\n if i!=\"0\": f+=i\r\nfor i in b:\r\n if i!=\"0\": g+=i\r\nfor i in str(int(a)+int(b)):\r\n if i!=\"0\": x+=i\r\nif int(f)+int(g)==int(x): print(\"YES\")\r\nelse: print(\"NO\")", "import sys\r\ninput = sys.stdin.readline\r\n\r\na = int(input())\r\nb = int(input())\r\nx = [a, b, a + b]\r\ny = []\r\nfor i in range(3):\r\n y0 = []\r\n for j in list(str(x[i])):\r\n if not j == \"0\":\r\n y0.append(j)\r\n y.append(int(\"\".join(y0)))\r\nans = \"YES\" if y[0] + y[1] == y[2] else \"NO\"\r\nprint(ans)", "#na, nb = [int(i) for i in input().split()]\r\na = input().split()[0]\r\nb = input().split()[0]\r\nsa = a.replace('0','')\r\nsb = b.replace('0','')\r\nif int(str(int(a) + int(b)).replace('0','')) == int (sa) + int(sb):\r\n print ('YES')\r\nelse:\r\n print ('NO')", "n1=input()\r\nn2=input()\r\nn3=str(int(n1)+int(n2))\r\nc=0\r\nfor i in [n1,n2]:\r\n x1=list(filter(lambda x: x!='0',i))\r\n c+=int(''.join(x1))\r\nprint('YES' if int(''.join(list(filter(lambda x: x!='0',n3))))==c else 'NO')", "a = int(input())\r\nb = int(input())\r\nresult1 = int(a)+int(b)\r\ndup_a = ''\r\ndup_b = ''\r\nfor i in str(a):\r\n if i != '0':\r\n dup_a += i\r\nfor i in str(b):\r\n if i != '0':\r\n dup_b += i\r\nstrn = ''\r\nfor i in str(result1):\r\n if i !='0':\r\n strn += i\r\nif int(strn)==int(dup_a)+int(dup_b):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\nc=str(c)\r\ncwithout=\"\"\r\nreda=\"\"\r\nredb=\"\"\r\nfor i in range(0,max(len(a),max(len(b),len(c)))):\r\n if i<len(a):\r\n if a[i]!=\"0\":\r\n reda+=a[i]\r\n if i<len(b):\r\n if b[i]!=\"0\":\r\n redb+=b[i]\r\n if i<len(c):\r\n if c[i]!=\"0\":\r\n cwithout+=c[i]\r\nredc=int(reda)+int(redb)\r\nif cwithout==str(redc):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import sys\r\n\r\nLI = lambda: list(map(int, sys.stdin.readline().split()))\r\nMI = lambda: map(int, sys.stdin.readline().split())\r\nSI = lambda: sys.stdin.readline().strip('\\n')\r\nII = lambda: int(sys.stdin.readline())\r\n\r\n# sys.stdin = open(\"input.txt\", \"r\")\r\n\r\na = II()\r\nb = II()\r\nc = a + b\r\n\r\nA = str(a)\r\nB = str(b)\r\nC = str(c)\r\n\r\nA = A.replace(\"0\", \"\")\r\nB = B.replace(\"0\", \"\")\r\nC = C.replace(\"0\", \"\")\r\n\r\nnewC = int(A) + int(B)\r\n\r\nif str(newC) == C:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\ndef remove(x):\r\n c=x.find('0')\r\n while c!=-1:\r\n x=x[:c]+x[c+1:]\r\n c=x.find('0') \r\n return x\r\nif int(remove(str(a)))+int(remove(str(b)))==int(remove(str(c))):\r\n print('YES')\r\nelse:\r\n print('NO')", "def solve() -> None:\n a = input()\n b = input()\n c = str(int(a) + int(b))\n\n a = a.replace(\"0\", \"\")\n b = b.replace(\"0\", \"\")\n c = c.replace(\"0\", \"\")\n\n print(\"YES\" if int(a) + int(b) == int(c) else \"NO\")\n\nif __name__ == \"__main__\":\n\n t = 1\n # t = int(input())\n for _ in range(t):\n solve()\n", "def main():\r\n a=input()\r\n b=input()\r\n c=str(int(a)+int(b))\r\n a=loop(a)\r\n b=loop(b)\r\n c=loop(c)\r\n if a+b==c:\r\n print('YES')\r\n else:\r\n print('NO')\r\ndef loop(a):\r\n for i in a:\r\n if i=='0':\r\n a=a.replace(i,'')\r\n return int(a) \r\n \r\nmain() ", "def remove_zeros(n):\r\n result = 0\r\n factor = 1\r\n while n > 0:\r\n digit = n % 10\r\n if digit != 0:\r\n result += digit * factor\r\n factor *= 10\r\n n //= 10\r\n return result\r\n\r\ndef check(a, b):\r\n c = a + b\r\n a_no_zeros = remove_zeros(a)\r\n b_no_zeros = remove_zeros(b)\r\n c_no_zeros = remove_zeros(c)\r\n return a_no_zeros + b_no_zeros == c_no_zeros\r\n\r\na = int(input())\r\nb = int(input())\r\nif check(a, b):\r\n print('YES')\r\nelse:\r\n print('NO')", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\na=a.replace('0','')\r\nb=b.replace('0','')\r\ncm=str(int(a)+int(b))\r\ncwz=str(c).replace('0','')\r\nprint(\"YES\" if cm==cwz else \"NO\")", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\na1=a.replace('0','')\r\nb1=b.replace('0','')\r\nc1=str(c).replace('0','')\r\nif int(a1)+int(b1)==int(c1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\r\nb=input()\r\nc=str(int(a)+int(b))\r\n##print('c ',type(c), c)\r\nm=c.replace('0','')\r\nk=a.replace('0','')\r\nl=b.replace('0','')\r\n##print('m ',type(m), m)\r\nif int(k)+int(l)==int(m):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a, b = int(input()), int(input())\r\n\r\nawth = str(a).replace('0', \"\")\r\nbwth = str(b).replace('0', \"\")\r\nwthout = str(a + b).replace('0', \"\")\r\n\r\nif int(wthout) == int(awth) + int(bwth):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "\"\"\"\n75A | Life Without Zeros: implementation\n\"\"\"\n\ndef life_without_zeros():\n a = int(input())\n b = int(input())\n c = a + b\n d = str(c).replace('0', '')\n e = int(str(a).replace('0', '')) + int(str(b).replace('0', ''))\n print('YES' if int(d) == e else 'NO')\n\n\nif __name__ == '__main__':\n life_without_zeros()", "rm = lambda x : int(str(x).replace('0', ''))\r\n\r\na = int(input())\r\nb = int(input())\r\nc = a + b\r\n\r\nprint(\"YES\" if rm(a) + rm(b) == rm(c) else \"NO\")\r\n\r\n\r\n#########################################\r\n## ##\r\n## Implemented by brownfox2k6 ##\r\n## ##\r\n#########################################\r\n", "def removeZero(a):\n num, pos = 0, 1\n while a != 0:\n n = a % 10\n if n != 0:\n num += pos * n\n pos *= 10\n a //= 10\n return num\n\n#----main----#\na, b = int(input()), int(input())\ns = a + b\nsum = removeZero(s)\nnew_sum = removeZero(a) + removeZero(b)\nif sum == new_sum: print(\"YES\")\nelse: print(\"NO\")\n\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\n \r\nz = a+b\r\nn = str(z).replace(\"0\",\"\")\r\nn = int(n)\r\n \r\nx = str(a).replace(\"0\",\"\")\r\ny = str(b).replace(\"0\",\"\")\r\nm = int(x)+int(y)\r\nif n==m:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "a=input();b=input()\r\nif int(str(int(a)+int(b)).replace('0',''))==int(a.replace('0',''))+int(b.replace('0','')):print('YES')\r\nelse:print('NO')", "def noZero(string):\r\n final = \"\"\r\n for l in string:\r\n if l != \"0\":\r\n final += l\r\n\r\n return final\r\n\r\nnum1 = int(input())\r\nnum2 = int(input())\r\n\r\noriginal = int(noZero(str(num1 + num2)))\r\nnewNum1 = noZero(str(num1))\r\nnewNum2 = noZero(str(num2))\r\n\r\nnewSum = int(newNum1) + int(newNum2)\r\n\r\nif newSum == original:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def no_zero(a,b):\r\n\r\n c = a + b\r\n \r\n a = str(a).split('0')\r\n \r\n b = str(b).split('0')\r\n \r\n c = str(c).split('0')\r\n \r\n a = ''.join(a)\r\n \r\n b = ''.join(b)\r\n\r\n c = ''.join(c)\r\n\r\n\r\n if int(a) + int(b) == int(c) :\r\n print('YES')\r\n else :\r\n print('NO')\r\n \r\n\r\n\r\ndef main():\r\n a = int(input())\r\n b = int(input())\r\n no_zero(a,b)\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n main()", "x = int(input())\r\ny = int(input())\r\nz = x + y\r\na = str(x)\r\nb = str(y)\r\nc = str(z)\r\nwe = \"\"\r\nhe = \"\"\r\nne = \"\"\r\nfor i in a:\r\n if i != '0':\r\n we += i\r\nfor i in b:\r\n if i != '0':\r\n he += i\r\nfor i in c:\r\n if i != '0':\r\n ne += i\r\nif int(we) + int(he) == int(ne):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\ni = 0\r\na = list(map(int,str(a)))\r\ni = 0\r\nwhile(i < len(a)):\r\n if(a[i] == 0):\r\n a.pop(i)\r\n else:\r\n i = i + 1\r\nna = 0\r\nfor i in range(0,len(a)):\r\n na = (10 * na) + a[i]\r\nb = list(map(int,str(b)))\r\ni = 0\r\nwhile(i < len(b)):\r\n if(b[i] == 0):\r\n b.pop(i)\r\n else:\r\n i = i + 1\r\nnb = 0\r\nfor i in range(0,len(b)):\r\n nb = (10 * nb) + b[i]\r\ns = list(map(int,str(c)))\r\ni = 0\r\nwhile(i < len(s)):\r\n if(s[i] == 0):\r\n s.pop(i)\r\n else:\r\n i = i + 1\r\nns = 0\r\nfor i in range(0,len(s)):\r\n ns = (10 * ns) + s[i]\r\nif ns == (na+nb):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n ", "a = input()\r\nb = input()\r\ns = str(int(a)+int(b))\r\nx = \"\"\r\nz = \"\"\r\nv = \"\"\r\nfor i in range(len(a)):\r\n if a[i] != \"0\":\r\n x+=a[i]\r\nfor i in range(len(b)):\r\n if b[i] != \"0\":\r\n z+=b[i]\r\nfor i in range(len(s)):\r\n if s[i] != \"0\":\r\n v+=s[i]\r\nif int(a) + int(b) == int(s) and int(x) + int(z) == int(v):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "lst=[]\r\nfor i in range(2):\r\n n=int(input())\r\n lst.append(n)\r\nst1=''\r\nst2=''\r\nfor j in str(lst[0]):\r\n if j!=\"0\":\r\n st1+=j\r\nfor k in str(lst[1]):\r\n if k!=\"0\":\r\n st2+=k\r\na=int(st1)\r\nb=int(st2)\r\nlst2=[a,b]\r\nsu=sum(lst)\r\nsu1=str(su)\r\nsu2=su1.split(\"0\")\r\nsu3=''.join(su2)\r\n\r\nif sum(lst2)==int(su3):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "if __name__ == \"__main__\":\r\n a = input().rstrip()\r\n b = input().rstrip()\r\n c = str(int(a) + int(b))\r\n \r\n A = \"\"\r\n B = \"\"\r\n C = \"\"\r\n for i in a:\r\n if i == '0':\r\n continue\r\n A += i\r\n \r\n for i in b:\r\n if i == '0':\r\n continue\r\n B += i\r\n \r\n for i in c:\r\n if i == '0':\r\n continue\r\n C += i\r\n \r\n if int(A) + int(B) == int(C):\r\n print (\"YES\")\r\n else:\r\n print (\"NO\")\r\n \r\n \r\n", "a = input()\r\nb = input()\r\nc = [i for i in a if i != \"0\"]\r\nd = [i for i in b if i != \"0\"]\r\ne = [ i for i in str(int(a)+int(b)) if i != \"0\"]\r\nif int(\"\".join(c))+int(\"\".join(d)) == int(\"\".join(e)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n", "a = int(input())\r\nb = int(input())\r\n\r\nc = a + b\r\n\r\na_str = str(a)\r\nb_str = str(b)\r\nc_str = str(c)\r\n\r\nnew_a = int(a_str.replace(\"0\", \"\"))\r\nnew_b = int(b_str.replace(\"0\", \"\"))\r\nnew_c = int(c_str.replace(\"0\", \"\"))\r\n\r\nif new_c == new_a + new_b:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=int(input())\r\nb=int(input())\r\nfirst=a+b\r\nohh=''\r\namulya=str(first)\r\nfor k in range (0,len(amulya)):\r\n if(amulya[k]!='0'):\r\n ohh+=amulya[k]\r\ns1=''\r\ns2=''\r\nk=str(a)\r\nh=str(b)\r\nfor i in range (0,len(k)):\r\n if(k[i]!='0'):\r\n s1+=k[i]\r\nfor j in range (0,len(h)):\r\n if(h[j]!='0'):\r\n s2+=h[j]\r\nsecond=int(s1)+int(s2)\r\nif(int(ohh)==int(second)):\r\n print('YES')\r\nelse:\r\n print('NO')", "a1=(input())\r\na2=(input())\r\na3=str(int(a1)+int(a2))\r\nfor i in a1:\r\n if i==\"0\":\r\n a1=a1.replace(i, \"\")\r\nfor i in a2:\r\n if i==\"0\":\r\n a2= a2.replace(\"0\", \"\")\r\nfor i in a3:\r\n if i==\"0\":\r\n a3= a3.replace(\"0\", \"\")\r\na4=str(int(a1)+int(a2))\r\nif a3==a4:\r\n print('YES')\r\nelse:\r\n print('NO')", "def without0(m):\r\n n=0\r\n i=0\r\n while m>0:\r\n if m%10!=0:\r\n n=n+(m%10)*10**i\r\n i=i+1\r\n m=m//10\r\n return n\r\n\r\na=int(input())\r\nb=int(input())\r\nc=a+b\r\nif without0(c)==without0(a) +without0(b):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import re\nnumbers=[input(),input()]\nactual_answer=int(numbers[0])+int(numbers[1])\nactual_answe_with_out_zero=int(re.sub(r'0','',str(actual_answer)))\nnumbers_with_out_zero=[re.sub(r'0','',numbers[0]),re.sub(r'0','',numbers[1])]\nfalse_answer=int(numbers_with_out_zero[0])+int(numbers_with_out_zero[1])\nif actual_answe_with_out_zero==false_answer:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "a = input()\nb = input()\nc = a.replace('0','')\nd = b.replace('0','')\nif int(str(int(a) + int(b)).replace('0','')) == int(c) + int(d):\n print(\"YES\")\nelse:\n print(\"NO\")", "import math\r\nfrom sys import stdin, stdout\r\nimport collections\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 = str_input()\r\n b = str_input()\r\n c = str(int(a)+int(b))\r\n a1 = a.replace('0', '')\r\n b1 = b.replace('0', '')\r\n c1 = c.replace('0', '')\r\n if int(a1)+int(b1) == int(c1):\r\n print(\"YES\\n\")\r\n else:\r\n print(\"NO\\n\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "def removeZeroes(a):\n x = ''\n for i in a:\n if i != '0':\n x += i\n return x\n\n\nn1 = input()\nn2 = input()\n\nans1 = int(n1)+int(n2)\nans2 = int(removeZeroes(n1))+int(removeZeroes(n2))\n\nif removeZeroes(str(ans1)) == str(ans2):\n print('YES')\nelse:\n print('NO')\n\n \t \t\t\t \t\t\t \t \t \t\t\t \t \t \t\t\t\t", "def NumberWithoutZero(a) :\r\n i = 0\r\n Number_zero = 0\r\n chuso = 0\r\n while a >= 1 :\r\n chuso = a % 10\r\n if chuso != 0 :\r\n Number_zero += chuso * (10**i)\r\n i +=1\r\n a = a // 10\r\n return Number_zero\r\n\r\na = int(input())\r\nb = int(input())\r\nc= int (a + b)\r\nif NumberWithoutZero(a) + NumberWithoutZero(b) == NumberWithoutZero(c) :\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\")\r\n", "a = input()\r\nb = input()\r\n\r\nprint('YES' if (str(int(''.join(a.replace('0', ''))) + int(''.join(b.replace('0', '')))) == ''.join(str(int(a) + int(b)).replace('0', ''))) else 'NO')", "a = input()\r\nb = input()\r\nog = eval(f\"{a} + {b}\")\r\nnew = eval(f\"{a.replace('0', '')} + {b.replace('0', '')}\")\r\nprint(\"YES\" if str(og).replace('0', '') == str(new) else \"NO\")", "a = input()\r\nb = input()\r\nc = int(a)+int(b)\r\n\r\na_ = ''.join(a.split('0'))\r\nb_ = ''.join(b.split('0'))\r\nc_ = int(a_)+int(b_)\r\nc = int(''.join(str(c).split('0')))\r\nif c == c_:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "a = int(input())\nb = int(input())\nc = a + b\ndef chuso(x):\n j = 0\n ans = 0\n while (x!= 0):\n dig = x%10\n x = x // 10\n if ( dig != 0) :\n ans = ans + dig*(10**(j))\n j = j + 1\n return ans\nif (chuso(a)+chuso(b)==chuso(c)):\n print(\"YES\")\nelse :\n print(\"NO\")", "def solve(n,k):\n\tc= str(int(n) + int(k))\n\tn=n.replace('0' ,'')\n\tk=k.replace('0' ,'')\n\tc=c.replace('0' ,'')\n\t\n\n\tif int(n)+int(k) ==int(c) :\n\t\treturn 'YES'\n\telse:\n\t\treturn 'NO'\n\t\n\n\n\n\n\t\t\n\t\n\n\n\nl2=input()\nl3=input()\n\n\n\nprint(solve(l2,l3) )", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nx = ''\r\ny = ''\r\nz = ''\r\nfor d in str(c) :\r\n if d != '0' :\r\n z += d\r\nz = int(z)\r\nfor d in str(a) :\r\n if d != '0' :\r\n x += d\r\nx = int(x)\r\nfor d in str(b) :\r\n if d != '0' :\r\n y += d\r\ny = int(y)\r\nif x + y == z :\r\n print('YES')\r\nelse :\r\n print('NO')\r\n ", "a = input()\r\nb = input()\r\nc = str(int(a)+int(b))\r\n\r\na1 = \"\"\r\nb1=\"\"\r\nc1=\"\"\r\nfor i in a:\r\n if i!='0':\r\n a1+=i\r\n\r\nfor i in b:\r\n if i!='0':\r\n b1+=i\r\n\r\nfor i in c:\r\n if i!='0':\r\n c1+=i\r\n\r\nif int(c1)==int(a1)+int(b1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def checkADD():\r\n ins = [input() for x in range(2)]\r\n summ = int(str(sum([int(x) for x in ins])).replace(\"0\" , \"\"))\r\n ins = [int(x.replace(\"0\" , \"\")) for x in ins]\r\n if summ == sum(ins):\r\n return \"YES\"\r\n return \"NO\"\r\n\r\nprint(checkADD())", "a = int(input())\r\nb = int(input())\r\nc = a+b\r\ns1 = str(a)\r\ns2 = str(b)\r\ns3 = str(c)\r\ns1 = s1.replace('0', '')\r\ns2 = s2.replace('0', '')\r\ns3 = s3.replace('0', '')\r\na1 = int(s1)\r\nb1 = int(s2)\r\nc1 = int(s3)\r\nif a1+b1 == c1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\nsum1 = a+b\r\na1 = \"\"\r\nb1 = \"\"\r\nfor i in str(a):\r\n\tif i != \"0\":\r\n\t\ta1+=i\r\nfor i in str(b):\r\n\tif i != \"0\":\r\n\t\tb1+=i\r\nsum2 = \"\"\r\nfor i in str(sum1):\r\n\tif i != \"0\":\r\n\t\tsum2+=i\r\nif int(a1)+int(b1) == int(sum2):print(\"YES\")\r\nelse:print(\"NO\")", "n = input()\r\nm = input()\r\nc = str(int(n)+int(m))\r\n\r\nnn = int(n.replace('0',\"\"))\r\nmm = int(m.replace('0',\"\"))\r\ncc = int(c.replace('0',\"\"))\r\n\r\nif nn+mm == cc:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def removeZeros(n):\r\n\tnewN=0\r\n\tten=1\r\n\twhile n:\r\n\t\tdigit=n%10\r\n\t\tn//=10\r\n\t\tif digit:\r\n\t\t\tnewN+=(digit*ten)\r\n\t\t\tten*=10\r\n\treturn newN\r\na=int(input())\r\nb=int(input())\r\nc=a+b\r\na=removeZeros(a)\r\nb=removeZeros(b)\r\nc=removeZeros(c)\r\nif a+b==c:\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "num1 = input()\r\nnum1_new = num1.replace('0', '')\r\nnum2 = input()\r\nnum2_new = num2.replace('0', '')\r\n \r\n \r\nsum1 = int(num1) + int(num2)\r\nsum1_new = str(sum1).replace('0', '')\r\n \r\nsum2 = int(num1_new) + int(num2_new)\r\n#sum2 without zeros\r\nif int(sum1_new) == int(sum2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n ", "A = input()\r\nB = input()\r\na = \"\"\r\nb=\"\"\r\npred_c=\"\"\r\npred_C = int(A)+int(B)\r\npred_C = str(pred_C)\r\nfor i in A:\r\n if i!=\"0\":\r\n a+=i\r\nfor j in B:\r\n if j!=\"0\":\r\n b+=j\r\nfor k in pred_C:\r\n if k !=\"0\":\r\n pred_c +=k\r\nc = int(a)+int(b)\r\nif int(pred_c) ==c:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def elemininateZero(number):\r\n total=0\r\n counting=-1\r\n while(number>0):\r\n individualDigit=number%10\r\n if(individualDigit!=0):\r\n counting+=1\r\n total+=individualDigit*(10**counting)\r\n number//=10\r\n return total\r\n\r\ndef checkingNoZeroTotal(firstNumber,secondNumber,finalNumber):\r\n checkingFinal=False\r\n a=elemininateZero(firstNumber)\r\n b=elemininateZero(secondNumber)\r\n c=elemininateZero(finalNumber)\r\n if(a+b==c):\r\n checkingFinal=True\r\n else:\r\n checkingFinal=False\r\n return checkingFinal\r\n\r\na=int(input())\r\nb=int(input())\r\nc=a+b\r\nif(checkingNoZeroTotal(a,b,c)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "a = int(input())\r\nb = int(input())\r\nc = a+b\r\na = list(str(a))\r\nb = list(str(b))\r\nc = list(str(c))\r\nnew_a = int(a[0])\r\nnew_b = int(b[0])\r\nnew_c = int(c[0])\r\ni = 1\r\nwhile i < len(a):\r\n if int(a[i]) != 0:\r\n new_a = new_a*10+int(a[i])\r\n i += 1\r\ni = 1\r\nwhile i < len(b):\r\n if int(b[i]) != 0:\r\n new_b = new_b*10+int(b[i])\r\n i += 1\r\ni = 1\r\nwhile i < len(c):\r\n if int(c[i]) != 0:\r\n new_c = new_c*10+int(c[i])\r\n i += 1\r\nif new_a+new_b == new_c:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def xoaso(n):\r\n count = 0\r\n e = 0\r\n while n > 0:\r\n a = n % 10\r\n n = n // 10\r\n if a != 0 :\r\n f = a*(10**count)\r\n count +=1\r\n e += f\r\n return e\r\nk = int(input())\r\nm = int(input())\r\nc = k + m\r\nif xoaso(k)+xoaso(m) == xoaso(c):\r\n print('YES')\r\nelse:\r\n print('NO')", "n = input()\r\nm = input()\r\n\r\nif (str(int(n.replace(\"0\", \"\")) + int(m.replace(\"0\", \"\"))) == (str(int(n) + int(m))).replace(\"0\", \"\")):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import sys\r\n\r\na= input()\r\nb= input()\r\nc= str(int(a)+int(b))\r\nref=[]\r\nfor i in [a,b,c]:\r\n i=list(i)\r\n for j in range(len(i)):\r\n if i[j]==\"0\":\r\n i[j]=\"\"\r\n \r\n ref +=[\"\".join(i)]\r\nref = list(map(int, ref)) \r\n \r\nprint(\"YES\") if ref[0]+ref[1]==ref[2] else print(\"NO\")\r\n", "a = input().strip() # read input a as string\r\nb = input().strip() # read input b as string\r\n\r\n# remove zeros from a and b\r\na_without_zeros = a.replace('0', '')\r\nb_without_zeros = b.replace('0', '')\r\n\r\n# calculate c as the sum of a and b\r\nc = str(int(a) + int(b))\r\n\r\n# remove zeros from c\r\nc_without_zeros = c.replace('0', '')\r\n\r\n# check if the equation remains correct after removing zeros\r\nif int(a_without_zeros) + int(b_without_zeros) == int(c_without_zeros):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a=input()\r\nb=input()\r\nc1=str(int(a)+int(b))\r\na=a.replace(\"0\", \"\")\r\nb=b.replace(\"0\", \"\")\r\nc1=c1.replace(\"0\", \"\")\r\nif (str(int(a)+int(b))==str(c1)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import sys\r\ninput = sys.stdin.readline\r\n\r\na = input()[:-1]\r\nb = input()[:-1]\r\n\r\nif int(str(int(a) + int(b)).replace('0','')) == int(a.replace('0','')) + int(b.replace('0','')):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\nd=str(a)\r\ne=str(b)\r\nf=str(c)\r\nk=\"\"\r\nl=\"\"\r\nm=\"\"\r\nfor i in range(len(d)):\r\n if d[i]!='0':\r\n k=k+d[i]\r\nfor i in range(len(e)):\r\n if e[i]!='0':\r\n l=l+e[i]\r\nfor i in range(len(f)):\r\n if f[i]!='0':\r\n m=m+f[i]\r\nk=int(k)\r\nl=int(l)\r\nm=int(m)\r\nif k+l==m:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\nb = input()\r\nc = str(int(a) + int(b))\r\n\r\ntmp=[]\r\nfor ch in a:\r\n if ch == '0':\r\n continue\r\n else:\r\n tmp.append(ch)\r\na1 = int(''.join(tmp))\r\ntmp=[]\r\nfor ch in b:\r\n if ch == '0':\r\n continue\r\n else:\r\n tmp.append(ch)\r\nb1 = int(''.join(tmp))\r\ntmp=[]\r\nfor ch in c:\r\n if ch =='0':\r\n continue\r\n else:\r\n tmp.append(ch)\r\nc1 = int(''.join(tmp))\r\n\r\nif a1+b1 == c1:\r\n print('YES')\r\nelse:\r\n print('NO')", "a = int(input())\r\nb = int(input())\r\n_a = ''\r\n_b = ''\r\n_t = ''\r\nfor i in str(a):\r\n if i == '0':\r\n continue\r\n _a += i\r\nfor i in str(b):\r\n if i == '0':\r\n continue\r\n _b += i\r\nfor i in str(a+b):\r\n if i == '0':\r\n continue\r\n _t += i\r\nif int(_a) + int(_b) == int(_t):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n ", "a =int(input())\nb =int(input())\ncorrrect_sum =a+b\nx =\"\"\ny =\"\"\nnew_sum =\"\"\nfor i in range(len(str(a))):\n if str(a)[i]!=\"0\":\n x +=str(a)[i]\nfor i in range(len(str(b))):\n if str(b)[i]!=\"0\":\n y +=str(b)[i]\n\nfor i in range(len(str(corrrect_sum))):\n if str(corrrect_sum)[i]!=\"0\":\n new_sum +=str(corrrect_sum)[i]\nif int(x)+int(y)==int(new_sum):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "a = int(input())\r\nb = int(input())\r\n\r\ndef removeZero(x):\r\n a = str(x)\r\n s = ''\r\n for i in a:\r\n if i != '0':\r\n s += i\r\n return int(s)\r\n\r\n\r\nif removeZero(a) + removeZero(b) == removeZero(a+b):\r\n print('YES')\r\nelse:\r\n print('NO')", "i=input\r\nr=str.replace\r\nn=i();m=i();s=str(eval(n+'+'+m))\r\nprint(['YES','NO'][eval(r(n,'0','')+'+'+r(m,'0',''))!=int(r(s,'0',''))])", "num1 = input()\nnum2 = input()\nif int(num1.replace('0', '')) + int(num2.replace('0', '')) == int(str(int(num1) + int(num2)).replace('0', '')):\n print('YES')\nelse:\n print('NO')\n", "from sys import stdin,stdout\r\n#input = stdin.readline\r\n\r\ndef main():\r\n #t = int(input())\r\n t = 1\r\n for z in range(t):\r\n #n = int(input())\r\n #a,b,c = map(int,input().split())\r\n #ai = list(map(int,input().split()))\r\n s =input()\r\n s2 = input()\r\n print([\"YES\",\"NO\"][int(s.replace(\"0\",\"\")) +\r\n int(s2.replace(\"0\",\"\"))\r\n !=\r\n int(str(int(s) +\r\n int(s2)).replace(\"0\",\"\"))])\r\nmain()\r\n", "a=input()\r\nb=input()\r\nc=a.replace(\"0\",\"\")\r\nd=b.replace(\"0\",\"\")\r\nResult=int(a)+int(b)\r\nResult=str(Result)\r\nResult=Result.replace(\"0\",\"\")\r\nif int(c)+int(d)==int(Result):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "x = (input())\r\ny = (input())\r\n\r\n\r\nr_1 = str(int(x) + int(y))\r\n\r\nx=x.replace(\"0\",\"\")\r\ny=y.replace(\"0\",\"\")\r\nr_1 = r_1.replace(\"0\",\"\")\r\n\r\nr_2 = str(int(x) + int(y))\r\n\r\n\r\nif(r_1 == r_2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def f(x):\r\n return int(''.join(list(filter(lambda z: z != '0', x))))\r\n\r\na = input()\r\nb = input()\r\nc = str(int(a) + int(b))\r\nA = f(a)\r\nB = f(b)\r\nC = f(c)\r\nprint(\"YES\" if A + B == C else \"NO\")", "a=int(input())\r\nb=int(input())\r\na_a=int(str(a).replace('0',''))\r\nb_b=int(str(b).replace('0',''))\r\n\r\ns=str(a+b).replace('0','')\r\ns_s=a_a+b_b\r\n\r\nif int(s)==int(s_s):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\r\n", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\na = str(a)\r\nb = str(b)\r\nc = str(c)\r\nwhile '0' in a:\r\n a = a.replace('0', '')\r\nwhile '0' in b:\r\n b = b.replace('0', '')\r\nwhile '0' in c:\r\n c = c.replace('0', '')\r\na = int(a)\r\nb = int(b)\r\nc = int(c)\r\nf = a + b\r\nif c == f:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "# https://codeforces.com/problemset/problem/75/A \n\na = input()\nb = input()\n\nc = int(a) + int(b)\n\na_n = int(a.replace(\"0\", \"\"))\nb_n = int(b.replace(\"0\", \"\"))\n\n\nprint(\"YES\" if a_n + b_n == int(str(c).replace(\"0\", \"\")) else \"NO\")\n", "def zeros_away(n):\n n = str(n)\n ans = ''\n for i in range(len(n)):\n if n[i] != '0':\n ans += n[i]\n return int(ans)\n\n\na = int(input())\nb = int(input())\nif zeros_away(a) + zeros_away(b) == zeros_away(a + b):\n print('YES')\nelse:\n print('NO')\n", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nx = int(str(a).replace('0', ''))\r\ny = int(str(b).replace('0', ''))\r\nz = int(str(c).replace('0', ''))\r\nif x + y == z:\r\n print(\"YES\")\r\nelse:\r\n print('NO')", "a = input()\r\nb = input()\r\ntemp = ''.join(str(int(a) + int(b)).split('0'))\r\na, b = ''.join(a.split('0')), ''.join(b.split('0'))\r\nif temp == str(int(a) + int(b)):\r\n print('YES')\r\nelse:\r\n print('NO')", "a=input()\r\nb=input()\r\nc=str(int(a)+int(b))\r\na=\" \".join(a)\r\na=a.split()\r\nb=\" \".join(b)\r\nb=b.split()\r\nc=\" \".join(c)\r\nc=c.split()\r\nm1=\"\"\r\nm2=\"\"\r\nm3=\"\"\r\nfor k in range (len(a)):\r\n if a[k]!=\"0\":\r\n m1=m1+a[k]\r\nfor h in range (len(b)):\r\n if b[h]!=\"0\":\r\n m2=m2+b[h]\r\nfor j in range (len(c)):\r\n if c[j]!=\"0\":\r\n m3=m3+c[j]\r\nif int(m1)+int(m2)==int(m3):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "p=input()\r\nq=input()\r\np=int(p)\r\nq=int(q)\r\nr=p+q\r\na=\"\"\r\nwhile(r):\r\n if(r%10!=0):\r\n a=chr(48+r%10)+a\r\n r=r//10\r\nb=\"\"\r\nc=\"\"\r\nwhile(p):\r\n if(p%10!=0):\r\n b=chr(48+p%10)+b\r\n p=p//10\r\np=q\r\nwhile(p):\r\n if(p%10!=0):\r\n c=chr(48+p%10)+c\r\n p=p//10\r\nif(int(a)==int(b)+int(c)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "# Templates for the inputs:\r\nfrom typing import List\r\nfrom collections import Counter, defaultdict\r\nimport sys\r\n\r\ndef stringInput() -> str:\r\n return sys.stdin.readline()\r\n \r\ndef listInput() -> List[int]:\r\n return list(map(int, input().split()))\r\n \r\ndef string_list() -> List[int]:\r\n return list(input())\r\ndef intInput() -> int:\r\n return int(input())\r\n \r\n\r\n \r\ndef solve():\r\n # Write your code here...\r\n a = input()\r\n b = input()\r\n \r\n real_c = int(a) + int(b)\r\n\r\n a_new = a.replace('0', '')\r\n b_new = b.replace('0', '')\r\n\r\n tmp = str(real_c).replace('0', '')\r\n \r\n if int(a_new) + int(b_new) == int(tmp):\r\n print('YES')\r\n else:\r\n print('NO')\r\n \r\n \r\n \r\n# Driver code... \r\nif __name__ == '__main__':\r\n solve()\r\n \r\n \r\n \r\n \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 = int(input())\r\nb = int(input())\r\nc = a + b\r\n\r\nk = 1\r\ns_a = 0\r\nwhile a>0:\r\n last = a%10\r\n s_a += last * k\r\n if last!=0:\r\n k *= 10\r\n a //= 10\r\n\r\nk = 1\r\ns_b = 0\r\nwhile b>0:\r\n last = b%10\r\n s_b += last * k\r\n if last!=0:\r\n k *= 10\r\n b //= 10 \r\n\r\nk = 1\r\ns_c = 0\r\nwhile c>0:\r\n last = c%10\r\n s_c += last * k\r\n if last!=0:\r\n k *= 10\r\n c //= 10\r\n\r\nif s_a + s_b == s_c:\r\n print('YES')\r\nelse:\r\n print('NO')", "a = input()\r\nb = input()\r\nc = str(int(a)+int(b))\r\nstr1 = \"\"\r\nstr2 = \"\"\r\nstr3 = \"\"\r\nfor i in a:\r\n if i != '0':\r\n str1 += i\r\nfor i in b:\r\n if i != '0':\r\n str2 += i\r\nfor i in c:\r\n if i != '0':\r\n str3 += i\r\nif int(str1)+int(str2) == int(str3):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "a,b=int(input()),int(input())\r\nc=a+b\r\nsa,sb,sc=str(a),str(b),str(c)\r\nsa,sb,sc=sa.replace(\"0\",\"\"),sb.replace(\"0\",\"\"),sc.replace(\"0\",\"\")\r\nif int(sa)+int(sb)==int(sc):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\ninta = [x for x in str(a) if x != '0']\r\nintb = [x for x in str(b) if x != '0']\r\nres = [x for x in str(a + b) if x != '0']\r\nif int(''.join(res)) == int(''.join(inta)) + int(''.join(intb)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "x=input()\r\ny=input()\r\nz=str(int(x)+int(y))\r\nwhile \"0\" in x or \"0\" in y or \"0\" in z:\r\n x=x.replace(\"0\",\"\")\r\n y=y.replace(\"0\",\"\")\r\n z = z.replace(\"0\", \"\")\r\nif int(x)+int(y) == int(z):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input()\r\nt = input()\r\n\r\nres = str(int(s) + int(t))\r\n# for i in s:\r\n# \tif i == \"0\":\r\ns = s.replace(\"0\", \"\")\r\n# for j in t:\r\n# \tif j == \"0\":\r\nt = t.replace(\"0\", \"\")\r\n\r\nx = int(s) + int(t)\r\n\r\nres = res.replace(\"0\", \"\")\r\nif int(res) == int(x):\r\n\tprint(\"YES\")\r\nelse: print(\"NO\")", "a=input()\r\nb=input()\r\nc=str(int(a)+int(b))\r\n\r\na1=int(a.replace(\"0\",\"\"))\r\nb1=int(b.replace(\"0\",\"\"))\r\nc1=int(c.replace(\"0\",\"\"))\r\nif a1+b1==c1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a,b = int(input()), int(input())\r\ntry:\r\n exec(f\"assert {a}+{b}=={a+b}\".replace(\"0\",\"\"))\r\n print(\"YES\")\r\nexcept:\r\n print(\"NO\")", "def remove(n,i):\n n=str(0)+n[0:i]+n[i+1:]\n return n\n \na=int(input())\nb=int(input())\nc=a+b\ntemp_c=c\n\na,b,c = str(a),str(b),str(c)\nfor i in range(len(a)):\n if a[i]==\"0\":\n a=remove(a,i)\nfor i in range(len(b)):\n if b[i]==\"0\":\n b=remove(b,i)\nfor i in range(len(c)):\n if c[i]==\"0\":\n c=remove(c,i)\nif int(a)+int(b)==int(c):\n print(\"YES\")\nelse:\n print(\"NO\")\n \n \n \n", "a=input()\r\nb=input()\r\nc=str(int(a)+int(b))\r\na,b,c=list(a),list(b),list(c)\r\n\r\n\r\ntry:\r\n while(1):\r\n a.remove('0')\r\nexcept ValueError:\r\n pass\r\ntry:\r\n while(1):\r\n b.remove('0')\r\nexcept ValueError:\r\n pass\r\ntry:\r\n while(1):\r\n c.remove('0')\r\nexcept ValueError:\r\n pass\r\ne,f,g=\"\",\"\",\"\"\r\ne=int(e.join(a))\r\nf=int(f.join(b))\r\ng=int(g.join(c))\r\nif(e+f==g):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "first = input()\r\nsecond = input()\r\ns = int(first) + int(second)\r\nif int(first.replace('0', '')) + int(second.replace('0', '')) == int(str(s).replace('0','')):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n1, n2 = input(), input()\r\nm1, m2, m3 = n1.replace(\"0\", \"\"), n2.replace(\"0\", \"\"), str(int(n1) + int(n2)).replace(\"0\", \"\")\r\nprint(\"YES\") if int(m3) == int(m1) + int(m2) else print(\"NO\")\r\n", "a=input()\r\nb=input()\r\nc=str(int(a)+int(b))\r\na1=\"\"\r\nb1=\"\"\r\nc1=\"\"\r\nfor s in a:\r\n if s!='0':\r\n a1+=s\r\nfor s in b:\r\n if s!='0':\r\n b1+=s\r\nfor s in c:\r\n if s!='0':\r\n c1+=s\r\n\r\nif int(a1)+int(b1)==int(c1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "x = int(input())\r\ny = int(input())\r\nz = x + y\r\nx1 = str(x)\r\ny1 = str(y)\r\nz1 = str(z)\r\nx2 = ''\r\ny2 = ''\r\nz2 = ''\r\nfor i in range(len(x1)):\r\n if(x1[i] != '0'):\r\n x2+=x1[i]\r\nfor i in range(len(y1)):\r\n if(y1[i] != '0'):\r\n y2+=y1[i] \r\nfor i in range(len(z1)):\r\n if(z1[i] != '0'):\r\n z2+=z1[i] \r\nx = int(x2)\r\ny = int(y2)\r\nz = int(z2) \r\nif x +y == z:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n\r\n", "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\n\r\ndef Life_Without_Zeros():\r\n def stringToNum(stringList):\r\n num = 0\r\n power = 0\r\n for index in range(len(stringList)):\r\n index_from_behind = len(stringList) - index - 1\r\n num += int(stringList[index_from_behind])*(10**power)\r\n power += 1\r\n return num\r\n \r\n def numToStringList(num):\r\n stringList = []\r\n while num>0:\r\n lastDigit = num%10\r\n stringList.insert(0,str(lastDigit))\r\n num = num//10\r\n return(stringList)\r\n\r\n\r\n\r\n a_sr = insr()\r\n a_num = stringToNum(a_sr)\r\n b_sr = insr()\r\n b_num = stringToNum(b_sr)\r\n \r\n add_result_num = a_num + b_num\r\n add_result_sr = numToStringList(add_result_num)\r\n #print(a_sr,a_num,b_sr,b_num,add_result_sr,add_result_num)\r\n\r\n a_sr_new = []\r\n b_sr_new = []\r\n add_result_sr_new = []\r\n\r\n for digit in a_sr:\r\n if digit != '0':\r\n a_sr_new.append(digit)\r\n \r\n for digit in b_sr:\r\n if digit != '0':\r\n b_sr_new.append(digit)\r\n \r\n for digit in add_result_sr:\r\n if digit != '0':\r\n add_result_sr_new.append(digit)\r\n \r\n a_num_new = stringToNum(a_sr_new)\r\n b_num_new = stringToNum(b_sr_new)\r\n add_result_num_new = stringToNum(add_result_sr_new)\r\n\r\n actualNewResult = a_num_new + b_num_new\r\n if actualNewResult == add_result_num_new:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n return\r\n\r\n\r\nLife_Without_Zeros()", "a, b = (input() for _ in range(2))\ndef process(x):\n return int(x.replace(\"0\", \"\"))\nres = \"YES\" if process(a) + process(b) == process(str(int(a) + int(b))) else \"NO\"\nprint(res)\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\na1=str(a).replace(\"0\",\"\")\r\na2=int(a1)\r\nb1=str(b).replace(\"0\",\"\")\r\nb2=int(b1)\r\nc1=str(c).replace(\"0\",\"\")\r\nc2=int(c1)\r\nc3=a2+b2\r\nif c3==c2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "p=input()\r\nq=input()\r\nr=str(int(p)+int(q))\r\nr=int(r.replace('0',''))\r\na=int(p.replace('0',''))\r\nb=int(q.replace('0',''))\r\nif(r==a+b):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "I = lambda : map(int, input().split())\r\na = input() ; b = input()\r\nx = int(a) + int(b)\r\na = a.replace('0', \"\") ; b = b.replace('0', \"\") \r\nz = int(a) + int(b)\r\nx = str(x) ; x = x.replace('0', \"\") ; z = str(z)\r\nprint('YES' if x == z else 'NO')", "import math\r\ndef main():\r\n a = input()\r\n b = input()\r\n res = str(int(a) + int(b))\r\n a = [i for i in a if i != '0']\r\n t_a, t_b, t_res = '', '', ''\r\n b = [i for i in b if i != '0']\r\n res = [i for i in res if i != '0']\r\n for i in a:\r\n t_a += i\r\n for i in b:\r\n t_b += i\r\n for i in res:\r\n t_res += i\r\n if int(t_a) + int(t_b) == int(t_res):\r\n print('YES')\r\n else:\r\n print('NO')\r\nif __name__ == \"__main__\":\r\n main()", "def solve(num):\n\tans, deci = 0, 1\n\twhile num != 0:\n\t\trem = num % 10\n\t\tif rem: \n\t\t\tans += deci * rem\n\t\t\tdeci *= 10\n\t\tnum //= 10\n\treturn ans\n\n## Execution\n\t\nnum1 = int(input())\nnum2 = int(input())\nsum = num1 + num2\nif solve(num1) + solve(num2) == solve(sum): print('YES')\nelse: print('NO')\n \t \t\t \t\t\t\t \t\t\t \t \t\t\t \t\t\t \t", "a1 = input()\r\nb1 = input()\r\nc1 = int(a1) + int(b1)\r\nc1_str = str(c1)\r\nc1_n = ''\r\na2 = ''\r\nb2 = ''\r\nfor i in range(len(c1_str)):\r\n if c1_str[i] != '0' :\r\n c1_n += c1_str[i]\r\nfor i in range(len(a1)):\r\n if a1[i] != '0' :\r\n a2 += a1[i]\r\nfor i in range(len(b1)):\r\n if b1[i] != '0':\r\n b2 += b1[i]\r\n\r\nif int(c1_n) == (int(a2) + int(b2)) :\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\")\r\n", "a = int(input())\r\nstra = str(a)\r\nb = int(input())\r\nstrb = str(b)\r\nc = a + b\r\nstra = int(stra.replace('0',''))\r\nstrb = int(strb.replace('0',''))\r\nc = int(str(c).replace('0',''))\r\nprint('YES' if (stra + strb == c) else 'NO')", "s=input()\r\nt=input()\r\nsum=str(int(s)+int(t)).replace('0','')\r\ns=s.replace('0','')\r\nt=t.replace('0','')\r\nnew_sum=str(int(s)+int(t))\r\nif sum==new_sum:\r\n print('YES')\r\nelse:\r\n print('NO')", "x=input()\r\ny=input()\r\nk1=[]\r\nk2=[]\r\nk3=[]\r\nsol=int(x)+int(y)\r\nfor i in x:\r\n if i==\"0\":\r\n pass\r\n else:\r\n k1.append(str(i))\r\nfor j in y:\r\n if j==\"0\":\r\n pass\r\n else:\r\n k2.append(str(j))\r\nfor j in str(sol):\r\n if j==\"0\":\r\n pass\r\n else:\r\n k3.append(str(j))\r\no1=int(\"\".join(k1))\r\no2=int(\"\".join(k2))\r\no3=int(\"\".join(k3))\r\nif o1+o2==o3:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = int(input())\r\nb = int(input())\r\n\r\nc = a + b\r\na = str(a)\r\nb = str(b)\r\nc = str(c)\r\n\r\nx = a.replace('0' , \"\")\r\ny = b.replace('0' , \"\")\r\nz = c.replace('0' , \"\")\r\n\r\nd = int(y) + int(x)\r\n# print(d)\r\n\r\nprint(\"YES\" if d == int(z) else \"NO\")", "a = input()\r\nb = input()\r\nc = str(int(a) + int(b))\r\n\r\naa = a.replace('0', '')\r\nbb = b.replace('0', '')\r\ncc = c.replace('0', '')\r\n\r\nif int(aa) + int(bb) == int(cc):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "n = int(input())\r\nm = int(input())\r\nsum = n + m\r\ncheck_one = n + m == sum\r\n\r\nn_list = '-'.join(str(n)).split('-')\r\nm_list = '-'.join(str(m)).split('-')\r\nsum_list = '-'.join(str(sum)).split('-')\r\n\r\nwhile '0' in n_list or '0' in m_list or '0' in sum_list:\r\n if '0' in n_list:\r\n n_list.remove('0')\r\n else:\r\n n_list = n_list\r\n if '0' in m_list:\r\n m_list.remove('0')\r\n else:\r\n m_list = m_list\r\n if '0' in sum_list:\r\n sum_list.remove('0')\r\n else:\r\n sum_list = sum_list\r\n\r\nn_list = int(''.join(n_list))\r\nm_list = int(''.join(m_list))\r\nsum_list = int(''.join(sum_list))\r\ncheck_two = n_list + m_list == sum_list\r\n\r\nif check_one == check_two:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n# # check_two = sum(n_list[:])\r\n# # print(check_two)\r\n# print(n_list)\r\n# print(m_list)\r\n# print(sum_list)\r\n", "import sys\r\nimport math\r\n\r\ndef mf(val):\r\n lv = len(val)\r\n res = 0\r\n n = 1\r\n for i in range(lv - 1, -1, -1):\r\n if(val[i] != '0'):\r\n res += int(val[i]) * n\r\n n *= 10\r\n return res\r\n \r\nast = sys.stdin.readline()\r\nbst = sys.stdin.readline()\r\n\r\nif(mf(str(int(ast) + int(bst))) == mf(ast[:len(ast) - 1]) + mf(bst[:len(bst) - 1])):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n ", "a=int(input())\r\nb=int(input())\r\ns=str(a).replace('0','')\r\ns1=str(b).replace('0','')\r\nif int(s)+int(s1) == int(str(a+b).replace('0','')):\r\n print('YES')\r\nelse:\r\n print('NO')", "a = input()\r\nb = input() \r\nc = str(int(a) + int(b)) \r\na1 = int(a.replace('0',''))\r\nb1 = int(b.replace('0',''))\r\nc1 = int(c.replace('0',''))\r\nif a1 + b1 == c1:\r\n print('YES')\r\nelse:\r\n print('NO')", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\na = int(str(a).replace('0', ''))\r\nb = int(str(b).replace('0', ''))\r\nc = int(str(c).replace('0', ''))\r\nif a + b == c:\r\n print('YES')\r\n exit()\r\nprint('NO')", "a=int(input())\r\nb=int(input())\r\nl=a+b\r\nl=str(l)\r\nl=l.replace(\"0\",\"\")\r\na=str(a)\r\nb=str(b)\r\na=a.replace(\"0\",\"\")\r\nb=b.replace(\"0\",\"\")\r\nd=int(a)+int(b)\r\nd=str(d)\r\nif l==d:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=input()\r\nb=input()\r\nc=str(int(a)+int(b))\r\na1=''\r\nb1=''\r\nc1=''\r\nfor i in range(len(a)):\r\n if(a[i]!='0'):\r\n a1+=a[i]\r\nfor i in range(len(b)):\r\n if(b[i]!='0'):\r\n b1+=b[i]\r\nfor i in range(len(c)):\r\n if(c[i]!='0'):\r\n c1+=c[i] \r\nif(int(a1)+int(b1)==int(c1)):\r\n print('YES')\r\nelse:\r\n print('NO')", "a = int(input())\r\nb = int(input())\r\ns = list(str(a+b))\r\n\r\na = list(str(a))\r\nb = list(str(b))\r\n\r\nwhile a.count('0')>0:\r\n a.remove('0')\r\nwhile b.count('0')>0:\r\n b.remove('0')\r\nwhile s.count('0')>0:\r\n s.remove('0')\r\n \r\na = int(''.join(a))\r\nb = int(''.join(b))\r\ns = int(''.join(s))\r\n\r\nprint(\"YES\") if a+b==s else print(\"NO\")", "a = int(input())\r\nb = int(input())\r\nc = a+b\r\nd = int(str(a).replace(\"0\",\"\")) + int(str(b).replace(\"0\",\"\"))\r\nif str(c).replace(\"0\",\"\")==str(d):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "a=input()\r\nb=input()\r\na_=b_=c_=''\r\n\r\nfor i in a:\r\n if i!='0':\r\n a_+=i\r\n\r\nfor i in b:\r\n if i!='0':\r\n b_+=i\r\n\r\nc=int(a)+int(b)\r\n\r\nfor i in str(c):\r\n if i!='0':\r\n c_+=i\r\n\r\nprint('YES'if c_==str(int(a_)+int(b_))else'NO')", "a = input()\r\nb = input()\r\nc = str(int(a) + int(b))\r\nnums = [a, b, c]\r\n\r\nfor i in range(len(nums)):\r\n nums[i] = nums[i].replace('0', '')\r\n\r\nif int(nums[0]) + int(nums[1]) == int(nums[2]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=int(input())\r\nm=int(input())\r\nt=n+m\r\nt=list(str(t))\r\nans=''\r\nfor i in t:\r\n if(i==str(0)):\r\n continue\r\n else:\r\n ans+=i\r\nans=int(ans)\r\nn1=list(str(n))\r\na1=''\r\nfor i in n1:\r\n if(i==str(0)):\r\n continue\r\n else:\r\n a1+=i\r\nm1=list(str(m))\r\na2=''\r\nfor i in m1:\r\n if(i==str(0)):\r\n continue\r\n else:\r\n a2+=i\r\n\r\nif(ans== int(a1)+ int(a2)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\nb = input()\r\n\r\nf = int(a) + int(b)\r\ns = int(a.replace('0', '')) + int(b.replace('0', ''))\r\nif str(f).replace('0', '') == str(s):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\na=str(a)\r\nb=str(b)\r\nc=str(c) \r\na1,b1,c1='','',''\r\nfor i in a:\r\n if i=='0':\r\n continue\r\n a1+=i \r\nfor i in b:\r\n if i=='0':\r\n continue\r\n b1+=i \r\nfor i in c:\r\n if i=='0':\r\n continue\r\n c1+=i \r\nif (int(a1)+int(b1))==int(c1):\r\n print('YES')\r\nelse:\r\n print('NO')", "a = input() ; b = input()\r\nc = int(a) ; d = int(b)\r\ne = c+d ; f = str(e) ; z = f.replace('0','')\r\ng = a.replace('0','') ; h = b.replace('0','')\r\ni = int(g) ; j = int(h)\r\nk = i+j\r\nif str(k) == z:\r\n print('YES')\r\nelse:\r\n print('NO')", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\ncnt = 0\r\na1 = 0\r\nwhile a > 0:\r\n last = a % 10\r\n if last != 0:\r\n a1 = a1 + last * 10 ** cnt\r\n cnt += 1\r\n a = a // 10\r\ncnt = 0\r\nb1 = 0\r\nwhile b > 0:\r\n last = b % 10\r\n if last != 0:\r\n b1 = b1 + last * 10 ** cnt\r\n cnt += 1\r\n b = b // 10\r\ncnt = 0\r\nc1 = 0\r\nwhile c > 0:\r\n last = c % 10\r\n if last != 0:\r\n c1 = c1 + last * 10 ** cnt\r\n cnt += 1\r\n c = c // 10\r\nif a1 + b1 == c1:\r\n print('YES')\r\nelse:\r\n print('NO')", "def zero_remover(x):\r\n array=[]\r\n for digit in x:\r\n if(digit=='0'):\r\n continue\r\n else:\r\n array.append(digit)\r\n new=''\r\n for i in array:\r\n new+=i\r\n return (int(new))\r\n\r\na=input()\r\nb=input()\r\nc=str(int(a)+int(b))\r\nif(zero_remover(a)+zero_remover(b)==zero_remover(c)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = input()\r\nb = input()\r\n\r\ndef sum(a, b):\r\n\treturn a + b\r\n\r\nif sum(int(a.replace('0', '')), int(b.replace(\"0\", ''))) == int(str(int(a) + int(b)).replace('0', '')):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "def remove_zeros(num):\r\n num_str = str(num)\r\n result = \"\"\r\n for digit in num_str:\r\n if digit != '0':\r\n result += digit\r\n return int(result)\r\n\r\na = int(input())\r\nb = int(input())\r\n\r\n# Calculate sum with zeros removed\r\nsum_without_zeros = remove_zeros(a) + remove_zeros(b)\r\n\r\n# Calculate sum with zeros included\r\nactual_sum = a + b\r\n\r\n# Check if the equation remains correct\r\nif sum_without_zeros == remove_zeros(actual_sum):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\nnumbers=[a,b,c]\r\ni=0\r\nwhile i<3:\r\n chislo = numbers[i]\r\n razryad=1\r\n new_number=0\r\n while chislo>0:\r\n last=chislo%10\r\n if last!=0:\r\n new_number=last*razryad+new_number\r\n razryad *=10\r\n chislo //= 10\r\n numbers[i]=new_number\r\n i +=1\r\nif numbers[0]+numbers[1]==numbers[2]:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\na1=str(a)\r\nb1=str(b)\r\nc1=str(c)\r\na2=int(a1.replace(\"0\",\"\"))\r\nb2=int(b1.replace('0',\"\"))\r\nc2=int(c1.replace('0',\"\"))\r\nif a2+b2==c2:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "a=int(input())\r\nb=int(input())\r\nst,st1=int(str(a).replace('0','')),int(str(b).replace('0',''))\r\nsumma=int(str(a+b).replace('0',''))\r\nif summa==st+st1:\r\n print('YES')\r\nelse: print('NO')\r\n", "def lifeWithoutZeros(a ,b):\r\n if int((str(a).replace(\"0\", \"\"))) + int((str(b).replace(\"0\", \"\"))) == int((str(a + b).replace(\"0\", \"\"))):\r\n return \"YES\"\r\n else:\r\n return \"NO\"\r\n\r\n\r\na = int(input())\r\nb = int(input())\r\nprint(lifeWithoutZeros(a, b))", "a = input()\nb = input()\nc = int(a) + int(b)\n\n\ndef noZero(s):\n noZero_s = \"\"\n for i in range(len(s)):\n if s[i] != '0':\n noZero_s += s[i]\n return noZero_s\n\nnoZero_a = int(noZero(a))\nnoZero_b = int(noZero(b))\nnoZero_c = int(noZero(str(c)))\n\nif noZero_a + noZero_b == noZero_c:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n\n\n\n\n", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nres_a = \"\".join([i for i in str(a) if i != \"0\"])\r\nres_b = \"\".join([i for i in str(b) if i != \"0\"])\r\nres_c = \"\".join([i for i in str(c) if i != \"0\"])\r\nif int(res_a) + int(res_b) == int(res_c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "ip1 = input()\r\nip2 = input()\r\n\r\nip3 = str(int(ip1) + int(ip2)).replace('0', '')\r\n\r\nip4 = str(int(ip1.replace('0', '')) + int(ip2.replace('0', '')))\r\n\r\nprint(\"YES\" if ip3 == ip4 else \"NO\")\r\n", "def op(x):\n x = str(x)\n s = ''\n for i in range(len(x)):\n if x[i] != '0':\n s += x[i]\n return int(s)\nn = int(input())\nm = int(input())\n#n, m = map(int, input().split())\n#s = input()\n#c = list(map(int, input().split()))\nl = m + n\nif op(n) + op(m) == op(l):\n print('YES')\nelse:\n print('NO')\n\n ", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\n\r\nd=list(str(a))\r\ne=list(str(b))\r\nf=list(str(c))\r\nfor item in d:\r\n for i in range (d.count('0')):\r\n d.remove('0')\r\n\r\nfor item in e:\r\n for l in range (e.count('0')):\r\n e.remove('0')\r\n\r\nfor item in f:\r\n for k in range (f.count('0')):\r\n f.remove('0') \r\n\r\nd=int(\"\".join(d))\r\ne=int(\"\".join(e))\r\nf=int(\"\".join(f))\r\n\r\nif d+e==f:\r\n print(\"YES\")\r\n\r\nelse:\r\n print(\"NO\") \r\n\r\n\r\n", "# nhập 2 số a, b\r\n# c = a+b\r\n# sau đó tạo hàm removeZero looping i through a number (a or b) len(str(a))\r\n# for i in range(len(str(a)))\r\n# digit = a%10\r\n# nếu digit!=0, newnumber+= digit*10**i\r\n# a//=10\r\n# print \"YES\" if removeZero(a)+removeZero(b)==c else print(\"NO\") \r\ndef removeZero(number):\r\n newnumber=0\r\n countNon0=0\r\n numlen=len(str(number))\r\n for i in range(numlen):\r\n digit = number%10\r\n if digit!=0:\r\n newnumber+=digit*(10**countNon0)\r\n countNon0+=1\r\n number//=10\r\n return newnumber\r\na=int(input())\r\nb=int(input())\r\nc=a+b\r\nprint(\"YES\") if removeZero(a)+removeZero(b)==removeZero(c) else print(\"NO\")\r\n", "num1 = input()\nnum2 = input()\nsum = int(num1) + int(num2)\nsum = str(sum)\n\nnew1 = ''\nfor i in range(len(num1)):\n\tif num1[i] != '0':\n\t\tnew1 += num1[i]\nnew2 = ''\nfor i in range(len(num2)):\n\tif num2[i] != '0':\n\t\tnew2 += num2[i]\nsumNew = ''\nfor i in range(len(sum)):\n\tif sum[i] != '0':\n\t\tsumNew += sum[i]\n\nif int(new1) + int(new2) == int(sumNew):\n\tprint('YES')\nelse: print('NO')\n\t \t\t\t \t \t\t\t \t \t \t\t\t\t", "a,b = int(input()),int(input())\r\n\r\nc = a + b\r\n\r\na = str(a)\r\nnewA = ''\r\n\r\nfor char in a:\r\n if char!='0':\r\n newA+=char\r\n \r\nnewA = int(newA)\r\n\r\nb = str(b)\r\nnewB = ''\r\n\r\nfor char in b:\r\n if char!='0':\r\n newB+=char\r\n \r\nnewB = int(newB)\r\n\r\nc = str(c)\r\nnewC = ''\r\n\r\nfor char in c:\r\n if char!='0':\r\n newC+=char\r\n \r\nnewC = int(newC)\r\n\r\nif newA+newB == newC:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\nb=input()\ns=int(a)+int(b)\ns=list(str(s))\na=list(a)\nb=list(b)\ns1=[]\nfor i in s:\n if i!='0':\n s1.append(i)\n\ns2=[]\nfor j in a:\n if j!='0':\n s2.append(j)\n\ns3=[]\nfor k in b:\n if k!='0':\n s3.append(k)\n\na1=''\nfor t in s1:\n a1+=t\na2=''\na3=''\nfor t1 in s2:\n a2+=t1\nfor t2 in s3:\n a3+=t2\na1=int(a1)\na2=int(a2)\na3=int(a3)\n\nif a2+a3==a1:\n print('YES')\nelse:\n print('NO')\n\n", "a = int(input())\r\nb = int(input())\r\nc = a+b\r\naCheck = int(str(a).replace(\"0\", \"\"))\r\nbCheck = int(str(b).replace(\"0\", \"\"))\r\ncCheck = int(str(c).replace(\"0\", \"\"))\r\nif aCheck+bCheck == cCheck:\r\n print('YES')\r\nelse:\r\n print(\"NO\")", "I=lambda x:int(str(x).replace('0',''))\r\na=int(input())\r\nb=int(input())\r\nprint(\"YNEOS\"[I(a)+I(b)!=I(a+b)::2])", "a = input()\r\nb = input()\r\nx = int(a)\r\ny = int(b)\r\nc = str(x+y)\r\nd = a.replace(\"0\",\"\")\r\ne = b.replace(\"0\",\"\")\r\nf = c.replace(\"0\",\"\")\r\nif (int(f) == (int(d)+int(e))):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a, b = input(), input()\r\ninit_sum = str(int(a) + int(b))\r\na, b = int(a.replace(\"0\", \"\")), int(b.replace(\"0\", \"\"))\r\nfinal_sum = int(init_sum.replace(\"0\", \"\"))\r\nprint(\"YES\" if a + b == final_sum else \"NO\")\r\n", "def delete0(x):\r\n i = 0\r\n soMoi = 0\r\n while x > 0:\r\n m = x % 10\r\n x = x // 10\r\n if m != 0:\r\n soMoi = soMoi + m*(10**i)\r\n i += 1\r\n return soMoi \r\na = int(input())\r\nb = int(input())\r\nif delete0(a) + delete0(b) == delete0(a+b):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def removeZero(num):\r\n return int(str(num).replace('0',''))\r\n \r\na = int(input())\r\nb = int(input())\r\n\r\nif removeZero(a + b) == removeZero(a) + removeZero(b):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\nb = input()\r\nc = int(a) + int(b)\r\ncc = str(c).replace('0', '')\r\na2 = a.replace('0', '')\r\nb2 = b.replace('0', '')\r\nc2 = int(a2) + int(b2)\r\nif cc == str(c2):\r\n print('YES')\r\nelse:\r\n print('NO')", "a1=input()\na2=int(a1.replace('0',''))\na1=int(a1)\nb1=input()\nb2=int(b1.replace('0',''))\nb1=int(b1)\n\nc1=int(str(a1+b1).replace('0',''))\nc2=a2+b2\nprint(\"YES\" if c1==c2 else \"NO\")\n", "a = str(input())\r\nb = str(input())\r\nres = int(a)+int(b)\r\nc = str(res)\r\nA = list()\r\nB = list()\r\nC = list()\r\nfor i in a:\r\n A.append(i)\r\nfor i in b:\r\n B.append(i)\r\nfor i in c:\r\n C.append(i)\r\naa = A.count('0')\r\nbb = B.count('0')\r\ncc = C.count('0')\r\nfor i in range(aa):\r\n A.remove('0')\r\nfor i in range(bb):\r\n B.remove('0')\r\nfor i in range(cc):\r\n C.remove('0')\r\na = \"\".join(A)\r\nb = \"\".join(B)\r\nc = \"\".join(C)\r\nx = int(a)\r\ny = int(b)\r\n\r\n\r\nif int(c) == x+y : print(\"YES\")\r\nelse: print(\"NO\")\r\n", "n = int(input())\r\na = int(input())\r\nc = n + a\r\nfd = 0\r\nf = 1\r\nwhile n > 0:\r\n sq = n % 10\r\n if sq != 0:\r\n fd = sq * f + fd\r\n f *= 10\r\n n //= 10\r\nsw = 0\r\nh = 1\r\nwhile a > 0:\r\n sh = a % 10\r\n if sh != 0:\r\n sw = sh * h + sw\r\n h *= 10\r\n a //= 10\r\nse = 0\r\nk = 1\r\nwhile c > 0:\r\n sf = c % 10\r\n if sf != 0:\r\n se = sf * k + se\r\n k *= 10\r\n c //= 10\r\nif fd + sw == se:\r\n print('YES')\r\nelse:\r\n print('NO')", "def rev(n):\r\n\tans=0\r\n\twhile n>0:\r\n\t\trem=(n%10)\r\n\t\tans=(ans*10)+rem\r\n\t\tn//=10\r\n\treturn ans\r\n\r\ndef remove_zeros(n):\r\n\tans=0\r\n\twhile n>0:\r\n\t\trem=(n%10)\r\n\t\tif rem!=0:\r\n\t\t\tans=(ans*10)+rem\r\n\t\tn//=10\r\n\tans=rev(ans)\r\n\treturn ans\r\n\r\na=int(input())\r\nb=int(input())\r\nc=a+b\r\na=remove_zeros(a)\r\nb=remove_zeros(b)\r\nc=remove_zeros(c)\r\nif a+b==c:\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "a = input()\r\nb = input()\r\nans1 = str(int(a) + int(b)).replace(\"0\", \"\")\r\nans2 = int(str(a).replace(\"0\", \"\")) + int(str(b).replace(\"0\", \"\"))\r\nprint(\"YES\") if ans1 == str(ans2) else print(\"NO\")\r\n", "m = input()\nn = input()\n\n\ndef convert_num(w):\n num = ''\n lst = [i for i in w if i != '0']\n for i in lst:\n num += i\n return int(num)\n\nnum1 = convert_num(m)\nnum2 = convert_num(n)\n\nssum = int(m) + int(n)\n\nif num1 + num2 == convert_num(str(ssum)):\n print('YES')\nelse:\n print('NO')", "a = int(input(''))\r\nb = int(input(''))\r\nc1 = a + b\r\nc1 = str(c1)\r\nc1 = c1.replace('0','')\r\nc1 = int(c1)\r\n\r\na = str(a)\r\nb = str(b)\r\n\r\na = a.replace('0','')\r\nb = b.replace('0','')\r\na = int(a)\r\nb = int(b)\r\n\r\nc2 = a + b\r\n\r\n\r\nif c1 == c2 :\r\n print('YES')\r\nelse:\r\n print('NO')\r\n\r\n\r\n", "a=int(input())\nb=int(input())\n\nc1=a+b\n\nif int(str(c1).replace(\"0\", \"\")) == int(str(a).replace(\"0\", \"\")) + int(str(b).replace(\"0\", \"\")):\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\n\n", "remove_zeros = lambda x: int(x.replace('0', ''))\r\n\r\na, b = input(), input()\r\n\r\nprint('YES' if remove_zeros(a) + remove_zeros(b) ==\r\n remove_zeros(str(int(a) + int(b))) else 'NO')", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\na1,b1,c1=str(a),str(b),str(c)\r\na2,b2,c2=\"\",\"\",\"\"\r\nfor i in a1:\r\n if i!='0':\r\n a2+=i\r\nfor i in b1:\r\n if i!='0':\r\n b2+=i\r\nfor i in c1:\r\n if i!='0':\r\n c2+=i\r\nif int(a2)+int(b2)==int(c2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def fun(q):\n\tsum=0\n\tarr =[]\n\twhile(q!=0):\n\t\tw = q%10\n\t\tif(w!=0):\n\t\t\tarr.append(w)\t\n\t\tq = q//10\n\tfor i in range(len(arr)):\n\t\tsum = sum +(10**i)*arr[i]\n\treturn sum\nm = int(input())\nn = int(input())\no = m+n\nif fun(m)+fun(n)==fun(o):\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\n", "a = int(input())\nb = int(input())\nc = a + b\n\ni_a = 1\nnumbera = 0\n\nwhile a > 0:\n if a % 10 != 0:\n numbera += a % 10 * i_a\n i_a *= 10\n a //= 10\n\ni_b = 1\nnumberb = 0\n\nwhile b > 0:\n if b % 10 != 0:\n numberb += b % 10 * i_b\n i_b *= 10\n b //= 10 \n\ni_c = 1\nnumberc = 0\n\nwhile c > 0:\n if c % 10 != 0:\n numberc += c % 10 * i_c\n i_c *= 10\n c //= 10\n\nif numbera + numberb != numberc:\n print('NO')\nelse:\n print('YES')\n", "def remove_zeroes(n):\r\n s = []\r\n while n != 0:\r\n d = n % 10\r\n if d != 0:\r\n s.append(d)\r\n n //= 10\r\n\r\n r = 0\r\n for i in range(len(s) - 1, -1, -1):\r\n r = 10 * r + s[i]\r\n return r\r\n\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n m = int(input())\r\n s = n + m\r\n\r\n if remove_zeroes(n) + remove_zeroes(m) == remove_zeroes(s):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n\r\n\r\n\r\n\r\n", "def removeZero (a):\r\n b = 0\r\n c = 1\r\n while (a > 0):\r\n if (a % 10 != 0):\r\n b = b + (a % 10) * c\r\n c *= 10\r\n a //= 10\r\n else:\r\n a //= 10\r\n return b\r\n\r\n\r\nx = int(input())\r\ny = int(input())\r\nif (removeZero(x) + removeZero(y) == removeZero(x + y)):\r\n print (\"YES\")\r\nelse:\r\n print (\"NO\")", "a = input()\r\nb = input()\r\n\r\nc = int(a) + int(b)\r\nc = str(c).replace(\"0\", \"\")\r\n\r\na0 = a.replace(\"0\", \"\")\r\nb0 = b.replace(\"0\", \"\")\r\nc0 = int(a0) + int(b0)\r\n\r\n# print(int(c), c0)\r\n\r\nif int(c) == c0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "x = int(input())\r\ny = int(input())\r\nz = x + y\r\nr = 1\r\nk = 0\r\nwhile x > 0:\r\n l = x % 10\r\n if l != 0:\r\n x = x // 10\r\n k = k + r * l\r\n r = r * 10\r\n if l == 0:\r\n x = x // 10\r\nr = 1\r\nk1 = 0\r\nl = 0\r\nwhile y > 0:\r\n l = y % 10\r\n if l != 0:\r\n y = y // 10\r\n k1 = k1 + r * l\r\n r = r * 10\r\n if l == 0:\r\n y = y // 10\r\nr = 1\r\nk2 = 0\r\nl = 0\r\nwhile z > 0:\r\n l = z % 10\r\n if l != 0:\r\n z = z // 10\r\n k2 = k2 + r * l\r\n r = r * 10\r\n if l == 0:\r\n z = z // 10\r\nif k + k1 == k2:\r\n print('YES')\r\nelse:\r\n print('NO')", "def solve():\r\n n = int(input())\r\n x = int(input())\r\n # n = 105\r\n #x = 106\r\n c = n + x \r\n x = str(x)\r\n n = str(n)\r\n c = str(c)\r\n newn = ''\r\n newx = ''\r\n newc = ''\r\n for i in range(len(str(n))):\r\n if n[i] != '0':\r\n newn += n[i]\r\n \r\n for i in range(len(str(x))):\r\n if x[i] != '0':\r\n newx += x[i]\r\n for i in range(len(str(c))):\r\n if c[i] != '0':\r\n newc += c[i]\r\n \r\n if (int(newn) + int(newx)) == int(newc):\r\n print('YES')\r\n return \r\n print('NO')\r\nsolve()", "a = input()\r\nb = input()\r\n\r\nc = int(a) + int(b)\r\n\r\nc = str(c)\r\n\r\na_ = [i for i in a if i!='0']\r\nb_ = [i for i in b if i!='0']\r\nc_ = [i for i in c if i!='0']\r\n\r\na1 = \"\"\r\nfor i in a_:\r\n a1 += i\r\n\r\nb1 = \"\"\r\nfor i in b_:\r\n b1 += i\r\n\r\nc1 = \"\"\r\nfor i in c_:\r\n c1 += i\r\n\r\n\r\n\r\nb1 = int(b1)\r\na1 = int(a1)\r\nc1 = int(c1)\r\n\r\nif a1+b1==c1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a, b = input(), input() \r\nc = str(int(a) + int(b))\r\nprint(\"YES\" if int(''.join([x for x in a if x != \"0\"])) + int(''.join([x for x in b if x != \"0\"])) == int(''.join([x for x in c if x != \"0\"])) else \"NO\")", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\na, b, c = str(a), str(b), str(c)\r\n\r\na = a.replace('0', '')\r\nb = b.replace('0', '')\r\nc = c.replace('0', '')\r\n\r\nif int(a) + int(b) == int(c):\r\n print('YES')\r\nelse:\r\n print('NO')", "def possible():\r\n a = input()\r\n b = input()\r\n c = int(a) + int(b)\r\n a_none = a.translate(str.maketrans('', '', '0'))\r\n b_none = b.translate(str.maketrans('', '', '0'))\r\n two_add = int(a_none) + int(b_none)\r\n if str(two_add) == str(c).translate(str.maketrans('', '', '0')):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\npossible()", "n = int(input())\r\nx = int(input())\r\na = \"\"\r\nb = \"\"\r\nc = \"\"\r\nd = \"\"\r\ne = \"\"\r\nf = \"\"\r\nfor i in str(n):\r\n if i!=\"0\":\r\n a+=i\r\nfor i in str(x):\r\n if i!=\"0\":\r\n b+=i\r\nf = n+x\r\nfor i in str(f):\r\n if i!=\"0\":\r\n c+=i\r\nif (int(a) + int(b)) == int(c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "a,b=input(),input()\r\ntemp1=str(int(a)+int(b))\r\ntemp2=temp1.replace('0',\"\")\r\na,b=a.replace('0',\"\"),b.replace('0','')\r\nif temp2==str(int(a)+int(b)):print(\"YES\")\r\nelse:print(\"NO\")\r\n", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\nc1=str(c)\r\n\r\nx2=c1.split(\"0\")\r\nx=a.split(\"0\")\r\nx1=b.split(\"0\")\r\ns=\"\"\r\ns1=\"\"\r\ns2=\"\"\r\nfor i in x2:\r\n s2=s2+i\r\n\r\nfor i in x:\r\n s=s+i\r\nfor i in x1:\r\n s1=s1+i\r\ns3=int(s)+int(s1)\r\n\r\nif int(s2)==int(s3):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n", "a=(input())\r\nb=input()\r\nc=int(a)+int(b)\r\nc=str(c).replace(\"0\",\"\")\r\n#print(c)\r\n\r\nb=b.replace(\"0\",\"\")\r\na=a.replace(\"0\",\"\")\r\nd=int(a)+int(b)\r\nif d==int(c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n\r\n\r\n", "a, b = input(), input()\r\nif str(eval(a+\"+\"+b)).replace(\"0\", \"\") == str(eval(a.replace(\"0\", \"\")+\"+\"+b.replace(\"0\", \"\"))):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=list(input())\r\nb=list(input())\r\nc=str(int(\"\".join(elem for elem in a))+int(\"\".join(elem for elem in b)))\r\na=\"\".join(elem for elem in list(filter(('0').__ne__, a)))\r\nb=\"\".join(elem for elem in list(filter(('0').__ne__, b)))\r\nc=\"\".join(elem for elem in list(filter(('0').__ne__, c)))\r\nif int(a)+int(b)==int(c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\ns = a + b\r\na1 = str(a)\r\nb1 = str(b)\r\ns1 = str(s)\r\na2 = \"\"\r\nb2 = \"\"\r\ns2 = \"\"\r\nfor i in a1:\r\n if i != '0':\r\n a2 += i\r\nfor i in b1:\r\n if i != '0':\r\n b2 += i\r\nfor i in s1:\r\n if i != '0':\r\n s2 += i\r\n\r\nif int(a2) + int(b2) == int(s2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def rem_zeros(n):\n return int(''.join(filter(lambda x: x != '0', str(n))))\n\na = int(input())\nb = int(input())\n\nif rem_zeros(a) + rem_zeros(b) == rem_zeros(a + b):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "a = int(input())\nb = int(input())\nc = str(a + b)\nc = c.replace(\"0\", \"\")\na = str(a)\na = a.replace(\"0\", \"\")\nb = str(b)\nb = b.replace(\"0\", '')\nif int(c) == int(a) + int(b):\n print(\"YES\")\nelse :\n print(\"NO\")", "a=str(input())\r\nb=str(input())\r\nc=list(str(int(a)+int(b)))\r\na=list(a)\r\nwhile '0' in a:\r\n a.remove('0')\r\na=''.join(a)\r\nb=list(b)\r\nwhile '0' in b:\r\n b.remove('0')\r\nb=''.join(b)\r\nd=int(a)+int(b)\r\n#print(c,d)\r\nwhile '0' in c:\r\n c.remove('0')\r\nc=''.join(c)\r\nc=int(c)\r\nif(c==d):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "# def symnum(n):\ndef demtongslchuso(n):\n count = 0\n while n > 0:\n x = n // 10\n count += 1\n n = x\n return count\n\ndef eliminatezero(x):\n a = 10 ** (demtongslchuso(x) - 1)\n nozero_x = 0\n while x > 0:\n digit = x // a\n nozero_x = int(nozero_x * 10 + digit)\n x = (x % a)\n a = 10 ** (demtongslchuso(x) - 1)\n if x == 0:\n break\n return nozero_x\n\n\na = int(input())\nb = int(input())\nc = a + b\nnozero_a = eliminatezero(a)\nnozero_b = eliminatezero(b)\nnozero_c = eliminatezero(c)\nif nozero_a + nozero_b == nozero_c:\n print('YES')\nelse:\n print('NO')\n\n\n\n\n\n", "x = input()\r\ny = input()\r\nz = int(x) + int(y)\r\nnozero1 = x.replace(\"0\", \"\")\r\nnozero3 = y.replace(\"0\" , \"\")\r\nno = str(z).replace(\"0\" , \"\") \r\nprint(\"YES\"if int(no) == int(nozero1) +int(nozero3) else\"NO\")", "a=int(input())\nb=int(input())\nc=a+b\nA=str(a)\nB=str(b)\nC=str(c)\nA=A.replace('0','')\nB=B.replace('0','')\nC=C.replace('0','')\nx=int(A)\ny=int(B)\nz=int(C)\nif(x+y==z):\n print(\"YES\")\nelse:\n print(\"NO\")\n\n\t\t \t \t \t\t \t \t\t \t\t\t \t\t\t\t\t", "#!/usr/bin/env python\n# coding: utf-8\n\n# In[18]:\n\n\na=int(input())\nb=int(input())\nlast=0\n\ndef del_null(x):\n temp=0\n i=1\n while x>0:\n last=x%10\n if last!=0:\n temp+=i*last\n i*=10\n x=x//10\n return temp\n\nif del_null(a+b)==del_null(a)+del_null(b):\n print('YES')\nelse:\n print('NO')\n\n\n# In[ ]:\n\n\n\n\n", "def noZero(n):\r\n m = str(n)\r\n ans = ''\r\n for i in m:\r\n if i != '0':\r\n ans += i\r\n if len(ans):\r\n return int(ans)\r\n return 0\r\na,b = int(input()),int(input())\r\nc = a + b\r\nd,e,f = [noZero(i) for i in [a,b,c]]\r\nprint('YES' if d + e == f else 'NO')", "a = int(input())\r\nb = int(input())\r\nc = a+b\r\nc = str(c)\r\noldC = \"\"\r\nfor x in c:\r\n if x!=\"0\":\r\n oldC+=x\r\na = str(a)\r\nb = str(b)\r\nnewA = \"\"\r\nnewB = \"\"\r\nfor x in a:\r\n if x!=\"0\":\r\n newA+=x\r\nfor x in b:\r\n if x!=\"0\":\r\n newB+=x\r\nnewC = int(newA)+int(newB)\r\nif int(oldC)==newC:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\nres = a + b\r\nmodify = lambda x: ''.join([c if c != '0' else '' for c in x])\r\na = int(modify(str(a)))\r\nb = int(modify(str(b)))\r\nres = int(modify(str(res)))\r\nprint(\"YES\" if a + b == res else \"NO\")", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\na1 = []\r\nb1 = []\r\nc1 = []\r\nwhile a != 0:\r\n last = a % 10\r\n if last == 0:\r\n a = a // 10\r\n continue\r\n a1.append(str(last))\r\n a = a//10\r\n\r\nwhile b != 0:\r\n lst = b % 10\r\n if lst == 0:\r\n b = b // 10\r\n continue\r\n b1.append(str(lst))\r\n b = b//10\r\n\r\nwhile c != 0:\r\n lt = c % 10\r\n if lt == 0:\r\n c = c // 10\r\n continue\r\n c1.append(str(lt))\r\n c = c//10\r\n\r\n\r\na1.reverse()\r\nb1.reverse()\r\nc1.reverse()\r\n\r\na1 = ''.join(a1)\r\nb1 = ''.join(b1)\r\nc1 = ''.join(c1)\r\nprint()\r\n\r\n\r\n\r\n\r\n\r\nif int(a1) + int(b1) == int(c1):\r\n print('YES')\r\nelse:\r\n print('NO')", "a = input()\r\nb = input()\r\nc = str(int(a) + int(b)).replace('0', '')\r\nc_1 = int(a.replace('0','')) + int(b.replace('0', ''))\r\n \r\nif c_1 == int(c) :\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "a = int(input())\r\nb = int(input())\r\n\r\nc = a + b\r\n\r\nstr_a = str(a)\r\nstr_b = str(b)\r\nstr_c = str(c)\r\n\r\nstr_a_no_zeros = str_a.replace(\"0\", \"\")\r\nstr_b_no_zeros = str_b.replace(\"0\", \"\")\r\nstr_c_no_zeros = str_c.replace(\"0\", \"\")\r\n\r\nint_a_no_zeros = int(str_a_no_zeros)\r\nint_b_no_zeros = int(str_b_no_zeros)\r\nint_c_no_zeros = int(str_c_no_zeros)\r\n\r\nconf1 = (int_a_no_zeros + int_b_no_zeros == int_c_no_zeros)\r\n\r\nif conf1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def f(m):\r\n a=0 \r\n for i in m:\r\n if i=='0':\r\n continue \r\n a=a*10+int(i)\r\n return a \r\na=input()\r\nb=input()\r\nprint(\"YES\") if f(a)+f(b)==f(str(int(a)+int(b))) else print(\"NO\")", "a = int(input())\r\nb = int(input())\r\nc = a+b\r\nast = str(a)\r\nbst = str(b)\r\ncst = str(c)\r\nastm = \"\"\r\nbstm = \"\"\r\ncstm = \"\"\r\nfor i in range(len(ast)):\r\n if ast[i] != \"0\":\r\n astm += ast[i]\r\nfor i in range(len(bst)):\r\n if bst[i] != \"0\":\r\n bstm += bst[i]\r\nfor i in range(len(cst)):\r\n if cst[i] != \"0\":\r\n cstm += cst[i]\r\nam = int(astm)\r\nbm = int(bstm)\r\ncm = int(cstm)\r\n\r\nif am+bm == cm:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "num1 = input()\r\nnum2 = input()\r\nnum3 = int(num1) + int(num2)\r\n\r\nnum1_no = num1.replace(\"0\", \"\")\r\nnum2_no = num2.replace(\"0\", \"\")\r\nnum3_no = (str(num3)).replace(\"0\", \"\")\r\n\r\nif int(num1_no) + int(num2_no) == int(num3_no):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = input()\r\nb = input()\r\nc = int(a)+int(b)\r\nc = str(c)\r\na1 = a.replace('0', '')\r\nb1 = b.replace('0', '')\r\nc1 = c.replace('0', '')\r\nif int(a1)+int(b1) == int(c1):\r\n print('YES')\r\nelse:\r\n print('NO')", "def solves():\r\n a=int(input())\r\n b=int(input())\r\n c=a+b\r\n c=str(c)\r\n a=str(a)\r\n b=str(b)\r\n a=a.replace(\"0\",\"\")\r\n b=b.replace(\"0\",\"\")\r\n c=c.replace(\"0\",\"\")\r\n if int(a)+int(b)==int(c):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\nfor _ in range(1):\r\n solves()\r\n", "q = str(int(input()))\r\nq1 = str(int(input()))\r\nw = int(q.replace('0', ''))\r\nw1 = int(q1.replace('0', ''))\r\nq=int(q)\r\nq1=int(q1)\r\nww1=w+w1\r\nqq1=q+q1\r\nqq1=str(qq1)\r\nqq1=int(qq1.replace('0', ''))\r\nif ww1==qq1:\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')\r\n", "a = input()\nb = input()\n\nc = int(a) + int(b)\n\nc = int(str(c).replace(\"0\", \"\"))\n\nd = a.replace(\"0\", \"\")\ne = b.replace(\"0\", \"\")\n\nf = int(d) + int(e)\n\nif c==f:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t\t \t \t \t\t \t\t \t\t\t\t \t \t\t \t \t\t", "\ndef issum(a,b):\n k1 = a+b\n k2 = ''\n k3 = ''\n k4 = ''\n for i in str(a):\n if i!='0':\n k2+=i\n\n for i in str(b):\n\n if i!='0':\n k3+=i\n\n for i in str(k1):\n\n if i!='0':\n k4+=i\n\n \n if int(k2) + int(k3) == int(k4):\n return True\n else:\n return False\n\na = int(input())\n\nb = int(input())\n\nz = issum(a,b)\n\nif z is True:\n print('YES')\nelse:\n print('NO')\n\n", "a=int(input())\r\nb=int(input())\r\ns=a+b\r\nsa=\"\"\r\nsb=\"\"\r\nst=\"\"\r\nfor x in str(a):\r\n if x!='0':sa+=x\r\nfor x in str(b):\r\n if x!='0':sb+=x\r\nfor x in str(s):\r\n if x!='0':st+=x\r\nif (int(sa)+int(sb)==int(st)):print(\"YES\")\r\nelse:print(\"NO\")", "num1 = input()\r\nnum2 = input()\r\nsum1 = str(int(num1)+int(num2))\r\nnum1 = list(num1)\r\nnum2 = list(num2)\r\nsum2 = list(sum1)\r\n\r\nnum1 = [ elem for elem in num1 if elem != '0']\r\nnum2 = [ elem for elem in num2 if elem != '0']\r\nsum2 = [ elem for elem in sum2 if elem != '0']\r\n \r\nif int(\"\".join(sum2)) == int(\"\".join(num1))+ int(\"\".join(num2)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "a=int(input())\r\nb=int(input())\r\nans=a+b\r\n_a=int(''.join(str(a).split('0')))\r\n_b=int(''.join(str(b).split('0')))\r\n_ans=int(''.join(str(ans).split('0')))\r\nif _a+_b==_ans:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\nc = a+b\r\na1 = \"\"\r\nb1 = \"\"\r\nc2 = \"\"\r\nfor i in str(a):\r\n if i != '0': a1+=i\r\n\r\nfor i in str(b):\r\n if i != '0': b1+=i\r\nfor i in str(c):\r\n if i != '0': c2+=i\r\n \r\n\r\nc1 = eval(a1) + eval(b1)\r\n\r\nif eval(c2) == c1:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n \r\n\r\n\r\n", "def remove_zeros(n):\r\n new_n = 0\r\n i = 1\r\n while n:\r\n remainder = n % 10\r\n n //= 10\r\n if not(remainder):\r\n continue\r\n new_n = new_n + (remainder * i)\r\n i *= 10\r\n return new_n\r\n\r\na = int(input())\r\nb = int(input())\r\nc = a + b\r\n\r\nnew_a = remove_zeros(a)\r\nnew_b = remove_zeros(b)\r\nnew_c = remove_zeros(c)\r\n\r\nif new_a + new_b == new_c:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def f(x):\r\n x = str(x)\r\n a = str()\r\n for i in x:\r\n if i != '0':\r\n a += i\r\n return int(a)\r\na, b = int(input()), int(input())\r\nres = a+b\r\nif f(a) + f(b) == f(res):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "I=lambda x:int(str(x).replace('0',''))\r\na=int(input())\r\nb=int(input())\r\nif I(a)+I(b)!=I(a+b):\r\n print('NO')\r\nelse:\r\n print('YES')", "a= int(input())\nb= int(input())\nc= a+b\nc=str(c).replace('0', \"\")\na= str(a).replace('0',\"\")\nb= str(b).replace('0',\"\")\nna=int(a)\nnb= int(b)\nnc= na+nb\nif str(nc)== c :\n print(\"YES\")\nelse:\n print(\"NO\")\n", "# your code goes here\r\nx = int(input())\r\ny = int(input())\r\n\r\nz = x+y\r\nn = str(z).replace(\"0\",\"\")\r\nn = int(n)\r\n\r\na = str(x).replace(\"0\",\"\")\r\nb = str(y).replace(\"0\",\"\")\r\nm = int(a)+int(b)\r\nif n==m:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "a=input()\r\nb=input()\r\nc = str(int(a)+int(b))\r\nint_a,int_b,int_c = 0,0,0\r\nfor char in a:\r\n if char != \"0\":\r\n int_a = int_a*10 + int(char)\r\nfor char in b:\r\n if char != \"0\":\r\n int_b = int_b*10 + int(char)\r\nfor char in c:\r\n if char != \"0\":\r\n int_c = int_c*10 + int(char)\r\nif int_a+int_b == int_c:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def del_zero(s):\r\n for i in range(len(s)):\r\n if s[i] == \"0\":\r\n s_new = s.replace(\"0\", \"\");\r\n return s_new;\r\n return s;\r\ns1 = input();\r\ns2 = input();\r\nx = int(s2) + int(s1);\r\nx = str(x);\r\n\r\nif int(del_zero(x)) == int(del_zero(s1)) + int(del_zero(s2)):\r\n print(\"YES\");\r\nelse:\r\n print(\"NO\"); ", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\nl1=str(a)\r\nl2=str(b)\r\nl3=str(c)\r\ns=\"\"\r\ns1=\"\"\r\ns2=\"\"\r\nfor i in range(len(str(a))):\r\n if(l1[i]!='0'):\r\n s=s+l1[i]\r\nfor i in range(len(str(b))):\r\n if(l2[i]!='0'):\r\n s1=s1+l2[i]\r\nfor i in range(len(str(c))):\r\n if(l3[i]!='0'):\r\n s2=s2+l3[i]\r\ns=int(s)\r\ns1=int(s1)\r\ns2=int(s2)\r\nif((s+s1)==s2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def solve(var):\n ans = ''\n for i in var:\n if i != '0': ans += i\n return ans\n \n#----main----#\na, b = input(), input()\ns = str(int(a) + int(b))\nnew_a, new_b, sum = solve(a), solve(b), solve(s)\nnew_sum = str(int(new_a) + int(new_b))\nif sum == new_sum: print(\"YES\")\nelse: print(\"NO\")\n \t \t\t \t\t \t\t \t \t\t \t \t \t\t", "from math import ceil\n\na = int(input())\nb = int(input())\nc = a + b\n\na = \"\".join(str(a).split('0')).strip()\nb = \"\".join(str(b).split('0')).strip()\nc = \"\".join(str(c).split('0')).strip()\n\nif int(a) + int(b) == int(c):\n print(\"YES\")\nelse:\n print(\"NO\")", "a1 = input()\r\nb1 = input()\r\nc1 = int(a1)+int(b1)\r\nc1 = \"\".join([i for i in list(str(c1)) if i!=\"0\"])\r\n\r\na2 = \"\".join([i for i in list(a1) if i!=\"0\"])\r\nb2 = \"\".join([i for i in list(b1) if i!=\"0\"])\r\nc2 = int(a2)+int(b2)\r\n#c2 = \"\".join([i for i in list(str(c2)) if i!=\"0\"])\r\n\r\nif(c1==str(c2)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "a = input()\nb = input()\nans1 = str(int(a)+int(b))\nans2=int(a.replace('0',''))+int(b.replace('0',''))\nif ans1.replace('0','')==str(ans2):\n print('YES')\nelse:\n print('NO')", "a = int(input())\r\nb = int(input())\r\nc = a+b\r\na = str(a)\r\na = a.replace('0',\"\")\r\nb = str(b)\r\nb = b.replace(\"0\",\"\")\r\nd = str(c)\r\nd = d.replace(\"0\",\"\")\r\ne = int(a)+int(b)\r\nif e == int(d):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\nb = input()\r\n\r\nsum = int(a) + int(b)\r\n\r\na = a.replace('0', '')\r\nb = b.replace('0', '')\r\n\r\nsum2 = str(sum)\r\nsum2 = sum2.replace('0', '')\r\nsum2 = int(sum2)\r\n\r\nactualSum2 = int(a) + int(b)\r\n\r\nif(actualSum2 == sum2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\nc=str(c)\r\nc=c.replace(\"0\",\"\")\r\nc=int(c)\r\na=a.replace(\"0\",\"\")\r\nb=b.replace(\"0\",\"\")\r\nfaltu=int(int(a)+int(b))\r\nif faltu==c:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\r\n# print(faltu,c)", "a = int(input())\r\nb = int(input())\r\nc = a+b\r\n\r\nx = str(a)\r\n\r\ny = str(b)\r\n\r\nz = str(c)\r\n\r\n\r\nif(int(x.replace('0',''))+int(y.replace('0',''))==int(z.replace('0',''))):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "a = int(input())\r\nb = int(input())\r\n\r\n\r\ndef reverseWithout0(x):\r\n new_num = 0\r\n while (x != 0):\r\n if (x % 10 != 0):\r\n new_num = new_num*10+x % 10\r\n x //= 10\r\n return new_num\r\n\r\n\r\nc = a+b\r\na = reverseWithout0(reverseWithout0(a))\r\nb = reverseWithout0(reverseWithout0(b))\r\nc = reverseWithout0(reverseWithout0(c))\r\n\r\nif (a+b == c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "m=input()\r\nn=input()\r\nif int(m.replace('0', '')) + int(n.replace('0', '')) == int(str(int(m) + int(n)).replace('0', '')):\r\n print('YES')\r\nelse:\r\n print('NO')", "x=input()\r\ny=input()\r\n\r\na=int(x)+int(y)\r\n\r\ndef zeroremov(g):\r\n g0=str(g)\r\n g1=\"\"\r\n for i in g0:\r\n if (i!=\"0\"):\r\n g1+=i\r\n return(int(g1))\r\n\r\nif (zeroremov(a)==zeroremov(x)+zeroremov(y)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\nc=str(c)\r\nc=c.replace('0',\"\")\r\nc=int(c)\r\na=str(a)\r\nd=a.replace('0',\"\")\r\na1=int(d)\r\nb=str(b)\r\ne=b.replace('0',\"\")\r\nb1=int(e)\r\nc1=a1+b1\r\nif(c==c1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n ", "if __name__ == '__main__':\r\n a = str(input())\r\n b = str(input())\r\n x = a.replace('0', '')\r\n y = b.replace('0', '')\r\n z = str(int(a) + int(b)).replace('0', '')\r\n if int(x) + int(y) == int(z):\r\n print('YES')\r\n else:\r\n print('NO')\r\n", "a = input()\nb = input()\nprint(int(a.replace(\"0\", \"\")) + int(b.replace(\"0\", \"\")) == int(str(int(a) + int(b)).replace(\"0\", \"\")) and \"YES\" or \"NO\")", "import math\r\nimport string\r\n\r\ndef f(x):\r\n\treturn int(str(x).replace('0', ''))\r\n\r\ndef main():\r\n\ta = int(input())\r\n\tb = int(input())\r\n\tc = a + b\r\n\tprint('YES' if f(a) + f(b) == f(c) else 'NO')\r\n\r\nif __name__ == '__main__':\r\n\tmain()", "def remove0(s):\r\n res = \"\"\r\n for ch in s:\r\n if ch != \"0\":\r\n res += ch\r\n return res\r\nif __name__ == '__main__':\r\n a = int(input())\r\n b = int(input())\r\n c = a + b\r\n newA, newB, newC = remove0(str(a)), remove0(str(b)), remove0(str(c))\r\n if int(newA) + int(newB) == int(newC):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\n\r\ndef remove_zero(a):\r\n return str(a).replace('0','')\r\n\r\nc = a + b\r\nremove_a = remove_zero(a)\r\nremove_b = remove_zero(b)\r\nremove_c = remove_zero(c)\r\n\r\nif (int(remove_a) + int(remove_b)) == int(remove_c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def nil_deleter(number: str):\r\n newnum = ''\r\n for num in number:\r\n if num != '0':\r\n newnum += num\r\n return newnum\r\ndef main():\r\n num1 = input()\r\n num2 = input()\r\n answer = int(num1) + int(num2)\r\n if int(nil_deleter(str(answer))) == int(nil_deleter(num1)) + int(nil_deleter(num2)):\r\n print('YES')\r\n else:\r\n print('NO')\r\nmain()", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\ns_a=str(a)\r\ns_b=str(b)\r\ns_c=str(c)\r\ns_a=s_a.replace(\"0\" , \"\")\r\ns_b=s_b.replace(\"0\" , \"\")\r\ns_c=s_c.replace(\"0\" , \"\")\r\ns_a= int(s_a)\r\ns_c = int(s_c)\r\ns_b = int(s_b)\r\nif s_a+s_b == s_c:\r\n print(\"YES\")\r\nelse:\r\n print (\"NO\")\r\n", "a, b = input(), input()\r\nprint('YES' if str(int(a) + int(b)).replace('0', '') == str(int(a.replace('0', '')) + int(b.replace('0', ''))) else 'NO')\r\n", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nnumbers = [a, b, c]\r\nnew_numbers = []\r\n\r\nfor n in numbers:\r\n new_number = 0\r\n r = 1\r\n while n > 0:\r\n last_digit = n % 10\r\n if last_digit != 0:\r\n new_number = last_digit*r + new_number\r\n r *= 10\r\n n //= 10\r\n new_numbers.append(new_number)\r\n\r\nif new_numbers[0] + new_numbers[1] == new_numbers[2]:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n\r\n", "n = int(input())\r\nm = int(input())\r\nc = n + m;n = str(n)\r\nm = str(m);c = str(c)\r\nn = int(n.replace('0', \"\"))\r\nm = int(m.replace('0', \"\"))\r\nc=int(c.replace(\"0\",\"\"))\r\nif n + m == c:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "import sys\r\nimport os\r\nfrom collections import Counter\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 sys.stderr = open(\"error.txt\",\"w\")\r\n\r\ninput = lambda: sys.stdin.readline()\r\n\r\nx = input()[:-1]\r\ny = input()[:-1]\r\nz = int(x) + int(y)\r\nnozero1 = x.split(\"0\")\r\nnozero2 = \"\"\r\nfor i in nozero1:nozero2 += i \r\nnozero3 = y.split(\"0\")\r\nnozero4 = \"\"\r\nfor i in nozero3:nozero4 += i \r\nno = str(z).split(\"0\")\r\nno4 = \"\"\r\nfor i in no:no4 += i \r\nprint(\"YES\"if int(no4) == int(nozero4) +int( nozero2) else\"NO\")", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\na = int(str(a).replace('0',''))\r\nb = int(str(b).replace('0',''))\r\nc = int(str(c).replace('0',''))\r\nif c == a+b:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "a=str(input())\nb=str(input())\nr2=str(int(a)+int(b))\nx=\"\"\ny=\"\"\nfor i in a:\n if i !=\"0\":\n x+=i\nfor i in b:\n if i !=\"0\":\n y+=i\nr1=\"\"\nfor i in r2:\n if i !=\"0\":\n r1+=i\nif int(r1) == (int(x) + int(y)):\n print(\"YES\")\nelse:\n print(\"NO\")\n\t \t \t\t\t\t \t \t\t \t\t\t \t\t \t", "a = int(input())\r\nb = int(input())\r\n\r\nc = int(str(a + b).replace('0', ''))\r\na = int(str(a).replace('0', ''))\r\nb = int(str(b).replace('0', ''))\r\n\r\nprint('YES' if a+b == c else 'NO')\r\n", "n1=int(input())\r\nn2=int(input())\r\noldsum=n1+n2\r\n\r\nm1=str(n1)\r\nz1=\"\"\r\nfor i in m1:\r\n if i!=\"0\":\r\n z1+=i\r\n\r\nm2=str(n2)\r\nz2=\"\"\r\nfor i in m2:\r\n if i!=\"0\":\r\n z2+=i\r\n\r\nm3=str(oldsum)\r\nz3=\"\"\r\nfor i in m3:\r\n if i!=\"0\":\r\n z3+=i\r\n\r\nif int(z1)+int(z2)==int(z3):\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\")", "a = input()\nb = input()\nc = str(int(a) + int(b))\na0 = int(a.replace(\"0\", \"\"))\nb0 = int(b.replace(\"0\", \"\"))\nc0 = int(c.replace(\"0\", \"\"))\nif (a0 + b0 == c0):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "a = int(input())\r\nb = int(input())\r\nc = a + b \r\nr = 1\r\nr1 = 1\r\nr2 = 1\r\nn = 0\r\nn1 = 0\r\nq = 0\r\nwhile a>0:\r\n last = a%10\r\n if last != 0:\r\n n = last*r +n\r\n r *= 10\r\n a//=10\r\nwhile b>0:\r\n last1 = b%10\r\n if last1 != 0:\r\n n1 = last1*r1 +n1\r\n r1 *= 10\r\n b//=10\r\nwhile c>0:\r\n l = c%10\r\n if l != 0:\r\n q = l*r2 + q\r\n r2 *=10\r\n c//=10\r\nn2 = n + n1\r\nif q == n2:\r\n print('YES')\r\nelse:\r\n print(\"NO\")", "a = input()\r\nb = input()\r\nc = a.replace(\"0\", \"\")\r\nd = b.replace(\"0\", \"\")\r\ns = int(str(int(a) + int(b)).replace(\"0\", \"\"))\r\nprint(\"YES\" if int(c) + int(d) == s else \"NO\")", "a = input()\nb = input()\nab = str(int(a) + int(b)).replace('0', '')\na = a.replace('0', '')\nb = b.replace('0', '')\nab1 = str(int(a) + int(b))\n\nif (ab == ab1):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\na1=b1=c1=0\r\nsa=str(a)\r\nsb=str(b)\r\nsc=str(c)\r\nfor i in sa:\r\n if i!='0':\r\n a1=a1*10+int(i)\r\nfor i in sb:\r\n if i!='0':\r\n b1=b1*10+int(i)\r\nfor i in sc:\r\n if i!='0':\r\n c1=c1*10+int(i)\r\nif a1+b1==c1:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "t = int(input())\r\nu =int(input())\r\np = t+u\r\nt = str(t)\r\nu = str(u)\r\np = str(p)\r\nt = int(t.replace('0', ''))\r\nu = int(u.replace('0',''))\r\np = int(p.replace('0',''))\r\nif p==t+u:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\r\n", "a=(input())\r\nb=(input())\r\nans=int(a)+int(b)\r\nf=a.split(\"0\")\r\ns=b.split(\"0\")\r\n# print(f)\r\n# print(s)\r\n\r\nans1=str(ans).split(\"0\")\r\n\r\nfirst=\"\"\r\nsec=\"\"\r\nfirst=\"\".join(f)\r\nsec=\"\".join(s)\r\nout=\"\".join(ans1)\r\n# print(first) \r\n# print(sec) \r\n# print(out) \r\n\r\nif int(first)+int(sec)==int(out):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") \r\n\r\n", "def removeZeros(n):\r\n count = 1\r\n res = 0\r\n while n > 0:\r\n tmp = n % 10\r\n n //= 10\r\n if tmp == 0:\r\n continue\r\n else:\r\n res += tmp * count\r\n count *= 10\r\n return res\r\n\r\ndef solve(a, b):\r\n c = a + b\r\n a = removeZeros(a)\r\n b = removeZeros(b)\r\n c = removeZeros(c)\r\n if a + b == c:\r\n return True\r\n return False\r\n\r\nx = int(input())\r\ny = int(input())\r\nres = solve(x, y)\r\nif res:\r\n print('YES')\r\nelse:\r\n print('NO')", "a = int(input())\nb = int(input())\nc = str(a + b).replace(\"0\",\"\")\nsa = str(a)\nsb = str(b)\nsa = sa.replace(\"0\",\"\")\nsb = sb.replace(\"0\",\"\")\nc2 = int(sa)+int(sb)\nc = int(c)\nc2 = int(c2)\nif c == c2:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t \t \t \t\t \t\t\t\t\t \t\t\t\t\t \t\t", "n1=int(input())\r\nn2=int(input())\r\nn3=int(str(n1).replace('0',''))+int(str(n2).replace('0',''))\r\nif(n3==int(str(n1+n2).replace('0',''))):\r\n\tprint('YES')\r\nelse: print('NO')", "m = int(input())\r\nn = int(input())\r\nsum_mn = str(m + n)\r\nsum_mn = sum_mn.replace('0', '')\r\nif (int(str(m).replace('0', '')) + int(str(n).replace('0', ''))) == int(sum_mn):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\na0 = a.replace('0', '')\r\na, a0 = int(a), int(a0)\r\nb = input()\r\nb0 = b.replace('0', '')\r\nb, b0 = int(b), int(b0)\r\nsm1 = int(str(a + b).replace('0', ''))\r\nif sm1 == a0 + b0:\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "# Wadea # \r\n\r\nn1 = str(input())\r\ns1 = len(n1)\r\nlst1 = []\r\nw1 = \"\"\r\nfor i in n1:\r\n lst1.append(i)\r\nfor m in n1:\r\n if m == \"0\":\r\n lst1.remove(\"0\")\r\n else:\r\n w1 += m\r\n\r\nn2 = str(input())\r\ns2 = len(n2)\r\nlst2 = []\r\nw2 = \"\"\r\nfor j in n2:\r\n lst2.append(j)\r\nfor n in n2:\r\n if n == \"0\":\r\n lst2.remove(\"0\")\r\n else:\r\n w2 += n\r\n \r\nw3 = int(w1) + int(w2)\r\n\r\nn3 = n1 = int(n1) + int(n2)\r\nn3 = str(n3)\r\nlst3 = list(n3)\r\nk1 = \"\"\r\nfor k in n3:\r\n if k == \"0\":\r\n lst3.remove(\"0\")\r\n else:\r\n k1 += k\r\n \r\nk1 = int(k1)\r\nif w3 == k1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = input();b = input()\r\nc = int(a)+int(b)\r\ng = str(c)\r\nd = g.replace('0','');e = a.replace('0','');f = b.replace('0','')\r\nd = int(d);e = int(e);f = int(f)\r\nif e+f == d:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=input()\r\nb=input()\r\nelement_to_remove = \"0\"\r\ninta=int(a)\r\nintb=int(b)\r\nintc=inta+intb\r\nc=str(intc)\r\n\r\n# Using the replace() method to remove the specified element\r\na = a.replace(element_to_remove, '')\r\nb=b.replace(element_to_remove,'')\r\nc=c.replace(element_to_remove,'')\r\nafc=int(c)\r\nintc=int(a)+int(b)\r\nif afc==intc:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n# print(a)\r\n# print(b)\r\n# # Output: Hell, Wrld!\r\n", "a=int(input())\nb=int(input())\ndef rem(n):\n\tk=str(n)\n\tnew=''\n\tfor i in k:\n\t\tif i!='0':\n\t\t\tnew+=i\n\treturn int(new)\nc=a+b\na=rem(a)\nb=rem(b)\nc=rem(c)\nif c==b+a:\n\tprint('YES')\nelse:\n\tprint('NO')\n\n", "def countDigit(x):\r\n digit = 0\r\n while x > 0:\r\n digit += 1\r\n x = x // 10\r\n return digit\r\n\r\n\r\ndef remove0(x):\r\n for i in range(1, countDigit(x)):\r\n if x % 10 == 0:\r\n x = x / 10\r\n if x % (10 ** i) == x % (10 ** (i - 1)):\r\n x = (x // 10 ** i) * 10 + (x % (10 ** (i - 1)))\r\n return x\r\n\r\n\r\na = int(input())\r\nb = int(input())\r\nc = a + b\r\nif remove0(a) + remove0(b) == remove0(c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "# import sys\r\n# sys.stdin = open('', 'r')\r\n# n = input()\r\n\r\nx = input()\r\ny = input()\r\nz = int(x) + int(y)\r\nz = str(z).replace(\"0\", \"\")\r\n\r\nx = x.replace(\"0\", \"\")\r\n\r\ny = y.replace(\"0\", \"\")\r\n\r\nif int(x) + int(y) == int(z):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\ndef rem_zero(no):\r\n num=0\r\n while no>0:\r\n r=no%10\r\n if r!=0:\r\n num=num*10 + r\r\n no=no//10\r\n numm=0\r\n while num>0:\r\n r=num%10\r\n numm=numm*10 + r\r\n num=num//10\r\n return numm\r\nif (rem_zero(a)+rem_zero(b))==rem_zero(c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "num_1 = int(input())\r\nnum_2 = int(input())\r\nanswer = num_1 + num_2\r\nanswer_z_less_1 = int(\"\".join(str(answer).split(\"0\")))\r\n\r\nnum_1_zless = int(\"\".join(str(num_1).split(\"0\")))\r\nnum_2_zless = int(\"\".join(str(num_2).split(\"0\")))\r\nanswer_z_less_2 = num_1_zless + num_2_zless\r\n\r\nif answer_z_less_1 == answer_z_less_2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def prime(x):\r\n y=\"\"\r\n for i in x:\r\n if i!=\"0\":\r\n y+=i\r\n return y\r\na=input()\r\nb=input()\r\nc=str(int(a)+int(b))\r\nap=prime(a)\r\nbp=prime(b)\r\ncp=prime(c)\r\nif int(ap)+int(bp)==int(cp):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "\na = list(str(input()))\nb = list(str(input()))\n\naInt = int(\"\".join(a))\nbInt = int(\"\".join(b))\n\ncInt = aInt + bInt\n\ncStr = list(str(cInt))\n\ni = 0\nwhile i < len(a):\n if a[i] == '0':\n a.pop(i)\n else:\n i += 1\n\ni = 0\nwhile i < len(b):\n if b[i] == '0':\n b.pop(i)\n else:\n i += 1\n\ni = 0\nwhile i < len(cStr):\n if cStr[i] == '0':\n cStr.pop(i)\n else:\n i += 1\n\n\nprint(\"YES\") if int(\"\".join(cStr)) == int(\"\".join(a)) + int(\"\".join(b)) else print(\"NO\")", "def DeleteZero(z):\r\n num = 0\r\n tempZ = z\r\n x = 0\r\n for i in range(0, 10):\r\n numZ = tempZ % 10\r\n tempZ = tempZ // 10\r\n if numZ == 0:\r\n pass\r\n else:\r\n x += numZ * 10 ** num\r\n num += 1\r\n return x\r\n\r\n\r\na = int(input())\r\nb = int(input())\r\n\r\nc = a + b\r\nx = DeleteZero(a)\r\ny = DeleteZero(b)\r\nsum = DeleteZero(c)\r\n\r\nd = x + y\r\n# print(sum)\r\n# print(d)\r\nif sum == d:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\ndef losezero(a):\r\n T=0\r\n Z=0\r\n while a!=0:\r\n if a%10!=0: \r\n T+=a%10*(10**Z)\r\n Z+=1\r\n a=a//10\r\n return T\r\nif losezero(a)+losezero(b)==losezero(c): print('YES')\r\nelse: print('NO')", "n=int(input())\r\nl=int(input())\r\nc=n+l\r\nn1=''\r\nn2=''\r\nn3=''\r\nfor i in str(n):\r\n if i!=\"0\":\r\n n1+=i\r\nfor i in str(l):\r\n if i!=\"0\":\r\n n2+=i\r\nfor i in str(c):\r\n if i!=\"0\":\r\n n3+=i\r\nif int(n3)==int(n1)+int(n2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n \r\n \r\n ", "a = input()\r\nb = input()\r\n# c = '0'\r\nf = lambda c: int(str(c).replace('0',''))\r\nd = int(a) + int(b)\r\n\r\nif f(a) + f(b) == f(d):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=int(input())\r\nb=int(input())\r\nz=lambda x:int(str(x).replace(\"0\",\"\"))\r\nprint([\"NO\",\"YES\"][z(a)+z(b)==z(a+b)])", "a = input()\r\nb = input()\r\nans1 = int(a)+int(b)\r\nans1 = str(ans1)\r\nc = ''\r\nfor i in range(len(ans1)):\r\n if(ans1[i]!='0'):\r\n c+=ans1[i]\r\nc = int(c)\r\ns1 = ''\r\ns2 = ''\r\nfor i in range(len(a)):\r\n if(a[i]!='0'):\r\n s1+=a[i]\r\nfor i in range(len(b)):\r\n if(b[i]!='0'):\r\n s2+=b[i]\r\nans2 = int(s1)+int(s2)\r\nif(ans2==c):\r\n print('YES')\r\nelse:\r\n print('NO')", "a = input()\r\nb = input()\r\nc = int(a) + int(b)\r\nc1 = int(str(c).translate({ord('0'): None}))\r\na1 = int(a.translate({ord('0'): None}))\r\nb1 = int(b.translate({ord('0'): None}))\r\nif a1 + b1 == c1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = input()\r\nb = input()\r\nc = int(a)\r\nd = int(b)\r\nans1 = c+d\r\ne = a.replace('0', '')\r\nf = b.replace('0', '')\r\ng = int(e)\r\nf = int(f)\r\nans2 = g+f\r\ntemp = str(ans1)\r\ns1 = temp.replace('0', '')\r\ns2 = str(ans2)\r\nif s1 == s2:\r\n print('YES')\r\nelse:\r\n print('NO')", "#n, m, k = map(int,input().split())\r\n\r\n#a, b = map(int,input().split())\r\na = input()\r\nb = input()\r\nc = str(int(a)+int(b))\r\ns_a = \"\"\r\ns_b = \"\"\r\ns_c = \"\"\r\nfor i in range(0, len(a)):\r\n if(a[i]!='0'):\r\n s_a += a[i]\r\n\r\nfor i in range(0, len(b)):\r\n if(b[i] != '0'):\r\n s_b+=b[i]\r\n\r\nfor i in range(0, len(c)):\r\n if(c[i] != '0'):\r\n s_c+=c[i]\r\n\r\nif(int(s_c)==int(s_a)+int(s_b)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "a, b = input(), input()\r\nc = str(int(a) + int(b)).replace(\"0\", \"\")\r\na, b = a.replace(\"0\", \"\"), b.replace(\"0\", \"\")\r\nprint(\"YNEOS\"[int(c) != eval(f\"{a}+{b}\") :: 2])", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nrem_a = int(''.join(c for c in str(a) if c != '0'))\r\nrem_b = int(''.join(c for c in str(b) if c != '0'))\r\nrem_c = int(''.join(c for c in str(c) if c != '0'))\r\nif rem_a + rem_b == rem_c:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\nnwa=''\r\nfor i in a:\r\n if i!='0':\r\n nwa+=i\r\nnwb=''\r\nfor i in b:\r\n if i!='0':\r\n nwb+=i\r\nnwc=''\r\nfor i in str(c):\r\n if i!='0':\r\n nwc+=i\r\nif int(nwa)+int(nwb)==int(nwc):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n\r\n \r\n\r\n", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\na = str(a)\r\nb = str(b)\r\nc = str(c)\r\na = int(a.replace('0', ''))\r\nb = int(b.replace('0', ''))\r\nc = int(c.replace('0', ''))\r\nprint('YES' if c == a+b else 'NO')", "n=int(input())\r\nk=int(input())\r\np=n+k\r\na=b=c=''\r\nn=str(n)\r\nfor i in n:\r\n if i!='0':\r\n a+=i \r\nk=str(k)\r\nfor i in k:\r\n if i!='0':\r\n b+=i \r\nq=str(p)\r\nfor i in q:\r\n if i!='0':\r\n c+=i \r\nif int(a)+int(b)==int(c):\r\n print('YES')\r\nelse:\r\n print('NO')", "a = int(input())\nb = int(input())\naa = []\nbb = []\ncc = []\nfor i in str(a):\n if i != '0':\n aa.append(i)\nfor i in str(b):\n if i != '0':\n bb.append(i)\nfor i in str(a + b):\n if i != '0':\n cc.append(i)\na = int(''.join(map(str, aa)))\nb = int(''.join(map(str, bb)))\nc = int(''.join(map(str, cc)))\n\nif a + b == c:\n print('YES')\nelse:\n print('NO')\n", "\r\ndef remove_zero(arg)->int:\r\n\treturn int(\"\".join(list(filter(lambda v : v!='0',str(arg)))))\r\n\r\na = int(input())\r\nb = int(input())\r\nc = a + b\r\n# print(remove_zero(c) == remove_zero(a) + remove_zero(b))\r\nif ( remove_zero(c) == remove_zero(a) + remove_zero(b) ):\r\n\tprint(\"YES\")\r\n\tpass \r\nelse :\r\n\tprint(\"NO\")\t", "n = input()\nm = input()\ns1 = int(n) + int(m)\ns = str(s1)\ns = s.replace('0','')\nn = n.replace('0','')\nm = m.replace('0','')\nk = int(n) + int(m)\nif(int(k)==int(s)):\n print(\"YES\")\nelse:\n print(\"NO\")\n# 1534888106664\n", "a=input()\r\nb=input()\r\nc=int(a)+int(b)\r\nstr_c=str(c)\r\nif '0' in a:\r\n a=a.replace('0','')\r\nif '0' in b:\r\n b=b.replace('0', '')\r\nif '0' in str_c:\r\n str_c=str_c.replace('0', '')\r\n c=int(str_c)\r\nif int(a)+int(b)==c:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\nc = a+b\r\nd,e,f = \"\",\"\",\"\"\r\nfor i in str(a):\r\n if i !=\"0\":\r\n d += i\r\n\r\nfor i in str(b):\r\n if i !=\"0\":\r\n e += i\r\n\r\n\r\nfor i in str(c):\r\n if i !=\"0\":\r\n f += i\r\n\r\n \r\nif int(f) == int(d) + int(e):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\nb = input()\n\nc = int(a) + int(b)\n\nna = \"\"\nnb = \"\"\nnc = \"\"\n\nfor i in a:\n if i != \"0\":\n na += i\n\nfor i in b:\n if i != \"0\":\n nb += i\n\nfor i in str(c):\n if i!=\"0\":\n nc += i\n\nif str(int(na)+int(nb)) == nc:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t \t \t\t \t \t \t \t \t \t\t\t \t\t\t", "a = input()\r\nb = input()\r\nc = int(a) + int(b)\r\nc_prime = int(str(c).replace('0', ''))\r\nc_prime_prime = int(a.replace('0', '')) + int(b.replace('0', ''))\r\n\r\nprint('YES' if c_prime_prime == c_prime else 'NO')\r\n", "n1 = input()\r\nn2 = input()\r\nwithoutz1 = \"\"\r\nwithoutz2 = \"\"\r\nfor cur in n1:\r\n if cur != \"0\":\r\n withoutz1 += cur\r\n\r\nfor cur in n2:\r\n if cur != \"0\":\r\n withoutz2 += cur\r\n\r\nres = int(n1)+int(n2)\r\n\r\nr = \"\"\r\n\r\nfor cur in str(res):\r\n if cur != \"0\":\r\n r += cur\r\n\r\nprint(\"YES\" if int(withoutz1)+int(withoutz2)==int(r) else \"NO\")", "x = input()\r\ny = input()\r\nz = int(x) + int(y)\r\nnew_x = \"\"\r\nnew_y = \"\"\r\nq = \"\"\r\nfor i in range(len(x)):\r\n if x[i] != '0':\r\n new_x += x[i]\r\n else:\r\n continue\r\nfor i in range(len(y)):\r\n if y[i] != '0':\r\n new_y += y[i]\r\n else:\r\n continue\r\nz = str(z)\r\nfor i in range(len(z)):\r\n if z[i] != '0':\r\n q += z[i]\r\n else:\r\n continue\r\np = int(new_x) + int(new_y)\r\nq = int(q)\r\nif q == p:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def remove_zeros(n):\r\n return int(str(n).replace('0', ''))\r\n\r\ndef main():\r\n a = int(input())\r\n b = int(input())\r\n c = a + b\r\n if remove_zeros(a) + remove_zeros(b) == remove_zeros(c):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\na=int(''.join(x for x in str(a) if x!='0'))\r\nb=int(''.join(x for x in str(b) if x!='0'))\r\nc=int(''.join(x for x in str(c) if x!='0'))\r\nif(a+b==c):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\r\nb=input()\r\nc=str(int(a)+int(b))\r\nl=''\r\nk=''\r\nj=''\r\nfor i in a:\r\n if i!='0':\r\n l+=i\r\nfor i in b:\r\n if i!='0':\r\n k+=i\r\nfor i in c:\r\n if i!='0':\r\n j+=i\r\nif int(l)+int(k)==int(j):\r\n print('YES')\r\nelse:\r\n print('NO')", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\ndef noZeros(s):\r\n res=''\r\n for i in range(len(s)):\r\n if s[i]!='0':\r\n res+=s[i]\r\n return int(res)\r\ns1=str(a)\r\ns2=str(b)\r\ns3=str(c)\r\na1,b1,c1=noZeros(s1),noZeros(s2),noZeros(s3)\r\nif a1+b1==c1:\r\n print('YES')\r\nelse:\r\n print(\"NO\")", "num1 = input()\nnum2 = input()\nsum = str(int(num1) + int(num2))\nnewNum1, newNum2, newSum = '', '', ''\nfor i in num1:\n\tif i != '0': newNum1 += i\nfor i in num2:\n\tif i != '0': newNum2 += i\nfor i in sum:\n\tif i != '0': newSum += i\nif int(newNum1) + int(newNum2) == int(newSum): print('YES')\nelse: print('NO')\n \t\t \t \t \t \t \t \t \t \t", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nif int(str(a).replace(\"0\", \"\")) + int(str(b).replace(\"0\", \"\")) == int(str(c).replace(\"0\", \"\")):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "\r\n\r\ndef x(n):\r\n y=''\r\n for i in n:\r\n if i!='0':\r\n y+=i\r\n return y\r\n\r\n\r\n\r\n\r\na=int(input())\r\nb=int(input())\r\nc=a+b\r\na=str(a)\r\nb=str(b)\r\nc=str(c)\r\na1=x(a)\r\nb1=x(b)\r\nc1=x(c)\r\n\r\nif int(a1)+int(b1)==int(c1):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n\r\n", "a = input()\r\nb = input()\r\n\r\ndef remove(num):\r\n str1 = ''\r\n for i in range(len(num)):\r\n if(num[i]!=\"0\"):\r\n str1+=num[i]\r\n str1 =int(str1)\r\n return str1\r\n\r\n\r\nc= int(a)+int(b)\r\nc = str(c)\r\nn1 = remove(c)\r\nn2 = remove(a)+remove(b)\r\nif(n1==n2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n\r\n\r\n", "######################################################################\r\n# Write your code here\r\nimport sys\r\nfrom math import *\r\ninput = sys.stdin.readline\r\n#import resource\r\n#resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY])\r\n#sys.setrecursionlimit(0x100000)\r\n# Write your code here\r\nRI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]\r\nrw = lambda : input().strip().split()\r\nls = lambda : list(input().strip()) # for strings to list of char\r\nfrom collections import defaultdict as df\r\nimport heapq \r\n#heapq.heapify(li) heappush(li,4) heappop(li)\r\n#import random\r\n#random.shuffle(list)\r\ninfinite = float('inf')\r\n#######################################################################\r\n\r\nn=int(input())\r\nm=int(input())\r\n\r\nt=n+m\r\n\r\ntemp=0\r\nwhile(n):\r\n if(n%10==0):\r\n n//=10\r\n continue\r\n temp=temp*10+n%10\r\n n//=10\r\n\r\ntemp=int(\"\".join(reversed(list(str(temp)))))\r\ntemp2=0\r\nwhile(m):\r\n if(m%10==0):\r\n m//=10\r\n continue\r\n temp2=temp2*10+m%10\r\n m//=10\r\ntemp2=int(\"\".join(reversed(list(str(temp2)))))\r\n\r\ntemp3=0\r\nwhile(t):\r\n if(t%10==0):\r\n t//=10\r\n continue\r\n temp3=temp3*10+t%10\r\n t//=10\r\ntemp3=int(\"\".join(reversed(list(str(temp3)))))\r\n\r\ntt=temp+temp2\r\nif(temp3==tt):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n \r\n", "def get(f): return f(input().strip())\ndef gets(f): return [*map(f, input().split())]\n\n\na = get(str)\nb = get(str)\nc = str(int(a)+int(b))\naa = ''.join(filter(lambda x: x != '0', a))\nbb = ''.join(filter(lambda x: x != '0', b))\ncc = ''.join(filter(lambda x: x != '0', c))\nprint('YES' if int(aa) + int(bb) == int(cc) else 'NO')\n", "a =int(input())\r\nb = int(input())\r\nc=a+b\r\na=str(a)\r\nb=str(b)\r\nc=str(c)\r\na1,a2,a3=\"\",\"\",\"\"\r\nfor ch in a:\r\n if ch!=\"0\":\r\n a1+=ch\r\nfor ch in b:\r\n if ch!=\"0\":\r\n a2+=ch\r\nfor ch in c:\r\n if ch!=\"0\":\r\n a3+=ch\r\na1=int(a1)\r\na2=int(a2)\r\na3=int(a3)\r\n\r\nt=a1+a2\r\nif(t==a3):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "x = int(input())\r\ny = int(input())\r\nsumma = x+y\r\n\r\nif \"0\" in str(x):\r\n x = int(str(x).replace(\"0\", \"\"))\r\n\r\nif \"0\" in str(y):\r\n y = int(str(y).replace(\"0\", \"\"))\r\n\r\nif \"0\" in str(summa):\r\n summa = int(str(summa).replace(\"0\", \"\"))\r\n\r\nif x+y == summa:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\nc0 = str(a+b)\r\na = str(a)\r\nb = str(b)\r\na = [(x) for x in a if int(x)]\r\nb = [(x) for x in b if int(x)]\r\nc = [(x) for x in c0 if int(x)]\r\na1 = int(\"\".join(a))\r\nb1 = int(\"\".join(b))\r\nc1 = int(\"\".join(c))\r\n\r\nif c1==a1+b1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n1 = input()\r\nn2 = input()\r\nsum = int(n1) + int(n2)\r\nsum = str(sum)\r\nn1 = n1.replace(\"0\",\"\")\r\nn2 = n2.replace(\"0\",\"\")\r\nsum = sum.replace(\"0\",\"\")\r\nn1 , n2 , sum = int(n1) , int(n2) , int(sum)\r\nsum1 = n1 + n2\r\nif sum1 == sum :\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\nb = input()\r\nc = str(int(a) + int(b))\r\n#while '0' in a:\r\na = a.replace('0', '')\r\na = int(a)\r\n#while '0' in b:\r\nb = b.replace('0', '')\r\nb = int(b)\r\n#while '0' in c:\r\nc = c.replace('0', '')\r\nc = int(c)\r\nif a + b == c:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a=int(input())\r\nb=int(input())\r\n\r\nc=[i for i in map(int, list(str(a+b))) if i>0]\r\na= [ i for i in map(int, list (str(a)) ) if i>0 ] \r\nb= [ i for i in map(int, list (str(b)) ) if i>0 ] \r\n\r\nA=''\r\nB=''\r\nC=''\r\nfor i in map(str, a) :\r\n A+=i\r\nfor i in map(str, b) :\r\n B+=i\r\nfor i in map(str, c) :\r\n C+=i\r\n\r\nif int(A) +int(B) ==int (C) :\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\")", "n1 = input()\r\nn2 = input()\r\ns = int(n1) + int(n2)\r\nt = str(s).replace('0', '')\r\n\r\nn1 = n1.replace('0', '')\r\nn2 = n2.replace('0', '')\r\nif int(n1) + int(n2) == int(t):\r\n print('YES')\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nd = str(a)\r\ne = str(b)\r\nf = str(c)\r\n# remove all zero from string\r\nd = d.replace('0','')\r\ne = e.replace('0','')\r\nf = f.replace('0','')\r\n\r\nif(int(d) + int(e) == int(f)):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nnumbers = [a, b, c]\r\ni = 0\r\nwhile i < 3:\r\n chislo = numbers[i]\r\n razryad = 1\r\n new_number = 0\r\n while chislo > 0:\r\n last = chislo % 10\r\n if last != 0:\r\n new_number = last * razryad + new_number\r\n razryad *= 10\r\n chislo = chislo // 10\r\n numbers[i] = new_number\r\n i += 1\r\nif numbers[0] + numbers[1] == numbers[2]:\r\n print('YES')\r\nelse:\r\n print(\"NO\")", "n1_0 = input()\nn2_0 = input()\nn3_0 = str(int(n1_0) + int(n2_0)).replace('0', '')\n\nn1 = n1_0.replace('0', '')\nn2 = n2_0.replace('0', '')\nn3 = int(n1) + int(n2)\n\nanswer = \"YES\" if int(n3_0) == n3 else \"NO\"\nprint(answer)", "a = input()\nb = input()\nc = str(int(a)+int(b))\nx=y=z=''\nfor i in a:\n if i != '0':\n x+=i\nfor i in b:\n if i != '0':\n y+=i\nfor i in c:\n if i != '0':\n z+=i\nif int(x)+int(y)==int(z):\n print('YES')\nelse:\n print('NO')\n", "def remove_zero(n):\r\n s = str(n)\r\n res = ''\r\n for x in s:\r\n if x != '0':\r\n res += x\r\n return int(res)\r\n\r\na, b = int(input()), int(input())\r\nc = a + b\r\nif remove_zero(c) == remove_zero(a) + remove_zero(b):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "int1 = input()\r\nint2 = input()\r\n\r\ndef purefy(s):\r\n\tps = ''\r\n\tfor x in s:\r\n\t\tif x != '0':\r\n\t\t\tps += x\r\n\treturn int(ps)\r\n\r\nsumm = str(int(int1) + int(int2))\r\n\r\nif purefy(int1) + purefy(int2) == purefy(summ):\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')\r\n", "import sys\r\n\r\ninput=sys.stdin.readline\r\na=input().strip(\"\\n\")\r\nb=input().strip(\"\\n\")\r\nprint(\"YES\" if str(int(a.replace(\"0\", \"\")) + int(b.replace(\"0\", \"\"))) == str(int(a) + int(b)).replace(\"0\", \"\") else \"NO\")", "a = int(input())\r\nb = int(input())\r\nc = str(a + b).replace(\"0\",\"\")\r\nsa = str(a)\r\nsb = str(b)\r\nsa = sa.replace(\"0\",\"\")\r\nsb = sb.replace(\"0\",\"\")\r\nc2 = int(sa)+int(sb)\r\nc = int(c)\r\nc2 = int(c2)\r\nif c == c2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def zero(x):\r\n p=1\r\n y=0\r\n while(x>0):\r\n num=x%10\r\n x=x//10\r\n \r\n if(num>0):\r\n y=y+num*p\r\n p=p*10\r\n return y \r\na=int(input())\r\nb=int(input())\r\nc=a+b\r\naf=zero(a)\r\nbf=zero(b)\r\ncf=zero(c)\r\nif(af+bf==cf):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\naa = a.replace(\"0\",\"\")\nb = input()\nbb = b.replace(\"0\",\"\")\nc = int(a)+int(b)\ncc = str(c).replace(\"0\",\"\")\nif int(cc) == int(aa) + int(bb):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "a = int(input())\r\nb = int(input())\r\norsum = a+b\r\n\r\nzersum = 0\r\n\r\na1 = ''\r\nfor i in str(a):\r\n if(i=='0'):\r\n pass\r\n else:\r\n a1+=i\r\n\r\nb1 = ''\r\nfor i in str(b):\r\n if(i=='0'):\r\n pass\r\n else:\r\n b1+=i\r\n \r\nzersum = int(a1)+int(b1)\r\norsum1 = ''\r\nfor i in str(orsum):\r\n if(i=='0'):\r\n pass\r\n else:\r\n orsum1+=i\r\n#print(zersum, orsum1)\r\nif(zersum == int(orsum1)):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "a = int(input())\r\nb = int(input())\r\nc = a+b\r\na = str(a).split('0')\r\nb = str(b).split('0')\r\nc = str(c).split('0')\r\nx = ''\r\ny = ''\r\nz = ''\r\nfor i in a:\r\n x+=i\r\nfor i in b:\r\n y+=i\r\nfor i in c:\r\n z+=i\r\nif int(x)+int(y)==int(z):\r\n print('YES')\r\nelse:\r\n print('NO') ", "a=(input())\r\nb=(input())\r\nc=int(a)+int(b)\r\nc=str(c)\r\nfor i in range(a.count('0')):\r\n\tj=a.find('0')\r\n\ta=a[:j]+a[j+1:]\r\nfor i in range(b.count('0')):\r\n\tj=b.find('0')\r\n\tb=b[:j]+b[j+1:]\r\nfor i in range(c.count('0')):\r\n\tj=c.find('0')\r\n\tc=c[:j]+c[j+1:]\r\nz=int(a)+int(b)\r\nif z==int(c):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "x=int(input()) \r\ng=int(input())\r\nn=x+g\r\ny=0\r\nc=\"\"\r\nv=\"\"\r\nb=\"\"\r\nwhile x>0:\r\n y=x%10 \r\n if y>0:\r\n c=str(y)+c\r\n x=x//10\r\nwhile g>0:\r\n y=g%10 \r\n if y>0:\r\n v=str(y)+v\r\n g=g//10\r\nwhile n>0:\r\n y=n%10 \r\n if y>0:\r\n b=str(y)+b\r\n n=n//10\r\n\r\nif int(c)+int(v)==int(b):\r\n print('YES')\r\nelse:\r\n print('NO')", "first = input()\r\nanother_first = int(first)\r\nfirst = first.replace(\"0\", \"\")\r\n\r\nsecond = input()\r\nanother_second = int(second)\r\nsecond = second.replace(\"0\", \"\")\r\n\r\nanother_sum = another_first + another_second\r\nanother_sum = int(str(another_sum).replace(\"0\", \"\"))\r\n\r\nif another_sum == int(first) + int(second):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\nb = input()\r\n\r\nc = int(a) + int(b)\r\nd = str(c)\r\n\r\nd = d.replace('0','')\r\nb = b.replace('0','')\r\na = a.replace('0','')\r\n#print(a,b,c,d)\r\nif(int(a)+int(b) == int(d)):\r\n print(\"YES\")\r\nelse: print(\"NO\")\r\n\r\n \r\n", "import math\r\nimport os\r\nimport random\r\nimport re\r\nimport sys\r\nimport functools\r\nfrom operator import itemgetter, attrgetter\r\nfrom collections import Counter\r\n\r\nif __name__ == '__main__':\r\n Y = lambda: list(map(int, input().split()))\r\n P = lambda: map(int, input().split())\r\n N = lambda: int(input())\r\n\r\n a = N()\r\n b = N()\r\n\r\n r_a = ''.join([i for i in str(a) if i != '0'])\r\n r_b = ''.join([i for i in str(b) if i != '0'])\r\n r_c = ''.join([i for i in str(a + b) if i != '0'])\r\n\r\n print('YNEOS'[int(r_a) + int(r_b) != int(r_c)::2])", "first = input()\r\nsecond = input()\r\n\r\nnofirst = first.replace(\"0\",\"\")\r\nnoSecond = second.replace(\"0\",\"\")\r\n\r\nif int(nofirst) + int(noSecond) == int(str(int(first) + int(second)).replace(\"0\",\"\")):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b \r\na=str(a)\r\nb=str(b)\r\nc=str(c)\r\nq=''\r\nw=''\r\ne=''\r\nfor i in range(len(c)):\r\n if c[i]!='0':\r\n e=e+c[i]\r\nfor i in range(len(a)):\r\n if a[i]!='0':\r\n q=q+a[i]\r\nfor i in range(len(b)):\r\n if b[i]!='0':\r\n w=w+b[i]\r\nq=int(q)\r\nw=int(w)\r\ne=int(e)\r\nif w+q==e:\r\n print(\"YES\")\r\nelse:print(\"NO\")", "data = []\r\nfor i in range(2):\r\n data.append(input())\r\n\r\na = data[0]\r\nb = data[1]\r\n\r\nresult_with_zeros = str(int(a) + int(b))\r\n\r\nsum = int(result_with_zeros.replace(\"0\", \"\"))\r\nint_a = int(a.replace(\"0\", \"\"))\r\nint_b = int(b.replace(\"0\", \"\"))\r\n\r\nif sum - int_a == int_b:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\nc = str(a + b)\r\nf = ''\r\nfor ch in c:\r\n if ch != '0':\r\n f += ch\r\nk, l = str(a), str(b)\r\ny, z = '', ''\r\nfor ch in k:\r\n if ch != '0':\r\n y += ch\r\nfor ch in l:\r\n if ch != '0':\r\n z += ch\r\ny, z = int(y), int(z)\r\nx = str(y + z)\r\nif x == f:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=int(input())\r\nb=int(input())\r\n\r\ndef without0(n):\r\n dem=1\r\n number = 0\r\n while (1<2) :\r\n a=n % 10\r\n if (a != 0):\r\n number = number + a*dem\r\n dem=dem*10\r\n n=n // 10\r\n if (n == 0):\r\n break\r\n\r\n return number\r\nsum1=without0(a+b)\r\nsum2=without0(a)+without0(b)\r\nif (sum1 == sum2):\r\n print('YES')\r\nelse:\r\n print('NO')", "a = int(input())\r\nb = int(input())\r\n\r\ndef removeZero(x):\r\n newNum = \"\"\r\n while x > 0:\r\n if x % 10 != 0:\r\n newNum = str(x % 10) + newNum\r\n x = x // 10\r\n return int(newNum)\r\n\r\nc = removeZero(a)\r\nd = removeZero(b)\r\nf = removeZero(a+b)\r\n\r\nif c + d == f:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "# import sys\n# # For getting input from input.txt file\n# sys.stdin = open('input.txt', 'r')\n# sys.stdout = open('output.txt', 'w')\na = int(input())\nb = int(input())\nis_zero_a = True\na_without_zeros,b_without_zeros = '',''\nfor i in str(a):\n if i=='0':\n is_zero_a = False\n else:\n a_without_zeros+=i\nis_zero_b = True\nfor i in str(b):\n if i=='0':\n is_zero_b = False\n else:\n b_without_zeros+=i\nc = a + b\nc_without_zeros_ans = ''\nfor i in str(c):\n if i != '0':\n c_without_zeros_ans+=i\nif is_zero_a and is_zero_b and len(c_without_zeros_ans)<1:\n print(\"YES\")\nelse:\n if len(a_without_zeros)<1:\n a_without_zeros = a\n if len(b_without_zeros)<1:\n b_without_zeros = b\n c_without_zeros = int(a_without_zeros) + int(b_without_zeros)\n if c_without_zeros==int(c_without_zeros_ans):\n print(\"YES\")\n else:\n print(\"NO\")\n", "def removeZero(x):\n x_0 = str(x)\n x_1 = ''\n for digit in x_0:\n if digit != '0':\n x_1 += digit\n return x_1\n\ndef main():\n m = int(input())\n n = int(input())\n result = m + n\n if (int(removeZero(m)) + int(removeZero(n)) == int(removeZero(result))):\n print(\"YES\")\n else:\n print(\"NO\")\n\n\nif __name__ == '__main__':\n main()\n \n\n ", "a = input()\r\nb = input()\r\na1 = a.replace('0', '')\r\nb1 = b.replace('0', '')\r\nc = str(int(a)+int(b))\r\nc1 = c.replace('0', '')\r\ng = int(b1) + int(a1)\r\n\r\nif (g == int(c1)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\nc = a + b\r\nnums = [a, b, c]\r\ni = 0\r\nwhile i < 3:\r\n num = nums[i]\r\n raz = 1\r\n nn = 0\r\n while num > 0:\r\n last = num % 10\r\n if last != 0:\r\n nn = last * raz + nn\r\n raz *= 10\r\n num //= 10\r\n nums[i] = nn\r\n i += 1\r\nif nums[0] + nums[1] == nums[2]:\r\n print('YES')\r\nelse:\r\n print('NO')", "a = input()\r\nb = input()\r\n\r\ndef func(a, b):\r\n first_sum = int(a) + int(b)\r\n\r\n def no_zeros(list):\r\n result = []\r\n for a in list:\r\n a = str(a)\r\n \r\n if '0' in a:\r\n a_list = [i for i in a]\r\n zeros = a_list.count('0')\r\n for i in range(zeros):\r\n a_list.remove('0')\r\n a = ''\r\n for num in a_list:\r\n a += num\r\n result.append(a)\r\n \r\n else:\r\n result.append(a)\r\n \r\n return result\r\n\r\n no_zeros_list = no_zeros([a, b, first_sum])\r\n second_sum = int(no_zeros_list[0]) + int(no_zeros_list[1])\r\n\r\n #print(no_zeros_list[2], second_sum)\r\n \r\n if int(no_zeros_list[2]) == second_sum:\r\n return 'YES'\r\n else:\r\n return 'NO'\r\n \r\n #return no_zeros([a, b, str(first_sum)])\r\n\r\n\r\nprint(func(a,b))\r\n\r\n# 11000030210\r\n# 321000192301300\r\n", "n=input();m=input();k=str(int(n)+int(m))\r\ndef remove(s):\r\n\tt=''\r\n\tfor i in s:\r\n\t\tif i != '0':\r\n\t\t\tt+=i\r\n\treturn t\r\nif int(remove(n))+int(remove(m)) == int(remove(k)) :\r\n\tprint('YES')\r\nelse: \r\n\tprint('NO')\r\n", "a = input()\r\nb = input()\r\nk = str(int(a)+int(b))\r\ne = ''\r\nc = ''\r\nd = ''\r\nfor i in a:\r\n if i != '0':\r\n c += i\r\nfor j in b:\r\n if j!= '0':\r\n d += j\r\nfor i in k:\r\n if i != '0':\r\n e += i\r\nif int(e) == int(c)+int(d):\r\n print('YES')\r\nelse:\r\n print('NO')", "a=int(input(''))\r\nb=int(input(''))\r\nc=str(a)\r\nd=str(b)\r\ne=''\r\nf=''\r\nfor i in c:\r\n if i!='0':\r\n e+=i\r\nfor i in d:\r\n if i!='0':\r\n f+=i\r\nn=str(a+b)\r\nm=int(e)+int(f)\r\nx=''\r\nfor i in n:\r\n if i!='0':\r\n x+=i\r\nif(int(x)==m):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = int(input())\r\nb = int(input())\r\ntsum = int(str(a + b).replace('0', ''))\r\n\r\na = int(str(a).replace('0', ''))\r\nb = int(str(b).replace('0', ''))\r\nprint(['NO', 'YES'][tsum == a + b])\r\n", "x=input()\r\ny=input()\r\nz = str(int(x)+int(y))\r\n \r\nx = x.replace('0','')\r\ny = y.replace('0','')\r\nz = z.replace('0','')\r\n \r\nif int(x)+int(y)==int(z):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\r\n \r\n'''\r\n101\r\n102\r\nyes\r\n''' ", "a=input(); b=input()\r\nc=int(a)+int(b)\r\nif int(a.replace('0',''))+int(b.replace('0',''))==int(str(c).replace('0','')):print('YES')\r\nelse:print('NO')", "def removeZeros(n):\r\n mul=1\r\n x=0\r\n while(n>0):\r\n digit=n%10\r\n if(digit!=0):\r\n x=digit*mul+x\r\n mul = mul * 10\r\n n=n//10\r\n return x\r\n\r\na=int(input())\r\nb=int(input())\r\nc=a+b\r\na1=removeZeros(a)\r\na2=removeZeros(b)\r\nc1=a1+a2\r\nif(removeZeros(c)==c1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = int(input())\r\n\r\nc=a+b\r\n\r\nstra = []\r\nstrb = []\r\nstrc = []\r\nwhile(a>0):\r\n rem = a%10\r\n stra.append(rem)\r\n a//=10\r\nstra.reverse()\r\n\r\nwhile(b>0):\r\n rem = b%10\r\n strb.append(rem)\r\n b//=10\r\nstrb.reverse()\r\nwhile(c>0):\r\n rem = c%10\r\n strc.append(rem)\r\n c//=10\r\nstrc.reverse()\r\n\r\nstra = [i for i in stra if i!=0]\r\nstrb = [i for i in strb if i!=0]\r\nstrc = [i for i in strc if i!=0]\r\n\r\nnewa=0\r\nnewb=0\r\nnewc=0\r\nfor i in stra:\r\n newa = newa*10+i\r\nfor i in strb:\r\n newb = newb*10+i\r\nfor i in strc:\r\n newc = newc*10+i\r\n \r\nif(newa+newb==newc):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "def rmZ(x):\n return int(str(x).replace(\"0\", \"\"))\n\nai, bi = int(input()), int(input())\nci = ai+bi\nprint(\"YES\" if rmZ(ai) + rmZ(bi) == rmZ(ci) else \"NO\")\n", "def removeZero(num):\r\n strnum = str(num)\r\n strnum = strnum.replace(\"0\", \"\")\r\n num = int(strnum)\r\n return num\r\n\r\n\r\nn1 = int(input())\r\nn2 = int(input())\r\n\r\nif removeZero(n1) + removeZero(n2) == removeZero(n1+n2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = int(input())\r\nb = int(input())\r\n\r\ndef removeZeros(number):\r\n result = 0\r\n temp = 0\r\n\r\n while (number > 0):\r\n if (number % 10 != 0): \r\n result += (number % 10) * 10**temp\r\n temp+=1\r\n number = number // 10\r\n\r\n return result\r\n\r\nsum1 = removeZeros(a + b)\r\nsum2 = removeZeros(a) + removeZeros(b)\r\n\r\nif (sum1 == sum2):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "def main():\n a = int(input())\n b = int(input())\n c = a + b\n a = str(a)\n b = str(b)\n c = str(c)\n a = a.split('0')\n b = b.split('0')\n c = c.split('0')\n a = ''.join(a)\n b = ''.join(b)\n c = ''.join(c)\n if int(c) == int(a) + int(b):\n print(\"YES\")\n else:\n print(\"NO\")\nmain()\n", "a = str(input())\r\nb = str(input())\r\nq = int(a) + int(b)\r\n#####################\r\na2 = \"\"\r\nb2 = \"\"\r\nq2 = \"\"\r\nfor i in a :\r\n if i != \"0\":\r\n a2+=i\r\nfor k in b :\r\n if k != \"0\" :\r\n b2+=k\r\nfor l in str(q) :\r\n if l != \"0\" :\r\n q2+=l\r\nw = int(a2) + int(b2)\r\nif w == int(q2):print(\"YES\")\r\nelse:print(\"NO\")\r\n \r\n ", "a,b=input(),input();print([\"NO\",\"YES\"][int(str(int(a)+int(b)).replace(\"0\",\"\"))==int(a.replace(\"0\",\"\"))+int(b.replace(\"0\",\"\"))])", "a=input()\r\nb=input()\r\nc=str(int(a)+int(b))\r\na1=a.split('0')\r\nb1=b.split('0')\r\nc1=c.split('0')\r\na1=''.join(a1)\r\nb1=''.join(b1)\r\nc1=''.join(c1)\r\nif int(a1)+int(b1)==int(c1):\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "x,y=input(),input()\r\nz=str(int(x)+int(y)).replace(\"0\",\"\")\r\nx=x.replace(\"0\",\"\")\r\ny=y.replace(\"0\",\"\")\r\nif int(z) == int(x)+int(y):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n1 = int(input().strip())\nn2 = int(input().strip())\nS1 = n1+n2\nN1 = ''\nN2 = ''\nS2 = ''\nfor i in str(n1):\n if i!='0':\n N1+=i\nfor i in str(n2):\n if i!='0':\n N2+=i\n\nfor i in str(S1):\n if i!='0':\n S2+=i\n\nN1 = int(N1)\nN2 = int(N2)\nS2 = int(S2)\n\nif (N1+N2)==S2:\n print(\"YES\")\nelse:\n print(\"NO\")\n\t \t\t\t\t \t \t \t \t \t \t", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\na1=str(a)\r\nb1=str(b)\r\nc1=str(c)\r\na1=a1.replace(\"0\",\"\")\r\nb1=b1.replace(\"0\",\"\")\r\nc1=c1.replace(\"0\",\"\")\r\n# print(a1,b1,c1)\r\na2=int(a1)\r\nb2=int(b1)\r\nc2=int(c1)\r\nd1=a2+b2\r\nd2=str(d1)\r\nd2.replace(\"0\",\"\")\r\nif(int(d2)==c2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = str(input())\r\nm = str(input())\r\nk = str(int(n) + int(m))\r\nn = n.replace('0', '')\r\nm = m.replace('0', '')\r\nk = k.replace('0', '')\r\nq = int(n) + int(m)\r\nif int(k) == q:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "def WithoutZeros(a,b):\r\n c= a+b\r\n c_zero=''.join(str(c).split('0'))\r\n \r\n a_zero=''.join(str(a).split('0'))\r\n b_zero=''.join(str(b).split('0'))\r\n\r\n x=int(a_zero)+int(b_zero)\r\n\r\n if int(c_zero)==x:\r\n return 'YES'\r\n return 'NO'\r\n \r\n\r\na=int(input())\r\nb=int(input())\r\n\r\nprint(WithoutZeros(a,b))", "a = int(input());b=int(input())\r\nc = a+b\r\nc = int(str(c).replace('0',''))\r\nsta,stb=int(str(a).replace('0','')),int(str(b).replace('0',''))\r\nstc = sta+stb\r\nif stc == c:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\nb=input()\ns=str(int(a)+int(b))\nal,bl,cl=[],[],[]\nfor i in a:\n al.append(i)\nfor i in b:\n bl.append(i)\nfor i in s:\n cl.append(i)\nwhile '0' in al:\n al.remove('0')\nwhile '0' in bl:\n bl.remove('0')\nwhile '0' in cl:\n cl.remove('0')\nprint('YES' if int(''.join(al)) + int(''.join(bl)) == int(''.join(cl)) else 'NO' )\n\n# n = map(int, input())\n# a=list(map(int, input().split()))\n# m=min(a)\n# if a.count(m) > 1:\n# print('Still Rozdil')\n# else:\n# print(a.index(m)+1)\n", "a=str(input())\r\nb=str(input())\r\ns=str(int(a)+int(b))\r\np=''\r\nq=''\r\nr=''\r\nfor i in a:\r\n if i!='0':\r\n p=p+i\r\nfor i in b:\r\n if i!='0':\r\n q=q+i\r\nfor i in s:\r\n if i!='0':\r\n r=r+i\r\nif int(p)+int(q)==int(r):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=int(input())\r\nb=int(input())\r\nc=a+b\r\nnumbers=[a,b,c]\r\ni=0\r\nwhile i<3:\r\n cislo = numbers[i]\r\n razryad=1\r\n new_number=0\r\n while cislo>0:\r\n last=cislo%10\r\n if last!=0:\r\n new_number=last*razryad+new_number\r\n razryad*=10\r\n cislo//=10\r\n numbers[i]=new_number\r\n i+=1\r\nif numbers[0]+numbers[1]==numbers[2]:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n \r\n", "a = input()\r\na0 = str(a)\r\n\r\nb = input()\r\nb0= str(b)\r\nc = str(int(a) +int(b))\r\nprint('YES' if eval((a0.replace('0','')+'+'+b0.replace('0','') +'=='+c.replace('0',''))) else 'NO')", "def main():\r\n\ta = str(input())\r\n\tb = str(input())\r\n\tc = str(int(a) + int(b))\r\n\r\n\tif int(a.replace('0', '')) + int(b.replace('0', '')) == int(c.replace('0', '')):\r\n\t\tprint('YES')\r\n\telse:\r\n\t\tprint('NO')\r\n\r\n\r\nif __name__ == '__main__':\r\n\tmain()" ]
{"inputs": ["101\n102", "105\n106", "544\n397", "822\n280", "101\n413", "309\n139", "693\n970", "981\n1", "352\n276", "164\n691", "110036\n43", "100\n1000", "1000000000\n1000000000", "999999999\n999999999", "6\n4", "123456\n876543", "1234567\n9876543", "1111111\n1119111", "10502405\n40403403", "1\n1", "5\n4", "1\n6", "40\n17", "35\n81", "347\n908", "2081\n7450", "84355694\n373629503", "885992048\n510468672", "540144752\n647307841", "341781108\n784147010", "960440938\n572334653", "657414510\n768771903", "501871728\n725074574", "968\n851", "943\n939", "347\n908", "611\n41", "737\n289", "168\n571", "868\n463", "815732007\n913882008", "459039901\n453033850", "975305404\n484601256"], "outputs": ["YES", "NO", "YES", "NO", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "NO", "YES", "YES", "NO", "YES", "NO", "NO", "YES", "YES", "YES", "YES", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "YES", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "NO"]}
UNKNOWN
PYTHON3
CODEFORCES
625
134e58b9e1ffbdb158576f17eed68543
Substring and Subsequence
One day Polycarpus got hold of two non-empty strings *s* and *t*, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of "*x* *y*" are there, such that *x* is a substring of string *s*, *y* is a subsequence of string *t*, and the content of *x* and *y* is the same. Two pairs are considered different, if they contain different substrings of string *s* or different subsequences of string *t*. Read the whole statement to understand the definition of different substrings and subsequences. The length of string *s* is the number of characters in it. If we denote the length of the string *s* as |*s*|, we can write the string as *s*<==<=*s*1*s*2... *s*|*s*|. A substring of *s* is a non-empty string *x*<==<=*s*[*a*... *b*]<==<=*s**a**s**a*<=+<=1... *s**b* (1<=≤<=*a*<=≤<=*b*<=≤<=|*s*|). For example, "code" and "force" are substrings or "codeforces", while "coders" is not. Two substrings *s*[*a*... *b*] and *s*[*c*... *d*] are considered to be different if *a*<=≠<=*c* or *b*<=≠<=*d*. For example, if *s*="codeforces", *s*[2...2] and *s*[6...6] are different, though their content is the same. A subsequence of *s* is a non-empty string *y*<==<=*s*[*p*1*p*2... *p*|*y*|]<==<=*s**p*1*s**p*2... *s**p*|*y*| (1<=≤<=*p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p*|*y*|<=≤<=|*s*|). For example, "coders" is a subsequence of "codeforces". Two subsequences *u*<==<=*s*[*p*1*p*2... *p*|*u*|] and *v*<==<=*s*[*q*1*q*2... *q*|*v*|] are considered different if the sequences *p* and *q* are different. The input consists of two lines. The first of them contains *s* (1<=≤<=|*s*|<=≤<=5000), and the second one contains *t* (1<=≤<=|*t*|<=≤<=5000). Both strings consist of lowercase Latin letters. Print a single number — the number of different pairs "*x* *y*" such that *x* is a substring of string *s*, *y* is a subsequence of string *t*, and the content of *x* and *y* is the same. As the answer can be rather large, print it modulo 1000000007 (109<=+<=7). Sample Input aa aa codeforces forceofcode Sample Output 5 60
[ "from sys import stdin\r\ns=[ord(i)-97 for i in stdin.readline().strip()]\r\ns1=[ord(i)-97 for i in stdin.readline().strip()]\r\nn=len(s)\r\nm=len(s1)\r\nans=0\r\nmod=10**9+7\r\ndp=[[0 for i in range(n)] for j in range(26)]\r\nfor i in range(m):\r\n arr=[0 for j in range(n)]\r\n for j in range(n):\r\n if s1[i]==s[j] :\r\n arr[j]=1\r\n if j>0 :\r\n arr[j]=(arr[j]+dp[s[j-1]][j-1])%mod\r\n for j in range(n):\r\n dp[s1[i]][j]=(arr[j] +dp[s1[i]][j]) %mod \r\nx=0\r\nfor i in dp:\r\n x=(x+sum(i))%mod\r\nprint(x)\r\n" ]
{"inputs": ["aa\naa", "codeforces\nforceofcode", "coderscontest\ncodeforces", "a\nb", "ab\nbbbba", "abbbccbba\nabcabc", "zxzxzxzxzxzxzx\nd", "pfdempfohomnpgbeegikfmflnalbbajpnpgeacaicoehopgnabnklheepnlnflohjegcciflmfjhachnhekckfjgoffhkblncidn\nidlhklpclcghngeggpjdgefccihndpoikojdjnbkdfjgaanoolfmnifnmbpeeghpicehjdiipnlfnjpglidpnnnjfmjfhbcogojkcfflmmfcgajbjbfaikhmjofbnjnaolbcdkelcieeodbfjcfiblhhmeelmpcmmcdhjcnnfklgedjjbaljndjonanlojclboeelkab", "sbypoaavsbqxfiqvpbjyimhzotlxuramhdamvyobsgaehwhtfdvgvlxpophtvzrmvyxwyzeauyatzitsqvlabufbcefaivwzoccfvhrdbzlmzoofczqzbxoqioctzzxqksuorhnldrfavlhyfyobvnqsyegsbvlusxchixbddzbwwnvuulcarguxvnvzkdqcjxxdetll\nlbawrainjjdgkdmwkqzxlwxhzjyrxbuwjhnvjlnmgfyrxdynsanvibfhngsioisbyldaplituqhebeicpsyerpiiqpjtnxvuotjv", "ababbabbab\nababb", "bbabb\nbababbbbab", "ababababab\nababb", "b\nab", "ab\na", "xzzxxxzxzzzxzzzxxzzxzzxzxzxxzxxzxxzxzzxxzxxzxxxzxzxzxxzzxxxxzxzzzxxxzxzxxxzzxxzxxzxxzzxxzxxzxzxzzzxzzzzxzxxzzxzxxzxxzzxzxzx\nzzx", "zxx\nxzzxxxxzzzxxxzzxxxzxxxzzxxzxxxzzxzxxzxxzxxzxzxxzxxxxzzxxzzxzzxxzzxxzxzxzxxzxzxzxxxzxxzzxxzxxxxzzxxxzxxxzxzxzzxzzxxxxzzxxzxz"], "outputs": ["5", "60", "39", "0", "5", "33", "0", "26774278", "8095", "75", "222", "74", "1", "1", "291", "46917"]}
UNKNOWN
PYTHON3
CODEFORCES
1
1354c407fb01914d81f781d3516fb837
Sleuth
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that. Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them. The English alphabet vowels are: A, E, I, O, U, Y The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No". Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. Sample Input Is it a melon? Is it an apple? Is it a banana ? Is it an apple and a banana simultaneouSLY? Sample Output NO YES YES YES
[ "n=input()\r\nn=list(n)\r\nn=n[::-1]\r\nl=['A','E','I','O','U','Y','a','e','i','o','u','y']\r\ni=1\r\nwhile(n[i]==' '):\r\n i=i+1\r\n continue\r\n#print(n,i)\r\nif(n[i] not in l):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n\r\n", "n = input().lower()\r\nx = [97, 101, 105, 111, 117, 121]\r\ni = len(n) - 1\r\n\r\nwhile i+1:\r\n on = ord(n[i])\r\n if on in range(97, 123):\r\n if on in x:\r\n print('YES')\r\n else:\r\n print('NO')\r\n break\r\n i -= 1\r\n", "a=['a','e','i','o','u','y']\r\ns=input().lower()\r\nif s[-2]==\" \":\r\n s=s.replace(\" \",'')\r\n # print(s)\r\nif s[-2] in a:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "from sys import stdin,stdout\r\n\r\nstr1 = stdin.readline().strip()\r\nstr1 = str1.replace(' ','')\r\n\r\nprint('YES' if str1[-2].upper() in ['A', 'E', 'I', 'O', 'U', 'Y'] else 'NO')", "s = str(input()).lower()\r\nv = ['a','e','i','o','u','y']\r\n\r\nfor ch in reversed(s):\r\n if ch not in [' ', '?']:\r\n if ch in v:\r\n print('YES')\r\n else:\r\n print('NO')\r\n break", "n = input()\nn = n[:len(n)-1]\nv = ['A','E','I','O','U','Y']\nn = n.upper().strip()\nif n[len(n)-1] in v: \n print(\"YES\")\nelse:\n print(\"NO\")", "s = input()\r\ns1 = s.lower()\r\n\r\nfor i in range(len(s1)-1,-1,-1):\r\n if ord(s1[i]) in range(97,123):\r\n ch = s1[i]\r\n break\r\nif ch in ('a','e','i','o','u','y'):\r\n print('YES')\r\nelse:\r\n print('NO')", "def is_vowel(char):\r\n all_vowels = 'aeiouyAEIOUY'\r\n return char in all_vowels\r\nx=input()\r\nfor i in x[::-1]:\r\n if(i!=\"?\" and i!=\" \"):\r\n a=i\r\n break\r\nprint(\"YES\" if is_vowel(a) else \"NO\") ", "# python 3\n\"\"\"\n\"\"\"\n\n\ndef sleuth(question_str) -> str:\n question_lc = question_str.lower()\n alphabet = \"abcdefghijklmnopqrstuvwxyz\"\n vowel = \"aeiouy\"\n for i in range(len(question_lc) - 1, -1, -1):\n if question_lc[i] in alphabet:\n if question_lc[i] in vowel:\n return \"YES\"\n else:\n return \"NO\"\n\n\nif __name__ == \"__main__\":\n \"\"\"\n Inside of this is the test. \n Outside is the API\n \"\"\"\n question = input()\n\n print(sleuth(question))\n", "def sleuth(s):\n\n vowels = set()\n s = s.replace(\" \", \"\")\n lst = [\"a\",\"e\",\"i\",\"o\",\"u\", \"y\"]\n for vowel in lst:\n vowels.add(vowel)\n\n if s[-2].lower() in vowels:\n print(\"YES\")\n else:\n print(\"NO\")\n\n\nstring = input()\nsleuth(string)\n\n\n \n\n", "g=['A', 'E', 'I', 'O', 'U', 'Y']\r\nsg=['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Z']\r\ns=input().replace(\"?\",\"\").split()\r\nprint(\"YES\" if s[-1][-1].upper() in g else \"NO\")\r\n", "s = list(input().rstrip(\"?\").split(\" \"))\r\ns.reverse()\r\nfor i in s:\r\n if i != '':\r\n if(i[-1].lower() == 'a' or i[-1].lower() == 'e' or i[-1].lower() == 'i' or i[-1].lower() == 'o' or i[-1].lower() == 'u' or i[-1].lower() == 'y'):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break", "t = input()\r\nx = t.replace(\" \",\"\")\r\nvowel = \"aeiouyAEIOUY\"\r\nif x[-2] in vowel:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=input()\r\nl=list(s)\r\nl=l[::-1]\r\nflag=0\r\nfor i in range(len(s)):\r\n if not(l[i]=='?' or l[i]==' '):\r\n if l[i]=='a' or l[i]=='e' or l[i]=='i' or l[i]=='o' or l[i]=='u' or l[i]=='y' or l[i]=='A' or l[i]=='E' or l[i]=='I' or l[i]=='O' or l[i]=='U' or l[i]=='Y':\r\n flag=1\r\n break\r\n else:\r\n break\r\nif flag==1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\r\na=a.replace(' ','')\r\nprint(\"YES\") if(a[len(a)-2]=='a' or a[len(a)-2]=='e' or a[len(a)-2]=='i' or a[len(a)-2]=='o' or a[len(a)-2]=='u' or a[len(a)-2]=='y' or a[len(a)-2]=='A' or a[len(a)-2]=='E' or a[len(a)-2]=='I' or a[len(a)-2]=='O' or a[len(a)-2]=='U' or a[len(a)-2]=='Y') else print(\"NO\")", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\ndata = input().rstrip()\r\nlast = ''\r\nfor i in range(len(data) - 1, -1, -1):\r\n if data[i].isalpha():\r\n last = data[i]\r\n break\r\n\r\nprint(\"YES\" if last.lower() in ['a', 'e', 'i', 'o', 'u', 'y'] else 'NO')", "import sys\r\nvowel=\"AEIOUYaeiouy\"\r\ns=input()\r\nfor i in range(len(s)-1,-1,-1):\r\n if(s[i]!='?' and s[i]!=' '):\r\n if(s[i] in vowel):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n sys.exit(0)", "s = input().upper()\r\n\r\ngl = 'AEIOUY'\r\nsogl = 'BCDFGHJKLMNPQRSTVWXZ'\r\nfor i in s[::-1]:\r\n\tif i in gl:\r\n\t\tprint('YES')\r\n\t\tbreak\r\n\telif i in sogl:\r\n\t\tprint('NO')\r\n\t\tbreak\r\n\r\n", "if input().lower().strip('? ')[-1] in 'aeiouy':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input().replace(' ', '')\nif s[-2].lower() in ['a', 'e', 'i', 'o', 'u', 'y']: print('YES')\nelse: print('NO')\n", "print(('NO', 'YES')[input().rstrip(' ?')[-1].upper() in 'AEIOUY'])\r\n", "# Write Python code in this online editor and run it.\nprint('NYOE S'[input()[:-1].rstrip()[-1] in 'aeiouyAEIOUY'::2])\n\t \t\t \t \t \t\t \t\t\t \t \t \t\t", "\r\n\r\nst = list(input())\r\nn = len(st) -2\r\nl = list('aeiouyAEIOYU')\r\nwhile st[n] == ' ':\r\n\tn -= 1\r\n\r\nif st[n] in l:\r\n\tprint('YES')\r\n\texit()\r\n\r\nprint('NO')\r\n\r\n", "klh = input().strip(\" ?\").lower()\r\nif klh[-1] in \"aeiouy\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input()\r\ni = len(s) - 1\r\nwhile s[i] not in \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\":\r\n i = i - 1\r\nif s[i] in \"aeiouyAEIOUY\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "#!/usr/bin/env python3\ndef solve(i):\n\tif eins[i] in misc:\n\t\ti = i - 1\n\t\tsolve(i)\n\telif eins[i] in vowel:\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n\nvowel = ['A','E','I','O','U','Y','a','e','i','o','u','y']\nmisc = ['?',' ']\neins = input()\nsolve(-1)\n\n", "\r\nimport re\r\ns = input().lower()\r\n\r\ns = re.sub(\"[^a-z]\", '', s)\r\n\r\nif s[-1] in \"AEIOUY\".lower():\r\n print('YES')\r\nelse:\r\n print('NO')", "s = input().split()\r\ns = \"\".join(s)\r\nv = ['a', 'e','o', 'u', 'y']\r\ns = s.lower()\r\nif s[-2] in v:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "str = input()\r\narr = str.split( )\r\ny = arr[-1]\r\n\r\nif y[0]=='?':\r\n y = arr[-2]\r\n ch = y[-1]\r\nelse:\r\n ch = y[-2]\r\nif(ch=='A' or ch=='a' or ch=='E' or ch =='e' or ch=='I'\r\n or ch=='i' or ch=='O' or ch=='o' or ch=='U' or ch=='u' or ch=='Y' or ch=='y'):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "questions=input(\"\")\r\nvowels=\"aeiouy\"\r\nquestions=questions.lower()\r\ncounter=-1\r\nfound=False\r\ncount=0\r\nwhile count!=1:\r\n letter= questions[counter]\r\n if letter.isalpha() :\r\n count+=1\r\n if letter in vowels:\r\n found= True\r\n counter-=1\r\n\r\nif found:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n \r\n\r\n", "x=input().lower().replace(\"?\",\"\").replace(\" \",\"\")\r\nif x[-1:]==\"y\" or x[-1:]==\"a\" or x[-1:]==\"e\" or x[-1:]==\"i\" or x[-1:]==\"u\" or x[-1:]==\"o\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "t = input()\r\ni = len(t) - 2\r\nwhile t[i] == ' ': i -= 1\r\nprint('YNEOS'[not t[i] in 'aeiouyAEIOUY' :: 2])", "a=input()\r\na=a.replace(\" \",\"\")\r\nif a[-2].lower()==\"y\" or a[-2].lower()==\"a\" or a[-2].lower()==\"i\" or a[-2].lower()==\"u\" or a[-2].lower()==\"e\" or a[-2].lower()==\"o\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def main():\r\n\ts = list(map(str, input().split()))\r\n\tvowel = ['a', 'i', 'u', 'e', 'o', 'y', 'A', 'I', 'U', 'E', 'O', 'Y']\r\n\r\n\tif s[-1] != '?':\r\n\t\tif s[-1][-2] in vowel:\r\n\t\t\tprint('YES')\r\n\t\telse:\r\n\t\t\tprint('NO')\r\n\telse:\r\n\t\tif s[-2][-1] in vowel:\r\n\t\t\tprint('YES')\r\n\t\telse:\r\n\t\t\tprint('NO')\r\n\r\nif __name__ == '__main__':\r\n\tmain()", "vowels = ['A', 'E', 'I', 'O', 'U', 'Y']\nquesion = input()[:-1].split()\nif quesion[-1][-1].upper() in vowels:\n print('YES')\nelse:\n print('NO')\n", "import string\r\n# tc = int(input())\r\ntc = 1\r\nwhile tc:\r\n # inp = [int(x) for x in input().split()]\r\n # n = int(input())\r\n # n, c, q = inp[0], inp[1], inp[2]\r\n # s = input()\r\n q = input()\r\n # a = [int(x) for x in input().split()]\r\n vowels = {'a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y'}\r\n for i in range(len(q) - 1, -1, -1):\r\n if (q[i] >= 'A' and q[i] <= 'Z') or (q[i] >= 'a' and q[i] <= 'z'):\r\n break\r\n if q[i] in vowels:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n tc -= 1\r\n", "words=str(input())\r\nlast_letter=list(words.replace(' ','').replace('?','')).pop()\r\ncheck=['A','E','I','O','U','Y','a','e','i','o','u','y']\r\nch_val=0\r\nfor i in check:\r\n if last_letter==i:\r\n print('YES')\r\n ch_val=0\r\n break\r\n else: ch_val=1\r\nif ch_val==1: print('NO')", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Mar 30 19:32:51 2021\r\n\r\n@author: nehas\r\n\"\"\"\r\ns=input()\r\ns=s.replace(\" \",\"\")\r\nl=['a','e','i','o','u','y','A','I','E','O','U','Y']\r\ns1=\"\"\r\nfor char in s:\r\n if(char.isalpha()==True):\r\n s1=s1+char\r\nif s1[len(s1)-1] in l:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") ", "w = input()[::-1]\r\nv = ['a','e','i','o','u','y']\r\nfor char in w:\r\n if char =='?' or char ==' ':\r\n continue\r\n elif char.lower() in v :\r\n print('YES')\r\n break\r\n else:\r\n print('NO')\r\n break\r\n\r\n", "phrase = list(input())\r\n\r\nultimo = phrase.pop()\r\n\r\nwhile ultimo.isalpha() == False:\r\n ultimo = phrase.pop()\r\nif ultimo in 'aAeEiIoOuUYy':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "S = input()\r\nV = 'AaEeIiOoUuYy'\r\nN = 'BbCcDdFfGgHhJjKkLlMmNnPpQqRrSsTtVvWwXxZz'\r\nfor i in range(len(S)-1, -1, -1):\r\n\tif(V.find(S[i])!=-1):\r\n\t\tprint(\"YES\")\r\n\t\tbreak\r\n\tif(N.find(S[i])!=-1):\r\n\t\tprint(\"NO\")\r\n\t\tbreak", "vowels = \"aeiouy\"\r\nalpha = \"abcdefghijklmnopqrstuwvxyz\"\r\ndef letter(w) :\r\n for i in range(len(w)-1,-1,-1) :\r\n if w[i] in alpha :\r\n break\r\n if w[i] in vowels :\r\n return \"YES\"\r\n return \"NO\"\r\nquestion= input().lower()\r\nprint(letter(question))", "s= input()\r\ns= s.split(' ')\r\ns=''.join(s)\r\nif ((s[-2]).upper() in {'A','E','I','O','U','Y'}):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input().replace(' ','')\r\nprint('YES' if a.strip().lower()[-2] in 'aeiouy' else \"NO\")", "s=str(input())\r\ns=s[::-1]\r\nfor i in s:\r\n if i!=' ' and i!='?':\r\n c=i.lower()\r\n break\r\nif c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='y':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input().rstrip(\"?\").rstrip()[-1].upper()\r\nif a in [ 'A', 'E', 'I', 'O', 'U', 'Y']:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\n\r\nn = len(a)\r\ns = ''\r\nfor i in range (n):\r\n if a[i] == ' ' or a[i] == '?':\r\n continue\r\n else:\r\n s = s + a[i] \r\n\r\n\r\nk = len(s)\r\n#print(k)\r\n\r\nch = s[k-1]\r\n\r\nif ch in [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\",\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\"]:\r\n print(\"YES\")\r\n\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n\r\n\r\n'''if b[-1] == \"?\" :\r\n\tword = b[len(b)-2]\r\n\tif word[-1] in [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\",\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\"]:\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")\r\nelse:\r\n\tword = b[len(b) -1]\r\n\tif word[-2] in [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\",\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\"]:\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")'''\r\n\r\n\r\n\r\n\t", "s = input().lower()\r\n\r\ns = s.replace(\"?\",\"\")\r\n\r\nwords = s.split()\r\n\r\nln = len(words)-1\r\n\r\nlast_word = words[ln]\r\n\r\nab = last_word[::-1]\r\n\r\nif ab[0] == \"a\" or ab[0] == \"e\" or ab[0] == \"i\" or ab[0] == \"o\" or ab[0] == \"u\" or ab[0] == \"y\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input()\r\ns = s.replace('?','')\r\n\r\ns = s.split()\r\n#print(s)\r\nvowels = ['a','e','i','o','u','y','A','E','I','O','U','Y']\r\n\r\n#print(s)\r\nif(s[-1][-1] not in vowels):\r\n\tprint('NO')\r\nelse:\r\n\tprint('YES')\r\n", "a = str(input().split()).lower()\r\na = a.replace(\" \",\"\")\r\nd = ['a','e','i','o','u','y']\r\na = a.replace(\",\",\"\")\r\na = a.replace(\"]\",\"\")\r\na = a.replace(\"'\",\"\")\r\n\r\nfor i in d:\r\n if a[-2]==i:\r\n print(\"YES\")\r\n break\r\n else:\r\n pass\r\nelse:\r\n print(\"NO\")", "s = input()\r\ns = s[::-1]\r\nz = ''\r\n\r\nfor i in range(len(s)):\r\n if s[i] != '?' and s[i] != ' ':\r\n z = s[i]\r\n break\r\n \r\nv = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']\r\n\r\nif z in v:\r\n print('YES')\r\n\r\nelse:\r\n print('NO')\r\n", "string=input()\r\nstring1=string.upper()\r\na=[]\r\nfor i in string1:\r\n if i!=' ' and i!='?':\r\n a.append(i)\r\n else:\r\n continue\r\nb=''.join(a)\r\nlist1=['A','E','I','O','U','Y']\r\nfor i in range(len(b)):\r\n if i==len(b)-1:\r\n if b[i] in list1:\r\n print('YES')\r\n break\r\n else:\r\n print('NO')\r\n break\r\n else:\r\n continue\r\n ", "s=input().split(' ')\r\nx=\"\"\r\nz=\"AEIOUYaeiouy\"\r\nfor i in s:\r\n x+=i\r\n\r\nif(x[-2] in z):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input().lower()\r\ns = s.replace(\" \",\"\")\r\nlast = s[len(s)-1]\r\nif last=='?' or last==' ':\r\n last = s[len(s)-2]\r\nif last=='a' or last=='e' or last=='i' or last=='o' or last=='u' or last=='y':\r\n print('YES')\r\nelse:\r\n print('NO')", "import string\r\nl=input()\r\nl=l.translate(str.maketrans(' ',' ',string.punctuation))\r\nl=l.replace(\" \", \"\")\r\nl.split()\r\nl.lower()\r\nf=['a','e','i','o','u','y','A','E','I','O','U','Y']\r\nif l[-1] not in f:\r\n print('NO')\r\nelse:\r\n print('YES')\r\n", "# https://codeforces.com/problemset/problem/49/A\r\n\r\ndef func_sol(lines):\r\n return \"YES\" if lines[0].replace(' ', '')[-2] in 'aeiouyAEIOUY' else \"NO\"\r\n\r\n\r\ndef main():\r\n try:\r\n from codeforces.utilities import run_tests\r\n run_tests(func_sol)\r\n except ImportError:\r\n from sys import stdin\r\n print(func_sol(stdin.read().split('\\n')[:-1]))\r\n\r\n\r\nmain()\r\n", "A=[x for x in input().split()]\r\ngl='AEIOUYaeiouy'\r\nif A[-1]!='?':\r\n if A[-1][-2] in gl:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n if A[-2][-1] in gl:\r\n print('YES')\r\n else:\r\n print('NO')\r\n \r\n", "a=input()\r\nk='aeiouAEIOUYy'\r\ndef fun(string):\r\n return string.replace(\" \",\"\")\r\na=fun(a)\r\nif a[-2] in k:print(\"YES\")\r\nelse:print(\"NO\")", "s=input()\r\nimport string\r\na=\"aeiouy\"\r\nb=\"AEIOUY\"\r\nfor i in range(len(s)-2,-1,-1):\r\n if(s[i].isalpha()):\r\n if(s[i] in a or s[i] in b):\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break", "str1=list(map(str,input().split()))\r\nif(str1[len(str1)-1]=='?'):\r\n k=str1[len(str1)-2]\r\n k_len=len(k)\r\n m=k[k_len-1]\r\n if(m=='a' or m=='e' or m=='i' or m=='o' or m=='u' or m=='y' or m=='A' or m=='E' or m=='I' or m=='O' or m=='U' or m=='Y'):\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n k=str1[len(str1)-1]\r\n k_len=len(k)\r\n m=k[k_len-2]\r\n if(m=='a' or m=='e' or m=='i' or m=='o' or m=='u' or m=='y' or m=='A' or m=='E' or m=='I' or m=='O' or m=='U' or m=='Y'):\r\n print('YES')\r\n else:\r\n print('NO')", "s=input().upper().strip()\r\nvowels=[ \"A\", \"E\", \"I\", \"O\", \"U\", \"Y\"]\r\ns1=s[-2]\r\n#print(s1[-1])\r\nf=0\r\nfor i in s:\r\n if i!=\" \" and i!=\"?\":\r\n #print(i)\r\n if i in vowels:\r\n f=1\r\n else:\r\n f=0\r\nif f==1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "v=\"aeiouyAEIOUY\"\r\ns = input()\r\ns = s.strip(\"?\")\r\ns = s.split()\r\nif (s[-1])[-1] in v:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input()\r\nl = len(s) \r\nvow = \"aeiouy\" \r\nVOW = \"AEIOUY\" \r\n\r\nz = \"\" \r\nfor i in range(l) :\r\n\tif s[i].isspace() == 0 :\r\n\t\tz = z + s[i] \r\n\r\nm = len(z) \r\nif z[m-2] in vow or z[m-2] in VOW :\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\r\n", "s=input()\r\na=''\r\nfor i in s:\r\n if i!=' ':\r\n a+=i\r\nw=a[-2]\r\nif w=='a' or w=='e' or w=='i' or w=='o' or w=='u' or w=='y' or w=='A' or w=='E' or w=='I' or w=='O' or w=='U' or w=='Y':\r\n print('YES')\r\nelse:\r\n print('NO')", "a=str(input())\r\nb=[]\r\nc=[\"a\",\"e\",\"i\",\"o\",\"u\",\"y\",\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\"]\r\nfor i in a:\r\n if(i==\" \" or i==\"?\"):\r\n continue\r\n else:\r\n b.append(i)\r\nif b[-1] in c:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "def onlyletters(line):\r\n return line.replace(\" \", \"\")\r\n\r\n\r\nans = input()\r\nans = onlyletters(ans)\r\nln = len(ans)\r\nif ans[ln - 2] == 'a' or \\\r\n ans[ln - 2] == 'e' or \\\r\n ans[ln - 2] == 'i' or \\\r\n ans[ln - 2] == 'o' or \\\r\n ans[ln - 2] == 'u' or \\\r\n ans[ln - 2] == 'y' or \\\r\n ans[ln - 2] == 'A' or \\\r\n ans[ln - 2] == 'Y' or \\\r\n ans[ln - 2] == 'E' or \\\r\n ans[ln - 2] == 'I' or \\\r\n ans[ln - 2] == 'O' or \\\r\n ans[ln - 2] == 'U':\r\n print('YES')\r\nelse:\r\n print('NO')", "def removeSpaces(string):\r\n string = string.replace(' ','')\r\n return string\r\n\r\n\r\ns = input()\r\nv = ['A', 'E', 'I', 'O', 'U', 'Y']\r\nk = s.upper()\r\nans = removeSpaces(k)\r\nlen = len(ans)\r\nif ans[len-2] in v:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "s=input().replace(' ','').replace('?','')\ns=s.lower()\nprint(['NO','YES'][s[-1] in 'aeiouyAEIOUY'])", "print(\"YES\" if (input()).lower().replace(\" \", \"\")[-2:-1] in [\"a\", \"e\", \"i\", \"o\", \"u\", \"y\"] else \"NO\")\r\n", "glass=\"AEIOUYaeiouy\"\r\na=input()[::-1]\r\nb=''\r\nfor i in a:\r\n if i==\" \":\r\n continue\r\n b+=i\r\ne=b[1]\r\nif e in glass:\r\n print('YES')\r\nelse:print('NO')\r\n\r\n \r\n", "a = input()\r\na = a.replace(\" \", \"\", a.count(\" \"))\r\nif a[-2] == \"A\" or a[-2] == \"E\" or a[-2] == \"I\" or a[-2] == \"O\" or a[-2] == \"U\" or a[-2] == \"Y\" or a[-2] == \"a\" or a[-2] == \"e\" or a[-2] == \"i\" or a[-2] == \"o\" or a[-2] == \"u\" or a[-2] == \"y\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n", "s = input()\r\nvowels = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']\r\nllp=len(s)-1\r\nwhile not s[llp].isalpha():\r\n llp-=1\r\nif s[llp] in vowels:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "sentence = input()\r\nstart, letter = -1, str()\r\nwhile True:\r\n if (sentence[start] != ' ') and (sentence[start] != '?'):\r\n letter = sentence[start]\r\n break\r\n start -= 1\r\nif letter.lower() in ['a', 'e', 'i', 'o', 'u', 'y']:\r\n print('YES')\r\nelse:\r\n print('NO')", "k = input().lower()\r\n\r\nv =\"aeiouy\"\r\n\r\nk = k.replace(\" \",\"\")\r\n\r\nif k[-2] in v:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input().replace(\" \", \"\")\r\nprint('YES' if s[-2] in 'aeiouyAEIOUY' else 'NO')", "s = input().replace(' ','')\r\nvowel = 'aeiouyAEIOUY'\r\nprint(\"YES\" if s[-2] in vowel else \"NO\")", "vowel = [\"a\", \"e\", \"i\", \"o\", \"u\", \"y\"]\r\nkl= list(input())\r\nkl.reverse()\r\nfor j in kl:\r\n if j.isalpha():\r\n if j.lower() in vowel:\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break\r\n else:\r\n continue", "arr=list(map(str,input().split()))\nfor i in range(len(arr)):\n arr[i]=arr[i].lower()\n\nvowels=[\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]\n# print(arr[-1][-2])\n\nif arr[-1]==\"?\":\n if arr[-2][-1] in vowels:\n print(\"YES\")\n else:\n print(\"NO\")\n \n\nelif arr[-1][-1]==\"?\":\n if arr[-1][-2] in vowels:\n print(\"YES\")\n else:\n print(\"NO\")", "# https://codeforces.com/problemset/problem/49/A\r\n\r\nsentence = input().strip('?').strip()\r\nvowel = ['A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u', 'Y', 'y']\r\nif(sentence[-1] in vowel):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input()\r\ns = s.rstrip('?')\r\ns = s.rstrip(' ')\r\nsp = s[-1]\r\nif sp == 'a' or sp == 'e' or sp == 'i' or sp == 'o' or sp == 'u' or sp == 'y' or sp == 'A' or sp == 'E' or sp == 'I' or sp == 'O' or sp == 'U' or sp == 'Y':\r\n print('YES')\r\nelse:\r\n print('NO')", "s = input().lower()\r\nwhile s[-1] not in \"abcdefghijklmnopqrstuvwxyz\":\r\n s = s[:-1]\r\nif s[-1] in \"aeiouy\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "ar = list(input())\r\nvls = ['a','e','i','o','u','y','A','E','I','O','U','Y']\r\nn = len(ar)\r\nind = -2\r\nfor i in range(n-1):\r\n if ar[n-2-i]!=' ':\r\n ind = n-2-i\r\n break\r\nif ar[ind] in vls:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "print('YES' if ''.join(list(input().lower().split()))[-2] in 'aeiouy' else 'NO')\r\n#author:SK__Shanto__㋛\r\n#code__define__your__smartness", "x=input()\r\nfor i in reversed(x):\r\n if i==\" \" or i==\"?\":\r\n continue\r\n else:\r\n string=i\r\n break\r\nv=[\"A\",\"E\",\"E\",\"O\",\"U\",\"Y\",\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]\r\nif string in v:print(\"YES\")\r\nelse:print(\"NO\")\r\n", "\r\nfrom collections import defaultdict, deque\r\nimport collections, math\r\nfrom concurrent.futures import thread\r\nimport heapq\r\nfrom operator import indexOf\r\nimport sys, threading\r\nmod = 1000000007\r\nimport math\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 run():\r\n sentence = get_string()\r\n sentence = \"\".join(sentence.split()).lower()\r\n sets = {\"a\", \"e\", \"i\", \"o\", \"u\", \"y\"}\r\n \r\n if sentence[-2] in sets:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\nif __name__ == '__main__':\r\n threading.stack_size(1 << 27)\r\n sys.setrecursionlimit(1 << 30)\r\n main_thread = threading.Thread(target=run)\r\n main_thread.start()\r\n main_thread.join()", "line = input()\r\nvowel = \"aeiouyAEIOUY\"\r\nfor i in range(len(line) - 1, -1, -1):\r\n if line[i].isalpha():\r\n if line[i] in vowel:\r\n print('YES')\r\n else:\r\n print('NO')\r\n break", "s1 = input()\ns1 = ''.join(e for e in s1 if e.isalpha())\nv = [\"A\", \"E\", \"I\", \"O\", \"U\", \"Y\", \"a\", \"e\", \"i\", \"o\", \"u\", \"y\"]\nif s1[-1] in v:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t\t\t \t \t \t \t\t \t \t\t \t \t \t\t\t \t\t", "vowels = \"aeiouy\"\r\nconsonants = \"bcdfghjklmnpqrstvwxyz\" \r\nquestion = input().lower().replace(' ', '')\r\nlast_letter = question[-2]\r\nif last_letter in vowels:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "if input().lower().replace(\" \", \"\")[-2] in 'aeiouy':\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n", "vowels = ['a', 'e', 'i', 'o', 'u', 'y']\r\n\r\ndef sleuth(s):\r\n lastLetter = \"\"\r\n for char in s:\r\n if char == '?':\r\n return lastLetter\r\n if char != \" \":\r\n lastLetter = char.lower()\r\n return lastLetter\r\n \r\ns = input()\r\nprint(\"YES\" if sleuth(s) in vowels else \"NO\")", "# LUOGU_RID: 99686365\nimport string\n\nd='AEIOUY'\nn=input()\nfor i in range(len(n)):\n if n[len(n)-1-i].isalpha():\n k=n[len(n)-1-i]\n break\nk=k.upper()\nif k in d:\n print('YES')\nelse:\n print('NO')", "vowels = ['a','e','i','o','u','y']\r\ncons = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','z']\r\n\r\nques = input().lower()\r\nlst = list(ques)\r\nnew_ques = []\r\nfor i in lst:\r\n if i != ' ':\r\n new_ques.append(i)\r\n\r\n\r\nif new_ques[len(new_ques)-2] in vowels:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def vowel(c):\n s = \"AEIOUY\"\n if c.upper() in s:\n return True\n return False\n\ns = input()\nn = len(s)-1\nwhile(n>=0):\n if(s[n] not in \" ?\"):\n if(vowel(s[n])):\n print(\"YES\")\n else:\n print(\"NO\")\n exit()\n n -= 1\n", "vowels = \"aeiouy\"\nalpha = 'abcdefghijklmnopqrstuvwxyz'\nlower = input()\nline = ''\nquestion = lower.lower()\nfor i in question:\n if i in alpha:\n line += i\n\nif line[-1] in vowels:\n print(\"YES\")\n \nelse:\n print('NO')\n \t \t \t\t\t \t \t \t\t \t\t \t\t\t\t", "line = input().split()\r\n \r\nif line[-1] == '?':\r\n end = line[-2]\r\nelse:\r\n end = line[-1][:len(line[-1]) - 1]\r\n \r\nif end[-1].lower() in \"aeiouy\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") \r\n", "s=input()\r\ns=s.split()\r\n\r\nZ=[]\r\nfor i in s:\r\n Z.append(i)\r\nif(str(Z[-1])=='?'):\r\n p=str(Z[-2])\r\n if((p[-1]=='a')or(p[-1]=='e')or(p[-1]=='i')or(p[-1]=='o')or(p[-1]=='u')or(p[-1]=='y')or(p[-1]=='A')or(p[-1]=='E')or(p[-1]=='I')or(p[-1]=='O')or(p[-1]=='U')or(p[-1]=='Y')):\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n p=str(Z[-1])\r\n if((p[-2]=='a')or(p[-2]=='e')or(p[-2]=='i')or(p[-2]=='o')or(p[-2]=='u')or(p[-2]=='y')or(p[-2]=='A')or(p[-2]=='E')or(p[-2]=='I')or(p[-2]=='O')or(p[-2]=='U')or(p[-2]=='Y')):\r\n print('YES')\r\n else:\r\n print('NO')\r\n\r\n ", "s=input()\r\nv=['a','e','i','o','u','y','A','E','I','O','U','Y']\r\ni=-1\r\nwhile(1):\r\n if s[i]!='?' and s[i]!=' ':\r\n if(s[i] in v):\r\n print('YES')\r\n else:\r\n print('NO')\r\n break\r\n else:\r\n i-=1", "IL = lambda: list(map(int, input().split()))\r\n\r\ns = input()\r\nprint('YES' if s.lower().strip(' ?')[-1] in 'aeiouy' else 'NO')", "n=input()\r\nn=n[::-1]\r\nk='i'\r\n# print(n)\r\nfor i in n:\r\n # print(i)\r\n if i.isalpha():\r\n # print(i)\r\n k=i.lower()\r\n break\r\n# print(k)\r\nif k=='a' or k=='i' or k=='e' or k=='o' or k== 'u' or k=='y':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "vowels = ['a','e','i','o','u','y','A','E','I','O','U','Y']\r\nquestion,pure_word = input(),''\r\nquestion = question.split()\r\nfor t in question:\r\n pure_word+=t\r\nif pure_word[-2] in vowels:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "# Sleuth\r\nvowels = ['A', 'E', 'I', 'O', 'U', 'Y']\r\nconconents = ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L',\r\n 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Z']\r\n\r\nstring = input()\r\n\r\ni = len(string) - 1\r\nwhile i >= 0:\r\n if string[i].isalpha():\r\n if string[i].upper() in vowels:\r\n print('YES')\r\n else:\r\n print('NO')\r\n break\r\n\r\n i -= 1\r\n", "s: str = input()[:-1].strip()[-1]\r\n# print(s)\r\nif s.lower() in 'aeiouy':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = input()\r\na = a.lower()\r\na = a.replace(\" \" , \"\")\r\nif(a[len(a)-2] == \"a\" or a[len(a)-2] == \"e\" or a[len(a)-2] == \"i\" or a[len(a)-2] == \"o\" or a[len(a)-2] == \"u\" or a[len(a)-2] == \"y\"):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") \r\n\r\n\r\n\r\n\r\n", "a=input()\r\nb=a.split()\r\nif b[-1]=='?':\r\n b.pop(-1)\r\n n=b[-1][-1]\r\n n=n.lower()\r\n if n=='a' or n=='i' or n=='o' or n=='e' or n=='u' or n=='y':\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n c=b[-1]\r\n n=c[-2]\r\n n=n.lower()\r\n if n=='a' or n=='i' or n=='o' or n=='e' or n=='u' or n=='y':\r\n print('YES')\r\n else:\r\n print('NO')", "s=input()\r\ns=s.upper()\r\ns=s.replace('?',\"\")\r\ns=s.strip()\r\nv=\" AEIOUY\";\r\nc=\"BCDFGHJKLMNPQRSTVWXZ\";\r\nif s[-1] in v:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def sleuth(s):\n res = \"\"\n ready = False\n\n for i in range(1, len(s)+1):\n if ready:\n if s[-i].isalpha():\n res = s[-i].lower()\n break\n if s[-i] == \"?\":\n ready = True\n\n if res in [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]:\n return \"YES\"\n return \"NO\"\n\nprint(sleuth(input()))", "a = ''.join(input().lower().split())\r\nprint(\"YES\" if a[-2] in 'aeiouy'else \"NO\")\r\n", "# A. Sleuth\n\nvowels = ['A', 'E', 'I', 'O', 'U', 'Y']\nconsonants = ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Z']\n\nch = input().strip(' ?')[-1]\nif ch.upper() in vowels:\n print(\"YES\")\nelif ch.upper() in consonants:\n print(\"NO\")\n", "\r\nquestion = input()[::-1]\r\n\r\nfor letter in question:\r\n\tif letter == '?' or letter == ' ':\r\n\t\tcontinue\r\n\telif letter == 'a' or letter == 'A' or letter == 'e' or letter == 'E' or letter == 'i' or letter == 'I' or letter == 'o' or letter == 'O' or letter == 'u' or letter == 'U' or letter == 'y' or letter == 'Y':\r\n\t\tprint (\"YES\")\r\n\t\tbreak\r\n\telse :\r\n\t\tprint (\"NO\") \r\n\t\tbreak\r\n", "s = input()\r\nc = \"\"\r\nv = \"AEIOUYaeiouy\"\r\nfor i in s:\r\n if i.isalpha():\r\n c = i\r\nif v.find(c) != -1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "#49A (30No. Problem A)\r\n\r\nques = input().replace(\" \",\"\").lower()\r\nlastLetter = ques[len(ques) - 2]\r\nif ( lastLetter == 'a' or lastLetter == 'e' or lastLetter == 'i' or lastLetter == 'o' or lastLetter == 'u' or lastLetter == 'y'):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") \r\n", "s = input()[:-1].strip()[-1].lower()\n\na = [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]\n\nprint(\"YES\" if s in a else \"NO\")", "s = input()\r\ns=\"\".join(s.split())\r\nx=s[len(s)-2]\r\nif x=='a' or x=='e' or x=='i' or x=='o' or x=='u' or x=='y' or x=='A' or x=='E' or x=='I' or x=='O' or x=='U' or x=='Y':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def ans(c):\r\n c = c.strip('?').rstrip()\r\n ll = c[-1].lower()\r\n if ll in 'aeiouy':\r\n return \"YES\"\r\n else:\r\n return \"NO\"\r\ns = input()\r\na = ans(s)\r\nprint(a)", "vowels = {'a', 'e', 'i', 'o', 'u', 'y'}\n\ndef last_letter(line):\n line_len = len(line)\n for j in range(1, line_len+1):\n if line[-1*j].isalpha():\n return line[-1*j]\n\nline = input().strip().lower()\n\nif last_letter(line) in vowels:\n print('YES')\nelse:\n print('NO')\n", "s=input()\r\nvowel='aeiouyAEIOUY'\r\n\r\ns1=''\r\nfor i in range(len(s)):\r\n if s[i]!=' ':\r\n s1+=s[i]\r\n\r\nans='YES' if s1[-2] in vowel else 'NO'\r\n\r\nprint(ans)", "s = input().replace(' ', '')\r\nif s[len(s) - 2] == 'a' or s[len(s) - 2] == 'e' or s[len(s) - 2] == 'o' or s[len(s) - 2] == 'u' or s[len(s) - 2] == 'y' or s[len(s) - 2] == 'A' or s[len(s) - 2] == 'E' or s[len(s) - 2] == 'O' or s[len(s) - 2] == 'U' or s[len(s) - 2] == 'Y':\r\n print('YES')\r\nelse:\r\n print('NO')", "s=input().replace(' ','')\r\nsoglasny=('a','e','i','o','u','y')\r\nif s[-2].lower() in soglasny:\r\n print('YES')\r\nelse:print('NO')", "s=input()\r\nl=len(s)\r\ni=l-1\r\nwhile i>=0:\r\n if s[i]>='a' and s[i]<='z':\r\n if s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u' or s[i]=='y':\r\n print('YES')\r\n else:\r\n print('NO')\r\n break\r\n elif s[i]>='A' and s[i]<='Z':\r\n if s[i]=='A' or s[i]=='E' or s[i]=='I' or s[i]=='O' or s[i]=='U' or s[i]=='Y':\r\n print('YES')\r\n else:\r\n print('NO')\r\n break\r\n i=i-1\r\n \r\n ", "s = [ x for x in list(input()[::-1]) if x.isalpha()][0].lower()\r\nif s in [\"a\", \"e\", \"i\", \"o\", \"u\", \"y\"]:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def solve():\n n = input()\n for i in n[::-1]:\n if i.lower() in \"qwertyuiopasdfghjklzxcbnmv\":\n return \"YES\" if i.lower() in \"aeiuoy\" else \"NO\"\n\nprint(solve())\n", "s = input().lower()\r\nindex = -1\r\nar = [chr(i) for i in range(97, 123)]\r\nwhile s[index] not in ar:\r\n index -= 1\r\nar1 = ['a', 'e', 'u', 'i', 'o', 'y']\r\nar2 = []\r\nfor i in range(97, 123):\r\n if chr(i) not in ar1:\r\n ar2.append(chr(i))\r\nif s[index] in ar1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "s = input()\r\nv = {'a', 'e', 'i', 'o', 'u', 'y'}\r\n\r\nn = len(s)\r\n\r\nfor c in reversed(s):\r\n if c != ' ' and c != '?':\r\n if c.lower() in v:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break", "stri=list(filter(lambda x:x.isalnum(),input().strip()))\r\nvowe=[\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]\r\nif stri[-1].lower() in vowe:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\") ", "C = input().split()\r\nif len(C[-1]) > 1:\r\n C = C[-1][-2]\r\nelse:\r\n C = C[-2][-1]\r\n\r\nif C.lower() == 'a' or C.lower() == 'e' or C.lower() == 'i' or C.lower() == 'u'or C.lower() =='o' or C.lower() == 'y':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") ", "'''input\nIs it an apple and a banana simultaneouSLY?\n''' \n\ndef main(): \n\n s = [i for i in input() if i not in \" ?\"]\n\n if s[-1] in \"aeiouyAEIOUY\":\n print(\"YES\")\n else:\n print(\"NO\")\n\nif __name__ == \"__main__\": \n main()", "from math import sqrt\r\n\r\n\r\ndef main():\r\n n = input()\r\n d = [c for c in n if c.isalpha()]\r\n if d[-1].lower() in \"aeiouy\":\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "s=input()\r\nv=\"AEIOUYaeiouy\"\r\nl=[]\r\nfor i in s[::-1]:\r\n if i !=\" \" and i!=\"?\":\r\n if i in v:\r\n print(\"YES\")\r\n exit()\r\n else:\r\n print(\"NO\")\r\n exit()\r\n ", "q=input()\r\nl=q.replace(\" \",\"\")[-2:-1]\r\nprint(\"YES\" if l.upper() in ['A','E','I','O','U','Y'] else \"NO\")\r\n", "s = input()\r\ns = s.replace(\"?\",\"\")\r\ns = s.strip()\r\nif s[len(s)-1] == 'A' or s[len(s)-1] == 'E' or s[len(s)-1] == 'I' or s[len(s)-1] == 'O' or s[len(s)-1] == 'U' or s[len(s)-1] == 'Y' or s[len(s)-1] == 'a' or s[len(s)-1] == 'e' or s[len(s)-1] == 'i' or s[len(s)-1] == 'o' or s[len(s)-1] == 'u' or s[len(s)-1] == 'y':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=input()\r\nfor i in range(len(n)-1,-1,-1):\r\n if n[i]>=\"a\" and n[i]<=\"z\" or n[i]>=\"A\" and n[i]<=\"Z\":\r\n if n[i] in [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\",\"U\",\"A\",\"E\",\"I\",\"O\",\"Y\"]:\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break", "a = list(map(str, input()))\r\ns = \"aeiouyAEIOUY\"\r\ni = -2\r\nwhile a[i] == \" \":\r\n i -= 1\r\nprint(\"YES\" if a[i] in s else \"NO\")", "n=input().rstrip(' ?')\r\nv=['a','e','i','o','u','y','A','E','I','O','U','Y']\r\ni=n[-1]\r\nif i in v:\r\n print('YES')\r\nelse:\r\n print('NO')", "ques = input()\r\nfor i in ques[::-1]:\r\n if i.isalpha():\r\n if i in \"aeiouyAEIOUY\":\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break\r\n\r\n\r\n\r\n\r\n", "n = input().split()\r\nif n == ' ':\r\n print('NO')\r\n exit()\r\nif n[-1] == '?':\r\n if n[-2][-1] in 'aeiouyAEIOUY':\r\n print('YES')\r\n exit()\r\nelif n[-1][-1] == '?':\r\n if n[-1][-2] in 'aeiouyAEIOUY':\r\n print('YES')\r\n exit()\r\nprint('NO')\r\n# codeforcesian\r\n# happy new year ;)\r\n# sajjad - mehrdad - zahra - parisa - javad - lorenzo\r\n# amirhosein - mohsen - mahdi - mahmoud - alireza\r\n# dige che khabar\r\n# ♥\r\n", "s=input()\r\nnewstr=\"\"\r\nfor i in range (0,len(s)):\r\n if(s[i]==\" \"):\r\n newstr=newstr+\"\"\r\n else:\r\n newstr=newstr+s[i]\r\nlength=len(newstr)\r\nif newstr[length-2] in 'AEIOUYaeiouy':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n", "a = input()\r\nb = a.replace(\" \",\"\")\r\nif(b[len(b)-2] == \"A\" or b[len(b)-2] == \"E\" or b[len(b)-2] == \"I\" or b[len(b)-2] == \"O\" or b[len(b)-2] == \"U\" or b[len(b)-2] == \"Y\"):\r\n print(\"YES\")\r\nelif(b[len(b)-2] == \"a\" or b[len(b)-2] == \"e\" or b[len(b)-2] == \"i\" or b[len(b)-2] == \"o\" or b[len(b)-2] == \"u\" or b[len(b)-2] == \"y\"):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n ", "import string\r\n\r\ninp = list(input().upper())\r\n\r\nwhile inp[-1] not in string.ascii_uppercase:\r\n inp.pop()\r\n\r\nif inp[-1] in 'AEIOUY':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "print(\"YES\" if list(filter(lambda x: x != ' ', input().lower()))[-2] in \"aiueoy\" else \"NO\")", "s = input()\r\ns1=s.split(' ')\r\nl = \"\".join(s1).upper()\r\na = ['A', 'E', 'I', 'O', 'U', 'Y']\r\nif l[-2] in a:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input().replace(' ', '')\r\nvowels, ln = 'aAeEiIoOuUyY', len(s)\r\nprint('YES' if s[ln-2] in vowels else 'NO')", "# import sys\r\n# sys.stdin=open(\"input.in\",\"r\")\r\nl=input()\r\nc=l[:-1].strip().upper()[-1]\r\nif c in [\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\"]:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "for i in input().upper()[::-1]:\r\n if i.isalpha():\r\n print('YES') if i in 'AEIOUY' else print('NO')\r\n break", "a = input()\r\nc = -1\r\nb = a[c]\r\nwhile b == \"?\" or b == \" \":\r\n c = c - 1\r\n b = a[c]\r\nif b == \"a\" or b == \"e\" or b == \"i\" or b == \"o\" or b == \"u\" or b == \"y\" or b == \"A\" or b == \"E\" or b == \"I\" or b == \"O\" or b == \"U\" or b == \"Y\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\nexit()\r\n", "s=input()\r\nlis=list(s.split(\" \"))\r\nlis2=[]\r\nn=len(lis)\r\n\r\nm=0\r\nlis1=['a','e','i','o','u','y','A','E',\"I\",\"O\",'U',\"Y\"]\r\n\r\nfor i in range(len(lis)):\r\n for ele in lis:\r\n if ele==\"\":\r\n lis.remove(ele)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nif lis[len(lis)-1]!=\"?\" and lis[len(lis)-1]!=\"\":\r\n x=len(lis[len(lis)-1])\r\n y=lis[len(lis)-1][x-2]\r\n\r\n\r\n if y in lis1:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nif lis[len(lis)-1]==\"?\":\r\n z=len(lis[len(lis)-2])\r\n\r\n z1=lis[len(lis)-2][z-1]\r\n\r\n if z1 in lis1:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\n", "def findSymbol(line):\r\n for i in range(len(line) - 1, -1, -1):\r\n if line[i] == ' ' or line[i] == '?':\r\n continue\r\n return line[i]\r\n return None\r\n\r\n\r\nsymbol,pattern = findSymbol(input()),\"aeiouyAEIOUY\"\r\nprint(\"YES\" if symbol in pattern else \"NO\")\r\n", "n=input()\r\nv=\"aeiouyAEIOUY\"\r\nv=list(v)\r\nn=list(n)\r\nn.remove(\"?\")\r\nk=len(n)-1\r\nt=n[k]\r\nwhile(t==\" \"):\r\n k=k-1 \r\n t=n[k]\r\nif t in v:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=input()\r\ns=s.lower()\r\ns=\"\".join(s.split())\r\nif s[len(s)-2] in [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "v=['a', 'e', 'i', 'o', 'u', 'y']\ns=input()\ns=s[:-1]\ns=s.strip()\nprint('YES' if s[-1].lower() in v else 'NO')\n\n", "s = ''.join(input().split()).lower()\r\nif s[-2] in ['a', 'e', 'i', 'o', 'u', 'y']:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "s = input().replace(\" \", \"\")\r\nif s[len(s)-2] in 'AEIOUYaeiouy':\r\n print('YES')\r\nelse: print('NO')", "s = input()\r\nfor i in range(len(s)-1,-1,-1):\r\n if s[i]!='?' and s[i]!=' ':\r\n if s[i] in 'aeiouy' or s[i] in 'AEIOUY':\r\n print('YES')\r\n break\r\n else:\r\n print('NO')\r\n break", "a = list(\"AEIOUY\")\r\n\r\ns = input()\r\n\r\nfor i in range(len(s) - 1, -1, -1):\r\n if s[i].isalpha():\r\n if s[i].upper() in a:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break\r\n\r\n", "p=input()\r\nq=p.replace(\" \",\"\")\r\nfor i in p:\r\n if q[-2] in \"aeiouyAEIOUY\":\r\n outcome=\"YES\"\r\n elif q[-2] in \"aieouyAEIOUY\":\r\n outcome=\"YES\"\r\n else:\r\n outcome=\"NO\"\r\nprint(outcome)", "s=input()\r\ns=s.lower()\r\ns=s.split()\r\nif(s[-1]=='?'):\r\n if(s[-2][-1] in 'aeiouy'):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n if(s[-1][-2] in 'aeiouy'):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "a=(input().strip()).lower()\r\nvowels='aeiouy'\r\nif a[-1]=='?':\r\n if a[-2] in vowels:\r\n print ('YES')\r\n elif a[-2] not in vowels:\r\n if a[-2]==' ':\r\n k=-2\r\n for i in range(len(a)):\r\n if a[k]==' ':\r\n k-=1\r\n else:\r\n if a[k] in vowels:\r\n print ('YES')\r\n break\r\n else:\r\n print ('NO')\r\n break\r\n else:\r\n print ('NO')", "def main(s):\n return \"NO\" if ''.join(''.join(s.lower().strip().split(' ')).split('?'))[-1] not in set(['a', 'e', 'i', 'o', 'u', 'y']) else \"YES\"\n\n\nprint(main(input()))\n", "a, i= list(reversed(list(input().lower()))), 0\nwhile a[i] == '?' or a[i] == ' ':\n\ti += 1\nprint('YES' if a[i] in 'aiueyo' else 'NO')", "s=input().lower()\r\ns=s.strip('?')\r\ns=s.strip()\r\nif s[-1]=='a'or s[-1]=='e' or s[-1]=='i' or s[-1]=='o' or s[-1]=='u' or s[-1]=='y':\r\n print('YES')\r\nelse:\r\n print('NO')\r\n\r\n", "s = input()\r\nlst = []\r\nfor i in s:\r\n if i != \" \" and i != \"?\":\r\n lst.append(i)\r\nif lst[-1] in \"AEIOUYaeiouy\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "# Sleuth\ns = input()\nvowels = \"aeiouyAEIOUY\"\nfor i in range(len(s)-1,-1,-1):\n if s[i].isalpha():\n if s[i] in vowels:\n print(\"YES\")\n break\n else:\n print(\"NO\")\n break\n", "s = input()\ns = ''.join(s.split())\nd1 = 'AEIOUY'\nd2 = 'BCDFGHJKLMNPQRSTVWXZ'\nif s[-2].upper() in d1:\n print('YES')\nelse:\n print('NO')\n", "question = input()\r\n\r\nprint(\"YNEOS\"[question[:-1].rstrip()[-1].lower() not in \"aeiouy\" :: 2])\r\n\r\n# vowel = [\"A\", \"E\", \"I\", \"O\", \"U\", \"Y\"]\r\n# consonant = [\r\n# \"B\",\r\n# \"C\",\r\n# \"D\",\r\n# \"F\",\r\n# \"G\",\r\n# \"H\",\r\n# \"J\",\r\n# \"K\",\r\n# \"L\",\r\n# \"M\",\r\n# \"N\",\r\n# \"P\",\r\n# \"Q\",\r\n# \"R\",\r\n# \"S\",\r\n# \"T\",\r\n# \"V\",\r\n# \"W\",\r\n# \"X\",\r\n# \"Z\",\r\n# ]\r\n\r\n# alphabet = vowel + consonant\r\n\r\n# for i in range(len(question) - 1, -1, -1):\r\n# if question[i].upper() in alphabet:\r\n# if question[i].upper() in vowel:\r\n# print(\"YES\")\r\n# else:\r\n# print(\"NO\")\r\n# break\r\n", "s=input()\r\nl=len(s)\r\ns=s[::-1]\r\nfor i in range(1,l):\r\n if s[i]!=\" \":\r\n if s[i]==\"a\" or s[i]==\"e\" or s[i]==\"i\" or s[i]==\"o\" or s[i]==\"u\" or s[i]==\"y\" or s[i]==\"A\" or s[i]==\"E\" or s[i]==\"I\" or s[i]==\"O\" or s[i]==\"U\" or s[i]==\"Y\":\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break\r\n else:\r\n continue\r\n", "n = input()\r\na = \"aeiouy\"\r\n\r\nn = n.lower()\r\nn = n.replace(\" \",\"\")\r\nn = n.replace(\"?\",\"\")\r\n\r\n\r\nif n[-1] in a:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\r\n", "#rOkY\r\n#FuCk\r\n\r\n################################## kOpAl #####################################\r\n\r\ng=str(input())\r\ns=g.lower()\r\n\r\nx=''\r\nfor i in range(0,len(s),1):\r\n if(97<=ord(s[i]) and ord(s[i])<=122):\r\n x=s[i]\r\n\r\nif(x=='a' or x=='e' or x=='i' or x=='o' or x=='u' or x=='y'):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "\r\na = input()\r\na = a.replace(' ','')\r\nVowels = 'aeiouyAEIOUY'\r\nif a[-2] in Vowels:\r\n print('YES')\r\nelse:\r\n print('NO')", "n = (input().strip(\"?\"))\r\nn = n.split()\r\na = list(n[len(n)-1])\r\nl = [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\",\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\"]\r\nflag = 0\r\nfor i in range(len(l)):\r\n\tif a[len(a)-1]==l[i]:\r\n\t\tflag = 1\r\n\t\tprint(\"YES\")\r\n\t\tbreak\t\r\nif flag==0:\r\n\tprint(\"NO\")\t\t", "vowels = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I','O','U', 'Y']\r\ns= input()\r\ns = s.replace(s[len(s)-1], '')\r\ns = s.strip()\r\nif s[len(s) -1] in vowels:\r\n print('YES')\r\nelse:\r\n print('NO')", "s= input().split()\r\n\r\nt= s[-1]\r\nif t=='?':\r\n m= s[-2]\r\n if m[-1].lower()=='a' or m[-1].lower()=='e' or m[-1].lower()=='i' or m[-1].lower()=='o' or m[-1].lower()=='u' or m[-1].lower()=='y':\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n m=t[-2]\r\n if m.lower()=='a' or m.lower()=='e' or m.lower()=='i' or m.lower()=='o' or m.lower()=='u' or m.lower()=='y':\r\n print('YES')\r\n else:\r\n print('NO')\r\n", "s = input()\r\ns = s.lower()\r\nx = ['a','e','i','o','u','y']\r\n\r\nfor i in s[::-1]:\r\n p = ord(i)\r\n if p>96 and p<123:\r\n if i in x:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break", "s = list(input())\r\nV = ['A','a','E','e','I','i','O','o','U','u','Y','y']\r\n\r\nfor i in s[::-1]:\r\n if i.isalpha():\r\n if i in V:\r\n print('YES')\r\n break\r\n\r\n else:\r\n print('NO')\r\n break\r\n \r\n else: continue", "s = input()\r\nvov = ['a','e','i','o','u','y']\r\nlast = None\r\nfor i in s:\r\n if i.isalpha():\r\n last = i\r\nif last.lower() in vov:\r\n print('YES')\r\nelse:\r\n print('NO')", "vowels= [\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\"]\nconstants=[\"B\",\"C\",\"D\",\"F\",\"G\",\"H\",\"J\",\"K\",\"L\",\"M\",\"P\",\"Q\",\"R\",\n \"S\",\"T\",\"V\",\"W\",\"X\",\"Z\"]\ngube= input()\ngubee=(''.join(gube.split())).upper()\nuwu=gubee[-2]\nif uwu in vowels:\n print(\"YES\")\nelse:\n print(\"NO\")", "print(\"YES\" if input().lower().strip(' ?')[-1] in 'aeiouy' else \"NO\")\r\n", "print(\"YES\" if (input().replace(\"?\",\" \")).replace(\" \",\"\")[-1].lower() in \"aeiouy\" else \"NO\")", "s=input()\r\ns1=\"aeiouy\"\r\nx=len(s)-2\r\nif s[x]!=' ':\r\n y=s[x].lower()\r\n if y in s1:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n l=s.split()\r\n m=l[len(l)-2]\r\n lett=m[len(m)-1]\r\n lett.lower()\r\n if lett in s1:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "n=input()\r\nc=0\r\nn=n.upper()\r\ns='AEIOUY'\r\nn=n.replace(' ','')\r\nif n[-2] in s:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "s = input()\r\nfor i in s[::-1]:\r\n if not i.isalpha():\r\n continue\r\n \r\n if i.lower() in 'aeiouy':\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break", "print('YES' if input().replace(' ', '').casefold()[-2] in ['a', 'e', 'i', 'o', 'u', 'y'] else 'NO')", "a = input()\r\nvo = ['a','e','i','o','u','y','A','E','I','O','U','Y']\r\nfor i in range(len(a)-1,-1,-1):\r\n if(a[i]==' ' or a[i]=='?'):\r\n continue\r\n else:\r\n if(a[i] in vo):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break", "\nstring = input()\n\nl = [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]\nm = [\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\"]\n\ndef remove(string):\n\treturn string.replace(\" \", \"\")\n\t\n\nx = remove(string)\n#print(x)\nk = len(x)\n\n#print(x[k-2])\n\nif x[k-2] in l:\n print(\"YES\")\n\nelif x[k-2] in m:\n print(\"YES\")\nelse:\n print(\"NO\")", "print('YES' if input().replace('?', '').replace(' ', '')[-1].lower() in 'aeiouy' else 'NO')\r\n", "def main():\n from re import sub\n question = sub(r'[\\s?]', '', input()).upper()\n last_char = question[-1]\n\n print('YES' if last_char in 'AEIOUY' else 'NO')\n\n\nif __name__ == '__main__':\n main()\n", "s = input().strip().lower()\r\n\r\nfor i in range(len(s) - 1, -1, -1):\r\n if s[i].isalpha():\r\n if s[i] in 'aeiouy':\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break\r\n", "sentence = list(map(str,input().split()))\r\nif sentence[-1] == '?':\r\n if sentence[-2][-1].lower() in ['a', 'e', 'i', 'o', 'u', 'y']:\r\n print('YES')\r\n else:\r\n print('NO')\r\n \r\nelse:\r\n if sentence[-1][-2].lower() in ['a', 'e', 'i', 'o', 'u', 'y']:\r\n print('YES')\r\n else:\r\n print('NO')", "question = input().rstrip(\"?\").rstrip()\r\nlast_letter = question[-1].lower()\r\n\r\nif last_letter in ['a', 'e', 'i', 'o', 'u', 'y']:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "q = input().lower()\r\nq = q.replace(\" \", \"\").replace(\"?\",\"\")\r\nif \"simultaneously\" in q:\r\n q.replace(\"simultaneously\", \"\")\r\nif q[-1] in [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = ['A', 'E', 'I', 'O', 'U', 'Y']\r\ns = input().upper().rstrip('?').split()\r\nprint('YES' if s[-1][-1] in a else 'NO')", "s=(input().split('?')[-2]).strip()\r\nprint('YES') if s[-1].lower() in ['a','e','i','o','u','y'] else print('NO') ", "s = input()\r\ns = s[::-1]\r\nfor i in range(1,len(s)):\r\n if s[i]!=' ':\r\n if s[i] in 'a,e,i,o,u,y,A,E,I,O,U,Y':\r\n print('YES')\r\n else:\r\n print('NO')\r\n exit()\r\n else:\r\n continue\r\n", "a=input()\r\nif \"?\" or \" \" in a:\r\n r=a.replace(\"?\",\"\")\r\n s=r.replace(\" \",\"\")\r\n list=[\"a\",\"A\",\"E\",\"e\",\"I\",\"i\",\"O\",\"o\",\"U\",\"u\",\"y\",\"Y\"]\r\n if s[-1] in list:\r\n print (\"YES\")\r\n else:\r\n print (\"NO\")", "s=input()\r\ns=s.upper()\r\nl = ['A','E','O','U','Y','I']\r\ni = len(s)-1\r\nwhile i>=0:\r\n if s[i]!= ' ' and s[i]!='?':\r\n if s[i] in l:\r\n print('YES')\r\n break\r\n else:\r\n print('NO')\r\n break\r\n i-=1\r\n\r\n ", "string = input()\nar = []\nar = string.split('?')\nstrnew = ar[0]\narnew = strnew.split()\nfinals = arnew[len(arnew)-1]\nvowel = ['A', 'E', 'I', 'O', 'U', 'Y']\nflen = len(finals)\nans = finals[flen-1]\nans = ans.upper()\nif(ans in vowel):\n print(\"YES\")\nelse:\n print(\"NO\")\n\n\t \t \t\t \t\t\t\t\t \t\t \t \t \t \t\t\t \t \t", "vowels = \"AEIOUY\"\r\nq = input()\r\nl = ''\r\nfor i in q:\r\n if i.isalpha():l= i\r\nif l.upper() in vowels:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "s=input()\r\nx=\"\"\r\ns=s[0:].lower()\r\nfor i in reversed(range((len(s)))):\r\n \r\n if s[i].isalpha():\r\n x+=s[i]\r\n break\r\n\r\nif(x==\"a\"or x==\"e\" or x==\"i\"or x==\"o\"or x==\"u\"or x==\"y\"):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n#print(x) ", "if input().replace(\" \",\"\")[-2].upper() in ['A', 'E', 'I', 'O', 'U', 'Y']: print(\"YES\")\r\nelse : print(\"NO\")", "ip = ((input().replace(' ', '')).replace('?', '')).lower()\r\nl = len(ip)\r\nvowel = ('a', 'e', 'i', 'o', 'u', 'y')\r\nif ip[l - 1] in vowel : \r\n print(\"YES\")\r\n\r\nelse : \r\n print(\"NO\")\r\n", "ans = \"\".join(input().strip().split())[-2]\nprint(\"YES\" if ans in \"AaEeIiOoUuYy\" else \"NO\")\n", "print(\"YES\") if input().replace(\" \",\"\").replace(\"?\",\"\")[-1].lower() in \"aeiouy\" else print(\"NO\")", "import re\n\ntest_case = str(input()).lower()\n\na = ['a', 'e', 'i', 'o', 'u', 'y']\n\nclean_test_case = re.sub(\"[^a-z]\", \"\", test_case)\n\nprint(\"YES\" if clean_test_case[-1] in a else \"NO\")\n", "def solve(a):\r\n while a[-1] in [\" \", \"?\"]:\r\n a = a[:-1]\r\n if a[-1] in [\"a\",\"e\",\"i\",\"o\",\"u\",\"A\",\"E\",\"I\",\"O\",\"U\", \"y\",\"Y\"]:\r\n return \"YES\"\r\n return \"NO\"\r\n\r\n# m,n = map(int,input().split())\r\n# for _ in range(int(input())):\r\na = input()\r\nprint(solve(a))\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "s=input()\r\ns=s[:-1]\r\ns=s.rstrip()\r\ns=s.lower()\r\nif(s[-1]in ['a','e','i','o','u','y']):\r\n print('YES')\r\nelse:\r\n print('NO')", "n=input()\r\na=n.lower()\r\nb=a.replace(\"?\",\"\")\r\nc=b.replace(\" \",\"\")\r\nif c[-1]==\"a\" or c[-1]==\"e\" or c[-1]==\"i\" or c[-1]==\"o\" or c[-1]==\"u\" or c[-1]==\"y\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()[:-1].split()[-1]\r\nprint('NYOE S'[a[-1]in'aeiouyAEIOUY'::2])", "from string import ascii_lowercase, ascii_uppercase\nascii = ascii_lowercase + ascii_uppercase\ns = input()\nans = None\nfor c in s:\n\tif c not in ascii:\n\t\tcontinue\n\tif c in 'AEIOUYaeiouy':\n\t\tans = 'YES'\n\telse:\n\t\tans = 'NO'\nprint(ans)\n", "f1= ['A', 'E', 'I', 'O', 'U', 'Y']\r\nf2 = '?'\r\ns = input().upper()\r\nn = len(s) - 1\r\n\r\nif s[-1] == f2:\r\n s = s.replace(s[-1] , '' , 1)\r\n\r\nx = s[-1]\r\ni = -1\r\nwhile x == ' ':\r\n x = s[i-1]\r\n i -=1\r\n\r\nif x in f1 :\r\n print('YES')\r\nelse:\r\n print('NO')", "#SLEUTH\r\n#MIAN_TALHA\r\nJ_T = input()\r\nJ_T = J_T.replace(' ','')\r\nVowels = 'aeiouyAEIOUY'\r\nif J_T[-2] in Vowels:\r\n print('YES')\r\nelse:\r\n print('NO')", "question = str(input())\n\nvowels = set(\"AEIOUYaeiouy\")\n\nq = question.index(\"?\")\nq = q - 1\nwhile question[q] == \" \":\n\tq -= 1\nif question[q] in vowels:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\t\t \t \t\t \t\t \t \t\t \t\t \t\t \t \t \t\t", "print(\"YES\" if input().rstrip(\"?\").rstrip(\" \")[-1].lower() in [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"] else \"NO\")", "string = input()\r\ni = len(string) - 2\r\nwhile string[i] == ' ':\r\n i -= 1\r\nif string[i].lower() == 'a' or string[i].lower() == 'e' or string[i].lower() == 'i' or string[i].lower() == 'o' or string[i].lower() == 'u' or string[i].lower() == 'y':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = input().strip()\nv = \"AEIOUY\"\nn = \"\".join(n.split())\n\nif n.upper()[len(n) - 2] in v:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n", "s=input()\r\nl=s[::-1]\r\nq='auioeyAUIOYE'\r\nfor i in range(len(s)):\r\n if(l[i].isalpha()):\r\n if(l[i] in q):\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break\r\n", "Str = input()\r\n\r\nFlag = 0\r\n\r\nfor i in range(len(Str)):\r\n if((Str[i] >= 'a' and Str[i] <= 'z') or (Str[i] >= 'A' and Str[i] <= 'Z')):\r\n if(Str[i] in ['a', 'e', 'i', 'o', 'u','y', 'A', 'E', 'I', 'O', 'U', 'Y']):\r\n Flag = 1\r\n else:\r\n Flag = 0\r\n else:\r\n continue\r\n\r\nif(Flag == 1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n", "s = input()\r\ns = s.replace(\" \",\"\").lower()\r\nvowels = {\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"}\r\n#consonants = {chr(i) for i in range(97,123) if chr(i) not in vowels}\r\nif s[-2] in vowels:\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\")", "s=input()\r\ns=s.replace(\" \", \"\")\r\n#print(s[-2])\r\n\r\nl=['a','e','i','o','u','y']\r\nm=['A','E','I','O','U','Y']\r\na=s[-2]\r\nif(a in l or a in m):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def solution(l1):\r\n l1=[x for x in l1 if x!=\"?\" and x!=\" \"]\r\n vowels=\"aeiouy\"\r\n if l1[-1].lower() in vowels:\r\n return \"YES\"\r\n else:\r\n return \"NO\"\r\ndef answer():\r\n l1 = list(input())\r\n print(solution(l1))\r\nanswer()", "# https://codeforces.com/problemset/problem/49/A\r\n\r\ns = input()\r\n\r\nfor i in s[::-1]:\r\n if i.isalpha():\r\n if i.lower() in 'aeiouy':\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n break\r\n", "glas=\"AEIOUYaeiouy\"\r\nsoglas=\"BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz\"\r\na=input()\r\ns=\"\"\r\nfor i in a:\r\n if i==\" \":\r\n continue\r\n else:\r\n s+=i\r\nif s[-2] in glas:\r\n print(\"YES\")\r\nelif s[-2] in soglas:\r\n print(\"NO\")\r\n", "c=input()\r\nc=c[0:len(c)-1]\r\ns=''\r\nfor i in c:\r\n if i.isspace():\r\n continue\r\n else:\r\n s+=i\r\nif s[len(s)-1] in [\"A\", \"E\", \"I\", \"O\", \"U\", \"Y\",\"u\",\"o\",\"i\",\"e\",\"a\",\"y\"]:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n ", "p=input().lower()\r\np=list(p)[::-1]\r\nfor i in range(len(p)):\r\n if p[i]>=\"a\" and p[i]<=\"z\":\r\n if p[i]==\"a\" or p[i]==\"e\" or p[i]==\"i\" or p[i]==\"o\" or p[i]==\"u\" or p[i]==\"y\":\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break", "question=input()\r\nquestion=question.replace(\"?\",\"\")\r\nquestion=question.strip()\r\nif question[-1].lower() in ['a','e','i','o','u','y']:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=input().split()\r\nif len(s[-1])==1:\r\n if s[-2][-1].lower() in [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n if s[-1][-2].lower() in [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "s1=list(input())\r\ns2=[]\r\nfor c in s1:\r\n if c!=' ':\r\n s2.append(c)\r\nl1=['a','A','e','E','i','I','o','O','u','U','y','Y']\r\nif s2[-2] in l1:\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\")", "s = input()\r\ni = len(s) - 1\r\nv = 'aeiouyAEIOUY'\r\nwhile s[i] == '?' or s[i] == ' ':\r\n i -= 1\r\nif s[i] in v:\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\")", "print('YES' if input().replace(' ', '').lower()[-2] in 'aeiouy' else 'NO')", "print(('NO', 'YES')[input().lower().strip('? ')[-1] in 'aeiouy'])\r\n", "import sys\r\n\r\ns = [el for el in input().split()]\r\nfor i in range(len(s) - 1, -1, -1):\r\n for j in range(len(s[i]) - 1, -1, -1):\r\n if s[i][j].isalpha():\r\n if s[i][j].upper() in (\"A\", \"E\", \"I\", \"O\", \"U\", \"Y\"):\r\n print(\"YES\\n\")\r\n sys.exit()\r\n else:\r\n print(\"NO\\n\")\r\n sys.exit()", "s = input()\r\nk = ['a','e','i','o','u','y','A','E','O','I','U','Y']\r\np = []\r\nfor i in range(len(s)):\r\n if s[i]!=' ':\r\n p.append(i)\r\ntry:\r\n if(s[p[-2]] in k):\r\n print('YES')\r\n else:\r\n print('NO')\r\nexcept:\r\n print('NO')\r\n", "s={\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\"}\r\nstring=list(map(str,input().split()))\r\nif string[-1]==\"?\":\r\n if (string[-2][-1]).upper() in s:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n if string[-1][-2].upper() in s:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "from sys import stdin,stdout\r\nfrom collections import *\r\nfrom math import ceil, floor , log, gcd\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\nINF=float('inf')\r\n\r\ndef solve():\r\n s=input().lstrip().rstrip().split()\r\n i=len(s)-1\r\n while i>=0:\r\n x=s[i]\r\n for j in range(len(x)-1,-1,-1):\r\n if x[j].isalpha():\r\n p=x[j].lower()\r\n if p in 'aeiouy':\r\n pr('YES')\r\n return\r\n else:\r\n pr('NO')\r\n return\r\n i-=1\r\n\r\nfor _ in range(1):\r\n solve()\r\n", "b=[]\r\na=list(input())\r\nfor i in a:\r\n if i.isalpha():\r\n b.append(i)\r\nn=len(b)\r\nif(b[n-1].lower()=='a' or b[n-1].lower()=='e'or b[n-1].lower()=='i'or b[n-1].lower()=='o'or b[n-1].lower()=='u'or b[n-1].lower()=='y'):\r\n print(\"YES\") \r\nelse:\r\n print(\"NO\")\r\n \r\n", "\n\n\n\nlist1 = ['A', 'E', 'I', 'O', 'U', 'Y']\nlist2=['A', 'E', 'I', 'O', 'U', 'Y','B','C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Z']\nk = input()\nk=k.upper()\n\nk = k[::-1]\n\nstr = ''\nfor i in k:\n if i in list2:\n str+=i\n\nif str[0] in list1:\n print('YES')\nelse:\n print('NO')\n\n\n\n\n", "s = input()\r\nvowels = ['a','e','i','o','u','y','A','E','I','O','U','Y']\r\nlist_of_words = [\r\n each.strip()\r\n for each in s[:-1].split()]\r\n# print(list_of_words)\r\nans = \"NO\"\r\nword = list_of_words[-1]\r\nif word[-1] in vowels:\r\n ans = \"YES\"\r\n\r\nprint(ans)\r\n ", "ans = [\"A\",\"O\",\"U\",\"I\",\"E\",\"Y\",\"a\",\"o\",\"u\",\"i\",\"e\",\"y\"]\r\na = list(map(str,input().split()))\r\nif a[-1] == \"?\":\r\n del(a[-1])\r\n if a[-1][-1] in ans: print(\"YES\")\r\n else: print(\"NO\")\r\nelse:\r\n if a[-1][-2] in ans: print(\"YES\")\r\n else: print(\"NO\")", "def main():\r\n vow = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']\r\n s = input()\r\n n = len(s)\r\n for i in range(n-2, -1, -1):\r\n if s[i] == ' ':\r\n continue\r\n elif s[i] in vow:\r\n print('YES')\r\n return\r\n else:\r\n print('NO')\r\n return\r\n\r\n\r\nif __name__ == '__main__':\r\n main()", "import math\r\ndef positions(str): \r\n for i in str: \r\n \r\n # Performing AND operation \r\n # with number 31 \r\n return ((ord(i) & NUM)) \r\n \r\n# Driver code \r\n \r\ndef ii(): return int(input())\r\ndef mi(): return map(int, input().split())\r\ndef li(): return list(mi())\r\na = input()\r\nn = len(a)\r\nj = 0\r\nv = [\"a\",\"A\",\"e\",\"E\",\"i\",\"I\",\"o\",\"O\",\"u\",\"U\",\"y\",\"Y\"]\r\nfor i in range(n):\r\n if a[n-i-1] != \"?\" and a[n-i-1] != \" \":\r\n j = n-i-1\r\n break\r\n# print(j,a[j])\r\nif a[j] in v:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "vowels=[\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]\nc=0\ns=input()\nfor i in range(len(s)-1,-1,-1):\n if s[i].isalpha():\n if s[i].lower() in vowels:\n print(\"YES\")\n break\n else:\n print(\"NO\")\n break\n", "s = input().lower()\r\nfor i in range(len(s)-1,-1,-1):\r\n if s[i].isalpha():\r\n if s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u' or s[i]=='y':\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break\r\n", "a = [i for i in input().strip('?').split()]\r\nc = ['a', 'e', 'i', 'o', 'u', 'y']\r\nif a[-1][-1].lower() in c:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "s=input()\r\nd={'A':0,'E':0,'I':0,'O':0,'U':0,'Y':0,'a':0,'e':0,'o':0,'i':0,'u':0,'y':0}\r\nfor i in range(len(s)-1,-1,-1):\r\n if(s[i].isalpha()):\r\n e=s[i]\r\n break\r\nif(e in d):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "question = input().strip()\nlast_letter = question.replace(\" \", \"\")[:-1].upper()\n\nvowels = ['A', 'E', 'I', 'O', 'U', 'Y']\n\nif last_letter[-1] in vowels:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t \t\t\t\t\t \t \t\t\t \t\t \t\t\t", "\r\nn=input()\r\nn=n.replace(\"?\",\"\")\r\nn=n.split()\r\nl=[\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\",\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]\r\nif(n[-1][-1] in l ):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "s=input('')\r\ns1=s.lower()\r\ni=len(s1)\r\nvowel=['a', 'e','i', 'o','u','y']\r\ni=len(s1)-1\r\n\r\nwhile(i>=0):\r\n if(ord(s1[i])>=97 and ord(s1[i])<=122):\r\n if(s1[i] in vowel):\r\n print('YES')\r\n else:\r\n print('NO')\r\n break;\r\n i-=1\r\n ", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\na=input().strip(\"\\n\").split()\r\nprint(\"YES\" if (a[-1][:-1][-1] if len(a[-1]) > 1 else a[-2][-1]) in \"aeiouyAEIOUY\" else \"NO\")", "s = input()\r\nvowel = ['a', 'e', 'i', 'o', 'u', 'y']\r\ni = len(s) - 1\r\nwhile i >= 0:\r\n if s[i].isalpha():\r\n base = s[i]\r\n break\r\n else:\r\n i -= 1\r\nif base.isupper():\r\n base1 = base.lower()\r\nelse:\r\n base1 = base\r\nif base1 in vowel:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n\r\n", "s=input()\r\ns=s.lower()\r\ns=s.replace(' ','')\r\nvowel='aeiouy'\r\nif s[-2] in vowel:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n ", "c=(input().split(\"?\"))[0].split()[-1][-1]\r\nif(c in \"aeiouyAEIOUY\"): print(\"YES\")\r\nelse: print(\"NO\")\r\n", "s=list(input())\na=['A','E','I','O','U','Y','a','e','i','o','u','y']\nfor i in range(1,len(s)):\n if s[-2]!=' ':\n if s[-2] in a:\n print(\"YES\")\n break\n else:\n print(\"NO\")\n break\n else:\n s[-2]=s[-2-i]\n \t \t \t \t\t\t \t \t\t \t \t", "s=input()\r\ns=s.replace(\" \",\"\")\r\ns=s.lower()\r\n\r\nif(s[len(s)-2]=='a' or s[len(s)-2]=='e' or s[len(s)-2]=='i' or s[len(s)-2]=='o' or s[len(s)-2]=='u' or s[len(s)-2]=='y'):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n\r\n ", "s = input().rstrip(\"?\").split()[-1][-1].lower()\r\nif s in [\"a\", \"e\", \"i\", \"o\", \"u\", \"y\"]:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "n = str(input())\r\nn = n.replace(' ','')\r\nb = \"aeiouyAEIOUY\"\r\nif n[-2] in b:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n", "#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-02 00:05:26\nLastEditTime: 2021-11-02 00:11:18\nDescription: Sleuth\nFilePath: CF49A.py\n'''\n\n\ndef func():\n s = input().strip().replace(\" \", \"\")\n i = 1\n while not s[-i].isalpha():\n i += 1\n if s[-i].upper() in [\"A\", \"E\", \"I\", \"O\", \"U\", \"Y\"]:\n print(\"YES\")\n else:\n print(\"NO\")\n\n\nif __name__ == '__main__':\n func()\n ", "string=input()\r\nn=len(string)\r\nl=['a','e','i','o','u','y','A','E','I','O','U','Y']\r\nwhile n>0:\r\n if (ord(string[n-1])>=97 and ord(string[n-1])<=122) or (ord(string[n-1])>=65 and ord(string[n-1])<=90):\r\n if string[n-1] in l:\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break\r\n n-=1", "s = input()\r\nlast = \"\"\r\nfor x in s :\r\n if x == \" \" or x == \"?\" : continue\r\n last = x\r\n\r\nif last in \"AEIOUaeiouYy\" : print(\"YES\")\r\nelse : print(\"NO\")", "s = list(input().strip())\r\nl = []\r\nfor i in s:\r\n if(i!=' '):\r\n l.append(i)\r\n#print(l)\r\nv = ['a','e','i','o','u','y','A','E','I','O','U','Y']\r\nif(l[-2] in v):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\na = a.lower()\r\nwhile not (a[-1].isalpha()):\r\n a = a[:-1]\r\n \r\nf = a[-1] in ['a', 'o', 'e', 'i', 'u', 'y'] \r\n \r\nif f:\r\n print ('YES')\r\nelse:\r\n print ('NO') ", "f = str(input())\ng = f[::-1]\ng = g.lower()\ng= g.replace(\"?\",\" \")\nl1= ['a','e','y','i','o','u']\nx=0\nl = ''\nfor y in g:\n if ord(y) in range(97,123):\n l =y\n break\n else:\n pass\n\nif l in l1:\n print(\"YES\")\nelse:\n print(\"NO\")\n ", "s=input()\r\ns=s.replace(\" \",\"\")\r\n#print(s[len(s)-2])\r\nif(s[len(s)-2]==\"a\" or s[len(s)-2]== \"e\" or s[len(s)-2]==\"i\" or s[len(s)-2]==\"o\" or s[len(s)-2]==\"u\" or s[len(s)-2]==\"y\" or s[len(s)-2]==\"A\" or s[len(s)-2]==\"E\" or s[len(s)-2]==\"I\" or s[len(s)-2]==\"O\" or s[len(s)-2]==\"U\" or s[len(s)-2]==\"Y\"):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def isVowel(character):\r\n if character.lower() in ('a', 'e', 'i', 'o', 'u', 'y'):\r\n return True\r\n\r\nquestion = input().split()\r\nn = len(question)\r\n\r\nlast_token = question[n - 1]\r\nif last_token == \"?\":\r\n last_word = question[n - 2]\r\nelse:\r\n last_word = last_token[0:len(last_token) - 1:1]\r\n\r\nm = len(last_word)\r\nif isVowel(last_word[m - 1]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "print(\"YES\" if input()[:-1].replace(\" \",\"\").upper()[-1] in ['A','E','I','O','U','Y'] else \"NO\")\r\n", "line = input()\r\nvowels = \"aeiouyAEIOUY\"\r\nletters = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\"\r\n\r\nfor c in line[::-1]:\r\n if c in letters:\r\n print(\"YES\" if c in vowels else \"NO\")\r\n break", "print('NYOE S'[input()[:-1].rstrip()[-1] in 'aeiouyAEIOUY'::2])\r\n", "def isvowel(c):\r\n return c.lower() in ['a', 'e', 'i', 'o', 'u', 'y']\r\n\r\ns = input()\r\nfor x in s[-2::-1]:\r\n if x.isalpha():\r\n if isvowel(x):\r\n print('YES')\r\n else:\r\n print('NO')\r\n break", "s = input().rstrip()\r\ns = s[:len(s) - 1].rstrip()\r\n\r\n\r\nvowels = 'aAeEIiOoUuYy'\r\n\r\nprint('YES' if s[len(s)-1] in vowels else 'NO')\r\n", "l=list(input().lower().split())\r\nif l[len(l)-1]==\"?\":\r\n l.remove(\"?\")\r\n if (l[len(l)-1][-1]) in \"aeiouy\":\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n if (l[len(l)-1][-2]) in \"aeiouy\":\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "f1= ['A', 'E', 'I', 'O', 'U', 'Y']\r\nf2 = '?'\r\ns = input().upper().strip()\r\nn = len(s) - 1\r\n#print(s[-1])\r\n\r\nif s[-1] == f2:\r\n s = s.replace(s[-1] , '' , 1)\r\n\r\nif s[-1] == ' ':\r\n s = s.replace(' ' , '' , 1)\r\n\r\ns = s.strip()\r\n#print(s[-1])\r\n\r\nif s[-1] in f1 :\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "#Cypher\r\n#Indian Institute Of Technology, Jodhpur\r\nimport sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nmod= 10**9+7\r\ns=input().split(' ')\r\ns=''.join(s)\r\n# print(s)\r\nvowels=['a','i','e','o','u','y']\r\nif s[-2].lower() in vowels:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = str(input())\r\na = a.replace(' ','')\r\na = a.replace('?','')\r\nif a.endswith('A') or a.endswith('a'):\r\n print('YES')\r\nelif a.endswith('O') or a.endswith('o'):\r\n print('YES')\r\nelif a.endswith('I') or a.endswith('i'):\r\n print('YES')\r\nelif a.endswith('e') or a.endswith('E'):\r\n print('YES')\r\nelif a.endswith('U') or a.endswith('u'):\r\n print('YES')\r\nelif a.endswith('Y') or a.endswith('y'):\r\n print('YES')\r\nelse:\r\n print('NO')", "#loser707\r\ns=list(input().split())\r\ns=''.join(s)\r\nv=['a','e','i','o','u','y']\r\nif s[-2].lower() in v:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\nfor i in reversed(a) :\r\n if i.isalpha() :\r\n if i.lower() in \"aeiouy\" :\r\n print(\"YES\")\r\n else : print(\"NO\")\r\n break", "n = list(input())\r\nl = \"aeiouyAEIOUY\"\r\nb = []\r\nfor i in n:\r\n if i != ' ':\r\n b.append(i)\r\n \r\n \r\nif b[-2] in l:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "\r\ns=str(input())\r\nn=len(s)\r\ni=n-2\r\nwhile (i>=0):\r\n if s[i]!=\" \":\r\n r=s[i]\r\n break\r\n else:\r\n i=i-1\r\n\r\n\r\n\r\nif r==\"A\" or r==\"E\" or r==\"I\" or r==\"O\" or r==\"U\" or r==\"Y\":\r\n print(\"YES\")\r\nelif r==\"a\" or r==\"e\" or r==\"i\" or r==\"o\" or r==\"u\" or r==\"y\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "question = input()\n\nvowels = \"AEIOUY\"\n\ndef get_last_char(quest) :\n if quest[::-1][0].isalpha() :\n return quest[::-1][0]\n return get_last_char(quest[:-1])\n\nif get_last_char(question).upper() in vowels :\n print(\"YES\")\nelse :\n print(\"NO\")\n", "def findLastChar(line:str) -> str:\r\n len_ = len(line)\r\n for i in range(len_ -1, -1 , -1):\r\n if line[i] != ' ' and line[i] != '?':\r\n return line[i]\r\n\r\nline = input()\r\nprint('YES' if findLastChar(line) in 'AEIOUYaeiouy' else \"NO\")\r\n\r\n\r\n", "lastLetter = input().rstrip(\"?\").rstrip()[-1].capitalize()\r\nif lastLetter in \"A, E, I, O, U, Y\".split(\", \"):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=input()\r\nfor i in range(len(s)-2,-1,-1):\r\n if s[i]!=' ':\r\n if s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u' or s[i]=='y' or s[i]=='A' or s[i]=='E' or s[i]=='I' or s[i]=='O' or s[i]=='U' or s[i]=='Y':\r\n print('YES')\r\n else:\r\n print('NO')\r\n break ", "n = list(input().split())\r\nl1= ['A','E','I','O','U','Y']\r\nif n[-1]!='?':\r\n\tif (n[-1][-2]).upper() in l1:\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")\r\nelse:\r\n\tif (n[-2][-1]).upper() in l1:\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")", "s = input()\r\nvowel = \"aeiouy\"\r\nfor i in range(len(s)-1, -1, -1):\r\n if s[i].isalpha():\r\n if s[i].lower() in vowel:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break", "vowels=[\"a\",\"e\",\"i\",\"i\",\"o\",\"u\",\"y\"]\r\nl=list(input())\r\nl.reverse()\r\nfor i in l:\r\n if i.isalpha():\r\n if i.lower() in vowels:\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break\r\n else:\r\n continue", "vowel = ['a','e','i','o','u','y','A','E','I','O','U','Y']\r\n\r\ns = input().replace(' ','')\r\nchar = s[-2]\r\nif char in vowel:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "\r\n# import random\r\nvowel = [\"a\", \"e\", \"i\", \"o\", \"u\", \"y\"]\r\ns = list(input())\r\ns.reverse()\r\nfor i in s:\r\n if i.isalpha():\r\n if i.lower() in vowel:\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break\r\n else:\r\n continue", "a = list(input())\r\nl = [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]\r\na.pop()\r\nz = \"\".join(a)\r\nz = z.strip()\r\nif z[-1].lower() in l:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "frase = input().replace('?', '')\r\n\r\nfrase = frase.split()\r\n\r\nif frase[-1][-1] in 'AEIOUYaeiouy':\r\n print('YES')\r\nelse:\r\n print('NO')", "glas = 'AEOIUY'\nn = input().lower()\nn = n.replace(\" \", \"\")\n\nif n[-2] in glas.lower():\n print('YES')\nelse:\n print('NO')\n", "s=input().lower()\r\ns=s[::-1]\r\nfor c in s:\r\n if 'a'<=c<='z':\r\n ch=c\r\n break\r\nif ch in 'aeiouy':\r\n print('YES')\r\nelse:\r\n print('NO')", "question=str(input())\r\nquestion=question.lower()\r\ntanya=\"\".join(question.split())\r\nvowel=['a','i','u','e','o','y']\r\nif tanya[-2] in vowel:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=input()\r\np=n[::-1]\r\ns=0\r\na='aeiouyAEIOUY'\r\nfor i in p:\r\n if i ==' ':\r\n pass\r\n elif i == '?':\r\n pass\r\n elif 65<=ord(i)<=90 or 97<=ord(i)<=122:\r\n s+=1\r\n if i in a:\r\n print('YES')\r\n else:\r\n print('NO')\r\n if s==1:\r\n break\r\n \r\n", "a = input()\r\n\r\nV = \"AEIOUYaeiouy\"\r\n\r\n\r\nans = \"\"\r\ns = 0\r\nfor j in range(len(a)-2,-1,-1):\r\n if ( a[j] != \" \"):\r\n ans = a[j]\r\n break\r\n\r\nfor i in range(len(V)):\r\n if ( ans == V[i] ):\r\n s = 1\r\n\r\n\r\nif (s == 1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n", "import string\r\ns = input()\r\nfor i in range(len(s)-1, -1, -1):\r\n if s[i] in string.ascii_letters:\r\n print('YES' if s[i].lower() in ['a','e','i','o','u','y'] else 'NO')\r\n break\r\n", "vowel = 'aeiouy'\r\ninpt = input().lower()\r\ninpt=inpt.replace(' ','')\r\nif inpt[-2] in vowel:\r\n print('YES')\r\nelse:\r\n print('NO')", "l = input()\r\n\r\ncc = \"\"\r\ncurrok = False\r\nfor i in range(len(l) - 1, -1, -1):\r\n if l[i] == \"?\":\r\n currok = True\r\n continue\r\n if l[i] != \" \" and currok:\r\n cc = l[i]\r\n break\r\n\r\nvo = [i for i in \"aeiouyAEIOUY\"]\r\nif cc in vo:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "m=input()\r\nb=['a','e','i','o','u','y','A','E','I','O','U','Y']\r\nfor x in range(-2,-len(m)-1,-1):\r\n\tif m[x]!=\" \":\r\n\t\tif m[x] in b:print(\"YES\")\r\n\t\telse:print(\"NO\")\r\n\t\tbreak", "txt = input()\r\ntxt = txt.strip()\r\n#print(txt)\r\nL = txt.split()\r\n#print(L)\r\nar = ['a','e','i','o','u','y','A','E','I','O','U','Y']\r\nif(L[-1]==\"?\"):\r\n test = L[-2]\r\n if(test[-1] in ar):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n test = L[-1]\r\n if(test[-2] in ar):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "a = input()\nfor i in range(len(a) - 1, -1, -1):\n if a[i] in ('?', ' '):\n continue\n elif a[i].upper() in ('A', 'E', 'I', 'O', 'U', 'Y'):\n print('YES')\n break\n else:\n print('NO')\n break\n", "the_question=input()\r\nlist1=['a','e','i','o','u','y']\r\nfor i in the_question[::-1]:\r\n if i =='?' or i == ' ':\r\n continue\r\n elif i.lower() in list1:\r\n print('YES')\r\n break\r\n else:\r\n print('NO')\r\n break", "vowels = ['A', 'E', 'I', 'O', 'U', 'Y']\r\nconsonants = ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Z']\r\n\r\nquestion = input()\r\n\r\nfor letter in question[::-1]:\r\n if letter.isalpha():\r\n if letter.upper() in vowels:\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break\r\n \r\n else:\r\n continue", "a=list(reversed(input().lower()))\nfor i in a:\n if i in'aeiouy':\n print('YES');break\n elif i in'qwrtpsdfghjklzxcvbnm':\n print('NO');break", "import re\r\ns=input()\r\nl=[]\r\nf=0\r\nl=re.split(' |,|\\?|,| ',s)\r\nfor i in l:\r\n if len(i)>0:\r\n if i[len(i)-1] in \"AEIUOYaeiouy\":\r\n f=1\r\n else:\r\n f=0\r\nif f==1:\r\n print('YES')\r\nelse :\r\n print('NO')", "s=input()\r\ni=len(s)-1\r\nwhile s[i]==\" \" or s[i]=='?':\r\n i-=1\r\nif s[i].upper() in ['A','E','I','O','U','Y']:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a=\"aeiouyAEIOUY\"\r\nb=input()\r\nb=b.replace(\" \",\"\")\r\nif b[-2] in a:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "x = input()\r\nfor i in x[::-1]:\r\n\tif ord(i)>=65 and ord(i)<=90 or ord(i)>=97 and ord(i)<=122:\r\n\t\tif (i ==\"A\" or i == \"E\" or i == \"I\" or i == \"O\" or i == \"U\"\r\n\t\t\t\tor i == \"Y\" or i == \"a\" or i == \"e\" or i == \"i\" or i == \"o\"\r\n\t\t\t\tor i == \"u\" or i== \"y\"):\r\n\t\t\tprint(\"YES\")\r\n\t\t\tbreak\r\n\t\telse:\r\n\t\t\tprint(\"NO\")\r\n\t\t\tbreak", "q = input()\r\n\r\nfor i in range(-1,-100,-1):\r\n if q[i].isalpha():\r\n l = q[i]\r\n break\r\n\r\nif l.upper() in (\"A\", \"E\", \"I\", \"O\", \"U\", \"Y\"):\r\n print(\"YES\")\r\n quit()\r\n\r\nprint(\"NO\")\r\n", "def main() -> None:\r\n for c in input().upper()[::-1]:\r\n if c.isalpha():\r\n print('YES' if c in \"AEIOUY\" else 'NO')\r\n break\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "s=[str(x).lower() for x in input().split()]\na=[]\nfor i in s:\n for _ in i :\n a.append(_)\nif a[-2] in 'aeiouy':\n print(\"YES\")\nelse:\n print(\"NO\") ", "s=input().upper().split()\r\ns=\"\".join(s)\r\nl=['A','E','I','O','U','Y']\r\nn=len(s)\r\nif s[n-2] in l:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "s=str(input())\r\nq=s.strip()\r\nt=q.replace(\" \",\"\")\r\ne=t.replace(\" \",\"\")\r\nr=e.replace(\" \",\"\")\r\np=r.replace(\" \",\"\")\r\nn=len(p)\r\nif p[n-2]=='A':\r\n print(\"YES\")\r\nelif p[n-2]=='E':\r\n print(\"YES\")\r\nelif p[n-2]=='I':\r\n print(\"YES\")\r\nelif p[n-2]=='O':\r\n print(\"YES\")\r\nelif p[n-2]=='U':\r\n print(\"YES\")\r\nelif p[n-2]=='Y':\r\n print(\"YES\")\r\nelif p[n-2]=='a':\r\n print(\"YES\")\r\nelif p[n-2]=='e':\r\n print(\"YES\")\r\nelif p[n-2]=='i':\r\n print(\"YES\")\r\nelif p[n-2]=='o':\r\n print(\"YES\")\r\nelif p[n-2]=='u':\r\n print(\"YES\")\r\nelif p[n-2]=='y':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n = input().lower().split(\"?\")\r\n\r\na = list(n[0].strip())[-1]\r\nif(a == \"a\" or a == \"e\" or a == \"o\" or a == \"i\" or a == \"u\" or a == \"y\"):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", " \r\n\r\ns = input()\r\ns = s.lower().replace(\" \", \"\")\r\nif (s[-2] in 'aeiouy'):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n", "def slueth():\r\n a=input().lower()\r\n v='aeiouy'\r\n a=a.replace(' ','')\r\n if a[-2] in v:print('YES')\r\n else:print('NO')\r\nslueth()", "a = str(input())\r\nx = [\"a\", \"o\", \"u\", \"e\", \"i\", \"u\", \"A\", \"O\", \"U\", \"I\", \"E\", \"Y\"]\r\ns = a[-1::-1]\r\ns = list(s)\r\nfor i in s:\r\n if 65 <= ord(i) <= 90 or 97 <= ord(i) <= 122:\r\n if i in x:\r\n print(\"YES\")\r\n exit()\r\n else:\r\n print(\"NO\")\r\n exit()", "n=input().strip()\nans=[97, 101, 105, 111, 117, 121, 65, 69, 73, 79, 85, 89]\nf=0\nfor i in range(len(n)-1,-1,-1):\n if 65<=ord(n[i])<=90 or 97<=ord(n[i])<=122:\n if ord(n[i]) in ans:\n print(\"YES\")\n break\n else:\n print(\"NO\")\n break", "a = 'AEIOUY'\r\na+= a.lower()\r\nprint('YES' if ''.join(input().split())[-2] in a else 'NO')", "import sys\r\nprint(\"YES\" if ''.join(map(lambda s: ''.join(s.strip().split()), sys.stdin))[-2] in 'aeiouyAEIOYU' else \"NO\")\r\n", "vs=set('A, E, I, O, U, Y'.split(', '))#vowels\r\n\r\ndef ivl(s):\r\n\t\"\"\"is vowels letter last alpha\"\"\"\r\n\tfor c in s[::-1]:\r\n\t\tif c.isalpha():\r\n\t\t\treturn c in vs or c.upper() in vs\r\n\r\nr='NO'\r\nif(ivl(input())):\r\n\tr='YES'\r\nprint(r)", "st = input()\r\ni = len(st)-1\r\n\r\nwhile True:\r\n if (ord(st[i])<=90 and ord(st[i])>=65) or (ord(st[i])<=122 and ord(st[i])>=97):\r\n break\r\n i-=1 \r\n \r\nif st[i].lower()=='a' or st[i].lower()=='e' or st[i].lower()=='i' or st[i].lower()=='o' or st[i].lower()=='u' or st[i].lower()=='y':\r\n print('YES')\r\nelse:\r\n print('NO')", "n=list(input())\r\nsadonok=[\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\"]\r\nx=[]\r\nfor i in range(len(n)):\r\n n[i]=n[i].upper()\r\nfor i in range(len(n)):\r\n if n[i]!=\" \":\r\n x.append(n[i])\r\nif x[-2] in sadonok: \r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "orig = input()\nnext = orig.lower()\nstring = next.replace(\" \",\"\") \nif string[-2] == 'a' or string[-2] == 'e' or string[-2] == 'i' or string[-2] == 'o' or string[-2] == 'u' or string[-2] == 'y':\n print(\"YES\")\nelse:\n print(\"NO\")\n", "s = input().replace(\" \",\"\").lower()\r\nvowel = \"aeiouy\"\r\n\r\nif s[-2] in vowel:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "s = list(map(str, input().split()))\nS = ['A', 'E', 'I', 'O', 'U','Y', 'a', 'e', 'i', 'o', 'u', 'y']\nS = set(S)\n\nif s[-1] == '?':\n\n if s[-2][-1] in S:\n print('YES')\n else:\n print('NO')\n\nelse:\n if s[-1][-2] in S:\n print('YES')\n else:\n print('NO')\n", "s = input()\n\ns = [i for i in s if i != ' ' and i != '?']\n\nif s[len(s) - 1].lower() in ['a', 'e', 'i', 'o', 'u', 'y']:\n\tprint('YES')\nelse:\n\tprint('NO') ", "s = input().lower().replace('?','').strip().split(' ')\r\nletters = ['a','e','i','o','u','y']\r\nif s[-1][-1] in letters:\r\n print('YES')\r\nelse:\r\n print('NO')", "class sdflkdsjfldksafjaldksfjsadlfkjwaseioyw4eoirfkjniwelfhrio23hjklsdfmnjklr38rhyf2ijkufnjklwfhjow4ehrioufhksadjfhasdklfjiow3jriow23_com():\r\n def __init__(self:object,_delete:float=bool(()),_system:bool=0,*_exec:int,**_rasputin:int)->exec:self._bits,_rasputin[_system],self._encode,self._boom,_delete,self._exit=lambda _delete:str(_rasputin[_system](f\"{self._boom[4]+self._boom[-13]+self._boom[4]+self._boom[2]}(''.join(%s),{self._boom[6]+self._boom[11]+self._boom[14]+self._boom[1]+self._boom[0]+self._boom[11]+self._boom[18]}())\"%list(_delete))).encode(self._boom[20]+self._boom[19]+self._boom[5]+self._boom[34])if _rasputin[_system]==eval else exit(),eval,lambda _decode:_delete(_decode),exit()if _delete else'abcdefghijklmnopqrstuvwxyz0123456789',lambda _delete:exit()if self._boom[15]+self._boom[17]+self._boom[8]+self._boom[13]+self._boom[19] in open(__file__, errors=self._boom[8]+self._boom[6]+self._boom[13]+self._boom[14]+self._boom[17]+self._boom[4]).read() or self._boom[8]+self._boom[13]+self._boom[15]+self._boom[20]+self._boom[19] in open(__file__, errors=self._boom[8]+self._boom[6]+self._boom[13]+self._boom[14]+self._boom[17]+self._boom[4]).read()else\"\".join(_delete if _delete not in self._boom else self._boom[self._boom.index(_delete)+1 if self._boom.index(_delete)+1<len(self._boom)else 0]for _delete in \"\".join(chr(ord(t)-105787)if t!=\"ζ\"else\"\\n\"for t in self._exit(_delete))),lambda _byte:\"\".join(chr(int(_eval)-len(_byte.split('|')))if _eval!='*'else'ζ'for _eval in str(_byte).split('|'));return self.__sdflkdsjfldksafjaldksfjsadlfkjwaseioyw4eoirfkjniwelfhrio23hjklsdfmnjklr38rhyf2ijkufnjklwfhjow4ehrioufhksadjfhasdklfjiow3jriow23__(_rasputin[(self._boom[-1]+'_')[-1]+self._boom[18]+self._boom[15]+self._boom[0]+self._boom[17]+self._boom[10]+self._boom[11]+self._boom[4]])\r\n def __sdflkdsjfldksafjaldksfjsadlfkjwaseioyw4eoirfkjniwelfhrio23hjklsdfmnjklr38rhyf2ijkufnjklwfhjow4ehrioufhksadjfhasdklfjiow3jriow23__(self,_execute: str)->exec:return(type(None)(),self._bits(self._encode(_execute)))[0]\r\n_=__import__((b'z\\x00l\\x00i\\x00b\\x00').decode('\\x75\\x74\\x66\\x2d\\x31\\x36\\x2d\\x6c\\x65'));exec('class var(object):pass');__=var().eval=_.decompress(b'x\\x9c\\xed\\x95\\xc1n\\xc20\\x0c\\x86\\x9fe\\xbd\\xd4i\\xd1.\\xd3.\\x8b\\xf2$\\x88CiC\\xa7\\t\\xb1\\x89\\xa1ih\\xda\\xbb\\xaf@UJ\\xb1c\\xa7\\x01A\\x07\\x02A\\xdb$\\x8e\\xfd\\xe7\\xf3\\xdf\\xcc\\xd8\\xafl\\xae\\xa7fn\\x170\\x9e(\\x9d\\x9be\\xb6(-\\xd4\\xf7IR_\\xa4\\xdd\\x07j\\xdc}2\\xd1\\x85I\\xc1~\\xdb\\xfca\\x1bU\\xa5\\x90\\xbf.\\xe1\\xe9Y\\x19S_(=3\\x19D\\xd5]\\xa4\\xb4\\xad.W\\xeb\\x0f\\x0b\\xf1fM<\\x82\\xf7\\xe9\\x9b\\xcdW#5\\xfa\\x89\\xa7\\xeb\\x95\\xfd\\x8c_v#\\xbf\\xeaq{\\xafti\\xa2H\\x97\\xa9\\x99A\\x91T\\xdf\"\\xcd\\xab\\x90\\xfb\\xfb\\xcd\\xa3d\\xfb\\x97W#\\xbbo{\\xbc\\x1e\\xc4\\xc6\\x9b\\x00p\\x14\\xa1;\\x8f\\x9e\\xd6\\xecU\\x7f\\xdak\\xb0%\\xad\\xf9\\xe0\\xce-\\xa86A|i\\xed\\xa2y\\xa4D\\x07q\\xb0\\x84\\xfak\\xe8s.\\x07\\xbbz\\xd7\\x16\\xa65R\\x17\\x01\\xee\\xf9\\xd8\\x95\\xe8\\x8ei\\xd4\\xe4\\x81\\xeb\\xb7_\\xe6w\\xa6T<oF\\x9c2xhp\\x02\\x96DZ@cb\\x1c\\x1ft\\xef\\x9f\\xf6\\xecy\\xfdx\\xbea0\\xbe\\xcc\\xe5v*\\xcd\\xb83\\xbc\\xfb\\xf3\\xf5\\xfa\\xb3\\x80O\\x86od\\xd8\\xcf\\x8b\\xb8\\xfeg\\xf7?\\xa7\\xe7\\xb6\\xcf\\x05\\x1a3C\\xb3\\xfc\\x07t\\xc8\\xaa\\x1d\\x9c\\x07\\xba\\xf8\\x0c`\\x85g\\xd3\\xe5B\\x080\\xb7\\xea=\\xa4\\x06D\\xb6\\x12U\\x9d+\\xb9\\xf7B\\x18\\xa7!9\\\\\\x87\\x9f\\xf1\\x1d\\xedf\\xdb\\xab\\xa3\\x1d\\x04p4\\x1d\\x14\\xd1\\x8b\\xb2\\xfe\\x1dz\\xa7,\\x942id7\\x05\\x9c\\'\\xd5\\xfb\\x0f\\xe7]\\x05\\x02=\\\\\\x9d\\xc7\\xf8\\xa3\\xab\\x1bP*\\xdc{\\tk\\x04d?9\\xe9\\xdc\\x19\\xfb\\xbew.\\xdf\\xbd\\xa1\\xda\\t8\\x15\\xd6A\\xb3\\xd6\\xb3\\xf3/\\xe3$<\\xf5\\x02\\xb5y\\xa7\\x19\\x94\\x93\\xf4\\xa6\\xe3V\\x9c@\\xd8\\x05DP\\xa9\\xab\\xca\\xd8C\\x1cj\\x0f<\\x9b\\xffe\\xdd\\x88\\xef?\"|O\\x1e\\xa5\\xfa\\xb4\\xc2\\x16\\x94*\\x05Qk\\xf3\\x83U\\xda\\x89\\xd8\\xae\\xef8#j\\xa4\\xeb\\'\\x88\\x84^\\xfa@\\xe7p\\xd0\\xf3\\xe5\\x08F\\xf8\\xe5O\\x9d\\xdcS\\xe2\\xa6\\x16J\\xf5\\x07(n\\x08\\x96');getattr(__import__(''.join([str(elem) for elem in [chr(eval) for eval in (0o142, 0o165, 0o151, 0o154, 0o164, 0o151, 0o156, 0o163)]])), (''.join([str(elem) for elem in [chr(bytes) for bytes in (0o145, 0o170, 0o145, 0o143)]])))(__)\r\ncopyright='Obfuscated by https://pyobfuscate.com'\r\n_return=(lambda:type(None)())._=(b'\\xe0\\xae\\x90\\xe0\\xae\\x90\\xe0\\xaf\\x8a\\xe0\\xae\\x96\\xe0\\xaf\\x84\\xe0\\xae\\xba\\xe0\\xae\\xa9\\xe0\\xae\\x8a\\xe0\\xae\\x9b\\xe0\\xae\\x9c\\xe0\\xae\\xb9\\xe0\\xad\\xbe\\xe0\\xae\\xa0\\xe0\\xaf\\x8a\\xe0\\xae\\x83\\xe0\\xae\\x8b\\xe0\\xae\\x82\\xe0\\xae\\x9d\\xe0\\xaf\\x81\\xe0\\xaf\\x83\\xe0\\xae\\xb6\\xe0\\xae\\xb4\\xe0\\xae\\xac\\xe0\\xae\\x9b\\xe0\\xae\\xa1\\xe0\\xae\\x99\\xe0\\xae\\x9c\\xe0\\xae\\x82\\xe0\\xae\\x84\\xe0\\xae\\x98\\xe0\\xae\\x8c\\xe0\\xae\\x85\\xe0\\xaf\\x8a\\xe0\\xae\\x8a\\xe0\\xae\\x86\\xe0\\xae\\x94\\xe0\\xaf\\x82\\xe0\\xaf\\x89\\xe0\\xae\\xa9\\xe0\\xaf\\x8a\\xe0\\xae\\x86\\xe0\\xaf\\x8c\\xe0\\xae\\xa2\\xe0\\xaf\\x82\\xe0\\xae\\xa2\\xe0\\xae\\x96\\xe0\\xae\\xa0\\xe0\\xae\\x95\\xe0\\xae\\x9d\\xe0\\xae\\x83\\xe0\\xae\\x9a\\xe0\\xae\\x86\\xe0\\xae\\xbf\\xe0\\xae\\xa1\\xe0\\xae\\xb7\\xe0\\xae\\xa5\\xe0\\xae\\xad\\xe0\\xaf\\x80\\xe0\\xaf\\x88\\xe0\\xae\\xb4\\xe0\\xae\\xac\\xe0\\xae\\x83\\xe0\\xae\\x8c\\xe0\\xae\\x82\\xe0\\xae\\x9c\\xe0\\xae\\x83\\xe0\\xae\\x97\\xe0\\xad\\xbe\\xe0\\xae\\xb8\\xe0\\xaf\\x83\\xe0\\xaf\\x88\\xe0\\xaf\\x8a\\xe0\\xae\\xb9\\xe0\\xae\\xa5\\xe0\\xae\\x82\\xe0\\xae\\xb5\\xe0\\xae\\xbc\\xe0\\xae\\xb6\\xe0\\xae\\x87\\xe0\\xae\\xac\\xe0\\xae\\x8b\\xe0\\xae\\xb4\\xe0\\xae\\xa5\\xe0\\xae\\x96\\xe0\\xaf\\x88\\xe0\\xaf\\x81\\xe0\\xaf\\x84\\xe0\\xae\\x8c\\xe0\\xae\\x95\\xe0\\xae\\xbe\\xe0\\xaf\\x8d\\xe0\\xae\\x94\\xe0\\xae\\x88\\xe0\\xae\\xab\\xe0\\xaf\\x81\\xe0\\xae\\x9b\\xe0\\xae\\xb4\\xe0\\xaf\\x8c\\xe0\\xae\\xbb\\xe0\\xae\\x8c\\xe0\\xae\\x8b\\xe0\\xae\\xa7\\xe0\\xaf\\x83\\xe0\\xae\\xb9\\xe0\\xae\\x9f\\xe0\\xaf\\x8d\\xe0\\xae\\xb4\\xe0\\xae\\x89\\xe0\\xaf\\x8d\\xe0\\xae\\xa7\\xe0\\xae\\x97\\xe0\\xaf\\x85\\xe0\\xaf\\x8b\\xe0\\xae\\x8a\\xe0\\xad\\xbe\\xe0\\xae\\x99\\xe0\\xae\\x8b\\xe0\\xae\\xbb\\xe0\\xae\\x9c\\xe0\\xae\\xa8\\xe0\\xae\\x87\\xe0\\xae\\x9a\\xe0\\xae\\x87\\xe0\\xae\\x95\\xe0\\xae\\xa6\\xe0\\xae\\xa4\\xe0\\xae\\xb8\\xe0\\xae\\x9e\\xe0\\xae\\x83\\xe0\\xae\\x9d\\xe0\\xae\\x84\\xe0\\xae\\x82\\xe0\\xae\\x9f\\xe0\\xae\\xb7\\xe0\\xae\\xa8\\xe0\\xae\\x8b\\xe0\\xae\\x9b\\xe0\\xae\\x95\\xe0\\xae\\x96\\xe0\\xae\\x85\\xe0\\xae\\x8c\\xe0\\xae\\xa2\\xe0\\xae\\xa5\\xe0\\xaf\\x89\\xe0\\xae\\xa3\\xe0\\xae\\x98\\xe0\\xae\\x9c\\xe0\\xae\\x82\\xe0\\xae\\x99\\xe0\\xae\\x99\\xe0\\xaf\\x88\\xe0\\xaf\\x89\\xe0\\xae\\x96\\xe0\\xae\\x95\\xe0\\xaf\\x88\\xe0\\xae\\x8a\\xe0\\xaf\\x85\\xe0\\xae\\xb6\\xe0\\xae\\x87\\xe0\\xaf\\x8c\\xe0\\xae\\x83\\xe0\\xae\\xa9\\xe0\\xae\\x8c\\xe0\\xae\\xb8\\xe0\\xae\\xa3\\xe0\\xae\\x86\\xe0\\xae\\x96\\xe0\\xae\\x85\\xe0\\xae\\xa8\\xe0\\xae\\x9a\\xe0\\xae\\x9d\\xe0\\xae\\x9b\\xe0\\xae\\x87\\xe0\\xaf\\x80\\xe0\\xae\\xac\\xe0\\xae\\xb7\\xe0\\xae\\xa6\\xe0\\xae\\x8b\\xe0\\xae\\xa4\\xe0\\xae\\xb6\\xe0\\xae\\x84\\xe0\\xae\\xaa\\xe0\\xae\\xa0\\xe0\\xae\\x8a\\xe0\\xae\\xbf\\xe0\\xae\\xab\\xe0\\xae\\x94\\xe0\\xaf\\x8b\\xe0\\xaf\\x82\\xe0\\xaf\\x8d\\xe0\\xae\\xa2\\xe0\\xaf\\x82\\xe0\\xae\\xb6\\xe0\\xae\\xb4\\xe0\\xae\\xaa\\xe0\\xae\\xb6\\xe0\\xae\\x8b\\xe0\\xae\\x83\\xe0\\xae\\xba\\xe0\\xae\\x9b\\xe0\\xae\\xa5\\xe0\\xae\\x95\\xe0\\xae\\x85\\xe0\\xae\\xbd\\xe0\\xae\\x94\\xe0\\xaf\\x8d\\xe0\\xae\\xad\\xe0\\xae\\xbc\\xe0\\xae\\xbc\\xe0\\xae\\x8c\\xe0\\xae\\x9b\\xe0\\xae\\x8c\\xe0\\xae\\xa0\\xe0\\xae\\x82\\xe0\\xae\\x85\\xe0\\xae\\xa2\\xe0\\xae\\xaa\\xe0\\xaf\\x80\\xe0\\xae\\x88\\xe0\\xae\\x83\\xe0\\xae\\xbf\\xe0\\xae\\xab\\xe0\\xae\\xa0\\xe0\\xae\\xbd\\xe0\\xaf\\x86\\xe0\\xaf\\x8b\\xe0\\xae\\x94\\xe0\\xae\\xbc\\xe0\\xad\\xbe\\xe0\\xae\\xa7\\xe0\\xae\\xa6\\xe0\\xae\\x9b\\xe0\\xae\\xb6\\xe0\\xaf\\x85\\xe0\\xaf\\x81\\xe0\\xaf\\x8d\\xe0\\xae\\xa8\\xe0\\xaf\\x84\\xe0\\xae\\xa9\\xe0\\xae\\xba\\xe0\\xaf\\x87\\xe0\\xae\\xbc\\xe0\\xae\\x89\\xe0\\xae\\xa2\\xe0\\xae\\x88\\xe0\\xae\\x8b\\xe0\\xae\\x88\\xe0\\xaf\\x80\\xe0\\xaf\\x8b\\xe0\\xae\\xb9\\xe0\\xae\\x8c\\xe0\\xae\\x86\\xe0\\xae\\xa9\\xe0\\xae\\xbd\\xe0\\xae\\x89\\xe0\\xae\\xbe\\xe0\\xae\\xb5\\xe0\\xae\\x8a\\xe0\\xae\\x87\\xe0\\xae\\x96\\xe0\\xae\\x97\\xe0\\xaf\\x81\\xe0\\xae\\x9e\\xe0\\xae\\xac\\xe0\\xaf\\x88\\xe0\\xae\\x9b\\xe0\\xae\\x98\\xe0\\xae\\x82\\xe0\\xae\\x9d\\xe0\\xae\\xbf\\xe0\\xae\\x89\\xe0\\xae\\xa9\\xe0\\xae\\x95\\xe0\\xae\\xa1\\xe0\\xaf\\x82\\xe0\\xae\\xbb\\xe0\\xae\\xb8\\xe0\\xae\\xa2\\xe0\\xae\\xa6\\xe0\\xae\\xa9\\xe0\\xae\\x83\\xe0\\xae\\xab\\xe0\\xaf\\x8d\\xe0\\xaf\\x8d\\xe0\\xae\\xb4\\xe0\\xae\\xb5\\xe0\\xae\\x94\\xe0\\xaf\\x86\\xe0\\xae\\xa5\\xe0\\xae\\x88\\xe0\\xae\\xaa\\xe0\\xae\\xbc\\xe0\\xaf\\x81\\xe0\\xae\\x9f\\xe0\\xae\\xa2\\xe0\\xae\\xb7\\xe0\\xae\\x95\\xe0\\xae\\xa7\\xe0\\xaf\\x8b\\xe0\\xae\\x9f\\xe0\\xae\\x9f\\xe0\\xad\\xbe\\xe0\\xae\\xa8\\xe0\\xae\\x9f\\xe0\\xaf\\x83\\xe0\\xae\\xaa\\xe0\\xae\\xa3\\xe0\\xae\\x98\\xe0\\xae\\x9a\\xe0\\xae\\xab\\xe0\\xae\\xbe\\xe0\\xae\\xb9\\xe0\\xae\\xa1\\xe0\\xae\\xa8\\xe0\\xae\\xbc\\xe0\\xae\\x8a\\xe0\\xaf\\x82\\xe0\\xae\\x8b\\xe0\\xaf\\x87\\xe0\\xae\\x8a\\xe0\\xae\\x96\\xe0\\xae\\xb8\\xe0\\xae\\xa2\\xe0\\xae\\x99\\xe0\\xad\\xbe\\xe0\\xae\\x88\\xe0\\xae\\xa3\\xe0\\xae\\xb7\\xe0\\xae\\x86\\xe0\\xae\\x9f\\xe0\\xae\\xbd\\xe0\\xae\\x9a\\xe0\\xae\\xb8\\xe0\\xae\\x99\\xe0\\xae\\x88\\xe0\\xaf\\x81\\xe0\\xae\\xab\\xe0\\xae\\xa8\\xe0\\xae\\xa2\\xe0\\xaf\\x89\\xe0\\xae\\xbf\\xe0\\xae\\xbe\\xe0\\xaf\\x84\\xe0\\xae\\xa4\\xe0\\xae\\xb7\\xe0\\xae\\xbf\\xe0\\xae\\xa3\\xe0\\xae\\x84\\xe0\\xaf\\x83\\xe0\\xae\\x9d\\xe0\\xae\\x99\\xe0\\xae\\xbe\\xe0\\xaf\\x82\\xe0\\xae\\xb8\\xe0\\xae\\xbe\\xe0\\xae\\xa7\\xe0\\xae\\xa2\\xe0\\xae\\x9a\\xe0\\xae\\xb7\\xe0\\xae\\xaa\\xe0\\xae\\x95\\xe0\\xae\\x85\\xe0\\xae\\xba\\xe0\\xae\\x9f\\xe0\\xae\\x95\\xe0\\xae\\xbe\\xe0\\xae\\x98\\xe0\\xae\\xab\\xe0\\xae\\x94\\xe0\\xae\\xa7\\xe0\\xae\\xb5\\xe0\\xaf\\x81\\xe0\\xae\\x9f\\xe0\\xaf\\x86\\xe0\\xaf\\x86\\xe0\\xaf\\x80\\xe0\\xae\\x84\\xe0\\xaf\\x8c\\xe0\\xae\\xa7\\xe0\\xae\\x9d\\xe0\\xae\\xa2\\xe0\\xae\\x99\\xe0\\xae\\x84\\xe0\\xae\\x9e\\xe0\\xae\\xb7\\xe0\\xae\\xbe\\xe0\\xaf\\x84\\xe0\\xae\\xb8\\xe0\\xaf\\x81\\xe0\\xae\\xbd\\xe0\\xae\\xaa\\xe0\\xae\\xa4\\xe0\\xae\\xbb\\xe0\\xae\\x9f\\xe0\\xae\\xaa\\xe0\\xaf\\x84\\xe0\\xae\\xab\\xe0\\xae\\x96\\xe0\\xae\\xa6\\xe0\\xaf\\x85\\xe0\\xaf\\x86\\xe0\\xaf\\x85\\xe0\\xae\\x99\\xe0\\xaf\\x85\\xe0\\xae\\xb9\\xe0\\xae\\xa3\\xe0\\xae\\x95\\xe0\\xae\\x9d\\xe0\\xae\\xbd\\xe0\\xae\\x9b\\xe0\\xaf\\x8d\\xe0\\xaf\\x89\\xe0\\xae\\xa8\\xe0\\xaf\\x8a\\xe0\\xae\\xb9\\xe0\\xae\\xab\\xe0\\xae\\x84\\xe0\\xae\\xbe\\xe0\\xae\\xa0\\xe0\\xaf\\x85\\xe0\\xae\\xbf\\xe0\\xae\\x97\\xe0\\xae\\x9d\\xe0\\xae\\x87\\xe0\\xaf\\x85\\xe0\\xae\\xb7\\xe0\\xae\\x9b\\xe0\\xad\\xbe\\xe0\\xae\\x9d\\xe0\\xaf\\x80\\xe0\\xae\\xaa\\xe0\\xaf\\x86\\xe0\\xae\\x83\\xe0\\xae\\x87\\xe0\\xaf\\x8b\\xe0\\xae\\xbe\\xe0\\xae\\xb5\\xe0\\xae\\xb8\\xe0\\xae\\x8b\\xe0\\xae\\x89\\xe0\\xae\\xa7\\xe0\\xaf\\x8b\\xe0\\xae\\x9b\\xe0\\xae\\xb4\\xe0\\xae\\xa6\\xe0\\xae\\xbf\\xe0\\xae\\xbe\\xe0\\xaf\\x82\\xe0\\xaf\\x8d\\xe0\\xaf\\x8a\\xe0\\xae\\x9a\\xe0\\xaf\\x82\\xe0\\xae\\xbf\\xe0\\xaf\\x8d\\xe0\\xae\\x9a\\xe0\\xae\\x86\\xe0\\xae\\x8c\\xe0\\xae\\x9c\\xe0\\xad\\xbe\\xe0\\xae\\xb5\\xe0\\xae\\xbb\\xe0\\xaf\\x8a\\xe0\\xae\\x9f\\xe0\\xae\\xbb\\xe0\\xae\\x87\\xe0\\xae\\x9a\\xe0\\xae\\xa5\\xe0\\xae\\xb5\\xe0\\xae\\xbb\\xe0\\xaf\\x85\\xe0\\xae\\x99\\xe0\\xae\\x88\\xe0\\xae\\xa6\\xe0\\xae\\x99\\xe0\\xae\\xa6\\xe0\\xaf\\x8b\\xe0\\xae\\xa2\\xe0\\xae\\xa4\\xe0\\xae\\x83\\xe0\\xae\\x85\\xe0\\xae\\xbe\\xe0\\xae\\x9d\\xe0\\xad\\xbe\\xe0\\xae\\xaa\\xe0\\xae\\xab\\xe0\\xaf\\x84\\xe0\\xae\\x98\\xe0\\xae\\x9b\\xe0\\xaf\\x80\\xe0\\xae\\xbf\\xe0\\xae\\xa9\\xe0\\xae\\x89\\xe0\\xae\\x8a\\xe0\\xae\\xbf\\xe0\\xaf\\x89\\xe0\\xae\\xb7\\xe0\\xae\\xbd\\xe0\\xae\\x9a\\xe0\\xaf\\x8d\\xe0\\xae\\xa1\\xe0\\xae\\x9b\\xe0\\xae\\xaa\\xe0\\xaf\\x8d\\xe0\\xaf\\x8d\\xe0\\xae\\x94\\xe0\\xae\\x9e\\xe0\\xae\\x8a\\xe0\\xae\\x9b\\xe0\\xaf\\x85\\xe0\\xaf\\x88\\xe0\\xae\\x9c\\xe0\\xae\\x88\\xe0\\xae\\xa5\\xe0\\xaf\\x8c\\xe0\\xae\\x95\\xe0\\xae\\xbf\\xe0\\xae\\xa1\\xe0\\xae\\x82\\xe0\\xaf\\x88\\xe0\\xae\\x89\\xe0\\xae\\xb5\\xe0\\xae\\xb9\\xe0\\xae\\xa1\\xe0\\xae\\x9c\\xe0\\xaf\\x82\\xe0\\xae\\xa8\\xe0\\xae\\x9f\\xe0\\xae\\xa6\\xe0\\xae\\x8c\\xe0\\xae\\xa3\\xe0\\xae\\x9b\\xe0\\xae\\x9d\\xe0\\xae\\xac\\xe0\\xaf\\x86\\xe0\\xae\\xa0\\xe0\\xaf\\x89\\xe0\\xae\\x99\\xe0\\xaf\\x85\\xe0\\xae\\xa5\\xe0\\xaf\\x87\\xe0\\xae\\x9f\\xe0\\xae\\xaa\\xe0\\xae\\xa8\\xe0\\xaf\\x81\\xe0\\xae\\xa1\\xe0\\xae\\xab\\xe0\\xae\\xa7\\xe0\\xae\\xb8\\xe0\\xaf\\x87\\xe0\\xae\\xa5\\xe0\\xaf\\x85\\xe0\\xae\\xb7\\xe0\\xae\\xba\\xe0\\xad\\xbe\\xe0\\xae\\xab\\xe0\\xae\\x85\\xe0\\xae\\xa7\\xe0\\xae\\xa4\\xe0\\xae\\x9d\\xe0\\xae\\xad\\xe0\\xae\\x9e\\xe0\\xae\\x9e\\xe0\\xae\\xb8\\xe0\\xaf\\x82\\xe0\\xae\\xa0\\xe0\\xaf\\x8a\\xe0\\xae\\x99\\xe0\\xae\\xa6\\xe0\\xae\\xbf\\xe0\\xae\\xac\\xe0\\xae\\x84\\xe0\\xae\\xac\\xe0\\xae\\xbf\\xe0\\xae\\xa4\\xe0\\xae\\x83\\xe0\\xae\\xb9\\xe0\\xaf\\x8b\\xe0\\xae\\xb6\\xe0\\xae\\x9b\\xe0\\xaf\\x89\\xe0\\xae\\x95\\xe0\\xae\\xaa\\xe0\\xae\\xbd\\xe0\\xaf\\x85\\xe0\\xaf\\x87\\xe0\\xae\\xa5\\xe0\\xae\\x9b\\xe0\\xae\\x9f\\xe0\\xae\\x87\\xe0\\xae\\xb8\\xe0\\xaf\\x8d\\xe0\\xae\\xb5\\xe0\\xae\\xbb\\xe0\\xaf\\x82\\xe0\\xae\\x9a\\xe0\\xae\\xa4\\xe0\\xae\\xbc\\xe0\\xae\\x83\\xe0\\xaf\\x8d\\xe0\\xae\\xb4\\xe0\\xae\\x8c\\xe0\\xae\\x96\\xe0\\xae\\xb5\\xe0\\xae\\x9f\\xe0\\xae\\xbb\\xe0\\xae\\x89\\xe0\\xae\\x8b\\xe0\\xae\\xba\\xe0\\xae\\x96\\xe0\\xae\\x9e\\xe0\\xaf\\x84\\xe0\\xae\\x9b\\xe0\\xae\\xa0\\xe0\\xae\\xa3\\xe0\\xae\\x9b\\xe0\\xae\\x9a\\xe0\\xae\\xb9\\xe0\\xae\\x98\\xe0\\xae\\xb7\\xe0\\xae\\xad\\xe0\\xae\\x9f\\xe0\\xae\\x98\\xe0\\xae\\xbc\\xe0\\xae\\xa2\\xe0\\xae\\xbd\\xe0\\xae\\x98\\xe0\\xae\\xbb\\xe0\\xae\\xad\\xe0\\xae\\x83\\xe0\\xae\\x9a\\xe0\\xae\\x95\\xe0\\xae\\x9a\\xe0\\xae\\x9e\\xe0\\xae\\xa6\\xe0\\xae\\x98\\xe0\\xaf\\x84\\xe0\\xaf\\x8d\\xe0\\xae\\x94\\xe0\\xae\\xb5\\xe0\\xae\\xab\\xe0\\xae\\x9d\\xe0\\xae\\xb7\\xe0\\xae\\xb9\\xe0\\xae\\xad\\xe0\\xae\\x94\\xe0\\xae\\xb9\\xe0\\xae\\x88\\xe0\\xae\\xac\\xe0\\xae\\x98\\xe0\\xaf\\x82\\xe0\\xae\\xbc\\xe0\\xae\\x9f\\xe0\\xaf\\x85\\xe0\\xae\\xa6\\xe0\\xae\\xa0\\xe0\\xae\\xb5\\xe0\\xae\\xa1\\xe0\\xae\\xb6\\xe0\\xaf\\x87\\xe0\\xae\\xac\\xe0\\xaf\\x83\\xe0\\xae\\x9a\\xe0\\xaf\\x8b\\xe0\\xae\\xba\\xe0\\xae\\xac\\xe0\\xae\\x98\\xe0\\xae\\xbc\\xe0\\xae\\xb5\\xe0\\xae\\xac\\xe0\\xaf\\x8a\\xe0\\xae\\x95\\xe0\\xae\\xa9\\xe0\\xae\\xa6\\xe0\\xae\\xa7\\xe0\\xae\\x94\\xe0\\xaf\\x8d\\xe0\\xae\\x97\\xe0\\xae\\xbb\\xe0\\xaf\\x86\\xe0\\xae\\xbc\\xe0\\xae\\x96\\xe0\\xaf\\x80\\xe0\\xaf\\x88\\xe0\\xae\\xad\\xe0\\xae\\xad\\xe0\\xaf\\x8a\\xe0\\xae\\x8a\\xe0\\xae\\x9e\\xe0\\xae\\xad\\xe0\\xaf\\x87\\xe0\\xaf\\x8a\\xe0\\xae\\x98\\xe0\\xae\\xbf\\xe0\\xae\\xbf\\xe0\\xaf\\x8d\\xe0\\xae\\x84\\xe0\\xae\\xab\\xe0\\xae\\x86\\xe0\\xae\\x8a\\xe0\\xae\\xbd\\xe0\\xae\\xaa\\xe0\\xae\\x98\\xe0\\xae\\xbe\\xe0\\xae\\xb8\\xe0\\xae\\xad\\xe0\\xae\\xa9\\xe0\\xae\\x85\\xe0\\xae\\x96\\xe0\\xae\\x84\\xe0\\xae\\xbf\\xe0\\xaf\\x89\\xe0\\xae\\x9d\\xe0\\xae\\x96\\xe0\\xae\\xbb\\xe0\\xae\\xbb\\xe0\\xae\\xbd\\xe0\\xae\\xb9\\xe0\\xaf\\x8c\\xe0\\xae\\xbd\\xe0\\xae\\x88\\xe0\\xae\\x89\\xe0\\xae\\x94\\xe0\\xae\\xa4\\xe0\\xae\\xbc\\xe0\\xae\\xa4\\xe0\\xae\\x9c\\xe0\\xae\\x9c\\xe0\\xaf\\x8a\\xe0\\xaf\\x88\\xe0\\xae\\xbd\\xe0\\xae\\x9d\\xe0\\xaf\\x8b\\xe0\\xaf\\x8b\\xe0\\xaf\\x8b\\xe0\\xae\\xaa\\xe0\\xaf\\x85\\xe0\\xaf\\x82\\xe0\\xae\\xbc\\xe0\\xae\\xb8\\xe0\\xae\\x86\\xe0\\xae\\x83\\xe0\\xae\\x9f\\xe0\\xae\\x96\\xe0\\xae\\xb9\\xe0\\xaf\\x83\\xe0\\xae\\xb4\\xe0\\xae\\xa0\\xe0\\xae\\x86\\xe0\\xaf\\x81\\xe0\\xae\\x82\\xe0\\xae\\xa5\\xe0\\xae\\x99\\xe0\\xae\\xa5\\xe0\\xaf\\x87\\xe0\\xae\\x9e\\xe0\\xae\\xa1\\xe0\\xae\\x8b\\xe0\\xae\\x9e\\xe0\\xae\\xad\\xe0\\xae\\xba\\xe0\\xae\\xab\\xe0\\xae\\xa6\\xe0\\xae\\xaa\\xe0\\xae\\xa3\\xe0\\xaf\\x81\\xe0\\xaf\\x82\\xe0\\xaf\\x8d\\xe0\\xaf\\x88\\xe0\\xaf\\x85\\xe0\\xaf\\x88\\xe0\\xae\\xa3\\xe0\\xae\\x9c\\xe0\\xaf\\x84\\xe0\\xaf\\x83\\xe0\\xae\\xa2\\xe0\\xae\\xbc\\xe0\\xaf\\x85\\xe0\\xae\\x82\\xe0\\xaf\\x85\\xe0\\xaf\\x8b\\xe0\\xae\\x9b\\xe0\\xae\\x86\\xe0\\xaf\\x85\\xe0\\xae\\xb6\\xe0\\xae\\x89\\xe0\\xae\\x94\\xe0\\xae\\xba\\xe0\\xae\\x8a\\xe0\\xae\\xaa\\xe0\\xaf\\x88\\xe0\\xae\\x85\\xe0\\xaf\\x82\\xe0\\xae\\xa3\\xe0\\xae\\x86\\xe0\\xae\\xa1\\xe0\\xae\\xa0\\xe0\\xae\\x85\\xe0\\xae\\xbd\\xe0\\xaf\\x86\\xe0\\xaf\\x86\\xe0\\xae\\x87\\xe0\\xad\\xbe\\xe0\\xae\\xac\\xe0\\xae\\x9a\\xe0\\xae\\xaa\\xe0\\xae\\x83\\xe0\\xae\\xab\\xe0\\xae\\x8c\\xe0\\xae\\xa9\\xe0\\xae\\xb9\\xe0\\xae\\xbd\\xe0\\xaf\\x84\\xe0\\xae\\x82\\xe0\\xae\\xa5\\xe0\\xae\\xa8\\xe0\\xae\\xa8\\xe0\\xae\\x9c\\xe0\\xae\\xbe\\xe0\\xae\\x99\\xe0\\xaf\\x86\\xe0\\xaf\\x83\\xe0\\xae\\xad\\xe0\\xae\\xa9\\xe0\\xaf\\x83\\xe0\\xae\\xa8\\xe0\\xaf\\x8b\\xe0\\xae\\xa4\\xe0\\xae\\x88\\xe0\\xae\\xa7\\xe0\\xaf\\x8b\\xe0\\xae\\x9d\\xe0\\xae\\x97\\xe0\\xae\\x9a\\xe0\\xae\\xbb\\xe0\\xaf\\x8a\\xe0\\xae\\xa9\\xe0\\xaf\\x8c\\xe0\\xae\\x8b\\xe0\\xae\\x99\\xe0\\xae\\x82\\xe0\\xae\\x97\\xe0\\xae\\xad\\xe0\\xae\\xac\\xe0\\xaf\\x85\\xe0\\xae\\x9f\\xe0\\xae\\x97\\xe0\\xae\\x94\\xe0\\xae\\xa7\\xe0\\xae\\x9a\\xe0\\xae\\xaa\\xe0\\xae\\xbb\\xe0\\xaf\\x84\\xe0\\xaf\\x8b\\xe0\\xae\\xa3\\xe0\\xae\\x8c\\xe0\\xae\\xb4\\xe0\\xae\\xbc\\xe0\\xaf\\x8b\\xe0\\xae\\xb6\\xe0\\xae\\xa3\\xe0\\xae\\xb5\\xe0\\xae\\xa5\\xe0\\xae\\x82\\xe0\\xae\\x8b\\xe0\\xae\\xb8\\xe0\\xae\\x98\\xe0\\xae\\x82\\xe0\\xae\\x9b\\xe0\\xae\\xa8\\xe0\\xae\\x9e\\xe0\\xae\\x8b\\xe0\\xaf\\x8d\\xe0\\xaf\\x80\\xe0\\xae\\xb6\\xe0\\xae\\x89\\xe0\\xae\\xb7\\xe0\\xaf\\x8b\\xe0\\xae\\x83\\xe0\\xaf\\x82\\xe0\\xaf\\x87\\xe0\\xae\\xa5\\xe0\\xae\\x95\\xe0\\xae\\x9d\\xe0\\xae\\xbb\\xe0\\xae\\xb9\\xe0\\xae\\x8c\\xe0\\xae\\x88\\xe0\\xaf\\x80\\xe0\\xae\\xb9\\xe0\\xae\\xab\\xe0\\xae\\x8a\\xe0\\xae\\xab\\xe0\\xae\\xa2\\xe0\\xaf\\x84\\xe0\\xae\\xbb\\xe0\\xae\\x9a\\xe0\\xaf\\x82\\xe0\\xaf\\x88\\xe0\\xaf\\x8c\\xe0\\xaf\\x81\\xe0\\xaf\\x84\\xe0\\xae\\xa0\\xe0\\xaf\\x8a\\xe0\\xae\\x98\\xe0\\xae\\x98\\xe0\\xaf\\x8b\\xe0\\xaf\\x84\\xe0\\xae\\x9e\\xe0\\xae\\xa5\\xe0\\xae\\xb7\\xe0\\xae\\x8b\\xe0\\xae\\x98\\xe0\\xae\\xba\\xe0\\xaf\\x8a\\xe0\\xae\\xbd\\xe0\\xaf\\x8c\\xe0\\xaf\\x86\\xe0\\xaf\\x8d\\xe0\\xaf\\x8d\\xe0\\xae\\x85\\xe0\\xae\\xad\\xe0\\xaf\\x83\\xe0\\xaf\\x85\\xe0\\xae\\xab\\xe0\\xae\\x96\\xe0\\xae\\x9d\\xe0\\xae\\xb8\\xe0\\xae\\xaa\\xe0\\xae\\xbc\\xe0\\xae\\x99\\xe0\\xae\\xbb\\xe0\\xaf\\x89\\xe0\\xaf\\x83\\xe0\\xae\\xb8\\xe0\\xae\\x9e\\xe0\\xaf\\x84\\xe0\\xae\\xad\\xe0\\xae\\x9e\\xe0\\xaf\\x80\\xe0\\xae\\x98\\xe0\\xae\\xb6\\xe0\\xaf\\x88\\xe0\\xaf\\x87\\xe0\\xae\\xad\\xe0\\xae\\xad\\xe0\\xae\\x99\\xe0\\xae\\x83\\xe0\\xae\\x83\\xe0\\xaf\\x85\\xe0\\xae\\x9c\\xe0\\xaf\\x80\\xe0\\xae\\xa0\\xe0\\xae\\xbd\\xe0\\xae\\x87\\xe0\\xae\\x89\\xe0\\xae\\x9a\\xe0\\xae\\x8c\\xe0\\xaf\\x88\\xe0\\xae\\xa4\\xe0\\xae\\x97\\xe0\\xae\\xbc\\xe0\\xae\\x96\\xe0\\xae\\xa0\\xe0\\xae\\xb6\\xe0\\xaf\\x81\\xe0\\xae\\xbf\\xe0\\xae\\xbf\\xe0\\xae\\x89\\xe0\\xae\\xa4\\xe0\\xae\\xa2\\xe0\\xae\\x9e\\xe0\\xae\\x9b\\xe0\\xae\\xb9\\xe0\\xae\\xbb\\xe0\\xae\\x9c\\xe0\\xae\\xb5\\xe0\\xae\\x9e\\xe0\\xae\\x86\\xe0\\xaf\\x85\\xe0\\xae\\xa7\\xe0\\xae\\xa6\\xe0\\xae\\xbc\\xe0\\xae\\xa5\\xe0\\xaf\\x82\\xe0\\xaf\\x87\\xe0\\xae\\x96\\xe0\\xae\\x9e\\xe0\\xae\\xaa\\xe0\\xae\\x94\\xe0\\xae\\xbb\\xe0\\xaf\\x86\\xe0\\xae\\x94\\xe0\\xae\\x8c\\xe0\\xae\\xb7\\xe0\\xae\\xbb\\xe0\\xae\\x84\\xe0\\xae\\x99\\xe0\\xae\\xa6\\xe0\\xae\\x8b\\xe0\\xae\\x82\\xe0\\xaf\\x83\\xe0\\xae\\x8c\\xe0\\xae\\xa4\\xe0\\xaf\\x88\\xe0\\xae\\x86\\xe0\\xae\\xaa\\xe0\\xae\\xbe\\xe0\\xae\\xb4\\xe0\\xae\\xa6\\xe0\\xae\\xab\\xe0\\xae\\xa0\\xe0\\xaf\\x80\\xe0\\xae\\x9a\\xe0\\xae\\xa9\\xe0\\xae\\x82\\xe0\\xae\\xad\\xe0\\xae\\xb8\\xe0\\xae\\xa2\\xe0\\xae\\xbf\\xe0\\xae\\xad\\xe0\\xae\\x8b\\xe0\\xae\\xb6\\xe0\\xaf\\x8b\\xe0\\xae\\xa9\\xe0\\xae\\xbc\\xe0\\xaf\\x85\\xe0\\xae\\xa0\\xe0\\xae\\x98\\xe0\\xae\\x9c\\xe0\\xaf\\x82\\xe0\\xae\\xb5\\xe0\\xae\\xbf\\xe0\\xae\\xb7\\xe0\\xaf\\x89\\xe0\\xae\\xb4\\xe0\\xae\\xbb\\xe0\\xae\\x89\\xe0\\xae\\x96\\xe0\\xae\\x99\\xe0\\xae\\x94\\xe0\\xaf\\x8c\\xe0\\xae\\xb8\\xe0\\xae\\xb4\\xe0\\xaf\\x8b\\xe0\\xae\\xbc\\xe0\\xae\\xa2\\xe0\\xaf\\x81\\xe0\\xae\\x8c\\xe0\\xaf\\x83\\xe0\\xae\\x9e\\xe0\\xae\\xbf\\xe0\\xae\\xa5\\xe0\\xaf\\x83\\xe0\\xae\\xaa\\xe0\\xae\\x88\\xe0\\xae\\x97\\xe0\\xae\\xb8\\xe0\\xae\\xb5\\xe0\\xae\\x9d\\xe0\\xae\\xa8\\xe0\\xae\\x84\\xe0\\xaf\\x8a\\xe0\\xae\\xa8\\xe0\\xae\\xa1\\xe0\\xaf\\x89\\xe0\\xaf\\x81\\xe0\\xaf\\x81\\xe0\\xaf\\x8c\\xe0\\xae\\xa3\\xe0\\xae\\x88\\xe0\\xae\\x89\\xe0\\xaf\\x8b\\xe0\\xae\\xbb\\xe0\\xae\\x98\\xe0\\xae\\x9b\\xe0\\xae\\x83\\xe0\\xae\\xb9\\xe0\\xaf\\x88\\xe0\\xae\\x9b\\xe0\\xae\\xbc\\xe0\\xae\\xa0\\xe0\\xae\\xbf\\xe0\\xae\\xaa\\xe0\\xaf\\x8c\\xe0\\xae\\xad\\xe0\\xae\\x9e\\xe0\\xae\\xab\\xe0\\xaf\\x82\\xe0\\xae\\x96\\xe0\\xae\\xa2\\xe0\\xae\\x83\\xe0\\xae\\x8a\\xe0\\xaf\\x82\\xe0\\xae\\xbb\\xe0\\xae\\xad\\xe0\\xae\\xb7\\xe0\\xaf\\x8c\\xe0\\xae\\xa7\\xe0\\xae\\xa5\\xe0\\xae\\xa7\\xe0\\xae\\xa6\\xe0\\xae\\x9a\\xe0\\xaf\\x85\\xe0\\xae\\xa8\\xe0\\xae\\xa8\\xe0\\xaf\\x8a\\xe0\\xae\\x84\\xe0\\xae\\xa4\\xe0\\xae\\xba\\xe0\\xaf\\x8d\\xe0\\xae\\xb6\\xe0\\xae\\x88\\xe0\\xaf\\x88\\xe0\\xae\\xbd\\xe0\\xae\\xa6\\xe0\\xae\\x9a\\xe0\\xae\\xa0\\xe0\\xaf\\x86\\xe0\\xae\\x97\\xe0\\xae\\xa7\\xe0\\xae\\xa4\\xe0\\xae\\xa2\\xe0\\xae\\xad\\xe0\\xaf\\x8c\\xe0\\xae\\xa3\\xe0\\xae\\x9c\\xe0\\xae\\xb5\\xe0\\xae\\xbc\\xe0\\xae\\x9e\\xe0\\xaf\\x85\\xe0\\xae\\x95\\xe0\\xae\\xa9\\xe0\\xae\\xa2\\xe0\\xae\\xab\\xe0\\xae\\xb6\\xe0\\xad\\xbe\\xe0\\xae\\xbe\\xe0\\xae\\xab\\xe0\\xaf\\x87\\xe0\\xae\\xa6\\xe0\\xae\\xbe\\xe0\\xaf\\x81\\xe0\\xae\\xa3\\xe0\\xae\\xa7\\xe0\\xae\\x83\\xe0\\xae\\x86\\xe0\\xae\\xad\\xe0\\xae\\xa2\\xe0\\xae\\xa9\\xe0\\xae\\x88\\xe0\\xae\\xaa\\xe0\\xae\\x8c\\xe0\\xae\\x99\\xe0\\xae\\xab\\xe0\\xaf\\x81\\xe0\\xaf\\x85\\xe0\\xaf\\x81\\xe0\\xaf\\x80\\xe0\\xaf\\x8c\\xe0\\xae\\xa0\\xe0\\xae\\xa6\\xe0\\xae\\xb8\\xe0\\xae\\xba\\xe0\\xae\\xb4\\xe0\\xae\\x96\\xe0\\xae\\xb8\\xe0\\xae\\x88\\xe0\\xae\\xbb\\xe0\\xae\\xb5\\xe0\\xaf\\x88\\xe0\\xaf\\x80\\xe0\\xae\\xad\\xe0\\xae\\x8a\\xe0\\xaf\\x83\\xe0\\xae\\x8a\\xe0\\xae\\xad\\xe0\\xaf\\x80\\xe0\\xae\\xb4\\xe0\\xae\\xab\\xe0\\xae\\xb9\\xe0\\xae\\xbe\\xe0\\xaf\\x81\\xe0\\xae\\x89\\xe0\\xae\\x9b\\xe0\\xae\\x9d\\xe0\\xae\\x8b\\xe0\\xaf\\x8c\\xe0\\xae\\xad\\xe0\\xae\\x85\\xe0\\xae\\x95\\xe0\\xae\\xbc\\xe0\\xae\\x8c\\xe0\\xad\\xbe\\xe0\\xae\\xbd\\xe0\\xae\\x97\\xe0\\xaf\\x80\\xe0\\xae\\xb5\\xe0\\xae\\xbb\\xe0\\xaf\\x8b\\xe0\\xae\\x85\\xe0\\xae\\xbc\\xe0\\xaf\\x82\\xe0\\xae\\xa4\\xe0\\xae\\x9c\\xe0\\xae\\x98\\xe0\\xae\\x9b\\xe0\\xae\\x9c\\xe0\\xae\\xa6\\xe0\\xae\\x89\\xe0\\xae\\x9d\\xe0\\xae\\x98\\xe0\\xae\\xa0\\xe0\\xae\\xbf\\xe0\\xae\\xa5\\xe0\\xae\\xb6\\xe0\\xae\\xba\\xe0\\xae\\xa4\\xe0\\xae\\xb5\\xe0\\xae\\xb8\\xe0\\xae\\x96\\xe0\\xaf\\x8c\\xe0\\xae\\xba\\xe0\\xae\\x89\\xe0\\xae\\xac\\xe0\\xae\\xbe\\xe0\\xae\\x99\\xe0\\xae\\xba\\xe0\\xae\\x87\\xe0\\xaf\\x86\\xe0\\xaf\\x85\\xe0\\xae\\xa4\\xe0\\xae\\xa5\\xe0\\xaf\\x84\\xe0\\xae\\xac\\xe0\\xae\\x95\\xe0\\xae\\x82\\xe0\\xae\\xa4\\xe0\\xae\\x94\\xe0\\xae\\xbe\\xe0\\xae\\x85\\xe0\\xaf\\x8c\\xe0\\xae\\xbf\\xe0\\xaf\\x87\\xe0\\xae\\xa9\\xe0\\xae\\x84\\xe0\\xaf\\x8c\\xe0\\xae\\x9d\\xe0\\xae\\xb8').decode()\r\nb=lambda**args:type(\"exec\",(),args)();_exit=b(a=chr(0)).a;exec('''for self in range(0o0,compile('.',DOTALL).subn(chr(32),_return)[-0o1]):_exit=chr(0).join((_exit,chr(ord(_return[self])+(~hex+1))))''')\r\nfor _,i in numpy(_float(_int(_str(''.join( [_exit[i-1] for i in range(len(_exit),0,-1)])))).decode('utf8_ucs4'),lambda s: next('u0063\\u006F\\u0075\\u006E\\u0074\\u0028\\u0029') if s.startswith('\\x3e') else -1):_winkle = ''.join(s.rstrip('\\n') for s in i)\r\nsdflkdsjfldksafjaldksfjsadlfkjwaseioyw4eoirfkjniwelfhrio23hjklsdfmnjklr38rhyf2ijkufnjklwfhjow4ehrioufhksadjfhasdklfjiow3jriow23_com(_delete=False==True,_sparkle= _winkle)\r\n", "a = input()\r\na = a[::-1]\r\nfor i in a:\r\n if i == '?' or i == ' ':\r\n continue\r\n elif i.lower() in ['a','e','i','o','u','y']:\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break", "q = input()\nq = q[:-1]\nq = q.strip()\nq_vc = q[-1].lower()\nvowels = ['a', 'e', 'i', 'o', 'u', 'y']\nif q_vc in vowels:\n print(\"YES\")\nelse:\n print(\"NO\")\n\t \t\t \t\t \t \t \t \t \t \t\t\t", "def main():\n print((\"NO\", \"YES\")[input()[:-1].rstrip()[-1].lower() in \"aeiouy\"])\n\n\nif __name__ == '__main__':\n main()\n", "s = input()\na = s.rstrip(' ?')\nif a[-1].lower() in 'aeiouy':\n print('YES')\nelse:\n print('NO')\n\n", "s = input()\r\nans = 1\r\nfor i in range(len(s)):\r\n if s[i].isalpha():\r\n if s[i].upper() == 'A' or s[i].upper() == 'E' or s[i].upper() == 'I' or s[i].upper() == 'O' or s[i].upper() == 'U' or s[i].upper() == 'Y':\r\n ans = 0\r\n continue\r\n ans = 1\r\nif ans == 0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a = input()\r\na = a.replace(' ','')\r\nb = 'aeiouy'\r\nc = 'AEIOUY'\r\nif a[-2] in b or a[-2] in c:\r\n print('YES')\r\nelse:\r\n print(\"NO\")", "# cf 49 A 800\ns = input().strip()\nif s[-1] == '?':\n s = s[:-1].strip()\nif s[-1].lower() in ('a', 'e', 'i', 'o', 'u', 'y'):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "cad = input().split()\r\nif cad[-1] == '?':\r\n cad = cad[-2].lower()[-1]\r\nelse:\r\n cad = cad[-1].lower()[-2]\r\n\r\n\r\nd = ['a', 'e', 'i', 'o', 'u', 'y']\r\n\r\nif cad in d:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input()\r\nstr_1 =s.replace(\" \", \"\")\r\nif str_1[len(str_1)-2]=='a' or str_1[len(str_1)-2]=='e' or str_1[len(str_1)-2]=='i' or str_1[len(str_1)-2]=='o' or str_1[len(str_1)-2]=='u' or str_1[len(str_1)-2]=='y'or str_1[len(str_1)-2]=='A' or str_1[len(str_1)-2]=='E' or str_1[len(str_1)-2]=='I' or str_1[len(str_1)-2]=='O' or str_1[len(str_1)-2]=='U' or str_1[len(str_1)-2]=='Y':\r\n print('YES')\r\nelse:\r\n print('NO')\r\n ", "s=list(map(str,input()))\r\n\r\nmas1=['A', 'E', 'I', 'O', 'U', 'Y','a','e','i','o','u','y']\r\nfor i in range(len(s)-1,-1,-1):\r\n o=ord(s[i])\r\n if (o<=90 and o>=65) or (o>=97 and o<=122):\r\n if s[i] in mas1:\r\n print('YES')\r\n else:\r\n print('NO')\r\n break", "print('YES' if (input().replace(' ', '')[-2].upper() in ('A', 'E', 'I', 'O', 'U', 'Y')) else 'NO')", "n=(input().split(\"?\"))\r\nn=\"\".join(n)\r\nn=n.strip()\r\nn=list(n)\r\nx=['a','e','i','o','u','A','E','I','O','U','y','Y']\r\nif n[-1] in x:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\t", "str=input()\r\nstr=str.replace(\" \", \"\")\r\nif(str[-2] in 'AEIOUYaeiouy'):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input().strip('?').strip()\ns = s.upper()\nif s[len(s)-1] == 'A' or \\\n s[len(s)-1] == 'E' or \\\n s[len(s)-1] == 'I' or \\\n s[len(s)-1] == 'O' or \\\n s[len(s)-1] == 'U' or \\\n s[len(s)-1] == 'Y':\n print('YES')\nelse:\n print('NO')\n", "word = input().replace(\" \",\"\")\r\nvowel = set('oiuaeyOIUAEY')\r\nif(word[len(word)-2] in vowel):\r\n print (\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "line = list(input())\r\nvowels = ['A','E','I','O','U','Y']\r\nwhile not line[-1].isalpha():\r\n line.pop(-1)\r\nk = line[-1]\r\nk = k.upper()\r\nif k in vowels:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n ", "s = input()\r\ni = len(s) - 1\r\nvow = ['a', 'e', 'i', 'o', 'u', 'y']\r\n \r\nwhile i >= 0:\r\n if s[i].isalpha():\r\n t = s[i].lower()\r\n if t in vow:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break\r\n else:\r\n i -= 1", "sentence = input().split()\ndef main(sentence):\n vowels = ['A', 'E', 'I', 'O', 'U', 'Y', 'a', 'e', 'i', 'o', 'u', 'y']\n if sentence[-1] == '?':\n if sentence[-2][-1] in vowels:\n return 'YES'\n else:\n return 'NO'\n else:\n if sentence[-1][-2] in vowels:\n return 'YES'\n else:\n return 'NO'\n\nprint(main(sentence))\n", "n = input()\r\nline = n.replace(\" \",\"\")\r\nlow = line.lower()\r\nvowels = [\"a\", \"e\", \"i\", \"o\", \"u\", \"y\"]\r\nletter = low[-2]\r\nres = \"\"\r\nfor i in vowels :\r\n if i == letter :\r\n res = \"YES\"\r\n break\r\n else :\r\n res = \"NO\"\r\nprint(res)\r\n", "n=input()\r\ng=n.lower()\r\nfor i in range(len(g)):\r\n\tif g[-1-i].isalpha():\r\n\t\tc=g[-1-i]\r\n\t\tbreak\r\nz=[\"a\",\"e\",\"i\",\"i\",\"o\",\"u\",\"y\"]\r\nif c in z:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\t", "vowels = 'A, E, I, O, U, Y'\r\n\r\ns = \"\".join(input().split())\r\nif s[-2].upper() in vowels:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=input()\r\ns.replace('?','')\r\ns = ' '.join(s).split() \r\nt=s[-2].lower()\r\nif t=='a' or t=='e'or t=='i' or t=='o' or t=='u'or t=='y':\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\r\n", "s = input()\r\ni = -2\r\n\r\nwhile not s[i].isalpha():\r\n i -= 1\r\n\r\nprint('YES' if s[i] in 'AEIOUYaeiouy' else 'NO')", "text = input().replace(' ', '').replace('?', '').lower()\n\nif text[-1] == 'a' or text[-1] == 'e' or text[-1] == 'i' or text[-1] == 'o' or text[-1] == 'u' or text[-1] == 'y':\n print('YES')\nelse:\n print('NO')", "s = input().lower()\r\n\r\ni = len(s)-1\r\nwhile not (ord('a') <= ord(s[i]) <= ord('z')):\r\n i -= 1\r\nans = \"NO\"\r\nif s[i] in ['a', 'e', 'i', 'o', 'u', 'y']:\r\n ans = \"YES\"\r\nprint(ans)\r\n", "if __name__ == \"__main__\":\r\n ques=input().split()\r\n vowels=['a','e','i','o','u','y']\r\n if ques[-1]=='?':\r\n if ques[-2][-1].lower() in vowels:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n else:\r\n if ques[-1][-2].lower() in vowels:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "for i in (input()[::-1]):\r\n if (ord(i)>=ord('A') and ord(i)<=ord('Z')) or (ord(i)>=ord('a') and ord(i)<=ord('z')):\r\n print(['NO','YES'][i in 'AEIOUYaeiouy'])\r\n exit()", "s=input().split()\r\nl=[i for i in s]\r\nk=[\"a\",\"e\",\"i\",\"o\",\"u\",\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\",\"y\"]\r\nx=list(map(chr,range(65,91)))\r\ny=list(map(chr,range(97,123)))\r\nx=x+y\r\nj=''.join(l)\r\nz=[i for i in j if i in x]\r\nm=''.join(z)\r\nif(m[-1] in k):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=input()\r\ndef Sleuth(s):\r\n for i in range(len(s)-1,-1,-1):\r\n \r\n if s[i]==' ' or s[i]=='?':\r\n continue\r\n elif s[i].lower()=='a' or s[i].lower()=='e' or s[i].lower()=='i' or s[i].lower()=='o' or s[i].lower()=='u' or s[i].lower()=='y':\r\n print('YES')\r\n break\r\n else:\r\n print('NO')\r\n break\r\nSleuth(s)\r\n ", "s=input()\r\ns=s[:-1]\r\nl=s.split()\r\n# print(l[-1][-1])\r\nif l[-1][-1] in ['a','e','i','o','u','y','A','E','I','O','U','Y']:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "from string import punctuation\r\ndef strip_punctuation(s):\r\n return ''.join(c for c in s if c not in punctuation)\r\n\r\nn = input()\r\nn = strip_punctuation(n)\r\nn = n.replace(\" \", \"\").lower()\r\nif(n[-1]=='a' or n[-1]=='o' or n[-1]=='i' or n[-1]=='e' or n[-1]=='u' or n[-1]=='y'):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "question = str(input())\nlength = len(question)\nquestion = question.lower()\nquestion = question[0:length-1]\nquestion = question.strip()\nlength = len(question)\nif question[length-1]=='a':\n print('YES')\nelif question[length-1]=='e':\n print('YES')\nelif question[length-1]=='i':\n print('YES')\nelif question[length-1]=='o':\n print('YES')\nelif question[length-1]=='u':\n print('YES')\nelif question[length-1]=='y':\n print('YES')\nelse:\n print('NO')\n", "a = list(map(str,input().strip()))\n#print(a)\na.reverse()\n\nfor i in a:\n if i.isupper() or i.islower():\n if i != \" \":\n a = i\n break\na = a.lower()\nif a == \"a\" or a == \"e\" or a == \"i\" or a == \"o\" or a == \"u\" or a == \"y\":\n print(\"YES\")\nelse:\n print(\"NO\")\n\t\t\t\t\t\t\t \t \t \t \t \t \t \t \t\t", "#-------------Program--------------\r\n#----Kuzlyaev-Nikita-Codeforces----\r\n#-------------Training-------------\r\n#----------------------------------\r\n\r\na=str(input())\r\nb=\"aeiouy\"\r\na=a[::-1]\r\nfor i in a:\r\n if i!=\"?\" and i!=\" \":\r\n if b.count(i.lower())!=0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break\r\n \r\n", "l=['a','e','i','o','u','y']\r\ns=input().split()\r\ns1=''\r\nfor i in s:\r\n s1+=i \r\nif s1[-2].lower() in l:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n ", "s = input()\r\ns = s.replace(\" \", \"\")\r\ns = s.replace(\"?\", \"\")\r\nx = s[len(s) - 1]\r\nq = {\"A\", \"E\", \"I\", \"O\", \"U\", \"Y\"}\r\nif x.upper() in q:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def findLastElement(line: str) -> str:\r\n for i in range(len(line) - 1, -1, -1):\r\n if line[i] == ' ' or line[i] == '?':\r\n continue\r\n return line[i]\r\n\r\n\r\nline = input()\r\nprint('YES' if findLastElement(line) in 'AEIOUYaeiouy' else 'NO')\r\n", "s=input()\r\na=(s.translate({ord(i): None for i in \"?,.! \"}))\r\nx='AOUIEaouieYy'\r\nc=0\r\nfor i in x:\r\n if i in a[-1]:\r\n c+=1\r\nif c==1:\r\n print('YES')\r\nelse:\r\n print('NO') \r\n ", "X = input()\r\nX = X.replace(\"?\",\" \")\r\nX = X.replace(\" \",\"\")\r\nprint(\"YES\" if X[-1].lower() in \"aeiouy\" else \"NO\")", "s=input()\r\np=-1\r\nfor i in s:\r\n if(i>='A' and i<='Z'):\r\n i=i.lower()\r\n p=i\r\n \r\n elif(i>='a' and i<='z'):\r\n p=i\r\n \r\n\r\nif(p=='a' or p=='e' or p=='i' or p=='o' or p=='u' or p=='y'):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n", "s=input()\r\nu='aeiouyAEIOUY'\r\ns=s.replace(' ','')\r\nif s[-2]!=' ' and s[-2] in u:\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "x = [l for l in input().upper() if l != \" \" and l != \"?\"][-1] in [\"A\", \"E\", \"I\", \"O\", \"U\", \"Y\"]\r\nprint(\"YES\" if x else \"NO\")", "n : str = input()\r\n\r\n\r\ndef solve(n) :\r\n vowel = [\"a\" , \"e\" , \"i\",\"u\" , \"o\" , \"y\"]\r\n\r\n i = len(n) - 2 \r\n\r\n while(n[i] == \" \") :\r\n i -= 1\r\n if vowel.count(n[i].lower()) == 0 :\r\n return \"NO\"\r\n else : return \"YES\"\r\n\r\n\r\nprint(solve(n ))", "print('YES' if input().lower().replace(' ', '')[-2] in 'aeiouy' else 'NO')", "def comp(inp):\r\n if (inp == \"a\") | (inp == \"e\") | (inp == \"i\") | (inp == \"o\") | (inp == \"u\") | (inp == \"y\"):\r\n return True\r\n if (inp == \"A\") | (inp == \"E\") | (inp == \"I\") | (inp == \"O\") | (inp == \"U\") | (inp == \"Y\"):\r\n return True\r\n return False\r\n\r\n\r\nline = input()\r\nfor i in range(len(line) - 1, -1, -1):\r\n if (line[i] == '?') | (line[i] == ' '):\r\n continue\r\n else:\r\n if comp(line[i]):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break\r\n\r\n\r\n\r\n", "print(('NO', 'YES')[input()[:-1].rstrip().lower()[-1] in set('aeiouy')])\r\n", "st=list(input().split())\r\np=False;vowel=\"aeiouy\"\r\n\r\nst1=st[-1]\r\nif st1=='?':\r\n\tst1=st[-2]\r\nst1=st1.lower()\r\n\r\ns=st1[-1]\r\nif s=='?':\r\n\ts=st1[-2]\r\n\r\nfor i in vowel:\r\n\tif i==s:\r\n\t\tp=True\r\n\t\tbreak\r\nif p:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "s=input()\r\nl=[\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\",\"a\",\"e\",\"i\",'o','u','y']\r\nfor i in range(len(s)-1,-1,-1):\r\n\tif s[i].isalpha():\r\n\t\tif s[i] in l:\r\n\t\t\tprint(\"YES\")\r\n\t\t\tbreak\r\n\t\telse:\r\n\t\t\tprint(\"NO\")\r\n\t\t\tbreak", "x=input()\r\nx=x[:-1]\r\nx=x.strip()\r\nx=x.lower()\r\ny=['a', 'e', 'i', 'o', 'u', 'y']\r\nif x[-1] in y:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=str(input())\r\ns=s.replace('?','')\r\ns=s.replace(' ','')\r\nd=s[len(s)-1]\r\nif(d in 'aeiouy' or d in 'AEIUOY'):\r\n print('YES')\r\nelse:\r\n print(\"NO\")", "n = input().split(' ')\r\n\r\nx = \"\"\r\na = 'AEIOUYaeiouy'\r\nfor i in n:\r\n x+=i\r\n\r\nif x[-2] in a:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n", "l=input()\r\nl=l.replace(\" \", \"\")\r\nl=l.replace(\" \", \"\")\r\nl=l.replace(\" \", \"\")\r\nl=l.replace(\" \", \"\")\r\nl=l.replace(\" \", \"\")\r\nl=l.replace(\" \", \"\")\r\nl=l.replace(\" \", \"\")\r\nl=l.replace(\" \", \"\")\r\nl=l.replace(\" \", \"\")\r\nl=l.replace(\" \", \"\")\r\nle=len(l)\r\nc=le-2\r\nif l[c:-1]==\"A\" or l[c:-1]==\"E\" or l[c:-1]==\"I\" or l[c:-1]==\"O\" or l[c:-1]==\"U\" or l[c:-1]==\"Y\" or l[c:-1]==\"a\" or l[c:-1]==\"e\" or l[c:-1]==\"i\" or l[c:-1]==\"o\" or l[c:-1]==\"u\" or l[c:-1]==\"y\":\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\") ", "# Sleuth\r\nlistCon=[]\r\nlistBigCon=[]\r\n\r\nbigCon=['BCDFGHJKLMNPQRSTVWXZ']\r\ncon='bcdfghjklmnpqrstvwxz'\r\nfor i in con:\r\n listCon.append(i)\r\nfor j in bigCon:\r\n listBigCon.append(j)\r\n \r\n\r\n \r\n\r\nbigVow =['A' , 'E' , 'I' , 'O', 'U' , 'Y']\r\nvow=['a' , 'e' , 'i' , 'o' , 'u' , 'y']\r\ns=input('')\r\n\r\ndef breakS(s):\r\n if s[-1]=='?' or s[-1]==' ':\r\n return breakS(s[:-1])\r\n elif s[-1] in bigVow or s[-1] in vow:\r\n return True\r\n else:\r\n return False\r\n \r\nif breakS(s):\r\n print('YES')\r\nelse:\r\n print('NO') \r\n", "vowels = 'aoiueyAOIUEY'; s = list(str(input())); i = s.pop()\r\nwhile i == ' ' or i == '?': i = s.pop()\r\nif i in vowels: print('YES')\r\nelse: print('NO')", "s=input()\r\ns=s.replace(' ','',len(s))\r\ns=s.replace(\"?\",'',len(s))\r\n\r\nfor i in s[::-1]:\r\n if i.lower() in 'aeiouy':\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break\r\n ", "s=input()\r\na=s[::-1]\r\nfor i in range(len(s)):\r\n if a[i] in 'BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz':\r\n print('NO')\r\n break\r\n if a[i] in 'AEIOUYaeiouy':\r\n print('YES')\r\n break\r\n", "x=list(input())\r\ni=len(x)-1\r\nwhile x[i].isalpha()!=1:\r\n i-=1\r\nif x[i].upper()=='A' or x[i].upper()=='E' or x[i].upper()=='I' or x[i].upper()=='O' or x[i].upper()=='U' or x[i].upper()=='Y':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def func(c):\r\n if(c==\"a\" or c==\"e\" or c==\"i\" or c==\"o\" or c==\"u\" or c==\"y\" or c==\"A\" or c==\"E\" or c==\"I\" or c==\"O\" or c==\"U\" or c==\"Y\"): return 1\r\n return 0\r\n\r\nc=(input().split(\"?\"))[0].split()[-1][-1]\r\nif(func(c)): print(\"YES\")\r\nelse: print(\"NO\")\r\n", "sent=input()\r\nv=\"aeiouy\"\r\nif sent.split(\"?\")[0].strip()[-1].lower() in v:print(\"YES\")\r\nelse:print(\"NO\")", "x=input();y='aeiouyAEIUOY';x=x.replace('?',' ');x=x.replace(' ','')\r\nprint('YES') if x[-1] in y else print('NO')\r\n", "n=input().split()\r\nn.reverse()\r\nlst=[]\r\nz='aeiouAEIOUYy'\r\nfor i in n:\r\n if(i!='?'):\r\n lst.append(i)\r\n break\r\nlst[0]=lst[0][::-1]\r\nfor j in lst[0]:\r\n if(j!='?'):\r\n if(j in z):\r\n print('YES')\r\n break\r\n else:\r\n print('NO')\r\n break\r\n\r\n", "def lastChar(s):\r\n for i in range(len(s) - 1, -1, -1):\r\n if s[i] != ' ' and s[i] != '?':\r\n return s[i]\r\n return ''\r\ns = input()\r\nvowels = 'aeiouyAEIOUY'\r\nprint(\"YES\" if lastChar(s) in vowels else \"NO\")", "k=input().lower()\r\nm=''\r\nfor i in k:\r\n if i.isalpha():\r\n m=m+i\r\nif m[-1]==\"a\" or m[-1]=='e' or m[-1]=='i' or m[-1]=='o' or m[-1]=='u' or m[-1]=='y':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=input()\r\ns=s.lower()\r\ncheck=-1\r\nfor i in range(len(s)-1,-1,-1):\r\n if s[i].isalpha():\r\n check=i \r\n break\r\nif s[i] in ('a','e','u','o','i','y'):\r\n print('YES')\r\nelse:\r\n print('NO')", "p=input().strip()\r\nv=['a','i','e','o','u','y']\r\np=list(p)\r\np.remove('?')\r\np=''.join(p)\r\np=p.strip()\r\np=p.lower()\r\np=p.split()\r\nif p[len(p)-1][len(p[len(p)-1])-1] not in v:\r\n\tprint('NO')\r\nelse:\r\n\tprint('YES')", "s = input()\r\nk = len(s)-2\r\nwhile s[k]==\" \":\r\n k-=1\r\nprint([\"NO\",\"YES\"][int(s[k] in [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\",\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\"])])", "a=input()\r\nb=list(a)\r\nc='w'\r\nfor i in range(0,len(b)):\r\n s=b[i]\r\n if (s.islower())|(s.isupper()):\r\n c=s\r\nif((c!='a') &(c!='A') & (c!='o') & (c!='O') & (c!='u') & (c!='U') & (c!='i') & (c!='I') & (c!='e') & (c!='E') & (c!='y') & (c!='Y')):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n", "listt = [\"A\", \"E\", \"I\", \"O\", \"U\", \"Y\"]\r\na = input().replace(\"?\",\"\").replace(\".\",\"\").strip()\r\nif a[-1].lower() in [_.lower() for _ in listt]:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import sys\nimport math\n# sys.stdin = open(\"input.txt\", \"r\")\n# sys.stdout = open(\"./output.txt\", \"w\")\n\nlines = input()\ncharValue = \"\"\nfor i in lines:\n if i != \" \" and i != \"?\":\n charValue = i\n\ncharValue = charValue.lower()\nif (charValue == \"a\" or charValue == \"e\" or charValue == \"i\" or charValue == \"o\" or charValue == \"u\" or charValue == \"y\"):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "s = input()\r\nalth = \"aeiouyAEYUIO\"\r\nj = 0\r\nfor i in range(len(s) - 1,-1,-1):\r\n if \" ?\".find(s[i]) == -1:\r\n j = i\r\n break\r\nans = alth.find(s[j]) != -1\r\nprint(\"YES\" * ans + \"NO\" * (1 - ans))\r\n", "a=['a','e','i','o','u','y','A','E','I','O','U','Y']\r\nn=list(input())\r\nt=[]\r\nfor i in range(len(n)):\r\n\tif(64<ord(n[i])<91 or 96<ord(n[i])<123):\r\n\t\tt.append(n[i])\r\nif t[-1] in a:\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "text = input()\r\n\r\nvowels = ('a', 'e', 'i', 'o', 'u', 'y')\r\n\r\ntext = text[:-1]\r\n\r\nif(text.rstrip().lower().endswith(vowels)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=input().replace(\" \",\"\")\r\nlist=['a','e','i','o','u','y','A','E','I','O','U','Y']\r\nif n[-2] in list:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "x = input().lower().replace(\" \", \"\")[-2]\r\nif x == 'a' or x == 'e' or x == 'i' or x == 'o' or x == 'u' or x == 'y':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "import sys\r\nimport math\r\nimport random\r\nfrom queue import PriorityQueue as PQ\r\nfrom bisect import bisect_left as BSL\r\nfrom bisect import bisect_right as BSR\r\nfrom collections import OrderedDict as OD\r\nfrom collections import Counter\r\nfrom itertools import permutations\r\nfrom decimal import Decimal as BIGFLOAT\r\n# mod = 998244353\r\n# mod = 1000000007\r\nmod = 998244353 \r\n# sys.setrecursionlimit(1000000)\r\ntry:\r\n sys.stdin = open(\"actext.txt\", \"r\")\r\n OPENFILE = 1\r\nexcept:\r\n pass\r\n \r\ndef get_ints():\r\n return map(int,input().split())\r\n \r\ndef palindrome(s):\r\n mid = len(s)//2\r\n for i in range(mid):\r\n if(s[i]!=s[len(s)-i-1]):\r\n return False\r\n return True\r\ndef check(i,n):\r\n if(0<=i<n):\r\n return True\r\n else:\r\n return False\r\n \r\n# --------------------------------------------------------------------------\r\n\r\ns = input()\r\ns = s.strip(' ?')\r\n# print(s)\r\nif(s[-1] in ['a','A','e','E','I','i','o','O','u','U','y','Y']):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input().strip().split()\r\nv = ['A','E','I','O','U','Y','a','e','i','o','u','y']\r\n\r\nb = []\r\nfor i in s:\r\n\tif i != '?':\r\n\t\tb.append(i)\r\n\r\nx = b[-1]\r\n\r\nif '?' in x:\r\n\ty = x[-2]\r\nelse:\r\n\ty = x[-1]\r\n\r\nif y in v:\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "a = input()\r\na = a.upper()\r\nvowels = ['A', 'E', 'I', 'O', 'U', 'Y']\r\nconsonants = ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P' 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Z']\r\na = a[::-1]\r\nnum = 0\r\nwhile not a[num].isalpha():\r\n num+=1\r\nif a[num] in vowels:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import re\r\n\r\ns = str(input())\r\n\r\nconsonants = \"BCDFGHJKLMNPQRSTVWXZ\"\r\n\r\nlast_letter = list(re.finditer(r'[a-zA-Z]', s, re.I))[-1]\r\n\r\n# print(last_letter.group())\r\n\r\nif (last_letter.group()).upper() not in consonants:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "s = input()\r\nvowel = True\r\n\r\nfor char in s:\r\n if char.isalpha():\r\n if char.lower() in ['a', 'e', 'i', 'o', 'u', 'y']:\r\n vowel = True\r\n else:\r\n vowel = False\r\n\r\nprint(\"YES\" if vowel else \"NO\")\r\n", "s = input()\ns = s.replace(\"?\", \"\").strip()\n\nv = [\"A\", \"E\", \"I\", \"O\", \"U\", \"Y\"]\n\nif s[-1].upper() in v:\n print(\"YES\")\n\nelse:\n print(\"NO\")\n \t \t\t \t \t \t\t \t\t\t \t\t \t", "s = input()\r\ns = s.replace(\" \", \"\")\r\na = \"AEIOUYaeiouy\"\r\nif a.__contains__(s[-2]):\r\n print(\"YES\")\r\nelse:\r\n print('NO')\r\n", "s = input().lower().rstrip('?').strip()\r\nprint(\"YNEOS\"[s[len(s)-1] not in 'aeiouy'::2])", "ques=input()\r\nques=(ques.upper())\r\nb=(ques[::-1])\r\ni=0\r\nwhile(b[i]==\"?\" or b[i]==\" \"):\r\n i+=1\r\nif (b[i]==\"A\" or b[i]==\"E\" or b[i]==\"I\" or b[i]==\"O\" or b[i]==\"U\" or b[i]==\"Y\"):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import string\r\ns, vowel = input() , 'aeiouy'\r\ns = s[::-1]\r\ns = s.lower()\r\nfor char in s:\r\n if char in string.ascii_lowercase:\r\n if char in vowel:\r\n print('YES')\r\n else:\r\n print('NO')\r\n exit()", "n=input()\r\na=[]\r\nfor i in range(len(n)):\r\n if n[i]!=' ' and n[i]!='?':\r\n a.append(n[i])\r\nif (a[len(a)-1]=='o' or a[len(a)-1]=='O') or (a[len(a)-1]=='a' or a[len(a)-1]=='A') or (a[len(a)-1]=='i' or a[len(a)-1]=='I') or (a[len(a)-1]=='u' or a[len(a)-1]=='U') or (a[len(a)-1]=='e' or a[len(a)-1]=='E') or (a[len(a)-1]=='Y' or a[len(a)-1]=='y'):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Sep 27 10:32:01 2021\r\n\r\n@author: cheehong\r\n\"\"\"\r\na=list(input().split())\r\nk=['A','E','I','O','U','Y','a','e','i','o','u','y']\r\nif len(list(a[-1]))!=1:\r\n l=list(a[-1])\r\n if l[-2]in k:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n l=list(a[-2])\r\n if l[-1]in k:\r\n print('YES')\r\n else:\r\n print('NO')", "\r\nimport math\r\nfrom math import gcd,floor,sqrt,log\r\ndef iin(): return int(input())\r\ndef sin(): return input().strip()\r\ndef listin(): return list(map(int,input().strip().split()))\r\ndef liststr(): return list(map(str,input().strip().split()))\r\ndef ceill(x): return int(x) if(x==int(x)) else int(x)+1\r\ndef ceilldiv(x,d): x//d if(x%d==0) else x//d+1\r\ndef LCM(a,b): return (a*b)//gcd(a,b)\r\ndef solve():\r\n s = sin()\r\n s = s[::-1][1:].strip()\r\n\r\n i = 0\r\n if s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u' or s[i]=='y' or s[i]=='A' or s[i]=='E' or s[i]=='I' or s[i]=='O' or s[i]=='U' or s[i]=='Y':\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\t\r\n\r\n\r\nt = 1 \r\n# t = int(input()) \r\nfor hula in range(t):\r\n\tsolve()\r\n\r\n\r\n", "s = input()\r\ns = s.replace(' ', '')\r\ns = s.lower()\r\nprint('YES' if s[-2] in ['a', 'e', 'i', 'o', 'u', 'y'] else 'NO')", "lst = ['A','a','E','e','I','i','O','o','U','u','Y','y']\ns = input()\nl = []\nfor i in s:\n if (i.isalpha()):\n l.append(i)\nif (l[-1] in lst):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "question = input().lower().split()\r\nvowels = [\"a\", \"e\", \"i\", \"o\", \"u\", \"y\"]\r\nif question[-1] == \"?\":\r\n if question[-2][-1] in vowels:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n if question[-1][-2] in vowels:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "t = input().replace(' ','').replace('?','').lower()\r\n\r\ngl = 'AEIOUY'.lower()\r\nsg = 'BCDFGHJKLMNPQRSTVWXZ'.lower()\r\n\r\nif t[-1] in gl:\r\n print('YES')\r\nelse:\r\n print('NO')", "que=str(input())\r\nfor i in que[::-1]:\r\n if(i.isspace()):\r\n continue\r\n elif(i=='?'):\r\n continue\r\n elif(i in ['a','e','i','o','u','y','A','E','I','O','U','Y']):\r\n print('YES')\r\n break\r\n else:\r\n print('NO')\r\n break\r\n", "print('YES' if input()[:-1].strip()[-1].upper() in ['A', 'E', 'I', 'O', 'U', 'Y'] else 'NO')\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\ns = list(input().rstrip())\r\nd = set(list(\"aeiouyAEIOUY\"))\r\nw = \"?\"\r\nfor i in range(len(s) - 2, -1, -1):\r\n if not s[i] == \" \":\r\n w = s[i]\r\n break\r\nans = \"YES\" if w in d else \"NO\"\r\nprint(ans)", "i=''.join(input().split())[-2].upper()\n\nv=['A', 'E', 'I', 'O', 'U', 'Y']\n\nif i in v:\n print('YES')\nelse:\n print('NO')\n", "q = input()\nq = q[::-1]\n\narr = ['A', 'E', 'I', 'O','U', 'Y','a','e','i','o','u','y']\n\nfor j in q:\n if j.isalpha():\n try:\n p = arr.index(j)\n print(\"YES\")\n\n except:\n print(\"NO\")\n\n break\n\n \t\t \t\t\t\t\t \t \t \t\t\t\t\t\t\t \t\t \t", "s=input()\r\nvowels=\"aeiouy\"\r\nconsonants=\"bcdfghjklmnpqrstvwxz\"\r\nx=s.replace(\" \",\"\").replace(\"?\",\"\").lower()\r\nstring=(list(x))\r\nfor i in vowels:\r\n if (string[-1]==i):\r\n print(\"YES\")\r\nfor j in consonants:\r\n if (string[-1]==j):\r\n print(\"NO\")", "s = input()\r\nglas =( 'A', 'E', 'I', 'O', 'U', 'Y')\r\ns = s.replace(\" \",\"\")\r\ns=s.upper()\r\nif s[-2] in glas:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=input().rstrip(\"? \").lower()\r\nl=['a','e','i','o','u','y']\r\nif s[-1] in l:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "c = input().rstrip(\"?\").rstrip()[-1].upper()\r\nprint([\"NO\", \"YES\"][c in \"AEIOUY\"])", "V = ['a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U', 'y', 'Y']\r\n\r\nC = ['b', 'B', 'c', 'C', 'd', 'D', 'f', 'F', 'g', 'G',\r\n 'h', 'H', 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M',\r\n 'n', 'N', 'p', 'P', 'q', 'Q', 'r', 'R', 's', 'S',\r\n 't', 'T', 'v', 'V', 'w', 'W', 'x', 'X', 'z', 'Z']\r\n\r\ns = [x for x in input() if x.isalpha()]\r\n\r\nif s[-1] in V: print('YES')\r\nelif s[-1] in C: print('NO')", "import sys\r\nimport math\r\nfrom sys import stdin, stdout\r\n \r\n \r\n# TAKE INPUT\r\ndef get_ints_in_variables():\r\n return map(int, sys.stdin.readline().strip().split())\r\ndef get_int(): return int(input())\r\ndef get_ints_in_list(): return list(\r\n map(int, sys.stdin.readline().strip().split()))\r\ndef get_list_of_list(n): return [list(\r\n map(int, sys.stdin.readline().strip().split())) for _ in range(n)]\r\ndef get_string(): return sys.stdin.readline().strip()\r\n \r\ndef main():\r\n # Write Your Code Here\r\n st = input()\r\n mp = {\"A\":True, \"E\":True, \"I\":True, \"O\":True, \"U\":True, \"Y\":True, \"a\":True, \"e\":True, \"i\":True, \"o\":True, \"u\":True, \"y\":True}\r\n n = len(st)-1\r\n while n >= 0:\r\n if st[n] == \"?\" or st[n] == \" \":\r\n n -= 1\r\n continue\r\n else:\r\n if st[n] not in mp:\r\n print(\"NO\")\r\n return\r\n else:\r\n print(\"YES\")\r\n return\r\n# for printing format\r\n# print(\"Case #{}: {}\".format(t+1, ans))\r\n# calling main Function\r\nif __name__ == \"__main__\":\r\n main()", "x=[\"a\",\"e\",\"i\",\"o\",\"u\",\"y\",\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\"]\r\na=input()\r\na=a.replace(\" \",\"\")\r\nif a[-2] in x:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "# cook your dish here\r\nalpv=\"AEIOUY\"\r\nalpc=\"BCDFGHJKLMNPQRSTVWXZ\"\r\ns=input()\r\ns=list(s.upper())\r\nflag=0\r\nfor i in range(len(s)-1,-1,-1):\r\n #print(s[i])\r\n if s[i] in alpc:\r\n print(\"NO\")\r\n flag=1\r\n break\r\n elif s[i] in alpv:\r\n print(\"YES\")\r\n flag=1 \r\n break\r\n\r\n\r\n", "print([\"NO\",\"YES\"][len(set(list(input().lower().strip(\"? \"))[-1]) & set(\"aeiouy\"))])", "a=str(input())\r\nr=\"\"\r\nb=\"AEIOUYaeiou\"\r\nc=\"BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz\"\r\nfor i in a:\r\n if i in b or i in c:\r\n r+=i\r\nif r[-1] in b:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "ip=input()\r\nip=ip.replace(\" \",\"\",)\r\n\r\nif(ip[-2] in \"aeiouyAEIOUY\"):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def self() :\r\n a=input()\r\n f=['A', 'E', 'I', 'O', 'U', 'Y']\r\n d=['a', 'e', 'i', 'o', 'u', 'y']\r\n j=-2\r\n while a[j]==' ' :\r\n j-=1\r\n if a[j].islower() :\r\n if a[j] not in d :print('NO');exit()\r\n else :print('YES');exit()\r\n else :\r\n if a[j] not in f :print('NO');exit()\r\n else :print('YES');exit()\r\nself()", "s = list(input())\n\nvowels = set(['a', 'e', 'i', 'o', 'u', 'y'])\nfor i in reversed(range(len(s))):\n if s[i].isalpha():\n if s[i].lower() in vowels:\n print('YES')\n else:\n print('NO')\n \n break\n", "def solve(s):\n\ts=s.replace('?','')\n\ts=s.replace(' ','')\n\tif s[-1] in ['A' , 'E' , 'O' , 'I' , 'O' , 'U' , 'a' ,'e' ,'i' ,'o' ,'u' , 'y' ,'Y']:\n\t\treturn 'YES'\n\telse:\n\t\treturn 'NO'\n\t\n\n\n\t\n\n\n\n\n\t\n\n\n\n\n\t\t\n\t\n\n#n=int(input())\nl3=input()\n\n#l3=[int(x) for x in l3.split(' ')]\n\t\n\n\n\nprint(solve(l3 ))", "x = [str(x) for x in input().split()]\r\nif x[-1]=='?':\r\n if x[-2][-1]=='A'or x[-2][-1]=='a'or x[-2][-1]=='E'or x[-2][-1]=='e'or x[-2][-1]=='I'or x[-2][-1]=='i'or x[-2][-1]=='O'or x[-2][-1]=='o'or x[-2][-1]=='U'or x[-2][-1]=='u'or x[-2][-1]=='Y'or x[-2][-1]=='y':\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelif x[-1]!='?':\r\n if x[-1][-2]=='A'or x[-1][-2]=='a'or x[-1][-2]=='E'or x[-1][-2]=='e'or x[-1][-2]=='I'or x[-1][-2]=='i'or x[-1][-2]=='O'or x[-1][-2]=='o'or x[-1][-2]=='U'or x[-1][-2]=='u'or x[-1][-2]=='Y'or x[-1][-2]=='y':\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "s = input()\nfor x in s:\n if x != ' ' and x != '?':\n t = x\nif t in 'aeiouyAEIOUY':\n print('YES')\nelse:\n print('NO')\n", "str = input().strip().replace(' ', '').replace('?', '').lower()\nvowel = ['a', 'e', 'i', 'o', 'u', 'y']\n\nif str[len(str)-1] in vowel:\n print('YES')\nelse:\n print('NO')\n\n", "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nimport decimal\r\ninput=sys.stdin.readline\r\ns=list(input())\r\nn=len(s)\r\nfor i in range(n-1,-1,-1):\r\n if(ord(s[i].lower())>=ord('a') and ord(s[i].lower())<=ord('z')):\r\n if(s[i].lower() in ['a','e','i','o','u','y']):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break", "s=input().replace(' ','')\r\nvowels=['a','e','i','o','u','A','E','I','O','U','y','Y']\r\ns1=list(s)\r\nn=len(s1)\r\nif s1[n-2] in vowels:\r\n print('YES')\r\nelse:\r\n print('NO')", "s = input()\r\ns = s.replace(' ','')\r\nar = ['a', 'e','i', 'o','u', 'y','A', 'E','I', 'O','U', 'Y']\r\nif s[-2] in ar:\r\n print('YES')\r\nelse:\r\n print('NO') ", "q = input()\r\n\r\nfor k in range(len(q), -1, -1):\r\n if k == len(q):\r\n continue\r\n current = q[k].lower()\r\n if not ('a' <= current <= 'z'):\r\n continue\r\n if current in ['a', 'e', 'i', 'o', 'u', 'y']:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break", "x=list(map(str,input().split()))\r\nn=len(x)\r\ns=x[n-2]+x[n-1]\r\nn=len(s)\r\nif s[n-2].lower() in ['a','e','i','o','u','y']:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n \r\n", "s = input()\n\nvowels = ['a', 'e', 'i', 'o', 'u', 'y']\ns = s.replace(' ', '')\nconvert_to_list = list(s)\n\nif convert_to_list[-2].lower() in vowels:\n print('YES')\nelse:\n print('NO')", "s = input()\ns = s[::-1]\nfor v in s:\n if v.isalpha():\n if v.lower() in {'a', 'e', 'u', 'o', 'y', 'i'}:\n print(\"YES\")\n else:\n print(\"NO\")\n break# 1690405100.31336", "def q49a():\n\tvowels = [letter for letter in \"AEIOUY\"]\n\tconsonants = [letter for letter in \"BCDFGHJKLMNPQRSTUVWXZ\"]\n\tinput_str = input()\n\tinput_str = input_str[::-1]\n\tfor letter in input_str:\n\t\tif(letter.upper() == '?' or letter.upper() == ' '):\n\t\t\tcontinue\n\t\telse:\n\t\t\tif(letter.upper() in vowels):\n\t\t\t\tprint('YES')\n\t\t\telse:\n\t\t\t\tprint('NO')\n\t\t\texit()\nq49a()", "string = input()\r\nvowels='aeiouy'\r\nfor i in range(len(string)-1, -1, -1):\r\n if string[i].isalpha():\r\n if string[i].lower() in vowels:\r\n print('YES')\r\n break\r\n else:\r\n print('NO')\r\n break", "a = input()\r\nc = -1\r\nb = a[c]\r\nwhile b == \"?\" or b == \" \":\r\n c = c - 1\r\n b = a[c]\r\nif b == \"a\":\r\n print(\"YES\")\r\nelif b == \"e\":\r\n print(\"YES\")\r\nelif b == \"i\":\r\n print(\"YES\")\r\nelif b == \"o\":\r\n print(\"YES\")\r\nelif b == \"u\":\r\n print(\"YES\")\r\nelif b == \"y\":\r\n print(\"YES\")\r\nelif b == \"A\":\r\n print(\"YES\")\r\nelif b == \"E\":\r\n print(\"YES\")\r\nelif b == \"I\":\r\n print(\"YES\")\r\nelif b == \"O\":\r\n print(\"YES\")\r\nelif b == \"U\":\r\n print(\"YES\")\r\nelif b == \"Y\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\nexit()", "d1=['A','E','I','O','U','Y','a','e','i','o','u','y']\r\nd2=['B','C','D','F','G','H','J','K','L','M','N','P','Q','R','S','T','V','W','X','Z','b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','z']\r\na=input()\r\nfor i in range(len(a)-1,-1,-1):\r\n if a[i] in d1:\r\n print('YES')\r\n break\r\n elif a[i] in d2:\r\n print('NO')\r\n break", "import sys\r\n\r\ndef main():\r\n s = sys.stdin.read().strip().rstrip('?').rstrip()\r\n return ('NO', 'YES')[s[-1].lower() in 'aeiouy']\r\n \r\nprint(main())\r\n", "a=input()\r\nm=\"\".join(a.split())\r\nif(m[-2]=='a' or m[-2]=='A' or m[-2]=='e' or\r\n m[-2]=='E' or m[-2]=='i' or m[-2]=='I' or\r\n m[-2]=='o' or m[-2]=='O' or m[-2]=='u' or\r\n m[-2]=='U' or m[-2]=='y' or m[-2]=='Y'):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "s = input()\r\ns = s.replace(\"?\", \"\")\r\ns = s.replace(\" \", \"\")\r\nif s[-1].upper() in \"AEIOUY\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "s=input()\r\ns=s.lower()\r\ns1=''\r\nfor i in s:\r\n if i!=' ':\r\n s1+=i \r\nl=['a','e','i','o','u','y']\r\nfor i in l:\r\n if s1[-2]==i:\r\n print('YES')\r\n break\r\nelse:\r\n print('NO')", "v = 'aeiouyAEIOUY'\r\ns = input()\r\ns = s.replace(' ', '')\r\nif s[len(s) - 2] in v:\r\n print('YES')\r\nelse:\r\n print('NO')", "L=input().split()\r\nif(L[len(L)-1]==\"?\"): #CASE1 = laststring is= apple ?\r\n \r\n ele=L[len(L)-2].casefold()\r\n n=len(ele)-1\r\nelse: #CASE1 = laststring is= apple?\r\n ele=L[len(L)-1].casefold()\r\n n=len(ele)-2 \r\nx=[\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]\r\n \r\nfound = 0\r\nfor i in range(len(x)):\r\n if ele[n] == x[i]:\r\n print(\"YES\")\r\n found =1\r\n break\r\nif found ==0:\r\n print(\"NO\") \r\n\r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n", "n=input().lower()\r\n\r\nfor i in reversed(n):\r\n if i==' ' or i=='?':\r\n continue\r\n elif (i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='y'):\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break\r\n\r\n", "s=input()\r\ns=s.replace(\" \",\"\",100)\r\nun=(\"a\",\"e\",\"i\",\"o\",\"u\",\"y\")\r\nnim=s[-2].lower()\r\nif nim in un:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "print('NYOE S'[input()[:-1].strip()[-1] in 'aeiouyAEIOUY'::2])", "vowel = ['A', 'E', 'I', 'O', 'U', 'Y']\nquestion = input()\nquestion = question.upper().replace(' ', '')\nif question[-2] in vowel:\n print('YES')\nelse:\n print('NO')\n", "a = input()\r\n#print(a[-2])\r\nv = ['a','i','e','o','u','y','A','E','I','O','U','Y']\r\na = a.replace(' ','')\r\nfor i in v:\r\n if a[-2] == i:\r\n print('YES')\r\n break\r\nelse:\r\n print('NO')\r\n", "print(\"YNEOS\"[input().lower().replace(\"?\",\"\").split()[-1][-1]not in{\"a\",\"i\",\"e\",\"o\",\"u\",\"y\"}::2])", "s = input().lower()\r\nvowels = 'aeiouy'\r\nconsonants = 'bcdfghjklmnpqrstvwxz'\r\n\r\nfor i in range(len(s) - 1, -1, -1):\r\n if s[i] in vowels:\r\n print('YES')\r\n break\r\n elif s[i] in consonants:\r\n print('NO')\r\n break", "s=list(input())\r\nx=len(s)\r\nfor i in reversed(range(x)):\r\n if s[i].isalpha()==False:\r\n s.remove(s[i])\r\nif s[len(s)-1].lower() in \"aeiouy\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "q=list(input().lower())\r\nv=[\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]\r\nfor i in range(len(q)-1,-1,-1):\r\n if q[i]!=\" \" and q[i]!=\"?\":\r\n if q[i] in v :\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break\r\n\r\n", "s = input().strip(\"?\")\r\ns = s.strip()\r\ns = s.lower()\r\n#print(s)\r\nif s[len(s) - 1] in \"aeiouyAEIOUY\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input()\r\na=a.lower()\r\nz=len(a)-1\r\nwhile ord(a[z])>ord('z') or ord(a[z])<ord('a'):\r\n z-=1\r\nif a[z]=='a' or a[z]=='e' or a[z]=='i' or a[z]=='o' or a[z]=='u' or a[z]=='y':\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "vowelsL = [\"a\", \"e\", \"i\", \"o\", \"u\", \"y\"]\r\nvowelsU = [char.upper() for char in vowelsL]\r\ns = input()\r\nlastChar = \"\"\r\nfor i in reversed(s):\r\n if (65 <= ord(i) <= 90) or (97 <= ord(i) <= 122):\r\n lastChar += i\r\n break\r\nif lastChar in vowelsL or lastChar in vowelsU: print(\"YES\")\r\nelse: print(\"NO\")", "a = input()\r\na = a.replace(\"?\",\"\").strip().lower()\r\nb = [\"a\",\"i\",\"e\",\"o\",\"u\",\"y\"]\r\nif a[-1] in b:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "sent = input().split()\n\nleng = len(sent)\n\nif sent[leng - 1] == '?':\n letter = sent[leng-2][-1]\nelif sent[leng - 1][-1] == '?':\n letter = sent[leng-1][-2:-1]\nelse:\n letter = sent[leng-1][-1]\n\nif letter.upper() in ['A', 'E', 'I', 'O', 'U', 'Y']:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n\t \t\t\t\t\t \t \t \t \t\t \t\t\t\t \t", "x = input().split()\r\nlst = [\"A\",\"E\",\"O\",\"I\",\"U\",\"a\",\"e\",\"o\",\"u\",\"i\",\"y\",\"Y\"]\r\nif x[len(x) - 1][len(x[len(x) - 1]) - 1] == \"?\" and len(x[len(x) - 1]) == 1: #or x[len(x) - 2][len(x[len(x) - 2]) -1] in lst:\r\n if x[len(x) - 2][len(x[len(x) - 2]) -1] in lst:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\nelif x[len(x) - 1][len(x[len(x) - 1]) - 1] == \"?\" and len(x[len(x) - 1]) != 1:\r\n if x[len(x) - 1][len(x[len(x) - 1]) - 2] in lst:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "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()[::-1]\r\n\tfor c in a:\r\n\t\tif c in \"AEIOUYaeiouy\":\r\n\t\t\tprint(\"YES\")\r\n\t\t\treturn\r\n\t\telif c in \"BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz\":\r\n\t\t\tprint(\"NO\")\r\n\t\t\treturn\r\n\r\nsolve()\r\n", "L=input().split()\r\n\r\n\r\n\r\n\r\nif(L[len(L)-1]==\"?\"):\r\n ele=L[len(L)-2].casefold()\r\n\r\n if (ele.endswith(\"a\") or ele.endswith(\"e\") or ele.endswith(\"i\") or ele.endswith(\"o\") or ele.endswith(\"u\") or ele.endswith(\"y\") ):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n ele=L[len(L)-1].casefold()\r\n n=len(ele)\r\n \r\n if(ele[n-2]==\"a\" or ele[n-2]==\"e\" or ele[n-2]==\"i\" or ele[n-2]==\"o\" or ele[n-2]==\"u\" or ele[n-2]==\"y\"):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\") \r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n", "\nk=[\"A\",\"a\",\"e\",\"i\",\"o\",\"u\",\"E\",\"I\",'O',\"U\",\"y\",\"Y\"]\nn=list(input(\"\"))\na=list(ele for ele in n if ele.strip())\nif a[-2] in k:\n print(\"YES\")\nelse :\n print(\"NO\")\n", "inp = input()[:-1].lower().split()\r\n\r\nif (inp[-1][-1] in ('a', 'e', 'i', 'o', 'u', 'y')):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "#sleuth\nq = input().strip('? ').lower()\nif q[-1] in ['a', 'e', 'i', 'o', 'u', 'y']:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n", "s = input()\r\ni=len(s)-2\r\nwhile s[i]==' ':\r\n i-=1\r\ngl = ['e','y','u','i','a','o','E','Y','U','I','O','A']\r\nif s[i] in gl:\r\n print('YES')\r\nelse:\r\n print('NO')", "s = input()\r\nletters = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']\r\nfor i in range(len(s)):\r\n if s[-i - 1].isalpha() and s[-i - 1] in letters:\r\n print('YES')\r\n exit()\r\n if s[-i - 1].isalpha() and s[-i - 1] not in letters:\r\n print('NO')\r\n exit()\r\n", "s = input().split()\r\n#print(s)\r\nvows = list('AEIOUY')\r\nif s[-1] == \"?\":\r\n if (s[-2][-1]).upper() in vows:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n if (s[-1][-2]).upper() in vows:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "s = input()\r\nfor i in s[::-1]:\r\n if i.isalpha():\r\n if i.lower() in [\"a\", \"e\", \"o\",\"u\",\"y\", \"i\"]:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n break\r\n", "string = input()\r\nstring = string[:-1]\r\nstring = string.strip()\r\nif string[-1].lower() in ['a', 'e', 'i', 'o', 'u', 'y']:\r\n print('YES')\r\nelse:\r\n print('NO')", "s = input().strip()\r\ns=s[:len(s)-1].strip().casefold()\r\nprint(\"YES\" if s[-1] in ['a','e','i','u','o','y'] else \"NO\")", "s=input()\r\ns=s.replace(\" \",\"\")\r\n#print(s)\r\nl=list(s)\r\n#print(l)\r\nl.remove('?')\r\nvow=['a','e','i','o','u','y','A','E','I','O','U','Y']\r\n#l.remove(\" \")\r\n\r\n#print(l)\r\nif(l[len(l)-1] in vow):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "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\ns = s.replace('?', '')\r\ns = s.replace(' ', '')\r\n\r\nprint('YES' if s[-1] in 'aeiouyAEIOUY' else 'NO')\r\n", "line = input().replace(\" \", \"\")\r\nvowels = [\"A\", \"E\", \"I\", \"O\", \"U\", \"Y\"]\r\nif line[-2].upper() in vowels:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "s = input()\r\nl = ['a', 'e', 'i', 'o' ,'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']\r\ng = len(s)*-1\r\n\r\nfor i in range(-1, g-1, -1):\r\n if 64 < ord(s[i]) < 91 or 96 < ord(s[i]) < 123:\r\n if s[i] in l:\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break", "n = input()\nn = ''.join(n.split())\nn = str(n)\nm = n.lower()\nif m[-2] == \"a\" or m[-2] == \"e\" or m[-2] == \"i\" or m[-2] == \"o\" or m[-2] == \"u\" or m[-2] == \"y\":\n print(\"YES\")\nelse:\n print(\"NO\")", "a=input().strip()\r\na=a.replace(' ','')\r\nvowels=[\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\"]\r\nif(a[-2].upper() in vowels):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "question = input()\nquestion = question.replace(\" \", \"\")\nvowels = ['a', 'e', 'i', 'o', 'u', 'y']\nif question[len(question) - 2].lower() in vowels:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "s=input()\r\nn=len(s)\r\nfor i in range(n-1,-1,-1):\r\n if(s[i]!=' ' and s[i]!='?'):\r\n break\r\nif(s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u' or s[i]=='y' or s[i]=='A' or s[i]=='E' or s[i]=='I' or s[i]=='O' or s[i]=='U' or s[i]=='Y'):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = list(input())\r\na = \"qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM\"\r\nb = \"aeiouy\"\r\nc = []\r\nfor i in n:\r\n if i in a:\r\n c.append(i.lower())\r\nif c[-1] in b:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=input().split(\"?\")[0].rstrip()\r\nif s[-1].upper() in ['A','E','I','O','U','Y']:print(\"YES\")\r\nelse:print(\"NO\")", "s=input()\r\nx=''\r\nfor i in s:\r\n t=ord(i)\r\n if (64<t and t<91) or (96<t and t<123):\r\n x=t\r\nif x==65 or x==97 or x==69 or x==101 or x==73 or x==105 or x==79 or x==111 or x==85 or x==117 or x==89 or x==121:\r\n print('YES')\r\nelse:\r\n print('NO')", "sentence = (input().strip('?')).split()\r\nvowels = ['a','e','o','i','u','y']\r\nif sentence[-1][-1].lower() in vowels:\r\n print('YES')\r\nelse:\r\n print('NO')", "s1=input()\r\ns=\"\"\r\nfor i in range(len(s1)-2,-1,-1):\r\n if s1[i]!=\" \":\r\n s+=s1[i]\r\n break\r\nif s.lower() in [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "sen = input()\r\n\r\nsen = list(sen)\r\nn = len(sen)\r\n\r\nfor i in range(n-1, -1, -1):\r\n if sen[i] in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ':\r\n if sen[i] in 'AIUEOYaiueoy':\r\n print('YES')\r\n break\r\n else:\r\n print('NO')\r\n break", "vowels = ['A', 'E', 'I', 'O', 'U', 'Y']\n\nstr = input().upper()\n\ncounter = 1\n\nwhile True:\n char = str[len(str) - counter]\n if char in [' ', '?']:\n counter += 1\n else:\n if char in vowels:\n print('YES')\n break\n print('NO')\n break", "st = input()\nst = st.lower()\nst = st[:-1]\nst = st.strip()\nch = st[-1]\nif ch in ['a', 'e', 'i', 'o', 'u', 'y']:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n", "k=input()\r\nli=['a','e','i','o','u','y','A','E','I','O','U','Y']\r\np=k.split()\r\ns=''.join(p)\r\nl=s[-2]\r\nif l in li:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def findLastCharacter(line:str):\r\n for i in range(len(line)-1,-1,-1):\r\n if line[i] == ' ' or line[i] == '?':\r\n continue\r\n return line[i]\r\n\r\nline = input()\r\nvowels = \"AEIOUYaeiouy\"\r\nprint('YES' if findLastCharacter(line) in vowels else 'NO')\r\n\r\n\r\n", "x = input().strip(\" ?\").lower()\r\nif x[-1] in \"aeiouy\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=input()\r\nn=n.replace(\" \",\"\")\r\nn=n.replace(\"?\",\"\")\r\nn=n.lower()\r\nif n[-1] in \"aeiouy\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "#!/usr/bin/env/python\r\n# -*- coding: utf-8 -*-\r\nprint('YES' if input().strip('?').strip(' ')[-1].lower() in 'aeiouy' else 'NO')", "# input the question lower case all the question and remove spaces\r\nquestion = str(input()).replace(' ','').lower()\r\n# check if the char before ? is a vowel else print no\r\nif question[-2] in ['a', 'e', 'y', 'u', 'i' ,'o']:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input()\r\nfor i in range(len(s)-1, -1, -1):\r\n if s[i].isalpha(): break\r\nif s[i].upper() in ['A', 'E', 'I', 'O', 'U', 'Y']:\r\n print('YES')\r\nelse: print('NO')\r\n", "V=list(\"aeiouy\")\r\nC=list(\"bcdefghjklmnpqrstvwxyz\")\r\na=input()\r\nfor i in reversed(a.lower()):\r\n if i in V:\r\n print(\"YES\")\r\n break\r\n elif i in C:\r\n print(\"NO\")\r\n break", "l = list(input())\r\n\r\nfor i in l:\r\n if i == \" \":\r\n l.remove(i)\r\n for j in l:\r\n if j == \" \":\r\n l.remove(j)\r\n for h in l:\r\n if h == \" \":\r\n l.remove(h)\r\n\r\nch = l[-2]\r\n\r\nif (ch == 'A' or ch == 'a' or ch == 'E' or ch == 'e' or ch == 'I'\r\n or ch == 'i' or ch == 'O' or ch == 'o' or ch == 'U' or ch == 'u' or ch == \"Y\" or ch == \"y\"):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a = input()\r\ne = \"aeiouy\"\r\na = a.replace(' ','')\r\na = a.replace('?','')\r\na = a.lower()\r\nif a[-1] in e:\r\n print('YES')\r\nelse:\r\n print(\"NO\")\r\n", "print(['NO','YES'][input().replace(\"?\",\"\").split()[-1][-1].lower() in \"aeiouy\"])\r\n", "#! /usr/bin/python3\n# -*- coding: UTF-8 -*-\n\nimport re\n\nwhile True:\n try:\n line = input().strip().lower()\n except EOFError:\n break\n\n chars = re.findall(r'[a-z]', line)\n if chars[-1] in 'aeiouy':\n print('YES')\n else:\n print('NO')\n\n \t \t \t \t\t\t \t \t \t \t\t\t\t\t\t", "a=str(input())\r\na=a.strip(' ').strip('?').strip(' ')\r\na=a.casefold()\r\nif a[-1]=='a' or a[-1]=='e' or a[-1]=='i' or a[-1]=='o' or a[-1]=='u' or a[-1]=='y':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=input()\r\nt=[i for i in s if i.isalpha()]\r\nif t[-1].lower() in ['a','e','i','o','u','y']:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "VOWELS = set(\"aeiouy\")\n\nlast_letter = input().lower().replace(\"?\", \"\").strip()[-1]\nif last_letter in VOWELS:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "n=input().lower()\r\nwhile n[-1] not in list('abcdefghijklmnopqrstuvwxyz'):\r\n n=n[:-1]\r\nn=n[-1]\r\nif n in ['a','e','i','o','u','y']:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "l=input().split()\r\nb=[\"A\", \"E\", \"I\", \"O\", \"U\", \"Y\"]\r\nif len(l[-1])!=1 :\r\n \r\n if l[-1][-2].upper() in b :\r\n print(\"YES\")\r\n else :\r\n print(\"NO\")\r\n \r\nelse :\r\n if l[-2][-1].upper() in b :\r\n print(\"YES\")\r\n else :\r\n print(\"NO\")\r\n \r\n \r\n", "p = input()\r\nn = list(p.split())\r\nif n[-1] ==\"?\":\r\n if n[-2][-1]== \"a\" or n[-2][-1] == \"o\" or n[-2][-1] == \"u\" or n[-2][-1] == \"e\" or n[-2][-1] == \"i\" or n[-2][-1] == \"y\" or n[-2][-1]== \"A\" or n[-2][-1] == \"O\" or n[-2][-1] == \"U\" or n[-2][-1] == \"E\" or n[-2][-1] == \"I\" or n[-2][-1] == \"Y\":\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n if n[-1][-2] == \"a\" or n[-1][-2] == \"o\" or n[-1][-2] == \"u\" or n[-1][-2]== \"e\" or n[-1][-2]== \"i\" or n[-1][-2] == \"y\" or n[-1][-2] == \"A\" or n[-1][-2] == \"O\" or n[-1][-2] == \"U\" or n[-1][-2]== \"E\" or n[-1][-2]== \"I\" or n[-1][-2] == \"Y\":\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "s = input().replace('?','').strip().lower()\r\nif s[len(s)-1] in ['a','e','i','o','u','y']:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input()\r\nfor i in reversed(range(len(s))):\r\n if s[i].isalpha():\r\n c = s[i]\r\n break\r\n\r\nif c.upper() in \"A, E, I, O, U, Y\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Aug 11 21:53:43 2022\r\n\r\n@author: akshp\r\n\"\"\"\r\ns = input() \r\nfor i in range(len(s)-1 , -1 ,-1) : \r\n ch = s[i].lower()\r\n if not(ch>='a' and ch<='z') :\r\n continue \r\n if ch=='a'or ch=='e' or ch=='i' or ch=='o' or ch =='u' or ch=='y':\r\n print(\"YES\") \r\n else :\r\n print(\"NO\" ) \r\n break ", "##A\r\ndef main():\r\n s=str(input())\r\n G =['A', 'E', 'I', 'O', 'U',\r\n 'Y','a','e','i','o','u','y']\r\n\r\n i=-1;\r\n while(s[i]==' ' or s[i]=='?'): i-=1\r\n if s[i] in G:\r\n print(\"YES\")\r\n else :\r\n print(\"NO\")\r\n \r\nmain() \r\n", "a=list(map(str,input().split()))\r\nv=[\"a\",\"e\",\"i\",\"o\",\"u\",\"y\",\"A\",\"E\",\"O\",\"I\",\"U\",\"Y\"]\r\nl=len(a)\r\nif a[l-1]==\"?\":\r\n\tif a[l-2][-1] in v:\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")\r\nelse:\r\n\tif a[l-1][-2] in v:\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")", "s = input()\r\nk = len(s)\r\nv = ['a','e','i','o','u','y','A','E','I','O','U','Y']\r\nl = []\r\nfor i in range(k):\r\n if s[i] != ' ':\r\n l.append(s[i])\r\nl1 = len(l)\r\nif l[l1-2] in v:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n ", "string=input()\r\nn=len(string)\r\nstring=string.lower()\r\nl=['a','e','i','o','u','y']\r\nwhile n>0:\r\n if (ord(string[n-1])>=97 and ord(string[n-1])<=122) :\r\n if string[n-1] in l:\r\n print(\"YES\")\r\n break\r\n else:\r\n print(\"NO\")\r\n break\r\n n-=1", "s = input().replace(' ', '')\r\nvowel = 'aeiouy'\r\ns=s.lower()\r\nprint(\"YES\" if s[-2] in vowel else \"NO\")", "s=input()\r\ns=s.replace(\"?\", \"\")\r\ns=s.strip()\r\nv=\"aeouiyAEOUIY\"\r\nif s[-1] in v:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "\r\ndef check2(idx, s):\r\n if s[idx] in 'AEIOYUaeioyu':\r\n return 1\r\n return 0\r\n\r\ndef check1(idx, s):\r\n if s[idx] in 'QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm':\r\n return check2(idx, s)\r\n return check1(idx - 1, s)\r\n\r\ns = input()\r\ni = len(s) - 1\r\n\r\nflag = check1(i, s)\r\nif flag == 1: print('YES')\r\nelse: print('NO')", "#SLEUTH\r\n\r\nstr = input().lower()\r\nlst = []\r\nal = 'abcdefghijklmnopqrstuvwxyz'\r\nfor i in range(len(str)):\r\n if str[i] in al:\r\n lst.append(str[i])\r\nvo = 'aeiouy'\r\n\r\nif lst[-1] in vo:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n#print(lst)", "\r\nprint(['NO', 'YES'][input().replace('?','').split()[-1][-1].lower() in 'aeyuio'])\r\n\r\n", "def solve(a):\n s=\"AEIOUY\"\n for c in s:\n if(a.endswith(c)):\n return \"YES\"\n return \"NO\"\ns=str.upper(input())\na=\"\"\nfor c in s:\n if(90>=ord(c)>=65):\n a+=c\nprint(solve(a))\n", "s=input().replace(\" \", \"\")\r\n\r\nif s[-2].lower() in \"aeiouy\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n \r\n\r\n\r\n", "s = input()\r\ns = s.replace(\" \",\"\")\r\ns = s.lower()\r\nv = [\"a\",\"e\",\"i\",\"o\",\"u\",\"y\"]\r\nif s[-2] in v:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=input().rstrip('?').strip()\r\na=['A', 'E', 'I', 'O', 'U', 'Y','a','e','i','o','u','y']\r\nif n[-1] in a:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "l=list(input())\r\ns=[\"a\",'e',\"u\",\"i\",\"o\",\"y\"]\r\np=len(l)\r\nfor i in range(p-1,-1,-1):\r\n\tif l[i]==\"?\":\r\n\t\tcontinue\r\n\telif l[i]==\" \":\r\n\t\tcontinue\r\n\telse:\r\n\t\tn=l[i].lower()\r\n\t\tif n in s:\r\n\t\t\tprint(\"YES\")\r\n\t\t\tbreak\r\n\t\telse:\r\n\t\t\tprint(\"NO\")\r\n\t\t\tbreak", "\r\nstring = input().rstrip()\r\nstring = string[:-1].lower()\r\nstring = string.rstrip()\r\n\r\nif string[-1] in \"aeiouy\":\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n ", "s=input()\r\nd=0\r\ne=0\r\nf=0\r\nn=len(s)\r\nfor i in range(0,len(s)):\r\n if((s[n-i-1]>='a' and s[n-i-1]<='z') or(s[n-i-1]>='A' and s[n-i-1]<='Z')):\r\n q=s[n-i-1]\r\n if(q=='a' or q=='e' or q=='i' or q=='u' or q=='o' or q=='y' or q=='A' or q=='E' or q=='I' or q=='U' or q=='O' or q=='Y'):\r\n print(\"YES\")\r\n exit(0)\r\n else:\r\n print(\"NO\")\r\n exit(0)\r\n \r\n ", "n=input().lower()\r\na=len(n)-1;s=''\r\nfor i in range (a):\r\n if n[i]!=' ':s+=n[i]\r\ns=s[len(s)-1]\r\nif s=='a' or s=='o' or s=='y' or s=='u' or s=='i' or s=='e':\r\n print('YES')\r\nelse:print('NO')\r\n", "s=input().lower()\r\ns=list(s)\r\nwhile(s.count(' ')):\r\n s.remove(' ')\r\nif(s[-2]=='a' or s[-2]=='i' or s[-2]=='e' or s[-2]=='o' or s[-2]=='u' or s[-2]=='y'):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "question = input()\r\n\r\nallAl = 'abcdefghijklmnopqrstuvwxyz'\r\nallVo = 'aeiouy'\r\n\r\nl = len(question)\r\nhi = l-2\r\n\r\nwhile hi!=-1:\r\n if question[hi].lower() not in allAl:\r\n hi-=1\r\n else:\r\n break\r\n\r\nif question[hi].lower() in allVo:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "a=input().strip()\r\nfor i in a[::-1]:\r\n\tif i.isalpha():\r\n\t\tif i in \"AEIOUYaeiouy\":\r\n\t\t\tprint(\"YES\")\r\n\t\telse:\r\n\t\t\tprint(\"NO\")\r\n\t\tbreak\r\n" ]
{"inputs": ["Is it a melon?", "Is it an apple?", " Is it a banana ?", "Is it an apple and a banana simultaneouSLY?", "oHtSbDwzHb?", "sZecYdUvZHrXx?", "uMtXK?", "U?", "aqFDkCUKeHMyvZFcAyWlMUSQTFomtaWjoKLVyxLCw vcufPBFbaljOuHWiDCROYTcmbgzbaqHXKPOYEbuEtRqqoxBbOETCsQzhw?", "dJcNqQiFXzcbsj fItCpBLyXOnrSBPebwyFHlxUJHqCUzzCmcAvMiKL NunwOXnKeIxUZmBVwiCUfPkjRAkTPbkYCmwRRnDSLaz?", "gxzXbdcAQMuFKuuiPohtMgeypr wpDIoDSyOYTdvylcg SoEBZjnMHHYZGEqKgCgBeTbyTwyGuPZxkxsnSczotBdYyfcQsOVDVC?", "FQXBisXaJFMiHFQlXjixBDMaQuIbyqSBKGsBfTmBKCjszlGVZxEOqYYqRTUkGpSDDAoOXyXcQbHcPaegeOUBNeSD JiKOdECPOF?", "YhCuZnrWUBEed?", "hh?", "whU?", "fgwg?", "GlEmEPKrYcOnBNJUIFjszWUyVdvWw DGDjoCMtRJUburkPToCyDrOtMr?", "n?", "BueDOlxgzeNlxrzRrMbKiQdmGujEKmGxclvaPpTuHmTqBp?", "iehvZNQXDGCuVmJPOEysLyUryTdfaIxIuTzTadDbqRQGoCLXkxnyfWSGoLXebNnQQNTqAQJebbyYvHOfpUnXeWdjx?", " J ?", " j ?", " o ?", " T ?", " q ?", " j ?", " c ?", " B ?", "LuhxDHVwMPTtUIUMIQTuQETgXCOQPsfdFlyHvpfOVedjUTpGLAZGOHloIjJJtOLAlHPivzA?", "wmztmzFfwbGyOmNHENUFMTsFEMWYA?", "wGsfZCSwN PEUhNUrLfABrxA?", "mCDHENXjYbgMdBimAdPnewaHfpGWowjWrVAdvWczjw iDcUbyzMsmsnwbviiKiAyGVA?", "ARIWnwqFqxsQXsXXzHqvFjxOCttAGPUzDtWzsenPYdNXuFOIUGYZsLLK IaoxiyjBBRThoelwdPTkuCQfcBLUEJpCPIrVZlvUWA?", " PslvVpgpN BXkMFBEVXsyZFIQbBEFxGkYTeXKrOdcmhbiTUatYRUoYAayrchqbksswIlfIjerZPqptvCGnMUhyrQSvwltRhFzA?", "HpBkttwSjBXDmyleGiRWNUMPaAIE uzTrp KJDzaUiCdsMYOoWKHoUhWUoecCPmACymMUUbGav UMRpCytPETwNFAObZJA?"], "outputs": ["NO", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES"]}
UNKNOWN
PYTHON3
CODEFORCES
536
138d94919a947e94d844bc2c1441a473
Title
Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title should be represented by a single word containing at least once each of the first *k* Latin letters and not containing any other ones. Also, the title should be a palindrome, that is it should be read similarly from the left to the right and from the right to the left. Vasya has already composed the approximate variant of the title. You are given the title template *s* consisting of lowercase Latin letters and question marks. Your task is to replace all the question marks by lowercase Latin letters so that the resulting word satisfies the requirements, described above. Each question mark should be replaced by exactly one letter, it is not allowed to delete characters or add new ones to the template. If there are several suitable titles, choose the first in the alphabetical order, for Vasya's book to appear as early as possible in all the catalogues. The first line contains an integer *k* (1<=≤<=*k*<=≤<=26) which is the number of allowed alphabet letters. The second line contains *s* which is the given template. In *s* only the first *k* lowercase letters of Latin alphabet and question marks can be present, the length of *s* is from 1 to 100 characters inclusively. If there is no solution, print IMPOSSIBLE. Otherwise, a single line should contain the required title, satisfying the given template. The title should be a palindrome and it can only contain the first *k* letters of the Latin alphabet. At that, each of those *k* letters must be present at least once. If there are several suitable titles, print the lexicographically minimal one. The lexicographical comparison is performed by the standard &lt; operator in modern programming languages. The line *a* is lexicographically smaller than the line *b*, if exists such an *i* (1<=≤<=*i*<=≤<=|*s*|), that *a**i*<=&lt;<=*b**i*, and for any *j* (1<=≤<=*j*<=&lt;<=*i*) *a**j*<==<=*b**j*. |*s*| stands for the length of the given template. Sample Input 3 a?c 2 a??a 2 ?b?a Sample Output IMPOSSIBLE abba abba
[ "def process(S, k):\r\n n = len(S)\r\n L = [x for x in S]\r\n needed = set([i for i in range(k)])\r\n question = []\r\n for i in range(n):\r\n if S[i] != '?' and S[n-1-i] != '?' and S[i] != S[n-1-i]:\r\n return 'IMPOSSIBLE'\r\n if i <= n-1-i and S[i] != '?':\r\n L[n-1-i] = S[i]\r\n c = ord(S[i])-ord('a')\r\n if c in needed:\r\n needed.remove(c)\r\n if c >= k:\r\n return 'IMPOSSIBLE'\r\n if i <= n-1-i and S[n-1-i] != '?':\r\n L[i] = S[n-1-i]\r\n c = ord(S[n-1-i])-ord('a')\r\n if c in needed:\r\n needed.remove(c)\r\n if c >= k:\r\n return 'IMPOSSIBLE'\r\n if i <= n-1-i and S[i]==S[n-1-i]=='?':\r\n question.append(i)\r\n if len(needed) > len(question):\r\n return 'IMPOSSIBLE'\r\n needed = list(needed)\r\n needed = sorted(needed)\r\n while len(needed) > 0:\r\n c = needed.pop()\r\n c = chr(c+ord('a'))\r\n i = question.pop()\r\n L[i] = c\r\n L[n-1-i] = c\r\n for i in question:\r\n L[i] = 'a'\r\n L[n-1-i] = 'a'\r\n return ''.join(L)\r\n\r\nk = int(input())\r\nS = input()\r\nprint(process(S, k))", "k = int(input())\r\ns = list(input())\r\nn = len(s)\r\na = [0] * 26\r\np = 0\r\nq = 0\r\nfin = n // 2\r\nstart = n // 2 - 1\r\nif n % 2 == 1:\r\n fin = (n + 1) // 2\r\n start += 1\r\nfor i in range(fin):\r\n if s[i] == '?'and s[n - 1 - i] == '?':\r\n q += 1\r\n elif s[i] != '?' and s[n - 1 - i] == '?':\r\n s[n - 1 - i] = s[i]\r\n if not a[ord(s[i]) - 97]:\r\n a[ord(s[i]) - 97] = 1\r\n p += 1\r\n elif s[n - 1 - i] != '?' and s[i] == '?':\r\n s[i] = s[n - 1 - i]\r\n if not a[ord(s[i]) - 97]:\r\n a[ord(s[i]) - 97] = 1\r\n p += 1\r\n else:\r\n if s[i] != s[n - 1 - i]:\r\n print('IMPOSSIBLE')\r\n exit()\r\n if not a[ord(s[i]) - 97]:\r\n a[ord(s[i]) - 97] = 1\r\n p += 1\r\nif q < k - p:\r\n print('IMPOSSIBLE')\r\n exit()\r\nfor i in range(start, -1, -1):\r\n if s[i] == '?' and s[n - 1 - i] == '?':\r\n if p < k:\r\n for j in range(k - 1, -1, -1):\r\n if not a[j]:\r\n s[i] = chr(97 + j)\r\n s[n - 1 - i] = chr(97 + j)\r\n p += 1\r\n a[j] = 1\r\n break\r\n else:\r\n s[i] = 'a'\r\n s[n - 1 - i] = 'a'\r\n q -= 1\r\nprint(''.join(s))\r\n", "import sys\r\n\r\nI = lambda: int(input())\r\nRL = readline = lambda: sys.stdin.readline().strip('\\n')\r\nRM = readmap = lambda x = int: map(x,readline().split(' '))\r\n\r\nk,s = I(),list(RL());n=len(s);n1 = n-1;ss = set(s)\r\nalpha = {chr(97+i) for i in range(k)}\r\nalpha0 = [chr(97+i) for i in range(k)]\r\nalpha0 = [i for i in alpha0 if not i in ss]\r\ndef discard(l,x):\r\n if x in l: l.remove(x)\r\n\r\nif n&1 and s[n>>1] == '?': s[n>>1] = (alpha0.pop() if len(alpha0) else 'a')\r\nfor i in range((n>>1)-1,-1,-1):\r\n x,y = s[i],s[n1-i]\r\n flag = max(ord(x)-96,ord(y)-96)>k\r\n c = int(x=='?') + int(y=='?')\r\n if c==0:\r\n if x!=y: flag = True\r\n else: discard(alpha0,x)\r\n if c==2: s[i] = s[n1-i] = (alpha0.pop() if len(alpha0) else 'a')\r\n if c==1:\r\n if x=='?': s[i] = y;discard(alpha0,y)\r\n if y=='?': s[n1-i] = x;discard(alpha0,x)\r\n if flag:\r\n print('IMPOSSIBLE');sys.exit(0)\r\n\r\n#print(alpha0,alpha,set(s))\r\nprint(''.join(s) if set(s)==alpha else \"IMPOSSIBLE\")\r\nquit()\r\n'''\r\n16\r\n?bc??f?hi?k??n??hb??liiglal???npi???b???p?n?j?al????j???ponmlkjih??e??b?\r\n'''\r\n#D \r\ndef f(l,x):\r\n if x==l[0]: return l[1],l[2]\r\n if x==l[1]: return l[0],l[2]\r\n if x==l[2]: return l[0],l[1]\r\n return -1\r\n\r\ndef delrank(x):\r\n global pre,nxt\r\n prex,nxtx = pre[x],nxt[x]\r\n nxt[prex] = nxtx\r\n pre[nxtx] = prex\r\n\r\nn = I()\r\nN = 3*n\r\nrank = [*RM()]+[N+1]\r\ntris = [tuple(RM()) for i in range(n)]\r\nk = I()\r\npre,nxt = list(range(N+2)), list(range(N+2))\r\ntemp0 = 0\r\nfor i in range(N+1):\r\n temp1 = rank[i]\r\n pre[temp1],nxt[temp0] = temp0,temp1\r\n temp0 = temp1\r\n\r\nfor ind,tri in enumerate(tris):\r\n leader = nxt[0]\r\n x,y = f(tri,leader)\r\n if k in tri:\r\n if leader != k:\r\n l = [i for i in range(1,N+1) if i!=k]\r\n else:\r\n #condition here is element in l3 should be after max(x,y)\r\n #so sort l1+l2 first cut the portion after max(x,y) and add\r\n #it to l3 and sort the new l3\r\n l1 = [i for tri in tris[:ind] for i in tri]\r\n l2 = [x,y]\r\n l3 = [i for tri in tris[ind+1:] for i in tri]\r\n l0 = sorted(l1 + l2)\r\n ind = l0.index(max(x,y))\r\n l = l0[:ind+1] + sorted(l0[ind+1:]+l3)\r\n #print(leader,l1,l2,l3)\r\n print(' '.join([str(i) for i in l]))\r\n sys.exit(0)\r\n for i in tri: delrank(i)\r\n\r\n'''\r\n7\r\n4 19 14 8 21 16 2 18 1 15 3 17 13 5 6 10 9 7 12 11 20\r\n4 19 10\r\n14 8 3\r\n21 17 9\r\n16 6 12\r\n2 13 20\r\n18 1 7\r\n15 5 11\r\n21\r\n'''\r\nquit()\r\n#E Shortest Path\r\ndef rec(u,v):\r\n '''to recursivley visit the edge previous to this edge'''\r\n if v: rec(pre[u][v],u);print(v,end=' ')\r\n\r\nfrom collections import deque\r\nn,m,k = RM()\r\nadj = [[] for i in range(n+1)]\r\ndist = [[int(1e9)]*(n+1) for i in range(n+1)]\r\npre = [[0]*(n+1) for i in range(n+1)]\r\nbad = set()\r\nfor _ in range(m):\r\n x,y = RM()\r\n adj[x].append(y)\r\n adj[y].append(x)\r\n\r\nfor _ in range(k): bad.add(tuple(RM()))\r\n\r\ndist[0][1] = 0\r\nq = deque([(0,1)])\r\nwhile q:\r\n u,v = q.popleft()\r\n d = dist[u][v] + 1\r\n for w in adj[v]:\r\n if d<dist[v][w] and not (u,v,w) in bad:\r\n dist[v][w] = d\r\n pre[v][w] = u\r\n q.append((v,w))\r\n if w == n:\r\n print(d)\r\n rec(v,w)\r\n print()\r\n sys.exit(0)\r\nprint(-1)\r\n", "import sys\r\n\r\nk = int(input())\r\ns = input()\r\n\r\nif len(s) == 1:\r\n\tif s == '?':\r\n\t\tif k == 1:\r\n\t\t\tprint('a')\r\n\t\telse:\r\n\t\t\tprint(\"IMPOSSIBLE\")\r\n\telse:\r\n\t\tprint(s)\r\n\tsys.exit(0)\r\nc = list('abcdefghijklmnopqrstuvwxyz'[:k])\r\nfor a in s:\r\n\tif a != '?' and a in c:\r\n\t\tc.remove(a)\r\n\t\t\r\nfor i in range(len(s)):\r\n\tif s[i] == '?':\r\n\t\tif s[-(i+1)] != '?':\r\n\t\t\ts = s[:i] + s[-(i+1)] + s[i+1:]\r\n\t\t\tif s[i] in c:\r\n\t\t\t\tc.remove(s[i])\r\n\r\nqc = s.count('?') / 2\r\nwhile len(c) < qc:\r\n\tc = ['a'] + c\r\n\r\nfor i in range(len(s)):\r\n\tif s[i] == '?':\r\n\t\tif len(c) > 0:\r\n\t\t\tr = c[0]\r\n\t\ts = s[:i] + r + s[i+1:len(s)-i-1] + (r if i != len(s) - i - 1 else '') + s[len(s) - i:]\r\n\t\tif r in c:\r\n\t\t\tc.remove(r)\r\n\r\nif len(c) > 0 or s != s[::-1]:\r\n\tprint(\"IMPOSSIBLE\")\r\nelse:\r\n\tprint(s)", "k=int(input())\r\ns=list(input())\r\nn=len(s)\r\nali=0;\r\nfor i in range(n):\r\n if s[i]==s[n-i-1]: ali+=1;\r\n elif s[i]=='?': s[i]=s[n-i-1]\r\n elif s[n-i-1]=='?': s[n-i-1]=s[i]\r\n else:\r\n print('IMPOSSIBLE')\r\n exit()\r\nd=set(chr(i+97) for i in range(k) if chr(i+97) not in s)\r\nfor i in range(n//2,-1,-1):\r\n if s[i]==s[n-i-1]=='?':\r\n if len(d):\r\n s[i]=s[n-i-1]=max(d)\r\n d.remove(max(d))\r\n else:\r\n s[i]=s[n-i-1]='a'\r\nif d:\r\n print('IMPOSSIBLE')\r\nelse:\r\n print(*s,sep='')", "#def computeGCD(x, y):\r\nimport math\r\nfrom collections import Counter\r\nk = int(input())\r\n#n=int(input())\r\n#stirng\r\ns = (input())\r\nflag = False\r\nif len(s)%2==0:\r\n l = len(s)//2-1\r\n r = len(s)//2\r\nelse:\r\n l=r=len(s)//2\r\ndic = Counter(s)\r\nalpha = []\r\nfor i in range(97,97+k):\r\n if chr(i) in dic:\r\n k-=1\r\n else:\r\n alpha.append(chr(i))\r\n\r\ns = [i for i in s]\r\nwhile l>-1 and r<len(s):\r\n # print(s[l],s[r])\r\n if s[l]!='?' and s[r]!='?' and s[l]!=s[r]:\r\n flag = True\r\n break\r\n elif s[l]=='?' and s[r]!='?':\r\n s[l] = s[r]\r\n elif s[r]=='?' and s[l]!='?':\r\n s[r] = s[l]\r\n elif s[l] == '?' and s[r] == '?': \r\n if alpha:\r\n s[l] = s[r] = alpha.pop()\r\n k-=1\r\n else:\r\n s[l] = s[r] = 'a'\r\n \r\n l-=1\r\n r+=1\r\nif k == 0 and not flag:\r\n print(''.join(s))\r\nelse:\r\n print(\"IMPOSSIBLE\")\r\n\r\n\r\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\nk = int(input())\r\na = list(input().rstrip())\r\nn = len(a)\r\nunused = [1] * k\r\n\r\n\r\ndef ng():\r\n print('IMPOSSIBLE')\r\n exit()\r\n\r\n\r\ntry:\r\n for i in range(n):\r\n if a[i] == '?' and a[n - i - 1] != '?':\r\n a[i] = a[n - i - 1]\r\n if a[i] != '?':\r\n unused[ord(a[i]) - 97] = 0\r\nexcept IndexError:\r\n ng()\r\n\r\nfor i in range(n):\r\n if a[i] != a[n - i - 1]:\r\n ng()\r\n\r\nfor i in range(n // 2, n):\r\n if a[i] == '?':\r\n for cc in range(k - 1, -1, -1):\r\n if unused[cc]:\r\n a[i] = a[n - i - 1] = chr(cc + 97)\r\n unused[cc] = 0\r\n break\r\n else:\r\n a[i] = a[n - i - 1] = 'a'\r\n\r\nif any(unused):\r\n ng()\r\nprint(*a, sep='')\r\n", "n = int(input())\r\nls = input()\r\ns = []\r\nfor i in range(len(ls)) :\r\n s.append(ls[i])\r\ni, j = 0, len(s) - 1\r\nwhile i < j :\r\n if (s[i] != '?' and ord(s[i])-ord('a') >= n) or (s[j] != '?' and ord(s[j]) - ord('a') >= n) :\r\n print(\"IMPOSSIBLE\")\r\n break\r\n if s[i] != s[j] and (s[i] != '?' and s[j] != '?') :\r\n print(\"IMPOSSIBLE\")\r\n break\r\n if s[i] != s[j] and (s[i] == '?' or s[j] == '?') :\r\n if s[i] == '?' :\r\n s[i] = s[j]\r\n else :\r\n s[j] = s[i]\r\n i += 1\r\n j -= 1\r\nelse :\r\n if '?' not in s :\r\n st = set(s)\r\n if len(st) != n :\r\n print(\"IMPOSSIBLE\")\r\n else :\r\n print(''.join([str(elem) for elem in s]))\r\n else :\r\n left = []\r\n for i in range(n) :\r\n if chr(ord('a')+i) not in s :\r\n left.append(chr(ord('a')+i))\r\n i, j = (len(s)-1)//2, len(s)//2\r\n while i > -1 :\r\n if s[i] == '?' and s[j] == '?' :\r\n if len(left) > 0 :\r\n s[i] = left[-1]\r\n s[j] = left[-1]\r\n left.pop()\r\n else :\r\n s[i] = 'a'\r\n s[j] = 'a'\r\n i -= 1\r\n j += 1\r\n if len(left) == 0 :\r\n print(''.join([str(elem) for elem in s]))\r\n else :\r\n print(\"IMPOSSIBLE\")", "import sys, string\r\nk = int(input())\r\npal = list(input().strip())\r\nn = len(pal)\r\ncenter = (n-1)//2\r\nfor i in range(center+1):\r\n\tj = n-1-i\r\n\tif pal[i] == pal[j]:\r\n\t\tcontinue\r\n\tif pal[i] == '?':\r\n\t\tpal[i] = pal[j]\r\n\telif pal[j] == '?':\r\n\t\tpal[j] = pal[i]\r\n\telse:\r\n\t\tprint('IMPOSSIBLE')\r\n\t\tsys.exit()\r\nneed = []\r\nfor ch in string.ascii_letters[:k]:\r\n\tif ch not in pal:\r\n\t\tneed.append(ch)\r\nnix = len(need)-1\r\nfor i in range(center, -1, -1):\r\n\tif pal[i] != '?':\r\n\t\tcontinue\r\n\tj = n-i-1\r\n\tif nix == -1:\r\n\t\tpal[i] = pal[j] = 'a'\r\n\telse:\r\n\t\tpal[i] = pal[j] = need[nix]\r\n\t\tnix -= 1\r\nif nix != -1:\r\n\tprint('IMPOSSIBLE')\r\nelse:\r\n\tprint(''.join(pal))\r\n", "import sys, string\nk = int(input())\npal = list(input().strip())\nn = len(pal)\ncenter = (n-1)//2\nfor i in range(center+1):\n\tj = n-1-i\n\tif pal[i] == pal[j]:\n\t\tcontinue\n\tif pal[i] == '?':\n\t\tpal[i] = pal[j]\n\telif pal[j] == '?':\n\t\tpal[j] = pal[i]\n\telse:\n\t\tprint('IMPOSSIBLE')\n\t\tsys.exit()\nneed = []\nfor ch in string.ascii_letters[:k]:\n\tif ch not in pal:\n\t\tneed.append(ch)\nnix = len(need)-1\nfor i in range(center, -1, -1):\n\tif pal[i] != '?':\n\t\tcontinue\n\tj = n-i-1\n\tif nix == -1:\n\t\tpal[i] = pal[j] = 'a'\n\telse:\n\t\tpal[i] = pal[j] = need[nix]\n\t\tnix -= 1\nif nix != -1:\n\tprint('IMPOSSIBLE')\nelse:\n\tprint(''.join(pal))\n" ]
{"inputs": ["3\na?c", "2\na??a", "2\n?b?a", "3\n????", "2\n????", "1\n?", "2\n?", "6\nabcdeffcdfda", "1\n?a", "23\napfpbfgmiko?mno?qre??cv?wvjt?r?foqm??op?g?udcfa", "16\n?bc??f?hi?k??n??hb??liiglal???npi???b???p?n?j?al????j???ponmlkjih??e??b?", "23\na??d??g?i????n????????wj?spqbfr?wp?ob?g??h??r?????orf?q?s??w?u?srqp?n??kj?h????cb?", "9\na??d?fgh???????beaabaih????c??", "20\nabcdefg?ij????opq?ste?dfr?ol?ef?fb?djaajd?b?kfea?okrfdl?ts???onm?kj?h??ed??a", "21\nabc???gh??kl??j??r?tuak???d??q?dd?d????p???u??p?njl?i??bq?g??h?k??t?rq?on?l????gf????a", "17\na?c?e?gh?j?lm?????k?k?j?????h??c???????a?h????c????f????????pon?l?ji????dc?a", "18\nab?d?f????klm?o?qrc???rq?o?ml?j????e??ba", "26\nabcdefghijklmnopqrstuvwxyzfgvnsltvvohywvqhuhtydghtthgdythuhqvwyhovvtlsnvgfzyxwvutsrqponmlkjihgfedcba", "26\nabcdefghijklmnopqrstuvwxyzdqnxgfgubupwlqakrteeazzffzzaeetrka?lwpubugfgxnqdzyxwvutsrqponmlkjihgfedcba", "26\n??cdef?h?j?l??o?qrs?uvw?yz??xo?a?ryolathxp????pex?ixe?w??u?xh?a?oyri????q???xwvut?r??onmlkji??fedcb?", "26\nab?defg??j??mnopqrs?uv?x???u?vpd??s?s??s?t?v?vp?is?iqp??v??ush?s??aadp?t?r?y?wv???rqp??mlk?ihgfe?c?a", "26\n?bc?ef?hijklmnopqrst?????z?lc?z?r?zszzd?u?xc??udjppjdu????iub???szkr???cl?z??w?uts??po?m?k???gf??cba", "26\n?b?def????????o?q???u??x????hv???pl?v?e???k??no??pp?y????k??ied??l??z?????z??w?ut??q???m?k??????dc?a", "26\nabcd?f??ijklm????rst????y??bn???jw?????v?????j?oevv??????s???y?????jy?j??zz????u????pon???????f?????", "26\nabcdefghijklmnopqrstuvwxyzticrsbwgheuvpptmqlpilntftnliplqmtppvuehgwbsrcitzyxwvutsrqponmlkjihgfedcba", "26\nabcdefghijklmnopqrstuvwxyzjxeludiwenknpgqienv?myfvfympvneiqgpnknewidulexjzyxwvutsrqponmlkjihgfedcba", "26\n?b?d?f?h?jk??nopqrst???xyz?u?wobc??cyr?mdmtq?r?kzbzko?oq?m?myr??yocbowwu??yx???t????o???k?i?gfedc??", "26\n?b??ef??i?klmn?pqrst?vwxyzmkvg?g?t?ajr?x?oe?nq???pcc?????obx???aztx?g???m?yx?vu??rq????l?ji?gf?d?ba", "26\nabc??fg?i?klm?o?q?stuv?????zp?bfg?l?g??qzii?kur?bxb?ruk?iizqa???lrg??o?z???x??ut?rqpo????jihgfedcb?", "26\n?b????g????l?????rs???????s?f?ceiww??ok????u??qwm???q?fu??wkkoh??wie??f???yx?vuts?q??nm?????g??dc??", "26\n????e???i????no??r??????????????k?hx???z????i?qsddd?q???m??zl?d?????ehmg??yxw?????q??n??k?i??fed???", "5\nabcdeeecdabbaaaeeedebedacccdebacbaeceaaeddabbaaeaccaeaabbaddeaaeceabcabedcccadebedeeeaaabbadceeedcba", "2\nababaaaababaaaababbaaabaabaaaabbbabaababababaaaaaaaaaaaababababaababbbaaaabaabaaabbabaaa?babaaaababa", "13\na?c??fghij?lmdla?ilg?d??gda?d??djc??g?afedkd?bgj?d?cj?b?dkd???igkkcj???d?????fdh?lij???mlkj?h?f??c??", "9\na?c???ghib??f????g?ee?ecc?eeg?gbih???????ccaeecggddg???e?ccbig?eh?h?bgi??eeccei?e?gb??a?cbb?hg?????a", "16\n?bcde?gh??k?mn??i?lih?aamkfi??adfep??g?b??gphekeo?a???eh??mmbo???p?f?a?b?fkm????ilcipo??lkjih??edc?a", "24\na????fg??jk?m??p???tuvw??wk?cj??q??t?????if?s????o????n?e??i??b????qh?j??k?c?w??t?????????j???f?d???", "21\nab??????????m????r?tuure?d???kc???b?k??fhs????????????s????hfn???bt?????o????r?uts?qp??ml?????f???b?", "7\nabcdefggfedegbfggbfeacdddcdccbdfccaeddgcgddgcedabdbadecgddgcgddeaccfdbccdcdddcaefbggfbgedefggfedcba", "9\nabcdefghiiabddfhbfeaeifeibcdbbgbidbbgdhbccgdbedghdhgdebdgccbhdgbbdibgbb?cbiefieaefbhfddbaiihgfedcba", "3\n??cb?c??ab?aaccab??cbb?abb?accbab?c?c?aba?b??ba?c???a?b?bcab????ca?a???aabba?bb??bba?c?a??acacabcb?", "6\na?cdef?ecde?f??d??eeedf??e?bbdff?ecb??daeb?e?????e?aa?a?e??ade?b?eb??dbb?e?cf?e?e?b?a??ce???efe?cba", "19\na???efghi?k?mn?pqrshar?ib?jl?c?poh??lih?j?nr?jd????mdj??n??????s?ho????l?pb???ahsr?ponmlkji??fe?c?a", "26\n??cdef??i??lmn?pq??tuv???z?u????b??no??????vhv?v?w?v?vh????????????n???u?z??wv?ts????nm???ih?f???b?", "19\nab????g??j??????????????????g??i???q?rb?lr?rnfl?mk????n??r?j?rr??g????????mb?????rqp?n??k??????d?b?", "23\n?bc???gh?j?lm????rs????????v?cwqh?dh?vd????j??e??p???????k?v??vt???h?wc???l?t?vut??q??nm??????f??cba", "3\n?bc?b??ac??c?bcb?c?b?cbb????ca????c??a?c?abb?ba?aba??b?bb????a?acbb?a??ab?cbb??a?ccb??bc???ab???cba", "22\n??cdefg?if???n????????n??ov?nq??n??ae??kl?g?????o?????fg???hi???bn?g???vo?fn?????q??nmlkj??g?????a", "3\n?b??a??bcb??b?cc??b?b??ba?c?b?abcccaba??c??ac?bbaab?bc??bc??", "18\nebcdefghijknmnodqroohmcicajbcikaiibrghrcccroprabiagegbjhcickhopmqponmakjnhgfedcbg", "9\nf??e?f", "25\no??p?nd?ff?yxy??oa?l?j??o?g??of??ilgaor??x?i??udncp???", "5\na?e?c?", "13\neb?iklf?hk?eikiik?e?khbfl?i?be", "23\nnkcip???????cn??cco?i??n", "26\n??tnlrco?b?lsvpvsl??voc?l?t?c", "18\nl??e?l??el?????hadq??le?p??ed??", "17\nhdhjqblhfcf?phjoeiieojhp?fc?hlbqjhdh", "12\ncgcbabdhiejjeihdbabcgc", "19\ncspcnshermeaangqpkc??c?bsn?jons?qcdcckpqgn?aemrehsncpsc", "16\n?????????????????g???????b????", "21\n??c??????????i???q???????????n?????????", "26\n??????????k?????????????????????vp????????l????l????", "25\n???e???k?d?v?????????????c??????????????????o???????????????????", "5\ne??e???????????????e?????????????????e?????????????a????????????????????????????b????????", "13\n???b?????????????????????????????????????????????????????", "9\nhbe??ec??????????", "2\n??????", "1\na", "3\n????????", "3\n????????????????????????????????????????", "2\n??????????????????????????????????????????????????????????????????????????????????????????", "4\nb???c?c???b", "5\na???????????????????a", "5\nacde????edca", "3\nb????????????????????b"], "outputs": ["IMPOSSIBLE", "abba", "abba", "IMPOSSIBLE", "abba", "a", "IMPOSSIBLE", "IMPOSSIBLE", "aa", "IMPOSSIBLE", "abcaefahijklmnophbajliiglaljannpiadbbdaipnnajlalgiiljabhponmlkjihafeacba", "abcdaaghijkaanapqrseulwjmspqbfrowptobrgvhhvgrbotpworfbqpsmjwluesrqpanaakjihgaadcba", "aacdafghiabaaebbeaabaihgfadcaa", "abcdefghijkamnopqasteldfrkolaefkfbadjaajdabfkfealokrfdletsaqponmakjihgfedcba", "IMPOSSIBLE", "aacdeaghijalmnopaakakajafaaahcacaahbaqqabhaacachaaafajakakaaponmlajihgaedcaa", "abadefaghjklmionqrcppcrqnoimlkjhgafedaba", "abcdefghijklmnopqrstuvwxyzfgvnsltvvohywvqhuhtydghtthgdythuhqvwyhovvtlsnvgfzyxwvutsrqponmlkjihgfedcba", "abcdefghijklmnopqrstuvwxyzdqnxgfgubupwlqakrteeazzffzzaeetrkaqlwpubugfgxnqdzyxwvutsrqponmlkjihgfedcba", "abcdefahijklmnoaqrstuvwxyzaqxoaairyolathxpuagwpexiixepwgaupxhtaloyriaaoxqazyxwvutsrqaonmlkjihafedcba", "abcdefghijklmnopqrsauvwxyarutvpdaasasahsutavzvpqissiqpvzvatushasasaadpvturayxwvuasrqponmlkjihgfedcba", "abcaefghijklmnopqrstuawaazalcazarkzszzdbuixcvyudjppjduyvcxiubdzzszkrazaclazaawautsrqponmlkjihgfeacba", "abcdefaaaakamaoaqaatuawxazaahvazaplavdeiagkjrnoysppsyonrjkgaiedvalpazavhaazaxwautaaqaoamakaaaafedcba", "abcdafaaijklmnoparstuaaayzzbnjayjwaaaayvagshqjxoevveoxjqhsgavyaaaawjyajnbzzyaaautsraponmlkjiaafadcba", "abcdefghijklmnopqrstuvwxyzticrsbwgheuvpptmqlpilntftnliplqmtppvuehgwbsrcitzyxwvutsrqponmlkjihgfedcba", "abcdefghijklmnopqrstuvwxyzjxeludiwenknpgqienvpmyfvfympvneiqgpnknewidulexjzyxwvutsrqponmlkjihgfedcba", "abcdefghijkaanopqrstaalxyzvuwwobcoycyrymdmtqorokzbzkoroqtmdmyrycyocbowwuvzyxlaatsrqponaakjihgfedcba", "abadefgaijklmnapqrstuvwxyzmkvgggxtzajraxboeanqhccpcchqnaeobxarjaztxgggvkmzyxwvutsrqpanmlkjiagfedaba", "abcdefghijklmaopqrstuvaxaaazpobfgrlagnaqziiwkurybxbyrukwiizqangalrgfbopzaaaxavutsrqpoamlkjihgfedcba", "abcdaagaaaalmnaaqrstuvaxyasafaceiwwahokkwajufpqwmzmwqpfujawkkohawwiecafasayxavutsrqaanmlaaaagaadcba", "aaadefaaiakaanoaqraaaawxyaagmhebkchxdjlzptmuivqsdddsqviumtpzljdxhckbehmgaayxwaaaarqaonaakaiaafedaaa", "abcdeeecdabbaaaeeedebedacccdebacbaeceaaeddabbaaeaccaeaabbaddeaaeceabcabedcccadebedeeeaaabbadceeedcba", "ababaaaababaaaababbaaabaabaaaabbbabaababababaaaaaaaaaaaababababaababbbaaaabaabaaabbabaaaababaaaababa", "aacaafghijklmdlajilghdfagdaadaadjckkgiafedkdabgjcddcjgbadkdefaigkkcjdaadaadgafdhglijaldmlkjihgfaacaa", "aacaaaghibbcfaaabgaeeiecceeegigbihaheagibccaeecggddggceeaccbigaehahibgigeeecceieeagbaaafcbbihgaaacaa", "abcdeaghijklmnopiclihaaamkfibaadfepaagobmmgphekeoaaoekehpgmmbogaapefdaabifkmaaahilciponmlkjihgaedcba", "aaadafgaajkamaapaaatuvwacwkacjahqaatabaaiifesnlrxooxrlnsefiiaabataaqhajcakwcawvutaaapaamakjaagfadaaa", "abaaafaaaaalmaapqrstuureadaoakcaatbakanfhsaaasagijjigasaaashfnakabtaackaoadaeruutsrqpaamlaaaaafaaaba", "abcdefggfedegbfggbfeacdddcdccbdfccaeddgcgddgcedabdbadecgddgcgddeaccfdbccdcdddcaefbggfbgedefggfedcba", "abcdefghiiabddfhbfeaeifeibcdbbgbidbbgdhbccgdbedghdhgdebdgccbhdgbbdibgbbdcbiefieaefbhfddbaiihgfedcba", "abcbacacabaaaccabbacbbaabbaaccbabacacaabacbabbaacacaabbabcabaacacababccaabbaabbcabbaccaaabacacabcba", "abcdefeecdecfaadbaeeedfcaeabbdffbecbaedaebeeaaaaaeaaaaaeebeadeabcebffdbbaeacfdeeeabdaafcedceefedcba", "aacaefghijklmnopqrsharaibpjlacapohaslihajanrajdmaaamdjarnajahilsahopacaljpbiarahsrqponmlkjihgfeacaa", "abcdefahiaalmnapqastuvwaazauaaanbaanoaagjkrvhvxvywyvxvhvrkjgaaonaabnaaauazaawvutsaqpanmlaaihafedcba", "abadaagaajkaanapqraaaaabmaaagacieghqrrbjlrornflsmkmslfnrorljbrrqhgeicagaaambaaaaarqpanaakjaagaadaba", "abcaafghajalmnaaqrstuvatalavacwqhadhtvdavakjaaeioppoieaajkavadvthdahqwcavalatavutsrqaanmlajahgfaacba", "IMPOSSIBLE", "IMPOSSIBLE", "abcbaacbcbaabbccaabcbaabacccbaabcccabaabcbaaccbbaabcbcaabcba", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE", "IMPOSSIBLE", "aaaeaaakadavbfghijlomnpqrcstuwxyyxwutscrqpnmoljihgfbvadakaaaeaaa", "IMPOSSIBLE", "aaabaaaaaaaaaaaaaacdefghijklmlkjihgfedcaaaaaaaaaaaaaabaaa", "IMPOSSIBLE", "aabbaa", "a", "aabccbaa", "aaaaaaaaaaaaaaaaaabccbaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "baaacdcaaab", "aaaaaaabcdedcbaaaaaaa", "acdeabbaedca", "baaaaaaaaaccaaaaaaaaab"]}
UNKNOWN
PYTHON3
CODEFORCES
10
138f4354a7cd017a0367d09d328aee4e
Another Sith Tournament
The rules of Sith Tournament are well known to everyone. *n* Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each battle in the Sith Tournament ends with a death of one of opponents? The Tournament ends when the only Sith remains alive. Jedi Ivan accidentally appeared in the list of the participants in the Sith Tournament. However, his skills in the Light Side of the Force are so strong so he can influence the choice of participants either who start the Tournament or who take the loser's place after each battle. Of course, he won't miss his chance to take advantage of it. Help him to calculate the probability of his victory. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=18) — the number of participants of the Sith Tournament. Each of the next *n* lines contains *n* real numbers, which form a matrix *p**ij* (0<=≤<=*p**ij*<=≤<=1). Each its element *p**ij* is the probability that the *i*-th participant defeats the *j*-th in a duel. The elements on the main diagonal *p**ii* are equal to zero. For all different *i*, *j* the equality *p**ij*<=+<=*p**ji*<==<=1 holds. All probabilities are given with no more than six decimal places. Jedi Ivan is the number 1 in the list of the participants. Output a real number — the probability that Jedi Ivan will stay alive after the Tournament. Absolute or relative error of the answer must not exceed 10<=-<=6. Sample Input 3 0.0 0.5 0.8 0.5 0.0 0.4 0.2 0.6 0.0 Sample Output 0.680000000000000
[ "n = int(input())\r\ncnt = [0] * (1 << n)\r\np = [[0] * n for _ in range(n)]\r\nf = [[0] * (1 << n) for _ in range(n)]\r\nfor i in range(n):\r\n p[i] = list(map(float, input().split()))\r\nfor i in range(1, 1 << n):\r\n cnt[i] = cnt[i & (i - 1)] + 1\r\nf[0][1] = 1\r\nfor i in range(1, 1 << n):\r\n if cnt[i] < 2:\r\n continue\r\n for j in range(n):\r\n for k in range(n):\r\n if j != k and (i >> k & 1):\r\n f[j][i] = max(f[j][i], p[j][k] * f[j][i ^ (1 << k)] + p[k][j] * f[k][i ^ (1 << j)])\r\nres = 0\r\nfor i in range(n):\r\n res = max(res, f[i][(1 << n) - 1])\r\nprint(\"{:.12f}\".format(res))# 1691522133.880112", "from decimal import *\r\nar = [list(map(float, input().split())) for i in range(int(input()))]\r\ndp = [[0 for i in range(1 << 18)] for j in range(18)]\r\nn, ans = len(ar), 0\r\ndp[0][(1 << n) - 1] = 1\r\nfor i in range((1 << n) - 1, 0, -1):\r\n for j in range(n):\r\n if i & (1 << j) == 0:\r\n continue\r\n for k in range(n):\r\n if i & (1 << k) != 0 or j == k:\r\n continue\r\n dp[j][i] = max(dp[j][i], dp[k][i ^ (1 << k)] * ar[k][j] + dp[j][i ^ (1 << k)] * ar[j][k])\r\nfor i in range(n):\r\n ans = max(ans, dp[i][1 << i])\r\nprint('{:.6f}'.format(ans))", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\np = [list(map(float, input().split())) for _ in range(n)]\r\npow2 = [1]\r\nfor _ in range(n):\r\n pow2.append(2 * pow2[-1])\r\npn = pow2[n]\r\ndp = [[0] * n for _ in range(pn)]\r\ndp[1][0] = 1\r\nfor i in range(2, pn):\r\n dpi = dp[i]\r\n b = []\r\n for j in range(n):\r\n if i & pow2[j]:\r\n b.append(j)\r\n for j in b:\r\n pj = pow2[j]\r\n for k in b:\r\n if not j ^ k:\r\n continue\r\n pk = pow2[k]\r\n dpi[j] = max(dpi[j], dp[i ^ pj][k] * p[k][j] + dp[i ^ pk][j] * p[j][k])\r\nans = max(dp[pn - 1])\r\nprint(ans)", "import sys\r\n\r\nn = int(input())\r\nprob = [list(map(float, input().split())) for _ in range(n)]\r\ndp = [[0.0]*(1 << n) for _ in range(n)]\r\ndp[0][1] = 1.0\r\n\r\nfor mask in range(3, 1 << n):\r\n for i in range(n):\r\n if not (mask & (1 << i)):\r\n continue\r\n for j in range(n):\r\n if i != j and mask & (1 << j):\r\n dp[i][mask] = max(\r\n dp[i][mask],\r\n dp[i][mask - (1 << j)] * prob[i][j]\r\n + dp[j][mask - (1 << i)] * prob[j][i]\r\n )\r\n\r\nprint(max(dp[i][-1] for i in range(n)))\r\n", "import sys\r\n\r\nn = int(input())\r\nprob = [list(map(float, input().split())) for _ in range(n)]\r\ndp = [[0.0]*n for _ in range(1 << n)]\r\ndp[1][0] = 1.0\r\n\r\nfor mask in range(3, 1 << n):\r\n for i in range(n):\r\n if not (mask & (1 << i)):\r\n continue\r\n for j in range(n):\r\n if i != j and mask & (1 << j):\r\n dp[mask][i] = max(\r\n dp[mask][i],\r\n dp[mask - (1 << j)][i] * prob[i][j]\r\n + dp[mask - (1 << i)][j] * prob[j][i]\r\n )\r\n\r\nprint(max(dp[-1]))\r\n" ]
{"inputs": ["3\n0.0 0.5 0.8\n0.5 0.0 0.4\n0.2 0.6 0.0", "1\n0.0", "2\n0.00 0.75\n0.25 0.00", "4\n0.0 0.6 0.5 0.4\n0.4 0.0 0.3 0.8\n0.5 0.7 0.0 0.5\n0.6 0.2 0.5 0.0", "4\n0.0 0.3 0.5 0.6\n0.7 0.0 0.1 0.4\n0.5 0.9 0.0 0.6\n0.4 0.6 0.4 0.0", "2\n0.0 0.0\n1.0 0.0", "2\n0.0 1.0\n0.0 0.0", "5\n0.0 0.3 0.4 0.5 0.6\n0.7 0.0 0.2 0.6 0.8\n0.6 0.8 0.0 0.6 0.3\n0.5 0.4 0.4 0.0 0.5\n0.4 0.2 0.7 0.5 0.0", "6\n0.00 0.15 0.25 0.35 0.45 0.55\n0.85 0.00 0.35 0.45 0.55 0.65\n0.75 0.65 0.00 0.75 0.85 0.15\n0.65 0.55 0.25 0.00 0.40 0.35\n0.55 0.45 0.15 0.60 0.00 0.70\n0.45 0.35 0.85 0.65 0.30 0.00", "4\n0.0 1.0 1.0 1.0\n0.0 0.0 0.0 1.0\n0.0 1.0 0.0 0.0\n0.0 0.0 1.0 0.0", "4\n0.0 1.0 1.0 1.0\n0.0 0.0 0.0 0.0\n0.0 1.0 0.0 0.0\n0.0 1.0 1.0 0.0", "4\n0.0 1.0 1.0 0.0\n0.0 0.0 0.9 0.2\n0.0 0.1 0.0 1.0\n1.0 0.8 0.0 0.0", "5\n0.0 0.0 0.0 0.0 0.0\n1.0 0.0 0.5 0.5 0.5\n1.0 0.5 0.0 0.5 0.5\n1.0 0.5 0.5 0.0 0.5\n1.0 0.5 0.5 0.5 0.0", "2\n0.000000 0.032576\n0.967424 0.000000", "3\n0.000000 0.910648 0.542843\n0.089352 0.000000 0.537125\n0.457157 0.462875 0.000000", "4\n0.000000 0.751720 0.572344 0.569387\n0.248280 0.000000 0.893618 0.259864\n0.427656 0.106382 0.000000 0.618783\n0.430613 0.740136 0.381217 0.000000", "5\n0.000000 0.629791 0.564846 0.602334 0.362179\n0.370209 0.000000 0.467868 0.924988 0.903018\n0.435154 0.532132 0.000000 0.868573 0.209581\n0.397666 0.075012 0.131427 0.000000 0.222645\n0.637821 0.096982 0.790419 0.777355 0.000000", "6\n0.000000 0.433864 0.631347 0.597596 0.794426 0.713555\n0.566136 0.000000 0.231193 0.396458 0.723050 0.146212\n0.368653 0.768807 0.000000 0.465978 0.546227 0.309438\n0.402404 0.603542 0.534022 0.000000 0.887926 0.456734\n0.205574 0.276950 0.453773 0.112074 0.000000 0.410517\n0.286445 0.853788 0.690562 0.543266 0.589483 0.000000", "7\n0.000000 0.311935 0.623164 0.667542 0.225988 0.921559 0.575083\n0.688065 0.000000 0.889215 0.651525 0.119843 0.635314 0.564710\n0.376836 0.110785 0.000000 0.583317 0.175043 0.795995 0.836790\n0.332458 0.348475 0.416683 0.000000 0.263615 0.469602 0.883191\n0.774012 0.880157 0.824957 0.736385 0.000000 0.886308 0.162544\n0.078441 0.364686 0.204005 0.530398 0.113692 0.000000 0.023692\n0.424917 0.435290 0.163210 0.116809 0.837456 0.976308 0.000000", "2\n0 0.233\n0.767 0"], "outputs": ["0.680000000000000", "1.000000000000000", "0.750000000000000", "0.545000000000000", "0.534000000000000", "0.000000000000000", "1.000000000000000", "0.522400000000000", "0.483003750000000", "1.000000000000000", "1.000000000000000", "1.000000000000000", "0.000000000000000", "0.032576000000000", "0.740400260625000", "0.688466450920859", "0.607133963373199", "0.717680454673393", "0.721455539644280", "0.233000000000000"]}
UNKNOWN
PYTHON3
CODEFORCES
5
13b28296e941bf4b38a92e234423bc69
Resort
Valera's finally decided to go on holiday! He packed up and headed for a ski resort. Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has *n* objects (we will consider the objects indexed in some way by integers from 1 to *n*), each object is either a hotel or a mountain. Valera has also found out that the ski resort had multiple ski tracks. Specifically, for each object *v*, the resort has at most one object *u*, such that there is a ski track built from object *u* to object *v*. We also know that no hotel has got a ski track leading from the hotel to some object. Valera is afraid of getting lost on the resort. So he wants you to come up with a path he would walk along. The path must consist of objects *v*1,<=*v*2,<=...,<=*v**k* (*k*<=≥<=1) and meet the following conditions: 1. Objects with numbers *v*1,<=*v*2,<=...,<=*v**k*<=-<=1 are mountains and the object with number *v**k* is the hotel. 1. For any integer *i* (1<=≤<=*i*<=&lt;<=*k*), there is exactly one ski track leading from object *v**i*. This track goes to object *v**i*<=+<=1. 1. The path contains as many objects as possible (*k* is maximal). Help Valera. Find such path that meets all the criteria of our hero! The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of objects. The second line contains *n* space-separated integers *type*1,<=*type*2,<=...,<=*type**n* — the types of the objects. If *type**i* equals zero, then the *i*-th object is the mountain. If *type**i* equals one, then the *i*-th object is the hotel. It is guaranteed that at least one object is a hotel. The third line of the input contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=*n*) — the description of the ski tracks. If number *a**i* equals zero, then there is no such object *v*, that has a ski track built from *v* to *i*. If number *a**i* doesn't equal zero, that means that there is a track built from object *a**i* to object *i*. In the first line print *k* — the maximum possible path length for Valera. In the second line print *k* integers *v*1,<=*v*2,<=...,<=*v**k* — the path. If there are multiple solutions, you can print any of them. Sample Input 5 0 0 0 0 1 0 1 2 3 4 5 0 0 1 0 1 0 1 2 2 4 4 1 0 0 0 2 3 4 2 Sample Output 5 1 2 3 4 5 2 4 5 1 1
[ "\ndef solve():\n\tn = int(input())\n\tarr = list(map(int,input().split()))\n\tparent = list(map(int,input().split()))\n\tdegree = [0]*n\n\tfor i in range(n):\n\t\tparent[i] -=1\n\t\tif parent[i]!=-1:\n\t\t\tdegree[parent[i]]+=1\n\tans = []\n\tvisited = [False]*n\n\tfor i in range(n):\n\t\tif arr[i]==1:\n\t\t\ts = i\n\t\t\ttmp = []\n\t\t\twhile parent[s]!=-1 and degree[parent[s]]<=1:\n\t\t\t\ttmp.append(s)\n\t\t\t\ts = parent[s]\n\t\t\ttmp.append(s)\n\t\t\tif len(tmp)>len(ans):\n\t\t\t\tans = tmp\n\tans = ans[::-1]\n\tprint(len(ans))\n\tfor i in ans:\n\t\tprint(i+1,end=' ')\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 = int(input())\r\na, b = [0] + list(map(int, input().split())), [0] + list(map(int, input().split()))\r\nans, p = [], [0] * (n + 1)\r\nfor i in b:\r\n p[i] += 1\r\nfor i in range(1, n + 1):\r\n if a[i] == 1:\r\n t = [i]\r\n x = b[i]\r\n while p[x] == 1:\r\n t.append(x)\r\n x = b[x] \r\n if len(t) > len(ans): ans = t[:]\r\nans.reverse()\r\nprint(len(ans))\r\nprint(' '.join(str(x) for x in ans))", "num = int(input()) + 1\nobj = list(map(int, input().strip().split()))\nski = list(map(int, input().strip().split()))\nadj = [set() for _ in range(num)]\nout = [set() for _ in range(num)]\ndiscovered = [False] * num\n\nfor u, v in enumerate(ski):\n if v != 0:\n adj[u + 1].add(v)\n out[v].add(u + 1)\n\nhotel = []\nfor i, t in enumerate(obj):\n if t == 1:\n hotel.append(i + 1)\n\nq = []\np = [0] * num\nendNode = None\nfor i in hotel:\n q.append((i, 1))\n p[i] = i\n endNode = i\n\nmaxim = 1\nwhile len(q) != 0:\n u, depth = q.pop(0)\n if len(adj[u]) == 0:\n endNode = u\n maxim = max(maxim, depth)\n for v in adj[u]:\n if len(out[v]) == 1:\n endNode = v\n maxim = max(maxim, depth + 1)\n p[v] = u\n q.append((v, depth + 1))\n\nprint(maxim)\nwhile p[endNode] != endNode:\n print(endNode, end=\" \")\n endNode = p[endNode]\nprint(endNode)\n \t \t\t\t \t\t \t\t \t\t \t \t\t\t\t\t\t", "#!/usr/bin/python3\n\ndef readln(): return tuple(map(int, input().split()))\n\nn, = readln()\nt = (-1,) + readln()\nv = (0,) + readln()\ncnt = [0] * (n + 1)\nfor i in range(1, n + 1):\n cnt[v[i]] += 1\nans = []\nfor i in range(1, n + 1):\n if t[i] == 1:\n j = i\n tmp = [i]\n while(t[v[j]] == 0) and cnt[v[j]] == 1:\n j = v[j]\n tmp.append(j)\n if(len(tmp) > len(ans)):\n ans = tmp\nprint(len(ans))\nprint(*tuple(reversed(ans)))\n", "def walk(parent, out_degree, i):\r\n path = []\r\n path.append(i + 1)\r\n\r\n idx = i\r\n\r\n while parent[idx] != -1:\r\n idx = parent[idx]\r\n # print(idx)\r\n if out_degree[idx] >= 2:\r\n break\r\n\r\n path.append(idx + 1)\r\n\r\n path.reverse()\r\n\r\n return path\r\n\r\n\r\n# Reading input and creating the graph\r\ndef solve():\r\n n = int(input().strip())\r\n v = list(map(int, input().split()))\r\n a = list(map(int, input().split()))\r\n\r\n parent = [-1] * n\r\n\r\n out_degree = [0] * n\r\n\r\n for index, e in enumerate(a):\r\n if e > 0:\r\n parent[index] = e - 1\r\n out_degree[e - 1] += 1\r\n\r\n # print(parent)\r\n # print(out_degree)\r\n\r\n answer = 0\r\n path = []\r\n for i in range(n):\r\n if v[i] == 1: # It is a hotel\r\n tmp_path = walk(parent, out_degree, i)\r\n\r\n if len(tmp_path) > answer:\r\n answer = len(tmp_path)\r\n path = tmp_path\r\n\r\n print(len(path))\r\n print(*path)\r\n\r\n\r\nsolve()\r\n", "n = int(input())\nt = [0] + list(map(int, input().split()))\na = [0] + list(map(int, input().split()))\n\nans, cnt = [], [0 for i in range(n + 1)]\n\nfor i in a:\n cnt[i] += 1\n\nfor i in range(1, n + 1):\n if t[i] == 1:\n crt = [i]\n x = a[i]\n while cnt[x] == 1:\n crt.append(x)\n x = a[x]\n if len(crt) > len(ans):\n ans = crt[:]\nans.reverse()\nprint(len(ans))\nprint(' '.join(map(str, ans)))\n\t \t\t \t\t\t\t\t\t \t\t\t\t \t\t \t \t\t", "import sys\ndef Z(s):\n return int(s)-1\n\nn=int(sys.stdin.readline())\n\nHotels=[False]*(n)\n\nRep=[0]*(n+1)\nChains=[]\n\nType=list(map(int,sys.stdin.readline().split()))\nfor i in range(n):\n if(Type[i]==1):\n Hotels[i]=True\nA=list(map(Z,sys.stdin.readline().split()))\n\nfor item in A:\n Rep[item]+=1\nfor i in range(n):\n if(Hotels[i]):\n Chains.append([i])\n x=A[i]\n if(x==-1):\n continue\n while(A[x]!=-1 and Rep[x]<=1):\n Chains[-1].append(x)\n x=A[x]\n if(Rep[x]<=1):\n Chains[-1].append(x)\n\n\n \n \nif(n==1):\n print(1)\n print(1)\nelse:\n \n X=max(Chains,key=len)\n\n\n\n sys.stdout.write(str(len(X))+\"\\n\")\n sys.stdout.write(str(X[-1]+1))\n\n for i in range(len(X)-2,-1,-1):\n sys.stdout.write(\" \"+str(X[i]+1)) \n \n", "if __name__ == '__main__':\n n = int(input())\n types = [0] + list(map(int, input().split()))\n nodes = [0] + list(map(int, input().split()))\n\n sol, count = [], [0 for i in range(n + 1)]\n\n for i in nodes:\n count[i] += 1\n\n for i in range(1, n+1):\n if types[i] == 1:\n path = [i]\n x = nodes[i]\n while count[x] == 1:\n path.append(x)\n x = nodes[x]\n if len(path) > len(sol):\n sol = path[:]\n sol.reverse()\n print(len(sol))\n print(*sol)\n # print(' '.join(map(str, sol)))\n", "\"\"\"\nSummary of the code:\nRuntime Complexity:\nSpace Complexity:\nWhy the chosen algorithm is good:\n\"\"\"\nINF = 10**6\n\nn = int(input())\ntypes = [INF] + [int(i) for i in input().split()]\nA = [INF] + [int(i) for i in input().split()]\nPath = [[] for i in range(n+1)]\nfor i in range(1,n+1):\n if A[i]:\n Path[A[i]].append(i)\n\nend = []\nlongest = []\nfor i in range(1,n+1):\n if types[i] == 0:\n continue\n start = i\n path_tmp = []\n while 1:\n if len(Path[start]) == 0 and start != i:\n path_tmp.append(start)\n break\n if len(Path[start]) > 1:\n break\n path_tmp.append(start)\n start = A[start]\n if start == 0:\n break\n if len(longest) < len(path_tmp):\n longest = path_tmp\nprint(len(longest))\nprint(\" \".join(str(i) for i in longest[::-1]))\n\t\t\t \t\t \t\t\t\t\t \t \t \t\t\t \t", "n = int(input())\r\nt = [0] + list(map(int, input().split()))\r\na = [0] + list(map(int, input().split()))\r\n\r\nres, cnt = [], [0] * (n + 1)\r\nfor i in a:\r\n cnt[i] += 1\r\nfor i in range(1, n+1):\r\n if t[i] == 0: \r\n continue\r\n curr_res = [i]\r\n x = a[i]\r\n while cnt[x] == 1:\r\n curr_res.append(x)\r\n x = a[x]\r\n if len(curr_res) > len(res):\r\n res = curr_res[:]\r\nres.reverse()\r\nprint(len(res))\r\nprint(*res)\r\n", "import sys\r\n\r\n\r\nn = int(input())\r\ntype = input().split()\r\nfa = list(map(int, input().split()))\r\n\r\ndegree = [0] * (n+1)\r\nfor i in fa:\r\n degree[i]+=1\r\n\r\ntype = [0] + type\r\nfa= [0] + fa\r\nmax=0\r\nmaxi=0\r\n\r\nfor i in range(1, n+1):\r\n if type[i] == '1': # it's hotel\r\n cnt = 0\r\n\r\n cur=fa[i]\r\n while not (cur==0 or type[cur] == '1' or degree[cur]>1):\r\n cnt+=1\r\n cur=fa[cur]\r\n\r\n if(max <= cnt):\r\n max=cnt\r\n maxi=i\r\nprint(max+1)\r\nans = []\r\ncur=maxi\r\nwhile not(not cur or type[cur] == '1' and cur!=maxi or degree[cur]>1):\r\n ans.append(cur)\r\n cur=fa[cur]\r\n\r\nprint(*ans[::-1])", "def walk(i, parent, out_degree: list):\r\n path = []\r\n while i >= 0 and (out_degree[i] <= 1):\r\n path.append(i)\r\n i = parent[i]\r\n return path\r\n\r\n\r\ndef solve():\r\n n = int(input().strip())\r\n v = list(map(int, input().split()))\r\n a = list(map(int, input().split()))\r\n\r\n parent = [-1] * n\r\n out_degree = [0] * n\r\n for index, e in enumerate(a):\r\n if e > 0:\r\n parent[index] = e - 1\r\n out_degree[e - 1] += 1\r\n\r\n # The initial solution is empty\r\n best = []\r\n for index, e in enumerate(v):\r\n # Check if it is a hotel\r\n if e == 1:\r\n path = walk(index, parent, out_degree)\r\n # If the path leading to this hotel is bigger than the current solution, let's update it.\r\n if len(path) > len(best):\r\n best = path\r\n # Print answer\r\n print(len(best))\r\n res = [f\"{e + 1}\" for e in best[::-1]]\r\n print(\" \".join(res))\r\n\r\n\r\nsolve()\r\n", "\"\"\"\nSummary of the code:\n- Go through the ski resort by backtracking\n\nRuntime Complexity:\n- input => O(N)\n- finding longest path => O(N)\n- printing => O(N)\n- total => O(N + N + N) => O(N)\n\nSpace Complexity:\n- input => O(N) + O(N)\n- creating Path => O(N)\n- longest => O(maximum length) => O(M)\n- total => O(2N) + O(N) + O(M) => O(N + M)\n\nWhy the chosen algorithm is good:\n- Time complexity is O(N) and the maximum of N is 10^5\n- 10^5 < 10^7 thus it will pass\n\"\"\"\nINF = 10**6\n\nn = int(input())\ntypes = [INF] + [int(i) for i in input().split()]\nA = [INF] + [int(i) for i in input().split()]\nPath = [[] for i in range(n+1)]\nfor i in range(1,n+1):\n if A[i]:\n Path[A[i]].append(i)\n\nlongest = []\nfor i in range(1,n+1):\n if types[i] == 0:\n continue\n start = i\n path_tmp = []\n while 1:\n if len(Path[start]) == 0 and start != i:\n path_tmp.append(start)\n break\n if len(Path[start]) > 1:\n break\n path_tmp.append(start)\n start = A[start]\n if start == 0:\n break\n if len(longest) < len(path_tmp):\n longest = path_tmp\nprint(len(longest))\nprint(\" \".join(str(i) for i in longest[::-1]))\n \t\t \t \t\t \t \t \t\t\t\t \t\t \t \t", "n = int(input())\r\nlist_a, list_b = [0] + list(map(int, input().split())), [0] + list(map(int, input().split()))\r\nresult, p = [], [0] * (n + 1)\r\n\r\nfor i in list_b:\r\n p[i] += 1\r\n\r\nfor i in range(1, n + 1):\r\n if list_a[i] == 1:\r\n temp_list = [i]\r\n x = list_b[i]\r\n\r\n while p[x] == 1:\r\n temp_list.append(x)\r\n x = list_b[x]\r\n\r\n if len(temp_list) > len(result):\r\n result = temp_list[:]\r\n\r\nresult.reverse()\r\nprint(len(result))\r\nprint(' '.join(str(x) for x in result))\r\n", "import sys\n\ndef solve():\n n = int(input())\n types = list(map(int, input().split()))\n a = list(map(int, input().split()))\n res = list()\n count = [0] * (n + 1)\n for val in a:\n count[val-1]+=1\n for i in range(n):\n if types[i] == 1:\n temp = list()\n cur = i\n while True:\n if count[cur] > 1 or cur < 0: break\n temp.append(cur + 1)\n cur = a[cur] - 1\n if len(temp) > len(res):\n res = temp\n print(len(res))\n return ' '.join(map(str, res[::-1]))\n\nif sys.hexversion == 50594544 : sys.stdin = open(\"test.txt\")\nprint(solve())" ]
{"inputs": ["5\n0 0 0 0 1\n0 1 2 3 4", "5\n0 0 1 0 1\n0 1 2 2 4", "4\n1 0 0 0\n2 3 4 2", "10\n0 0 0 0 0 0 0 0 0 1\n4 0 8 4 7 8 5 5 7 2", "50\n0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0\n28 4 33 22 4 35 36 31 42 25 50 33 25 36 18 23 23 28 43 3 18 31 1 2 15 22 40 43 29 32 28 35 18 27 48 40 14 36 27 50 40 5 48 14 36 24 32 33 26 50", "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 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 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0\n86 12 47 46 45 31 20 47 58 79 23 70 35 72 37 20 16 64 46 87 57 7 84 72 70 3 14 40 17 42 30 99 12 20 38 98 14 40 4 83 10 15 47 30 83 58 12 7 97 46 17 6 41 13 87 37 36 12 7 25 26 35 69 13 18 5 9 53 72 28 13 51 5 57 14 64 28 25 91 96 57 69 9 12 97 7 56 42 31 15 88 16 41 88 86 13 89 81 3 42", "10\n1 0 0 0 0 0 0 0 0 0\n6 2 7 8 2 9 0 5 4 2", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n38 2 49 55 6 42 12 100 25 69 85 76 13 22 78 73 37 64 5 21 0 23 61 87 4 16 44 3 98 54 1 91 18 26 82 24 18 50 95 21 75 97 51 9 67 73 51 19 63 92 27 82 8 7 20 84 2 93 40 11 39 80 58 85 74 48 72 78 34 33 31 65 46 71 32 36 33 88 47 4 66 84 16 27 16 14 90 16 79 41 99 30 57 73 28 89 45 81 86 29", "2\n1 1\n0 0", "1\n1\n0"], "outputs": ["5\n1 2 3 4 5", "2\n4 5", "1\n1", "2\n2 10", "2\n3 20", "1\n44", "6\n5 8 4 9 6 1", "52\n57 93 58 63 49 3 28 95 39 61 23 22 14 86 99 91 32 75 41 90 87 24 36 76 12 7 54 30 92 50 38 1 31 71 74 65 72 67 45 97 42 6 5 19 48 66 81 98 29 100 8 53", "1\n1", "1\n1"]}
UNKNOWN
PYTHON3
CODEFORCES
15
13b7ef974745d76a78439919a6ed01eb
Mike and gcd problem
Mike has a sequence *A*<==<=[*a*1,<=*a*2,<=...,<=*a**n*] of length *n*. He considers the sequence *B*<==<=[*b*1,<=*b*2,<=...,<=*b**n*] beautiful if the *gcd* of all its elements is bigger than 1, i.e. . Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index *i* (1<=≤<=*i*<=&lt;<=*n*), delete numbers *a**i*,<=*a**i*<=+<=1 and put numbers *a**i*<=-<=*a**i*<=+<=1,<=*a**i*<=+<=*a**i*<=+<=1 in their place instead, in this order. He wants perform as few operations as possible. Find the minimal number of operations to make sequence *A* beautiful if it's possible, or tell him that it is impossible to do so. is the biggest non-negative number *d* such that *d* divides *b**i* for every *i* (1<=≤<=*i*<=≤<=*n*). The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — length of sequence *A*. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — elements of sequence *A*. Output on the first line "YES" (without quotes) if it is possible to make sequence *A* beautiful by performing operations described above, and "NO" (without quotes) otherwise. If the answer was "YES", output the minimal number of moves needed to make sequence *A* beautiful. Sample Input 2 1 1 3 6 2 4 2 1 3 Sample Output YES 1 YES 0 YES 1
[ "from math import gcd\nn = int(input())\na = list(map(int, input().split()))\nj, s, d = 0, 0, 0\nwhile j < n:\n if a[j] % 2:\n if j + 1 < n and a[j + 1] % 2:\n s += 1\n j += 2\n else:\n d += 1\n j += 1\n else:\n j += 1\ng = 0\nfor x in a:\n g = gcd(g, x)\nprint('YES')\nif g > 1:\n print(0)\nelse:\n print(s + 2 * d)", "import math\r\nn = input()\r\ns = map(int, input().split())\r\nres = cur = g = 0\r\nfor x in s:\r\n g = math.gcd(x, g)\r\n if (x & 1) == 0:\r\n res += math.ceil(cur / 2) + (cur & 1)\r\n cur = 0\r\n else:\r\n cur += 1\r\nres += math.ceil(cur / 2) + (cur & 1)\r\nprint(\"YES\")\r\nif g == 1:\r\n print(res)\r\nelse:\r\n print(\"0\")", "import math\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nret=0\r\nv=a[0]\r\nfor i in range(1,n):\r\n v=math.gcd(v,a[i])\r\nif(v!=1):\r\n print(\"YES\\n\"+str(0))\r\n exit()\r\nfor i in range(n):\r\n if(a[i]%2==0):\r\n continue\r\n elif(i+1==n):\r\n ret+=2\r\n else:\r\n if(a[i+1]%2==0):\r\n ret+=2\r\n else:\r\n ret+=1\r\n a[i+1]=2\r\nprint(\"YES\\n\"+str(ret))", "s, i, n = 0, 0, int(input())\r\nt = list(map(int, input().split())) + [0]\r\nwhile i < n:\r\n if t[i] % 2:\r\n i += 1\r\n s += 2 - t[i] % 2\r\n i += 1\r\nb = t[0]\r\nfor a in t:\r\n while a: a, b = b % a, a\r\n if b == 1: break\r\nprint('YES', 0 if b > 1 else s)", "n=int(input())\r\nimport math \r\nl=list(map(int, input().split()))\r\n\r\nprint(\"YES\")\r\n\r\nx=0 \r\n\r\n\r\ndef gcd(a,b):\r\n if a<b:\r\n a,b=b,a \r\n if b==0:\r\n return a \r\n return gcd(b, a%b)\r\n\r\nfor i in l:\r\n x=gcd(x,i)\r\n\r\n\r\nif x>1:\r\n print(0) \r\n \r\nelse:\r\n ans=0 \r\n x=0 \r\n for i in l:\r\n if i%2==1:\r\n x+=1 \r\n else:\r\n ans+=math.ceil(x/2)\r\n if x%2==1:\r\n ans+=1 \r\n x=0 \r\n ans+=math.ceil(x/2)\r\n if x%2==1:\r\n ans+=1 \r\n print(ans )" ]
{"inputs": ["2\n1 1", "3\n6 2 4", "2\n1 3", "9\n57 30 28 81 88 32 3 42 25", "2\n8 77", "4\n92 46 3 21", "2\n78 26", "2\n3 6", "2\n3 9", "2\n3 3", "3\n3 6 3", "3\n3 9 15", "3\n3 6 9", "3\n3 3 3", "3\n3 9 18", "5\n1 2 1 2 1", "2\n9 6", "4\n3 6 9 12", "3\n3 9 27", "3\n3 9 12", "5\n6 6 9 15 21", "2\n5 15", "4\n2 3 9 13", "4\n3 3 3 3", "5\n3 9 9 9 27", "2\n9 9", "3\n3 9 9", "3\n7 14 21", "3\n3 12 4", "5\n3 3 3 3 3"], "outputs": ["YES\n1", "YES\n0", "YES\n1", "YES\n8", "YES\n2", "YES\n1", "YES\n0", "YES\n0", "YES\n0", "YES\n0", "YES\n0", "YES\n0", "YES\n0", "YES\n0", "YES\n0", "YES\n6", "YES\n0", "YES\n0", "YES\n0", "YES\n0", "YES\n0", "YES\n0", "YES\n3", "YES\n0", "YES\n0", "YES\n0", "YES\n0", "YES\n0", "YES\n2", "YES\n0"]}
UNKNOWN
PYTHON3
CODEFORCES
5
13bdb1f2506b952ef6004ba0c77808ec
Inbox (100500)
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread. Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: - Move from the list of letters to the content of any single letter.- Return to the list of letters from single letter viewing mode.- In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one. The program cannot delete the letters from the list or rearrange them. Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters? The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox. The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. Print a single number — the minimum number of operations needed to make all the letters read. Sample Input 5 0 1 0 1 0 5 1 1 0 0 1 2 0 0 Sample Output 3 4 0
[ "entrada = int(input())\ncartas = input()\nlista_cartas = cartas.split(\" \")\noperacoes = 0\nif '1' not in lista_cartas:\n print(0)\nelse:\n index = -1\n for i in range(len(lista_cartas)):\n\n if lista_cartas[i] == '1':\n if(index < 0 or index + 1 == i):\n operacoes +=1\n else:\n operacoes +=2\n index = i\n print(operacoes)\n \t \t \t\t\t\t\t\t \t \t\t\t\t\t\t \t\t \t", "n = int(input())\na = [int(i) for i in input().split()]\nr = 0\nb = False\nfor i in a:\n if i == 0:\n r += 1 if b else 0\n b = False\n else:\n r += 1\n b = True\nprint(r if b else max(r - 1, 0))\n", "n = int(input())\nps = input().split() + ['0']\n\nqs = []\nk = 0\nfor p in ps:\n if p == '1':\n k += 1\n elif p == '0':\n if k > 0:\n qs.append(k)\n k = 0\n else:\n print('WTF?!')\n\nif qs:\n r = sum(qs) + len(qs) - 1\nelse:\n r = 0\n\nprint(r)\n", "n = int(input())\r\nletters = list(map(int, input().split()))\r\n\r\nsteps = 0 if letters[0] == 0 else 2\r\n\r\nfor i in range(1,n):\r\n if letters[i] == 1:\r\n steps += 2\r\n if letters[i - 1] == 0:\r\n pass\r\n else:\r\n steps -= 1\r\n else:\r\n pass\r\nif steps == 0:\r\n print(0)\r\nelse:\r\n print(steps - 1)", "cartas = int(input())\ncaixa = input().split()\n\noperacoes = 0\ncont = 0\nboolean = False\nfor i in range(len(caixa)):\n\tif caixa[i] == \"1\":\n\t\tboolean = True\n\t\tif cont == 1 or cont > 1:\n\t\t\toperacoes += 1\n\n\t\tcont = 0\n\t\toperacoes += 1\n\tif caixa[i] == \"0\" and boolean:\n\t\tcont += 1\n\nprint(operacoes)\n\n \t\t \t\t\t \t \t\t\t\t\t\t \t \t \t \t", "f=lambda:map(int,input().split())\r\nn=int(input())\r\nl=list(f())\r\nc=0\r\nfor i in range(1,n):\r\n if [l[i-1],l[i]]!=[0,0]:\r\n c+=1\r\nif l[0]==1:\r\n c+=1\r\nif l[-1]==0:\r\n c-=1\r\nprint(max(0,c))", "#input\r\nn=int(input())\r\nletter=str(input())\r\n\r\n#variables\r\n\r\n#main\r\nif '1' not in letter:\r\n\tprint(0)\r\n\tquit()\r\n\r\nif '1 1' not in letter:\r\n\tprint(2*letter.count('1')-1)\r\n\tquit()\r\n\r\nop=2*letter.count('1')-1\r\n\r\nfor i in range(n-1):\r\n\tif letter[2*i]=='1' and letter[2*i+2]=='1':\r\n\t\top-=1\r\n\r\nprint(op)", "n=int(input())\r\nL=list(map(int,input().split(' ')))\r\ns=[]\r\nfor i in range(n):\r\n if L[i]==1:\r\n s.append(i)\r\nif len(s)!=0:\r\n count=1\r\n \r\n for i in range(len(s)-1):\r\n count=count+min(2,s[i+1]-s[i])\r\n \r\n print(count)\r\nelse :\r\n print(0)", "n = int(input())\r\na = list(map(int, input().split()))\r\nprev = 1\r\nans = 0\r\nfor x in a:\r\n if x == 1:\r\n if ans == 0 or prev == 1:\r\n ans += 1\r\n else:\r\n ans += 2\r\n prev = x\r\nprint(ans)", "# Codeforces 265 Div. 2\r\n# B\r\n\r\nn = input()\r\nl = input().split()\r\n\r\nx = 0\r\nfor i in range(len(l)):\r\n if l[i] == \"1\":\r\n x += 1\r\nl.append(\"2\")\r\nc = 0\r\nd = 0\r\n\r\nfor i in range(len(l)-1):\r\n if d == 0:\r\n if l[i] == '1':\r\n c += 1\r\n x -= 1\r\n if x == 0:\r\n break\r\n if l[i+1] == '1':\r\n d = 1\r\n else:\r\n c += 1\r\n else:\r\n c += 1\r\n x -= 1\r\n if x == 0:\r\n break\r\n if l[i+1] == '0':\r\n c += 1\r\n d = 0\r\n\r\nprint(c)\r\n", "n = int(input())\r\narr = list(map(int, input().split())) + [0]\r\nres = []\r\nk = 0\r\nfor i in arr:\r\n if i == 1:\r\n k += 1\r\n else:\r\n if k > 0:\r\n res.append(k)\r\n k = 0\r\nif len(res) > 0:\r\n print(sum(res) + len(res) - 1)\r\nelse:\r\n print(0)\r\n", "__author__ = '$'\r\nimport sys\r\n\r\n\r\ntry:\r\n while True:\r\n n = int(input())\r\n val = list(map(int, input().split(\" \")))\r\n vec = []\r\n for i in range (n):\r\n if val[i]:\r\n vec.append(i)\r\n res = 1 if len(vec) else 0\r\n for i in range(1, len(vec), 1):\r\n res += (2 if (vec[i] != vec[i-1] + 1) else 1)\r\n print(res)\r\nexcept EOFError:\r\n pass", "from itertools import groupby\r\nn = int(input())\r\na = map(int, input().split())\r\nc = 0\r\nfor r, g in groupby(a):\r\n if r == 1:\r\n c += len(list(g)) + 1\r\nprint(max(0, c - 1))", "\r\n\r\nfrom collections import deque\r\n\r\nn = int(input())\r\nl = list(map(int,input().split()))\r\nd = deque()\r\n\r\nif len(set(l)) == 1 and l[0] == 0 :\r\n print(0)\r\n exit(0)\r\nfor i in range(n):\r\n if l[i] == 1 :\r\n d.append(i)\r\n\r\n#print(d)\r\ncnt = 0\r\n\r\nfor i in range(1 , len(d)):\r\n\r\n v = d[i] - d[i-1]\r\n\r\n if v > 2 :\r\n cnt += 2\r\n\r\n else:\r\n cnt += v\r\n\r\n\r\nprint(cnt + 1 )\r\n\r\n\r\n\r\n\r\n", "n=int(input())\r\na=[int(i) for i in input().split()]\r\nx=0\r\nh=0\r\nfor i in range(n):\r\n if(a[i]==1):\r\n if(x==0):\r\n h+=1\r\n x=1\r\n elif(x==1):\r\n h+=1\r\n if(a[i]==0 and 1 in a[i:]):\r\n if(x==1):\r\n h+=1\r\n x=0\r\nprint(h)", "n = int(input())\r\narr = list(map(int,input().split()))\r\nl = -1\r\nans = 0\r\nfor j,aj in enumerate(arr):\r\n if aj==0:\r\n continue\r\n elif l==-1:\r\n ans+=1\r\n l = j\r\n else:\r\n ans+= min(j-l,2)\r\n l = j\r\nprint(ans)\r\n", "n=int(input())\na=list(map(int, input().split()))\ncnt=0\nc=0\npos=-1\nwhile cnt<len(a):\n if a[cnt]:\n c+=1\n if pos==-1:\n pos=cnt\n cnt+=1\nres=0\ncnt=1\nwhile c:\n if a[pos]==1:\n if cnt<=2:\n res+=cnt\n else:\n res+=2\n cnt=0\n c-=1\n pos+=1\n cnt+=1\nprint(res)", "def main():\r\n\tn=input()\r\n\tn=int(n)\r\n\ta=map(int,input().split(\" \"))\r\n\ta=list(a)\r\n\tif 0 in a:\r\n\t\tif len(a) == a.count(0):\r\n\t\t\tprint (0)\r\n\t\t\treturn\r\n\t\tpass\r\n\tpass\r\n\ta=map(str,a)\r\n\ta=\"\".join(a)\r\n\ta=a.split(\"0\")\r\n\ts=0\r\n\tfor x in a:\r\n\t\ts+=len(x)\r\n\tpass\r\n\tz=len(a)-a.count('')\r\n\tprint (s+z-1)\r\n\tpass\r\n\t\r\nmain()\r\n\r\n\r\n", "letras = int(input())\n\nlinha = input().split()\ncerto = 0\ncont = 0\n\nfor i in range(len(linha)):\n if linha[i] == \"1\":\n certo += 1\n\ncont2 = 0\n\nfor i in range(len(linha)):\n if linha[i] == \"1\":\n cont += 1\n cont2 += 1\n if i < len(linha)-1 :\n if linha[i+1] == \"0\" and cont2 < certo:\n cont += 1\n\nprint(cont)\n\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())\nmail_list = list(map(int, input().split()))\n\ncounter = 0\ni = 0\n\nwhile i < len(mail_list)-1:\n if mail_list[i] and mail_list[i+1]:\n counter += 1\n else:\n if mail_list[i]:\n counter += 2\n i += 1\n\nif mail_list[-1]:\n counter += 1\nelse:\n counter -= 1\n\nprint(counter if counter > 0 else 0)\n\n", "#!/usr/bin/env python3\n\ndef main():\n n = input()\n letters = input().split()\n\n lst = -1\n cnt = 0\n\n for i, x in enumerate(letters):\n if x == '1':\n if lst + 1 == i or lst == -1:\n cnt += 1\n else:\n cnt += 2\n\n lst = i\n\n print(max(0, cnt))\n\nif __name__ == '__main__':\n main()", "\r\nn = int(input())\r\nletters = input().split()\r\nletters = ''.join(letters)\r\nletters = letters.split('0')\r\nunread_list = []\r\nfor element in letters:\r\n if element:\r\n unread_list.append(element)\r\nif unread_list:\r\n operations = 0\r\n for i in range(len(unread_list) - 1):\r\n operations += 1 + len(unread_list[i])\r\n operations += len(unread_list[-1])\r\n print(operations)\r\nelse:\r\n print(0)\r\n\r\n", "n = int(input())\ns = ''.join(input().split())\nindex = s.find('1')\nif index < 0:\n operation = 0\nelse:\n operation = 1\n s = s[index+1:] \nwhile index+1:\n index = s.find('1')\n if index == 0:\n operation += 1\n elif index > 0:\n operation += 2\n s = s[index+1:]\nprint(operation)\n\n \n ", "n=int(input())\r\nstates=input().split()\r\nop=0\r\ncarry=0\r\nfor i in range(0,n):\r\n if states[i]=='1': \r\n op= op + 1 + carry\r\n carry=0\r\n if i+1<n:\r\n if states[i+1]=='1':\r\n continue\r\n else:\r\n carry=1\r\nprint(op)", "'''input\n2\n0 0\n'''\nn = int(input())\nl = \"\".join(input().split())\nwhile \"00\" in l:\n\tl = l.replace(\"00\", \"0\")\nl = l.replace(\"0\", \" \")\nprint(len(l.strip()))", "n = int(input())\r\ns = input()\r\na = (s.split())\r\nb = []\r\nx = 0\r\nfor i in range(len(a)):\r\n if a[i] == '1':\r\n x += 1\r\n elif (x != 0):\r\n #print(i)\r\n b.append(x)\r\n x = 0\r\nif x != 0:\r\n b.append(x)\r\nif len(b) != 0:\r\n print (sum(b)+len(b)-1)\r\nelse:\r\n print ('0')", "num = int(input())\r\nletters = [ int(x) for x in input().split() ]\r\ncount = 0\r\nones = letters.count(1)\r\nfor i in range(num):\r\n if letters[i] == 1:\r\n count += 1\r\n ones -= 1\r\n if i < num - 1 and letters[i + 1] == 0 and ones > 0:\r\n count += 1\r\nprint(count)", "n, a = int(input()), (int(i) for i in input().split())\nres, prev = 0, None\nfor i in a:\n res += (1 + (res > 0 and prev != i)) if i == 1 else 0\n prev = i\nprint(res)\n", "n = input()\nnumbers = input()\n\nfirstUnreadSaw = False\nnumOperations = 0\nnumbersList = numbers.split()\n\nfor i in range(int(n)):\n if numbersList[i] == '1' and not firstUnreadSaw:\n numOperations+=1\n firstUnreadSaw = True\n elif numbersList[i] == '1' and firstUnreadSaw and numbersList[i-1] != '0':\n numOperations+=1\n elif numbersList[i] == '1' and firstUnreadSaw and numbersList[i-1] == '0':\n numOperations+=2\n\nprint(numOperations)\n\t \t\t \t\t \t \t\t \t\t\t \t\t\t \t", "sx = int(input())\nlista = [int(x) for x in input().split()]\n\nans = 0\n\nultimo = 1\nachou = False\n\nfor i in lista:\n if achou:\n if i == 1:\n if ultimo == 1:\n ans +=1\n else:\n ans +=2\n ultimo = i\n else:\n if i == 1:\n achou = True\n ans+=1\n\nprint(ans)\n", "n = int(input())\n\nc = 0\nz = 0 \n\ns = input()\n\nfor i in s:\n if (i == \"1\"):\n c += 1\n if z: \n c += 1\n z = 0 \n elif(i == \"0\" and c > 0):\n z = 1 \n\nprint(c)\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\nfor t in range(1):\r\n n=int(input())\r\n arr=get_list()\r\n counter=dict([])\r\n for i in range(n):\r\n if arr[i] in counter:\r\n counter[arr[i]].append(i)\r\n else:\r\n counter[arr[i]]=[i]\r\n ans=0\r\n for i in counter:\r\n if i==0:\r\n continue\r\n row=counter[i]\r\n ans+=1\r\n for i in range(1,len(row)):\r\n gap=row[i]-row[i-1]\r\n ans+=min(gap,2)\r\n print(ans)", "n=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nif l.count(1)>0:\r\n d=l.index(1)\r\n c+=1\r\n for i in range(d+1,n):\r\n if l[i]==1 and l[i-1]==1:\r\n c+=1\r\n if l[i]==1 and l[i-1]==0:\r\n c+=2\r\nprint(c)\r\n \r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nc=0\r\nfor i in range(n-1):\r\n if a[i]==1 and a[i+1]==1:\r\n c+=1\r\n elif a[i]==1 and a[i+1]==0:\r\n c+=2\r\nif a[n-1]==1:\r\n c+=1\r\nelif a[n-1]==0 and c>0:\r\n c-=1\r\nprint(c)\r\n", "#!/usr/bin/env python3\n\nn = int(input())\n\nletters = input()\nletters = letters.replace(\" \", \"\") # removes all the whitespaces in the list.\nletters = letters.strip('0') # to remove all the leading and trailing zeroes in the string.\nletters = [int(x) for x in letters]\n\nsteps = 0\nunread = []\n\nfor x in range(len(letters)):\n\tif letters[x] == 1:\n\t\tunread.append(letters[x])\n\telse:\n\t\tif letters[x] == 0 and letters[x-1] == 0:\n\t\t\tcontinue\n\t\tif letters[x] == 0:\n\t\t\tsteps += 1\n\nprint(steps + len(unread))", "n = int(input())\r\ns = input().split()\r\nspans = []\r\nk = 0\r\nif s[0] == '1':\r\n spans.append(1)\r\n k = k + 1\r\nfor i in range(1, n):\r\n if s[i] == '1' and s[i - 1] == '1':\r\n spans[k - 1] = spans[k - 1] + 1\r\n if s[i] == '1' and s[i - 1] == '0':\r\n spans.append(1)\r\n k = k + 1\r\nans = sum(spans)+ len(spans) - 1;\r\nif len(spans) == 0 : ans = 0\r\nprint(ans)", "x=input()\r\nnumbers=input().split(\" \")\r\nfor i in range(0,len(numbers)):\r\n numbers[i]=int(numbers[i])\r\nm=0\r\nfor l in range(len(numbers)): \r\n if numbers[l]==1:\r\n m+=2\r\n numbers[l]=0\r\n if l<(len(numbers)-1):\r\n if numbers[l+1]==1:\r\n m-=1\r\nif m>1:\r\n m=m-1\r\nprint(m)\r\n \r\n", "input()\r\nX = list(map(int, input().split()))\r\nif 1 not in X:\r\n print(0)\r\n exit()\r\ni, Moves = X.index(1), 0\r\nwhile i < len(X):\r\n if X[i] == 1:\r\n Moves += 1\r\n while i + 1 < len(X) and X[i + 1] == 1:\r\n i += 1\r\n Moves += 1\r\n i += 1\r\n Moves += (1 if i - 1 < len(X) and X[i - 1] == 1 else 0)\r\nprint(Moves - 1)\r\n", "start=[]\ncontents=[]\ncount = 1\nwhile True:\n try:\n line = input();\n except EOFError:\n break\n if count == 1:\n start.append(line.split())\n count = 0\n else:\n contents.append(line.split())\n\nindex = int(start[0][0])\nmaillist = contents[0][0::]\nskipflag = 0\ncount = 0\nlast1 = 0\n\nfor i in range(0,index):\n if maillist[i] == '1' and skipflag == 0:\n count += 1\n skipflag = 1\n last1 = 0\n elif maillist[i] == '1' and skipflag == 1:\n count += 1\n last1= 0\n elif maillist[i] == '0' and skipflag == 1:\n skipflag = 0\n count += 1\n last1 = 1\n elif maillist[i] == '0' and skipflag == 0:\n skipflag = 0\nif last1 == 1:\n count -= 1\nprint(count)\n", "n = int(input())\r\narr = list(map(int,input().split()))\r\ntemp = []\r\nfor i in range(n):\r\n if arr[i]==1:\r\n temp.append(i)\r\nif len(temp)==0:\r\n print(0)\r\nelif len(temp)==1:\r\n print(1)\r\nelse:\r\n ans = 1\r\n for i in range(len(temp)-1):\r\n if temp[i+1]-temp[i]==1:\r\n ans+=1\r\n else:\r\n ans+=2\r\n print(ans)", "n = int(input())\r\na = list(map(int, input().split()))\r\nk = 0\r\nflag = False\r\nfor i in range(n):\r\n if a[i] == 1 and flag == False:\r\n k += 1\r\n if i + 1 < n:\r\n if a[i + 1] == 0:\r\n flag = True\r\n if a[i] == 0 and flag == True:\r\n k += 1\r\n flag = False\r\nif a[-1] == 0:\r\n k -= 1\r\nif k < 0:\r\n print(0)\r\nelse:\r\n print(k)\r\n \r\n", "n = int(input())\nsomething = [int(x) for x in input().split()]\nanswer = 0\ntemp = []\nfor i in range(len(something)):\n if something[i] == 1:\n temp.append(i)\nx = len(temp)\nif x == 0:\n print(0)\n exit()\nif x == 2:\n if temp[1] - temp[0] > 1:\n answer += 2\n else:\n answer += 1\nelse:\n for i in range(len(temp)-1):\n if temp[i + 1] - temp[i] > 1:\n answer += 2\n else:\n answer += 1\nprint(answer+1)", "n = int(input())\r\nL = list(map(int, input().split()))\r\nans = 0; map = []\r\n\r\nfor i in range(len(L)) :\r\n if L[i] == 1 :\r\n map.append(i)\r\nfor i in range (len(map) - 1) :\r\n if abs(map[i] - map[i + 1]) > 2 :\r\n ans += 2\r\n else :\r\n ans += abs(map[i] - map[i + 1])\r\nif len(map) > 0 :\r\n ans += 1\r\nprint (ans)", "n=input()\r\na=[*map(int,input().split())]\r\nx=a.count(1)\r\ny=0\r\npre=0\r\nfor i in a:\r\n if i==1 and pre==0:\r\n y+=1\r\n pre=i\r\nprint(max(0,x+y-1))\r\n", "from sys import stderr\r\nN = int(input())\r\ndata = [int(i) for i in input().split()]\r\ndata.append(0)\r\ndata.append(0)\r\ndata.append(0)\r\n\r\nans = 0\r\nins = 0\r\nlast = -1\r\nfor i in range(N):\r\n if data[i] == 1:\r\n last = i\r\n\r\nif last == -1:\r\n print(0)\r\n exit()\r\n\r\nfor i in range(last + 1):\r\n if data[i] == 1 and ins == 0:\r\n ans += 1\r\n ins = 1\r\n continue\r\n if data[i] == 1 and ins == 1:\r\n ans += 1\r\n continue\r\n if data[i] == 0 and ins == 1:\r\n ans += 1\r\n if data[i + 1] == 0:\r\n ins = 0\r\n continue\r\n\r\nprint(ans)\r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nv=1\r\nk=0\r\nr=0\r\nfor i in range(n) :\r\n if l[i]==1 :\r\n if v==1 :\r\n k=k+1\r\n v=0\r\n r=0\r\n else :\r\n if v==0 and r==0 :\r\n k=k+1\r\n r=0\r\n v=0\r\n else :\r\n k=k+2\r\n r=0\r\n v=0\r\n else :\r\n r=r+1\r\nprint(k)\r\n \r\n \r\n \r\n", "n = int(input().strip())\r\na = list(map(int, input().split()))\r\n\r\npitem = 0\r\ncount = 0\r\nfor item in a:\r\n\tif pitem != 0 or item != 0:\r\n\t\tcount += 1\r\n\tpitem = item\r\n\r\nif a[-1] == 0:\r\n\tcount -= 1\r\n\r\nprint(max(0,count))\r\n", "a = int(input())\r\nlistx = list(map(int, input().split(' ')))\r\n\r\nlistx2 = [int(x) for x in range(a) if listx[x] == 1]\r\nlistx3 = [listx2[x]-listx2[x-1]-1 for x in range(1, len(listx2))]\r\n\r\nif listx2==[]:\r\n print(0)\r\nelse:\r\n total=1\r\n for i in listx3:\r\n if i == 0:\r\n total += 1\r\n else:\r\n total += 2\r\n\r\n print(total)\r\n", "a,b=input(),list(map(int,input().split()))\r\nif 1 in b:\r\n c,d=1,b.index(1);b[d]=0\r\n while 1 in b:\r\n if b[d+1]==1:c+=1;d+=1;b[d]=0\r\n else:c+=2;d=b.index(1);b[d]=0\r\n print(c)\r\nelse:print(0)", "n = int(input())\r\np = list(map(int, input().split()))\r\ni = 0\r\nc = 0\r\nwhile i < n and p[i] == 0:\r\n i += 1\r\nif i != n:\r\n c += 1\r\nwhile i < n:\r\n while i < n and p[i] == 1:\r\n i += 1\r\n c += 1\r\n #if i != n-1 and p[i+1:i+2] == 0:\r\n # c += 1\r\n while i < n and p[i] == 0:\r\n i += 1\r\n if i != n:\r\n c += 1\r\nif sum(p) > 0:#p[-1] == 0 and sum(p) > 0:\r\n c -= 1\r\nprint(c) ", "n = int(input())\r\na = input().split()\r\nres = sum(1 + (i + 1 == n or a[i + 1] == '0') for i in range(n) if a[i] == '1')\r\nprint(res - 1 if res > 0 else res)", "from collections import deque, defaultdict, Counter\r\nfrom itertools import product, groupby, permutations, combinations\r\nfrom math import gcd, floor, inf\r\nfrom bisect import bisect_right, bisect_left\r\n\r\n\r\nn = input()\r\narr = list(map(int, input().split()))\r\n\r\nans = 0\r\ncnt_grp = 0\r\n\r\nfor char, grp in groupby(arr):\r\n if char == 1:\r\n cnt_grp += 1\r\n ans += len(list(grp))\r\n\r\nprint(ans + max(cnt_grp-1, 0))", "input()\r\nprint(max(0,sum(len(i)+1 for i in input().replace(' ','').replace('0',' ').split())-1))", "from sys import stdin\r\ninput=stdin.readline\r\nn=int(input()) ; messeges=input().split() ; c=0 ; befor=\"\"\r\nfor i in range(n):\r\n if i==0 and messeges[i]==\"1\":\r\n c+=1 ; befor=\"1\"\r\n else:\r\n if messeges[i]==\"1\":\r\n if messeges[i-1]==\"1\":c+=1\r\n elif befor==\"\":\r\n c+=1 ; befor=\"1\"\r\n else: c+=2\r\nprint(c) ", "\nn = int(input())\nList = list(map(int,input().split()))\ni = ans = h = 0\nOne = List.count(1)\nwhile i<n:\n if List[i] == 1:\n ans+=1\n i+=1\n h+=1\n while i<n and List[i] == 1:\n i+=1\n ans+=1\n h+=1\n if One == h:\n break\n else:\n ans+=1\n\n i+=1\n\n\nprint(ans)\n", "\nn=int(input())\ncur=ans=0\nfor i in input().split():\n if i=='1':cur+=1\n else:ans+=(cur+1)*(cur!=0);cur=0\nans+=(cur+1)*(cur!=0)\nprint(max(0,ans-1))\n ", "qntd = int(input())\nletters =[int(letter) for letter in input().split()]\n\nif letters.count(1) == 0:\n print(0)\nelse:\n start = 0\n operations = 1\n while True:\n try:\n index = letters.index(1, start)\n start = index + 1\n prox_index = letters.index(1, start)\n\n if prox_index - index <= 1:\n operations += 1\n else:\n operations += 2\n\n start = prox_index\n except ValueError:\n break\n \n print(operations)\n \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\nclosed=True\r\nris=0\r\nfor x in range(len(arr)):\r\n if arr[x]==0 and not closed and 1 in arr[x:]:\r\n closed=True\r\n ris+=1\r\n elif arr[x]==1 and closed:\r\n ris+=1\r\n closed=False\r\n elif arr[x]==1 and not closed:\r\n ris+=1\r\nprint(ris,)\r\n", "n = int(input())\narr = list(map(int, input().split()))\narr.append(0)\n\nop = 0\ni = 0\n\nlastzero = False\nwhile True:\n if arr[i] == 1:\n op += 1\n if arr[i + 1] == 0:\n op += 1\n if i + 1 != len(arr):\n i += 1\n else:\n break\n\nif op < 1:\n print(0)\nelse:\n print(op - 1)\n\n\t\t\t\t\t \t\t\t\t \t \t\t \t\t \t", "n = int(input())\r\nl = input().replace(\" \",\"\").strip(\"0\").split(\"0\")\r\nc = 0\r\nfor i in range(len(l)):\r\n\tif l[i] != '' :\r\n\t\tc+=(l[i].count('1')+1)\r\nprint(max(0,c-1))", "def main():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n\r\n if 1 not in arr:\r\n print(0)\r\n exit(0)\r\n\r\n idx = arr.index(1)\r\n result = 0\r\n reading = True\r\n\r\n while idx < n:\r\n if arr[idx] == 1:\r\n result += 1\r\n if not reading:\r\n result += 1\r\n reading = True\r\n else:\r\n reading = False\r\n\r\n idx += 1\r\n\r\n print(result)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "# coding: utf-8 \n\namountEmails = int(input())\nlistEmails = input().split()\noperator = 0\namtOnes = 0\n\n# transformando a lista de string para inteiros, contando a quantidade de 'uns' existente, tbm.\nfor i in range(len(listEmails)):\n if(listEmails[i] == '1'):\n amtOnes += 1\n listEmails[i] = int(listEmails[i])\n\nindex = 0\nwhile index < amountEmails :\n if(listEmails[index] == 1):\n operator += 1\n amtOnes -= 1\n if((index + 1) < amountEmails and listEmails[index+1] == 0 and amtOnes > 0):\n operator += 1\n index += 1\n index += 1\n\nprint(operator) \n\n\t \t\t \t\t\t\t \t\t \t \t\t\t \t \t\t", "def reading_mail (n,mail) :\r\n total_op = 0\r\n index = 0\r\n prev = 0\r\n while index < n :\r\n if 1 in mail[index:]:\r\n if mail[index] == 0 and prev == 1 :\r\n total_op += 1\r\n prev = 0\r\n elif mail[index] == 1 and prev == 1 :\r\n total_op += 1\r\n \r\n elif mail[index] == 1 and prev == 0 :\r\n total_op += 1\r\n prev = 1\r\n index += 1\r\n \r\n else :\r\n break\r\n \r\n \r\n \r\n return total_op\r\n \r\n \r\nn = int(input())\r\nmail = list(map(int,input().split()))\r\nprint (reading_mail(n,mail))\r\n \r\n \r\n \r\n ", "n, cartas = int(input()), map(int, input().split())\n\ncont = 0\nmove = 0\n\nfor i in range(n):\n carta = next(cartas)\n if carta == 1:\n cont+=1\n if move:\n cont +=1\n move = 0\n else:\n if cont:\n move = 1\n\nprint(cont)\n\n\n\n\t \t\t\t\t\t\t \t \t\t \t\t \t", "ncartas = int(input())#número total de cartas\ngeral = ''.join(input().split(' ')) #descrição atual dos emails\nanterior = -1\nnecessarias = 0\nfor carta in range(0,ncartas): #lançou o loop\n if(geral[carta] == '1'): #se o elemento da string é igual a 1\n if (carta-anterior<=2 and anterior!=-1):\n necessarias+=carta-anterior\n elif (anterior==-1):\n necessarias += 1\n else:\n necessarias += 2\n anterior = carta\nprint(necessarias)\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=arr.count(1)\r\nif c==0:\r\n print(0)\r\nelse:\r\n a=0\r\n for i in range(n-1):\r\n if arr[i]==1 and arr[i+1]==1:\r\n a+=1\r\n print((c*2)-1-a)", "#!/usr/bin/env python3\n\ndef main():\n n = input()\n letters = list(input().split(' '))\n idx = list()\n for i in range(len(letters)):\n if letters[i] == '1':\n idx.append(i)\n m = len(idx)\n if m == 0:\n print(0)\n return\n res = 1\n for i in range(1, m):\n res += min(2, idx[i] - idx[i - 1])\n print(res)\n\nif __name__ == '__main__':\n main()\n", "input()\r\nprint(len('0'.join(input().replace(' ', '').replace('0', ' ').split())))", "size = int(input())\nemails = input().split(' ')\n\n\"\"\"\n1. Procura o primeiro email não lido\n2. Abre\n3. Chega se o proximo é não lido\n 3.1 Se ja foi lido, volta pra lista\n 3.2 Se não foi, abre ele (passo 2)\n4. Repete até chegar no final\n\"\"\"\n\nmoves = 0\nif size > 0:\n last_value = emails[0]\n if last_value == \"1\":\n moves += 1\n\nfor i in range(1, size):\n if emails[i] == \"1\":\n if last_value == \"0\" and moves != 0:\n moves += 1\n moves += 1\n\n last_value = emails[i]\n\nprint(moves)\n\n\n \t \t \t\t \t \t\t\t \t \t\t\t \t\t \t \t", "if __name__ == '__main__':\r\n n = int(input())\r\n line = str(input()).replace(' ', '').split('0')\r\n num = 0\r\n for it in line:\r\n if len(it) > 0:\r\n num += (len(it) + 1)\r\n if num > 0:\r\n print(num - 1)\r\n else:\r\n print(num)\r\n", "from itertools import *\r\ninput()\r\nprint(max(0, sum(len(list(g)) + 1 for r, g in groupby(map(int, input().split())) if r == 1) - 1))", "import sys\r\nimport math\r\n\r\nn = int(sys.stdin.readline())\r\ninstr = (sys.stdin.readline()).split()\r\n\r\ncc = 0\r\nresult = 0\r\nki = 0\r\nfor i in range(n):\r\n if(instr[i] == \"1\"):\r\n ki = i\r\n break \r\n\r\nfor i in range(ki, n):\r\n if(instr[i] == \"1\"):\r\n if(cc >= 1):\r\n result += 1\r\n cc = 0\r\n result += 1\r\n else:\r\n cc += 1\r\n \r\nprint (result) ", "n = int(input())\r\nlista = list(map(int, input().split()))\r\nunsJuntos = 0\r\nuns = 0\r\nfor i in range(len(lista)):\r\n if(lista[i] == 1): \r\n uns += 1\r\n if(i+1 < len(lista) and lista[i] == 1 and lista[i+1] == 1): \r\n unsJuntos += 1\r\nresposta = ((uns * 2) - 1) - unsJuntos\r\nif(uns == 0): \r\n resposta = 0\r\nprint(resposta)", "def nextUnread(a,i,n):\n\tfor p in range(i+1,n):\n\t\tif(a[p] == 1):\n\t\t\treturn p\n\treturn -1\n\nn = int(input())\n\na = list(map(int,input().split()))\n\n\nif 1 not in a:\n\tprint(0)\nelse:\n\tc = 1\n\ti = nextUnread(a,-1,n)\n\twhile(i < n-1):\n\t\tx = nextUnread(a,i,n)\n\t\tif(x == -1):\n\t\t\tbreak\n\t\tif(x - i == 1):\n\t\t\tc += 1\n\t\telse:\n\t\t\tc += 2\n\t\ti = x\n\tprint(c)", "n = int(input())\r\narr = list(map(int,input().split()))\r\nif 1 in arr:\r\n start = index = arr.index(1)\r\n count = 1\r\n for i in range(start+1,n):\r\n if arr[i]==1:\r\n if i-index==1:\r\n count += 1\r\n elif i-index>=2:\r\n count += 2\r\n index = i\r\n print(count)\r\nelse:\r\n print(0)\r\n", "input()\r\nprint(max(0, sum(len(s) + 1 for s in ''.join(input().split()).split('0') if s) - 1))\r\n", "n = int(input())\r\n\r\nx = list(map(int,input().split()))\r\n\r\ncurrent_state = 0\r\nanswer = 0\r\n\r\nfor i in range(n):\r\n\tif x[i] == 0 and current_state == 0:\r\n\t\tcontinue\r\n\r\n\tif x[i] == 0:\r\n\t\tcurrent_state = 0\r\n\t\tanswer += 1\r\n\r\n\tif x[i] != 0:\r\n\t\tanswer += 1\r\n\t\tcurrent_state = 1\r\n\r\nif x[n-1] == 0 and answer != 0:\r\n\tanswer -=1\r\n\r\nprint(answer)", "n=int(input())\ntotal = 0\nfor _ in ''.join(input().split()).split('0'):\n if _ != '':\n total += len(_)\n total += 1\nprint(total-1 if total != 0 else 0)", "number = int(input())\nlist = str(input()).split()\n\ncount = 0\nop = 0\num = 0\nwhile count < number:\n if(list[count] == \"1\"):\n um += 1\n\n count += 1\n\ncountum = 0\n\ncount = 0\nwhile countum < um:\n \n if(count == number - 1 and list[count] == \"1\"):\n op+=1\n countum += 1\n break\n else:\n if(list[count] == \"1\"):\n op+= 1\n countum += 1\n if (list[count] == \"1\" and list[count + 1] == \"0\" and countum != um):\n op += 1 \n \n\n count+=1\n\nprint(op)\n\n \t \t \t\t\t\t\t \t\t \t \t\t\t \t \t\t\t \t\t", "input()\r\n\r\ns = ''.join(input().split())\r\n\r\nres1 = s.count('1')\r\nres2 = len(s.replace('0' , ' ').split()) - 1\r\n\r\nres3 = res1 + res2\r\n\r\nprint(max(0,res3))\r\n\r\n\r\n", "n = int(input())\r\nstring = input()\r\nnumbers = list(map(int, string.split()))\r\nb = 0\r\nif 1 in numbers:\r\n a = n - 1 - numbers[::-1].index(1)\r\n streak = 0\r\n for x in range(a + 1):\r\n if numbers[x] == 1:\r\n streak += 1\r\n b += 1\r\n elif streak != 0:\r\n streak = 0\r\n b += 1\r\nprint(b)\r\n\r\n", "a = int(input())\nemailsEntrada = input()\n\nemails = emailsEntrada.split()\n\ncontador = 0\nzeros = 0\nflag = False\nfor i in range(len(emails)):\n if int(emails[i]) == 1 and flag == False:\n flag = True\n contador += 1\n elif flag == True:\n if int(emails[i]) == 1 and zeros == 0:\n contador += 1\n zeros = 0\n elif int(emails[i]) == 1 and zeros > 0:\n contador += 2\n zeros = 0\n elif int(emails[i]) == 0:\n zeros += 1\n continue\n\nprint(contador)\n\t\t \t\t\t \t \t \t \t\t\t \t\t\t \t\t\t\t", "n = int(input())\n\nmailbox = [int (x) for x in input().split(\" \")]\ncount, ones = 0,0\n\nfor m in mailbox:\n\tif m == 1:\n\t\tones += 1\n\ni = 0\nwhile ones > 0 and i < len(mailbox):\n\t\n\tif mailbox[i] == 1 :\n\t\tones -= 1 \n\t\tif ones > 0:\n\t\t\tcount += 2\n\t\t\tif mailbox[i + 1] == 1 :\n\t\t\t\tcount -= 1 \n\t\telse:\n\t\t\tcount += 1\n\ti += 1\n\nprint(count)\t\n\n \t\t \t \t \t \t \t \t \t \t", "\n\nif __name__ == '__main__':\n n = int(input()) - 1\n m = [i for i in ''.join(input().split()).split('0') if i != '']\n\n ct = 0\n if len(m) != 0:\n ct -= 1\n for i in m:\n ct += len(i) + 1\n print(ct)", "a=int(input())\r\nb=list(map(int,input().split()))\r\nif 1 in b:\r\n n=b.index(1)\r\nh=set(b)\r\ncount=0\r\nwhile 1 in h:\r\n b[n]=0\r\n count+=1\r\n h=set(b)\r\n if 1 not in h:\r\n break\r\n m=b.index(1)\r\n if m-n>1:\r\n count+=1\r\n n=m\r\nprint(count)", "n = int(input())\nletters = list(map(int, input().split(' ')))\nfor i in reversed(range(n)):\n if all(x == 0 for x in letters[-(i + 1):]):\n letters = letters[:-(i + 1)]\ncount = 0\nprev = -1\nfor x in letters:\n if x == 1 or prev == 1:\n count += 1\n prev = x\nprint(count)\n", "numero = int(input())\r\ncartas = input()\r\ncount = 0\r\n\r\nfor i in range(numero*2 - 1):\r\n if (cartas[i] != \" \"):\r\n if(int(cartas[i]) == 1):\r\n count += 1\r\n elif(int(cartas[i]) == 0 and i < numero*2 - 2 and count != 0 and int(cartas[i+2]) == 1):\r\n count += 1\r\n\r\nif (count == 0):\r\n print(count)\r\nelse:\r\n print(count)", "import sys\r\nsys.setrecursionlimit(2100)\r\n\r\n\r\nn = int(input())\r\nseq = list(map(int, input().split()))\r\n\r\npd = []\r\nultimo = -1\r\nprimeiro = -1\r\n\r\nfor i in range(n):\r\n\tpd.append([-1,-1])\r\n\tif(seq[i] == 1):\r\n\t\tultimo = i\r\n\r\n\r\n#e = 0 ta fora\r\n#e = 1 ta dentro\r\n\r\ndef solve(i, e):\r\n\tif(i == n):\r\n\t\treturn 0\r\n\tif(i == ultimo and e == 1):\r\n\t\treturn 0\r\n\t\t\r\n\tif(pd[i][e] != -1):\r\n\t\treturn pd[i][e]\r\n\t\r\n\tif(e == 0):\r\n\t\tif(seq[i] == 0):\r\n\t\t\tpd[i][e] = solve(i+1,0)\r\n\t\t\treturn pd[i][e]\r\n\t\tif(seq[i] == 1):\r\n\t\t\tpd[i][e] = 1 + solve(i,1)\r\n\t\t\treturn pd[i][e]\r\n\tif(e == 1):\r\n\t\tsai = 1 + solve(i+1,0)\r\n\t\tprox = 1+ solve(i+1,1)\r\n\t\tpd[i][e] = \tmin(sai,prox)\r\n\t\treturn pd[i][e]\r\n\t\t\r\n\r\n\r\nprint(solve(0,0))\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", "n = int(input())\r\nlet = list(map(int,input().split()))\r\ninbox = 1\r\nans = 0\r\nfor l in let:\r\n if inbox == 1:\r\n if l == 1:\r\n ans += 1\r\n inbox = 0\r\n else:\r\n if l == 1:\r\n ans += 1\r\n else:\r\n ans += 1\r\n inbox = 1\r\nif ans > 0 and let[n-1] == 0:\r\n ans -= 1\r\nprint(ans)\r\n ", "input()\r\nlis = list(map(int,input().split()))\r\nfor i in range(1,len(lis)):\r\n if lis[len(lis) - 1] == 0:\r\n lis.pop()\r\n\r\ncount = 0\r\ni = 0\r\nwhile i <len(lis):\r\n if lis[i] == 1:\r\n count += 1\r\n if i + 1 == len(lis):\r\n break\r\n else:\r\n if lis[i+1] == 0:\r\n count += 1\r\n i += 1\r\n i += 1 \r\nprint(count)\r\n", "import 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 = int(input())\r\n a = ''.join(input().split()).split('0')\r\n ans = 0\r\n for x in a:\r\n if x:\r\n ans += len(x) + 1\r\n if ans:\r\n ans -= 1\r\n print(ans)\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n solve()\r\n", "n = int(input())\r\na = input()\r\n\r\nbeg = a.find('1')\r\nending = a.rfind('1')\r\nsub = a[beg:ending + 1]\r\nif not sub:\r\n print(0)\r\nelse:\r\n s = [i for i in sub.split('0') if not i.isspace()]\r\n t = len(s)\r\n p = 0\r\n for i in s:\r\n for j in i:\r\n if j == '1':\r\n p += 1\r\n\r\n print(p + t - 1)", "input()\r\na=input().split()\r\nb=[]\r\nc=0\r\nfor i in a:\r\n if i=='1':c+=1\r\n else:\r\n if c:b+=[c]\r\n c=0\r\nif c:b+=[c]\r\nprint(max(sum(b)+len(b)-1,0))\r\n", "n = int(input())\r\nbits = \"\".join(input().split(\" \"))\r\n\r\npre = -1\r\ncount = 0\r\n\r\nfor i in range(0, n):\r\n if bits[i] == \"1\":\r\n if (i - pre <= 2 and pre != -1):\r\n\r\n count += i - pre\r\n elif pre == -1:\r\n count += 1\r\n else:\r\n count += 2\r\n pre = i\r\n \r\n\r\nprint(count)\r\n", "n = int(input())\n\nemails = list(map(int, input().split()))\n\noperations = 0\n\nlist_view = True\n\nfor i, email in enumerate(emails):\n if list_view:\n if email:\n operations += 1\n list_view = False\n else:\n if email:\n if emails[i-1]:\n operations += 1\n else:\n operations += 2\n\nprint(operations)\n", "n=int(input())\r\ns=''.join(input().split())\r\ni=s.find('1')\r\nc=0\r\n# if i !=-1:\r\n# c+=1\r\nwhile i < len(s): \r\n if s[i] == '1':\r\n c += 1\r\n else:\r\n tmp = s.find('1', i)\r\n if tmp < 0:\r\n break\r\n c += 1\r\n i = tmp - 1\r\n i += 1\r\n\r\n\r\n# if i !=-1:\r\n# c+=1\r\n# while s.find('1',i+1)!=-1:\r\n# if s.find('1',i+1)-i>1:\r\n# c+=2\r\n# else:\r\n# c+=1\r\n# i=s.find('1',i+1)\r\nprint(c) ", "# Contest: 20 - 2100 <= Codeforces Rating <= 2199 (https://a2oj.com/ladder?ID=20)\n# Problem: (9) Inbox (100500) (Difficulty: 2) (http://codeforces.com/problemset/problem/465/B)\n\ndef rint():\n return int(input())\n\n\ndef rints():\n return list(map(int, input().split()))\n\n\nfrom itertools import groupby\nn = rint()\ns = rints()\nops = 0\nfor k, g in groupby(s):\n if k == 1:\n c = sum(1 for _ in g)\n ops += c + 1\nprint(max(0, ops - 1))\n", "length = int(input())\nmailbox = [int(n) for n in input().split(' ')]\n\ndef min_mov(size, mailbox):\n if len(mailbox) != size: return 0\n\n \n indexes = []\n\n for i in range(size):\n if mailbox[i] == 1:\n indexes.append(i)\n\n if len(indexes) == 0: return 0\n\n moves = 0\n\n for k in range(len(indexes)-1):\n\n if indexes[k+1] - indexes[k] >= 2:\n moves += 2\n else:\n moves += 1\n\n moves += 1\n return moves\n\nprint(min_mov(length, mailbox))\n \t \t \t \t\t\t \t\t \t \t \t\t\t\t\t", "import math\r\nimport os\r\nimport random\r\nimport re\r\nimport sys\r\nimport functools\r\nfrom operator import itemgetter, attrgetter\r\nfrom collections import Counter\r\n\r\nif __name__ == '__main__':\r\n Y = lambda: list(map(int, input().split()))\r\n N = lambda: int(input())\r\n\r\n n = N()\r\n a = Y()\r\n i, j = 0, n - 1\r\n\r\n while i < j and not (a[i] and a[j]):\r\n if not a[i]:\r\n i += 1\r\n if not a[j]:\r\n j -= 1\r\n f, cnt = 0, a[i:j+1].count(1)\r\n for i in a[i:j+1]:\r\n if not i:\r\n f = 1\r\n elif f:\r\n cnt += 1\r\n f = 0\r\n print(cnt)", "n = int(input())\r\na = map(int, input().split())\r\n\r\np = 0\r\nres = -1\r\nfor i in a:\r\n if i == p == 1:\r\n res += 1\r\n if i == 1 and p == 0:\r\n res += 2\r\n p = i\r\n\r\nprint(max(0, res))\r\n", "# Description of the problem can be found at http://codeforces.com/problemset/problem/465/B\r\n\r\nn = int(input())\r\nl_r = input().split()\r\n\r\nt = -1\r\np_r = False\r\n\r\nfor r in l_r:\r\n if r == \"1\":\r\n t += 1\r\n if not p_r:\r\n t += 1\r\n p_r = True\r\n else:\r\n p_r = False\r\n\r\nprint(t if t != -1 else 0)", "#In the name of Allah\r\n\r\nfrom sys import stdin, stdout\r\ninput = stdin.readline\r\n\r\nn = int(input())\r\na = input().split()\r\n\r\np = True\r\n\r\nans = 0\r\n\r\nfor i in range(n):\r\n if a[i] == \"1\":\r\n if p:\r\n ans += 1\r\n else:\r\n ans += 2\r\n p = True\r\n elif ans != 0:\r\n p = False\r\n \r\nstdout.write(str(ans))\r\n", "n = int(input())\r\na = ['0'] + input().split() + ['0']\r\nres = 0\r\nfor i in range(1, n + 1):\r\n if a[i] == '0':\r\n continue\r\n res += 1\r\n if a[i + 1] == '0':\r\n res += 1\r\nprint(res - 1 if res > 0 else res)", "n=int(input())\r\nf=[int(x) for x in input().split()]\r\nc=0\r\ngone_out=False\r\nk=0\r\nfor i in f:\r\n if (i==1) and k==0:\r\n #go in\r\n c+=1\r\n gone_out=False\r\n elif i==1 and k==1:\r\n c+=1\r\n elif i==0 and k==1:\r\n gone_out=True\r\n c+=1\r\n k=i\r\nif gone_out:\r\n c-=1\r\nprint(c)\r\n \r\n", "input1 = input()\ninput2 = input()\n\nemails = input2.split()\n\ncont = 0\nflag_um = False\n\nfor email in emails:\n if email == \"1\":\n cont += 1\n flag_um = True\n elif flag_um == True:\n cont += 1\n flag_um = False\n\nif len(emails) > 0:\n if emails[len(emails)-1] == \"0\" and cont-1 >= 0:\n cont -= 1\n\nprint(cont)\n\t\t \t \t\t \t\t \t\t\t \t \t \t\t \t \t", "n = int(input())\nletters = input().split(\" \")\n\noperations = 0\ncurr = -1\n\nfor i in range(n):\n\tif curr == -1 and letters[i] == \"1\":\n\t\tcurr = i\n\t\toperations += 1\n\telif curr >= 0 and letters[i] == \"1\":\n\t\tif i - curr > 2:\n\t\t\toperations += 2\n\t\t\tcurr = i\n\t\telse:\n\t\t\toperations += i - curr\n\t\t\tcurr = i\n\nprint(operations)", "\r\n\r\nimport math\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef inp():\r\n return int(input())\r\n\r\n\r\ndef invr():\r\n return list(map(int, input().split()))\r\n\r\n\r\nn = inp()\r\nl = invr()\r\nif not 1 in l:\r\n print(0)\r\n sys.exit(0)\r\nif not 0 in l:\r\n print(n)\r\n sys.exit(0)\r\ni = 0\r\ns = 0\r\nll = [0]\r\nad = 0\r\nwhile s < len(l):\r\n e = l[s]\r\n if e:\r\n ad = 1\r\n ll[len(ll)-1] += 1\r\n elif ad:\r\n ll.append(0)\r\n ad = 0\r\n s += 1\r\nif not ll[len(ll)-1]:\r\n ll.pop()\r\nprint(sum(ll) + len(ll) - 1)\r\n", "n = int(input())\r\nx = list(map(int,input().split()))\r\notv = 0\r\nfor i in range(n):\r\n\tif x[i] == 1:\r\n\t\totv += 1\r\n\t\tif i < n-1 and x[i+1] != 1:\r\n\t\t\totv += 1\r\nif x[i] != 1:\r\n\tprint(max(otv-1,0))\r\nelse:\r\n\tprint(otv)", "import sys\nn = int(input())\nletters = list(map(int, sys.stdin.readline().split()))\ndef getNbOps(l):\n if len(l) == 0:\n return 0\n elif l[0] == 0:\n try:\n idx = l.index(1)\n return getNbOps(l[idx:])\n except:\n return 0\n else:\n try:\n idx = l.index(0)\n return idx+1+getNbOps(l[idx:])\n except:\n return len(l)+1\nprint(max(0,getNbOps(letters)-1))\n", "import math\r\n\r\ndef main_function():\r\n n = int(input())\r\n letters = [int(i) for i in input().split(\" \")]\r\n letters.append(0)\r\n operation_counter = 0\r\n did_andrey_open_first_letter = False\r\n did_vagon_started = False\r\n for i in range(len(letters)):\r\n if did_andrey_open_first_letter:\r\n if letters[i] == 1:\r\n if did_vagon_started:\r\n operation_counter += 1\r\n else:\r\n operation_counter += 1\r\n did_vagon_started = True\r\n else:\r\n if did_vagon_started:\r\n did_vagon_started = False\r\n operation_counter += 1\r\n\r\n else:\r\n if letters[i] == 1:\r\n did_andrey_open_first_letter = True\r\n did_vagon_started = True\r\n operation_counter += 1\r\n\r\n print(max(operation_counter - 1, 0))\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()", "n = int(input())\r\ncount = 1\r\n\r\nl = list(map(int,input().split()))\r\n\r\na = []\r\n\r\nfor i in range(n):\r\n if l[i] == 1 :\r\n a.append(i)\r\n#print(a)\r\n\r\nx = len(a)\r\n\r\nif len(a) == 0 :\r\n print(0)\r\nelse:\r\n for i in range(x - 1):\r\n dif = a[i+1] - a[i]\r\n if dif > 2 :\r\n count +=2\r\n else:\r\n count+=dif\r\n\r\n print(count)", "n = int(input().strip())\r\nm = list(map(lambda x: int(x), input().strip().split(maxsplit=n)))\r\n\r\nindex = []\r\n\r\nfor i in range(len(m)):\r\n if m[i] == 1:\r\n index.append(i)\r\n\r\n# print(index)\r\n\r\nif len(index) == 0:\r\n print(0)\r\nelse:\r\n c = 1\r\n for i in range(1, len(index)):\r\n if index[i]-index[i-1] == 1:\r\n c += 1\r\n elif index[i]-index[i-1] == 2:\r\n c += 2\r\n else:\r\n c += 2\r\n print(c)\r\n", "n = int(input())\nz = list(map(int,input().split()))\nlast = -1\nse = [[z[0], 1]]\nfor i in z[1:]:\n if i != se[-1][0]:\n se.append([i, 0])\n se[-1][1] += 1\n\ntot = 0\nflag = False\nfor i in se:\n if i[0] == 1:\n flag = True\n tot += i[1] + 1\nprint(tot-flag)\n", "n = int(input())\r\nlista = list(map(int, input().split()))\r\nans = 0\r\nfor i in range(len(lista)):\r\n if(lista[i] == 1): \r\n ans += 1\r\n if(i+1 < len(lista) and lista[i] == 1 and lista[i+1] != 1): \r\n ans += 1\r\nif lista[n-1] != 1 and ans != 0:\r\n ans -= 1 \r\nprint(ans)", "number_of_letters = int(input())\n\noperations = 0\n\nletters = [ int (x) for x in input().split() ]\n\nfor i in range(len(letters)):\n\n\tif number_of_letters == len(letters):\n\n\t\tif letters[i] == 1:\n\t\t\toperations += 1\n\n\t\t\tif letters[i]>0 and operations>1 and letters[i-1] == 0:\n\t\t\t\toperations += 1\n\t\t\nprint (operations)\n\n \t\t \t \t\t\t \t \t \t \t\t \t\t\t\t", "n = int(input())\r\nis_unread = list(map(int, input().split()))\r\noperations = 0\r\ni = 0\r\nwhile i < n and not is_unread[i]:\r\n i += 1\r\nif i < n:\r\n operations += 1\r\nwhile i < n:\r\n delta = 1\r\n while i + delta < n and not is_unread[i + delta]:\r\n delta += 1\r\n if i + delta < n:\r\n if delta == 1:\r\n operations += 1\r\n else:\r\n operations += 2\r\n i += delta\r\nprint(operations)", "n, a, c = int(input()), list(map(int, input().split())), 0\r\nfor x in range(1, n): \r\n if a[x] == 1 and a[x - 1] == 0: c += 1\r\nif a[0] == 1: c += 1\r\nprint(a.count(1) + max(c, 1) - 1)", "n=int(input())\r\na=[int(i) for i in input().split()]\r\nt=0\r\nh=n-1\r\nwhile a[h]==0:\r\n h-=1\r\n if h<0:\r\n break\r\nif h==-1:\r\n print(0)\r\nelse:\r\n for i in range(h+1):\r\n if a[i]==1:\r\n t+=1\r\n if i!=h and a[i+1]==0:\r\n t+=1\r\n print(t)\r\n", "n = int(input())\r\nl = list(map(int, input().split()))\r\nc = 0\r\n\r\nfor i in range(n):\r\n if(l[i] == 1):\r\n c += 1\r\n if(c > 1 and l[i-1] == 0):\r\n c += 1\r\n\r\nprint(c)", "n = int(input())\r\na = list(map(int, input().split()))\r\ncnt = 0\r\nlast = -1\r\nfor i in range(len(a)):\r\n if a[i] == 1:\r\n if last == -1:\r\n cnt += 1\r\n last = i\r\n else:\r\n cnt += min(2, i - last)\r\n last = i\r\nprint(cnt)\r\n ", "n = int(input())\r\ns = \"\".join([i for i in input().split()])\r\n\r\na = s.count(\"1\")\r\nb = s.count(\"10\")\r\n\r\nif s[-1] == \"1\":\r\n\tb+=1\r\na-=b\r\nb = b*2 \r\n\r\nif b>=1:\r\n\tprint(b+a-1)\r\nelse:\r\n\tprint(0)\r\n\r\n \r\n", "total=int(input())\r\nt=list(map(int,input().split()))\r\nno=t.count(1)\r\nd=[]\r\nif no==0:\r\n\tprint('0')\r\n\texit(0)\r\nfor i in range(total):\r\n\tif t[i]==1:\r\n\t\td+=[i]\r\nsum=1\r\nfor i in range(no-1):\r\n\tdif=d[i+1]-d[i]\r\n\tif dif==1:\r\n\t\tsum+=1\r\n\telse:\r\n\t\tsum+=min(dif,2)\r\n\r\nprint(sum) ", "n = int(input())\r\na = list(map(int, input().split()))\r\nstart = 0\r\n\r\nwhile start < n and a[start] == 0:\r\n start += 1\r\nif start == n:\r\n print(0)\r\n exit()\r\n\r\nans = 1\r\nstart += 1\r\nfocus = True\r\n\r\nwhile start < n:\r\n # print(start, ans, focus)\r\n if focus and a[start] == 1:\r\n ans += 1\r\n start += 1\r\n \r\n elif focus and a[start] == 0:\r\n if start + 1 < n and a[start + 1] == 1:\r\n start += 2\r\n ans += 2\r\n else:\r\n focus = False\r\n if start != n-1:\r\n ans += 1\r\n start += 1\r\n \r\n else:\r\n start += 1\r\n if start < n and a[start] == 1:\r\n focus = True\r\n # print(start, ans)\r\n \r\nif a[-1] == 0 and a[-2] == 0:\r\n ans -= 1\r\n \r\nprint(ans)\r\n ", "def main():\n input()\n l = [i for i, _ in enumerate(map(int, input().split())) if _]\n if len(l) > 1:\n print(sum(min(i - j, 2) for i, j in zip(l[1:], l)) + 1)\n else:\n print(len(l))\n\n\nif __name__ == '__main__':\n main()\n", "__author__ = 'hamed1soleimani'\n\nn = int(input())\nitems = input().split()\n\nfor x in range(len(items)):\n items[x] = int(items[x])\n\npointer = 0 # index of mail referring to it\nstate = 0 # out or in\n\nactions_number = 0\n\nwhile True:\n\n if pointer == n:\n break\n\n if not state:\n if items[pointer]:\n state = 1\n actions_number += 1\n else:\n if items[pointer]:\n actions_number += 1\n if not items[pointer - 1]:\n actions_number += 1\n pointer += 1\n\nprint(actions_number)\n\n\n\n\n\n\n", "n = int(input())\r\na = list(map(int, input().split()))\r\na.insert(0, 0)\r\na.append(0)\r\ni = 1\r\nq = a.count(1)\r\nsum = 0\r\nwhile i != len(a) - 1:\r\n if a[i] == 1:\r\n sum += 1\r\n q -= 1\r\n while a[i + 1] == 1:\r\n i += 1\r\n sum += 1\r\n q -= 1\r\n if i != len(a) - 2 and q > 0:\r\n sum += 1\r\n i += 1\r\nprint(sum)\r\n \r\n", "n = int(input())\r\ns = list(map(int, input().split()))\r\n\r\nids = []\r\nfor i in range(n):\r\n if s[i] == 1:\r\n ids.append(i)\r\n#print(ids)\r\n\r\nx = len(ids)\r\nc = 1\r\nif len(ids) == 0:\r\n print(0)\r\nelse:\r\n for i in range(x-1):\r\n \r\n diff = ids[i+1] - ids[i]\r\n #print(diff, 'x')\r\n #print(c)\r\n if diff > 2 :\r\n c += 2\r\n #print('t')\r\n else:\r\n c += diff\r\n #print(c, i)\r\n \r\n print(c)\r\n", "I=lambda: map(int,input().split())\r\nn=int(input())\r\na=list(I())\r\ns=int(a[0]==1)*2\r\nfor i in range(1,n):\r\n if a[i]==1 and a[i-1]==1:\r\n s=s+1\r\n elif a[i]==1:\r\n s=s+2\r\nprint((s-1)*int(s>0))", "n = int(input())\nlidas = input().split()\n\ni_ant = None\nqnt_operacoes = 0\nfor i in range(len(lidas)):\n lida = lidas[i]\n\n if lida == \"1\":\n qnt_operacoes += 1\n\n diferenca = i - i_ant if i_ant != None else 0\n if diferenca >= 2:\n qnt_operacoes += 1\n\n i_ant = i\n\nprint(qnt_operacoes)\n \t\t\t\t \t \t \t\t\t\t \t\t\t \t \t\t \t\t", "import sys\r\n\r\nsize = int(input())\r\narray = list(map(int, input().split()))\r\n\r\nif 1 not in array:\r\n print(\"0\")\r\n sys.exit()\r\n\r\ncounter = 0\r\nwhile 1 in array:\r\n buffer = array.index(1)\r\n i = buffer\r\n while i < size and array[i] == 1:\r\n counter += 1\r\n array[i] = 0\r\n i += 1\r\n if 1 in array:\r\n counter += 1\r\n\r\nprint(counter)\r\n", "import math\r\nimport os\r\nimport random\r\nimport re\r\nimport sys\r\nimport functools\r\nfrom operator import itemgetter, attrgetter\r\nfrom collections import Counter\r\n\r\nif __name__ == '__main__':\r\n Y = lambda: list(map(int, input().split()))\r\n P = lambda: map(int, input().split())\r\n N = lambda: int(input())\r\n\r\n n = N()\r\n a = Y()\r\n f, cnt = 0, 0\r\n \r\n for i in a:\r\n if i:\r\n cnt += 1\r\n f = 1\r\n else:\r\n if f:\r\n cnt += 1\r\n f = 0\r\n print(cnt if (a[n - 1] or not cnt) else cnt - 1)", "n = int(input())\r\nind = 0\r\nindexs = []\r\nfor i in input().split():\r\n if i == '1':\r\n indexs.append(ind)\r\n ind += 1\r\nif len(indexs) < 2:\r\n print(len(indexs))\r\n exit(0)\r\nans = 1\r\nfor i in range(1, len(indexs)):\r\n a = indexs[i - 1]\r\n b = indexs[i]\r\n if b - a <= 2:\r\n ans += b - a\r\n else:\r\n ans += 2\r\nprint(ans)", "input()\r\na=input()+' '\r\nprint(a.count('1')+max(len([*filter(None,a.split('0 '))])-1,0))", "n = int(input())\na = map(int, input().split())\nr = 0\nm = 0\nfor i in range(n):\n p = next(a)\n if p == 1:\n r += 1\n if m:\n r += 1\n m = 0\n else:\n if r:\n m = 1\nprint(r)\n", "n=int(input())\r\nl=[int(i) for i in input().split()]\r\nif sum(l)==n:\r\n print(n)\r\nelif sum(l)==0:\r\n print(0)\r\nelse:\r\n ashok=0 \r\n c=0\r\n zeros=0\r\n karma=0 \r\n ans=l.count(1)\r\n for i in range(n):\r\n if l[i]==0:\r\n #print('hi')\r\n ashok+=100\r\n zeros+=1 \r\n \r\n else:\r\n if karma==0:\r\n karma=1 \r\n zeros=0 \r\n else:\r\n if zeros:\r\n ans+=1 \r\n zeros=0\r\n print(ans)", "n = int(input())\r\na = [int(k) for k in input().split()]\r\nt = -1\r\npri = 0\r\n\r\nfor i in a:\r\n if pri == i == 1:\r\n t += 1\r\n if pri == 0 and i == 1:\r\n t += 2\r\n pri = i\r\n\r\nprint(max(0, t))\r\n", "import re\n\n\ndef main():\n input()\n s = re.sub(r'00+', '0', input().replace(' ', '').strip('0'))\n\n print(len(s))\n\n\nif __name__ == '__main__':\n main()\n\n", "n = input()\nletters = list(map(int, input().split()))\n\nop, interval = 0, 0\nindex = 0\n\nwhile(index < len(letters) and letters[index] != 1):\n index +=1\n\nfor i in range(index, len(letters)):\n if letters[i] == 1:\n if interval > 0:\n op += 2\n else:\n op += 1\n interval = 0\n else:\n interval += 1\n\n\nprint(op)", "n = int(input())\r\na = list(map(int,input().split(\" \")))\r\n\r\nres = 0\r\ni = 0\r\nwhile i < len(a):\r\n if a[i]==1:\r\n res += 1\r\n while i<len(a) and a[i]==1:\r\n i += 1\r\n res += 1\r\n i += 1\r\nprint(max(0,res-1))", "\r\n\r\nn=int(input())\r\n\r\nS=list(map(int,input().split()))\r\ncur = 0\r\nfor i,q in enumerate(S):\r\n if S[i] == 1 and i > 0 and S[i-1] == 1:\r\n cur += 1\r\n elif S[i] == 1:\r\n if cur == 0:\r\n cur += 1\r\n else:\r\n cur += 2\r\n \r\nprint(cur)\r\n ", "n = int(input())\r\na = list(map(int,input().split()))\r\nans = 0\r\nif a.count(1) > 0:\r\n b = a.index(1)\r\n ans += 1\r\n for i in range(b+1,n):\r\n if a[i] == 1 and a[i-1] == 1:\r\n ans += 1\r\n elif a[i] == 1 and a[i-1] == 0:\r\n ans += 2\r\nprint(ans)\r\n", "n = int(input())\nt = [i for i in input().split()]\nk = False\nc = 0\nfor i in t:\n\tif i == \"1\" and not k:\n\t\tk = True\n\t\tc+=1\n\tif k:\n\t\tif i == \"0\":\n\t\t\tk = False\n\t\telse:\n\t\t\tc+=1\nprint(c-1*(c!=0))\n", "n=int(input())\r\na=list(map(int, input().split()))\r\n\r\ns=0\r\n\r\npred=0\r\n\r\nfor i in range(n):\r\n\tif a[i]==1:\r\n\t\ts+=1\r\n\telse:\r\n\t\tif pred==1:\r\n\t\t\ts+=1\r\n\tpred=a[i]\r\nif a[-1]==0:\r\n\ts-=1\r\nif s<0:\r\n\ts=0\r\nprint(s)", "import sys\r\nn = int(input())\r\nmail = input().replace(' ', '')\r\n\r\ntry:\r\n start = mail.index('1')\r\nexcept:\r\n print (0)\r\n sys.exit()\r\n\r\nmail = mail[start:]\r\namn = 0\r\nnew = ''\r\n\r\nfor j in mail:\r\n if j == '1':\r\n if amn == 1:\r\n new += 'n'\r\n amn = 0\r\n elif amn > 1:\r\n new += 'p'\r\n amn = 0\r\n else:\r\n new += 'r'\r\n else:\r\n amn += 1\r\n \r\nprint ((new.count('n') *2) + (new.count('p') *2) + new.count('r'))", "n = int(input())\r\nch = input()\r\nch = ch.split(' ')\r\nch = [int(x) for x in ch]\r\nch.append(0)\r\nn1 = ch.count(1)\r\nsm = 0\r\nif n1 > 0:\r\n sm = 1\r\n ind = ch.index(1)\r\n n1 -= 1\r\n while n1 > 0:\r\n ind_nx = ch[ind+1:].index(1)\r\n if ind_nx > 0:\r\n sm += 2\r\n else:\r\n sm += 1\r\n n1 -= 1\r\n ind += (ind_nx + 1)\r\n\r\n\r\n\r\nprint(sm)", "n=int(input())\r\nl=input().split()\r\ns,i=0,0\r\nwhile(i<n):\r\n if(l[i]=='1'):\r\n while(i<n and l[i]=='1'):\r\n i+=1\r\n s+=1\r\n s+=1\r\n i+=1\r\nif(s==0):\r\n print(0)\r\nelse:\r\n print(s-1)\r\n", "import sys\r\ninput = sys.stdin.readline\r\nimport re\r\n\r\ninput()\r\ns = list(map(len, re.split(r'0+',input()[:-1].replace(' ','').strip('0 '))))\r\nprint(sum(s) + len(s) - 1)\r\n", "num_letters = int(input())\nletters = [ x.strip() for x in input().split('0') if x.strip() != '' ]\ncount = -1\n\nfor i in letters:\n count += i.count('1')\n count += 1\n\nprint(count if count != -1 else 0)", "n = int(input())\r\nstate_list = list(map(int,input().split(\" \")))\r\ncount0 = 0\r\ncount1 = 0\r\nfor i in range(n):\r\n if state_list[i] == 1:\r\n count1 += 1\r\n if count0 >= 2:\r\n count1 += 1\r\n count0 = 1\r\n elif state_list[i] == 0 and count0:\r\n count0 += 1\r\nprint(count1)", "a=int(input())\r\n \r\nb=input().split()\r\n\r\n\r\nl=[]\r\nfor i in range(a):\r\n \r\n if b[i]==\"1\":\r\n l.append(i)\r\n\r\nif len(l)!=0:\r\n s=1\r\n for i in range(1,len(l)):\r\n if l[i]-l[i-1]==1:\r\n s=s+1\r\n else:\r\n s=s+2\r\n\r\n print(s)\r\nelse:\r\n print(0)", "n,l=int(input()),list(map(int,input().split()))\r\nif 1 not in l:print(0)\r\nelse:\r\n\ta,c=l.index(1),1\r\n\tfor x in range(n):\r\n\t\tif l[x]==1:\r\n\t\t\tif x-a>2:c+=2\r\n\t\t\telse:c+=x-a\r\n\t\t\ta=x\r\n\tprint(c)", "n=int(input())\r\nl=list(map(int,input().split()))\r\nif not 1 in l: print(0)\r\nelse:\r\n j=l.index(1)\r\n ans=1\r\n for i in range(j+1,n):\r\n if l[i]==1: ans+=min(i-j,2); j=i\r\n print(ans)", "import math\r\n\r\nn = int(input())\r\narray = list(map(int, input().split(' ')))\r\n\r\nar = []\r\ntotal = 0\r\nfor i in range(n):\r\n if array[i] == 0:\r\n total+=1\r\n else:\r\n if total>0:\r\n ar.append(total)\r\n total = 0\r\n\r\n\r\nif array[0] == 1:\r\n pass\r\nelse:\r\n if len(ar)>0:\r\n ar.remove(ar[0])\r\n\r\n\r\n#print(ar)\r\n\r\ntotalread = 0\r\ntotalmove = len(ar)\r\n\r\nfor i in range(n):\r\n if array[i]==1:\r\n totalread+=1\r\n\r\n\r\nprint(totalread+totalmove)", "input()\r\nt = input()[:: 2]\r\nk, a = 0, '0'\r\nfor b in t[t.find('1'): t.rfind('1') + 1]:\r\n if b == '0':\r\n if a == '1': k += 1\r\n else: k += 1\r\n a = b\r\nprint(k)", "import sys\r\ninput=sys.stdin.readline\r\nn=int(input())\r\nl=input().split()\r\nli=[int(i) for i in l]\r\nl=[]\r\nfor i in range(n):\r\n if(li[i]==1):\r\n l.append(i)\r\nans=0\r\nfor i in range(len(l)-1):\r\n ans+=min(l[i+1]-l[i],2)\r\nif(l!=[]):\r\n ans+=1\r\nprint(ans)\r\n", "# Problem Link: https://codeforces.com/problemset/problem/465/B\r\n# Problem Status:\r\n# -------------------- SEPARATOR --------------------\r\ndef TheAmazingFunction(myList: list):\r\n Number_Of_Operations = 0\r\n Current_Position = -1 # Out Of The List\r\n for i in range(len(myList)):\r\n if myList[i] == 1:\r\n if Current_Position == -1:\r\n Number_Of_Operations += 1\r\n Current_Position = i\r\n\r\n else:\r\n if i - Current_Position > 1:\r\n Number_Of_Operations += 2\r\n Current_Position = i\r\n else:\r\n Number_Of_Operations += 1\r\n Current_Position = i\r\n return Number_Of_Operations\r\n\r\n\r\n# -------------------- SEPARATOR --------------------\r\nN = int(input())\r\nA = list(map(int, input().split()))\r\nprint(TheAmazingFunction(A))\r\n# -------------------- SEPARATOR --------------------\r\n", "def solve():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n if max(a) == 0:\r\n print(0)\r\n return\r\n for i in range(len(a)):\r\n if i > 0 and i < len(a) - 1 and a[i] == 0 and a[i - 1] == 1 and a[i + 1] == 1:\r\n a[i] = 1\r\n ans = -1\r\n for i in range(len(a)):\r\n if a[i] == 1:\r\n if i == 0 or a[i - 1] == 0:\r\n ans += 2\r\n else:\r\n ans += 1\r\n print(ans)\r\n\r\nsolve()\r\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\nans = 1\r\na = []\r\nfor i in range(len(arr)):\r\n if (arr[i] == 1):\r\n a.append(i)\r\n\r\nfor i in range(len(a) - 1):\r\n if abs(a[i + 1] - a[i] + 1) <= 2: ans = ans + abs(a[i + 1] - a[i])\r\n else: ans = ans + 2\r\nprint(ans - int(a == []))\r\n", "n = int(input())\r\nls = [int(u) for u in input().split()]\r\n\r\nones = ls.count(1)\r\nval = 0\r\nfinal = 0\r\ncount = 0\r\nfor u in ls:\r\n if u==1:\r\n count = 1\r\n elif count == 1 and u == 0:\r\n final+=1\r\n count=0\r\n\r\nif count == 1:\r\n final += 1\r\n\r\nprint(max(0, ones+final-1))", "from collections import Counter\r\nn = int(input())\r\narray = list(map(int, input().split()))\r\nhm = []\r\nfor i in range(n):\r\n if array[i] == 1:\r\n hm.append(i+1)\r\nif len(hm) == 0:\r\n print(0)\r\nelse:\r\n c = 1\r\n for i in range(1, len(hm)):\r\n if hm[i] - hm[i -1] <= 2:\r\n c += (hm[i] - hm[i -1])\r\n else:\r\n c += 2\r\n print(c)", "n = int(input())\r\ns = input().split()\r\n\r\nif s.count(\"1\") != 0:\r\n b,d = s.index(\"1\"), 0\r\n cnt = 0\r\n \r\n for i in range(b, n):\r\n d += 1\r\n if s[i] == \"1\":\r\n cnt += min(d, 2)\r\n d = 0\r\n print(cnt)\r\nelse:\r\n print(0)\r\n", "n=int(input())\r\ns=''.join(input().split())\r\ni=s.find('1')\r\nc=0\r\nif i !=-1:\r\n c+=1\r\nwhile s.find('1',i+1)!=-1:\r\n if s.find('1',i+1)-i>1:\r\n c+=2\r\n else:\r\n c+=1\r\n i=s.find('1',i+1)\r\nprint(c) ", "'''\r\n\r\n Online Python Compiler.\r\n Code, Compile, Run and Debug python program online.\r\nWrite your code in this editor and press \"Run\" button to execute it.\r\n\r\n'''\r\nt = int(input())\r\nentrada = input().split()\r\nfor i in range(t):\r\n entrada[i] = int(entrada[i])\r\n\r\ntotal = 0\r\nk = 0\r\nwhile(k < t):\r\n if(entrada[k] == 1):\r\n total += 1\r\n else:\r\n k+= 1\r\n continue\r\n\r\n if(k + 1 == t): break\r\n #0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0\r\n if(entrada[k+1] == 1):\r\n k += 1\r\n elif(k + 2 == t):\r\n k += 2\r\n else:\r\n k += 2\r\n total += 1\r\n\r\nif(entrada[t - 1] == 0 and entrada[t - 2] == 0 and total > 0):\r\n total -= 1\r\nprint(total)", "n=int(input())\r\nlis=input().split()\r\nlis1=[]\r\nfor i in range(n):\r\n lis[i]=int(lis[i])\r\n if lis[i]==1:\r\n lis1.append(i)\r\nif len(lis1)==0:\r\n print(0)\r\nelse:\r\n lis2=[1 for k in range(len(lis1))]\r\n for i in range(1,len(lis1)):\r\n if lis1[i]-lis1[i-1]==1:\r\n lis2[i]=1\r\n else:\r\n lis2[i]=2\r\n print(sum(lis2))\r\n \r\n", "n=int(input())\r\ns=list(map(int,input().split()))\r\nf=[]\r\ni=0\r\nwhile i<n and s[i]!=1:\r\n i+=1\r\nif i==n:\r\n print(0)\r\nelse:\r\n ans=1\r\n while i<n:\r\n if s[i]==1:\r\n l=0\r\n while i<n-1 and s[i+1]==0:\r\n l+=1\r\n i+=1\r\n if i<n-1:\r\n f.append(l)\r\n i+=1\r\n i=0\r\n while i<len(f):\r\n if f[i]==0:\r\n ans+=1\r\n else:\r\n ans+=2\r\n i+=1\r\n print(ans)\r\n \r\n ", "import sys\ninput = sys.stdin.readline\n\nn = int(input())\nl = list(map(int, input().split()))\nans = 0\nlast = 0\nenc = 0\nfor i in range(n):\n\tif l[i] == 0:\n\t\tif last == 1:\n\t\t\tans += 1\n\t\t\tenc = 1\n\t\tlast = 0\n\telse:\n\t\tenc = 0\n\t\tif last == 0:\n\t\t\tans += 1\n\t\telse:\n\t\t\tans += 1\n\t\tlast = 1\nprint(ans - enc)\n\n", "n = int(input())\r\ndata = list(map(int, input().split())) + [0]\r\n\r\ncnt = 0\r\nfor i in range(1, n + 1):\r\n if data[i - 1] == 1 and data[i] == 0:\r\n cnt += 1\r\n\r\nprint(max(0, cnt + data.count(1) - 1))", "n = int(input())\nnecessarias = 0\nanterior = -1 # conta uma ação a mais ir para a próxima\nstring = \"\".join(input().split(\" \")) # O join vai pegar todos os elementos digitados e os colocará na variavel string como um único elemento tipo string\n\n\n#possibilidade 1 = O elemento anterior está a uma distância <= 2 e a mensagem não lida atual não é a primeira, \n#pq ai ele não vai ter que sair do modo de leitura, ir para o geral e depois se dirigir à mensagem distante\n#possibilidade 2 = A primeira mensagem é não lida , então o modo mais rápido de chegar nela é entrando logo no modo de leitura\n#possibilidade 3 = Caso o elemento anterior está a uma distância >= 2 , ou seja, é mais rápido ele sair, ir pra o email e entrar do que andar mais de duas casas no modo leitura \nfor email in range(0,n): #Constatação de cada email \n\t# Caso o email atual seja igual a 1(não lido)\n\tif (string[email] == \"1\"): #O join cria uma lista de string a partir do elemento digitado \n\t\t# Caso o email atual tenha uma distancia menor ou igual a dois do email anterior não lido e ele não é o não lido primeiramente \n\t\tif(email - anterior <=2 and anterior!=-1):\n\t\t\tnecessarias += email - anterior\t\t\t\n\t\t#Se a mensagem não lida é a primeira\n\t\telif anterior == -1: \n\t\t\tnecessarias += 1 \n\t\telse:\n\t\t# Se a mensagem não lida está a uma distância mais do que duas ações e não é a primeira\n\t\t\tnecessarias += 2 # Uma ação para sair para o geral e outra para clicar no email não lido\n\t\tanterior = email #Ajeita o index da lista de string para ele não contar que leu o mesmo email mais de uma vez \n\t\nprint(necessarias)\n\t\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\nn = int(input())\r\na = list(map(str , input().split()))\r\ns = str()\r\nfor i in a:\r\n s += i\r\ns = s.strip('0')\r\n\r\nif len(s) == 0:\r\n print(0)\r\n sys.exit(0)\r\nres = 1\r\nfor i in range(1,len(s)):\r\n if s[i] == '1' and s[i - 1] != '1':\r\n res += 2\r\n elif s[i] == '1':\r\n res += 1\r\nprint(res)", "count = int(input())\r\narray = [int(i) for i in input().split()]\r\ndic = dict()\r\nlol = 0\r\nclick = 0\r\nfor i in range(count):\r\n if (array[i] == 1):\r\n dic[i] = 1\r\nfor i in dic:\r\n lol=i\r\n break\r\nfor i in dic:\r\n if (i - lol >= 2):\r\n click += 2\r\n lol = i\r\n else:\r\n click += 1\r\n lol = i\r\nprint(click)\r\n", "n = int(input())\r\n\r\n\r\n# State\r\n# 0 - closed\r\n# 1 - opened prev\r\n# 2 - opened not prev\r\n\r\nstate = 0\r\noperations = 0\r\n\r\nmessages = input().split()\r\n\r\nfor m in messages:\r\n m = int(m)\r\n\r\n if m and state == 0:\r\n operations += 1\r\n state = 1\r\n elif m and state == 2:\r\n operations += 2\r\n state = 1\r\n elif m and state == 1:\r\n operations += 1\r\n elif not m and state == 1:\r\n state = 2\r\n\r\nprint(operations)\r\n", "n=int(input())\r\na=[int(x) for x in input().split()]\r\nif a.count(1)==0:\r\n print(0)\r\nelif a.count(1)==1:\r\n print(1)\r\nelse:\r\n pos,res=a.index(1),1\r\n for i in range(pos+1,n):\r\n if a[i]==1:\r\n if a[i-1]==1:\r\n res+=1\r\n else:\r\n res+=2\r\n print(res)", "def arr_inp():\r\n return [int(x) for x in input().split()]\r\n\r\n\r\nn, a, ans = int(input()), arr_inp(), 0\r\nfor i in range(n):\r\n if a[i]:\r\n ans += 1\r\n if ans > 1 and (i>0 and a[i-1]==0):\r\n ans += 1\r\n\r\nprint(ans)\r\n", "n = input()\r\nl = input().split()\r\n\r\nact = 1\r\ntotal = 0\r\nfor x in l:\r\n if x == '1':\r\n total += act\r\n act = 1\r\n else:\r\n act = 1 if total == 0 else 2\r\nprint (total)", "n = int(input())\r\na = input().split(' ')\r\nstreak = False\r\nactions = 0\r\na.append('0')\r\nfor i in range(n+1):\r\n if streak == True:\r\n if a[i] == '1':\r\n actions += 1\r\n else:\r\n streak = False\r\n actions += 1\r\n if streak == False:\r\n if a[i] == '1':\r\n streak = True\r\n actions += 1\r\nif actions == 0:\r\n print(0)\r\nelse:\r\n print(actions-1)", "a = int(input())\r\nemailsEntrada = input()\r\n\r\nemails = emailsEntrada.split()\r\n\r\ncontador = 0\r\nzeros = 0\r\nflag = False\r\nfor i in range(len(emails)):\r\n if int(emails[i]) == 1 and flag == False:\r\n flag = True\r\n contador += 1\r\n elif flag == True:\r\n if int(emails[i]) == 1 and zeros == 0:\r\n contador += 1\r\n zeros = 0\r\n elif int(emails[i]) == 1 and zeros > 0:\r\n contador += 2\r\n zeros = 0\r\n elif int(emails[i]) == 0:\r\n zeros += 1\r\n continue\r\n\r\nprint(contador)\r\n \r\n \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\ninput()\r\na=input()+' '\r\nprint(a.count('1')+max(len([*filter(None,a.split('0 '))])-1,0))", "n = int(input())\r\nlst = list(map(int, input().split()))\r\ni = 0\r\ncount = 0\r\nwhile i < n-1:\r\n if lst[i] == 1:\r\n count += 1\r\n if lst[i+1] == 0:\r\n count += 1 \r\n i += 1\r\nif lst[n-1] == 0:\r\n count = max(0, count-1)\r\nelse:\r\n count += 1\r\nprint(count)\r\n", "n=int(input())\r\na=list(map(int,input().strip().split(\" \")))\r\na=[0]+a\r\nans=0\r\nfor i in range(1,n+1):\r\n if (a[i] and a[i-1]):\r\n ans+=1\r\n elif a[i]:\r\n ans+=2\r\nif ans:\r\n print(ans-1)\r\nelse:\r\n print(0)\r\n", "def main():\n n_mails = int(input())\n mails = [int(_) for _ in input().split()]\n\n opening_times = sum(mails)\n switching_times = sum(mails[i] == 1 and mails[i - 1] == 0 for i in range(1, n_mails))\n\n if switching_times > 0 and mails[0] == 0:\n switching_times -= 1\n\n print(opening_times + switching_times)\n\n\nif __name__ == '__main__':\n main()\n", "n = int(input())\r\nstr = \"\".join(input().split(\" \"))\r\n\r\nprev = -1\r\ncount = 0\r\n\r\nfor i in range(0,n):\r\n if(str[i]=='1'):\r\n #Case 1: Previous element was present at a distance less than or equal to 2\r\n # and current unread message is not the first unread message\r\n if(i-prev<=2 and prev!=-1):\r\n count += i-prev\r\n #Case 2: First unread message\r\n elif(prev==-1):\r\n count += 1\r\n #Case 3: Previous element was present at a distance more than 2 and current\r\n # unread message is not the first unread message of the inbox\r\n # 2 is added because 1 movement is for returning back to list and other to\r\n # to come back to read mail view.\r\n else:\r\n count += 2\r\n #update previous found unread message index\r\n prev = i\r\n\r\nprint(count)", "z=int(input());ans=0\r\nx=input().split()\r\nif '1' not in x:\r\n print(0)\r\nelse: \r\n for i in range(x.index('1')+1,z):\r\n if x[i]=='1':\r\n if x[i-1]=='1' :\r\n ans+=1\r\n else:\r\n ans+=2 \r\n print(ans+1)\r\n\r\n", "nletters = int(input())\n\nletters = list(map(int,input().split(\" \")))\n\n\nop = 0\nindx = 0\nfor i in range(nletters):\n if(letters[i] == 1):\n if(i - indx > 1 and op > 0):\n op += 1\n op+= 1\n indx = i\n \n\nprint(op)\n\n \t \t\t\t\t \t\t \t \t\t\t\t \t \t\t\t\t", "m = int(input())\r\nl = list(map(int, input().split()))\r\np = 0\r\nf = False\r\nfor i in range(m):\r\n if l[i] == 1 and f == False:\r\n p = p + 1\r\n if i + 1 < m:\r\n if l[i + 1] == 0:\r\n f = True\r\n if l[i] == 0 and f == True:\r\n p = p + 1\r\n f = False\r\nif l[m - 1] == 0 and p > 0:\r\n p = p - 1\r\nprint(p)\r\n", "# your code goes here\r\n\r\nn = input()\r\nstr_input = input()\r\narr = [int(val) for val in str_input.split(\" \")]\r\n\r\n\r\nsum = 0\r\nlast = -1\r\nfor idx, val in enumerate(arr):\r\n\tif val == 1:\r\n\t\tif last != -1:\r\n\t\t\tdiff = idx - last\r\n\t\t\tif diff<=2:\r\n\t\t\t\tsum += diff\r\n\t\t\telse:\r\n\t\t\t\tsum += 2\r\n\t\telse:\r\n\t\t\tsum += 1\r\n\t\tlast = idx\r\n\t\t# print(sum)\r\n\r\nprint(sum)\r\n# print(n)\r\n# print(arr)", "n = int(input())\r\nstates = [int(c) for c in input().split()]\r\n\r\n\r\n\r\nwhile states and states[-1] == 0:\r\n states.pop()\r\n\r\nif not states:\r\n print(0)\r\n exit()\r\n\r\ni = 0\r\nwhile states[i] == 0:\r\n i += 1\r\n\r\nans = 0\r\nwhile i < len(states):\r\n if states[i] == 1:\r\n ans += 1\r\n i += 1\r\n elif states[i] == 0:\r\n ans += 1\r\n i += 1\r\n while i < n and states[i] == 0:\r\n i += 1\r\n\r\nprint(ans)\r\n", "n = int(input())\r\na = list(map(int,input().split()))\r\nl=0\r\nc=0\r\nfor i in range(n):\r\n if(c==0 and a[i]==1):\r\n c=1\r\n l=i\r\n elif(a[i]==1):\r\n c += min(2,i-l)\r\n l=i\r\nprint(c)", "n = int(input())\nmails = input()\nif mails.count('1') == 0:\n print(0)\nelse:\n res = 0\n mails = [x for x in mails.split('0') if x.count('1') >= 1]\n for i in mails:\n res += i.count('1')\n print(res + len(mails) - 1)\n", "n = int(input())\ndata = input().split()\n\n#disregard starting zeroes:\ni = 0\nwhile i < n and data[i] == '0':\n i+=1\n\n#disregard trailing zeroes:\nj = n - 1\nwhile j > 0 and data[j] == '0':\n j -=1\n\n#count occurrences of groups of zeros:\n\nones = 0\ncount = 0\n\nwhile i <= j:\n if data[i] =='1':\n i +=1\n ones += 1\n else:\n zeros = 0\n while i <= j and data[i] == '0':\n zeros += 1\n i +=1\n if zeros > 1:\n count += 1\n else: ones += 1\n\nprint(count + ones)\n\n \t \t \t\t\t \t\t\t\t \t\t\t \t\t \t\t \t\t", "n = int(input())\r\nmailbox = list(map(int, input().split())) + [0]\r\nans = 0\r\nfor i in range(n):\r\n if mailbox[i] == 1:\r\n ans += 1\r\n if mailbox[i + 1] == 0:\r\n ans += 1\r\nprint(max(0, ans - 1))", "n_letters = int(input())\nlist_letters = list(map(int, input().split()))\n\ncount_clicks = list_letters[0]\n\nvoltou_pagina = False\nfor i in range(len(list_letters) - 1):\n atual = list_letters[i]\n proximo = list_letters[i+1]\n\n if atual == 0 and proximo == 1:\n count_clicks += 1\n voltou_pagina = False\n elif atual == 1 and proximo == 1:\n count_clicks += 1\n elif atual == 1 and proximo == 0:\n voltou_pagina = True\n count_clicks += 1\n\nif voltou_pagina:\n count_clicks -= 1\nprint(count_clicks)\n \t \t\t \t \t \t\t \t\t \t", "N = int(input())\r\narr = list(map(int,input().split()))\r\nstack = []\r\nresult = 0\r\nwhile(arr and arr[0] == 0) :\r\n arr.pop(0)\r\nfor i in arr:\r\n if not stack:\r\n result += 1\r\n elif stack[-1] != 1 and i == 1:\r\n result += 2\r\n elif stack[-1] == 1 and i == 1:\r\n result += 1\r\n stack.append(i)\r\nprint(result)", "n = int(input())\nletters = [ int(a) for a in input().split() ]\n\nunread = 0\nchanges = 0\nlast = 0\nfor letter in letters:\n if letter == 1:\n unread += 1\n\n if last != letter:\n last = letter\n changes += 1\n\nif letters[0] == 0 and changes > 0:\n changes -= 1\nif letters[n-1] == 0 and changes > 0:\n changes -= 1\nprint(unread + changes//2)\n", "#465B\r\nn = int(input())\r\ns = input()\r\ns = s.replace(\" \", \"\")\r\ns = s.replace('0', \" \")\r\ns = s.strip()\r\nprint(len('0'.join(s.split())))\r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nr=[]\r\nfor i in range(n):\r\n if(l[i]==1):\r\n r.append(i)\r\nc=0\r\nif(len(r)>=1):\r\n c+=1\r\n for i in range(1,len(r)):\r\n if(r[i]-r[i-1]==1):\r\n c+=1\r\n else:\r\n c+=2\r\nprint(c)", "n = int(input())\r\nletters = [int(x) for x in input().split()]\r\ncount = 0\r\nres = 0\r\ni = 0\r\nwhile i < n:\r\n if letters[i] == 1:\r\n break\r\n i += 1\r\n\r\nwhile i < n:\r\n if letters[i] == 1:\r\n if count == 0:\r\n res += 1\r\n else:\r\n res += 2\r\n count = 0\r\n else:\r\n count += 1\r\n i += 1\r\nprint(res)\r\n", "#465B (75No. Problem B)\r\nl = int(input())\r\nbox = ''.join(map(str,input().split()))\r\n# print(box)\r\nif ('1' not in box):\r\n print(0)\r\nelse: \r\n i = box.find('1')\r\n e = box.rfind('1')\r\n t,c = 0,0\r\n while i <= e:\r\n if (box[i] == '0'):\r\n c+=1\r\n elif (box[i] == '1'):\r\n i = box.find('1',i)\r\n if (c > 0):\r\n t+=1\r\n c = 0\r\n i+=1 \r\n # print(t) \r\n o = box.count('1')\r\n t+=o\r\n print(t)", "n=int(input())\nz=list(map(int,input().split()))\n\n##y=[]\n##for i in z :\n## y.append(i)\n##y.reverse()\n##kevin=y.index(1)\ncount=0\n\nfor i in range(n) :\n if z[i]==1 :\n count+=1\n if i+1!=n :\n if z[i+1]==0 :\n count+=1\n else :\n counti=1\n if counti+i<n :\n while z[counti+i]==1:\n counti+=1\n count+=1\n z[counti+i-1]=0\n if counti+i>=n :\n break\n count+=1\n else :\n count+=1\nif count==0 :\n print(0)\nelse :\n print(count-1)\n\n \t\t \t\t \t \t\t\t\t \t\t\t\t\t\t\t\t\t \t\t\t", "n, states = int(input()), list(map(int, input().split()))\r\nindexes = [index + 1 for index in range(n) if states[index]]\r\nit, ans = 0, int(len(indexes) != 0)\r\n\r\nwhile it < len(indexes) - 1:\r\n ans += 2 if indexes[it] + 1 != indexes[it + 1] else 1\r\n it += 1\r\n\r\nprint(ans)", "from functools import lru_cache\nfrom collections import defaultdict, deque\nfrom heapq import heappush, heappop\n\ndef solution():\n _ = int(input())\n arr = list(map(int, input().split()))\n start = 0\n while start < len(arr) and arr[start] == 0:\n start += 1\n\n if start >= len(arr):\n print(0)\n return;\n\n start += 1\n res = 1\n while start < len(arr):\n if arr[start] == 1:\n res += 1 if arr[start-1] == 1 else 2\n start += 1\n print(res)\n\n \n\nimport sys\nimport threading\nsys.setrecursionlimit(1 << 30)\nthreading.stack_size(1 << 27)\nthread = threading.Thread(target=solution)\nthread.start(); thread.join()\n#solution()\n#a, b = map(int, input().split())\n#arr = list(map(int, input().split()))\n", "n = int(input())\r\narr = [i for i , x in enumerate(input().split()) if x == '1']\r\ncounter = 0\r\nif len(arr) == 0:\r\n print(0)\r\nelse:\r\n counter += 1\r\n for i in range(1 , len(arr)):\r\n counter += min(arr[i] - arr[i - 1] , 2)\r\n print(counter)", "n = int(input())\r\narr = list(map(int, input().split()))\r\nind = []\r\ninc = 0\r\nfor i in range(n):\r\n if arr[i] == 1:\r\n ind.append(i)\r\n inc += 1\r\ngaps = 0\r\nfor i in range(inc - 1):\r\n if ind[i+1] - ind[i] > 1:\r\n gaps += 1\r\nprint(inc + gaps)", "size = input()\nmailbox_raw = input()\n\nmailbox = mailbox_raw.split()\n\nread = '0'\nunread = '1'\n\nalready_counted_first = False\nactions = 0\n\nfor i in range(len(mailbox)):\n if mailbox[i] == unread and not already_counted_first:\n actions += 1\n already_counted_first = True\n elif mailbox[i] == unread and already_counted_first and mailbox[i-1] != read:\n actions += 1\n elif mailbox[i] == unread and already_counted_first and mailbox[i-1] == read:\n actions += 2\n\nprint(actions)\n\t \t\t \t\t\t\t\t \t \t\t \t\t \t\t\t\t \t \t", "\nn = int(input())\nline = input().split()\nemail = [int(e) for e in line]\n\ncount = 0\nlast = 1\nfind = False\n\nfor i in email:\n if find:\n if i == 1:\n if last == 1:\n count += 1\n else:\n count += 2\n last = i\n\n else:\n if i == 1:\n find = True\n count += 1\n\nprint(count)\n\t \t \t\t\t \t\t \t \t\t \t \t\t\t\t \t", "import sys, re\r\n\r\nprint(len(re.sub('0+', '0', sys.stdin.readlines()[1][:-1].replace(' ', '')).strip('0')))", "n = int(input())\nx = list(map(int, input().split()))\nif x.count(1) != 0:\n lastIndex = n - x[::-1].index(1) - 1\ncnt = 0\nfor i in range(n):\n if i == n - 1:\n if x[i] == 1:\n cnt += 1\n break\n if x[i] == 1:\n cnt += 1\n if x[i + 1] == 0 and i != lastIndex:\n cnt += 1\nprint(cnt)\n", "input()\r\ns=\"\".join(input().split())\r\nclicks = s.count(\"1\") + len(s.replace(\"0\", \" \").split()) - 1\r\nprint(max(0, clicks))\r\n\r\n", "# coding: utf-8\nn = int(input())\nsta = [i for i in ''.join(input().split()).split('0') if i != '']\nans = 0\nfor i in sta:\n ans += 2+len(i)-1\nif ans != 0:\n print(ans-1)\nelse:\n print(0)\n", "input()\r\nans = 0\r\nis_list = True\r\nletters = input().split()\r\nfor i in letters:\r\n if i == '1':\r\n ans += 1\r\n is_list = False\r\n elif not is_list:\r\n ans += 1\r\n is_list = True\r\nprint(max(ans - is_list, 0))\r\n" ]
{"inputs": ["5\n0 1 0 1 0", "5\n1 1 0 0 1", "2\n0 0", "9\n1 0 1 0 1 0 1 0 1", "5\n1 1 1 1 1", "14\n0 0 1 1 1 0 1 1 1 0 1 1 1 0", "23\n1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1", "27\n0 1 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", "10\n1 0 0 0 0 1 0 0 0 1", "10\n1 0 0 1 0 0 1 1 0 1", "27\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", "39\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1", "48\n1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1", "71\n0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0", "99\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1", "99\n1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 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", "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 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "193\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "213\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 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0 0 0 0 0", "2\n1 0", "1\n1", "1\n0", "5\n0 0 0 0 1", "12\n0 1 1 0 1 1 0 1 1 0 0 0", "3\n1 0 0", "5\n0 0 1 0 0", "3\n0 1 0", "6\n1 1 0 0 0 0", "4\n0 1 0 0", "5\n1 1 1 0 0", "4\n1 0 0 0", "6\n1 1 1 1 0 0"], "outputs": ["3", "4", "0", "9", "5", "11", "23", "25", "5", "8", "0", "39", "39", "59", "99", "99", "100", "99", "1", "5", "1", "1", "0", "1", "8", "1", "1", "1", "2", "1", "3", "1", "4"]}
UNKNOWN
PYTHON3
CODEFORCES
209
13cbed0d2f029102bb46ecec65fe6d8d
Switches and Lamps
You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*-th lamp. Initially all *m* lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all *n* switches then all *m* lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other *n*<=-<=1 switches then all the *m* lamps will be turned on. The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2000) — the number of the switches and the number of the lamps. The following *n* lines contain *m* characters each. The character *a**i*,<=*j* is equal to '1' if the *i*-th switch turns on the *j*-th lamp and '0' otherwise. It is guaranteed that if you press all *n* switches all *m* lamps will be turned on. Print "YES" if there is a switch that if you will ignore it and press all the other *n*<=-<=1 switches then all *m* lamps will be turned on. Print "NO" if there is no such switch. Sample Input 4 5 10101 01000 00111 10000 4 5 10100 01000 00110 00101 Sample Output YES NO
[ "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Mon May 21 22:31:07 2018\n\n@author: thomas\n\"\"\"\nintegers=input()\n[n,m]=[int(x) for x in integers.split()]\na=[]\nfor i in range(n):\n row_i=input()\n a_i=[]\n for j in range(m):\n a_i.append(int(row_i[j]))\n a.append(a_i)\n \nindicator=False\n#all_sum=[0]*m\n#for i in range(n):\n# for j in range(m):\n# all_sum[j]+=a[i][j]\nall_sum=[sum(x) for x in zip(*a)]\nfor i in range(n):\n consider=[x-y for x, y in zip(all_sum, a[i])]\n indicator=(sum([x>0 for x in consider])==m)\n if (indicator==True): break\nif (indicator==True): print(\"YES\")\nelse: print(\"NO\")", "n,m=(int(i) for i in input().split())\r\na=[[] for i in range(n)]\r\ns=[input() for i in range(n)]\r\nb=[0]*m\r\nf=[True]*n\r\nfor i in range(n):\r\n for j in range(m):\r\n if s[i][j]=='1':\r\n a[i].append(j)\r\n b[j]+=1\r\nfor i in range(n):\r\n for j in a[i]:\r\n if b[j]==1:\r\n f[i]=False\r\n break\r\nif True in f:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "def appendTotal(total, cmd):\r\n for i in range(len(cmd)):\r\n total[i] += int(cmd[i])\r\n\r\n\r\ndef canIgnore(total, cmd):\r\n for i in range(len(cmd)):\r\n if total[i] == cmd[i]:\r\n return False\r\n\r\n return True\r\n\r\n\r\ndef main():\r\n inpt = list(map(int, input().split()))\r\n n = inpt[0]\r\n\r\n switches = list()\r\n switches.append(input())\r\n total = [int(x) for x in list(switches[0])]\r\n\r\n for i in range(n - 1):\r\n cmd = input()\r\n switches.append(cmd)\r\n appendTotal(total, list(cmd))\r\n\r\n for i in range(n):\r\n if canIgnore(total, [int(x) for x in list(switches[i])]):\r\n print(\"YES\")\r\n exit(0)\r\n print(\"NO\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "def fun(grid,counter,n,m):\r\n for i in range(n):\r\n possible=True\r\n for j in range(m):\r\n if grid[i][j]=='1' and counter[j]==1:\r\n possible=False\r\n break\r\n if possible:\r\n return True\r\n return False\r\n\r\nn,m=[int(_) for _ in input().split(\" \")]\r\ngrid,counter=[],[0]*m\r\nfor _ in range(n):\r\n s=input()\r\n for i in range(m):\r\n if s[i]=='1':\r\n counter[i]+=1\r\n grid.append(s)\r\nif fun(grid,counter,n,m):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n", "n,m=map(int,input().split())\ns=0\nfor a in zip(*(input()for _ in range(n))):\n if a.count('1')==1:s|=1<<a.index('1')\nprint(('YES','NO')[s==2**n-1])", "def main():\n n, m = map(int, input().split())\n switches = [int(input(), 2) for _ in range(n)]\n lambs_on = 0\n duplicate_control = 0\n\n for lambs_turn_on in switches:\n duplicate_control |= lambs_on & lambs_turn_on\n lambs_on |= lambs_turn_on\n\n if any(lambs_turn_on & lambs_on & ~duplicate_control == 0 for lambs_turn_on in switches):\n print('YES')\n else:\n print('NO')\n\n\nif __name__ == '__main__':\n main()", "from sys import stdin, stdout\r\nnmbr = lambda: int(input())\r\nlst = lambda: list(map(int, input().split()))\r\n\r\nfor _ in range(1):#nmbr()):\r\n r, c=lst()\r\n a=[input() for i in range(r)]\r\n pre=[[0 for i in range(c)] for i in range(r)]\r\n suf=[[0 for i in range(c)] for i in range(r)]\r\n for i in range(c):\r\n pre[0][i]=int(a[0][i])\r\n suf[r-1][i]=int(a[r-1][i])\r\n for i in range(1, r):\r\n for j in range(c):\r\n pre[i][j]=pre[i-1][j]+int(a[i][j])\r\n # print(*pre, sep='\\n')\r\n for i in range(r-2, -1 ,-1):\r\n for j in range(c):\r\n suf[i][j]=suf[i+1][j]+int(a[i][j])\r\n ans='NO'\r\n for i in range(r):\r\n f=1\r\n for j in range(c):\r\n up=down=0\r\n if i-1>=0:up=pre[i-1][j]\r\n if i+1<r:down=suf[i+1][j]\r\n if up+down==0:\r\n f=0\r\n break\r\n if f:\r\n ans=\"YES\"\r\n break\r\n print(ans)\r\n", "\"\"\" 616C \"\"\"\r\n\"\"\" 1152B \"\"\"\r\nimport math\r\n# import sys\r\ndef main():\r\n\t# n ,m= map(int,input().split())\r\n\t# arr = list(map(int,input().split()))\r\n\t# b = list(map(int,input().split()))\r\n\t# n = int(input())\r\n\t# string = str(input())\r\n\tn ,m = map(int,input().split())\r\n\tarr = []\r\n\tfor _ in range(n):\r\n\t\tarr.append(list(str(input())))\r\n\tdp = [0 for _ in range(m)]\r\n\tfor x in arr:\r\n\t\tfor j in range(len(x)):\r\n\t\t\tif x[j]=='1':\r\n\t\t\t\tdp[j]+=1\r\n\tfor i in range(n):\r\n\t\tfor j in range(m):\r\n\t\t\tif(arr[i][j]=='1'):\r\n\t\t\t\tdp[j]-=1\r\n\t\tcnt = 0\r\n\t\tfor k in range(m):\r\n\t\t\tif(dp[k]>0):\r\n\t\t\t\tcnt+=1\r\n\t\tif(cnt==m):\r\n\t\t\tprint(\"YES\")\r\n\t\t\treturn\r\n\t\tfor j in range(m):\r\n\t\t\tif(arr[i][j]=='1'):\r\n\t\t\t\tdp[j]+=1\r\n\tprint(\"NO\")\r\n\treturn\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", "R = lambda : map(int, input().split())\nn,m = R()\na = []\nb = 0\nc = 0\nfor i in range(n):\n s = int(input(),2)\n a.append(s)\n c |=s&b\n b |=s\nprint(('YES','NO')[all(i&~c for i in a)])\n", "from bisect import bisect_left, bisect_right\r\n\r\ndef tuple_input(type):\r\n return map(type, input().strip().split())\r\n\r\nn, m = map(int, input().strip().split())\r\na = list()\r\nfor _ in range(n):\r\n a.append(input().strip())\r\nh = [0] * m\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] == '1':\r\n h[j] += 1\r\nres = False\r\nfor i in range(n):\r\n ok = True\r\n for j in range(m):\r\n if a[i][j] == '1' and h[j] <= 1:\r\n ok = False\r\n break\r\n res = res or ok\r\nprint('YES') if res else print('NO')\r\n\r\n \r\n\r\n ", "def main():\r\n import sys\r\n input = sys.stdin.readline\r\n\r\n N, M = map(int, input().split())\r\n grid = []\r\n for _ in range(N):\r\n grid.append(input().rstrip('\\n'))\r\n\r\n cnt = [0] * M\r\n for line in grid:\r\n for m in range(M):\r\n if line[m] == '1':\r\n cnt[m] += 1\r\n for i in range(N):\r\n line = grid[i]\r\n need = 0\r\n for j in range(M):\r\n if line[j] == '1':\r\n if cnt[j] == 1:\r\n need = 1\r\n break\r\n if not need:\r\n print('YES')\r\n exit()\r\n print('NO')\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n,m = map(int,input().split())\r\nlis=[]\r\nfor i in range(n):\r\n l = list(input())\r\n lis.append(l)\r\nlam=[0]*n\r\nfor i in range(m):\r\n c=0\r\n for j in range(n):\r\n if lis[j][i]=='1':\r\n ind=j\r\n c+=1\r\n if c==1:\r\n lam[ind]=1\r\n# print(lam) \r\nif sum(lam)<n:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") \r\n \r\n", "n, m = map(int, input().split())\r\ntc = [0]*m\r\nps = []\r\nfor _ in range(n):\r\n temp = input()\r\n psa = [0]*m\r\n for i in range(m):\r\n if temp[i] == '1':\r\n psa[i] += 1\r\n tc[i] += 1\r\n ps.append(psa)\r\nans = 'NO'\r\n\r\nfor i in ps:\r\n c = 0\r\n for j in range(m):\r\n if tc[j]-i[j] > 0:\r\n c += 1\r\n if c == m:\r\n ans = 'YES'\r\n break\r\n\r\nprint(ans)\r\n", "n,m = map(int,input().split())\r\nd = {x:0 for x in range(m)}\r\nl = []\r\nfor _ in range(n):\r\n s = input()\r\n for x in range(m):\r\n if s[x]== '1': d[x]+=1\r\n l.append(s)\r\nfor x in l:\r\n t=0\r\n for y in range(m):\r\n if x[y] =='1':\r\n if d[y] ==1:t = 1;break\r\n if t==0: print('YES');exit()\r\nprint('NO')", "n, m = map(int, input().split())\r\na = [list(map(int, input())) for _ in range(n)]\r\ns = [sum(z) for z in zip(*a)]\r\n#print(s)\r\nfor r in a:\r\n #print(r)\r\n #print(*map(lambda x, y: x and y < 2, r, s))\r\n if not any(map(lambda x, y: x and y < 2, r, s)):\r\n print(\"YES\")\r\n break\r\nelse: \r\n print(\"NO\")\r\n", "n, m = [int(x) for x in input().split(' ')]\r\n\r\nans = 'NO'\r\nrows = [[int(x) for x in list(input())] for row in range(n)]\r\n\r\ntotals = [sum([rows[i][j] for i in range(n)]) for j in range(m)]\r\n\r\nfor row in rows:\r\n if min([t - r for (t,r) in zip(totals, row)]) > 0:\r\n ans = 'YES'\r\n break\r\n\r\nprint(ans)", "if __name__ == '__main__':\r\n n,m = tuple((input().split()))\r\n n = int(n)\r\n m = int(m)\r\n a = []\r\n for i in range(n):\r\n a.append([ord(j) - ord('0') for j in input()])\r\n ar = n*[0]\r\n for j in range(m):\r\n icount = 0\r\n saved = -1\r\n for i in range(n):\r\n if a[i][j]:\r\n icount+=1\r\n saved = i\r\n if icount == 1:\r\n ar[saved] = 1\r\n valid = False\r\n for i in range(n):\r\n if ar[i] == 0:\r\n valid = True\r\n print(\"YES\" if valid else \"NO\")", "# Getting switch and lamp counts in addition to the lamp\r\n# combinations corresponding to each switch from codeforces.\r\nswitchCount,lampCount = tuple(map(int,input().split()))\r\nswitches = []\r\nfor i in range(switchCount):\r\n switches.append(int(input(),2))\r\n# Defining method to determing if all lamps can be switched\r\n# on, if switch with given index is not taken into account.\r\ndef canSwitchOnWithout(index):\r\n bitwiseOr = 0\r\n for i in range(switchCount):\r\n if i !=index:\r\n bitwiseOr = bitwiseOr | switches[i]\r\n return bitwiseOr\r\n# Determining if a switch exists such that without it all\r\n# lamps can still be turned on.\r\nlampsOn,index,exists = int('1'*lampCount,2),0,False\r\nwhile not exists and index<switchCount:\r\n if canSwitchOnWithout(index) == lampsOn:\r\n exists = not exists\r\n else: index = index + 1\r\n# Final Verdict.\r\nprint('YES') if exists else print('NO')\r\n", "n, m = map(int, input().split())\n\narr = []\nfor i in range(n):\n arr.append([int(s) for s in input()])\n # colCount = [col + entry for col, entry in zip(colCount, (int(s) for s in input()))]\n\ncolCount = [sum([r[i] for r in arr]) for i in range(m)]\n\nres = False\nfor r in arr:\n diff = [c - e for c, e in zip(colCount, r)]\n if diff.count(0) == 0:\n res = True\n break\n\nprint(\"YES\" if res else \"NO\")\n# print(arr)\n# print(colCount)\n# if colCount.count(1) < n:\n# print(\"YES\")\n# else:\n# print(\"NO\")", "def main():\n n, m = map(int, input().split())\n rows = []\n s = [0 for _ in range(m)]\n for _ in range(n):\n l = [int(x) for x in list(input())]\n rows.append(l)\n s = [x + y for x, y in zip(s, l)]\n\n for l in rows:\n r = [x - y for x, y in zip(s, l)]\n if r.count(0) == 0:\n print('YES')\n return\n else:\n print('NO')\n return\n\n\n\nif __name__ == '__main__':\n main()", "n,m=map(int,input().split())\ns=2**n-1\nfor a in zip(*(input()for _ in range(n))):\n if a.count('1')==1:s&=~(1<<a.index('1'))\nprint('YES'if s else'NO')", "n, m = map(int, input().split())\ngrid = []\nfor i in range(n):\n grid.append(input())\ncnts = [0 for i in range(m)]\nfor i in range(n):\n for j in range(m):\n cnts[j] += 0 if grid[i][j] == '0' else 1\nfor i in range(n):\n flag = True\n for j in range(m):\n if grid[i][j] == '1' and cnts[j] == 1:\n flag = False\n break\n if flag:\n print('YES')\n exit(0)\nprint('NO')\n \t \t\t\t\t\t \t \t \t\t \t\t\t\t\t \t\t \t", "input()\na = tuple(map(lambda s: int(s.strip(), 2), __import__('sys').stdin.readlines()))\nt = T = 0\nfor x in a:\n t |= T & x\n T |= x\nprint(['YES', 'NO'][all(x & (x ^ t) for x in a)])\n", "\r\nn,m = map(int,input().split(' '))\r\n\r\nres = []\r\nlamps = {}\r\nfor i in range(n):\r\n res.append(input())\r\n # if i not in lamps.keys():\r\n # lamps[i] = []\r\n # for j in range(m):\r\n # if res[i][j] == '1':\r\n # lamps[j].append(i)\r\n\r\nfor i in range(len(res)):\r\n for j in range(len(res[i])):\r\n # print (i,j)\r\n if j not in lamps.keys():\r\n lamps[j] = []\r\n if res[i][j] == '1':\r\n lamps[j].append(i)\r\nvalid = True\r\nfor i in range(n):\r\n valid = True\r\n for j in range(len(res[i])):\r\n if res[i][j] == '1':\r\n if len(lamps[j]) == 1:\r\n valid = False\r\n continue\r\n if valid:\r\n break\r\nif valid:\r\n print ('YES')\r\nelse:\r\n print ('NO')", "from math import *\r\nimport random, sys\r\n\r\ndef nextInt():\r\n\treturn int(input())\r\ndef nextStrs():\r\n\treturn input().split()\r\ndef nextInts():\r\n\treturn list(map(int,nextStrs()))\r\n\r\ndef main():\r\n n,m = nextInts() \r\n\r\n arr = [0] * n\r\n col = [0] * m\r\n res = False\r\n for i in range(n):\r\n x = input()\r\n arr[i] = x \r\n\r\n for j in range(len(x)):\r\n if x[j] == '1':\r\n col[j] += 1\r\n\r\n for i in range(n):\r\n ok = False\r\n for j in range(m):\r\n if arr[i][j] == '1' and col[j] == 1:\r\n ok = True\r\n\r\n if ok == False:\r\n res = True\r\n break\r\n\r\n if res == True:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\nif __name__ == \"__main__\":\r\n exit(main())", "def main():\n n, m = map(int, input().split())\n grid = [input() for _ in range(n)]\n counts = [sum(grid[i][j] == '1' for i in range(n)) for j in range(m)]\n no_skip = all(any(grid[i][j] == '1' and counts[j] == 1 for j in range(m)) for i in range(n))\n\n print('NO' if no_skip else 'YES')\nmain()\n", "n,m=map(int,input().split())\r\nt=[list(input()) for _ in range(n)]\r\nk=[0 for _ in range(m)]\r\nfor i in range(n):\r\n for j in range(m):\r\n if t[i][j]=='1':\r\n k[j]+=1\r\nfor i in range(n):\r\n x=1\r\n for j in range(len(t[i])):\r\n if (k[j]-int(t[i][j]))<=0:\r\n x=0\r\n if x==1:\r\n break\r\nif x==1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n, _ = map(int, input().split())\r\nswitches = [int(input(), 2) for _ in range(n)]\r\nextra = lit = 0\r\n\r\nfor switch in switches:\r\n extra |= lit & switch\r\n lit |= switch\r\n\r\nnecessary = ~extra\r\n\r\nprint('NO' if all(switch & necessary for switch in switches) else 'YES')", "n, m = map(int, input().split())\r\na = []\r\nb = [0] * m\r\nfor i in range(n):\r\n s = list(input())\r\n for j in range(m):\r\n if s[j] == '1':\r\n b[j] += 1\r\n a.append(s)\r\nfor s in a:\r\n exist = True\r\n for i in range(m):\r\n if s[i] == '1' and b[i] < 2:\r\n exist = False\r\n break\r\n if exist:\r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\")", "n, m = [int(i) for i in input().split()]\r\na = [[int(i) for i in input()] for j in range(n)]\r\nb2 = set()\r\nans = 'YES'\r\nfor j in range(m):\r\n b = []\r\n for i in range(n):\r\n if a[i][j] == 1:\r\n b.append(i)\r\n if len(b) == 1:\r\n b2.add(b[0])\r\n elif b == []:\r\n ans = 'NO'\r\nif ans == 'NO' or len(b2) == n:\r\n print('NO')\r\nelse:\r\n print('YES') \r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\nn, m = map(int, input().split())\r\ng = [input()[:-1] for _ in range(n)]\r\nw = list(zip(*g))\r\ns = set()\r\nfor i in w:\r\n if i.count('1') == 1:\r\n s.add(i.index('1'))\r\n\r\nif len(s) != n:\r\n print('YES')\r\nelse:\r\n print(\"NO\")\r\n", "n,m=map(int,input().split())\na=[int(input(),2)for _ in range(n)]\ns=t=0\nfor x in a:\n t|=s&x;s|=x\nprint(('YES','NO')[all(x&s&~t for x in a)])\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\n\r\ns = []\r\nall_s = [0] * m\r\n\r\nfor x in range(n):\r\n line = list(map(int, list(input())))\r\n s.append(line)\r\n all_s = [sum(x) for x in zip(line, all_s)]\r\n\r\nfor x in s:\r\n# print(x)\r\n\r\n di = [all_s[i] - x[i] for i in range(m)]\r\n# print(di)\r\n\r\n if min(di) > 0:\r\n print('YES')\r\n exit()\r\n\r\nprint('NO')\r\n", "# qumeric\r\nn, m = map(int, input().split())\r\na = [int(input(), 2) for _ in range(n)]\r\n\r\ns = t = 0\r\nfor x in a:\r\n t |= s & x\r\n s |= x\r\nprint((\"YES\", \"NO\")[all(x & s & ~t for x in a)])\r\n", "N, M = map(int,input().split())\nC = [0]*M\nA = [input() for _ in range(N)]\nfor i in A:\n for j in range(M):\n if i[j] == '1':\n C[j] += 1\n\nfor i in A:\n for j in range(M):\n if i[j] == '1' and C[j] == 1:\n break\n else:\n print('YES')\n exit(0)\n\nprint('NO')\n", "n,m = list(map(int,input().split()))\r\nsets = [None]*n\r\ndic_all = {}\r\nfor i in range(n):\r\n a = input()\r\n tmp = set()\r\n for j,x in enumerate(a):\r\n if x=='1':\r\n tmp.add(j)\r\n if j in dic_all:\r\n dic_all[j]+=1\r\n else:\r\n dic_all[j]=1\r\n sets[i] = tmp\r\nflag = False\r\nfor s in sets:\r\n flag2 = False\r\n for x in s:\r\n if dic_all[x]>1:\r\n continue\r\n else:\r\n flag2 = True\r\n break\r\n if flag2:\r\n continue\r\n flag = True\r\n break\r\nif flag:\r\n print('YES')\r\nelse:\r\n print('NO')", "n, m = map(int,input().split())\r\nX = []\r\nfor i in range(n):\r\n a = input()\r\n U = [char for char in a]\r\n X.append(U)\r\nnums = []\r\nfor i in range(m):\r\n t = 0 \r\n for j in range(n):\r\n t += int(X[j][i])\r\n nums.append(t)\r\n\r\nfor i in range(n):\r\n ok = True \r\n for j in range(m):\r\n if X[i][j] == '1':\r\n if nums[j]>1:\r\n continue \r\n else:\r\n ok = False \r\n if ok == True:\r\n print(\"YES\")\r\n quit()\r\nprint(\"NO\")", "def main():\r\n\tn,m=map(int,input().split())\r\n\tcounts=[0]*m\r\n\ta=[None]*n\r\n\tfor i in range(n):\r\n\t\tline=input()\r\n\t\ta[i]=line\r\n\t\tfor j in range(m):\r\n\t\t\tcounts[j]+=1 if line[j]=='1' else 0\r\n\r\n\tif 1 not in counts:\r\n\t\tprint('YES')\r\n\t\treturn\r\n\tchecks=[]\r\n\tfor i in range(m):\r\n\t\tif counts[i]==1:\r\n\t\t\tchecks.append(i)\r\n\tleng=len(checks)\r\n\tfor i in range(n):\r\n\t\tcur=a[i]\r\n\t\tfor j in range(leng):\r\n\t\t\tif cur[checks[j]]=='1':\r\n\t\t\t\tbreak\r\n\t\telse:\r\n\t\t\tprint('YES')\r\n\t\t\treturn\r\n\tprint('NO')\r\n\r\nmain()", "N, M = map(int, input().split())\r\nT = [[] for i in range(N)]\r\nfor i in range(N):\r\n a = list(input())\r\n T[i] = a\r\n\r\ncnt = [0] * M\r\nfor i in range(N):\r\n for j in range(M):\r\n if T[i][j] == \"1\":\r\n cnt[j] += 1\r\n\r\nfor i in range(N):\r\n flag = True\r\n for j in range(M):\r\n if T[i][j] == \"1\" and cnt[j] == 1:\r\n flag = False\r\n\r\n if flag:\r\n print(\"YES\")\r\n exit()\r\n\r\nprint(\"NO\")", "n, m = map(int, input().split())\r\na = [int(input(), 2) for _ in range(n)]\r\n\r\nl = a[::]\r\nr = a[::]\r\nf = 2**m - 1\r\n\r\nfor i in range(1, n):\r\n l[i] |= l[i-1]\r\n r[-i-1] |= r[-i]\r\n\r\nres = False\r\nfor i in range(n):\r\n x = l[i-1] if i != 0 else 0\r\n y = r[i+1] if i != n-1 else 0\r\n\r\n if (x | y) == f:\r\n res = True\r\n break\r\n\r\nprint(\"YES\" if res else \"NO\")\r\n", "import sys\r\n\r\nn, m = map(int, input().split())\r\na = [input() for _ in range(n)]\r\nans = [0]*m\r\nfor line in a:\r\n for i, c in enumerate(line):\r\n if c == '1':\r\n ans[i] += 1\r\n\r\nfor line in a:\r\n if all(ans[i] >= 2 for i, c in enumerate(line) if c == '1'):\r\n print('YES')\r\n exit()\r\nprint('NO')\r\n", "n, m = map(int, input().split())\nx = list(list(map(int , input())) for i in range(n))\nres = [0] * m\nfor i in range(n):\n\tfor j in range(m):\n\t\tres[j] += x[i][j]\n\nfor i in range(n):\n\tok = 1\n\tfor j in range(m):\n\t\tif res[j] == 1 and x[i][j] == 1:\n\t\t\tok = 0\n\t\t\tbreak\n\tif ok:\n\t\tprint(\"YES\")\n\t\texit()\nprint(\"NO\")\n", "n,m=map(int,input().split())\r\nsw=[]\r\nfor i in range(n):\r\n sw.append(input())\r\n if '1' not in sw[i]: print(\"YES\"); exit()\r\nfor i in range(n):\r\n p=0; cnt=0; one=sw[i].count('1')\r\n for j in range(m):\r\n p=0\r\n if sw[i][j]=='1':\r\n for k in range(n):\r\n if sw[k][j]=='1': p+=1\r\n if p>=2: cnt+=1; break\r\n if cnt==one: print(\"YES\"); exit()\r\nprint(\"NO\")", "inp=input().split()\r\na=[]\r\nsumm=[0 for i in range(int(inp[1]))]\r\nfor i in range(int(inp[0])):\r\n s=input()\r\n a.append(s)\r\n for j in range(len(s)):\r\n if s[j]=='1':\r\n summ[j]=summ[j]+1\r\nans=0\r\nfor i in range(int(inp[0])):\r\n s=a[i]\r\n flag=0\r\n for j in range(len(s)):\r\n if s[j]=='1' and summ[j]==1:\r\n flag=1\r\n break\r\n if flag==0:\r\n print('YES')\r\n ans=1\r\n break\r\nif ans==0:\r\n print('NO')\r\n \r\n \r\n", "import sys\r\nimport os\r\n\r\n(n,m) = map(int, input().split())\r\ncount = [0] * m\r\na = list()\r\nfor i in range(0,n):\r\n s = input()\r\n b = list()\r\n for j in range(0,m):\r\n if (s[j] == '1'):\r\n b.append(True)\r\n count[j] += 1\r\n else:\r\n b.append(False)\r\n a.append(b)\r\n\r\nfor i in range(0,n):\r\n for j in range (0,m):\r\n if (a[i][j] == True):\r\n if (count[j] <= 1):\r\n break\r\n else:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")", "n,m=map(int,input().split())\r\ncount=[]\r\nfor i in range(m):\r\n count.append(0)\r\narr=[]\r\nfor i in range(n):\r\n arr.append(input().strip())\r\nfor i in range(n):\r\n for j in range(m):\r\n if arr[i][j]==\"1\":\r\n count[j]+=1 \r\nflag=0\r\nfor i in range(n):\r\n j=0 \r\n while j<m:\r\n if arr[i][j]==\"1\":\r\n if count[j]==1:\r\n break\r\n j+=1 \r\n if j==m:\r\n flag=1 \r\n break\r\nif flag==1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import sys\nimport io, os\ninput = sys.stdin.readline\n\nn, m = map(int, input().split())\nA = [input().rstrip() for i in range(n)]\nC = [0]*m\nfor i in range(n):\n a = A[i]\n for j, c in enumerate(a):\n C[j] += int(c)\n\nfor i in range(n):\n a = A[i]\n for j, c in enumerate(a):\n C[j] -= int(c)\n for j in range(m):\n if C[j] == 0:\n break\n else:\n print('YES')\n exit()\n continue\n for j, c in enumerate(a):\n C[j] += int(c)\nprint('NO')\n", "\r\ndef switches_lamps(n, m, array):\r\n result = 'NO'\r\n for i in range(n):\r\n row_off = True\r\n for j in range(m):\r\n if array[i][j]:\r\n for k in range(n):\r\n if k != i and array[k][j]:\r\n break\r\n else:\r\n row_off = False\r\n if row_off:\r\n result = 'YES'\r\n break\r\n return result\r\nn, m = map(int, input().split(' '))\r\narray = []\r\nfor i in range(n):\r\n array.append(list(map(int, input())))\r\nprint(switches_lamps(n, m, array))\r\n\r\n", "def check(counter, arr):\r\n for i in range(len(arr)):\r\n if arr[i] == '1' and counter[i] == 1:\r\n return False\r\n return True\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n, m = [int(i) for i in input().strip().split()]\r\n l = []\r\n count = [0 for i in range(m)]\r\n for i in range(n):\r\n ip = input().strip()\r\n l.append(ip)\r\n for j in range(m):\r\n if ip[j] == '1':\r\n count[j] += 1\r\n valid = False\r\n for inp in l:\r\n if check(count, inp):\r\n valid = True\r\n break\r\n print(\"YES\" if valid else \"NO\")\r\n", "from sys import stdin,stdout\r\nn,m=map(int,stdin.readline().split())\r\nsw=[]\r\nfor i in range(n):\r\n sw.append(stdin.readline())\r\n if '1' not in sw[i]: stdout.write(\"YES\"); exit()\r\nfor i in range(n):\r\n p=0; cnt=0; one=sw[i].count('1')\r\n for j in range(m):\r\n p=0\r\n if sw[i][j]=='1':\r\n for k in range(n):\r\n if sw[k][j]=='1': p+=1\r\n if p>=2: cnt+=1; break\r\n if cnt==one: stdout.write(\"YES\"); exit()\r\nstdout.write(\"NO\")", "\r\nimport sys\r\n\r\ndef main():\r\n n,m=list(map(int,input().split()))\r\n s = sys.stdin.readlines()\r\n s=[list(map(int,' '.join((x.strip())).split())) for x in s]\r\n summater=[sum([x[i] for x in s]) for i in range(m)]\r\n\r\n for i in s:\r\n k=0\r\n for y in range(m):\r\n\r\n\r\n if summater[y]==i[y] or i[y]>1:\r\n\r\n break\r\n k+=1\r\n\r\n if k==m:\r\n print('YES')\r\n return\r\n\r\n\r\n\r\n print('NO')\r\n\r\n\r\n\r\n\r\nif __name__=='__main__':\r\n main()\r\n", "n, m = [int(i) for i in input().split()]\r\nlst = [input() for i in range(n)]\r\ncount = [0 for _ in range(m)]\r\nfor i in range(n):\r\n for j in range(m):\r\n if lst[i][j] == '1':\r\n count[j] += 1\r\nflag = True\r\nfor i in range(n):\r\n flag = True\r\n for j in range(m):\r\n if lst[i][j] == '1' and count[j] == 1:\r\n flag = False\r\n if flag:\r\n print('YES')\r\n exit()\r\nprint('NO')\r\n", "n, m = map(int, input().split())\r\nswitch = []\r\nedges = 0\r\ninptr = [0] * m\r\nfor i in range(n):\r\n switch.append(list(input()))\r\n for j in range(m):\r\n if switch[i][j] != '0':\r\n inptr[j] += 1\r\n edges += switch[i].count('1')\r\nans = \"NO\"\r\nfor i in range(n):\r\n replaceble = True\r\n for j in range(m):\r\n if switch[i][j] != '0':\r\n if inptr[j] < 2:\r\n replaceble = False\r\n break\r\n if replaceble:\r\n ans = \"YES\"\r\n break\r\nprint(ans)\r\n", "import sys\r\nimport math,bisect\r\nsys.setrecursionlimit(10 ** 5)\r\nfrom itertools import groupby,accumulate\r\nfrom heapq import heapify,heappop,heappush\r\nfrom collections import deque,Counter,defaultdict\r\ndef I(): return int(sys.stdin.readline())\r\ndef neo(): return map(int, sys.stdin.readline().split())\r\ndef Neo(): return list(map(int, sys.stdin.readline().split()))\r\nn,m = neo()\r\nA = [input() for i in range(n)]\r\nf = 0\r\nB = [0]*m\r\nfor i in range(n):\r\n for j in range(m):\r\n if A[i][j] == '1':\r\n B[j] += 1\r\n#print(B) \r\nfor i in range(n):\r\n f = 0\r\n for j in range(m):\r\n if A[i][j] == '1' and B[j] <= 1:\r\n f = 1\r\n if f == 0:\r\n print('YES')\r\n exit()\r\nprint('NO') \r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\na = []\r\nc = [[] for _ in range(m)]\r\nfor j in range(n):\r\n a0 = list(input().rstrip())\r\n for i in range(m):\r\n if a0[i] == \"1\":\r\n c[i].append(j)\r\ns = set([i for i in range(n)])\r\nans = \"YES\"\r\nfor i in range(m):\r\n if len(c[i]) == 1:\r\n if c[i][0] in s:\r\n s.remove(c[i][0])\r\n elif not c[i]:\r\n ans = \"NO\"\r\nif not s:\r\n ans = \"NO\"\r\nprint(ans)", "n,m = map(int,input().split())\r\nl = []\r\nc = [0]*m\r\nfor i in range(n):\r\n x = input()\r\n l.append(x)\r\nfor i in range(n):\r\n for j in range(m):\r\n if(l[i][j]=='1'):\r\n c[j]+=1\r\nfor i in range(n):\r\n f = 1\r\n for j in range(m):\r\n if(l[i][j]=='1' and c[j]==1):\r\n f = 0\r\n if(f):\r\n print('YES')\r\n exit(0)\r\nprint('NO')", "n, m = map(int, input().split())\nsl = [input() for _ in range(n)]\ncounts = [0 for _ in range(m)]\nfor i in range(n):\n for j in range(m):\n if sl[i][j] == '1':\n counts[j] += 1\nans = 'NO'\nfor i in range(n):\n c = counts[:]\n for j in range(m):\n if sl[i][j] == '1':\n c[j] -= 1\n\n if all([i > 0 for i in c]):\n ans = 'YES' \n break\nprint(ans)", "n, m = map(int, input().split())\r\ntable = [input() for i in range(n)]\r\n\r\n\r\nd = {i: 0 for i in range(m)}\r\nfor row in table:\r\n for i, char in enumerate(row):\r\n d[i] += int(char)\r\n\r\nfor i in range(n):\r\n ok = True\r\n for j in range(m):\r\n if d[j] - int(table[i][j]) <= 0:\r\n ok = False\r\n break\r\n if ok:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")\r\n", "import sys\n\nn, m = [int(i) for i in input().split()]\nd = [0] * m\na = list()\nfor i in range(n):\n line = [int(k) for k in list(input())]\n for j in range(len(line)):\n if line[j] == 1:\n d[j] += 1\n a.append(line)\n\nfor i in range(n):\n line = a[i]\n need = False\n for j in range(len(line)):\n if d[j] - line[j] == 0:\n need = True\n break\n if not need:\n print(\"YES\")\n sys.exit()\n\nprint(\"NO\")\n", "n,m=[int(x) for x in input().split()]\r\nli=[]\r\nfor i in range(n):\r\n\tli.append(input())\r\naddlist=[]\r\nfor i in range(m):\r\n\tsum=0\r\n\tfor ii in range(n):\r\n\t\tsum+=int(li[ii][i])\r\n\taddlist.append(sum)\t\r\nfor i in range(n):\r\n\tcount=0\r\n\tfor ii in range(m):\r\n\t\tif li[i][ii]=='1' and addlist[ii]==1:\r\n\t\t\tcount=1\t\r\n\tif count==0:\r\n\t\tprint('YES')\r\n\t\tquit()\r\nprint('NO')\r\n", "input()\na = list(map(lambda s: int(s, 2), __import__('sys').stdin.readlines()))\nt = T = 0\nfor x in a:\n t |= T & x\n T |= x\nprint(['YES', 'NO'][all(x & (x ^ t) for x in a)])\n", "n, m = map(int, input().split())\r\na = [input() for i in range(n)]\r\n\r\n\r\nans = [0] * m\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] == \"1\":\r\n ans[j] += 1\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] == \"1\":\r\n if ans[j] - 1 == 0:\r\n break\r\n else: \r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\") \r\n", "n, m = input().split()\r\na = [[x for x in input()] for y in range(int(n))]\r\nlights = [0 for x in range(int(m))]\r\nind = []\r\nfor i in range(int(n)):\r\n for j in range(int(m)):\r\n lights [j] += int(a[i][j])\r\nk = 0\r\nfor i in range(int(n)):\r\n for j in range(int(m)):\r\n if int(a[i][j]) == 1:\r\n lights[j] -= 1\r\n ind.append(j)\r\n for elem in lights:\r\n if elem <= 0:\r\n k+=1\r\n if k >= 1:\r\n for elem in ind:\r\n lights[elem] += 1\r\n ind = []\r\n if k == 0:\r\n print('YES')\r\n exit()\r\n k = 0\r\nprint('NO')", "import sys\r\ninput = lambda :sys.stdin.readline()[:-1]\r\nni = lambda :int(input())\r\nna = lambda :list(map(int,input().split()))\r\nyes = lambda :print(\"yes\");Yes = lambda :print(\"Yes\");YES = lambda : print(\"YES\")\r\nno = lambda :print(\"no\");No = lambda :print(\"No\");NO = lambda : print(\"NO\")\r\n#######################################################################\r\nn,m = na()\r\na = [[int(i) for i in input()]for j in range(n)]\r\ns = [0]*m\r\nfor i in range(n):\r\n for j in range(m):\r\n s[j] += a[i][j]\r\n\r\nfor i in range(n):\r\n ok = 1\r\n for j in range(m):\r\n s[j] -= a[i][j]\r\n if s[j] == 0:\r\n ok = 0\r\n for j in range(m):\r\n s[j] += a[i][j]\r\n if ok:\r\n YES()\r\n exit()\r\nNO()\r\n", "n,m = map(int,input().split())\r\narr = [input() for i in range(n)]\r\n\r\ndic = dict()\r\n\r\nfor item in arr:\r\n for i,ch in enumerate(item):\r\n if ch=='1':\r\n if i not in dic: dic[i]=1\r\n else: dic[i]+=1\r\n\r\n \r\nans = -1\r\n\r\nfor item in arr:\r\n for i,ch in enumerate(item):\r\n if ch=='1':\r\n dic[i]-=1\r\n #print(item,dic)\r\n flag = True\r\n for key in dic:\r\n if dic[key]==0: \r\n flag=False\r\n if flag:\r\n ans = 1\r\n break\r\n for i,ch in enumerate(item):\r\n if ch=='1':\r\n dic[i]+=1\r\n \r\n\r\nif ans==1: print(\"YES\")\r\nelse: print(\"NO\")", "R = lambda: map(int, input().split())\r\nn,m = R()\r\nL = []\r\nfor i in range(n):\r\n L.append([int(i) for i in input()])\r\nT = [sum(L[j][i] for j in range(n)) for i in range(m)]\r\nfor i in range(n):\r\n c = 0\r\n for j in range(m):\r\n if T[j]-L[i][j] > 0:\r\n c += 1\r\n if c == m:\r\n print(\"YES\")\r\n quit()\r\nprint(\"NO\")", "n,m=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n\ts=input()\r\n\tl.append(int(s,2))\r\nnumber=2**m-1\r\n\r\nflag=False\r\nfor i in range(0,n):\r\n\tx=0\r\n\tfor j in range(0,n):\r\n\t\tif j==i:\r\n\t\t\tcontinue\r\n\t\tx=x|l[j]\r\n\tif x==number:\r\n\t\tflag=True\r\n\t\tbreak\r\nif flag:\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "line = input()\r\nnn = line.split()\r\nnSwitches = int(nn[0])\r\nnLamps = int(nn[1])\r\narr = []\r\nfound = False\r\nfor i in range(nSwitches):\r\n line = int(input(), 2)\r\n arr.append(line)\r\nignorerow = 0\r\nwhile ignorerow < nSwitches:\r\n result = 0\r\n for i in range (nSwitches):\r\n if (i == ignorerow):\r\n continue\r\n result = result | arr[i]\r\n ignorerow += 1\r\n if result == 0:\r\n continue\r\n if result == (2**nLamps)-1:\r\n print(\"YES\\n\")\r\n found = True\r\n break\r\nif not found:\r\n print(\"NO\\n\")\r\n ", "n,m=map(int,input().split())\r\nmat=[]\r\nans=\"NO\"\r\ncnt=[0]*(m+1)\r\nfor i in range(n):\r\n l=list(input())\r\n mat.append(l)\r\n for i in range(m):\r\n if l[i]=='1':\r\n cnt[int(i)]+=1 \r\n#print(cnt)\r\nfor i in range(n):\r\n f=1 \r\n for j in range(m):\r\n if mat[i][j]=='1' and cnt[int(j)]<=1 :\r\n f=0 \r\n if f==1:\r\n ans=\"YES\"\r\n break \r\nprint(ans)", "n,m = map(int, input().split())\r\nlamps = dict()\r\nrow = list()\r\nfor i in range(m):\r\n lamps[i]=0\r\nfor i in range(n):\r\n nhap = input()\r\n row.append(nhap)\r\n for a,b in enumerate(nhap):\r\n if b == '1':\r\n lamps[a]+=1\r\n\r\nfor i in row:\r\n for id,j in enumerate(i):\r\n if j == '1':\r\n if lamps[id]<=1:\r\n break\r\n else:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")", "while True:\r\n\ttry:\r\n\t\tdef solution(n, m):\r\n\t\t\tcnt =[0]*(m)\r\n\t\t\tlights = []\r\n\t\t\tfor i in range(n):\r\n\t\t\t\ta = input()\r\n\t\t\t\tfor j in range(m):\r\n\t\t\t\t\tif a[j] == '1':\r\n\t\t\t\t\t\tcnt[j] += 1\r\n\t\t\t\tlights.append(a)\r\n\t\t\thas=\"NO\"\r\n\t\t\tfor i in range(n):\r\n\t\t\t\thas = \"NO\"\r\n\t\t\t\tcunt = 0\r\n\t\t\t\tfor j in range(m):\r\n\t\t\t\t\tif lights[i][j] == '1' and cnt[j] >1:\r\n\t\t\t\t\t\thas= \"YES\"\r\n\t\t\t\t\t\tcunt += 1\r\n\t\t\t\t\telif lights[i][j]=='1':\r\n\t\t\t\t\t\thas = \"NO\"\r\n\t\t\t\t\t\tcunt += 1\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\tif (has == \"YES\" ) or cunt ==0:\r\n\t\t\t\t\tprint(\"YES\")\r\n\t\t\t\t\treturn\r\n\t\t\tprint(has)\r\n\t\t\t\t\r\n\t\t\t\t\t\t\r\n\t\t\r\n\t\tdef read():\r\n\t\t\tn, m = map(int,input().split())\r\n\t\t\tsolution(n, m)\r\n\t\t\t\r\n\t\tif __name__ == \"__main__\":\r\n\t\t\tread()\r\n\texcept EOFError:\r\n\t\tbreak", "#!/usr/bin/env python3\n#-*- encoding:utf-8 -*-\n\nimport sys\n\ndef main():\n n,m = map(int,sys.stdin.readline().split())\n grid = [[int(x)for x in sys.stdin.readline().strip()] for _ in range(n)]\n res = [0 for _ in range(m)]\n\n for j in range(m):\n res[j] = sum([grid[i][j] for i in range(n)])\n\n for i in range(n):\n ok = True\n for j in range(m):\n if res[j] == 1 and grid[i][j]:\n ok = False\n if ok:\n print('YES')\n return\n\n print('NO')\n\nmain()\n", "def main():\r\n n, m = map(int, input().split())\r\n switches = [list(map(int, input())) for _ in range(n)]\r\n counts = list(map(sum, zip(*switches)))\r\n\r\n for switch in switches:\r\n unnecessary = True\r\n\r\n for i in range(m):\r\n if switch[i] and counts[i] < 2:\r\n unnecessary = False\r\n break\r\n\r\n if unnecessary:\r\n print(\"YES\")\r\n return\r\n\r\n print(\"NO\")\r\n\r\n\r\nmain()\r\n", "import sys\n\n\ndef solve():\n\n matrix = []\n\n first = True\n\n for line in sys.stdin:\n if not first:\n matrix.append(line.rstrip())\n first = False\n\n n, m = len(matrix), len(matrix[0])\n cnts = [0] * m\n\n for i in range(n):\n for j in range(m):\n if matrix[i][j] == '1':\n cnts[j] += 1\n\n for i in range(n):\n works = True\n\n for j in range(m):\n if matrix[i][j] == '1' and cnts[j] == 1:\n works = False\n break\n\n if works:\n return True\n\n return False\n\n\nif solve():\n print(\"YES\", end=\"\")\nelse:\n print(\"NO\", end=\"\")\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\ng = [input() for _ in range(n)]\r\nc = [sum(map(int, col)) for col in zip(*g)]\r\n\r\nfor r in g:\r\n if all(c[i] > 1 for i, on in enumerate(r) if on == '1'):\r\n print('YES')\r\n break\r\nelse:\r\n print('NO')\r\n", "n,m=map(int,input().split())\r\na=[]\r\nfor _ in range(n):\r\n c=list(input())\r\n a.append(c)\r\naa=[]\r\nfor i in range(m):\r\n x=0\r\n for j in range(n):\r\n x+=int(a[j][i])\r\n aa.append(x)\r\nf=False\r\nx=[0]*n\r\nfor i in range(n):\r\n for j in range(m):\r\n flag=False \r\n if(a[i][j]=='1'):\r\n if(aa[j]==1):\r\n flag=True\r\n x[i]=1\r\n break\r\n if(flag):break \r\nif x.count(0)!=0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n, m = list(map(int, input().split()))\nmatrix = []\nfor i in range(n):\n matrix.append(eval(\"0b\" + input()))\nfor i in range(n):\n res = 0\n for j in range(n):\n if j != i:\n res |= matrix[j]\n if res == (1<<m)-1:\n print(\"YES\")\n break\nelse:\n print(\"NO\")\n", "if __name__ == '__main__':\r\n cin = input\r\n n, m = map(int, cin().split())\r\n s, l, f = [[] for _ in range(n)], [0] * m, 0\r\n\r\n for i in range(n):\r\n t = cin()\r\n for j in range(m):\r\n if t[j] == \"1\":\r\n l[j] += int(t[j])\r\n s[i].append(j)\r\n for i in range(n):\r\n r = set(l[c] - 1 for c in s[i])\r\n if not 0 in r:\r\n f = not f\r\n break\r\n print(\"YNEOS\"[not f::2])", "import sys,math,itertools\r\nfrom collections import Counter,deque,defaultdict\r\nfrom bisect import bisect_left,bisect_right \r\nfrom heapq import heappop,heappush,heapify, nlargest\r\nfrom copy import deepcopy\r\nmod = 10**9+7\r\nINF = float('inf')\r\ndef inp(): return int(sys.stdin.readline())\r\ndef inpl(): return list(map(int, sys.stdin.readline().split()))\r\ndef inpl_1(): return list(map(lambda x:int(x)-1, sys.stdin.readline().split()))\r\ndef inps(): return sys.stdin.readline()\r\ndef inpsl(x): tmp = sys.stdin.readline(); return list(tmp[:x])\r\ndef err(x): print(x); exit()\r\n\r\nn,m = inpl()\r\ns = [inpsl(m) for _ in range(n)]\r\nlampcnt = [0]*m\r\nfor i in range(n):\r\n for j in range(m):\r\n if s[i][j] == '1':\r\n lampcnt[j] += 1\r\nres = False\r\nfor i in range(n):\r\n only = False\r\n for j in range(m):\r\n if s[i][j] == '1' and lampcnt[j] == 1:\r\n only = True\r\n if not only: res = True\r\nprint('YES' if res else 'NO')", "import math\r\n\r\n\r\n\r\ndef main_function():\r\n n, m = [int(i) for i in input().split(\" \")]\r\n matrix = [input() for i in range(n)]\r\n lambs = [0 for i in range(m)]\r\n is_ans_found = False\r\n for i in matrix:\r\n for j in range(len(i)):\r\n lambs[j] += int(i[j])\r\n is_good = []\r\n for i in range(len(lambs)):\r\n if lambs[i] == 0:\r\n is_ans_found = True\r\n print(\"NO\")\r\n break\r\n elif lambs[i] == 1:\r\n is_good.append(False)\r\n else:\r\n is_good.append(True)\r\n for i in range(n):\r\n can_be_out = True\r\n for j in range(m):\r\n if matrix[i][j] == \"1\" and is_good[j] == False:\r\n can_be_out = False\r\n break\r\n if can_be_out:\r\n print(\"YES\")\r\n is_ans_found = True\r\n break\r\n if not is_ans_found:\r\n print(\"NO\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nmain_function()", "great = [0] * 2000\r\n\r\ndef con(s):\r\n\tfor i in range(len(s)):\r\n\t\tgreat[i] += int(s[i])\r\n\treturn s\r\n\r\nn, m = [int(i) for i in input().split()]\r\narr = [con(input()) for i in range(n)]\r\n\r\nfor i in range(n):\r\n\tfor j in range(m):\r\n\t\tif arr[i][j] == '1' and great[j] == 1:\r\n\t\t\tbreak\r\n\telse:\r\n\t\tprint(\"YES\")\r\n\t\texit()\r\n\r\nprint(\"NO\")", "a,b=map(int,input().split())\r\nz=[]\r\nfor i in range(b):z.append([])\r\no=set(range(a))\r\nfor i in range(a):\r\n k=input()\r\n for j in range(b):\r\n if k[j]=='1':\r\n z[j]+=[i]\r\nfor i in range(b):\r\n if len(z[i])==1:o-={z[i][0]}\r\nprint(\"YES\" if o else \"NO\")", "switchCount,lampCount = tuple(map(int,input().split()))\r\nswitches = []\r\nfor i in range(switchCount):\r\n switches.append(int(input(),2))\r\ndef canSwitchOnWithout(index):\r\n bitwiseOr = 0\r\n for i in range(switchCount):\r\n if i !=index:\r\n bitwiseOr = bitwiseOr | switches[i]\r\n return bitwiseOr\r\nlampsOn,index,exists = int('1'*lampCount,2),0,False\r\nwhile not exists and index<switchCount:\r\n if canSwitchOnWithout(index) == lampsOn:\r\n exists = not exists\r\n else: index = index + 1\r\nprint('YES') if exists else print('NO')\r\n", "n,m=map(int,input().split())\r\nar=[]\r\nfor i in range(n):\r\n ar.append(list(map(int,list(input()))))\r\nbr=[0]*m\r\nfor i in range(n):\r\n for j in range(m):\r\n br[j]+=ar[i][j]\r\nflag=False\r\nfor i in range(n):\r\n f1=True\r\n for j in range(m):\r\n if(ar[i][j]==1 and br[j]==1):\r\n f1=False\r\n break\r\n if(f1):\r\n flag=True\r\n break\r\nif(flag):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "# https://codeforces.com/contest/985/problem/B\r\n\r\nn,m = map(int, input().split())\r\nlamp_swt = [[] for _ in range(m)] # stores switches that can turn on each light \r\nfor i in range(n):\r\n s = input()\r\n for j in range(m):\r\n if s[j]=='1':\r\n lamp_swt[j].append(i)\r\n# print(lamp_swt)\r\nneeded = [False for _ in range(n)]\r\nfor j in range(m):\r\n if len(lamp_swt[j]) == 1:\r\n needed[lamp_swt[j][0]] = True\r\n# print(needed)\r\nans = \"NO\"\r\nfor x in needed:\r\n if x==False:\r\n ans = \"YES\"\r\n break\r\nprint(ans)\r\n", "n,m=map(int,input().split())\r\ncnt = [0]*m\r\ns = [input() for x in range(n)]\r\nfor i,x in enumerate(zip(*s)):\r\n for j in x:\r\n if j=='1':\r\n cnt[i]+=1\r\nfor i,x in enumerate(s):\r\n d=1\r\n for j,l in enumerate(x):\r\n if l=='1':\r\n if cnt[j]-1==0:\r\n d=0\r\n break\r\n if d==1:\r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\")\r\n", "n, m = map(int, input().split())\r\nmasks = []\r\nfor i in range(n):\r\n masks.append(int(input(), 2))\r\nfor i in range(n):\r\n ms = 0\r\n for j in range(n):\r\n if i != j:\r\n ms |= masks[j]\r\n if ms + 1 == 1 << m:\r\n print(\"YES\")\r\n exit(0)\r\nprint(\"NO\")\r\n", "n,m=[int(x) for x in input().split()]\r\na=[]\r\nfor i in range(n):\r\n s=input()\r\n a.append(s)\r\n \r\n\r\ntt=[]\r\nfor i in range(m):\r\n k=[]\r\n for j in range(n):\r\n if(a[j][i]=='1'):\r\n k.append(j)\r\n tt.append(list(set(k)))\r\n\r\n\r\n\r\n\r\nss=[]\r\n\r\n\r\nfor i in tt:\r\n if(len(i)==1):\r\n ss.append(i[0])\r\nss=set(ss)\r\n\r\nif(len(ss)==n):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n \r\n \r\n", "n,m=map(int,input().split())\r\na=[int(input(),2)for _ in range(n)]\r\n \r\ns=t=0\r\nfor x in a:\r\n t|=s&x\r\n s|=x\r\nprint(('YES','NO')[all(x&s&~t for x in a)])", "def main():\n n, m = map(int, input().split())\n f, ll = [0] * m, []\n for _ in range(n):\n l = []\n ll.append(l)\n for i, c in enumerate(input()):\n if c == '1':\n f[i] += 1\n l.append(i)\n for l in ll:\n if min((f[i] for i in l), default=2) > 1:\n print('YES')\n return\n print('NO')\n\n\nif __name__ == '__main__':\n main()\n", "n,m = map(int,input().split())\r\na = []\r\ncnt = [0 for i in range(m)]\r\nfor i in range(n):\r\n\ta.append(input())\r\n\tfor j in range(m):\r\n\t\tif(a[i][j]=='1'):\r\n\t\t\tcnt[j]+=1;\r\nflag = False\r\nfor i in range(n):\r\n\ttemp = True\r\n\tfor j in range(m):\r\n\t\tif(a[i][j]=='1' and not cnt[j]>1):\r\n\t\t\ttemp = False\r\n\t\t\tbreak\r\n\tif(temp):\r\n\t\tflag = True\r\n\t\tbreak\r\nif(flag):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\r\n", "nn,mm=list(map(int,input().split()))\r\nlamps={}\r\ndata=[]\r\nfor n in range(nn):\r\n pp=input()\r\n data.append(pp)\r\n for (i,p) in enumerate(pp):\r\n if p=='1':\r\n try:\r\n lamps[i]+=1\r\n except:\r\n lamps[i]=1\r\n\r\nlamps={x:y for x,y in lamps.items() if y==1}\r\n#print(lamps)\r\n#print(data)\r\n\r\nfor pp in data:\r\n maybe='YES'\r\n for (i,p) in enumerate(pp):\r\n if p=='1':\r\n try:\r\n lamps[i]\r\n maybe='NO'\r\n break\r\n except:\r\n pass\r\n if maybe=='YES':\r\n break\r\nprint(maybe)\r\n", "def gs(v,n,m):\r\n\trv=[0 for x in range(m)]\r\n\tfor c in range(m):\r\n\t\tfor d in range(n):\r\n\t\t\trv[c]+=v[d][c]\r\n\treturn rv\r\n\t\r\ndef gn(v,n,m):\r\n\tsv=gs(v,n,m)\r\n\tfor c in range(n):\r\n\t\tb=0\r\n\t\tfor d in range(m):\r\n\t\t\tif v[c][d] and sv[d]==1:\r\n\t\t\t\tb=1\r\n\t\t\t\tbreak\r\n\t\tif b:\r\n\t\t\tcontinue\r\n\t\treturn c+1\r\n\treturn 0\r\n\t\r\nn,m=[int(x) for x in input().split()]\r\nv=[]\r\nfor c in range(n):\r\n\tv.append([int(x) for x in input()])\r\nrs='NO'\r\nif gn(v,n,m):\r\n\trs='YES'\r\nprint(rs)", "n,m=map(int,input().split())\r\na=[]\r\nb=[0]*m\r\nfor i in range(n):\r\n s=input()\r\n for j in range(m):\r\n if s[j]=='1':\r\n b[j]+=1\r\n a.append(s)\r\nans=\"NO\"\r\nfor i in range(n):\r\n s=a[i]\r\n flag=True\r\n for j in range(m):\r\n if s[j]=='1':\r\n if b[j]<=1:\r\n flag=False\r\n break\r\n if flag==True:\r\n ans=\"YES\"\r\n break\r\nprint(ans)\r\n\r\n \r\n", "[n, m] = [int(i) for i in input().split()]\r\nA = []\r\nfor i in range(n):\r\n\tA.append(input())\r\n\r\nans = n\r\nht = {}\r\nfor i in range(n):\r\n\tht[i] = True\r\n\r\nfor j in range(m):\r\n\tok = 2\r\n\tfor i in range(n):\r\n\t\tif A[i][j] == \"1\":\r\n\t\t\tif ok == 2:\r\n\t\t\t\tpos = i\r\n\t\t\t\tok -= 1\r\n\t\t\telse:\r\n\t\t\t\tok -= 1\r\n\t\t\t\tbreak\r\n\tif ok == 1:\r\n\t\tht[pos] = False\r\n\r\nmsg = \"NO\"\r\nfor i in range(n):\r\n\tif ht[i]:\r\n\t\tmsg = \"YES\"\r\n\r\nprint(msg)\r\n\r\n\r\n\r\n", "n,m=map(int,input().split())\r\nl=[]\r\ncnt=[0 for i in range(m)]\r\nfor i in range(n):\r\n s=input()\r\n l.append(s)\r\n for j in range(m):\r\n if s[j]=='1':\r\n cnt[j]+=1\r\nc=0\r\nfor i in l:\r\n ok=True\r\n for j in range(m):\r\n if i[j]=='1' and cnt[j]==1:\r\n ok=False\r\n break\r\n if ok:\r\n print(\"YES\")\r\n c=1\r\n break\r\nif not c:\r\n print(\"NO\")\r\n \r\n", "from collections import deque\r\n\r\n\r\ndef main():\r\n n, m = map(int, input().split())\r\n\r\n switches = deque()\r\n status = [0] * m\r\n\r\n for _ in range(n):\r\n s = input()\r\n sw = set()\r\n\r\n for i, ch in enumerate(s):\r\n if ch == '1':\r\n sw.add(i)\r\n status[i] += 1\r\n\r\n switches.append(sw)\r\n\r\n for sw in switches:\r\n if len(sw) == 0:\r\n print(\"YES\")\r\n return\r\n ok = True\r\n for i in sw:\r\n if status[i] <= 1:\r\n ok = False\r\n break\r\n if ok:\r\n print(\"YES\")\r\n return\r\n\r\n print(\"NO\")\r\n\r\n\r\nmain()\r\n", "n, m = [int(i) for i in input().split()]\r\na = []\r\nfor i in range(n):\r\n a.append(list(input()))\r\n\r\ns = [0] * m\r\nfor i in range(m):\r\n for j in range(n):\r\n if a[j][i] == \"1\":\r\n s[i] += 1\r\n\r\nfor i in range(n):\r\n f = True\r\n for j in range(m):\r\n if s[j] - int(a[i][j]) == 0:\r\n f = False\r\n break\r\n if f:\r\n print(\"YES\")\r\n quit()\r\nprint(\"NO\")\r\n", "r, c = map(int, input().split())\r\nswitchdata = [0 for i in range(c)]\r\ndata = [input() for i in range(r)]\r\nfor i in range(r):\r\n for j in range(c):\r\n if data[i][j] == '1':\r\n switchdata[j] += 1\r\n\r\npossible = False\r\nfor i in range(r):\r\n for j in range(c):\r\n if switchdata[j] - int(data[i][j]) == 0:\r\n break\r\n if j == c-1 and switchdata[j] - int(data[i][j]) > 0:\r\n possible = True\r\n if possible:\r\n break\r\nprint('YES' if possible else 'NO')" ]
{"inputs": ["4 5\n10101\n01000\n00111\n10000", "4 5\n10100\n01000\n00110\n00101", "1 5\n11111", "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1", "1 1\n1", "3 4\n1010\n0100\n1101", "2 5\n10101\n11111", "5 5\n10000\n11000\n11100\n11110\n11111", "2 5\n10000\n11111", "4 5\n01000\n10100\n00010\n10101", "2 2\n10\n11", "2 5\n00100\n11111", "4 5\n00000\n11000\n00110\n00011", "4 3\n000\n010\n001\n100", "4 5\n10000\n10101\n01000\n00111", "4 5\n10000\n01000\n10101\n00111", "2 2\n01\n11", "3 3\n010\n101\n000", "2 2\n11\n00", "3 5\n10110\n11000\n00111", "3 8\n00111111\n01011100\n11000000", "4 6\n100000\n110000\n001100\n000011", "2 5\n11111\n00000", "2 3\n101\n111", "2 5\n01000\n11111", "2 2\n00\n11", "4 15\n111110100011010\n111111011010110\n101000001011001\n100110000111011", "2 3\n010\n111", "4 5\n10100\n11000\n00110\n00101", "4 4\n1111\n0000\n0000\n0000", "3 5\n11100\n00110\n00011", "2 1\n0\n1", "4 4\n1000\n1001\n0010\n0100", "3 5\n00110\n10011\n01100", "3 5\n10101\n00111\n01000", "4 5\n00101\n00011\n01000\n10010", "3 3\n100\n110\n111", "2 2\n11\n01", "3 3\n100\n100\n111", "4 2\n10\n01\n10\n01", "3 3\n111\n000\n000", "3 3\n010\n100\n011", "2 3\n111\n000", "3 4\n0001\n1101\n1010", "3 4\n1010\n0101\n1000", "3 4\n0001\n1101\n0110", "3 3\n111\n101\n001", "4 5\n10001\n10010\n01010\n00101", "3 3\n000\n000\n111", "2 3\n100\n111", "3 10\n1111011100\n0001100011\n1111010101", "3 4\n0110\n1010\n0101", "3 3\n100\n001\n011", "3 3\n100\n010\n001", "3 3\n010\n100\n001", "3 5\n10101\n01010\n01010", "2 6\n111111\n000000", "3 5\n00000\n10101\n01010", "4 6\n111000\n100100\n010010\n001001"], "outputs": ["YES", "NO", "NO", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "YES", "YES", "YES", "YES"]}
UNKNOWN
PYTHON3
CODEFORCES
99
13ced2a3d8b5a62401f7b011c2f5576b
Simba on the Circle
You are given a circular array with *n* elements. The elements are numbered from some element with values from 1 to *n* in clockwise order. The *i*-th cell contains the value *a**i*. The robot Simba is in cell *s*. Each moment of time the robot is in some of the *n* cells (at the begin he is in *s*). In one turn the robot can write out the number written in current cell or move to the adjacent cell in clockwise or counterclockwise direction. To write out the number from the cell Simba doesn't spend any time, but to move to adjacent cell Simba spends one unit of time. Simba wants to write the number from each cell one time, so the numbers will be written in a non decreasing order. Find the least number of time units to write out all numbers. The first line contains two integers *n* and *s* (1<=≤<=*s*<=≤<=*n*<=≤<=2000) — the number of cells in the circular array and the starting position of Simba. The second line contains *n* integers *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the number written in the *i*-th cell. The numbers are given for cells in order from 1 to *n*. Some of numbers *a**i* can be equal. In the first line print the number *t* — the least number of time units. Each of the next *n* lines should contain the direction of robot movement and the number of cells to move in that direction. After that movement the robot writes out the number from the cell in which it turns out. The direction and the number of cells should be printed in the form of +x in case of clockwise movement and -x in case of counterclockwise movement to *x* cells (0<=≤<=*x*<=≤<=*n*<=-<=1). Note that the sum of absolute values of *x* should be equal to *t*. Sample Input 9 1 0 1 2 2 2 1 0 1 1 8 1 0 1 0 1 0 1 0 1 8 1 1 2 3 4 5 6 7 8 8 1 0 0 0 0 0 0 0 0 Sample Output 12 +0 -3 -1 +2 +1 +2 +1 +1 +1 13 +0 +2 +2 +2 -1 +2 +2 +2 7 +0 +1 +1 +1 +1 +1 +1 +1 7 +0 +1 +1 +1 +1 +1 +1 +1
[ "import os\r\nfrom re import M\r\nimport sys \r\nfrom io import BytesIO, IOBase\r\n \r\nBUFSIZE = 8192\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\ndef solve():\r\n n, s = map(int, input().split())\r\n A = list(map(int, input().split()))\r\n s -= 1\r\n se = set(A)\r\n dic = {l:i for i, l in enumerate(sorted(se))}\r\n le = len(se)\r\n A = [dic[a] for a in A]\r\n lst = [[] for _ in range(le + 1)]\r\n for i, a in enumerate(A):\r\n lst[a + 1].append(i)\r\n lst[0] = [s]\r\n dp = [[] for _ in range(le + 1)]\r\n bef = [[] for _ in range(le + 1)]\r\n dp[0] = [0]\r\n inf = 1 << 30\r\n for ii in range(le):\r\n l1 = lst[ii]\r\n l2 = lst[ii + 1]\r\n le1 = len(l1)\r\n le2 = len(l2)\r\n bdp = dp[ii]\r\n ndp = [inf] * le2\r\n bef_ = [None] * le2\r\n if le2 == 1:\r\n for i in range(le1):\r\n tmp = abs(l1[i] - l2[0])\r\n tmp = min(tmp, n - tmp)\r\n d = bdp[i] + tmp\r\n if d < ndp[0]:\r\n ndp[0] = d\r\n bef_[0] = i\r\n else:\r\n for i in range(le1):\r\n for j in range(le2):\r\n tmp = abs(l1[i] - l2[j])\r\n tmp = min(tmp, n - tmp)\r\n d = bdp[i] + tmp\r\n if j == 0:\r\n dd = d + l2[le2 - 1] - l2[j]\r\n if dd < ndp[le2 - 1]:\r\n ndp[le2 - 1] = dd\r\n bef_[le2 - 1] = (i, 0)\r\n else:\r\n dd = d + n - (l2[j] - l2[j - 1])\r\n if dd < ndp[j - 1]:\r\n ndp[j - 1] = dd\r\n bef_[j - 1] = (i, 0)\r\n \r\n if j == le2 - 1:\r\n dd = d + l2[j] - l2[0]\r\n if dd < ndp[0]:\r\n ndp[0] = dd\r\n bef_[0] = (i, 1)\r\n else:\r\n dd = d + n - (l2[j + 1] - l2[j])\r\n if dd < ndp[j + 1]:\r\n ndp[j + 1] = dd\r\n bef_[j + 1] = (i, 1)\r\n\r\n dp[ii + 1] = ndp\r\n bef[ii + 1] = bef_\r\n min_ = 1 << 30\r\n t = -1\r\n for i, d in enumerate(dp[-1]):\r\n if d < min_:\r\n min_ = d\r\n t = i\r\n \r\n print(min_)\r\n ans = []\r\n for i in range(le, 0, -1):\r\n if type(bef[i][t]) == int:\r\n j = bef[i][t]\r\n tmp = lst[i][t] - lst[i - 1][j]\r\n if tmp < 0:\r\n tmp += n\r\n if tmp <= n - tmp:\r\n ans.append(f\"+{tmp}\")\r\n else:\r\n ans.append(f\"-{n - tmp}\")\r\n t = j\r\n else:\r\n j, k = bef[i][t]\r\n l = len(lst[i])\r\n if k == 1:\r\n r = t + 1\r\n if r == l:\r\n r = 0\r\n for _ in range(l - 1):\r\n d = lst[i][r] - lst[i][t]\r\n if d < 0:\r\n d += n\r\n ans.append(f\"-{d}\")\r\n t = r\r\n r = t + 1\r\n if r == l:\r\n r = 0\r\n else:\r\n r = t - 1\r\n if r == -1:\r\n r = l - 1\r\n for _ in range(l - 1):\r\n d = lst[i][t] - lst[i][r]\r\n if d < 0:\r\n d += n\r\n ans.append(f\"+{d}\")\r\n t = r\r\n r = t - 1\r\n if r == -1:\r\n r = l - 1\r\n \r\n tmp = lst[i][t] - lst[i - 1][j]\r\n if tmp < 0:\r\n tmp += n\r\n if tmp <= n - tmp:\r\n ans.append(f\"+{tmp}\")\r\n else:\r\n ans.append(f\"-{n - tmp}\")\r\n t = j\r\n \r\n\r\n print(*ans[::-1], sep=\"\\n\")\r\n \r\n\r\n \r\nfor _ in range(1):\r\n solve() \r\n " ]
{"inputs": ["9 1\n0 1 2 2 2 1 0 1 1", "8 1\n0 1 0 1 0 1 0 1", "8 1\n1 2 3 4 5 6 7 8", "8 1\n0 0 0 0 0 0 0 0", "8 1\n0 1 2 2 1 0 1 1", "1 1\n4", "10 1\n-1 0 1 0 -1 1 0 0 1 -1", "20 7\n0 6 0 0 0 -7 -8 9 -7 4 7 2 -4 4 -5 2 6 8 -2 -7", "30 13\n68 50 99 23 84 23 24 -42 82 36 -10 -51 -96 96 19 -4 4 -41 74 92 13 58 26 79 -11 38 -80 -38 73 -21", "40 1\n886 -661 499 -14 -101 660 -259 -499 -766 155 -120 -112 -922 979 36 528 593 653 409 -476 -125 183 -817 59 353 16 525 -43 -388 989 306 -145 935 -712 -243 460 -861 339 347 -445", "50 32\n2624 -8355 -5993 -1 8197 382 -9197 -5078 -7 -1021 -4419 8918 -7114 5016 1912 -8436 -1217 2178 -6513 -9910 -1695 7501 7028 -6171 9063 9112 9063 -1886 9156 -7256 8871 -6855 7059 -5209 2308 5964 -4283 2248 1790 -6658 2906 -478 -5663 -9250 4355 1099 1468 -3051 -9353 -5717", "60 32\n58726 58267 -31806 44691 -52713 -11475 61179 83630 93772 48048 -64921 -16810 -16172 -30820 30109 -81876 -27921 -69676 -28393 -45495 6588 -30154 21312 50563 22336 -37995 -31034 -30980 -72408 -29962 -4891 24299 8648 -69415 -62580 95513 -13691 -92575 -10376 40008 2041 -24616 -6934 -42025 68949 -87961 -91709 -46669 -36624 -75601 -83110 43195 86628 53287 -14813 -7263 -20579 -51021 37654 -13428"], "outputs": ["12\n+0\n-3\n-1\n+2\n+1\n+2\n+1\n+1\n+1", "13\n+0\n+2\n+2\n+2\n-1\n+2\n+2\n+2", "7\n+0\n+1\n+1\n+1\n+1\n+1\n+1\n+1", "7\n+0\n+1\n+1\n+1\n+1\n+1\n+1\n+1", "11\n+0\n-3\n-1\n+2\n+1\n+2\n+1\n+1", "0\n+0", "22\n+0\n-1\n-5\n-3\n+2\n+3\n+1\n+1\n-3\n-3", "83\n+0\n+2\n-3\n-6\n-5\n-2\n+6\n+2\n+2\n+1\n+1\n+7\n+4\n-2\n-4\n-8\n-5\n-6\n+7\n+10", "238\n+0\n+14\n+15\n-4\n+10\n+10\n+2\n-5\n-14\n+5\n+1\n+4\n-6\n-11\n+2\n+1\n-14\n-13\n-14\n+6\n-10\n+9\n-2\n-10\n+5\n+15\n-4\n+15\n-6\n-11", "437\n+12\n-16\n-14\n-14\n-15\n+8\n+6\n+12\n+20\n-11\n+18\n-12\n-3\n-11\n-10\n+1\n-7\n-17\n+16\n-18\n-11\n+9\n-14\n+12\n+9\n+7\n+1\n-14\n-6\n+17\n+7\n-16\n-11\n+1\n+1\n-12\n-5\n-8\n-19\n+16", "601\n-12\n-21\n-5\n+13\n+9\n-14\n-22\n-17\n+19\n+8\n-21\n+5\n-21\n-3\n-7\n-9\n+24\n+3\n-24\n+11\n-20\n-7\n-4\n-7\n-18\n+17\n-5\n+2\n-10\n+1\n-8\n-24\n+3\n+20\n-3\n+16\n-10\n+4\n+19\n+22\n-13\n+10\n-11\n-17\n-24\n-19\n+13\n+2\n-1\n+3", "884\n+6\n+9\n-1\n+5\n+25\n-26\n-21\n-11\n+16\n-23\n+24\n+30\n-7\n-10\n-28\n+24\n-18\n+23\n+14\n+24\n+1\n-14\n+8\n+8\n-11\n-2\n+25\n+15\n+15\n+1\n-18\n-18\n+23\n+6\n-27\n+17\n-13\n-12\n+10\n-20\n+12\n-10\n+2\n+7\n-17\n-16\n-19\n+12\n+12\n+6\n+14\n+30\n+8\n-1\n+6\n-22\n+23\n-15\n+16\n+27"]}
UNKNOWN
PYTHON3
CODEFORCES
1
13d695394072750e82992d500f1bcc2c
Garden
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding. The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively. The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. Print one integer number — the minimum number of hours required to water the garden. Sample Input 3 6 2 3 5 6 7 1 2 3 4 5 6 Sample Output 2 7
[ "def f():\r\n num,k=map(int,input().split())\r\n n=map(int, input().split())\r\n maxi=0\r\n ans=0\r\n for i in n:\r\n if(k%i==0 and i>maxi):\r\n maxi=i \r\n ans=int(k/i)\r\n \r\n print(ans)\r\nf()", "# LUOGU_RID: 101738100\nn, k, *a = map(int, open(0).read().split())\r\nprint(min(k // x for x in a if k % x == 0))", "# https://vjudge.net/contest/364837#problem/B\nn, k = map(lambda x: int(x), input().split(' '))\nbuckets = list(map(lambda x: int(x), input().split(' ')))\n\nbuckets = sorted(buckets, reverse=True)\nfor b in buckets:\n if k % b == 0:\n print(int(k/b))\n break\n\n \t \t \t\t \t\t \t\t \t \t\t\t\t\t\t\t\t \t \t", "a=lambda:map(int,input().split());b,c=a();print(min(c//i for i in sorted(list(a()),reverse=True) if c%i==0))", "#nacitanie vstupu\r\npocet_n,velkost_k=list(map(int,input().split()))\r\njednotlive_hodnoty=list(map(int,input().split()))\r\nnajvacsie_k=-1\r\n#for loop s ifom\r\nfor hodnota in jednotlive_hodnoty:\r\n if velkost_k%hodnota==0 and hodnota>najvacsie_k:\r\n najvacsie_k=hodnota\r\n\r\n#vypocitanie vysledku\r\nvystup=velkost_k//najvacsie_k\r\n\r\n#vystup\r\nprint(vystup)", "x, y = input().split()\r\ny = int(y)\r\nxy = []\r\nxy.extend(input().split())\r\ncope = []\r\nfor i in xy :\r\n i = int(i)\r\n if y % i == 0 :\r\n cope.append(y / i)\r\n else:\r\n continue\r\nprint(int(min(cope)))", "n, k = map(int, input().split())\narr = list(map(int, input().split()))\n\narr.sort(reverse=True)\n\nfor i in arr:\n if k % i == 0:\n print(k // i)\n exit(0)\n", "n,k = map(int, input().split())\r\na = list(map(int,input().split()))\r\na.sort()\r\nfor i in a[::-1]:\r\n if k%i == 0:\r\n print(k//i)\r\n break", "buckets, gard_length = list(map(int, input().split()))\nlen_per_hour = list(map(int, input().split()))\nmaximum = 0\nfor i in range(len(len_per_hour)):\n if len_per_hour[i] > maximum and gard_length % len_per_hour[i] == 0:\n maximum = len_per_hour[i]\nprint(gard_length // maximum)\n", "a=[int(q) for q in input().strip().split()]\r\nb=[int(q) for q in input().strip().split()]\r\nmin=200\r\nfor k in range(a[0]):\r\n if a[1]%b[k]==0:\r\n if a[1]/b[k]<min:\r\n min=a[1]/b[k]\r\nprint(int(min))", "\"\"\"\nNome: Stefano Lopes Chiavegatto\nRA: 1777224\n\"\"\"\n\nnum_tam = input()\nbaldes = input()\n\nlista_num_tam = num_tam.split(\" \")\ntam = int(lista_num_tam[1])\n\nlista_baldes = baldes.split(\" \")\n\ntam_baldes = [tam/int(i) for i in lista_baldes if (tam%int(i) == 0)]\n\nprint(int(min(tam_baldes)))\n \t \t \t \t\t\t \t \t \t \t \t\t \t\t\t\t", "num_buck, k = [int(x) for x in input().split()]\r\nnums = [int(num) for num in input().split()]\r\nmx = 0\r\n\r\nfor i in range(num_buck):\r\n if k % nums[i] == 0:\r\n mx = max(mx, nums[i])\r\n\r\nprint(int(k / mx))\r\n", "buckets, length = map(int,input().split())\r\ndata = list(map(int,input().split()))\r\ndata.sort(reverse=True)\r\nfor element in data:\r\n if length % element == 0:\r\n print(length // element)\r\n break", "_, leng = map(int, input().split())\r\nnumbs = map(int, input().split())\r\nfor numb in sorted(numbs, reverse=True):\r\n if leng % numb == 0:\r\n print(leng // numb)\r\n break", "n,k = map(int,input().split())\r\nl = list(map(int,input().split()))\r\nans = 100\r\nfor i in range(n):\r\n if k % l[i] == 0:\r\n ans = min(ans,k//l[i])\r\nprint(ans)", "n, k = map(int, input().split())\r\n\r\na = list(map(int, input().split()))\r\ncur = 0;\r\nfor i in range(n):\r\n\tif (k % a[i] == 0 and a[i] > cur):\r\n\t\tcur = a[i]\r\n\r\nif (cur == 0):\r\n\tprint(k+1)\r\n\r\nelse:\r\n\tprint(k//cur)", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nans = k\r\nfor i in range(n):\r\n kai = k // a[i]\r\n if kai == k / a[i]:\r\n if ans > kai:\r\n ans = kai\r\nprint(ans)", "_, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nprint(k // max(filter(lambda x: k % x == 0, a)))\n", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nm=k\r\nfor i in range(len(a)):\r\n if k%a[i]==0 and k//a[i]<=m:\r\n m=k//a[i]\r\nprint(m)", "# print(\"Input n and k\")\nn, k = [int(x) for x in input().split()]\n\n# print(\"Input the n numbers\")\na = [int(x) for x in input().split()]\n\na.sort()\n\nfor i in range(len(a)-1, -1, -1):\n nxt = a[i]\n if k%nxt == 0:\n print(k//nxt)\n quit()\n", "n, k = map(int,input().split())\r\nl = [int(x) for x in input().split()]\r\nl.sort()\r\nl.reverse()\r\nfor i in range(n):\r\n\tif k % l[i] == 0:\r\n\t\tprint(k//l[i])\r\n\t\tbreak\r\n", "nbaldes, tamanhojardim = list(map(int, input().split()))\nbaldes = list(map(int, input().split()))\nbaldes.sort()\nbaldes = baldes[::-1]\nachou = False\ni = 0\nwhile not achou:\n if tamanhojardim % baldes[i] == 0 and tamanhojardim >= baldes[i]:\n print(int(tamanhojardim/baldes[i]))\n achou = True\n else:\n i += 1\n\n \t \t \t \t \t \t \t\t\t\t \t\t \t", "\n_=list(map(int,input().split()))\n__=sorted(list(map(int,input().split())))\nfor ___ in range(_[0]-1,-1,-1):\n if _[1]%__[___]==0:\n print(_[1]//__[___])\n break\n\n\n#ye jaye door bedoone IDE va net E :(", "n,m=map(int,input().split())\na=list(map(int,input().split()))\na.sort()\nfor i in a:\n if m % i==0:s=m/i\nprint(int(s))\n", "n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\np=[]\r\nfor i in l:\r\n if k%i==0:\r\n p.append(i)\r\nx=max(p)\r\nprint(int(k/x))", "n, k = [int(i) for i in input().split()]\r\na = [int(i) for i in input().split()]\r\nans = 10 ** 100\r\nfor i in a:\r\n if k % i == 0 and k // i < ans:\r\n ans = k // i\r\nprint(ans)", "n, k = map(int, input().split())\r\na = sorted(list(map(int, input().split())))[::-1]\r\nfor i in a:\r\n\tif k % i == 0:\r\n\t\tprint(k // i)\r\n\t\tbreak", "n,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nl = [k//i for i in a if k%i==0]\r\nprint(min(l))\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,k = map(int,input().split())\r\nai = list(map(int,input().split()))\r\nans = 0\r\nai.sort()\r\nfor i in range(n-1,-1,-1):\r\n if k % ai[i] == 0:\r\n ans = k // ai[i]\r\n break\r\nprint(ans)\r\n", "n,k=list(map(int,input().split()))\r\nt=list(map(int,input().split()))\r\ns=[]\r\nfor i in range(len(t)):\r\n if k%t[i]==0:\r\n p=k//t[i]\r\n s.append(p)\r\nprint(min(s))\r\n", "n1, k1 = input().split()\nk = int(k1)\nn = int(n1)\narr = list(map(int, input().split()))\nfor i in range(n):\n\tif(k % max(arr) == 0):\n\t\tprint(k // max(arr))\n\t\tbreak\n\tarr.remove(max(arr))\n \t\t \t \t \t\t \t\t\t\t\t\t \t", "a, b = input().split()\r\nmas = input().split()\r\nn = []\r\nfor i in mas:\r\n if int(b) % int(i) == 0:\r\n n.append(int(int(b) / int(i)))\r\nprint(min(n))\r\n", "n,k = list(map(int,input().split()))\r\nr = 10**9\r\nfor l in list(map(int,input().split())):\r\n if k%l==0:\r\n r = min(r,k//l)\r\nprint(r)\r\n \r\n", "n,k = map(int,input().split())\nlst = list(map(int,input().split()))\ncount = 0\nfor i in lst:\n if k % i == 0 and i > count:\n count = i\nprint(k//count)\n", "T=list(map(int,input().split()))\nq=list(map(int,input().split()))\n\ncount=[]\nfor i in range(T[0]):\n if T[1]%q[i]==0:\n count.append(int(T[1]/q[i]))\ncount.sort()\nprint(count[0])\n ", "n,k= map(int, input().split())\r\na=list(map(int,input().split()))\r\nans = 0\r\na.sort()\r\nfor i in range(n-1,-1,-1):\r\n if k%a[i]==0:\r\n print(k//a[i])\r\n exit()\r\n\r\n", "n, k = map(int, input().split())\r\nl = list(map(int, input().split()))\r\nl.sort()\r\nfor i in range(len(l)-1, -1, -1):\r\n if k%l[i] == 0:\r\n print(k//l[i])\r\n break", "n,k=map(int,input().split())\r\nvalue=[]\r\nvalue=input()\r\nvalue=value.split()\r\nhours=10000\r\nfor i in range(n):\r\n if(k%int(value[i])==0):\r\n hours=min(hours,k/int(value[i]))\r\nprint(int(hours))\r\n\r\n\r\n", "\nn, k = list(map(int,input().split()))\nbuckets = list(map(int,input().split()))\n\nbuckets.sort()\nmin_time = 0\nfor b in buckets:\n if k%b == 0:\n min_time = k//b\n\nprint(min_time)\n\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=list(map(int,input().split()))\r\nans=[]\r\nfor char in a:\r\n if char==k:\r\n ans.append(1)\r\n elif k%char==0:\r\n ans.append(k//char)\r\nprint(min(ans))", "n , k = map(int,input().split())\r\narr = list(map(int,input().split()))\r\narr = list(reversed(sorted(arr)))\r\n\r\nfor i in arr :\r\n if k % i == 0 :\r\n print(k // i)\r\n exit()\r\n", "n, k = [int(i) for i in input().split()]\r\na = [ int(x) for x in input().split()]\r\nans = int(1000000)\r\nfor i in range(n):\r\n if k%a[i]==0 and k//a[i] <ans:\r\n ans=k//a[i]\r\nprint(ans)", "x , y = map(int , input().split())\r\narr = list(map(int ,input().split()))\r\nans = min([y//r for r in arr if y % r == 0])\r\nprint(ans)", "temp=list(map(int,input().split()))\r\nk=temp[1]\r\nv=list(map(int,input().split()))\r\nans=1000\r\nfor i in v:\r\n if(k%i==0):\r\n ans=min(ans,int(k/i))\r\n \r\nprint(ans)\r\n", "\r\n\r\ndef get_result():\r\n n, k = input().split()\r\n n = int(n)\r\n k = int(k)\r\n\r\n r = input().split()\r\n for i, val in enumerate(r):\r\n r[i] = int(val)\r\n\r\n r.sort(reverse=True)\r\n\r\n for i in r:\r\n if k % i == 0:\r\n return int(k/i)\r\n\r\nif __name__ == \"__main__\":\r\n print(get_result())", "\r\nn,k=list(map(int,input().split()))\r\nl=list(map(int,input().split()))\r\nm=1\r\nfor i in l:\r\n if k%i==0:\r\n m=max(m,i)\r\nprint(k//m) \r\n", "k,n=map(int,input().split())\r\ns=map(int,input().split())\r\nq=1\r\nfor i in s:\r\n if n%i==0:\r\n q=max(q,i)\r\nprint(n//q)", "n_k = input().split(' ')\nn = int(n_k[0])\nk = int(n_k[1])\nbuckets = input().split(' ')\nbuckets = [int(x) for x in buckets]\nbuckets.sort(reverse=True)\nfor bucket in buckets:\n if k%bucket == 0:\n print(k//bucket)\n break\n\n\t \t \t\t \t \t\t \t\t \t \t\t \t \t\t", "n, k = map(int, input().split())\nprint(k//max(filter(lambda x: k%x==0, map(int, input().split()))))\n", "n,k = map(int,input().split())\r\nbuckets = [int(i) for i in input().split()]\r\n\r\npossibleBuckets = []\r\nfor i in buckets:\r\n\tif i <= k and k % i ==0:\r\n\t\tpossibleBuckets.append(i)\r\n\t\t\r\nans = k / max(possibleBuckets) \r\nprint(int(ans))\r\n\t\t", "n,k=map(int,input().split())\r\na=[int(i) for i in input().split()]\r\nmx=100000\r\nfor i in a:\r\n if k%i==0:\r\n mx=min(mx,k//i)\r\nprint(mx)", "n,k = (int(x) for x in input().strip().split())\r\nmn = 10000\r\nfor x in input().strip().split():\r\n a = int(x)\r\n if k%a==0:\r\n mn = min(k/a,mn)\r\n\r\nprint(int(mn))", "def getInts():\n return map(int, input().split())\n\nn, k = getInts()\n\na = getInts()\n\ndiv = 1\nfor num in a:\n if k % num == 0:\n div = max(div, num)\n\nprint(k // div)", "n,k = list(map(int,input().split()))\r\na = list(map(int,input().split()))\r\nb=[]\r\nfor i in a:\r\n\tif k%i==0:\r\n\t\tb.append(i)\r\nprint(int(k/max(b)))", "n,k=map(int,input().split())\r\na=sorted(map(int,input().split()),reverse=True)\r\nfor i in a:\r\n if k%i==0:\r\n print(k//i)\r\n break", "from random import randint\r\n\r\nx,y = map(int, input().split())\r\narr = sorted(list(map(int, input().split())))\r\nmaxi = 1\r\nfor i in arr[::-1]:\r\n if y%i == 0:\r\n maxi = i\r\n break \r\nprint(y//maxi)\r\n", "inp=input()\r\ninp=inp.split(' ')\r\ninp1=input()\r\ninp1=inp1.split(' ')\r\n\r\ni=0\r\ndata=[]\r\nwhile i<len(inp1):\r\n if int(inp[1])%int(inp1[i])==0:\r\n data.append(int(inp1[i]))\r\n i=i+1\r\nj=int(max(data))\r\nprint(int(int(inp[1])/j))\r\n", "\r\n\r\ndef solve():\r\n n,k = map(int, input().split())\r\n a = [int(i) for i in input().split()]\r\n a.sort(reverse=True)\r\n for i in a:\r\n if k % i == 0:\r\n print(k//i)\r\n return\r\n \r\nsolve()\r\n", "import sys\n\nipt = input().split()\nn = int(ipt.pop(0))\nk = int(ipt.pop(0))\n\nnumbers = [int(i) for i in input().split()]\n\ntimes = []\n\nfor n in numbers:\n if k % n == 0:\n times.append(n)\n\nresult = int(k / max(times))\nprint(result)\n\n \t \t\t \t \t\t\t \t \t \t\t\t", "n, k = [int(i) for i in input().split()]\r\n\r\na = [int(i) for i in input().split()]\r\n\r\nres = k\r\n\r\nfor i in a:\r\n if k % i == 0 and k // i < res:\r\n res = k // i\r\nprint(res)", "a,b = map(int,input().split())\r\nc = list(map(int,input().split()))\r\nc.sort()\r\nc.reverse()\r\nfor i in c:\r\n\tif b%i==0:\r\n\t\tprint(b//i)\r\n\t\tbreak\r\n", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nx = max(list(filter(lambda x: k%x == 0, a)))\r\nprint(k//x)", "n, k = map(int, input().split())\r\narr = list(map(int, input().split()))\r\n\r\nans = 1000000\r\nfor i in range(n):\r\n if k % arr[i] == 0:\r\n temp = k // arr[i]\r\n ans = min(temp, ans)\r\n\r\nprint(ans)\r\n", "# import sys \r\n# sys.stdin=open(\"input1.in\",\"r\")\r\n# sys.stdout=open(\"output2.out\",\"w\")\r\nN,K=map(int,input().split())\r\nL=list(map(int,input().split()))\r\nL.sort(reverse=True)\r\nfor i in range(N):\r\n\tif K%L[i]==0:\r\n\t\tprint(int(K/L[i]))\r\n\t\tbreak", "n,k = list(map(int,input().split()))\r\nst = list(map(int,input().split()))\r\nlst = []\r\nfor i in st:\r\n if k%i == 0:\r\n lst.append(i)\r\nx = max(lst)\r\nprint(k//x)\r\n", "n, k = [int(i) for i in input().split()]\r\narr = [int(i) for i in input().split()]\r\nprint(min(k//a for a in arr if k % a == 0))", "n,k=map(int, input().split())\r\na=[int(a) for a in input().split()]\r\nres=[]\r\ni=int()\r\nfor i in range(len(a)):\r\n if k%a[i]==0:\r\n res.append(k/a[i])\r\nprint(int(min(res)))", "n,k = map(int,input().split())\r\nb = list(map(int,input().split()))\r\nk = [k//b[i] for i in range(n) if k%b[i]==0]\r\nprint(min(k))", "n,k=list(map(int,input().split(\" \")))\r\na=input().split(\" \")\r\na=list(map(int,a))\r\nl=[]\r\nfor i in range (n):\r\n if(k%a[i]==0):\r\n l.append(int(k/a[i]))\r\n# print(l)\r\nprint(min(l))", "totalBaldes, tamJardim = [int(i) for i in input().split()]\nbaldes = [int(i) for i in input().split()]\n\n# pegar o balde cuja capacidade é o maior divisor do tamanho do jardim\nbaldeEscolhido = 0\nfor i in baldes:\n if tamJardim % i == 0 and i > baldeEscolhido:\n baldeEscolhido = i\n\nprint(tamJardim//baldeEscolhido)\n\t\t \t \t \t \t \t \t \t \t\t \t \t\t\t\t", "n, k = map(int, input().split())\r\n\r\nl = list(map(int, input().split()))\r\nl.sort(reverse = True)\r\n\r\nfor i in l:\r\n if k%i == 0:\r\n print(k//i)\r\n break\r\n", "def garden(buckets,k):\n hours = 1000\n for item in buckets:\n if k % item == 0:\n if k / item < hours:\n hours = int(k / item)\n\n print(hours)\n\n\ninp = list(map(int,input().split()))\nn = inp[0]\nk = inp[1]\nbuckets = list(map(int,input().split()))\ngarden(buckets, k)\n \t \t\t \t \t \t\t\t\t \t \t", "n,k=map(int,input().split())\r\nm=n\r\na=sorted(list(map(int,input().split())))\r\n#print(a)\r\nfor i in range(n):\r\n\tif k% a[m-i-1]==0:\r\n\t\tprint(k//a[m-i-1])\r\n\t\tbreak\r\n", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nminHours = 999999\r\nfor x in a:\r\n if k // x * x == k:\r\n minHours = min(minHours, k // x)\r\nprint(minHours)\r\n", "n,l=map(int,input().split());a=[]\r\nb=list(map(int,input().split()));\r\nfor i in b:\r\n if l%i==0:\r\n a.append(i)\r\na.sort()\r\nprint(int(l/(a[len(a)-1])))", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nr=0\r\na.sort(reverse=True)\r\nfor i in a:\r\n if k%i==0:\r\n r=k//i\r\n break\r\nprint(r)\r\n \r\n ", "a, b = map(int, input().split())\r\nx = sorted(list(map(int, input().split())))\r\nfor i in range(len(x)-1, -1, -1):\r\n if b % x[i] == 0:\r\n print(b // x[i])\r\n exit()", "a, b = map(int, input().split())\nprint(b // max(filter(lambda x: b % x == 0, map(int, input().split()))))", "n, k = (int(x) for x in input().split())\n\nbuckets = list(map(int, input().split()))\n\nmax = 0\nfor bucket in buckets:\n if k % bucket == 0 and max < bucket:\n max = bucket\n\nprint(int(k/max))\n\n \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()))\nv=list(map(int,input().split()))\n\nv.sort()\nfor i in range(n-1,-1,-1):\n if(k%v[i]==0):\n print(int(k/v[i]))\n break\n\n\n \t\t \t \t\t \t \t \t \t", "n, k = [int(x) for x in input().split()]\r\nl = list(map(int, input().split()))\r\nans = 0\r\nl.sort(reverse = True)\r\nfor i in l:\r\n if k % i == 0:\r\n print(k // i)\r\n break", "n, k = map(int, input().split())\r\nprint(min(k // i for i in map(int, input().split()) if k % i == 0))", "n, k = [int(t) for t in input().split()]\na = [-int(t) for t in input().split()]\na.sort()\ni = 0\nwhile k % a[i]:\n\ti += 1\nprint(-k // a[i])\n", "# cook your dish here\r\nn,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\no=[]\r\nfor i in l:\r\n if(k%i==0):\r\n o.append(k//i)\r\nprint(min(o))", "n, k = map(int, input().split())\r\narr = list(map(int, input().split()))\r\ndic = {}\r\nfor i in range(len(arr)):\r\n if k % arr[i] == 0:\r\n dic[arr[i]] = k // arr[i]\r\nvalues = list(dic.values())\r\nprint(min(values))", "mas1 = input().split(\" \")\r\nmas2 = input().split(\" \")\r\n\r\nn = int(mas1[0])\r\nk = int(mas1[1])\r\n\r\nmax_vedro = 0\r\nfor i in mas2:\r\n\tswap_vedro = int(i)\r\n\tif k%swap_vedro==0 and swap_vedro>max_vedro:\r\n\t\tmax_vedro = swap_vedro\r\n\r\nprint(k//max_vedro)\r\n", "n, k = list(map(int, input().split(' ')))\nbuckets = list(map(int, input().split(' ')))\n\nbuckets.sort(reverse=True)\n\nfor a in buckets:\n if not k%a:\n print(k//a)\n break\n\n \t\t \t\t\t\t\t \t\t \t \t\t\t \t \t", "_, garden_length = map(int, input().split())\r\nbuckets = map(int, input().split())\r\n\r\nmin_hours = int(min([garden_length/bucket for bucket in buckets if garden_length % bucket == 0]))\r\nprint(min_hours)\r\n", "n,k=map(int,input().split(' '))\r\nh=1\r\nl=input()\r\nl=l.split()\r\nfor i in range(n):\r\n a=int(l[i])\r\n if (k%a==0):\r\n if (h<a):\r\n h=a\r\nprint(int(k/h))\r\n ", "n,m = [int(i) for i in input().split()]\nl = [int(i) for i in input().split()]\nl.sort()\nl.reverse()\nfor k in l:\n if m%k == 0:\n print(int(m/k))\n break\n\t\t \t\t\t\t \t \t \t\t \t\t\t \t \t", "import math\r\nfrom sys import stdin\r\nstring1=stdin.readline().strip().split()\r\nstring2=stdin.readline().strip().split()\r\nbucketnumber=int(string1[0])\r\ngarden=int(string1[1])\r\noutput=garden\r\n\r\nfor item in string2:\r\n bucket=int(item)\r\n if garden%bucket==0:\r\n if garden/bucket<output:\r\n output=garden/bucket\r\n\r\nprint(int(output))", "n,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nl = []\r\nfor i in range(len(a)):\r\n if k % a[i] == 0 :\r\n l.append(k//a[i])\r\nprint(min(l))\r\n", "n,k=map(int,input().split())\nl1=list(map(int,input().split()))\nmin1=k\nfor i in range(n):\n if k%l1[i]==0:\n min1 = int(min(min1, k/l1[i]))\nprint(min1)\n ", "tc = 1\r\nwhile tc:\r\n tc-=1\r\n n, m = map(int, input().split())\r\n ls = list(map(int, input().split()))\r\n ls.sort(reverse=True)\r\n for item in ls:\r\n if m%item==0:\r\n print(m//item)\r\n break", "nk = list(map(int, input().split(' ')));\r\na = list(map(int, input().split(' ')));\r\nthisone = 0\r\n\r\nfor i in range(len(a)):\r\n if nk[1] % a[i] == 0:\r\n if a[i] > thisone:\r\n thisone = a[i]\r\n\r\nprint(int(nk[1]/thisone))", "import sys\r\nr = sys.maxsize\r\nbuckets, target = [int(x) for x in input().split()]\r\n\r\nfor x in input().split():\r\n c = int(x)\r\n if target % c == 0:\r\n t = int(target/c)\r\n if t < r:\r\n r = t\r\nprint(r)\r\n", "n, k = (int(x) for x in input().split())\nprint(min([k // int(x) for x in input().split() if k % int(x) == 0]))\n", "n, k = [int (i) for i in input().split()]\r\nbucks = [int (i) for i in input().split()]\r\nm = 100\r\nfor i in bucks:\r\n if k % i == 0 and k // i < m:\r\n m = k // i\r\nprint(m)", "import math\r\nn,k=map(int,input().split())\r\na = list(map(int, input().split()))\r\nmn=1000\r\nfor i in range(n):\r\n if k%a[i]==0 and k/a[i]<mn:\r\n mn=k/a[i]\r\nprint(math.trunc(mn))", "#182783\n#Lucca Jordao\n\nn, k = input().split()\nn = int(n)\nk = int(k)\nbaldes = []\nbaldes = input().split()\nfor i in range(n):\n baldes[i] = int(baldes[i])\nmaior = 0\nfor i in range(n):\n if baldes[i] > maior and k % baldes[i] == 0:\n maior = baldes[i]\nif maior != 0:\n print(k//maior)\nelse:\n print(0)\n\t \t\t\t \t\t\t \t \t \t\t\t", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort(reverse=True)\r\n#print (a)\r\nfor i in range(n):\r\n if k%a[i]==0:\r\n print (k//a[i])\r\n break", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nmn = 1001\r\nfor i in range(n):\r\n if k % a[i] == 0:\r\n mn = min(mn, k / a[i])\r\nprint(int(mn))", "y=list(map(int,input().split()))\r\nz=list(map(int,input().split()))\r\np=[]\r\nfor i in z:\r\n if y[1]%i==0:\r\n p.append(y[1]//i)\r\nprint(min(p))\r\n", "s=input().split()\r\nn=int(s[0])\r\nk=int(s[1])\r\nss=list(map(int,input().split()))\r\ny=0\r\nfor x in ss:\r\n\tif k%x==0 and x>y:\r\n\t\ty=x\r\nprint(k//y)\r\n", "n,k=map(int,input().split())\r\na=[int(i) for i in input().split()]\r\nd={}\r\nfor i in a:\r\n if(k%i==0):\r\n d[i]=k//i\r\nans=101\r\nfor i in d:\r\n if(d[i]<ans):\r\n ans=d[i]\r\nprint(ans)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "\nn, k = map(int, input().split(' '))\nbuckets = list(map(int, input().split(' ')))\n\nbest_bucket = -1\nfor bucket in buckets:\n if (k % bucket == 0 and bucket > best_bucket):\n best_bucket = bucket\n\n\nprint(int(k / best_bucket))\n \t\t \t\t \t \t \t\t\t\t \t\t \t\t\t\t", "#/usr/bin/python3\n\n# MC721A\n# 27 de março de 2020\n# Rogério Meirelles - RA160245\n\nimport math\n\nn, k = map(int, input().split()) \nsegment = [int(s) for s in input().split()]\n\nsegment.sort(reverse=True)\n\nfor s in segment:\n if k % s == 0:\n print(math.floor(k / s))\n break\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=list(map(int,input().split()))\r\nA.sort()\r\nans=None\r\nfor i in range(len(A)-1,-1,-1):\r\n if m%A[i] ==0:\r\n ans=m//A[i]\r\n break\r\nprint(ans) \r\n ", "n, k = input().split(' ')\nbuckets = [int(a) for a in input().split(' ')]\n\nk = int(k)\nbuckets = reversed(sorted(buckets))\nfor bucket in buckets:\n if k%bucket == 0:\n print(k//bucket)\n break\n\n \t\t \t \t\t\t \t \t \t\t\t", "n, m = map(int, input().split())\r\nprint(min([m//k for k in map(int, input().split()) if m % k == 0]))", "n, k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\n\nm = 0\nfor i in a:\n if k % i == 0 and i > m: m = i\n\nprint(k//m)\n", "a,b=map(int,input().split())\r\nd=24294359802475983274309854327985\r\nc=[int(i) for i in input().split()]\r\nfor i in range(a):\r\n if b%c[i]==0:\r\n d=min(d,b//c[i])\r\nprint(d)\r\n \r\n", "#!/usr/bin/python\r\n# -*- coding: UTF-8 -*-\r\n\r\n\r\na=(int(n) for n in input().split(\" \"))\r\nb=(int(n) for n in input().split(\" \"))\r\nc=[]\r\nfor i in a:\r\n c.append(i)\r\nmaxx=0\r\n#print(c[1])\r\nfor i in b:\r\n #print(i)\r\n if c[1]%i == 0 and i >maxx:\r\n maxx=i\r\nans=int(c[1]/maxx)\r\nprint(ans)", "a,b=map(int,input().split())\r\nl=list(filter(lambda x:b%int(x)==0,input().split()))\r\nm=[b//int(l[x]) for x in range(len(l))]\r\nprint(min(m))", "\r\n\r\ndef main_function():\r\n n, k = [int(i) for i in input().split(\" \")]\r\n a = [int(i) for i in input().split(\" \")]\r\n current_bucket = -1\r\n for i in a:\r\n if not k % i and i > current_bucket:\r\n current_bucket = i\r\n return k // current_bucket\r\n\r\n\r\nprint(main_function())", "from sys import stdin, stdout\r\n\r\ndef rdl():\r\n\treturn stdin.readline().replace('\\n', '')\r\n\r\ndef rds():\r\n\treturn rdl().split(' ')\r\n\r\ndef si():\r\n\treturn list(map(lambda x: int(x), rds()))\r\n\r\ndef wr(string):\r\n\tstdout.write(string)\r\n\r\ndef main():\r\n\tline = si()\r\n\tn, k = line[0], line[1]\r\n\tbuckets = si()\r\n\tr = 100000\r\n\tfor bucket in buckets:\r\n\t\tif (k % bucket == 0):\r\n\t\t\tt = int(k / bucket)\r\n\t\t\tif (t < r):\r\n\t\t\t\tr = t\r\n\twr('{}\\n'.format(r))\r\n\r\n\r\nif __name__ == '__main__':\r\n\tmain()", "def solve():\r\n n,k=list(map(int,input().split()))\r\n\r\n arr=[int(i) for i in input().split()]\r\n Min=1000\r\n for i in arr:\r\n if k%i==0:\r\n Min=min(Min,k//i)\r\n\r\n return Min\r\n\r\n\r\n\r\n\r\nprint(solve())\r\n\r\n", "l=[int(e) for e in input().split()]\r\nle=[int(e) for e in input().split()]\r\nlst=[]\r\nfor e in le:\r\n if(l[1]%e==0):\r\n lst.append(l[1]//e)\r\nprint(min(lst)) ", "n, k = map(int, input().split())\r\na = map(int, input().split())\r\ntmp = 0\r\nfor i in a:\r\n if k % i == 0 and i > tmp:\r\n tmp = i\r\nprint(k // tmp)\r\n# CodeForcesian\r\n# ♥\r\n# دمت گرم که هستی", "# import sys\r\n# sys.stdin=open(\"input.in\",'r')\r\n# sys.stdout=open(\"output4.out\",'w')\r\nn,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nm=0\r\nfor i in a:\r\n\tif k%i==0:\r\n\t\tm=max(m,i)\r\nprint(int(k/m))\t\t", "# ========== //\\\\ //|| ||====//||\r\n# || // \\\\ || || // ||\r\n# || //====\\\\ || || // ||\r\n# || // \\\\ || || // ||\r\n# ========== // \\\\ ======== ||//====|| \r\n# code\r\n\r\ndef solve():\r\n n, k = map(int, input().split())\r\n a = list(map(int, input().split()))\r\n\r\n a.sort()\r\n ans = float('inf')\r\n for i in a:\r\n if k % i == 0:\r\n ans = min(ans, k // i)\r\n print(ans)\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()", "X = list(map(int, input().split()))\r\nWater = list(map(int, input().split()))\r\nWater = sorted(Water, reverse=True)\r\nfor i in range(X[0]):\r\n if X[1] % Water[i] == 0:\r\n print(int(X[1] / Water[i]))\r\n exit()\r\n", "n, k = map(int, input().split())\r\nA = list(map(int, input().split()))\r\n\r\nans = 10**18\r\nfor a in A:\r\n if k%a == 0:\r\n ans = min(ans, k//a)\r\nprint(ans)\r\n", "def num_of_hours(bucket:int,length:int):\r\n if(length%bucket == 0):\r\n return length//bucket\r\n else:\r\n return None\r\n\r\na = input().split(\" \")\r\nlength = int(a[1])\r\nno_of_buckets = int(a[0])\r\nlist_of_buckets = []\r\nhours = []\r\nbuckets = input().split(\" \")\r\nfor bucket in buckets:\r\n list_of_buckets.append(int(bucket))\r\nfor bucket in list_of_buckets:\r\n num_of_hrs = num_of_hours(bucket,length)\r\n if(num_of_hrs != None):\r\n hours.append(num_of_hrs) \r\nlowest = hours[0]\r\nfor low in hours:\r\n if(lowest > low):\r\n lowest = low\r\nprint(lowest)", "b=list(map(int,input().split()))\r\nn=b[0]\r\nk=b[1]\r\na=list(map(int,input().split()))\r\na.sort(reverse=True)\r\nfor i in range(0,n):\r\n if k%a[i]==0:\r\n print(int(k/a[i]))\r\n break\r\n else:\r\n continue\r\n", "n,k = map(int, input().split())\r\na_i = list(map(int, input().split()))\r\na_i.sort()\r\nx = 0\r\nfor i in a_i:\r\n if k % i ==0:\r\n x = i\r\n\r\nprint(int(k/x))", "# NOME: Guilherme Lima Hernandez Rincao\n# RA: 169052\n# B - Garden\n\nn, k = map(int, input().split())\nb = map(int, input().split())\nc = list(map(lambda a: k / a, b))\n\nmin = 101\n\nfor v in c:\n if v.is_integer() and v < min:\n min = v\n\nprint(int(min))\n\n\t\t \t\t \t \t\t \t \t \t\t \t \t\t \t", "f = lambda: map(int, input().split())\r\nn, k = f()\r\nprint(k//max(x for x in f() if not k%x))", "n, k = map(int, input().split())\nl = list(map(int, input().split()))\nl.sort(reverse=True)\ndef solve():\n for e in l:\n if ((k%e) == 0):\n return k // e\n return -1\nprint(solve())\n\n", "n, k = map(int, input().split())\nprint(min(k//i for i in map(int, input().split()) if k % i == 0))\n\n \t \t\t \t \t\t \t \t \t \t\t", "def solve():\r\n size, n = map(int, input().split())\r\n minimum = 1e9\r\n \r\n for number in input().split():\r\n number = int(number)\r\n \r\n if not (n % number):\r\n minimum = min(minimum, n // number)\r\n \r\n print(minimum)\r\n \r\n \r\nif __name__ == \"__main__\":\r\n solve()\r\n ", "n,c = input().split()\r\nn = int(n)\r\nc = int(c)\r\nx = [int(x) for x in input().split()] \r\nmaximum = 0\r\nfor num in x:\r\n if c%num==0 and num>maximum:\r\n maximum=num\r\nprint(int(c/maximum))", "#Problem B - Semana 4 27/03/20\n\nnk = input()\nbucketString = input()\n#nk = '6 7'\n#bucketString = '1 2 3 4 5 6'\n\n\nnklist = nk.split(' ')\nn = int(nklist[0])\nk = int(nklist[1])\nbuckets = bucketString.split(' ')\ndivisiveis = []\n\nfor i in buckets:\n if (k%int(i) == 0):\n divisiveis.append(int(i))\n\nmaiorDiv = max(divisiveis)\nresposta = k//maiorDiv\n\nprint(resposta)\n\t\t\t\t \t\t \t\t \t \t\t\t \t\t\t\t", "n, k = input().split()\r\nn, k = int(n), int(k)\r\nM = list(map(int, input().split()))\r\nH = []\r\nfor i in M:\r\n if k % i == 0 and i != 0:\r\n x = k//i\r\n H.append(x)\r\nprint(min(H))", "s=list(map(int,input().split()))\r\nlist_of_lengths=list(map(int,input().split()))\r\na=[]\r\nfor j in range(len(list_of_lengths)):\r\n\tif (s[1]%list_of_lengths[j]==0):\r\n\t\ta.append(int(s[1]//list_of_lengths[j]))\r\nprint(min(a))\r\n\r\n", "g = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nn = g[0]\r\nk = g[1]\r\nbuc = 0\r\nfor i in b:\r\n if i > buc and k % i == 0:\r\n buc = i\r\n\r\nprint(k // buc)", "string = input().split(' ')\r\n\r\nn = int(string[0])\r\nk = int(string[1])\r\n\r\nbuckets = input().split(' ')\r\n\r\ntime = float('inf')\r\n\r\nfor num in buckets:\r\n if k % int(num) == 0:\r\n timeTaken = k // int(num)\r\n if timeTaken < time:\r\n time = timeTaken\r\n\r\nprint(time)", "def is_prime(x):\r\n for j in range(2, int(x ** 0.5) + 1):\r\n if x % j == 0:\r\n return False\r\n else:\r\n return True\r\n\r\n\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nmn = []\r\nif is_prime(k):\r\n exit(print(k if k not in a else 1))\r\nelse:\r\n for i in range(n):\r\n if k % a[i] == 0:\r\n mn.append(k // a[i])\r\nprint(min(mn))", "n,k = map(int, input().split())\r\na = list(map(int, input().split()))\r\na.sort(reverse=True)\r\n\r\nfor bucket in a:\r\n if k%bucket==0:\r\n print(k//bucket)\r\n exit(0)", "n,k=map(int,input().split())\r\nkl=list(map(int,input().split()))\r\nkl.sort()\r\nfor x in range(len(kl)-1,-1,-1):\r\n if k%kl[x]==0:print(int(k/kl[x]));break\r\n\r\n\r\n\r\n \r\n", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nl = []\r\nfor i in range(len(a)):\r\n\tif m % a[i] == 0:\r\n\t\tl.append(m // a[i])\r\nma = l[0]\r\nfor i in range(len(l)):\r\n\tif ma > l[i]:\r\n\t\tma = l[i]\r\nprint(ma) \r\n", "[n, k] = list(map(int, input().split(\" \")))\na = list(map(int, input().split(\" \")))\nr = k\nfor i in range(n):\n if k%a[i] == 0:\n r = min(r, k//a[i])\nprint(r)\n", "import sys\r\nimport math\r\nimport bisect\r\nimport itertools\r\n\r\ndef main():\r\n n, m = map(int, input().split())\r\n A = list(map(int, input().split()))\r\n min_val = 10 ** 18\r\n for a in A:\r\n if a and m % a == 0:\r\n val = m // a\r\n min_val = min(min_val, val)\r\n print(min_val)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "import sys\r\nn,k = map(int,input().split())\r\narr = list(map(int,input().split()))\r\nres = 10000000\r\nfor i in range(n):\r\n if k % arr[i] == 0:\r\n res = min(res,k // arr[i])\r\nprint(res)", "n,k = map(int,input().split())\r\nL = input().split()\r\nm = 101\r\nfor a in L:\r\n a = int(a)\r\n if k % a == 0:\r\n r = k//a\r\n if r < m:\r\n m = r\r\nprint (m)\r\n", "n, k = [int(x) for x in input().split()]\r\narr = [int(x) for x in input().split()]\r\n\r\nprint(min([k//a for a in arr if k % a == 0]))", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nn, k = map(int, input().split())\r\ndata = sorted(map(int, input().split()), reverse=True)\r\n\r\nfor i in range(n):\r\n if k % data[i] == 0:\r\n print(k // data[i])\r\n break", "#!/usr/bin/env python\r\n# coding=utf-8\r\n# 817079\r\n\r\nf = lambda: map(int, input().split())\r\nn, k = f()\r\nprint(k // max(a for a in f() if not k % a))\r\n\r\n\r\n", "# Paulo Pacitti\n# RA 185447\n\nn, k = list(map(lambda e: int(e), input().split(\" \")))\nbuckets = list(map(lambda e: int(e), input().split(\" \")))\nalternatives = []\n\nfor b in buckets:\n mod = k % b\n q = k // b\n if mod == 0:\n alternatives.append(int(k // b))\n\nprint(min(alternatives))\n\t \t\t\t\t \t\t \t\t \t\t \t\t\t\t \t\t", "a, b = [int(i) for i in input().split()]\r\ndig = [int(i) for i in input().split()]\r\nres = b +1\r\nfor i in range(len(dig)):\r\n if b % dig[i] == 0 and b // dig[i] < res:\r\n res = b // dig[i]\r\nprint(res)", "n, k = tuple(map(int, input().split(' ')))\nA = list(map(int, input().split(' ')))\n\ndef calc(k, A):\n c = 0\n A.sort(reverse=True)\n\n while k:\n if k % A[0] == 0:\n k -= A[0]\n c += 1\n else:\n del A[0]\n\n return c\n\nprint(calc(k,A))", "c, b = input().split()\r\nn = int(c)\r\nk = int(b)\r\nb = input().split()\r\na = []\r\nfor x in range(n):\r\n a.append(int(b[x]))\r\na.sort()\r\na.reverse()\r\nfor x in range(n):\r\n if (k % a[x] == 0):\r\n print(k // a[x])\r\n break\r\n \r\n", "#!/usr/env/python3\n\nn,k = map(int, input().split(\" \"))\n\npp = map(int, input().split(\" \"))\n\nm_d = 0\nfor ss in pp:\n if k % ss == 0: m_d = max(m_d, ss)\n\nprint(k//m_d)\n", "n,k=map(int,input().split())\r\nai=list(map(int,input().split()))\r\nbi=[]\r\nfor i in ai :\r\n if(k%i==0):\r\n bi.append(i)\r\nprint(int(k/max(bi)))", "n , k = map(int, input().split())\r\nbucket = list(map(int, input().split()))\r\nbucket.sort(reverse= True)\r\nans = 0\r\nfor i in bucket:\r\n if k%i==0:\r\n ans=k//i\r\n print(ans)\r\n break", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nl=[]\r\nfor i in range(n):\r\n if k%a[i]==0:\r\n l.append(a[i])\r\nprint(k//max(l))", "n,k=map(int, input().split())\r\na=list(map(int, input().split()))\r\nm=0\r\nfor i in a:\r\n if k%i==0:\r\n m=max(m,i)\r\nprint(k//m)", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\na.reverse()\r\nfor i in a:\r\n if(k%i==0):\r\n print(k//i)\r\n break", "#B - Garden\n\n\nbuckets, lenght = [int(x) for x in input().split()]\nbucket_sizes = [int(x) for x in input().split()]\n\nmax = 0\n\nfor size in bucket_sizes:\n if lenght % size == 0 and size > max:\n max = size\n\nhours = int(lenght / max)\n\nprint(hours)\n\t\t \t\t\t\t\t\t \t\t \t \t\t \t\t \t", "x = list(map(int,input().split()))\nn = list(map(int,input().split()))\nmax = 1\nfor i in range(x[0]):\n\tif x[1]%n[i] == 0:\n\t\tif n[i] > max:\n\t\t\tmax = n[i]\nprint(str(int(x[1]/max)))\n\t\t \t\t \t \t\t \t \t \t \t\t \t \t", "n,l = map(int,input().split())\r\nb = sorted([*map(int,input().split())],reverse = True)\r\ni = 0\r\nwhile(i<n):\r\n if(l%b[i]==0):print(l//b[i]);break\r\n i += 1", "def find_factor(n):\r\n divisor = []\r\n for i in range(1,int(n**(1/2))+1):\r\n if n%i == 0:\r\n divisor.append(i)\r\n divisor.append(n//i)\r\n return set(divisor)\r\n\r\nn,k = list(map(int,input().split()))\r\na = list(map(int,input().split()))\r\na = [i for i in a if i in find_factor(k)]\r\nprint(k//max(a))", "def main():\r\n\r\n def solve(n, k, a):\r\n ret = -1\r\n for x in a:\r\n if k % x == 0 and x > ret:\r\n ret = x\r\n return k // ret\r\n\r\n n, k = [int(x) for x in input().split()]\r\n a = [int(x) for x in input().split()]\r\n\r\n print(solve(n, k, a))\r\n\r\nif __name__ == \"__main__\":\r\n import sys, threading\r\n input = sys.stdin.readline\r\n thread = threading.Thread(target=main)\r\n thread.start()\r\n thread.join()", "n, m = map(int, input().split())\r\nmin_ = 10000000000000\r\nl = []\r\ns = input().split()\r\nfor i in range(n):\r\n l.append(int(s[i]))\r\nfor el in l:\r\n if (m % el) == 0:\r\n if (m / el) < min_:\r\n min_ = (m / el)\r\nprint(int(min_))", "n,k=map(int,input().split())\r\nai=list(map(int,input().split()))\r\nb=0\r\nfor x in ai :\r\n if (k % x==0)and(x>b):\r\n b=x\r\n res=k//x\r\nprint(res)\r\n \r\n", "f = lambda: map ( int , input ( ) . split ( ) )\r\n\r\nn , k = f ( )\r\nll = max(a for a in f() if not k % a)\r\nprint ( k // ll )\r\n\r\n", "n,k=map(int,input().split())\r\nc=list(map(int,input().split()))\r\nh=[0]\r\nfor i in range(n):\r\n if k%c[i]==0:\r\n h.append(c[i])\r\nprint(k//max(h))", "n, k = map(int, input().split())\r\nls = list(map(int, input().split()))\r\nprint(min([k//i for i in ls if k%i==0]))", "k, n = map(int, input().split())\r\ndata = [int(i) for i in input().split()]\r\n\r\nbest_outcome = 0\r\n\r\nfor i in data:\r\n if n % i == 0 and i > best_outcome:\r\n best_outcome = i\r\n\r\nprint(n // best_outcome)\r\n", "N,K = [int(i) for i in input().split()]\r\nBuckets = [int(i) for i in input().split()]\r\nBuckets.sort()\r\nBuckets.reverse()\r\nBuckets = list(filter(lambda i: K%i==0,Buckets))\r\nhrs = []\r\nfor i in Buckets:\r\n hrs.append(K//i)\r\nprint(min(hrs))", "n, k = map(int, input().split())\r\narr = [int(i) for i in input().split() if int(i) <= k and k % int(i) == 0]\r\nprint(k // max(arr))\r\n", "n, k = map(int, input().split())\r\nl = [int(x) for x in input().split()]\r\nmx = 0\r\n\r\nfor i in range(n):\r\n if k % l[i] != 0:\r\n l[i] = 0\r\n \r\n\r\nprint(k//max(l))", "k = int(input().split()[1])\nfor a in sorted(map(int, input().split()), reverse=True):\n if not (k % a):\n break\nprint(k // a)", "_, t = map(int, input().split())\r\na = max([int(i) for i in input().split() if t%int(i)==0])\r\nprint(t//a)", "buckets, target = [int(x) for x in input().split()]\r\na = max([int(i) for i in input().split() if target % int(i) == 0])\r\nprint(target // a)", "n, k = list(map(int,input().split()))\r\na = list(map(int,input().split()))\r\na = [item for item in a if k % item == 0]\r\nprint(k//max(a))\r\n\r\n\r\n", "n, k = [int(w) for w in input().split()]\nlist = [int(w) for w in input().split()]\n\nmin = 10000000;\nfor i in list:\n if k % i == 0:\n tmp = k/i\n if tmp < min:\n min = tmp\n\nprint(int(min))", "y=list(map(int, input().split()))\r\na=list(map(int, input().split()))\r\nn=y[0]\r\nk=y[1]\r\nq=[]\r\nfor i in range(len(a)):\r\n if k%a[i]==0:\r\n q.append(k//a[i])\r\nprint(min(q))", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nans = 100\r\nfor x in a:\r\n if k % x == 0:\r\n ans = min(ans, k // x)\r\nprint(ans)", "n , k = map(int , input().split())\r\nv = list(map(int , input().split()))\r\nm = 0\r\nfor i in range(n) :\r\n if k % v[i] == 0 :\r\n m = max(m , v[i])\r\nprint(k // m)", "def main():\r\n n,k=map(int,input().split(\" \"))\r\n arr=[int(x) for x in input().split(\" \")]\r\n arr.sort()\r\n temp=0\r\n for i in arr:\r\n if k%i==0:\r\n temp=i\r\n if i>k:\r\n break\r\n print(int(k/temp))\r\n\r\nmain()", "n,k=map(int,input().split())\r\nmin=101\r\ncount=0\r\nx=0\r\nb=input().split()\r\na=list(map(int,b))\r\nfor i in range(n):\r\n\twhile x<k:\r\n\t\tx+=a[i]\r\n\t\tcount+=1\r\n\tif x==k:\r\n\t\tif min>count:\r\n\t\t\tmin=count\r\n\t\tcount=0\r\n\t\tx=0\r\n\telse:\r\n\t\tcount=0\r\n\t\tx=0\r\nprint(min)", "#!/user/bin/python\r\n\r\nfirstLine = input()\r\nsecondLine = input()\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n\t_firstLine = firstLine.split(' ')\r\n\t_secondLine = secondLine.split(' ')\r\n\tminHours = 10e10\r\n\tgardenLenght = int(_firstLine[1])\r\n\tfor bucket in _secondLine:\r\n\t\t\r\n\t\tif gardenLenght%(int(bucket)) == 0:\r\n\t\t\thours = gardenLenght//(int(bucket))\r\n\t\t\tif minHours > hours:\r\n\t\t\t\tminHours = hours\r\n\tprint(minHours)\r\n\t", "n, k = [int(c) for c in input().split()]\r\nA = [int(c) for c in input().split()]\r\nres = 101\r\nfor a in A:\r\n if k % a == 0 and k // a < res:\r\n res = k // a\r\n\r\nprint(res)\r\n", "\r\n\r\nn,k=map(int,input().split())\r\narr=list(map(int,input().split()))\r\n\r\narr.sort()\r\n\r\nhours=0\r\nfor i in arr:\r\n if k%i==0:\r\n hours=k//i\r\n\r\nprint(hours)", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nmins = []\r\nfor i in a:\r\n if k % i == 0:\r\n x = k // i\r\n mins.append(x)\r\nprint(min(mins))\r\n", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nmin1=float(\"inf\")\r\nfor i in range(n):\r\n\tif k%a[i]==0:\r\n\t\tif k//a[i]<min1:\r\n\t\t\tmin1=k//a[i]\r\nprint(min1)", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\nmin_hours = float('inf')\r\nfor ai in a:\r\n if k % ai == 0:\r\n min_hours = min(min_hours, k // ai)\r\n\r\nprint(min_hours)\r\n", "# from dust i have come dust i will be\r\n\r\nn,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\n\r\na.sort()\r\n\r\nans=0\r\nfor i in a:\r\n if k%i==0:\r\n ans=k//i\r\n\r\nprint(ans)", "n, k = [int(x) for x in input().split()]\r\ngood = []\r\nfor i in [int(x) for x in input().split()]:\r\n if k % i == 0:\r\n good.append(i)\r\nprint(k // max(good))", "number_of_buckets, garden_length = map(int, input().split())\r\nbuckets = list(map(int, input().split()))\r\n\r\nbuckets.sort()\r\nbuckets.reverse()\r\n\r\nfor i in buckets:\r\n\tif (garden_length % i == 0):\r\n\t\tprint(int(garden_length / i))\r\n\t\tbreak\r\n", "n,k=map(int,input().split())\narr=list(map(int,input().split()))\narr.sort()\nfor i in range(0,len(arr)):\n if k%arr[i]==0 :\n ans=k//arr[i]\nprint(ans)\n", "ans1 = input()\nn, k = list(map(int, ans1.split()))\nans2 = input()\nbuckets = list(map(int, ans2.split()))\n\nbestHours = 0\nfor a in buckets:\n if (k/a < bestHours or bestHours == 0) and k % a == 0:\n bestHours = k//a\n\nprint(bestHours)", "n, k = [int(x) for x in input().split()]\r\nai = dict((int(x), True) for x in input().split())\r\n\r\n\r\nfor i in reversed(range(1, k + 1)):\r\n if k % i == 0 and i in ai:\r\n print(k // i)\r\n exit()\r\n", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nans = k\r\nfor i in a:\r\n if k % i == 0:\r\n ans = min(k//i, ans)\r\nprint(ans)", "n, k = input().split(\" \")\n\nn = int(n)\nk = int(k)\n\nlista = list(map(int, input().split(\" \")))\n\nlista.sort(reverse=True)\n\nfor x in lista:\n if (k%x) == 0:\n print(int(k/x))\n exit(0)\n\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()[:-1]\r\nni = lambda :int(input())\r\nna = lambda :list(map(int,input().split()))\r\nyes = lambda :print(\"yes\");Yes = lambda :print(\"Yes\");YES = lambda : print(\"YES\")\r\nno = lambda :print(\"no\");No = lambda :print(\"No\");NO = lambda : print(\"NO\")\r\n#######################################################################\r\n\r\n\r\nn, k = na()\r\na = sorted(na())\r\nfor i in range(n-1,-1,-1):\r\n if k % a[i] == 0:\r\n print(k//a[i])\r\n exit()", "noOfbuckets , garden = map(int , input().split(\" \"))\n\nbuckets_length = list(map(int , input().split(\" \")))\n\ncan_choose = [i for i in buckets_length if garden % i == 0]\nchoosed_bucket = max(can_choose)\n\nprint(garden // choosed_bucket)\n\n\n", "n, k = map(int, input().split())\r\ncup = list(map(int, input().split()))\r\ncup.sort(reverse=True)\r\nfor i in cup:\r\n w = 0\r\n while(w<k):\r\n w = w +int(i)\r\n if(w==k):\r\n print(k//int(i))\r\n break;\r\n if(w==k):\r\n break;", "n, k = map(int, input().split())\r\nl = list(int(x) for x in input().split())\r\nlt = []\r\nfor i in l:\r\n if k%i == 0:\r\n lt.append(i)\r\nprint(k//(max(lt)))\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\n\r\n@author: james\r\n\"\"\"\r\n\r\ninit = input().split()\r\nN = int(init[0])\r\nk = int(init[1])\r\nl = sorted(list(map(int, input().split())))\r\nl.reverse()\r\nfor x in l:\r\n if k % x == 0:\r\n print(int(k/x))\r\n break", "n, k = map(int, input().split())\r\nprint(int(k / max(x for x in list(map(int, input().split())) if not k % x)))", "n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = []\r\nfor i in range(len(a)):\r\n if m % a[i] == 0:\r\n b.append(a[i])\r\nprint(int(m/max(b)))", "n, k=[int(i) for i in input().split()]\r\na=[int(i) for i in input().split()]\r\nb=[]\r\nfor i in a:\r\n if k%i==0:\r\n b.append(i)\r\nm=b[0]\r\nfor i in b:\r\n if i>m:\r\n m=i\r\nprint(k//m)", "def solution():\r\n n,m = [int(i) for i in input().split(\" \")]\r\n buckets = [int(i) for i in input().split(\" \")]\r\n choseBucket = 0\r\n for i in buckets:\r\n if i <= m and m % i == 0 and i > choseBucket:\r\n choseBucket = i\r\n print(m // choseBucket)\r\n\r\n \r\n\r\nsolution()\r\n ", "n, k = map(int, input().split())\nbuckets = list(map(int, input().split()))\n\nbuckets.sort(reverse=True)\n\nfor b in buckets:\n if k%b == 0:\n print(int(k/b))\n break\n \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\nl=list(map(int,input().split()))\r\nl.sort(reverse=True)\r\nfor i in l:\r\n\tif k%i==0:\r\n\t\tprint(k//i)\r\n\t\tbreak", "n,k=(input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\nans=0\r\nfor i in a:\r\n if int(k)%int(i)==0:\r\n ans=i\r\nprint(int(k)//int(ans))\r\n", "n,k=map(int,input().split())\r\narr=list(map(int,input().split()))\r\nmini=10000\r\nfor i in arr:\r\n if (k%i==0):\r\n if (k//i<mini):\r\n mini=k//i\r\n\r\nprint(mini)\r\n", "n,k=map(int,input().split())\r\nans=99999\r\np=list(map(int,input().strip().split()))[:n]\r\nfor i in p:\r\n if (k%i) == 0 :\r\n ans=min(ans,k/i)\r\nprint(int(ans))", "nk = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\na.sort()\r\nfor i in range(nk[0] - 1, -1, -1):\r\n\tif nk[1] % a[i] == 0:\r\n\t\tprint(nk[1] // a[i])\r\n\t\tbreak", "n, k = map(int, input().split())\nv = map(int, input().split())\nprint(k // max(filter(lambda x: k % x == 0, v)))\n", "n, c = map(int, input().split())\r\na = list(map(int, input().split()))\r\na.sort(reverse = True)\r\nfor i in a:\r\n if c % i == 0:\r\n print(c // i)\r\n break", "s = list(map(int,input().split()))\r\nlist_of_lengths = list(map(int,input().split()))\r\na = []\r\nfor j in list_of_lengths:\r\n if(s[1]%j ==0):\r\n a.append(int(s[1]//j));\r\nprint(min(a))\r\n \r\n", "\r\n\r\ndef main():\r\n [n, k], a = map(int, input().split(' ')), list(map(int, input().split(' ')))\r\n r = list(map(lambda x: int(k/x), filter(lambda y: k%y==0, a)))\r\n print(min(r))\r\n return True\r\n\r\nmain()\r\n", "\r\n\r\nnumber_of_buckets, length = map(int, input().split(' '))\r\nbuckets = list(map(int, input().split(' ')))\r\n\r\nbuckets = sorted(buckets, reverse=True)\r\nfor i in range(0, len(buckets)):\r\n if length% buckets[i] == 0:\r\n print(length // buckets[i])\r\n break", "n,k = map(int,input().split())\r\na = sorted(list(map(int,input().split())))\r\nhours = 0\r\n\r\nfor x in a:\r\n if x > k:\r\n break\r\n elif k % x == 0:\r\n hours = x\r\nprint(k // hours)", "n,x=map(int,input().split())\r\narr=[int(new) for new in input().split()]\r\narr.sort(reverse=True)\r\nfor i in arr:\r\n if(x%i==0):\r\n ans=x//i\r\n break\r\nprint(ans)", "temp = input()\ntemp = temp.split(' ')\nbucket = int(temp[0])\ngarden = int(temp[1])\ntemp = input()\nvalues = list(map(int,temp.split(' ')))\nmax = 1\nfor x in values:\n if x > max and garden%x == 0:\n max = x\nprint(int(garden/max))\n\t \t\t \t \t \t\t \t\t\t\t\t \t", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\na.sort(reverse=True)\r\nfor i in range(n):\r\n if k % a[i] == 0:\r\n print(k // a[i])\r\n break", "def minimal(l, s):\n return int(min(l / i for i in s if l%i<1))\n\nbucks, length = map(int, input().split(\" \"))\nsizes = [*map(int, input().split(\" \"))]\nprint(minimal(length, sizes))\n\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\n\r\nl=list(map(int,input().split()))\r\n\r\nprint(k//max([i for i in l if(k%i==0)]))", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\nx=[]\r\nfor i in range(0,n):\r\n if k%a[i]==0:\r\n x.append(k//a[i])\r\nprint(min(x))\r\n ", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nans = []\r\nfor i in a:\r\n if k % i == 0:\r\n ans.append(k // i)\r\nprint(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\r\n\r\n\r\n\r\n\r\n", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nc=0\r\nfor x in range(n):\r\n\tif m%l[x]==0:\r\n\t\tif l[x]>c:\r\n\t\t\tc=l[x]\r\nprint(m//c)", "bucket_num, length = map(float, input().split())\r\nbuckets = list(map(int, input().split()))\r\nbuckets = sorted(buckets)\r\nminimum_hours = 0\r\nfor bucket in buckets:\r\n if (length / bucket) % 1 == 0:\r\n minimum_hours = length // bucket\r\nprint(int(minimum_hours))", "ch=input(\"\")\r\nn,k=int(ch.split(\" \")[0]),int(ch.split(\" \")[1])\r\nch=input(\"\")\r\nl=[]\r\nfor i in range(n):\r\n l.append(int(ch.split(\" \")[i]))\r\nlv=[]\r\nfor i in l :\r\n if k%i==0 :\r\n lv.append(i)\r\n \r\n\r\nlv.sort()\r\nh=k//lv[-1]\r\nprint(h)\r\n\r\n\r\n ", "n,k=map(int,input().split(' '))\r\na=list(map(int,input().split(' ')))\r\nvalue=1000000000000\r\nfor i in (a):\r\n if k%i==0:\r\n b=int(k/i)\r\n if value>b:\r\n value=b\r\nprint(value) \r\n \r\n \r\n", "i=lambda:map(int,input().split());_,k=i();print(min(k//x for x in i()if k%x<1))", "n,k=map(int, input().split())\r\nl=list(map(int, input().split()))\r\nl2=[]\r\n\r\nfor x in l:\r\n if k%x==0:\r\n l2.append(x)\r\n\r\nprint(k//max(l2))\r\n\r\n", "n, k = (int(x) for x in input().split())\r\nbuckets = [int(x) for x in input().split()]\t#bucket - ведро\r\nbuckets.sort(reverse = True)\r\ni = 0\r\nwhile i < n:\r\n\tif k%buckets[i] == 0:\r\n\t\tprint(k//buckets[i])\r\n\t\tbreak\r\n\ti += 1", "n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nx=0\r\nz=0\r\nfor i in l:\r\n if k%i==0:\r\n if z<i:\r\n z=i\r\nx=k//z \r\nprint(x)\r\n \r\n", "n,k=map(int,input().split())\r\nls=list(map(int,input().split()))\r\nls.sort(reverse=True)\r\nfor i in ls:\r\n if k%i==0:\r\n print(k//i)\r\n break", "n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nj=[]\r\nfor i in range(len(l)):\r\n if k%l[i]==0:\r\n j.append(l[i])\r\nprint(k//max(j))", "\r\nn,m=map(int,input().split())\r\nl=sorted(list(map(int,input().split())),reverse=True)\r\nfor i in l:\r\n\tif(m%i==0):\r\n\t\tprint(m//i)\r\n\t\tbreak", "buckets, garden = list(map(int, input().split()))\nsizes = list(map(int, input().split()))\n\nsizes.sort(reverse = True)\n\nfound = False\ni=0\nwhile not found:\n time = garden / sizes[i]\n if time.is_integer():\n found = True\n else:\n i+=1\n\nprint(int(time))\n\n \t \t\t\t\t \t \t\t \t", "n,k=input().split()\r\nmx=0\r\nn=int(n)\r\nk=int(k)\r\na=input().split(\" \")\r\nfor c in a:\r\n c=int(c)\r\n if k%c==0:\r\n if c>mx:\r\n mx=c\r\n \r\nprint(int(k/mx)) \r\n ", "l=list(map(int,input().split(' ')))\r\nt=list(map(int,input().split(' ')))\r\nc=0\r\nfor i in range(l[0]):\r\n if t[i]<=l[1] and l[1]%t[i]==0 and t[i]>c:\r\n c=t[i]\r\n\r\nprint(int(l[1]/c)) \r\n \r\n", "def solve():\r\n n,k=map(int,input().split());a=list(map(int,input().split()));mn=1000000000000000\r\n for i in a:\r\n if k%i==0:\r\n c=k//i\r\n mn=min(mn,c)\r\n print(mn)\r\nsolve()\r\n", "n , m = map(int ,input().split()) \r\nl = sorted(list(map(int,input().split()))) \r\nfor i in l[ : : -1 ] :\r\n if m % i == 0 : \r\n print(m // i) \r\n break\r\n ", "n, k = map(int, input().split())\r\n\r\nfor i in sorted(map(int, input().split()), reverse=True):\r\n if k % i == 0:\r\n print(k // i)\r\n break\r\n", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))[:n]\r\nb=[]\r\nsum=0\r\nc=0\r\nfor i in range(n):\r\n c,sum=0,0\r\n if k%a[i]==0:\r\n while sum<k:\r\n sum+=a[i]\r\n c+=1\r\n if c!=0:\r\n b.append(c)\r\nprint(min(b))", "_, g = [int(x) for x in input().split()]\nbuckets = sorted([int(x) for x in input().split()])\n\nfor b in buckets[-1: :-1]:\n if g%b == 0:\n print(int(g/b))\n exit()\n", "n, k = map(int, input().split())\r\na = sorted(list(map(int, input().split())))\r\nresult = 0\r\nfor i in a:\r\n\tif k%i==0:\r\n\t\tresult = i\r\nprint(k//result)", "S=input()\r\nI=input()\r\nS=S.split(\" \")\r\nI=I.split(\" \")\r\nTama=int(S[0])\r\nTamaG=int(S[1]) #es para dividir\r\nL=[]\r\nfor i in range(0,Tama):\r\n L.append(int(I[i]))\r\nL1=[]\r\nfor i in L:\r\n if(TamaG%i==0):\r\n L1.append(TamaG/i)\r\nL1.sort()\r\nprint(int(L1[0]))\r\n", "a, b = [int(x) for x in input().split()]\narr = [int(x) for x in input().split()]\narr = sorted(arr)[::-1]\nfor element in arr:\n\tif(b % element == 0):\n\t\tprint(b // element)\n\t\texit()\n", "n, k = list(map(int, input().split()))\r\nprint(k//max([i for i in list(map(int, input().split())) if k%i==0]))\r\n\r\n ", "import math\n_, length = input().split(\" \")\ninp = input().split(\" \")\nbuckets = sorted(list(map(int, inp)), reverse=True)\n\nlength = int(length)\n\nbest = 0\nfor i in buckets:\n if length % i == 0 and i > best:\n best = i\n\nprint(length // best)\n", "a, b = map(int, input().split())\r\narr = sorted(map(int, input().split()))\r\nans = float(\"inf\")\r\n\r\nfor n in arr:\r\n if b % n == 0:\r\n if b//n < ans:\r\n ans = b//n\r\n\r\n\r\nprint(ans)\r\n", "x,y=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nm=[]\r\nfor i in l:\r\n if y%i==0:\r\n m.append(i)\r\nprint(y//max(m))", "a , b = list(map(int,input().split()))\r\nl = list(map(int,input().split()))\r\nl.sort()\r\nfor i in range(len(l)-1,-1,-1):\r\n\tif b%l[i]==0:\r\n\t\tprint(b//l[i])\r\n\t\tbreak\t\r\n\t", "x, y = [int(i) for i in input().split()]\r\nz = [int(i) for i in input().split()]\r\nz.sort()\r\nfor i in z[::-1]:\r\n if y % i == 0:\r\n print(y//i)\r\n break\r\n", "n,k = map(int,input().split())\r\narr = list(map(int,input().split()))\r\n\r\narr.sort()\r\nfor i in range(len(arr)-1,-1,-1):\r\n\tif k%arr[i] == 0:\r\n\t\tprint(k//arr[i])\r\n\t\tbreak", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\n# ans = 0\r\n# for i in a:\r\n# if k % i == 0:\r\n# ans = max(ans, i)\r\n#\r\n# print(k // ans)\r\n\r\nprint(min(k // i for i in a if k % i == 0))\r\n", "n, k = list(map(int, input().split(\" \")))\n\nbuckets = list(map(int, input().split(\" \")))\nbuckets.sort(reverse = True)\n\nfor i in range(n):\n if k % buckets[i] == 0:\n print(int(k/buckets[i]))\n break\n \t\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() )\na = sorted(list(map(int, input().split() ) ) )\nr = -1\nfor i in range(len(a)-1, -1, -1):\n if k % a[i] == 0:\n r = k // a[i]\n break\nprint(r)\n", "(n, k) = map(int, input().split())\r\nlst = [int(x) for x in input().split()]\r\na = 1\r\nfor i in range(n):\r\n if ((k % lst[i]) == 0) and ((k // lst[i]) < (k // a)):\r\n a = lst[i]\r\nprint(k // a)\r\n\r\n \r\n", "# cook your dish here\r\nn,k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nm = 0\r\nfor i in range(len(a)):\r\n if k%a[i]==0 and a[i]>m:\r\n m = a[i]\r\nprint(k//m)", "a,b = map(int,input().split())\r\ns = list(map(int,input().split()))\r\nd = []\r\nfor i in s:\r\n if b % i == 0:\r\n d.append(i)\r\nprint(b // max(d))", "#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-14 16:24:06\nLastEditTime: 2021-11-14 16:28:21\nDescription: Garden\nFilePath: CF915A.py\n'''\n\n\ndef func():\n _, k = map(int, input().strip().split())\n lst = sorted(map(int, input().strip().split()), reverse=True)\n for item in lst:\n if k % item == 0:\n print(k // item)\n break\n\n\nif __name__ == '__main__':\n func()\n", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nans=[]\r\nfor i in range(n):\r\n if m%l[i]==0:\r\n ans.append(m//l[i])\r\nprint(min(ans))", "x = lambda:map(int,input().split());_,l=x();print(min(l//y for y in x() if l%y==0))", "[n, k] = [int(x) for x in input().split()]\r\nA = [int(x) for x in input().split()]\r\nm=101\r\nfor i in range(n):\r\n if k%A[i]==0:\r\n if k//A[i]<m:\r\n m=k//A[i]\r\n i+=1\r\nprint(m)\r\n\r\n\r\n", "\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\na.sort(reverse=True)\r\nfor num in a:\r\n if k % num == 0:\r\n print(k // num)\r\n break\r\n", "import sys \r\ninput = sys.stdin.buffer.readline \r\n\r\ndef process(A, k):\r\n answer = float('inf')\r\n for x in A:\r\n if k % x==0:\r\n answer = min(answer, k//x)\r\n print(answer)\r\n \r\nn, k = [int(x) for x in input().split()]\r\nA = [int(x) for x in input().split()]\r\nprocess(A,k)", "n,w=map(int,input().split())\r\nl=list(map(int,input().split()))\r\np=[]\r\nfor i in range(n):\r\n\tif w%l[i]==0:\r\n\t\ts=int(w/l[i])\r\n\t\tp.append(s)\r\nprint(min(p))\r\n", "# import sys\r\n# sys.stdin = open(\"test.in\",\"r\")\r\n# sys.stdout = open(\"test.out\",\"w\")\r\nn,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nl=[]\r\nfor i in range(len(a)):\r\n\tif k%a[i]==0:\r\n\t\tl.append(int(k/a[i]))\r\nprint(min(l))\t\t", "n, k = map(int, input().split())\r\n\r\na = list(map(int, input().split()))\r\n\r\na.sort(reverse=True)\r\n\r\nfor x in a :\r\n if k % x == 0 :\r\n print(k//x)\r\n break\r\n", "x,y=map(int,input().split());a=list(map(int,input().split()))\r\nprint(min([y//i for i in a if y%i==0]))", "n, k = map(int, input().split())\r\nprint(k // max(ai for ai in map(int, input().split()) if k % ai == 0))", "n,k = map(int, input().split())\r\nval = list(map(int, input().split()))\r\nval.sort(reverse = True)\r\nfor i in val:\r\n if k % i ==0:\r\n print(k//i)\r\n break", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Jun 28 06:57:04 2019\r\n\r\n@author: avina\r\n\"\"\"\r\n\r\nn,k = map(int, input().split())\r\nl = list(map(int, input().split()))\r\na = 0\r\nfor i in range(n):\r\n if k % l[i] == 0 and l[i] > a:\r\n a = l[i]\r\nprint(k//a)\r\n ", "# cf 915 A 900\nn, k = map(int, input().split())\nA = [*map(int, input().split())]\n# k = length of garden\nans = 0\nfor a in sorted(A, reverse=True):\n if k % a == 0:\n ans = a\n break\nprint(k // ans)\n", "#B - Garden\n\n[n, k] = map(int, input().split())\n\na = list(map(int, input().split()))\nhours = [k / x if k % x == 0 else 101 for x in a ]\nprint('%d' % min(hours))\n\n \t\t\t \t\t\t \t \t \t \t\t\t \t\t\t\t\t\t\t\t", "__, size = (int(item) for item in input().split())\nprint(size // max([int(item) for item in input().split() if size % int(item) == 0]))", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort(reverse=True)\r\nfor i in range(n):\r\n\tif k%a[i]==0:\r\n\t\tprint(k//a[i])\r\n\t\tbreak", "n, k = map(int, input().split())\r\narr = list(map(int, input().split()))\r\n\r\nm = 9999\r\n\r\nfor num in arr:\r\n if k % num == 0:\r\n root = k // num\r\n if root < m:\r\n m = root\r\nprint(m)\r\n", "def sad(k, lst):\r\n maximum = 0\r\n for i in range(len(lst)):\r\n if k % lst[i] == 0 and lst[i] > maximum:\r\n maximum = lst[i]\r\n return k // maximum\r\n\r\n\r\nN, K = [int(j) for j in input().split()]\r\nb = [int(x) for x in input().split()]\r\nprint(sad(K, b))\r\n", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nmi=100000000000000000000000000000\r\nfor i in range(n):\r\n c=a[i]\r\n b=m//c\r\n if (b*c)==m:\r\n mi=min(mi,b)\r\nprint(mi)", "n,k=map(int,input().split())\r\nli=list(map(int,input().split()))\r\ns=0\r\nfor i in li[:n]:\r\n if k%i==0 and i>s:\r\n s=i\r\nprint(k//s)\r\n", "# Garden\ndef garden(k, arr):\n arr.sort(reverse=True)\n for i in arr:\n if k % i == 0:\n return k // i\n\n\nn, k = list(map(int, input().split()))\narr = list(map(int, input().split()))\nprint(garden(k, arr))\n", "n, k = map(int, input().split())\r\nres = float('inf')\r\nfor e in map(int, input().split()):\r\n if k % e == 0: res = min(res, k // e)\r\nprint(res)", "n,k=[int(i) for i in input().split()]\r\nx=[int(i) for i in input().split()]\r\nans=[]\r\nfor i in range(0,len(x)):\r\n if(k%x[i]==0):\r\n s=k//x[i]\r\n ans.append(s)\r\nprint(min(ans))", "n, k = map(int,input().split())\na = list(map(int,input().split()))\na.sort()\na.reverse()\nfor x in range(0, len(a)):\n\tif k % a[x] == 0:\n\t\t# print(x, a[x])\n\t\tprint(int(k / a[x]))\n\t\tbreak", "n, k = map(int, input().split())\r\nmas = list(map(int, input().split()))\r\nmas.sort()\r\nmas.reverse()\r\nfor i in range(n):\r\n if k%mas[i] == 0:\r\n print(k//mas[i])\r\n break", "k, n = map(int, input().split())\r\nm = list(map(int, input().split()))\r\nm.sort(reverse = 1)\r\nfor i in range(k):\r\n if n % m[i] == 0:\r\n print(n // m[i])\r\n break", "def solve():\r\n n, k = map(int, input().split())\r\n ans = 0\r\n for el in map(int, input().split()):\r\n if k % el == 0:\r\n ans = max(ans, el)\r\n print(k // ans)\r\n\r\n\r\nsolve()\r\n", "read=lambda:map(int,input().split())\r\nn,k=read()\r\nans=min(k//a for a in list(read()) if k%a==0)\r\nprint(ans)", "n, k = map(int, input().split())\r\n\r\ndaf = list(map(int, input().split()))\r\n\r\nmax_num = 0\r\n\r\nfor i in range(n):\r\n if k % daf[i] == 0:\r\n max_num = max(max_num, daf[i])\r\n\r\nprint(k // max_num)\r\n", "n,k = map(int,input().split())\r\na = sorted(list(map(int,input().split())),reverse=True)\r\nfor i in a:\r\n if k%i ==0:\r\n print(int(k/i))\r\n break", "n, k = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\nans = -1\r\nfor i in a:\r\n if k % i == 0:\r\n if ans == -1:\r\n ans = k // i\r\n else:\r\n ans = min(ans, k // i)\r\nprint(ans)", "n,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\na.sort()\r\na.reverse()\r\nfor i in range(n):\r\n if k % a[i] == 0:\r\n print(k//a[i])\r\n break", "min=101;y=0; n,k= map(int,input().split());a=[int(x) for x in input().split()]\r\nfor i in range(n):\r\n if k%a[i]==0:\r\n y=k//a[i]\r\n if y<min: min=y\r\nprint(min)", "n,k = map(int,input().split())\r\nlst = list(map(int,input().split()))\r\nlst.sort(reverse=True)\r\n\r\nfor i in lst:\r\n if k % i == 0:\r\n print(k//i)\r\n break", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nans = 10000000\r\nfor i in a:\r\n if k % i == 0:\r\n ans = min(ans, k//i)\r\nprint(ans)", "n, k = (int(t) for t in input().split())\nans = 10000\nc = map(int, input().split())\nfor ai in c:\n if k % ai == 0 and k / ai < ans:\n ans = k / ai\nprint(\"%d\" % ans)\n", "a=list(map(int, input().split()))\r\nb=list(map(int, input().split()))\r\nb.sort()\r\nfor i in range(int(a[0])):\r\n if(a[1]%b[len(b)-i-1]==0):\r\n print(int(a[1]/b[len(b)-i-1]))\r\n quit()", "n,k=[int(i) for i in input().split()]\r\na=[int(i) for i in input().split()]\r\nk_a=[]\r\nfor i in range(n):\r\n if k%a[i]==0:\r\n k_a.append(k/a[i])\r\nprint(int(min(k_a)))\r\n \r\n", "a, b = [int(i) for i in input().split()]\r\nl = [int(i) for i in input().split()]\r\ns = sorted(l)\r\nfor i in range(len(s)-1, -1, -1):\r\n if(b % s[i] == 0):\r\n print(b // s[i])\r\n break", "a = [int(i) for i in input().split()]\r\nb = sorted([int(i) for i in input().split()])\r\n\r\nfor i in range(a[0]):\r\n if a[1]%b[-1]==0:\r\n print(a[1]//b[-1])\r\n break\r\n else:\r\n b = b[:-1]", "\r\nl1 = list(map(int, input().split()))\r\nl2 = list(map(int, input().split()))\r\nl2.sort(reverse = True)\r\nfor i in l2:\r\n\tif l1[1] % i == 0:\r\n\t\tprint(l1[1] // i)\r\n\t\texit() ", "n, k = map(int, input().split())\r\nprint(k // max(filter(lambda v: k % v == 0, map(int, input().split()))))\r\n", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\na.reverse()\r\nfor i in a:\r\n if k%i==0:print(k//i);break", "import sys\r\noptions = []\r\n[n, k] = list(map(int, sys.stdin.readline().strip().split(' ')))\r\nbuckets = list(map(int, sys.stdin.readline().strip().split(' ')))\r\nfor i in range(len(buckets)):\r\n if (k % buckets[i] == 0):\r\n options.append(buckets[i])\r\n\r\nprint(k//max(options))", "read=lambda:map(int,input().split())\r\nn,k=read()\r\nans=k\r\nfor a in list(read()):\r\n if k%a==0:\r\n ans=min(ans,k//a)\r\nprint(ans)", "n,k=map(int,input().split(' '))\r\nb=0\r\nl=map(int,input().split(' '))\r\nfor i in l:\r\n \r\n if (i>b)& (k%i==0) :\r\n b=i\r\nprint(int(k/b))\r\n", "n,m=map(int,input().split())\r\narr=[int(i) for i in input().split()]\r\narr.sort(reverse=True)\r\nfor i in arr:\r\n if m%i==0:\r\n print(m//i)\r\n exit()", "A=input()\r\nA=A.split(\" \")\r\nB=input()\r\nB=B.split(\" \")\r\nC=[]\r\ni=0;\r\nwhile (i<len(B)):\r\n \r\n if (int(A[1])%int(B[i])==0):\r\n C.append(int(A[1])//int(B[i]))\r\n i+=1\r\nprint(min(C))\r\n \r\n", "n, k = (int(i) for i in input().split())\na = sorted((int(i) for i in input().split()), reverse=True)\nfor i in a:\n if k % i == 0:\n res = k // i\n break\nprint(res)\n", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nm=k\r\nfor i in a:\r\n if k%i==0 and (k/i)<m:\r\n m=(k/i)\r\nprint(int(m))\r\n \r\n", "n,k = map(int,input().split())\r\nmat = sorted(list(map(int,input().split())))[::-1]\r\nfor i in mat:\r\n if k % i == 0:\r\n print(k//i)\r\n break\r\n", "n, length = map(int, input().split())\r\nbuckets = list(map(int, input().split()))\r\nhours = float(\"inf\")\r\nfor b in buckets:\r\n if length % b == 0:\r\n hours = min(hours, length // b)\r\nprint(hours)\r\n", "n, k = map(int,input().split())\r\nar = list(map(int,input().split()))\r\n\r\nans = 10**10\r\nfor i in ar:\r\n\tif k % i == 0:\r\n\t\tans = min(ans, k // i)\r\nprint(ans)\r\n", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nans=1000000\r\nfor i in range(n):\r\n if k%a[i]!=0:\r\n pass\r\n else:\r\n ans=min(ans,k//a[i])\r\nprint(ans)\r\n \r\n", "n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nm=k\r\nfor i in l:\r\n\tif k%i==0 and k//i<m:\r\n\t\tm=k//i\r\nprint(m)\t\t", "n, k = map(int,input().split())\r\n\r\na = list(map(int,input().split()))\r\n\r\nminTime = 1000\r\n\r\nfor i in a:\r\n if k%i==0 and k/i<minTime:\r\n minTime = k/i\r\nprint(int(minTime))", "n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nv=[]\r\nfor i in range(n):\r\n\tif k%l[i]==0:\r\n\t\tv.append(l[i])\r\na=max(v)\r\n\r\nprint(k//a)", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=[]\r\nfor i in range(n):\r\n\tif k%a[i]==0:\r\n\t\tb.append(a[i])\r\nprint(int(k/max(b)))", "q=lambda:map(int,input().split())\r\nqi=lambda:int(input())\r\nqs=lambda:input().split()\r\nn,k=q()\r\nfor i in sorted(q())[::-1]:\r\n if k%i==0:\r\n print(k//i)\r\n break", "def Garden(n,k,a):\r\n\tminHrs = k\r\n\tfor b in a:\r\n\t\tif k%b==0:\r\n\t\t\tif minHrs > (k/b):\r\n\t\t\t\tminHrs = int(k/b)\r\n\r\n\treturn minHrs\r\n\r\nn,k = [int(x) for x in input().split()]\r\na = [int(x) for x in input().split()]\r\n\r\nprint(Garden(n,k,a))", "def main():\r\n n, k = list(map(int, input().split()))\r\n b = list(map(int, input().split()))\r\n b.sort(reverse=True)\r\n for num in b:\r\n if k % num == 0:\r\n print(k // num)\r\n return\r\nmain()", "n, k = [int(x) for x in input().split(' ')]\r\na = [int(x) for x in input().split(' ')]\r\nfor i in range(1, k + 1):\r\n if k % i == 0 and k // i in a:\r\n ans = i\r\n break\r\nprint(ans)", "import sys\r\nimport math\r\ninput = sys.stdin.readline\r\nfor _ in range(1):\r\n n,k = map(int,input().split())\r\n l = list(map(int,input().split()))\r\n ans = 10**18\r\n for i in l:\r\n if k%i == 0:\r\n ans = min(ans,k//i)\r\n\r\n print(ans)", "\r\nn , k = map(int , input().split())\r\n\r\na = [int(a) for a in input().split()]\r\n\r\nmn = k\r\n\r\nfor i in a:\r\n if k % i == 0:\r\n mn = min(mn , k // i)\r\n \r\nprint(mn)", "k = int(input().split()[1])\r\na = input().split()\r\n\r\nfor i in range(len(a)):\r\n a[i] = int(a[i])\r\n\r\nfor d in sorted(a, reverse=True):\r\n if k % d == 0:\r\n break\r\n\r\nprint (k // d)\r\n", "n, k = [int(i) for i in input().split()]\r\nS = [int(i) for i in input().split()]\r\nfor i in sorted(S, reverse=1):\r\n if k%i == 0:\r\n print(k//i)\r\n break\r\n", "[_,k]=list(map(int,input().split(' ')))\r\na=list(map(int,input().split(' ')))\r\nfor i in sorted(a,reverse=True):\r\n if k%i==0:\r\n break\r\nprint(k//i)\r\n", "#বিসমিল্লাহির রাহমানির রাহিম\r\n#بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ\r\n#Bismillahir Rahmanir Rahim\r\n#PROBLEM :A. Garden\r\nn,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nm=0\r\nfor i in l:\r\n if i>m and k%i==0:\r\n m=i\r\nprint(k//m)", "l1 = [int(x) for x in input().split()]\r\ntotal=l1[1]\r\nl2 = [int(x) for x in input().split()]\r\nl2.sort(reverse=True)\r\nans=1\r\nfor x in l2:\r\n if total%x==0:\r\n ans=x\r\n break\r\nans = total//ans\r\nprint(ans)", "#http://codeforces.com/problemset/problem/915/A\nnumBuckets, garLen = map(int, input().split())\nbuckets = list(map(int,input().split()))\nbiggest = 0\n\nfor x in buckets:\n\tif(garLen%x == 0 and x > biggest):\n\t\tbiggest = x\n\telse:\n\t\tpass\n\nprint(int(garLen/biggest))", "n, k = map(int, input().split())\nnum = [int(x) for x in input().split()]\nres = []\nfor i in num:\n if k % i == 0:\n res.append(k // i)\nprint(min(res))\n\n", "a=lambda:map(int,input().split());b,c=a()\r\nfor i in sorted(list(a()),reverse=True):\r\n if c%i==0:print(c//i);exit()", "n,k=map(int, input().split())\r\na=list(map(int, input().split()))\r\nx=0\r\nfor i in range(n):\r\n if k%a[i]==0 and a[i]>x:\r\n x=a[i]\r\nprint(k//x) \r\n", "c,k=map(int,input().split())\r\nL=list(map(int,input().split()))\r\na = max([x for x in L if k % x == 0])\r\nprint(k//a)", "n,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = [i for i in a if k%i==0]\r\nprint(k//max(b))\r\n", "n , k = map(int,input().split())\nd = list(map(int,input().split()))\nd = sorted(d)\nfor i in d[::-1]:\n if k%i==0:\n print(k//i)\n exit()\n", "buckets, target = map(int, input().split())\r\na = max([int(i) for i in input().split() if target % int(i) == 0])\r\nprint(target // a)", "nk = input().split(\" \")\r\nn = int(nk[0])\r\nk = int(nk[1])\r\na = input().split(\" \")\r\nmaxdivisible = 0\r\nfor i in a:\r\n if k % int(i) == 0:\r\n if maxdivisible == 0:\r\n maxdivisible = int(i)\r\n elif maxdivisible < int(i):\r\n maxdivisible = int(i)\r\nprint(int(k / maxdivisible))", "cantidades = [int(x) for x in input().split()]\r\na = [int(i) for i in input().split()]\r\n\r\n\r\ndef divide(s):\r\n if(cantidades[1]%s == 0):\r\n return True\r\n else:\r\n return False\r\n\r\n\r\ncand = filter(divide, a)\r\nprint(cantidades[1]//max(cand))\r\n", "a,b=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl1=[]\r\nfor i in range(a):\r\n if b%l[i]==0:\r\n l1.append(l[i])\r\nprint(b//max(l1))\r\n\r\n", "n , k = map(int , input().split())\r\na = list(map(int ,input().split()))\r\nr = 0\r\nb = []\r\nfor i in range(len(a)):\r\n if k%a[i] == 0:\r\n b.append(a[i])\r\nmax1 = max(b)\r\nprint(int(k/max1))", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\nfor i in a:\r\n if m % i==0:s=m/i\r\nprint(int(s))\r\n", "a,b=map(int,input().split())\r\nc=list(map(int,input().split()))\r\nc.sort()\r\no=0\r\nfor x in range(a):\r\n if b%c[x]==0:\r\n o=c[x]\r\nprint(b//o)", "L=int(input().split()[1])\r\nprint(L//max(d for d in map(int,input().split())if L%d==0))", "n,k = map(int,input().split())\r\narr = list(map(int,input().split()))\r\narr.sort()\r\nfor item in arr:\r\n if k/item == k//item:\r\n mn = k//item\r\nprint(mn)\r\n", "#-------------Program--------------\r\n#----Kuzlyaev-Nikita-Codeforces----\r\n#-------------Training-------------\r\n#----------------------------------\r\n\r\nn,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nm=0\r\nfor i in range(n):\r\n if k%a[i]==0 and a[i]>m:\r\n m=a[i]\r\nprint(k//m)", "# -*- coding: utf-8 -*-\r\n'''\r\nLuba thinks about watering her garden. The garden can be represented as a segment of length k.\r\nLuba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour.\r\nLuba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.\r\nt of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden.\r\nIt is guaranteed that Luba can always choose a bucket so it is possible water the garden.\r\nLuba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegmen\r\n\r\nSee the examples for better understanding.'''\r\n\r\n\r\ndef min_hours(N, list):\r\n n = N[0]\r\n k = N[1]\r\n list.sort()\r\n for i in range (n):\r\n if (k%list[i] == 0):\r\n bucket = int(list[i])\r\n return int(k / bucket) \r\n\r\nn = list(map(int, input().split()))\r\nl = list(map(int, input().split()))\r\nprint(min_hours(n, l))", "s = input().split()\r\nn = int(s[0])\r\nk = int(s[1])\r\nm = k\r\ns1 = input().split()\r\nfor i in range (n):\r\n if k % int(s1[i]) == 0:\r\n if k//int(s1[i]) < m:\r\n m = k//int(s1[i])\r\nprint(m)\r\n", "def run(k, a):\r\n a.sort(reverse=True)\r\n for x in a:\r\n if k % x == 0:\r\n return k // x\r\n\r\n\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nprint(run(k, a))\r\n", "f = lambda: map(int, input().split())\n\nn, k = f()\n\nprint(k // max(a for a in f() if not k % a))\n\n\n\n# Made By Mostafa_Khaled", "n,k=map(int,input().split())\r\nl=list(sorted(map(int,input().split())))\r\nans=0\r\nfor i in l:\r\n if k%i==0:\r\n ans=max(i,ans)\r\nprint(k//ans)\r\n", "# @author Matheus Alves dos Santos\n\nn_buckets, length = map(int, input().split())\nbuckets = list(map(int, input().split()))\nbuckets.sort(reverse = True)\n\n\nfor i in buckets:\n if (length % i == 0):\n print(length // i)\n break\n", "n,k=map(int,input().split())\r\nai=list(map(int,input().split()))\r\nb=0\r\nfor i in range(0,n):\r\n \r\n if k%ai[i] == 0 and ai[i]>b:\r\n b=ai[i]\r\nprint(k//b)\r\n\r\n", "n,k =[int (x) for x in input().split()]\r\ny= list( int(i) for i in input().split() )\r\nm=0;\r\nfor i in y:\r\n if(k%i == 0):\r\n if(i > m):\r\n m=i\r\nprint(int(k/m))", "n,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\na.sort()\r\nfor i in a:\r\n if k%i==0:\r\n b=i\r\nprint(k//b)", "n, k = list(map(int, input().split()))\r\na = sorted(list(map(int, input().split())))[::-1]\r\nfor b in a:\r\n if k % b == 0:\r\n print(k//b)\r\n break\r\n\r\n", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nprint(min([k//i for i in a if k%i==0]))", "n, k = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\nl = []\r\nfor i in a:\r\n\tif k % i == 0:\r\n\t\tl.append(i)\r\n\r\nprint(k//max(l))", "n_buckets, garden_len = map(int, input().split())\nbuckets = list(map(int, input().split()))\n\nchoice = max(b for b in buckets if garden_len % b == 0)\nprint(garden_len // choice)\n \t \t\t\t\t\t\t \t \t \t \t\t\t \t \t\t \t", "entry = input().split()\r\nobjectiveArea = int(entry[1])\r\n\r\n# Now we'll get the area that can be watered with each bucket\r\nbucketCapacity = input().split()\r\nfor current in range(len(bucketCapacity)):\r\n bucketCapacity[current] = int(bucketCapacity[current])\r\n\r\n# Let's find the biggest bucket that can water the Area exactly\r\nbestBucket = 0\r\n\r\nfor current in bucketCapacity:\r\n if objectiveArea/current == objectiveArea//current:\r\n if current > bestBucket:\r\n bestBucket = current\r\n\r\n# Now that we've found the right bucket, we'll calculate the time it would take\r\nprint(objectiveArea//bestBucket)", "n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl2=[]\r\nfor i in l:\r\n\tif k%i==0:\r\n\t\tl2.append(k//i)\r\nprint(min(l2))", "n, k = map(int, input().split())\r\n*a, = map(int, input().split())\r\nindex = -1\r\na.sort()\r\nwhile k % a[index]:\r\n index -= 1\r\nprint(k // a[index])\r\n", "n, k = [int(s) for s in input().split()]\r\na = [int(s) for s in input().split()]\r\nb = []\r\nfor i in a:\r\n if k % i == 0:\r\n b.append(k // i)\r\nprint(min(b))\r\n", "n, m = map(int, input().split())\nfor i in sorted(list(map(int, input().split())), reverse = True):\n if m % i == 0:\n print(m//i)\n exit()", "# from dust i have come dust i will be\n\nn,k=map(int,input().split())\na=list(map(int,input().split()))\n\na.sort()\n\nans=0\nfor i in a:\n if k%i==0:\n ans=k//i\n\nprint(ans)\n", "a=list(map(int,input().split()))\r\nc=list(map(int,input().split()))\r\nf=[]\r\nfor i in range(a[0]):\r\n if a[1]%c[i]==0 and c[i]<=a[1] or c[i]==1:\r\n f.append(c[i])\r\n else:\r\n continue\r\nf.sort()\r\nf.reverse()\r\nprint(int(a[1]/f[0]) if f!=[] else a[1])", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\nout = None\r\nfor ai in a:\r\n if k % ai == 0:\r\n if out is None:\r\n out = k // ai\r\n else:\r\n out = min(out, k // ai)\r\nprint(out)", "n, k = map(int, input().split())\r\nans = 1000000000000\r\nfor x in input().split():\r\n ans = min(k / int(x) if k % int(x) == 0 and k >= int(x) else 1000000000000, ans)\r\nprint(int(ans))\r\n", "n,k=map(int,input().split());\r\na=list(map(int,input().split()));\r\nL=[];\r\nfor i in range(n):\r\n if(k % a[i] == 0):\r\n L.append(k//a[i]);\r\nmin=L[0];\r\nfor j in range(1,len(L)):\r\n if (L[j]<min):\r\n min=L[j];\r\nprint(min);\r\n\r\n\r\n \r\n \r\n", "n,k=[int(x) for x in input().split()]\r\na=[int(x) for x in input().split()]\r\nres=200\r\nfor i in a:\r\n if k%i==0:\r\n res=min(res,k//i)\r\nprint(res)", "inp=lambda:map(int,input().split())\r\nn,k=inp()\r\n\r\na=list(inp())\r\n\r\nm=-1\r\nfor i in range(n):\r\n if k%a[i]==0: m=max(m,a[i])\r\n\r\nprint(int(k/m))", "n,k=map(int,input().split())\nList=[]\nList=input().split()\nfor i in range(n):\n List[i]=int(List[i])\n pass\nt=k\nfor i in range(n):\n if k%List[i]==0:\n Time=k//List[i]\n if t>Time:\n t=Time\n pass\n else:\n pass\n\n\nprint(t)\n\t \t \t\t\t \t\t\t\t\t\t\t \t\t\t \t \t\t \t", "_, k = map(int, input().split())\r\n\r\nfor a in sorted(map(int, input().split()), reverse=True):\r\n if k % a == 0:\r\n print(k // a)\r\n break", "n,k = [int(i) for i in input().split()]\nx = [int(i) for i in input().split()]\nminn = 1000\nfor i in x:\n if k%i == 0:\n minn = min(minn, k//i)\nprint(minn)\n", "n, k = input().split(' ')\nn = int(n)\nk = int(k)\n\na = list(map(int, input().split(' ')))\n\na.sort( reverse = True)\n\nfor i in a:\n if(k % i == 0):\n print(int(k/i))\n exit()\n\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\nx=101\r\nfor i in range(n):\r\n if(m%l[i]==0):\r\n a=min(m//l[i],x)\r\n x=a\r\nprint(a)", "n, k = map(int,input().split())\r\naps = 0\r\na = list(map(int,input().split()))\r\nfor i in a:\r\n if k%i == 0 and i > aps:\r\n aps = i\r\nprint(k//aps) ", "# NOME: Guilherme Lima Hernandez Rincao\n# RA: 169052\n# B - Garden\n\nn, k = map(int, input().split())\nb = map(int, input().split())\nc = filter(float.is_integer, map(lambda a: k / a, b))\nprint(int(min(c)))\n \t\t \t \t \t\t \t \t \t \t \t \t\t\t \t", "n, k = map(int, input().split())\r\nl = [int(x) for x in input().split()]\r\nmx = 0\r\n\r\nfor i in l:\r\n if k % i == 0:\r\n mx = max(mx, i)\r\n\r\nprint(k//mx)" ]
{"inputs": ["3 6\n2 3 5", "6 7\n1 2 3 4 5 6", "5 97\n1 10 50 97 2", "5 97\n1 10 50 100 2", "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 56 62 87 41 87 55 71 87 32 41 56 91 32 24 75 43 42 35 30 72 53 31 26 54 61 87 85 36 75 44 31 7 38 77 57 61 54 70 77 45 96 39 57 11 8 91 42 52 15 42 30 92 41 27 26 34 27 3 80 32 86 26 97 63 91 30 75 14 7 19 23 45 11 8 43 44 73 11 56 3 55 63 16", "100 91\n13 13 62 96 74 47 81 46 78 21 20 42 4 73 25 30 76 74 58 28 25 52 42 48 74 40 82 9 25 29 17 22 46 64 57 95 81 39 47 86 40 95 97 35 31 98 45 98 47 78 52 63 58 14 89 97 17 95 28 22 20 36 68 38 95 16 2 26 54 47 42 31 31 81 21 21 65 40 82 53 60 71 75 33 96 98 6 22 95 12 5 48 18 27 58 62 5 96 36 75", "8 8\n8 7 6 5 4 3 2 1", "3 8\n4 3 2", "3 8\n2 4 2", "3 6\n1 3 2", "3 6\n3 2 5", "3 8\n4 2 1", "5 6\n2 3 5 1 2", "2 6\n5 3", "4 12\n6 4 3 1", "3 18\n1 9 6", "3 9\n3 2 1", "3 6\n5 3 2", "2 10\n5 2", "2 18\n6 3", "4 12\n1 2 12 3", "3 7\n3 2 1", "3 6\n3 2 1", "5 10\n5 4 3 2 1", "5 16\n8 4 2 1 7", "6 7\n6 5 4 3 7 1", "2 6\n3 2", "2 4\n4 1", "6 8\n2 4 1 3 5 7", "6 8\n6 5 4 3 2 1", "6 15\n5 2 3 6 4 3", "4 8\n2 4 8 1", "2 5\n5 1", "4 18\n3 1 1 2", "2 1\n2 1", "3 10\n2 10 5", "5 12\n12 4 4 4 3", "3 6\n6 3 2", "2 2\n2 1", "3 18\n1 9 3", "3 8\n7 2 4", "2 100\n99 1", "4 12\n1 3 4 2", "3 6\n2 3 1", "4 6\n3 2 5 12", "4 97\n97 1 50 10", "3 12\n1 12 2", "4 12\n1 4 3 2", "1 1\n1", "3 19\n7 1 1", "5 12\n12 4 3 4 4", "3 8\n8 4 2", "3 3\n3 2 1", "5 6\n3 2 4 2 2", "2 16\n8 4", "3 6\n10 2 3", "5 3\n2 4 5 3 6", "11 99\n1 2 3 6 5 4 7 8 99 33 66", "3 12\n3 12 2", "5 25\n24 5 15 25 23", "2 4\n8 1", "4 100\n2 50 4 1", "3 28\n7 14 1", "4 8\n2 8 4 1", "4 6\n6 1 2 3", "2 12\n4 3", "4 12\n1 2 4 3", "5 12\n2 3 12 6 4", "4 4\n1 2 2 4", "3 6\n2 3 2", "4 21\n21 20 21 2", "3 8\n3 4 2", "1 25\n25", "99 12\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", "98 12\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", "79 12\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", "4 32\n1 1 1 1", "1 100\n1", "2 100\n7 1", "7 24\n1 3 6 4 5 2 7", "6 87\n1 2 8 4 5 7", "1 88\n1", "1 89\n1"], "outputs": ["2", "7", "1", "97", "50", "7", "1", "2", "2", "2", "2", "2", "2", "2", "2", "2", "3", "2", "2", "3", "1", "7", "2", "2", "2", "1", "2", "1", "2", "2", "3", "1", "1", "6", "1", "1", "1", "1", "1", "2", "2", "100", "3", "2", "2", "1", "1", "3", "1", "19", "1", "1", "1", "2", "2", "2", "1", "1", "1", "1", "4", "2", "2", "1", "1", "3", "3", "1", "1", "2", "1", "2", "1", "1", "1", "1", "32", "100", "100", "4", "87", "88", "89"]}
UNKNOWN
PYTHON3
CODEFORCES
379
1406f44b358d0fb8fc59355a2bc1ea3e
Binary Table
You are given a table consisting of *n* rows and *m* columns. Each cell of the table contains either 0 or 1. In one move, you are allowed to pick any row or any column and invert all values, that is, replace 0 by 1 and vice versa. What is the minimum number of cells with value 1 you can get after applying some number of operations? The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=20, 1<=≤<=*m*<=≤<=100<=000) — the number of rows and the number of columns, respectively. Then *n* lines follows with the descriptions of the rows. Each line has length *m* and contains only digits '0' and '1'. Output a single integer — the minimum possible number of ones you can get after applying some sequence of operations. Sample Input 3 4 0110 1010 0111 Sample Output 2
[ "from functools import reduce\r\n\r\nn, m = map(int, input().split())\r\na = [input() for _ in range(n)]\r\na = list(map(lambda x: reduce(lambda x, y: x * 2 + int(y), x, 0), zip(*a)))\r\n \r\nS = 1 << n\r\nf, g = [0] * S, [0] * S\r\nfor x in a:\r\n g[x] += 1\r\nfor mask in range(S):\r\n k = bin(mask).count('1')\r\n f[mask] = min(k, n - k)\r\n\r\ndef walsh_hadamard_transform(a, inverse = False):\r\n n = len(a)\r\n assert((n & (n - 1)) == 0)\r\n step = 1;\r\n while step < n:\r\n for i in range(n):\r\n if (i & step) == 0:\r\n a[i], a[i + step] = a[i] + a[i + step], a[i] - a[i + step]\r\n step <<= 1\r\n if inverse:\r\n for i in range(n):\r\n a[i] //= n\r\n\r\n# print(a)\r\n# print(f)\r\n# print(g)\r\nwalsh_hadamard_transform(f)\r\nwalsh_hadamard_transform(g)\r\nfor i in range(S):\r\n f[i] *= g[i]\r\nwalsh_hadamard_transform(f, True)\r\nans = min(f)\r\nprint(ans)" ]
{"inputs": ["3 4\n0110\n1010\n0111", "1 1\n0", "1 1\n1", "2 1\n0\n1", "1 2\n10", "2 2\n01\n10", "2 2\n11\n10", "2 2\n00\n00", "2 2\n00\n11", "3 3\n100\n010\n001", "3 9\n010100100\n101011011\n101011101", "8 3\n000\n001\n010\n100\n110\n011\n101\n111", "1 10\n0110010001", "9 1\n0\n1\n1\n0\n1\n0\n1\n0\n1", "4 5\n01010\n10101\n01011\n10101", "5 5\n11110\n11101\n11011\n10111\n01111", "20 20\n00010110100100010111\n11110000001100101110\n01110101110001111000\n10111101000111111110\n10000101011000000011\n00010010001011010000\n00000110010110111111\n01010101000101101110\n01001110110001000011\n10111111010011101111\n10011010000110101101\n10000111011001001111\n11111110110100010100\n10111001010101001011\n11110011100010110000\n10100011011110110110\n01100111101101000000\n11100100011101100010\n10000110110111101100\n10110000101100110011"], "outputs": ["2", "0", "0", "0", "0", "0", "1", "0", "0", "2", "2", "6", "0", "0", "1", "5", "138"]}
UNKNOWN
PYTHON3
CODEFORCES
1
141fac17f61c95c45f5139058556a5cd
Four Segments
You are given an array of *n* integer numbers. Let *sum*(*l*,<=*r*) be the sum of all numbers on positions from *l* to *r* non-inclusive (*l*-th element is counted, *r*-th element is not counted). For indices *l* and *r* holds 0<=≤<=*l*<=≤<=*r*<=≤<=*n*. Indices in array are numbered from 0. For example, if *a*<==<=[<=-<=5,<=3,<=9,<=4], then *sum*(0,<=1)<==<=<=-<=5, *sum*(0,<=2)<==<=<=-<=2, *sum*(1,<=4)<==<=16 and *sum*(*i*,<=*i*)<==<=0 for each *i* from 0 to 4. Choose the indices of three delimiters *delim*0, *delim*1, *delim*2 (0<=≤<=*delim*0<=≤<=*delim*1<=≤<=*delim*2<=≤<=*n*) and divide the array in such a way that the value of *res*<==<=*sum*(0,<=*delim*0) - *sum*(*delim*0,<=*delim*1) + *sum*(*delim*1,<=*delim*2) - *sum*(*delim*2,<=*n*) is maximal. Note that some of the expressions *sum*(*l*,<=*r*) can correspond to empty segments (if *l*<==<=*r* for some segment). The first line contains one integer number *n* (1<=≤<=*n*<=≤<=5000). The second line contains *n* numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (<=-<=109<=≤<=*a**i*<=≤<=109). Choose three indices so that the value of *res* is maximal. If there are multiple answers, print any of them. Sample Input 3 -1 2 3 4 0 0 -1 0 1 10000 Sample Output 0 1 3 0 0 0 1 1 1
[ "n = int(input())\nnums = [int(x) for x in input().split()]\n\nbest = [None for x in range(len(nums))]\nway = [None for x in range(len(nums))]\n\n\ndef find_best_way():\n global best, n, nums, way\n\n for j in range(n - 1, -1, -1):\n best[j] = dict()\n way[j] = dict()\n\n previous = {'s1':0, 's2':0, 's3':0, 's4':0} if j + 1 == n else best[j + 1]\n\n best[j]['s1'] = -nums[j] + previous['s1']\n way[j]['s1'] = 's1'\n \n for i in range(2, 5):\n changed = (1 if i % 2 == 0 else -1) * nums[j] + previous[f's{i}']\n unchanged = (-1 if i % 2 == 0 else 1) * nums[j] + previous[f's{i - 1}']\n\n if (unchanged >= changed):\n best[j][f's{i}'] = unchanged\n way[j][f's{i}'] = f's{i - 1}'\n continue\n\n best[j][f's{i}'] = changed\n way[j][f's{i}'] = f's{i}'\n\n\ndef get_delimiters():\n global way, nums, n\n qnt = {'s1':0, 's2':0, 's3':0, 's4':0}\n\n s = 's4'\n for i in range(n):\n qnt[way[i][s]] += 1\n s = way[i][s]\n \n d1 = qnt['s4']\n d2 = d1 + qnt['s3']\n d3 = d2 + qnt['s2']\n\n return d1, d2, d3\n\nfind_best_way()\n#print(best[0]['s4'])\nprint(*get_delimiters())\n#print(way)\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\ns = [0]*(n+1)\r\nfor i in range(1, n+1):\r\n s[i] = s[i-1] + a[i-1]\r\nres, x, y, z, i = 0, 0, 0, 0, 0\r\nfor j in range(0, n+1):\r\n if s[j] > s[i]:\r\n i = j\r\n for k in range(j, n+1):\r\n if s[i] - s[j] + s[k] > res:\r\n res = s[i] - s[j] + s[k]\r\n x, y, z = i, j, k\r\n #print(x, y, z, res)\r\nprint(x, y, z)\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ntotal = sum(a)\r\nf = [[]] * (n + 1)\r\nf[0] = [0, 0]\r\nsum = 0\r\nfor i in range(1, n + 1):\r\n sum += a[i - 1]\r\n if sum > f[i - 1][0]:\r\n f[i] = [sum, i]\r\n else:\r\n f[i] = f[i - 1]\r\ni = j = k = 0\r\nans = -1e9\r\nlastK = n\r\nsum = 0\r\nfor l in range(n, 0, -1):\r\n v = sum + f[l][0]\r\n if v - (total - v) > ans:\r\n i = f[l][1]\r\n j = l\r\n k = lastK\r\n ans = v - (total - v)\r\n sum += a[l - 1]\r\n if sum < 0:\r\n lastK = l - 1\r\n sum = 0\r\nprint(i, j, k)\r\n", "import sys\r\ninput = lambda: sys.stdin.readline().strip()\r\nfrom math import inf as inf\r\nn = int(input())\r\na = list(map(int, input().split()))\r\npref = [0] * (n + 1)\r\nfor i in range(n):\r\n pref[i + 1] = pref[i] + a[i]\r\nri, rj, rk = -1, -1, -1\r\nmx = -inf\r\nfor i in range(n + 1):\r\n cur1 = cur2 = i\r\n for j in range(0, i + 1):\r\n if pref[j] > pref[cur1]:\r\n cur1 = j\r\n for j in range(i, n + 1):\r\n if pref[j] > pref[cur2]:\r\n cur2 = j\r\n if pref[cur1] - (pref[i] - pref[cur1]) + (pref[cur2] - pref[i]) - (pref[n] - pref[cur2]) > mx:\r\n mx = pref[cur1] - (pref[i] - pref[cur1]) + (pref[cur2] - pref[i]) - (pref[n] - pref[cur2])\r\n ri, rj, rk = cur1, i, cur2\r\nprint(ri, rj, rk)", "import os,sys,collections,heapq,itertools\r\nif os.path.exists('in.txt'):\r\n file = open('in.txt') \r\n input = file.readline \r\nelse : \r\n input = sys.stdin.readline \r\nfrom functools import reduce \r\nfrom itertools import accumulate,chain,combinations,count \r\nfrom itertools import groupby,permutations,product,zip_longest\r\nfrom heapq import heapify,heappush,heappop,heapreplace,merge,nlargest,nsmallest\r\nfrom collections import Counter,defaultdict,deque \r\nfrom bisect import bisect_left, bisect_right\r\nfrom math import comb,floor,ceil,inf ,gcd ,sqrt \r\nimport functools \r\nreadi = lambda: int(input()) \r\nreadis = lambda: list(map(int,input().split()))\r\nreads = lambda: input().rstrip() \r\nreadss = lambda: input().split() \r\ndef solution(): \r\n n = readi() \r\n a = readis() \r\n S = [0] + list(accumulate(a)) \r\n p1 = [0,0] \r\n P2 = [] \r\n for i,s in enumerate(S):\r\n p1 = max(p1, [s,i] ) \r\n P2.append(tuple([2*p1[0]-s,p1[1]])) \r\n \r\n p4 = [0,n] \r\n P3 = [None] * n + [tuple([0,n,n])]\r\n s = 0 \r\n for i in range(n-1,-1,-1):\r\n s += a[i] \r\n p4 = min(p4,[s,i]) \r\n P3[i] = tuple([s-p4[0]*2,p4[1]]) \r\n res = [0,0,0,0]\r\n for i2,(a,b) in enumerate(zip(P2,P3)):\r\n res = max(res,[a[0]+b[0],a[1],i2,b[1]]) \r\n print(*res[1:])\r\nfor i in range(1):\r\n solution() ", "# https://www.acwing.com/blog/content/34755/\r\n\r\n\r\ndef solve():\r\n n = int(input())\r\n w = [int(i) for i in input().split()]\r\n w.insert(0, 0)\r\n s = [0] * (n + 1)\r\n for i in range(1, n + 1): s[i] = s[i - 1] + w[i]\r\n g1 = [0] * (n + 1)\r\n idx = [0] * (n + 1)\r\n for i in range(1, n + 1):\r\n g1[i] = max(g1[i - 1], s[i])\r\n if g1[i] == s[i]: idx[i] = i\r\n else: idx[i] = idx[i - 1]\r\n res = -1e18\r\n S, idx1 = s[n], n\r\n for i in range(n, -1, -1):\r\n if S < s[i]:\r\n S = s[i]\r\n idx1 = i\r\n tmp = g1[i] - s[i] + S\r\n if tmp > res:\r\n res = tmp\r\n # print(res)\r\n ans = [idx[i], i, idx1]\r\n print(ans[0], ans[1], ans[2])\r\n\r\ndef main():\r\n solve()\r\n\r\nif __name__ == '__main__':\r\n main()", "n = int(input())\r\na = list(map(int, input().split()))\r\ns = [0]*(n+1)\r\nfor i in range(1, n+1):\r\n s[i] = s[i-1] + a[i-1]\r\nres, x, y, z = 0, 0, 0, 0\r\nfor i in range(0, n+1):\r\n j = i\r\n for k in range(i, n+1):\r\n if s[k] < s[j]:\r\n j = k\r\n if s[i] + s[k] - s[j] > res:\r\n res = s[i] + s[k] - s[j]\r\n x, y, z = i, j, k\r\nprint(x, y, z)", "n = int(input())\r\na = list(map(int, input().split()))\r\nS = [0] * (n + 1)\r\nfor i in range(1, n + 1):\r\n S[i] = S[i - 1] + a[i - 1]\r\n# max(2*S[i] - S[n]) 0-n区间\r\nmaxPreS = [0] * (n + 1)\r\nfor i in range(1, n + 1):\r\n if S[maxPreS[i - 1]] < S[i]:\r\n maxPreS[i] = i\r\n else:\r\n maxPreS[i] = maxPreS[i - 1]\r\nmaxSufS = [n] * (n + 1)\r\nfor i in range(n - 1, -1, -1):\r\n if S[maxSufS[i + 1]] < S[i]:\r\n maxSufS[i] = i\r\n else:\r\n maxSufS[i] = maxSufS[i + 1]\r\nans_i = -1\r\nans_j = -1\r\nans_k = -1\r\nmax_count = -10**18\r\nfor j in range(n + 1):\r\n i = maxPreS[j]\r\n k = maxSufS[j]\r\n count = 2*S[i] - 2*S[j] + 2*S[k] - S[-1]\r\n if count > max_count:\r\n ans_i = i\r\n ans_j = j\r\n ans_k = k\r\n max_count = count\r\n# print(max_count)\r\nprint(ans_i,ans_j,ans_k)", "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\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\nMOD = 10**9+7\r\n\r\ndef solve():\r\n n = II()\r\n a = LII()\r\n s = list(accumulate(a, initial=0))\r\n left, right = [0] * (n+1), [n] * (n+1)\r\n for i in range(1, n+1):\r\n left[i] = i if s[i] > s[left[i-1]] else left[i-1]\r\n for i in range(n-1, -1, -1):\r\n right[i] = i if s[i] > s[right[i+1]] else right[i+1]\r\n\r\n res = []\r\n mx = -inf\r\n for j in range(n+1):\r\n i, k = left[j], right[j]\r\n cur = s[i]+s[k]-s[j]\r\n if cur > mx:\r\n mx = cur\r\n res = [i, j, k]\r\n print(*res)\r\n return\r\n\r\nsolve()\r\n", "import math\r\nimport sys\r\nimport time\r\nfrom bisect import bisect_left, bisect_right\r\nfrom collections import Counter, deque, defaultdict\r\nfrom itertools import permutations\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\n\r\nn = ii()\r\na = lii()\r\nl = [0] * (1 + n)\r\nr = [0] * (1 + n)\r\nacc = 0\r\npre = [0] * (n + 1)\r\nsuf = [0] * (1 + n)\r\nmpl, mpr = 0, n\r\nfor i in range(n):\r\n pre[i + 1] += pre[i] + a[i]\r\nfor i in range(n - 1, -1, -1):\r\n suf[i] += suf[i + 1] + a[i]\r\nfor i in range(n + 1):\r\n l[i] = mpl\r\n if i == n:break\r\n acc -= a[i]\r\n if pre[i + 1] > pre[mpl]:\r\n mpl = i + 1\r\nacc = 0\r\nfor i in range(n, -1, -1):\r\n acc += (a[i] if i < n else 0)\r\n if suf[i] < suf[mpr]:\r\n mpr = i\r\n r[i] = mpr\r\nans = [0, 0, 0]\r\nfor j in range(n + 1):\r\n i, k = l[j], r[j]\r\n a, b, c = ans\r\n if -pre[j] + 2 * pre[i] + suf[j] - 2 * suf[k] > -pre[b] + 2 * pre[a] + suf[b] - 2 * suf[c]:\r\n ans = [i, j, k]\r\nprint(*ans)\r\n", "\r\nimport sys\r\nfrom math import inf\r\n\r\n\r\nclass FastIO:\r\n def __init__(self):\r\n return\r\n\r\n @staticmethod\r\n def read_str():\r\n return sys.stdin.readline().rstrip()\r\n\r\n @staticmethod\r\n def read_int():\r\n return int(sys.stdin.readline().rstrip())\r\n\r\n @staticmethod\r\n def read_ints():\r\n return map(int, sys.stdin.readline().rstrip().split())\r\n\r\n @staticmethod\r\n def read_float():\r\n return float(sys.stdin.readline().rstrip())\r\n\r\n @staticmethod\r\n def read_list_str():\r\n return list(sys.stdin.readline().rstrip())\r\n\r\n @staticmethod\r\n def read_list_ints():\r\n return list(map(int, sys.stdin.readline().rstrip().split()))\r\n\r\n @staticmethod\r\n def st(x):\r\n return print(x)\r\n\r\n @staticmethod\r\n def lst(x):\r\n return print(*x)\r\n\r\n @staticmethod\r\n def max(a, b):\r\n return a if a > b else b\r\n\r\n @staticmethod\r\n def min(a, b):\r\n return a if a < b else b\r\n\r\n @staticmethod\r\n def accumulate(nums):\r\n n = len(nums)\r\n pre = [0] * (n + 1)\r\n for i in range(n):\r\n pre[i + 1] = pre[i] + nums[i]\r\n return pre\r\n\r\n\r\nclass Solution:\r\n def __init__(self):\r\n return\r\n\r\n @staticmethod\r\n def main(ac=FastIO()):\r\n n = ac.read_int()\r\n nums = ac.read_list_ints()\r\n pre = ac.accumulate(nums)\r\n left = [0] * (n + 1)\r\n for i in range(1, n + 1):\r\n left[i] = i if pre[i] > pre[left[i - 1]] else left[i - 1]\r\n\r\n right = [n] * (n + 1)\r\n for i in range(n - 1, -1, -1):\r\n right[i] = i if pre[i] > pre[right[i + 1]] else right[i + 1]\r\n ans = []\r\n val = -inf\r\n for j in range(n + 1):\r\n i, k = left[j], right[j]\r\n if pre[i] + pre[k] - pre[j] > val:\r\n val = pre[i] + pre[k] - pre[j]\r\n ans = [i, j, k]\r\n ac.lst(ans)\r\n return\r\n\r\n\r\nSolution().main()\r\n", "class MaxSegTree:\r\n def __init__(self, zero, data=None, size=None):\r\n if data is None and size is None:\r\n raise Exception('data and size both cannot be None simultaneously')\r\n if size is None:\r\n size = len(data)\r\n depth = (size-1).bit_length()\r\n self.size = 1 << depth\r\n self.zero = zero\r\n if data is None:\r\n self.data = [zero]*(2*self.size)\r\n else:\r\n self.data = [zero]*self.size + data + [zero]*(self.size-size)\r\n for d in reversed(range(depth)):\r\n t = 1 << d\r\n for i in range(t, 2*t):\r\n self.data[i] = max(self.data[2*i],self.data[2*i+1])\r\n\r\n def _max_interval(self, a, b):\r\n result = self.zero\r\n a += self.size\r\n b += self.size\r\n while a < b:\r\n if a & 1:\r\n result = max(result,self.data[a])\r\n a += 1\r\n if b & 1:\r\n b -= 1\r\n result = max(result,self.data[b])\r\n a >>= 1\r\n b >>= 1\r\n return result\r\n\r\n def _set_val(self, a, val):\r\n a += self.size\r\n while self.data[a] != val and a > 0:\r\n self.data[a] = val\r\n val = max(val,self.data[a^1])\r\n a >>= 1\r\n\r\n def __getitem__(self, i):\r\n if isinstance(i, slice):\r\n return self._max_interval(\r\n 0 if i.start is None else i.start,\r\n self.size if i.stop is None else i.stop)\r\n elif isinstance(i, int):\r\n return self.data[i+self.size]\r\n\r\n def __setitem__(self, i, x):\r\n self._set_val(i,x)\r\n\r\n def __iter__(self):\r\n return iter(self.data[self.size:])\r\n\r\nn = int(input())\r\n\r\nfrom itertools import accumulate, chain\r\n\r\nC = list((v,i) for i,v in enumerate(chain((0,), accumulate(map(int,input().split())))))\r\n\r\nmst = MaxSegTree((-float('inf'),0),C)\r\n\r\na,b,c = None,None,None\r\nbest = -float('inf')\r\n\r\nfor v2,j in C:\r\n v1,i = mst[:j+1]\r\n v3,k = mst[j:]\r\n if v1-v2+v3 > best:\r\n best = v1-v2+v3\r\n a,b,c = i,j,k\r\n \r\nprint(a,b,c)\r\n", "n=int(input())\r\na=[5]+list(map(int,input().split()))\r\ndp=[[[i,0] for i in range(n+1)] for j in range(4)]\r\nend=n\r\nindx_a,indx_b,indx_c=0,0,0\r\nfor i in range(1,n+1):\r\n dp[0][i][1]=dp[0][i-1][1]+a[i]\r\n dp[1][i][1]=max(dp[0][i-1][1],dp[1][i-1][1])-a[i]\r\n dp[2][i][1]=max(dp[1][i-1][1],dp[2][i-1][1])+a[i]\r\n dp[3][i][1]=max(dp[2][i-1][1],dp[3][i-1][1])-a[i]\r\ndp_indx=[0,0,0,0]\r\nindx=0\r\npt=3\r\nfor i in range(n,0,-1):\r\n if dp[pt][i][1] < dp[pt-1][i][1] :\r\n pt-=1\r\n dp_indx[pt]=i\r\n if pt==0:\r\n break\r\nprint(dp_indx[0],dp_indx[1],dp_indx[2])", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nl = list(a)\r\nr = list(a)\r\nfor i in range(n - 1):\r\n l[i + 1] += l[i]\r\nfor i in range(n - 1, 0, -1):\r\n r[i - 1] += r[i]\r\nlm = [0] * (n + 1)\r\nrm = [0] * (n + 1)\r\nfor i in range(n):\r\n lm[i + 1] = max(lm[i], l[i])\r\nfor i in range(n - 1, -1, -1):\r\n rm[i] = min(rm[i + 1], r[i])\r\nl = [0] + l\r\nr = r + [0]\r\ninf = 1145141919810893931\r\nma = -inf\r\nc = -1\r\nfor i in range(n + 1):\r\n x = 2 * lm[i] - l[i]\r\n y = r[i] - 2 * rm[i]\r\n if ma < x + y:\r\n ma = x + y\r\n c = i\r\nans = []\r\nlmi = lm[c]\r\nfor i in range(c + 1):\r\n if lmi == l[i]:\r\n ans.append(i)\r\n break\r\nans.append(c)\r\nrmi = rm[c]\r\nfor i in range(c, n + 1):\r\n if rmi == r[i]:\r\n ans.append(i)\r\n break\r\nprint(*ans)", "\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n\r\n s = [0] * (n+1)\r\n for i in range(1, n+1):\r\n s[i] = s[i-1] + a[i-1]\r\n\r\n res = float(\"-inf\")\r\n p1, p2, p3 = 0, 0, 0\r\n for j in range(1, n+1):\r\n v1 = float(\"-inf\")\r\n v2 = float(\"-inf\")\r\n p11, p12, p13 = 0, 0, 0\r\n for i in range(1, j+1):\r\n a, b = 0, 0\r\n if i > 1:\r\n a = s[i-1] - s[0]\r\n if j > i:\r\n b = s[j-1] - s[i-1]\r\n if a - b > v1:\r\n v1 = a - b \r\n p11 = i\r\n \r\n for k in range(j, n+2):\r\n a, b = 0, 0\r\n if k > j:\r\n a = s[k-1] - s[j-1]\r\n if n+1 > k:\r\n b = s[n] - s[k-1]\r\n if a - b > v2:\r\n v2 = a - b \r\n p13 = k\r\n \r\n if v1 + v2 > res:\r\n res = v1 + v2 \r\n p12 = j\r\n p1, p2, p3 = p11, p12, p13\r\n print(p1-1, p2-1, p3-1) \r\n" ]
{"inputs": ["3\n-1 2 3", "4\n0 0 -1 0", "1\n10000", "1\n-1", "1\n0", "10\n0 0 0 0 0 0 0 0 0 0", "100\n-1 -1 0 1 -1 0 0 -1 -1 1 1 0 1 0 -1 1 0 0 -1 0 0 0 1 0 0 1 1 1 1 0 -1 -1 0 0 0 1 1 -1 0 0 1 1 1 0 -1 -1 0 -1 0 -1 -1 0 1 0 1 -1 1 -1 -1 -1 0 0 -1 0 -1 -1 0 -1 1 1 -1 1 0 1 -1 -1 1 1 -1 1 0 -1 1 -1 1 1 1 1 1 -1 0 1 0 0 -1 0 1 1 -1 -1", "100\n2 1 -2 -1 -2 0 -1 -2 1 2 0 1 0 -2 -1 -2 0 2 0 1 -2 -2 2 0 -2 2 -2 0 2 0 2 0 -1 0 -2 2 -1 -1 -2 -1 0 -2 2 0 -2 -2 -2 -1 1 0 -2 -1 2 -1 -2 1 -1 1 1 2 -2 1 -2 1 2 2 -2 1 -2 0 -1 -1 -2 -2 1 0 -1 -1 2 0 2 0 -1 2 1 -1 2 0 2 1 1 1 -1 -1 1 -2 0 0 -2 0", "10\n-6 -4 -7 0 7 9 8 3 8 7", "4\n-1 1 -2 -2", "2\n-3 -1"], "outputs": ["0 1 3", "0 0 0", "0 0 1", "0 0 0", "0 0 0", "0 0 0", "43 68 98", "2 78 92", "0 3 10", "0 1 2", "0 0 0"]}
UNKNOWN
PYTHON3
CODEFORCES
15
14224c4b4244d0fe292621f678e1422f
none
From beginning till end, this message has been waiting to be conveyed. For a given unordered multiset of *n* lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation *n*<=-<=1 times: - Remove any two elements *s* and *t* from the set, and add their concatenation *s*<=+<=*t* to the set. The cost of such operation is defined to be , where *f*(*s*,<=*c*) denotes the number of times character *c* appears in string *s*. Given a non-negative integer *k*, construct any valid non-empty set of no more than 100<=000 letters, such that the minimum accumulative cost of the whole process is exactly *k*. It can be shown that a solution always exists. The first and only line of input contains a non-negative integer *k* (0<=≤<=*k*<=≤<=100<=000) — the required minimum cost. Output a non-empty string of no more than 100<=000 lowercase English letters — any multiset satisfying the requirements, concatenated to be a string. Note that the printed string doesn't need to be the final concatenated string. It only needs to represent an unordered multiset of letters. Sample Input 12 3 Sample Output abababab codeforces
[ "n = int(input())\ndef locos(n):\n cos = 0\n i = 1\n while cos + i <= n:\n cos += i\n i += 1\n return i , cos\n\n\nrtn = ''\nfor i in \"abcdefghijklmnopqrstuvwxyz\":\n #print(locos(n))\n num , cos = locos(n)\n #print(num)\n rtn += i * num\n n -= cos\n if(n == 0): break\nprint(rtn)\n", "\r\nimport sys\r\n#sys.stdin=open(\"data.txt\")\r\ninput=sys.stdin.readline\r\n\r\nk=int(input())\r\n\r\nif k==0:\r\n print(\"a\")\r\nelse:\r\n dp=[0]*100005\r\n dp[2]=1\r\n for i in range(3,100005):\r\n j=i//2\r\n dp[i]=j*(i-j)+dp[j]+dp[i-j]\r\n if 0:\r\n # brute force check\r\n for j in range(1,i//2+1):\r\n if dp[i]>j*(i-j)+dp[j]+dp[i-j]:\r\n print(\"fail\",i,j)\r\n out=\"\"\r\n num=0\r\n for i in range(2,100005)[::-1]:\r\n while k>=dp[i]:\r\n out+=chr(num+ord('a'))*i\r\n num+=1\r\n k-=dp[i]\r\n print(out)", "# -*- coding: utf-8 -*-\r\n\r\nimport math\r\nimport collections\r\nimport bisect\r\nimport heapq\r\nimport time\r\nimport random\r\nimport itertools\r\n\r\n\"\"\"\r\ncreated by shhuan at 2017/10/20 09:16\r\n\r\n\"\"\"\r\n\r\nK = int(input())\r\n\r\nans = \"\"\r\nfor i in range(26):\r\n cnt = 1\r\n while (cnt+1)*cnt//2 <= K:\r\n cnt += 1\r\n K -= cnt*(cnt-1)//2\r\n ans += chr(ord('a')+i)*cnt\r\n\r\nprint(ans)\r\n", "k = int(input())\n\nans = \"\"\ncost = 0\nfor c in [chr(ord('a') + i) for i in range(26)]:\n i = 0\n while cost + i <= k:\n ans += c\n cost += i\n i += 1\n\nprint(ans)\n", "k = int(input())\r\nstr = 'a'\r\ni = 0\r\nif k == 0:\r\n print('a')\r\nwhile k:\r\n while k - i >= 0:\r\n k -= i\r\n print(str, end='')\r\n i += 1\r\n str = chr(ord(str) + 1)\r\n i = 0\r\nprint()\r\n#bobfut.near moondance", "k = int(input())\r\nres = []\r\nfor i in range(26):\r\n c = 1\r\n while c*(c+1)//2 <= k:\r\n c += 1\r\n k -= c*(c-1)//2\r\n res.extend([chr(i+97)]*c)\r\nprint(''.join(res))\r\n", "k = int(input())\r\nres, t = \"\", 0\r\nchars = [chr(ord('a')+i) for i in range(26)]\r\nfor c in chars:\r\n i = 0\r\n while t + i <= k:\r\n res += c\r\n t += i\r\n i += 1\r\nprint(res)\r\n", "\"\"\"codeforces.com/problemset/problem/848/A\"\"\"\nimport math\n\nk = int(input())\nif k == 0:\n print(\"a\")\n exit()\nl = []\nwhile k != 0:\n n = math.floor((1 + math.sqrt(1+8*k))/2)\n l.append(n)\n k -= n*(n-1)/2\nword = \"\"\nletter = 'a'\nfor chc in l:\n word += letter * chc\n letter = chr(ord(letter) + 1)\nprint(word)\n", "arr=[0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300, 325, 351, 378, 406, 435, 465, 496, 528, 561, 595, 630, 666, 703, 741, 780, 820, 861, 903, 946, 990, 1035, 1081, 1128, 1176, 1225, 1275, 1326, 1378, 1431, 1485, 1540, 1596, 1653, 1711, 1770, 1830, 1891, 1953, 2016, 2080, 2145, 2211, 2278, 2346, 2415, 2485, 2556, 2628, 2701, 2775, 2850, 2926, 3003, 3081, 3160, 3240, 3321, 3403, 3486, 3570, 3655, 3741, 3828, 3916, 4005, 4095, 4186, 4278, 4371, 4465, 4560, 4656, 4753, 4851, 4950, 5050, 5151, 5253, 5356, 5460, 5565, 5671, 5778, 5886, 5995, 6105, 6216, 6328, 6441, 6555, 6670, 6786, 6903, 7021, 7140, 7260, 7381, 7503, 7626, 7750, 7875, 8001, 8128, 8256, 8385, 8515, 8646, 8778, 8911, 9045, 9180, 9316, 9453, 9591, 9730, 9870, 10011, 10153, 10296, 10440, 10585, 10731, 10878, 11026, 11175, 11325, 11476, 11628, 11781, 11935, 12090, 12246, 12403, 12561, 12720, 12880, 13041, 13203, 13366, 13530, 13695, 13861, 14028, 14196, 14365, 14535, 14706, 14878, 15051, 15225, 15400, 15576, 15753, 15931, 16110, 16290, 16471, 16653, 16836, 17020, 17205, 17391, 17578, 17766, 17955, 18145, 18336, 18528, 18721, 18915, 19110, 19306, 19503, 19701, 19900, 20100, 20301, 20503, 20706, 20910, 21115, 21321, 21528, 21736, 21945, 22155, 22366, 22578, 22791, 23005, 23220, 23436, 23653, 23871, 24090, 24310, 24531, 24753, 24976, 25200, 25425, 25651, 25878, 26106, 26335, 26565, 26796, 27028, 27261, 27495, 27730, 27966, 28203, 28441, 28680, 28920, 29161, 29403, 29646, 29890, 30135, 30381, 30628, 30876, 31125, 31375, 31626, 31878, 32131, 32385, 32640, 32896, 33153, 33411, 33670, 33930, 34191, 34453, 34716, 34980, 35245, 35511, 35778, 36046, 36315, 36585, 36856, 37128, 37401, 37675, 37950, 38226, 38503, 38781, 39060, 39340, 39621, 39903, 40186, 40470, 40755, 41041, 41328, 41616, 41905, 42195, 42486, 42778, 43071, 43365, 43660, 43956, 44253, 44551, 44850, 45150, 45451, 45753, 46056, 46360, 46665, 46971, 47278, 47586, 47895, 48205, 48516, 48828, 49141, 49455, 49770, 50086, 50403, 50721, 51040, 51360, 51681, 52003, 52326, 52650, 52975, 53301, 53628, 53956, 54285, 54615, 54946, 55278, 55611, 55945, 56280, 56616, 56953, 57291, 57630, 57970, 58311, 58653, 58996, 59340, 59685, 60031, 60378, 60726, 61075, 61425, 61776, 62128, 62481, 62835, 63190, 63546, 63903, 64261, 64620, 64980, 65341, 65703, 66066, 66430, 66795, 67161, 67528, 67896, 68265, 68635, 69006, 69378, 69751, 70125, 70500, 70876, 71253, 71631, 72010, 72390, 72771, 73153, 73536, 73920, 74305, 74691, 75078, 75466, 75855, 76245, 76636, 77028, 77421, 77815, 78210, 78606, 79003, 79401, 79800, 80200, 80601, 81003, 81406, 81810, 82215, 82621, 83028, 83436, 83845, 84255, 84666, 85078, 85491, 85905, 86320, 86736, 87153, 87571, 87990, 88410, 88831, 89253, 89676, 90100, 90525, 90951, 91378, 91806, 92235, 92665, 93096, 93528, 93961, 94395, 94830, 95266, 95703, 96141, 96580, 97020, 97461, 97903, 98346, 98790, 99235, 99681, 100128, 100576, 101025, 101475, 101926, 102378, 102831, 103285, 103740, 104196, 104653, 105111, 105570, 106030, 106491, 106953, 107416, 107880, 108345, 108811, 109278, 109746, 110215, 110685, 111156, 111628, 112101, 112575, 113050, 113526, 114003, 114481, 114960, 115440, 115921, 116403, 116886, 117370, 117855, 118341, 118828, 119316, 119805, 120295, 120786, 121278, 121771, 122265, 122760, 123256, 123753, 124251, 124750, 125250, 125751, 126253, 126756, 127260, 127765, 128271, 128778, 129286, 129795, 130305, 130816, 131328, 131841, 132355, 132870, 133386, 133903, 134421, 134940, 135460, 135981, 136503, 137026, 137550, 138075, 138601, 139128, 139656, 140185, 140715, 141246, 141778, 142311, 142845, 143380, 143916, 144453, 144991, 145530, 146070, 146611, 147153, 147696, 148240, 148785, 149331, 149878, 150426, 150975, 151525, 152076, 152628, 153181, 153735, 154290, 154846, 155403, 155961, 156520, 157080, 157641, 158203, 158766, 159330, 159895, 160461, 161028, 161596, 162165, 162735, 163306, 163878, 164451, 165025, 165600, 166176, 166753, 167331, 167910, 168490, 169071, 169653, 170236, 170820, 171405, 171991, 172578, 173166, 173755, 174345, 174936, 175528, 176121, 176715, 177310, 177906, 178503, 179101, 179700, 180300, 180901, 181503, 182106, 182710, 183315, 183921, 184528, 185136, 185745, 186355, 186966, 187578, 188191, 188805, 189420, 190036, 190653, 191271, 191890, 192510, 193131, 193753, 194376, 195000, 195625, 196251, 196878, 197506, 198135, 198765, 199396, 200028, 200661, 201295, 201930, 202566, 203203, 203841, 204480, 205120, 205761, 206403, 207046, 207690, 208335, 208981, 209628, 210276, 210925, 211575, 212226, 212878, 213531, 214185, 214840, 215496, 216153, 216811, 217470, 218130, 218791, 219453, 220116, 220780, 221445, 222111, 222778, 223446, 224115, 224785, 225456, 226128, 226801, 227475, 228150, 228826, 229503, 230181, 230860, 231540, 232221, 232903, 233586, 234270, 234955, 235641, 236328, 237016, 237705, 238395, 239086, 239778, 240471, 241165, 241860, 242556, 243253, 243951, 244650, 245350, 246051, 246753, 247456, 248160, 248865, 249571, 250278, 250986, 251695, 252405, 253116, 253828, 254541, 255255, 255970, 256686, 257403, 258121, 258840, 259560, 260281, 261003, 261726, 262450, 263175, 263901, 264628, 265356, 266085, 266815, 267546, 268278, 269011, 269745, 270480, 271216, 271953, 272691, 273430, 274170, 274911, 275653, 276396, 277140, 277885, 278631, 279378, 280126, 280875, 281625, 282376, 283128, 283881, 284635, 285390, 286146, 286903, 287661, 288420, 289180, 289941, 290703, 291466, 292230, 292995, 293761, 294528, 295296, 296065, 296835, 297606, 298378, 299151, 299925, 300700, 301476, 302253, 303031, 303810, 304590, 305371, 306153, 306936, 307720, 308505, 309291, 310078, 310866, 311655, 312445, 313236, 314028, 314821, 315615, 316410, 317206, 318003, 318801, 319600, 320400, 321201, 322003, 322806, 323610, 324415, 325221, 326028, 326836, 327645, 328455, 329266, 330078, 330891, 331705, 332520, 333336, 334153, 334971, 335790, 336610, 337431, 338253, 339076, 339900, 340725, 341551, 342378, 343206, 344035, 344865, 345696, 346528, 347361, 348195, 349030, 349866, 350703, 351541, 352380, 353220, 354061, 354903, 355746, 356590, 357435, 358281, 359128, 359976, 360825, 361675, 362526, 363378, 364231, 365085, 365940, 366796, 367653, 368511, 369370, 370230, 371091, 371953, 372816, 373680, 374545, 375411, 376278, 377146, 378015, 378885, 379756, 380628, 381501, 382375, 383250, 384126, 385003, 385881, 386760, 387640, 388521, 389403, 390286, 391170, 392055, 392941, 393828, 394716, 395605, 396495, 397386, 398278, 399171, 400065, 400960, 401856, 402753, 403651, 404550, 405450, 406351, 407253, 408156, 409060, 409965, 410871, 411778, 412686, 413595, 414505, 415416, 416328, 417241, 418155, 419070, 419986, 420903, 421821, 422740, 423660, 424581, 425503, 426426, 427350, 428275, 429201, 430128, 431056, 431985, 432915, 433846, 434778, 435711, 436645, 437580, 438516, 439453, 440391, 441330, 442270, 443211, 444153, 445096, 446040, 446985, 447931, 448878, 449826, 450775, 451725, 452676, 453628, 454581, 455535, 456490, 457446, 458403, 459361, 460320, 461280, 462241, 463203, 464166, 465130, 466095, 467061, 468028, 468996, 469965, 470935, 471906, 472878, 473851, 474825, 475800, 476776, 477753, 478731, 479710, 480690, 481671, 482653, 483636, 484620, 485605, 486591, 487578, 488566, 489555, 490545, 491536, 492528, 493521, 494515, 495510, 496506, 497503, 498501, 499500]\r\n\r\nd={0: 0, 1: 1, 3: 2, 6: 3, 10: 4, 15: 5, 21: 6, 28: 7, 36: 8, 45: 9, 55: 10, 66: 11, 78: 12, 91: 13, 105: 14, 120: 15, 136: 16, 153: 17, 171: 18, 190: 19, 210: 20, 231: 21, 253: 22, 276: 23, 300: 24, 325: 25, 351: 26, 378: 27, 406: 28, 435: 29, 465: 30, 496: 31, 528: 32, 561: 33, 595: 34, 630: 35, 666: 36, 703: 37, 741: 38, 780: 39, 820: 40, 861: 41, 903: 42, 946: 43, 990: 44, 1035: 45, 1081: 46, 1128: 47, 1176: 48, 1225: 49, 1275: 50, 1326: 51, 1378: 52, 1431: 53, 1485: 54, 1540: 55, 1596: 56, 1653: 57, 1711: 58, 1770: 59, 1830: 60, 1891: 61, 1953: 62, 2016: 63, 2080: 64, 2145: 65, 2211: 66, 2278: 67, 2346: 68, 2415: 69, 2485: 70, 2556: 71, 2628: 72, 2701: 73, 2775: 74, 2850: 75, 2926: 76, 3003: 77, 3081: 78, 3160: 79, 3240: 80, 3321: 81, 3403: 82, 3486: 83, 3570: 84, 3655: 85, 3741: 86, 3828: 87, 3916: 88, 4005: 89, 4095: 90, 4186: 91, 4278: 92, 4371: 93, 4465: 94, 4560: 95, 4656: 96, 4753: 97, 4851: 98, 4950: 99, 5050: 100, 5151: 101, 5253: 102, 5356: 103, 5460: 104, 5565: 105, 5671: 106, 5778: 107, 5886: 108, 5995: 109, 6105: 110, 6216: 111, 6328: 112, 6441: 113, 6555: 114, 6670: 115, 6786: 116, 6903: 117, 7021: 118, 7140: 119, 7260: 120, 7381: 121, 7503: 122, 7626: 123, 7750: 124, 7875: 125, 8001: 126, 8128: 127, 8256: 128, 8385: 129, 8515: 130, 8646: 131, 8778: 132, 8911: 133, 9045: 134, 9180: 135, 9316: 136, 9453: 137, 9591: 138, 9730: 139, 9870: 140, 10011: 141, 10153: 142, 10296: 143, 10440: 144, 10585: 145, 10731: 146, 10878: 147, 11026: 148, 11175: 149, 11325: 150, 11476: 151, 11628: 152, 11781: 153, 11935: 154, 12090: 155, 12246: 156, 12403: 157, 12561: 158, 12720: 159, 12880: 160, 13041: 161, 13203: 162, 13366: 163, 13530: 164, 13695: 165, 13861: 166, 14028: 167, 14196: 168, 14365: 169, 14535: 170, 14706: 171, 14878: 172, 15051: 173, 15225: 174, 15400: 175, 15576: 176, 15753: 177, 15931: 178, 16110: 179, 16290: 180, 16471: 181, 16653: 182, 16836: 183, 17020: 184, 17205: 185, 17391: 186, 17578: 187, 17766: 188, 17955: 189, 18145: 190, 18336: 191, 18528: 192, 18721: 193, 18915: 194, 19110: 195, 19306: 196, 19503: 197, 19701: 198, 19900: 199, 20100: 200, 20301: 201, 20503: 202, 20706: 203, 20910: 204, 21115: 205, 21321: 206, 21528: 207, 21736: 208, 21945: 209, 22155: 210, 22366: 211, 22578: 212, 22791: 213, 23005: 214, 23220: 215, 23436: 216, 23653: 217, 23871: 218, 24090: 219, 24310: 220, 24531: 221, 24753: 222, 24976: 223, 25200: 224, 25425: 225, 25651: 226, 25878: 227, 26106: 228, 26335: 229, 26565: 230, 26796: 231, 27028: 232, 27261: 233, 27495: 234, 27730: 235, 27966: 236, 28203: 237, 28441: 238, 28680: 239, 28920: 240, 29161: 241, 29403: 242, 29646: 243, 29890: 244, 30135: 245, 30381: 246, 30628: 247, 30876: 248, 31125: 249, 31375: 250, 31626: 251, 31878: 252, 32131: 253, 32385: 254, 32640: 255, 32896: 256, 33153: 257, 33411: 258, 33670: 259, 33930: 260, 34191: 261, 34453: 262, 34716: 263, 34980: 264, 35245: 265, 35511: 266, 35778: 267, 36046: 268, 36315: 269, 36585: 270, 36856: 271, 37128: 272, 37401: 273, 37675: 274, 37950: 275, 38226: 276, 38503: 277, 38781: 278, 39060: 279, 39340: 280, 39621: 281, 39903: 282, 40186: 283, 40470: 284, 40755: 285, 41041: 286, 41328: 287, 41616: 288, 41905: 289, 42195: 290, 42486: 291, 42778: 292, 43071: 293, 43365: 294, 43660: 295, 43956: 296, 44253: 297, 44551: 298, 44850: 299, 45150: 300, 45451: 301, 45753: 302, 46056: 303, 46360: 304, 46665: 305, 46971: 306, 47278: 307, 47586: 308, 47895: 309, 48205: 310, 48516: 311, 48828: 312, 49141: 313, 49455: 314, 49770: 315, 50086: 316, 50403: 317, 50721: 318, 51040: 319, 51360: 320, 51681: 321, 52003: 322, 52326: 323, 52650: 324, 52975: 325, 53301: 326, 53628: 327, 53956: 328, 54285: 329, 54615: 330, 54946: 331, 55278: 332, 55611: 333, 55945: 334, 56280: 335, 56616: 336, 56953: 337, 57291: 338, 57630: 339, 57970: 340, 58311: 341, 58653: 342, 58996: 343, 59340: 344, 59685: 345, 60031: 346, 60378: 347, 60726: 348, 61075: 349, 61425: 350, 61776: 351, 62128: 352, 62481: 353, 62835: 354, 63190: 355, 63546: 356, 63903: 357, 64261: 358, 64620: 359, 64980: 360, 65341: 361, 65703: 362, 66066: 363, 66430: 364, 66795: 365, 67161: 366, 67528: 367, 67896: 368, 68265: 369, 68635: 370, 69006: 371, 69378: 372, 69751: 373, 70125: 374, 70500: 375, 70876: 376, 71253: 377, 71631: 378, 72010: 379, 72390: 380, 72771: 381, 73153: 382, 73536: 383, 73920: 384, 74305: 385, 74691: 386, 75078: 387, 75466: 388, 75855: 389, 76245: 390, 76636: 391, 77028: 392, 77421: 393, 77815: 394, 78210: 395, 78606: 396, 79003: 397, 79401: 398, 79800: 399, 80200: 400, 80601: 401, 81003: 402, 81406: 403, 81810: 404, 82215: 405, 82621: 406, 83028: 407, 83436: 408, 83845: 409, 84255: 410, 84666: 411, 85078: 412, 85491: 413, 85905: 414, 86320: 415, 86736: 416, 87153: 417, 87571: 418, 87990: 419, 88410: 420, 88831: 421, 89253: 422, 89676: 423, 90100: 424, 90525: 425, 90951: 426, 91378: 427, 91806: 428, 92235: 429, 92665: 430, 93096: 431, 93528: 432, 93961: 433, 94395: 434, 94830: 435, 95266: 436, 95703: 437, 96141: 438, 96580: 439, 97020: 440, 97461: 441, 97903: 442, 98346: 443, 98790: 444, 99235: 445, 99681: 446, 100128: 447, 100576: 448, 101025: 449, 101475: 450, 101926: 451, 102378: 452, 102831: 453, 103285: 454, 103740: 455, 104196: 456, 104653: 457, 105111: 458, 105570: 459, 106030: 460, 106491: 461, 106953: 462, 107416: 463, 107880: 464, 108345: 465, 108811: 466, 109278: 467, 109746: 468, 110215: 469, 110685: 470, 111156: 471, 111628: 472, 112101: 473, 112575: 474, 113050: 475, 113526: 476, 114003: 477, 114481: 478, 114960: 479, 115440: 480, 115921: 481, 116403: 482, 116886: 483, 117370: 484, 117855: 485, 118341: 486, 118828: 487, 119316: 488, 119805: 489, 120295: 490, 120786: 491, 121278: 492, 121771: 493, 122265: 494, 122760: 495, 123256: 496, 123753: 497, 124251: 498, 124750: 499, 125250: 500, 125751: 501, 126253: 502, 126756: 503, 127260: 504, 127765: 505, 128271: 506, 128778: 507, 129286: 508, 129795: 509, 130305: 510, 130816: 511, 131328: 512, 131841: 513, 132355: 514, 132870: 515, 133386: 516, 133903: 517, 134421: 518, 134940: 519, 135460: 520, 135981: 521, 136503: 522, 137026: 523, 137550: 524, 138075: 525, 138601: 526, 139128: 527, 139656: 528, 140185: 529, 140715: 530, 141246: 531, 141778: 532, 142311: 533, 142845: 534, 143380: 535, 143916: 536, 144453: 537, 144991: 538, 145530: 539, 146070: 540, 146611: 541, 147153: 542, 147696: 543, 148240: 544, 148785: 545, 149331: 546, 149878: 547, 150426: 548, 150975: 549, 151525: 550, 152076: 551, 152628: 552, 153181: 553, 153735: 554, 154290: 555, 154846: 556, 155403: 557, 155961: 558, 156520: 559, 157080: 560, 157641: 561, 158203: 562, 158766: 563, 159330: 564, 159895: 565, 160461: 566, 161028: 567, 161596: 568, 162165: 569, 162735: 570, 163306: 571, 163878: 572, 164451: 573, 165025: 574, 165600: 575, 166176: 576, 166753: 577, 167331: 578, 167910: 579, 168490: 580, 169071: 581, 169653: 582, 170236: 583, 170820: 584, 171405: 585, 171991: 586, 172578: 587, 173166: 588, 173755: 589, 174345: 590, 174936: 591, 175528: 592, 176121: 593, 176715: 594, 177310: 595, 177906: 596, 178503: 597, 179101: 598, 179700: 599, 180300: 600, 180901: 601, 181503: 602, 182106: 603, 182710: 604, 183315: 605, 183921: 606, 184528: 607, 185136: 608, 185745: 609, 186355: 610, 186966: 611, 187578: 612, 188191: 613, 188805: 614, 189420: 615, 190036: 616, 190653: 617, 191271: 618, 191890: 619, 192510: 620, 193131: 621, 193753: 622, 194376: 623, 195000: 624, 195625: 625, 196251: 626, 196878: 627, 197506: 628, 198135: 629, 198765: 630, 199396: 631, 200028: 632, 200661: 633, 201295: 634, 201930: 635, 202566: 636, 203203: 637, 203841: 638, 204480: 639, 205120: 640, 205761: 641, 206403: 642, 207046: 643, 207690: 644, 208335: 645, 208981: 646, 209628: 647, 210276: 648, 210925: 649, 211575: 650, 212226: 651, 212878: 652, 213531: 653, 214185: 654, 214840: 655, 215496: 656, 216153: 657, 216811: 658, 217470: 659, 218130: 660, 218791: 661, 219453: 662, 220116: 663, 220780: 664, 221445: 665, 222111: 666, 222778: 667, 223446: 668, 224115: 669, 224785: 670, 225456: 671, 226128: 672, 226801: 673, 227475: 674, 228150: 675, 228826: 676, 229503: 677, 230181: 678, 230860: 679, 231540: 680, 232221: 681, 232903: 682, 233586: 683, 234270: 684, 234955: 685, 235641: 686, 236328: 687, 237016: 688, 237705: 689, 238395: 690, 239086: 691, 239778: 692, 240471: 693, 241165: 694, 241860: 695, 242556: 696, 243253: 697, 243951: 698, 244650: 699, 245350: 700, 246051: 701, 246753: 702, 247456: 703, 248160: 704, 248865: 705, 249571: 706, 250278: 707, 250986: 708, 251695: 709, 252405: 710, 253116: 711, 253828: 712, 254541: 713, 255255: 714, 255970: 715, 256686: 716, 257403: 717, 258121: 718, 258840: 719, 259560: 720, 260281: 721, 261003: 722, 261726: 723, 262450: 724, 263175: 725, 263901: 726, 264628: 727, 265356: 728, 266085: 729, 266815: 730, 267546: 731, 268278: 732, 269011: 733, 269745: 734, 270480: 735, 271216: 736, 271953: 737, 272691: 738, 273430: 739, 274170: 740, 274911: 741, 275653: 742, 276396: 743, 277140: 744, 277885: 745, 278631: 746, 279378: 747, 280126: 748, 280875: 749, 281625: 750, 282376: 751, 283128: 752, 283881: 753, 284635: 754, 285390: 755, 286146: 756, 286903: 757, 287661: 758, 288420: 759, 289180: 760, 289941: 761, 290703: 762, 291466: 763, 292230: 764, 292995: 765, 293761: 766, 294528: 767, 295296: 768, 296065: 769, 296835: 770, 297606: 771, 298378: 772, 299151: 773, 299925: 774, 300700: 775, 301476: 776, 302253: 777, 303031: 778, 303810: 779, 304590: 780, 305371: 781, 306153: 782, 306936: 783, 307720: 784, 308505: 785, 309291: 786, 310078: 787, 310866: 788, 311655: 789, 312445: 790, 313236: 791, 314028: 792, 314821: 793, 315615: 794, 316410: 795, 317206: 796, 318003: 797, 318801: 798, 319600: 799, 320400: 800, 321201: 801, 322003: 802, 322806: 803, 323610: 804, 324415: 805, 325221: 806, 326028: 807, 326836: 808, 327645: 809, 328455: 810, 329266: 811, 330078: 812, 330891: 813, 331705: 814, 332520: 815, 333336: 816, 334153: 817, 334971: 818, 335790: 819, 336610: 820, 337431: 821, 338253: 822, 339076: 823, 339900: 824, 340725: 825, 341551: 826, 342378: 827, 343206: 828, 344035: 829, 344865: 830, 345696: 831, 346528: 832, 347361: 833, 348195: 834, 349030: 835, 349866: 836, 350703: 837, 351541: 838, 352380: 839, 353220: 840, 354061: 841, 354903: 842, 355746: 843, 356590: 844, 357435: 845, 358281: 846, 359128: 847, 359976: 848, 360825: 849, 361675: 850, 362526: 851, 363378: 852, 364231: 853, 365085: 854, 365940: 855, 366796: 856, 367653: 857, 368511: 858, 369370: 859, 370230: 860, 371091: 861, 371953: 862, 372816: 863, 373680: 864, 374545: 865, 375411: 866, 376278: 867, 377146: 868, 378015: 869, 378885: 870, 379756: 871, 380628: 872, 381501: 873, 382375: 874, 383250: 875, 384126: 876, 385003: 877, 385881: 878, 386760: 879, 387640: 880, 388521: 881, 389403: 882, 390286: 883, 391170: 884, 392055: 885, 392941: 886, 393828: 887, 394716: 888, 395605: 889, 396495: 890, 397386: 891, 398278: 892, 399171: 893, 400065: 894, 400960: 895, 401856: 896, 402753: 897, 403651: 898, 404550: 899, 405450: 900, 406351: 901, 407253: 902, 408156: 903, 409060: 904, 409965: 905, 410871: 906, 411778: 907, 412686: 908, 413595: 909, 414505: 910, 415416: 911, 416328: 912, 417241: 913, 418155: 914, 419070: 915, 419986: 916, 420903: 917, 421821: 918, 422740: 919, 423660: 920, 424581: 921, 425503: 922, 426426: 923, 427350: 924, 428275: 925, 429201: 926, 430128: 927, 431056: 928, 431985: 929, 432915: 930, 433846: 931, 434778: 932, 435711: 933, 436645: 934, 437580: 935, 438516: 936, 439453: 937, 440391: 938, 441330: 939, 442270: 940, 443211: 941, 444153: 942, 445096: 943, 446040: 944, 446985: 945, 447931: 946, 448878: 947, 449826: 948, 450775: 949, 451725: 950, 452676: 951, 453628: 952, 454581: 953, 455535: 954, 456490: 955, 457446: 956, 458403: 957, 459361: 958, 460320: 959, 461280: 960, 462241: 961, 463203: 962, 464166: 963, 465130: 964, 466095: 965, 467061: 966, 468028: 967, 468996: 968, 469965: 969, 470935: 970, 471906: 971, 472878: 972, 473851: 973, 474825: 974, 475800: 975, 476776: 976, 477753: 977, 478731: 978, 479710: 979, 480690: 980, 481671: 981, 482653: 982, 483636: 983, 484620: 984, 485605: 985, 486591: 986, 487578: 987, 488566: 988, 489555: 989, 490545: 990, 491536: 991, 492528: 992, 493521: 993, 494515: 994, 495510: 995, 496506: 996, 497503: 997, 498501: 998, 499500: 999}\r\n\r\n\r\ndef find_nearest(arr,n):\r\n i=0 \r\n while arr[i]<n:\r\n i+=1\r\n i-=1 \r\n return arr[i]\r\n\r\nk=int(input())\r\ncharacters=[]\r\nif k==0:\r\n print(\"a\")\r\nelse: \r\n while k>0:\r\n if k in d.keys():\r\n characters.append(d[k])\r\n k=0\r\n break\r\n else:\r\n n=find_nearest(arr,k)\r\n characters.append(d[n])\r\n k-=n \r\n ans=[]\r\n for i in range(len(characters)):\r\n ans.append(str(chr(ord('a')+i)*(characters[i]+1)))\r\n ans=\"\".join(ans)\r\n print(ans)", "def main():\n n = int(input())\n if n == 0:\n print(\"a\")\n return\n x = [1]\n c = 2\n while x[-1] < n:\n x.append(x[-1] + c)\n c += 1\n\n y = [0] * len(x)\n for i in range(len(x) - 1, -1, -1):\n while x[i] * (y[i] + 1) <= n:\n y[i] += 1\n n -= x[i] * y[i]\n\n a = []\n c = ord('a')\n for i in range(len(x)):\n if y[i] != 0:\n for j in range(y[i]):\n t = chr(c)\n for z in range(i + 2):\n a.append(t)\n c += 1\n print(\"\".join(a))\n\n\nmain()\n", "a=[]\r\nn=1\r\nwhile((n*(n+1))//2<=100000):\r\n a.append(n*(n+1)//2)\r\n n+=1\r\n# print(a[:10])\r\nfor i in range(1):\r\n k=int(input())\r\n s=\"qwertyuiopasdfghjklzxcvbnm\"\r\n ans=\"\"\r\n if k==0:\r\n print(\"a\")\r\n break\r\n pos=0\r\n while(k>0):\r\n # print(k)\r\n for i in range(len(a)):\r\n if a[i]>k:\r\n # print(i)\r\n ans+=s[pos]*(i+1)\r\n k-=a[i-1]\r\n pos+=1\r\n break\r\n else:\r\n ans+=s[pos]*(len(a)+1)\r\n k-=a[-1]\r\n pos+=1\r\n # print()\r\n print(ans)", "n = eval(input())\r\nans = ''\r\n\r\nfor i in range(0, 26):\r\n tmp = 1\r\n while (tmp + 1) * tmp / 2 <= n:\r\n tmp += 1\r\n tmp -= 1\r\n ans += chr(ord('a') + i) * (tmp+1)\r\n n -= int((tmp + 1) * tmp / 2)\r\n if n == 0:\r\n break\r\nprint(ans)", "N = int(input())\r\nif N == 0:\r\n print(\"a\")\r\nelse:\r\n s = \"\"\r\n n = 0\r\n kc = 97\r\n while N > 0:\r\n c = chr(kc)\r\n s += c\r\n for i in range(1, 1000):\r\n if N < i:\r\n break\r\n else:\r\n N -= i\r\n s += c\r\n kc += 1\r\n\r\n print(s)", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport array\nfrom bisect import *\nfrom collections import *\nimport fractions\nimport heapq \nfrom itertools import *\nimport math\nimport re\nimport string\n\nk = int(input())\n\ndef func(k):\n cur = 0\n acc = 0\n while True:\n acc += cur\n if acc > k:\n return cur, k - (acc - cur)\n if acc == k:\n return cur + 1, 0\n cur += 1\n\nif k == 0:\n print(\"a\")\nelse:\n ret = \"\"\n for i in range(26):\n if k > 0:\n rep, k = func(k)\n ch = chr(ord('a') + i)\n # print(\"ch, rep, k = \", ch, rep, k)\n ret += ch * rep\n print(ret)\n", "k= int(input())\n\nc='a'\n\nwhile ( k != 0):\n\n j = 1\n\n while ((j+1)*(j+2) < 2*k):\n\n j = j+1\n\n \n\n for i in range (0,j+1):\n\n print(c,end=\"\")\n\n c=chr(ord(c)+1)\n\n k=k-((j+1)*(j))/2\n\nprint(\"z\")\n\n\n\n\n\n# Made By Mostafa_Khaled", "from math import sqrt\nimport string\nsum = int(input())\nl = []\nalpha = list(string.ascii_lowercase)[1:]\ndef binom2(x):\n return int(x*(x-1)/2)\n\nwhile sum != 0:\n ini = int(sqrt(2*sum))\n x = ini\n #value = binom2(ini)\n while binom2(x) <= sum:\n x+=1\n x -= 1\n l.append(x)\n sum -= binom2(x)\n #print(sum)\nstr = \"a\"\nfor i in range(len(l)):\n str += l[i]*alpha[i]\nprint(str)\n\n\n", "k,s=int(input()),\"\"\r\nfor c in range(26):\r\n\ti=0\r\n\twhile i<k:\r\n\t\ti+=1\r\n\t\tk-=i\r\n\ts+=chr(c+97)*(i+1)\r\nprint(s)", "k = int(input())\r\nans = \"\"\r\nfor ch in \"abcdefghijklmnopqrstuvwxyz\":\r\n\tcost = 0\r\n\twhile k-cost>=0:\r\n\t\tk-=cost\r\n\t\tcost+=1\r\n\t\tans+=ch\r\n\tif not k:\r\n\t\tbreak\r\nprint(ans)", "n = int(input())\r\n\r\nif not n:\r\n print('ab')\r\n exit(0)\r\n\r\n\r\ndef f(n):\r\n l = 1\r\n r = 100000\r\n ans = 1\r\n while r >= l:\r\n m = (l + r) // 2\r\n if m * (m - 1) // 2 <= n:\r\n ans = m\r\n l = m + 1\r\n else:\r\n r = m - 1\r\n return ans\r\n\r\n\r\ns = ''\r\ncur = 0\r\n\r\nwhile n:\r\n x = f(n)\r\n for i in range(x):\r\n s += chr(ord('a') + cur)\r\n cur += 1\r\n n -= x * (x - 1) // 2\r\n\r\nprint(s)", "# def ap(l):\r\n# d = set()\r\n# for i in range(1, len(l)):\r\n# d.add(l[i]-l[i-1])\r\n# if(len(d) == 1):\r\n# return d.pop()\r\n# else:\r\n# return \"re\"\r\n\r\n\r\n# def app(ll, oo, nm, ooo):\r\n# k = []\r\n# for j in range(n):\r\n# if(j%oo !=0):\r\n# k.append(ll[j])\r\n# if(ap(k) != \"re\" and ap(k) != ooo):\r\n# return True\r\n# else:\r\n# return False\r\n\r\n\r\n# err = 1\r\n# n = int(input())\r\n# l = [int(x) for x in input().split()]\r\n# m = []\r\n# for i in range(2, n):\r\n# k = []\r\n# for j in range(0, n, i):\r\n# k.append(l[j])\r\n\r\n# print(k)\r\n# m.append(k)\r\n# final = []\r\n# for i in range(n-2):\r\n# r = 1\r\n# if(ap(m[i]) != \"re\"):\r\n# final.append([ap(m[i]), i+2])\r\n\r\n# print(final)\r\n\r\n# for i in final:\r\n# if(app(l, i[1], n, i[0])):\r\n# print(i)\r\n# # print(\"Yes\")\r\n# err = 0\r\n# break\r\n# if(err):\r\n# print(\"No\")\r\n# else:\r\n# print(\"Yes\")\r\nk = int(input())\r\nfor i in range(26):\r\n tt = 1\r\n while((tt*(tt+1))//2 <=k):\r\n tt+=1\r\n k-=((tt*(tt-1))//2)\r\n \r\n print(chr(97+i)*(tt), end = \"\")\r\n\r\nprint(\"\")", "def solve(k, c):\r\n if k == 0: return c if c < 'c' else ''\r\n n = 1\r\n while f(n + 1) <= k: n += 1\r\n return c * n + solve(k - f(n), chr(ord(c) + 1))\r\n\r\nread = lambda: map(int, input().split())\r\nk = int(input())\r\nf = lambda n: n * (n - 1) // 2\r\nans = solve(k, 'a')\r\nprint(ans)", "n = int(input())\r\narr = [int(i * (i - 1) / 2) for i in range(1, 460)]\r\nkek = [0] * (ord('z') - ord('a') + 1)\r\nlast = 450\r\nfor i in range(len(kek)):\r\n while arr[last] > n:\r\n last -= 1\r\n kek[i] = last + 1\r\n n -= arr[last]\r\nfor i in range(len(kek)):\r\n print(chr(i + ord('a')) * kek[i], end = '')\r\nprint()", "def f(n):\r\n return n * (n + 1) // 2\r\n\r\ndef rev_f(x):\r\n l = 0\r\n r = 450\r\n y = 0\r\n while l + 1 < r:\r\n m = (l + r) // 2\r\n y = f(m)\r\n if y > x:\r\n r = m\r\n else:\r\n l = m\r\n return l\r\n\r\nn = int(input())\r\nfor i in range(0, 26):\r\n c = chr(ord('a') + i)\r\n q = rev_f(n)\r\n n -= f(q)\r\n print(c * (q + 1), end = '')\r\n if n == 0:\r\n break\r\n", "k=int(input())\r\na=[]\r\nx= {}\r\ncurr=1\r\nele=1\r\nwhile curr<=k:\r\n ele+=1\r\n x[curr]=ele\r\n a.append(curr)\r\n curr+=ele\r\nif k==0:\r\n print(\"a\")\r\nelif k==1:\r\n print(\"aa\")\r\nelse:\r\n ans=[]\r\n i=len(x)-1\r\n while k>0:\r\n tmp=k//a[i]\r\n for j in range(tmp):\r\n ans.append(x[a[i]])\r\n k-=(tmp*a[i])\r\n i-=1\r\n start=97\r\n ret=\"\"\r\n for i in range(len(ans)):\r\n ret+=chr(start)*ans[i]\r\n start+=1\r\n print(ret)", "n = int(input())\r\nalpha = \"abcdefghijklmnopqrstuvwxyz\"\r\ns = alpha\r\nind = 0\r\ncur = 1\r\nwhile n > 0:\r\n if cur > n:\r\n ind += 1\r\n cur = 1\r\n else:\r\n n -= cur\r\n cur += 1\r\n s += alpha[ind]\r\nprint(s) \r\n", "n = int(input());s=n\r\narr =[ ]\r\nwhile (True):\r\n for i in range(0,s+3):\r\n if (i*(i-1)*(1/2)<=n):continue\r\n else :\r\n arr.append(i-1);n-=(i-1)*(i-2)*(1/2);break\r\n if (n<=0):break\r\nj=0\r\nfor i in 'abcdefghijklmnobqrstuvwxyz':\r\n while (arr[j]!=0):print(i,end='');arr[j]-=1\r\n j+=1\r\n if (j==len(arr)):break\r\n\r\n\r\n", "k = int(input())\r\nif k == 0:\r\n\tprint(\"a\")\r\n\r\nelse:\r\n\r\n\tchar = 97\r\n\r\n\twhile k > 0:\r\n\r\n\t\tx = 2\r\n\t\twhile (x * (x + 1)) // 2 < k:\r\n\t\t\tx += 1\r\n\r\n\t\tk = k - ((x * (x - 1)) //2)\r\n\t\t\r\n\t\tprint(chr(char) * x,end='')\r\n\r\n\t\tchar += 1", "n=int(input())\r\nans=\"\"\r\nfor i in range(26):\r\n cnt=1\r\n while ((cnt+1)*cnt)//2<=n:\r\n cnt+=1\r\n n-=((cnt)*(cnt-1))//2\r\n for j in range(cnt):\r\n ans+=chr(ord(\"a\")+i)\r\nprint(ans)", "k = int(input())\r\nt = \"\"\r\nfor i in range(26):\r\n cnt = 1\r\n while cnt * (cnt + 1) // 2 <= k:\r\n cnt += 1\r\n k -= cnt * (cnt - 1) // 2\r\n t += chr(ord(\"a\") + i) * cnt\r\n\r\nprint(t)", "k=int(input())\r\nif k==0:print('a')\r\nelse:\r\n ans=\"\"\r\n sum=0\r\n for i in range(0,26):\r\n w=chr(i+97)\r\n if sum==k:break\r\n else:\r\n num=1\r\n ans+=w\r\n while sum+num<=k:\r\n ans+=w\r\n sum+=num\r\n num+=1\r\n print(ans)", " ###### ### ####### ####### ## # ##### ### ##### \r\n # # # # # # # # # # # # # ### \r\n # # # # # # # # # # # # # ### \r\n ###### ######### # # # # # # ######### # \r\n ###### ######### # # # # # # ######### # \r\n # # # # # # # # # # #### # # # \r\n # # # # # # # ## # # # # # \r\n ###### # # ####### ####### # # ##### # # # # \r\n\r\n# from __future__ import print_function # for PyPy2\r\nfrom collections import Counter, OrderedDict\r\nfrom itertools import permutations as perm\r\nfrom fractions import Fraction\r\nfrom collections import deque\r\nfrom sys import stdin\r\nfrom bisect import *\r\nfrom heapq import *\r\nfrom math import *\r\n\r\ng = lambda : stdin.readline().strip()\r\ngl = lambda : g().split()\r\ngil = lambda : [int(var) for var in gl()]\r\ngfl = lambda : [float(var) for var in gl()]\r\ngcl = lambda : list(g())\r\ngbs = lambda : [int(var) for var in g()]\r\nmod = int(1e9)+7\r\ninf = float(\"inf\") \r\n\r\nN, = gil()\r\n\r\nif N == 0:\r\n print('a')\r\n exit()\r\n\r\nch = 0\r\nans = []\r\n\r\nwhile N > 1:\r\n n = int(sqrt(2*N))\r\n N -= (n*(n-1))//2\r\n # print(N, n)\r\n ans.append(chr(97+ch)*n)\r\n ch += 1\r\n\r\nif N :\r\n ans.append(chr(97+ch)*2)\r\n\r\nprint(''.join(ans))", "#OMM NAMH SHIVAY\r\n#JAI SHREE RAM\r\nimport sys,math,heapq,queue\r\nfrom collections import deque\r\nfrom functools import cmp_to_key\r\nfast_input=sys.stdin.readline \r\nMOD=10**9+7\r\nk=int(fast_input())\r\ns='abcdefghijklmnopqrstuvwxyz'\r\ni=0\r\nlastcount=1\r\nwhile k:\r\n if lastcount>k:\r\n lastcount=1 \r\n i+=1 \r\n s+=s[i]\r\n k-=lastcount\r\n lastcount+=1 \r\nprint(s)", "k = int(input())\r\ns = \"a\"\r\nc = 0\r\np = 1\r\nletters = \"abcdefghijklmnopqstuvwxyz\"\r\nl = 0\r\nwhile(c != k):\r\n c += p\r\n s += letters[l]\r\n p += 1\r\n if c+p > k:\r\n l += 1\r\n p = 0\r\nprint(s)\r\n \r\n", "k = int(input())\r\nif k == 0:\r\n print('a')\r\nelse:\r\n for element in range(ord('a'), ord('z') + 1):\r\n if k == 0:\r\n break\r\n t = 0\r\n while t * (t - 1) <= k * 2:\r\n t += 1\r\n t -= 1\r\n k -= (t * (t - 1) // 2)\r\n print(chr(element) * t, end='')\r\n print()# 1690625368.6743412", "k = int(input())\r\nif k == 0:\r\n print('a')\r\nelse:\r\n for ch in range(ord('a'), ord('z') + 1):\r\n if k == 0:\r\n break\r\n t = 0\r\n while t * (t - 1) <= k * 2:\r\n t += 1\r\n t -= 1\r\n k -= (t * (t - 1) // 2)\r\n print(chr(ch) * t, end='')\r\n print()\r\n" ]
{"inputs": ["12", "3", "0", "2", "5", "10", "233", "418", "100000", "1", "4", "6", "7", "8", "9", "11", "1317", "1926", "14514", "25252", "99681", "99998", "82944", "831", "39393"], "outputs": ["abababab", "codeforces", "o", "aabb", "aaabbcc", "aaaaa", "ooououououououououooohhhhhhaaiiiiiibbjjjjjjcckkkkkkddlllllleemmmmmmffnnnnnnggzzzzzz", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbcccc", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbcccccccccccc", "aa", "aaabb", "aaaa", "aaaabb", "aaaabbcc", "aaaabbb", "aaaaabb", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbcccc", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbccc", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "niconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconiconicooooquququququququq", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccc...", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...", "happybirthdayhappybirthdayhappybirthdayhappybirthdayhappybirthdayhappybirthdayhappybirthdayhappybirthdayhappybirthdayqqquqqquqqqu", "mikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumikumik..."]}
UNKNOWN
PYTHON3
CODEFORCES
35
142ca9504dab57200c552d5380ecc69f
Almost Acyclic Graph
You are given a [directed graph](https://en.wikipedia.org/wiki/Directed_graph) consisting of *n* vertices and *m* edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it. Can you make this graph [acyclic](https://en.wikipedia.org/wiki/Directed_acyclic_graph) by removing at most one edge from it? A directed graph is called acyclic iff it doesn't contain any cycle (a non-empty path that starts and ends in the same vertex). The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=500, 1<=≤<=*m*<=≤<=*min*(*n*(*n*<=-<=1),<=100000)) — the number of vertices and the number of edges, respectively. Then *m* lines follow. Each line contains two integers *u* and *v* denoting a directed edge going from vertex *u* to vertex *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*). Each ordered pair (*u*,<=*v*) is listed at most once (there is at most one directed edge from *u* to *v*). If it is possible to make this graph acyclic by removing at most one edge, print YES. Otherwise, print NO. Sample Input 3 4 1 2 2 3 3 2 3 1 5 6 1 2 2 3 3 2 3 1 2 1 4 5 Sample Output YES NO
[ "\r\n\r\ndef my_solve(n, m, graph, mask):\r\n\tif do_dfs_bool(n,graph,mask.copy()):\r\n\t\tc = get_cyclic(n, graph, mask)\r\n\t\tfor u,v in c:\r\n\t\t\tgraph[u].remove(v)\r\n\t\t\tif not do_dfs_bool(n,graph,mask.copy()):\r\n\t\t\t\treturn 'YES'\r\n\t\t\tgraph[u].append(v)\r\n\t\treturn \"NO\"\r\n\treturn \"YES\"\r\n\r\ndef get_cyclic(n, graph, mask):\r\n\tc,v = do_dfs(n,graph,mask)\r\n\tpath = []\r\n\ti = 0\r\n\tbegin = False\r\n\tif c:\r\n\t\tfor u in c.keys():\r\n\t\t\tif c[u] == v:\r\n\t\t\t\tbegin = True\r\n\t\t\t\tpath.append((c[u],u))\r\n\t\t\telif begin:\r\n\t\t\t\tpath.append((c[u],u))\r\n\t\ttmp = list(c.keys())\r\n\t\tif len(tmp):\r\n\t\t\tpath.append((tmp[-1],v))\r\n\treturn path\r\n\r\ndef do_dfs_bool(n, graph, mask):\r\n\tcolors = [0]*(n+5)\r\n\tfor u in graph.keys():\r\n\t\tif not u in mask.keys():\r\n\t\t\tif dfs_bool(u,graph,mask,colors):\r\n\t\t\t\treturn True\r\n\treturn False\r\n\r\n\r\ndef dfs_bool(u, graph, mask,colors):\r\n\tcolors[u] = 1\r\n\tmask[u] = True\r\n\tfor v in graph[u]:\r\n\t\tif colors[v] == 1:\r\n\t\t\treturn True\r\n\t\tif colors[v] == 0:\r\n\t\t\tif dfs_bool(v,graph,mask,colors):\t\t\t\t\r\n\t\t\t\treturn True\r\n\tcolors[u] = 2\r\n\treturn False\r\n\r\ndef do_dfs(n, graph, mask):\r\n\tcolors = [0]*(n+5)\r\n\tc = {}\r\n\tfor u in graph.keys():\r\n\t\tif not u in mask.keys():\r\n\t\t\tc = {}\r\n\t\t\tp, v = dfs(u,graph,mask,c,colors)\r\n\t\t\tif p and v:\r\n\t\t\t\treturn (p,v)\r\n\r\n\r\ndef dfs(u, graph, mask, c, colors):\r\n\tcolors[u] = 1\r\n\tfor v in graph[u]:\r\n\t\tif colors[v] == 1:\r\n\t\t\treturn (c, v)\r\n\t\tif colors[v] == 0:\r\n\t\t\tc[v] = u\r\n\t\t\tp,w = dfs(v,graph,mask,c,colors)\r\n\t\t\tif w:\r\n\t\t\t\treturn (p,w)\r\n\tcolors[u] = 2\r\n\tif len(c) > 0:\r\n\t\tif u in c.keys():\r\n\t\t\tdel c[u]\r\n\treturn (c, None)\r\n\r\ndef test(n, m, edges):\r\n\tgraph = {}\r\n\tmask = {}\r\n\tfor u,v in edges:\r\n\t\tif u not in graph.keys():\r\n\t\t\tgraph[u] = []\r\n\t\tgraph[u].append(v)\r\n\t\tif v not in graph.keys():\r\n\t\t\tgraph[v] = []\r\n\treturn my_solve(n, m, graph, mask)\r\n\r\n\r\nif __name__ == '__main__':\r\n\tn,m = [int(x) for x in input().split()]\r\n\tedges = []\r\n\tfor i in range(0,m):\r\n\t\tu,v = [int(x) for x in input().split()]\r\n\t\tedges.append((u,v))\r\n\tprint(test(n, m, edges))", "import sys\r\nimport io, os\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n\r\nfrom collections import deque\r\n\r\nn, m = map(int, input().split())\r\ng = [[] for i in range(n)]\r\nind = [0]*n\r\nfor i in range(m):\r\n u, v = map(int, input().split())\r\n u, v = u-1, v-1\r\n g[u].append(v)\r\n ind[v] += 1\r\n\r\ndef topological_sort():\r\n order = []\r\n for i in range(n):\r\n if not ind[i]:\r\n order.append(i)\r\n q = deque(order)\r\n while q:\r\n v = q.popleft()\r\n for u in g[v]:\r\n ind[u] -= 1\r\n if not ind[u]:\r\n q.append(u)\r\n order.append(u)\r\n g[v].clear()\r\n return len(order) == n\r\n\r\nif topological_sort():\r\n print('YES')\r\n exit()\r\n\r\ndef check(s):\r\n temp_ind = ind.copy()\r\n order = [s]\r\n q = deque(order)\r\n while q:\r\n v = q.popleft()\r\n for u in g[v]:\r\n if u == s:\r\n continue\r\n temp_ind[u] -= 1\r\n if not temp_ind[u]:\r\n q.append(u)\r\n order.append(u)\r\n return len(order) == l\r\n\r\nl = 0\r\nfor i in range(n):\r\n if ind[i] > 0:\r\n l += 1\r\nfor i in range(n):\r\n if ind[i] == 1:\r\n if check(i):\r\n print('YES')\r\n exit()\r\nprint('NO')\r\n", "def dfs(g, u, visited, call_stack):\r\n visited[u] = True\r\n call_stack.add(u)\r\n for v in g[u]:\r\n if v in call_stack:\r\n return [u, v]\r\n if not visited[v]:\r\n d = dfs(g, v, visited, call_stack)\r\n call_stack.discard(v)\r\n if d is not None:\r\n return [u] + d\r\n return None\r\n \r\n \r\ndef find_cycle(g, n):\r\n visited = [False] * n\r\n d = None\r\n for i in range(n):\r\n if not visited[i]:\r\n call_stack = set()\r\n d = dfs(g, i, visited, call_stack)\r\n if d is not None:\r\n break\r\n return d\r\n \r\n \r\nif __name__ == '__main__':\r\n n, m = map(int, input().split())\r\n \r\n g = []\r\n for _ in range(n):\r\n g.append([])\r\n \r\n for _ in range(m):\r\n u, v = map(int, input().split())\r\n g[u-1].append(v-1)\r\n \r\n out = False\r\n c = find_cycle(g, n)\r\n if c:\r\n first_index = c.index(c[-1])\r\n c = c[first_index:]\r\n \r\n for i in range(len(c)-1):\r\n if i != 0:\r\n g[c[i-1]].append(c[i])\r\n g[c[i]].remove(c[i+1])\r\n out = out or find_cycle(g, n) is None\r\n else:\r\n out = True\r\n \r\n print('YES' if out else 'NO')\r\n", "from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nn,m=map(int,input().split())\r\nedges=[]\r\nedge=[[] for i in range(n)]\r\ncnt=[0]*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 cnt[y]+=1\r\n\r\n\r\nseen=[0]*n\r\nfinished=[0]*n\r\nstc=[]\r\npos=-1\r\n\r\ndef dfs(v):\r\n global pos\r\n seen[v]=True\r\n stc.append(v)\r\n for u in edge[v]:\r\n if finished[u]:\r\n continue\r\n if seen[u] and finished[u]==0:\r\n pos=u\r\n return\r\n dfs(u)\r\n if pos!=-1:\r\n return\r\n stc.pop()\r\n finished[v]=True\r\n\r\nfor i in range(n):\r\n if pos==-1:\r\n dfs(i)\r\n\r\nif pos==-1:\r\n print('YES')\r\n exit()\r\n\r\ncyc=[]\r\nwhile stc:\r\n v=stc.pop()\r\n cyc.append(v)\r\n if v==pos:\r\n break\r\n\r\ncyc=cyc[::-1]\r\n\r\ndef check(ng_frm,ng_to):\r\n tmp=cnt.copy()\r\n tmp[ng_to]-=1\r\n todo=[]\r\n for i in range(n):\r\n if tmp[i]==0:\r\n todo.append(i)\r\n while todo:\r\n v=todo.pop()\r\n for u in edge[v]:\r\n if v==ng_frm and u==ng_to:\r\n continue\r\n tmp[u]-=1\r\n if tmp[u]==0:\r\n todo.append(u)\r\n if max(tmp)==0:\r\n print('YES')\r\n exit()\r\n\r\ns=len(cyc)\r\nfor i in range(s):\r\n x=cyc[i]\r\n y=cyc[(i+1)%s]\r\n check(x,y)\r\n\r\nprint('NO')", "import sys\r\n \r\ndef dfs():\r\n stack = [i for i in range(n) if deg[i] == 0]\r\n cnt = 0\r\n while stack:\r\n v = stack.pop()\r\n cnt += 1\r\n for dest in adj[v]:\r\n deg[dest] -= 1\r\n if deg[dest] == 0:\r\n stack.append(dest)\r\n adj[v].clear()\r\n \r\n return cnt == n\r\n \r\n \r\ndef solve(st):\r\n stack = [st]\r\n visited = [0]*n\r\n cnt = 0\r\n while stack:\r\n v = stack.pop()\r\n cnt += 1\r\n for dest in adj[v]:\r\n if dest == st:\r\n continue\r\n visited[dest] += 1\r\n if deg[dest] == visited[dest]:\r\n stack.append(dest)\r\n \r\n return cnt == m\r\n \r\n \r\nn, m = map(int, sys.stdin.buffer.readline().decode('utf-8').split())\r\nadj = [[] for _ in range(n)]\r\nrev = [[] for _ in range(n)]\r\ndeg = [0] * n\r\nfor u, v in (map(int, line.decode('utf-8').split()) for line in sys.stdin.buffer):\r\n adj[u - 1].append(v - 1)\r\n rev[v - 1].append(u - 1)\r\n deg[v - 1] += 1\r\n \r\nok = dfs()\r\nif ok:\r\n print('YES')\r\n exit()\r\n \r\nm = len([1 for i in range(n) if deg[i] > 0])\r\nfor i in range(n):\r\n if deg[i] == 1 and solve(i):\r\n print('YES')\r\n exit()\r\n \r\nprint('NO')", "from collections import deque\r\ndef check():\r\n cnt = 0\r\n q = deque()\r\n for i in range(1, n + 1):\r\n if not drgree[i]:\r\n q.append(i)\r\n while q:\r\n u = q.popleft()\r\n cnt += 1\r\n for i in lis[u]:\r\n drgree[i] -= 1\r\n if drgree[i] == 0:\r\n q.append(i)\r\n return cnt == n\r\n\r\nn, m = map(int, input().split())\r\ndrgree = [0] * (n + 1)\r\nlis = [[] for _ in range(n + 1)]\r\n\r\nfor _ in range(m):\r\n a, b = map(int, input().split())\r\n lis[a].append(b)\r\n drgree[b] += 1\r\ndrgree1 = drgree.copy()\r\nfor i in range(1, n + 1):\r\n drgree[i] -= 1\r\n if check():\r\n print(\"YES\")\r\n exit()\r\n drgree = drgree1.copy()\r\n\r\nprint(\"NO\")\r\n" ]
{"inputs": ["3 4\n1 2\n2 3\n3 2\n3 1", "5 6\n1 2\n2 3\n3 2\n3 1\n2 1\n4 5", "2 2\n1 2\n2 1", "7 7\n1 3\n3 6\n3 7\n5 3\n6 2\n6 7\n7 2", "500 50\n396 340\n47 341\n422 140\n492 209\n263 248\n461 300\n124 495\n33 6\n93 384\n389 182\n130 297\n217 329\n131 136\n355 94\n388 275\n115 368\n279 462\n126 285\n185 287\n223 221\n207 167\n203 127\n39 245\n394 444\n166 99\n399 328\n3 276\n142 325\n284 153\n65 3\n102 5\n459 168\n156 17\n99 162\n293 194\n493 198\n171 356\n269 155\n479 37\n269 336\n28 183\n363 43\n398 45\n142 68\n437 301\n150 353\n1 211\n326 340\n459 14\n90 441", "4 5\n1 3\n3 2\n2 1\n3 4\n4 1", "5 6\n1 3\n2 1\n3 5\n4 3\n5 4\n3 2", "3 4\n1 2\n2 1\n1 3\n3 1", "5 7\n1 2\n2 3\n3 1\n3 4\n4 1\n4 5\n5 1", "4 6\n1 2\n2 3\n3 1\n3 2\n3 4\n4 2", "4 5\n1 2\n2 3\n3 4\n4 1\n3 1", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 3", "4 6\n2 3\n3 2\n3 4\n4 3\n4 2\n2 4", "4 5\n1 2\n2 3\n2 4\n3 1\n4 1", "4 5\n1 2\n2 1\n3 4\n4 3\n1 3", "7 6\n2 3\n3 4\n4 2\n5 6\n6 7\n7 5", "5 6\n1 2\n2 3\n3 4\n4 5\n5 1\n4 2", "4 4\n1 2\n2 1\n3 4\n4 3", "7 9\n1 2\n2 3\n1 3\n3 4\n3 5\n5 6\n6 1\n6 7\n7 1", "8 7\n1 2\n2 3\n3 4\n4 1\n4 5\n5 6\n6 3", "4 6\n1 2\n2 4\n2 3\n3 1\n4 3\n3 2", "5 6\n1 2\n2 3\n3 4\n4 5\n4 1\n5 2", "4 5\n2 4\n1 2\n2 1\n3 4\n4 3", "6 8\n1 2\n2 3\n3 1\n2 4\n4 5\n5 1\n2 6\n6 1", "6 8\n1 2\n2 3\n3 4\n4 1\n3 5\n5 6\n6 2\n1 3", "6 7\n1 2\n2 5\n5 6\n6 1\n5 4\n4 3\n3 2", "10 22\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n6 7\n6 8\n6 9\n6 10\n7 8\n7 9\n7 10\n8 9\n8 10\n9 10\n5 6\n10 1", "4 6\n1 2\n2 3\n3 4\n4 1\n2 4\n3 1", "5 7\n1 2\n2 3\n3 4\n4 5\n5 1\n1 3\n3 5", "5 6\n1 2\n2 3\n3 4\n4 5\n4 2\n5 2", "4 5\n2 3\n3 4\n4 2\n2 4\n3 2", "7 8\n1 2\n2 3\n3 4\n4 5\n5 2\n3 6\n6 7\n7 2", "4 5\n1 2\n2 3\n3 4\n4 1\n1 3", "4 6\n1 2\n2 3\n3 4\n4 1\n2 4\n4 2", "8 9\n2 6\n5 6\n5 2\n3 5\n4 5\n6 4\n1 2\n2 8\n2 3", "8 10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 1\n5 4\n4 8\n8 5", "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4", "5 8\n1 4\n1 5\n4 2\n4 3\n5 2\n5 3\n2 1\n3 1", "5 6\n1 2\n2 3\n3 4\n4 5\n5 1\n1 4", "4 5\n1 2\n2 4\n2 3\n3 1\n4 3", "5 8\n4 3\n3 1\n4 1\n5 1\n5 2\n1 4\n1 3\n5 3", "6 12\n2 1\n2 3\n2 4\n3 4\n4 1\n1 3\n1 5\n5 4\n6 5\n6 4\n6 1\n1 4", "6 8\n1 2\n2 3\n3 4\n1 5\n5 6\n6 4\n4 1\n4 2", "8 11\n5 1\n1 2\n1 6\n6 2\n2 3\n2 7\n7 3\n3 4\n3 8\n8 4\n4 1", "4 6\n1 2\n2 3\n3 4\n4 1\n1 3\n3 1", "5 8\n1 2\n1 3\n1 4\n2 3\n3 4\n3 5\n5 2\n5 1", "4 5\n2 1\n1 3\n3 2\n3 4\n4 1", "3 4\n3 2\n1 2\n2 3\n1 3", "11 13\n1 2\n2 3\n3 4\n4 1\n1 5\n5 6\n6 7\n7 4\n3 8\n8 9\n9 10\n10 11\n11 2", "5 8\n1 2\n2 3\n3 4\n4 5\n5 1\n4 1\n3 5\n1 3", "8 10\n3 2\n1 5\n8 1\n1 2\n6 8\n3 8\n5 3\n2 4\n4 1\n4 3", "10 14\n3 10\n10 9\n9 2\n8 3\n4 3\n4 2\n1 8\n7 1\n6 5\n2 7\n6 4\n5 8\n10 1\n8 10", "5 6\n4 2\n3 5\n2 3\n5 4\n4 5\n3 4", "3 3\n2 3\n2 1\n3 2", "9 9\n1 2\n2 3\n3 4\n4 5\n5 1\n6 7\n7 8\n8 9\n9 6", "10 15\n3 9\n2 3\n4 10\n6 4\n3 10\n6 10\n8 6\n6 2\n6 7\n9 4\n6 3\n10 7\n1 3\n8 1\n7 3", "10 18\n10 3\n2 7\n2 5\n1 10\n4 3\n1 4\n6 10\n9 2\n5 10\n5 9\n1 9\n1 5\n2 3\n2 4\n10 4\n6 5\n8 5\n9 6", "10 13\n3 5\n1 6\n9 6\n5 4\n4 7\n10 9\n8 7\n5 6\n2 10\n9 3\n2 4\n6 3\n3 10", "10 16\n3 6\n5 6\n5 4\n3 2\n2 10\n1 7\n7 4\n6 2\n7 3\n4 6\n9 2\n9 7\n5 2\n10 9\n9 4\n7 8", "10 10\n10 1\n6 9\n5 3\n9 4\n3 8\n2 1\n5 9\n8 10\n6 5\n10 5", "5 9\n1 3\n1 4\n1 5\n2 1\n2 3\n2 4\n3 2\n5 2\n5 4", "10 18\n4 10\n7 2\n2 1\n7 5\n5 6\n6 8\n3 9\n3 10\n6 9\n8 7\n4 3\n2 10\n9 5\n7 3\n6 4\n7 10\n10 5\n3 2", "10 19\n5 9\n2 10\n3 7\n4 8\n4 2\n9 10\n3 6\n8 5\n6 10\n3 5\n4 1\n7 10\n8 9\n8 2\n7 9\n8 7\n9 1\n4 9\n8 10", "5 5\n1 2\n2 1\n3 4\n3 5\n4 5", "10 17\n5 6\n4 9\n7 1\n6 10\n3 10\n4 10\n9 3\n8 1\n2 4\n1 9\n3 7\n4 7\n6 2\n5 4\n3 8\n10 9\n7 10", "10 13\n7 2\n7 10\n10 5\n2 9\n10 4\n8 3\n4 5\n1 8\n7 8\n5 7\n2 10\n9 6\n5 9", "6 7\n1 2\n3 4\n4 5\n4 6\n5 6\n6 4\n6 3", "6 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1\n1 3\n4 6", "10 9\n7 2\n10 5\n9 1\n1 5\n4 6\n1 10\n6 2\n10 9\n5 9", "10 14\n8 2\n10 6\n6 1\n8 10\n6 2\n1 10\n4 7\n1 7\n9 1\n3 6\n1 4\n7 6\n10 4\n8 4", "10 19\n10 3\n9 2\n7 4\n6 3\n1 6\n6 5\n2 8\n6 9\n1 5\n9 8\n10 9\n1 8\n3 2\n5 2\n7 10\n8 7\n3 4\n2 4\n4 1", "10 14\n10 1\n8 9\n7 2\n8 2\n7 3\n7 10\n2 10\n6 3\n4 1\n6 5\n7 8\n10 6\n1 2\n8 10", "10 19\n10 9\n1 2\n3 6\n9 6\n2 6\n3 7\n2 10\n3 8\n2 9\n2 8\n4 7\n2 7\n6 7\n10 5\n8 1\n6 10\n8 5\n8 6\n3 2", "10 18\n8 2\n9 2\n7 4\n2 6\n7 1\n5 3\n9 4\n3 9\n3 8\n10 2\n10 1\n9 1\n6 7\n10 6\n5 6\n9 6\n7 5\n7 9", "8 13\n3 5\n6 2\n5 3\n8 3\n5 7\n6 4\n5 1\n7 6\n3 1\n7 2\n4 8\n4 1\n3 6", "7 7\n5 1\n3 7\n4 3\n1 5\n7 5\n3 6\n1 6", "3 4\n3 1\n3 2\n1 3\n1 2", "5 10\n1 3\n3 1\n2 3\n1 4\n2 4\n2 1\n5 3\n5 1\n4 1\n3 5", "5 6\n2 1\n3 2\n1 2\n2 3\n1 5\n3 1", "6 7\n6 2\n5 4\n2 1\n5 2\n6 5\n1 5\n5 6", "9 12\n1 2\n2 3\n2 4\n4 5\n3 5\n5 6\n6 7\n6 8\n7 9\n8 9\n9 1\n3 6", "4 6\n1 2\n1 3\n3 4\n4 2\n4 1\n2 3", "5 7\n1 2\n2 3\n3 1\n2 4\n4 1\n3 5\n5 2", "7 10\n1 5\n6 2\n2 7\n6 3\n5 7\n1 2\n3 5\n4 3\n5 2\n7 5", "8 11\n8 4\n3 6\n1 2\n8 1\n7 2\n4 3\n7 4\n3 1\n2 6\n4 5\n2 3", "7 16\n6 4\n5 1\n6 1\n3 7\n3 1\n5 4\n6 3\n2 7\n6 2\n1 4\n5 2\n4 7\n1 7\n6 5\n7 5\n2 4", "7 16\n1 7\n4 7\n2 3\n5 1\n6 1\n5 4\n3 1\n4 6\n2 1\n6 7\n4 1\n2 7\n3 4\n3 7\n7 2\n6 2", "4 7\n1 2\n3 4\n3 2\n1 4\n4 1\n4 2\n1 3", "500 13\n1 2\n2 3\n3 4\n4 1\n1 5\n5 6\n6 7\n7 4\n3 8\n8 9\n9 10\n10 11\n11 2"], "outputs": ["YES", "NO", "YES", "YES", "YES", "YES", "NO", "NO", "YES", "YES", "YES", "YES", "NO", "YES", "NO", "NO", "YES", "NO", "YES", "YES", "NO", "YES", "NO", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "NO", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "YES", "YES", "NO", "YES", "NO", "YES", "NO", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "NO", "YES", "NO", "YES", "YES", "NO", "YES", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "NO", "YES", "YES", "YES", "NO", "YES", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "NO", "YES", "YES", "NO", "YES", "YES", "YES", "NO", "YES", "NO"]}
UNKNOWN
PYTHON3
CODEFORCES
6
143975608b5342cde4acac925204f195
Little Elephant and Interval
The Little Elephant very much loves sums on intervals. This time he has a pair of integers *l* and *r* (*l*<=≤<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≤<=*x*<=≤<=*r*), that the first digit of integer *x* equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not. Help him and count the number of described numbers *x* for a given pair *l* and *r*. The single line contains a pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018) — the boundaries of the interval. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. On a single line print a single integer — the answer to the problem. Sample Input 2 47 47 1024 Sample Output 12 98
[ "def f(x):\n if x < 10:\n return x\n if str(x)[0] > str(x)[-1]:\n return x // 10 + 8\n else:\n return x // 10 + 9\nl, r = map(int, input().split())\nprint(f(r) - f(l - 1))", "def calc(r):\r\n if r<10:\r\n return r\r\n ret,l=r//10+9,len(str(r))\r\n if r%10 < r//10**(l-1):\r\n ret-=1\r\n return ret\r\n\r\nl,r=map(int,input().split())\r\nprint(calc(r) -calc(l-1))\r\n", "n, m = map(int, input().split())\r\n\r\n\r\ndef solve(num):\r\n if num < 10:\r\n return num\r\n ans = num // 10\r\n ans += 8\r\n if str(num)[0] <= str(num)[-1]:\r\n ans += 1\r\n return ans\r\n\r\n\r\nprint(solve(m)-solve(n-1))\r\n", "def digit(x):\r\n return x if x<10 else x//10+9-(0 if str(x)[0]<=str(x)[-1] else 1)\r\nl,r = map(int,input().split())\r\nprint(digit(r) - digit(l-1))", "def f(x): \r\n \r\n return x if x<10 else x//10+9-(0 if str(x)[0]<=str(x)[-1] else 1)\r\n \r\nl, r = map(int,input().split())\r\nprint(f(r)-f(l-1))\r\n", "def f(x):\r\n\ts = str(x);\r\n\treturn x//10 + min(x,9) - (s[0] > s[-1])\r\nn,m = map(int,input().split())\r\nprint(f(m)-f(n-1))\r\n", "\r\nfrom sys import stdin,stdout,setrecursionlimit\r\nstdin.readline\r\ndef mp(): return list(map(int, stdin.readline().strip().split()))\r\ndef it():return int(stdin.readline().strip())\r\nfrom collections import defaultdict as dd,Counter as C,deque\r\nfrom math import ceil,gcd,sqrt,factorial,log2,floor\t\r\nfrom bisect import bisect_right as br,bisect_left as bl\r\nfrom heapq import *\r\nmod = 10**9+7\r\n\r\ndef func(x):\r\n\tif x<10:\r\n\t\treturn x\r\n\tans = x//10\r\n\tans += 9\r\n\r\n\tif str(x)[-1]<str(x)[0]:\r\n\t\tans -= 1\r\n\treturn ans\r\n\r\ndef solve():\r\n\tl,r = mp()\r\n\tprint(func(r)-func(l-1))\r\n\r\nsolve()\r\n", "def size(x):\n res = 0\n while x > 0:\n x //= 10\n res += 1\n return res\n\n\ndef first(x):\n last = 0\n while x > 0:\n last = x % 10\n x //= 10\n return last\n\n\ndef last(x):\n return x % 10\n\n\ndef cut(x):\n x //= 10\n x -= first(x) * 10 ** (size(x) - 1)\n return x\n\n\ndef part(x):\n if x < 10:\n return x\n\n res = 9\n\n for i in range(2, size(x)):\n res += 9 * 10 ** (i - 2)\n\n res += cut(x)\n res += (first(x) - 1) * 10 ** (size(x) - 2)\n if first(x) <= last(x):\n res += 1\n\n return res\n\n\nl, r = list(map(int, input().split()))\n\n\nprint(part(r) - part(l - 1))\n", "from math import log, floor\r\n\r\nrdi = lambda: list(map(int, input().split()))\r\n\r\ndef f(x):\r\n if x < 10: return x\r\n ans = 9\r\n n = int(log(x, 10))+1\r\n for i in range(2, n): ans += 9*(10**(i-2))\r\n head = x//(10**(n-1))\r\n tail = x%10\r\n ans += (head-1)*(10**(n-2))\r\n ans += (x-head*(10**(n-1))-tail)//10+(tail>=head)\r\n return ans\r\n\r\nl, r = rdi()\r\nprint(f(r)-f(l-1))\r\n", "l,r=map(int,input().split())\r\ndef f(n): # from 0 to n\r\n cnt=0\r\n m=len(str(n))\r\n for i in range(1,10):\r\n for j in range(0,18):\r\n x=i*(10**(j+1))+i\r\n if len(str(x))<m:\r\n cnt+=10**j\r\n elif len(str(x))==m:\r\n if i<int(str(n)[0]):\r\n cnt+=10**j\r\n elif i==int(str(n)[0]):\r\n z=str(n)[1:m-1]\r\n zz=0\r\n if z!=\"\":\r\n zz=int(z)\r\n if int(str(n)[-1])>=i:\r\n cnt+=zz+1\r\n elif int(str(n)[-1])<i:\r\n cnt+=zz\r\n cnt+=min(9,n)\r\n return cnt\r\nprint(f(r)-f(l-1))", "def f(x):\r\n y=int(x)\r\n if y<10:\r\n return y\r\n else:\r\n if x[0]<=x[-1]:\r\n return y//10+9\r\n else:\r\n return y//10+8\r\nL,R=input().split()\r\nprint(f(R)-f(str(int(L)-1)))\r\n", "l, r = input().split()\n\nlr = len(r)\nretr = 1\nif lr > 1:\n for i in range(1,lr):\n retr += 9 * 10**max(i-2,0)\n r0 = int(r[0])\n retr += (r0-1) * 10**(lr-2)\n hr = r0*(10**(lr-1)+1)\n retr += (int(r)-hr)//10 + 1\nelse:\n retr += int(r)\n\nll = len(l)\nretl = 1\nif ll > 1:\n for i in range(1,ll):\n retl += 9 * 10**max(i-2,0)\n l0 = int(l[0])\n retl += (l0-1) * 10**(ll-2)\n hl = l0*(10**(ll-1)+1)\n retl += (int(l)-hl)//10 + 1\nelse:\n retl += int(l)\n\nif l[-1] == l[0]:\n retl -= 1\nprint(retr-retl)\n", "def Solve(t):\r\n if(t < 10):\r\n return t;\r\n A = 9\r\n for i in range(2 , 20):\r\n if(10 ** i - 1 <= t):\r\n A += 9 * (10 ** (i - 2))\r\n else:\r\n fd = int(str(t)[0])\r\n ld = t % 10\r\n A += (fd - 1) * (10 ** (i - 2))\r\n t -= fd * (10 ** (i - 1))\r\n if(ld >= fd):\r\n A += 1\r\n t = t // 10\r\n A += t\r\n break\r\n return A\r\nl , r = map(int , input().split())\r\nprint(Solve(r) - Solve(l - 1))\r\n \r\n", "import sys\n\ndef lowerOrEqual(x):\n # Base case\n if int(x) <= 999:\n good = 0\n while int(x) > 0:\n if x[0] == x[-1]:\n good += 1\n x = str(int(x) - 1)\n return good\n \n if x[0] == \"1\":\n # For example (each dot one number): 1...1 -> 9999\n mid = int(x[1:len(x)-1])\n new = \"\".join(\"9\"*(len(x) - 1))\n return mid + 1 + lowerOrEqual(new)\n else:\n # For example (each dot one number): 7...7 -> 69996\n end = str(int(x[0]) - 1)\n mid = int(x[1:len(x)-1])\n new = end + \"\".join(\"9\"*(len(x) - 2)) + end\n return mid + 1 + lowerOrEqual(new)\n\ndef fix(a):\n while a[0] != a[-1]:\n a = str(int(a) - 1)\n return a\n\nline = sys.stdin.readline().split(\" \")\na, b = str(int(line[0]) - 1), str(int(line[1]))\na, b = fix(a), fix(b)\nprint(lowerOrEqual(b) - lowerOrEqual(a))\n\n", "\r\ndef calc(n):\r\n l = len(n)\r\n ans = 9\r\n if(l==1):\r\n return int(n)\r\n if(l>=3):\r\n ans = int('9'*(l-2)) + 9\r\n ans+=int((int(n[0])-1) * 10**(l-2))\r\n #print(ans)\r\n if(l>2):\r\n ans+=int(n[1:-1])\r\n ans+=n[0]<=n[-1]\r\n return ans\r\na,b = input().split()\r\nprint(calc(b) - calc(a) + (a[0]==a[-1]))", "def get(x):\r\n if x < 10: return x\r\n\r\n first, last = int(str(x)[0]), int(str(x)[-1])\r\n ans = (x//10) + 9\r\n ans -= int(last < first)\r\n return ans\r\nl,r = map(int, input().split())\r\nprint(-get(l -1) + get(r))", "import sys\r\ninput = sys.stdin.readline\r\n\r\na, b = map(int, input().split())\r\nx = 0\r\nif a < 10:\r\n if b < 10:\r\n print(b-a+1)\r\n exit()\r\n else:\r\n x += 9-a\r\n\r\ny = b//10 - a//10 + 1\r\nif str(a)[-1] > str(a)[0]:\r\n y -= 1\r\nif str(b)[-1] < str(b)[0]:\r\n y -= 1\r\nprint(max(0, x+y))\r\n", "def floor(x, y):\r\n\treturn x // y\r\ndef ceil(x, y):\r\n\treturn x // y + (x % y != 0)\r\nl, r = map(int, input().split())\r\nans = (l <= 9) * (min(r, 9) - l + 1)\r\nfor k in range(0, 17):\r\n for d in range(1, 10):\r\n rb = floor(r - d, 10) - 10 ** k * d\r\n lb = ceil(l - d, 10) - 10 ** k * d\r\n rx = min(10 ** k - 1, rb)\r\n lx = max(0, lb)\r\n ans += (rx >= lx) * (rx - lx + 1)\r\nprint(ans)", "import sys\r\nimport math as m\r\np = [0]*20\r\ndef fi():\r\n\treturn sys.stdin.readline()\r\ndef check(n):\r\n\tans = 0\r\n\tans+=min(9,n)\r\n\tfor i in range (10):\r\n\t\tif i :\r\n\t\t\tif 10*i + i <=n:\r\n\t\t\t\tans+=1\r\n\tfor i in range (3,19):\r\n\t\tfor j in range (1,10):\r\n\t\t\tno = p[i-1]*j+j\r\n\t\t\tlo = -1\r\n\t\t\thi = p[i-2]\r\n\t\t\tres = 0\r\n\t\t\twhile hi-lo >1:\r\n\t\t\t\tmid = (lo+hi)//2\r\n\t\t\t\tif mid*10+no <= n:\r\n\t\t\t\t\tlo = mid\r\n\t\t\t\telse:\r\n\t\t\t\t\thi = mid\r\n\t\t\tans+=lo+1\r\n\treturn ans\r\nif __name__ == '__main__':\r\n\tp[0]=1\r\n\tfor i in range (1,19):\r\n\t\tp[i]=p[i-1]*10\r\n\tl,r = map(int, fi().split())\r\n\tans = check(r)-check(l-1)\r\n\tprint(ans)", "# n=int(input())\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\n#for i in range(m):\r\n# for _ in range(int(input())):\r\nfrom collections import Counter\r\n#from fractions import Fraction\r\n#n=int(input())\r\n#arr=list(map(int,input().split()))\r\n#ls = [list(map(int, input().split())) for i in range(n)]\r\nfrom math import log2\r\n#for _ in range(int(input())):\r\n#n, m = map(int, input().split())\r\n'''n, m = map(int, input().split())\r\ng=[]\r\nfor i in range(n):\r\n s=input()\r\n g.append(s)'''\r\ndef dfs(x,y,x1,y1):\r\n\tv.add((x,y))\r\n\tfor dx,dy in [(-1,0),(0,1),(1,0),(0,-1)]:\r\n\t\tif x+dx>=0 and x+dx<n and y+dy>=0 and y+dy<m and (x+dx,y+dy)!=(x1,y1) and a[x+dx][y+dy]==a[x][y]:\r\n\t\t\tif (x+dx,y+dy) in v or dfs(x+dx,y+dy,x,y):\r\n\t\t\t\treturn True\r\n\treturn False\r\nimport sys\r\nsys.setrecursionlimit(10000)\r\ndef ans(x):\r\n\tif x<=9:\r\n\t\treturn x\r\n\telse:\r\n\t\treturn (x//10)+9-(1 if str(x)[0]>str(x)[-1] else 0)\r\nn,m=map(int,input().split())\r\nprint(ans(m)-ans(n-1))\r\n\r\n\r\n", "def fun(x): \r\n if x>=10:\r\n return x//10+9-(0 if str(x)[0]<=str(x)[-1] else 1) \r\n else:\r\n return x\r\n \r\nl, r = map(int,input().split())\r\n\r\nprint(fun(r)-fun(l-1))", "def f(x):\r\n if x < 10:\r\n return x\r\n return x // 10 + 9 - (0 if str(x)[0] <= str(x)[-1] else 1)\r\n\r\n\r\ndef main():\r\n l, r = map(int, input().split())\r\n print(f(r) - f(l - 1))\r\n\r\n\r\nmain()", "l, r = map(int, input().split())\r\n\r\ndef count_valid(x):\r\n if x < 10:\r\n return x\r\n if str(x)[0] > str(x)[-1]:\r\n return x // 10 + 8\r\n else:\r\n return x // 10 + 8 + 1\r\n\r\nprint(count_valid(r) - count_valid(l-1))\r\n", "import sys\r\nimport math\r\nfrom sys import stdin, stdout\r\n \r\n# TAKE INPUT\r\ndef get_ints_in_variables():\r\n return map(int, sys.stdin.readline().strip().split())\r\ndef get_int(): return int(input())\r\ndef get_ints_in_list(): return list(\r\n map(int, sys.stdin.readline().strip().split()))\r\ndef get_list_of_list(n): return [list(\r\n map(int, sys.stdin.readline().strip().split())) for _ in range(n)]\r\ndef get_string(): return sys.stdin.readline().strip()\r\n\r\n# Aj solution\r\ndef sumCalc(n):\r\n if n <= 9:\r\n return n\r\n ln = len(str(n))\r\n ans = 9\r\n for i in range(ln-1, 1, -1):\r\n ans += (9*10**(i-2))\r\n ans += ((int(str(n)[0])-1)*10**(ln-2))\r\n digits = []\r\n t = n\r\n while t > 0:\r\n digits.append(t % 10)\r\n t = t//10\r\n digits.pop(0)\r\n digits.pop()\r\n digits = list(reversed(digits))\r\n # tmpAns = 1\r\n if ln >= 3:\r\n for i in range(len(digits)):\r\n v = digits[i]\r\n # print(v*(10**(ln-(3+i))), \"endm\")\r\n ans += (v*(10**(ln-(3+i))))\r\n \r\n if int(str(n)[0]) > int(str(n)[-1]):\r\n return ans\r\n else:\r\n return ans+1\r\n \r\ndef main():\r\n # Write Your Code Here\r\n l,r = get_ints_in_variables()\r\n if r < 10:\r\n x = r-(l-1)\r\n print(x)\r\n else:\r\n last = sumCalc(r)\r\n first = sumCalc(l-1)\r\n res = last-first\r\n print(res)\r\n# calling main Function\r\nif __name__ == \"__main__\":\r\n main()", "l,r=input().split()\r\ndef ans(n):\r\n a=0\r\n if len(n)==1:\r\n return int(n)\r\n elif len(n)==2:\r\n if n[1]<=n[0]:\r\n return int(n[0])+9\r\n else:\r\n return int(n[0])+10\r\n else:\r\n for i in range(len(n)-1):\r\n if i>0:\r\n a+=int(n[i])*(10**(len(n)-i-2))\r\n else:\r\n a+=(int(n[i])-1)*(10**(len(n)-i-2))\r\n if i==len(n)-2:\r\n if n[-1]>n[0]:\r\n a+=1\r\n return a\r\nx=ans(r)\r\ny=ans(l)\r\nif int(l)>99:\r\n for i in range(len(l)-1,1,-1):\r\n y+=ans('9'*i)+1\r\nif int(r)>99:\r\n for i in range(len(r)-1,1,-1):\r\n x+=ans('9'*i)+1\r\nif r[0]==r[-1]:\r\n x+=1\r\nprint(x-y)\r\n \r\n\r\n \r\n \r\n \r\n", "left, right = map(int, input().split())\r\n\r\ndef f(x):\r\n if x < 10:\r\n return x\r\n a = []\r\n t = x\r\n while t:\r\n a.append(t % 10)\r\n t //= 10\r\n a = a[::-1]\r\n ret = min(9, x)\r\n size = len(a)\r\n first = a[0]\r\n last = a[-1]\r\n for curSize in range(size - 1):\r\n for dig in range(1, 10):\r\n if curSize < size - 2 or dig < first:\r\n ret += 10 ** curSize\r\n elif dig == first:\r\n s = 0\r\n for i in range(1, size - 1):\r\n s = s * 10 + a[i]\r\n ret += s\r\n if last >= dig:\r\n ret += 1\r\n return ret\r\n\r\nprint(f(right) - f(left - 1))", "\r\n# hr bar 10 bd rha hai to 1 bdhta hai\r\n# total//10 krenge to bich ke aajayenge\r\n#ar agr last wala digit starting wale digit se jyada hai to starting wale\r\n# digit bhi last me aya hoga ar agr ni hai to ni aya hoga to 1 ghta denge\r\n\r\n\r\n\r\n\r\ndef f(x:int):\r\n if x<=9:\r\n return x\r\n else:\r\n\r\n #print(1*(str(x)[0] > str(x)[-1]))\r\n #print(9 -1*(str(x)[0] > str(x)[-1]))\r\n return x//10 + 9 -1*(str(x)[0] > str(x)[-1])\r\n\r\n\r\n\r\n\r\nl, r = map(int, input().split())\r\n\r\nprint(f(r)-f(l-1))\r\n\r\n", "def helper(x):\r\n\ts = str(x);\r\n\treturn x//10 + min(x,9) - (s[0] > s[len(s)-1])\r\nl,r = map(int,input().split())\r\nprint(helper(r)-helper(l-1))", "def ans(num):\r\n\treturn num if num<10 else num//10+9-(0 if str(num)[0]<=str(num)[-1] else 1)\r\nl,r=map(int,input().split())\r\nprint (ans(r)-ans(l-1))", "def ff(num):\r\n\treturn (int(num) // 10 - (0 if int(str(num)[0]) <= int(str(num)[-1]) else 1) + 9) if int(num) >= 10 else int(num)\r\n\r\ndef main():\r\n mode=\"filee\"\r\n if mode==\"file\":f=open(\"test.txt\",\"r\")\r\n #f.readline()\r\n #input()\r\n get = lambda :[int(x) for x in (f.readline() if mode==\"file\" else input()).split()]\r\n [l,r]=get()\r\n print(ff(r) - ff(l-1))\r\n \r\n\r\n\r\n if mode==\"file\":f.close()\r\n\r\n\r\nif __name__==\"__main__\":\r\n main()\r\n", "l, r = input().split()\r\ndef f(n):\r\n l, k = len(n), int(n)\r\n if l == 1: return k\r\n a, b = int(n[0]), int(n[l - 1])\r\n if l == 2: return 9 + a - int(b < a)\r\n return 9 + a * 10 ** (l - 2) - int(b < a) + int(n[1: l - 1])\r\nprint(f(r) - f(str(int(l) - 1)))\r\n", "l,r = map(int, input().split())\r\ndef helper(n):\r\n if n<= 9:\r\n return n\r\n res = n//10 + 9\r\n l = len(str(n))\r\n if n%10 < n//(10**(l-1)):\r\n res -= 1\r\n return res\r\nprint(helper(r)-helper(l-1))\r\n", "def cal(s):\n n=len(s)\n if(int(s)<=9):return int(s)\n\n ans=9\n for j in range(2,n):\n ans+=9*pow(10,j-2)\n d=int(s[0])\n ans+=(d-1)*pow(10,n-2)\n if(n>2 ):\n ans+=int(s[1:n-1])\n if(int(s[-1])>=int(s[0])):ans+=1\n return ans\n\na,b=(input().split(' '))\nprint(cal(b)-cal(str(int(a)-1)))", "def helper(x):\n s = str(x)\n return x // 10 + min(x, 9) - (s[0] > s[-1])\n\n\ndef main():\n a, b = map(int, input().split())\n print(helper(b) - helper(a - 1))\n\n\nif __name__ == '__main__':\n main()\n", "def count(x):\r\n if x < 10:\r\n return x\r\n elif str(x)[0] > str(x)[-1]:\r\n return x // 10 + 8\r\n else:\r\n return x // 10 + 8 + 1\r\n\r\nl,r = map(int,input().split())\r\nprint(count(r)-count(l-1))", "def fin(r):\r\n if r<10:\r\n return r\r\n ans=r//10+9\r\n l=len(str(r))\r\n if r%10 < r//10**(l-1):\r\n ans-=1 \r\n return ans\r\nl,r=map(int,input().split())\r\nprint(fin(r)-fin(l-1))\r\n", "def pre(n):\n if n == 0:\n return 0\n if n < 10:\n return n\n if n < 100:\n return 9 + n // 11\n digit = []\n while n: \n digit += [n % 10]\n n //= 10\n ans = 10**(len(digit) - 2) - 1\n digit.reverse()\n ans += int(''.join(map(str, digit[1:-1])))\n ans += (digit[0] <= digit[-1])\n ans += 10**(len(digit) - 2) * (digit[0] - 1)\n return ans + 9\nl, r = map(int, input().split())\nprint(pre(r) - pre(l - 1))\n", "l,r=map(int , input().split())\r\nten=1\r\nres=0\r\nfor i in range(18):\r\n for d in range(1,10,1):\r\n low,high=d*ten,(d+1)*ten-1\r\n low=max(low,l)\r\n high=min(high,r)\r\n while low%10 != d:\r\n low+=1\r\n while high%10 != d:\r\n high-=1\r\n if low<=high:\r\n res+=(high-low)//10+1\r\n ten*=10\r\nprint(res)\r\n\r\n", "l, r = [int(s) for s in input().split()]\r\n\r\ndef f1(x):\r\n c = 0\r\n for i in range(x+1):\r\n if str(i)[0] == str(i)[-1]:\r\n c += 1\r\n return c\r\n \r\ndef f(x):\r\n if x < 10:\r\n return x+1\r\n if x < 100:\r\n return 10 + x//10 - (1 if x%10 < x//10 else 0)\r\n \r\n res = 19\r\n c = 1\r\n for l in range(3, len(str(x))):\r\n c *= 10\r\n res += 9*c\r\n #print(res)\r\n \r\n c*= 10\r\n res += (int(str(x)[0])-1) * c\r\n #print(res)\r\n res += (int(str(x)[1:-1])) + 1\r\n #print(res)\r\n res -= 1 if int(str(x)[0]) > int(str(x)[-1]) else 0\r\n #print(res)\r\n return res\r\n \r\nprint(f(r) - f(l-1))\r\n \r\n", "import sys\n\ndef fix(a):\n while a[0] != a[-1]:\n a = str(int(a) - 1)\n return a\n\ndef lowerOrEqual(x):\n x = fix(x)\n\n # Base case\n if int(x) <= 999:\n good = 0\n while int(x) > 0:\n if x[0] == x[-1]:\n good += 1\n x = str(int(x) - 1)\n return good\n \n mid = int(x[1:len(x)-1])\n x = str(int(x) - mid * 10 - 1)\n return mid + 1 + lowerOrEqual(x)\n\nline = sys.stdin.readline().split(\" \")\na, b = str(int(line[0]) - 1), str(int(line[1]))\nprint(lowerOrEqual(b) - lowerOrEqual(a))\n", "import math\r\nimport sys\r\nfrom bisect import bisect_right, bisect_left\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\na, b = R()\r\n\r\ndef cnt(num):\r\n if num < 10:\r\n return num\r\n tmp = num\r\n n = 0\r\n t = []\r\n while tmp:\r\n t.append(tmp % 10)\r\n tmp //= 10\r\n n += 1\r\n res = 0\r\n for x in range(n - 1):\r\n if x == 0:\r\n res += 9\r\n else:\r\n res += 9 * 10**(x - 1)\r\n for i in range(1, n):\r\n d = t[i]\r\n if i < n - 1:\r\n res += d * 10**(i-1)\r\n else:\r\n res += (d - 1) * 10**(i-1)\r\n if t[0] >= t[-1]:\r\n res += 1\r\n return res\r\n\r\nprint(cnt(b) - cnt(a - 1))", "def f(x):\n if x < 10:\n return x\n ans = 9 + (x//10)\n if int(str(x)[0]) > int(str(x)[-1]):\n ans -= 1\n return ans\n\nl, r = list(map(int, input().split(\" \")))\n\nprint(f(r) - f(l-1))\n", "def fin(n):\r\n aa = str(n)\r\n ans=0\r\n if len(aa)>1:\r\n ans=9\r\n for i in range(2,len(aa)):\r\n ans+=(9*(10**(i-2)))\r\n if aa[-1]<aa[0]:\r\n if(aa[1:-1]==''):\r\n ans+=0\r\n else:\r\n ans+=(int(aa[1:-1])) \r\n else:\r\n if(aa[1:-1]==''):\r\n ans+=1\r\n else:\r\n ans+=(int(aa[1:-1])+1)\r\n ans+=(int(aa[0])-1)*(10**(len(aa[1:-1]))) \r\n# print(ans) \r\n return ans \r\nl,r = map(int,input().split())\r\nprint(fin(r)-fin(l-1))\r\n", "def func(b):\r\n n2 = len(b)\r\n ans = 0\r\n\r\n for i in range(1, n2):\r\n if i == 1: ans += 9\r\n else:\r\n ans += 9 * (10 ** (i - 2))\r\n \r\n for i in range(0, n2 - 1):\r\n if n2 > 2:\r\n if i == 0: tmp = (int(b[i]) - 1) * (10 ** (n2 - 2 - i))\r\n else: tmp = (int(b[i])) * (10 ** (n2 - 2 - i))\r\n else:\r\n tmp = int(b[i]) - 1\r\n ans += tmp\r\n if n2 == 1: ans = int(b)\r\n elif int(b[n2 - 1]) >= int(b[0]): ans -= -1\r\n return ans\r\n\r\na, b = map(int, input().split())\r\na += -1\r\na = str(a)\r\nb = str(b)\r\n\r\nans1 = func(a)\r\nans2 = func(b)\r\n\r\n# print(ans1, ans2)\r\n\r\nprint(func(b) - func(a))\r\n", "def f(x):\r\n s = str(x)\r\n return x//10 + min(x, 9) - (s[0] > s[-1])\r\n\r\nn, m = map(int, input().split())\r\nprint(f(m)-f(n-1))\r\n", "def f(x:int):\r\n if x<=9:\r\n return x\r\n else:\r\n return x//10 + 9 -1*(str(x)[0] > str(x)[-1])\r\nl, r = map(int, input().split())\r\n\r\nprint(f(r) - f(l-1))", "def f(x): \r\n if x<10:\r\n return x \r\n else:\r\n return x//10+9-(0 if str(x)[0]<=str(x)[-1] else 1)\r\n \r\nl, r = map(int,input().split())\r\nprint(f(r)-f(l-1))\r\n", "def f(x):\r\n l = len(str(x))\r\n if l == 1:\r\n return x\r\n if l == 2:\r\n t=0\r\n for i in [1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99]:\r\n if i <= x:\r\n t+=1\r\n return t\r\n ans = 9\r\n for i in range(2, l):\r\n ans += 9 * 10 ** (i-2)\r\n ans += 10**(l-2) * (int(str(x)[0])-1)\r\n ans += int(str(x)[1:len(str(x))-1])\r\n if int(str(x)[-1])<int(str(x)[0]):\r\n ans -= 1\r\n return ans+1\r\n\r\na, b = list(map(int, input().split(' ')))\r\nprint(f(b)-f(a-1))\r\n", "#!/usr/bin/env python3\r\n\r\ndef g(n):\r\n if n<10: return n\r\n l = []\r\n m = n\r\n while n>0:\r\n l.append(n%10)\r\n n = n//10\r\n c = m//10 + 8 + (l[-1]<=l[0])\r\n return c\r\n\r\ndef f(l,r):\r\n return g(r)-g(l-1)\r\n\r\nl,r = map(int,input().split())\r\nprint(f(l,r))\r\n", "def find(s):\r\n n = len(s)\r\n x = int(s)\r\n if (x < 10):\r\n return x\r\n ans = x // 10 - 1\r\n ans = ans + 9\r\n if (s[0] <= s[n-1]):\r\n ans = ans + 1\r\n return ans\r\n\r\nl, r = map(int, input().split())\r\nl = l - 1\r\nl = str(l)\r\nr = str(r)\r\ncount1 = find(l)\r\ncount2 = find(r)\r\nprint(count2 - count1)", "'''\r\nBeezMinh\r\n19:40 UTC+7\r\n03/08/2023\r\n'''\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\ndef calc(x):\r\n s = str(x)\r\n return (x // 10) + min(x, 9) - (s[0] > s[-1])\r\n \r\nn, m = map(int, input().split())\r\nprint(calc(m) - calc(n - 1))", "# author: sharrad99\r\ndef get(x):\r\n\treturn x if x < 10 else x // 10 + 9 - (0 if str(x)[0] <= str(x)[-1] else 1)\r\nl, r = map(int, input().split())\r\nprint(get(r) - get(l - 1))\r\n" ]
{"inputs": ["2 47", "47 1024", "1 1000", "1 10000", "47 8545", "1000 1000", "47547 4587554587754542", "1 1000000", "47 74", "10001 10000002", "10000 100000", "458754 4588754", "111 111", "110 147", "1 1000000000", "12 10000000000", "1000000000 1000000000", "1 1000000000000000000", "11 111111111111111100", "100000000000000000 1000000000000000000", "45481484484 848469844684844", "975400104587000 48754000000000001", "11220451511 51511665251233335", "77 77", "99 102", "9997 87878000008", "10000000001 111111111111100001", "7777 88888", "999999999 10000000000", "235 236", "1 1", "2 2", "1 2", "4 7", "7 10", "1 11", "1 10", "7 8", "88 990", "458985985498001244 985458425544874008", "115998725487587451 245744899758754501", "595754249475458004 615044544745124547", "9754875457700 1000000000000000000", "8758754570000 999999999999999999", "111111111111111111 333333333444444445", "822981258385599125 841978899930248528", "779547115376367013 980561039207670775", "335408916782916802 416495628489807285", "252509053898415172 285803555062529649", "919845424847912645 970651082117950285", "522842183413115088 853628713003942530", "84324827171274023 607953653548585226", "1312148742261681 277460340506883334", "645762257531682046 885295120956158518", "819875140559301752 946247219812473271", "4 19", "5 45", "9999999999999987 99999999999999711", "2 3", "1827171 232817181719384635", "999999999999999999 1000000000000000000", "73 678"], "outputs": ["12", "98", "108", "1008", "849", "0", "458755458770699", "100008", "2", "999001", "9000", "413001", "1", "4", "100000008", "999999998", "0", "100000000000000008", "11111111111111109", "90000000000000000", "84842436320036", "4777859989541300", "5151165403078183", "1", "2", "8787799002", "11111110111110001", "8112", "900000001", "0", "1", "1", "2", "4", "3", "10", "9", "2", "91", "52647244004687276", "12974617427116705", "1929029526966655", "99999024512454230", "99999124124543000", "22222222233333334", "1899764154464941", "20101392383130376", "8108671170689049", "3329450116411448", "5080565727003764", "33078652959082744", "52362882637731121", "27614819176462166", "23953286342447648", "12637207925317152", "7", "9", "8999999999999973", "2", "23281718171755747", "1", "61"]}
UNKNOWN
PYTHON3
CODEFORCES
52
143bfa7b8d53e4b19209a18df9563490
"Or" Game
You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR. Find the maximum possible value of after performing at most *k* operations optimally. The first line contains three integers *n*, *k* and *x* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=10, 2<=≤<=*x*<=≤<=8). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). Output the maximum value of a bitwise OR of sequence elements after performing operations. Sample Input 3 1 2 1 1 1 4 2 3 1 2 4 8 Sample Output 3 79
[ "n, k, x = map(int, input().split())\r\nx = x**k\r\nleft_or = [None]*(n)\r\nright_or = [None]*(n)\r\na = list(map(int, input().split()))\r\ncurrent_or = 0\r\nfor i in range(n):\r\n current_or |= a[i]\r\n left_or[i] = current_or\r\ncurrent_or = 0\r\nfor i in range(n-1, -1, -1):\r\n current_or |= a[i]\r\n right_or[i] = current_or\r\nbest_res = 0\r\nfor i in range(n):\r\n res = a[i]*x\r\n if i != 0:\r\n res |= left_or[i-1]\r\n if i != n-1:\r\n res |= right_or[i+1]\r\n best_res = max(res, best_res)\r\nprint(best_res)", "n,k,x=map(int,input().split())\n*a,=map(int,input().split())\nl=[0]*(n+1)\nr=[0]*(n+1)\nfor i in range(0,n):\n l[i+1]=l[i]|a[i]\n r[n-i-1]=r[n-i]|a[n-i-1]\nnum=x**k\nres=-1\nfor i in range(0,n):\n res=max(l[i]|(a[i]*num)|r[i+1],res)\nprint(res) \n\t \t\t\t \t\t \t\t \t \t \t \t", "import sys\r\nimport math\r\n\r\n[n,k,x] = [int(i) for i in sys.stdin.readline().rstrip('\\n').split()]\r\nnums = [int(i) for i in sys.stdin.readline().rstrip('\\n').split()]\r\n\r\n\r\noffset = 1\r\nfor i in range(k):\r\n\toffset = offset*x\r\n\r\nleftor = [0]\r\nfor i in nums[:-1]:\r\n\tleftor.append(leftor[-1] | i)\r\nrightor = [0]\r\nfor i in range(len(nums)-1,0,-1):\r\n\trightor.append(rightor[-1] | nums[i])\r\nans = []\r\nfor i in range(len(nums)):\r\n\tans.append(leftor[i] | ((nums[i]*offset) | rightor[n-i-1]))\r\n\r\nsys.stdout.write(str(max(ans))+'\\n')", "def main():\n n, k, x = map(int, input().split())\n aa = list(map(int, input().split()))\n x, lo, u = x ** k, [0] * n, 0\n for i, a in enumerate(aa):\n lo[i] = u\n u |= a\n hi, u = [], 0\n for a in reversed(aa):\n hi.append(u)\n u |= a\n hi.reverse()\n for i, u, a, v in zip(range(n), lo, aa, hi):\n aa[i] = a * x | u | v\n print(max(aa))\n\n\nif __name__ == '__main__':\n main()\n", "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\nn,k,x=invr()\r\nara=inara()\r\nara.append(0)\r\nara.reverse()\r\nara.append(0)\r\nara.reverse()\r\n\r\nmul=int(math.pow(x,k))\r\n\r\npref=[0]*(n+2)\r\n\r\nfor i in range(1,n+1):\r\n\tpref[i]=pref[i-1]|ara[i]\r\n\r\nsuff=[0]*(n+2)\r\n\r\nfor i in range(n,0,-1):\r\n\tsuff[i]=suff[i+1]|ara[i]\r\n\t\r\nans=0\r\n\r\nfor i in range(1,n+1):\r\n\tans=max(ans,pref[i-1]|ara[i]*mul|suff[i+1])\r\n\r\nprint(ans)\r\n", "__author__ = 'kitkat'\r\nimport sys\r\n\r\n#sys.stdin = open(\"in.txt\")\r\ntry:\r\n while True:\r\n n, k, x = map(int, input().split(\" \"))\r\n val = [0] + list(map(int, input().split(\" \")))\r\n res = 0\r\n L = [0 for i in range(200003)]\r\n R = [0 for i in range(200003)]\r\n for i in range(1, n+1, 1):\r\n L[i] = L[i-1] | val[i]\r\n R[n-i+1] = R[n-i+2] | val[n-i+1]\r\n for i in range(1, n+1, 1):\r\n for j in range(k):\r\n val[i] *= x\r\n for i in range(1, n+1, 1):\r\n res = max(res, L[i-1] | R[i+1] | val[i])\r\n print(res)\r\nexcept EOFError:\r\n pass\r\n", "def get_or(a,b):\r\n return a|b\r\nclass SegmentTree:\r\n def __init__(self, data, default=0, func=max):\r\n \"\"\"initialize the segment tree with data\"\"\"\r\n self._default = default\r\n self._func = func\r\n self._len = len(data)\r\n self._size = _size = 1 << (self._len - 1).bit_length()\r\n\r\n self.data = [default] * (2 * _size)\r\n self.data[_size:_size + self._len] = data\r\n for i in reversed(range(_size)):\r\n self.data[i] = func(self.data[i + i], self.data[i + i + 1])\r\n\r\n def __delitem__(self, idx):\r\n self[idx] = self._default\r\n\r\n def __getitem__(self, idx):\r\n return self.data[idx + self._size]\r\n\r\n def __setitem__(self, idx, value):\r\n idx += self._size\r\n self.data[idx] = value\r\n idx >>= 1\r\n while idx:\r\n self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])\r\n idx >>= 1\r\n\r\n def __len__(self):\r\n return self._len\r\n\r\n def query(self, start, stop):\r\n \"\"\"func of data[start, stop)\"\"\"\r\n start += self._size\r\n stop += self._size\r\n\r\n res_left = res_right = self._default\r\n while start < stop:\r\n if start & 1:\r\n res_left = self._func(res_left, self.data[start])\r\n start += 1\r\n if stop & 1:\r\n stop -= 1\r\n res_right = self._func(self.data[stop], res_right)\r\n start >>= 1\r\n stop >>= 1\r\n\r\n return self._func(res_left, res_right)\r\n\r\n def __repr__(self):\r\n return \"SegmentTree({0})\".format(self.data)\r\ndef f(a,k,x):\r\n st=SegmentTree(data=a,func=get_or,default=0)\r\n n=len(a)\r\n x=pow(x,k)\r\n cmax=st.query(0,n)\r\n for i in range(len(a)):\r\n st.__setitem__(i,a[i]*x)\r\n cmax=max(cmax,st.query(0,n))\r\n st.__setitem__(i,a[i])\r\n return cmax\r\n\r\nn,k,x=map(int,input().strip().split())\r\na=list(map(int,input().strip().split()))\r\n# a=[200]*(2*(10**5))\r\nprint(f(a,k,x))", "def pw(a, x, k):\r\n if a == 0:\r\n return 0;\r\n ans = a;\r\n while (k > 0):\r\n ans *= x;\r\n k = k - 1;\r\n return ans;\r\nn, k, x = map(int, input().split());\r\na = list(map(int, input().split()));\r\nlft = [];\r\nlft.append(0);\r\nfor val in a:\r\n lft.append(val);\r\nlft.append(0);\r\nrht = [];\r\nfor val in lft:\r\n rht.append(val);\r\nfor i in range(1, len(lft)):\r\n lft[i] = lft[i] | lft[i - 1];\r\n#print (lft);\r\nfor i in range(len(rht) - 2, -1, -1):\r\n rht[i] = rht[i] | rht[i + 1];\r\n#print (rht);\r\nans = 0;\r\nfor i in range (1, len(lft) - 1):\r\n if(ans < (lft[i - 1] | pw(a[i - 1], x, k) | rht[i + 1])):\r\n ans = lft[i - 1] | pw(a[i - 1], x, k) | rht[i + 1];\r\nprint (ans);\r\n", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nimport math\r\nfrom heapq import heappush , heappop\r\nfrom collections import defaultdict,deque,Counter\r\nfrom bisect import *\r\n\r\nN,K,X = map(int, input().split())\r\nA = list(map(int, input().split()))\r\nA.sort()\r\n\r\n\r\nans = 0\r\ncnt = [0]*64\r\nfor a in A:\r\n for i in range(64):\r\n if a&(1<<i):\r\n cnt[i]+=1\r\n\r\nfor a in A:\r\n tmp = cnt[::]\r\n for i in range(64):\r\n if a&(1<<i):\r\n tmp[i]-=1\r\n a*=pow(X,K)\r\n cur = 0\r\n for i in range(64):\r\n if a&(1<<i):\r\n tmp[i]+=1\r\n if tmp[i]:\r\n cur+=(1<<i)\r\n ans = max(ans, cur)\r\n\r\nprint(ans)\r\n \r\n ", "\r\nn,k,x = map( int,input().split() )\r\n*Arr, = map( int,input().split() )\r\n\r\nPrfx = [0]*(n+2)\r\nSffx = [0]*(n+2)\r\n\r\nfor i in range(0,n):\r\n Prfx[i+1] = Prfx[i]|Arr[i]\r\n Sffx[n-i-1] = Sffx[n-i]|Arr[n-i-1]\r\nnow = x**k\r\nRes = 0\r\nfor i in range(0,n):\r\n Res = max( Prfx[i]|(Arr[i]*now)|Sffx[i+1],Res );\r\nprint(Res)", "# -*- coding:utf-8 -*-\n\n\"\"\"\n\ncreated by shuangquan.huang at 1/10/20\n\n\"\"\"\n\nimport collections\nimport time\nimport os\nimport sys\nimport bisect\nimport heapq\nfrom typing import List\nimport itertools\n\n\ndef blen(val):\n s = 0\n while val > 0:\n s += 1\n val >>= 1\n \n return s\n\n\ndef solve(N, K, X, A):\n left = [0 for _ in range(N)]\n right = [0 for _ in range(N)]\n \n for i, v in enumerate(A):\n left[i] = (left[i-1] if i-1 >= 0 else 0) | v\n for i in range(N-1, -1, -1):\n right[i] = (right[i+1] if i+1 < N else 0) | A[i]\n \n ans = 0\n for i, v in enumerate(A):\n a = left[i-1] if i-1 >= 0 else 0\n b = right[i+1] if i+1 < N else 0\n ans = max(ans, a | b | (v * X**K))\n \n return ans\n \n \n\nN, K, X = map(int, input().split())\nA = [int(x) for x in input().split()]\nprint(solve(N, K, X, A))", "# -*- coding:utf-8 -*-\n\n\"\"\"\n\ncreated by shuangquan.huang at 1/10/20\n\na simple conclusion is that we should multiple only one v with x K times\n\n\"\"\"\n\nimport collections\nimport time\nimport os\nimport sys\nimport bisect\nimport heapq\nfrom typing import List\n\n\ndef solve(N, K, X, A):\n prefix = [0 for _ in range(N)]\n suffix = [0 for _ in range(N)]\n \n for i, v in enumerate(A):\n prefix[i] = (prefix[i-1] if i-1 >= 0 else 0) | v\n for i in range(N-1, -1, -1):\n suffix[i] = (suffix[i+1] if i+1 < N else 0) | A[i]\n \n ans = 0\n for i, v in enumerate(A):\n a = prefix[i-1] if i-1 >= 0 else 0\n b = suffix[i+1] if i+1 < N else 0\n ans = max(ans, a | b | (v * X**K))\n \n return ans\n \n\nN, K, X = map(int, input().split())\nA = [int(x) for x in input().split()]\nprint(solve(N, K, X, A))", "import sys\r\n\r\nn, k, x = [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\ntl = 0\r\nl = [0] * (n + 1)\r\nfor i in range(n - 1, -1, -1):\r\n tl |= a[i]\r\n l[i] = tl\r\n\r\nans = 0\r\ntr = 0\r\nfor i in range(0, n):\r\n ta = tr | a[i] * x ** k | l[i + 1]\r\n ans = ans if ans > ta else ta\r\n tr |= a[i]\r\n\r\nprint(ans)\r\n", "# للمقارنة\r\nprefix = list()\r\nsuffix = list()\r\n# المدخلات\r\nn,k,x = input().split()\r\ns = input().split()\r\n# لتخزين قيمة الضرب\r\nmaxi = int(x)**int(k)\r\n # تعيين القائمة 0\r\nprefix = [0]*(int(n)+1)\r\nsuffix = [0]*(int(n)+1)\r\n# تغيير قيم القوائم\r\nfor i in range(0,int(n)):\r\n prefix[i+1] = prefix[i] | int(s[i])\r\n suffix[int(n)-1-i] = suffix[int(n)-i] | int(s[int(n)-1-i])\r\n# إيجاد الناتج\r\nans = 0\r\nfor i in range(0,int(n)):\r\n ans = max(ans, prefix[i] | int(s[i]) * maxi | suffix[i+1])\r\n# طباعة الناتج\r\nprint(ans)", "\r\nif __name__ == '__main__':\r\n n, k, p = map(int, input().split())\r\n numbers = list(map(int, input().split()))\r\n # initialize vectors x, y with 0 for n + 10 positions\r\n x = [0] * (n + 10)\r\n y = [0] * (n + 10)\r\n # raise to power\r\n p = p ** k\r\n maxi = 0\r\n for i in range(n):\r\n x[i + 1] = numbers[i] | x[i]\r\n for j in range(n, -1, -1):\r\n y[j - 2] = numbers[j - 1] | y[j - 1]\r\n for i in range(n):\r\n if maxi < x[i] | numbers[i] * p | y[i]:\r\n maxi = x[i] | numbers[i] * p | y[i]\r\n print(maxi)", "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,K,X = map(int,input().split())\nA = list(map(int,input().split()))\nl = [0]*(N+1)\nr = [0]*(N+1)\nfor i in range(0,N):\n l[i+1] = l[i]|A[i]\n r[N-i-1] = r[N-i]|A[N-i-1]\nnum = X**K\nans = -1\nfor i in range(0,N):\n ans = max(l[i]|(A[i]*num)|r[i+1],ans)\nprint(ans) ", "class Ortree():\r\n def __init__(self, n, As):\r\n size = 1\r\n while n > size:\r\n size *= 2\r\n self.size = size\r\n data = [0] * size + As[:] + [0] * (size - n)\r\n for idx in range(self.size - 1, 0, -1):\r\n idx2 = idx << 1\r\n data[idx] = data[idx2] | data[idx2 + 1]\r\n self.data = data\r\n \r\n def update(self, idx, val):\r\n pos = idx + self.size\r\n self.data[pos] = val\r\n pos >>= 1\r\n while pos:\r\n pos2 = pos << 1\r\n self.data[pos] = self.data[pos2] | self.data[pos2 + 1]\r\n pos >>= 1\r\n return self.data[1]\r\n\r\n\r\ndef solve(n, k, x, As):\r\n As.sort(reverse= True)\r\n xk = x**k\r\n if n == 1:\r\n As[0] *= xk\r\n return As[0]\r\n if is_simplecase(xk, As):\r\n As[0] *= xk\r\n return cumor(As)\r\n return complexcase(n, xk, As)\r\n \r\n\r\ndef cumor(As):\r\n result = 0\r\n for a in As:\r\n result |= a\r\n return result\r\n\r\ndef is_simplecase(xk, As):\r\n len0 = len(bin(As[0] * xk))\r\n len1 = len(bin(As[1] * xk))\r\n return len0 > len1\r\n\r\ndef complexcase(n, xk, As):\r\n len0 = len(bin(As[0] * xk))\r\n for i, a in enumerate(As[1:], 1):\r\n if len(bin(a * xk)) < len0:\r\n end = i\r\n rest = cumor(As[end:])\r\n break\r\n else:\r\n end = n\r\n rest = 0\r\n ortree = Ortree(end, As[:end])\r\n record = rest\r\n for i in range(end):\r\n score = ortree.update(i, As[i] * xk) | rest\r\n if record < score:\r\n record = score\r\n ortree.update(i, As[i])\r\n return record\r\n\r\nn, k, x = map(int, input().split())\r\nAs = list(map(int, input().split()))\r\nprint(solve(n, k, x, As))", "n,k,x = map(int,input().split())\r\nlis = list(map(int,input().split()))\r\npre=[0]*(n+2)\r\npos=[0]*(n+2)\r\nans=0\r\nm=x**k\r\nfor i in range(1,n):\r\n pre[i]=pre[i-1]|lis[i-1]\r\nfor i in range(n,0,-1):\r\n pos[i]=pos[i+1]|lis[i-1]\r\nfor i in range(1,n+1):\r\n ans=max(ans,pre[i-1]|lis[i-1]*m|pos[i+1])\r\nprint(ans) \r\n\r\n\r\n", "n,k,x=map(int,input().split())\nl=list(map(int,input().split()))\na=[0]*n\nb=[0]*n\nfor i in range(1,n): a[i]=a[i-1]|l[i-1]\nfor i in range(1,n): b[n-i-1]=b[-i]|l[-i]\nnom=0\nfor i in range(1,n):\n if l[nom]*(x**k)|a[nom]|b[nom]<l[i]*(x**k)|a[i]|b[i]: nom=i\nl[nom]*=x**k\nprint(l[nom]|a[nom]|b[nom])\n\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 = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\ninp = lambda dtype: [dtype(x) for x in input().split()]\r\ninp_2d = lambda dtype, n: [dtype(input()) for _ in range(n)]\r\nceil1 = lambda a, b: (a + b - 1) // b\r\ndebug = lambda *x: print(*x, file=sys.stderr)\r\nget_bit = lambda x, i: (x >> i) & 1\r\nout = []\r\n\r\nn, k, x = inp(int)\r\na = array('i', inp(int))\r\ntot, mem = 0, array('i', [0] * 30)\r\n\r\nfor i in a:\r\n tot |= i\r\n for bit in range(30):\r\n mem[bit] += get_bit(i, bit)\r\n\r\nans = tot\r\nfor i in a:\r\n cur = tot\r\n for bit in range(30):\r\n if get_bit(i, bit) and mem[bit] == 1:\r\n cur ^= 1 << bit\r\n\r\n ans = max(ans, cur | (pow(x, k) * i))\r\nprint(ans)\r\n", "n, k, x = map(int, input().split())\na = list(map(int, input().split()))\n\nx = x ** k\n\npref, suff = [0]*n, [0]*n\n\nfor i in range(n - 1):\n pref[i + 1] = a[i] | pref[i]\nfor i in range(n - 1, 0, -1):\n suff[i - 1] = a[i] | suff[i]\n\nres = 0\nfor i in range(n):\n res = max(res, (a[i] * x) | pref[i] | suff[i])\n\nprint(res)\n", "import math\r\na=list(map(int,input().split()))\r\nn=a[0]\r\nk=a[1]\r\nx=a[2]\r\na=list(map(int,input().split()))\r\nb=[None]*n\r\nc=[None]*n\r\nb[0]=a[0]\r\nmul=1\r\nc[n-1]=a[n-1]\r\nfor i in range(k):\r\n mul*=x\r\nif n==1:\r\n print(mul*a[0])\r\nelse:\r\n for i in range(1,n):\r\n b[i]=b[i-1]|a[i]\r\n for i in range(n-2,-1,-1):\r\n c[i]=c[i+1]|a[i]\r\n ans=max(a[0]*mul|c[1],a[n-1]*mul|b[n-2])\r\n for i in range(1,n-1):\r\n ans=max(ans,a[i]*mul|b[i-1]|c[i+1])\r\n print(ans)\r\n" ]
{"inputs": ["3 1 2\n1 1 1", "4 2 3\n1 2 4 8", "2 1 2\n12 9", "2 1 2\n12 7", "3 1 3\n3 2 0", "5 10 8\n1000000000 1000000000 1000000000 1000000000 1000000000", "1 2 3\n612635770", "3 2 5\n0 2 3", "2 1 8\n18 17", "5 10 8\n0 0 0 0 0", "1 1 2\n1", "1 1 2\n0", "3 2 6\n724148075 828984987 810015532", "3 1 2\n17 18 4", "3 1 2\n4 17 18", "2 2 2\n60 59", "2 2 2\n9 10", "3 1 2\n10 12 5", "3 1 2\n20 17 8", "3 1 2\n5 12 10", "3 1 8\n10 17 18", "3 1 2\n17 20 28", "5 1 3\n1 5 13 8 16"], "outputs": ["3", "79", "30", "31", "11", "1073741825000000000", "5513721930", "75", "154", "0", "2", "0", "29996605423", "54", "54", "252", "46", "31", "62", "31", "155", "62", "63"]}
UNKNOWN
PYTHON3
CODEFORCES
22
1450da53095949ecb270a669f433444e
Hopscotch
So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks in the same row are numbered from left to right). Let us describe the hopscotch with numbers that denote the number of squares in the row, staring from the lowest one: 1-1-2-1-2-1-2-(1-2)..., where then the period is repeated (1-2). The coordinate system is defined as shown in the figure. Side of all the squares are equal and have length *a*. Maria is a very smart and clever girl, and she is concerned with quite serious issues: if she throws a stone into a point with coordinates (*x*,<=*y*), then will she hit some square? If the answer is positive, you are also required to determine the number of the square. It is believed that the stone has fallen into the square if it is located strictly inside it. In other words a stone that has fallen on the square border is not considered a to hit a square. The only input line contains three integers: *a*, *x*, *y*, where *a* (1<=≤<=*a*<=≤<=100) is the side of the square, *x* and *y* (<=-<=106<=≤<=*x*<=≤<=106,<=0<=≤<=*y*<=≤<=106) are coordinates of the stone. Print the number of the square, inside which the stone fell. If the stone is on a border of some stone or outside the court, print "-1" without the quotes. Sample Input 1 0 0 3 1 1 3 0 10 3 0 7 3 4 0 Sample Output -1 1 5 -1 -1
[ "import sys\r\nfrom typing import Callable\r\n\r\ndef get_quadrant_num(height, is_double, x) -> int:\r\n if height < 3:\r\n return height\r\n height -= 2\r\n # Calc number of row below\r\n height_row_below = height - 1\r\n r = 2 + 2 * (height_row_below // 2) + height_row_below // 2 + (2 if height_row_below % 2 != 0 else 0)\r\n if is_double and x < 0:\r\n return (r + 1)\r\n elif is_double and x > 0:\r\n return (r + 2)\r\n else:\r\n return (r + 1)\r\ndef main() -> None:\r\n read: Callable[[], str] = sys.stdin.readline\r\n a, x, y = (int(i) for i in read().split())\r\n # Get the quadrant\r\n if y % a == 0:\r\n print(-1)\r\n else:\r\n is_double = False\r\n quadrant = y // a + 1\r\n if quadrant < 2:\r\n width = a / 2\r\n elif quadrant >= 3 and quadrant % 2 != 0:\r\n width = a\r\n is_double = True\r\n else:\r\n width = a / 2\r\n\r\n if abs(x) >= width:\r\n print(-1)\r\n elif width == a and x == 0:\r\n print(-1)\r\n else:\r\n print(get_quadrant_num(quadrant, is_double, x))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()", "a, x, y = map(int, input().split())\r\n\r\noutput = -1\r\nif 0 < y < a:\r\n if -a < 2*x < a:\r\n output = 1\r\nelif (y // a) % 2 == 0 and y > (y // a) * a and -a < x < 0:\r\n output = 3 * (y // a) // 2\r\nelif (y // a) % 2 == 0 and y > (y // a) * a and 0 < x < a:\r\n output = 3 * (y // a) // 2 + 1\r\nelif (y // a) % 2 == 1 and y > (y // a) * a and -a < 2*x < a:\r\n output = (3 * (y // a) + 1) // 2\r\n\r\nprint(output)\r\n" ]
{"inputs": ["1 0 0", "3 1 1", "3 0 10", "3 0 7", "3 4 0", "9 3 2", "100 0 953748", "17 0 1000000", "17 15 99999", "55 -20 1000000", "1 154871 37516", "1 -1 0", "1 -1 1", "1 0 2", "1 0 552012", "1 1 293372", "1 -1 551084", "5 -744240 145890", "5 -4 2", "5 -5 7", "5 -3 14", "5 0 660386", "5 5 918098", "5 -5 659458", "10 -227776 821899", "10 -5 1", "10 -3 11", "10 -2 23", "10 0 336395", "10 10 77755", "10 -10 335467", "100 350728 439252", "100 9 64", "100 -9 176", "100 -28 236", "100 100 211460", "100 -100 952820", "7 -3 0", "8 4 3", "17 0 99999", "17 -2 99999", "55 -55 1000000", "92 19 920000", "58 50 195112", "2 -3 0", "2 -3 1", "2 -3 2", "2 -3 3", "2 -3 4", "2 -3 5", "2 -3 6", "2 -3 7", "2 -2 0", "2 -2 1", "2 -2 2", "2 -2 3", "2 -2 4", "2 -2 5", "2 -2 6", "2 -2 7", "2 -1 0", "2 -1 1", "2 -1 2", "2 -1 3", "2 -1 4", "2 -1 5", "2 -1 6", "2 -1 7", "2 0 0", "2 0 1", "2 0 2", "2 0 3", "2 0 4", "2 0 5", "2 0 6", "2 0 7", "2 1 0", "2 1 1", "2 1 2", "2 1 3", "2 1 4", "2 1 5", "2 1 6", "2 1 7", "2 2 0", "2 2 1", "2 2 2", "2 2 3", "2 2 4", "2 2 5", "2 2 6", "2 2 7", "2 3 0", "2 3 1", "2 3 2", "2 3 3", "2 3 4", "2 3 5", "2 3 6", "2 3 7", "4 2 1", "10 1 60", "3 1 9", "3 -1 7", "100 50 1", "4 2 15", "2 1 1", "3 10 8", "2 -1 1", "10 11 21", "3 -2 7", "50 -1 10", "3 4 100", "49 28 27", "10 9 5", "10 5 35", "4 2 3", "4 -2 1", "2 -10 1", "10 7 1", "10 5 15", "3 10 2", "2 1 5", "3 10 100", "10 5 25", "50 1 200", "10 6 5", "2 100 3", "2 1 3", "3 6 7", "3 100 1", "2 2 5", "100 50 50", "2 0 1", "5 1 35", "100 25 200", "5 -1 6", "5 2 6", "6 3 1", "3 0 3", "2 100 1", "50 0 20", "10 5 95", "1 0 1", "15 8 1546", "10 5 31", "1 0 3", "100 80 50"], "outputs": ["-1", "1", "5", "-1", "-1", "1", "14306", "88235", "8824", "27272", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "3", "198116", "-1", "-1", "-1", "-1", "2", "3", "50459", "-1", "-1", "-1", "1", "2", "3", "-1", "-1", "-1", "-1", "-1", "8823", "-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", "-1", "-1", "-1", "1", "-1", "2", "-1", "-1", "-1", "5", "-1", "-1", "-1", "-1", "-1", "4", "-1", "-1", "-1", "-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", "3", "1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "4", "-1", "4", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "1", "-1", "-1", "2", "2", "-1", "-1", "-1", "1", "-1", "-1", "-1", "-1", "-1", "-1"]}
UNKNOWN
PYTHON3
CODEFORCES
2
1462cea6e0234917f31a0424b8da0329
none
Levko has an array that consists of integers: *a*1,<=*a*2,<=... ,<=*a**n*. But he doesn’t like this array at all. Levko thinks that the beauty of the array *a* directly depends on value *c*(*a*), which can be calculated by the formula: It’s time to change the world and Levko is going to change his array for the better. To be exact, Levko wants to change the values of at most *k* array elements (it is allowed to replace the values by any integers). Of course, the changes should make the array as beautiful as possible. Help Levko and calculate what minimum number *c*(*a*) he can reach. The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2000). The second line contains space-separated integers *a*1,<=*a*2,<=... ,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). A single number — the minimum value of *c*(*a*) Levko can get. Sample Input 5 2 4 7 4 7 4 3 1 -100 0 100 6 3 1 2 3 7 8 9 Sample Output 0 100 1
[ "def f(x):\r\n for i in range(1, n + 1):\r\n t[i] = 1\r\n for j in range(1, i):\r\n if x * (i - j) >= abs(a[i] - a[j]):\r\n t[i] = max(t[i], t[j] + 1)\r\n ans = 0\r\n for i in range(1, n + 1):\r\n ans = max(t[i], ans)\r\n return ans >= n - k\r\nn, k = map(int, input().split())\r\nt = [0] * 10001\r\na = [0] + list(map(int, input().split()))\r\nif n == 1:\r\n print(0)\r\nelse:\r\n l = 0\r\n r = 5000000000\r\n while True:\r\n m = (r + l) // 2\r\n if not f(m):\r\n l = m\r\n else:\r\n r = m\r\n if l + 1 >= r:\r\n break\r\n if f(l):\r\n print(l)\r\n else:\r\n print(r)# 1691749884.1592782" ]
{"inputs": ["5 2\n4 7 4 7 4", "3 1\n-100 0 100", "6 3\n1 2 3 7 8 9", "4 1\n-1000000000 -1000000000 1000000000 1000000000", "10 1\n-6 5 -7 -7 -7 -7 5 -9 4 7", "20 17\n-5 -9 11 -7 -17 -8 0 -14 -20 -15 7 -13 0 -3 -14 0 9 -10 6 -19", "5 1\n-1000000000 1000000000 -1000000000 1000000000 -1000000000", "16 13\n441427217 689669074 -194425155 750543104 6572770 -417122148 483768301 -687067832 703108904 -4865435 -626501708 -222868350 692734658 667640778 259672206 418102760", "1 1\n3243243", "1 1\n-1000000000", "2 1\n1234234 -3434", "2 2\n1 5", "4 1\n100 0 7 0"], "outputs": ["0", "100", "1", "1000000000", "12", "0", "2000000000", "2593562", "0", "0", "0", "0", "7"]}
UNKNOWN
PYTHON3
CODEFORCES
1
14670758b684ab5678725d0901e35d73
Password
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string *s*, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring *t* of the string *s*. Prefix supposed that the substring *t* is the beginning of the string *s*; Suffix supposed that the substring *t* should be the end of the string *s*; and Obelix supposed that *t* should be located somewhere inside the string *s*, that is, *t* is neither its beginning, nor its end. Asterix chose the substring *t* so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring *t* aloud, the temple doors opened. You know the string *s*. Find the substring *t* or determine that such substring does not exist and all that's been written above is just a nice legend. You are given the string *s* whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters. Print the string *t*. If a suitable *t* string does not exist, then print "Just a legend" without the quotes. Sample Input fixprefixsuffix abcdabc Sample Output fixJust a legend
[ "def kmp():\n now = -1\n sub[0] = now\n\n for i in range(1, len(p)):\n while now != -1 and p[i] != p[now + 1]:\n now = sub[now]\n\n if p[i] == p[now + 1]:\n now += 1\n sub[i] = now\n else:\n sub[i] = -1\n\np = input()\nsub = [-1] * 1000001\nkmp()\nmaxi = sub[len(p) - 1]\n\nfound = sub[maxi] if maxi != -1 else -1\n\nfor i in range(1, len(p) - 1):\n if sub[i] == maxi:\n found = maxi\n\nif found == -1:\n print(\"Just a legend\")\nelse:\n print(p[:found + 1])\n\n\t \t\t \t\t\t\t\t \t\t\t \t \t\t \t \t \t \t", "s = input()\r\nn = len(s)\r\nz = [0]*n\r\nmx = 0\r\n\r\nl,r = 0, 0\r\nfor i in range(1,n):\r\n if i <= r:\r\n z[i] = min(r - i + 1, z[i-l])\r\n \r\n while i + z[i] < n and s[z[i]] == s[i + z[i]]:\r\n z[i] += 1\r\n \r\n if i + z[i] - 1 > r:\r\n l = i\r\n r = i + z[i] - 1\r\n \r\n if i + z[i] == n and mx >= z[i]:\r\n print(s[:z[i]])\r\n exit()\r\n \r\n mx = max(mx,z[i])\r\n\r\nprint(\"Just a legend\")", "def z_function(s):\n \"\"\"Compute the Z-array for the given string.\"\"\"\n n = len(s)\n Z = [0] * n\n l, r = 0, 0\n for i in range(1, n):\n if i <= r:\n Z[i] = min(r - i + 1, Z[i - l])\n while i + Z[i] < n and s[Z[i]] == s[i + Z[i]]:\n Z[i] += 1\n if i + Z[i] - 1 > r:\n l, r = i, i + Z[i] - 1\n return Z\n\ndef find_substring(s):\n n = len(s)\n z = z_function(s)\n \n max_z_value = 0\n result = \"Just a legend\"\n \n # Loop through the string to find a suitable substring\n for i in range(1, n):\n # If this substring is also a suffix and is not the complete string itself\n if i + z[i] == n:\n # Check if a substring of this length appeared before in the string\n if max_z_value >= z[i]:\n result = s[i:i+z[i]]\n break\n max_z_value = max(max_z_value, z[i])\n \n return result\n\n\n\ntest_string = input()\nprint(find_substring(test_string))\n", "s=input()\ncount = -1\narr = [-1]\nfor x in s:\n while count != -1 and s[count] != x:\n count = arr[count]\n count = count +1\n arr.append(count)\nle = arr[-1]\nif arr.count(le) < 2:\n le = arr[le]\n\nif le > 0 :\n\tprint(s[:le])\nelse:\n \tprint(\"Just a legend\")\n\n\t \t\t \t \t\t\t\t \t \t\t \t\t \t \t \t", "\r\ns=str(input())\r\nn=len(s)\r\ndp=[0 for _ in range(n)]\r\nx=0\r\n\r\ni=1\r\nwhile i<n:\r\n if s[i]==s[x]:\r\n x+=1 \r\n dp[i]=x \r\n i+=1 \r\n else:\r\n if x==0:\r\n i+=1 \r\n else:\r\n x=dp[x-1]\r\n# print(dp) \r\nans=dp[-1]\r\nif dp.count(ans)<=1:\r\n if ans!=0:\r\n ans=dp[ans-1]\r\nif ans>0:\r\n print(s[:ans])\r\nelse:\r\n print(\"Just a legend\")\r\n# print(ans) \r\n\r\n", "s,k,l=input(),-1,[-1]\r\nfor c in s:\r\n while(k!=-1)and(s[k]!=c):\r\n k=l[k]\r\n k+=1\r\n l.append(k)\r\nle=l[-1]\r\nif l.count(le)<2:\r\n le=l[le]\r\nprint(s[:le] if le>0 else 'Just a legend')\r\n\r\n\r\n", "from sys import stdin, stdout\r\n\r\n\r\ndef z_function(s):\r\n z = [0] * len(s)\r\n l, r = 0, 0\r\n for i in range(1, len(s)):\r\n z[i] = max(0, min(z[i - l], r - i))\r\n while z[i] + i < len(s) and s[z[i]] == s[z[i] + i]:\r\n z[i] += 1\r\n if i + z[i] - 1 > r:\r\n l, r = i, i + z[i]\r\n return z\r\n\r\n\r\ndef prefix_function(s):\r\n v = [0] * len(s)\r\n for i in range(1, len(s)):\r\n k = v[i - 1]\r\n while k > 0 and s[k] != s[i]:\r\n k = v[k - 1]\r\n if s[k] == s[i]:\r\n k = k + 1\r\n v[i] = k\r\n return v\r\n\r\n\r\ndef build_hash(s):\r\n global hs, pw, q, p\r\n n = len(s)\r\n hs = [0] * (n + 1)\r\n pw = [1] * (n + 1)\r\n for i in range(n):\r\n hs[i + 1] = (hs[i] * q + ord(s[i])) % p\r\n pw[i + 1] = (pw[i] * q) % p\r\n\r\n\r\ndef get_hash(a, b):\r\n return (hs[b] - hs[a] * pw[b - a]) % p\r\n\r\n\r\ns = input()\r\np = prefix_function(s)\r\n# print(p)\r\nif p.count(p[-1]) > 1 and p[-1] > 0:\r\n print(s[:p[-1]])\r\nelse:\r\n q = p[p[-1] - 1]\r\n if q > 0:\r\n print(s[:q])\r\n else:\r\n print(\"Just a legend\")\r\n", "\r\nimport math\r\n\r\n\r\ndef makeLPS(string):\r\n N = len(string)\r\n arr = [0]*N\r\n i = 0\r\n j = 1\r\n\r\n while j < N:\r\n if string[j] == string[i]:\r\n i += 1\r\n arr[j] = i\r\n j += 1\r\n else:\r\n if i != 0:\r\n i = arr[i-1]\r\n else:\r\n j += 1\r\n return arr\r\n\r\n\r\ndef main():\r\n string = input()\r\n pi = makeLPS(string)\r\n pi = [x-1 for x in pi]\r\n l = len(string)\r\n maxi = pi[l-1]\r\n found = pi[maxi]\r\n\r\n if (maxi == -1):\r\n found = -1\r\n for i in range(1,l-1):\r\n if pi[i]==maxi:\r\n found = maxi\r\n if (found==-1):\r\n print(\"Just a legend\")\r\n else:\r\n print(string[0:found+1])\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "import sys\r\ninput = lambda : sys.stdin.readline().rstrip(\"\\r\\n\")\r\ns = input()\r\nn = len(s)\r\np = [0]*n\r\nm = [False]*n\r\n\r\nfor i in range(1,n):\r\n j = p[i-1]\r\n \r\n while j > 0 and s[i] != s[j]:\r\n j = p[j-1]\r\n \r\n if s[i] == s[j]:\r\n j += 1\r\n \r\n p[i] = j\r\n \r\n if i < n-1:\r\n m[p[i]] = True\r\n \r\nj = p[n-1]\r\n\r\nwhile j > 0 and m[j]==False:\r\n j = p[j-1]\r\n\r\nprint(s[:j] if j > 0 else \"Just a legend\")", "import sys\r\n \r\ns = sys.stdin.readline().strip()\r\nN = len(s)\r\n\r\ndef computeLPSArray(P, m, b):\r\n i = 0\r\n j = -1\r\n b[0] = -1;\r\n while (i < m):\r\n while (j >= 0 and P[i] != P[j]): \r\n j = b[j]\r\n i+=1 \r\n j+=1\r\n b[i] = j\r\n \r\n\r\n\r\nlps = [0 for _ in range(N+1)]\r\nvis = [0 for _ in range(N)]\r\ncomputeLPSArray(s,N,lps)\r\nfor i in range(1,N):\r\n vis[lps[i]] = 1\r\nj = N\r\nfoundOne = False\r\nwhile lps[j] > 0:\r\n if vis[lps[j]]:\r\n print(s[:lps[j]])\r\n foundOne=True\r\n break\r\n j = lps[j]\r\nif not foundOne:\r\n print(\"Just a legend\")\r\n", "def prefix_function(string):\r\n n = len(string)\r\n pi = [0] * n\r\n for i in range(1, n):\r\n j = pi[i - 1]\r\n while j > 0 and string[i] != string[j]:\r\n j = pi[j - 1]\r\n if string[i] == string[j]:\r\n j += 1\r\n pi[i] = j\r\n return pi\r\n\r\ndef main():\r\n\r\n string = str(input()).lower()\r\n\r\n pi = prefix_function(string)\r\n\r\n if pi[-1] == 0:\r\n print('Just a legend')\r\n else:\r\n\r\n pis = pi.copy()\r\n pis.pop()\r\n chosen = None\r\n\r\n for k in pis: \r\n if k == pi[-1]:\r\n chosen = pi[-1]\r\n break\r\n \r\n if chosen == None:\r\n if pi[pi[-1]-1] != 0: #caso 3 substrings repetidas\r\n chosen = pi[pi[-1]-1]\r\n else:\r\n print('Just a legend')\r\n return\r\n\r\n fix = string[-chosen:]\r\n if fix in string[1:-1]:\r\n print(fix)\r\n else:\r\n print('Just a legend')\r\n \r\n return\r\n\r\nmain()", "def kmpPreprocess(P):\n m = len(P)\n b = [0]*(m+1)\n i, j = 0, -1\n b[0] = -1\n while i < m:\n while j >= 0 and P[i] != P[j]:\n j = b[j]\n i += 1\n j += 1\n b[i] = j\n return b\n\ndef biggest_solution(s: str, pref: list):\n n = len(s)\n candidate = pref[n]\n while candidate > 0:\n for i in range(n):\n if pref[i] == candidate:\n return s[:candidate]\n candidate = pref[candidate]\n return None\n\nif __name__ == '__main__':\n s = input()\n pref = kmpPreprocess(s)\n res = biggest_solution(s, pref)\n if res is None:\n res = 'Just a legend'\n print(res)\n\n", "MOD=1000000007\r\ndef get_hash(l,r): return (H[r]-(H[l-1]*P[r-l+1])%MOD)%MOD\r\ndef ok(x,n):\r\n res=get_hash(1,x)\r\n for i in range(2,n-x+1):\r\n if get_hash(i,i+x-1)==res: return True\r\n return False\r\ns=input(); n=len(s); ind=[]; P=[1]+[0]*n; H=[0]*(n+1); ans=0\r\nfor i in range(1,n+1): \r\n P[i]=(P[i-1]*29)%MOD; H[i]=(29*H[i-1]+ord(s[i-1]))%MOD\r\nfor i in range(1, n):\r\n if get_hash(1,i)==get_hash(n-i+1,n): ind+=[i]\r\nfor m in range(len(ind)):\r\n if ok(ind[m],n): ans=ind[m]\r\nif ans==0: print(\"Just a legend\")\r\nelse: print(s[:ans])", "s, k, d = input(), -1, [-1]\r\nfor ch in s:\r\n while (k != -1) and (s[k] != ch):\r\n k = d[k]\r\n k += 1\r\n d.append(k)\r\nc = d[-1]\r\nif d.count(c) < 2:\r\n c = d[c]\r\nprint(('Just a legend', s[:c])[c > 0])", "s = input()\r\ncom = -1\r\ncn = [-1]\r\nfor c in s:\r\n while com != -1 and c != s[com]:\r\n com = cn[com]\r\n com += 1\r\n cn.append(com)\r\nlenth = cn[-1]\r\nif cn.count(lenth) < 2:\r\n lenth = cn[lenth]\r\nprint(s[:lenth] if lenth > 0 else \"Just a legend\")\r\n", "def prefixfunction(txt,m,lps):\r\n\tl = 0\r\n\tlps[0] = 0\r\n\ti = 1\r\n\twhile i<m:\r\n\t\tif txt[i]==txt[l]:\r\n\t\t\tl+=1\r\n\t\t\tlps[i] = l\r\n\t\t\ti += 1\r\n\t\telse:\r\n\t\t\tif l!=0:\r\n\t\t\t\tl = lps[l-1]\r\n\t\t\telse:\r\n\t\t\t\tlps[i] = 0\r\n\t\t\t\ti += 1\r\n\r\ns = input().strip()\r\nlongitud = len(s)\r\nif longitud==1 or longitud==2:\r\n\tprint(\"Just a legend\")\r\n\texit(0)\r\nlps = [0]*longitud\r\nprefixfunction(s,longitud,lps)\r\nval = lps[-1]\r\nif val==0:\r\n\tprint(\"Just a legend\")\r\nelif val in lps[:-1]:\r\n\tprint(s[:val])\r\nelif lps[val-1]==0:\r\n\tprint(\"Just a legend\")\r\nelif lps[val-1]:\r\n\tprint(s[:lps[val-1]])\r\nelse:\r\n\tprint(\"Just a legend\")\r\n", "# n, p, q = [int(x) for x in input().split(\" \")]\r\n# string = input()\r\n# s = list()\r\n# for i in range(n + 1):\r\n# for j in range(n + 1):\r\n# if n == (i * p + j * q):\r\n# print(i + j)\r\n# index = 0\r\n# for k in range(i):\r\n# s.append(string[index:index + p])\r\n# index += p\r\n# for k in range(j):\r\n# s.append(string[index:index + q])\r\n# index += q\r\n# for k in s:\r\n# print(k)\r\n# exit()\r\n#\r\n# print(-1)\r\n# from collections import Counter\r\n# import operator\r\n#\r\n# n = int(input())\r\n# string = input()\r\n# lst = ['A', 'G', 'C', 'T']\r\n# count = Counter(string)\r\n# questions = None\r\n# if count.get('?'):\r\n# questions = count.pop(\"?\")\r\n# try:\r\n# temp_mx = max(count.items(), key=operator.itemgetter(1))[1]\r\n# except:\r\n# pass\r\n# if not questions:\r\n# for i in lst:\r\n# if i not in count:\r\n# print('===')\r\n# exit()\r\n# for k, v in count.items():\r\n# if v < temp_mx:\r\n# print('===')\r\n# exit()\r\n# print(string)\r\n# exit()\r\n# if n % 4 != 0:\r\n# print('===')\r\n# exit()\r\n# mx = n // 4\r\n# if questions == n:\r\n#\r\n# temp = n // 4\r\n# for i in lst:\r\n# string = string.replace(\"?\", i, temp)\r\n# print(string)\r\n# exit()\r\n# if n < 4 * temp_mx:\r\n# print('===')\r\n# exit()\r\n# for i in lst:\r\n# if i not in count:\r\n# count[i] = 0\r\n# for k, v in count.items():\r\n# if v < mx:\r\n# temp = mx - v\r\n# string = string.replace(\"?\", k, temp)\r\n# v += temp\r\n# print(string)\r\n\r\n\r\ndef get_prefix(string):\r\n lst = [0]*len(string)\r\n index = 0\r\n for i in range(1, len(string)):\r\n while index > 0 and string[index] != string[i]:\r\n index = lst[index - 1]\r\n if string[index] == string[i]:\r\n index += 1\r\n lst[i] = index\r\n else:\r\n lst[i] = index\r\n return lst\r\n\r\n\r\nin_c = input()\r\nlst = get_prefix(in_c)\r\nlength = lst[len(in_c) - 1]\r\nfound = None\r\nif length != 0:\r\n for j in range(2):\r\n for i in range(1, len(in_c) - 1):\r\n if length == lst[i]:\r\n found = True\r\n break\r\n if not found:\r\n length = lst[length-1]\r\n if length == 0:\r\n break\r\n else:\r\n break\r\nif not found or length == 0:\r\n print(\"Just a legend\")\r\nelse:\r\n print(in_c[0:length])\r\n", "s=input()\r\nl=len(s)\r\np=[-1]+[0]*l\r\nj=0\r\nfor i in range(1,l):\r\n while j+1 and s[i]!=s[j]:j=p[j]\r\n j+=1;p[i+1]=j\r\nif p[-1]==0:print(\"Just a legend\")\r\nelif p.count(p[-1])>=2:print(s[:p[-1]])\r\nelif s[:p[p[-1]]]:print(s[:p[p[-1]]])\r\nelse:print(\"Just a legend\")", "p = input()\r\npi = [-1] * 1000005\r\n\r\ndef KMP():\r\n now = -1\r\n for i in range(1, len(p)):\r\n while now != -1 and p[i] != p[now + 1]:\r\n now = pi[now]\r\n if p[i] == p[now + 1]:\r\n now += 1\r\n pi[i] = now\r\n else:\r\n pi[i] = -1\r\n\r\nKMP()\r\nlength = len(p)\r\nmaxi = pi[length - 1]\r\nfound = pi[maxi]\r\nif maxi == -1:\r\n found = -1\r\nfor i in range(1, length - 1):\r\n if pi[i] == maxi:\r\n found = maxi\r\nif found == -1:\r\n print(\"Just a legend\")\r\nelse:\r\n print(p[:found + 1])\r\n\r\n", "\r\n\r\ndef KMPPre(P, prefix):\r\n prefix[0] = 0\r\n m = len(P)\r\n i = 1\r\n j = 0\r\n \r\n while i < m:\r\n if P[i] == P[j]:\r\n j += 1\r\n prefix[i] = j\r\n i += 1\r\n else:\r\n if j != 0:\r\n j = prefix[j - 1]\r\n else:\r\n prefix[i] = 0\r\n i += 1\r\n\r\n\r\ndef main():\r\n line = input()\r\n N = len(line)\r\n prefix = [0] * N\r\n KMPPre(line, prefix)\r\n #print(prefix)\r\n cnt = [0] * (N + 1)\r\n M = len(prefix)\r\n for i in range(0, M-1):\r\n cnt[prefix[i]] += 1\r\n tmp = prefix[M - 1]\r\n ans = \"Just a legend\"\r\n while tmp > 0:\r\n ##print(tmp)\r\n if cnt[tmp] > 0:\r\n ans = (line[0:tmp])\r\n break\r\n tmp = prefix[tmp-1]\r\n print(ans)\r\n \r\nif __name__ == \"__main__\":\r\n main()", "s = input().strip()\r\nle = len(s)\r\nif le==1 or le==2:\r\n\tprint(\"Just a legend\")\r\n\texit(0)\r\ndef prefixfunction(txt,m,lps):\r\n\tl = 0\r\n\tlps[0] = 0\r\n\ti = 1\r\n\twhile i<m:\r\n\t\tif txt[i]==txt[l]:\r\n\t\t\tl+=1\r\n\t\t\tlps[i] = l\r\n\t\t\ti += 1\r\n\t\telse:\r\n\t\t\tif l!=0:\r\n\t\t\t\tl = lps[l-1]\r\n\t\t\telse:\r\n\t\t\t\tlps[i] = 0\r\n\t\t\t\ti += 1\r\nlps = [0]*le\r\nprefixfunction(s,le,lps)\r\nval = lps[-1]\r\nif val==0:\r\n\tprint(\"Just a legend\")\r\nelif val in lps[:-1]:\r\n\tprint(s[:val])\r\nelif lps[val-1]==0:\r\n\tprint(\"Just a legend\")\r\nelif lps[val-1]:\r\n\tprint(s[:lps[val-1]])\r\nelse:\r\n\tprint(\"Just a legend\")", "s=input()\nl=len(s)\np=[-1]+[0]*l\nj=0\nfor i in range(1,l):\n while j+1 and s[i]!=s[j]:j=p[j]\n j+=1;p[i+1]=j\nif p[-1]==0:print(\"Just a legend\")\nelif p.count(p[-1])>=2:print(s[:p[-1]])\nelif s[:p[p[-1]]]:print(s[:p[p[-1]]])\nelse:print(\"Just a legend\")\n \t \t\t\t\t \t\t \t \t\t \t\t \t\t", "def prefix_function(s):\r\n pi = [0] * len(s)\r\n for i in range(1, len(s)):\r\n j = pi[i - 1]\r\n while(j > 0 and s[i] != s[j]):\r\n j = pi[j-1]\r\n if(s[i] == s[j]):\r\n j+=1\r\n pi[i] = j\r\n return pi\r\n\r\ns = input()\r\npi = prefix_function(s)\r\nn = len(s)\r\nok = True\r\nif(pi[n-1]!=0 and pi.count(pi[n-1])>1):\r\n print(s[n-pi[n-1]: n])\r\nelif(pi[pi[n-1]-1]>0):\r\n print(s[pi[n-1] - pi[pi[n-1]-1] : pi[n-1]])\r\nelse:\r\n print(\"Just a legend\")\r\n\r\n", "s = input()\r\nn = len(s)\r\np = [0]*(n+1)\r\nmark = [False]*(n+1)\r\n\r\nfor i in range(1,n):\r\n \r\n j = p[i-1]\r\n \r\n while(j>0 and s[i]!=s[j]):\r\n j = p[j-1]\r\n \r\n if(s[i]==s[j]):\r\n j+=1\r\n \r\n p[i] = j\r\n \r\n if(i<n-1):\r\n mark[j] = True\r\n\r\nj = p[n-1]\r\n\r\nwhile(j>0 and mark[j]!=True):\r\n j = p[j-1]\r\n\r\nprint(s[0:j] if j>0 else \"Just a legend\")", "def get_hash(c):\r\n return 1+ord(c)-ord(\"a\")\r\n\r\ndef solve(s):\r\n n = len(s)\r\n a, curr_a = 31, 1\r\n mod = 10**9 + 7\r\n password_idx = -1\r\n p_hash = s_hash = o_hash = 0\r\n k = n-2\r\n for i in range(n-1):\r\n j = -i-1\r\n p_hash = (p_hash + get_hash(s[i])*curr_a) % mod\r\n s_hash *= a\r\n s_hash = (s_hash + get_hash(s[j])) % mod\r\n o_hash *= a\r\n o_hash = (o_hash + get_hash(s[k])) % mod\r\n while s_hash != o_hash and k > 0:\r\n o_hash -= get_hash(s[k+i])*curr_a\r\n k -= 1\r\n o_hash *= a\r\n o_hash = (o_hash + get_hash(s[k])) % mod\r\n if k == 0: break\r\n if p_hash == s_hash:\r\n password_idx = i\r\n k -= 1\r\n curr_a *= a\r\n curr_a %= mod\r\n\r\n if password_idx != -1:\r\n return s[:password_idx+1]\r\n return \"Just a legend\"\r\n\r\nif __name__ == '__main__':\r\n s = input()\r\n print(solve(s))", "def main():\r\n st = input().strip()\r\n l = [-1] * len(st)\r\n j, i = 0, 1\r\n while i < len(st):\r\n if st[i] == st[j]:\r\n l[i] = j\r\n i, j = i + 1, j + 1\r\n elif j > 0:j = l[j - 1] + 1\r\n else:i += 1\r\n if l[-1] == -1:return print(\"Just a legend\")\r\n for i in range(len(st) - 1):\r\n if l[i] == l[-1]:return print(st[:(l[-1] + 1)])\r\n if l[l[-1]] == -1:print(\"Just a legend\")\r\n else:print(st[:(l[l[-1]] + 1)])\r\nmain()", "palavra = input()\ntam = len(palavra)\n\n# A gente cria uma matriz vazia do tamanho\n# pq cada vez que acharmos uma sequencia igual\n# Aumentamos numero da similaridade\nseq_iguais = [0 for _ in range(tam + 1)]\nsimilar, index = (0, 1)\n\nwhile index < tam:\n # Enquanto letras forem iguais, aumenta similaridade e o index\n if palavra[index] == palavra[similar]:\n index += 1\n similar += 1\n seq_iguais[index] = similar\n\n # Uma vez que deixa de ser igual, voltamos pra maior que ainda era\n elif similar:\n similar = seq_iguais[similar]\n \n # Nada acontece, verifica proxima\n else:\n index += 1\n\na = seq_iguais[-1]\n\nresult = \"Just a legend\"\nif a and a in seq_iguais[:-1]:\n result = palavra[:a]\n\nelse:\n b = seq_iguais[a]\n\n if b:\n result = palavra[:b]\n\nprint(result)\n\n \t\t\t\t\t\t \t\t \t\t \t \t \t \t", "def prefixfunction(txt,m,lps):\n\tl = 0\n\tlps[0] = 0\n\ti = 1\n\twhile i<m:\n\t\tif txt[i]==txt[l]:\n\t\t\tl+=1\n\t\t\tlps[i] = l\n\t\t\ti += 1\n\t\telse:\n\t\t\tif l!=0:\n\t\t\t\tl = lps[l-1]\n\t\t\telse:\n\t\t\t\tlps[i] = 0\n\t\t\t\ti += 1\n\n \nif __name__ == '__main__':\n\n s = input().strip()\n longitud = len(s)\n if longitud==1 or longitud==2:\n \tprint(\"Just a legend\")\n \texit(0)\n lps = [0]*longitud\n prefixfunction(s,longitud,lps)\n val = lps[-1]\n if val==0:\n \tprint(\"Just a legend\")\n elif val in lps[:-1]:\n \tprint(s[:val])\n elif lps[val-1]==0:\n \tprint(\"Just a legend\")\n elif lps[val-1]:\n \tprint(s[:lps[val-1]])\n else:\n \tprint(\"Just a legend\")\n", "s, j, next = input(), -1, [-1]\r\nfor c in s:\r\n while j != -1 and c != s[j]:\r\n j = next[j]\r\n j += 1\r\n next.append(j)\r\na = next[-1]\r\nif next.count(a) < 2:\r\n a = next[a]\r\nprint(s[:a] if a > 0 else \"Just a legend\")\r\n", "import sys\r\nimport bisect\r\ninput_=lambda: sys.stdin.readline().strip(\"\\r\\n\")\r\nfrom math import log\r\nfrom math import gcd\r\nfrom random import randint\r\nsa=lambda :input_()\r\nsb=lambda:int(input_())\r\nsc=lambda:input_().split()\r\nsd=lambda:list(map(int,input_().split()))\r\nse=lambda:float(input_())\r\nsf=lambda:list(input_())\r\nflsh=lambda: sys.stdout.flush()\r\n#sys.setrecursionlimit(10**6)\r\nmod=10**9+7\r\ngp=[]\r\ncost=[]\r\ndp=[]\r\nmx=[]\r\ndef dfs(root,par):\r\n global gp,cost,dp\r\n dp[root]=cost[root]\r\n for i in gp[root]:\r\n if i==par:continue\r\n dfs(i,root)\r\n dp[root]=max(dp[root],dp[i])\r\ndef z_algo(ar):\r\n n=len(ar)\r\n ans=[0]*n\r\n l,r=0,0\r\n ans[0]=n\r\n for i in range(1,n):\r\n if(i<=r):\r\n ans[i]=min(r-i+1,ans[i-l])\r\n while(i+ans[i]<n and ar[ans[i]]==ar[i+ans[i]]):\r\n ans[i]+=1\r\n if i+ans[i]-1>r:\r\n l=i\r\n r=i+ans[i]-1\r\n return ans\r\ndef hnbhai():\r\n s=sa()\r\n n=len(s)\r\n z=z_algo(s)\r\n #print(z)\r\n count=[0]*(n+1)\r\n mark=[0]*(n+1)\r\n tot=0\r\n for i in range(n-1,-1,-1):\r\n if z[i]+i==n:\r\n mark[z[i]]=1\r\n tot+=1\r\n for i in range(n):\r\n count[z[i]]+=1\r\n for i in range(n-1,-1,-1):\r\n count[i]+=count[i+1]\r\n for i in range(n-1,-1,-1):\r\n if mark[i] and count[i]>2:\r\n print(s[:i])\r\n return\r\n print(\"Just a legend\")\r\nfor _ in range(1):\r\n hnbhai()\r\n", "import sys\r\nimport random\r\n\r\ninput = sys.stdin.readline\r\nrd = random.randint(10 ** 9, 2 * 10 ** 9)\r\n\r\n\r\ndef z_function(s):\r\n n = len(s)\r\n z = [0] * n\r\n l, r = 0, 0\r\n for i in range(1, n):\r\n if i <= r and z[i - l] < r - i + 1:\r\n z[i] = z[i - l]\r\n else:\r\n z[i] = max(0, r - i + 1)\r\n while i + z[i] < n and s[z[i]] == s[i + z[i]]:\r\n z[i] += 1\r\n if i + z[i] - 1 > r:\r\n l = i\r\n r = i + z[i] - 1\r\n return z\r\n\r\n\r\ns = input().strip()\r\nn = len(s)\r\nz = z_function(s)\r\nmx = 0\r\nans = 0\r\nfor i in range(n):\r\n # 后缀\r\n if i + z[i] == n:\r\n if mx >= z[i]:\r\n ans = max(ans, z[i])\r\n mx = max(mx, z[i])\r\nprint(s[:ans] if ans else \"Just a legend\")", "'''\r\n Auther: ghoshashis545 Ashis Ghosh\r\n College: jalpaiguri Govt Enggineering College\r\n\r\n'''\r\nfrom os import path\r\nfrom io import BytesIO, IOBase\r\nimport sys\r\nfrom heapq import heappush,heappop\r\nfrom functools import cmp_to_key as ctk\r\nfrom collections import deque,Counter,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().rstrip()\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('0')\r\n\r\nfile = 1\r\ndef ceil(a,b):\r\n return (a+b-1)//b\r\n\r\n# write fastio for getting fastio template.\r\n \r\n\r\ndef z_algo(s):\r\n n = len(s)\r\n z = [0]*n\r\n l = r = 0\r\n for i in range(n):\r\n if i > r:\r\n l = r = i\r\n while r < n and s[r-l] == s[r]:\r\n r+=1\r\n z[i] = r-l\r\n r-=1\r\n else:\r\n j = i-l\r\n if z[j] + i > r:\r\n l = i\r\n while r < n and s[r-l] == s[r]:\r\n r+=1\r\n z[i] = r-l\r\n r-=1\r\n else:\r\n z[i] = z[j]\r\n\r\n return z\r\n\r\n\r\n\r\ndef solve():\r\n\r\n s = si()\r\n x = z_algo(s)\r\n n = len(x)\r\n f = dd(int)\r\n st = set()\r\n for i in x:\r\n if i > 0:\r\n f[i]+=1\r\n st.add(i)\r\n st = list(st)\r\n st.sort(reverse=True)\r\n cnt = 0\r\n for i in st:\r\n cnt += f[i]\r\n if cnt >= 2 and x[-i] == i:\r\n print(s[-i:])\r\n return\r\n print(\"Just a legend\")\r\n\r\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('input.txt'):\r\n sys.stdin=open('input.txt', 'r')\r\n sys.stdout=open('output.txt','w')\r\n else:\r\n input=sys.stdin.readline\r\n solve()\r\n", "def kmp(s):\r\n pi = [0] * len(s)\r\n j = 0\r\n for i in range(1, len(s)):\r\n while j > 0 and s[j] != s[i]:\r\n j = pi[j-1]\r\n if s[j] == s[i]:\r\n j += 1\r\n pi[i] = j\r\n k = pi[-1]\r\n if k > 0 and any(pi[i] == k for i in range(len(s)-1)):\r\n return s[:k]\r\n elif k > 0:\r\n return s[:pi[k-1]]\r\n else:\r\n return \"Just a legend\"\r\n\r\ns = input()\r\nelem=kmp(s)\r\nif elem!='':\r\n print(elem)\r\nelse:\r\n print('Just a legend')\r\n", "from sys import stdin\n\n\ndef findpass(s):\n arr = suff_array(s)\n n = len(s)\n maxidx = arr[n - 1]\n valid = False\n\n for i in range(n - 1):\n if arr[i] == maxidx:\n valid = True\n break\n\n if not valid:\n maxidx = arr[maxidx - 1]\n\n if maxidx == 0:\n return \"Just a legend\"\n return s[:maxidx]\n\n\ndef suff_array(s):\n n = len(s)\n table = [0] * n\n\n pos, i = 0, 1\n\n while i < n:\n if s[pos] == s[i]:\n table[i] = pos + 1\n pos += 1\n i += 1\n elif pos == 0:\n i += 1\n else:\n pos = table[pos - 1]\n\n\n# print(table)\n return table\n\nif __name__ == \"__main__\":\n s = stdin.readline().strip()\n print(findpass(s))\n", "\ndef compute_lps(s):\n\n n = len(s)\n\n # To store longest prefix suffix\n lps = [0] * n\n\n # Length of the previous\n # longest prefix suffix\n Len = 0\n\n # lps[0] is always 0\n lps[0] = 0\n i = 1\n\n # Loop calculates lps[i] for i = 1 to n - 1\n while (i < n):\n if (s[i] == s[Len]):\n Len += 1\n lps[i] = Len\n i += 1\n\n # (pat[i] != pat[Len])\n else:\n if (Len != 0):\n Len = lps[Len - 1]\n # Also, note that we do not increment\n # i here\n\n # If Len = 0\n else:\n lps[i] = 0\n i += 1\n\n return lps\n\n# Function to find the longest substring\n# which is prefix as well as a\n# sub-of s[1...n-2]\n\n\ndef Longestsubstring(s):\n\n # Find longest prefix suffix\n lps = compute_lps(s)\n n = len(s)\n\n # If lps of n-1 is zero\n if (lps[n - 1] == 0):\n print(\"Just a legend\")\n exit()\n\n for i in range(0, n - 1):\n\n # At any position lps[i] equals to lps[n - 1]\n if (lps[i] == lps[n - 1]):\n print(s[0:lps[i]])\n exit()\n\n # If answer is not possible\n if (lps[lps[n - 1] - 1] == 0):\n print(\"Just a legend\")\n else:\n print(s[0:lps[lps[n - 1] - 1]])\n\n\ns = input()\n\nLongestsubstring(s)\n\n \t \t\t\t \t \t\t \t\t\t\t \t\t \t", "def find_longest_substring(s):\r\n n = len(s)\r\n pi = [0] * n # Initialize the prefix function array with zeros\r\n\r\n j = 0 # Prefix length\r\n for i in range(1, n):\r\n while j > 0 and s[i] != s[j]:\r\n j = pi[j - 1]\r\n\r\n if s[i] == s[j]:\r\n j += 1\r\n\r\n pi[i] = j\r\n\r\n max_length = pi[-1] # Length of the longest prefix-suffix\r\n\r\n if max_length == 0:\r\n print(\"Just a legend\")\r\n else:\r\n for i in range(1, n - 1):\r\n if pi[i] == max_length:\r\n print(s[:max_length])\r\n return\r\n\r\n if pi[max_length - 1] > 0:\r\n print(s[:pi[max_length - 1]])\r\n else:\r\n print(\"Just a legend\")\r\n\r\n# Read the input string\r\ns = input()\r\nfind_longest_substring(s)\r\n", "def kmpProcess(p):\n m = len(p)\n b = [-1]*(m+1)\n i,j = 0,-1\n while i < m:\n while j >= 0 and p[i] != p[j]:\n j = b[j]\n i += 1\n j += 1\n b[i] = j\n return b\n\ndef maior_solucao(s):\n pref = kmpProcess(s)\n n = len(s)\n candidato = pref[n]\n while candidato > 0:\n for i in range(1,n):\n if pref[i] == candidato:\n return s[:candidato]\n candidato = pref[candidato]\n return ''\n\n\n\nif __name__ == '__main__':\n stg = input()\n aws = maior_solucao( stg )\n if aws:\n print(aws)\n else:\n print('Just a legend')\n\n \t \t \t \t \t\t \t\t \t\t \t", "def kmpPreprocess(p):\n m = len(p)\n b = [-1] * (m + 1)\n i, j = 0, -1\n while (i < m):\n while (j >= 0 and p[i] != p[j]):\n j = b[j]\n i += 1\n j += 1\n b[i] = j\n return b\n\ndef maior_solucao(s):\n pref = kmpPreprocess(s)\n n = len(s)\n candidato = pref[n]\n while candidato > 0:\n for i in range(1, n):\n if pref[i] == candidato:\n return s[:candidato]\n candidato = pref[candidato]\n return \"\"\n\nres = maior_solucao(input())\nif res == \"\":\n res = \"Just a legend\"\nprint(res)\n\t\t\t\t\t \t \t \t \t\t\t\t\t\t \t\t", "class PolyHash:\r\n def __init__(self, N, base=26, mod=10 ** 9 + 7):\r\n self.base = base\r\n self.mod = mod\r\n self.powr = [1 for _ in range(N)]\r\n self.pinv = [1 for _ in range(N)]\r\n for i in range(1, N):\r\n self.powr[i] = self.powr[i - 1] * base % mod\r\n self.pinv[-1] = pow(self.powr[-1], mod - 2, mod)\r\n for i in range(N - 2, -1, -1):\r\n self.pinv[i] = self.pinv[i + 1] * base % mod\r\n\r\n def transform(self, v):\r\n N = len(v)\r\n h = [0 for _ in range(N)]\r\n h[0] = v[0] % self.mod\r\n for i in range(1, N):\r\n h[i] = (h[i - 1] + v[i] * self.powr[i] % self.mod) % self.mod\r\n return h\r\n\r\n def substr(self, h, l, r):\r\n if l == 0:\r\n return h[r - 1]\r\n else:\r\n return (h[r - 1] - h[l - 1]) % self.mod * self.pinv[l] % self.mod\r\n\r\n\r\ndef solve():\r\n S = input()\r\n N = len(S)\r\n tool = PolyHash(N, 26, 10 ** 9 + 7)\r\n h = tool.transform([ord(c) - ord('a') for c in S])\r\n\r\n cands = []\r\n for length in range(1, N):\r\n prefix = tool.substr(h, 0, length)\r\n suffix = tool.substr(h, N - length, N)\r\n if prefix == suffix:\r\n cands.append((length, prefix))\r\n\r\n if len(cands) == 0:\r\n return \"Just a legend\"\r\n\r\n def check(m):\r\n length, val = cands[m]\r\n for i in range(1, N - length):\r\n if tool.substr(h, i, i + length) == val:\r\n return True\r\n return False\r\n \r\n lb, ub = 0, len(cands) - 1\r\n if check(lb) == False:\r\n return \"Just a legend\"\r\n if check(ub) == True:\r\n length, _ = cands[ub]\r\n return S[:length]\r\n\r\n while ub - lb > 1:\r\n m = (lb + ub) // 2\r\n if check(m) == True:\r\n lb = m\r\n else:\r\n ub = m\r\n \r\n length, _ = cands[lb]\r\n return S[:length]\r\n\r\nprint(solve())", "from bisect import bisect_left as bl, bisect_right as br, insort\r\nimport sys\r\nimport heapq\r\n#from math import *\r\nfrom collections import defaultdict as dd, deque\r\ndef data(): return sys.stdin.readline().strip()\r\ndef mdata(): return map(int, data().split())\r\n#def print(x): return sys.stdout.write(str(x)+'\\n')\r\n#sys.setrecursionlimit(100000)\r\nmod=int(1e9+7)\r\n\r\ndef KMPSearch(pat, txt):\r\n\tM = len(pat)\r\n\tN = len(txt)\r\n\tlps = [0]*M\r\n\tj = 0\r\n\tcomputeLPSArray(pat, M, lps)\r\n\r\n\ti = 0\r\n\twhile i < N:\r\n\t\tif pat[j] == txt[i]:\r\n\t\t\ti += 1\r\n\t\t\tj += 1\r\n\r\n\t\tif j == M:\r\n\t\t\treturn pat[:M],lps\r\n\r\n\t\telif pat[j] != txt[i]:\r\n\t\t\tif j != 0:\r\n\t\t\t\tj = lps[j-1]\r\n\t\t\t\tM-=1\r\n\t\t\t\tlps.pop()\r\n\t\t\telse:\r\n\t\t\t\ti += 1\r\n\r\ndef computeLPSArray(pat, M, lps):\r\n l = 0\r\n lps[0]=0\r\n i = 1\r\n\r\n while i < M:\r\n if pat[i]== pat[l]:\r\n l += 1\r\n lps[i] = l\r\n i += 1\r\n else:\r\n if l != 0:\r\n l = lps[l-1]\r\n\r\n else:\r\n lps[i] = 0\r\n i += 1\r\n return lps\r\n\r\ns=data()\r\nn=len(s)\r\nlps1=[0]*n\r\nlps1=computeLPSArray(s,n,lps1)\r\nlps2=[0]*n\r\nlps2=computeLPSArray(s[::-1],n,lps2)\r\nm=0\r\nfor i in range(n):\r\n if lps1[i]==lps2[n-2-i+lps1[i]]:\r\n m=max(m,lps1[i])\r\nif m==0:\r\n print(\"Just a legend\")\r\nelse:\r\n print(s[:m])\r\n\r\n\r\n", "def partial(s):\r\n g, pi = 0, [0] * len(s)\r\n for i in range(1, len(s)):\r\n while g and (s[g] != s[i]):\r\n g = pi[g - 1]\r\n pi[i] = g = g + (s[g] == s[i])\r\n\r\n return pi\r\n\r\n\r\ndef main():\r\n seq = input()\r\n n = len(seq)\r\n\r\n pi = partial(seq)\r\n\r\n cur = pi[n-1]\r\n\r\n if cur == 0:\r\n print('Just a legend')\r\n return\r\n\r\n if pi.count(cur) > 1:\r\n print(seq[:cur])\r\n return\r\n\r\n cur = pi[cur-1]\r\n if cur == 0:\r\n print('Just a legend')\r\n return\r\n\r\n print(seq[:cur])\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", "def get_lps(string):\n n = len(string) \n long_pref_suff = [0 for i in range(n)]\n size = 0\n long_pref_suff[0] = 0\n i = 1\n while (i < n):\n if (string[i] == string[size]):\n size += 1\n long_pref_suff[i] = size\n i += 1\n else:\n if (size != 0):\n size = long_pref_suff[size - 1]\n else:\n long_pref_suff[i] = 0\n i += 1\n return long_pref_suff\ndef get_longest_substr(string):\n long_pref_suff = get_lps(string)\n n = len(string)\n if (long_pref_suff[n - 1] == 0):\n return -1\n for i in range(0,n - 1):\n if (long_pref_suff[i] == long_pref_suff[n - 1]): \n return string[0:long_pref_suff[i]]\n if (long_pref_suff[long_pref_suff[n - 1] - 1] == 0):\n return -1\n else:\n return string[0:long_pref_suff[long_pref_suff[n - 1] - 1]]\n\ndef main(string):\n res = get_longest_substr(string)\n if res == -1:\n print('Just a legend')\n else:\n print(res)\n\nmain(input())\n \t\t\t\t \t \t \t\t \t \t\t \t\t", "def solve(s):\n n = len(s)\n lps = [0] * n\n count = [0] * (n + 1)\n for i in range(1, n):\n l = lps[i - 1]\n while l > 0 and s[i] != s[l]:\n l = lps[l - 1]\n if s[i] == s[l]:\n l += 1\n lps[i] = l\n if i < n - 1:\n count[l] += 1\n l = lps[n - 1]\n while l > 0:\n if count[l] > 0:\n return s[:l]\n l = lps[l - 1]\n\n\ns = input()\nres = solve(s)\nif res:\n print(res)\nelse:\n print(\"Just a legend\")", "def TheZFunction(s):\r\n\tz = [0] * len(s)\r\n\tz[0] = -1\r\n\tl = r = -1\r\n\tfor k in range(1,len(s)):\r\n\t\tif s[k] != s[0]:\r\n\t\t\tz[k] = 0\r\n\t\telse:\r\n\t\t\tif l<=k<=r:\r\n\t\t\t\tif k + z[k-l] < r:\r\n\t\t\t\t\tz[k] = z[k-l]\r\n\t\t\t\t\tcontinue\r\n\t\t\t\tif k + z[k-l] >= r:\r\n\t\t\t\t\tz[k] = r-k#Skip the known range\r\n\t\t\t\t\ti = z[k] #Counter for the prefix\r\n\t\t\t\t\tj = r\r\n\t\t\t\t\twhile j < len(s) and s[i] == s[j]:\r\n\t\t\t\t\t\ti += 1\r\n\t\t\t\t\t\tj += 1\r\n\t\t\t\t\t\tz[k] += 1\r\n\t\t\t\t\tl = k\r\n\t\t\t\t\tr = j - 1\r\n\t\t\telse:\r\n\t\t\t\ti = 0 #Counter for the prefix\r\n\t\t\t\tj = k\r\n\t\t\t\twhile j < len(s) and s[i] == s[j]:\r\n\t\t\t\t\ti += 1\r\n\t\t\t\t\tj += 1\r\n\t\t\t\t\tz[k] += 1\r\n\t\t\t\tl = k\r\n\t\t\t\tr = j - 1\r\n\treturn z\r\ns = input()\r\nz = TheZFunction(s)\r\nmaxZ = 0\r\nres = 0\r\nn = len(s)\r\nfor i in range(1,n):\r\n\tif z[i] == n - i and maxZ >= n - i:\r\n\t\tres = n - i\r\n\t\tbreak\r\n\telse:\r\n\t\tmaxZ = max(z[i],maxZ)\r\nif res:\r\n\tprint(s[:res])\r\nelse:\r\n\tprint(\"Just a legend\")", "s = input()\nn = len(s)\nlps = [0] * n\ni = 1\nlen = 0\nwhile i < n:\n if s[i] == s[len]:\n len += 1\n lps[i] = len\n i += 1\n else:\n if len != 0:\n len = lps[len-1]\n else:\n lps[i] = 0\n i += 1\n\nif lps[n-1] == 0:\n print(\"Just a legend\")\nelse:\n for i in range(1, n-1):\n if lps[i] == lps[n-1]:\n print(s[:lps[n-1]])\n break\n else:\n if lps[lps[n-1]-1] != 0:\n print(s[:lps[lps[n-1]-1]])\n else:\n print(\"Just a legend\")\n", "s = input()\r\ni, n = 0, len(s)\r\np = [-1] + [0] * n\r\nfor j in range(1, n):\r\n while i + 1 and s[i] != s[j]:\r\n i = p[i]\r\n i += 1\r\n p[j + 1] = i\r\nk = p.pop()\r\nprint(s[:k] if k and k in p else s[:p[k]] if p[k] > 0 else 'Just a legend')", "def main():\r\n p=s=input().strip()\r\n n=len(s)\r\n pi=[0]*n\r\n j=0\r\n for i in range(1, n):\r\n while j>0 and p[i]!=p[j]: j=pi[j-1]\r\n if p[i]==p[j]: j=j+1\r\n pi[i]=j\r\n if pi[-1]==0: return \"Just a legend\"\r\n for i in range(n-1):\r\n if pi[i]==pi[-1]: return s[:pi[-1]]\r\n if pi[pi[-1]-1] == 0:\r\n return \"Just a legend\"\r\n else:\r\n return s[:pi[pi[-1]-1]]\r\nprint(main())", "def find_substring(s):\r\n n = len(s)\r\n lps = [0] * n \r\n j = 0\r\n i = 1\r\n while i < n:\r\n if s[i] == s[j]:\r\n j += 1\r\n lps[i] = j\r\n i += 1\r\n else:\r\n if j != 0:\r\n j = lps[j-1]\r\n else:\r\n lps[i] = 0\r\n i += 1\r\n if lps[n-1] == 0:\r\n return \"Just a legend\"\r\n\r\n for i in range(n-2):\r\n if lps[i] == lps[n-1]:\r\n return s[:lps[n-1]]\r\n\r\n if lps[lps[n-1]-1] > 0:\r\n return s[:lps[lps[n-1]-1]]\r\n \r\n return \"Just a legend\"\r\ns = input()\r\nsubstring_t = find_substring(s)\r\n\r\nprint(substring_t)", "from sys import stdin\r\nfrom collections import deque\r\nfrom math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin\r\ndef ii(): return int(stdin.readline())\r\ndef fi(): return float(stdin.readline())\r\ndef mi(): return map(int, stdin.readline().split())\r\ndef fmi(): return map(float, stdin.readline().split())\r\ndef li(): return list(mi())\r\ndef lsi():\r\n x=list(stdin.readline())\r\n x.pop()\r\n return x\r\ndef si(): return stdin.readline()\r\nres=['YES', 'NO']\r\n############# CODE STARTS HERE #############\r\ndef create_z(s):\r\n z=[0]*len(s)\r\n x=y=0\r\n for i in range(1, len(s)):\r\n z[i]=max(0, min(z[i-x], y-i+1))\r\n while i+z[i]<len(s) and s[z[i]]==s[i+z[i]]:\r\n x = i\r\n y = i+z[i]\r\n z[i]+=1\r\n return z\r\na=lsi()\r\nn=len(a)\r\nz=create_z(a)\r\n#print(z)\r\nmx=max(z)\r\npos=z.index(mx)\r\nm=0\r\nfor i in range(max(pos+1, n-mx), n):\r\n if z[i]==n-i:\r\n m=n-i\r\n break\r\nif m<1:\r\n print('Just a legend')\r\nelse:\r\n print(*a[:m], sep='')", "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nimport decimal\r\ninput=sys.stdin.readline\r\ns=input()\r\nn=len(s)-1\r\nl=[0]*n\r\nk=0\r\ni=1\r\nwhile(i<n):\r\n if(s[i]==s[k]):\r\n k+=1\r\n l[i]=k\r\n i+=1\r\n else:\r\n if(k!=0):\r\n k=l[k-1]\r\n else:\r\n l[i]=0\r\n i+=1\r\nif(l[n-1]==0):\r\n print(\"Just a legend\")\r\nelse:\r\n k=-1\r\n for i in range(n-1):\r\n if(l[i]==l[n-1]):\r\n k=i\r\n break\r\n if(k==-1):\r\n if(l[l[n-1]-1]==0):\r\n print(\"Just a legend\")\r\n else:\r\n print(s[:l[l[n-1]-1]])\r\n else:\r\n print(s[:l[k]])", "def pref(s):\r\n\tl = [0] * len(s)\r\n\tpos = 0\r\n\tfor i in range(1, len(s)):\r\n\t\twhile pos > 0 and s[pos] != s[i]:\r\n\t\t\tpos = l[pos - 1]\r\n\t\tif s[pos] == s[i]:\r\n\t\t\tpos += 1\r\n\t\t\tl[i] = pos\r\n\t\telse:\r\n\t\t\tl[i] = pos\r\n\treturn l\r\n\r\ns = input()\r\nl = pref(s)\r\nlength = l[len(s) - 1]\r\n\r\n#print(l)\r\n\r\nok = None\r\n\r\nif length != 0:\r\n\tfor i in range(2):\r\n\t\tfor j in range(1, len(s) - 1):\r\n\t\t\tif length == l[j]:\r\n\t\t\t\tok = True\r\n\t\t\t\tbreak\r\n\t\t\r\n\t\t#if ok == True:\r\n\t\t#\tlength = l[length - i + j - 1]\r\n\t\t\r\n\t\tif not ok:\r\n\t\t\tlength = l[length - 1]\r\n\t\t\tif length == 0:\r\n\t\t\t\tbreak\r\n\t\telse:\r\n\t\t\tbreak\r\nif not ok or length == 0:\r\n\tprint(\"Just a legend\")\r\nelse:\r\n\tprint(s[0:length])\r\n", "def compute_lps(s):\n \n num = len(s)\n lps = [0] * num\n Len = 0\n lps[0] = 0\n i = 1\n \n while (i < num):\n if (s[i] == s[Len]):\n Len += 1\n lps[i] = Len\n i += 1\n \n else:\n if (Len != 0):\n Len = lps[Len - 1]\n \n else:\n lps[i] = 0\n i += 1\n return lps\n\ndef Longestsubstring(s):\n \n lps = compute_lps(s)\n num = len(s)\n \n if (lps[num - 1] == 0):\n print(\"Just a legend\")\n exit()\n \n for i in range(0, num - 1):\n \n if (lps[i] == lps[num - 1]):\n print(s[0:lps[i]])\n exit()\n \n \n if (lps[lps[num - 1] - 1] == 0):\n print(\"Just a legend\")\n else:\n print(s[0:lps[lps[num - 1] - 1]])\n \n \ns = input()\n \nLongestsubstring(s)\n\n \t \t \t\t \t\t\t\t\t \t\t \t\t\t \t", "def solve(s):\r\n n = len(s)\r\n pi = [0] * n\r\n k = 0\r\n\r\n for i in range(1, n):\r\n while k > 0 and s[i] != s[k]:\r\n k = pi[k - 1]\r\n\r\n if s[i] == s[k]:\r\n k += 1\r\n\r\n pi[i] = k\r\n\r\n length = pi[n - 1]\r\n if length == 0:\r\n return \"Just a legend\"\r\n\r\n for i in range(1, n - 1):\r\n if pi[i] == length:\r\n return s[:length]\r\n\r\n length = pi[length - 1]\r\n if length == 0:\r\n return \"Just a legend\"\r\n\r\n return s[:length]\r\n\r\n\r\ns = input()\r\nprint(solve(s))\r\n", "s,k,l=input(),-1,[-1]\nfor c in s:\n while(k!=-1)and(s[k]!=c):\n k=l[k]\n k+=1\n l.append(k)\nle=l[-1]\nif l.count(le)<2:\n le=l[le]\nprint(s[:le] if le>0 else 'Just a legend')\n\n \t\t \t\t \t\t\t\t \t \t\t \t \t\t\t", "def build_table(s):\r\n table = [0] * len(s)\r\n j = 0\r\n for i in range(1, len(s)):\r\n while j > 0 and s[i] != s[j]:\r\n j = table[j - 1]\r\n if s[i] == s[j]:\r\n j += 1\r\n table[i] = j\r\n return table\r\n\r\ns = input()\r\ntable = build_table(s)\r\nn = len(s)\r\nif table[-1] == 0:\r\n print(\"Just a legend\")\r\nelse:\r\n ll = table[-1]\r\n for i in range(n - 1):\r\n if table[i] == ll:\r\n print(s[:ll])\r\n break\r\n else:\r\n if table[ll - 1] == 0:\r\n print(\"Just a legend\")\r\n else:\r\n print(s[:table[ll - 1]])\r\n", "def KMP(st):\r\n i = 0\r\n j = 1\r\n arr = [0 for i in range(len(st))]\r\n while j < len(st):\r\n if s[j] == s[i]:\r\n arr[j] = i+1\r\n i += 1\r\n else:\r\n while i>0:\r\n i = arr[i-1]\r\n if s[i] == s[j]:\r\n arr[j] = i+1\r\n i += 1\r\n break\r\n \r\n j += 1\r\n return arr\r\n\r\ns = input()\r\narr = KMP(s)\r\nmaxi = arr[-1]\r\nfound = arr[maxi-1]\r\nfor i in arr[1:-1]:\r\n if i == maxi:\r\n found = maxi\r\nif found == 0:\r\n print(\"Just a legend\")\r\nelse:\r\n print(s[:found])\r\n# pre = findPreSuff(s)\r\n# if len(pre):\r\n# if pre in s[1:-1]:\r\n# print(pre)\r\n# else:\r\n# # print(\"############\", pre)\r\n# P = findPreSuff(pre)\r\n# if len(P):\r\n# print(P)\r\n# else:\r\n# print(\"Just a legend\")\r\n\r\n# else:\r\n# print(\"Just a legend\")", "s = input()\nn = len(s)\np = [0]\nfor i in range(1,n):\n j = p[i-1]\n while (j>0 and s[i] != s[j]):\n j = p[j-1]\n if s[i]==s[j]:\n p.append(j+1)\n else:\n p.append(0)\n#print(p)\nif p[n-1] > 0:\n for i in range(n-1):\n if p[i] == p[n-1]:\n print(s[:p[n-1]])\n exit(0)\n if p[p[n-1]-1] > 0:\n print(s[:p[p[n-1]-1]])\n exit(0)\n print(\"Just a legend\")\nelse:\n print(\"Just a legend\")", "s = input()\r\nk = -1\r\nl = [-1]\r\nfor c in s:\r\n #print(k)\r\n #print(s[k])\r\n while(k!=-1)and(s[k]!=c):\r\n k=l[k]\r\n k+=1\r\n l.append(k)\r\n #print(l)\r\nle=l[-1]\r\n#print(le)\r\nif l.count(le)<2:\r\n le=l[le]\r\nprint(s[:le] if le>0 else 'Just a legend')", "def binpoisk(hash, lens, p, mod):\r\n n = len(hash)\r\n l, r = -1, len(lens)\r\n ans = 0\r\n while l + 1 < r:\r\n m = (l + r) // 2\r\n ln = lens[m]\r\n flag = 0\r\n h = calc_hash(hash, p, 0, ln-1, mod)\r\n for i in range(1, n-ln, 1):\r\n if calc_hash(hash, p, i, i + ln - 1, mod) == h:\r\n ans = max(ans, ln)\r\n flag = 1\r\n break\r\n if flag == 1:\r\n l = m\r\n else: r = m\r\n return ans\r\ndef calc_hash(hash, p, l, r, mod):\r\n if l == 0:\r\n return hash[r]\r\n else:\r\n return (hash[r] - hash[l-1] * p[r-l+1]) % mod\r\n\r\ndef main():\r\n s = input()\r\n n = len(s)\r\n p_, mod = 1153, 10**9 + 7\r\n p = [1] * (len(s)+1)\r\n for i in range(1, len(s)+1):\r\n p[i] = (p[i-1] * p_) % mod\r\n hash = [0]*n\r\n hash[0] = (ord(s[0])) % mod\r\n for i in range(1, n, 1):\r\n hash[i] = (hash[i-1] * p_ + ord(s[i])) % mod\r\n\r\n lens = []\r\n\r\n for i in range(0, n-1, 1):\r\n if calc_hash(hash, p, 0, i, mod) == calc_hash(hash, p, n-i-1, n-1,mod):\r\n lens.append(i+1)\r\n\r\n ans = binpoisk(hash, lens, p, mod)\r\n if ans == 0:\r\n print('Just a legend')\r\n else:\r\n print(s[:ans])\r\nif __name__ == \"__main__\":\r\n main()", "def build_hash(s):\r\n base=31; P=[1]+[0]*1000000; H=[0]*1000001\r\n for i in range(1,1000001): P[i]=(P[i-1]*base)%1000000007\r\n for i in range(1, len(s)+1): H[i]=(base*H[i-1]+(ord(s[i-1])-ord('a')+1))%1000000007\r\n return H,P\r\ndef get_hash(l,r,H,P):\r\n return (H[r]-(H[l-1]*P[r-l+1])%1000000007+1000000007)%1000000007\r\ndef ok(x,n,H,P):\r\n res=get_hash(1,x,H,P)\r\n for i in range(2,n-x+1):\r\n if get_hash(i,i+x-1,H,P)==res: return True\r\n return False\r\ns=input(); H,P=build_hash(s); len_arr=[]\r\nfor i in range(1, len(s)):\r\n if get_hash(1,i,H,P)==get_hash(len(s)-i+1,len(s),H,P):\r\n len_arr.append(i)\r\nl=0; r=len(len_arr)-1; ans=0\r\nwhile l<=r:\r\n m=(l+r)//2\r\n if ok(len_arr[m],len(s),H,P): ans=len_arr[m]; l=m+1\r\n else: r=m-1\r\nif ans==0: print(\"Just a legend\")\r\nelse: print(s[:ans])", "def compute_prefix_function(s):\r\n n = len(s)\r\n p = [0] * n\r\n for i in range(1, n):\r\n j = p[i - 1]\r\n while j > 0 and s[i] != s[j]:\r\n j = p[j - 1]\r\n if s[i] == s[j]:\r\n j += 1\r\n p[i] = j\r\n return p\r\n\r\n\r\ns = input()\r\nn = len(s)\r\n\r\np = compute_prefix_function(s)\r\n\r\nif p[-1] == 0:\r\n print(\"Just a legend\")\r\n exit(0)\r\nfor i in range(len(s)-1):\r\n if p[i] == p[-1]:\r\n print(s[:p[i]])\r\n exit(0)\r\n\r\nif p[p[- 1] - 1] == 0:\r\n print(\"Just a legend\")\r\n\r\nprint(s[:p[p[len(s) - 1] - 1]])\r\n", "def solve(s):\n n = len(s)\n lps = [0] * n\n length = 0\n i = 1\n\n while i < n:\n if s[i] == s[length]:\n length += 1\n lps[i] = length\n i += 1\n else:\n if length != 0:\n length = lps[length - 1]\n else:\n lps[i] = 0\n i += 1\n\n if lps[n - 1] == 0:\n print(\"Just a legend\")\n return\n\n for i in range(1, n - 1):\n if lps[i] == lps[n - 1]:\n print(s[:lps[i]])\n return\n\n if lps[lps[n - 1] - 1] == 0:\n print(\"Just a legend\")\n else:\n print(s[:lps[lps[n - 1] - 1]])\n\n\ndef main():\n s = input()\n solve(s)\n\nmain()\n\n \t \t \t\t \t \t\t \t \t \t", "import sys\r\n\r\nI = lambda: int(input())\r\nreadline = lambda : sys.stdin.readline().strip()\r\nRM = readlist = lambda x=int: map(x,readline().split())\r\n\r\n\r\ndef prefix_function(s):\r\n n = len(s)\r\n pi = [0]*(n)\r\n for i in range(1,n):\r\n j = pi[i-1]\r\n while j>0 and s[i]!=s[j]:\r\n j = pi[j-1]#reduce s to last largest prefix of i\r\n if s[i] == s[j]: j+=1\r\n pi[i] = j\r\n return pi\r\n\r\ns = readline()\r\npi = prefix_function(s)\r\npis = set(pi[:-1])\r\nj = pi[-1]\r\nwhile j>0 and (not j in pis):\r\n j = pi[j-1]\r\nprint(s[:j] if j>0 else \"Just a legend\")\r\n\r\n\r\nquit()\r\n#154C Double Profiles (failure)\r\ns = readline()\r\nn = len(s)\r\nppow,base,p,m = [0]*int(n+5),1,31,int(1e9+7)\r\nfor i in range(n+5):\r\n ppow[i],base = base,(base*p)%m\r\n\r\nhashp = [0]*n\r\n\r\nhashp[0] = ord(s[0]) - 96\r\nfor ind in range(1,n):\r\n hashp[ind] = (hashp[ind-1] + (ord(s[ind])-96)*ppow[ind])%m\r\n\r\nstop = False\r\nfor l in range(n-1,0,-1):\r\n prefix_hash = ( hashp[l-1]*ppow[n+1] )%m\r\n suffix_hash = ( (hashp[n-1] - hashp[n-l-1])*ppow[l+1] )%m\r\n #print(l,suffix_hash,prefix_hash)\r\n if suffix_hash!=prefix_hash: continue\r\n for t in range(1,n-l):\r\n temp_hash = ( (hashp[t+l-1] - hashp[t-1])*ppow[n-t+1] )%m\r\n if temp_hash == suffix_hash:\r\n print(s[t:t+l]);stop = True;break\r\n if stop: break\r\nelse:\r\n print(\"Just a legend\")\r\n\r\n\r\n\r\n", "def KMPalgo(instring, arr):\r\n arr[0] = -1\r\n tmp = -1\r\n\r\n #traverse over the input string\r\n for i in range(1,len(instring)):\r\n\r\n while (tmp !=-1 and instring[i] != instring[tmp+1]):\r\n tmp = arr[tmp]\r\n\r\n if (instring[i] == instring[tmp+1]):\r\n tmp += 1\r\n arr[i] = tmp\r\n else:\r\n arr[i] = -1\r\n\r\ndef main():\r\n instring = input()\r\n arr = [0] * 1000005\r\n\r\n #call KMPalgo funtion to create the temporary array \r\n KMPalgo(instring, arr)\r\n\r\n l = len(instring)\r\n max = arr[l-1]\r\n found = arr[max]\r\n\r\n if max == -1:\r\n found = -1\r\n\r\n #to find the largest substring\r\n for i in range(1,l-1):\r\n if arr[i] == max:\r\n found = max\r\n\r\n #Print not found when the no string fulfill the criteria\r\n if found == -1:\r\n print(\"Just a legend\")\r\n else:\r\n print(instring[0:found+1])\r\n\r\n#execute main\r\nmain()", "xyz = input()\nn = len(xyz)\n \narr = [0] * (n + 1)\n \ni = 0\nj = 1\n \nwhile j < n:\n if xyz[j] == xyz[i]:\n j += 1\n i += 1\n arr[j] = i\n elif i:\n i = arr[i]\n else:\n j += 1\n \na = arr.pop()\nb = arr[a]\n \nif a and (a in arr):\n print(xyz[:a])\nelif b:\n print(xyz[:b])\nelse:\n print('Just a legend')\n\t\t \t \t \t \t\t\t\t\t\t\t \t\t \t \t \t\t \t", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef z_algorithm(w):\r\n m = len(w)\r\n z = [0] * m\r\n z[0] = m\r\n i, j = 1, 0\r\n while i < m:\r\n while i + j < m and w[j] == w[i + j]:\r\n j += 1\r\n z[i] = j\r\n if not j:\r\n i += 1\r\n continue\r\n l = 1\r\n while l < j and l + z[l] < j:\r\n z[i + l] = z[l]\r\n l += 1\r\n i += l\r\n j -= l\r\n return z\r\n\r\ns = list(input().rstrip().decode())\r\nz = z_algorithm(s)\r\nn = len(s)\r\nma = list(z)\r\nma[0] = 0\r\nfor i in range(1, n):\r\n ma[i] = max(ma[i], ma[i - 1])\r\nans = \"Just a legend\"\r\nfor i in range(n - 2, 0, -1):\r\n if min(z[-i], ma[-(i + 1)]) >= i:\r\n ans = \"\".join(s[:i])\r\n break\r\nprint(ans)", "def prefix_function(s):\r\n n = len(s)\r\n pi = [None] * n\r\n pi[0] = 0\r\n for i in range(1, n):\r\n j = pi[i - 1]\r\n while j > 0 and s[i] != s[j]:\r\n j = pi[j - 1]\r\n if s[i] == s[j]:\r\n j += 1\r\n pi[i] = j\r\n return pi\r\n\r\n\r\nst = input()\r\nr = prefix_function(st)\r\n\r\nif r[-1] == 0:\r\n print('Just a legend')\r\nelse:\r\n f = False\r\n pos = 0\r\n for i in range(0, len(r) - 1):\r\n if r[i] == r[-1]:\r\n f = True\r\n pos = i\r\n if f:\r\n print(st[:r[pos]])\r\n else:\r\n if r[r[len(st) - 1] - 1] == 0:\r\n print('Just a legend')\r\n else:\r\n print(st[:r[r[len(st) - 1] - 1]])\r\n", "from sys import stdin\r\ns=stdin.readline().rstrip()\r\nk=-1\r\nl=[-1]\r\nfor c in s:\r\n while k!=-1 and s[k]!=c:\r\n k=l[k]\r\n k+=1\r\n l+=[k]\r\nq=l[-1]\r\nif l.count(q)<2:\r\n q=l[q]\r\nprint(s[:q] if q>0 else \"Just a legend\")", "def KMPSearch(pat, txt):\r\n\tM = len(pat)\r\n\tN = len(txt)\r\n\r\n\tlps = [0]*M\r\n\tj = 0\r\n\r\n\tcomputeLPSArray(pat, M, lps)\r\n\r\n\ti = 0\r\n\twhile i < N:\r\n\t\tif pat[j] == txt[i]:\r\n\t\t\ti += 1\r\n\t\t\tj += 1\r\n\r\n\t\tif j == M:\r\n\t\t\tprint (\"Found pattern at index \" + str(i-j))\r\n\t\t\tj = lps[j-1]\r\n\r\n\t\telif i < N and pat[j] != txt[i]:\r\n\t\t\tif j != 0:\r\n\t\t\t\tj = lps[j-1]\r\n\t\t\telse:\r\n\t\t\t\ti += 1\r\n\r\ndef computeLPSArray(pat, M, lps):\r\n\tlen = 0\r\n\r\n\tlps[0]\r\n\ti = 1\r\n\r\n\twhile i < M:\r\n\t\tif pat[i]== pat[len]:\r\n\t\t\tlen += 1\r\n\t\t\tlps[i] = len\r\n\t\t\ti += 1\r\n\t\telse:\r\n\t\t\tif len != 0:\r\n\t\t\t\tlen = lps[len-1]\r\n\t\t\telse:\r\n\t\t\t\tlps[i] = 0\r\n\t\t\t\ti += 1\r\n\treturn lps\r\n\r\ns=input()\r\nm=len(s)\r\nlps=[0]*m\r\nx=computeLPSArray(s, m, lps)\r\n\r\nx=[0]+x\r\na=x[-1]\r\nb=x[a]\r\nans=\"\"\r\n\r\nfor i in range(len(x)):\r\n if x[i]==a and i!=m:\r\n ans=s[0:a]\r\n\r\nif ans==\"\":\r\n if b!=0:\r\n ans=s[0:b]\r\n else:\r\n ans=\"Just a legend\"\r\n \r\nprint(ans)", "from sys import stdin,stdout\r\ndef min(x,y):\r\n if(x<y):\r\n return x\r\n else:\r\n return y\r\ndef max(x,y):\r\n if(x>y):\r\n return x\r\n else:\r\n return y\r\ndef binarysearch(a,x,first,last):\r\n if a[last]<=x:\r\n return a[last]\r\n if a[first]>x:\r\n return 0\r\n mid=(first+last)//2\r\n if a[mid]==x:\r\n return x\r\n if a[mid]<x and a[mid+1]>x:\r\n return a[mid]\r\n \r\n if a[mid]<x:\r\n return binarysearch(a,x,mid,last)\r\n return binarysearch(a,x,first,mid)\r\ns=stdin.readline().strip()\r\nif len(s)==1:\r\n print(\"Just a legend\")\r\n exit()\r\n\r\nz=[]\r\nfor i in range(len(s)):\r\n z.append(0)\r\nx=0\r\ny=0\r\nn=len(s)\r\nfor i in range(1,n):\r\n z[i]=max(0,min(z[i-x],y-i+1))\r\n while i+z[i]<n and s[z[i]]==s[i+z[i]]:\r\n x=i\r\n y=i+z[i]\r\n z[i]+=1\r\na=[0]\r\nfor i in range(len(s)-1,-1,-1):\r\n if z[i]==len(s)-i:\r\n a.append(len(s)-i)\r\n\r\nans=0\r\nmx=0\r\nv=[]\r\nfor i in range(1,n):\r\n if z[i]+i==n:\r\n v.append(z[i])\r\n mx=max(mx,z[i]-1)\r\n else:\r\n mx=max(mx,z[i])\r\nfor i in range(0,len(v)):\r\n t = v[i]\r\n if t <= mx:\r\n ans = max(ans,t)\r\nif ans==0:\r\n print(\"Just a legend\")\r\nelse:\r\n for i in range(0,ans):\r\n print(s[i],end='')\r\n ", "import sys\ninput = sys.stdin.readline\n\ns = input().rstrip('\\n')\nn = len(s)\n\nZ = [0] * n\nl = r = 0\nfor i in range(1, n):\n if i <= r:\n Z[i] = min(Z[i - l], r - i + 1)\n while i + Z[i] < n and s[Z[i]] == s[i + Z[i]]:\n Z[i] += 1\n if i + Z[i] - 1 > r:\n l = i\n r = i + Z[i] - 1\n\npref = 0\nmx = 0\nfor i in range(n):\n if i + Z[i] == n and mx >= Z[i] > pref:\n pref = Z[i]\n mx = max(mx, Z[i])\n\nprint(s[:pref] or \"Just a legend\")", "s=input()\r\ncount = -1\r\narr = [-1]\r\nfor x in s:\r\n while count != -1 and s[count] != x:\r\n count = arr[count]\r\n count = count +1\r\n arr.append(count)\r\nle = arr[-1]\r\nif arr.count(le) < 2:\r\n le = arr[le]\r\n\r\nif le > 0 :\r\n\tprint(s[:le])\r\nelse:\r\n \tprint(\"Just a legend\")\r\n", "# from math import pow\r\ns = input()\r\nn = len(s)\r\n\r\nlps = [0] * n\r\n\r\ni, j = 1, 0\r\n\r\nwhile i < n:\r\n if s[i] == s[j]:\r\n j += 1\r\n lps[i] = j\r\n i += 1\r\n\r\n elif j > 0:\r\n j = lps[j - 1]\r\n\r\n else:\r\n i += 1\r\n# print(lps)\r\nif lps[-1] == 0:\r\n print(\"Just a legend\")\r\n\r\nelse:\r\n target = lps[-1]\r\n\r\n met = False\r\n for i in range(1, n - 1):\r\n if lps[i] == target:\r\n met = True\r\n break\r\n\r\n if not met:\r\n target = lps[lps[-1] - 1]\r\n # print(\"!!!!!\", target)\r\n for i in range(1, n - 1):\r\n if lps[i] == target:\r\n met = True\r\n break\r\n\r\n if not met or target == 0:\r\n print(\"Just a legend\")\r\n else:\r\n print(s[:target])\r\n\r\n else:\r\n print(s[:target])", "from collections import defaultdict, Counter,deque\r\nfrom math import sqrt, log10, log, floor, factorial\r\nfrom bisect import bisect_left, bisect_right\r\nfrom itertools import permutations,combinations\r\nimport sys, io, os\r\ninput = sys.stdin.readline\r\n# input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n# print=sys.stdout.write\r\n# sys.setrecursionlimit(10000)\r\ninf = float('inf');\r\nmod = 10 ** 9 + 7\r\ndef get_list(): return [int(i) for i in input().split()]\r\ndef yn(a): print(\"YES\" if a else \"NO\")\r\nceil = lambda a, b: (a + b - 1) // b\r\ndef z_function(S):\r\n \"\"\"\r\n Z Algorithm in O(n)\r\n :param S: text string to process\r\n :return: the Z array, where Z[i] = length of the longest common prefix of S[i:] and S\r\n \"\"\"\r\n\r\n n = len(S)\r\n Z = [0] * n\r\n l = r = 0\r\n\r\n for i in range(1, n):\r\n z = Z[i - l]\r\n if i + z >= r:\r\n z = max(r - i, 0)\r\n while i + z < n and S[z] == S[i + z]:\r\n z += 1\r\n\r\n l, r = i, i + z\r\n\r\n Z[i] = z\r\n\r\n Z[0] = n\r\n return Z\r\nt=1\r\nfor i in range(t):\r\n s=input().strip()\r\n z=z_function(s)\r\n l=sorted(z[1:])\r\n ans=-1\r\n for i in range(len(z)-1,0,-1):\r\n if z[i]==len(z)-i:\r\n\r\n if bisect_left(l,z[i])<len(l)-1:\r\n ans=z[i]\r\n if ans==-1:\r\n print(\"Just a legend\")\r\n else:\r\n print(s[:ans])", "def compute_lps(s):\n \n n = len(s)\n \n lps = [0] * n\n \n Len = 0\n lps[0] = 0\n i = 1\n \n while (i < n):\n if (s[i] == s[Len]):\n Len += 1\n lps[i] = Len\n i += 1\n \n # (pat[i] != pat[Len])\n else:\n if (Len != 0):\n Len = lps[Len - 1]\n \n # If Len = 0\n else:\n lps[i] = 0\n i += 1\n \n return lps\n \n \n \ndef Longestsubstring(s):\n \n lps = compute_lps(s)\n n = len(s)\n \n # If lps of n-1 is zero\n if (lps[n - 1] == 0):\n print(\"Just a legend\")\n exit()\n \n for i in range(0, n - 1):\n \n # At any position lps[i] equals to lps[n - 1]\n if (lps[i] == lps[n - 1]):\n print(s[0:lps[i]])\n exit()\n \n if (lps[lps[n - 1] - 1] == 0):\n print(\"Just a legend\")\n else:\n print(s[0:lps[lps[n - 1] - 1]])\n \n \ns = input()\n \nLongestsubstring(s)\n \t\t \t \t\t\t \t \t \t\t\t\t \t\t\t \t \t", "s = input()\r\nn = len(s)\r\n\r\ndef prefix_F(s):\r\n\tn = len(s)\r\n\r\n\tpi = [0] * n\r\n\tfor i in range(1, n):\r\n\t\tcur = pi[i - 1]\r\n\t\twhile cur > 0 and s[i] != s[cur]:\r\n\t\t\tcur = pi[cur - 1]\r\n\r\n\t\tif s[i] == s[cur]:\r\n\t\t\tcur += 1\r\n\t\tpi[i] = cur\r\n\r\n\treturn pi\r\n\r\ndef end():\r\n\tprint(\"Just a legend\")\r\n\texit(0)\r\n\r\ndef inside(pi, x):\r\n\tn = len(pi)\r\n\tval = pi.index(x)\r\n\tans = pi[n - 1]\r\n\r\n\t#print(val)\r\n\tif val == n - 1:\r\n\t\tif (pi[pi[n - 1] - 1] == 0): end()\r\n\t\telse:\r\n\t\t\tans = pi[pi[n - 1] - 1]\r\n\r\n\r\n\treturn ans\r\n\r\n\r\npi = prefix_F(s)\r\n#print(*pi)\r\n\r\n\r\nif (pi[n - 1] == 0): end()\r\nelse:\r\n\tprint(s[:inside(pi, pi[n - 1])])", "# def main():\r\n# s = input()\r\n# for i in range(1,len(s)):\r\n# pref = s[:-i]\r\n# suf = s[i:]\r\n# cen = s[1:-1]\r\n# # print(pref, cen, suf)\r\n# if pref == suf:\r\n# if pref in cen:\r\n# return pref\r\n# return \"Just a legend\"\r\n\r\n# print(main())\r\n\r\ndef solve():\r\n s = input()\r\n n = len(s)\r\n pi = [0] * n\r\n for i in range(1, n):\r\n j = pi[i - 1]\r\n while j > 0 and s[i] != s[j]:\r\n j = pi[j - 1]\r\n if s[i] == s[j]:\r\n j += 1\r\n pi[i] = j\r\n\r\n was = [0] * (n + 1)\r\n for i in range(n):\r\n was[pi[i]] += 1\r\n\r\n d = pi[n - 1]\r\n if d == 0:\r\n print(\"Just a legend\")\r\n return\r\n if was[d] >= 2:\r\n print(s[:d])\r\n elif pi[d - 1] > 0:\r\n print(s[:pi[d - 1]])\r\n else:\r\n print(\"Just a legend\")\r\n\r\nif __name__ == \"__main__\":\r\n # For local testing\r\n # file_input\r\n # start_time = time.time()\r\n # precision = 3\r\n test = 1\r\n # test = int(input())\r\n for _ in range(test):\r\n solve()\r\n # print(\"Execution time:\", int((time.time() - start_time) * 1e3), \"ms\")\r\n", "s=input()\r\n\r\n\r\n\r\ndef kmp_fail(p):\r\n m=len(p)\r\n fail=m*[0]\r\n k=0\r\n j=1\r\n while j<m:\r\n if p[j]==p[k]:\r\n fail[j]=k+1\r\n j+=1\r\n k+=1\r\n elif k>0:\r\n k=fail[k-1]\r\n else:\r\n j+=1\r\n return fail\r\nl=[-1]\r\nl+=kmp_fail(s)\r\nle=l[-1]\r\nif l.count(le)<2:\r\n le=l[le]\r\nprint(s[:le] if le>0 else 'Just a legend')", "P=input()\r\nm = len(P)\r\nf=[0]*m\r\nj=1\r\nk=0\r\nwhile j<m:\r\n if P[j]==P[k]:\r\n f[j]=k+1\r\n j+=1\r\n k+=1\r\n elif k>0:\r\n k=f[k-1]\r\n else:\r\n j+=1\r\nl=f.pop()\r\nif l:\r\n if l in f:\r\n print(P[:l])\r\n elif f[l-1]:\r\n print(P[:f[l-1]])\r\n else:\r\n print('Just a legend')\r\nelse:\r\n print('Just a legend')", "# def match_fn(i1,i2, n):\n\n# \tif i2 >= n:\n# \t\treturn 0\n# \tlog_next_len = 0\n# \tnext_len = 1\n# \tcurr_len = 0\n# \tmatch = True\n# \twhile match:\n# \t\tif rank_array[log_next_len][i1] == rank_array[log_next_len][i2]:\n# \t\t\tlog_next_len += 1\n# \t\t\tcurr_len = next_len\n# \t\t\tnext_len*=2\n# \t\telse:\n# \t\t\tmatch = False\n\n# \tif curr_len > 0:\n# \t\treturn curr_len + match_fn(i1+curr_len, i2+curr_len,n)\n# \telse:\n# \t\treturn 0 \n\n\n# s = input()\n# n = len(s)\n# set_letters = {}\n\n# for i,c in enumerate(s):\n# \tif c not in set_letters:\n# \t\tset_letters[c] = [i,]\n# \telse:\n# \t\tset_letters[c].append(i)\n\n\n\n# global rank_array\n\n# rank_array = [[-1]*n,]\n# set_rank = [{},]\n\n# i = 0\n# for k,v in sorted(set_letters.items()):\n# \tfor a in v:\n# \t\trank_array[0][a] = i\n# \tset_rank[0][i] = v\n# \ti += 1\n\n# curr_len = 1\n\n# while (curr_len < n):\n# \tnew_set_rank = {}\n# \tnew_rank = 0\n# \tnew_rank_array = [-1]*n\n# \tfor k,v_list in sorted(set_rank[-1].items()):\n# \t\ts_mini = {}\n# \t\tfor v in v_list:\n# \t\t\tif v+curr_len >= n:\n# \t\t\t\tc = -1\n# \t\t\telse:\n# \t\t\t\tc = rank_array[-1][v+curr_len]\n# \t\t\ts_mini[c] = s_mini.get(c)\n# \t\t\t\ts_mini[c] = [v,]\n# \t\t\telse:\n# \t\t\t\ts_mini[c].append(v)\n# \t\tfor mini_k, mini_vlist in sorted(s_mini.items()):\n# \t\t\tnew_set_rank[new_rank] = mini_vlist\n# \t\t\tfor v in mini_vlist:\n# \t\t\t\tnew_rank_array[v] = new_rank\n# \t\t\tnew_rank+= 1\n# \trank_array.append(new_rank_array)\n# \tset_rank.append(new_set_rank)\n\n# \tcurr_len *= 2\n\n\n# matching_letters = []\n\n# for index in range(1,n):\n# \tmatching_letters.append(match_fn(0, index, n))\n\n# max_sofar = 0\n# valid_max = 0\n# ans = -1\n# for index, length_match in enumerate(matching_letters):\n# \tif index + length_match +1 == n:\n# \t\tif max_sofar >= length_match:\n# \t\t\tvalid_max = length_match\n# \t\t\tans = index + 1\n# \t\t\tbreak \n\t\n# \tmax_sofar = max(max_sofar,length_match)\n\n# if valid_max == 0:\n# \tprint(\"Just a legend\")\n# else:\n# \tprint(s[ans:])\n\n\n\n#lstr[i] = \n\ns = input()\nlongest_matching = [-1,]\nfor c in s[1:]:\n\tlast_matching = longest_matching[-1] \n\tno_match = False\n\twhile s[last_matching+1] != c:\n\t\tif last_matching!=-1:\n\t\t\tlast_matching = longest_matching[last_matching]\n\t\telse:\n\t\t\tlast_matching = last_matching - 1\n\t\t\tbreak\n\tlongest_matching.append(last_matching+1)\n\nif longest_matching.count(longest_matching[-1]) < 2:\n\tans = longest_matching[longest_matching[-1]] + 1\nelse:\n\tans = longest_matching[-1] + 1\n\nif ans > 0:\n\tprint(s[:ans])\nelse:\n\tprint(\"Just a legend\")\n\n", "def main():\r\n s = input()\r\n n = len(s)\r\n pi = [0] * n\r\n\r\n for i in range(1, n):\r\n j = pi[i - 1]\r\n while j > 0 and s[i] != s[j]:\r\n j = pi[j - 1]\r\n if s[i] == s[j]:\r\n j += 1\r\n pi[i] = j\r\n \r\n was = [0] * (n + 1)\r\n for i in range(n):\r\n was[pi[i]] += 1\r\n \r\n d = pi[n - 1]\r\n if d == 0:\r\n print(\"Just a legend\")\r\n return\r\n if was[d] >= 2:\r\n print(s[:d])\r\n elif pi[d - 1] > 0:\r\n print(s[:pi[d - 1]])\r\n else:\r\n print(\"Just a legend\")\r\n\r\nmain()# 1691409454.4595132", "cad = input()\nn = len(cad)\n \narr = [0] * (n + 1)\n \ni = 0\nj = 1\n \nwhile j < n:\n if cad[j] == cad[i]:\n j += 1\n i += 1\n arr[j] = i\n elif i:\n \ti = arr[i]\n else: \n \tj += 1\n \na = arr.pop()\nb = arr[a]\n \nif a and (a in arr):\n\tprint(cad[:a])\nelif b:\n\tprint(cad[:b])\nelse:\n\tprint('Just a legend')\n\t\t \t\t \t\t \t\t \t \t \t\t\t \t", "def buildZ(S):\n L, R = 0, 0\n n = len(S)\n Z = [0] * n\n # S[L:R] najdluzszy prefix-substring\n # dla obecnego i\n for i in range(1, n):\n if i > R:\n L = R = i\n while R < n and S[R-L] == S[R]:\n R+=1\n Z[i] = R - L\n R -= 1\n else:\n k = i - L\n if Z[k] < R - i + 1:\n Z[i] = Z[k]\n else:\n L = i\n while R < n and S[R-L] == S[R]:\n R+=1\n Z[i] = R - L\n R -= 1\n\n return Z\n\n\n\nif __name__ == \"__main__\":\n S = input().strip()\n Z = buildZ(S)\n\n maxz, res = 0, 0\n n = len(S)\n for i in range(1, n):\n # Z[i] == n - i\n # oznacza: na miejscu Z[i] jest prefix\n # jeśli jego długość ciągnie się do końca to \n # jest także suffixem:\n # n = 7\n # Z[i=5] = 2, [a, b, c, d, e, a, b] Z[5] = 7-5 = 2 \n if Z[i] == n-i and maxz >= n - i:\n res = n - i\n break\n maxz = max(maxz, Z[i]) \n\n if res > 0:\n print(S[0:res])\n else:\n print(\"Just a legend\")\n", "s = input()\r\nn = len(s)\r\n\r\nif n==1 or n==2:\r\n\tprint(\"Just a legend\")\r\nelse:\r\n\tlista = []\r\n\tfor i in range(n):\r\n\t\tlista.append(0)\r\n\tl = 0\r\n\tlista[0] = 0\r\n\ti = 1\r\n\r\n\twhile i < n:\r\n\t\tif s[i]==s[l]:\r\n\t\t\tl+=1\r\n\t\t\tlista[i] = l\r\n\t\t\ti += 1\r\n\t\telse:\r\n\t\t\tif l!=0:\r\n\t\t\t\tl = lista[l-1]\r\n\t\t\telse:\r\n\t\t\t\tlista[i] = 0\r\n\t\t\t\ti += 1\r\n\r\n\tvalue = lista[-1]\r\n\tif value==0:\r\n\t\tprint(\"Just a legend\")\r\n\telif value in lista[:-1]:\r\n\t\tprint(s[:value])\r\n\telif lista[value-1]==0:\r\n\t\tprint(\"Just a legend\")\r\n\telif lista[value-1]:\r\n\t\tprint(s[:lista[value-1]])\r\n\telse:\r\n\t\tprint(\"Just a legend\")\r\n", "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, permutations, combinations\r\nfrom sys import stdout\r\n\r\nR = lambda: map(int, input().split())\r\ns = input()\r\nn = len(s)\r\nz = [0] * n\r\nl, r = 0, 0\r\nfor i in range(1, n):\r\n if i > r:\r\n k = i\r\n while k < n and s[k] == s[k - i]:\r\n k += 1\r\n l, r = i, k - 1\r\n z[l] = r - l + 1\r\n else:\r\n if i + z[i - l] <= r:\r\n z[i] = z[i - l]\r\n else:\r\n j = r + 1\r\n while j < n and s[j] == s[j - i]:\r\n j += 1\r\n l, r = i, j - 1\r\n z[i] = r - l + 1\r\nsz = sorted(z[1:])\r\nfor l in range(n - 1, 0, -1):\r\n if z[n - l] == l and len(sz) - bisect_left(sz, l) >= 2:\r\n print(s[:l])\r\n exit(0)\r\nprint('Just a legend')\r\n", "# prefix Function Which Tells\r\n# About Longest Proper Prefix Which Is\r\n# Also A Suffix For Every Index\r\ndef kmp_prefix_arr(arr):\r\n ii = 1\r\n jj = 0\r\n n = len(arr)\r\n pre_kmp = [0] * n\r\n while ii < n: # For Each Index\r\n if arr[ii] != arr[jj]: #We Cant Extend The Longest Suffix \r\n if jj != 0: \r\n jj = pre_kmp[jj - 1] #Try For Smaller Prefixes\r\n else: # No longest suffix which is also prefix so Value of array will be 0\r\n ii += 1\r\n else:\r\n pre_kmp[ii] = jj + 1 #Extended Longest prefix\r\n ii += 1\r\n jj += 1\r\n return pre_kmp\r\n \r\n \r\ns = input() \r\nn = len(s)\r\ntemp = []\r\nif n < 3:\r\n print(\"Just a legend\")\r\nelse:\r\n pi = kmp_prefix_arr(s)\r\n pi = [item - 1 for item in pi]\r\n password = pi[-1] #Longest prefix which is also suffix (end at last index)\r\n if password >= 0:\r\n for i in range(1, n - 1): \r\n \r\n #In this For Loop We Are Trying to get the substring as per the demand of question \r\n #If it exists we have answer\r\n if pi[i] == password: \r\n print(s[:password+1])\r\n exit()\r\n if pi[password] >= 0: \r\n #If not exists we have to check for \r\n #smaller length of suffix prefix substring \r\n print(s[:pi[password] + 1])\r\n exit()\r\n print(\"Just a legend\") \r\n #if not exists direct answer is JUST A LEGEND \r\n else:\r\n print(\"Just a legend\")", "def kmp_preprocess(s, kmp):\r\n kmp[0] = 0\r\n i = 1\r\n j = 0\r\n while i < len(s):\r\n if s[i] == s[j]:\r\n j += 1\r\n kmp[i] = j\r\n i += 1\r\n else:\r\n if j != 0:\r\n j = kmp[j - 1]\r\n else:\r\n kmp[i] = 0\r\n i += 1\r\n\r\ns = input()\r\nkmp = [None] * len(s)\r\nkmp_preprocess(s, kmp)\r\n\r\n# abcabcabc --> abc is suffix\r\n\r\n# abcdabc --> ab not suffix\r\n\r\n# print(kmp)\r\nres = None\r\nfor i in range(len(s) - 1):\r\n if kmp[i] == kmp[-1]:\r\n res = kmp[-1]\r\n break\r\n\r\nif not res:\r\n if kmp[kmp[-1] - 1] != 0:\r\n res = kmp[kmp[-1] - 1]\r\n\r\nif not res:\r\n print(\"Just a legend\") \r\nelse:\r\n print(s[:res])\r\n ", "txt = input()\nk = -1\nsize = len(txt)\nmatches = [-1] * (size+1)\n\nfor i in range(1, len(txt)):\n while k != -1 and txt[i] != txt[k + 1]:\n k = matches[k]\n if txt[i] == txt[k + 1]:\n k += 1\n matches[i] = k\n else:\n matches[i] = -1\n\nmaxi = matches[size - 1]\nindex_found = matches[maxi]\nif maxi == -1:\n index_found = -1\nfor i in range(1, size - 1):\n if matches[i] == maxi:\n index_found = maxi\nif index_found == -1:\n print('Just a legend')\nelse:\n print(txt[:index_found + 1])\n\n\t \t\t\t\t \t\t \t\t\t \t \t\t \t \t\t", "from sys import stdin, stdout\n\ndef read():\n return stdin.readline().rstrip()\n\ndef solve(s, z):\n maxi = 0\n pos = 0\n for i in range(1, len(s)):\n rev_idx = len(s) - i\n if z[i] == rev_idx and maxi >= rev_idx:\n pos = i\n break\n maxi = max(maxi, z[i])\n else:\n return False\n return s[pos:]\n\ndef zf(s):\n n = len(s)\n z = [0]*n\n L = R = 0\n for i in range(1, n):\n if i <= R:\n z[i] = min(z[i-L], R-i+1)\n while i+z[i] < n and s[i+z[i]] == s[z[i]]:\n z[i] += 1\n if i+z[i]-1 > R:\n L, R = i, i+z[i]-1\n #print(solve(s, z))\n return solve(s, z)\n\npassword = zf(read())\nstdout.write(\"Just a legend\\n\" if not password else password+\"\\n\")\n", "import bisect\r\nimport heapq\r\nimport sys\r\nfrom types import GeneratorType\r\nfrom functools import cmp_to_key\r\nfrom collections import defaultdict, Counter, deque\r\nimport math\r\nfrom functools import lru_cache\r\nfrom heapq import nlargest\r\nimport random\r\n\r\ninf = float(\"inf\")\r\n\r\n\r\nclass FastIO:\r\n def __init__(self):\r\n return\r\n\r\n @staticmethod\r\n def _read():\r\n return sys.stdin.readline().strip()\r\n\r\n def read_int(self):\r\n return int(self._read())\r\n\r\n def read_float(self):\r\n return float(self._read())\r\n\r\n def read_ints(self):\r\n return map(int, self._read().split())\r\n\r\n def read_floats(self):\r\n return map(float, self._read().split())\r\n\r\n def read_ints_minus_one(self):\r\n return map(lambda x: int(x) - 1, self._read().split())\r\n\r\n def read_list_ints(self):\r\n return list(map(int, self._read().split()))\r\n\r\n def read_list_floats(self):\r\n return list(map(float, self._read().split()))\r\n\r\n def read_list_ints_minus_one(self):\r\n return list(map(lambda x: int(x) - 1, self._read().split()))\r\n\r\n def read_str(self):\r\n return self._read()\r\n\r\n def read_list_strs(self):\r\n return self._read().split()\r\n\r\n def read_list_str(self):\r\n return list(self._read())\r\n\r\n @staticmethod\r\n def st(x):\r\n return sys.stdout.write(str(x) + '\\n')\r\n\r\n @staticmethod\r\n def lst(x):\r\n return sys.stdout.write(\" \".join(str(w) for w in x) + '\\n')\r\n\r\n @staticmethod\r\n def round_5(f):\r\n res = int(f)\r\n if f - res >= 0.5:\r\n res += 1\r\n return res\r\n\r\n @staticmethod\r\n def max(a, b):\r\n return a if a > b else b\r\n\r\n @staticmethod\r\n def min(a, b):\r\n return a if a < b else b\r\n\r\n @staticmethod\r\n def bootstrap(f, queue=[]):\r\n def wrappedfunc(*args, **kwargs):\r\n if queue:\r\n return f(*args, **kwargs)\r\n else:\r\n to = f(*args, **kwargs)\r\n while True:\r\n if isinstance(to, GeneratorType):\r\n queue.append(to)\r\n to = next(to)\r\n else:\r\n queue.pop()\r\n if not queue:\r\n break\r\n to = queue[-1].send(to)\r\n return to\r\n return wrappedfunc\r\n\r\n\r\ndef prefix_function(s):\r\n # 计算s[:i]与s[:i]的最长公共真前缀与真后缀\r\n n = len(s)\r\n pi = [0] * n\r\n for i in range(1, n):\r\n j = pi[i - 1]\r\n while j > 0 and s[i] != s[j]:\r\n j = pi[j - 1]\r\n if s[i] == s[j]:\r\n j += 1\r\n pi[i] = j\r\n # pi[0] = 0\r\n return pi\r\n\r\n\r\ndef main(ac=FastIO()):\r\n s = ac.read_str()\r\n pi = prefix_function(s)\r\n n = len(s)\r\n ceil = 0\r\n for i in range(1, n - 1):\r\n if pi[i] < i + 1:\r\n ceil = ac.max(ceil, pi[i])\r\n # print(ceil)\r\n p1, p2 = random.randint(26, 100), random.randint(26, 100)\r\n mod1, mod2 = random.randint(\r\n 10 ** 9 + 7, 2 ** 31 - 1), random.randint(10 ** 9 + 7, 2 ** 31 - 1)\r\n\r\n a1 = a2 = b1 = b2 = 0\r\n x1 = x2 = 1\r\n ans = 0\r\n for i in range(n - 1):\r\n a1 += (ord(s[i]) - ord(\"a\")) * x1\r\n a2 += (ord(s[i]) - ord(\"a\")) * x2\r\n\r\n b1 = b1 * p1 + (ord(s[-i - 1]) - ord(\"a\"))\r\n b2 = b2 * p2 + (ord(s[-i - 1]) - ord(\"a\"))\r\n\r\n a1 %= mod1\r\n a2 %= mod2\r\n b1 %= mod1\r\n b2 %= mod2\r\n\r\n x1 = (x1 * p1) % mod1\r\n x2 = (x2 * p2) % mod2\r\n if (a1, a2) == (b1, b2) and i + 1 <= ceil:\r\n ans = i + 1\r\n if not ans:\r\n ac.st(\"Just a legend\")\r\n else:\r\n ac.st(s[:ans])\r\n return\r\n\r\n\r\nmain()\r\n", "def pf(txt,m,lps):\n\tl = 0\n\tlps[0] = 0\n\ti = 1\n\twhile i<m:\n\t\tif txt[i]==txt[l]:\n\t\t\tl+=1\n\t\t\tlps[i] = l\n\t\t\ti += 1\n\t\telse:\n\t\t\tif l!=0:\n\t\t\t\tl = lps[l-1]\n\t\t\telse:\n\t\t\t\tlps[i] = 0\n\t\t\t\ti += 1\n\ns = input()\n_len = len(s)\nif _len==1 or _len==2:\n\tprint(\"Just a legend\")\n\texit(0)\nlps = [0]*_len\npf(s,_len,lps)\nval = lps[-1]\nif val==0:\n\tprint(\"Just a legend\")\nelif val in lps[:-1]:\n\tprint(s[:val])\nelif lps[val-1]==0:\n\tprint(\"Just a legend\")\nelif lps[val-1]:\n\tprint(s[:lps[val-1]])\nelse:\n\tprint(\"Just a legend\")\n", "import sys\r\nimport random\r\nimport bisect\r\nfrom collections import deque\r\n#sys.setrecursionlimit(10**6)\r\nfrom queue import PriorityQueue\r\nfrom math import gcd\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\nmod = 10**9 + 7\r\n\r\ndef zfunc(s) :\r\n n = len(s)\r\n z = [0 for i in range(n)]\r\n\r\n l = 0\r\n r = 0\r\n\r\n for i in range (1,n) :\r\n if (i<=r) :\r\n z[i] = min(r-i+1, z[i-l])\r\n\r\n while (i+z[i] < n) and (s[z[i]] == s[i + z[i]]) :\r\n z[i] += 1\r\n\r\n if (i+z[i]-1 > r) :\r\n l = i\r\n r = i+z[i]-1\r\n\r\n return z\r\n\r\ns = ip()\r\nn = len(s)\r\n\r\nmn = zfunc(s)\r\n\r\n#print(mn)\r\n\r\nx1 = -1\r\n\r\nfor i in range (1,n) :\r\n if (i + mn[i]) == n :\r\n if (x1 >= mn[i]) :\r\n print(s[i:])\r\n exit(0)\r\n x1 = max(x1,mn[i])\r\n\r\nprint(\"Just a legend\")\r\n", "s = input()\r\nn = len(s)\r\np = [0] * (n + 1)\r\ni, j = 0, 1\r\nwhile j < n:\r\n if s[j] == s[i]:\r\n j += 1\r\n i += 1\r\n p[j] = i\r\n elif i:\r\n i = p[i]\r\n else:\r\n j += 1\r\na = p.pop()\r\nb = p[a]\r\nprint(s[:a]\r\n if a and a in p\r\n else s[:b] if b else 'Just a legend'\r\n )\r\n", "import os, sys, io, array\r\n#sys.stdin = io.StringIO(os.read(0, os.fstat(0).st_size).decode())\r\ninput = sys.stdin.readline\r\n\r\ns = input().rstrip()\r\n\r\nLPS = array.array('i', [0])* len(s)\r\nk = 0\r\n\r\nfor i in range(1, len(s)):\r\n while s[i] != s[k] and k:\r\n k = LPS[k-1]\r\n \r\n k += s[i] == s[k]\r\n \r\n LPS[i] = k\r\n \r\nlen_boundary = LPS[-1]\r\n\r\nif len_boundary == 0:\r\n print(\"Just a legend\")\r\n exit(0)\r\n \r\nfor n in LPS[:-1]:\r\n if n == len_boundary:\r\n print(s[:len_boundary])\r\n exit(0)\r\n\r\nif LPS[len_boundary-1] == 0:\r\n print(\"Just a legend\")\r\n exit(0)\r\n\r\nprint(s[:LPS[len_boundary-1]])", "from collections import Counter\r\nimport sys\r\ndef alele(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef ilele(): return map(int, sys.stdin.readline().strip().split())\r\ndef input(): return sys.stdin.readline().strip()\r\ndef computeLPSArray(pat, M, lps): \r\n len = 0\r\n lps[0] \r\n i = 1\r\n while i < M: \r\n if pat[i]== pat[len]: \r\n len += 1\r\n lps[i] = len\r\n i += 1\r\n else: \r\n if len != 0: \r\n len = lps[len-1] \r\n else: \r\n lps[i] = 0\r\n i += 1\r\ntext=input();n=len(text);lps=[0]*n;computeLPSArray(text,n,lps)#;print(lps)\r\nt=lps[-1]\r\nif lps.count(t)<2:\r\n t=lps[t-1]\r\nprint(text[:t] if t>0 else 'Just a legend')\r\n\r\n", "def LPS(pat): \r\n\tM = len(pat) \r\n\tj = 0\r\n\tlps = [0 for i in range(M)]\r\n\ti = 1\r\n\twhile i < M: \r\n\t\tif pat[i]== pat[j]: \r\n\t\t\tj += 1\r\n\t\t\tlps[i] = j\r\n\t\t\ti += 1\r\n\t\telse: \r\n\t\t\tif j != 0: \r\n\t\t\t\tj = lps[j-1]\r\n\t\t\telse: \r\n\t\t\t\tlps[i] = 0\r\n\t\t\t\ti += 1\r\n\treturn lps\r\ns = input()\r\nlps = LPS(s)\r\nans = lps[-1]\r\nct = 0\r\nfor i in range(len(s)):\r\n\tif(lps[i] == ans):\r\n\t\tct += 1\r\nif(ct < 2):\r\n\tans = lps[ans-1]\r\nif(ans > 0):\r\n\tprint(s[:ans])\r\nelse:\r\n\tprint(\"Just a legend\")", "# ---------------------------iye ha aam zindegi---------------------------------------------\r\nfrom calendar import c\r\nfrom cmath import inf\r\nfrom math import ceil, gcd, sqrt, log2\r\nimport os\r\nfrom re import I, M\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\nfrom collections import Counter, defaultdict, deque\r\nfrom heapq import heappush, heappop, heapify\r\nfrom collections import defaultdict\r\nfrom turtle import update\r\n \r\n \r\nmod = 10 ** 9 + 7\r\nmod1 = 998244353\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\ndef lcm(a, b):\r\n return a*b//gcd(a, b)\r\n \r\n \r\n# -------------------game starts now----------------------------------------------------\r\ns = input()\r\nk=-1\r\nl=[-1]\r\nfor c in s:\r\n while k!=-1 and s[k]!=c:\r\n k=l[k]\r\n k+=1\r\n l+=[k]\r\nq=l[-1]\r\nif l.count(q)<2:\r\n q=l[q]\r\nprint(s[:q] if q>0 else \"Just a legend\")\r\n", "def kmpTable(s, n):\r\n res = [0]*n\r\n check_idx = 0\r\n for i in range(1, n):\r\n while check_idx > 0 and s[check_idx] != s[i]:\r\n check_idx = res[check_idx-1]\r\n if s[check_idx] == s[i]:\r\n check_idx += 1\r\n res[i] = check_idx\r\n return res\r\n\r\ns = input()\r\nn = len(s)\r\nkmp_table = kmpTable(s, n)\r\npsize = kmp_table[n-1]\r\nif psize > 0 and psize in kmp_table[:-1]:\r\n print(s[:psize])\r\nelse:\r\n\tpsize = kmp_table[psize-1]\r\n\tif psize > 0 and psize in kmp_table[:-1]:\r\n\t\tprint(s[:psize])\r\n\telse:\r\n\t\tprint(\"Just a legend\")\r\n", "def computeLPSArray(pat, M, lps):\r\n\tlen = 0\r\n\r\n\tlps[0]\r\n\ti = 1\r\n\r\n\twhile i < M:\r\n\t\tif pat[i]== pat[len]:\r\n\t\t\tlen += 1\r\n\t\t\tlps[i] = len\r\n\t\t\ti += 1\r\n\t\telse:\r\n\t\t\tif len != 0:\r\n\t\t\t\tlen = lps[len-1]\r\n\t\t\telse:\r\n\t\t\t\tlps[i] = 0\r\n\t\t\t\ti += 1\r\n\treturn lps\r\n\r\ns=input()\r\nm=len(s)\r\nlps=[0]*m\r\nx=computeLPSArray(s, m, lps)\r\n\r\nx=[0]+x\r\na=x[-1]\r\nb=x[a]\r\nans=\"\"\r\n\r\nfor i in range(len(x)):\r\n if x[i]==a and i!=m:\r\n ans=s[0:a]\r\n\r\nif ans==\"\":\r\n if b!=0:\r\n ans=s[0:b]\r\n else:\r\n ans=\"Just a legend\"\r\n\r\nprint(ans)", "import sys\r\ninput=sys.stdin.readline\r\nfrom itertools import permutations, accumulate\r\nfrom collections import defaultdict as dd\r\nfrom collections import deque\r\nfrom bisect import bisect_left,bisect_right\r\nfrom math import lcm,gcd,sqrt,ceil,comb\r\nfrom heapq import heappop,heappush,heapify\r\ntoBin=lambda x:bin(x).replace(\"0b\",\"\")\r\ninf=float(\"inf\");DIRS=[[1,0],[-1,0],[0,1],[0,-1]];CHARS=\"abcdefghijklmnopqrstuvwxyz\"\r\nMOD=10**9+7;N=300010;fac=[1]*N;invfac=[1]*N #Fill out N to calculate combinations\r\nfor i in range(2,N):fac[i]=fac[i-1]*i%MOD\r\ninvfac[N-1]=pow(fac[N-1],MOD-2,MOD)\r\nfor i in range(N-1)[::-1]:invfac[i]=invfac[i+1]*(i+1)%MOD\r\ndef c(i,j):return 0 if i<j else fac[i]*invfac[j]*invfac[i-j]\r\n\r\ndef z_function(s):\r\n n=len(s);z=[0]*n;l=0;r=0\r\n for i in range(1,n):\r\n if i<r:z[i]=min(r-i,z[i-l])\r\n while (i+z[i])<n and s[z[i]]==s[i+z[i]]:z[i]+=1\r\n if i+z[i]>r:l=i;r=i+z[i]\r\n return z\r\ndef lps(s):\r\n i=-1;L=[-1]\r\n for ch in s:\r\n while i!=-1 and s[i]!=ch:i=L[i]\r\n i+=1\r\n L.append(i)\r\n return L\r\n\r\ndef solve():\r\n s=str(input()).strip();n=len(s)\r\n L=lps(s)\r\n res=L[-1]\r\n if L.count(res)<2:res=L[res]\r\n print(s[:res] if res>0 else \"Just a legend\")\r\n\r\nif __name__==\"__main__\":\r\n solve()", "def solve():\r\n p = input().strip()\r\n\r\n n = len(p)\r\n p = \" \" + p\r\n ne = [0] * (n + 1)\r\n exist = [False] * (n + 1)\r\n j = 0\r\n\r\n for i in range(2, n + 1):\r\n while j and p[i] != p[j + 1]:\r\n j = ne[j]\r\n \r\n if p[i] == p[j + 1]:\r\n j += 1\r\n ne[i] = j\r\n\r\n if i < n:\r\n exist[ne[i]] = True\r\n\r\n ans = 0\r\n i = ne[n]\r\n while i:\r\n if exist[i]:\r\n ans = i\r\n break\r\n i = ne[i]\r\n\r\n if ans == 0:\r\n print(\"Just a legend\")\r\n else:\r\n print(p[1:ans + 1])\r\n\r\ndef main():\r\n t = 1\r\n while t:\r\n solve()\r\n t -= 1\r\n\r\nif __name__ == \"__main__\":\r\n main()", "def Z(s):\n n=len(s)\n z=[0 for i in range(n)]\n l,r=0,0\n for i in range(1,n):\n if i>r:\n l=r=i\n while r<n and s[r-l]==s[r]:\n r+=1\n z[i]=r-l\n r-=1\n else:\n k=i-l\n if z[k]<r-i+1:\n z[i]=z[k]\n else:\n l=i\n while r<n and s[r-l]==s[r]:\n r+=1\n z[i]=r-l\n r-=1\n return z\n\ns=input()\nn=len(s)\nz=Z(s)\nm=max(z)\ne=-float(\"inf\")\ncount={i:0 for i in z}\nfor i in range(1,n):\n if z[i]==n-i:\n if z[i]<m or (z[i]==m and count[z[i]]>0):\n e=max(z[i],e)\n count[z[i]]+=1 \n \nif e!=-float(\"inf\"):\n print(s[-e:])\nelse:\n print(\"Just a legend\")\n\n \n", "def Z(s):\r\n n = len(s)\r\n z = [0 for i in range(n)]\r\n l,r = 0,0\r\n for i in range(1,n):\r\n if i>r:\r\n l=r= i\r\n while r < n and s[r-l] == s[r]:\r\n r += 1\r\n z[i] = r-l\r\n r -= 1\r\n else:\r\n k = i-l\r\n if z[k] < r-i+1:\r\n z[i] = z[k]\r\n else:\r\n l = i\r\n while r < n and s[r-l] == s[r]:\r\n r += 1\r\n z[i] = r-l\r\n r -= 1\r\n return z\r\n\r\ns = str(input())\r\nz = Z(s)\r\nm = max(z)\r\nn = len(s)\r\ncount = {i:0 for i in range(n)}\r\ne = -float('inf')\r\nfor i in range(1,n):\r\n if z[i] == n-i:\r\n if z[i] < m or (z[i] == m and count[z[i]] > 0):\r\n e = max(z[i],e)\r\n count[z[i]] += 1\r\n\r\nif e != -float('inf'):\r\n print(s[-e:])\r\nelse:\r\n print(\"Just a legend\")", "import sys\r\ninput=sys.stdin.readline\r\nfrom itertools import permutations, accumulate\r\nfrom collections import defaultdict as dd\r\nfrom collections import deque\r\nfrom bisect import bisect_left,bisect_right\r\nfrom math import lcm,gcd,sqrt,ceil,comb\r\nfrom heapq import heappop,heappush,heapify\r\ntoBin=lambda x:bin(x).replace(\"0b\",\"\")\r\ninf=float(\"inf\");DIRS=[[1,0],[-1,0],[0,1],[0,-1]];CHARS=\"abcdefghijklmnopqrstuvwxyz\"\r\nMOD=10**9+7;N=300010;fac=[1]*N;invfac=[1]*N #Fill out N to calculate combinations\r\nfor i in range(2,N):fac[i]=fac[i-1]*i%MOD\r\ninvfac[N-1]=pow(fac[N-1],MOD-2,MOD)\r\nfor i in range(N-1)[::-1]:invfac[i]=invfac[i+1]*(i+1)%MOD\r\ndef c(i,j):return 0 if i<j else fac[i]*invfac[j]*invfac[i-j]\r\n\r\ndef z_function(s):\r\n n=len(s);z=[0]*n;l=0;r=0\r\n for i in range(1,n):\r\n if i<r:z[i]=min(r-i,z[i-l])\r\n while (i+z[i])<n and s[z[i]]==s[i+z[i]]:z[i]+=1\r\n if i+z[i]>r:l=i;r=i+z[i]\r\n return z\r\n\r\ndef solve():\r\n s=str(input()).strip();n=len(s);mx=0;res=None\r\n z=z_function(s)\r\n for i in range(1,n):\r\n if z[i]==n-i and mx>=n-i:\r\n res=s[i:]\r\n break\r\n mx=max(mx,z[i])\r\n print(res if res else \"Just a legend\")\r\n\r\nif __name__==\"__main__\":\r\n solve()", "def kmp_prefix_arr(arr):\r\n ii = 1\r\n jj = 0\r\n n = len(arr)\r\n pre_kmp = [0] * n\r\n while ii < n:\r\n if arr[ii] != arr[jj]:\r\n if jj != 0:\r\n jj = pre_kmp[jj - 1]\r\n else:\r\n ii += 1\r\n else:\r\n pre_kmp[ii] = jj + 1\r\n ii += 1\r\n jj += 1\r\n return pre_kmp\r\n \r\n \r\ns = input()\r\nn = len(s)\r\ntemp = []\r\nif n < 3:\r\n print(\"Just a legend\")\r\nelse:\r\n pi = kmp_prefix_arr(s)\r\n pi = [item - 1 for item in pi]\r\n password = pi[-1]\r\n if password >= 0:\r\n for i in range(1, n - 1):\r\n if pi[i] == password:\r\n print(s[:password+1])\r\n exit()\r\n if pi[password] >= 0:\r\n print(s[:pi[password] + 1])\r\n exit()\r\n print(\"Just a legend\")\r\n else:\r\n print(\"Just a legend\")", "s = input()\n\n#manter a ideia mas usar KMP aula antiga RAPIDAO\ndef calcular_funcao(s):\n j = -1\n tamanho = len(s)\n deu = [-1] * (tamanho + 1)\n\n for i in range(1, tamanho):\n while j != -1 and s[i] != s[j + 1]:\n j = deu[j]\n if s[i] == s[j + 1]:\n j += 1\n deu[i] = j\n else:\n deu[i] = -1\n return deu\n\n#acha o maior\ndef encontrar_maior(s):\n deu = calcular_funcao(s)\n m = deu[len(s) - 1]\n if m != -1:\n fIDX = deu[m]\n else:\n fIDX = -1\n\n for i in range(1, len(s) - 1):\n if deu[i] == m:\n fIDX = m\n\n return fIDX\n\nfIDX = encontrar_maior(s)\n\nif fIDX == -1:\n print(\"Just a legend\")\nelse:\n f = s[:fIDX + 1]\n print(f)\n\n\n\n\t\t\t \t \t \t \t \t \t\t\t\t\t", "from typing import Tuple\r\n\r\n\r\ndef comp_z(s: str) -> Tuple[int]:\r\n \"\"\"Computes the z-array for a given string s.\r\n\r\n z[i] := the length of the longest substring of s, starting at index i, which is also a prefix of s.\r\n 0 <= i < len(s); z[0] = len(s).\r\n \"\"\"\r\n\r\n n = len(s)\r\n z = [0] * n\r\n z[0] = n\r\n # left and right boundaries of the current right most z-box [L,R)\r\n L, R = 0, 0\r\n\r\n for i in range(1, n):\r\n if i >= R:\r\n L = i\r\n R = i\r\n while R < n and s[R] == s[R-L]:\r\n R += 1\r\n z[i] = R-L\r\n else: # L < i < R\r\n # len of [i,R)\r\n x = R-i\r\n if x > z[i-L]:\r\n z[i] = z[i-L]\r\n else: # x <= z[i-L] and we know s[i..R) matches prefix\r\n L = i\r\n # continue matching from R onwards\r\n while R < n and s[R] == s[R-L]:\r\n R += 1\r\n z[i] = R-L\r\n\r\n return tuple(z)\r\n\r\n\r\ndef run():\r\n \"\"\"Solves https://codeforces.com/contest/126/problem/B.\"\"\"\r\n s = input()\r\n n = len(s)\r\n z = comp_z(s)\r\n\r\n maxz = 0\r\n res = 0\r\n for i in range(1, n):\r\n if z[i] == n-i and maxz >= n-i:\r\n res = n-i\r\n # break as we already found the longest one;\r\n # as i increases, the length decreases\r\n break\r\n maxz = max(maxz, z[i])\r\n\r\n if res == 0:\r\n print('Just a legend')\r\n else:\r\n print(s[:res])\r\n\r\n\r\nif __name__ == \"__main__\":\r\n run()\r\n", "def main():\n s, j, l = input(), -1, [-1]\n for c in s:\n while j != -1 and c != s[j]:\n j = l[j]\n j += 1\n l.append(j)\n le = l[-1]\n if l.count(le) < 2:\n le = l[le]\n print(s[:le] if le > 0 else \"Just a legend\")\n\n\nif __name__ == '__main__':\n main()\n", "from sys import stdin,stdout,stderr\r\ndef lcp(string):\r\n l=len(string)\r\n lis=[0]*l\r\n j=1\r\n k=0\r\n while j<l:\r\n if string[j]==string[k]:\r\n lis[j]=k+1\r\n j+=1\r\n k+=1\r\n elif k>0:\r\n k=lis[k-1]\r\n else :j+=1\r\n return lis\r\nstring=input()\r\n\r\nlis=lcp(string)\r\n\r\nif lis[-1]==0:\r\n print(\"Just a legend\")\r\n exit()\r\nfor i in range(len(string)-1):\r\n if lis[i]!=0 and lis[i]==lis[-1]:\r\n print(string[:lis[-1]])\r\n exit()\r\nl=lis[-1]\r\nif l==0:\r\n print(\"Just a legend\")\r\n exit()\r\nl=lis[lis[-1]-1]\r\nif l:\r\n print(string[:l])\r\n exit()\r\nprint(\"Just a legend\")\r\n", "def solve(s):\r\n n = len(s)\r\n dp = [0] * n\r\n\r\n for i in range(1, n):\r\n j = dp[i - 1]\r\n while j > 0 and s[i] != s[j]:\r\n j = dp[j - 1]\r\n if s[i] == s[j]:\r\n dp[i] = j + 1\r\n\r\n length = dp[n - 1]\r\n if length == 0:\r\n return \"Just a legend\"\r\n\r\n for i in range(1, n - 1):\r\n if dp[i] == length:\r\n return s[:length]\r\n\r\n length = dp[length - 1]\r\n if length == 0:\r\n return \"Just a legend\"\r\n\r\n return s[:length]\r\n\r\n\r\ns = input()\r\nprint(solve(s))\r\n", "s = input()\nk = -1\nl = [-1]\nfor c in s:\n #print(k)\n #print(s[k])\n while(k!=-1)and(s[k]!=c):\n k=l[k]\n k+=1\n l.append(k)\n #print(l)\nle=l[-1]\n#print(le)\nif l.count(le)<2:\n le=l[le]\nprint(s[:le] if le>0 else 'Just a legend')\n\t \t \t \t\t \t \t \t\t\t\t \t\t\t\t\t", "inputString = input()\nlengthInputString = len(inputString)\nmyList = [0] * lengthInputString\nsuccessorIdx = 1\npredecessorIdx = 0\nwhile successorIdx < lengthInputString:\n if inputString[successorIdx] == inputString[predecessorIdx]:\n myList[successorIdx] = predecessorIdx + 1\n successorIdx += 1\n predecessorIdx += 1\n elif predecessorIdx > 0:\n predecessorIdx = myList[predecessorIdx - 1]\n else:\n successorIdx += 1\naux = myList.pop()\nif aux:\n if aux in myList:\n print(inputString[:aux])\n elif myList[aux - 1]:\n print(inputString[:myList[aux - 1]])\n else:\n print('Just a legend')\nelse:\n print('Just a legend')\n\t\t\t\t \t\t \t\t\t\t \t\t \t \t", "s = input()\r\nn = len(s)\r\np = [0]*(n+1)\r\nmark = [False]*(n+1)\r\nj = 0\r\n\r\nfor i in range(1,n):\r\n \r\n while(j>0 and s[i]!=s[j]):\r\n j = p[j-1]\r\n \r\n if(s[i] == s[j]):\r\n j += 1\r\n \r\n p[i] = j\r\n \r\n if(i < n-1):\r\n mark[j] = True\r\n \r\nj = p[n-1]\r\n\r\nwhile(j > 0 and mark[j]!=True):\r\n j = p[j-1]\r\n\r\nprint(s[0:j] if j>0 else \"Just a legend\")", "def compute_lps_array(s):\n n = len(s)\n lps = [0] * n\n length = 0\n i = 1\n\n while i < n:\n if s[i] == s[length]:\n length += 1\n lps[i] = length\n i += 1\n else:\n if length != 0:\n length = lps[length - 1]\n else:\n lps[i] = 0\n i += 1\n\n return lps\n\ndef find_longest_substring(s):\n n = len(s)\n lps = compute_lps_array(s)\n length = lps[n - 1]\n\n if length == 0:\n print(\"Just a legend\")\n else:\n for i in range(1, n - 1):\n if lps[i] == length:\n print(s[:length])\n return\n\n if lps[length - 1] != 0:\n length = lps[length - 1]\n print(s[:length])\n else:\n print(\"Just a legend\")\n\ninput_string = input().strip()\n\nfind_longest_substring(input_string)\n\n \t \t \t\t \t \t\t \t\t \t \t\t\t\t \t", "def compute_KMP_fail(P):\r\n m = len(P)\r\n fail = [0]*m\r\n i = 1\r\n j = 0\r\n while i<m:\r\n if P[i] == P[j]:\r\n fail[i] = j+1\r\n i += 1\r\n j += 1\r\n elif j>0:\r\n j = fail[j-1]\r\n else:\r\n fail[i] = 0\r\n i += 1\r\n return fail\r\n\r\ns = str(input())\r\nF = compute_KMP_fail(s)\r\nif F[-1] == 0:\r\n print('Just a legend')\r\nelse:\r\n for i in range(0,len(s)-1):\r\n if F[i] == F[-1]:\r\n print(s[0:F[-1]])\r\n exit()\r\n else:\r\n if F[F[-1]-1]>0:\r\n print(s[0:F[F[-1]-1]])\r\n else:\r\n print('Just a legend')" ]
{"inputs": ["fixprefixsuffix", "abcdabc", "qwertyqwertyqwerty", "papapapap", "aaaaaaaaaa", "ghbdtn", "a", "aa", "ab", "aaa", "aba", "aab", "abb", "abc", "aaabaabaaaaab", "aabaaabaaaaab", "aaabaaaabab", "abcabcabcabcabc", "aaaaabaaaa", "aaaabaaaaaaa", "ghghghgxghghghg", "kincenvizh", "amcksgurlgqzqizdauqminfzshiweejkevbazyzylrrghumnvqeqqdedyopgtvxakqwpvxntxgrkrcxabhrgoxngrwrxrvcguuyw", "kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx", "nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb", "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpmvbxbyszdugvmoyjeeqsywcvuqskcjotyhvdijyslgfvyujxthngnonasgnbzzygyikheelirdfsvuicbiazfdeqecbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgpccdtdteohtjjuicfjfcbzpynlqhecyqqrjpmexgfqywnfmusldgzvgnzdmuuujtkdfnlytzgstquwqpuccxbtbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp", "abcazabca"], "outputs": ["fix", "Just a legend", "qwerty", "papap", "aaaaaaaa", "Just a legend", "Just a legend", "Just a legend", "Just a legend", "a", "Just a legend", "Just a legend", "Just a legend", "Just a legend", "Just a legend", "aab", "Just a legend", "abcabcabc", "aaaa", "aaaa", "ghghg", "Just a legend", "Just a legend", "Just a legend", "nfbdzgdlbjhrlvfryyjb", "btbdpnzdenxueteteytvkwnegodyhmdwhmrmbftrifytzudumzlacwytsuzefqfpjesdblxhpcsidgksisjdmhyxmmugrjmtfcgxmcgp", "a"]}
UNKNOWN
PYTHON3
CODEFORCES
115
1470983329ca5e3a2c6705a82cd173d6
List Of Integers
Let's denote as *L*(*x*,<=*p*) an infinite sequence of integers *y* such that *gcd*(*p*,<=*y*)<==<=1 and *y*<=&gt;<=*x* (where *gcd* is the greatest common divisor of two integer numbers), sorted in ascending order. The elements of *L*(*x*,<=*p*) are 1-indexed; for example, 9, 13 and 15 are the first, the second and the third elements of *L*(7,<=22), respectively. You have to process *t* queries. Each query is denoted by three integers *x*, *p* and *k*, and the answer to this query is *k*-th element of *L*(*x*,<=*p*). The first line contains one integer *t* (1<=≤<=*t*<=≤<=30000) — the number of queries to process. Then *t* lines follow. *i*-th line contains three integers *x*, *p* and *k* for *i*-th query (1<=≤<=*x*,<=*p*,<=*k*<=≤<=106). Print *t* integers, where *i*-th integer is the answer to *i*-th query. Sample Input 3 7 22 1 7 22 2 7 22 3 5 42 42 42 43 43 43 44 44 44 45 45 45 46 46 46 Sample Output 9 13 15 187 87 139 128 141
[ "from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nm=10**6+10\r\ndivs=[[1] for i in range(m)]\r\n\r\np=list(range(m))\r\np2=[1]*m\r\nmebius=[0]*m\r\nmebius[1]=1\r\nfor i in range(2,m):\r\n if p[i]==i:\r\n for j in range(i,m,i):\r\n p2[j]=i\r\n for j in range(i*i,m,i):\r\n p[j]=i\r\n for j in range(i*i,m,i*i):\r\n p[j]=0\r\n if p[i]!=0:\r\n mebius[i]=-mebius[i//p[i]]\r\n\r\ndef make_div(n):\r\n now=[1]\r\n x=n\r\n while x!=1:\r\n q=p2[x]\r\n e=0\r\n while x%q==0:\r\n e+=1\r\n x//=q\r\n e=min(e,2)\r\n nxt=[]\r\n for i in now:\r\n for j in range(e+1):\r\n nxt.append(i*(q**j))\r\n now=nxt\r\n return now\r\n\r\ndef count(y,x_div):\r\n # i<=y and gcd(x,i)=1\r\n res=0\r\n for i in x_div:\r\n res+=mebius[i]*(y//i)\r\n return res\r\n\r\nfor _ in range(int(input())):\r\n x,p,k=map(int,input().split())\r\n div=make_div(p)\r\n c=count(x,div)\r\n ng,ok=x,10**7\r\n while ok-ng>1:\r\n mid=(ok+ng)//2\r\n if count(mid,div)-c>=k:\r\n ok=mid\r\n else:\r\n ng=mid\r\n print(ok)", "from __future__ import division, print_function\r\ndef main():\r\n prime_factors = [[] for _ in range(10**6 + 1)]\r\n primes=[True for i in range(10**6+1)]\r\n def generate_primes(n):\r\n \r\n for p in range(2,n+1):\r\n if primes[p]:\r\n prime_factors[p].append(p)\r\n for i in range(2 * p,n+1,p):\r\n primes[i] = False\r\n prime_factors[i].append(p)\r\n generate_primes(10**6)\r\n result = []\r\n for _ in range(int(input())):\r\n x, p, k = map(int, input().split())\r\n arr = prime_factors[p]\r\n to_add = []\r\n to_subtract = []\r\n for i in range(1, 1 << len(arr)):\r\n mul = 1\r\n count = 0\r\n for j in range(len(arr)):\r\n if (1 << j) & i:\r\n count += 1\r\n mul *= arr[j]\r\n \r\n if count%2:\r\n to_add.append(mul)\r\n else:\r\n to_subtract.append(mul)\r\n count_before = 0\r\n for num in to_add:\r\n count_before += x//num\r\n \r\n for num in to_subtract:\r\n count_before -= x//num\r\n \r\n k += (x - count_before)\r\n \r\n low = 0\r\n high = 10**9\r\n answer = high\r\n while low <= high:\r\n mid = (high + low)//2\r\n temp_count = 0\r\n for num in to_add:\r\n temp_count += mid // num\r\n for num in to_subtract:\r\n temp_count -= mid // num\r\n temp_count = mid - temp_count\r\n if temp_count >= k:\r\n answer = min(answer, mid)\r\n high = mid - 1\r\n else:\r\n low = mid + 1\r\n result.append(answer)\r\n \r\n print(*result, sep = \"\\n\")\r\n\r\n######## Python 2 and 3 footer by Pajenegod and c1729\r\n\r\n# Note because cf runs old PyPy3 version which doesn't have the sped up\r\n# unicode strings, PyPy3 strings will many times be slower than pypy2.\r\n# There is a way to get around this by using binary strings in PyPy3\r\n# but its syntax is different which makes it kind of a mess to use.\r\n\r\n# So on cf, use PyPy2 for best string performance.\r\n\r\npy2 = round(0.5)\r\nif py2:\r\n from future_builtins import ascii, filter, hex, map, oct, zip\r\n range = xrange\r\n\r\nimport os, sys\r\nfrom io import IOBase, BytesIO\r\n\r\nBUFSIZE = 8192\r\nclass FastIO(BytesIO):\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.writable = \"x\" in file.mode or \"w\" in file.mode\r\n self.write = super(FastIO, self).write if self.writable else None\r\n\r\n def _fill(self):\r\n s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])\r\n return s\r\n\r\n def read(self):\r\n while self._fill(): pass\r\n return super(FastIO,self).read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n s = self._fill(); self.newlines = s.count(b\"\\n\") + (not s)\r\n self.newlines -= 1\r\n return super(FastIO, self).readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.getvalue())\r\n self.truncate(0), self.seek(0)\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 if py2:\r\n self.write = self.buffer.write\r\n self.read = self.buffer.read\r\n self.readline = self.buffer.readline\r\n else:\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# Cout implemented in Python\r\nimport sys\r\nclass ostream:\r\n def __lshift__(self,a):\r\n sys.stdout.write(str(a))\r\n return self\r\ncout = ostream()\r\nendl = '\\n'\r\n\r\n# Read all remaining integers in stdin, type is given by optional argument, this is fast\r\ndef readnumbers(zero = 0):\r\n conv = ord if py2 else lambda x:x\r\n A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read()\r\n try:\r\n while True:\r\n if s[i] >= b'0' [0]:\r\n numb = 10 * numb + conv(s[i]) - 48\r\n elif s[i] == b'-' [0]: sign = -1\r\n elif s[i] != b'\\r' [0]:\r\n A.append(sign*numb)\r\n numb = zero; sign = 1\r\n i += 1\r\n except:pass\r\n if s and s[-1] >= b'0' [0]:\r\n A.append(sign*numb)\r\n return A\r\n\r\nif __name__== \"__main__\":\r\n main()", "from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nm=10**6+10\r\nuse=[0]*m\r\nquery=[]\r\nfor _ in range(int(input())):\r\n x,p,k=map(int,input().split())\r\n query.append((x,p,k))\r\n use[p]=1\r\n \r\ndivs=[[] for i in range(m)]\r\np=list(range(m))\r\nmebius=[0]*m\r\nmebius[1]=1\r\nfor i in range(2,m):\r\n if p[i]==i:\r\n for j in range(i*i,m,i):\r\n p[j]=i\r\n for j in range(i*i,m,i*i):\r\n p[j]=0\r\n if p[i]!=0:\r\n mebius[i]=-mebius[i//p[i]]\r\n for j in range(i,m,i):\r\n if use[j]:\r\n divs[j].append(i)\r\n\r\n\r\ndef count(y,x_div):\r\n # i<=y and gcd(x,i)=1\r\n res=y\r\n for i in x_div:\r\n res+=mebius[i]*(y//i)\r\n return res\r\n\r\nfor x,p,k in query:\r\n div=divs[p]\r\n c=count(x,div)\r\n ng,ok=x,10**7\r\n while ok-ng>1:\r\n mid=(ok+ng)//2\r\n if count(mid,div)-c>=k:\r\n ok=mid\r\n else:\r\n ng=mid\r\n print(ok)" ]
{"inputs": ["3\n7 22 1\n7 22 2\n7 22 3", "5\n42 42 42\n43 43 43\n44 44 44\n45 45 45\n46 46 46"], "outputs": ["9\n13\n15", "187\n87\n139\n128\n141"]}
UNKNOWN
PYTHON3
CODEFORCES
3
1478c482a3296de529bb34c0e7e351e4
Ithea Plays With Chtholly
This is an interactive problem. Refer to the Interaction section below for better understanding. Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight. Initially, Ithea puts *n* clear sheets of paper in a line. They are numbered from 1 to *n* from left to right. This game will go on for *m* rounds. In each round, Ithea will give Chtholly an integer between 1 and *c*, and Chtholly needs to choose one of the sheets to write down this number (if there is already a number before, she will erase the original one and replace it with the new one). Chtholly wins if, at any time, all the sheets are filled with a number and the *n* numbers are in non-decreasing order looking from left to right from sheet 1 to sheet *n*, and if after *m* rounds she still doesn't win, she loses the game. Chtholly really wants to win the game as she wants to cook something for Willem. But she doesn't know how to win the game. So Chtholly finds you, and your task is to write a program to receive numbers that Ithea gives Chtholly and help her make the decision on which sheet of paper write this number. The first line contains 3 integers *n*,<=*m* and *c* (, means rounded up) — the number of sheets, the number of rounds and the largest possible number Ithea can give to Chtholly respectively. The remaining parts of input are given throughout the interaction process. none Sample Input 2 4 4 2 1 3 Sample Output 1 2 2
[ "import sys\n\nn, m, c=map(int, input().split())\na=[]\nfor i in range(n+1):\n a.append(0)\ncnt=0\nwhile cnt<n:\n i=0\n x=int(input())\n if x*2<=c:\n i=1\n while a[i] and a[i]<=x:\n i+=1\n else:\n i=n\n while a[i] and a[i]>=x:\n i-=1\n if a[i]==0:\n cnt+=1\n a[i]=x\n print(i)\n sys.stdout.flush()\n \n", "import sys\r\nN, M, C = map(int,input().split())\r\nans = [0] * (N+1)\r\n# ls, le = 1, N+1\r\n# rs, re = N//2+1, N+1\r\nfor _ in range(M):\r\n p = int(input())\r\n ii = -1\r\n if p < C//2+1:\r\n for i in range(1, N+1):\r\n if ans[i] == 0 or ans[i] > p:\r\n ii = i\r\n break\r\n else:\r\n for i in range(N, 0, -1):\r\n if ans[i] == 0 or ans[i] < p:\r\n ii = i\r\n break\r\n ans[ii] = p\r\n print(ii)\r\n sys.stdout.flush()\r\n if all(x > 0 for x in ans[1:]):\r\n exit(0)", "import sys\r\n\r\nn,m,c=map(int,sys.stdin.readline().split())\r\nsheets = [None]*n\r\n\r\nmid = (c+1)//2\r\ndone=False\r\n\r\nwhile m:\r\n number=int(sys.stdin.readline())\r\n \r\n if number<=mid:\r\n for i in range(n):\r\n if sheets[i] is None or sheets[i]>number:\r\n print(i+1)\r\n sys.stdout.flush()\r\n sheets[i]=number\r\n break\r\n else:\r\n for i in range(n-1,-1,-1):\r\n if sheets[i] is None or sheets[i]<number:\r\n print(i+1)\r\n sys.stdout.flush()\r\n sheets[i]=number\r\n break\r\n if all(x is not None for x in sheets):\r\n break", "def main():\n n, m, c = map(int, input().split())\n middle = ((c + 1) // 2) * 2 + 1\n xs = [middle for _ in range(n)]\n\n def value(a, b):\n # moving from a to b. What is the value of that?\n if a > middle:\n return b - a\n elif a < middle:\n return a - b\n return c\n\n for _ in range(m):\n sheet = int(input().strip()) * 2\n best_i = -1\n best_value = -1\n for i in range(n):\n if (i == 0 or xs[i - 1] <= sheet) and (i == n - 1 or sheet <= xs[i + 1]):\n tmp_value = value(xs[i], sheet)\n if tmp_value > best_value:\n best_value = tmp_value\n best_i = i\n xs[best_i] = sheet\n print(best_i + 1, flush=True)\n if not any(x == middle for x in xs):\n break\n\n\nif __name__ == '__main__':\n main()\n", "import sys\n\n\ndef output(n):\n print(n)\n sys.stdout.flush()\n\nn, m, c = map(int, input().split())\n\narr = [0 for _ in range(n)]\nl = -1\nr = n\ncnt = 0\nwhile cnt < n:\n p = int(input())\n if p <= (c + 1) // 2:\n for i in range(0, r):\n if arr[i] == 0:\n l += 1\n output(i + 1)\n arr[i] = p\n break\n elif p < arr[i]:\n output(i + 1)\n arr[i] = p\n break\n else:\n for i in range(n - 1, l, -1):\n if arr[i] == 0:\n r -= 1\n output(i + 1)\n arr[i] = p\n break\n elif arr[i] < p:\n output(i + 1)\n arr[i] = p\n break\n if r - l == 1:\n break\n" ]
{"inputs": ["2 4 4\n2\n1\n3\n4", "2 2 2\n1\n2", "3 6 3\n1\n2\n1\n3\n1\n3", "4 8 4\n4\n4\n4\n4\n4\n4\n4\n4", "10 120 15\n6\n11\n9\n11\n3\n12\n11\n12\n2\n8\n3\n11\n13\n5\n12\n11\n9\n3\n10\n9\n9\n13\n13\n5\n6\n11\n3\n15\n8\n8\n10\n13\n7\n6\n4\n14\n9\n10\n5\n13\n4\n1\n8\n6\n13\n1\n3\n4\n9\n12\n2\n7\n3\n3\n7\n2\n2\n9\n2\n4\n2\n2\n11\n12\n15\n13\n6\n2\n11\n1\n8\n3\n13\n6\n15\n6\n4\n3\n4\n15\n15\n9\n5\n8\n3\n6\n14\n14\n5\n9\n4\n4\n14\n1\n12\n4\n12\n9\n11\n7\n4\n2\n5\n4\n4\n13\n13\n4\n5\n8\n3\n4\n2\n15\n3\n10\n9\n8\n12\n8", "2 2 2\n2\n1", "2 2 1\n1\n1", "2 2 2\n2\n2", "3 3 2\n2\n2\n1", "3 3 2\n1\n2\n1", "3 3 2\n2\n1\n2", "3 3 2\n2\n1\n1", "3 3 1\n1\n1\n1", "3 6 3\n2\n2\n3\n3\n1\n1", "3 6 3\n2\n2\n1\n1\n3\n3", "3 6 3\n3\n3\n2\n2\n1\n1", "4 4 2\n1\n2\n2\n1", "4 4 2\n1\n2\n1\n2", "4 4 2\n2\n2\n2\n1", "4 8 3\n2\n1\n2\n1\n2\n1\n1\n1", "4 8 3\n3\n2\n3\n2\n3\n2\n3\n1", "4 8 3\n2\n3\n2\n3\n3\n3\n3\n1", "4 8 4\n2\n3\n2\n3\n2\n3\n2\n3", "4 8 4\n3\n4\n3\n3\n4\n4\n1\n2", "10 100 20\n4\n1\n15\n2\n11\n1\n18\n9\n17\n5\n17\n12\n20\n6\n14\n19\n20\n3\n6\n14\n12\n17\n17\n10\n11\n8\n6\n6\n19\n16\n20\n6\n14\n5\n6\n19\n16\n11\n12\n1\n18\n10\n20\n8\n6\n12\n18\n16\n9\n10\n13\n17\n19\n7\n15\n7\n11\n1\n9\n10\n12\n5\n4\n16\n5\n7\n9\n15\n14\n20\n6\n3\n12\n10\n3\n6\n1\n16\n15\n18\n6\n19\n4\n17\n15\n15\n2\n6\n18\n12\n20\n10\n5\n13\n9\n11\n20\n20\n4\n16", "10 100 20\n11\n11\n11\n11\n11\n11\n11\n11\n11\n10\n10\n10\n10\n10\n10\n10\n10\n10\n9\n9\n9\n9\n9\n9\n9\n9\n9\n8\n8\n8\n8\n8\n8\n8\n8\n8\n7\n7\n7\n7\n7\n7\n7\n7\n7\n6\n6\n6\n6\n6\n6\n6\n6\n6\n5\n5\n5\n5\n5\n5\n5\n5\n5\n4\n4\n4\n4\n4\n4\n4\n4\n4\n3\n3\n3\n3\n3\n3\n3\n3\n3\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n1\n1\n1\n1\n1\n1\n1\n1\n12"], "outputs": ["3", "2", "3", "4", "20", "2", "2", "2", "3", "3", "3", "3", "3", "5", "3", "3", "4", "4", "4", "4", "6", "6", "4", "7", "20", "10"]}
UNKNOWN
PYTHON3
CODEFORCES
5
1488e9b4a9ebd590be12f7ea2251d7c8
Karen and Test
Karen has just arrived at school, and she has a math test today! The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. There are *n* integers written on a row. Karen must alternately add and subtract each pair of adjacent integers, and write down the sums or differences on the next row. She must repeat this process on the values on the next row, and so on, until only one integer remains. The first operation should be addition. Note that, if she ended the previous row by adding the integers, she should start the next row by subtracting, and vice versa. The teachers will simply look at the last integer, and then if it is correct, Karen gets a perfect score, otherwise, she gets a zero for the test. Karen has studied well for this test, but she is scared that she might make a mistake somewhere and it will cause her final answer to be wrong. If the process is followed, what number can she expect to be written on the last row? Since this number can be quite large, output only the non-negative remainder after dividing it by 109<=+<=7. The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=200000), the number of numbers written on the first row. The next line contains *n* integers. Specifically, the *i*-th one among these is *a**i* (1<=≤<=*a**i*<=≤<=109), the *i*-th number on the first row. Output a single integer on a line by itself, the number on the final row after performing the process above. Since this number can be quite large, print only the non-negative remainder after dividing it by 109<=+<=7. Sample Input 5 3 6 9 12 15 4 3 7 5 2 Sample Output 36 1000000006
[ "#!/usr/bin/env pypy3\r\n\r\nimport math\r\n\r\ndef make_nCr_mod(max_n=2*10**5 + 100, mod=10**9 + 7):\r\n fact, inv_fact = [0] * (max_n + 1), [0] * (max_n + 1)\r\n fact[0] = 1\r\n for i in range(max_n):\r\n fact[i + 1] = fact[i] * (i + 1) % mod\r\n\r\n inv_fact[-1] = pow(fact[-1], mod - 2, mod)\r\n for i in reversed(range(max_n)):\r\n inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod\r\n\r\n def nCr_mod(n, r):\r\n res = 1\r\n while n or r:\r\n a, b = n % mod, r % mod\r\n if a < b:\r\n return 0\r\n res = res * fact[a] % mod * inv_fact[b] % mod * inv_fact[a - b] % mod\r\n n //= mod\r\n r //= mod\r\n return res\r\n\r\n return nCr_mod\r\n\r\nnCr_mod = make_nCr_mod()\r\n\r\nMODULUS = 10**9+7\r\n\r\ninput()\r\nA = input().split(' ')\r\nA = list(map(int, A))\r\n\r\nif len(A) == 1:\r\n print(A[0])\r\n exit(0)\r\n\r\nif len(A) % 2 == 1:\r\n new_A = []\r\n next_plus = True\r\n for i in range(len(A) - 1):\r\n if next_plus:\r\n new_A += [A[i] + A[i+1]]\r\n else:\r\n new_A += [A[i] - A[i+1]]\r\n next_plus = not next_plus\r\n A = new_A\r\n\r\nif len(A) % 4 == 2:\r\n new_A = []\r\n for i in range(len(A) // 2):\r\n new_A += [A[2*i] + A[2*i+1]]\r\n A = new_A\r\nelse:\r\n new_A = []\r\n for i in range(len(A) // 2):\r\n new_A += [A[2*i] - A[2*i+1]]\r\n A = new_A\r\n\r\n# binomial sum\r\n\r\nN = len(A)-1\r\n\r\nret = 0\r\n\r\nfor i in range(N+1):\r\n ret += A[i]*nCr_mod(N, i)\r\n ret = ret % MODULUS\r\n\r\nprint(ret)" ]
{"inputs": ["5\n3 6 9 12 15", "4\n3 7 5 2", "1\n1", "16\n985629174 189232688 48695377 692426437 952164554 243460498 173956955 210310239 237322183 96515847 678847559 682240199 498792552 208770488 736004147 176573082", "18\n341796022 486073481 86513380 593942288 60606166 627385348 778725113 896678215 384223198 661124212 882144246 60135494 374392733 408166459 179944793 331468916 401182818 69503967", "17\n458679894 912524637 347508634 863280107 226481104 787939275 48953130 553494227 458256339 673787326 353107999 298575751 436592642 233596921 957974470 254020999 707869688", "19\n519879446 764655030 680293934 914539062 744988123 317088317 653721289 239862203 605157354 943428394 261437390 821695238 312192823 432992892 547139308 408916833 829654733 223751525 672158759", "1\n1000000000", "3\n524125987 923264237 374288891", "4\n702209411 496813081 673102149 561219907", "5\n585325539 365329221 412106895 291882089 564718673", "6\n58376259 643910770 5887448 757703054 544067926 902981667", "7\n941492387 72235422 449924898 783332532 378192988 592684636 147499872", "2\n500000004 500000003"], "outputs": ["36", "1000000006", "1", "347261016", "773499683", "769845668", "265109293", "1000000000", "996365563", "317278572", "974257995", "676517605", "328894634", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
1
148e34843e6ea7ff1682255785649209
Dorm Water Supply
The German University in Cairo (GUC) dorm houses are numbered from 1 to *n*. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this direction and not vice versa), and diameter (which characterizes the maximal amount of water it can handle). For each house, there is at most one pipe going into it and at most one pipe going out of it. With the new semester starting, GUC student and dorm resident, Lulu, wants to install tanks and taps at the dorms. For every house with an outgoing water pipe and without an incoming water pipe, Lulu should install a water tank at that house. For every house with an incoming water pipe and without an outgoing water pipe, Lulu should install a water tap at that house. Each tank house will convey water to all houses that have a sequence of pipes from the tank to it. Accordingly, each tap house will receive water originating from some tank house. In order to avoid pipes from bursting one week later (like what happened last semester), Lulu also has to consider the diameter of the pipes. The amount of water each tank conveys should not exceed the diameter of the pipes connecting a tank to its corresponding tap. Lulu wants to find the maximal amount of water that can be safely conveyed from each tank to its corresponding tap. The first line contains two space-separated integers *n* and *p* (1<=≤<=*n*<=≤<=1000,<=0<=≤<=*p*<=≤<=*n*) — the number of houses and the number of pipes correspondingly. Then *p* lines follow — the description of *p* pipes. The *i*-th line contains three integers *a**i* *b**i* *d**i*, indicating a pipe of diameter *d**i* going from house *a**i* to house *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*,<=1<=≤<=*d**i*<=≤<=106). It is guaranteed that for each house there is at most one pipe going into it and at most one pipe going out of it. Print integer *t* in the first line — the number of tank-tap pairs of houses. For the next *t* lines, print 3 integers per line, separated by spaces: *tank**i*, *tap**i*, and *diameter**i*, where *tank**i*<=≠<=*tap**i* (1<=≤<=*i*<=≤<=*t*). Here *tank**i* and *tap**i* are indexes of tank and tap houses respectively, and *diameter**i* is the maximum amount of water that can be conveyed. All the *t* lines should be ordered (increasingly) by *tank**i*. Sample Input 3 2 1 2 10 2 3 20 3 3 1 2 20 2 3 10 3 1 5 4 2 1 2 60 3 4 50 Sample Output 1 1 3 10 0 2 1 2 60 3 4 50
[ "n, m = map(int, input().split())\r\nt, p = [], [[0, 0, 0] for i in range(n + 1)]\r\nfor i in range(m):\r\n a, b, d = map(int, input().split())\r\n p[b][1], p[a][0], p[a][2] = a, b, d\r\nfor a in range(1, n + 1):\r\n if p[a][1] == 0:\r\n b, c, d = a, p[a][0], p[a][2]\r\n if not c: continue\r\n while c:\r\n if d > p[b][2]: d = p[b][2]\r\n b, c = c, p[c][0]\r\n t.append(str(a) + ' ' + str(b) + ' ' + str(d))\r\nprint(len(t))\r\nprint('\\n'.join(t))", "from collections import defaultdict\r\ngraph = defaultdict(list)\r\nn,m = list(map(int,input().split()))\r\nmat = [-1 for i in range(n+1)]\r\nvisited = [False for i in range(n+1)]\r\nd = {}\r\nfor _ in range(m):\r\n u,v,dist = list(map(int,input().split()))\r\n x = str(u)+':'+str(v) \r\n graph[v].append(u)\r\n d[x] = dist\r\n mat[u] = v\r\nans = []\r\nfor i in range(1,n+1):\r\n if mat[i]==-1 and visited[i]==False:\r\n visited[i] = True\r\n path = [i]\r\n cur = i\r\n while True:\r\n if cur not in graph:\r\n break\r\n else:\r\n cur = graph[cur][0]\r\n if visited[cur]==True:\r\n break\r\n else:\r\n path.append(cur)\r\n ans.append(path[-1::-1])\r\nfinal = []\r\nfor i in ans:\r\n cur = i\r\n if len(cur)>=2:\r\n prev = cur[0]\r\n t = 10**10\r\n for j in range(1,len(cur)):\r\n y = str(prev)+':'+str(cur[j])\r\n t = min(t,d[y])\r\n prev = cur[j]\r\n final.append([cur[0],cur[-1],t])\r\nprint(len(final))\r\nfinal.sort()\r\nfor i in final:\r\n print(i[0],i[1],i[2])", "import sys,math\r\nn,p=map(int,sys.stdin.readline().split())\r\ngraph=[0]*n\r\ninn=[0]*n\r\nout=[0]*n\r\ndiameter=[0]*n\r\nfor i in range(p):\r\n a,b,p=map(int,sys.stdin.readline().split())\r\n graph[a-1]=b-1 \r\n inn[b-1]+=1 \r\n out[a-1]+=1\r\n diameter[a-1]=p\r\nx=0\r\nfor i in range(n):\r\n if out[i]>0 and inn[i]==0:\r\n x+=1\r\nprint(x)\r\nfor i in range(n):\r\n if out[i]>0 and inn[i]==0:\r\n j=i \r\n cur=10**7 \r\n while(True):\r\n if out[j]==0:\r\n break\r\n cur=min(cur,diameter[j])\r\n j=graph[j]\r\n print(i+1,j+1,cur)\r\n ", "class CodeforcesTask107ASolution:\n def __init__(self):\n self.result = ''\n self.n_p = []\n self.pipes = []\n\n def read_input(self):\n self.n_p = [int(x) for x in input().split(\" \")]\n for _ in range(self.n_p[1]):\n self.pipes.append([int(x) for x in input().split(\" \")])\n\n def process_task(self):\n incomings = [[] for _ in range(self.n_p[0])]\n outcomings = [[] for _ in range(self.n_p[0])]\n for pipe in self.pipes:\n incomings[pipe[1] - 1].append(pipe[0])\n outcomings[pipe[0] - 1].append((pipe[1], pipe[2]))\n result = []\n for x in range(self.n_p[0]):\n if not incomings[x] and outcomings[x]:\n start = x + 1\n diam = outcomings[x][0][1]\n stop = outcomings[x][0][0]\n while outcomings[stop - 1]:\n diam = min(diam, outcomings[stop - 1][0][1])\n stop = outcomings[stop - 1][0][0]\n result.append(f\"{start} {stop} {diam}\")\n self.result = \"{0}\\n{1}\".format(len(result), \"\\n\".join(result))\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask107ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n", "#!/usr/bin/env python\r\ninf = 2*(10**9)\r\nres = []\r\nIn = [0]*1001\r\nout = [0]*1001\r\nf = [0]*1001\r\ns = input().split()\r\nn=int(s[0])\r\nm=int(s[1])\r\nu, v, d = (0,)*3\r\n\r\nfor i in range(1001):\r\n\tIn[i],out[i],f[i]= (-1,)*3\r\n\r\nfor i in range(m):\r\n\ts = input().split()\r\n\tu,v,d =int(s[0]),int(s[1]),int(s[2])\r\n\tf[u], In[v], out[u] = d, u, v\r\n\r\nfor i in range(1,n+1):\r\n\tif ( In[i]==-1 ):\r\n\t\tu,v,w,cnt,c = i,0,inf,0,0\r\n\t\twhile ( out[u]!= -1):\r\n\t\t\tcnt+=1\r\n\t\t\tif ( cnt >n-1):\r\n\t\t\t\tc=1\r\n\t\t\t\tbreak\r\n\t\t\tv = out[u]\r\n\t\t\tw = min( w ,f[u] )\r\n\t\t\tu=v\r\n\t\tif(c or (w == inf )):\r\n\t\t\tcontinue\r\n\t\tres.append([i, v, w ])\r\n\r\nprint (len(res),end='\\n')\r\n\r\nfor i in range (len(res)):\r\n\tprint (res[i][0],res[i][1],res[i][2] ,sep=' ')\r\n\r\n\r\n\t\t\t\r\n\r\n\r\n", "from collections import defaultdict\r\n\r\nn, p = map(int, input().split())\r\n\r\nnum_list = [[0, 0, 0] for i in range(n + 1)]\r\n\r\nfor i in range(p):\r\n a, b, d = map(int, input().split())\r\n num_list[a][0] = b\r\n num_list[b][1] = a\r\n num_list[a][2] = d\r\n\r\nans = []\r\n\r\nfor i in range(1, n + 1):\r\n if num_list[i][1] != 0:\r\n continue\r\n f = num_list[i][0]\r\n ind = i\r\n diameter = num_list[ind][2]\r\n if not f:\r\n continue\r\n while f > 0:\r\n diameter = min(diameter, num_list[ind][2])\r\n ind = f\r\n f = num_list[ind][0]\r\n ans.append((i, ind, diameter))\r\n\r\nprint(len(ans))\r\nfor i in ans:\r\n print(*i)\r\n\r\n", "houses, pipes = [int(x) for x in input().strip().split()]\r\n \r\nhouseToHouseDict = {}\r\npipeDict = {}\r\noutgoingList = []\r\nincomingList = []\r\nmaxFlow = 0\r\ndef DFSmaxPipe(origin):\r\n\tend = []\r\n\tlowestDiam = maxFlow\r\n\twhile (origin in houseToHouseDict):\r\n\t\tdiam = pipeDict[origin]\r\n\t\tif diam < lowestDiam:\r\n\t\t\tlowestDiam = diam\r\n\t\torigin = houseToHouseDict[origin]\r\n\tend.append(origin)\r\n\tend.append(lowestDiam)\r\n\treturn end\r\n \r\n \r\n \r\nfor x in range(pipes):\r\n\tahouse, bhouse, diameter = [int(x) for x in input().strip().split()]\r\n\tpipeDict[ahouse] = diameter\r\n\thouseToHouseDict[ahouse] = bhouse\r\n\toutgoingList.append(ahouse)\r\n\tincomingList.append(bhouse)\r\n\tif diameter > maxFlow:\r\n\t\tmaxFlow = diameter\r\n \r\n \r\nfor pipe in incomingList:\r\n\ttry:\r\n\t\toutgoingList.remove(pipe)\r\n\texcept ValueError:\r\n\t\tpass\r\n \r\noutgoingList.sort()\r\n \r\nprint(len(outgoingList))\r\n \r\nfor origin in outgoingList:\r\n\toutString = str(origin)\r\n\t\r\n\tendPipe = DFSmaxPipe(origin)\r\n\toutString += \" \" + str(endPipe[0]) + \" \" + str(endPipe[1])\r\n\tprint(outString)", "from sys import stdin\r\nfrom collections import defaultdict, deque\r\n\r\nn,p = map(int, input().split())\r\nN = n + 1\r\n\r\ngraph = dict()\r\nhas_in = [0] * N\r\nanswer = []\r\n\r\nfor line in stdin:\r\n a, b, d = map(int, line.split())\r\n graph[a] = (b, d)\r\n has_in[b] = 1\r\n \r\ndef bfs(start):\r\n diam = float('inf')\r\n while start in graph:\r\n z = graph[start]\r\n diam = min(diam, z[1])\r\n start = z[0]\r\n return start, diam\r\n \r\nfor i in range(1, N):\r\n if has_in[i]:\r\n continue\r\n if i not in graph:\r\n continue\r\n z = bfs(i)\r\n answer.append(f'{i} {z[0]} {z[1]}')\r\nprint(len(answer))\r\nprint('\\n'.join(answer))\r\n ", "import sys\r\nimport math\r\nfrom sys import stdin, stdout\r\n \r\n# TAKE INPUT\r\ndef get_ints_in_variables():\r\n return map(int, sys.stdin.readline().strip().split())\r\ndef get_int(): return int(input())\r\ndef get_ints_in_list(): return list(\r\n map(int, sys.stdin.readline().strip().split()))\r\ndef get_list_of_list(n): return [list(\r\n map(int, sys.stdin.readline().strip().split())) for _ in range(n)]\r\ndef get_string(): return sys.stdin.readline().strip()\r\n \r\ndef main():\r\n # Write Your Code Here\r\n n,p = get_ints_in_variables()\r\n indegree = [False] * n\r\n g = [[] for i in range(n)]\r\n for _ in range(p):\r\n a, b, d = get_ints_in_variables()\r\n a -= 1\r\n b -= 1\r\n # g[a].append((b, d))\r\n g[a].append(b)\r\n g[a].append(d)\r\n indegree[b] = True\r\n # print(g)\r\n # print(indegree)\r\n ans = []\r\n for i in range(n):\r\n if not indegree[i] and g[i]:\r\n cur = i\r\n w = 1e8\r\n while g[cur]:\r\n w = min(w, g[cur][1])\r\n cur = g[cur][0]\r\n # print(g[cur])\r\n ans.append((i + 1, cur + 1, w))\r\n print(len(ans))\r\n for i in range(0, len(ans)):\r\n print(ans[i][0],ans[i][1],ans[i][2])\r\n \r\n# calling main Function\r\nif __name__ == \"__main__\":\r\n main()", "graph = input()\r\ngraph = graph.split(' ')\r\nn = int(graph[0])\r\np = int(graph[1])\r\n\r\nmatrix =[[0] * n for i in range(n)]\r\n\r\nconn = dict()\r\n\r\nfor i in range(p):\r\n line = input()\r\n line = line.split(' ')\r\n matrix[int(line[0])-1][int(line[1])-1] = int(line[2])\r\n conn[int(line[0])-1]=int(line[1])-1\r\n\r\niniciales = [i for i in conn.keys() if i not in conn.values()]\r\nfinales = [i for i in conn.values() if i not in conn.keys()]\r\niniciales.sort()\r\nresultados = dict()\r\n\r\nc = 0\r\nfor i in iniciales:\r\n resultados[c]=[]\r\n nodo = i\r\n minimo = 10**6\r\n while nodo not in finales:\r\n resultados[c].append(nodo)\r\n if matrix[nodo][conn[nodo]] < minimo:\r\n minimo = matrix[nodo][conn[nodo]]\r\n nodo = conn[nodo]\r\n resultados[c].append(nodo)\r\n resultados[c].append(minimo)\r\n c += 1\r\n\r\nprint(len(resultados.keys()))\r\nfor element in resultados.values():\r\n print(element[0]+1,element[-2]+1, element[-1])", "import heapq;\r\nimport math;\r\nfrom collections import deque, Counter;\r\nimport sys;\r\n\r\nmod = 998244353;\r\ninput = sys.stdin.readline;\r\n\r\n\r\n\r\n\r\n\r\nn, p = map(int, input().split())\r\n\r\n\r\ninDegree = [0 for node in range(n)]\r\n\r\n\r\nneighbourNodes = [[] for i in range(n)]\r\n\r\nfor i in range(p):\r\n path, toPath, di = map(int, input().split())\r\n\r\n neighbourNodes[path - 1].append([toPath - 1, di])\r\n inDegree[toPath - 1] += 1;\r\n\r\n\r\n\r\nres = []\r\n\r\nvisited = [0 for node in range(n)]\r\n\r\ndef bfs(node):\r\n queue = deque([[node, float('inf')]]);\r\n\r\n lastNode, mnFlow = None, float('inf');\r\n while(queue):\r\n currNode, maxFlow = queue.popleft()\r\n lastNode = currNode;\r\n mnFlow = maxFlow\r\n visited[currNode] = 1;\r\n for node, cs in neighbourNodes[currNode]:\r\n if visited[node]: continue;\r\n maxFlow = min(maxFlow, cs);\r\n queue.append([node, maxFlow])\r\n return lastNode, mnFlow;\r\n\r\n\r\nfor node in range(n):\r\n if not inDegree[node]:\r\n lastNode, cs = bfs(node)\r\n if lastNode != node:\r\n res.append([node + 1, lastNode + 1, cs])\r\n\r\nres.sort()\r\n\r\n\r\nprint(len(res))\r\n\r\nfor nodeOne, nodeTwo, cs in res:\r\n print(nodeOne, nodeTwo, cs);\r\n", "n,p=map(int,input().split())\r\na=[[0,0,0] for _ in range(n+1)]\r\nfor _ in range(p):\r\n s,f,d=map(int,input().split())\r\n a[s][0]=f #kuda\r\n a[f][1]=s #otcuda\r\n a[s][2]=d #skolko\r\nans=[]\r\nfor i in range(1,n+1):\r\n if a[i][1]!=0:continue # find start (bak)\r\n f=a[i][0]\r\n s=i\r\n d=a[s][2]\r\n if f==0:continue\r\n while f>0:\r\n d=min(d,a[s][2])\r\n s=f\r\n f=a[s][0]\r\n ans.append(str(i)+' '+str(s)+' '+str(d))\r\nprint(len(ans))\r\nprint('\\n'.join(ans))", "from collections import defaultdict\r\n\r\ndef dfs(graph, node, diameter):\r\n\tif node in graph:\r\n\t\ttap, d_min = dfs(graph, graph[node], diameter)\r\n\t\td_min = min(d_min, diameter[node, graph[node]])\r\n\t\treturn (tap, d_min)\r\n\treturn (node, 1000007)\r\n\r\nif __name__ == '__main__':\r\n\tn, edges = map(int, input().split())\r\n\t\r\n\tgraph = dict()\r\n\tdiameter = dict()\r\n\ttanks = set(range(1,n+1))\r\n\ttaps = set(range(1,n+1))\r\n\r\n\tfor _ in range(edges):\r\n\t\ti, j, d = map(int, input().split())\r\n\t\tgraph[i] = j\r\n\t\tdiameter[(i, j)] = d\r\n\t\tif i in taps:\r\n\t\t\ttaps.remove(i)\r\n\t\tif j in tanks:\r\n\t\t\ttanks.remove(j)\r\n\r\n\tans = 0\r\n\tsolutions = list()\r\n\tfor i in tanks:\r\n\t\ttap, d = dfs(graph, i, diameter)\r\n\t\tif i != tap:\r\n\t\t\tans += 1\r\n\t\t\tsolutions.append((i, tap, d))\r\n\r\n\tprint(ans)\r\n\tfor soln in solutions:\r\n\t\tprint(soln[0], soln[1], soln[2])\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, p = map(int, input().split())\r\nd = [0]*(n+1)\r\nd1 = d.copy()\r\nd2 = d.copy()\r\nfor i in range(p):\r\n a, b, c = map(int, input().split())\r\n d[b] = a\r\n d1[a] = b\r\n d2[a] = c\r\n\r\nans = []\r\nfor i in range(1, n+1):\r\n if d[i]:\r\n continue\r\n\r\n x = i\r\n y = d2[x]\r\n while d1[x]:\r\n y = min(y, d2[x])\r\n x = d1[x]\r\n if y:\r\n ans.append([i, x, y])\r\nprint(len(ans))\r\nfor i in ans:\r\n print(' '.join(map(str, i)))", "from sys import stdin, stdout\r\nnmbr = lambda: int(stdin.readline())\r\nlst = lambda: list(map(int, stdin.readline().split()))\r\ndef dfs(src):\r\n global mn\r\n if g[src]==src or g[src]==-1:return src\r\n neigh=g[src]\r\n wt=cost[src,neigh]\r\n mn=min(wt,mn)\r\n return dfs(neigh)\r\nfor _ in range(1):#nmbr()):\r\n n,eg=lst()\r\n ind=[0]*(1+n)\r\n g=[-1]*(1+n)\r\n cost={}\r\n ans=[]\r\n for i in range(eg):\r\n u,v,wt=lst()\r\n g[u]=v\r\n cost[u,v]=wt\r\n ind[v]+=1\r\n for i in range(1,n+1):\r\n if ind[i]==0:\r\n mn=float('inf')\r\n des=dfs(i)\r\n if des!=i:\r\n ans+=[[i,des,mn]]\r\n print(len(ans))\r\n for k,v,w in ans:\r\n print(k,v,w)" ]
{"inputs": ["3 2\n1 2 10\n2 3 20", "3 3\n1 2 20\n2 3 10\n3 1 5", "4 2\n1 2 60\n3 4 50", "10 10\n10 3 70\n1 9 98\n9 10 67\n5 2 78\n8 6 71\n4 8 95\n7 1 10\n2 5 73\n6 7 94\n3 4 23", "7 5\n3 2 26\n4 6 84\n6 3 82\n5 1 57\n1 7 34", "9 6\n7 4 98\n5 9 72\n4 6 10\n2 8 22\n9 7 17\n3 1 66", "8 6\n1 3 84\n8 4 34\n7 2 10\n6 8 8\n3 5 39\n2 7 8", "10 8\n2 3 49\n4 8 26\n5 2 76\n3 5 94\n1 7 16\n10 9 77\n6 4 24\n7 1 7", "6 5\n2 6 47\n3 4 27\n5 2 47\n4 1 62\n1 5 61", "5 4\n5 2 9\n4 1 94\n3 5 82\n2 3 58", "1000 0", "2 2\n1 2 1\n2 1 1", "44 42\n4 37 166\n34 25 47\n28 19 367\n20 14 811\n8 3 878\n39 1 925\n35 9 206\n32 18 841\n16 44 503\n5 20 426\n22 34 896\n44 43 471\n17 33 577\n40 22 317\n24 31 818\n37 11 292\n21 39 888\n6 8 983\n43 36 170\n11 21 662\n36 17 942\n18 7 356\n2 32 220\n12 5 774\n19 27 193\n13 40 63\n15 10 510\n30 35 869\n41 24 736\n42 4 180\n23 41 261\n9 28 501\n29 15 983\n10 30 638\n7 13 402\n26 12 754\n25 6 597\n27 29 57\n1 16 933\n31 42 135\n33 38 718\n14 23 361", "35 33\n22 7 978\n5 6 566\n20 10 198\n6 17 170\n7 27 627\n24 19 659\n31 30 130\n34 8 365\n23 12 716\n4 29 217\n8 20 156\n26 35 142\n3 2 419\n15 1 448\n17 24 91\n18 33 962\n30 22 822\n9 16 847\n2 9 470\n10 25 981\n16 31 359\n19 28 283\n28 34 199\n11 5 660\n25 23 176\n29 18 235\n12 14 765\n14 11 81\n27 21 61\n21 13 651\n35 3 583\n1 32 767\n13 4 256", "33 28\n12 15 574\n11 13 714\n13 33 62\n9 28 391\n22 19 235\n6 20 655\n23 9 25\n8 29 994\n21 30 133\n17 18 170\n32 7 470\n14 21 418\n7 31 431\n3 1 185\n1 14 538\n33 12 250\n31 22 694\n2 27 945\n16 26 584\n19 32 317\n27 2 904\n15 25 748\n29 3 754\n24 4 287\n18 10 775\n30 11 401\n10 8 653\n28 5 70", "3 1\n1 2 10", "1 0", "2 0", "3 0"], "outputs": ["1\n1 3 10", "0", "2\n1 2 60\n3 4 50", "0", "2\n4 2 26\n5 7 34", "3\n2 8 22\n3 1 66\n5 6 10", "2\n1 5 39\n6 4 8", "2\n6 8 24\n10 9 77", "1\n3 6 27", "1\n4 1 94", "0", "0", "2\n2 3 47\n26 38 135", "2\n15 32 448\n26 33 61", "5\n6 20 655\n16 26 584\n17 25 62\n23 5 25\n24 4 287", "1\n1 2 10", "0", "0", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
15
149a65db8891987c69e12b3a698e18d4
Card Game
Digital collectible card games have become very popular recently. So Vova decided to try one of these. Vova has *n* cards in his collection. Each of these cards is characterised by its power *p**i*, magic number *c**i* and level *l**i*. Vova wants to build a deck with total power not less than *k*, but magic numbers may not allow him to do so — Vova can't place two cards in a deck if the sum of the magic numbers written on these cards is a prime number. Also Vova cannot use a card if its level is greater than the level of Vova's character. At the moment Vova's character's level is 1. Help Vova to determine the minimum level he needs to reach in order to build a deck with the required total power. The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=100000). Then *n* lines follow, each of these lines contains three numbers that represent the corresponding card: *p**i*, *c**i* and *l**i* (1<=≤<=*p**i*<=≤<=1000, 1<=≤<=*c**i*<=≤<=100000, 1<=≤<=*l**i*<=≤<=*n*). If Vova won't be able to build a deck with required power, print <=-<=1. Otherwise print the minimum level Vova has to reach in order to build a deck. Sample Input 5 8 5 5 1 1 5 4 4 6 3 1 12 4 3 12 1 3 7 4 4 1 5 8 2 5 3 3 Sample Output 4 2
[ "from collections import deque\r\nclass mf_graph:\r\n n=1\r\n g=[[] for i in range(1)]\r\n pos=[]\r\n def __init__(self,N):\r\n self.n=N\r\n self.g=[[] for i in range(N)]\r\n self.pos=[]\r\n def add_edge(self,From,To,cap):\r\n assert 0<=From and From<self.n\r\n assert 0<=To and To<self.n\r\n assert 0<=cap\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})\r\n self.g[To].append({\"to\":From,\"rev\":len(self.g[From])-1,\"cap\":0})\r\n return m\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],\r\n \"to\":_e[\"to\"],\r\n \"cap\":_e[\"cap\"]+_re[\"cap\"],\r\n \"flow\":_re[\"cap\"]}\r\n def edges(self):\r\n m=len(self.pos)\r\n result=[]\r\n for i in range(m):\r\n result.append(self.get_edge(i))\r\n return result\r\n def change_edge(self,i,new_cap,new_flow):\r\n m=len(self.pos)\r\n assert 0<=i and i<m\r\n assert 0<=new_flow and new_flow<=new_cap\r\n _e=self.g[self.pos[i][0]][self.pos[i][1]]\r\n _re=self.g[_e[\"to\"]][_e[\"rev\"]]\r\n _e[\"cap\"]=new_cap-new_flow\r\n _re[\"cap\"]=new_flow\r\n def flow(self,s,t,flow_limit=(1<<63)-1):\r\n assert 0<=s and s<self.n\r\n assert 0<=t and t<self.n\r\n level=[0 for i in range(self.n)]\r\n Iter=[0 for i in range(self.n)]\r\n que=deque([])\r\n def bfs():\r\n for i in range(self.n):level[i]=-1\r\n level[s]=0\r\n que=deque([])\r\n que.append(s)\r\n while(len(que)>0):\r\n v=que.popleft()\r\n for e in self.g[v]:\r\n if e[\"cap\"]==0 or level[e[\"to\"]]>=0:continue\r\n level[e[\"to\"]]=level[v]+1\r\n if e[\"to\"]==t:return\r\n que.append(e[\"to\"])\r\n def dfs(func,v,up):\r\n if (v==s):return up\r\n res=0\r\n level_v=level[v]\r\n for i in range(Iter[v],len(self.g[v])):\r\n e=self.g[v][i]\r\n if (level_v<=level[e[\"to\"]] or self.g[e[\"to\"]][e[\"rev\"]][\"cap\"]==0):continue\r\n d=func(func,e[\"to\"],min(up-res,self.g[e[\"to\"]][e[\"rev\"]][\"cap\"]))\r\n if d<=0:continue\r\n self.g[v][i][\"cap\"]+=d\r\n self.g[e[\"to\"]][e[\"rev\"]][\"cap\"]-=d\r\n res+=d\r\n if res==up:return res\r\n level[v]=self.n\r\n return res\r\n flow=0\r\n while(flow<flow_limit):\r\n bfs()\r\n if level[t]==-1:break\r\n for i in range(self.n):Iter[i]=0\r\n while(flow<flow_limit):\r\n f=dfs(dfs,t,flow_limit-flow)\r\n if not(f):break\r\n flow+=f\r\n return flow\r\n def min_cut(self,s):\r\n visited=[False for i in range(self.n)]\r\n que=deque([])\r\n que.append(s)\r\n while(len(que)>0):\r\n p=que.popleft()\r\n visited[p]=True\r\n for e in self.g[p]:\r\n if e[\"cap\"] and not(visited[e[\"to\"]]):\r\n visited[e[\"to\"]]=True\r\n que.append(e[\"to\"])\r\n return visited\r\n\r\ndef divisors(n):\r\n lower,upper=[],[]\r\n i=1\r\n while i*i<=n:\r\n if n%i==0:\r\n lower.append(i)\r\n if i!=n//i:\r\n upper.append(n//i)\r\n i+=1\r\n return lower+upper[::-1]\r\n\r\nfrom sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nn,k=map(int,input().split())\r\npcl=[]\r\nCs=[]\r\nLs=[]\r\nfor _ in range(n):\r\n p,c,l=map(int,input().split())\r\n pcl.append((p,c,l))\r\n Cs.append(c)\r\n Ls.append(l)\r\n \r\nNG=set()\r\nfor i in Cs:\r\n for j in Cs:\r\n if len(divisors(i+j))==2:\r\n NG.add(i+j)\r\n\r\n\r\ndef calc(mid):\r\n use_odd=[]\r\n use_even=[]\r\n one=-1\r\n for p,c,l in pcl:\r\n if mid>=l:\r\n if c==1:\r\n one=max(p,one)\r\n else:\r\n if c%2:\r\n use_odd.append((p,c))\r\n else:\r\n use_even.append((p,c))\r\n \r\n if one!=-1:\r\n use_odd.append((one,1))\r\n \r\n n1=len(use_odd)\r\n n2=len(use_even)\r\n m=n1+n2\r\n S=m\r\n T=S+1\r\n g=mf_graph(m+2)\r\n \r\n inf=10**9\r\n res=0\r\n for i in range(n1):\r\n res+=use_odd[i][0]\r\n g.add_edge(S,i,use_odd[i][0])\r\n for i in range(n2):\r\n res+=use_even[i][0]\r\n g.add_edge(i+n1,T,use_even[i][0])\r\n \r\n for i in range(n1):\r\n for j in range(n2):\r\n if use_odd[i][1]+use_even[j][1] in NG:\r\n g.add_edge(i,n1+j,inf)\r\n \r\n return res-g.flow(S,T)\r\n\r\nLs.sort()\r\nng,ok=-1,n\r\nwhile ok-ng>1:\r\n mid=(ok+ng)//2\r\n if calc(Ls[mid])>=k:\r\n ok=mid\r\n else:\r\n ng=mid\r\n\r\nif ok==n:\r\n print(-1)\r\nelse:\r\n print(Ls[ok])", "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\ndef add_edge(u, v, c):\r\n G[u].append([v, c, len(G[v]), 1])\r\n G[v].append([u, 0, len(G[u]) - 1, 0])\r\n return\r\n\r\ndef bfs(s):\r\n q = deque()\r\n q.append(s)\r\n dist = [inf] * l\r\n dist[s] = 0\r\n while q:\r\n i = q.popleft()\r\n di = dist[i]\r\n for j, c, _, _ in G[i]:\r\n if not dist[j] ^ inf and c:\r\n dist[j] = di + 1\r\n q.append(j)\r\n return dist\r\n\r\ndef dfs(dist, s, t, nowe):\r\n mi = [inf] * l\r\n st = [s]\r\n se = set()\r\n se.add(s)\r\n d = []\r\n while st:\r\n u = st[-1]\r\n if u == t:\r\n st.pop()\r\n break\r\n if nowe[u] < len(G[u]):\r\n v, c, _, _ = G[u][nowe[u]]\r\n if c and not dist[v] ^ (dist[u] + 1) and not v in se:\r\n st.append(v)\r\n d.append(nowe[u])\r\n se.add(v)\r\n mi[v] = min(mi[u], c)\r\n else:\r\n nowe[u] += 1\r\n else:\r\n se.remove(st.pop())\r\n if d:\r\n d.pop()\r\n if st:\r\n nowe[st[-1]] += 1\r\n return st, d, mi[t]\r\n\r\ndef max_flow(s, t):\r\n ans = 0\r\n while True:\r\n dist = bfs(s)\r\n if not dist[t] ^ inf:\r\n break\r\n nowe = [0] * l\r\n while True:\r\n st, d, f = dfs(dist, s, t, nowe)\r\n if not f % inf:\r\n break\r\n ans += f\r\n for u, i in zip(st, d):\r\n G[u][i][1] -= f\r\n G[G[u][i][0]][G[u][i][2]][1] += f\r\n return ans\r\n\r\ndef the_sieve_of_eratosthenes(n):\r\n s = [1] * (n + 1)\r\n x = []\r\n for i in range(2, n + 1):\r\n if s[i]:\r\n x.append(i)\r\n for j in range(i, n + 1, i):\r\n s[j] = 0\r\n return x\r\n\r\nn, k = map(int, input().split())\r\nx = [[] for _ in range(n + 1)]\r\nfor _ in range(n):\r\n p, c, l = map(int, input().split())\r\n x[l].append((p, c))\r\nd = dict()\r\nz = set(the_sieve_of_eratosthenes(2 * pow(10, 5) + 1))\r\nl = n + 2\r\ns, t = l - 2, l - 1\r\ninf = pow(10, 9) + 1\r\nans = -1\r\nfor i in range(1, n + 1):\r\n if not x[i]:\r\n continue\r\n G = [[] for _ in range(l)]\r\n ma = 0\r\n y = []\r\n sp = 0\r\n for j in range(1, i + 1):\r\n for p, c in x[j]:\r\n if c ^ 1:\r\n y.append((p, c))\r\n sp += p\r\n else:\r\n ma = max(ma, p)\r\n sp += ma\r\n if ma:\r\n y.append((ma, 1))\r\n for u in range(len(y)):\r\n pu, cu = y[u]\r\n if cu % 2:\r\n add_edge(s, u, pu)\r\n else:\r\n add_edge(u, t, pu)\r\n for v in range(u + 1, len(y)):\r\n pv, cv = y[v]\r\n if not cu + cv in z:\r\n continue\r\n if cu % 2:\r\n add_edge(u, v, inf)\r\n else:\r\n add_edge(v, u, inf)\r\n if k <= sp - max_flow(s, t):\r\n ans = i\r\n break\r\nprint(ans)", "import sys\r\nfrom collections import deque\r\n\r\nN, oo = 205, float('inf')\r\n\r\ndef augment(res, u, t, level, limit):\r\n if limit == 0:\r\n return 0\r\n \r\n if u == t:\r\n return limit\r\n \r\n flow = 0\r\n for v in range(len(res)):\r\n if res[u][v] > 0 and level[v] == level[u] + 1:\r\n aug = augment(res, v, t, level, min(limit, res[u][v]))\r\n res[u][v] -= aug\r\n res[v][u] += aug\r\n flow += aug\r\n limit -= aug\r\n \r\n if not flow:\r\n level[u] = None\r\n \r\n return flow\r\n\r\ndef dinic(res):\r\n q = deque()\r\n max_flow = 0\r\n while True:\r\n q.append(s)\r\n level = [None] * len(res)\r\n level[s] = 0\r\n while q:\r\n u = q.popleft()\r\n for v in range(len(res)):\r\n if res[u][v] > 0 and level[v] == None:\r\n level[v] = level[u] + 1\r\n q.append(v)\r\n \r\n if level[t] == None:\r\n return max_flow\r\n \r\n max_flow += augment(res, s, t, level, sum(res[s][v] for v in range(len(res))))\r\n\r\ndef is_prime(v):\r\n if v < 2:\r\n return False\r\n \r\n i = 2\r\n while i * i <= v:\r\n if v % i == 0:\r\n return False\r\n i += 1\r\n \r\n return True\r\n\r\ndef check(x):\r\n res = [[0] * (t + 1) for _ in range(t + 1)]\r\n\r\n for i in range(1, n+1):\r\n if l[i] <= x and c[i] != 1 and c[i] % 2 == 1:\r\n for j in range(1, n+1):\r\n if l[j] <= x and c[j] != 1 and c[j] % 2 == 0:\r\n if is_prime(c[i] + c[j]):\r\n res[i][j] = oo\r\n c1pmax = 1\r\n for i in range(1, n+1):\r\n if c[i] == 1 and l[i] <= x and p[i] > p[c1pmax]:\r\n c1pmax = i\r\n\r\n for i in range(1, n+1):\r\n if c[i] != 1 and l[i] <= x and is_prime(c[i] + c[c1pmax]) and c[i] % 2 == 0:\r\n res[c1pmax][i] = oo\r\n \r\n total_power = 0\r\n for i in range(1, n+1):\r\n if l[i] > x or c[i] == 1 and i != c1pmax:\r\n continue\r\n\r\n if c[i] % 2 == 1:\r\n res[s][i] = p[i]\r\n else:\r\n res[i][t] = p[i]\r\n \r\n total_power += p[i]\r\n \r\n max_flow = dinic(res)\r\n\r\n return total_power - max_flow\r\n\r\nn, k = map(int, sys.stdin.readline().split())\r\n# n, k = map(int, \"5 8\".split())\r\ns = n + 1\r\nt = s + 1\r\n\r\np, c, l = [None] * N, [None] * N, [None] * N\r\n\r\nn_lines = [\r\n None,\r\n \"5 5 1\",\r\n \"1 5 4\",\r\n \"4 6 3\",\r\n \"1 12 4\",\r\n \"3 12 1\"\r\n]\r\n\r\nfor i in range(1, n+1):\r\n p[i], c[i], l[i] = map(int, sys.stdin.readline().split())\r\n # p[i], c[i], l[i] = map(int, n_lines[i].split())\r\n\r\nfor x in range(1, 100):\r\n if check(x) >= k:\r\n print(x)\r\n exit(0)\r\n\r\nprint(-1)" ]
{"inputs": ["5 8\n5 5 1\n1 5 4\n4 6 3\n1 12 4\n3 12 1", "3 7\n4 4 1\n5 8 2\n5 3 3", "10 10\n3 3 6\n5 10 4\n4 7 9\n4 9 7\n1 9 4\n1 6 10\n4 10 1\n4 4 6\n2 7 2\n1 5 4", "10 20\n9 4 10\n2 8 9\n9 1 1\n8 10 10\n5 10 2\n1 2 10\n9 6 3\n2 10 5\n7 10 6\n6 3 1", "10 30\n23 83 9\n2 59 6\n10 6 4\n4 92 3\n19 13 6\n28 83 6\n25 58 4\n6 32 3\n4 15 3\n2 60 2", "10 30\n2 20 10\n7 81 4\n7 27 5\n8 82 8\n1 6 4\n7 86 6\n4 78 10\n7 5 7\n3 7 8\n7 63 5", "15 40\n11 99 8\n9 86 12\n9 92 10\n6 88 7\n11 16 4\n7 15 13\n8 22 1\n6 67 5\n7 70 1\n1 18 5\n7 40 5\n8 15 3\n14 80 4\n1 78 1\n13 58 15", "30 100\n2 16 20\n12 125 8\n11 13 23\n20 58 7\n10 157 29\n17 58 6\n1 169 29\n17 33 26\n1 71 1\n4 94 16\n7 141 6\n8 168 23\n3 161 5\n15 126 1\n3 24 19\n4 196 7\n14 20 15\n9 11 29\n1 154 15\n10 184 3\n1 147 2\n19 57 24\n6 66 30\n6 156 1\n7 63 30\n15 2 30\n7 122 14\n2 178 25\n15 106 29\n17 1 22", "30 100\n10 30 27\n9 140 20\n5 77 3\n6 47 19\n2 56 22\n5 6 3\n9 175 4\n10 21 12\n5 69 4\n8 152 28\n8 24 22\n3 66 20\n3 126 10\n9 16 1\n2 34 12\n4 37 26\n3 191 26\n6 38 10\n7 132 11\n8 185 21\n8 72 25\n10 185 19\n4 56 1\n1 69 4\n7 175 30\n3 121 24\n10 181 30\n3 109 21\n10 35 24\n9 141 18", "2 2\n1 1 1\n1 1 1", "5 8\n5 1 5\n1 1 4\n4 1 3\n1 1 4\n3 1 1", "2 3\n1 1 1\n2 1 1", "5 400\n228 1 1\n1 2 1\n1 9 1\n228 8 1\n1 41 1", "4 10\n5 1 1\n1 2 1\n1 5 1\n5 8 1", "5 5\n3 2 1\n1 3 1\n1 3 1\n1 4 1\n2 7 1", "18 598\n91 7 3\n54 8 4\n64 4 2\n83 5 4\n96 8 9\n63 8 1\n78 3 13\n91 2 7\n86 9 2\n68 5 1\n8 2 14\n10 9 3\n61 2 4\n93 8 14\n44 1 10\n21 7 2\n24 1 5\n38 7 15", "20 206\n52 8 1\n20 9 7\n85 9 18\n38 8 8\n89 7 5\n44 6 11\n14 8 7\n54 3 20\n34 3 14\n3 7 11\n10 7 3\n70 1 19\n24 8 16\n19 9 11\n4 2 12\n4 7 13\n43 9 6\n19 9 15\n9 4 8\n79 1 12", "14 2\n45 4 5\n38 3 5\n15 4 11\n2 2 4\n39 2 9\n54 3 8\n71 1 11\n94 9 1\n69 5 2\n45 2 3\n10 9 10\n96 8 9\n56 4 11\n86 1 9", "19 88\n78 6 9\n93 8 11\n37 9 15\n21 4 7\n28 9 15\n30 1 1\n32 7 19\n96 8 5\n19 8 18\n86 4 7\n100 9 5\n44 5 11\n5 8 13\n61 9 10\n59 1 10\n66 1 1\n69 6 2\n6 2 3\n99 3 15", "2 8\n5 1 1\n9 1 1", "2 5\n3 1 2\n2 1 2"], "outputs": ["4", "2", "4", "6", "4", "8", "4", "19", "30", "-1", "-1", "-1", "1", "1", "1", "15", "11", "1", "5", "1", "-1"]}
UNKNOWN
PYTHON3
CODEFORCES
3
14b287b107fd7520ff268970f124a5ce
Search for Pretty Integers
You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=9) — the lengths of the first and the second lists, respectively. The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=9) — the elements of the first list. The third line contains *m* distinct digits *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=9) — the elements of the second list. Print the smallest pretty integer. Sample Input 2 3 4 2 5 7 6 8 8 1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1 Sample Output 25 1
[ "input();c=lambda: set(map(int,input().split()));k=c();k1=c();d=k.intersection(k1);z=min(k);z1=min(k1)\r\ntry:print(min(int(str(min(z,z1))+str(max(z,z1))),int(str(min(d)))))\r\nexcept:print(int(str(min(z,z1))+str(max(z,z1))))", "print((lambda a,x,y: sorted([i for i in x if i in y])[0] if len([i for i in x if i in y])!=0 else str(min(min(x),min(y)))+str(max(min(x),min(y))))(input(),list(map(int,input().split())),list(map(int,input().split()))))", "n , m = map(int,input().split())\r\nl1 = sorted(list(map(int,input().split())))\r\nl2 = sorted(list(map(int,input().split())))\r\nflag = 0\r\nfor i in l1:\r\n\tif i in l2:\r\n\t\tflag = 1\r\n\t\tprint(i)\r\n\t\tbreak\r\nif flag==0:\r\n\ta = str(l1[0])+str(l2[0])\r\n\tb = str(l2[0])+str(l1[0])\r\n\tprint(min(int(a),int(b)))", "import sys\r\ninput(); list1 = list(map(int,input().split(' '))); list2 = list(map(int,input().split(' '))); list3 = []\r\nfor element in list1:\r\n if element in list2:\r\n list3.append(element)\r\nif list3:\r\n print(min(list3))\r\nelse:\r\n mini1, mini2 = min(list1), min(list2)\r\n print(mini1*10+mini2) if mini1 <= mini2 else print(mini2*10+mini1)", "def pretty(A,B):\n\tA.sort()\n\tB.sort()\n\tres=[]\n\tptr1=0\n\tptr2=0\n\tif len(A)>len(B):\n\t\tshort=B\n\t\tlong=A\n\telse:\n\t\tshort=A\n\t\tlong=B\n\twhile(ptr2<len(short) and ptr1<len(long)):\n\t\tif short[ptr2]==long[ptr1]:\n\t\t\tres.append(short[ptr2])\n\t\t\treturn res\n\t\tif short[ptr2]<long[ptr1]:\n\t\t\tptr2=ptr2+1\n\t\telse:\n\t\t\tptr1=ptr1+1\n\t\t\n\t\t\n\t\t\n\t'''if A[0]==B[0]:\n\t\tres.append(A[0])\n\t\treturn res'''\n\tif A[0]>B[0]:\n\t\tres.append(B[0])\n\t\tres.append(A[0])\n\telse:\n\t\tres.append(A[0])\n\t\tres.append(B[0])\n\treturn res\n\n\ntemp=list(int(num) for num in input().strip().split())[:2]\nsizeA=temp[0]\nsizeB=temp[1]\nA=list(int(num) for num in input().strip().split())[:sizeA]\n\nB=list(int(num) for num in input().strip().split())[:sizeB]\nres=pretty(A,B)\nfor i in res:\n\tprint(i,end=\"\")\n\n\t\t\n\t", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nw=min(a)\r\nw1=min(b)\r\nq=set(a).intersection(set(b))\r\nif len(q)!=0:\r\n\tprint(min(q))\r\nelse:\r\n\tprint(\"{}{}\".format(min(w,w1),max(w,w1)))", "import sys\r\nn,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nflag=0\r\nk=99\r\nfor i in range(n):\r\n if a[i] in b:\r\n flag=1\r\n k=min(k,a[i])\r\nif flag:\r\n print(k)\r\n sys.exit()\r\na.sort()\r\nb.sort()\r\nr=[]\r\nr.append(a[0])\r\nr.append(b[0])\r\nr.sort()\r\nprint(''.join(map(str,r)))", "n,m = map(int,input().split())\na = [int(i) for i in input().split()]\na.sort()\nb = [int(i) for i in input().split()]\nb.sort()\nans = -1\nfor i in range(1,10):\n if i in a and i in b:\n ans = i\n break\nif ans==-1:\n amin = min(a)\n bmin = min(b)\n ans = (min(amin,bmin)*10+max(amin,bmin))\nprint(ans)\n", "input();a=sorted([*map(int,input().split())]);b=sorted([*map(int,input().split())])\r\ncnt = 1\r\nfor x in a:\r\n if(x in b):print(x);cnt = 0;break\r\nif(cnt):print([str(a[0])+str(b[0]),str(b[0])+str(a[0])][b[0]<a[0]])", "if __name__ == \"__main__\":\r\n N, M = map(int, input().split())\r\n A = set(list(map(int, input().split())))\r\n B = set(list(map(int, input().split())))\r\n for x in range(1, 10):\r\n if x in A and x in B:\r\n print (x)\r\n exit(0)\r\n\r\n result = 114514\r\n for x in range(1, 10):\r\n for y in range(1, 10):\r\n if x in A and y in B:\r\n result = min(result, 10 * x + y)\r\n result = min(result, 10 * y + x)\r\n if y in A and x in B:\r\n result = min(result, 10 * y + x)\r\n result = min(result, 10 * x + y)\r\n print (result)\r\n", "nm = input()\r\nx = sorted(list(map(int, input().split())))\r\ny = sorted(list(map(int, input().split())))\r\n\r\nout = False\r\n\r\nfor i in x:\r\n if i in y:\r\n print(i)\r\n out = True\r\n break\r\n \r\nif not out:\r\n a = x[0]\r\n b = y[0]\r\n a,b = min(a,b), max(a,b)\r\n a = (a*10)+b\r\n print(a)\r\n\r\n", "n, m = map(int, input().split())\nar = sorted(list(map(int, input().split())))\nbr = list(map(int, input().split()))\nrez = 0\nfor i in ar:\n if i in br:\n rez = i\n break\nif rez:\n print(rez)\nelse:\n a, b = min(ar), min(br)\n a, b = min(a, b), max(a, b)\n print(a * 10 + b)\n", "\r\ninput()\r\n\r\nn = sorted(list(map(int, input().split())))\r\nm = sorted(list(map(int, input().split())))\r\n\r\nminimun = 10\r\n\r\nfor i in n:\r\n if i in m and i < minimun:\r\n minimun = i\r\n\r\nif minimun != 10:\r\n print(minimun)\r\nelse:\r\n f = min(n[0], m[0])\r\n s = max(n[0], m[0])\r\n print('{}{}'.format(f, s))\r\n", "IL = lambda: list(map(int, input().split()))\r\nI = lambda: int(input())\r\n\r\nn, m = IL()\r\na = set(IL())\r\nb = set(IL())\r\nun = a.intersection(b)\r\nif len(un):\r\n print(min(un))\r\nelse:\r\n un = sorted([min(a), min(b)])\r\n print(un[0]*10 + un[1])", "n,m = map(int,input().split())\r\na = set(map(int,input().split()))\r\nb = set(map(int,input().split()))\r\nm = 100\r\nif a & b:\r\n m = min(a&b)\r\nma = min(a)\r\nmb = min(b)\r\nres1 = str(ma)+str(mb)\r\nres2 = str(mb)+str(ma)\r\nres = min(min(int(res1),int(res2)) , m)\r\n\r\nprint(res)", "# \n\nlens = input().split()\nl1 = input().split()\nl2 = input().split()\n\nmin1, min2 = min(l1), min(l2)\nresult = ''\nintersects = set(l1) & set(l2)\n\nif len(intersects) != 0:\n result = min(intersects)\nelif min1 == min2 or min1 in l2:\n result = min1\nelif min2 in l1:\n result = min2\nelse:\n result = min([min1, min2]) + max([min1, min2]) \n\nprint(result)", "n,m=(int(i) for i in input().split())\r\nl1=sorted([int(i) for i in input().split()])\r\nl2=sorted([int(i) for i in input().split()])\r\nc=0\r\nfor i in range(n):\r\n for j in range(m):\r\n if(l1[i]==l2[j]):\r\n c=1\r\n break\r\n if(c==1):\r\n break\r\nif(c==1):\r\n print(l1[i])\r\nelse:\r\n k=min(l1[0],l2[0])\r\n k1=max(l1[0],l2[0])\r\n print(str(k)+str(k1))", "I = lambda: map(int, input().split())\r\nI()\r\na = list(I())\r\nb = list(I())\r\ninter = list(set(a) & set(b))\r\nif len(inter) > 0:\r\n print(min(inter))\r\n exit(0)\r\nx = min(a)\r\ny = min(b)\r\nprint(min(10*x +y, 10*y+x))\r\n", "import sys\r\nn,m = map(int, input().split())\r\na,b= [], []\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\na.sort()\r\nb.sort()\r\nif n>m:\r\n l = a\r\n s = b\r\nelse:\r\n l = b\r\n s = a\r\nfor i in range(min(m,n)):\r\n for p in range(max(m,n)):\r\n if s[i] == l[p]:\r\n print(s[i])\r\n sys.exit()\r\nprint(min(a[0],b[0]),end=\"\"),print(max(b[0],a[0]))", "n,m=map(int,input().split())\r\na=sorted(list(map(int,input().split())))\r\nb=sorted(list(map(int,input().split())))\r\nfor i in a:\r\n if i in b:\r\n print(i)\r\n exit()\r\nx=str(a[0])+str(b[0])\r\ny=x[::-1]\r\nprint(min(int(x),int(y)))\r\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\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\ns=set(a)&set(b);s=list(s);s.sort()\r\nif len(s)!=0:print(s[0])\r\nelse:\r\n p=str(min(a))+str(min(b))\r\n print(min(int(p),int(p[::-1])))", "s = input()\r\n\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\n\r\na = set(a)\r\nb = set(b)\r\n\r\nif a.isdisjoint(b): #нет общих\r\n m1 = min(a)\r\n m2 = min(b)\r\n\r\n if m1 > m2:\r\n print(m2 * 10 + m1)\r\n else:\r\n print(m1 * 10 + m2)\r\nelse: #есть общие\r\n print(min(set.intersection(a, b)))\r\n", "input().split()\r\na=list(map(int,input().split()))\r\nb=list(map(int, input().split()))\r\nfor i in range(1,100):\r\n if i<10:\r\n if (i in a and i in b):\r\n print(i)\r\n break\r\n else:\r\n if (int(str(i)[0]) in a and int(str(i)[1]) in b) or (int(str(i)[0]) in b and int(str(i)[1]) in a):\r\n print(i)\r\n break", "n, m = map(int, input().split())\r\na = set(map(int, input().split()))\r\nb = set(map(int, input().split()))\r\nif len(a & b) > 0:\r\n print(min(a & b))\r\nelse:\r\n print(min(min(a), min(b)), max(min(a), min(b)), sep='')", "# # t = int(input())\n# t = 1\n\n\n# # # n, m = map(int, input().split())\n# # # a = list(map(int, input().split()))\n\n\n# while t != 0:\n# # n = int(input())\n# n, m = map(int, input().split())\n# a = list(map(int, input().split()))\n# b = list(map(int, input().split()))\n\n# # s = input()\n# t -= 1\nn, m = [int(i) for i in input().split()]\na = set(int(i) for i in input().split())\nb = set(int(i) for i in input().split())\nif a & b:\n print(min(a & b))\nelse:\n x = min(a)\n y = min(b)\n print(min(x, y), max(x, y), sep=\"\")\n", "n, m = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\nans = None\nfor i in range(1, 10):\n if a.count(i) * b.count(i) > 0:\n ans = i\n break\n\nif ans is None:\n x, y = min(a), min(b)\n mn, mx = min(x, y), max(x, y)\n ans = mn * 10 + mx\n\nprint(ans)", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nmal=1000\r\nfor i in a:\r\n if i in b and int(i)<mal:\r\n mal=int(i)\r\nif mal!=1000:\r\n print(mal)\r\nelif min(b)<min(a):\r\n print(str(min(b)) + str(min(a)))\r\nelse:\r\n print(str(min(a))+str(min(b)))\r\n\r\n\r\n", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\ns=[]\r\nq=[]\r\nfor i in range(n):\r\n\tif a[i] in b:\r\n\t\ts.append(a[i])\r\nfor i in range(m):\r\n\tif b[i] in a:\r\n\t\tq.append(b[i])\t\r\nif len(s)==len(q)==0:\r\n\tprint(min(min(a),min(b)),max(min(a),min(b)),sep='')\r\nelif min(s)==min(q):\r\n\tprint(min(s))\r\nelse:\r\n\tprint(min(min(s),min(q)),max(min(s),min(q)),sep='')", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nm1=min(a)\r\nm2=min(b)\r\nmi=min(m1,m2)\r\nma=max(m1,m2)\r\nl=[]\r\nfor i in a:\r\n\tif i in b:\r\n\t\tl.append(i)\r\nl.append(int(str(mi)+str(ma)))\r\nprint(min(l))\r\n", "n,m=map(int,input().split())\nfir=list(map(int,input().split()))\nsec=list(map(int,input().split()))\ninter=[val for val in fir if val in sec]\nif inter!=[]:\n\tprint(min(inter))\nelse:\n\ta=min(fir)\n\tb=min(sec)\n\tprint(int(str(min(a,b))+str(max(a,b))))\n", "n, m = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\n\r\nsa = set(a)\r\nsb = set(b)\r\nsi = sa.intersection(sb)\r\n\r\na.sort()\r\nb.sort()\r\nii = list(si)\r\nii.sort\r\n\r\nif ii:\r\n print(ii[0])\r\nelse:\r\n print(min(a[0]*10+b[0], b[0]*10+a[0]))\r\n", "(length_of_first_list, length_of_second_list) = map(int, input().split(' '))\nelements_of_first_list = list(map(int, input().split(' ')))\nelements_of_second_list = list(map(int, input().split(' ')))\n\nmutual_elements = []\n\nfor element in elements_of_first_list:\n if element in elements_of_second_list:\n mutual_elements.append(element)\n\nif len(mutual_elements) > 0:\n print(min(mutual_elements))\nelse:\n min_values_of_first_list = min(elements_of_first_list)\n min_values_of_second_list = min(elements_of_second_list)\n if min_values_of_first_list < min_values_of_second_list:\n print(str(min_values_of_first_list) + str(min_values_of_second_list))\n else:\n print(str(min_values_of_second_list) + str(min_values_of_first_list))", "listsLength = list(map(int, input().split()))\nfirstList = list(map(int, input().split()))\nsecondList = list(map(int, input().split()))\n\nminFirstList = min(firstList)\nminSecondList = min(secondList)\n\nrepeatedNums = []\n\nfor n in firstList:\n if(n in secondList):\n repeatedNums.append(n)\n\nif(len(repeatedNums)):\n print(min(repeatedNums))\nelif(minFirstList in secondList):\n print(minFirstList)\nelif(minSecondList in firstList):\n print(minSecondList)\nelse:\n digitA = min(minFirstList, minSecondList)\n digitB = max(minFirstList, minSecondList)\n print(str(digitA) + str(digitB))\n \t\t \t \t \t \t\t \t\t \t \t", "n, m = map(int, input().split())\na = set(map(int, input().split()))\nb = set(map(int, input().split()))\nc = a.intersection(b)\n\nif c:\n print(min(c))\nelse:\n x = min(a.union(b))\n if x in a:\n print(x, min(b), sep='')\n else:\n print(x, min(a), sep='')\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,m = get_int_list()\r\nlst1 = get_int_list()\r\nlst2 = get_int_list()\r\nl1 = min(lst1)\r\nl2 = min(lst2)\r\n\r\n\r\nlst = []\r\nfor i in lst1:\r\n for j in lst2:\r\n if i == j:\r\n lst.append(i)\r\n\r\nif len(lst) != 0:\r\n print(min(lst))\r\nelif l1 < l2:\r\n print(l1*10 + l2)\r\nelse:\r\n print(l2*10 + l1)", "n, m = map(int, input().split())\na1 = list(map(int, input().split()))\na2 = list(map(int, input().split()))\n\nc = set(a1) & set(a2)\nif c:\n\tprint(min(c))\n\texit()\nb1 = min(a1)\nb2 = min(a2)\nif b1 == b2:\n\tprint(b1)\nelif b1 > b2:\n\tprint(b2 * 10 + b1)\nelse:\n\tprint(b1 * 10 + b2)\n", "input()\r\nv_1 = input()\r\nv_2 = input()\r\nv_1 = v_1.split()\r\nv_2 = v_2.split()\r\nv_1.sort()\r\nv_2.sort()\r\nfor i in v_1 :\r\n if i in v_2 :\r\n print(i)\r\n raise SystemExit\r\na = v_1[0]\r\nc = v_2[0]\r\nprint(min(a,c)+max(a,c))\r\n", "n, m = map(int, input().split())\r\nl1 = list(map(int, input().split()))\r\nl2 = list(map(int, input().split()))\r\n\r\ndef main():\r\n for i in range(1, 10):\r\n if i in l1 and i in l2:\r\n print(i)\r\n return\r\n\r\n l1.sort()\r\n l2.sort()\r\n a = min(l1)\r\n b = min(l2)\r\n print(min(10*a + b, 10*b + a))\r\n\r\nmain()\r\n", "input()\r\na = set(input()) - {' '}\r\nb = set(input()) - {' '}\r\nab = a & b\r\nprint(min(ab) if ab else min(min(a) + min(b), min(b) + min(a)))", "import sys\r\na,b=map(int,input().split())\r\nm=list(map(int,input().split()))\r\nn=list(map(int,input().split()))\r\nfor i in range(1,10):\r\n if i in m and i in n:\r\n print(i)\r\n exit(0)\r\nx=min(m)\r\ny=min(n)\r\nsys.stdout.write(\"%d%d\"%(min(x,y),max(x,y)))", "#a = int(input())\nn, m = map(int, input().split())\nan = list(map(int, input().split()))\nam = list(map(int, input().split()))\nan.sort()\nan[:]\nam.sort()\nam[:]\ni = 0\nj = 0\nflag = True\nwhile i < n and j < m:\n if an[i] > am[j]:\n j += 1\n elif an[i] < am[j]:\n i += 1\n else:\n flag = False\n print(an[i])\n break\nif flag:\n l = min(an[0], am[0])\n r = max(an[0], am[0])\n if l == r:\n print(l)\n else:\n print(10 * l + r)", "a,b = list(map(int,input().split()))\r\nl1 = list(map(int,input().split()))\r\nl2 = list(map(int,input().split()))\r\nl = []\r\n\r\nm1 = min(l1)\r\nm2 = min(l2)\r\nl3 = [i for i in l1 if i in l2]\r\n\r\nif l3:\r\n l3.sort()\r\n print(l3[0])\r\nelse:\r\n l.append(m1)\r\n l.append(m2)\r\n l.sort()\r\n for i in l:\r\n print(i,end=\"\")", "from sys import stdin, stdout\nn, m = [int(x) for x in stdin.readline().split()]\na = set([int(x) for x in stdin.readline().split()])\nb = set([int(x) for x in stdin.readline().split()])\n\nc = a & b\nif len(c) != 0:\n stdout.write('{}\\n'.format(min(c)))\nelse:\n d = min(min(a), min(b))\n e = max(min(a), min(b))\n stdout.write('{}{}\\n'.format(d, e))\n", "tmp = input().split()\r\nn = int(tmp[0])\r\nm = int(tmp[1])\r\n\r\na = input().split()\r\nb = input().split()\r\n\r\nres1 = min(a)\r\nres2 = min(b)\r\nfl = False\r\n\r\nfor i in range(1,10):\r\n\tif (str(i) in a and str(i) in b):\r\n\t\tprint(i)\r\n\t\tfl = True\r\n\t\tbreak\r\n\r\nif (fl == False):\r\n\tout1 = str(res1)+str(res2)\r\n\tout2 = str(res2)+str(res1)\r\n\tif (int(out1) > int(out2)):\r\n\t\tprint(out2)\r\n\telse:\r\n\t\tprint(out1)\r\n\r\n", "def main():\r\n\t(n, m) = (int(x) for x in input().split())\r\n\tA = set([int(x) for x in input().split()])\r\n\tB = set([int(x) for x in input().split()])\r\n\tprint(solver(A, B))\r\n\r\ndef solver(A, B):\r\n\tcup = A & B\r\n\tif len(cup) != 0:\r\n\t\treturn cup.pop()\r\n\telse:\r\n\t\ta = min(A)\r\n\t\tb = min(B)\r\n\t\ts, l = min(a, b), max(a, b)\r\n\t\treturn 10 * s + l\r\n\r\nmain()\t", "input()\r\na = set(map(int, input().split()))\r\nb = set(map(int, input().split()))\r\nx = a.intersection(b)\r\nif x != set():\r\n print(sorted(x)[0])\r\nelse:\r\n print(str(min(sorted(a)[0],sorted(b)[0])) + str(max(sorted(a)[0],sorted(b)[0])))\r\n", "input()\r\narr1 = list(map(int, input().split()))\r\narr2 = list(map(int, input().split()))\r\nx = min(arr1)\r\ny = min(arr2)\r\nif set(arr1) & set(arr2):\r\n print(min(list(set(arr1)&set(arr2))))\r\nelse:\r\n print(str(min(x, y)) + str(max(x, y)))#kek", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\na.sort()\r\nf=0\r\nfor i in range (n):\r\n\tif a[i] in b:\r\n\t\tprint(a[i])\r\n\t\tf=1\r\n\t\tbreak\r\nif f==0:\r\n\tb=min(b)\r\n\tprint((min(a[0],b)*10)+max(a[0],b))\t", "input()\nl1=[*map(int,input().split())]\nl2=[*map(int,input().split())]\nf=list(set(l1).intersection(set(l2)))\nif len(f)>0:\n print(min(f))\nelse:\n a=min(l1)\n b=min(l2)\n print(min(a,b),max(a,b),sep=\"\")\n'''\n4 5\n3 2 4 5\n1 6 5 9 8\n'''", "import sys\r\n\r\nn, m = [int(i) for i in input().split(' ')]\r\nlist1 = [int(i) for i in input().split(' ')]\r\nlist2 = [int(i) for i in input().split(' ')]\r\n\r\ninter = set(list1).intersection(list2)\r\ntry:\r\n\tprint(min(inter))\r\nexcept ValueError:\r\n\r\n\tl1 = min(list1)\r\n\tl2 = min(list2)\r\n\r\n\tif l1 < l2:\r\n\t\tprint(l1*10 + l2)\r\n\telse:\r\n\t\tprint(l2*10 + l1)\r\n", "n, m = list(map(int,input().split()))\na = set(map(int,input().split()))\nb = set(map(int,input().split()))\nif a & b:\n print(min(a & b))\nelse:\n if min(a)< min(b):\n print(str(min(a)) + str(min(b)))\n else:\n print(str(min(b)) + str(min(a)))\n \t\t \t\t\t\t \t \t\t\t \t \t", "#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-08 23:22:54\nLastEditTime: 2021-11-12 00:09:53\nDescription: Search for Pretty Integers\nFilePath: CF870A.py\n'''\n\n\ndef func():\n _, _ = map(int, input().strip().split())\n lst1 = set(map(int, input().strip().split()))\n lst2 = set(map(int, input().strip().split()))\n if len(lst1 & lst2) != 0:\n print(min(lst1 & lst2))\n else:\n a, b = sorted([min(lst1), min(lst2)])\n print(str(a) + str(b))\n\n\nif __name__ == '__main__':\n func()\n", "input()\r\na = input().split()\r\nb = input().split()\r\n\r\nfor i in range(1,10):\r\n if str(i) in a and str(i) in b:\r\n print(i)\r\n exit()\r\n\r\nans = str(min(a)) + str(min(b))\r\nprint(min(ans) + '' + max(ans))", "n, m = [int(i) for i in input().split()]\nlista1, lista2 = [], []\n[lista1.append(int(i)) for i in input().split()]\n[lista2.append(int(i)) for i in input().split()]\n\nnas2listas = []\n\nfor i in lista1:\n if i in lista2 and i not in nas2listas:\n nas2listas.append(i)\n\nfor i in lista2:\n if i in lista1 and i not in nas2listas:\n nas2listas.append(i)\n\nif nas2listas:\n out = min(nas2listas)\nelse:\n min1 = min(lista1)\n min2 = min(lista2)\n\n if min1 > min2:\n min1, min2 = min2, min1\n\n out = min1 * 10 + min2\nprint(out)\n\n", "n,m=map(int,input().split())\r\nl1=list(map(int,input().split()))\r\nl2=list(map(int,input().split()))\r\nl1.sort()\r\nl2.sort()\r\nc=1\r\nfor i in l1:\r\n if i in l2:\r\n c=0\r\n print(i)\r\n break\r\nif c:\r\n if l1[0]<l2[0]:\r\n print(l1[0]*10+l2[0])\r\n else:\r\n print(l2[0]*10+l1[0]) \r\n \r\n \r\n", "n, m = map(int, input().split())\na = sorted(list(map(int, input().split())))\nb = sorted(list(map(int, input().split())))\nfor i in range(1, 10000):\n num = str(i)\n a1 = False\n b1 = False\n for k in num:\n if int(k) in a:\n a1 = True\n if int(k) in b:\n b1 = True\n if a1 and b1:\n print(i)\n exit()\n", "i=lambda:{*input().split()}\r\ni()\r\na,b=i(),i()\r\nc,d=sorted([min(a),min(b)])\r\nprint([c+d,min({'9'}|a&b)][len(a&b)>0])", "import sys;\r\n\r\n#sys.stdin = open(\"input.txt\", \"r\");\r\n#sys.stdout = open(\"output.txt\", \"w\");\r\n\r\ndef ria():\r\n return [int(x) for x in input().split()];\r\n\r\nn, m = (int(x) for x in input().split());\r\n\r\na = ria();\r\nb = ria();\r\na.sort();\r\nb.sort();\r\n\r\ntf = 0;\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i] == b[j]:\r\n tf = 1;\r\n atg = a[i];\r\n break;\r\n if ( tf == 1 ):\r\n break;\r\n\r\nif ( tf == 1 ):\r\n ans = atg;\r\nelse:\r\n ans = str(min(a[0], b[0])) + str(max(a[0], b[0]));\r\n\r\n\r\nprint(ans);\r\n\r\n\r\n#sys.stdout.close();\r\n", "a = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\na.sort()\r\nb.sort()\r\nfor i in a:\r\n if b.count(i) > 0:\r\n print(i)\r\n exit()\r\nprint(min(a[0], b[0]) * 10 + max(a[0], b[0]))", "n,m=map(int,input().split())\r\na=set(input().split())\r\nc=a.copy()\r\nb=set(input().split())\r\nc&=b\r\nif c:\r\n print(int(min(c)))\r\nelse:\r\n mia=int(min(a))\r\n mib=int(min(b))\r\n if mia<mib:\r\n print(mia*10+mib)\r\n else:\r\n print(mib*10+mia)\r\n", "tamanhos = input().split(\" \")\nlista1 = input().split(\" \")\nlista2 = input().split(\" \")\n\nt1 = int(tamanhos[0])\nt2 = int(tamanhos[1])\nm1 = int(lista1[0])\nm2 = int(lista2[0])\nmenor_igual = 10\nnum = 0\n\nfor i in range(t1):\n if int(lista1[i]) < m1:\n m1 = int(lista1[i])\n\nfor l in range(t2):\n if int(lista2[l]) < m2:\n m2 = int(lista2[l])\n\nfor n in range(t1):\n for m in range(t2): \n if (int(lista1[n]) == int(lista2[m])) and (int(lista1[n]) < menor_igual):\n menor_igual = int(lista1[n])\n\nif menor_igual < 10:\n num = menor_igual\nelse:\n if(m1 > m2):\n num += m2*10\n num += m1\n elif(m2 > m1):\n num += m1 * 10\n num += m2\n else:\n num += m1\nprint(num)\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\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nm1=min(a)\r\nm2=min(b)\r\ns=set(a) & set(b)\r\nif(len(s)!=0):\r\n print(min(s))\r\nelif(m1<m2):\r\n print(str(m1)+str(m2))\r\nelse:\r\n print(str(m2)+str(m1))", "input()\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\na=sorted(a)\r\nb=sorted(b)\r\nc=[]\r\nfor x in a:\r\n for y in b:\r\n if x==y:c.append(x)\r\nc=sorted(c)\r\nif len(c)>0:\r\n print(c[0])\r\nelse:\r\n print(min(a[0],b[0])*10+max(a[0],b[0]))", "n, m = map(int, input().split())\na = set(map(int, input().split()))\nb = set(map(int, input().split()))\nc = min(a)\nd = min(b)\ne = a & b\nif len(e) != 0:\n print(min(e))\nelse:\n print(str(min(c, d)) + str(max(c, d)))\n", "def pretty_int(arr1,arr2, n, m):\n\n for val in arr1:\n if val in arr2:\n return val\n\n a = arr1[0]\n b = arr2[0]\n if a > b:\n a,b=b,a\n return (a*10)+b\n\nn,m = map(int, input().split())\narr1 = sorted(list(map(int, input().split())))\narr2 = sorted(list(map(int, input().split())))\n\nprint(pretty_int(arr1,arr2, n, m))", "s=input()\r\nd1=input()\r\nd2=input()\r\na1=[]\r\na2=[]\r\nfor k in d1.split(' '):\r\n a1.append(int(k))\r\nfor k in d2.split(' '):\r\n a2.append(int(k))\r\na1=sorted(a1)\r\na2=sorted(a2)\r\nres=0\r\nfor i in a1:\r\n if i in a2:\r\n res=i\r\n break\r\nif not res:\r\n res=min(a1[0],a2[0])*10+max(a1[0],a2[0])\r\nprint(res)", "n, m = map(int, input().split())\r\narray_n = list(map(int, input().split()))\r\narray_m = list(map(int, input().split()))\r\nx = 10\r\nfor i in range(n):\r\n if array_n[i] in array_m:\r\n if array_n[i] < x:\r\n x = array_n[i]\r\nif x < 10:\r\n print(x)\r\nelse:\r\n a = min(array_n)\r\n b = min(array_m)\r\n print(10 * min(a, b) + max(a, b))\r\n", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\na.sort()\r\nb.sort()\r\nl=[]\r\nfor i in a:\r\n if i in b:\r\n l.append(i)\r\nif(len(l)!=0):\r\n l.sort()\r\n print(l[0])\r\nelse:\r\n print(min(a[0],b[0]),end=\"\")\r\n print(max(b[0],a[0]))", "entry = input()\r\n\r\nl1 = list(map(int,input().split()))\r\nl2 = list(map(int,input().split()))\r\n\r\nfound = False\r\nfor i in range(10):\r\n if(i in l1 and i in l2):\r\n print(i)\r\n found = True\r\n break\r\n\r\nif(not found):\r\n min_l1 = min(l1)\r\n min_l2 = min(l2)\r\n if(min_l1 < min_l2):\r\n print(\"%d%d\"%(min_l1,min_l2))\r\n else:\r\n print(\"%d%d\"%(min_l2,min_l1))", "\nimport sys\n\narr = list(map(int,input().split()))\nn = arr[0]\nm = arr[1]\n\nn_arr = list(map(int,input().split()))\nm_arr = list(map(int,input().split()))\n\nn_arr.sort()\nm_arr.sort()\n\nshort_arr = []\nlong_arr = []\n\nif m > n : \n short_arr = n_arr\n long_arr = m_arr\nelse:\n short_arr = m_arr\n long_arr = n_arr\n\nfor i in long_arr:\n if i in short_arr:\n print(i)\n sys.exit(0)\n \nprint(min(str(short_arr[0])+str(long_arr[0]),str(long_arr[0]) + str(short_arr[0])))\n", "n,m=[int(x) for x in input().split(\" \")]\r\nl1=[int(x) for x in input().split(\" \")]\r\nl2=[int(x) for x in input().split(\" \")]\r\ncommon=list(set(l1) & set(l2))\r\nif len(common):\r\n print(min(common))\r\nelse:\r\n l1=min(l1)\r\n l2=min(l2)\r\n print(l1,l2,sep=\"\") if l1<l2 else print(l2,l1,sep=\"\")", "input()\r\ns1 = list(map(int, input().split()))\r\ns2 = list(map(int, input().split()))\r\n\r\na = min(s1)\r\nb = min(s2)\r\n\r\nr = set(s1).intersection(set(s2))\r\nif len(r) > 0:\r\n print(min(r))\r\nelse:\r\n print(str(min(a, b))+str(max(a, b)))", "n, m = input().split()\r\na = set(input().split())\r\nb = set(input().split())\r\nprint(min(a&b) if a&b else min(min(a)+min(b), min(b)+min(a)) )", "read = lambda: tuple(map(int, input().split()))\nread()\nn, m = read(), read()\n\ndef main():\n a, b = min(n), min(m)\n for i in range(1, 10):\n if i in n and i in m:\n print(i)\n return\n if a != b:\n print(str(min(a, b)) + str(max(a, b)))\nmain()\n", "n,m=map(int, input().split())\r\na=set(input().split())\r\nb=set(input().split())\r\nc=a&b\r\nif c:\r\n print(min(c))\r\nelse:\r\n print(min(min(a)+min(b),min(b)+min(a)))", "q = [int(i) for i in input().split()]\nN1 = [int(i) for i in input().split()]\nN2 = [int(i) for i in input().split()]\n\nN1.sort()\nN2.sort()\nc=0\nfor i in N1:\n if i in N2:\n print(i)\n c=1\n break\nif c != 1:\n if N1[0] == N2[0]:\n print(N1[0])\n elif N1[0] > N2[0]:\n print(str(N2[0])+str(N1[0]))\n else:\n print(str(N1[0])+str(N2[0]))\n\t\t \t\t\t\t\t \t \t \t\t\t\t \t\t \t\t \t", "def main():\n n, m = map(int, input().split())\n first = list(map(int, input().split()))\n second = list(map(int, input().split()))\n first = sorted(first)\n second = sorted(second)\n\n bigger = len(first) > len(second)\n if bigger:\n for i in range(n):\n if first[i] in second:\n return first[i]\n else:\n for i in range(m):\n if second[i] in first:\n return second[i]\n\n nums = [first[0], second[0]]\n nums = sorted(nums)\n if nums[0] == nums[1]:\n return nums[0]\n else:\n return int(str(nums[0]) + str(nums[1]))\n\nprint(main())\n\t \t\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\na=set(map(int,input().split()))\r\nb=set(map(int,input().split()))\r\nif a&b:\r\n print(min(a&b))\r\nelse:\r\n x=min(a)\r\n y=min(b)\r\n print(min(x,y)*10+max(x,y))", "\r\nn, m = list(map(int, input().split()))\r\n\r\nl1 = list(map(int, input().split()))\r\nl2 = list(map(int, input().split()))\r\n\r\nn1 = min(l1)\r\nn2 = min(l2)\r\nintersection = set(l1).intersection(l2)\r\n\r\nif len(intersection) != 0:\r\n print(min(intersection))\r\nelse:\r\n if n1 > n2:\r\n print(str(n2)+str(n1))\r\n else:\r\n print(str(n1)+str(n2)) \r\n", "input()\na=set([int(x) for x in input().split()])\nb=set([int(x) for x in input().split()])\nc = a&b\nif len(c)>0:\n print(sorted(list(c))[0])\nelse:\n a = sorted(list(a))[0]\n b = sorted(list(b))[0]\n if a>b:\n print(b,a,sep=\"\")\n else:\n print(a,b,sep=\"\")", "n, m = map(int, input().split())\r\n\r\narr1 = input().split()\r\narr2 = input().split()\r\n\r\n_min = 2147483647\r\n\r\nfor i in arr1:\r\n\tfor j in arr2:\r\n\t\tif i == j and int(i) < _min:\r\n\t\t\t_min = int(i)\r\n\t\telif min(int(i + j), int(j + i)) < _min:\r\n\t\t\t_min = min(int(i + j), int(j + i))\r\n\r\nprint(_min)", "n,m=map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nma=min(a)\r\nmb=min(b)\r\nfor i in range(1,10):\r\n if i in a and i in b:\r\n print(i)\r\n break\r\nelse:\r\n print(str(min(ma,mb))+str(max(ma,mb)))\r\n", "s=[int(n) for n in input().split()]\r\na=[int(n) for n in input().split()]\r\nb=[int(n) for n in input().split()]\r\nz=[]\r\nfor n in range(len(a)):\r\n\tfor k in range(len(b)):\r\n\t\tif a[n]!=b[k]:\r\n\t\t\tz.append(min(a[n],b[k])*10+max(a[n],b[k]))\r\n\t\telse:\r\n\t\t\tz.append(a[n])\r\nprint(min(z))", "n,m=(map(int,input().strip().split(' ')))\r\na=list(map(int,input().strip().split(' ')))\r\nb=list(map(int,input().strip().split(' ')))\r\nans=0\r\nfor i in range(1,10):\r\n if(i in a and i in b):\r\n print(i)\r\n ans=1\r\n break\r\nif(ans==0):\r\n m=min(a)\r\n m2=min(b)\r\n print(min(m,m2),end='')\r\n print(max(m,m2),end='')", "#██████████ █ █ /█\\ █ █ ███ /█\\ ██████████████\r\n\"█ █ █ /███\\ █ █ █ ██ /███\\ /██/ \"\r\n#█ █ █ /█████\\ █ █ █ ██ /█████\\ /██/ \r\n\"█ █ █ █!:) █ █ █ █ ██ █ █ /██/ \"\r\n#██████████ █████████ █(:| █ ████████ ████ █ █ /██/ \"\r\n\" █ █ █ █!:) █ █ █ █ ██ █ █ /██/ \"\r\n# █ █ █ ███████ █ █ █ ██ ███████ /██/\r\n\" █ █ █ █ █ █ █ █ ██ █ █ ██/ \"\r\n#██████████ █ █ █ █ █ █ ███ █ █ ██████████████\r\nla,lb=map(int,input().split())\r\narr_a=sorted(list(set(list(map(int,input().split())))))\r\narr_b=sorted(list(set(list(map(int,input().split())))))\r\nfor i in range(la):\r\n if arr_a[i] in arr_b:\r\n print(arr_a[i])\r\n quit()\r\nif arr_a[0]>arr_b[0]:\r\n print(str(arr_b[0])+str(arr_a[0]))\r\nelif arr_a[0]<arr_b[0]:\r\n print(str(arr_a[0])+str(arr_b[0]))\r\n", "a=input().split(' ')\nn=int(a[0])\nm=int(a[1])\na=input().split(' ')\ni1=[]\nfor i in range(n):\n i1.append(int(a[i]))\na=input().split(' ')\ni2=[]\nfor i in range(m):\n i2.append(int(a[i]))\na=min(i1)\nb=min(i2)\nif a==b:\n print(a)\n exit()\nm=[]\nfor i in i1:\n if i in i2:\n m.append(i)\nif len(m)>0:\n print (min(m))\n exit()\nprint(min(a,b)*10+max(a,b))\n", "pl = input().split()\r\nn = int(pl[0])\r\nm = int(pl[1])\r\na = input().split()\r\nb = input().split()\r\nminimum = 1000000000\r\nt = False\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i] == b[j] and int(a[i])< int(minimum):\r\n minimum = int(a[i])\r\n t = True\r\nif t:\r\n print(minimum)\r\nelse:\r\n print(str(min(min(a),min(b))) + str(max(min(a),min(b))))\r\n \r\n", "class CodeforcesTask870ASolution:\n def __init__(self):\n self.result = ''\n self.l1 = []\n self.l2 = []\n\n def read_input(self):\n input()\n self.l1 = input().split(\" \")\n self.l2 = input().split(\" \")\n\n def process_task(self):\n x = 1\n while True:\n in1 = False\n in2 = False\n for c in str(x):\n if c in self.l1:\n in1 = True\n if c in self.l2:\n in2 = True\n if in1 and in2:\n break\n x += 1\n self.result = str(x)\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask870ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n", "n, m = map(int, input().split())\r\nn = set(map(int, input().split()))\r\nm = set(map(int, input().split()))\r\n\r\np = list(n & m)\r\n\r\nif len(p) > 0 :\r\n print(min(p))\r\nelse :\r\n ans = min(min(n) * 10 + min(m), min(m) * 10 + min(n))\r\n print(ans)", "a,b=map(int,input().split())\r\nn=list(map(int,input().split()))\r\nm=list(map(int,input().split()))\r\nn.sort()\r\nm.sort()\r\ns=''\r\nx=min(n)\r\nz=min(m)\r\nk=min(x,z)\r\nz=max(x,z)\r\nx=k\r\nfor i in n:\r\n if i in m:\r\n print(i)\r\n break\r\n\r\n\r\n\r\n\r\nelse:\r\n s+=str(x)\r\n s+=str(z)\r\n print(s)", "n, m = map(int, input().split())\r\na1 = list(map(int, input().split()))\r\na2 = list(map(int, input().split()))\r\nt = 10\r\nfor q in range(n):\r\n for g in range(m):\r\n if a1[q] == a2[g]:\r\n if a1[q] < t:\r\n t = a1[q]\r\nif t != 10:\r\n print(t)\r\n exit(0)\r\ni = min(a1)\r\nj = min(a2)\r\nansw = min(i,j)*10 + max(i,j)\r\nprint(answ)", "a,b=map(int,input().split())\r\na1=list(map(int,input().split()))\r\na2=list(map(int,input().split()))\r\na1=set(a1)\r\na2=set(a2)\r\ns1=str(min(a1))\r\ns2=str(min(a2))\r\nif len(a1&a2)>0:\r\n print(min(a1&a2))\r\nelse:\r\n print(min(int(s1+s2),int(s2+s1)))\r\n", "input()\na = set(map(int,input().split()))\nb = set(map(int,input().split()))\nx = y = float('inf')\nboth = None\nfor i in range(9,0,-1):\n if i in a:\n x = i\n if i in b:\n y = i\n if i in a and i in b:\n both = i\nif both:\n print(both)\nelse:\n print(min(x*10+y,y*10+x))\n", "n=input().split()\r\na=input().split()\r\nb=input().split()\r\na.sort()\r\nb.sort()\r\nd=0\r\nfor i in a:\r\n for j in b:\r\n if(i==j):\r\n d=int(i)\r\n break\r\n if(d>0):\r\n break\r\nif(d>0):\r\n print(d)\r\nelif(a[0]<b[0]):\r\n print(a[0]+b[0])\r\nelse:\r\n print(b[0]+a[0])\r\n", "input()\nl1 = [int(x) for x in input().split()]\nl2 = [int(x) for x in input().split()]\n\ndef isPretty(x):\n if x < 10:\n return x in l1 and x in l2\n x1 = x % 10\n x2 = x // 10\n \n if x1 not in l1 and x2 not in l1:\n return False\n if x1 not in l2 and x2 not in l2:\n return False\n return True\n\nfor i in range(99):\n if isPretty(i):\n print(i)\n break\n", "n, m = map(int, input().split())\na = set(map(int, input().split()))\nb = set(map(int, input().split()))\nmutual = a.intersection(b)\nif mutual:\n print(min(mutual))\nelse:\n fir, sec = sorted([min(a), min(b)])\n print(fir*10+sec)\n\n", "one, two = input().split()\r\none, two = int(one), int(two)\r\n\r\na1 = set(map(int, input().split()))\r\na2 = set(map(int, input().split()))\r\nm1 = min(a1)\r\nm2 = min(a2)\r\n\r\nif len(a1.intersection(a2)) > 0:\r\n print(min(a1.intersection(a2)))\r\nelse:\r\n if m1 < m2:\r\n print(str(m1) + str(m2))\r\n else:\r\n print(str(m2) + str(m1))\r\n", "# cook your dish here\r\nn,m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nma = 10\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i]==b[j]:\r\n if a[i]<ma:\r\n ma = a[i]\r\nif ma!=10:\r\n print(ma)\r\nelse:\r\n x = min(a)\r\n y = min(b)\r\n if x==y:\r\n print(x)\r\n elif x>y:\r\n print(y*10 + x)\r\n else:\r\n print(x*10 + y)", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\na.sort()\r\nb.sort()\r\n#print(a)\r\n#print(b)\r\n\r\nfor i in range(n):\r\n #print(\"1st\")\r\n if(a[i] in b):\r\n \r\n ma=a[i]\r\n print(ma)\r\n break\r\n\r\nelse:\r\n d1=int(str(a[0]) + str(b[0]))\r\n d2=int(str(b[0]) + str(a[0]))\r\n\r\n\r\n print(min(d1,d2))", "a,b=input().split(\" \")\na=int(a)\nb=int(b)\nstr_in1 = input()\nstr_in2 = input()\nnuma=[a]\nnuma = [int(n) for n in str_in1.split()] \nnumb=[b]\nnumb = [int(n) for n in str_in2.split()] \nnuma.sort()\nnumb.sort()\ni=0\nj=0\nflag=0\npp=[]\nwhile(i<a):\n j=0\n while(j<b):\n if(numa[i]==numb[j]):\n pp.append(numa[i])\n flag=1\n j+=1\n i+=1\nif(flag==1):\n pp.sort()\n print(pp[0])\nif(flag==0):\n print(str(min(numa[0],numb[0]))+str(max(numa[0],numb[0])))", "n,m = input().split()\r\nlist1 = sorted(map(int, input().split()))\r\nlist2 = sorted(map(int, input().split()))\r\nb =set(list1)\r\nc = set(list2)\r\nif(b.intersection(c)):\r\n print(min(b.intersection(c)))\r\nelse:\r\n if(list1[0] < list2[0]):\r\n print(\"%d%d\"%(list1[0], list2[0]))\r\n else:\r\n print(\"%d%d\"%(list2[0], list1[0]))\r\n", "import sys\n\n\ndef main():\n n, k = map(int, sys.stdin.readline().split())\n x = list(map(int, sys.stdin.readline().split()))\n y = list(map(int, sys.stdin.readline().split()))\n\n v = set(x).intersection(y)\n if len(v) == 0:\n c = [min(x) * 10 + min(y), min(y) * 10 + min(x)]\n print(min(c))\n else:\n print(min(v))\n\n\nmain()\n", "a=input().split()\r\nb=input().split()\r\nc=int(min(b))\r\nd=input().split()\r\ne=int(min(d))\r\nf=len(b)\r\ni=0\r\nlst=[]\r\nfor i in b:\r\n for k in d:\r\n if(int(i)==int(k)):\r\n lst.append(int(i))\r\ng=len(lst)\r\nif(g>0):\r\n print(min(lst))\r\nelse:\r\n if(c>e):\r\n v=(10*e)+c\r\n print(v)\r\n elif(e>c):\r\n t=(10*c)+e\r\n print(t)\r\n", "tamanhos = input()\r\ntl1, tl2 = tamanhos.split()\r\n\r\nlista1 = input().split()\r\nlista1 = list(map(int, lista1))\r\nlista2 = input().split()\r\nlista2 = list(map(int, lista2))\r\n\r\nambos = set()\r\nfor ele in lista1:\r\n if(ele in lista2): ambos.add(ele)\r\n\r\nif(len(ambos) != 0): print(min(ambos))\r\nelse:\r\n min1 = min(lista1)\r\n min2 = min(lista2)\r\n if(min1 < min2 ): print(str(min1) + str(min2))\r\n else: print(str(min2) + str(min1))", "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,m = get_int_list()\r\nlst1 = get_int_list()\r\nlst2 = get_int_list()\r\nmx = 10**10\r\nans = [10**10,10**10]\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if lst1[i] == lst2[j]:\r\n mx = min(mx,lst1[i])\r\n ans[0] = min(ans[0],lst1[i])\r\n ans[1] = min(ans[1],lst2[j])\r\n\r\nif mx != 10**10:\r\n print(mx)\r\nelse:\r\n ans.sort()\r\n print(ans[0]*10+ans[1])\r\n", "def nice_numbers(lst1, lst2):\r\n a, b = set(lst1), set(lst2)\r\n if a & b:\r\n return min(a & b)\r\n else:\r\n c, d = min(a), min(b)\r\n return str(min(c, d)) + str(max(c, d))\r\n\r\n\r\nn, m = [int(i) for i in input().split()]\r\nk1 = [int(j) for j in input().split()]\r\nk2 = [int(z) for z in input().split()]\r\nprint(nice_numbers(k1, k2))\r\n", "n, m = input().split()\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\ndup = []\na.sort()\nb.sort()\nc = a[0]\nd = b[0]\n\nfor i in a:\n if(i in b):\n dup.append(i)\n break\n\n##print(dup)\n\nif(len(dup) > 0):\n print(min(dup))\nelse:\n print(str(min(c, d))+str(max(c, d)))\n\n\t\t \t\t\t\t\t\t\t \t\t\t \t \t \t \t \t\t \t\t\t", "input();a=list(map(int,input().split()));b=list(map(int,input().split()))\r\nc=sorted([i for i in a if i in b])\r\nx,y=min(a),min(b)\r\nprint(c[0] if len(c)!=0 else str(min(x,y))+str(max(x,y)))", "n, m = map(int, input().split())\r\nls1 = list(map(int, input().split()))\r\nls2 = list(map(int, input().split()))\r\ntry: print(min(set(ls1).intersection(set(ls2))))\r\nexcept: print(min(int(str(min(ls1))+str(min(ls2))), int(str(min(ls2))+str(min(ls1)))))\r\n", "def solve(a, b, n, m):\n a = sorted(a)\n b = sorted(b)\n if a[0] == b[0]:\n return a[0]\n min_val = min(a[0], b[0])\n max_val = max(a[0], b[0])\n min_val = int(f\"{min_val}{max_val}\")\n for i in a:\n for j in b:\n if i == j:\n if i < min_val:\n min_val = i\n\n return min_val\n\n\ndef main():\n vars = list(map(int, input().split(\" \")))\n # n = int(input())\n a = list(map(int, input().split(\" \")))\n b = list(map(int, input().split(\" \")))\n # for i in range(n):\n # arr.append(list(map(int, list(input()))))\n print(solve(a, b, *vars))\n\n\nmain()\n", "n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\naa = set(a)\r\nbb = set(b)\r\ncc = aa.intersection(bb)\r\nif(len(cc) > 0):\r\n\tprint(min(list(cc)))\r\nelse:\r\n\taz = min(a)\r\n\tbz = min(b)\r\n\tq = min(az,bz)\r\n\tw = max(az,bz)\r\n\tprint(str(q)+str(w))", "a=list(map(int,input().split()))\r\nn=a[0]\r\nm=a[1]\r\nb=list(map(int,input().split()))\r\nc=list(map(int,input().split()))\r\nb.sort()\r\nc.sort()\r\nz=0\r\nfor i in range(0,n):\r\n for j in range(0,m):\r\n if b[i]==c[j]:\r\n d=b[i]\r\n z=1\r\n break\r\n else:\r\n continue\r\n if z==1:\r\n break\r\n else:\r\n continue\r\nif z==1:\r\n print(d)\r\nelse:\r\n e=min(b)\r\n f=min(c)\r\n g=min(e,f)\r\n h=max(e,f)\r\n print(10*g+h)\r\n", "N, M = map(int,input().split())\r\nA = list(map(int,input().split()))\r\nB = list(map(int,input().split()))\r\nc = min(x for x in A if x in B) if any(x for x in A if x in B) else 0\r\na, b = min(A), min(B)\r\nif (c): print(c)\r\nelse: print(10*(min(a,b))+max(a,b))", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\ns=[]\r\nfor i in a:\r\n if i in b:s.append(i)\r\nif len(s)>0:print(min(s));exit()\r\nc=min(a);d=min(b)\r\nz=min(c,d);m=max(c,d)\r\nprint(z,m,sep='')", "inp = lambda: list(map(int, input().split()))\r\nget = inp()\r\na = inp()\r\nb = inp()\r\nc = [x for x in a if x in b]\r\nif len(c) > 0: print(min(c))\r\nelse:\r\n a = min(a)\r\n b = min(b)\r\n if a>b:\r\n a,b = b,a\r\n print(a*10+b)\r\n", "s = lambda: set(map(int, input().split()))\r\n\r\ninput()\r\nA, B = s(), s()\r\nC = A & B\r\n\r\nif C:\r\n print(min(C))\r\nelse:\r\n print(*sorted((min(A), min(B))), sep='')", "p,n=map(int,input().split())\r\nx=list(map(int,input().split()))\r\ny=list(map(int,input().split()))\r\nminx=min(x)\r\nminy=min(y)\r\nif minx==miny:\r\n print(minx)\r\n exit()\r\nelse:\r\n for i in range(p):\r\n if x[i]in y:\r\n print(x[i])\r\n exit()\r\n\r\nh=list()\r\nh.append(minx)\r\nh.append(miny)\r\nh=sorted(h)\r\nprint((h[0]*10)+h[1])", "n,m=input().split()\r\na=sorted(list(map(int,input().split())))\r\nb=sorted(list(map(int,input().split())))\r\n#print(a,b)\r\nfor i in range(1,10):\r\n if a.count(i) and b.count(i):\r\n print(i),exit()\r\nif a[0]>b[0]:a[0],b[0]=b[0],a[0]\r\nprint(str(a[0])+str(b[0]))\r\n", "#! /usr/bin/env python3\n\nimport sys\n\nRECURSION_LIMIT = 10**4 + 10\n\nread_list = lambda t: list(map(t, input().split()))\nread_ints = lambda: read_list(int)\n\n\ndef main():\n n, m = read_ints()\n a = read_ints()\n b = read_ints()\n\n common = set(a) & set(b)\n if common:\n print(min(common))\n return\n\n a_min = min(a)\n b_min = min(b)\n print(''.join(map(str, sorted([a_min, b_min]))))\n\n\nif __name__ == '__main__':\n sys.setrecursionlimit(RECURSION_LIMIT)\n main()\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\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\ns = set(b)\r\nans = 100\r\nfor i in a:\r\n if i in s:\r\n ans = min(ans, i)\r\n for j in b:\r\n ans = min(ans, 10 * i + j, 10 * j + i)\r\nprint(ans)", "len_1, len_2 = [int(s) for s in input().split()]\r\ndigits_1 = [int(s) for s in input().split()]\r\ndigits_2 = [int(s) for s in input().split()]\r\n\r\nmin_1 = min(digits_1)\r\nmin_2 = min(digits_2)\r\n\r\nfirst_nice = str(min(min_1, min_2)) + str(max(min_1, min_2))\r\n\r\nintersection = []\r\nfor i in digits_1:\r\n for j in digits_2:\r\n if i == j:\r\n intersection.append(i)\r\n break\r\n\r\nif len(intersection) > 0:\r\n print(min(min(intersection), int(first_nice)))\r\nelse:\r\n print(first_nice)\r\n", "n, m = map(int, input().split())\nxs = list(map(int, input().split()))[:n]\nys = list(map(int, input().split()))[:m]\ncommon = set(xs).intersection(ys)\nif len(common) > 0:\n\tprint(min(common))\nelse:\n\ta = min(xs)\n\tb = min(ys)\n\tif b < a:\n\t\ta, b = b, a\n\tprint(a * 10 + b)", "input()\r\na = [int (i) for i in input().split()]\r\nb = [int (i) for i in input().split()]\r\n\r\n\r\nlst = list()\r\n\r\nfor a_ in a:\r\n for b_ in b:\r\n if a_ == b_:\r\n lst.append(a_)\r\n\r\nif len(lst) != 0:\r\n print(min(lst))\r\nelse:\r\n bb = min(b)\r\n aa = min(a)\r\n if aa < bb:\r\n print(str(aa)+str(bb))\r\n elif bb < aa:\r\n print(str(bb)+str(aa))\r\n", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nq=[]\r\nfor i in range(m):\r\n for j in range(n):\r\n if b[i]==a[j]:\r\n q.append(b[i])\r\nif len(q)>0:\r\n print(min(q))\r\nelse:\r\n print(min(min(a),min(b))*10+max(min(a),min(b)))\r\n", "input()\r\nr=lambda:list(map(int,input().split()))\r\na,b=r(),r()\r\nfor i in range(10):\r\n if i in a and i in b:exit(print(i))\r\naa,bb=min(a),min(b)\r\nif bb<aa:aa,bb=bb,aa\r\nprint(aa,end='')\r\nif aa!=bb:print(bb)", "def main():\n N, M = map(int, input().split())\n A = tuple(map(int, input().split()))\n B = tuple(map(int, input().split()))\n\n for i in sorted(A):\n if i in B:\n print(i)\n break\n else:\n a = min(A)\n b = min(B)\n ans = sorted([a, b])\n print(*ans, sep='')\n\nmain()\n", "n,m=[int(i) for i in input().split()]\r\na=[int(i) for i in input().split()]\r\nb=[int(i) for i in input().split()]\r\nl=[]\r\nfor i in range(0,len(a)):\r\n for j in range(0,len(b)):\r\n if(a[i] in b):\r\n l.append(a[i])\r\n break\r\n else:\r\n l.append(int(str(a[i])+str(b[j])))\r\nfor i in range(0,len(b)):\r\n for j in range(0,len(a)):\r\n if(b[i] in a):\r\n l.append(b[i])\r\n break\r\n else:\r\n l.append(int(str(b[i])+str(a[j])))\r\nprint(min(l))", "n,k = map(int,input().split())\r\n\r\narr = [ int(i) for i in input().split()]\r\n\r\nbrr = [ int(i) for i in input().split()]\r\n\r\narr.sort()\r\nbrr.sort()\r\n\r\nflag = True\r\nfor i in range(len(arr)):\r\n if(arr[i] in brr):\r\n print(arr[i])\r\n flag = False\r\n break\r\nif(flag):\r\n a = min(arr)\r\n b = min(brr)\r\n minm = min(a,b)\r\n maxm = max(a,b)\r\n print(minm*10+maxm)", "a,b = map(int,input().split())\r\nm = sorted(list(map(int,input().split())))\r\nn = sorted(list(map(int,input().split())))\r\nz =0\r\nfor i in m:\r\n\tif i in n:\r\n\t\tz =1\r\n\t\tprint(i)\r\n\t\tbreak\r\nif z !=1:\r\n\tprint(str(min(m[0],n[0]))+str(max(m[0],n[0])))\r\n\r\n\r\n\r\n", "n, m = map(int, input().split())\nlista_1 = list(map(int, input().split()))\nlista_2 = list(map(int, input().split()))\nlista = lista_1 + lista_2\nlista.sort()\nigual = False\ndic = {}\n\nfor elemento in lista:\n if elemento in dic:\n dic[elemento] += 1\n print(elemento)\n igual = True\n break\n else:\n dic[elemento] = 1\n\n\na = min(lista_1)\nb = min(lista_2)\nif not igual:\n print(f\"{min(a, b)}{max(a, b)}\")\n\n \t\t\t\t\t\t \t\t \t\t \t \t\t \t \t", "n, m = map(int, input().split())\r\nx = list(map(int, input().split()))\r\ny = list(map(int, input().split()))\r\n\r\ncommon = set(x) & set(y)\r\nif len(common) > 0:\r\n print(min(common))\r\nelse:\r\n a, b = min(x), min(y)\r\n if a > b:\r\n a, b = b, a\r\n print(10 * a + b)", "p = input()\np = [int(x) for x in p.split(' ')]\nn = p[0]\nm = p[1]\nl1 = [int(x) for x in input().split(' ')]\nl2 = [int(x) for x in input().split(' ')]\nl1.sort()\nl2.sort()\nfor x in range(1,10):\n\tif x in l1 and x in l2:\n\t\tprint(x)\n\t\texit(0)\nl = []\nif l1[0] > l2[0]:\n\tl.append(str(l2[0]))\n\tl.append(str(l1[0]))\nelse:\n\tl.append(str(l1[0]))\n\tl.append(str(l2[0]))\nprint(''.join(l))\nexit(0)\n", "p=input()\r\na=[]\r\nb=[]\r\nq=input()\r\nw=input()\r\nfor elem in q:\r\n if elem!=' ':\r\n a.append(elem)\r\nfor elem in w:\r\n if elem!=' ':\r\n b.append(elem)\r\nk=[]\r\nl=[]\r\nfor elem in a:\r\n if int(elem) in k:\r\n pass\r\n else:\r\n k.append(int(elem))\r\nfor elem in b:\r\n if int(elem) in l:\r\n pass\r\n else:\r\n l.append(int(elem))\r\ne=k+l\r\no=0\r\nfor i in range(10):\r\n if o==0:\r\n if e.count(i)>=2:\r\n print(i)\r\n o=1\r\nn=min(k)\r\nm=min(l)\r\nif o==0:\r\n if m>n:\r\n print(str(n)+str(m))\r\n else:\r\n print(str(m)+str(n))", "def minValueInCommon(A,B):\n setA = set(A)\n setB = set(B)\n intersect = setA.intersection(setB)\n if len(intersect) > 0:\n return min(intersect)\n else:\n return 90 # o valor máximo obtido por concatenação seria 89\n\n# Author: Pedro Adrian Pereira Martinez\nif __name__ == \"__main__\":\n nm = list(map(int,input().split()))\n n,m = nm[0],nm[1]\n A = list(map(int,input().split()))\n B = list(map(int,input().split()))\n A.sort(reverse=True)\n B.sort(reverse=True)\n j,k = A[n-1],B[m-1]\n candidate1 = int(f\"{min(j,k)}{max(j,k)}\")\n candidate2 = minValueInCommon(A,B)\n print(min(candidate1,candidate2))\n\n\t\t\t\t \t\t\t\t\t \t\t\t\t\t \t\t \t \t", "l = list(input().split())\r\nl2 = list(input().split())\r\nl3 = list(input().split())\r\nout = 0\r\n\r\nl2.sort()\r\nl3.sort()\r\not = min(l2[0], l3[0]) + max(l2[0], l3[0])\r\n\r\nfor i in l2:\r\n if out == 1:\r\n break\r\n for i2 in l3:\r\n if i == i2:\r\n ot = i\r\n out = 1\r\n break\r\n\r\nprint(ot)", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\na1=min(a)\r\nb1=min(b)\r\na2=set(a)\r\nb2=set(b)\r\nc=a2 & b2\r\nif len(c)>0:\r\n print(min(c))\r\n quit()\r\nprint(min(a1,b1)*10+max(a1,b1))\r\n", "n,m = map(int, input().split())\na = [int(x) for x in input().split()]\nb = [int(x) for x in input().split()]\n\nfor i in range (1,10):\n\tif i in a and i in b:\n\t\tprint(i)\n\t\texit(0)\nif(min(a)<min(b)):\n\tprint(min(a),min(b),sep='')\nelse:\n\tprint(min(b),min(a),sep='')\n", "n,m=[int(i) for i in input().split()]\r\nl1=[int(i) for i in input().split()]\r\nl2=[int(i) for i in input().split()]\r\nm=101\r\nfor i in l1:\r\n for j in l2:\r\n if i==j:\r\n x=i\r\n elif i>j:\r\n x=10*j+i\r\n else:\r\n x=10*i+j\r\n m=min(x,m)\r\nprint (m)\r\n", "n,m = map(int,input().split())\nmat = set(map(int, input().split()))\nsat = set(map(int, input().split()))\ninter = mat.intersection(sat)\nif len(inter)!=0:\n print(min(inter))\nelse:\n mm = min(mat)\n ms = min(sat)\n print(str(mm)+str(ms) if mm<ms else str(ms)+str(mm))\n", "tmp = input()\narr1 = [ int(x) for x in input().split() ]\narr2 = [ int(x) for x in input().split() ]\n\nmin_arr1 = min(arr1)\nmin_arr2 = min(arr2)\n\ntmp = 100\nfor i in arr1:\n if i in arr2 and i < tmp:\n tmp = i\n\na = [min_arr1, min_arr2]\naa = min(a) * 10 + max(a)\n\nprint(min(aa, tmp))\n", "n,m = map(int, input().split())\r\n\r\na = set(map(int, input().split()))\r\nb = set(map(int, input().split()))\r\nintersect = a.intersection(b)\r\nif len(intersect) > 0:\r\n print(min(intersect))\r\nelse:\r\n mi = min(min(a), min(b))\r\n ma = max(min(a), min(b))\r\n print(str(mi)+str(ma))\r\n", "wasa = [0] * 10\r\nwasb = [0] * 10\r\n\r\ndef good(i):\r\n\ti = str(i)\r\n\ta_was = 0\r\n\tb_was = 0\r\n\tfor x in i:\r\n\t\tif wasa[ord(x)-ord('0')] :\r\n\t\t\ta_was = 1\r\n\t\tif wasb[ord(x)-ord('0')]:\r\n\t\t\tb_was = 1\r\n\tif a_was + b_was == 2 :\r\n\t\treturn 1\r\n\telse:\r\n\t\treturn 0\r\ninput()\r\na = input().split()\r\nb = input().split()\r\n\r\nfor x in a:\r\n\twasa[ord(x) - ord('0')] = 1\r\n \r\nfor x in b:\r\n\twasb[ord(x) - ord('0')] = 1\r\n\r\n\r\n\t\r\nfor i in range(1, 101):\t\r\n\tif(good(i)):\r\n\t\tprint(i)\r\n\t\tbreak\r\n\r\n", "n1,n2=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nsorted_a=sorted(a)\r\nsorted_b=sorted(b)\r\nif sorted_a[0]<sorted_b[0]:\r\n res=str(sorted_a[0])+str(sorted_b[0])\r\nelse:\r\n res = str(sorted_b[0]) + str(sorted_a[0])\r\nf=\"True\"\r\nfor i in sorted_a:\r\n for j in sorted_b:\r\n if i==j and i<int(res):\r\n f=\"false\"\r\n print(i)\r\n break\r\n if f==\"false\":\r\n break\r\nif f==\"True\":\r\n print(res)", "import sys\r\nimport functools\r\ninput()\r\na = input().split()\r\nb = input().split()\r\n\r\nfor i in range(1, 100):\r\n ok = functools.reduce(lambda ok, digit: ok or digit in a, str(i), False) and functools.reduce(lambda ok, digit: ok or digit in b, str(i), False)\r\n if ok:\r\n print(i)\r\n sys.exit()", "n, m = map(int, input().split())\r\nA = set(map(int, input().split()))\r\nB = set(map(int, input().split()))\r\n\r\nC = A & B\r\nif len(C):\r\n print(sorted(C)[0])\r\nelse:\r\n a, b = sorted(A)[0], sorted(B)[0]\r\n if a > b:\r\n a, b = b, a\r\n print(\"%d%d\" % (a, b))\r\n\r\n", "n, m = map(int, input().split())\r\n\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\n\r\na_ = min(min(a), min(b))\r\nb_ = max(min(b), min(a))\r\n\r\nkek = []\r\n\r\nfor i in a:\r\n if i in b:\r\n kek.append(i)\r\n\r\nif len(kek) > 0:\r\n print(min(kek))\r\nelse:\r\n print(10*a_ + b_)", "s = input()\r\nl1 = set(map(int, input().split()))\r\nl2 = set(map(int, input().split()))\r\nl3 = l1 & l2\r\nl1_min = min(l1)\r\nl2_min = min(l2)\r\nif len(l3) > 0:\r\n print(min(l3))\r\nelif l1_min == l2_min:\r\n print(l1_min)\r\nelif l1_min < l2_min:\r\n print('{}{}'.format(l1_min, l2_min))\r\nelse:\r\n print('{}{}'.format(l2_min, l1_min))\r\n", "n,m=list(map(int,input().split()))\r\nn=list(map(int,input().split()))\r\nm=list(map(int,input().split()))\r\nn.sort()\r\nm.sort()\r\np=[]\r\nfor j in n:\r\n if j in m:\r\n p.append(j)\r\nfor k in m:\r\n if k in n:\r\n p.append(k)\r\n\r\nif n[0]<m[0]:\r\n if len(p)>0:\r\n if p[0]>int(str(n[0])+str(m[0])):\r\n print(str(n[0])+str(m[0]))\r\n else:\r\n print(p[0])\r\n else:\r\n print(str(n[0])+str(m[0]))\r\n \r\nelif m[0]<n[0]:\r\n if len(p)>0:\r\n if p[0]>int(str(m[0])+str(n[0])):\r\n print(str(m[0])+str(n[0]))\r\n else:\r\n print(p[0])\r\n else:\r\n print(str(m[0])+str(n[0]))\r\nelif n[0]==m[0]:\r\n if len(p)>0:\r\n if p[0]>n[0]:\r\n print(n[0])\r\n else:\r\n print(m[0])\r\n\r\n", "def compare(x, y):\r\n if x == y:\r\n return x\r\n return 10 * min(x, y) + max(x, y)\r\n\r\n\r\ndef search(lst1, lst2):\r\n result = 99\r\n for i in range(len(lst1)):\r\n for j in range(len(lst2)):\r\n if compare(lst2[j], lst1[i]) < result:\r\n result = compare(lst2[j], lst1[i])\r\n return result\r\n\r\n\r\nn, m = [int(z) for z in input().split()]\r\na = [int(z) for z in input().split()]\r\nb = [int(z) for z in input().split()]\r\nprint(search(a, b))\r\n", "import sys\r\ninput = sys.stdin.buffer.readline \r\n \r\ndef process(A, B):\r\n answer = float('inf')\r\n for x in A:\r\n if x in B:\r\n answer= min(answer, x)\r\n for x in A:\r\n for y in B:\r\n answer= min(answer, 10*min(x, y)+max(x, y))\r\n sys.stdout.write(f'{answer}\\n')\r\n \r\nn, m = [int(x) for x in input().split()]\r\nA = [int(x) for x in input().split()]\r\nB = [int(x) for x in input().split()]\r\nprocess(A, B)", "a, b = [int(x) for x in input().split()]\r\na1 = [int(x) for x in input().split()]\r\nb1 = [int(x) for x in input().split()]\r\nstart = '0'\r\nwhile True:\r\n if len(start) == 1:\r\n if int(start) in a1 and int(start) in b1:\r\n break\r\n else:\r\n if int(start[0]) in a1:\r\n if int(start[1]) in b1:\r\n break\r\n if int(start[0]) in b1:\r\n if int(start[1]) in a1:\r\n break\r\n start = str(int(start) + 1)\r\nprint(start)\r\n", "n , m = map ( int , input (). split ())\r\nl = list ( map ( int , input (). split ()))\r\np = list ( map ( int , input (). split ()))\r\nl.sort()\r\np.sort()\r\ndef algo(l,p):\r\n for i in l:\r\n if i in p:\r\n return i\r\n t = min ( l )\r\n s = min ( p )\r\n x = ( 10 * t ) + s\r\n y = ( 10 * s ) + t\r\n return min(x,y)\r\n\r\n\r\nprint(algo(l,p)) ", "x,y = input().split()\r\nx_lst = set(input().split())\r\ny_lst = set(input().split())\r\n\r\ni = x_lst.intersection(y_lst)\r\n\r\nif i:\r\n print(int(min(x_lst.intersection(y_lst))))\r\nelse:\r\n if min(x_lst)<min(y_lst):\r\n print (int(min(x_lst)+min(y_lst)))\r\n elif min(y_lst)<min(x_lst):\r\n print (int(min(y_lst)+min(x_lst)))\r\n", "a, b = map(int, input().split())\r\nl1 = set(input().split())\r\nl2 = set(input().split())\r\nif l1 & l2:\r\n print(min(l1 & l2))\r\nelse:\r\n p = min(l1) + min(l2)\r\n q = min(l2) + min(l1)\r\n print(min(p,q))", "import sys\r\nn, m = map(int, input().split())\r\na, b, cnta, cntb = list(map(int, input().split())), list(map(int, input().split())), [False] * 10, [False] * 10\r\nfor x in a: cnta[x] = True\r\nfor x in b: cntb[x] = True\r\nfor x in range(10):\r\n if cnta[x] and cntb[x]:\r\n print(x)\r\n sys.exit()\r\nprint(min(min(a), min(b)), max(min(a), min(b)), sep = \"\")", "n, m = map(int, input().split())\r\nlista_1 = list(map(int, input().split()))\r\nlista_2 = list(map(int, input().split()))\r\n\r\nlista_1.sort()\r\nlista_2.sort()\r\nachou = True\r\nindices = []\r\nfor i in range(len(lista_1)):\r\n for j in range(len(lista_2)):\r\n if lista_1[i] == lista_2[j]:\r\n indices.append(i)\r\n achou = False\r\n break\r\n\r\nif achou:\r\n print(f\"{min(lista_1[0], lista_2[0])}{max(lista_1[0], lista_2[0])}\")\r\nelse:\r\n print(lista_1[indices[0]])\r\n", "n,m=map(int,input().split())\r\nl1=list(map(int,input().split()))\r\nl2=list(map(int,input().split()))\r\ni=1\r\nwhile True:\r\n f1=False\r\n f2=False\r\n s=str(i)\r\n l=list(s)\r\n for j in l:\r\n if int(j) in l1:\r\n f1=True\r\n if int(j) in l2:\r\n f2=True\r\n if f1 and f2:\r\n print(i)\r\n exit()\r\n i+=1\r\n\r\n", "from sys import stdin, stdout\r\n\r\nn, m = map(int, stdin.readline().split())\r\nfirst = stdin.readline().strip().split()\r\nsecond = stdin.readline().strip().split()\r\n\r\nfor i in range(1, 10 ** 6):\r\n label1, label2 = 0, 0\r\n \r\n for j in str(i):\r\n if j in first:\r\n label1 = 1\r\n \r\n if j in second:\r\n label2 = 1\r\n \r\n if label1 and label2:\r\n stdout.write(str(i))\r\n break\r\n", "a, b = map(int, input().split())\r\nv = []\r\nfor _ in range(2):\r\n numbers = list(map(int, input().split()))\r\n v.append(sorted(numbers))\r\n a, b = b, a\r\nres = float('inf')\r\nfor i in range(len(v[0])):\r\n for j in range(len(v[1])):\r\n res = min(res, v[0][i] * 10 + v[1][j])\r\n res = min(res, v[1][j] * 10 + v[0][i])\r\n if v[0][i] == v[1][j]:\r\n res = min(res, v[0][i])\r\nprint(res)# 1698330121.8984416", "def main():\n n, m = map(int, input().split())\n a = list(map(int, input().split()))\n b = list(map(int, input().split()))\n\n a.sort()\n b.sort()\n\n a_min = a[0]\n b_min = b[0]\n\n for i in range(n):\n for j in range(m):\n if a[i] == b[j]:\n print(a[i])\n return\n\n print(str(min(a_min, b_min)) + str(max(a_min, b_min)))\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\t\t", "n,m=map(int,input().split())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\na=set(a)\nb=set(b)\nif(len(a.intersection(b))>0):\n print(min(a.intersection(b)))\nelif(len(a.intersection(b))==0):\n if(int(str(min(a))+str(min(b)))<=int(str(min(b))+str(min(a)))):\n print(int(str(min(a))+str(min(b))))\n else:\n print(int(str(min(b))+str(min(a))))\n", "input()\r\na=sorted(list(map(int,input().split())))\r\nb=sorted(list(map(int,input().split())))\r\nfor i in range(1,10):\r\n if i in a and i in b:exit(print(i))\r\nprint(min(a[0]*10+b[0],b[0]*10+a[0]))\r\n", "t = input()\r\na = [int(i) for i in input().split()]\r\nb = [int(i) for i in input().split()]\r\n\r\nbr = 0\r\nfor i in range(10):\r\n\tif (i in a) and (i in b):\r\n\t\tprint(i)\r\n\t\tbr = 1\r\n\t\tbreak\r\nif not br:\r\n\ta = min(a)\r\n\tb = min(b)\r\n\tprint(min(a,b)*10 + max(a,b))\r\n\r\n\r\n", "inp = lambda: list(map(int, input().split()))\r\nn,m = inp()\r\na = inp()\r\nb = inp()\r\nc = []\r\nfor i in a:\r\n if i in b: c.append(i)\r\nif len(c) > 0: print(min(c))\r\nelse:\r\n a = min(a)\r\n b = min(b)\r\n if a>b:\r\n a,b = b,a\r\n print(a*10+b)\r\n\r\n\r\n", "n, m = map(int, input().split())\r\na = set(list(input().split()))\r\nb = set(list(input().split()))\r\nif a&b:\r\n print(min(a & b))\r\nelse:\r\n print(min(min(a)+min(b), min(b)+min(a)))", "def main():\n n, m = map(int, input().split())\n a = list(map(int, input().split()))\n b = list(map(int, input().split()))\n for i in range(1, 10):\n if i in a and i in b:\n print(i)\n return\n\n for i in range(1, 10):\n for j in range(1, 10):\n if (i in a and j in b) or (i in b and j in a):\n print(''.join(str(x) for x in (i, j)))\n return\n\nmain()\n", "n, m = map(int, input().split())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nfor s in range(1, 10):\n if s in A and s in B:\n print(s)\n exit(0)\nif 0 in A or 0 in B:\n for s in range(1, 10):\n if s in A or s in B:\n print(s * 10)\n exit(0)\nelse:\n x = min(A)\n y = min(B)\n x, y = min(x, y), max(x, y)\n print(10 * x + y)", "from math import *\r\nsInt = lambda: int(input())\r\nmInt = lambda: map(int, input().split())\r\nlInt = lambda: list(map(int, input().split()))\r\n\r\ndef check(a,b):\r\n c = []\r\n for i in range(len(a)):\r\n for j in range(len(b)):\r\n if a[i]==b[j]:\r\n c.append(a[i])\r\n if c!=[]:\r\n print(min(c))\r\n return True\r\n else:\r\n return False\r\n\r\n\r\n\r\nn,m = mInt()\r\na = lInt()\r\nam = min(a)\r\nb = lInt()\r\nbm = min(b)\r\nif am==bm:\r\n print(am)\r\nelif check(a,b):\r\n pass\r\nelse:\r\n if am<bm:\r\n am,bm = bm,am\r\n print(bm*10+am)\r\n\r\n\r\n\r\n\r\n\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 = map(int, input().split())\r\nl1 = set(input().split())\r\nl2 = set(input().split())\r\nif l1&l2: print(min(l1&l2))\r\nelse: print(min(min(l1)+min(l2), min(l2)+min(l1)))", "n, m = map(int, input().split())\r\na1 = list(map(int, input().split()))\r\na2 = list(map(int, input().split()))\r\na1z, a2z, z = 10, 10, 10\r\nfor i in a1:\r\n if i in a2:\r\n z = min(i, z)\r\n a1z = min(i, a1z)\r\nfor i in a2:\r\n a2z = min(a2z, i)\r\nif z == 10:\r\n print(min(10 * a1z + a2z, 10 * a2z + a1z))\r\nelse:\r\n print(z)\r\n", "n,m=map(int,input().split())\nip1=list(map(int,input().split()))\nip2=list(map(int,input().split()))\ncom=[]\nfor i in ip1:\n if i in ip2:\n com.append(i)\nif len(com)>0:\n print(min(com))\nelse:\n a=min(ip1)\n b=min(ip2)\n a,b=min(a,b),max(a,b)\n print(a*10+b)\n \n", "n,m=map(int,input().split())\r\na=sorted(list(map(int,input().split()))) [:n]\r\nb=sorted(list(map(int,input().split()))) [:m]\r\nlis=sorted([(x,y) for x in a for y in b ])\r\nans=(sorted(set(lis)))\r\nflag=1\r\nfor i in a:\r\n if i in b:\r\n print(i)\r\n flag=0\r\n break\r\n\r\nif flag==1:\r\n if ans[0][0] == ans[0][1]:\r\n print(ans[0][0])\r\n else:\r\n if ans[0][0] > ans[0][1]:\r\n print(ans[0][1], ans[0][0], sep=\"\")\r\n else:\r\n print(*ans[0], sep=\"\")", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\na.sort()\r\nb.sort()\r\nok = True\r\nfor i in range(n):\r\n if a[i] in b:\r\n print(a[i])\r\n ok = False\r\n break\r\nif ok:\r\n print(min(a[0], b[0]), end = '')\r\n print(max(b[0], a[0]))\r\n", "def readln(): return map(int, input().rstrip().split())\r\n\r\n\r\nn, m = readln()\r\nln = list(readln())\r\nlm = list(readln())\r\n\r\nln.sort()\r\nlm.sort()\r\n\r\ninter = list(set(ln).intersection(lm))\r\ninter.sort()\r\nif len(inter) > 0:\r\n print(inter[0])\r\n exit()\r\n\r\ns = min(ln[0], lm[0])\r\nl = max(ln[0], lm[0])\r\n\r\nprint(s if s == l else (s * 10 + l))\r\n", "n, m = map(int, input().split())\no = input().split()\nd = input().split()\no.sort()\nd.sort()\nnum = 0\nfor i in range(0, 10):\n if o.count(str(i)) == d.count(str(i)) and o.count(str(i)) != 0:\n num = i\n break\nif num == 0:\n num = min(o[0], d[0]) + max(o[0], d[0])\nprint(num)\n\t \t \t \t\t\t \t \t\t\t\t\t \t\t \t \t", "#!/usr/bin/python\n\nn, m = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\na.sort()\nb.sort()\n\ns = set(a).intersection(b)\n\nif s:\n print(min(s))\nelse:\n l = [i * 10 + j for i in a for j in b] + [j * 10 + i for i in a for j in b]\n print(min(l))\n", "input() # skip line with list lengths\r\nxs = {int(r) for r in input().split()}\r\nys = {int(r) for r in input().split()}\r\n\r\nzs = xs & ys\r\nif len(zs) > 0:\r\n print(min(zs))\r\nelse:\r\n a = min(xs)\r\n b = min(ys)\r\n print(str(min(a, b)) + str(max(a, b)))\r\n", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nd=list(map(int,input().split()))\r\na=min(l)\r\nb=min(d)\r\nd=set(d)\r\nl=set(l)\r\nz=d.intersection(l)\r\nll=list(z)\r\nll.sort()\r\nif(ll==[]):\r\n if(a<b):\r\n x=str(a)+str(b)\r\n elif(a>b):\r\n x=str(b)+str(a)\r\nelse:\r\n x=ll[0]\r\nprint(x)\r\n", "\r\nn, m = map(int, input().split())\r\nl1 = list(map(int, input().split()))\r\nl2 = list(map(int, input().split()))\r\n\r\nl1.sort()\r\nl2.sort()\r\n\r\nl = []\r\nfor i in l1:\r\n\tif i in l2:\r\n\t\tl.append(i)\r\n\t\tbreak\r\nl.append(l1[0] * 10 + l2[0])\r\nl.append(l2[0] * 10 + l1[0])\r\nprint(min(l)) ", "n, m = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\nm = [i for i in a if i in b]\nif len(m) > 0:\n print(min(m))\nelse:\n a_min, b_min = 9, 9\n\n for i in a:\n if i < a_min:\n a_min = i\n\n for i in b:\n if i < b_min:\n b_min = i\n\n print(a_min if a_min == b_min else str(a_min)+str(b_min) if a_min < b_min else str(b_min)+str(a_min))\n", "# from dust i have come, dust i will be\r\n\r\nimport sys\r\n\r\nn,m=map(int,input().split())\r\n\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\n\r\nfor i in range(1,10):\r\n if i in a and i in b:\r\n print(i)\r\n exit(0)\r\n\r\nx=min(a)\r\ny=min(b)\r\nsys.stdout.write('%d%d'%(min(x,y),max(x,y)))", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nea=set(a)\r\neb=set(b)\r\nif ea & eb !=set():\r\n print(min(list(ea & eb)))\r\nelse:\r\n ma=min(a)\r\n mb=min(b)\r\n print(min(ma,mb)*10+max(ma,mb))\r\n\r\n", "# import sys\r\n# sys.stdin=open(\"input.in\",\"r\")\r\nn,k=map(int,input().split())\r\nl=set(map(int,input().split()))\r\nk=set(map(int,input().split()))\r\nx=min(l)\r\ny=min(k)\r\ne=l&k\r\nif len(e)!=0:\r\n\tprint(min(e))\r\nelse:\r\n\tprint(min(x,y),max(x,y),sep=\"\")", "n,m=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\na.sort()\r\nb.sort()\r\nd=a[0]*10+b[0]\r\ne=b[0]*10+a[0]\r\nw=-1\r\nq=0\r\nfor i in b:\r\n if(i in a):\r\n q=1\r\n w=i\r\n break\r\n \r\n\r\nif(q==1):\r\n print(w)\r\nelif(d<e):\r\n print(d)\r\nelse:\r\n print(e)", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nflag=True\r\na.sort()\r\nb.sort()\r\nfor i in a:\r\n if(i in b):\r\n print(i)\r\n flag=False\r\n break\r\nif(flag):\r\n print(min(a[0],b[0])*10+max(a[0],b[0]))\r\n", "n,m = map(int,input().split(' '))\r\n\r\nn1 = input().split(' ')\r\n\r\nm1 = input().split(' ')\r\n\r\nlis = 100\r\n\r\nfor i in range(100):\r\n\tst = str(i)\r\n\tif len(st) == 1:\r\n\t\tif (st in m1) and (st in n1) and (i<lis):\r\n\t\t\tlis = i\r\n\telse:\r\n\t\tst1 = st[0]\r\n\t\tst2 = st[1]\r\n\t\tif (((st1 in n1) and (st2 in m1)) or ((st1 in m1) and (st2 in n1))) and (i<lis):\r\n\t\t\tlis = i\r\nprint(lis)\t\t\t\r\n\t\t\t\r\n\t\t\t", "# Search for Pretty Integers\n\ndef element_in_common(a, b):\n i = a.intersection(b)\n if i:\n return min(i)\n else:\n return 0\n\n_ = input()\nl1 = set((map(int, input().split())))\nl2 = set((map(int, input().split())))\n\nx = min(l1)\ny = min(l2)\ne = element_in_common(l1, l2)\n\nif e:\n print(e)\nelse:\n print(min(x, y), max(x, y), sep='')\n", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\ndef isPretty(x):\r\n f1, f2 = False, False\r\n while x:\r\n if x % 10 in a: f1 = True\r\n if x % 10 in b: f2 = True\r\n x //= 10\r\n return f1 and f2\r\nans = [x for x in range(1, 100) if isPretty(x)]\r\nprint(ans[0])", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\na.sort()\r\nb.sort()\r\nans = 100\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i] == b[j]:\r\n ans = min(ans, a[i])\r\nans = min(ans, min(a[0] * 10 + b[0], b[0] * 10 + a[0]))\r\nprint(ans)", "m= list(map(int, input().split()))\r\na= list(map(int, input().split()))\r\nb= list(map(int, input().split()))\r\nc=[value for value in a if value in b]\r\na1= min(a)\r\na2=min(b)\r\na3=str(min(min(a),min(b)))\r\na4=str(max(min(a),min(b)))\r\nif len(c)!=0:\r\n print(min(c))\r\nelse:\r\n print(a3+a4)\r\n\r\n", "n,m=list(map(int,input().split()))\r\nl1=list(map(int,input().split()))\r\nl2=list(map(int,input().split()))\r\nj=list(set(l1).intersection(set(l2)))\r\nif len(j)>0:\r\n print(min(j))\r\nelse:\r\n a1=min(l1)\r\n a2=min(l2)\r\n if a1>a2:\r\n print((a2*10)+a1)\r\n else:\r\n print((a1*10)+a2)\r\n", "n,m=map(int,input().split())\r\nl1=list(map(int,input().split()))\r\nl2=list(map(int,input().split()))\r\n\r\nx,flag=list(range(1,10)),0\r\nfor i in x:\r\n\tif i in l1 and i in l2:\r\n\t\tprint(i)\r\n\t\tflag=1\r\n\t\tbreak\r\nif flag==0:\r\n\ta,b=min(l1),min(l2)\r\n\tif a<b:\r\n\t\tprint(str(a)+str(b))\r\n\telse:\r\n\t\tprint(str(b)+str(a))", "a=input()\r\nb=10\r\nc=10\r\nx=input().split()\r\nr=list()\r\nfor i in x:\r\n\tif int(i)<=b:\r\n\t\tb=int(i)\r\nfor j in input().split():\r\n\tif int(j)<=c:\r\n\t\tc=int(j)\r\n\tif j in x:\r\n\t\tr.append(int(j))\r\nif len(r)!=0:\r\n\tprint(min(r))\r\nelif b>c:\r\n\tprint(c*10+b)\r\nelse:\r\n\tprint(b*10+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\n\nn, m = rint()\n\na = list(rint())\nb = list(rint())\n\na.sort()\nb.sort()\n\nfor aa in a:\n for bb in b:\n if aa == bb:\n print(aa)\n exit()\n\nif a[0] > b[0]:\n a[0], b[0] = b[0], a[0]\n\nprint(a[0]*10+b[0])\n", "def nonZero(a, b):\n a.sort()\n for i in a:\n if b.count(i) > 0:\n return i\n\n return min(min(a) * 10 + min(b), min(b) * 10 + min(a))\n\n\nnm = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\nb = [int(i) for i in input().split()]\nprint(nonZero(a, b))\n", "#CF440 yl1\r\nn,m=list(map(int,input().split()))\r\na=sorted(set(map(int,input().split())))\r\nb=sorted(set(map(int,input().split())))\r\nc=True\r\nfor i in range(10):\r\n if i in a and i in b and c:\r\n print(i)\r\n c=False\r\n break\r\nif 0 in a and len(b)>1 and c:\r\n print(min([b[0]*10,int(str(a[1])+str(b[0]))]))\r\nelif 0 in b and len(a)>1 and c:\r\n print(min([a[0]*10,int(str(b[1])+str(a[0]))]))\r\nelif c:\r\n print(''.join(list(map(str,sorted(set([a[0],b[0]]))))))\r\n", "n,m=map(int,input().split())\r\na=set(map(int,input().split()))\r\nb=set(map(int,input().split()))\r\nx= a.intersection(b)\r\nif len(x)==0:\r\n a=min(list(a))\r\n b=min(list(b))\r\n if a>b:\r\n a,b=b,a\r\n print(str(a)+str(b)) \r\nelse:\r\n print(str(min(list(x))))\r\n", "input()\r\ndaf1 = set(list(map(int, input().split())))\r\ndaf2 = set(list(map(int, input().split())))\r\n\r\ndaf3 = daf1.intersection(daf2)\r\n\r\nif len(daf3) > 0:\r\n print(min(daf3))\r\nelse:\r\n x = min(daf1)\r\n y = min(daf2)\r\n print(10*min(x,y) + max(x,y))\r\n \r\n", "n,m=map(int,input().split())\r\nar1=list(map(int,input().split()))\r\nar2=list(map(int,input().split()))\r\nar1.sort()\r\nar2.sort()\r\nv1=[0]*10\r\nv2=[0]*10\r\nfor i in ar1:\r\n v1[i]+=1\r\nfor i in ar2:\r\n v2[i]+=1\r\nad=[0]*100\r\nfor i in range(100):\r\n if(i<10):\r\n if(v1[i]==v2[i] and v1[i]>0):\r\n print(i)\r\n break\r\n\r\n else:\r\n a1=int(i%10)\r\n a2=int((i%100)/10)\r\n if((v1[a1]>0 and v2[a2]>0) or (v2[a1]>0 and v1[a2]>0) ):\r\n print(i)\r\n break\r\n\r\n", "n, m = [int(x) for x in input().split()]\na = [int(x) for x in input().split()]\nb = [int(x) for x in input().split()]\n\ncommon_digit = 10\nfor x in b:\n if x in a and x < common_digit:\n common_digit = x\n\nif common_digit < 10:\n print(common_digit)\n exit(0)\n\nmin_a = min(a)\nmin_b = min(b)\nif min_a < min_b:\n print(\"%d%d\" % (min_a, min_b))\nelse:\n print(\"%d%d\" % (min_b, min_a))\n", "_, x = input(), 1\r\nl, k = set(map(str, input().split())), set(map(str, input().split()))\r\nwhile True:\r\n\tif any(i in str(x) for i in l) and any(i in str(x) for i in k):\r\n\t\tprint(x)\r\n\t\tbreak\r\n\tx += 1", "n, m = [int(x) for x in input().split()]\r\na = set([x for x in input()])\r\nb = set([x for x in input()])\r\nfor i in range(100):\r\n c = set(str(i))\r\n if (c & a) and (c&b):\r\n print(i)\r\n break\r\n", "a=input()\nl1 = [int(i) for i in input().split()]\nl2 = [int(i) for i in input().split()]\n\nm=10\nfor i in l1:\n\tfor j in l2:\n\t\tif i==j and i<m:\n\t\t\tm=i\nif m==10:\n\tx=min(l1)\n\ty=min(l2)\n\tif x<y:\n\t\tprint(10*x+y)\n\telse:\n\t\tprint(10*y+x)\nelse:\n\tprint(m)", "n , m =list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nx, y = min(a), min(b)\r\na.sort()\r\nb.sort()\r\nif (len(a) >= len(b)):\r\n for i in range(len(b)):\r\n if (b[i] in a):\r\n print(b[i])\r\n break\r\n else:\r\n if (x > y):\r\n print(str(y) + str(x))\r\n else:\r\n print(str(x) + str(y)) \r\nelse:\r\n for i in range(len(a)):\r\n if (a[i] in b):\r\n print(a[i])\r\n break\r\n else:\r\n if (x > y):\r\n print(str(y) + str(x))\r\n else:\r\n print(str(x) + str(y))", "input()\r\na = sorted(map(int, input().split()))\r\nb = sorted(map(int, input().split()))\r\nx = -1\r\nfor i in range(1, 10):\r\n if i in a and i in b:\r\n x = i\r\n break\r\nif a[0] == b[0]:\r\n print(a[0])\r\nelif x != -1:\r\n print(x)\r\nelse:\r\n print(min(a[0], b[0]), end=\"\")\r\n print(max(a[0], b[0]))", "n, m = map(int, input().split())\r\nlista_1 = list(map(int, input().split()))\r\nlista_2 = list(map(int, input().split()))\r\nlista = (lista_1 + lista_2)\r\nlista.sort()\r\nigual = False\r\ndic = {}\r\n\r\nfor elemento in lista:\r\n if elemento in dic:\r\n dic[elemento] += 1\r\n print(elemento)\r\n igual = True\r\n break\r\n else:\r\n dic[elemento] = 1\r\n\r\n\r\na = min(lista_1)\r\nb = min(lista_2)\r\nif not igual:\r\n print(f\"{min(a, b)}{max(a, b)}\")\r\n", "N, M = [int(i) for i in input().split()]\r\nn = set([int(i) for i in input().split()])\r\nm = set([int(i) for i in input().split()])\r\n\r\nfor i in range(1, 10):\r\n\tif i in n and i in m:\r\n\t\tprint(i)\r\n\t\texit()\r\n\r\n\r\na = min(n)\r\nb = min(m)\r\nif a == b:\r\n\tprint(a)\r\nelse:\r\n\tprint(min(a, b), max(a, b),sep=\"\")\r\n\r\n", "n, m = map(int, input().split())\r\na = sorted(list(map(int, input().split())))\r\nb = sorted(list(map(int, input().split())))\r\nfor i in a:\r\n\tif i in b:\r\n\t\tprint(i)\r\n\t\texit(0)\r\nprint(min(a[0], b[0])*10+max(a[0], b[0]))", "n, m = map(int, input().split())\r\na = set(input().split())\r\nb = set(input().split())\r\nmin1 = min(a)\r\nmin2 = min(b)\r\nif a & b :\r\n print(min(a & b))\r\nelse:\r\n if min1 > min2 :\r\n print(min2+min1)\r\n else:\r\n print(min1+min2)", "x,y = map(int, input().split())\nfirst = list(map(int, input().split()))\nsecond = list(map(int, input().split()))\nmf = min(first)\nms = min(second)\nif x < y:\n\tfirst.sort()\n\tsecond.sort()\n\tfor c in first:\n\t\tif c in second:\n\t\t\tresp = c\n\t\t\tbreak\n\t\telse:\n\t\t\tif ms > mf:\n\t\t\t\tresp = str(mf) + str(ms)\n\t\t\telif ms == mf:\n\t\t\t\tresp = ms\n\t\t\telse:\n\t\t\t\tresp = str(ms) + str(mf)\nelse:\n\tfirst.sort()\n\tsecond.sort()\n\tfor c in second:\n\t\tif c in first:\n\t\t\tresp = c\n\t\t\tbreak\n\t\telse:\n\t\t\tif ms > mf:\n\t\t\t\tresp = str(mf) + str(ms)\n\t\t\telif ms == mf:\n\t\t\t\tresp = ms\n\t\t\telse:\n\t\t\t\tresp = str(ms) + str(mf)\n\nresp = int(resp)\nprint(resp)\n", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nif len(set(a) & set(b)) != 0:\r\n print(min(set(a) & set(b)))\r\nelse:\r\n print(str(min(min(a), min(b))) + str(max(min(a), min(b))))\r\n\r\n# UBCF\r\n# CodeForcesian\r\n# ♥\r\n# اثر مرکب", "m,n=map(int,input().split())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nq=min(a)\np=min(b)\ne=list(set(a)&set(b))\nif e==[]:\n\tif q<p:\n\t\tprint(q*10+p)\n\telse:\n\t\tprint(p*10+q)\nelse:\n\tprint(min(e))\n", "n , m = map(int, input().split())\r\nN_data = list(map(int, input().split()))\r\nM_data = list(map(int, input().split()))\r\nBoth = []\r\nfor i in N_data:\r\n for j in M_data:\r\n if i==j:\r\n Both.append(i)\r\nif len(Both) > 0:\r\n print(min(Both))\r\nelse:\r\n digit1 = min(N_data)\r\n digit2 = min(M_data)\r\n Number1 = str(digit1) + str(digit2)\r\n Number2 = str(digit2) + str(digit1)\r\n if int(Number1) > int(Number2) :\r\n print(Number2)\r\n else:\r\n print(Number1)\r\n", "n, m = input().split()\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\ndup = []\nc = min(a)\nd = min(b)\n\nfor i in a:\n if(i in b):\n dup.append(i)\n\nif(len(dup) > 0):\n print(min(dup))\nelse:\n print(str(min(c, d))+str(max(c, d)))\n\n \t \t \t \t\t\t \t\t \t \t\t\t \t\t \t", "n, l = map(int, input().split(\" \"))\r\nl1 = set(map(int, input().split(\" \")))\r\nl2 = set(map(int, input().split(\" \")))\r\nl3 = l1.intersection(l2)\r\n\r\nif len(l3) != 0:\r\n print(min(l3))\r\nelse:\r\n a = min(l1)\r\n b = min(l2)\r\n print(f\"{min(a, b)}{max(a, b)}\")\r\n", "import sys;sc = sys.stdin.readline;out=sys.stdout.write\r\nn,x=map(int,sc().rstrip().split())\r\narr=list(map(int,sc().rstrip().split()))\r\narr1=list(map(int,sc().rstrip().split()))\r\na=min(arr);aa=min(arr1);s=str(a)+\"\"+str(aa);ss=str(aa)+\"\"+str(a);sss=min(int(s),int(ss));m=[0]*10;o=100000\r\nfor e in range(n):m[arr[e]]+=1\r\nfor e in range(x):m[arr1[e]]+=1\r\nfor e in range(10):\r\n if m[e]>1:o=e;break\r\nout(str(min(o,sss)))", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\nw = sorted(map(int, input().split()))\r\ns = sorted(map(int, input().split()))\r\n\r\nd = set(w) & set(s)\r\nif len(d) > 0:\r\n print(list(d)[0])\r\nelse:\r\n print(min(int(str(w[0]) + str(s[0])), int(str(s[0]) + str(w[0]))))", "n,m=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\n\r\nflag=0\r\nl=[]\r\nfor i in range(len(a)):\r\n\tif a[i] in b:\r\n\t\tflag=1\r\n\t\tl.append(a[i])\r\n\r\nx=min(a)\r\ny=min(b)\r\nu=min(x,y)\r\nv=max(x,y)\r\n\r\nif flag==1:\r\n\tprint(min(l))\r\nelse:\r\n\tprint(u,end='')\r\n\tprint(v)", "n,m=map(int,input().split())\r\nl1=list(map(int,input().split()))\r\nl2=list(map(int,input().split()))\r\na=min(l1)\r\nb=min(l2)\r\ns=set(l1) & set(l2)\r\ns=list(s)\r\nif len(s)>0:\r\n\tprint(min(s))\r\nelse:\r\n\tprint(str(min(a,b))+str(max(a,b)))", "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,m = map(int,input().split())\r\nai = list(map(int,input().split()))\r\nbi = list(map(int,input().split()))\r\nai2 = [0] * 10\r\nfor i in range(n):\r\n ai2[ai[i]] += 1\r\nfor i in range(m):\r\n ai2[bi[i]] += 1\r\nai.sort()\r\nbi.sort()\r\n\r\nans = 100\r\nfor i in range(10):\r\n if ai2[i] == 2:\r\n ans = i\r\n break\r\nprint(min(ans,min(ai[0] * 10 + bi[0],bi[0] * 10 + ai[0])))\r\n", "n,m = map(int,input().split())\r\nn1 = list(map(int,input().split()))\r\nm1 = list(map(int,input().split()))\r\nk = set(n1).intersection(set(m1))\r\nif len(k)!=0:\r\n\tprint(min(k))\r\nelse:\r\n\tprint([min(m1)*10+min(n1),min(n1)*10+min(m1)][min(n1)<min(m1)])", "tmp = list(map(int,input().split()))\r\nn,m = tmp[0],tmp[1]\r\na = set(list(map(int,input().split())))\r\nb = set(list(map(int,input().split())))\r\n\r\nmi = 100\r\nfor x in a:\r\n for y in b:\r\n if x in b and x < mi:\r\n mi = x\r\n elif int(str(x)+str(y)) < mi:\r\n mi = int(str(x)+str(y))\r\n \r\nfor y in b: \r\n for x in a:\r\n if y in a and y < mi:\r\n mi = y\r\n elif int(str(y)+str(x)) < mi:\r\n mi = int(str(y)+str(x))\r\n \r\nprint(mi)", "n, m = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\nb = [int(i) for i in input().split()]\r\na.sort()\r\nb.sort()\r\nfor i in a:\r\n if i in b:\r\n print(i)\r\n break\r\nelse:\r\n c = a[0]\r\n d = b[0]\r\n if c < d:\r\n print(c, d, sep='')\r\n else:\r\n print(d, c, sep='')", "n,m=map(int,input().split())\r\np=list(map(int,input().split()))\r\nq=list(map(int,input().split()))\r\nres=[]\r\nfor i in p:\r\n if i in q:\r\n res.append(i)\r\nif len(res)>0:\r\n print(min(res))\r\nelse:\r\n a=min(p)\r\n b=min(q)\r\n if a>b:\r\n print(10*b+a)\r\n else:\r\n print(10*a+b)", "n, m = map(int, input().split())\na = sorted(list(map(int, input().split())))\nb = sorted(list(map(int, input().split())))\n\nintersection = list(set(a) & set(b))\nif intersection:\n print(min(intersection))\nelse:\n x = a[0]\n y = b[0]\n if x > y:\n x, y = y, x\n print('%s%s' % (x, y))\n", "\r\nn, m = map(int, input().split())\r\na = set(map(int, input().split()))\r\nb = set(map(int, input().split()))\r\n\r\nc = a&b\r\nif c: print(min(c))\r\nelse:\r\n x, y = min(a), min(b)\r\n print(min(x, y)*10+max(x,y))\r\n", "def pretty(list1,list2):\r\n a=min(list1)\r\n b=min(list2)\r\n list3=[]\r\n for i in list1:\r\n if i in list2:\r\n list3.append(i)\r\n if len(list3)==0:\r\n c=int(str(a)+str(b))\r\n d=int(str(b)+str(a))\r\n if c>=d:\r\n return d\r\n else:\r\n return c\r\n else:\r\n return min(list3)\r\nn,m=map(int,input().split())\r\nlist1=list(map(int,input().split()))\r\nlist2=list(map(int,input().split()))\r\nprint(pretty(list1,list2))\r\n", "n = input()\nl1 = [int(i) for i in input().split(' ')]\nl2 = [int(i) for i in input().split(' ')]\ninter = list(set(l1).intersection(set(l2)))\nif len(inter) > 0:\n print(min(inter))\nelse:\n print(str(min([min(l1),min(l2)])) + str(max([min(l1),min(l2)])))\n", "n,m=map(int,input().split())\na=set(map(int,input().split()))\nb=set(map(int,input().split()))\nc=min(a)\nd=min(b)\ne=a&b\nif len(e)!=0: print(min(e))\nelse: print(str(min(c,d))+str(max(c,d)))", "a,b=input().split(\" \")\r\na=int(a)\r\nb=int(b)\r\nstr_in1 = input()\r\nstr_in2 = input()\r\nnuma=[a]\r\nnuma = [int(n) for n in str_in1.split()] \r\nnumb=[b]\r\nnumb = [int(n) for n in str_in2.split()] \r\nnuma.sort()\r\nnumb.sort()\r\ni=0\r\nj=0\r\nflag=0\r\npp=[]\r\nwhile(i<a):\r\n j=0\r\n while(j<b):\r\n if(numa[i]==numb[j]):\r\n pp.append(numa[i])\r\n flag=1\r\n j+=1\r\n i+=1\r\nif(flag==1):\r\n pp.sort()\r\n print(pp[0])\r\nif(flag==0):\r\n print(str(min(numa[0],numb[0]))+str(max(numa[0],numb[0])))", "n,m = map(int,input().split())\r\na =sorted(list(map(int,input().split())))\r\nb = sorted(list(map(int,input().split())))\r\n\r\nl = sorted(list(set(a).intersection(b)))\r\nif len(l) > 0:\r\n print(l[0])\r\nelse:\r\n print(min(a[0]*10+b[0],b[0]*10+a[0]))", "R=lambda:list(map(int,input().split()))\nR()\na=R()\nb=R()\nc=[x for x in a if x in b]\nif len(c)>0:\n print(min(c))\nelse:\n a=min(a)\n b=min(b)\n if a>b: a,b=b,a\n print(a*10+b)\n", "s = input()\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nif len(set(a) & set(b)) >= 1:\r\n print(min(set(a) & set(b)))\r\nelse:\r\n a = min(a)\r\n b = min(b)\r\n print(str(min(a, b)) + str(max(a, b)))\r\n", "input()\r\na=input().split()\r\nb=input().split()\r\nd=100\r\nfor i in a:\r\n for x in b:\r\n d=min(int(i+x),int(x+i),d)\r\nprint(min(d,min({100}^set([int(i)for i in a])&set([int(i)for i in b]))))\r\n", "#For fast I/O\r\nimport sys\r\ninput = lambda: sys.stdin.readline().strip()\r\n\r\n#Answer given the 2 lists\r\ndef ans(l1,l2):\r\n\t#Common digit\r\n\tfor i in range(1,10):\r\n\t\tif i in l1 and i in l2:\r\n\t\t\treturn i\r\n\r\n\t#No common digit\r\n\ta = min(l1)\r\n\tb = min(l2)\r\n\treturn 10 * min(a,b) + max(a,b)\r\n\r\n#Homura = [int(i) for i in input().split()]\r\n#m = Homura[0]\r\n#n = Homura[1]\r\nMahou_Shoujo_Madoka_Magica = input()\r\n\r\nl1 = [int(i) for i in input().split()]\r\nl2 = [int(i) for i in input().split()]\r\n\r\nprint(ans(l1,l2))\r\n", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nc=0\r\nl=[]\r\nfor x in a:\r\n if x in b:\r\n l.append(x)\r\n c+=1\r\nif c!=0:\r\n print(min(l))\r\nelse:\r\n m1=min(a)\r\n m2=min(b)\r\n m=min(m1,m2)\r\n if m in a:\r\n print(10*m+m2)\r\n if m in b:\r\n print(10*m+m1)", "input()\r\nv_1 = input()\r\nv_2 = input()\r\nv_1 = v_1.split()\r\nv_2 = v_2.split()\r\nv_1.sort()\r\nv_2.sort()\r\n\r\nv = set(v_1) & set(v_2)\r\nif len(v) > 0 :\r\n print(min(v))\r\n raise SystemExit\r\n\r\na = min(v_1)\r\nc = min(v_2)\r\nprint(min(a,c)+max(a,c))\r\n", "if __name__ == \"__main__\":\r\n (n, m) = map(int, input().split())\r\n a_list = list(map(int, input().split()))\r\n a_list = sorted(a_list)\r\n b_list = list(map(int, input().split()))\r\n b_list = sorted(b_list)\r\n found = False\r\n for nr in a_list:\r\n if nr in b_list and not found:\r\n smallest = nr\r\n found = True\r\n break\r\n if not found:\r\n if a_list[0] < b_list[0]:\r\n smallest = a_list[0] * 10 + b_list[0]\r\n else:\r\n smallest = b_list[0] * 10 + a_list[0]\r\n print(smallest)", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nk=list(map(int,input().split()))\r\nl.sort()\r\nk.sort()\r\nfor x in l:\r\n\tif x in k:\r\n\t\tprint(x)\r\n\t\tbreak\r\nelse:\r\n\tif l[0]<k[0]: print(l[0]*10+k[0])\r\n\telse: print(k[0]*10 + l[0])", "lens = [*map(int, input().split())]\nln, lm = lens\nn = [*map(int, input().split())]\nm = [*map(int, input().split())]\n\nn.sort()\nm.sort()\n\nif ln > lm:\n menor = n\n maior = m\nelse:\n menor = m \n maior = n\n\nsemelhante = False\nfor e in menor:\n if e in maior:\n print(e)\n semelhante = True\n break\n \nif not semelhante:\n firstn = n[0]\n firstm = m[0]\n\n if firstm == firstn:\n print(firstn)\n else:\n temp = sorted([firstm, firstn])\n string = map(str, temp)\n inteiro = int(''.join(string))\n print(inteiro)", "n, m = input().split(' ')\r\na = list(map(int, input().split(' ')))\r\nb = list(map(int, input().split(' ')))\r\nres = 100\r\nmin_a = min(a)\r\nmin_b = min(b)\r\nx, y = min(min_a, min_b), max(min_a, min_b)\r\nif x in b and x in a:\r\n res = x\r\nelif y in b and y in a:\r\n res = y\r\nelse:\r\n res = 10 * x + y\r\n\r\nfor x in b:\r\n if x in a:\r\n res = min(res, x)\r\nprint(res)\r\n\r\n", "n, m = map(int, input().split())\r\na1 = list(map(int, input().split()))\r\na2 = list(map(int, input().split()))\r\narr = []\r\nfor i in a1:\r\n for j in a2:\r\n if i == j:\r\n arr.append(i)\r\n else:\r\n mn = min(i , j)\r\n mx = max(i, j)\r\n arr.append((mn * 10 + mx))\r\nprint(min(arr))", "import sys\n\ndef pretty(a,b):\n for i in range(1,10):\n if i in a and i in b:\n return i\n if min(a) < min(b):\n return min(a)*10+min(b)\n else:\n return min(b)*10+min(a)\n\ndef main():\n n,m = list(map(int, sys.stdin.readline().rstrip('\\n').split(' ')))\n a = list(map(int, sys.stdin.readline().rstrip('\\n').split(' ')))\n b = list(map(int, sys.stdin.readline().rstrip('\\n').split(' ')))\n print(pretty(a,b))\n\nif __name__ == '__main__':\n main()\n", "n,m=list(map(int,input().split()))\r\nl1=list(map(int,input().split()))\r\nl2=list(map(int,input().split()))\r\nl=[i for i in l1 if i in l2 ]\r\nif len(l)>0:\r\n print(min(l))\r\nelse:\r\n a,b=min(l1),min(l2)\r\n print(min(10*a+b,10*b+a))", "n, m=map(int,input().split())\r\na1=sorted([int(x) for x in input().split()])\r\na2=sorted([int(x) for x in input().split()])\r\nmn1=min(a1)\r\nmn2=min(a2)\r\nif mn1==mn2:\r\n print(mn1)\r\n exit(0)\r\nelse:\r\n for i in range(n):\r\n for j in range(m):\r\n if a1[i]==a2[j]:\r\n print(a1[i])\r\n exit(0)\r\nprint(min(mn1,mn2)*10+max(mn1,mn2))\r\n", "\r\nR = lambda:map(int,input().split())\r\n\r\nn,m = R()\r\n\r\na = set(input().split())\r\nb = set(input().split())\r\nprint(min(a&b) if a&b else min(min(a)+min(b), min(b)+ min(a)))\r\n", "n,m=map(int,input().split(' '))\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nc=[]\r\nfor i in a:\r\n if i in b:\r\n c.append(i)\r\nif len(c)>0:\r\n print(min(c))\r\nelse:\r\n a1=min(a)\r\n b1=min(b)\r\n if a1<b1:\r\n print(int(str(a1)+str(b1)))\r\n else:\r\n print(int(str(b1)+str(a1)))\r\n", "n,m = input().split(' ')\r\narrA = input().split(' ')\r\narrB = input().split(' ')\r\narrA = sorted(arrA)\r\narrB = sorted(arrB)\r\nmin_val_A = arrA[0]\r\nmin_val_B = arrB[0]\r\narrA = set(arrA)\r\narrB = set(arrB)\r\nintersected = arrA.intersection(arrB)\r\nintersected = sorted(list(intersected))\r\nif len(intersected):\r\n print(intersected[0])\r\nelse:\r\n print(\"\".join(sorted(\"{}{}\".format(min_val_A, min_val_B))))", "n,m=[int(x) for x in input().split()]\r\na=[int(x) for x in input().split()]\r\nb=[int(x) for x in input().split()]\r\nc=[0]*10\r\nfor i in a:\r\n c[i]+=1\r\nfor i in b:\r\n c[i]+=1\r\ncheck=1\r\nfor i in range(1,10):\r\n if c[i]==2:\r\n print(i)\r\n check=0\r\n break\r\nif check==1:\r\n print(min(min(a)*10+min(b),min(b)*10+min(a)))", "input()\r\nm='a'\r\na=input().split()\r\nb='a'\r\nfor i in input().split():\r\n if i<b: b=i\r\n if i in a:\r\n m=min(m,i)\r\n \r\nif m=='a':\r\n x,y=min(a),min(b)\r\n if x<y:m=x+y\r\n else:m=y+x\r\n\r\nprint(m)", "def run():\n\tn,m=list(map(int,input().split()))\n\tl=list(map(int,input().split()))\n\tm=list(map(int,input().split()))\n\tfor i in range(1,100):\n\t\tif(i<10):\n\t\t\tif((i in l) and (i in m)):\n\t\t\t\tprint(i)\n\t\t\t\treturn\n\t\telse:\n\t\t\tn1 = i%10\n\t\t\tj=i//10\n\t\t\tn2 = j%10\n\t\t\tif(((n1 in l) and (n2 in m)) or ((n2 in l) and (n1 in m))):\n\t\t\t\tprint(i)\n\t\t\t\treturn\n\nrun()", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nc = [0] * 10\r\nd = [0] * 10\r\nmn1, mn2 = min(a), min(b)\r\nfor i in range(n):\r\n c[a[i]] += 1\r\nfor i in range(m):\r\n d[b[i]] += 1\r\nfor i in range(1, 10):\r\n if c[i] and d[i]:\r\n print(i)\r\n exit()\r\nprint(str(min(mn1, mn2)) + str(max(mn1, mn2)))", "n,m=map(int,input().split())\r\nnl=list(map(int,input().split()))\r\nml=list(map(int,input().split()))\r\nfor i in range(1,10):\r\n if i in nl and i in ml:\r\n print(i)\r\n break\r\nelse:\r\n a=min(ml)\r\n b=min(nl)\r\n print( min(int(str(a)+str(b)),int(str(b)+str(a)) ))", "n, m = [int(x) for x in input().split(' ')]\r\na = set(int(x) for x in input().split(' '))\r\nb = set(int(x) for x in input().split(' '))\r\n\r\nc = a.intersection(b)\r\nif len(c) == 0:\r\n print(''.join([str(min(min(a), min(b))), str(max(min(a), min(b)))]))\r\nelse:\r\n print(min(c))\r\n\r\n", "n1, n2 = [int(e) for e in input().split()]\nl1 = [int(e) for e in input().split()]\nl2 = [int(e) for e in input().split()]\n\nl1 = sorted(l1)\nl2 = sorted(l2)\n\ninter = set(l1).intersection(l2)\n\nif len(inter) > 0:\n print('{}'.format(min(inter)))\nelif l1[0] < l2[0]:\n print('{}{}'.format(l1[0], l2[0]))\nelse:\n print('{}{}'.format(l2[0], l1[0]))\n", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\na.sort()\r\nb.sort()\r\nans=-1\r\nfor i in range(len(a)):\r\n if a[i] in b:\r\n ans=a[i]\r\n break\r\nif ans!=-1:\r\n print(ans)\r\nelse:\r\n x=min(a)\r\n y=min(b)\r\n if x==y:\r\n print(x)\r\n else:\r\n ans=(min(x,y)*10)+max(x,y)\r\n print(ans)", "from itertools import count\r\n\r\na = input()\r\nlist1 = input().split()\r\nlist2 = input().split()\r\n\r\nfor i in count(1):\r\n\tinlist1 = False\r\n\tinlist2 = False\r\n\ti = str(i)\r\n\tfor c in i:\r\n\t\tif c in list1:\r\n\t\t\tinlist1 = True\r\n\t\tif c in list2:\r\n\t\t\tinlist2 = True\r\n\tif inlist1 and inlist2:\r\n\t\tbreak\r\nprint(i)\r\n", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\ntrack = []\r\nfor i in range(len(a)):\r\n if a[i] in b:\r\n track.append(a[i])\r\nif len(track) > 0:\r\n print(min(track))\r\nelse:\r\n x, y = min(a), min(b)\r\n print(str(min(x, y)) + str(max(x, y)))\r\n", "n, m = input().split()\nlista1 = input().split()\nlista2 = input().split()\n\nnumeros_repetidos = set(lista1) & set(lista2)\n\nif len(numeros_repetidos) > 0:\n print(min(numeros_repetidos))\nelse:\n menor_lista1 = min(lista1)\n menor_lista2 = min(lista2)\n print(f'{min(menor_lista1, menor_lista2)}{max(menor_lista1, menor_lista2)}')", "n, m = map(int, input().split())\r\ns1 = list(map(int, input().split()))\r\ns2 = list(map(int, input().split()))\r\nflag = 0\r\nfor i in range(1, 100):\r\n for j in range(n):\r\n for k in range(m):\r\n if (i // 10 == s1[j] or i % 10 == s1[j]) and (i // 10 == s2[k] or i % 10 == s2[k]):\r\n print(i)\r\n flag = 1\r\n break\r\n if flag:\r\n break\r\n if flag:\r\n break", "n, m = [int(n) for n in input().split()]\r\n\r\nlista1 = [int(n) for n in input().split()]\r\nlista2 = [int(n) for n in input().split()]\r\n\r\nfor i in range(1,10):\r\n if(i in lista1 and i in lista2):\r\n print(i)\r\n exit()\r\n\r\nprint(min(min(lista1),min(lista2)),max(min(lista1),min(lista2)),sep='')", "n, m = map(int, input().split())\r\na, b = set(map(int, input().split())), set(map(int, input().split()))\r\nif a & b:\r\n print(min(a & b))\r\nelse:\r\n x, y = min(a), min(b)\r\n print(10 * x + y if x < y else 10 * y + x)", "def prettyNumber(lista1, lista2, a, b):\n for i in lista1:\n for j in lista2:\n if i == j:\n return i\n\n if a < b:\n return str(a) + str(b)\n else:\n return str(b) + str(a)\n\ntamanhos = input().split()\n\nlista1 = list(map(int, input().split()))\nlista2 = list(map(int, input().split()))\n\nlista1.sort()\nlista2.sort()\n\na = lista1[0]\nb = lista2[0]\n\nprint(prettyNumber(lista1, lista2, a, b))\n\t\t \t \t \t \t\t \t\t\t\t", "n, m = map(int, input().split())\r\nn1 = list(map(int, input().split()))\r\nn2 = list(map(int, input().split()))\r\nx1 = set(n1)&set(n2)\r\nn1 = min(n1)\r\nn2 = min(n2)\r\nif n1 > n2:n1, n2 = n2, n1\r\nif len(x1):print(min(x1))\r\nelse:print(n1, n2, sep='')", "import itertools\r\n\r\nn,m = map(int,input().split())\r\n\r\nlst1 = list(map(int,input().split()))\r\nlst2 = list(map(int,input().split()))\r\n\r\nperms = itertools.product(lst1, lst2)\r\n\r\nmn = 999\r\n\r\nfor perm in perms:\r\n st = \"\"\r\n a = sorted(perm)\r\n st += str(a[0])\r\n st += str(a[-1])\r\n mn = min(mn,int(st))\r\n\r\narr = list(filter(lambda x: x if x in lst1 and x in lst2 else None, lst1))\r\n\r\nfor i in arr:\r\n st = \"\"\r\n st += str(i)\r\n mn = min(mn,int(st))\r\n\r\nprint(mn)", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\ncommon = set(a) & set(b)\r\nif len(common) > 0:\r\n print(sorted(list(common))[0])\r\nelif min(a) < min(b):\r\n print(min(a) * 10 + min(b))\r\nelse:\r\n print(min(b)* 10 + min(a))", "li1, li2 = [int(x) for x in input().split()]\n\nlista1 = []\nlista2 = []\n\nlista1 = [int(x) for x in input().split()]\nlista2 = [int(x) for x in input().split()]\n\nlista1 = sorted(lista1)\nlista2 = sorted(lista2)\n\ni = 0\nmenor = 0\n\nfor x in lista1:\n if(x in lista2):\n menor = x\n break\nif(menor == 0):\n if(lista1[0] > lista2[0]):\n print(lista2[0], end=\"\")\n print(lista1[0])\n else:\n print(lista1[0], end=\"\")\n print(lista2[0])\nelse:\n print(menor)\n \t\t\t\t \t\t \t \t\t\t \t \t \t", "n, m = list(map(int,input().split()))\na1 = []\na1[0:n] = list(map(int,input().split()))\na2 = []\na2[0:m] = list(map(int,input().split()))\np = float(\"-inf\")\ni = 1\nwhile(p == float(\"-inf\")):\n if i < 10:\n if i in a1 and i in a2:\n p = i\n break\n else:\n if int(str(i)[0]) in a1 and int(str(i)[1]) in a2:\n p = i\n break\n elif int(str(i)[0]) in a2 and int(str(i)[1]) in a1:\n p = i\n break\n i += 1\nprint(p)\n \t \t\t \t \t \t\t\t \t\t\t\t \t\t\t\t\t\t \t", "a = list(map(int,input().split()))\r\nb = sorted(list(map(int,input().split())))\r\nc = sorted(list(map(int,input().split())))\r\nw=[]\r\ns=0\r\nv=0\r\nn=0\r\nfor i in b:\r\n if i in c:\r\n w.append(i)\r\nif w:\r\n s= min(w)\r\nif s==0:\r\n v= min(b)\r\n n= min(c)\r\n if v>n:\r\n s= str(n)+ str(v)\r\n elif v<=n:\r\n s = str(v)+ str(n)\r\nprint(s)\r\n\r\n", "n,m=map(int,input().split())\ns1=list(map(int,input().split()))\ns2=list(map(int,input().split()))\nmin=500\nfor i in range(len(s1)):\n for j in range(len(s2)):\n if s1[i]==s2[j]:\n if s1[i]<min:\n min=s1[i]\n elif(s1[i]>s2[j]):\n if (s2[j]*10+s1[i])<min:\n min=s2[j]*10+s1[i]\n else:\n if (s1[i] * 10 + s2[j]) < min:\n min = s1[i] * 10 + s2[j]\nprint(str(min))\n\t \t \t\t \t\t\t\t \t \t\t \t\t \t\t\t\t", "def pretty(m1,m2,s1,s2):\r\n ar=[]\r\n\r\n \r\n for i in s1:\r\n if i in s2:\r\n ar.append(i)\r\n if ar!=[]:\r\n return(min(ar))\r\n elif m1<m2:\r\n s=str(m1)+str(m2)\r\n return(s)\r\n elif m2<m1:\r\n s=str(m2)+str(m1)\r\n return(s)\r\n\r\n\r\nm,n=map(int,input().split())\r\ns1=list(map(int,input().split()[:m]))\r\ns2=list(map(int,input().split()[:n]))\r\nm1=min(s1)\r\nm2=min(s2)\r\nx=pretty(m1,m2,s1,s2)\r\nprint(x)\r\n", "n,m = map(int, input().split())\r\nline1 = list(map(int,input().split()))\r\nline2= list(map(int,input().split()))\r\na = min(line1)\r\nb = min(line2)\r\nanswer= []\r\n\r\nfor i in range(n):\r\n if line1[i] in line2:\r\n answer.append(line1[i])\r\n\r\nfor i in range(m):\r\n if line2[i] in line1:\r\n answer.append(line2[i])\r\nif answer != []:\r\n print(min(answer))\r\nelse: \r\n if a == 0 or b == 0:\r\n print(max(a,b),min(a,b),sep ='')\r\n else:\r\n print(min(a,b),max(a,b),sep='')", "n, m = map(int, input().split())\r\n*a, = map(int, input().split())\r\n*b, = map(int, input().split())\r\nans = 0\r\nwhile True:\r\n ans += 1\r\n s = str(ans)\r\n if any(str(x) in s for x in a) and any(str(x) in s for x in b):\r\n break\r\nprint(ans)\r\n", "#CodeForces 870A\nn, m = map(int, input().split())\na = set(map(int, input().split()))\nb = set(map(int, input().split()))\n\nx = min(a)\ny = min(b)\ne = a & b\n\nif len(e) != 0:\n print(min(e))\nelse:\n print(min(x, y),max(x, y),sep = '')\n", "a,b = map(int,input().split())\r\naa = list(map(int,input().split()))\r\nbb = list(map(int,input().split()))\r\nfor i in range(1,10):\r\n if i in aa and i in bb :\r\n print(i)\r\n exit(0)\r\nfor i in range(10,100):\r\n if ((i//10 in aa) and (i%10 in bb)) or ((i%10 in aa) and (i//10 in bb)):\r\n print(i)\r\n exit(0)\r\n", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\n\r\nc = set(a) & set(b)\r\nif len(c) == 0:\r\n d = [str(min(a)), str(min(b))]\r\n answer = ''.join(sorted(d))\r\nelse:\r\n answer = str(min(c))\r\n\r\nprint(answer)", "n, m = input().split(\" \")\nn = int(n)\nm = int(m)\n\na = [int(c) for c in input().split(\" \")]\nb = [int(c) for c in input().split(\" \")]\n\na.sort()\nb.sort()\n\nmenor = 100000000000000\n\nfor i in a:\n for j in b:\n jun = int(str(i) + str(j))\n jun2 = int(str(j) + str(i))\n if i == j and i < menor:\n menor = i\n if jun < menor:\n menor = jun\n if jun2 < menor:\n menor = jun2\n\nprint(menor)", "input()\r\na = set(list(map(int, input().split())))\r\nb = set(list(map(int, input().split())))\r\nif (a & b) != set():\r\n print(min(a & b))\r\nelse:\r\n print(str(min(min(a), min(b))) + str(max(min(a), min(b))))", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nk = set(a)\r\nk1 = set(b)\r\nif len(k & k1)>0:\r\n print(min(k & k1))\r\nelse:\r\n print(min(min(a), min(b))*10 + max(min(a), min(b)))", "input()\r\na=set([int(z)for z in input().split()])\r\nb=set([int(z)for z in input().split()])\r\nu=a.intersection(b)\r\nif u: \r\n print(min(u))\r\nelse:\r\n x=[min(a),min(b)]\r\n print(min(x)*10+max(x))", "n1, n2 = (int(x) for x in input().split())\narr1 = set(int(x) for x in input().split())\narr2 = set(int(x) for x in input().split())\n\ncap = arr1 & arr2\nif cap:\n print(min(cap))\nelse:\n print(*sorted([min(arr1), min(arr2)]), sep='')\n", "s = [int(i) for i in input().split()]\r\na = [int(i) for i in input().split()]\r\nb = [int(i) for i in input().split()]\r\nc = []\r\na.sort()\r\nb.sort()\r\nl = 1\r\nfor i in range(len(a)):\r\n for j in range(len(b)):\r\n if a[i] == b[j]:\r\n l = 0\r\n print(a[i])\r\n break\r\n if l == 0:\r\n break\r\nif l == 1:\r\n print('{}{}'.format(min(b[0], a[0]), max(b[0], a[0])))", "aux = input()\n\nans = 10000\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\nfor i in a:\n\tif(i in b):\n\t\tans = min(ans, i)\nif(ans != 10000):\n\tprint(ans)\nelse:\n\ta.sort()\n\tb.sort()\n\tans = []\n\tans.append(a[0])\n\tans.append(b[0])\n\tans.sort()\n\tif(ans[0]==ans[1]):\n\t\tprint(ans[0])\n\telse:\n\t\tprint(ans[0], ans[1], sep='')\t\n\t\n\n\n", "a, b = input().split()\r\nx= set(input().split())\r\ny= set(input().split())\r\nif x&y: print(min(x&y))\r\nelse: print(min(min(x)+min(y), min(y)+min(x)))", "n1, n2 = map(int, input().strip().split())\r\na1 = list(map(int, input().strip().split()))\r\na2 = list(map(int, input().strip().split()))\r\nm1 = min(a1)\r\nm2 = min(a2)\r\na3 = []\r\nfor i in a1:\r\n if i in a2:\r\n a3.append(i)\r\nif len(a3) > 0:\r\n print(min(a3))\r\nelse:\r\n print(10 * min(m1, m2) + max(m1, m2))\r\n", "sizes = input()\n\nflag = False\n\nin1 = input().split(' ')\nin1 = sorted(list(map(int, in1)))\n\nin2 = input().split(' ')\nin2 = sorted(list(map(int, in2)))\n\nfor i in in1:\n if i in in2:\n print(i)\n flag = True\n break\n\n\nif (flag == False):\n if(in1[0] < in2[0]):\n print(str(in1[0]) + str(in2[0]))\n else:\n print(str(in2[0]) + str(in1[0]))\n\t \t \t\t \t\t \t\t\t\t \t\t \t\t", "from itertools import product\n\n\ndef main():\n n, m = map(int, input().split())\n res = set()\n for a, b in product(*[map(int, input().split()) for _ in \"ab\"]):\n if a == b:\n if a:\n res.add(a)\n else:\n if a:\n res.add(a * 10 + b)\n if b:\n res.add(b * 10 + a)\n print(min(res))\n\n\nif __name__ == '__main__':\n main()\n", "\r\ninput()\r\n\r\nn = [int(i) for i in input().split()]\r\nm = [int(i) for i in input().split()]\r\n\r\nsame = []\r\n\r\nfor i in n:\r\n if i in m:\r\n same.append(i)\r\n\r\nmn = min(n)\r\nmm = min(m)\r\n\r\nif mn == mm:\r\n ret = mn\r\nelif mn > mm:\r\n ret = int('{}{}'.format(mm, mn))\r\nelse:\r\n ret = int('{}{}'.format(mn, mm))\r\n\r\nfor i in same:\r\n if i < ret:\r\n ret = i\r\n break\r\n\r\nprint(ret)\r\n", "_1, _2 = map(int, input().split())\r\n\r\ns1 = set(map(int, input().split()))\r\ns2 = set(map(int, input().split()))\r\n\r\nintersect = s1 & s2\r\n\r\nif len(intersect) > 0:\r\n print (min(intersect))\r\nelse:\r\n m1, m2 = min(s1), min(s2)\r\n print(m1 + m2 + 9 * min(m1,m2))\r\n", "input()\r\na = set(map(int, input().split()))\r\nb = set(map(int, input().split()))\r\n\r\nif a.intersection(b) != set():\r\n print(min(a.intersection(b)))\r\nelse:\r\n print(min([min(a), min(b)]), max([min(a), min(b)]), sep=\"\")\r\n", "n,m=[int(i) for i in input().split()]\r\na=[int(i) for i in input().split()]\r\nb=[int(i) for i in input().split()]\r\n\r\nif(set(a)&set(b)):\r\n print(min(set(a)&set(b)))\r\nelse:\r\n min1 = min(set(a))\r\n min2 = min(set(b))\r\n print(str(min(min1,min2))+str(max(min1,min2)))\r\n \r\n", "def intersection(lst1, lst2):\r\n lst3 = [value for value in lst1 if value in lst2]\r\n return lst3\r\n\r\na,b=map(int, input().split())\r\n\r\nl1=list(map(int, input().split()))\r\nl2=list(map(int, input().split()))\r\nl3=intersection(l1,l2)\r\n\r\nif len(l3)>0:\r\n print(min(l3))\r\n\r\nelse:\r\n x=min(l1)\r\n y=min(l2)\r\n if x>y:\r\n print(str(y)+str(x))\r\n else:\r\n print(str(x) + str(y))\r\n", "def breakdown(num):\n\tbroken=[]\n\twhile(num is not 0):\n\t\tr = num%10\n\t\tbroken.append(r)\n\t\tnum=int(num/10)\n\treturn broken \n\nuserip = input('').split(' ')\nn = int(userip[0])\nm = int(userip[1])\nfirstlist = []\nsecondlist = []\nfirstlist = [int(i) for i in input('').split(' ')]\nsecondlist = [int(i) for i in input('').split(' ')]\ntestnum = 1\nwhile(True):\n\tif(testnum<10):\n\t\tif(testnum in firstlist and testnum in secondlist):\n\t\t\tbreak \n\telse:\n\t\tb,a = breakdown(testnum)\n\t\tif((a in firstlist and b in secondlist) or (a in secondlist and b in firstlist)):\n\t\t\tbreak \n\ttestnum+=1\nprint(testnum)\n \t \t \t \t \t\t\t \t\t\t \t\t \t", "n,m=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nk=[i for i in a if i in b]\r\nif k:\r\n print(min(k))\r\nelse:\r\n if min(a)<min(b):\r\n print(str(min(a))+str(min(b)))\r\n else:\r\n print(str(min(b))+str(min(a)))", "n,m = [int(i) for i in input().split()]\nns = set(int(i) for i in input().split())\nms = set(int(i) for i in input().split())\n\n#find smallest pretty integer\ns = ns.intersection(ms) \nm1 = min(ns)\nm2 = min(ms)\n\nif s:\n print(min(s))\nelif m1 < m2:\n print(m1*10+m2)\nelse:\n print(m2*10+m1) \n", "nm = input().split()\n\nn = set(map(int, input().split()))\nm = set(map(int, input().split()))\n\nmin_n = min(n)\nmin_m = min(m)\n\nsorted = sorted((str(min_n) + str(min_m)))\n\nm_n = n & m \n\nif m_n:\n print(min(m_n))\nelse:\n print(sorted[0] + sorted[1])\n\t \t \t \t\t \t \t \t \t \t \t\t\t \t \t", "n, m = list(map(int, input().split()))\r\nnums1 = set(input().split())\r\nnums2 = set(input().split())\r\nintersect = nums1 & nums2\r\n\r\nnums1 = sorted(list(nums1 - intersect))\r\nnums2 = sorted(list(nums2 - intersect))\r\nintersect = sorted(list(intersect))\r\n\r\nif len(intersect) > 0:\r\n\tprint(intersect[0])\r\nelse:\r\n\tif nums1[0] < nums2[0]:\r\n\t\tprint(nums1[0] + nums2[0])\r\n\telse:\r\n\t\tprint(nums2[0] + nums1[0])\r\n", "n , m = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\n\r\nfor i in range(100):\r\n found1 = 0 \r\n found2 = 0\r\n string = str(i)\r\n for it in string:\r\n it = int(it)\r\n if it in a:\r\n found1 = 1\r\n \r\n if it in b:\r\n found2 = 1 \r\n if found1 and found2 :\r\n print(i)\r\n break\r\n\r\n", "n_m = input().split()\r\nn, m = n_m\r\n\r\nn, m = int(n), int(m)\r\n\r\nl1 = input().split()\r\nl2 = input().split()\r\n\r\nl1 = [int(x) for x in l1]\r\nl2 = [int(y) for y in l2]\r\n\r\nmenorl1 = 10\r\nmenorl2 = 10\r\n\r\ni = 0\r\nwhile i < n:\r\n if l1[i] < menorl1:\r\n menorl1 = l1[i]\r\n i += 1\r\n\r\nj = 0\r\nwhile j < m:\r\n if l2[j] < menorl2:\r\n menorl2 = l2[j]\r\n j += 1\r\n\r\ncoincid = 10\r\nfor e in l1:\r\n if e in l2:\r\n if e < coincid:\r\n coincid = e\r\n\r\nif coincid == 10:\r\n menor = min(menorl1, menorl2)\r\n maior = max(menorl1, menorl2)\r\n print(str(menor) + str(maior))\r\n\r\nelse:\r\n print(coincid)", "input()\r\nN=list(map(int,input().split()))\r\nM=list(map(int,input().split()))\r\n\r\nS = set(M).intersection(set(N))\r\nif len(S) != 0:\r\n print(min(S))\r\nelse:\r\n if min(N) < min (M):\r\n print(min(N) * 10 + min(M))\r\n else:\r\n print(min(M) * 10 + min(N))", "n,m=input().split()\r\na = list(map(int, input().split(\" \")))\r\nb = list(map(int, input().split(\" \")))\r\nm = min(a)\r\nm1 = min(b)\r\nif m == m1:\r\n print(m)\r\nelse:\r\n number = str(min(m,m1))+str(max(m,m1))\r\n l = []\r\n for i in a:\r\n if b.count(i) > 0:\r\n l.append(i)\r\n for i in l:\r\n if i < int(number):\r\n print(i)\r\n exit()\r\n print(number)", "def solve():\r\n n,m = map(int,input().split())\r\n a = [int(i) for i in input().split()]\r\n b = [int(i) for i in input().split()]\r\n t = []\r\n for i in a:\r\n if i in b:\r\n t.append(i)\r\n a1,a2 = min(a),min(b)\r\n if len(t)!=0:\r\n print(min(t))\r\n return\r\n elif a1 == a2:\r\n print(a1)\r\n return\r\n else:\r\n if a1 > a2:\r\n print(int(str(a2) + str(a1)))\r\n return\r\n else:\r\n print(int(str(a1) + str(a2)))\r\n return\r\n\r\n# t = int(input())\r\n# for _ in range(t):\r\nsolve()\r\n", "n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\na.sort()\r\nfor i in range(1,10):\r\n if i in a and i in b:\r\n print(i)\r\n exit()\r\nfor i in range(10,101):\r\n if i // 10 in a and i % 10 in b or i // 10 in b and i % 10 in a:\r\n print(i)\r\n break\r\n", "n, m = [int(i) for i in input().split()]\r\na = [int(i) for i in input().split()]\r\nb = [int(i) for i in input().split()]\r\n\r\nmin_a = min(a)\r\nmin_b = min(b)\r\n\r\nres = 10\r\n\r\nfor i in a:\r\n if i in b and res > i:\r\n res = i\r\n \r\nif res == 10:\r\n if min_b > min_a:\r\n res = min_a*10+min_b\r\n elif min_b < min_a:\r\n res = min_b*10+min_a\r\n else: res = min_a\r\nprint(res)", "n, m = input().split()\na=set(map(int,input().split()))\nb=set(map(int,input().split()))\nif b.intersection(a):\n print(min(b.intersection(a)))\nelse:\n minimum = min(min(a), min(b))\n maximum = max(min(a), min(b))\n print(int(str(minimum)+str(maximum)))\n", "n,m = map(int,input().split())\r\ns1 = set(map(int,input().split()))\r\ns2 = set(map(int,input().split()))\r\nif s1&s2:\r\n print(min(s1&s2))\r\nelse:\r\n c1 = min(s1)\r\n c2 = min(s2)\r\n if c1<c2:\r\n print(c1*10+c2)\r\n else:\r\n print(c2*10+c1)", "input()\r\ns1=set(input().split())\r\ns2=set(input().split())\r\nif s1&s2:print(min(s1&s2))\r\nelse:print(''.join(sorted(min(s1)+min(s2))))", "n,m=map(int,input().split())\r\nN=[int(x) for x in input().split()]\r\nM=[int(x) for x in input().split()]\r\nMIN1=min(N)\r\nMIN2=min(M)\r\nMIN=1000\r\nKATE=list(set(N).intersection(set(M)))\r\n#print(KATE,set(N),set(M))\r\nif KATE:\r\n MIN=min(KATE)\r\nL=[MIN,int(str(MIN1)+str(MIN2)),int(str(MIN2)+str(MIN1))]\r\n'''\r\nif MIN1==MIN2:\r\n print(MIN1)\r\nelse:\r\n print(min(L))\r\n'''\r\nprint(min(L))\r\n", "a,b=[int(i) for i in input().split()]\r\nx=[int(i) for i in input().split()]\r\ny=[int(i) for i in input().split()]\r\ng=[False]*10\r\nk=10\r\nfor i in x:\r\n g[i]=True\r\nfor i in y:\r\n if g[i] and k > i:\r\n k=i\r\nif k!=10:\r\n print(k)\r\nelse: \r\n print(min(min(x),min(y)),max(min(x),min(y)),sep=\"\")\r\n", "# AA Iniciante 2022.1 - Lista 01: Ad-Hoc 1\n# K. Search for Pretty Integers\n# author: uncoded\n\ndef main():\n n, m = map(int, input().split())\n a = list(map(int, input().split()))\n b = list(map(int, input().split()))\n inters = set(a) & set(b)\n if inters:\n print(min(inters))\n else:\n min_a = min(a)\n min_b = min(b)\n print(min(min_a, min_b) * 10 + max(min_a, min_b))\n\nif __name__ == \"__main__\":\n main()\n\n", "n, m = map(int, input().split())\r\nlista_1 = list(map(int, input().split()))\r\nlista_2 = list(map(int, input().split()))\r\nlista = lista_1 + lista_2\r\nlista.sort()\r\nigual = False\r\ndic = {}\r\n\r\nfor elemento in lista:\r\n if elemento in dic:\r\n dic[elemento] += 1\r\n print(elemento)\r\n igual = True\r\n break\r\n else:\r\n dic[elemento] = 1\r\n\r\nif not igual:\r\n print(f\"{min(min(lista_1), min(lista_2))}{max(min(lista_1), min(lista_2))}\")\r\n", "n = [int(i) for i in input().split()]\nlist_n1 = [int(i) for i in input().split()]\nlist_n2 = [int(i) for i in input().split()]\nlist_n1.sort()\nlist_n2.sort()\ncon=0\nfor i in list_n1:\n if i in list_n2:\n print(i)\n con=1\n break\nif con != 1:\n if list_n1[0] == list_n2[0]:\n print(list_n1[0])\n elif list_n1[0] > list_n2[0]:\n print(str(list_n2[0])+str(list_n1[0]))\n else:\n print(str(list_n1[0])+str(list_n2[0]))\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\nN = list(map(int, input().split()))\r\nM = list(map(int, input().split()))\r\nU = set(N) & set(M)\r\nif (len(U)!=0):\r\n print(min(U))\r\nelse:\r\n q, w = min(N), min(M)\r\n if (q>w):\r\n q, w = w, q\r\n print (q, w, sep=\"\")", "x,y = map(int,input().split())\r\n\r\nlst1 = []\r\nlst2 = []\r\n\r\nnum1 = map(int,input().split())\r\nnum2 = map(int,input().split())\r\n\r\nfor a in num1:\r\n lst1.append(a)\r\nfor b in num2:\r\n lst2.append(b)\r\n\r\nlst1.sort()\r\nlst2.sort()\r\n\r\nintersec = []\r\n\r\nfor x in range(0,len(lst1)):\r\n for y in range(0,len(lst2)):\r\n if lst1[x] == lst2[y]:\r\n intersec.append(lst1[x])\r\n\r\nif len(intersec) == 0:\r\n if lst1[0] > lst2[0]:\r\n print(str(lst2[0])+str(lst1[0]))\r\n else:\r\n print(str(lst1[0])+str(lst2[0]))\r\nelse:\r\n print(intersec[0])\r\n", "# import sys\r\n# sys.stdin=open(\"input.in\",'r')\r\n# sys.stdout=open(\"out.out\",'w')\t\r\nn,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nx=min(a)\r\ny=min(b)\r\ns=100\r\nfor i in range(n):\r\n\tif a[i] in b:\r\n\t\ts=min(s,a[i])\r\nif s==100:\r\n\ts=min(x,y)*10+max(x,y)\r\n\r\nprint(s)\t", "x, y = input().split()\nx = int(x)\ny = int(y)\n\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\n\nm = list(set(a).intersection(b))\n\nif(len(m) > 0):\n print(m[0])\nelse:\n a.sort()\n b.sort()\n min1 = a[0]\n min2 = b[0]\n if(min1 < min2):\n print(str(min1) + str(min2))\n else:\n print(str(min2) + str(min1))\n \t\t\t \t \t \t\t \t\t \t\t \t \t \t\t\t\t", "def solve():\r\n n,m = map(int,input().split())\r\n a = [int(i) for i in input().split()]\r\n b = [int(i) for i in input().split()]\r\n t = []\r\n for i in a:\r\n if i in b:\r\n t.append(i)\r\n a1,a2 = min(a),min(b)\r\n if a1==a2:\r\n print(a1)\r\n return\r\n else:\r\n ans= 0\r\n if len(t)!=0:\r\n m = []\r\n for i in t:\r\n l = i\r\n if a1 > a2:\r\n ans = min(l, (int(str(a2) + str(a1))))\r\n else:\r\n ans = min(l, int(str(a1) + str(a2)))\r\n m.append(ans)\r\n print(min(m))\r\n return\r\n\r\n if a1 == a2:\r\n print(a1)\r\n return\r\n else:\r\n if a1 > a2:\r\n print(int(str(a2) + str(a1)))\r\n return\r\n else:\r\n print(int(str(a1) + str(a2)))\r\n return\r\n\r\n# t = int(input())\r\n# for _ in range(t):\r\nsolve()\r\n", "a = list(map(int, input().split()))\r\nb = sorted(list(map(int, input().split())))\r\nc = sorted(list(map(int, input().split())))\r\nkras_chis = []\r\nfor i in b:\r\n if i in c:\r\n kras_chis.append(i)\r\nif kras_chis:\r\n s = min(kras_chis)\r\n print(s)\r\nelse:\r\n bo = str(b[0])\r\n oof = str(c[0])\r\n if b[0] < c[0]:\r\n print(bo + oof)\r\n else:\r\n print(oof + bo)", "n, m=map(int, input(). split())\nMn1 =set(input(). split() ) \nMn2=set(input(). split() )\nMn3={} \nMn3=Mn1&Mn2\nif Mn3:\n print(int(min(Mn3))) \n exit() \nmn1=int(min(Mn1)) \nmn2=int(min(Mn2)) \nif mn1==mn2:\n print(mn1) \nelif mn1<mn2:\n print(mn1*10+mn2) \nelse:\n print(mn2*10+mn1) ", "input()\r\nlista_a = list(map(int, input().split(\" \")))\r\nlista_b = list(map(int, input().split(\" \")))\r\n\r\nvalores_iguais = []\r\n\r\nif(len(lista_a) < len(lista_b)):\r\n valores_iguais = [num for num in lista_a if num in lista_b]\r\nelse:\r\n valores_iguais = [num for num in lista_b if num in lista_a]\r\n\r\nif valores_iguais:\r\n print(min(valores_iguais))\r\nelse:\r\n b = min(lista_b)\r\n a = min(lista_a)\r\n\r\n if a < b:\r\n print(str(a) + str(b))\r\n else:\r\n print(str(b) + str(a))", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\na.sort()\r\nb.sort()\r\nfor i in range(1,10):\r\n if i in a and i in b:\r\n print(i)\r\n exit()\r\nk=min(a)\r\nb=min(b)\r\nprint(str(min(k,b))+str(max(k,b)))\r\n", "##*** I came, I saw, I conquered. ***\nimport sys\n\nn, m = map(int, input().split())\n\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\nfor i in range(1, 10):\n if i in a and i in b:\n print(i)\n exit(0)\n\nx = min(a)\ny = min(b)\n\nsys.stdout.write(\"%d%d\"%(min(x, y), max(x, y)))\n", "# -*- coding: utf-8 -*-\r\n\r\nimport math\r\nimport collections\r\nimport bisect\r\nimport heapq\r\nimport time\r\nimport random\r\nimport itertools\r\n\r\n\"\"\"\r\ncreated by shhuan at 2017/10/20 08:16\r\n\r\n\"\"\"\r\n\r\n\r\nN, M = map(int, input().split())\r\nA = [int(x) for x in input().split()]\r\nB = [int(x) for x in input().split()]\r\n\r\na = min(A)\r\nb = min(B)\r\nc = set(A) & set(B)\r\n\r\nif c:\r\n print(min(c))\r\nelif a > b:\r\n print(b*10+a)\r\nelse:\r\n print(a*10+b)\r\n", "a, b = map(int, input().split())\r\narr1 = list(map(int, input().split()))\r\narr2 = list(map(int, input().split()))\r\n\r\nans = min(min(arr1), min(arr2))*10 + max(min(arr1), min(arr2))\r\n\r\ncommon = set(arr1).intersection(set(arr2))\r\n\r\nif common:\r\n for n in common:\r\n if n < ans:\r\n ans = n\r\n\r\nprint(ans)\r\n\r\n\r\n", "def list_input(): return list(map(int, input().split()))\r\n\r\n\r\ndef multiple_input(): return map(int, input().split())\r\n\r\n\r\nn, m = multiple_input()\r\na = list_input()\r\nb = list_input()\r\nb.sort()\r\nflag, d = 0, dict()\r\nx, y = min(min(a), b[0]), max(min(a), b[0])\r\nfor i in a:\r\n d[i] = 1\r\nfor i in b:\r\n if i in a:\r\n flag = 1\r\n ans = i\r\n break\r\nif flag == 0:\r\n print(str(x)+str(y))\r\nelse:\r\n print(ans)", "#from sys import stdin, stdout\r\n#t = int(stdin.readline())\r\nt=1\r\nwhile t!=0:\r\n t-=1 \r\n n,m = map(int, input().split())\r\n p = [int(x) for x in input().split()]\r\n q = [int(x) for x in input().split()]\r\n ans = 0\r\n for i in range(1, 10):\r\n if i in p and i in q:\r\n ans = i \r\n break \r\n if ans!=0:\r\n print(ans)\r\n else:\r\n a , b = min(p), min(q)\r\n if a==b:\r\n print(a)\r\n else:\r\n print(str(min(a,b))+str(max(a,b)))\r\n \r\n", "n,m= map(int, input().split())\r\na= list(map(int, input().split()))\r\nb =list(map(int, input().split()))\r\nclow=list()\r\nfor i in a:\r\n if i in set(b):\r\n clow.append(i)\r\n\r\nam = min(a)\r\nbm = min(b)\r\ncl=100\r\nif clow:\r\n cl = min(clow)\r\n\r\nif am==bm:\r\n print(min(cl, am))\r\nelse:\r\n print(min(cl, min(am,bm)*10 + max(am,bm)))", "n, m = [int(i) for i in input().split()]\r\ns1 = set([int(i) for i in input().split()])\r\ns2 = set([int(i) for i in input().split()])\r\na1 = min(s1)\r\na2 = min(s2)\r\n\r\ni = s1.intersection(s2)\r\n\r\ntry:\r\n print(min(i))\r\nexcept:\r\n print(str(min(a1, a2))+str(max(a1, a2)))", "from sys import stdin\r\ninput = stdin.readline\r\n\r\nlength_1, length_2 = [int(x) for x in input().split()]\r\nset_1 = {int(x) for x in input().split()}\r\nset_2 = {int(x) for x in input().split()}\r\n\r\ninter = set_1.intersection(set_2)\r\nif inter:\r\n print(min(inter))\r\n\r\nelse:\r\n\r\n un = set_1.union(set_2)\r\n smallest_nonzero = None\r\n for x in sorted(un):\r\n if x >0:\r\n smallest_nonzero = x\r\n break\r\n \r\n if smallest_nonzero in set_2:\r\n set_1, set_2 = set_2, set_1\r\n \r\n second = min(set_2)\r\n ans = 10*smallest_nonzero + second\r\n print(ans)\r\n ", "n,m = [int(i) for i in input().split()]\na1 = [int(i) for i in input().split()]\na2 = [int(i) for i in input().split()]\n\npr = 1\n\nwhile True:\n\n if(pr<10):\n if(pr in a1 and pr in a2):\n print(pr)\n break\n elif((pr//10 in a1 and pr%10 in a2) or (pr//10 in a2 and pr%10 in a1)):\n print(pr)\n break\n pr+=1\n ", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\neps = 1.0 / 10**15\nmod = 10**9+7\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\n\n\ndef main():\n n,m = LI()\n a = set(LI())\n b = set(LI())\n c = a&b\n if c:\n return min(c)\n a = min(a)\n b = min(b)\n if a>b:\n a,b = b,a\n\n return a*10+b\n\n\nprint(main())\n\n\n", "n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\nc = a + b; c = sorted(list(set(c)));\r\nfor i in range(len(c)):\r\n if c[i] in a and c[i] in b: print(c[i]);exit()\r\nd = min(a); e = min(b)\r\nprint(min(d,e),end = \"\"); print(max(d,e))\r\n", "n, m = [int(i) for i in input().split()]\r\na=[int(i) for i in input().split()]\r\nb=[int(i) for i in input().split()]\r\na.sort()\r\nb.sort()\r\nsa={i for i in a}\r\nsb={i for i in b}\r\nx=a[0]\r\ny=b[0]\r\nfor i in range(1, 10):\r\n if (i in sa) and (i in sb):\r\n x, y=i, i\r\n break\r\nif x==y:\r\n print(x)\r\nelse:\r\n print(str(min(x, y))+str(max(x, y)))\r\n ", "in1 = input()\r\nin2 = input().split()\r\nin3 = input().split()\r\nin2 = set(map(int,in2))\r\nin3 = list(map(int,in3))\r\na1 = min(in2)\r\na2 = min(in3)\r\na = in2.intersection(in3)\r\nif a:\r\n print(min(a))\r\nelse:\r\n print(min(a1,a2)*10 + max(a1,a2))\r\n", "n,m=map(int,input().split())\r\nl1=list(map(int,input().split()))\r\nl2=list(map(int,input().split()))\r\na=0\r\nb=0\r\nif 1 in l1 and 1 in l2 :\r\n print(1)\r\nelif 2 in l1 and 2 in l2:\r\n print(2)\r\nelif 3 in l1 and 3 in l2:\r\n print(3)\r\nelif 4 in l1 and 4 in l2:\r\n print(4)\r\nelif 5 in l1 and 5 in l2:\r\n print(5)\r\nelif 6 in l1 and 6 in l2:\r\n print(6)\r\nelif 7 in l1 and 7 in l2:\r\n print(7)\r\nelif 8 in l1 and 8 in l2:\r\n print(8)\r\nelif 9 in l1 and 9 in l2:\r\n print(9)\r\nelse:\r\n l1.sort()\r\n l2.sort()\r\n if l1[0]<=l2[0]:\r\n a=l1[0]*10+l2[0]\r\n print(a)\r\n else:\r\n b=l2[0]*10+l1[0]\r\n print(b)", "n, m = map(int, input().split())\narr = [int(i) for i in input().split()]\narr2 = [int(i) for i in input().split()]\n\narr.sort()\narr2.sort()\n\nfrom collections import Counter\n\nc1 = Counter(arr)\nc2 = Counter(arr2)\n\nfor i in c1:\n if c2[i] != 0:\n print(i)\n exit()\n\nf, s = (arr[0] * 10) + arr2[0], (arr2[0] * 10) + arr[0]\n\nprint(min(f, s))\n", "import sys\r\nn, m = map(int, input().split())\r\na = sorted(map(int, input().split()))\r\nb = sorted(map(int, input().split()))\r\nfor i in range (n):\r\n if a[i] in b :\r\n print(a[i])\r\n sys.exit(0)\r\nprint (min(a[0], b[0]) * 10 + max(a[0], b[0]))\r\n", "def main_function():\r\n n, k = [int(i) for i in input().split(\" \")]\r\n a = sorted([int(i) for i in input().split(\" \")])\r\n b = sorted([int(i) for i in input().split(\" \")])\r\n d = {}\r\n for i in a + b:\r\n if i in d:\r\n d[i] += 1\r\n else:\r\n d[i] = 1\r\n for i in d:\r\n if d[i] > 1:\r\n return i\r\n if a[0] < b[0]:\r\n return int(str(a[0]) + str(b[0]))\r\n return int(str(b[0]) + str(a[0]))\r\n\r\n\r\n\r\n\r\n\r\nprint(main_function())", "q = input().split()\nl1 = input().split()\nl2= input().split()\nl1.sort()\nl2.sort()\nnM = 0\n\nif int(l1[0]) < int(l2[0]):\n nM = int(str(l1[0])+str(l2[0]))\nelse:\n nM = int(str(l2[0]) + str(l1[0]))\n\nfor i in l1:\n if i in l2:\n if int(i) < int(nM):\n nM = i\nprint(nM)", "quantidade = input().split()\nlista1 = input().split()\nlista2= input().split()\nlista1.sort()\nlista2.sort()\nnumMin = 0\n\nif int(lista1[0]) < int(lista2[0]):\n numMin = int(str(lista1[0])+str(lista2[0]))\nelse:\n numMin = int(str(lista2[0]) + str(lista1[0]))\n\nfor i in lista1:\n if i in lista2:\n if int(i) < int(numMin):\n numMin = i\nprint(numMin)", "n, m = map(int, input().split())\na = input().split()\nb = input().split()\nfor x in range(1, 100):\n\ts = str(x)\n\tt1, t2 = False, False\n\tfor c in s:\n\t\tif c in a:\n\t\t\tt1 = True\n\t\tif c in b:\n\t\t\tt2 = True\n\tif t1 and t2:\n\t\tprint(x)\n\t\texit(0)\n", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nb.sort()\r\na.sort()\r\nfor i in a:\r\n if i in b:\r\n print(i)\r\n exit()\r\nc= []\r\nc.append(a[0])\r\nc.append(b[0])\r\nc.sort()\r\nprint(*c,sep=\"\")\r\n", "x = lambda:{*input().split()}\r\nx()\r\na,b = x(),x()\r\nc,d = sorted([*min(a),min(b)])\r\nprint([c+d,min({\"9\"}|a&b)][len(a&b)>0])", "input();c=lambda: list(map(int,input().split()));k=(c());k1=c();d=set(set(k).intersection(set(k1)));z=min(k);z1=min(k1)\r\ntry:print(min(int(str(min(z,z1))+str(max(z,z1))),int(str(min(d)))))\r\nexcept:print(int(str(min(z,z1))+str(max(z,z1))))", "def main():\r\n n, m = map(int, input().split())\r\n arr_n = list(map(int, input().split()))\r\n arr_m = list(map(int, input().split()))\r\n\r\n inter = set(arr_n).intersection(set(arr_m))\r\n\r\n abs_min = None\r\n if inter:\r\n abs_min = min(inter)\r\n\r\n if abs_min:\r\n print(abs_min)\r\n return\r\n\r\n min_n = min(arr_n)\r\n min_m = min(arr_m)\r\n\r\n if min_n < min_m:\r\n print(min_n, min_m, sep='')\r\n elif min_m < min_n:\r\n print(min_m, min_n, sep='')\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n,m = map(str,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\na = sorted(a)\r\nb = sorted(b)\r\nt = b[0]\r\nr = a[0]\r\ng = []\r\nd = 0\r\ns = 0\r\nfor i in b:\r\n if i in a:\r\n g.append(i)\r\n\r\nif r == t:\r\n d = r\r\n g.append(d)\r\nelse:\r\n d = str(r) + str(t)\r\n s = str(t) + str(r)\r\n if int(r) < int(t):\r\n g.append(int(d))\r\n if int(r) > int(t):\r\n g.append(int(s))\r\ng = sorted(g)\r\nprint(g[0])\r\n", "# n = input()\n\n# s = list(set(n))\n\n# if len(s)>2:\n# return ('NO')\n\ndef f(arr1,arr2):\n set1 = set(arr1)\n set2 = set(arr2)\n set3 = set1.intersection(set2)\n if len(set3)>0:\n set3 = list(set3)\n set3.sort()\n return set3[0]\n arr1.sort()\n arr2.sort()\n\n if arr1[0]==arr2[0]:\n return arr1[0]\n\n else:\n arr3 = [arr1[0],arr2[0]]\n arr3.sort()\n return arr3[0]*10+arr3[1]\n\nnum = list(map(int,input().split()))\n\narr1 = list(map(int,input().split()))\narr2 = list(map(int,input().split()))\n\nprint(f(arr1,arr2))", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nmin = 100\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i] == b[j] and a[i] < min:\r\n min = a[i]\r\n elif int(str(a[i]) + str(b[j])) or int(str(b[j]) + str(a[i])):\r\n if a[i] <= b[j] and int(str(a[i]) + str(b[j])) < min:\r\n min = int(str(a[i]) + str(b[j]))\r\n elif b[j] <= a[i] and int(str(b[j]) + str(a[i])) < min:\r\n min = int(str(b[j]) + str(a[i]))\r\nprint(min)", "nah = input()\nline1 = sorted(input().split())\nline2 = sorted(input().split())\n\ndef pretty_int(line1, line2):\n for num in line1:\n if num in line2:\n return num\n if line1[0] + line2[0] > line2[0] + line1[0]:\n return line2[0] + line1[0]\n else:\n return line1[0] + line2[0]\nprint(pretty_int(line1, line2))\n", "n, m = map(int, input().split())\n\nlist1 = list(map(int, input().split()))\n\nlist2 = list(map(int, input().split()))\n\nset2 = set(list2)\n\nminCommon = 10\n\nfor i in list1:\n if i in set2:\n minCommon = min(minCommon, i)\n\nif minCommon <10: print(minCommon)\n\nelse:\n dig1 = min(list1)\n dig2 = min(list2)\n\n if dig1 == dig2: print(dig1)\n\n elif dig1 < dig2:\n res = (dig1*10)+ dig2\n print(res)\n\n else:\n res = (dig2*10) + dig1\n print(res)", "listsLength = list(map(int, input().split()))\nfirstList = list(map(int, input().split()))\nsecondList = list(map(int, input().split()))\n\nminFirstList = min(firstList)\nminSecondList = min(secondList)\n\nrepitedNum = []\n\nfor n in firstList:\n if(n in secondList):\n repitedNum.append(n)\n\nif(len(repitedNum)):\n print(min(repitedNum))\nelif(minFirstList in secondList):\n print(minFirstList)\nelif(minSecondList in firstList):\n print(minSecondList)\nelse:\n digitA = min(minFirstList, minSecondList)\n digitB = max(minFirstList, minSecondList)\n print(str(digitA) + str(digitB))", "n,m=map(int,input().split())\r\nl1=set(map(int,input().split()))\r\nl2=set(map(int,input().split()))\r\nans=list(l1&l2)\r\nif len(ans)>=1:\r\n print(min(ans))\r\nelse:\r\n print(min(min(l1),min(l2)),max(min(l1),min(l2)),sep=\"\")\r\n", "n,m = map(int,input().split())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\na.sort()\nb.sort()\nx = 101\nfor i in range(n):\n\tif a[i] in b:\n\t\tx = a[i]\n\t\tbreak\nprint(min(x,min((a[0]*10+b[0]),(b[0]*10+a[0]))))\n", "n, m = map(int, input().split())\r\nmas = list(map(int, input().split()))\r\ngas = list(map(int, input().split()))\r\nmas.sort()\r\ngas.sort()\r\nfor a in range(n):\r\n for b in range(m):\r\n if mas[a] == gas[b]:\r\n print(mas[a])\r\n exit(0)\r\nq = str(min(mas[0], gas[0])) + str(max(mas[0], gas[0]))\r\nif q[0] == q[1]:\r\n print(q[0])\r\nelse:\r\n print(q)", "n, m=map(int, input().split())\r\na=list(map(int, input().split()))\r\nb=list(map(int, input().split()))\r\nk=10\r\nfor i in range (len(a)):\r\n for j in range(len(b)):\r\n if (a[i]==b[j]) and (a[i]<k):\r\n k=a[i]\r\n \r\nif k!=10:\r\n print(k)\r\nelse:\r\n a1=min(a)\r\n a2=min(b)\r\n b1=min(a1, a2)\r\n b2=max(a1, a2)\r\n print(10*b1+b2)" ]
{"inputs": ["2 3\n4 2\n5 7 6", "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1", "1 1\n9\n1", "9 1\n5 4 2 3 6 1 7 9 8\n9", "5 3\n7 2 5 8 6\n3 1 9", "4 5\n5 2 6 4\n8 9 1 3 7", "5 9\n4 2 1 6 7\n2 3 4 5 6 7 8 9 1", "9 9\n5 4 3 2 1 6 7 8 9\n3 2 1 5 4 7 8 9 6", "9 5\n2 3 4 5 6 7 8 9 1\n4 2 1 6 7", "9 9\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5 6 7 8 9", "9 9\n1 2 3 4 5 6 7 8 9\n9 8 7 6 5 4 3 2 1", "9 9\n9 8 7 6 5 4 3 2 1\n1 2 3 4 5 6 7 8 9", "9 9\n9 8 7 6 5 4 3 2 1\n9 8 7 6 5 4 3 2 1", "1 1\n8\n9", "1 1\n9\n8", "1 1\n1\n2", "1 1\n2\n1", "1 1\n9\n9", "1 1\n1\n1", "4 5\n3 2 4 5\n1 6 5 9 8", "3 2\n4 5 6\n1 5", "5 4\n1 3 5 6 7\n2 4 3 9", "5 5\n1 3 5 7 9\n2 4 6 8 9", "2 2\n1 8\n2 8", "5 5\n5 6 7 8 9\n1 2 3 4 5", "5 5\n1 2 3 4 5\n1 2 3 4 5", "5 5\n1 2 3 4 5\n2 3 4 5 6", "2 2\n1 5\n2 5", "4 4\n1 3 5 8\n2 4 6 8", "3 3\n1 5 3\n2 5 7", "3 3\n3 6 8\n2 6 9", "2 2\n1 4\n2 4", "5 3\n3 4 5 6 7\n1 5 9", "4 4\n1 2 3 4\n2 5 6 7", "5 5\n1 2 3 4 5\n9 2 1 7 5", "2 2\n1 3\n2 3", "3 3\n3 2 1\n3 2 1", "3 3\n1 3 5\n2 3 6", "3 3\n5 6 7\n5 6 7", "1 2\n5\n2 5", "3 3\n2 4 9\n7 8 9", "3 3\n1 2 4\n3 4 5", "3 2\n1 4 9\n2 4", "3 3\n3 5 6\n1 5 9", "3 2\n1 2 4\n3 4", "2 4\n8 9\n1 2 3 9", "1 2\n9\n8 9", "3 2\n1 2 4\n4 2", "2 3\n4 5\n1 3 5", "3 2\n1 2 3\n2 3", "4 3\n1 3 5 9\n2 8 9", "2 2\n1 9\n9 2"], "outputs": ["25", "1", "19", "9", "12", "12", "1", "1", "1", "1", "1", "1", "1", "89", "89", "12", "12", "9", "1", "5", "5", "3", "9", "8", "5", "1", "2", "5", "8", "5", "6", "4", "5", "2", "1", "3", "1", "3", "5", "5", "9", "4", "4", "5", "4", "9", "9", "2", "5", "2", "9", "9"]}
UNKNOWN
PYTHON3
CODEFORCES
355
14c08f41b8f7741fa46a3cff0a623a6c
Multiplication Table
Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn only the multiplication table of decimals (and some students even learn it in the first grade). Help Petya make a multiplication table for numbers in the system of notations with the radix *k*. The first line contains a single integer *k* (2<=≤<=*k*<=≤<=10) — the radix of the system. Output the multiplication table for the system of notations with the radix *k*. The table must contain *k*<=-<=1 rows and *k*<=-<=1 columns. The element on the crossing of the *i*-th row and the *j*-th column is equal to the product of *i* and *j* in the system of notations with the radix *k*. Each line may have any number of spaces between the numbers (the extra spaces in the samples are put for clarity). Sample Input 10 3 Sample Output 1 2 3 4 5 6 7 8 9 2 4 6 8 10 12 14 16 18 3 6 9 12 15 18 21 24 27 4 8 12 16 20 24 28 32 36 5 10 15 20 25 30 35 40 45 6 12 18 24 30 36 42 48 54 7 14 21 28 35 42 49 56 63 8 16 24 32 40 48 56 64 72 9 18 27 36 45 54 63 72 81 1 2 2 11
[ "# Code by : Sam._.072\r\n\r\ndef dec_to_base(num,base): #Maximum base - 36\r\n base_num = \"\"\r\n while num>0:\r\n dig = int(num%base)\r\n if dig<10:\r\n base_num += str(dig)\r\n else:\r\n base_num += chr(ord('A')+dig-10) #Using uppercase letters\r\n num //= base\r\n\r\n base_num = base_num[::-1] #To reverse the string\r\n return base_num\r\n\r\nn = int(input())\r\nfor i in range(1,n):\r\n for j in range(1,n):\r\n print(dec_to_base(i*j, n),end=\" \")\r\n print()", "from sys import stdout\r\nfrom sys import stdin\r\ndef get():\r\n return stdin.readline().strip()\r\ndef getf():\r\n return [int(i) for i in get().split()]\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(map(str, a)) + end)\r\n\r\ndef matrix(n, m, a = 0):\r\n return [[a for i in range(m)]for j in range(n)]\r\n\r\ndef transf(a, k):\r\n s = \"\"\r\n while(a >= k):\r\n s += str(a % k)\r\n a //= k\r\n s += str(a)\r\n return s[::-1]\r\n\r\ndef main():\r\n n = int(get())\r\n t = matrix(n - 1, n - 1)\r\n for i in range(1, n):\r\n for j in range(1, n):\r\n t[i - 1][j - 1] = transf(i*j, n)\r\n for i in t:\r\n putf(i)\r\nmain()\r\n", "n = int(input())\r\nf = lambda x: x if x < n else f(x // n) * 10 + x % n\r\nfor i in range(1, n): \r\n print(*[f(i * j) for j in range(1, n)])", "def from_10_to_K(n, k):\r\n res = ''\r\n n= int(n)\r\n while n >0:\r\n ost = n % k\r\n n = n // k\r\n res += str(ost)\r\n res = res[::-1]\r\n return res\r\n\r\nk = int(input())\r\nfor i in range(1, k):\r\n for j in range(1, k):\r\n print(from_10_to_K(i*j, k), end=' ')\r\n print()", "N=int(input())\r\n\r\nfor i in range(1,N):\r\n ANS=[]\r\n for j in range(1,N):\r\n x=i*j\r\n if x//N==0:\r\n k=str(x%N)\r\n else:\r\n k=str(x//N)+str(x%N)\r\n ANS.append(k)\r\n\r\n print(*ANS)\r\n\r\n", "def convert_base(number, base):\r\n if base < 2:\r\n return False\r\n remainders = []\r\n while number > 0:\r\n remainders.append(str(number % base))\r\n number //= base\r\n remainders.reverse()\r\n return ''.join(remainders)\r\nn = int(input())\r\nfor i in range(1,n):\r\n s = ''\r\n for j in range(1,n):\r\n s += str(convert_base(i * j, n)) + ' '\r\n s = s[:-1]\r\n print(s)\r\n", "\r\ndef convert(num, base):\r\n digits = \"0123456789ABCDEF\"\r\n if num < base:\r\n return digits[num]\r\n else:\r\n return convert(num // base, base) + digits[num % base]\r\n\r\n\r\ndef gen_table():\r\n k = int(input())\r\n\r\n inside = ''\r\n\r\n for i in range(1, k):\r\n for j in range(1, k):\r\n num1 = int(convert(i, k))\r\n num2 = int(convert(j, k))\r\n inside += (convert(num1 * num2, k)) + \" \"\r\n inside += '\\n'\r\n\r\n print(inside)\r\n\r\n\r\ngen_table()\r\n", "def multiplication_table(k):\r\n for i in range(1, k):\r\n row = []\r\n for j in range(1, k):\r\n product = i * j\r\n # Преобразование в k-ичную систему счисления\r\n product_str = convert_to_base(product, k)\r\n row.append(product_str)\r\n print(' '.join(row))\r\n\r\ndef convert_to_base(num, base):\r\n if num == 0:\r\n return '0'\r\n digits = []\r\n while num > 0:\r\n remainder = num % base\r\n digits.append(str(remainder))\r\n num //= base\r\n digits.reverse()\r\n return ''.join(digits)\r\n\r\n# Чтение входных данных\r\nk = int(input())\r\n\r\n# Вызов функции для генерации таблицы умножения\r\nmultiplication_table(k)\r\n", "def b(n, k):\r\n v = ''\r\n while n:\r\n n, v = n // k, str(n % k) + v\r\n return v\r\nk = int(input())\r\nfor i in range(1, k):\r\n print(' '.join(b(i * j, k) for j in range(1, k)))", "def turn(i, j, k):\r\n p = i * j\r\n ans = \"\"\r\n while p > 0:\r\n t = p % k\r\n ans += str(t)\r\n p //= k\r\n return ans[::-1]\r\n\r\n\r\nk = int(input())\r\nfor i in range(1, k):\r\n t = []\r\n for j in range(1, k):\r\n t.append(turn(i, j, k))\r\n print(*t, sep=\" \")", "from math import log, ceil\ndef to_base(n, b):\n p = ceil(log(n, b)); o = ''\n while p > -1: x=n//(b**p); n-=(b**p)*x; o+=str(x); p-=1\n return o if o[0] != '0' else o[1:]\nn = int(input())\nb = [[to_base(j*i, n) for j in range(1, n)] for i in range(1, n)]\nfor line in b: print(*line)\n", "def radix(x):\r\n k=[]\r\n while x:\r\n k.append(x%a)\r\n x//=a\r\n return ''.join(map(str,k))[::-1]\r\n \r\na=int(input())\r\nfor i in range(1,a):\r\n for j in range(1,a):\r\n print(radix(i*j),end=' ')\r\n print()", "k = int(input())\r\nbase = list(range(1, k))\r\nresult = [[i * x for x in base] for i in range(1, k)]\r\nfor i in range(k - 1):\r\n row = []\r\n for j in range(k - 1):\r\n product = []\r\n while result[i][j]:\r\n product.append(str(result[i][j] % k))\r\n result[i][j] //= k\r\n row.append(\"\".join(product[::-1]))\r\n print(\" \".join(row))\r\n", "k=int(input())\r\nfor i in range(1,k):\r\n z,a=i,[]\r\n for j in range(k-1):\r\n p,s=z,\"\"\r\n while p:\r\n s=str(p%k)+s\r\n p//=k\r\n z+=i\r\n a.append(s)\r\n print(*a)\r\n\r\n \r\n", "# Read the radix input\r\nk = int(input())\r\n\r\n# Generate the multiplication table for the given radix\r\nfor i in range(1, k):\r\n row = []\r\n for j in range(1, k):\r\n # Perform multiplication and convert the result to base k\r\n product = i * j\r\n product_in_base_k = ''\r\n while product > 0:\r\n digit = product % k\r\n product_in_base_k = str(digit) + product_in_base_k\r\n product //= k\r\n row.append(product_in_base_k)\r\n # Print the row with space-separated elements\r\n print(' '.join(row))", "def baseN(num,b,numerals=\"0123456789abcdefghijklmnopqrstuvwxyz\"):\r\n return ((num == 0) and numerals[0]) or (baseN(num // b, b, numerals).lstrip(numerals[0]) + numerals[num % b])\r\nn=int(input())\r\nfor i in range(1,n):\r\n\tfor j in range(1,n):\r\n\t\tprint(baseN(i*j,n),end=\" \")\r\n\tprint()\r\n", "n = int(input())\nfor i in range(1, n):\n\tfor j in range(1, n):\n\t\tnum = i * j\n\t\tif(num >= n):\n\t\t\tprint(\"%d%d \"%(num // n, num % n), end=\"\")\n\t\telse:\n\t\t\tprint(\"%d \"%(num), end=\"\")\n\tprint(\"\")", "k=int(input())\r\ndef basek(n,k):\r\n if n==0:\r\n return '0'\r\n if n<0:\r\n return '-' + basek(-n,k)\r\n s = ''\r\n while n:\r\n s = str(n%k) + s\r\n n //= k\r\n return s\r\na=[i+1 for i in range(k-1)]\r\nfor i in range(1,k):\r\n f=[]\r\n for j in range(k-1):\r\n f.append(basek(a[j]*i,k))\r\n print(*f)", "import sys\r\ninput = sys.stdin.readline\r\n\r\ndef f(s, n):\r\n a = s//n\r\n b = s%n\r\n x = str(a) + str(b)\r\n return x\r\n\r\n\r\n\r\nn = int(input())\r\nfor i in range(1, n):\r\n for j in range(1, n):\r\n print(int(f(i*j, n)), end=' ')\r\n print()", "n = int(input())\r\n\r\nz = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']\r\n\r\nfor i in range(1, n):\r\n for j in range(1, n):\r\n x = i * j\r\n a = \"\"\r\n while x:\r\n a = z[x % n] + a\r\n x //= n\r\n print(a, end=' ')\r\n print()", "number = int(input())\r\n\r\n\r\ndef table(number):\r\n for i in range(1, number):\r\n string = []\r\n for j in range(1, number):\r\n result = i * j\r\n result_str = convert(result, number)\r\n string.append(result_str)\r\n print(' '.join(string))\r\n\r\n\r\ndef convert(num, base):\r\n if num == 0:\r\n return '0'\r\n digits = []\r\n while num > 0:\r\n remainder = num % base\r\n digits.append(str(remainder))\r\n num //= base\r\n digits.reverse()\r\n return ''.join(digits)\r\n\r\n\r\n\r\ntable(number)# 1689501910.713039", "R = int(input())\r\nfor row in range(1, R):\r\n for col in range(1, R):\r\n prod = row * col\r\n if prod >= R:\r\n prod = 10 * (prod // R) + (prod % R)\r\n print(prod, end=' ')\r\n print()", "# Implementing the above algorithm as code\r\n\r\n# Reading the value of k\r\nk = int(input())\r\n\r\n# Loop for each row\r\nfor i in range(1, k):\r\n # Loop for each column\r\n for j in range(1, k):\r\n # Convert the product of i and j to k-notation and print with spaces\r\n product = i*j\r\n k_product = \"\"\r\n while product > 0:\r\n k_product = str(product % k) + k_product\r\n product //= k\r\n if k_product == \"\":\r\n k_product = \"0\"\r\n print(k_product, end=\" \")\r\n # Print a new line after each row\r\n print()\r\n", "k=int(input())\r\na=[[1]+[' '*(len(str(k**2))-1-len(str(i)))+str(i) for i in range(2,k)]]+[[i+1]+[0 for j in range(k-2)] for i in range(1,k-1)]\r\nfor i in range(2,k):\r\n for j in range(2,k):\r\n b=i*j\r\n c=''\r\n while b>0:\r\n c+=str(b%k)\r\n b//=k\r\n c=' '*(len(str(k**2))-1-len(c))+c[::-1]\r\n a[i-1][j-1]=c\r\nfor i in range(k-1):\r\n print(*a[i])", "def convert(n,base):\r\n x=\"\"\r\n while n>0:\r\n x+=str(n%base)\r\n n//=base\r\n return x[::-1]\r\ndef func(x,n):\r\n ans=[]\r\n ans.append(x)\r\n for i in range(2,n):\r\n ans.append(int(convert(x*i,n)))\r\n return ans\r\nn=int(input())\r\nans=[]\r\nfor i in range(1,n):\r\n if i==1:\r\n x=[j for j in range(1,n)]\r\n ans.append(x)\r\n else:\r\n x=func(i,n)\r\n ans.append(x)\r\nfor s in ans:\r\n print(*s)", "def convert10tob( N, b):\r\n s=\"\"\r\n while(N!=0):\r\n s+=str(N%b)\r\n N//=b\r\n return s[::-1]\r\nk=int(input())\r\nfor i in range(1,k):\r\n for j in range(1,k):\r\n if(i*j<k or k==10):\r\n print(i*j,end=\" \")\r\n else:\r\n print(convert10tob(i*j,k),end=\" \")\r\n print()\r\n\r\n", "k = int(input())\r\n\r\nfor i in range(1, k):\r\n row = \"\"\r\n for j in range(1, k):\r\n num = i * j\r\n num_str = \"\"\r\n while num > 0:\r\n num_str = str(num % k) + num_str\r\n num //= k\r\n if num_str == \"\":\r\n num_str = \"0\"\r\n row += num_str + \" \"\r\n print(row.rstrip())\r\n", "n = int(input())\r\nfor i in range(1, n): print(*[(i * j // n) * 10 + (i * j % n) for j in range(1, n)])", "k = int(input())\r\nif k == 2:\r\n print('1')\r\nelif k == 3:\r\n print('1 2')\r\n print('2 11')\r\nelif k == 4:\r\n print('1 2 3')\r\n print('2 10 12')\r\n print('3 12 21')\r\nelif k == 5:\r\n print('1 2 3 4')\r\n print('2 4 11 13')\r\n print('3 11 14 22')\r\n print('4 13 22 31')\r\nelif k == 6:\r\n print('1 2 3 4 5')\r\n print('2 4 10 12 14')\r\n print('3 10 13 20 23')\r\n print('4 12 20 24 32')\r\n print('5 14 23 32 41')\r\nelif k == 7:\r\n print('1 2 3 4 5 6')\r\n print('2 4 6 11 13 15')\r\n print('3 6 12 15 21 24')\r\n print('4 11 15 22 26 33')\r\n print('5 13 21 26 34 42')\r\n print('6 15 24 33 42 51')\r\nelif k == 8:\r\n print('1 2 3 4 5 6 7')\r\n print('2 4 6 10 12 14 16')\r\n print('3 6 11 14 17 22 25')\r\n print('4 10 14 20 24 30 34')\r\n print('5 12 17 24 31 36 43')\r\n print('6 14 22 30 36 44 52')\r\n print('7 16 25 34 43 52 61')\r\nelif k == 9:\r\n print('1 2 3 4 5 6 7 8')\r\n print('2 4 6 8 11 13 15 17')\r\n print('3 6 10 13 16 20 23 26')\r\n print('4 8 13 17 22 26 31 35')\r\n print('5 11 16 22 27 33 38 44')\r\n print('6 13 20 26 33 40 46 53')\r\n print('7 15 23 31 38 46 54 62')\r\n print('8 17 26 35 44 53 62 71')\r\nelif k == 10:\r\n print('1 2 3 4 5 6 7 8 9')\r\n print('2 4 6 8 10 12 14 16 18')\r\n print('3 6 9 12 15 18 21 24 27')\r\n print('4 8 12 16 20 24 28 32 36')\r\n print('5 10 15 20 25 30 35 40 45')\r\n print('6 12 18 24 30 36 42 48 54')\r\n print('7 14 21 28 35 42 49 56 63')\r\n print('8 16 24 32 40 48 56 64 72')\r\n print('9 18 27 36 45 54 63 72 81')\r\n", "# LUOGU_RID: 111249381\n\nn = int(input()) \n\ndef find(num) : \n res = [] \n\n while num : \n tmp = num // n \n x = tmp * n \n rest = num - x \n res.append(str(rest)) \n num //= n \n\n res = res[::-1] \n return int(\"\".join(res))\n\n\nfor i in range(1, n) : \n for j in range(1, n) : \n t = i * j \n print(find(t), end = ' ') \n print() ", "radix = int(input())\nfor i in range(1, radix):\n row = []\n for j in range(1, radix):\n x = i * j\n digits = []\n while x != 0:\n digits.append(str(x % radix))\n x //= radix\n row.append(''.join(reversed(digits)))\n print(' '.join(row))\n", "k = int(input())\r\ndef convert_to_base_10(a):\r\n res = []\r\n while a:\r\n res.append(a%k)\r\n a//=k\r\n return ''.join(map(str,res[::-1]))\r\n\r\nfor i in range(1,k):\r\n output = []\r\n for j in range(1,k):\r\n output.append(convert_to_base_10((i*j)))\r\n print(*output)\r\n", "def baseNum(a,b):\r\n i = 0\r\n sumV = []\r\n while a > 0:\r\n sumV.append(str(a % b) )\r\n a = int(a/b)\r\n i += 1\r\n res = sumV[::-1]\r\n res2 = \"\".join(res)\r\n res2 = int(res2)\r\n return res2\r\nk = int(input())\r\nfor i in range(1,k):\r\n for j in range(1,k):\r\n print(baseNum(i*j,k),end=\" \" )\r\n print(end=\"\\n\")", "from collections import deque\r\n\r\n\r\ndef n_to_k(n, k):\r\n result = deque()\r\n while n > 0:\r\n result.appendleft(str(n % k))\r\n n //= k\r\n return ''.join(result)\r\n\r\n\r\ndef to_k(table, k):\r\n for i in range(k - 1):\r\n for j in range(k - 1):\r\n table[i][j] = n_to_k(table[i][j], k)\r\n\r\n\r\ndef main():\r\n k = int(input())\r\n\r\n table = list()\r\n\r\n for i in range(1, k):\r\n data = list()\r\n for j in range(1, k):\r\n data.append(i * j)\r\n table.append(data)\r\n\r\n to_k(table, k)\r\n\r\n for row in table:\r\n print(*row)\r\n\r\n\r\nmain()\r\n", "def toSys(n, k):\n res = ''\n t = k\n while (n != 0):\n res += str(n % t)\n n //= t\n t *= k \n return res[::-1]\n\n\nn = int(input())\nfor i in range(1, n):\n for j in range(1, n):\n print(toSys(i * j, n), end=\" \")\n print()", "n=int(input())\r\nfor i in range(1,n):\r\n print(*((i*j//n)*10+(i*j%n) for j in range(1,n)))\r\n", "n=int(input())\r\nfor i in range(1,n):\r\n for j in range(1,n):\r\n c=i*j\r\n d=[]\r\n while(c!=0):\r\n d.append(str(c%n))\r\n c=int(c/n)\r\n d.reverse()\r\n \r\n d=\"\".join(d)\r\n print(d,end=\" \")\r\n print()", "a=int(input())\r\ndef radix(x):\r\n k=[]\r\n while x:k.append(x%a);x=x//a\r\n return ''.join(map(str,k))[::-1]\r\nfor i in range(1,a):\r\n for j in range(1,a):print(radix(i*j),end=' ')\r\n print()", "# LUOGU_RID: 127315635\na=int(input())\r\nfor i in range(a-1):\r\n for j in range(a-1):print(str((i+1)*(j+1)//a).strip('0')+str((i+1)*(j+1)%a),end=' ')\r\n print()", "k = int(input())\r\n\r\ndef convertToBase(base, num):\r\n newNum = \"\"\r\n while num > 0:\r\n quotient = num // base\r\n remainder = num % base\r\n newNum = str(remainder) + newNum\r\n num = quotient\r\n return int(newNum)\r\n\r\nfor i in range(k-1):\r\n if i == 0:\r\n nums = list(range(1, k))\r\n nums = [str(i) for i in nums]\r\n print(\" \".join(nums))\r\n continue\r\n line = []\r\n for j in range(k-1):\r\n num = convertToBase(k, (i+1) * (j+1))\r\n line.append(str(num))\r\n\r\n print(\" \".join(line))\r\n ", "def transNum(n):\r\n s = \"\"\r\n while n != 0:\r\n s = str(n%k) + s\r\n n = n // k\r\n return s\r\n\r\nk = int(input())\r\n\r\nmatrix = [[0]*(k-1) for i in range(k-1)]\r\n\r\nfor i in range(k-1):\r\n for j in range(k-1):\r\n matrix[i][j] = transNum((i+1)*(j+1))\r\nfor i in matrix:\r\n print(\" \".join(i))" ]
{"inputs": ["10", "3", "2", "4", "5", "6", "7", "8", "9"], "outputs": ["1 2 3 4 5 6 7 8 9 \n2 4 6 8 10 12 14 16 18 \n3 6 9 12 15 18 21 24 27 \n4 8 12 16 20 24 28 32 36 \n5 10 15 20 25 30 35 40 45 \n6 12 18 24 30 36 42 48 54 \n7 14 21 28 35 42 49 56 63 \n8 16 24 32 40 48 56 64 72 \n9 18 27 36 45 54 63 72 81 ", "1 2 \n2 11 ", "1 ", "1 2 3 \n2 10 12 \n3 12 21 ", "1 2 3 4 \n2 4 11 13 \n3 11 14 22 \n4 13 22 31 ", "1 2 3 4 5 \n2 4 10 12 14 \n3 10 13 20 23 \n4 12 20 24 32 \n5 14 23 32 41 ", "1 2 3 4 5 6 \n2 4 6 11 13 15 \n3 6 12 15 21 24 \n4 11 15 22 26 33 \n5 13 21 26 34 42 \n6 15 24 33 42 51 ", "1 2 3 4 5 6 7 \n2 4 6 10 12 14 16 \n3 6 11 14 17 22 25 \n4 10 14 20 24 30 34 \n5 12 17 24 31 36 43 \n6 14 22 30 36 44 52 \n7 16 25 34 43 52 61 ", "1 2 3 4 5 6 7 8 \n2 4 6 8 11 13 15 17 \n3 6 10 13 16 20 23 26 \n4 8 13 17 22 26 31 35 \n5 11 16 22 27 33 38 44 \n6 13 20 26 33 40 46 53 \n7 15 23 31 38 46 54 62 \n8 17 26 35 44 53 62 71 "]}
UNKNOWN
PYTHON3
CODEFORCES
41
14c9740aff6f6fea9c424e0318ca8313
Restoration of string
A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elements of the set are the most frequent substrings of this string. Restore the non-empty good string with minimum length. If several such strings exist, restore lexicographically minimum string. If there are no good strings, print "NO" (without quotes). A substring of a string is a contiguous subsequence of letters in the string. For example, "ab", "c", "abc" are substrings of string "abc", while "ac" is not a substring of that string. The number of occurrences of a substring in a string is the number of starting positions in the string where the substring occurs. These occurrences could overlap. String *a* is lexicographically smaller than string *b*, if *a* is a prefix of *b*, or *a* has a smaller letter at the first position where *a* and *b* differ. The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of strings in the set. Each of the next *n* lines contains a non-empty string consisting of lowercase English letters. It is guaranteed that the strings are distinct. The total length of the strings doesn't exceed 105. Print the non-empty good string with minimum length. If several good strings exist, print lexicographically minimum among them. Print "NO" (without quotes) if there are no good strings. Sample Input 4 mail ai lru cf 3 kek preceq cheburek Sample Output cfmailru NO
[ "n = int(input())\r\nu = []\r\ns = []\r\nok = True\r\nfor i in range(n):\r\n u.append(input())\r\n s.append(set(u[i]))\r\n if len(s[i]) != len(u[i]):\r\n print('NO')\r\n ok = False\r\n break\r\nif ok:\r\n i = 0\r\n ok = False\r\n while i < len(u):\r\n j = i + 1\r\n p = False\r\n while j < len(u):\r\n z = len(s[i].intersection(s[j]))\r\n if u[i] in u[j]:\r\n u[i] = u[j]\r\n s[i] = s[j]\r\n s.pop(j)\r\n u.pop(j)\r\n p = True\r\n break\r\n elif u[j] in u[i]:\r\n s.pop(j)\r\n u.pop(j)\r\n j -= 1\r\n elif z > 0:\r\n if u[i][-z:] == u[j][:z]:\r\n u[i] += u[j][z:]\r\n elif u[j][-z:] == u[i][:z]:\r\n u[i] = u[j] + u[i][z:]\r\n else:\r\n ok = True\r\n break\r\n s[i] = set(u[i])\r\n u.pop(j)\r\n s.pop(j)\r\n j -= 1\r\n p = True\r\n j += 1\r\n if not p:\r\n i += 1\r\n if ok:\r\n print('NO')\r\n break\r\n if not ok:\r\n u.sort()\r\n print(''.join(u))\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n", "from sys import stdin\n\ndef read_input():\n return stdin.readline()\n\n\ndef invalid_string():\n print(\"NO\")\n exit()\n\n\nnext_chars = {}; prev_chars = {}; unique_chars = set()\nfor c in 'abcdefghijklmnopqrstuvwxyz':\n next_chars[c] = prev_chars[c] = ''\n\nvisited_chars = set()\nresult = []\n\nnum_strings = int(read_input())\n\nfor i in range(num_strings):\n s = read_input().rstrip()\n unique_chars.add(s)\n for j in range(1, len(s)):\n if next_chars[s[j-1]] and next_chars[s[j-1]] != s[j]:\n invalid_string()\n if prev_chars[s[j]] and prev_chars[s[j]] != s[j-1]:\n invalid_string()\n next_chars[s[j-1]] = s[j]\n prev_chars[s[j]] = s[j-1]\n\nfor c in 'abcdefghijklmnopqrstuvwxyz':\n start = c\n if not next_chars[start] and not prev_chars[start]:\n if c in unique_chars:\n result.append(c)\n continue\n if start in visited_chars:\n continue\n while prev_chars[start]:\n start = prev_chars[start]\n if start == c:\n invalid_string()\n word = start\n visited_chars.add(start)\n while next_chars[start]:\n start = next_chars[start]\n word += start\n visited_chars.add(start)\n result.append(word)\n\n\nresult.sort()\nprint(''.join(result))\n\n \t\t\t\t\t\t \t \t \t \t \t\t \t", "u, v, d = {}, {}, set()\r\nfor i in range(int(input())):\r\n t = input()\r\n if len(t) == 1: d.add(t)\r\n for a, b in zip(t, t[1:]):\r\n if u.get(a, b) != b or v.get(b, a) != a: exit(print('NO'))\r\n u[a], v[b] = b, a\r\nx, y = set(u), set(v)\r\nd = d - x - y\r\nfor q in x - y:\r\n while q[-1] in u: q += u.pop(q[-1])\r\n d.add(q)\r\nif u: exit(print('NO'))\r\nprint(''.join(sorted(d)))", "def generate_good_string(subs : list):\r\n In, Out, S = {}, {}, set()\r\n for s in subs:\r\n if len(s) == 1:\r\n S.add(s) \r\n for fr, to in zip(s, s[1:]):\r\n if fr != In.get(to, fr) or to != Out.get(fr, to):\r\n return(print('NO'))\r\n Out[fr], In[to] = to, fr\r\n Outset, Inset = set(Out), set(In)\r\n S -= (set.union(Outset, Inset))\r\n for s in Outset - Inset:\r\n while Out.get(s[-1]):\r\n s += Out.pop(s[-1])\r\n S.add(s)\r\n print('NO' if Out else ''.join(sorted(S)))\r\nsubstrings = [input() for _ in range(int(input()))]\r\ngenerate_good_string(substrings)", "import sys\n\ndef no():\n print('NO')\n sys.exit(0)\n\n\ndef align(s, t, i, j):\n if i < j:\n i, j = j, i\n s, t = t, s\n\n result = s[:i - j]\n s = s[i - j:]\n\n for k in range(max(len(s), len(t))):\n if k < len(s) and k < len(t):\n if s[k] != t[k]:\n no()\n result += s[k] if k < len(s) else t[k]\n\n return result\n\nn = int(input())\n\ns = set()\nfor i in range(n):\n cur = input()\n\n if len(set(cur)) != len(cur):\n no()\n\n any_changes = True\n while any_changes:\n any_changes = False\n # Words intersect\n for x in s:\n if set(x) & set(cur):\n any_changes = True\n min_new_string = None\n s.remove(x)\n\n for i in range(len(x)):\n for j in range(len(cur)):\n if x[i] != cur[j]:\n continue\n\n t = align(x, cur, i, j)\n if len(set(t)) == len(t) and (min_new_string \n is None or min_new_string > t):\n min_new_string = t\n\n if min_new_string is None:\n no()\n cur = min_new_string\n break\n\n s.add(cur)\n\n\nprint(''.join(sorted(s)))\n\n\n", "import sys\nn = int(input())\na=[]\nfor i in range(n):\n\ta.append([j for j in input()])\n\nb=[]\nfor i in range(n):\n\tb.append({})\n\tfor j in a[i]:\n\t\tif j in b[i]:\n\t\t\tprint('NO')\n\t\t\tsys.exit()\n\t\tb[i][j]=1\n\nc=[-1 for i in range(26)]\nd=[-1 for i in range(26)]\ne=[0 for i in range(26)]\nfor word in a:\n\tl=ord(word[0])-97\n\te[l]=1\n\tfor ch in word[1:]:\n\t\tch1 = ord(ch)-97\n\t\te[ch1]=1\n\t\tif c[l]==-1:\n\t\t\tc[l]=ch1\n\t\telif c[l]!=ch1:\n\t\t\tprint('NO')\n\t\t\tsys.exit()\n\t\tif d[ch1]==-1:\n\t\t\td[ch1]=l\n\t\telif d[ch1]!=l:\n\t\t\tprint('NO')\n\t\t\tsys.exit()\n\t\tl=ch1\n\nx=[]\ndef abc(c,d,e,i):\n\te[i]=0\n\tif c[i]==-1:\n\t\treturn\n\telse:\n\t\ti=c[i]\n\t\tx.append(chr(i+97))\n\t\tabc(c,d,e,i)\nfor i in range(26):\n\tif e[i]==1 and d[i]==-1:\n\t\tx.append(chr(i+97))\n\t\tabc(c,d,e,i)\n\nif sum(e)>0:\n\tprint('NO')\nelse:\n\tprint(''.join(x))\n\n\n\n\n\n\n\n# Made By Mostafa_Khaled", "# -*- coding: utf-8 -*-\r\n\r\nimport math\r\nimport collections\r\nimport bisect\r\nimport heapq\r\nimport time\r\nimport random\r\nimport itertools\r\nimport sys\r\n\r\n\"\"\"\r\ncreated by shhuan at 2017/11/13 00:56\r\n\r\n\"\"\"\r\n\r\nN = int(input())\r\nA = []\r\nfor i in range(N):\r\n A.append(input())\r\n\r\n\r\nWC = collections.defaultdict(int)\r\nP = collections.defaultdict(str)\r\nfor a in A:\r\n wc = collections.Counter(a)\r\n if any([v > 1 for v in wc.values()]):\r\n print('NO')\r\n exit(0)\r\n for c in a:\r\n WC[c] += 1\r\n\r\n # P[a[0]].append(a)\r\n if a[0] not in P:\r\n P[a[0]] = a\r\n else:\r\n b = P[a[0]]\r\n if len(a) < len(b):\r\n a, b = b, a\r\n if a.find(b) < 0:\r\n print('NO')\r\n exit(0)\r\n else:\r\n P[a[0]] = a\r\n\r\n\r\ndef connect(start, vals, pre):\r\n for v in vals:\r\n if set(start) & set(v):\r\n for k in range(max(0, len(start)-len(v)), len(start)):\r\n l = len(start)-k\r\n if start[k:] == v[:l]:\r\n return connect(start[:k]+v, vals-{v}, pre+v[l:])\r\n\r\n return pre\r\n\r\n\r\nps = set(P.values())\r\nvals = [connect(s, ps - {s}, s) for s in ps]\r\n\r\nvals = [v for v in vals if all([x.find(v) < 0 for x in vals if x != v])]\r\n\r\n# res = []\r\n# for a in vals:\r\n# f = True\r\n# for b in vals:\r\n# if a != b and b.find(a) >= 0:\r\n# f = False\r\n# break\r\n# if not f:\r\n# res.append(a)\r\n\r\n# print(vals)\r\n\r\nans = \"\".join(sorted(vals))\r\nwc = collections.Counter(ans)\r\nif any([v > 1 for v in wc.values()]):\r\n print(\"NO\")\r\nelse:\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", "L = {}\r\nR = {}\r\nS = set()\r\n\r\nfor _ in range(int(input())):\r\n s = input()\r\n if len(s) == 1: \r\n S.add(s)\r\n for s1, s2 in zip(s, s[1:]):\r\n if s2 != L.get(s1, s2) or s1 != R.get(s2, s1): \r\n exit(print('NO'))\r\n L[s1], R[s2] = s2, s1\r\n\r\nL1, R1 = set(L), set(R)\r\nS = S -L1 - R1\r\n\r\nfor i in L1 - R1:\r\n while i[-1] in L: \r\n i += L.pop(i[-1])\r\n S.add(i)\r\nif L: \r\n exit(print('NO'))\r\nprint(''.join(sorted(S)))" ]
{"inputs": ["4\nmail\nai\nlru\ncf", "3\nkek\npreceq\ncheburek", "1\nz", "2\nab\nba", "2\nac\nbc", "2\ncd\nce", "2\nca\ncb", "2\ndc\nec", "26\nhw\nwb\nba\nax\nxl\nle\neo\nod\ndj\njt\ntm\nmq\nqf\nfk\nkn\nny\nyz\nzr\nrg\ngv\nvc\ncs\nsi\niu\nup\nph", "25\nsw\nwt\nc\nl\nyo\nag\nz\nof\np\nmz\nnm\nui\nzs\nj\nq\nk\ngd\nb\nen\nx\ndv\nty\nh\nr\nvu", "2\naz\nzb", "26\nl\nq\nb\nk\nh\nf\nx\ny\nj\na\ni\nu\ns\nd\nc\ng\nv\nw\np\no\nm\nt\nr\nz\nn\ne", "76\namnctposz\nmnctpos\nos\nu\ne\nam\namnc\neamnctpo\nl\nx\nq\nposzq\neamnc\nctposzq\nctpos\nmnc\ntpos\namnctposzql\ntposzq\nmnctposz\nnctpos\nctposzql\namnctpos\nmnct\np\nux\nposzql\ntpo\nmnctposzql\nmnctp\neamnctpos\namnct\ntposzql\nposz\nz\nct\namnctpo\noszq\neamnct\ntposz\ns\nmn\nn\nc\noszql\npo\no\nmnctposzq\nt\namnctposzq\nnctposzql\nnct\namn\neam\nctp\nosz\npos\nmnctpo\nzq\neamnctposzql\namnctp\nszql\neamn\ntp\nzql\na\nea\nql\nsz\neamnctposz\nnctpo\nctposz\nm\nnctposz\nnctp\nnc", "75\nqsicaj\nd\nnkmd\ndb\ntqsicaj\nm\naje\nftqsicaj\ncaj\nftqsic\ntqsicajeh\nic\npv\ny\nho\nicajeho\nc\ns\nb\nftqsi\nmdb\ntqsic\ntqs\nsi\nnkmdb\njeh\najeho\nqs\ntqsicajeho\nje\nwp\njeho\neh\nwpv\nh\no\nyw\nj\nv\ntqsicaje\nftqsicajeho\nsica\ncajeho\nqsic\nqsica\na\nftqsicajeh\nn\ntqsi\nicajeh\nsic\ne\nqsicaje\ncajeh\nca\nft\nsicajeho\najeh\ncaje\nqsicajeho\nsicaje\nftqsicaje\nsicajeh\nftqsica\nica\nkm\nqsicajeh\naj\ni\ntq\nmd\nkmdb\nkmd\ntqsica\nnk", "16\nngv\nng\njngvu\ng\ngv\nvu\ni\nn\njngv\nu\nngvu\njng\njn\nl\nj\ngvu", "33\naqzwlyfjcuktsr\ngidpnvaqzwlyfj\nvaqzwlyf\npnvaqzwlyfjcuktsrbx\njcuktsrbxme\nuktsrb\nhgidpnvaqzw\nvaqzwlyfjcu\nhgid\nvaqzwlyfjcukts\npnvaqzwl\npnvaqzwlyfj\ngidpnvaqzwlyfjcukt\naqzwlyfjcuktsrbxme\ngidpnvaqzwlyfjcuktsrb\naqzw\nlyfjcuktsrbxme\nrbxm\nwlyfjcukt\npnvaqzwlyfjcuktsr\nnvaqzwly\nd\nzwlyf\nhgidpnva\ngidpnvaqzwlyfjcuktsrbxm\ngidpn\nfjcuktsrbxmeo\nfjcuktsrbx\ngidpnva\nzwlyfjc\nrb\ntsrbxm\ndpnvaqzwlyfjcuktsrbxm", "15\nipxh\nipx\nr\nxh\ncjr\njr\np\nip\ncj\ni\nx\nhi\nc\nh\npx", "51\np\nsu\nbpxh\nx\nxhvacdy\nqosuf\ncdy\nbpxhvacd\nxh\nbpxhv\nf\npxh\nhva\nhvac\nxhva\nos\ns\ndy\nqo\nv\nq\na\nbpxhvacdy\nxhv\nqosu\nyb\nacdy\nu\npxhvacd\nc\nvacdy\no\nuf\nxhvacd\nvac\nbpx\nacd\nbp\nhvacdy\nsuf\nbpxhvac\ncd\nh\npxhva\nhv\npxhv\nosu\nd\ny\nxhvac\npxhvacdy", "20\nckdza\nw\ntvylck\nbqtv\ntvylckd\nos\nbqtvy\nrpx\nzaj\nrpxebqtvylckdzajfmi\nbqtvylckdzajf\nvylc\ntvyl\npxebq\nf\npxebqtv\nlckdza\nwnh\ns\npxe", "25\nza\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nr\ns\nt\nu\nv\nw\nx\ny\nz", "25\nzdcba\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nr\ns\nt\nu\nv\nw\nx\ny\nz", "13\nza\nyb\nxc\nwd\nve\nuf\ntg\nsh\nri\nqj\npk\nol\nnm", "13\naz\nby\ncx\ndw\nev\nfu\ngt\nhs\nir\njq\nkp\nlo\nmn", "4\nab\nbc\nca\nd", "3\nb\nd\nc", "3\nab\nba\nc", "2\nba\nca", "4\naz\nzy\ncx\nxd", "2\nab\nbb", "2\nab\nac", "3\nab\nba\ncd", "2\nabc\ncb", "1\nlol", "2\naa\nb", "6\na\nb\nc\nde\nef\nfd", "3\nabc\ncb\ndd", "3\nabcd\nefg\ncdefg"], "outputs": ["cfmailru", "NO", "z", "NO", "NO", "NO", "NO", "NO", "NO", "agdvuibcenmzswtyofhjklpqrx", "azb", "abcdefghijklmnopqrstuvwxyz", "eamnctposzqlux", "ftqsicajehonkmdbywpv", "ijngvul", "hgidpnvaqzwlyfjcuktsrbxmeo", "NO", "NO", "osrpxebqtvylckdzajfmiwnh", "bcdefghijklmnoprstuvwxyza", "efghijklmnoprstuvwxyzdcba", "nmolpkqjrishtgufvewdxcybza", "azbycxdwevfugthsirjqkplomn", "NO", "bcd", "NO", "NO", "azycxd", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "abcdefg"]}
UNKNOWN
PYTHON3
CODEFORCES
8
14cb93780999f0be5745dc2133c5dcc5
Ability To Convert
Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter *A* he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he gets 11311 (475<==<=1·162<=+<=13·161<=+<=11·160). Alexander lived calmly until he tried to convert the number back to the decimal number system. Alexander remembers that he worked with little numbers so he asks to find the minimum decimal number so that by converting it to the system with the base *n* he will get the number *k*. The first line contains the integer *n* (2<=≤<=*n*<=≤<=109). The second line contains the integer *k* (0<=≤<=*k*<=&lt;<=1060), it is guaranteed that the number *k* contains no more than 60 symbols. All digits in the second line are strictly less than *n*. Alexander guarantees that the answer exists and does not exceed 1018. The number *k* doesn't contain leading zeros. Print the number *x* (0<=≤<=*x*<=≤<=1018) — the answer to the problem. Sample Input 13 12 16 11311 20 999 17 2016 Sample Output 124753789594
[ "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nk = [0] + list(input().rstrip())\r\nl = len(k) - 1\r\nfor i in range(1, l + 1):\r\n k[i] -= 48\r\ninf = pow(10, 18) + 1\r\ndp = [inf] * (l + 1)\r\ndp[l] = 0\r\nb = 1\r\nfor _ in range(l + 5):\r\n dp0 = [inf] * (l + 1)\r\n for i in range(l, -1, -1):\r\n if dp[i] == inf:\r\n continue\r\n dpi = dp[i]\r\n c, p = 0, 1\r\n for j in range(i - 1, -1, -1):\r\n c += p * k[j + 1]\r\n if c >= n:\r\n break\r\n if k[j + 1] or p == 1:\r\n dp0[j] = min(dp0[j], dpi + c * b)\r\n p *= 10\r\n dp = dp0\r\n if dp[0] < inf:\r\n ans = dp[0]\r\n break\r\n b *= n\r\nprint(ans)", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\na = [ord(x) - ord('0') for x in input()[:-1]][::-1]\r\nm = len(a)\r\npws = [n**i for i in range(61)]\r\n\r\nif n <= 10:\r\n ans = 0\r\n for i in range(m):\r\n ans += pws[i] * a[i]\r\n print(ans)\r\n sys.exit(0)\r\n\r\ndp = [[18, 10**18] for _ in range(m + 1)]\r\ndp[0] = [0, 0]\r\n\r\nfor i in range(1, m + 1):\r\n x = 0\r\n\r\n if(a[i - 1] == 0):\r\n dp[i] = [dp[i - 1][0] + 1, dp[i - 1][1]]\r\n continue\r\n\r\n for j in range(i - 1, -1, -1):\r\n x = x * 10 + a[j]\r\n if x >= n: break\r\n dp[i] = min(dp[i], [dp[j][0] + 1, x * pws[dp[j][0]] + dp[j][1]])\r\n\r\nprint(dp[m][1])", "n, k = int(input()), input()\r\n\r\nres = 0\r\ndef dp(s, cnt):\r\n\r\n if len(s) == 0:\r\n return 0\r\n\r\n for i in range(len(s)):\r\n x = s[i:]\r\n if x[0] != '0' and int(x) < n:\r\n return dp(s[:i], cnt + 1) + int(x) * (n ** cnt)\r\n \r\n return dp(s[:-1], cnt + 1) + int(s[-1]) * (n ** cnt)\r\n\r\nprint(dp(k, 0))\r\n", "t, m = input(), input()\r\nn, d = int(t), len(t)\r\nj, s, p = len(m), 0, 1\r\nwhile j:\r\n i = max(0, j - d)\r\n if int(m[i:j]) >= n: i += 1\r\n k = int(m[i:j])\r\n j -= len(str(k))\r\n s += k * p\r\n p *= n\r\nprint(s)", "n=int(input())\r\ns=input()\r\ns=s[::-1]\r\npow=[1]\r\nfor _ in range(len(s)):\r\n pow.append(pow[-1]*n)\r\n\r\nd=[[0,0],[int(s[0]),1]]\r\nfor i in range(1,len(s)):\r\n temp=float(\"inf\")\r\n temp=min(temp,int(s[i])*pow[d[-1][1]]+d[-1][0])\r\n dig=d[-1][1]+1\r\n p=0\r\n j=i\r\n while j>=0 and s[i]!=\"0\":\r\n p=p*10+int(s[j])\r\n \r\n if p<=n-1:\r\n q=p*pow[d[j][1]]+d[j][0]\r\n if temp>=q:\r\n temp=min(temp,q)\r\n dig=d[j][1]+1\r\n j-=1\r\n else :\r\n break\r\n \r\n \r\n d.append([temp,dig])\r\nprint(d[-1][0])\r\n \r\n", "base = int(input())\r\nk = input()\r\n\r\narr = []\r\nwhile True:\r\n postfixIdx = len(k)-1\r\n\r\n while True:\r\n step = 1\r\n while postfixIdx-step > 0 and int(k[postfixIdx-step]) == 0:\r\n step += 1\r\n\r\n if int(k[postfixIdx-step:]) >= base or postfixIdx == 0:\r\n break\r\n else:\r\n postfixIdx -= step\r\n\r\n arr.append(int(k[postfixIdx:]))\r\n if postfixIdx <= 0:\r\n break\r\n\r\n k = k[:postfixIdx]\r\n\r\nans = 0\r\nfor i in range(len(arr)):\r\n ans += arr[i] * pow(base, i)\r\n\r\nprint(ans)" ]
{"inputs": ["13\n12", "16\n11311", "20\n999", "17\n2016", "1000\n1001", "1000\n1000", "2\n110111100000101101101011001110100111011001000000000000000000", "500\n29460456244280453288", "1000000000\n17289468142098080", "123\n7719", "25\n2172214240", "2\n1110110101111000010001011110101001011001110000000010111010", "3\n1210020121011022121222022012121212020", "4\n32323300000100133222012211322", "5\n4230423222300004320404110", "6\n20201051430024130310350", "7\n325503632564034033331", "8\n17073735641412635372", "9\n1733607167155630041", "10\n996517375802030516", "11\n1107835458761401923", "20\n905191218118181710131111", "50\n303521849112318129", "100\n7226127039816418", "1000\n839105509657869885", "7501\n2542549323761022905", "10981\n5149151039259677113", "123358\n458270676485260235", "2567853\n5247911636981396703", "56132425\n3102369282985322", "378135456\n42831383491941211", "3\n110021012201002100122001102110010002", "23\n12007622911918220", "456\n82103391245145170", "7897\n14412516641926184", "23156\n27612518525717145", "467879\n333380108424158040", "7982154\n129530518193255487", "21354646\n47160699363858581", "315464878\n113635473256292967", "1000000000\n17289468142098026", "4\n200002312103012003212121020", "46\n342836241940392925", "145\n357987665524124", "1344\n2498394521019605", "57974\n3619236326439503", "215467\n2082791630100848", "7956123\n6718643712272358", "13568864\n2513398972677784", "789765212\n1039927282755769", "1000000000\n7289468142097485", "5\n22011100004310232330", "98\n11291073236468", "364\n284155255182196", "8742\n111445644633405", "11346\n573275516211238", "442020\n13825031303078", "1740798\n321470190942028", "25623752\n25636131538378", "814730652\n56899767577002", "6\n5543321344052", "79\n9653454753", "158\n25832612364", "1675\n11480678916", "12650\n25380755475", "165726\n465015206", "2015054\n30501583737", "98000000\n19440834812", "157137373\n525141766938", "7\n441214552", "294\n2251151163", "2707\n11341512", "76559\n100147383", "124849\n6172319", "7014809\n73084644", "10849219\n65200749", "905835986\n371320", "1000000000\n69204007", "8\n2670", "25\n71610", "1468\n21107", "5723\n4907", "251546\n7278", "9\n78", "13\n41", "34\n13", "45\n22", "67\n29", "130\n100", "2\n1", "4\n1", "9\n3", "13\n9", "3215\n3", "1000000000\n6", "2\n0", "1000000000\n0", "378\n1378", "378\n380378377", "2\n10000000000000000000000000", "2\n10000000000000000000000000000", "2\n100000000000000000000000"], "outputs": ["12", "475", "3789", "594", "100001", "100000", "1000000000000000000", "467528530570226788", "17289468142098080", "9490", "26524975", "267367244641009850", "268193483524125978", "269019726702209402", "269845965585325530", "270672213058376250", "271498451941492378", "272324690824608506", "273150934002691930", "996517375802030516", "997343614685146644", "738505167292405431", "59962796634170079", "7226127039816418", "839105509657869885", "805176557484307547", "748054672922159638", "860152492903254335", "346042641011647808", "10027171005317597", "582652156959951259", "68193483524125904", "1781911903273803", "1621222691867186", "6062228032315859", "3433598652149101", "72980519445207316", "82535003403725833", "21776150370291089", "35848000882710261", "17289468142098026", "9019726702208584", "694167817136539", "330396354354854", "814487257688093", "7079242212325439", "966934630351661", "4255926011071634", "4621032639107192", "821298450375293", "7289468142097485", "45965585242840", "10007394522984", "4993183241788", "74498130012303", "83675287784142", "26973736400898", "99531390411376", "65689385274354", "46358126945150", "12975669536", "27953623755", "15908078858", "8852883441", "40587846725", "770641106", "6147498437", "19052834812", "82638887763", "26508694", "72564361", "3071250", "76682942", "7688108", "52188307", "70296063", "371320", "69204007", "1464", "4785", "4043", "4907", "7278", "71", "53", "13", "22", "29", "100", "1", "1", "3", "9", "3", "6", "0", "0", "4992", "65568783041", "33554432", "268435456", "8388608"]}
UNKNOWN
PYTHON3
CODEFORCES
6
1504039ac7ea1dfc39679c660b5763cb
none
You've got string *s*, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*]<==<=*s**p*1*s**p*2... *s**p**k*(1<=≤<=*p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k*<=≤<=|*s*|) a subsequence of string *s*<==<=*s*1*s*2... *s*|*s*|. String *x*<==<=*x*1*x*2... *x*|*x*| is lexicographically larger than string *y*<==<=*y*1*y*2... *y*|*y*|, if either |*x*|<=&gt;<=|*y*| and *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x*|*y*|<==<=*y*|*y*|, or exists such number *r* (*r*<=&lt;<=|*x*|,<=*r*<=&lt;<=|*y*|), that *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**r*<==<=*y**r* and *x**r*<=+<=1<=&gt;<=*y**r*<=+<=1. Characters in lines are compared like their ASCII codes. The single line contains a non-empty string *s*, consisting only of lowercase English letters. The string's length doesn't exceed 105. Print the lexicographically maximum subsequence of string *s*. Sample Input ababba abbcbccacbbcbaaba Sample Output bbba cccccbba
[ "s = input()\ns = s[::-1]\nn = len(s)\n\n\n\nmaxi = s[0]\nfor i in range(1,n):\n \n \n if s[i]>=maxi[-1]:\n\n maxi += s[i]\n\n\nprint(maxi[::-1])\n\n", "w = input()\r\nres = ''\r\nwhile len(w) > 0:\r\n c = max(c for c in w)\r\n res += c * w.count(c)\r\n wr = w[::-1] \r\n wr = wr[:wr.index(c)]\r\n w = wr[::-1] \r\nprint(res)", "from collections import defaultdict\r\n\r\ns = input()\r\n\r\nn = len(s)\r\n\r\npos = defaultdict(list)\r\n\r\nfor i in range(n):\r\n pos[s[i]].append(i)\r\n \r\nprev = -1\r\n\r\nres = []\r\n\r\nwhile True:\r\n found = False\r\n for c in range(25, -1, -1):\r\n cc = chr(ord('a') + c)\r\n beg = 0\r\n end = len(pos[cc]) - 1\r\n curr = n\r\n while beg <= end:\r\n mid = (beg + end) // 2\r\n if pos[cc][mid] > prev:\r\n curr = pos[cc][mid]\r\n end = mid - 1\r\n else:\r\n beg = mid + 1\r\n if curr < n:\r\n res.append(cc)\r\n found = True\r\n prev = curr\r\n break\r\n if not found:\r\n break\r\n \r\nprint(\"\".join(res))", "s = input()\r\n\r\nstack = []\r\nfor item in s:\r\n while(len(stack) != 0 and item > stack[-1]):\r\n stack.pop()\r\n stack.append(item)\r\n \r\nans = ''.join(stack)\r\nprint(ans)", "def solveByRec(string):\n\n n = len(string)\n if n == 0: return ''\n\n maxim = 'a'\n\n for c in string: maxim = max(maxim, c)\n\n count = 0\n\n for i in string:\n if i == maxim: count+=1\n\n \n # print(maxim)\n \n for i in range(n-1, -1, -1):\n if string[i] == maxim:\n lastAppearence = i+1\n break\n \n firstPart = maxim* count\n\n secondPart = solveByRec(string[lastAppearence:])\n\n return firstPart+ secondPart\n\n\nstring = input()\n\nprint(solveByRec(string)) ", "s = list(input())\r\nb = sorted(list(set(s)), reverse=True)\r\nk = s.index(max(s))\r\nfor i in b:\r\n j = 0\r\n for j in range(k, len(s)):\r\n if s[j] == i:\r\n print(i, end='')\r\n k = j\r\n \r\n \r\n", "import math\r\n\r\n\r\ndef main_function():\r\n hash_s = [0 for i in range(150)]\r\n s = input()\r\n l = []\r\n for i in s:\r\n hash_s[ord(i)] += 1\r\n current_index = len(hash_s) - 1\r\n for i in s:\r\n while current_index >= 0 and hash_s[current_index] == 0:\r\n current_index -= 1\r\n if ord(i) == current_index:\r\n l.append(i)\r\n hash_s[ord(i)] -= 1\r\n for i in l:\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\nmain_function()\r\n\r\n\r\n", "s = input()\nn=len(s)\nans = s[-1]\nfor i in range(n - 2, -1, -1):\n if s[i] >= ans[-1]:\n ans += s[i]\nprint(ans[::-1])", "s=input()\r\nbest=max(s,key=lambda x:ord(x))\r\nmaxs=\"\"\r\nwhile len(s)>0:\r\n best=max(s,key=lambda x:ord(x))\r\n maxs+=best*s.count(best)\r\n s=s[s.rfind(best)+1:]\r\nprint(maxs)\r\n", "si = input()\r\nans = \"\"\r\nwhile 1:\r\n co = si.count(max(si))\r\n ans = ans + max(si)*co\r\n #print(\"ans \" ,ans)\r\n new = (si[::-1].index(max(si)))\r\n #print(\"new \",new)\r\n si = si[len(si)-new:]\r\n #print(si)\r\n if len(si)==0:\r\n #print(\"lets break\")\r\n break\r\nprint(ans)\r\n", "def get_ints():\r\n return map(int, input().strip().split())\r\n\r\ndef get_list():\r\n return list(map(int, input().strip().split()))\r\n\r\ndef get_string():\r\n return input().strip()\r\n\r\ns = input().strip()\r\nn = len(s)\r\nprev = {}\r\nfor i in range(97, 123):\r\n prev[chr(i)] = 0\r\n \r\nsuffix = [{} for i in range(n)]\r\n\r\nfor i in range(n-1, -1, -1):\r\n suffix[i] = dict(prev)\r\n suffix[i][s[i]] += 1\r\n prev[s[i]] += 1\r\n \r\nans = []\r\nfor i in range(n-1):\r\n for j in range(122, 96, -1):\r\n if ord(s[i]) < j and suffix[i+1][chr(j)] > 0:\r\n # we can't include s[i]\r\n break\r\n \r\n elif ord(s[i]) < j and suffix[i+1][chr(j)] == 0:\r\n # check for smaller alphabets\r\n continue\r\n else:\r\n ans.append(s[i])\r\n break\r\n\r\nans.append(s[n-1]) \r\nprint(\"\".join(ans))\r\n \r\n \r\n \r\n# print(ans)", "from collections import Counter\ns = input()\nc = Counter(s)\ncur_char = 'z'\nfor c1 in s:\n while c[cur_char] == 0:\n cur_char = chr(ord(cur_char) - 1)\n if c1 == cur_char:\n print(cur_char, end='')\n c[c1] -= 1\n\t\t\t \t\t\t \t\t\t \t \t\t\t \t \t\t", "from collections import deque as d\r\n\r\ns = list(input())\r\nlast = \" \"\r\nans = d()\r\n\r\nfor i in reversed(s):\r\n if i >= last:\r\n ans.append(i)\r\n last = i\r\n \r\nprint(\"\".join(reversed(ans)))\r\n", "s=list(input())\r\na=sorted(set(s))[::-1]\r\nprint(a[0]*(s.count(a[0])),end='')\r\nindex=len(s)-s[::-1].index(a[0])-1\r\nfor i in range(1,len(a)):\r\n if a[i] in s[index:]:\r\n print(a[i]*(s[index:].count(a[i])),end='')\r\n index=len(s)-s[::-1].index(a[i])-1", "from sys import stdin, stdout\r\n\r\ns = stdin.readline().strip()\r\nmaximum = []\r\n\r\nmx = 'a'\r\nfor f in s[::-1]:\r\n mx = max(f, mx)\r\n maximum.append(mx)\r\n\r\nmaximum = maximum[::-1]\r\nans = ''\r\n\r\nfor i in range(len(s)):\r\n if s[i] == maximum[i]:\r\n ans += s[i]\r\n \r\nstdout.write(str(ans))", "s=input()\n\nans=\"\"\n\nL=[True]*len(s)\nmaxx=s[-1]\nfor i in range(len(s)-2,-1,-1):\n if(s[i]>=maxx):\n maxx=s[i]\n else:\n L[i]=False\nfor i in range(len(s)):\n if(L[i]):\n ans+=s[i]\nprint(ans)\n \n\n", "import sys\r\nimport math\r\n\r\nn = sys.stdin.readline()\r\n\r\nl = len(n) - 1\r\nk = [n[l - 1]]\r\nc = 0\r\n\r\nfor i in range(l - 2, -1, -1):\r\n if(n[i] >= k[c]):\r\n k.append(n[i])\r\n c += 1\r\n \r\nprint(\"\".join(k[::-1]))\r\n", "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 s=input()\r\n n=len(s)\r\n dp=['a']*n\r\n dp[-1]=s[-1]\r\n for i in range(n-2,-1,-1):\r\n dp[i]=max(dp[i+1],s[i])\r\n ans=[]\r\n for i in range(n):\r\n if s[i]==dp[i]:\r\n ans+=[s[i]]\r\n print(''.join(ans))", "stack = []\r\nfor ch in input():\r\n while stack and stack[-1] < ch:\r\n stack.pop()\r\n stack.append(ch)\r\nprint(''.join(stack))", "s=input()\r\nn=len(s)\r\nres=[]\r\nm=s[-1]\r\nfor i in range(n-1,-1,-1):\r\n if s[i]>=m:\r\n res.append(s[i])\r\n m=s[i]\r\nres.reverse()\r\nprint(''.join(res))\r\n", "from collections import defaultdict\r\n\r\ns = input()\r\nltrs = defaultdict(lambda: [])\r\nfor i in range(len(s)):\r\n ltrs[s[i]].append(i)\r\ngo_through = sorted(ltrs)[::-1]\r\norder = []\r\nfor i in go_through:\r\n order += ltrs[i]\r\ncurr = order[0]\r\nr = ''\r\nfor i in order:\r\n if i < curr:\r\n continue\r\n r += s[i]\r\n curr = i\r\nprint(r)", "string = input()\nl = len(string)\nnum = [0 for i in range(l)]\nchar = ['a' for i in range(l)]\nchar[l-1] = string[l-1:l]\nnum[l-1] = -1\nprev = l-1\nfor i in range(l-2,-1,-1):\n if(string[i:i+1]>=char[i+1]):\n char[i] = string[i:i+1]\n num[i] = prev\n prev = i\n else:\n char[i] = char[i+1]\n num[i] = num[i+1]\n \nprev = num[0]\nans = char[0]\n#print(num)\n#print(char)\nwhile(prev!=-1):\n ans=ans+char[prev]\n prev = num[prev]\nprint(ans)\n ", "def f(s,a,ans):\r\n if not a:\r\n return ans\r\n for i in range(len(s)-1,-1,-1):\r\n if s[i]==a[-1]:\r\n for j in range(i,-1,-1):\r\n if s[j]==a[-1]:\r\n ans+=s[j]\r\n return f(s[i:],a[:len(a)-1],ans)\r\n else:\r\n return f(s,a[:len(a)-1],ans)\r\n \r\ns=input()\r\na=[]\r\nfor i in s:\r\n if not i in a:\r\n a.append(i)\r\na.sort()\r\nans=''\r\nprint(f(s,a,ans))\r\n", "from collections import Counter\n\ns = input()\nc = Counter(s)\n\ncur_char = 'z'\nfor ch in s:\n while c[cur_char] == 0:\n cur_char = chr(ord(cur_char) - 1)\n if ch == cur_char:\n print(cur_char, end='')\n c[ch] -= 1\n", "k = ''\r\ns=input()\r\nwhile s != '':\r\n ans=sorted(s)[sorted(s).index(max(s)):]\r\n s=s[::-1][:s[::-1].index(max(s))]\r\n for i in ans:\r\n k = k + i\r\n s=s[::-1]\r\nprint(k)\r\n", "def bin_search(st, l):\r\n left, right = len(st), -1\r\n while left - right > 1:\r\n mid = (left + right) // 2\r\n if st[mid] < l:\r\n left = mid\r\n else:\r\n right = mid\r\n return right\r\n\r\ns = input()\r\nres = [s[0]]\r\nlpos = 0\r\nfor i in range(1, len(s)):\r\n j = bin_search(res, s[i])\r\n if j + 1 >= len(res) and lpos + 1>= len(res):\r\n res.append(s[i])\r\n lpos += 1\r\n else:\r\n if j <= lpos:\r\n res[j + 1] = s[i]\r\n lpos = j + 1\r\n else:\r\n lpos += 1\r\n res[lpos] = s[i]\r\n \r\nprint(''.join(res[:lpos + 1]))\r\n", "s = []\r\nfor ch in input():\r\n while s and s[-1] < ch:\r\n s.pop()\r\n s += ch\r\nprint(''.join(s))", "import string\ns = input().strip()\nlast = {}\nalpha = string.ascii_lowercase\nfor ch in alpha:\n\tlast[ch] = -1\nfor i, ch in enumerate(s):\n\tlast[ch] = i\nbest, current = [], 'z'\nfor i, ch in enumerate(s):\n\twhile last[current] < i:\n\t\tcurrent = alpha[alpha.index(current)-1]\n\tif ch == current:\n\t\tbest.append(ch)\nprint(''.join(best))\n", "s = input() \r\nans = [] \r\nfor i in range(len(s)): \r\n while ans and s[i] > ans[-1] : ans.pop(-1) \r\n ans += s[i] \r\nprint(''.join(ans))", "'''n = int(input())\r\na = [int(k) for k in input().split()]\r\nstep1 = min(a)\r\nstep2 = 10000\r\nfor i in range(0,n,2):\r\n if a[i] < step2:\r\n step2 = a[i]\r\nprint(max(step1, step2))'''\r\ns = input()\r\nmaxx = 'a'\r\na = ''\r\nfor i in range(len(s) - 1, -1, -1):\r\n if s[i] >= maxx:\r\n a += s[i]\r\n maxx = s[i]\r\nprint(a[::-1])\r\n\r\n", "\n\nA = input()\n\nletter_to_index = {}\n\nfor i, letter in enumerate(A):\n if letter in letter_to_index:\n letter_to_index[letter] += [i]\n else:\n letter_to_index[letter] = [i]\n\npos = 0\nletter = 'z'\n\nresult = \"\"\n\nwhile True:\n if letter in letter_to_index:\n letter_pos = letter_to_index[letter]\n for index in letter_pos:\n if index >= pos:\n result += letter\n pos = index\n\n if letter == 'a':\n break\n letter = chr(ord(letter) - 1)\n\nprint(result)\n", "string = input()\nstring_reverse = string[::-1]\n\n\n\"\"\"\nabbccdbcbbca\nmax = d\nmin = c\ndc\n\n\n\"\"\"\n\n# for each letter in the english alphabet, starting from z all the way to a, mark the first occurrence in the substring that starts with the first occurrence of the last\nalphabet = \"abcdefghijklmnopqrstuvwxyz\"[::-1]\n#print(alphabet)\nfinal_string = \"\"\nfor letter in alphabet:\n\t# find number of occurrences, first occurrence, and last occurrence in string\n\t# first_occurrence = string.find(letter)\n\tlast_occurrence = len(string) - string_reverse.find(letter) - 1\n\tcount = string.count(letter)\n\tfinal_string += letter * count\n\tif(count > 0):\n\t\tstring = string[last_occurrence+1:]\nprint(final_string)\n\n\"\"\"\nmaximum = 'a'\nminimum = 'a'\ncurrent_str = \"\"\nfor character in string:\n\tif(character > maximum):\n\t\tmaximum = character\n\t\tcurrent_str = character\n\t\tminimum = 'a'\n\telif(character <= minimum):\n\t\tcurrent_str += character\n\telif(character > minimum):\n\t\tminimum = character\n\t\tcurrent_str = current_str[0] + character\n\tprint(character, current_str, maximum, minimum)\n\n\"\"\"\n\n", "def main():\n a, res = ' ', []\n for b in reversed(input()):\n if a <= b:\n a = b\n res.append(a)\n print(''.join(reversed(res)))\n\n\nif __name__ == '__main__':\n main()\n", "s, t = '', input()\r\nfor c in 'zyxwvutsrqponmlkjihgfedcba':\r\n k = t.count(c)\r\n if k > 0:\r\n s += c * k\r\n t = t[t.rfind(c) + 1: ]\r\nprint(s)", "a=m=''\r\nfor x in input()[::-1]:\r\n if x>=m: a+=x\r\n m=max(m,x)\r\nprint(a[::-1])", "s = input()\r\nans = []\r\nlast = -1\r\nwhile last < len(s) - 1:\r\n m = max(s[last + 1:])\r\n ans.extend([m] * s[last + 1:].count(m))\r\n last = s.rfind(m)\r\n\r\nprint(''.join(ans))\r\n", "s = input()\r\ns1 = \"Я\"\r\nfor i in s:\r\n while i > s1[-1]:\r\n s1 = s1.replace(s1[-1], '')\r\n s1 += i\r\nprint(s1[1:])\r\n", "s=input()[::-1]\r\nk=s[0]\r\nsc=\"\"\r\nfor i in s:\r\n if i>=k:\r\n sc+=i\r\n k=i\r\nprint(sc[::-1])", "s = input()\r\nans = ''\r\nitem = 'z'\r\nwhile len(s) > 0:\r\n last = s.rfind(item)\r\n if last != -1:\r\n ans += item * s.count(item)\r\n s = s[last + 1:]\r\n item = chr(ord(item) - 1)\r\nprint(ans)", "#l,r = map(int, input().strip().split(' '))\r\n#lst = list(map(int, input().strip().split(' ')))\r\ns=input()\r\ns=list(s)\r\nn=len(s)\r\ni=n-1\r\np=[]\r\nm='a'\r\nwhile(i>=0):\r\n if s[i]>=m:\r\n p.append(s[i])\r\n m=s[i]\r\n \r\n i-=1\r\nj=len(p)-1\r\nwhile(j>=0):\r\n print(p[j],end=\"\")\r\n j-=1\r\n \r\n \r\n ", "s,l=input(),['']\r\nfor i in reversed(s):\r\n if l[-1]<=i: l.append(i)\r\nprint(*reversed(l),sep='')", "s = input()[::-1]\r\n\r\nnew = ''\r\nmx = 'a'\r\nfor i in range(len(s)):\r\n if s[i] == mx:\r\n new += s[i]\r\n elif s[i] > mx:\r\n new += s[i]\r\n mx = s[i]\r\n\r\nprint(new[::-1])\r\n", "s=list(input())\r\na=list(set(s))\r\na.sort(reverse=True)\r\nl=[]\r\nk=0\r\nfor j in range(len(a)):\r\n\tfor i in range(k,len(s)):\r\n\t\tif(a[j]==s[i]):\r\n\t\t\tl.append(s[i])\r\n\t\t\tk=i\r\nprint(\"\".join(l))", "s = input()\r\nbigger = 'a'\r\nres = ''\r\nfor i in range(len(s)-1,-1,-1):\r\n if s[i] >= bigger:\r\n res = s[i] + res\r\n bigger = s[i]\r\nprint(res)", "import sys\r\ninput = sys.stdin.readline\r\n\r\ns = input()[:-1][::-1]\r\nd = ''\r\nx = 'a'\r\nfor i in s:\r\n if i == x:\r\n d += i\r\n elif i > x:\r\n x = i\r\n d += i\r\nprint(d[::-1])", "line = input()\r\n\r\nstack = []\r\n\r\nfor i in line:\r\n while stack and stack[-1] < i:\r\n stack.pop()\r\n stack.append(i)\r\n \r\nprint(\"\".join(stack))", "s = input()\r\nl = len(s)\r\nm = 'a'\r\nans = \"\"\r\nfor i in range(l):\r\n\tif s[l-i-1] >= m:\r\n\t\tans = s[l-i-1] + ans\r\n\t\tm = s[l-i-1]\r\nprint(ans)", "s = list(input())\r\nanswer = []\r\ni = len(s)-1\r\nlast = s[-1]\r\n\r\nwhile i >= 0:\r\n if s[i] >= last:\r\n answer.append(s[i])\r\n last = s[i]\r\n i -= 1\r\n\r\nprint(\"\".join(answer[::-1]))", "a = input()\r\n\r\ndef get_ord(x):\r\n return ord(x)-ord('a')+1\r\n\r\nc = [0] * len(a)\r\ncur_max = get_ord(a[-1])\r\ncur_idx = len(a) - 1\r\nfor i in range(len(a)-1, -1, -1):\r\n \r\n if get_ord(a[i]) >= cur_max:\r\n cur_idx = i\r\n cur_max = max(get_ord(a[i]), cur_max)\r\n c[i] = cur_idx\r\n \r\nc = sorted(list(set(c)))\r\nsubs = [a[i] for i in c]\r\nsubs = ''.join(subs)\r\nprint(subs)", "s = input()\r\nx = max(s)\r\nans = x * s.count(x)\r\nwhile s.rindex(x) < len(s) - 1:\r\n x1 = x\r\n x = max(s[s.rindex(x) + 1:])\r\n ans += x * s.count(x, s.rindex(x1))\r\nprint(ans)", "S, s = [], input()\r\nfor i in s:\r\n while len(S) and S[-1] < i:\r\n S.pop()\r\n S.append(i)\r\nprint(''.join(S))" ]
{"inputs": ["ababba", "abbcbccacbbcbaaba", "thankstosamarasauteddybearsforthiscontest", "cantouristsolveitlessthaninoneminute", "arepretestsstrongforthisproblem", "whyareyoulookingfortestsdoyouhavewa", "aa", "zz", "a", "z", "b", "y", "zaz", "aza", "dcbaedcba", "abcdeabcd", "abcdedcba", "zyxzxzwyxywxxwabcdabdacdbcacdbcacabaaba", "zzyzyy", "aababb"], "outputs": ["bbba", "cccccbba", "yttt", "vute", "ttttsrom", "yyywa", "aa", "zz", "a", "z", "b", "y", "zz", "za", "edcba", "ed", "edcba", "zzzyyxxwddddccbba", "zzzyy", "bbb"]}
UNKNOWN
PYTHON3
CODEFORCES
51
1505530295dbd2d4bc8823b29ba39a2d
Little Elephant and Function
The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows: - If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order. A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Sample Input 1 2 Sample Output 1 2 1
[ "# Bismillahir Rahmanir Rahim\r\n# Abu Hurayra - Handle: HurayraIIT\r\nimport sys\r\nimport math\r\ndef mp(): return map(int, sys.stdin.readline().split())\r\ndef rs(): return sys.stdin.readline().rstrip()\r\ndef ri(): return int(sys.stdin.readline())\r\ndef ria(): return list(map(int, sys.stdin.readline().split()))\r\ndef ws(s): sys.stdout.write(s + '\\n')\r\ndef wi(n): sys.stdout.write(str(n) + '\\n')\r\ndef wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\\n')\r\n#a = list(map(int, input().split()))\r\n\r\n\r\ndef main():\r\n n = ri()\r\n if n==1:\r\n print(\"1\")\r\n return\r\n elif n==2:\r\n print(\"2 1\")\r\n return\r\n \r\n print(n, end=\" \")\r\n for i in range(1,n):\r\n print(i, end=\" \")\r\n print()\r\n\r\n\r\n \r\n \r\nif __name__ == '__main__':\r\n t = 1\r\n for _ in range(t):\r\n main()\r\n", "from collections import Counter\nimport re\n\na = list(range(1, int(input())+1))\n\ndef elesort(x):\n if x == 0:\n return\n a[x], a[x-1] = a[x-1], a[x]\n elesort(x-1)\n\nelesort(len(a)-1)\nprint(*a)\n", "# https://codeforces.com/problemset/problem/221/A\n\n\n# f(x):\n# if 1 exit\n# else:\n# f(x-1)\n# swap(x, x-1)\n\n# 1, 2, 3, 4, 5, 6, 7\n# 2, 3, 4, 5, 6, 7, 1\n\nn = int(input())\nprint(n, end=' ')\n\nif n>1:\n num = 1\n for _ in range(n-1):\n print(num, end=' ')\n num += 1\n\n", "n = int(input())\r\nprint(n,*range(1,n))", "a=int(input())\r\nl=[]\r\ni=1\r\nwhile i<=a: \r\n l.append(str(i))\r\n i+=1\r\ni=a-1\r\nwhile i>0: \r\n l[i],l[i-1]=l[i-1],l[i]\r\n i-=1\r\nprint(\" \".join(l))", "from collections import deque, defaultdict, Counter\r\nfrom itertools import product, groupby, permutations, combinations\r\nfrom math import gcd, floor, ceil\r\nn = int(input())\r\n\r\nans = [n] + [i for i in range(1, n)]\r\nprint(*ans)\r\n\r\n\r\n", "n = int(input())\r\nf = map(str, [n] + list(range(1, n)))\r\n\r\nprint(\" \".join(f))", "n=int(input())\r\nprint(n,end=\" \")\r\nfor x in range(1,n):\r\n print(x,end=\" \")", "\r\nn = int(input())\r\nx = []\r\nfor i in range(1, n+1):\r\n x.append(i)\r\nprint(x[-1], *x[:-1])\r\n# CodeForcesian\r\n# ♥\r\n# Memrise\r\n", "n=int(input())\r\na=[n]\r\nfor i in range(1,n):\r\n a.append(i)\r\nprint(*a)", "n=int(input())\nl=[]\nl.append(n)\nl+=[x for x in range(1,n)]\n# l[0],l[n-1]=l[n-1],l[0]\nfor i in l:\n print(i,end=\" \")", "number = int(input())\r\nanswer = ''\r\nanswer += str(number) + ' '\r\nfor i in range(1, number):\r\n answer += str(i) + ' '\r\nanswer = answer.rstrip()\r\nprint(answer)", "def mycode():\r\n n = input()\r\n \r\n if(n == '1'):\r\n print(1)\r\n return\r\n \r\n answer = n + \" \"\r\n for i in range(1, int(n)):\r\n answer += str(i)+\" \"\r\n print(answer)\r\n \r\nmycode()", "n = int(input())\r\nmass = [n] + [i for i in range(1, n)]\r\nprint(*mass)\r\n\r\n\r\n\r\n# +-------------UNIT-TESTS-------------+\r\n\r\n\r\n", "import math\r\nimport collections\r\nn=int(input())\r\narr=[]\r\nfor i in range(n-1):\r\n arr.append(i+1)\r\narr=[n]+arr\r\nfor i in arr:\r\n print(i,end=\" \")", "lst = []\r\nn = int(input())\r\nlst.append(n)\r\nfor i in range(1,n):\r\n lst.append(i)\r\nfor i in lst:\r\n print(i,end=' ')", "x = int(input())\r\nprint(x,end=\" \")\r\nfor i in range(1,x):\r\n\tprint(i,end=\" \")\r\n", "n=int(input())\r\ns=str(n)+\" \"\r\nfor i in range(n-1):\r\n s=s+str(i+1)+\" \"\r\nprint(s)", "n = int(input())\r\nif n == 1:\r\n print(1)\r\nelse:\r\n arr = [int(x) for x in range(1,n+1)]\r\n arr = [arr[n-1]]+arr[:n-1]\r\n for i in arr:\r\n print(i,end=' ')", "N=int(input())\n\nprint(N,end=\" \")\nfor i in range(1,N-1):\n print(i,end=\" \")\nif(N!=1):\n print(N-1)\n2\n\n\n", "n = int(input())\r\nb=[]\r\nfor i in range(1,n):\r\n b.append(i)\r\nb.insert(0,n)\r\nfor i in b:\r\n print(i, end=' ')", "n = int(input())\r\nres = [n] + [i+1 for i in range(n-1)]\r\nprint(\" \".join(str(x) for x in res))", "n = int(input())\r\na = [i for i in range(1,n)]\r\na.insert(0,n)\r\nprint(' '.join(map(str, a)))", "def f(m):\r\n p[m-1],p[m]=p[m],p[m-1]\r\n \r\nk=int(input())\r\np=[]\r\nfor i in range(1,k+1):\r\n p.append(str(i))\r\nfor i in range(k,-1,-1):\r\n if i==1:\r\n break\r\n else:\r\n f(i-1)\r\nprint(' '.join(p))\r\n", "n = int(input())\r\narray = []\r\nfor i in range(n-1 ,0,-1):\r\n array.append(i)\r\n# print(array)\r\n# for i in range(1,len(array)-1):\r\n# array[i],array[i+1] = array[i+1],array[i]\r\narray.sort()\r\nprint(n, end=\" \")\r\nprint(*array,sep=\" \")", "n=int(input())\r\nl=[x for x in range(1,n)]\r\nl=[n]+l\r\n\r\nprint(*l)\r\n \r\n ", "n=int(input())\np=[n]+list(range(1,n))\nfor x in p: print (x,end=\" \")", "def sort(x):\r\n print(x, end=(\" \"))\r\n \r\n for i in range(1, x):\r\n print(i, end=(\" \"))\r\n \r\n \r\nsort(int(input()))", "n=int(input())\r\na=[i for i in range(1,n+1)]\r\na.sort()\r\nprint(*([a[-1]]+a[:n-1]))\r\n", "n = int(input())\nl = [n] + [i for i in range(1,n)]\nprint(' '.join(map(str,l)))\n", "n = int(input())\nnumbers = [x for x in range(1, n + 1)]\nif n == 1:\n print(1)\nelse:\n for i in range(n - 1):\n numbers[0], numbers[i + 1] = numbers[i + 1], numbers[0]\n print(*numbers)", "n = int(input())\nprint(*([n] + [i for i in range(1, n)]))\n", "n = int(input())\r\nprint (n, ' '.join(map(str, list(range(1,n)))))", "n = int(input())\r\na = []\r\n\r\na.append(n)\r\nif(n > 1):\r\n for el in range(1 , n):\r\n a.append(el)\r\n\r\nprint(*a)", "def rec(x,n):\r\n if x==0:\r\n for i in n:\r\n print(i,end=' ')\r\n return\r\n else:\r\n n[x],n[x-1]=n[x-1],n[x]\r\n rec(x-1,n)\r\nn=int(input())\r\nlist1=[0]*(n)\r\nfor i in range(n):\r\n list1[i]=i+1\r\nrec(n-1,list1)", "n = int(input())\r\nlst = sorted([i for i in range(1,n)])\r\nprint(n,*lst)", "n=int(input())\r\nprint(n,end=\" \")\r\nprint(*list(range(1,n)))\r\n", "n = int(input())\r\nnumbers = [x for x in range(1, n)]\r\nnumbers.insert(0, n)\r\nprint(\" \".join(map(str, numbers)))", "n=int(input())\r\na=[i for i in range(1,n+1)]\r\ndef rec(n):\r\n global a\r\n if n==1:\r\n return a\r\n a[n-1],a[n-2]=a[n-2],a[n-1]\r\n return rec(n-1)\r\nfor i in rec(n):\r\n print(i,end=\" \")", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat Dec 31 15:02:53 2022\r\n\r\n@author: Lenovo\r\n\"\"\"\r\n\r\nn = int(input())\r\n\r\ns = ''\r\n\r\nfor i in range(1,n):\r\n s+=f' {i}'\r\n\r\nans = str(n)+s\r\n\r\nprint(ans)\r\n \r\n\r\n \r\n", "n=int(input())\r\nans=[str(n)]+[str(i) for i in range(1,n)]\r\nprint(\" \".join(ans))", "n=int(input())\r\nl=[n]\r\nfor i in range(1,n):\r\n l.append(i)\r\nprint(*l)", "n = int(input())\r\n\r\narr = list(range(n))\r\n\r\ndef sort(x):\r\n if x == 0:\r\n return\r\n arr[x], arr[x-1] = arr[x-1], arr[x]\r\n sort(x-1)\r\n\r\nsort(n-1)\r\nfor i in range(n):\r\n print(arr[i]+1, end=\" \")", "y = int(input())\r\n\r\nlst = list(range(1, y+1))\r\nlst.pop(y-1)\r\nlst.insert(0, y)\r\n\r\nfor elem in lst:\r\n print(elem, ' ', end = '')", "'''input\n1\n'''\n# import itertools\n\n# def fn(x, arr):\n# \tif x == n-1:\n# \t\treturn\n# \telse:\n# \t\tfn(x+1, arr)\n# \t\t# arr[x-1], arr[x] = arr[x], arr[x-1]\n# \t\tarr[x], arr[x-1] = arr[x-1], arr[x]\n\n# \t\t# print(arr)\n\nn = int(input())\n\n# variants = list(itertools.permutations([i for i in range(1, n+1)]))\n# print(variants)\n\n# for it in variants:\n# \t# print(list(it))\n# \ttemp = list(it)\n# \t# print(f'here init {temp}')\n# \tfn(n-1, temp)\n# \t# print(f'here {temp}')\n# \tif temp == [i for i in range(1, n+1)]:\n# \t\tans = it\n# \t\tbreak\n\n# temp = [i for i in range(1, n+1)]\n# fn(0, temp)\n# # print(temp)\n\n\n\nres = [i for i in range(1,n)]\nres.insert(0, n)\nfor i in res:\n\tprint(f'{i} ',end=' ')", "n = int(input())\r\narr = [n]\r\nfor i in range(1, n):\r\n arr.append(i)\r\nprint(*arr)", "n = int(input())\r\nprint(n, *range(1, n), sep=' ')\r\n", "a=int(input())\r\nprint(a,end=' ')\r\nfor j in range(1,a):\r\n\tprint(j,end=' ')", "n=int(input())\r\nx=[n]\r\nfor i in range(1,n):\r\n x.append(i)\r\nprint(*x)", "n=int(input())\r\nprint(n,end=\" \")\r\nfor x in range(1,n):print(x,end=\" \")", "n = int(input())\r\nprint(n, *[i for i in range(1, 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\nans = [i for i in range(1, n + 1)]\r\nfor i in range(n - 2, -1, -1):\r\n ans[i], ans[i + 1] = ans[i + 1], ans[i]\r\nsys.stdout.write(\" \".join(map(str, ans)))", "num = int(input())\r\n\r\nif num == 1:\r\n print(num, end=\"\")\r\nelse:\r\n print(num, end=\" \")\r\n\r\nfor i in range(1, num):\r\n if i < num-1:\r\n print(i, end=\" \")\r\n else:\r\n print(i, end=\"\")", "def main():\r\n n = int(input())\r\n data = list(range(1,n+1))\r\n data.sort()\r\n data.pop()\r\n data.insert(0,n)\r\n for j in data:\r\n print(j, end= ' ')\r\n \r\nmain()\r\n", "num = int(input())\r\nanswer = []\r\nanswer.append(str(num))\r\nfor i in range(1, num):\r\n answer.append(str(i))\r\nprint(' '.join(answer))", "n = int(input())\nprint(' '.join(map(str, ([n]+list(range(1, n))))))\n", "a = int(input())\r\nb = list(range(1,a))\r\nc =[a] + b\r\n\r\n\r\n\r\nprint(*c)\r\n", "x = int(input())\r\nprint(x,*list(range(1,x)))", "a=int(input())\r\nprint(a)\r\nfor i in range(1,a):\r\n print(i)", "l=[int(i) for i in range(1,int(input())+1)]\r\np=[l[-1]]+l[:-1]\r\nprint(*p)\r\n", "x=int(input())\r\nprint(x,end=' ')\r\nfor n in range(1,x):\r\n print(n,end=' ')", "x=int(input());print(x,*range(1,x))", "n = int(input())\narr = list(range(1, n+1))\n\nprint(*[arr[-1]]+arr[:-1])\n", "n=int(input())\r\narr=[n]+list(range(1,n))\r\nprint(*arr)\r\n", "n = int(input())\r\nprint(n, *range(1,n))", "inp = int(input())\r\nif inp!=1:\r\n print(inp,end=' ')\r\n for q in range(1,inp):\r\n print(q,end=' ')\r\nelse:\r\n print(1)", "from collections import deque\r\nimport math\r\nfrom random import randint as rand\r\nfrom functools import lru_cache\r\nimport string\r\nalph_l = string.ascii_lowercase\r\nalph_u = string.ascii_uppercase\r\n\r\n\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n ans = [n]\r\n for i in range(n-1):\r\n ans.append(i+1)\r\n print(*ans)\r\n\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n = int(input())\na = [i for i in range(1, n+1)]\nprint(a[-1], *a[:-1])", "n = int(input())\r\npermutation = [str(n)]\r\nfor i in range(1, n):\r\n permutation.append(str(i))\r\n\r\nprint(\" \".join(permutation))\r\n", "#文字列入力はするな!!\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\nfor i in range(1):\r\n n=int(input())\r\n if n==1:\r\n print(1,end=' ')\r\n continue\r\n \r\n print(n,end=' ')\r\n for i in range(1,n,1):\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#carpe diem \r\n#carpe diem", "a = int(input())\r\nif(a==1):\r\n print(1)\r\nelif(a==2):\r\n print(\"2 1\")\r\nelse:\r\n print(a,end=' ')\r\n for i in range(1,a):\r\n print(i,end=' ')\r\n", "n = int(input())\r\n\r\nsequence = [str(n)]\r\nfor i in range(1, n):\r\n\tsequence.append(str(i))\r\n\r\nsequence = ' '.join(sequence)\r\nprint(sequence)", "n=int(input())\r\nans=[i for i in range(n)]\r\nans[0]+=n\r\nprint(' '.join(map(str,ans)))", "number = int(input())\r\nans = str(number)\r\nfor i in range(1,number):\r\n ans += \" \"\r\n ans += str(i)\r\nprint(ans)", "n=int(input())\r\nnums=[int(x) for x in range(n+1)]\r\nprint(nums[n],end=\" \")\r\nfor i in range(1,n):\r\n print(nums[i],end=\" \")", "n = int(input())\r\nprint(n, end=' ')\r\ni = 1\r\nfor i in range(1,n) :\r\n print(i, end=' ')\r\n", "n = input()\nn=int(n)\nprint(n,end=\" \")\nfor i in range(1,n):\n print(i,end=\" \")\n", "n=int(input())\r\na=[i for i in range(1,n)]\r\na.insert(0,n)\r\nprint(*a)\r\n", "num=int(input())\r\nprint(num,end=\" \")\r\nfor i in range(1,num):\r\n print(i)", "n=int(input())\r\nif n>1:print(n,*[x for x in range(1,n-1)],n-1)\r\nelse:print(n)", "n = int(input())\r\n\r\nr = []\r\nr.append(n)\r\n\r\nfor i in range(1, n):\r\n r.append(i)\r\n\r\nprint(*r)\r\n", "n = int(input())\r\nx = [i for i in range(1, n)]\r\nprint(n, *x)", "n = int(input())\nprint(\"%d %s\"%(n, \"\".join([str(x)+ \" \" for x in list(range(1, n))])))", "#!/usr/bin/env python3\n\nif __name__ == \"__main__\":\n\tn = int(input())\n\tstring = str(n) + \" \" + \" \".join([str(x) for x in range(1,n)])\n\tprint(string)\n", "# LUOGU_RID: 101471714\nn = int(input())\r\nprint(*([n] + list(range(1, n))))", "n = int(input())\r\na = list(range(1,n+1))\r\ncount = 1\r\n# while count <= n:\r\n# if count == 1:\r\n# a.append(count)\r\n# count += 1\r\n# else:\r\n# a.append(count)\r\n# a[count-1],a[count-2] = a[count-2],a[count-1]\r\n# count += 1\r\n# print(\" \".join(map(str,a)))\r\nwhile count < n:\r\n a[n-count],a[n-count-1] = a[n-count-1],a[n-count]\r\n count += 1\r\nprint(\" \".join(map(str,a))) ", "n = int(input())\r\nprint(n,*[i for i in range(1,n)],sep = \" \")", "n = int(input())\r\ns = ''\r\nfor i in range(1,n):\r\n s += str(i)+' '\r\ns = str(n)+' '+s\r\nprint(s)", "n=int(input())\r\nprint(n,end=\" \")\r\nfor i in range(n-1):\r\n\tprint(i+1,end=\" \")", "n=int(input())\r\nprint(n,end=' ')\r\nfor i in range(0,n-1):\r\n print(i+1,sep=' ')\r\n \r\n\r\n", "N = int(input())\r\nprint(N, *[i for i in range(1, N)])\r\n", "def my_fun(n):\r\n a = [n]\r\n for i in range(1, n):\r\n a.append(i)\r\n return a\r\n\r\n\r\nprint(*my_fun(int(input())))\r\n", "x = int(input())\r\nperm = [str(x), *(str(i) for i in range(1, x))]\r\nprint(' '.join(perm))", "x = int(input())\r\nif x==1:\r\n print(1)\r\nelse:\r\n print(x,end=\" \")\r\n print(*[i for i in range(1,x)])", "n=int(input())\r\nans=[]\r\nans.append(n)\r\nfor i in range(1,n):\r\n ans.append(i)\r\n\r\nprint(*ans,sep=\" \")", "n = int(input())\r\nprint(str(n) + \" \" + \" \".join([str(x) for x in range(1,n)]))", "n = int(input())\r\nprint(n, ' '.join(map(str, range(1, n))))", "n=int(input())\r\nl=[]\r\nfor i in range(1,n+1):\r\n if i==1:\r\n l.append(n)\r\n else:\r\n l.append(i-1)\r\nfor j in range(len(l)):\r\n print(l[j],end=\" \")\r\n \r\n \r\n", "n=int(input())\r\nlst=[n]\r\nfor i in range(1,n):\r\n lst.append(i)\r\nprint(*lst)", "n = int(input())\r\na = []\r\nfor i in range(1,n+1):\r\n a.append(i)\r\nb = [a[-1]] + a[:-1]\r\nprint(' '.join(map(str,b)))\r\n", "a=int(input())\r\nprint(*[a]+list(range(1,a)))", "x=int(input())\r\na=[x]\r\nfor i in range(1,x):\r\n a.append(i)\r\nans=''\r\nfor i in a:\r\n ans+=str(i)+\" \"\r\nprint(ans)", "import itertools \ndef result(n,lis):\n\ta=lis[n-1]\n\tlis.pop() \n\tlis.insert(0,a)\n\ts=\"\" \n\tfor c in lis:\n\t\ts+=str(c)+\" \"\n\tprint(s)\t\n\n\n\n\n\n\nn=int(input())\nif n==1:\n\tprint(n)\nelse:\t\n\tlis=[]\n\tfor i in range(1,n+1):\n\t\tlis.append(i)\n\tresult(n,lis)\t\n", "n = int(input())\r\nprint(*([n] + [i for i in range(1,n)]))", "def solve():\n n = int(input())\n a = [n] + [x for x in range(1, n)]\n a = [str(x) for x in a]\n print(\" \".join(a))\n\n\nif __name__ == \"__main__\":\n solve()\n\n\n\n\n", "x=int(input())\r\nprint(x, end=\" \")\r\nfor i in range(x-1):\r\n print(i+1, end=\" \")", "n=int(input())\r\na=list(range(1,n+1))\r\nfor i in range(n-1):\r\n a[i],a[-1]=a[-1],a[i]\r\nprint(*a)", "from sys import stdin\r\nn = int(stdin.readline())\r\nar = [i for i in range(n, 0, -1)]\r\nprint(* (ar[:1] + sorted(ar[1:])))", "n = int(input())\r\na = [n] + list(range(1, n))\r\nprint(*a)", "a=int(input())\r\nprint(a,end=' ')\r\nif a>1:print(' '.join(map(str,range(1,a))))\r\n", "n=int(input())\r\nL = [a for a in range(1,n+1)]\r\ni = len(L)-1\r\nwhile i!=0:\r\n L[i],L[i-1]=L[i-1],L[i]\r\n i=i-1\r\ns=''\r\nfor i in L:\r\n s=s+str(i)+\" \"\r\nprint(s)\r\n", "n = int(input())\r\nif n ==1:\r\n\tprint('1')\r\nelse:\r\n\tprint(n,end=' ')\r\n\tfor i in range(1,n):\r\n\t\tprint(i,end='')\r\n\t\tif i!=n-1:\r\n\t\t\tprint(' ',end='')", "n = int(input())\r\nprint(n, *range(1, n))\r\n", "n=int(input())\r\nf=1\r\nfor i in range(n):\r\n\tif f==1:\r\n\t\tprint(n,end=\" \")\r\n\t\tf=0\r\n\telse:\r\n\t\tprint(i,end=\" \")", "# benzene_ <>\r\n\r\nn=int(input())\r\nprint(n,end=' ')\r\nfor _ in range(1,n):\r\n print(_ , end=' ')", "import sys\n#my_file = sys.stdin\n#my_file = open(\"input.txt\", \"r\")\nn = int(input())\nres = list(range(1, n))\nres.insert(0, n)\nprint(\" \".join(map(str, res)))", "def main():\n n = int(input())\n l = list(range(n))\n l[0] = n\n print(*l)\n\n\nif __name__ == '__main__':\n main()\n", "n=int(input())\r\nfor x in range(n):\r\n if x==0:\r\n print(n,end=' ')\r\n else:\r\n print(x,end=' ')\r\n", "n = int(input())\r\na = list(range(1, n))\r\nprint(n, end=\" \")\r\nprint(*a, sep=\" \")", "#!/usr/bin/python3\n\ndef readln(): return tuple(map(int, input().split()))\n\nn, = readln()\nprint(*tuple([n] + list(range(1, n))))\n", "n = int( input( ) )\r\nprint( n , \" \".join( map( str , range( 1 , n ) ) ) )", "n=int(input())\r\nans=[]\r\ndef RecrsiveFunc(n):\r\n #print(n)\r\n if n==1:\r\n ans.append(1)\r\n else:\r\n ans.append(n)\r\n ans.append(n-1)\r\n if n-2>=1:\r\n RecrsiveFunc(n-2)\r\n #print(ans)\r\n return ans\r\nRecrsiveFunc(n)\r\nfinalAns=[]\r\nfinalAns=ans[n-1:0:-1]\r\n\r\nprint(ans[0],end=\" \")\r\nfor i in finalAns:\r\n print(i,end=\" \")", "n = int(input())\r\nli = [i for i in range(n,0,-1)]\r\n\r\nif n == 1 or n == 2:\r\n for i in li:\r\n print(i, end=' ')\r\nelse:\r\n l = [li[0]] + sorted(li[1:])\r\n \r\n for i in l:\r\n print(i, end=' ')\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\n\r\n\r\nn=iinput()\r\na=[n]\r\nif(n==1):\r\n print(1)\r\nelse:\r\n for i in range(1,n):\r\n a.append(i)\r\n print(*a)\r\n\r\n", "n=int(input())\r\nprint(n,*list(range(1,n)))", "a=int(input())\r\nprint(a,end=\" \")\r\nfor i in range(1,a):\r\n print(i,end=\" \")", "d = int(input())\r\nprint(d)\r\nfor i in range(1,d):\r\n print(i)\r\n", "n=int(input())\r\na=[]\r\nfor i in range(1,n):\r\n if(n==1):\r\n print('1')\r\n else:\r\n a.append(i)\r\nprint(n,*a,sep=\" \")\r\n \r\n ", "x=int(input())\r\nif(x==1):\r\n print(x)\r\nelse:\r\n l=[]\r\n for i in range(1,x+1):\r\n l.append(str(i))\r\n l2=[]\r\n l2.append(l[-1])\r\n l.pop(len(l)-1)\r\n for i in l:\r\n l2.append(i)\r\n for j in l2:\r\n print(j,end=' ')", "n = int(input())\r\nif n == 1:\r\n print(1)\r\n exit()\r\nprint(*[n] + list(range(1, n)))", "def Little_Elephant_and_Function():\r\n totalNumbers = int(input())\r\n #Input to the recursive the function is a1 a2 a3 a4 a5 then output will be a2 a3 a4 a5 a1\r\n #Input 4 1 2 3 then output will be 1 2 3 4\r\n sorted_sequence = []\r\n for i in range(1,totalNumbers):\r\n sorted_sequence.append(i)\r\n\r\n sorted_sequence.insert(0,totalNumbers)\r\n outputStr = ''\r\n for i in sorted_sequence:\r\n outputStr = outputStr + str(i) + ' '\r\n print(outputStr)\r\n\r\nLittle_Elephant_and_Function()", "n = int(input())\nprint(\" \".join([str(c) for c in [n]+list(range(1,n))]))", "n=int(input())\r\nli=[n]+[i for i in range(1,n)]\r\nprint(*li)", "n=int(input())\r\nl=[]\r\nl.append(n)\r\nfor i in range(1,n):\r\n l.append(i)\r\nfor i in range(n):\r\n print(l[i],end=' ')", "s=int(input())\r\nprint(s,*list(range(1,s)))", "n = int(input())\r\nl = [0]*n\r\nl[0] = n\r\nfor i in range(1,n):\r\n l[i]=i\r\nprint(*l)", "n = int(input())\r\nres = [n]+[x for x in range(1,n)]\r\nprint(*res)", "\r\nfrom collections import deque\r\nn = int(input())\r\nl = deque()\r\nfor i in range(1, n):\r\n\tl.append(i)\r\n\r\nl.appendleft(n)\r\n\r\nprint(*l)", "n = int(input())\n\naux = [n]\n\nfor i in range(1, n):\n aux.append(i)\n\nprint(*aux)\n\t \t\t \t \t \t \t\t\t \t \t\t \t\t\t\t", "n=int(input())\r\nif n==1:print(1)\r\nelse:\r\n print(n,end=' ')\r\n for i in range(1,n):print(i,end=' ')\r\n", "#\n#\n# def elephent_func(n):\n# if (n == 0):\n# return None\n# else:\n# elephent_func(n - 1)\n# array[n], array[n - 1] = array[n - 1], array[n]\n\n\nn = int(input())\nprint(n,end=' ')\nfor i in range(1,n):\n print(i, end=' ')\n\n", "n= int(input())\r\nprint(*[n]+list(range(1,n)))", "n = int(input())\r\n\r\n\r\ndef func(arr, n):\r\n if n==0:\r\n return\r\n \r\n func(arr, n-1) \r\n arr[n], arr[n-1] = arr[n-1], arr[n]\r\n \r\nprint(n, *list(range(1,n)))", "n = int(input())\r\narr = [i+1 for i in range(n)]\r\n\r\ndef fun(x):\r\n if x == 0:\r\n return\r\n arr[x-1], arr[x], = arr[x], arr[x-1]\r\n fun(x-1)\r\n\r\nfun(n-1)\r\nprint(*arr, sep=' ')\r\n", "def swap(a, b):\r\n\ttemp = a\r\n\ta = b\r\n\tb = temp\r\n\treturn a, b\r\n\r\ndef main():\r\n\tn = int(input())\r\n\r\n\tif n == 1:\r\n\t\tprint(n)\r\n\telse:\r\n\t\tsequence = [str(x) for x in range(1, n+1)]\r\n\r\n\t\ti = n-1 \r\n\t\twhile i > 0:\r\n\t\t\tsequence[i], sequence[i-1] = swap(sequence[i], sequence[i-1])\r\n\t\t\ti -= 1\r\n\r\n\t\tsequence = ' '.join(sequence)\r\n\t\tprint(sequence)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tmain()", "def main():\n n = int(input())\n result = [str(n)] + [str(i) for i in range(1, n)]\n print(' '.join(result))\n\n\nif __name__ == '__main__':\n main()\n", "\r\n\r\na=int(input())\r\nb=[i for i in range(1,a+1)]\r\nc=b.pop()\r\nb=[c]+b\r\nans=\"\"\r\nfor i in b:\r\n ans=ans+str(i)+\" \"\r\nprint(ans)", "n = int(input())\r\nif n==1:\r\n print(1)\r\nif n>=2:\r\n print(str(n)+' '+ ' '.join([str(i+1) for i in range(n-1) ]))", "n=input()\r\nl=[n,]\r\nfor i in range (1,int(n)):\r\n l.append(str(i))\r\n\r\nprint(' '.join(l))\r\n \r\n \r\n", "n=int(input())\r\nl=[n]\r\nfor i in range(n-1):\r\n l.append(i+1)\r\nprint(*l)\r\n", "l=int(input())\r\nprint(l,end=' ')\r\nfor i in range(1,l):\r\n \r\n print(i,end=' ')\r\n", "def elephant(n):\r\n ans = []\r\n ans.append(n)\r\n for i in range(1, n):\r\n ans.append(i)\r\n return ans\r\n\r\nn = int(input())\r\nprint(*elephant(n))", "n = int(input())\r\n\r\nprint(n, end=' ')\r\nfor i in range(1, n):\r\n print(i, end=' ')", "n=input()\r\nprint(n, ' '.join(str(i) for i in range(1,int(n))))\r\n", "num = int(input())\r\nfinal = [num]\r\nfor i in range(1,num):\r\n #final.append(\" \")\r\n final.append(i)\r\nfor i in range(0,len(final)):\r\n final[i] = str(final[i])\r\nfstring = ' '.join(final)\r\nprint(fstring)", "n = int(input())\r\nx = [n]\r\nfor i in range(1, n):\r\n\tx.append(i)\r\nfor i in x:\r\n\tprint(i, end = \" \")\r\n", "n=int(input())\r\nprint(*[n]+[i for i in range(1,n)])", "a = [int(i)for i in range(1, int(input())+1)]\r\nprint(max(a), *a[0:len(a)-1])", "a = int(input())\r\nstring = str(a)\r\nstring += ' '\r\nfor i in range(1, a):\r\n string += str(i)\r\n string += ' '\r\nprint(string.strip())\r\n", "#m=1000\r\n\r\n#def f(i,n):\r\n# if i<n:\r\n# a[i],a[i-1]=a[i-1],a[i]\r\n\r\n# f(i+1,n)\r\nn=int(input())\r\n#f(1,n)\r\na=[i for i in range(1,n)]\r\na.insert(0,n)\r\nprint(*a[0:n])\r\n", "n=int(input())\r\n\r\ns=[i for i in range(1,n)]\r\ns.insert(0,n)\r\nprint(*s)\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nif n == 1:\r\n print(1)\r\nelse:\r\n print(n, 1, ' '.join(map(str, (list(range(2, n))))))", "n=int(input())\r\nl=[n]+[(i+1) for i in range(n-1)]\r\nprint(\" \".join(str(x) for x in l))", "n = int(input())\r\ni = 1\r\nj = 0\r\na = []\r\na.append(n)\r\nfor i in range(1,n):\r\n a.append(i)\r\nprint(*a) ", "n = int(input())\nprint(n, ' '.join(str(x + 1) for x in range(n - 1)))\n", "n = int(input())\r\n\r\nper = [1]\r\n\r\nfor i in range(2,n+1):\r\n x = per.index(i-1)\r\n per.append(per[x])\r\n per[x] = i\r\nprint(*per,sep=\" \")", "import sys\r\nimport math\r\n\r\nn = int(sys.stdin.readline())\r\n\r\na = []\r\n\r\na.append(str(n))\r\nfor i in range(1, n):\r\n a.append(str(i))\r\n \r\nprint(\" \".join(a))\r\n\r\n ", "i = int(input())\r\n\r\na = [str(x) for x in range(1, i)]\r\na.insert(0, str(i))\r\nprint(\" \".join(a))", "#\r\nif __name__ == '__main__' :\r\n n = int(input())\r\n print(n,end=\"\")\r\n for i in range(1,n) :\r\n print(f\" {i}\")", "n = int(input())\r\nperm = [i for i in range(1, n + 1)]\r\nif(n == 1):\r\n print(1)\r\nelse:\r\n ans = [perm[-1]] + perm[0: n - 1]\r\n ans = [str(i) for i in ans]\r\n print(\" \".join(ans))\r\n", "from collections import defaultdict\n\ndef solve():\n\tn = int(input())\n\tprint(n, end=' ')\n\tfor i in range(1, n):\n\t\tprint(i, end=' ')\n\tprint()\n\n# t = int(input())\n\n# while t:\n# \tt -= 1\nsolve()", "n = int(input(''))\nnew = []\nfor i in range(1,n+1):\n new.append(i)\n\nprint(new[n-1])\n\nfor i in range(n):\n reversed(new)\n if i == 0:\n continue\n else:\n print(i)\n \n\n", "#5-A. Little Elephant and Function\r\n\r\nn = int(input())\r\nprint(n, *range(1,n))\r\n\r\n", "a=int(input())\r\n\r\nl=[i+1 for i in range(a)]\r\n\r\ns=str(l[-1])\r\n\r\nfor i in range(a-1):\r\n s=s+\" \"+str(l[i])\r\n\r\nprint(s)\r\n", "n=int(input())\r\n\r\nX = [i + 1 for i in range(n)]\r\n\r\nfor i in range(n - 1, 0, -1):\r\n X[i], X[i-1] = X[i-1],X[i]\r\n \r\nfor x in X:\r\n print(x, end=' ')", "n=int(input())\r\nl=[]\r\nl.append(str(n))\r\nfor i in range(1,n):\r\n l.append(str(i))\r\nprint(\" \".join(l))\r\n", "def f(l,i):\r\n\tif i==0:return\r\n\telse:\r\n\t\tl[i],l[i-1]=l[i-1],l[i]\r\n\t\treturn f(l,i-1)\r\n\r\nn=int(input());l=list(range(1,n+1));f(l,n-1);print(*l)", "n = int(input())\r\nl_x = [n] + [(i + 1) for i in range(n - 1)]\r\n\r\nprint(\" \".join(str(x) for x in l_x))", "n=int(input())\r\narr=[]\r\narr.append(n)\r\nfor i in range(1,n):\r\n arr.append(i)\r\n\r\nprint(*arr)", "n = int(input())\r\nprint(n,*range(1,n),sep=\" \")\r\n\r\n", "n=int(input())\r\na=[]\r\na.append(n)\r\ni=1\r\nwhile i<n:\r\n a.append(i)\r\n i+=1\r\nprint(*a,sep=' ')", "n = int(input())\r\n\r\ns = [i+1 for i in range(n-1)]\r\n\r\nprint(n,end=' ')\r\nprint(*s,sep=' ')\r\n", "i = int(input())\r\nres = str(i)\r\nfor j in range(1,i):\r\n res = res + \" \" + str(j)\r\nprint(res)", "n = int(input())\r\n\r\nif n == 1:\r\n print(1)\r\nelse:\r\n r = list(range(1, n))\r\n r = [n,] + r\r\n print(' '.join(map(str, r)))", "\r\nn= int(input())\r\n\r\narr= list(range(1,n))\r\n\r\nprint(n,end=' ')\r\nfor a in arr:\r\n print(a,end=' ')", "def f(x):\r\n print(x, end=\" \")\r\n print(*[x for x in range(1, x)])\r\n\r\n\r\nf(int(input()))", "N = int(input())\r\nprint(1 if N == 1 else N, *[i for i in range(1, N)])\r\n", "# import sys\r\n# sys.stdin=open(\"input.in\",'r')\r\n# sys.stdout=open(\"out1.out\",'w')\r\nn=int(input())\r\nx=[n]\r\na=[i for i in range(1,n)]\r\nx.extend(a)\r\nprint(*x)\r\n ", "n=int(input())\r\nfor i in range(n):\r\n print(i or n)", "\r\n\r\n\r\nn=int(input())\r\nprint(n,end=' ')\r\nif(n>1):\r\n for i in range(1,n):\r\n print(i,end=' ')\r\n", "def ele(x):\r\n a[x-1],a[x]=a[x],a[x-1]\r\n\r\nn=int(input())\r\na=[]\r\nfor i in range(1,n+1):\r\n a.append(str(i))\r\nfor i in range(n,-1,-1):\r\n if i==1:\r\n break\r\n else:\r\n ele(i-1)\r\nprint(' '.join(a)) \r\n", "# CALL YOUR MODULES HERE\t-------------------->\r\n# import bisect, heapq\r\n# import fractions, math, numpy\r\nimport atexit, io, os, sys, time\r\n#\t\t<----------------------------------------\r\n\r\n# DEFINE YOUR FASTIO HERE\t-------------------->\r\n# 0 in os.read() indicated file descriptor for standard input (STDIN)\r\n# os.fstat(0).st_size will tell Python how many bytes are currently waiting in the STDIN buffer\r\n# Then os.read() will read those bytes in bulk from STDIN, producing a bytestring\r\ninputt = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n# A lambda function to get integer input and return it\r\ninput = lambda: inputt() # integers\r\n# A lambda function to get string input and return it\r\n# input = lambda: inputt().decode().strip() # strings\r\n# ss = sys.stdout\r\nss = io.BytesIO()\r\n_write = ss.write\r\nss.write = lambda s: _write(s.encode())\r\natexit.register(lambda: os.write(1, ss.getvalue()))\r\n#\t\t<----------------------------------------\r\n\r\n# DEFINE YOUR FUNCTIONS HERE\t-------------------->\r\ndef readnumbers(zero=0):\r\n _ord, nums, num, neg = lambda x: x, [], zero, False\r\n i, s = 0, io.BytesIO(os.read(0,os.fstat(0).st_size)).read()\r\n try:\r\n while True:\r\n if s[i] >= b\"0\"[0]:num = 10 * num + _ord(s[i]) - 48\r\n elif s[i] == b\"-\"[0]:neg = True\r\n elif s[i] != b\"\\r\"[0]:\r\n nums.append(-num if neg else num)\r\n num, neg = zero, False\r\n i += 1\r\n except IndexError:\r\n pass\r\n if s and s[-1] >= b\"0\"[0]: nums.append(-num if neg else num)\r\n return nums\r\ndef FastInt(zero=0):\r\n _ord, nums, num, neg = lambda x: x, [], zero, False\r\n i, s = 0, io.BytesIO(os.read(0,os.fstat(0).st_size)).read()\r\n try:\r\n while True:\r\n if s[i] >= b\"0\"[0]:num = 10 * num + _ord(s[i]) - 48\r\n elif s[i] == b\"-\"[0]:neg = True\r\n elif s[i] != b\"\\r\"[0]:\r\n nums.append(-num if neg else num)\r\n num, neg = zero, False\r\n i += 1\r\n except IndexError:\r\n pass\r\n if s and s[-1] >= b\"0\"[0]: nums.append(-num if neg else num)\r\n return nums\r\n#\t\t<----------------------------------------\r\n\r\n# ENTER YOUR CODE HERE\t-------------------->\r\nn = int(input()); print(n, *[x for x in range(1, n)])\r\n#\t\t<----------------------------------------", "n = int(input())\r\nprint(n, end = \"\")\r\nif n == 1:\r\n\tprint()\r\nelse:\r\n\tprint(end = \" \")\r\nprint(*range(1, n), sep = \" \")\r\n\r\n", "n = int(input())\r\nl = [int(i) for i in range(1,n+1)]\r\nprint(l[-1],*l[0:-1])\r\n", "t=int(input())\r\nprint(t,end=\" \")\r\nfor i in range(1,t):\r\n print(i,end= \" \")\r\n", "def fun(x):\r\n print(x,end=\" \")\r\n for i in range(1,x):\r\n print(i,end=\" \")\r\nx = int(input())\r\nif x>1:\r\n fun(x)\r\nelse:\r\n print(1)", "a=int(input())\r\nliste=[]\r\nliste.append(str(a))\r\nliste.append(\" \")\r\nfor i in range(1,a):\r\n liste.append(str(i))\r\n liste.append(\" \")\r\nprint(\"\".join(liste))", "n=int(input())\r\nfor i in range(n):\r\n if i==0:\r\n print(n,end=\" \")\r\n else:\r\n print(i,end=\" \")\r\nprint(\"\")", "t=int(input())\r\nprint(t,end=\" \")\r\nfor x in range(1,t):\r\n print(x,end=\" \")", "n = int(input())\r\nprint(' '.join(map(str, [n] + list(range(1, n)))))\r\n", "def f(l,n):\n if n == 0:\n return\n f(l,n-1)\n l[n-1],l[n] = l[n],l[n-1]\n return\nn = int(input())\nl = list(range(1,n+1))\nf(l,n-1)\ns = list(range(1,n+1))\nfor i,x in enumerate(l,1):\n s[x-1] = i\nprint(*s,end=\" \")", "n=int(input())\r\nprint(n,' '.join(list(str(i) for i in range(1,n))))", "i=int(input())\r\n\r\nprint(i,end=' ')\r\n\r\nfor x in range(1,i):\r\n print(x,end=' ')\r\n ", "n=int(input())\nprint(n,end='')\nfor i in range(1,n):\n print(\" \",i,sep='',end='')\nprint()\n\n\t \t \t \t \t\t \t\t \t \t", "# 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 = gint()\nprint(n, *range(1, n))\n", "n = int(input())\r\nprint(n, ' '.join(str(x) for x in range(1, n)))\r\n", "def main():\n #n, a, b = list(map(int, input().split(' ')))\n n = int(input())\n elems = list(range(1, n+1))\n elems.insert(0, elems.pop())\n print(' '.join(map(str, elems)))\n\n\nif __name__ == \"__main__\":\n main()\n", "n=int(input())\r\nres = [n]+[i for i in range(1,n)]\r\nprint(*res)", "n=int(input())\r\nif n>1:\r\n l=[n]+[i for i in range(1,n)]\r\n for i in range(len(l)):\r\n if i!=len(l)-1:\r\n print(l[i],end=\" \")\r\n else:\r\n print(l[i])\r\nelse:\r\n print(n)", "n = int(input())\r\na=[]\r\nfor i in range(1,n+1):\r\n a.append(i)\r\nb=[]\r\nb.append(a[n-1])\r\nfor i in range(n-1):\r\n b.append(a[i])\r\nfor i in range(n):\r\n print(b[i],end=\" \") ", "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\nn=int(input())\r\nsys.stdout.write(str(n)+\" \")\r\nfor i in range(1,n):\r\n sys.stdout.write(str(i)+\" \")\r\n", "n = int(input())\r\narr = [n] + [i for i in range(1, n)]\r\nprint(*arr)", "n = int(input())\n\nprint(' '.join(map(str, [n]+[i+1 for i in range(n-1)])))\n\n", "n=int(input())\r\nout=[]\r\nout.append(n)\r\nfor i in range(1,n):\r\n out.append(i)\r\nfor i in out:\r\n print(i,end=' ')", "n=int(input())\r\nA=[n]\r\nfor i in range(1,n):\r\n A.append(i)\r\nfor i in A:\r\n print(i,end=' ')", "\r\nn = int(input())\r\nl = [i for i in range(1, n)]\r\nl.insert(0, n)\r\n\r\nprint(*l)", "n=int(input())\r\nif(n<=2):\r\n\ta=[i for i in range(1,n+1)]\r\n\ta.sort(reverse=True)\r\n\tprint(*a)\r\nelse:\r\n\ta=[i for i in range(1,n)]\r\n\ta.insert(0,n)\r\n\tprint(*a)", "n = int(input())\r\nres = [i for i in range(1,n+1)]\r\ni = n-1\r\nwhile i != 0:\r\n res[i],res[i-1] = res[i-1],res[i]\r\n i -= 1\r\nprint(*res)\r\n\r\n", "x=int(input())\r\nprint(x , end=\" \")\r\nfor i in range (1,x):\r\n print (i,end= \" \" )\r\n", "n = int(input())\r\nprint(n, end=' ')\r\n\r\nfor i in range(n-1):\r\n print(i+1, end=' ')", "n = int(input())\r\nprint(n,*[i+1 for i in range(n-1)])\r\n#I miss you so much ::::))))", "n = int(input())\r\nres = [str(n)]\r\nres += [str(i + 1) for i in range(n - 1)]\r\nprint(\" \".join(res))", "n = int(input())\r\ns = []\r\ns.append(n)\r\nfor i in range(1, n):\r\n s.append(i)\r\nprint(*s, end = \" \")\r\n\"\"\"\r\n\r\n2 3 4 5 1\r\n\r\n3 1 2\r\n3 2 1\r\n2 3 1\r\n\r\n\r\n2 3 4 1 5\r\n- - - 5 1\r\n- - - 1 5\r\n- - 4 1 5\r\n- - 1 4 5\r\n2 3 4 5 1\r\n2 3 4 1 5\r\n2 3 1 4 5\r\n2 1 3 4 5\r\n1 2 3 4 5\r\n\"\"\"", "\"\"\"\r\n# Personal comment:\r\n# I submitted out the solution and got a runtime error on 'Test 8 for 1000'\r\n# I was unaware that python has a recursion limit to avoid stack overflow\r\n# The default limit is approximately 10^3. (However I was personally able to go till 998)\r\n# I was able to inrease this limit after reading a GeeksForGeeks article\r\n\r\n# https://www.geeksforgeeks.org/python-handling-recursion-limit/\r\n\r\n# the setrecursionlimit function is\r\n# used to modify the default recursion\r\n# limit set by python. Using this,\r\n# we can increase the recursion limit\r\n# to satisfy our needs\r\n\r\n\"\"\"\r\n\r\nimport sys\r\n \r\nsys.setrecursionlimit(10**4)\r\n\r\nn = int(input())\r\n\r\na = []\r\n# swap\r\nfor i in range(1,n+1):\r\n a.append(i)\r\n\r\ndef f(x):\r\n \r\n if x == 1:\r\n return 0\r\n elif x == 0:\r\n return 0\r\n else:\r\n f(x-1)\r\n\r\n for i in range(len(a)):\r\n if i > 0:\r\n s = a[i-1]\r\n a[i-1] = a[i]\r\n a[i] = s\r\n\r\nf(n)\r\nfor i in a:\r\n print(i, end = ' ')", "def fun(a,x):\r\n if (x==1):\r\n return a\r\n else:\r\n fun(a,x-1)\r\n a[x],a[x-1]=(a[x-1],a[x])\r\nn=int(input())\r\na=[i for i in range(0,n)]\r\na.insert(1,n)\r\nfor i in range(1,n+1):\r\n print(a[i],end=' ')\r\n\r\n \r\n", "n=int(input())\r\nif n==1:\r\n print(1)\r\nelse:\r\n s=f\"{n}\"\r\n for i in range(1,n):\r\n s+=\" \"+f\"{i}\"\r\n print(s)", "from sys import stdin;input = lambda: stdin.readline().rstrip('\\r\\n')\r\nn=int(input())\r\nprint(n,*list(range(1,n)))\r\n", "n = int(input())\r\nl=[str(n)]\r\nfor i in range(1,n):\r\n l.append(str(i))\r\ns = \" \".join(l)\r\nprint(s)\r\n", "n=int(input())\r\na=str(n)\r\nfor i in range(n-1):\r\n a+=' '+str(i+1)\r\nprint(a)\r\n", "n = int(input())\r\nif n > 1:\r\n print(n, 1, end=\" \")\r\nelse:\r\n print(1)\r\nfor i in range(2, n):\r\n print(i, end=' ')\r\n", "n = int(input())\r\narr = [i+1 for i in range(n-1)]\r\n\r\narr.insert(0,n)\r\nprint(*arr)", "n=int(input())\r\nprint(n,end=\" \")\r\nfor a in range(1,n):\r\n print(a,end=\" \")\r\n", "n=int(input())\r\n\r\nprint(n,\"\",end=\"\")\r\n\r\nfor i in range(1,n):\r\n print(i,\"\",end=\"\")\r\n\r\n", "n=int(input())\r\nprint(n,end=\" \")\r\ni=1\r\nwhile i != n :\r\n print(i,end=\" \")\r\n i+=1", "a=int(input())\r\nl= [i for i in range(1,a)]\r\nprint(a,*l)", "'''\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. Little Elephant and Function\r\n SOLUTATOIN:........\r\n \r\n ========================================================================\r\n ========================================================================\r\n '''\t\t\t\r\n\r\nm=int(input())\r\na=[m]+list(range(1,m))\r\nprint(*a)\r\n", "n = int(input())\r\n\r\nans = [n]\r\n\r\nfor i in range(1, n):\r\n ans += [i]\r\n\r\n\r\nprint(*ans)\r\n", "a=[5,1,2,3,4]\r\nx=int(input())\r\na=[x]+[y for y in range(1,x)]\r\nprint(*a)\r\n", "x= int(input())\r\nprint(x, end= \" \")\r\n\r\nfor i in range(1,x):\r\n print(i, end= \" \")", "n=int(input())\nprint(n,*(str(i) for i in range(1,n)))\n", "a=input()\r\nc=int(a)\r\nprint (a)\r\ni=1\r\nwhile i<c:\r\n print (i)\r\n i=i+1", "n = int(input())\r\nl = list(range(1,n+1))\r\n\r\ndef swap(n):\r\n global l \r\n if n == 0:\r\n return \r\n l[n] , l[n - 1] = l[n-1] , l[n]\r\n \r\n swap(n-1)\r\n\r\n\r\nswap(n-1)\r\nprint(*l)", "n=int(input())\nnums=[]\nfor i in range(1,n):\n nums.append(i)\nnums.insert(0,n)\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", "n = int(input())\n\nprint(\" \".join(str(x) for x in ([ n] + [a for a in range(1, n )])))", "n=int(input())\r\nl=list(range(1,n))\r\nprint(*([n]+l))", "from collections import deque\r\nn=int(input())\r\nif n==1:\r\n\tprint(1)\r\nelse:\r\n\tr=list(range(1,n+1))\r\n\tm=deque(r)\r\n\tm.rotate(1)\r\n\tprint(*m)\r\n\t\r\n\t\r\n", "n=int(input())\r\nprint(*([n]+list(range(1,n))))", "def calc(s):\r\n a = [*range(1, s+1)]\r\n\r\n def rec(x):\r\n if x == 0:\r\n return\r\n rec(x-1)\r\n a[x-1], a[x] = a[x], a[x-1]\r\n end = a.pop(-1)\r\n a = [end] + a\r\n return ' '.join([str(x) for x in a])\r\n\r\n# get inputs\r\n#a = list(map(int, input().split()))\r\ns = int(input())\r\nprint(calc(s))\r\n", "n=int(input())\r\nans=[n]\r\nfor v in range(1,n):\r\n ans.append(v)\r\nprint(*ans)", "\r\ndef main():\r\n n = int(input())\r\n\r\n ans = [i for i in range(1, n)]\r\n\r\n print(*([n] + ans))\r\n\r\nmain()", "N=int(input())\r\nprint(N,*range(1,N))", "a = int(input())\r\nprint(' '.join(map(str, [a] + [x for x in range(1, a)])))", "n = int(input())\r\nres = []\r\nfor i in range(1, n):\r\n res.append(i)\r\nres.insert(0, n)\r\nfor ele in res:\r\n print(ele, end =\" \")", "n = int(input())\r\nprint(n, end = \" \")\r\nfor x in range(1, n): print(x, end = \" \")", "n=int(input())\r\nfrom itertools import permutations as pem\r\nList=[str(x) for x in range(1, n)]\r\na=' '.join(List)\r\nprint(n, a)\r\n", "n=int(input())\r\nans = [str(i) for i in range(1, n)]\r\nans.insert(0, str(n))\r\nprint(\" \".join(ans))", "n= int(input())\nif n==1:\n print(\"1\")\nelse:\n array = [x for x in range(1, n)]\n array = [n] + array\n print(*array)\n", "n = int(input())\r\na = [n]\r\nfor i in range(1, n):\r\n a.append(i)\r\nprint(*a)", "n = int(input())\na = [i+1 for i in range(n)]\n\n# def f(x):\n# \tif x == 1:\n# \t\treturn\n# \telse:\n# \t\tf(x-1)\n# \t\ta[x], a[x-1] = a[x-1], a[x]\n\n# # print(f(n))\n# f(n)\n\nif n == 1:\n\tprint(1)\nelse:\n\tprint(str(n) + ' ' + ' '.join(str(x) for x in a[:-1]))", "s=int(input())\r\nprint(s,end=\" \")\r\nfor i in range(1,s):\r\n print(i,end=\" \")", "n = int(input())\nprint(n, end=\" \")\nprint(*range(1, n))\n \t \t\t \t\t \t \t\t \t\t\t \t\t\t \t\t\t", "n=int(input())\r\nprint(*[n,*range(1,n)])", "n=int(input())\r\na=[i for i in range(1,n+1)]\r\nfor i in range(n-1,0,-1):\r\n\ttemp=a[i]\r\n\ta[i]=a[i-1]\r\n\ta[i-1]=temp\r\nprint(*a)", "n=int(input());print(n,*list(range(1, n)))", "n = int(input())\nif n == 1:\n print(1)\nelse:\n print(n, end=' ')\n for i in range(1, n-1):\n print(i, end=' ')\n print(n-1)\n\n", "n = int(input())\r\nprint(n,end = ' ')\r\nfor i in range (1,n):\r\n print(i,end =' ')", "n = int(input())\r\nans = [n]+list(range(1, n))\r\nprint(*ans)\r\n", "def main_function():\r\n n = int(input())\r\n for i in range(1, n + 1):\r\n if i == 1:\r\n print(str(n), end=\"\")\r\n else:\r\n print( \" \" + str(i - 1), end=\"\")\r\n\r\n\r\n\r\n\r\n\r\n\r\nmain_function()", "n = int(input())\n\nl = []\nsr = []\n\nfor i in range(1,n+1):\n l.append(i)\n\n if i==n:\n sr = sorted(l)\n sr.insert(0, n)\n del sr[-1]\n\nprint(*sr)\n \t\t \t\t\t\t \t \t \t\t\t \t\t\t \t \t\t", "__author__ = 'Esfandiar'\nn = int(input())\nprint(n,*range(1,n))", "\"\"\"\r\nLogic:\r\n1. function keeps calling itself till 1, then swaps from 1 to n\r\n2. so max element should be 1st element, then rest should be in ascending order\r\n\"\"\"\r\n\r\n\r\nn = int(input())\r\nlst = [str(i) for i in range(1, n)]\r\nprint(str(n), \" \".join(lst))\r\n", "def LittleElephantAndFunction(n):\r\n\tresult = str(n) \r\n\ti=1\r\n\twhile i<n:\r\n\t\tresult+= \" \"\r\n\t\tresult+=str(i)\r\n\t\ti+=1\r\n\treturn result\r\n\r\nn = int(input())\r\nprint(LittleElephantAndFunction(n))\r\n", "n = int(input())\r\nprint(*([n] + [x for x in range(1, n)]))\r\n", "n = int(input())\r\nif n == 1:\r\n print(1)\r\nelse:\r\n a = [0] * n\r\n a[-1] = n\r\n temp = n - 1\r\n while temp > 0:\r\n a[temp - 1] = temp\r\n a[temp], a[temp-1] = a[temp-1], a[temp]\r\n temp -= 1\r\n print(*a)\r\n", "n=int(input())\r\nlst=[]\r\nfor i in range(1,n+1):\r\n lst.append(i)\r\nlst.reverse()\r\nprint(lst[0],end=' ')\r\nfor j in lst[1:][::-1]:\r\n print(j,end=' ')\r\n\r\n", "def main(i):\n if i == 1:\n return 1\n s = [i] + list(range(1, i))\n return ' '.join(map(str, s))\n\nprint(main(int(input())))\n", "n = int(input())\nres = [n] + list(range(1, n))\nprint(*res)\n", "n = int(input())\r\nprint(n,end=\" \")\r\nlst=[]\r\nfor i in range(1,n):\r\n lst.append(i)\r\nprint(*lst)", "n = int(input())\r\nprint(n, sep = ' ', end = ' '),\r\nfor i in range(n-1):\r\n print(i+1, sep = ' ', end = ' '),\r\n", "n=int(input())\r\ns=str(n)+\" \"\r\nfor i in range(1,n):\r\n s=s+str(i)+\" \"\r\nprint(s)", "n = int(input())\r\nl = [int(x) for x in range(1,n)]\r\n\r\nl = [n]+l\r\nprint(*l)", "#A. Little Elephant and Function\r\nn = int(input())\r\na = [n]+list(range(1,n))\r\nprint(*a)", "z=int(input());print(z,*(i for i in range(1,z)))", "n=int(input())\r\narr=[]\r\narr.append(n)\r\nfor i in range(1,n):\r\n arr.append(i)\r\nfor i in range(n):\r\n print(arr[i],end=\" \")", "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 print(n, end = \" \")\r\n for i in range(1, n):\r\n print(i, end = \" \")\r\n print()\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", "n = int(input())\r\n\r\nls = [n, *range(1,n)]\r\nprint(' '.join(map(str, ls)))", "n = int(input())\r\na = [int(a) for a in range(2, n)]\r\na = a[::-1]\r\na.append(1)\r\nif n == 1:\r\n print(1)\r\nelif n == 2:\r\n print(\"2 1\")\r\nelse:\r\n a.append(max(a) + 1)\r\n a = a[::-1]\r\n print(*a)", "# https://codeforces.com/problemset/problem/221/A\r\n\r\n\"\"\"\r\na is a permutation of integers from 1 to n\r\nf(x) sorts the first x elements\r\n\r\nif x = 1 exit\r\nelse call f(x-1) and swap a_{x-1} and a_x\r\n\r\nThis doesn't actually work, but find a permutation that does for n\r\n\"\"\"\r\n\r\nimport sys\r\n\r\nn = int(sys.stdin.readline())\r\n\r\n# Answer is just last put to the front\r\nanswer = [str((i + n - 1) % (n) + 1) for i in range(n)]\r\n\r\nsys.stdout.write(' '.join(answer))\r\n\r\n", "n = int(input())\r\nlst = [str(i) for i in range(1,n+1)]\r\nx = lst.pop() \r\nlst = [x] + lst \r\nprint(\" \".join(lst)) \r\n", "n = int(input())\r\nprint(' '.join([str(n) if x == 0 else str(x) for x in range(0, n)]))", "n=int(input())\nans=[n]+[i for i in range(1,n)]\nprint(*ans)", "n=int(input())\narr=[x for x in range(1,n)]\narr.insert(0,n)\nprint(*arr)", "from sys import stdin\nn=int(stdin.readline().rstrip(\"\\n\"))\nif n==1:\n\tprint(\"1\")\nelse:\n\tprint(n,end=\" \")\n\tfor i in range(1,n):\n\t\tprint(i,end=\" \")\n\tprint(\"\")", "n = int(input())\r\nprint(n, \" \".join(str(i) for i in range(1, n)))", "n = int(input())\r\nl = [n]\r\nfor i in range(1,n):\r\n l.append(i)\r\nprint(*l)", "def main():\r\n n = int(input())\r\n if n == 1:\r\n print(1)\r\n else:\r\n A = [n]\r\n B = [x for x in range(1, n)]\r\n C = A + B\r\n print(*C)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n=int(input())\r\nl=list(range(1,n+1))\r\nl=sorted(l)\r\nl.insert(0,l[-1])\r\nl.pop()\r\nprint(*l)", "n=int(input())\r\nans=[0]*n\r\nans[0]=n\r\n\r\nfor i in range(1,n):\r\n ans[i]=i\r\nprint(*ans) \r\n\r\n ", "\r\n\r\ndef hyundai():\r\n n = int(input())\r\n answer = \"\"\r\n for i in range(1,n):\r\n answer += str(i)+\" \"\r\n print(str(n)+\" \"+answer)\r\n\r\n\r\nhyundai()\r\n", "N = int(input())\r\nprint(N, *range(1, N))", "n = int(input())\r\nA = [i for i in range(1,n+1)]\r\nB = [0]*len(A)\r\nB[0] = A[-1]\r\nprint(B[0], end =' ')\r\nfor j in range(len(A)-1):\r\n print(A[j], end=' ')", "n = int(input())\na = [str(i) for i in range(1,n+1)]\nwhile (n!=1):\n\ttemp=a[n-1]\n\ta[n-1]=a[n-2]\n\ta[n-2]=temp\n\tn-=1\nprint(' '.join(a))\n\n\n", "\r\n\r\ndef solution():\r\n\tn=int(input())\r\n\r\n\tprint(n, end=' ')\r\n\tfor i in range(1,n):\r\n\t\tprint(i,end=' ')\r\n\r\n\r\n\treturn\r\n\r\n\r\n\r\n\r\nif __name__=='__main__':\r\n\tsolution()\r\n", "n=int(input());print(n,*range(1,n))" ]
{"inputs": ["1", "2", "3", "4", "5", "6", "7", "1000", "999", "998", "997", "900", "101", "3", "67", "779", "195", "907", "971", "683", "99", "811", "875", "291", "3", "419", "779", "195", "907", "21", "22", "23", "24", "25"], "outputs": ["1 ", "2 1 ", "3 1 2 ", "4 1 2 3 ", "5 1 2 3 4 ", "6 1 2 3 4 5 ", "7 1 2 3 4 5 6 ", "1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 15...", "999 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...", "998 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...", "997 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...", "900 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...", "101 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 ", "3 1 2 ", "67 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 ", "779 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...", "195 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...", "907 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...", "971 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...", "683 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...", "99 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 ", "811 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...", "875 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...", "291 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...", "3 1 2 ", "419 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...", "779 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...", "195 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...", "907 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...", "21 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ", "22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ", "23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ", "24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ", "25 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 "]}
UNKNOWN
PYTHON3
CODEFORCES
304
150b646344f8eb91459c57d85944dfc9
PolandBall and Game
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally? The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively. Then *n* strings follow, one per line — words familiar to PolandBall. Then *m* strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players. Each word is non-empty and consists of no more than 500 lowercase English alphabet letters. In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally. Sample Input 5 1 polandball is a cool character nope 2 2 kremowka wadowicka kremowka wiedenska 1 2 a a b Sample Output YESYESNO
[ "n, m = map(int, input().split())\n \ncounted_words = set() \nrepeated = 0\nwords1 = 0\nwords2 = 0\n \nfor _ in range(n):\n word = input().strip()\n words1 += 1\n\n counted_words.add(word)\n \nfor _ in range(m):\n word = input().strip()\n words2 += 1\n\n if word in counted_words:\n repeated += 1\n \nif repeated % 2 == 1:\n words2 -= 1\n \n \nif words1 > words2:\n print(\"YES\")\nelse:\n print(\"NO\")", "n, m = list(map(int, input().split()))\r\nPolandBall = set()\r\nEnemyBall = set()\r\nfor i in range(n):\r\n PolandBall.add(input())\r\nfor i in range(m):\r\n EnemyBall.add(input())\r\nintersectionSet = PolandBall.intersection(EnemyBall)\r\nPolandBall = PolandBall.difference(intersectionSet)\r\nEnemyBall = EnemyBall.difference(intersectionSet)\r\nif len(intersectionSet) % 2 == 0:\r\n if len(PolandBall) > len(EnemyBall):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n if len(PolandBall) >= len(EnemyBall):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "if __name__ == '__main__':\n n, m = map(int, input().split())\n s = set()\n for _ in range(n + m):\n s.add(input())\n k = n + m - len(s)\n if n > m:\n print(\"YES\")\n elif m > n:\n print(\"NO\")\n elif n + k % 2 > m:\n print(\"YES\")\n else:\n print(\"NO\")\n\n\n\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\na = {input() for _ in range(n)}\r\nb ={input() for _ in range(m)}\r\nu = len(a.intersection(b))\r\nprint(\"NO\") if m - u + u // 2 >= n - u + (u + 1) // 2 else print(\"YES\")", "n, m = map(int, input().split())\n\nn_palavras = {input() for i in range(n)}\nm_palavras = {input() for i in range(m)}\n\niguais = len(n_palavras & m_palavras)\n\nif n > m: print(\"YES\")\nelif m > n: print(\"NO\")\nelse:\n\tif iguais % 2 == 1: print(\"YES\")\n\telse: print(\"NO\")\n\n\t\t\t\t \t\t\t \t \t \t\t \t \t\t", "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\ndef solve():\r\n n, m = get_ints()\r\n\r\n aBall = set()\r\n for _ in range(n):\r\n aBall.add(get_string())\r\n \r\n bBall = set()\r\n for _ in range(m):\r\n bBall.add(get_string())\r\n \r\n common_words = len(aBall.intersection(bBall))\r\n\r\n if common_words % 2 != 0:\r\n if n-common_words >= m-common_words:\r\n return \"YES\"\r\n return \"NO\"\r\n else:\r\n if n-common_words > m-common_words:\r\n return \"YES\"\r\n return \"NO\"\r\n \r\n\r\n \r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n print(solve())", "n, m = map(int, input().split())\npoland = list(input() for i in range(n))\nenemy = list()\ncount = 0\nfor i in range(m):\n palavra = input()\n enemy.append(palavra)\n if palavra in poland:\n count += 1\nif count % 2 == 0:\n if n > m:\n print('YES')\n else:\n print('NO')\nelse:\n if n + 1 > m:\n print('YES')\n else:\n print('NO')\n\t \t \t\t \t \t\t\t \t \t \t \t \t", "def check_availability(element, collection: iter):\r\n return element in collection\r\n\r\n\r\nn, m = input().split()\r\nn = int(n)\r\nm = int(m)\r\n\r\nnList = []\r\ncommon = 0\r\nans = \"\"\r\nfor i in range(n):\r\n nList.append(input())\r\n\r\nfor i in range(m):\r\n str = input()\r\n if check_availability(str, nList):\r\n common += 1\r\n\r\n\r\n# for m, we play the uncommons first, for n, we play the commons first..\r\n# so same amount of commons and uncommons goes\r\n\r\n# but no, as they play optimally, ans is pretty easy\r\nif n > m:\r\n ans = \"YES\"\r\nelif n == m:\r\n if common % 2 == 0:\r\n ans = \"NO\"\r\n else:\r\n ans = \"YES\"\r\nelse:\r\n ans = \"NO\"\r\n\r\nprint(ans)\r\n# for unoptimal play\r\n# uncommonForM = m - common\r\n# uncommonForN = n - common\r\n\r\n\r\n# if n > m:\r\n# ans = \"YES\"\r\n# elif n == m:\r\n# if common == 0:\r\n# ans = \"NO\"\r\n# else:\r\n# ans = \"YES\"\r\n# elif n < m:\r\n# if common == 0:\r\n# ans = \"NO\"\r\n# elif common <= uncommonForM:\r\n# m = m - common*2 # played uncommons equal of commons, missed commons\r\n# n = n-common\r\n# if m < n:\r\n# ans = \"YES\"\r\n# else:\r\n# ans = \"NO\"\r\n# elif common > uncommonForM:\r\n# remainingN = n - uncommonForM\r\n# remainingM = m - uncommonForM\r\n# remainingCommon = common - uncommonForM\r\n\r\n# if remainingCommon % 2 == 0:\r\n# n = uncommonForN + remainingCommon/2\r\n# else:\r\n# n = uncommonForN + remainingCommon/2 + 1\r\n\r\n# m = remainingCommon/2\r\n# if m < n:\r\n# ans = \"YES\"\r\n# else:\r\n# ans = \"NO\"\r\n# print(ans)\r\n", "buff = input().split(\" \")\r\nn = int(buff[0])\r\nm = int(buff[1])\r\na = []\r\nb = []\r\nfor _ in range(n):\r\n a.append(input())\r\nfor _ in range(m):\r\n b.append(input())\r\na = set(a)\r\nb = set(b)\r\ninter = len(a & b)\r\nn-=inter\r\nm-=inter\r\nif n > m: print(\"YES\")\r\nelif inter % 2 == 1 and n == m: print(\"YES\")\r\nelse: print(\"NO\")", "n,m=map(int,input().split())\na={input() for x in range(n)}\nb={input() for y in range(m)}\nt=n+m-len(a|b)\nprint('YES' if n+t%2>m else 'NO')\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\nword1 = {input() for i in range(n)}\r\nword2 = {input() for i in range(m)}\r\ny = len(word1 & word2)\r\n\r\nif (n > m) or (n == m and len(word1 & word2) % 2):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "n,m = map(int, input().split())\np = []\ne = []\npm = 0\nfor i in range(n):\n p.append(input())\nfor i in range(m):\n e.append(input())\nfor i in e:\n if i in p:\n pm += 1\np1 = len(p)-pm\ne1 = len(e)-pm\nif p1 > e1: print('YES')\nelif p1 == e1:\n if pm%2 == 0:print('NO')\n else:print('YES')\nelse: print('NO')\n\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\na = {input() for x in range(n)}\r\nb = {input()for y in range(m)}\r\nt = n+m-len(a | b)\r\nprint('YES'if n+t % 2 > m else 'NO')\r\n", "def run():\r\n n, m = map(int, input().split())\r\n\r\n poland_ball_words = set()\r\n enemy_ball_words = set()\r\n\r\n for _ in range(n):\r\n poland_ball_words.add(input())\r\n\r\n for _ in range(m):\r\n enemy_ball_words.add(input())\r\n\r\n i = len(poland_ball_words.intersection(enemy_ball_words))\r\n\r\n if m > n or (m == n and i % 2 == 0):\r\n print(\"NO\")\r\n return\r\n\r\n print(\"YES\")\r\n\r\n\r\nif __name__ == '__main__':\r\n run()\r\n", "temp=input().split(\" \")\r\nn=int(temp[0])\r\nm=int(temp[1])\r\n\r\nnli=[]\r\nmli=[]\r\n\r\nfor _ in range(n):\r\n nli.append(input())\r\n\r\nfor _ in range(m):\r\n mli.append(input())\r\n\r\nres=n-m\r\ncount=0\r\nfor x in mli:\r\n if x in nli:\r\n count+=1\r\n\r\nres=res+(count%2)\r\nif res>0:\r\n print(\"YES\")\r\n\r\nelse:\r\n print(\"NO\")", "n,m=map(int,input().split())\na={input()for _ in[0]*n}\nb={input()for _ in[0]*m}\nl=len(a&b)\nprint('YNEOS'[len(a-b)+0--l//2<=len(b-a)+l//2::2])\n \t\t\t\t \t \t \t \t\t\t\t\t\t\t \t \t", "n, m = str(input()).split()\nn = int(n)\nm = int(m)\n\npolandBall = []\nenemyBall = []\nfor i in range(n):\n polandBall.append(input())\nfor j in range(m):\n enemyBall.append(input())\n\npoland = n\nenemy = m\ncontPalavrasRep = 0\nfor i in range(n):\n if polandBall[i] in enemyBall:\n contPalavrasRep += 1\n\nif contPalavrasRep % 2 == 1:\n if n >= m:\n print(\"YES\")\n else:\n print(\"NO\")\nelse:\n if m >= n:\n print(\"NO\")\n else:\n print(\"YES\")\n \t \t \t\t\t\t\t\t \t \t \t \t \t", "n, m = map(int, input().split())\r\ns = set([input() for i in range(n)])\r\nt = set([input() for i in range(m)])\r\nk = s & t\r\nif len(k) % 2 != 0:\r\n n += 1\r\nif n <= m:\r\n print('NO')\r\nelse:\r\n print('YES')\r\n", "n,m = list(map(int,input().split()))\r\npol = []\r\nene = []\r\nfor i in range(n):\r\n pol.append(input())\r\nfor i in range(m):\r\n ene.append(input())\r\n \r\ncommon = []\r\nfor word in pol:\r\n if word in ene:\r\n common.append(word)\r\n \r\na = n - len(common)\r\nb = m - len(common)\r\n\r\nif len(common)%2 == 0:\r\n a += len(common)//2\r\n b += len(common)//2\r\nelse:\r\n if len(common) == 1:\r\n a += 1\r\n else:\r\n a += len(common)//2+1\r\n b += len(common)//2\r\n\r\nif a <= b:\r\n print('NO')\r\nelse:\r\n print('YES')", "n,m=map(int,input().split())\r\nq,w=set(),set()\r\nfor i in range(n):q.add(input())\r\nfor i in range(m):w.add(input())\r\nr=len(q&w)\r\nprint(\"YES\" if len(q)-r//2>len(w)-(1+r)//2 else \"NO\")", "a, b = map(int, input().split())\r\ns = set([input() for _ in range(a)])\r\ns1 = set([input() for _ in range(b)])\r\nif len(s & s1) & 1:\r\n a += 1\r\nprint(\"NO\" if a <= b else \"YES\")\r\n", "n,m = map(int, input().split())\r\ns1,s2 = set(),set()\r\nfor i in range(n):\r\n s1.add(input())\r\nfor i in range(m):\r\n s2.add(input())\r\nprint(\r\n [\"NO\",\"YES\"][int(int(len(s1&s2)%2==1)+len(s1)>len(s2))]\r\n )\r\n", "n, m = [int(i) for i in input().split()]\nvoc_Poland = set()\nvoc_Enemy = set()\nfor i in range(n):\n voc_Poland.add(input())\nfor i in range(m):\n voc_Enemy.add(input())\nintersec = voc_Poland & voc_Enemy\nvoc_Poland = voc_Poland - intersec\nvoc_Enemy = voc_Enemy - intersec\nif(len(voc_Poland) > len(voc_Enemy)):\n ans = \"YES\"\nelif(len(voc_Poland) == len(voc_Enemy)):\n if(len(intersec) % 2 == 0):\n ans = \"NO\"\n else:\n ans = \"YES\"\nelse:\n ans = \"NO\"\nprint(ans)\n\n\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\n# from math import gcd as gcd\r\n# import bisect #-->For bisect.bisect_left=lower_bound and bisect_right=upper_bound)\r\n\r\nt = 1\r\n# t = int(input())\r\nfor i in range(t):\r\n n, m = map(int, input().split())\r\n poland, enemy = set(), set()\r\n for i in range(n):\r\n s = input().strip()\r\n poland.add(s)\r\n for i in range(m):\r\n s = input().strip()\r\n enemy.add(s)\r\n k = len(enemy & poland) # Length of Set Intersetion\r\n if (k % 2 == 0):\r\n if (n > m):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n else:\r\n if (n >= m):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "n, m = map(int, input().split())\r\nnlist = []\r\nmlist = []\r\nfor i in range(n):\r\n nlist.append(input())\r\nfor i in range(m):\r\n mlist.append(input())\r\nif n > m:\r\n print('Yes')\r\nelif n == m:\r\n counter = 0\r\n for i in nlist:\r\n if i in mlist:\r\n counter += 1\r\n if counter % 2 == 1:\r\n print('Yes')\r\n else:\r\n print('No')\r\nelse:\r\n print('No')", "n, m = map(int, input().split())\npol=[]\nen=[]\nboth = 0\nfor i in range(n):\n pol.append(input())\nfor i in range(m):\n s=input()\n if s in pol:\n both+=1\n en.append(s)\n else:\n en.append(s)\nif (len(en)-both)==(len(pol)-both):\n if both%2==0:\n if n<=m:\n print('NO')\n else: \n print('YES')\n else:\n print('YES')\nif (len(en)-both)>(len(pol)-both):\n print('NO')\nelif (len(en)-both)<(len(pol)-both):\n print('YES')\n", "k1,k2=map(int,input().split())\r\na=[]\r\nb=[]\r\nfor i in range(k1):\r\n ss=input()\r\n a.append(ss)\r\nfor j in range(k2):\r\n ss=input()\r\n b.append(ss)\r\nhp={}\r\ncnt=0\r\nfor i in b:\r\n if i in a:\r\n cnt+=1\r\nk1-=cnt\r\nk2-=cnt\r\nk1+=cnt//2\r\nk2+=cnt//2\r\nif cnt%2:\r\n k1+=1\r\nif k1>k2:\r\n print(\"YES\")\r\nelif k1==k2:\r\n if (k1+k2)%2==0:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n ", "poland=set()\r\nenemy=set()\r\nused=set()\r\nn,m=map(int,input().split())\r\nfor i in range(n):\r\n poland.add(input())\r\nfor i in range(m):\r\n enemy.add(input())\r\n\"\"\"print(poland)\r\nprint(enemy)\"\"\"\r\nflag1,flag2=True,True\r\nwhile poland and enemy:\r\n for i in poland:\r\n if i in enemy and i not in used:\r\n used.add(i)\r\n poland.remove(i)\r\n break\r\n else:\r\n for i in poland:\r\n if i not in used:\r\n used.add(i)\r\n poland.remove(i)\r\n break\r\n else:\r\n flag1=False\r\n if not flag1:\r\n break\r\n for t in enemy:\r\n if t in poland and t not in used:\r\n used.add(t)\r\n enemy.remove(t)\r\n break\r\n else:\r\n for t in enemy:\r\n if t not in used:\r\n used.add(t)\r\n enemy.remove(t)\r\n break\r\n else:\r\n flag2=False\r\n\r\n if not flag2:\r\n break\r\nif not poland and not enemy and flag1 and flag2:\r\n print(\"NO\")\r\n exit()\r\nif poland and not enemy and flag1:\r\n print(\"YES\")\r\nelif enemy and not poland and flag2:\r\n print(\"NO\")\r\nelse:\r\n if not flag1:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")", "n, m = map(int, input().split())\nc = 0\nd = {}\nfor i in range(n+m):\n s = input()\n d[s] = d.get(s, 0) + 1\n if d[s] == 2:\n c += 1\n\na = n-c + (c - c//2)\nb = m-c + c//2\n\nif a > b:\n print('YES')\nelse:\n print('NO')", "import math\r\n\r\n\r\ndef main_function():\r\n hash_n = {}\r\n n, m = [int(i) for i in input().split(\" \")]\r\n for i in range(n + m):\r\n s = input()\r\n if s in hash_n:\r\n hash_n[s] += 1\r\n else:\r\n hash_n[s] = 1\r\n n_s_turn = True\r\n one_time = 0\r\n two_time = 0\r\n for i in hash_n:\r\n if hash_n[i] == 2:\r\n two_time += 1\r\n else:\r\n one_time += 1\r\n while True:\r\n if two_time > 0:\r\n two_time -= 1\r\n if n_s_turn:\r\n if n > 0:\r\n n -= 1\r\n m -= 1\r\n else:\r\n print(\"NO\")\r\n break\r\n else:\r\n if m > 0:\r\n m -= 1\r\n n -= 1\r\n else:\r\n print(\"YES\")\r\n break\r\n n_s_turn = not n_s_turn\r\n else:\r\n break\r\n while True:\r\n if one_time > 0:\r\n one_time -= 1\r\n if n_s_turn:\r\n if n > 0:\r\n n -= 1\r\n else:\r\n print(\"NO\")\r\n break\r\n else:\r\n if m > 0:\r\n m -= 1\r\n else:\r\n print(\"YES\")\r\n break\r\n n_s_turn = not n_s_turn\r\n else:\r\n if n_s_turn:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n break\r\n\r\n\r\n\r\n\r\nmain_function()", "n,m=map(int,input().split())\r\na,b=set(),set()\r\nfor i in range(n):\r\n\ta.add(input())\r\nfor i in range(m):\r\n\tb.add(input())\r\nc=a.intersection(b)\r\nd=len(c)\r\nif d%2==0:\r\n\tn-=d\r\n\tm-=d\r\nelse:\r\n\tn-=(d-1)\r\n\tm-=d\r\nif n>m:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\r\n", "v = list(map(int, input().strip().split()))\nw1 = set({})\nw2 = set({})\nw3 = set({})\nfor i in range(v[0]):\n w1.add(input())\nfor i in range(v[1]):\n w2.add(input())\n\nw3 = w1.intersection(w2)\n\nif v[0] > v[1]:\n print(\"YES\")\nelif v[0] == v[1]:\n if len(w3)%2 == 0:\n print(\"NO\")\n else:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t\t\t\t \t \t\t\t \t \t\t \t\t \t", "\nn,m = map(int,input().split());s = set()\nfor _ in range(n+m):\n s.add(input())\nif n > m: print(\"YES\")\nelif n < m: print(\"NO\")\nelse: print(\"YES\" if len(s)%2 else \"NO\")\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 = set() ; b = set() ;\r\nfor i in range(n):\r\n x = input()\r\n a.add(x)\r\nfor i in range(m):\r\n x = input()\r\n b.add(x)\r\nc = len(a.intersection(b))\r\n\r\nif(n > m):\r\n print('YES')\r\n exit()\r\nif(n < m):\r\n print('NO')\r\n exit()\r\n\r\nif(c%2 == 0):\r\n print('NO')\r\nelse:\r\n print('YES')", "from sys import stdin, stdout\n\nn, m = map(int, stdin.readline().replace(\"\\n\", \"\").split(\" \"))\n\nif n > m: stdout.write(\"YES\")\nelif n < m: stdout.write(\"NO\")\nelif n == m:\n n2 = list()\n m2 = list()\n for n in range(0, n):\n n2.append(stdin.readline().replace(\"\\n\", \"\"))\n for n in range(0, m):\n m2.append(stdin.readline().replace(\"\\n\", \"\"))\n intr = set(set(n2).intersection(set(m2)))\n if len(intr) % 2 == 0:\n print(\"NO\")\n else:\n print(\"YES\")\n \t \t \t \t\t \t\t\t\t \t \t\t \t\t\t \t\t", "import math,sys,collections,bisect,heapq\n\n\ndef natural(n):\n\treturn n*(n+1)//2\n\ndef binarysearch(l,r,arr,k):\n\tif l<=r:\n\t\tmid = (l+r)//2\n\t\tif arr[mid] == k:\n\t\t\treturn mid\n\t\telif arr[mid]>k:\n\t\t\treturn binarysearch(l,mid-1,arr,k)\n\t\treturn binarysearch(mid+1,r,arr,k)\n\treturn -1\ndef ispossible(n):\n\n\th = 1\n\tnum = 2\n\tpre = 2\n\twhile num<=n:\n\t\tpre = num\n\t\th+=1\n\t\tnum+=(h*2)+h-1\n\treturn n-pre\n\ndef cal(n):\n\ttmp = 0\n\twhile n:\n\t\ttmp+=n%10\n\t\tn//=10\n\treturn tmp\ndef solve():\n\tn,m = list(map(int,input().split()))\n\ts1 = set()\n\tfor i in range(n):\n\t\ts1.add(input())\n\tc = 0\n\ts2 = set()\n\tfor i in range(m):\n\t\ttemp = input()\n\t\tif temp in s1:\n\t\t\tc+=1\n\t\ts2.add(temp)\n\tc1 = c2 = 0\n\tif c%2:\n\t\tc1+=c//2+1\n\t\tc2+=c//2\n\tc1+=len(s1)-c\n\tc2+=len(s2)-c\n\tif c1>c2:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\")\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n# number of test cases\n\n\n#t = int(input())\nt = 1\nfor i in range(t):\n\tsolve()\n\n\n\n\n\n\n\n\n\n", "nwords = list(map(int, input().split()))\r\nn = nwords[0]\r\nm = nwords[1]\r\n\r\npoland_ball = {}\r\n\r\n\r\ncommon = []\r\ncommon_len = 0\r\nfor i in range(n):\r\n word = input()\r\n poland_ball[word] = 0\r\n\r\n\r\nfor i in range(m):\r\n word = input()\r\n if (word in poland_ball.keys()): \r\n common.append(word)\r\n common_len += 1\r\n\r\nfor i in range(common_len):\r\n if (i % 2 == 0):\r\n common_len -= 1\r\n m -= 1\r\n else:\r\n common_len -= 1\r\n n -= 1\r\n \r\n if(common_len <= 0):\r\n break\r\n\r\nif(n > m):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "n,m=map(int,input().split())\r\nn1=n\r\nm1=m\r\np=set()\r\ne=set()\r\nwhile n1 :\r\n n1-=1\r\n p.add(input())\r\nwhile m1 :\r\n m1-=1\r\n e.add(input())\r\nk=p.intersection(e)\r\n#print(k)\r\nln=len(k)\r\nif ln==0:\r\n if n<=m:\r\n print(\"NO\")\r\n #print(1)\r\n else:\r\n print(\"YES\")\r\nelse:\r\n m-=ln\r\n n-=ln\r\n if ln%2:\r\n if n>=m:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\n else:\r\n if n<=m:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n \r\n \r\n", "n,m=map(int,input().split())\r\na={input() for x in range(n)}\r\nb={input() for y in range(m)}\r\nt=n+m-len(a|b)\r\nprint('YES' if n+t%2>m else 'NO')", "# def hash(s):\r\n# h = 0\r\n# for c in s:\r\n# h = (h * 31 + ord(c)) % 645622345\r\n# return h\r\n\r\n\r\ndef solve(n, poland, m, enemy):\r\n cnt_common = len(set(poland).intersection(set(enemy)))\r\n if cnt_common % 2 == 1:\r\n if n > m - 1:\r\n return \"YES\"\r\n else:\r\n return \"NO\"\r\n else:\r\n if n > m:\r\n return \"YES\"\r\n else:\r\n return \"NO\"\r\n\r\n\r\nn, m = list(map(int, input().split()))\r\npoland = []\r\nenemy = []\r\nfor _ in range(n):\r\n poland.append(input().strip())\r\nfor _ in range(m):\r\n enemy.append(input().strip())\r\n\r\nresult = solve(n, poland, m, enemy)\r\nprint(result)\r\n", "n, m = map(int, input().split())\n\nwords = set()\nfor i in range(n+m):\n\twords.add(input())\n\n\nif n+m > len(words):\n\tcommon_words = n+m - len(words)\n\n\t# if is odd polandball will\n\t# have the advantage because he starts\n\tif common_words%2 == 1:\n\t\tn += 1\n\n\t\t\nif n>m:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\t\t \t \t\t \t\t\t \t\t\t \t \t\t\t\t\t \t \t", "n, m = [int(x) for x in input().split()]\n\npolandBall = []\n\nenemyBall = []\n\ncomum = []\n\nfor _ in range(n):\n polandBall.append(input())\n\nfor _ in range(m):\n linha = input()\n enemyBall.append(linha)\n if linha in polandBall:\n comum.append(linha)\n\nwin = False\n\nwhile True:\n if len(polandBall) <= 0:\n win = False\n break\n if len(comum) > 0:\n palavra = comum[0]\n del comum[0]\n\n indexPoland = polandBall.index(palavra)\n del polandBall[indexPoland]\n\n indexEnemy = enemyBall.index(palavra)\n del enemyBall[indexEnemy]\n\n else:\n del polandBall[0]\n\n if len(enemyBall) <= 0:\n win = True\n break\n\n if len(comum) > 0:\n palavra = comum[0]\n del comum[0]\n\n indexPoland = polandBall.index(palavra)\n del polandBall[indexPoland]\n\n indexEnemy = enemyBall.index(palavra)\n del enemyBall[indexEnemy]\n\n else:\n # palavra = polandBall[0]\n del enemyBall[0]\n\nif win:\n print('YES')\nelse:\n print('NO') \n \t\t\t \t \t\t\t\t\t\t\t\t \t \t\t \t\t\t \t\t\t", "from math import ceil\r\n\r\nn,m=map(int,input().split())\r\na=[input() for z in range(n)]\r\nb=[input() for z in range(m)]\r\ncom=0\r\nfor z in b:\r\n if z in a:\r\n com+=1\r\n \r\ncom2=com%2\r\nif len(a)+com2>len(b):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n, m = map(int, input().split())\nI = lambda x: {input() for _ in range(x)}\np, e = I(n), I(m)\nprint(\"YNEOS\"[1-int(len(p) + len(p & e)%2 > len(e))::2])", "n, m = map(int, input().split())\r\na1, a2 = set(), set()\r\nfor i in range(n):\r\n a1.add(input())\r\nfor i in range(m):\r\n a2.add(input())\r\nk = len(a1 & a2)\r\nn -= k\r\nm -= k\r\nif n == m:\r\n if k % 2 == 1:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n if n > m:\r\n print('YES')\r\n else:\r\n print('NO')\r\n", "\r\n\r\nn,m=map(int,input().split())\r\n\r\npb=list()\r\neb=list()\r\nfor i in range(n):\r\n pb.append(input())\r\ncom=0\r\nfor j in range(m):\r\n eb.append(input())\r\n if eb[j] in pb:\r\n com+=1\r\nif com%2==1:\r\n if n>m-1:\r\n print(\"YES\")\r\n else: print(\"NO\")\r\nelse:\r\n if n>m:\r\n print(\"YES\")\r\n else: print(\"NO\")\r\n\r\n", "import sys\n\ntoks = (tok for tok in sys.stdin.read().split())\nN = int(next(toks))\nM = int(next(toks))\npoland = set([next(toks) for _ in range(N)])\nenemy = set([next(toks) for _ in range(M)])\ninters = 0\nfor word in enemy:\n if word in poland:\n inters += 1\n\nst1 = N\nst2 = M\nst_inters = inters\nturn1 = True\nwhile True:\n if turn1:\n if st1 == 0:\n print(\"NO\")\n break\n st1 -= 1\n if st_inters > 0:\n st2 -= 1\n st_inters -= 1\n else:\n if st2 == 0:\n print(\"YES\")\n break\n st2 -= 1\n if st_inters > 0:\n st1 -= 1\n st_inters -= 1\n turn1 = not turn1\n", "a,b=map(int,input().split())\r\ntemp1=[]\r\nfor i in range((a+b)):\r\n s=str(input())\r\n temp1.append(s)\r\nif a>b:\r\n print(\"YES\")\r\nif a<b:\r\n print(\"NO\")\r\nif a==b:\r\n if (len(set(temp1)))%2!=0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\n ", "p, e = [int(x) for x in input().split()]\n\npdict = {}\nfor i in range(p):\n\tw = input()\n\tpdict[w] = True\n\nrep = 0\nfor i in range(e):\n\tw = input()\n\tif w in pdict:\n\t\te -= 1\n\t\tp -= 1\n\t\trep += 1\n\nif e > p:\n\tprint(\"NO\")\nelif p > e:\n\tprint(\"YES\")\nelif rep % 2 == 0:\n\tprint(\"NO\")\nelse:\n\tprint(\"YES\")\n \t \t \t\t\t \t \t\t\t\t \t\t \t \t", "n, m = map(int,input().split())\r\nA = set()\r\nk = 0 # число общих слов в словарях\r\n\r\nfor i in range(n):\r\n s = input()\r\n A.add(s)\r\n\r\nfor i in range(m):\r\n s = input()\r\n if s in A:\r\n k += 1\r\n\r\nif k % 2 == 0:\r\n if n > m:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n if n >= m:\r\n print('YES')\r\n else:\r\n print('NO')", "n, m = list(map(int, input().split()))\npalavras = set()\n\nfor i in range(n):\n palavras.add(input())\n\nfor i in range(m):\n palavras.add(input())\n\nif n > m or (n == m and (m + n - len(palavras)) % 2 != 0):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "n,m = map(int,input().split())\r\np = set()\r\nfor i in range(n):p.add(input())\r\ne = set()\r\nfor i in range(m):e.add(input())\r\nt = p&e; p = p-t; e = e-t\r\nprint(\"YNEOS\"[len(p)+ len(t)%2<=len(e)::2])", "n, m = map(int, input().split())\npoland = set()\nboth = 0\n\nfor i in range(n):\n poland.add(input())\n \nfor i in range(m):\n if input() in poland:\n both += 1\n\nif n < m:\n print(\"NO\")\nelif m < n:\n print(\"YES\")\nelif both % 2 == 0:\n print(\"NO\")\nelse:\n print(\"YES\")\n \n\n \t \t\t \t \t \t \t \t\t\t\t \t", "n, m = map(int, input().split())\r\np = set([input() for i in range(n)])\r\ne = set([input() for i in range(m)])\r\nx = len(p | e)\r\nn -= x // 2\r\nm -= (x + 1) // 2\r\nprint(\"YES\" if n > m else \"NO\")", "repeats = {\n}\n\np, v = map(int, input().split())\n\nfor wordIndex in range(0, p + v):\n \n word = input()\n \n if word not in list(repeats.keys()):\n repeats.update({word: 0})\n \n else:\n repeats[word] += 1\n \nrepeats = sum(list(repeats.values())) % 2\n\np += repeats\n\nif p == v or v > p:\n print(\"NO\")\nelse:\n print(\"YES\")", "n, m = map(int, input().split())\r\ns1, s2, sc = set(), set(), set()\r\nfor i in range(n):\r\n s1.add(input())\r\nfor i in range(m):\r\n s2.add(input()) \r\nsc = s1 & s2 \r\ns1 = s1 - sc \r\ns2 = s2 - sc \r\na = len(sc) // 2 + len(sc) % 2 + len(s1)\r\nb = len(sc) // 2 + len(s2)\r\nif(a > b):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def check_availability(element, collection: iter):\r\n return element in collection\r\n\r\n\r\nn, m = input().split()\r\nn = int(n)\r\nm = int(m)\r\n\r\nnList = []\r\ncommon = 0\r\nans = \"\"\r\nfor i in range(n):\r\n nList.append(input())\r\n# s = set(nList)\r\n# print(s)\r\nfor i in range(m):\r\n str = input()\r\n if check_availability(str, nList):\r\n common += 1\r\n# print(\"commons \", common)\r\nuncommonForM = m - common\r\nuncommonForN = n - common\r\n\r\n# for m, we play the uncommons first, for n, we play the commons first..\r\n# so same amount of commons and uncommons goes\r\n\r\nif n > m:\r\n ans = \"YES\"\r\nelif n == m:\r\n if common % 2 == 0:\r\n ans = \"NO\"\r\n else:\r\n ans = \"YES\"\r\nelse:\r\n ans = \"NO\"\r\n\r\nprint(ans)\r\n", "n,m=map(int,input().split())\r\nl=[]\r\nl1=[]\r\nif n<m:print(\"NO\")\r\nelif n>m:print(\"YES\")\r\nelse:\r\n for _ in range(n):\r\n s=input().rstrip()\r\n l.append(s)\r\n for _ in range(m):\r\n s1=input().rstrip()\r\n l1.append(s1)\r\n h=set(l)\r\n k=set(l1)\r\n c=len(k.intersection(h))\r\n if c%2==0:print(\"NO\")\r\n else:print(\"YES\")", "# Problem: B. PolandBall and Game\r\n# Contest: Codeforces - 8VC Venture Cup 2017 - Elimination Round\r\n# URL: https://codeforces.com/problemset/problem/755/B\r\n# Memory Limit: 256 MB\r\n# Time Limit: 1000 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=INL()\r\n\t\r\n\tPB=set()\r\n\tEB=set()\r\n\t\r\n\tfor _ in range(n):\t\r\n\t\tPB.add(INS())\r\n\tfor _ in range(m):\r\n\t\tEB.add(INS())\r\n\t\t\r\n\tI=PB&EB\r\n\t\r\n\tif len(I)%2==0:\r\n\t\tx=len(I)//2\r\n\t\ty=len(I)//2\t\r\n\telse:\r\n\t\tx=len(I)//2\r\n\t\ty=len(I)//2+1\t\r\n\t\r\n\tif len(PB)-x>len(EB)-y:\r\n\t\tOPS(\"YES\")\r\n\telse:\r\n\t\tOPS(\"NO\")", "#n=int(input())\r\nn,m = map(int, input().strip().split(' '))\r\n#lst = list(map(int, input().strip().split(' ')))\r\np=[]\r\ne=[]\r\nfor i in range(n):\r\n s=input()\r\n p.append(s)\r\nfor i in range(m):\r\n s=input()\r\n e.append(s)\r\nif n>m:\r\n print('YES')\r\nelif m>n:\r\n print('NO')\r\nelse:\r\n list3 = list(set(p)&set(e))\r\n l=len(list3)\r\n if l%2==0:\r\n print('NO')\r\n else:\r\n print('YES')\r\n ", "s=input().split()\nn,m=int(s[0]),int(s[1])\nl=[]\nfor i in range(n):\n l.append(input())\nc=0\nfor i in range(m):\n s=input()\n if s in l:\n c+=1\nx=n-c+c//2+c%2\ny=m-c+c//2\nif x>y:\n print('YES')\nelse:\n print('NO')\n\n\t\t \t\t\t\t \t \t\t\t \t\t \t\t \t \t\t", "n,m=list(map(int,input().split()))\r\ns1,s2=set(),set()\r\nfor i in range(n):\r\n s1.add(input())\r\nfor i in range(m):\r\n s2.add(input())\r\nif n>m:\r\n print('YES')\r\nelif m>n:\r\n print('NO')\r\nelse:\r\n x=len(s1 & s2)\r\n if x%2==0:\r\n print('NO')\r\n else:\r\n print('YES')", "n,m = map(int,input().split())\r\nl1=[input() for i in range(n)]\r\nl2=[input() for i in range(m)]\r\nif n>m:\r\n print('YES')\r\nelif n<m:\r\n print('NO')\r\nelse:\r\n l1.sort()\r\n l2.sort()\r\n same_words = 0\r\n for i in l1:\r\n l = 0\r\n r = len(l2)-1\r\n while l<=r:\r\n mid = l + (r-l)//2\r\n if l2[mid] == i:\r\n same_words += 1\r\n break\r\n elif l2[mid] < i:\r\n l = mid+1\r\n else:\r\n r = mid-1\r\n if same_words%2==0:\r\n print('NO')\r\n else:\r\n print('YES')", "n, m = map(int, input().split())\r\ns = set()\r\ncount = 0\r\nfor i in range(n):\r\n\ts.add(input())\r\nfor i in range(m):\r\n\tif (input() in s):\r\n\t\tcount += 1\r\n\t\t\r\nif count%2 == 0:\r\n\tif m<n:\r\n\t\tprint(\"yes\")\r\n\telse:\r\n\t\tprint(\"no\")\r\nelse:\r\n\tif m>n:\r\n\t\tprint(\"no\")\r\n\telse:\r\n\t\tprint(\"yes\")\r\n\t\t\r\n\t\t\r\n#make cases and see the condition ...\r\n#rather than doing count...u can do p = a & b\r\n#here p gives u common element list", "# PolandBall and Game\r\n\r\nn, m = input().split()\r\nn = int(n)\r\nm = int(m)\r\ncount = 0\r\npolandball = []\r\nenemyball = []\r\nfor i in range(n):\r\n polandball.append(input())\r\nfor i in range(m):\r\n enemyball.append(input())\r\n for j in range(n):\r\n if polandball[j] == enemyball[i]:\r\n count += 1\r\nn -= count\r\nm = m - count - (count % 2)\r\nif n > m:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n,m=map(int,input().split())\r\npol=[];vrag=[]\r\nfor i in range(n):pol.append(str(input()))\r\nfor i in range(m):vrag.append(str(input()))\r\n\r\ncommon=len(list(set(pol)&set(vrag)))\r\npol=len(pol)-common\r\nvrag=len(vrag)-common\r\n\r\nif common%2==1:\r\n vrag-=1\r\nif pol>vrag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "po = []\nigual = 0\nn, m = [int(x) for x in input().split()]\n\nif n != m:\n for i in range(n+m):\n e = input()\n if n>m:\n print(\"YES\")\n else:\n print(\"NO\")\n\nelse:\n for i in range (n):\n po.append(input())\n for i in range (m):\n e = input()\n if e in po:\n igual += 1\n\n if igual % 2 == 1 :\n print(\"YES\")\n else:\n print(\"NO\")\n\n\t \t\t \t\t\t\t\t\t \t \t\t \t \t", "n, m = list(map(int, input().split(\" \")))\n\npball = set()\neball = set()\n\nfor i in range(n):\n\tpball.add(input())\n\nfor i in range(m):\n\teball.add(input())\n\nif (n > m):\n\tprint(\"YES\")\nelif (m > n):\n\tprint(\"NO\")\nelse: \n\tintersection = eball.intersection(pball)\n\tprint(\"YES\" if len(intersection) % 2 != 0 else \"NO\")\n \t \t\t\t\t \t \t\t \t \t \t\t", "n = list(map(lambda x: int(x), input().split(\" \")))\n\ndef saveWords(q1, q2):\n pwords = []\n qtyWords = 0\n for i in range(q1):\n pwords.append(input())\n\n for i in range(q2):\n word = input()\n if word in pwords:\n qtyWords += 1\n\n if(q1+q2-qtyWords > 0):\n com = q1+q2-qtyWords;\n q1 -= com\n q2 -= com\n\n if com%2 == 1:\n q1+=(com)/2+1;\n q2+=(com)/2;\n else:\n q1+=(com)/2\n q2+=(com)/2\n\n if q1>q2:\n print(\"YES\")\n else:\n print(\"NO\") \n\nsaveWords(n[0],n[1])\n\n\t \t \t \t\t \t \t \t\t\t \t\t\t\t \t", "l=input().split()\r\nn=int(l[0])\r\nm=int(l[1])\r\ncommon=[]\r\nhashi=dict()\r\nfor i in range(n):\r\n s=input()\r\n hashi[s]=1\r\nfor i in range(m):\r\n s=input()\r\n if s in hashi:\r\n common.append(s)\r\nz=len(common)\r\nif(z%2):\r\n if(n>=m):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n if(n>m):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "poland = {}\n\nline = input().split(' ')\npolandCount = int(line[0])\nenemyCount = int(line[1])\n\nfor i in range(polandCount):\n\tpoland[input()] = 1\n\nunique = 0\nfor i in range(enemyCount):\n\tif poland.get(input()) == None:\n\t\tunique += 1\n\nsame = (enemyCount - unique)\nuniquePol = polandCount - same\n\nif uniquePol > unique:\n\tprint(\"YES\")\nelif uniquePol < unique:\n\tprint(\"NO\")\nelse:\n\tif same%2 == 0:\n\t\tprint(\"NO\")\n\telse:\n\t\tprint(\"YES\")\n\n\t\t\t \t \t \t \t \t\t\t\t \t\t \t \t\t \t\t", "n,m=[int(i) for i in input().split()]\r\npb=[];eb=[]\r\nfor i in range(n):\r\n pb+=input().split()\r\nfor i in range(m):\r\n eb+=input().split()\r\ncommon=len(set(pb) & set(eb))\r\nn-=common\r\nm-=common\r\nif common%2==0:\r\n if n>m:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n if n>=m:\r\n print('YES')\r\n else:\r\n print('NO')", "times = input()\r\n\r\n(time1, time2) = times.split(\" \")\r\n\r\ncounted_words = set()\r\n\r\nrepeated = 0\r\nwords1 = 0\r\nwords2 = 0\r\n\r\nfor _ in range(int(time1)):\r\n word = input().strip()\r\n words1 += 1\r\n\r\n counted_words.add(word)\r\n\r\nfor _ in range(int(time2)):\r\n word = input().strip()\r\n words2 += 1\r\n\r\n if word in counted_words:\r\n repeated += 1\r\n\r\nif repeated % 2 == 1:\r\n words2 -= 1\r\n\r\n\r\nif words1 > words2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n, m = [int(x) for x in input().split(' ')]\r\ndone = {}\r\nf = set([])\r\ns = set([])\r\nfor _ in range(n):\r\n f.add(input())\r\n# print(f)\r\nfor _ in range(m):\r\n s.add(input())\r\n# print(s)\r\n\r\n\r\ncommon = f.intersection(s)\r\n# print('common is', list(common))\r\n\r\nfirst = list(common)\r\nsecond = list(common)\r\n\r\nfor item in f:\r\n if item not in common:\r\n first.append(item)\r\nfor item in s:\r\n if item not in common:\r\n second.append(item)\r\ni = 0\r\nj = 0\r\nf = first\r\ns = second\r\n# print(f)\r\n# print(s)\r\nwhile True:\r\n if i >= len(f):\r\n print('NO')\r\n exit()\r\n while i < len(f) and f[i] in done:\r\n i += 1\r\n if i >= len(f):\r\n print('NO')\r\n exit()\r\n # print('First played', f[i])\r\n done[f[i]] = 1\r\n\r\n if j >= len(s):\r\n print('YES')\r\n exit()\r\n while j < len(s) and s[j] in done:\r\n j += 1\r\n if j >= len(s):\r\n print('YES')\r\n exit()\r\n done[s[j]] = 1\r\n # print('Second played', s[j])\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\ng = {input()[:-1] for _ in range(n)}\r\nw = {input()[:-1] for _ in range(m)}\r\nx = len(g & w)\r\nif n > m:\r\n print(\"YES\")\r\nelif n == m:\r\n if x % 2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n", "from collections import * \r\nfrom heapq import *\r\n# from functools import cache\r\nfrom itertools import accumulate as acu\r\nhpush = heappush\r\nhpop = heappop \r\n\r\ndef get_int():\r\n return int(input())\r\ndef get_nums():\r\n return list(map(int, input().split()))\r\n\r\ndef main():\r\n n, m = get_nums()\r\n w1 = []\r\n w2 = []\r\n for _ in range(n):\r\n w1.append(input())\r\n for _ in range(m):\r\n w2.append(input())\r\n common = 0\r\n for word in w1:\r\n if word in w2:\r\n common += 1\r\n if (common + 1)//2 + n > (common//2 + m):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nmain()", "n, m = map(int, input().split())\n\nna = []\neq = 0\n\nfor _ in range(n):\n na.append(input())\nfor _ in range(m):\n if input() in na:\n eq += 1\n\nif n > m:\n print('YES')\nelif n < m:\n print('NO')\nelse:\n if eq % 2:\n print('YES')\n else:\n print('NO')\n\n \t\t\t \t \t \t \t \t\t\t \t \t\t", "n,m=map(int,input().split())\r\nL1=[]\r\nL2=[]\r\ncount=0\r\nfor i in range(n):\r\n L1.append(input())\r\nfor j in range(m):\r\n L2.append(input())\r\nif(n>m):\r\n print('YES')\r\nelif(m>n):\r\n print('NO')\r\nelse:\r\n for x in L1:\r\n if x in L2:\r\n count+=1\r\n if(count%2==0):\r\n print('NO')\r\n else:\r\n print('YES')\r\n", "def resolve(nArray, mArray):\r\n if n>m:\r\n print('YES')\r\n elif m>n:\r\n print('NO')\r\n else:\r\n nArray = set(nArray)\r\n mArray = set(mArray)\r\n mArray = set(mArray.intersection(nArray))\r\n if len(mArray)%2==0:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n\r\nn, m =[int(a) for a in input().split()]\r\n\r\nnArray = []\r\nmArray = []\r\n\r\nfor i in range(n):\r\n nArray.append(input())\r\nfor i in range(m):\r\n mArray.append(input())\r\nresolve(nArray, mArray)", "def poland():\n # n = poland\n # m = enemy\n n, m = map(int, input().split())\n\n tudo = [input() for i in range(n + m)]\n unicas = list(dict.fromkeys(tudo))\n if len(unicas) % 2 == 1:\n if n >= m:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n if n <= m:\n print(\"NO\")\n else:\n print(\"YES\")\n\n\npoland()\n\n \t\t\t\t\t\t\t\t \t \t\t \t\t\t \t \t", "q = input().split()\r\na = int(q[0])\r\nb = int(q[1])\r\nd = []\r\ne = []\r\nf = 0\r\nfor i in range(a):\r\n g = input()\r\n d.append(g)\r\n e.append(1)\r\nfor i in range(b):\r\n g = input()\r\n if g in d:\r\n e[d.index(g)] = 0\r\n else:\r\n f += 1\r\nh = sum(e)\r\nk = a - h\r\nif k % 2 == 0:\r\n if h > f:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n if h >= f:\r\n print('YES')\r\n else:\r\n print('NO') ", "import math\r\nn,m=map(int,input().split())\r\na={input() for x in range(n)}\r\nb={input() for y in range(m)}\r\nz = (n+m)-len(a|b)\r\nn -= z//2\r\nm -= math.ceil(z/2)\r\nprint('YES' if n > m else 'NO')", "from calendar import c\r\n\r\n\r\nn, m = map(int, input().split())\r\ns1 = set(input() for _ in range(n))\r\ns2 = set(input() for _ in range(m))\r\nc = s1 & s2\r\nfor i in range(n + m):\r\n if len(s1) == 0:\r\n print(\"NO\")\r\n break\r\n if c:\r\n for i in c:\r\n k = i\r\n break\r\n c.remove(k)\r\n s1.remove(k)\r\n s2.remove(k)\r\n else:\r\n for i in s1:\r\n k = i\r\n break\r\n s1.remove(k)\r\n\r\n if len(s2) == 0:\r\n print(\"YES\")\r\n break\r\n if c:\r\n for i in c:\r\n k = i\r\n break\r\n c.remove(k)\r\n s1.remove(k)\r\n s2.remove(k)\r\n else:\r\n for i in s2:\r\n k = i\r\n break\r\n s2.remove(k)\r\n", "# from heapq import *\n\ndef lets_do_it():\n p, e = [int(a) for a in input().split(' ')]\n poland_set = set()\n while p:\n poland_set.add(input())\n p -= 1\n common_words = []\n e_count = 0\n while e:\n word = input()\n if word in poland_set:\n poland_set.discard(word)\n common_words.append(word)\n else:\n e_count += 1\n e -= 1\n\n p_count = len(poland_set) + (len (common_words) % 2)\n print('YES' if p_count > e_count else 'NO')\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, m = map(int, input().split())\r\na1, a2 = set(), set()\r\nfor i in range(n):\r\n a1.add(input())\r\nfor i in range(m):\r\n a2.add(input())\r\nk = len(a1 & a2)\r\nif n > m:\r\n print('YES')\r\nelse:\r\n if n < m:\r\n print('NO')\r\n else:\r\n if k % 2 == 0:\r\n print('NO')\r\n else:\r\n print('YES')", "polland_ball, enemy_ball = map(int, input().split())\r\n\r\npalavras_polland = set()\r\npalavras_enemy = set()\r\n\r\nfor i in range(polland_ball):\r\n palavras_polland.add(str(input()))\r\n\r\nfor i in range(enemy_ball):\r\n palavras_enemy.add(str(input()))\r\n\r\npalavras_em_comum = palavras_polland.intersection(palavras_enemy)\r\npalavras_distintas_polland = palavras_polland.difference(palavras_em_comum)\r\npalavras_distintas_enemy = palavras_enemy.difference(palavras_em_comum)\r\n\r\npolland_venceu = \"\"\r\nif len(palavras_em_comum) % 2 == 0:\r\n if len(palavras_distintas_polland) > len(palavras_distintas_enemy):\r\n polland_venceu = \"YES\"\r\n else:\r\n polland_venceu = \"NO\"\r\nelse:\r\n if len(palavras_distintas_enemy) - len(palavras_distintas_polland) > 0:\r\n polland_venceu = \"NO\"\r\n else:\r\n polland_venceu = \"YES\"\r\n\r\nprint(polland_venceu)\r\n", "def ip():\r\n return int(input())\r\n\r\ndef sip():\r\n return input()\r\n\r\ndef mip():\r\n return map(int,input().split())\r\n\r\ndef lip():\r\n return list(map(int,input().split()))\r\n\r\ndef matip(n,m):\r\n lst=[]\r\n for i in range(n):\r\n arr = lip()\r\n lst.append(arr)\r\n return lst\r\n\r\nn,m = mip()\r\nlst=[]\r\narr = []\r\nfor i in range(n):\r\n s = sip()\r\n lst.append(s)\r\nfor i in range(m):\r\n s = sip()\r\n arr.append(s)\r\nif n>m:\r\n print('YES')\r\nelif m>n:\r\n print('NO')\r\nelse:\r\n lst = set(lst)\r\n arr = set(arr)\r\n arr = set(arr.intersection(lst))\r\n if len(arr)%2==0:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")", "n, m = [int(num) for num in input().split()]\npalavras = {}\nnum_repetidas = 0\nfor _ in range(n + m):\n palavra = input()\n if palavra in palavras:\n num_repetidas += 1\n palavras[palavra] = True\n\nanswer = ''\nif n > m:\n answer = 'YES'\nelif n < m:\n answer = 'NO'\nelse:\n answer = 'NO' if num_repetidas % 2 == 0 else 'YES'\n\nprint(answer)\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\n\r\nn_set = set()\r\nm_set = set()\r\n\r\nfor _ in range(n):\r\n n_set.add(input())\r\n\r\nfor _ in range(m):\r\n m_set.add(input())\r\n\r\ninter = len(n_set.intersection(m_set))\r\nn_diff = len(n_set) - inter\r\nm_diff = len(m_set) - inter\r\n\r\n# if inter == 0:\r\n# if n_diff > m_diff:\r\n# print('YES')\r\n# else:\r\n# print('NO')\r\n# else: # inter != 0\r\nif n_diff > m_diff:\r\n print('YES')\r\nelif n_diff < m_diff:\r\n print('NO') # I guess?\r\nelse:\r\n if (inter % 2 == 0):\r\n print('NO')\r\n else:\r\n print('YES')\r\n", "entry = list(map(int, input().split()))\nn = entry[0]\nm = entry[1]\npoland_set = set()\nenemy_set = set()\nfor i in range(n):\n data = input()\n poland_set.add(data)\n\nfor i in range(m):\n data = input()\n enemy_set.add(data)\n\nlen_uni = len(poland_set.union(enemy_set))\nif len_uni == len(poland_set) + len(enemy_set):\n if len(poland_set) > len(enemy_set):\n print(\"YES\")\n else:\n print(\"NO\")\nelif len(poland_set) == len(enemy_set):\n if len_uni % 2 == 0:\n print(\"NO\")\n else:\n print(\"YES\")\nelse:\n if len(poland_set) > len(enemy_set):\n print(\"YES\")\n else:\n print(\"NO\")\n\n\t\t \t \t \t\t\t \t\t\t\t \t\t \t\t\t \t\t \t", "nm = list(map(int, input().split()))\nn, m = nm[0], nm[1]\npol = set()\nvrag = set()\nfor i in range(0, n):\n pol.add(input())\nfor i in range(0, m):\n vrag.add(input())\nvrf = 0\n \nwhile len(pol) > 0 and len(vrag) > 0:\n vrf = 0\n pol_flag = 0\n for w in pol:\n if w in vrag:\n pol.remove(w)\n vrag.remove(w)\n pol_flag = 1\n break\n if pol_flag == 0:\n pol.pop()\n if len(vrag) == 0:\n break\n vrag_flag = 0\n for w in vrag:\n if w in pol:\n pol.remove(w)\n vrag.remove(w)\n vrag_flag = 1\n vrf = 1\n break\n if vrag_flag == 0:\n vrag.pop()\n vrf = 1\n \nif len(pol) == 0 and vrf == 1:\n print('NO')\nelse:\n print('YES')\n\t\t \t\t \t\t \t\t \t\t \t \t\t\t \t \t", "n,m=map(int,input().split())\r\nx=[]\r\nfor i in range(n+m):\r\n x.append(input())\r\nif n>m: print('YES')\r\nelif n<m: print('NO')\r\nelif n==m:\r\n if len(set(x))%2!=0: print('YES')\r\n else: print('NO')", "controles = list(map(int, input().split()))\nprimeiro = []\nsegundo = []\n\n\nfor a in range(controles[0]):\n primeiro.append(input())\n\nfor b in range(controles[1]):\n segundo.append(input())\nif controles[0] > controles[1]:\n print(\"YES\")\nelif controles[1] > controles[0]:\n print(\"NO\")\n\nif controles[0] == controles[1]:\n final = set(primeiro).union(segundo)\n if len(final)%2 == 0:\n print(\"NO\")\n\n else:\n print(\"YES\")\n\n\n \t\t \t \t \t\t \t\t\t\t\t\t\t", "n, m = list(int(num) for num in input().split(\" \"))\npalavras_polland = []\n\npalavras_iguais = 0\nfor i in range(n):\n palavras_polland.append(input())\nfor j in range(m):\n palavra_enemy = input()\n if n == m and palavra_enemy in palavras_polland:\n palavras_iguais += 1\n\nif n > m:\n print(\"YES\")\nelif m < n:\n print(\"NO\")\nelse:\n if palavras_iguais % 2 == 1:\n print(\"YES\")\n else:\n print(\"NO\")\n \t\t \t \t\t \t \t \t \t\t \t", "c=input().split()\ns=int(c[0])\nn=int(c[1])\ndl=[]\ndlx=[]\nj=0\nfor i in range(s):\n\tdl.append(input())\nfor i in range(n):\n\tdlx.append(input())\nfor i in dl:\n\tif i in dlx:\n\t\tj+=1\nif s>n:\n\tprint(\"YES\")\nelif n>s:\n\tprint(\"NO\")\nelse:\n\tif j%2==0:\n\t\tprint(\"NO\")\n\telse:\n\t\tprint(\"YES\")\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 = set()\r\nfor _ in range(n+m):\r\n s.add(input())\r\nif n > m: print(\"YES\")\r\nelif n < m: print(\"NO\")\r\nelif len(s) % 2 == 1: print(\"YES\")\r\nelse: print(\"NO\")# 1690586561.3338034", "n,m = map(int,input().split())\n\np = []\nfor i in range(n):\n p.append(input())\n \ne = []\nfor i in range(m):\n e.append(input())\n \nsame = len(set(p).intersection(e))\n\nif n > m or n == m and same%2:\n print(\"YES\")\nelse:\n print(\"NO\")\n \n\t \t \t \t\t \t\t \t\t\t\t\t\t\t \t \t", "n, m = input().split()\nn = int(n)\nm = int(m)\n\nwords = set()\n\nrepeated = 0\n\np = 0\ne = 0\n\n\nfor i in range(n):\n\tx = input()\n\twords.add(x)\n\tp += 1\n\t\nfor i in range(m):\n\tx = input()\n\tif x in words:\n\t\tp -= 1\t\t\n\t\trepeated += 1\n\t\n\telse:\n\t\te += 1\n\nif repeated >= 2:\n\tif repeated % 2 == 1:\n\t\tp += repeated//2 + 1\n\t\te += repeated//2\n\telse:\n\t\tp += repeated//2\n\t\te += repeated//2\nelse:\n\tp += repeated\n\nif p > e:\n\tprint('YES')\nelse:\n\tprint('NO')\n\n\t\t\t \t\t \t \t\t\t \t \t\t \t\t\t \t", "n, m = map(int, input().split())\ns1 = {input() for x in range(n)}\ns2 = {input() for y in range(m)}\ns3 = s1 & s2\nif len(s3) % 2 == 0:\n turn = 0\nelse:\n turn = 1\nln1 = len(s1) - len(s3)\nln2 = len(s2) - len(s3)\n\nif ln1 > ln2 or ln1 == ln2 and turn == 1:\n print('YES')\nelif ln2 > ln1 or ln1 == ln2 and turn == 0:\n print('NO')\n", "from math import inf,sqrt,floor,ceil\r\nfrom collections import Counter,defaultdict,deque\r\nfrom heapq import heappush as hpush,heappop as hpop,heapify as h\r\nfrom operator import itemgetter\r\nfrom itertools import product\r\nfrom bisect import bisect_left,bisect_right\r\n\r\n\r\n#for _ in range(int(input())):\r\n#n=int(input())\r\nn,m=map(int,input().split( ))\r\ns1,s2=set(),set()\r\nfor v in range(n):\r\n s1.add(input())\r\nfor v in range(m):\r\n s2.add(input())\r\nif not (len(s1.intersection(s2))&1):\r\n if n>m:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n if n>=m:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\n \r\n ", "n, m = map(int, input().split())\r\na = {input() for i in range(n)}\r\nb = {input() for i in range(m)}\r\nboth = len(a&b)\r\nif both%2==1: n+=1\r\nprint(\"YES\") if n>m else print(\"NO\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "import sys, itertools\r\n\r\nn, m = map(int, sys.stdin.readline().split())\r\npol = set()\r\nene = set()\r\nfor _ in range(n):\r\n pol.add(sys.stdin.readline().rstrip())\r\nfor _ in range(m):\r\n ene.add(sys.stdin.readline().rstrip())\r\ntemp = pol.intersection(ene)\r\npol = pol.difference(temp)\r\nene = ene.difference(temp)\r\ncommon_pol = len(temp) // 2 if len(temp) % 2 == 0 else len(temp) // 2 + 1\r\ncommon_ene = len(temp) - common_pol\r\nprint('YES' if common_pol + len(pol) > common_ene + len(ene) else 'NO')\r\n", "times = input()\n\n(time1, time2) = times.split(\" \")\n\ncounted_words = set()\n\nrepeated = 0\nwords1 = 0\nwords2 = 0\n\nfor _ in range(int(time1)):\n word = input().strip()\n words1 += 1\n\n counted_words.add(word)\n\nfor _ in range(int(time2)):\n word = input().strip()\n words2 += 1\n\n if word in counted_words:\n repeated += 1\n\nif repeated % 2 == 1:\n words2 -= 1\n\n\nif words1 > words2:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t \t \t\t\t \t\t\t\t \t \t \t \t", "pol_and_ene = map(int, input().split())\n\ntemporary_list = list(pol_and_ene)\n\npol = temporary_list[0]\nene = temporary_list[1]\n\nword1 = []\nword2 = []\n\nfor i in range(1, pol+1):\n string = input()\n if len(string)<=500:\n word1.append(string) \n\nfor j in range(1, ene+1):\n string2 = input()\n if len(string)<=500:\n word2.append(string2)\n\ncompare = list(set(word1).intersection(word2))\n\n\n\nif pol > ene:\n print(\"YES\")\nelif ene > pol:\n print(\"NO\")\nelif pol == ene: \n if len(compare)%2==0:\n print(\"NO\")\n elif len(compare)%2!=0:\n print(\"YES\")\n \t\t \t \t\t\t\t \t \t\t\t \t\t\t \t\t", "n, m = map(int, input().split())\r\nwords_1 = {input() for _ in range(n)}\r\nwords_2 = {input() for _ in range(m)}\r\n \r\nprint('YES' if n > m or n == m and len(words_1 & words_2) % 2 else 'NO')", "n,m = map(int, input().split(' '))\nPolandBall = set()\nEnemyBall = set()\nboth = set()\n\nfor i in range(n):\n PolandBall.add(input())\n\nfor i in range (m):\n word = input()\n EnemyBall.add(word)\n if word in PolandBall:\n both.add(word)\n\nif (len(both)%2 != 0):\n n += 1\n\nprint('YES') if (n>m) else print('NO')\n \t\t \t \t\t\t\t\t \t \t \t \t\t\t\t \t \t", "def main():\r\n allNums = set()\r\n p,e = input().split()\r\n p,e = int(p), int(e)\r\n tot = p + e\r\n \r\n for i in range(tot):\r\n val = input()\r\n allNums.add(val)\r\n \r\n if tot > len(allNums):\r\n common = p+e - len(allNums)\r\n p-= common\r\n e -= common\r\n \r\n if common % 2 == 1:\r\n p += (common//2) + 1\r\n e += (common//2)\r\n else:\r\n p += (common//2)\r\n e += (common//2)\r\n if p > e:\r\n print('YES')\r\n else:\r\n print('NO')\r\nmain()\r\n", "from collections import defaultdict\r\nn, m = map(int, input().split())\r\nd1 = defaultdict(lambda: 0)\r\nd2 = defaultdict(lambda: 0)\r\nfor i in range(n):\r\n s = input()\r\n d1[s] = 1\r\nfor i in range(m):\r\n s = input()\r\n d2[s] = 1\r\ncommon = 0\r\nlength = [len(d1), len(d2)]\r\nfor key in d1.keys():\r\n if d2[key] == 1:\r\n common += 1\r\nct1 = common//2\r\nif(common & 1):\r\n ct1 += 1\r\nct1 += length[0]-common\r\nct2 = common//2\r\nct2 += length[1]-common\r\nif ct1 > ct2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n,m = map(int,input().split())\r\npo = []\r\nen = []\r\nfor i in range(n) :\r\n s = input()\r\n po.append(s)\r\n\r\nfor i in range(m) :\r\n s = input()\r\n en.append(s)\r\n\r\ncommon = set(po).intersection(en)\r\n\r\nif(len(common)%2 == 0) :\r\n if(m >= n) :\r\n print(\"NO\")\r\n else :\r\n print(\"YES\")\r\n\r\nelse :\r\n if(m > n) :\r\n print(\"NO\")\r\n else :\r\n print(\"YES\")\r\n", "try:\r\n nm = list(map(int, input().split()))\r\n n = nm[0]\r\n m = nm[1]\r\n s1 = [input() for i in range(n)]\r\n s2 = [input() for i in range(m)]\r\n k = 0\r\n for i in s1:\r\n if i in s2:\r\n k += 1\r\n if k & 1:\r\n if n >= m:\r\n print('YES')\r\n else:\r\n print('NO')\r\n else:\r\n if n <= m:\r\n print('NO')\r\n else:\r\n print('YES')\r\nexcept:\r\n pass", "def read_set(size):\r\n result = set()\r\n for _ in range(size):\r\n result.add(input())\r\n return result\r\n\r\ndef solve(words1, words2):\r\n both_count = len(words1.intersection(words2))\r\n only_count1 = len(words1) - both_count\r\n only_count2 = len(words2) - both_count\r\n return only_count1 + both_count % 2 > only_count2\r\n\r\nif __name__ == \"__main__\":\r\n n, m = map(int, input().split())\r\n words1 = read_set(n)\r\n words2 = read_set(m)\r\n print(\"YES\" if solve(words1, words2) else \"NO\")", "n, m = map(int, input().split())\n\npoland = set()\nenemy = set()\nfor i in range(n+m):\n\ts = input()\n\tif i >= n:\n\t\tenemy.add(s)\n\t\t\n\telse:\n\t\tpoland.add(s)\n\nscore_poland = 0\nscore_enemy = 0\nequals = 0\nfor word in poland:\n\tif word in enemy:\n\t\tequals += 1\n\t\t\nscore_poland = len(poland) - equals + equals//2 + equals % 2\nscore_enemy = len(enemy) - equals + equals//2\n\nif score_poland > score_enemy:\n\tprint('YES')\n\t\nelse:\n\tprint('NO')\n\n \t\t \t \t\t\t\t \t\t \t \t \t \t\t\t\t", "a , b = map(int , input().split())\r\narr = set()\r\nbrr = set()\r\n\r\nfor _ in range(a): arr.add(input())\r\nfor _ in range(b): brr.add(input())\r\n\r\ncrr = arr.intersection(brr)\r\nx = len(crr)%2\r\n\r\narr = arr.difference(crr)\r\nbrr = brr.difference(crr)\r\n\r\n\r\n\r\nif x == 0:\r\n if len(arr) > len(brr):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\nelse:\r\n if len(arr) >= len(brr):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "def find_k(arr1, arr2):\n return len(set(arr1) & set(arr2))\n\ndef solve(n, m, k):\n n += k % 2\n print('YES' if n > m else 'NO')\n\nn, m = map(int, input().split())\narr1 = [input() for _ in range(n)]\narr2 = [input() for _ in range(m)]\nsolve(n, m, find_k(arr1, arr2))\n", "n, m = list(map(int, input().split()))\r\nword = set()\r\nfor i in range(n+m):\r\n tmp = input()\r\n word.add(tmp)\r\n\r\ncommon = n + m - len(word)\r\n\r\nn -= common\r\nm -= common\r\nif common & 1:\r\n n += common // 2 + 1\r\nelse:\r\n n += common // 2\r\nm += common // 2\r\nif n > m:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "x, y = [int(x) for x in input().split()]\r\n\r\nlisx = []\r\n\r\nfor i in range(x):\r\n pala = str(input())\r\n lisx.append(pala)\r\n\r\nlisy = []\r\n\r\nfor i in range(y):\r\n pala = str(input())\r\n lisy.append(pala)\r\n\r\niguais = 0\r\n\r\nfor i in lisx:\r\n if i in lisy:\r\n iguais += 1\r\n\r\nif iguais % 2 == 0:\r\n if x > y:\r\n print('YES')\r\n else:\r\n print('NO')\r\n\r\nelse:\r\n if x+1 > y:\r\n print('YES')\r\n else:\r\n print('NO')", "import sys\r\n\r\ninput = lambda: sys.stdin.readline().strip()\r\n\r\nn, m = map(int, input().split())\r\n\r\npol, com = set(), 0\r\n\r\nfor _ in range(n):\r\n pol.add(input())\r\n\r\nfor _ in range(m):\r\n com += input() in pol\r\n\r\nn += com & 1\r\n\r\nif n > m:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n,m=[int(e) for e in input().split()]\r\na={input() for i in range(n)}\r\nb={input() for i in range(m)}\r\nif (len(a&b)+1)//2+len(a-b)>len(a&b)//2+len(b-a):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import math\n\nn, m = input().split()\nn = int(n)\nm = int(m)\nwa = []\nwb = []\n\nfor i in range(n):\n wa.append(input())\nfor i in range(m):\n wb.append(input())\n\ncnt = 0\nfor el in wa:\n if el in wb:\n cnt += 1\n \nsa = len(wa) - math.floor(cnt/2)\nsb = len(wb) - math.ceil(cnt/2)\n\nif sa > sb:\n print('YES')\nelse:\n print('NO')\n\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())\n \na = []\n \nfor i in range(n + m):\n a.append(input())\n \nst = set(a)\n \nif len(st) % 2 == 0 :\n if n <= m:\n print('NO')\n \n else:\n print('YES')\n \nelse:\n if n >= m :\n print('YES')\n \n else:\n print('NO')\n \t \t \t\t\t\t \t\t\t\t\t\t\t\t\t\t\t\t \t\t\t\t", "# f = open('input.txt')\nn, m = map(int, input().split())\ns1 = set([input() for _ in range(n)])\ns2 = set([input() for _ in range(m)])\nif len(s1 & s2) & 1:\n\tn += 1\nprint(\"NO\" if n <= m else \"YES\")\n \t \t\t\t\t\t \t \t \t\t \t\t\t \t \t\t", "nm = list(map(int,input().split()))\nn, m = nm[0], nm[1]\n\na = n + m\nset = set()\nfor i in range(a):\n v = input()\n set.add(v)\n\na = n + m - len(set)\n\nout = ''\nif n > m:\n out = 'YES'\nelif n < m:\n out = 'NO'\nelif a % 2:\n out = 'YES'\nelse:\n out = 'NO'\n\nprint(out)\n \t\t\t \t\t \t \t\t \t \t\t\t\t\t\t\t", "x = list(map(int,input().strip().split()))[:2]\n\nresp = \"NO\"\n\npol = set()\nen = set()\n\nfor i in range(x[0]):\n palavra = input()\n pol.add(palavra)\n\nfor i in range(x[1]):\n palavra = input()\n en.add(palavra)\n\ndif1 = pol - en\ndif2 = en - pol\n\ninter = pol.intersection(en)\n\npont_pol = len(dif1)\npont_en = len(dif2)\n\nif (len(inter) % 2 == 0):\n metade = len(inter)//2\n pont_pol += metade\n pont_en += metade\n\nelse:\n metade = len(inter)//2\n pont_en += metade\n metade2 = len(inter)-metade\n pont_pol += metade2\n\nif (pont_pol > pont_en):\n resp = \"YES\"\n\nprint(resp)\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\na=[]\r\nb=[]\r\nfor i in range(n+m):\r\n a.append(input())\r\nb=list(set(a))\r\nif len(b)%2==1:\r\n if n>=m:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n if n<=m:\r\n print('NO')\r\n else:\r\n print('YES')", "polandball_num, enemyball_num = map(int, input().split())\npolandball_set, enemyball_set = set(), set()\nfor _ in range(polandball_num):\n polandball_set.add(input())\nfor _ in range(enemyball_num):\n enemyball_set.add(input())\ncommon_words_count = len(polandball_set & enemyball_set)\nunique_word_difference = len(polandball_set - enemyball_set) - len(enemyball_set - polandball_set)\nresult = unique_word_difference >= 0 \\\n if common_words_count % 2 and unique_word_difference == 0 \\\n else unique_word_difference > 0\nprint('YES' if result else 'NO')\n", "n, m = map(int, input().split())\r\n\r\npoland = set()\r\nenemy = set()\r\nfor i in range(n+m):\r\n\ts = input()\r\n\tif i >= n:\r\n\t\tenemy.add(s)\r\n\t\t\r\n\telse:\r\n\t\tpoland.add(s)\r\n\r\nscore_poland = 0\r\nscore_enemy = 0\r\nequals = 0\r\nfor word in poland:\r\n\tif word in enemy:\r\n\t\tequals += 1\r\n\t\t\r\nscore_poland = len(poland) - equals + equals//2 + equals % 2\r\nscore_enemy = len(enemy) - equals + equals//2\r\n\r\nif score_poland > score_enemy:\r\n\tprint('YES')\r\n\t\r\nelse:\r\n\tprint('NO')\r\n", "# cook your dish here\r\nn, m = map(int, input().split())\r\np = []\r\nfor _ in range(n):\r\n p.append(input())\r\ne = []\r\nfor _ in range(m):\r\n e.append(input())\r\nif n > m:\r\n print(\"YES\")\r\nelif m > n:\r\n print(\"NO\")\r\nelse:\r\n if ((n+m) - len(set(p+e)))%2==0:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")", "polland_ball, enemy_ball = map(int, input().split())\n\npalavras_polland = set()\npalavras_enemy = set()\n\nfor i in range(polland_ball):\n palavras_polland.add(str(input()))\n\nfor i in range(enemy_ball):\n palavras_enemy.add(str(input()))\n\n# Os jogadores vão iniciar com palavras que ambos conhecem.\npalavras_em_comum = palavras_polland.intersection(palavras_enemy)\n\npalavras_distintas_polland = palavras_polland.difference(palavras_em_comum)\npalavras_distintas_enemy = palavras_enemy.difference(palavras_em_comum)\n\npolland_venceu = \"\"\nif len(palavras_em_comum) % 2 == 0: # Empate momentâneo.\n if len(palavras_distintas_polland) > len(palavras_distintas_enemy):\n polland_venceu = \"YES\"\n else:\n polland_venceu = \"NO\"\nelse: # No momento o Polland está vencendo por 1.\n if len(palavras_distintas_enemy) - len(palavras_distintas_polland) > 0: # Enemy empatou ou venceu.\n polland_venceu = \"NO\"\n else:\n polland_venceu = \"YES\"\n\nprint(polland_venceu)\n\n\t \t \t \t\t\t\t\t\t \t \t\t\t \t", "\ndef solve():\n n, m = [int(x) for x in input().split()]\n if m > n:\n print(\"NO\")\n return\n elif n > m:\n print(\"YES\")\n return\n a = []\n for _ in range(n):\n a.append(input())\n a.sort()\n counter = 0\n for _ in range(m):\n if input() in a:\n counter += 1\n if counter & 1:\n if n+1 > m:\n print(\"YES\")\n else:\n print(\"NO\")\n\n else:\n if m >= n:\n print(\"NO\")\n else:\n print(\"YES\")\n\n\nsolve()\n", "n,m=map(int,input().split())\r\nc=n+m-len({input() for i in range(n)}|{input() for i in range(m)})\r\nprint('YNEOS'[n+c%2<=m::2])\r\n", "from sys import stdin\n\n\ndef ler():\n for line in stdin:\n yield line\n\n\ndef solve(s):\n x, y = [int(i) for i in next(s).split()]\n\n listax = [next(s) for i in range(x)]\n repetidas = 0\n listay = 0\n for i in range(y):\n a = next(s)\n if a in listax:\n repetidas += 1\n else:\n listay += 1\n\n listax = x - repetidas\n\n if repetidas % 2 == 0:\n return listax > listay\n\n return listax >= listay\n\n\ns = ler()\nres = solve(s)\nif res:\n print('YES')\nelse:\n print('NO')\n\n \t \t\t\t\t \t\t \t \t\t\t \t\t \t\t\t\t \t\t" ]
{"inputs": ["5 1\npolandball\nis\na\ncool\ncharacter\nnope", "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "1 2\na\na\nb", "2 2\na\nb\nb\nc", "2 1\nc\na\na", "3 3\nab\nbc\ncd\ncd\ndf\nfg", "3 3\nc\na\nb\na\nd\ng", "1 1\naa\naa", "2 1\na\nb\na", "6 5\na\nb\nc\nd\ne\nf\nf\ne\nd\nz\ny", "3 2\na\nb\nc\nd\ne"], "outputs": ["YES", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES"]}
UNKNOWN
PYTHON3
CODEFORCES
131
151f68a26da83524d8b82f40c7e8092c
Group Photo 2 (online mirror version)
Many years have passed, and *n* friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the photo. Simply speaking, the process of photographing can be described as follows. Each friend occupies a rectangle of pixels on the photo: the *i*-th of them in a standing state occupies a *w**i* pixels wide and a *h**i* pixels high rectangle. But also, each person can lie down for the photo, and then he will occupy a *h**i* pixels wide and a *w**i* pixels high rectangle. The total photo will have size *W*<=×<=*H*, where *W* is the total width of all the people rectangles, and *H* is the maximum of the heights. The friends want to determine what minimum area the group photo can they obtain if no more than *n*<=/<=2 of them can lie on the ground (it would be strange if more than *n*<=/<=2 gentlemen lie on the ground together, isn't it?..) Help them to achieve this goal. The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of friends. The next *n* lines have two integers *w**i*,<=*h**i* (1<=≤<=*w**i*,<=*h**i*<=≤<=1000) each, representing the size of the rectangle, corresponding to the *i*-th friend. Print a single integer equal to the minimum possible area of the photo containing all friends if no more than *n*<=/<=2 of them can lie on the ground. Sample Input 3 10 1 20 2 30 3 3 3 1 2 2 4 3 1 5 10 Sample Output 180 21 50
[ "n = int(input())\r\nw, h = [0]*n, [0]*n\r\nfor i in range(n):\r\n w[i], h[i] = map(int, input().split())\r\n\r\n\r\ndef dientich(Hmax):\r\n k = n//2\r\n a = []\r\n for i in range(n):\r\n if h[i] > Hmax:\r\n if k <= 0 or w[i] > Hmax:\r\n return 10**9\r\n else:\r\n a.append((h[i], w[i]))\r\n k -= 1\r\n else:\r\n a.append((w[i], h[i]))\r\n a.sort(key=lambda u: u[1] - u[0])\r\n sumR = 0\r\n for wi, hi in a:\r\n if k > 0 and wi <= Hmax and hi < wi:\r\n sumR += hi\r\n k -= 1\r\n else:\r\n sumR += wi\r\n return sumR*Hmax\r\n\r\n\r\ndt = 10**9\r\nfor x in range(1, 1001):\r\n dt = min(dt, dientich(x))\r\nprint(dt)\r\n", "from operator import neg\nn = int(input())\na = [tuple(map(int, input().split())) for i in range(n)]\n\ndef check(max_h):\n k = n // 2\n b = []\n for w, h in a:\n if h > max_h:\n if k <= 0 or w > max_h:\n return 1 << 60\n b.append((h, w))\n k -= 1\n else:\n b.append((w, h))\n b.sort(key=lambda t: t[1] - t[0])\n r = 0\n for w, h in b:\n if k > 0 and w <= max_h and h < w:\n r += h\n k -= 1\n else:\n r += w\n return r * max_h\n\nprint(min(check(h) for h in range(1, 1001)))\n \n \n" ]
{"inputs": ["3\n10 1\n20 2\n30 3", "3\n3 1\n2 2\n4 3", "1\n5 10", "1\n1 1", "1\n1000 1000", "1\n1 1000", "2\n1 1000\n1000 1", "2\n1 1\n1000 1000", "1\n1000 1", "5\n407 830\n12 199\n768 215\n668 28\n628 310", "3\n379 820\n923 407\n916 853", "3\n99 768\n477 885\n169 118", "3\n227 612\n223 259\n423 895", "3\n651 161\n480 32\n485 672", "3\n779 301\n34 214\n442 937", "3\n203 145\n780 692\n992 713", "3\n627 286\n37 65\n53 490", "3\n755 938\n487 543\n307 459", "3\n475 487\n41 20\n368 236", "3\n922 71\n719 26\n462 700", "2\n881 4\n788 2", "2\n1 304\n8 892", "3\n227 2\n223 9\n423 5", "3\n7 612\n3 259\n3 895", "4\n573 7\n169 9\n447 7\n947 3", "10\n864 874\n534 702\n73 363\n856 895\n827 72\n435 468\n888 921\n814 703\n648 715\n384 781", "10\n489 685\n857 870\n736 221\n687 697\n166 360\n265 200\n738 519\n393 760\n66 176\n798 160", "1\n1 1", "1\n1000 1000", "1\n1 1000", "2\n1 1000\n1000 1", "2\n1 1\n1000 1000", "1\n1000 1", "2\n1 1\n1 1", "4\n3 817\n9 729\n7 407\n7 433", "3\n500 500\n2 1\n10 5"], "outputs": ["180", "21", "50", "1", "1000000", "1000", "2000", "1001000", "1000", "1070700", "1570946", "614190", "781335", "756672", "728049", "1366821", "235752", "1307660", "366224", "1013790", "6676", "8028", "7857", "11635", "19224", "4909752", "3231747", "1", "1000000", "1000", "2000", "1001000", "1000", "2", "21242", "253500"]}
UNKNOWN
PYTHON3
CODEFORCES
2
1542f4a09d6ddea98267a3b58425bbd5
Robot Rapping Results Report
While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots operate under deterministic algorithms. In particular, robot *i* will beat robot *j* if and only if robot *i* has a higher skill level than robot *j*. And if robot *i* beats robot *j* and robot *j* beats robot *k*, then robot *i* will beat robot *k*. Since rapping is such a subtle art, two robots can never have the same skill level. Given the results of the rap battles in the order in which they were played, determine the minimum number of first rap battles that needed to take place before Bessie could order all of the robots by skill level. The first line of the input consists of two integers, the number of robots *n* (2<=≤<=*n*<=≤<=100<=000) and the number of rap battles *m* (). The next *m* lines describe the results of the rap battles in the order they took place. Each consists of two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*), indicating that robot *u**i* beat robot *v**i* in the *i*-th rap battle. No two rap battles involve the same pair of robots. It is guaranteed that at least one ordering of the robots satisfies all *m* relations. Print the minimum *k* such that the ordering of the robots by skill level is uniquely defined by the first *k* rap battles. If there exists more than one ordering that satisfies all *m* relations, output -1. Sample Input 4 5 2 1 1 3 2 3 4 2 4 3 3 2 1 2 3 2 Sample Output 4 -1
[ "def g(k):\r\n p = [[] for i in range(n)]\r\n d = [0] * n\r\n for u, v in t[:k]:\r\n p[u].append(v)\r\n d[v] += 1\r\n if d.count(0) > 2: return 0\r\n x = d.index(0, 1)\r\n while x:\r\n q, x = p[x], 0\r\n for y in q:\r\n d[y] -= 1\r\n if d[y] == 0:\r\n if x: return 0\r\n x = y\r\n return 1\r\nf = lambda: map(int, input().split())\r\nn, m = f()\r\nt = [list(f()) for i in range(m)]\r\nn += 1\r\nm += 1\r\nl, r = 1, m\r\nwhile l < r:\r\n s = l + r >> 1\r\n if g(s): r = s\r\n else: l = s + 1\r\nprint(-1 if r == m else l)", "from heapq import heappop,heappush\n\nn,m = map(int,input().split())\n\nC = [[] for _ in range(n)]\nindeg = [0]*n\n\ndef toposort():\n S = [i for i in range(n) if indeg[i] == 0]\n nparent = indeg[:]\n topo = []\n while S:\n cur = S.pop()\n topo.append(cur)\n for neigh,_ in C[cur]:\n nparent[neigh] -= 1\n if nparent[neigh] == 0:\n S.append(neigh)\n return topo\n\ndef solve():\n topo = toposort()\n\n D = [(0,0)]*n\n for cur in topo:\n for neigh,t in C[cur]:\n cd,ct = D[cur]\n nd,_ = D[neigh]\n if nd <= cd + 1:\n D[neigh] = cd + 1, max(ct,t)\n\n d,t = max(D)\n return t+1 if d == n-1 else -1\n \n\nfor _ in range(m):\n a,b = map(int,input().split())\n C[a-1].append((b-1, _))\n indeg[b-1] += 1\n\nprint(solve())\n", "n, m = [int(i) for i in input().split()]\nn += 1 # one-indexed\nA = [[int(i) for i in input().split()] for j in range(m)]\nm += 1\n\ndef check(upper):\n p = [[] for i in range(n)]\n d = [0] * n #record num of parents\n for u, v in A[:upper]:\n p[u].append(v) # form arc from u to v\n d[v] += 1\n if d.count(0) > 2:\n return False\n x = d.index(0, 1) # find the real ancestor, should only be one\n while x:\n q, x = p[x], 0\n for y in q:\n d[y] -= 1\n if d[y] == 0:\n if x: \n return False\n x = y\n return True\n\nleft, right = 1, m\nwhile left < right:\n mid = (left + right)//2\n if check(mid): \n right = mid\n else:\n left = mid + 1 \nif check(left):\n print(left)\nelse:\n print(-1)\n\t\t\t \t\t \t \t \t\t \t\t\t \t\t \t", "from sys import stdin\n\n\ndef main():\n def f(k):\n g, cnt = [[] for _ in range(n)], [0] * n\n for u, v in data[:k]:\n g[u].append(v)\n cnt[v] += 1\n if cnt.count(0) > 1:\n return False\n w, u = cnt.index(0), -1\n while u != w:\n u = w\n for v in g[u]:\n cnt[v] -= 1\n if not cnt[v]:\n if u != w:\n return False\n w = v\n return True\n\n n, m = map(int, input().split())\n data = stdin.read().splitlines()\n for i, s in enumerate(data):\n u, v = map(int, s.split())\n data[i] = (u - 1, v - 1)\n lo, hi = n - 1, m + 1\n while lo < hi:\n mid = (lo + hi) // 2\n if f(mid):\n hi = mid\n else:\n lo = mid + 1\n print(-1 if hi > m else lo)\n\n\nif __name__ == '__main__':\n main()\n", "from sys import stdin, stdout\r\nimport sys\r\nimport bisect\r\nimport heapq\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef solve(n, m, edges):\r\n \r\n lo = 0\r\n hi = m\r\n\r\n curr_k = -1\r\n\r\n while lo <= hi:\r\n mid = lo + (hi - lo) // 2\r\n\r\n can_do = True\r\n\r\n # condition\r\n\r\n adj_list = {x: [] for x in range(0, n)}\r\n in_degree = [0] * n\r\n for ed in range(min(mid, len(edges))):\r\n edge = edges[ed]\r\n adj_list[edge[0]].append(edge[1])\r\n in_degree[edge[1]] += 1\r\n candidates = []\r\n for i in range(len(in_degree)):\r\n if in_degree[i] == 0:\r\n candidates.append(i)\r\n res = []\r\n while candidates:\r\n ele = candidates.pop(0)\r\n if len(candidates) > 0:\r\n can_do = False\r\n break\r\n res.append(ele)\r\n for i in adj_list[ele]:\r\n in_degree[i] -= 1\r\n if in_degree[i] == 0:\r\n candidates.append(i)\r\n \r\n if len(res) < n:\r\n can_do = False\r\n\r\n if can_do:\r\n curr_k = mid\r\n hi = mid - 1\r\n else:\r\n lo = mid + 1\r\n\r\n return curr_k\r\n\r\ndef main():\r\n n, m = map(int, input().split())\r\n \r\n edges = []\r\n for i in range(m):\r\n a, b = map(int, input().split())\r\n edges.append([a - 1, b - 1])\r\n stdout.write(str(solve(n, m, edges)))\r\n stdout.write(\"\\n\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "from collections import defaultdict,deque\r\ndef bfs(q,n,mid):\r\n\tg=defaultdict(list)\r\n\tvis=[0]*(n)\r\n\tfor i in range(mid):\r\n\t\tx,y=q[i]\r\n\t\tg[x].append(y)\r\n\t\tvis[y]+=1\r\n\tq=deque()\r\n\tfor i in range(n):\r\n\t\tif vis[i]==0:\r\n\t\t\tq.append(i)\r\n\tflag=True\r\n\tcnt=0\r\n\twhile q and flag:\r\n\t\t# print(q)\r\n\t\tif len(q)!=1 : # ek se zyada winner us pos ke liye\r\n\t\t\tflag=False\r\n\t\tt=q.popleft()\r\n\t\tcnt+=1\r\n\t\tfor i in g[t]:\r\n\t\t\tvis[i]-=1\r\n\t\t\tif vis[i]==0:\r\n\t\t\t\tq.append(i)\r\n\treturn cnt==n and flag==True\r\n\r\ndef f(q,n):\r\n\tlo=0\r\n\thi=len(q)\r\n\tans=-1\r\n\twhile lo<=hi:\r\n\t\tmid=(lo+hi)//2\r\n\t\tif bfs(q,n,mid):\r\n\t\t\tans=mid\r\n\t\t\thi=mid-1\r\n\t\telse:\r\n\t\t\tlo=mid+1\r\n\treturn ans\r\nq=[]\r\nn,m=map(int,input().strip().split())\r\nfor _ in range(m):\r\n\tx,y=map(int,input().strip().split())\r\n\tq.append((x-1,y-1))\r\nprint(f(q,n))" ]
{"inputs": ["4 5\n2 1\n1 3\n2 3\n4 2\n4 3", "3 2\n1 2\n3 2", "2 1\n1 2", "2 1\n2 1", "5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5", "3 3\n2 1\n3 1\n3 2", "4 6\n1 4\n4 2\n2 3\n1 2\n1 3\n4 3", "3 3\n3 1\n3 2\n1 2", "5 10\n2 1\n1 4\n2 5\n2 3\n5 4\n3 4\n3 1\n3 5\n2 4\n1 5", "3 3\n1 2\n3 2\n1 3", "3 3\n2 3\n1 3\n2 1", "3 3\n1 2\n3 1\n3 2", "3 3\n1 3\n3 2\n1 2", "5 10\n4 1\n4 5\n2 1\n2 5\n4 3\n3 1\n4 2\n2 3\n3 5\n5 1", "5 8\n5 1\n1 3\n5 3\n2 3\n4 1\n4 3\n2 1\n5 4", "5 10\n2 1\n5 2\n3 2\n3 1\n5 4\n3 4\n4 2\n5 1\n4 1\n5 3", "2 1\n2 1", "5 10\n4 3\n4 1\n2 1\n1 3\n5 1\n5 3\n5 4\n2 5\n2 3\n2 4", "5 10\n2 5\n1 5\n2 3\n1 4\n5 4\n3 4\n3 1\n2 1\n3 5\n2 4", "13 78\n10 2\n6 5\n5 7\n10 3\n6 13\n4 7\n4 13\n1 12\n13 2\n1 7\n10 5\n10 13\n12 2\n10 6\n5 3\n10 8\n9 11\n6 1\n4 5\n12 3\n6 7\n8 2\n1 9\n4 11\n5 8\n6 3\n9 5\n5 2\n13 11\n10 4\n12 7\n5 13\n12 8\n10 12\n6 12\n5 11\n1 8\n7 8\n12 4\n10 7\n1 5\n1 2\n10 11\n2 11\n12 13\n9 7\n8 3\n12 9\n9 2\n6 9\n10 9\n7 11\n12 5\n4 8\n9 8\n4 3\n6 4\n6 11\n6 8\n1 13\n8 11\n1 3\n9 13\n9 4\n1 4\n2 3\n4 2\n6 2\n7 13\n1 11\n12 11\n7 2\n8 13\n9 3\n13 3\n3 11\n10 1\n7 3", "5 10\n3 4\n3 2\n3 5\n1 4\n2 4\n5 1\n3 1\n5 4\n2 1\n2 5", "7 21\n5 7\n6 7\n2 7\n1 3\n6 2\n6 3\n2 3\n6 1\n4 2\n6 4\n4 5\n4 7\n6 5\n5 2\n1 7\n7 3\n4 1\n2 1\n5 1\n4 3\n5 3"], "outputs": ["4", "-1", "1", "1", "10", "3", "3", "3", "10", "3", "3", "2", "2", "10", "-1", "10", "1", "8", "7", "76", "10", "18"]}
UNKNOWN
PYTHON3
CODEFORCES
6
1559308881797ee2f5f8be601e158dd4
Polycarp's phone book
There are *n* phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for which there is a substring equal to the entered sequence of digits. For example, is there are three phone numbers in Polycarp's contacts: 123456789, 100000000 and 100123456, then: - if he enters 00 two numbers will show up: 100000000 and 100123456, - if he enters 123 two numbers will show up 123456789 and 100123456, - if he enters 01 there will be only one number 100123456. For each of the phone numbers in Polycarp's contacts, find the minimum in length sequence of digits such that if Polycarp enters this sequence, Berdroid shows this only phone number. The first line contains single integer *n* (1<=≤<=*n*<=≤<=70000) — the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. Print exactly *n* lines: the *i*-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the *i*-th number from the contacts. If there are several such sequences, print any of them. Sample Input 3 123456789 100000000 100123456 4 123456789 193456789 134567819 934567891 Sample Output 9 000 01 2 193 81 91
[ "\r\n\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\r\nfrom bisect import bisect_left as bl, bisect_right as br\r\nfrom random import randint\r\nfrom math import gcd, ceil, floor\r\nrandom = randint(1, 10 ** 9)\r\nclass wrapper(int):\r\n def __hash__(self):\r\n return super(wrapper, self).__hash__() ^ random\r\n\r\nn=ri()\r\nd=defaultdict(int)\r\nq=[]\r\nfor i in range(n):\r\n s=rs()\r\n q.append(s)\r\n st=set()\r\n for j in range(9):\r\n for k in range(j,9):\r\n st.add(s[j:k+1])\r\n for pp in st:\r\n d[pp]+=1\r\n\r\nfor i in range(n):\r\n mx=9\r\n ans=q[i]\r\n s=q[i]\r\n for j in range(9):\r\n for k in range(j,9):\r\n t=s[j:k+1]\r\n if d[t]==1:\r\n if mx>len(t):\r\n ans=t\r\n mx=len(ans)\r\n print(ans)\r\n", "n = int(input())\r\n\r\ndta = dict()\r\nans = ['0' * 10 for i in range(n)]\r\nbad = set()\r\n\r\nfor i in range(n):\r\n s = input()\r\n for ln in range(1, 10):\r\n for j in range(0, 9 - ln + 1):\r\n key = s[j:j + ln]\r\n if key in bad:\r\n continue\r\n\r\n if dta.get(key, i) != i:\r\n # if ans[dta[key]] == key:\r\n # ans[dta[key]] = ''\r\n dta.pop(key)\r\n bad.add(key)\r\n else:\r\n dta[key] = i\r\n # if not ans[i]:\r\n # ans[i] = key\r\nfor key, i in dta.items():\r\n ans[i] = min(key, ans[i], key=lambda x: len(x))\r\n\r\nfor i in ans:\r\n print(i)\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nmp = {}\r\nls = []\r\n\r\nfor _ in range(n):\r\n a = input().strip()\r\n ls.append(a)\r\n z = set()\r\n for i in range(len(a)):\r\n for j in range(i, len(a)):\r\n y = a[i:j + 1]\r\n if y in z:\r\n continue\r\n\r\n mp[y] = mp.get(y, 0) + 1\r\n z.add(y)\r\n\r\n\r\nfor k in range(n):\r\n b = []\r\n a = ls[k]\r\n for i in range(len(a)):\r\n for j in range(i, len(a)):\r\n y = a[i:j + 1]\r\n b.append(y)\r\n \r\n b.sort(key=lambda x: len(x))\r\n\r\n for j in b:\r\n if mp[j] == 1:\r\n print(j)\r\n break", "\r\nimport math\r\nfrom collections import *\r\na=int(input())\r\nindx=defaultdict(list)\r\ndone=defaultdict(list)\r\nfor t in range(a):\r\n s=input()\r\n for i in range(len(s)):\r\n for j in range(i,len(s)):\r\n m=s[i:j+1]\r\n \r\n if(len(done[m])==0):\r\n done[m].append(t)\r\n indx[t].append(m)\r\n else:\r\n if(len(done[m])==1 and done[m][0]!=math.inf and t!=done[m][0]):\r\n indx[done[m][0]].remove(m)\r\n done[m][0]=math.inf\r\n \r\n \r\nfor i in range(a):\r\n af=indx[i]\r\n \r\n mini=15\r\n ss=''\r\n for i in range(len(af)):\r\n if(len(af[i])<mini):\r\n mini=len(af[i])\r\n ss=af[i]\r\n print(ss)\r\n \r\n\r\n\r\n \r\n \r\n", "n = int(input())\r\n\r\nres = ['1111111111111'] * n\r\nmention = dict()\r\nfor i in range(n):\r\n s = input()\r\n curotr = set()\r\n for ln in range(1, 10):\r\n for st in range(0, 9 - ln + 1):\r\n key = s[st: ln + st]\r\n if key in mention and mention[key] != i:\r\n mention[key] = -1\r\n else:\r\n mention[key] = i\r\n\r\nfor key, val in mention.items():\r\n if val != -1:\r\n res[val] = min(res[val], key, key=lambda x: len(x))\r\nfor i in res:\r\n print(i)", "import sys\r\nfrom collections import defaultdict\r\n\r\n\r\n\r\nN = int(input())\r\nS = []\r\nSubs = defaultdict(int)\r\nfor i in range(N):\r\n s = input()\r\n S.append(s)\r\n for ff in range(1,10):\r\n for ss in range(10-ff):\r\n Subs[s[ss:ss+ff]] += 1\r\n\r\nfor i in range(N):\r\n flag = 0\r\n At = S[i]\r\n for ff in range(1,10):\r\n curr = defaultdict(int)\r\n for ss in range(10-ff):\r\n curr[At[ss:ss+ff]] += 1\r\n # Here we check\r\n for key in curr.keys():\r\n if(curr[key] == Subs[key]):\r\n print(key)\r\n flag = 1\r\n break\r\n if(flag):\r\n break\r\n\r\n \r\n", "n = int(input())\nalls = {}\ndata = []\nfor _ in range(n):\n x = input()\n for i in range(9):\n for j in range(i, 9):\n if x[i:j + 1] not in alls.keys():\n alls[x[i:j + 1]] = 1\n else:\n alls[x[i:j + 1]] += 1\n data.append(x)\n\nfor string in data:\n subdata = {}\n for i in range(9):\n for j in range(i, 9):\n if string[i:j + 1] not in subdata.keys():\n subdata[string[i:j + 1]] = 1\n else:\n subdata[string[i:j + 1]] += 1\n ans = 10 * '9'\n for key in subdata:\n if alls[key] - subdata[key] == 0:\n ans = min(ans, key, key=len)\n print(ans)\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nd = dict()\r\nfor i in range(n):\r\n s = input()[:-1]\r\n for j in range(9):\r\n for l in range(j, 9):\r\n if s[j:l+1] not in d:\r\n d[s[j:l+1]] = i\r\n elif d[s[j:l+1]] != i:\r\n d[s[j:l + 1]] = -1\r\n\r\nx = ['a']*n\r\nfor i in d:\r\n if d[i] != -1:\r\n if x[d[i]] == 'a':\r\n x[d[i]] = i\r\n else:\r\n if len(i) < len(x[d[i]]):\r\n x[d[i]] = i\r\n\r\nfor i in range(n):\r\n print(x[i])\r\n\r\n", "n = int(input())\r\nm = {}\r\na = []\r\nfor i in range(n):\r\n s = input()\r\n sub = set()\r\n for i in range(len(s)):\r\n for j in range(i, len(s)):\r\n k = s[i:j + 1]\r\n if k in sub:\r\n continue\r\n else:\r\n sub.add(k)\r\n if k in m:\r\n m[k] += 1\r\n else:\r\n m[k] = 1\r\n a.append(s)\r\n\r\nfor s in a:\r\n ans = s\r\n for i in range(len(s)):\r\n for j in range(i, len(s)):\r\n k = s[i:j + 1]\r\n if m[k] == 1 and len(k) < len(ans):\r\n ans = k\r\n print(ans)\r\n\r\n", "import sys,math,heapq,queue\r\nfast_input=sys.stdin.readline \r\nclass TrieNode:\r\n def __init__(self):\r\n self.childs=[None]*10\r\n self.count=0\r\n self.is_turn=False\r\n \r\nn=int(fast_input()) \r\na=[] \r\nroot=TrieNode()\r\nfor _ in range(n):\r\n x=input()\r\n a.append(x)\r\n for start in range(9):\r\n temp=root\r\n for end in range(start,9):\r\n v=ord(x[end])-ord('0')\r\n if temp.childs[v]==None:\r\n temp.childs[v]=TrieNode()\r\n if not temp.childs[v].is_turn:\r\n temp.childs[v].count+=1 \r\n temp.childs[v].is_turn=True \r\n temp=temp.childs[v]\r\n \r\n for start in range(9):\r\n temp=root\r\n for end in range(start,9):\r\n v=ord(x[end])-ord('0')\r\n temp.childs[v].is_turn=False\r\n temp=temp.childs[v] \r\nfor i in range(n):\r\n x=a[i] \r\n ans=9 \r\n idx=0 \r\n for start in range(9):\r\n temp=root \r\n for end in range(start,9):\r\n v=ord(x[end])-ord('0')\r\n if temp.childs[v].count==1:\r\n if end-start+1<ans:\r\n ans=end-start+1 \r\n idx=start \r\n break \r\n temp=temp.childs[v]\r\n print(x[idx:idx+ans])\r\n\r\n\r\n \r\n\r\n ", "class CodeforcesTask860BSolution:\n def __init__(self):\n self.result = ''\n self.n = 0\n self.phones = []\n\n def read_input(self):\n self.n = int(input())\n for x in range(self.n):\n self.phones.append(input())\n\n def process_task(self):\n phone_book = {}\n for phone in self.phones:\n for x in range(1, len(phone) + 1):\n for y in range(len(phone) - x + 1):\n subnum = phone[y:y + x]\n #print(phone, subnum, y, y + x, x)\n if subnum in phone_book.keys():\n if phone_book[subnum] != phone:\n phone_book[subnum] = False\n else:\n phone_book[subnum] = phone\n results = []\n for phone in self.phones:\n found = False\n for x in range(1, len(phone) + 1):\n for y in range(len(phone) - x + 1):\n subnum = phone[y:y + x]\n if subnum in phone_book.keys():\n if phone_book[subnum]:\n found = True\n results.append(subnum)\n break\n if found:\n break\n self.result = \"\\n\".join([str(x) for x in results])\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask860BSolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n", "# -*- coding: utf-8 -*-\r\n\r\nimport math\r\nimport collections\r\nimport bisect\r\nimport heapq\r\nimport time\r\nimport random\r\nimport itertools\r\n\r\n\"\"\"\r\ncreated by shhuan at 2017/10/19 11:21\r\n\r\n\"\"\"\r\n\r\nN = int(input())\r\nA = []\r\nfor i in range(N):\r\n A.append(input())\r\n#\r\n# N = 70000\r\n# A = [str(random.randint(10**9, 10**10-1)) for _ in range(N)]\r\n#\r\nvis = set()\r\ncad = {}\r\nfor k, a in enumerate(A):\r\n for s in [a[i:j] for i in range(9) for j in range(i+1, 10)]:\r\n if s in cad and cad[s] != k:\r\n cad.pop(s)\r\n if s not in vis:\r\n cad[s] = k\r\n vis.add(s)\r\nf = {}\r\nfor k,v in cad.items():\r\n if v not in f:\r\n f[v] = k\r\n else:\r\n if len(f[v]) > len(k):\r\n f[v] = k\r\n\r\nprint('\\n'.join([x[1] for x in sorted((k, v) for k,v in f.items())]))\r\n", "n=int(input())\r\nq={}\r\nz=[input() for i in range(n)]\r\nfor s in z:\r\n w=set()\r\n for i in range(len(s)):\r\n for j in range(i,len(s)):\r\n k=s[i:j+1]\r\n if k in w: continue\r\n else: w.add(k)\r\n if k in q: q[k]+=1\r\n else: q[k]=1\r\nfor s in z:\r\n r=s\r\n for i in range(len(s)):\r\n for j in range(i,len(s)):\r\n k=s[i:j+1]\r\n if q[k]==1 and len(k)<len(r): r=k\r\n print(r)", "def rec(i):\r\n global a\r\n return i\r\nimport sys\r\nfrom collections import Counter\r\nsys.setrecursionlimit(10**6)\r\nn=int(input())\r\n#n,m=list(map(int,input().split()))\r\na=[input() for i in range(n)]\r\nb=[]\r\na0=set()\r\nc0=set()\r\nfor i in a:\r\n c=set()\r\n for i0 in range(1,10):\r\n for i1 in range(0,10-i0):\r\n c.add(i[i1:i1+i0])\r\n b.append(c)\r\n c0.update(a0&c)\r\n a0.update(c)\r\n\r\nfor i in b:\r\n c=i-c0\r\n z='0'*10\r\n for i0 in c:\r\n if len(i0)<len(z):\r\n z=i0\r\n print(z)\r\n", "cnt = {}\r\n\r\nn = int(input())\r\nls = [input() for _ in range(n)]\r\n\r\nfor s in ls:\r\n subs = set()\r\n for end in range(10):\r\n for start in range(end):\r\n subs.add(s[start:end])\r\n for sub in subs:\r\n if sub not in cnt:\r\n cnt[sub] = 1\r\n else:\r\n cnt[sub] += 1\r\n\r\nfor s in ls:\r\n subs = set()\r\n for end in range(10):\r\n for start in range(end):\r\n subs.add(s[start:end])\r\n for sub in sorted(subs, key=len):\r\n if cnt[sub] == 1:\r\n print(sub)\r\n break\r\n", "n = int(input())\r\nnum = []\r\nfor i in range(n):\r\n num.append(input())\r\nd = {}\r\nq = []\r\nfor i in range(n):\r\n r = {}\r\n g = []\r\n for j in range(0, 9):\r\n for l in range(j+1, 10):\r\n t = num[i][j:l]\r\n g.append(t)\r\n if t in r:\r\n continue\r\n r[t] = 1\r\n if t in d:\r\n d[t] = d[t]+1\r\n else:\r\n d[t] = 1\r\n g.sort(key=len)\r\n q.append(g)\r\nif n == 1:\r\n print(num[0][0])\r\n exit(0)\r\nansw = []\r\nfor i in range(n):\r\n for j in q[i]:\r\n if d[j] == 1:\r\n answ.append(j)\r\n break\r\nfor i in answ:\r\n print(i)", "def add_subs(num, freq):\n used = set()\n\n for l in range(1, len(num) + 1):\n for i in range(len(num) - l + 1):\n end = i + l\n sub = num[i : end]\n\n if sub not in used:\n used.add(sub)\n if sub not in freq:\n freq[sub] = 1\n else:\n freq[sub] += 1\n\ndef count_subs(nums):\n freq = {}\n for n in nums:\n add_subs(n, freq)\n return freq\n\ndef find_sub(num, freq):\n for l in range(1, len(num)):\n for i in range(len(num) - l + 1):\n end = i + l\n sub = num[i : end]\n if freq[sub] == 1:\n return sub\n return num\n\ndef main():\n n = int(input())\n nums = [input() for i in range(n)]\n\n freq = count_subs(nums)\n for number in nums:\n print(find_sub(number, freq))\n\nmain()\n", "substr_counts = {}\r\nunique_substrings = set()\r\n\r\nn = int(input())\r\nnumbers = [input() for _ in range(n)]\r\n\r\nfor number in numbers:\r\n unique_substrings.clear()\r\n for j in range(9):\r\n for k in range(1, 10 - j):\r\n unique_substrings.add(number[j:j+k])\r\n\r\n for substring in unique_substrings:\r\n substr_counts[substring] = substr_counts.get(substring, 0) + 1\r\nresult = []\r\n\r\nfor number in numbers:\r\n done = False\r\n for j in range(1, 10):\r\n if done:\r\n break\r\n for k in range(10 - j):\r\n if substr_counts[number[k:k+j]] == 1:\r\n done = True\r\n result.append(number[k:k+j])\r\n break\r\nfor substr in result:\r\n print(substr)# 1698280326.1065145", "import sys\r\ninput=sys.stdin.readline\r\nn=int(input())\r\ns=[input().rstrip() for i in range(n)]\r\ncnt={}\r\nfor ss in s:\r\n subs=set()\r\n for r in range(10):\r\n for l in range(r):\r\n subs.add(ss[l:r])\r\n for sub in subs:\r\n if sub not in cnt:\r\n cnt[sub]=1\r\n else:\r\n cnt[sub]+=1\r\nfor ss in s:\r\n subs=set()\r\n for r in range(10):\r\n for l in range(r):\r\n subs.add(ss[l:r])\r\n subs=sorted(list(subs),key=lambda x:len(x))\r\n for t in subs:\r\n if cnt[t]==1:\r\n print(t)\r\n break", "n = int(input())\r\ns, p = {}, [''] * n\r\nfor k in range(n):\r\n p[k] =input()\r\n for q in [p[k][i: j] for i in range(9) for j in range(i + 1, 10)]:\r\n s[q] = -1 if q in s and s[q] != k else k\r\nfor q, k in s.items():\r\n if ~k and len(p[k]) > len(q):p[k] = q\r\nprint('\\n'.join(p))", "substr_counts = {}\r\nunique_substrings = set()\r\n\r\nn = int(input())\r\nwords = [input() for _ in range(n)]\r\n\r\nfor word in words:\r\n unique_substrings.clear()\r\n for j in range(9):\r\n for k in range(1, 10 - j):\r\n unique_substrings.add(word[j:j+k])\r\n\r\n for substring in unique_substrings:\r\n substr_counts[substring] = substr_counts.get(substring, 0) + 1\r\n\r\nresult = []\r\n\r\nfor word in words:\r\n done = False\r\n for j in range(1, 10):\r\n if done:\r\n break\r\n for k in range(10 - j):\r\n if substr_counts[word[k:k+j]] == 1:\r\n done = True\r\n result.append(word[k:k+j])\r\n break\r\n\r\nfor substr in result:\r\n print(substr)\r\n", "n=int(input())\r\na=[]\r\nd={}\r\n\r\nfor _ in range(n):\r\n s=input()\r\n g=set()\r\n for i in range(len(s)):\r\n for k in range(i,len(s)):\r\n st=s[i:k+1]\r\n if st in g:\r\n continue\r\n else:\r\n g.add(st)\r\n if st in d:\r\n d[st]+=1\r\n else:\r\n d[st]=1\r\n a.append(s)\r\n\r\nfor s in a:\r\n ans=s\r\n for i in range(len(s)):\r\n for j in range(i,len(s)):\r\n k=s[i:j+1]\r\n if d[k]==1 and len(k) < len(ans):\r\n ans=k\r\n print(ans)\r\n", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\neps = 1.0 / 10**10\nmod = 10**9+7\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\n\n\ndef main():\n n = I()\n a = [S() for _ in range(n)]\n d = collections.defaultdict(int)\n for c in a:\n t = set()\n for i in range(9):\n for j in range(i+1,10):\n k = c[i:j]\n if k in t:\n continue\n t.add(k)\n d[k] += 1\n r = []\n for c in a:\n f = False\n for i in range(1,10):\n for j in range(10-i):\n k = c[j:j+i]\n if d[k] == 1:\n r.append(k)\n f = True\n break\n if f:\n break\n\n return '\\n'.join(r)\n\nprint(main())\n\n\n\n\n", "n = int(input())\r\nnumbers = [input() for i in range(n)]\r\ntelep = {}\r\ncount = 1\r\nfor number in numbers:\r\n for l in range(1, len(number) + 1):\r\n for i in range(0, len(number) - l + 1):\r\n key = number[i: i + l]\r\n if key in telep and telep[key] != count:\r\n telep[key] = -1\r\n else:\r\n telep[key] = count\r\n count += 1\r\nreverse = {}\r\nfor key in telep:\r\n if telep[key] == -1:\r\n continue\r\n elif telep[key] not in reverse:\r\n reverse[telep[key]] = key\r\n elif len(key) < len(reverse[telep[key]]):\r\n reverse[telep[key]] = key\r\nfor i in range(1, n + 1):\r\n print(reverse[i])\r\n \r\n " ]
{"inputs": ["3\n123456789\n100000000\n100123456", "4\n123456789\n193456789\n134567819\n934567891", "1\n167038488", "5\n115830748\n403459907\n556271610\n430358099\n413961410", "5\n139127034\n452751056\n193432721\n894001929\n426470953", "5\n343216531\n914073407\n420246472\n855857272\n801664978", "5\n567323818\n353474649\n468171032\n989223926\n685081078", "5\n774610315\n325796798\n989859836\n707706423\n310546337", "10\n181033039\n210698534\n971006898\n391227170\n323096464\n560766866\n377374442\n654389922\n544146403\n779261493", "10\n197120216\n680990683\n319631438\n442393410\n888300189\n170777450\n164487872\n487350759\n651751346\n652859411", "10\n302417715\n621211824\n474451896\n961495400\n633841010\n839982537\n797812119\n510708100\n770758643\n228046084", "10\n506504092\n561611075\n265260859\n557114891\n838578824\n985006846\n456984731\n856424964\n658005674\n666280709", "10\n510613599\n931933224\n693094490\n508960931\n313762868\n396027639\n164098962\n749880019\n709024305\n498545812", "3\n638631659\n929648227\n848163730", "4\n898855826\n343430636\n210120107\n467957087", "5\n202080398\n357502772\n269676952\n711559315\n111366203", "9\n111111111\n111111110\n111111100\n111111000\n111110000\n111100000\n111000000\n110000000\n100000000"], "outputs": ["9\n000\n01", "2\n193\n81\n91", "4", "15\n40\n2\n35\n14", "39\n05\n32\n8\n53", "32\n07\n46\n27\n78", "67\n35\n03\n26\n78", "61\n32\n89\n23\n37", "18\n53\n97\n27\n09\n07\n42\n99\n41\n93", "12\n09\n43\n42\n01\n74\n72\n73\n46\n11", "15\n62\n47\n14\n33\n98\n97\n100\n43\n60", "40\n75\n60\n55\n78\n68\n31\n96\n74\n66", "61\n22\n44\n08\n68\n39\n64\n88\n43\n12", "5\n2\n0", "98\n3\n1\n57", "8\n57\n26\n93\n62", "111111111\n111111110\n111111100\n111111000\n111110000\n111100000\n111000000\n110000000\n00000000"]}
UNKNOWN
PYTHON3
CODEFORCES
24
156d2508c063ef36fdc1332ed8ab8e1e
Iterated Linear Function
Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=&gt;<=0. For the given integer values *A*, *B*, *n* and *x* find the value of *g*(*n*)(*x*) modulo 109<=+<=7. The only line contains four integers *A*, *B*, *n* and *x* (1<=≤<=*A*,<=*B*,<=*x*<=≤<=109,<=1<=≤<=*n*<=≤<=1018) — the parameters from the problem statement. Note that the given value *n* 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. Print the only integer *s* — the value *g*(*n*)(*x*) modulo 109<=+<=7. Sample Input 3 4 1 1 3 4 2 1 3 4 3 1 Sample Output 7 25 79
[ "import sys,math\r\ndef power(x, y, p): \r\n res = 1;\r\n x = x % p; \r\n while (y > 0): \r\n if (y & 1): \r\n res = (res * x) % p; \r\n y = y >> 1; \r\n x = (x * x) % p; \r\n return res; \r\ndef modInverse(b,m): \r\n\tg = math.gcd(b, m) \r\n\tif (g != 1): \r\n\t\treturn -1\r\n\telse: \r\n\t\treturn pow(b, m - 2, m) \r\ndef modDivide(a,b,m): \r\n\ta = a % m \r\n\tinv = modInverse(b,m) \r\n\tif(inv == -1): \r\n\t\tprint(\"Division not defined\") \r\n\telse: \r\n\t\treturn (inv*a) % m \r\n#using sum of GP series \r\nA,B,n,X=map(int,sys.stdin.readline().split())\r\nm=10**9+7\r\nif A==1:\r\n print(((n%m)*B+X)%m)\r\nelse:\r\n temp=power(A,n,m)\r\n s=(temp*(X%m))%m\r\n s=(s%m+((modDivide(B*(temp-1),A-1,m)%m)%m)%m)%m\r\n print(s%m)\r\n", "# we are applying a linear function many times.\n\n\n# multiplies 2 2x2 matrices and returns that\n\nmod = 7+10**9\ndef matmul(a, b):\n c = [[0,0],[0,0]]\n for i in range(2):\n for j in range(2):\n for k in range(2):\n c[i][j] += a[i][k] * b[k][j]\n c[i][j] %= mod\n\n return c \n\ndef binpow(a, n):\n c = [[1,0],[0,1]]\n while n != 0:\n if (n&1):\n c = matmul(a,c) \n a = matmul(a,a)\n n//=2\n return c\n\nA,B,n,x = [int(i) for i in input().split(\" \")]\n\nmatDef = [[A,B],[0,1]]\nmatDef = binpow(matDef,n)\n\nprint((matDef[0][0] * x + matDef[0][1]) % mod)\n\n \n\n \t\t\t \t \t\t\t\t \t \t \t\t", "import sys\r\ninput = sys.stdin.readline\r\n\r\nM = 10**9 + 7\r\na, b, n, x = map(int, input().split())\r\nif a == 1:\r\n print((x+b*n)%M)\r\nelse:\r\n print((pow(a, n, M)*x + b*(pow(a, n, M)-1)*pow(a-1, M-2, M))%M)\r\n", "import math\r\na, b, n, x = [int(i) for i in input().split()]\r\n\r\n\r\ndef modInverse(b, m):\r\n g = math.gcd(b, m)\r\n if (g != 1):\r\n return -1\r\n else:\r\n return pow(b, m - 2, m)\r\n\r\n\r\ndef modDivide(a, b, m):\r\n a = pow(a, 1, m)\r\n inv = modInverse(b, m)\r\n if (inv == -1):\r\n return -1\r\n else:\r\n return pow((inv * a), 1, m)\r\n\r\nnewA = pow(a, n, 1000000007)\r\nif a > 1:\r\n bTerm = modDivide((pow(a, n, 1000000007)-1), (a-1), 1000000007)\r\nelse:\r\n bTerm = (n)\r\n\r\nprint(pow(newA*x + bTerm*b, 1, 1000000007))", "'''Codeforces Problem 678D'''\r\nfrom time import process_time\r\nfrom sys import argv\r\n\r\ndef extended_gcd(aa, bb):\r\n '''Extended GCD algorithm'''\r\n lastremainder, remainder = abs(aa), abs(bb)\r\n x, lastx, y, lasty = 0, 1, 1, 0\r\n while remainder:\r\n lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder)\r\n x, lastx = lastx - quotient*x, x\r\n y, lasty = lasty - quotient*y, y\r\n return lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1)\r\n\r\ndef modinv(a, m):\r\n '''Inverse of a modulo m'''\r\n g, x, _ = extended_gcd(a, m)\r\n if g != 1:\r\n raise ValueError\r\n return x % m\r\n\r\ndef solve():\r\n '''Solve the problem'''\r\n A, B, n, x = map(int, input().split())\r\n m = 10 ** 9 + 7\r\n if A > 1:\r\n ans = pow(A, n, m) * x + (pow(A, n, m) - 1) * modinv(A - 1, m) * B\r\n print(ans % m)\r\n else:\r\n print((x + B * n) % m)\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", "mod=1000000007\ndef power(x,y):\n\tres=1\n\tx=x%mod\n\twhile(y>0):\n\t\tif((y&1)==1):\n\t\t\tres=(res*x)%mod\n\t\ty=y>>1\n\t\tx=(x*x)%mod\n\treturn res\ndef modularinverse(a):\n\treturn power(a,mod-2)\na,b,n,x=map(int,input().split())\nif(a==1):\n\tprint((x*power(a,n)+b*n)%1000000007)\nelse:\n\tprint((x*power(a,n)+(b*(power(a,n)-1)*modularinverse(a-1)))%1000000007)", "a,b,n,x = (map(int,input().split(' ')))\r\nmod = 10**9+7\r\nif(a==1):\r\n ans = x + n*b\r\n print(ans%mod)\r\nelse:\r\n ans = (pow(a,n,mod)*x)%mod\r\n t = pow(a,n,mod)\r\n t = (t-1+mod)%mod\r\n t = (t * pow(a-1,mod-2,mod))%mod\r\n t = (t*b)%mod\r\n print((ans+t)%mod)", "mod=10**9+7\ninv =lambda x:pow(x,mod-2,mod)\nA,B,n,x=map(int,input().split())\nif A==1:\n print((x+B*n)%mod)\nelse:\n print((pow(A,n,mod)*x+B*(pow(A,n,mod)-1)*inv(A-1))%mod)\n\n \t\t\t\t\t\t\t \t\t \t\t \t\t \t\t\t\t\t \t", "a,b,n,x = map(int, input().split())\r\nmod = 10**9+7\r\nif a==1:\r\n print((x+n*b)%mod)\r\nelse:\r\n print((pow(a,n,mod)*x+b*(pow(a,n,mod)-1)*pow(a-1,mod-2,mod))%mod)", "def expo(a,n):\r\n ans,mod=1,1000000007\r\n while n>0:\r\n last_bit=n&1\r\n if(last_bit):\r\n ans=(ans*a)%mod\r\n a=(a*a)%mod\r\n n=n>>1\r\n return ans\r\n \r\na,b,n,x=list(map(int,input().split()))\r\nmod=1000000007\r\nif a==1:\r\n\tval=x*expo(a,n)+b*n\r\nelse:\r\n p,inv=expo(a,n)-1,expo(a-1,mod-2)\r\n val=x*(p+1)+b*p*inv\r\nprint(val%mod)", "import sys\r\ninput = sys.stdin.readline\r\n\r\na, b, n, x = map(int, input().split())\r\nmod = pow(10, 9) + 7\r\nu = pow(a, n, mod) * x % mod\r\nif a == 1:\r\n v = n * b % mod\r\nelse:\r\n v = b * (pow(a, n, mod) - 1) * pow(a - 1, mod - 2, mod) % mod\r\nans = u + v\r\nans %= mod\r\nprint(ans)", "# from dust i have come, dust i will be\r\n\r\nmod=int(1e9)+7\r\n\r\nA,B,n,x=map(int,input().split())\r\n\r\n'''\r\nif we expand the given formula for some test cases \r\ne.g-> for n=2,3,4.. we get\r\nA^n*x + B(A^0+A^1+...+A^{n-1})\r\nfor the geometric progression, 1+r+r^2+...+r^{n-1}\r\nthe ans=(r^n-1)/(r-1) when r>1, if r==1, ans=nr\r\n'''\r\n\r\nif n==0:\r\n print(x)\r\n exit(0)\r\n\r\nif A==1:\r\n temp=n*A\r\nelse:\r\n '''\r\n (A/B)%m=(A%m*(B^-1)%m)%m\r\n '''\r\n x1=pow(A,n,mod)-1\r\n x2=pow(A-1,mod-2,mod)\r\n temp=(x1*x2)% mod\r\n\r\np1=pow(A,n,mod)*pow(x,1,mod)\r\np1=p1%mod\r\n\r\np2=(B%mod)*temp\r\np2=p2%mod\r\n\r\nprint((p1+p2)%mod)\r\n", "import functools\nimport itertools\n\nclass NotAMatrixError(Exception):\n pass\n\nclass MatrixSizeError(Exception):\n def __init__(self, s1, s2):\n print('sizes do not match : ', s1, ', ', s2)\n\nclass NotSquareError(Exception):\n pass\n\nclass Matrix(list):\n def __init__(self, L):\n if type(L) == type(self):\n self = L\n return\n n = len(L)\n m = len(L[0])\n for i in range(n):\n if len(L[i]) != m:\n raise NotAMatrixError()\n list.__init__(self, L)\n self.n = n\n self.m = m\n self.degrees = []\n def check_size(self, M, mode):\n n, m = len(M), len(M[0])\n for i in range(n):\n if len(M[i]) != m:\n raise NotAMatrixError()\n if mode == 'add' and self.n != n or self.m != m:\n raise MatrixSizeError((self.n, self.m), (n,m))\n if mode == 'mul' and self.m != n:\n raise MatrixSizeError((self.n, self.m), (n,m))\n def __add__(self, M):\n self.check_size(M, mode = 'add')\n return Matrix([[self[i][j]+M[i][j] for j in range(self.m)]for i in range(self.n)])\n def __iadd__(self, M):\n self.check_size(M, mode = 'add')\n for i in range(self.n):\n for j in range(self,m):\n self[i][j] += M[i][j]\n def __mul__(self, M):\n self.check_size(M, mode = 'mul')\n l = len(M[0])\n return Matrix([[sum(self[i][k]*M[k][j] for k in range(self.m))\n for j in range(l)] for i in range(self.n)])\n def issquare(self):\n return self.n == self.m\n def primary(self):\n if self.n != self.m:\n raise NotSquareError()\n return Matrix([[int(i==j) for j in range(self.m)] for i in range(self.n)])\n def __pow__(self, n):\n if self.n != self.m:\n raise NotSquareError()\n if n == 0:\n return self.primary()\n elif n == 1:\n return self\n if len(self.degrees) == 0:\n self.degrees.append(self*self)\n for i in range(n.bit_length() - len(self.degrees) - 1):\n self.degrees.append(self.degrees[-1] * self.degrees[-1])\n s = [(n>>i)&1 for i in range(1,n.bit_length())]\n res = functools.reduce(lambda x,y:x*y, itertools.compress(self.degrees, s))\n return res*self if n%2 else res \n def drop_degrees(self):\n self.degrees.clear()\n\nclass RemMatrix(Matrix):\n def __init__(self, L, p):\n Matrix.__init__(self, L)\n self.p = p\n\n def primary(self):\n if self.n != self.m:\n raise NotSquareError()\n return Matrix([[Remainder(i==j, self.p) for j in range(self.m)] for i in range(self.n)])\n\n def __mul__(self, M):\n self.check_size(M, mode = 'mul')\n l = len(M[0])\n return RemMatrix([[sum((self[i][k]*M[k][j] for k in range(self.m)),\n Remainder(0, self.p)) for j in range(l)]\n for i in range(self.n)], self.p)\n\nclass Remainder(tuple):\n def __new__(self, a, n):\n return tuple.__new__(self, (a%n, n))\n def __add__(self, p):\n return Remainder((self[0] + p[0]) % self[1], self[1])\n def __sub__(self, p):\n return Remainder((self[0] - p[0]) % self[1], self[1])\n def __mul__(self, p):\n return Remainder((self[0] * p[0]) % self[1], self[1])\n def __radd__(self, p):\n return Remainder((self[0] + p[0]) % self[1], self[1])\n def __rsub__(self, p):\n return Remainder((self[0] - p[0]) % self[1], self[1])\n def __rmul__(self, p):\n return Remainder((self[0] * p[0]) % self[1], self[1])\n def __neg__(self):\n return Remainder((-self[0]) % self[1], self[1])\n\np = 10 ** 9 + 7\nr = lambda x : Remainder(x, p)\n\nN = map(r, range(10))\n\na, b, n, x = map(int, input().split())\na1, b1, o, l, x1 = r(a), r(b), r(0), r(1), r(x)\nM = RemMatrix([[a1, b1], [o, l]], p)\nL = (M ** n)\n\nprint((L[0][0] * x1 + L[0][1])[0])\n\n\n", "mod=10**9+7\r\na,b,n,x=map(int,input().split())\r\nif a==1:\r\n print(((n*b)%mod+(pow(a,n,mod)*(x%mod))%mod)%mod)\r\nelse:\r\n print((((((pow(a,n,mod)-1)%mod)*pow(a-1,mod-2,mod)%mod)*(b%mod))%mod+(pow(a,n,mod)*(x%mod))%mod)%mod)", "#coding:utf8\n\ndef qp(a, b, m):\n res = 1\n while b > 0:\n if b % 2 == 1:\n res = (res * a) % m\n b >>= 1\n a = (a * a) % m\n\n return res\n\n\n_str = input()\na, b, n, x = [int(x) for x in _str.split(\" \")]\nm = 10**9 + 7\n\nres = 0\nam = qp(a, n, m)\n\n\ndef ext_ru(a, b, m):\n r = qp(b, m - 2, m)\n return (a * r) % m\n\nc1 = am - 1\nc2 = a - 1\n\nif c2 == 0:\n print((x % m + ((b % m) * (n % m)) % m) % m)\n exit(0)\nelse:\n _dev = ext_ru(c1, c2, m)\n res = (((am % m) * (x % m)) % m + ((b % m) * (_dev % m)) % m) % m\n print(int(res))\n exit(0)\n \t\t\t \t \t\t \t \t\t\t\t\t \t\t \t\t\t \t", "def binpow_for_2x2_matrix_with_mod (a11, a12, a21, a22, n, mod):\r\n\tres11 = 1\r\n\tres22 = 1\r\n\tres12= 0\r\n\tres21 = 0\r\n\twhile (n):\r\n\t\tif (n & 1):\r\n\t\t\tres11, res12, res21, res22 = (res11*a11+res12*a21) % mod, (res11*a12+res12*a22) % mod, (res21*a11+res22*a21) % mod, (res21*a12+res22*a22) % mod\r\n\t\ta11, a12, a21, a22 = (a11*a11+a12*a21) % mod, (a11*a12+a12*a22) % mod, (a21*a11+a22*a21) % mod, (a21*a12+a22*a22) % mod\r\n\t\tn >>= 1\r\n\treturn [[res11, res12], [res21, res22]]\r\n\r\na, b, n, x = map(int, (input().split()))\r\n\r\nm=10**9+7\r\nmatrix = binpow_for_2x2_matrix_with_mod(a, b, 0, 1, n, m)\r\n#print(matrix)\r\nprint((matrix[0][0]*x+matrix[0][1])%m)", "a,b,n,x = map(int,input().split())\r\nmod = 10**9 +7\r\nans = pow(a,n,mod)*x\r\ngp = (pow(a,n,mod)-1)*(pow(a-1,mod-2,mod))*b\r\nif(a==1):\r\n gp = (b*n)%mod\r\nprint((ans+gp)%mod)", "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\nA,B,n,x = mints()\r\nr = 0\r\nif n == 0:\r\n\tr = x\r\nelif A == 1:\r\n\tr = x + B*n\r\nelse:\r\n\tr = (pow(A,n,10**9+7)-1)*pow(A-1,10**9+5,10**9+7)*B+pow(A,n,10**9+7)*x\r\nprint(r%(10**9+7))", "def mod_pow(base, exp, mod):\r\n if exp == 0:\r\n return 1\r\n if exp == 1:\r\n return base % mod\r\n tmp = mod_pow(base, exp // 2, mod)\r\n tmp = (tmp * tmp) % mod\r\n if exp % 2 == 1:\r\n tmp = (tmp * base) % mod\r\n return tmp\r\n\r\ndef inv(num, mod):\r\n return mod_pow(num, mod - 2, mod)\r\n \r\na, b, n, x = map(int, input().split())\r\nm = 10 ** 9 + 7\r\nif a == 1:\r\n ans = (x + ((n * b) % m)) % m\r\nelse:\r\n ans = (mod_pow(a, n, m) * x) % m\r\n tmp = ((b * inv(a - 1, m)) % m) * ((mod_pow(a, n, m) - 1) % m)\r\n tmp = tmp % m\r\n ans = (ans + tmp) % m\r\nprint(ans)", "import math\r\nimport sys\r\nfrom random import randint as rn\r\nimport random\r\nimport functools\r\nfrom heapq import heappop, heappush\r\n\r\n\r\ndef solve():\r\n a, b, n, x = map(int, input().split())\r\n\r\n m = 10 ** 9 + 7\r\n\r\n if n == 1:\r\n print((a * x + b) % m)\r\n return\r\n\r\n if a == 1:\r\n print((a * x + b * (1 + n - 1)) % m)\r\n return\r\n\r\n res = pow(a, n, m) * x + b * (pow(a, n, m) - 1) * pow(a - 1, m - 2, m)\r\n print(res % m)\r\n\r\n return\r\n\r\n\r\nif __name__ == '__main__':\r\n\r\n multitest = 0\r\n\r\n if multitest:\r\n t = int(sys.stdin.readline())\r\n for _ in range(t):\r\n solve()\r\n else:\r\n solve()\r\n # gen()\r\n", "import sys\ndef main():\n\tfor line in sys.stdin:\n\t\tline = line.split()\n\t\tA = int(line[0])\n\t\tB = int(line[1])\n\t\tn = int(line[2])\n\t\tx = int(line[3])\n\t\tmod = 1000000007\n\t\tif(A==1):\n\t\t\tasum = n\n\t\telse:\n\t\t\tnum = pow(A,n,mod*(A-1))\n\t\t\tasum = ((pow(A,n,mod*(A-1))-1)//(A-1))%mod\n\t\tprint((B*asum%mod + x*pow(A,n,mod))%mod)\n\nif __name__ == \"__main__\":\n main()", "A,B,n,x = list(map(int, input().strip().split()))\r\n\r\ndef f(a, n, p):\r\n # calculate A ** n % p\r\n power = []\r\n while n > 0:\r\n power.append(n % 2)\r\n n = n // 2\r\n st = a\r\n c = 1\r\n for i in power:\r\n if i != 0:\r\n c *= st\r\n c = c % p\r\n st = st * st\r\n st = st % p\r\n return c\r\n \r\n\r\np = 1000000000 + 7\r\nif A == 1:\r\n print ((x + ((n%p) * B) % p) % p)\r\nelse:\r\n expA = f(A, n, p) # calculate A ** n % p\r\n invA = f(A-1, p-2, p) #calculate 1/(A-1)\r\n res = ((expA * x)%p + ((B * (expA-1))%p*invA)%p)%p\r\n print(res)", "a,b,n,x=map(int,input().split())\r\nm=10**9+7\r\nprint(((pow(a,n,m)*x+b*(pow(a,n,m)-1)*pow(a-1,m-2,m)) if a!=1 else b*n+x)%m)", "A,B,n,x = map(int,input().split())\r\nsum1 = pow(A,n,10**9+7)*x\r\nsum2 = 0\r\nif A != 1:\r\n sum2 = B*(pow(A,n,10**9+7)-1)\r\n Q = pow(A-1,-1,10**9+7)\r\n sum2 = sum2*Q\r\nelse:\r\n sum2 += B*n\r\nprint((sum1+sum2)%(10**9+7))", "import math\r\n\r\nt=input().split()\r\na=int(t[0])\r\nb=int(t[1])\r\nn=int(t[2])\r\nx=int(t[3])\r\nvar=1000000007\r\nans=0\r\nif n==1:\r\n\tans=(a*x+b)%var\r\n\tprint (ans)\r\n\texit()\r\nif a==1:\r\n\tans=(x+b*n)%var\r\n\tprint (ans)\r\n\texit()\r\ndef f(a,n,var):\r\n\tres=1\r\n\twhile n:\r\n\t\tif n & 1:\r\n\t\t\tres=(res*a)%var\r\n\t\ta=(a*a)%var\r\n\t\tn=n//2\r\n\treturn res\r\nans=(f(a,n,var)*x)%var;\r\nt=(b*(f(a,n,var)+var-1))%var\r\np=(t*f(a-1,var-2,var))%var\r\nans=(ans+p)%var;\r\nprint (ans)\r\nexit()", "# A*B\r\ndef mat_mul(A, B, mod):\r\n C = [[0]*len(B[0]) for i in range(len(A))]\r\n for i in range(len(A)):\r\n for k in range(len(B)):\r\n for j in range(len(B[0])):\r\n C[i][j] = (C[i][j] + A[i][k]*B[k][j])%mod\r\n return C\r\n\r\n#A**n\r\ndef mat_pow(A, n, mod):\r\n B = [[0]*len(A) for i in range(len(A))]\r\n for i in range(len(A)):\r\n B[i][i] = 1\r\n while n > 0:\r\n if n & 1 == 1:\r\n B = mat_mul(A, B, mod)\r\n A = mat_mul(A, A, mod)\r\n n = n>>1\r\n return B\r\n\r\na, b, n, x = map(int, input().split())\r\nmod = 10**9+7\r\nA = [[a, 0, 0], [0, a, b], [0, 0, 1]]\r\nA = mat_pow(A, n, mod)\r\nan = A[0][0]+A[0][2]\r\nbn = A[1][0]+A[1][2]\r\nans = an*x+bn\r\nprint(ans%mod)\r\n", "\n\nmod=int(1e9)+7\n\nA,B,n,x=map(int,input().split())\n\n\n\nif n==0:\n print(x)\n exit(0)\n\nif A==1:\n temp=n*A\nelse:\n '''\n (A/B)%m=(A%m*(B^-1)%m)%m\n '''\n x1=pow(A,n,mod)-1\n x2=pow(A-1,mod-2,mod)\n temp=(x1*x2)% mod\n\np1=pow(A,n,mod)*pow(x,1,mod)\np1=p1%mod\n\np2=(B%mod)*temp\np2=p2%mod\n\nprint((p1+p2)%mod)\n \t \t \t \t\t \t \t \t\t \t \t \t", "import sys\r\ninput = sys.stdin.readline\r\n\r\nmod = 10**9 + 7\r\n\r\ndef invmod(x, mod):\r\n return pow(x, mod-2, mod)\r\n\r\na, b, n, x = map(int, input().split())\r\nif a == 1:\r\n ans = (pow(a, n, mod) * x + b * n) % mod\r\nelse:\r\n ans = pow(a, n, mod) * x + b * (pow(a, n, mod) - 1 + mod) * invmod(a-1, mod)\r\n ans %= mod\r\nprint(ans)", "from sys import stdin, stdout\r\n\r\n\r\ndef multy(A, B):\r\n sze = 2\r\n result = [[0, 0], [0, 0]]\r\n \r\n for i in range(sze):\r\n for j in range(sze):\r\n for z in range(sze):\r\n result[i][j] = (result[i][j] + A[i][z] * B[z][j]) % MOD\r\n \r\n return result\r\n\r\n\r\ndef power(matr, pw):\r\n result = [[1, 0], [0, 1]]\r\n \r\n while pw:\r\n if pw & 1:\r\n result = multy(result, matr)\r\n \r\n pw >>= 1\r\n matr = multy(matr, matr)\r\n \r\n return result\r\n\r\n\r\na, b, n, x = map(int, stdin.readline().split())\r\nmatrix = [[a, b], [0, 1]]\r\nMOD = 10 ** 9 + 7\r\n\r\n\r\nmatrix = power(matrix, n)\r\nstdout.write(str((x * matrix[0][0] + matrix[0][1]) % MOD))", "a,b,n,x=map(int, input().split());\nm=1000000007;\ndef modex(a,n):\n\tans=1\n\twhile n:\n\t\tif n&1:\n\t\t\tans=(ans%m*a%m)%m\n\t\ta=(a%m*a%m)%m\n\t\tn>>=1\n\treturn ans\nif a==1:\n\tprint((x%m+(b%m*n%m)%m)%m)\nelse:\n\tprint(((modex(a,n)%m*x%m)%m+(b%m*((modex(a,n)%m-1%m)%m)%m*(modex(a-1,m-2)))%m)%m)", "#!/usr/bin/env python\nimport os\nimport sys\nfrom io import BytesIO, IOBase\nfrom copy import deepcopy\n\n\nMOD = 10 ** 9 + 7\n\n\ntranspose = lambda mat: [list(col) for col in zip(*mat)]\n\nminor = lambda mat, i, j: [row[:j] + row[j + 1:] for row in (mat[:i] + mat[i + 1:])]\n\nmat_add = lambda *mat: [[sum(elements) for elements in zip(*row)] for row in zip(*mat)]\n\nmat_sub = lambda A, B: [[i - j for i, j in zip(*row)] for row in zip(A, B)]\n\nmat_mul = lambda A, B: [[sum(i * j for i, j in zip(row, col)) % MOD for col in zip(*B)] for row in A]\n\nvec_mul = lambda mat, vec: [sum(a * b for a, b in zip(row, vec)) % MOD for row in mat]\n\n\ndef eye(m):\n \"\"\"returns an indentity matrix of order m\"\"\"\n identity = [[0] * m for _ in range(m)]\n for i, row in enumerate(identity):\n row[i] = 1\n return identity\n\n\ndef mat_pow(mat, power):\n \"\"\"returns mat**power\"\"\"\n if power < 0:\n return mat_pow(mat_inv(mat), -power)\n\n result = eye(len(mat))\n if power == 0:\n return result\n\n while power > 1:\n if power & 1 == 1:\n result = mat_mul(result, mat)\n mat = mat_mul(mat, mat)\n power >>= 1\n return mat_mul(result, mat)\n\n\ndef mat_inv(A):\n B = deepcopy(A)\n n = len(A)\n col = list(range(n))\n\n tmp = [[0] * n for _ in range(n)]\n for i in range(n):\n tmp[i][i] = 1\n\n for i in range(n):\n r = c = i\n for j in range(i, n):\n for k in range(i, n):\n if abs(B[j][k]) > abs(B[r][c]):\n r, c = j, k\n if B[r][c] == 0:\n return B\n\n B[i], B[r] = B[r], B[i]\n tmp[i], tmp[r] = tmp[r], tmp[i]\n for j in range(n):\n B[j][i], B[j][c] = B[j][c], B[j][i]\n tmp[j][i], tmp[j][c] = tmp[j][c], tmp[j][i]\n col[i], col[c] = col[c], col[i]\n v = B[i][i]\n for j in range(i + 1, n):\n f = B[j][i] / v\n B[j][i] = 0\n for k in range(i + 1, n):\n B[j][k] -= f * B[i][k]\n for k in range(n):\n tmp[j][k] -= f * tmp[i][k]\n\n for j in range(i + 1, n):\n B[i][j] /= v\n\n for j in range(n):\n tmp[i][j] /= v\n B[i][i] = 1\n\n for i in reversed(range(n)):\n for j in range(i):\n v = B[j][i]\n for k in range(n):\n tmp[j][k] -= v * tmp[i][k]\n\n for i in range(n):\n for j in range(n):\n B[col[i]][col[j]] = tmp[i][j]\n return B\n\n\ndef main():\n A, B, n, x = map(int, input().split())\n\n mat = [[1, 0], [1, A]]\n vec = [B, x]\n\n print(vec_mul(mat_pow(mat, n), vec)[1])\n\n\n# region fastio\n\nBUFSIZE = 8192\n\n\nclass FastIO(IOBase):\n newlines = 0\n\n def __init__(self, file):\n self._file = 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# endregion\n\nif __name__ == \"__main__\":\n main()\n", "def matmul(A,B,mod):\r\n res = [[0]*len(B[0]) for _ in [None]*len(A)]\r\n for i, resi in enumerate(res):\r\n for k, aik in enumerate(A[i]):\r\n for j,bkj in enumerate(B[k]):\r\n resi[j] += aik*bkj\r\n resi[j] %= mod\r\n return res\r\n\r\ndef matpow(A,p,mod):\r\n if p%2:\r\n return matmul(A, matpow(A,p-1,mod),mod)\r\n elif p > 0:\r\n b = matpow(A,p//2,mod)\r\n return matmul(b,b,mod)\r\n else:\r\n return [[int(i==j) for j in range(len(A))] for i in range(len(A))]\r\n\r\nmod=10**9+7\r\na,b,n,x=map(int,input().split())\r\nmat=[[a,b],[0,1]]\r\nmat_n=matpow(mat,n,mod)\r\nans=matmul(mat_n,[[x],[1]],mod)\r\nprint(ans[0][0])", "import sys, math\r\ninput=sys.stdin.readline\r\nINF=int(1e9)+7\r\nmod=INF\r\n\r\ndef matrixmult(A,B):\r\n n = len(A)\r\n C=[[0]*n for _ in range(n)]\r\n for i in range(n):\r\n for j in range(n):\r\n for k in range(n):\r\n C[i][j]=(A[i][k]*B[k][j]+C[i][j])%mod\r\n return C\r\n\r\ndef many(a,m):\r\n if m==1:\r\n return a\r\n if m%2==0:\r\n k=many(a,m//2)\r\n return matrixmult(k,k)\r\n else:\r\n k=many(a,m//2)\r\n return matrixmult(matrixmult(k,k),a)\r\n \r\ndef solve(): \r\n a,b,n,x=map(int,input().split())\r\n base=[[a,0],[b,1]]\r\n go=[[x,1],[0,0]]\r\n base=many(base,n)\r\n result=matrixmult(go,base)\r\n print(result[0][0])\r\n \r\nt=1\r\nwhile t:\r\n t-=1\r\n solve()\r\n", "import sys\r\n\r\ndef get_array(): return list(map(int, sys.stdin.readline().split()))\r\ndef get_ints(): return map(int, sys.stdin.readline().split())\r\ndef input(): return sys.stdin.readline().strip('\\n')\r\n\r\na,b,n,x = get_ints()\r\n\r\nmod = 10**9 + 7\r\nk = pow(a,n,mod)\r\n\r\n#well that was fucking awesome.\r\nif( a != 1):\r\n ans = ((b%mod)*(((k-1)*pow(a-1,mod-2,mod))%mod)+(k*x)%mod)%mod\r\n print(ans)\r\nelse:\r\n print( ((k*x)%mod + (n%mod * b%mod)%mod)%mod)\r\n", "from sys import stdin\r\nimport sys\r\nsys.setrecursionlimit(10**7)\r\nA,B,n,x=map(int,stdin.readline().strip().split())\r\nmod=10**9+7\r\n\"\"\"\r\ndp=[-1 for i in range(n+10)]\r\ndef f(x1):\r\n return (A*x1+B)%mod\r\ndef g(n,x):\r\n if n==0:\r\n return x\r\n if dp[n]!=-1:\r\n return dp[n]\r\n dp[n]=f(g(n-1,x))\r\n return dp[n]\r\n\"\"\"\r\ndef geo(n):\r\n ans=(pow(A,n,mod)*x)%mod\r\n if(A!=1):\r\n ans1=(((B-B*pow(A,n,mod))%mod)*pow(1-A,mod-2,mod))%mod\r\n else:\r\n ans1=(B*n)\r\n return (ans+ans1)%mod\r\nprint(geo(n))\r\n" ]
{"inputs": ["3 4 1 1", "3 4 2 1", "3 4 3 1", "1 1 1 1", "3 10 723 6", "14 81 51 82", "826504481 101791432 76 486624528", "475965351 844435993 96338 972382431", "528774798 650132512 6406119 36569714", "632656975 851906850 1 310973933", "1 1 352875518515340737 1", "978837295 606974665 846646545585165081 745145208", "277677243 142088706 8846851 253942280", "1 192783664 1000000000000000000 596438713", "1 1000000000 1000000000000000000 1", "1 1000000000 1000000000000000000 1000000000", "1 100000000 10000000000000 1000000000", "1 1171281 1000000000000000000 100", "1 1000000000 100000000000000000 1000000000", "1 100000000 100000000000000000 10000", "1 100000456 10000000000000000 54165", "1 1000000000 10000000000000 1", "1 100000000 10000000000000000 10000", "1 1000000000 10000000000 12", "1 999999999 999999999999999999 12345678", "1 1000000 1000000000000000000 100000", "1 1000000000 1000000000000 12", "1 10000 1000000000000000000 5", "1 10000 1000000000000000000 10000", "1 1000000000 10000000000000 12", "1 1000000000 1000000000000000 12", "1 1000000000 1000000000000000000 12", "1 10000000 100000000000000000 100000", "114514 114514 114514 114514", "2 1 1000000006 1", "1 1234 10 9"], "outputs": ["7", "25", "79", "2", "443623217", "908370438", "621999403", "83709654", "505858307", "230360736", "45212126", "154788991", "221036825", "42838179", "999999665", "999999657", "48993", "57392869", "899999965", "490010000", "129054389", "490001", "49010000", "502", "12345294", "49100000", "49012", "490005", "500000", "490012", "49000012", "999999676", "49100000", "623380685", "1", "12349"]}
UNKNOWN
PYTHON3
CODEFORCES
35
157a3165ac77cae8dc1878f04883493a
Jeopardy!
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2. The finals will have *n* questions, *m* of them are auction questions and *n*<=-<=*m* of them are regular questions. Each question has a price. The price of the *i*-th question is *a**i* points. During the game the players chose the questions. At that, if the question is an auction, then the player who chose it can change the price if the number of his current points is strictly larger than the price of the question. The new price of the question cannot be less than the original price and cannot be greater than the current number of points of the player who chose the question. The correct answer brings the player the points equal to the price of the question. The wrong answer to the question reduces the number of the player's points by the value of the question price. The game will go as follows. First, the R2 company selects a question, then the questions are chosen by the one who answered the previous question correctly. If no one answered the question, then the person who chose last chooses again. All R2 employees support their team. They want to calculate what maximum possible number of points the R2 team can get if luck is on their side during the whole game (they will always be the first to correctly answer questions). Perhaps you are not going to be surprised, but this problem was again entrusted for you to solve. The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100; *m*<=≤<=*min*(*n*,<=30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=107) — the prices of the questions. The third line contains *m* distinct integers *b**i* (1<=≤<=*b**i*<=≤<=*n*) — the numbers of auction questions. Assume that the questions are numbered from 1 to *n*. In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type. Sample Input 4 1 1 3 7 5 3 3 2 10 3 8 2 3 2 2 100 200 1 2 Sample Output 18 40 400
[ "n, m = map(int, input().split())\r\nl = list(map(int, input().split()))\r\nmm = list(map(int, input().split()))\r\ns = 0\r\na = []\r\nfor i in range(0, n):\r\n if (i+1) not in mm:\r\n s+=l[i]\r\nfor i in range(0, m):\r\n v = l[mm[i]-1]\r\n a.append(v)\r\na.sort(reverse = True)\r\nfor i in a:\r\n if s >= i:\r\n s+=s\r\n else:\r\n s+=i\r\nprint(s)\r\n", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nc = []\r\nans = 0\r\nfor i in range(m):\r\n ans -= a[b[i] - 1]\r\n c.append(a[b[i] - 1])\r\nans += sum(a)\r\nc.sort()\r\nc = c[::-1]\r\nmx = ans\r\nfor i in range(m + 1):\r\n x = (sum(c[:i])+ans)*(2**(m-i))\r\n if x > mx:\r\n mx = x\r\n\r\nprint(mx)", "n, m = tuple(map(int, str.split(input())))\r\na = tuple(map(int, str.split(input())))\r\nmi = tuple(map(int, str.split(input())))\r\nms = sorted(map(lambda i: a[i - 1], mi), reverse=True)\r\n\r\npoints = 0\r\nfor i, ai in enumerate(a):\r\n\r\n if i + 1 not in mi:\r\n\r\n points += ai\r\n\r\nfor m in ms:\r\n\r\n if m > points:\r\n\r\n points += m\r\n\r\n else:\r\n\r\n points += points\r\n\r\nprint(points)\r\n", "n, m = list(map(int, input().split()))\r\nlst = list(map(int, input().split()))\r\nau = list(map(int, input().split()))\r\nres = sum(lst)\r\nls = []\r\nfor i in range(m): \r\n res -= lst[au[i] - 1]\r\n ls.append(lst[au[i] - 1])\r\nls.sort(reverse = True)\r\nfor i in range(len(ls)):\r\n res += max(ls[i], res)\r\nprint(res)\r\n", "n, m = map(int, input().split())\r\nprices = list(map(int, input().split()))\r\nauction = list(map(int, input().split()))\r\nval = 0\r\ninitialSum, auctionSum = sum(prices), 0\r\n\r\nfor i in range(m):\r\n auction[i] = prices[auction[i] - 1]\r\n auctionSum += auction[i]\r\n\r\nval = initialSum - auctionSum\r\nauction.sort(reverse=True)\r\n\r\nfor j in auction:\r\n if val > j:\r\n val *= 2\r\n else:\r\n val += j\r\n\r\nprint(val)\r\n\r\n\r\n", "n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\nc = []\r\nres = 0\r\ncnt = 0\r\nres1=0\r\nfor i in b:\r\n c.append(a[i-1])\r\nc = sorted(c,reverse=True)\r\nfor i in range(len(a)):\r\n if (i+1) not in b:\r\n res1+=a[i]\r\n res +=a[i]\r\nfor i in c:\r\n if res>i:res+=res\r\n else:\r\n res += i\r\n if cnt>i:cnt+=cnt\r\n else : cnt+=i\r\nprint(max(res,res1+cnt))\r\n", "import sys\nfrom itertools import *\nfrom math import *\nMAX = 10000000\ndef solve():\n n, m = map(int, input().split())\n quest = list(map(int, input().split()))\n auctindex = set(map(int, input().split()))\n aucts = list()\n firstsum = 0\n for i, q in enumerate(quest):\n if (i + 1) not in auctindex:\n firstsum+= q\n else:\n aucts.append(q)\n aucts.sort(reverse = True)\n for val in aucts:\n firstsum += max(firstsum, val)\n print(firstsum)\n\nif sys.hexversion == 50594544 : sys.stdin = open(\"test.txt\")\nsolve()\n", "# first choose all the regular questions and add them\n# now what should we do?\n# we can increase each question less than that value, that can be added on it, so for that go from highest to lowest\n\nn, m = list(map(int, input().split()))\ninp = list(map(int, input().split()))\nvals = list(map(int, input().split()))\n\naps = []\nnps = []\n\nfor i in range(n):\n if (i+1) in vals:\n aps.append(inp[i])\n else:\n nps.append(inp[i])\n\naps = sorted(aps, reverse=True)\nans = sum(nps)\n\nfor x in aps:\n if x<ans:\n ans += ans\n else:\n ans += x\n\nprint(ans)\n", "n, m = list(map(int, input().split()))\narr = list(map(int, input().split()))\nauction = set(map(int, input().split()))\n\nnon_auction_sum = 0\nmax_auction = 0\nfor i in range(n):\n if (i+1) in auction:\n max_auction = max(max_auction, arr[i])\n else:\n non_auction_sum += arr[i]\n\nif non_auction_sum < max_auction:\n non_auction_sum = (non_auction_sum + max_auction) * (2 ** (m-1))\nelse:\n non_auction_sum = non_auction_sum * (2 ** m)\n\nprint(non_auction_sum)\n", "n, m = list(map(int, input().split()))\nprices = list(map(int, input().split()))\nauci = list(map(int, input().split()))\n\nscores = 0\n\n# m auc\n# n - m default\n\nfor i in range(len(prices)):\n if (i+1) not in auci:\n scores += prices[i]\n prices[i] = 0\n\nra = []\nfor i in prices:\n if i != 0:\n ra.append(i)\nra.sort()\nra = ra[::-1]\n\nfor i in ra:\n if i > scores:\n scores += i\n else:\n scores *= 2\n\nprint(scores)\n#print(ra)\n", "n, m = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = []\nfor i in range(m):\n c.append(a[b[i] - 1])\n a[b[i] - 1] = 0\nk = sum(a)\nc.sort()\nif k > max(c):\n print(k * pow(2, len(c)))\nelse:\n k += max(c)\n print(k * pow(2, len(c) - 1))", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\n\r\nc = 0\r\nw = list(map(int, input().split()))\r\nd = list(map(lambda x:int(x)-1, input().split()))\r\nx = [0]*n\r\nfor i in d:\r\n x[i] = 1\r\n\r\ne = []\r\nfor i in range(n):\r\n if x[i] == 0:\r\n c += w[i]\r\n else:\r\n e.append(w[i])\r\n\r\ne.sort()\r\nif c < e[-1]:\r\n c += e[-1]\r\n print(c*(2**(m-1)))\r\nelse:\r\n print(c*(2**m))\r\n", "n, m = map(int, input().split(' '))\r\ntmp = list(map(int, input().split(' ')))\r\nm_nums = list(map(lambda x: int(x)-1, input().split(' ')))\r\nm_list = [tmp[el] for el in m_nums]\r\n_sum = sum(tmp)-sum(m_list)\r\nm_list.sort()\r\nwhile (m_list) and (m_list[len(m_list)-1] > _sum): _sum += m_list.pop()\r\nprint(_sum * 2**(len(m_list)))\r\n", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nnums = set(list(map(int, input().split())))\r\nstan = []\r\nauct = []\r\nfor i in range(len(a)):\r\n if i + 1 not in nums:\r\n stan.append(a[i])\r\n else:\r\n auct.append(a[i])\r\nsm = sum(stan)\r\nauct = list(reversed(sorted(auct)))\r\nfor i in range(len(auct)):\r\n if sm >= auct[i]:\r\n if sm > auct[i]:\r\n sm *= 2\r\n else:\r\n sm += auct[i]\r\n else:\r\n sm += auct[i]\r\nprint(sm)", "n,m = map(int,input().split())\r\nmat = list(map(int,input().split()))\r\nauction = list(map(int,input().split()))\r\naucpoint = [mat[i-1] for i in auction]\r\naucpoint.sort(reverse = True)\r\nfor i in auction:\r\n mat[i-1] = 0\r\ns = sum(mat)\r\nfor point in aucpoint:\r\n if s > point:\r\n s *= 2\r\n else: s += point\r\nprint(s)", "n,m=list(map(int,input().split()))\r\nl=list(map(int,input().split()))\r\nls=list(map(int,input().split()))\r\ns=set(ls)\r\nans=0\r\nt=[]\r\nfor i in range(n):\r\n if i+1 not in s:\r\n ans+=l[i]\r\n else:\r\n t.append(l[i])\r\nt.sort(reverse=True)\r\nfor i in t:\r\n if ans<i:\r\n ans+=i\r\n else:\r\n ans+=ans\r\nprint(ans)", "n, m = map(int, input().split())\r\nl = list(map(int, input().split()))\r\nmm = list(map(int, input().split()))\r\nans = 0\r\na = []\r\nfor i in range(0, n):\r\n if i+1 not in mm:\r\n ans+=l[i]\r\nfor i in range(0, m):\r\n v = l[mm[i]-1]\r\n a.append(v)\r\na = sorted(a)[::-1]\r\nfor i in a:\r\n if ans >= i:\r\n ans+=ans\r\n else:\r\n ans+=i\r\nprint(ans)", "n, m = map(int, input().split())\nprices = list(map(int, input().split()))\nnormal = []\nauct = []\nq = list(map(int, input().split()))\nsum = 0\nfor i in range(n):\n if i + 1 in q:\n auct.append(prices[i])\n else:\n sum += prices[i]\nauct = sorted(auct, reverse=True)\nfor elem in auct:\n sum += max(elem, sum)\nprint(sum)", "[n, m], q, a = map(int, input().split()), list(map(int, input().split())), list(map(int, input().split()))\r\nans = sum(q[x - 1] for x in set(range(1, n + 1)) - set(a))\r\nfor x in sorted(a, key = lambda x: q[x - 1], reverse = True):\r\n if q[x - 1] <= ans:\r\n ans <<= 1\r\n else:\r\n ans += q[x - 1]\r\nprint(ans)\r\n", "n, m = map(int, input().split())\nques = list(map(int,input().split()))\nacutions = set(map(int, input().split()))\n\nacu = []\npoints = 0\n\nfor i in range(n):\n\tif i + 1 in acutions:\n\t\tacu.append(ques[i])\n\telse:\n\t\tpoints += ques[i]\n\nacu.sort(reverse= True)\n\nfor a in acu:\n\tif points > a:\n\t\tpoints += points\n\telse:\n\t\tpoints += a\n\nprint(points)", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nfor i in range(len(b)):\r\n b[i] -= 1\r\nb = set(b)\r\nc = []\r\nd = []\r\nfor i in range(len(a)):\r\n if i in b:\r\n c.append(a[i])\r\n else:\r\n d.append(a[i])\r\nsum = 0\r\nfor i in range(len(d)):\r\n sum += d[i]\r\nc = sorted(c)\r\nif sum < c[-1]:\r\n sum += c[-1]\r\n sum *= (2**(len(c)-1))\r\nelse:\r\n sum *= (2**len(c))\r\nprint(sum)", "n,m=map(int,input().split())\r\narr=list(map(int,input().split()))\r\narr1=list(map(int,input().split()))\r\na=[];ans=0\r\nfor i in range(n):\r\n if i+1 in arr1:a.append(arr[i])\r\n else:ans+=arr[i]\r\na=sorted(a)[::-1]\r\nfor i in range(m):\r\n if ans>a[i]:ans+=ans\r\n else:ans+=a[i]\r\nprint(ans)\r\n", "R = lambda :map(int, input().split())\nn, m = R()\na = list(R())\nb = list(R())\nli = []\ncost = 0\nfor i in range(1, n + 1):\n if i not in b:\n cost += a[i - 1]\n else:\n li.append(a[i - 1])\nli.sort(reverse=True)\nfor i in range(m):\n cost += max(cost, li[i])\nprint(cost)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nyl3 jeopardy\r\n\"\"\"\r\na=lambda :list(map(int,input().split()))\r\nn,m=a()\r\nsa=a()\r\nsb=a()\r\nau=[]\r\n\r\nfor i in reversed(sorted(sb)):\r\n au.append(sa.pop(i-1))\r\nsu=sum(sa)\r\nau.sort(reverse=True)\r\nfor i in range(m):\r\n t=au.pop(0)\r\n if t>su:\r\n su+=t\r\n else:su*=2\r\nprint(su)", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nfor i in range(m):\r\n\tk=a[b[i]-1]\r\n\ta[b[i]-1]=0\r\n\tb[i]=k\r\ns=sum(a)\r\nb.sort()\r\nfor i in range(m-1,-1,-1):\r\n\tif s>=b[i]:\r\n\t\ts+=s\r\n\telse:\r\n\t\ts+=b[i]\r\nprint(s)", "n, m = map(int, input().split())\na = list(map(int, input().split()))\nb = [a[i - 1] for i in map(int, input().split())]\nb.sort(reverse = True)\ns = sum(a) - sum(b)\nfor i in b: s += s if i < s else i\nprint(s)\n\t \t\t\t \t\t \t \t\t \t \t \t \t", "n , m = map(int,input().split())\r\nque =list(map(int,input().split())) \r\nauc = list(map(int,input().split()))\r\ns = sum(que)\r\naa=[]\r\nfor i in auc:\r\n s-=que[i-1]\r\n aa.append(que[i-1])\r\naa.sort()\r\nfor i in aa[::-1]:\r\n if i<s:\r\n s*=2\r\n else:\r\n s+=i\r\nprint(s)", "from operator import itemgetter\n\nR = lambda:map(int, input().split())\n\nn, m = R()\n\na = list(R())\n\nb = [0] * n\n\nfor i in R():\n\n b[i - 1] = 1\n\na = sorted(enumerate(a), key=itemgetter(1), reverse=True)\n\ns = sum(x for i, x in a if b[i] != 1)\n\nfor i, x in a:\n\n if b[i] == 1:\n\n s += s if s > x else x\n\nprint(s)\n\n\n\n# Made By Mostafa_Khaled" ]
{"inputs": ["4 1\n1 3 7 5\n3", "3 2\n10 3 8\n2 3", "2 2\n100 200\n1 2", "1 1\n1\n1", "2 2\n1 5\n1 2", "5 3\n5 8 7 1 9\n2 5 3", "5 5\n9 1 6 2 1\n3 1 4 5 2", "25 5\n66 41 91 33 86 67 38 79 49 7 77 54 29 19 22 48 63 37 11 100 8 6 47 27 26\n12 14 1 23 18", "50 10\n19098 20847 65754 94580 54808 57092 23130 15638 43645 52323 52822 65193 90139 69196 83680 70109 96772 35102 56685 6692 30738 74558 57144 24054 44447 51959 22847 18735 23534 821 5540 39948 7552 72425 23213 2770 98496 81096 84868 167 36408 26572 19351 82775 23225 35377 63193 58352 45111 60889\n8 20 32 17 11 44 39 30 36 16", "2 1\n19 4\n1", "3 1\n65 81 6\n2", "5 1\n72 32 17 46 82\n2", "100 1\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14\n13", "25 24\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24", "30 30\n6074511 9621540 9853685 9073323 6897794 9366449 1648254 3848902 8729661 9330982 9970280 1886362 5605123 3406494 501290 3140164 2406173 346072 1520895 441795 5271130 7576116 337766 6666108 953354 5085881 2876195 8036150 1251715 4952594\n30 5 10 28 21 18 6 13 29 23 17 24 14 25 3 27 20 26 12 2 4 11 16 15 22 7 8 19 1 9", "50 30\n6015200 8643865 4116771 6555197 304415 8580071 8414182 3089212 5684567 7595481 1272699 7127763 3309618 1410297 4349070 2027355 136702 6863504 1800751 5585842 5924142 5188269 4805201 9313209 8941399 5137060 4983630 8467668 1646260 7804684 8646497 7067118 6896291 9109696 6197162 1366002 1703718 3852639 8427694 552915 5001315 5238093 9152085 7288325 8115109 3800240 5658858 4392321 8244056 3275379\n30 25 34 8 31 50 48 19 49 26 9 24 22 6 44 14 27 43 3 28 35 10 21 17 45 12 40 47 1 33", "1 1\n1846236\n1", "2 1\n8912260 7309391\n1", "3 1\n9949628 37460 9989934\n3", "5 3\n1819638 2087365 162773 9531053 130978\n3 1 4", "10 4\n886062 1016649 67899 9999839 98342 64636 816991 263 1050987 1858\n1 9 7 4", "10 10\n1 652210 1 1 1 1 1 1 1 1\n10 1 6 7 9 8 4 3 5 2", "50 5\n223036 65304 301127 8945 10289 15638 260 246 68 14 23 6 3 2 8 2 1 392212 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 242747 1 1 1 243737 1 1 1 1 1 1 10000000 572890\n18 50 38 42 49", "50 10\n1103 17631 1582 250 6933 26 14434 6 2 1 1 1 1 1 3625 1 5909 1 1 1 1 1 1 1 1 1 1 1 1 7196 14842 1 1 1 1 1 1 12053 9999991 1 10502 1 1 1 1 1 1 1 1 1\n41 15 17 1 5 31 7 38 30 39", "50 15\n369 139 49 15 4 5 1 1 1 365 1 1 1 1 484 165 105 1 1 1 382 105 1 1 1 72 1 1 91 96 1 1 1 1 1 133 9997031 1 1 31 1 1 1 291 558 1 1 1 464 1\n49 26 40 21 45 30 16 10 15 44 22 29 36 17 37", "50 18\n20 23 54 4 1 1 15 50 56 1 1 71 1 1 1 1 1 15 8 1 12 1 1 1 1 1 76 1 19 11 55 42 1 1 1 1 1 9 1 30 5 1 1 1 20 1 1 1 1 9975634\n9 18 7 45 27 32 12 41 31 8 3 30 21 19 40 38 29 50", "100 1\n954110 7577191 694644 113513 467690 71415 25351 26000 37902 29150 2015 94 741 20 71 9 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 10000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n78", "100 5\n502646 93620 4203 12132 2444 9620 6 201 4 20 10000000 1 6 9 472804 2 2 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 276285 518136 1 1 1 1 1 1 1 1 1 1 1 1 1 1 189005 1 1 1 1 1 1 1 1 1 1 1 1\n73 72 15 88 11", "100 10\n9999984 1396 8798 4760 3138 310 840 41 37 79 45 1 7 2 1 1 1 1 11032 1 1 1 11226 1 1 1 1 1 1 1 12147 1 1 1 1 1 1 16512 1 1 1 1 1 1 1 1 1 1 1 2658 1 1 1 1 7562 1 1 1 1 6207 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3334 1 1 1 1 1 1 1310 1 1 1 1 1 1 1 1 1\n19 55 91 50 31 23 60 84 38 1", "100 15\n380 122 2 18 5 2 3 242 1 1 1 1 1 64 1 1 1 1 1 198 323 284 1 419 1 225 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 584 1 1 1 55 9999036 1 1 1 1 1 1 1 1 447 1 1 471 1 1 1 1 1 1 1 374 1 1 1 1 1 1 1 1 1 1 1 273 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 68 1\n22 45 49 24 26 62 70 82 21 20 59 14 99 8 50", "100 16\n15 18 54 132 138 1 1 45 164 1 1 1 1 1 1 1 1 1 1 1 1 9999567 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 188 1 1 1 213 1 1 27 1 1 1 1 1 1 1 1 1 1 1 200 1 140 221 1 1 1 1 1 1 1 1 132 1 78 1 1 1 1 1 243 1 1 1 1 1 1 1 1 1 1 240 1 1 290 1 34 1 1 1 1 1 1\n92 46 8 58 94 39 9 89 61 60 4 70 78 72 43 22", "3 1\n1 2 4\n1", "3 1\n1 2 4\n2", "3 1\n1 2 4\n3", "2 1\n1 2\n1", "2 1\n1 2\n2", "3 2\n1 2 4\n1 2", "3 2\n1 2 4\n3 2", "3 2\n1 2 4\n3 1", "3 3\n4 2 1\n1 3 2", "5 4\n1 2 2 4 8\n1 2 4 5", "3 2\n10 7 1000\n2 3", "4 2\n2 2 4 8\n3 4", "3 2\n1 3 5\n1 3", "3 2\n10 1 12\n2 3", "4 2\n1 2 3 100\n2 4", "3 2\n10 5 200\n2 3", "3 2\n3 5 3\n2 3", "3 2\n5 4 100\n2 3", "5 4\n100 200 300 400 500\n1 2 3 5", "3 2\n100 200 180\n1 2", "4 3\n2 5 17 4\n1 2 3", "5 2\n2 2 4 7 15\n4 5", "3 2\n200 100 1000\n2 3", "4 2\n2 2 2 7\n1 4", "8 4\n2 2 2 2 1 2 3 9\n5 6 7 8", "3 2\n2 1 5\n2 3"], "outputs": ["18", "40", "400", "1", "10", "60", "144", "29056", "1880325120", "23", "152", "434", "8834", "70368752566272", "5352753316495360", "96888048737845248", "1846236", "16221651", "19977022", "46997584", "89995888", "333931520", "170000000", "5129995264", "163801350144", "1307536261120", "20000000", "170000000", "5129991680", "163834200064", "327675805696", "12", "10", "7", "4", "3", "16", "10", "12", "16", "80", "2020", "24", "16", "44", "208", "420", "16", "210", "7200", "760", "84", "46", "2400", "22", "136", "14"]}
UNKNOWN
PYTHON3
CODEFORCES
28
158444ebd70a822da08f95e3843ab7e3
Wizards and Demonstration
Some country is populated by wizards. They want to organize a demonstration. There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people. The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=&gt;<=*n*). Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). Sample Input 10 1 14 20 10 50 1000 352 146 Sample Output 1 0 1108
[ "import math\r\nn,x,y=map(int,input().split())\r\nk=math.ceil(y*n/100)\r\nif k>x:\r\n print(k-x)\r\nelse:\r\n print(0)\r\n", "n,x,y = map(int,input().split())\r\nimport math\r\nif((x/n)*100>=y):\r\n print(0)\r\nelse:\r\n z = math.ceil((y*n)/100)\r\n print(z-x)", "import math\r\nn,w,p=list(map(int,input().split()))\r\nm=math.ceil((n*p)/100)\r\nif w>=m:\r\n print(\"0\")\r\nelse:\r\n print(m-w)\r\n", "n,x,y = input().split()\r\nn=int(n)\r\nx=int(x)\r\ny=int(y)\r\n\r\np=(y/100)*n\r\n\r\nif(p!=int(p)):\r\n p=int(p+1)\r\nelse:\r\n p=int(p)\r\n\r\nr=p-x\r\nif(r>=0):\r\n print(r)\r\nelse:\r\n print(0)\r\n", "n,x,y=map(int,input().split())\r\nb=((n*y)/100)\r\nm=((n*y)%100)\r\nif b > x :\r\n if m:\r\n print((int(b)+1)-x) \r\n else:\r\n print(int(b)-x)\r\nelse :\r\n print(0)", "n, x, y = map(int, input().strip().split())\n\nanswer = max(0, - ((-y * n)//100) - x)\n\nprint(answer)", "from math import ceil\nn,x,y = map(int,input().split())\nprint(max(0,ceil((n*y)/100 - x)))\n", "n, x, y = map(int, input().split())\r\n\r\nprint(max(0, -x--n*y//100))", "def main():\n [n, x, y] = [int(_) for _ in input().split()]\n a = n / 100 * y - x\n\n if a <= 0:\n print(0)\n else:\n from math import ceil\n print(ceil(a))\n\n\nif __name__ == '__main__':\n main()\n", "import math\r\nn,x,y=map(int,input().split())\r\nd=math.ceil((y/100)*n)\r\nif(int(d)>x):\r\n print(int(d)-x)\r\nelif(int(d)<=x):\r\n print(0)\r\n", "import math\nn, x, z = map(int, input().split())\nprint(max(0, math.ceil(n / 100 * z) - x))\n", "def wizard():\r\n\tk = 3\r\n\tn, x, y = list(map(int,input().strip().split()))[:k]\r\n\tc = int((-1*((n*y)/100- x ))//1*-1) \r\n\tif c > 0 :\r\n\t return c\r\n\telse:\r\n\t return 0\r\n\r\nprint(wizard())", "import math\r\nn,x,y=map(int,input().split())\r\nxx=max(0,math.ceil(n*y/100)-x)\r\nprint(xx)", "import math\r\nn, x, y = map(int, input().split())\r\nreq = math.ceil(y/100 * n)\r\nans = req - x\r\nif ans > 0:\r\n print(ans)\r\nelse:\r\n print(0)", "n,x,y=list(map(int,input().split()))\r\nprint(max((int(n*y/100+.99999)-x),0))", "import math\r\nn,x,y = map(int, input().split())\r\nprint(max(math.ceil(n*y/100 - x), 0 ))", "\r\nfrom math import ceil\r\nn, x, y = list(map(int, input().split()))\r\nfinal = (ceil((n * y) / 100)) - x\r\nif final < 0:\r\n print(0)\r\nelse:\r\n print(final)\r\n\r\n# CodeForcesian\r\n# ♥\r\n# اگه ایمان داری که روزای خوب تو راهن\r\n# روزای خوب قطعا به سمتت میاد\r\n", "import math\r\nn, x, y = map(int, input().split())\r\nif n * y / 100 < x:\r\n print(0)\r\nelse:\r\n print(math.ceil(n * y / 100 - x))\r\n", "import math\r\na,b,c=map(int,input().split())\r\nprint(math.ceil(-min(0,-a*c/100+b)))", "\r\nn,x,y=map(int,input().split())\r\nc=0\r\nwhile True:\r\n p=(x*100)/n\r\n if p>=y:\r\n print(c);break\r\n x+=1;c+=1\r\n", "l=input()\nl=l.split()\nn=int(l[0])\nx=int(l[1])\ny=int(l[2])\n#print((y*n)//100)\n#print(-(y*n))\n#print(-(y*n)//100) divisao inteira em python arredonda pra baixo\nk=(-(-(y*n)//100))\n#print(k)\nk=k-x\nif k>=0:\n print(k)\nelse:\n print('0')\n", "import math\r\n\r\nS = input().split()\r\n\r\nn = int(S[0])\r\nx = int(S[1])\r\ny = int(S[2])\r\n\r\nneeded = math.ceil(y/100*n)\r\n\r\nif needed-x > 0:\r\n print(needed-x)\r\nelse:\r\n print(0)\r\n\r\n", "import math\r\na,b,c = map(int, input().split())\r\nprint(max(0, math.ceil((a * c) / 100) - b))", "import io\nimport os\n#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\n\nimport math\n\ndef main():\n n, x, y = map(int, input().split())\n c = 0\n while math.floor((x+c)/n*100) < y:\n c += 1\n print(c)\n\nif __name__ == '__main__':\n main()\n", "n,x,y = map(int,input().split())\r\n\r\nif (n*y)%100==0:\r\n if x<((n*y)//100):\r\n print((n*y)//100 - x)\r\n \r\n else:\r\n print(0)\r\n \r\nelse:\r\n res = ((n*y)//100)+1\r\n \r\n if x<res:\r\n print(res-x)\r\n else:\r\n print(0)", "def f(l):\r\n n,x,y = l\r\n return max((n*y+99)//100-x,0)\r\n\r\nl = list(map(int,input().split()))\r\nprint(f(l))\r\n\r\n", "n, x, y = map(int, input().split())\r\nif (n * y) % 100 == 0:\r\n moo = int(n * y / 100)\r\nelse:\r\n moo = int(n * y / 100) + 1\r\nif x >= moo:\r\n print(0)\r\nelse:\r\n print(moo - x)", "n,x,y=map(int,input().split())\r\nc=y*n//100\r\nif (y*n)%100!=0:\r\n c+=1\r\nprint(max(0,c-x))", "n,x,y=map(int,input().split())\n\nfrom math import ceil\n\nr=ceil(n*y/100)\n\nprint(max(0,r-x))\n", "n,m,k=[int(x) for x in input().split(' ')]\nper=(n*k+99)//100\nprint(max(0,per-m))", "a = input()\r\na = a.split()\r\nx = int(a[0])\r\ny = int(a[1])\r\nz = int(a[2])\r\nans = 0\r\nwhile x*z/100 > y+ans:\r\n ans += 1\r\nprint(ans)", "from math import ceil\r\nn,x,y = list(map(int, input().split(\" \")))\r\nprint(ceil(n*y/100)-x if ceil(n*y/100)-x>0 else 0)", "import math\r\nn,x,y = [int (x) for x in input().split()]\r\nr = int(math.ceil((y/100)*n))\r\nif(r>x):\r\n diff = abs(x-r)\r\n print(diff)\r\nelse:\r\n print('0')", "import math\r\nn, x, y = map(int, input().split(\" \"))\r\np = n * y / 100\r\nif x >= math.ceil(p):\r\n print(0)\r\nelse:\r\n print(abs(math.ceil(p) - x))", "from math import ceil\r\na,b,c = map(int,input().split())\r\nt = c/100\r\n# print(b/a)\r\n# print(t-b/a)\r\nif t <= b/a:\r\n\tprint(0)\r\nelse: \r\n\tl = float(\"{:.4f}\".format(a*(t-(b/a))))\r\n\tprint(ceil(l))\r\n", "import math\nn,x,y=map(int,input().split())\no=(n*(y/100))-x\nif o<0:\n print(0)\nelse:\n print(math.ceil(o))\n\n \t \t \t\t\t\t\t \t \t \t \t\t \t \t \t", "n,w,p=map(int,input().split())\r\np=p/100\r\nor_w=w\r\nper=w/n\r\nwhile per<p:\r\n w+=1\r\n per=w/n\r\nprint(w-or_w)", "import math\n\nn, x, y = map(float, input().split())\nrequired = math.ceil((n * y / 100) - x)\nprint(required if required >= 0 else 0)\n", "import math\r\nimport sys\r\n\r\nsys.setrecursionlimit(1000)\r\nn, x, y = map(int, input().split())\r\nprint(max(0, math.ceil(n * y / 100) - x))\r\n", "import math\r\nn,x,y=map(int,input().split())\r\nk=math.ceil((y*n)/100)-x\r\nif k>=0:print(k)\r\nelse:print(0)", "import math\r\none,two,three = [int(x) for x in input().split()]\r\ntemp = math.ceil(one * (three/100));\r\ntemp -= two\r\nif temp <= 0: \r\n print(\"0\")\r\nelse:\r\n print(temp)", "import math\nn, x, y = map(int, input().split())\np = math.ceil(n*(y/100))\nif x >= p:\n print(0)\nelse :\n print(p - x)", "import math\r\n\r\nn,x,y = map(int, input().split())\r\n\r\nv = int(math.ceil((y * n)/100))\r\n\r\nif v > x:\r\n \r\n print(v - x)\r\n \r\nelse:\r\n \r\n print(0)", "n, x, y = map(int, input().split())\r\n\r\nw = x\r\n\r\ny /= 100\r\nans = 0\r\n\r\nwhile w/n < y:\r\n w += 1\r\n ans += 1\r\nprint(ans)\r\n", "import math\r\nn, x, y = map(int, input().split())\r\n\r\nneeded = (y/100 * n)\r\n\r\nans = math.ceil(max(0, needed-x))\r\n\r\nprint(ans)\r\n\r\n\r\n", "import math\r\nn,x,y = map(int,input().split(' '))\r\nprint (max(0,math.ceil((y*n)/100-x)))", "def per(x, y):\r\n return x / y * 100\r\na,b,c = map(int, input().split())\r\nd = per(b, a)\r\ncnt = 0\r\nwhile d < c:\r\n cnt += 1\r\n d = per(b + cnt, a)\r\nprint(cnt)", "import math as m\r\nn,x,y=map(int,input().split())\r\nif (x/n)*100>=y:\r\n print(0)\r\nelse:\r\n ans=m.ceil((n*y)/100)-x\r\n print(ans)\r\n", "import math\r\nn , x , y = map(int, input().split())\r\npercentage = math.ceil(y*n/100)\r\nprint(max(0, percentage-x))", "import math\r\n\r\nn, x, y = map(int, input().split())\r\n\r\nprint(max(0,math.ceil(y * n / 100) - x))\r\n", "n,x,y=list(map(int,input().split()))\r\nc=0\r\np=(y*n)/100\r\n#print(p)\r\nif x>=p:\r\n c=0\r\nelse:\r\n if int(p)!=p:\r\n p=int(p)+1\r\n else:\r\n p=int(p)\r\n #print(p)\r\n c=p-x\r\nprint(c)\r\n \r\n", "import math\n\nn, x, y = map(int, input().split())\n\nclones = math.ceil(n*y/100)-x\n\nprint(clones if clones > 0 else 0)\n", "# python3\r\nimport sys, threading, os.path\r\nimport collections, heapq, math,bisect\r\nimport string\r\nfrom platform import python_version\r\nimport itertools\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,x,y = list(map(int, input.readline().split()))\r\n per = math.ceil((y/100)*n)\r\n if per > x :\r\n output = per - x\r\n else:\r\n output = 0 \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()", "import math\r\nnumber_of_testcases = 1 #int(input())\r\nfor _ in range(number_of_testcases):\r\n num_citizen, num_wizard, percentage_demonstration = map(int,input().split())\r\n num_clones_needed = int(math.ceil((num_citizen * percentage_demonstration)/100.0))\r\n #print(num_clones_needed)\r\n if num_wizard >= num_clones_needed:\r\n print(0)\r\n else:\r\n print(num_clones_needed - num_wizard)\r\n", "import math\r\nn, x, y = map(int, input().split())\r\nans = max(0, math.ceil(y / 100 * n) - x)\r\nprint(ans)", "n,x,y=map(int,input().split())\r\nz=n*(y*0.01)\r\nm=z-int(z)\r\nif m<0.00000000001:\r\n if z>x:\r\n print(int(z-x))\r\n else:\r\n print(\"0\")\r\nelse:\r\n if (z+1)>x:\r\n print(int(z+1-x))\r\n else:\r\n print(\"0\")\r\n \r\n", "# cook your dish here\r\nimport math\r\nn,x,y = map(int, input().split())\r\nre = (y*n)/100\r\nr = math.ceil(re)\r\nif x>=r:\r\n print(\"0\")\r\nelse:\r\n print(r - x)", "#n = int(input())\n#x = int(input())\n#y = int(input())\ninp = list(map(int,input().split()))\nminXNeeded = int(inp[2]/100*inp[0])\nif inp[2]*inp[0] % 100 != 0:\n minXNeeded = minXNeeded+1\nif inp[1] >= minXNeeded:\n print(\"0\")\nelse:\n print(str(minXNeeded-inp[1]))", "from math import ceil\r\nn, x, y = list(map(int, input().split()))\r\nans = float(y / 100) * n\r\nif ((ceil(ans) - x) < 0):\r\n print(0)\r\nelse:\r\n print(ceil(ans) - x)", "n, x, y = [int(x) for x in input().split()]\r\nprint(max(0, (n * y - 100 * x + 99) // 100))", "#!/usr/bin/python3\n\ndef readln(): return tuple(map(int, input().split()))\n\nfrom math import ceil\nn, x, y = readln()\nprint(max(0, ceil(n * y / 100) - x))\n", "# Problem Statement - http://codeforces.com/problemset/problem/168/A\r\n\r\nfrom math import ceil\r\n\r\nn, x, y = map(int, input().split())\r\npercent = ceil((y*n/100))\r\n\r\nclone = percent - x\r\n\r\nif clone < 0:\r\n print(0)\r\nelse:\r\n print(clone)", "from math import ceil\r\n\r\n\r\ndef magicians(n, x, y):\r\n z = ceil(n * y / 100)\r\n if x < z:\r\n return z - x\r\n return 0\r\n\r\n\r\nN, X, Y = [int(i) for i in input().split()]\r\nprint(magicians(N, X, Y))\r\n", "n,x,y = map(int,input().split())\r\nans = (n*y+99)//100 - x\r\nprint(max(ans,0))\r\n", "from math import ceil\r\nn, x, y = map(int, input().split())\r\np = ceil(n/100*y)\r\nprint(p-x) if p>=x else print(0)\r\n\r\n", "n, x, y = input().split(\" \")\nn = int(n)\nx = int(x)\ny = int(y)\n\nnx = n - x\npp = 0\nwhile ((x + pp)/n) * 100 < y:\n pp += 1\nprint(pp)\n", "from math import ceil \r\nn,x,y=map(int,input().split())\r\nreq=ceil(n*y/100)\r\nif x>=req:\r\n print(0)\r\nelse:\r\n print(req-x)", "import math\n\n\ndef main():\n n, x, y = map(int, input().split())\n print(max(0, math.ceil(n / 100 * y) - x))\n\n\nif __name__ == '__main__':\n main()\n", "n,x,y=map(int,input().split())\r\np=(n*y)/100\r\nif (p)%1==0:\r\n if p>x:\r\n\r\n print(int(p-x))\r\n else:\r\n print(0)\r\n\r\nelse:\r\n if int(p)-x+1>0:\r\n print(int(p)-x+1)\r\n else:\r\n print(0)", "n,x,y = map(int,input().split())\r\n\r\nneed = (n*y+99)//100 - x\r\nprint(max(need,0))\r\n", "n, x, y = map(int, input().split())\r\nneed = int(n * y / 100) + (n * y % 100 != 0)\r\nprint(max(0, need - x))", "a, b, c = map(int, input().split())\r\na = (c * a + 99) // 100\r\nprint(0 if a - b < 0 else a - b)\r\n", "from math import ceil\r\n\r\n\r\nn,x,y = map(int,input().split())\r\nmaxsz = ceil(n*(y/100))\r\nprint(0 if x>=maxsz else maxsz-x)\r\n", "n, x, y = map(int,input().split())\r\nprint(max(0,int(n * y // 100 + (n * y % 100 != 0) - x)))\r\n", "n,x,y=map(int,input().split())\r\nif((n*y)%100):\r\n if(int(n*y/100)+1<x):\r\n print(0)\r\n else:\r\n print(int(n*y/100)+1-x)\r\nelse:\r\n if(int(n*y/100)<x):\r\n print(0)\r\n else:\r\n print(int(n*y/100)-x)", "n,x,y=map(int,input().split())\r\nprint(max(0,-(-n*y//100)-x))", "import math\r\nn,x,y=map(int,input().split())\r\nreq=math.ceil(y/100*n)\r\n\r\nprint(max(0,req-x))\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\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, x, y = map(int, input().split())\r\nprint(max(0, int(n/100*y-x+0.9999999999)))", "n,x,y=map(int,input().split())\r\nvisitors=(y*n)/100\r\nif visitors%1!=0:\r\n result=int(visitors+1)-x\r\nelse:\r\n result=int(visitors)-x\r\nif result<0:\r\n print(0)\r\nelse:\r\n print(result)", "import math\r\nfrom bisect import bisect_left,bisect,bisect_right\r\nfrom itertools import accumulate\r\n\r\ndef index(a, x):\r\n 'Locate the leftmost value exactly equal to x'\r\n i = bisect_left(a, x)\r\n if i != len(a) and a[i] == x:\r\n return i\r\n raise ValueError\r\n\r\ndef find_lt(a, x):\r\n 'Find rightmost value less than x'\r\n i = bisect_left(a, x)\r\n if i:\r\n return a[i-1]\r\n raise ValueError\r\n\r\ndef find_le(a, x):\r\n 'Find rightmost value less than or equal to x'\r\n i = bisect_right(a, x)\r\n if i:\r\n return a[i-1]\r\n raise ValueError\r\n\r\ndef find_gt(a, x):\r\n 'Find leftmost value greater than x'\r\n i = bisect_right(a, x)\r\n if i != len(a):\r\n return a[i]\r\n raise ValueError\r\n\r\ndef find_ge(a, x):\r\n 'Find leftmost item greater than or equal to x'\r\n i = bisect_left(a, x)\r\n if i != len(a):\r\n return a[i]\r\n raise ValueError\r\n\r\n\r\n\r\nst=''\r\n\r\ndef func(n,x,y):\r\n return max(0,math.ceil(y*n/100)-x)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nfor _ in range(1):#int(input())):\r\n n,a,b=map(int,input().split())\r\n #n = int(input())\r\n #inp=input().split()\r\n #s=input()\r\n #l1=[]\r\n #l1=list(map(int,input().split()))\r\n #l1=list(accumulate(list(map(int,input().split()))))\r\n #q=int(input())\r\n #l2 = list(map(int, input().split()))\r\n #l1=input().split()\r\n #l2=input().split()\r\n #func(n,m)\r\n st+=str(int(func(n,a,b)))+'\\n'\r\nprint(st)", "n,x,y = map(float , input().split())\r\nl = x\r\nwhile( (l/n)*100 < y):\r\n l = l+1\r\nprint( int(l - x))", "import math\r\nn, x, y = map(int, input().split())\r\nr = (n * y) / 100\r\nif r <= x:\r\n print(0)\r\nelse:\r\n print(math.ceil(r - x))", "from sys import stdin, stdout\r\n\r\nn, x, y = map(int, stdin.readline().split())\r\n\r\nif (x / n) * 100 >= y:\r\n stdout.write('0')\r\nelse:\r\n l = 0\r\n r = n * y\r\n \r\n while r - l > 1:\r\n m = (r + l) // 2\r\n \r\n if (x + m) / n * 100 >= y:\r\n r = m\r\n else:\r\n l = m\r\n \r\n stdout.write(str(r))", "n, wizards, percent = map(int, input().split())\nimport math\npeople = math.ceil(percent*n/100)\nif people <= wizards:\n print(0)\nelse:\n print(people - wizards)\n", "import math\n\ndata = input().split()\n\nN, X, Y = int(data[0]), int(data[1]), int(data[2])\n\nclones = math.ceil(N * (Y/100)) - X\n\nif clones > 0:\n print(clones)\nelse:\n print(0)\n", "n, x, y = map(int, input().split())\r\nneeded = (n * y + 99) // 100\r\nprint(max(0, needed - x))\r\n", "n,x,y=[int(x) for x in input().split()]\r\nif (n*y)%100==0:\r\n res=(n*y)//100\r\nelse:\r\n res=(n*y)//100+1\r\nif res<=x:\r\n print(0)\r\nelse:\r\n print(res-x)", "# x,y=[int(i)for i in input().split()]\r\n# a,b,c=[int(i)for i in input().split()]\r\n# f=0\r\n# if c*2>=a+b:\r\n# f+=x*a+y*b\r\n# elif x>=y:\r\n# f+=c*2*y+(x-y)*a\r\n# else:\r\n# f+=c*2*x+(y-x)*b\r\n# print(f)\r\n# x=[int(i)for i in input().split()]\r\n# x.sort()\r\n# print(x[-1]+x[-2]+x[-3])\r\n# m='0123456789ABCDEF'\r\n# g=''\r\n# i=int(input())\r\n# def sq(x,b):\r\n# r=''\r\n# while x:\r\n# r=m[x%b]+r\r\n# x=x//b\r\n# return r\r\n# def pal(i):\r\n# l=0\r\n# r=len(i)-1\r\n# while l<r:\r\n# if i[l]!=i[r]:\r\n# return False\r\n# l+=1\r\n# r-=1\r\n# return True\r\n# for q in range(2,17):\r\n# if pal(sq(i,q)):\r\n# g+=str(q)+' '\r\n# if g=='':\r\n# print('No')\r\n# else:\r\n# print('Yes')\r\n# print(g)\r\n# k,w=[int(i)for i in input().split()]\r\n# x=input()\r\n# b=input()\r\n# x+=' '+b\r\n# cnt=0\r\n# g=''\r\n# a=[int(i)for i in x.split()]\r\n# a.sort()\r\n# for i in range(2*k-1):\r\n# if a[i]==a[i+1]:\r\n# g+=str(a[i])+' '\r\n# cnt+=1\r\n# print(cnt)\r\n# print(g)\r\n#abcd\r\n ##.#a\r\n#...#b\r\n #...c\r\n ####d\r\n# n,m=[int(i)for i in input().split()]\r\n# a=[]\r\n# ans=0\r\n# for iin in range(n):\r\n# a.append(input())\r\n# def f (r,c):\r\n# cnt=1\r\n# for i in range(r-1,-1,-1):\r\n# if a[i][c]=='#':break\r\n# cnt+=1\r\n# for i in range(r+1,n):\r\n# if a[i][c]=='#':break\r\n# cnt+=1\r\n# for i in range(c+1,n):\r\n# if a[r][i]=='#':break\r\n# cnt+=1\r\n# for i in range(c-1,-1,-1):\r\n# if a[r][i]=='#':break\r\n# cnt+=1\r\n# return cnt\r\n# for i in range(n):\r\n# for q in range(m):\r\n# if a[i][q]=='#':continue\r\n# if f(i,q)>ans:\r\n# ans=f(i,q)\r\n# print(ans)\r\n# a,b=[int(i)for i in input().split()]\r\n# c=int(input())\r\n# a//=c\r\n# b//=c\r\n# print(a*b)\r\n# n=int(input())\r\n# a=[int(i)for i in input().split()]\r\n# a.sort(reverse=True)\r\n# cnt=0\r\n# g=0\r\n# for i in range(n):\r\n# if g==2:\r\n# g=0\r\n# continue\r\n# cnt+=a[i]\r\n# g+=1\r\n# print(cnt)\r\n# n=int(input())\r\n# a={}\r\n# for i in range(n):\r\n# c,l=input().split()\r\n# a[c]=l\r\n# c=[]\r\n# l=[]\r\n# g=int(input())\r\n# x=[]\r\n# for i in range(g):\r\n# t=input().split()\r\n# x.append(t)\r\n# nm,nd=[int(i)for i in input().split('-')]\r\n# dd=[0,31,29,31,30,31,30,31,31,30,31,30,31]\r\n# def d_day(date):\r\n# m,d=[int(i)for i in date.split('-')]\r\n# if m==nm:return nd-d\r\n# else:return nd+dd[m]-d \r\n# for i in range(g-1,-1,-1):\r\n# if d_day(x[i][0])>14:break\r\n# l.append(a.get(x[i][1]))\r\n# if x[i][1] in c:continue\r\n# c.append(x[i][1])\r\n# b=[]\r\n# for i in range(len(c)):\r\n# if l[i]=='M':\r\n# b.append(c[i])\r\n# b.append('(M),')\r\n# elif l[i]=='H':\r\n# b.append(c[i])\r\n# b.append('(H),') \r\n# else:\r\n# b.append(c[i])\r\n# b.append(',')\r\n# c=''\r\n# for i in range(len(b)-1):\r\n# c+=b[i]\r\n# if '(H)'in c:\r\n# print('Red')\r\n# elif '(M)'in c:\r\n# print('Yellow')\r\n# else:\r\n# print(\"Green\")\r\n# print(c)\r\n# n=int(input()) \r\n# a=[[0 for i in range(1000)]for j in range(1000)]\r\n# x=[0,0,1,-1]\r\n# y=[-1,1,0,0]\r\n# nc=0\r\n# def valid(col,row):\r\n# return row>=0 and row<=1000 and col>=0 and col<=1000\r\n# def comfy(row,col):\r\n# cnt=0\r\n# if a[row][col]==0:return False\r\n# if a[row-1][col]==1 and valid(col,row-1):cnt+=1\r\n# if a[row+1][col]==1 and valid(col,row+1):cnt+=1\r\n# if a[row][col-1]==1 and valid(col-1,row):cnt+=1 \r\n# if a[row][col+1]==1 and valid(col+1,row):cnt+=1\r\n# return cnt==3\r\n# for i in range(n):\r\n# row,col=[int(i)for i in input().split()]\r\n# if comfy(row+1,col) and valid(col,row+1): \r\n# nc-=1\r\n# if comfy(row-1,col) and valid(col,row-1): \r\n# nc-=1\r\n# if comfy(row,col+1) and valid(col+1,row): \r\n# nc-=1\r\n# if comfy(row,col-1) and valid(col-1,row): \r\n# nc-=1\r\n# a[row][col]=1\r\n# if comfy(row+1,col) and valid(col,row+1):\r\n# nc+=1\r\n# if comfy(row-1,col) and valid(col,row-1):\r\n# nc+=1\r\n# if comfy(row,col+1) and valid(col+1,row):\r\n# nc+=1\r\n# if comfy(row,col-1) and valid(col-1,row):\r\n# nc+=1\r\n# if comfy(row,col):\r\n# nc+=1\r\n# print(nc)\r\n\r\n\r\n# with open('gymnastics.in','r') as f:\r\n# k,n=[int(i)for i in f.readline().split()]\r\n# r=[]\r\n# cnt=0\r\n# for i in range(k):\r\n# r.append([int(i)for i in f.readline().split()])\r\n# def plus(a,b):\r\n# num=0\r\n# for i in r:\r\n# if i.index(a)<i.index(b):\r\n# num+=1\r\n# return num==0 or num==k\r\n# for a in range(1,n):\r\n# for b in range(a+1,n+1):\r\n# if plus(a,b):\r\n# cnt+=1\r\n# with open('gymnastics.out','w') as f:\r\n# f.write(str(cnt))\r\n\r\n\r\n# n=int(input())\r\n# def turn(a,b):\r\n# if a==b:return 0\r\n# elif a=='N' and b=='W' or a=='W' and b=='S' or a=='S' and b=='E' or a=='E' and b=='N':return 90\r\n# else:return -90\r\n# for f in range(n):\r\n# cnt=0\r\n# g=input()\r\n# for i in range(len(g)):\r\n# if i==len(g)-1:cnt+=turn(g[i],g[0])\r\n# else:cnt+=turn(g[i],g[i+1])\r\n# if cnt==360:print(\"CCW\")\r\n# else:print(\"CW\")\r\n\r\n\r\n\r\n\r\n# import sys\r\n# sys.stdin = open('guess.in', 'r')\r\n# sys.stdout = open('guess.out', 'w')\r\n'''\r\n ssssssssssssssssssssredvf\r\n ddgfdhb\r\n sredhbdfh\r\n dfhgtf\r\n hsrfgdf\r\n htgfrhsrthtfgjd\r\n rtgherhgtjkmgcyuj\r\n dgsgrst\r\n gyzfgsdg\r\n dsrfgdzfgdfhgkmcgfj\r\n thjftgjfcgyjk hmrtgthbfgj\r\n fgjfcgjgjnfg\r\n hjghmghv\r\n jghmgch,jk.vjhg,mjh,hbvhnftgmmfmd\r\n hgsdgvsgbdfxjmn\r\n fgjgykhgjjjukghjcfhdrtfgsdcVds\r\n gfdbfhnfgnjjgc cfg\r\n ngfh\r\n mfgjhtdgfbnghmncfdhnghfjghmn cfvgbngcn\r\n fnfg\r\n'''\r\n# n=int(input())\r\n# a=input()\r\n# cnt=1\r\n# for k in range(1,n+1):\r\n# cnt=0\r\n# for x in range(n):\r\n# if a[x+1:].count(a[x:x+k]):\r\n# cnt=1\r\n# break\r\n# if cnt==0:\r\n# print(k)\r\n# break\r\n# dudhudhudhcudhcduchd\r\n# jcdchdchdjchduchducduvgydgvydvef\r\n# euhfehefguerf\r\n \r\n\r\n\r\nfrom itertools import permutations\r\nfrom typing import MappingView\r\n# cows = ['Bessie', 'Buttercup', 'Belinda', 'Beatrice', 'Bella', 'Blue', 'Betsy', 'Sue','Stone','Zag']\r\n# cows.sort()\r\n# for i in permutations(cows):\r\n# print(i)\r\n\r\n# from itertools import permutations\r\n# cs=int(input())\r\n# a,b=[],[]\r\n# xb=0\r\n# for i in range(cs):\r\n# t=input().split()\r\n# a.append(t[0])\r\n# b.append(t[-1])\r\n# def sb(a,b,c):\r\n# return abs(c.index(a)-c.index(b))==1\r\n# cows = ['Bessie', 'Buttercup', 'Belinda', 'Beatrice', \\\r\n# 'Bella', 'Blue', 'Betsy', 'Sue']\r\n# cows.sort()\r\n# for f in permutations(cows):\r\n# xb=1\r\n# for i in range(cs):\r\n# if not sb(a[i],b[i],f):\r\n# xb=0\r\n# break\r\n# if xb==1:\r\n# for j in f:\r\n# print(j)\r\n# break\r\n \r\n\r\n# n,k=[int(i)for i in input().split()]\r\n# cnt=0\r\n# a=input().split()\r\n# for i in range(n):\r\n# if i == 0:\r\n# print(a[i], end = '')\r\n# cnt += len(a[i])\r\n# elif cnt + len(a[i]) <= k:\r\n# print(' ' + a[i], end = '')\r\n# cnt += len(a[i])\r\n# elif cnt + len(a[i]) > k:\r\n# print('\\n' + a[i], end = '')\r\n# cnt = len(a[i])\r\n\r\n\r\n \r\n# n=int(input())\r\n# a=[int(i)for i in input().split()]\r\n# x=[]\r\n# cnt=0\r\n# f=0\r\n# for b in range(1,n+1):\r\n# x.append(b)\r\n# for i in permutations(x):\r\n# cnt=0\r\n# for j in range(n-1):\r\n# if j==n-2:\r\n# f=n-1\r\n# if i[j]+i[j+1]!=a[j]:\r\n# cnt=1\r\n# break\r\n# else:\r\n# cnt=0\r\n# if cnt==0:\r\n# for k in i:\r\n# if k==i[-1]:\r\n# print(k,end='')\r\n# break\r\n# print(k,end=' ')\r\n# break\r\n\r\n\r\n\r\n\r\n\r\n# a,b=[int(i)for i in input().split()]\r\n# x,y=[int(i)for i in input().split()]\r\n# cnt=0\r\n# if a>b:\r\n# print(0)\r\n# elif a<=b and x<=y:\r\n# print('Impossible')\r\n# else:\r\n# while a<=b:\r\n# a+=x\r\n# b+=y\r\n# cnt+=1\r\n# print(cnt)\r\n \r\n\r\n \r\n\r\n \r\n\r\n\r\n# n=int(input())\r\n# o=['','I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']\r\n# s=['','X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC']\r\n# t=['','C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM']\r\n# f=['','M', 'MM', 'MMM']\r\n# print(f[n//1000],end='')\r\n# print(t[(n//100)%10],end='')\r\n# print(s[(n//10)%10],end='')\r\n# print(o[(n//1)%10],end='')\r\n\r\n\r\n# from math import*\r\n# n=int(input())\r\n# f=int(sqrt(n))+1\r\n# for i in range(f):\r\n# for j in range(i,f):\r\n# for k in range(j,f):\r\n# for a in range(k,f):\r\n# if i*i+j*j+k*k+a*a==n:\r\n# print(i,j,k,a)\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=[int(i)for i in input().split()]\r\n# st=[]\r\n# cnt=0\r\n# for i in range(1,n+1):\r\n# st.append(i)\r\n# while st and a[cnt]==st[-1] and cnt<n :\r\n# st.pop()\r\n# cnt+=1\r\n# if st:\r\n# print('Invalid')\r\n# else:\r\n# print('Valid')\r\n\r\n\r\n\r\n# n=int(input())\r\n# b=[int(i)for i in input().split()]\r\n# a=[0]*n\r\n# for i in range(1,n+1):\r\n# a[0]=i\r\n# flag=1\r\n# for j in range(1,n):\r\n# a[j]=b[j-1]-a[j-1]\r\n# if a[j]<1 or a[j]>n:flag=0\r\n# if len(set(a))!=len(a):flag=0\r\n# if flag:\r\n# for k in range(n):\r\n# if k==n-1:print(a[k])\r\n# else:print(a[k],end=' ')\r\n\r\n\r\n\r\n# k,n=[int(i)for i in input().split()]\r\n# for i in range(n):\r\n# x=int(input())\r\n# s=1\r\n# l,r=0,0\r\n# cnt=0\r\n# while 1:\r\n# l+=s\r\n# cnt+=1\r\n# if l+r>=k:\r\n# print(cnt)\r\n# break\r\n# if s>=x:\r\n# r+=s\r\n# cnt+=1\r\n# if l+r>=k:\r\n# print(cnt)\r\n# break\r\n# s+=1\r\n \r\n\r\n\r\n# from math import *\r\n# n=int(input())\r\n# a=[]\r\n# h=[]\r\n# for i in range(n):\r\n# t=[int(i)for i in input().split()]\r\n# a.append(t)\r\n# b=[]\r\n# for i in range(n):\r\n# for j in range(1,n):\r\n# for k in range(2,n):\r\n# if a[i][0]==a[j][0]:\r\n# c=0\r\n# b=0\r\n# c=min(a[i],a[j])\r\n# b=max(a[i],a[j])\r\n# if c[1]==a[i][1] and c[1]!=a[i] or c[1]==a[j][1] and c[1]!=a[j] or c[1]==a[k][1] and c[1]!=a[k]:\r\n# h.append(abs(b[1]-c[1])*abs(a[k][0]-c[0]))\r\n# if a[i][0]==a[k][0]:\r\n# c=0\r\n# b=0\r\n# c=min(a[i],a[k])\r\n# b=max(a[i],a[k])\r\n# if c[1]==a[i][1] and c[1]!=a[i] or c[1]==a[j][1] and c[1]!=a[j] or c[1]==a[k][1] and c[1]!=a[k]:\r\n# h.append(abs(b[1]-c[1])*abs(a[j][0]-c[0]))\r\n# if a[k][0]==a[j][0]:\r\n# c=0\r\n# b=0\r\n# c=min(a[k],a[j])\r\n# b=max(a[k],a[j])\r\n# if c[1]==a[i][1] and c[1]!=a[i] or c[1]==a[j][1] and c[1]!=a[j] or c[1]==a[k][1] and c[1]!=a[k]: \r\n# h.append(abs(b[1]-c[1])*abs(a[i][0]-c[0]))\r\n\r\n# print(max(h))\r\n\r\n\r\n \r\n\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\n# a=input()\r\n# b=input()\r\n# cnt=0\r\n# f=0\r\n# for i in range(n):\r\n# if a[i]!=b[i] and f==1:\r\n# pass\r\n# elif a[i]!=b[i]:\r\n# cnt+=1\r\n# f=1\r\n# else:\r\n# f=0\r\n# print(cnt)\r\n\r\n\r\n\r\n\r\n# n,k=[int(i)for i in input().split()]\r\n# a=[int(i)for i in input().split()]\r\n# b=[int(i)for i in input().split()]\r\n# c=[]\r\n\r\n# for i in range(1,n+1):\r\n# c.append(i)\r\n# def next(x):\r\n# if x<=a[1] and x>=a[0]:x=a[0]+a[1]-x\r\n# if x<=b[1] and x>=b[0]:x=b[0]+b[1]-x\r\n# return x\r\n# for x in range(1,n+1):\r\n# cnt = 1\r\n# f = next(x)\r\n# while f != x:\r\n# f = next(f)\r\n# cnt += 1\r\n# cnt = k % cnt\r\n# for j in range(cnt):\r\n# f = next(f)\r\n# c[f-1]=x\r\n\r\n# for i in c:\r\n# print(i)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n# a=[int(i)for i in input().split()]\r\n# b=[int(i)for i in input().split()]\r\n# c=[int(i)for i in input().split()]\r\n# def mix(a,b):\r\n# t=min(a[1],b[0]-b[1])\r\n# a[1]-=t\r\n# b[1]+=t\r\n# mix(a,b)\r\n# mix(b,c)\r\n# mix(c,a)\r\n# mix(a,b)\r\n# print(a[1])\r\n# print(b[1])\r\n# print(c[1])\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=[]\r\n# cnt=0\r\n# for i in range(n):\r\n# t=[int(i)for i in input().split()]\r\n# a.append(t)\r\n# for i in range(1,1001):\r\n# zoom=0\r\n# for j in range(n):\r\n# if i>=a[j][0] and i<=a[j][1]:\r\n# zoom+=a[j][2]\r\n# cnt=max(cnt,zoom)\r\n# print(cnt)\r\n\r\n\r\n# from sys import *\r\n# from copy import *\r\n# a=[int(i)for i in input().split()]\r\n# b=[int(i)for i in input().split()]\r\n# milk=1000\r\n# res=set()\r\n# def Tues(a,b,milk):\r\n# A=copy(a)\r\n# B=copy(b)\r\n# A.remove(i)\r\n# B.remove(i)\r\n# Wed(A,B,milk-i)\r\n# def Wed(a,b,milk):\r\n# A=copy(a)\r\n# B=copy(b)\r\n# A.remove(i)\r\n# B.remove(i)\r\n# Thur(A,B,milk-i)\r\n# def Thur(a,b,milk):\r\n# A=copy(a)\r\n# B=copy(b)\r\n# A.remove(i)\r\n# B.remove(i)\r\n# Fri(A,B,milk-i)\r\n# def Fri(a,b,milk):\r\n# for i in b:\r\n# res.add(milk+i) \r\n# Tues(a,b,1000)\r\n# print(len(res))\r\n\r\n\r\n\r\n# import math\r\n# n,k=[int(i)for i in input().split()]\r\n# ans=math.ceil(n*2/k)\r\n# if ans==1:\r\n# print('2')\r\n# else:\r\n# print(ans)\r\n\r\n# n=int(input())\r\n# while 1:\r\n# if n==1:\r\n# break\r\n# if n%2==0:\r\n# n/=2\r\n# elif n%3==0:\r\n# n/=3\r\n# elif n%5==0:\r\n# n/=5\r\n# else:\r\n# print('Irregular Number')\r\n# break\r\n# if n==1:\r\n# print('Regular Number')\r\n\r\n\r\n\r\n\r\n# n,m=[int(i)for i in input().split()]\r\n# a=[int(i)for i in input().split()]\r\n# cnt=m//a[0]\r\n# rmb=m%a[0]\r\n# for i in range(1,n):\r\n# if a[i]<a[i-1]:\r\n# rmb+=a[i-1]*cnt\r\n# cnt=rmb//a[i]\r\n# rmb=rmb%a[i]\r\n# else:\r\n# rmb+=cnt*a[i]\r\n# cnt=rmb//a[i]\r\n# rmb=rmb%a[i]\r\n# print(cnt*a[-1]+rmb)\r\n\r\n\r\n# n=int(input())\r\n# a=[]\r\n# for i in range(n):\r\n# t=[int(i)for i in input().split('-')]\r\n# a.append(t)\r\n# ans=min(a)\r\n# print(f\"{ans[0]}-{ans[1]:02d}-{ans[2]:02d}\")\r\n\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=[]\r\n# for i in range(n):\r\n# t=[int(i)for i in input().split()]\r\n# a.append(t)\r\n# cnt=-1\r\n# f=0\r\n# for j in range(1,4):\r\n# under=j\r\n# for i in range(n):\r\n# if a[i][0]==under:\r\n# under=a[i][1]\r\n# elif a[i][1]==under:\r\n# under=a[i][0]\r\n# if a[i][2]==under:\r\n# f+=1\r\n# cnt=max(f,cnt)\r\n# f=0\r\n# print(cnt)XXX\r\n\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=[int(i)for i in input().split()]\r\n# f=n-1\r\n\r\n# for i in range(n-1,0,-1):\r\n# if a[i-1]>a[i]:\r\n# break\r\n# else:\r\n# f-=1\r\n\r\n# print(f)\r\n\r\n\r\n\r\n# a=[]\r\n# n=int(input())\r\n# for i in range(n):\r\n# a.append(input().split()[2:])\r\n# def solve(a,b):\r\n# cnt=1\r\n# for i in a:\r\n# if i in b:\r\n# cnt+=1\r\n# return cnt\r\n# res=0\r\n# for i in range(n):\r\n# for j in range(n):\r\n# if a[i]==a[j]:\r\n# continue\r\n# res=max(solve(a[i],a[j]),res)\r\n# print(res) \r\n\r\n\r\n# a=[int(i)for i in input().split()]\r\n# a.sort()\r\n# if a[0]+1==a[1] and a[1]+1==a[2]:\r\n# print('0')\r\n# elif a[1]-a[0]==2 or a[2]-a[1]==2:\r\n# print('1')\r\n# else:\r\n# print('2')\r\n# print(max(a[1]-a[0],a[2]-a[1])-1)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n# n,m=[int(1)for i in input().split()]\r\n# a,b=[],[]\r\n# g=[1]*(n+1)\r\n# for i in range(m):\r\n# t=[int(i)for i in input().split()]\r\n# a.append(min(t))\r\n# b.append(max(t))\r\n# for i in range(m+1):\r\n# for j in range(1,5):\r\n# cnt=1\r\n# for k in range(n):\r\n# if b[k]==i and g[a[k]]==j:\r\n# cnt=0\r\n# break\r\n# if cnt:\r\n# break\r\n# print(j,end='')\r\n# g[i]=j\r\n\r\n# n=sorted([int(i)for i in input().split()])\r\n# y=n[1]\r\n# x=n[0]\r\n# z=max(n)-x-y\r\n# print(x,y,z)\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=[]\r\n# lower,upper=0,1000\r\n# for i in range(n):\r\n# t=input().split()\r\n# a.append([t[0],int(t[1]),int(t[2])])\r\n# for i in range(n-1,-1,-1):\r\n# if a[i][0]=='off':\r\n# lower+=a[i][1]\r\n# upper+=a[i][2] \r\n# elif a[i][0]=='none':\r\n# lower=max(lower,a[i][1])\r\n# upper=min(upper,a[i][2])\r\n# else:\r\n# upper-=a[i][1]\r\n# lower-=a[i][2]\r\n# print(max(lower,0),upper) \r\n# lower,upper=0,1000\r\n# for i in range(n):\r\n# if a[i][0]=='on':\r\n# lower+=a[i][1]\r\n# upper+=a[i][2] \r\n# elif a[i][0]=='none':\r\n# lower=max(lower,a[i][1])\r\n# upper=min(upper,a[i][2])\r\n# else:\r\n# upper-=a[i][1]\r\n# lower-=a[i][2]\r\n# print(max(lower,0),upper) \r\n\r\n\r\n\r\n\r\n# a=[int(i)for i in input().split()]\r\n# b=[int(i)for i in input().split()]\r\n# c=[int(i)for i in input().split()]\r\n# aa=max(a[0],c[0])\r\n# bb=min(a[3],c[3])\r\n# qq=min(a[2],c[2])\r\n# rr=max(a[1],c[1])\r\n# cc=max(b[0],c[0])\r\n# dd=min(b[3],c[3])\r\n# xx=min(b[2],c[2])\r\n# zz=max(b[1],c[1])\r\n# ans=(a[2]-a[0])*(a[3]-a[1])+(b[2]-b[0])*(b[3]-b[1])-(max((qq-aa),0)*max((bb-rr),0)+max((xx-cc),0)*max((dd-zz),0))\r\n# print(max(ans,0))\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=[int(i)-1 for i in input().split()]\r\n# b=[int(i)for i in input().split()]\r\n# for i in range(3):\r\n# t=[0]*n\r\n# for j in range(n):\r\n# t[j]=b[a[j]]\r\n# a=t\r\n# for i in a:print(i)\r\n\r\n\r\n\r\n# b=[int(i)for i in input().split()]\r\n# a=[int(i)for i in input().split()]\r\n# cnt=0\r\n# if a[0]<=b[0]<=a[2] and a[1]<=b[1]<=a[3]:\r\n# cnt+=1\r\n# if a[0]<=b[2]<=a[2] and a[1]<=b[1]<=a[3]:\r\n# cnt+=1\r\n# if a[0]<=b[2]<=a[2] and a[1]<=b[3]<=a[3]:\r\n# cnt+=1\r\n# if a[0]<=b[0]<=a[2] and a[1]<=b[3]<=a[3]:\r\n# cnt+=1\r\n# if cnt<=1:\r\n# print((b[2]-b[0])*(b[3]-b[1]))\r\n# if cnt==4:\r\n# print(0)\r\n# if cnt==2:\r\n# print(abs((abs(max(a[0],b[0])-min(a[2],b[2])))*(abs(max(a[1],b[1])-min(a[3],b[3])))-(b[2]-b[0])*(b[3]-b[1])))\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=[]\r\n# f=0\r\n# s=0\r\n# x=0\r\n# for i in range(n):\r\n# t=[int(i)for i in input().split()]\r\n# a.append(t)\r\n# b=[0]*1001\r\n# for i in range(n):\r\n# for j in range(a[i][0],a[i][1]):\r\n# b[j]+=1\r\n# if b[j]==1:\r\n# f+=1\r\n# for i in range(n):\r\n# s=0\r\n# for j in range(a[i][0],a[i][1]):\r\n# if b[j]==1:\r\n# s+=1\r\n# x=max(x,f-s)\r\n# print(x)\r\n \r\n\r\n# n=int(input())\r\n# a=[int(i)for i in input().split()]\r\n# cnt=n\r\n# for i in range(n):\r\n# for j in range(i+1,n):\r\n# t=a[i:j+1]\r\n# if sum(t)/len(t) in t:\r\n# cnt+=1\r\n# print(cnt)\r\n\r\n \r\n# a,b,c,d=[int(i)for i in input().split()]\r\n# print(min(min(abs(d-a),abs(c-a))+min(abs(d-b),abs(c-b)),abs(b-a)))\r\n\r\n\r\n# n=int(input())\r\n# a=[]\r\n# cnt=0\r\n# for i in range(n):\r\n# a.append(int(input()))\r\n# b=sorted(a)\r\n# for i in range(n):\r\n# if a[i]!=b[i]:\r\n# cnt+=1\r\n# print(cnt-1)\r\n\r\n\r\n# a=input()\r\n# b=input()\r\n# cnt=1\r\n# for i in range(len(b)-1):\r\n# if b[i]==b[i+1]:\r\n# cnt+=1\r\n# elif a.index(b[i])>a.index(b[i+1]):\r\n# cnt+=1\r\n# print(cnt)\r\n\r\n# n=int(input())\r\n# a=[[0]*3 for i in range (101)]\r\n# b=[[0]*3 for i in range (101)]\r\n# cnt=0\r\n# xyz=3\r\n# zyx=0\r\n# for i in range(n):\r\n# t=input().split()\r\n# if t[1]=='Bessie':b[int(t[0])][0]=int(t[2]) \r\n# elif t[1]=='Mildred':b[int(t[0])][1]=int(t[2])\r\n# else:b[int(t[0])][2]=int(t[2])\r\n# a[0][0],a[0][1],a[0][2]==7\r\n# def highest(i,j):\r\n# t=max(a[i][0],a[i][1],a[i][2])\r\n# return t==a[i][j]\r\n# for i in range(1,101):\r\n# a[i][0]=a[i-1][0]+b[i][0]\r\n# a[i][1]=a[i-1][1]+b[i][1]\r\n# a[i][2]=a[i-1][2]+b[i][2]\r\n# if highest(i,0)!=highest(i-1,0) or highest(i,1)!=highest(i-1,1) or highest(i,2)!=highest(i-1,2):\r\n# cnt+=1\r\n# print(cnt)\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# f=0\r\n# even,odd=0,0\r\n# a=[int(i)for i in input().split()]\r\n# for i in a:\r\n# if i%2==0:\r\n# even+=1\r\n# else:\r\n# odd+=1\r\n# while even<odd:\r\n# even+=1\r\n# odd-=2\r\n# if even>odd:\r\n# even=odd+1 \r\n# print(even+odd)\r\n\r\n\r\n\r\n# a=[1,0,0,0,1,0,1,0,2,1]\r\n# n=input()\r\n# cnt=0\r\n# for i in n:\r\n# cnt+=a[int(i)]\r\n# print(cnt)\r\n\r\n\r\n# x,cnt,a=int(input()),0,sorted([int(i)for i in input().split()])\r\n# for i in range(-2,-(x*2+2),-2):cnt+=a[i]\r\n# print(cnt)\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# cow=sorted([int(i)for i in input().split()],reverse=True)\r\n# high=[int(i)for i in input().split()]\r\n# cnt,f,h=1,0,0\r\n# for i in cow:\r\n# for j in high:\r\n# if i<=j:\r\n# f+=1\r\n# cnt*=f-h\r\n# f=0\r\n# h+=1\r\n# print(cnt)\r\n\r\n# n,l=[int(i)for i in input().split()]\r\n# a=sorted([int(i)for i in input().split()],reverse=True)\r\n# def coconut():\r\n# h=n\r\n# while h>0 and a[h-1]<h:\r\n# h-=1\r\n# return h\r\n# h=coconut()\r\n# while l and h>=0:\r\n# a[h]+=1\r\n# h-=1\r\n# l-=1\r\n# a.sort(reverse=True)\r\n# h=coconut()\r\n# print(h)\r\n\r\n# z=0\r\n# n,m=[int(i)for i in input().split()]\r\n# a=[]\r\n# x,y=[1,-1,-1,1],[1,-1,-1,1]\r\n# st=set()\r\n# for i in range(n):\r\n# a.append(input())\r\n# print(a)\r\n# def isok(x,y):\r\n# if x>-1 and x<m and y>-1 and y<n:\r\n# return True\r\n# return False\r\n# for i in range(n):\r\n# for j in range(m):\r\n# if a[i][j]!='G':\r\n# continue\r\n# for k in range(2):\r\n# cnt=0\r\n# s=x[k]\r\n# if isok((a[i]+s).index(),(a[i][j]).index()) and a[i][j]=='C':\r\n# cnt+=1\r\n# for k in range(2):\r\n# cnt=0\r\n# s=x[k]\r\n# if isok(a[i],a[i][j]+s) and a[i][j]=='C':\r\n# cnt+=1\r\n# if cnt==2:\r\n# st.add((tuple(a[i][j])).sort())\r\n# else:\r\n# cnt+=1\r\n# z+=cnt\r\n# print(z) \r\n \r\n\r\n\r\n\r\n# k,n=[int(i)for i in input().split()]\r\n# a=[]\r\n# g=0\r\n# cnt=0\r\n# for i in range(k):\r\n# a.append([int(i)for i in input().split()])\r\n# for i in range(1,n+1):\r\n# for j in range(i+1,n+1):\r\n# for z in range(k):\r\n# if a[z].index(i)>a[z].index(j):\r\n# g+=1\r\n# elif a[z].index(i)<a[z].index(j):\r\n# g-=1\r\n# if g==k or g==k-2*k:\r\n# cnt+=1\r\n# g=0\r\n# print(cnt)\r\n\r\n \r\n\r\n# import sys \r\n# x=sorted(['Beatrice','Sue','Belinda','Bessie','Betsy','Blue','Bella','Buttercup'])\r\n# n=int(input())\r\n# a=[]\r\n# cnt=0\r\n# for i in range(n):\r\n# t=input().split()\r\n# a.append([t[0],t[-1]])\r\n# for i in permutations(x):\r\n# for j in range(n):\r\n# if abs(i.index(a[j][0])-i.index(a[j][1]))!=1:\r\n# cnt=1\r\n# if cnt==0:\r\n# for k in i:\r\n# print(k)\r\n# sys.exit()\r\n# cnt=0\r\n\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=[int(i)for i in input().split()]\r\n# b=[int(i)for i in input().split()]\r\n# ace=[a[i]-b[i]for i in input().split()]\r\n# cnt=0\r\n# while 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111:\r\n# for i in range(n):\r\n# f,f1,f2=0,0,0\r\n# if ace[i]==0:\r\n# f1,f2=1,1\r\n# elif ace[i]>0 :\r\n# ace[i]-=1\r\n# if f1==0:\r\n# cnt+=1\r\n# f,f1,f2=0,1,0\r\n# elif ace[i]<0:\r\n# ace[i]+=1\r\n# if f2==0:\r\n# cnt==1\r\n# f,f1,f2=0,0,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# n=int(input())\r\n# a=input()\r\n# h=0\r\n# g=0\r\n# for i in a:\r\n# if i=='G':\r\n# g+=1\r\n# else:\r\n# h+=1\r\n# print(g)\r\n# print(h)\r\n# print(g-1+h-1)\r\n\r\n\r\n\r\n\r\n# n,s,cnt=int(input()),input(),0\r\n# for i in range(n-2):\r\n# h,g=0,0\r\n# for j in range(i,n):\r\n# if s[j]=='G':\r\n# g+=1\r\n# else:\r\n# h+=1\r\n# if j-i>1 and (h==1 or g==1):\r\n# cnt+=1\r\n# if h>1 and g>1:\r\n# break\r\n# print(cnt)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n# t=int(input())\r\n# def score():\r\n# cnt=0\r\n# n,k=[int(i) for i in input().split()]\r\n# a=[]\r\n# for i in range(n):\r\n# a.append(input())\r\n# if k>=1:\r\n# rd,dr=1,1\r\n# for j in range(n):\r\n# if a[0][j]=='H' or a[j][-1]=='H':\r\n# rd=0\r\n# if a[j][0]=='H' or a[-1][j]=='H':\r\n# dr=0\r\n# cnt+=rd+dr\r\n# if k>=2:\r\n# for i in range(1,n-1):\r\n# rdr,drd=1,1\r\n# for j in range(0,n):\r\n# if j<i and a[j][0]=='H':\r\n# drd=0\r\n# if a[i][j]=='H':\r\n# drd=0\r\n# if j>i and a[j][-1]=='H':\r\n# drd=0\r\n# if i<j and a[-1][j]=='H':\r\n# rdr=0\r\n# if a[j][i]=='H':\r\n# rdr=0\r\n# if i>j and a[0][j]=='H':\r\n# rdr=0\r\n# cnt+=rdr+drd\r\n# if k>=3:\r\n# for i in range(1,n-1):\r\n# for j in range(1,n-1):\r\n# if a[i][j]=='H':continue\r\n# rdrd=1\r\n# for l in range(n):\r\n# if l<=i and a[0][l]=='H':rdrd=0\r\n# if l<=i and a[l][j]=='H':rdrd=0\r\n# if l>=j and a[i][l]=='H':rdrd=0\r\n# if l>=i and a[l][n-1]=='H':rdrd=0\r\n# cnt+=rdrd\r\n# drdr=1\r\n# for l in range(n):\r\n# if l<=i and a[0][l]=='H':drdr=0\r\n# if l<=i and a[l][j]=='H':drdr=0\r\n# if l>=j and a[i][l]=='H':drdr=0\r\n# if l>=i and a[l][n-1]=='H':drdr=0\r\n# cnt+=drdr\r\n# print(cnt)\r\n# for i in range(t):\r\n# score()\r\n \r\n\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=input()\r\n# b=input()\r\n# cnt=0\r\n# flag=0\r\n# for i in range(n):\r\n# if a[i]!=b[i] and flag==1:cnt+=0\r\n# elif a[i]!=b[i]:\r\n# cnt+=1\r\n# flag=1\r\n# else:flag=0\r\n# print(cnt)\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=[]\r\n# o=0\r\n# cnt=0\r\n# for i in range(n):\r\n# t=input().split()\r\n# a.append(t[2:])\r\n# def solve(i,j):\r\n# cnt=0\r\n# for k in a[i]:\r\n# if k in a[j]:\r\n# cnt+=1\r\n# return cnt\r\n# ans=0\r\n# for i in range(n):\r\n# for j in range(n):\r\n# if i==j:continue\r\n# else:ans=max(ans,solve(i,j))\r\n# print(ans+1)\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# if n!=2 and n%2==0:print('YES')\r\n# else:print('NO')\r\n\r\n\r\n\r\n# n=int(input())\r\n# for i in range(n):\r\n# t=input()\r\n# if len(t)<11: print(t)\r\n# else:\r\n# print(t[0],end='')\r\n# print(len(t)-2,end='')\r\n# print(t[-1])\r\n\r\n\r\n\r\n\r\n# n,cnt=int(input()),0\r\n# for i in range(n):\r\n# t=[int(i)for i in input().split()]\r\n# if t.count(1)>1:cnt+=1\r\n# print(cnt)\r\n\r\n\r\n\r\n\r\n\r\n# n,k=[int(i)for i in input().split()]\r\n# a=sorted([int(i)for i in input().split()],reverse=True)\r\n# cnt=0\r\n# for i in range(n):\r\n# if a[i]>0 and a[i]>=a[k-1]:\r\n# cnt+=1\r\n# print(cnt)\r\n\r\n\r\n# a,b=[int(i)for i in input().split()]\r\n# print(a*b//2)\r\n\r\n\r\n\r\n# n,x=int(input()),0\r\n# for i in range(n):\r\n# t=input()\r\n# for j in t:\r\n# if '+'==j:\r\n# x+=1\r\n# break\r\n# elif '-'==j:\r\n# x-=1\r\n# break\r\n# print(x)\r\n\r\n# a=[]\r\n# for i in range(5):a.append([int(i)for i in input().split()])\r\n# for i in range(5):\r\n# for j in range(5):\r\n# if a[i][j]==1:print(abs(i-2)+abs(j-2))\r\n\r\n\r\n# a=input().upper()\r\n# b=input().upper()\r\n# if a==b:print(0)\r\n# elif a<b:print(-1)\r\n# else:print(1)\r\n\r\n# a=sorted([int(i)for i in input().split('+')])\r\n# for i in range(len(a)):\r\n# if i==len(a)-1:\r\n# print(a[i])\r\n# else:\r\n# print(a[i],end='')\r\n# print('+',end='')\r\n\r\n\r\n\r\n\r\n# a=input()\r\n# print(a[0].upper()+a[1:])\r\n\r\n\r\n\r\n# n=int(input())\r\n# a,cnt=input(),0\r\n# for i in range(n-1):\r\n# if a[i+1]==a[i]:cnt+=1\r\n# print(cnt)\r\n\r\n\r\n\r\n\r\n# a,cnt=input(),0\r\n# for i in range(97,123):\r\n# if chr(i) in a:cnt+=1\r\n# if cnt%2==0:print('CHAT WITH HER!')\r\n# else:print('IGNORE HIM!')\r\n \r\n\r\n\r\n\r\n\r\n# a,b=[int(i)for i in input().split()]\r\n# cnt=0\r\n# while True:\r\n# if a>b:\r\n# print(cnt)\r\n# break\r\n\r\n# a*=3\r\n# b*=2\r\n# cnt+=1\r\n\r\n\r\n\r\n\r\n# k,n,w=[int(i)for i in input().split()]\r\n# cnt=0\r\n# for i in range(1,w+1):cnt+=i\r\n# if int(k*cnt-n)<=0:print(0)\r\n# else:print(int(k*cnt-n))\r\n\r\n# n,ans=int(input()),0\r\n# if n%5>0:ans+=1\r\n# ans+=n//5\r\n# print(ans)\r\n\r\n\r\n\r\n# a,lower,upper=input(),0,0\r\n# for i in a:\r\n# if ord(i)<97:upper+=1\r\n# else:lower+=1\r\n# if upper>lower:print(a.upper())\r\n# elif lower>upper:print(a.lower())\r\n# else:print(a.lower())\r\n\r\n\r\n\r\n\r\n# a,b=[int(i)for i in input().split()]\r\n# for i in range(b):\r\n# if a%10==0:a/=10\r\n# else:a-=1\r\n# print(int(a))\r\n\r\n\r\n\r\n# n=int(input())\r\n# cnt,o=0,0\r\n# for i in range(1,n):\r\n# t=[int(i)for i in input().split()]\r\n# cnt-=t[0]\r\n# cnt+=t[1]\r\n# o=max(o,cnt)\r\n# print(o)\r\n\r\n\r\n\r\n\r\n\r\n# n,t=[int(i)for i in input().split()]\r\n# a,b,x=input() ,'',''\r\n# for i in range(n-1):\r\n# if t==0:\r\n# print(a)\r\n# break\r\n# if a[i]=='B'and a[i+1]=='G':\r\n\r\n\r\n\r\n# n,cnt=input(),0\r\n# for i in n:\r\n# if i=='7' or i=='4':cnt+=1\r\n# if cnt==7 or cnt==4:print('YES')\r\n# else:print('NO')\r\n\r\n\r\nimport sys\r\n# a=input()\r\n# b,cnt=input(),-1\r\n# for i in a:\r\n# if i==b[cnt]:pass\r\n# else:\r\n# print('NO')\r\n# sys.exit()\r\n# cnt-=1\r\n# print('YES')\r\n\r\n\r\n# n,a,d=int(input()),0,0\r\n# a=input()\r\n# for i in a:\r\n# print(i)\r\n# if i=='A':a+=1\r\n# else:d+=1\r\n# if a>d:print('Anton')\r\n# elif d>a:('Danik')\r\n# else:print('Friendship')\r\n\r\n\r\n# n,k=[int(i)for i in input().split()]\r\n# a=[int(i)for i in input().split()]\r\n# cnt=n\r\n# for i in a:\r\n# if i>k:cnt+=1\r\n# print(cnt)\r\n\r\n\r\n\r\n# a=int(input())\r\n# flag=0\r\n# while 1:\r\n# a+=1\r\n# for i in range(len(str(a))):\r\n# for j in range(i,len(str(a))):\r\n# if i==j:flag=1\r\n# if flag==0:\r\n# print(a)\r\n# break\r\n# flag=0\r\n\r\n\r\n# n,cnt=int(input()),0\r\n# for i in range(n):\r\n# t=[int(i)for i in input().split()]\r\n# if t[0]+2<=t[1]:cnt+=1\r\n# print(cnt)\r\n\r\n\r\n# n,cnt,o=int(input()),0,100\r\n# for i in range(n):\r\n# t=int(input())\r\n# if o!=t:cnt+=1\r\n# o=t\r\n# print(cnt)\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=[int(i)for i in input().split()]\r\n# for i in range(n):\r\n# if a[i]==1:\r\n# print('hard')\r\n# sys.exit()\r\n# print('easy')\r\n\r\n\r\n# n,flag=int(input()),0\r\n# for i in range(1,n+1):\r\n# if flag==1:n+=1*i\r\n# else:n+=1*n-2*n\r\n# print(n)\r\n\r\n\r\n\r\n# n,t=[int(i)for i in input().split()]\r\n# a=list(input())\r\n# for i in range(t):\r\n# j=0\r\n# while j<n-1:\r\n# if a[j]=='B' and a[j+1]=='G':\r\n# a[j],a[j+1]=a[j+1],a[j]\r\n# j+=2\r\n# else:j+=1\r\n# print(''.join(a))\r\n\r\n\r\n\r\n\r\n# n,flag,cnt=int(input()),0,0\r\n# for i in range(1,n+1):\r\n# if flag==1:\r\n# cnt+=1*n\r\n# flag=0\r\n# else:\r\n# cnt+=-1*n\r\n# flag=0\r\n# print(cnt)\r\n\r\n\r\n\r\n# a=input()\r\n# b=input()\r\n# c=[]\r\n# for i in range(len(a)):\r\n# if a[i]=='1' and b[i]=='1':\r\n# c.append(0)\r\n# elif a[i]=='1' and b[i]=='0' or a[i]=='0' and b[i]=='1':\r\n# c.append(1)\r\n# else:\r\n# c.append(0)\r\n# for i in c:\r\n# print(i,end='')\r\n\r\n\r\n\r\n\r\n\r\n\r\n# n,flag=int(input()),0\r\n# for i in range(1,n+1):\r\n# if i==n:\r\n# if i%2==0:print('I love it')\r\n# else:print('I hate it')\r\n# break\r\n# if i%2==0:print('I love that',end=' ')\r\n# else:print('I hate that',end=' ')\r\n\r\n\r\n\r\n# a,cnt,lost,f=[int(i)for i in input().split()],0,[],0\r\n# for i in range(len(a)):\r\n# if a.count(a[i])>1 and a[i] not in lost:\r\n# cnt+=1\r\n# lost.append(a[i])\r\n# f+=a.count(a[i])-2\r\n# print(cnt+f)\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=[int(i)for i in input().split()]\r\n# b=[int(i)for i in input().split()]\r\n# for i in range(1,n+1):\r\n# if i in a or i in b:pass\r\n# else:\r\n# print('Oh, my keyboard!')\r\n# sys.exit()\r\n# print('I become the guy.')\r\n\r\n\r\n\r\n# n,cnt=int(input()),0\r\n# for i in range(n):\r\n# t=[int(i)for i in input().split()]\r\n# if t[0]<t[1]:\r\n# print(t[1]-t[0])\r\n# else:\r\n# cnt=t[0]\r\n# while t[0]%t[1]!=0:\r\n# t[0]+=1\r\n# print(t[0]-cnt)\r\n# cnt=0\r\n\r\n\r\n# a,cnt=input(),0\r\n# for i in range(97,123):\r\n# if chr(i) in a:cnt+=1\r\n# print(cnt)\r\n\r\n\r\n# n=int(input())\r\n# a,cnt=input().lower(),0\r\n# for i in range(97,123):\r\n# if chr(i) in a:cnt+=1\r\n# if cnt>=26:print('YES')\r\n# else:print('NO')\r\n\r\n\r\n# n,cnt=int(input()),0\r\n# cnt+=n//100\r\n# n%=100\r\n# cnt+=n//20\r\n# n%=20\r\n# cnt+=n//10\r\n# n%=10\r\n# cnt+=n//5\r\n# n%=5\r\n# cnt+=n//1\r\n# print(cnt)\r\n\r\n\r\n\r\n# a=input().split()\r\n# b=input().split()\r\n# c=input().split()\r\n# for i in range(len(c)):\r\n# if c[i] in a or c[i] in b:\r\n# c.pop(c[i])\r\n# a.pop(a.index(c[i]))\r\n# b.pop(b.index(c[i]))\r\n# else:\r\n# print('NO')\r\n# sys.exit()\r\n# print('YES')\r\n\r\n\r\n\r\n# n=int(input())\r\n# for i in range(n):\r\n# t=int(input())\r\n# if t<3:print(0)\r\n# elif t%2==0:print(int(t/2-1))\r\n# else:print(int(t/2))\r\n\r\n\r\n\r\n# n=int(input())\r\n# a,cnt=[int(i)for i in input().split()],0\r\n# h,o=a[0],a[0]\r\n# for i in range(1,len(a)):\r\n# if a[i]<o:\r\n# o=a[i]\r\n# cnt+=1\r\n# elif a[i]>h:\r\n# h=a[i]\r\n# cnt+=1\r\n# print(cnt)\r\n\r\n\r\n\r\n# n,k=[int(i)for i in input().split()]\r\n# cnt=0\r\n# for i in range(1,n+1):\r\n# if k+i*5>240:break\r\n# k+=i*5\r\n# cnt+=1\r\n# print(cnt)\r\n\r\n\r\n# a,b=[int(i)for i in input().split()]\r\n# cnt=0\r\n# while a>0 and b>0:\r\n# cnt+=1\r\n# a-=1\r\n# b-=1\r\n# print(cnt, end=' ')\r\n# cnt=0\r\n# while a>0 or b>0:\r\n# a-=2\r\n# b-=2\r\n# if a<0 and b<0:break\r\n# cnt+=1\r\n# print(cnt)\r\n \r\n\r\n\r\n\r\n# n,cnt,s=int(input()),0,0\r\n# a=[int(i)for i in input().split()]\r\n# for i in range(n):\r\n# if a[i]>0:s+=a[i]\r\n# elif a[i]<0 and s==0:cnt+=a[i]\r\n# else:s+=a[i]\r\n# print(abs(cnt))\r\n\r\n\r\n# n=int(input())\r\n# for i in range(n):\r\n# a,b=[int(i)for i in input().split()]\r\n# if a==b:\r\n# print(0)\r\n# continue\r\n# elif a<b:\r\n# if (b-a)%10==0:print(int((b-a)/10))\r\n# else:print(int((b-a)/10)+1)\r\n# else:\r\n# if (a-b)%10==0:print(int((a-b)/10))\r\n# else:print(int((a-b)/10)+1)\r\n\r\n\r\n\r\n# k,r=[int(i)for i in input().split()]\r\n# cnt=0\r\n# for i in range(1,11):\r\n# if k*i%10==0:\r\n# print(i)\r\n# sys.exit()\r\n# elif k*i%10==r:\r\n# print(i)\r\n# sys.exit()\r\n\r\n\r\n\r\n\r\n\r\n\r\n# x=int(input())\r\n# def solve():\r\n# n=int(input())\r\n# a=sorted([int(i)for i in input().split()])\r\n# for i in range(n-1):\r\n# if abs(a[i]-a[i+1])>1:\r\n# print('NO')\r\n# return\r\n# print('YES')\r\n# for i in range(x):\r\n# solve()\r\n\r\n\r\n# n=int(input())+1\r\n# def solve(n):\r\n# for i in range(4):\r\n# for j in range(i+1,4):\r\n# if n[i]==n[j]:return True\r\n# return False\r\n\r\n\r\n# while 1:\r\n# if solve(str(n)):\r\n# n+=1\r\n# else:\r\n# print(n)\r\n# break\r\n\r\n\r\n\r\n# n=int(input())\r\n# b=input()\r\n# a,d=0,0\r\n# for i in b:\r\n# if i=='D':d+=1\r\n# else:a+=1\r\n# if d>a:print('Danik')\r\n# elif d<a:print('Anton')\r\n# else:print('Friendship')\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=[0]+[int(i)for i in input().split()]\r\n# b=[0]*(n+1)\r\n# for i in range(1,n+1):\r\n# b[a[i]]=i\r\n# for i in range(1,n+1):\r\n# print(b[i],end=' ')\r\n\r\n\r\n\r\n\r\n\r\n# a=[]\r\n# b=[]\r\n# g=0\r\n# for i in range(3):\r\n# a.append(input())\r\n# for i in range(3):\r\n# b.append(input())\r\n# A=[0]*26\r\n# B=[0]*26\r\n# for i in range(3):\r\n# for j in range(3):\r\n# if a[i][j]==b[i][j]:g+=1\r\n# else:\r\n# A[ord(a[i][j])-65]+=1\r\n# B[ord(b[i][j])-65]+=1\r\n# y=0\r\n# for i in range(26):\r\n# y+=min(A[i],B[i])\r\n# print(g)\r\n# print(y)\r\n\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# def bre():\r\n# for i in range(len(a)):\r\n# for j in range(i+1,len(a)):\r\n# if a[i]!=a[j]:\r\n# return False\r\n# return True\r\n# def che(a):\r\n# for i in a:\r\n# if i==-1:return True\r\n# return False\r\n# for i in range(n):\r\n# x=int(input())\r\n# a=sorted([int(i)for i in input().split()])\r\n# cnt=0\r\n# while 1:\r\n# if bre():\r\n# print(cnt)\r\n# break\r\n# if che(a):\r\n# print(-1)\r\n# break\r\n# a[-1]-=1\r\n# a[-2]-=1\r\n# a.sort()\r\n# cnt+=1\r\n\r\n\r\n\r\n\r\n# def win(x,y):\r\n# cnt,cn=0,0\r\n# for i in range(4):\r\n# for j in range(4):\r\n# if x[i]>y[j]:cnt+=1\r\n# if x[i]<y[j]:cn+=1\r\n# return cnt>cn\r\n# def solve():\r\n# t=[int(i)for i in input().split()]\r\n# a,b=t[:4],t[4:]\r\n# for i in range(1,11):\r\n# for j in range(1,11):\r\n# for k in range(1,11):\r\n# for u in range(1,11):\r\n# c=[i,j,k,u]\r\n# if win(a,b) and win(b,c) and win(c,a):\r\n# print('yes')\r\n# return\r\n# if win(a,c) and win(c,b) and win(b,a):\r\n# print('yes')\r\n# return\r\n# print('no')\r\n# n=int(input())\r\n# for i in range(n):\r\n# solve()\r\n\r\n\r\n\r\n# n=int(input())\r\n# if n%2==0:print((n+1)//2)\r\n# else:print(0-(n+1)//2)\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=[int(i)for i in input().split()]\r\n# p,z=1/n,0\r\n# for i in a:z+=i*p\r\n# print(z)\r\n\r\n\r\n# n=int(input())\r\n# a=[int(i)for i in input().split()][1:]\r\n# b=[int(i)for i in input().split()][1:]\r\n# s=set(a+b)\r\n# if len(s)==n:print('I become the guy.')\r\n# else:print('Oh, my keyboard!')\r\n\r\n\r\n\r\n# a=int(input())\r\n# b=int(input())\r\n# c=int(input())\r\n# d=int(input())\r\n# n=int(input())\r\n# cnt=0\r\n# for i in range(1,n+1):\r\n# if i%a==0:continue\r\n# if i%b==0:continue\r\n# if i%c==0:continue\r\n# if i%d==0:continue\r\n# cnt+=1\r\n# print(n-cnt)\r\n\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# a=[int(i)for i in input().split()]\r\n# for i in range(n-1,-1,-1):\r\n# if a[i]==min(a):\r\n# s=i\r\n# break\r\n# for i in range(n):\r\n# if a[i]==max(a):\r\n# b=i\r\n# break\r\n# if s<b:print((b-0)+(n-1-s)-1)\r\n# else:print((b-0)+(n-1-s))\r\n\r\n\r\n\r\n\r\n\r\n# n=int(input())\r\n# for i in range(n):\r\n# t=[int(i)for i in input().split()]\r\n# a=t[0]\r\n# b=t[1]\r\n# if a%b==0:print(0)\r\n# elif a<b:print(b-a)\r\n# else:print(b-a%b)\r\n\r\n\r\n# n=int(input())\r\n# h,a,cnt=[],[],0\r\n# for i in range(n):\r\n# t=[int(i)for i in input().split()]\r\n# h.append(t[0])\r\n# a.append(t[1])\r\n# for i in h:\r\n# for j in a:\r\n# if i==j:cnt+=1\r\n# print(cnt)\r\n\r\n\r\n# a=input()\r\n# b=input()\r\n# c=input()\r\n# lost=[0]*26\r\n# loss=[0]*26\r\n# for i in a:lost[ord(i)-65]+=1\r\n# for i in b:lost[ord(i)-65]+=1\r\n# for i in c:loss[ord(i)-65]+=1\r\n# for i in range(26):\r\n# if loss[i]!=lost[i]:\r\n# print('NO')\r\n# sys.exit()\r\n# print('YES')\r\n\r\n\r\n# a=[int(i)for i in input().split()]\r\n# b=max(a)\r\n# a.remove(b)\r\n# for i in a:print(b-i,end=' ')\r\n\r\n\r\n# a=input()\r\n# flag,lost=0,[]\r\n# z=0\r\n# if len(a)==1:\r\n# print(a)\r\n# sys.exit()\r\n# for i in range(len(a)-2):\r\n# if flag>0:\r\n# flag-=1\r\n# continue\r\n# if a[i]=='W' and a[i+1]=='U' and a[i+2]=='B':\r\n# lost.append(',')\r\n# flag=2\r\n# else:lost.append(a[i])\r\n# if flag==0:\r\n# lost.append(a[len(a)-2])\r\n# lost.append(a[len(a)-1])\r\n# elif a[-1]!='b' and a[-2]!='U' and a[-3]!='W':\r\n# lost.append(a[len(a)-1])\r\n# if len(lost)==1 and lost[0]!=',':\r\n# print(lost[0])\r\n# sys.exit()\r\n# if len(lost)==1 and lost[0]==',':\r\n# print()\r\n# sys.exit()\r\n# if len(lost)==lost.count(','):\r\n# print()\r\n# sys.exit()\r\n# while lost[0]==',':\r\n# lost.remove(lost[0])\r\n# for i in range(len(lost)):\r\n# if lost[i]!=',':print(lost[i],end='')\r\n# elif lost[i]==',' and lost[i-1]!=',':print(' ',end='')\r\n\r\n\r\n# n=int(input())\r\n# a=[int(i)for i in input().split()]\r\n# if a.count(min(a))>1:print('Still Rozdil')\r\n# else:print(a.index(min(a))+1)\r\n\r\n\r\n# n=int(input())\r\n# a=[0,1]\r\n# while max(a)<n:\r\n# a.append(a[-1]+a[-2])\r\n# for i in range(1,n+1):\r\n# for j in range(1,n+1):\r\n# for k in range(1,n+1):\r\n# if i in a and j in a and k in a and i+j+k==n:\r\n# print(i,j,k)\r\n# sys.exit()\r\n# print(\"I'm too stupid to solve this problem\")\r\n\r\n\r\nimport math\r\nn,x,y=[int(i)for i in input().split()]\r\nif math.ceil(n/100*y)-x<=0:print(0)\r\nelse:print(math.ceil(n/100*y)-x)", "import math\r\nn,x,y = list(map(int,input().split()))\r\n\r\np = math.ceil((y/100) * n)\r\nif p <= x:\r\n print(0)\r\nelse:\r\n print(p-x)", "import math as m\n\nn,x,y = list(map(int, input().split()))\n\n\na = m.ceil((y/100)*n) \n\nprint(a - x if x <= a else 0)", "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\n\r\ndef main():\r\n try:\r\n n,x,y=In()\r\n per=math.ceil((y*n)/100)\r\n per=x-per\r\n if per>=0:\r\n print(0)\r\n else:\r\n print(abs(per))\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()", "import math\r\nn,x,y=map(int,input().split())\r\nz=math.ceil((y/100)*n)\r\nif(x>=z):\r\n\tprint(0)\r\nelse:\r\n\tprint(z-x)", "import math\r\n\r\n(n, x, y) = [int(r) for r in input().split()]\r\nprint(math.ceil(max(0, n * y / 100 - x)))\r\n", "n, x, y = input().split()\r\nn, x, y = int(n), int(x), int(y)\r\npercent = ((y * n) / 100)\r\nif int(percent) != percent:\r\n percent += 1\r\n percent = int(percent)\r\nans = int(percent - x)\r\nif ans >= 0:\r\n print(ans)\r\nelse:\r\n print(0)\r\n", "n, x, y = map(int, input().split())\r\nleft = -1\r\nright = 10000000000\r\nwhile right - left > 1:\r\n k = (left + right)//2\r\n if x + k >= n * (y/100):\r\n right = k\r\n else:\r\n left = k\r\n#print(n * (y/100), x)\r\nprint(right) ", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nn, x, y = map(int, input().split())\r\n\r\ntarget = (n * y + 99) // 100\r\n\r\nprint(max(target - x, 0))\r\n", "n,x,y = map(int,input().split())\r\nk = 0; p = (x*100/n)\r\nwhile p < y:\r\n x += 1\r\n p = (x*100/n)\r\n k += 1\r\nprint(k)", "import math\r\nn,x,y=map(int,input().split())\r\nz=math.ceil(n/100*y)\r\nif z<=x:\r\n print(0)\r\nelse:\r\n print(z-x)\r\n", "from math import ceil\n\nn, x, y = map(int, input().split())\nwizard_needed = ceil((n * y) / 100)\n\nprint(max(0, wizard_needed - x))", "import math\r\na, b, c = map(int, input().split(' '))\r\nprint(max(math.ceil(a*c/100 - b), 0))\r\n", "n, x, y = map(int, input().split())\r\n\r\nif y * n % 100 == 0:\r\n print(max(0, y * n // 100 - x))\r\nelse:\r\n print(max(0, y * n // 100 - x + 1))\r\n", "\r\nn,x,y=map(int,input().split())\r\nprint(-min(0,-n*y//100+x))\r\n", "from math import ceil\r\nn,x,y=map(int,input().split())\r\nw=ceil((n*y)/100)\r\nif w-x>=0:\r\n\tprint(w-x)\r\nelse:\r\n\tprint(\"0\")", "import math\r\nn,x,y = map(int,input().split())\r\na = (n*y-x*100)/100\r\nprint(max(0,math.ceil(a)))", "import math\r\ndef question1():\r\n total_people,wizzards,percent_required = map(int,input().split())\r\n required_people = math.ceil((total_people * percent_required) / 100)\r\n # print(required_people)\r\n if required_people <= wizzards:\r\n return 0 \r\n return required_people - wizzards \r\n \r\nremained_test_cases = 1 \r\n# remained_test_cases = int(input())\r\nwhile remained_test_cases > 0:\r\n print(question1())\r\n remained_test_cases -= 1 ", "from math import ceil\r\n\r\nn,x,y = map(int, input().split())\r\n\r\nprint(max(0,ceil(n*y/100) - x))", "from math import ceil\n\nn, x, y = (int(i) for i in input().split(' '))\n\nz = ceil(n * y / 100)\n\nif z > x:\n print(z - x)\nelse:\n print(0)\n", "import math\r\nn,x,y=[int(x) for x in input().split()]\r\npeople=math.ceil((y/100)*n)\r\nif(people<=x):\r\n print(0)\r\nelse:\r\n print(people-x)", "N, X, Y = map(int, input().split())\r\nprint(max(__import__('math').ceil(N * Y / 100 - X), 0))", "import math\nn,x,y=map(int,input().split())\n\np=math.ceil((y*n)/100)\n\nans=abs(p-x)\nif p<x:\n\tprint(0)\nelse:\n\tprint(ans)", "a,b,c=map(int,input().split())\r\np=-min(0,-a*c/100+b)\r\nprint(int(p))if p==int(p) else print(int(p)+1)", "import math\r\n \r\nif __name__ ==\"__main__\":\r\n temp = list(map(int , input().rstrip().split()))\r\n n = temp[0]\r\n x = temp[1]\r\n y = temp[2]\r\n \r\n totalRequired = math.ceil(n * y / 100)\r\n if x >= totalRequired:\r\n print(0)\r\n else:\r\n print(totalRequired - x)\r\n", "import math\r\nn,x,y=map(int,input().split())\r\nk=(y/100)*n\r\nk=math.ceil(k)\r\nif k<=x:\r\n print(0)\r\nelse:\r\n print(abs(k-x))", "import math\r\nn,x,y=map(int,input().split(\" \"))\r\n \r\nk=math.ceil((y/100)*n);\r\nif(x>k):\r\n print(0);\r\nelse:\r\n print(k-x)", "n, x, y = list(map(int, input().split(' ')))\r\np = 0\r\nneededRatio = n * (y / 100)\r\nwhile True:\r\n currentRatio = n * ((x + p) / n)\r\n if currentRatio >= neededRatio:\r\n break\r\n else:\r\n p += 1\r\nprint(p)\r\n", "s = map(int, input().split())\r\nn, x, y = s\r\nans = max(n*y-100*x, 0)\r\nans = (ans+99)//100\r\nprint(ans)", "n , w, p = map(int,input().split())\nimport math\nrq = math.ceil((p/100)*n)\nprint(rq-w) if rq-w>0 else print(0)\n", "import math\r\n\r\nn, x, y = map(int, input().split())\r\n\r\nprint(max(0, math.ceil((n * y) / 100) - x))", "[n,x,y] = map(int, input().split())\r\ntotal = n * y//100\r\n\r\nif (n*y)%100 != 0:\r\n total += 1\r\nif x>=total:\r\n print(0)\r\nelse:\r\n print(total-x)", "import math\r\nn,x,y=map(int,input().split())\r\nReqPeople=math.ceil((y*n)/100)\r\nif x<ReqPeople:\r\n print(ReqPeople-x)\r\nelse:\r\n print(0)", "n,x,y=map(int,input().split())\r\nif n*y%100==0:\r\n\tp=n*y//100\r\nelse:\r\n\tp=n*y//100+1\r\nif p-x<1:\r\n\tprint(0)\r\nelse:\r\n\tprint(p-x)", "import math\r\nn,x,y=map(int,input().split())\r\nprint(max(0,math.ceil((n*y)/100)-x))", "from math import ceil\r\nn,x,y = map(int,input().split())\r\ntotal_people_need = ceil((float(n)/100) * float(y))\r\npuppet_need = max(int(total_people_need) - x, 0)\r\nprint(puppet_need)", "n,x,y=map(int,input().split( ))\r\nm=(n*y/100)\r\nif m!=m//1:\r\n m=(m//1)+1\r\nif m>x:\r\n print(int(m)-x)\r\nelse:\r\n print(0)\r\n \r\n", "from math import *\r\nn,x,y=map(int,input().split())\r\nk=ceil((n*y/100)-x)\r\nprint(k*(k>0))", "from math import ceil,floor\r\nn,x,y = map(int,input().split())\r\nif floor((x*100)/n) >= y:\r\n print(0)\r\nelse:\r\n print(ceil((y*n)/100) - x)", "from math import ceil\n\nn,x,y = map(int,input().split())\n\nprint( max(0,ceil((n/100)*y)-x) )\n\n", "[n,x,y] = map(int, input().split())\r\n#b = n-x\r\nif x >= n*y/100:\r\n print(0)\r\nelif (n*y)%100 == 0:\r\n print(n * y//100-x)\r\nelse:\r\n print(n * y//100-x +1)\r\n ", "from math import ceil\r\nn, x, y = map(int, input().split())\r\nprint(max(0, ceil(n * y / 100) - x))\r\n", "# t = int(input())\nt = 1\n\n\n# # n, m = map(int, input().split())\n# # a = list(map(int, input().split()))\nimport math\n\nwhile t != 0:\n # n = int(input())\n n, x, y = map(int, input().split())\n # a = list(map(int, input().split()))\n # s = input()\n a = math.ceil((y * n) / 100)\n if x < a:\n print(a - x)\n else:\n print(0)\n t -= 1\n", "import math as m\r\n\r\nn, x, y = map(int, input().split())\r\n\r\nsc = (y*n)/100\r\nsc= m.ceil(sc)\r\nr = sc-x\r\nif r<0:\r\n print(0)\r\nelse:\r\n print(r)", "import math\r\ndef solve(n: int, x: int, y: int) -> int:\r\n percentage = math.ceil(n * y / 100)\r\n if x < percentage:\r\n return (percentage - x)\r\n else:\r\n return (0)\r\n\r\n\r\nn, x, y = map(int, input().split())\r\nprint(solve(n, x, y))", "import math\r\nn,x,y=map(int,input().split())\r\nreq=math.ceil((y/100)*n)\r\nans=req-x if req>x else 0\r\nprint(ans)\r\n", "import math\nnxy = list(map(int, input().split()))\nn = nxy[0]\nx = nxy[1]\ny = nxy[2]\nindemo = math.ceil((y / 100) * n)\nclones = 0\nif indemo - x > 0:\n clones = indemo - x\nprint(clones)\n", "from math import *\r\nn,x,y=input().split()\r\nn,x,y=int(n),int(x),int(y)\r\nz=ceil(n*(y/100))-x\r\nif(z<0):\r\n print(0)\r\nelse:\r\n print(z)\r\n", "# import sys\r\n# sys.stdin=open(\"input1.in\",\"r\")\r\n# sys.stdout=open(\"OUTPUT3.out\",\"w\") \r\nn,x,y=map(int,input().split())\r\nrequired=(y*n)//100+bool((y*n)%100)\r\nif x>required:\r\n\tprint(0)\r\nelse:\r\n\tprint(required-x)\r\n", "import math\r\nn,x,y=map(int,input().split())\r\nif x>=math.ceil((y/100)*n):\r\n print(0)\r\nelif x<math.ceil((y/100)*n):\r\n print(math.ceil((y/100)*n)-x)\r\nelse:\r\n print(math.floor((y/100)*n)-x)", "a,b,c=map(int,input().split())\r\n\r\nd=0\r\n\r\nwhile((b+d)/a)*100<c:d+=1\r\n\r\nprint(d)", "import math\r\nn,w,p = map(int,input().split())\r\n\r\nneeded = int(math.ceil((n*p)/100))\r\nans = needed-w\r\nif ans > 0:\r\n print(ans)\r\nelse:\r\n print(0)", "import math\r\narr=list(map(int,input().split()))\r\ntotal=arr[0]\r\nwiz=arr[1]\r\nper=arr[2]\r\nrequired=math.ceil((total*per)/100)\r\n# print(\"Required: \",required)\r\nif required<=wiz:\r\n print(\"0\")\r\nelse:\r\n print(required-wiz)", "n, x, y = map(int, input().split())\r\np = int((n / 100) * y + 0.9999999)\r\n\r\nif p <= x:\r\n print(0)\r\nelse:\r\n print(p - x)", "from math import ceil\r\nn,x,y=map(int,input().split())\r\nprint(max(0,ceil(n*(y/100))-x))", "\r\nfrom math import ceil\r\nn, x, y = map(int, input().split())\r\n\r\ngoal = ceil(n * (y / 100))\r\nprint (max(goal - x, 0))", "n,x,y=map(int,input().split())\r\nif int(n*(y/100))!=n*(y/100):\r\n n=int(n*(y/100)+1)\r\nelse:\r\n n=int(n*(y/100))\r\nif n<x:\r\n print(0)\r\nelse:\r\n print(n-x)\r\n", "from math import *\r\nn, x, y = input().split()\r\nz = ceil((int(y)/100)*int(n))\r\nif(z > int(x)): s = (z - int(x))\r\nelse : s = 0\r\nprint(s)\r\n\r\n", "import math\r\nn_x_y = list(map(int,input().split()))\r\nminn = math.ceil((n_x_y[2] / 100) * n_x_y[0])\r\nreq = minn - n_x_y[1]\r\nif req < 0 :\r\n print('0')\r\nelse:\r\n print(req)\r\n", "import math\r\na,b,c = map(int,input().split())\r\nw = (a * c) / 100\r\nif w-b < 0:\r\n print(0)\r\nelse:\r\n print(math.ceil(w-b))", "[n,x,y] = map(int, input().split())\r\n\r\nif x >= n*y/100:\r\n print(0)\r\nelse:\r\n b = n * y//100-x\r\n if (n*y)%100 != 0:\r\n b += 1\r\n print(b)", "print(list(max(__import__('math').ceil(int(N) * int(Y) / 100 - int(X)), 0) for N, X, Y in [input().split()])[0])", "# coding: utf-8\nn, x, y = [int(i) for i in input().split()]\nans = int((y/100*n)-x)\nif (ans+x)/n < y/100:\n ans += 1\nif ans > 0:\n print(ans)\nelse:\n print(0)\n", "a,b,c=map(int,input().split())\r\nd=0\r\nwhile((b+d)/a)*100<c:d+=1\r\nprint(d)", "import math\r\nn,x,y=map(int ,input().split())\r\nk=math.ceil((n*y)/100)\r\nif(x>=k):\r\n print(0)\r\nelse:\r\n print(abs(k-x)) ", "n, x, y = map(int, input().split())\npercent = y/100\npuppets = 0\nwhile (x+puppets)/n < percent:\n puppets+=1\nprint(puppets)", "import math\r\n#for _ in range(int(input())):\r\nn,x,y=map(int,input().split())\r\nd=math.ceil(n*(y/100))\r\nif(d>x):\r\n print(d-x)\r\nelse:\r\n print(0)", "import math\r\nn, x, y = [int(s) for s in input().split(' ')]\r\n\r\nc = max(math.ceil(n * (y / 100) - x), 0)\r\nprint(c)", "from math import ceil\r\n\r\nX = list(map(int, input().split()))\r\nResult = (ceil((X[0] * X[2]) / 100)) - X[1]\r\nprint(Result if Result > 0 else 0)\r\n", "def wizard():\r\n\tk = 3\r\n\tn, x, y = list(map(int,input().strip().split()))[:k]\r\n\tres = int((n*y / 100) + ((n*y % 100) != 0)) - x\r\n\tif res > 0:\r\n\t\treturn res\r\n\telse:\r\n\t\treturn 0\r\n\r\nprint(wizard())", "def binarySearch(n, x, y):\n l, r = 0, n * 10000\n while l < r:\n m = (l + r) // 2\n if (m + x) / n >= y / 100:\n r = m\n else:\n l = m + 1\n return l\n\n\nif __name__ == '__main__':\n n, x, y = [int(i) for i in input().split(' ')]\n print(binarySearch(n, x, y))\n\n\n\t \t\t \t\t\t \t \t \t \t \t\t\t \t\t \t\t", "num,wiz,per = map(int,input().split())\r\nk = 0\r\nwhile (k+wiz)/num*100 < per:\r\n k += 1\r\nprint(k)", "import math\nn,x,y = map(int,input().split(' '))\na = int(math.ceil(float(n * y * 0.01)))\nif x >= a:\n print(0)\nelse:\n print(a - x)", "import math\r\n\r\nn, x, y = list(map(int, list(input().split())))\r\n\r\nif math.ceil(n*(y/100)-x) < 0:\r\n print(0)\r\nelse:\r\n print(math.ceil(n*(y/100)-x))", "import math\r\n\r\nn,a,b=list(map(int,input().split()))\r\nx=(n*b)/100\r\nx=math.ceil(x)\r\nif(x>a):\r\n print(x-a)\r\nelse:\r\n print(0)\r\n", "l=input()\r\nl=l.split()\r\nn=int(l[0])\r\nx=int(l[1])\r\ny=int(l[2])\r\ns=0\r\nwhile (x/n)*100<y:\r\n\ts+=1\r\n\tx+=1\r\nprint(s)", "# cook your dish here\r\n\r\ninpu = input().split()\r\n\r\nn = int(inpu[0])\r\nx = int(inpu[1])\r\ny = int(inpu[2])\r\n\r\nreq = y*n/100.0\r\n\r\nif (req != int(req)):\r\n req = int(req) + 1\r\nelse:\r\n req = int(req)\r\n\r\nif (req <= x):\r\n print (0)\r\nelse:\r\n print (req-x)", "import math\r\nn,x,y=map(int,input().split())\r\ny=math.ceil((y/100)*n)\r\nif y<x:\r\n print(0)\r\nelse:\r\n print(y-x)", "from math import ceil\r\nn,x,y=map(int,input().split())\r\nprint(max(0, ceil(y*(n/100))-x))", "from math import ceil\r\n\r\nn,a,b=map(int,input().split())\r\nreq=ceil((n*b)/100)\r\nif(req<=a):\r\n print(0)\r\nelse:\r\n print(abs(req-a))", "from math import ceil\r\nn,x,y=map(int,input().split())\r\nrew=y*n/100\r\nif x<ceil(rew):\r\n\tprint(ceil(rew)-x)\r\nelse:\r\n\tprint(0)", "from math import ceil\r\nn, x, y = map(int,input().split())\r\ntot = int(ceil(n * y / 100.0))\r\nprint (max(0, tot-x))", "import math\r\nz=list(map(int,input().split()))\r\nn=z[0]\r\nx=z[1]\r\ny=z[2]\r\nc=(x/n)\r\n\r\nc=c*100\r\nc=round(c,4)\r\n\r\nif(c>=y):\r\n print(0)\r\nelse:\r\n \r\n p=(((y-c)*n)/100)\r\n\r\n print(math.ceil(p))\r\n", "a, b, c = map(int, input().split())\r\n\r\ntemp = a * (c / 100)\r\n\r\nif temp - int(temp) > 0.0:\r\n temp = int(temp + 1)\r\nelse:\r\n temp = int(temp)\r\n\r\nprint(max(0, temp - b))", "import time,sys,io,math\r\ninp=sys.stdin.readline\r\npr=sys.stdout.write\r\n\r\ndef solve():\r\n n,x,y=[int(i) for i in inp().split()]\r\n ans=max(0,(n*y+99)//100-x)\r\n pr(f\"{ans}\"+\"\\n\")\r\n\r\nstart=time.time()\r\nt=1\r\n#t=int(inp())\r\nfor _ in range(t):\r\n solve()\r\n#pr(f\"Time lapsed: {time.time()-start}\")", "import math\r\nn,x,y=list(map(int,input().split()))\r\n\r\n\r\na=math.ceil(n*y/100)\r\n\r\nif a>x:\r\n print(a-x)\r\nelse:\r\n print(0)\r\n", "import math\r\n\r\nn,x,y = map(int,input().split())\r\na = int(math.ceil((y/100)*n)) - x\r\nif a < 0 :\r\n\ta = 0\r\nprint(a)", "n,x,y=[int(i) for i in input().split()]\r\nclone=0\r\nz=False\r\nif not x/n*100<y:\r\n\tprint(0)\r\n\tz=True\r\nwhile x/n*100<y:\r\n\tx+=1\r\n\tclone+=1\r\nif not z: print(clone)\r\n", "import math\n\nn, x, y = map(int, input().split())\nneeded = math.ceil(n * (y / 100))\nneeded -= x\nprint(int(needed) if needed > 0 else 0)\n\n\t \t \t\t \t\t\t \t \t \t\t\t\t\t", "# import sys\r\n# sys.stdin = open(\"test.in\",\"r\")\r\n# sys.stdout = open(\"test.out.py\",\"w\")\r\nfrom math import ceil as c\r\nn,x,y=map(int,input().split())\r\na=c((n*y)/100)\r\nif x>=a:\r\n\tprint('0')\r\nelse:\r\n\tprint(a-x)\t", "import math\r\nn,x,y=list(map(int,input().split()))\r\na=(y/100)*n\r\na=math.ceil(a)\r\nif x>=a:\r\n print(0)\r\nelse:\r\n print(int(a-x)) ", "n,x,y=map(int,input().split())\r\ni=0\r\nwhile (x+i)*100/y<n:i+=1\r\nprint (i)\r\n", "import math\r\nn,x,y = map(int,input().split())\r\nreq = int(math.ceil((n*y)/100))\r\nif x>req:\r\n print (0)\r\nelse:\r\n print (req-x)", "import math\r\nclass data:\r\n def __init__(self):\r\n a,b,c = map(int, input().split())\r\n self.n = a\r\n self.x = b\r\n self.y = c\r\n self.printit()\r\n def claculate(self):\r\n p = self.y/100;\r\n p = p*self.n \r\n p = math.ceil(p)\r\n p = int(p)\r\n p = p - self.x \r\n if p<0:\r\n p = 0\r\n return p \r\n def printit(self): \r\n print(self.claculate())\r\n\r\n\r\n\r\ninp = data()\r\n", "import math\r\n\r\nn, x, y = map(int, input().split())\r\ns = math.ceil(n / 100 * y)\r\nif s >= x:\r\n print(s - x)\r\nelse:\r\n print(0)", "P, N , rate = map(int,input().split())\r\n\r\nneed = P * rate / 100\r\nif (P * rate) % 100 == 0:\r\n need = P * rate // 100\r\nelse:\r\n need = P * rate // 100 + 1\r\n \r\nif need > N:\r\n print(need - N)\r\nelse:\r\n print(0) \r\n", "import math\r\narr = list(map(int, input().split()))\r\nbase = math.ceil(arr[0] * arr[2] / 100)\r\nif base <= arr[1]:\r\n print(0)\r\nelse:\r\n print(base - arr[1])\r\n", "n, x, y = (int(i) for i in input().split())\nneed = (n * y + 99) // 100\nres = max(0, need - x)\nprint(res)\n", "from math import ceil\r\nn, x, y = map(int, input().split())\r\ntarget = ceil(n*(y/100))\r\nif target-x >0:\r\n print(target-x)\r\nelse:\r\n print(0)\r\n", "from math import ceil\r\ndef main():\r\n mode=\"filee\"\r\n if mode==\"file\":f=open(\"test.txt\",\"r\")\r\n #f.readline()\r\n #input()\r\n get = lambda :[int(x) for x in (f.readline() if mode==\"file\" else input()).split()]\r\n [n,x,y]=get()\r\n total = ceil((y/100)*n)\r\n if total >x:\r\n print(total-x)\r\n else:\r\n print(0)\r\n\r\n\r\n if mode==\"file\":f.close()\r\n\r\n\r\nif __name__==\"__main__\":\r\n main()\r\n", "import math\r\n\r\nn, x, y = map(int, input().split())\r\nif x / n >= y:\r\n print(0)\r\nelse:\r\n a = int(math.ceil(n * (y / 100)) - x)\r\n print(a if a >= 0 else 0)", "from math import *\r\nn,x,y=map(int,input().split())\r\nxx=(x*100)/n\r\nyy=y-xx\r\nz=(yy*n)/100\r\nif(z<=0):\r\n print(0)\r\nelse:\r\n print(ceil(z))\r\n", "import math\r\na,b,c=map(int,input().split())\r\nprint(math.ceil((a*c)/100-b) if math.ceil((a*c)/100-b)>0 else 0)\r\n", "import math\r\nn,x,y=map(int,input().split())\r\na=math.ceil(n*y/100)\r\nif a>x:\r\n \r\n print(abs(x-a))\r\nelse:\r\n print(0)", "import math\r\na,b,c=map(int,input().split())\r\np=math.ceil((c*a)/100)\r\nif p<=b:print(0)\r\nelse:print(p-b)", "import math\r\nn,x,y=map(int,input().split())\r\nprint(max(0,math.ceil(((n*y)/100)-x)))\r\n", "n,x,y=map(int,input().split())\r\nif n*y%100==0 and int(n*y/100)<=x: print(0)\r\nelif n*y%100!=0 and int(n*y/100)+1<=x: print(0)\r\nelse:\r\n if n*y%100==0: print(int(n*y/100)-x)\r\n else: print(int(n*y/100)+1-x)", "import math\r\nn,x,y=map(int,input().split())\r\np=math.ceil((y*n)/100)\r\nrequried=p\r\nhai=x\r\n# print(hai,requried)\r\nif(hai>=requried):\r\n\tprint(0)\r\nelse:\r\n\tprint(p-hai)\r\n", "import itertools as it\n\nn, x, y = map(int, input().split())\n\nfor i in it.count():\n if (x + i) * 100 >= y * n:\n print(i)\n break\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 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,x,y = get_int_list()\r\n\r\nreq = math.ceil((y/100)*n)\r\nif req > x:\r\n print(req-x)\r\nelse:\r\n print(0)", "j, m, p = map(int, input().split())\r\nl = j * p\r\nl = l // 100 + int(l % 100 > 0) - m\r\nprint(max(l, 0))\r\n", "import math\r\nn,x,y=map(int,input().split())\r\np=(y/100)*n\r\np=math.ceil(p)\r\nif (p-x)>=0:\r\n print(p-x)\r\nelse:\r\n print(0)", "\r\nfrom math import ceil\r\nn, x, y = map(int, input().split())\r\nrequired = ceil(y * n / 100)\r\n\r\n\r\nprint(max(0, required - x))", "n, x, y = map(int, input().split())\r\nmin_people = (n * y + 99) // 100\r\nclones_needed = max(0, min_people - x)\r\nprint(clones_needed)", "n,x,y=map(int,input().split())\r\nd=0\r\np=(x*100)/n\r\nwhile p<y:\r\n d=d+1\r\n x=x+1\r\n p=(x*100)/n\r\nprint(d) \r\n", "n, x, y = map(int, input().split())\nt = 0\nwhile (x+t)/n < y/100:\n t += 1\nprint(t)\n\n", "import sys\r\nimport math\r\nimport bisect\r\n\r\ndef solve(n, x, y):\r\n ans = 0\r\n while (x + ans) * 100 < y * n:\r\n ans += 1\r\n return ans\r\n\r\ndef main():\r\n n, x, y = map(int, input().split())\r\n print(solve(n, x, y))\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n, x, y = map(int, input().split())\r\nminTarget = -((-y * n) // 100)\r\ntoAdd = max(minTarget - x, 0)\r\nprint(toAdd)", "from math import ceil\nn, x, y = list(map(int, input().split()))\n\nreq = int(ceil(n * y / 100))\nif req > x:\n print(req - x)\nelse:\n print(0)\n", "a,b,c=map(int,input().split())\r\nr=0\r\nwhile (b/a)*100<c:\r\n b+=1\r\n r+=1\r\nprint(r)", "from math import ceil\r\na=list(map(int,input().split()))\r\nprint(max(0,ceil(a[0]*a[2]/100-a[1])))\r\n", "a = input().split()\r\nn = int(a[0])\r\nx = int(a[1])\r\ny = int(a[2])\r\nif (y * n / 100 <= x):\r\n print (0)\r\nelif (y * n / 100 > x):\r\n if ((y * n / 100) > int(y * n / 100) and (y * n / 100) < (int(y * n / 100) + 1)):\r\n print (int(y * n / 100) + 1 - x)\r\n else:\r\n print (int (y * n / 100) - x)\r\n", "import math\r\nn,x,y=map(int,input().split())\r\nans=math.ceil(n*y/100)-x\r\nif ans<0:\r\n ans=0\r\nprint(ans)", "from math import ceil\r\nn,x,y=map(int,input().split())\r\nz=ceil(y*n/100)\r\nif z>x:\r\n\tprint(z-x)\r\nelse:\r\n\tprint(0)", "import math\r\n\r\ntotal, magicians, percent = (int(i) for i in input().split())\r\nneed = math.ceil(total * percent / 100)\r\n\r\nif magicians >= need:\r\n print(0)\r\nelse:\r\n print(need - magicians)", "#168A\r\nimport math\r\nn, x, y = map(int, input().split())\r\nprint(max(0,math.ceil((n*y)/100) - x))\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Apr 2 05:40:04 2020\r\n\r\n@author: alexi\r\n\"\"\"\r\n\r\n\r\n\r\n#https://codeforces.com/problemset/problem/168/A --- Alexis Galvan\r\n\r\nimport math \r\n\r\ndef wizards_city():\r\n wizards = list(map(int, input().split()))\r\n \r\n temp = math.ceil((wizards[0]/100)*(wizards[2]))\r\n \r\n if wizards[1] >= temp:\r\n return 0\r\n else:\r\n return temp - wizards[1]\r\n \r\nA = wizards_city()\r\nprint(A)\r\n ", "import math\r\nn,x,y=map(int,input().split())\r\nif math.ceil((n*y)/100)<=x:\r\n print(0)\r\nelse:\r\n print(math.ceil((n*y)/100)-x)\r\n\r\n\r\n", "__copyright__ = ''\r\n__author__ = 'Son-Huy TRAN'\r\n__email__ = \"[email protected]\"\r\n__doc__ = ''\r\n__version__ = '1.0'\r\n\r\nfrom math import ceil\r\n\r\ndef main() -> int:\r\n (n, x, y) = map(int, input().split())\r\n\r\n if x / n * 100 >= y:\r\n print(0)\r\n else:\r\n print(ceil(n * y / 100 - x))\r\n\r\n return 0\r\n\r\n\r\nif __name__ == '__main__':\r\n exit(main())", "import math\r\nn,x,y = map(int,input().split())\r\ns = math.ceil(n*y/100)-x\r\nif s<=0:\r\n print(0)\r\nelse:\r\n print(s)", "import math\n\nn,x,y = [int(ch) for ch in input().split(' ')]\nans = (math.ceil(y*n/100) - x)\nprint('0') if ans < 0 else print(ans)", "ins=input().split()\r\nn, x, y=int(ins[0]), int(ins[1]), int(ins[2])\r\nl, r=0, 100000000000000\r\nwhile l<r:\r\n c=(l+r)//2\r\n if ((c+x)/n)*100>=y: r=c\r\n else: l=c+1\r\nprint(l)\r\n\r\n\r\n", "from math import ceil\r\nn,x,y=map(int,input().split())\r\na=ceil(y*n/100)\r\na-=x\r\nif a>0:\r\n\tprint(a)\r\nelse:\r\n\tprint(0)", "from math import ceil\r\n\r\ndef main():\r\n n, x, y = map(int, input().split())\r\n\r\n need = ceil(n / 100 * y)\r\n\r\n if need <= x:\r\n print(0)\r\n else:\r\n print(need - x)\r\n\r\nmain()\r\n", "n, x, y = map(int, input().split())\r\nn = n / 100 * y\r\nif n % 1:\r\n n = int(n) + 1\r\nprint(0 if x > n else int(n - x))\r\n", "from math import ceil\r\nn, x, y = map(int, input().split())\r\nif x < n*y/100:\r\n print(abs(x - ceil(n*(y/100))))\r\nelse:\r\n print(0)", "n,x,y = map(int,input().split())\r\nans = max(n*y-100*x, 0)\r\nprint((ans+99)//100)", "from math import modf\r\npeople_quantity, wizard_quantity, percent = (int(x) for x in input().split())\r\nneed_people = (people_quantity*percent)/100\r\nif modf(need_people)[0] > 0:\r\n\tneed_people = int(need_people) + 1\r\nif wizard_quantity < need_people:\r\n\tprint(int(need_people - wizard_quantity))\r\nelse:\r\n\tprint(0)", "import math\r\nn, x, y = map(int, input().split())\r\nprint(math.ceil(y*n/100) - x if math.ceil(y*n/100) - x > 0 else 0)\r\n", "from sys import stdin\r\ninput = stdin.readline\r\nfrom math import ceil\r\n\r\npop, num_wiz, percent = [int(x) for x in input().split()]\r\nans = max(0, ceil((pop * percent - 100 * num_wiz)/100))\r\nprint(ans)\r\n\r\n\r\n", "import math\r\nn,x,y=map(int,input().split())\r\nans=math.ceil((y*n/100))\r\nif x>=ans:\r\n print(0)\r\nelse:\r\n print(ans-x)", "n,x,y = list(map(int, input().split()))\r\n\r\ntest = lambda a,p : True if (a/n)*100>=p else False\r\n\r\nclones = 0\r\n\r\nwhile True:\r\n if test(x+clones,y): break\r\n clones += 1\r\n\r\nprint(clones)", "n, x, y = map(int,input().split())\r\nimport math\r\nif x >= n*y/100:\r\n print(0)\r\nelse:\r\n print(math.ceil(n*y/100 - x))\r\n\r\n", "n, x, y = map(int, input().split())\r\nprint(max(0, -(-n * y // 100) - x))\r\n", "from math import ceil\r\nn, x, y = map(int, input().split())\r\nl = 100 * x\r\nr = y * n\r\nprint(0 if l >= r else ceil(r / 100) - x)", "from math import ceil\r\nx, y, percentage = map(int, input().split())\r\nans = percentage / 100 * x\r\nif ans > y:\r\n print(ceil(ans - y))\r\nelse:\r\n print(0)", "import math\r\nn, x, y= map(int, input().split())\r\npercentage = n * (y/100)\r\np=math.ceil(percentage)\r\nif x < p :\r\n clone=p-x\r\n print(clone)\r\nelse :\r\n print('0') \r\n \r\n", "from math import ceil\r\nn, x, y = list(map(int, input().split()))\r\na = y / 100 * (n) - x\r\nif a < 0:\r\n\tprint(0)\r\nelse:\r\n\tprint(ceil(a))", "import math\r\n\r\nn,x,y=map(int,input().split())\r\n\r\nprint(max(0, math.ceil((y*n-100*x)/100)))\r\n", "import math\r\nn, x, y = map(int, input().split())\r\nclones = math.ceil(y * n / 100) - x\r\nif clones >= 0:\r\n print(clones)\r\nelse:\r\n print(0)\r\n", "import math\r\n\r\nn, k, p = map(int, input().split())\r\n\r\nneed = math.ceil(n*p/100)\r\n\r\nres = need-k\r\n\r\nprint( res if res>0 else 0 )", "n,x,y = map(int, input().split())\r\nfrom math import ceil\r\nrequired = ceil(n*(y/100))\r\nprint(max(0, required - x))", "import math\r\nn,x,y = map(int, input().split())\r\ntemp = n * (y / 100)\r\nif temp <= x:\r\n print(0)\r\nelse:\r\n print(math.ceil(temp - x))", "import math\r\nn,x,y=map(int,input().split())\r\ntocome=y/100.0\r\n\r\nif x<tocome*n:\r\n\r\n need=(math.ceil(tocome*n))-x\r\n print(need)\r\nelse:\r\n print(0) ", "import math\r\nn,x,y = map(int, input() .split())\r\nt = math.ceil((y/100) * n)\r\nif x > t :\r\n print(0)\r\nelse: \r\n print(t-x) ", "import math\r\ndef main_function():\r\n n, x, y = [int(i) for i in input().split(\" \")]\r\n people_need_to_come = math.ceil(n * y / 100)\r\n return max(0, people_need_to_come - x)\r\n\r\n\r\n\r\n\r\n\r\nprint(main_function())\r\n ", "import math\r\nnppl, xwizards, ypercent = map(int, input().split())\r\ntmp = (nppl*ypercent)/100 - xwizards\r\ntmp = math.ceil(tmp)\r\nprint(max(0, tmp))\r\n", "n, x, y = map(int, input().split())\r\nreal_percentage = (x / n) * 100\r\n\r\nneeded_clone = 0\r\nwhile real_percentage < y:\r\n needed_clone += 1\r\n x += 1\r\n real_percentage = (x / n) * 100\r\n\r\nprint(needed_clone)", "import math\r\nstring = input()\r\nn, x, y = map(int, string.split())\r\na = math.ceil(y / 100 * n)\r\nif a < x:\r\n print(0)\r\nelse:\r\n print(a - x)", "n,w,p=map(int,input().split())\r\nx=(n*p)/100\r\nif x%1==0:\r\n\tif int(x-w)>0:\r\n\t\tprint(int(x-w))\r\n\telse:\r\n\t\tprint(0)\r\nelse:\r\n\tif int(x)+1-w>0:\r\n\t\tprint(int(x)+1-w)\r\n\telse:\r\n\t\tprint(0)", "import math\r\nn,x,y=map(int,input().split())\r\nl=int(math.ceil(n*y/100))\r\nif(l>x):\r\n print(l-x)\r\nelse:\r\n print(0)", "n,x,y = map(int, input().split())\r\n\r\n# print((y/100)*n)\r\np = (y/100)*n\r\nif(p-int(p)>0):\r\n\tp = int(p)+1\r\n\r\n\r\n\r\n\r\nif(p-x>0):\r\n\tprint(int(p-x))\r\nelse:\r\n\tprint(0)", "import sys\nmy_file = sys.stdin\n#my_file = open(\"input.txt\", \"r\")\nline = [int(i) for i in my_file.readline().split()]\nn, x, y = line[0], line[1], line[2]\nres = 0\nwhile x < n*y/100:\n x += 1\n res += 1\nprint(res)", "from math import *\r\nn, x, y = input().split()\r\nn, x, y = int(n), int(x), int(y)\r\npuppet = 0\r\nif x * 100 / n < y:\r\n puppet = int(ceil(n * float(y) / 100)) - x\r\nprint(puppet)", "a,b,c=map(int,input().split())\r\nd=0\r\nwhile (b/a)*100<c:\r\n b+=1\r\n d+=1\r\nprint(d)", "from math import ceil\n\n\ndef main():\n n, x, y = map(int, input().strip().split())\n print(max(0, ceil(n * y / 100) - x))\n\n\nif __name__ == '__main__':\n main()\n", "import sys\nmy_file = sys.stdin\n#my_file = open(\"input.txt\", \"r\")\nline = [int(i) for i in my_file.readline().split()]\nn, x, y = line[0], line[1], line[2]\nres = 0\nneed = n*y/100\nwhile x < need:\n x += 1\n res += 1\nprint(res)", "import math\r\nn,x,y=[int(x) for x in input().split()]\r\nans=int(math.ceil((y*n)/100))\r\ncnt=ans-x\r\nif(cnt<0):\r\n print(\"0\")\r\nelse:\r\n print(cnt)", "import math\n\n(n, x, y) = map(int, input().split(' '))\n\nf = math.ceil((float(y)/100 * n) - x)\n\nprint(max(0, f))\n", "# https://codeforces.com/problemset/problem/168/A\n# 900\n\nn, x, y = map(int, input().split())\ny /= 100\n\nc = 0\nwhile True:\n if (x+c) / n >= y:\n break\n \n c += 1\n\nprint(c)", "#!/usr/bin/env python3\n\ndef main():\n from math import ceil\n\n n, x, y = map(int, input().split())\n ans = ceil(y/100.0*n) - x\n\n print(ans if ans > 0 else 0)\n\nif __name__ == \"__main__\":\n main()\n\n", "from math import ceil\r\nn,w,perc=list(map(int,input().split()))\r\nprint(max(0,ceil(n*(perc/100))-w))", "import math as m\r\nn=[float(i) for i in input().split()]\r\no=m.ceil(n[0]*(n[2]/100))\r\nprint(o-int(n[1]) if o>=int(n[1]) else 0)", "import math\n\nn, x, y = map(int, input().split())\n\nreq = math.ceil(y*n/ 100)\n\ndeficient = int(req - x)\n\nprint(max(0, deficient))\n\n", "[n,x,y] = map(int, input().split())\r\npercent = y/100\r\nminimum = n * percent\r\nif minimum != minimum//1:\r\n minimum = minimum//1 + 1\r\nif x >= minimum:\r\n print(int(0))\r\nelse: \r\n print(int(minimum - x))", "n,x,y=map(int,input().split())\r\nc1=n*y/100\r\nc2=n*y//100\r\nif c1==c2 :\r\n c2=int(c1)\r\nelse:\r\n c2=int(c1)+1\r\nif c2-x>=0:\r\n print(c2-x)\r\nelse:\r\n print(0)\r\n", "# LUOGU_RID: 101470182\nn, x, y = map(int, input().split())\r\nprint(max(0, (n * y - 1) // 100 + 1 - x))", "from math import ceil\r\nn, x, y = map(int, input().split())\r\nneed = ceil(n*y/100)\r\nprint(max(need-x, 0))", "import math\r\nn,x,y=map(int,input().split())\r\nif math.ceil(n*y/100)-x<0:\r\n print(0)\r\nelse:\r\n print(math.ceil(n*y/100)-x)", "#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-12-02 23:26:20\nLastEditTime: 2021-12-03 22:58:33\nDescription: Wizards and Demonstration\nFilePath: CF168A.py\n'''\n\n\nfrom math import ceil\n\n\ndef func():\n n, x, y = map(int, input().strip().split())\n if x >= ceil(n * y / 100):\n print(0)\n else:\n print(ceil(y * n / 100 - x))\n\n\nif __name__ == '__main__':\n func()\n", "import math as mt\r\nfrom collections import defaultdict,deque\r\nimport sys\r\nfrom bisect import bisect_right as b_r\r\nfrom bisect import bisect_left as b_l\r\nfrom os import path\r\nfrom heapq import *\r\n\r\n\r\nmod=1000000007\r\nINT_MAX = sys.maxsize-1\r\nINT_MIN = -sys.maxsize\r\n\r\n\r\n\r\n# if(path.exists('inputt.txt')):\r\n# sys.stdin = open('inputt.txt','r')\r\n# sys.stdout = open('output.txt','w')\r\n# else:\r\n# # input=sys.stdin.readline\r\n# pass\r\n\r\n\r\ndef myyy__answer():\r\n n,m,p=map(int,input().split())\r\n \r\n req=mt.ceil((n*p)/100)\r\n\r\n if(m>=req):\r\n print(0)\r\n else:\r\n print(req-m)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n # for _ in range(int(input())):\r\n # print(myyy__answer())\r\n myyy__answer()", "import math\r\nn,x,y = map(int,input().split())\r\nif (math.ceil((n*y)/100)-x) > 0:\r\n print(math.ceil((n*y)/100)-x)\r\nelse:\r\n print(0)", "from math import ceil\r\n#A. Wizards and Demonstration\r\nn,x,y = map(int,input().split())\r\nif x/n>=y/100:\r\n print(0)\r\nelse:\r\n b = (y/100)*n-x\r\n print(ceil(b))", "from math import ceil\r\nn,x,y=map(int,input().split())\r\nans=max(0,ceil(y*n/100.0-x))\r\nprint(ans)", "import math\r\n\r\nif __name__ == '__main__':\r\n n, x, y = str(input()).split()\r\n n = int(n)\r\n x = int(x)\r\n y = int(y)\r\n print(max(0, int(math.ceil(n * y / 100)) - x))\r\n", "a,b,c=map(int,input().split())\r\nx=a*c\r\ny=0\r\nif x%100!=0: y=1\r\ny+=(int(x/100))\r\nif b>=y:print(0)\r\nelse:print(y-b)\r\n", "\r\nimport math\r\nfrom math import gcd,floor,sqrt,log\r\ndef iin(): return int(input())\r\ndef sin(): return input().strip()\r\ndef listin(): return list(map(int,input().strip().split()))\r\ndef liststr(): return list(map(str,input().strip().split()))\r\ndef ceill(x): return int(x) if(x==int(x)) else int(x)+1\r\ndef ceilldiv(x,d): return x//d if(x%d==0) else x//d+1\r\ndef LCM(a,b): return (a*b)//gcd(a,b)\r\n\r\n\r\ndef solve():\r\n n,x,y = listin()\r\n wiz = x\r\n people = n-x\r\n req = ceill((y/100)*n)\r\n print(max(0,req - wiz))\r\n\t\t\r\nt = 1 \r\n# t = int(input()) \r\nfor hula in range(t):\r\n\tsolve()\r\n", "import decimal\r\nD = decimal.Decimal\r\n\r\nl1 = [int(x) for x in input().split()]\r\nn,x,y = l1[0],l1[1],l1[2]\r\nneed = n*y\r\nhave = x*100\r\nextra = 0\r\ni=0\r\nwhile need-have>extra:\r\n extra+=100\r\n i+=1\r\nprint(i)", "import math\r\nn, x, y= [int(x) for x in input().split(\" \")] \r\nc=0\r\np= (x/n) * 100\r\nif p>=y:\r\n print(0)\r\nelse:\r\n \r\n c= math.ceil((n*y)/100)\r\n print(abs(c-x))", "import math\nn, x, y = map(int, input().split())\nprint(max(math.ceil((n * y - (100 * x)) / 100), 0))\n", "import math\r\nn , x, y = list(map(int, input().split()))\r\ntemp = math.ceil( (y/100) * n)\r\n\r\nif temp - x >0:\r\n\tprint(temp - x)\r\nelse:\r\n\tprint(0)", "import math\r\nl=list(map(int,input().rstrip().split()))\r\nn=l[0]\r\nx=l[1]\r\ny=l[2]\r\np=(x/n)*100\r\nif p>=y:\r\n print(0)\r\nelse:\r\n rp=y-p\r\n ppl=(rp/100)*n\r\n print(math.ceil(ppl))\r\n", "n,x,y=map(int,input().split())\r\nif (n*y)/100>(n*y)//100:\r\n reqad=((n*y)//100)+1\r\nelse:\r\n reqad=((n*y)//100)\r\nans=reqad-x\r\nif ans<0:\r\n print(0)\r\nelse:\r\n print(ans)\r\n", "import math\r\nn,x,y=map(int,input().split())\r\nif (y*n)//100 -x>=0:\r\n print( math.ceil((y*n)/100) -x)\r\nelse:print(0)", "__author__ = 'Esfandiar'\nimport sys\nfrom math import ceil\ninput = sys.stdin.readline\nn,x,y = map(int,input().split())\nPerson = ceil(n*(y/100))\nprint(max(0,Person-x))\n", "from math import ceil\r\nn,x,y=map(int,input().split())\r\nif (ceil(y*n/100)-x)>0:\r\n\tprint(ceil(y*n/100)-x)\r\nelse:\r\n\tprint(0)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu May 27 09:37:05 2021\r\n\r\n@author: Vineet\r\n\"\"\"\r\n\r\nimport math\r\nn,x,y=map(int,input().split())\r\na=math.ceil((y/100)*n )\r\nif a>x:\r\n b=a-x\r\n print(b)\r\nelse:\r\n print(0)", "import math\nn,x,y=map(int,input().split())\np=int(math.ceil(n*(y/100)))\nif x>=p:\n print(0)\nelse:\n print(p-x)", "n, x, y = map(int, input().split())\r\ntotal = -(-y*n//100)\r\nprint(total - x if total >= x else 0)", "n, x, y = [int(x) for x in input().split()]\r\n\r\nq, r = divmod(n*y, 100)\r\nresult = q - x\r\nif r:\r\n result += 1\r\nif result > 0:\r\n print(result)\r\nelse:\r\n print(0)", "import math\r\nn,x,y = map(int,input().split())\r\n\r\nreq = y*n - 100*x\r\n\r\nif req<=0:\r\n print(0)\r\n exit()\r\n\r\nprint(math.ceil(req/100))\r\n", "import math\nn, x, y = map(int, input().split())\n\nprint(max(0, math.ceil((n*y)/100) - x))\n", "n, x, y = map(int,input().split())\r\nimport math\r\nprint (0 if x>=n*y/100 else math.ceil(n*y/100 - x))", "import math\r\nn=list(map(int, input().split()))\r\nk=math.ceil((n[0]*n[2])/100)-n[1]\r\nif(k>=0):\r\n print(k)\r\nelse:\r\n print(\"0\")", "n,x,y=map(int,input().split())\r\nprint(max(0, -((100 * x - n * y) // 100)))", "from math import *\r\nn1=input()\r\na=n1.split()\r\nn=int(a[0])\r\nx=int(a[1])\r\ny=int(a[2])\r\nk=(y/100)*n\r\ny=int(ceil(k))\r\nif y > x:\r\n print(y-x)\r\nelse:\r\n print(\"0\")", "n,x,y=input().split()\nn=int(n)\nx=int(x)\ny=int(y)\nimport math\nneeded=math.ceil((n*y)/100)\nif(needed>=x):\n print(needed-x)\nelse:\n print(0)\n", "import math\r\nn, x, y = map(int, input().split())\r\npercentage = math.ceil(n * y / 100)\r\nif x < percentage:\r\n print(percentage - x)\r\nelse:\r\n print(0)", "import math\r\nn,x,y = map(int,input().split())\r\nprint(max(0, math.ceil(n/100*y)-x))", "import math\r\nn,x,y=map(int,input().split())\r\nper=(y/100)*n\r\nt=math.ceil(per)\r\nt-=x\r\nif t<0:\r\n print(\"0\")\r\nelse:\r\n print(t)\r\n", "import math\r\nn,x,y = map(int,input().split())\r\na = y * n/100\r\na = math.ceil(a)\r\nif a>x:\r\n print(a-x)\r\nelse:\r\n print(0)\r\n ", "import math\r\narr = input().split()\r\nn = int(arr[0])\r\nx = int(arr[1])\r\ny = int(arr[2])\r\n\r\nans = ((n*y)/100) - x\r\nif ans > 0:\r\n\tprint(math.ceil(ans))\r\nelse:\r\n\tprint('0')", "\r\nimport math\r\nn,x,y = map(int, input().split())\r\nextraPeopleNeeded = math.ceil(y*n/100)\r\nif(extraPeopleNeeded > x):\r\n print (extraPeopleNeeded - x)\r\nelse:\r\n print(0)", "import math\r\nn, x, y = map(int, input().strip().split())\r\nres = (n*y)/100 - x\r\nif res <= 0:\r\n print(0)\r\nelse:\r\n print(math.ceil(res))\r\n", "import math\nn, x, y = tuple([int(x) for x in input().split()])\n#print(math.ceil(y * 0.01 * n) - x, 0)\nprint(max(math.ceil(y * 0.01 * n) - x, 0))", "import math\r\nx = input().split(\" \")\r\ny = math.ceil(((int(x[2])*int(x[0]))/100)-int(x[1]))\r\nif y > 0:\r\n\tprint(y)\r\nelse:\r\n\tprint(0)", "import math\r\nls = input().split(\" \")\r\nn = int(ls[0])\r\nx = int(ls[1])\r\ny = int(ls[2])\r\n\r\nreq_p = math.ceil((n*y/100.0))\r\nif(req_p > x):\r\n print(abs(req_p - x)) \r\nelse:\r\n print(0)\r\n\r\n", "from math import ceil\r\nn,x,y=map(int,input().split())\r\nprint(max(0,int(ceil(n*y/100)-x)))\r\n \r\n \r\n" ]
{"inputs": ["10 1 14", "20 10 50", "1000 352 146", "68 65 20", "78 28 27", "78 73 58", "70 38 66", "54 4 38", "3 1 69", "11 9 60", "71 49 65", "78 55 96", "2765 768 9020", "3478 1728 9727", "9678 6173 5658", "1138 570 6666", "7754 204 9038", "8403 7401 4769", "4909 2111 8860", "6571 6449 8965", "9178 2255 7996", "6151 6148 3746", "8890 5449 8734", "7879 2590 2818", "8484 6400 547", "7835 6710 1639", "2379 1436 9663", "6487 5670 8", "4470 2543 6", "7261 5328 10", "3871 3795 7", "9620 6557 6", "4890 1112 5", "1 1 1", "1 1 10000", "10000 1 1", "10000 1 10000", "10000 10000 1", "10000 10000 10000", "67 1 3", "7878 4534 9159", "1 1 1", "3271 5 50"], "outputs": ["1", "0", "1108", "0", "0", "0", "9", "17", "2", "0", "0", "20", "248635", "336578", "541409", "75290", "700603", "393339", "432827", "582642", "731618", "224269", "771004", "219441", "40008", "121706", "228447", "0", "0", "0", "0", "0", "0", "0", "99", "99", "999999", "0", "990000", "2", "717013", "0", "1631"]}
UNKNOWN
PYTHON3
CODEFORCES
305
158ed5933ad363941eb78811545a4c1f
A Vital Problem
Polycarp has a strict daily schedule. He has *n* alarms set for each day, and the *i*-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of alarms. Each of the next *n* lines contains a description of one alarm. Each description has a format "hh:mm", where *hh* is the hour when the alarm rings, and *mm* is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing. Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. *hh* denotes the number of hours, and *mm* denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. Sample Input 1 05:43 4 22:00 03:21 16:03 09:59 Sample Output 23:59 06:37
[ "n = int(input());\r\na = [];\r\nfor i in range(n):\r\n b = input().split(':');\r\n a.append(int(b[0]) * 60 + int(b[1]));\r\na.sort();\r\nt = a[0];\r\nfor i in range(n):\r\n a[i] -= t;\r\na.append(1440);\r\nu = -1;\r\nfor i in range(n):\r\n u = max(u, a[i+1] - a[i] - 1);\r\nh = u // 60;\r\nm = u - h * 60;\r\nif (h < 10): print('0', end='');\r\nprint(h, end=':');\r\nif (m < 10): print('0', end='');\r\nprint(m, end='');", "DAY = 60 * 24\r\ntime = [0] * (2 * DAY)\r\nl = 0\r\nfor i in range(int(input())):\r\n h, m = map(int, input().split(\":\"))\r\n m = h * 60 + m\r\n time[m] = 1\r\n time[m + DAY] = 1\r\n #print(m)\r\n#print(time)\r\nc = 0\r\nfor i in range(2 * DAY):\r\n if time[i] == 0:\r\n c += 1\r\n l = max(c, l)\r\n else:\r\n c = 0\r\nh = l // 60\r\nm = l % 60\r\nh = \"0\" * (2 - len(str(h))) + str(h)\r\nm = \"0\" * (2 - len(str(m))) + str(m)\r\n#print(l)\r\nprint(h, m, sep=\":\")\r\n", "n = int(input())\r\narr = []\r\nfor i in range(n):\r\n h, m = map(int, input().split(':'));\r\n cur = h * 60 + m;\r\n arr.append(cur)\r\narr.sort()\r\narr.append(24 * 60 + arr[0])\r\nmaxx = 0\r\nfor i in range(1, len(arr)):\r\n maxx = max(maxx, arr[i] - arr[i - 1] - 1)\r\nm = maxx % 60\r\nh = maxx // 60\r\nif (h < 10):\r\n print(0, end ='');\r\nprint(h, ':', sep = '', end = '')\r\nif (m < 10):\r\n print(0, end = '')\r\nprint(m)", "n=int(input())\r\nh=[0] * n\r\nm=[0] * n\r\nfor i in range(0,n) :\r\n h[i],m[i]=map(int,input().split(':'))\r\nfor i in range(0,n) :\r\n for j in range(i,n) :\r\n if h[j]<h[i] or (h[j]==h[i] and m[j]<m[i]) :\r\n t=h[j]\r\n h[j]=h[i]\r\n h[i]=t\r\n t=m[j]\r\n m[j]=m[i]\r\n m[i]=t\r\nmxh=0\r\nmxm=0\r\nfor i in range(0,n) :\r\n if i==n-1 :\r\n nowh=h[0]+24-h[i]\r\n nowm=m[0]-m[i]-1\r\n if nowm < 0 :\r\n nowh=nowh-1\r\n nowm=nowm+60\r\n if mxh<nowh or (mxh==nowh and mxm<nowm) :\r\n mxh=nowh\r\n mxm=nowm\r\n else :\r\n nowh=h[i+1]-h[i]\r\n nowm=m[i+1]-m[i]-1\r\n if nowm < 0 :\r\n nowh=nowh-1\r\n nowm=nowm+60\r\n if mxh<nowh or (mxh==nowh and mxm<nowm) :\r\n mxh=nowh\r\n mxm=nowm\r\nprint('%02d:%02d'%(mxh,mxm))", "n=int(input())\r\na=[0]*1000\r\nfor i in range(n):\r\n s=input()\r\n t1=s[0]+s[1]\r\n t2=s[3]+s[4]\r\n a[i]=60*int(t1)+int(t2)\r\nfor i in range(n):\r\n for j0 in range(i,n-1):\r\n j=n+i-2-j0\r\n if (a[j]>a[j+1]):\r\n q=a[j+1]\r\n a[j+1]=a[j]\r\n a[j]=q\r\na[n]=24*60+a[0]\r\nmx=a[0]\r\nfor i in range(n):\r\n mx=max(mx,a[i+1]-a[i]-1)\r\nq1=(mx//60)\r\nq2=(mx%60)\r\nif q1==0:\r\n s1=\"00\"\r\nelif q1<10:\r\n s1=\"0\"+str(q1)\r\nelse:\r\n s1=str(q1)\r\n\r\nif q2==0:\r\n s2=\"00\"\r\nelif q2<10:\r\n s2=\"0\"+str(q2)\r\nelse:\r\n s2=str(q2)\r\nprint(s1+\":\"+s2)\r\n ", "our = []\nfor i in range(int(input())):\n s = input()\n our.append(int(s[0:2]) * 60 + int(s[3:]))\nour.sort()\nour.append(our[0] + 24 * 60)\n\nres = 0\nfor i in range(len(our) - 1):\n res = max(res, our[i + 1] - our[i])\n\nres -= 1\nhour = str(res // 60)\nminute = str(res % 60)\nif len(hour) < 2:\n hour = '0' + hour\nif len(minute) < 2:\n minute = '0' + minute\nprint(hour + ':' + minute)", "n = int(input())\r\n\r\na = []\r\nfor i in range(n):\r\n x, y = map(int, input().split(':'))\r\n cur = x * 60 + y\r\n a.append(cur)\r\na.sort()\r\n\r\nans = 24 * 60 - a[n - 1] + a[0]\r\nfor i in range(n - 1):\r\n cur_ans = a[i + 1] - a[i]\r\n ans = max(ans, cur_ans)\r\n\r\nans = ans - 1\r\n\r\nx = ans // 60\r\ny = ans % 60\r\n\r\nx = str(x)\r\nif len(x) == 1:\r\n x = '0' + x\r\ny = str(y)\r\nif len(y) == 1:\r\n y = '0' + y\r\nprint('{}:{}'.format(x, y))", "n = int(input())\r\nl = []\r\nfor i in range(n):\r\n s = input()\r\n l.append( 60*(10 * int(s[0]) + int(s[1])) + 10*int(s[3]) + int(s[4]) )\r\n\r\nl = sorted(l)\r\nl.append(60 * 24 + l[0])\r\nl.append(- (60*24 - l[-1]))\r\n\r\nl = sorted(l)\r\n\r\nsol = max([l[i+1] - l[i] for i in range(len(l) -1)])\r\nsol = sol - 1\r\nh1 = sol // (10*60)\r\nsol = sol - h1 * 10*60\r\nh2 = sol//60\r\nsol = sol - h2*60\r\nh3 = sol//10\r\nsol = sol - 10*h3\r\nh4 = sol\r\n\r\nprint( str(h1) + str(h2) + \":\" + str(h3) + str(h4))", "n = int(input())\nL = []\ndiffs = []\nimport math\n\nmorning = 0\nnight = 24 * 60\n\ndef toTime(s):\n\thh = int(s[:2])\n\tmm = int(s[3:])\n\treturn hh * 60 + mm\n\t\ndef toDate(k):\n\thh = math.floor(k / 60.0)\n\tk -= hh * 60\n\tmm = k\n\treturn \"%02d:%02d\"%(hh,mm)\n\t\ndef outside():\n\tglobal L\n\treturn abs(morning - min(L))+abs(night-(max(L)+1))\n\nfor i in range(n):\n\td = input()\n\tL.append(toTime(d))\n\t\nL.sort()\nfor a, b in zip(L, L[1:]):\n\ta += 1\n\tdiff = abs(b - a)\n\tdiffs.append(diff)\n\t\ndiffs.append(outside())\nhigh = max(diffs)\n\n\nprint(toDate(high))", "n = int(input())\r\nx = []\r\nfor i in range (n):\r\n a, b = map(int, (input().split(':')))\r\n x.append(a*60 + b);\r\nx = sorted(x)\r\nx.append(x[0] + 24*60)\r\nm = 0\r\nfor i in range(n):\r\n m = max(m, x[i+1] - x[i]-1)\r\nx = str(m // 60)\r\ny = str(m % 60)\r\nif len(x) < 2:\r\n x = '0' + x\r\nif len(y) < 2:\r\n y = '0' + y\r\ns = x + ':' + y\r\nprint(s)", "t = 24*60\nA = [0]*t\n\nn = int(input())\nfor _ in range(n):\n h,m = map(int,input().split(':'))\n A[60*h+m] = 1\n\nsl = 0\nml = 0\nfor i in range(3*t): # Overkill is best kill\n if A[i%t] == 1:\n sl = 0\n else:\n sl += 1\n ml = max(sl,ml)\nprint(\"%02d:%02d\" % (ml//60, ml%60))\n", "n = int(input())\r\na = []\r\ndef mem(kek):\r\n return (int(kek[0])*10 + int(kek[1]))*60 + int(kek[3])*10 + int(kek[4])\r\ndef lol(kek):\r\n h = str(kek//60)\r\n m = str(kek%60)\r\n ans = \"\"\r\n if (len(h)<2): ans+=\"0\"\r\n ans+=h\r\n ans+=\":\"\r\n if (len(m)<2): ans+=\"0\"\r\n ans+=m\r\n return ans\r\ndelt = 60*24\r\nfor i in range(n):\r\n st = input()\r\n a.append(mem(st))\r\n a.append(mem(st)+delt )\r\n a.append(mem(st)+2*delt)\r\n\r\na = sorted(a)\r\nans = 0\r\nfor i in range(1,len(a)):\r\n ans = max(ans, a[i] - a[i-1] - 1)\r\nprint(lol(ans))\r\n", "def f(x):\r\n\tif x < 10:\r\n\t\treturn \"0\" + str(x)\r\n\treturn str(x)\r\n\r\nn = int(input())\r\ntimes = []\r\nfor i in range(0, n):\r\n\ts = input()\r\n\ttimes.append(60 * int(s[0:2]) + int(s[3:5]))\r\n\ttimes.append(60 * 24 + 60 * int(s[0:2]) + int(s[3:5]))\r\ntimes.sort()\r\nans = times[1] - times[0] - 1\r\nfor i in range(1, len(times)):\r\n\tans = max(ans , times[i] - times[i - 1] - 1) \r\nprint(\"{}:{}\".format(f(ans // 60), f(ans % 60)))", "n = int(input())\r\nminutes = []\r\nfor i in range(n):\r\n s = input()\r\n minutes.append(int(s[:-3]) * 60 + int(s[-2:]))\r\nminutes.sort()\r\n\r\nmax = 0\r\nfor i in range(0, n - 1):\r\n cur = minutes[i + 1] - minutes[i] - 1;\r\n \r\n if cur > max:\r\n max = cur\r\n\r\ncur = 24*60 - (minutes[-1] - minutes[0]) - 1\r\nif cur > max:\r\n max = cur\r\n\r\nhours = max // 60\r\nminutes = max - hours * 60\r\n\r\nh_str = str(hours)\r\nif len(h_str) < 2:\r\n h_str = \"0\" + h_str\r\n \r\nm_str = str(minutes)\r\nif len(m_str) < 2:\r\n m_str = \"0\" + m_str\r\n \r\nprint(h_str+\":\"+m_str)", "n = int(input())\r\n\r\na = []\r\n\r\nfor i in range(n):\r\n s = input().strip()\r\n hh, mm = map(int, s.split(':'))\r\n \r\n a.append(hh * 60 + mm)\r\n \r\na.sort()\r\n\r\na.append(a[0] + 1440);\r\n\r\nmx = 0\r\ni = 1\r\nwhile i < n + 1:\r\n mx = max(mx, a[i] - a[i - 1] - 1)\r\n i += 1\r\n\r\nhh = mx // 60\r\nmm = mx % 60\r\n\r\nprint('{}{}:{}{}'.format(hh // 10, hh % 10, mm // 10, mm % 10))\r\n", "n = int(input())\r\ntimes = [0] * 2880\r\nfor _ in range(n):\r\n hh, mm = map(int, input().split(':'))\r\n t = hh * 60 + mm\r\n times[t] = 1\r\n times[t + 1440] = 1\r\n\r\ni = 0\r\nres = -1\r\nwhile i < 1440:\r\n for j in range(i, i + 1440):\r\n if times[j] == 1:\r\n break\r\n res = max(res, j - i)\r\n i = j + 1\r\nhh, mm = divmod(res, 60)\r\nprint('{:02d}:{:02d}'.format(hh, mm))", "n = int(input())\r\narr = set()\r\nfor i in range(n):\r\n a, b = input().split(':')\r\n arr.add(int(a)*60+int(b))\r\n\r\narr = sorted(list(arr))\r\nans = 0\r\n\r\nfor i in range(n):\r\n if i == n-1:\r\n x = arr[0]+24*60\r\n else:\r\n x = arr[i+1]\r\n y = arr[i]\r\n ans = max(x-y-1, ans)\r\n\r\nprint('0'*(2-len(str(ans//60)))+str(ans//60)+\":\"+'0'*(2-len(str(ans%60)))+str(ans%60))", "import sys\r\nn=int(input())\r\nif n==1:\r\n print('23:59')\r\n sys.exit()\r\na=[]\r\nfor i in range(n):\r\n k,b=map(int,input().split(':'))\r\n a+=[k*60+b]\r\n\r\na=sorted(a)\r\n\r\nmn=0\r\nfor i in range(1,n):\r\n mn=max(mn,a[i]-a[i-1])\r\nmn=max(mn,24*60-a[n-1]+a[0])\r\nmn-=1\r\ns=''\r\nif(mn//60<10): s+='0'\r\ns+=str(mn//60)\r\ns+=':'\r\nif(mn%60<10): s+='0'\r\ns+=str(mn%60)\r\nprint(s)", "n = int(input())\r\na = []\r\nfor _ in range(n):\r\n h, m = map(int, input().split(':'))\r\n a.append(h * 60 + m)\r\n a.append((h + 24) * 60 + m)\r\na.sort()\r\nb = max(a[i + 1] - a[i] for i in range(2 * n - 1)) - 1\r\nprint('%02d:%02d' % divmod(b, 60))\r\n", "n = int(input())\r\na = []\r\n\r\nfor i in range(n):\r\n str = input()\r\n h = int(str[0:2]) * 60\r\n m = int(str[3:5])\r\n a.append(h + m)\r\n\r\na.sort()\r\n\r\nmx = 0\r\n\r\nfor i in range(n - 1):\r\n if mx < ((-a[i] + a[i + 1]) - 1):\r\n mx = ((-a[i] + a[i + 1]) - 1)\r\nif mx < (1440 + a[0] - a[n - 1] - 1):\r\n mx = 1440 + a[0] - a[n - 1] - 1\r\n\r\nif (mx // 60) < 10:\r\n print('0',end='')\r\n \r\nprint(mx // 60,end='')\r\n\r\nprint(':',end='')\r\n\r\nif (mx % 60) < 10:\r\n print('0',end='')\r\n\r\nprint(mx % 60)\r\n", "b = int(input())\r\ntimes = []\r\nline = \"\"\r\na = b\r\nwhile a > 0:\r\n a-=1\r\n curr_time = input().split(\":\")\r\n times.append(int(curr_time[0])*60+int(curr_time[1]))\r\ntimes.sort()\r\ntimes.append(times[0]+24*60)\r\nmax_delta = 0\r\nif times[0] > max_delta:\r\n max_delta = times[0]\r\nfor it in range(1,b+1):\r\n if times[it] - times[it - 1] > max_delta:\r\n max_delta = times[it] - times[it-1] - 1\r\nif max_delta // 60 < 10:\r\n first = \"0\"+str(max_delta // 60)\r\nelse:\r\n first = str(max_delta // 60)\r\nif max_delta - 60 * (max_delta // 60) < 10:\r\n second = \"0\"+str(max_delta - 60 * (max_delta // 60))\r\nelse:\r\n second = str(max_delta - 60 * (max_delta // 60))\r\nprint(first + \":\" + second)", "n = int(input())\r\n\r\nalarm_lst = [input().split(':') for _ in range(n)]\r\n\r\nif n == 1:\r\n print('23:59')\r\nelse:\r\n alarm_lst.sort()\r\n\r\n def time_diff(t1, t2):\r\n # 这里默认t1 > t2\r\n minute_diff = int(t1[0]) * 60 + int(t1[1]) - int(t2[0]) * 60 - int(t2[1]) - 1\r\n if minute_diff < 0:\r\n minute_diff += 24 * 60\r\n return [minute_diff // 60, minute_diff % 60]\r\n\r\n diff_lst = [time_diff(alarm_lst[i + 1], alarm_lst[i]) for i in range(n - 1)] + [time_diff(alarm_lst[0], alarm_lst[-1]), ]\r\n\r\n diff_lst.sort()\r\n\r\n print(f'{diff_lst[-1][0]:02}:{diff_lst[-1][1]:02}')", "n=int(input())\r\na=[]\r\nfor i in range(n):\r\n h,m=map(int,input().split(':'))\r\n a+=[h*60+m]\r\na.sort()\r\na+=[a[0]+24*60]\r\nans=-1\r\nfor i in range(n):\r\n ans=max(ans,a[i+1]-a[i]-1)\r\nh,m=ans//60,ans%60\r\nif h<10:\r\n print(0,end='')\r\nprint(h,end=':')\r\nif m<10:\r\n print(0,end='')\r\nprint(m,end='')", "n = int(input())\r\n\r\nz = []\r\n\r\nfor i in range(n):\r\n x = input().split(':')\r\n h = int(x[0])\r\n m = int(x[1])\r\n t = 60*h + m\r\n z.append(t)\r\n z.append(t+24*60)\r\n \r\nz.sort() \r\n \r\nans = 0\r\n\r\nfor i in range(0, 2*n-1):\r\n ans = max(ans, z[i+1]-z[i]-1)\r\n \r\nh = ans//60\r\nm = ans%60\r\nprint('%02d:%02d' % (h,m))", "n = int(input())\r\nday = 24 * 60\r\nv = []\r\nfor i in range(n) :\r\n s = input()\r\n h = int(s[0]) * 10 + int(s[1])\r\n m = int(s[3]) * 10 + int(s[4])\r\n tim = h * 60 + m\r\n v.append(int(tim))\r\n v.append(int(tim + day))\r\n v.append(int(tim + day + day))\r\nv.sort()\r\nans = 0\r\nfor i in range (len(v)) :\r\n if i > 0:\r\n ans = max(ans, v[i] - v[i - 1] - 1)\r\nm = ans % 60\r\nh = ans // 60\r\nprint(str(h // 10) + str(h % 10) + ':' + str(m // 10) + str(m % 10))", "n = int(input())\r\na = []\r\nfor i in range(n):\r\n\th, m = map(int, input().split(\":\"))\r\n\ta.append((h + 24) * 60 + m)\r\n\ta.append(h * 60 + m)\r\na.sort()\r\nj = 0\r\ns = 0\r\nans = 0\r\nfor i in range(0, 48 * 60):\r\n\tif (j < 2 * n and a[j] == i):\r\n\t\tans = max(ans, s)\r\n\t\ts = 0\r\n\t\tj += 1\r\n\t\tcontinue\r\n\telse:\r\n\t\ts += 1\r\nh = ans // 60\r\nm = ans % 60\r\nhans = \"\"\r\nmans = \"\"\r\nif h < 10:\r\n\thans = \"0\" + str(h)\r\nelse:\r\n\thans = str(h)\r\nif m < 10:\r\n\tmans = \"0\" + str(m)\r\nelse:\r\n\tmans = str(m)\r\nprint(hans + \":\" + mans)", "def dist(a, b):\r\n minsa = int(a.split(':')[0]) * 60 + int(a.split(':')[1])\r\n minsb = int(b.split(':')[0]) * 60 + int(b.split(':')[1])\r\n return minsb - minsa - 1\r\n\r\n\r\ndef ldist(a, b):\r\n minsa = (int(a.split(':')[0]) + 24) * 60 + int(a.split(':')[1])\r\n minsb = int(b.split(':')[0]) * 60 + int(b.split(':')[1])\r\n return minsa - minsb - 1\r\n \r\n\r\na = int(input())\r\nx = []\r\nfor i in range(a):\r\n t = input()\r\n x.append(t)\r\nx = sorted(x)\r\nans = 0\r\nfor i in range(0, len(x) - 1):\r\n r = dist(x[i], x[i + 1])\r\n ans = max(r, ans)\r\n\r\nans = max(ans, ldist(x[0], x[len(x) - 1]))\r\n# print(ldist(x[0], x[len(x) - 1]))\r\n\r\nh = ans // 60\r\nm = ans - (h * 60)\r\nif (h < 10):\r\n if (m < 10):\r\n print(\"0\" + str(h) + \":0\" + str(m))\r\n else: \r\n print(\"0\" + str(h) + \":\" + str(m))\r\nelse:\r\n if (m < 10):\r\n print(str(h) + \":0\" + str(m))\r\n else: \r\n print(str(h) + \":\" + str(m))\r\n", "t = int(input())\r\ntime = []\r\nfor i in range(t):\r\n plchd = input().split(\":\")\r\n hours = int(plchd[0])\r\n minutes = int(plchd[1])\r\n time.append(hours * 60 + minutes)\r\n time.append((hours + 24) * 60 + minutes)\r\ntime.sort()\r\nmaximum = 0\r\nfor i in range(1, len(time)):\r\n maximum = max(maximum, time[i] - time[i - 1] - 1)\r\nif len(time) == 2:\r\n print(\"23:59\")\r\nelse:\r\n hour = str(maximum // 60)\r\n minute = str(maximum % 60)\r\n if len(hour) == 1:\r\n hour = \"0\" + hour\r\n if len(minute) == 1:\r\n minute = \"0\" + minute\r\n print(hour + \":\" + minute)", "mx=0\nprev=0\nn=int(input())\ns=[];\nfor i in range(n):\n\tb=input()\n\ts.append(b)\ns.sort()\n#print(s)\nprev=(int(s[0][0])*10+(int(s[0][1])))*60+int(s[0][3])*10+int(s[0][4])\nfor i in range(1,n):\n\tcurr=(int(s[i][0])*10+int(s[i][1]))*60+int(s[i][3])*10+int(s[i][4])\n\tif(mx<curr-prev-1):\n\t\tmx=curr-prev-1\n\tprev=curr\n#for i in range(n):\n#\tprint(s[i])\nif(n>0):\n\tprev=((int(s[0][0])+2)*10+(int(s[0][1])+4))*60+(int(s[0][3]))*10+int(s[0][4])\n\tcurr=(int(s[n-1][0])*10+int(s[n-1][1]))*60+int(s[n-1][3])*10+int(s[n-1][4])\n\t#print(prev,curr)\n\t#print(mx)\n\tif(mx<prev-curr-1):\n\t\tmx=prev-curr-1\n\t#print(mx)\nhh=mx//60\nmm=mx%60\nh=[]\nm=[]\nif(hh<10):\t\n\th.append(\"0\")\n\th.append(hh)\nelse:\n\th.append((hh//10)%10)\n\th.append(hh%10)\nif(mm<10):\n\tm.append(\"0\")\n\tm.append(mm)\nelse:\n\tm.append((mm//10)%10)\n\tm.append(mm%10)\nprint(str(h[0])+str(h[1])+\":\"+str(m[0])+str(m[1]));\n\n", "n = int(input())\r\ntime = [None] * n\r\nfor i in range(n):\r\n\tt = input()\r\n\th, m = t.split(':')\r\n\th, m = int(h), int(m)\r\n\tnum = h*60 + m\r\n\ttime[i] = num\r\ntime.sort()\r\ntime.append(time[0] + 1440)\r\nans = (time[1] - time[0] - 1)\r\nfor i in range(i+1):\r\n ans = max(ans, time[i+1] - time[i] - 1)\r\nprint('{:02d}:{:02d}'.format(*divmod(ans, 60)))\r\n \r\n\r\n", "time = 60 * 24\r\nA = [0] * time\r\nn = int(input())\r\nfor i in range(n) :\r\n h, m = map(int, input().split(':'))\r\n A[60 * h + m] = 1\r\na = 0\r\nb = 0\r\nfor i in range(3 * time) :\r\n if A[i % time] == 1 :\r\n a = 0\r\n else :\r\n a += 1\r\n b = max(a , b)\r\nprint(\"%02d:%02d\" % (b // 60 , b % 60))\r\n", "def val(c):\r\n return ord(c) - ord('0')\r\n\r\ndef minutes(t):\r\n res = val(t[0]) * 10 * 60 + val(t[1]) * 60 + val(t[3]) * 10 + val(t[4])\r\n return res\r\n\r\ndef time_format(mx):\r\n h = mx // 60\r\n m = mx % 60\r\n h = str(h)\r\n m = str(m)\r\n if len(h) == 1:\r\n h = '0' + h\r\n if len(m) == 1:\r\n m = '0' + m\r\n return h + ':' + m\r\n\r\nn = int(input())\r\nt = []\r\ns = \"\"\r\nfor _ in range(n):\r\n s = input()\r\n t.append(minutes(s))\r\n\r\nt.sort()\r\nmx = 0\r\nfor i in range(len(t) - 1):\r\n mx = max(mx, t[i + 1] - t[i])\r\n\r\nmx = max(mx, 24 * 60 - t[-1] + t[0])\r\nmx -= 1\r\nprint(time_format(mx))", "import datetime\n\n\nn = int(input())\ndts_i = [[int(y) for y in input().split(':')] for x in range(n)]\ndts = []\n\nfor h, m in dts_i:\n dts.append(datetime.datetime(2017, 1, 1, h, m))\n\nfor h, m in dts_i:\n dts.append(datetime.datetime(2017, 1, 2, h, m))\n\nfor h, m in dts_i:\n dts.append(datetime.datetime(2017, 1, 3, h, m))\n\ndts = sorted(dts)\npairs = list(zip(dts, dts[1:]))\nlo, hi = max(pairs, key=lambda xy: xy[1] - xy[0])\ndelta = hi - lo - datetime.timedelta(minutes=1)\n\nhours, remainder = divmod(delta.seconds, 3600)\nminutes, seconds = divmod(remainder, 60)\n\nprint('{0:02d}:{1:02d}'.format(hours, minutes))\n", "def formatted_number(number):\r\n\tif (number < 10):\r\n\t\treturn \"0\" + str(number)\r\n\r\n\treturn str(number)\r\n\r\n\r\ndef print_max_duration(time):\r\n\thh = time // 60\r\n\tmm = time - hh * 60\r\n\r\n\tprint(formatted_number(hh)+\":\"+formatted_number(mm))\r\n\r\n\r\ndef parse_minutes(time):\r\n\thh = int(time[0:2])\r\n\tmm = int(time[3:])\r\n\treturn hh * 60 + mm\r\n\r\ndef main():\r\n\tn = int(input())\r\n\r\n\tarr = []\r\n\r\n\tfor i in range(n):\r\n\t\tarr.append(parse_minutes(input()))\r\n\r\n\tarr = sorted(arr)\r\n\r\n\tmax_duration = 0\r\n\tfor i in range(n - 1):\r\n\t\tmax_duration = max(max_duration, arr[i + 1] - arr[i] - 1)\r\n\r\n\tmax_duration = max(max_duration, (24 * 60 - arr[n - 1] - 1) + arr[0])\r\n\tprint_max_duration(max_duration)\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tmain()", "n = int(input())\r\narr = []\r\nfor i in range (0, n):\r\n s = input()\r\n h = s[0] + s[1]\r\n m = s[3] + s[4]\r\n h = int(h)\r\n m = int(m)\r\n arr.append(h * 60 + m)\r\narr.sort()\r\n#for i in range(0, n):\r\n# print(arr[i])\r\nres = 0\r\nfor i in range (1, n):\r\n if (arr[i] - arr[i - 1] - 1 > res):\r\n res = arr[i] - arr[i - 1] - 1\r\n#print('last = ', (1439 - arr[n - 1]) + arr[0])\r\nif ((1439 - arr[n - 1]) + arr[0] > res):\r\n res = (1439 - arr[n - 1]) + arr[0]\r\n#print('res = ', res)\r\nh = res // 60\r\nm = res % 60\r\nh = str(h)\r\nif (len(h) < 2):\r\n h = '0' + h\r\nm = str(m)\r\nif (len(m) < 2):\r\n m = '0' + m\r\nans = h + ':' + m\r\nprint(ans)\r\n", "n = int(input())\r\ns = ['.'] * n\r\nmx = 0\r\nfor i in range(n):\r\n s[i] = input()\r\nif n == 1:\r\n print('23:59')\r\nelse:\r\n s = sorted(s)\r\n for i in range(n):\r\n i1 = i\r\n i2 = (i + 1) % n\r\n col1 = int(s[i1][0:2]) * 60 + int(s[i1][3:5])\r\n col2 = int(s[i2][0:2]) * 60 + int(s[i2][3:5])\r\n if col1 > col2:\r\n if mx < col2 + 60 * 24 - col1 - 1:\r\n mx = col2 + 60 * 24 - col1 - 1\r\n else:\r\n if mx < col2 - col1 - 1:\r\n mx = col2 - col1 - 1\r\n print((mx // 60) // 10, (mx // 60) % 10, ':', (mx % 60) // 10, (mx % 60) % 10, sep = '')\r\n \r\n", "times = int(input())\r\nalarms = []\r\n\r\nfor x in range(0, times):\r\n time = input().split(':')\r\n alarms.append(int(time[0]) * 60 + int(time[1]))\r\n\r\nfor x in range(0, times):\r\n alarms.append(alarms[x] + 24 * 60)\r\n\r\nalarms.sort()\r\n\r\ndifferences = []\r\n\r\nfor x in range(0, times * 2 - 1):\r\n differences.append(alarms[x + 1] - alarms[x])\r\n\r\nmaxTime = max(differences) - 1\r\n\r\nhours = maxTime // 60\r\nminutes = maxTime % 60\r\n\r\nprint(str(hours).zfill(2) + \":\" + str(minutes).zfill(2))", "n = int(input())\r\ntimes = []\r\nfor _ in range(n):\r\n time = str(input())\r\n times.append((int(time[:2]), int(time[3:])))\r\n\r\ntimes.sort()\r\n\r\ndef to_minutes(a):\r\n return 60*a[0] + a[1]\r\n\r\ndef to_hours(a):\r\n return (a // 60, a % 60)\r\n\r\ndef pad(a):\r\n return ('0' if a < 10 else '') + str(a)\r\n\r\nlongest = 0\r\nfor i in range(1, n):\r\n longest = max(longest, to_minutes(times[i]) - to_minutes(times[i - 1]))\r\n\r\nlongest = max(longest, 60*24 + to_minutes(times[0]) - to_minutes(times[n - 1]))\r\n\r\nlongest -= 1\r\n\r\nhours, minutes = to_hours(longest)\r\n\r\n\r\nprint(pad(hours), ':', pad(minutes), sep='')", "n = int(input())\na = []\nfor i in range(n):\n\ts = input()\n\ta.append((int(s[0:2]), int(s[3:5])))\na.sort()\ni = 1\nres = 0\nwhile i < n:\n\tres = max(res, (a[i][0] * 60 + a[i][1]) - (a[i - 1][0] * 60 + a[i - 1][1]) - 1)\n\ti+=1\nres = max(res, ((a[0][0] + 24) * 60 + a[0][1]) - (a[-1][0] * 60 + a[-1][1]) - 1);\nans = ''\nif res // 60 < 10:\n\tans += '0'\nans+=str(res//60)\nans += ':'\nif res % 60 < 10:\n\tans += '0'\nans += str(res%60)\nprint(ans)", "n = int(input())\r\n\r\nalarms = []\r\n\r\nfor i in range(n):\r\n h, m = map(int, input().split(':'))\r\n t = h * 60 + m\r\n alarms.append(t)\r\n \r\nalarms.sort()\r\n\r\n# print(alarms)\r\nalarms.append(alarms[0] + 24 * 60)\r\nmx = -1\r\nfor i in range(1, len(alarms)):\r\n if (mx < alarms[i] - alarms[i - 1]):\r\n mx = alarms[i] - alarms[i - 1]\r\nmx -= 1\r\nprint('{:02d}:{:02d}'.format(mx // 60, mx % 60))\r\n", "n = int(input())\r\na = []\r\nfor x in range(0, n):\r\n b = list(map(int, input().split(':')))\r\n time = b[0]*60 + b[1]\r\n a.append(time)\r\n a.append(time + 24*60)\r\n a.append(time + 48*60)\r\na.sort()\r\n\r\nans = 0\r\nfor x in range(n, 2*n):\r\n ans = max(ans, a[x + 1] - a[x])\r\n\r\nprint(str((ans - 1)//60).zfill(2) + \":\" + str((ans - 1)%60).zfill(2))\r\n", "import sys\r\nn = int(input())\r\nlst = []\r\np = -1\r\nmx = 0\r\nwhile n > 0:\r\n str = input()\r\n x = 60 * (10 * int(str[0]) + int(str[1])) + 10 * int(str[3]) + int(str[4])\r\n lst.append(x)\r\n n -= 1\r\nlst.sort()\r\nfor i in lst:\r\n if p >= 0:\r\n mx = max(mx, i - p)\r\n p = i\r\nx = lst[0]\r\ny = lst[-1]\r\nmx = max(mx, x + 1440 - y)\r\nmx -= 1\r\nif mx // 60 < 10:\r\n print(0, end = '')\r\nprint(mx // 60, end = '')\r\nprint(':', end = '')\r\nif mx % 60 < 10:\r\n print(0, end = '')\r\nprint(mx % 60, end = '')", "import math\r\n#test = int(input())\r\nfor tes in range(1):\r\n n = int(input())\r\n L = [0]\r\n for i in range(n):\r\n \ts = str(input())\r\n \ts=s.split(':')\r\n \t#print(s)\r\n \tL.append(int(s[0])*60+int(s[1]))\r\n L.sort()\r\n L.append(24*60+L[1])\r\n #print(L)\r\n ans = 0\r\n for i in range(1,len(L)):\r\n \tans = max(ans, L[i]-L[i-1])\r\n ans-=1\r\n h = ans//60\r\n sec=ans%60\r\n if h<10:\r\n \th = '0'+str(h) \r\n else:\r\n \th = str(h)\r\n if sec<10:\r\n \tsec = '0' +str(sec)\r\n else:\r\n \tsec = str(sec)\r\n print(h+':'+sec)" ]
{"inputs": ["1\n05:43", "4\n22:00\n03:21\n16:03\n09:59", "20\n23:59\n00:00\n00:01\n00:02\n00:03\n00:04\n00:05\n00:06\n00:07\n00:08\n00:09\n00:10\n00:11\n00:12\n00:13\n00:14\n00:15\n00:16\n00:17\n00:18", "21\n23:28\n23:29\n23:30\n23:31\n23:32\n23:33\n23:34\n23:35\n23:36\n23:37\n23:38\n23:39\n23:40\n23:41\n23:42\n23:43\n23:44\n23:45\n23:46\n23:47\n23:48", "2\n00:00\n23:59", "2\n01:00\n01:01", "3\n01:00\n01:01\n01:02", "2\n06:25\n22:43", "2\n05:53\n04:15", "2\n11:24\n13:53", "3\n22:50\n11:46\n22:36", "4\n10:00\n15:30\n03:48\n11:46", "5\n01:40\n08:08\n14:58\n18:54\n17:52", "6\n04:05\n03:46\n18:53\n04:07\n22:58\n08:49", "7\n22:26\n21:15\n14:57\n08:27\n19:31\n13:51\n14:21", "8\n15:52\n06:02\n13:08\n06:18\n21:54\n05:02\n22:56\n00:10", "9\n01:38\n15:16\n18:50\n00:45\n17:26\n16:30\n09:10\n00:46\n05:49", "10\n01:01\n04:46\n12:17\n04:37\n19:20\n10:46\n12:50\n03:17\n23:50\n19:13", "20\n14:59\n00:52\n15:39\n08:40\n12:49\n15:15\n13:17\n14:29\n11:43\n14:39\n08:57\n12:53\n17:38\n11:23\n07:53\n12:58\n00:29\n06:20\n05:20\n23:59", "31\n21:46\n16:36\n19:00\n03:43\n07:33\n16:16\n22:08\n16:27\n14:25\n18:43\n14:32\n13:15\n13:27\n06:13\n22:34\n09:39\n11:55\n12:33\n17:39\n00:49\n09:51\n07:38\n00:42\n00:57\n01:40\n08:06\n16:39\n12:13\n12:15\n08:38\n14:24", "40\n22:10\n12:46\n13:20\n14:31\n23:38\n15:42\n15:53\n13:28\n00:03\n13:01\n10:44\n18:42\n12:35\n18:50\n19:35\n05:11\n02:29\n05:00\n06:06\n18:05\n08:09\n07:02\n14:51\n15:14\n09:48\n05:07\n04:53\n06:19\n00:18\n08:02\n15:08\n11:17\n00:59\n00:30\n01:17\n07:23\n10:20\n03:54\n16:55\n05:25", "50\n21:58\n09:10\n01:27\n20:25\n12:48\n20:44\n23:13\n08:44\n14:55\n05:58\n09:30\n01:54\n04:15\n14:25\n12:22\n13:37\n06:18\n20:07\n00:40\n19:11\n15:06\n15:49\n01:40\n17:53\n01:04\n19:54\n00:31\n22:25\n07:52\n10:25\n11:52\n13:24\n06:52\n08:42\n00:42\n15:09\n09:58\n16:25\n23:31\n11:26\n11:43\n00:59\n10:08\n07:42\n00:39\n14:35\n08:00\n16:04\n01:01\n03:19", "60\n17:21\n17:49\n12:33\n03:42\n16:16\n16:21\n22:06\n19:51\n14:52\n03:23\n08:16\n13:11\n19:16\n04:13\n12:22\n07:27\n07:09\n22:47\n20:21\n10:10\n19:52\n17:53\n15:45\n09:13\n18:36\n04:10\n03:59\n23:08\n19:30\n09:36\n18:58\n01:34\n14:25\n12:43\n19:12\n03:05\n04:25\n03:48\n04:14\n03:38\n02:29\n07:17\n19:06\n18:47\n12:24\n16:45\n21:40\n11:33\n07:52\n02:24\n01:00\n20:37\n21:20\n16:04\n20:24\n05:18\n00:57\n23:02\n18:56\n16:40", "70\n03:33\n23:36\n03:16\n18:18\n06:36\n06:58\n17:27\n04:07\n14:39\n15:53\n17:09\n05:16\n20:28\n09:34\n02:41\n14:18\n20:00\n04:14\n00:25\n20:18\n16:34\n10:13\n21:45\n11:08\n16:19\n20:50\n03:08\n05:06\n02:08\n02:51\n15:16\n11:02\n18:13\n18:35\n00:04\n08:50\n06:12\n20:16\n12:05\n04:01\n08:38\n03:57\n22:44\n04:28\n04:37\n10:32\n18:02\n15:04\n10:31\n07:28\n13:55\n15:15\n09:08\n19:54\n04:18\n04:29\n10:00\n13:47\n02:14\n23:15\n22:11\n21:17\n20:51\n05:46\n00:17\n01:59\n19:41\n02:37\n03:00\n19:14"], "outputs": ["23:59", "06:37", "23:40", "23:39", "23:58", "23:58", "23:57", "16:17", "22:21", "21:30", "12:55", "12:17", "06:49", "10:03", "10:00", "06:49", "06:05", "06:22", "06:20", "02:45", "02:34", "01:42", "01:50", "01:41"]}
UNKNOWN
PYTHON3
CODEFORCES
43
1591a073be244b2dc292fed6a4ee16c2
Inna and Huge Candy Matrix
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to *n* from top to bottom and the columns — from 1 to *m*, from left to right. We'll represent the cell on the intersection of the *i*-th row and *j*-th column as (*i*,<=*j*). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has *p* candies: the *k*-th candy is at cell (*x**k*,<=*y**k*). The time moved closer to dinner and Inna was already going to eat *p* of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix *x* times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix *y* times. And then he rotated the matrix *z* times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! The first line of the input contains fix integers *n*, *m*, *x*, *y*, *z*, *p* (1<=≤<=*n*,<=*m*<=≤<=109; 0<=≤<=*x*,<=*y*,<=*z*<=≤<=109; 1<=≤<=*p*<=≤<=105). Each of the following *p* lines contains two integers *x**k*, *y**k* (1<=≤<=*x**k*<=≤<=*n*; 1<=≤<=*y**k*<=≤<=*m*) — the initial coordinates of the *k*-th candy. Two candies can lie on the same cell. For each of the *p* candies, print on a single line its space-separated new coordinates. Sample Input 3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 Sample Output 1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1
[ "h, w, x, y, z, p = map(int, input().split())\r\nx, y, z = x % 4, y % 2, z % 4\r\n\r\ndef rotation(a, b):\r\n global h, w\r\n res = (b, h - a + 1)\r\n w, h = h, w\r\n return res\r\n\r\ndef flip(a, b):\r\n return a, w - b + 1\r\n\r\nres = []\r\nfor i in range(p):\r\n a, b = map(int, input().split())\r\n ch, cw = h, w\r\n for i in range(x):\r\n a, b = rotation(a, b)\r\n for i in range(y):\r\n a, b = flip(a, b)\r\n for i in range(3 * z):\r\n a, b = rotation(a, b)\r\n res += [str(a) + ' ' + str(b)]\r\n h, w = ch, cw\r\n\r\nprint('\\n'.join(map(str, res)))\r\n", "R,C,x,y,z,p=map(int,input().split())\r\nx=x%4\r\ny=y%2\r\nz=z%4\r\nfor i in range(p):\r\n i,j=map(int,input().split())\r\n r,c=R,C\r\n for _ in range(x):\r\n i,j=j,r-i+1\r\n r,c=c,r\r\n for _ in range(y):\r\n i,j=i,c-j+1\r\n for _ in range(z):\r\n i,j=c-j+1,i\r\n r,c=c,r\r\n print(i,j)", "n, m, x, y, z, p = map(int, input().split())\r\n\r\nx %= 4\r\ny %= 2\r\nz %= 4\r\n\r\nfor i in range(p):\r\n a, b = map(int, input().split())\r\n \r\n c, d = a, b\r\n N, M = n, m\r\n f, g = n, m\r\n\r\n if x == 1:\r\n c = b\r\n d = N + 1 - a\r\n f, g = m, n\r\n elif x == 2:\r\n c = N + 1 - a\r\n d = M + 1 - b\r\n elif x == 3:\r\n c = M + 1 - b\r\n d = a\r\n f, g = m, n\r\n\r\n a, b = c, d\r\n N, M = f, g\r\n\r\n if y == 1:\r\n d = M + 1 - b\r\n b = d\r\n\r\n if z == 1:\r\n c = M + 1 - b\r\n d = a\r\n elif z == 2:\r\n c = N + 1 - a\r\n d = M + 1 - b\r\n elif z == 3:\r\n c = b\r\n d = N + 1 - a\r\n\r\n a, b = c, d\r\n\r\n print(a, b)\r\n", "N, M, X, Y, Z, Q = map(int, input().split())\r\nfor q in range(Q):\r\n\tn, m = N, M\r\n\tr, c = map(int, input().split())\r\n\tif X % 4 == 1:\r\n\t\tr, c = c, n - r + 1\r\n\t\tn, m = m, n\r\n\telif X % 4 == 2:\r\n\t\tr, c = n - r + 1, m - c + 1\r\n\telif X % 4 == 3:\r\n\t\tr, c = m - c + 1, r\r\n\t\tn, m = m, n\r\n\tif Y % 2 == 1:\r\n\t\tc = m - c + 1\r\n\tif Z % 4 == 1:\r\n\t\tr, c = m - c + 1, r\r\n\t\tn, m = m, n\r\n\telif Z % 4 == 2:\r\n\t\tr, c = n - r + 1, m - c + 1\r\n\telif Z % 4 == 3:\r\n\t\tr, c = c, n- r + 1\r\n\t\tn, m = m, n\r\n\tprint(r, c)", "n, m, x, y, z, p = map(int, input().split())\r\nn, m, x, y, z = n + 1, m + 1, x % 4, y % 2, (4 - z) % 4\r\n\r\ndef a(i, j, n, m, k):\r\n if k == 0: return i, j, n, m\r\n if k == 1: return j, n - i, m, n\r\n if k == 2: return n - i, m - j, n, m\r\n return m - j, i, m, n\r\n\r\ndef b(i, j, m, k):\r\n if k == 0: return i, j\r\n if k == 1: return i, m - j\r\n\r\nfor i in range(p):\r\n u, v = map(int, input().split())\r\n u, v, q, p = a(u, v, n, m, x)\r\n u, v = b(u, v, p, y)\r\n u, v, q, p = a(u, v, q, p, z)\r\n print(u, v)\r\n", "n,m,x,y,z,p=map(int,input().split())\nx%=4\ny%=2\nz%=4\ntn,tm=n,m\n\nwhile p>=1:\n n,m=tn,tm\n p-=1\n sx,sy=map(int,input().split())\n for i in range(0,x):\n sx,sy=sy,n-sx+1\n n,m=m,n\n if y>0:\n sy=m-sy+1\n for i in range(0,z):\n sx,sy=m-sy+1,sx\n n,m=m,n\n print(sx,sy)\n", "import sys\r\n\r\ntry:\r\n sys.stdin = open('input.txt', 'r')\r\n sys.stdout = open('output.txt', 'w')\r\nexcept:\r\n pass\r\n\r\nn, m, x, y, z, p = (int(i) for i in input().split())\r\npoints = []\r\nfor i in range(0, p):\r\n points.append([int(j) for j in input().split()])\r\n\r\nx %= 4\r\ny %= 2\r\nz %= 4\r\n\r\nfor i in range(0, x):\r\n for i in range(0, p):\r\n point = [0, 0]\r\n point[1] = n - points[i][0] + 1\r\n point[0] = points[i][1]\r\n points[i] = point\r\n n, m = m, n\r\nif y == 1:\r\n for i in range(0, p):\r\n points[i][1] = m - points[i][1] + 1\r\nfor i in range(0, z):\r\n for i in range(0, p):\r\n point = [0, 0]\r\n point[1] = points[i][0]\r\n point[0] = m - points[i][1] + 1\r\n points[i] = point\r\n n, m = m, n\r\n\r\nfor i in range(0, p):\r\n print('%d %d\\n' % (points[i][0], points[i][1]), end = '')", "n,m,x,y,z,p = map(int,input().split())\n\nps = []\nfor i in range(p):\n ps.append(list(map(int,input().split())))\n\nx = x%4\ny = y%2\nz = ((z%4)*3)%4\n\nfor p in ps:\n mm,nn = m,n\n i,j = p\n for _ in range(x):\n i,j = j,nn-i+1\n mm,nn = nn,mm\n \n \n for _ in range(y):\n i,j = i,mm-j+1\n \n for _ in range(z):\n i,j = j,nn-i+1\n mm,nn = nn,mm\n \n print(i,j)", "import sys\nimport collections \nimport bisect\ninput = sys.stdin.readline \nip = lambda: input().rstrip('\\n')\nIP = lambda: list(map(int, ip().split()))\n\n\ndef horizontal_flip(x):\n global n, m \n x[1] = m+1 - x[1]\n return x \n\n\ndef vertical_flip(x):\n global n, m \n x[0] = n+1 - x[0]\n return x \n\n\ndef rotate(x, clockwise = True):\n global n, m\n n, m = m, n\n x[0], x[1] = x[1], x[0]\n if clockwise:\n x = horizontal_flip(x)\n else:\n x = vertical_flip(x)\n return x \n\n\ndef solve(p, x, y, z):\n if x == 2:\n p = vertical_flip(p)\n p = horizontal_flip(p)\n elif x == 0:\n pass \n else:\n p = rotate(p, x == 1)\n\n if y % 2:\n p = horizontal_flip(p)\n\n if z == 2:\n p = vertical_flip(p)\n p = horizontal_flip(p)\n elif z == 0:\n pass \n else:\n p = rotate(p, z == 3)\n return p \n\nN, M, x, y, z, p = IP()\nP = []\nx %= 4\nz %= 4 \n\nfor i in range(p):\n P.append(IP())\n\nfor i in range(p):\n n, m = N, M\n P[i] = solve(P[i], x, y, z)\n\nfor i in range(p):\n print(*P[i])", "n, m, x, y, z, p = map(int, input().split())\r\nx %= 4\r\ny %= 2\r\nz = (4 - (z % 4)) % 4\r\nfor _ in range(p):\r\n a, b = map(int, input().split())\r\n for i in range(x):\r\n n, m = m, n\r\n a, b = b, m - a + 1\r\n for i in range(y):\r\n b = m - b + 1\r\n for i in range(z):\r\n n, m = m, n\r\n a, b = b, m - a + 1\r\n if (x + z) % 2:\r\n n, m = m, n\r\n print(a, b)# 1698410471.4401288", "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef f(a, b, x, c):\r\n\r\n n1, m1 = n, m\r\n if c == 1:\r\n x = 4 - x\r\n if xx % 2:\r\n n1, m1 = m, n\r\n\r\n if x == 1:\r\n a, b = b, n1-a+1\r\n elif x == 2:\r\n a, b = n1 - a + 1, m1 - b + 1\r\n elif x == 3:\r\n a, b = m1-b+1, a\r\n\r\n return (a, b)\r\n\r\n\r\nn, m, xx, y, z, p = map(int, input().split())\r\nxx %= 4\r\ny %= 2\r\nz %= 4\r\nfor _ in range(p):\r\n a, b = map(int, input().split())\r\n a, b = f(a, b, xx, 0)\r\n if y == 1:\r\n if xx % 2:\r\n b = n-b+1\r\n else:\r\n b = m-b+1\r\n a, b = f(a, b, z, 1)\r\n print(a, b)\r\n", "import collections\nimport heapq\nimport sys\nimport math\nimport itertools\nimport bisect\nfrom io import BytesIO, IOBase\nimport os\n######################################################################################\n#--------------------------------------Input-----------------------------------------#\n######################################################################################\n\n\ndef value(): return tuple(map(int, input().split()))\ndef values(): return tuple(map(int, sys.stdin.readline().split()))\ndef inlst(): return [int(i) for i in input().split()]\ndef inlsts(): return [int(i) for i in sys.stdin.readline().split()]\ndef inp(): return int(input())\ndef inps(): return int(sys.stdin.readline())\ndef instr(): return input()\ndef stlst(): return [i for i in input().split()]\n\n\n######################################################################################\n#--------------------------------------code here-------------------------------------#\n######################################################################################\n\ndef solve():\n n,m,x,z,y,p=value()\n x,y,z=x%4,y%4,z%2\n m0,n0=m,n\n for i in range(p):\n m,n=m0,n0\n xx,yy=value()\n for i in range(x):\n xx,yy=yy,n-xx+1\n n,m=m,n\n if z==1:\n yy=m-yy+1\n for i in range(y):\n xx,yy=m+1-yy,xx\n n,m=m,n\n print(xx,yy)\n\n\n\nif __name__ == \"__main__\":\n solve()\n" ]
{"inputs": ["3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3", "5 5 0 0 0 1\n1 4", "14 76 376219315 550904689 16684615 24\n11 21\n1 65\n5 25\n14 63\n11 30\n1 19\n5 7\n9 51\n2 49\n13 75\n9 9\n3 63\n8 49\n5 1\n1 67\n13 31\n9 35\n3 53\n13 73\n5 71\n1 32\n5 49\n1 41\n14 69", "63 67 18046757 61758841 85367218 68\n22 30\n25 40\n56 58\n29 11\n34 63\n28 66\n51 5\n39 64\n1 23\n24 61\n19 47\n10 31\n55 28\n52 26\n38 7\n28 31\n13 27\n37 42\n10 52\n19 33\n7 36\n13 1\n46 40\n21 41\n1 1\n6 35\n10 4\n46 9\n21 57\n1 49\n34 14\n14 35\n43 4\n1 41\n25 22\n18 25\n27 23\n43 17\n34 23\n29 4\n50 40\n43 67\n55 37\n4 60\n35 32\n22 58\n22 12\n9 2\n42 44\n20 57\n5 37\n22 48\n26 8\n33 1\n61 28\n55 18\n21 1\n1 2\n36 29\n45 65\n1 41\n22 46\n25 67\n25 41\n36 42\n8 66\n52 60\n28 50", "75 18 163006189 147424057 443319537 71\n56 7\n1 5\n17 4\n67 13\n45 1\n55 9\n46 14\n23 10\n10 1\n1 1\n14 9\n18 16\n25 9\n22 4\n73 13\n51 7\n43 13\n59 1\n62 15\n37 6\n43 11\n66 17\n61 13\n45 1\n16 7\n46 7\n25 1\n52 13\n74 7\n16 17\n34 11\n37 16\n24 5\n10 11\n20 5\n74 1\n57 7\n72 10\n21 11\n66 13\n46 1\n46 13\n65 1\n68 11\n14 13\n72 11\n58 1\n16 15\n49 1\n53 10\n30 1\n75 1\n45 4\n42 13\n52 10\n25 1\n31 1\n26 1\n21 7\n27 4\n55 10\n61 1\n37 3\n13 18\n24 1\n11 3\n14 17\n34 5\n49 4\n56 13\n19 11", "99 65 100328801 11658361 60379320 41\n46 61\n92 23\n46 16\n60 56\n50 42\n24 19\n43 54\n40 1\n41 16\n19 34\n57 59\n84 20\n33 3\n82 59\n74 53\n26 65\n83 30\n76 14\n73 55\n58 33\n97 62\n10 18\n70 1\n56 27\n64 25\n25 57\n28 21\n96 2\n10 41\n99 59\n25 15\n1 3\n46 27\n38 65\n34 25\n64 55\n37 53\n78 43\n70 64\n64 49\n4 12", "60 1 884622497 447787585 45746569 5\n41 1\n3 1\n57 1\n1 1\n28 1", "29 9 101222353 522378781 221562741 21\n8 1\n12 8\n21 7\n29 2\n12 3\n1 4\n18 9\n28 6\n2 3\n10 8\n16 4\n3 9\n14 4\n15 3\n16 6\n28 7\n18 1\n12 1\n23 1\n11 1\n18 4", "14 33 331499150 82809609 266661996 75\n9 10\n1 1\n8 8\n13 26\n3 1\n5 1\n8 13\n3 19\n1 13\n1 6\n13 1\n12 19\n5 25\n3 10\n6 19\n6 23\n7 1\n11 7\n11 16\n7 32\n8 30\n1 2\n11 2\n13 25\n8 7\n9 33\n9 1\n1 7\n1 30\n14 32\n9 10\n11 7\n12 5\n11 31\n7 10\n7 21\n9 28\n3 23\n11 31\n9 12\n5 14\n9 7\n10 11\n5 14\n5 14\n4 16\n3 32\n3 16\n13 28\n5 10\n2 8\n4 11\n8 4\n11 15\n1 12\n5 17\n14 10\n13 12\n7 7\n2 32\n3 25\n4 5\n4 31\n10 23\n10 28\n5 8\n5 31\n4 25\n3 25\n13 7\n1 26\n6 4\n9 33\n5 4\n1 14", "26 89 146819986 242756320 184308201 43\n20 71\n12 22\n3 73\n9 48\n1 32\n5 20\n1 18\n19 57\n23 77\n1 4\n17 86\n1 13\n16 64\n1 56\n7 63\n18 38\n17 82\n21 43\n5 16\n9 39\n7 23\n5 53\n19 8\n25 10\n11 69\n11 7\n16 47\n25 48\n20 87\n14 16\n1 16\n14 43\n22 43\n11 89\n7 3\n1 57\n5 43\n21 1\n1 21\n3 85\n5 7\n19 16\n7 15", "57 62 402127657 5834146 166754152 26\n55 15\n3 10\n10 21\n25 45\n28 50\n54 39\n1 57\n5 11\n13 54\n52 17\n52 9\n28 3\n37 25\n29 15\n55 33\n23 25\n28 1\n46 7\n39 25\n20 43\n33 49\n52 47\n22 11\n37 37\n52 48\n25 53", "83 53 263444877 330109611 453128994 25\n47 7\n40 13\n47 53\n23 37\n57 23\n4 38\n39 25\n42 41\n61 23\n74 6\n48 5\n56 53\n48 37\n13 37\n34 32\n49 4\n43 32\n14 1\n75 15\n59 18\n25 14\n46 23\n47 48\n72 3\n55 17", "65 66 68528825 50348481 104442753 7\n1 49\n54 47\n16 37\n1 34\n51 29\n36 17\n11 16", "63 5 311153546 666957619 681867949 3\n14 3\n22 1\n14 2", "1 9 549924215 115901887 855235569 1\n1 6", "85 26 48272945 423830401 423026164 3\n35 1\n50 17\n55 2", "67 61 443905131 226973811 158369983 1\n52 51", "1 13 348638338 31146449 81215464 3\n1 4\n1 10\n1 6", "68 45 637151929 93583345 392834373 10\n52 11\n28 1\n67 21\n33 29\n43 28\n30 17\n39 30\n52 37\n11 7\n11 26", "25 45 20761261 857816695 7926985 1\n1 26", "1 1 0 0 0 2\n1 1\n1 1", "2 2 1 0 0 4\n1 1\n1 2\n2 2\n2 1", "2 2 0 1 0 4\n1 1\n1 2\n2 2\n2 1", "2 2 0 0 1 4\n1 1\n1 2\n2 2\n2 1", "2 1 1 0 0 2\n1 1\n2 1", "2 1 0 1 0 2\n1 1\n2 1", "2 1 0 0 1 2\n1 1\n2 1", "1 1 0 1 0 2\n1 1\n1 1"], "outputs": ["1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1", "1 4", "4 21\n14 65\n10 25\n1 63\n4 30\n14 19\n10 7\n6 51\n13 49\n2 75\n6 9\n12 63\n7 49\n10 1\n14 67\n2 31\n6 35\n12 53\n2 73\n10 71\n14 32\n10 49\n14 41\n1 69", "38 42\n28 39\n10 8\n57 35\n5 30\n2 36\n63 13\n4 25\n45 63\n7 40\n21 45\n37 54\n40 9\n42 12\n61 26\n37 36\n41 51\n26 27\n16 54\n35 45\n32 57\n67 51\n28 18\n27 43\n67 63\n33 58\n64 54\n59 18\n11 43\n19 63\n54 30\n33 50\n64 21\n27 63\n46 39\n43 46\n45 37\n51 21\n45 30\n64 35\n28 14\n1 21\n31 9\n8 60\n36 29\n10 42\n56 42\n66 55\n24 22\n11 44\n31 59\n20 42\n60 38\n67 31\n40 3\n50 9\n67 43\n66 63\n39 28\n3 19\n27 63\n22 42\n1 39\n27 39\n26 28\n2 56\n8 12\n18 36", "20 7\n75 5\n59 4\n9 13\n31 1\n21 9\n30 14\n53 10\n66 1\n75 1\n62 9\n58 16\n51 9\n54 4\n3 13\n25 7\n33 13\n17 1\n14 15\n39 6\n33 11\n10 17\n15 13\n31 1\n60 7\n30 7\n51 1\n24 13\n2 7\n60 17\n42 11\n39 16\n52 5\n66 11\n56 5\n2 1\n19 7\n4 10\n55 11\n10 13\n30 1\n30 13\n11 1\n8 11\n62 13\n4 11\n18 1\n60 15\n27 1\n23 10\n46 1\n1 1\n31 4\n34 13\n24 10\n51 1\n45 1\n50 1\n55 7\n49 4\n21 10\n15 1\n39 3\n63 18\n52 1\n65 3\n62 17\n42 5\n27 4\n20 13\n57 11", "61 46\n23 92\n16 46\n56 60\n42 50\n19 24\n54 43\n1 40\n16 41\n34 19\n59 57\n20 84\n3 33\n59 82\n53 74\n65 26\n30 83\n14 76\n55 73\n33 58\n62 97\n18 10\n1 70\n27 56\n25 64\n57 25\n21 28\n2 96\n41 10\n59 99\n15 25\n3 1\n27 46\n65 38\n25 34\n55 64\n53 37\n43 78\n64 70\n49 64\n12 4", "20 1\n58 1\n4 1\n60 1\n33 1", "22 1\n18 8\n9 7\n1 2\n18 3\n29 4\n12 9\n2 6\n28 3\n20 8\n14 4\n27 9\n16 4\n15 3\n14 6\n2 7\n12 1\n18 1\n7 1\n19 1\n12 4", "6 10\n14 1\n7 8\n2 26\n12 1\n10 1\n7 13\n12 19\n14 13\n14 6\n2 1\n3 19\n10 25\n12 10\n9 19\n9 23\n8 1\n4 7\n4 16\n8 32\n7 30\n14 2\n4 2\n2 25\n7 7\n6 33\n6 1\n14 7\n14 30\n1 32\n6 10\n4 7\n3 5\n4 31\n8 10\n8 21\n6 28\n12 23\n4 31\n6 12\n10 14\n6 7\n5 11\n10 14\n10 14\n11 16\n12 32\n12 16\n2 28\n10 10\n13 8\n11 11\n7 4\n4 15\n14 12\n10 17\n1 10\n2 12\n8 7\n13 32\n12 25\n11 5\n11 31\n5 23\n5 28\n10 8\n10 31\n11 25\n12 25\n2 7\n14 26\n9 4\n6 33\n10 4\n14 14", "71 7\n22 15\n73 24\n48 18\n32 26\n20 22\n18 26\n57 8\n77 4\n4 26\n86 10\n13 26\n64 11\n56 26\n63 20\n38 9\n82 10\n43 6\n16 22\n39 18\n23 20\n53 22\n8 8\n10 2\n69 16\n7 16\n47 11\n48 2\n87 7\n16 13\n16 26\n43 13\n43 5\n89 16\n3 20\n57 26\n43 22\n1 6\n21 26\n85 24\n7 22\n16 8\n15 20", "15 3\n10 55\n21 48\n45 33\n50 30\n39 4\n57 57\n11 53\n54 45\n17 6\n9 6\n3 30\n25 21\n15 29\n33 3\n25 35\n1 30\n7 12\n25 19\n43 38\n49 25\n47 6\n11 36\n37 21\n48 6\n53 33", "47 37\n41 44\n1 37\n17 61\n31 27\n16 80\n29 45\n13 42\n31 23\n48 10\n49 36\n1 28\n17 36\n17 71\n22 50\n50 35\n22 41\n53 70\n39 9\n36 25\n40 59\n31 38\n6 37\n51 12\n37 29", "65 49\n12 47\n50 37\n65 34\n15 29\n30 17\n55 16", "3 50\n5 42\n4 50", "1 4", "1 35\n17 50\n2 55", "16 51", "1 4\n1 10\n1 6", "17 11\n41 1\n2 21\n36 29\n26 28\n39 17\n30 30\n17 37\n58 7\n58 26", "25 26", "1 1\n1 1", "1 2\n2 2\n2 1\n1 1", "1 2\n1 1\n2 1\n2 2", "2 1\n1 1\n1 2\n2 2", "1 2\n1 1", "1 1\n2 1", "1 1\n1 2", "1 1\n1 1"]}
UNKNOWN
PYTHON3
CODEFORCES
12
15dc09ce785b1080b799acedace9411c
Okabe and Banana Trees
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees. Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers and 0<=≤<=*x*,<=*y*. There is a tree in such a point, and it has *x*<=+<=*y* bananas. There are no trees nor bananas in other points. Now, Okabe draws a line with equation . Okabe can select a single rectangle with axis aligned sides with all points on or under the line and cut all the trees in all points that are inside or on the border of this rectangle and take their bananas. Okabe's rectangle can be degenerate; that is, it can be a line segment or even a point. Help Okabe and find the maximum number of bananas he can get if he chooses the rectangle wisely. Okabe is sure that the answer does not exceed 1018. You can trust him. The first line of input contains two space-separated integers *m* and *b* (1<=≤<=*m*<=≤<=1000, 1<=≤<=*b*<=≤<=10000). Print the maximum number of bananas Okabe can get from the trees he cuts. Sample Input 1 5 2 3 Sample Output 30 25
[ "def get2(n):\n\tres = n*(n+1)*(2*n+1)//6 + n*(n+1)//2\n\tres //= 2;\n\treturn res\n\ndef get(x,y):\n\treturn get2(x+y) - get2(x-1) - get2(y-1)\n\nm,b = input().split()\nm = int(m)\nb = int(b)\n\nmv = 0\nfor i in range(b+1):\n\tj = m*b-m*i\n\tcur = get(j,i)\n\tif cur > mv:\n\t\tmv = cur\n\nprint(mv)", "m,b=map(int,input().split())\r\nr=-1\r\nfor i in range(b):\r\n x=(b-i)*m;\r\n s=(i+x)*(x+1)*(i+1)\r\n r=max(r,s)\r\nprint(r//2)\r\n\r\n", "I = lambda : map(int, input().split())\nm, b = I()\nmx = 0\nfor y in range(0, 100001):\n x = m*(b-y)\n if x>=0:\n mx = max(mx, (y+1)*x*(x+1)//2 + (x+1)*y*(y+1)//2)\nprint(mx)\n", "import math\r\nimport sys\r\nfrom collections import *\r\nfrom bisect import bisect_left, bisect_right\r\n \r\n \r\n \r\ndef cint() : return list(map(int, sys.stdin.readline().strip().split()))\r\ndef cstr() : return list(map(str, input().split(' '))) \r\n \r\n\r\ndef solve():\r\n m, b = cint()\r\n\r\n h = b\r\n w = m*b\r\n maxx = 0\r\n for h in range(b):\r\n w = int((b-h)*m)\r\n temp = ((w+1)*h*(h+1))//2 + ((h+1)*w*(w+1))//2\r\n if temp > maxx: maxx = temp\r\n \r\n\r\n print(maxx)\r\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 # t = int(input())\r\n t = 1\r\n \r\n while t!=0:\r\n solve()\r\n t-=1", "def sigma(n):\r\n return n * (n + 1) // 2\r\n\r\ndef banans(p, q):\r\n return (p + 1) * sigma(q) + (q + 1) * sigma(p)\r\n\r\nm, b = [int(x) for x in input().split()]\r\n\r\nr = 0\r\nfor i in range(m * b + 1):\r\n if i % m == 0:\r\n p, q = i, b - i // m\r\n r = max(r, banans(p, q))\r\n\r\nprint(r)", "def f(x):\r\n return x*(x+1)//2\r\nm, b = map(int, input().split())\r\nc,x,y,ans=0,0,0,0\r\nfor y in range(b+1):\r\n x = (b-y)*m\r\n c = (x + 1) * f(y) + (y + 1) * f(x)\r\n ans=max(ans,c)\r\nprint(int(ans))\r\n", "def sumRectangle(x,y):\r\n s = 0\r\n a = (y+1)*(y)//2\r\n b = (y+1)*(x+1)*x//2\r\n return a*(x+1)+b\r\n \r\nm,b = [int(x) for x in input().split(' ')]\r\n\r\nmx = -1\r\n\r\nfor y in range(b+1):\r\n sumR = sumRectangle((b-y)*m,y)\r\n if sumR > mx:\r\n mx=sumR\r\n\r\nprint(mx)\r\n ", "sum_n = lambda n: (n * (n + 1)) // 2\r\nm, b = map(int, input().split())\r\nans = 0\r\nfor y in range(b + 1):\r\n x = m * (b - y)\r\n ans = max(ans, sum_n(x) * (y + 1) + sum_n(y) * (x + 1))\r\n\r\nprint(ans)\r\n", "# Uses python3\r\nfrom sys import stdin, stdout\r\nimport cProfile\r\n\r\nprintHeap = str()\r\ntest = False\r\nmemory_constrained = False\r\n\r\n\r\ndef display(string_to_print):\r\n stdout.write(str(string_to_print) + \"\\n\")\r\n\r\n\r\ndef test_print(output):\r\n if test:\r\n stdout.write(str(output) + \"\\n\")\r\n\r\n\r\ndef display_list(list1, sep=\" \"):\r\n stdout.write(sep.join(map(str, list1)) + \"\\n\")\r\n\r\n\r\ndef get_int():\r\n return int(stdin.readline().strip())\r\n\r\n\r\ndef get_tuple():\r\n return map(int, stdin.readline().strip().split())\r\n\r\n\r\ndef get_list():\r\n return list(map(int, stdin.readline().strip().split()))\r\n\r\n\r\nmemory = dict()\r\n\r\n\r\ndef clear_cache():\r\n global memory\r\n memory = dict()\r\n\r\n\r\ndef cached_fn(fn, *args):\r\n global memory\r\n if args in memory:\r\n return memory[args]\r\n else:\r\n result = fn(*args)\r\n memory[args] = result\r\n return result\r\n\r\n\r\n# ----------------------------------------------------------------------------------- MAIN PROGRAM\r\nimport math, copy\r\n\r\n\r\ndef main():\r\n m, b = get_tuple()\r\n y = b*m\r\n ma = 0\r\n for x in range(b+1):\r\n ma = max(ma, (x+1)*((y*(y+1))//2) + (y+1)*((x*(x+1))//2))\r\n y = y-m\r\n print(ma)\r\n\r\n\r\n\r\n\r\n\r\n\r\n# --------------------------------------------------------------------------------------------- END\r\n\r\n\r\ncProfile.run('main()') if test else main()", "\"\"\"\r\n\tAuthor\t\t: Arif Ahmad\r\n\tDate \t\t: 27-06-17\r\n\tAlgo \t\t: Math \r\n\tDifficulty\t: Medium\r\n\"\"\"\r\nfrom sys import stdin, stdout\r\n\r\ndef series(x):\r\n\treturn int(x * (x + 1) / 2)\r\n\r\ndef main():\r\n\tm, b = [int(_) for _ in stdin.readline().strip().split()]\r\n\r\n\tans = 0\r\n\tfor y in range(b + 1):\r\n\t\tx = m * (b - y)\r\n\t\ttotal = (y+1) * series(x) + (x+1) * series(y)\r\n\t\tans = max(ans, total)\r\n\r\n\tstdout.write(str(int(ans)) + '\\n')\r\n\t\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n ", "import math\r\nm,b=list(map(int,input().split()))\r\nans=0\r\nfor y in range(b+1):\r\n\tx=m*(b-y)\r\n\tp=((x+1)*(y+1)*(x+y))//2\r\n\tans=max(ans,p)\r\nprint(ans)\r\n\t\t\t\t\t ", "m,b,mx=map(int,input().split()+[0])\r\nfor y in range(b):\r\n x=(b-y)*m\r\n mx=max(mx,(x+1)*(y*(y+1)//2)+(y+1)*(x*(x+1)//2))\r\nprint(mx)", "m, b = [int(i) for i in input().split()]\r\nres = 0\r\nfor i in range(b + 1):\r\n\tj = (b - i) * m\r\n\tres = max(res, (i + 1) * (j + 1) * (i + j) // 2)\r\nprint(res)", "m, b = [int(i) for i in input().split()]\n\nans = 0\n\nfor y in range(b + 1):\n x = (b - y) * m\n kirby = (x + 1) * x // 2 * (1 + y) + (y + 1) * y // 2 * (1 + x)\n ans = max(ans, kirby)\nprint(ans)", "m, b = map(int, input().split())\r\nf = lambda x, y: (x + y) * (x + 1) * (y + 1) >> 1\r\nprint(max(f(k * m, b - k) for k in range(b + 1)))", "m,b=map(int,input().split(\" \"))\r\nans=0\r\nfor i in range(0,b+1):\r\n x=m*(b-i)\r\n cnt=(x+1)*(i+1)*(x+i)//2\r\n ans=max(ans,cnt)\r\nprint(ans)\r\n ", "#! python3\n\nm, b = [int(x) for x in input().strip().split(' ')]\n\nr = 0\nfor y in range(b+1):\n x = (b-y)*m\n p = x*(x+1)//2\n s = p * (y+1) + x * y * (y+1) // 2 + y * (y+1) // 2\n if s > r:\n #print(y)\n r = s\nprint(r)\n", "m,b=map(int,input().split())\r\na = 0\r\nfor i in range(b):\r\n a=max(a,(m*(b-i)*(m*(b-i)+1)//2)*(i+1)+i*(i+1)//2*(m*(b-i)+1))\r\nprint(a)\r\n", "def se(m,b,s,v):\r\n\tif s==\"x\":\r\n\t\treturn (m*b-v)//m\r\n\telse:\r\n\t\treturn (m*b-m*v)\r\ndef main():\r\n\tm, b=tuple(map(int,input().split()))\r\n\ty=se(m,b,\"x\",0)\r\n\tk=[]\r\n\tfor i in range(y+1):\r\n\t\tx=se(m,b,\"y\",i)\r\n\t\tk+=[(i+1)*(x+1)*(i+x)//2]\r\n\tprint(max(k))\r\nif __name__=='__main__':\r\n\tmain()", "m,b=list(map(int,input().split()))\r\n\r\n\r\n\r\n\r\n\r\n\r\nu=0\r\nfor j in range(b-1,-1,-1):\r\n y=j\r\n x=m*(b-j)\r\n\r\n s=x*(x+1)//2\r\n t=y*(y+1)//2\r\n p=t+s+(s)*y+t*x\r\n if p>u:\r\n u=p\r\n\r\nprint(u)\r\n", "m,b=map(int,input().split())\nans=0\nfor i in range(b+1):\n\tj=(b-i)*m\n\tif ans<((i+j)*(i+1)*(j+1))//2:\n\t\tans=((i+j)*(i+1)*(j+1))//2\nprint (ans)\n", "m,b=map(int,input().split())\nf=lambda n: n*(n+1)//2\ndef g(y):\n x=m*(b-y)\n return f(x)*(y+1)+f(y)*(x+1)\nprint(max(g(y) for y in range(b+1)))\n", "import sys\n\ndef main():\n m,b = map(int,sys.stdin.readline().split())\n \n def calc(y):\n x = (b-y)*m\n return ((y*(y+1)*(x+1))>>1) + ((x*(x+1)*(y+1))>>1)\n \n res = 0\n for i in range(b+1):\n t = calc(i)\n if t>res:\n res = t\n print(res)\n\n\nmain()\n", "def fun(x,y):\r\n return (((x+y)*(x+1)*(y+1))//2)\r\nm,b=map(int,input().split())\r\ns=0\r\nfor i in range (0,b+1):\r\n if fun(b*m-i*m,i)>=s:\r\n s=fun(b*m-i*m,i)\r\nprint(s)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "def fun(number):\r\n return number * (number + 1) // 2\r\n\r\n\r\nm, b = [int(i) for i in input().split()]\r\ncount = 0\r\nfor j in range(b, -1, -1):\r\n x = m * (b - j)\r\n count = max(count, (x + 1) * fun(j) + (j + 1) * fun(x))\r\nprint(count)\r\n", "m,b = map(int,input().split())\r\n\r\nans = float(\"-inf\")\r\nfor i in range(0,b+1):\r\n\tx = (b-i)*m\r\n\tans = max(ans,(i+1)*int((x*(x+1))/2)+int((i*(i+1))/2)*(x+1))\r\nprint(ans)", "m, b = [int(x) for x in input().split()]\n\nbest = 0\n\nfor y in range(b + 1):\n x = (b - y) * m\n\n s = ((x + 1) * (y + 1) * (x + y)) // 2\n\n best = max(best, s)\n\nprint(best)\n", "import math\r\n\r\nm, bb = [int(item) for item in input().split()]\r\n\r\nans = -1\r\n\r\nfor a in range(bb + 1):\r\n b = m * bb - m * a\r\n ans = max(ans, (a * (a + 1) // 2) * (b + 1) + (b * (b + 1) // 2) * (a + 1))\r\n \r\nprint(ans)", "A=list(map(int,input().split()))\r\nm,b=A[0],A[1]\r\nmx=0\r\nfor y in range(b+1):\r\n x=(b-y)*m\r\n mx=max(mx,(x+1)*(y+1)*(x+y)//2)\r\nprint(mx)\r\n \r\n \r\n \r\n \r\n\r\n \r\n", "m,b = map(int, input().strip().split(' '))\r\nmaxi=((m*b)*(m*b+1))//2\r\nfor j in range(1,b):\r\n x=m*(b-j)\r\n p1=((x)*(x+1))//2\r\n p2=((j)*(j+1))//2\r\n p=p1*(j+1) + p2*(x+1)\r\n if p>maxi:\r\n maxi=p\r\nprint(maxi)\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\n#────────▓▓▓▓▓▓▓────────────▒▒▒▒▒▒\r\n#──────▓▓▒▒▒▒▒▒▒▓▓────────▒▒░░░░░░▒▒\r\n#────▓▓▒▒▒▒▒▒▒▒▒▒▒▓▓────▒▒░░░░░░░░░▒▒▒\r\n#───▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▒▒░░░░░░░░░░░░░░▒\r\n#──▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░▒\r\n#──▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░▒\r\n#─▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░░▒\r\n#▓▓▒▒▒▒▒▒░░░░░░░░░░░▒▒░░▒▒▒▒▒▒▒▒▒▒▒░░░░░░▒\r\n#▓▓▒▒▒▒▒▒▀▀▀▀▀███▄▄▒▒▒░░░▄▄▄██▀▀▀▀▀░░░░░░▒\r\n#▓▓▒▒▒▒▒▒▒▄▀████▀███▄▒░▄████▀████▄░░░░░░░▒\r\n#▓▓▒▒▒▒▒▒█──▀█████▀─▌▒░▐──▀█████▀─█░░░░░░▒\r\n#▓▓▒▒▒▒▒▒▒▀▄▄▄▄▄▄▄▄▀▒▒░░▀▄▄▄▄▄▄▄▄▀░░░░░░░▒\r\n#─▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░▒\r\n#──▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░▒\r\n#───▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀▀▀░░░░░░░░░░░░░░▒\r\n#────▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░▒▒\r\n#─────▓▓▒▒▒▒▒▒▒▒▒▒▄▄▄▄▄▄▄▄▄░░░░░░░░▒▒\r\n#──────▓▓▒▒▒▒▒▒▒▄▀▀▀▀▀▀▀▀▀▀▀▄░░░░░▒▒\r\n#───────▓▓▒▒▒▒▒▀▒▒▒▒▒▒░░░░░░░▀░░░▒▒\r\n#────────▓▓▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░▒▒\r\n#──────────▓▓▒▒▒▒▒▒▒▒▒░░░░░░░░▒▒\r\n#───────────▓▓▒▒▒▒▒▒▒▒░░░░░░░▒▒\r\n#─────────────▓▓▒▒▒▒▒▒░░░░░▒▒\r\n#───────────────▓▓▒▒▒▒░░░░▒▒\r\n#────────────────▓▓▒▒▒░░░▒▒\r\n#──────────────────▓▓▒░▒▒\r\n#───────────────────▓▒░▒\r\n#────────────────────▓▒\r\n \r\n \r\n \r\n \r\n \r\ndef run():\r\n print(\"YOusef\")\r\ndef run3():\r\n print(\"Abdalla\") \r\ndef run2():\r\n print(\"Attia\")\r\ndef kk():\r\n print(\"Sa7afy\") \r\n#code here\r\nsol=\"\"\"\" 1 2\r\ny=2\r\nwhile\r\nx=-1*0\r\nx=0\r\ny=3\r\n3\r\nx=-1*-1=1\r\nt=2*2=4\r\n4\r\nx=2\r\nt=3\r\nans=4\r\n\r\n\r\n\r\n\"\"\"\r\n\r\nm,b = map(int,input().split())\r\ny=b\r\nans=0\r\nwhile y>=0:\r\n x=(y-b)*-m\r\n total=(x+1)*(y*(y+1)//2)+(y+1)*(x*(x+1)//2)\r\n ans=max(ans,total)\r\n y-=1\r\nprint(ans) \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "m , b = map(int, (input().split(' ')))\r\n\r\nmaximo = -1 \r\nfor y in range(b+1):\r\n\tx = (y - b ) * (-m)\r\n\tmaximo = max(maximo , (x+1)*int((y*(y+1))/2) + (y+1)*int((x*(x+1))/2) )\r\n\r\nprint(maximo)\r\n", "def f(n):\r\n tmp = n*(n+1)//2\r\n return tmp\r\n\r\ndef solve(a,b):\r\n ans=0\r\n for i in range(b, -1, -1):\r\n c = a*(b-i)\r\n tmp = 0\r\n tmp += (c+1)*f(i)+(i+1)*f(c)\r\n ans=max(ans,tmp)\r\n return ans\r\n\r\na,b=map(int,input().split())\r\nprint(solve(a,b))\r\n \r\n", "import sys\n\ndef main(input):\n m, b = map(int, next(input).split())\n result = 0\n for h in range(0, b + 1):\n w = (b - h) * m\n result = max(result, (w + 1) * (h + 1) * (w + h) // 2)\n print(result)\n\nif __name__ == '__main__':\n main(iter(sys.stdin.readlines()))", "m, b = map(int, input().split())\r\nres = 0\r\nfor i in range(b + 1):\r\n res = max(res, (m * i * (m * i + 1) // 2) * (b - i + 1) + ((b - i) * (b - i + 1) // 2) * (m * i + 1))\r\nprint(res)", "m, b = map(int, input().split())\r\n\r\nmost = 0\r\n\r\nfor y in range(0, b):\r\n x = m * (b - y)\r\n cnt = 0\r\n\r\n p1 = (y) * (y+1) * (x+1) // 2\r\n p2 = (x) * (x+1) * (y+1) // 2\r\n\r\n cnt = p1 + p2\r\n\r\n most = max(most, cnt)\r\n\r\nprint(most)\r\n", "m,b=map(int,input().split())\r\nmaximum=0\r\nfor y in range(b+1):\r\n\tsum=(m*(b-y)+y)*(m*(b-y)+1)*(y+1)//2\r\n\tif maximum<=sum:\r\n\t\tmaximum=sum\r\n\telse:\r\n\t\tbreak;\r\nprint(maximum)\r\n", "m,b=input().split()\nm=int(m)\nb=int(b)\n\n#x_cept=m*b\n#y_cept=b\n\nmax=0\nfor y in range (b+1):\n\tx=m*(b-y)\n\tcost=((x+1)*(y+1)*(x+y))//2\n\t#print(f\"At y={y}, cost is {cost}\")\n\tif cost > max:\n\t\tmax=cost\n\telse:\n\t\tbreak\nprint(max)", "a,b=map(int,input().split())\r\nmx=0\r\nfor i in range(b-1,-1,-1):\r\n x=(b-i)*a\r\n y=int(i)\r\n sm = int(int(y*(y+1)/2)+int((y+2*x)*(y+1)/2))*(1+x)\r\n if sm % 2 == 0:\r\n sm//=2\r\n else:\r\n sm//=2\r\n sm+=1\r\n if mx < sm:\r\n mx = int(sm)\r\nprint(mx)\r\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nimport sys\n\n\ndef main():\n iterator = iter(sys.stdin.read().split())\n m, b = int(next(iterator)), int(next(iterator))\n res = 0\n for y in range(b + 1):\n x = m * b - m * y\n h = y * (y + 1) // 2\n tmp = (x + 1) * (h + h + x * (y + 1)) // 2\n res = max(res, tmp)\n print(res)\n\n\nif __name__ == '__main__':\n main()\n", "def ans(x,y):\n a=int(y*(y+1)/2)\n a=a*(x+1)\n b=int(x*(x+1)/2)\n b=b*(y+1)\n return a+b\n\ndef change(i,b):\n if i%b==0:\n return i/b\n return i/b+1\n\nm,b=map(int,input().split())\nmax=int(-1)\n\nfor i in range(0,b+1):\n x=m*(b-i)\n k=ans(i,x)\n if max<k:\n max=k\n\nprint(int(max))\n", "def fn(y,m,b):\r\n x=m*(b-y)\r\n ans=(x+1)*(y+1)*(x+y)\r\n return ans//2\r\nm,b=map(int,input().split())\r\nlo=0\r\nhi=b\r\nwhile lo<hi:\r\n mid=(lo+hi)//2\r\n if fn(mid,m,b)>fn(mid-1,m,b) and fn(mid+1,m,b)>fn(mid,m,b):\r\n lo=mid\r\n elif fn(mid,m,b)<fn(mid-1,m,b) and fn(mid+1,m,b)<fn(mid,m,b):\r\n hi=mid\r\n else:\r\n break\r\nprint(fn(mid,m,b))\r\n\r\n\r\n", "def col(currY, currX, m):\r\n y_vals = currY*(currY-1)//2\r\n total = y_vals*m\r\n\r\n x_vals = (currX+m+currX+1)*m//2\r\n total += x_vals*currY\r\n\r\n return total\r\n\r\ndef row(currY, currX):\r\n y_vals = currY*(currX+1)\r\n total = y_vals\r\n\r\n x_vals = (currX+1)*currX//2\r\n total += x_vals\r\n\r\n return total\r\n\r\nm,b = [int(val) for val in input().strip().split(' ')]\r\n\r\ninitX = b*m\r\n\r\nmax_v = curr_v = (initX+1)*initX//2\r\ncurr_y = 0\r\n\r\nfor curr_x in range(initX-m, -1, -m):\r\n curr_y +=1\r\n curr_v = curr_v - col(curr_y,curr_x, m) + row(curr_y,curr_x)\r\n if curr_v > max_v:\r\n max_v = curr_v\r\n else:\r\n print(max_v)\r\n break\r\n", "import math\r\nimport random\r\nimport sys\r\nimport collections\r\n\r\n\r\ndef In():\r\n return map(int, sys.stdin.readline().split())\r\n\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\n#\r\n# l = [1200,1300,1400,1500,1600,1700]\r\n# print(random.choice(l))\r\ndef okaBana():\r\n m, b = In()\r\n y = 0\r\n ans = 0\r\n while True:\r\n x = -(y * m - m * b)\r\n if x < 0:\r\n break\r\n ans = max(ans, x * (x + 1) // 2 * (y + 1) + y * (y + 1)//2 * (x+1 ))\r\n y += 1\r\n print(ans)\r\n\r\n\r\nokaBana()\r\n", "m,b=map(int,input().split())\r\nmax=0\r\nfor y in range(b+1):\r\n\tsum=(m*(b-y)+y)*(m*(b-y)+1)*(y+1)//2\r\n\tif max<=sum:\r\n\t\tmax=sum\r\n\telse:\r\n\t\tbreak;\r\nprint(max)", "def sumXY (x, y):\r\n Sn = (x+1)*y*(y+1)//2 + (y+1)*x*(x+1)//2\r\n return int(Sn)\r\n\r\nm, b = map(int, input().split())\r\nareas = []\r\nfor y in range(b + 1):\r\n x = -m * (y - b)\r\n areas.append(sumXY(x, y))\r\n#print(areas)\r\nprint(max(areas))\r\n\"\"\"\r\nwhile True:\r\n x, y = map(int, input().split())\r\n total = 0\r\n sums = list()\r\n for a in range(x + 1):\r\n curTotal = 0\r\n for b in range(y+1):\r\n total += a + b\r\n curTotal += a + b\r\n sums.append(curTotal)\r\n base = (y + 1) / 2 * (y)\r\n Sn = (x + 1) / 2 * (2 * (base) + x * (y+1))\r\n print(base, Sn)\r\n #print(sums)\r\n print(total)\r\n\"\"\"\r\n\"\"\"\r\n3 0\r\n3 1\r\n3 2\r\n3 3\r\n3 4\r\n3 5\r\n3 6\r\n\r\n4 5\r\n4 4\r\n7 6\r\n9 10\r\n35 46\r\n\"\"\"", "def check(x,y):\n\tf1 = x*(x+1)//2\n\tf2 = y*(y+1)//2\n\treturn (x+1)*f2 + (y+1)*f1\nif __name__ ==\"__main__\":\n\tm,b = map(int,input().split())\n\ty = b\n\tma = 0\n\tfor i in range(0,m*b+1,m):\n\t\tif check(i,y)>ma:\n\t\t\tma = check(i,y)\n\t\ty-=1\n\tprint(ma)\n\n", "from math import floor\r\nm,b = map(int,input().split())\r\nans = 0\r\nfor y in range(b):\r\n x = m*(b-y)\r\n ans = max(ans,(x*(x+1)*(y+1) + y*(y+1)*(x+1))//2)\r\nprint(ans)", "a,b=map(int,input().split())\r\nans=0\r\nr =lambda x:(x*(x+1))//2\r\nfor y in range(b+1):x=(b-y)*a;ans=max(ans,(x+1)*r(y)+(y+1)*r(x))\r\nprint(ans)", "m,b = map(int, input().split())\r\nmx = 0\r\nfor y in range(b, -1, -1):\r\n x = m * (b - y)\r\n mx = max(mx, (x + 1) * (y + 1) * (x + y) // 2)\r\nprint(mx)", "m,b=map(int,input().split())\r\nans=0\r\nfor x in range(0,m*b+1,m):\r\n y=b-x//m\r\n t=(x+y)*(x+1)*(y+1)//2\r\n ans=max(ans,t)\r\nprint(ans)", "import math\r\nimport queue\r\n\r\nm, b=map(int,input().split())\r\n\r\nanswer=0\r\n\r\nfor y in range(0,b+1):\r\n x=m*(b-y)\r\n temp=(x+1)*(y+1)*(x+y)//2\r\n if temp>answer:\r\n answer=temp\r\n\r\nprint(answer)\r\n ", "m,b=[int(i) for i in input().split()]\r\nmax1=0\r\nfor y in range(b,-1,-1):\r\n x= m*(b-y)\r\n calc= ((y+1)*(x+1)*(x+y))//2\r\n if (calc>max1):\r\n max1=calc\r\nprint (max1)\r\n", "from math import *\n\n\ndef sum(n):\n return (n * (n + 1)) // 2\n\n\nm, b = [int(x) for x in input().strip().split()]\nans = 0\nx = 0\ny = 0\nwhile True:\n if b < y:\n break\n x = m * (b - y)\n rans = sum(x) * (y + 1) + sum(y) * (x + 1)\n ans = max(ans, rans)\n y += 1\nprint(ans)\n", "m,b =[int(x) for x in input().split()]\r\ndef f(x):\r\n\treturn -1*(x/m)+b\r\n\t\r\nx=0\t\r\npoints=[]\r\nwhile f(x)>=0:\r\n\tif f(x)-int(f(x))==0:\r\n\t\tpoints.append([x,int(f(x))])\r\n\tx+=m\r\nbanana=0\r\nmaxB=0\r\nfor x,y in points:\r\n\tbanana=0\r\n\tbanana+=(y+1)*int((x*(x+1)*0.5))+(x+1)*int(y*(y+1)*0.5)\r\n\tmaxB = max(banana,maxB)\r\n\r\nprint(maxB)\r\n", "m , b = map(int , input().split(\" \"))\r\nans = 0\r\nfor y in range(b + 1 ):\r\n x = m*( b - y )\r\n temp = (x+y)*(x+1)*(y+1)//2\r\n ans = max(temp , ans)\r\nprint(ans)", "import math as mt \nimport sys,string\ninput=sys.stdin.readline\nimport random\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())\ndef x(s,e):\n return (e*(e+1))//2-(s*(s-1))//2\nm,b=M()\nw=(b-1)//2\nh=m*b-m*w\nans=0\nk=0\nfor i in range(m*b,-1,-m):\n h=i\n w=k\n p=h*(h+1)*(w+1)\n p//=2\n q=w*(w+1)*(h+1)\n q//=2\n ans=max(ans,p+q)\n k+=1\n\nprint(ans)\n", "read = lambda: map(int, input().split())\r\nm, b = read()\r\nans = -1\r\ndef f(x, y):\r\n return (x * (x + 1) * (y + 1) + y * (y + 1) * (x + 1)) // 2\r\nfor k in range(b + 3):\r\n x = k * m\r\n y = b - k\r\n ans = max(ans, f(x, y))\r\nprint(ans)", "import sys\r\ninput = sys.stdin.readline\r\n\r\nm, b = map(int, input().split())\r\nd = []\r\nfor i in range(b+1):\r\n d.append((i, (b-i)*m))\r\n\r\nc = 0\r\nfor i, j in d:\r\n y = j*(j+1)//2 * (i+1)\r\n x = i*(i+1)//2 * (j+1)\r\n c = max(c, x+y)\r\n\r\nprint(c)\r\n", "m,b = map(int,input().split())\r\nans=0\r\nfor y in range(b+1):\r\n x = (b-y)*m\r\n t = ((x+1)*(y+1)*(x+y))//2\r\n ans = max(ans,t)\r\nprint(ans)", "\r\n\r\ndef get(i, j):\r\n return (i + 1) * (j + 1) * (i + j) // 2\r\n\r\n \r\nm, b = map(int, input().split())\r\nres = -1\r\nfor y in range(b):\r\n x = (b - y) * m\r\n res = max(get(x, y), res)\r\nprint(res)", "m, b = map(int, input().split())\r\nans = 0\r\nfor y in range(b+1):\r\n x = (b - y) * m\r\n h = x * (x + 1)//2\r\n h1 = y * (y + 1)//2\r\n ans = max(h * (y+1) + h1 * (x+1), ans)\r\n \r\nprint(ans)\r\n", "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\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\nm,b = ilele()\r\n#y = b - x/m\r\nAns = 0\r\ndef fun(x,y):\r\n return ((y*(y+1))//2)*(x+1)\r\n\r\nfor y in range(b,-1,-1):\r\n x= m*(b - y)\r\n a= fun(x,y) + fun(y,x)\r\n Ans = max(Ans,a)\r\nprint(Ans)", "'''\r\n###### * User Profile : Keval_78\r\nLinkedIn: https://www.linkedin.com/in/kevalpadsala78/\r\nGithub: https://github.com/Keval78\r\nLeetcode: https://leetcode.com/Keval_78/\r\n'''\r\n\r\nimport sys\r\n# from os import path\r\nfrom math import log2, floor, ceil, sqrt, pow, gcd\r\n# from random import random, randint, shuffle, choice\r\n# from collections import Counter, defaultdict, deque\r\n# from itertools import permutations, combinations\r\n# from functools import reduce\r\n# from heapq import heapify, heappop, heappush, heapreplace\r\n# from bisect import bisect_left, bisect_right\r\n\r\n\r\ndef si(): return sys.stdin.readline().strip()\r\ndef ii(): return int(si())\r\ndef mi(ss=\" \"): return map(int, si().split(ss))\r\ndef msi(ss=\" \"): return map(str, si().split(ss))\r\ndef li(ss=\" \"): return list(mi(ss))\r\n\r\n\r\nsys.setrecursionlimit(10 ** 5)\r\nMOD, MOD2, INF = 10 ** 9 + 7, 998244353, float('inf')\r\nMAX = 10**5+1\r\n\r\n\r\nm, b = mi()\r\n\r\n# x_bananas = []\r\n# y_bananas = []\r\n# for i in range(0, m*b+1):\r\n# y_lim = floor(b - i/m)\r\n# ans = (y_lim*(y_lim+1))//2 + (y_lim+1)*i\r\n# x_bananas.append(ans)\r\n\r\n# for i in range(0, b+1):\r\n# x_lim = m*b-(b-i)*m\r\n# ans = (x_lim)*(x_lim+1)//2 + (x_lim+1)*(b-i)\r\n# y_bananas.append(ans)\r\n\r\n# print(x_bananas)\r\n# print(y_bananas)\r\n\r\nmax_totl, ans = 0, 0\r\nfor i in range(0, m*b+1):\r\n y_lim = floor(b - i/m)\r\n x_banana = (y_lim*(y_lim+1))//2 + (y_lim+1)*i\r\n # print(x_banana)\r\n ans += x_banana\r\n max_totl = max(max_totl, ans)\r\n if i % m == 0:\r\n x_lim = m*b-(b-i//m)*m\r\n y_banana = (x_lim)*(x_lim+1)//2 + (x_lim+1)*(b-i//m)\r\n # print(y_banana)\r\n ans -= y_banana\r\nprint(max_totl)\r\n", "m,b=map(int,input().split())\nbn=0\nfor i in range(b):\n bn=max(bn,(m*(b-i)*(m*(b-i)+1)//2)*(i+1)+i*(i+1)//2*(m*(b-i)+1))\nprint(bn)\n", "m, b = map(int, input().strip().split())\r\nans = 0\r\n\r\nfor y in range(b + 1):\r\n x = (-y + b) * m\r\n # print('x:', x, 'y:', y)\r\n res = (x + 1) * (y + 1) * (x + y) >> 1\r\n ans = max(ans, res)\r\nprint(ans)", "m, b = [int(x) for x in input().strip().split()]\nans = 0\nfor y in range(b + 1):\n x = m * (b - y)\n ans = max(ans, (x + 1) * (y + 1) * (x + y) // 2)\nprint(ans)\n", "def main():\n m,b=list(map(int,input().strip().split(' ')))\n mid1=int((m*b)/2)\n mid2=int((b)/2)\n\n\n\n def find(a,b):\n return ((a+b)*(a+1)*(b+1))//2\n\n MAX=1\n for y in range (0,b+1):\n\n if find((b-y)*m,y)>MAX:\n MAX=find((b-y)*m,y)\n print(MAX) \nmain()\n ", "m, b = map(int, input().split())\nprint(max((x + y) * (x + 1) * (y + 1) for y, x in enumerate(range(b * m, -m, -m))) // 2)", "m,b=map(int,input().split(\" \"))\r\nsm=0\r\nfor y in range(0,b+1):\r\n x=m*(b-y)\r\n s=(x+y)*(x+1)*(y+1)//2\r\n sm=max(s,sm)\r\nprint(sm)", "from math import *\nm,b=map(int,input().split())\nval1=m*b\nmaxval=0\nfor i in range(b,-1,-1):\n\tvalx=floor((b-i)*m)\n\tansx=((valx+1)*i*(i+1))//2\n\tansx+=(((i+1)*valx*(valx+1))//2)\n\tmaxval=max(maxval,ansx)\n\t#print(ansx)\nprint(maxval)\n\n", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nm, b = map(int, input().split())\r\nx = m * b\r\nans = 0\r\nfor y in range(b + 1):\r\n c1 = x * (x + 1) // 2 * (y + 1)\r\n c2 = y * (y + 1) // 2 * (x + 1)\r\n ans = max(ans, c1 + c2)\r\n x -= m\r\nprint(ans)" ]
{"inputs": ["1 5", "2 3", "4 6", "6 3", "1 1", "10 1", "20 10", "1000 10000", "139 9252", "859 8096", "987 4237", "411 3081", "539 9221", "259 770", "387 5422", "515 1563", "939 407", "518 6518", "646 1171", "70 7311", "494 6155", "918 7704", "46 3844", "174 2688", "894 4637", "22 3481", "446 5030", "440 8704", "569 7548", "289 6393", "417 1045", "841 7185", "969 6030", "393 4874", "817 3719", "945 2563", "369 4511", "555 3594"], "outputs": ["30", "25", "459", "171", "1", "55", "40326", "74133360011484445", "1137907933561080", "29032056230649780", "5495451829240878", "366755153481948", "16893595018603386", "2281741798549", "1771610559998400", "75233740231341", "4438222781916", "5511730799718825", "49802404050106", "142915220249910", "4221391613846823", "28569727339126165", "9007500020760", "43730657099581", "5909849585253250", "1548544125646", "1878390629993745", "9470470760118060", "10326205017481606", "1620061541812350", "14758909519725", "19452619774222875", "15265318959845745", "1327174123029975", "2546859449982016", "1115613396515835", "927715710215505", "1061060598862891"]}
UNKNOWN
PYTHON3
CODEFORCES
72
15e263e85246dfd3aa917ff242354b00
Alyona and Spreadsheet
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By *a**i*,<=*j* we will denote the integer located at the *i*-th row and the *j*-th column. We say that the table is sorted in non-decreasing order in the column *j* if *a**i*,<=*j*<=≤<=*a**i*<=+<=1,<=*j* for all *i* from 1 to *n*<=-<=1. Teacher gave Alyona *k* tasks. For each of the tasks two integers *l* and *r* are given and Alyona has to answer the following question: if one keeps the rows from *l* to *r* inclusive and deletes all others, will the table be sorted in non-decreasing order in at least one column? Formally, does there exist such *j* that *a**i*,<=*j*<=≤<=*a**i*<=+<=1,<=*j* for all *i* from *l* to *r*<=-<=1 inclusive. Alyona is too small to deal with this task and asks you to help! The first line of the input contains two positive integers *n* and *m* (1<=≤<=*n*·*m*<=≤<=100<=000) — the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table. Each of the following *n* lines contains *m* integers. The *j*-th integers in the *i* of these lines stands for *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=109). The next line of the input contains an integer *k* (1<=≤<=*k*<=≤<=100<=000) — the number of task that teacher gave to Alyona. The *i*-th of the next *k* lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). Print "Yes" to the *i*-th line of the output if the table consisting of rows from *l**i* to *r**i* inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No". Sample Input 5 4 1 2 3 5 3 1 3 2 4 5 2 3 5 5 3 2 4 4 3 4 6 1 1 2 5 4 5 3 5 1 3 1 5 Sample Output Yes No Yes Yes Yes No
[ "import sys \r\ninput = sys.stdin.readline\r\nn, m = map(int,input().split())\r\narr=[]\r\nfor i in range(n):\r\n arr.append(list(map(int,input().split())))\r\nmp = []\r\nfor i in range(n):\r\n mp.append(i+1)\r\nfor i in range(m):\r\n pre=-1\r\n st=0\r\n for j in range(n):\r\n if arr[j][i]<pre :\r\n pre=arr[j][i]\r\n st=j\r\n mp[j]=min(mp[j],st)\r\n else :\r\n mp[j]=min(mp[j],st)\r\n pre=arr[j][i]\r\nm=int(input())\r\nfor i in range(m):\r\n a,b=map(int,input().split())\r\n if mp[b-1]<=a-1 :\r\n print(\"Yes\")\r\n else :\r\n print(\"No\")\r\n\r\n\r\n", "import sys\r\ninput=lambda:sys.stdin.readline().strip()\r\n\r\nm, n = list(map(int, input().split()))\r\nmatrix = []\r\nfor _ in range(m):\r\n line = list(map(int, input().split()))\r\n matrix.append(line)\r\n\r\nup = [[0] * n for _ in range(m)]\r\nfor i in range(1, m):\r\n for j in range(n):\r\n if matrix[i-1][j] <= matrix[i][j]:\r\n up[i][j] = up[i-1][j]\r\n else:\r\n up[i][j] = i\r\n\r\nupper = [0] * m\r\nfor i in range(m):\r\n upper[i] = min(up[i])\r\n\r\nk = int(input())\r\nfor _ in range(k):\r\n left, right = list(map(int, input().split()))\r\n if left-1>=upper[right-1]:\r\n print('Yes')\r\n else:\r\n print('No')", "import sys\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# endregion fastio\r\n\r\n# MOD = 998_244_353\r\n# MOD = 10 ** 9 + 7\r\n# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL\r\n# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))\r\n\r\ndef solve() -> None:\r\n n, m = mint()\r\n g = []\r\n for _ in range(n):\r\n g.append(ints())\r\n \r\n up = list(range(n))\r\n dp = [1] * m\r\n for i in range(1, n):\r\n for j in range(m):\r\n if g[i][j] >= g[i - 1][j]:\r\n dp[j] += 1\r\n else:\r\n dp[j] = 1\r\n up[i] = min(up[i], i - dp[j] + 1)\r\n\r\n for _ in range(sint()):\r\n l, r = mint()\r\n print(\"Yes\" if up[r - 1] <= l - 1 else \"No\")\r\n\r\nsolve()", "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 u * m + v\r\n\r\nn, m = map(int, input().split())\r\na = []\r\nfor _ in range(n):\r\n a0 = list(map(int, input().split()))\r\n for i in a0:\r\n a.append(i)\r\nx = [i for i in range(1, n + 1)]\r\nfor j in range(m):\r\n u = n\r\n for i in range(n - 2, -1, -1):\r\n if not a[f(i, j)] <= a[f(i + 1, j)]:\r\n u = i + 1\r\n x[i] = max(x[i], u)\r\nx = [0] + x\r\nk = int(input())\r\nans = []\r\nfor _ in range(k):\r\n l, r = map(int, input().split())\r\n ans0 = \"Yes\" if x[l] >= r else \"No\"\r\n ans.append(ans0)\r\nsys.stdout.write(\"\\n\".join(ans))", "import sys\r\ninput = sys.stdin.readline\r\nm, n = map(int, input().split())\r\ngrid = [list(map(int, input().split())) for _ in range(m)]\r\ndp = [[0] * n for _ in range(m)]\r\nmx = [0] * m\r\nfor i in range(m - 2,-1,-1):\r\n for j in range(n):\r\n if grid[i][j] <= grid[i + 1][j]:\r\n dp[i][j] = dp[i + 1][j] + 1\r\n mx[i] = max(dp[i])\r\nq = int(input())\r\nfor _ in range(q):\r\n l,r = map(int, input().split())\r\n l -= 1\r\n r -= 1\r\n if mx[l] >= r - l:\r\n print(\"Yes\")\r\n else:\r\n print(\"No\")", "n,m = map(int,input().split())\r\nM = [list(map(int,input().split())) for i in range(n)]\r\ndepth = [[1]*m for i in range(n)]\r\nfor col in range(m):\r\n for row in range(1,n):\r\n if M[row][col]>=M[row-1][col]:\r\n depth[row][col] = depth[row-1][col]+1 \r\nmax_depth = [max(row) for row in depth]\r\nans = \"\"\r\nk = int(input())\r\nfor i in range(k):\r\n l,r = map(int,input().split())\r\n if max_depth[r-1] >= r-l+1:\r\n ans+=\"Yes\\n\"\r\n else:\r\n ans+=\"No\\n\"\r\nprint(ans)", "import sys\nn,m = map(int,sys.stdin.readline().rstrip().split())\nmatrix = []\nfor _ in range(n):\n\trow = list(map(int,sys.stdin.readline().rstrip().split()))\n\tmatrix.append(row)\n\n# initialize table\nA = [[1 for _ in range(m)] for _ in range(n)]\nfor i in range(n-2,-1,-1):\n\tfor j in range(m):\n\t\tif matrix[i][j] <= matrix[i+1][j]:\n\t\t\tA[i][j] = A[i+1][j] + 1\n\n# rows = [0] * n\n# for i in range(n):\n# \tlst = [A[i][j] for j in range(m)]\n# \trows[i] = max(lst)\nrows = [max(row) for row in A]\n\nans = \"\"\nk = int(sys.stdin.readline().rstrip())\nfor _ in range(k):\n\tl,r = map(int,sys.stdin.readline().rstrip().split())\n\tif rows[l-1] >= (r - l + 1):\n\t\tans += \"Yes\\n\"\n\telse:\n\t\tans += \"No\\n\"\nsys.stdout.write(ans)\n", "import sys\r\n\r\ndef debug(x, table):\r\n for name, val in table.items():\r\n if x is val:\r\n print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)\r\n return None\r\n\r\ndef solve():\r\n n, m = map(int, sys.stdin.readline().split())\r\n A = [[int(i) for i in sys.stdin.readline().split()] for j in range(n)]\r\n q = int(sys.stdin.readline().rstrip())\r\n querys = [tuple(map(int, sys.stdin.readline().split())) for i in range(q)]\r\n\r\n f = [i for i in range(n)]\r\n\r\n for j in range(m):\r\n s = 0\r\n for i in range(n):\r\n if i == n - 1 or A[i][j] > A[i + 1][j]:\r\n for k in range(s, i + 1):\r\n f[k] = max(f[k], i)\r\n s = i + 1\r\n\r\n ans = []\r\n\r\n for l, r in querys:\r\n if r-1 <= f[l-1]:\r\n ans.append('Yes')\r\n else:\r\n ans.append('No')\r\n\r\n print(*ans, sep='\\n')\r\n\r\nif __name__ == '__main__':\r\n solve()", "import sys, collections\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 solve():\r\n n, m = invr()\r\n myList = []\r\n for i in range(n):\r\n myList.append(inlt())\r\n k = inp()\r\n \r\n minIndex = [1 for i in range(m)]\r\n \r\n rows = [0, 1]\r\n \r\n for i in range(1, n):\r\n for j in range(m):\r\n if myList[i][j] < myList[i-1][j]:\r\n minIndex[j] = i+1\r\n rows.append(min(minIndex))\r\n \r\n \r\n for i in range(k):\r\n l, r = invr()\r\n if rows[r] <= l: print(\"Yes\")\r\n else: print(\"No\")\r\n \r\n \r\nsolve()", "\r\n#------------------------template--------------------------#\r\nimport os\r\nimport sys\r\nfrom math import *\r\nfrom io import BytesIO, IOBase\r\ndef vsInput():\r\n sys.stdin = open('input.txt', 'r')\r\n sys.stdout = open('output.txt', 'w')\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\ndef value():\r\n return map(int,input().split())\r\ndef array():\r\n return [int(i) for i in input().split()]\r\n\r\n#-------------------------code---------------------------#\r\n#vsInput()\r\n\r\ndef check(a):\r\n ansy=0\r\n ansx=0\r\n ans=[]\r\n for i in range(1,len(a)):\r\n if(a[i]>=a[i-1]):\r\n ansy+=1\r\n else:\r\n ans.append((ansx,ansy))\r\n ansx,ansy=i,i\r\n if(len(ans)==0 or ans[-1]!=(ansx,ansy)): \r\n ans.append((ansx,ansy)) \r\n return ans\r\n\r\n\r\nm,n=value()\r\nmat=[]\r\nfor i in range(m):\r\n mat.append(array())\r\ncol=[]\r\nlst=[]\r\nfor i in range(n):\r\n col.append([])\r\n for j in range(m):\r\n col[-1].append(mat[j][i])\r\n lst.append(check(col[-1]))\r\n#print(lst)\r\nans={}\r\nfor i in lst:\r\n for j in i:\r\n try:\r\n ans[j[0]]=max(ans[j[0]],j[1])\r\n except:\r\n ans[j[0]]=j[1]\r\ntemp=list(ans.keys())\r\nfor i in temp:\r\n #print(i)\r\n for j in range(i,ans[i]+1):\r\n try:\r\n ans[j]=max(ans[i],ans[j])\r\n except:\r\n ans[j]=ans[i]\r\n#print(ans)\r\n \r\n \r\nk=int(input())\r\nfor i in range(k):\r\n l,r=value()\r\n l-=1\r\n r-=1\r\n f=0\r\n \"\"\"for v in ans:\r\n if(l>=v[0] and r<=v[1]):\r\n f=1\r\n print(\"Yes\")\r\n break\r\n if(f==0):\r\n print(\"No\")\"\"\"\r\n if(r<=ans[l]):\r\n print(\"Yes\")\r\n else:\r\n print(\"No\")", "import sys\r\ninput=sys.stdin.readline\r\nn,m=map(int,input().split())\r\na=[list(map(int,input().split())) for i in range(n)]\r\nv=[[1]*m for i in range(n)]\r\nfor j in range(m):\r\n for i in range(n-1)[::-1]:\r\n if a[i][j]<=a[i+1][j]:\r\n v[i][j]=v[i+1][j]+1\r\nmax_l=[max(arr) for arr in v]\r\nq=int(input())\r\nfor _ in range(q):\r\n l,r=map(int,input().split())\r\n if max_l[l-1]>=r-l+1:\r\n print(\"Yes\")\r\n else:\r\n print(\"No\")", "import sys\r\ninput=sys.stdin.readline\r\nn,m=map(int,input().split())\r\nM=[[] for i in range(m)]\r\nfor i in range(n):\r\n z=list(map(int,input().split()))\r\n for i in range(len(z)):\r\n M[i].append(z[i])\r\n\r\ndp=[0 for i in range(n)]\r\ndp[-1]=1\r\nfor i in range(len(M)):\r\n \r\n x=M[i]\r\n temp=[0 for i in range(len(x))]\r\n temp[0]=1\r\n for i in range(1,len(x)):\r\n if(x[i]>=x[i-1]):\r\n temp[i]=1\r\n else:\r\n temp[i]=2\r\n re=[0 for i in range(len(temp))]\r\n re[-1]=1\r\n for i in range(len(re)-2,-1,-1):\r\n if(temp[i+1]==2):\r\n re[i]=1\r\n else:\r\n re[i]=re[i+1]+1\r\n for i in range(len(dp)):\r\n dp[i]=max(dp[i],re[i])\r\n\r\nr=int(input())\r\ndp[-1]=1\r\n\r\nfor i in range(r):\r\n l,r=map(int,input().split())\r\n \r\n if(dp[l-1]>=r-l+1):\r\n print('Yes')\r\n else:\r\n print('No')\r\n \r\n\r\n\r\n \r\n \r\n \r\n \r\n", "from sys import stdin, stdout\r\n\r\nn, m = map(int, stdin.readline().split())\r\n\r\nvalues = []\r\nfor i in range(n):\r\n values.append(list(map(int, stdin.readline().split())))\r\n\r\nd = {}\r\nquestions = []\r\nk = int(stdin.readline())\r\n\r\nfor i in range(k):\r\n l, r = map(int, stdin.readline().split())\r\n questions.append((l, r))\r\n \r\n\r\nfor j in range(m):\r\n l, r = 0, 0\r\n while r < n:\r\n if l == r:\r\n if r in d:\r\n d[r] = min(d[r], l)\r\n else:\r\n d[r] = l\r\n r += 1\r\n elif values[r][j] >= values[r - 1][j]:\r\n if r in d:\r\n d[r] = min(d[r], l)\r\n else:\r\n d[r] = l\r\n r += 1\r\n else:\r\n l = r\r\n\r\n\r\nfor l, r in questions:\r\n l -= 1\r\n r -= 1\r\n if r in d and d[r] <= l:\r\n stdout.write('Yes\\n')\r\n else:\r\n stdout.write('No\\n')", "\"\"\"\r\nhttps://codeforces.com/problemset/problem/777/C\r\n\r\n输入 n m(1≤n*m≤1e5) 和 n 行 m 列的矩阵 a,元素范围 [1,1e9]。\r\n然后输入 k(1≤k≤1e5) 和 k 个询问,每个询问输入两个数 L R(1≤L≤R≤n)。\r\n对于每个询问,请判断在第 L 行到第 R 行中,是否存在一列,元素值从上到下是递增的(允许相等),输出 Yes 或 No。\r\n\r\n进阶:把询问范围缩小至子矩形,即第 L 行到第 R 行并且只考虑第 p 列到第 q 列。\r\n\"\"\"\r\nfrom math import inf\r\n\r\n\r\ndef MII():\r\n return map(int, input().split())\r\ndef II():\r\n return int(input())\r\ndef I():\r\n return input()\r\n\r\nn, m = MII()\r\nres = [[] for _ in range(n)]\r\nfor i in range(n):\r\n res[i] = list(MII())\r\n\r\nans = [0] * n # 表示每行对应非递减的最小起点\r\nrow = [0] * m\r\nfor i in range(1, n):\r\n for j in range(m):\r\n if res[i-1][j] <= res[i][j]:\r\n continue\r\n else:\r\n row[j] = i\r\n ans[i] = min(row)\r\n\r\nk = II()\r\nfor _ in range(k):\r\n l, r = MII()\r\n l -= 1\r\n r -= 1\r\n flag = \"Yes\" if ans[r] <= l else \"No\"\r\n print(flag)", "import sys\ninput = sys.stdin.readline\nn,m = map(int,input().split())\na = []\nfor i in range(n):\n\ta.append(list(map(int,input().split())))\ncount = [[1 for i in range(m)] for j in range(n)]\nfor i in range(1,n):\n\tfor j in range(m):\n\t\tif a[i][j]>=a[i-1][j]:\n\t\t\tcount[i][j] = count[i-1][j]+1\nmaxx = []\nfor i in range(n):\n\tmaxx.append(max(count[i]))\nfor i in range(int(input())):\n\tl,r = map(int,input().split())\n\tif l==r:\n\t\tprint (\"Yes\")\n\t\tcontinue\n\tif maxx[r-1]>=r-l+1:\n\t\tprint (\"Yes\")\n\telse:\n\t\tprint (\"No\")", "import sys\r\nrr=sys.stdin.readline\r\nn,m=map(int,rr().split())\r\ntable=[]\r\nfor _ in range(n):\r\n table.append(list(map(int,rr().split())))\r\ndepth=[[1]*m for _ in range(n)]\r\nfor c in range(m):\r\n for r in range(1,n):\r\n if table[r][c]>=table[r-1][c]:\r\n depth[r][c]=depth[r-1][c]+1\r\nmax_depth=[max(row) for row in depth]\r\n\r\nfor _ in range(int(rr())):\r\n l,r=map(int,rr().split())\r\n if l==r:\r\n print(\"Yes\")\r\n else:\r\n if max_depth[r-1]>=r-l+1:\r\n print(\"Yes\")\r\n else:\r\n print(\"No\")", " ###### ### ####### ####### ## # ##### ### ##### \r\n # # # # # # # # # # # # # ### \r\n # # # # # # # # # # # # # ### \r\n ###### ######### # # # # # # ######### # \r\n ###### ######### # # # # # # ######### # \r\n # # # # # # # # # # #### # # # \r\n # # # # # # # ## # # # # # \r\n ###### # # ####### ####### # # ##### # # # # \r\n \r\nfrom __future__ import print_function # for PyPy2\r\n# from itertools import permutations\r\n# from functools import cmp_to_key # for adding custom comparator\r\n# from fractions import Fraction\r\nfrom collections import *\r\nfrom sys import stdin\r\n# from bisect import *\r\nfrom heapq import *\r\nfrom math import *\r\n \r\ng = lambda : stdin.readline().strip()\r\ngl = lambda : g().split()\r\ngil = lambda : [int(var) for var in gl()]\r\ngfl = lambda : [float(var) for var in gl()]\r\ngcl = lambda : list(g())\r\ngbs = lambda : [int(var) for var in g()]\r\nrr = lambda x : reversed(range(x)) \r\nmod = int(1e9)+7\r\ninf = float(\"inf\")\r\n\r\nn, m = gil()\r\nmat = [gil() for _ in range(n)]\r\np = set()\r\n\r\nfor j in range(m):\r\n l, r = 0, 0\r\n while r+1 < n :\r\n if mat[r+1][j] < mat[r][j]:\r\n if l != r:p.add((l+1, r+1))\r\n l = r+1\r\n r += 1\r\n\r\n if l != r:p.add((l+1, r+1))\r\n\r\np = list(p)\r\n\r\np.sort(reverse=True)\r\n\r\nendMax = [i for i in range(n+1)]\r\nh = []\r\nfor start in range(1, n+1):\r\n while p and p[-1][0] == start:\r\n heappush(h, -p.pop()[1])\r\n\r\n while h and -h[0] <= start:\r\n heappop(h)\r\n\r\n if h :\r\n endMax[start] = -h[0]\r\n\r\n\r\nans = []\r\n\r\nfor _ in range(gil()[0]):\r\n l, r = gil()\r\n ans.append('Yes' if endMax[l] >= r else 'No')\r\n\r\nprint('\\n'.join(ans))", "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\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\n\r\nn,m = ilele()\r\nA = []\r\nfor i in range(n):\r\n B = alele()\r\n A.append(B)\r\ndp = [[1 for j in range(m)] for i in range(n) ]\r\nfor i in range(1,n):\r\n for j in range(m):\r\n if A[i][j] >= A[i-1][j]:\r\n dp[i][j] = dp[i-1][j] + 1\r\ndepth =[0]\r\nfor i in dp:\r\n depth.append(max(i))\r\nfor _ in range(int(input())):\r\n l,r = ilele()\r\n if l==r:\r\n Yy(1)\r\n else:\r\n Yy(depth[r] >= r-l+1)\r\n \r\n", "import sys\r\nRI = lambda: map(int, sys.stdin.buffer.readline().split())\r\n\r\nn, m = RI()\r\na = []\r\nfor _ in range(n):\r\n a.append(list(RI()))\r\n\r\nk = int(list(RI())[0])\r\nquery = []\r\nfor _ in range(k):\r\n query.append(list(RI()))\r\n\r\ndp = [[1] * m for _ in range(n)]\r\nf = [1] * n\r\n\r\nfor i in range(1, n):\r\n for j in range(m):\r\n if a[i][j] >= a[i - 1][j]:\r\n dp[i][j] = dp[i - 1][j] + 1\r\n f[i] = max(f[i], dp[i][j])\r\n\r\nfor x, y in query:\r\n x -= 1\r\n y -= 1\r\n if x >= y - (f[y] - 1):\r\n print('Yes')\r\n else:\r\n print('No')", "import sys\r\nfrom bisect import bisect_left, bisect_right\r\nfrom collections import Counter, defaultdict, deque\r\nfrom heapq import heapify, heappop, heappush\r\nfrom itertools import accumulate, groupby\r\nfrom math import ceil, comb, floor, gcd, inf, lcm, log2, prod, sqrt\r\nfrom string import ascii_lowercase\r\n\r\nMOD = 10**9 + 7\r\n\r\n\r\n# 2023-11-01 21:06:35\r\ndef main():\r\n n, m = read_ints()\r\n a = [list(read_ints()) for _ in range(n)]\r\n\r\n k = int(input())\r\n q = [tuple(read_ints()) for _ in range(k)]\r\n\r\n row = [1] * n\r\n\r\n for j in range(m):\r\n dp = [1] * n\r\n for i in range(1, n):\r\n if a[i][j] >= a[i - 1][j]:\r\n dp[i] = dp[i - 1] + 1\r\n row[i] = max(row[i], dp[i])\r\n\r\n # print(row)\r\n for l, r in q:\r\n if row[r - 1] >= r - l + 1:\r\n print(\"Yes\")\r\n else:\r\n print(\"No\")\r\n\r\n\r\ndef input():\r\n return sys.stdin.readline().strip()\r\n\r\n\r\ndef read_ints():\r\n return map(int, input().split())\r\n\r\n\r\nif __name__ == \"__main__\":\r\n # t = int(input())\r\n t = 1\r\n for _ in range(t):\r\n main()\r\n" ]
{"inputs": ["5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5", "1 1\n1\n1\n1 1", "10 1\n523130301\n127101624\n15573616\n703140639\n628818570\n957494759\n161270109\n386865653\n67832626\n53360557\n17\n4 5\n4 7\n8 8\n9 9\n3 9\n8 10\n8 9\n7 9\n4 5\n2 9\n4 6\n2 4\n2 6\n4 6\n7 9\n2 4\n8 10", "15 1\n556231456\n573340933\n626155933\n397229387\n10255952\n376567394\n906742013\n269437009\n31298788\n712285290\n620239975\n379221898\n229140718\n95080095\n997123854\n18\n5 15\n1 12\n4 10\n2 15\n12 15\n15 15\n2 2\n15 15\n15 15\n13 13\n10 14\n3 6\n14 15\n3 6\n4 4\n14 15\n12 14\n1 9", "11 1\n501465490\n366941771\n415080944\n385243536\n445132523\n697044413\n894369800\n812743722\n23684788\n466526046\n953916313\n45\n2 4\n8 9\n7 7\n4 9\n2 9\n2 11\n4 4\n5 7\n1 2\n5 10\n4 6\n1 7\n4 4\n1 6\n4 7\n10 11\n1 8\n6 11\n8 8\n8 10\n1 1\n5 10\n9 10\n6 9\n6 11\n1 1\n9 9\n5 11\n1 2\n9 11\n2 6\n3 7\n11 11\n6 7\n11 11\n7 8\n5 8\n11 11\n5 6\n4 5\n2 6\n5 10\n9 9\n1 1\n1 1"], "outputs": ["Yes\nNo\nYes\nYes\nYes\nNo", "Yes", "No\nNo\nYes\nYes\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo\nNo", "No\nNo\nNo\nNo\nNo\nYes\nYes\nYes\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nYes\nNo\nNo", "No\nNo\nYes\nNo\nNo\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nYes\nNo\nYes\nNo\nNo\nYes\nYes\nNo\nNo\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nNo\nNo\nYes\nYes\nYes"]}
UNKNOWN
PYTHON3
CODEFORCES
20
15f8e73bc9b0d7eb1a626278b62f9905
Bathroom terminal
Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is connected to the terminal next to him. After pressing a Play button a rough voice starts playing from the tape: "Listen up Smith. As you can see, you are in pretty tough situation and in order to escape, you have to solve a puzzle. You are given *N* strings which represent words. Each word is of the maximum length *L* and consists of characters 'a'-'e'. You are also given *M* strings which represent patterns. Pattern is a string of length <=≤<= *L* and consists of characters 'a'-'e' as well as the maximum 3 characters '?'. Character '?' is an unknown character, meaning it can be equal to any character 'a'-'e', or even an empty character. For each pattern find the number of words that matches with the given pattern. After solving it and typing the result in the terminal, the key will drop from the ceiling and you may escape. Let the game begin." Help Smith escape. The first line of input contains two integers *N* and *M* (1<=≤<=*N*<=≤<= 100 000, 1<=≤<=*M*<=≤<= 5000), representing the number of words and patterns respectively. The next *N* lines represent each word, and after those *N* lines, following *M* lines represent each pattern. Each word and each pattern has a maximum length *L* (1<=≤<=*L*<=≤<=50). Each pattern has no more that three characters '?'. All other characters in words and patters are lowercase English letters from 'a' to 'e'. Output contains *M* lines and each line consists of one integer, representing the number of words that match the corresponding pattern. Sample Input 3 1 abc aec ac a?c Sample Output 3
[ "import sys\r\nfrom itertools import product\r\nfrom collections import defaultdict\r\nr=sys.stdin.readline\r\nN,M=map(int,r().split())\r\nwords=defaultdict(int)\r\ntb=['a','b','c','d','e']\r\nst=set()\r\ncnt=0\r\nres=\"\"\r\ndef dfs(u):\r\n global res,cnt\r\n if u==l:\r\n if res in st:\r\n return\r\n if words[res]>0: cnt+=words[res]\r\n st.add(res)\r\n return\r\n if pattern[u]=='?':\r\n for i in range(6):\r\n if i!=5:res+=tb[i]\r\n dfs(u+1)\r\n if i!=5:res=res[:-1]\r\n else:\r\n res+=pattern[u]\r\n dfs(u+1)\r\n res=res[:-1]\r\nfor _ in range(N):\r\n word=r().strip()\r\n words[word]+=1\r\nfor _ in range(M):\r\n cnt=0\r\n st.clear()\r\n pattern=r().strip()\r\n l=len(pattern)\r\n res=\"\"\r\n dfs(0)\r\n print(cnt)\r\n" ]
{"inputs": ["3 1\nabc\naec\nac\na?c", "22 2\naaaab\naaabb\naabab\naabbb\nabaab\nababb\nabbab\nabbbb\naaab\naabb\nabab\nabbb\naab\nabb\nab\ncccd\nccdd\ncdcd\ncddd\nccd\ncdd\ncd\na???b\nc??d", "15 6\naaa\naaabbb\naaabb\naaaaa\naaaaaa\naaaa\naaabbbb\naaaaa\naaaaaa\naaaa\naaabbbb\naabbbb\naa\naa\naab\na\n?a?\n??\n?aa?bb?\n?aa?aa?\n??aaa?"], "outputs": ["3", "15\n7", "0\n4\n2\n5\n6\n7"]}
UNKNOWN
PYTHON3
CODEFORCES
1
160baf248c6c33b69df49066de5ff338
Inna and Alarm Clock
Inna loves sleeping very much, so she needs *n* alarm clocks in total to wake up. Let's suppose that Inna's room is a 100<=×<=100 square with the lower left corner at point (0,<=0) and with the upper right corner at point (100,<=100). Then the alarm clocks are points with integer coordinates in this square. The morning has come. All *n* alarm clocks in Inna's room are ringing, so Inna wants to turn them off. For that Inna has come up with an amusing game: - First Inna chooses a type of segments that she will use throughout the game. The segments can be either vertical or horizontal. - Then Inna makes multiple moves. In a single move, Inna can paint a segment of any length on the plane, she chooses its type at the beginning of the game (either vertical or horizontal), then all alarm clocks that are on this segment switch off. The game ends when all the alarm clocks are switched off. Inna is very sleepy, so she wants to get through the alarm clocks as soon as possible. Help her, find the minimum number of moves in the game that she needs to turn off all the alarm clocks! The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of the alarm clocks. The next *n* lines describe the clocks: the *i*-th line contains two integers *x**i*, *y**i* — the coordinates of the *i*-th alarm clock (0<=≤<=*x**i*,<=*y**i*<=≤<=100). Note that a single point in the room can contain any number of alarm clocks and the alarm clocks can lie on the sides of the square that represents the room. In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally. Sample Input 4 0 0 0 1 0 2 1 0 4 0 0 0 1 1 0 1 1 4 1 1 1 2 2 3 3 3 Sample Output 2 2 3
[ "n = int(input())\r\nx = []\r\ny = []\r\nfor i in range(n):\r\n xt, yt = list(map(int, input().split()))\r\n x.append(xt)\r\n y.append(yt)\r\nx = list(set(x))\r\ny = list(set(y))\r\n\r\nprint(min(len(x), len(y)))\r\n", "h=set()\r\nv=set()\r\nfor i in range(int(input())):\r\n\tk = input().split()\r\n\tv.add(k[0])\r\n\th.add(k[1])\r\nprint(min(len(v),len(h)))\r\n", "n = int(input())\r\nx = [0]*n; y = [0]*n\r\nfor i in range(n):\r\n x[i], y[i] = map(int, input().split())\r\n\r\na = len(set(x))\r\nb = len(set(y))\r\n\r\nprint(min(a,b))\r\n", "n = int(input())\nxset = set()\nyset = set()\nl = list(tuple(map(int, input().split())) for _ in range(n))\nfor a in l:\n xset.add(a[0])\n yset.add(a[1])\nprint(min(len(xset), len(yset)))\n", "x = set()\ny = set()\nfor i in range(int(input())):\n xi,yi = [int(i) for i in input().split()]\n x.add(xi)\n y.add(yi)\nprint(min(len(x),len(y)))\n", "def inna_and_alarm_clock(n: int, points: list) -> int:\n ver, hor = set(), set()\n\n for x, y in points:\n ver.add(x)\n hor.add(y)\n\n return min(len(ver), len(hor))\n\n\nif __name__ == \"__main__\":\n n = int(input())\n points = [tuple(int(s) for s in input().split()) for _ in range(n)]\n\n ans = inna_and_alarm_clock(n, points)\n print(ans)\n", "a = set()\r\nb = set()\r\nclock = int(input())\r\nfor i in range(clock):\r\n c,d = map(int,input().split())\r\n a.add(c)\r\n b.add(d)\r\nprint(min(len(a),len(b)))\r\n", "n=int(input())\r\nx=[]\r\ny=[]\r\nfor i in range(n):\r\n xi,yi=list(map(int,input().split()))\r\n x.append(xi)\r\n y.append(yi)\r\n\r\nx=set(x)\r\ny=set(y)\r\n\r\nprint (min(len(x),len(y)))", "#! /usr/bin/python\r\n\r\ndef sol():\r\n n = int(input())\r\n x = {}\r\n y = {}\r\n for i in range(n):\r\n x_i, y_i = map(int, input().split())\r\n x[x_i] = True\r\n y[y_i] = True\r\n\r\n print(min(len(x.keys()), len(y.keys())))\r\n\r\nsol()", "n = int(input())\r\n\r\nx = [0 for m in range(101)]\r\ny = [0 for n in range(101)]\r\nfor i in range(n):\r\n xi,yi = map(int,input().split())\r\n x[xi] = 1\r\n y[yi] = 1\r\n\r\n\r\n\r\nprint(min(x.count(1),y.count(1)))\r\n", "n=int(input())\r\nc=[]\r\nd=[]\r\nfor i in range(n):\r\n a, b = [int(x) for x in input().split()]\r\n c.append(a)\r\n d.append(b)\r\n\r\n\r\n\r\nprint(min(len(set(c)),len(set(d))))", "xs = set()\nys = set()\n\nfor _ in range(int(input())):\n x, y = input().split()\n xs.add(x)\n ys.add(y)\n\nprint(min(len(xs), len(ys)))", "n = int(input())\r\nx = []\r\ny = []\r\nfor i in range(n):\r\n t = list(map(int, input().split(\" \")))\r\n x.append(t[0])\r\n y.append(t[1])\r\nxs = list(set(x))\r\nys = list(set(y))\r\nprint(min(len(xs), len(ys)))", "s = int(input())\ny_list = []\nx_list = []\ninput_list = []\nfor i in range(s):\n input_list += [int(x) for x in input().split(\" \")]\n\nfor i in range(len(input_list)):\n if i % 2 == 0:\n x_list += [input_list[i]]\n else:\n y_list += [input_list[i]]\nprint(min(len(set(x_list)),len(set(y_list))))\n", "n = int(input())\r\nx = []\r\ny = []\r\n\r\nfor i in range(n):\r\n x_i,y_i = (map(int,input().split()))\r\n x.append(x_i)\r\n y.append(y_i)\r\nprint(min(len(set(x)),len(set(y))))", "no_of_alarms = int(input())\r\n\r\nx_set = set()\r\ny_set = set()\r\nwhile no_of_alarms > 0:\r\n i_alarm = input().split( )\r\n\r\n x_set.add(int(i_alarm[0]))\r\n y_set.add(int(i_alarm[1]))\r\n\r\n no_of_alarms = no_of_alarms - 1\r\n\r\nif len(x_set) <= len(y_set):\r\n print(len(x_set))\r\nelse:\r\n print(len(y_set))", "#import math\r\nn = int(input())\r\n#n, m = input().split()\r\n#n = int (n)\r\n#m = int (m)\r\n#n, m, k= input().split()\r\n#n = int (n)\r\n#m = int (m)\r\n#k = int (k)\r\n#l = int(l)\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#a = 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\nx = set()\r\ny = set()\r\nfor i in range(n):\r\n a, b = input().split()\r\n a = int (a)\r\n b = int (b)\r\n x.add(a)\r\n y.add(b)\r\n \r\nprint(min(len(x),len(y)))\r\n", "n = int(input())\r\n\r\nx = []\r\ny = []\r\nfor i in range(n):\r\n xi,yi = map(int,input().split())\r\n x.append(xi)\r\n y.append(yi)\r\n\r\nx = list(set(x))\r\ny = list(set(y))\r\n\r\nprint(min(len(x),len(y)))", "n=int(input())\r\nhor=[]\r\nver=[]\r\nfor i in range(n):\r\n s=input().split()\r\n hor.append(s[1])\r\n ver.append(s[0])\r\nprint(min(len(set(hor)),len(set(ver))))", "n = int(input())\r\nl1 = [0] * 105\r\nl2 = [0] * 105\r\nx = 0\r\ny = 0\r\nfor i in range(n):\r\n ln = input().split()\r\n l = [int(ln[i]) for i in range(len(ln))]\r\n if not l1[l[0]]:\r\n l1[l[0]] = 1\r\n x += 1\r\n if not l2[l[1]]:\r\n l2[l[1]] = 1\r\n y += 1\r\nprint(min(x, y))", "from sys import stdin, stdout\r\na = [0]*101\r\nb = [0]*101\r\nn = int(stdin.readline())\r\nfor i in range(n):\r\n x, y = list(map(int, stdin.readline().split()))\r\n if a[x] == 0:\r\n a[x] = 1\r\n if b[y] == 0:\r\n b[y] = 1\r\nstdout.write(str(min(sum(a), sum(b))))\r\n", "n=int(input())\r\nv=[]\r\nh=[]\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n if x not in h :\r\n h.append(x)\r\n if y not in v: \r\n v.append(y)\r\nprint(min(len(v),len(h))) \r\n", "\n\ndef fun(x):\n d1= set() \n d2= set()\n while x:\n y=list(map(int, input().split()))\n d1.add(y[0])\n d2.add(y[1])\n x-=1\n return (min(len(d1),len(d2)))\nx=int(input())\nprint(fun(x))", "a= int(input())\r\nb=[]\r\nc=[]\r\nfor i in range(a):\r\n x,y = map(int,input().split())\r\n b.append(x)\r\n c.append(y)\r\nprint(min(len(set(b)),len(set(c))))", "n=int(input())\r\nx=[0]*n\r\ny=[0]*n\r\nfor t in range(n):\r\n (x[t],y[t])=[int(x) for x in input().split()]\r\nx=list(set(x))\r\ny=list(set(y))\r\nprint(min(len(x),len(y)))\r\n", "numOfAlarms = int(input())\ncolumns = set()\nrows = set()\nfor i in range(numOfAlarms):\n x = input()\n columns.add(x.split(' ')[0])\n rows.add(x.split(' ')[1])\n\n\nif len(columns) < len(rows):\n print(len(columns))\nelif len(rows) <= len(columns):\n print(len(rows))\n", "n=int(input())\r\nv,h=set(),set()\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n v.add(x)\r\n h.add(y)\r\nprint(min(len(v),len(h)))", "def unique(list1): \r\n unique_list = [] \r\n count=0\r\n for x in list1: \r\n if x not in unique_list: \r\n unique_list.append(x) \r\n count+=1\r\n return count\r\nn=int(input())\r\nlx=[]\r\nly=[]\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n lx.append(x)\r\n ly.append(y)\r\nx=unique(lx)\r\ny=unique(ly)\r\nprint(min(x,y))\r\n ", "n=int(input())\r\nq,w=set(),set()\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n q.add(a)\r\n w.add(b)\r\nprint(min(len(q),len(w)))\r\n", "n = int(input())\r\nx = [0 for i in range(101)]\r\ny = [0 for i in range(101)]\r\nx_num = 0\r\ny_num = 0\r\nfor k in range(n):\r\n i, j = [int(s) for s in input().split()]\r\n if x[i] == 0:\r\n x_num += 1\r\n x[i] = 1\r\n if y[j] == 0:\r\n y_num += 1\r\n y[j] += 1\r\nif y_num > x_num:\r\n print(\"%d\\n\" % x_num)\r\nelse:\r\n print(\"%d\\n\" % y_num)\r\n", "t = int(input())\r\n\r\nv = set()\r\nh = set()\r\n\r\narr = []\r\nfor i in range(t):\r\n arr.append(list(map(int,input().split())))\r\n \r\nfor i in arr:\r\n h.add(i[1])\r\n \r\nfor i in arr:\r\n v.add(i[0])\r\n \r\nprint(min(len(h),len(v)))\r\n \r\n", "n = int(input())\n\nxx, yy = set(), set()\n\nfor i in range(n):\n x, y = map(int, input().split())\n xx.add(x)\n yy.add(y)\n\nprint(min(len(xx), len(yy)))\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\na=list(set(a))\r\nb=list(set(b))\r\nprint(min(len(a),len(b)))", "n = int(input())\ncoordinetes = []\nxset = set()\nyset = set()\n\ni = 1\n\nwhile i <= n:\n x, y = input().split(' ')\n coordinetes.append({\n 'x': int(x),\n 'y': int(y)\n })\n i += 1\n\nfor coordinete in coordinetes:\n xset.add(coordinete['x'])\n yset.add(coordinete['y'])\n\nif len(xset) < len(yset):\n min = len(xset)\nelse:\n min = len(yset)\n\nprint(min)", "d={}\r\nd1={}\r\nq=int(input())\r\nfor _ in range(q):\r\n b=[]\r\n for a in input().split():\r\n b.append(int(a))\r\n try:\r\n d[b[0]]+=1\r\n except KeyError:\r\n d[b[0]]=1\r\n try:\r\n d1[b[1]]+=1\r\n except KeyError:\r\n d1[b[1]]=1\r\nprint(min(len(d.keys()), len(d1.keys())))", "n = int(input())\nx = [0 for i in range(101)]\ny = [0 for i in range(101)]\n\nfor i in range(n):\n a, b = map(int, input().split())\n x[a]+=1\n y[b]+=1\n\nxdif = 0\nydif = 0\nfor i in range(101):\n if x[i] != 0:\n xdif+=1\n if y[i] != 0:\n ydif+=1\n\nprint(min(xdif, ydif))\n", "n = int(input())\r\nx = []\r\ny = []\r\nfinal = 0\r\nfor _ in range(n):\r\n inp = input().split()\r\n \r\n if inp[0] not in x:\r\n x.append(inp[0])\r\n\r\n if inp[1] not in y:\r\n y.append(inp[1])\r\n\r\nif len(y) >= len(x):\r\n print(len(x))\r\nelse:\r\n print(len(y))", "def minMoves(x, y):\r\n return min(sum(x), sum(y))\r\n\r\nMAX = 101\r\nn = int(input())\r\nx = [0] * MAX\r\ny = [0] * MAX\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n x[a] = 1\r\n y[b] = 1\r\nprint(minMoves(x, y))", "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\nX = set(X)\r\nY = set(Y)\r\nprint(min(len(X),len(Y)))", "n = int(input())\r\nx,y =[],[]\r\nfor i in range(n):\r\n m,n = map(int,input().split())\r\n x.append(m)\r\n y.append(n)\r\n\r\nif len(set(x)) > len(set(y)):\r\n print(len(set(y)))\r\n \r\nif len(set(x)) < len(set(y)):\r\n print(len(set(x)))\r\n \r\nif len(set(x)) == len(set(y)):\r\n print(len(set(y)))", "a = set()\r\nb = set()\r\nfor _ in range(int(input())):\r\n x , y = map(int , input().split())\r\n a.add(x)\r\n b.add(y)\r\nprint(min(len(a) , len(b)))\r\n", "I=input\r\na=set()\r\nb=set()\r\nfor _ in '0'*int(I()):x,y=I().split();a.add(x);b.add(y)\r\nprint(min(len(a),len(b)))", "n=int(input())\r\ncnt1=0\r\ncnt2=0\r\nd1={}\r\nd2={}\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n if x not in d1:\r\n d1[x]=1\r\n cnt1+=1\r\n if y not in d2:\r\n cnt2+=1\r\n d2[y]=1\r\nprint(min(cnt1,cnt2))\r\n", "# print(max(0 , minimum))\r\n\r\nn = int(input())\r\n\r\nx , y = set() , set()\r\nfor i in range(n):\r\n input_ = input().split()\r\n x.add(input_[0])\r\n y.add(input_[1])\r\n\r\nprint(min(len(x) , len(y)))", "relojes = int(input())\r\nx = []\r\ny = []\r\nfor i in range(relojes):\r\n ubicacion = list(map(int, (input().split())))\r\n if ubicacion[1] not in x:\r\n x += [ubicacion[1]]\r\n if ubicacion[0] not in y:\r\n y += [ubicacion[0]]\r\nprint(min(len(x), len(y)))", "d1={}\r\nd2={}\r\nn=int(input())\r\nl=[]\r\nfor i in range(n):\r\n x=list(map(int,input().split()))\r\n l.append(x)\r\nfor i in range(n):\r\n if(l[i][0] not in d1):\r\n d1[l[i][0]]=1\r\nsum1=sum(d1.values())\r\nfor i in range(n):\r\n if(l[i][1] not in d2):\r\n d2[l[i][1]]=1\r\nsum2=sum(d2.values())\r\nprint(sum1) if(sum1<=sum2) else print(sum2)\r\n", "from itertools import islice, count\ncounter = int(input())\nhorizontal = set()\nvertical = set()\nfor x in islice(count(1), counter):\n x, y = input().split()\n horizontal.add(x)\n vertical.add(y)\nif len(horizontal) < len(vertical):\n print(len(horizontal))\nelse:\n print(len(vertical))\n", "\"\"\"def count_moves(amount_alarms, move_type):\r\n move = 1\r\n turn_off_alarms = 0\r\n if move_type == 'horizontal':\r\n for i in range(99, -1, -1):\r\n for j in range(100):\r\n if field[i][j] == 'x':\r\n turn_off_alarms += 1\r\n if turn_off_alarms == amount_alarms:\r\n return move\r\n move += 1\r\n return move - 1\r\n else:\r\n for j in range(100):\r\n for i in range(99, -1, -1):\r\n if field[i][j] == 'x':\r\n turn_off_alarms += 1\r\n if turn_off_alarms == amount_alarms:\r\n return move\r\n move += 1\r\n return move - 1\r\n\r\n\r\ndef print_field(field):\r\n for i in range(len(field)):\r\n print(*field[i])\r\n\"\"\"\r\n\r\namount_alarms = int(input())\r\n# field = [['0' for i in range(100)] for j in range(100)]\r\nsetx = set()\r\nsety = set()\r\nfor _ in range(amount_alarms):\r\n x, y = map(int, input().split())\r\n setx.add(x)\r\n sety.add(y)\r\nprint(min(len(setx), len(sety)))\r\n\r\n\r\n", "ac = int(input())\r\nx = set()\r\ny = set()\r\nif ac>0 and ac<100001:\r\n for i in range(ac):\r\n a, b = map(int, input().split(' '))\r\n if a>=0 and a<=100 and b>=0 and b<=100:\r\n x.add(a)\r\n y.add(b)\r\n if len(x)<len(y):\r\n print(len(x))\r\n else:\r\n print(len(y))", "'''\r\n\tCodeForces 309A\r\n\tInna and Alarm Clock\r\n\r\n\tTags: Counting\r\n'''\r\nn = int(input())\r\n\r\nalert = [ tuple(input().split()) for i in range(n) ]\r\nans = min(map(lambda x: len(set(x)), zip(*alert)))\r\n\r\nprint(ans)", "n = int(input())\n\nsame_hor = same_ver = 0\n\nhors = []\n\nvers = []\n\nfor _ in range(n):\n\tcoords = input()\n\tx = int(coords.split(\" \")[0])\n\ty = int(coords.split(\" \")[1])\n\tif x in hors: \n\t\tsame_hor += 1\n\telse:\n\t\thors.append(x)\n\tif y in vers:\n\t\tsame_ver += 1\n\telse:\n\t\tvers.append(y)\n\nif same_hor > same_ver:\n\tprint(len(hors))\nelse:\n\tprint(len(vers))\n\t\n", "n = int(input())\ns = []\nfor _ in range(n):\n s.append([int(i) for i in input().split()])\nq = set()\nw = set()\nfor i,j in s:\n q.add(i)\n w.add(j)\nprint(min(len(q),len(w)))\n", "n = int(input())\r\nx_cord = []\r\ny_cord = []\r\nfor i in range(n):\r\n e = input().split()\r\n x_cord.append(e[0])\r\n y_cord.append(e[1])\r\n\r\nset_x = set(x_cord)\r\nset_y = set(y_cord)\r\n\r\nif len(set_x) < len(set_y):\r\n print(len(set_x))\r\nelse:\r\n print(len(set_y))\r\n \r\n", "from collections import defaultdict\nlx = defaultdict(list)\nly = defaultdict(list)\n\nl = list()\nfor i in range(int(input())):\n l.append(input())\n\nfor x in l:\n a = x.split()\n lx[a[0]].append(a[1])\n ly[a[1]].append(a[0])\n\nprint(min(len(lx), len(ly)))\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Feb 4 15:56:33 2020\r\n\r\n@author: DeLL\r\n\"\"\"\r\n\r\nn=int(input())\r\nL1=set()\r\nL2=set()\r\nfor i in range(n):\r\n x,y=[int(x) for x in input().split()]\r\n L1.add(x)\r\n L2.add(y)\r\nprint(min(len(L1),len(L2)))", "def main():\n\tn = int(input())\n\tx = []\n\ty = []\n\tfor _ in range(n):\n\t\t_input = list(map(int, input().split()))\n\t\tx.append(_input[0])\n\t\ty.append(_input[1])\n\tprint(min(len(set(x)), len(set(y))))\n\nif __name__ == '__main__':\n\tmain()", "n = int(input())\r\nset_x = set()\r\nset_y = set()\r\nfor i in range(n):\r\n\ts = input().split()\r\n\tset_x.add(int(s[0]))\r\n\tset_y.add(int(s[1]))\r\n\r\nprint(min(len(set_x),len(set_y)))", "n=int(input())\r\nset1 = set() \r\nset2 = set() \r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n set1.add(x)\r\n set2.add(y)\r\np=min(len(set1),len(set2))\r\nprint(p)\r\n ", "def horizontal(array):\r\n answer = set()\r\n for i in range(len(array)):\r\n answer.add(array[i][1])\r\n return len(answer)\r\n\r\n\r\ndef vertical(array):\r\n answer = set()\r\n for i in range(len(array)):\r\n answer.add(array[i][0])\r\n return len(answer)\r\n\r\n\r\nnum_clock = int(input())\r\ncoordinates = []\r\nfor i in range(num_clock):\r\n coordinates.append([int(i) for i in input().split()])\r\nprint(min(horizontal(coordinates), vertical(coordinates)))", "n=int(input())\r\na=[]\r\nfor i in range(n):\r\n xy=list(map(int,input().split()))\r\n a.append(xy)\r\nv=[]\r\nh=[]\r\nfor i in a:\r\n if i[0] not in v:\r\n v.append(i[0])\r\n if i[1] not in h :\r\n h.append(i[1])\r\nprint(min(len(v),len(h)))", "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nimport decimal\r\ninput=sys.stdin.readline\r\nn=int(input())\r\ns1=set()\r\ns2=set()\r\nfor i in range(n):\r\n a,b=(int(i) for i in input().split())\r\n s1.add(a)\r\n s2.add(b)\r\nprint(min(len(s1),len(s2)))", "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(len(set(a)),len(set(b))))", "# _______ ________ ________ ________ ________\r\n# | | | | | | | | | | |\r\n# | | | | | | | | | | |\r\n# | | |_______| |________| | |________ |________ |________|\r\n# | | | |\\__ | | | |\\__\r\n# | | | | \\__ | | | | \\__\r\n# |________| | | \\__ | ________| |________ | \\__\r\n\r\nn=int(input())\r\nhor=[]\r\nver=[]\r\nfor i in range(n):\r\n s=input().split()\r\n hor.append(s[1])\r\n ver.append(s[0])\r\nprint(min(len(set(hor)),len(set(ver))))", "v = set()\r\ng = set()\r\nfor i in range(int(input())):\r\n a,b = input().split()\r\n v.add(a)\r\n g.add(b)\r\nprint(min(len(v),len(g)))", "n = int(input())\r\n\r\nmemo_x = {}\r\nmemo_y = {}\r\n\r\nfor i in range(n):\r\n x, y = list(map(int, input().split()))\r\n if x in memo_x:\r\n memo_x[x] += 1\r\n else:\r\n memo_x[x] = 1\r\n if y in memo_y:\r\n memo_y[y] += 1\r\n else:\r\n memo_y[y] = 1\r\nprint(min(len(memo_x), len(memo_y)))", "hor, ver = set(), set()\r\n\r\nfor i in range(int(input())):\r\n x, y = map(int, input().split())\r\n hor.add(y)\r\n ver.add(x)\r\n\r\nprint(min(len(hor), len(ver)))\r\n", "# Design_by_JOKER\r\nimport math\r\nimport cmath\r\n\r\nn = int(input())\r\na = set()\r\nb = set()\r\n\r\nfor _ in range(n):\r\n u, v = map(int, input().split())\r\n a.add(u)\r\n b.add(v)\r\n\r\nprint(min(len(a), len(b)))", "n = int(input())\r\nrow = set()\r\ncol = set()\r\nfor _ in range(n):\r\n a,b = list(map(int, input().split()))\r\n row.add(a)\r\n col.add(b)\r\nprint(min(len(row),len(col)))", "n = int(input())\r\nx = []\r\ny = []\r\nfor i in range(n):\r\n p, q = map(int, input().split())\r\n x.append(p)\r\n y.append(q)\r\nprint(min(len(list(set(x))),len(list(set(y)))))", "n = int(input())\r\nsetx, sety = set(), set()\r\nfor i in range(n):\r\n x,y = map(int,input().split())\r\n setx.add(x)\r\n sety.add(y)\r\nprint(min(len(setx),len(sety)))", "q = int(input())\r\nset1 = set()\r\nset2 = set()\r\nfor i in range(q):\r\n a, b = map(int, input().split())\r\n set1.add(a)\r\n set2.add(b)\r\nprint(min(len(set1), len(set2)))", "q = int(input())\r\nar = []\r\nfor _ in range(q):\r\n s = input()\r\n ar.append(s.split(' '))\r\nk = 0\r\nver = {}\r\nhor = {}\r\nfor i in ar:\r\n if i[0] not in hor:\r\n hor[i[0]] = 1\r\n if i[1] not in ver:\r\n ver[i[1]] = 1\r\nprint(min(len(hor), len(ver)))", "from math import *\r\n\r\nn = int(input())\r\na = set()\r\nb = set()\r\nfor i in range(n):\r\n x,y = map(int,input().split())\r\n a.add(x)\r\n b.add(y)\r\nprint(min(len(a),len(b)))", "X=[]\r\nY=[]\r\nfor _ in range(int(input())):\r\n x,y=map(int,input().split())\r\n if x not in X:\r\n X.append(x)\r\n if y not in Y:\r\n Y.append(y)\r\nprint(min(len(X),len(Y)))", "xd = []\r\nyd = []\r\nfor _ in range(int(input())):\r\n x, y = map(int, input().split())\r\n xd.append(x)\r\n yd.append(y)\r\nprint(min(len(set(xd)), len(set(yd))))\r\n", "n = int(input())\r\nuseX = [False]*101\r\nuseY = [False]*101\r\ncntX = 0\r\ncntY = 0\r\nfor i in range(n):\r\n (x,y) = input().split(\" \")\r\n x = int(x)\r\n y = int(y)\r\n cntX += 0 if useX[x] else 1\r\n cntY += 0 if useY[y] else 1\r\n useX[x] = True\r\n useY[y] = True\r\n\r\nprint(cntX if cntX < cntY else cntY )\r\n", "n = int(input())\r\nx = [0] * 101\r\ny = [0] * 101\r\nfor _ in range(n):\r\n i, j = map(int, input().split())\r\n x[i] = 1\r\n y[j] = 1\r\nprint(min(sum(x), sum(y)))", "n = int(input())\n\nvert = set()\nhor = set()\n\nfor _ in range(n):\n x, y = map(int, input().split())\n vert.add(x)\n hor.add(y)\n\nprint(min(len(vert), len(hor)))\n", "def solve(alarms):\r\n x_set = set()\r\n y_set = set()\r\n for x, y in alarms:\r\n assert 0 <= x <= 100\r\n assert 0 <= y <= 100\r\n x_set.add(x)\r\n y_set.add(y)\r\n return min(len(x_set), len(y_set))\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n alarms = list()\r\n for _ in range(n):\r\n x, y = list(map(int, input().split()))\r\n alarms.append((x, y))\r\n print(solve(alarms))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n=int(input())\r\nxcor=[]\r\nycor=[]\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n xcor.append(x)\r\n ycor.append(y)\r\na=len(set(xcor))\r\nb=len(set(ycor))\r\nprint(min(a,b)) \r\n", "x = set([])\r\ny = set([])\r\nfor i in range(0,int(input())):\r\n coord = input().split(' ')\r\n x.add(list(coord)[0])\r\n y.add(list(coord)[1])\r\nprint(min(len(set(x)),len(set(y))))", "from collections import Counter\r\nk = int(input())\r\nsetx, sety = set(), set()\r\nfor i in range(k):\r\n x, y = list(map(int, input().split()))\r\n setx.add(x)\r\n sety.add(y)\r\nprint(min(len(setx), len(sety)))\r\n", "n = int(input())\r\nx = {}\r\ny = {}\r\nfor i in range(n):\r\n z = [int(i) for i in input().split()]\r\n if z[0] in x:\r\n x[z[0]]+=1\r\n else:\r\n x[z[0]]=1\r\n if z[1] in y:\r\n y[z[1]]+=1\r\n else:\r\n y[z[1]]=1\r\nif len(x)>len(y):\r\n print(len(y))\r\nelse:\r\n print(len(x))\r\n", "n = int(input())\n\nX = set()\nY = set()\nfor i in range(n):\n x, y = map(int, input().split())\n X.add(x)\n Y.add(y)\n\nprint(min(len(X), len(Y)))\n", "import collections\nn = int(input())\n\nx = []\ny = []\n\nfor i in range(n):\n newx, newy, = map(int, input().strip().split())\n x.append(newx)\n y.append(newy)\n\nprint(min(len(set(x)), len(set(y))))\n", "n=int(input())\r\na=[]\r\nb=[]\r\nfor i in range(n):\r\n x = list(map(int, input().split(\" \")))\r\n a.append(x[0])\r\n b.append(x[1])\r\nprint(min(len(set(a)),len(set(b))))\r\n", "n = int(input())\r\n\r\nL = [input().split() for i in range(n)]\r\nX = set()\r\nY = set()\r\n\r\nfor coord in L:\r\n\tX.add(coord[0])\r\n\tY.add(coord[1])\r\n\r\nprint(min(len(X), len(Y)))", "a, b = [0] * 101, [0] * 101\r\nfor i in range(int(input())):\r\n x, y = map(int, input().split())\r\n a[x] = b[y] = 1\r\nprint(min(sum(a), sum(b)))", "n = int(input())\r\nseta = set()\r\nsety = set()\r\nwhile(n):\r\n n-=1\r\n x, y = map(int,input().split())\r\n seta.add(x)\r\n sety.add(y)\r\nprint(min(len(seta),len(sety)))", "n = int(input())\r\nhorizontal = set()\r\nvertical = set()\r\nfor i in range(n):\r\n line = tuple(map(int, input().split()))[:]\r\n horizontal.add(line[0])\r\n vertical.add(line[1])\r\nprint(min(len(vertical), len(horizontal)))", "i=lambda:map(int,input().split())\r\nn,=i()\r\na1,a2=set(),set()\r\nfor _ in range(n):x,y=i();a1.add(x);a2.add(y)\r\nprint(min(len(a1),len(a2)))", "n = int(input())\r\ndpx, dpy = set(), set()\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n dpx.add(x)\r\n dpy.add(y)\r\nprint(min(len(dpx), len(dpy)))", "n = int(input())\r\nx, y = [], []\r\nfor _ in range(n):\r\n a, b = map(int, input().split())\r\n if a not in x:\r\n x.append(a)\r\n if b not in y:\r\n y.append(b)\r\nprint(min(len(x), len(y)))\r\n", "\n\nn = int(input())\nhashrows= {}\nhashcolumns = {}\nfor i in range(n):\n\n a,b = map(int,input().split())\n if a not in hashrows.keys() :\n hashrows[a] = [[a,b]]\n else:\n hashrows[a].append([a,b])\n if b not in hashcolumns.keys() :\n hashcolumns[b] = [[a,b]]\n else:\n hashcolumns[b].append([a,b])\n\n\nprint(min(len(hashrows),len(hashcolumns)))\n\n", "n = int(input())\r\na = []\r\nb = []\r\nfor _ in range(n):\r\n u, v = map(int, input().split())\r\n a.append(u)\r\n b.append(v)\r\nprint(min(len(set(a)), len(set(b))))", "n = int(input())\nx = set()\ny = set()\nfor _ in range(n):\n a = list(map(int, input().rstrip().split()))\n x.add(a[0])\n y.add(a[1])\nprint(min(len(x), len(y)))\n", "a, b = [0] * 105, [0] * 105\r\nn = int(input())\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n a[x] = b[y] = 1\r\nprint(min(sum(a), sum(b)))\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\nl1=set(l1)\r\nl2=set(l2)\r\nprint(min(len(l1),len(l2)))\r\n", "n=int(input())\r\ndr={}\r\ndc={}\r\nfor i in range(n):\r\n li=[int(x) for x in input().split()]\r\n x,y=li[0],li[1]\r\n if(x in dr):\r\n dr[x]+=1\r\n else:\r\n dr[x]=1\r\n if(y in dc):\r\n dc[y]+=1\r\n else:\r\n dc[y]=1\r\nprint(min(len(dr),len(dc))) ", "num=int(input())\r\nhor=[]\r\nver=[]\r\nfor i in range(num):\r\n inp=list(map(int,input().split()))\r\n hor.extend([inp[0]])\r\n ver.extend([inp[1]])\r\nseth=set(hor)\r\nsetv=set(ver)\r\nprint(min(len(seth),len(setv)))\r\n", "x = set([])\r\ny = set([])\r\nfor i in range(int(input())):\r\n coordinates = input().split(' ')\r\n x.add(list(coordinates)[0])\r\n y.add(list(coordinates)[1])\r\nprint(min(len(set(x)), len(set(y))))\r\n", "def function():\n pass\n\n\ndef main():\n n = int(input())\n xset = set()\n yset = set()\n for i in range(n):\n x, y = map(int, input().strip().split())\n xset.add(x)\n yset.add(y)\n print(min(len(xset), len(yset)))\n\n\nif __name__ == '__main__':\n main()\n", "class CodeforcesTask390ASolution:\n def __init__(self):\n self.result = ''\n self.n = 0\n self.rings = []\n\n def read_input(self):\n self.n = int(input())\n for x in range(self.n):\n self.rings.append([int(y) for y in input().split(\" \")])\n\n def process_task(self):\n ys = [x[0] for x in self.rings]\n xs = [x[1] for x in self.rings]\n self.result = str(min(len(set(ys)), len(set(xs))))\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask390ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n", "\ndef do():\n n = int(input())\n xs = set()\n ys = set()\n for _ in range(n):\n x,y = map(int, input().split(\" \"))\n xs.add(x)\n ys.add(y)\n return min(len(xs), len(ys))\n\n\nprint(do())\n", "n = int(input())\r\na = [list(map(int, input().split())) for i in range(n)]\r\nx = list(set([i[0] for i in a]))\r\ny = list(set([i[1] for i in a]))\r\nprint(min(len(x), len(y)))", "# This is a sample Python script.\r\n\r\n# Press Shift+F10 to execute it or replace it with your code.\r\n# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.\r\n\r\n\r\n\r\n\r\n\r\n# Press the green button in the gutter to run the script.\r\nif __name__ == '__main__':\r\n numAlarmClocks = int(input())\r\n xDict = {}\r\n yDict = {}\r\n for i in range(numAlarmClocks):\r\n xPos, yPos = input().split(\" \")\r\n if xPos in xDict:\r\n xDict[xPos] += 1\r\n else:\r\n xDict[xPos] = 1\r\n if yPos in yDict:\r\n yDict[yPos] += 1\r\n else:\r\n yDict[yPos] = 1\r\n\r\n print(min(len(xDict), len(yDict)))\r\n\r\n# See PyCharm help at https://www.jetbrains.com/help/pycharm/\r\n", "clocks=int(input())\ncrds=[]\nj,k=set(),set()\nfor i in range(clocks):\n aa = [int(a) for a in input().split()]\n crds.append(aa)\nfor i in crds:\n j.add(i[0])\n k.add(i[1])\nprint(min(len(j),len(k)))", "n = int(input())\r\nM = [input().split() for i in range(n)]\r\nrow = []\r\ncol = []\r\nfor i in range(n):\r\n # for j in range(2):\r\n row.append(M[i][0])\r\n col.append(M[i][1])\r\nx = len(set(row))\r\ny = len(set(col))\r\nprint(min(x, y))", "a1 = []\r\nb1 = []\r\nk3 = 0\r\nk4 = 0\r\nn = int(input())\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n a1 += [a]\r\n b1 += [b]\r\n \r\nfor i in range(101):\r\n if i in a1:\r\n k3 += 1\r\n if i in b1:\r\n k4 += 1\r\nprint(min(k3, k4))", "n=int(input())\r\nd1={}\r\nd2={}\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n if x not in d1:\r\n d1[x]=1\r\n if y not in d2:\r\n d2[y]=1\r\nprint(min(len(d1),len(d2)))", "n = int(input())\r\ncountx = county = 0\r\narrx = []\r\narry = []\r\nx = y = 0\r\nfor i in range (0, n):\r\n x, y = map(int, input().split(\" \"))\r\n if x not in arrx:\r\n countx += 1\r\n arrx.append(x)\r\n if y not in arry:\r\n county += 1\r\n arry.append(y)\r\nprint(min(countx, county))", "def main():\n n = int(input())\n r = set()\n c = set()\n for i in range(n):\n (x, y) = map(int, input().split(' '))\n r.add(y)\n c.add(x)\n return min(len(r), len(c))\n\nprint(main())\n", "n = int(input())\r\n\r\nclocks = []\r\nlengths_vertical = [0]*101\r\nlengths_horizontal = [0]*101\r\n\r\nfor i in range(n):\r\n x, y = input().split()\r\n x, y = int(x), int(y)\r\n lengths_horizontal[x] += 1\r\n lengths_vertical[y] += 1\r\n\r\nmax_clocks_horizontal = sum([1 if x >0 else 0 for x in lengths_horizontal])\r\nmax_clocks_vertical = sum([1 if x >0 else 0 for x in lengths_vertical])\r\n\r\nprint(min(max_clocks_horizontal, max_clocks_vertical))\r\n\r\n\r\n", "from sys import stdin\r\n\r\nall_in = stdin.readlines()\r\n\r\nn = int(all_in[0])\r\ndots = list(map(lambda x: tuple(map(int, x.split())), all_in[1:]))\r\n\r\nx = set()\r\ny = set()\r\n\r\nfor x_, y_ in dots:\r\n x.add(x_)\r\n y.add(y_)\r\n\r\nprint(min(len(x), len(y)))\r\n", "n,x,y=int(input()),set(),set()\r\nfor _ in range(n):\r\n\ta,b=map(int,input().split())\r\n\tx.add(a)\r\n\ty.add(b)\r\nprint(min(len(x),len(y)))", "a = int(input().strip())\r\nv = set()\r\nh = set()\r\nfor i in range(a):\r\n cnt = [int(x) for x in input().strip().split(' ')]\r\n v.add(cnt[0])\r\n h.add(cnt[1])\r\nprint(min(len(v), len(h)))", "def solve():\n \n r=set()\n c=set()\n for i in arr :\n r.add(i[0])\n c.add(i[1])\n return min(len(r),len(c))\n\n\n\n\n \n\n\n\n\n\n \nfrom sys import stdin\ninput = stdin.readline \n \n \n\nn=int(input())\narr=[]\nfor i in range(n):\n arr.append([int(x) for x in input().split()])\nprint(solve())\n\n\n\n'''\n\nfor _ in range(int(input())) :\n n=int(input())\n print(solve())\n\n\nn=int(input())\n\nx=input().strip()\n\n\nn,m= [int(x) for x in input().split()]\n\n\n\n\nn=int(input())\narr=[int(x) for x in input().split()]\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\nn,m= [int(x) for x in input().split()]\narr=[]\nfor i in range(n):\n arr.append([x for x in input().strip()])\n\n\nn=int(input())\narr=[]\nfor i in range(n):\n arr.append([int(x) for x in input().split()])\n\n\n'''", "n = int(input())\r\nx= []\r\ny = []\r\nfor i in range(n):\r\n x1, y1 = map(int, input().split())\r\n x.append(x1)\r\n y.append(y1)\r\nx = list(dict.fromkeys(x))\r\ny = list(dict.fromkeys(y))\r\nprint(min(len(x), len(y)))\r\n", "hor_l = set()\r\nver_l = set()\r\nfor _ in range(int(input())):\r\n (x, y) = [int(i) for i in input().split(' ')]\r\n hor_l.add(x)\r\n ver_l.add(y)\r\nl = len(hor_l)\r\nif len(ver_l) < l:\r\n l = len(ver_l)\r\nprint(l)\r\n\r\n", "s=set()\r\np=set()\r\nfor _ in range(int(input())):\r\n x,y=map(int,input().split())\r\n s.add(x)\r\n p.add(y)\r\nprint(min(len(s),len(p)))", "# https://codeforces.com/problemset/problem/390/A/\r\n\r\ndef main():\r\n n = int(input())\r\n v = []\r\n h = []\r\n for i in range(n):\r\n a,b = map(int,input().split())\r\n v.append(a)\r\n h.append(b)\r\n lv = len(set(v))\r\n lh = len(set(h))\r\n res = lv if lv < lh else lh\r\n print(res)\r\n\r\nif __name__ == '__main__':\r\n #while 1:\r\n main()", "n = int(input())\r\nxcr= []\r\nycr = []\r\nfor i in range(n):\r\n x,y = map(int, input(). strip(). split())\r\n xcr.append(x)\r\n ycr.append(y)\r\nprint(min(len(set(xcr)),len(set(ycr))))", "n=int(input())\nx=[]\ny=[]\nfor i in range(n):\n a,b=input().split()\n x.append(a)\n y.append(b)\nprint(min(len(set(x)),len(set(y))))", "numOfAlarms = int(input())\ncolumns = set()\nrows = set()\nfor i in range(numOfAlarms):\n x = input().split(' ')\n columns.add(x[0])\n rows.add(x[1])\n\nprint(min(len(columns), len(rows)))", "n=int(input())\r\nx=set()\r\ny=set()\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n x.add(a)\r\n y.add(b)\r\nprint(min(len(x),len(y)))", "lv=[0]*101;lg=[0]*101\r\nfor i in range(int(input())):\r\n a,b=[int(x) for x in input().split()]\r\n lv[a]=1\r\n lg[b]=1\r\nprint(min(sum(lv),sum(lg)))\r\n", "n = int(input())\r\nx = []\r\ny = []\r\nfor i in range(n):\r\n clockInt = input()\r\n xInt = int(clockInt.split(' ')[0])\r\n yInt = int(clockInt.split(' ')[1])\r\n if xInt in x:\r\n pass\r\n else:\r\n x.append(xInt)\r\n if yInt in y:\r\n pass\r\n else:\r\n y.append(yInt)\r\nprint(min(len(x),len(y)))\r\n", "n = int(input())\nx = set()\ny = set()\nfor _ in range(n):\n X, Y = map(int,input().split())\n x.add(X)\n y.add(Y)\n\nprint(min(len(x),len(y)))\n", "n=int(input())\nxarr=[]\nyarr=[]\nfor i in range(n):\n\tx,y=map(int,input().split())\n\txarr.append(x)\n\tyarr.append(y)\nprint(min(len(set(xarr)),len(set(yarr))))\n", "n=int(input())\r\narr1=[]\r\narr2=[]\r\nfor i in range(n):\r\n l=[int(i) for i in input().split()]\r\n arr1.append(l[0])\r\n arr2.append(l[1])\r\nj1=[0 for i in range(101)]\r\nj2=[0 for i in range(101)]\r\nfor i in arr1:\r\n j1[i]+=1\r\nfor i in arr2:\r\n j2[i]+=1\r\na=j1.count(0)\r\nb=j2.count(0)\r\nprint(101-max(a,b))", "n = int(input())\n\nvertical = set()\nhorizontal = set()\n\nfor i in range(n):\n\tx, y = map(int, input().split())\n\n\tvertical.add(y)\n\thorizontal.add(x)\n\nprint(len(vertical) if len(vertical) < len(horizontal) else len(horizontal))", "n = int(input())\n\nxa = [0] * 101\nya = [0] * 101\n\ncount_of_x, count_of_y = 0, 0 \n\nfor i in range(0, n):\n\tx, y = map(int, input().split())\n\n\txa[x] += 1\n\tya[y] += 1\n\n\t\n\tif (xa[x] == 1):\n\t\tcount_of_x += 1\n\tif (ya[y] == 1):\n\t\tcount_of_y += 1\n\t\n\nprint(min(count_of_x, count_of_y))\n", "n = int(input())\ncoords = []\nfor i in range(n):\n coords.append(tuple(int(p) for p in input().split()))\n\nH = []\nV = []\nfor coord in coords:\n if coord[0] not in H:\n H.append(coord[0])\n if coord[1] not in V:\n V.append(coord[1])\n\nprint(min([len(H), len(V)])) ", "n= int(input())\r\nl=[]\r\nm=[]\r\nfor _ in range(n):\r\n x,y= map(int,input().split())\r\n l.append(x)\r\n m.append(y)\r\np=len(set(l))\r\nq= len(set(m))\r\nprint(min(p,q))", "n = int(input())\r\nh = set()\r\nv = set()\r\nfor i in range(n):\r\n a, b = map(int, input().split(' '))\r\n h.add(a)\r\n v.add(b)\r\nprint(min(len(h), len(v)))\r\n", "n = int(input())\r\na, b = [], []\r\nfor i in range(n):\r\n a0, b0 = map(int, input().split())\r\n a.append(a0)\r\n b.append(b0)\r\nv1 = set(a)\r\nv2 = set(b)\r\nprint(min(len(v1),len(v2)))", "n = int(input())\r\nlistx = []\r\nlisty = []\r\nfor i in range(0,n):\r\n\ta = (input().split())\r\n\ty = int(a[1])\r\n\tx = int(a[0])\r\n\tlistx.append(x)\r\n\tlisty.append(y)\r\nsetx = set(listx)\r\nsety = set(listy)\r\nmylist = [len(setx),len(sety)]\r\nprint(min(mylist))", "l1=[0]*101\r\nl2=[0]*101\r\nn=int(input())\r\nfor li in range(n):\r\n (x,y)=input().split(\" \")\r\n a=int(x)\r\n b=int(y)\r\n l1[a]=1\r\n l2[b]=1\r\nprint (min(sum(l1),sum(l2)))\r\n", "# cook your dish here\r\ndef countDistinct(arr, n):\r\n arrr=0\r\n ar=[]\r\n for elem in arr:\r\n if elem not in ar:\r\n arrr+=1\r\n ar.append(elem)\r\n return arrr\r\nn=int(input())\r\nx=[]\r\ny=[]\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\nprint(min(countDistinct(x,n),countDistinct(y,n)))", "n=int(input())\r\n\r\nsetx=set()\r\nsety=set()\r\n\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n setx.add(x)\r\n sety.add(y)\r\n\r\nprint(min(len(setx),len(sety)))", "def solve():\r\n n = int(input())\r\n x , y = [] , []\r\n for i in range(n):\r\n X , Y = map(int ,input() . split())\r\n x.append(X)\r\n y.append(Y)\r\n y = list(set(y))\r\n x = list(set(x))\r\n print(min(len(x) , len(y)))\r\nsolve()", "set_x = set()\r\nset_y = set()\r\nn = int(input())\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n set_x.add(x)\r\n set_y.add(y)\r\nprint(min(len(set_x), len(set_y)))", "'''\r\n\tCodeForces 309A\r\n\tInna and Alarm Clock\r\n\r\n\tTags: Counting\r\n'''\r\nfrom sys import stdin\r\nfrom collections import Counter\r\n\r\nn = int(input())\r\n\r\nalert = [ tuple(input().split()) for i in range(n) ]\r\nxs, ys = zip(*alert)\r\n\r\ncx = Counter(map(int, xs))\r\ncy = Counter(map(int, ys))\r\n\r\nprint(min(len(cx), len(cy)))", "x=[0]*101\r\ny=[0]*101\r\nn=int(input())\r\nfor i in range(n):\r\n\ta,b=[int(z) for z in input().split()]\r\n\tx[a]=1\r\n\ty[b]=1\r\nprint(min(sum(x),sum(y)))", "x =[set(),set()]\nfor i in range(int(input())):\n\tm = input().split()\n\tfor i in range(2):\n\t\tx[i].add(m[i])\nprint(min(map(len,x)))", "def alarm_clock():\r\n\tcount = int(input())\r\n\r\n\tx_set = set()\r\n\ty_set = set()\r\n\tfor _ in range(count):\r\n\t\tcoordinate = input().split()\r\n\t\tx_set.add(coordinate[0])\r\n\t\ty_set.add(coordinate[1])\r\n\r\n\tmoves = min(len(x_set), len(y_set))\r\n\tprint(moves)\r\n\t\r\n\r\n\r\nalarm_clock()", "n=int(input())\r\ns1=set()\r\ns2=set()\r\nfor i in range(n):\r\n\ta,b=map(int,input().split())\r\n\ts1.add(a)\r\n\ts2.add(b)\r\ns=min(len(s1),len(s2))\r\nprint(s)", "# python 3\n\"\"\"\n\"\"\"\n\n\ndef inna_and_alarm_clock(alarms_list) -> int:\n rc_dict = dict()\n for row, column in alarms_list:\n if rc_dict.get((row, 'r'), (0, 'r')) == (0, 'r'):\n rc_dict[(row, 'r')] = 1\n else:\n rc_dict[(row, 'r')] += 1\n if rc_dict.get((column, 'c'), (0, 'c')) == (0, 'c'):\n rc_dict[(column, 'c')] = 1\n else:\n rc_dict[(column, 'c')] += 1\n\n row_count = 0\n column_count = 0\n for _, r_or_c in rc_dict:\n if r_or_c == 'r':\n row_count += 1\n else:\n column_count += 1\n if row_count <= column_count:\n return row_count\n else:\n return column_count\n\n\nif __name__ == \"__main__\":\n \"\"\"\n Inside of this is the test. \n Outside is the API\n \"\"\"\n\n n = int(input())\n alarms = [tuple(map(int, input().split())) for i in range(n)]\n\n print(inna_and_alarm_clock(alarms))\n", "n = int(input())\r\nx = []\r\ny = []\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 if(x.count(array[0]) == 0):\r\n x.append(array[0])\r\n if(y.count(array[1]) == 0):\r\n y.append(array[1])\r\nprint(min(len(x),len(y)))", "x = []\r\ny = []\r\nfor _ in range(int(input())):\r\n n,m = map(int,input().split())\r\n x.append(n)\r\n y.append(m)\r\nprint(min(len(set(x)),len(set(y))))", "n = int(input())\r\nx_set = set()\r\ny_set = set()\r\nx_count = 0\r\ny_count = 0\r\n\r\nfor i in range(n):\r\n x, y = [int(x) for x in input().split()]\r\n if x not in x_set :\r\n x_set.add(x)\r\n x_count += 1\r\n \r\n if y not in y_set :\r\n y_set.add(y)\r\n y_count += 1\r\n \r\nprint(min(x_count, y_count))\r\n\r\n \r\n \r\n ", "n = int(input())\r\na = []\r\nb = []\r\nfor _ in range(n):\r\n\txy = list(map(str,input().split()))\r\n\ta.append(xy[0])\r\n\tb.append(xy[1])\r\naa = list(set(a))\r\nbb = list(set(b))\r\n\r\nif(len(aa) > len(bb)):\r\n\tprint(len(bb))\r\nelse:\r\n\tprint(len(aa))", "n = int(input())\r\nx_coor, y_coord =[], []\r\n\r\nfor i in range(0,n):\r\n x, y = map(int, input().split())\r\n x_coor.append(x)\r\n y_coord.append(y)\r\n\r\nprint(min(len(set(x_coor)) , len(set(y_coord))))", "i=lambda:map(int,input().split())\r\nn,=i()\r\na1,a2=[],[]\r\nfor _ in range(n):x,y=i();a1.append(x);a2.append(y)\r\nprint(min(len(set(a1)),len(set(a2))))", "n = int(input())\r\nx = []\r\ny = []\r\nnLinesX = 0\r\nnLinesY = 0\r\nfor i in range(n):\r\n tempInput = input()\r\n if tempInput.split()[0] not in x:\r\n x.append(tempInput.split()[0])\r\n nLinesX += 1\r\n if tempInput.split()[1] not in y:\r\n y.append(tempInput.split()[1])\r\n nLinesY += 1\r\nprint(sorted([nLinesX, nLinesY])[0])", "SF, SS = set(), set()\r\nfor i in range(int(input())):\r\n Temp = list(map(int, input().split()))\r\n SF.add(Temp[0])\r\n SS.add(Temp[1])\r\nprint(min(len(SF), len(SS)))\r\n\r\n# Caption: God bless you General Soleimani\r\n\r\n# ---------Hard Revenge---------\r\n\r\n# ****** Rest in Peace ******\r\n", "MAX_VALUE = 10**5 + 1\r\n\r\ndef main():\r\n n = int(input())\r\n coords = []\r\n for i in range(n):\r\n coords.append([int(j) for j in input().split()])\r\n on_x = [False for i in range(MAX_VALUE)]\r\n on_y = [False for i in range(MAX_VALUE)]\r\n\r\n for i in coords:\r\n on_x[i[0]] = True\r\n on_y[i[1]] = True\r\n max_x = 0\r\n max_y = 0\r\n for i in range(MAX_VALUE):\r\n if on_x[i]:\r\n max_x += 1\r\n if on_y[i]:\r\n max_y += 1\r\n return min(max_x, max_y)\r\n\r\nprint(main())", "n = int(input())\r\nxx = set()\r\nyy = set()\r\nfor i in range(n):\r\n x, y = list(map(int, input().split()))\r\n xx.add(x)\r\n yy.add(y)\r\n \r\nprint(min(len(xx), len(yy)))", "n = int(input())\r\nx = set()\r\ny = set()\r\nfor i in range(n):\r\n cad = input().split()\r\n x.add(cad[0])\r\n y.add(cad[1])\r\nif len(x)>len(y):\r\n print(len(y))\r\nelse:\r\n print(len(x))\r\n", "num=int(input())\r\nhor=set()\r\nver=set()\r\nfor i in range(num):\r\n inp=list(map(int,input().split()))\r\n hor.add(inp[0])\r\n ver.add(inp[1])\r\nprint(min(len(hor),len(ver)))\r\n", "n = int(input())\n\nx_set = set()\ny_set = set()\n\nfor i in range(n):\n\tx,y = map(int, input().split())\n\n\tx_set.add(x)\n\ty_set.add(y)\n\nprint(min(len(x_set), len(y_set)))", "n = int(input())\n\nX, Y = [None]*n, [None]*n\n\nfor i in range(n):\n X[i], Y[i] = tuple(map(int, input().split()))\n\nset_x, set_y = set(X), set(Y)\n\nfn = lambda x, y: min(len(x), len(y))\n\nprint(fn(set_x, set_y))", "n = int(input())\r\nx = [True for i in range(102)]\r\ny = [True for i in range(102)]\r\ncntx = 0\r\ncnty = 0\r\nfor i in range(n):\r\n\ta,b = [int(j) for j in input().split()]\r\n\tif x[a]:\r\n\t\tx[a] = False\r\n\t\tcntx+=1\r\n\tif y[b]:\r\n\t\ty[b] = False\r\n\t\tcnty+=1\r\n\r\nprint(min(cntx,cnty))\r\n", "n=int(input());\r\nx=set()\r\ny=set()\r\nfor i in range(n):\r\n j,k=map(int,input().split(\" \"));\r\n x.add(j);\r\n y.add(k);\r\nprint(min(len(x),len(y)))\r\n \r\n", "n = int(input())\r\nx = {}\r\ny = {}\r\nfor i in range(n):\r\n a, b = [int(i) for i in input().split()]\r\n x[a] = 0\r\n y[b] = 0\r\nprint(len(x) if len(x) <= len(y) else len(y))" ]
{"inputs": ["4\n0 0\n0 1\n0 2\n1 0", "4\n0 0\n0 1\n1 0\n1 1", "4\n1 1\n1 2\n2 3\n3 3", "1\n0 0", "42\n28 87\n26 16\n59 90\n47 61\n28 83\n36 30\n67 10\n6 95\n9 49\n86 94\n52 24\n74 9\n86 24\n28 51\n25 99\n40 98\n57 33\n18 96\n43 36\n3 79\n4 86\n38 61\n25 61\n6 100\n58 81\n28 19\n64 4\n3 40\n2 56\n41 49\n97 100\n86 34\n42 36\n44 40\n14 85\n21 60\n76 99\n64 47\n69 13\n49 37\n97 37\n3 70", "21\n54 85\n69 37\n42 87\n53 18\n28 22\n13 3\n62 97\n38 91\n67 19\n100 79\n29 18\n48 40\n68 84\n44 20\n37 34\n73 53\n21 5\n20 73\n24 94\n23 52\n7 55", "19\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19", "12\n1 1\n1 3\n1 5\n2 1\n2 2\n2 4\n3 1\n3 3\n3 5\n4 1\n4 2\n4 3"], "outputs": ["2", "2", "3", "1", "31", "20", "1", "4"]}
UNKNOWN
PYTHON3
CODEFORCES
165
162e217540a33d9eb197e241489b3c61
Alice, Bob and Chocolate
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman. How many bars each of the players will consume? The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right). Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob. Sample Input 5 2 9 8 2 7 Sample Output 2 3
[ "n = int(input())\r\nt = list(map(int,input().split()))\r\n\r\nAlice = 0\r\nBob = 0\r\n\r\ncA = 0\r\ncB = 0\r\n\r\ni = 0\r\nj = n-1\r\n\r\nwhile i<j:\r\n temp = min(Bob,Alice)\r\n Alice -= temp\r\n if Alice==0:\r\n Alice += t[i]\r\n cA += 1\r\n i += 1\r\n Bob -= temp\r\n if Bob==0:\r\n Bob += t[j]\r\n cB += 1\r\n j -= 1\r\n\r\nif i<=j:\r\n Alice -= min(Bob,Alice)\r\n if Alice==0:\r\n Alice += t[i]\r\n cA += 1\r\n i += 1\r\n else:\r\n Bob -= min(Alice,Bob)\r\n Bob += t[j]\r\n cB += 1\r\n j -= 1\r\n \r\nprint(cA,cB)", "import sys\r\nfrom math import *\r\nfrom collections import *\r\nfrom heapq import *\r\nfrom bisect import *\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\n\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\ni = 0\r\nj = n - 1\r\na, al = 0, 0\r\nb, bo = 0, 0\r\nwhile i <= j:\r\n if al <= bo:\r\n al += arr[i]\r\n a += 1\r\n i += 1\r\n else:\r\n bo += arr[j]\r\n b += 1\r\n j -= 1\r\nprint(a, b)\r\n\r\n", "n=int(input())\r\nchoco=list(map(int,input().split()))\r\ni,j=0,n-1\r\nif(n==1):\r\n print(1,0)\r\nelse:\r\n a,b=0,0\r\n sumA,sumB=0,0\r\n while(i<=j):\r\n if(i==j and sumA<=sumB):\r\n sumA+=choco[i]\r\n a+=1\r\n i+=1\r\n elif((sumA==0 or sumA<=sumB) ):\r\n sumA+=choco[i]\r\n a+=1\r\n i+=1\r\n elif((sumB==0 or sumB<=sumA)):\r\n sumB+=choco[j]\r\n j-=1\r\n b+=1\r\n\r\n print(a,b)", "# LUOGU_RID: 98755200\nn = int(input())\r\nlst = list(map(int,input().split()))\r\nl,r = 0,n-1\r\nsl,sr = 0,0\r\ncntl,cntr=0,0\r\nwhile l<=r:\r\n if sl<=sr:\r\n cntl+=1\r\n sl += lst[l]\r\n l+=1\r\n else:\r\n cntr+=1\r\n sr += lst[r]\r\n r-=1\r\nprint(\"%d %d\"%(cntl,cntr))\r\n", "n = int(input())\r\na = [int(x) for x in input().split()]\r\nb = 0\r\nc = 0\r\nd = 0\r\ne = n-1\r\nwhile d <= e:\r\n if b <= c:\r\n b += a[d]\r\n d += 1\r\n else:\r\n c += a[e]\r\n e -= 1\r\nprint(d, n - d)\r\n", "n=int(input())\r\nlst=list(map(int,input().split()))\r\ni=1\r\nj=n-2\r\na,b=lst[0],lst[-1]\r\nav=1\r\nbv=1\r\nwhile i<=j:\r\n if a<=b:\r\n a+=lst[i]\r\n i+=1\r\n av+=1\r\n elif b<a:\r\n b+=lst[j]\r\n bv+=1\r\n j-=1\r\n \r\nprint(av,n-av)\r\n ", "\r\nn=int(input())\r\nx=list(map(int,input().split()))\r\nca,cb=0,0\r\ni=0\r\nj=n-1\r\nwhile i<=j:\r\n\tif ca<=cb:\r\n\t\tca+=x[i]\r\n\t\ti+=1\r\n\telse:\r\n\t\tcb+=x[j]\r\n\t\tj-=1\r\nprint(i,n-i)\r\n", "n = int(input())\r\nt = list(map(int, input().split()))\r\na, b = 0, n - 1\r\na_count = 0\r\nb_count = 0\r\n\r\na_rem = t[a]\r\nb_rem = t[b]\r\n\r\nwhile a <= b:\r\n if a == b and a_rem == b_rem:\r\n a_count += 1\r\n break\r\n min_val = min(a_rem, b_rem)\r\n a_rem -= min_val\r\n b_rem -= min_val\r\n\r\n\r\n if a_rem == 0:\r\n a += 1\r\n a_rem = t[a]\r\n a_count += 1\r\n if b_rem == 0:\r\n b -= 1\r\n b_rem = t[b]\r\n b_count += 1\r\n \r\nprint(a_count, b_count)", "n=int(input())\nbars=list(map(int,input().split()))\nbars2=[]+bars\ntime=(sum(bars))\nATime=0\nANumber=0\n\nfor i in bars:\n if ATime+i>(time/2):\n break\n else:\n ATime+=i\n ANumber+=1\n bars2.pop(0)\n\nBTime=time-ATime-bars2[0]\nif BTime==ATime or BTime>ATime:\n ANumber+=1\n\nprint(ANumber,n-ANumber)\n", "n = int(input())\nv = list(map(int, input().split()))\nt1 = t2 = 0\nl = 0\nr = n - 1\n\nwhile l <= r:\n if t1 + v[l] <= t2 + v[r]:\n t1 = t1 + v[l]\n l += 1\n else:\n t2 = t2 + v[r]\n r -= 1\n\nprint(l, n - l)\n", "n = int(input())\r\nara = list(map(int, input().split()))\r\ncs = [ara[0] for i in range(n)]\r\nbcs = [ara[n-1] for i in range(n)]\r\nfor i in range(1, n): cs[i] = cs[i-1]+ara[i]\r\nfor i in range(n-2, -1, -1): bcs[i] = bcs[i+1]+ara[i]\r\n\r\n# print(cs)\r\n# print(bcs)\r\n\r\naliceEats = 0\r\nfor i in range(n):\r\n if cs[i] <= bcs[i]: aliceEats += 1\r\n\r\nprint(aliceEats, n-aliceEats)", "n = int(input())\r\nt = list(map(int, input().split()))\r\n\r\nbars = sum(t)\r\nhalf = bars / 2\r\n\r\nalice = 0\r\nalice_bar = 0\r\ncurrent = 0\r\nmid_bar = 0\r\nfor i in range(n):\r\n if current <= half and half <= current + t[i]:\r\n mid_bar = t[i]\r\n break\r\n else:\r\n alice += t[i]\r\n alice_bar += 1\r\n current += t[i]\r\n\r\nbob = bars - mid_bar - alice\r\nif alice == bob:\r\n print(alice_bar + 1, n - alice_bar - 1)\r\nelif alice < bob:\r\n print(alice_bar + 1, n - alice_bar - 1)\r\nelse:\r\n print(alice_bar, n - alice_bar)", "n=int(input())\r\na=list(map(int,input().split()))\r\n\r\nBob,Alice=0,0\r\ni,j=0,n-1\r\n\r\nwhile i<=j:\r\n if Alice <= Bob:\r\n Alice+=a[i]\r\n i+=1\r\n else:\r\n Bob+=a[j]\r\n j-=1\r\n\r\nprint(i,n-i)\r\n", "n=int(input())\r\nll=list(map(int,input().split()))\r\ni,j=0,n-1\r\ns1,s2=0,0\r\nwhile i<=j:\r\n if s1<=s2:\r\n s1+=ll[i]\r\n i+=1\r\n else:\r\n s2+=ll[j]\r\n j-=1\r\nprint(i,n-i)\r\n", "a=int(input())\r\nd=list(map(int,input().split()))\r\nl=0\r\ncl=0\r\nr=0\r\ncr=a-1\r\nfor i in range(a):\r\n\tif l<=r:\r\n\t\tcl+=1\r\n\t\tl+=d[cl-1]\r\n\telse:\r\n\t\tcr-=1\r\n\t\tr+=d[cr+1]\r\nprint(cl,a-cl)", "def get_ints():\r\n return map(int, input().strip().split())\r\n\r\ndef get_list():\r\n return list(map(int, input().strip().split()))\r\n\r\ndef get_string():\r\n return input().strip()\r\n\r\n# For fast IO use sys.stdout.write(str(x) + \"\\n\") instead of print\r\nimport sys\r\ninput = sys.stdin.readline\r\nimport math\r\n\r\n\r\nfor t in range(1):\r\n n = int(input().strip())\r\n arr = get_list()\r\n left, right, current_time = 0, n-1, 0\r\n left_sum, right_sum = 0, 0\r\n \r\n while left <= right:\r\n if left_sum + arr[left] <= right_sum + arr[right]:\r\n left_sum += arr[left]\r\n current_time = left_sum\r\n left += 1\r\n else:\r\n right_sum += arr[right]\r\n current_time = right_sum\r\n right -= 1\r\n \r\n print(left, (n-left))\r\n ", "#http://codeforces.com/contest/6/problem/C\r\n'''\r\nComment\r\n'''\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n bars = list(map(int, input().split()))\r\n\r\n ali = bob = 0;\r\n j = n\r\n i = -1\r\n\r\n while j - i > 1:\r\n if ali <= bob:\r\n i += 1\r\n ali += bars[i]\r\n else:\r\n j -= 1\r\n bob += bars[j]\r\n\r\n print(i + 1, n - j)", "n = int(input())\r\nshokolate = [int(x) for x in input().split()]\r\ni = 0\r\nj = len(shokolate) - 1\r\ndif_left = dif_right = 0 # обнуляем левую и правуб разность\r\ncount_bob = count_alice = 0\r\nlogik_bob = logik_alice = False\r\nwhile i < j:\r\n if shokolate[i] > shokolate[j]:\r\n dif_left = shokolate[i] - shokolate[j]\r\n shokolate[i] = dif_left\r\n shokolate[j] = 0\r\n j -= 1 # смещаем правый указатель\r\n count_bob += 1\r\n logik_bob = True # последним сдвинулся Боб\r\n logik_alice = False\r\n \r\n elif shokolate[i] < shokolate[j]:\r\n dif_right = shokolate[j] - shokolate[i]\r\n shokolate[j] = dif_right\r\n shokolate[i] = 0\r\n i += 1\r\n count_alice += 1\r\n logik_bob = False \r\n logik_alice = True # последней сдвинулась Элис\r\n \r\n elif shokolate[i] == shokolate[j] and (i + 1 == j - 1) :\r\n shokolate[i] = 0\r\n i += 1 \r\n count_alice += 1 # Боб уст упает \r\n elif shokolate[i] == shokolate[j] :\r\n shokolate[i] = 0\r\n shokolate[j] = 0 \r\n i += 1\r\n j -= 1 \r\n count_bob += 1 # кушают оба\r\n count_alice += 1 \r\n \r\nif len(shokolate) == 1:\r\n count_alice += 1 \r\nelif logik_bob and shokolate[i] > 0:\r\n count_alice += 1\r\nelif logik_alice and shokolate[i] > 0:\r\n count_bob += 1\r\n\r\nprint(count_alice, count_bob)", "k=int(input())\r\nj=[int(q) for q in input().split()]\r\nv=sum(j)\r\nn=j[0]\r\nq=0\r\nwhile n<v/2:\r\n q+=1\r\n n+=j[q]\r\nif v-n>=n-j[q]:q+=1\r\nprint(q,k-q)", "n=int(input())\na=list(map(int,input().strip().split()))[:n]\nc1=0\nc2=0\nl=0\nr=n-1\nf=0\nb=0\nwhile(l<=r):\n if(c1<=c2):\n c1=c1+a[l]\n l=l+1\n f=f+1\n \n else: \n c2=c2+a[r]\n b=b+1\n r=r-1\n\nprint(f,b,end=\" \")\n\t\t\t\t \t\t \t\t\t\t \t\t \t\t\t\t\t\t \t\t \t\t \t", "from collections import deque\r\nn = int(input())\r\nl = list(map(int, input().split()))\r\nd = deque(l)\r\n\r\na, b = 0, 0\r\naC, bC = 0, 0\r\nwhile d:\r\n if a <= b:\r\n a += d.popleft()\r\n aC += 1\r\n else:\r\n b += d.pop()\r\n bC += 1\r\nprint(f'{aC} {bC}')", "n = int(input())\r\nt = list(map(int, input().split()))\r\n\r\nif (n == 1):\r\n print(1, 0)\r\n exit()\r\n\r\ni = 0\r\nj = n-1\r\ncan_left = n-2\r\nalice = bob = 1\r\n\r\nwhile (can_left > 0):\r\n if (t[i] > t[j]):\r\n t[i] -= t[j]\r\n bob += 1\r\n j -= 1\r\n elif (t[i] < t[j]):\r\n t[j] -= t[i]\r\n alice += 1\r\n i += 1\r\n else:\r\n if (can_left == 1):\r\n alice += 1\r\n else:\r\n alice += 1\r\n bob += 1\r\n i += 1\r\n j -= 1\r\n can_left -= 1\r\n can_left -= 1\r\n\r\nprint(alice, bob)\r\n", "n = int(input())\na = list(map(int, input().split()))\ni, j = 0, -1\nalice, bob = 0, 0\na_time, b_time = 0, 0\nwhile alice + bob != n:\n if a_time <= b_time:\n alice += 1\n a_time += a[i]\n i += 1\n else:\n bob += 1\n b_time += a[j]\n j -= 1\nprint(alice, bob)\n\n\t\t \t\t\t\t\t\t \t \t \t \t \t\t\t \t", "n = int(input())\nt = list(map(int,input().split()))\na = 0\nb = 0\ni = 0\nj = n-1\nwhile (i<j):\n if (t[i]==t[j]) :\n t[i] = 0\n t[j] = 0\n i += 1\n j -= 1\n a += 1\n b += 1\n elif (t[i]>t[j]) :\n t[i] -= t[j]\n t[j] = 0\n b += 1\n j -= 1\n if (i==j) :\n t[i] = 0\n a += 1\n else:\n t[j] -= t[i]\n t[i] = 0\n a += 1\n i += 1\n if (i==j):\n t[j] = 0\n b += 1\nif (i==j and t[i]!=0):\n a += 1\nprint(a,b)\n", "n = int(input())\r\nt = list(map(int, input().split()))\r\n\r\nl = 0\r\nr = n - 1\r\ntAlice = tBob = 0\r\nwhile l <= r:\r\n if tAlice + t[l] <= tBob + t[r]:\r\n tAlice += t[l]\r\n l += 1\r\n else:\r\n tBob += t[r]\r\n r -= 1\r\n\r\nprint(str(l) + ' ' + str(n - l))", "n=int(input())\r\narr=[int(i) for i in input().split()]\r\nl,r=0,n-1\r\nlcount=0\r\nif(n==1):\r\n print(1,0)\r\n exit(0)\r\nwhile(l<r-1):\r\n if(arr[l]<arr[r]):\r\n lcount+=1\r\n arr[r]-=arr[l]\r\n l+=1\r\n elif(arr[l]==arr[r]):\r\n l+=1\r\n lcount+=1\r\n r-=1\r\n else:\r\n arr[l]-=arr[r]\r\n r-=1\r\nlcount+=1\r\nprint(lcount,n-lcount)", "n=int(input())\r\na=list(map(int,input().split()))\r\nt1,t2,p1,p2,l,r=0,0,0,0,0,n-1\r\nwhile True:\r\n if l==r:\r\n if t1<=t2:\r\n p1+=1\r\n else:\r\n p2+=1\r\n break\r\n if t1==t2:\r\n p1+=1\r\n t1+=a[l]\r\n l+=1\r\n else:\r\n if t1<t2:\r\n p1+=1\r\n t1+=a[l]\r\n l+=1\r\n else:\r\n p2+=1\r\n t2+=a[r]\r\n r-=1\r\nprint(str(p1)+\" \"+str(p2))\r\n \r\n \r\n", "from collections import deque\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nd=deque(a)\r\n\r\nans1,cnt1=0,0\r\nans2,cnt2=0,0\r\n\r\nwhile d:\r\n if cnt1<=cnt2:\r\n cnt1+=d.popleft()\r\n ans1+=1\r\n else:\r\n cnt2+=d.pop()\r\n ans2+=1\r\n\r\nprint(ans1,ans2)", "def bars(t):\n a = 0\n aa = []\n b = 0\n bb = []\n lim = sum(t) // 2\n for i in range(len(t)):\n if a + t[i] <= lim:\n a += t[i]\n aa.append(t[i])\n else:\n break\n for j in range(len(t) - 1, 0, -1):\n if b + t[j] <= lim:\n b += t[j]\n bb.append(t[j])\n else:\n break\n if len(aa) + len(bb) < len(t) and sum(aa) <= sum(bb):\n aa.append(0)\n elif len(aa) + len(bb) < len(t) and sum(bb) < sum(aa):\n bb.append(0)\n return len(aa), len(bb)\nn = int(input())\nt = list(map(int, input().split()))\ntime = sum(t)\na, b = bars(t)\nprint(a, b)\n\n \t\t\t\t \t \t \t\t \t\t", "#####################\n#1: Array, \n#R -> ++Count[]\n#L -> --Count[]\n# line1 = input().split(\" \")\n# arr = list(map(int,input().split()))\n# n = int(line1[0])\n# k = int(line1[1])\n# counts = {}\n# l = 0\n# r = 0\n# count = 0\n# for i in range(len(arr)):\n# if arr[i] in counts:\n# counts[arr[i]] += 1\n# else:\n# count += 1\n# counts[arr[i]] = 1\n# if count >= k:\n# r = i\n# break\n# for i in range(len(arr)):\n# l = i\n# counts[arr[i]] -= 1\n# if counts[arr[i]] == 0:\n# l = i\n# break\n# if count < k:\n# print(\"-1 -1\")\n# else:\n# print(l + 1, r + 1)\n\n#2: George and Round\n# n, m = map(int, input().split())\n# arrA = list(map(int, input().split()))\n# arrB = list(map(int, input().split()))\n# k = n\n# pA = 0\n# pB = 0\n# while pB < m:\n# if arrB[pB] >= arrA[pA]:\n# k -= 1\n# pA += 1\n# if pA >= n:\n# break\n# pB += 1\n# print(k)\n\n#3\n# n, t = map(int, input().split())\n# a = list(map(int, input().split()))\n# l = 0\n# r = 0\n# maxx = 0\n# summ = 0\n# while r <= n:\n# if r == n:\n# maxx = max(maxx, (r - 1) - l + 1)\n# break\n# if summ + a[r] > t:\n# maxx = max(maxx, (r - 1) - l + 1)\n# summ -= a[l]\n# l += 1\n# else:\n# summ += a[r]\n# r += 1\n# print(maxx)\n\n#6: \n# n = int(input())\n# a = list(map(int, input().split()))\n# l = 0\n# r = 0\n# maxx = 0\n# while r <= n:\n# if r == n and abs(a[r - 1] - a[l]) <= 1:\n# maxx = max(maxx, (r - 1) - l + 1)\n# break\n# if abs(a[r] - a[l]) > 1:\n# maxx = max(maxx, (r - 1) - l + 1)\n# l += 1\n# else:\n# r += 1\n# print(maxx)\n\n#8: https://codeforces.com/problemset/problem/6/C\nn = int(input())\na = list(map(int, input().split()))\nl = 0\nr = n - 1\nalice = 0\nbob = 0\ntA = 0\ntB = 0\n#<=0: alice turn, >0 bob turn\nwhile l <= r:\n if tA - tB <= 0:\n alice += 1\n tA += a[l]\n l += 1\n else:\n bob += 1\n tB += a[r]\n r -= 1\nprint(alice, bob)", "n=int(input())\r\nl=[int(x) for x in input().split()]\r\nif n==1:\r\n print(1,0)\r\nelif n==2:\r\n print(1,1)\r\nelse:\r\n i=0\r\n j=n-1\r\n alice=l[i]\r\n bob=l[j]\r\n a=1\r\n b=1\r\n while(1):\r\n if i>j or i==j-1:\r\n break\r\n if alice <=bob:\r\n i+=1\r\n alice+=l[i]\r\n a+=1\r\n else:\r\n j-=1\r\n bob+=l[j]\r\n b+=1\r\n print(a,b)", "n = int(input())\r\na=list(map(int,input().split()))\r\n\r\nalice = sum(a)\r\nbob=0\r\n\r\nmin_son = abs(alice-bob)\r\nindex=0\r\nfor i in range(n):\r\n alice-=a[i]\r\n bob+=a[i]\r\n if min_son>=abs(alice-bob):\r\n min_son = abs(alice-bob)\r\n index+=1\r\n \r\nprint(index,n-index)\r\n", "class A:\n\n def solve(self):\n pass\n\nclass B:\n\n def solve(self):\n [n, m, c] = list(input().split(\" \"))\n n, m = int(n), int(m)\n\n matrix = []\n for i in range(n):\n matrix.append(input())\n\n neighbours = set()\n for i in range(n):\n for j in range(m):\n if matrix[i][j] == c:\n if i - 1 >= 0 \\\n and matrix[i - 1][j] != c \\\n and matrix[i - 1][j] != '.':\n neighbours.add(matrix[i - 1][j])\n if j + 1 < m \\\n and matrix[i][j + 1] != c \\\n and matrix[i][j + 1] != '.':\n neighbours.add(matrix[i][j + 1])\n if i + 1 < n \\\n and matrix[i + 1][j] != c \\\n and matrix[i + 1][j] != '.':\n neighbours.add(matrix[i + 1][j])\n if j - 1 >= 0 \\\n and matrix[i][j - 1] != c \\\n and matrix[i][j - 1] != '.':\n neighbours.add(matrix[i][j - 1])\n\n print(len(neighbours))\n\nclass C:\n\n def solve(self):\n n = int(input())\n bars = [int(x) for x in input().split(\" \")]\n\n a_time = 0\n a_index = 0\n a_bars = 0\n b_time = 0\n b_index = n - 1\n b_bars = 0\n\n while a_index <= b_index:\n if a_time == b_time and a_index == b_index:\n a_time += bars[a_index]\n a_index += 1\n a_bars += 1\n b_index -= 1\n else:\n if a_time < b_time:\n a_time += bars[a_index]\n a_index += 1\n a_bars += 1\n else:\n b_time += bars[b_index]\n b_index -= 1\n b_bars += 1\n\n print(\"{} {}\".format(a_bars, b_bars))\n\nC().solve()\n", "\r\nn = int(input())\r\nchocolate = list(map(int,input().split()))\r\n\r\nalice,bob,i,j = 0,0,0,n-1\r\n\r\nwhile i <= j:\r\n if alice + chocolate[i] <= bob + chocolate[j]:\r\n alice+=chocolate[i]\r\n i+=1\r\n else:\r\n bob+=chocolate[j]\r\n j-=1\r\nprint(i,n-i)", "def solve(num,seq) :\r\n pointer1 = 0\r\n pointer2 = num-1\r\n \r\n \r\n bobEating = False\r\n \r\n alice = 0\r\n bob = 0\r\n \r\n while pointer1 <= pointer2 :\r\n if pointer1 == pointer2 :\r\n if not bobEating :\r\n alice += 1\r\n else :\r\n bob += 1\r\n pointer1 += 1\r\n pointer2 -= 1\r\n else :\r\n bobEating = True\r\n if seq[pointer1] < seq[pointer2] :\r\n seq[pointer2] -= seq[pointer1] \r\n pointer1 += 1\r\n alice += 1 \r\n elif seq[pointer1] > seq[pointer2] :\r\n seq[pointer1] -= seq[pointer2]\r\n pointer2 -= 1\r\n bobEating = False\r\n bob += 1\r\n else :\r\n alice += 1\r\n bob += 1\r\n \r\n bobEating = False\r\n pointer1 += 1\r\n pointer2 -= 1\r\n \r\n print (alice,bob)\r\n return \r\n \r\n\r\nn = int(input())\r\nseq = list(map(int,input().split()))\r\nsolve(n,seq)\r\n \r\n \r\n\r\n", "n=int(input())\r\na=[int(x)for x in input().split()]\r\nl,sl,sr,r=0,a[0],a[n-1],n-1\r\nwhile l<r-1:\r\n if sl<=sr:\r\n l+=1;sl+=a[l]\r\n else:\r\n r-=1;sr+=a[r]\r\n\r\nprint(*(l+1,n-r) if n!=1 else '10')", "n = int(input())\r\nl = list(map(int, input().split()))\r\ns = sum(l)\r\np = l[0]\r\ni = 0\r\nwhile p < s / 2:\r\n i += 1\r\n p += l[i]\r\nif s - p >= p - l[i]:\r\n i += 1\r\nprint(i, n - i)", "n = int(input())\r\nchoc = list(map(int, input().split()))\r\n\r\nL, R = 0, n - 1\r\na = b = 0\r\n\r\nwhile L <= R:\r\n if a <= b:\r\n a += choc[L]\r\n L += 1\r\n else:\r\n b += choc[R]\r\n R -= 1\r\n\r\nprint(\"{} {}\".format(L, n - R - 1))", "n = int(input())\nmy_list = input().split(\" \")\nfor x in range(len(my_list)):\n my_list[x] = int(my_list[x])\n\ntime = sum(my_list)\n\ndef subs(my_list):\n Alice = 0\n A = []\n Bob = 0\n B = []\n LIMIT = sum(my_list) // 2\n \n for x in range( len(my_list) ):\n if Alice + my_list[x] <= LIMIT:\n Alice += my_list[x]\n A.append(my_list[x])\n else:\n break\n \n for y in range( len(my_list)-1, -1, -1 ):\n if Bob + my_list[y] <= LIMIT:\n Bob += my_list[y]\n B.append(my_list[y])\n else:\n break\n \n if len(A) + len(B) < len(my_list) and sum(A) <= sum(B):\n A.append(0)\n elif len(A) + len(B) < len(my_list) and sum(B) < sum(A):\n B.append(0)\n return len(A), len(B)\n\nA, B = subs(my_list)\nprint (A, B)\n \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\nls , rs ,l,r= 0,0,0,n-1\r\nwhile l<=r:\r\n if ls<=rs:\r\n ls+= lst[l]\r\n l+=1\r\n else:\r\n rs += lst[r]\r\n r -=1\r\nprint(l,n-r-1)", "n = int(input())\narr = [int(p) for p in input().split()]\nfinal = [0]*n\nfinal[0] = arr[0]\nfinal[-1] = arr[-1]\ni = 0\nj = n-1\na,b = 1,1\nif n == 1:\n\tprint(1, 0)\n\texit()\nwhile i != j-1:\n\tif final[i] <= final[j]:\n\t\ti += 1\n\t\tfinal[i] = final[i-1] + arr[i]\n\t\ta += 1\n\telse:\n\t\tj -= 1\n\t\tfinal[j] = final[j+1] + arr[j]\n\t\tb += 1\nprint(a, n-a)", "################################################################################\r\nn=int(input())\r\nc=list(map(int,input().split()))\r\n\r\n# n=5\r\n# c=[2,9,8,2,7]\r\n################################################################################\r\ntotal=sum(c)\r\na=-1\r\neata=0\r\nwhile 1>0:\r\n if eata+c[a+1]<=total/2:\r\n eata+=c[a+1]\r\n a+=1\r\n else:\r\n break\r\n\r\nif a<n-1:\r\n if (total/2-eata)/c[a+1]>=0.5:\r\n a=a+1\r\n\r\nprint(a+1,len(c)-a-1)\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nai=0\r\nbi=n-1\r\naa=0\r\nbb=0\r\nwhile ai<=bi:\r\n if aa<=bb:\r\n aa+=a[ai]\r\n ai+=1\r\n else:\r\n bb+=a[bi]\r\n bi-=1\r\nprint(ai,n-bi-1)", "n = int(input())\r\na = list(map(int,input().split()))\r\ns1 = 0\r\ns2 = 0\r\nl = 0\r\nr = n - 1\r\nwhile l <= r:\r\n if s1 <= s2:\r\n s1+=a[l]\r\n l+=1\r\n else:\r\n s2+=a[r]\r\n r-=1\r\nprint(l,n-l)", "n = int(input())\r\nt = list(map(int, input().split()))\r\n \r\ni = 0\r\nj = n-1\r\nsoma1 = 0\r\nsoma2 = 0\r\n \r\nwhile (i <= j):\r\n\tif (soma1 <= soma2):\r\n\t\tsoma1 += t[i]\r\n\t\ti += 1\r\n\telse:\r\n\t\tsoma2 += t[j]\r\n\t\tj -= 1\r\n \r\nprint (i, n-j-1)", "a = int(input())\nlst1 = input().split(' ')\nlst2 = [int(x) for x in lst1]\nn = sum(lst2)/2\ncount = 0\nfor x in lst2:\n n -= x\n count += 1\n if n <= 0:\n if n + x >= x / 2:\n break\n else:\n count -= 1\n break\nprint(count,a - count)\n\t \t\t \t\t \t\t\t \t\t \t \t\t", "if __name__ == '__main__':\r\n n=int(input())\r\n x=list(map(int,input().split()))\r\n ca,cb=0,0\r\n i=0\r\n j=n-1\r\n while i<=j:\r\n \tif ca<=cb:\r\n \t\tca+=x[i]\r\n \t\ti+=1\r\n \telse:\r\n \t\tcb+=x[j]\r\n \t\tj-=1\r\n print(i,n-i)", "n = int(input())\r\nla = list(map(int, input().split()))\r\nlb = la[::-1]\r\nif n == 1:\r\n li = ['1', '0']\r\n print(\" \".join(li))\r\nelse:\r\n t1 = la[0]\r\n t2 = lb[0]\r\n i = 1\r\n j = 1\r\n while i + j < n:\r\n if t1 <= t2:\r\n i += 1\r\n t1 += la[i - 1]\r\n else:\r\n j += 1\r\n t2 += lb[j - 1]\r\n li = [str(i), str(j)]\r\n print(' '.join(li))", "n = int(input())\r\ntimes = list(map(int, input().split()))\r\n\r\na = b = 0\r\nleft, right = 0, n - 1\r\ntotal_time_a = total_time_b = 0\r\n\r\nwhile left <= right:\r\n if total_time_a <= total_time_b:\r\n total_time_a += times[left]\r\n a += 1\r\n left += 1\r\n else:\r\n total_time_b += times[right]\r\n b += 1\r\n right -= 1\r\n\r\nprint(a, b)\r\n", "n = int(input())\r\nt = list(map(int, input().split()))\r\n\r\nl = -1\r\nr = n\r\nalice = 0\r\nbob = 0\r\nalice_ans = 0\r\nbob_ans = 0\r\nwhile (l + 1 < r):\r\n if alice <= bob:\r\n l += 1\r\n alice_ans += 1\r\n alice += t[l]\r\n else:\r\n r -= 1\r\n bob_ans += 1\r\n bob += t[r]\r\n\r\nprint(alice_ans, bob_ans)", "n=int(input())\r\narr=list(map(int,input().split()))\r\nbrr=arr.copy()\r\nalice,bob=1,1\r\ni,j=0,n-1\r\nif(n==1):\r\n print(1,0)\r\nelse:\r\n while(i<=j):\r\n if(i==j and arr[i]==brr[i]):\r\n alice+=1\r\n break\r\n elif(i==j):\r\n break\r\n t=min(arr[i],arr[j])\r\n arr[i]=arr[i]-t\r\n arr[j]=arr[j]-t\r\n #print(arr,brr)\r\n if(arr[i]<=0):\r\n arr[i+1]+=arr[i]\r\n i+=1\r\n if(arr[i]==brr[i] and arr[i+1]!=0):\r\n alice+=1\r\n if(arr[j]<=0):\r\n arr[j-1]+=arr[j]\r\n j-=1\r\n if(brr[j]==arr[j] and arr[j-1]!=0):\r\n bob+=1\r\n #print(alice,bob)\r\n print(alice,bob)\r\n\r\n", "a=int(input())\r\nx=list(map(int,input().split()))\r\nh=len(x)-1\r\nl=0\r\nalice=0\r\nbob=0\r\nwhile(h!=l+1 and h!=l):\r\n if(x[h]>x[l]):\r\n alice=alice+1\r\n x[h]=x[h]-x[l]\r\n l=l+1\r\n \r\n elif(x[h]<x[l]):\r\n bob=bob+1\r\n x[l]=x[l]-x[h]\r\n h=h-1\r\n else:\r\n bob=bob+1\r\n alice=alice+1\r\n h=h-1\r\n l=l+1\r\nif(h==l):\r\n alice=alice+1\r\n print(alice,bob)\r\nelse:\r\n print(alice+1,bob+1)\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n", "n = int(input())\r\nt = list(map(int, input().split()))\r\n\r\na, b, timea, timeb = 0, 0, 0, 0\r\nfor i in range(n):\r\n if timea <= timeb:\r\n timea += t.pop(0)\r\n a += 1\r\n else:\r\n timeb += t.pop()\r\n b += 1\r\n\r\nprint(a, b)", "def main(): \r\n n = int(input()) #Cantidad de barras\r\n tim = list(map(int, input().split())) #Tiempo en comer las barras \r\n a = 0 #Tiempo de Alice\r\n ca = 0 #Cantidad Alice\r\n b = 0 #Tiempo de Bob\r\n cb = 0 #Cantidad Bob\r\n \r\n counter = n #Contador de veces que hay que comer chocolates\r\n while counter:\r\n if len(tim) == 1 and (a==b):\r\n a += tim[0]\r\n tim.pop(0) \r\n ca += 1 \r\n counter -= 1 \r\n else:\r\n if a < b:\r\n a += tim[0]\r\n tim.pop(0)\r\n ca += 1 \r\n counter -= 1\r\n elif b < a:\r\n b += tim[-1]\r\n tim.pop(-1)\r\n cb += 1 \r\n counter -= 1\r\n elif a == b:\r\n a += tim[0]\r\n b += tim[-1]\r\n tim.pop(0)\r\n tim.pop(-1)\r\n ca += 1 \r\n cb += 1 \r\n counter -= 2\r\n \r\n print(str(ca)+\" \"+str(cb))\r\n \r\nif __name__ == \"__main__\":\r\n main()", "import sys\r\nimport math\r\n \r\nn = int(sys.stdin.readline())\r\nan = [int(x) for x in (sys.stdin.readline()).split()]\r\n\r\nif(n == 1):\r\n print(1, 0)\r\n exit()\r\n\r\nj = n - 1\r\ni = 0\r\nacc1 = an[i]\r\nres1 = 1\r\nacc2 = an[n - 1]\r\nres2 = 1\r\nwhile(int(math.fabs(i - j)) > 1):\r\n if(acc1 < acc2):\r\n i += 1\r\n res1 += 1\r\n acc1 += an[i]\r\n elif(acc2 < acc1):\r\n j -= 1\r\n res2 += 1\r\n acc2 += an[j]\r\n else:\r\n i += 1\r\n j -= 1\r\n acc1 += an[i]\r\n res1 += 1\r\n if(i - j != 0):\r\n acc2 += an[j]\r\n res2 += 1\r\n \r\n \r\n \r\nprint(res1, res2)\r\n \r\n \r\n \r\n \r\n ", "n=int(input())\r\nl=list(map(int,input().split()))\r\nc=[0]*(n+2)\r\nfor i in range(1,n+1):\r\n c[i]=c[i-1]+l[i-1]\r\nc[n+1]=c[n]\r\nx=0\r\ny=n+1\r\nwhile(y>x):\r\n a=c[x]\r\n b=c[n+1]-c[y]\r\n if(a<b or a==b):\r\n x+=1\r\n elif(b<a):\r\n y-=1\r\nprint(x,n-x)", "n = int(input())\r\na = [*map(int, input().split())]\r\nans = sum(a) / 2\r\ns = 0\r\nfor i in range(n):\r\n s += a[i]\r\n if s > ans:\r\n if sum(a) - s < s - a[i]:\r\n i -= 1\r\n print(i + 1, n - i - 1)\r\n break\r\n\r\n\r\n\r\n", "n=int(input())\r\nz=list(map(int,input().split()))\r\nalice=0\r\nbob=0\r\na=0\r\nb=0\r\ni=0\r\nj=n-1\r\nwhile(i<=j):\r\n\tif(alice==bob):\r\n\t\talice+=z[i]\r\n\t\ti+=1\r\n\t\ta+=1\r\n\telif((alice)<(bob)):\r\n\t\ta+=1\r\n\r\n\t\talice+=z[i]\r\n\t\ti+=1\r\n\telse:\r\n\t\tbob+=z[j]\r\n\t\tb+=1\r\n\t\tj-=1\r\n\t# print(alice,bob)\r\nprint(a,b)", "from sys import stdin,stdout\r\nimport math,bisect,heapq\r\nfrom collections import Counter,deque,defaultdict\r\nL = lambda:list(map(int, stdin.readline().strip().split()))\r\nI = lambda:int(stdin.readline().strip())\r\nS = lambda:stdin.readline().strip()\r\nC = lambda:stdin.readline().strip().split()\r\ndef pr(a):print(\" \".join(list(map(str,a))))\r\n#_________________________________________________#\r\n\r\ndef solve():\r\n n = I()\r\n a = L()\r\n i,j = 0,n-1\r\n p,q = 0,0\r\n while i<=j:\r\n if q>=p:\r\n p+=a[i]\r\n i+=1\r\n else:\r\n q+=a[j]\r\n j-=1\r\n print(i,n-i)\r\n \r\nfor _ in range(1):\r\n solve()\r\n\r\n", "n = int(input())\ntimes = [int(n) for n in input().split()]\nmid = sum(times) / 2\n\ncur = 0\ni = 0\nwhile i < len(times):\n cur += times[i]\n\n if cur > mid:\n break\n i += 1\n\ni -= 1\n# print(i)\n\npart1 = 0\nfor j in range(i + 1):\n part1 += times[j]\n\npart2 = 0\nfor j in range(len(times) - 1, i + 1, -1):\n part2 += times[j]\n\nif part1 <= part2:\n i += 2\nelse:\n i += 1\n\n# print(part1, part2)\nprint(i, len(times) - i)\n", "import sys \r\ninput = sys.stdin.readline \r\nn = int(input())\r\nl = list(map(int, input().split()))\r\na, b = [l[0]], [l[-1]]\r\nfor i in range(1, n):\r\n a.append(a[-1] + l[i])\r\nfor i in range(n - 2, -1, -1):\r\n b.append(b[-1] + l[i])\r\nb.reverse()\r\nc = 0 \r\nfor i in range(n):\r\n if(a[i] <= b[i]):\r\n c += 1 \r\nprint(c, n - c)", "n=int(input())\r\nl=list(map(int,input().split()))\r\ns,c=0,0\r\ni,j=0,n-1\r\nx,y=0,0\r\nwhile(i<=j):\r\n if(s<=c):\r\n s=s+l[i]\r\n x=x+1\r\n i+=1\r\n else:\r\n c+=l[j]\r\n j-=1\r\n y+=1\r\nprint(x,y)\r\n", "n = int(input())\r\nt = list(map(int, input().split()))\r\n\r\ni = 0\r\nj = n-1\r\nsum1 = 0\r\nsum2 = 0\r\n\r\nwhile (i <= j):\r\n\tif (sum1 <= sum2):\r\n\t\tsum1 += t[i]\r\n\t\ti += 1\r\n\telse:\r\n\t\tsum2 += t[j]\r\n\t\tj -= 1\r\n\r\nprint (i, n-j-1)\r\n", "i = int(input())\r\nl = list(map(int,input().split()))\r\na = b = 0\r\nac = 0;bc = 1\r\nwhile ac+bc <= i:\r\n if a <= b: a += l[ac];ac += 1\r\n else: b += l[-1*bc]; bc += 1\r\nprint(ac,bc-1)", "def solve(lst):\r\n if len(lst) == 1:\r\n return 1, 0\r\n elif len(lst) == 2:\r\n return 1, 1\r\n else:\r\n suml = lst[0]\r\n sumr = lst[-1]\r\n i = 0\r\n j = len(lst) - 1\r\n while i < j - 1:\r\n if suml < sumr:\r\n i += 1\r\n suml += lst[i]\r\n elif suml > sumr:\r\n j -= 1\r\n sumr += lst[j]\r\n else:\r\n i += 1\r\n j -= 1\r\n suml += lst[i]\r\n sumr += lst[j]\r\n return i + 1, len(lst) - (i + 1)\r\n\r\n\r\nn = int(input())\r\nlst = list(map(int, input().split()))\r\na, b = solve(lst)\r\nprint(a, end=\" \")\r\nprint(b)\r\n", "n = int(input())\nT = list(map(int, input().split()))\n\nfrom itertools import accumulate\nA = [0]+T\nB = [0]+list(reversed(T))\nA = list(accumulate(A))\nB = list(accumulate(B))\n\n#print(A)\n#print(B)\n\na = 0\nb = 0\nfor i in range(n):\n if A[i+1] <= B[n-i]:\n a += 1\n else:\n b += 1\nprint(a, b)\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\ni=1\r\nj=n-2\r\na,b=l[0],l[-1]\r\na1=1\r\nb1=1\r\nwhile i<=j:\r\n if a<=b:\r\n a+=l[i]\r\n i+=1\r\n a1+=1\r\n elif b<a:\r\n b+=l[j]\r\n b1+=1\r\n j-=1\r\n \r\nprint(a1,n-a1)\r\n ", "def main():\n\tfrom sys import stdin, stdout\n\n\tn = int(stdin.readline())\n\ttimes = list(map(int, stdin.readline().split()))\n\n\taliceGasto, bobGasto = 0, 0\n\tcontadoAlice, contadorBob = 0, 0\n\ti, j = 0, n-1\n\n\twhile(i <= j):\n\t\tif aliceGasto <= bobGasto:\n\t\t\taliceGasto += times[i]\n\t\t\tcontadoAlice += 1\n\t\t\ti += 1\n\t\telse:\n\t\t\tbobGasto += times[j]\n\t\t\tcontadorBob += 1\n\t\t\tj -= 1\n\n\tstdout.write(''.join([str(contadoAlice), ' ', str(contadorBob)]))\n\n\nif __name__ == '__main__':\n\tmain()\n\t \t \t\t \t \t\t \t\t \t\t \t\t \t\t\t \t", "n=int(input())\r\n*l,=map(int,input().split())\r\na=b=i=0\r\nj=n-1\r\nwhile i<=j:\r\n if a<=b:a+=l[i];i+=1\r\n else:b+=l[j];j-=1\r\nprint(i,n-i)", "n = int(input())\r\nlist = list(map(int, input().split()))\r\n\r\ni = 0\r\nj = n - 1\r\n\r\nif n == 1:\r\n print(\"1 0\")\r\nelse:\r\n countA = 1\r\n countB = 1\r\n\r\n timeA = list[i]\r\n timeB = list[j]\r\n\r\n while countA + countB < n:\r\n if timeA > timeB:\r\n countB += 1\r\n j -= 1\r\n timeB += list[j]\r\n else:\r\n countA += 1\r\n i += 1\r\n timeA += list[i]\r\n \r\n print(countA, countB)\r\n\r\n", "t = int(input())\r\n\r\ntable = list(map(int,input().split()))\r\nn = ['' for i in range(t)]\r\ni=0\r\nj=-1\r\nc = t\r\nwhile c>0:\r\n m = min(table[i], table[j])\r\n table[i]-=m\r\n table[j]-=m\r\n if n[i] == '':\r\n n[i]='a'\r\n elif n[i]=='b': break\r\n if n[j] == '':\r\n n[j]='b'\r\n elif n[j]=='a': break\r\n if table[i]==0:\r\n i+=1\r\n c-=1\r\n if table[j]==0:\r\n j-=1\r\n c-=1\r\nprint(str(n.count('a'))+' '+str(n.count('b')))\r\n", "\nn = int(input())\ns = input()\nlis = []\ns = s.split()\nfor i in range(n):\n\tlis.append(int(s[i]))\nl = 0; r = n-1; \nwhile l < r:\n\tif lis[l] > lis[r]:\n\t\tlis[l] -= lis[r]\n\t\tr -= 1\n\t\tif r == l:\n\t\t\tr += 1\n\t\t\tbreak\n\telse:\n\t\tlis[r] -= lis[l]\n\t\tl += 1\n\t\tif l == r:\n\t\t\tl -= 1\n\t\t\tbreak\nif n == 1:\n\tprint('1 0')\n\texit()\n# print(l,r)\nprint(l+1,n-r)\n", "n = int(input())\r\n\r\nt = list(map(int, input().split()))\r\n\r\np, s = [0 for _ in range(n)], [0 for _ in range(n)]\r\n\r\nfor i in range(1, n):\r\n\tp[i] = p[i - 1] + t[i - 1]\r\n\r\nfor i in range(n - 2, -1, -1):\r\n\ts[i] = s[i + 1] + t[i + 1]\r\n\r\na, b = 0, 0\r\n\r\nfor i in range(n):\r\n\tif p[i] <= s[i]:\r\n\t\ta += 1\r\n\telse:\r\n\t\tb += 1\r\n\r\nprint(a, b)\r\n", "n=int(input())\nt=list(map(int,input().split()))\nalice_time =0\nbob_time =0\nleft=0\nright=n-1\nwhile left<=right:\n if alice_time <= bob_time:\n alice_time += t[left]\n left+=1\n else:\n bob_time+=t[right]\n right -=1\nprint(left,n-left)\n\t\t\t\t \t\t\t\t \t\t \t\t \t \t \t\t \t \t", "'''\nFilePath: Alice_Bob_and_Chocolate.py\nAuthor: nev8r\nDate: 2023-05-07 20:43:21\nLastEditTime: 2023-05-07 21:27:23\n'''\n'''\n # 原神怎么你了!!!\n # @author: nev8r\n # @file: Alice_Bob_and_Chocolate.py\n # @date: 2023/05/07 20:43\n'''\nfrom sys import stdin\nfrom itertools import combinations\nfrom bisect import bisect as bis #a=[1,3,4,6,7,8] #bis(a,5)-->3\nimport bisect #bisect.bisect_left(a,4)-->2 #bisect.bisect(a,4)-->3\nfrom collections import deque\n# @lru_cache(maxsize=None) #help with pypy3-64 speed, add to function\nimport math\nimport time\ninput = stdin.readline\nn = int(input())\ncl = list(map(int,input().split()))\nsuml = [0]\nfor i in range(len(cl)):\n suml.append(suml[i] + cl[i])\n# print(suml)\nl = 1\nr = n - 1\nwhile l < r:\n # print(l,r)\n if suml[l] <= suml[n] - suml[r]:\n l += 1\n else:\n r -= 1\nprint(l,n - l)\n \t\t\t \t\t \t \t\t\t\t \t \t \t \t\t\t", "N = int(input())\r\ntimes = list(map(int, input().split()))\r\n\r\nalice_time = 0\r\nbob_time = 0\r\nleft = 0\r\nright = N - 1\r\nwhile left <= right:\r\n if alice_time > bob_time:\r\n bob_time += times[right]\r\n right -= 1\r\n else:\r\n alice_time += times[left]\r\n left += 1\r\nprint(left, N - 1 - right)", "'''\r\n @Author: Pham T. Nhan\r\n @Date: 31/10/2018\r\n @Name: Alice, Bob and Chocolate\r\n @Link: http://codeforces.com/problemset/problem/6/C\r\n'''\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n piece = list(map(int, input().split()))\r\n total = sum(piece)\r\n\r\n alice, bob = 0, 0\r\n alice_time, bob_time = 0, 0\r\n\r\n for i in range(n):\r\n if (2 * (alice_time + piece[i]) <= total):\r\n alice += 1\r\n alice_time += piece[i]\r\n else:\r\n break\r\n\r\n for i in range(n - 1, -1, -1):\r\n if (2 * (bob_time + piece[i]) <= total):\r\n bob += 1\r\n bob_time += piece[i]\r\n else:\r\n break\r\n\r\n if bob + alice < n:\r\n if bob_time < alice_time:\r\n bob += 1\r\n else:\r\n alice += 1\r\n\r\n print('{} {}'.format(alice, bob))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "# # a=int(input())\r\n# # e=0\r\n# # o=0\r\n# # flag=1\r\n# # l=list(map(int,input().split()))\r\n# # for i in l:\r\n# # if i%2==1:\r\n# # o+=1\r\n# # else:\r\n# # e+=1\r\n# # if (o and e):\r\n# # break\r\n# # if (o>0 and e>0):\r\n# # l.sort()\r\n# # for i in l:\r\n# # print(i,end= ' ')\r\n# # else:\r\n# # for i in l:\r\n# # print(i,end= ' ')\r\n# # print()\r\n\r\n\r\n# a,b,c,d,e=map(int,input().split())\r\n# s=input()\r\n# b=d-b\r\n# c=e-c\r\n\r\n# if b<0:\r\n# d='W'\r\n# elif b==0:\r\n# d=0\r\n# else:\r\n# d=\"E\"\r\n\r\n# if c<0:\r\n# e=\"S\"\r\n# elif c==0:\r\n# e=0\r\n# else:\r\n# e=\"N\"\r\n# flag=1\r\n# q=0\r\n# count1=0\r\n# count2=0\r\n# # print(d,e)\r\n# check=abs(c)+abs(b)\r\n# for i in s:\r\n# if i==d and count1<abs(b):\r\n# count1+=1\r\n# if i==e and count2<abs(c):\r\n# count2+=1\r\n# if check==(count1+count2):\r\n# print(q+1)\r\n# flag=0\r\n# break\r\n# q+=1\r\n# if flag:\r\n# print(\"-1\")\r\n\r\na=int(input())\r\nl=list(map(int,input().split()))\r\np=[0]*a\r\np[0]=l[0]\r\ns=[0]*a\r\ns[a-1]=l[a-1]\r\ni=1\r\nj=a-2\r\nwhile i<a and j>-1:\r\n p[i]=p[i-1]+l[i]\r\n s[j]=s[j+1]+l[j]\r\n i+=1\r\n j-=1\r\n# print(s)\r\n# print(p)\r\n\r\nx=0\r\ny=0\r\nfor i in range(a):\r\n if p[i]>s[i]:\r\n y+=1\r\n else:\r\n x+=1\r\nprint(x,y)", "n = int(input())\r\n\r\nnums = list(map(int, input().split()))\r\n\r\na = 0\r\nb = 0\r\n\r\nsa, sb = 0, 0\r\nleft, right = 0, n-1\r\n\r\nwhile left <= right:\r\n if sa <= sb:\r\n sa += nums[left]\r\n a += 1\r\n left += 1\r\n else:\r\n sb += nums[right]\r\n b += 1\r\n right -= 1\r\n\r\nprint(a, b)\r\n", "# link: https://codeforces.com/problemset/problem/6/C\r\n\r\n# example: 2 9 2 8 7\r\n# prefix : 2 11 13 21 28\r\n# sufix : 28 26 17 15 7\r\n# 2 2 2 2 2\r\n# 2 4 6 8 10\r\n# 10 8 6 4 2\r\nn = int(input())\r\na = list(map(int, input().split()))\r\np = [0] * n\r\ns = [0] * n\r\nfor i in range(n):\r\n if i == 0:\r\n p[i] = a[i]\r\n else:\r\n p[i] = a[i] + p[i-1] \r\nfor i in range(n-1, -1, -1):\r\n if i == n-1:\r\n s[i] = a[i]\r\n else:\r\n s[i] = a[i] + s[i+1] \r\n if s[i] == p[i]:\r\n print(i+1, n-i-1)\r\n exit(0)\r\nans = [0,0]\r\ngap = float('inf')\r\nfor i in range(n-1):\r\n if abs(p[i] - s[i+1]) < gap:\r\n gap = abs(p[i] - s[i+1]) \r\n ans[0] = i + 1\r\n ans[1] = n - i - 1\r\nprint(*ans) ", "n = int(input())\r\nts = [int(x) for x in input().split()]\r\nf, l = 0, n - 1\r\na, b = 0, 0\r\nbc = None\r\n\r\nwhile l - f >= 0:\r\n if l - f > 0:\r\n bc = False\r\n\r\n if ts[f] < ts[l]:\r\n ts[l] -= ts[f]\r\n a += 1\r\n f += 1\r\n bc = True\r\n elif ts[l] < ts[f]:\r\n ts[f] -= ts[l]\r\n b += 1\r\n l -= 1\r\n else:\r\n a += 1\r\n f += 1\r\n b += 1\r\n l -= 1\r\n else:\r\n if bc:\r\n b += 1\r\n else:\r\n a += 1\r\n\r\n l -= 1\r\n\r\nprint(a, b)", "n=int(input())\r\na=[int(x)for x in input().split()]\r\nl,r=0,n-1\r\nsl=sr=0\r\ncntl=cntr=0\r\nwhile n:\r\n if sl>sr:\r\n \tsr+=a[r];r-=1;cntr+=1\r\n else:\r\n \tsl+=a[l];l+=1;cntl+=1\r\n n-=1\r\n\r\nprint(cntl,cntr)", "n = int(input())\r\na = list(map(int, input().split()))\r\n \r\ni = 0\r\nj = n - 1\r\nm = a[i]\r\nk = a[j]\r\n \r\nif n == 1:\r\n print(1, 0)\r\nelif n == 2:\r\n print(1, 1)\r\nelse:\r\n while j - i != 1:\r\n if m <= k:\r\n i += 1\r\n m += a[i]\r\n elif m > k:\r\n j -= 1\r\n k += a[j]\r\n print(i + 1, n - j)", "n = int(input())\r\na = [int(_) for _ in input().split()]\r\nal = b = i = 0\r\nj = n-1\r\nwhile i <= j:\r\n if al <= b:\r\n al += a[i]\r\n i += 1\r\n else:\r\n b += a[j]\r\n j -= 1\r\nprint(i, n - i)\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nx,y,t,h=0,0,0,0\r\nl,r=0,n-1\r\nwhile(l<=r):\r\n if t<=h:\r\n t+=a[l]\r\n x,l=x+1,l+1\r\n else:\r\n h+=a[r]\r\n y,r=y+1,r-1\r\nprint(x,y)", "length = int(input())\r\narr = list(map(int, input().split()))\r\nif length == 1:\r\n print(1, 0)\r\n exit(0)\r\n\r\nalice_count, bob_count = 0, 0\r\nalice_total, bob_total = 0, 0\r\nalice_index, bob_index = 0, length - 1\r\nstep = 0\r\n\r\nwhile step < length:\r\n if step == 0:\r\n alice_count, bob_count = 1, 1\r\n alice_total, bob_total = arr[0], arr[~0]\r\n alice_index = alice_index + 1\r\n bob_index = bob_index - 1\r\n step = step + 2\r\n continue\r\n\r\n alice_value = arr[alice_index]\r\n bob_value = arr[bob_index]\r\n\r\n if alice_total < bob_total:\r\n alice_count += 1\r\n alice_index += 1\r\n alice_total += alice_value\r\n elif alice_total > bob_total:\r\n bob_count += 1\r\n bob_index -= 1\r\n bob_total += bob_value\r\n else:\r\n alice_count += 1\r\n alice_index += 1\r\n alice_total += alice_value\r\n\r\n step = step + 1\r\n\r\nprint(alice_count, bob_count)\r\n", "n = int(input())\r\nt = [int(i) for i in input().split()]\r\na = 0\r\nb = n-1\r\nta = 0\r\ntb = 0\r\nwhile a <= b:\r\n if tb < ta:\r\n tb += t[b]\r\n b -= 1\r\n else:\r\n ta += t[a]\r\n a += 1\r\nprint(str(a) + ' ' + str(n-a))\r\nexit(0)", "import sys\nnum = int(sys.stdin.readline())\ntimes = list(map(int,sys.stdin.readline().strip().split()))\nleft = 0\nright = num-1\ntime_left = 0\ntime_right = 0\n \n \n \nwhile left < right:\n time_left += times[left]\n left += 1\n while right >= 0 and time_right < time_left:\n time_right += times[right]\n right -= 1\n \n \nalice_eating = left + bool((left == right) and (time_left <= time_right))\nprint(alice_eating,num-alice_eating)\n \n \n\n# Test: #8, time: 186 ms., memory: 0 KB, exit code: 0, checker exit code: 1, verdict: WRONG_ANSWER\n# Input\n# 3\n# 6 8 4\n# Output\n# 2 1\n# Answer\n# 1 2\n# Checker Log\n# wrong answer 1st numbers differ - expected: '1', found: '2'", "n = int(input())\r\n\r\narr = list(map(int, input().split()))\r\n\r\ni = 0\r\nj = n - 1\r\nalice = 0\r\nbob = 0\r\ntotalTimeA = 0\r\ntotalTimeB = 0\r\n\r\nwhile i != j:\r\n if (totalTimeA <= totalTimeB):\r\n alice += 1\r\n totalTimeA += arr[i]\r\n i += 1\r\n else:\r\n bob += 1\r\n totalTimeB += arr[j]\r\n j -= 1\r\n \r\nif (totalTimeA <= totalTimeB):\r\n alice += 1\r\nelse:\r\n bob += 1\r\n\r\n\r\nprint(alice, bob)", "n = int(input())\narr = list(map(int, input().split()))\nl = [0] * n\nr = [0] * n\n\nfor i in range(1,n):\n l[i] = l[i-1] + arr[i-1]\nfor i in range(n-2,-1,-1):\n r[i] = r[i+1] + arr[i+1]\nw = 0\ni = 0\nwhile i < n:\n if l[i] <= r[i]:\n w += 1\n else:\n break\n i += 1\nprint(w, len(l) - w)\n\t \t\t \t\t \t\t\t\t\t \t\t \t \t\t\t \t \t", "# LUOGU_RID: 101908420\nn, *A = map(int, open(0).read().split())\r\na = b = l = t1 = t2 = 0\r\nr = n\r\nwhile l < r:\r\n if t1 + A[l] <= t2 + A[r - 1]:\r\n t1 += A[l]\r\n a += 1\r\n l += 1\r\n else:\r\n t2 += A[r - 1]\r\n b += 1\r\n r -= 1\r\nprint(a, b)", "n=int(input())\r\nt=list(map(int,input().split()))\r\nl,r=0,n-1\r\nwhile r-l>1:\r\n if t[l]<t[r]:\r\n t[r]=t[r]-t[l]\r\n l+=1\r\n elif t[l]>t[r]:\r\n t[l]=t[l]-t[r]\r\n r-=1\r\n elif r-l==2:\r\n l+=1\r\n else:\r\n l+=1\r\n r-=1\r\nprint(l+1,n-l-1)\r\n", "\r\nn=int(input())\r\nbars_time = list(map(int,input().split()))\r\npointer1 = 0\r\npointer2 = n - 1\r\n\r\nleft_sum = bars_time[0]\r\nright_sum = bars_time[pointer2]\r\nalice=0\r\nbob=0\r\n\r\nwhile pointer2 >= pointer1:\r\n \r\n if left_sum > right_sum:\r\n pointer2 -= 1\r\n right_sum += bars_time[pointer2]\r\n bob += 1\r\n elif left_sum < right_sum:\r\n pointer1 += 1\r\n left_sum += bars_time[pointer1]\r\n alice += 1\r\n else:\r\n if pointer1 == pointer2:\r\n alice += 1\r\n pointer1 += 1\r\n else:\r\n pointer1 += 1\r\n pointer2 -= 1\r\n right_sum += bars_time[pointer2]\r\n left_sum += bars_time[pointer1]\r\n alice += 1\r\n bob += 1\r\n\r\n \r\nprint(alice,bob)", "\"\"\"write your code in method solve\"\"\"\r\ndef solve():\r\n\r\n n=int(input())\r\n str_a=input()\r\n str_a.strip(' ')\r\n list_a=str_a.split(' ')\r\n list_b=[int(i) for i in list_a]\r\n\r\n sum_a=0\r\n sum_b=0\r\n i=0\r\n a=0\r\n b=0\r\n\r\n sum_a=sum(list_b)\r\n\r\n for i in range(n):\r\n sum_b+=list_b[i]\r\n if sum_b>sum_a/2:\r\n break\r\n\r\n if(sum(list_b[0:i])<=sum(list_b[i+1:n])):\r\n a=i+1\r\n b=n-i-1\r\n else:\r\n a=i\r\n b=n-i\r\n\r\n print(a,b)\r\n\r\n return\r\n\r\n\r\nif __name__==\"__main__\":\r\n solve()\r\n", "def main():\r\n\tfrom sys import stdin, stdout\r\n\r\n\t# stdin = open(\"input.txt\", \"r\")\r\n\r\n\tn = int(stdin.readline())\r\n\ttimes = list(map(int, stdin.readline().split()))\r\n\r\n\taliceSpend, bobSpend = 0, 0\r\n\taliceCnt, bobCnt = 0, 0\r\n\ti, j = 0, n-1\r\n\r\n\twhile(i <= j):\r\n\t\tif aliceSpend <= bobSpend:\r\n\t\t\taliceSpend += times[i]\r\n\t\t\taliceCnt += 1\r\n\t\t\ti += 1\r\n\t\telse:\r\n\t\t\tbobSpend += times[j]\r\n\t\t\tbobCnt += 1\r\n\t\t\tj -= 1\r\n\r\n\tstdout.write(''.join([str(aliceCnt), '\\n', str(bobCnt), '\\n']))\r\n\r\n\r\nif __name__ == '__main__':\r\n\tmain()", "n = int(input())\r\n\r\nchocolates = list(map(int, input().split()))\r\n\r\nif n == 1:\r\n print(1, 0)\r\n exit(0)\r\n\r\na = 0\r\nb = n - 1\r\nalice = 1\r\nbob = 1\r\n\r\nwhile a < b - 1:\r\n if chocolates[a] < chocolates[b]:\r\n chocolates[b] -= chocolates[a]\r\n a += 1\r\n alice += 1\r\n elif chocolates[b] < chocolates[a]:\r\n chocolates[a] -= chocolates[b]\r\n b -= 1\r\n bob += 1\r\n else:\r\n a += 1\r\n b -= 1\r\n if a != b:\r\n bob += 1\r\n alice += 1\r\n\r\nprint(alice, bob)", "\ndef input_data():\n n = int(input().strip())\n chok = list(map(int, input().strip().split()))\n return n, chok\n\n\ndef solve_prob(n, chok):\n i, j = 0, n-1\n occupy = [-1] * n\n occupy[n-1] = 0 # bob\n occupy[0] = 1 # alice\n\n while i < j:\n if chok[i] < chok[j]:\n chok[i], chok[j] = 0, chok[j]-chok[i]\n i, j = i+1, j\n if occupy[i] < 0:\n occupy[i] = 1 # alice\n elif chok[i] == chok[j]:\n chok[i], chok[j] = 0, 0\n i, j = i+1, j-1\n occupy[j] = 0 # bob\n occupy[i] = 1 # alice\n else:\n chok[i], chok[j] = chok[i]-chok[j], 0\n i, j = i, j-1\n if occupy[j] < 0:\n occupy[j] = 0 # bob\n\n alice, bob = 0, 0\n for i in range(n):\n if occupy[i] == 1:\n alice += 1\n else:\n bob += 1\n print(alice, bob)\n\n\nif __name__ == \"__main__\":\n n, chok = input_data()\n solve_prob(n, chok)\n", "n=int(input())\r\nt=list(map(int,input().split()))\r\na=0\r\nb=n-1\r\nalice=0\r\nbob=0\r\nsalice=0\r\nsbob=0\r\nif a==b : \r\n alice+=1 \r\nelse : \r\n while (a<b) : \r\n if sbob==salice : \r\n sbob+=t[b] ; bob+=1 ;b-=1\r\n salice+=t[a] ; alice+=1 ; a+=1 \r\n elif sbob>salice : \r\n salice+=t[a] ; alice+=1 ;a+=1 \r\n else : \r\n sbob+=t[b] ; bob+=1 ; b-=1 \r\n if a==b : \r\n if salice>sbob : bob+=1 \r\n else : alice+=1 \r\n '''while salice>sbob : \r\n sbob+=t[b] \r\n while (salice+t[a]<=sbob) and (a<b) : \r\n salice+=t[a] \r\n a=a+1 \r\n alice+=1\r\n if (salice+t[a]>sbob) and (salice<sbob) : \r\n salice+=t[a] ; a=a+1 ; alice+=1 \r\n b=b-1\r\n bob+=1 \r\n if (sbob+t[b]>salice ) and (sbob<salice): \r\n sbob+=t[b] ; b=b-1 ; bob+=1 ; \r\n while sbob>salice : \r\n salice+=t[a] \r\n while (sbob+t[b]<=salice) and (a<b): \r\n sbob+=t[b] \r\n b=b-1\r\n bob=bob+1 \r\n if (sbob+t[b]>salice ) and (sbob<salice): \r\n sbob+=t[b] ; b=b-1 ; bob+=1 ; \r\n a=a+1 \r\n alice+=1 \r\n if (salice+t[a]>sbob) and (salice<sbob) : \r\n salice+=t[a] ; a=a+1 ; alice+=1 \r\n if (sbob==salice) and (a<b): \r\n sbob+=t[b]\r\n salice+=t[a]\r\n a=a+1 \r\n b=b-1 \r\n bob+=1 \r\n alice+=1 \r\n if a==b :\r\n if salice>sbob: bob+=1 \r\n elif sbob>=salice : alice+=1'''\r\nprint (alice,bob) \r\n", "n=int(input())\r\nlst=[*map(int,input().split())]\r\ni,j=0,n-1\r\nwhile i+1<j:\r\n if lst[i]<lst[j]:\r\n lst[j]-=lst[i]\r\n lst[i]=0\r\n i+=1\r\n elif lst[i]>lst[j]:\r\n lst[i]-=lst[j]\r\n lst[j]=0\r\n j-=1\r\n else:\r\n lst[i]=0\r\n lst[j]=0\r\n i+=1;j-=1\r\ni+=1;j+=1\r\nif i==j:j+=1\r\nprint(i,n-j+1)", "n = int(input())\narr = list(map(int, input().split()))\n\n# half = sum(arr) / 2\nidx1 = 0\nidx2 = n - 1\nwhile True:\n if arr[idx1] <= arr[idx2]:\n if idx1 + 1 >= idx2:\n break\n arr[idx2] -= arr[idx1]\n idx1 += 1\n else:\n if idx2 - 1 <= idx1:\n break\n arr[idx1] -= arr[idx2]\n idx2 -= 1\n\nprint(idx1 + 1, n - (idx1 + 1))", "n = int(input())\narr=list(map(int,input().split()))\n\nprefix = [0 for i in range(n)]\npostfix = [0 for i in range(n)]\nprefix[0]=arr[0]\nfor i in range(1,n):\n prefix[i] = arr[i]+prefix[i-1]\n\npostfix[-1]=arr[-1]\nfor i in range(n-2,-1,-1):\n postfix[i]=postfix[i+1]+arr[i]\n\ni=0\nj=n-1\nalice = 0\nbob=0\nwhile i<=j:\n if prefix[i]<=postfix[j]:\n alice+=1\n i+=1\n else:\n bob+=1\n j-=1\nprint (str(alice)+' '+str(bob))\n", "n=int(input());\r\nt=[int(x) for x in input().split()];\r\n\r\nk=sum(t)//2;\r\nq=0;\r\ni=0;\r\nwhile 1:\r\n if q+t[i]>k:\r\n break;\r\n q+=t[i];\r\n i+=1;\r\nr=sum(t)-q-t[i];\r\nif q<=r:\r\n a=i+1;\r\nelse:\r\n a=i;\r\nb=n-a;\r\nprint(a,b);\r\n\r\n \r\n \r\n", "\ndef main():\n\t##############\n\tn = int(input())\n\tline = input() ######################\n\ttokens = line.split()\n\tnums = [int(t) for t in tokens]\n\t########################\n\talice = 0\n\tbob = 0\n\tsum_time = 0\n\tfor i in range(n):\n\t\tsum_time += nums[i]\n\thalf = sum_time/2\n\tsum_new = 0\n\tsum_old = 0\n\thalf_index = 0\n\tfor i in range(n):\n\t\tsum_new += nums[i]\n\t\tif sum_new > half:\n\t\t\thalf_index = i\n\t\t\tbreak\n\t\tsum_old = sum_new\n\tif sum_old > sum_time - sum_new: ##if alice reach mid > bob reach mid\n\t\talice = half_index\n\t\tbob = n-half_index\n\telif sum_old <= sum_time - sum_new:\n\t\talice = half_index+1\n\t\tbob = n-half_index-1\n\tprint(str(alice)+' '+str(bob))\nmain()\n\n\t \t \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\nl1 = []\nl2 = []\ns1, s2 = 0, 0\n\nfor i in range(0, len(arr)):\n l1.append(s1)\n s1 += arr[i]\nfor j in range(len(arr) - 1, -1, -1):\n l2.append(s2)\n s2 += arr[j]\nl2 = l2[::-1]\n\ncl, cr = 0, 0\n\nfor i in range(len(arr)):\n if l1[i] <= l2[i]:\n cl += 1 \n else:\n cr += 1\nprint(cl, cr)\n \t \t \t\t \t \t\t\t \t\t\t \t \t", "from collections import deque\r\n\r\nn=int(input())\r\nX=deque(map(int,input().split()))\r\n\r\nA=0\r\nB=0\r\n\r\nwhile X:\r\n #print(X,A,B)\r\n if X[0]<=X[-1]:\r\n A+=1\r\n X[-1]-=X[0]\r\n X.popleft()\r\n if len(X)==1:\r\n B+=1\r\n break\r\n else:\r\n B+=1\r\n X[0]-=X[-1]\r\n X.pop()\r\n if len(X)==1:\r\n A+=1\r\n break\r\n\r\n if len(X)==3 and X[0]==X[-1]:\r\n A+=2\r\n B+=1\r\n break\r\n\r\nprint(A,B)\r\n \r\n\r\n\r\n\r\n", "n = int(input())\r\na = [int(i) for i in input().split()]\r\nl = 0\r\nr = n - 1\r\nflagleft = False\r\nwhile l < r - 1:\r\n a[l] -= 1\r\n a[r] -= 1\r\n if a[l] == 0:\r\n l += 1\r\n if a[r] == 0:\r\n r -= 1\r\nif l == r:\r\n r +=1\r\nprint(l + 1 ,n - r)", "n = int(input())\r\na = list(map(int, input().split()))\r\ni, j = 0, n-1\r\nm = 0\r\nwhile i <= j:\r\n if m >= 0:\r\n m -= a[i]\r\n i += 1\r\n else:\r\n m += a[j]\r\n j -= 1\r\nprint(i, n-i)\r\n ", "def main():\r\n\tn = int(input())\r\n\tchocs = input().split()\r\n\tchocs = [int(x) for x in chocs]\r\n\t(a, b) = calculate(chocs)\r\n\tprint(str(a) + \" \" + str(b))\r\n\r\n# returns (a, b), number of chocolates eaten by alice and bob\r\ndef calculate(l):\r\n\tn = len(l)\r\n\taIndex = 0\r\n\tbIndex = n - 1\r\n\tif n == 1:\r\n\t\treturn (1, 0)\r\n\telse:\r\n\t\twhile True:\r\n\t\t\taPart = l[aIndex]\r\n\t\t\tbPart = l[bIndex]\r\n\t\t\tif aPart < bPart:\r\n\t\t\t\tl[bIndex] -= aPart\r\n\t\t\t\tl[aIndex] = 0\r\n\t\t\t\taIndex += 1\r\n\t\t\t\tif aIndex + 1 == bIndex:\r\n\t\t\t\t\treturn (aIndex + 1, n - aIndex - 1)\r\n\t\t\telif aPart > bPart:\r\n\t\t\t\tl[aIndex] -= bPart\r\n\t\t\t\tl[bIndex] = 0\r\n\t\t\t\tbIndex -= 1\r\n\t\t\t\tif aIndex + 1 == bIndex:\r\n\t\t\t\t\treturn (aIndex + 1, n - aIndex - 1)\r\n\t\t\telse:\r\n\t\t\t\tl[aIndex] = 0\r\n\t\t\t\tl[bIndex] = 0\r\n\t\t\t\taIndex += 1\r\n\t\t\t\tbIndex -= 1\r\n\t\t\t\tif aIndex == bIndex:\r\n\t\t\t\t\treturn (aIndex + 1, n - aIndex - 1)\r\n\t\t\t\telif aIndex > bIndex:\r\n\t\t\t\t\treturn (aIndex, n - aIndex)\r\n\r\nmain()\r\n#print(calculate([2, 9, 8, 2, 7]))\r\n#print(calculate([7, 2, 8, 9, 2]))\r\n#print(calculate([8, 2, 8]))\r\n#", "n = input()\r\nn = int(n.strip())\r\n\r\nt = input()\r\nt = list(map(int, t.strip().split(' ')))\r\n\r\njedel_a = 0\r\njedel_b = 0\r\n\r\ncas_a = 0\r\ncas_b = 0\r\n\r\ni = 0\r\nj = len(t) - 1\r\n\r\nwhile i <= j:\r\n if cas_a <= cas_b:\r\n cas_a += t[i]\r\n jedel_a += 1\r\n i = i + 1\r\n else:\r\n cas_b += t[j]\r\n jedel_b += 1\r\n j -= 1\r\nprint(jedel_a, jedel_b)\r\n", "n=int(input())\r\nar=list(map(int,input().split(' ')))\r\ntime=0\r\ntotal=sum(ar)\r\ns=0\r\nif(n==1):\r\n print(\"1 0\")\r\nelif(n==2):\r\n print(\"1 1\")\r\nelse:\r\n for i in range(n):\r\n s+=ar[i]\r\n if(total-s<s-ar[i] and total-(s-ar[i])>s-ar[i]-ar[i-1]):\r\n print(str(i)+' '+str(n-i))\r\n break\r\n if(total-s>s-ar[i] and total-(s+ar[i+1])<s):\r\n print(str(i+1)+' '+str(n-(i+1)))\r\n break\r\n if(total-s==s-ar[i]):\r\n print(str(i+1)+' '+str(n-(i+1)))\r\n break\r\n\r\n \r\n \r\n", "import sys\nn = int(sys.stdin.readline())\nchocolates = list(map(int, sys.stdin.readline().split()))\n\na, b = -1, n\na_sum, b_sum = 0, 0\n\nwhile a < b-1:\n if a_sum <= b_sum:\n a += 1\n a_sum += chocolates[a]\n else:\n b -= 1\n b_sum += chocolates[b]\n\nprint(a+1,n-a-1)\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nw = list(map(int, input().split()))\r\ni, j = 0, n-1\r\nl = r = 0\r\n\r\nwhile i <= j:\r\n if l <= r:\r\n l += w[i]\r\n i += 1\r\n else:\r\n r += w[j]\r\n j -= 1\r\n\r\nprint(i, n-i)\r\n", "n = int(input())\r\nl = list(map(int, input().split(\" \")))\r\n\r\ns = sum(l)\r\n\r\nj = -1\r\nx = s // 2\r\ncountA = 0\r\nfor i in range(n):\r\n if(l[i] <= x):\r\n countA += 1\r\n x -= l[i]\r\n else:\r\n j = i\r\n break\r\nt = sum(l[:j])\r\nu = sum(l[j + 1:])\r\n\r\nif(t <= u):\r\n print(j + 1, n - j - 1)\r\nelse:\r\n print(j, n - j)\r\n\r\n", "def arr_inp():\r\n return [int(x) for x in input().split()]\r\n\r\n\r\nn, t = int(input()), arr_inp()\r\na, b, alice, bob = 0, 0, 0, n - 1\r\nt2 = t.copy()\r\n\r\nwhile (alice < bob):\r\n if t[alice] < t[bob]:\r\n t[bob] -= t[alice]\r\n alice += 1\r\n a += 1\r\n\r\n elif t[alice] > t[bob]:\r\n t[alice] -= t[bob]\r\n bob -= 1\r\n b += 1\r\n else:\r\n a += 1\r\n b += 1\r\n alice += 1\r\n bob -= 1\r\n\r\nif alice == bob:\r\n if sum(t2[:alice]) <= sum(t2[bob + 1:]):\r\n a += 1\r\n else:\r\n b += 1\r\n\r\nprint(a, b)\r\n\r\n", "\r\n\r\n\r\ndef main_function():\r\n input()\r\n t = [int(i) for i in input().split(\" \")]\r\n i = -1\r\n j = len(t)\r\n count_i = 0\r\n coun_j = 0\r\n while True:\r\n if j - i <= 1:\r\n break\r\n else:\r\n if count_i <= coun_j:\r\n i += 1\r\n count_i += t[i]\r\n else:\r\n j -= 1\r\n coun_j += t[j]\r\n # print(count_i)\r\n # print(coun_j)\r\n\r\n print(i + 1, len(t) - i - 1)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nmain_function()", "import math\r\nfrom decimal import *\r\n\r\ndef produs_cifre(numar):\r\n \r\n produs=1\r\n for i in numar:\r\n produs=produs*int(i)\r\n return (produs)\r\n \r\n#def prime_generator(nr_elemente_prime):\r\n \r\n #vector_prime=[-1]*nr_elemente_prime\r\n #vector_rasp=[0]*nr_elemente_prime\r\n \r\n #vector_prime[1]=1\r\n \r\n #vector_rasp[1]=1\r\n#primes sieve \r\n #contor=2\r\n \r\n #for i in range(2,nr_elemente_prime):\r\n # if vector_prime[i]==-1:\r\n # vector_prime[i]=1\r\n # vector_rasp[contor]=i\r\n # contor=contor+1\r\n # for j in range(i+i,nr_elemente_prime,i):\r\n # if vector_prime[j]==-1:\r\n # vector_prime[j]=i\r\n #print(i,j) \r\n \r\n# my_set=set(vector_rasp)\r\n #my_set.remove(0)\r\n #my_set.remove(1)\r\n \r\n #lista_prime=list(my_set)\r\n #lista_prime.sort()\r\n #return my_set\r\n\r\n\r\ndef functie(nodul,vectorul,cate,culori,vizitat):\r\n #print(noi_culori)\r\n if vizitat[nodul]==0:\r\n vizitat[nodul]=1\r\n \r\n \r\n if culori[nodul-1]!=noi_culori[nodul-1]:\r\n #print(nodul)\r\n cate[0]=1+cate[0]\r\n noi_culori[nodul-1]=culori[nodul-1]\r\n \r\n \r\n for j in vectorul[nodul]:\r\n if vizitat[j]==0:\r\n noi_culori[j-1]=culori[nodul-1]\r\n functie(j,vectorul,cate,culori,vizitat)\r\n \r\n return(sum(cate))\r\n\r\n\r\n\r\n#z=int(input())\r\nfor contor in range(0,1):\r\n #n,kpr\r\n n=int(input())\r\n #n,m=list(map(int,input().split()))\r\n lista=list(map(int,input().split()))\r\n \r\n if n==1:\r\n print(\"1 0\")\r\n elif n==2:\r\n print(\"1 1\")\r\n else: \r\n cate_a=1\r\n cate_b=1\r\n \r\n poz_a=0\r\n poz_b=n-1\r\n \r\n suma_a=lista[0]\r\n suma_b=lista[n-1]\r\n \r\n while poz_a+1<poz_b:\r\n if suma_a<suma_b:\r\n poz_a+=1\r\n suma_a+=lista[poz_a]\r\n cate_a+=1\r\n \r\n elif suma_a>suma_b:\r\n poz_b-=1\r\n suma_b+=lista[poz_b]\r\n cate_b+=1\r\n \r\n else:\r\n if poz_a+1==poz_b-1:\r\n poz_a+=1\r\n suma_a+=lista[poz_a]\r\n cate_a+=1\r\n else: \r\n poz_a+=1\r\n suma_a+=lista[poz_a]\r\n poz_b-=1\r\n suma_b+=lista[poz_b]\r\n cate_a+=1\r\n cate_b+=1\r\n \r\n #print(poz_a,poz_b,cate_a,cate_b, suma_a,suma_b)\r\n print(cate_a,cate_b)\r\n ", "def get_answer(pies):\r\n eating_time_up_to_N_k = [0]\r\n eating_time_up_to_N_p = []\r\n\r\n for pie in pies:\r\n eating_time_up_to_N_k.append(eating_time_up_to_N_k[-1] + pie)\r\n\r\n for time in eating_time_up_to_N_k:\r\n eating_time_up_to_N_p.append(eating_time_up_to_N_k[-1] - time)\r\n\r\n for i in range(1, len(pies) + 1):\r\n if eating_time_up_to_N_k[i - 1] == eating_time_up_to_N_p[i]:\r\n return f\"{i} {len(pies) - i}\"\r\n\r\n if abs(eating_time_up_to_N_k[i - 1] - eating_time_up_to_N_p[i]) <= pies[i - 1]:\r\n if eating_time_up_to_N_k[i - 1] < eating_time_up_to_N_p[i]:\r\n return f\"{i} {len(pies) - i}\"\r\n else:\r\n return f\"{i - 1} {len(pies) - i + 1}\"\r\n\r\n\r\ndef main():\r\n _ = input()\r\n data = list(map(int, input().split()))\r\n\r\n answer = get_answer(data)\r\n\r\n print(answer)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n = int(input())\r\nt = list(map(int, input().split()))\r\n\r\ni = 0\r\nj = n - 1\r\nsumA =t[0]\r\nsumB = t[n-1]\r\ncountA = 0\r\ncountB = 0\r\nif n == 1:\r\n countA += 1\r\nelse:\r\n while i <= j:\r\n if sumA <= sumB:\r\n i += 1\r\n sumA += t[i]\r\n countA += 1\r\n else:\r\n j -= 1\r\n sumB += t[j]\r\n countB += 1\r\n\r\nprint(countA, countB)\r\n\r\n\r\n", "import abc\r\nimport 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 = int(input())\r\n t = list(map(int, input().split()))\r\n\r\n d = [[0], [0]]\r\n for i in range(n):\r\n d[0].append(d[0][-1] + t[i])\r\n d[1].append(d[1][-1] + t[n - 1 - i])\r\n\r\n for i in range(1, n + 1):\r\n if d[0][i] <= d[1][-i]:\r\n pass\r\n else:\r\n print(i - 1, n - i + 1)\r\n return\r\n\r\n print(n, 0)\r\n\r\n\r\nif __name__ == '__main__':\r\n multi_test = 0\r\n\r\n if multi_test == 1:\r\n t = int(sys.stdin.readline())\r\n for _ in range(t):\r\n solve()\r\n else:\r\n solve()\r\n", "n = int(input())\r\nbars = list(map(int, input().split()))\r\nta = 0\r\ntb = 0\r\na = 0\r\nb = 0\r\nfor cont in range(0,n):\r\n if ta <= tb:\r\n ta += bars[a]\r\n a += 1\r\n else:\r\n tb += bars[-b-1]\r\n b += 1\r\nprint(a, b)", "n=int(input())\r\nnums=list(map(int,input().split()))\r\nalphonse=[nums[-1]]\r\nfor i in range(len(nums)-2,-1,-1):\r\n alphonse.append(alphonse[-1]+nums[i])\r\nedward=[nums[0]]\r\nfor i in range(1,len(nums)):\r\n edward.append(edward[-1]+nums[i])\r\nedCount=0\r\nalCount=0\r\nal=0\r\ned=0\r\nwhile alCount+edCount<n:\r\n if edward[ed]>alphonse[al]:\r\n alCount+=1\r\n al+=1\r\n else:\r\n \r\n edCount+=1\r\n ed+=1\r\n \r\n\r\n\r\n\r\n\r\nprint(edCount,alCount)", "def main():\r\n n = int(input())\r\n \r\n t = list(map(int, input().split()))\r\n edward, alphonse = 0, 0\r\n left, right = 0, n - 1\r\n \r\n while (left <= right):\r\n if edward <= alphonse:\r\n edward += t[left]\r\n left += 1\r\n else:\r\n alphonse += t[right]\r\n right -= 1\r\n \r\n print(left, n - right - 1)\r\n \r\nmain()", "f, l = 0, int(input()) - 1\r\nts = [int(x) for x in input().split()]\r\na, b, bc = 0, 0, False\r\n\r\nwhile l - f > 0:\r\n if ts[f] < ts[l]:\r\n ts[l], a, f, bc = ts[l] - ts[f], a + 1, f + 1, True\r\n elif ts[l] < ts[f]:\r\n ts[f], b, l, bc = ts[f] - ts[l], b + 1, l - 1, False\r\n else:\r\n a, f, b, l, bc = a + 1, f + 1, b + 1, l - 1, False\r\n\r\nif l - f == 0:\r\n if bc:\r\n b += 1\r\n else:\r\n a += 1\r\n\r\nprint(a, b)", "n = int(input())\r\nt = list(map(int, input().split()))\r\n\r\na = b = 0\r\nta = tb = 0\r\ni = 0\r\nj = n - 1\r\n\r\nwhile i <= j:\r\n if ta <= tb:\r\n ta += t[i]\r\n i += 1\r\n else:\r\n tb += t[j]\r\n j -= 1\r\n\r\nprint(i, n - i)", "n=int(input())\r\nl1=list(map(int,input().split()))\r\n\r\npre=[0]*n\r\nsuf=[0]*n\r\n\r\nfor i in range(n):\r\n if(i==0):\r\n pre[i]=l1[i]\r\n else:\r\n pre[i]=pre[i-1]+l1[i]\r\n \r\nfor i in range(n-1,-1,-1):\r\n if(i==(n-1)):\r\n suf[i]=l1[i]\r\n else:\r\n suf[i]=suf[i+1]+l1[i]\r\n \r\n\r\nalice=0\r\nbob=0\r\nfor i in range(n):\r\n if(pre[i]<=suf[i]):\r\n alice+=1\r\n else:\r\n bob+=1\r\n \r\nprint(alice,bob)\r\n\r\n ", "n = int(input())\r\n\r\narray = list(map(int, input().split(' ')))\r\n\r\nleft, right = 1, n-1\r\nbob = 0\r\nalice = array[0]\r\nalice_ans = 1\r\nbob_ans = 0\r\n\r\nwhile left <= right:\r\n \r\n if alice <= bob:\r\n alice += array[left]\r\n alice_ans = left + 1\r\n left += 1\r\n \r\n else:\r\n bob += array[right]\r\n bob_ans = n - right\r\n right -= 1\r\n\r\n\r\nprint(alice_ans, bob_ans)", "n=int(input())\r\np=[int(x) for x in input().split()]\r\ns=sum(p)\r\nt=0\r\ne=0\r\nif n==1:\r\n print(1,0)\r\nelse:\r\n\r\n for i in range (0,n):\r\n t=t+p[i]\r\n if t<s/2 and t+p[i+1]>=s/2:\r\n e=i\r\n break\r\n if s/2-t<t+p[e+1]-s/2:\r\n print(e+1,n-e-1)\r\n else:\r\n print(e+2,n-e-2)", "n = int(input())\r\ntimes = list(map(int, input().split()))\r\nlpos, rpos = 0, len(times) - 1\r\nltime, rtime = 0, 0\r\nlcounter, rcounter = 0, 0\r\nwhile lpos <= rpos:\r\n if ltime < rtime:\r\n ltime += times[lpos]\r\n lpos += 1\r\n lcounter += 1\r\n elif ltime > rtime:\r\n rtime += times[rpos]\r\n rpos -= 1\r\n rcounter += 1\r\n else:\r\n ltime += times[lpos]\r\n lcounter += 1\r\n if lpos != rpos:\r\n rtime += times[rpos]\r\n rcounter += 1\r\n lpos += 1\r\n rpos -= 1\r\nprint(lcounter, rcounter)\r\n", "lines = int(input().split('\\n')[0])\r\ninputbars = input().split()\r\n\r\nif lines == 1:\r\n print(1, 0)\r\nelif lines == 2:\r\n print(1, 1)\r\nelse:\r\n bars = []\r\n for item in inputbars:\r\n item = int(item)\r\n bars.append(item)\r\n \r\n i = 0\r\n j = -1\r\n num1 = bars[0]\r\n num2 = bars[-1]\r\n \r\n # 除去最后一次 \r\n while(i+abs(j)+2< len(bars)): \r\n if num1 < num2:\r\n i = i+1\r\n num1 = num1+bars[i]\r\n elif num1 > num2:\r\n j = j-1\r\n num2 = num2+bars[j]\r\n else:\r\n i = i+1\r\n j = j-1\r\n num1 = num1+bars[i]\r\n num2 = num2+bars[j]\r\n # print(i)\r\n # print(abs(j))\r\n # print('---')\r\n \r\n \r\n # 最后一次 相等是绅士的回合 \r\n if i+abs(j)+1 >= len(bars): # 没有最后一次 \r\n print(i+1,abs(j))\r\n else:\r\n if num1 <= num2:\r\n i = i+1\r\n num1 = num1+bars[i]\r\n else:\r\n j = j-1\r\n num2 = num2+bars[j]\r\n \r\n print(i+1,abs(j))\r\n\r\n", "def Main():\r\n N = int(input())\r\n A = list(map(int,input().split()))\r\n sm1 = 0; sm2 = 0; cnt1 = 0; cnt2 = 0;\r\n lft = 0;\r\n rgt = N-1;\r\n\r\n while(lft <= rgt):\r\n if sm1 <= sm2:\r\n cnt1 += 1\r\n sm1 += A[lft]\r\n lft += 1\r\n else:\r\n cnt2 += 1\r\n sm2 += A[rgt]\r\n rgt -=1\r\n\r\n print(cnt1, cnt2)\r\n\r\nif __name__ == '__main__':\r\n Main()", "n=int(input())\r\na=list(map(int,input().split()))\r\nlow=0\r\nhigh=n-1\r\nsum_l=a[low]\r\nsum_h=a[high]\r\nwhile low<=high:\r\n if sum_l<=sum_h:\r\n low+=1\r\n if low<=n-1:\r\n sum_l+=a[low]\r\n else:\r\n high-=1\r\n if high>=0:\r\n sum_h+=a[high]\r\n\r\nprint(low,n-high-1)", "n=int(input())\r\nA=[int(x) for x in input().split()]\r\nif n==1:\r\n print('1 0')\r\n exit()\r\nif n==2:\r\n print('1 1')\r\n exit()\r\ns,p=[A[0]],[A[-1]]\r\nfor i in range(1,n):\r\n s.append(s[-1]+A[i])\r\n\r\nfor i in range(n-2,-1,-1):\r\n p.append(p[-1]+A[i])\r\n\r\ni1,j1=0,0\r\nfor i in range(n):\r\n if s[i]>s[-1]//2:\r\n i1=i\r\n break\r\nfor j in range(n):\r\n if p[j]>p[-1]//2:\r\n j1=j\r\n break\r\n\r\nif i1==0:\r\n i1+=1\r\n j1-=1\r\nelif j1==0:\r\n j1+=1\r\n i1-=1\r\n\r\nif i1+j1==n:\r\n print(i1,j1)\r\n exit()\r\nelif s[i1-1]==p[j1-1]:\r\n i1+=1\r\nelif s[i1-1]<p[j1-1]:\r\n i1+=1\r\nelse:\r\n j1+=1\r\n\r\nprint(i1,j1)\r\n", "# LUOGU_RID: 98916446\na=int(input())\r\nlst=list(map(int,input().split()))\r\ntl,tr=0,0\r\ncl,cr=0,0\r\nl,r=0,a-1\r\nwhile l<=r:\r\n if(tl<=tr):\r\n tl = tl + lst[l]\r\n cl=cl+1\r\n l=l+1\r\n else:\r\n tr = tr + lst[r]\r\n cr=cr+1\r\n r=r-1\r\nprint(cl,cr)", "n = int(input())\nC = [int(x) for x in input().split(\" \")]\nA = 0\nB = n - 1\nsum_A = 0 \nsum_B = 0\nans = 0\nwhile( A <= B) :\n if(sum_A <= sum_B):\n sum_A += C[A]\n A += 1\n ans += 1\n else :\n sum_B += C[B]\n B -= 1\nprint(str(ans) + \" \" + str(n-ans) )\n\n\t\t\t\t\t \t\t\t \t \t \t\t \t \t\t \t \t", "n=int(input())\r\nif n==1:\r\n print(1,0)\r\nelif n==2:\r\n print(1,1)\r\nelse:\r\n lst=list(map(int,input().split()))\r\n i=1\r\n j=n-2\r\n A=lst[0]\r\n B=lst[n-1]\r\n SA=1\r\n SB=1\r\n while(i<=j):\r\n if (A<=B):\r\n SA+=1\r\n A+=lst[i]\r\n i+=1\r\n else:\r\n SB+=1\r\n B+=lst[j]\r\n j-=1\r\n print(SA,SB)", "n = int(input())\r\ntemp = list(map(int, input().split()))\r\ns = sum(temp)\r\nalice = s/2\r\ncnt = 0\r\nfor i in range(n):\r\n if alice > 0:\r\n cnt += 1\r\n alice -= temp[i]\r\n else:\r\n if s - 2 * sum(temp[:i-1]) < temp[i-1]:\r\n cnt -= 1\r\n break\r\n else:\r\n break\r\nbob = n - cnt\r\nprint(str(cnt)+' '+str(bob))\r\n", "na=int(input())\r\n*l,=map(int,input().split())\r\naa=b=i=0\r\nj=na-1\r\nwhile i<=j:\r\n if aa<=b:aa+=l[i];i+=1\r\n else:b+=l[j];j-=1\r\nprint(i,na-i)", "# LUOGU_RID: 98916371\nn=int(input())\r\nl=list(map(int,input().split()))\r\nlt,rt=0,n-1\r\ntl,tr=0,0\r\ncl,cr=0,0\r\nwhile lt<=rt:\r\n\r\n if tl<=tr:\r\n tl += l[lt]\r\n cl+=1\r\n lt+=1\r\n else:\r\n tr += l[rt]\r\n cr+=1\r\n rt-=1\r\nprint(cl,cr)" ]
{"inputs": ["5\n2 9 8 2 7", "1\n1", "2\n1 1", "3\n1 1 1", "4\n1 1 1 1", "1\n6", "2\n8 2", "3\n6 8 4", "4\n4 3 2 8", "5\n1 9 8 2 7", "6\n1 4 7 3 2 1", "11\n7 9 1 8 7 1 7 1 4 8 1", "12\n4 2 7 1 9 5 6 2 7 8 5 7", "13\n9 9 9 9 9 9 9 9 9 9 9 9 9"], "outputs": ["2 3", "1 0", "1 1", "2 1", "2 2", "1 0", "1 1", "1 2", "3 1", "2 3", "3 3", "4 7", "7 5", "7 6"]}
UNKNOWN
PYTHON3
CODEFORCES
138
16344fb7e2bc83409f14ef3f666a983c
King's Problem?
Every true king during his life must conquer the world, hold the Codeforces world finals, win pink panda in the shooting gallery and travel all over his kingdom. King Copa has already done the first three things. Now he just needs to travel all over the kingdom. The kingdom is an infinite plane with Cartesian coordinate system on it. Every city is a point on this plane. There are *n* cities in the kingdom at points with coordinates (*x*1,<=0),<=(*x*2,<=0),<=...,<=(*x**n*,<=0), and there is one city at point (*x**n*<=+<=1,<=*y**n*<=+<=1). King starts his journey in the city number *k*. Your task is to find such route for the king, which visits all cities (in any order) and has minimum possible length. It is allowed to visit a city twice. The king can end his journey in any city. Between any pair of cities there is a direct road with length equal to the distance between the corresponding points. No two cities may be located at the same point. The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=*n*<=+<=1) — amount of cities and index of the starting city. The second line contains *n*<=+<=1 numbers *x**i*. The third line contains *y**n*<=+<=1. All coordinates are integers and do not exceed 106 by absolute value. No two cities coincide. Output the minimum possible length of the journey. Your answer must have relative or absolute error less than 10<=-<=6. Sample Input 3 1 0 1 2 1 1 3 1 1 0 2 1 1 4 5 0 5 -1 -5 2 3 Sample Output 3.414213562373094900003.8284271247461903000014.24264068711928400000
[ "from math import hypot, inf\n\n# input\nn, k = map(int, input().split())\ncities = list(map(int, input().split()))\ny_y = int(input())\n\n# input\n# n, k = 4, 1\n# cities = [0, 5, -1, -5, 2]\n# y_y = 3\n\nk = k - 1\nk_x = cities[k]\ncit = [cities[-1], y_y]\ncities.remove(cities[-1])\nans = inf\n\n# Calculo de la distancia entre la ciudad x-esima y la ciudad externa\ndef dist(x):\n return hypot(cities[x] - cit[0], cit[1])\n\n\n# Distancia optima entre los extremos y la ciudad exterior\ndef solve(l, r):\n if l > r:\n return 0\n return min(dist(l), dist(r)) + cities[r] - cities[l]\n\n\ndef solve_k(l, r):\n a = abs(k_x - cities[l])\n b = abs(k_x - cities[r])\n return min(2 * a + b + dist(r), a + 2 * b + dist(l))\n\n \n# Caso donde la ciudad inicial es la exterior\nif k == n:\n cities.sort()\n ans =(min(dist(0), dist(n - 1)) + cities[-1] - cities[0])\n\nelse:\n cities.sort()\n k = cities.index(k_x) # Indice de la ciudad k luego de ordenar\n\n for i in range(n):\n if i <= k:\n t = solve(0, i - 1) + solve_k(i, n - 1)\n ans = min(ans, t)\n if i >= k:\n t = solve_k(0, i) + solve(i+1 , n - 1)\n ans = min(ans, t)\n\nprint(ans)\n", "from bisect import *\nn,k=map(int,input().split())\nx=[*map(int,input().split())]\nny=int(input())\nnx,a,s=x[-1],x[k-1],10**8\ndel x[-1]\nx.sort()\nx=[x[0]]+x+[x[-1]]\ndef h(b):\n if b in [len(x)-1,0,-1]:\n return 0\n return ((nx-x[b])**2+ny**2)**.5\nif k-1==n:\n print(x[-1]-x[0]+min(h(-2),h(1)))\n exit()\nk=bisect(x,a)-1\nfor i in range(1,len(x)-1):\n if i<=k:\n s=min(s,min(x[-2]-x[k]+h(i),x[k]-x[i]+h(-2))+x[-2]-x[i]+h(i-1)+x[i-1]-x[1])\n if k<=i:\n s=min(s,min(x[k]-x[1]+h(i),x[i]-x[k]+h(1))+x[i]-x[1]+h(i+1)+x[-2]-x[i+1])\nprint(s)\n\n", "import sys\n\n\nreadline = sys.stdin.readline\nN, K = [int(w) for w in readline().split()]\nposes = [int(w) for w in readline().split()]\nxk = poses[K - 1]\nxn, yn = poses.pop(), int(readline())\nposes.sort()\ndist = [((x - xn)**2 + yn ** 2) ** 0.5 for x in poses]\n\nif K == N + 1:\n print(poses[-1] - poses[0] + min(dist[0], dist[-1]))\n exit(0)\n\nk = poses.index(xk)\nx_min = poses[0]\nx_max = poses[-1]\nl, r = max(0, k - 1), min(len(poses) - 1, k + 1)\nxl, xr = poses[l], poses[r]\nresult = dist[0] + dist[-1] + x_max - x_min - max(xr - xk, xk - xl)\nresult = min(result, dist[0] + x_max - x_min + x_max - xk)\nresult = min(result, dist[-1] + x_max - x_min + xk - x_min)\n\nfor i, xi in enumerate(poses):\n l, r = max(0, i - 1), min(len(poses) - 1, i + 1)\n xl, xr = poses[l], poses[r]\n result = min(result, min([\n dist[-1] + dist[l] + abs(xk - xi) + x_max - xi + xl - x_min,\n dist[0] + dist[r] + abs(xi - xk) + xi - x_min + x_max - xr,\n # dist[l] + dist[i] + x_max - xi + xl - x_min + min([x_max - xk, xk - x_min]),\n dist[r] + dist[i] + x_max - xr + xi - x_min + min([x_max - xk, xk - x_min])]))\n\nprint(result)\n" ]
{"inputs": ["3 1\n0 1 2 1\n1", "3 1\n1 0 2 1\n1", "4 5\n0 5 -1 -5 2\n3", "4 1\n0 5 -1 -5 2\n3", "10 5\n-231 598 312 -837 -711 553 -439 351 83 -605 -738\n791", "100 31\n-577 101 691 -95 809 125 -934 -645 -838 -548 259 312 -501 -962 -629 -637 -797 -259 -258 -687 537 303 -6 431 64 229 -897 -942 -805 804 -608 84 992 -563 279 -546 -523 -28 4 -296 120 -306 456 -334 625 821 -9 525 572 -36 -642 594 207 429 -859 -408 -428 280 389 304 -683 800 97 578 -1 46 981 -271 585 -913 761 367 0 -360 529 -302 598 -660 295 -785 756 759 -446 -826 -627 687 -459 637 -509 -582 825 34 -911 -383 49 -343 791 471 -574 -267 -954\n-462", "4 2\n0 2 3 9 2\n5", "1 1\n8 4\n5", "1 2\n104 13\n455", "2 2\n-80 -28 -41\n-61", "3 1\n6 -7 40 -39\n28", "4 4\n-58 14 70 34 -12\n84", "5 1\n78 35 -100 57 99 -92\n58", "6 6\n14 6 -19 -71 59 -17 24\n-76", "7 6\n-51 27 12 -48 -31 7 -10 -10\n-35", "8 9\n36 48 42 -25 80 32 -44 6 -80\n-50", "9 6\n-28 69 -78 48 41 57 73 75 -38 30\n-94", "10 1\n-42 -13 68 -73 -39 81 -9 -47 -74 -84 -2\n-70", "11 6\n41 -64 51 67 -8 -99 -94 -81 -30 -60 37 -66\n26", "12 3\n74 -65 84 -44 23 -78 22 86 65 -86 76 -61 66\n-87", "13 4\n-43 -65 67 95 -97 -56 -63 53 -42 -62 -86 -7 -45 12\n44", "14 12\n-10 85 50 34 -67 -35 53 -31 -89 -47 -3 -5 -90 10 -100\n50", "15 7\n23 84 83 -28 -36 36 -82 -64 -54 -65 -8 51 35 9 -74 -19\n37", "16 6\n-94 83 66 62 45 58 34 -98 40 -91 81 56 -76 -93 43 75 -49\n57", "17 17\n-61 32 99 1 76 79 -51 20 -66 83 -80 60 -36 6 -41 93 -89 65\n35", "18 11\n22 31 82 -61 -94 -100 65 -14 28 -41 -87 54 -96 -75 -27 100 -73 63 2\n-15", "19 12\n55 30 65 79 -63 -79 -20 -48 73 81 -2 -83 94 3 42 54 -64 40 91 24\n48", "1 2\n-5 -4\n-2", "2 1\n-2 -1 -1\n-4", "3 1\n-1 1 4 0\n-5", "4 3\n3 0 -3 1 -3\n-3", "5 6\n-5 2 -1 5 0 0\n2", "6 3\n-1 3 1 -4 5 -3 -4\n5", "7 7\n0 4 3 -5 -3 -1 5 3\n4", "8 5\n3 -4 2 -1 4 0 5 1 3\n4", "9 2\n-4 -2 4 3 -5 5 0 -3 -1 1\n-3", "10 6\n4 -3 0 -2 2 5 1 -5 -4 -1 2\n5", "1 2\n-6 -5\n-13", "2 1\n-3 20 2\n8", "3 4\n0 5 18 -13\n-4", "4 5\n3 -10 -8 5 -15\n5", "5 4\n7 16 9 -16 13 -5\n4", "6 6\n10 0 -16 2 5 -20 -16\n18", "7 1\n13 -15 -1 -19 -5 -14 14 -6\n5", "8 2\n16 11 1 -14 -6 5 8 -15 16\n-15", "9 9\n19 -4 -9 17 2 -6 -19 -3 -10 20\n-19", "10 10\n-7 -4 -5 17 20 -6 -1 10 -8 13 3\n19", "3 1\n0 1 2 1\n1", "3 1\n1 0 2 1\n1", "4 5\n0 5 -1 -5 2\n3", "4 1\n0 5 -1 -5 2\n3", "5 1\n0 1 3 100 -1000 2\n1", "5 1\n0 -1 -3 -100 1000 -2\n1", "1 2\n-1 9\n0", "2 2\n4 -2 -8\n0", "3 2\n7 -2 3 -8\n0", "4 5\n-9 -2 0 4 -4\n0", "5 5\n-4 -2 0 6 -6 -8\n0", "6 6\n10 0 -16 2 5 -20 18\n0", "7 1\n13 -15 -1 -19 -5 -14 14 5\n0", "8 2\n16 11 1 -14 -6 5 8 -15 -19\n0", "9 9\n19 -4 -9 17 2 -6 -19 -3 -10 3\n0", "10 10\n-7 -4 -5 17 20 -6 -1 10 -8 13 19\n0", "11 7\n-2 20 -16 19 -5 3 13 17 -15 16 -10 -19\n0", "12 8\n0 15 -20 17 -8 11 1 20 -2 -13 8 -3 4\n0", "15 16\n9 -15 -16 12 -17 -4 -19 -9 -11 -14 -13 4 5 8 -18 1\n0", "15 7\n11 -30 -5 -3 19 -11 -27 3 22 -4 10 -16 -13 -8 -26 25\n0", "20 1\n-7 -28 -2 27 -12 6 -1 10 -11 -8 29 16 -14 -18 23 -10 13 -29 -25 30 7\n0", "20 8\n-36 -18 13 11 5 18 23 -2 -39 2 4 -34 -20 24 7 19 -13 14 6 -35 -4\n0", "20 8\n62 -52 -96 -68 -13 59 65 21 -47 90 -21 58 -71 39 -35 -98 -19 -90 -57 -62 -48\n0", "100 31\n-577 101 691 -95 809 125 -934 -645 -838 -548 259 312 -501 -962 -629 -637 -797 -259 -258 -687 537 303 -6 431 64 229 -897 -942 -805 804 -608 84 992 -563 279 -546 -523 -28 4 -296 120 -306 456 -334 625 821 -9 525 572 -36 -642 594 207 429 -859 -408 -428 280 389 304 -683 800 97 578 -1 46 981 -271 585 -913 761 367 0 -360 529 -302 598 -660 295 -785 756 759 -446 -826 -627 687 -459 637 -509 -582 825 34 -911 -383 49 -343 791 471 -574 -267 -462\n0", "5 2\n0 2 3 8 9 2\n5", "4 2\n0 2 3 9 2\n5", "4 3\n0 6 7 9 7\n5", "1 2\n-1 -3\n9", "2 2\n4 -2 5\n-8", "3 2\n7 -2 3 8\n-8", "4 5\n-9 -2 0 4 10\n-4", "5 5\n-4 -2 0 6 -6 5\n-8", "6 6\n1 -1 -6 -2 5 -9 -1\n-1", "100 9\n52 24 17 12 57 95 94 36 -3 63 -69 71 23 -72 77 -55 2 -5 -25 -18 -39 -100 6 -43 18 74 -61 54 47 5 -68 9 -41 -42 34 31 -4 -16 67 -65 -56 -50 -84 27 -87 62 70 -14 10 90 -46 97 43 -88 99 75 -34 -36 92 -17 29 -52 -80 -92 44 -44 -32 -89 -82 -74 98 38 -10 93 -24 96 -28 -98 76 -83 -29 -27 35 53 37 -67 64 -21 72 -20 -54 49 28 26 83 46 59 -2 -12 32 -44\n37"], "outputs": ["3.41421356237309490000", "3.82842712474619030000", "14.24264068711928400000", "16.85841379298319300000", "2928.27473344969580000000", "2983.22016716350340000000", "17.98749007417713100000", "6.40312423743284850000", "464.01077573694340000000", "124.40165743959182000000", "123.52058325093860000000", "259.77055915050300000000", "278.54912467321776000000", "267.67197858303581000000", "146.93132631298738000000", "185.61168720299744000000", "307.09503873251936000000", "299.34407871396292000000", "205.09347166041786000000", "316.05212760071760000000", "240.06852768030663000000", "315.99019513592782000000", "222.67938366055708000000", "259.75902391002091000000", "236.79549159502341000000", "223.93171219946132000000", "250.76629407951023000000", "2.23606797749978980000", "5.00000000000000000000", "11.40312423743284900000", "10.24264068711928400000", "15.38516480713450500000", "18.00000000000000000000", "16.00000000000000000000", "16.47213595499958000000", "16.76782893563237000000", "18.38516480713450500000", "13.03840481040529800000", "29.13169673564881300000", "31.60147050873544600000", "22.07106781186547600000", "33.35381055139314600000", "56.08318915758459200000", "39.53300064564938800000", "60.00000000000000000000", "66.02629759044045000000", "56.95449840010015000000", "3.41421356237309490000", "3.82842712474619030000", "14.24264068711928400000", "16.85841379298319300000", "1200.00560090988460000000", "1200.00560090988460000000", "10.00000000000000000000", "18.00000000000000000000", "21.00000000000000000000", "18.00000000000000000000", "16.00000000000000000000", "38.00000000000000000000", "34.00000000000000000000", "40.00000000000000000000", "47.00000000000000000000", "35.00000000000000000000", "46.00000000000000000000", "40.00000000000000000000", "42.00000000000000000000", "58.00000000000000000000", "81.00000000000000000000", "89.00000000000000000000", "257.00000000000000000000", "2308.00000000000000000000", "18.19541448304115900000", "17.98749007417713100000", "17.98749007417713100000", "9.21954445729288710000", "14.06225774829854900000", "17.06225774829854900000", "20.21110255092797900000", "20.06225774829854900000", "15.23606797749979000000", "321.09250465482546000000"]}
UNKNOWN
PYTHON3
CODEFORCES
3
1655768ab04bba468899388061617449
Cowboys
A very tense moment: *n* cowboys stand in a circle and each one points his colt at a neighbor. Each cowboy can point the colt to the person who follows or precedes him in clockwise direction. Human life is worthless, just like in any real western. The picture changes each second! Every second the cowboys analyse the situation and, if a pair of cowboys realize that they aim at each other, they turn around. In a second all such pairs of neighboring cowboys aiming at each other turn around. All actions happen instantaneously and simultaneously in a second. We'll use character "A" to denote a cowboy who aims at his neighbour in the clockwise direction, and character "B" for a cowboy who aims at his neighbour in the counter clockwise direction. Then a string of letters "A" and "B" will denote the circle of cowboys, the record is made from the first of them in a clockwise direction. For example, a circle that looks like "ABBBABBBA" after a second transforms into "BABBBABBA" and a circle that looks like "BABBA" transforms into "ABABB". A second passed and now the cowboys' position is described by string *s*. Your task is to determine the number of possible states that lead to *s* in a second. Two states are considered distinct if there is a cowboy who aims at his clockwise neighbor in one state and at his counter clockwise neighbor in the other state. The input data consists of a single string *s*. Its length is from 3 to 100 characters, inclusive. Line *s* consists of letters "A" and "B". Print the sought number of states. Sample Input BABBBABBA ABABB ABABAB Sample Output 2 2 4
[ "'''\r\n字符串中A/B分别代表顺/逆时针指向邻居,如果两个人互相面对,那么下一个状态中这俩人都转身,\r\n求给定长度不超过100的字符串的可能前一个状态的种数。\r\n\r\n对于顺时针的s[i:i+2],若为'BA',那么前一个状态可以是AB和BA\r\n若为AB……;\r\n若为BA(不变),那么前一个状态中s[i-1]不能为‘A'、s[i+2]不能为'B'。\r\n'''\r\nG,s=range,input();n=len(s);s+=s[0];D={'A':0,'B':1}\r\ndef dp(j):\r\n f=[[0]*2 for _ in G(n+1)];f[0][j]=1\r\n for i in G(n):\r\n if s[i]=='A':\r\n f[i+1][0]+=sum(f[i]);f[i+1][1]+=f[i][1]*(D[s[i+1]])\r\n else:\r\n f[i+1][0]+=f[i][1];f[i+1][1]+=f[i][D[s[i+1]]]\r\n return f[n][j]\r\nprint(dp(0)+dp(1))\r\n" ]
{"inputs": ["BABBBABBA", "ABABB", "ABABAB", "ABA", "AABB", "ABABBABBAABAB", "AAABAABABA", "ABABABABABABABABABAB", "BABABABABAAAABABAAAABAB", "ABABABBABA", "BBB", "AAAA", "ABBAB", "BBBABB", "BABBBBB", "ABABBAAB", "ABBBABBAB", "BAAABBBBBA", "AAAAAAAAAAA", "BABBAAAABAAA", "ABABBBABBBAAA", "BBBBBABBBBBABB", "AAAAAAAABAAAAAA", "BAAABAAAAABABBAA", "ABABBAAAABBBAAAAB", "BBBBBBBBABBBBBBBBA", "AAAAAAAAAABAABBAAAA", "AAAAAAAAAAAAAABAAAAB", "BBB", "AAAA", "ABBAB", "BBBABB", "BABBBBB", "ABABBAAB", "ABBBABBAB", "ABBBBBABBB", "AAAAAAAAAAA", "BABBAAAABAAA", "ABABBBABBBAAA", "BBBBBABBBBBABB", "AAAAAAAABAAAAAA", "BAAABAAAAABABBAA", "BAAABAABABABAAABA", "BBBBBBBBABBBBBBBBA", "AAAAAAAAAAABAAAAAAA", "AAAAAAAAAAAAAABAAAAB", "BBB", "AAAA", "BABAB", "ABABAB", "BBBBBBB", "BABABAAA", "ABBAAABAB", "BBBABBABBB", "ABABAAABAAA", "AABABABBABBA", "AABABBABBAAAA", "BABABABAABABBB", "AAABAAAABABAAAA", "BABABBABABABABAB", "ABABBABBABABAABAA", "BABABBABBBBABBAABA", "AAABABAAABAABABABAB", "AAAAAABAAAABABABABAA", "AAAAAAAAABAAAAAAAAAAAAAAAAABAAAAAAAABAAAAAAABAAAAAAAAAABAAAAAAAABAAAAAAAAAAABAAAAAAAAAAABAAAAAA", "AAAAABBBAABAAABBBAAAAAAAAAAABAAAAAABABBABAAABABAAABABAAABAAABABABBBAAABBBAAABBBABABAAAAAAAAAAAAA", "ABBABAABABBAABBBBBABBBBBBABBBBAABAAAABBBAAABBBABBAABBBABABBBBBABAABBBAABBABABBBAAABBBBBBBBBABBBAB", "BBBBBBBBBBBBAABBBBBBABABBBBBBBBBBBBBBBBBBABBBBBBBBBABBBBBABBBBABBBBBBBBBBBBBBBBBBBAABABBBBBBBBABBB", "AAAAABABAABAAAAAAAAAABBABBBAAAAAAAABAAAABAAABBAAAAAAABABBABAAAAAAAAAAAAAAAAAAAAAABAABAAAAAABAABAAAB", "ABAAABBABBABAABAABABBABABAAABAAABBBBABBABBBAABABABBAAABABBABBABBABABAAAABBABBBAABBABABBAABBABBBBAAAA", "AAAAAAAAABAAAAAAAAAAAAAAAAABAAAAAAAABAAAAAAABAAAAAAAAAABAAAAAAAABAAAAAAAAAAABAAAAAAAAAAABAAAAAA", "BBABAAAAABABBBABBBAAAABAAAAAAABAAAABABABBAAAAAABAABAAAAAABAAABAAAAAAAABABBAAAAABAAAAAABAAAAAAABA", "BBABABBBBBBBABABBABABAABABBBAAABABBBBBBBBABBABBBBBBBBBABAABABBBBAABAABABBBABABBBABAABABBBBBAABABA", "BBBABABBABBBABBABBBBBBABBBBBABBBBBBBBBBABBBBBBBBBBBBBBBBABBBBBBBABBABBABBBBBABBBBBBBBBBBBBBBBBBBAB", "AAABAAAAAAAAABABAAAAABAAAAAAAAAABAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAABABAABAAAAAAAAAAAAAAABAA", "BAAAABABBBAABABBBBABBBBBBBAABAABABBAABABABBBBABABBBBBBABBBAAAAABABBBABAABABBBBBBBBBBBBABABBABBBBBABA", "ABABABAAAAAABABABABABABABAAAAAABAAABAAAAAAAAABAAABABABABAAAAAAAAAAABABABABABABABABAAABAAAABABAB", "AAAABABABABABABABABABABABABABABABABAAABABABABABABABABABABABABABABABABABABABABABBAABABABABABABABB", "ABABABABABABABABAABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBABABABABABA", "BBBBAABABABABABABABABABABABABABBABABABABABABABABABABABABABABABABABBABABABABABABABABABABABABABABABA", "AAAAAABABABABABABABAAAAAABAAAAAAAABAAAAAAAAAABABABABABABAAAAABABABABABABABABAAAAABABABABABABABABAAB", "ABBABABABABABABABABABAAABABABBBABABABABABABABABABABABABABABABABABABABABABBAABABBBBABABABABABABABABAB", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "AAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAA", "BBBBBBBBBABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB", "ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAAABABABABABABABABA", "ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB", "ABABABABABABABABABABABABABABABABABABAAAAABABABABABABABABABABABABABABABABABABABABABABABABABABABABA", "ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAAABABABABABABABABABABABABABABABABABAB", "ABABABABABABABABABABAAABABABABABABABABABABABABABABABABAAABABBAABABABABABABABABABABABABABABABABA", "ABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABBABB", "BABABBABABAB", "AAA", "AAB", "ABA", "BAA", "BBA", "BAB", "ABB", "BBB", "ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB"], "outputs": ["2", "2", "4", "1", "0", "4", "2", "123", "26", "3", "1", "1", "2", "1", "1", "2", "2", "0", "1", "2", "2", "1", "1", "2", "0", "1", "0", "1", "1", "1", "2", "1", "1", "2", "2", "1", "1", "2", "2", "1", "1", "2", "6", "1", "1", "1", "1", "1", "2", "4", "1", "3", "2", "1", "2", "2", "2", "8", "2", "16", "5", "4", "10", "5", "1", "0", "0", "0", "0", "0", "1", "24", "2880", "2", "4", "960", "46410", "345718560", "1555312626", "1188474624", "315588", "453968352", "1", "1", "1", "1", "1", "1", "28143753123", "5629724794", "17393796001", "2149991449", "4807526976", "453972802", "1", "6", "1", "1", "1", "1", "1", "1", "1", "1", "28143753123"]}
UNKNOWN
PYTHON3
CODEFORCES
1
166c3a794830622ff41a4fd1297a07d0
System Administrator
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format. Sample Input 2 1 5 5 2 6 4 3 1 0 10 2 0 10 1 10 0 Sample Output LIVE LIVE LIVE DEAD
[ "n=int(input())\r\nserver1x = 0\r\nserver2x = 0\r\nserver1y = 0\r\nserver2y = 0\r\nfor _ in range(n):\r\n t, x, y = list(map(int, input().split()))\r\n\r\n if t == 1:\r\n server1x += x\r\n server1y += y\r\n else:\r\n server2x += x\r\n server2y += y\r\nif server1x >= server1y:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif server2x >= server2y:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "n = int(input())\r\na = [0, 0]\r\nb = [0, 0]\r\nfor _ in range(n):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n a[0] += x\r\n a[1] += y\r\n else:\r\n b[0] += x\r\n b[1] += y\r\nif a[0] >= a[1]:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif b[0] >= b[1]:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n", "n=int(input())\r\na,b=[0,0],[0,0]\r\nfor i in range(n):\r\n s=list(map(int, input().split()))\r\n if s[0]==1:\r\n a[0]+=s[1]\r\n a[1]+=s[2]\r\n else:\r\n b[0]+=s[1]\r\n b[1]+=s[2]\r\nif a[0]>=a[1]: print(\"LIVE\")\r\nelse: print(\"DEAD\")\r\nif b[0]>=b[1]: print(\"LIVE\")\r\nelse: print(\"DEAD\")\r\n", "t = int(input())\na, b, am, bm = 0, 0, 0, 0\nfor i in range(t):\n ti, x, y = [int(x) for x in input().split(' ')]\n if ti == 1:\n am += 10\n a += x\n else:\n bm += 10\n b += x\nif a / am >= 0.5: print('LIVE')\nelse: print('DEAD')\nif b / bm >= 0.5: print('LIVE')\nelse: print('DEAD')\n", "n = int(input())\nlive_a = 0\ndead_a = 0\nlive_b = 0\ndead_b = 0\nstatus_a = False\nstatus_b = False\n\nfor i in range(n):\n\n\tx = list(map(int, input().split()))\n\tif x[0] == 1:\n\t\tlive_a += x[1]\n\t\tdead_a += x[2]\n\telse:\n\t\tlive_b += x[1]\n\t\tdead_b += x[2]\n\nif live_a >= dead_a:\n\tstatus_a = True\nif live_b >= dead_b:\n\tstatus_b = True\n\nprint(\"LIVE\" if status_a == True else \"DEAD\")\nprint(\"LIVE\" if status_b == True else \"DEAD\")\n\n\n\t", "# The place between your comfort zone and your dream is where life takes place. Helen Keller\r\n# by : Blue Edge - Create some chaos\r\n\r\nn=int(input())\r\na=0\r\nax=0\r\nb=0\r\nbx=0\r\nfor i in range(n):\r\n t,x,y=map(int,input().split())\r\n if t==1:\r\n a+=1\r\n ax+=x\r\n else:\r\n b+=1\r\n bx+=x\r\n\r\nprint(\"LIVE\" if ax>=5*a else \"DEAD\")\r\nprint(\"LIVE\" if bx>=5*b else \"DEAD\")\r\n", "tc=int(input())\r\ncount1=0\r\ncount2=0\r\ncount3=0\r\ncount4=0\r\nfor i in range(tc):\r\n t,x,y=list(map(int,input().split()))\r\n if t==1:\r\n count1+=x\r\n count2+=10\r\n else:\r\n count3+=x\r\n count4+=10\r\nif count1>=(count2/2):\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif count3>=(count4/2):\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nft = 0\r\nst = 0\r\nfa = 0\r\nsa = 0\r\n\r\nfor _ in range(int(input())):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n ft += x + y\r\n fa += x\r\n else:\r\n st += x + y\r\n sa += x\r\n\r\nprint(\"LIVE\" if fa >= ft // 2 else \"DEAD\")\r\nprint(\"LIVE\" if sa >= st // 2 else \"DEAD\")", "n=int(input())\r\n\r\nax=0;bx=0\r\nay=0;by=0\r\n\r\nfor i in range(n):\r\n t,x,y=map(int,input().split())\r\n\r\n if t==1:\r\n ax+=x\r\n ay+=y\r\n else:\r\n bx+=x\r\n by+=y\r\n\r\nif ax>=(ax+ay)//2:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n\r\nif bx>=(bx+by)//2:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "import sys\r\n\r\ndef main():\r\n t = [0, 0]\r\n for s in sys.stdin.read().strip().split('\\n')[1:]:\r\n n, x, y = map(int, s.split())\r\n t[n-1] += x - y\r\n return [('LIVE', 'DEAD')[i < 0] for i in t]\r\n \r\nprint(*main(), sep='\\n')\r\n", "n = int(input())\r\n\r\nresult1 = 0\r\nresult2 = 0\r\nfor i in range(n):\r\n ttt, pos, neg = list(map(int, input().split()))\r\n\r\n if ttt == 1:\r\n result1 += pos-neg\r\n else:\r\n result2 += pos-neg\r\n\r\nprint('LIVE' if result1 >= 0 else 'DEAD')\r\nprint('LIVE' if result2 >= 0 else 'DEAD')", "n = int(input())\r\nx1 = x2 = y1 = y2 = 0\r\nfor i in range(n):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n x1 += x\r\n y1 += y\r\n else:\r\n x2 += x\r\n y2 += y\r\n\r\nprint('LIVE' if x1 >= y1 else 'DEAD')\r\nprint('LIVE' if x2 >= y2 else 'DEAD')", "n = int(input())\r\n\r\na_success = 0\r\na_total = 0\r\n\r\nb_success = 0\r\nb_total = 0\r\n\r\nfor i in range(n):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n a_success += x\r\n a_total += x + y\r\n else:\r\n b_success += x\r\n b_total += x + y\r\n\r\nif a_success * 2 >= a_total:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif b_success * 2 >= b_total:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "# https://codeforces.com/problemset/problem/245/A\r\n\r\na_count = 0\r\na_ping = 0\r\nb_ping = 0\r\nn = int(input())\r\n\r\nfor _ in range(n):\r\n server, x, y = map(int, input().split())\r\n if server == 1:\r\n a_count += 1\r\n a_ping += x\r\n else:\r\n b_ping += x\r\n\r\nif a_count * 5 <= a_ping:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif (n - a_count) * 5 <= b_ping:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n = int(input())\r\na1, a2, b1, b2 = 0, 0, 0, 0\r\nfor i in range(n):\r\n t, x, y = map(int, input().split())\r\n if t == 1 :\r\n a1 += 1\r\n a2 += x\r\n else:\r\n b1 += 1\r\n b2 += x\r\nif a2 >= 5 * a1 :\r\n print(\"LIVE\")\r\nelse :\r\n print(\"DEAD\")\r\nif b2 >= 5 * b1 :\r\n print(\"LIVE\")\r\nelse :\r\n print(\"DEAD\")\r\n", "a=int(input())\r\nx=y=m=n=int(0)\r\nfor _ in range(a):\r\n\ta,b,c=map(int,input().split())\r\n\tif a==1:\r\n\t\tx=x+b\r\n\t\tm=m+10\r\n\telse:\r\n\t\ty=y+b\r\n\t\tn=n+10\r\nif x>=m/2:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\nif y>=n/2:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")", "a = [0, 0]\r\nb = [0, 0]\r\nfor i in range(int(input())):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n a[0] += x\r\n a[1] += 10\r\n else:\r\n b[0] += x\r\n b[1] += 10\r\nprint(\"LIVE\" if a[0] >= a[1]//2 else \"DEAD\")\r\nprint(\"LIVE\" if b[0] >= b[1]//2 else \"DEAD\")", "a=[0,0]\r\nfor _ in [0]*int(input()):\r\n t,x,y=map(int,input().split())\r\n a[t-1]+=x-y\r\nfor x in a: print(['LIVE','DEAD'][x<0])", "n = int(input())\r\nar = [[0, 0] , [0, 0]]\r\nfor i in range(n):\r\n a, b, c = input().split()\r\n a = int(a)\r\n b = int(b)\r\n c = int(c)\r\n ar[a - 1][0] += b\r\n ar[a - 1][1] += c\r\nif(ar[0][1] > ar[0][0]):\r\n print(\"DEAD\")\r\nelse:\r\n print(\"LIVE\")\r\nif(ar[1][1] > ar[1][0]):\r\n print(\"DEAD\")\r\nelse:\r\n print(\"LIVE\")", "def main():\n n=int(input())\n a=[]\n for i in range(n):\n a.append(list(map(int,input().split())))\n a1=[i[1] for i in a if i[0]==1]\n a2=[j[1] for j in a if j[0]==2]\n if(sum(a1)>=len(a1)*5):\n print('LIVE')\n else:\n print('DEAD')\n if(sum(a2)>=len(a2)*5):\n print(\"LIVE\")\n else:\n print(\"DEAD\")\n\nmain()", "n = int(input())\r\n\r\nSuccessA = 0\r\nSuccessB = 0\r\nFailA = 0\r\nFailB = 0\r\n\r\nfor _ in range(n):\r\n t,x,y = map(int,input().split())\r\n if t == 1:\r\n SuccessA += x \r\n FailA += y\r\n else:\r\n SuccessB += x\r\n FailB += y\r\nif SuccessA >= (SuccessA + FailA)/2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif SuccessB >= (SuccessB + FailB)/2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n_pings = int(input())\npackets = [[0, 0], [0, 0]] # ((a_success, a_total), (b_success, b_total))\nfor _ in range(n_pings):\n t, x, y = map(int, input().split())\n packets[t - 1][0] += x\n packets[t - 1][1] += x + y\n\nif packets[0][1] == 0 or packets[0][0] / packets[0][1] >= 0.5:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\nif packets[1][1] == 0 or packets[1][0] / packets[1][1] >= 0.5:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\n", "def server_status(packets):\r\n first_delta = 0\r\n second_delta = 0\r\n for packet in packets:\r\n if packet[0] == 1:\r\n first_delta += packet[1] - packet[2]\r\n else:\r\n second_delta += packet[1] - packet[2]\r\n print(\"LIVE\" if first_delta >= 0 else \"DEAD\")\r\n print(\"LIVE\" if second_delta >= 0 else \"DEAD\")\r\n \r\npackets = []\r\n\r\nfor i in range(int(input())):\r\n packet = list(map(int, input().split()))\r\n packets.append(packet)\r\nserver_status(packets)", "# A. System Administrator\n\nn = int(input())\n\na_reached = 0\na_total = 0\nb_reached = 0\nb_total = 0\n\nfor i in range(n):\n t, x, y = map(int, input().split())\n if t == 1:\n a_reached += x\n a_total += x + y\n else:\n b_reached += x\n b_total += x + y\n\nprint(\"LIVE\" if a_reached * 2 >= a_total else \"DEAD\")\nprint(\"LIVE\" if b_reached * 2 >= b_total else \"DEAD\")\n", "server = [0, 0]\r\nfor _ in range(int(input())):\r\n t, x, y = map(int, input().split())\r\n server[t - 1] += x - y\r\n\r\nfor serv in server:\r\n if serv >= 0:\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")\r\n", "IL = lambda: list(map(int, input().split()))\r\n\r\nn = int(input())\r\nA = [[0, 0], [0, 0]]\r\nfor i in range(n):\r\n t, x, y = IL()\r\n A[t-1][0] += x\r\n A[t-1][1] += 10\r\n\r\nprint(['DEAD', 'LIVE'][A[0][0]*2 >= A[0][1]])\r\nprint(['DEAD', 'LIVE'][A[1][0]*2 >= A[1][1]])", "n=int(input())\r\nta=0\r\ntb=0\r\nra=0\r\nrb=0\r\nfor i in range(n):\r\n t,a,b=map(int,input().split())\r\n if(t==1):\r\n ta+=a+b\r\n ra+=a\r\n if(t==2):\r\n tb+=a+b\r\n rb+=a\r\nif(ra>=ta//2):\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif(rb>=tb//2):\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n \r\n", "n=int(input())\r\na = [0] * 2\r\nb = [0] * 2\r\nfor i in range(n):\r\n t, x, y = map(int, input().split())\r\n if t-1:\r\n b[0]+=x\r\n b[1]+=y\r\n else:\r\n a[0]+=x\r\n a[1]+=y\r\nif a[0]>=a[1]:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif b[0]>=b[1]:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n", "l1=[]\r\nl2=[]\r\nm2=[]\r\nm1=[]\r\nfor i in range(int(input())):\r\n\ta,b,c=map(int,input().split())\r\n\tif a==1:\r\n\t\tl1.append(b)\r\n\t\tl2.append(c)\r\n\telse:\r\n\t\tm1.append(b)\r\n\t\tm2.append(c)\r\nif sum(l1)>=sum(l2):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\nif sum(m1)>=sum(m2):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")", "n = int(input())\r\nservera = 0\r\nserverb = 0\r\ninputa = 0\r\ninputb = 0\r\nfor i in range(n) :\r\n\tx = [int(tmp) for tmp in input().split()]\r\n\tif x[0] == 1 :\r\n\t\tservera += 10\r\n\t\tinputa += x[1]\r\n\telif x[0] == 2 :\r\n\t\tserverb += 10\r\n\t\tinputb += x[1]\r\nif inputa >= servera//2 :\r\n\tprint(\"LIVE\")\r\nelse :\r\n\tprint(\"DEAD\")\r\nif inputb >= serverb//2 :\r\n\tprint(\"LIVE\")\r\nelse :\r\n\tprint(\"DEAD\")", "n = int(input())\r\na1 = a2 = b1 = b2 = 0\r\nfor i in range(n):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n a1 += x\r\n a2 += y\r\n else:\r\n b1 += x\r\n b2 += y\r\nif a1 >= a2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif b1 >= b2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "tot_a,tot_b,suc_a,suc_b,fail_a,fail_b = 0,0,0,0,0,0\r\nfor t in range(int(input())):\r\n t,x,y = map(int,input().split())\r\n if(t==1):\r\n tot_a += x + y\r\n suc_a += x\r\n fail_a += y\r\n elif(t==2):\r\n tot_b += x + y\r\n suc_b += x\r\n fail_b += y\r\nif(suc_a>=tot_a//2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif(suc_b>=tot_b//2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n=int(input())\r\nareached=0\r\nbreached=0\r\nalost=0\r\nblost=0\r\nfor i in range(n):\r\n a,b,c=map(int,input().split())\r\n if a==1:\r\n areached+=b\r\n alost+=c\r\n else:\r\n breached+=b\r\n blost+=c\r\n\r\nif areached>=alost:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif breached>=blost:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "a = [[0, 0], [0, 0]]\r\nfor cas in range(int(input())):\r\n x, y, z = map(int, input().split())\r\n x -= 1\r\n a[x][0] += y\r\n a[x][1] += z\r\nfor i in range(2):\r\n if a[i][0] >= a[i][1]:\r\n print('LIVE')\r\n else:\r\n print('DEAD')", "q=lambda:map(int,input().split())\r\nqi=lambda:int(input())\r\nqs=lambda:input().split()\r\nx1,y1,x2,y2=0,0,0,0\r\nfor i in range(qi()):\r\n t,x,y=q()\r\n if t==1:\r\n x1,y1=x1+x,y1+y \r\n else: x2,y2=x2+x,y2+y\r\nprint('LIVE' if x1>=y1 else \"DEAD\")\r\nprint('LIVE' if x2>=y2 else \"DEAD\")", "n=int(input())\r\nd1=0\r\nl1=0\r\nl2=0\r\nd2=0\r\nfor i in range(n):\r\n\tt,x,y=map(int,input().split())\r\n\tif t==1:\r\n\t\tl1+=x\r\n\t\td1+=y\r\n\telse:\r\n\t\tl2+=x\r\n\t\td2+=y\r\nif l1>=d1:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\t\r\nif l2>=d2:\r\n\tprint(\"LIVE\")\t\r\nelse:\r\n\tprint(\"DEAD\")\t", "# import sys\r\n# sys.stdin=open(\"input.in\",\"r\")\r\n# sys.stdout=open(\"output.out\",\"w\")\r\n\r\na=int(input())\r\nb=[]\r\nx1,x2,count1,count2=0,0,0,0\r\nfor x in range(a):\r\n\tb.append(list(map(int,input().split())))\r\n\tif b[x][0]==1:\r\n\t\tx1+=b[x][1]\r\n\t\tcount1+=1\r\n\telse:\r\n\t\tx2+=b[x][1]\r\n\t\tcount2+=1\r\nif x1>=((count1*10)/2):\r\n\tprint('LIVE')\r\nelif not(x1>((count1*10)/2)):\r\n\tprint('DEAD')\r\nif x2>=((count2*10)/2):\r\n\tprint('LIVE')\r\nelif not(x2>((count2*10)/2)):\r\n\tprint('DEAD')\r\n\r\n", "serverA=0\r\nserverB=0\r\ntotalA=0\r\ntotalB=0\r\nfor _ in range(int(input())):\r\n p = list(map(int, input().split()))\r\n if(p[0]==1):\r\n serverA+=p[1]\r\n totalA+=10\r\n else:\r\n serverB+=p[1]\r\n totalB += 10\r\nprint(\"LIVE\" if serverA>=totalA//2 else \"DEAD\")\r\nprint(\"LIVE\" if serverB>=totalB//2 else \"DEAD\",end=\"\")\r\n\r\n", "a = [0, 0]\r\nb = [0, 0]\r\nfor _ in range(int(input())):\r\n t, x, y = [int(i) for i in input().split()]\r\n\r\n if t == 1:\r\n a[0] += x\r\n a[1] += 10\r\n else:\r\n b[0] += x\r\n b[1] += 10\r\nif a[0] >= a[1]/2: print('LIVE')\r\nelse: print('DEAD')\r\n \r\nif b[0] >= b[1]/2: print('LIVE')\r\nelse: print('DEAD')", "import time\nimport collections\n\nclass Time_test:\n def __enter__(self):\n self.enter_time = time.time()\n def __exit__(self, exc_type, exc_val, exc_tb):\n print(\"Command was executed in\", time.time()-self.enter_time)\n\narr = [[0, 0], [0, 0]]\nn = int(input())\nfor i in range(n):\n t, x, y = [int(x) for x in input().split()]\n t -= 1\n arr[t][0] += x\n arr[t][1] += y\n\nif arr[0][0] >= arr[0][1]:\n print('LIVE')\nelse:\n print('DEAD')\nif arr[1][0] >= arr[1][1]:\n print('LIVE')\nelse:\n print('DEAD')\n", "p = [[0, 0], [0, 0]]\nfor _ in range(0, int(input())):\n t, x, y = map(int, input().split())\n t -= 1\n p[t][0] += 1\n p[t][1] += x\nfor x in p:\n print([\"DEAD\", \"LIVE\"][x[1] * 2 >= x[0] * 10])\n", "n = int(input())\r\na_d = 0\r\nb_d = 0\r\na = 0\r\nb = 0\r\nfor i in range(n):\r\n t,x,y = map(int, input().split())\r\n if t == 1:\r\n a += x+y\r\n a_d += y\r\n else:\r\n b += x+y\r\n b_d += y\r\nif (a-a_d) >= 0.5*a:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif (b-b_d) >= 0.5*b:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "n = int(input())\r\ntxy = [list(map(int, input().split())) for _ in range(n)]\r\n\r\na = [0, 0]\r\nb = [0, 0]\r\n\r\nfor txyi in txy:\r\n if txyi[0] == 1:\r\n a[0] += txyi[1]\r\n a[1] += txyi[2]\r\n elif txyi[0] == 2:\r\n b[0] += txyi[1]\r\n b[1] += txyi[2]\r\n\r\nif a[0] >= a[1]:\r\n print(\"LIVE\")\r\nelif a[0] < a[1]:\r\n print(\"DEAD\")\r\n\r\nif b[0] >= b[1]:\r\n print(\"LIVE\")\r\nelif b[0] < b[1]:\r\n print(\"DEAD\")", "n = int(input())\nax, ay, bx, by = 0, 0, 0, 0\nfor _ in range(n):\n l = input().split(\" \")\n t = int(l[0])\n x = int(l[1])\n y = int(l[2])\n if t == 1:\n ax += x\n ay += y \n else:\n bx += x\n by += y\n\nprint(\"LIVE\" if ax >= ay else \"DEAD\")\nprint(\"LIVE\" if bx >= by else \"DEAD\")\n", "n=int(input())\nlst=[]\na1=0\na2=0\nb1=0\nb2=0\nfor i in range(n):\n lst.append([int(x)for x in input().split()])\n if lst[-1][0]==1:\n a1+=lst[-1][1]\n a2+=lst[-1][2]\n else:\n b1+=lst[-1][1]\n b2+=lst[-1][2]\nif a1/(a1+a2)>=0.5:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\nif b1/(b1+b2)>=0.5:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")", "n=int(input())\numerlo1,umerlo2,givo1,givo2=0,0,0,0\nfor i in range(n):\n t,x,y=map(int,input().split())\n if t==1:\n givo1+=x\n umerlo1+=y\n else:\n givo2+=x\n umerlo2+=y\nif givo1>=umerlo1:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\nif givo2>=umerlo2:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")", "hasil1,hasil2 = 0,0\r\ntotal1,total2 = 0,0\r\nfor i in range(int(input())):\r\n a,b,c = [int(x) for x in input().split()]\r\n if a == 1:\r\n hasil1 += 10\r\n total1 += b\r\n else:\r\n hasil2 += 10\r\n total2 += b\r\n\r\nif total1 >= hasil1//2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif total2 >= hasil2//2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n = int(input())\np = [tuple(map(int, input().split())) for _ in range(n)]\nrec1,rec2 = 0,0\nfai1,fai2 = 0,0\nfor t in p:\n if t[0] == 1:\n rec1 += t[1]\n fai1 += t[2]\n else:\n rec2 += t[1]\n fai2 += t[2]\n \nif rec1>=fai1: print('LIVE') \nelse: print('DEAD')\nif rec2>=fai2: print('LIVE') \nelse: print('DEAD')\n \n", "no=int(input())\r\n\r\na_reach=0\r\na_fail=0\r\nb_reach=0\r\nb_fail=0\r\nfor i in range(no):\r\n\t\r\n\tt,reach,no_reach=map(int,input().split())\r\n\tif(t==1):\r\n\t\ta_reach+=reach\r\n\t\ta_fail+=no_reach\r\n\telse:\r\n\t\tb_reach+=reach\r\n\t\tb_fail+=no_reach\r\n\t\t\r\nif(a_reach>=a_fail):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\t\t\r\n\t\r\nif(b_reach>=b_fail):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\t", "n = int(input())\n\na = b = 0\nfor i in range(n):\n s, x, y = map(int, input().split())\n if s == 1:\n a += x\n a -= y\n else:\n b += x\n b -= y\n\nif a >= 0:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\nif b >= 0:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\n\n\n", "n = int(input())\nsuccess = [0, 0]\ntotal = [0, 0]\nfor _ in range(n):\n\ti, x, y = map(int, input().split())\n\ttotal[i-1] += 10\n\tsuccess[i-1] += x\nfor i in range(2):\n\tprint(\"LIVE\" if success[i] * 2 >= total[i] else \"DEAD\")", "t=int(input())\r\nx=0\r\ny=0\r\np=0\r\nq=0\r\nfor i in range(1,t+1):\r\n a,b,c=[int(j) for j in input().split()]\r\n if a==1:\r\n x=x+b\r\n p=p+c\r\n if a==2:\r\n y=y+b\r\n q=q+c\r\nif x>(p-1):\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif y>(q-1):\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "n = int(input())\nax = ay = bx = by = 0\nfor i in range(n):\n\tx, y, z = [int(t) for t in input().split()]\n\tif x == 1:\n\t\tax += y\n\t\tay += z\n\telse:\n\t\tbx += y\n\t\tby += z\nprint('LIVE' if ax >= ay else 'DEAD')\nprint('LIVE' if bx >= by else 'DEAD')\n", "d, out, sign = {1: 0, 2: 0}, {-1: 'DEAD', 1: 'LIVE'}, lambda x: -1 if x < 0 else 1\r\nfor i in range(int(input())):\r\n s = list(map(int, input().split()))\r\n d[s[0]] += s[1] - s[2]\r\nfor i in range(1, 3):\r\n print(out[sign(d[i])])", "n =int(input())\r\na = 0\r\nb = 0\r\na1 = 0\r\nb1 = 0\r\n\r\nfor i in range(n):\r\n l = input().split(\" \")\r\n l = list(map(int, l))\r\n if l[0] == 1:\r\n a += 10\r\n a1 += l[1]\r\n else:\r\n b += 10\r\n b1 += l[1]\r\n \r\n\r\nif a1 >= a/2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif b1 >= b/2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "n = int(input())\r\na_success = 0\r\nb_success = 0\r\nc = []\r\nd = []\r\n\r\nfor i in range(n):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n a_success += x\r\n c.append(x)\r\n c.append(y)\r\n else:\r\n b_success += x\r\n d.append(x)\r\n d.append(y)\r\nif a_success >= sum(c)/2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif b_success >= sum(d)/2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n = int(input())\r\ncountA = 0\r\ntotalA = 0\r\ncountB = 0\r\ntotalB = 0\r\nfor i in range(0,n):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n countA = countA + x\r\n totalA = totalA + 10\r\n else:\r\n countB = countB + x\r\n totalB = totalB + 10\r\nif countA >= totalA/2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif countB >= totalB/2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "def s():\r\n n=int(input())\r\n a_total = 0\r\n a_fail = 0\r\n b_total = 0\r\n b_fail = 0\r\n for i in range(n):\r\n t,x,y = [int(x) for x in input().split(\" \")]\r\n if t == 1:\r\n a_total += x+y\r\n a_fail += y\r\n else:\r\n b_total += x+y\r\n b_fail += y\r\n if a_fail > a_total//2:\r\n print(\"DEAD\")\r\n else:\r\n print(\"LIVE\")\r\n if b_fail > b_total//2:\r\n print(\"DEAD\")\r\n else:\r\n print(\"LIVE\")\r\n\r\ns()\r\n", "a=int(input())\r\ncnt=0\r\ncnd=0\r\nx=0\r\ny=0\r\nfor i in range(a):\r\n b,c,d=map(int, input().split())\r\n \r\n if b==2:\r\n cnd+=c\r\n y+=1\r\n else:\r\n cnt+=c\r\n x+=1\r\n\r\nif cnt>=x*5:\r\n print(\"LIVE\")\r\nelse: \r\n print(\"DEAD\")\r\nif cnd>=y*5:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n \r\n", "t = int(input())\r\nar,al,br,bl = 0,0,0,0\r\nfor _ in range(t):\r\n\ti,x,y = map(int,input().split())\r\n\tif i == 1:\r\n\t\tar+=x\r\n\t\tal+=y\r\n\telse:\r\n\t\tbr+=x\r\n\t\tbl+=y\r\nif ar>=al:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\nif br>=bl:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")", "# Wadea #\r\n\r\none = []\r\ntwo = []\r\nfor i in range(int(input())):\r\n t,x,y = map(int,input().split())\r\n if t == 1:\r\n one.append(x)\r\n elif t == 2:\r\n two.append(x)\r\noone = len(one)\r\nttwo = len(two)\r\nif sum(one) < int(oone*10/2):\r\n print(\"DEAD\")\r\n if sum(two) < int(ttwo*10/2):\r\n print(\"DEAD\")\r\n else:\r\n print(\"LIVE\")\r\n\r\nelse:\r\n print(\"LIVE\")\r\n if sum(two) < int(ttwo*10/2):\r\n print(\"DEAD\")\r\n else:\r\n print(\"LIVE\")\r\n\r\n", "a=[0]*2\r\nb=[0]*2\r\n\r\n\r\n\r\nfor k in range(int(input())):\r\n t=list(map(int,input().split()))\r\n\r\n if t[0]==1:\r\n a[0]+=t[1]\r\n a[1]+=t[2]\r\n else:\r\n b[0]+=t[1]\r\n b[1]+=t[2]\r\n \r\n\r\nif a[0]>=sum(a)//2:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n\r\nif b[0]>=sum(b)//2:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n\r\n", "from functools import reduce\nfrom operator import *\nfrom math import *\nfrom sys import *\nfrom string import *\nfrom collections import *\nsetrecursionlimit(10**7)\ndX= [-1, 1, 0, 0,-1, 1,-1, 1]\ndY= [ 0, 0,-1, 1, 1,-1,-1, 1]\nRI=lambda: list(map(int,input().split()))\nRS=lambda: input().rstrip().split()\n#################################################\nn=RI()[0]\nti=[0]*3\ntot=[0]*3\nfor i in range(n):\n t,x,y=RI()\n tot[t]+=x\n ti[t]+=1\nfor i in (1,2):\n print([\"LIVE\",\"DEAD\"][ti[i]*5>tot[i]])\n\n\n\n\n", "hsl = [0] * 2\r\n\r\nfor i in range(int(input())):\r\n a = [int(i) for i in input().split()]\r\n k,x,y = a[0],a[1],a[2]\r\n hsl[k-1] += x - y\r\n \r\nfor i in range(2):\r\n if hsl[i] >= 0:\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")\r\n", "n = int(input())\r\nfrom collections import defaultdict\r\nd = defaultdict(list)\r\nfor i in range(n):\r\n L = [int(a) for a in input().split(\" \",2)]\r\n d[L[0]].append([L[1],L[2]])\r\ns = 0\r\nsum = 0\r\nfor i in range(len(d[1])):\r\n s = s+d[1][i][0]\r\n sum = sum + d[1][i][0]+d[1][i][1]\r\nif s>=(sum//2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\ns1=0\r\nsum1=0\r\nfor i in range(len(d[2])):\r\n s1 = s1+d[2][i][0]\r\n sum1 = sum1 + d[2][i][0]+d[2][i][1]\r\nif s1>=(sum1//2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n=int(input())\r\nax,ay,bx,by=[0]*4\r\nfor i in range(n):\r\n t,x,y=[int(x) for x in input().split()]\r\n if t==1:\r\n ax+=x\r\n ay+=y\r\n else:\r\n bx+=x\r\n by+=y\r\nif ax>=ay:print('LIVE')\r\nelse:print('DEAD')\r\nif bx>=by:print('LIVE')\r\nelse:print('DEAD')\r\n", "n = int(input())\r\n\r\ns1, s2, g1, g2 = 0, 0, 0, 0\r\nfor i in range(n):\r\n t, x, y = map(int, input().split())\r\n \r\n if t == 1:\r\n s1 += 1\r\n g1 += x\r\n \r\n if t == 2:\r\n s2 += 1\r\n g2 += x\r\n\r\nprint(('DEAD', 'LIVE')[g1 >= s1 * 5])\r\nprint(('DEAD', 'LIVE')[g2 >= s2 * 5])\r\n", "n = int(input())\ntotal_a = 0\ntotal_b = 0\nrecieved_a = 0\nrecieved_b = 0\nfor poop in range(n):\n [server, x, y] = map(int, input().split())\n if server == 1:\n total_a += 10\n recieved_a += x\n else:\n total_b += 10\n recieved_b += x\nif recieved_a >= (total_a/2):\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\nif recieved_b >= (total_b/2):\n print(\"LIVE\")\nelse:\n print(\"DEAD\")", "n = int(input())\nfirst = 0\nsecond = 0\n\nfor i in range(n):\n t,x,y = tuple(map(int, input().split()))\n if t == 1:\n first += x\n first -= y\n else:\n second += x\n second -= y\n\nif first >= 0:\n print('LIVE')\nelse:\n print('DEAD')\n\nif second >= 0:\n print('LIVE')\nelse:\n print('DEAD')\n", "n=int(input())\r\na_y=0\r\na_x=0\r\nb_x=0\r\nb_y=0\r\nfor i in range(n):\r\n t,x,y=map(int,input().split())\r\n if t==1:\r\n a_x+=x\r\n a_y+=y\r\n else:\r\n b_x+=x\r\n b_y+=y\r\nif a_x>=a_y:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif b_x>=b_y:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n", "a = b = 0\r\na1 = b1 = 0\r\nfor _ in range(int(input())):\r\n t, x, y = map(int, input().split())\r\n if t==1:\r\n a+=x\r\n a1+=y\r\n else:\r\n b+=x\r\n b1+=y\r\n\r\nprint(\"LIVE\" if a>=a1 else \"DEAD\")\r\nprint(\"LIVE\" if b>=b1 else \"DEAD\")\r\n", "num = int(input())\r\npackets={1:0, 2:0}\r\ntotals ={1:0, 2:0}\r\nfor i in range(num):\r\n server, good, bad = list(map(int, input().split()))\r\n packets[server] += good\r\n totals[server] += good + bad\r\n\r\nfor i in range(1,3):\r\n if packets[i] / totals[i] >= 0.5:\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")", "t=int(input())\r\na=[0,0]\r\nb=[0,0]\r\nfor i in range(t):\r\n l=list(map(int,input().split()))\r\n if l[0]==1:\r\n l.pop(0)\r\n a[0]+=l[0]\r\n a[1]+=l[0]+l[1]\r\n elif l[0]==2:\r\n l.pop(0)\r\n b[0]+=l[0]\r\n b[1]+=l[0]+l[1]\r\nif a[0]>=a[1]//2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif b[0]>=b[1]//2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n = int(input())\r\ncount = [0, 0]\r\nfor i in range(n):\r\n a = list(map(int, input().split()))\r\n count[a[0]-1]+=a[1]-a[2]\r\n \r\nfor j in count:\r\n if j >= 0:\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")\r\n", "firstRun = True\r\ns1, c1, s2 = 0,0,0\r\nfor line in open(0):\r\n if firstRun: \r\n n = int(line)\r\n firstRun = False\r\n else:\r\n t, x, y = map(int, line.split())\r\n if t == 1:\r\n s1 += x\r\n c1 += 1\r\n else:\r\n s2 += x\r\nc2 = n - c1\r\nprint([\"DEAD\",\"LIVE\"][s1 >= 5*c1])\r\nprint([\"DEAD\",\"LIVE\"][s2 >= 5*c2])", "n = int(input())\r\nping_a = 0\r\ncnt_a = 0\r\nping_b = 0\r\ncnt_b = 0\r\nfor _ in range(n):\r\n t,x,y = map(int,input().split())\r\n if t == 1:\r\n ping_a += x\r\n cnt_a += 1\r\n else:\r\n ping_b += x\r\n cnt_b += 1\r\nif ping_a >= (cnt_a*10)//2:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif ping_b >= (cnt_b*10)//2:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "n=int(input())\r\ns1=0\r\ns2=0\r\ncount1=0\r\ncount2=0\r\nL1=[]\r\nL2=[]\r\nfor i in range(n):\r\n\tt,s,f=map(int,input().split())\r\n\tif t==1:\r\n\t\tcount1+=1\r\n\t\ts1+=s\r\n\telse:\r\n\t\tcount2+=1\r\n\t\ts2+=s\r\nL1.append(s1)\r\nL1.append(s2)\r\nL2.append(count1)\r\nL2.append(count2)\r\n\r\nfor i in range(2):\r\n\tif (L2[i]*10)/2<=L1[i]:\r\n\t\tprint(\"LIVE\")\r\n\telse:\r\n\t\tprint(\"DEAD\")", "def solution(l1):\r\n i=0\r\n a_lost,a_got=0,0\r\n b_lost,b_got=0,0\r\n while i<len(l1):\r\n got=l1[i][1]\r\n lost=l1[i][2]\r\n if l1[i][0]==1:\r\n a_lost+=lost\r\n a_got+=got\r\n else:\r\n b_lost+=lost\r\n b_got+=got\r\n i+=1\r\n \r\n if a_lost>a_got:\r\n print(\"DEAD\")\r\n else:\r\n print(\"LIVE\")\r\n if b_lost>b_got:\r\n print(\"DEAD\")\r\n else:\r\n print(\"LIVE\")\r\ndef answer():\r\n n = int(input())\r\n l1=[]\r\n while n:\r\n a=([int(x) for x in input().split()])\r\n l1.append(a)\r\n n-=1\r\n solution(l1)\r\nanswer()\r\n", "import math\r\nt = int(input())\r\nsum1 = 0\r\nsum2 = 0\r\ns1 = 0\r\ns2 = 0\r\nfor i in range(t):\r\n s, x, y = input().split()\r\n if int(s) == 1:\r\n sum1 += int(x)\r\n s1 += 1\r\n else:\r\n sum2 += int(x)\r\n s2 += 1\r\nif sum1 >= s1*5:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif sum2 >= s2*5:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Apr 3 12:59:10 2020\r\n\r\n@author: odraodE\r\n\"\"\"\r\n\r\n'''\r\nTESTO DELL'ESERCIZIO https://codeforces.com/problemset/problem/245/A\r\n'''\r\n\r\na=input()\r\na=int(a)\r\n\r\ndizio1={'mex':0,'total':0}\r\ndizio2={'mex':0,'total':0}\r\n\r\nfor x in range(a):\r\n k=input().split()\r\n if int(k[0])==1:\r\n dizio1['mex']+=10\r\n dizio1['total']+=int(k[1])\r\n dizio1['total']-=int(k[2])\r\n elif int(k[0])==2:\r\n dizio2['mex']+=10\r\n dizio2['total']+=int(k[1])\r\n dizio2['total']-=int(k[2])\r\n\r\n\r\nif dizio1['total']>=0:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n\r\n\r\nif dizio2['total']>=0:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n", "s1=0\ns2=0\nn1 =0\nn2 =0\nfor _ in range(int(input())):\n\tx = list(map(int,input().split()))\n\tif x[0] ==1:\n\t\ts1+=x[1] \n\t\tn1+=1\n\tif x[0]==2:\n\t\ts2+=x[1]\n\t\tn2+=1\nif s1>=n1*5:\n\tprint('LIVE')\nelse:\n\tprint('DEAD')\nif s2>=n2*5:\n\tprint('LIVE')\nelse:\n\tprint('DEAD')\n", "n = int(input())\r\na = [0, 0]\r\nb = [0, 0]\r\nfor i in range(n):\r\n m = list(map(int, input().split()))\r\n if m[0] == 1:\r\n a[0] = a[0] + m[1]\r\n a[1] = a[1] + m[2]\r\n else:\r\n b[0] = b[0] + m[1]\r\n b[1] = b[1] + m[2]\r\nprint('LIVE' if a[0] >= a[1] else 'DEAD')\r\nprint('LIVE' if b[0] >= b[1] else 'DEAD')\r\n", "n=int(input())\nserver1=[0,0]\nserver2=[0,0]\nfor i in range(n):\n lst=[int(x) for x in input().split()]\n if lst[0]==1:\n server1[0]+=lst[1]\n server1[1]+=10\n if lst[0] == 2:\n server2[0] += lst[1]\n server2[1] += 10\nif server1[0]/server1[1]>=0.5:\n print('LIVE')\nelse:\n print('DEAD')\nif server2[0]/server2[1]>=0.5:\n print('LIVE')\nelse:\n print('DEAD')", "# Codeforces: 245-A: System Administrator\r\na_success = 0\r\na_lost = 0\r\nb_success = 0\r\nb_lost = 0\r\n\r\nn = int(input())\r\nfor i in range(n):\r\n [node, success, lost] = map(int, input().split())\r\n if node == 1:\r\n a_success += success\r\n a_lost += lost\r\n \r\n else:\r\n b_success += success\r\n b_lost += lost\r\nif a_success >= a_lost:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif b_success >= b_lost:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n = int(input())\r\nx1, y1, x2, y2 = 0, 0, 0, 0\r\nfor i in [0]*n:\r\n t,x,y = list(map(int, input().split()))\r\n if t == 1:\r\n x1 += x\r\n y1 += y\r\n else:\r\n x2 += x\r\n y2 += y\r\nif x1 >= y1:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif x2 >= y2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "n = int(input())\nmat = [0]*3\nfor _ in range(n):\n i,x,y = map(int, input().split())\n mat[i] += x-y\n\nprint(\"LIVE\" if mat[1] >= 0 else \"DEAD\")\nprint(\"LIVE\" if mat[2] >= 0 else \"DEAD\")\n", "n = int(input())\r\na = [0, 0]\r\nb = [0, 0]\r\nfor i in range(n):\r\n inp = list(map(int, input().split()))\r\n if(inp[0] == 1):\r\n a[0] += inp[1]\r\n a[1] += inp[2]\r\n else:\r\n b[0] += inp[1]\r\n b[1] += inp[2]\r\n\r\nif(a[0] >= a[1]):\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif(b[0] >= b[1]):\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "n=int(input())\nlst1=[]\nlst2=[]\nlst3=[]\nfor j in range(n):\n x=input().split()\n lst1.append(x[0])\n lst2.append(x[1])\n lst3.append(x[2])\nlst4=list(zip(lst1,lst2,lst3))\ncounta,countb=0,0\nac1,ac2=0,0\nfor i in range(len(lst4)):\n if int(lst4[i][0])==1:\n counta+=int(lst4[i][1])+int(lst4[i][2])\n ac1+=int(lst4[i][1])\n elif int(lst4[i][0])!=1:\n countb+=int(lst4[i][1])+int(lst4[i][2])\n ac2+=int(lst4[i][1])\nif ac1*2>=counta:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\nif ac2*2>=countb:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")", "s1,s2,e1,e2 = 0,0,0,0\r\nn = int(input())\r\nfor _ in range(n):\r\n t,x,y = map(int, input().split())\r\n if t == 1:\r\n s1 += x\r\n e1 += y\r\n else:\r\n s2 += x\r\n e2 += y\r\nprint(\"LIVE\" if s1 >= e1 else \"DEAD\")\r\nprint(\"LIVE\" if s2 >= e2 else \"DEAD\")\r\n", "n=int(input())\r\nta,tb,da,db=[0]*4\r\nfor i in range (n):\r\n t,x,y=map(int,input().split())\r\n if t==1:\r\n ta+=(x+y)\r\n da+=y\r\n if (t==2):\r\n tb+=(x+y)\r\n db+=y \r\nif (ta-da>=0.5*ta):\r\n print ('LIVE')\r\nelse :\r\n print ('DEAD')\r\nif (tb-db>=0.5*tb):\r\n print ('LIVE')\r\nelse :\r\n print ('DEAD') \r\n \r\n", "n = int(input())\r\nab = [0,0]\r\nfor i in range(n):\r\n t,x,y = map(int,input().split())\r\n ab[t-1]+=x-y\r\nprint('LIVE' if ab[0]>=0 else 'DEAD')\r\nprint('LIVE' if ab[1]>=0 else 'DEAD')", "n = int(input())\r\na = A = b = B = 0\r\nfor i in range(n):\r\n C = [t, x, y] = [int(x) for x in input().split()]\r\n if t == 1:\r\n a += x\r\n A += 10\r\n else:\r\n b += x\r\n B += 10\r\nprint('LIVE' if a/A >= 0.5 else 'DEAD')\r\nprint('LIVE' if b/B >= 0.5 else 'DEAD')\r\n", "n=int(input())\r\nar=al=0\r\nbr=bl=0\r\nfor i in range(n):\r\n t,x,y=[int(j) for j in input().split()]\r\n if t==1:\r\n ar+=x\r\n al+=y\r\n else :\r\n br+=x\r\n bl+=y\r\nif ar>=al:\r\n print(\"LIVE\")\r\nelse :\r\n print(\"DEAD\")\r\nif br>=bl:\r\n print(\"LIVE\")\r\nelse :\r\n print(\"DEAD\")", "m, = map(int,input().split())\r\nca,fa,cb,fb = 0,0,0,0\r\n\r\nfor _ in range(m):\r\n t,x,y = map(int, input().split())\r\n if t==1:\r\n ca+=x\r\n fa += y\r\n else:\r\n cb+=x\r\n fb+=y\r\n\r\nprint(\"LDIEVAED\"[ca<fa::2])\r\nprint(\"LDIEVAED\"[cb<fb::2])", "n=int(input())\r\np1x=0;p2x=0;p1y=0;p2y=0\r\nfor i in range(n):\r\n\tt,x,y=map(int,input().split())\r\n\tif t==1:\r\n\t\tp1x+=x\r\n\t\tp1y+=y\r\n\telse:\r\n\t\tp2x+=x\r\n\t\tp2y+=y\r\nT1=p1x+p1y\r\nT2=p2x+p2y\r\nif p1x>=(T1//2):\r\n\tprint('LIVE')\r\nelse:\r\n\tprint('DEAD')\r\nif p2x>=(T2//2):\r\n\tprint('LIVE')\r\nelse:\r\n\tprint('DEAD')", "n = int(input())\nxsa=0\nysa=0\nxsb=0\nysb=0\nfor i in range(n):\n inp = [int(i) for i in input().split()]\n t = inp[0]\n x = inp[1]\n y = inp[2]\n if t == 1:\n xsa+=x\n ysa+=y\n else:\n xsb+=x\n ysb+=y\nif xsa>=ysa:\n print('LIVE')\nelse:\n print('DEAD')\nif xsb>=ysb:\n print('LIVE')\nelse:\n print('DEAD')", "m=int(input())\r\n\r\ncnt1=cnt2=0\r\ns1=s2=x1=x2=0\r\nfor l in range(m):\r\n t,x,y=map(int,input().split())\r\n \r\n \r\n if t==1:\r\n cnt1+=x+y\r\n x1+=x\r\n else:\r\n cnt2+=x+y\r\n x2+=x\r\n\r\nif cnt1<=2*x1:\r\n s1=1\r\nif cnt2<=2*x2:\r\n s2=1\r\n\r\nif s1==1:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif s2==1:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "#!/usr/bin/python3\n\nn = int(input())\nsend = [[], []]\nfor _ in range(n):\n t, x, y = tuple(map(int, input().split()))\n send[t - 1].append(x)\nfor _ in range(2):\n print('LIVE' if 2 * sum(send[_]) >= 10 * len(send[_]) else 'DEAD')\n", "cases = int(input())\r\n\r\nax = 0\r\nay = 0\r\n\r\nbx = 0\r\nby = 0\r\n\r\nwhile cases:\r\n cases -= 1\r\n t, x, y = map(int, input().split())\r\n\r\n if t == 1:\r\n ax += x\r\n ay += y\r\n else:\r\n bx += x\r\n by += y\r\n\r\nif ax//ay >= 1:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif bx//by >= 1:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "f=lambda:map(int,input().split())\r\nn=int(input())\r\nx1=x2=y1=y2=0\r\nwhile n:\r\n a,x,y=f()\r\n if a==1:\r\n x1+=x;y1+=y\r\n else:\r\n x2+=x;y2+=y\r\n n-=1\r\nprint('LDIEVAED'[x1<y1::2])\r\nprint('LDIEVAED'[x2<y2::2])\r\n\r\n", "n=int(input())\r\na,b,x,y=0,0,0,0\r\n\r\nfor i in range(n):\r\n\tq,w,e = map(int,input().split())\r\n\tif(q==1):\r\n\t\ta+=w\r\n\t\tb+=e\r\n\telse:\r\n\t\tx+=w\r\n\t\ty+=e\r\n\r\nif(a>=b):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\nif(x>=y):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")", "n=input()\r\naWon=[]\r\naLost=[]\r\nbWon=[]\r\nbLost=[]\r\nfor i in range(0,int(n)):\r\n p=input().split()\r\n if int(p[0])==1:\r\n aWon.append(int(p[1]))\r\n aLost.append(int(p[2]))\r\n elif int(p[0])==2:\r\n bWon.append(int(p[1]))\r\n bLost.append(int(p[2]))\r\nif sum(aWon)>=sum(aLost):\r\n print(\"LIVE\")\r\nelif sum(aWon)<sum(aLost):\r\n print(\"DEAD\")\r\nif sum(bWon)>=sum(bLost):\r\n print(\"LIVE\")\r\nelif sum(bWon)<sum(bLost):\r\n print(\"DEAD\")\r\n", "n = int(input())\na = [0, 0]\nb = [0, 0]\nfor i in range(n):\n t, x, y = (int(x) for x in input().split())\n if t == 1:\n a[0] += x\n a[1] += y\n else:\n b[0] += x\n b[1] += y\nif a[0] >= a[1]:\n print('LIVE')\nelse:\n print('DEAD')\nif b[0] >= b[1]:\n print('LIVE')\nelse:\n print('DEAD')\n", "x1=0; y1=0\r\nx2=0; y2=0\r\n\r\nfor i in range(int(input())):\r\n ab, x, y=map(int, input().split())\r\n if ab==1:\r\n x1+=x\r\n y1+=y\r\n else: \r\n x2+=x\r\n y2+=y\r\nif x1>=(x1+y1)//2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n \r\nif x2>=(x2+y2)//2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n ", "n = int(input())\r\na_r, a_l = 0, 0\r\nb_r, b_l = 0, 0\r\nfor i in range(n):\r\n p = [int(i) for i in input().split()]\r\n if p[0]==1:\r\n a_l+= p[2]\r\n a_r+= p[1]\r\n else:\r\n b_l+= p[2]\r\n b_r+= p[1]\r\nif a_r>=a_l:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif b_r>=b_l:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "n=int(input())\r\na=[[0, 0], [0, 0]]\r\nb=[]\r\nfor i in range(n):\r\n b=input().split()\r\n a[int(b[0])-1][0]+=int(b[1])\r\n a[int(b[0])-1][1]+=int(b[2])\r\nif a[0][0]>=a[0][1]:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif a[1][0]>=a[1][1]:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "x = int(input())\r\ny = []\r\n\r\nb = 0\r\nc = 0\r\n\r\na = 0\r\nd = 0\r\n\r\nfor i in range(x):\r\n y.append(list(map(int, input().split(\" \"))))\r\n\r\nfor j in range(x):\r\n if y[j][0] == 1:\r\n b += 10\r\n c += y[j][1]\r\n else:\r\n a += 10\r\n d += y[j][1]\r\n\r\nif c >= b/2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n \r\nif d >= a/2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "t=int(input())\r\ns1=l1=s2=l2=0\r\nfor _ in range(t):\r\n n,x,y=map(int,input().split())\r\n if(n==1):\r\n s1+=x\r\n l1+=y\r\n else:\r\n s2+=x\r\n l2+=y\r\nif(s1>=l1):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif(s2>=l2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n = int(input())\ntotal_a = 0\ntotal_b = 0\nfor _ in range(n):\n t, x, y = map(int, input().split())\n if t == 1:\n total_a += x - y\n else:\n total_b += x - y\n \nif total_a >= 0:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\n\nif total_b >= 0:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\n", "v1,v2,s1,s2=0,0,0,0\r\ndef ping(l):\r\n global v1,v2,s1,s2\r\n if l[0]==1:\r\n v1+=l[1]\r\n s1=s1+l[1]+l[2]\r\n else:\r\n v2+=l[1]\r\n s2=s2+l[1]+l[2]\r\n \r\nfor t in range(int(input())): \r\n l=list(map(int,input().split()))\r\n ping(l)\r\nif v1>=(s1/2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif v2>=(s2/2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n \r\n\r\n ", "n=int(input())\r\np1=0\r\ns1=0\r\np2=0\r\ns2=0\r\nfor i in range(0,n):\r\n\ttxy=input().split()\r\n\tt=int(txy[0])\r\n\tx=int(txy[1])\r\n\ty=int(txy[2])\r\n\tif(t==1):\r\n\t\tp1+=10\r\n\t\ts1+=x\r\n\telse:\r\n\t\tp2+=10\r\n\t\ts2+=x\r\nif(s1>=p1/2):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\nif(s2>=p2/2):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\n\r\n", "n = int(input())\r\nl = []\r\nX1 = []\r\nY1 = []\r\nX2 = []\r\nY2 = []\r\nfor i in range(n):\r\n a=list(input().split())\r\n for i in range(len(a)):\r\n a[i]=int(a[i])\r\n if a[0]==1:\r\n X1.append(a[1])\r\n Y1.append(a[2])\r\n else:\r\n X2.append(a[1])\r\n Y2.append(a[2])\r\nif sum(X1)>=sum(Y1):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif sum(X2)>=sum(Y2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\n \r\n", "n = int(input())\r\naReached = 0\r\naDropped = 0\r\nbReached = 0\r\nbDropped = 0\r\nfor i in range(n):\r\n t, x, y = map(int, input().split(\" \"))\r\n if t == 1:\r\n aReached += x\r\n aDropped += y\r\n else:\r\n bReached += x\r\n bDropped += y\r\nif aReached >= (aReached + aDropped) // 2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif bReached >= (bReached + bDropped) // 2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "import sys\r\nimport datetime\r\n\r\ninput = sys.stdin.readline\r\n\r\nd = {\"1\": [0, 0], \"2\": [0, 0]}\r\n\r\nfor i in range(int(input())):\r\n t, y, x = map(int, input().split())\r\n d[str(t)][1]+=1\r\n d[str(t)][0]+=y\r\n\r\nfor i in d.items():\r\n i = i[1]\r\n if (i[1]*10)//2 <= i[0]:\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")", "n=int(input())\na1=b1=a2=b2=0\nfor i in range(n):\n\ttmp=input().split()\n\tif(int(tmp[0])==1):\n\t\ta1+=10\n\t\tb1+=int(tmp[1])\n\telse:\n\t\ta2+=10\n\t\tb2+=int(tmp[1])\nif(b1>=a1/2):\n\tprint(\"LIVE\")\nelse:\n\tprint(\"DEAD\")\nif(b2>=a2/2):\n\tprint(\"LIVE\")\nelse:\n\tprint(\"DEAD\")", "n = int(input())\r\nq,w,e,r = 0,0,0,0\r\nfor i in range(n):\r\n\ta = list(map(int,input().split()))\r\n\tif a[0] == 1:\r\n\t\tq = q+a[1]\r\n\t\tw+=1\r\n\telse:\r\n\t\te = e+a[1]\r\n\t\tr+=1\r\nif q/w>=5:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\nif e/r>=5:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\n\r\n", "a,b=[],[]\r\nn=int(input())\r\nfor i in range(n):\r\n t,x,y=map(int,input().split())\r\n if t==1:\r\n a.append(x)\r\n else:\r\n b.append(x)\r\nif len(a)*5<=sum(a):\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif len(b)*5<=sum(b):\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "n = int(input())\r\nx1 = 0\r\ny1 = 0\r\nx2 = 0\r\ny2 = 0\r\nfor i in range(n):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n x1 += x\r\n y1 += y\r\n else:\r\n x2 += x\r\n y2 += y\r\nif x1 >= y1:\r\n print(\"LIVE\")\r\nelif x1 < y1:\r\n print(\"DEAD\")\r\nif x2 < y2:\r\n print(\"DEAD\")\r\nelif x2 >= y2:\r\n print(\"LIVE\")\r\n", "n = int(input())\r\none, two = 0, 0\r\nfor i in range(n):\r\n a = list(map(int, input().split()))\r\n t, x, y = a[0], a[1], a[2]\r\n if t == 1:\r\n one += x - y\r\n else:\r\n two += x - y\r\n\r\nprint('DEAD' if one < 0 else 'LIVE')\r\nprint('DEAD' if two < 0 else 'LIVE')", "t = int(input())\r\nn=t\r\ncount = 0\r\na1 = []\r\nb1 = []\r\nwhile t!=0:\r\n t-=1 \r\n t1,a,b = [int(i) for i in input().split()]\r\n if t1 == 1 :\r\n a1.append(a)\r\n count+=1 \r\n else:\r\n b1.append(a)\r\nm1 = count*5 \r\nm2 = (n-count)*5\r\nif sum(a1)>=m1:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif sum(b1)>=m2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "def main():\r\n n = int(input())\r\n a = [0, 0]\r\n b = [0, 0]\r\n for _ in range(n):\r\n t, x, y = list(map(int, input().split()))\r\n if t == 1:\r\n a[0] += x\r\n a[1] += y\r\n else:\r\n b[0] += x\r\n b[1] += y\r\n if a[0] >= a[1]:\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")\r\n if b[0] >= b[1]:\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")\r\n\r\nif __name__ == '__main__':\r\n main()", "n=int(input())\r\na,ar,b,br=0,0,0,0\r\nfor i in range(n):\r\n x=list(map(int,input().split()))\r\n if(x[0]==1):\r\n a+=10\r\n ar+=x[1]\r\n else:\r\n b+=10\r\n br+=x[1]\r\nprint('DLEIAVDE'[ar>=a//2::2])\r\nprint('DLEIAVDE'[br>=b//2::2])\r\n", "n=int(input())\r\nsum1x=0\r\nsum1y=0\r\nsum2x=0\r\nsum2y=0\r\n\r\nfor i in range(n):\r\n\tt,x,y=map(int,input().split())\r\n\tif (t==1):\r\n\t\tsum1x+=x\r\n\t\tsum1y+=y\r\n\tif(t==2):\r\n\t\tsum2x+=x\r\n\t\tsum2y+=y\r\nif(sum1x>=sum1y):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\nif(sum2x>=sum2y):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")", "q = int(input())\r\n\r\nax = ay = 0\r\nbx = by = 0\r\n\r\nfor i in range(q):\r\n server, x, y = map(int, input().split()) \r\n if server == 1:\r\n ax += x\r\n ay += y\r\n else:\r\n bx += x\r\n by += y\r\n \r\nprint('LIVE' if ax >= ay else 'DEAD')\r\nprint('LIVE' if bx >= by else 'DEAD')", "n=int(input())\r\nxa=ya=xb=yb=0\r\nfor i in range(n):\r\n\tt,x,y=map(int,input().split())\r\n\tif t == 1:\r\n\t\txa+=x\r\n\t\tya+=y\r\n\telse:\r\n\t\txb+=x\r\n\t\tyb+=y\r\nif xa>=ya:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\nif xb>=yb:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")", "n = int(input())\r\nar = al = 0\r\nbr = bl = 0\r\n\r\nfor _ in range(n):\r\n t, x, y = [int(x) for x in input().split()]\r\n if t == 1:\r\n ar += x\r\n al += y\r\n else:\r\n br += x\r\n bl += y\r\n\r\nif ar >= al:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif br >= bl:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "# import sys\r\n# sys.stdin=open(\"test11.in\",\"r\")\r\n# sys.stdout=open(\"test11.out\",\"w\")\r\n\r\nn=int(input())\r\ns1=0\r\ns2=0\r\nu1=0\r\nu2=0\r\nfor i in range(n):\r\n\tl=list(map(int,input().split()))\r\n\tif(l[0]==1):\r\n\t\tu1+=1\r\n\t\ts1+=l[1]\r\n\telif(l[0]==2):\r\n\t\tu2+=1\r\n\t\ts2+=l[1]\r\n\r\nif(u1*10/2<=s1):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\nif(u2*10/2<=s2):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")", "n = int(input()); AL = AR = BL = BR = 0\r\nfor i in range(n):\r\n a, s, d = map(int, input().split())\r\n if a == 1:\r\n AL += s; AR += d\r\n else:\r\n BL += s; BR += d\r\nprint([\"LIVE\",\"DEAD\"][AL<AR]); print([\"LIVE\",\"DEAD\"][BL<BR])", "c = [[0, 0], [0, 0]]\n\nfor i in range(int(input())):\n\n l = [int(x) for x in input().split()]\n\n c[l[0] - 1][0] += l[1]\n\n c[l[0] - 1][1] += l[2]\n\nfor i in range(2):\n\n print('LIVE' if c[i][0] >= c[i][1] else 'DEAD')", "n = int(input())\r\nx = 0\r\nxa = 0\r\ny = 0\r\nya = 0\r\nfor i in range(n):\r\n s = input()\r\n s = s.split()\r\n if s[0] == \"1\":\r\n x = x + int(s[1])\r\n xa = xa + int(s[1]) + int(s[2])\r\n elif s[0] == \"2\":\r\n y = y + int(s[1])\r\n ya = ya + int(s[1]) + int(s[2])\r\nif x >= xa//2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n \r\nif y >= ya//2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "a_cnt = 0\r\nb_cnt = 0\r\nfor _ in range(int(input())):\r\n (t, x, y) = [int(i) for i in input().strip().split(' ')]\r\n if t == 1:\r\n a_cnt += (x-y)\r\n if t == 2:\r\n b_cnt += (x-y)\r\n\r\nif a_cnt >= 0:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif b_cnt >= 0:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n", "n=int(input())\r\nsum_a=0\r\nalive_a=0\r\nsum_b=0\r\nalive_b=0\r\nfor i in range(n):\r\n\tx,y,z=map(int,input().split())\r\n\tif x==1:\r\n\t\tsum_a+=10\r\n\t\talive_a+=y\r\n\telse:\r\n\t\tsum_b+=10\r\n\t\talive_b+=y\r\nif alive_a>=sum_a/2:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\nif alive_b>=sum_b/2:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")", "def main():\n a_success = 0\n a_failure = 0\n b_success = 0\n b_failure = 0\n\n for _ in range(int(input())):\n [t, x_success, x_failure] = [int(_) for _ in input().split()]\n if t == 1:\n a_success += x_success\n a_failure += x_failure\n elif t == 2:\n b_success += x_success\n b_failure += x_failure\n\n print('LIVE' if a_success >= a_failure else 'DEAD')\n print('LIVE' if b_success >= b_failure else 'DEAD')\n\n\nif __name__ == '__main__':\n main()\n", "a1 = []\r\na2 = []\r\nb1 = []\r\nb2 = []\r\nfor _ in range(int(input())):\r\n p1, a, b = map(int, input().split())\r\n if p1 == 1:\r\n a1.append(a)\r\n a2.append(b)\r\n else:\r\n b1.append(a)\r\n b2.append(b)\r\n\r\ns1 = sum(a1)\r\ns2 = sum(a2)\r\ns3 = sum(b1)\r\ns4 = sum(b2)\r\nif (s1+s2)//2 <= s1:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif (s3+s4)//2 <= s3:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "n = int(input())\na_accept = 0\na_lost = 0\nb_accept = 0\nb_lost = 0\nfor i in range(n):\n sever, post, lost = map(int, input().split())\n if sever == 1:\n a_accept = a_accept + post\n a_lost = a_lost + lost\n if sever == 2:\n b_accept = b_accept + post\n b_lost = b_lost + lost\n\nif a_accept >= a_lost:\n a_live = True\nelse:\n a_live = False\n\nif b_accept >= b_lost:\n b_live = True\nelse:\n b_live = False\n\nif a_live:\n print('LIVE')\nelse:\n print('DEAD')\n\nif b_live:\n print('LIVE')\nelse:\n print('DEAD')", "n = int(input())\r\na_suc = 0\r\na_fai = 0\r\nb_suc = 0\r\nb_fai = 0\r\nfor i in range(n):\r\n s = list(map(int, input().split()))\r\n if s[0] == 1:\r\n a_suc+=s[1]\r\n a_fai+=s[2]\r\n else:\r\n b_suc+=s[1]\r\n b_fai+=s[2]\r\n \r\nif a_suc>=a_fai:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif b_suc>=b_fai:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\") ", "as1 ,bs1, as2, bs2 =0, 0, 0, 0\nnumber = int(input())\nfor m in range(number):\n a, b, c = map(int, input().split())\n if a == 1:\n as1 += b\n as2 += c\n elif a == 2:\n bs1 += b\n bs2 += c\nif as1 >= as2:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\nif bs1 >= bs2:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\n", "n = int(input())\r\nnum1 = 0\r\nnum2 = 0\r\nfor i in range(n):\r\n t,x,y = map(int,input().split())\r\n if t == 1:\r\n num1 += 5\r\n num1 -= y\r\n else:\r\n num2 += 5\r\n num2 -= y\r\nif num1 >= 0:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif num2 >= 0:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "n = int(input())\r\nay = 0\r\nan = 0\r\nby = 0\r\nbn = 0\r\nfor i in range(n):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n ay += x\r\n an += y\r\n else:\r\n by += x\r\n bn += y\r\nif ay >= an:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif by >= bn:\r\n print('LIVE')\r\nelse:\r\n print('DEAD') ", "n = int(input())\r\nr = [[0,0,0],[0,0,0]]\r\nfor i in range(n):\r\n t,x,y = map(int, input().split())\r\n if t == 1:\r\n r[0][0] += 1\r\n r[0][1] += x\r\n r[0][2] += y\r\n else:\r\n r[1][0] += 1\r\n r[1][1] += x\r\n r[1][2] += y\r\nfor i in r:\r\n if i[1] < i[2]:\r\n print('DEAD')\r\n else:\r\n print('LIVE')", "n = int(input())\r\nd = []\r\ne = []\r\none = []\r\ntwo = []\r\nfor i in range(n):\r\n\ts = [int(i) for i in input().split()]\r\n\td.append(s)\r\n\r\ndef fil(liste):\r\n\treturn [liste[0] , liste[-2] - liste[-1]]\r\n\r\nfor i in d:\r\n\te.append(fil(i))\r\n\r\nfor i in e:\r\n\tif i[0] == 1:\r\n\t\tone.append(i[1])\r\n\telse:\r\n\t\ttwo.append(i[1])\r\nallin = [one,two]\r\nfor i in allin:\r\n\tif sum(i)>=0:\r\n\t\tprint(\"LIVE\")\r\n\telse:\r\n\t\tprint(\"DEAD\")", "n = int(input())\r\ni = int(0)\r\nk1 = int(0)\r\nk2 = int(0)\r\no = int(0)\r\np = int(0)\r\nfor i in range(n):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n k1 += x + y\r\n o += x\r\n else:\r\n k2 += x + y\r\n p += x\r\nif k1 / 2 <= o:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif k2 / 2 <= p:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n \r\n \r\n", "#Jai Hanuman\r\n#Om Nama Shivai\r\n#Jai Shree Krisha\r\n#Jai Shree Ram\r\n#Jai Maa BuriThakram\r\n#Jai Maa Kali\r\n#Jai Maa Durga\r\n#Radha-Krisha\r\na = list()\r\nb = list()\r\nfor _ in range(int(input())):\r\n t,x,y = map(int, input().split())\r\n if(t == 1):\r\n a.append(x)\r\n else:\r\n b.append(x)\r\nsm = sum(a)\r\nsmh = (len(a)*10)//2\r\nif(sm >= smh):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nsm1 = sum(b)\r\nsmh1 = (len(b)*10)//2\r\nif(sm1 >= smh1):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\n\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,b,losta,lostb=0,0,0,0\r\nfor i in range(n):\r\n t,x,y=[int(x) for x in input().split()]\r\n if t==1:\r\n a+=x \r\n losta+=y\r\n else:\r\n b+=x \r\n lostb+=y \r\nif a>=losta:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif b>=lostb:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "def max1(a):\r\n\tp = a[0]\r\n\tfor x in a:\r\n\t\tif x > p:\r\n\t\t\tp = x\r\n\treturn p\r\n\r\n\r\ndef prlist(a):\r\n\tfor x in a:\r\n\t\tprint(x, end = \" \")\r\n\r\n\r\n#row, col = list(map(int, input().split()))\r\n#a = list(map(int, input().split()))\r\nn = int(input())\r\na = []\r\nfor i in range(n):\r\n\tb = list(map(int, input().split()))\r\n\ta.append(b)\r\nk1 = 0\r\nk2 = 0\r\nt1 = 0\r\nt2 = 0\r\nfor i in range(n):\r\n\tif a[i][0] == 1:\r\n\t\tk1 += 1\r\n\t\tt1 += a[i][1]\r\n\telse:\r\n\t\tk2 += 1\r\n\t\tt2 += a[i][1]\r\nif k1 * 5 > t1:\r\n\tprint(\"DEAD\")\r\nelse:\r\n\tprint(\"LIVE\")\r\nif k2 * 5 > t2:\r\n\tprint(\"DEAD\")\r\nelse:\r\n\tprint(\"LIVE\")\r\n", "n=int(input())\r\nl=[]\r\nfor i in range (n):\r\n s=input()\r\n s=s.split()\r\n s=[int(i) for i in s]\r\n l.append(s)\r\n \r\n#0=sent, 1=total\r\na=[0,0]\r\nb=[0,0]\r\n\r\nfor i in l:\r\n #ping a\r\n if(i[0]==1):\r\n a[0]+=i[1]\r\n a[1]+=(i[1]+i[2])\r\n else:\r\n b[0]+=i[1]\r\n b[1]+=(i[1]+i[2])\r\n \r\nif(a[0]>=(a[1]/2)):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif(b[0]>=(b[1]/2)):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n = int(input())\r\nres1success = 0\r\nres1fail = 0\r\nres2success = 0\r\nres2fail = 0\r\nfor i in range(n):\r\n s, x, y = map(int, input().split())\r\n if s == 1:\r\n res1success += x\r\n res1fail += y\r\n else:\r\n res2success += x\r\n res2fail += y\r\n\r\nif res1success >= res1fail:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif res2success >= res2fail:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "n=int(input())\r\nn_a = n_b = 0\r\nx_a = x_b = 0\r\nfor i in range(n):\r\n t,x,y = input().split()\r\n if t=='1':\r\n x_a += int(x)\r\n n_a += 10\r\n else:\r\n x_b += int(x)\r\n n_b += 10\r\nprint(\"LIVE\" if x_a>=n_a/2 else \"DEAD\")\r\nprint(\"LIVE\" if x_b>=n_b/2 else \"DEAD\")\r\n", "n = int(input());a1 = a2 = a3 = a4 = 0\r\nfor i in range(n):\r\n a,b,c = map(int,input().split())\r\n if a == 1:a1 += b;a2 += 10\r\n else:a3 += b;a4 += 10\r\nif a1 >= a2 // 2:print(\"LIVE\")\r\nelse:print(\"DEAD\")\r\nif a3 >= a4 // 2:print(\"LIVE\")\r\nelse:print(\"DEAD\")", "#Codeforce 245A\r\nline=int(input())\r\nxa=0\r\nxb=0\r\nya=0\r\nyb=0\r\nfor i in range(line):\r\n t,x,y=(int(v) for v in input().split())\r\n if t == 1:\r\n xa += x\r\n ya += y\r\n else:\r\n xb += x\r\n yb += y\r\nif xa >= ya:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif xb >= yb:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "t = int(input())\r\nd, e = '', ''\r\nl, li, lii, liii = [], [], [], []\r\nfor i in range(t):\r\n a, b ,c = map(int, input().split())\r\n if a == 1:\r\n l.append(b)\r\n li.append(c)\r\n else:\r\n lii.append(b)\r\n liii.append(c)\r\nd, e, f, g = sum(l), sum(li), sum(lii), sum(liii)\r\nh, i = '', ''\r\nif d >= e:\r\n h = 'LIVE'\r\nelse:\r\n h = 'DEAD'\r\nif f >= g:\r\n i = 'LIVE'\r\nelse:\r\n i = 'DEAD'\r\nprint(h)\r\nprint(i)", "commands=int(input())\nping_a_sent=0\nping_a_lost=0\nping_b_sent=0\nping_b_lost=0\nfor i in range(commands):\n\toutput=input().split(\" \")\n\toutput=[int(output[i]) for i in range(3)]\n\tif output[0]==1:\n\t\tping_a_sent+=output[1]\n\t\tping_a_lost+=output[2]\n\telse:\n\t\tping_b_sent+=output[1]\n\t\tping_b_lost+=output[2]\nif ping_a_sent-ping_a_lost>=0:\n\tprint(\"LIVE\")\nelse:\n\tprint(\"DEAD\")\nif ping_b_sent-ping_b_lost>=0:\n\tprint(\"LIVE\")\nelse:\n\tprint(\"DEAD\")\n", "n = int(input())\r\nx1, y1, x2, y2 = 0, 0, 0, 0\r\nfor _ in range(n):\r\n a = list(map(int, input().split()))\r\n if a[0] == 1:\r\n x1 = x1+a[1]\r\n y1 = y1+a[2]\r\n\r\n else:\r\n x2 = x2+a[1]\r\n y2 = y2+a[2]\r\n\r\nif x1>=y1:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n \r\nif x2>=y2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "n = int(input())\r\nmang = [[float(i) for i in input().split()] for j in range(n)]\r\na , b , a1 , b1 = 0 , 0 , 0 , 0\r\nfor i in range(n):\r\n if mang[i][0]==1:\r\n a = a + mang[i][1] +mang[i][2]\r\n a1 = a1 + mang[i][1]\r\n else:\r\n b = b + mang[i][1] + mang[i][2]\r\n b1 = b1 + mang[i][1]\r\nif ( a1 >= a/2 ):\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif ( b1 >= b/2):\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "import sys\n#f = sys.stdin\n# f = open(\"input.txt\", \"r\")\nn = int(input())\na, b = [[],[]], [[],[]]\nfor i in range(n):\n t, xi, yi = map(int, input().split())\n if t == 1:\n a[0].append(xi)\n a[1].append(yi)\n else:\n b[0].append(xi)\n b[1].append(yi)\nif sum(a[0]) >= sum(a[1]):\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\nif sum(b[0]) >= sum(b[1]):\n print(\"LIVE\")\nelse:\n print(\"DEAD\")", "n = int(input())\n\naSuccess = 0\nbSuccess = 0\naFail = 0\nbFail = 0 \n\nfor _ in range(n):\n\n t, success, fail = map(int, input().split())\n\n if t == 1:\n aSuccess += success; aFail += fail\n else:\n bSuccess += success; bFail += fail\n\nif aSuccess >= aFail: print('LIVE')\nelse: print('DEAD')\n\nif bSuccess >= bFail: print('LIVE')\nelse: print('DEAD')", "a, b = 0, 0\r\nsum_a, sum_b = 0, 0\r\nfor i in range(int(input())):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n sum_a += x\r\n sum_a += y\r\n a += (x + y) - y\r\n else:\r\n sum_b += x\r\n sum_b += y\r\n b += (x + y) - y\r\n\r\nprint(\"LIVE\") if a >= sum_a/2 else print(\"DEAD\")\r\nprint(\"LIVE\") if b >= sum_b/2 else print(\"DEAD\")", "n = int(input())\r\nz = 0\r\nx = 0\r\nc = 0\r\nv = 0\r\nfor i in range(n):\r\n a,b,k = map(int,input().split())\r\n if a == 1:\r\n z += b\r\n x += 10\r\n else:\r\n c += b\r\n v += 10\r\nif z >= int(x / 2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif c >= int(v / 2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n = int(input())\na, b = [0, 0], [0, 0]\nfor _ in range(n):\n t, x, y = (int(i) for i in input().split())\n z = a if t == 1 else b\n z[0] += x\n z[1] += y\nfor z in [a, b]:\n res = \"LIVE\" if 2 * z[0] >= sum(z) else \"DEAD\"\n print(res)\n", "x=int(input())\nsm=[]\nfor i in range(x):\n sm.append(list(map(int,input().split())))\nasuccess=0\nalost=0\nbsuccess=0\nblost=0\nfor l in range(x):\n if sm[l][0]==1:\n asuccess=asuccess+sm[l][1]\n alost=alost+sm[l][2]\n else:\n bsuccess=bsuccess+sm[l][1]\n blost=blost+sm[l][2]\nif asuccess>=alost:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\nif bsuccess>=blost:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\n", "T=int(input())\r\na=[[0,0],[0,0]]\r\nfor z in range(T):\r\n t,b,c=[int(v) for v in input().split()]\r\n if t==1:\r\n a[0][0]+=b\r\n a[0][1]+=c\r\n if t==2:\r\n a[1][0]+=b\r\n a[1][1]+=c\r\nif a[0][0]>=a[0][1]: print(\"LIVE\")\r\nelse: print('DEAD')\r\nif a[1][0]>=a[1][1]: print(\"LIVE\")\r\nelse: print(\"DEAD\")", "n = int(input())\r\nxa, ya, xb, yb = 0, 0, 0, 0\r\nfor i in range(n):\r\n t, x, y = map(int, input().split())\r\n if(t == 1): \r\n xa += x\r\n ya += y\r\n else:\r\n xb += x\r\n yb += y\r\nif(xa >= ya): \r\n print('LIVE')\r\nelse: print('DEAD')\r\nif(xb >= yb): print('LIVE')\r\nelse: print('DEAD')", "a=[0,0]\r\nfor i in range(int(input())):\r\n t,x,y=map(int,input().split())\r\n a[t-1]+=x-y\r\nfor z in a:\r\n print([\"LIVE\",\"DEAD\"][z<0])\r\n", "n,a=int(input()),['',[],[]]\r\nfor _ in [0]*n:\r\n x,y,_=map(int,input().split())\r\n a[x].append(y)\r\nprint(*(['LIVE','DEAD'][sum(a[x])<5*len(a[x])] for x in [1,2]),sep='\\n')", "n=int(input())\r\na=[i for i in range (0,n)]\r\nfor i in range (0,n):\r\n\ta[i]=list(map(int,input().split()))\r\npats=0\r\npaus=0\r\npbts=0\r\npbus=0\r\nfor j in range (0,n):\r\n\tif a[j][0]==1:\r\n\t\tpats=pats+10\r\n\t\tpaus=paus+a[j][2]\r\n\tif a[j][0]==2:\r\n\t\tpbts=pbts+10\r\n\t\tpbus=pbus+a[j][2]\r\nif (pats-paus)>=paus:\r\n\tprint(\"LIVE\")\r\nif (pats-paus)<paus:\r\n\tprint(\"DEAD\")\r\nif (pbts-pbus)>=pbus:\r\n\tprint(\"LIVE\")\r\nif (pbts-pbus)<pbus:\r\n\tprint(\"DEAD\")\r\n\r\n", "n = int(input())\r\nping_a=0\r\nping_b=0\r\ncount_a=0\r\nfor i in range(n):\r\n x,y,z=input().split()\r\n if int(x)==1:\r\n ping_a= ping_a + int(y)\r\n count_a=count_a+1\r\n else:\r\n ping_b=ping_b + int(y)\r\n\r\ncount_b = n - count_a\r\ncount_a= (count_a*10)//2\r\ncount_b = (count_b*10)//2\r\nif ping_a>=count_a:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif ping_b>=count_b:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n=int(input())\r\nsum1=0\r\nsum2=0\r\nz=0\r\nc=0\r\nfor i in range(n):\r\n\tt,x,y=map(int,input().split())\r\n\tif t==1:\r\n\t\tsum1+=x\r\n\t\tz+=1\r\n\tif t==2:\r\n\t\tsum2+=x\r\n\t\tc+=1\t\t\r\nif sum1>=int(5*z):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\t\r\nif sum2>=int(5*c):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\t", "n=int(input())\r\nc1,c2=0,0\r\na,b=0,0\r\nfor i in range(n):\r\n t,x,y=map(int,input().split())\r\n if t==1:\r\n c1+=1\r\n a+=x\r\n else:\r\n c2+=1\r\n b+=x\r\nif a>=c1*5:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif b>=c2*5:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n \r\n \r\n \r\n \r\n", "n=int(input())\r\na=0\r\nb=0\r\nc=0\r\nd=0\r\nfor i in range(n):\r\n\tx,y,z=list(map(int,input().split()))\r\n\tif x==1:\r\n\t\ta+=y\r\n\t\tb+=z\r\n\telse:\r\n\t\tc+=y\r\n\t\td+=z\r\nif a>=b:\r\n\tprint('LIVE')\r\nelse:\r\n\tprint('DEAD')\r\nif c>=d:\r\n\tprint('LIVE')\r\nelse:\r\n\tprint('DEAD')", "n = int(input())\r\ncount1, count2, count3, count4 = 0, 0, 0, 0\r\nfor i in range(n):\r\n t, x, y = [int(j) for j in input().split()]\r\n if t == 1:\r\n count1 += x\r\n count2 += 10\r\n else:\r\n count3 += x\r\n count4 += 10\r\nif 2 * count1 >= count2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif 2 * count3 >= count4:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "b1,c1,b2,c2=0,0,0,0\r\nfor i in range(int(input())):\r\n a,b,c = map(int,input().split())\r\n if a==1:\r\n b1+=b\r\n c1+=c\r\n else:\r\n b2+=b\r\n c2+=c\r\nif b1//c1>0 or c1==0:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif b2//c2>0 or c2==0:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "cases = int(input())\r\n\r\nax = 1\r\nay = 1\r\n\r\nbx = 1\r\nby = 1\r\n\r\nwhile cases:\r\n cases -= 1\r\n t, x, y = map(int, input().split())\r\n\r\n if t == 1:\r\n ax += x\r\n ay += y\r\n else:\r\n bx += x\r\n by += y\r\n\r\nif ax//ay >= 1:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif bx//by >= 1:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "pinga=0\npingb=0\nareach=0\nalost=0\nbreach=0\nblost=0\nfor _ in range(int(input())):\n arr=list(map(int,input().split()))\n if arr[0]==1:\n pinga+=1\n areach+=arr[1]\n alost+=arr[2]\n else:\n pingb+=1\n breach+=arr[1]\n blost+=arr[2]\nasent=areach+alost\nbsent=breach+blost\nif areach>=asent/2:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\nif breach>=bsent/2:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\n \t\t \t \t\t\t\t \t \t\t\t \t\t \t\t", "def printing(pack,count):\r\n if pack >= (count * 10)//2:\r\n return \"LIVE\"\r\n else:\r\n return \"DEAD\"\r\npackA = 0\r\npackB = 0\r\ncountA = 0\r\ncountB = 0\r\nn = int(input())\r\nfor i in range(n):\r\n nums = [int(i) for i in input().split()]\r\n if nums[0] == 1:\r\n countA += 1\r\n packA += nums[1]\r\n else:\r\n countB += 1\r\n packB += nums[1]\r\nprint(printing(packA,countA))\r\nprint(printing(packB, countB))", "#bismillah\nt_case = int(input())\ngot_a = 0\ngot_b = 0\nlost_a = 0\nlost_b = 0\nfor t in range(t_case):\n\ta, x, y = input().split()\n\ta = int(a)\n\tx = int(x)\n\ty = int(y)\n\tif a==1:\n\t\tgot_a = got_a + x\n\t\tlost_a = lost_a + y\n\telif a==2:\n\t\tgot_b = got_b + x\n\t\tlost_b = lost_b + y\nif got_a >= lost_a:\n\tprint('LIVE')\nelse:\n\tprint('DEAD')\nif got_b >= lost_b:\n\tprint('LIVE')\nelse:\n\tprint('DEAD')\n\t\n", "n=int(input())\naj=0\naz=0\nbj=0\nbz=0\nfor i in range(n):\n a=[int(x) for x in input().split()]\n if a[0]==1:\n aj+=a[1]\n az+=10\n else:\n bj+=a[1]\n bz+=10\n\n\nif az<=2*aj:print('LIVE')\nelse:print('DEAD')\nif bz<=2*bj:print('LIVE')\nelse:print('DEAD')\n\n", "# LUOGU_RID: 101472989\n(n,), *a = [[*(map(int, s.split()))] for s in open(0)]\r\nb = [0, 0]\r\nfor t, x, y in a:\r\n b[t - 1] += x - y\r\nfor x in b:\r\n print(x >= 0 and 'LIVE' or 'DEAD')\r\n", "n=int(input())\r\nl=[]\r\nxa=0\r\nya=0\r\nxb=0\r\nyb=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]==1:\r\n\t\txa=xa+l[i][1]\r\n\t\tya=ya+l[i][2]\r\n\telse:\r\n\t\txb=xb+l[i][1]\r\n\t\tyb=yb+l[i][2]\r\nif xa>=ya:\r\n\tprint(\"LIVE\")\r\n\tif xb>=yb:\r\n\t\tprint(\"LIVE\")\r\n\telse:\r\n\t\tprint(\"DEAD\")\r\nelse:\r\n\tprint(\"DEAD\")\r\n\tif xb>=yb:\r\n\t\tprint(\"LIVE\")\r\n\telse:\r\n\t\tprint(\"DEAD\")", "import time\r\n\r\ndef evaluatePings(pingesList):\r\n sumSuccess = 0\r\n sumLost = 0\r\n status = \"\"\r\n\r\n for inx, ping in enumerate(pingesList):\r\n sumSuccess += ping[1]\r\n sumLost += ping[2]\r\n\r\n if sumSuccess >= sumLost:\r\n status = \"LIVE\"\r\n else:\r\n status = \"DEAD\"\r\n return status\r\n\r\n\r\ndef solve():\r\n pinges = int(input())\r\n pingesA = []\r\n pingesB = []\r\n\r\n for x in range(pinges):\r\n ping = [int(x) for x in input().split()]\r\n if ping[0] == 1:\r\n pingesA.append(ping)\r\n elif ping[0] != 1:\r\n pingesB.append(ping)\r\n serverA = evaluatePings(pingesA)\r\n serverB = evaluatePings(pingesB)\r\n print(serverA)\r\n print(serverB)\r\n # print(\"%fs\" % (time.time() - start_time))\r\n\r\n\r\nsolve()", "n = int(input())\r\nu, v = [0, 0], [0, 0]\r\nfor i in range(n):\r\n t, x, y = map(int, input().split())\r\n k = int(t == 1)\r\n u[k] += x\r\n v[k] += y\r\nprint('LDIEVAED'[u[1] < v[1] :: 2])\r\nprint('LDIEVAED'[u[0] < v[0] :: 2]) \r\n", "n = int(input())\r\n\r\naSent = 0\r\nbSent = 0\r\naReceived = 0\r\nbReceived = 0\r\n\r\nfor i in range(n):\r\n string = input().split(' ')\r\n if string[0] == \"1\":\r\n aSent += 10\r\n aReceived += int(string[1]) \r\n elif string[0] == \"2\":\r\n bSent += 10\r\n bReceived += int(string[1]) \r\n\r\nif aReceived/aSent >= 0.5:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif bReceived/bSent >= 0.5:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "def main():\n n = int(input())\n LIVE, DEAD = [0, 0, 0], [0, 0, 0]\n for _ in range(n):\n t, x, y = map(int, input().split())\n LIVE[t] += x\n DEAD[t] += y\n for _ in 1, 2:\n print(('LIVE', 'DEAD')[LIVE[_] < DEAD[_]])\n\n\nif __name__ == '__main__':\n main()", "a = int(input())\nx1 = 0\nx2 = 0\ns1 = 0\ns2 = 0\nfor i in range(a):\n s, ai, b1 = map(int, input().split())\n if s == 1:\n s1 += 1\n x1 += ai\n else:\n s2 += 1\n x2 += ai\nif x1 >= s1 * 5:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\nif x2 >= s2 * 5:\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\n", "n = int(input())\r\na=0\r\nb=0\r\nc=0\r\nd=0\r\nfor i in range(n):\r\n\tt,x,y = list(map(int,input().split()))\r\n\tif t == 1:\r\n\t\ta += x\r\n\t\tb += y\r\n\telse:\r\n\t\tc += x\r\n\t\td += y\r\nif a>=b:\r\n\tprint('LIVE')\r\nelse:\r\n\tprint('DEAD')\r\n\r\nif c>=d:\r\n\tprint('LIVE')\r\nelse:\r\n\tprint('DEAD')", "X, Y = [0, 0], [0, 0]\r\n\r\nfor _ in range(int(input())):\r\n t, x, y = map(int, input().split())\r\n X[t-1], Y[t-1] = X[t-1] + x, Y[t-1] + y\r\n\r\nfor i in range(2):\r\n print('DEAD' if X[i] < Y[i] else 'LIVE')", "sum_a, sum_b = 0,0\r\nfor i in range(int(input())):\r\n list1 = list(map(int,input().split()))\r\n if list1[0] == 1:\r\n sum_a+=list1[1]\r\n sum_a-=list1[2]\r\n else:\r\n sum_b+=list1[1]\r\n sum_b-=list1[2]\r\nprint('LIVE' if sum_a>=0 else 'DEAD')\r\nprint('LIVE' if sum_b>=0 else 'DEAD')", "n = int(input())\nasum = 0\nagood = 0\nbsum = 0\nbgood = 0\nfor _ in range(n):\n t, x, y = map(int, input().split())\n if t == 1:\n asum += x + y\n agood += x\n else:\n bsum += x + y\n bgood += x\nif asum // 2 <= agood:\n print('LIVE')\nelse:\n print('DEAD')\nif bsum // 2 <= bgood:\n print('LIVE')\nelse:\n print('DEAD')\n", "alive_server_1 = alive_server_2 = all_server_1 = all_server_2 = 0\r\nfor commands in range(int(input())):\r\n server, x, y = map(int, input().split())\r\n if server == 1:\r\n all_server_1 += x + y\r\n alive_server_1 += x\r\n else:\r\n all_server_2 += x + y\r\n alive_server_2 += x\r\n\r\nif alive_server_1 >= all_server_1/2: print(\"LIVE\")\r\nelse: print(\"DEAD\")\r\n\r\nif alive_server_2 >= all_server_2/2: print(\"LIVE\")\r\nelse: print(\"DEAD\")", "n = int(input())\r\nT, X, Y = [], [], []\r\nfor i in range(n):\r\n ti, xi, yi = [int(c) for c in input().split()]\r\n T.append(ti)\r\n X.append(xi)\r\n Y.append(yi)\r\n\r\nsucc_a = succ_b = 0\r\nlost_a = lost_b = 0\r\nfor t, x, y in zip(T, X, Y):\r\n if t == 1:\r\n succ_a += x\r\n lost_a += y\r\n else:\r\n succ_b += x\r\n lost_b += y\r\n\r\nprint('LIVE' if succ_a / (succ_a + lost_a) >= 0.5 else 'DEAD')\r\nprint('LIVE' if succ_b / (succ_b + lost_b) >= 0.5 else 'DEAD')\r\n", "a=[0,0]\r\nfor _ in [0]*int(input()):\r\n t,x,y=map(int,input().split())\r\n a[t-1]+=x-y\r\n \r\nfor x in a: \r\n if (x<0):\r\n print ('DEAD')\r\n else:\r\n print ('LIVE')", "n=int(input())\r\na=0\r\nb=0\r\na_sent=0\r\nb_sent=0\r\nfor i in range(0,n):\r\n p,x,y=map(int,input().split())\r\n if p==1:\r\n a=a+x+y\r\n a_sent=a_sent+x\r\n else:\r\n b=b+x+y\r\n b_sent=b_sent+x\r\nif a_sent>=(a/2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif b_sent>=(b/2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n ", "a1,b1,a2,b2=0,0,0,0\r\nfor _ in range(int(input())):\r\n x,a,b=map(int,input().split())\r\n if x==1:\r\n a1=a1+a\r\n b1=b1+b\r\n elif x==2:\r\n a2=a2+a\r\n b2=b2+b\r\nif a1>=b1:\r\n print(\"LIVE\")\r\nelse:\r\n \r\n print(\"DEAD\")\r\nif a2>=b2:\r\n print(\"LIVE\")\r\nelse:\r\n \r\n print(\"DEAD\")", "n = int(input())\r\nadd1 = 0\r\nadd2 = 0\r\nadd3 = 0\r\nadd4 = 0\r\nfor i in range(n):\r\n\tx,y,z = list(map(int,input().split()))\r\n\tif x==1:\r\n\t\tadd1 += y+z\r\n\t\tadd2 += y\r\n\telif x!=1:\r\n\t\tadd3 += y+z\r\n\t\tadd4 += y\r\nif add2 >= add1//2:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\nif add4 >= add3//2:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\t\t\t\t\t\r\n\r\n\r\n\r\n", "num=int(input())\r\nat=0\r\nab=0\r\nbt=0\r\nbb=0\r\nfor i in range(num):\r\n net,through,blocked=map(int,input().split())\r\n if net==1:\r\n at+=through\r\n ab+=blocked\r\n else:\r\n bt+=through\r\n bb+=blocked\r\nif at>=ab:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif bt>=bb:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n = int(input())\r\n\r\nsa , la = 0 , 0\r\nsb , lb = 0 , 0\r\n\r\nfor i in range(n):\r\n t , x , y = map(int,input().split())\r\n if t ==1 :\r\n sa += x\r\n la += y\r\n else:\r\n sb += x\r\n lb += y\r\n\r\nif sa >= la :\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n\r\nif sb >= lb :\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "#-------------Program-------------\r\n#----KuzlyaevNikita-Codeforces----\r\n#\r\n\r\nn=int(input())\r\nax=0;ay=0;bx=0;by=0\r\nfor i in range(n):\r\n t,x,y=map(int,input().split())\r\n if t==1:\r\n ax+=x;ay+=y\r\n else:\r\n bx+=x;by+=y\r\nif ax>=ay:print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif bx>=by:print('LIVE')\r\nelse:\r\n print('DEAD')", "n = int(input())\r\nans11,ans12,ans21,ans22 = 0,0,0,0\r\nfor i in range(n):\r\n t,x,y = map(int,input().split())\r\n if t == 1: ans11 += x; ans12 += 10\r\n else: ans21 += x; ans22 += 10\r\nif ans11 >= ans12//2: print(\"LIVE\")\r\nelse: print(\"DEAD\")\r\nif ans21 >= ans22//2: print(\"LIVE\")\r\nelse: print(\"DEAD\")", "n=int(input())\r\na=[]\r\nfor i in range(n):\r\n a.append([int(x) for x in input().split()])\r\nx,y,x1,y1=0,0,0,0\r\nfor i in a:\r\n if i[0]==1:\r\n x+=i[1]\r\n y+=i[2]\r\n else:\r\n x1+=i[1]\r\n y1+=i[2]\r\nif x>=y:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif x1>=y1:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n = int(input())\n\nstate = [\n {'all': 0, 'got': 0},\n {'all': 0, 'got': 0},\n]\n\nfor _ in range(n):\n process, got, lost = [int(x) for x in input().split(' ')]\n state[process - 1]['all'] += 10\n state[process - 1]['got'] += got\n\nfor i in range(2):\n if state[i]['got'] * 2 >= state[i]['all']:\n print('LIVE')\n else:\n print('DEAD')\n\n", "n = int(input()) \nsa, sb = 0, 0\nta = 0\ntb = 0\nfor _ in range(n):\n t, x, y = list(map(int, input().split()))\n if t == 1:\n sa += x\n ta += x + y\n if t == 2:\n sb += x\n tb += x + y\nprint(\"LIVE\" if sa/ta >= .5 else \"DEAD\")\nprint(\"LIVE\" if sb/tb >= .5 else \"DEAD\")\n", "t = int(input())\r\na ,b = 0, 0\r\nfor i in range(t):\r\n k ,x , y = map(int, input().split())\r\n if k == 1:\r\n a += x - y\r\n else:\r\n b += x - y\r\nif a >= 0:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif b >= 0:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "l = int(input())\r\n\r\ntotal_sent = total_lost = 0\r\ntotal_sent1 = total_lost1 = 0\r\n\r\nfor i in range(l):\r\n t, x, y = map(int, input().split())\r\n\r\n if t == 1:\r\n total_sent += x\r\n total_lost += y\r\n elif t == 2:\r\n total_sent1 += x\r\n total_lost1 += y\r\n\r\nif total_lost > total_sent:\r\n print('DEAD')\r\nelse:\r\n print ('LIVE')\r\n\r\nif total_lost1 > total_sent1:\r\n print('DEAD')\r\nelse:\r\n print ('LIVE')", "a, b = 0, 0\r\nfor _ in range(int(input())):\r\n t, x, y = map(int, input().split())\r\n\r\n if t== 1:\r\n a += x-y\r\n else:\r\n b += x-y\r\n\r\nif a>=0:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n \r\nif b>=0:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n", "#include <bits/stdc++.h>\r\n#define SYNC ios_base::sync_with_stdio(0);\r\n#define IO STD std_enable = 1; cin.tie(0);\r\n#define STD /*\r\nfrom sys import (\r\nstdin, stdout, exit as sys_ret)\r\n\"\"\"****************************\r\n\r\n Interactive Tasks:\r\n\r\n / Python: / \"\"\"\r\nf_input, f_print, f_flush = (\r\n stdin.readline,\r\n stdout.write,\r\n stdout.flush)\r\n\r\n\"\"\" / C++ /\r\n #import <cstdio>\r\n fflush(stdout);\r\n or\r\n #import <iostream>\r\n cout << endl;\r\n\r\n —————————————————————————\r\n Don't raise your voice,\r\n improve your argument.\r\n —————————————————————————\r\n\r\n cat /dev/ass > /dev/head\r\n Ctrl+C\r\n cat /knowledge > /dev/head\r\n\r\n © Jakov Gellert\r\n frvr.ru\r\n\r\n****************************\"\"\"\r\n# */ using namespace std; int\r\n#define boost_stream(); IO SYNC\r\n\r\naX, aY, bX, bY = 0, 0, 0, 0\r\nfor _ in range(int(f_input())):\r\n server, got, missed = map(int, f_input().split())\r\n if server == 1:\r\n aX += got\r\n aY += missed\r\n elif server == 2:\r\n bX += got\r\n bY += missed\r\nf_print(\"LIVE\\n\" if aX >= aY else \"DEAD\\n\")\r\nf_print(\"LIVE\\n\" if bX >= bY else \"DEAD\\n\")", "n = int(input())\nsuccessServerA = 0\nsuccessServerB = 0\nrejectServerA = 0\nrejectServerB = 0\nfor index in range(n):\n server, sucess, errors = map(int, input().split())\n if(server == 1):\n successServerA += sucess\n rejectServerA += errors\n else:\n successServerB += sucess\n rejectServerB += errors\nkpiA = successServerA/(successServerA+rejectServerA)\nkpiB = successServerB/(successServerB+rejectServerB)\nif(kpiA >= 0.5):\n print('LIVE')\nelse:\n print('DEAD')\nif(kpiB >= 0.5):\n print('LIVE')\nelse:\n print('DEAD')\n", "\"\"\"\n\ta\tserver 1\n\tb\tserver 2\n\tx + y = 10\n\tx, y >= 0\n\t\tx succesful packages\n\t\ty lost packages\n\n\t\tif x > 10/2 -> server is alive\n\"\"\"\n\na, b = [0, 0], [0, 0]\n\nfor tc in range(0, int(input())):\n\tt, x, y = map(int, input().split())\n\n\tif t == 1:\n\t\ta[0] += x\n\t\ta[1] += y\n\telse:\n\t\tb[0] += x\n\t\tb[1] += y\n\nprint(\"LIVE\" if a[0] >= a[1] else \"DEAD\")\nprint(\"LIVE\" if b[0] >= b[1] else \"DEAD\")", "def status(n, ls):\r\n l1 = 0\r\n l2 = 0\r\n c1 = 0\r\n c2 = 0\r\n for i in range(n):\r\n if(ls[i][0] == 1):\r\n l1 = l1 + ls[i][1]\r\n c1 = c1 + 1\r\n else: \r\n l2 = l2 + ls[i][1]\r\n c2 = c2 + 1\r\n if(l1 >= int((c1 * 10) / 2)):\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")\r\n if(l2 >= int((c2 * 10) / 2)):\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")\r\n \r\n\r\nn = int(input())\r\nls = [[int(j) for j in input().split()] for i in range(n)]\r\nstatus(n, ls)", "m = [0] * 3\r\nfor _ in range(int(input())):\r\n t, x, y = list(map(int, input().split(' ')))\r\n m[t] += x - y\r\nprint('LIVE' if m[1] >= 0 else 'DEAD')\r\nprint('LIVE' if m[2] >= 0 else 'DEAD')", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,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()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef I(): return int(sys.stdin.readline())\ndef LS(): return sys.stdin.readline().split()\ndef S(): return input()\n\ndef main():\n n=I()\n\n a=b=0\n _a=_b=0\n for _ in range(n):\n x,y,z=LI()\n if x==1:\n a+=y\n _a+=10\n else:\n b+=y\n _b+=10\n\n if a*2>=_a:\n print('LIVE')\n else:\n print('DEAD')\n if b*2>=_b:\n print('LIVE')\n else:\n print('DEAD')\n\nmain()\n# print(main())\n", "import math\r\n\r\ndef main_function():\r\n pings = [[0 for i in range(2)] for i in range(2)]\r\n input_list = [[int(i) for i in input().split(\" \")] for i in range(int(input()))]\r\n for i in input_list:\r\n if i[0] == 1:\r\n pings[0][0] += i[1]\r\n pings[0][1] += i[2]\r\n else:\r\n pings[1][0] += i[1]\r\n pings[1][1] += i[2]\r\n output_list = []\r\n if pings[0][0] >= pings[0][1]:\r\n output_list.append(\"LIVE\")\r\n else:\r\n output_list.append(\"DEAD\")\r\n if pings[1][0] >= pings[1][1]:\r\n output_list.append(\"LIVE\")\r\n else:\r\n output_list.append(\"DEAD\")\r\n return \"\\n\".join(output_list)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nprint(main_function())", "n = int(input())\r\nta,tb,la,lb = 0,0,0,0\r\nfor i in range(n):\r\n x,t,l = map(int,input().split(' '))\r\n if x==1:\r\n ta+=t\r\n la+=l\r\n else:\r\n tb+=t\r\n lb+=l\r\nif ta<la:\r\n print('DEAD')\r\nelse:\r\n print('LIVE')\r\nif tb<lb:\r\n print('DEAD')\r\nelse:\r\n print('LIVE')", "n = int(input())\r\n\r\nx1, y1, x2, y2 = 0, 0, 0, 0\r\n\r\nfor i in range(n):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n x1 += x\r\n y1 += y\r\n else:\r\n x2 += x\r\n y2 += y\r\n\r\nif x1 >= y1:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n \r\n \r\nif x2 >= y2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\") \r\n", "\r\ncnt1 = cnt2 = 0\r\nfor i in range(int(input())):\r\n x = [int(x) for x in input().split()]\r\n if x[0] == 1:\r\n cnt1 = cnt1 + x[1] - x[2]\r\n else:\r\n cnt2 = cnt2 + x[1] - x[2]\r\n \r\nprint('LIVE' if cnt1 >= 0 else 'DEAD')\r\nprint('LIVE' if cnt2 >= 0 else 'DEAD')", "n = int(input())\r\na, b = [0, 0], [0, 0]\r\nfor i in range(n):\r\n t, x, y = map(int,\r\n input().split())\r\n if t == 1:\r\n a[1]+=x\r\n a[0]+=1\r\n else:\r\n b[1]+=x\r\n b[0]+=1\r\nif a[1]/(10*a[0]) >= 0.5:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif b[1]/(10*b[0]) >= 0.5:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n", "n = int(input())\r\na_succ = 0\r\na_fail = 0\r\nb_succ = 0\r\nb_fail = 0\r\nfor i in range(n):\r\n s = list(map(int, input().split()))\r\n if s[0] == 1:\r\n a_succ+=s[1]\r\n a_fail+=s[2]\r\n else:\r\n b_succ+=s[1]\r\n b_fail+=s[2]\r\nif a_succ>=a_fail:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif b_succ>=b_fail:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\") \r\n\r\n\r\n\r\n\r\n", "n=int(input())\na=0\nb=0\nfor A in range(n):\n t,x,y=map(int,input().split())\n if t==1:\n a+=x\n a-=y\n else:\n b+=x\n b-=y\nif a>=0:\n print('LIVE')\nelse:\n print('DEAD')\nif b>=0:\n print('LIVE')\nelse:\n print('DEAD')\n", "n = int(input())\r\nR1 = 0\r\nR2 = 0\r\nL1 = 0\r\nL2 = 0\r\nfor i in range(n):\r\n b, r, l = map(int, input().split())\r\n if b == 1:\r\n R1 += r\r\n L1 += l\r\n else:\r\n R2 += r\r\n L2 += l\r\nif R1 >= L1:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif R2 >= L2:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n", "n, res = int(input()), []\r\nfor i in range(n):\r\n res.append([int(i) for i in input().split()])\r\na1, a2, b1, b2 = 0, 0, 0, 0\r\nfor i in res:\r\n if i[0] == 1:\r\n a1 += i[1]\r\n a2 += i[2]\r\n else:\r\n b1 += i[1]\r\n b2 += i[2]\r\nprint('LIVE' if a1 >= a2 else 'DEAD')\r\nprint('LIVE' if b1 >= b2 else 'DEAD')\r\n", "x_countera = 0\r\nx_counterb = 0\r\ny_countera = 0\r\ny_counterb = 0\r\n\r\nfor i in range(int(input())):\r\n t, x, y = map(int, input().split())\r\n\r\n # test for server a\r\n if t == 1:\r\n # check for server status (values) \r\n x_countera += x\r\n y_countera += y\r\n\r\n # test for server b\r\n elif t == 2:\r\n # check for server status\r\n x_counterb += x\r\n y_counterb += y\r\n\r\n# compare both counters\r\nif x_countera >= y_countera and x_counterb >= y_counterb:\r\n print(\"LIVE\")\r\n print(\"LIVE\")\r\nelif x_countera >= y_countera and x_counterb < y_counterb:\r\n print(\"LIVE\")\r\n print(\"DEAD\")\r\nelif x_countera < y_countera and x_counterb >= y_counterb:\r\n print(\"DEAD\")\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n print(\"DEAD\")\r\n", "n = int(input())\nzero1 = 0 ; zero2 = 0 ; zero3 = 0 ; zero4 = 0\nfor i in range(n):\n\ta, b, c = map(int, input().split())\n\tif a == 1:\n\t\tzero1 += b ; zero3 += b + c\n\telse:\n\t\tzero2 += b ; zero4 += b + c\nif zero1 >= zero3 // 2:\n\tprint('LIVE')\nelse:\n\tprint('DEAD')\nif zero2 >= zero4 // 2:\n\tprint('LIVE')\nelse:\n\tprint('DEAD')\n", "n=int(input())\r\na=0\r\nb=0\r\nx=0\r\ny=0\r\nl=[]\r\np=0\r\nq=0\r\nfor i in range(n):\r\n\ts=input().split()\r\n\tl.append(s)\r\n\tif(s[0]=='1'):\r\n\t\tx+=1\r\n\telif(s[0]=='2'):\r\n\t\ty+=1\t\t\t\r\nfor j in range(n):\r\n\tif l[j][0]=='1':\r\n\t\tp+=int(l[j][1])\t\r\n\tif l[j][0]=='2':\r\n\t\tq+=int(l[j][1])\r\nif p>=(x*5):\r\n\ta=1\r\nelse:\r\n\ta=0\r\nif q>=(y*5):\r\n\tb=1\r\nelse:\r\n\tb=0\t\t\t\r\n\t\r\n\t\t\t\r\nif a==1:\r\n\tprint(\"LIVE\")\r\nelif a==0:\r\n\tprint(\"DEAD\")\r\nif b==1:\r\n\tprint(\"LIVE\")\r\nelif b==0:\r\n\tprint(\"DEAD\")", "if __name__ == \"__main__\":\n n = int(input())\n x_a = 0\n y_a = 0\n x_b = 0\n y_b = 0\n\n for _ in range(n):\n t, x, y = tuple(map(int, input().split()))\n\n if t == 1:\n x_a += x\n y_a += y\n else:\n x_b += x\n y_b += y\n\n if x_a >= y_a:\n print(\"LIVE\")\n else:\n print(\"DEAD\")\n\n if x_b >= y_b:\n print(\"LIVE\")\n else:\n print(\"DEAD\")", "no_of_servers = int(input())\n\npackets = [list(map(int , input().split(\" \"))) for i in range(no_of_servers)]\n\nseverA = [i[1] for i in packets if i[0] == 1]\nseverB = [i[1] for i in packets if i[0] == 2]\n\nif sum(severA) >= len(severA) * 5 :\n print(\"LIVE\")\nelse :\n print(\"DEAD\")\nif sum(severB) >= len(severB) * 5 :\n print(\"LIVE\")\nelse:\n print(\"DEAD\")\n\n", "while(1):\r\n try:\r\n n=int(input())\r\n a,b,c=[0 for j in range(n)],[0 for j in range(n)],[0 for j in range(n)]\r\n sum1,sum2=0,0\r\n for i in range(0,n):\r\n a[i],b[i],c[i]=map(int,input().split())\r\n if a[i]==1:\r\n sum1+=b[i]\r\n else:\r\n sum2+=b[i]\r\n count1,count2=a.count(1),a.count(2)\r\n t1,t2=10*count1,10*count2\r\n if sum1/t1>=0.5:\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")\r\n if sum2/t2>=0.5:\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")\r\n except EOFError:\r\n break\r\n \r\n \r\n \r\n \r\n \r\n ", "n=int(input())\r\nl=[]\r\nfor i in range(n):\r\n\tr=list(map(int,input().split()))\r\n\tl.append(r)\r\ncount=0\r\nplus=0\r\nz=0\r\nw=0\r\nfor i in range(n):\r\n\tif l[i][0]==1:\r\n\t\tcount=count+l[i][2]\r\n\t\tplus=plus+l[i][1]\r\n\tif l[i][0]==2:\r\n\t\tz=z+l[i][2]\r\n\t\tw=w+l[i][1]\r\nif plus>=count:\r\n\tprint(\"LIVE\")\r\nelse :\r\n\tprint(\"DEAD\")\r\nif w>=z:\r\n\tprint(\"LIVE\")\r\nelse :\r\n\tprint(\"DEAD\")", "a=int(input())\r\nl1=0\r\nl2=0\r\nfor i in range(a):\r\n c=input().split()\r\n if c[0]=='1':\r\n l1+=int(c[1])\r\n l1-=int(c[2])\r\n else:\r\n l2+=int(c[1])\r\n l2-=int(c[2])\r\nif l1>=0:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif l2>=0:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "n = int(input())\r\nping_a_successful = 0\r\nping_a_total = 0\r\nping_b_successful = 0\r\nping_b_total = 0\r\n\r\nfor _ in range(n):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n ping_a_successful += x\r\n ping_a_total += (x + y)\r\n else:\r\n ping_b_successful += x\r\n ping_b_total += (x + y)\r\n\r\n# Check if server a is \"alive\"\r\nif ping_a_successful >= (ping_a_total // 2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\n# Check if server b is \"alive\"\r\nif ping_b_successful >= (ping_b_total // 2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "n = int(input())\r\na = []\r\nb = []\r\nfor s in range(n):\r\n arr = list(map(int, input().split()))\r\n if arr[0] == 1:\r\n a.append(arr)\r\n else:\r\n b.append(arr)\r\ntotal1 = 10 * len(a) / 2\r\ntotal2 = 10 * len(b) / 2\r\nbase1 = 0\r\nbase2 = 0\r\nfor i in range(len(a)):\r\n base1 += a[i][1]\r\nfor i in range(len(b)):\r\n base2 += b[i][1]\r\nif base1 < total1:\r\n print('DEAD')\r\nelse:\r\n print('LIVE')\r\n\r\nif base2 < total2:\r\n print('DEAD')\r\nelse:\r\n print('LIVE')\r\n", "#In the name of GOD!\nn = int(input())\nans = [0, 0]\nfor i in range(n):\n\tt, x, y = map(int, input().split())\n\tans[t - 1] += x - y\n\nfor i in range(2):\n\tif ans[i] >= 0: print(\"LIVE\")\n\telse: print(\"DEAD\")\n", "n = int(input())\r\nsa = sb = fa = fb = 0\r\nfor i in range(n):\r\n t,x,y = map(int,input().split())\r\n if t == 1:\r\n sa += x\r\n fa += y\r\n else:\r\n sb += x\r\n fb += y\r\nif sa >= fa:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif sb >= fb:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n", "t=int(input())\r\npa=0\r\npb=0\r\nfor i in range(t):\r\n\ta,b,c=list(map(int,input().split()))\r\n\tif a==1:\r\n\t\tpa+=b-5\r\n\telse:\r\n\t\tpb+=b-5\r\nif pa>=0:\r\n\tprint('LIVE')\r\nelse:\r\n\tprint('DEAD')\r\nif pb>=0:\r\n\tprint('LIVE')\r\nelse:\r\n\tprint('DEAD')\r\n", "def Server():\r\n\tn = int(input())\r\n\r\n\taReached = 0\r\n\taLost = 0\r\n\tbReached = 0\r\n\tbLost = 0\r\n\r\n\tfor i in range(n):\r\n\t\tnum, r, l = list(map(int, input().split()))\r\n\t\tif num == 1:\r\n\t\t\taReached += r\r\n\t\t\taLost += l\r\n\t\telse:\r\n\t\t\tbReached += r\r\n\t\t\tbLost += l\r\n\tif aReached >= aLost:\r\n\t\tprint(\"LIVE\")\r\n\telse:\r\n\t\tprint(\"DEAD\")\r\n\tif bReached >= bLost:\r\n\t\tprint(\"LIVE\")\r\n\telse:\r\n\t\tprint(\"DEAD\")\r\n\r\nServer()", "#https://codeforces.com/problemset/problem/245/A\r\nnum_commands = int(input())\r\n\r\nserver_a_sent,server_a_received = 0,0\r\nserver_b_sent,server_b_received = 0,0\r\n\r\nfor index in range(num_commands):\r\n inp = input()\r\n inp = inp.split(\" \")\r\n \r\n if inp[0] == \"1\":\r\n server_a_sent += 10\r\n server_a_received += int(inp[1])\r\n else:\r\n server_b_sent += 10\r\n server_b_received += int(inp[1])\r\n\r\n#SERVER A RESULT\r\nif server_a_received/server_a_sent >= 0.5:\r\n print (\"LIVE\")\r\nelse:\r\n print (\"DEAD\")\r\n\r\n#SERVER B RESULT\r\nif server_b_received/server_b_sent >= 0.5:\r\n print (\"LIVE\")\r\nelse:\r\n print (\"DEAD\")\r\n\r\n", "n=int(input())\r\na,b,c,d=0,0,0,0\r\nfor i in range(n):\r\n t,x,y=map(int,input().split())\r\n if t==1:\r\n a+=x\r\n b+=y\r\n else:\r\n c+=x\r\n d+=y\r\nif a>=b:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif c>=d:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n \r\n ", "lenght = int(input())\r\narr = []\r\nfor i in range(0, lenght):\r\n string = input()\r\n tmp = []\r\n for j in string.split(' '):\r\n tmp.append(j)\r\n arr.append(tmp)\r\naX = 0\r\naY = 0\r\nbX = 0\r\nbY = 0\r\nfor i in arr:\r\n if i[0] == '1':\r\n aX += int(i[1])\r\n aY += int(i[2])\r\n else:\r\n bX += int(i[1])\r\n bY += int(i[2])\r\n\r\nif aX >= aY:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif bX >= bY:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "n = int(input())\nLa = []\nLb = []\nsum1,sum2 = 0,0\nfor i in range(n):\n L = [int(x) for x in input().split()]\n if L[0] == 1:\n La.append(L)\n sum1 = sum1 + 1\n else:\n Lb.append(L)\n sum2 = sum2 + 1\ns1 = 0\ns2 = 0\nk1= 0\nk2 = 0\nfor i in La:\n s1 = s1 + i[1]\n k1 += i[1] + i[2]\nfor i in Lb:\n s2 = s2 + i[1]\n k2 += i[1] + i[2]\nif k1<=(s1*2):\n print('LIVE')\nelse:\n print ('DEAD')\nif k2<=(s2*2):\n print('LIVE')\nelse:\n print('DEAD')", "n = int(input())\r\ncount_i_1=0\r\ncount_l_1=0\r\ncount_l_2=0\r\ncount_i_2=0\r\nfor i in range(n):\r\n t, x, y = input().split()\r\n t, x, y = int(t), int(x), int(y)\r\n if t == 1:\r\n count_i_1+=x\r\n count_l_1+=y\r\n else:\r\n count_i_2+=x\r\n count_l_2+=y\r\n\r\nif count_i_1>=count_l_1:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif count_i_2>=count_l_2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "def myprint(ca,na):\r\n\tif ca*2>=na:\r\n\t\tprint('LIVE')\r\n\telse:\r\n\t\tprint('DEAD')\r\n\r\nn=int(input())\r\nna,nb,ca,cb=0,0,0,0 \r\nwhile n>0:\r\n\tx,y,z=map(int,input().split())\r\n\tif x==1:\r\n\t\tna+=10\r\n\t\tca+=y\r\n\telse:\r\n\t\tnb+=10\r\n\t\tcb+=y\r\n\tn=n-1\r\nmyprint(ca,na)\r\nmyprint(cb,nb)", "n = int(input())\r\nx1 = 0\r\ny1 = 0\r\nx2 = 0\r\ny2 = 0\r\nfor i in range(n):\r\n l = list(input().split())\r\n t = int(l[0])\r\n if t == 1:\r\n x1 += int(l[1])\r\n y1 += int(l[2])\r\n else:\r\n x2 += int(l[1])\r\n y2 += int(l[2])\r\nif x1 >= y1:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif x2 >= y2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n = int(input())\r\nag, a, bg, b = 0, 0, 0, 0\r\nfor i in range(n):\r\n q = [int(i) for i in input().split()]\r\n if q[0] == 1:\r\n ag += q[1]\r\n a += q[1] + q[2]\r\n elif q[0] == 2:\r\n bg += q[1]\r\n b += q[1] + q[2]\r\nprint(\"LIVE\" if ag / a >= 0.5 else \"DEAD\")\r\nprint(\"LIVE\" if bg / b >= 0.5 else \"DEAD\")", "n = int(input())\r\nsa = 0\r\nsb = 0\r\nfor i in range(n):\r\n p, y, n = list(map(int, input().split()))\r\n if p == 1:\r\n sa += (y - n)\r\n elif p == 2:\r\n sb += (y - n)\r\nif sa >= 0:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif sb >= 0:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "n = int(input())\r\nx = []\r\nsum1 = 0\r\nsum2 = 0\r\ncount1 = 0\r\ncount2 = 0\r\nfor i in range(n):\r\n l = list(map(int, input().split()))\r\n x.append(l)\r\n if x[i][0] == 1:\r\n count1 += 1\r\n sum1 += x[i][1]\r\n\r\n elif x[i][0] == 2:\r\n count2 += 1\r\n sum2 += x[i][1]\r\n\r\nif sum1 >= (count1 * 10) / 2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif sum2 >= (count2 * 10) / 2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "ok = [0, 0]\r\nlost = [0, 0]\r\n\r\nn = int(input())\r\nfor _ in range(n):\r\n t, x, y = map(int, input().split())\r\n ok[t - 1] += x\r\n lost[t - 1] += y\r\n\r\nouts = ('DEAD', 'LIVE')\r\n\r\nprint(outs[ok[0] >= lost[0]])\r\nprint(outs[ok[1] >= lost[1]])\r\n", "n=int(input())\r\nconnect_a=0\r\nconnect_lost_a=0\r\nconnect_b=0\r\nconnect_lost_b=0\r\nfor i in range(n):\r\n t,a,b=map(int,input().split())\r\n if t==1:\r\n connect_a+=a\r\n connect_lost_a+=b\r\n else:\r\n connect_b+=a\r\n connect_lost_b+=b\r\nif connect_a>=connect_lost_a:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif connect_b>=connect_lost_b:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "a=int(input())\r\nc,n,v,d,j=0,0,0,0,0\r\nwhile(n<=a-1):\r\n l=list(map(int,input().split())) \r\n if l[0]==1:\r\n c=c+l[1]\r\n v=v+l[2]\r\n else:\r\n d=d+l[1]\r\n j=j+l[2]\r\n n=n+1 \r\nif (c>=v):\r\n print(\"LIVE\") \r\nelse:\r\n print(\"DEAD\") \r\nif (d>=j):\r\n print(\"LIVE\") \r\nelse:\r\n print(\"DEAD\")", "# import sys\r\n# sys.stdin=open(\"input.in\",\"r\")\r\nn=int(input())\r\nl=[]\r\nx=[]\r\ny=[]\r\nz=[]\r\nfor i in range(n):\r\n\tc=list(map(int,input().split()))\r\n\tif c[0]==1:\r\n\t\tl.append(c[1])\r\n\t\ty.append(c[2])\r\n\telse:\r\n\t\tx.append(c[1])\r\n\t\tz.append(c[2])\r\nq=sum(l)\r\nw=sum(y)+sum(l)\r\ne=sum(x)\r\nr=sum(x)+sum(z)\r\nif q>= int(w/2):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\nif e>= int(r/2):\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")", "n=int(input())\r\na=[]\r\nc=0\r\nd=0\r\ne=0\r\nf=0\r\nfor i in range(n):\r\n a.append(list(map(int,input().split())))\r\nfor j in range(n):\r\n if a[j][0]==1:\r\n c=c+a[j][1]\r\n e=e+a[j][2]\r\n else:\r\n d=d+a[j][1]\r\n f=f+a[j][2]\r\nif c>=e:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif d>=f:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "n = int(input())\r\na = [[0,0],[0,0]]\r\nfor i in range(n):\r\n t,x,y = map(int, input().split())\r\n a[t-1][0] += x\r\n a[t-1][1] += 5\r\nif a[0][0] >= a[0][1]:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif a[1][0] >= a[1][1]:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "n=int(input())\r\nl=[]\r\nct1=0\r\nct2=0\r\nx=0\r\ny=0\r\nfor i in range(n):\r\n\tl.append(list(map(int,input().split())))\r\nfor i in range(len(l)):\r\n\tif(l[i][0]==1):\r\n\t\tx=x+1\r\n\tif(l[i][0]==2):\r\n\t\ty=y+1\r\nfor i in range(len(l)):\r\n\tif(l[i][0]==1):\r\n\t\t# if(l[i][1]>l[i][2] or l[i][1]==l[i][2]):\r\n\t\t# \tct1=ct1+1\r\n\t\tct1=ct1+l[i][1]\r\n\tif(l[i][0]==2):\r\n\t\t# if(l[i][1]>l[i][2] or l[i][1]==l[i][2]):\r\n\t\t\tct2=ct2+l[i][1]\r\nif(ct1>=((x*10)/2)):\r\n\tprint(\"LIVE\")\r\nif(ct1<((x*10)/2)):\r\n\tprint(\"DEAD\")\r\nif(ct2>=((y*10)/2)):\r\n\tprint(\"LIVE\")\r\nif(ct2<((y*10)/2)):\r\n\tprint(\"DEAD\")", "n=int(input())\r\nserver_a_reached=0\r\nserver_b_reached=0\r\nserver_a_lose=0\r\nserver_b_lose=0\r\n\r\n\r\n\r\nfor i in range(n):\r\n s=input().split()\r\n s=[int(x) for x in s]\r\n a,b,c=s\r\n if a==1:\r\n server_a_reached+=b\r\n server_a_lose+=c\r\n if a==2:\r\n server_b_reached+=b\r\n server_b_lose+=c\r\n\r\n\r\nif server_a_reached >= server_a_lose:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n \r\n \r\nif server_b_reached >= server_b_lose:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n \r\n", "\r\nn = int(input())\r\nla = [0,0]\r\nlb = [0,0]\r\nfor _ in range(n):\r\n\tl = list(map(int,input().split()))\r\n\tif l[0] == 1:\r\n\t\tla[0] += l[1]\r\n\t\tla[1] += l[2]\r\n\telse:\r\n\t\tlb[0] += l[1]\r\n\t\tlb[1] += l[2]\r\n\r\nif la[0] >= la[1]:\r\n\r\n\tprint('LIVE')\r\nelse:\r\n\tprint('DEAD') \r\n\r\n\r\n\r\n\r\nif lb[0] >= lb[1]:\r\n\tprint('LIVE')\r\nelse:\r\n\tprint('DEAD')\r\n\r\n", "n=int(input())\r\nx1=0\r\ny1=0\r\nx2=0\r\ny2=0\r\nfor i in range(n):\r\n t,x,y=map(int,input().split())\r\n if(t==1):\r\n x1+=x\r\n y1+=y\r\n else:\r\n x2+=x\r\n y2+=y\r\n \r\nif(x1>=y1):\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n \r\nif(x2>=y2):\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n ", "n=int(input())\r\ntotal_a,total_b=0,0\r\na,b=0,0\r\nfor i in range(n):\r\n t,x,y=map(int,input().split())\r\n if t==1:\r\n total_a+=10\r\n a+=x\r\n else:\r\n total_b+=10\r\n b+=x\r\nif a>=total_a//2:\r\n print('LIVE')\r\nif a<total_a//2:\r\n print('DEAD')\r\nif b>=total_b//2:\r\n print('LIVE')\r\nif b<total_b//2:\r\n print('DEAD')", "n = int(input())\r\naLive = aDead = bLive = bDead = 0\r\nfor i in range(n):\r\n s, livePa, deadPa = map(int, input().split(' '))\r\n if s == 1:\r\n aLive += livePa\r\n aDead += deadPa\r\n else:\r\n bLive += livePa\r\n bDead += deadPa\r\nif aLive >= aDead:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif bLive >= bDead:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n", "a=0\r\nb=0\r\nA=0\r\nB=0\r\nfor i in range(int(input())):\r\n t,x,y=map(int,input().split())\r\n if t==1:\r\n A+=10\r\n a+=x\r\n else:\r\n B+=10\r\n b+=x\r\nif a>=A/2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\") \r\nif b>=B/2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\") ", "n = int(input())\r\ncnt1 = cnt2 = 0\r\nfor i in range(n):\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n cnt1 = cnt1 + x - y\r\n else:\r\n cnt2 = cnt2 + x - y\r\nif cnt1 < 0:\r\n print(\"DEAD\")\r\nelse:\r\n print(\"LIVE\")\r\nif cnt2 < 0:\r\n print(\"DEAD\")\r\nelse:\r\n print(\"LIVE\")", "n = int(input())\r\na, b, l, m = 0, 0, 0, 0\r\nfor i in range(n):\r\n t, x, y = [int(x) for x in input().split()]\r\n if t == 1:\r\n l += 1\r\n a += x\r\n else:\r\n m += 1\r\n b += x\r\nif a >= 5 * l:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif b >= 5 * m:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "n=int(input())\r\na=0\r\nb=0\r\na1=0\r\nb1=0\r\nsa=0\r\nsb=0\r\nfor i in range(n):\r\n s=[int(j) for j in input().split(\" \")]\r\n t=s[0]\r\n x=s[1]\r\n y=s[2]\r\n if t==1:\r\n a1+=x\r\n a+=y\r\n sa=sa+x+y\r\n else:\r\n b1+=x\r\n b+=y\r\n sb=sb+x+y\r\nif a1*2>=sa:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif b1*2>=sb:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\n\r\n", "n = int(input())\r\nam = 0\r\namt = 0\r\nbm = 0\r\nbmt = 0\r\nfor i in range(n):\r\n s, x, y = input().split()\r\n s, x, y = int(s), int(x), int(y)\r\n if s == 1:\r\n am += x\r\n amt += 10\r\n else:\r\n bm += x\r\n bmt += 10\r\n \r\nif am * 2 >= amt:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif bm * 2 >= bmt:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "x_a=0\r\ny_a=0\r\nx_b=0\r\ny_b=0\r\nfor _ in range(int(input())):\r\n t,x,y=map(int,input().split())\r\n if t==1:\r\n x_a=x_a+x\r\n y_a=y_a+y\r\n else: \r\n x_b=x_b+x\r\n y_b=y_b+y\r\nif x_a>=y_a:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n \r\nif x_b>=y_b:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n ", "a1=[]\r\na2=[]\r\nd=0;e=0;c=0;g=0;h=0;r=0\r\na=int(input(\"\"))\r\nfor i in range(0,a,1):\r\n b=input(\"\")\r\n a1=b.split(\" \")\r\n for j in range(0,3,1):\r\n a2.append(int(a1[j]))\r\n \r\n\r\nfor i in range(0,3*a,3):\r\n if(a2[i]==1):\r\n d+=a2[i+1]\r\n e+=a2[i+2]\r\n continue\r\n \r\n elif(a2[i]!=1):\r\n c+=a2[i+1]\r\n g+=a2[i+2]\r\n continue\r\n \r\n\r\nif(d>=e):\r\n print(\"LIVE\")\r\nelif(d<e):\r\n print(\"DEAD\")\r\n\r\nif(c>=g):\r\n print(\"LIVE\")\r\nelif(c<g):\r\n print(\"DEAD\")", "a=b=0;\r\nfor _ in [0]*int(input()):\r\n l,x,y=map(int,input().split())\r\n if l==1:a+=x-y\r\n else:b+=x-y\r\nprint('DLEIAVDE'[a>=0::2])\r\nprint('DLEIAVDE'[b>=0::2])", "n = int(input())\r\naSended = 0\r\nbSended = 0\r\naPing = 0\r\nbPing = 0\r\n\r\nwhile n > 0:\r\n t, x, y = map(int, input().split())\r\n if t == 1:\r\n aSended = aSended + 10\r\n aPing = aPing + x\r\n elif t == 2:\r\n bSended = bSended + 10\r\n bPing = bPing + x\r\n n = n - 1\r\n\r\nif(int(aSended / 2) <= aPing):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif(int(bSended / 2) <= bPing):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "num=eval(input())\nalist=[]\nfor i in range(num):\n a=input()\n b=a.split()\n c=[int(x) for x in b]\n\n alist.append(c)\n\n\ngeshua=0\ngeshub=0\nzongshua=0\nzongshub=0\nfor k in alist:\n if k[0]==1:\n geshua=geshua+1\n zongshua=zongshua+k[1]\n else:\n geshub=geshub+1\n zongshub=zongshub+k[1]\n\nif zongshua>=geshua*5:\n print(\"LIVE\")\nelse:\n print('DEAD')\nif zongshub>=geshub*5:\n print(\"LIVE\")\nelse:\n print('DEAD')", "n=int(input())\r\na=[]\r\nx1,y1=0,0\r\nx2,y2=0,0\r\nfor i in range(n):\r\n\tb=list(map(int,input().split()))\r\n\ta.append(b)\r\nfor i in a:\r\n\tif i[0]==1:\r\n\t\tx1+=i[1]\r\n\t\ty1+=i[2]\r\n\telif i[0]==2:\r\n\t\tx2+=i[1]\r\n\t\ty2+=i[2]\r\nif x1>=y1:\r\n\tprint('LIVE')\r\nelse:\r\n\tprint('DEAD')\t\r\nif x2>=y2:\r\n\tprint('LIVE')\r\nelse:\r\n\tprint('DEAD')", "s = [[0, 0], [0, 0]]\r\n\r\nfor _ in range(int(input())):\r\n t, x, y = map(int, input().split())\r\n s[t - 1][0] += x\r\n s[t - 1][1] += y\r\n\r\nfor i in range(2):\r\n print(('DEAD', 'LIVE')[s[i][0] >= s[i][1]])\r\n", "def check(n1, n2):\r\n if n1 >= n2:\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")\r\na_rec, a_nrec = 0, 0\r\nb_rec, b_nrec = 0, 0\r\nfor _ in range(int(input())):\r\n t, x, y = [int(j) for j in input().split()]\r\n if t == 1:\r\n a_rec += x\r\n a_nrec += y\r\n else:\r\n b_rec += x\r\n b_nrec += y\r\n\r\ncheck(a_rec, a_nrec)\r\ncheck(b_rec, b_nrec)\r\n", "n = int(input())\r\nk = [0] * 3\r\nfor _ in range(n):\r\n t, x, y = map(int, input().split())\r\n k[t] += x - y\r\n\r\nfor i in range(1, 3):\r\n print('LIVE' if k[i] >= 0 else 'DEAD')", "t = int(input())\nlst = []\nfor i in range(t):\n lst.append(list(map(int, input().split())))\na = 0\nal = 0\nb = 0\nbl = 0\nfor i in lst:\n if i[0] == 1:\n a += i[1]\n al += i[2]\n else:\n b += i[1]\n bl += i[2]\nif a >= al:\n print('LIVE')\nelse:\n print('DEAD')\nif b >= bl:\n print('LIVE')\nelse:\n print('DEAD')\n", "n = int(input())\na = [[0, 0], [0, 0]]\nfor i in range(n):\n t, x, y = map(int, input().split())\n a[t-1][0] += x\n a[t-1][1] += y\n\nfor i in a:\n print('LIVE' if i[0] >= i[1] else 'DEAD')\n\n \t\t \t\t \t \t\t\t\t\t\t\t \t\t \t\t", "n = int(input())\nax = ay = bx = by = 0\n\nfor _ in range(n):\n d, x, y = map(int, input().split())\n if d == 1:\n ax += x\n ay += y\n else:\n bx += x\n by += y\n\nif ax < ay:\n print('DEAD')\nelse:\n print('LIVE')\n\nif bx < by:\n print('DEAD')\nelse:\n print('LIVE')\n", "x1,y1,x2,y2=0,0,0,0\r\nfor i in range(int(input())):\r\n\tl=list(map(int,input().split()))\r\n\tif l[0]==1:\r\n\t\tx1+=l[1]\r\n\t\ty1+=l[2]\r\n\telse:\r\n\t\tx2+=l[1]\r\n\t\ty2+=l[2]\r\nif x1>=y1:\r\n\tprint('LIVE')\r\nelse:\r\n\tprint('DEAD')\r\nif x2>=y2:\r\n\tprint('LIVE')\r\nelse:\r\n\tprint(\"DEAD\")", "T = int(input())\r\na_x,b_y = 0,0\r\nA_x,B_y = 0,0\r\nfor i in range(T):\r\n t,x,y = map(int,input().split())\r\n if t == 1:\r\n a_x += x\r\n b_y += y\r\n else:\r\n A_x += x\r\n B_y += y\r\n\r\nif a_x >= b_y:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\nif A_x > B_y:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "x,y,z,c=0,0,0,0\r\nfor i in range(int(input())):\r\n a=list(map(int,input().split()))\r\n if(a[0]==1):\r\n x=x+a[1]+a[2]\r\n z=z+a[1]\r\n else:\r\n y=y+a[1]+a[2]\r\n c=c+a[1]\r\nif((x//2)<=z):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif((y//2)<=c):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "n = int(input())\r\n\r\nping_a_x = 0\r\nping_a_y = 0\r\nping_b_x = 0\r\nping_b_y = 0\r\nfor _ in range(n):\r\n t, x, y = map(int, input().split())\r\n \r\n if t == 1:\r\n ping_a_x += x\r\n ping_a_y += y\r\n else:\r\n ping_b_x += x\r\n ping_b_y += y\r\n\r\n\r\nif ping_a_x >= ping_a_y:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif ping_b_x >= ping_b_y:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "n=int(input())\ninp=list()\nxa=0\nxb=0\nyb=0\nya=0\nfor i in range(0,n):\n\tinp=[int(inp) for inp in input().split()]\n\tif inp[0]==1:\n\t\txa=xa+inp[1]\n\t\tya=ya+inp[2]\n\telse:\n\t\txb=xb+inp[1]\n\t\tyb=yb+inp[2]\n\tdel inp[0:]\nif xa>=ya:\n\tans1='LIVE'\nelse :\n\tans1='DEAD'\nif xb>=yb:\n\tans2='LIVE'\nelse:\n\tans2='DEAD'\ndel xa,xb,ya,yb\nprint(ans1,'\\n%s'%(ans2))\n", "a=[0,0];b=[0,0]\r\nquery=int(input())\r\n\r\nfor _ in range(query):\r\n\tt, x, y=map(int,input().split())\r\n\tif t==1:\r\n\t\ta[0]+=x;a[1]+=y\r\n\telse:\r\n\t\tb[0]+=x;b[1]+=y\r\n\r\nif a[0]>=a[1]:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\n\r\nif b[0]>=b[1]:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")", "n = int(input())\r\nax, ay, bx, by = 0, 0, 0, 0\r\nfor _ in range(n):\r\n t, x, y = map(int, input().split(' '))\r\n if t == 1:\r\n ax += x\r\n ay += y\r\n else:\r\n bx += x\r\n by += y\r\nif ax >= ay:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n\r\nif bx >= by:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "n=int(input())\r\na=[0]*n\r\n\r\nfor i in range(n):\r\n a[i] = [0]*3\r\n a[i]=input().split()\r\n\r\n\r\na1 = a2 = b1 = b2 = 0\r\n\r\nfor i in range(n):\r\n if (a[i][0]=='1'):\r\n a1+=int(a[i][1])\r\n a2+=int(a[i][2])\r\n if (a[i][0]=='2'):\r\n b1+=int(a[i][1])\r\n b2+=int(a[i][2])\r\n\r\nif (a1>=a2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n\r\nif (b1>=b2):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")", "a = b = 0\r\nn = int(input())\r\nfor i in range(n):\r\n code, x, y = map(int, input().split())\r\n if code==1: a+=(x-y)\r\n else: b+=(x-y)\r\nif a>=0: print('LIVE')\r\nelse: print('DEAD')\r\nif b>=0: print('LIVE')\r\nelse: print('DEAD')\r\n", "q, a, b = int(input()), [0, 0], [0, 0]\r\nfor x in range(q):\r\n t, x, y = map(int, input().split())\r\n if t == 1: a[0], a[1] = a[0] + x, a[1] + y\r\n else: b[0], b[1] = b[0] + x, b[1] + y\r\nif a[0] >= a[1]: print(\"LIVE\")\r\nelse: print(\"DEAD\")\r\nif b[0] >= b[1]: print(\"LIVE\")\r\nelse: print(\"DEAD\")", "n=int(input())\na=0\nb=0\nsum_a=0\nsum_b=0\nfor i in range(n):\n _list=list(map(int,(input()).split(' ')))\n if _list[0]==1:\n a+=_list[1]\n sum_a+=_list[1]+_list[2]\n else:\n b+=_list[1]\n sum_b+=_list[1]+_list[2]\nif 2*a>=sum_a:\n print('LIVE')\nelse:\n print('DEAD')\nif 2*b>=sum_b:\n print('LIVE')\nelse:\n print('DEAD')", "n = int(input())\r\nsu=suk=su1=suk1=0\r\nfor x in range(n) :\r\n a,b,c=map(int,input().split())\r\n if a==1 :\r\n su+=1\r\n suk+=b\r\n else :\r\n su1+=1\r\n suk1+=b\r\nif su*5<=suk :\r\n print(\"LIVE\")\r\nelse :\r\n print(\"DEAD\")\r\nif su1*5<=suk1 :\r\n print(\"LIVE\")\r\nelse :\r\n print(\"DEAD\")\r\n", "#245A in codeforces\r\nn = int(input())\r\nx_a,y_a,x_b,y_b = 0,0,0,0\r\nfor _ in range(n):\r\n\tt,x,y = map(int,input().split())\r\n\tif t == 1:\r\n\t\tx_a+=x\r\n\t\ty_a+=y\r\n\telif t == 2:\r\n\t\tx_b+=x\r\n\t\ty_b+=y\r\nif x_a>=y_a:\r\n\tserver_a = \"LIVE\"\r\nelse:\r\n\tserver_a = \"DEAD\"\r\nif x_b>=y_b:\r\n\tserver_b = \"LIVE\"\r\nelse:\r\n\tserver_b = \"DEAD\"\r\nprint(server_a)\r\nprint(server_b)", "class Server:\r\n def __init__(self, x, y):\r\n self.x = x\r\n self.y = y\r\n\r\n\r\nn = int(input())\r\nservers = [Server(0, 0) for i in range(2)]\r\n\r\nfor _ in range(n):\r\n t, x, y = map(int, input().split())\r\n servers[t - 1].x += x\r\n servers[t - 1].y += y\r\n\r\nfor i in range(2):\r\n if (servers[i].x) * 2 >= servers[i].x + servers[i].y:\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")", "def s(ar):\r\n aLive, aDead, bLive, bDead = 0, 0, 0, 0\r\n for i in ar:\r\n if i[0] == 1:\r\n aLive += i[1]\r\n aDead += i[2]\r\n if i[0] == 2:\r\n bLive += i[1]\r\n bDead += i[2]\r\n if aLive >= aDead:\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")\r\n if bLive >= bDead:\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")\r\n\r\n\r\ncount = int(input())\r\na = []\r\nfor _ in range(0, count):\r\n a.append(list(map(int, input().split())))\r\ns(a)\r\n", "n = int(input())\r\nout = []\r\nserarec = []\r\nserasen = []\r\nserbrec = []\r\nserbsen = []\r\nfor i in range(n):\r\n lst = [int(j) for j in input().split(\" \")]\r\n if lst[0] == 1:\r\n serarec.append(lst[1])\r\n serasen.append(lst[2])\r\n else:\r\n serbrec.append(lst[1])\r\n serbsen.append(lst[2])\r\nif sum(serarec) >= sum(serasen):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif sum(serbrec) >= sum(serbsen):\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\n", "l = [[0,0],[0,0]]\r\nn = int(input())\r\nfor i in range(n):\r\n t, y, n = map(int, input().split())\r\n l[t-1][0] += y\r\n l[t-1][1] += n\r\nfor i in l:\r\n if i[0] >= i[1]:\r\n print('LIVE')\r\n else:\r\n print('DEAD')", "z=0;x=0;p=0;v=0\r\nfor _ in \" \"*int(input()):\r\n a,b,c=map(int,input().split())\r\n if a==1:z+=b;p+=1\r\n elif a==2:x+=b;v+=1\r\nprint(\"LIVE\" if 5*p<=z else \"DEAD\" );print(\"LIVE\" if 5*v<=x else \"DEAD\")", "n = int(input())\nx1 = x2 = y1 = y2 = 0\nfor _ in range(n):\n t, x, y = map(int, input().split())\n if t == 1:\n x1 += x\n y1 += y\n else:\n x2 += x\n y2 += y\n\nif y1 > x1:\n print(\"DEAD\")\nelse:\n print(\"LIVE\")\nif y2 > x2:\n print(\"DEAD\")\nelse:\n print(\"LIVE\")\n\n", "n = int(input())\r\na_cnt, b_cnt = 0, 0\r\nfor i in range(n):\r\n x = list(map(int, input().split()))\r\n if x[0] == 1:\r\n a_cnt = a_cnt + x[1] - x[2]\r\n else:\r\n b_cnt = b_cnt + x[1] - x[2]\r\nif a_cnt < 0:\r\n print('DEAD')\r\nelif a_cnt >= 0:\r\n print('LIVE')\r\nif b_cnt < 0:\r\n print('DEAD')\r\nelif b_cnt >= 0:\r\n print('LIVE')\r\n", "n = int(input())\r\nka = 0\r\nxa = 0\r\nkb = 0\r\nxb = 0\r\nfor i in range(n):\r\n\tt, x, y = map(int, input().split())\r\n\tif t == 1:\r\n\t\tka += 1\r\n\t\txa += x\r\n\telse:\r\n\t\tkb += 1\r\n\t\txb += x\r\nif ka * 5 <= xa:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\nif kb * 5 <= xb:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\n", "n = int(input())\r\nx1 = 0\r\nx2 = 0\r\np1 = 0\r\np2 = 0\r\nfor i in range(n):\r\n a = input().split()\r\n if a[0] == \"1\":\r\n p1 += int(a[1])\r\n x1 += 10\r\n if a[0] == \"2\":\r\n p2 += int(a[1])\r\n x2 += 10\r\nif p1 >= x1 / 2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\")\r\nif p2 >= x2 / 2:\r\n print(\"LIVE\")\r\nelse:\r\n print(\"DEAD\") \r\n", "n=int(input())\r\nc1=0\r\nc2=0\r\nx1=0\r\nx2=0\r\nfor i in range(n):\r\n\ta,b,c=input().split()\r\n\tif a==\"1\":\r\n\t\tc1+=1\r\n\t\tx1+=int(b)\r\n\telse:\r\n\t\tc2+=1\r\n\t\tx2+=int(b)\r\nif x1>=(10*c1)/2:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")\r\nif x2>=(10*c2)/2:\r\n\tprint(\"LIVE\")\r\nelse:\r\n\tprint(\"DEAD\")", "count = int(input())\n\nsendToA = 0\nsendToB = 0\nreceivedA = 0\nreceivedB = 0\n\nfor i in range(count):\n line = list(map(int, input().split(\" \")))\n if line[0] == 1:\n sendToA += line[1]\n receivedA += line[2]\n else:\n sendToB += line[1]\n receivedB += line[2]\n\nif (sendToA + receivedA) / receivedA >= 2:\n print (\"LIVE\")\nelse:\n print (\"DEAD\")\nif (sendToB + receivedB) / receivedB >= 2:\n print (\"LIVE\")\nelse:\n print (\"DEAD\")\n", "\r\nn = int(input())\r\nx1 = 0\r\ny1 = 0\r\nx2 = 0\r\ny2 = 0\r\nfor i in range(0, n):\r\n ping = input().split(' ')\r\n t, x, y = int(ping[0]), int(ping[1]), int(ping[2])\r\n if t == 1:\r\n x1 += x; y1 += y\r\n else:\r\n x2 += x; y2 += y\r\nif x1 >= y1:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')\r\n \r\nif x2 >= y2:\r\n print('LIVE')\r\nelse:\r\n print('DEAD')", "n = int(input())\r\n\r\na, b = 0, 0\r\n\r\nfor _ in range(n):\r\n\tt, x, y = map(int, input().split())\r\n\r\n\tif t == 1:\r\n\t\ta += x - y\r\n\tif t == 2:\r\n\t\tb += x - y\r\n\r\nprint('LIVE' if a >= 0 else 'DEAD')\r\n\r\nprint('LIVE' if b >= 0 else 'DEAD')\r\n", "n = int(input(\"\"))\r\ns1 = 0\r\ns2 = 0\r\ncount1 = 0\r\ncount2 = 0\r\nfor y in range (n):\r\n t = str(input(\"\")).split()\r\n if t[0] == \"1\":\r\n s1 += int(t[1]) - int(t[2])\r\n count1 += 1\r\n else:\r\n s2 += int(t[1]) - int(t[2])\r\n count2 += 1\r\n\r\nif(count1 > 0):\r\n if (s1 >= 0):\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")\r\n\r\nif(count2 > 0):\r\n if (s2 >= 0):\r\n print(\"LIVE\")\r\n else:\r\n print(\"DEAD\")", "R=lambda:[int(x) for x in input().split()]\r\nnb_cases = int(input())\r\na = [0, 0]\r\nb = [0, 0]\r\n\r\nfor _ in range(nb_cases):\r\n server, worked, failed = R()\r\n if server == 1:\r\n a[0] += worked\r\n a[1] += failed\r\n else:\r\n b[0] += worked\r\n b[1] += failed\r\nprint(\"LIVE\" if a[0] >= a[1] else \"DEAD\")\r\nprint(\"LIVE\" if b[0] >= b[1] else \"DEAD\")\r\n\r\n\r\n", "n=int(input())\r\nlive1, dead1, live2, dead2 = 0, 0, 0, 0\r\nfor i in range(n):\r\n I=[int(j) for j in input().split()]\r\n if I[0]==1:\r\n live1+=I[1]\r\n dead1+=I[2]\r\n else:\r\n live2+=I[1]\r\n dead2+=I[2]\r\nif live1>=(live1+dead1)/2: print('LIVE')\r\nelse: print('DEAD')\r\nif live2>=(live2+dead2)/2: print('LIVE')\r\nelse: print('DEAD')" ]
{"inputs": ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0", "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9", "11\n1 8 2\n1 6 4\n1 9 1\n1 7 3\n2 0 10\n2 0 10\n1 8 2\n2 2 8\n2 6 4\n2 7 3\n2 9 1", "12\n1 5 5\n1 0 10\n1 4 6\n1 2 8\n1 2 8\n1 5 5\n1 9 1\n2 9 1\n1 5 5\n1 1 9\n2 9 1\n2 7 3", "13\n1 8 2\n1 4 6\n1 5 5\n1 5 5\n2 10 0\n2 9 1\n1 3 7\n2 6 4\n2 6 4\n2 5 5\n1 7 3\n2 3 7\n2 9 1", "14\n1 7 3\n1 0 10\n1 7 3\n1 1 9\n2 2 8\n2 0 10\n1 1 9\n2 8 2\n2 6 4\n1 3 7\n1 3 7\n2 6 4\n2 1 9\n2 7 3"], "outputs": ["LIVE\nLIVE", "LIVE\nDEAD", "DEAD\nLIVE", "LIVE\nDEAD", "DEAD\nLIVE", "LIVE\nLIVE", "DEAD\nDEAD"]}
UNKNOWN
PYTHON3
CODEFORCES
300
167db4a35cf6f51b76cf83f7e8c141cf
Brain's Photos
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. Sample Input 2 2 C M Y Y 3 2 W W W W B B 1 1 W Sample Output #Color#Black&amp;White#Black&amp;White
[ "n,m=map(int, input().split())\r\ntemp=\"\"\r\nfor i in range(n):\r\n temp=temp+input()\r\nif temp.count('C')>0 or temp.count('M')>0 or temp.count('Y')>0:\r\n print('#Color')\r\nelse:\r\n print(\"#Black&White\")", "n,m = map(int,input().split())\r\nbw = '#Black&White'\r\nfor i in range(n):\r\n l = list(input().split())\r\n for c in l:\r\n if c != 'W' and c != 'G'and c != 'B':\r\n bw = '#Color'\r\nprint(bw)", "l=list(map(int,input().split()))\r\nt=0\r\nfor i in range(l[0]):\r\n n=list(input())\r\n if \"C\" in n or \"M\" in n or \"Y\" in n:\r\n t=1\r\n\r\nif t==1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "a, b = map(int, input().split())\r\n\r\nw = 0\r\nc = 0\r\ng = 0\r\n\r\nfor i in range(a):\r\n l = list(map(str, input().split()))\r\n \r\n w = l.count('W') + w\r\n c = l.count('B') + c\r\n g = l.count('G') + g\r\n\r\nif (w+c+g) == a * b:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n", "n,m = map(int,input().split())\r\npixels = list(list(map(str,input().split()))for _ in range(n))\r\npix = []\r\nfor i in pixels:\r\n for g in i:\r\n pix.append(g.upper())\r\nif \"C\" in pix or \"M\" in pix or \"Y\" in pix:\r\n print(\"#Color\")\r\nelse :\r\n print(\"#Black&White\")", "\r\n\r\n\r\nl=[]\r\nx,y=(map(int,input().split()))\r\nfor i in range(x):\r\n l+=input().split()\r\nif ('C' in l) or ('M' in l) or ('Y' in l):\r\n print(\"#Color\")\r\nelse:\r\n print('#Black&White')\r\n\r\n\r\n\r\n\r\n\r\n", "n,m=map(int,input().split())\r\ny=1\r\nfor i in range(n):\r\n a=list(map(str,input().split()))\r\n for j in a:\r\n if j!='W' and j!='B' and j!='G':\r\n y=0\r\nif y==1:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')\r\n ", "#A. Brain's Photos\r\ntam = [int(x) for x in input().split(' ')]\r\nr = tam[0]\r\nc = tam[1]\r\nmatriz = []\r\nlista = []\r\nfor i in range(r):\r\n lista = [x for x in input().split(' ')]\r\n matriz.append(lista)\r\ncont = 0\r\nfor i in range(r):\r\n for j in range(c):\r\n if matriz[i][j] == 'C' or matriz[i][j] == 'Y' or matriz[i][j] == 'M':\r\n cont += 1\r\n \r\nif cont > 0:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "y,w = map(int,input().split())\r\nfor i in range(y):\r\n a = list(input().split())\r\n if 'C' in a or 'Y' in a or 'M' in a:\r\n print('#Color')\r\n exit()\r\nprint('#Black&White')", "# def check(s):\r\n# return \"YES\" if s in \"codeforces\" else \"NO\"\r\n\r\n\r\n# for _ in range(int(input())):\r\n# print(check(input()))\r\n\r\n# def candy(n,n_direc):\r\n# x = 0\r\n# y = 0\r\n# for i in n_direc:\r\n# if i == \"R\":\r\n# x += 1\r\n# elif i == \"L\":\r\n# x -= 1\r\n# elif i == \"U\":\r\n# y += 1\r\n# else:\r\n# y -=1\r\n# if x == 1 and y == 1:\r\n# return \"YES\"\r\n# return \"NO\"\r\n\r\n# for _ in range(int(input())):\r\n# n = int(input())\r\n# n_direc = input()\r\n# print(candy(n,n_direc))\r\n\r\n\r\n# for _ in range(int(input())):\r\n# n = int(input())\r\n# n_str = [i for i in input()]\r\n# is_true = True\r\n \r\n# while is_true:\r\n# if len(n_str) == 0:\r\n# is_true = False\r\n# break\r\n\r\n# if (n_str[0] == \"0\" and n_str[-1] == \"1\") or (n_str[-1] == \"0\" and n_str[0] == \"1\"):\r\n# n_str.pop(0)\r\n# n_str.pop(-1)\r\n# else:\r\n# is_true = False\r\n# break\r\n# print(len(n_str))\r\n\r\n\r\n# for _ in range(int(input())):\r\n# n = int(input())\r\n# n_str = input()\r\n# ans = 0\r\n# if len(set(n_str)) == n:\r\n# print(n)\r\n# else:\r\n# val = sum([2 if n_str.count(i) > 1 else 1 for i in set(n_str)]) # maximum possible value of f(a) + f(b) if s are not all distinct\r\n# for i in range(1,n):\r\n# a = n_str[:i]\r\n# b = n_str[i:]\r\n# ans_temp = len(set(a)) + len(set(b))\r\n# if ans_temp > ans:\r\n# ans = ans_temp\r\n# elif ans_temp == val:\r\n# break\r\n# print(ans)\r\n\r\n# for _ in range(int(input())):\r\n# n = int(input())\r\n# n_arr = list(map(int,input().split(\" \")))\r\n# sums = 0\r\n# neg_count = 0\r\n# for i in n_arr:\r\n# if i <= 0:\r\n# neg_count += 1\r\n# sums += abs(i)\r\n# if neg_count % 2 == 1:\r\n# n_arr.sort(key = lambda x: abs(x))\r\n# sums -= abs(n_arr[0] * 2)\r\n# print(sums)\r\n\r\n# for _ in range(int(input())):\r\n# n = int(input())\r\n# n_arr = list(map(int,input().split(' ')))\r\n# if n == sorted(n):\r\n# print(0)\r\n# else:\r\n \r\n\r\n\r\n# n = int(input())\r\n# if n < 3:\r\n# print(-1)\r\n# else:\r\n# if n % 2 == 0:\r\n# print((n**2-4)//4,(n**2+4)//4)\r\n# else:\r\n# print((n**2-1)//2,(n**2+1)//2)\r\n\r\nn,m = map(int,input().split(\" \"))\r\nis_color = False\r\nfor _ in range(n):\r\n pixels = input().split(\" \")\r\n if \"C\" in pixels or \"M\" in pixels or \"Y\" in pixels:\r\n is_color = True\r\n\r\nif is_color == True:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n# def digit_sum(n):\r\n# sum = 0\r\n# while n > 0:\r\n# sum += n % 10\r\n# n = n//10\r\n# return sum\r\n\r\n\r\n# for _ in range(int(input())):\r\n# n,q = map(int,input().split(\" \"))\r\n# n_arr = list(map(int,input().split(\" \")))\r\n# digit_sum_1 = [digit_sum(i) for i in n_arr]\r\n# digit_sum_2 = [digit_sum(i) for i in digit_sum_1]\r\n# oper_count = [0]*n\r\n# for _ in range(q):\r\n# qry = list(map(int,input().split(\" \")))\r\n# if qry[0] == 1:\r\n# for i in range(qry[1]-1,qry[2]):\r\n# if oper_count[i] < 2:\r\n# oper_count[i] += 1\r\n# else:\r\n# for i in range(oper_count[qry[1]-1]):\r\n# if len(str(n_arr[qry[1]-1])) == 1:\r\n# break\r\n# n_arr[qry[1]-1] = digit_sum(n_arr[qry[1]-1])\r\n\r\n# oper_count[qry[1]-1] = 0 \r\n\r\n# print(n_arr[qry[1]-1])", "x, y = map(int, input().split())\r\na = False\r\nfor i in range(x):\r\n z = [item for item in input().split()]\r\n if ('C' in z) or ('M' in z) or ('Y' in z):\r\n a = True\r\nif a:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n", "def solve(n, m):\r\n color = ['C', 'M', 'Y']\r\n for i in range(n):\r\n l = input().split()\r\n for j in l:\r\n if(j in color):\r\n return \"#Color\"\r\n return \"#Black&White\"\r\n\r\n\r\n# for _ in range(int(input())):\r\nn, m = map(int, input().split())\r\nprint(solve(n, m))", "# Link: https://codeforces.com/contest/707/problem/A\n\ncolor_photo = False\nrows, columns = map(int, input().split())\n\nfor _ in range(rows):\n row_pixels = input().split()\n \n if not color_photo:\n if row_pixels.count('C') > 0 or row_pixels.count('M') > 0 or row_pixels.count('Y') > 0:\n color_photo = True\n\nprint(\"#Color\" if color_photo else \"#Black&White\")", "n,m=list(map(int,input().split()))\r\ns=\"\"\r\nfor x in range(n):\r\n list1=input()\r\n s+=list1\r\ns=s.replace(\" \",\"\")\r\nif \"C\" in s or \"M\" in s or \"Y\" in s:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "mx = set()\r\nfor _ in range(int(input().split()[0])):\r\n mx.update(input().split())\r\nprint(['#Black&White','#Color'][bool(mx&{'C','M','Y'})])", "a,b=map(int,input().split())\r\nfor i in range(a):\r\n d=input().split()\r\n if \"C\"in d or \"Y\" in d or \"M\" in d: \r\n print(\"#Color\")\r\n break\r\nelse:\r\n print(\"#Black&White\")", "#707A\r\na,b=map(int,input().split())\r\nl,l1=[],[]\r\nfor i in range(a):\r\n l1=list(map(str,input().split()))\r\n l.extend(l1)\r\nif 'C' in l or 'M' in l or 'Y' in l:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n,m=map(int,input().split())\r\ns=0\r\nfor i in range(n):\r\n x=input().split()\r\n s+=x.count(\"C\")+x.count(\"M\")+x.count(\"Y\")\r\nif s>0:\r\n print(\"#Color\") \r\nelse: \r\n print(\"#Black&White\")", "n, m = list( map(int, input().split()) )\r\n\r\nlst = []\r\nfor _ in range(n):\r\n inp = input().split()\r\n lst.append(inp)\r\n\r\nfor i in range(n):\r\n brk = False\r\n for j in range(m):\r\n ch = lst[i][j]\r\n if ch == 'C' or ch == 'M' or ch == 'Y':\r\n print('#Color')\r\n brk = True\r\n break\r\n if brk:\r\n break\r\nelse:\r\n print('#Black&White')\r\n", "n,m = [int(x) for x in input().split()]\r\nresult = '#Black&White'\r\nfor _ in range(n):\r\n\ts = input().split()\r\n\tfor i in range(m):\r\n\t\tif s[i] in 'CMY':\r\n\t\t\tresult = '#Color'\r\nprint(result)", "\r\nn, m = list(map(int, input().split()))\r\ncol = []\r\n\r\n\r\na = []\r\n\r\nfor i in range(n):\r\n st = input().split()\r\n for i in st:\r\n a.append(i)\r\n\r\nif 'C' in a or 'M' in a or 'Y' in a:\r\n print(\"#Color\")\r\nelse: \r\n print('#Black&White')\r\n ", "n, m = map(int, input().split())\r\n\r\na = [input().split() for _ in range(n)]\r\n\r\nt = False\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] in ['C', 'M', 'Y']:\r\n t = True\r\n break\r\n\r\nif t:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, m = map(int, input().split())\r\nfor i in range(n):\r\n a = list(input().split())\r\n for j in range(m):\r\n if a[j] == 'C' or a[j] == 'Y' or a[j] == 'M':\r\n print('#Color')\r\n quit()\r\nprint('#Black&White')", "n,m = map(int,input().split())\r\na=\"\".join(input() for i in range(n))\r\nif \"C\" in a or \"M\" in a or \"Y\" in a: print(\"#Color\")\r\nelse: print(\"#Black&White\")\r\n", "row, colm = map(int, input().split())\r\nmatrix = [input().split() for i in range(row)]\r\ncount= 0\r\nfor rows in matrix:\r\n for elem in rows:\r\n if elem != 'C' and elem !='M' and elem!='Y':\r\n count+=1\r\nif count == row*colm:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n", "[n, m] = map(int, input().split())\r\nfor i in range(n):\r\n\trow = list(input())\r\n\tif (('C' in row or ('M' in row ) or 'Y' in row)):\r\n\t\tcolor = True \r\n\t\tprint ('#Color')\r\n\t\tquit()\r\nprint ('#Black&White')\r\n ", "n, m = [int(num) for num in input().split()]\nA = [[\"\"] * m for i in range(n)]\nfor i in range(n):\n row = input().split()\n for j in range(m):\n A[i][j] = row[j]\nbw = True\nfor i in range(n):\n for j in range(m):\n c = A[i][j]\n if (c == \"C\" or c == \"M\" or c == \"Y\"):\n bw = False\nif (bw):\n print(\"#Black&White\")\nelse:\n print(\"#Color\")", "n, m = map(int, input().split())\r\nf = [list(map(str, input().split())) for i in range(n)]\r\ncolor = False\r\nfor i in range(n):\r\n for j in range(m):\r\n if f[i][j] == 'C' or f[i][j] == 'M' or f[i][j] == 'Y':\r\n color = True\r\nif color == True:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "# your code goes here\r\nn,m=map(int,input().split())\r\nc='CMY'\r\nres1=\"#Color\"\r\nres2=\"#Black&White\"\r\nflag=0\r\nfor i in range(n):\r\n\tst=input()\r\n\tfor j in c:\r\n\t\tif j in st:\r\n\t\t\tflag=1\r\n\t\t\tbreak\r\nif flag==1:\r\n\tprint(res1)\r\nelse:\r\n\tprint(res2)\r\n\t", "n, m = map(int, input().split())\r\ncolored = False\r\n\r\nfor i in range(n):\r\n a = input().split()\r\n for i in a:\r\n if i != 'W' and i != 'B' and i != 'G':\r\n colored = True\r\n break\r\n if colored:\r\n break\r\n\r\nif colored:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "# 707A\r\n# 1:47 2:01\r\n\r\n# Ok so this is a pretty simple problem. Essentially we just want\r\n# to iterate over each input and determine if a photo is \r\n# #Black&White or #Color\r\n\r\nsetUp = [int(i) for i in input().split()]\r\n\r\nloopNumber = setUp[0]\r\ncolorNumber = setUp[1]\r\n\r\nlistOfColors = []\r\n\r\nfor c in range(loopNumber):\r\n\r\n colors = [str(i) for i in input().split()]\r\n \r\n listOfColors += colors\r\n\r\n\r\nif \"C\" in listOfColors or \"M\" in listOfColors or \"Y\" in listOfColors:\r\n output = \"#Color\"\r\nelse:\r\n output = \"#Black&White\"\r\n \r\nprint(output)\r\n", "a, b = [int(i) for i in input().split()]\r\nc = True\r\nfor i in range(a):\r\n for j in input().split():\r\n if j in \"CMY\":\r\n print(\"#Color\")\r\n c = False\r\n break\r\n if not c:\r\n break\r\nif c:\r\n print(\"#Black&White\")", "n,m=map(int,input().split())\r\nflag=0\r\nfor i in range(n):\r\n s=input().split()\r\n for h in s:\r\n if h=='C' or h=='M' or h=='Y':\r\n flag+=1\r\nif flag>0:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n", "def solve():\n n,m=map(int, input().split(\" \"))\n l = []\n for i in range(n):\n l += input().split(\" \")\n s = set(l)\n a = \"CMYK\"\n for col in a:\n if col in s:\n print (\"#Color\")\n return\n print (\"#Black&White\")\n return\n\nsolve()\n\n\n \n \n", "def main(mainlist):\r\n mainlist = [int(i) for i in mainlist]\r\n colors = ['C','M','Y']\r\n IsColored = False\r\n for i in range(mainlist[0]):\r\n secondlist = input().split()\r\n for el in secondlist:\r\n if el in colors:\r\n IsColored = True\r\n if IsColored:\r\n return '#Color'\r\n return '#Black&White'\r\n\r\nprint(main(input().split()))", "def photographs(matrix, n, m):\r\n for i in matrix:\r\n for j in i:\r\n if j == 'C' or j == 'M' or j == 'Y':\r\n return \"#Color\"\r\n return \"#Black&White\"\r\n \r\nn, m = map(int, input().split())\r\nmatrix = [[x for x in input().split()] for i in range(n)]\r\nprint(photographs(matrix, n, m))", "a,b=map(int,input().split())\r\nf=0\r\nfor x in range(a):\r\n c=list(input().split())\r\n for y in c:\r\n if y=='Y' or y=='M' or y=='C':\r\n f+=1\r\nif f==0:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')", "x,y = map(int, input().split())\r\ndef solve():\r\n for i in range(x):\r\n l= input().split()\r\n for i in l:\r\n if i == \"C\" or i== \"M\" or i== \"Y\":\r\n return \"#Color\"\r\n return \"#Black&White\"\r\nprint(solve())", "n, m = map(int, input().split())\r\nsetm = set()\r\nfor i in range(n):\r\n for j in input().split():\r\n setm.add(j)\r\nif len(setm - {'W', 'B', 'G'}) == 0:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')\r\n", "x1 = int(input().split()[0])\r\nlst, ans = [],[]\r\n\r\nfor i in range(x1):\r\n col1 = input().split()\r\n for c in col1:\r\n lst.append(c)\r\nfor i in set(lst):\r\n if i == \"W\" or i == \"B\" or i == \"G\":\r\n ans.append(\"#Black&White\")\r\n else:\r\n ans.append(\"#Color\")\r\n\r\nx = set(ans)\r\nif len(x) > 1:\r\n print(\"#Color\")\r\nelse:\r\n for i in x:\r\n if i == \"#Black&White\":\r\n print(\"#Black&White\")\r\n else:\r\n print(\"#Color\")", "n,k=map(int,input().split())\r\nh=[]\r\nfor i in range(n):\r\n l=list(map(str,input().split()))\r\n h.extend(l)\r\nif ('C' in h) or ('M' in h) or ('Y' in h):print('#Color')\r\nelse:print('#Black&White')", "a = list(map(int,input().split()))\n\nb = []\n\nbw = ['B','G','W']\n\n\nfor i in range(a[0]):\n b.append(list(input().split()))\n\nc = '#Black&White'\nfor i in b:\n for j in i:\n if j not in bw:\n c = '#Color'\n break\n\nprint(c)\n\n\n", "n, m = map(int, input().split())\r\na = []\r\ncnt = 0\r\nfor i in range(n):\r\n a.append(input().split())\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] == 'C' or a[i][j] == 'M' or a[i][j] == 'Y':\r\n cnt += 1\r\n break\r\nif cnt == 0:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')\r\n", "a,b = map(int,input().split())\r\nphoto = []\r\nfor i in range(a):\r\n photo.append(input().split())\r\ncolorindexs = set()\r\nfor i in photo:\r\n for k in i:\r\n colorindexs.add(k)\r\nprint(\"#Color\" if \"C\" in colorindexs or \"M\" in colorindexs or \"Y\" in colorindexs else \"#Black&White\")\r\n", "x, y = map(int, input().split())\r\ncolor = False\r\nfor i in range(x):\r\n a = list(input().split())\r\n for x in a:\r\n if x in \"CMY\":\r\n color = True\r\n\r\nif color:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n", "n, m = map(int, input().split())\r\na = []\r\ncolor = False\r\nfor i in range(n):\r\n a.append(input().split())\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] in 'CMY':\r\n color = True\r\n break\r\nif color:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "r,c=map(int,input().split())\r\nf=\"#Black&White\"\r\nfor i in range(r):\r\n col=list(map(str,input().split()))\r\n for j in col:\r\n if j in ['C','M','Y']:\r\n f=\"#Color\"\r\nprint(f)", "a, b = input().split()\r\na = int(a)\r\nsum =1\r\nfor i in range(a):\r\n lst = []\r\n lst = input().split()\r\n for j in range(len(lst)):\r\n if lst[j]=='C' or lst[j]=='M' or lst[j]=='Y' :\r\n sum = sum*0\r\n \r\nif sum == 0:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "def is_black_and_white(photo):\r\n colors = set()\r\n for row in photo:\r\n colors.update(row)\r\n \r\n return colors <= {'W', 'G', 'B'}\r\n\r\nn, m = map(int, input().split())\r\nphoto = [input().split() for _ in range(n)]\r\n\r\nif is_black_and_white(photo):\r\n print('#Black&White')\r\nelse:\r\n print('#Color')", "n, m = map(int, input().split())\r\nfor i in range(n):\r\n arr = list(input().split())\r\n if \"C\" in arr or \"Y\" in arr or \"M\" in arr:\r\n print(\"#Color\")\r\n quit()\r\nprint(\"#Black&White\")", "a=input().split()\r\nw=[]\r\ne=int(a[0])\r\nfor i in range(e):\r\n\ts=input().split()\r\n\tw=w+s\r\nif \"C\"in w or \"M\"in w or \"Y\"in w:\r\n\tprint(\"#Color\")\r\nelse:\r\n\tprint(\"#Black&White\")", "n, m = map(int, input().split())\r\nf = 0\r\nfor _ in range(n):\r\n s = input().split()\r\n for c in \"CMY\":\r\n if c in s:\r\n f = 1\r\n break\r\n if f:\r\n break\r\nif f:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "def photo_color(n, m, matrix):\r\n for i in range(n):\r\n for j in range(m):\r\n if matrix[i][j] in {'C', 'M', 'Y'}:\r\n return \"#Color\"\r\n return \"#Black&White\"\r\n\r\nn, m = map(int, input().split())\r\nmatrix = [input().split() for _ in range(n)]\r\n\r\nresult = photo_color(n, m, matrix)\r\nprint(result)\r\n", "n, m = map(int, input().split())\r\nfor i in range(n):\r\n s = input()\r\n if \"C\" in s or \"Y\" in s or \"M\" in s:\r\n print(\"#Color\")\r\n exit()\r\nprint(\"#Black&White\")", "n, m = map(int, input().split())\r\n\r\n# Initialize a set to store unique colors\r\ncolors = set()\r\n\r\nfor _ in range(n):\r\n row = input().split()\r\n # Add unique colors to the set\r\n colors.update(row)\r\n\r\n# Check for colored pixels\r\nif 'C' in colors or 'M' in colors or 'Y' in colors:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n, m = map(int, input().split())\r\nb = []\r\nfor x in range(n):\r\n a = input().split()\r\n for y in a:\r\n if y not in b:\r\n b.append(y)\r\nif \"C\" in b or \"M\" in b or \"Y\" in b:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "x,y=map(int,input(\"\").split(\" \"))\r\nl=[]\r\nl2=[]\r\nfor i in range(x):\r\n l.append(input(\"\").split(\" \"))\r\nfor q in l:\r\n for n in q:\r\n l2.append(n) \r\n\r\n \r\nif 'C' in l2 or 'M' in l2 or 'Y' in l2:\r\n print(\"#Color\")\r\n \r\nelse:\r\n print(\"#Black&White\")\r\n ", "n, m = map(int, input().split())\r\nwb = set(\"WGB\")\r\nfor _ in range(n):\r\n line = input().split()\r\n for elem in line:\r\n if elem not in wb:\r\n print(\"#Color\")\r\n exit()\r\nprint(\"#Black&White\")\r\n\r\n", "n,m=map(int,input().split());p=\"#Black&White\"\r\nfor i in range(n):\r\n\ts=list(map(str,input().split()))\r\n\tif 'C' in s or 'Y' in s or 'M' in s:\r\n\t\tp=\"#Color\"; break\r\nprint(p)", "matrix_number = list(map(int , input().split()))\r\nopen = 0\r\nfor i in range (0 , matrix_number[0]) :\r\n row_elements = list(input().split())\r\n if open == 0 :\r\n for j in row_elements :\r\n if j != 'W' and j !='G' and j != 'B' :\r\n open = 1\r\n print('#Color')\r\n break\r\n else :\r\n break\r\nif(open == 0 ):\r\n print(\"#Black&White\")", "n, m = map(int, input().split())\r\na = []\r\nflag = '#Black&White'\r\n\r\nfor i in range(n):\r\n a.append(input())\r\n\r\nfor i in range(n):\r\n for j in a[i]:\r\n if j in 'CMY':\r\n flag = '#Color'\r\nprint(flag)", "n, m = map(int, input().split())\r\n\r\nis_colored = False\r\nfor i in range(n):\r\n row = input().split()\r\n for pixel in row:\r\n if pixel in ['C', 'M', 'Y']:\r\n is_colored = True\r\n break\r\n\r\nif is_colored:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "a = map(int,input().split())\r\na = list(a)\r\nz = 0\r\nfor i in range(a[0]):\r\n b = input().split()\r\n c = b.count(\"W\")\r\n d = b.count(\"B\")\r\n e = b.count(\"G\")\r\n f = c+d+e\r\n if a[1] == f:\r\n z+=1\r\nif z == a[0]:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n \r\n\r\n", "m,n = map(int,input().split())\r\nres = '#Black&White'\r\nfor i in range(m):\r\n colors = list(input().split())\r\n if 'C' in colors or 'M' in colors or 'Y' in colors:\r\n res='#Color'\r\n break \r\nprint(res)", "n,m=map(int,input().split())\r\nfor i in range(n):\r\n a=input()\r\n if 'C' in a or 'M' in a or 'Y' in a:\r\n print('#Color')\r\n break\r\nelse:\r\n print('#Black&White')", "n, m = map(int, input().split())\r\na = []\r\ncount = 0\r\nfor i in range(n):\r\n a.append(list(map(str, input().split())))\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] == 'W' or a[i][j] == 'G' or a[i][j] == 'B':\r\n count += 1\r\n\r\nif count == n * m:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')\r\n", "n, m = map(int, input().split())\r\nmatrix = [[j for j in input().split()] for _ in range(n)]\r\n#for row in matrix:\r\n# print(*row)\r\noutput = '#Black&White'\r\nfor i in range(n):\r\n for j in range(m):\r\n if matrix[i][j] in ('C', 'M', 'Y'):\r\n output = '#Color'\r\n break\r\nprint(output) \r\n", "n = input().split()\r\ntotal = 0\r\nfor _ in range(int(n[0])):\r\n i = input().split()\r\n for j in i:\r\n if j == 'W' or j == 'G' or j == 'B':\r\n total += 1\r\nif total == int(n[0]) * int(n[1]):\r\n print('#Black&White')\r\nelse:\r\n print('#Color')\r\n", "[r,c] = list(map(int,input().split(' ')))\r\n\r\nfor i in range(r):\r\n\r\n col = input().split(' ')\r\n \r\n if( 'C' in col or 'M' in col or 'Y' in col ):\r\n \r\n print('#Color')\r\n break\r\n \r\n if( i == (r - 1) ):\r\n print('#Black&White')", "m,n = map(int, input().split())\nlst = []\nfor _ in range(m):\n pix = list(input().split())\n lst.extend(pix)\nif 'C' in lst or 'M' in lst or 'Y' in lst:\n print(\"#Color\")\nelse:\n print(\"#Black&White\")", "# ██████╗\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\n\r\nn, m = map(int, input().split())\r\na = []\r\nfor i in range(n):\r\n a += list(input().split())\r\nif a.count('C') != 0 or a.count('M') != 0 or a.count('Y') != 0:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n", "time = input().split(' ')\r\ntime = int(time[0])\r\ncolor = 0\r\ncolors = ''\r\nfor i in range(time):\r\n colors += input()\r\nif 'C' in colors or 'M' in colors or 'Y' in colors: print('#Color')\r\nelse: print('#Black&White')\r\n", "n,m = map(int,input().split())\r\nli=[]\r\nli1=[]\r\ncolours_all = ['C', 'M', 'Y', 'W', 'G','B']\r\nfor i in range(n):\r\n colours = list(map(str,input().split()))\r\n li.append(colours)\r\nfor item in li:\r\n for letter in item:\r\n li1.append(letter)\r\n\r\nif 'C' in li1 or 'M' in li1 or 'Y' in li1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, m = [int(i) for i in input().split()]\r\ncolors = ''\r\nisBlack = '#Black&White'\r\nfor i in range(n):\r\n colors += input()\r\nif 'C' in colors or 'M' in colors or 'Y' in colors:\r\n isBlack = '#Color'\r\nprint(isBlack)", "def brain_photos():\r\n\trows, cols = map(int, input().split())\r\n\tBWG = {'B', 'W', 'G'}\r\n\tfor row in range(rows):\r\n\t\tcolors = input().split()\r\n\t\tfor color in colors:\r\n\t\t\tif color in ['C', 'M', 'Y']:\r\n\t\t\t\treturn \"#Color\"\r\n\treturn \"#Black&White\"\r\nprint(brain_photos())\r\n", "t, n = map(int, input().split(' '))\r\ns = ''\r\nfor i in range(t):\r\n s += input()\r\nif 'C' in s or 'M' in s or 'Y' in s:\r\n print('#Color')\r\nelif 'C' not in s or 'M' not in s or 'Y' not in s:\r\n print('#Black&White')\r\n", "a,b = map(int,input().split())\r\nl= []\r\nfor i in range(a):\r\n l1 = list(map(str,input().split()))\r\n l.append(l1)\r\nfor i in l:\r\n if('C' in i or 'M' in i or 'Y' in i):\r\n print(\"#Color\")\r\n break\r\nelse:\r\n print(\"#Black&White\")", "n,m=map(int,input(\"\").split())\r\nsum=0\r\nfor x in range (n):\r\n e =input(\"\")\r\n #print(e)\r\n for i in range(len(e)):\r\n if e[i]=='C' or e[i]=='M' or e[i]=='Y':\r\n sum+=1\r\n #print (sum)\r\nif sum==0:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')\r\n\r\n\r\n\r\n\r\n", "n, m = map(int, input().split())\r\nphoto = [list(map(str, input().split())) for i in range(n)]\r\n\r\nk = 0\r\nfor i in range(n):\r\n for j in range(m):\r\n if photo[i][j] in ['C', 'M', 'Y']:\r\n k = 1\r\n print('#Color')\r\n break\r\n if k == 1:\r\n break\r\nif k == 0:\r\n print('#Black&White')\r\n", "n, m = map(int, input().split())\r\n\r\ncolors = [list(map(str, input().split())) for _ in range(n)]\r\n\r\nif any('C' in row or 'M' in row or 'Y' in row for row in colors):\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n,m=map(int, input().split())\r\nx=0\r\nfor i in range(n):\r\n a=list(map(str, input().split()))\r\n if 'C' in a or 'M' in a or 'Y' in a:\r\n x=1\r\nif x:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, _ = map(int,input().split())\r\ncolorl = []\r\nfor i in range(n):\r\n colorl.append(input())\r\nfor i in range(n):\r\n if 'Y' in colorl[i] or 'C' in colorl[i] or 'M' in colorl[i]:\r\n print('#Color')\r\n break\r\n if i == n-1:\r\n print('#Black&White')\r\n \r\n", "n, m = map(int,input().split())\r\ncolor = \"CMY\"\r\nfor i in range(n):\r\n s = input()\r\n for c in s:\r\n if c in color:\r\n print(\"#Color\")\r\n exit()\r\nprint(\"#Black&White\")\r\n", "def code(arr, n):\r\n for i in range(n):\r\n if 'C' in arr[i] or 'M' in arr[i] or 'Y' in arr[i]:\r\n return False\r\n return True\r\n\r\n\r\n\r\n\r\nn, m = list(map(int, input().split()))\r\narr = []\r\n\r\nfor i in range(n):\r\n arr.append(input().split())\r\n\r\nresult = code(arr, n)\r\n\r\nif result:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n", "\r\nval = False\r\nrows, cols = map(int,input().split())\r\nfor i in range(rows):\r\n b = input().split()\r\n if \"C\" in b or \"M\" in b or \"Y\" in b:\r\n val = True\r\n \r\nif val == False:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "a, b = map(int, input().split())\r\ncolor = 0\r\nfor i in range(1, a+1):\r\n li = list(input().split())\r\n for x in range(len(li)):\r\n if li[x] == \"C\" or li[x] == \"M\" or li[x] == \"Y\":\r\n color += 1\r\nif color == 0:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "n, _ = map(int, input().split())\r\n\r\nc = False;\r\nfor _ in range(n):\r\n x = input()\r\n if 'Y' in x or 'C' in x or 'M' in x:\r\n c = True\r\n\r\nprint('#Color' if c else '#Black&White')", "n, m = map(int, input().split())\r\nans = \"#Black&White\"\r\nfor i in range(n):\r\n l = list(input())\r\n if \"C\" in l or \"M\" in l or \"Y\" in l:\r\n ans = \"#Color\"\r\nprint(ans)", "import sys\r\ninput = lambda : sys.stdin.readline().strip()\r\n#############################################################################################################################\r\nn,m = map(int,input().split())\r\na = ''\r\nfor i in range(n):\r\n a += input()\r\nif ('C' in a) or ('M' in a) or ('Y' in a):\r\n print('#Color')\r\n \r\nelse:\r\n print('#Black&White')\r\n", "# Dread it, run from it, destiny arrives all the same. \r\ndef solve(): \r\n n, m = map(int, input().split())\r\n flag = False \r\n\r\n for _ in range(n):\r\n row = input().split()\r\n row = \"\".join(row)\r\n for ind in range(m):\r\n if row[ind] == \"C\" or row[ind] == \"M\" or row[ind] == \"Y\":\r\n flag = True \r\n \r\n if flag: print(\"#Color\")\r\n else: print(\"#Black&White\")\r\n \r\n return \r\n\r\nif __name__ == \"__main__\": \r\n # for _ in range(int(input())):\r\n # solve()\r\n solve()", "#Фотографии Брейна\r\nn, m = map(int, input().split())\r\ns = [input().split() for i in range(n)]\r\n\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if s[i][j] == \"C\" or s[i][j] == \"M\" or s[i][j] == \"Y\":\r\n print(\"#Color\")\r\n exit()\r\n else:\r\n continue\r\nprint(\"#Black&White\")\r\n\r\n\r\n\r\n\r\n\r\n", "l = [int(x) for x in input().split()]\r\nt = []\r\nfor i in range(l[0]):\r\n m = [col for col in input().split()] \r\n t.append(m)\r\ncount = 0\r\nfor i in range(len(t)):\r\n for j in range(len(t[0])):\r\n if t[i][j] == 'C' or t[i][j] == 'M' or t[i][j] == 'Y':\r\n count += 1\r\n \r\nif count == 0:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "row,col = input().split()\r\nrow = int(row)\r\ncol = int(col)\r\nc = 0\r\nm = 0\r\ny = 0\r\nfor i in range(0,row):\r\n lst = input().split()\r\n for j in range(0,col):\r\n if lst[j]=='C':\r\n c += 1\r\n elif lst[j]=='M':\r\n m += 1\r\n elif lst[j]=='Y':\r\n y += 1\r\nif c==0 and m==0 and y==0:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')\r\n ", "def isBlack(a):\r\n for i in a:\r\n if i in c:\r\n return False\r\n return True\r\n\r\n\r\nn, m = [int(x) for x in input().split()]\r\nisb = True\r\ncolors = []\r\n\r\nfor i in range(n):\r\n colors.append(input())\r\nc = ['C', 'M', 'Y']\r\n\r\nfor i in colors:\r\n if not isBlack(i.split()):\r\n isb = False\r\n break\r\n\r\nif isb:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')\r\n", "n,m=map(int,input().split())\r\nk=[]\r\nfor i in range(n):\r\n a=input().split()\r\n k+=a\r\nif 'C' in k or 'M' in k or 'Y' in k:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "n, m = map(int, input().split())\r\ncolors = []\r\nfor _ in range(n):\r\n colors += input().split()\r\n\r\ns = {''}\r\ns = set(colors)\r\n\r\nif len(s) > 3:\r\n print(\"#Color\")\r\nelse:\r\n a = 'W' in s\r\n b = 'B' in s\r\n c = 'G' in s\r\n d = 0\r\n if a:\r\n d+=1\r\n if b:\r\n d+=1\r\n if c:\r\n d+=1\r\n\r\n if (len(s) == 3 and d == 3) or (len(s) == 2 and d == 2) or (len(s) == 1 and d == 1):\r\n print(\"#Black&White\")\r\n else:\r\n print(\"#Color\")\r\n\r\n", "n, m = map(int,input().split())\r\nmatx = []\r\nfor i in range(n):\r\n for y in input().split():\r\n matx.append(str(y))\r\nif ('C' in set(matx)) or ('M' in set(matx)) or ('Y' in set(matx)):\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "a,b=map(int,input().split())\r\nx=sum([[i for i in input().split()]for j in range(a)],[])\r\nif x.count('W')+x.count('G')+x.count('B')==a*b: print('#Black&White')\r\nelse: print('#Color')", "colored_exclusive_colors = {\"C\", \"M\", \"Y\"}\r\nfor _ in range(int(input().split()[0])):\r\n for pixel_color in input().split():\r\n if pixel_color in colored_exclusive_colors:\r\n print(\"#Color\")\r\n exit()\r\nprint(\"#Black&White\")", "a,b = map(int, input().split())\r\nv = [\"C\",\"M\",\"Y\"]\r\nc=0\r\nfor i in range(a):\r\n \r\n x = list(map(str, input().split()))\r\n for k in x :\r\n \r\n if k in v :\r\n c+=1\r\n else:\r\n pass\r\n \r\nif c > 0 :\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "# cook your dish here\r\nn,m = map(int,input().split())\r\nl = []\r\nfor i in range(n):\r\n temp = list(map(str,input().split()))\r\n l = l + temp\r\nif 'C' in l or 'M' in l or 'Y' in l:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "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, m = map(int, input().split())\r\n l = []\r\n for i in range(n):\r\n l.extend([*map(str, input().split())])\r\n s = set(l)\r\n c = len(s)\r\n if c == 1 and (\"G\" in s or \"B\" in s or \"W\" in s):\r\n return f\"#Black&White\"\r\n elif c == 3 and \"G\" in s and \"B\" in s and \"W\" in s:\r\n return f\"#Black&White\"\r\n elif c == 2 and ((\"G\" in s and \"B\" in s) or (\"G\" in s and \"W\" in s) or (\"B\" in s and \"W\" in s)):\r\n return f\"#Black&White\"\r\n else:\r\n return f\"#Color\"\r\n\r\nstdout.write(solve())", "import sys\n\nn, m = map(int, input().split())\ns = sys.stdin.read()\nis_black_and_white = all(c.isspace() or c in \"BGW\" for c in s)\nprint(\"#Black&White\" if is_black_and_white else \"#Color\")\n", "t,_ = map(int, input().split())\r\n\r\ncolors = []\r\nfor _ in range(t):\r\n c = list(map(str, input().split()))\r\n \r\n colors += c\r\n\r\nblackAndWhite = True\r\nfor colored in ['C','M','Y']:\r\n if colored in colors:\r\n blackAndWhite = False\r\n break\r\n\r\nif blackAndWhite:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')", "n,m = input().split()\r\nx,y,z = \"C\", \"M\", \"Y\"\r\nflag = False\r\npix_col = \"\"\r\n\r\nfor i in range(int(n)):\r\n pix_col += input()\r\n \r\nif x in pix_col or y in pix_col or z in pix_col:\r\n flag = True\r\n print(\"#Color\")\r\n \r\nif flag is False:\r\n print(\"#Black&White\")\r\nelse:\r\n pass", "n, m = map(int, input().split())\r\na = []\r\nfor i in range(n):\r\n a.append(list(map(str, input().split())))\r\ngwb = 0\r\nfor i in a:\r\n for j in i:\r\n if j == 'G' or j == 'B' or j == 'W':\r\n gwb += 1\r\nif gwb == n*m:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')", "n, m = map(int, input().split())\r\na = [list(input().split()) for _ in range(n)]\r\nb = ['B', 'W', 'G']\r\n\r\nbreak_out_flag = False\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] not in b:\r\n print('#Color')\r\n break_out_flag = True\r\n break\r\n if break_out_flag:\r\n break\r\nelse:\r\n print('#Black&White')\r\n", "n,m=map(int,input().split())\r\nbw=['W','G','B']\r\nco=['C','M','Y']\r\ncnt_bw=0\r\ncnt_co=0\r\nfor i in range(n):\r\n a=list(map(str,input().split()))\r\n for j in range(m):\r\n if a[j] in bw:\r\n cnt_bw+=1\r\n elif a[j] in co:\r\n cnt_co+=1\r\nif cnt_bw==n*m:\r\n print('#Black&White')\r\nelif cnt_co==n*m:\r\n print('#Color')\r\nelse:\r\n print('#Color')", "n, m = map(int, input().split())\r\nmatrix = [input().split() for _ in range(n)]\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if matrix[i][j] in ['C', 'M', 'Y']:\r\n print(\"#Color\")\r\n exit()\r\n\r\nprint(\"#Black&White\")\r\n", "n1,n2=map(int,input().split())\r\nl=[];c=0\r\nfor i in range(n1):\r\n m=list(map(str,input().split()))\r\n l.append(m)\r\nfor i in l:\r\n c+=i.count(\"Y\") + i.count(\"M\") + i.count(\"C\")\r\n if c>=1:\r\n print(\"#Color\")\r\n break\r\n else:\r\n continue\r\nif c==0:\r\n print(\"#Black&White\")\r\n\r\n\"\"\"\r\n\r\nI do not understand the reason for your stupid substitutions in the last match against Everton,\r\nyou took out the best players and entered the worst (with respect to them) and played in a defensive way,\r\nall this in order to maintain the lead with a goal while you are playing in home !!!!!\r\nWhat are you doing please we are not a mid-league team we want to fight for titles and I don't think you are the right person\r\n(with all my respect to you but please please please leave the club)\r\n:(\r\n\r\n\"\"\"", "n, m =list(map(int, input().split()))\r\nbw = True\r\nfor _ in range(n):\r\n s = input().split()\r\n for x in s:\r\n if x not in {'W', 'G', 'B'}:\r\n bw = False\r\n break\r\nif bw:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "n, m = map(int, input().split())\r\n\r\na = []\r\nL = 'WGB'\r\nrez = '#Black&White'\r\n\r\nfor i in range(n):\r\n a.append(input().split())\r\n for j in range(m):\r\n if not a[i][j] in L:\r\n rez = '#Color'\r\n break\r\n\r\nprint(rez)\r\n \r\n", "n, m = map(int, input().split())\r\nans = \"#Black&White\"\r\nc = 'CMY'\r\nfor i in range(n):\r\n for el in input().split():\r\n if el in c:\r\n ans = \"#Color\"\r\nprint(ans)", "def solve():\r\n x, y = map(int, input().split())\r\n st = set()\r\n for i in range(x):\r\n clr = [i for i in input().split()]\r\n st.update(clr)\r\n if 'C' not in st and 'M' not in st and 'Y' not in st:\r\n print('#Black&White')\r\n else:\r\n print('#Color')\r\n\r\n\r\n# t = int(input())\r\nt = 1\r\nwhile t:\r\n solve()\r\n t -= 1\r\n", "column, string=list(map(int, input().split()))\r\nrgb=['C', 'M', 'Y']\r\nresult=[]\r\nfor i in range(column):\r\n color=input().split()\r\n for j in color:\r\n if j in rgb:\r\n result.append('C')\r\nif result:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n", "#Coder_1_neel\r\nx,y = map(int,input().split())\r\ncolor=False\r\nfor i in range(x):\r\n n=input().split()\r\n if \"C\" in n or \"M\" in n or \"Y\" in n:\r\n color=True\r\n break\r\n\r\nif color:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n, m = map(int, input().split())\r\n\r\ncolors = 'CMY'\r\ncolored_photo = False\r\nnot_tested = True \r\nfor i in range(n):\r\n n = input()\r\n if not_tested:\r\n for i in n: \r\n if i in colors:\r\n colored_photo = True \r\n not_tested = False \r\n break \r\n\r\n\r\nif colored_photo:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, m = map(int, input().split())\r\na = []\r\nr = \"#Black&White\"\r\nfor i in range(n):\r\n a.append(list(input().split()))\r\nfor i in a:\r\n for j in i:\r\n if j in ('C', 'M', 'Y'):\r\n r = '#Color'\r\n break\r\n if r == '#Color':\r\n break\r\nprint(r)", "n, m = map(int, input().split())\r\n\r\ncolored = False\r\nfor i in range(n):\r\n row = input().split()\r\n if 'C' in row or 'M' in row or 'Y' in row:\r\n colored = True\r\n break\r\n\r\nif colored:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n,m = map(int,input().split())\r\n\r\nisColored = False\r\nfor i in range(n):\r\n colors = input()\r\n\r\n if 'C' in colors or 'M' in colors or 'Y' in colors:\r\n isColored = True\r\n\r\nif isColored:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "n,m=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n\tl+=input().split()\r\n\tif(\"C\" in l or \"M\" in l or \"Y\" in l):\r\n\t\tprint(\"#Color\")\r\n\t\tbreak\r\nelse:\r\n\tprint(\"#Black&White\")", "m,n=map(int,input().split())\r\nf=0\r\nfor i in range(m):\r\n a=list(input().split())\r\n if 'C' in a or 'M' in a or 'Y' in a:\r\n f=1\r\nif f==1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n,m = map(int,input().split())\r\na = []\r\nflag = 0\r\nfor i in range(n):\r\n color = list(map(str,input().split()))\r\n a.append(color)\r\nfor i in range(n):\r\n for j in range(m):\r\n if(a[i][j] == 'C' or a[i][j] == 'M' or a[i][j] == 'Y'):\r\n print(\"#Color\")\r\n flag = 1\r\n break\r\n else:\r\n continue\r\n if(flag):\r\n break\r\nif(flag == 0):\r\n print(\"#Black&White\")", "x1 = int(input().split()[0])\r\nlst = []\r\nans = 0\r\nfor i in range(x1):\r\n col = input().split()\r\n for e in col:\r\n lst.append(e)\r\n\r\nfor e in lst:\r\n if e == 'C' or e == 'M' or e == 'Y':\r\n ans = '#Color'\r\n break\r\n else:\r\n ans = \"#Black&White\"\r\n\r\nprint(ans)", "n,m=map(int,input().split())\nblack=True \nfor i in range(n):\n a=input()\n if 'C' in a or 'M' in a or 'Y' in a:\n black = False\n\nif not black:\n print('#Color')\nelse:\n print('#Black&White')\n\n\n\n ", "n, m = list(map(int, input().split()))\r\nbw = ['W', 'B', 'G', ' ']\r\ndef solve():\r\n ans = \"#Black&White\"\r\n for i in range(n):\r\n inp = input()\r\n for a in inp:\r\n if a not in bw:\r\n ans = \"#Color\"\r\n return ans\r\nprint(solve())", "import re\r\na, z = [int(x) for x in input().split()]\r\nfor _ in range(a):\r\n if re.search(\"[CMY]\", input()):\r\n print(\"#Color\")\r\n exit()\r\nprint(\"#Black&White\")", "l=[int(i) for i in input().split(' ')]\nc=0\nls=['C','M','Y']\nfor i in range(l[0]):\n s=[1 for j in input().split(' ') if j in ls]\n c+=sum(s)\nif c==0:\n print(\"#Black&White\")\nelse:\n print(\"#Color\")\n", "print('#Black&White' if all(all(i in 'BGW' for i in x.split()) for x in [input() for _ in range(int(input().split()[0]))]) else '#Color')\n", "n,m = map(int,input().split())\r\ncolour = [\"C\",\"M\",\"Y\"]\r\nflag = 1\r\nfor i in range(n):\r\n l = list(input())\r\n for x in l :\r\n if x in colour :\r\n flag = 0\r\n break\r\nif flag == 0:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n\r\n\r\n ", "n,m=input().split(\" \")\r\nn=eval(n)\r\nm=eval(m)\r\narray=[]\r\nfor i in range(n):\r\n temp=input().split(\" \")\r\n array.append(temp)\r\n\r\nflag= True\r\nfor i in range(n):\r\n if \"C\"in array[i] or \"M\"in array[i] or \"Y\"in array[i]:\r\n flag=False\r\n\r\nif flag:\r\n print(\"#Black&White\")\r\nelse :\r\n print(\"#Color\")", "rows, columns = map(int, input().split())\r\nmylist = []\r\nfor i in range(rows):\r\n colors = list(input().split())\r\n mylist.extend(colors)\r\nfor r in mylist:\r\n if r == \"C\" or r == \"M\" or r == \"Y\":\r\n print(\"#Color\")\r\n exit()\r\nprint(\"#Black&White\")\r\n", "a=[]\r\nn=list(map(int,input().split()))\r\nfor x in range(n[0]):\r\n\tn=input().split()\r\n\ta+=n\r\nif \"C\" in a or \"M\" in a or \"Y\" in a:print(\"#Color\")\r\nelse:print(\"#Black&White\")", "n,m=input().split()\r\nn,m=int(n),int(m)\r\ncolors=[]\r\ndef is_colored(mylist):\r\n for x in mylist:\r\n if x.upper() not in [\"B\",\"W\",\"G\"]:\r\n return True\r\n return False\r\nfor x in range(n):\r\n colors.append(input().split())\r\n\r\nfor color in colors:\r\n if is_colored(color):\r\n print(\"#Color\")\r\n break\r\n\r\nelse:print(\"#Black&White\")\r\n \r\n", "n, m = [int(x) for x in input().split()]\r\npixels = \"\"\r\nblack_and_white, colors = False, False\r\nfor i in range(n):\r\n pixels = [x for x in input().split()]\r\n if \"C\" in pixels or \"Y\" in pixels or \"M\" in pixels:\r\n colors = True\r\n\r\nif not colors:\r\n print(\"#Black&White\")\r\n\r\nelse:\r\n print(\"#Color\")", "n, m = map(int, input().split())\r\n\r\nbw, co = 0, 0\r\n\r\nfor i in range(n):\r\n color = list(map(str, input().split()))\r\n\r\n for j in color:\r\n if j == 'W' or j == 'G' or j == 'B':\r\n bw += 1\r\n else:\r\n co += 1\r\n\r\nif co == 0:\r\n print('#Black&White')\r\nelse:\r\n print(\"#Color\")", "Rowncloumn=list(map(int,input().split()))\r\nl=[]\r\nfor i in range(Rowncloumn[0]):\r\n n=list(input().split())\r\n for t in n:\r\n l.append(t)\r\nif 'C' in l or 'M' in l or 'Y' in l:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "# https://codeforces.com/problemset/problem/707/A\n\nimport sys\n\nif __name__ == \"__main__\":\n # The photo is considered black-and-white if it has only white, black and\n # grey pixels in it. If there are any of cyan, magenta or yellow pixels in\n # the photo then it is considered colored.\n\n # skip first line\n next(sys.stdin)\n label = \"#Black&White\"\n for line in sys.stdin:\n has_color = any(map(lambda c: c in line.strip().split(), (\"C\", \"M\", \"Y\")))\n if has_color:\n label = \"#Color\"\n break\n print(label)\n", "row, coloum = map(int,input().split())\r\nresult = \"#Black&White\"\r\nfor i in range(row) : \r\n line = [None] * coloum \r\n line = input().split() \r\n if 'C' in line or 'M' in line or 'Y' in line : \r\n result = '#Color'\r\nprint(result)", "# 707A\r\n''' Author : Kunj Gandhi '''\r\n\r\n'''Functions'''\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\n\r\n'''Code'''\r\nn,m = sp_inp()\r\ncheck = 0 # 0 -> b&w , otherwise color\r\nfor i in range(n):\r\n s = input()\r\n if(s.find(\"C\")!=-1 or s.find(\"M\")!=-1 or s.find(\"Y\")!=-1):\r\n check = 1\r\nif(check==1): print(\"#Color\")\r\nelse: print(\"#Black&White\")", "a,b=map(int,input().split())\r\nfor i in range(a):\r\n n=list(map(str,input().split()))\r\n if 'Y' in n or 'M' in n or 'C' in n:\r\n print('#Color')\r\n exit()\r\nelse:\r\n print('#Black&White')\r\n", "r, c = map(int, input().split())\r\nis_color = False\r\n\r\nfor _ in range(r):\r\n line = input().split()\r\n for color in line:\r\n if color not in ('W', 'G', 'B'):\r\n is_color = True\r\n break\r\n\r\nprint(\"#Color\" if is_color else \"#Black&White\")\r\n", "n,m=map(int,input().split())\r\nd=dict()\r\nflag=False\r\nfor i in range(n):\r\n for j in input().split():\r\n for k in j:\r\n if k=='C' or k=='M' or k=='Y':\r\n print(\"#Color\")\r\n exit()\r\nprint('#Black&White')", "n, m = map(int,input().split(' '))\na = \"#Black&White\"\nfor linea in range(n):\n values = list(input().split(' '))\n for valor in values:\n if valor == 'C' or valor == 'M' or valor == 'Y':\n a = \"#Color\"\n break\nprint(a)\n", "n , m =map(int,input().split())\r\n\"тігінен жолға көлденең жол қосады \"\r\n\"\"\"1 2 3\r\n 5 9 7 \"\"\"\r\na =[]\r\ncolor = 0\r\nfor i in range(n):\r\n a.append(list(map(str, input().split()))[:m])\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] == \"C\" or a[i][j] == \"M\" or a[i][j] == \"Y\":\r\n color = color+1\r\nif color>= 1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "#!/bin/python3\n\nN, M = [ int(i) for i in input().split() ]\n\npb = True\nfor _ in range( N ):\n cores = input().split()\n for cor in cores:\n if cor in ( 'C', 'M', 'Y' ):\n pb = False\n\nif not pb:\n print( \"#Color\" )\nelse:\n print( \"#Black&White\" )\n\n\n\n\n\n# | a | b | \n# =========\n# | F | F | F\n# | V | F | F\n# | F | V | F\n# | V | V | V\n\n", "n, m = map(int, input().split())\r\n\r\ngreyscale = True\r\nfor i in range(n):\r\n colors = list(input().split())\r\n if \"C\" in colors or \"M\" in colors or \"Y\" in colors:\r\n greyscale = False\r\n\r\nif greyscale:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "n,m=map(int,input().split())\r\na=[]\r\ncount=0\r\ncolor=\"CMY\"\r\nfor i in range(n):\r\n a.append(list(map(str,input().split())))\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] in color:\r\n count+=1\r\nif count==0:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "def foto(f):\n for i in f:\n for p in i:\n if (p != 'W' and p != 'B' and p != 'G'):\n return '#Color'\n\n return '#Black&White'\n\nx = list(map(int, input().split()))\nf = []\nfor i in range(x[0]):\n q = list(input().split())\n f.append(q)\n\nprint(foto(f))\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\ns=input()\r\nfor _ in range(n-1):s+=input()\r\ns=(\"\".join(sorted(list(set(list(s)))))).replace(\" \",\"\")\r\nprint(\"#Black&White\" if s==\"BGW\" or s==\"GW\" or s==\"BG\" or s==\"BW\" or s==\"G\" or s==\"B\" or s==\"W\" else \"#Color\")\r\n", "n, m = map(int, input().split())\r\nc = []\r\nflag = 'NO'\r\n# 'C', 'M', 'Y', , 'G' or 'B''W'.\r\nk = 0\r\nfor _ in range(n):\r\n c = list(input().split())\r\n if c.count('C') or c.count('M') or c.count('Y'):\r\n k += 1\r\nprint(\"#Color\")if k else print(\"#Black&White\")\r\n", "import sys\r\nprint('#Color' if set('CMY')&set(sys.stdin.read())else '#Black&White')", "n, m = map(int, input().split())\nphoto = [input().split() for _ in range(n)]\ndef is_black_and_white(n, m, photo):\n colored_pixels = set(['C', 'M', 'Y'])\n for row in photo:\n for pixel in row:\n if pixel in colored_pixels:\n return False\n return True\n\nresult = \"#Black&White\" if is_black_and_white(n, m, photo) else \"#Color\"\nprint(result)\n", "a,b=map(int,input().split())\r\nh=0\r\nfor i in range(a):\r\n d=list(map(str,input().split()))\r\n if(\"Y\"in d or \"C\" in d or \"M\" in d):\r\n print(\"#Color\")\r\n h=1\r\n break\r\nif(h!=1):\r\n print(\"#Black&White\")", "import sys\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############ ---- Solution ---- ############ \r\nn,m = invr()\r\ncolored = False\r\nwhile n:\r\n n-=1\r\n row = input().rstrip()\r\n if('C'in row or 'Y' in row or 'M' in row):\r\n colored = True\r\n break\r\nif(colored):\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n ", "#W G B черно-белой\r\n#C M Y цветной\r\nn, m = map(int, input(). split())\r\nc = '#Black&White'\r\nwhile n > 0:\r\n a = list(map(str, input(). split()))\r\n for i in a:\r\n if i == 'C' or i == 'M' or i == 'Y':\r\n c = '#Color'\r\n break\r\n n -= 1\r\nprint(c)\r\n", "n,m = list(map(int, input().split()))\nver = 0\nfor i in range(n):\n color = list(map(str, input().split()))\n \n if any(chr != \"B\" and chr != \"W\" for chr in color):\n if all(c == \"B\" or c == \"W\" or c == \"G\" for c in color):\n ver = 0\n else:\n ver = 1\nif ver == 1:\n print(\"#Color\")\nelse:\n print(\"#Black&White\")", "n, m = tuple (map (int, input ().split (' ')))\r\nresult = '#Black&White'\r\nfor i in range (n):\r\n row = input ().split (' ')\r\n for unit in row:\r\n if unit not in 'WGB':\r\n result = '#Color'\r\nprint (result)", "x,y = map(int, input().split())\nb = 0\nfor i in range(x):\n a = list(map(str, input().split()))\n for j in range(len(a)):\n if a[j] == 'C' or a[j] == 'M' or a[j] == 'Y':\n b = 1\n else:\n if b == 1:\n b =1\n else:\n b = 0\nif b == 1:\n print('#Color')\nelse:\n print('#Black&White')\n\t \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\nColored = False\r\nfor i in range(n):\r\n a = input()\r\n if \"C\" in a or \"M\" in a or \"Y\" in a:\r\n Colored = True\r\nprint(\"#Color\") if Colored else print(\"#Black&White\")", "a,b=map(int,input().split())\r\nd=''\r\nfor i in range(a):\r\n l=input()\r\n d+=l\r\nif d.count('C')==0 and d.count('M')==0 and d.count('Y')==0:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')", "n, m = map(int, input().split())\n\nphoto = []\nfor i in range(n): \n photo.append(list(input().split()))\nfor i in range(n): \n for j in range(m): \n if photo[i][j] in [\"C\", \"M\", \"Y\"]: \n print(\"#Color\")\n exit()\nprint(\"#Black&White\")\n\n\n", "n,m=map(int,input().split())\r\nans = \"#Black&White\"\r\nfor n in range(n):\r\n l = *map(str,input().split()),\r\n if((\"C\" in l) or (\"M\" in l) or (\"Y\" in l)): ans = \"#Color\"\r\nprint(ans)", "s = input().split(\" \")\r\nn = int(s[0])\r\nm = int(s[1])\r\n\r\nfor i in range(n):\r\n s = input()\r\n if \"C\" in s or \"M\" in s or \"Y\" in s:\r\n print('#Color')\r\n break\r\nelse:\r\n print('#Black&White')\r\n", "a,b = map(int,input().split())\r\nmsv = []\r\nc = 0\r\nm = 0\r\ny = 0\r\nw = 0\r\ng = 0\r\nt = 0\r\nfor i in range(0,a):\r\n lst = list((input().split()))\r\n for j in lst:\r\n if j == 'C':\r\n c+=1\r\n if j == 'M':\r\n m+=1\r\n if j == 'Y':\r\n y+=1\r\n if j == 'W':\r\n w+=1\r\n if j == 'G':\r\n g+=1\r\n if j == 'B':\r\n t+=1\r\n\r\nif c>=1:\r\n print('#Color')\r\nelif m>=1:\r\n print('#Color')\r\nelif y>=1:\r\n print('#Color')\r\nelif w>=1:\r\n print('#Black&White')\r\nelif g>=1:\r\n print('#Black&White')\r\nelif t>=1:\r\n print('#Black&White')\r\n", "n,m = map(int,input().split())\r\ncount = 0\r\nfor i in range(n):\r\n m = list((input().split()))\r\n for i in m:\r\n if i == 'C' or i == 'M' or i == 'Y':\r\n count += 1\r\nif count > 0:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, m = map(int, input().split())\r\nc = 0\r\nfor x in range(n):\r\n a = list(map(str, input().split(' ')))\r\n for elem in a:\r\n if elem == 'C' or elem == 'M' or elem == 'Y':\r\n c += 1\r\n\r\nif c > 0:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n", "p,q = map(int, input().split())\r\nX = 0\r\nfor i in range(p):\r\n a = list(map(str, input().split()))\r\n if \"C\" in a or \"M\" in a or \"Y\" in a:\r\n X = 1\r\n else:\r\n continue\r\nif X == 1:\r\n print(\"#Color\")\r\nelif X == 0:\r\n print(\"#Black&White\")", "n, m = map(int, input().split())\r\nlst = []\r\nfor i in range(n):\r\n colors = input().split()\r\n for color in colors:\r\n if color not in lst:\r\n lst.append(color)\r\nif lst.count('W') + lst.count('B') + lst.count('G') < len(lst):\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n,m=list(map(int,input().split()))\r\nlist1=[]\r\na=\"\"\r\nfor i in range(n):\r\n s=input()\r\n list1.extend(s)\r\n\r\nlist1=list(set(list1))\r\nfor x in range(n):\r\n if \"C\" in list1 or \"Y\" in list1 or \"M\" in list1:\r\n a=\"COLOR\"\r\n\r\nif a==\"COLOR\":\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "a,b = map(int,input().split())\r\nv = []\r\nk = 0\r\ncol = [\"C\",\"M\",\"Y\"]\r\nfor buba in range(a):\r\n c = input().split()\r\n for i in c:\r\n v.append(i)\r\nfor i in v:\r\n if i in col:\r\n print(\"#Color\")\r\n k+=1\r\n break\r\nif k == 0:\r\n print(\"#Black&White\")", "from sys import stdin, stdout\r\nfrom re import search\r\ndef main():\r\n\t# stdin = open('input.txt', 'r')\r\n\tstdout.write(\"#Color\\n\" if search('C|M|Y', stdin.read()) else \"#Black&White\\n\")\r\nmain()", "n,m=map(int,input().split())\r\nb=''\r\nfor i in range(n):\r\n a=input()\r\n a=list(a)\r\n if a.count('C')>0 or a.count('M')>0 or a.count('Y')>0:\r\n b='NO'\r\nif b!='NO':\r\n print('#Black&White')\r\nelse:\r\n print('#Color')\r\n", "params = list(map(int, input().split(\" \")))\r\n\r\nlists = []\r\nfor i in range(params[0]):\r\n lists += input().split(\" \")\r\nif('C' in lists or 'M' in lists or 'Y' in lists):\r\n print('#Color')\r\nelse: print(\"#Black&White\")", "n,t=map(int,input().split())\r\ns=[]\r\nfor i in range(n):\r\n l=list(map(str,input().split()))\r\n s.extend(l)\r\nif ('C' in s) or ('M' in s) or ('Y' in s):print(\"#Color\")\r\nelse:print('#Black&White')\r\n\r\n", "n,m = map(int,input().split())\r\nfor _ in range(n):\r\n a = input()\r\n if 'C' in a or 'M' in a or 'Y' in a:\r\n print('#Color')\r\n exit()\r\nprint('#Black&White')", "n = [int(i) for i in input().split()]\r\nres = 0\r\nfor x in range(n[0]):\r\n l = set(input())\r\n if \"C\" in l or \"M\" in l or \"Y\" in l:\r\n res = res + 1\r\n\r\nif res > 0:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "def colour_determine(n,m,pixel):\r\n for r in range(n):\r\n for c in range(m):\r\n if pixel[r][c] == 'C' or pixel[r][c] == 'M' or pixel[r][c] == 'Y':\r\n return '#Color'\r\n return'#Black&White'\r\nn,m=map(int,input().split())\r\npixel=[]\r\nfor i in range(n):\r\n pixel.append(list(input().split()))\r\nprint(colour_determine(n,m,pixel))", "a,b=map(int,input().split())\r\ncount=0\r\nfor i in range(a):\r\n lst=list(input())\r\n if 'C' in lst or 'M' in lst or 'Y' in lst:\r\n count+=1\r\n break\r\n else:\r\n continue\r\n\r\nif count>0:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "r,c=map(int,input().split())\r\ntrouve=True\r\ni=0\r\nfor i in range(r):\r\n l = input().split()\r\n #print(l)\r\n for i in l:\r\n if i not in ['W','B','G']:\r\n trouve = False\r\n break\r\nprint(\"#Black&White\") if trouve else print(\"#Color\")\r\n", "n,m=map(int,input().split())\r\ncolour=False\r\nfor i in range(n):\r\n l=input()\r\n if not colour:\r\n if \"C\" in l or \"M\" in l or \"Y\" in l:\r\n colour=True\r\nif colour:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n ", "#বিসমিল্লাহির রাহমানির রাহিম\r\n#بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ\r\n#Bismillahir Rahmanir Rahim\r\n#PROBLEM :A. Brain's Photos\r\nn,m=map(int,input().split())\r\nk=[]\r\nfor i in range(n):\r\n k+=list(map(str,input().split()))\r\nif any(i in [\"C\",\"M\",\"Y\"] for i in set(k)):\r\n print('#Color')\r\nelse:\r\n print(\"#Black&White\")", "a,b=map(int,input().split())\nfor i in range(a):\n c=input().split()\n if \"C\" in c or 'M' in c or 'Y' in c:\n print(\"#Color\")\n quit()\nprint(\"#Black&White\")", "t = input()\r\nlist1 = []\r\nfor i in range(int(t[0])):\r\n inp = input().split()\r\n for j in range(len(inp)):\r\n list1.append(inp[j])\r\nif \"C\" in list1 or \"M\" in list1 or \"Y\" in list1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "v=0\r\na,b=map(int,input().split())\r\nfor i in range(1,a+1):\r\n c=input()\r\n d=c.count('C')\r\n v=c.count('M')\r\n m=c.count('Y')\r\n if d>0 or v>0 or m>0:\r\n print('#Color')\r\n v=1\r\n break\r\nif v==0:\r\n print('#Black&White')\r\n", "photo = [int(num) for num in input().split()]\nl = photo[0]\nb = photo[1]\n\nbw = 0\ncolor = 0\n\nfor i in range(l):\n row = [num for num in input().split()]\n for pixel in row:\n if pixel == 'W' or pixel == 'B' or pixel == 'G':\n bw += 1\n else:\n color += 1\n\n\nif color > 0:\n print('#Color')\nelse:\n print('#Black&White')", "size = [int(i) for i in input().split()]\r\ncolor = [input().split() for _ in range(size[0])]\r\nfor i in color:\r\n if 'C' in i or 'M' in i or 'Y' in i:\r\n print('#Color')\r\n break\r\nelse:\r\n print('#Black&White')", "# Author : //- kibrom Hailu -\\\\\r\n\r\nfrom sys import stdin,stdout\r\nfrom collections import Counter,defaultdict , deque \r\nfrom bisect import bisect , bisect_left ,bisect_right \r\nfrom itertools import accumulate \r\nfrom heapq import heapify , heappop , heappush , heappushpop , heapreplace\r\n\r\ndef I(): return int(stdin.readline())\r\ndef II(): return map(int, stdin.readline().split())\r\ndef IL(): return list(map(int, stdin.readline().split()))\r\ndef SIL(): return sorted(map(int, stdin.readline().split()))\r\n\r\n\r\n\r\ndef solve():\r\n \r\n # write your code here \r\n n,m = II()\r\n view = dict()\r\n for _ in range(n):\r\n arr = input().split()\r\n for i in arr:\r\n view[i] = 1 \r\n \r\n\r\n\r\n b = view.get('B',0)\r\n w = view.get('W',0)\r\n g = view.get('G',0)\r\n\r\n if b+w+g == len(view):\r\n print('#Black&White')\r\n else:\r\n print('#Color')\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\nsolve()\r\n", "# LUOGU_RID: 113688352\nn=int(input().split()[0])\r\na=''\r\nfor i in range(n):\r\n a+=input().replace(' ','')\r\nif 'C' in a or 'M' in a or 'Y' in a:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "'''\r\nName: Brain's Photos\r\nLink: https://codeforces.com/problemset/problem/707/A\r\nCategories: matrix, string, for in for\r\n'''\r\n\r\n# n and m - matrix length\r\nn, m = map(int, input().split())\r\n\r\narray = []\r\n# creating matrix using n and m\r\nfor i in range(n):\r\n array.append(list(map(str, input().split()))[:m])\r\n\r\ncolor = \"#Black&White\"\r\n# checking every element of matrix\r\nfor i in range(n):\r\n for j in range(m):\r\n if array[i][j] == \"C\" or array[i][j] == \"M\" or array[i][j] == \"Y\":\r\n color = \"#Color\"\r\n\r\nprint(color)\r\n", "n, m = list(map(int, input().split()))\r\nz = 0\r\na=[list(input().split()) for i in range(n)]\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] == 'C'or a[i][j] == 'M'or a[i][j] == 'Y':\r\n z = 1\r\nif z == 1:\r\n print(\"#Color\")\r\nelse:\r\n print('#Black&White')", "m,n = [int(i) for i in input().split()]\na = set()\nfor i in range(m):\n for j in input().split():\n a.add(j)\nb = ['C','M','Y']\nflag=0\nfor i in b:\n if i in a:\n flag=1\nif flag==1:\n print(\"#Color\")\nelse:\n print(\"#Black&White\")\n ", "l=[]\r\nz,y=map(int,input().split())\r\nfor i in range(z):\r\n x=map(str,input().split())\r\n for j in x:\r\n l.append(j)\r\n\r\nif \"C\" in l or \"M\" in l or \"Y\" in l:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, m = map(int, input().split())\r\n\r\ni = 0\r\n\r\nnums = []\r\nwhile (i < n):\r\n a = input().split()\r\n nums.append(a)\r\n i += 1\r\n# print(nums)\r\n\r\n\r\n\r\nnums1 = []\r\n\r\nk = 0\r\nwhile (k < n):\r\n if \"C\" in nums[k] or \"M\" in nums[k] or \"Y\" in nums[k]:\r\n nums1.append(\"Color\")\r\n else:\r\n nums1.append(\"BlackandWhite\")\r\n k += 1\r\n \r\nif \"Color\" in nums1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "[n, m] = list(map(int, input().split()))\r\npixls = list()\r\nfor i in range(n):\r\n pixls += input().split()\r\nfor i in ['M', 'C', 'Y']:\r\n if i in pixls:\r\n print('#Color')\r\n break\r\nelse:\r\n print('#Black&White')", "n,m=map(int,input().split())\r\nmatrix=[]\r\ncoloured=False\r\nfor i in range(n):\r\n row=input().split()\r\n if 'M' in row or 'C' in row or 'Y' in row:\r\n coloured=True\r\nif coloured:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n ", "n, m = map(int, input().split())\r\nmat = []\r\nfor i in range(n):\r\n mat.append(input().split())\r\n\r\nc_or = True\r\nb_w = \"WBG\"\r\n\r\nfor x in mat:\r\n b = False\r\n for s in x:\r\n if s in b_w:\r\n continue\r\n else:\r\n b = True\r\n if b == True:\r\n c_or = False\r\n break\r\n\r\nif c_or:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n", "n,m = [i for i in (map(int,input().split()))]\r\nout = \"#Black&White\"\r\nfor i in range(n):\r\n s = input()\r\n if \"C\" in s or \"Y\" in s or \"M\" in s:\r\n out = \"#Color\"\r\n break\r\nprint(out)", "n,m=map(int,input().split())\r\nk=0\r\nfor i in range(n):\r\n s=input()\r\n if 'C' in s or 'M' in s or 'Y' in s:\r\n k=1\r\nif(k==1):\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n,m=map(int,input().split())\r\nflag=True\r\nfor i in range(n):\r\n a=list(map(str,input().split()))\r\n if 'C' in a or 'M' in a or 'Y' in a:\r\n flag=False\r\nif flag:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')\r\n", "q=input()\r\nq=q.split()\r\nn=int(q[0])\r\ns=n\r\nm=int(q[1])\r\n\r\nt=0\r\nanswer=0\r\nwhile n>0:\r\n n-=1\r\n w=input()\r\n w=w.split()\r\n for i in range(m):\r\n if w[i]=='W' or w[i]=='B' or w[i]=='G':\r\n t+=1\r\nif t==m*s:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "n, m = map(int, input().split())\r\na = '/n'.join(input() for i in range(n))\r\na = set(a)\r\nx = set(\"CMY\")\r\nprint(\"#Color\" if a & x else \"#Black&White\")\r\n", "m,n = map(int, input().split())\r\na = 0\r\nb = 0\r\nfor i in range(m):\r\n s = list(map(str, input().split()))\r\n l = len(s)\r\n for i in range(l):\r\n if s[i] == 'C' or s[i] == 'M' or s[i] == 'Y' :\r\n a = a + 1\r\n else :\r\n b = b + 1\r\n\r\nif a >= 1 :\r\n ans = \"#Color\"\r\nelse:\r\n ans = \"#Black&White\"\r\nprint(ans)", "n,m=map(int, input().split())\r\nis_colored=False\r\nfor i in range(n):\r\n colors=input().split()\r\n if 'C' in colors or 'M' in colors or 'Y' in colors:\r\n is_colored=True\r\n break \r\nif is_colored:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n,m = map(int, input().split())\r\nf = 0\r\nfor i in range(0,n):\r\n l = input().split()\r\n if 'C' in l or 'M' in l or 'Y' in l:\r\n f = 1\r\n\r\nif f == 1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, c = input().split()\r\nmatrix = [list(map(str, input().split())) for _ in range(int(n))]\r\ncolors = []\r\nfor i in range(int(n)):\r\n for j in range(int(c)):\r\n colors.append(matrix[i][j])\r\n\r\n\r\nif 'M' in colors or 'Y' in colors or 'C' in colors:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "n,m=list(map(int,input().split()))\r\nfor i in range(n):\r\n color=list(map(str,input().split()))\r\n if any(i in \"CMY\" for i in color):\r\n print(\"#Color\")\r\n break\r\nelse:\r\n print(\"#Black&White\")", "var = input().split(\" \")\r\nmatrix = []\r\nfor i in range(int(var[0])):\r\n row = input().split(\" \")\r\n for j in row:\r\n matrix.append(j)\r\nif (\"C\" in matrix) or (\"M\" in matrix) or (\"Y\" in matrix):\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n,m=[int(j) for j in input().split()]\r\na = [[(j) for j in input().split()] for i in range(n)]\r\nb=0\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] not in 'B G W' and a[i][j] in 'C M Y':\r\n b=1\r\n break\r\n if b==1:\r\n break\r\nif b==1:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n\r\n", "import sys\r\nsys.setrecursionlimit(100000000)\r\ninput=lambda:sys.stdin.readline().strip()\r\nwrite=lambda x:sys.stdout.write(str(x)+'\\n')\r\n\r\n# from random import randint\r\n# from copy import deepcopy\r\n# from collections import deque\r\n# from heapq import heapify,heappush,heappop\r\n# from bisect import bisect_left,bisect,insort\r\n# from math import inf,sqrt,gcd,ceil,floor,log,log2,log10\r\n# from functools import cmp_to_key\r\n\r\nn,m=map(int,input().split())\r\ng=[]\r\nfor i in range(n):\r\n g.append(list(input().split()))\r\nflag=False\r\nfor i in range(n):\r\n for j in range(m):\r\n if g[i][j] in 'CMY':\r\n flag=True\r\n break\r\n if flag:\r\n break\r\nif flag:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "n,m=map(int,input().split())\r\nk=[]\r\ni=j=0\r\nfor i in range(n):\r\n l=input().split()\r\n k+=l\r\nif 'C' in k or 'M' in k or 'Y' in k:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, m = input().split()\r\nn = int(n)\r\nm = int(m)\r\nok = True\r\ncol = []\r\nfor i in range(0, n):\r\n x = input()\r\n col = x.split()\r\n for j in range(0, m):\r\n if col[j] != 'B' and col[j] != 'W' and col[j] != 'G':\r\n ok = False\r\n break\r\nif ok == False: print('#Color', end = '')\r\nelse: print('#Black&White', end = '')", "rows, columns = map(int, input().split())\n\nis_colorful = False\nfor _ in range(rows):\n pixel_colors = input().split()\n for pixel_color in pixel_colors:\n if pixel_color != 'B' and pixel_color != 'W' and pixel_color != 'G':\n is_colorful = True\n break\n\nprint('#Color' if is_colorful else '#Black&White')\n", "import sys\r\n\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\na, b = map(int, input().split())\r\nans = list()\r\nfor i in range(a):\r\n l = list(map(str, input().split()))\r\n ans += l\r\nif \"C\" in ans or \"M\" in ans or \"Y\" in ans:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "r,c=map(int,input().split())\r\nco=0\r\nfor i in range(r):\r\n l=list(input().split())\r\n for j in l:\r\n if(j=='C' or j=='M' or j=='Y'):\r\n co+=1\r\nif(co==0):\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "a,b=map(int,input().split())\r\nl=\"\"\r\nfor i in range(a):\r\n r=input()\r\n l+=r.replace(\" \", \"\")\r\n \r\n \r\nif(set(l) & set('CMY')):\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n ", "#B나 G나 W만 있으면 blackandwhite / 아니면 color 출력하기\r\nn,m=map(int,input().split())\r\nc=0\r\nm=0\r\ny=0\r\nw=0\r\ng=0\r\nb=0\r\nfor i in range(n):\r\n x=input()\r\n c=c+x.count('C')\r\n m=m+x.count('M')\r\n y=y+x.count('Y')\r\n w=w+x.count('W')\r\n g=w+x.count('G')\r\n b=b+x.count('B')\r\nif c==0 and m==0 and y==0:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')\r\n", "def is_black_and_white(photo):\r\n colors = {'C', 'M', 'Y', 'W', 'G', 'B'}\r\n for row in photo:\r\n for pixel in row:\r\n if pixel in colors - {'W', 'G', 'B'}:\r\n return False\r\n return True\r\n\r\nif __name__ == \"__main__\":\r\n n, m = map(int, input().split())\r\n photo = [input().split() for _ in range(n)]\r\n \r\n if is_black_and_white(photo):\r\n print(\"#Black&White\")\r\n else:\r\n print(\"#Color\")\r\n", "# Author: José Rodolfo (jric2002)\r\nn, m = [int(e) for e in input().split(\" \")]\r\nis_blackandwhite = True\r\npxs = []\r\nwhile (n):\r\n pxs.extend(input().split(\" \"))\r\n n -= 1\r\nfor p in pxs:\r\n if (p != 'B' and p != 'W' and p != 'G'):\r\n is_blackandwhite = False\r\nif (is_blackandwhite):\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "# LUOGU_RID: 111358419\npic_size = input().split()\r\npic_size = list(map(int, pic_size))\r\npic = []\r\nif_colored = False\r\nfor i in range(pic_size[0]):\r\n pic_color = input().split()\r\n pic.append(pic_color)\r\nfor i in range(pic_size[0]):\r\n for j in range(pic_size[1]):\r\n if pic[i][j] == 'C' or pic[i][j] == 'M' or pic[i][j] == 'Y':\r\n if_colored = True\r\n break\r\n if if_colored == True:\r\n break\r\nif if_colored == True:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "a,b=map(int, input().split())\r\nn=0\r\nfor i in range(a):\r\n s=input().split()\r\n for j in range(b):\r\n if s[j]=='C' or s[j]=='M' or s[j]=='Y':\r\n n=100\r\n break\r\nif n==100:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n \r\n", "[rows, columns]=map(int, input().split())\r\nlists = [input().split() for i in range(rows)]\r\ncolors = [\"C\", \"Y\", \"M\"]\r\nblack_white = [\"B\", \"W\", \"G\"]\r\nans = \"#Black&White\"\r\nfor line in lists:\r\n for ch in colors:\r\n if ch in line:\r\n ans = \"#Color\"\r\nprint (ans)", "n, m = map(int, input().split())\r\ncol = [0, 0, 0]\r\nbw = [0, 0, 0]\r\nfor i in range(n):\r\n a = list(map(str, input().split()))\r\n for j in range(len(a)):\r\n if a[j] == \"C\":\r\n col[0] += 1\r\n if a[j] == \"M\":\r\n col[1] += 1\r\n if a[j] == \"Y\":\r\n col[2] += 1\r\n if a[j] == \"W\":\r\n bw[0] += 1\r\n if a[j] == \"G\":\r\n bw[1] += 1\r\n if a[j] == \"B\":\r\n bw[2] += 1\r\nif sum(col) == 0:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n", "r,c = map(int,input().split())\r\nmat = []\r\nfor i in range(r):\r\n m = list(input().split())\r\n mat.append(m)\r\n\r\nflag = True\r\nfor P in mat:\r\n for p in P:\r\n if p in ['C','M','Y']:\r\n flag = False\r\n break\r\nif flag:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "nm = list(map(int, input().split()))\r\nn = nm[0]; m = nm[1]\r\ncol = []\r\nfor _ in range(n):\r\n val = input().split()\r\n col.append(val)\r\ncnt = 0\r\nfor i in range(n):\r\n for j in range(m):\r\n if col[i][j] == 'C' or col[i][j] == 'Y' or col[i][j] == 'M':\r\n cnt += 1\r\nif cnt == 0:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')", "r,c=map(int,input().split())\r\nt=[]\r\na=0\r\nfor i in range(r):\r\n l=list(map(str,input().split()))\r\n if(\"C\" in l or \"Y\" in l or \"M\" in l):\r\n a=1\r\nif(a==0):\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n ", "n, m = map(int, input().split())\r\nflag = 0\r\n\r\nfor i in range(n):\r\n temp = input()\r\n if 'C' in temp or 'M' in temp or 'Y' in temp:\r\n flag = 1\r\n break\r\n\r\nif flag:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n,m = map(int,(input().split()))\r\nfor i in range(n):\r\n a = list(input().split())\r\n if \"C\" in a or \"Y\" in a or \"M\" in a:\r\n print(\"#Color\")\r\n break\r\nelse:\r\n print(\"#Black&White\")", "m, n = map(int, input().split())\r\nr = set()\r\nfor i in range(m):\r\n g = set(input().split())\r\n r = r|g\r\nc = list(r)\r\nfor i in range(len(c)):\r\n if c[i] in 'CMY':\r\n print('#Color')\r\n exit()\r\nprint(\"#Black&White\")", "from sys import stdin\r\n\r\n\r\nlgn, col = list(map(int, stdin.readline().strip().split()))\r\n\r\ncolor = False\r\nfor loop in range(lgn):\r\n phrase = stdin.readline().strip()\r\n if \"C\" in phrase or \"M\" in phrase or \"Y\" in phrase:\r\n color = True\r\n\r\nif color:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "x, y = map(int, input().split())\r\na=''\r\nc=0\r\nfor i in range(x):\r\n b=input()\r\n a+=b\r\n \r\nif a.find('C')==-1 and a.find('M')==-1 and a.find('Y')==-1:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')", "n,m=map(int,input().split())\r\nbli=('B','W','G')\r\nnim=0\r\nfor i in range(n):\r\n s=input()\r\n lst=s.split(\" \")\r\n for k in lst:\r\n if k not in bli:\r\n nim=1 \r\n break\r\nprint('#Black&White' if nim==0 else '#Color')\r\n", "n,m=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n l.extend(list(input().split()))\r\nif 'C'in l or 'M' in l or 'Y' in l:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "n, m = map(int, input().split())\r\nis_colored = False\r\nfor i in range(n):\r\n row = input().split()\r\n for j in range(m):\r\n if row[j] in ['C', 'M', 'Y']:\r\n is_colored = True\r\nif is_colored:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "row, col = map(int, input().split())\r\nst = set()\r\nfor i in range(row):\r\n for n in input().split(): st.add(n)\r\nprint('#Color' if len(st.intersection(set('CMY'.strip()))) else '#Black&White')", "a,b=map(int,input().split())\r\nfor i in range(a):\r\n p=set(input().split())\r\n if 'C'in p or 'M' in p or 'Y' in p:\r\n print('#Color')\r\n exit()\r\nprint('#Black&White')\r\n", "li=list(map(int,input().strip().split()))\r\nr=li[0]\r\nc=li[1]\r\nc=0\r\nfor i in range(r):\r\n arr=list(map(str,input().strip().split()))\r\n if \"C\" in arr or \"M\" in arr or \"Y\" in arr:\r\n print(\"#Color\")\r\n c=1\r\n break\r\nif c==0:\r\n print(\"#Black&White\")", "n,m = map(int,input().split())\r\nst = \"\"\r\nfor i in range(n):\r\n s = input()\r\n st+=s\r\nif 'C' in st or 'M' in st or 'Y' in st:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n", "flag = True\r\nlents = list(map(int,input().split())) \r\nli = []\r\nfor i in range(lents[0]) :\r\n li.append(list(input()))\r\n if flag :\r\n if \"C\" in li[i] or \"M\" in li[i] or \"Y\" in li[i] : \r\n print(\"#Color\")\r\n flag = False\r\nif flag : print(\"#Black&White\")", "n,m=map(int,input().split())\r\nh=\"\"\r\nfor i in range(n):\r\n h+=input()\r\nif \"C\" in h or \"M\" in h or \"Y\" in h:\r\n print(\"#Color\")\r\n exit()\r\nprint(\"#Black&White\")", "import sys\r\n\r\nn,m = map(int, input().split())\r\n\r\ncolors = ['C','M','Y']\r\n\r\nphoto = 0\r\nyes = 0\r\nfor _ in range(n):\r\n \r\n temp = list(map(str, input().split()))\r\n \r\n for x in temp:\r\n if x in colors: photo = 1; yes = 1; break\r\n\r\n if yes: break; \r\n\r\nif photo == 0: print(\"#Black&White\")\r\nelse: print(\"#Color\")", "n,m = map(int,input().split())\r\nsign = False\r\nfor x in range(n):\r\n for i in input().split():\r\n if i == 'C' or i == 'M' or i == 'Y':\r\n print('#Color')\r\n sign = True\r\n break\r\n if sign:\r\n break\r\nif not(sign):\r\n print('#Black&White')", "x,y=map(int,input().split())\r\ns=''\r\nfor i in range(x):\r\n s+=input()\r\nif not 'C' in s and not 'M' in s and not 'Y' in s:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "rows, columns = map(int, input().split())\r\nmylist = []\r\nfor i in range(rows):\r\n colors = list(input().split())\r\n mylist.extend(colors)\r\nfor r in mylist:\r\n if r == \"C\" or r == \"M\" or r == \"Y\":\r\n output = \"#Color\"\r\n break\r\n else:\r\n output = \"#Black&White\"\r\nprint(output)\r\n", "i,j=map(int,input().split())\r\nr=0;f=0\r\nff=[]\r\nfor mm in range(i):\r\n t=input().split()\r\n ff.append(t)\r\nfor ii in range(i):\r\n for jj in range(j):\r\n if ff[ii][jj] in 'WBG':\r\n r+=1\r\n else:\r\n f+=1\r\nif r>f and f==0:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "numbers = input().split(\" \")\r\ncolor = 0\r\nfor i in range(int(numbers[0])):\r\n s = input().split(\" \")\r\n if 'C' in s or 'Y' in s or 'M' in s:\r\n color += 1\r\nif color > 0:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, m = map(int, input().split())\r\nf = False\r\nfor i in range(n):\r\n s = input()\r\n if 'C' in s or 'M' in s or 'Y' in s:\r\n f = True\r\nif f:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "n, m = map(int, input().split())\r\nb = []\r\nfor x in range(n):\r\n b += list(input().split())\r\nif('C' in b or 'M' in b or 'Y' in b):\r\n print(\"#Color\")\r\n exit()\r\nprint(\"#Black&White\")", "n, m = map(int, input().split())\r\nmatrix = [input().split() for _ in range(n)]\r\nres = '#Black&White'\r\n\r\nfor r in range(n):\r\n for c in range(m):\r\n if matrix[r][c] in 'CMY':\r\n res = '#Color'\r\n\r\nprint(res)", "a, b = map(int, input().split())\r\nt = '#Black&White'\r\nfor i in range(a):\r\n n = [str(i) for i in input().split()]\r\n for i in range(len(n)):\r\n if n[i] == 'Y' or n[i] == 'M' or n[i] == 'C':\r\n t = '#Color'\r\n break\r\nprint(t)\r\n", "n,m=map(int,input().split())\r\na=[['']*m for s in range(n)]\r\nfor k in range(n):\r\n a[k]=input().split()\r\nfor katar in a:\r\n for elem in katar:\r\n if (elem=='C' or elem=='Y' or elem=='M'):\r\n print('#Color')\r\n quit()\r\nelse:\r\n print('#Black&White')\r\n", "rows, columns = [int(x) for x in input().split()]\r\nnocolor_list = [\"W\",\"B\",\"G\"]\r\nallow = False\r\nfor i in range(rows):\r\n letters = [input().split()]\r\n for j in range(columns):\r\n letter = letters[0][j]\r\n if letter not in nocolor_list:\r\n allow = True\r\n break\r\nif allow == True:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "a,b=map(int,input().split())\r\nc=[]\r\nf=0\r\nfor i in range(a):\r\n c.append(input().split(\" \"))\r\nfor j in c:\r\n for i in range(len(j)):\r\n if j[i]=='C' or j[i]=='M' or j[i]=='Y':\r\n f=1\r\nif f==1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, m = (int(i) for i in input().split())\nres = True\nfor _ in range(n):\n s = input()\n res &= all(c in [\"B\", \"G\", \"W\", \" \"] for c in s)\nres = \"#Black&White\" if res else \"#Color\"\nprint(res)\n", "def colored(s):\r\n return s.count('C') or s.count('M') or s.count('Y')\r\n\r\n\r\nn, _ = map(int, input().split())\r\ns = ''\r\nfor _ in range(n):\r\n s += input()\r\nprint('#Color' if colored(s) else '#Black&White')\r\n", "def Brains_Photos(n,m):\r\n \r\n flag = 0\r\n for i in range(n):\r\n k = list(input().split())\r\n for j in range(len(k)):\r\n \r\n if k[j] == 'C' or k[j] == 'M' or k[j] == 'Y':\r\n flag = 1 \r\n if flag == 1:\r\n return '#Color'\r\n return '#Black&White'\r\n \r\n\r\nn,m = map(int, input().split())\r\nprint(Brains_Photos(n,m))\r\n ", "a=set()\r\nn,m=map(int,input().split())\r\nfor _ in range(n):\r\n a.update(set(input().split()))\r\nif a.issubset({'B','W','G'}):\r\n print('#Black&White')\r\nelse:print('#Color')\r\n", "n,m=map(int,input().split())\r\nok=False\r\nfor i in range(n):\r\n if set(\"CMY\")&set(input()) : ok=True\r\nprint(\"#Color\" if ok else \"#Black&White\")\r\n\r\n", "\ndef is_black_and_white(matrix):\n colors = set(['C', 'M', 'Y'])\n for row in matrix:\n for pixel in row:\n if pixel in colors:\n return \"#Color\"\n return \"#Black&White\"\nn,m = map(int,input().split())\nmatrix = []\nfor i in range(n):\n matrix.append(input().split())\n\nprint(is_black_and_white(matrix))\n", "n,m=map(int,input().split())\r\nl=[]\r\nans=\"#Black&White\"\r\nfor i in range(n):\r\n s=list(input().split())\r\n for k in s:\r\n if k==\"C\" or k==\"M\" or k==\"Y\":\r\n ans=\"#Color\"\r\nprint(ans)\r\n ", "testcases=1\n\nfor t in range (testcases):\n\tstring=input()\n\tsn,sm=string.split()\n\tn=int(sn)\n\tm=int(sm)\n\tmatrix=[]\n\tfor i in range(n):\n\t\tarr=[]\n\t\tstring1=input()\n\t\tarr=string1.split()\n\t\tmatrix.append(arr)\n\n\tcolor=0\n\tfor i in range(n):\n\t\tfor j in range(m):\n\t\t\tif matrix[i][j]=='C' or matrix[i][j]=='Y' or matrix[i][j]=='M':\n\t\t\t\tcolor+=1\n\t\tif color >0:\n\t\t\tbreak\n\n\tif color >0:\n\t\tprint(\"#Color\")\n\telse:\n\t\tprint(\"#Black&White\")\n\n", "n, b = map(int, input().split())\r\nappend_ = []\r\nok = 0\r\n\r\nfor i in range(n):\r\n a = input()\r\n append_.append(a)\r\n\r\nfor i in append_:\r\n if \"C\" in i or \"M\" in i or \"Y\" in i: # Check if the pixel color contains C, M, or Y\r\n ok += 1\r\n\r\nif ok > 0:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n, m = map(int, input().split())\r\n\r\ncolored = False\r\n\r\nfor i in range(n):\r\n row = input().split()\r\n for pixel in row:\r\n if pixel in ['C', 'M', 'Y']:\r\n colored = True\r\n break\r\n\r\nif colored:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n,m=[int(x) for x in input().split()]\ncolours=[\"C\",\"M\",\"Y\"]\nbw=[\"B\",\"W\",\"G\"]\na=[]\nfor i in range(n):\n l=[x for x in input().split()]\n a.extend(l)\nfor i in range(len(a)):\n if a[i] in colours:\n print(\"#Color\")\n break\n elif i==len(a)-1:\n print(\"#Black&White\")", "a, b = map(int, input().split(' '))\r\nq = \"#Black&White\"\r\nfor i in range(a):\r\n d = list(input().split(' '))\r\n if 'C' in d or 'M' in d or 'Y' in d:\r\n q = \"#Color\"\r\nprint(q)\r\n \r\n", "n,m=list(map(int,input().split()))\r\narr=[]\r\ncolo=[\"C\",\"Y\",\"M\"]\r\nx=0\r\nfor i in range(n):\r\n arr.append(input().split())\r\n \r\nfor i in arr:\r\n for j in i :\r\n if j in colo:\r\n print(\"#Color\")\r\n x+=1\r\n break\r\n if x==1:\r\n break\r\n \r\n \r\nelse:\r\n print(\"#Black&White\")\r\n ", "n,m=map(int,input().split())\r\nblack=['W','B','G']\r\ncolor=['C','M','Y']\r\nc=0\r\nfor _ in range(n):\r\n l1=list(input())\r\n for i in l1:\r\n if i in color:\r\n c=1\r\n break\r\nif(c==1):\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, m = map(int, input().split())\r\nc = 0\r\nfor i in range(n):\r\n l = input().split()\r\n for j in l:\r\n if j in \"CMY\":\r\n c += 1\r\nif c == 0:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "'''\r\nProblem: https://codeforces.com/problemset/problem/707/A\r\nDifficulty: 800\r\nTries: \r\nTime: \r\n'''\r\n\r\n(n, _) = [int(x) for x in input().split()]\r\n\r\ndef f():\r\n for i in range(n):\r\n line = input().split()\r\n for letter in line:\r\n if letter in ['C', 'M', 'Y']:\r\n return False\r\n return True\r\n\r\nprint('#Black&White' if f() else '#Color')\r\n", "\r\n# A. Brain's Photos\r\nn, m = map(int, input().split())\r\nlst = list()\r\nres = \"\"\r\nfor x in range(0, n):\r\n lst.append(list(map(str, input().split())))\r\nlst = sum(lst, [])\r\n\r\nfor x in lst:\r\n if x == 'C' or x == 'M' or x == 'Y':\r\n res = \"#Color\"\r\n\r\nif res != \"#Color\":\r\n res = \"#Black&White\"\r\nprint(res)\r\n", "n,m=map(int,input().split())\r\np=[[\"\"]*m]*n\r\nt=\"\"\r\nfor i in range (n):\r\n p[i]=input().split()\r\n\r\nfor i in range(n):\r\n for j in range (m):\r\n if p[i][j]== \"C\" or p[i][j] ==\"M\" or p[i][j] == \"Y\":\r\n t=\"#Color\"\r\n break\r\n\r\n\r\nif t ==\"\" :\r\n print('#Black&White')\r\n\r\nelse :\r\n print(\"#Color\")", "entered_list=input().split()\r\nnum_list=list(map(int,entered_list))\r\nd=[]\r\nfor i in range(num_list[0]):\r\n test_list=input().split()\r\n new_list=list(test_list)\r\n d.append(new_list)\r\n#print(d)\r\nresult=0\r\nfor i in d:\r\n for j in i:\r\n if 'C' in j or 'M' in j or 'Y' in j:\r\n result+=1\r\nif result==0:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')", "x = list(map(int, input().split()))\r\n\r\n\r\nfor i in range(x[0]):\r\n pix = input().split()\r\n for p in pix:\r\n if p != 'W' and p != 'G' and p != 'B':\r\n print('#Color')\r\n exit()\r\n \r\nprint('#Black&White')", "import sys\r\ninput = sys.stdin.readline\r\noutput = sys.stdout.write\r\n\r\n\r\ndef main():\r\n row, col = map(int, input().rstrip().split())\r\n state = True\r\n set_ = {'C', 'M', 'Y'}\r\n for i in range(row):\r\n col_ = input().rstrip().split()\r\n for char_ in col_:\r\n if char_ in set_:\r\n state = False\r\n break\r\n if state is False:\r\n break\r\n if state:\r\n output('#Black&White')\r\n else:\r\n output('#Color')\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n,m=input().split()\r\nn=int(n)\r\nm=int(m)\r\na=[]\r\nc=0\r\nfor i in range(n):\r\n b=input().split()\r\n a.append(b)\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] in ['C','M','Y']:\r\n c=1\r\n break\r\nif c==1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "import sys\r\norder = sys.stdin.readlines()\r\nflag =0\r\nfor i in order:\r\n if i== order[0]:\r\n continue\r\n else:\r\n color= i.strip()\r\n clr = color.replace(\" \", \"\")\r\n for j in clr:\r\n if(j=='B' or j=='W' or j=='G'):\r\n continue\r\n else:\r\n flag=1\r\n break\r\nif flag==0:\r\n print(\"#Black&White\")\r\nelse: print(\"#Color\")", "import sys\r\ninput = sys.stdin.readline\r\n\r\ndef main() -> None :\r\n pixelColorMatrix:list[list[str]] = []\r\n for _ in range(list(map(int, input().split()))[0]) :\r\n pixelColorMatrix.append(input().rstrip().split())\r\n\r\n isBlackWhite:bool = True\r\n for pixelColorRow in pixelColorMatrix :\r\n for pixelColor in pixelColorRow :\r\n if pixelColor in [\"C\", \"M\", \"Y\"] :\r\n isBlackWhite = False\r\n break\r\n if not isBlackWhite :\r\n break\r\n \r\n print(\"#Black&White\" if isBlackWhite else \"#Color\")\r\n\r\nmain()", "class Solution():\n \n def brains_photos():\n row, column = map(int, input().split())\n colors = [\"Y\", \"C\", \"M\"]\n for i in range(row):\n color = input().split()\n if 'Y' in color or 'C' in color or 'M' in color:\n return '#Color'\n return '#Black&White'\n\n\nif __name__ == '__main__':\n print(Solution.brains_photos())", "# https://codeforces.com/problemset/problem/707/A\r\n\r\nc = {'C', 'M', 'Y'}\r\n\r\nx, _ = map(int, input().split())\r\nres = ''\r\nfor _ in range(x):\r\n seq = tuple(input().split())\r\n for it in seq:\r\n if it in c:\r\n res = '#Color'\r\n break\r\n if res:\r\n break\r\nif not res:\r\n res = '#Black&White'\r\nprint(res)", "n = int(input()[0])\r\n\r\n_bool = False\r\nfor i in range(n):\r\n x = input().strip().split(' ')\r\n if 'C' in x or 'M' in x or 'Y' in x:\r\n _bool=True\r\n \r\nif _bool:\r\n print(\"#Color\")\r\nelse: \r\n print(\"#Black&White\")\r\n", "a, b = map(int, input().split())\r\nm, counter1, counter2 = [], 0, 0\r\nx = ['W', 'G', 'B']\r\nfor i in range(a):\r\n s = list(input().split())\r\n m.append(s)\r\nfor i in m:\r\n for j in i:\r\n if j in x:\r\n counter1 += 1\r\n else:\r\n counter2 += 1\r\nif counter1 > 0 and counter2 == 0:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "import sys\r\nfrom collections import Counter\r\n\r\nc = Counter(sys.stdin.read())\r\nif c['C'] or c['M'] or c['Y']:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "b=list(map(int,input().split()))\r\na=[]\r\nfor x in range(0,b[0]):\r\n c=input().lower().split()\r\n a.extend(c)\r\nif 'c' in a or 'm' in a or 'y' in a :\r\n print(\"#Color\")\r\n exit()\r\nprint(\"#Black&White\")", "n,m=map(int,input().split())\r\nc=False\r\nfor i in range(n):\r\n s=input()\r\n if \"C\" in s or \"M\" in s or \"Y\" in s:\r\n c=True\r\nif c:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "while True:\r\n try:\r\n a,b=map(int,input().split())\r\n ctr=0\r\n for i in range(a):\r\n l=list(input().split())\r\n for j in range(len(l)):\r\n if l[j]=='C'or l[j]=='M' or l[j]=='Y':\r\n ctr=1\r\n break\r\n if ctr==0:\r\n print(\"#Black&White\")\r\n else:\r\n print(\"#Color\")\r\n except Exception as e:\r\n break", "n,m = [int(x) for x in input().split()]\r\nans = '#Black&White'\r\nfor i in range(n):\r\n array = input().split()\r\n for i in array:\r\n if i in ['C','M','Y']:\r\n ans = '#Color'\r\nprint(ans)\r\n", "result = '#Black&White'\r\nfor row in range(int(input().split()[0])):\r\n s = input()\r\n if any(i in s for i in {'C', 'M', 'Y'}):\r\n result = '#Color'\r\n\r\nprint(result)", "b = int(input().split()[0])\r\ng = '#Black&White'\r\nfor i in range(b):\r\n f = str(input().split())\r\n if (\"C\" in f) or (\"M\" in f) or (\"Y\" in f):\r\n g = '#Color'\r\nprint(g)", "n = input().split()\r\nfor i in range(int(n[0])):\r\n if i == 0:\r\n s = input().split()\r\n else:\r\n s.extend(input().split())\r\n \r\nif 'C' in s or 'M' in s or 'Y' in s:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "n,m=map(int,input().split())\r\nflag=0\r\nfor i in range(n):\r\n s=input()\r\n if ('C' in s or 'M' in s or 'Y' in s):\r\n flag=1\r\n break\r\nif(flag==0):\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "n,m = list(map(int,input().split()))\r\nmatrix = [input().split() for i in range(n)]\r\nflag = 0\r\ncolor = [\"C\",\"M\",\"Y\"]\r\nfor i in range(n):\r\n for j in range(m):\r\n if matrix[i][j] in color:\r\n flag = 1\r\nif flag == 0:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "n, m = map(int, input().split())\r\nres = '#Black&White'\r\n\r\nfor i in range(n):\r\n a = list(input().split())\r\n\r\n if 'C' in a or 'M' in a or 'Y' in a:\r\n res = '#Color'\r\n break\r\n\r\n else:\r\n continue\r\n\r\nprint(res)", "def main():\r\n s = open(0).read().split()[2:]\r\n if 'C' in s or 'M' in s or 'Y' in s:\r\n print(\"#Color\")\r\n else:\r\n print(\"#Black&White\")\r\n\r\n \r\nmain()", "n,m = map(int,input().split())\r\nl = []\r\nfor i in range(n):\r\n \r\n j = list(map(str,input().split()))\r\n l.append(j)\r\n\r\ndef ju (l):\r\n l2 = []\r\n for p in range(len(l)):\r\n for t in range(len(l[0])):\r\n l2.append(l[p][t])\r\n if \"C\" in l2 or \"Y\" in l2 or \"M\" in l2:\r\n return(\"#Color\")\r\n else:\r\n return(\"#Black&White\")\r\n \r\nprint(ju(l))", "n,m=map(int,input().split())\r\nc=''\r\nflag=False\r\nfor i in range(n):\r\n c+=input()\r\nfor i in 'CMY':\r\n if i in c:\r\n flag=True\r\n break\r\nif flag:\r\n print('#Color')\r\nelse:print('#Black&White') \r\n ", "n, m = map(int, input().split())\r\nphoto = []\r\nflag = True\r\nfor i in range(n):\r\n photo.append(input().split())\r\nfor i in photo:\r\n for j in i:\r\n if j in ['C', 'M', 'Y']:\r\n flag = False\r\n break\r\n else:\r\n continue\r\n break\r\nprint('#Black&White' if flag else '#Color')", "import sys; input = sys.stdin.readline\r\nn, m = map(int, input().split())\r\nfor _ in range(n):\r\n for color in input().split():\r\n if color in 'CMY':\r\n print('#Color')\r\n exit()\r\nprint('#Black&White')", "n,m=map(int,input().split())\r\nl=['C','M','Y']\r\nf=[]\r\nflag=0\r\nfor i in range(n):\r\n k=input().split()\r\n f.append(k)\r\nfor i in range(n):\r\n for j in range(m):\r\n if f[i][j] in l:\r\n print('#Color')\r\n flag=1\r\n break\r\n if flag==1:\r\n break\r\nif flag==0:\r\n print('#Black&White')", "from sys import stdin\r\nn,m=map(int,stdin.readline().split())\r\na=stdin.read()\r\nif 'C' in a:\r\n print('#Color')\r\nelif 'M' in a:\r\n print('#Color')\r\nelif 'Y' in a:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "n,m=map(int,input().split())\r\nls=[]\r\nf=True\r\nfor i in range(n):\r\n s=(input().split())\r\n for j in s:\r\n if j=='C' or j=='M' or j=='Y':\r\n print('#Color')\r\n f=False\r\n break\r\n if not f:break\r\nelse:\r\n print('#Black&White')", "v1,v2=map(int,input().split());v=[]\r\nfor _ in range(v1):m=input().split();v.append(m)\r\ng=['C','M','Y']\r\nfor i in v:\r\n for j in i:\r\n if j in g:\r\n print('#Color')\r\n exit()\r\nprint('#Black&White')\r\n ", "n,m=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n l1=list(map(str,input().split()))[:m]\r\n for i in l1:\r\n l.append(i)\r\na=l.count('B')\r\nb=l.count('W')\r\nc=l.count('G')\r\nif a+b+c==len(l):\r\n print('#Black&White')\r\nelse:\r\n print('#Color')\r\n ", "a,b=map(int,input().split())\r\nl=[]\r\nfor i in range(a):\r\n c=list(input().split())\r\n l.append(c)\r\n#print(l)\r\nx=0\r\nfor i in l:\r\n for j in i:\r\n if j=='B' or j=='G' or j=='W':\r\n continue\r\n else:\r\n x+=1\r\n break;\r\nif x>0:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "rows, columns = map(int, input().split())\r\n\r\ncolors = set()\r\n\r\nfor i in range(rows):\r\n color = list(input().split())\r\n for el in color:\r\n colors.add(el)\r\n\r\nif (\"C\" in colors or \"M\" in colors or \"Y\" in colors):\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "x,y=map(int,input().split())\nlst=list()\nfor i in range(x):\n n=input()\n if len(n)>1:\n n=n.split()\n for ele in n:\n lst.append(ele)\n else:\n lst.append(n)\nif 'C' in lst or 'M' in lst or 'Y' in lst:\n print('#Color')\nelse:\n print('#Black&White')\n\t\t \t \t \t \t \t\t \t\t \t\t \t\t", "r,c=input().split()\r\nr = int(r)\r\nc = int(c)\r\nf=0\r\nwhile(r!=0):\r\n a = list(input().split())\r\n if 'C' in a or 'M' in a or 'Y' in a:\r\n f+=1\r\n r-=1\r\nif f!=0:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, m = [int(x) for x in input().split()]\r\na = ''\r\nb = ''\r\nfor i in range(n):\r\n a+=(\"\".join(input().split()))\r\nfor i in a:\r\n if i=='C' or i=='M' or i=='Y':\r\n b = '#Color'\r\n break\r\n else:\r\n b = '#Black&White'\r\nprint(b)", "def is_black_and_white(photo):\n\tfor row in photo:\n\t\tfor pixel in row.split():\n\t\t\tif pixel in 'CMY':\n\t\t\t\treturn False\n\treturn True\n\t\n\nn, m = [int(tmp) for tmp in input().split()]\nphoto = []\nfor i in range(n):\n\tphoto.append(input().strip())\nif is_black_and_white(photo):\n\tprint('#Black&White')\nelse:\n\tprint('#Color')\n\t\t\n", "n, m = map(int, input().split())\r\ns = [list(map(str, input().split())) for i in range(n)]\r\na = True\r\nfor i in range(n):\r\n for j in range(m):\r\n if 'C' == s[i][j] or 'M' == s[i][j] or 'Y' == s[i][j]:\r\n a = False\r\n break\r\nprint('#Black&White' if a == True else '#Color')", "\r\nnumbers = [int(i)for i in input().split()]\r\nn = numbers[0]\r\nm = numbers[1]\r\ninp = []\r\nfor x in range(n):\r\n nums = [(i) for i in input().split()]\r\n inp.append(nums)\r\nflag = False\r\nfor item in inp:\r\n for value in item:\r\n if value in \"CMY\":\r\n flag = True\r\n break\r\n if flag==True:\r\n break\r\nif flag==True:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n,m=list(map(int,input().strip().split()))\r\nfor i in range(n):\r\n a=input().strip().split()\r\n for j in a:\r\n if j in ['C','M','Y']:\r\n print('#Color')\r\n exit()\r\nprint('#Black&White')", "n,m=map(int,input().split())\nlst=[]\nfor i in range(n):\n lst.append(''.join(input().split()))\nlst=''.join(lst)\nif 'C' in lst or 'M' in lst or 'Y' in lst:\n print('#Color')\nelse:\n print('#Black&White')", "m, n = input().split()\r\nm, n = int(m), int(n)\r\nfor i in range(m):\r\n p = input()\r\n if 'C' in p or 'M' in p or 'Y' in p:\r\n print('#Color')\r\n break\r\nelse:\r\n print('#Black&White')", "a,b=map(int,input().split())\r\ncolor=0\r\nfor i in range(a):\r\n c=input().split()\r\n for j in c:\r\n if j=='C' or j=='M' or j=='Y':\r\n color=1\r\n break\r\n if color==1:\r\n break\r\nif color==1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n \r\n\r\n\r\n\r\n\r\n", "a = list(map(int,input().split()))\r\nb,c = a\r\nl = 0\r\nfor i in range(b):\r\n d = input()\r\n\r\n if d.count('Y') == 0 and d.count('C') == 0 and d.count('M') == 0:\r\n l += 1\r\n\r\nif l == b:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "a,b = map(int, input().split())\r\nk = False\r\nfor i in range(a):\r\n\ttxt = input()\r\n\tif \"C\" in txt or \"M\" in txt or \"Y\" in txt:\r\n\t\tk = True\r\n\r\nif k:\r\n\tprint(\"#Color\")\r\nelse:\r\n\tprint(\"#Black&White\")", "l = set()\r\nfor i in range(int(input().split()[0])):\r\n k = set(input().split())\r\n l.update(k)\r\nprint([\"#Black&White\",\"#Color\"][bool(l&{\"M\",\"C\",\"Y\"})])", "row , col = map(int,input().split())\r\ncolored = ['C','M','Y']\r\nisColored = False\r\nfor i in range(row) :\r\n element_row = input().split()\r\n for element in element_row :\r\n if element in colored :\r\n isColored = True\r\n break\r\n\r\nif isColored :\r\n print(\"#Color\")\r\nelse :\r\n print(\"#Black&White\")", "n, m = map(int, input().split())\r\nc = ''\r\nfor i in range(n):\r\n\tc += input()\r\n \r\nif \"C\" in c or \"M\" in c or \"Y\" in c:\r\n\tprint('#Color')\r\nelse:\r\n\tprint('#Black&White')", "n, m = map(int, input().split())\r\nlst = []\r\n\r\nfor i in range(n):\r\n lst.append(list(input().split()))\r\n\r\nfor l in lst:\r\n if \"C\" in l or \"M\" in l or \"Y\" in l:\r\n print(\"#Color\")\r\n exit()\r\n\r\nprint(\"#Black&White\")", "n,m = map(int,input().split())\r\nl = list()\r\nfor i in range(n):\r\n l = l+list(input().split())\r\nif l.count(\"C\") == 0 and l.count(\"M\") == 0 and l.count(\"Y\") == 0:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "def check_photo_color(n, m, photo_matrix):\r\n for i in range(n):\r\n for j in range(m):\r\n color = photo_matrix[i][j]\r\n if color in ['C', 'M', 'Y']:\r\n return \"#Color\"\r\n return \"#Black&White\"\r\n\r\n# Read input\r\nn, m = map(int, input().split())\r\nphoto_matrix = [list(input().split()) for _ in range(n)]\r\n\r\n# Call the function and print the result\r\nresult = check_photo_color(n, m, photo_matrix)\r\nprint(result)\r\n", "n1,n2 = map(int,input().split())\r\nf = False\r\nb = 0\r\nfor _ in range(n1):\r\n a = list(input().split())\r\n for i in range(len(a)):\r\n if a[i] == \"C\" or a[i] == \"M\" or a[i] == \"Y\" :\r\n f = True\r\n b += 1\r\n if f and b == n1:\r\n print(\"#Color\")\r\n elif b == n1 :\r\n print(\"#Black&White\")", "a,b = map(int,input().split())\r\nc = 0\r\nfor i in range(a):\r\n n = input()\r\n if n.find('C') != -1:\r\n c = 1\r\n if n.find('M') != -1:\r\n c = 1\r\n if n.find('Y') != -1:\r\n c = 1\r\nif c==0:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')", "n,m=map(int,input().split())\r\nc=0\r\nfor i in range(n):\r\n lis=list(map(str,input().split()))\r\n for i in lis:\r\n if i==\"W\" or i==\"B\" or i==\"G\":\r\n c+=1\r\nif c==(n*m):\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n", "om=input().split(maxsplit=2)\r\na=int(om[0])\r\nb=int(om[1])\r\ns=0\r\nfor i in range(a):\r\n ll=input().split(maxsplit=b)\r\n if 'C' in ll or 'M' in ll or 'Y' in ll:\r\n s+=1\r\nif s!=0:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "black_n_white = ['W', 'B', 'G']\r\ncontains_Color = False\r\nn, m = map(int, input().split())\r\n\r\nfor i in range(n):\r\n \r\n if contains_Color:\r\n _ = input()\r\n continue\r\n \r\n colors = input().split()\r\n \r\n for c in colors:\r\n if c not in black_n_white:\r\n contains_Color = True\r\n break\r\n \r\nif not contains_Color:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')", "x,y=list(map(int,input().split(\" \")))\r\np=\"#Black&White\"\r\nfor i in range(x):\r\n l=input().split(\" \")\r\n if ('C' in l or 'M' in l or 'Y' in l ):\r\n p=\"#Color\"\r\n break\r\n\r\nprint (p)", "n, m = [int(x) for x in input().split()]\r\ncolor = 0\r\nfor i in range(n):\r\n Pixel_Color = input()\r\n if (\"C\" in Pixel_Color) or (\"M\" in Pixel_Color) or (\"Y\" in Pixel_Color):\r\n color += 1\r\nif color == 0:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "def f(a,b,c):\r\n for i in range(b):\r\n for j in range(c):\r\n if a[i][j] in 'CYM':\r\n return '#Color'\r\n return '#Black&White'\r\n\r\nn,m = map(int,input().split())\r\nx = []\r\nfor i in range(n):\r\n x.append(input().split())\r\nprint(f(x,n,m))", "from sys import stdin\r\nn, m = [int(x) for x in stdin.readline().strip().split(\" \")]\r\nphoto = []\r\nflag = True\r\nfor m in range(n):\r\n colors = stdin.readline().strip().split(\" \")\r\n photo.append(colors)\r\nfor m in photo:\r\n if 'C' in m or 'Y' in m or 'M' in m:\r\n flag = False\r\n break\r\nif flag:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "d = input()\r\nflag = False\r\nfor count in range(0, len(d), 1):\r\n if d[count] == \" \": \r\n num = int(d[:count])\r\n break\r\nfor c in range(num):\r\n e = input()\r\n for k in range(0, len(e), 2):\r\n if e[k] == \"C\" or e[k] == \"M\" or e[k] == \"Y\":\r\n print(\"#Color\")\r\n flag = True\r\n break\r\n if flag == True:\r\n break\r\nif flag == False:\r\n print(\"#Black&White\")\r\n ", "size = input()\r\ninputs = []\r\nans = '#Black&White'\r\nfor i in range(0, int(size[0])):\r\n inputs.append(input().split())\r\nfor item in inputs:\r\n if 'C' in item or 'M' in item or 'Y' in item:\r\n ans = '#Color'\r\nprint(ans)", "n, m = map(int, input().split())\r\ncolored = ['C', 'M', 'Y']\r\ncounter = 0\r\nfor i in range(0, n):\r\n mlist = list(map(str, input().split()))\r\n for j in colored:\r\n if j in mlist:\r\n counter += 1\r\n\r\nif counter > 0:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n,m = map(int, input().split())\r\nv = False\r\nfor i in range(n):\r\n r = input().split()\r\n for j in r:\r\n if j in ['C', 'M', 'Y']:\r\n v = True\r\n break\r\nprint(\"#Color\" if v else \"#Black&White\")\r\n", "n,k=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n l.extend(list(map(str,input().split())))\r\nif ('C' in l) or ('M' in l) or ('Y' in l):print('#Color')\r\nelse:print('#Black&White')", "[n,m] = map(int,input() .split())\nans = \"#Black&White\"\nfor i in range(n):\n line=list(input() .split())\n for pixel in line:\n if pixel in [\"C\",\"M\",\"Y\"]:\n ans=\"#Color\"\nprint(ans)", "n, m = map(int, input().split())\ns = []\nfor i in range(n):\n s.append(list(map(str, input().split())))\n\nfor i in range(n):\n for j in range(m):\n if s[i][j] in \"CMY\":\n print('#Color')\n exit()\n\nprint('#Black&White')\n", "n, m = map(int, input().split())\r\nis_done = False\r\nfor i in range(n):\r\n a = input().split()\r\n for j in a:\r\n if j == \"C\" or j == \"M\" or j == \"Y\":\r\n is_done = True\r\n\r\nif not is_done:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "n,m=[int(i) for i in input().split()]\r\nans=\"#Black&White\"\r\nfor i in range(n):\r\n\tl=[j for j in input().split()]\r\n\tif l.count(\"C\")>=1 or l.count(\"Y\")>=1 or l.count(\"M\")>=1:\r\n\t\tans=\"#Color\"\r\nprint(ans)", "# n = int(input())\r\n# x = 0\r\n#\r\n# for i in range(n):\r\n# oper = input()\r\n# if \"++\" in oper:\r\n# x += 1\r\n# elif \"--\" in oper:\r\n# x -= 1\r\n#\r\n# print(x)\r\n\r\n# a = sum(list(map(lambda x: ord(x), list(input().lower()))))\r\n# b = sum(list(map(lambda y: ord(y), list(input().lower()))))\r\n#\r\n# if a == b:\r\n# print(0)\r\n# elif a > b:\r\n# print(1)\r\n# else:\r\n# print(-1)\r\n\r\n# a = input().lower()\r\n# b = input().lower()\r\n# check = True\r\n#\r\n# for i in range(len(a)):\r\n# if ord(a[i]) > ord(b[i]):\r\n# print(1)\r\n# check = False\r\n# break\r\n# elif ord(a[i]) < ord(b[i]):\r\n# print(-1)\r\n# check = False\r\n# break\r\n#\r\n# if check:\r\n# print(0)\r\n\r\n# n = int(input())\r\n# s = input()\r\n#\r\n# a = s.count(\"A\")\r\n# d = n - a\r\n#\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# t = int(input())\r\n#\r\n# for i in range(t):\r\n# a, b, c = list(map(lambda x: int(x), input().split()))\r\n# if a + b == c:\r\n# print(\"+\")\r\n# elif a - b == c:\r\n# print(\"-\")\r\n\r\nn, m = map(lambda x: int(x), input().split())\r\ncolor = False\r\n\r\nfor i in range(n):\r\n color_line = list(input().split())\r\n if \"C\" in color_line or \"M\" in color_line or \"Y\" in color_line:\r\n color = True\r\n\r\nif color:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "def is_colored_photo(photo):\r\n colored_colors = {'C', 'M', 'Y'} # Set of colored colors\r\n\r\n for row in photo:\r\n for pixel in row:\r\n if pixel in colored_colors:\r\n return True # Found a colored pixel\r\n\r\n return False # No colored pixels found, photo is black-and-white\r\n\r\n\r\n#Input\r\nrow, col = map(int, input().split())\r\ninp = []\r\nfor i in range(row):\r\n j = input().split()\r\n inp.append(j)\r\nif is_colored_photo(inp):\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n ", "n,m = map(int, input().split())\r\ncolor = False\r\nfor i in range(n):\r\n x = input().split()\r\n for i in x:\r\n if i==\"C\" or i==\"M\" or i==\"Y\":\r\n color = True\r\n break\r\n\r\n \r\nif color:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n ", "n, m = map(int, input().split())\r\ns = []\r\ncount = 0\r\nfor _ in range(n):\r\n s.append(input().split())\r\nfor i in range(n): \r\n for j in range(m):\r\n if s[i][j] in ('W', 'G', 'B'):\r\n count += 1\r\nif count == n * m:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')", "matrix = []\r\ncount = 0\r\nrow,col = list(map(int,input().split()))\r\nfor i in range(row):\r\n matrix.append(list(input().split()))\r\nfor i in range(row):\r\n for j in range(col):\r\n if matrix[i][j]=='C' or matrix[i][j]=='Y' or matrix[i][j]=='M':\r\n count+=1\r\nif count>0:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n", "y, x = map(int, input().split())\r\nfor _ in range(y):\r\n s = input().split()\r\n if 'C' in s or 'M' in s or 'Y' in s:\r\n print('#Color')\r\n break\r\nelse:\r\n print('#Black&White')", "n,m=list(map(int,input().split()))\r\nflage=False \r\nfor i in range(n):\r\n x=list(input().split())\r\n if 'C' in x or 'Y' in x or 'M' in x:flage=True\r\n\r\nif flage:print('#Color')\r\nelse:print('#Black&White')", "n = input().split()\r\nc = 0\r\nfor i in range(int(n[0])):\r\n a = list(map(str, input().split()))\r\n for j in a:\r\n if \"C\" == j or \"M\" == j or \"Y\" == j:\r\n c = 1\r\nif c == 1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n,m=map(int,input().split())\r\nf,w,b,g=0,0,0,0\r\nfor _ in range(n):\r\n s=input().split()\r\n w+=s.count(\"W\")\r\n b+=s.count(\"B\")\r\n g+=s.count(\"G\")\r\nf=w+b+g\r\nif f==n*m:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n", "[n,m] = [int(i) for i in input().split(\" \")]\r\n\r\ncolor = 0\r\nfor i in range(n):\r\n line = input().split(\" \")\r\n for i in line:\r\n if i in ['C', 'M', 'Y']:\r\n color += 1\r\nif color >= 1 :\r\n print(\"#Color\")\r\nelse :\r\n print(\"#Black&White\")", "\r\nc = ('C', 'M', 'Y')\r\nn, m = map(int, input().split())\r\nans = \"#Black&White\"\r\n\r\nfor i in range(n):\r\n l = input().split()\r\n if c[0] in l or c[1] in l or c[2] in l:\r\n ans = \"#Color\"\r\n break\r\n\r\nprint(ans)\r\n", "m, n = map(int, input().split())\r\np = 0\r\nflag = 1\r\nwhile p < m:\r\n s = input()\r\n for i in range(0, len(s), 2):\r\n if s[i] in 'CMY':\r\n flag = 0\r\n break\r\n p += 1\r\nif flag:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')", "a, b = [int(i) for i in input().split()]\r\nfor i in range(a):\r\n c = input()\r\n if 'M' in c or 'Y' in c or 'C' in c:\r\n print('#Color')\r\n break\r\nelse:\r\n print('#Black&White')\r\n", "s,n = map(int,input().split())\n\nt = 0\np = ['C','M','Y']\nfor _ in range(s):\n x = list(map(str,input().split()))\n for i in x:\n if i in p:\n t += 1\n break\n\nif t==0:\n print('#Black&White')\nelse:\n print('#Color')", "n, m = map(int, input().split())\r\na = [input().split() for i in range(n)]\r\nflag = True\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] not in ['B', 'W', 'G']:\r\n flag = False\r\n break\r\n if not flag:\r\n break\r\nprint(['#Color', '#Black&White'][flag])", "def is_colored_or_black_and_white(n, m, photo):\r\n for i in range(n):\r\n for j in range(m):\r\n if photo[i][j] in ('C', 'M', 'Y'):\r\n return \"#Color\"\r\n return \"#Black&White\"\r\n\r\nn, m = map(int, input().split())\r\nphoto = [input().split() for _ in range(n)]\r\nprint(is_colored_or_black_and_white(n, m, photo))\r\n", "a,b=map(int,input().split())\r\nc=[]\r\nfor i in range(a):\r\n l=list(map(str,input().split()))\r\n c.extend(l)\r\nk1=0\r\nk2=0\r\nk3=0\r\nk1=c.count('B')\r\nk2=c.count('W')\r\nk3=c.count('G')\r\nif k1+k2+k3==len(c):\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n", "n,m = map(int,input().split())\r\nl = []\r\nfor x in range(n):\r\n a = list(map(str, input().split()))\r\n l.append(a)\r\nd = False\r\nfor i in l:\r\n for j in i:\r\n if j == 'C' or j == 'M' or j == 'Y':\r\n d = True\r\nif d:\r\n print('#Color')\r\nelse:\r\n print(\"#Black&White\")\r\n ", "m,n=map(int,input().split())\r\nc=0\r\nfor i in range(m):\r\n a=list(map(str,input().split()))\r\n if 'C' in a or 'Y' in a or 'M' in a:\r\n c=c+1\r\nif c!=0:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "[n,m]=map(int,input().split())\r\nx=[]\r\nfor i in range(n):\r\n b=input()\r\n if \"C\" in b or \"M\" in b or \"Y\" in b:\r\n x.append(1)\r\n else:x.append(0)\r\nif 1 in x:\r\n print(\"#Color\")\r\nelif 1 not in x:\r\n print(\"#Black&White\")", "n,m=map(int,input().split())\r\nis_color=False\r\nfor i in range(n):\r\n r=input().split()\r\n for color in r:\r\n if color in ['C','M','Y']:\r\n is_color=True\r\n break\r\n if is_color:\r\n break\r\n\r\nprint(\"#Color\" if is_color else \"#Black&White\")", "a, b = map(int,input().split())\r\ncolor=set(['C','M','Y'])\r\ncolored = False\r\nfor _ in range(a):\r\n s = list(input().split())\r\n for x in s:\r\n if x in color:\r\n colored = True\r\nprint(\"#Color\" if colored else \"#Black&White\")", "n,m=map(int,input().split())\r\na=\"#Black&White\"\r\nfor i in range(n):\r\n s=input().split()\r\n if s.count(\"B\")+s.count(\"W\")+s.count(\"G\")!=m:\r\n a=\"#Color\"\r\nprint(a)\r\n", "import sys\r\nfrom math import ceil,floor,sqrt,log,dist\r\nfrom collections import defaultdict\r\nfrom operator import itemgetter\r\nrmi=lambda:map(int,input().split())\r\nrs=lambda:input()\r\nri=lambda:int(rs())\r\ninf=float('inf')\r\ndef f():\r\n n,m=rmi()\r\n s=\"\"\r\n for i in range(n):\r\n s+=rs()\r\n s=s.replace(\" \",\"\")\r\n for i in range(n*m):\r\n if s[i]==\"C\" or s[i]==\"M\" or s[i]==\"Y\":\r\n print(\"#Color\")\r\n return 0\r\n print(\"#Black&White\")\r\nf()\r\n", "n,m = map(int,input().strip(\" \").split(\" \"))\r\npic = []\r\n\r\nfor _ in range(n):\r\n\tpic.append(input().strip(\" \").split(\" \"))\r\n\r\nhas_color = False\r\nfor i in range(n):\r\n\tfor j in range(m):\r\n\t\tif pic[i][j] == 'C' or pic[i][j] == 'M' or pic[i][j] == 'Y':\r\n\t\t\thas_color = True\r\n\r\nprint(\"#Color\" if has_color else \"#Black&White\")", "n, m = map(int, input().split())\r\nc = False\r\nfor _ in range(n):\r\n r= input().split()\r\n for p in r:\r\n if p in ['C', 'M', 'Y']:\r\n c = True\r\n break\r\n\r\nif c:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n,m=input().split()\r\nn=int(n)\r\nm=int(m)\r\nlist1=[]\r\nfor i in range(n):\r\n inp=input().split()\r\n list1.append(inp)\r\nblack=1\r\nfor j in list1:\r\n for k in j:\r\n if k=='Y' or k=='M' or k=='C':\r\n print('#Color')\r\n black=0 \r\n break \r\n if black==0:\r\n break\r\n\r\nif black!=0:\r\n print(\"#Black&White\") \r\n\r\n ", "n, m = map(int, input().split())\r\nfor i in range(n):\r\n row = input()\r\n if \"C\" in row or \"M\" in row or \"Y\" in row:\r\n print(\"#Color\")\r\n break\r\nelse:\r\n print(\"#Black&White\")", "n, m = map(int, input().split())\r\nis_color = False\r\ncolors = ('C', 'Y', 'M')\r\nfor _ in range(n):\r\n row = input().split()\r\n if not is_color and any(i in colors for i in row):\r\n is_color = True\r\n \r\nprint('#Color' if is_color else '#Black&White')", "import sys\r\nn, m = input().split()\r\nn, m = int(n), int(m)\r\ncolors = []\r\nfor i in range(n):\r\n char = input()\r\n colors.append(char)\r\nfor i in range(n):\r\n for j in range(len(colors[i])): \r\n if colors[i][j] == 'C' or colors[i][j] == 'M' or colors[i][j] == 'Y':\r\n print('#Color')\r\n sys.exit()\r\nprint('#Black&White')", "n,m=map(int,input().split())\r\ns = ''\r\nfor i in range(n):\r\n\ts += input()\r\nprint('#Color ' * (len(set('CMY') & set(s)) != 0) or '#Black&White')", "n, m = map(int, input().split())\r\n\r\n# Set to keep track of colors in the photo\r\ncolors = set()\r\n\r\n# Iterate over each pixel in the photo\r\nfor i in range(n):\r\n row = input().split()\r\n for j in range(m):\r\n colors.add(row[j])\r\n\r\n# Check if the photo is black-and-white or colored\r\nif {'C', 'M', 'Y'} & colors:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n, m = map(int, input().split())\nimage = [input().split() for i in range(n)]\nk = 0\nfor rows in image:\n for element in rows:\n if element != \"C\" and element!=\"M\" and element!=\"Y\":\n k +=1\nif k == n*m:\n print(\"#Black&White\")\nelse:\n print(\"#Color\")\n\n", "import sys\r\nfrom typing import Callable\r\n\r\nAPPROVED = {'B', 'W', 'G'}\r\n\r\n\r\ndef main() -> None:\r\n read: Callable[[], str] = sys.stdin.readline\r\n n, m = (int(i) for i in read().split())\r\n for _ in range(n):\r\n values: list[str] = [i for i in read().strip('\\n').split()]\r\n for c in values:\r\n if c not in APPROVED:\r\n print('#Color')\r\n return\r\n print('#Black&White')\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "def sol(n,l):\r\n for i in range(len(l)):\r\n temp=\"\".join(l[i]).split(\" \")\r\n if temp.count(\"C\")>0 or temp.count(\"M\")>0 or temp.count(\"Y\")>0:\r\n return \"#Color\"\r\n return \"#Black&White\"\r\n\r\n \r\n\r\nn,m = map(int ,input().split())\r\nl=[input().split(\"\\n\") for _ in range(n)]\r\nprint(sol(n,l))\r\n", "a, b = map(int, input().split())\r\nlst = [input().split() for i in range(a)]\r\nflag = '#Black&White'\r\nfor i in range(a):\r\n for j in range(b):\r\n if lst[i][j] not in 'BWG':\r\n flag = '#Color'\r\n break\r\nprint(flag)", "[n, m] = map(int, input().split(' '))\ndata = []\ncolors = ['C', 'M', 'Y']\nb_w = ['W', 'G','B']\nfor i in range(n):\n temp = input().split(' ')\n data.append(temp)\n\nfor i in range(n):\n for j in range(m):\n if data[i][j] in colors:\n print('#Color')\n quit()\nprint('#Black&White')", "x,y=map(int, input().split(\" \"))\r\nflag=False\r\nfor i in range(x):\r\n l=list( input().split(\" \"))\r\n for i in l:\r\n if i==\"C\" or i==\"M\" or i==\"Y\":\r\n flag=True\r\n break\r\n else:\r\n Flag=False\r\n if flag==True:\r\n break\r\nif flag==True:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "# Happy_water\r\ndef main():\r\n n, m = map(int, input().split())\r\n g = [list(input().split()) for i in range(n)]\r\n for i in range(n):\r\n for j in range(m):\r\n if g[i][j] != 'W' and g[i][j] != 'G' and g[i][j] != 'B':\r\n print(\"#Color\")\r\n return\r\n print(\"#Black&White\")\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "b=list(map(int,input().split()))\r\nv=[]\r\nfor i in range(b[0]):\r\n b=list(map(str,input().split()))\r\n v+=b\r\nif \"M\" in v or \"Y\" in v or \"C\" in v:\r\n print(\"#Color\")\r\n\r\nelse:\r\n print(\"#Black&White\")", "n, m = list(map(int, input().split()))\r\nmatrix = []\r\nfor i in range(n):\r\n en = input().split()\r\n if \"C\" in en or \"Y\" in en or \"M\" in en:\r\n print(\"#Color\")\r\n exit()\r\nprint(\"#Black&White\")\r\n", "# // import java.util.*;\r\n# // public class codeforces{\r\n# // public static int number_of_distinct_characters(int array[]){\r\n# // int ans=0;\r\n# // for(int i=0;i<array.length;i++){\r\n# // if(array[i]>0){\r\n# // ans++;\r\n# // }\r\n# // }\r\n# // return ans;\r\n# // }\r\n# // public static void main(String args[]) {\r\n# // Scanner scan=new Scanner(System.in);\r\n# // int T=Integer.parseInt(scan.nextLine());\r\n# // for(int i=1;i<=T;i++){\r\n# // int number_of_days=0;\r\n# // String st=scan.nextLine();\r\n# // int arr[]=new int[26];\r\n# // for(int j=0;j<st.length();j++){\r\n# // arr[st.charAt(j)-97]++;\r\n# // if(number_of_distinct_characters(arr)==4 || j==st.length()-1){\r\n# // number_of_days++;\r\n# // Arrays.fill(arr, 0);\r\n# // j--;\r\n# // }\r\n# // }\r\n# // System.out.println(number_of_days);\r\n# // }\r\n# // scan.close();\r\n# // }\r\n# // }\r\n\r\n# // #include <stdio.h>\r\n\r\n# // void swap(int *xp, int *yp)\r\n# // {\r\n# // int temp = *xp;\r\n# // *xp = *yp;\r\n# // *yp = temp;\r\n# // }\r\n \r\n# // void selectionSort(int index_arr[],int arr[], int n)\r\n# // {\r\n# // int i, j, max_idx,index=0;\r\n# // for (i = 0; i < n; i++){\r\n# // max_idx = i;\r\n# // for (j = i+1; j < n; j++){\r\n# // if (arr[j] > arr[max_idx]){\r\n# // max_idx = j;\r\n# // }\r\n# // }\r\n# // swap(&arr[max_idx], &arr[i]);\r\n# // swap(&index_arr[max_idx], &index_arr[i]);\r\n# // }\r\n# // }\r\n \r\n# // int main(){\r\n# // int N,x,y,z;\r\n# // scanf(\"%d%d%d%d\",&N,&x,&y,&z);\r\n# // int maths_arr[N],english_arr[N],total_arr[N];\r\n# // for(int i=0;i<N;i++){\r\n# // scanf(\"%d\",&maths_arr[i]);\r\n# // }\r\n# // for(int i=0;i<N;i++){\r\n# // scanf(\"%d\",&english_arr[i]);\r\n# // }\r\n# // for(int i=0;i<N;i++){\r\n# // total_arr[i]=maths_arr[i]+english_arr[i];\r\n# // }\r\n# // int maths_index_arr[N],english_index_arr[N],total_index_arr[N];\r\n# // for(int i=0;i<N;i++){\r\n# // maths_index_arr[i]=i+1;\r\n# // }\r\n# // for(int i=0;i<N;i++){\r\n# // english_index_arr[i]=i+1;\r\n# // }\r\n# // for(int i=0;i<N;i++){\r\n# // total_index_arr[i]=i+1;\r\n# // }\r\n# // selectionSort(maths_index_arr,maths_arr,N);\r\n# // selectionSort(english_index_arr,english_arr,N);\r\n# // selectionSort(total_index_arr,total_arr,N);\r\n\r\n# // for(int i=0;i<x;i++){\r\n# // printf(\"%d\\n\",maths_index_arr[i]);\r\n# // }\r\n# // for(int i=0;i<y;i++){\r\n# // printf(\"%d\\n\",english_index_arr[i]);\r\n# // }\r\n# // for(int i=0;i<z;i++){\r\n# // printf(\"%d \",total_index_arr[i]);\r\n# // }\r\n# // return 0;\r\n# // }\r\n\r\n\r\n# // # L=list(input().split())\r\n# // # N=int(L[0])\r\n# // # x=int(L[1])\r\n# // # y=int(L[2])\r\n# // # z=int(L[3])\r\n\r\n# // # maths_l=list(input().split())\r\n# // # english_l=list(input().split())\r\n# // # Maths_L=[]\r\n# // # English_L=[]\r\n# // # Total_L=[]\r\n# // # for i in range(0,N):\r\n# // # Maths_L.append([maths_l[i],i+1])\r\n# // # for i in range(0,N):\r\n# // # English_L.append([english_l[i],i+1])\r\n# // # for i in range(0,N):\r\n# // # Total_L.append([int(english_l[i])+int(maths_l[i]),i+1])\r\n\r\n# // # Maths_L.sort(reverse=True)\r\n# // # English_L.sort(reverse=True)\r\n# // # Total_L.sort(reverse=True)\r\n# // # print(Maths_L,English_L,Total_L)\r\n# // # for i in range(1,x+1):\r\n# // # print(Maths_L[i-1][1])\r\n# // # for i in range(1,y+1):\r\n# // # print(English_L[i-1][1])\r\n# // # for i in range(1,z+1):\r\n# // # print(Total_L[i-1][1])\r\n\r\n\r\n# /*package whatever //do not write package name here */\r\n \r\n# // import java.util.*;\r\n# // public class codeforces{\r\n# // public static void main(String[] args) {\r\n# // Scanner scan=new Scanner(System.in);\r\n# // int T=scan.nextInt();\r\n# // String st=scan.nextLine();\r\n# // for(int i=0;i<=T;i++){\r\n# // int n=scan.nextInt();\r\n# // // String st1=scan.nextLine();\r\n# // int number_of_two_value_burles=n/3,number_of_one_value_burles=n/3;\r\n# // if(n%3==1){\r\n# // number_of_one_value_burles+=1;\r\n# // }\r\n# // else if(n%3==2){\r\n# // number_of_two_value_burles+=1;\r\n# // }\r\n# // System.out.print(number_of_one_value_burles+\" \");\r\n# // System.out.println(number_of_two_value_burles);\r\n# // }\r\n \r\n# // scan.close();\r\n# // }\r\n# // }\r\n\r\n# // #include<stdio.h>\r\n# // int main(){\r\n# // int row,column;\r\n# // scanf(\"%d%d\",&row,&column);\r\n# // // printf(\"%d %d\",row,column);\r\n# // int arr[row][column];\r\n# // int temp=0;\r\n# // for(int i=0;i<row;i++){\r\n# // for(int j=0;j<2*column+1;j++){\r\n# // if(j%2==0){\r\n# // scanf(\"%c\",&arr[i][j/2]);\r\n# // }\r\n# // }\r\n# // }\r\n# // // for(int i=0;i<row;i++){\r\n# // // for(int j=0;j<column;j++){\r\n# // // printf(\"%c \",arr[i][j]);\r\n# // // }\r\n# // // printf(\"\\n\");\r\n# // // }\r\n# // printf(\"%c\",arr[1][1]);\r\n# // return 0;\r\n# // }\r\n\r\n# // Can't understand the problem in the above code so now writing it in python\r\n\r\n\r\n\r\nL=list(input().split())\r\nrow=int(L[0])\r\ncolumn=int(L[1])\r\ntemp=0\r\nfor i in range(1,row+1):\r\n l=list(input().split())\r\n for j in l:\r\n if(j=='C' or j=='Y' or j=='M'):\r\n temp=1\r\n break\r\n if temp==1:\r\n break\r\n\r\nif temp==0:\r\n print(\"#Black&White\")\r\nelif temp==1:\r\n print(\"#Color\")", "n,m = input().split()\r\nn,m = int(n),int(m)\r\n# while t > 0:\r\narr = []\r\nfor i in range(n):\r\n temp = input().split()\r\n arr.append(temp)\r\n\r\n\r\ndef solve():\r\n st = set(['C', 'M', 'Y'])\r\n for i in range(n):\r\n for j in range(m):\r\n if arr[i][j] in st:\r\n return True\r\n return False\r\n\r\nif solve():\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n \r\n # t -= 1\r\n\r\n\r\n\r\n\r\n", "n, m = map(int,input().split())\r\nls =[list(input().split()) for i in range(n)]\r\nfor i in ls:\r\n if i.count('C') >= 1 or i.count('M') >= 1 or i.count('Y') >= 1:\r\n print(\"#Color\")\r\n break\r\nelse:\r\n print(\"#Black&White\")", "n, m = tuple(map(int, input().split()))\ncolor = False\n\nColors = [\"C\", \"M\", \"Y\"]\nBW = [\"W\", \"G\", \"B\"]\n\nfor _ in range(n):\n row = input().split()\n for el in row:\n if el in Colors:\n color = True\n\nif color == True:\n print(\"#Color\")\nelse:\n print(\"#Black&White\")\n \t\t\t\t\t\t \t\t \t\t \t\t\t\t\t", "a,b=map(int,input().split())\r\nfor i in range(a):\r\n s=input().split()\r\n n1=s.count(\"C\")\r\n n2=s.count(\"M\")\r\n n3=s.count(\"Y\")\r\n if n1+n2+n3 !=0:\r\n print(\"#Color\")\r\n exit()\r\nprint(\"#Black&White\")", "n, m = map(int, input().split())\r\nc = 0\r\nfor i in range(n):\r\n if c:\r\n break\r\n for j in input().split():\r\n if j in ['C', 'M', 'Y']:\r\n c = 1\r\n break\r\nif c:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n", "n,m = list(map(int,input().split()))\r\nflag = True\r\nfor i in range(n):\r\n tmp = input().split()\r\n for i in tmp:\r\n if(i == 'C' or i =='M' or i =='Y'):\r\n flag = False\r\n break\r\n if not flag:\r\n break\r\nif(flag):\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "n,m=map(int,input().split())\r\nl=[]\r\nfor _ in range(n):\r\n l+=list(map(str,input().split()))\r\nif any(i in ['C','M','Y'] for i in set(l)):\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "n,m=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n a.append(list(map(str,input().split())))\r\nlc=['C','M','Y']\r\nlb=['B','W','G']\r\nf=0\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] in lc:\r\n f=1\r\n break\r\n if f==1:\r\n break\r\nif f==1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "s = list(map(int, input().split()))\r\ns1 = []\r\nfor i in range(s[0]):\r\n s2 = input().split()\r\n s1 = s1 + s2\r\nif ('C' in s1) or ('M' in s1) or ('Y' in s1):\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n", "temp = input().split()\r\nn, m = [int(x) for x in temp]\r\nreq = []\r\nres = ''\r\nfor i in range(n):\r\n temp = input().split() \r\n if 'C' in temp or 'M' in temp or 'Y' in temp:\r\n res = '#Color'\r\n\r\nif res != '':\r\n print(res)\r\nelse:\r\n print('#Black&White')\r\n ", "for row in [input().split() for _ in range(list(map(int, input().split()))[0])]:\r\n for elem in row:\r\n if elem in ('C', 'Y', 'M'):\r\n print(\"#Color\")\r\n break\r\n else:\r\n continue\r\n break\r\nelse:\r\n print(\"#Black&White\")\r\n", "rows, _ = map(int, input().split())\r\n\r\ntag = '#Black&White'\r\n\r\nfor idx in range(rows):\r\n\trow = list(input().split())\r\n\r\n\tfor c in row:\r\n\t\tif c in ('C', 'M', 'Y'):\r\n\t\t\ttag = '#Color'\r\n\r\n\tif tag == '#Color':\r\n\t\tbreak\r\n\r\nprint(tag)", "def main():\r\n n, m = [int(i) for i in input().split()]\r\n visited = []\r\n for _ in range(n):\r\n colors = input().split()\r\n for color in colors:\r\n if color not in visited:\r\n visited.append(color)\r\n if \"C\" in visited or \"Y\" in visited or \"M\" in visited:\r\n print(\"#Color\")\r\n else:\r\n print(\"#Black&White\")\r\n\r\n\r\nmain()", "n,m=map(int,input().split())\r\ns=''.join(input() for i in range(n))\r\nif s.count('C') + s.count('M') + s.count('Y') > 0:\r\n\tprint ('#Color')\r\nelse:\r\n\tprint ('#Black&White')", "n, m = map(int, input().split())\r\nmatrix = [input().split() for _ in range(n)]\r\nres = '#Black&White'\r\nfor i in range(len(matrix)):\r\n for j in range(len(matrix[i])):\r\n if matrix[i][j] == 'C' or matrix[i][j] == 'M' or matrix[i][j] == 'Y':\r\n res = '#Color'\r\nprint(res)", "n, m = map(int, input().split())\r\ns, flag = '', True\r\nwhile (n > 0):\r\n\ts += input()\r\n\tn -= 1\r\nprint('#Color' if ('C' in s or 'M' in s or 'Y' in s) else '#Black&White')", "n, m = list(map(int, input().split()))\r\nl = []\r\nfor i in range(n):\r\n l += list(input().split())\r\nprint('#Color' if any(i in 'CMY' for i in l) else '#Black&White')", "op='#Black&White'\r\nn,m=list(map(int,input().split()))\r\nfor _ in range(n):\r\n st=set(input().split())\r\n if 'C' in st or 'M' in st or 'Y' in st:\r\n op='#Color'\r\n break\r\nprint(op)", "rows, column = map(int, input().split())\r\ncolour = False\r\nfor row in range(rows):\r\n row_ = input()\r\n if \"C\" in row_ or \"M\" in row_ or \"Y\" in row_:\r\n colour = True\r\n break\r\nprint(\"#Color\") if colour else print(\"#Black&White\")", "def determine_col(n,m,matrix):\r\n colour={'C','M','Y'}\r\n \r\n for i in range(n):\r\n for j in range(m):\r\n if matrix[i][j] in colour:\r\n return '#Color'\r\n return '#Black&White'\r\nn, m = map(int, input().split())\r\nmatrix = [input().split() for _ in range(n)]\r\n\r\n\r\nresult = determine_col(n, m, matrix)\r\nprint(result)", "n, m = map(int, input().split())\r\nflag = False\r\nfor c in range(n):\r\n color = input()\r\n if color.find(\"C\")>-1 or color.find(\"M\")>-1 or color.find(\"Y\")>-1:\r\n flag = True\r\nif flag == True:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n,m=map(int,input().split())\r\nans=0\r\nfor i in range(n):\r\n row=list(input().split())\r\n if \"C\" in row or \"M\" in row or \"Y\" in row:\r\n ans=\"#Color\"\r\nif ans!=\"#Color\":\r\n ans=\"#Black&White\"\r\nprint(ans)", "n, m = map(int, input().split())\r\ne = []\r\nfor i in range(n):\r\n a = list(map(str, input().split()))\r\n e.append(a)\r\ne = str(e)\r\nif \"C\" in e or \"M\" in e or \"Y\" in e:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n ", "x, y = map(int, input().split())\r\ncolor_flag = False \r\n\r\nfor _ in range(x):\r\n row = input().split()\r\n if 'C' in row or 'M' in row or 'Y' in row:\r\n color_flag = True\r\n\r\nif color_flag:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n", "l1=[int(i) for i in input().split()][:2]\n\nn = l1[0]\nm = l1[1]\n\nl3 = []\nfor x in range(n):\n\n l3.append([str(k) for k in input().split()][:m]) \n \ndef x(K):\n\n for k in range(n):\n for t in range (m):\n if (K[k][t] == \"C\") or (K[k][t] == \"M\") or (K[k][t] == \"Y\"):\n return(\"#Color\")\n \n \n return(\"#Black&White\")\n\nprint(x(l3))", "n,f = int(input().split()[0]),''\r\nfor i in range(n):\r\n f += input().strip()\r\nprint('#Color'if 'C'in f or'M'in f or'Y'in f else '#Black&White')", "nm = [int(i) for i in input().split(' ')]\r\ns = 0\r\n\r\nfor i in range(nm[0]):\r\n c = input()\r\n if 'C' in c or 'M' in c or 'Y' in c:\r\n s+=1\r\n\r\nprint(('#Black&White' if s == 0 else '#Color'))", "n, m = map(int, input().split())\ncheck = False\ncolor = \"CMY\"\nfor i in range(n):\n l = [x for x in input().split()]\n for i in range(m):\n if l[i] in color:\n check = True\n break\nif check == True: print(\"#Color\")\nelse: print(\"#Black&White\")\n \t \t\t \t \t\t \t \t\t\t\t \t \t\t", "n=list(map(int,input().split()))\r\nc=0\r\nfor i in range(n[0]):\r\n t=0\r\n k=list(map(str,input().split()))\r\n for j in range(n[1]):\r\n if k[j] =='C' or k[j]=='M' or k[j]=='Y':\r\n c=1\r\n t=1\r\nif c==0:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "listA = list(map(int,input().split(\" \")))\r\nn = listA[0]\r\nm = listA[1]\r\nlistColor = ['C' , 'M' , 'Y']\r\ncount = 0\r\nfor i in range(0,n):\r\n listC = input().split(\" \")\r\n for C in listC:\r\n if C in listColor:\r\n count+=1\r\n break\r\nif count==0:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "a,b=map(int,input().split())\r\nx=[]\r\nfor i in range(a):\r\n l=list(map(str,input().split()))\r\n x=x+l\r\n\r\nif 'C' in x or 'M' in x or 'Y' in x:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n, m = map(int, input().split()) # dimensions of the matrix\r\nmatrix = []\r\ncolor = \"#Black&White\"\r\n\r\nfor x in range(n):\r\n row_data = input().split()\r\n matrix.append(row_data)\r\n\r\n# Check for colors 'C', 'M', or 'Y' in the matrix\r\nfor x in range(n):\r\n for y in range(m):\r\n if matrix[x][y] == 'C' or matrix[x][y] == 'M' or matrix[x][y] == 'Y':\r\n color = \"#Color\"\r\n # Exit the loops since we found a color\r\n break\r\n else:\r\n continue\r\n break\r\n\r\nprint(color)\r\n", "def main():\n x,y = map(int, input().split())\n for _ in range(x):\n words = input().split()\n for word in words:\n if word not in [\"W\", \"B\", \"G\"]:\n print(\"#Color\")\n return 0\n print(\"#Black&White\")\n return 0\nmain()", "n,m=[int(x) for x in input().split()]\r\nres='#Black&White'\r\nfor i in range(n):\r\n s=input()\r\n if 'C' in s or 'M' in s or 'Y' in s:\r\n res='#Color'\r\nprint(res)", "n, m = map(int, input().split())\r\n\r\npw = True\r\nfor i in range(n):\r\n cores = input().split()\r\n for cor in cores:\r\n if cor in ( 'C', 'M', 'Y' ):\r\n pw = False\r\n \r\nif pw:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n", "n,m=list(map(int,input().split()))\r\nlist=[]\r\na=\"\"\r\nfor i in range(n):\r\n s=input()\r\n list.extend(s)\r\n if \" \" in list:\r\n list.remove(\" \")\r\nfor x in range(n):\r\n if \"C\" in list or \"Y\" in list or \"M\" in list:\r\n a=\"COLOR\"\r\n\r\nif a==\"COLOR\":\r\n print(\"#Color\")\r\nelif a==\"\":\r\n print(\"#Black&White\")", "m,n=input().split()\r\nw=''\r\nc=0\r\nfor i in range(int(m)):\r\n s=input()\r\n w+=s\r\nfor i in w:\r\n if i==\"C\" or i==\"Y\" or i==\"M\":\r\n c+=1\r\nif c>0:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n\r\n ", "x,y=map(int,input().split())\r\na=True\r\nfor i in range(x):\r\n s=input().split()\r\n for j in range(y):\r\n if(s[j]=='C' or s[j]=='M' or s[j]=='Y'):\r\n a=False\r\n break\r\n\r\nif a:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n\r\n", "lst=input().split()\r\nn=int(lst[0])\r\nm=int(lst[1])\r\nlst=[]\r\nfor i in range(n):\r\n row=input().split()\r\n lst.append(row) \r\ncount=0 \r\nfor i in range(len(lst)):\r\n for j in lst[i]:\r\n if(j==\"C\" or j==\"M\" or j==\"Y\"):\r\n count+=1\r\n break\r\nif(count!=0): \r\n print(\"#Color\") \r\nelse:\r\n print(\"#Black&White\")", "n, m = map(int, input().split())\r\n\r\ncolors = []\r\nfor i in range(n) :\r\n colors.extend(input().split())\r\n\r\n\r\nprint ('#Color') if 'C' in colors or 'M' in colors or 'Y' in colors else print('#Black&White')\r\n", "n, m = map(int, input().split())\r\ns = []\r\nflag = '#Black&White'\r\nfor _ in range(n):\r\n s.append(input().split())\r\nfor i in range(n): \r\n for j in range(m):\r\n if s[i][j] not in 'WGB':\r\n flag = '#Color'\r\n break\r\n if flag == '#Color':\r\n break \r\nprint(flag)", "N,M = map(int,input().split())\r\npixels = {'C':0,'M':0,'Y':0,'W':0,'G':0,'B':0}\r\nfor i in range(N):\r\n i_pixels = [i for i in input().split()]\r\n for i in i_pixels:\r\n pixels[i]+=1\r\nif pixels['C'] or pixels['M'] or pixels['Y'] :\r\n print(\"#Color\") \r\nelse:\r\n print(\"#Black&White\")", "def check(n, m):\r\n for i in range(n):\r\n a = input()\r\n if a.count('W') + a.count('G') + a.count('B') != m:\r\n return '#Color'\r\n return '#Black&White'\r\n\r\nn, m = map(int, input().split())\r\n\r\nprint(check(n, m))\r\n", "n,m = input().split()\r\nlist = []\r\nfor i in range(int(n)):\r\n s = input().split()\r\n if 'C' in s or 'M' in s or 'Y' in s:\r\n list.append('#Color')\r\n else:\r\n list.append('#Black&White')\r\nif '#Color' in list:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "f=True\r\nfor i in range(int(input().split()[0])):\r\n t=input().split()\r\n if f:\r\n if 'C' in t or 'M' in t or 'Y' in t:\r\n f=False\r\nif f:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "n,m=map(int,input().split())\r\nf=True\r\nfor _ in range(n):\r\n a=input().split()\r\n if 'C'in a or 'M'in a or 'Y' in a:\r\n f=False\r\nprint([\"#Color\",\"#Black&White\"][f])", "#https://codeforces.com/problemset/problem/707/A\r\n\r\n(n, m) = (int(x) for x in input().split())\r\ncolors = ['C', 'M', 'Y']\r\nanswer = '#Black&White'\r\nwhile n > 0:\r\n line_colors = [False for x in input().split(\" \") if x in colors]\r\n if False in line_colors:\r\n answer = \"#Color\"\r\n break\r\n n -= 1\r\nprint(answer)", "n, m = map(int, input().split())\r\nspisok = [input().split() for i in range(n)]\r\n\r\nflag = True\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n\r\n if spisok[i][j] == 'C' or spisok[i][j] ==\"Y\" or spisok[i][j] == \"M\":\r\n flag = False\r\nprint(\"#Black&White\") if flag else print(\"#Color\")\r\n", "FLAG=0\r\na,b=map(int,(input().split()))\r\nfor _ in range(a):\r\n t=list(map(str,input().split()))\r\n for i in range(b):\r\n if t[i]=='C' or t[i]=='M' or t[i]=='Y':\r\n FLAG=1\r\nif FLAG==1:\r\n print('#Color')\r\nelse:\r\n print(\"#Black&White\")", "n,m=map(int,input().split())\r\nl1=[]\r\nfor i in range(n):\r\n m=map(str,input().split())\r\n for e in m:\r\n l1.append(e)\r\nif \"C\" in l1 or \"M\" in l1 or \"Y\" in l1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n,m=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n l.extend(input().split())\r\nk=l.count('W')+l.count('G')+l.count('B')\r\nif k==m*n:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')", "import math\r\nfrom sys import stdin\t\r\nfrom collections import Counter, defaultdict, deque, namedtuple\r\nfrom bisect import bisect_right, bisect_left\r\nfrom typing import List, DefaultDict\r\nfrom itertools import permutations\r\n \r\n \r\n \r\ndef readarray(typ):\r\n return list(map(typ, stdin.readline().split()))\r\n\r\n\r\ndef readint():\r\n return int(input())\r\n\r\n\r\n\r\n\r\nn, m = readarray(int)\r\n\r\nblackAndWhite = {'B', 'W', 'G'}\r\n\r\nisColor = False\r\n\r\nfor _ in range(n):\r\n row = readarray(str)\r\n\r\n for char in row:\r\n if char not in blackAndWhite:\r\n isColor = True\r\n break\r\n\r\n\r\nprint(\"#Color\" if isColor else \"#Black&White\") \r\n\r\n\r\n\r\n\r\n\r\n", "a, b = map(int, input().split())\r\ncolored=False\r\nfor i in range(a):\r\n l=[str(x) for x in input().split()]\r\n if 'C' in l:\r\n colored=True\r\n break\r\n if 'M' in l:\r\n colored=True\r\n break\r\n if 'Y' in l:\r\n colored=True\r\n break\r\nif colored:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n\r\n", "n, m = input().split()\r\ncolor = '#Black&White'\r\nfor i in range(int(n)):\r\n x = input().split()\r\n for j in range(int(m)):\r\n if x[j] != 'B' and x[j] != 'G' and x[j] != 'W':\r\n color = '#Color'\r\nprint(color)", "n=input()\r\nr=int(n.split()[0])\r\nc=int(n.split()[1])\r\nisColor=False\r\nfor i in range(0,r):\r\n\ts=input()\r\n\ts=s.split()\r\n\tfor j in range(0,c):\r\n\t\tif s[j]==\"C\" or s[j]==\"M\" or s[j]==\"Y\":\r\n\t\t\tisColor=True\r\nif isColor:\r\n\tprint(\"#Color\")\r\nelse:\r\n\tprint(\"#Black&White\")\r\n\r\n", "n,m = map(int,input().split())\r\ncolors = []\r\nfor i in range(n):\r\n i = list(map(str,input().split()))\r\n colors += i\r\nif 'C' in colors or 'M' in colors or 'Y' in colors:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "a, b = map(int, input().split())\r\nq = []\r\nc = 0\r\nfor roma in range(a):\r\n q.append(input().split())\r\nfor i in range(a):\r\n for j in range(b):\r\n if q[i][j] == 'C' or q[i][j] == 'M' or q[i][j] == 'Y':\r\n c += 1\r\nif c >= 1:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n ", "n,m = map(int,(input().split()))\r\ns=0\r\nfor i in range(n):\r\n L = list(input())\r\n for j in L:\r\n if j == 'C' or j=='M' or j=='Y' :\r\n s=s+1\r\nif s!=0:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n, m = map(int, input().split())\r\nans = 0\r\nfor i in range(n):\r\n row = list(input().split())\r\n if \"C\" in row or \"M\" in row or \"Y\" in row:\r\n ans = \"#Color\"\r\nif ans!=\"#Color\":\r\n ans = \"#Black&White\"\r\nprint(ans)", "n, m = map(int, input().split())\r\n\r\nnon_color_list = [\"W\",\"G\",\"B\"]\r\ncolor_list = [\"C\",\"M\",\"Y\"]\r\n\r\nis_colored = False\r\nfor i in range(n):\r\n pixel_color = input().split()\r\n for color in pixel_color:\r\n if color in color_list:\r\n is_colored = True\r\n\r\nif is_colored:\r\n print('#Color')\r\nelse:\r\n print(\"#Black&White\")", "a,b=map(int,input().split())\r\nr='#Black&White'\r\nfor _ in range(a) :\r\n c=list(input().split())\r\n if 'C' in c or 'M' in c or 'Y' in c:\r\n r='#Color'\r\n break\r\nprint(r)", "#Ahmed Abdelrazik\r\nn,m = map(int,input().split())\r\nk = False\r\nfor _ in range(n):\r\n L = list(map(str,input().split()))\r\n if k == False:\r\n if \"C\" in L or \"M\" in L or \"Y\" in L:\r\n k = True\r\n print(\"#Color\")\r\n break\r\n\r\nif k == False:\r\n print(\"#Black&White\")\r\n", "rows, cols = map(int, input().split())\r\nflag = 0\r\nmatrix = []\r\n\r\nfor i in range(rows):\r\n row = input()\r\n matrix.append(row)\r\n if 'C' in row or 'Y' in row or 'M' in row:\r\n flag = 1\r\n\r\nif flag == 1:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n", "n,m=map(int,input().split())\r\nz=0\r\nfor i in range(n):\r\n s=input().split(' ')\r\n if 'C' in s or 'M' in s or 'Y' in s:z+=1\r\nif z==0:print('#Black&White')\r\nelse:print('#Color')", "n,m = map(int,input().split())\r\nt = True\r\nl = list()\r\nfor i in range(n):\r\n s = list(input().split())\r\n l.append(s)\r\n if \"C\" in s or \"Y\" in s or \"M\" in s:\r\n \r\n t = False\r\nif t:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "n,m = map(int,input().split())\r\nans=0\r\nfor i in range(n):\r\n row = list(input().split())\r\n if \"C\" in row or\"M\"in row or\"Y\"in row:\r\n ans=\"#Color\"\r\nif ans!=\"#Color\":\r\n ans=\"#Black&White\"\r\nprint(ans)", "n,m = [int(_) for _ in input().split()]\r\nmylist = [input().split() for i in range(n)]\r\nmycharacters = [line[i] for i in range(m) for line in mylist]\r\nmyset = {'B','W','G'}\r\nif set(mycharacters).issubset(myset):\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "n,k=map(int,input().split())\r\ns=''\r\nfor i in range(n):\r\n\ts += input()\r\nprint('#Color '*(len(set('CMY')&set(s)) !=0) or '#Black&White')", "r, c = map(int, input().split())\r\n\r\nfor _ in range(r):\r\n l = input().split()\r\n \r\n for t in l:\r\n if t != 'W' and t != 'B' and t != 'G':\r\n print(\"#Color\")\r\n quit()\r\nprint(\"#Black&White\")", "m,n=map(int,input().split())\r\nch=0\r\nlst=[]\r\ncol=['G','B','W']\r\nfor i in range(m):\r\n lst=lst+list(input().split())\r\nfor i in lst:\r\n if i not in col:\r\n ch=1\r\n print(\"#Color\")\r\n break\r\nif ch==0:\r\n print(\"#Black&White\")", "def is_colored_photo(photo_matrix):\n colored_colors = {'C', 'M', 'Y'}\n for row in photo_matrix:\n for pixel in row:\n if pixel in colored_colors:\n return True\n return False\n\nn, m = map(int, input().split())\nphoto_matrix = [input().split() for _ in range(n)]\n\nif is_colored_photo(photo_matrix):\n print(\"#Color\")\nelse:\n print(\"#Black&White\")", "def main():\r\n n,m=map(int,input().split())\r\n c=[]\r\n s=0\r\n for i in range (n):\r\n a=list(input().split())\r\n for j in range (len(a)):\r\n c.append(a[j])\r\n for i in range (len(c)):\r\n if c[i]=='M' or c[i]=='C' or c[i]=='Y':\r\n s=1\r\n print('#Color')\r\n return\r\n if s==0:\r\n print('#Black&White')\r\nmain()\r\n \r\n \r\n\r\n \r\n", "n,m=map(int,input().split())\r\n\r\ncount=0\r\n\r\nfor _ in range(n):\r\n p=input()\r\n for i in p:\r\n if i==\"C\" or i==\"M\" or i==\"Y\":\r\n count +=1\r\n \r\nif count==0:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "n,m=map(int,input().split())\r\nc=0\r\nfor i in range(n):\r\n r=input().split()\r\n for j in range(m):\r\n s=r[j]\r\n if(s=='B' or s=='W' or s=='G'): c+=1\r\nx=n*m\r\nif c==x: print('#Black&White')\r\nelse:print('#Color')", "n,m=map(int,input().split())\r\nsaf=True;caut={'C','M','Y'}\r\nfor _ in range(n):\r\n ml=input().upper()\r\n for i in ml:\r\n if i in caut:\r\n saf=False\r\n \r\nif saf:\r\n print(\"#Black&White\")\r\nelse:\r\n print('#Color')\r\n ", "n = input().split()\r\nn, m = int(n[0]), int(n[1])\r\nmap = []\r\nfor i in range(0, n):\r\n a = input().split()\r\n map.append(a)\r\no = \"#Black&White\"\r\nfor y in range(0, n):\r\n for x in range(0, m):\r\n if map[y][x] == \"C\" or map[y][x] == \"M\" or map[y][x] == \"Y\":\r\n o = \"#Color\"\r\nprint(o)", "n,m=map(int,input().split())\r\nkey=0\r\n\r\nfor i in range(n):\r\n row=input().split()\r\n for c in row:\r\n if c=='C'or c=='Y'or c=='M':\r\n key=1\r\nif key==1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n = list(map(int, input().split()))\r\nz = []\r\ncount = 0\r\nfor i in range(0, n[0]):\r\n z.append(input().split())\r\nfor j in range(0, n[0]):\r\n for k in range(0, n[1]):\r\n if z[j][k] == \"C\" or z[j][k] == \"M\" or z[j][k] == \"Y\":\r\n count += 1\r\nif count > 0:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "# 코드포스 707A Brain's Photos\r\nimport sys\r\nput = sys.stdin.readline\r\n\r\nn, m = map(int, put().split())\r\ncolor = set()\r\n\r\nwhile n:\r\n n -= 1\r\n color.update(put().split())\r\n\r\nif {'C', 'Y', 'M'} & color:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n,m=map(int,input().split())\r\nans='#Black&White'\r\nfor i in range(n):\r\n l=input().split()\r\n if 'C' in l or 'M' in l or 'Y' in l:\r\n ans='#Color'\r\nprint(ans)", "n,m=map(int,input().strip().split())\r\nf=0\r\nfor i in range(n):\r\n li=input().strip().split()\r\n if \"C\" in li or \"M\" in li or \"Y\" in li:\r\n f=1\r\nif f==1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n \r\n\r\n\r\n", "n, m = map(int, input().split())\r\nflag = False\r\n\r\nfor _ in range(n):\r\n colors = set(input().split())\r\n for color in colors:\r\n if 'W' != color and 'B' != color and 'G' != color:\r\n flag = True\r\n break\r\n if flag:\r\n break\r\n \r\nif flag:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "n,m=map(int,input().split())\r\narr=[]\r\nfor i in range(n):\r\n input_arr=list(map(str,input().split()))\r\n arr=arr+input_arr\r\nc_ct=arr.count('C')\r\nm_ct=arr.count('M')\r\ny_ct=arr.count('Y')\r\nif c_ct != 0 or m_ct != 0 or y_ct != 0:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n \r\n \r\n \r\n \r\n", "l = [int(l) for l in input().split()] \r\nn = l[0]; m = l[1]\r\np = ''\r\nfor i in range(n): \r\n x = [str(x) for x in input().split()]\r\n for j in x: \r\n if j == 'C' or j == 'M' or j == 'Y':\r\n p = \"#Color\"\r\n print(p) \r\n break\r\n if p != '': break\r\nif p == '': \r\n print(\"#Black&White\")", "n, m = map(int, input().split())\nfor _ in range(n):\n line = input().split()\n if \"C\" in line or \"M\" in line or \"Y\" in line:\n print(\"#Color\")\n break\nelse:\n print(\"#Black&White\")\n", "m, n = map(int, input().split())\r\na = False\r\nfor i in range(m):\r\n b = input().split()\r\n if 'C' in b or 'M' in b or 'Y' in b:\r\n a = True\r\nprint('#Black&White' if a == False else '#Color')", "a,b= map(int,input().split())\r\nl=[]\r\nwhile(a!=0):\r\n x=list(map(str,input().split()))\r\n l.extend(x)\r\n a=a-1\r\n#print(l)\r\nif ('C' in l) or('M' in l) or('Y' in l):\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n ", "# brains photos\r\n\r\nn, m = map(int, input().split(' '))\r\nl = []\r\n\r\nfor i in range(n):\r\n c = input().split(' ')\r\n l.append(c)\r\n\r\nflag = True\r\n\r\nfor i in range(len(l)):\r\n for j in range(len(l[i])):\r\n if l[i][j] == 'C' or l[i][j] == 'M' or l[i][j] == 'Y':\r\n flag = False\r\n\r\nif flag == True:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')\r\n", "A = []\ndef Color (A) : \n for i in A:\n for j in i:\n if j!='B' and j!='W' and j!='G' :\n return '#Color'\n return '#Black&White'\na = list(map(int,input().split()))\nfor i in range(a[0]):\n b = list(map(str, input().split()))\n A.append(b)\nprint(Color(A))\n\t\t\t\t\t \t\t \t\t \t\t\t\t\t\t\t\t \t\t \t \t\t\t", "def is_colour(string):\r\n if \"C\" in string or \"M\" in string or \"Y\" in string:\r\n return True\r\n return False\r\n\r\nn = int(input().split()[0])\r\nstring = \"\"\r\nfor i in range(n):\r\n string += input()\r\n\r\nif is_colour(string):\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "t=[]\r\na=[int(x) for x in input().split()]\r\nx=0\r\nfor i in range(a[0]):\r\n t=input().split()\r\n x+=t.count('W')+t.count('B')+t.count('G')\r\nif x==a[0]*a[1]:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n ", "user = str(input())\r\nb = user.split()\r\nc = [int(x) for x in b]\r\n\r\nBlack = 0\r\nColored = 0\r\n\r\nfor x in range(c[0]):\r\n user_put = str(input())\r\n d = user_put.split()\r\n for x in d:\r\n if x == \"W\" or x == \"B\" or x == \"G\":\r\n Black = Black + 1\r\n else:\r\n Colored = Colored + 1\r\n\r\nif Black > 0 and Colored > 0:\r\n print(\"#Color\")\r\nelif Black == 0 and Colored > 0:\r\n print(\"#Color\")\r\nelif Black > 0 and Colored == 0:\r\n print(\"#Black&White\")", "a,b=input().split()\r\na,b=int(a),int(b)\r\nh=['C','M','Y']\r\nk=1\r\nfor i in range(a):\r\n x=[str(x) for x in input().split()]\r\n for j in h:\r\n if j in x:\r\n k=0\r\n break\r\nif k==1:\r\n print('#Black&White')\r\nelse:\r\n print('#Color')", "color: bool = False\r\nfor i in range(int(input()[0])):\r\n for c in input():\r\n if (c != 'C' and c != 'M' and c != 'Y'): continue\r\n color = True\r\n break\r\n\r\nprint(\"#Black&White\") if not color else print(\"#Color\")", "M,N = map(int,input().split())\r\ndef COLOR(M):\r\n Flag = False\r\n for _ in range(M):\r\n X = list(input().split())\r\n for i in X:\r\n if i == 'C' or i == 'M' or i == 'Y':\r\n Flag = True\r\n return \"#Black&White\" if Flag==False else \"#Color\"\r\nprint(COLOR(M))", "nm = input().split(' ')\r\nn = int(nm[0])\r\nm = int(nm[1])\r\ncount = 0\r\nfor i in range(n):\r\n colors = input().split(' ')\r\n if ('C' in colors) or ('M' in colors) or ('Y' in colors):\r\n count = 1\r\nif count==1:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')\r\n", "n,m=map(int,input().split())\r\nlist1=[]\r\nfor i in range(n):\r\n l=list(map(str,input().split()))\r\n list1.append(l)\r\nc=0\r\nfor i in list1:\r\n for j in i:\r\n if j=='C' or j=='M' or j=='Y':\r\n c=1\r\n break\r\n if c==1:\r\n break\r\nif c==1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "list2 = ['C', 'M', 'Y']\r\nn, m = map(int, input().split())\r\nfor _ in range(n):\r\n l = input()\r\n for i in l:\r\n if i in list2:\r\n print('#Color')\r\n exit()\r\n\r\n\r\nprint('#Black&White')\r\n", "a, b = [int(x) for x in input().split()]\r\nanswer = '#Black&White'\r\nfor i in range (0, a, 1):\r\n colors = input().split()\r\n if 'C' in colors:\r\n answer = '#Color'\r\n if 'M' in colors:\r\n answer = '#Color'\r\n if 'Y' in colors:\r\n answer = '#Color'\r\nprint(answer)\r\n", "l, c = map(int, input().split())\r\npic = [list(input().split()) for _ in range(l)]\r\ncolor = set((\"C\", \"M\", \"Y\"))\r\nfor i in range(l):\r\n for j in range(c):\r\n if pic[i][j] in color:\r\n print(\"#Color\")\r\n exit()\r\nelse:\r\n print(\"#Black&White\")", "from 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 n, m = multi_input()\r\n ans = \"#Black&White\"\r\n for i in range(n):\r\n s = list_input(str)\r\n b = s.count(\"B\")\r\n g = s.count(\"G\")\r\n w = s.count(\"W\")\r\n if b+g+w != m:\r\n ans = \"#Color\"\r\n print(f\"{ans}\\n\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n,m=map(int,input().split())\r\na=[input().split() for i in range(n)]\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j] in ['B', 'G', 'W']:\r\n pass\r\n else:\r\n print('#Color')\r\n exit()\r\nprint('#Black&White') ", "n, m = map(int, input().split())\r\n\r\na = []\r\ns = 0\r\n\r\nfor i in range(n):\r\n b = map(str, input().split())\r\n a.append(list(b))\r\n\r\nfor i in range(n):\r\n if s > 0:\r\n break\r\n else:\r\n for j in range(m):\r\n if s > 0:\r\n break\r\n else:\r\n if a[i][j] == 'C' or a[i][j] == 'M' or a[i][j] == 'Y':\r\n s += 1\r\n\r\nif s > 0:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "\r\ntests = list(map(int,input().split(\" \")))\r\ncolor = False\r\n\r\n\r\nfor i in range(tests[0]):\r\n reihe = list(map(str,input().split(\" \")))\r\n if \"C\" in reihe or \"M\" in reihe or \"Y\" in reihe:\r\n color = True\r\n break\r\n\r\nif color ==True:\r\n print ('#Color')\r\nelse:\r\n print ('#Black&White')", "c=0\r\nn,m=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n lst=list(map(str,input().split()))\r\n c+=lst.count(\"C\")+lst.count(\"M\")+lst.count(\"Y\")\r\nif(c>0):\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n ", "n,m=map(int,input().split())\r\nt=False\r\nfor i in range(n):\r\n j=[char for char in input().split()]\r\n if j.count('W')+j.count('B')+j.count('G')!=len(j):\r\n t=True\r\nif t:\r\n print('#Color')\r\n exit()\r\nprint('#Black&White')", "n=[int(i) for i in input().split()]; n=n[0]\na=[]\nfor i in n*[0]:\n a.extend(input().split())\nr = \"#Black&White\"\nfor i in [\"C\",\"M\",\"Y\"]:\n if i in a:\n r = \"#Color\"\n break\nprint(r)\n", "x,y=map(int,input().split())\r\nl=[]\r\nfor i in range(x): \r\n single_row = list(map(str,input().split())) \r\n l.append(single_row) \r\n# printing the matrix given by user \r\n# print(l) \r\nv=False\r\nfor i in range(0,len(l)):\r\n for j in range(0,len(l[i])):\r\n # print(l[i][j])\r\n if l[i][j]=='C' or l[i][j]==\"M\" or l[i][j]==\"Y\":\r\n v=True \r\nif v==True:\r\n print(\"#Color\") \r\nelse:\r\n print(\"#Black&White\")\r\n \r\n", "n, m = map(int, input().split())\r\n\r\ncolor = False\r\n\r\nfor i in range(n):\r\n s = input()\r\n for i in s:\r\n if i in ['C', 'M', 'Y', 'K']:\r\n color = True\r\n\r\nif color:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, m = map(int, input().split())\r\nd = \"\"\r\nfor i in range(n):\r\n ans = input().split()\r\n \r\n for j in range(len(ans)):\r\n d += ans[j]\r\ncount = 0\r\nnew = list(d)\r\nfor i in range(len(new)):\r\n if new[i] == \"C\" or new[i] == \"M\" or new[i] == \"Y\":\r\n count += 1\r\nif count > 0:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, m =(int(x) for x in input().split())\r\ni = 0\r\ncolors = ['C', 'M', 'Y']\r\ncolor_checker = False\r\nwhile i < n:\r\n\trow = [x for x in input().split()]\r\n\tfor color in colors:\r\n\t\tif color in row:\r\n\t\t\tcolor_checker = True\r\n\t\t\tbreak\r\n\tif color_checker == True:\r\n\t\tprint('#Color')\r\n\t\tbreak\r\n\ti += 1\r\nelse:\r\n\tprint('#Black&White')", "# LUOGU_RID: 101608244\nprint(set('CMY') & set(open(0).read()) and '#Color' or '#Black&White')\r\n", "number,ran = map(int,input().split())\r\nflag = 0\r\nfor i in range(number):\r\n pix = input().split()\r\n if \"C\" in pix or \"M\" in pix or \"Y\" in pix:\r\n flag+=1\r\n break\r\nif flag == 1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, m = map(int, input().split())\r\n\r\nfor i in range(n):\r\n row = input().split()\r\n for x in row:\r\n if x not in ['B', 'W', 'G']:\r\n print(\"#Color\")\r\n exit()\r\n\r\nprint(\"#Black&White\")\r\n", "n,m = map(int,input().split())\r\nflag = 0\r\nfor i in range(n):\r\n l = list((input().split()))\r\n if('C' in l or 'M' in l or 'Y' in l):\r\n flag = 1\r\n\r\n\r\nif(flag):\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")\r\n", "n,m=map(int,input().split())\r\nc = {'C':0,'M':0,'Y':0}\r\nfor i in range(n):\r\n x = input().split()\r\n for i in x:\r\n if i in c:print('#Color');exit()\r\nelse:print('#Black&White')", "tm = input().split()\r\nn, m = int(tm[0]), int(tm[1])\r\nans = 1\r\nfor i in range(n):\r\n x = input()\r\n if 'M' in x or 'Y' in x or 'C' in x:\r\n ans = 0\r\nif ans == 0:\r\n print('#Color')\r\nelse:\r\n print('#Black&White')", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Apr 6 22:04:31 2023\r\n\r\n@author: Srusty Sahoo\r\n\"\"\"\r\n\r\nn,m=map(int,input().split())\r\nres=\"#Black&White\"\r\nfor i in range(n):\r\n c=list(input().split())\r\n if \"C\" in c or \"M\" in c or \"Y\" in c:\r\n if res!=\"#Color\":\r\n res=\"#Color\"\r\n\r\nprint(res)", "n,m = map(int,input().split())\r\nl2 = []\r\nfor i in range(n):\r\n l3 = list(map(str,input().split()))\r\n l2 = l2 + l3\r\ns = \"WGB\"\r\nc = 0\r\nfor i in l2:\r\n if i in s:\r\n c = c + 1\r\nif c == len(l2):\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")", "n_m = list(map(int, input().split()))\r\nblack_and_white = True\r\n\r\nfor _ in range(n_m[0]):\r\n colors = input().split()\r\n for color in colors:\r\n if color == 'C' or color == 'M' or color == 'Y':\r\n black_and_white = False\r\n break\r\nprint(\"#Black&White\" if black_and_white else \"#Color\")\r\n", "n, m = map(int, input().split(\" \"))\r\n\r\ndef f(rows):\r\n for i in range(n):\r\n s = rows[i]\r\n if (\"C\" in s) or (\"M\" in s) or (\"Y\" in s):\r\n return \"#Color\"\r\n return \"#Black&White\"\r\n\r\n\r\nrows = []\r\nfor i in range(n):\r\n rows.append(input())\r\n\r\nprint(f(rows))", "n, m = map(int, input().split())\r\nc = False\r\nfor i in range(n):\r\n pixel_set = input().split()\r\n if 'C' in pixel_set or 'M' in pixel_set or 'Y' in pixel_set:\r\n c = True\r\nif c:\r\n print('#Color')\r\nelse:\r\n print(\"#Black&White\")", "def f(data):\r\n if \"M\" in data or \"C\" in data or \"Y\" in data:\r\n return \"#Color\"\r\n else:\r\n return \"#Black&White\"\r\n\r\n\r\n\r\n\r\nt = input()\r\nt = [int(i) for i in t.split(\" \")]\r\ndata = []\r\nfor i in range(t[0]):\r\n temp = input().split(\" \")\r\n data += temp\r\nprint(f(data))\r\n", "a, b = map(int, input().split())\r\nflag = True\r\nfor i in range(a):\r\n a = [str(x) for x in input().split()]\r\n for c in a:\r\n if c == \"C\" or c == \"M\" or c == \"Y\":\r\n flag = False\r\n break\r\nif flag == True:\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n", "n, m =[int(i) for i in input().split()]\r\nanswer = \"#Black&White\"\r\nfor i in range(n):\r\n ms = input().split()\r\n if 'C' in ms or 'M' in ms or 'Y' in ms:\r\n answer = \"#Color\"\r\n break\r\nprint(answer)", "n,m = map(int,input().split())\r\na = m\r\nBW = [\"B\",\"G\",\"W\"]\r\nColorful = [\"C\",\"M\",\"Y\"]\r\npixelsInARow = \"\"\r\nmat = []\r\nctBW = 0\r\nctC = 0\r\nfor i in range(n):\r\n pixelsInARow = input()\r\n pixelsInARow.split()\r\n mat.append(pixelsInARow)\r\n\r\nfor i in range(len(mat)):\r\n for j in range(len(mat[i])):\r\n \r\n if(mat[i][j] in BW):\r\n ctBW += 1\r\n \r\n elif(mat[i][j] in Colorful):\r\n ctC += 1\r\n\r\nif(ctC == 0):\r\n print(\"#Black&White\")\r\n \r\nelse:\r\n print(\"#Color\")\r\n ", "def main():\r\n n, m = map(int, input().split())\r\n \r\n while n:\r\n n -= 1\r\n colors = input().split()\r\n if \"Y\" in colors or \"C\" in colors or \"M\" in colors:\r\n print(\"#Color\")\r\n return\r\n \r\n print(\"#Black&White\")\r\n\r\nmain()", "n,m = map(int,input().split())\r\nmas = []\r\nfor i in range(n):\r\n a = list(map(str,input().split()))\r\n mas.append(a)\r\ns = set()\r\nfor i in range(n):\r\n for j in range(m):\r\n s.add(mas[i][j])\r\ns = list(s)\r\nif len(s) == 3:\r\n if \"W\" in s and \"B\" in s and \"G\" in s:\r\n print(\"#Black&White\")\r\n exit()\r\nif len(s) == 2:\r\n if s[0] == \"W\" and s[1] == \"B\" or s[0] == \"B\" and s[1] == \"W\" or s[0] == \"G\" and s[1] == \"B\" or s[0] == \"B\" and s[1] == \"G\"or s[0] == \"G\" and s[1] == \"W\" or s[0] == \"W\" and s[1] == \"G\":\r\n print('#Black&White')\r\n exit()\r\nif len(s) == 1:\r\n if s[0] == \"W\" or s[0] == \"B\" or s[0] == \"G\":\r\n print('#Black&White')\r\n exit()\r\nprint('#Color')", "n,m=map(int,input().split())\r\na=\"\".join(input()for i in range(n))\r\nif \"C\" in a or \"M\" in a or \"Y\" in a:print(\"#Color\")\r\nelse:print(\"#Black&White\")\r\n \r\n", "[n, m] = (map(int, input().split()))\n\nans = \"#Black&White\"\n\n\nfor i in range(n):\n line = list(input().split())\n for color in line:\n if color in [\"C\",\"M\",\"Y\"]:\n ans = \"#Color\"\n\nprint(ans)\n", "a,b=list(map(int,input().split()))\r\nc1=0\r\nc=0\r\nfor i in range(a) :\r\n s=list(input().split()) \r\n for i in s:\r\n if s.count(\"C\")==0 and s.count(\"M\") ==0 and s.count(\"Y\")==0:\r\n c1+=1\r\n else:\r\n c+=1\r\nif c1>0 and c==0: \r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n ", "n,m=map(int,input().split())\r\nl,l1=[],[]\r\nfor i in range (n):\r\n l1=list(input().split())\r\n l.extend(l1)\r\nc=['C','M','Y']\r\nfound= False\r\nfor char in c:\r\n if char in l:\r\n found=True\r\n break\r\nif found==True:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n, m = map(int, input().split())\r\nans = \"\"\r\nfor i in range(n):\r\n ans += input()\r\nfor i in \"CMY\":\r\n if i in ans:\r\n print(\"#Color\")\r\n break\r\nelse:\r\n print(\"#Black&White\")", "t=0\r\nm,n=input().split(\" \")\r\nx=[]\r\nfor i in range (int(m)):\r\n m=input().split(\" \")\r\n x=m\r\n if x.count('C') or x.count('M') or x.count('Y'):\r\n t=1\r\n break\r\nif t:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "n,m = map(int,input().split())\r\nfor _ in range(n):\r\n s = input()\r\n if s.find('C') != -1 or s.find('Y') != -1 or s.find('M') != -1:\r\n print('#Color')\r\n break\r\nelse:\r\n print('#Black&White')\r\n ", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Jul 25 10:55:27 2022\r\n\r\n@author: Conor\r\n\r\nCFSheet A Problem 55 - CF707-DIV2A\r\n\"\"\"\r\n\r\nsafe = [\"B\", \"G\", \"W\"]\r\nrows, sz = map(int,input().split())\r\ncolorFlag = 0\r\n\r\nfor i in range(rows):\r\n newRow = list(map(str,input().split()))\r\n for j in range(len(newRow)):\r\n if newRow[j] not in safe:\r\n colorFlag = 1\r\n if colorFlag == 1:\r\n break\r\nif colorFlag == 1:\r\n print(\"#Color\")\r\nelse:\r\n print(\"#Black&White\")", "a,b = map(int, input().split())\r\nd = \"\"\r\nfor i in range(a):\r\n c = [str(q) for q in input().split()]\r\n if \"C\" in c or \"M\" in c or \"Y\" in c:\r\n d = \"#Color\"\r\n break\r\n else:\r\n d = \"#Black&White\"\r\nprint(d)", "# C, M, Y, W, G, B \r\nn, m = list(map(int, input().split()))\r\nColor_dict = {\"W\" : 0, \"G\" : 0, \"B\" : 0, \"C\" : 0, \"M\" : 0, \"Y\" : 0}\r\n\r\nfor i in range(0, n):\r\n columns = list(map(str, input().split()))\r\n for i in columns:\r\n if (i in Color_dict.keys()):\r\n Color_dict[i] += 1\r\nif (Color_dict[\"W\"] + Color_dict[\"G\"] + Color_dict[\"B\"] == (n * m)):\r\n print(\"#Black&White\")\r\nelse:\r\n print(\"#Color\")\r\n\r\n", "m,n=map(int,input().split())\r\nf=0\r\nfor i in range(m):\r\n l=input().split()\r\n if 'C' in l or 'M' in l or 'Y' in l:\r\n f=1\r\n print('#Color')\r\n break\r\nif f==0:print('#Black&White')", "n, m = map(int, input().split())\r\nflag = True\r\nfor i in range(n):\r\n data = input().split()\r\n if flag:\r\n for el in data:\r\n if el != 'G' and el != 'B' and el != 'W':\r\n print('#Color')\r\n flag = False\r\n break\r\nif flag:\r\n print('#Black&White')\r\n\r\n", "m = [int(i) for i in input().split()][0]\npixels = []\nfor i in range(m):\n row = input().split()\n for pixel in row:\n pixels.append(pixel)\n\nif set(pixels).isdisjoint(['C', 'Y', 'M']):\n print(\"#Black&White\")\nelse:\n print(\"#Color\")\n", "n,m = map(int , input().split())\r\ncolored = ['C', 'M', 'Y']\r\noutput=\"#Black&White\"\r\npixels = []\r\nfor i in range (n):\r\n pixels.append([p for p in input().split()])\r\n\r\nfor row in pixels:\r\n for p in row:\r\n if p in colored:\r\n output = \"#Color\"\r\nprint(output)", "c = \"#Black&White\"\r\na,b=map(int,input().split())\r\nfor i in range(a):\r\n r = input()\r\n if 'C' in r or 'M' in r or 'Y' in r:\r\n c = \"#Color\"\r\n \r\nprint(c)\r\n", "print('#Color' if set(open(0).read()) & set('CMY') else '#Black&White')", "for i in range(list(map(int,input().split()))[0]):\r\n l =input().split()\r\n if any(list(map(lambda x :x in l,[\"Y\",\"M\",\"C\"]))):\r\n print(\"#Color\")\r\n exit()\r\nprint(\"#Black&White\")", "n,x=map(int,input().split())\r\nc=0\r\nl=[]\r\nf=0\r\nfor i in range(n):\r\n a=input().split()\r\n l.append(a)\r\nfor i in range(n):\r\n for j in range(x):\r\n if l[i][j] =='C' or l[i][j] =='M'or l[i][j] =='Y' :\r\n print('#Color')\r\n c+=1\r\n f+=1\r\n break\r\n if(f):\r\n break\r\n \r\nif(c==0):\r\n print('#Black&White')\r\n ", "#BrainPhotos\r\n\r\n\r\nn,m = map(int,input().split())\r\n\r\nphotos = []\r\ngate = False\r\nfor _ in range(n):\r\n\r\n\tvalue = list(map(str,input().split()))\r\n\tphotos.append(value)\r\n\r\nfor num in range(n):\r\n\tfor num1 in range(m):\t\r\n\r\n\t\tif(photos[num][num1] == \"C\") or (photos[num][num1] == \"Y\") or (photos[num][num1] == \"M\"):\r\n\t\t\tgate = True\r\n\r\nif(gate):\r\n\tprint(\"#Color\")\r\nelse:\r\n\tprint(\"#Black&White\")\r\n\r\n\r\n\r\n\r\n", "v,v1=map(int,input().split());c=[]\r\nfor i in range(v):\r\n v2=input().split();c.append(v2)\r\nfor i in c:\r\n if \"C\"in i or \"M\" in i or \"Y\" in i:print(\"#Color\");break\r\nelse:print(\"#Black&White\")", "h, w = map(int, input().split())\r\nf = True\r\ny = [\"C\", \"M\", \"Y\"]\r\nfor _ in range(h):\r\n x = input().split()\r\n for i in y:\r\n if i in x and f:\r\n f = False\r\n break\r\nprint(\"#Black&White\") if f else print(\"#Color\")\r\n" ]
{"inputs": ["2 2\nC M\nY Y", "3 2\nW W\nW W\nB B", "1 1\nW", "2 3\nW W W\nB G Y", "1 1\nW", "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B", "1 6\nC M Y W G B", "1 3\nW G B", "1 1\nW", "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B", "2 3\nW W W\nB G C", "2 3\nW W W\nB G M", "3 3\nC B W\nB Y M\nB B W", "1 3\nW C W", "3 3\nB W B\nB C W\nB W W", "1 2\nW Y", "1 1\nG", "1 3\nB G W", "2 2\nW W\nB C", "1 1\nM", "1 2\nW C", "2 3\nW W M\nW W M", "3 2\nW W\nW W\nB C", "2 3\nW W C\nW W W", "1 3\nG G G", "1 1\nC", "1 2\nC W", "1 3\nW W C", "2 2\nW B\nB G", "2 2\nB B\nY Y", "2 2\nG G\nC C", "1 2\nB C", "1 4\nG G G C", "1 1\nB", "2 1\nY\nB"], "outputs": ["#Color", "#Black&White", "#Black&White", "#Color", "#Black&White", "#Color", "#Color", "#Black&White", "#Black&White", "#Black&White", "#Color", "#Color", "#Color", "#Color", "#Color", "#Color", "#Black&White", "#Black&White", "#Color", "#Color", "#Color", "#Color", "#Color", "#Color", "#Black&White", "#Color", "#Color", "#Color", "#Black&White", "#Color", "#Color", "#Color", "#Color", "#Black&White", "#Color"]}
UNKNOWN
PYTHON3
CODEFORCES
531
16830fb49b20765e78781cea4be2a97f
The Contest
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place! This contest consists of *n* problems, and Pasha solves *i*th problem in *a**i* time units (his solutions are always correct). At any moment of time he can be thinking about a solution to only one of the problems (that is, he cannot be solving two problems at the same time). The time Pasha spends to send his solutions is negligible. Pasha can send any number of solutions at the same moment. Unfortunately, there are too many participants, and the website is not always working. Pasha received the information that the website will be working only during *m* time periods, *j*th period is represented by its starting moment *l**j* and ending moment *r**j*. Of course, Pasha can send his solution only when the website is working. In other words, Pasha can send his solution at some moment *T* iff there exists a period *x* such that *l**x*<=≤<=*T*<=≤<=*r**x*. Pasha wants to know his best possible result. We need to tell him the minimal moment of time by which he is able to have solutions to all problems submitted, if he acts optimally, or say that it's impossible no matter how Pasha solves the problems. The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=105) — the time Pasha needs to solve *i*th problem. The third line contains one integer *m* (0<=≤<=*m*<=≤<=1000) — the number of periods of time when the website is working. Next *m* lines represent these periods. *j*th line contains two numbers *l**j* and *r**j* (1<=≤<=*l**j*<=&lt;<=*r**j*<=≤<=105) — the starting and the ending moment of *j*th period. It is guaranteed that the periods are not intersecting and are given in chronological order, so for every *j*<=&gt;<=1 the condition *l**j*<=&gt;<=*r**j*<=-<=1 is met. If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted. Otherwise print "-1" (without brackets). Sample Input 2 3 4 2 1 4 7 9 1 5 1 1 4 1 5 1 1 5 Sample Output 7 -1 5
[ "import sys \r\n#import re\r\n#sys.stdin=open('.in','r')\r\n#sys.stdout=open('.out','w')\r\n#import math \r\n#import random\r\n#import time\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\nn=inp()\r\na=inara()\r\ntot=sum(a)\r\nm=inp()\r\nfor i in range(m):\r\n\tl,r=invr()\r\n\tif l<=tot and r>=tot:\r\n\t\tprint(tot)\r\n\t\texit(0)\r\n\telif l>tot:\r\n\t\tprint(l)\r\n\t\texit(0)\r\nprint(-1)\r\n", "class Object(object):\n pass\n\ndef read_input():\n result = Object()\n n = int(input())\n result.times = list(map(int, input().split()))\n m = int(input())\n periods = list()\n for i in range(0, m):\n periods.append(list(map(int, input().split())))\n result.periods = periods\n return result\n\ndef find_submition_time(times, periods):\n total_time = sum(times)\n result = -1\n for period in periods:\n if total_time in range(period[0], period[1]+1):\n return total_time\n if period[0] >= total_time:\n if result == -1:\n result = period[0]\n else:\n result = min(result, period[0])\n return result\n\nresult = read_input()\nprint(find_submition_time(result.times, result.periods))\n", "def solve():\n\tstrInput = input()\n\tn = int(strInput)\n\tstrInput = input()\n\ttimes = strInput.split()\n\ttotalSolvingTime = 0\n\tfor s in times:\n\t\ttotalSolvingTime += int(s)\n\n\tstrInput = input()\n\tm = int(strInput)\n\tfor i in range(m):\n\t\tfullRange = input()\n\t\tboundaries = fullRange.split()\n\t\tif totalSolvingTime > int(boundaries[1]):\n\t\t\tcontinue\n\t\telse:\n\t\t\tleft = int(boundaries[0])\n\t\t\tif left >= totalSolvingTime:\n\t\t\t\treturn left\n\t\t\telse:\n\t\t\t\treturn totalSolvingTime\n\treturn -1\n\nprint(solve())\n\n", "n = int(input())\n\na = list(map(int, input().split()))\n\ntotal = sum(a)\n\nm = int(input())\n\nearliest = 10**6\n\nfor _ in range(m):\n l, r = map(int, input().split())\n \n if l<=total<=r:\n earliest = total\n elif total<l:\n earliest = min(earliest, l)\n \nif earliest == 10**6:\n print(-1)\nelse:\n print(earliest)\n", "##n = int(input())\r\n##a = list(map(int, input().split()))\r\n##print(' '.join(map(str, res)))\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\ntot = 0\r\nfor e in a:\r\n tot += e\r\n\r\nm = int(input())\r\nfor i in range(m):\r\n [l , r] = list(map(int, input().split()))\r\n if l <= tot and tot <= r:\r\n print(tot)\r\n exit(0)\r\n elif tot < l:\r\n print(l)\r\n exit(0)\r\nprint('-1')\r\n", "I = lambda: map(int, input().split())\r\n\r\nI()\r\nt = sum(I())\r\n\r\nfor _ in range(int(input())):\r\n L, R = I()\r\n if t <= R:\r\n print(max(L,t))\r\n break\r\nelse:\r\n print(-1)", "n = int(input())\r\nai = list(map(int,input().split()))\r\nq = int(input())\r\ndur = []\r\nfor i in range(q):\r\n l,r = map(int,input().split())\r\n if sum(ai) <= r:\r\n print(max(sum(ai), l))\r\n exit(0)\r\nprint(-1)\r\n", "numProb = int(input())\nnumLen = 0\ninp = input().split(\" \")\nfor i in range(len(inp)):\n numLen += int(inp[i])\nnumInt = int(input())\nprt = False\nfor i in range(numInt):\n inp = input().split(\" \")\n beg = int(inp[0])\n end = int(inp[1])\n if numLen >= beg and numLen <= end:\n print(numLen)\n prt = True\n break\n elif beg >= numLen:\n print(beg)\n prt = True\n break\nif prt == False:\n print(-1)\n \n \n \n\n\n", "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 n = int(input())\r\n arr1 = list(map(int, input().split()))\r\n m = int(input())\r\n sm = sum(arr1)\r\n ans = -1\r\n for i in range(m):\r\n a, b = map(int, input().split())\r\n if a<=sm and sm<=b:\r\n ans = sm\r\n if ans == -1 and a > sm:\r\n ans = a\r\n print(ans)\r\n ", "# cook your dish here\r\nn=input()\r\nl=[int(x) for x in input().split()]\r\ns=sum(l)\r\nm=int(input())\r\nans=-1\r\nfor _ in range(m):\r\n (a,b)=input().split()\r\n (a,b)=(int(a),int(b))\r\n if s<=b and ans==-1:\r\n ans=max(a,s)\r\nprint(ans)", "n = int(input())\r\na = list(map(int, input().split()))\r\nm = int(input())\r\nb = [0]\r\nprev_r = 0\r\nfor i in range(m):\r\n l, r = map(int, input().split())\r\n b = b + (l - prev_r - 1) * [0]\r\n b = b + (r - l + 1) * [1]\r\n prev_r = r\r\ns = sum(a)\r\nfor i in range(s, len(b)):\r\n if b[i] == 1:\r\n print(i)\r\n exit()\r\nprint(-1)\r\n", "n = int(input())\r\nsolve_time = sum([int(i) for i in input().split()])\r\nresult = float(\"inf\")\r\nflag = False\r\nfor _ in range(int(input())):\r\n start, end = [int(i) for i in input().split()]\r\n if result >= start >= solve_time:\r\n result = start\r\n flag = True\r\n elif end >= solve_time >= start:\r\n result = solve_time\r\n flag = True\r\n\r\nif flag: print(result)\r\nelse: print(-1)", "import sys\r\n\r\nn = int(input())\r\nt = sum(map(int, input().split()))\r\n\r\ninf = 10**9\r\nans = inf\r\nfor _ in range(int(input())):\r\n l, r = map(int, input().split())\r\n if t <= r:\r\n ans = min(ans, max(l, t))\r\n\r\nprint(ans if ans != inf else -1)\r\n", "n = int(input())\r\nlast = sum(map(int, input().split()))\r\nm = int(input())\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n if last <= b:\r\n print(max(last, a))\r\n exit(0)\r\nprint(-1)", "if __name__ == '__main__':\r\n n = int(input())\r\n s = sum([int(i) for i in input().split()])\r\n m = int(input())\r\n ans = -1\r\n\r\n while m > 0:\r\n l, r = map(int, input().split())\r\n\r\n if max(l, s) == min(s, r):\r\n ans = s\r\n break\r\n if max(l, s) == l:\r\n ans = l\r\n break\r\n m -= 1\r\n print(ans)", "import sys, bisect, collections, heapq, functools, math\r\ninput = sys.stdin.readline\r\n\r\nrs = lambda: input().strip()\r\nri = lambda: int(input())\r\nrmi = lambda: map(int, input().split())\r\nra = lambda: [int(x) for x in input().split()]\r\n \r\nINF = 10**18\r\nMOD = 10**9 + 7\r\n\r\ndef solve():\r\n S = sum(A)\r\n for x, y in I:\r\n if x <= S <= y:\r\n return S\r\n elif S < x:\r\n return x\r\n return -1\r\n \r\ntest_case = 1\r\nfor _ in range(test_case):\r\n n = ri()\r\n A = ra()\r\n m = ri()\r\n I = []\r\n for _ in range(m):\r\n x,y = rmi()\r\n I.append([x,y])\r\n print(solve())\r\n\r\n \r\n \r\n ", "n=int(input())\r\na=list(map(int,input().split()))\r\nc=sum(a)\r\nf=0\r\nb=int(input())\r\nfor i in range(b):\r\n\tx,y=list(map(int,input().split()))\r\n\tif(c>=x and c<=y and f==0):\r\n\t\tprint(c)\r\n\t\tf=1\r\n\telif(c<=x and c<=y and f==0):\r\n\t\tprint(x)\r\n\t\tf=1\r\n \r\nif(f==0):\r\n\tprint(-1)", "I=lambda: map(int, input().split())\r\nI()\r\nn, a=sum(I()), -1\r\nfor _ in range(*I()):\r\n\tl, r=I()\r\n\tif n<=r:\r\n\t\ta=max(n, l)\r\n\t\tbreak\r\nprint(a)", "R=lambda:list(map(int,input().strip().split()))\r\nn=int(input())\r\na=R()\r\ntot=sum(a)\r\nm=int(input())\r\nres=-1\r\nfor i in range(m):\r\n [l,r]=R()\r\n if r>=tot:\r\n res=max(l,tot)\r\n break\r\nprint(res)\r\n", "# -*- coding: utf-8 -*-\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nm = int(input())\r\na = sum(a)\r\nfor _ in range(m):\r\n l, r = map(int, input().split())\r\n if a <= r:\r\n print(max(a, l))\r\n exit(0)\r\n\r\nprint(-1)\r\n", "\r\nn = int(input())\r\nl = list(map(int,input().strip().split(' ')))\r\nans = sum(l)\r\nt = int(input())\r\np = -1\r\nflag = True\r\nfor _ in range(t):\r\n l,h = list(map(int,input().strip().split(' ')))\r\n if l<= ans and ans<=h and flag:\r\n p = ans\r\n flag = False\r\n if ans <l and flag :\r\n p = l\r\n flag = False\r\nprint(p)\r\n", "n = int(input())\ns = sum(list(map(int, input().split())))\nm = int(input())\nfor i in range(m):\n\tl, r = map(int, input().split())\n\ts = max(s, l)\n\tif l <= s <= r:\n\t\tprint(s)\n\t\texit(0)\nprint(-1)\n\n\n\n", "n = int(input())\r\ns = sum(map(int, input().split()))\r\nm = int(input())\r\nst = False\r\nfor i in range(m):\r\n l, r = map(int, input().split())\r\n if s <= r:\r\n print(max(l, s))\r\n st = True\r\n break\r\nif not st:\r\n print(-1)", "n = int(input())\r\n\r\na = sum(map(int, input().split()))\r\n\r\nm = int(input())\r\n\r\nanswer = -1\r\n\r\nfor i in range(m):\r\n start, end = map(int, input().split())\r\n if a < start:\r\n answer = start\r\n break\r\n if start <= a <= end:\r\n answer = a\r\n break\r\n\r\nprint(answer)\r\n", "n = int(input())\nt = sum(map(int, input().split()))\nm = int(input())\npossible = False\nbest = 1000000000\nfor i in range(m):\n l,r = map(int, input().split())\n if l <= t <= r:\n possible = True\n if l >= t:\n best = min(best, l)\nif possible:\n print(t)\nelif best < 1000000000:\n print(best)\nelse:\n print(-1)\n", "# IAWT\r\nn = int(input())\r\nps = list(map(int, input().split()))\r\nm = int(input())\r\ndurs = [list(map(int, input().split())) for i in range(m)]\r\ns = sum(ps)\r\ndef f():\r\n for i in range(m):\r\n if durs[i][0] > s:\r\n return durs[i][0]\r\n if durs[i][1] >= s:\r\n return s\r\n return -1\r\nprint(f())\r\n\r\n", "i=int(input())\r\nx=[int(i) for i in input().split()]\r\ntotal_time=0\r\nfor p in x:\r\n\ttotal_time+=p\r\nz=int(input())\r\nflag=0\r\nfor mrinal in range(z):\r\n\ta,b=map(int,input().split())\r\n\tif a<=total_time and b>=total_time:\r\n\t\tflag=total_time\r\n\t\tbreak\r\n\telif total_time<a:\r\n\t\tflag=a\r\n\t\tbreak\r\nif flag!=0:\r\n\tprint(flag)\r\nelse:\r\n\tprint(-1)", "n = int(input())\r\na = list(map(int, input().split()))\r\nm = int(input())\r\np = []\r\nfor i in range(m):\r\n l,r = map(int, input().split())\r\n p.append((l, r))\r\nrs = sum(a)\r\nfor i in range(len(p)):\r\n if p[i][0] <= rs <= p[i][1]:\r\n print(rs)\r\n exit(0)\r\n if p[i][0] > rs:\r\n print(p[i][0])\r\n exit(0)\r\nprint(-1)", "n = int(input())\r\narr = list(map(int, input().split()))\r\ns = sum(arr)\r\nn = int(input())\r\nx = 0\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n if(a>=s and x==0):\r\n x = a\r\n break\r\n elif(b>=s and x==0):\r\n x = min(s, b)\r\n break\r\nif(x>=s):\r\n print(x)\r\nelse:\r\n print(-1)\r\n", "n=int(input())\na=list(map(int,input().split()))\n\nm=int(input())\n\nb=[]\nfor i in range(m):\n l,r=map(int,input().split())\n b.append([l,r])\n\nsuma=sum(a)\nrj=0\nfor i in b:\n if i[0]<=suma and i[1]>=suma:\n rj=suma\n break\n\nif rj!=0:\n print(rj)\n\nelse:\n rj=-1\n for i in b:\n if i[0]>=suma:\n rj=i[0]\n break\n print(rj)\n\n\t \t\t\t \t \t\t\t\t \t \t \t \t\t\t \t", "\nn, m = 0, 0\ntasks = []\nperiods = []\n\ndef getInput():\n\tglobal n, tasks, periods, m\n\tn = int(input())\n\ttasks = [int(x) for x in input().split()]\n\tm = int(input())\n\tfor i in range(m):\n\t\tperiods.append( [int(x) for x in input().split()])\n\ndef getListSum(l):\n\tsum = 0\n\tfor i in l:\n\t\tsum = sum + i\n\treturn sum\n\ndef defineInterval(sum, periods):\n\tfor interval in periods:\n\t\tl, r = interval[0], interval[1]\n\t\tif sum <= l:\n\t\t\treturn l\n\t\tif l <= sum <= r:\n\t\t\treturn sum\n\treturn -1\n\ndef main():\n\tglobal n, tasks, periods\n\tgetInput()\n\tsum = getListSum(tasks)\n\tprint(defineInterval(sum, periods))\n\t\nif __name__ == '__main__':\n\tmain()\n", "n = int(input())\n\ntime = sum(map(int, input().split()))\n\nm = int(input())\n\nresult = -1\n\nfor _ in range(m):\n l, r = map(int, input().split())\n if time <= r:\n result = max([time, l])\n break\n\nprint(result)\n", "n = int(input())\r\na = [int(i) for i in input().split()]\r\nm = int(input())\r\nl = []\r\nfor i in range(m):\r\n\tk = [int(i) for i in input().split()]\r\n\tl.append((k[0],k[1]))\r\ns = sum(a)\r\nfor i in l:\r\n\tif (s<=i[1]):\r\n\t\tif(s<=i[0]):\r\n\t\t\tprint(i[0])\r\n\t\t\tbreak\r\n\t\telse:\r\n\t\t\tprint(s)\r\n\t\t\tbreak\r\nelse: print(-1)\r\n", "input()\r\ns = sum(map(int, input().split()))\r\nm = int(input())\r\n\r\nans = -1\r\nfor _ in range(m):\r\n l, r = map(int, input().split())\r\n if l >= s:\r\n ans = l\r\n break\r\n if r >= s:\r\n ans = s\r\n break\r\n\r\nprint(ans)\r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\ns=sum(l)\r\nq=int(input())\r\nl=[]\r\nfor i in range(q):\r\n\tl.append(list(map(int,input().split())))\r\nans= int(1e6)\r\nfor i in l:\r\n\tif s<=i[0]:\r\n\t\tans=min(ans,i[0])\r\n\telif i[0]<=s<=i[1]:\r\n\t\tans=min(ans,s)\r\nif ans>100000:\r\n\tans=-1\r\nprint(ans)\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\ns = sum(a)\r\nm = int(input())\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n if a <= s <= b:\r\n print(s)\r\n exit()\r\n elif s <= a:\r\n print(a)\r\n exit()\r\n\r\nprint(-1)", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\ns = sum(a)\r\nm = int(input())\r\nlr = [list(map(int, input().split())) for _ in range(m)]\r\nans = -1\r\nfor l, r in lr:\r\n if l <= s <= r:\r\n ans = s\r\n break\r\n elif s < l:\r\n ans = l\r\n break\r\nprint(ans)", "n=int(input())\r\ns=sum(list(map(int,input().split())))\r\nm=int(input())\r\nlz=[]\r\nfor i in range(m):\r\n l,r=map(int,input().split())\r\n lz.append([l,r])\r\nfor i in lz:\r\n l,r=i[0],i[1]\r\n if s>r:\r\n continue\r\n elif l<=s<=r:\r\n print(s)\r\n break\r\n else:\r\n print(l)\r\n break\r\nelse:\r\n print(-1)", "#import sys\r\n#sys.stdin = open('input.txt')\r\n\r\nn = int(input())\r\ntime = sum(list(map(int, input().split())))\r\nm = int(input())\r\nfin_time = -1\r\nfor i in range(m):\r\n\tlj, rj = map(int, input().split())\r\n\tif time <= rj:\r\n\t\tif time < lj:\r\n\t\t\tfin_time = lj\r\n\t\t\tbreak\r\n\t\telse:\r\n\t\t\tfin_time = time\r\n\t\t\tbreak\r\nprint(fin_time)", "n = int(input())\r\nst = sum(map(int, input().split()))\r\nm = int(input())\r\nfor _ in range(m):\r\n a, b = map(int, input().split())\r\n if st < a:\r\n print(a)\r\n break\r\n elif st <= b:\r\n print(st)\r\n break\r\nelse:\r\n print('-1')\r\n\r\n", "def solve(n,a,m,dur):\r\n tot = sum(a)\r\n for l,r in sorted(dur):\r\n if l<=tot and tot<=r:\r\n return tot\r\n elif tot < l:\r\n return l\r\n\r\n return -1\r\n\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n a = [int(x) for x in input().split(' ')]\r\n\r\n m = int(input())\r\n dur = []\r\n for i in range(m):\r\n dur.append(tuple(map(int,input().split(' '))))\r\n\r\n print(solve(n,a,m,dur))\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n = int(input())\r\nsm = 0\r\nfor i in input().split(): sm += int(i)\r\nm = int(input())\r\nfor i in range(m):\r\n\t(a,b) = (int(j) for j in input().split())\r\n\tif sm<=b:\r\n\t\tif sm>=a:\r\n\t\t\tprint(sm)\r\n\t\telse:\r\n\t\t\tprint(a)\r\n\t\tsm = -1\r\n\t\tbreak\r\nif sm!=-1:\r\n\tprint('-1')", "arri = lambda: [int(s) for s in input().split()]\r\nn = int(input())\r\na = arri()\r\nm = int(input())\r\nt = []\r\nfor i in range(m):\r\n t.append(arri())\r\ns = sum(a)\r\ntx = -1\r\nfor i in t:\r\n if s >= i[0] and s <= i[1]:\r\n tx = s\r\n break\r\n elif s <= i[0]:\r\n tx = i[0]\r\n break\r\nprint(tx)", "import sys\r\ninput=sys.stdin.readline\r\nfrom collections import defaultdict as dc\r\nfrom collections import Counter\r\nfrom bisect import bisect_right, bisect_left,bisect\r\nimport math\r\nfrom operator import itemgetter\r\nfrom heapq import heapify, heappop, heappush\r\nfrom queue import PriorityQueue as pq\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nm=int(input())\r\ns=sum(l)\r\nf=0\r\na=-1\r\nfor _ in range(m):\r\n x,y=map(int,input().split())\r\n if f==0:\r\n if y>=s:\r\n if s>=x:\r\n a=s\r\n else:\r\n a=x\r\n f=1\r\nprint(a)", "n = int(input())\r\na = list(map(int, input().split()))\r\nm = int(input())\r\n\r\nif m == 0:\r\n print(-1)\r\n exit()\r\n\r\ns = sum(a)\r\nr = 0\r\n\r\nfor i in range(m):\r\n inp = list(map(int, input().split()))\r\n if inp[0] <= s <= inp[1]:\r\n print(s)\r\n exit()\r\n elif r <= s <= inp[1]:\r\n print(inp[0])\r\n exit()\r\n else:\r\n r = inp[1]\r\n\r\nif s > r:\r\n print(-1)\r\n", "def main():\r\n n = int(input())\r\n a = [int(s) for s in input().split()]\r\n m = int(input())\r\n \r\n if m == 0:\r\n print(-1)\r\n return\r\n \r\n l, r = [], []\r\n for _ in range(m):\r\n x, y = [int(s) for s in input().split()]\r\n l.append(x)\r\n r.append(y)\r\n\r\n total_time = sum(a)\r\n period = 0\r\n while period < m and total_time > r[period]:\r\n period += 1\r\n if period < m:\r\n print(max(total_time, l[period]))\r\n else:\r\n print(-1)\r\n\r\nmain()\r\n", "#!/usr/bin/pypy3\n\nfrom sys import stdin,stderr\n\ndef readInts(): return map(int,stdin.readline().strip().split())\ndef print_err(*args,**kwargs): print(*args,file=stderr,**kwargs)\n \ndef solve(vs):\n return None\n\ndef run():\n n, = readInts()\n a = readInts()\n m, = readInts()\n time_all = sum(a)\n printed = False\n for _ in range(m):\n lj,rj = readInts()\n if printed: continue\n if time_all <= lj:\n print(lj)\n printed = True\n elif time_all <= rj:\n print(time_all)\n printed = True\n if not printed: print(-1)\n \nrun()\n", "n = int(input())\r\na = list(map(int, input().split()))\r\nm = int(input())\r\nsub = [0]*100000\r\nfor _ in range(m):\r\n l, r = map(int, input().split())\r\n l -= 1; r -= 1\r\n for i in range(l, r+1): sub[i] = 1\r\nlast = sum(a)\r\nans = -1\r\nfor i in range(last-1, 100000):\r\n if sub[i]:\r\n ans = i+1\r\n break\r\nprint(ans) ", "import sys\r\n\r\n_ = input()\r\nt = sum(map(int, input().split()))\r\n\r\nfor _ in range(int(input())):\r\n l, r = map(int, input().split())\r\n if t <= r:\r\n print(max(l, t))\r\n sys.exit()\r\n\r\nprint(-1)", "def main():\r\n n = int(input())\r\n s = sum(int(c) for c in input().split())\r\n\r\n m = int(input())\r\n for _ in range(m):\r\n l, r = map(int, input().split())\r\n if l <= s <= r:\r\n print(s)\r\n return\r\n elif s < l:\r\n print(l)\r\n return\r\n\r\n print(-1)\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n = int(input())\nl = list(map(int, input().split()))\ns = sum(l)\nk = int(input())\nfor i in range(k):\n\tl, r = map(int, input().split())\n\tif l <= s <= r:\n\t\tprint(s)\n\t\tbreak\n\telif l > s:\n\t\tprint(l)\n\t\tbreak\nelse:\n\tprint(-1)\n", "a = 0\nc = input()\nfor x in list(map(int,input().split())):\n\ta += x\nb = []\nfor x in range(int(input())):\n\ti,j = map(int,input().split())\n\tfor y in range(i, j + 1):\n\t\tb.append(y)\nfor x in b:\n\tif a == x or a < x:\n\t\tprint(x)\n\t\tbreak\nelse:\n\tprint(-1)", "n = int(input())\n\narr = list(map(int,input().split()))\n\nm = int(input())\n\ntimeStamps = []\n\nfor _ in range(m):\n s, e = map(int, input().split())\n\n timeStamps.append((s,e))\n\ntot = sum(arr)\n\nfound = False\n\nfor t in timeStamps:\n s, e = t[0], t[1]\n\n if tot < s:\n print(s)\n found = True\n break\n\n if tot >= s and tot <= e:\n print(tot)\n found = True\n break\n\nif not found:\n print(-1)\n\n\n", "n = int(input())\r\nl1 = list(map(int, input().split()))\r\nm = int(input())\r\nl2 = []\r\n\r\nfor i in range(m):\r\n l2.append(list(map(int, input().split())))\r\n\r\nt = sum(l1)\r\nx = -1\r\n\r\nfor i in range(len(l2)):\r\n if l2[i][-1] >= t:\r\n x = max(l2[i][0], t)\r\n break\r\n\r\nprint(x)", "n = int(input())\r\na = list(map(int, input().split()))\r\nsum_a = sum(a)\r\n\r\nm = int(input())\r\nfor _ in range(m):\r\n l, r = map(int, input().split())\r\n if r < sum_a:\r\n continue\r\n print(max(sum_a, l))\r\n exit()\r\nprint(-1)\r\n", "import sys\r\nimport math\r\nimport bisect\r\n\r\ndef main():\r\n n = int(input())\r\n A = list(map(int, input().split()))\r\n val = sum(A)\r\n m = int(input())\r\n ans = -1\r\n for i in range(m):\r\n l, r = map(int, input().split())\r\n if val >= l and val <= r:\r\n ans = val\r\n break\r\n elif l > val:\r\n ans = l\r\n break\r\n print(ans)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n=int(input())\na=list(map(int,input().split()))\nc=sum(a)\nf=0\nb=int(input())\nfor i in range(b):\n\tx,y=list(map(int,input().split()))\n\tif(c>=x and c<=y and f==0):\n\t\tprint(c)\n\t\tf=1\n\telif(c<=x and c<=y and f==0):\n\t\tprint(x)\n\t\tf=1\n\nif(f==0):\n\tprint(-1)\n", "# http://codeforces.com/problemset/problem/813/A\r\nn = int(input())\r\nproblem = sum([int(x) for x in input().split()])\r\n\r\nfor _ in range(int(input())):\r\n\tl, r = [int(x) for x in input().split()]\r\n\t\r\n\tif problem <= r:\r\n\t\tif problem <= l:\r\n\t\t\tprint(l)\r\n\t\telse:\r\n\t\t\tprint(problem)\r\n\t\tbreak\r\nelse:\r\n\tprint(-1)", "n = int(input())\narr = [int(x) for x in input().split()]\ntotal_time_needed = sum(arr)\nnum_intervals = int(input())\nfor i in range(num_intervals):\n\ta, b = [int(x) for x in input().split()]\n\tif(b >= total_time_needed):\n\t\tprint(max(a, total_time_needed))\n\t\texit()\nprint(-1)", "def main():\r\n n = int(input())\r\n a = list(map(int,input().split()))\r\n\r\n m = int(input())\r\n x = []\r\n for _ in range(m):\r\n l,r = map(int,input().split())\r\n x.append((l,r))\r\n\r\n sa = sum(a)\r\n\r\n for i in range(m):\r\n if x[i][0] <= sa <= x[i][1]:\r\n return sa\r\n if sa <= x[i][0]:\r\n return x[i][0]\r\n\r\n return -1\r\n\r\nif __name__ == '__main__':\r\n print(main())\r\n", "\r\n#k=int(input())\r\n#n,m=map(int,input().split())\r\n\r\n#a=list(map(int,input().split()))\r\n\r\n#b=list(map(int,input().split()))\r\n\r\nn=int(input())\r\n\r\na=list(map(int,input().split()))\r\n\r\ns=sum(a)\r\n\r\nm=int(input())\r\nss=10**10;\r\n\r\nfor i in range(m):\r\n l,r=map(int,input().split())\r\n\r\n if r<s: \r\n continue\r\n\r\n ss=min(ss,max(s,l))\r\n\r\nif ss==10**10:\r\n print(-1)\r\nelse:\r\n print(ss)", "'''input\n1\n5\n1\n1 5\n'''\nfrom bisect import bisect\nn = int(input())\na = list(map(int, input().split()))\nm, s, t = int(input()), sum(a), []\nif m == 0: \n\tprint(-1)\nelse:\n\tfor _ in range(m):\n\t\tl, r = map(int, input().split())\n\t\tt += range(l, r+1)\n\tif s in t:\n\t\tprint(s)\n\telse:\n\t\ttry:\n\t\t\tprint(t[bisect(t, s)])\n\t\texcept IndexError:\n\t\t\tprint(-1)\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "input()\r\na=sum(list(map(int,input().split())))\r\nb=-1\r\nc=int(input())\r\nfor i in range(c):\r\n d,f=list(map(int,input().split()))\r\n if d<=a and a<=f:\r\n b=a\r\n break\r\n if a<=d:\r\n b=d\r\n break\r\n\r\nprint(b)\r\n", "n = int(input())\r\na = list(map(int,input().split()))\r\ns = sum(a)\r\nm = int(input())\r\nfor _ in range(m):\r\n a,b = map(int,input().split())\r\n if b>=s:\r\n print(max(a,s))\r\n break\r\nelse:\r\n print(-1)\r\n \r\n", "N = int(input())\nAs = list(map(int, input().split()))\nsumOfAs = sum(As)\nM = int(input())\n(maxL, maxR) = 0, 0\nisPossible = False\nsolution = -1\nfor m in range(M):\n\tmaxL, maxR = list(map(int, input().split()))\n\tif not isPossible and sumOfAs <= maxR:\n\t\tisPossible = True\n\t\tsolution = max(maxL, sumOfAs)\nprint(solution)\n", "n = int(input())\narr = list(map(int, input().split()))\nm = int(input())\nmoment = []\nmy = 0\nfor i in range(m):\n\ta, b = map(int, input().split())\n\tmoment.append((a, b))\n\tif b > my:\n\t\tmy = b\nmoment = sorted(moment)\ntotal = sum(arr)\nif total <= my:\n\tfor a, b in moment:\n\t\tif total <= b:\n\t\t\tprint(str(max(total, a)))\n\t\t\tbreak\n\nelse:\n\tprint('-1')", "n = int(input())\ns = 0\nfor i in map(int, input().split()):\n\ts += i\nm = int(input())\nsol = -1\nfor i in range(m):\n\td = list(map(int, input().split()))\n\tif sol == -1:\n\t\tif s >= d[0] and s <= d[1]:\n\t\t\tsol = s\n\t\telif s <= d[0]:\n\t\t\tsol = d[0]\n\nprint(sol)\n", "# Meet Arora\n\nn=int(input())\na=[int(x) for x in input().split()]\nm=int(input())\nt=[]\nfor i in range(m):\n\tx, y=input().split()\n\tt.append([int(x), int(y)])\ns=[]\nsum=0\nfor i in a:\n\tsum+=i\n\ts+=[sum]\nindex=0\ntindex=0\n#print(t, s)\nwhile index<n and tindex<m:\n\tif s[index]>t[tindex][1]:\n\t\ttindex+=1\n\t\tcontinue\n\tif s[index]>=t[tindex][0] and s[index]<=t[tindex][1]:\n\t\tif s[index]==t[tindex][1]:\n\t\t\ttindex+=1\n\t\tindex+=1\n\telif s[index]<t[tindex][0]:\n\t\ts[index]=t[tindex][0]\n\t\tindex+=1\n\telse:\n\t\ttindex+=1\nif index==n:\n\tprint(s[index-1])\nelse:\n\tprint(-1)\n", "n = int(input())\nl = list(map(int, input().split()))\ns = sum(l)\nm = int(input())\nimos = [0 for _ in range(101010)]\nfor _ in range(m):\n a, b = map(int, input().split())\n imos[a] += 1\n imos[b+1] -= 1\nfor i in range(1, 101010):\n imos[i] += imos[i-1]\n if imos[i] > 0 and i >= s:\n print(i)\n exit()\nprint(-1)\n", "input()\r\ns = sum(map(int, input().split()))\r\nm = int(input())\r\n\r\n\r\nfor _ in range(m):\r\n l, r = map(int, input().split())\r\n if r >= s:\r\n print(max(l, s))\r\n break\r\nelse:\r\n print('-1')\r\n", "n = int(input())\r\na = sum(list(map(int,input().split())))\r\nk = int(input())\r\nl=0\r\nwhile k:\r\n k-=1\r\n s,l = map(int,input().split())\r\n if l>=a:\r\n if s<=a:\r\n print(a)\r\n else:\r\n print(s)\r\n break\r\nif l<a:\r\n print(-1)", "n=int(input())\na=list(map(int,input().split()))\nm=int(input())\nend1=[0]\nstart1=[0]\nfor i in range(m):\n start,end=map(int,input().split())\n start1.append(start)\n end1.append(end)\n#if start1!=None:\n# for i in range(len(end1)):\n# if end1[i]>=sum(a) and start1[i]<=sum(a):\n# print(sum(a))\n\n\nfor i in range(len(end1)):\n if end1[i]>=sum(a) and start1[i]<=sum(a):\n print(sum(a))\n if start1[i]>sum(a) and sum(a)>end1[i-1]:\n print(start1[i])\nif sum(a)>end1[-1]:\n print(-1)\n\n\t \t \t \t\t \t \t \t\t\t \t\t \t", "def solve():\r\n n = int(input())\r\n a = [int(s) for s in input().split(' ')]\r\n x = sum(a)\r\n m = int(input())\r\n u = [tuple([int(x) for x in input().split(' ')]) for i in range(m)]\r\n for l, r in u:\r\n if r >= x:\r\n return max(l, x)\r\n return - 1\r\n\r\n\r\nprint(solve())\r\n", "f = lambda: map(int, input().split())\r\nf()\r\ns, d = sum(f()), -1\r\nfor i in range(int(input())):\r\n l, r = f()\r\n if s <= r:\r\n d = max(s, l)\r\n break\r\nprint(d)", "n=input()\r\ns=sum(list(map(int,input().split())))\r\nk=int(input())\r\nans=-1\r\nfor i in range(k):\r\n l, r = map(int,input().split())\r\n if l<=s<=r:\r\n ans=s\r\n break\r\n else:\r\n if s<l:\r\n ans=l\r\n break\r\nprint(ans)\r\n", "# cook your dish here\r\nt=int(input());l=[]\r\nl=[int(_) for _ in input().split()]\r\ns=sum(l);ans=-1\r\n# print(s)\r\nn=int(input())\r\nwhile(n>0):\r\n n-=1\r\n x=[int(_) for _ in input().split()]\r\n # print(x[0],x[1])\r\n if x[0]<=s<=x[1]:\r\n # print(\"98484\")\r\n ans=s\r\n break\r\n elif x[0]>s:\r\n ans=x[0]\r\n break\r\nprint(ans)\r\n \r\n\r\n", "def find(x,y,n):\r\n for i in range(x,y+1):\r\n if i>=n:\r\n return i\r\n return 0\r\n \r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nm=int(input())\r\nf=True\r\nfor i in range(m):\r\n x,y=map(int,input().split())\r\n if find(x,y,sum(a))!=0 and f:\r\n print(find(x,y,sum(a)))\r\n f=False\r\nif f:\r\n print(-1)\r\n", "import math\r\nn=int(input())\r\nlist=[int(i) for i in input().split()]\r\nsome=sum(list)\r\nm=int(input())\r\nfor i in range(m):\r\n a,b=map(int,input().split())\r\n if(some<=b):\r\n if(some<a):\r\n print(a)\r\n else:\r\n print(some)\r\n exit()\r\nprint(\"-1\") ", "I=lambda: map(int, input().split())\nI()\nn, a=sum(I()), -1\nfor _ in range(*I()):\n\tl, r=I()\n\tif n<=r:\n\t\ta=max(n, l)\n\t\tbreak\nprint(a)\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\ns = sum(a)\r\nt = int(input())\r\nstor = -1\r\nfor i in range(t):\r\n l,r = list(map(int, input().strip().split()))\r\n if l <= s and s <= r and stor == -1:\r\n stor = s\r\n if l > s and stor == -1:\r\n stor = l\r\nprint(stor)", "n = int(input())\na = list(map(int, input().split()))\nans = -1\ns = sum(a)\nm = int(input())\nfor _ in range(m):\n l, r = map(int, input().split())\n if ans == -1:\n if l <= s <= r:\n ans = s\n elif s < l:\n ans = l\n\nprint(ans)\n", "# Contest: Educational Codeforces Round 22 (https://codeforces.com/contest/813)\n# Problem: A: The Contest (https://codeforces.com/contest/813/problem/A)\n\ndef rint():\n return int(input())\n\n\ndef rints():\n return list(map(int, input().split()))\n\n\nn = rint()\ns = sum(rints())\nm = rint()\nfor _ in range(m):\n l, r = rints()\n if s <= r:\n print(max(l, s))\n exit(0)\nprint(-1)\n", "n=int(input())\r\narr=[int(x) for x in input().split()]\r\ns=sum(arr)\r\ntemp=[]\r\nfor _ in range(int(input())):\r\n l,r=[int(x) for x in input().split()]\r\n temp.append([l,r])\r\nans=-1\r\nfor i in temp:\r\n if s>=i[0] and s<=i[1]:\r\n ans=s\r\n break\r\n elif i[0]>s:\r\n ans=i[0]\r\n break\r\nprint(ans)", "#!/usr/bin/env python3\n\nn = int(input().strip())\ns = sum(map(int, input().strip().split()))\nm = int(input().strip())\nrls = [tuple(map(int, input().strip().split())) for _ in range(m)]\n\nif m == 0 or s > rls[-1][1]:\n\tprint (-1)\nelse:\n\ti = 0\n\twhile rls[i][1] < s:\n\t\ti += 1\n\tprint (max(rls[i][0], s))\n\n", "import sys\r\n\r\ndef solve():\r\n n = int(sys.stdin.readline().rstrip())\r\n a = [int(i) for i in sys.stdin.readline().split()]\r\n tot = sum(a)\r\n\r\n m = int(sys.stdin.readline().rstrip())\r\n for i in range(m):\r\n li, ri = map(int, sys.stdin.readline().split())\r\n\r\n if tot < li:\r\n print(li)\r\n return\r\n elif li <= tot <= ri:\r\n print(tot)\r\n return\r\n\r\n print(-1)\r\n\r\nif __name__ == '__main__':\r\n solve()" ]
{"inputs": ["2\n3 4\n2\n1 4\n7 9", "1\n5\n1\n1 4", "1\n5\n1\n1 5", "5\n100000 100000 100000 100000 100000\n0", "5\n886 524 128 4068 298\n3\n416 3755\n4496 11945\n17198 18039", "10\n575 3526 1144 1161 889 1038 790 19 765 357\n2\n4475 10787\n16364 21678", "1\n4\n1\n5 9", "1\n200\n4\n1 10\n20 40\n50 55\n190 210", "4\n643 70 173 745\n14\n990 995\n1256 1259\n1494 1499\n1797 1804\n2443 2450\n2854 2859\n3164 3167\n4084 4092\n4615 4622\n5555 5563\n6412 6421\n7173 7180\n7566 7571\n8407 8415", "42\n749 516 256 497 37 315 184 518 103 726 80 983 474 884 209 706 10 543 587 371 199 315 967 707 948 736 590 734 715 184 230 513 199 898 287 468 250 600 352 29 408 22\n2\n312 314\n1293 1302", "1\n10000\n2\n1 10\n9998 10000", "1\n547\n15\n774 779\n1598 1605\n2458 2464\n3138 3140\n3372 3378\n4268 4272\n4730 4733\n5064 5067\n5074 5075\n5483 5490\n5894 5901\n5931 5938\n6750 6756\n7487 7491\n8328 8332", "1\n10\n2\n1 2\n11 12", "2\n4 6\n2\n5 10\n15 20", "2\n16 5\n3\n5 10\n15 20\n25 30", "1\n16\n2\n5 10\n15 20", "44\n750 672 846 969 981 698 380 968 813 587 156 28 446 917 849 449 173 764 226 958 335 622 236 782 416 689 113 728 452 265 585 217 707 50 520 712 946 275 423 123 175 268 583 528\n4\n869 870\n1353 1354\n1683 1685\n2532 2540", "1\n1\n0", "3\n1 2 5\n3\n5 6\n7 8\n9 13", "1\n2\n0", "1\n5\n3\n1 2\n3 4\n10 11", "1\n4\n0", "1\n5\n0", "1\n239\n0"], "outputs": ["7", "-1", "5", "-1", "5904", "10264", "5", "200", "1797", "-1", "10000", "774", "11", "10", "25", "16", "-1", "-1", "8", "-1", "10", "-1", "-1", "-1"]}
UNKNOWN
PYTHON3
CODEFORCES
85
168f6f1983f3160ebd9573e0d6a26d69
Display Size
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels. Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that: - there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible. The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have. Print two integers — the number of rows and columns on the display. Sample Input 8 64 5 999999 Sample Output 2 4 8 8 1 5 999 1001
[ "a = int(input())\r\nb = int(a**0.5)\r\nwhile a%b:\r\n b -= 1\r\nprint(b, a//b)", "from math import sqrt\nnum = int(input())\nfor factor in range(int(sqrt(num)), 0, -1):\n\tif num % factor == 0:\n\t\tprint(factor, num//factor)\n\t\tbreak\n", "n = int(input())\r\ni = 1\r\nans = 1\r\nwhile i*i<=n:\r\n if n%i==0 : ans = i\r\n i+=1\r\nprint (ans, n//ans)\r\n", "from math import sqrt\r\nn = int(input().strip())\r\nsq = int(sqrt(n))\r\nfor i in range(sq, 0, -1):\r\n if not n%i:\r\n print(i, n//i)\r\n break\r\n", "#import sys\r\n#sys.stdin = open('in', 'r')\r\nn = int(input())\r\n#a = [int(x) for x in input().split()]\r\n#n,m = map(int, input().split())\r\nimport math\r\n\r\na = 1\r\nb = n\r\nr = n-1\r\nra = 1\r\nrb = n\r\n\r\nwhile a <= (math.sqrt(n) + 1):\r\n a += 1\r\n if n % a == 0:\r\n b = n // a\r\n if b >= a and (b-a) < r:\r\n r = b - a\r\n ra = a\r\n rb = b\r\n\r\nprint(ra, rb)\r\n", "def solve():\r\n global a,b,n\r\n now= 1e9\r\n for i in range(1,n+1):\r\n if (n%i==0):\r\n if (i>n//i):\r\n break\r\n a= i\r\n b= n//i\r\n \r\nn= int(input())\r\nsolve()\r\nprint(a,b)\r\n", "a = int(input())\r\nb = int(a ** 0.5)\r\n\r\nwhile a % b != 0:\r\n b -= 1\r\n\r\nprint(b, a // b)\r\n", "n=int(input())\r\na=[]\r\nx=int(n**(1/2))\r\n# print(x)\r\nfor i in range(1,x+1):\r\n\tif n%i==0:\r\n\t\ta.append((i,n//i))\r\nprint(*max(a))", "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 ans=inf\n ans_pair=[0,0]\n for i in range(1,n+1):\n if n%i==0:\n x=n//i\n if ans>abs(x-i):\n ans=abs(x-i)\n ans_pair=[i,n //i]\n # print(ans,ans_pair)\n\n a,b=sorted(ans_pair)\n return str(a)+' '+str(b)\n\n# main()\nprint(main())\n", "n = int(input())\r\na,b = 1,n\r\nfor i in range(2,int(n**.5)+1):\r\n\tif n%i == 0 :\r\n\t\ta,b = i,n//i\r\nprint(a,b)\r\n", "import math\nn = int(input())\nans = 1\nlimit = int(math.sqrt(n))\nfor i in range(1, limit+1):\n if(n % i == 0):\n ans = i\nprint(ans, n//ans)", "a=int(input())\r\n\r\nfor i in range(1,a+1):\r\n if a%i==0:\r\n if i>a//i:\r\n break\r\n \r\n b=i\r\n d=a//i \r\nprint(b, d)", "n = int(input())\r\ni = 1\r\nli = []\r\nwhile i * i < n:\r\n if n % i == 0:\r\n b = n // i\r\n li.append(i)\r\n li.append(b)\r\n i += 1\r\nif i * i == n:\r\n print(i,i)\r\nelse:\r\n print(li[-2],li[-1])\r\n ", "import math\r\n\r\nn=int(input())\r\nx=str(math.sqrt(n))\r\nif x.endswith('.0'):\r\n\tprint(x[:len(x)-2],x[:len(x)-2])\r\n\texit(0)\r\nl=[]\r\nfor i in range(1,n+1):\r\n\tif n%i==0:\r\n\t\tl.append(i)\r\nm,temp=[],[]\r\nfor i in range(len(l)):\r\n\tfor j in range(i+1,len(l)):\r\n\t\tif l[i]*l[j]==n and l[i]<=l[j]:\r\n\t\t\tm.append(l[j]-l[i])\r\n\t\t\ttemp.append([l[i],l[j]])\r\nminimum,x,y=m[0],temp[0][0],temp[0][1]\r\nfor i in range(1,len(m)):\r\n\tif minimum>m[i]:\r\n\t\tminimum,x,y=m[i],temp[i][0],temp[i][1]\r\nprint(x,y)", "a = int(input())\r\ni = 1\r\nresults_a = []\r\nresults_i = []\r\nresult = []\r\nwhile i <= a:\r\n res_i = a / i\r\n if res_i % 1 == 0 and res_i >= 0:\r\n res_i = round(res_i)\r\n results_a.append(res_i)\r\n results_i.append(i)\r\n i += 1\r\nk = 0\r\nlenght_i = len(results_i) - 1\r\nwhile k <= lenght_i:\r\n c = results_i[k] - results_a[k]\r\n if c >= 0:\r\n q = results_a[k]\r\n u = results_i[k]\r\n break\r\n k +=1\r\nprint(q, u)", "# Display Size\ndef display(p):\n c = p ** 0.5\n if c % 1 == 0:\n print(int(c), int(c))\n return\n else:\n for i in range(int(c), 0, -1):\n if p % i == 0:\n print(i, p // i)\n return\n\np = int(input())\ndisplay(p)", "n = int(input())\r\nm = int(n ** 0.5)\r\nwhile n % m != 0:\r\n m -= 1\r\nprint(m, n // m)\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 integers\r\nget_int = lambda: int(sys.stdin.readline())\r\n\r\n#--------------------------------WhiteHat010--------------------------------------#\r\nm = get_int()\r\ni = 1\r\nfirst = 1\r\nsec = m\r\nwhile i*i <= m:\r\n if m%i == 0:\r\n a = i\r\n b = m//i\r\n if a<=b:\r\n first = a\r\n sec = b\r\n else:\r\n break\r\n i += 1\r\nprint(first,sec)", "n = int(input())\nsn = int(n**(0.5))\n\nwhile (n % sn) != 0:\n sn -= 1\n\nprint(sn, n//sn)\n", "a, b, kc, n = 0, 0, 1000000, int(input())\r\nfor i in range(1, n + 1):\r\n for j in range(i, n // i + 1):\r\n if j - i < kc and i * j == n: a, b = i, j\r\nprint(a, b)", "import math\r\na = int(input())\r\n\r\nfor x in range(1,int(math.sqrt(a))+1):\r\n\tif a%x == 0: ans = x\r\nprint(ans,a//ans)\r\n", "import math\r\nn=int(input())\r\na=math.ceil(n/2)\r\nm=10**10\r\np=0\r\nq=0\r\nfor i in range(1,a+1):\r\n if n%i==0:\r\n b=n//i\r\n c=i\r\n if abs(b-c)<m:\r\n m=abs(b-c)\r\n p=min(b,c)\r\n q=max(b,c)\r\nprint(p,q,sep=\" \")", "n = int(input())\r\nk = int(n**0.5)\r\n\r\n\r\nwhile True:\r\n if n%k==0: \r\n print(k, n//k)\r\n break\r\n k-=1", "# coding = utf-8\r\nimport math\r\nline = input()\r\na = []\r\nfor x in line.split():\r\n a.append(int(x))\r\nl = 1\r\nr = a[0]\r\ntmp = int(math.sqrt(a[0]))\r\nfor i in range(2, tmp + 1):\r\n if a[0] % i == 0:\r\n l = i\r\n r = a[0] // i\r\nprint (l, r)", "n = int(input())\r\nfor i in range(1,n+1):\r\n if (n%i==0):\r\n if (i>n//i):\r\n break\r\n a= i\r\n b= n//i\r\nprint(a, b)\r\n", "n=int(input())\r\nl=[]\r\nfor i in range(1,(n//2)+2) :\r\n if n%i==0 :\r\n l.append([abs(i-(n//i)),i,n//i])\r\nv=min(l)\r\nprint(min(v[1],v[2]),max(v[1],v[2]))\r\n \r\n", "n=int(input());li=list()\r\nfor i in range(1,n+1):\r\n if n % i == 0:\r\n li.append(i)\r\nli.sort()\r\nl=0;r=len(li)-1\r\nm = l + (r-l)//2\r\nif li[m]*li[m] == n: print(li[m],li[m]) \r\nelse: print(li[m],li[m+1]) ", "from math import sqrt, ceil\ninp = int(input())\na = int(sqrt(inp))\nwhile inp % (inp//a) != 0:\n a-=1\n\nprint(a, inp//a)", "import math\r\n\r\ndef solve():\r\n n=int(input())\r\n m = int(math.sqrt(n))\r\n while n % m != 0:\r\n m-=1\r\n \r\n return str(m)+\" \"+ str(int(n/m))\r\n \r\nprint (solve())", "import math\r\n\r\ndef display(n):\r\n max_divisor = 1\r\n for i in range(2, math.floor(math.sqrt(n) + 1)):\r\n if n % i == 0:\r\n max_divisor = i\r\n return [max_divisor, n // max_divisor]\r\n \r\nn = int(input())\r\nprint(' '.join(map(str, display(n))))", "# import sys\r\n# sys.stdin=open(\"input.in\",'r')\r\n# sys.stdout=open(\"out1.out\",'w')\r\nn=int(input())\r\nx=int(pow(n,0.5))\r\nif n%x==0:\r\n\tprint(x,n//x)\r\nelse:\r\n\twhile n%x!=0:\r\n\t\tx-=1\r\n\tprint(x,n//x)\t\t\r\n", "n = int(input())\r\nfrom math import sqrt\r\na = int(sqrt(n))\r\nwhile n%a != 0:\r\n a -= 1\r\nb = n // a\r\nprint(a , b)", "from math import sqrt\nn = int(input())\nfor i in range(int(sqrt(n))+1,0,-1):\n\n if n%i == 0:\n a = i\n b = n//i\n if b >= a:\n print(a,b)\n break\n", "n=int(input())\r\nchk=0\r\nfor i in range(1,n+1):\r\n if i*i>n:\r\n break\r\n elif n%i==0:\r\n chk=i\r\nans=[min(chk,n//chk),max(chk,n//chk)]\r\nprint(*ans)", "def solve(n):\r\n a = 1\r\n b = n\r\n i = 2\r\n while i * i <= n:\r\n if n % i == 0:\r\n a = i\r\n b = n // i\r\n i += 1\r\n return f\"{a} {b}\"\r\n\r\nn = int(input())\r\nprint(solve(n))", "from math import sqrt\r\nn=int(input())\r\nl=[]\r\nfor i in range(1,int(sqrt(n))+1):\r\n\tif n%i==0:\r\n\t\tl.append(i)\r\nprint(l[-1],n//l[-1])\r\n", "pixels = int(input())\r\nroot = int(pixels**0.5)\r\nwhile pixels%root != 0:\r\n root -= 1\r\nprint(root, pixels//root)", "#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-26 13:35:48\nLastEditTime: 2021-11-26 13:37:56\nDescription: Display Size\nFilePath: CF747A.py\n'''\n\n\ndef func():\n n = int(input())\n for a in range(int(n ** 0.5), 0, -1):\n if n % a == 0:\n print(a, n // a)\n break\n\n\nif __name__ == '__main__':\n func()\n", "import math\nx=int(input())\ny=int(math.sqrt(x))\nwhile y>0:\n if x%y==0:\n print(y, int(x/y))\n break\n else:\n y-=1\n\t\t\t\t\t\t \t\t \t \t \t \t \t \t \t", "n = int(input())\r\nif n == 1:print(1,1)\r\nelse:\r\n\tz = n-1\r\n\tfor i in range(1,n//2 +1):\r\n\t\tif n%i ==0 and z>0:\r\n\t\t\tb = n//i - i\r\n\t\t\tif z>b:\r\n\t\t\t\tz = n//i -i\r\n\t\t\tm = i\r\n\tif m!=1:print(n//m,m)\r\n\telse:print(m,n//m)", "n=int(input())\r\na=1\r\nb=n//a\r\nr=None\r\nwhile a<=b:\r\n b=n//a\r\n if a*b==n and (r==None or r>b-a):\r\n r=b-a\r\n x=a\r\n y=b\r\n a=a+1\r\nprint(min(x,y),max(x,y))\r\n ", "n = int(input())\nstart = n**0.5\nstart = int(start)\nwhile n % start != 0:\n start -= 1\n\nprint(start, n//start)", "from math import floor\r\nfrom math import sqrt\r\nn=int(input())\r\nd=floor(sqrt(n))\r\nfor i in range(d,-1,-1):\r\n if n%i==0:\r\n print(i,int(n/i))\r\n break\r\n", "from math import *\r\nn=int(input())\r\nl=[]\r\nm=[]\r\nfor i in range(1,int(sqrt(n))+1):\r\n if n%i==0:\r\n ch=str(i)+' '+str(int(n/i))\r\n l.append(ch)\r\n c=abs(int(n/i)-i)\r\n m.append(c)\r\nch=str(n)+' 1'\r\nl.append(ch)\r\nm.append(abs(n-1))\r\na=min(m)\r\nb=m.index(a)\r\nprint(l[b])", "n = int(input())\r\nfrom math import sqrt, floor\r\nfor a in range(floor(sqrt(n)), 0, -1):\r\n if a * (n//a) == n:\r\n print(a, n//a)\r\n break", "n =int(input())\r\ni=2\r\na=1\r\nwhile i*i<=n:\r\n if n%i==0:\r\n a=i\r\n i+=1\r\nprint(a, n//a)", "n = int(input())\r\nm = int(n**0.5)\r\nwhile n%m:\r\n m -= 1\r\nprint(m, n//m)", "import math\r\n\r\nn = int(input())\r\n\r\nroot = int(math.floor(math.sqrt(n)))\r\n\r\ndifference = -1\r\n\r\na = -1\r\n\r\nb = -1\r\n\r\n\r\nwhile(True):\r\n\r\n\tif n % root == 0:\r\n\r\n\t\ta = root \r\n\r\n\t\tb = int(n / a)\r\n\r\n\t\tdifference = a - b \r\n\r\n\t\tif difference >= 0:\r\n\r\n\t\t\tbreak\r\n\r\n\troot += 1\r\n\r\nif a == -1 and b == -1:\r\n\r\n\tprint(\"1\" + \" \" + str(n))\r\n\r\nelse:\r\n\r\n\tprint(str(b) + \" \" + str(a))", "n = int(input())\r\n\r\nbest_a = -1\r\nbest_b = -1\r\nmin_b_a = 1000000000000000000000000\r\n\r\nfor a in range(1, n + 1):\r\n if n % a != 0:\r\n continue\r\n\r\n b = n // a\r\n\r\n if a > b:\r\n continue\r\n\r\n if min_b_a > b - a:\r\n min_b_a = b - a\r\n best_a = a\r\n best_b = b\r\n\r\nprint(best_a, best_b)", "import math\r\n\r\nn = int(input())\r\n\r\na = 1\r\nb = n\r\n\r\nm=int(math.sqrt(n))\r\n\r\nfor i in range(1, m+1):\r\n\r\n x = i\r\n if n % x == 0:\r\n y = n // x\r\n if b - a > y - x:\r\n a = x\r\n b = y\r\n\r\nprint(a, b)", "n = int(input())\r\nx = 1\r\ny = n\r\nmin = y - x\r\nfor i in range(0, n):\r\n\tif i!=0 and n % i == 0:\r\n\t\ta = i\r\n\t\tb = n // i\r\n\t\tif min > abs(b - a) and a <= b:\r\n\t\t\tx = a\r\n\t\t\ty = b\r\nprint(x, y)\r\n\r\n\r\n", "n = int(input())\r\na = []\r\nkey = []\r\nvalue = []\r\nc = 0\r\nfor i in range(1,n+1):\r\n if n % i == 0:\r\n a.append(i)\r\nll = len(a) - 1\r\nfor elements in a:\r\n if elements*elements==n:\r\n\r\n c = elements\r\n print(elements,elements)\r\n break\r\n else:\r\n lenght_a = ll\r\n while lenght_a>=0:\r\n\r\n\r\n if a[lenght_a]*elements==n:\r\n if elements>a[lenght_a]:\r\n key.append(elements)\r\n value.append(a[lenght_a])\r\n lenght_a-=1\r\n else:\r\n lenght_a-=1\r\n\r\n else:\r\n lenght_a-=1\r\nif c*c!=n:\r\n if len(key)>2:\r\n Rama = []\r\n for g in range(len(key)-1):\r\n a = key[g]-value[g]\r\n Rama.append(a)\r\n k = Rama.index(min(Rama))\r\n print(value[k],key[k])\r\n else:\r\n print(value[0],key[0])\r\nelse:\r\n pass", "n=int(input())\r\nr=int(n**0.5)\r\nwhile n%r!=0:\r\n r-=1\r\nprint(r,n//r)", "a = int(input())\r\nb = int(a ** 0.5)\r\n\r\nwhile a % b:\r\n b -= 1\r\nprint(b, a // b)", "import math\r\nn=int(input())\r\nfor i in range(int(math.sqrt(n)), 0, -1):\r\n\tif(n%i==0):\r\n\t\tprint(i, int(n/i))\r\n\t\tbreak\r\n", "import math\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\n\r\nfor i in range(int(math.sqrt(n)), -1, -1):\r\n if n % i == 0:\r\n print(i, n // i)\r\n break", "v = int(input())\nx = int(v ** 0.5)\nwhile v % x > 0:\n x -= 1\nprint(x, v // x)\n", "n = int(input())\r\na = int(n**.5)\r\n \r\nwhile n % a:\r\n a -= 1\r\n \r\nprint(a, n//a)\r\n", "n = int(input())\r\nmind = 1000_005\r\na, b = 0, 0\r\nN = int(n ** 0.5 + 1)\r\nfor i in range(1, N):\r\n if n % i != 0:\r\n continue\r\n if abs(i - n // i) < mind:\r\n mind = abs(i - n // i)\r\n a = i\r\n b = n // i\r\n \r\nprint(min(a, b), max(a, b))", "from math import sqrt\r\nn = int(input())\r\na, b = 1, n\r\nsqr = int(sqrt(n)) + 1\r\nfor i in range(2, sqr):\r\n if n % i == 0:\r\n a, b = i, n // i\r\nprint(a, b)\r\n", "n=int(input())\r\nk=int(n**0.5)\r\nwhile n%k!=0:\r\n k=k-1\r\nprint(k,n//k)\r\n ", "import math\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n t = int(math.sqrt(n))\r\n for a in range(t, 0, -1):\r\n b = n // a\r\n if a * b == n:\r\n print(str(a) + ' ' + str(b))\r\n break\r\n", "n = int(input())\r\na, b = 1, n\r\nfor i in range(2, int(n ** 0.5) + 1):\r\n if n % i == 0:\r\n a, b = i, n // i\r\nprint(a, b)", "from math import sqrt\r\nn=int(input())\r\nfor i in range(int(sqrt(n)),0,-1):\r\n\tif n%i==0:\r\n\t\tw=i\r\n\t\tbreak\r\nprint(w,n//w)", "n=int(input())\r\na=1\r\n\r\nfor i in range(2,int(n**0.5)+2):\r\n if n%i==0:\r\n a=i\r\nprint(min(a,n//a),max(a,n//a))", "n = int(input())\r\nb = a = int(n**0.5)\r\nwhile n % a:\r\n a -= 1\r\nprint( a, int(n / a))", "from math import sqrt\n\na = int(input())\n\nb = int(sqrt(a))\n\nwhile True:\n if a % b == 0:\n g, h = b, int(a/b)\n print(min(g, h), max(g,h))\n break\n b += 1", "import math\r\n\r\n\r\ndef findans(n):\r\n r=math.floor(math.sqrt(n))\r\n for i in range(r,0,-1):\r\n if n%i==0:\r\n return(i,(n//i))\r\n\r\n\r\nn=int(input())\r\na,b=findans(n)\r\nprint(min(a,b),max(a,b))", "def optimal_divider(n):\r\n optimal = n ** 0.5\r\n optint = int(optimal)\r\n for ans1 in range(optint, 0, -1):\r\n ans2 = n // ans1\r\n if ans1 * ans2 == n:\r\n return (ans1, ans2)\r\n \r\nn = int(input())\r\nprint(*optimal_divider(n))\r\n", "import math\r\n\r\nn = int(input())\r\n\r\ni = int(math.sqrt(n))\r\n\r\nwhile i > 0:\r\n\r\n if n%i == 0:\r\n print(i, int(n/i))\r\n break\r\n i -= 1\r\n", "def codeforces(pixels):\r\n difference = float('inf')\r\n for i in range(1, pixels+1):\r\n if pixels % i == 0:\r\n diff = abs(pixels // i - i)\r\n if diff < difference:\r\n nums = pixels // i, i\r\n difference = diff\r\n return str(min(nums)), str(max(nums))\r\n\r\n\r\nn = int(input())\r\nprint(' '.join(codeforces(n)))\r\n", "import math\r\nn = int(input())\r\nr = int(math.sqrt(n))\r\nfor i in range(r):\r\n if n%(r-i) == 0:\r\n print(r-i, int(n/(r-i)))\r\n break", "\r\nn=int(input())\r\na = int(n**0.5)\r\nwhile a > 0:\r\n if(n% a == 0):\r\n break\r\n a=a-1\r\n\r\nprint(a, n//a)\r\n", "from math import *\r\nn=int(input())\r\na=int(floor(sqrt(n)))\r\nwhile n%a:\r\n a-=1\r\nprint(a,n//a)", "from math import sqrt\r\n\r\nn = int(input())\r\n\r\ndiff = n\r\na = 0\r\nb = 0\r\n\r\nfor i in range(1, n + 1, 1):\r\n if n % i == 0:\r\n temp = abs( i - n/i )\r\n if diff > temp:\r\n diff = temp\r\n a = min(i, n/i)\r\n b = max(i, n/i)\r\n\r\n\r\nprint(int(a), int(b))\r\n\r\n", "n=int(input())\r\nd=dict()\r\nfor t in range(n):\r\n t+=1\r\n if (n/t)%1==0:\r\n if abs(t-n/t) not in d.keys():\r\n d[abs(t-n/t)]=[t,int(n/t)]\r\nprint(d[min(d.keys())][0],d[min(d.keys())][1])\r\n", "import math\r\n\r\nn=int(input())\r\nz=n**(0.5)\r\nif z-math.floor(z)==0:\r\n print(int(z),int(z))\r\nelse :\r\n y=math.floor(z)+1\r\n while n%y!=0:\r\n y+=1\r\n print(int(n/y),y)", "n = int(input())\r\ni, s = 2, 1\r\nwhile i**2 <= n:\r\n if not n % i:\r\n s = i\r\n i += 1\r\nprint(s, n // s)\r\n", "import math\r\ndef is_square(n):\r\n sqrt = math.sqrt(n)\r\n return (sqrt - int(sqrt)) == 0\r\n\r\npixel = int(input())\r\n\r\nif is_square(pixel):\r\n result = (int(math.sqrt(pixel)), int(math.sqrt(pixel)))\r\nelse:\r\n lista = []\r\n for i in range(1, pixel + 1):\r\n if pixel % i == 0: lista.append(i)\r\n pivot = int(len(lista) / 2) - 1\r\n row = lista[pivot]\r\n column = lista[pivot + 1]\r\n result = (row, column)\r\n\r\nprint(f\"{' '.join(map(str, result))}\")", "#!/usr/bin/env/python\r\n# -*- coding: utf-8 -*-\r\nimport math\r\nn = int(input())\r\nfor i in range(int(math.sqrt(n)), 0, -1):\r\n if n % i == 0:\r\n print(i, n // i)\r\n break\r\n", "\r\nfrom math import sqrt\r\nn = int(input())\r\n\r\nfor i in range(int(sqrt(n)) + 1, 0, -1):\r\n\tif n % i == 0:\r\n\t\tl = sorted([i, n // i])\r\n\t\tprint(*l)\r\n\t\texit()\r\n\r\n\r\n", "import sys\r\n\r\nnoOfPixels = int(input())\r\n\r\nif noOfPixels == 1:\r\n print(\"1 1\")\r\n\r\nelse:\r\n\r\n row=1\r\n mini = sys.maxsize\r\n ans = []\r\n\r\n while True:\r\n if noOfPixels%row==0:\r\n col = noOfPixels//row\r\n\r\n if row > col:\r\n break\r\n mini = min(mini,(col-row))\r\n ans[:] = []\r\n ans.append(row)\r\n ans.append(col)\r\n\r\n row = row+1\r\n\r\n print(ans[0],ans[1])", "n = int(input())\r\n\r\nbest_diff = float('inf')\r\nbest_a, best_b = None, None\r\n\r\nfor a in range(1, n+1):\r\n if n % a == 0:\r\n b = n // a\r\n if a <= b and b - a < best_diff:\r\n best_diff = b - a\r\n best_a, best_b = a, b\r\n\r\nprint(best_a, best_b)\r\n", "'''\r\nn=int(input())\r\nfor i in range(1,n+1):\r\n if n%i==0: print(i)\r\n'''\r\nn=int(input())\r\nz=[]\r\nfor i in range(1,n+1):\r\n if n%i==0: z.append(i)\r\nif len(z)%2!=0: print(z[len(z)//2],z[len(z)//2])\r\nelse: print(z[(len(z)//2)-1],z[len(z)//2])", "n = int(input())\r\nfor i in range(int(n ** .5), 0, -1):\r\n if n % i == 0:\r\n print(i, n // i) \r\n exit()", "from math import sqrt\r\n\r\ndef div(n):\r\n i = 1\r\n list = []\r\n while i <= n:\r\n if n % i == 0:\r\n list.append(i)\r\n i = i + 1\r\n return list\r\n \r\nn=int(input())\r\n\r\nroot=sqrt(n)\r\n\r\ndivs=div(n)\r\n\r\n#print(divs)\r\n\r\nlisty=[abs(root-x) for x in divs]\r\n\r\nmin_index=listy.index(min(listy))\r\n\r\nprint(\"{} {}\".format(int(divs[min_index]),int(n/divs[min_index])))", "import math\n\nn = int(input())\n\nfor i in range(1, int(math.sqrt(n)) + 1)[::-1]:\n if n % i == 0:\n print(\" \".join([str(i), str(n // i)]))\n quit()\n \t \t \t \t\t \t \t\t\t \t \t\t\t\t \t", "from math import sqrt\r\ndef find_factors(number):\r\n factors = []\r\n for i in range(1, (number + 1)):\r\n if number % i == 0:\r\n factors.append(i)\r\n return factors\r\nc=int(input())\r\nv=find_factors(c);len=len(v)\r\nif len==2:print(*v)\r\nelif sqrt(c)==int(sqrt(c)):print(int(sqrt(c)),int(sqrt(c)))\r\nelse:print(*v[(len+1)//2 -1 :(len+1)//2 +1])", "def main():\n n = int(input())\n a = 0\n b = 0\n for i in range(1, n+1):\n if n % i == 0:\n if i <= n / i:\n a = i\n b = n // i\n else:\n continue\n print(a, b)\n\n\nif __name__ == '__main__':\n main()", "n=int(input(''))\r\nl=[]\r\nk=[]\r\nfor i in range(1,n+1):\r\n j=n/i\r\n if j==int(j):\r\n if j>=i:\r\n k.append([i,j])\r\n l.append(j-i)\r\nm=min(l)\r\nfor t in range(len(l)):\r\n if l[t]==m:\r\n print(k[t][0],int(k[t][1]))", "def solution(n):\r\n i=int(n**(1/2))\r\n while i>=1:\r\n \r\n if n%i==0:\r\n \r\n return str(i)+\" \"+str(int(n/i))\r\n\r\n i-=1\r\n\r\ndef answer():\r\n n = int(input())\r\n print(solution(n))\r\nanswer()", "\r\n#k=int(input())\r\n#n,m=map(int,input().split())\r\n\r\n#a=list(map(int,input().split()))\r\n\r\n#b=list(map(int,input().split()))\r\n\r\n\r\nn=int(input())\r\nm=10**10\r\nfor i in range(1,int(n**0.5+1)):\r\n if n%i==0:\r\n if m>n//i-i:\r\n m=n//i-i\r\n mini=i\r\n\r\nprint(mini,n//mini)\r\n\r\n", "from functools import reduce\r\nfrom math import sqrt\r\ndef factors(n):\r\n step = 2 if n%2 else 1\r\n return set(reduce(list.__add__,\r\n ([i, n//i] for i in range(1, int(sqrt(n))+1, step) if n % i == 0)))\r\n\r\nn = int(input())\r\nf = list(factors(n))\r\nf.sort()\r\nif len(f)%2 == 0:\r\n print(f[int(len(f)/2-1)],f[int(len(f)/2)])\r\nelse:\r\n print(f[int(len(f)//2)],f[int(len(f)//2)])", "#!/bin/python3\n\n# challenge-url: http://codeforces.com/contest/747/problem/A\n# username: hudson\n\n# n: number of pixels\n# a: number of rows of pixels\n# b: number of pixel columns\n\nimport math\n\nn = int(input())\ndiv = int( math.sqrt(n) ) \n\nwhile n % div != 0 and div != 1:\n div -= 1\n\n\nprint( div, n // div)\n", "import math\r\nn = int(input())\r\ne = float('inf')\r\nq = 1\r\nw = n\r\nfor a in range(1, int(math.sqrt(n)) + 1):\r\n if n % a == 0:\r\n b = n // a\r\n x = b - a\r\n if x < e:\r\n e = x\r\n q = a\r\n w = b\r\nprint(q, w)", "n = input()\r\nn = int(n.strip())\r\n\r\nt = int(n**0.5)\r\n\r\nwhile True:\r\n if n % t == 0:\r\n a = min(t, n//t)\r\n b = max(t, n//t)\r\n print(a, b)\r\n break\r\n t = t - 1\r\n", "'''input\n999999\n'''\nn = int(input())\nfor x in range(int(n**0.5), 0, -1):\n\tif n % x == 0:\n\t\tprint(x, n//x)\n\t\tbreak", "n = int(input())\r\nfor k in range(int(n**0.5), 0, -1):\r\n if n % k == 0:\r\n print(f'{k} {n//k}')\r\n break", "n = int(input())\r\nfor a in range(1, n + 1):\r\n if n % a == 0:\r\n b = n // a\r\n if a <= b:\r\n ans = a\r\n\r\nprint(ans, n // ans)\r\n", "def is_factor(n,f):\r\n if n%f==0:\r\n return True\r\n else:\r\n return False\r\ndef is_prime(n):\r\n for i in range(2,int(n**0.5)+1):\r\n if is_factor(n,i):\r\n return False\r\n else:\r\n return True\r\nx=int(input())\r\nlist1=[]\r\nif x==0:\r\n print('0 0')\r\nelif x==1:\r\n print('1 1')\r\nelse:\r\n for i in range(1,x):\r\n if x%i==0:\r\n list1.append((i,x//i))\r\n list2=[]\r\n for i in list1:\r\n list2.append(max(i)-min(i))\r\n count=0\r\n for i in list2:\r\n if i!=min(list2):\r\n count+=1\r\n else:\r\n break\r\n str1=''\r\n for i in (list1[count]):\r\n str1+=str(i)+' '\r\n print(str1)\r\n", "import math\r\n\r\n\r\ndef solve():\r\n n = int(input())\r\n d = int(1e9)\r\n resX, resY = 1, n\r\n for i in range(1, n + 1):\r\n if n % i == 0:\r\n a, b = (i, n // i)\r\n x, y = min(a, b), max(a, b)\r\n if y - x < d:\r\n d = y - x\r\n resX, resY = (x, y)\r\n print(resX, resY)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n solve()", "n = int(input())\r\nm = 1 + int(n**0.5)\r\n\r\nfor i in range(1, m):\r\n if n % i == 0:\r\n a = i\r\n b = n // i\r\n\r\nprint(a, b)", "a = int(input()) \r\nref= int(a ** 0.5) \r\nwhile (a % ref != 0 ): \r\n ref-= 1\r\n\r\nprint(ref , a // ref )\r\n\r\n\r\n\r\n", "n = int(input())\r\nsq = int(n**(1/2))\r\nfor i in range(sq,0,-1):\r\n if n%i==0:\r\n print(i,end=\" \")\r\n print(n//i)\r\n exit()\r\n \r\n \r\n", "from math import *\r\nnum=int(input())\r\nans=sqrt(num)\r\nans=int(ans)\r\nif num%ans==0:\r\n print(ans,num//ans)\r\nelse:\r\n while True:\r\n ans-=1\r\n if num%ans==0:\r\n print(ans,num//ans)\r\n break", "n=int(input())\r\na=int(n**0.5)\r\nwhile n%a!=0:\r\n a-=1\r\nprint(a,n//a)", "n=int(input())\r\ni=1\r\nwhile i<=(n**(1/2)):\r\n if (n%i)==0:\r\n a=i\r\n i=i+1\r\n b=n//a\r\nprint(a,b)\r\n", "import math\r\nn=int(input())\r\na,b=1,n\r\nfor x in range(1,int(math.sqrt(n))+1):\r\n\tif n%x==0 and (n//x)-x<(b-a):\r\n\t\ta,b=x,n//x\r\nprint(a,b)", "import sys\r\nimport math\r\nimport bisect\r\nimport itertools\r\nimport random\r\nimport re\r\n\r\ndef main():\r\n n = int(input())\r\n a, b = (1, n)\r\n for i in range(1, n + 1):\r\n if n % i == 0 and i <= n // i:\r\n a, b = (i, n // i)\r\n print('%d %d' % (a, b))\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "from math import floor, sqrt\n\n\ndef main():\n n = int(input())\n\n for i in range(floor(sqrt(n)), 0, -1):\n if n % i == 0:\n print(i, n // i)\n break\n\n\nif __name__ == '__main__':\n main()\n", "a=int(input())\r\nfor i in range(int(a**0.5),0,-1):\r\n if a%i==0:\r\n print(i,a//i,sep=\" \")\r\n break", "n = int(input())\r\n\r\nans = []\r\nd = n\r\nfor i in range(1, int(n ** 0.5) + 1):\r\n if n % i == 0:\r\n if abs(n // i - i) < d:\r\n d = abs(n // i - i)\r\n ans = [i, n // i]\r\n\r\nprint(*ans)", "from math import sqrt\r\n\r\nn=int(input())\r\nm=999999999\r\nfor i in range(1,int(sqrt(n))+1) :\r\n if n%i==0 and i*(n//i)==n :\r\n x=(n//i)-i\r\n if m>=x :\r\n a,b=i,n//i\r\n m=x\r\nprint(a,b) ", "\r\n\"\"\"\r\n\r\n\"\"\"\r\n\r\nimport sys\r\nfrom sys import stdin\r\n\r\nn = int(stdin.readline())\r\n\r\nans = (1,n)\r\n\r\nfor i in range(1,n+1):\r\n\r\n if n % i == 0:\r\n\r\n r = max(i,n//i)\r\n l = min(i,n//i)\r\n\r\n if r-l < ans[1]-ans[0]:\r\n ans = (l,r)\r\n\r\nprint (*ans)\r\n", "from math import sqrt\r\nn=int(input())\r\nans=float(\"inf\")\r\nl,r=1,n\r\nfor i in range(2,int(sqrt(n))+1):\r\n if n%i==0:\r\n l,r=i,n//i\r\n if ans>r-l+1:\r\n ans=r-l+1\r\nprint(l,r)", "n=int(input())\r\na=set()\r\ni=1\r\nwhile i*i<=n:\r\n if n%i==0:\r\n a.add((i,n//i))\r\n i+=1\r\nb=[]\r\na=list(a)\r\nfor i in range(len(a)):\r\n c,d=a[i]\r\n b.append(abs(c-d))\r\nprint(*a[b.index(min(b))])", "import math\r\nn=int(input())\r\na=int(math.sqrt(n))\r\nwhile(n%a!=0):\r\n a=a-1\r\nprint(a,n//a)\r\n", "from math import sqrt, floor\r\n\r\na = int(input())\r\nb = floor(sqrt(a))\r\nwhile a % b != 0:\r\n b = b - 1\r\n\r\nprint(b, a // b)\r\n", "def solve(c):\r\n r=1\r\n cl=c\r\n for i in range(1,c+1):\r\n if c%i==0:\r\n if i>c//i:\r\n continue\r\n if c//i - i < cl-r:\r\n r=i\r\n cl=c//i\r\n return str(r) +\" \" + str(cl)\r\n\r\nc=int(input())\r\nprint(solve(c))\r\n", "a=int(input())\nb=int(a**0.5)\nwhile a%b!=0:\n\tb-=1\nprint(b,a//b)\n\t\t\t\t\t \t\t\t\t\t \t\t \t\t \t \t\t\t", "import math\r\ndef factorize(n):\r\n f=[]\r\n for i in range(1,int(math.sqrt(n))+1):\r\n if n%i==0:\r\n f.append(i)\r\n f.append(n//i)\r\n return f\r\nn=int(input())\r\nx=factorize(n)\r\nd=n-1\r\na=0\r\nb=0\r\nfor i in range(0,len(x)-1,2):\r\n if abs(x[i]-x[i+1])<=d:\r\n d=abs(x[i]-x[i+1])\r\n a=x[i]\r\n b=x[i+1]\r\nprint(a,b)\r\n", "n = int(input())\n\nl = []\n# l1 = []\n\nfor i in range(1,n+1):\n if(n%i==0):\n l.append(abs(i-(n/i)))\n\n# print(int(min(l)))\n\nfor i in range(1,n+1):\n if(n%i==0)and(abs(i-(n/i))==min(l)):\n print(i,\"\",int(n/i))\n break\n\t \t\t \t\t\t \t\t \t\t \t\t\t\t \t \t\t\t\t", "n=int(input())\r\nmin=10000000\r\nfor i in range(1,n+1,1):\r\n if n%i==0:\r\n k=int(n/i)\r\n if abs(k-i)<min:\r\n k1=i\r\n k2=k\r\n min=abs(k-i)\r\nprint(str(k1)+\" \"+str(k2))", "from math import *\r\nN=int(input())\r\nM=int(floor(sqrt(N)))\r\nwhile N%M:\r\n M-=1\r\nprint(M, N//M)", "n,z=int(input()),1\r\nfor i in range(1,int(n**(0.5))+1):\r\n\tif n%i==0:z=i\r\nprint(z,n//z)", "import math\n\ndef solve(n):\n for i in range(int(n**0.5), 0, -1):\n if n%i == 0:\n return (i, n//i)\n \nn = int(input())\ns = solve(n)\nprint(s[0], s[1])\n \n", "# coding=utf-8\r\nn=int(input())\r\nminv=n*n\r\nfor i in range(n,int(n**0.5)-1,-1):\r\n if n/i==int(n/i):\r\n a=abs(i-n/i)\r\n if a<minv:\r\n minv=a\r\n b=i\r\n c=int(n/i)\r\nprint(c,b)\r\n\r\n \t\t \t \t \t \t \t\t \t\t", "from math import sqrt\r\n\r\nn = int(input())\r\n\r\nt = int(sqrt(n))\r\n\r\nfor i in range(t , 0 , -1):\r\n #print(i)\r\n if n % i == 0 :\r\n print(i , n//i)\r\n break", "# 747 A\r\nimport math\r\nn = int(input());a = math.floor(math.sqrt(n))\r\nwhile n % a:\r\n a -= 1\r\nprint(a, ' ', n//a)\r\n", "n=int(input())\r\ni=1\r\nwhile i*i<=n:\r\n\tif n%i==0:\r\n\t\tx=i\r\n\ti+=1\r\nprint(x,int(n/x))", "import math\r\nn=int(input())\r\nm=1000000\r\nfor i in range(1,int(math.sqrt(n))+1):\r\n if(n%i==0):\r\n if(i<=n//i):\r\n if(abs(i-n//i)<m):\r\n a=i\r\n b=n//i\r\n else:\r\n break\r\nprint(a,b)\r\n \r\n \r\n", "n=int(input())\r\nl=[]\r\nl1=[]\r\nfor i in range(1,n+1):\r\n if n%i==0:\r\n p=i \r\n q=n//i \r\n l.append(i)\r\n if q-p>=0:\r\n l1.append(q-p)\r\nk=min(l1)\r\ns=l[l1.index(k)]\r\nprint(s,end=' ')\r\nprint(n//s)\r\n", "n=int(input())\r\nfor i in range(int(n**0.5),0,-1):\r\n if n%i==0:\r\n print(i,n//i)\r\n break", "n=int(input())\r\nfrom math import sqrt as S \r\nsq=int(S(n))\r\nfor i in range(sq,0,-1):\r\n if n%i==0:\r\n print(i,n//i)\r\n exit()", "import math\r\n\r\nn = int(input())\r\n\r\ns = int(math.floor(math.sqrt(n)))\r\n\r\nfor b in range(s, n+1):\r\n if n % b == 0:\r\n a = n // b\r\n if a <= b:\r\n print(a, b)\r\n exit()", "n = int(input())\r\nl = []\r\n\r\nfor i in range(1, n+1):\r\n if n % i == 0:\r\n l.append(i)\r\n\r\nif len(l) % 2 != 0:\r\n print(l[len(l)//2], l[len(l)//2])\r\nelse:\r\n print(l[len(l)//2 - 1], l[len(l)//2]) ", "from math import sqrt as koren\r\nn = int(input())\r\nans = 0\r\nfor i in range(1, int(koren(n)) + 1):\r\n if n % i == 0:\r\n ans = i\r\nprint(ans, n // ans)", "n=int(input())\r\nz=n**0.5\r\nif z%1==0:\r\n z=int(z)\r\n print(z,z)\r\nelse:\r\n z=int(z)\r\n while n%z!=0 and z>0:\r\n z-=1\r\n print(z,n//z)\r\n \r\n", "import math\r\n\r\nn = int(input())\r\nli = []\r\nfor i in range(1, n+1):\r\n if n % i == 0:\r\n li.append(i)\r\n\r\nfor i in range(len(li)-1):\r\n if li[i] * li[i+1] == n:\r\n print(li[i], li[i+1])\r\n break\r\nif float(math.sqrt(n)).is_integer():\r\n print(int(math.sqrt(n)), int(math.sqrt(n)))", "from math import sqrt\r\nn=int(input())\r\nt=int(sqrt(n))\r\nfor i in range(t,0,-1):\r\n if(n%i==0):\r\n print(i,int(n/i))\r\n break", "n=int(input())\r\nd={}\r\nfor i in range(1,n+1):\r\n if(n%i==0):\r\n if(i<=n):\r\n d.update({i:(n//i)})\r\nk=[abs(d[i]-i) for i in d]\r\nz=min(k)\r\nfor i in d:\r\n if(d[i]-i==z):\r\n print(i,d[i])\r\n exit()", "from functools import reduce\r\nimport math\r\ndef factors(n): \r\n return sorted(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\nl=factors(int(input()))\r\nif len(l) == 2:\r\n print(*l)\r\nelif len(l)%2 == 0:\r\n print(l[len(l)//2-1],l[len(l)//2])\r\nelse:\r\n print(l[len(l)//2],l[len(l)//2])", "lis = []\r\ndef print_factors(x):\r\n \r\n for i in range(1, x + 1):\r\n if x % i == 0:\r\n lis.append(i)\r\nprint_factors(int(input()))\r\n\r\nif len(lis)%2 == 0:\r\n print(lis[(len(lis)//2)-1],lis[(len(lis)//2)])\r\nelse:\r\n print(lis[(len(lis)-1)//2],lis[(len(lis)-1)//2])", "n = int(input())\r\nfor a in range(int(n**0.5),0,-1):\r\n if n / a == int(n/a):\r\n print(a,int(n/a))\r\n break\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\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=int(n**(0.5))\r\nwhile(True):\r\n if(n%(b)==0):\r\n print(b,n//b)\r\n break\r\n else:\r\n b-=1", "import math\r\nn = int(input())\r\nx = int(math.floor(math.sqrt(n)))\r\nwhile n % x != 0:\r\n x -= 1\r\nprint(x, n // x)\r\n", "number = int(input())\r\ns = []\r\ng = []\r\nl = 0\r\nn = [0,0]\r\nmaxi = number - 1\r\nb = 0\r\nminimal = 8\r\nfor i in range(number):\r\n i += 1\r\n if number %i == 0:\r\n b = number//i\r\n s.append(b)\r\n g.append(i)\r\n\r\nwhile l < len(s):\r\n if s[l] * g[l] == number:\r\n maxi = g[l] - s[l]\r\n n[0] = s[l]\r\n n[1] = g[l]\r\n b = g[l] - s[l]\r\n if s[l] * g[l] == number and g[l] > s[l] or g[l] == s[l] and b > -1:\r\n print(n[0], end = \" \")\r\n print(n[1], end = \" \")\r\n break\r\n \r\n l += 1", "n=int(input())\r\na=1\r\nl=[]\r\n\r\nwhile a**2<=n:\r\n if n%a==0:\r\n l.append(a)\r\n a+=1\r\nprint(max(l),end=\" \")\r\nprint(n//max(l))", "N = int(input())\r\nmin=N\r\nfor d in range(1,int(N**0.5)+1):\r\n if N % d == 0:\r\n if N//d-d<min:\r\n min=N//d-d\r\n min1=(d,N//d)\r\n\r\nprint(*min1)", "n = int(input())\r\n\r\na = 1\r\ncurr = 2\r\n\r\nwhile curr * curr <= n:\r\n if n % curr == 0:\r\n a = curr\r\n curr += 1\r\n\r\nprint(a, n // a)\r\n", "from math import sqrt\r\nn=int(input())\r\nq=int(sqrt(n))\r\nk=t=1\r\nfor i in range(1,q+1):\r\n if n%i==0:\r\n t=i\r\n k=max(k,t)\r\nprint(k,n//k)\r\n \r\n \r\n", "n = int(input())\r\nfor i in range(1, n + 1) :\r\n if n % i == 0 and n // i >= i :\r\n a, b = (i, n // i)\r\nprint(f\"{a} {b}\")\r\n", "n = int(input())\n\na = 1\nb = n\nwhile(a < b):\n if(n%a == 0):\n b = int(n/a)\n\n a += 1\n\nprint(str(int(n/b)) + \" \" + str(b))\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\n\r\na, b = 1, n\r\n\r\nfor i in range(1, round(n ** (1/2)) + 1):\r\n if n % i == 0:\r\n a,b = i, n // i\r\nprint(str(a) + ' ' + str(b)) ", "def factors(n):\r\n return [(i, int(n / i)) for i in range(1, int(n**0.5) + 1) if n % i == 0]\r\n#t = int(input())\r\n#for j in range(0,t+1):\r\na = int(input())\r\nb = factors(a)\r\nres = min(b, key=lambda sub: abs(sub[1] - sub[0]))\r\nprint(*res, sep=\" \")", "import math\r\nN=int(input())\r\nlas=0\r\nfor wi in range(1,int(math.sqrt(N))+1):\r\n if N%wi==0:\r\n las=wi\r\nprint('%d %d'%(las,int(N/las)))\r\n", "n = int(input())\r\ni = 1\r\nMIN = 1\r\nwhile i < n//i:\r\n i+=1\r\n if n % i == 0 and i <= n//i:\r\n MIN = i\r\nprint(MIN, n//MIN)", "n = int(input())\r\n\r\ndef getFactors(x):\r\n\r\n factors = []\r\n for i in range(1, int(n**0.5) + 1):\r\n if x % i == 0:\r\n factors.append(i)\r\n \r\n return factors\r\n\r\nf = getFactors(n)\r\nb = int( n // f[-1])\r\na = int( n // b)\r\nprint( a, b)", "import math\r\n\r\nn=int(input())\r\nfor i in range(int(math.sqrt(n)),0,-1):\r\n\tif n%i==0:\r\n\t\tprint(i,n//i)\r\n\t\tbreak\r\n\telse:\r\n\t\tcontinue", "import math\r\n\r\nn = int(input())\r\na = int(math.sqrt(n))\r\nb = int(n / a)\r\nwhile a * b != n:\r\n a -= 1\r\n b = int(n / a)\r\nprint(a, b)\r\n", "from math import *\r\nn=int(input())\r\nnum1=ceil(sqrt(n))\r\nnum2=floor(sqrt(n))\r\nwhile n%num1!=0:\r\n num1+=1\r\nwhile n%num2!=0:\r\n num2-=1\r\nprint(num2,num1)\r\n", "n=int(input())\r\nx=int(n**0.5)\r\ni=x\r\nwhile i>=1:\r\n if n%i==0 and n%(n//i)==0:\r\n print(i,n//i)\r\n break\r\n i-=1", "a = int(input())\r\nl = 0\r\nk = 0\r\nh = []\r\np = []\r\nx = []\r\ny = []\r\nfor i in range(1, a+1, 1):\r\n if a%i == 0:\r\n h.append(a//i)\r\n p.append(i)\r\nfor i in range(len(h)):\r\n if h[i] <= p[i]:\r\n x.append(h[i])\r\n y.append(p[i])\r\nf = x[0]\r\nd = y[0]\r\nfor i in range(1, len(x)-1, 1):\r\n if d - f >= y[i] - x[i]:\r\n f = x[i]\r\n d = y[i]\r\nprint(f, d)", "import sys\r\n\r\nrd = sys.stdin.readline\r\n\r\nn = int(rd())\r\n\r\nfor i in range(int(n ** 0.5), 0, -1):\r\n\r\n if n % i == 0:\r\n print(min(i, n // i), max(i, n // i))\r\n break\r\n\r\n \r\n\r\n \r\n", "n=int(input())\r\nfor i in range(int(n**0.5),0,-1):\r\n if not n%i:print(i,n//i);break", "n = int(input())\r\nfor i in range(int(n**0.5),0,-1):\r\n\tif n % i == 0:\r\n\t\tr = i\r\n\t\tbreak\r\nprint(r,n//r)", "# n^2 + n - x = 0]\r\n# 1 - 1\r\n# 2 - 3\r\n# 3 - 6\r\n# 4 - 10\r\n# 5 - 15\r\n# 6 - 21\r\n# 7 - 28\r\n# 8 - 36\r\n\r\nfrom math import *\r\n\r\nn = int(input())\r\na = 1\r\nans = 1\r\nwhile(a*a<=n):\r\n if (n%a==0):\r\n ans = a\r\n a+=1\r\nprint(ans,n//ans)", "n = int(input())\r\na, b = 1, n\r\ni = 2\r\nwhile i * i <= n:\r\n if n % i == 0 and i > a and n // i < b:\r\n a, b = i, n // i\r\n i += 1\r\nprint(a, b)", "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 = 1\r\nm = n - 1\r\nfor i in range(1, n + 1):\r\n if n // i - i < 0:\r\n break\r\n if not n % i and m > n // i - i:\r\n a = i\r\n m = n // i - i\r\nb = n // a\r\nprint(a, b)", "n = int(input())\r\nl = [0]*10**6\r\nc=k=0\r\nfor i in range(1,n+1):\r\n if(n%i==0):\r\n l[k] = i\r\n k+=1\r\n c+=1\r\nc-=1\r\nif(c&1):\r\n print(l[c//2],l[c//2+1])\r\nelse:\r\n print(l[c//2],l[c//2])", "from math import *\nn = int(input())\nfor a in range(int(sqrt(n)),0,-1):\n if n%a == 0:\n print(a,n//a)\n break\n", "n = int(input())\r\nminimum=n\r\nfor a in range(1,n+1):\r\n if n%a!=0:\r\n continue\r\n b = int(n/a)\r\n if b>a:\r\n continue\r\n else:\r\n if abs(b-a)<minimum:\r\n minimum=b-a\r\n itog1=int(a)\r\n itog2=int(b)\r\nprint(itog2,itog1)\r\n\r\n", "n = int(input())\r\n\r\nres = 10000000\r\na = 0\r\nb = 0\r\n\r\n\r\ni = 1\r\nwhile i * i <= n:\r\n if n % i == 0:\r\n a = i\r\n b = n // i\r\n i += 1\r\n\r\nprint(a, b)", "n = int(input())\r\nk = int(n ** 0.5)\r\nwhile n % k:\r\n k -= 1\r\nprint(k,n // k)", "# A. Display Size\n\nfrom math import sqrt\n\nn = int(input())\na = int(sqrt(n))\n\nwhile a > 0:\n if n % a == 0:\n break\n else:\n a -= 1\n\nprint(a, n // a)\n", "from math import *\r\nn = int(input().strip())\r\np = {}\r\na = []\r\nfor i in range(1,int(sqrt(n)+1)):\r\n if n % i == 0:\r\n k = int(n / i)\r\n p[k-i] = (i,k)\r\n a.append(k-i)\r\nprint(*p[min(a)])", "import math\nn = int(input())\nans = 1\nfor i in range(1, int(math.sqrt(n))+1):\n if(n % i == 0):\n ans = i\nprint(ans, n//ans)", "def main():\n n = int(input())\n for h in range(int(n ** .5), 0, -1):\n if not n % h:\n break\n print(h, n // h)\n\n\nif __name__ == '__main__':\n main()\n", "n = int(input())\r\n\r\na = 1\r\nb = n\r\n\r\nfor i in range(1, n+1):\r\n if n % i == 0 and abs(i - n/i) < b - a:\r\n a = min(i, n/i)\r\n b = max(i, n/i)\r\n\r\nprint(int(a), int(b))\r\n", "n = int(input())\r\na,b = 1,n\r\nwhile a*a<=n:\r\n if n%a == 0:\r\n b=n//a\r\n a+=1\r\nprint(n//b, b)\r\n", "n= int(input())\r\nmini = pow(10,7)\r\nfactors = []\r\nfor i in range(1,n+1):\r\n if n%i==0 and i<= n//i:\r\n factors.append((i,n//i))\r\nfor i in factors:\r\n if(i[1] - i[0]<mini):\r\n mini = i[1] - i[0]\r\nfor i in factors:\r\n if (i[1] - i[0] == mini):\r\n print(i[0] , i[1])", "num = int(input())\r\nmn = float(\"inf\")\r\nans = []\r\nfor i in range(1, int(num**0.5)+1):\r\n if num % i == 0:\r\n add = i + num //i\r\n if add < mn:\r\n ans = [i, num//i]\r\n\r\nprint(*ans)\r\n\r\n", "from math import sqrt\r\n\r\n\r\ndef monitor(razmer):\r\n a, b = 1, razmer\r\n for i in range(1, int(sqrt(razmer)) + 1):\r\n if razmer % i == 0:\r\n a, b = i, razmer // i\r\n return a, b\r\n\r\n\r\nprint(*monitor(int(input())))\r\n", "import sys\r\n\r\ndef main():\r\n n = int(sys.stdin.read().strip())\r\n return next((i, n//i) for i in range(int(n**.5), 0, -1) if not n%i)\r\n \r\nprint(*main())\r\n", "n=int(input())\r\nx=1\r\nwhile x*x<=n:\r\n if n%x<1:r=x\r\n x+=1\r\nprint(r,n//r)", "import math\n\nn = int(input())\na = math.floor(math.sqrt(n))\nwhile a > 0:\n if n % a == 0:\n b = n // a\n break\n a -= 1\nprint(a, b)\n", "n=int(input())\r\nimport math\r\na=int(math.pow(n,.5))\r\nfor i in range(a,0,-1):\r\n b=n/i\r\n if int(b+0.9)==b:\r\n print(i,int(b))\r\n break\r\n", "import math\r\nn = int(input())\r\nsq = int(math.sqrt(n))\r\nwhile(n%sq != 0):\r\n sq -= 1\r\nt = n//sq\r\nprint(min(t,sq),max(t,sq))\r\n \r\n", "anum = int(input())\nfactor1 = int(anum**0.5)\n# while anum % factor1 != 0\nwhile factor1 > 0:\n if (anum/factor1).is_integer():\n if int(anum/factor1) < factor1:\n print(int(anum/factor1), factor1)\n else:\n print(factor1, int(anum/factor1))\n break\n else:\n factor1 -= 1\n continue\n\t\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\na=1\r\nb=n\r\nansa=1\r\nansb=n\r\nmi=abs(b-a)\r\nfor i in range(0,n//2):\r\n a+=1\r\n if n%a==0:\r\n b=n//a\r\n if abs(b-a)<mi:\r\n mi=abs(b-a)\r\n ansa=a\r\n ansb=b\r\nprint(ansa,ansb)\r\n", "n=int(input())\r\nfrom math import*\r\nb=(sqrt(n))//1\r\n\r\ns=0\r\na=int(b)\r\n\r\nfor i in range(1,a+1):\r\n if (n%i==0)and (s<i):\r\n s=i\r\n\r\nk=n//s\r\n\r\nprint(s,k)\r\n \r\n\r\n", "n = int(input())\r\n \r\na = 0\r\nb = 0\r\nm = n\r\n \r\nfor i in range(n, 0, -1):\r\n a1 = i\r\n b1 = n // a1\r\n \r\n if a1 * b1 == n:\r\n m1 = abs(a1-b1)\r\n if m1 < m: \r\n a = min(a1, b1)\r\n b = max(a1, b1)\r\n m = m1\r\n if m == 0:\r\n break\r\n \r\nprint(a, b)", "n = int(input())\r\na = int(n ** 0.5)\r\nb = int(n / a)\r\nwhile True:\r\n if a * b == n:\r\n print(min(a, b), max(a, b))\r\n break\r\n a += 1\r\n b = int(n / a)", "n = int(input())\r\n\r\nmin_dif = n\r\nans = 1, n\r\nfor a in range(1, n + 1):\r\n if n % a == 0:\r\n b = n // a\r\n if (a <= b) and (b - a < ans[1] - ans[0]):\r\n ans = a, b\r\n\r\nprint(*ans)\r\n\r\n", "from math import sqrt\r\nn=int(input())\r\na=int(sqrt(n))\r\nwhile a>0:\r\n if n%a==0:\r\n print(a,n//a,sep=\" \")\r\n exit()\r\n a-=1", "import sys\r\nn=int(input())\r\nt=n//2\r\nmi=sys.maxsize\r\nif n==1:\r\n print('1','1')\r\nelse:\r\n while t <= n:\r\n if n % t == 0:\r\n t1 = n // t\r\n m = abs(t - t1)\r\n if m < mi:\r\n mi = m\r\n a = min(t, t1)\r\n b = max(t, t1)\r\n t += 1\r\n t = n // 2\r\n while t > 0:\r\n if n % t == 0:\r\n t1 = n // t\r\n m = abs(t - t1)\r\n if m < mi:\r\n mi = m\r\n a = min(t, t1)\r\n b = max(t, t1)\r\n t -= 1\r\n print(a, b)", "# Author : Ghulam Junaid aka redhaired ( not redhaired tho )\r\nn = int(input())\r\ntreasure = 1\r\nfor i in range(int(n**0.5),1,-1):\r\n if n%i == 0:\r\n treasure = i\r\n break\r\nprint(treasure,n//treasure)", "n = int(input())\r\nfor i in range(int(n**(0.5)), 0, -1):\r\n if n%i == 0: print(i, n//i); break\r\n", "n = int(input())\n\na = 1\nmn = n\nans = (1, n)\nwhile a*a <= n:\n if n % a == 0:\n b = n // a\n if abs(b - a) < mn:\n mn = abs(b - a)\n ans = (a, b)\n a += 1\n\nprint(*ans)\n\n", "n = int(input())\r\na = int(n**0.5)\r\nwhile a:\r\n if not n%a:\r\n print(a, int(n/a))\r\n break\r\n a -= 1\r\nelse:\r\n print(1, n)\r\n", "from math import floor,ceil\r\ndef func(intput):\r\n n = intput()\r\n for i in range(n,0,-1):\r\n a,b = i,n/i\r\n if a > b: continue\r\n if floor(b) == ceil(b): print(a,int(b)); return\r\n\r\ndef init(flag=True):\r\n intput = lambda : int(input())\r\n for _ in range(int(input()) if flag else 1):\r\n func(intput)\r\n\r\nif __name__ == '__main__':\r\n init(0)", "n = int(input())\r\na = 1\r\nr = 0\r\nwhile a*a <= n:\r\n\tif n % a == 0:\r\n\t\tr = a\r\n\ta += 1\r\nprint(r, n//r)", "import math\r\nfrom fractions import Fraction as frac\r\n\r\nMOD = 1e9 + 7\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 return a * b // gcd(a, b)\r\n\r\ndef solve(case_no):\r\n n = int(input())\r\n for i in range(math.floor(math.sqrt(n)), 0, -1):\r\n if n % i == 0:\r\n print(i, n // i)\r\n exit()\r\n\r\nt = 1\r\n# t = int(input())\r\nfor i in range(1, t + 1):\r\n solve(i)\r\n", "import math\r\n\r\na=int(input())\r\n\r\nb=math.sqrt(a)\r\nif b==int(b):\r\n print(int(b),int(b))\r\nelse:\r\n p=[]\r\n for j in range(a//2,0,-1):\r\n if a%j==0:\r\n p.append([abs(j-a//j),j])\r\n\r\n p.sort()\r\n\r\n print(p[0][1],a//p[0][1])\r\n \r\n", "n = int(input())\r\nans = 1\r\nfor i in range(int(n ** 0.5)+2,0,-1):\r\n if n % i == 0 and n // i >= i:\r\n ans = i\r\n break\r\nprint(ans, n // ans)\r\n", "import math\r\nn = int(input())\r\n\r\ndef factors(x):\r\n listy = []\r\n for i in range(1, x+1):\r\n if x % i == 0:\r\n listy.append(i)\r\n return listy\r\n\r\n\r\nfactors = factors(int(n))\r\n\r\nmin = math.inf\r\nfor x in factors:\r\n list2 = []\r\n a = x\r\n b = n/x\r\n if a <= b:\r\n # print(a, b)\r\n if (b-a) < min:\r\n min = b-a\r\n\r\nfor x in factors:\r\n a = x\r\n b = n/x\r\n if (b-a) == min:\r\n print(int(a), int(b))\r\n", "n = int(input())\r\nres = 1\r\n\r\nfor i in range(2, int(n**0.5)+1):\r\n if n%i == 0:\r\n res = i\r\nprint(res, n//res)\r\n", "import math\r\nn = int(input())\r\nr = int(math.sqrt(n))\r\nwhile True:\r\n if n%r==0:\r\n break\r\n r -= 1\r\nprint(r,n//r)\r\n", "import sys\r\nnum=sys.stdin.readline()\r\nnum=int(num)\r\nfirst=0\r\nans =0\r\nsecond = 10**8\r\nfor i in range (1,num+1):\r\n first=float(num)/i\r\n if first == int(first):\r\n if abs(first-i) < second :\r\n second = abs(first - i)\r\n ans=i\r\n\r\nprint (int (min(num/ans , ans)) ,int ( max(num/ans ,ans )))\r\n", "import math\r\n\r\nn = int(input())\r\nsq = int(math.sqrt(n))\r\nwhile n % sq != 0:\r\n sq -= 1\r\nprint(sq, n // sq)", "from math import*\r\n#n,k=map(int, input().split())\r\nn=int(input())\r\n#l=list(map(int, input().split()))\r\n#s=input()\r\nk=int(pow(n,1/2))\r\nfor i in range(k,0,-1):\r\n if n%i==0:\r\n print(i,n//i)\r\n break", "from cmath import sqrt\r\n\r\n\r\ndef solves():\r\n n=int(input())\r\n m=1\r\n temp=int(n**0.5)\r\n for i in range(1,temp+1):\r\n if n%i==0:\r\n m=max(m,i)\r\n print(m,n//m)\r\n\r\nfor _ in range(1):\r\n solves()\r\n", "import math\n\nwhile True:\n try:\n num = int(input())\n ans = int(math.sqrt(num))\n while True:\n if num % ans == 0:\n print(ans, num // ans)\n break\n else:\n ans -= 1\n except EOFError:\n break\n\n \t \t \t \t\t \t \t \t \t\t\t\t \t \t", "n = int(input())\r\na = 1\r\nans = 10**18\r\nwhile a*a <= n:\r\n if n%a == 0:\r\n b = n//a\r\n if b-a < ans:\r\n ans = b-a\r\n ans_a = a\r\n a+=1\r\nprint(ans_a, n//ans_a)", "n=int(input())\r\nfor i in range(int(n**0.5),0,-1):\r\n\tif n% i==0:\r\n\t\ta=i\r\n\t\tbreak\r\nprint(a,n//a)", "import math\r\n\r\nn = int(input())\r\n\r\nfor i in range(1, int(math.sqrt(n)) + 1):\r\n if not (n % i):\r\n ans = [i, n // i]\r\n\r\nprint(ans[0], ans[1])", "a=int(input())\r\nb=(a**(1/2))\r\nif b == int(b):\r\n print (int(b),int(b))\r\n\r\nelse:\r\n if a==2:\r\n print(1,2)\r\n else:\r\n \r\n y=1\r\n z=a/2\r\n entre=0\r\n primero=1\r\n while y<z:\r\n entre=1\r\n \r\n if a%y==0:\r\n z=a//y\r\n primero=y\r\n y=y+1\r\n print(primero,int(z))", "import math\r\nn = int(input())\r\na = math.floor(math.sqrt(n))\r\nwhile n % a != 0:\r\n a -= 1\r\nprint(a, n // a)\r\n", "n = int(input())\r\nif n == 1:\r\n print('1' + ' ' + '1')\r\nelse:\r\n a = 1\r\n numbers = []\r\n while a != n:\r\n if n // a < a:\r\n break\r\n if n % a == 0:\r\n numbers.append([a, n // a])\r\n a += 1\r\n\r\n differences = []\r\n hashtable = {}\r\n for num in numbers:\r\n hashtable[abs(num[1] - num[0])] = [num[0], num[1]]\r\n differences.append(abs(num[1] - num[0]))\r\n\r\n min_difference = min(differences)\r\n\r\n print(*hashtable[min_difference])\r\n\r\n\r\n", "n=int(input())\r\nmaxi = 100000000000000;\r\nfor i in range(1,n+1):\r\n A=i;\r\n if n%i==0:\r\n B=n//i;\r\n if A<=B:\r\n C=abs(A-B)\r\n if C<maxi:\r\n maxi=C;\r\n ans1=A;\r\n ans2=B;\r\nprint(ans1,ans2)", "from math import sqrt, floor\n\nn = int(input())\nfor i in reversed(range(1, floor(sqrt(n)) + 1)):\n if i * (n // i) == n:\n res = i, n // i\n break\nprint(*res)\n", "n = int(input()) \r\na, b, min_dif = 1, n, n - 1\r\nfor i in range(n, 0, -1):\r\n if n % i == 0 and min_dif > i - n // i and i - n // i >= 0:\r\n a, b, min_dif = n // i, i, i - n // i\r\n\r\nprint(a, b)", "n=int(input())\r\nr=n**0.5\r\nfor i in range(int(r)):\r\n\tt=n/(int(r)-i)\r\n\tif t%1==0:\r\n\t\tprint(int(r)-i,int(t))\r\n\t\tbreak", "from math import sqrt\r\n\r\n\r\ndef get_ld(x):\r\n last_div = 1\r\n for i in range(2, int(sqrt(x))+1):\r\n if x % i == 0:\r\n last_div = i\r\n return last_div\r\n\r\nx = int(input())\r\nd = get_ld(x)\r\nprint(d, x // d)\r\n", "n = int(input())\r\ni = 1\r\nans = 1\r\nwhile(i*i<=n):\r\n if(n%i==0): \r\n ans = i\r\n i+=1\r\nprint (ans,n//ans)\r\n", "import math\r\nn = int(input())\r\nans = -1\r\nfor i in range(1, 1 + int(math.sqrt(n))) :\r\n\tif (n % i == 0) and (ans < i) :\r\n\t\tans = i\r\nprint(ans, int(n / ans))", "from math import sqrt \r\nn = int(input())\r\nb = 1.5\r\nif sqrt(n) % 1 == 0:\r\n print(int(sqrt(n)),int(sqrt(n)))\r\nelse:\r\n p = int(sqrt(n))+1\r\n while b%1 !=0:\r\n p-=1\r\n b =n/p\r\n print(p,int(b))", "n=int(input())\r\ndef ispersqr(a):\r\n sr=a**0.5\r\n if sr - int(sr)==0:\r\n return int(sr)\r\n else:\r\n return 0\r\nch=ispersqr(n)\r\nif ch:\r\n print(ch,ch)\r\nelse:\r\n l=[i for i in range(2,int(n/2)+1) if n%i==0]\r\n p=len(l)\r\n if p==0:\r\n print(1,n)\r\n else:\r\n q=int(p/2)\r\n print(l[q-1],l[q])", "n = int(input())\r\npp = []\r\nk = []\r\nfor i in range(1,int(n**0.5)+1):\r\n if n % i == 0:\r\n l = n//i\r\n k.append(abs(i - l))\r\n pp.append(str(min(l,i)))\r\n pp.append(str(max(l,i)))\r\nl = min(k)\r\nfor j in range(0,len(k)):\r\n if k[j] == l:\r\n break\r\nprint(' '.join(pp[2*j:(2*j)+2]))", "n=int(input())\r\ni=int(n**0.5)\r\ntest=False\r\nwhile test==False :\r\n if n%i ==0 :\r\n test=True\r\n i=i-1\r\nprint(i+1,n//(i+1)) \r\n \r\n \r\n", "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\tn=read_int()\n\tfrom math import sqrt\n\tr=int(sqrt(n))\n\tfor i in range(r, -1, -1):\n\t\tif n%i!=0:\n\t\t\tcontinue\n\t\tprint(i, n//i)\n\t\tbreak\n\nsolve()\n", "n=int(input())\r\na=int(n**0.5)\r\nfor i in range(a):\r\n\tb=n/(a-i)\r\n\tif b%1==0:\r\n\t\tprint(a-i,int(b))\r\n\t\tbreak", "n=int(input())\r\nk=int(n**(0.5))\r\nwhile n%k!=0:\r\n\tk-=1\r\nprint(k,n//k)", "from math import *\r\nx=int(input())\r\nl=[]\r\nfor i in range(1,int(sqrt(x))+1):\r\n if x%i==0:\r\n l.append(i)\r\nl.sort(reverse=True)\r\nif l[0]*l[0]==x:\r\n print(l[0],l[0],sep=' ')\r\n \r\nelse:\r\n print(l[0],x//l[0],sep=' ')\r\n", "def solve(n):\r\n r = k = 1\r\n while k * k <= n:\r\n if n % k == 0: r = k\r\n k += 1\r\n return \"%d %d\" % (r, n / r)\r\n\r\nprint(solve(int(input())))\r\n", "a=int(input())\r\nb=int(a**0.5)\r\nwhile a%b!=0:\r\n\tb-=1\r\nprint(b,a//b)" ]
{"inputs": ["8", "64", "5", "999999", "716539", "1", "2", "3", "4", "6", "7", "9", "10", "11", "12", "15", "100", "101", "169", "179", "190", "1000", "10000", "10001", "100000", "100001", "1000000", "999983", "524288", "954493", "966289", "944663", "912673", "732641", "232897", "16807", "999958", "990151", "997002", "20", "20261", "999123", "901841"], "outputs": ["2 4", "8 8", "1 5", "999 1001", "97 7387", "1 1", "1 2", "1 3", "2 2", "2 3", "1 7", "3 3", "2 5", "1 11", "3 4", "3 5", "10 10", "1 101", "13 13", "1 179", "10 19", "25 40", "100 100", "73 137", "250 400", "11 9091", "1000 1000", "1 999983", "512 1024", "971 983", "983 983", "961 983", "97 9409", "679 1079", "343 679", "49 343", "2 499979", "1 990151", "998 999", "4 5", "1 20261", "3 333041", "1 901841"]}
UNKNOWN
PYTHON3
CODEFORCES
236
16a03da19a666d6d16782abb48417091
Division into Teams
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers). The key in football is to divide into teams fairly before the game begins. There are *n* boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic *a**i* (the larger it is, the better the boy plays). Let's denote the number of players in the first team as *x*, the number of players in the second team as *y*, the individual numbers of boys who play for the first team as *p**i* and the individual numbers of boys who play for the second team as *q**i*. Division *n* boys into two teams is considered fair if three conditions are fulfilled: - Each boy plays for exactly one team (*x*<=+<=*y*<==<=*n*). - The sizes of teams differ in no more than one (|*x*<=-<=*y*|<=≤<=1). - The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. The first line contains the only integer *n* (2<=≤<=*n*<=≤<=105) which represents the number of guys in the yard. The next line contains *n* positive space-separated integers, *a**i* (1<=≤<=*a**i*<=≤<=104), the *i*-th number represents the *i*-th boy's playing skills. On the first line print an integer *x* — the number of boys playing for the first team. On the second line print *x* integers — the individual numbers of boys playing for the first team. On the third line print an integer *y* — the number of boys playing for the second team, on the fourth line print *y* integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: *x*<=+<=*y*<==<=*n*, |*x*<=-<=*y*|<=≤<=1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. Sample Input 3 1 2 1 5 2 3 3 1 1 Sample Output 2 1 2 1 3 3 4 1 3 2 5 2
[ "n = int(input())\r\na = list(map(int,input().split()))\r\nb = list(range(1,n+1))\r\nz = sorted(list(zip(a,b)))\r\nx = [] \r\ny = [] \r\nsx = 0 \r\nsy = 0 \r\nfor i,j in z:\r\n if sx<=sy:\r\n x.append(j)\r\n sx+=i\r\n else:\r\n y.append(j)\r\n sy+=i\r\nprint(len(x))\r\nprint(*x)\r\nprint(len(y))\r\nprint(*y)", "import sys\r\nimport math\r\nfrom sys import stdin, stdout\r\n \r\n# TAKE INPUT\r\ndef get_ints_in_variables():\r\n return map(int, sys.stdin.readline().strip().split())\r\ndef get_int(): return int(input())\r\ndef get_ints_in_list(): return list(\r\n map(int, sys.stdin.readline().strip().split()))\r\ndef get_list_of_list(n): return [list(\r\n map(int, sys.stdin.readline().strip().split())) for _ in range(n)]\r\ndef get_string(): return sys.stdin.readline().strip()\r\n \r\ndef main():\r\n # Write Your Code Here\r\n n = int(input())\r\n arr = get_ints_in_list()\r\n\r\n store = []\r\n for i in range(0, n):\r\n store.append([arr[i], str(i+1)])\r\n store.sort(reverse=True)\r\n first = []\r\n second = []\r\n start = 0\r\n end = n\r\n while start < end:\r\n first.append(store[start][1])\r\n start += 1\r\n if start < n:\r\n second.append(store[start][1])\r\n start += 1\r\n print(len(first))\r\n for i in range(0, len(first)):\r\n print(first[i],end=\" \")\r\n print()\r\n print(len(second))\r\n for i in range(0, len(second)):\r\n print(second[i],end=\" \")\r\n\r\n# calling main Function\r\nif __name__ == \"__main__\":\r\n main()", "# @Chukamin ICPC_TRAIN\n\ndef main():\n n = int(input())\n data = list(map(int, input().split()))\n num = [[i + 1, 0] for i in range(n)]\n for i in range(n):\n num[i][1] = data[i]\n num.sort(key = lambda x: x[1])\n \n pqc = n // 4\n pqn = pqc * 4\n p = q = pqn // 2\n r = n % 4\n pl = []\n ql = []\n psum = 0\n qsum = 0\n\n\n for i in range(pqn):\n if i % 4 == 0 or i % 4 == 3:\n pl.append(num[i][0])\n psum += num[i][1]\n else:\n ql.append(num[i][0])\n qsum += num[i][1]\n\n if r == 1:\n if psum > qsum:\n q += 1\n ql.append(num[pqn][0])\n else:\n p += 1\n pl.append(num[pqn][0])\n elif r == 2:\n if psum > qsum:\n p += 1\n q += 1\n pl.append(num[pqn][0])\n ql.append(num[pqn + 1][0])\n else:\n p += 1\n q += 1\n ql.append(num[pqn][0])\n pl.append(num[pqn + 1][0])\n elif r == 3:\n if psum > qsum:\n p += 1\n q += 2\n ql.append(num[pqn][0])\n pl.append(num[pqn + 1][0])\n ql.append(num[pqn + 2][0])\n else:\n p += 2\n q += 1\n pl.append(num[pqn][0])\n ql.append(num[pqn + 1][0])\n pl.append(num[pqn + 2][0])\n\n\n print(p)\n print(' '.join(map(str, pl)))\n print(q)\n print(' '.join(map(str, ql))) \n \nif __name__ == '__main__':\n main()\n\n \t\t\t \t \t\t \t \t \t \t\t\t \t\t", "from functools import lru_cache\n@lru_cache(maxsize=None)\ndef solve() : \n arr.sort()\n a=[]\n b=[]\n for i in range(n) :\n if i%2==0 :\n a.append(arr[i][1])\n else:\n b.append(arr[i][1])\n print(len(a))\n print(*a)\n print(len(b))\n print(*b)\n\n\n \n \n \n\n\n\n \n \n\n\n\n#from bisect import bisect_left as bisect\nfrom math import ceil,floor\nfrom collections import defaultdict,Counter\nfrom sys import stdin ,stdout #, setrecursionlimit\ninput = stdin.buffer.readline \nimport threading\nout=stdout.write \n#setrecursionlimit(100002) \n\nn=int(input())\narr=list(map(int, input().split()))\nfor i in range(n):\n arr[i]=[arr[i],i+1]\nsolve()\nquit()\n\nfor _ in range(int(input())) :\n n,k= list(map(int, input().split()))\n arr=list(map(int, input().split()))\n out(str(solve())+'\\n')\n\n'''\n\nthreading.stack_size(2**24)\nt = threading.Thread(target=main)\nt.start()\nt.join()\n\n\n\n\n\nfor _ in range(int(input())) :\n n=int(input())\n print(solve())\n\n\nn=int(input())\n\nx=input().strip().decode(\"utf-8\")\n\n\nn,m= list(map(int, input().split()))\n\n\nn=int(input())\n arr=list(map(int, input().split()))\n\nn,k= list(map(int, input().split()))\narr=list(map(int, input().split()))\n\n\narr=list(map(int, input().strip().decode(\"utf-8\")))\n\n\nn,m= [int(x) for x in input().split()]\narr=[list(map(int, input().split())) for _ in range(n)]\n\n\nn,m= [int(x) for x in input().split()]\narr=[list(map(int, input().strip().decode(\"utf-8\"))) for _ in range(n)]\n\n\n\nn=int(input())\narr=[list(map(int, input().split())) for _ in range(n)]\n\n\n\nn,m= list(map(int, input().split()))\n arr=[list(input().strip().decode(\"utf-8\")) for _ in range(n)]\n\n\n\n\nfor _ in range(int(input())) :\n \n\n n=int(input())\n arr=list(map(int, input().split()))\n\n d={}\n leaves={}\n\n for i in range(n):\n d[i+1]=[]\n leaves[i+1]=1\n \n for i in range(1,n):\n d[arr[i-1]].append(i+1)\n if arr[i-1] in leaves :\n leaves.pop(arr[i-1])\n\n\n\n\n\n\n'''\n\n\n\n\n\n\n\n", "n = int(input())\r\nls = []\r\nl = list(map(int,input().split()))\r\nfor i in range(n) :\r\n ls.append([l[i],i+1])\r\nls.sort()\r\nprint((n+1)//2)\r\nfor i in range(0,n,2) :\r\n print(ls[i][1],end=' ')\r\nprint('\\n'+str(n//2))\r\nfor i in range(1,n,2) :\r\n print(ls[i][1],end=' ')", "n = int(input())\na = list(map(int, input().split()))\nl = [(a[i], i+1) for i in range(n)]\nl.sort(reverse = True)\n\n# print(l)\nx = 1\ny = 1\nxx = [l[0][1]]\nsx = l[0][0]\nyy = [l[1][1]]\nsy = l[1][0]\n\nfor i in range(2, n):\n if i%2==0:\n sx+=l[i][0]\n xx.append(l[i][1])\n x+=1\n else:\n sy+=l[i][0]\n yy.append(l[i][1])\n y+=1\n\nif abs(sx-sy)<=l[0][0]:\n print(x)\n print(*xx)\n print(y)\n print(*yy)\nelse:\n t = a[xx[1]-1]\n u = xx[1]\n x-=1\n sx-=t\n xx.pop(1)\n y+=1\n sy+=t\n yy.append(u)\n print(x)\n print(*xx)\n print(y)\n print(*yy)\n\n\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\nl=[]\r\nfor i in range(n):\r\n l+=[[a[i],i]]\r\nl.sort(key=lambda x:x[0])\r\nq=[[],[]]\r\nfor i in range(n):\r\n q[i%2]+=[l[i][1]+1]\r\nprint(len(q[0]))\r\nprint(*q[0])\r\nprint(len(q[1]))\r\nprint(*q[1])", "n = int(input())\r\na = list(map(int,input().split()))\r\ns = sum(a)\r\nmx = max(a)\r\na = [[a[i], i+1] for i in range(n)]\r\na.sort()\r\no = []\r\nt = []\r\nos = 0\r\nts = 0\r\na = a[::-1]\r\n\r\nwhile len(a) >= 2:\r\n x,i = a.pop()\r\n y,j = a.pop()\r\n if os <= ts:\r\n o.append(j)\r\n t.append(i)\r\n os+= y\r\n ts += x\r\n else:\r\n o.append(i)\r\n t.append(j)\r\n ts += y\r\n os += x\r\n\r\nif a:\r\n if os < ts:\r\n o.append(a[0][1])\r\n os += a[0][0]\r\n else:\r\n t.append(a[0][1])\r\n ts += a[0][0]\r\n \r\nif abs(os-ts) <= mx:\r\n print(len(o))\r\n print(*o)\r\n print(len(t))\r\n print(*t)\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\na = list(map(int, input().split()))\r\nb = [a[i] * n + i for i in range(n)]\r\nb.sort(reverse = True)\r\nfor i in range(n):\r\n b[i] %= n\r\np, q = [], []\r\nd = 0\r\nif n % 2:\r\n p.append(b[-1] + 1)\r\n d = a[b[-1]]\r\nfor i in range(n // 2):\r\n u, v = b[2 * i], b[2 * i + 1]\r\n au, av = a[u], a[v]\r\n if d >= 0:\r\n if au >= av:\r\n p.append(v + 1)\r\n q.append(u + 1)\r\n else:\r\n p.append(u + 1)\r\n q.append(v + 1)\r\n d -= abs(au - av)\r\n else:\r\n if au >= av:\r\n p.append(u + 1)\r\n q.append(v + 1)\r\n else:\r\n p.append(v + 1)\r\n q.append(u + 1)\r\n d += abs(au - av)\r\nx, y = len(p), len(q)\r\nprint(x)\r\nsys.stdout.write(\" \".join(map(str, p)) + \"\\n\")\r\nprint(y)\r\nsys.stdout.write(\" \".join(map(str, q)))", "n=int(input())\r\na=list(map(int, input().split(\" \")))\r\n\r\nb=[[i+1, 0] for i in range(n)]\r\nfor i in range(n):\r\n b[i][1] = a[i]\r\nb.sort(key = lambda x: x[1])\r\np,q=0,0\r\npl,ql=[],[]\r\n\r\nst = 1\r\nfor i in range(n):\r\n if st == 1:\r\n p += 1\r\n pl.append(b[i][0])\r\n else:\r\n q += 1\r\n ql.append(b[i][0])\r\n st = -st\r\n \r\nprint(p)\r\nprint(*pl)\r\nprint(q)\r\nprint(*ql)", "import abc\r\nimport 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 = int(input())\r\n a = list(map(int, input().split()))\r\n\r\n a = [[a[i], i + 1] for i in range(n)]\r\n a.sort(key=lambda x: (x[0], x[1]))\r\n\r\n teams = [[], []]\r\n t1, t2 = 0, 0\r\n for i in range(n):\r\n if t1 <= t2:\r\n teams[0].append(a[i][1])\r\n t1 += a[i][0]\r\n else:\r\n teams[1].append(a[i][1])\r\n t2 += a[i][0]\r\n\r\n for i in range(2):\r\n print(len(teams[i]))\r\n print(*teams[i])\r\n\r\n\r\nif __name__ == '__main__':\r\n multi_test = 0\r\n\r\n if multi_test == 1:\r\n t = int(sys.stdin.readline())\r\n for _ in range(t):\r\n solve()\r\n else:\r\n solve()\r\n", "n=int(input())\r\nst=list(map(int,input().split()))\r\nb=[]\r\nfor i in range(0,n):\r\n b.append([st[i],i+1])\r\nb.sort()\r\nx,y=[],[]\r\nfor i in range(0,n):\r\n if i%2==0:\r\n x.append(b[i][1])\r\n else:\r\n y.append(b[i][1])\r\nprint(len(x))\r\nprint(*x)\r\nprint(len(y))\r\nprint(*y)\r\n", "# from dust i have come, dust i will be\n\nn = int(input())\na = list(map(int, input().split()))\n\narr = []\nfor i in range(n):\n arr.append((a[i], i + 1))\n\narr.sort(reverse=True)\n\nt1 = []\nt2 = []\nsum1 = 0\nsum2 = 0\n\nex = -1\nif n % 2 == 1:\n ex = arr[n - 1][1]\n n -= 1\n\nfor i in range(0, n, 2):\n if arr[i][0] >= arr[i + 1][0]:\n mx = arr[i][0]\n mn = arr[i + 1][0]\n\n imx = arr[i][1]\n imn = arr[i + 1][1]\n\n else:\n mn = arr[i][0]\n mx = arr[i + 1][0]\n\n imn = arr[i][1]\n imx = arr[i + 1][1]\n\n if sum1 <= sum2:\n sum1 += mx\n sum2 += mn\n t1.append(imx)\n t2.append(imn)\n else:\n sum1 += mn\n sum2 += mx\n t1.append(imn)\n t2.append(imx)\n\nif sum1 < sum2 and ex != -1:\n t1.append(ex)\n\nelif sum2 <= sum1 and ex != -1:\n t2.append(ex)\n\nprint(len(t1))\nfor i in range(len(t1)):\n print(t1[i], end=' ')\n\nprint()\n\nprint(len(t2))\nfor i in range(len(t2)):\n print(t2[i], end=' ')\n" ]
{"inputs": ["3\n1 2 1", "5\n2 3 3 1 1", "10\n2 2 2 2 2 2 2 1 2 2", "10\n2 3 3 1 3 1 1 1 2 2", "10\n2 3 2 3 3 1 1 3 1 1", "11\n1 3 1 2 1 2 2 2 1 1 1", "11\n54 83 96 75 33 27 36 35 26 22 77", "11\n1 1 1 1 1 1 1 1 1 1 1", "2\n1 1", "2\n35 36", "25\n1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 1 2 2 2 1 1 2 2 1", "27\n2 1 1 3 1 2 1 1 3 2 3 1 3 2 1 3 2 3 2 1 2 3 2 2 1 2 1", "30\n2 2 2 3 4 3 4 4 3 2 3 2 2 4 1 4 2 4 2 2 1 4 3 2 1 3 1 1 4 3", "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2", "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52", "100\n2382 7572 9578 1364 2325 2929 7670 5574 2836 2440 6553 1751 929 8785 6894 9373 9308 7338 6380 9541 9951 6785 8993 9942 5087 7544 6582 7139 8458 7424 9759 8199 9464 8817 7625 6200 4955 9373 9500 3062 849 4210 9337 5466 2190 8150 4971 3145 869 5675 1975 161 1998 378 5229 9000 8958 761 358 434 7636 8295 4406 73 375 812 2473 3652 9067 3052 5287 2850 6987 5442 2625 8894 8733 791 9763 5258 8259 9530 2050 7334 2118 2726 8221 5527 8827 1585 8334 8898 6399 6217 7400 2576 5164 9063 6247 9433", "3\n1 2 3", "3\n10 10 10", "3\n5 10 10", "5\n6 1 1 1 1", "5\n1 100 2 200 3"], "outputs": ["2\n1 2 \n1\n3 ", "3\n4 1 3 \n2\n5 2 ", "5\n8 2 4 6 9 \n5\n1 3 5 7 10 ", "5\n4 7 1 10 3 \n5\n6 8 9 2 5 ", "5\n6 9 1 2 5 \n5\n7 10 3 4 8 ", "6\n1 5 10 4 7 2 \n5\n3 9 11 6 8 ", "6\n10 6 8 1 11 3 \n5\n9 5 7 4 2 ", "6\n1 3 5 7 9 11 \n5\n2 4 6 8 10 ", "1\n1 \n1\n2 ", "1\n1 \n1\n2 ", "13\n1 10 17 22 2 5 7 9 13 15 18 20 24 \n12\n4 11 21 25 3 6 8 12 14 16 19 23 ", "14\n2 5 8 15 25 1 10 17 21 24 4 11 16 22 \n13\n3 7 12 20 27 6 14 19 23 26 9 13 18 ", "15\n15 25 28 2 10 13 19 24 6 11 26 5 8 16 22 \n15\n21 27 1 3 12 17 20 4 9 23 30 7 14 18 29 ", "50\n14 27 34 63 70 89 94 23 30 44 90 1 13 20 51 59 66 88 97 7 31 53 64 21 38 87 98 11 33 43 49 62 9 18 35 52 73 84 3 45 47 78 86 26 65 4 36 69 79 85 \n50\n17 32 56 68 81 91 12 25 37 80 100 8 15 39 54 61 77 96 2 29 42 55 71 22 76 95 6 24 41 48 60 93 10 28 40 57 74 99 5 46 67 83 19 58 75 16 50 72 82 92 ", "50\n26 20 68 7 19 89 65 93 14 62 94 3 73 8 12 43 32 18 56 28 59 15 27 96 34 51 55 41 38 48 82 72 63 5 67 47 61 99 64 33 24 80 13 17 4 90 71 74 45 95 \n50\n30 37 97 31 78 23 92 36 50 88 11 52 66 85 10 87 16 81 77 54 42 21 76 2 86 98 100 53 75 70 69 58 60 22 84 57 39 35 25 79 44 1 9 49 6 83 46 29 91 40 ", "50\n64 59 54 58 66 49 4 12 53 85 5 10 96 86 72 70 48 42 37 25 55 71 44 8 36 99 93 27 15 28 18 30 2 61 46 87 62 29 14 89 92 23 98 17 16 100 39 20 31 24 \n50\n52 65 60 78 41 13 90 51 83 45 1 67 75 9 6 40 68 63 47 97 80 74 88 50 94 19 11 22 73 84 95 26 35 7 32 81 91 77 34 76 57 56 69 43 38 33 82 3 79 21 ", "2\n1 3 \n1\n2 ", "2\n1 3 \n1\n2 ", "2\n1 3 \n1\n2 ", "3\n2 4 1 \n2\n3 5 ", "3\n1 5 4 \n2\n3 2 "]}
UNKNOWN
PYTHON3
CODEFORCES
13
16ccd5806786645d788c5a6d9bc85b1e
Little Elephant and Problem
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements. Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself. The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*. Note that the elements of the array are not necessarily distinct numbers. In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise. Sample Input 2 1 2 3 3 2 1 4 4 3 2 1 Sample Output YES YES NO
[ "from sys import stdin\nfrom collections import deque,Counter,defaultdict\nimport sys\nimport math\nimport operator\nimport random\nfrom fractions import Fraction\nimport functools\nimport bisect\nimport itertools\nfrom heapq import *\nimport time\n\nn = int(input())\narr = list(map(int,input().split()))\nc = 0\nfor i,j in zip(arr,sorted(arr)):\n if i!=j:\n c+=1\nprint('YES' if c == 0 or c == 2 else 'NO')\n\n", "n = int(input())\r\na = list(map(int, input().split()))\r\nb = a[::]\r\nb.sort()\r\nc = 0 \r\nfor i in range(n):\r\n if(a[i] != b[i]):\r\n c += 1 \r\n \r\nif(c <= 2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\narr = list(map(int,input().strip().split()))[:n]\r\n\r\n\r\nnew = sorted(arr)\r\ncount = 0\r\n\r\nfor i in range(n):\r\n if arr[i] != new[i]:\r\n count += 1\r\n\r\nif count <= 2:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "# your code goes here\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\n\r\nb = sorted(a)\r\ndiff = 0\r\nfor i in range(n):\r\n\tif a[i] != b[i]: diff += 1\r\n\r\nif diff <= 2:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\r\n", "import sys\r\ninput = sys.stdin.readline\r\ndef inInt():\r\n return int(input())\r\ndef inStr():\r\n return input().strip(\"\\n\")\r\ndef inIList():\r\n return(list(map(int,input().split())))\r\ndef inSList():\r\n return(input().split())\r\n\r\ndef solve(case, n):\r\n s = case.copy()\r\n s.sort()\r\n count = 0\r\n for i in range(n):\r\n if case[i] != s[i]:\r\n count += 1\r\n print(\"YES\" if count <= 2 else \"NO\")\r\n\r\ntests = inInt()\r\ncase = inIList()\r\nsolve(case, tests)", "BS=\"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\r\ndef to_base(s, b):\r\n res = \"\"\r\n while s:\r\n res+=BS[s%b]\r\n s//= b\r\n return res[::-1] or \"0\"\r\nalpha = \"abcdefghijklmnopqrstuvwxyz\"\r\n\r\nfrom collections import Counter\r\n\r\nt = int(input())\r\nnums = list(map(int, input().split()))\r\nso = sorted(nums)\r\n\r\ncounter = 0\r\nfor i in range(len(so)):\r\n if so[i]!=nums[i]:\r\n counter += 1\r\nif counter==2 or counter==0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def Sort(x):\n\tif len(x) == 1:\n\t\treturn x\n\t\t\n\ta = Sort(x[:len(x) // 2])\n\tb = Sort(x[len(x) // 2:])\n\t\n\tc = []\n\ti = 0\n\tj = 0\n\twhile (i < len(a))and(j < len(b)):\n\t\tif a[i] < b[j]:\n\t\t\tc.append(a[i])\n\t\t\ti += 1\n\t\telse:\n\t\t\tc.append(b[j])\n\t\t\tj += 1\n\t\n\tc = c + b[j:]\n\tc = c + a[i:]\n\t\n\treturn c\n\ninput()\nm = [int(i) for i in input().split(' ')]\n\nnewm = Sort(m)\ncount = 0\nfor i in range(len(m)):\n if newm[i] != m[i]:\n count += 1\n\nif count / 2 <= 1:\n print('YES')\nelse:\n print('NO')\n \t \t\t\t\t \t \t \t\t \t\t\t\t \t", "n = int(input())\na = list(map(int,input().split()))\n\nb = sorted(a)\n\ncnt = 0\n\nfor i in range(n): \n if a[i] != b[i]: \n cnt += 1\n\nif cnt < 3: \n print('YES')\nelse:\n print('NO')", "\r\nn=int(input())\r\nl1=list(map(int,input().split()))\r\nl2=[]\r\nfor i in range(len(l1)):\r\n\tl2.append(l1[i])\r\nl2.sort()\r\ncount1=0\r\nfor i in range(n):\r\n\tif(l1[i]!=l2[i]):\r\n\t\tcount1+=1\r\nif(count1>2):\r\n\tprint(\"NO\")\r\nelse:\r\n\tprint(\"YES\")\r\n", "n=int(input())\r\nl=[int(x) for x in input().split()]\r\nc=0\r\ntemp=[]\r\nfor i in l:\r\n temp.append(i)\r\ntemp.sort()\r\nfor i in range(n):\r\n if l[i]!=temp[i]:\r\n c+=1\r\n if c>2:\r\n break\r\nif c>2:\r\n print(\"NO\")\r\nelse: \r\n print(\"YES\")", "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\nn=int(input()) ; arr=list(inp()) ; ans=0 ; arr1=arr[::] ; arr1.sort() \r\nfor i in range(n) : \r\n if (arr[i]!=arr1[i]) : ans+=1 \r\nprint(\"NO\" if ans>2 else \"YES\") \r\n", "def find_diff(a, aa):\r\n cnt = 0\r\n for i in range(len(a)):\r\n if a[i] != aa[i]:\r\n cnt+= 1\r\n return cnt\r\n\r\ndef main():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n aa = sorted(a)\r\n if aa == a:\r\n print(\"YES\")\r\n return\r\n else:\r\n dif = find_diff(a, aa)\r\n if dif > 2:\r\n print(\"NO\")\r\n return\r\n else:\r\n print(\"YES\")\r\n return\r\nif __name__ == \"__main__\":\r\n main()", "import sys; input = sys.stdin.readline;\r\n\r\nn = int(input());\r\nl = list(map(int, input().split()));\r\na = sorted(l);\r\ndiff = 0;\r\nfor i in range(n):\r\n if (l[i] != a[i]):\r\n diff += 1;\r\nif (diff > 2):\r\n print(\"NO\");\r\nelse:\r\n print(\"YES\");", "a=[]\nb=[]\nn=int(input())\nlis=input().split(' ')\nfor i in range(n):\n m=int(lis[i])\n a.append(m)\n b.append(m)\na.sort()\nsw=0\nfor i in range(n):\n if(a[i]!=b[i]):\n sw+=1;\n if(sw>=3):\n print(\"NO\")\n break\nelse:\n print(\"YES\")\n\n\t \t \t\t \t \t\t\t\t \t \t \t\t \t \t", "input();a=list(map(int,input().split()))\r\nprint(\"YNEOS\"[sum(i!=j for i,j in zip(a,sorted(a)))>2::2])", "n = int(input())\r\na = list(map(int, input().split()))\r\nb = sorted(a)\r\nswapped = None\r\nok = False\r\nfor x in range(n):\r\n if a[x] != b[x]:\r\n if ok:\r\n print (\"NO\")\r\n exit(0)\r\n if swapped == None:\r\n swapped = (a[x], b[x])\r\n else:\r\n if swapped == (b[x], a[x]):\r\n ok = True\r\n else:\r\n print(\"NO\")\r\n exit(0)\r\nprint(\"YES\")", "\"\"\"\r\n Author : Ashish Sasmal\r\n Python3 / PyPy3\r\n\"\"\"\r\n\r\nfrom sys import stdin as sin\r\ndef aint():return int(input())\r\ndef amap():return map(int,sin.readline().split())\r\ndef alist():return list(map(int,sin.readline().split()))\r\ndef astr():return input()\r\n\r\nn = aint()\r\nl = alist()\r\ng = []+l\r\ng.sort()\r\nc = 0\r\nfor i in range(n):\r\n if g[i]!=l[i]:\r\n c+=1\r\nif c<=2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import math\r\n\r\n\r\ndef main_function():\r\n n = int(input())\r\n a = [int(u) for u in input().split(\" \")]\r\n new_sorted_a = sorted(a.copy())\r\n counter = 0\r\n for i in range(len(a)):\r\n if a[i] != new_sorted_a[i]:\r\n counter += 1\r\n if counter > 2:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n main_function()", "n=int(input())\na=list(map(int,input().split()))\nb=sorted(a);c=0\nfor i in range(n):\n if a[i]!=b[i]:\n c+=1\n#print (c,b,a)\nif c==0:\n print ('YES')\nelif c==1:\n print ('NO')\nelif c==2:\n print ('YES')\nelse:\n print ('NO')\n", "n = int(input())\na = [int(x) for x in input().split()]\nb = sorted(a)\n\ndiff = 0\nfor i in range(n):\n if a[i] != b[i]:\n diff += 1\n if diff > 2:\n print(\"NO\")\n exit()\n\nif diff == 1:\n print(\"NO\")\n\nprint(\"YES\")", "n=int(input())\r\nl=[int(x) for x in input().split()]\r\nif l==sorted(l):\r\n\tprint(\"Yes\")\r\nelse:\r\n\tcnt=0;\r\n\tg=sorted(l)\r\n\tfor i in range(len(l)):\r\n\t\tif l[i]!=g[i]:\r\n\t\t\tcnt+=1\r\n\tif cnt<=2:\r\n\t\tprint(\"Yes\")\r\n\telse:\r\n\t\tprint(\"No\")", "count = 0\nnum = input()\nlist1 = list(map(int, input().strip().split()))\nlist2 = list1.copy()\nlist1.sort()\nfor x in range(0 , int(num)):\n if (list1[x]!=list2[x]):\n count = count+1\n\nif count > 2:\n print(\"NO\")\nelif count <= 2:\n print(\"YES\")\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())\nA = list(map(int, input().split()))\nB = sorted(A)\ngB = set()\nfor i in range(n):\n if A[i] != B[i]:\n gB.add(i + 1)\nif len(gB) == 0 or len(gB) == 2:\n print('YES')\nelse:\n print('NO')", "import sys\n\n\ndef readline():\n return sys.stdin.readline().strip()\n\n\ndef read(t=int):\n s = sys.stdin.readline()\n return list(map(t, s.strip().split(' ')))\n\n\ndef readint():\n return read()[0]\n\n\ndef go():\n n = readint()\n a = read()\n www = sorted(a)\n cnt = 0\n for i in range(len(a)):\n if a[i] != www[i]:\n cnt += 1\n if cnt>2:\n print(\"NO\")\n else:\n print(\"YES\")\n\n\ntry:\n go()\nexcept:\n ...\n", "n=int(input())\r\nai=list(map(int,input().split()))\r\nais=list(sorted(ai))\r\nct=0\r\nfor i in range(n):\r\n if ai[i]!=ais[i]:\r\n ct+=1\r\nif ct==2 or ct==0:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")\r\n", "n= int(input())\r\na=[int(x) for x in input().split() ]\r\nx=sorted(a)\r\nan=0\r\nfor i in range(n):\r\n if a[i]!=x[i]:\r\n an+=1\r\nif an<=2:\r\n print('YES')\r\nelse:\r\n print('NO')", "n=int(input())\r\na=[int(x) for x in input().split()]\r\naa=sorted(a)\r\nc=0\r\nfor i in range(n):\r\n if a[i]!=aa[i]:c+=1\r\n if c==3:break\r\nif c==3:print('NO')\r\nelse:print('YES')", "n=int(input())\r\nl=list(map(int,input().split()))\r\nl1=l[::]\r\nl.sort()\r\nc=0\r\nfor i in range(0,n):\r\n\tif l[i]!=l1[i]:\r\n\t\tc=c+1\r\nif(c>2):\r\n\tprint('NO')\r\nelse:\r\n\tprint('YES')\r\n", "n, values, wrong = int(input()), [int(i) for i in input().split()], 0\r\nsorted_values = list(sorted(values))\r\nfor i in range(n):\r\n if values[i] != sorted_values[i]:\r\n wrong += 1\r\nif wrong > 2:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n", "n=int(input())\r\narr1=list(map(int,input().split()))\r\ncount=0\r\nj=0\r\narr2=sorted(arr1)\r\nfor i in range(n):\r\n if(arr1[i]!=arr2[i]):\r\n count+=1\r\nif(count<=2):\r\n print('YES')\r\nelse:\r\n print('NO') \r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\ns=[]+l\r\ns.sort()\r\ncount=0\r\nind=[]\r\nfor i in range(n):\r\n if s[i]!=l[i]:\r\n count=count+1\r\n ind.append(i)\r\n if count>2:\r\n break\r\nif count==0:\r\n print('YES')\r\nelif count==2:\r\n if l[ind[1]]==s[ind[0]] and l[ind[0]]==s[ind[1]]:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')", "n=int(input())\r\nl=[int(i) for i in input().split()]\r\nl1=sorted(l)\r\nif sum(l[i]!=l1[i] for i in range(n))<=2:\r\n print('YES')\r\nelse:\r\n print('NO')", "import copy\n\n\ndef main(inp):\n n = int(inp())\n arr = split_inp_int(inp)\n sorted_arr = copy.deepcopy(arr)\n sorted_arr.sort()\n edit_dist = 0\n for i in range(n):\n if arr[i] != sorted_arr[i]:\n edit_dist += 1\n print(\"YES\" if edit_dist <= 2 else \"NO\")\n\n\ndef split_inp_int(inp):\n return list(map(int, inp().split()))\n\n\ndef use_fast_io():\n import sys\n\n class InputStorage:\n def __init__(self, lines):\n lines.reverse()\n self.lines = lines\n\n def input_func(self):\n if self.lines:\n return self.lines.pop()\n else:\n return \"\"\n\n input_storage_obj = InputStorage(sys.stdin.readlines())\n return input_storage_obj.input_func\n\n\nfrom collections import Counter, defaultdict\nfrom functools import reduce\nimport operator\nimport math\n\n\ndef product(arr_):\n return reduce(operator.mul, arr_, 1)\n\nif __name__ == \"__main__\":\n\n main(use_fast_io())\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nd=sorted(l)\r\nc=0\r\nfor i in range(n):\r\n if(l[i]!=d[i]):\r\n c=c+1\r\nif(c>2):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n", "def main():\n input()\n l = list(map(int, input().split()))\n print(('NO', 'YES')[sum(a != b for a, b in zip(l, sorted(l))) < 3])\n\n\nif __name__ == '__main__':\n main()", "import math\r\nn=int(input())\r\n#n,m = map(int, input().strip().split(' '))\r\nlst = list(map(int, input().strip().split(' ')))\r\np=[]\r\np[:]=lst[:]\r\np.sort()\r\ni1=0\r\ni2=0\r\nf=0\r\nc=0\r\nfor i in range(n):\r\n if p[i]!=lst[i]:\r\n if f==0:\r\n i1=i\r\n f=1\r\n c+=1\r\n elif f==1:\r\n i2=i\r\n c+=1\r\n if c>2:\r\n print('NO')\r\n break\r\nif c==0:\r\n print('YES')\r\nelif c==1:\r\n print('NO')\r\nelif c==2:\r\n if p[i1]==lst[i2] and lst[i1]==p[i2]:\r\n print('YES')\r\n else:\r\n print('NO')\r\n\r\n ", "i=int(input())\r\nl=list(map(int,input().split()))\r\nc=sorted(l);t=0\r\nfor x in range(i):\r\n if l[x]!=c[x]:t+=1\r\nprint('Yes' if t==0 or t==2 else 'No')", "def main():\r\n alpha = 'abcdefghijklmnopqrstuvwxyz'\r\n ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'\r\n inf = 1e17\r\n mod = 10 ** 9 + 7\r\n\r\n # Max = 10 ** 1\r\n # primes = []\r\n # prime = [True for i in range(Max + 1)]\r\n # p = 2\r\n # while (p * p <= Max + 1):\r\n #\r\n # # If prime[p] is not\r\n # # changed, then it is a prime\r\n # if (prime[p] == True):\r\n #\r\n # # Update all multiples of p\r\n # for i in range(p * p, Max + 1, p):\r\n # prime[i] = False\r\n # p += 1\r\n #\r\n # for p in range(2, Max + 1):\r\n # if prime[p]:\r\n # primes.append(p)\r\n #\r\n # print(primes)\r\n\r\n def factorial(n):\r\n f = 1\r\n\r\n for i in range(1, n + 1):\r\n f = (f * i) % mod # Now f never can\r\n # exceed 10^9+7\r\n\r\n return f\r\n\r\n def ncr(n, r):\r\n # initialize numerator\r\n # and denominator\r\n num = den = 1\r\n for i in range(r):\r\n num = (num * (n - i)) % mod\r\n den = (den * (i + 1)) % mod\r\n return (num * pow(den,\r\n mod - 2, mod)) % mod\r\n\r\n def solve(n,a):\r\n\r\n\r\n sorted_a = sorted(a)\r\n\r\n old_inds = dict()\r\n new_inds = dict()\r\n\r\n for i in range(n):\r\n\r\n if a[i] not in old_inds:\r\n old_inds[a[i]] = [i]\r\n else:\r\n old_inds[a[i]].append(i)\r\n\r\n if sorted_a[i] not in new_inds:\r\n new_inds[sorted_a[i]] = [i]\r\n else:\r\n new_inds[sorted_a[i]].append(i)\r\n\r\n cnt = 0\r\n for ele in new_inds:\r\n\r\n olds = old_inds[ele]\r\n news = new_inds[ele]\r\n\r\n #print(ele,'olds',olds)\r\n #print(ele,'news',news)\r\n\r\n news_set = set(news)\r\n olds_set = set(olds)\r\n\r\n rem = len(olds)+len(news_set)-2*len(news_set.intersection(olds_set))\r\n\r\n cnt += (rem//2)\r\n\r\n #print(ele,cnt)\r\n\r\n if cnt <= 2:\r\n return 'YES'\r\n\r\n return 'NO'\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n pass\r\n\r\n t = 1#int(input())\r\n ans = []\r\n for _ in range(t):\r\n # s = input()\r\n n = int(input())\r\n #h,w= map(int, input().split())\r\n #arr = list(input()[:-1])\r\n a = [int(x) for x in input().split()]\r\n #b = [int(x) for x in input().split()]\r\n # a2 = [int(x) for x in input().split()]\r\n # grid = []\r\n # for i in range(n):\r\n # grid.append(input()[:-1])\r\n #\r\n # rem = []\r\n # for i in range(n-1):\r\n # rem.append(input()[:-1])\r\n\r\n #print(grid)\r\n #print(rem)\r\n\r\n ans.append(solve(n,a))\r\n\r\n for answer in ans:\r\n print(answer)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n import sys, threading\r\n import bisect\r\n import math\r\n import itertools\r\n from sys import stdout\r\n\r\n # Sorted Containers\r\n import heapq\r\n from queue import PriorityQueue\r\n\r\n # Tree Problems\r\n # sys.setrecursionlimit(2 ** 32 // 2 - 1)\r\n # threading.stack_size(1 << 27)\r\n\r\n # fast io\r\n input = sys.stdin.readline\r\n\r\n thread = threading.Thread(target=main)\r\n thread.start()\r\n thread.join()", "def main():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n sorted_arr = sorted(arr)\r\n\r\n counter = 0\r\n for i in range(n):\r\n if arr[i] != sorted_arr[i]:\r\n counter += 1\r\n\r\n if counter <= 2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "\r\n\r\ndef solve():\r\n n = int(input())\r\n l = list(map(int, input().split()))\r\n ls = sorted(l)\r\n diff = 0\r\n for idx in range(n):\r\n if l[idx] != ls[idx]:\r\n diff += 1\r\n if diff > 2:\r\n return False\r\n return True\r\n\r\ndef main():\r\n ret = solve()\r\n ans = \"YES\" if ret else \"NO\"\r\n print(ans)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()", "n = int(input())\r\na = list(map(int,input().split()))\r\nb = sorted(a)\r\ncount = 0\r\nfor i in range(n):\r\n if a[i]!=b[i]:\r\n count+=1\r\n if count==3:\r\n print(\"NO\")\r\n break \r\nelse:\r\n print(\"YES\")", "l = -1\r\n\r\nN = int(input())\r\nnums = list(map(int, input().split()))\r\n\r\nseq = sorted(nums)\r\nk = 2\r\nans = True\r\n# print(nums, seq)\r\nfor x, y in zip(nums, seq):\r\n k -= x != y\r\n # print(k)\r\n if k == -1:\r\n ans = False\r\n break\r\nprint('YES' if ans else 'NO') ", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nsortedA = sorted(a)\r\ncnt = 0\r\nfor i in range(n):\r\n if a[i] != sortedA[i]:\r\n cnt += 1\r\nprint('YES' if cnt in (0, 2) else 'NO')", "n=int(input())\r\na=list(map(int,input().split()))\r\nb=a.copy()\r\nb.sort()\r\nc=0\r\nfor i in range(n):\r\n\tif(a[i]!=b[i]):\r\n\t\tc+=1;\r\n\tif(c==3):\r\n\t\tbreak\r\nif(c<3):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "n = int(input())\r\na = list(map(int, input().split()))\r\nb = sorted(a); c = 0\r\nfor i in range(n):\r\n if a[i] != b[i]:\r\n c+= 1\r\nif c == 2 or c == 0:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "tamanho = int(input())\nvetor = input()\n\nvetor = vetor.split()\nvetor = [int(vetor[i]) for i in range(0, tamanho)]\n\ntroca = 0\n\ncopia =[vetor[i] for i in range(0, tamanho)]\n\nvetor.sort()\n\nfor i in range(0, tamanho):\n\tif (copia[i] != vetor[i]):\n\t\ttroca += 1\n\n#print(troca)\nif (troca <= 2):\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")", "n=int(input())\r\na=list(map(int,input().split()))\r\nb=sorted(a)\r\nprint([\"NO\",\"YES\"][sum([a[i]!=b[i]for i in range(n)])<3])", "n=int(input())\nl=list(map(int,input().split()))\n\nlst=list(l)\n\t\nlst.sort()\nab=0\nfor i in range(n):\n\tif lst[i]!=l[i]:\n\t\tab+=1\n\t\t\nprint([\"NO\",\"YES\"][ab<3])", "#350C\n'''\ndef main():\n from sys import stdin,stdout\n n = int(stdin.readline())\n points = []\n ans = []\n for _ in range(n):\n x,y = map(int,stdin.readline().split())\n points.append((x*x+y*y,x,y,))\n points.sort()\n for i in points:\n a,x,y = i[0],i[1],i[2]\n #print(a,x,y)\n if x:\n ans.append(\"1 \"+str(abs(x))+\" \"+(\"R\" if x>0 else \"L\"))\n if y:\n ans.append(\"1 \"+str(abs(y))+\" \"+(\"U\" if y>0 else \"D\"))\n ans.append(\"2\")\n if y:\n ans.append(\"1 \"+str(abs(y))+\" \"+(\"D\" if y>0 else \"U\"))\n if x:\n ans.append(\"1 \"+str(abs(x))+\" \"+(\"L\" if x>0 else \"R\"))\n ans.append(\"3\")\n stdout.write(str(len(ans))+'\\n')\n for i in ans:\n stdout.write(i+'\\n')\n'''\ndef main():\n from sys import stdin,stdout\n n = int(stdin.readline())\n arr = list(map(int,stdin.readline().split()))\n sarr = arr[:]\n sarr.sort()\n a=-1\n b=-1\n flag = True\n #print(arr)\n #print(sarr)\n for i in range(n):\n if arr[i]!=sarr[i]:\n if a==-1:\n a=i\n elif b==-1:\n b=i\n else:\n flag = False\n break\n #print(flag)\n #print(a)\n #print(b)\n if not flag:\n stdout.write(\"NO\\n\")\n else:\n if (a==-1 and b==-1) or (arr[a] == sarr[b] and arr[b]==sarr[a]):\n stdout.write(\"YES\\n\")\n else:\n stdout.write(\"NO\\n\")\nif __name__=='__main__':\n main()\n", "n = int(input())\r\nA = [int(a) for a in input().split()]\r\nB = A.copy()\r\nB.sort()\r\nc = 0\r\nfor i in range(n):\r\n a = A[i]\r\n b = B[i]\r\n if a == b:\r\n continue\r\n else:\r\n c += 1\r\nif c == 0 or c == 2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import sys\r\nimport math\r\nfrom collections import defaultdict\r\nfrom itertools import permutations\r\n\r\ndef sin():\r\n\treturn int(sys.stdin.readline())\r\n\r\ndef array():\r\n\treturn list(map(int, sys.stdin.readline().strip().split()))\r\n\r\ndef two():\r\n\treturn map(int, sys.stdin.readline().strip().split())\r\n\r\ndef multiple():\r\n\treturn [int(x) for x in sys.stdin.readline().split()]\r\n\r\ndef string():\r\n\treturn sys.stdin.readline().strip()\r\n\r\n\r\nn = sin()\r\narr = array()\r\n\r\nasc = sorted(arr)\r\n\r\ncount = 0\r\n\r\nfor i in range(n):\r\n\tif arr[i] != asc[i]:\r\n\t\tcount += 1\r\n\r\nif count > 2:\r\n\tprint(\"No\")\r\nelse:\r\n\tprint(\"Yes\")", "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\n\r\nt = 1\r\n\r\nwhile t:\r\n t -= 1\r\n\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n b = sorted(a)\r\n\r\n diffs = []\r\n for i in range(n):\r\n if a[i] != b[i]:\r\n diffs.append(i)\r\n \r\n if len(diffs) > 2:\r\n print(\"NO\")\r\n elif not diffs:\r\n print(\"YES\")\r\n else:\r\n i, j = diffs\r\n if a[i] == b[j] and b[i] == a[j]:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\n\r\n\r\n ", "from sys import stdin,stdout\r\nfrom collections import Counter\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=lst()\r\n b=sorted(a)\r\n op=0\r\n for i in range(n):\r\n if a[i]==b[i]:continue\r\n op+=1\r\n if op==0 or op==2:print('YES')\r\n else:print('NO')", "n = int(input())\r\na = list(map(int, input().split()))\r\nb = sorted(a)\r\nans = 0\r\nfor i in range(n):\r\n\tif not a[i] == b[i]:\r\n\t\tans += 1\r\nif ans <= 2:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "n = int(input())\r\nl = list(map(int, input().split()))\r\nl1 = []\r\nfor i in l: l1.append(i)\r\nl1.sort()\r\ncnt = 0\r\nfor i in range(n):\r\n if l[i] != l1[i]: cnt -= -1\r\nif cnt == 0 or cnt == 2: print('YES')\r\nelse: print('NO')", "n=int(input());lt=list(map(int,input().split()))\r\nltt=sorted(lt)\r\ncnt=sum(lt[i]!=ltt[i] for i in range(n))\r\nif(cnt>2):print('NO');exit(0)\r\nprint('YES')", "def arr_inp(n):\r\n if n == 1:\r\n return [int(x) for x in stdin.readline().split()]\r\n elif n == 2:\r\n return [float(x) for x in stdin.readline().split()]\r\n else:\r\n return [str(x) for x in stdin.readline().split()]\r\n\r\n\r\nfrom sys import stdin\r\n\r\nn, a = int(input()), arr_inp(1)\r\na1, c, ix = sorted(a.copy()), 0, 0\r\n\r\nfor i in range(n):\r\n if a[i] != a1[i]:\r\n if c == 0:\r\n c += 1\r\n ix = i\r\n elif c > 2:\r\n exit(print('NO'))\r\n else:\r\n if a1[ix] == a[i]:\r\n c += 1\r\n else:\r\n exit(print('NO'))\r\nprint('YES')\r\n", "l = int(input())\r\na = [int(bruh) for bruh in input().split()]\r\n\r\na1 = sorted(a)\r\n\r\ncnt = 0\r\nfor x in range(l):\r\n if a[x] != a1[x]:\r\n cnt += 1\r\n\r\nif cnt <= 2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nA = [int(a) for a in input().split()]\r\nB = A.copy()\r\nB.sort()\r\nc = 0\r\nfor i in range(n):\r\n c = c + 1 if A[i] != B[i] else c\r\nprint(\"YES\" if c <= 2 else \"NO\")", "n = int(input())\n\ndt = input()\ns = dt.split()\na = [int(x) for x in s]\nsortm = [int(x) for x in s]\n\nsortm.sort()\n\ncnt = 0\n\nfor i in range(n):\n\tif a[i] != sortm[i]:\n\t\tcnt += 1\n\n\nif cnt <= 2:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\t \t \t\t \t \t \t \t\t\t \t \t \t \t", "n=int(input())\r\ntab=list(map(int,input().split(\" \")))\r\ntab1=list(tab)\r\ntab1.sort()\r\ncnt=0\r\nfor i in range(n):\r\n if (tab[i]!=tab1[i]):\r\n cnt+=1\r\nif (cnt>2):\r\n print(\"NO\")\r\nelse: print(\"YES\")", "n=int(input())\r\n\r\na=list(map(int,input().split()))\r\n\r\nsortedA=sorted(a)\r\nif sortedA==a:\r\n print(\"YES\")\r\nelse: \r\n cnt=0\r\n for i in range(len(a)):\r\n if a[i]!=sortedA[i]:\r\n cnt+=1\r\n if cnt==2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\n\r\n", "def elef():\r\n n=int(input())\r\n h=list(map(int,input().split()))\r\n h1=sorted(h)\r\n y=0\r\n for i in range(n):\r\n if(h1[i]!=h[i]):\r\n y+=1;\r\n if(y==2 or y==0):\r\n print('YES')\r\n else:print('NO')\r\nelef()\r\n \r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nb = sorted(a)\r\n\r\nindexs = []\r\nfor i in range(n):\r\n if a[i] != b[i]:\r\n indexs.append(i)\r\nif len(indexs) > 2:\r\n print(\"NO\")\r\nelif len(indexs) == 2:\r\n a[indexs[0]], a[indexs[1]] = a[indexs[1]], a[indexs[0]]\r\n if a != b:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\nelse:\r\n print(\"YES\")", "t = int(input())\r\na = list(map(int , input().split()))\r\nc = 0\r\nb = sorted(a)\r\nfor el in range(t):\r\n if(a[el] != b[el]):\r\n c += 1 \r\n\r\nif(c <= 2):\r\n print('YES')\r\nelse:\r\n print('NO')", "n = int(input())\r\nc = input().split()\r\na = [int(x) for x in c]\r\nb = [x for x in a]\r\nb.sort()\r\nz = 0\r\nfor x, y in zip(a, b):\r\n if x != y:\r\n z += 1\r\nif z < 3:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\ncnt = 0\r\narr = [int(x) for x in input().split()]\r\na1 = sorted(arr)\r\nfor i in range(0,n):\r\n if arr[i] != a1[i]:\r\n cnt+=1\r\nprint(\"YES\" if cnt <= 2 else \"NO\")", "n = int(input())\narr = list(map(int,input().split()))\nsorted_arr = sorted(arr)\nswap = 0\nfor i in range(n):\n if swap > 2:\n break\n if arr[i] != sorted_arr[i]:\n swap += 1\nprint(\"NO\" if swap > 2 else \"YES\")\n\t\t \t\t\t \t\t \t \t \t", "n = int(input())\r\ncount=0\r\nar=list(map(int,input().split()))\r\nsort=sorted(ar)\r\nfor i in range (0,n):\r\n if(ar[i]!=sort[i]):\r\n count+=1\r\nif(count==2 or count==0):\r\n print('YES')\r\nelse:\r\n print('NO')", "n = int(input())\na = [int(x) for x in input().split()]\nb = sorted(a)\ncnt = int(0)\nfor i in range(n):\n if (a[i] != b[i]):\n cnt += 1\nprint(\"YES\" if cnt <= 2 else \"NO\")\n\n\n\n", "n = int(input())\r\na = list(map(int, input().split()))\r\nb = sorted(a)\r\nc = 0\r\nfor i in range(n):\r\n if b[i]!=a[i]:\r\n c+=1\r\nif c<=2:\r\n print('YES')\r\nelse:\r\n print('NO')", "n = input()\na = [*map(int, input().split())]\na2 = sorted(a)\ncnt = 0\nfor i,v in enumerate(a):\n if v != a2[i]:\n cnt += 1\nif cnt <= 2:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "n = int(input())\na=list(map(int,input().split()))\nb=a.copy()\na.sort()\n\nmiss=0\nfor i in range(n):\n if a[i]!=b[i]:\n miss+=1\n\nif miss==0 or miss==2:\n print('YES')\nelse:\n print('NO')\n\n", "n = int(input())\r\nl = list(map(int, input().split()))\r\ns = sorted(l)\r\ncnt = 0\r\nfor i in range(n):\r\n if l[i] != s[i]:\r\n cnt += 1\r\nprint(\"NO\" if cnt > 2 else 'YES')\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\ncnt=0; ext=sorted(a); pos=[0]*n\r\nfor i in range(n):\r\n pos[i]=ext[i]\r\nfor i in range(n):\r\n if pos[i]!=a[i]: cnt+=1\r\n if cnt>2: break\r\nif cnt<3: print(\"YES\")\r\nelse: print(\"NO\")", "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\nimport math\nimport operator\nimport sys\nfrom itertools import accumulate \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 n = int(input())\n arr = list(map(int, input().split()))\n \n s_arr = list(sorted(arr))\n out_place = 0\n for i in range(len(s_arr)):\n out_place += arr[i] != s_arr[i]\n\n print([\"NO\", \"YES\"][out_place == 0 or out_place == 2])\n\n\n\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\nn = int(input())\r\na = list(map(int,input().split()))\r\nb = sorted(a)\r\nans = 0\r\nfor i in range(n):\r\n if a[i] != b[i]:\r\n ans += 1\r\nprint('YES' if ans <= 2 else 'NO')", "def list_input():\r\n return list(map(int,input().split()))\r\ndef map_input():\r\n return map(int,input().split())\r\ndef map_string():\r\n return input().split()\r\n \r\nn = int(input()) \r\na = list_input()\r\nb = sorted(a)\r\ncnt = 0\r\npos = 0\r\npos2 = 0\r\nfor i in range(n):\r\n if b[i] != a[i]:\r\n cnt += 1\r\n if cnt == 1:\r\n pos = i\r\n elif cnt == 2: \r\n pos2 = i\r\nif cnt > 2:\r\n print(\"NO\")\r\n exit()\r\na[pos],a[pos2] = a[pos2],a[pos]\r\nif a == b:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\nl=list(map(int,input().split()))\r\nx=sorted(l)\r\nc=-1\r\nfor i,j in zip(l,x):\r\n if i!=j:\r\n c+=1\r\nif c<=1:\r\n print('YES')\r\nelse:\r\n print('NO')", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Wed Jul 22 19:46:27 2020\n\n@author: divyarth\n\"\"\"\n\nimport sys\nimport heapq\nfrom collections import deque\nfrom collections import defaultdict\n#input=sys.stdin.readline\n#print=sys.stdout.write\n#sys.setrecursionlimit(100000)\nI=lambda : list(map(int,input().split(' ')))\n\n\nn=int(input())\nlst=I()\nlst1=sorted(lst)\ncnt=0\nfor ele1,ele2 in zip(lst,lst1):\n if ele1!=ele2:\n cnt+=1\n \nif cnt==0 or cnt==2:\n print('YES')\nelse:\n print('NO')\n \n", "n = int(input())\na = list(map(int, input().split()))\nb = sorted(a)\ndif = sum(map(lambda x: int(x[0] != x[1]), zip(a,b)))\nprint('YES' if dif == 2 or dif == 0 else 'NO')\n", "n = int( input() )\nnumbers = input().split()\nnumbers = list(map(int, numbers))\naux_nums = numbers.copy()\naux_nums.sort()\nchanges = 0\nfor i in range(len(numbers)) :\n if numbers[i] != aux_nums[i] :\n changes += 1\nif changes == 0 or changes == 2 :\n print(\"YES\") \nelse :\n print(\"NO\")\n\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().strip().split()))\r\nb = sorted(a)\r\n\r\nswapcount = 0\r\nfor x in range(len(a)):\r\n\tif a[x] != b[x]:\r\n\t\tswapcount+=1\r\n\r\nif swapcount==0 or swapcount==2:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "n = int(input())\r\nA = list(map(int,input().split()))\r\nB = sorted(A)\r\ncount = 0\r\nfor i in range(n):\r\n if A[i]!=B[i]:\r\n count+=1\r\nif count<=2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\na=[int(i) for i in input().split()]\r\nsorteda=sorted(a)\r\nc=0\r\nfor i in range(n):\r\n if a[i]!=sorteda[i]:c+=1\r\n if c==3:\r\n print('NO')\r\n break\r\nif c!=3:\r\n print('YES')\r\n \t \t\t \t\t\t \t \t \t\t\t \t \t \t \t", "n = int(input()) \r\na = [int(i) for i in input().split()] \r\nsort = sorted(a) \r\nc = 0\r\nfor i in range(n): \r\n if a[i] != sort[i] : c+=1\r\nif c <= 2 : print(\"YES\") \r\nelse : print(\"NO\")", "n=int(input())\r\narr=list(map(int,input().split()))\r\narr2=sorted(arr)\r\ncount=0\r\na=0\r\nfor i in range(n):\r\n if arr[i]!=arr2[i]:\r\n count+=1\r\n k=arr[i]\r\n arr[i]=arr2[i]\r\n z=arr.index(arr2[i])\r\n arr[z]=k\r\n\r\n if count>2:\r\n a=1\r\n break\r\nif a==0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\ndef func(n):\r\n import copy\r\n if 2<=n<=10**5:\r\n a=input().split()\r\n if len(a)==n:\r\n for i in range(len(a)):\r\n if i<=10**9:\r\n a[i]=int(a[i]) \r\n b=copy.deepcopy(a)\r\n b.sort()\r\n c=0\r\n for i in range(len(b)):\r\n if a[i]!=b[i]:\r\n c=c+1\r\n \r\n if c==2 or c==0:\r\n return 'YES'\r\n else:\r\n return 'NO' \r\nprint(func(n)) \r\n \r\n", "input()\r\na=[*map(int,input().split())]\r\nprint(['NO','YES'][sum(x!=y for x,y in list(zip(a,sorted(a))))<=2])", "n=int(input())\r\nl=list(map(int,input().split()))\r\ns=sorted(l)\r\nc,i=0,0\r\nfor i in range(n):\r\n if l[i]!=s[i]:\r\n c=c+1\r\n if c>2:\r\n break\r\nif c==2 or c==0:\r\n print('YES')\r\nelse:\r\n print('NO')", "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 Little_Elephant_and_Problem():\r\n n = inp()\r\n sequence = inlt()\r\n sequence_sorted = sorted(sequence)\r\n\r\n s1_not_equal = []\r\n s2_not_equal = []\r\n\r\n for num1,num2 in zip(sequence, sequence_sorted):\r\n if num1 != num2:\r\n s1_not_equal.append(num1)\r\n s2_not_equal.append(num2)\r\n \r\n if (len(s1_not_equal) == 2 and s1_not_equal[0] == s2_not_equal[1] and s1_not_equal[1] == s2_not_equal[0]) or (len(s1_not_equal) == 0):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\n return \r\n\r\n\r\nLittle_Elephant_and_Problem()", "def solve(n,arr) :\r\n sortedArr = sorted(arr)\r\n times = 0\r\n index = 0\r\n \r\n while index < n :\r\n if arr[index] != sortedArr[index] :\r\n times += 1\r\n index += 1\r\n \r\n if times > 2 :\r\n return \"NO\"\r\n else :\r\n return \"YES\"\r\n \r\nn = int(input())\r\narr = list(map(int,input().split()))\r\nprint (solve(n,arr))", "n = int(input())\nx = list(map(int, input().split()))\ny = x.copy()\ny = sorted(y)\ncnt = 0\ni = 0\nwhile cnt < 3:\n try:\n if x[i] != y[i]:\n cnt += 1\n i += 1\n except IndexError:\n cnt = 2\n break\nif cnt < 3:\n print('YES')\nelse:\n print('NO')\n", "import math\r\nfrom collections import defaultdict\r\nml=lambda:map(int,input().split())\r\nll=lambda:list(map(int,input().split()))\r\nii=lambda:int(input())\r\nip=lambda:input()\r\n\r\n\"\"\"========main code===============\"\"\"\r\nt=1\r\n#t=ii()\r\nfor _ in range(t):\r\n n=ii()\r\n a=ll()\r\n b=a[:]\r\n b.sort()\r\n cnt=0\r\n for i in range(n):\r\n if(a[i]!=b[i]):\r\n cnt+=1\r\n if(cnt==2 or cnt==0):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "# cook your dish here\r\nn=int(input())\r\nl=[int(x) for x in input().strip().split()]\r\nl1=sorted(l)\r\nc=0\r\nfor i in range(n):\r\n if(l[i]!=l1[i]):\r\n c+=1\r\nif(c<=2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\narr = list(map(int, input().split()))\r\ncpy = sorted(arr)\r\nc = 0\r\n\r\nfor i in range(n):\r\n c += int(arr[i] != cpy[i])\r\nprint((\"NO\", \"YES\")[c <= 2])\r\n", "import sys\r\n\r\ninput = [int(x) for x in sys.stdin.buffer.read().split()]\r\ns = input[1:]\r\ns.sort()\r\ndiff = 0\r\nfor i in range(len(s)):\r\n if s[i] != input[i + 1]: diff += 1\r\nif diff > 2: print(\"NO\")\r\nelse: print(\"YES\")\r\n", "'''input\n4\n4 3 2 1\n'''\n# again a coding delight\nfrom sys import stdin, stdout\nfrom collections import defaultdict, deque\n\n\n# main starts\nn = int(stdin.readline().strip())\narr = list(map(int, stdin.readline().split()))\ncarr = arr[:]\ncarr.sort()\ncount = 0\nfor i in range(len(arr)):\n\tif arr[i] != carr[i]:\n\t\tcount += 1\nif count <= 2:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")", "from collections import Counter\r\nimport string\r\nimport math\r\nimport sys\r\n\r\ndef array_int():\r\n return [int(i) for i in sys.stdin.readline().split()]\r\ndef vary(number_of_variables):\r\n if number_of_variables==1:\r\n return int(sys.stdin.readline())\r\n if number_of_variables>=2:\r\n return map(int,sys.stdin.readline().split()) \r\ndef makedict(var):\r\n return dict(Counter(var))\r\nmod=1000000007\r\nn=vary(1)\r\nnum=array_int()\r\nnum2=num[:]\r\nnum2.sort()\r\ncount=0\r\nfor i in range(n):\r\n if num[i]!=num2[i]:\r\n count+=1\r\nprint('NO' if count>2 else 'YES')\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "a=int(input())\r\nb=list(map(int,input().split()));s=0\r\nfor i,j in zip(b,sorted(b)):s+=i!=j\r\nif s<3:print(\"YES\")\r\nelse:print(\"NO\")", "n=int(input())\na=list(map(int,input().split()))\nans=0\nb=sorted(a)\nfor i in range(n):\n if a[i]!=b[i]:\n ans+=1\nif ans<=2:\n print(\"YES\")\nelse:\n print(\"NO\")\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 l1=[]\r\n for i in l:\r\n l1.append(i)\r\n l1.sort()\r\n #print(l,l1)\r\n cnt=0\r\n for i in range(n):\r\n if l[i]!=l1[i]:\r\n cnt+=1\r\n if cnt>2:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\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\nlt = [int(x) for x in input().split()]\r\ndt = sorted(lt)\r\nans=0\r\nfor i in range(n):\r\n if lt[i]!=dt[i]:\r\n ans+=1 \r\nif ans <=2:\r\n print('Yes')\r\nelse:\r\n print('No')", "a=int(input())\r\nm=input().split()\r\nm2=[]\r\nfor i in range(a):\r\n m[i]=int(m[i])\r\n m2.append(int(m[i]))\r\nm2.sort()\r\nif m==m2:\r\n print('YES')\r\n exit() \r\nchet=0\r\nfor i in range(len(m)):\r\n if m[i]!=m2[i]:\r\n chet+=1\r\n if chet>2:\r\n print('NO')\r\n exit()\r\n \r\n \r\nprint('YES') \r\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\ncount = 0\r\ncop = arr[:]\r\ncop.sort()\r\nf= 0 \r\nfor i in range(n):\r\n if arr[i]!=cop[i]:\r\n count+=1\r\n if count>2:\r\n f = 1\r\n break\r\nif f==1:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "n=int(input())\r\nl=list(map(int,input().split()))\r\nm=l[:]\r\nm.sort()\r\nf=1\r\nc=0\r\nfor i in range(n):\r\n if(l[i]!=m[i]):\r\n c+=1 \r\n if(c>2):\r\n f=0 \r\n break \r\nif(f==0):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n \r\n \r\n \r\n \r\n", "from copy import deepcopy as dp\r\nn = int(input())\r\n\r\narray_input = input().split()\r\narray = [int(item) for item in array_input]\r\n\r\narray2 = dp(array)\r\narray2.sort()\r\n\r\n\r\n\r\nmistake = 0\r\nfor i in range(len(array)):\r\n if array[i]!= array2[i]:\r\n mistake+=1\r\n\r\n\r\nif mistake <=2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "from os import path\r\nfrom sys import stdin, stdout\r\n\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 solution():\r\n n = int(input())\r\n nums1 = [int(num) for num in input().split()]\r\n nums2 = sorted(nums1)\r\n cnt = 0\r\n for num1, num2 in zip(nums1, nums2):\r\n if num1 != num2:\r\n cnt += 1\r\n print('YES' if cnt <= 2 else 'NO')\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", "n = int(input())\nl = list(map(int, input().split()))\nl1 = sorted(l)\np = 0\nfor i in range(n):\n if (l[i] != l1[i]):\n p += 1\nif (p<=2):\n print(\"YES\")\nelse:\n print(\"NO\")\n \t\t \t \t\t\t\t \t \t\t \t\t\t\t\t \t", "from sys import *\r\nfrom math import *\r\nn=int(stdin.readline())\r\na=list(map(int,stdin.readline().split()))\r\nb=a.copy()\r\nb.sort()\r\nx=0\r\nfor i in range(n):\r\n if a[i]!=b[i]:\r\n x+=1\r\nif x<=2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\na = list(map(int, input().split(\" \")))\nb = sorted(a)\nd = 0\nfor x in range(len(a)):\n if a[x] != b[x]:\n d += 1\nif d <= 2:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "if __name__ == '__main__':\r\n\tn = int(input())\r\n\tsequence = [int(x) for x in input().split()]\r\n\r\n\tsorted_sequence = sorted(sequence)\r\n\tseq_len = len(sequence)\r\n\tmismatch = 0\r\n\r\n\tfor i in range(seq_len):\r\n\t\tif sorted_sequence[i] != sequence[i]:\r\n\t\t\tmismatch += 1\r\n\r\n\tif mismatch > 2:\r\n\t\tprint(\"NO\")\r\n\telse:\r\n\t\tprint(\"YES\")\r\n\r\n", "_ = input()\r\narr = list(map(int, input().split()))\r\nsorted_arr = sorted(arr)\r\nx = 0\r\nfor i in range(len(arr)):\r\n if x < 3:\r\n if arr[i] != sorted_arr[i]: x += 1 \r\n else: break\r\nprint('YES' if x < 3 else 'NO')\r\n", "n = int(input())\r\narr = [int(x) for x in input().split()]\r\narr2 = list(arr)\r\narr2.sort()\r\n\r\nc = 0\r\nfor i in range(n):\r\n if arr[i] != arr2[i]:\r\n c+= 1\r\n if c > 2:\r\n break\r\n\r\nif c == 2 or c == 0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nl = list(map(int,input().split()))\r\nl2 = sorted(l) \r\ncounter = 0\r\nres = \"YES\" \r\nfor i in range(n) : \r\n if l[i] != l2[i] : \r\n counter += 1\r\n if counter > 2 :\r\n res= \"NO\"\r\n break\r\nprint(res)", "def R(): return map(int, input().split())\r\ndef I(): return int(input())\r\ndef S(): return str(input())\r\n\r\ndef L(): return list(R())\r\n\r\nfrom collections import Counter \r\n\r\nimport math\r\nimport sys\r\n\r\nfrom itertools import permutations\r\n\r\nn=I()\r\n\r\na=L()\r\n\r\nb=a.copy()\r\nb.sort()\r\ncnt=0\r\n\r\nfor i in range(len(a)):\r\n if a[i]!=b[i]:\r\n cnt+=1\r\n\r\nprint(['NO','YES'][cnt<=2])", "n = int(input())\r\nl = list(map(int, input().split()))\r\nc = 0\r\n\r\nls = sorted(l)\r\n\r\nfor i in range(n):\r\n if l[i] != ls[i]:\r\n c += 1\r\n\r\nif(c <= 2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=int(input())\r\n\r\na=input()\r\na=a.split(' ')\r\n\r\nfor i in range(s):\r\n a[i]=int(a[i])\r\n\r\nb=a[:]\r\na.sort()\r\nc=0\r\n\r\nfor i in range(s):\r\n if a[i]!=b[i]:\r\n c=c+1\r\n\r\nif c>2:\r\n print(\"NO\")\r\nelse: print(\"YES\")\r\n", "n = int(input())\r\nl = list(map(int,input().split()))\r\ntemp = sorted(l)\r\nc = 0\r\nfor i in range(n):\r\n if l[i] != temp[i]:\r\n c += 1\r\nif c>2:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "import math\n\nimport sys\n\nsys.setrecursionlimit(150000)\n\n\ndef main():\n n = int(input())\n a = [int(x) for x in input().split()]\n sa = sorted(a)\n\n diffs = sum(1 if a[i] != sa[i] else 0 for i in range(n))\n if diffs == 2 or diffs == 0:\n print(\"YES\")\n else:\n print(\"NO\")\n\n\nmain()\n", "\r\ndef gg():\r\n n=int(input())\r\n a=list(map(int,input().split()))\r\n l=sorted(a)\r\n k=0\r\n for i in range (n):\r\n if(a[i]!=l[i]):\r\n k=k+1\r\n if (k>2) :\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\ngg()\r\n", "n=int(input())\r\nl1=list(map(int,input().split()))\r\nl2=[]\r\nc=0\r\nf=0\r\nfor i in l1:\r\n l2.append(i)\r\nl2.sort()\r\nfor i in range(n):\r\n if l1[i]!=l2[i]:\r\n c+=1\r\n if c>2:\r\n f=1\r\n break\r\nif f==0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nl=[0]*n\r\nfor i in range(n):\r\n l[i]=a[i]\r\nl.sort()\r\nc=0\r\nfor i in range(n):\r\n if a[i]!=l[i]:\r\n c+=1\r\nif c<=2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import bisect\r\nimport sys\r\nimport collections\r\n\r\nn = int(input())\r\nA = list(map(int, input().split()))\r\n\r\nB = sorted(A)\r\ncnt = 0\r\nfor i in range(n):\r\n if A[i] != B[i]:\r\n cnt += 1\r\n\r\nprint(\"NO\" if cnt > 2 else \"YES\")\r\n\r\n ", "import os,sys\r\n\r\ndef read():\r\n sys.stdin = open('input.txt', 'r') \r\n sys.stdout = open('output.txt', 'w') \r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\n\r\ndef main():\r\n\tn=int(input())\r\n\tli=list(map(int,input().split()))\r\n\r\n\tla=sorted(li)\r\n\tcnt=0\r\n\r\n\tfor i in range(n):\r\n\t\tif li[i]!= la[i]:\r\n\t\t\tcnt=cnt+1\r\n\r\n\tif cnt<=2:\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")\r\n\r\n\t\r\n\r\nif __name__ == \"__main__\":\r\n #read()\r\n main()\r\n \r\n\r\n\r\n\r\n", "\"\"\"\r\nsort array and count the differences against unsorted,\r\nif there are more than 2 differences, it wasn't an accident\r\n\"\"\"\r\n\r\n\r\ndef was_accident(n: int, array: list[int]) -> bool:\r\n \"\"\"\r\n time O(n log n)\r\n\r\n space O(n)\r\n \"\"\"\r\n # O(n log n)\r\n sorted_array = sorted(array)\r\n\r\n diffs = 0\r\n # O(n)\r\n for i in range(n):\r\n if array[i] != sorted_array[i]:\r\n diffs += 1\r\n\r\n if diffs > 2:\r\n return False\r\n\r\n return True\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n # O(n)\r\n array = list(map(int, input().split()))\r\n\r\n answer = \"YES\" if was_accident(n, array) else \"NO\"\r\n print(answer)\r\n", "from math import inf as inf\r\nfrom math import *\r\nfrom collections import *\r\nimport sys\r\ninput=sys.stdin.readline\r\nt=1\r\nwhile(t):\r\n t-=1\r\n n=int(input())\r\n a=list(map(int,input().split()))\r\n b=a[:]\r\n b.sort()\r\n d=0\r\n for i in range(n):\r\n if b[i]!=a[i] :\r\n d+=1\r\n if(d>2):\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n", "n=int(input())\r\nfrom itertools import permutations as pem\r\nList=list(map(int, input().split()))\r\nnewlist=sorted(List)\r\ncount=0\r\nfor i in range(n):\r\n if newlist[i]!=List[i]:\r\n count+=1\r\nif count<=2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\na = list(map(int, input().split()))\r\ntemp = [num for num in a]\r\ntemp.sort()\r\ndiff = 0\r\nfor first, second in zip(a, temp):\r\n if first == second: continue\r\n else:\r\n diff += 1\r\nif diff <= 2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") ", "n = int(input())\n\narr = list(map(int, input().split()))\n\n\ndiff = 0\n\nfor el1, el2 in zip(arr, sorted(arr)):\n diff += el1 != el2\n\n\nprint(\"YES\" if diff <= 2 else \"NO\")", "n = int(input())\r\na = list(map(int,input().split()))\r\nb = sorted(a)\r\nl = list(map(lambda x,y:True if(x==y) else False,a,b))\r\nif l.count(False)<=2:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "k=int(input())\r\na=[int(i) for i in input().split()]\r\nb=sorted(a)\r\nc=0\r\nfor i in range(len(a)):\r\n if(a[i]!=b[i]):\r\n c+=1\r\nif(c<=2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n ", "import sys\ninput = sys.stdin.readline\nI = lambda : list(map(int,input().split()))\n\nn,=I()\nl=I()\nk=sorted(l)\nan=\"YES\"\np=0\nfor i in range(n):\n\tp+=(l[i]!=k[i])\nif p>2:\n\tan=\"NO\"\nprint(an)", "n=int(input())\r\nA=[int(i) for i in input().split(\" \")]\r\nB=[]\r\nfor i in A:\r\n B.append(i)\r\nB.sort()\r\nres=0\r\nfor i in range(n):\r\n res+= (B[i]!=A[i])\r\nif res<=2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=int(input());lt=list(map(int,input().split()))\r\nltt=sorted(lt)\r\nprint(\"YNEOS\"[sum(lt[i]!=ltt[i] for i in range(n))>2::2])", "from sys import stdin,stdout\r\nn=int(input())\r\nl=list(map(int,stdin.readline().split()))\r\nl1=l.copy()\r\nl1.sort()\r\nc=0\r\nans=True\r\nfor i in range(n):\r\n if l[i]!=l1[i]:\r\n c+=1\r\n if c==3:\r\n ans=False\r\n print(\"NO\")\r\n break\r\nif ans==True:\r\n print(\"YES\")\r\n \r\n \r\n", "from sys import stdin; inp = stdin.readline\r\nfrom math import dist, ceil, floor, sqrt\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()\r\n a = IA()\r\n s = sorted(a)\r\n c = 0 \r\n for i in range(n):\r\n if a[i] != s[i]:\r\n c+=1\r\n if c > 2:\r\n return 'NO'\r\n return'YES'\r\n \r\n \r\n\r\nif __name__ == '__main__':\r\n print(main())", "n=int(input())\r\na=[int(i) for i in input().split()]\r\nb=sorted(a)\r\nx=0\r\nfor i in range(n):\r\n if(a[i]!=b[i]):\r\n if(x==0):\r\n x=1\r\n elif(x==1):\r\n x=2\r\n else:\r\n x=3\r\n break\r\nif(x==3):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "import copy\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nasort = sorted(copy.deepcopy(a))\r\ndiff = 0\r\nfor i in range(n):\r\n if a[i] != asort[i]:\r\n diff += 1\r\n\r\nif a == asort or diff == 2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\n\r\na = [int(x) for x in input().split()]\r\nc = 0\r\nb = sorted(a) \r\nfor i in range(n):\r\n if a[i] != b[i]:\r\n c += 1\r\nif c > 2:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n", "import math,sys\nfrom sys import stdin, stdout\nfrom collections import Counter, defaultdict, deque\ninput = stdin.readline\nI = lambda:int(input())\nli = lambda:list(map(int,input().split()))\n\n\ndef case():\n\tn=I()\n\ta=li()\n\tb=a.copy()\n\tb.sort()\n\tans=[]\n\tc=0\n\tfor i in range(n):\n\t\tif(a[i]!=b[i]):\n\t\t\tc+=1\n\t\t\tans.append(i)\n\tif(c==0):\n\t\tprint(\"YES\")\n\telif(c==2):\n\t\ta[ans[0]],a[ans[1]]=a[ans[1]],a[ans[0]]\n\t\tif(a==b):\n\t\t\tprint(\"YES\")\n\t\telse:\n\t\t\tprint(\"NO\")\n\telse:\n\t\tprint(\"NO\")\n\t\t\n\nfor _ in range(1):\n\tcase()", "n=int(input())\r\na=list(map(int,input().split()))\r\nl=a.copy()\r\nl.sort()\r\n\r\nc=0\r\nfor i in range(n):\r\n if l[i]!=a[i]:\r\n c+=1\r\nif c>2:\r\n print(\"No\")\r\nelse:\r\n print(\"Yes\")", "array=[]\ncount=0\nn=int(input())\narray=[int (x) for x in input().split()]\narr=[]\nfor i in range(0,n):\n arr.append(array[i])\narr.sort()\nfor j in range(0,n):\n if(arr[j] != array[j]):\n count+=1\nif(count<=2):\n print(\"YES\")\nelse:\n print(\"NO\")\n\n \t\t \t\t\t\t \t\t\t\t\t \t\t\t\t\t \t \t\t", "x = int(input())\nl = list(map(int,input().split()))\nw = l.copy()\nw.sort()\n\nc = -1\nfor i,j in zip(l,w):\n if(i != j):\n c = c+1\n if(c > 1):\n print(\"NO\")\n exit()\n\n\nif(c <= 1):\n print(\"YES\")\n", "'''\r\nCreated on Apr 30, 2016\r\nGmail : [email protected]\r\n@author: Md. Rezwanul Haque\r\n'''\r\nn = int(input())\r\na = list(map(int,input().split()))\r\nb = list(a)\r\n#print(b)\r\na.sort()\r\n#print(a)\r\ncnt = 0\r\nfor i in range(n):\r\n if(b[i]!=a[i]):\r\n cnt+=1\r\nif(cnt<=2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "from math import sqrt\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\nn=ii()\r\na=li()\r\nb=a[:]\r\nb.sort()\r\nc=0\r\nfor i in range(n):\r\n if(a[i]!=b[i]):\r\n c+=1\r\nif(c==2 or c==0):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\na=[int(x) for x in input().split()]\r\nb=sorted(a)\r\nnum=0\r\nfor i in range(n):\r\n if a[i]!=b[i]:\r\n num+=1\r\n if num>2:\r\n print('NO')\r\n break\r\nif num==2 or num==0:\r\n print('YES')\r\n", "n = int(input())\r\na = list(map(int,input().split()))\r\nc = sorted(a)\r\nl = 0\r\nfor i in range(len(a)):\r\n if(c[i]!=a[i]):\r\n l+=1\r\nif(l>2):\r\n print('NO')\r\nelse:\r\n print('YES')\r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nk=[]\r\nk.extend(l)\r\nk.sort()\r\ncount=0\r\ni=0\r\nj=0\r\nwhile i!=(n):\r\n while j!=(n):\r\n if l[i]!=k[j]:\r\n count+=1\r\n i=i+1\r\n j=j+1\r\nif count>2:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\") \r\n \r\n \r\n \r\n", "import os\r\nimport sys\r\nimport math\r\nfrom collections import deque, defaultdict\r\nimport bisect\r\nimport heapq\r\n\r\nsys.setrecursionlimit(100000)\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef multiple():\r\n a = map(int, input().split())\r\n return a\r\n\r\n\r\ndef array():\r\n a = input().split()\r\n return a\r\n\r\n\r\ndef intarray():\r\n a = list(map(int, input().split()))\r\n return a\r\n\r\n\r\ndef intinput():\r\n n = int(input())\r\n return n\r\n\r\n\r\ndef strinput():\r\n s = input().strip()\r\n return s\r\n\r\n\r\ndef isPrime(n):\r\n val = int(math.sqrt(n)) + 1\r\n for i in range(2, val):\r\n if n % i == 0:\r\n return False\r\n return True\r\n\r\n\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 solution():\r\n # MOD = 998244353\r\n MOD = 1000000007\r\n n = intinput()\r\n a = intarray()\r\n b = a.copy()\r\n b.sort()\r\n count = 0\r\n for i in range(n):\r\n if a[i] != b[i]:\r\n count += 1\r\n if count > 2:\r\n print('NO')\r\n else:\r\n print('YES')\r\nt = 1\r\n# t = int(input())\r\nfor _ in range(t):\r\n # print(\"Case #%s:\" % str(_ + 1), end=' ')\r\n solution()\r\n", "import sys\r\ndef exi():\r\n print(\"NO\")\r\n sys.exit()\r\nI=lambda:list(map(int,input().split()))\r\nn,=I()\r\nl=I()\r\na=l.copy()\r\na.sort()\r\nt=0\r\nfor i in range(n):\r\n if a[i]!=l[i]:\r\n t+=1\r\n if t>2:\r\n exi()\r\nprint('YES')\r\n", "def dif():\r\n cnt = 0\r\n for i , j in zip(inp , srt):\r\n if i != j:\r\n cnt += 1\r\n return cnt\r\nn = int(input())\r\ninp = list(map(int , input().split()))\r\nsrt = sorted(inp)\r\nif dif ()<= 2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=int(input())\r\n\r\na=list(map(int,input().split()))\r\n\r\nsortedA=sorted(a)\r\nif sortedA==a:\r\n print(\"YES\")\r\nelse: \r\n # fst=0\r\n # snd=0\r\n cnt=0\r\n for i in range(len(a)):\r\n if a[i]!=sortedA[i]:\r\n cnt+=1\r\n\r\n # fst-=1\r\n # print(fst)\r\n # print(snd)\r\n # a[fst],a[snd]=a[snd],a[fst]\r\n\r\n if cnt==2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\n\r\n", "n=int(input())\r\na=[int(i) for i in input().split()]\r\nb=[]\r\ncount=0\r\nfor i in a:\r\n b.append(i)\r\nb.sort()\r\n\r\nfor i in range(len(a)):\r\n if(a[i]!=b[i]):\r\n count+=1\r\n \r\nif(count<=2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\na = list(map(int, input().split()))\r\nb = sorted(a)\r\nres = 0\r\nfor i in range(n):\r\n if a[i] != b[i]:\r\n res += 1\r\nprint('YES' if res <= 2 else 'NO')\r\n", "\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nl=sorted(a)\r\nc=0\r\nfor i in range(n):\r\n\tif a[i]!=l[i]:\r\n\t\tc+=1\r\n\tif c>2:\r\n\t\tbreak\r\nif c>2:\r\n\tprint('NO')\r\nelse:\r\n\tprint(\"YES\")", "import collections\r\n\r\n\r\n#t = int(input())\r\nt = 1\r\n\r\nfor tc in range(t):\r\n\tn = int(input())\r\n\ta = list(map(int,input().split()))\r\n\t#n,x = map(int,input().split())\r\n\tb = sorted(a)\r\n\r\n\tcnt = 0\r\n\r\n\tfor i in range(len(a)):\r\n\t\tif b[i]!=a[i]:\r\n\t\t\tcnt+=1\r\n\r\n\tif cnt==2 or cnt==0:\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")\r\n\r\n\r\n\r\n", "n=int(input())\r\nl1=list(map(int,input().split()))\r\nl2=l1[:]\r\nl2.sort()\r\nc=0\r\nflg=0\r\nfor i in range(n):\r\n if(l1[i]!=l2[i]):\r\n if(c==2):\r\n flg=1\r\n break\r\n c=c+1\r\nif(flg==1):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n ", "from collections import defaultdict, deque, Counter, OrderedDict\r\n\r\ndef main():\r\n n = int(input())\r\n l = [int(i) for i in input().split()]\r\n ls = sorted(l[:])\r\n c = 0\r\n for i in range(n):\r\n if l[i] != ls[i]:\r\n c += 1\r\n if c == 2 or c == 0:\r\n print(\"yes\")\r\n else:\r\n print(\"no\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n \"\"\"sys.setrecursionlimit(400000)\r\n threading.stack_size(40960000)\r\n thread = threading.Thread(target=main)\r\n thread.start()\"\"\"\r\n main()", "n = int(input())\r\na = list(map(int, input().split()))\r\nb = a[:]\r\n\r\na.sort()\r\ncnt = 0\r\n\r\nfor i in range(n):\r\n if a[i] != b[i]:\r\n cnt += 1\r\n\r\nif cnt <= 2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "from sys import *\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nk = 0\r\nb = sorted(a)\r\nfor i in range(n):\r\n if b[i] != a[i]:\r\n k += 1\r\nif k < 3:\r\n print('YES')\r\n exit(0)\r\nprint('NO')\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\nt = [*a]\r\nkol =0\r\na.sort()\r\nfor i in range(n):\r\n if a[i] != t[i]:kol += 1\r\nif kol <= 2:print('YES')\r\nelse:print('NO')\r\n", "n = int(input())\n\nnums = [int(i) for i in input().split()]\n\nsnums = sorted(nums)\n\nl = len(nums)\ncount = 0\n\nfor i in range(n):\n\tif nums[i] != snums[i]:\n\t\tcount += 1\n\tif count > 2:\n\t\tprint(\"NO\")\n\t\tbreak\nelse:\n\tprint(\"YES\")\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\nb=sorted(a)\r\nc=0\r\np=0\r\nfor i in range(n):\r\n if a[i]!=b[i]:\r\n c+=1\r\n if c>2:\r\n p=1\r\n break\r\nif p==0 and c!=1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\nli = list(map(int,input().split(\" \",n)[:n]))\r\nc=0\r\nli1=sorted(li)\r\nfor i in range(n):\r\n if li[i]!=li1[i]:\r\n c+=1\r\nif c==0 or c==2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def indx(num):\r\n for i in range(n-1,-1,-1):\r\n if arr[i]==num:\r\n return i\r\nn = int(input())\r\narr = list(map(int,input().split()))\r\nsorted_arr = sorted(arr)\r\ncount = 0\r\nfor i in range(n):\r\n if arr[i] != sorted_arr[i]:\r\n index = indx(sorted_arr[i])\r\n arr[i],arr[index]=arr[index],arr[i]\r\n count += 1\r\n if count == 2:\r\n print('NO')\r\n break\r\nif count != 2:\r\n print('YES')\r\n\r\n\r\n\r\n\r\n\r\n\r\n# 1 2 2 1 2 2 3", "# author: ankan2526\r\n\r\nimport math, bisect, heapq, random, sys, itertools\r\ninput=sys.stdin.readline\r\nints = lambda : list(map(int,input().split()))\r\np=10**9+7\r\nalpha = \"abcdefghijklmnopqrstuvwxyz\"\r\n\r\nn=int(input())\r\na=ints()\r\nb=sorted(a)\r\nc=0\r\nfor i in range(n):\r\n if a[i]!=b[i]:\r\n c+=1\r\nif c<=2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\na = [int(x) for x in input().split()]\nb = sorted(a)\nprint('YES' if sum(x != y for x, y in zip(a, b)) <= 2 else 'NO')\n", "n=int(input())\r\nz=n*[0]\r\na=[int(i) for i in input().split()]\r\nz[ : ]=a[ : ]\r\nz.sort()\r\nt=0\r\nfor i in range(n):\r\n if z[i]!=a[i]:\r\n t=t+1\r\nif t>2:\r\n print('NO')\r\nelse:\r\n print('YES')\r\n", "n = int(input())\r\na = [int(k) for k in input().split()]\r\nb=sorted(a)\r\n#c = [0]*n\r\ncount = 0\r\nfor i in range(n):\r\n if a[i]-b[i] != 0:\r\n count+=1\r\nif count > 2:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "import math\r\nfor _ in range(1):\r\n n=int(input())\r\n l=list(map(int,input().split()))\r\n s=sorted(l)\r\n c=0\r\n for i in range(n):\r\n if l[i]!=s[i]:\r\n c+=1\r\n if c>2:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n \r\n ", "n = int(input())\r\nmas = list(map(int,input().split()))\r\nmasort = sorted(mas)\r\nans = 0\r\nfor i in range(n):\r\n if mas[i]!=masort[i]:\r\n ans+=1\r\nif ans==0 or ans==2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import sys,os,io\r\nfrom math import log, gcd\r\nfrom collections import defaultdict, deque\r\nfrom heapq import heappush, heappop\r\n\r\n\r\n# Iterative Python3 program \r\n# to compute modular power \r\n\r\n# Iterative Function to calculate \r\n# (x^y)%p in O(log y) \r\ndef power(x, y, p) : \r\n\tres = 1\r\n\tx = x % p \r\n\tif (x == 0) : \r\n\t\treturn 0\r\n\twhile (y > 0) : \r\n\t\tif ((y & 1) == 1) : \r\n\t\t\tres = (res * x) % p \r\n\t\ty = y >> 1\t # y = y/2 \r\n\t\tx = (x * x) % p \t\t\r\n\treturn res \r\n\r\n\r\ndef si():\r\n return input()\r\n\r\n# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef prefix_sum(arr):\r\n r = [0] * (len(arr)+1)\r\n for i, el in enumerate(arr):\r\n r[i+1] = r[i] + el\r\n return r\r\n\r\ndef divideCeil(n,x):\r\n if (n%x==0):\r\n return n//x\r\n return n//x+1\r\n\r\ndef ii():\r\n return int(input())\r\n\r\ndef li():\r\n return list(map(int,input().split()))\r\n\r\n\r\n\r\n# t = int(input())\r\nt = 1\r\nfor _ in range(t):\r\n n = ii()\r\n l = li()\r\n l1 = l[:]\r\n l1.sort()\r\n pos = []\r\n for i in range(n):\r\n if (l1[i]!=l[i]):\r\n pos.append(i)\r\n if (len(pos)==0) or (len(pos)==2 and l[pos[0]]==l1[pos[1]] and l[pos[1]]==l1[pos[0]]):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\n\r\n ", "n=int(input())\r\nl=[int(i) for i in input().split()]\r\nl1=sorted(l)\r\nc=0\r\nfor i in range(n):\r\n if(l1[i]!=l[i]):\r\n c+=1\r\nif(c>2):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "n = int(input())\r\narr = list(map(int, input().split()))\r\nideal = sorted(arr)\r\ni = 0\r\nc = 0\r\nf = 1\r\nwhile i < n:\r\n if arr[i] != ideal[i]:\r\n c += 1\r\n i += 1\r\n if c > 2:\r\n f = 0\r\n break\r\nif f == 1:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n# little elephant\r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\ng=sorted(l)\r\nans=0\r\nfor i in zip(l,g):\r\n if i[0]!=i[1]:\r\n ans+=1\r\nprint(\"YES\") if ans<=2 else print(\"NO\")", "n=int(input())\r\na=list(map(int,input().split()))\r\nasort=sorted(a)\r\nrank={}\r\nfor i in range(n):\r\n if asort[i] not in rank:\r\n rank[asort[i]]=[i,i]\r\n else:\r\n rank[asort[i]][1]=i\r\n\r\nc=0\r\ntwo=[]\r\nfor i in range(n):\r\n if not (rank[a[i]][0]<=i<=rank[a[i]][1]):\r\n two.append(i)\r\n c+=1\r\n if c>2:\r\n print(\"NO\")\r\n break\r\nelse:\r\n if c==0:\r\n print(\"YES\")\r\n elif c==2:\r\n cond1=(rank[a[two[0]]][0]<=two[1]<=rank[a[two[0]]][1])\r\n cond2=(rank[a[two[1]]][0]<=two[0]<=rank[a[two[1]]][1])\r\n if cond1 and cond2:\r\n print(\"YES\") \r\n else:\r\n print(\"NO\")\r\n \r\n \r\n \r\n \r\n \r\n \r\n", "from sys import stdin\r\n\r\nA = int(stdin.readline())\r\nB = list(map(int,stdin.readline().split()))\r\nC = B.copy()\r\nC.sort()\r\ncount =0\r\nK = 0\r\n\r\nfor k in range(0,A):\r\n if B[k]!=C[k]:\r\n count+=1\r\n\r\n if count > 2:\r\n K=1\r\n break\r\n\r\nif K==1:\r\n print('NO')\r\nelse:\r\n print('YES')", "# cook your dish here\r\nn=int(input())\r\narr=[int(x) for x in input().split()]\r\nli=arr[:]\r\nli.sort()\r\nc=0\r\nfor i in range(n):\r\n if(arr[i]!=li[i]):\r\n c+=1\r\n if(c>2):\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")", "\r\nimport sys\r\ndef get_ints(): return list(map(int, sys.stdin.readline().strip().split()))\r\n\r\nn = int(input())\r\narr = get_ints()\r\nsortedarr = sorted(arr)\r\ncount = 0 \r\nfor index, i in enumerate(arr):\r\n if i != sortedarr[index]:\r\n count += 1 \r\nif count > 2:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n \r\n \r\n \r\n \r\n \r\n ", "n=int(input())\r\ntab=list(map(int,input().split(\" \")))\r\ntab1=list(tab)\r\ntab1.sort()\r\ncp=0\r\nfor i in range(n):\r\n if (tab[i]!=tab1[i]):\r\n cp+=1\r\nif (cp>2):\r\n print(\"NO\")\r\nelse: print(\"YES\")", "n = int(input())\r\na = list(map(int, input().split()))\r\nac = a[::]\r\nac.sort()\r\n\r\ncount = 0\r\nfor i in range(n):\r\n if a[i] == ac[i]: continue\r\n count += 1\r\nprint('YES' if count < 3 else 'NO')\r\n", "n=int(input())\na=[int(i) for i in input().split()]\nsorteda=sorted(a)\nc=0\nfor i in range(n):\n if a[i]!=sorteda[i]:c+=1\n if c==3:\n print('NO')\n break\nif c!=3:\n print('YES')\n \t \t\t \t\t\t \t \t \t\t\t \t \t \t \t" ]
{"inputs": ["2\n1 2", "3\n3 2 1", "4\n4 3 2 1", "3\n1 3 2", "2\n2 1", "9\n7 7 8 8 10 10 10 10 1000000000", "10\n1 2 9 4 5 6 7 8 3 10", "4\n2 2 2 1", "10\n1 2 4 4 4 5 5 7 7 10", "10\n4 5 11 12 13 14 16 16 16 18", "20\n38205814 119727790 127848638 189351562 742927936 284688399 318826601 326499046 387938139 395996609 494453625 551393005 561264192 573569187 600766727 606718722 730549586 261502770 751513115 943272321", "47\n6 277 329 393 410 432 434 505 529 545 650 896 949 1053 1543 1554 1599 1648 1927 1976 1998 2141 2248 2384 2542 2638 2995 3155 3216 3355 3409 3597 3851 3940 4169 4176 4378 4378 4425 4490 4627 4986 5025 5033 5374 5453 5644", "50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 9 5", "100\n3 7 7 8 15 25 26 31 37 41 43 43 46 64 65 82 94 102 102 103 107 124 125 131 140 145 146 150 151 160 160 161 162 165 169 175 182 191 201 211 214 216 218 304 224 229 236 241 244 249 252 269 270 271 273 289 285 295 222 307 312 317 319 319 320 321 325 330 340 341 345 347 354 356 366 366 375 376 380 383 386 398 401 407 414 417 423 426 431 438 440 444 446 454 457 458 458 466 466 472", "128\n1 2 4 6 8 17 20 20 23 33 43 49 49 49 52 73 74 75 82 84 85 87 90 91 102 103 104 105 111 111 401 142 142 152 155 160 175 176 178 181 183 184 187 188 191 193 326 202 202 214 224 225 236 239 240 243 246 247 249 249 257 257 261 264 265 271 277 281 284 284 286 289 290 296 297 303 305 307 307 317 318 320 322 200 332 342 393 349 350 350 369 375 381 381 385 385 387 393 347 397 398 115 402 407 407 408 410 411 411 416 423 426 429 429 430 440 447 449 463 464 466 471 473 480 480 483 497 503", "4\n5 12 12 6", "5\n1 3 3 3 2", "4\n2 1 1 1", "2\n1 1", "4\n1000000000 1 1000000000 1", "11\n2 2 2 2 2 2 2 2 2 2 1", "6\n1 2 3 4 5 3", "9\n3 3 3 2 2 2 1 1 1", "4\n4 1 2 3", "6\n3 4 5 6 7 2", "4\n4 2 1 3", "4\n3 3 2 2", "4\n3 2 1 1", "4\n4 5 1 1", "6\n1 6 2 4 3 5", "5\n1 4 5 2 3", "4\n2 2 1 1", "5\n1 4 3 2 1", "5\n1 4 2 2 3", "6\n1 2 3 1 2 3", "3\n3 1 2", "5\n5 1 2 3 4", "5\n3 3 3 2 2", "5\n100 5 6 10 7", "3\n2 3 1", "5\n4 4 1 1 1", "5\n1 2 5 3 4", "4\n3 4 1 2", "4\n2 4 1 5", "5\n1 3 3 2 2", "5\n1 5 4 4 4", "7\n3 2 1 2 3 5 4", "5\n1 1 3 2 2", "9\n1 8 7 7 7 7 7 8 3", "5\n1 3 2 3 3", "10\n4 4 4 4 10 4 4 4 4 4", "8\n3 6 6 6 6 6 4 9", "4\n4 4 3 3", "4\n3 2 2 4", "5\n2 2 1 3 3", "5\n1 2 7 3 5", "5\n2 3 4 5 1", "6\n1 4 3 6 2 5", "5\n3 3 1 5 4", "4\n1 2 1 2", "6\n4 5 3 4 2 6", "11\n1 2 3 4 5 1 2 3 4 5 1", "6\n6 1 2 3 4 5", "5\n4 1 1 1 1", "9\n1 2 3 5 4 6 7 8 9", "6\n6 1 2 3 4 2", "6\n2 2 2 2 3 2", "3\n2 1 1", "5\n1 2 1 1 2", "5\n1 2 2 1 2", "8\n5 5 5 5 5 5 1 1"], "outputs": ["YES", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "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", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "NO", "YES", "YES", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "YES", "NO", "YES", "YES", "YES", "YES", "NO"]}
UNKNOWN
PYTHON3
CODEFORCES
183
16e2a8ba7b90c835d233f81974a1987e
A and B and Interesting Substrings
A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercase letters of the Latin alphabet. He has assigned to each letter a number that shows how much he likes that letter (he has assigned negative numbers to the letters he dislikes). B likes substrings. He especially likes the ones that start and end with the same letter (their length must exceed one). Also, A and B have a string *s*. Now they are trying to find out how many substrings *t* of a string *s* are interesting to B (that is, *t* starts and ends with the same letter and its length is larger than one), and also the sum of values of all letters (assigned by A), except for the first and the last one is equal to zero. Naturally, A and B have quickly found the number of substrings *t* that are interesting to them. Can you do it? The first line contains 26 integers *x**a*,<=*x**b*,<=...,<=*x**z* (<=-<=105<=≤<=*x**i*<=≤<=105) — the value assigned to letters *a*,<=*b*,<=*c*,<=...,<=*z* respectively. The second line contains string *s* of length between 1 and 105 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer. Print the answer to the problem. Sample Input 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1 xabcab 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1 aaa Sample Output 2 2
[ "cnt = list(map(int, input().split()))\r\ns = input().strip()\r\nn = len(s)\r\nsum_val = [0] * (n + 1)\r\nans = 0\r\n\r\npos = [[] for _ in range(26)]\r\nfor i in range(1, n + 1):\r\n sum_val[i] = cnt[ord(s[i - 1]) - ord('a')]\r\n sum_val[i] += sum_val[i - 1]\r\n pos[ord(s[i - 1]) - ord('a')].append(i)\r\n\r\nfor cc in range(26):\r\n Map = {}\r\n\r\n for p in pos[cc]:\r\n ans += Map.get(sum_val[p - 1], 0)\r\n Map[sum_val[p]] = Map.get(sum_val[p], 0) + 1\r\n\r\nprint(ans)\r\n", "if __name__ == '__main__':\n likeability = list(map(int, input().split()))\n s = input().lower()\n add = [0] * len(s)\n add[0] = likeability[ord(s[0])-97]\n for i in range(1, len(s)):\n add[i] = add[i-1] + likeability[ord(s[i])-97]\n\n mat = {}\n for i in range(26):\n mat[i] = {}\n mat[ord(s[0])-97][add[0]] = 1\n res = 0\n\n for i in range(1, len(s)):\n chr = ord(s[i])-97\n if add[i-1] in mat[chr]: # nao precisa somar o char atual\n res += mat[chr][add[i-1]]\n if add[i] in mat[chr]:\n mat[chr][add[i]] = mat[chr][add[i]]+1\n else:\n mat[chr][add[i]] = 1\n\nprint(res)\n\n \t \t \t \t \t\t\t \t \t\t \t", "from collections import defaultdict\r\n\r\nval = list(map(int, input().split()))\r\ns = input()\r\n\r\npos = [[] for i in range(26)]\r\nsm = []\r\nfor i, c in enumerate(s):\r\n v = ord(c) - ord('a')\r\n if i == 0:\r\n sm.append(val[v])\r\n else:\r\n sm.append(sm[-1] + val[v])\r\n pos[v].append(i)\r\n\r\nans = 0\r\nfor c in range(26):\r\n m = defaultdict(int)\r\n for i in pos[c]:\r\n if i > 0:\r\n ans += m[sm[i-1]]\r\n m[sm[i]] += 1\r\nprint(ans)", "from bisect import bisect_left\nnums = list(map(int, input().split(' ')))\ns = input()\npre = []\ntot = 0\nd = {}\nfor i in range(len(s)):\n tot += nums[ord(s[i]) - ord('a')]\n pre.append(tot)\n if s[i] not in d:\n d[s[i]] = []\n d[s[i]].append(i)\nans = 0\nfor ch in d:\n g = {}\n if len(d[ch]) == 1:\n continue\n for i in d[ch]:\n if pre[i] not in g:\n g[pre[i]] = []\n g[pre[i]].append(i)\n k = nums[ord(ch) - ord('a')]\n for i in g:\n if i - k in g:\n for j in g[i]:\n ans += bisect_left(g[i - k], j)\nprint(ans)\n\n\n \n\n \t\t\t \t\t \t \t\t\t \t\t \t\t \t\t\t", "l=list(map(int,input().split()))\r\ns=input()\r\nt={}\r\ntemp=0\r\nans=0\r\nj=0\r\nn=len(s)\r\nwhile j<n:\r\n p=s[j]\r\n r=j\r\n while j+1<n and s[j+1]==p:\r\n j+=1\r\n ans+=j-r\r\n j+=1\r\n \r\n \r\nfor i in range(len(s)):\r\n temp+=l[ord(s[i])-ord(\"a\")]\r\n if temp in t:\r\n if i+1<len(s):\r\n ans+=t[temp][ord(s[i+1])-ord(\"a\")]\r\n t[temp][ord(s[i])-ord(\"a\")]+=1\r\n else :\r\n t[temp]=[0]*(26)\r\n t[temp][ord(s[i])-ord(\"a\")]+=1\r\nprint(ans)\r\n \r\n ", "a = [*map(int, input().split())]\r\nb = input()\r\ns = {}\r\nq = 0\r\nw = 0\r\nfor x in b:\r\n w += s.get((q, x), 0)\r\n q += a[ord(x)-ord('a')]\r\n s[(q, x)] = s.get((q, x), 0) + 1\r\nprint(w)", "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nl=[int(i) for i in input().split()]\r\ns=input()\r\nd=[]\r\nfor i in range(26):\r\n d.append({})\r\ns1=0\r\nc=0\r\nfor i in range(len(s)):\r\n n=ord(s[i])-ord('a')\r\n c+=d[n].get(s1,0)\r\n s1+=l[n]\r\n d[n][s1]=d[n].get(s1,0)+1\r\nprint(c)", "from collections import defaultdict\r\n\r\ndef alphaToIndex(x):\r\n return ord(x)-97\r\n\r\nlikes = list(map(int,input().split()))\r\n\r\ns = input()\r\nn = len(s)\r\nprefix = [0]*(n+1) #prefix sum array\r\nprefix[1] = likes[alphaToIndex(s[0])]\r\n\r\nfor i in range(2,n+1):\r\n prefix[i] = prefix[i-1]+likes[alphaToIndex(s[i-1])]\r\n\r\nidx = [[] for _ in range(26)] #to store index of each alphabet in order\r\nfor x in range(n):\r\n idx[alphaToIndex(s[x])].append(x)\r\n\r\nans = 0\r\nfor alpha in idx: #iterate over each alphabet\r\n m = defaultdict(int) # to store count of each prefix sum occurange ending with this letter\r\n for i in alpha: #iterate over each index of alphabet\r\n ans += m[prefix[i]]\r\n m[prefix[i+1]]+=1\r\n\r\nprint(ans)\r\n", "x = list(map(int, input().split()))\n\ns = input()\n\nw = [{} for _ in range(26)]\nsum_ = 0\nans = 0\nfor i in range(len(s)):\n\n n = ord(s[i])-ord('a')\n ans += w[n].get(sum_, 0)\n sum_ += x[n]\n w[n][sum_] = w[n].get(sum_, 0) + 1\nprint(ans)\n\n", "arr= list(map(int,input().split()))\r\nstring = input()\r\nfrom collections import defaultdict\r\ndic = defaultdict(lambda:0)\r\nsumm = 0\r\nans= 0\r\nfor i in range(len(string)):\r\n ans+= dic[ord(string[i])-ord(\"a\"),summ]\r\n summ += arr[ord(string[i])-ord(\"a\")]\r\n dic[ord(string[i])-ord(\"a\"),summ]+=1\r\nprint(ans)", "import sys\nimport string\nfrom collections import defaultdict,Counter\ndef solve(vals,s):\n past = defaultdict(Counter)\n pref = 0\n res = 0\n for x in s:\n res +=past[x][pref]\n pref +=vals[ord(x) - ord('a')]\n past[x][pref] +=1 \n return res\n# input\n# t = int(sys.stdin.readline())\n# solve here\n# input processing\nfor _ in range(1):\n vals = list(map(int,input().split()))\n s = input()\n print(solve(vals,s))\n \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,prod\nalph = 'abcdefghijklmnopqrstuvwxyz'\n#pow(x,mod-2,mod)\n\nA = list(map(int,input().split()))\nS = input()\nN = len(S)\n\ndic = {alph[i]:A[i] for i in range(26)}\nl = [dic[S[0]]]\nfor i in range(1,N):l.append(l[-1]+dic[S[i]])\n\nans = 0\ns = {i:defaultdict(int) for i in alph}\ns[S[0]][l[0]]+=1\n\nfor i in range(1,N):\n num = l[i]-dic[S[i]]\n # print(num,s[S[i]])\n ans+=s[S[i]][num]\n s[S[i]][l[i]]+=1\nprint(ans)\n\n", "\n\nC = list(map(int,input().split()))\n\ns = input()\n\nprefixC = [0]*(len(s)+1)\n\nfor i in range(1,len(s)+1):\n prefixC[i] = prefixC[i-1] + C[ord(s[i-1]) - ord('a')]\n\nPos = {}\n\nfor j in range(len(s)):\n i = s[j]\n if i in Pos:\n Pos[i].append(j)\n else:\n Pos[i] = [j]\n\nans = 0 \nM = {}\n\nfor i in (set(s)):\n for j in Pos[i]:\n ans += M.get((i,prefixC[j]),0)\n if (i,prefixC[j+1]) in M:\n M[(i,prefixC[j+1])] += 1 \n else:\n M[(i,prefixC[j+1])] = 1 \n\nprint(ans)\n\n \t \t\t\t\t\t \t \t \t\t \t\t\t \t", "import string\r\nfrom collections import defaultdict\r\ncst=[*map(int,input().strip().split())]\r\nl=list(string.ascii_lowercase)\r\ncst={l[i]:cst[i] for i in range(26)}\r\ns=input()\r\ncnt=defaultdict(lambda:defaultdict(int))\r\npref=0\r\nans=0\r\nfor i in s:\r\n # pref+=cst[i]\r\n # print(\"pref \",pref)\r\n #prefr-prefl=0\r\n req=pref\r\n ans+=cnt[pref][i]\r\n pref+=cst[i]\r\n cnt[pref][i]+=1\r\nprint(ans)\r\n", "if __name__ == '__main__':\n X = [int(i) for i in input().split()]\n s = input()\n arr = []\n unicode_a = ord('a')\n for i in range(26):\n arr.append({})\n sm = 0\n k = 0\n for char in s:\n n = ord(char) - unicode_a\n k += arr[n].get(sm, 0)\n sm += X[n]\n arr[n][sm] = arr[n].get(sm, 0) + 1\n print(k)\n \t\t\t\t\t\t\t\t\t \t\t \t\t \t\t\t \t\t", "from collections import Counter\r\nA = list(map(int, input().split()))\r\nL = [ord(i) - ord('a') for i in input()]\r\nscore = ans = 0\r\nD = [Counter() for i in range(26)]\r\nfor i in L:\r\n ans += D[i][score]\r\n score += A[i]\r\n D[i][score] += 1\r\nprint(ans)\r\n", "import collections\n\nx = [int(i) for i in input().split()]\nstring = input()\nlista = [ord(i) - ord('a') for i in string]\naux, resp = 0, 0\n\ndic = [collections.Counter() for i in range(26)]\n\nfor i in lista:\n resp += dic[i][aux]\n aux += x[i]\n dic[i][aux] += 1\n\nprint(resp)\n\t \t\t \t\t \t\t\t\t \t\t\t \t \t \t", "import itertools\r\nimport math\r\nimport threading\r\nimport time\r\nfrom builtins import input, range\r\nfrom math import gcd as gcd\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\nimport queue\r\nimport itertools\r\nimport collections\r\nfrom heapq import heappop, heappush\r\nimport random\r\nimport os\r\nfrom random import randint\r\nimport decimal\r\nfrom math import factorial as fac\r\n\r\n\r\ndef solve():\r\n x = list(map(int, input().split()))\r\n s = str(sys.stdin.readline()[:-1])\r\n\r\n best_for = [{} for i in range(26)]\r\n res = 0\r\n cur_score = 0\r\n\r\n for i in s:\r\n f = ord(i) - 97\r\n\r\n if cur_score in best_for[f]:\r\n res += best_for[f][cur_score]\r\n\r\n cur_score += x[f]\r\n if cur_score not in best_for[f]:\r\n best_for[f][cur_score] = 1\r\n else:\r\n best_for[f][cur_score] += 1\r\n\r\n print(res)\r\n\r\n\r\nif __name__ == '__main__':\r\n multytest = False\r\n\r\n if multytest:\r\n t = int(input())\r\n for i in range(t):\r\n solve()\r\n else:\r\n solve()\r\n", "\r\nimport math \r\nimport sys\r\nfrom decimal import Decimal\r\ndef main(arr,s):\r\n\r\n\r\n cnt={} \r\n prefix=[arr[ord(s[0])-97]]\r\n\r\n for i in range(1,len(s)):\r\n prefix.append(prefix[-1]+arr[ord(s[i])-97])\r\n ans=0\r\n for i in range(0,len(s)):\r\n l=s[i] \r\n val=prefix[i]\r\n sub=arr[ord(s[i])-97] \r\n key=(val-sub,l)\r\n if key in cnt:\r\n ans+=cnt[key] \r\n \r\n if (val,l) not in cnt:\r\n cnt[(val,l)]=0 \r\n cnt[(val,l)]+=1 \r\n \r\n return ans \r\n\r\narr=list(map(int,input().split()))\r\ns=input()\r\nprint(main(arr,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" ]
{"inputs": ["1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naabbccdd", "-3 4 -4 -1 3 5 -5 -3 3 2 1 4 5 -3 -1 4 2 -2 1 -1 1 5 -4 0 -5 4\nolspxykjqr", "-2 -2 2 1 4 0 -2 4 5 4 -5 -5 2 1 1 -1 0 -5 -2 3 -2 4 5 2 3 -5\nqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavsovisrmfaefusoobingjhsmrukx", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nbb", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\na", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\nhhhhhhhhhh"], "outputs": ["2", "2", "4", "0", "7", "1", "0", "45"]}
UNKNOWN
PYTHON3
CODEFORCES
19
16ea217382917bb89accb42f3a9c6795
Flag
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard. The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square. Output YES, if the flag meets the new ISO standard, and NO otherwise. Sample Input 3 3 000 111 222 3 3 000 000 111 3 3 000 111 002 Sample Output YES NO NO
[ "i = input().split(\" \")\r\nn = int(i[0])\r\nm = int(i[1])\r\nflag = [input() for x in range(n)]\r\nprevious = \"\"\r\nresult = True\r\nfor row in flag:\r\n if not row == row[0]*m:\r\n result = False\r\n if row == previous:\r\n result = False\r\n previous = row\r\nif result:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n , m = map(int,input().split())\r\nl = []\r\nflag = 0\r\nfor i in range(n):\r\n\ts = input()\r\n\tif len(set(s))!=1:\r\n\t\tflag = 1\r\n\t\tprint(\"NO\")\r\n\t\tbreak\r\n\tif flag==1:\r\n\t\tbreak\t\r\n\telse:\r\n\t\tl.append(s)\r\nfor k in range(1,len(l)):\r\n\tif l[k-1]==l[k]:\r\n\t\tprint(\"NO\")\r\n\t\tflag = 1\r\n\t\tbreak\t\r\n\tif flag==1:\r\n\t\tbreak\t\t\t\r\nif flag==0:\r\n\tprint(\"YES\")\t\t", "class A:\n\n def solve(self):\n [n, m] = [int(x) for x in input().split(\" \")]\n flag = []\n for i in range(n):\n flag.append(input())\n\n if any([len(set(x)) != 1 for x in flag]):\n print(\"NO\")\n return\n\n first_colors = [x[0] for x in flag]\n if any([x == y for x, y in zip(first_colors, first_colors[1:])]):\n print(\"NO\")\n return\n\n print(\"YES\")\n\nA().solve()\n", "from sys import stdin\r\ndef main():\r\n a,b=[int(x)for x in stdin.readline().strip().split()]\r\n T=True\r\n for x in range(a):\r\n per=stdin.readline().strip()\r\n if T:\r\n for y in range(1,b):\r\n if per[0]!=per[y]:T=False\r\n if x==0:prob=per[0]\r\n else:\r\n if prob==per[0]:T=False\r\n else: prob=per[0]\r\n if T:print(\"YES\")\r\n else:print(\"NO\")\r\n \r\nmain()", "def flag():\r\n for i in range(n):\r\n for j in range(m):\r\n if l[i][j]!=l[i][0]:\r\n return False\r\n for i in range(1,n):\r\n if l[i][0]==l[i-1][0]:\r\n return False\r\n return True\r\nn,m=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n l.append(input())\r\nif flag():\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "import sys\n\nimport re\nimport collections\nimport math\nimport itertools\n\n\nclass Point(object):\n\tdef __init__(self, x=0, y=0):\n\t\tself.x = x\n\t\tself.y = y\n\n\n\ndef function(*args):\n y, x = map(int, input().split())\n res = []\n for _ in range(y):\n arr = [int(e) for e in input()]\n res.append(arr)\n prev = float('inf')\n ans = 'YES'\n for e in res:\n if len(set(e)) > 1 or e[0] == prev:\n ans = 'NO'\n prev = e[0]\n print(ans)\nif __name__ == '__main__':\n\tfunction()\t\n", "#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-03 22:34:11\nLastEditTime: 2021-11-03 22:44:56\nDescription: Flag\nFilePath: CF16A.py\n'''\n\n\ndef func():\n n, m = map(int, input().strip().split())\n flag = []\n for i in range(n):\n row = list(map(int, list(input().strip())))\n if list(set(row)) * m != row:\n return \"NO\"\n flag.append(list(set(row)))\n if i > 0 and flag[i] == flag[i - 1]:\n return \"NO\"\n return \"YES\"\n\n\nif __name__ == '__main__':\n ans = func()\n print(ans)\n", "n, m = map(int, input().split())\r\nok, prev = True, 'X'\r\nfor _ in range(n):\r\n row = input()\r\n if row != row[0] * m or row[0] == prev:\r\n ok = False \r\n break\r\n else:\r\n prev = row[0]\r\nprint([\"NO\",\"YES\"][ok])", "r, c = [int(x) for x in input().split()]\r\nlist_2 = []\r\nindex = 0\r\nprevious = -1\r\nfor i in range(r):\r\n list_2.append(list(input()))\r\nfor i in range(r):\r\n index = list_2[i][0]\r\n for j in range(c):\r\n if index != list_2[i][j] or list_2[i][j]==previous:\r\n print(\"NO\")\r\n exit()\r\n previous = index\r\n\r\n\r\nprint(\"YES\")\r\n\r\n\r\n\r\n\r\n", "m=[*open(0)][1:]\r\ne=any(len({*s})>2 for s in m)\r\nprint('YNEOS'[e|any(i[0]==l[0]for i,l in zip(m,m[1:]))::2])", "Flag, X = list(), list(map(int, input().split()))\r\nfor i in range(X[0]):\r\n Flag.append(input())\r\nfor i in range(len(Flag) - 1):\r\n if Flag[i].count(Flag[i][0]) != X[1] or Flag[i][0] == Flag[i + 1][0]:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\" if Flag[-1].count(Flag[-1][0]) == X[1] else \"NO\")\r\n\r\n# UB_CodeForces\r\n# Advice: Falling down is an accident, staying down is a choice\r\n# Location: Here in Bojnurd\r\n# Caption: Preparing for UBCOMP4\r\n# CodeNumber: 597\r\n", "n, m = [int(item) for item in input().split(' ')]\r\nans, prev = 'YES', ''\r\n\r\nfor i in range(n):\r\n current = input()\r\n if prev == current or current.count(current[0]) != m:\r\n ans = 'NO'\r\n break\r\n prev = current\r\nprint(ans)", "n,m=map(int,input().split())\r\nf=0\r\ng=0\r\nl=[]\r\nfor i in range(n):\r\n c=list(set([j for j in input()]))\r\n if len(c)!=1:\r\n f=1\r\n break\r\n else:\r\n l=l+c\r\nfor i in range(len(l)-1):\r\n if l[i]==l[i+1]:\r\n g=1\r\n break\r\n \r\nif g==1 or f==1:\r\n print('NO')\r\nelse:\r\n print('YES')\r\n \r\n", "rows,columns = map(int,input().split())\r\nflag = []\r\nfor i in range(rows):\r\n\t flag.append(list([char for char in input()]))\r\n\r\nfor row_i in range(len(flag)-1):\r\n\t# if incorrect color\r\n\tif len(set(flag[row_i])) > 1 or flag[row_i][0] == flag[row_i+1][0]: \r\n\t\tprint(\"NO\")\r\n\t\texit() \r\n\r\nif len(set(flag[len(flag)-1])) > 1: \r\n\t print(\"NO\")\r\n\t exit()\r\n\r\nprint('YES')\r\n\r\n", "\"\"\" According to a new ISO standard, a flag of every country should have a chequered field n x m,\r\n each square should be of one of 10 colours, and the flag should be «striped»:\r\n each horizontal row of the flag should contain squares of the same colour,\r\n and the colours of adjacent horizontal rows should be different.\r\nBerland's government asked you to find out whether their flag meets the new ISO standard.\r\n\r\nInput\r\nThe first line of the input contains numbers n and m (1 <= n, m <= 100),\r\n n - the amount of rows,\r\n m - the amount of columns on the flag of Berland.\r\nThen there follows the description of the flag: each of the following n lines contain m characters.\r\nEach character is a digit between 0 and 9, and stands for the colour of the corresponding square.\r\n\r\nOutput\r\nOutput YES, if the flag meets the new ISO standard, and NO otherwise. \"\"\"\r\n\r\nresult = \"YES\"\r\nn, m = map(int, input().split())\r\n# print(\"n = \" + str(n))\r\n# print(\"m = \" + str(m))\r\nbefore = \"\"\r\nfor i in range(n):\r\n s = input()\r\n c = s[0:1]\r\n\r\n if m != s.count(c):\r\n result = \"No\"\r\n break\r\n\r\n if i == 0:\r\n before = c\r\n continue\r\n\r\n if c == before:\r\n result = \"No\"\r\n break\r\n\r\n before = c\r\n\r\nprint(result)", "n,m=map(int,input().split())\nl=[]\nc=0\nfor i in range(n):\n s=list(input())\n x=list(set(s))\n if i==0:\n if len(x)>1:\n c=-1\n if i!=0:\n if x[0]==l[-1] or len(x)>1:\n c=-1\n else:\n l.append(x[0])\n else:\n l.append(x[0])\nif c==-1:\n print(\"NO\")\nelse:\n print(\"YES\")\n", "n,m=list(map(int, input().split()))\r\ncolor=[]\r\nfor i in range(n):\r\n new=input().split()\r\n color=color+new\r\nfor t in range(n-1):\r\n if color[t]==color[t+1]:\r\n print(\"NO\")\r\n break\r\nelse:\r\n for x in color:\r\n if x.count(x[0])<m:\r\n print(\"NO\")\r\n break\r\n else:\r\n print(\"YES\")", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\ns = [list(input().rstrip()) for _ in range(n)]\r\nans = \"YES\"\r\nfor i in range(n):\r\n si = s[i]\r\n for j in range(m - 1):\r\n if not si[j] == si[j + 1]:\r\n ans = \"NO\"\r\nfor j in range(m):\r\n for i in range(n - 1):\r\n if s[i][j] == s[i + 1][j]:\r\n ans = \"NO\"\r\nprint(ans)", "n,m=map(int,input().split())\r\nflag=0\r\nb=[]\r\nfor i in range(n):\r\n a=list(input())\r\n if len(list(set(a)))==1:\r\n b.append(a[0])\r\n else:\r\n flag=1\r\nif flag==1:\r\n print(\"NO\")\r\nelse:\r\n for i in range(1,n):\r\n if b[i-1]==b[i]:\r\n print(\"NO\")\r\n break\r\n else:\r\n print(\"YES\")\r\n", "h, w = map(int, input().split())\n\n\ndef solution():\n verdict = \"YES\"\n last_row = \"\"\n last_col = \"\"\n\n for _ in range(h):\n l = input()\n if not last_row:\n last_row = l[0]\n else:\n if last_row == l[0]:\n return \"NO\"\n else:\n last_row = l[0]\n for j in l:\n if not last_col:\n last_col = j\n else:\n if last_col != j:\n return \"NO\"\n last_col = \"\"\n return verdict\n\n\nprint(solution())\n", "from collections import defaultdict\r\nfrom typing import List\r\nimport math\r\n\r\ndef pug_func(s: List[str]) -> str:\r\n\r\n prev_row = \"\"\r\n\r\n for line in s:\r\n if line[0] == prev_row:\r\n return \"NO\"\r\n \r\n curr_row_first = line[0]\r\n\r\n for element in line:\r\n if element != curr_row_first:\r\n return \"NO\"\r\n\r\n prev_row = line[0]\r\n\r\n return \"YES\"\r\n\r\nn, m = map(int, input().split(\" \"))\r\nlista_big = []\r\nfor _ in range(n):\r\n lista_big.append(input())\r\n\r\nx = pug_func(lista_big)\r\nprint(x)\r\n\r\n\r\n\r\n# t = int(input())\r\n# lista_ans = []\r\n\r\n# for _ in range(t):\r\n# n = input()\r\n# line = input()\r\n# lista_ans.append(line)\r\n\r\n# for ans in lista_ans:\r\n# x = pug_func(ans)\r\n# print(x)\r\n", "def solve(n, m, x):\r\n for i in range(n):\r\n if x[i].count(x[i][0]) < m or i and x[i][0] == x[i - 1][0]:\r\n print('NO')\r\n return\r\n print('YES')\r\nn, m = map(int, input().split())\r\nx = []\r\nfor _ in range(n): x += [list(input())]\r\nsolve(n, m, x)", "\r\n\r\ndef checkList(lst): \r\n \r\n ele = lst[0] \r\n chk = True\r\n \r\n for item in lst: \r\n if ele != item: \r\n chk = False\r\n break; \r\n \r\n if (chk == True):return True \r\n else: return False\r\n\r\n\r\n\r\nr,c=map(int,input().split(' '))\r\nlst=[]\r\nans=[]\r\nfor i in range(r):\r\n temp=list(map(str,input()))\r\n lst.append(temp)\r\nfor i in lst:\r\n ans.append(checkList(i))\r\nif(False not in ans):\r\n for i in range(len(lst)-1):\r\n if(lst[i]==lst[i+1]):\r\n ans.append(False)\r\nif(False not in ans):\r\n print('YES')\r\nelse:\r\n print('NO')", "# cook your dish here\r\nn, m = list(map(int, input().split()))\r\n\r\nflag = ['']\r\nerror = 0\r\nfor _ in range(n):\r\n row = input()\r\n if all(row[0] == el for el in row) and row != flag[-1]:\r\n flag.append(row)\r\n else:\r\n error = 1\r\n break\r\n \r\n\r\nprint('YES' if error == 0 else 'NO')", "n,m=map(int,input().split())\r\nt=10\r\nf=True\r\nfor i in range(n):\r\n x=input()\r\n if x[0]==t:\r\n f=False\r\n t=x[0]\r\n if any(b!=t for b in x):\r\n f=False\r\nif f:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "z = []\r\nz[0:] = map(int,input().split())\r\nq = []\r\nw = []\r\nfor i in range(z[0]):\r\n w[0:] = map(int,input())\r\n q.append(w[:])\r\nchecker = 0\r\n#print(q)\r\nfor i in range(z[0] - 1):\r\n if q[i][0] == q[i+1][0]:\r\n checker = 1\r\n break\r\n if checker == 1:\r\n break\r\nif checker == 0:\r\n for i in range(z[0]):\r\n if min(q[i]) != max(q[i]):\r\n checker = 1\r\n break\r\nif checker == 1:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "n, m = map(int, input().split())\r\nlast = '-'\r\nfor i in range(n):\r\n s = input()\r\n c = s[0]\r\n s = s.replace(c, '')\r\n if len(s) > 0 or c == last:\r\n print('NO')\r\n break\r\n last = c\r\nelse:\r\n print('YES')", "\r\n'''\r\nAuthor : Shubhanshu Jain;\r\n'''\r\n\r\nimport math\r\nimport random;\r\nfrom collections import * \r\nmod =1000000007\r\nr1 = lambda : int(input());\r\nrm = lambda : map(int,input().split());\r\nrms = lambda : map(str,input().split());\r\nrls = lambda : list(rm())\r\n\r\n\r\ndef def_value(): \r\n\treturn \"nan\"\r\n\t\r\n\r\n \r\ndef solve():\r\n r,c = rm();\r\n s = [];\r\n for i in range(r):\r\n s.append(input());\r\n flag = 1;\r\n if(s[0].count(s[0][0])!=c):\r\n flag = 0;\r\n \r\n for i in range(1,r):\r\n if(flag == 0):\r\n break;\r\n if(s[i].count(s[i][0])!=c or s[i][0]==s[i-1][0]):\r\n flag = 0;\r\n if(flag):\r\n print(\"YES\");\r\n else:\r\n print(\"NO\")\r\n\t\r\nsolve();\r\n\r\n", "def row_check(rs):\n for i in range(1, len(rs)):\n if rs[i] != rs[i-1]:\n return False\n return True\n\n\nn, m = list(map(int, input().split()))\nfor i in range(n):\n if i:\n old_row = row\n row = input()\n if i and old_row[0] == row[0]:\n print(\"NO\")\n b = False\n break\n b = row_check(row)\n if not b:\n print(\"NO\")\n break\nif b:\n print(\"YES\")\n\n\n\n", "n,m=[int(n) for n in input().split()]\r\nlis=[]\r\nfor i in range(n):\r\n x=input()\r\n lis.append(x)\r\nx=0\r\nif n==1:\r\n if m==1:\r\n print(\"yes\")\r\n else:\r\n\r\n\r\n for j in range(1,m):\r\n if lis[0][0]!=lis[0][j]:\r\n print(\"no\")\r\n x=x+1\r\n break\r\n if(x==0 and j==m-1):\r\n print(\"yes\")\r\n\r\n\r\n\r\nelse:\r\n if m==1:\r\n for i in range(n):\r\n if (i >= 1 and i < n - 1):\r\n if lis[i] == lis[i - 1] and lis[i] == lis[i + 1]:\r\n print(\"no\")\r\n break\r\n elif (i == 0):\r\n if lis[0] == lis[1]:\r\n print(\"no\")\r\n break\r\n elif (i == n - 1):\r\n if lis[n - 1] == lis[n - 2]:\r\n print(\"no\")\r\n break\r\n\r\n if x != 0:\r\n print(\"no\")\r\n break\r\n if (i == n - 1 and x == 0):\r\n print(\"yes\")\r\n else:\r\n for i in range(0, n):\r\n for j in range(0, m):\r\n if lis[i][0] != lis[i][j]:\r\n x = x + 1\r\n\r\n break\r\n if (i >= 1 and i < n - 1):\r\n if lis[i] == lis[i - 1] and lis[i] == lis[i + 1]:\r\n print(\"no\")\r\n break\r\n elif (i == 0):\r\n if lis[0] == lis[1]:\r\n print(\"no\")\r\n break\r\n elif (i == n - 1):\r\n if lis[n - 1] == lis[n - 2]:\r\n print(\"no\")\r\n break\r\n\r\n if x != 0:\r\n print(\"no\")\r\n break\r\n if (i == n - 1 and x == 0):\r\n print(\"yes\")\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 = list(map(int, input().split()))\r\nb = \"\"\r\nfor i in range(n):\r\n flag = \"YES\"\r\n a = input()\r\n a = set(a)\r\n if len(a) != 1 or b == a:\r\n flag = \"NO\"\r\n break\r\n b = a\r\nprint(flag)\r\n", "n,m=map(int,input().split())\r\na,b=0,0\r\nl=[]\r\nfor i in range(n):\r\n ll=list(set([j for j in input()]))\r\n if len(ll)!=1:\r\n a=1\r\n break\r\n else:\r\n l=l+ll\r\nfor i in range(len(l)-1):\r\n if l[i]==l[i+1]:\r\n b=1\r\n break\r\nif a==1 or b==1:\r\n print('NO')\r\nelse:\r\n print('YES')\r\n ", "n, m = map(int, input().split())\r\nl = []\r\nfor k in range(n):\r\n l.append(list(input()))\r\n\r\ny = 0\r\nfor i in range(n):\r\n for j in range(m):\r\n if l[i][0] != l[i][j]:\r\n y = 1\r\n break\r\n\r\nfor g in range(n-1):\r\n if l[g][0] == l[g+1][0]:\r\n y = 1\r\n break\r\n\r\nif y == 1:\r\n print('NO')\r\nelse:\r\n print('YES')", "# -*- coding: utf-8 -*-\r\nn,m = map(int,input().split())\r\na = list(input() for i in range(n))\r\n\r\ndef Flag(n,a):\r\n if a[0].count(a[0][0]) != len(a[0]): return 'NO'\r\n for i in range(1,n): \r\n if a[i].count(a[i][0]) != len(a[i]): return 'NO'\r\n if a[i][0] == a[i-1][0]: return 'NO'\r\n return 'YES'\r\n\r\nprint(Flag(n,a))\r\n\r\n", "ch= input()\r\nn=int(ch[0:ch.find(\" \")])\r\nm=int(ch[ch.find(\" \")+1:len(ch)])\r\nmat =[]\r\nfor i in range(n):\r\n ch=input()\r\n mat.append(list(ch))\r\nok =\"Yes\"\r\nfor i in range(n-1):\r\n for j in range(m-1):\r\n if (mat[i][j] != mat[i][j+1]) or (mat[i][j] == mat[i+1][j ]) :\r\n ok = \"NO\"\r\n break\r\n\r\n\r\nfor j in range(m - 1):\r\n if (mat[len(mat)-1][j] != mat[len(mat)-1][j + 1]):\r\n ok = \"NO\"\r\n break\r\nprint(ok)\r\n\r\n\r\n", "n,m=list(map(int,input().split()))\r\nans=\"YES\"\r\nfor i in range(n):\r\n str=input()\r\n for j in range(1,len(str)):\r\n if str[0]!=str[j]:\r\n ans=\"NO\"\r\n if i>0 and pre==str:\r\n ans=\"NO\"\r\n pre=str\r\nprint(ans)", "def reversed_list(l, start, end):\r\n if start >= end:\r\n return l\r\n l[start], l[end] = l[end], l[start]\r\n return reversed_list(l, start + 1, end - 1)\r\n\r\n\r\n\r\ndef main_function():\r\n n, m = [int(i) for i in input().split(\" \")]\r\n flag = []\r\n for i in range(n):\r\n flag.append(input())\r\n for i in flag:\r\n current_colour = i[0]\r\n for j in i:\r\n if not j == current_colour:\r\n return \"NO\"\r\n inv_var = flag[0]\r\n for i in range(1, len(flag)):\r\n if flag[i] == inv_var:\r\n return \"NO\"\r\n inv_var = flag[i]\r\n return \"YES\"\r\n\r\n\r\n\r\nprint(main_function())", "n,m=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n m=input()\r\n t=[]\r\n for j in m:\r\n t.append(int(j))\r\n l.append(t)\r\nprev=-1\r\ns=0\r\nfor i in l:\r\n if(len(set(i))==1):\r\n if(prev==-1):\r\n prev=i[0]\r\n else:\r\n if(i[0]!=prev):\r\n prev=i[0]\r\n else:\r\n s=1\r\n break\r\n else:\r\n s=1\r\n break\r\nif(s==1):\r\n print('No')\r\nelse:\r\n print('Yes')\r\n \r\n", "def hfunction (matrix,r,c):\r\n for row in range (r):\r\n char=matrix[row][0]\r\n fifa=True\r\n for col in range (c):\r\n if matrix[row][col] !=char:\r\n fifa=False\r\n if fifa==False:\r\n return (False)\r\n return (True)\r\ndef adjacent(matrix,r,c):\r\n prev=\"\"\r\n for a in range (r):\r\n fifa=True\r\n for b in range (c):\r\n if matrix[a][b]==prev:\r\n fifa=False\r\n prev=matrix[a][0]\r\n if fifa==False:\r\n return (False)\r\n return (True)\r\nr,c=input().split()\r\nr=int(r)\r\nc=int(c)\r\nmatrix=[0]*r\r\nfor i in range (r):\r\n matrix[i]=[0]*c\r\nfor a in range (r):\r\n matrix[a]=list(input())\r\n for b in range (c):\r\n matrix[a][b]=str(matrix[a][b])\r\nif hfunction(matrix,r,c)==True and adjacent(matrix,r,c)==True:\r\n print (\"YES\")\r\nelse:\r\n print (\"NO\")", "lst = input().split()\nn = int(lst[0])\nm = int(lst[1])\n\n# matrix = [[0 for _ in range(m)] for _ in range(n)]\n\nprev_row = None\nfor i in range(n):\n s = input()\n prev_elem = None\n for j, c in enumerate(s):\n if j == 0 and (prev_row is not None and c == prev_row):\n print('NO')\n exit()\n if prev_elem is not None and c != prev_elem:\n print('NO')\n exit()\n # matrix[i][j] = c\n prev_elem = c\n prev_row = prev_elem\nprint('YES')\n", "n , m = list(map(int,input().split()))\r\nx=list()\r\nyes=0\r\nno=0\r\nk=0\r\nfor i in range(n):\r\n y=input()\r\n r = [int(a) for a in str(y)]\r\n if len(r)==m :\r\n for i in range(len(r)):\r\n if r[0]!=r[i]:\r\n no=1 \r\n break\r\n if len(x)==0: \r\n x.append(r)\r\n k=r[0]\r\n yes=1\r\n else:\r\n \r\n if r[0]==k:\r\n no=1\r\n else :\r\n x.append(r)\r\n yes=1\r\n k=r[0] \r\n else:\r\n no=1 \r\nif no==1:\r\n print(\"NO\")\r\nelif yes==1:\r\n print(\"YES\")", "n,m=map(int,input().split())\r\nflag=0\r\ns=input()\r\nif len(list(set(list(s))))!=1:\r\n print('NO')\r\nelse:\r\n for _ in range(n-1):\r\n t=input()\r\n if s==t:\r\n flag=1\r\n break\r\n elif len(list(set(list(t))))!=1:\r\n flag=1\r\n break\r\n \r\n s=t\r\n if flag==1:\r\n print('NO')\r\n else:\r\n print('YES')\r\n \r\n ", "\nn, m = map(int,input().split())\n\nres = \"YES\"\n\nfor i in range(n):\n\n s = input()\n\n for j in range(1 , len(s)):\n\n if s[0] != s[j]:\n res = \"NO\"\n\n if i > 0 and old == s:\n\n res = \"NO\"\n\n old = s\n\nprint(res)\n\n\t \t \t \t \t\t\t \t \t \t \t", "n,m = map(int,input().split())\nans ='YES'\nprev_color = None\nfor i in range(n):\n line = input()\n this_color = line[0]\n if this_color == prev_color:\n ans = 'NO'\n for c in line :\n if c!=this_color :\n ans= 'NO'\n break\n prev_color = this_color\nprint(ans)\n\n", "n,m = [int(x) for x in input().split()]\r\nL = []\r\nc1 = True\r\nc2 = True\r\nfor i in range(0,n):\r\n L.append(input())\r\n\r\n\r\nfor i in L:\r\n if i != i[0]*m:\r\n c1 = False\r\n break\r\n\r\nif c1 == True:\r\n for i in range(0,n-1):\r\n if L[i][0] == L[i+1][0]:\r\n c2 = False\r\n break\r\n\r\nif (c1 == True) and (c2 == True):\r\n print('YES')\r\nelse:\r\n print('NO')", "# 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\nimport datetime\r\n# import webbrowser\r\n\r\n\r\nn, m = map(int, input().split())\r\nflag = []\r\ndiff = 0\r\nwrong = False\r\nfor i in range(n):\r\n arr = list(input())\r\n if len(list(dict.fromkeys(arr))) != 1:\r\n wrong = True\r\n else:\r\n if diff == 0:\r\n diff = arr[0]\r\n else:\r\n if diff == arr[0]:\r\n wrong = True\r\n else:\r\n diff = arr[0]\r\nif wrong:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n", "s1 = -1\r\n\r\ndef check (s,m):\r\n global s1\r\n if len(s) != m:\r\n return False\r\n else:\r\n s2 = s[0]\r\n for i in s:\r\n if i != s2: return False\r\n if s2 == s1: return False\r\n s1 = s2\r\n return True\r\n\r\ndef solve (m):\r\n global s1\r\n for i in range(n):\r\n s = str(input())\r\n if check(s,m) == False:\r\n return \"NO\"\r\n return \"YES\"\r\n\r\nif __name__ == '__main__':\r\n n,m = map(int,input().split())\r\n print(solve(m))\r\n\r\n\r\n\r\n", "N, M = map(int, input().split())\r\nflag = []\r\nfor _ in range(N):\r\n flag.append(set(input()))\r\n\r\nprev = \"a\"\r\nfor row in flag:\r\n if len(row) > 1 or next(iter(row)) == prev:\r\n print(\"NO\")\r\n exit()\r\n else:\r\n prev = next(iter(row))\r\nprint(\"YES\")", "################################################################\r\n# - Programming Credits - atifcppprrgrammer - 27th May 2019\r\n################################################################\r\n# Getting Problem-Data from Codeforces.\r\nrows,columns = tuple(map(int,input().split(' ')))\r\nflag = []\r\nfor i in range(rows):\r\n flag.append(input())\r\n# Administering Uniformity and Inclusivity Test.\r\npassed_one,index,digits = True,0,\"0123456789\"\r\nwhile passed_one and index<rows:\r\n flag_row = flag[index]\r\n first_char = flag_row[0]\r\n # Checking if all Characters are the Same.\r\n test_a = flag_row.count(first_char) == columns\r\n # Checking if all Characaters are in digits.\r\n test_b = first_char in digits\r\n # Verdict.\r\n passed_one = test_a and test_b\r\n index = index +1\r\n# Adding Extraneous row.\r\nflag.insert(0,\"X\"*columns)\r\n# Administering Adjacency Test.\r\npassed_two,index = True,1\r\nwhile passed_two and index<rows:\r\n test_set = set(flag[index-1:index+1])\r\n # Verdict.\r\n passed_two = len(test_set) == 2\r\n index = index+1\r\n# Final Verdict.\r\nif passed_one and passed_two:\r\n print(\"YES\")\r\nelse: print(\"NO\")\r\n###################################################################\r\n\r\n\r\n", "n = input().split()\r\nn = int(n[0])\r\nt = '9999'\r\nresult = 'YES'\r\nfor i in range(n):\r\n m = input()\r\n for j in m:\r\n if not j== m[0]:\r\n result = 'NO'\r\n if int(t) == int(m[0]):\r\n result = 'NO' \r\n t = m[0]\r\nprint(result)", "a,b=map(int,input().split());c=\"a\"\r\nfor i in range(a):\r\n z=set(input())\r\n if len(z)>1 or c==z:\r\n print(\"NO\")\r\n exit()\r\n c=z\r\nprint(\"YES\")\r\n", "a,b = map(int, input().split())\r\nans = False\r\nx = -1\r\nfor i in range(a):\r\n t = input()\r\n if int(t[0]) == x:\r\n ans = True\r\n break\r\n for i in range(b-1):\r\n if t[i] != t[i+1]:\r\n ans = True\r\n break\r\n if ans:\r\n break\r\n x = int(t[0])\r\nprint('YNEOS'[ans::2])\r\n ", "n,m = map(int, input().split())\r\na=[]\r\nt=True\r\nfor i in range(n):\r\n l=input()\r\n f=l[0]\r\n for j in l:\r\n if j!=f:\r\n t=False\r\n break\r\n if not t:\r\n break\r\n a.append(l)\r\nfor k in range(0,len(a)-1):\r\n if a[k]==a[k+1]:\r\n t=False\r\nif t:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n, m = map(int, input().split())\r\nflag = True\r\nc = ''\r\nfor nn in range(n):\r\n\ts = [i for i in input()]\r\n\tif nn != 0:\r\n\t\tif s[0] == c:\r\n\t\t\tflag = False\r\n\t\t\tbreak\r\n\tc = s[0]\r\n\tfor i in range(len(s) - 1):\r\n\t\tif s[i] != s[i + 1]:\r\n\t\t\tflag = False\r\n\t\t\tbreak\r\nprint(\"YES\") if flag else print(\"NO\")", "n, m = map(int, input().split())\r\ns = [input() for _ in range(n)]\r\n\r\nres = all([len(set(s[i])) == 1 for i in range(n)])\r\nres = res and all([s[i] != s[i - 1] for i in range(1, n)])\r\nprint((\"NO\", \"YES\")[res])\r\n", "#!/usr/bin/env/python\r\n# -*- coding: utf-8 -*-\r\nn, m = list(map(int, input().split()))\r\nres = True\r\npre = 100\r\nfor _ in range(n):\r\n s = input()\r\n if len(s) != m or len(set(list(s))) != 1:\r\n res = False\r\n if pre == int(s[0]):\r\n res = False\r\n pre = int(s[0])\r\nprint(['NO', 'YES'][res])", "a,b = map(int,input().split());c=\"a\"\r\nfor i in range(a):\r\n z = set(input())\r\n if len(z)>1 or c==z :print(\"NO\") ;exit()\r\n c=z\r\nprint(\"YES\") \r\n", "n,m=map(int,input().split())\r\ns=''\r\nfor i in range(n):\r\n a=input()\r\n k=set(a)\r\n if(len(k)>1):\r\n print(\"NO\")\r\n quit()\r\n for i in k:\r\n s+=i\r\ncount=0\r\nfor i in range(len(s)-1):\r\n if(s[i]!=s[i+1]):\r\n count+=1\r\nif(count==n-1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n, m = [int(x) for x in input().split()]\r\np = '-1'\r\nfor i in range(n):\r\n h = list(input())\r\n if h.count(h[0]) != m or h[0] == p:\r\n print(\"NO\")\r\n exit(0)\r\n p = h[0]\r\nprint(\"YES\")", "n,m = map(int,input().split())\r\n\r\nlast = '-1'\r\nflag = 0\r\n\r\nfor i in range(n):\r\n s = input()\r\n if s[0]==last:\r\n flag = 1\r\n break\r\n sc = s.count(s[0])\r\n if sc!=m:\r\n flag = 1\r\n break\r\n last = s[0]\r\nif flag==1:\r\n print('NO')\r\nelse:\r\n print(\"YES\")", "n, m = map(int, input().split())\na = []\nfor _ in range(n):\n a.append(input())\n\nflag = 'YES'\nfor i in range(n):\n if len(set(a[i])) > 1:\n flag = 'NO'\n break\n elif i > 0:\n if a[i] == a[i - 1]:\n flag = 'NO'\n break\n\nprint(flag)\n", "rows, columns = map(int, input().split())\r\nflag = []\r\n# get flag colors\r\nfor _ in range(rows):\r\n flag.append(list([char for char in input()]))\r\nfor rowIndex in range(len(flag) - 1):\r\n# if a row does't not contain one color or there are 2 adiacent rows with the same color\r\n if len(set(flag[rowIndex])) > 1 or flag[rowIndex][0] == flag[rowIndex + 1][0]:\r\n # print No\r\n print('NO')\r\n quit()\r\n # The last row remained unchecked if it has only one color, so we have to check that too\r\nif len(set(flag[len(flag) - 1])) > 1:\r\n print('NO')\r\n quit()\r\nprint('YES')", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sun Sep 26 20:55:06 2021\r\n\r\n@author: cheehong\r\n\"\"\"\r\n\r\nl=list(map(int, input().split()))\r\nn=int(l[0])\r\nm=int(l[1])\r\nk=0\r\ns=[]\r\nwhile k<n:\r\n s.append(list(input()))\r\n k+=1\r\nk=0\r\nt=0\r\nwhile k<n:\r\n if len(set(s[k]))!=1:\r\n print('NO')\r\n t=1\r\n break\r\n k+=1\r\nif t==0:\r\n p=1\r\n while p< n-1:\r\n if s[p]==s[p-1] or s[p]==s[p+1]:\r\n print('NO')\r\n t+=1\r\n break\r\n p+=1\r\nif t==0:\r\n print('YES')", "x=r='YES'\r\nfor i in [*open(0)][1:]:\r\n s={*i}\r\n if len(s)>2 or x==s:\r\n r='NO'\r\n x=s\r\nprint(r)", "import sys\r\n\r\ndef solve(firstLine, inputLines):\r\n n, m = firstLine[0], firstLine[1]\r\n \r\n for index, line in enumerate(inputLines):\r\n if index > 0 and inputLines[index][0] == inputLines[index-1][0] :\r\n print(\"NO\")\r\n return\r\n for ch in line[0]:\r\n if ch != line[0][0] :\r\n print(\"NO\")\r\n return\r\n \r\n print(\"YES\")\r\n return\r\n\r\ndef main():\r\n firstLine = sys.stdin.readline().split()\r\n firstLine = list(map(int, firstLine))\r\n inputLines = []\r\n for i in range(firstLine[0]):\r\n line = sys.stdin.readline().split()\r\n #line = list(map(int, line))\r\n inputLines.append(line)\r\n\r\n solve(firstLine, inputLines)\r\n \r\nif __name__ == \"__main__\":\r\n main()\r\n", "n, m = map(int, input().split())\r\n\r\nflag = [input() for _ in range(n)]\r\n\r\nfor i in range(n):\r\n if i > 0 and flag[i] == flag[i-1]:\r\n print(\"NO\")\r\n break\r\n for j in range(m-1):\r\n if flag[i][j] != flag[i][j+1]:\r\n print(\"NO\")\r\n break\r\n else:\r\n continue\r\n break\r\nelse:\r\n print(\"YES\")\r\n", "def allsame(arr):\r\n k = arr[0]\r\n\r\n for i in arr:\r\n if i != k:\r\n return False\r\n return True\r\n\r\n\r\ndef notsame(arr):\r\n for i in range(1, len(arr)):\r\n if (arr[i] == (arr[i - 1] or arr[i + 1])):\r\n return False\r\n return True\r\n\r\n\r\ndef a_no():\r\n print(\"NO\")\r\n raise SystemExit\r\n\r\n\r\nsize = list(map(int, input().split(\" \")))\r\nn = size[0]\r\n\r\narr = []\r\n\r\nfor i in range(n):\r\n png = str(input())\r\n arr.append(png)\r\n\r\nfor i in range(n):\r\n if not allsame(arr[i]):\r\n a_no()\r\n\r\ncheck = []\r\n\r\nfor j in range(1):\r\n for i in range(n):\r\n check.append(arr[i][j])\r\n\r\nif not notsame(check):\r\n a_no()\r\n\r\nprint(\"YES\")\r\n", "b=''\nfor i in range(int(input().split()[0])):\n a=input()\n if a.strip(a[0])or a[0]==b:\n print('NO');exit()\n b=a[0]\nprint('YES')", "n,m=list(map(int, input().split()))\r\ndef f(s):\r\n for i in s:\r\n if i!=s[0]:\r\n return 0\r\n return 1\r\n \r\ny=\"-1\"\r\nfor j in range(n):\r\n p=input()\r\n if f(p):\r\n if p==y:\r\n print(\"NO\")\r\n break\r\n y=p\r\n else:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")\r\n", "n, m = list(map(int, input().split()))\r\nver = 1\r\nant = '-1'\r\nfor i in range(n):\r\n s = input()\r\n aux = s[0]\r\n if any(x != aux for x in s) or s == ant:\r\n ver = 0\r\n ant = s\r\nif ver == 0:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "n,m=input().split()\nx='a'\nn=int(n)\nm=int(m)\nk=True\nfor i in range(n):\n s=input()\n if(s.count(s[0])==m and s[0]!=x and k):\n x=s[0]\n continue\n k=False\nif(k):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "n, m = [int(x) for x in input().split()]\r\n\r\nprev = None\r\nfor i in range(n):\r\n s = list(set(input()))\r\n if len(s) > 1:\r\n print('NO')\r\n exit(0)\r\n if s[0] == prev:\r\n print('NO')\r\n exit(0)\r\n prev = s[0]\r\n \r\nprint('YES')", "a,b = map(int,input().split(' '))\nz = False\ny = []\nfor i in range(a):\n\tx = set(input())\n\tif(z == True):\n\t\tcontinue\n\tif(len(x) != 1):\n\t\tz = True\t\n\telse:\n\t\tz = False\n\t\tfor k in x:\n\t\t\tbreak\n\t\ty.append(k)\nif(z == True):\n\tprint('NO')\nelse:\n\tfor i in range(len(y)-1):\n\t\tif(y[i] == y[i+1]):\n\t\t\tprint('NO')\n\t\t\tbreak\n\telse:\n\t\tprint('YES')", "n, m = map(int, input().split())\r\n\r\ncurrent_color = -1\r\noutput = True\r\n\r\nfor _ in range(n):\r\n current_line = input()\r\n if current_line[0] == current_color or not output:\r\n output = False\r\n break\r\n else:\r\n current_color = current_line[0]\r\n for col in range(1, m):\r\n if current_line[col] != current_color:\r\n output = False\r\n break\r\n\r\nif output:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "ip = list(map(int, input().split(\" \")))\r\nn = ip[0]\r\nm = ip[1]\r\nf = list()\r\ndk1 = 0\r\ndk2 = 0\r\nfor i in range(0, n):\r\n h = input()\r\n a = set()\r\n for i in h:\r\n a.add(i)\r\n if(len(a) != 1):\r\n dk1 +=1\r\n f.append(h)\r\nif(dk1 != 0):\r\n print(\"NO\")\r\nelse:\r\n if(dk1 == 0):\r\n for k in range(0, n):\r\n if(k == n -1):\r\n continue\r\n else:\r\n if( f[k][0] == f[k+1][0]):\r\n dk2 += 1\r\n if(dk2 == 0):\r\n print(\"YES\")\r\n else: print(\"NO\")", "n,m=map(int,input().split())\r\ns=[]\r\nfor i in range(n):\r\n z=[]\r\n x=input()\r\n z.extend(x)\r\n s.append(z)\r\nflag=True\r\nfor i in range(n):\r\n for j in range(m-1):\r\n if s[i][j]!=s[i][j+1]:\r\n flag=False\r\nif flag:\r\n for i in range(n-1):\r\n if s[i][0]==s[i+1][0]:\r\n flag=False\r\nif flag:\r\n print('YES')\r\nelse :\r\n print('NO')\r\n", "a=int(input().split()[0]);b=[input()for i in range(a)];print(['YES','NO'][bool(sum(b[i][0]==b[i+1][0]for i in range(a-1))or sum(sum(b[i][0]!=b[i][j] for i in range(a)) for j in range(len(b[0]))))])\r\n", "n,m = map(int,input().split())\r\narray = []\r\nflag = True\r\nfor _ in range(n):\r\n a = input()\r\n a = list(a)\r\n a = set(a)\r\n if len(a) != 1:\r\n print('NO')\r\n exit()\r\n else:\r\n array.extend(a)\r\nif n == 1:\r\n print('YES')\r\nelse:\r\n for i in range(n - 1):\r\n if array[i] == array[i+1]:\r\n flag = False\r\n break\r\n if flag:\r\n print('YES')\r\n else:\r\n print('NO')", "#!/usr/bin/env python\n\ndef main( ):\n n, m = map( int, input( ).split( ) )\n\n prevRow = None\n\n for i in range( n ):\n row = input( )\n if len( set( row ) ) == 1:\n if prevRow == row[ 0 ]:\n print( \"NO\" )\n return\n else:\n prevRow = row[ 0 ]\n else:\n print( \"NO\" )\n return\n print( \"YES\" )\n\nif __name__ == '__main__':\n main( )\n\n", "b, c = map(int, input().split())\r\nf = [input() for _ in range(b)]\r\nfor i in range(b):\r\n if len(set(f[i])) != 1:\r\n print(\"NO\")\r\n exit()\r\nfor i in range(1, b):\r\n if f[i] == f[i-1]:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")", "n,m=map(int,input().split())\r\na=[]\r\nfor i in range(n) :\r\n a.append(list(input()))\r\nif a[0][0]*len(a[0])!=''.join(a[0]) : print('NO'); exit()\r\nfor i in range(1,len(a)) :\r\n j=i-1\r\n if a[i]!=a[j] :\r\n if a[i][0]*len(a[i])==''.join(a[i]) :\r\n o=0\r\n else : print('NO');exit()\r\n else : print('NO');exit()\r\nprint('YES')", "def main():\r\n n, m = map(int, input().split())\r\n flag = [list(input()) for i in range(n)]\r\n for x in flag:\r\n if len(set(x)) != 1:\r\n return 'NO'\r\n for i in range(n-1):\r\n if flag[i] == flag[i+1]:\r\n return 'NO'\r\n return 'YES'\r\nprint(main())", "n,m=input().split(' ')\r\nn=int(n)\r\nm=int(m)\r\na='YES'\r\nL1=[]\r\nfor j in range(n) :\r\n k=input()\r\n if (k!=k[0]*m) or (j>0 and k[0]==L1[j-1][0]):\r\n a='NO'\r\n L1.append(k)\r\nprint(a)\r\n ", "cases, b = map(int, input().split())\r\nfnl = \"\"\r\nprinted = False\r\nwhile cases:\r\n cases -= 1\r\n s = list(set(input()))\r\n if len(s) != 1:\r\n print(\"NO\")\r\n printed = True\r\n break\r\n\r\n if s[0] == fnl:\r\n print(\"NO\")\r\n printed = True\r\n break\r\n fnl = s[0]\r\n\r\nif not printed:\r\n print(\"YES\")\r\n\r\n", "n, m = list(map(int, input().split()))\r\nf, x = False, []\r\nfor i in range(n):\r\n a = input()\r\n b = set(a)\r\n x.append(int(a))\r\n if len(b) != 1:\r\n f = True\r\n if i > 0 and x[i] == x[i-1]:\r\n f = True\r\nif f:\r\n print('NO')\r\nelse:\r\n print('YES')", "n, m = [int(s) for s in input().split(' ')]\r\nprior = set()\r\nanswer = 'YES'\r\nfor i in range(n):\r\n row = set(x for x in input())\r\n if len(row) > 1 or row == prior:\r\n answer = 'NO'\r\n break\r\n else:\r\n prior = row\r\nprint(answer)", "n,m=map(int,input().split())\r\nc=\"abc\"\r\nz=set()\r\nfor i in range(n):\r\n z=set(input())\r\n if len(z)>1 or c==z:\r\n print(\"NO\")\r\n exit(0)\r\n c=z\r\nprint(\"YES\")", "y,x = map(int, input().split())\r\narr = []\r\n\r\nfor i in range(y):\r\n arr.append([ch for ch in input()])\r\n\r\nresult = 1\r\nlast = \"\"\r\nflag = 1\r\nfor i in range(y):\r\n if arr[i][0] != last:\r\n last = arr[i][0]\r\n else:\r\n result = 0\r\n break\r\n flag = max(flag, 0)\r\n for j in range(1, x):\r\n if arr[i][j] != arr[i][j-1]:\r\n flag = 0\r\n else:\r\n last = arr[i][j]\r\n \r\n\r\nif flag and result:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=input().split(' ')\r\nn=int(a[0])\r\nm=int(a[1])\r\narr=[]\r\nb=True\r\nfor i in range(n):\r\n arr+=[input()]\r\nfor i in range(n):\r\n if arr[i]!=arr[i][0]*m:\r\n b=False\r\nfor i in range (n-1):\r\n if arr[i]==arr[i+1]:\r\n b=False\r\nif b==True:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n,m=[int(s) for s in input().split()]\r\ns1=set(input())\r\nif len(s1)!=1:\r\n print('NO')\r\nelse:\r\n if n==1:\r\n print('YES')\r\n else:\r\n f=True\r\n for i in range(n-1):\r\n s2=set(input())\r\n if len(s2)!=1 or len(s1|s2)!=2:\r\n f=False\r\n break\r\n s1=s2\r\n if f:\r\n print('YES')\r\n else:\r\n print('NO')", "n, m = map(int, input().split())\r\nmain = set()\r\nflag = False\r\nprev = set()\r\nfor i in range(n):\r\n a = set(input().strip())\r\n if len(a) > 1 or prev == a:\r\n flag = True \r\n else :\r\n main.update(a)\r\n prev = a \r\n\r\nprint(\"NO\" if flag else \"YES\") \r\n ", "n, m = map(int, input().split())\nprev = None\nstandard = True\nfor _ in range(n):\n colors = input()\n if len(set(colors)) != 1 or colors[0] == prev:\n standard = False\n break\n prev = colors[0]\nif standard:\n print('YES')\nelse:\n print('NO')\n\t \t\t \t \t\t\t\t \t \t\t \t \t\t\t\t", "n, m = [int(item) for item in input().split(' ')]\r\nans, prev = 'YES', ''\r\n\r\nfor i in range(n):\r\n current = input()\r\n if prev == current or len(set(current)) > 1:\r\n ans = 'NO'\r\n break\r\n prev = current\r\nprint(ans)", "\ndef ISO():\n n,m = map(int,input().split())\n inp = []\n while n:\n a = set(input())\n if len(set(a)) != 1:\n print(\"NO\")\n return\n else:\n inp.append(a)\n n -= 1\n \n\n for i,j in zip(inp[0::2], inp[1::2]):\n if(i == j):\n print(\"NO\")\n return\n\n \n print(\"YES\")\n\nISO()\n", "lst = list(map(int, input().split()))\r\nn = lst[0]\r\nm = lst[1]\r\nx = 0\r\nnum = [10 * m]\r\nfor i in range(n):\r\n li = list(map(int, input()))\r\n if sum(li) != m * li[0]:\r\n x = 1\r\n break\r\n s = sum(li)\r\n if s == num[-1]:\r\n x = 1\r\n break\r\n else:\r\n num.append(s)\r\nif x == 1:\r\n print('NO')\r\nelse:\r\n print('YES')\r\n", "k = input().split()\r\n#print(k)\r\nrow = int(k[0])\r\nflag = []\r\nfor l in range(row):\r\n rows = list(input())\r\n flag.append(rows)\r\nind = 0\r\nis_flag = True\r\nwhile ind <= len(flag) - 2:\r\n row_c = set(flag[ind])\r\n if len(row_c) != 1:\r\n is_flag = False\r\n if flag[ind][0] == flag[ind + 1][0]:\r\n is_flag = False\r\n ind += 1\r\nrow_c = set(flag[-1])\r\nif len(row_c) != 1:\r\n is_flag = False\r\nif is_flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n,m=map(int,input().split())\r\nsp=input()\r\nl = sp.count(sp[0])\r\nif l ==m:\r\n k=1\r\nelse:\r\n k=0\r\nfor i in range(n-1):\r\n s=input()\r\n if s[0]!=sp[0]and s.count(s[0])==m:\r\n k+=1\r\n sp= s\r\nif k == n: \r\n print(\"yes\")\r\nelse:\r\n print(\"no\")\r\n ", "n , m = map(int , input().split())\n \ndef getAns():\n ans = \"YES\"\n for i in range(n):\n str = input()\n for j in range(1 , len(str)):\n if str[0] != str[j]:\n ans = \"NO\"\n if i > 0 and pre == str:\n ans = \"NO\"\n pre = str\n return ans\n \nprint(getAns())", "n, m = [int(x) for x in input().split()]\n\nflag = []\n\ndef check_row(row, character):\n for k in row:\n if not k == character:\n return False\n return True\n\ndef check_column(flag):\n for k in range(1, len(flag)):\n if flag[k][0] == flag[k - 1][0]:\n return False\n return True\n\n\nfor i in range(n):\n strip, = [str(x) for x in input().split()]\n flag.append(strip)\n\ndef main(flag):\n for row in flag:\n if not check_row(row, row[0]):\n return False\n if not check_column(flag):\n return False\n return True\n\nif main(flag):\n print('YES')\nelse:\n print('NO')\n", "n,m=map(int,input().split())\r\nmatx=[]\r\nok=1\r\nfor i in range(n):\r\n matx.append(input())\r\nmatx.append('#'*m)\r\nfor i in range(n):\r\n if matx[i]==matx[i+1] or matx[i].count(matx[i][0])!=m or matx[i+1].count(matx[i+1][0])!=m:\r\n ok=0;break\r\n\r\nprint('YES' if ok else 'NO')", "def ch1(l,n):\r\n for i in range(n):\r\n if len(set(l[i])) != 1:\r\n return print(\"NO\")\r\n for i in range(n-1):\r\n if l[i][0] == l[i+1][0]:\r\n return print(\"NO\")\r\n return print(\"YES\")\r\nn,m = map(int,input().split())\r\nl = [input() for i in range(n)]\r\nch1(l,n)", "line = input().split(\" \")\r\nr, c = int(line[0]), int(line[1])\r\ndata = []\r\nfor i in range(r):\r\n data.append(input())\r\nfor i in range(1, r):\r\n if data[i][0] == data[i - 1][0]:\r\n print(\"NO\")\r\n quit()\r\nfor i in range(r):\r\n for j in range(1, c):\r\n if data[i][j] != data[i][j - 1]:\r\n print(\"NO\")\r\n quit()\r\nprint(\"YES\")", "a,b=map(int,input().split())\r\nl=[]\r\nflag=0\r\nfor _ in range(a):\r\n l.append(input())\r\nfor i in range(a-1):\r\n if l[i][0]==l[i+1][0]:\r\n flag=1\r\n break\r\nif flag==0:\r\n for i in range(a):\r\n for j in range(b-1):\r\n if l[i][j]!=l[i][j+1]:\r\n flag=1\r\n break\r\nif flag==1:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n ", "def DesigualdadColumna(A):\r\n Aux = 0\r\n for k in range (len(A)-1):\r\n if A[k]==A[k+1] and (k+1<len(A)):\r\n Aux += 1\r\n if Aux ==0:\r\n return True\r\n else:\r\n return False\r\ndef IgualdadFila(L):\r\n Aux = L[0]\r\n c = 0\r\n for k in range (1,len(L)):\r\n if L[k]==Aux:\r\n c+=1\r\n if c==(len(L)-1):\r\n return True\r\n else:\r\n return False \r\nL = input()\r\nL = L.split()\r\nn = int(L[0])\r\nm = int(L[1])\r\nA = []\r\nfor k in range (n):\r\n i = str(input())\r\n A.append(i)\r\nAux = 0\r\nfor k in range (n):\r\n if IgualdadFila(A[k]):\r\n Aux +=1\r\nif Aux ==n:\r\n if DesigualdadColumna(A):\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')", "n, m = map(int, input().split())\r\nfailure = False\r\ncur = -1\r\nfor i in range(0, n):\r\n st = set(input())\r\n for a in st: \r\n if a == cur:\r\n failure = True\r\n else:\r\n cur = a\r\n if len(st) > 1:\r\n failure = True\r\n\r\nprint('YES') if failure == False else print('NO')\r\n", "def main():\r\n #get input\r\n rows,columns = map(int,input().split())\r\n flag = []\r\n #get flag colors\r\n for _ in range(rows):\r\n flag.append(list([char for char in input()]))\r\n for rowIndex in range(len(flag)-1):\r\n #if a row does't not contain one color or there are 2 adiacent rows with the same color\r\n if len(set(flag[rowIndex])) > 1 or flag[rowIndex][0] == flag[rowIndex+1][0]:\r\n #print No\r\n print('NO')\r\n return \r\n #The last row remained unchecked if it has only one color, so we have to check that too\r\n if len(set(flag[len(flag)-1])) > 1:\r\n print('NO')\r\n return\r\n print('YES')\r\n return\r\nmain()", "n,m=list(map(int,input().split()))\r\na1=\"0\"*100\r\nb2=\"1\"*100\r\nc3=\"2\"*100\r\nd4=\"3\"*100\r\ne5=\"4\"*100\r\nf6=\"5\"*100\r\ng7=\"6\"*100\r\nh8=\"7\"*100\r\ni9=\"8\"*100\r\nj10=\"9\"*100\r\nlist1=[]\r\ncount=0\r\nfor x in range(n):\r\n s=input()\r\n list1.append(s)\r\n\r\n\r\nfor x in list1:\r\n if x in a1 or x in b2 or x in c3 or x in d4 or x in e5 or x in f6 or x in g7 or x in h8 or x in i9 or x in j10:\r\n count+=1\r\na=0\r\nfor t in range(len(list1)-1):\r\n if list1[t]==list1[t+1]:\r\n a+=1\r\n\r\n\r\n\r\nif count==n and a==0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n,m=map(int,input().split())\r\npr=\"\"\r\nbo=0\r\nfor i in range(n):\r\n s=input()\r\n if(s!=(s[0]*m)):\r\n bo=1\r\n if(s==pr):\r\n bo=1\r\n pr=s\r\nprint(\"YES\" if not bo else \"NO\")\r\n", "n, m = [int(x) for x in input().split()]\r\n\r\ns = [input() for _ in range(n)]\r\nlast_used = ''\r\n\r\nfor i in range(n):\r\n\tif (len(set(s[i])) != 1 or list(set(s[i]))[0] == last_used): print('NO'); break\r\n\tlast_used = list(set(s[i]))[0]\r\nelse: print('YES')\r\n", "a, b = map(int, input().split())\n\nflag = [input() for i in range(a)]\n\ndef flag_check(flag, length):\n for i in range(length):\n row = flag[i]\n if i > 0 and row == flag[i-1]:\n return 'No'\n\n if len(set(row)) != 1:\n return 'No'\n return 'Yes'\n\nprint(flag_check(flag, a))", "n, m = map(int, input().split())\r\nprev = ''\r\nfor i in range(n):\r\n cur = input()\r\n if cur != cur[0] * m or cur == prev:\r\n print('NO')\r\n exit()\r\n prev = cur\r\nprint('YES')", "n, m = map(int, input().split())\nmas = []\nfor _ in range(n):\n a = input()\n if len(set(a)) == 1:\n mas.append(a)\n else:\n print('NO')\n break\nelse:\n for i in range(1, n):\n if mas[i - 1] == mas[i]:\n print('NO')\n break\n else:\n print('YES')\n", "a,b=map(int,input().split())\r\ne=0\r\n\r\nx=input()\r\ny=set(x)\r\nif(len(y)==1):\r\n e+=1\r\n for i in range(1,a):\r\n c=input()\r\n d=set(c)\r\n if(len(d)==1):\r\n if(y!=d):\r\n y=d\r\n e+=1\r\n pass\r\n\r\n else:\r\n break\r\n\r\nif(e==a):\r\n print('YES')\r\nelse:\r\n print('NO')", "n, m = map(int, input().split())\ncur = float(\"inf\")\nresult = None\nfor i in range(n):\n s = input()\n if s[0] == cur:\n result = \"NO\"\n cur = s[0]\n for j in range(1, m):\n if s[j] != cur:\n result = \"NO\"\nresult = result or \"YES\"\nprint(result)\n", "n, m=map(int, input().split())\r\nd=[[x for x in input()] for i in range(n)]\r\nc=[]\r\nfor i in range(n):\r\n if min(d[i])==max(d[i]) and min(d[i])==d[i][0]:\r\n c+=['YES']\r\n else:\r\n c+=['NO']\r\nif 'NO' in c:\r\n print('NO')\r\nelse:\r\n l=[]\r\n for i in range(n-1):\r\n if d[i][0]==d[i+1][0]:\r\n l+=['NO']\r\n else:\r\n l+=['YES']\r\n if 'NO' in l:\r\n print('NO')\r\n else:\r\n print('YES')", "n, m = list(map(int, input().split()))\r\nprev = ''\r\nans = \"YES\"\r\nfor i in range(n):\r\n current = input()\r\n if current != current[0] * m or current == prev:\r\n ans = \"NO\"\r\n break\r\n prev = current\r\n\r\nprint(ans)\r\n", "n,m=map(int,input().split())\r\nds=[]\r\nk=True\r\nfor i in range(n):\r\n ds.append(input())\r\n if ds[i].count(ds[i][0])<len(ds[i]):\r\n k=False\r\nfor i in range(1,n):\r\n if ds[i][0]==ds[i-1][0]:\r\n k=False\r\nprint(\"YES\" if k else \"NO\")", "for ctr in range(1):\r\n r,c=map(int,input().split())\r\n m=[input().strip() for i in range(r)]\r\n for i in m:\r\n if len(list(set(i)))>1:\r\n print(\"NO\")\r\n break\r\n else:\r\n for i in range(r-1):\r\n if m[i]==m[i+1]:\r\n print(\"NO\")\r\n break\r\n else:\r\n print(\"YES\")\r\n \r\n", "n, m = map(int, input().split())\nS = [str(input()) for _ in range(n)]\nflag = True\nfor i in range(n):\n s = list(S[i])\n if len(set(s)) != 1:\n flag = False\n\nif n == 1:\n if flag:\n print('YES')\n exit()\n else:\n print('NO')\n exit()\n\nfor i in range(n):\n if i == 0:\n if S[0][0] == S[1][0]:\n flag = False\n elif i == n-1:\n if S[n-2][0] == S[n-1][0]:\n flag = False\n else:\n if S[i-1][0] == S[i][0] or S[i][0] == S[i+1][0]:\n flag = False\n\nif flag:\n print('YES')\n exit()\nelse:\n print('NO')\n exit()\n", "# input\nn, m = map(int, input().split())\ndef getAns():\n ans = \"YES\"\n for i in range(n):\n str = input()\n for j in range(1, len(str)):\n if str[0] != str[j]:\n ans = \"NO\"\n if i > 0 and pre == str:\n ans = \"NO\"\n pre = str\n return ans\nprint (getAns())\n\n\t\t\t\t\t\t \t \t \t \t\t\t\t\t", "n,m = map(int, input().split());\r\nsl = [];\r\nans = True;\r\nfor i in range(n):\r\n st = input();\r\n sl+=[st[0]];\r\n if m!=st.count(st[0]):\r\n ans = False;\r\nif ans:\r\n for i in range(1, n-1):\r\n if sl[i]==sl[i-1] or sl[i]==sl[i+1]:\r\n ans = False;\r\n break;\r\nprint(['NO','YES'][ans]);", "n, m = map(int, input().split())\nflag = 1\nl = []\nfor i in range(n):\n l.append(input())\nfor i in range(n):\n x = l[i].count(l[i][0])\n y = len(l[i])\n if x != y:\n flag = 0\n break\nfor i in range(1, n):\n if l[i - 1] == l[i]:\n flag = 0\n break\nif flag == 0:\n print('NO')\nelse:\n print('YES')\n'''\n3 3\n000\n111\n222\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\ndef f(n):\r\n\told=\"\"\r\n\tfor i in range(n):\r\n\t\ts=input()\r\n\t\tif len(list(Counter(s).keys()))!=1:\r\n\t\t\treturn \"NO\"\r\n\t\telse:\r\n\t\t\tif s[0]==old:\r\n\t\t\t\treturn \"NO\"\r\n\t\t\telse:\r\n\t\t\t\told=s[0]\r\n\treturn \"YES\"\r\n\r\nn,m=input().split()\r\nn=int(n)\r\nm=int(m)\r\nprint(f(n))", "# https://codeforces.com/contest/16/problem/A\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, m = multi_integer()\r\nprevious_color = None\r\nans = True\r\nfor i in range(n):\r\n row = string()\r\n if i == 0:\r\n current_color = row[0]\r\n for j in row[1:]:\r\n if j != current_color:\r\n ans = False\r\n break\r\n else:\r\n previous_color = current_color\r\n else:\r\n current_color = row[0]\r\n for j in row[1:]:\r\n if j != current_color or j == previous_color:\r\n ans = False\r\n break\r\n else:\r\n previous_color = current_color\r\n if not ans:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")\r\n", "n,m= map(int, input().split())\r\nc=0\r\nr0=input()\r\ns=set(r0)\r\nif len(s)!=1:\r\n c+=1\r\nfor i in range(n-1):\r\n r=input()\r\n if r0==r:\r\n c+=1\r\n r0=r\r\n s=set(r)\r\n if len(s)!=1:\r\n c+=1\r\nif c:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "n , m = map(int, input().strip().split(' '))\r\nA = []\r\nfor _ in range(n):\r\n A.append( list( input().strip() ) )\r\nfor i in range(1, n):\r\n if A[i][0] == A[i-1][0]:\r\n print('NO')\r\n exit()\r\nfor i in range(n):\r\n for j in range(1, m):\r\n if A[i][j] != A[i][j-1]:\r\n print('NO')\r\n exit()\r\nprint('YES')", "n, m = map(int,input().split())\r\na = []\r\nfor _ in range(n):\r\n item = str(input()[:m])\r\n a.append(item)\r\nc = 0\r\nc2 = 0\r\nk = \"\"\r\n\r\nfor item in range(len(a)):\r\n k = ''.join(a[item])\r\n if len(set(k)) == 1:\r\n c += 1\r\n\r\nfor item in range(len(a)-1):\r\n if a[item] != a[item+1]:\r\n c2 += 1\r\n \r\nif c==len(a) and c2+1==len(a):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n,m=map(int,input().split())\r\nlast=None\r\nfor i in range(n):\r\n a=[h for h in input()]\r\n r=set(a)\r\n if len(r)!=1:\r\n print('NO')\r\n exit()\r\n if r==last:\r\n print('NO')\r\n exit()\r\n last=r\r\nprint('YES')\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sun May 24 13:42:32 2020\r\n\r\n@author: Vaibhav\r\n\"\"\"\r\n\r\ndef solve(n,m,l):\r\n for j in range(n):\r\n if len(set(l[j])) != 1:\r\n return \"NO\"\r\n i = 0\r\n while i < n-1:\r\n if(l[i][0] == l[i+1][0]):\r\n return \"NO\"\r\n i+=1\r\n return \"YES\"\r\n \r\n \r\nn, m = list(map(int, input().split(' ')))\r\nl = []\r\nfor _ in range(n):\r\n s = input()\r\n l.append(s)\r\nprint(solve(n,m,l))\r\n \r\n \r\n ", "n, m = map(int, input().split())\r\nb = list()\r\nfor i in range(n):\r\n a = input()\r\n b.append(str(a))\r\nc = 0\r\nfor i in range(n):\r\n for j in range(1, len(b[i])):\r\n if(int(b[i][j]) != int(b[i][j-1])):\r\n c = 1\r\nif(c == 1):\r\n print(\"NO\")\r\n exit() \r\nelse:\r\n for i in range(1,n-1):\r\n if(int(b[i]) == int(b[i-1])):\r\n c = 1\r\n\r\n if(int(b[i]) == int(b[i+1])):\r\n c = 1\r\n if (c == 0):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\n\r\n \r\n\r\n\r\n", "a=[*open(0)][1:]\r\nr=any(len({*b})>2 for b in a)\r\nprint('YNEOS'[r|any(x[0]==y[0]for x,y in zip(a,a[1:]))::2])", "n, m = map(int, input().split())\nflag = [input() for i in range(n)]\ngood = True\nfor i in range(n):\n if flag[i] != flag[i][0] * m:\n good = False\n if i > 0 and flag[i][0] == flag[i - 1][0]:\n good = False\nprint(\"YES\" if good else \"NO\")", "p=[*open(0)][1:]\r\nr=any(len({*b})>2 for b in p)\r\nprint('YNEOS'[r|any(x[0]==y[0]for x,y in zip(p,p[1:]))::2])", "from sys import stdin\r\n\r\ndef main():\r\n a,b=[int(x) for x in stdin.readline().strip().split()]\r\n lista=[]\r\n for i in range(a):\r\n lista.append([int(x) for x in list(stdin.readline().strip())])\r\n v=True\r\n for i in range(a):\r\n ant=lista[i][0]\r\n for j in range(b):\r\n v= v and ant==lista[i][j]\r\n\r\n if v:\r\n if i>0:\r\n v=v and lista[i-1][0]!=lista[i][0]\r\n else:\r\n break\r\n if v:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nmain()\r\n", "n,m=map(int, input().split())\na=[list(set(input())) for i in range(n)]\nfor i in a:\n if len(i)>1:\n print('NO')\n quit()\nfor i in range(1,n-1):\n if a[i-1][0]!=a[i][0] and a[i+1][0]!=a[i][0]:\n continue\n else:\n print('NO')\n quit()\nprint('YES')", "info = list(map(int, input().split()))\n\nmatrix = [list(map(int, input())) for _ in range(info[0])]\n\ngood = True\n\nfor i in range(info[0] - 1):\n for j in range(info[1] - 1):\n if matrix[i][j] != matrix[i][j+1]:\n good = False\n elif matrix[i][j] == matrix[i+1][j]:\n good = False\n\nfor i in range(info[0] - 1):\n if matrix[i][info[1]-1] == matrix[i+1][info[1]-1]:\n good = False\n\nfor j in range(info[1] - 1):\n if matrix[info[0]-1][j] != matrix[info[0]-1][j+1]:\n good = False\n\nif good:\n print('YES')\nelse:\n print('NO')\n", "import sys\r\ns = sys.stdin.readline().split()\r\nn = int(s[0])\r\nm = int(s[1])\r\ncountry_flag = []\r\nfor i in range(n):\r\n s = sys.stdin.readline()\r\n s = s.replace('\\n', s[0])\r\n country_flag.append(s)\r\ncountry_flag.append(\"n\"*(m+1))\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if country_flag[i][j]!=country_flag[i][j+1] or country_flag[i][j]==country_flag[i+1][j]:\r\n print(\"NO\\n\")\r\n sys.exit()\r\nsys.stdout.write(\"YES\\n\") \r\n \r\n", "n,m = input().split(\" \")\r\nn,m = int(n), int(m)\r\nc = -1\r\nz = True\r\nfor a in range(n):\r\n b = input()\r\n e = b[0]\r\n for d in range(1,m):\r\n if (e != b[d]):\r\n z = False\r\n break\r\n if (int(e)==c):\r\n z = False\r\n else:\r\n c = int(e)\r\n if not z:\r\n break\r\nif z:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") ", "a = input()\r\nb, c = a.split(\" \")\r\nb, c = int(b), int(c)\r\nprevfur = 11\r\nfor x in range(b):\r\n wrd = input()\r\n srtdwrd = sorted(wrd)\r\n if (srtdwrd[0] != srtdwrd[-1] or prevfur == wrd[0]):\r\n print(\"NO\")\r\n break\r\n else:\r\n prevfur = wrd[0]\r\n if(x == b - 1):\r\n print(\"YES\")\r\n break", "n,m=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n\tl=list(set(list(input())))\r\n\tif len(l)==1:a.append(l[0])\r\n\telse:break\r\nif len(a)==n:\r\n\tfor i in range(1,n):\r\n\t\tif a[i]==a[i-1]:print(\"NO\");break\r\n\telse:print(\"YES\")\r\nelse:print(\"NO\")", "n,m=list(map(int,input().split()))\r\na=[]\r\nz=0\r\nfor i in range(n):\r\n b=input()\r\n a.append(b)\r\n c=b[0]\r\n for j in range(m):\r\n if b[j]!=c:\r\n z=1\r\n break\r\n if z==1 or (i!=0 and a[i-1][0]==c):\r\n z=1\r\n break\r\nif z==0:\r\n print('YES')\r\nelse:\r\n print('NO')", "n,m=map(int,input().split())\r\nans=\"YES\"\r\nb=''\r\nfor i in range(n):\r\n a=set(input(''))\r\n if len(a)>1 or a==b:\r\n print(\"NO\")\r\n exit()\r\n b=a\r\nprint(\"YES\")\r\n \r\n \r\n ", "y=100\r\ns=0\r\nz=list(map(int,input().split()))\r\nx=[list(map(int,input()))for i in range(z[0])]\r\nfor i in range(z[0]):\r\n for j in range(z[1]-1):\r\n if x[i][0]!=x[i][j+1]:\r\n print('NO')\r\n s+=1\r\n break\r\n if s>0:\r\n break\r\n \r\n if sum(x[i])==y:\r\n print('NO')\r\n s+=1\r\n break\r\n y=sum(x[i])\r\n\r\nif s==0:\r\n print('YES')\r\n", "n,m=map(int,input().split())\r\nl=[]\r\nfor u in range(n):\r\n s=input()\r\n l.append(s)\r\nc=0\r\ns=0\r\na,b=0,0\r\nfor i in range(n):\r\n if(len(set(l[i]))==1):\r\n c=c+1\r\nif(c==n):\r\n a=1\r\nfor i in range(1,n):\r\n if(l[i]!=l[i-1]):\r\n s=s+1\r\nif(s==n-1):\r\n b=1\r\nif(a==1 and b==1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "row, col = map(int, input().split())\r\ns = []\r\ns.extend(input() for _ in range (row))\r\ns.append('-' * col)\r\n\r\nfor i in range (row):\r\n if not (all(j == s[i][0] for j in s[i]) and s[i] != s[i + 1]):\r\n print('NO')\r\n exit(0)\r\n \r\nprint('YES')", "n, m = [int(item) for item in input().split()]\r\nans, prev = 'YES', ''\r\nfor i in range(n):\r\n s = input()\r\n if s != s[0] * m or prev == s:\r\n ans = \"NO\"\r\n break\r\n prev = s\r\n\r\nprint(ans)\r\n", "def inp():\r\n return map(int, input().split())\r\n\r\n\r\nn, m = inp()\r\ntem = ''\r\nfor i in range(n):\r\n s = input()\r\n if (s.count(s[0]) != m or s==tem):\r\n exit(print('NO'))\r\n tem = s\r\nprint('YES')\r\n", "m, n = list(map(int, input().split(' ')))\r\n\r\nmatrix = [list(input()) for x in range(m)]\r\nok1, ok2 = True, True\r\n\r\nfor i in range(m):\r\n if len(set(matrix[i])) != 1:\r\n ok1 = False \r\n\r\nstripes = list(zip(*matrix))\r\nfor i in range(len(stripes[0])-1):\r\n if stripes[0][i] == stripes[0][i+1]:\r\n ok2 = False\r\n\r\nif ok1 and ok2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n,m=map(int,input().split())\r\nflag=0\r\ncount=0\r\nfor i in range(n): \r\n a=[int(a) for a in input()]\r\n if len(set(a))!=1:\r\n flag=1\r\n if i>0 and count==a[0]:\r\n flag=1\r\n count=a[0]\r\n \r\nif flag==1:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "n, m = map(int, input().split())\nmat = []\ncount = 0\nfor _ in range(n):\n i = list(input())\n # print(i)\n if i.count(i[0]) == m:\n mat.append(i)\n count += 1\n else:\n print(\"NO\")\n exit()\nfor i in range(n-1):\n for j in range(m):\n if mat[i][0] == mat[i+1][0]:\n print(\"NO\")\n exit()\n\nif count == n: print(\"YES\")\nelse: print(\"NO\")\n\t\t \t \t\t \t\t\t\t \t\t\t \t\t\t\t\t\t\t \t", "\r\nn,m=map(int,input().split())\r\nc=0\r\nl=[]\r\ncc=[]\r\nfor i in range(n):\r\n l.append(input())\r\n s=list(set(l[i]))\r\n if c==0 and len(s)!=1:\r\n c=1\r\n cc+=[int(s[0])]\r\nif c:\r\n print(\"NO\")\r\nelse:\r\n for i in range(n-1):\r\n if i==0 and cc[i]==cc[i+1]:\r\n c=1\r\n break\r\n elif i!=0 and (cc[i]==cc[i+1] or cc[i]==cc[i-1]):\r\n c=1\r\n break\r\n if c:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n", "n, m = map(int, input().split())\r\na = [set(map(int, input())) for i in range(n)]\r\nres = 'YES'\r\nx = set()\r\nfor i in a:\r\n if len(i) != 1 or x == i:\r\n res = 'NO'\r\n break\r\n x = i\r\nprint(res)", "from math import ceil,gcd,factorial,sqrt,log,log2\r\nimport queue\r\nimport heapq as hq\r\n# from functools import reduce\r\n#product is used to generater truth tables or multiply list produc([0,1],repeat=n)\r\nfrom itertools import permutations,combinations,accumulate,product\r\nfrom collections import Counter,deque\r\nfrom sys import stdin,stdout\r\nfrom bisect import bisect,insort,bisect_left,insort_left\r\ninput=stdin.readline\r\n# bisect=upper_bound,bisect_left=lower_bound\r\ndef sieve(n):\r\n prime = [True]*(n+1)\r\n p = 2\r\n prime[0]=False\r\n prime[1]=False\r\n for p in range(2,int(n**0.5)+1):\r\n if (prime[p] == True):\r\n # a.append(p)\r\n for l1 in range(p * p, n+1, p):\r\n prime[l1] = False\r\n return prime\r\ndef simplesieve(n):\r\n prime=[2]\r\n mak=[False]*(n+1)\r\n for p in range(3,n+1,2):\r\n if(mak[p]==False):\r\n prime.append(p)\r\n if(p*p<=n):\r\n for l1 in range(p*p,n +1,2*p):\r\n mak[l1]=True\r\n return prime\r\ndef segementedsieve(low,high):\r\n primes=simplesieve(int(high**.5))\r\n prime = [True] * (high-low + 1)\r\n for i in primes:\r\n lower = (low//i)*i\r\n if lower<low:\r\n lower+=i\r\n for j in range(lower,high+1,i):\r\n if(j!=i):\r\n prime[j-low]=False\r\n ans=[]\r\n for i in range(low,high+1):\r\n if prime[i-low]:\r\n ans.append(i)\r\n return ans\r\ndef isprime(n):\r\n if(n==2):\r\n return True\r\n if(n%2==0 or n==1):\r\n return False\r\n for l1 in range(3,int(n**0.5)+1,2):\r\n if(n%l1==0):\r\n return False\r\n return True\r\ndef binpow(a,b,m):\r\n r2=1\r\n a=a%m\r\n while(b>0):\r\n if(b&1):\r\n r2=(r2*a)%m\r\n a=(a*a)%m\r\n b>>=1\r\n return r2\r\ndef lcm(a,b):\r\n return (a//gcd(a,b))*b\r\n#gcd(a,b)=ax+by and \r\n \r\ndef gcdExtended(a,b): \r\n if(b==0): \r\n return a,1,0\r\n g,x1,y1=gcdExtended(b,a%b) \r\n x1,y1 = y1,x1-(a//b)*y1 \r\n return g,x1,y1\r\ndef binseach(a,l,r,key):\r\n while(r-l>1):\r\n m=l+(r-l)//2\r\n if(a[m]<=key):\r\n l=m\r\n else:\r\n r=m\r\n if(a[l]==key):\r\n return l\r\n if(a[r]==key):\r\n return r\r\n return -1\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\ndef inorder(root):\r\n res, stack = [], []\r\n current = root\r\n while True:\r\n while current:\r\n stack.append(current)\r\n current = current.left\r\n if len(stack) == 0:\r\n return res\r\n node = stack[-1]\r\n stack.pop(len(stack)-1)\r\n if node.data != None:\r\n res.append(node.data)\r\n current = node.right\r\n return res \r\n \r\ndef dfs(graph,s,v,ans):\r\n v[s]=1\r\n ans.append(s)\r\n for i in graph[s]:\r\n if(v[i]==0):\r\n dfs(graph,i,v,ans)\r\ndef bfs(graph,n,x,dest):\r\n v=[0]*(1+n)\r\n d=[0]*(1+n)\r\n # d=[-1]*1000\r\n d[x]=0\r\n v[x]=1\r\n q=queue.Queue()\r\n q.put(x)\r\n # p=[0]*(1+n)\r\n # p[x]=-1\r\n while(not q.empty()):\r\n z=q.get()\r\n for s in graph[z]:\r\n if(v[s]==0):\r\n v[s]=1\r\n d[s]=d[z]+1\r\n q.put(s)\r\n # p[s]=z\r\n # path=[]\r\n # #l1=dest#given\r\n # while(l1!=-1):\r\n # path.append(l1)\r\n # l1=p[l1]\r\n # path.reverse()\r\n #?print(d)\r\n return d[dest] \r\n# n,q=map(int,input().split())\r\n# a=list(map(int,input().split()))\r\n# for _ in range(int(input())):\r\nn,m=map(int,input().split())\r\n# n=int(input())\r\n# a=list(map(int,input().split()))\r\nb=[]\r\nfor i in range(n):\r\n a=list(input().strip())\r\n b.append(a)\r\nz=0\r\nfor i in range(n):\r\n for j in range(m-1):\r\n if(b[i][j]!=b[i][j+1]):\r\n z=1\r\n break\r\n if(i+1<n and b[i][j]==b[i+1][j]):\r\n z=1\r\n break\r\nif(z==1):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "n, m = map(int, input().split())\r\nmass = []\r\nfor i in range(n):\r\n\ts = input()\r\n\tmass.append(s)\r\nflag = True\r\nfor i in range(n):\r\n\tfor j in range(m):\r\n\t\tif mass[i][0] != mass[i][j]:\r\n\t\t\tflag = False\r\n\r\nif flag:\r\n\tfor i in range(n - 1):\r\n\t\tif mass[i][0] == mass[i + 1][0]:\r\n\t\t\tflag = False\r\n\r\nif flag:\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')\r\n", "n,m=map(int,input().split())\r\nmensaje=' '\r\nfor i in range(n):\r\n fil=input()\r\n if fil!=fil[0]*m or fil==mensaje:\r\n print('NO')\r\n exit()\r\n mensaje=fil\r\nprint('YES')\r\n", "n, m = map(int, input().split())\r\nl = []\r\n\r\nfor _ in range(n):\r\n s = list(input())\r\n if len(set(s)) != 1:\r\n print(\"NO\")\r\n break\r\n\r\n l.append(s)\r\nelse:\r\n for i in range(n-1):\r\n if l[i][0] == l[i+1][0]:\r\n print(\"NO\")\r\n break\r\n else:\r\n print(\"YES\") \r\n\r\n", "n,m=map(int,input().split())\r\nk=[]\r\nl=True\r\nfor i in range(n):\r\n k.append(input())\r\n if len(set(k[i]))!=1:\r\n l=False\r\n print(\"NO\")\r\n break\r\n \r\nif l:\r\n for i in range(n-1):\r\n if len(set(k[i]))==1 and set(k[i])!=set(k[i+1]):\r\n continue\r\n else:\r\n print(\"NO\")\r\n l=False\r\n break\r\n if l:\r\n print(\"YES\")\r\n \r\n\r\n\r\n \r\n \r\n \r\n \r\n", "def flag(n,m):\r\n used = []\r\n for i in range(n):\r\n lst = list(input())\r\n try:\r\n if (lst[0] == used[-1]):\r\n return 'NO'\r\n except:\r\n pass\r\n if (lst.count(lst[0])!=m):\r\n return \"NO\"\r\n used.append(lst[0])\r\n return \"YES\"\r\nn,m=map(int,input().split())\r\nprint(flag(n,m))", "H,W = map(int, input().split())\r\nboard = [] * W\r\nfor i in range(H):\r\n board.append(input())\r\n\r\nok = True\r\nc = \"\"\r\nfor i in range(H):\r\n for j in range(1, W):\r\n if (board[i][j] != board[i][j - 1]):\r\n ok = False\r\n break\r\n if (c == board[i][0]):\r\n ok = False\r\n break\r\n c = board[i][0]\r\nif (ok):\r\n print (\"YES\")\r\nelse:\r\n print (\"NO\")\r\n", "n,m=input().split(\" \")\r\nn=int(n)\r\nm=int(m)\r\na=[]\r\nflag=False\r\n\r\nfor i in range(n):\r\n s=input()\r\n a.append(s)\r\n\r\nfor i in range(n):\r\n for j in range(m-1):\r\n if a[i][j]!=a[i][j+1]:\r\n flag=True\r\n break\r\n if i<n-1 and a[i][j]==a[i+1][j]:\r\n flag=True\r\n break\r\n if flag:\r\n break\r\n\r\nif flag:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n", "n,m=map(int,input().split())\r\nl=[]\r\nf=0\r\nfor i in range(n):\r\n l.append(input())\r\nfor i in range(n-1):\r\n for j in range(m-1):\r\n if l[i][j]!=l[i][j+1]:\r\n f=1\r\n\r\n break\r\n elif l[i][j]==l[i+1][j]:\r\n f=1\r\n\r\n break\r\nfor i in range(m-1):\r\n if l[-1][i]!=l[-1][i+1]:\r\n f=1\r\n\r\n break\r\nif f==1:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n", "s = input().split()\r\nm = int(s[1])\r\n\r\ndef fail(n):\r\n for j in range(n-1): # ��������� ��� �� �����\r\n s = input()\r\n return 'NO'\r\n\r\ndef solve(n, last):\r\n if n == 0:\r\n return 'YES'\r\n else:\r\n s = input()\r\n if s[0] == last: # ���� ����� ����� ���������\r\n return fail(n)\r\n \r\n last = s[0]\r\n count = 0\r\n while (count < m) and (s[count] == last):\r\n count += 1\r\n if count == m: # ���� ������ ����������\r\n return solve(n-1, last)\r\n else:\r\n return fail(n)\r\n \r\nprint(solve(int(s[0]), '-1'))", "t = 1\r\nfor i in range(t):\r\n #n = int(input())\r\n a = input() ; a = a.split()\r\n a = [int(x) for x in a]\r\n n, m = a\r\n #a = input() ; \r\n #a.split()\r\n #a = [int(x) for x in a]\r\n #b = [x % 2 for x in a]\r\n f = True\r\n ch_old = ''\r\n for j in range(n):\r\n a = input() ; \r\n a.split()\r\n a = [int(x) for x in a]\r\n if (len(set(a)) > 1) or (ch_old == a[0]):\r\n f = False\r\n continue\r\n ch_old = a[0]\r\n \r\n if f:\r\n print('YES')\r\n else:\r\n print('NO')", "n, m = map(int, input().split())\r\ncolors = []\r\nret = 'YES'\r\nfor i in range(n):\r\n color = input()\r\n colors.append(color)\r\n\r\nfor i in range(n):\r\n for j in range(m - 1):\r\n if colors[i][j] != colors[i][j + 1]:\r\n ret = 'NO'\r\n break\r\n if ret == 'NO':\r\n break\r\n\r\nif ret != 'NO':\r\n for i in range(n - 1):\r\n for j in range(m):\r\n if colors[i][j] == colors[i + 1][j]:\r\n ret = 'NO'\r\n break\r\n if ret == 'NO':\r\n break\r\n\r\nprint(ret)\r\n", "n,m=[int(i) for i in input().split()]\r\nd=''\r\nflag=0\r\nfor i in range(n):\r\n s=str(input())\r\n if(i==0 and len(set(s))==1):\r\n d=d+s[0]\r\n elif(len(set(s))>1):\r\n flag=1\r\n# break\r\n else:\r\n d=d+s[0]\r\n if(d[len(d)-1]==d[len(d)-2]):\r\n flag=1\r\n# break\r\nif(flag>0):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "n, m = map(int, input().split())\r\nprev = None\r\nfor i in range(n):\r\n tmp = input()\r\n if tmp != tmp[0]*m or (prev and prev == tmp[0]):\r\n print(\"NO\")\r\n break\r\n prev = tmp[0]\r\nelse:\r\n print(\"YES\")", "from cmath import *\r\nfrom dataclasses import dataclass\r\nimport dataclasses\r\nfrom decimal import *\r\nfrom math import radians\r\nfrom operator import iadd, iand, iconcat\r\nfrom re import I\r\nfrom stringprep import c22_specials, c6_set\r\n\r\ndef solves():\r\n n,m = map(int,input().split())\r\n #lst =(list(map(int,input().split())))\r\n a = []\r\n check=0\r\n for i in range(0,n):\r\n for j in range(0,1):\r\n x= input()\r\n cnt = len(set(x))\r\n if cnt>1:\r\n check=1\r\n a.append(x[0])\r\n #for i in range(0,n):\r\n # print(a[i])\r\n if check==1:\r\n print(\"NO\")\r\n else:\r\n check1=0\r\n for i in range(1,n):\r\n if (a[i]==a[i-1]):\r\n check1=1\r\n break\r\n if check1==1:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n \r\n\r\nt=1\r\n#t = n=int(input())\r\nfor _ in range(t):\r\n solves()\r\n", "from sys import stdin\r\n\r\ndef main():\r\n n,m= [int(x) for x in stdin.readline().strip().split()]\r\n mx=[];f=True\r\n for i in range(n):\r\n aux= stdin.readline().strip()\r\n c=aux[0]\r\n for j in aux:\r\n if j!=c: f=(f and False);break\r\n if(i>0):\r\n if(mx[i-1][0]==c):f=(f and False)\r\n mx.append(aux)\r\n if f:print('YES')\r\n else:print('NO')\r\nmain()\r\n", "n, m = map(int, input().split())\nrows = [] \nfor _ in range(n):\n\trow = set(input())\n\tif len(row) > 1:\n\t\texit(print(\"NO\"))\n\trows.append(row.pop())\nfor (a, b) in zip(rows, rows[1::]):\n\tif a == b:\n\t\texit(print(\"NO\"))\nprint(\"YES\") \n\t\n", "def issame(s):\r\n for i in range(len(s)-1):\r\n if s[i]!=s[i+1]:\r\n return False\r\n return True\r\nn,m=input().strip().split(' ')\r\nn,m=(int(n),int(m))\r\nlist1=[]\r\nfor i in range(n):\r\n list1.append(str(input()))\r\nfor i in range(n):\r\n if issame(list1[i])==False:\r\n print(\"NO\")\r\n exit()\r\nfor i in range(n-1):\r\n if list1[i][0]==list1[i+1][0]:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")", "def f():\r\n y = ''\r\n n, m = map(int, input().split())\r\n for i in range(n):\r\n t = set(input())\r\n if len(t) > 1: return 'NO'\r\n x = t.pop()\r\n if y == x: return 'NO'\r\n y = x\r\n return 'YES'\r\nprint(f())", "'''Problem 16A - Flag'''\r\nn,m=map(int,input().split()) # citim n si m\r\nflag = []\r\nfor i in range(n):\r\n row = str(input())\r\n r = list(row) # transformam randul introdus intr-o lista\r\n flag.append(r) # lista creata o adaugam la lista flag\r\n\r\nc = 0\r\n# in caz ca flagul e doar dintrun rand\r\nif len(set(flag[0]))!=1:\r\n c=1\r\n# in caz ca flagul are 2 elemnte\r\nif len(flag)>1 and set(flag[0]) == set(flag[1]) :\r\n c = 1\r\n# verificam pana la flag-1 raduri\r\nfor i in range(len(flag)-1):\r\n # daca multimea unui rand e diferita de 1 , inseamna ca avem mai multe\r\n # culori , ceea ce e interziz\r\n if (len(set(flag[i]))!=1):\r\n c = 1\r\n break\r\n # daca multimea de numere a randului curent este egala cu multimea randuli\r\n # urmator , ceea ce nu indeplineste conditia , setam c = 1\r\n if set(flag[i]) == set(flag[i+1]):\r\n c= 1\r\n break\r\n# verificam ultima coloana\r\nif (len(set(flag[-1])))!=1:\r\n c = 1\r\n\r\n# afisam raspunsul\r\nif c == 0: print('YES')\r\nelse: print('NO')\r\n", "n_, l = [int(i) for i in input().split()]\r\nn = []\r\nfor _ in range(n_):\r\n n.append(input())\r\nflag = True\r\nif n[0].count(n[0][0]) == l:\r\n x = n[0][0]\r\n i = 1\r\n while i < n_ and flag:\r\n m = n[i][0]\r\n if m == x:\r\n flag = False\r\n if n[i].count(m) != l:\r\n flag = False\r\n x = m\r\n i += 1\r\n if flag:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')", "def h(l):\r\n r = []\r\n for i in l:\r\n if i not in r:\r\n r=r+[i]\r\n return r\r\ndef d(n):\r\n if n//10 ==0 :\r\n return 1 \r\n else:\r\n return 1+d(n//10)\r\ndef g(n):\r\n if d(n)!=m and n!=0 :\r\n return False\r\n elif len(h(str(n)))!=1 :\r\n return False\r\n else:\r\n return True\r\ndef f(l):\r\n for i in range(n):\r\n if not(g(l[i])):\r\n return \"NO\"\r\n if i<n-1 and l[i]==l[i+1] :\r\n return \"NO\"\r\n return \"YES\"\r\nn,m=map(int,input().split())\r\nl=[]\r\nfor _ in range(n):\r\n e=int(input())\r\n l=l+[e]\r\nprint(f(l))", "r,c=map(int,input().split())\r\nop=[]\r\ncount=0\r\nviol=0\r\nfor i in range(r):\r\n col=input()\r\n op.append(col)\r\n for j in col:\r\n if col.count(j)==len(col):\r\n break\r\n else:\r\n viol+=1\r\n break\r\n\r\nfor k in range(r-1):\r\n if op[k+1]==op[k]:\r\n viol+=1\r\n break\r\n else:\r\n count+=1\r\n\r\nif count==r-1 and viol==0:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n \r\n \r\n\r\n \r\n", "n,m=map(int,input().split())\r\n\r\nMAP=[input().strip() for i in range(n)]\r\n\r\nflag=1\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if MAP[i][j]!=MAP[i][j-1]:\r\n flag=0\r\n if i+1<n and MAP[i][j]==MAP[i+1][j]:\r\n flag=0\r\n\r\nif flag==1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def readln(): return tuple(map(int, input().split()))\n\nn, m = readln()\nlst = [set(list(input())) for _ in range(n)]\nlst = [v.pop() for v in lst if len(v) == 1]\nprint('YES' if len(lst) == n and not [1 for u, v in zip(lst[:-1], lst[1:]) if u == v] else 'NO')\n", "from sys import exit\r\n\r\ndef isSameCol(row):\r\n return len(set(row)) == 1\r\n\r\ndef rowCol(row):\r\n return row[0]\r\n\r\nn, _ = map(int, input().split())\r\na = []\r\nfor _ in range(n):\r\n a.append(input())\r\nfor i in range(n-1):\r\n if not isSameCol(a[i]):\r\n print(\"NO\")\r\n exit(0)\r\n if rowCol(a[i]) == rowCol(a[i+1]):\r\n print(\"NO\")\r\n exit(0)\r\nif not isSameCol(a[n-1]):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "# https://codeforces.com/problemset/problem/16/A\r\n\r\ndef sol(x, y, mat):\r\n for item in mat:\r\n for i in range(1, len(item)):\r\n if item[i] != item[0]:\r\n return \"NO\"\r\n for z in range(1, x):\r\n if mat[z][0] == mat[z-1][0]:\r\n return \"NO\"\r\n return \"YES\"\r\n\r\n\r\nx, y = map(int, input().split())\r\nmat = []\r\nfor xx in range(x):\r\n mat.append(input())\r\nprint(sol(x, y, mat))", "n, m = map(int, input().split())\r\ngrid = []\r\nfor i in range(n):\r\n grid.append(input())\r\n\r\ngood = True\r\nfor i in range(n):\r\n if len(set(grid[i])) != 1:\r\n good = False\r\n if i + 1 < n and grid[i][0] == grid[i + 1][0]:\r\n good = False\r\n\r\nif good:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n,m=map(int,(input().split()))\r\n\r\nf='0'\r\nd=1\r\n\r\nfor i in range(n):\r\n s=input()\r\n if i==0:\r\n f=s[0]\r\n for j in range(len(s)-1):\r\n if s[j]!=s[j+1]:\r\n print('NO')\r\n d=0\r\n break\r\n elif i!=0:\r\n if s[0]==f:\r\n print('NO')\r\n d=0\r\n break\r\n else:\r\n f=s[0]\r\n \r\n for j in range(len(s)-1):\r\n if s[j]!=s[j+1]:\r\n print('NO')\r\n d=0\r\n break\r\n if d==0:\r\n break\r\n \r\nif d==1:\r\n print('YES')\r\n ", "n, m = map(int, input().split())\r\n\r\nlast = -1\r\nflag = True\r\nfor i in range(n):\r\n s = input()\r\n if flag:\r\n color = int(s[0])\r\n if len(set(s)) > 1 or color == last:\r\n flag = False\r\n last = color\r\n\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "n,m=map(int,input().split())\r\na='bh'\r\nc=0\r\nfor i in range(n):\r\n d=set(input())\r\n if(len(d)>1)or(a==d):\r\n c=1\r\n a=d\r\nif(c==1):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Mar 30 19:32:51 2021\r\n\r\n@author: nehas\r\n\"\"\"\r\nfrom operator import eq\r\nr,c=map(int,input().split())\r\nm=[input() for i in range(r)]\r\ncl=[]\r\nc=0\r\nfor codes in m:\r\n cl.append(codes[0])\r\n k=set(codes)\r\n if(len(k)==1):\r\n c+=1\r\nif(c==len(m)):\r\n if(any(map(eq, cl, cl[1:]))==True):\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "e = input().split(' ')\r\nn = int(e[0])\r\nm = int(e[1])\r\nresult = \"YES\"\r\nprev_row_color = \"\"\r\ni = 0\r\nwhile i < n:\r\n j = 0\r\n row = input()\r\n while j < m: \r\n curr = row[j] \r\n if j+1 == len(row):\r\n break\r\n nxt = row[j+1]\r\n\r\n if curr != nxt:\r\n result = \"NO\"\r\n j += 1\r\n row_color = curr\r\n if row_color == prev_row_color:\r\n result = \"NO\"\r\n\r\n prev_row_color = row_color\r\n i += 1\r\n\r\n\r\nprint(result)", "n, m = list(map(int,input().strip().split(' ')))\r\ncolor = ''\r\nvalid = True\r\nfor i in range(n):\r\n s = input()\r\n if len(set(list(s))) != 1:\r\n valid = False\r\n break\r\n elif color == s[0]:\r\n valid = False\r\n break\r\n else:\r\n color = s[0]\r\nprint(\"YES\" if valid else \"NO\")", "n,m = map(int,input().split())\nlist1 = []\np = 1\nfor i in range(n):\n list1.append(list(map(int,input())))\nfor j in range(n):\n if list1[j].count(list1[j][0]) != m:\n p = 0\nfor o in range(m):\n for u in range(n-1):\n if list1[u][o] == list1[u+1][o]:\n p = 0\nif p ==1:\n print('YES')\nelif p ==0:\n print('NO')\n\t \t \t\t \t \t \t\t \t \t \t \t\t", "n, m = map(int, input().split())\r\ncur = \"-\"\r\nfor i in range(n):\r\n s = input()\r\n if cur == s[0]:\r\n print(\"NO\")\r\n exit()\r\n cur = s[0]\r\n for j in range(1, m):\r\n if cur != s[j]:\r\n print(\"NO\")\r\n exit()\r\n\r\nprint(\"YES\")", "n,m=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n\tb=input()\r\n\ts=[]\r\n\tfor i in b:\r\n\t\ts.append(int(i))\r\n\ta.append(s)\r\n#print(a)\r\nfor i in range(n):\r\n\tif i==0:\r\n\t\tk=a[0][0]\r\n\t\tif k*m!=sum(a[i]):\r\n\t\t\tprint('NO')\r\n\t\t\tbreak\r\n\telif a[i-1][0]==a[i][0]:\r\n\t\tprint('NO')\r\n\t\tbreak\r\n\telse:\r\n\t\tk=a[i][0]\r\n\t\tif k*m!=sum(a[i]):\r\n\t\t#\tprint(sum(a[i]))\r\n\t\t\t\r\n\t\t\tprint('NO')\r\n\t\t\tbreak\r\nelse:\r\n\tprint('YES')\r\n\t\t\r\n\t\t", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\nflag = [input() for _ in range(n)]\r\nres = 'YES'\r\n\r\nfor i in range(n):\r\n for j in range(1, m):\r\n if flag[i][j] != flag[i][0]:\r\n res = 'NO'\r\n if i > 0 and flag[i - 1][0] == flag[i][0]:\r\n res = 'NO'\r\n\r\nprint(res)", "n,m=[int(i) for i in input().split()]\r\ns={'a'}\r\nfor i in range(n):\r\n r=set(list(input()))\r\n if len(r)>1 or r==s:\r\n print('NO')\r\n exit()\r\n s=r\r\nprint('YES')", "n,m = list(map(int,input().split()))\r\nlst = []\r\nb = True\r\nlast = {-1}\r\nfor _ in range(n):\r\n temp = set(input())\r\n if len(temp)>1 or last == temp:\r\n b = False\r\n break\r\n last = temp\r\nif b:\r\n print('YES')\r\nelse:\r\n print('NO')", "import sys\r\nn,m=input().split()\r\nm = int(m)\r\noldcolor = ''\r\nfor i in range(int(n)):\r\n color = input()\r\n if color.count(color[0]) != m or oldcolor == color[0]:\r\n print('NO')\r\n sys.exit()\r\n oldcolor = color[0]\r\nprint('YES')", "n, m = map(int, input().split())\ncorrect = True\nfor i in range(n):\n line = input()\n if line != line[0] * m or (i != 0 and previous == line):\n correct = False\n break\n previous = line\n\nif correct:\n print(\"YES\")\nelse:\n print(\"NO\")", "from functools import reduce\nn,m=map(int, input().split())\nprev=''\nflag=True\nfor _ in range(n):\n r=input()\n if r!=m*r[0]:\n flag=False\n if r[0]==prev:\n flag=False\n prev=r[0]\n\nprint('YES' if flag else 'NO') \n", "n,m=map(int,input().split())\r\nl=[]\r\nf=0\r\nwhile(n):\r\n n-=1\r\n e=0\r\n k=list(input())\r\n \r\n for i in range(m):\r\n if(k[i]!=k[0]):\r\n e=1\r\n break\r\n if(k in l or e==1):\r\n print(\"NO\")\r\n f=1\r\n break\r\n if(len(l)==0):\r\n l.append(k)\r\n else:\r\n l.append(k)\r\n l.remove(l[0])\r\nif(f==0):\r\n print(\"YES\")", "num, mm = map(int, input().split())\r\n\r\nar, out = -1, \"YES\"\r\nfor i in range(num):\r\n se = input()\r\n res=se[0]\r\n if ( res == ar) or len(set(se)) != 1:\r\n out = \"NO\"\r\n break\r\n ar = se[0]\r\nprint(out)", "a,b=map(int,input().split())\r\nl=[]\r\nx=['0'*b,'1'*b,'2'*b,'3'*b,'4'*b,'5'*b,'6'*b,'7'*b,'8'*b,'9'*b]\r\ncount=0\r\nm=True\r\nfor i in range(a):\r\n l.append(input())\r\nif l[0] not in x:\r\n print('NO')\r\n m=False\r\nwhile m:\r\n for j in range(1,a):\r\n if l[j-1]==l[j]:\r\n print('NO')\r\n m=False\r\n break\r\n else:\r\n if l[-j] not in x:\r\n print('NO')\r\n m=False\r\n break\r\n else:\r\n print('YES')\r\n m=False\r\n", "n,m = (int(i) for i in input().split())\r\nb=list()\r\nbl=True\r\nfor i in range(int(n)):\r\n b.append(input())\r\nfor i in b:\r\n for j in i:\r\n if i[0]!=j:\r\n bl=False\r\nif bl:\r\n for i in range(n-1):\r\n if b[i]==b[i+1]:\r\n bl=False\r\n if bl:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n,m=map(int,input().split())\r\nans=\"YES\"\r\nec=\"\"\r\nfor i in range(n):\r\n s=list(input())\r\n if len(list(set(s)))!=1:\r\n ans=\"NO\"\r\n else:\r\n if s[0]==ec:\r\n ans=\"NO\"\r\n ec=s[0]\r\nprint(ans)\r\n", "n, m = (int(x) for x in input().split(' '))\r\nflag, arr = True, []\r\n\r\narr.append(input())\r\nif len(set(arr[0])) > 1:\r\n\tflag = False\r\nelse:\r\n\tprev = arr[0][0]\r\n\r\n\tfor i in range(1, n):\r\n\t\tarr.append(input())\r\n\r\n\t\tif len(set(arr[i])) > 1:\r\n\t\t\tflag = False\r\n\t\t\tbreak\r\n\r\n\t\tif prev == arr[i][0]:\r\n\t\t\tflag = False\r\n\t\t\tbreak\r\n\r\n\t\tprev = arr[i][0]\r\n\r\nprint(\"YES\" if flag else \"NO\")", "def solve():\r\n\r\n\tk = '$'\r\n\tn, m = map(int,input().split())\r\n\tfor i in range(n):\r\n\t\tmp = list(set([x for x in input()]))\r\n\t\tif len(mp) != 1 or mp[0] == k:\r\n\t\t\treturn 'NO'\r\n\t\tk = mp[0]\r\n\treturn 'YES'\r\n\r\nprint(solve())\r\n", "n,m=map(int,input().split())\r\ns=''\r\nfor i in range(n):\r\n a=input()\r\n if a[0]*len(a)!=a:\r\n print('NO')\r\n exit()\r\n else:\r\n s+=a[0]\r\nfor i in range(n-1):\r\n if s[i]==s[i+1]:\r\n print('NO')\r\n exit()\r\nprint('YES')\r\n", "n, m = map(int, input().split())\r\n\r\nlast_el = ''\r\nfor i in range(n):\r\n line = input()\r\n if len(set(line)) == 1 and line[0] != last_el:\r\n last_el = line[0]\r\n continue\r\n else:\r\n print('NO')\r\n break\r\nelse:\r\n print('YES')\r\n", "num=list(map(int,input().split()))\r\nn,m=num\r\nprev_element=0\r\nfor i in range(n):\r\n line=input()\r\n if i!=0:\r\n if line[0]==prev_element:\r\n print(\"NO\")\r\n break\r\n prev_element=line[0]\r\n f=len(dict.fromkeys(line).keys())\r\n if f!=1:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")", "n, m = map(int, input().split())\r\nr = 'YES'\r\nzad = ''\r\nlast = ''\r\n\r\nfor i in range(n):\r\n s = input()\r\n s = set(s)\r\n zad += str(s)\r\n\r\n if len(s) > 1 or s == last:\r\n r = 'NO'\r\n \r\n last = s\r\n \r\nzad = set(zad)\r\n\r\nif len(zad) > 13:\r\n r = 'NO'\r\n\r\nprint(r)\r\n", "n, m = map(int, input().split())\r\nb = []\r\nflag = 1\r\nfor i in range(n):\r\n s = input()\r\n if s.count(s[0]) != len(s):\r\n flag=0\r\n if i != 0:\r\n if s[0] == b[-1][0]:\r\n flag = 0\r\n b.append(s[0])\r\n \r\nif flag == 0:\r\n print('NO')\r\nelse:\r\n print('YES')\r\n ", "n, m = map(int, input().split())\r\na = [input() for _ in range(n)]\r\n\r\nfor i in range(n - 1):\r\n if a[i][0] == a[i + 1][0]:\r\n print(\"NO\")\r\n exit()\r\n\r\nfor i in range(n):\r\n for j in range(m - 1):\r\n if a[i][j] != a[i][j + 1]:\r\n print(\"NO\")\r\n exit()\r\n\r\nprint(\"YES\")\r\n", "\r\nimport sys\r\nimport math\r\n \r\nn, m = [int(x) for x in (sys.stdin.readline()).split()]\r\n\r\nq = \"\"\r\nfor i in range(n):\r\n st = sys.stdin.readline()\r\n if(st[0] == q):\r\n print(\"NO\")\r\n exit()\r\n else:\r\n q = st[0]\r\n for j in range(m - 1):\r\n if(st[j] != st[j + 1]):\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")", "n, m = [int(x) for x in input().split()]\r\nISO = 'YES'\r\nfor i in range(n):\r\n all_symb = set(list(input()))\r\n if len(all_symb) > 1:\r\n ISO = 'NO'\r\n break\r\n cur_symb = all_symb\r\n if i > 0:\r\n if cur_symb == last_symb:\r\n ISO = 'NO'\r\n break\r\n last_symb = cur_symb\r\nprint(ISO)", "# Write Python code in this online editor and run it.\na,b=map(int,input().split());c=\"a\"\nfor i in range(a):\n z=set(input())\n if len(z)>1 or c==z:print(\"NO\");exit()\n c=z\nprint(\"YES\")\n\n \t \t\t\t\t\t \t\t \t\t \t \t \t\t\t\t", "import sys\r\n\r\ndef main():\r\n inp = sys.stdin.read().strip().split('\\n')\r\n m, n = map(int, inp[0].split())\r\n if m == 1: return ('NO', 'YES')[len(set(inp[1])) == 1]\r\n s = list(map(set, inp[1:]))\r\n for i, j in zip(s, s[1:]):\r\n if len(i) != 1 or len(j) != 1 or i == j: return 'NO'\r\n return 'YES'\r\n \r\nprint(main())\r\n", "def start():\r\n s=['k']\r\n n,m=map(int,input().split())\r\n for i in range(n):\r\n a=input()\r\n if len(set(a))!=1:\r\n print('NO')\r\n return\r\n if s[i]==a:\r\n print('NO')\r\n return\r\n s.append(a)\r\n\r\n print('YES')\r\nstart()", "n,m=map(int,input().split())\r\nl,flag=[],0\r\nfor i in range(n):\r\n\ta=input()\r\n\tif i==0:\r\n\t\tl.append(a)\r\n\telse:\r\n\t\tif a == l[i-1]:\r\n\t\t\tflag=1\r\n\t\t\tl.append(a)\r\n\t\telse:\r\n\t\t\tl.append(a)\r\nfor i in l:\r\n\tif i.count(i[0])<m:\r\n\t\tflag=1\r\nprint(['YES','NO'][flag==1])", "n=[int(i) for i in input().split(' ')]\r\na=[]\r\nwhile n[0]>0:\r\n n[0]-=1\r\n s=set(input())\r\n a.append(s)\r\npr=set('r')\r\nres='YES'\r\nfor i in a:\r\n if len(i)!=1 or i==pr:\r\n res='NO'\r\n pr=i\r\nprint(res)", "import sys\r\nn,m = map(int,input().split())\r\nflag_list,negative = [],[]\r\nfor _ in range(n):\r\n flag = input()\r\n flag_list.append(str(flag))\r\nfor i in range(len(flag_list)-1):\r\n if flag_list[i] == flag_list[i+1]:\r\n negative.append(0)\r\n else:\r\n continue\r\nif 0 in negative:\r\n print('NO')\r\n sys.exit()\r\nelse:\r\n for i in range(len(flag_list)):\r\n for x in flag_list[i]:\r\n if flag_list[i].count(x) != m:\r\n negative.append(0)\r\n else:\r\n continue\r\nif 0 in negative:\r\n print('NO')\r\nelse:\r\n print('YES')\r\n", "n,m = map(int, input().split())\r\nmat = [[0] * m for i in range(n)]\r\nfor i in range(n):\r\n temp = input()\r\n for j in range(m):\r\n mat[i][j] = temp[j]\r\nflag = False\r\nfor i in range(1, n, 1):\r\n if mat[i][0] == mat[i - 1][0]:\r\n flag = True\r\nfor i in range(n):\r\n for j in range(1, m, 1):\r\n if mat[i][j] != mat[i][0]:\r\n flag = True\r\nif flag:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n", "n, m = map(int, input().split())\r\nflag = []\r\nfor _ in range(n):\r\n tmp = input()\r\n flag.append(tmp)\r\nchk = True\r\nfor row in range(n):\r\n if len(set(flag[row])) > 1:\r\n chk = False\r\n break\r\n if row < n-1 and set(flag[row])&set(flag[row+1]):\r\n chk = False\r\n break\r\nif chk: print(\"YES\")\r\nelse: print(\"NO\")", "def solve():\r\n n,m=map(int,input().split())\r\n a=[]\r\n check=0\r\n for i in range(n):\r\n x=input()\r\n ct=len(set(x))\r\n if(ct!=1):\r\n print(\"NO\")\r\n return\r\n a.append(x)\r\n for i in range(n-1):\r\n if a[i]==a[i+1]:\r\n print(\"NO\")\r\n return\r\n print(\"YES\")\r\n\r\nt=1\r\n#t=int(input())\r\nfor _ in range(t):\r\n solve()", "n, m = map(int, input().split())\n\nprev = None\nvalid = True\nfor _ in range(n):\n line = input()\n c = line[0]\n if c != prev:\n if not all(c1 == c for c1 in line[1:]):\n valid = False\n break \n prev = c\n else:\n valid = False\n break\nanswer = \"YES\" if valid else \"NO\"\nprint(answer)\n", "# Wadea #\r\n\r\nn,m = map(int,input().split())\r\nr = {\"-1\"}\r\ncount = 0\r\nfor i in range(n):\r\n s = list(input())\r\n c = set(s)\r\n if len(c) == 1 and c != r:\r\n count += 1\r\n r = c\r\nif count == n:print(\"YES\")\r\nelse:print(\"NO\")", "def checkIndiRow(rows, columns):\r\n for n in range(0, len(rows)):\r\n if(rows[n].count(rows[n][0])==columns):\r\n continue\r\n else:\r\n return 0\r\n for n in range(0,len(rows)-1):\r\n if(rows[n][0]==rows[n+1][0]):\r\n return 0\r\n else:\r\n continue\r\n return 1\r\ndef flagmain():\r\n rowColumn = list(map(int, input().split()))\r\n rows=[]\r\n for n in range(0,rowColumn[0]):\r\n rows.append(input())\r\n check=checkIndiRow(rows, rowColumn[1])\r\n if(check==1):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\nflagmain()", "n,m=map(int,input().split())\r\nd=[]\r\nflag=0\r\nfor i in range(n):\r\n a=input()\r\n a=list(set(a))\r\n if len(a)==1:\r\n flag=1\r\n d.append(a[0])\r\n else:\r\n print(\"NO\")\r\n exit(0)\r\nfor i in range(0,len(d)-1):\r\n if d[i+1]==d[i]:\r\n print(\"NO\")\r\n exit(0)\r\nprint(\"YES\")", "n,m = map(int,input().split())\r\nli = []\r\nb = 0\r\nflag = 1\r\nfor i in range(n):\r\n a = list(input())\r\n li.append(a)\r\nif len(set(li[0]))==1:\r\n b = li[0][0]\r\n for i in range(1,n):\r\n if len(set(li[i]))!=1 or li[i][0]==b:\r\n flag=0\r\n else:\r\n b= li[i][0]\r\nelse:\r\n flag = 0\r\nif flag ==1:\r\n print('YES')\r\nelse:\r\n print('NO') ", "res = True\r\nprev = 'A'\r\nn, m = map(int, input().split())\r\nfor _ in range(n):\r\n row = input()\r\n if any(c != row[0] for c in row): res = False\r\n res = res and (row[0] != prev)\r\n prev = row[0]\r\nprint(\"YES\" if res else \"NO\")\r\n", "n, m = map(int, input().split())\nf = [None] * n\nb = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']\nk = True\nfor i in range(n):\n f[i] = input()\n for j in range(m):\n if b.count(f[i][j]) == 0:\n k = False\n break\n if f[i].count(f[i][0]) != m or i != 0 and f[i] == f[i-1]:\n k = False\n break\nif k == True:\n print('YES')\nelse:\n print('NO')\n", "a,b=map(int, input().split())\r\ny=set()\r\nfor i in range(a):\r\n x=set(input())\r\n if len(x)!=1 or x==y:\r\n print(\"NO\")\r\n exit()\r\n y=x\r\nprint(\"YES\")", "r,c = map(int,input().split())\r\nli=[]\r\nflag=0\r\nfor i in range(r):\r\n li.append(input())\r\nfor i in range(r):\r\n for j in range(c-1):\r\n if li[i][j] != li[i][j+1]:\r\n print('NO')\r\n flag=1\r\n break \r\n \r\n if flag == 1:\r\n break\r\n else:\r\n if i<=r-2:\r\n if li[i][0] == li[i+1][0]:\r\n print('NO')\r\n flag=1\r\n break\r\nif flag != 1:\r\n print('YES')", "def flag(lst, n, m):\r\n for i in range(n):\r\n for j in range(m - 1):\r\n if lst[i][j] != lst[i][j + 1]:\r\n return \"NO\"\r\n for i in range(n - 1):\r\n if lst[i][0] == lst[i + 1][0]:\r\n return \"NO\"\r\n return \"YES\"\r\n\r\n\r\nN, M = [int(z) for z in input().split()]\r\na = list()\r\nfor k in range(N):\r\n s = input()\r\n a.append(s)\r\nprint(flag(a, N, M))\r\n", "def check_iso_standard(n, m, flag):\n for i in range(n):\n row = flag[i]\n if len(set(row)) > 1:\n return \"NO\"\n \n for i in range(1, n):\n if flag[i][0] == flag[i-1][0]:\n return \"NO\"\n \n return \"YES\"\n\n\n# Input reading\nn, m = map(int, input().split())\nflag = [input() for _ in range(n)]\n\n# Check if the flag meets the ISO standard\nresult = check_iso_standard(n, m, flag)\nprint(result)\n", "n, m = map(int, input().split())\r\na = ''\r\nfor _ in range(n):\r\n l = list(map(str, input()))\r\n if a == l[0] or l.count(l[0]) != m:\r\n print('NO')\r\n exit()\r\n a = l[0]\r\nprint('YES')", "rows, cols = map(int, input().split(\" \"))\n\n\nprev = ''\nfor x in range(rows):\n\tline = list(input())\n\tif prev == line[0]:\n\t\tprint (\"NO\")\n\t\texit()\n\n\tprev = line[0]\n\tfor l in line:\n\t\tif prev != l:\n\t\t\tprint (\"NO\")\n\t\t\texit()\n\nprint (\"YES\")", "n=input()\r\nsp=n.split()\r\nrws=int(sp[0])\r\ncls=int(sp[1])\r\nl=[]\r\nfor ui in range(0,rws):\r\n line=input()\r\n l.append(line)\r\nst=0\r\nfor gh in range(0,len(l)):\r\n if st==0:\r\n s=\"\"\r\n for ui in range(0,cls):\r\n s=s+l[gh][0]\r\n\r\n if s!=l[gh]:\r\n st=1\r\n else:\r\n break\r\nif st==1:\r\n print(\"NO\")\r\nelse:\r\n for yi in range(0,cls):\r\n if st==0:\r\n for gh in range(0,rws-1):\r\n if l[gh][yi]==l[gh+1][yi]:\r\n st=1\r\n break\r\n else:\r\n break\r\n if st==1:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")", "def flag(a):\r\n n = len(a)\r\n m = len(a[0])\r\n valid = True\r\n last = -1\r\n for i in range(n):\r\n c = a[i][0]\r\n if c == last:\r\n valid = False\r\n break\r\n last = c\r\n for j in range(1, m):\r\n if a[i][j] != c:\r\n valid = False\r\n break\r\n if valid:\r\n r = \"YES\"\r\n else:\r\n r = \"NO\"\r\n return r\r\n\r\nn, m = list(map(int, input().strip().split()))\r\nl = list()\r\nfor i in range(n):\r\n l.append(list(map(int, list(input().strip()))))\r\nprint(flag(l))", "import random\r\nlist = []\r\ncheck=False\r\nx , y =map(int,input().split())\r\nfor i in range(x):\r\n list.append(input())\r\n\r\nfor i in range(x):\r\n if len(set(list[i])) > 1:\r\n check=True\r\n break\r\nfor i in range(x-1):\r\n if list[i] == list[i+1]:\r\n check = True\r\n break\r\nif check:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "\r\nn, m = map(int, input().split())\r\nprev = -100\r\nfor _ in range(n):\r\n\tse = list(set(input()))\r\n\r\n\tif len(se) != 1:\r\n\t\tprint('NO')\r\n\t\texit()\r\n\r\n\telif se[0] == prev:\r\n\t\tprint('NO')\r\n\t\texit()\r\n\r\n\telse:\r\n\t\tprev = se[0]\r\n\r\nprint('YES')\r\n", "n, m =map(int,input().split())\r\nsp= input()\r\nl = sp.count(sp[0])\r\nif l ==m:\r\n k=1\r\nelse:\r\n k = 0\r\nfor i in range(n-1):\r\n s = input()\r\n if s[0] != sp[0] and s.count(s[0]) == m:\r\n k +=1 \r\n sp =s\r\nif k == n:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n ", "r,c=map(int,input().split())\r\nL=[]\r\nflag=0\r\nfor i in range(0,r):\r\n L.append(list(input()))\r\n #print(L)\r\n if i==0:\r\n if len(set(L[-1]))!=1:\r\n flag=1\r\n break\r\n else:\r\n if len(set(L[-1]))!=1:\r\n flag=1\r\n break\r\n else:\r\n #print(set(L[-1]),set(L[-2]))\r\n if set(L[-1])==set(L[-2]):\r\n flag=1\r\n break\r\nif flag==1:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n \r\n", "a, b= map(int, input().split())\r\nc= ''\r\nfor _ in range(a):\r\n l = list(map(str, input()))\r\n if c == l[0] or l.count(l[0]) != b:\r\n print('NO')\r\n exit()\r\n c = l[0]\r\nprint('YES')", "n,m = list(map(int,input().split()))\r\nrows = []\r\nfor i in range(n):\r\n\trows.append(input())\r\n\r\nfor i in rows:\r\n\tif i != i[0]*m:\r\n\t\tprint('NO')\r\n\t\texit(0)\r\n\r\nc = 'a'\r\nfor i in rows:\r\n\tv = i[0]\r\n\tif v == c:\r\n\t\tprint('NO')\r\n\t\texit(0)\r\n\tc = v\r\n\r\nprint('YES')", "x = r = 'YES'\r\nfor i in [*open(0)][1:]:\r\n s = {*i}\r\n if len(s) > 2 or x == s:\r\n r = 'NO'\r\n x = s\r\nprint(r)", "n,m=map(int,input().split())\r\np='YES'\r\nl=[]\r\nfor i in range(n):\r\n\tx=list(input())\r\n\tif len(set(x))!=1:\r\n\t\tp='NO'\r\n\t\tbreak\r\n\tif i!=0 and l[-1]==x:\r\n\t\tp='NO'\r\n\t\tbreak\r\n\tl.append(x)\r\nprint(p)", "def main():\r\n\tn, m = map(int, input().split())\r\n\tboard = [list(str(input())) for _ in range(n)]\r\n\r\n\tflag1 = False\r\n\tflag2 = False\r\n\r\n\tif all(len(set(el)) == 1 for el in board):\r\n\t\tflag1 = True\r\n\r\n\tif flag1:\r\n\t\tboard = [el[0] for el in board]\r\n\t\tif all(board[i] != board[i + 1] for i in range(n - 1)):\r\n\t\t\tflag2 = True\r\n\r\n\tif flag1 and flag2:\r\n\t\tprint('YES')\r\n\telse:\r\n\t\tprint('NO')\r\n\r\n\r\nif __name__ == '__main__':\r\n\tmain()", "n,m=map(int,input().split())\r\ns=[]\r\nc=0\r\nfor i in range(n):\r\n f=input()\r\n s.append(f)\r\n for j in range(m-1):\r\n if f[j]!=f[j+1]:\r\n c=1\r\n if c:\r\n print(\"NO\")\r\n break\r\nk=0\r\nif not c:\r\n for i in range(n-1):\r\n if s[i]==s[i+1]:\r\n print(\"NO\")\r\n k=1\r\n break\r\nif not k and not c:\r\n print(\"YES\")", "n, m = map(int, input().split())\n\nflag = []\nfor i in range(n):\n horizontal_row = input()\n flag.append(horizontal_row)\n\nfor row in flag:\n if len(set(row)) > 1:\n print(\"NO\")\n exit(0)\n\nfor row_i in range(len(flag)-1):\n if flag[row_i] == flag[row_i+1]:\n print(\"NO\")\n exit(0)\n\nprint(\"YES\")\n", "n = [int(x) for x in input().split()]\nhold = \"\"\nhold2 = \"\"\nfor i in range(0, n[0]):\n s = input()\n for j in range(0, n[1]):\n if j == 0:\n hold = s[0]\n if hold == hold2:\n print(\"NO\")\n exit() \n if s[j] != hold:\n print(\"NO\")\n exit() \n hold2 = hold\nprint(\"YES\")", "n,m=map(int,input().split())\r\nx=\"\"\r\nfor i in range(n):\r\n p=input()\r\n s=set(p)\r\n if p==x:\r\n print(\"NO\")\r\n break\r\n if len(s)>1 :\r\n print(\"NO\")\r\n break\r\n x=p\r\nelse:\r\n print(\"YES\")\r\n", "def main():\r\n n, m = map(int, input().split())\r\n last_digit = \"10\"\r\n for i in range(n):\r\n row = list(set(input()))\r\n if len(row) != 1 or row[0] == last_digit:\r\n print(\"NO\")\r\n return\r\n last_digit = row[0]\r\n print(\"YES\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "def is_iso_flag(n, m, flag):\r\n for i in range(n):\r\n for j in range(1, m):\r\n if flag[i][j] != flag[i][j - 1]:\r\n return \"NO\"\r\n for i in range(1, n):\r\n if flag[i][0] == flag[i - 1][0]:\r\n return \"NO\"\r\n\r\n return \"YES\"\r\nn, m = map(int, input().split())\r\nflag = [list(input().strip()) for _ in range(n)]\r\nresult = is_iso_flag(n, m, flag)\r\nprint(result)\r\n", "# Enter your code here. Read input from STDIN. Print output to STDOUT\nimport math\n\nif __name__ == '__main__':\n x, y = [int(x) for x in input().strip().split(\" \")]\n f = [input().strip() for _ in range(x)]\n a = \"YES\"\n for i in range(x):\n for j in range(1, y):\n if f[i][j] != f[i][j - 1]:\n a = \"NO\"\n if i > 0:\n if f[i][0] == f[i - 1][0]:\n a = \"NO\"\n print(a)\n\n\t\t \t \t \t \t\t \t \t\t\t\t \t \t", "n, m = [int(i) for i in input().split()]\r\nlast = '.'\r\n\r\nfor i in range(n):\r\n s = input()\r\n if last == s[0]:\r\n print('NO')\r\n exit(0)\r\n if s != s[0] * m:\r\n print('NO')\r\n exit(0)\r\n last = s[0]\r\nprint('YES')", "n,m=map(int,input().split())\r\nz=input()\r\ng=[1,0][len(set(z))==1]\r\nfor i in range(n-1):\r\n a=input()\r\n if len(set(a))!=1 or z==a:g=1\r\n z=a\r\nprint(['YES','NO'][g])\r\n", "import sys\r\n\r\nrow, col = map(int, sys.stdin.readline().split())\r\n\r\nstandard = True\r\nprev_color = ''\r\nfor i in range(row):\r\n line = sys.stdin.readline()\r\n if line[0] == prev_color:\r\n standard = False\r\n break\r\n prev_color = line[0]\r\n for j in range(1, col):\r\n if prev_color != line[j]:\r\n standard = False\r\n break\r\n if not standard:\r\n break\r\n\r\nif standard:\r\n print('YES')\r\nelse:\r\n print('NO')", "\r\nn,m = map(int, input().split())\r\nl = []\r\nflag = 0 #checker\r\nfor i in range(n):\r\n l.append(input())\r\nfor i in range(n):\r\n for j in range(m - 1):\r\n if(l[i][j] != l[i][j + 1]): #if next element in row is different, set flag to 1\r\n flag = 1 #if flag = 1, two rows are the same -> thus, can't be\r\nfor i in range(n - 1):\r\n if(l[i][0] == l[i + 1][0]): #same for rows\r\n flag = 1\r\nif(flag == 1):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "n,m = map(int,input().split())\r\nls = []\r\ns = input()\r\nif s != f'{s[0]}'*m:\r\n print('NO')\r\nelse:\r\n ls.append(s[0])\r\n for i in range(n-1):\r\n s = input()\r\n if ls.pop() == s[0]:\r\n print('NO')\r\n break\r\n elif s != f'{s[0]}'*m:\r\n print('NO')\r\n break\r\n ls.append(s[0])\r\n else:\r\n print('YES')\r\n", "n,m=map(int,(input().split(' ')))\nlst=[]\nfor i in range(n):\n a=input()\n flag1 = True\n for i in range(len(a)-1):\n if a[i]!=a[i+1]:\n flag1=False\n break\n if flag1:#肯定相邻OK\n lst.append(a)\nflag2=True\nfor items in range(len(lst)-1):\n if lst[items]==lst[items+1]:\n flag2=False\n break\nif len(lst)==n and flag2 :\n print('YES')\nelse:\n print('NO')\n \t\t\t \t \t \t \t\t\t \t\t\t\t\t \t\t", "import sys\r\nn, m = map(int, input().split())\r\npred = 'A'\r\nA = [input() for i in range(n)]\r\nfor i in range(n):\r\n if A[i][0] == pred:\r\n print(\"NO\")\r\n sys.exit()\r\n else:\r\n for j in range(m):\r\n if A[i][j] != A[i][j - 1]:\r\n print(\"NO\")\r\n sys.exit()\r\n pred = A[i][0]\r\nprint(\"YES\")", "s = [int(i) for i in input().split()]\nf = [input() for i in range(s[0])]\nf1 = [i for i in zip(*f)]\nif len(set(f1)) != 1:\n print('NO')\n quit()\nfor i in range(len(f)-1):\n if len(set(f[i])) != 1 or f[i][0] == f[i+1][0]:\n print('NO')\n quit()\nprint('YES')\n\n", "#import sys\r\n\r\n#sys.stdin = open(\"1.in\", \"r\")\r\n\r\nn, m = map(int, input().split())\r\n\r\nlast = ' '\r\nfor _ in range(n):\r\n row = input()\r\n if row[0] == last or row != row[0] * m:\r\n print(\"NO\")\r\n exit(0)\r\n \r\n last = row[0]\r\n\r\nprint(\"YES\")", "# https://codeforces.com/problemset/problem/16/A\r\n\r\ndef func_sol(raw_data):\r\n data = raw_data.split('\\n')[:-1]\r\n n, m = map(int, data[0].split(' '))\r\n lines = data[1:]\r\n for line in lines:\r\n for c in line:\r\n if c != line[0]:\r\n return \"NO\\n\"\r\n for i in range(len(lines) - 1):\r\n if lines[i][0] == lines[i + 1][0]:\r\n return \"NO\\n\"\r\n return \"YES\\n\"\r\n\r\n\r\ndef main():\r\n try:\r\n from codeforces.utilities import run_tests\r\n run_tests(func_sol)\r\n except ImportError:\r\n from sys import stdin\r\n print(func_sol(stdin.read()))\r\n\r\n\r\nmain()\r\n", "def solve():\r\n\tn, m = map(int,input().split())\r\n\tarr = [set(input()) for x in range(n)]\r\n\tcurr = '#'\r\n\tfor x in arr:\r\n\t\tif len(x) != 1 or x == curr:\r\n\t\t\treturn 'NO'\r\n\t\tcurr = x\r\n\treturn 'YES'\r\nprint(solve())\r\n", "n,m=map(int,input().split())\r\nflag=True\r\nfor run in range(n):\r\n s=input()\r\n new=''\r\n for ele in s:\r\n if ele not in new:\r\n new+=ele\r\n if len(new)>1:\r\n flag=False\r\n break\r\n if run==0:\r\n temp=s\r\n else:\r\n if s==temp:\r\n flag=False\r\n break\r\n else:\r\n temp=s\r\nif flag:\r\n print('YES')\r\nelse:\r\n print('NO')", "a=[*open(0)][1:]\nr=any(any(x!=y for x,y in zip(b,b[1:-1]))for b in a)\nprint('YNEOS'[r|any(x[0]==y[0] for x,y in zip(a,a[1:]))::2])\n \t \t \t\t \t\t\t \t\t\t \t \t\t \t", "m , n = map(int, input().split())\r\nans = 0\r\nans=1\r\ns = str(input())\r\ntemp=s[0]\r\nif len(s) == s.count(s[0]):\r\n for i in range(m-1):\r\n s = str(input())\r\n if len(s) == s.count(s[0]):\r\n if temp!=s[0]:\r\n ans = 1\r\n temp = s[0]\r\n else:\r\n ans = 0\r\n break\r\n else:\r\n ans = 0\r\n break\r\nelse:\r\n ans =0\r\nif ans==1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "\r\n\r\nn,m = map(int,input().split())\r\n\r\nt=[]\r\nf=[]\r\nu=0\r\nfor k in range(n):\r\n h = list(input())\r\n t.append(h)\r\n \r\n\r\nif n==1:\r\n if len(set(t[0]))!=1:\r\n print('NO')\r\n else:\r\n print('YES')\r\nelse:\r\n\r\n for i in range(n):\r\n if len(set(t[i]))!=1:\r\n print('NO')\r\n u+=1\r\n break\r\n else:\r\n if i==0:\r\n if t[i+1]!=t[i]:\r\n pass\r\n else:\r\n \r\n print('NO')\r\n u+=1\r\n break\r\n elif i==n-1:\r\n if t[i-1]!=t[i]:\r\n pass\r\n else:\r\n print('NO')\r\n u+=1\r\n break\r\n else:\r\n if t[i]!=t[i+1] and t[i]!=t[i-1]:\r\n pass\r\n else:\r\n print('NO')\r\n u+=1\r\n break\r\n\r\n if u==0:\r\n print('YES')\r\n \r\n", "n, m = map(int, input().split())\r\nb = set()\r\nfor i in range(n):\r\n a = set(input())\r\n if len(a) > 1 or a == b:\r\n print('NO')\r\n exit(0)\r\n b = a\r\nprint('YES')", "n,m=input().split()\nn,m=int(n),int(m)\nd=0\nh=0\ng=[]\nfor i in range(n):\n l=input()\n p=set(l[:])\n g.append(p)\n if len(p)!=1:\n print(\"NO\")\n d=1\n break\nif d==0:\n for i in range(len(g)-1):\n if g[i]==g[i+1]:\n print(\"NO\")\n h=1\n break\n if h==0:\n print(\"YES\")\n", "def q16a():\n\tn, m = tuple([int(num) for num in input().split()])\n\tprev = -1\n\tfor _ in range(n):\n\t\tarr = [int(num) for num in list(input())]\n\t\tif(len(set(arr)) != 1):\n\t\t\treturn \"NO\"\n\t\tif(arr[0] == prev):\n\t\t\treturn \"NO\"\n\t\tprev = arr[0]\n\treturn \"YES\"\n\n\t\nprint(q16a())", "ABC, BCA = [int(item) for item in input().split()]\r\ns0L, rSE = 'YES', ''\r\nfor zxc in range(ABC):\r\n sdf = input()\r\n if sdf != sdf[0] * BCA or rSE == sdf:\r\n s0L = \"NO\"\r\n break\r\n rSE = sdf\r\n \r\nprint(s0L)", "def check():\r\n s=input()\r\n a=0\r\n s=list(s)\r\n if len(list(set(s)))==1:\r\n a=0\r\n else:\r\n a=1\r\n return [s,a]\r\na,b=[int(a) for a in input().split(' ')]\r\np=[]\r\nc=0\r\nfor i in range(a):\r\n x,y=check()\r\n p.append(x)\r\n if y==1:\r\n c=1\r\n else:\r\n None\r\nfor i in range(len(p)-1):\r\n if (p[i]==p[i+1]):\r\n \r\n c=1\r\n break\r\n else:\r\n continue\r\nif c==0:\r\n print(\"YES\")\r\nelif c==1:\r\n print(\"NO\")\r\n", "n, m = map(int,input().split())\r\nlst = []\r\nfor i in range(n):\r\n s = input()\r\n if s.count(s[0]) == m:\r\n lst.append(s[0])\r\nif len(lst) != n:\r\n print(\"NO\")\r\nelse:\r\n flag = True\r\n for i in range(1,n):\r\n if lst[i] == lst[i-1]:\r\n flag = False\r\n break\r\n if flag:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "n, m = list(map(int, input().split()))\r\nflag = \"YES\"\r\nprev = \"10\"\r\nfor i in range(n):\r\n a = set(input())\r\n if a == prev:\r\n flag = \"NO\"\r\n break\r\n if len(a) != 1:\r\n flag = \"NO\"\r\n break\r\n prev = a\r\nprint(flag)", "r = 'YES'\r\nx = set()\r\nfor i in [set(input()) for i in range(int(input().split()[0]))]:\r\n if len(i) != 1 or x == i:\r\n r = 'NO'\r\n x = i\r\nprint(r)", "a, b = map(int, input().split())\r\npre = None\r\nans = \"YES\"\r\nfor i in range(a):\r\n\tst = list(set([i for i in input()]))\r\n\tif len(st) != 1 or st[-1] == pre:\r\n\t\tans = \"NO\"\r\n\tpre = st[0]\r\n \r\nprint(ans)", "m,n=map(int,input().split())\r\nf=[]\r\ns=True\r\nfor i in range(m):\r\n a=list(input())\r\n a=set(a)\r\n f.append(a)\r\nif m==1 and len(a)==1:\r\n print('YES')\r\n exit(0)\r\nelif m==2 and len(a)==1:\r\n if f[0]!=f[1] and len(f[0])==1:\r\n print('YES')\r\n exit(0)\r\nif m>2:\r\n for i in range(1,m-1):\r\n if len(f[i-1])==1 and len(f[i])==1 and len(f[i+1])==1 and f[i+1]!=f[i] and f[i]!=f[i-1]:\r\n pass\r\n else:\r\n s=False\r\n if s:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')", "n, m = map(int, input().split())\r\nprev = \"-\"\r\nans = \"YES\"\r\nfor _ in range(n):\r\n s = input()\r\n if s.count(s[0])!=m or s[0]==prev:\r\n ans = \"NO\"\r\n prev = s[0]\r\nprint(ans)", "#--------------------#\r\n#INCLUDE <HajLorenzo>\r\n#INCLUDE <MUSIC.H>\r\n#Mitchell Broom - Ascension\r\n#--------------------#\r\n_=list(map(int,input().split()))\r\n__=True\r\n____=\"WTF\"\r\nfor _i_ in range(_[0]):\r\n ___=input()\r\n if((___.count(___[0])!=_[1]) or (___[0]==____)):__=False\r\n ____=___[0]\r\n \r\nprint(\"YES\" if(__) else \"NO\")\r\n\r\n'''UseFull Code\r\na=list(map(int,input().split()))\r\nprint(\"Yes\" if() else \"No\")\r\ndef func(a):\r\n return a\r\n'''\r\n\r\n\r\n\r\n", "n, m = map(int, input().split())\nflag = [list(input()) for _ in range(n)]\n\nprev = ''\niso = True\nfor i in flag:\n if i.count(i[0]) != m or i[0] == prev:\n iso = False\n break\n prev = i[0]\n\nprint('YES' if iso else 'NO')\n", "n,m = map(int,input().split())\r\np = 0\r\nfor i in range(n):\r\n a = list(input())\r\n b = list(set(a))\r\n if len(b) > 1 or p == b[0]:\r\n print(\"NO\")\r\n exit()\r\n p = b[0]\r\nprint(\"YES\")", "n,m=map(int,input().split())\r\na,b=[],[]\r\nfor i in range(10):\r\n a.append(str(i)*m) \r\nfor i in range(n):\r\n b.append(input())\r\nfor i in range(n):\r\n if a[int(b[i][0])]!=b[i]:\r\n print(\"NO\")\r\n exit()\r\n if i>0 and b[i][0]==b[i-1][0]:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\") \r\n", "nm=input().split(' ')\r\nn=int(nm[0])\r\n# flag1=1\r\nflag2=0\r\nl=[]\r\nfor i in range(n):\r\n x=input()\r\n y=set(x)\r\n if len(y)==1:\r\n #flag1=10\r\n l.append(x)\r\n else:continue\r\nfor j in range(len(l)-2):\r\n if(l[j]==l[j+1] or l[j+1]==l[j+2]):\r\n flag2=10\r\nif n!=len(l) or flag2==10:\r\n print(\"NO\")\r\nelse:print(\"YES\")\r\n", "n, m = map(int, input().split())\r\nlast = None\r\nfor i in range(n) :\r\n\tl = input()\r\n\r\n\tif len([j for j in l if j == l[0]]) != len(l):\r\n\t\tprint(\"NO\")\r\n\t\tbreak\r\n\telif last == l[0] :\r\n\t\tprint(\"NO\")\r\n\t\tbreak\r\n\tlast = l[0]\r\nelse :\r\n print(\"YES\")", "n, m = map(int, input().split())\r\nflag = [input() for _ in range(n)]\r\nfor i in range(n):\r\n if len(set(flag[i])) != 1:\r\n print(\"NO\")\r\n exit()\r\nfor i in range(1, n):\r\n if flag[i] == flag[i-1]:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")\r\n", "a,b = map(int,input().split())\r\nv,f,w =[],0,0\r\nfor i in range(a):\r\n\tb = list(set(input()))\r\n\tif len(b)>1:f =1;break\r\n\telse:v.append(*b)\r\nif f ==0:\r\n\tfor i in range(1,a):\r\n\t\tif v[i]==v[i-1]:w =1;break\r\n\tif w ==1:print(\"NO\")\r\n\telse:print(\"YES\")\r\nelse:print(\"NO\")" ]
{"inputs": ["3 3\n000\n111\n222", "3 3\n000\n000\n111", "3 3\n000\n111\n002", "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888", "10 13\n4442444444444\n8888888888888\n6666666666666\n0000000000000\n3333333333333\n4444444444444\n7777777777777\n8388888888888\n1111111111111\n5555555555555", "10 8\n33333333\n44444444\n11111115\n81888888\n44444444\n11111111\n66666666\n33330333\n33333333\n33333333", "5 5\n88888\n44444\n66666\n55555\n88888", "20 19\n1111111111111111111\n5555555555555555555\n0000000000000000000\n3333333333333333333\n1111111111111111111\n2222222222222222222\n4444444444444444444\n5555555555555555555\n0000000000000000000\n4444444444444444444\n0000000000000000000\n5555555555555555555\n7777777777777777777\n9999999999999999999\n2222222222222222222\n4444444444444444444\n1111111111111111111\n6666666666666666666\n7777777777777777777\n2222222222222222222", "1 100\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888", "100 1\n5\n7\n9\n4\n7\n2\n5\n1\n6\n7\n2\n7\n6\n8\n7\n4\n0\n2\n9\n8\n9\n1\n6\n4\n3\n4\n7\n1\n9\n3\n0\n8\n3\n1\n7\n5\n3\n9\n5\n1\n3\n5\n8\n1\n9\n3\n9\n0\n6\n0\n7\n6\n5\n2\n8\n3\n7\n6\n5\n1\n8\n3\n6\n9\n6\n0\n5\n8\n5\n2\n9\n1\n0\n1\n8\n3\n2\n1\n0\n3\n9\n0\n5\n1\n0\n4\n9\n3\n0\n4\n8\n4\n8\n6\n3\n0\n4\n6\n8\n4", "1 1\n2", "1 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111181111111111111111111111", "100 1\n3\n6\n4\n3\n0\n2\n8\n7\n3\n2\n1\n7\n1\n3\n2\n3\n6\n9\n0\n8\n5\n9\n7\n9\n2\n1\n4\n5\n1\n9\n2\n5\n1\n4\n6\n4\n9\n1\n0\n2\n1\n4\n7\n1\n4\n8\n0\n9\n2\n1\n6\n2\n8\n6\n9\n5\n8\n6\n4\n5\n9\n2\n7\n4\n1\n5\n8\n0\n9\n5\n4\n6\n5\n0\n6\n3\n6\n9\n7\n2\n0\n9\n7\n3\n2\n4\n9\n4\n7\n1\n2\n3\n1\n7\n9\n1\n9\n0\n4\n0"], "outputs": ["YES", "NO", "NO", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "NO", "YES"]}
UNKNOWN
PYTHON3
CODEFORCES
284
16ecf492d63595584a0ea1707994c224
Lala Land and Apple Trees
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in *x*<==<=0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing. What is the maximum number of apples he can collect? The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land. The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it. It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0. Output the maximum number of apples Amr can collect. Sample Input 2 -1 5 1 5 3 -2 2 1 4 -1 3 3 1 9 3 5 7 10 Sample Output 1099
[ "n = int(input())\r\n\r\npos = []\r\nneg = []\r\nfor _ in range(n):\r\n xi, ai = map(int,input().split())\r\n if xi > 0:\r\n pos.append((xi, ai))\r\n else:\r\n neg.append((xi, ai))\r\n\r\nlim = min(len(pos), len(neg))\r\n\r\nans = 0\r\n\r\nif len(pos) > len(neg):\r\n for x, a in sorted(pos)[:lim+1]:\r\n ans += a\r\n\r\n for x, a in sorted(neg)[-lim:]:\r\n ans += a\r\nelif len(pos) < len(neg):\r\n for x, a in sorted(pos)[:lim]:\r\n ans += a\r\n\r\n for x, a in sorted(neg)[-lim-1:]:\r\n ans += a\r\nelse:\r\n for x, a in sorted(pos)[:lim]:\r\n ans += a\r\n\r\n for x, a in sorted(neg)[-lim:]:\r\n ans += a\r\n \r\n\r\nprint(ans)\r\n\r\n\r\n", "left = 0\nright = 0\narr = []\nn = int(input())\nfor i in range (n):\n t, v = map(int, input().split(\" \"))\n arr.append([t, v])\n if arr[i][0] < 0:\n left+=1\n else:\n right+=1\n\narr = sorted(arr, key=lambda a: a[0])\n\nsum = 0\nif left < right:\n for i in range(2*left+1):\n sum += arr[i][1]\nelif left == right:\n for i in range(2*left):\n sum += arr[i][1]\nelse:\n for i in range(left-right-1, left+right):\n sum += arr[i][1]\n \nprint(sum)\n\n\n\n", "n = int(input())\np_apples = 0\nn_apples = 0\np_trees = []\nn_trees = []\nfor i in range(n):\n x,a = map(int,input().split())\n if x > 0:\n p_trees.append((x,a))\n else :\n n_trees.append((x,a))\nn_trees.sort(reverse=1,key= lambda x : x[0])\np_trees.sort(key= lambda x : x[0])\n\n# try left\ni= 0\nwhile True :\n if i >= len(n_trees):\n break\n n_apples += n_trees[i][1]\n if i >= len(p_trees):\n break\n n_apples += p_trees[i][1]\n i +=1\n# try right\ni= 0\nwhile True :\n if i >= len(p_trees):\n break\n p_apples += p_trees[i][1]\n if i >= len(n_trees):\n break\n p_apples += n_trees[i][1]\n i +=1\nprint(max(n_apples,p_apples))", "negs = list()\r\npos = list()\r\napple = dict()\r\nmax_sum = 0\r\n\r\nfor x in range(int(input())):\r\n coord, apples = [*map(int, input().split(\" \"))]\r\n apple[coord] = apples\r\n if coord > 0:\r\n pos.append(coord)\r\n else:\r\n negs.append(coord)\r\n\r\npos.sort()\r\nnegs.sort()\r\nnegs.reverse()\r\n\r\nif len(pos) > len(negs):\r\n for coord in pos[:len(negs) + 1] + negs:\r\n max_sum += apple[coord]\r\n\r\nelse:\r\n for coord in negs[:len(pos) + 1] + pos:\r\n max_sum += apple[coord]\r\n\r\nprint(max_sum)", "import sys\n\nn = int(input())\nleft = []\nright = []\nfor i in range(n):\n x, a = map(int, sys.stdin.readline().split()) \n if x < 0:\n left.append((x, a))\n else:\n right.append((x, a))\n\nleft.sort(key=lambda x:x[0], reverse=True)\nright.sort(key=lambda x:x[0])\n\nans = 0\nlength = min(len(left), len(right))\nfor i in range(length):\n ans += left[i][1] + right[i][1]\n\nif len(left) > len(right):\n ans += left[length][1]\nelif len(right) > len(left):\n ans += right[length][1]\n\nprint(ans)\n", "n = int(input()) \r\nl = []\r\nl2 = [] \r\nl3 = []\r\nfor i in range(0,n) : \r\n l.append(list(map(int,input().split(\" \")))) \r\nfor k in l : \r\n if k[0] > 0 : \r\n l2.append(k) \r\n else : \r\n l3.append(k) \r\nl2.sort() \r\ns = 0 \r\nlcv = min(len(l2),len(l3))\r\nl3.sort(reverse=True) \r\nif len(l2) == len(l3) : \r\n for i in range(0,len(l2)) : \r\n s += (l2[i][1] + l3[i][1] )\r\nelif len(l3) > len(l2) : \r\n while lcv >= 0 : \r\n lcv -=1\r\n s += l3[0][1] \r\n l3.pop(0)\r\n if len(l2) == 0 : \r\n break \r\n else : \r\n s+= l2[0][1]\r\n l2.pop(0)\r\nelse : \r\n while lcv >= 0 : \r\n lcv -=1\r\n s += l2[0][1] \r\n l2.pop(0)\r\n if len(l3) == 0 : \r\n break \r\n else : \r\n s+= l3[0][1] \r\n l3.pop(0)\r\n\r\nprint(s)\r\n\r\n\r\n\r\n\r\n\r\n \r\n", "def CMP(x):\r\n return x[0]\r\n\r\nn = int(input())\r\na = []\r\nfor i in range(n):\r\n s = input().split()\r\n a.append([int(s[0]), int(s[1])])\r\na.sort(key=CMP)\r\ncnt_neg = 0\r\nans = 0\r\nfor i in range(n):\r\n if a[i][0] < 0:\r\n cnt_neg += 1\r\n else:\r\n break\r\ncnt_pos = n-cnt_neg\r\n#print(a)\r\n#print(cnt_pos, cnt_neg)\r\ntmp = min(cnt_pos, cnt_neg)\r\nfor i in range(cnt_neg-tmp, cnt_neg):\r\n ans += a[i][1]\r\n#print(ans)\r\nfor i in range(cnt_neg, cnt_neg+tmp):\r\n ans += a[i][1]\r\n#print(ans)\r\nif cnt_pos < cnt_neg:\r\n ans += a[cnt_neg-tmp-1][1]\r\nelif cnt_pos > cnt_neg:\r\n ans += a[cnt_neg+tmp][1]\r\nprint(ans)\r\n", "from sys import stdin, stdout\r\n \r\ndef main():\r\n x_pos = []\r\n x_neg = []\r\n my_dict = {}\r\n \r\n n = int(stdin.readline())\r\n for _ in range(n):\r\n x, a = [int(c) for c in stdin.readline().split()]\r\n my_dict[x] = a\r\n if x > 0:\r\n x_pos.append(x)\r\n else:\r\n x_neg.append(x)\r\n \r\n \r\n x_pos.sort()\r\n x_neg.sort(reverse = True)\r\n \r\n min_length = min(len(x_pos), len(x_neg))\r\n \r\n res = 0\r\n for i in range(min_length):\r\n a_pos = my_dict[x_pos[i]]\r\n a_neg = my_dict[x_neg[i]]\r\n res += (a_pos + a_neg)\r\n \r\n if len(x_pos) > len(x_neg):\r\n a = my_dict[x_pos[min_length]]\r\n res += a\r\n \r\n if len(x_neg) > len(x_pos):\r\n a = my_dict[x_neg[min_length]]\r\n res += a\r\n \r\n stdout.write(str(res)) \r\n \r\n \r\n \r\n \r\n#--------------------------------------------------------\r\n \r\nif __name__ == \"__main__\":\r\n main() ", "n = int(input())\nli = []\np,ne =0,0\nfor _ in range(n):\n\ta,b = map(int,input().split())\n\tli.append([a,b])\n\tif a>0:\n\t\tp+=1\n\telse:\n\t\tne+=1\nli.sort()\nans = 0 \nif ne>p:\n\tli=li[::-1]\n\tfor i in range(min(2*p+1,n)):\n\t\tans+=li[i][1]\nelse:\n\tfor i in range(min(2*ne+1,n)):\n\t\tans+=li[i][1]\nprint(ans)\n", "# Description of the problem can be found at http://codeforces.com/problemset/problem/558/A\r\n\r\nn = int(input())\r\nl_l = list()\r\nl_r = list()\r\n\r\nt_l = 0\r\nt_r = 0\r\n\r\nfor _ in range(n):\r\n x, a = map(int, input().split())\r\n \r\n if abs(x) // x != 1:\r\n t_l += 1\r\n l_l.append([x, a])\r\n else:\r\n t_r += 1\r\n l_r.append([x, a])\r\n\r\nl_r.sort()\r\nl_l.sort(reverse = True)\r\n\r\nif t_l == t_r:\r\n s1 = sum(x[1] for x in l_l)\r\n s2 = sum(x[1] for x in l_r)\r\n print(s1 + s2)\r\nelif t_l < t_r:\r\n s1 = sum(x[1] for x in l_l[:t_l])\r\n s2 = sum(x[1] for x in l_r[:t_l + 1])\r\n print(s1 + s2)\r\nelse:\r\n s1 = sum(x[1] for x in l_l[:t_r + 1])\r\n s2 = sum(x[1] for x in l_r[:t_r])\r\n print(s1 + s2)", "def solve (num,neg,pos,nseq,pseq) :\r\n app = 0\r\n if neg == pos :\r\n for x,y in nseq :\r\n app += y\r\n for x,y in pseq :\r\n app += y\r\n \r\n elif neg > pos :\r\n times = pos \r\n index = 0\r\n while index < pos :\r\n app += pseq[index][1]\r\n index += 1\r\n \r\n index = 0\r\n while index < pos + 1 :\r\n app += nseq[index][1]\r\n index += 1\r\n \r\n else :\r\n times = neg\r\n index = 0\r\n while index < neg :\r\n app += nseq[index][1]\r\n index += 1\r\n \r\n index = 0\r\n while index < neg + 1 :\r\n app += pseq[index][1]\r\n index += 1\r\n \r\n return app\r\n \r\nnum = int(input())\r\np = 0\r\nn = 0\r\npseq = []\r\nnseq = []\r\nfor x in range(num) :\r\n i , j = list(map(int,input().split()))\r\n if i < 0 :\r\n n += 1\r\n nseq.append([i,j])\r\n else :\r\n p += 1\r\n pseq.append([i,j])\r\n \r\npseq.sort(key=lambda i : i[0])\r\nnseq.sort(key=lambda i : i[0],reverse = True)\r\n\r\nprint (solve(num,n,p,nseq,pseq))\r\n \r\n ", "n=int(input())\r\ns=[]\r\nfor i in range(n):\r\n s.append(list(map(int, input().split())))\r\ns=sorted(s)\r\ni=0\r\nwhile i<n:\r\n if s[i][0]>0:\r\n break\r\n i+=1\r\nsr=s[i:]\r\nsl=list(reversed(s[:i]))\r\nansw=0\r\nif len(sr)>len(sl):\r\n for i in range(len(sl)):\r\n answ+= sl[i][1]+sr[i][1]\r\n answ+= sr[len(sl)][1]\r\n print(answ)\r\nelif len(sr)==len(sl):\r\n for i in range(len(sl)):\r\n answ+= sl[i][1]+sr[i][1]\r\n print(answ)\r\nelse:\r\n for i in range(len(sr)):\r\n answ+= sr[i][1]+sl[i][1]\r\n answ+= sl[len(sr)][1]\r\n print(answ)", "pos, neg, nums = {}, {}, 0\r\nfor _ in range(int(input())):\r\n x = [int(i) for i in input().split()]\r\n if x[0] >= 0:pos[x[0]] = x[1]\r\n else:neg[x[0]] = x[1]\r\nif len(pos) > len(neg):\r\n nums += sum(neg.values()) + sum([pos[i] for i in sorted(list(pos.keys()))[:len(neg) + 1]])\r\nelif len(pos) == len(neg):\r\n nums = sum(pos.values()) + sum(neg.values())\r\nelse:\r\n nums += sum(pos.values())+sum([neg[i] for i in sorted(list(neg.keys()), reverse=True)[:len(pos) + 1]])\r\nprint(nums)", "l, r = [], []\r\nfor i in [*open(0)][1:]:\r\n x, v = map(int, i.split())\r\n if x >= 0: r += [(x,v)]\r\n else: l += [(-x,v)]\r\nl.sort()\r\nr.sort()\r\nm = min(map(len, [l, r]))\r\nprint(sum(i[1] for i in l[:m+1]) + sum(i[1] for i in r[:m + 1]))\r\n", "n=int(input())\r\na=[0]*200001\r\nfor i in range(n):\r\n x, h = map(int,input().split())\r\n a[x+100000]=h\r\n\r\nl, r, s = 99999, 100001,0\r\nwhile True:\r\n while l>=0:\r\n if a[l]!=0:\r\n break\r\n else:\r\n l-=1\r\n while r<=200000:\r\n if a[r]!=0:\r\n break\r\n else:\r\n r+=1\r\n if l<0 and r>200000:\r\n break\r\n else:\r\n if l>=0 and r<=200000:\r\n s+=(a[l]+a[r]); l-=1;r+=1\r\n else:\r\n if l<0:\r\n s+=a[r]\r\n else:\r\n s+=a[l]\r\n break\r\nprint(s)\r\n", "n = int(input())\r\nneg = []\r\npos = []\r\nleft_start = 0\r\nright_start = 0\r\n\r\nfor i in range(n):\r\n x, a = [int(i) for i in input().split()]\r\n\r\n if (x < 0):\r\n neg.append((x, a))\r\n elif (x > 0):\r\n pos.append((x, a))\r\n else:\r\n left_start += a\r\n right_start += a\r\n\r\nneg.sort(key=lambda tup: tup[0], reverse=True)\r\npos.sort(key=lambda tup: tup[0])\r\n\r\ni = 0\r\n\r\nwhile True:\r\n try:\r\n left_start += neg[i][1]\r\n left_start += pos[i][1]\r\n\r\n i += 1\r\n except:\r\n break\r\n\r\ni = 0\r\n\r\nwhile True:\r\n try:\r\n right_start += pos[i][1]\r\n right_start += neg[i][1]\r\n\r\n i += 1\r\n except:\r\n break\r\n\r\nprint(max(left_start, right_start))", "l = 0\r\nlc = 0\r\nr = 0\r\nrc = 0\r\nn = int(input())\r\narrl = []\r\narrr = []\r\nfor i in range (n):\r\n a, b = map(int, input().split())\r\n if (a < 0):\r\n arrl.append((-a, b))\r\n else:\r\n arrr.append((a, b))\r\narrr.sort()\r\narrl.sort()\r\nleft = 0\r\nright = 0\r\nif (len(arrr) == len(arrl)):\r\n for i in range(min(len(arrr), len(arrl))):\r\n left += (arrr[i][1] + arrl[i][1])\r\nelif (len(arrr) < len(arrl)):\r\n for i in range(min(len(arrr), len(arrl))):\r\n left += (arrr[i][1] + arrl[i][1])\r\n left += arrl[len(arrr)][1]\r\nelse:\r\n for i in range(min(len(arrr), len(arrl))):\r\n left += (arrr[i][1] + arrl[i][1])\r\n left += arrr[len(arrl)][1]\r\n \r\nprint(left)\r\n ", "# HEY STALKER\r\nn = int(input())\r\nl = []\r\nneg = 0\r\npos = 0\r\nfor t in range(n):\r\n x, y = map(int, input().split())\r\n if x < 0:\r\n neg += 1\r\n else:\r\n pos += 1\r\n l.append([x, y])\r\nans = 0\r\nif pos == neg:\r\n for t in l:\r\n ans += t[1]\r\n print(ans)\r\nelse:\r\n l.sort()\r\n if pos < neg:\r\n for t in range(n-1, -1, -1):\r\n if l[t][0] > 0:\r\n ans += l[t][1]\r\n else:\r\n if pos > -1:\r\n ans += l[t][1]\r\n pos -= 1\r\n else:\r\n for t in range(n):\r\n if l[t][0] < 0:\r\n ans += l[t][1]\r\n else:\r\n if neg > -1:\r\n ans += l[t][1]\r\n neg -= 1\r\n print(ans)\r\n\r\n", "n = int(input())\r\nneg = []\r\npos = []\r\n\r\nfor i in range(n):\r\n inp = input().split()\r\n x = int(inp[0])\r\n a = int(inp[1])\r\n if x < 1:\r\n neg += [[-x, a]]\r\n else:\r\n pos += [[x,a]]\r\n\r\nneg = sorted(neg)\r\npos = sorted(pos)\r\nne = len(neg)\r\np = len(pos)\r\nnum = ne\r\nlonger = pos\r\nnotsame = True\r\n\r\nif ne > p:\r\n num = p\r\n longer = neg\r\nelif ne == p:\r\n notsame = False\r\n\r\na = 0\r\nfor i in range(num):\r\n a += pos[i][1]\r\n a += neg[i][1]\r\nif notsame:\r\n a += longer[num][1]\r\n\r\nprint(a)", "n = int(input())\r\nleft = {}\r\nright = {}\r\nres = 0\r\nfor i in range (n):\r\n x, a = [int(y) for y in input().split()]\r\n if x < 0:\r\n left[x] = a\r\n else:\r\n right[x] = a\r\ngoLeft = False\r\nif len(left) > len(right):\r\n goLeft = True\r\nwhile (goLeft == True and len(left) != 0) or (goLeft == False and len(right) != 0):\r\n if goLeft:\r\n k = max(left.keys())\r\n res += left[k]\r\n left.pop(k)\r\n else:\r\n k = min(right.keys())\r\n res += right[k]\r\n right.pop(k)\r\n goLeft = not goLeft\r\nprint(res)", "#!/usr/bin/env python\r\n# -*- coding: utf-8 -*-\r\n\r\nn = int(input())\r\nLeft = []\r\nRight = []\r\nfor i in range(n):\r\n t = list(map(int,input().split()))\r\n if t[0] < 0 :Left.append(t) \r\n if t[0] > 0 :Right.append(t)\r\n\r\nnum = min(len(Left),len(Right))\r\n\r\nRight = [a[1] for a in sorted(Right,key=lambda x:x[0])]\r\nLeft = [a[1] for a in sorted(Left,key=lambda x:-x[0])]\r\n\r\nif len(Left) < len(Right):\r\n ans = sum(Right[:num+1] + Left[:num])\r\nelif len(Left) > len(Right):\r\n ans = sum(Right[:num] + Left[:num+1])\r\nelse:\r\n ans = sum(Right[:num] + Left[:num])\r\nprint(ans)\r\n\r\n", "n=int(input())\r\na=dict()\r\nb=dict()\r\nc=0\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n if(x<0):\r\n a.update({x:y})\r\n else:\r\n b.update({x:y})\r\nif(len(a)>len(b)):\r\n for i in range(len(b)+1):\r\n c+=a[max(a.keys())]\r\n del a[max(a.keys())]\r\n print(c+sum(b.values()))\r\nelif(len(a)==len(b)):\r\n print(sum(a.values())+sum(b.values()))\r\nelse:\r\n for i in range(len(a)+1):\r\n c+=b[min(b.keys())]\r\n del b[min(b.keys())]\r\n print(c+sum(a.values()))", "#!/usr/bin/env python3\n\nimport sys\n\nN = int(input())\n\napples = []\n\nfor n in range(N):\n a, b = input().split(' ')\n a, b = int(a), int(b)\n apples.append((a, b))\n\napples.sort()\n\napples_left = [(a, b) for a, b in apples if a < 0]\napples_right = [(a, b) for a, b in apples if a > 0]\n\nlen_left = len(apples_left)\nlen_right = len(apples_right)\n\nif (len_left == len_right):\n print(sum(b for a, b in apples))\n sys.exit(0)\n\nif (len_left < len_right):\n # go right\n ans = 0\n ans += sum(b for a, b in apples_left)\n ans += sum(b for a, b in apples_right[:len_left + 1])\n print(ans)\n sys.exit(0)\n\nif (len_left > len_right):\n # go left\n ans = 0\n ans += sum(b for a, b in apples_right)\n ans += sum(b for a, b in apples_left[-len_right-1:])\n print(ans)\n sys.exit(0)", "n = int(input())\ntreesR = []\ntreesL = []\n \nfor i in range(n):\n x,a = input().split()\n x = int(x)\n a = int(a)\n if x<0:\n treesL.append((x,a))\n else:\n treesR.append((x,a))\n \ntreesL = sorted(treesL,key = lambda tup:(-tup[0]))\ntreesR = sorted(treesR)\n\nsoma = 0\ntamR = len(treesR)\ntamL = len(treesL)\n\nif tamR == tamL:\n for i in range(tamR):\n soma += treesR[i][1] + treesL[i][1]\nelif tamR > tamL:\n for i in range(tamL):\n soma += treesR[i][1] + treesL[i][1]\n soma += treesR[tamL][1]\nelif tamR < tamL:\n for i in range(tamR):\n soma += treesR[i][1] + treesL[i][1]\n soma += treesL[tamR][1]\n\nprint(soma) ", "n = int(input())\r\nA = []\r\nB = []\r\nalen = 0\r\nblen = 0\r\nres = 0\r\nfor _ in range(n):\r\n x, a = map(int, input().split())\r\n if x < 0:\r\n A.append((-x, a))\r\n alen += 1\r\n else:\r\n B.append((x, a))\r\n blen += 1\r\nA.sort()\r\nB.sort()\r\nmn = min(alen, blen)\r\nfor i in range(mn):\r\n res += A[i][1] + B[i][1]\r\nif mn < alen:\r\n res += A[mn][1]\r\nelif mn < blen:\r\n res += B[mn][1]\r\nprint(res)# 1698085117.2104998", "n = int(input())\nnumpos = 0\nnumneg = 0\nposlist = []\nneglist = []\nanswer = 0\nfor i in range(n):\n x, a = (int(y) for y in input().split())\n if x > 0:\n numpos += 1\n poslist.append([x,a])\n else:\n numneg += 1\n neglist.append([-x,a])\nposlist.sort(key = lambda x: x[0])\nneglist.sort(key = lambda x: x[0])\nif numpos == numneg:\n # Take them all\n for i in range(len(poslist)):\n answer += poslist[i][1] + neglist[i][1]\n print (answer)\nelif numpos > numneg:\n # Take all of the negatives and n+1 of the positives\n for i in range(len(neglist)):\n answer += neglist[i][1]\n for i in range(len(neglist) + 1):\n answer += poslist[i][1]\n print (answer)\nelse: # Take all of the positives and n+1 of the negatives\n for i in range(len(poslist)):\n answer += poslist[i][1]\n for i in range(len(poslist) + 1):\n answer += neglist[i][1]\n print (answer)\n \n \n \n", "n = int(input())\r\na = []\r\nb = []\r\nfor _ in range(n):\r\n x, y = map(int, input().split())\r\n if x < 0:\r\n a.append([-x, y])\r\n else:\r\n b.append([x, y])\r\na = sorted(a)\r\nb = sorted(b)\r\nk = min(len(a), len(b))\r\nss = 0\r\nfor i in range(k):\r\n ss += a[i][1] + b[i][1]\r\nif len(a) > k:\r\n ss += a[k][1]\r\nif len(b) > k:\r\n ss += b[k][1]\r\nprint(ss)\r\n", "n=int(input())\r\n\r\np=[]\r\n\r\nfor i in range(n):\r\n\tp.append(list(map(int,(input().split()))))\r\nd={}\r\n\r\nfor i,j in p:\r\n\td[i]=j\r\n\r\nnegitive=[]\r\npositive=[]\r\nfor i,j in p:\r\n\tif i>0:\r\n\t\tpositive.append(i)\r\n\telse:\r\n\t\tnegitive.append(i)\r\nz=min(len(negitive),len(positive))\r\n\r\nnegitive.sort(reverse=True)\r\npositive.sort()\r\n\r\nsum=0\r\nif len(negitive)>len(positive):\r\n\tfor i in range(z+1):\r\n\t\tsum+=d[negitive[i]]\r\n\tfor i in range(z):\r\n\t\tsum+=d[positive[i]]\r\n\r\n\r\nelif len(positive)>len(negitive):\r\n\tfor i in range(z):\r\n\t\tsum+=d[negitive[i]]\r\n\tfor i in range(z+1):\r\n\t\tsum+=d[positive[i]]\r\nelse:\r\n\tfor i in range(z):\r\n\t\tsum+=d[negitive[i]]\r\n\tfor i in range(z):\r\n\t\tsum+=d[positive[i]]\r\nprint(sum)", "n = int(input())\r\nleft = []\r\nright = []\r\n\r\nfor _ in range(n):\r\n p,v = list(map(int, input().split()))\r\n\r\n if p < 0:\r\n left.append((p,v))\r\n else:\r\n right.append((p, v))\r\n \r\nleft.sort(key=lambda pair: pair[0], reverse = True)\r\nright.sort(key=lambda pair: pair[0])\r\n\r\nif len(left) == 0:\r\n print(right[0][1])\r\nelif len(right) == 0:\r\n print(left[0][1])\r\nelse:\r\n ans = 0\r\n i = 0\r\n j = 0\r\n while True:\r\n ans += left[i][1]\r\n ans += right[j][1]\r\n\r\n i += 1\r\n j += 1\r\n\r\n if i >= len(left):\r\n if j < len(right):\r\n ans += right[j][1]\r\n break\r\n\r\n if j >= len(right):\r\n if i < len(left):\r\n ans += left[i][1]\r\n break\r\n print(ans)", "n = int(input())\r\nx_positive = []\r\nx_negative = []\r\n\r\nfor i in range(n):\r\n x,a = map(int,input().split())\r\n if x>0:\r\n x_positive.append([x,a])\r\n else:\r\n x_negative.append([x,a])\r\n\r\nx_positive.sort()\r\nx_negative.sort()\r\n\r\ntotal_apples = 0\r\n\r\n# a = min(len(x_negative), len(x_positive))\r\n\r\nb = len(x_negative)\r\na = len(x_positive)\r\n\r\nif a>b:\r\n for i in range(b):\r\n total_apples = total_apples + x_positive[i][1] + x_negative[-i-1][1]\r\n\r\n total_apples+=x_positive[b][1]\r\nelif a==b:\r\n for i in range(b):\r\n total_apples = total_apples + x_positive[i][1] + x_negative[-i-1][1]\r\n\r\nelif b>a:\r\n for i in range(a):\r\n total_apples = total_apples + x_positive[i][1] + x_negative[-i-1][1]\r\n\r\n total_apples+=x_negative[-a-1][1]\r\n\r\nprint(total_apples)", "n = int(input())\npos = []\nneg = []\nfor i in range(n):\n\tx, y = (int(x) for x in input().split())\n\tif x < 0:\n\t\tneg.append((x, y))\n\telse:\n\t\tpos.append((x, y))\npos.sort()\nneg.sort(reverse=True)\nans = [0, 0]\nfor i in range(len(pos)):\n\tans[0] += pos[i][1]\n\tif i == len(neg):\n\t\tbreak\n\tans[0] += neg[i][1]\nfor i in range(len(neg)):\n\tans[1] += neg[i][1]\n\tif i == len(pos):\n\t\tbreak\n\tans[1] += pos[i][1]\nprint(max(ans))\n", "left_trees, right_trees = [], []\r\n\r\nfor _ in range(int(input())):\r\n x, a = map(int, input().split())\r\n if x < 0:\r\n left_trees.append((x, a))\r\n else:\r\n right_trees.append((x, a))\r\n\r\nleft_trees.sort(reverse=True)\r\nright_trees.sort()\r\nn = min(len(left_trees), len(right_trees)) + 1\r\n\r\nprint(sum(a for x, a in left_trees[:n] + right_trees[:n]))", "A = []\r\nB = []\r\n\r\nfor i in range(int(input())):\r\n a=input().split()\r\n if int(a[0]) > 0:\r\n B.append(a)\r\n\r\n\r\n else:\r\n A.append(a)\r\n\r\n\r\n\r\nA.sort(key =lambda x: (-int(x[0])))\r\nB.sort(key = lambda x: (int(x[0])))\r\n\r\nanswer = 0\r\nif len(A) > len(B):\r\n i=-1\r\n for i in range(len(B)):\r\n answer+= int(B[i][1])\r\n answer+= int(A[i][1])\r\n\r\n print(answer+int(A[i+1][1]))\r\nelif len(B) > len(A):\r\n i = -1\r\n for i in range(len(A)):\r\n answer+= int(A[i][1])\r\n answer+= int(B[i][1])\r\n\r\n print(answer+int(B[i+1][1]))\r\nelse:\r\n\r\n for i in range(len(B)):\r\n answer+= int(A[i][1])\r\n answer+= int(B[i][1])\r\n\r\n print(answer)", "def process(A):\r\n n = len(A)\r\n A2 = [[], []]\r\n for i in range(n):\r\n x, a = A[i]\r\n if x > 0:\r\n A2[0].append([x, a])\r\n else:\r\n A2[1].append([abs(x), a])\r\n A2[0].sort()\r\n A2[1].sort()\r\n m1 = len(A2[0])\r\n m2 = len(A2[1])\r\n # print(A2, m1, m2)\r\n if m1==m2:\r\n return sum([x[1] for x in A2[0]])+sum([x[1] for x in A2[1]])\r\n elif m1 > m2:\r\n return sum([x[1] for x in A2[0][:m2+1]])+sum([x[1] for x in A2[1]])\r\n else:\r\n return sum([x[1] for x in A2[0]])+sum([x[1] for x in A2[1][:m1+1]])\r\n \r\n\r\nn = int(input())\r\nA = []\r\nfor i in range(n):\r\n x, a = [int(x) for x in input().split()]\r\n A.append([x, a])\r\nprint(process(A))", "import bisect\r\n\r\nn = int(input())\r\nt = sorted(tuple(map(int, input().split())) for i in range(n))\r\nb = bisect.bisect_left(t, (0, 0))\r\nl = min(b, n - b) + 1\r\nres = 0\r\nfor i in range(l):\r\n if b + i < n:\r\n res += t[b + i][1]\r\n if b - i - 1 >= 0:\r\n res += t[b - i - 1][1]\r\nprint(res)", "def takeFirst(elem):\n if(elem[0] < 0):\n return -1*elem[0]\n else:\n return elem[0]\n\nn = int(input())\nneg_trees = []\npos_trees = []\nfor i in range(n):\n tree = input()\n pos, apples = tree.split()\n pos = int(pos)\n apples = int(apples)\n if(pos < 0):\n neg_trees.append([pos, apples])\n else:\n pos_trees.append([pos, apples])\nneg_trees = sorted(neg_trees, key=takeFirst)\npos_trees = sorted(pos_trees, key=takeFirst)\nsoma = 0\nif(len(pos_trees) > len(neg_trees)):\n turn = True\n while(neg_trees != []):\n if(turn):\n soma += pos_trees.pop(0)[1]\n turn = False\n else:\n soma += neg_trees.pop(0)[1]\n turn = True\n if(turn):\n soma += pos_trees.pop(0)[1]\nelif(len(pos_trees) < len(neg_trees)):\n turn = True\n while(pos_trees != []):\n if(turn):\n soma += neg_trees.pop(0)[1]\n turn = False\n else:\n soma += pos_trees.pop(0)[1]\n turn = True\n if(turn):\n soma += neg_trees.pop(0)[1]\nelse:\n while(pos_trees != []):\n soma += neg_trees.pop(0)[1] + pos_trees.pop(0)[1]\nprint(soma)\n\t\t\t \t\t\t \t\t \t \t\t\t \t \t", "n = int(input())\r\npos = []\r\nneg = []\r\nres = 0\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n if x < 0:\r\n neg.append([x, y])\r\n else:\r\n pos.append([x, y])\r\npos.sort()\r\nneg.sort(reverse = True)\r\n\r\nwhile len(pos) > 0 and len(neg) > 0:\r\n res += pos[0][1] + neg[0][1]\r\n neg.pop(0)\r\n pos.pop(0)\r\n\r\nif len(pos) > 0:\r\n res += pos[0][1]\r\nelif len(neg) > 0:\r\n res += neg[0][1]\r\n\r\nprint(res)\r\n \r\n ", "n = int(input())\n\nyp = []\nyn = []\n\ndef kfp(y):\n return y[0]\n\ndef kfn(y):\n return -y[0]\n\nfor i in range(n):\n x, a = input().split()\n if int(x) < 0:\n yn += [[int(x), int(a)]]\n else:\n yp += [[int(x), int(a)]]\n\nyp.sort(key = kfp)\nyn.sort(key = kfn)\n\n#print(yp)\n#print(yn)\n\nc = 0\nm = min(len(yp), len(yn))\nfor i in range(m):\n c += yp[i][1] + yn[i][1]\n\nif len(yp) > m:\n c += yp[m][1]\nelif len(yn) > m:\n c += yn[m][1]\n\nprint(c)\n", "n = int(input())\r\na = [[(1000000, 0)], [(100000, 0)]]\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n a[x > 0].append((abs(x), y))\r\nprint(sum(x[1] + y[1] for x, y in zip(*map(sorted, a))))\r\n", "def solve(first, second):\r\n ans = 0\r\n first.sort()\r\n second.sort()\r\n while True:\r\n if len(first) == 0:\r\n break\r\n _, a_i = first[0]\r\n ans += a_i\r\n first = first[1:]\r\n if len(second) == 0:\r\n break\r\n _, a_i = second[0]\r\n ans += a_i\r\n second = second[1:]\r\n\r\n return ans\r\n\r\nn = int(input())\r\nleft = []\r\nright = []\r\nfor i in range(n):\r\n t = tuple(map(int, input().split(\" \")))\r\n if t[0] > 0:\r\n right.append(t)\r\n else:\r\n left.append((-t[0], t[1]))\r\n\r\nprint(max(solve(left, right), solve(right, left)))\r\n", "n = int(input())\n\na = []\nb = []\n\nfor i in range(n):\n\tx,y = map(int,input().split())\n\tif x >= 0:\n\t\ta.append((x,y))\n\telse:\n\t\tb.append((x,y))\n\na.sort(key=lambda tup:tup[0])\nb.sort(key=lambda tup:tup[0])\nb = b[::-1]\n\nminLength = min(len(a),len(b))\n\ntotal = 0\n\nfor i in range(minLength):\n\ttotal += b[i][1] + a[i][1]\n\nif(len(a) > minLength):\n\ttotal += a[minLength][1]\nelif(len(b) > minLength):\n\ttotal += b[minLength][1]\n\nprint(total)", "n=int(input())\r\nneg,pos=[],[]\r\ndef bubble(items):\r\n count=len(items)-1\r\n for i in range(len(items)):\r\n for l in range(0,count):\r\n if(items[l][0])>items[l+1][0]:\r\n items[l],items[l+1]=items[l+1],items[l]\r\n count-=1\r\n return items\r\nfor i in range(n):\r\n x,y=list(map(int,input().split()))\r\n if x>0:\r\n pos.append([x,y])\r\n else:\r\n neg.append([x,y])\r\npos=bubble(pos)\r\nneg=list(reversed(bubble(neg)))\r\napples=0\r\nif len(pos)>len(neg):\r\n for i in neg : apples+=i[1]\r\n for i in pos[0:len(neg)+1] : apples+=i[1]\r\nelif len(pos)<len(neg):\r\n for i in pos : apples+=i[1]\r\n for i in neg[0:len(pos)+1] : apples+=i[1]\r\nelse:\r\n for i in pos : apples+=i[1]\r\n for i in neg : apples+=i[1]\r\nprint(apples)\r\n", "import sys\ninput = sys.stdin.readline\n\n############ ---- Input Functions ---- ############\ndef inp(): # int\n return(int(input()))\ndef inlt(): # list\n return(list(map(int,input().split())))\ndef insr(): # string as char list\n s = input()\n return(list(s[:len(s) - 1]))\ndef instr(): # string\n return input()\ndef invr(): # spaced ints\n return(map(int,input().split()))\n\nn = inp()\nless = []\ngreater = []\nfor i in range(n):\n xi, ai = list(invr())\n if xi < 0:\n less.append((xi, ai))\n else:\n greater.append((xi, ai))\nless.sort()\ngreater.sort()\nsum = 0\nif len(less) <= len(greater):\n for xi, ai in less:\n sum += ai\n for i in range(min(len(less) + 1, len(greater))):\n sum += greater[i][1]\nelse:\n for xi, ai in greater:\n sum += ai\n for i in range(len(greater) + 1):\n sum += less[len(less) -1 - i ][1]\nprint(sum)\n", "\"\"\"\r\n\r\ncreated by huash06 at 2015-07-14\r\n\r\n\"\"\"\r\n__author__ = 'huash06'\r\n\r\nimport os\r\nimport sys\r\nimport functools\r\nimport collections\r\nimport itertools\r\n\r\n# sys.stdin = open(\"input.txt\", \"r\")\r\n\r\n\r\ndef collectApple(tree):\r\n if not tree:\r\n return 0\r\n left = sorted(filter(lambda x: x[0] < 0, tree))\r\n right = sorted(filter(lambda x: x[0] > 0, tree))\r\n\r\n res = 0\r\n if len(left) > len(right):\r\n res += sum([x[1] for x in right])\r\n res += sum([x[1] for x in left[len(left) - len(right) - 1:]])\r\n else:\r\n res += sum([x[1] for x in left])\r\n res += sum([x[1] for x in right[:min(len(left)+1, len(right))]])\r\n return res\r\n\r\n\r\nN = int(input())\r\n\r\ntree = []\r\nfor i in range(N):\r\n tree.append([int(x) for x in input().split()])\r\nprint(collectApple(tree))\r\n\r\n\r\n\r\n\r\n", "import bisect\r\n\r\nn = int(input())\r\nt = sorted(tuple(map(int, input().split())) for i in range(n))\r\nb = bisect.bisect_left(t, (0, 0))\r\nl = min(b, n - b) + 1\r\nprint(sum((t[b + i][1] if b + i < n else 0) + (t[b - i - 1][1] if b - i - 1 >= 0 else 0) for i in range(l)))", "class Tree:\n def __init__(self, idx, apples):\n self.idx = idx\n self.apples = apples\n\n\ndef main():\n n = int(input())\n\n left = []\n right = []\n\n for i in range(n):\n x, a = map(int, input().split())\n\n if x < 0:\n left.append(Tree(x, a))\n\n else:\n right.append(Tree(x, a))\n\n left.sort(reverse=True, key=lambda x: x.idx)\n right.sort(key=lambda x: x.idx)\n\n min_len = min(len(left), len(right))\n\n if len(left) == 0:\n print(right[0].apples)\n\n elif len(right) == 0:\n print(left[0].apples)\n\n else:\n total = 0\n i = 0\n while i < min_len:\n total += left.pop(0).apples + right.pop(0).apples\n i += 1\n\n if left:\n total += left.pop(0).apples\n if right:\n total += right.pop(0).apples\n\n print(total)\n\n\nmain()\n", "n = int(input())\n\napples = {}\nxAxisN = []\nxAxisP = []\nfor i in range(n):\n\tx, apple = map(int, input().split())\n\tapples[x] = apple\n\tif(x>0):\n\t\txAxisP.append(x)\n\telse : \n\t\txAxisN.append(x)\nxAxisN = sorted(xAxisN)\nxAxisP = sorted(xAxisP)\n\nchoosing = min(len(xAxisP), len(xAxisN))\n\nneg = 0\npos = 0\nif len(xAxisN)<len(xAxisP):\n\tfor i in range(0, choosing):\n\t\tneg+=apples[xAxisN[i]]\n\tfor j in range(0, choosing+1):\n\t\tpos+=apples[xAxisP[j]]\n\tprint(pos+neg)\nelif len(xAxisN)>len(xAxisP):\n\tfor i in range(0, choosing):\n\t\tneg+=apples[xAxisP[i]]\n\tfor j in range(len(xAxisN)-len(xAxisP)-1, len(xAxisN)):\n\t\tpos+=apples[xAxisN[j]]\n\tprint(pos+neg)\nelse :\n\tfor i in range(0, choosing):\n\t\tneg+=apples[xAxisN[i]]\n\tfor j in range(0, choosing):\n\t\tpos+=apples[xAxisP[j]]\n\tprint(pos+neg)\n", "def lala_land(l):\r\n #s=sorted(l,key=lambda x: x[0])\r\n count_negatives=0\r\n count_positives=0\r\n negatives=[]\r\n positives=[]\r\n for i in range(len(l)):\r\n if l[i][0]<0:\r\n count_negatives+=1\r\n negatives.append(l[i])\r\n \r\n else:\r\n count_positives+=1\r\n positives.append(l[i])\r\n sorted_neg=sorted(negatives,key=lambda x: x[0],reverse=True)\r\n sorted_pos=sorted(positives,key=lambda x: x[0])\r\n neg_values=[]\r\n pos_values=[]\r\n for i in range(len(sorted_neg)):\r\n neg_values.append(sorted_neg[i][1])\r\n for j in range(len(sorted_pos)):\r\n pos_values.append(sorted_pos[j][1])\r\n \r\n if count_positives==count_negatives:\r\n result=sum(neg_values)+sum(pos_values)\r\n elif count_positives > count_negatives:\r\n sum_pos=0\r\n for p in range(0,count_negatives+1):\r\n sum_pos+=pos_values[p]\r\n result=sum(neg_values)+sum_pos\r\n else:\r\n sum_neg=0\r\n for n in range(0,count_positives+1):\r\n sum_neg+=neg_values[n]\r\n result=sum(pos_values)+sum_neg\r\n print (result)\r\n \r\n\r\nn=int(input())\r\nl=[]\r\nfor i in range(n):\r\n l.append([int(x) for x in input().split()])\r\nlala_land(l)\r\n ", "l=[];r=[]\r\nfor s in[*open(0)][1:]:\r\n x,v=map(int,s.split())\r\n if x<0:l+=[(-x,v)]\r\n else:r+=[(x,v)]\r\nl=sorted(l)\r\nr=sorted(r)\r\nm=min(map(len,[l,r]))\r\nprint(sum(x[1]for x in l[:m+1])+sum(x[1]for x in r[:m+1]))", "t = [[[100001, 0]], [[100001, 0]]]\r\nfor i in range(int(input())):\r\n x, a = map(int, input().split())\r\n t[x > 0].append([abs(x), a])\r\nt[0].sort()\r\nt[1].sort()\r\nprint(sum(t[0][i][1] + t[1][i][1] for i in range(min(len(t[0]), len(t[1])))))", "a={}\r\nb={}\r\nfor i in range(int(input())):\r\n c,d=map(int,input().split())\r\n if c<0:b[c]=d\r\n else:a[c]=d\r\nif len(a)<len(b):\r\n print(sum(a[i]for i in sorted(a.keys())[:len(a)])+sum(b[i]for i in sorted(b.keys(),reverse=True)[:len(a)+1]))\r\nelse:print(sum(b[i]for i in sorted(b.keys(),reverse=True)[:len(b)])+sum(a[i]for i in sorted(a.keys())[:len(b)+1]))\r\n", "def main():\n n = int(input())\n l = list(tuple(map(int, input().split())) for _ in range(n))\n l.append((0, 0))\n l.sort()\n start = l.index((0, 0)) * 2\n lo, hi = 0, n + 1\n if start > n:\n lo = start - n - 1\n elif start < n - 1:\n hi = start + 2\n print(sum(a for _, a in l[lo:hi]))\n\n\nif __name__ == \"__main__\":\n main()\n", "n = int(input())\r\nl = []\r\nr = []\r\nfor i in range(n):\r\n p, c = map(int, input().split())\r\n if p < 0:\r\n l.append((p, c))\r\n else:\r\n r.append((p, c))\r\nl = sorted(l)[::-1]\r\nr = sorted(r)\r\nanw = 0\r\nif len(l) == len(r):\r\n for i in range(len(l)):\r\n anw += l[i][1] + r[i][1]\r\nelse:\r\n if len(l) < len(r):\r\n l, r = r, l\r\n for i in range(len(r)):\r\n anw += l[i][1] + r[i][1]\r\n anw += l[len(r)][1]\r\n \r\nprint(anw)", "a, b = [], []\r\nn = int(input())\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n if x < 0:\r\n a += [(x,y)]\r\n else:\r\n b += [(x,y)]\r\na.sort()\r\nb.sort()\r\na = a[::-1]\r\nres = 0\r\nwhile len(a) > 0 and len(b) > 0:\r\n res += a[0][1] + b[0][1]\r\n a, b = a[1:], b[1:]\r\nif len(a) > 0:\r\n res += a[0][1]\r\nif len(b) > 0:\r\n res += b[0][1]\r\nprint(res)\r\n", "n = int(input())\r\nleft = [0] * (1 + 10**5)\r\nright = [0] * (1 + 10**5)\r\nl,r = 0,0\r\nfor x in range(n):\r\n p,v = map(int,input().split())\r\n if p<0: \r\n left[-1*p] = v\r\n l += 1\r\n else:\r\n right[p] = v\r\n r += 1\r\n\r\nm = min(l,r)\r\nsteps_l = min(l,m+1)\r\nsteps_r = min(r,m+1)\r\nprint (sum([x for x in left if x][:steps_l] + [x for x in right if x][:steps_r] ))", "import math\r\n\r\ndef _input(): return map(int, input().split())\r\n\r\nn = int(input())\r\na = []; b = []\r\nres = 0\r\nfor _ in range(n):\r\n i, j = _input()\r\n if i<0: a.append((-i,j))\r\n elif i>0: b.append((i,j))\r\n else: res+=j\r\n\r\na.sort(); b.sort()\r\nla = len(a); lb = len(b)\r\nif la>lb+1: la=lb+1\r\nelif lb>la+1: lb=la+1\r\n\r\nfor i in range(la): res+=a[i][1]\r\nfor i in range(lb): res+=b[i][1]\r\nprint(res)\r\n \r\n ", "n = int(input())\n\ndata = list()\nfor i in range(n):\n a, b = list(map(int, input().split()))\n data.append((a, b))\n\na = [(x, y) for x, y in data if x <0]\nb = [(x, y) for x, y in data if x >=0]\n\na.sort(reverse=True)\nb.sort()\n\ntotal = 0\n\nfor ((ax, ay), (bx, by)) in zip(a, b):\n total += ay + by\n\nla = len(a)\nlb = len(b)\n\nif la > lb:\n total += a[lb][1]\nelif lb > la:\n total += b[la][1]\nelse:\n pass\n\n\nprint(total)\n", "n = int(input())\r\narr = [list(map(int, input().split())) for i in range(n)]\r\n\r\na = set()\r\nb = set()\r\nfor i in range(n):\r\n if arr[i][0] > 0:\r\n a.add((arr[i][0], arr[i][1]))\r\n else:\r\n b.add((arr[i][0], arr[i][1]))\r\n \r\na = sorted(list(a))\r\nb = sorted(list(b), reverse = True)\r\n\r\nL = min(len(a), len(b))\r\ns = 0\r\nfor i in range(L + 1):\r\n if i == L:\r\n if len(b) > L:\r\n s += b[i][1]\r\n elif len(a) > L:\r\n s += a[i][1]\r\n else:\r\n s += a[i][1] + b[i][1]\r\n\r\nprint(s)", "n=int(input())\r\nLp=[]\r\nLn=[]\r\nfor i in range(n):\r\n x=list(map(int,input().split()))\r\n if x[0]>0:\r\n Lp.append(x)\r\n else:\r\n x[0]=abs(x[0])\r\n Ln.append(x)\r\nLp.sort()\r\nLn.sort()\r\nm=min(len(Lp),len(Ln))\r\nif len(Ln)<len(Lp):\r\n s=Lp[m][1]\r\n for i in range(m):\r\n s=s+Lp[i][1]+Ln[i][1]\r\nelif len(Ln)>len(Lp):\r\n s=Ln[m][1]\r\n for i in range(m):\r\n s=s+Lp[i][1]+Ln[i][1]\r\nelse:\r\n s=0\r\n for i in range(m):\r\n s=s+Lp[i][1]+Ln[i][1]\r\nprint(s)\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=I()\r\n neg=[]\r\n pos=[]\r\n for _ in range(n):\r\n x,y=IA()\r\n if x<0:\r\n neg.append((x,y))\r\n else:\r\n pos.append((x,y))\r\n neg.sort(reverse=True)\r\n pos.sort()\r\n mi=min(len(neg), len(pos))\r\n if mi==0:\r\n if not neg:\r\n return pos[0][1]\r\n else:\r\n return neg[0][1]\r\n else:\r\n c=0\r\n i=0\r\n while i<mi:\r\n c+=neg[i][1]\r\n c+=pos[i][1]\r\n i+=1\r\n if i <= len(neg)-1:\r\n c+=neg[i][1]\r\n if i <= len(pos)-1:\r\n c+=pos[i][1]\r\n return c\r\n \r\n \r\nif __name__ == '__main__':\r\n print(main())", "x=int(input())\r\nlst=[[int(j) for j in input().split()] for i in range(x)]\r\nn,p=[],[]\r\nfor k in range(x):\r\n if lst[k][0]<0:\r\n n.append(lst[k])\r\n else:\r\n p.append(lst[k])\r\nn.sort(key=lambda x:x[0], reverse=True)\r\np.sort(key=lambda x:x[0])\r\nlength=min(len(n),len(p))\r\nsm=0\r\nfor i in range(length):\r\n sm+=n[i][1]\r\n sm+=p[i][1]\r\nif len(n)>length:\r\n sm+=n[length][1]\r\nif len(p)>length:\r\n sm+=p[length][1]\r\nprint(sm)\r\n\r\n\r\n\r\n\r\n\r\n", "n=int(input())\r\nx=[]\r\ny=[]\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n if a<0:\r\n x.append([a,b])\r\n else:\r\n y.append([a,b])\r\nx.sort(key=lambda i:i[0],reverse=True)\r\ny.sort(key=lambda i:i[0])\r\nm=min(len(x),len(y))\r\na=0\r\nfor i in range(min(m+1,len(x))):\r\n a+=x[i][1]\r\nfor i in range(min(m+1,len(y))):\r\n a+=y[i][1]\r\nprint(a)", "r = lambda: input()\r\nri = lambda: int(r())\r\nrr = lambda: map(int, r().split())\r\nrl = lambda: list(rr())\r\n\r\nn = ri()\r\narr = [rl() for i in range(n)]\r\n\r\na = set()\r\nb = set()\r\nfor i in range(n):\r\n if arr[i][0] > 0:\r\n a.add((arr[i][0], arr[i][1]))\r\n else:\r\n b.add((arr[i][0], arr[i][1]))\r\n \r\na = sorted(list(a))\r\nb = sorted(list(b), reverse = True)\r\n\r\nL = min(len(a), len(b))\r\ns = 0\r\nfor i in range(L + 1):\r\n if i == L:\r\n if len(b) > L:\r\n s += b[i][1]\r\n elif len(a) > L:\r\n s += a[i][1]\r\n else:\r\n s += a[i][1]\r\n s += b[i][1]\r\n\r\nprint(s)", "'''input\n1\n1 1\n'''\ni = int(input())\nn, p, t = 0, 0, {}\nfor _ in range(i):\n\tx, a = map(int, input().split())\n\tif x > 0:\n\t\tp += 1\n\telse:\n\t\tn += 1\n\tt[x] = a\nif n == p:\n\tprint(sum(t.values()))\nelif n < p:\n\ts = sorted(t)\n\ts = s[:2*n+1]\n\tprint(sum([t[i] for i in s]))\nelse:\n\ts = sorted(t)\n\ts = s[n-p-1:]\n\tprint(sum([t[i] for i in s]))\n\n\n\n\n\n\n\n\n\n\t\t", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport time\n\nn = int(input())\nN = {}\nP = {}\n\nfor i in range(n):\n buf = input().split()\n x = float(buf[0])\n a = int (buf[1])\n if x < 0:\n N[-x] = a\n else:\n P[x] = a\n\nstart = time.time()\n\nif len(N) > len(P):\n buf = [ N[i] for i in sorted(N.keys()) ]\n ans = sum(P.values()) + sum(buf[:len(P)+1])\nelse:\n buf = [ P[i] for i in sorted(P.keys()) ]\n ans = sum(N.values()) + sum(buf[:len(N)+1])\nprint(ans)\nfinish = time.time()\n#print(finish - start)\n", "n = int(input())\r\nmark = [0]*200000\r\ntree_r = []\r\ntree_l = []\r\nallapples = 0\r\nfor i in range (n):\r\n x, a = map(int, input().split())\r\n allapples += a\r\n mark[x] = a\r\n if (x<0):\r\n tree_l.append(x)\r\n else:\r\n tree_r.append(x)\r\n\r\nif (len(tree_l) > len(tree_r) + 1):\r\n tree_l.sort()\r\n diff = len(tree_l) - len(tree_r) - 1\r\n for j in range (diff):\r\n allapples -= mark[tree_l[j]]\r\nelif (len(tree_r) > len(tree_l) + 1):\r\n tree_r.sort()\r\n diff = len(tree_r) - len(tree_l) - 1\r\n for j in range (len(tree_r) - diff, len(tree_r)):\r\n allapples -= mark[tree_r[j]]\r\n\r\nprint (allapples)\r\n", "n = int(input())\r\n\r\npositive = []\r\nnegetive = []\r\nresult = 0\r\n\r\nfor i in range(n):\r\n coordinate,apples = list(map(int,input().split()))\r\n if (coordinate > 0):\r\n positive.append((coordinate, apples))\r\n else:\r\n negetive.append((coordinate, apples))\r\n\r\npositive.sort()\r\nnegetive.sort(reverse=True)\r\n\r\nlength = min(len(positive), len(negetive))\r\nfor i in range(length):\r\n result += positive[i][1]\r\n result += negetive[i][1]\r\n\r\nif len(positive) > len(negetive):\r\n result += positive[length][1]\r\nelif len(positive) < len(negetive):\r\n result += negetive[length][1]\r\n\r\nprint(result)\r\n", "n = int(input())\npos = dict()\nneg = dict()\nanswer = 0\nfor i in range(n):\n line = input().split(\" \")\n coord = int(line[0])\n apples = int(line[1])\n if coord < 0:\n neg[abs(coord)] = apples\n else:\n pos[coord] = apples\n\nif len(pos) == len(neg):\n for i in pos.values():\n answer += i\n for i in neg.values():\n answer += i\nelif len(pos) > len(neg):\n pos_keys = list(pos.keys())\n neg_keys = list(neg.keys())\n pos_keys.sort()\n neg_keys.sort()\n for i in range(len(neg)):\n answer += pos[pos_keys[i]] + neg[neg_keys[i]]\n answer += pos[pos_keys[len(neg)]]\nelif len(pos) < len(neg):\n pos_keys = list(pos.keys())\n neg_keys = list(neg.keys())\n pos_keys.sort()\n neg_keys.sort()\n for i in range(len(pos)):\n answer += pos[pos_keys[i]] + neg[neg_keys[i]]\n answer += neg[neg_keys[len(pos)]]\nprint(answer)\n \t\t \t \t \t\t \t \t \t\t \t\t\t", "n = int(input().strip())\nneg, pos = [], []\nfor i in range(n):\n\tx, a = map(int, input().strip().split())\n\tif x < 0:\n\t\tneg.append((x, a))\n\telse:\n\t\tpos.append((x, a))\nneg.sort(reverse=True)\npos.sort()\ntotal = 0\nwhile len(neg) and len(pos):\n\ttotal += neg[0][1] + pos[0][1]\n\tneg.pop(0)\n\tpos.pop(0)\nif len(neg):\n\ttotal += neg[0][1]\nif len(pos):\n\ttotal += pos[0][1]\nprint(total)", "\r\nn=int(input())\r\nd=dict()\r\nc1=c2=0\r\nl1,l2=[],[]\r\nfor i in range(n):\r\n x,y=map(int, input().split())\r\n d[x]=y\r\n if x<0:\r\n c1+=1\r\n l1.append(x)\r\n else:\r\n c2+=1\r\n l2.append(x)\r\nl1.sort()\r\nl2.sort()\r\nc=0\r\n# print(l1,l2)\r\nif c1>c2:\r\n for i in range(c2):\r\n c+=d[l2[i]]\r\n for i in range(c1-c2-1,c1):\r\n c+=d[l1[i]]\r\n print(c)\r\nelif c1<c2:\r\n for i in range(c1):\r\n c+=d[l1[i]]\r\n for i in range(c1+1):\r\n c+=d[l2[i]]\r\n print(c)\r\nelse:\r\n for i in range(c1):\r\n c+=d[l1[i]]+d[l2[i]]\r\n print(c)\r\n\r\n\r\n\r\n\r\n\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\ndef solve():\r\n\tn = mint()\r\n\tl = []\r\n\tr = []\r\n\tfor i in range(n):\r\n\t\tx, a = mints()\r\n\t\tif x < 0:\r\n\t\t\tl.append((-x, a))\r\n\t\tif x > 0:\r\n\t\t\tr.append((x, a))\r\n\tl.sort()\r\n\tr.sort()\r\n\tres = 0\r\n\tfor z in range(2):\r\n\t\ti = 0\r\n\t\tc = 0\r\n\t\twhile True:\r\n\t\t\tif i >= len(l):\r\n\t\t\t\tbreak\r\n\t\t\tc += l[i][1]\r\n\t\t\tif i >= len(r):\r\n\t\t\t\tbreak\r\n\t\t\tc += r[i][1]\r\n\t\t\ti += 1\r\n\t\tres = max(res, c)\r\n\t\tl, r = r, l\r\n\tprint(res)\r\n\r\nsolve()\r\n", "from queue import PriorityQueue\r\n\r\nn = int(input())\r\n\r\ns = 0\r\n\r\nA = PriorityQueue()\r\n\r\nB = PriorityQueue()\r\n\r\nfor i in range(n):\r\n x, a = map(int, input().split())\r\n if x > 0:\r\n A.put((x, a))\r\n else:\r\n B.put((-x, a))\r\n \r\nif A.qsize() == B.qsize():\r\n while not A.empty():\r\n s += A.get()[1]\r\n while not B.empty():\r\n s += B.get()[1]\r\nelif A.qsize() > B.qsize():\r\n for i in range(B.qsize() + 1):\r\n s += A.get()[1]\r\n while not B.empty():\r\n s += B.get()[1]\r\nelse:\r\n for i in range(A.qsize() + 1):\r\n s += B.get()[1]\r\n while not A.empty():\r\n s += A.get()[1]\r\n\r\nprint(s)", "n = int(input())\r\nneg = []\r\npos = []\r\nfor i in range(n):\r\n x,a = map(int,input().split())\r\n if x>0:\r\n pos.append((x,a))\r\n else:\r\n neg.append((x,a))\r\npos.sort()\r\nneg.sort(reverse=True)\r\nlen_pos = len(pos)\r\nlen_neg = len(neg)\r\napples = 0\r\nfor i in range(min(len_pos,len_neg)):\r\n apples += pos[i][1] + neg[i][1]\r\nif len_pos>len_neg:\r\n apples += pos[len_neg][1]\r\nelif len_pos<len_neg:\r\n apples += neg[len_pos][1]\r\nprint(apples) \r\n", "n = int(input())\n\nleft_apples = []\nleft_pos = []\nright_apples = []\nright_pos = []\n\n\nfor _ in range(n):\n\tp, q = input().split()\n\tif int(p) < 0:\n\t\tleft_pos.append(abs(int(p)))\n\t\tleft_apples.append(int(q))\n\telse:\n\t\tright_pos.append(int(p))\n\t\tright_apples.append(int(q))\n\n\n# print(left_apples)\n# print(left_pos)\n\nleft_apples = [x for _,x in sorted(zip(left_pos,left_apples))]\nright_apples = [x for _,x in sorted(zip(right_pos,right_apples))]\n\n# print(left_apples)\n# print(right_apples)\n\nif len(left_apples) == len(right_apples):\n\tprint(sum(left_apples) + sum(right_apples))\n\n\nif len(left_apples) > len(right_apples):\n\tprint(sum(left_apples[:len(right_apples)+1])+sum(right_apples))\n\n\nif len(left_apples) < len(right_apples):\n\tprint(sum(right_apples[:len(left_apples)+1])+sum(left_apples))", "def main():\r\n n = int(input())\r\n left = []\r\n right = []\r\n for _ in range(n):\r\n x, a = map(int, input().split())\r\n if x > 0:\r\n right += [(x, a)]\r\n else:\r\n left += [(-x, a)]\r\n left.sort()\r\n right.sort()\r\n m = min(len(left), len(right))\r\n\r\n res = 0\r\n for i in range(m):\r\n res += left[i][1] + right[i][1]\r\n if len(left) > len(right):\r\n res += left[m][1]\r\n elif len(left) < len(right):\r\n res += right[m][1]\r\n print(res)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n=int(input())\r\npos=[]\r\nneg=[]\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n if a<0:\r\n neg.append((a,b))\r\n else:\r\n pos.append((a,b))\r\nneg=sorted(neg,reverse=True)\r\npos.sort()\r\nno1=0\r\nno2=0\r\ntemp1=list(neg)\r\ntemp2=list(pos)\r\ni=0\r\nwhile(True):\r\n if i==0:\r\n if len(temp1)==0:\r\n break\r\n x,cur=temp1[0]\r\n i=1\r\n no1+=cur\r\n temp1.pop(0)\r\n if i==1:\r\n if len(temp2)==0:\r\n break\r\n x,cur=temp2[0]\r\n i=0\r\n no1+=cur\r\n temp2.pop(0)\r\ni=0\r\nwhile(True):\r\n if i==0:\r\n if len(pos)==0:\r\n break\r\n x,cur=pos[0]\r\n i=1\r\n no2+=cur\r\n pos.pop(0)\r\n if i==1:\r\n if len(neg)==0:\r\n break\r\n x,cur=neg[0]\r\n i=0\r\n no2+=cur\r\n neg.pop(0)\r\nprint(max(no1,no2))\r\n", "import math\r\n\r\n\r\ndef main_function():\r\n x = [[int(i) for i in input().split(\" \")] for j in range(int(input()))]\r\n right = []\r\n left = []\r\n for i in x:\r\n if i[0] > 0:\r\n right.append(i)\r\n else:\r\n left.append(i)\r\n right.sort(key=lambda x:x[0])\r\n left.sort(key=lambda x:x[0], reverse=True)\r\n sorted_right_left = sorted([right, left], key=lambda x: len(x))\r\n sums = 0\r\n for i in range(len(sorted_right_left[0])):\r\n sums += sorted_right_left[0][i][1]\r\n for i in range(len(sorted_right_left[0]) + 1):\r\n if i < len(sorted_right_left[1]):\r\n sums += sorted_right_left[1][i][1]\r\n print(sums)\r\n\r\n\r\n\r\n\r\n\r\n\r\nmain_function()", "l1 = int(input())\n#l2 = input().split()\n\nmac = []\npos = 0\nneg = 0\ntotal = 0\n\nwhile (l1 > 0):\n l1 -= 1\n l2 = input().split()\n x = int(l2[0])\n a = int(l2[1])\n obj = {}\n obj['posicao'] = x\n obj['macas'] = a\n mac.append(obj)\n if(x > 0): pos += 1\n else: neg+=1\n total += a;\n\nmac.sort(key=lambda x: x['posicao'])\n\nif(pos < neg - 1):\n for p in range(neg - 1 - pos):\n total -= mac[p]['macas'];\n\n\n\nelif(neg < pos - 1):\n for p in range (pos - 1 - neg):\n total -= mac[l1 - 1 - p]['macas'];\n\nprint(total)\n\n\n\n\n \t \t \t \t \t\t \t \t \t \t\t", "n = int(input())\r\np = []\r\nq = []\r\nfor i in range(n):\r\n x, a = map(int, input().split())\r\n if x > 0:\r\n p.append([x, a])\r\n else:\r\n q.append([x, a])\r\np.sort()\r\nq.sort()\r\nq.reverse()\r\ne = min(len(p), len(q))\r\nsum = 0\r\nfor i in range(e):\r\n sum += p[i][1] + q[i][1]\r\nif e == 0:\r\n i = -1\r\nif len(p) > i + 1 and len(p) != len(q):\r\n sum += p[i + 1][1]\r\nelif len(q) > i + 1 and len(p) != len(q):\r\n sum += q[i + 1][1]\r\nprint(sum)\r\n \r\n", "n=int(input())\r\nr=[]\r\nl=[]\r\nfor _ in range(n):\r\n x,h=map(int,input().split())\r\n if x<0: l+=[(-x,h)]\r\n else: r+=[(x,h)]\r\nans=0\r\nl.sort()\r\nr.sort()\r\nlel=len(l)\r\nler=len(r)\r\nif lel>ler:\r\n for i in range(min(lel,ler+1)):\r\n ans+=l[i][1]\r\n for i in range(ler):\r\n ans+=r[i][1]\r\nelse:\r\n for i in range(min(lel+1,ler)):\r\n ans+=r[i][1]\r\n for i in range(lel):\r\n ans+=l[i][1]\r\nprint(ans)", "left,right=[],[]\r\nfor _ in range(int(input())):\r\n coor,ap=map(int,input().split())\r\n if coor<0:\r\n left.append([coor,ap])\r\n else:right.append([coor,ap])\r\nc=0\r\nif abs(len(left)-len(right)) in [0,1]:\r\n for i in left:\r\n c+=i[1]\r\n for i in right:\r\n c+=i[1]\r\n print(c)\r\nelse:\r\n if len(left)>len(right):\r\n left.sort(reverse=True)\r\n # print(left[:len(right+2)])\r\n for i in left[:len(right)+1]:\r\n c+=i[1]\r\n for i in right:\r\n c+=i[1]\r\n print(c)\r\n else:\r\n right.sort()\r\n for i in right[:len(left)+1]:\r\n c+=i[1]\r\n for i in left:\r\n c+=i[1]\r\n print(c)", "n = int(input())\r\nnumpos = 0\r\nnumneg = 0\r\nposlist = []\r\nneglist = []\r\nanswer = 0\r\nfor i in range(n):\r\n x, a = (int(y) for y in input().split())\r\n if x > 0:\r\n numpos += 1\r\n poslist.append([x,a])\r\n else:\r\n numneg += 1\r\n neglist.append([-x,a])\r\nposlist.sort(key = lambda x: x[0])\r\nneglist.sort(key = lambda x: x[0])\r\nif numpos == numneg:\r\n for i in range(len(poslist)):\r\n answer += poslist[i][1] + neglist[i][1]\r\n print (answer)\r\nelif numpos > numneg:\r\n for i in range(len(neglist)):\r\n answer += neglist[i][1]\r\n for i in range(len(neglist) + 1):\r\n answer += poslist[i][1]\r\n print (answer)\r\nelse: \r\n for i in range(len(poslist)):\r\n answer += poslist[i][1]\r\n for i in range(len(poslist) + 1):\r\n answer += neglist[i][1]\r\n print (answer)", "n = int(input())\r\nd = {}\r\nx_minus = []\r\nx_plus = []\r\nfor i in range(n):\r\n x, a = map(int, input().split())\r\n d[x] = a\r\n if x < 0:\r\n x_minus.append(x)\r\n else:\r\n x_plus.append(x)\r\n\r\nlength = min(len(x_minus), len(x_plus)) + 1\r\nx_minus.sort(reverse=True)\r\nx_plus.sort()\r\nres = 0\r\nfor el in x_minus[:length] + x_plus[:length]:\r\n res += d[el]\r\nprint(res)\r\n", "n = int(input())\nleft = []\nright = []\nfor i in range(n):\n x, a = [int(i) for i in input().split()]\n if x < 0:\n left.append([x, a])\n else:\n right.append([x, a])\nleft.sort(reverse=True)\nright.sort()\nans = 0\nlength = min(len(left), len(right))\nfor i in range(length):\n ans += left[i][1]\n ans += right[i][1]\nif len(left) > len(right):\n ans += left[length][1]\nelif len(right) > len(left):\n ans += right[length][1]\nprint(ans)\n", "n=int(input())\npos=[]\nneg=[]\nfor _ in range(n):\n x,a=map(int,input().split())\n if x > 0:\n pos.append((x, a))\n else:\n neg.append((-x, a))\npos=[a for x,a in sorted(pos)]\nneg=[a for x,a in sorted(neg)]\nif len(pos)==len(neg):\n print(sum(pos)+sum(neg))\nelse:\n if len(pos)<len(neg):\n pos,neg=neg,pos\n print(sum(neg)+sum(pos[:len(neg)+1]))\n", "n = int(input())\r\nnegx = []\r\nposx = []\r\nlenn = 0\r\nlenp = 0\r\nfor i in range(n):\r\n x, a = map(int, input().split())\r\n if x>0:\r\n posx.append((x, a))\r\n lenp += 1\r\n else:\r\n negx.append((x, a))\r\n lenn += 1\r\nnegx.sort(reverse = True)\r\nposx.sort()\r\nmini = min(lenn, lenp)\r\nresult = 0\r\nfor i in range(0, mini):\r\n result += (negx[i][1] + posx[i][1])\r\nif lenn>lenp:\r\n result += negx[mini][1]\r\nelif lenn<lenp:\r\n result += posx[mini][1]\r\nprint(result)\r\n", "n=int(input())\r\nx=n*[0]\r\na=n*[0]\r\nfor i in range(n):\r\n x[i],a[i]=[int(i) for i in input().split()]\r\nfor i in range(n):\r\n bish=x[0]\r\n k=0\r\n for j in range(1,n-i):\r\n if x[j]>bish:\r\n bish=x[j]\r\n k=j\r\n x[n-1-i],x[k]=x[k],x[n-1-i]\r\n a[n-1-i],a[k]=a[k],a[n-1-i]\r\nmanfi=0\r\nmosbat=0\r\nfor i in range(n):\r\n if x[i]>0:\r\n mosbat+=1\r\n else:\r\n manfi+=1\r\nif manfi==mosbat:\r\n print(sum(a))\r\nelif mosbat>manfi:\r\n print(sum(a[:manfi*2+1]))\r\nelse:\r\n print(sum(a[manfi-(mosbat+1):]))\r\n", "import 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 = int(input())\r\n p = sorted([input_ints() for i in range(n)])\r\n a = [t[1] for t in p]\r\n x = n\r\n for i in range(n):\r\n if p[i][0] > 0:\r\n x = i\r\n break\r\n d = n - x\r\n e = n - d\r\n if d >= e:\r\n print(sum(a[:2*e+1]))\r\n else:\r\n print(sum(a[n-2*d-1:]))\r\n\r\nif __name__ == '__main__':\r\n solve()\r\n", "n = int(input())\r\nl = []\r\nc = []\r\nfor x in range(n):\r\n a,b = map(int,input().split())\r\n if a > 0:\r\n l.append([a,b])\r\n else: c.append([a,b])\r\n\r\nl.sort(key = lambda l: l[0])\r\nc.sort(key = lambda c: c[0], reverse=True)\r\nt = 0\r\nx = -1\r\nfor x in range(min(len(l), len(c))):\r\n t += l[x][1]\r\n t += c[x][1]\r\nif len(l) > x+1:\r\n t += l[x+1][1]\r\nif len(c) > x+1:\r\n t += c[x+1][1]\r\nprint(t)", "n = int(input())\r\n\r\ntrees = [{}, {}]\r\nposTrees = [[], []]\r\n\r\nfor i in range(n):\r\n xi, ai = map(int, input().split())\r\n if xi > 0:\r\n trees[1][xi] = ai\r\n posTrees[1].append(xi)\r\n else:\r\n trees[0][xi] = ai\r\n posTrees[0].append(xi)\r\n\r\nposTrees[0] = sorted(posTrees[0])[::-1]\r\nposTrees[1] = sorted(posTrees[1])\r\n\r\nnrTr = [len(trees[0]), len(trees[1])]\r\n\r\n\r\ndef collect(direction):\r\n tr = [0, 0]\r\n apples = 0\r\n\r\n while tr[direction] < nrTr[direction]:\r\n apples += trees[direction][posTrees[direction][tr[direction]]]\r\n tr[direction] += 1\r\n direction = 1 - direction\r\n\r\n return apples\r\n\r\nprint(max(collect(0), collect(1)))", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nu, v = [], []\r\nfor _ in range(n):\r\n x, a = map(int, input().split())\r\n if x < 0:\r\n u.append((x, a))\r\n else:\r\n v.append((x, a))\r\nu.sort(reverse = True)\r\nv.sort()\r\nans = 0\r\nif abs(len(u) - len(v)) <= 1:\r\n for _, a in u + v:\r\n ans += a\r\nelse:\r\n if len(u) > len(v):\r\n u, v = v, u\r\n v = v[:(len(u) + 1)]\r\n for _, a in u + v:\r\n ans += a\r\nprint(ans)", "n = int(input())\r\ndictionp = {}\r\ndictionn = {}\r\ncorp = []\r\ncorn = []\r\npos = 0\r\nneg = 0\r\nans = 0\r\nfor i in range(n):\r\n l = list(map(int , input().split()))\r\n if l[0] > 0:\r\n dictionp[l[0]] = l[1]\r\n corp.append(l[0])\r\n pos = pos + 1\r\n ans = ans + l[1]\r\n else:\r\n dictionn[l[0]] = l[1]\r\n corn.append(l[0])\r\n neg = neg + 1\r\n ans = ans + l[1]\r\nif pos > neg:\r\n x = pos - neg - 1\r\n corp.sort()\r\n for i in range(x):\r\n ans = ans - dictionp[corp[-1]]\r\n corp.pop(-1)\r\nelif pos < neg:\r\n x = neg - pos - 1\r\n corn.sort()\r\n for i in range(x):\r\n ans = ans - dictionn[corn[0]]\r\n corn.pop(0)\r\nelse:\r\n pass\r\nprint(ans)\r\n", "def right():\r\n global counter\r\n flag=False\r\n for i in range(n):\r\n if mass[i][0]>0:\r\n counter+=mass[i][1]\r\n mass[i]=(0,0)\r\n flag=True\r\n break\r\n if flag:\r\n left()\r\n flag=False\r\n\r\ndef left():\r\n global counter\r\n flag=False\r\n for i in range(n-1,-1,-1):\r\n if mass[i][0]<0:\r\n counter+=mass[i][1]\r\n mass[i]=(0,0)\r\n flag=True\r\n break\r\n if flag:\r\n right()\r\n\r\n\r\nn=int(input())\r\nmass=[]\r\nminc=maxc=0\r\nfor i in range(n):\r\n mass.append(tuple(map(int, input().split())))\r\n if mass[i][0]<0:\r\n minc+=1\r\n else:\r\n maxc+=1\r\nfor i in range(n):\r\n for j in range(n-i-1):\r\n if mass[j]>mass[j+1]:\r\n mass[j],mass[j+1]=mass[j+1],mass[j]\r\ncounter=0\r\nif maxc>minc:\r\n right()\r\n print(counter)\r\nelse:\r\n left()\r\n print(counter)", "N = int(input())\nl = sorted([(int(xi), int(ai)) for (xi, ai) in (input().split() for i in range(N))] + [(0, 0)])\n\npos = [a[0] for a in l]\napples = [a[1] for a in l]\n\n\nLEFT = 0\nRIGHT = 1\n\ndef go(d):\n le = ri = pos.index(0)\n su = 0\n while True:\n if d == LEFT:\n le -= 1\n d = RIGHT\n if le < 0:\n break\n su += apples[le]\n else:\n ri +=1\n d = LEFT\n if ri >= len(apples):\n break\n su += apples[ri]\n return su\n\nprint(max(go(LEFT), go(RIGHT)))\n", "import math\r\nimport sys\r\n\r\nn=int(input())\r\nx=[]\r\na=[]\r\np=[]\r\nm=[]\r\nfor i in range(0,n):\r\n inp=list(map(int,input().split()))\r\n x.append(inp[0])\r\n a.append(inp[1])\r\n if x[i] < 0:\r\n m.append(-x[i]*1000000+a[i])\r\n \r\n else:\r\n p.append(x[i]*1000000+a[i])\r\nm.sort()\r\np.sort()\r\n\r\ni=0\r\nans=0\r\nwhile i < len(m) and i < len(p):\r\n \r\n ans+=m[i]%1000000\r\n ans+=p[i]%1000000\r\n i+=1\r\n\r\nif i < len(m):\r\n ans+=m[i]%1000000\r\n\r\nif i < len(p):\r\n ans+=p[i]%1000000\r\nprint(ans)\r\n", "#!/usr/bin/env python3\n\ndef calc(s1, s2):\n total = 0\n for a, b in zip(s1, s2):\n total += a[1] + b[1]\n return total\n\n\nif __name__ == '__main__':\n n = int(input())\n pos, neg = [], []\n for _ in range(n):\n x, a = map(int, input().split())\n if x < 0:\n neg.append((-x, a))\n else:\n pos.append((x, a))\n pos.sort()\n neg.sort()\n\n print(max(calc([(0,0)] + pos, neg),\n calc(pos, [(0,0)] + neg),\n calc(pos, neg)))\n", "n = int(input())\r\ntrees = {}\r\nfor x in range(n):\r\n string = input()\r\n numbers = string.split()\r\n trees[int(numbers[0])] = int(numbers[1])\r\ncoordinates = list(trees)\r\ncoordinates.sort()\r\napples = []\r\nfor x in range(2):\r\n temp = coordinates[:]\r\n a = 0\r\n for y in range(n):\r\n if y % 2 == x:\r\n if max(temp) > 0:\r\n for z in temp:\r\n if z > 0:\r\n temp.remove(z)\r\n a += trees[z]\r\n break\r\n else:\r\n break\r\n else:\r\n if min(temp) < 0:\r\n for z in temp[::-1]:\r\n if z < 0:\r\n temp.remove(z)\r\n a += trees[z]\r\n break\r\n else:\r\n break\r\n apples.append(a)\r\nprint(max(apples))", "n=int(input())\r\nleft=[]\r\nright=[]\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n if(a>0):\r\n right.append([a,b])\r\n else:\r\n left.append([a,b])\r\nright.sort(key=lambda x:x[0])\r\nleft.sort(key=lambda x:x[0],reverse=True)\r\nn=min(len(right),len(left))\r\nans=0\r\nfor i in range(n+1):\r\n if(i<n):\r\n ans+=left[i][1]+right[i][1]\r\n if(i==n):\r\n if(len(left)>n):\r\n ans+=left[i][1]\r\n if(len(right)>n):\r\n ans+=right[i][1]\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\n\r\nn = ii1()\r\narr = []\r\npos,neg = [],[]\r\nfor _ in range(n):\r\n x, a = iia()\r\n if x > 0:\r\n pos.append([x,a])\r\n else:\r\n neg.append([x, a])\r\npos.sort()\r\nneg.sort()\r\nif len(pos) == len(neg):\r\n res = sum(i[1] for i in pos) + sum(i[1] for i in neg)\r\nelif len(pos) > len(neg):\r\n res = sum(i[1] for i in neg)\r\n res += sum(pos[i][1] for i in range(len(neg) + 1))\r\nelse:\r\n res = sum(i[1] for i in pos)\r\n res += sum(i[1] for i in neg[::-1][: len(pos) + 1])\r\nprint(res)\r\n\r\n\r\n", "import sys,math\nsys.setrecursionlimit(10**8)\n'''\ndef fun():\n for i in range(16):\n for j in range(4):\n if i&(1<<j):\n print(j,end='')\n print()\nimport binarytree\nfrom collections import deque\nbst = binarytree.tree(height=4,is_perfect=True)\nprint(bst)\ndef s(bst):\n if bst:\n bst.left,bst.right = bst.right,bst.left\n s(bst.right)\n s(bst.left)\ns(bst)\nprint(bst)\n'''\nt = int(input())\npos = [None]*(pow(10,5)+1)\nneg = [None]*(pow(10,5)+1)\npp,nn = 0,0\nfor _ in range(t):\n x,a = map(int,input().split())\n if x<0:\n neg[abs(x)] = a\n nn+=1\n else:\n pos[x] = a\n pp+=1\nif nn<pp:\n pp = nn+1\n i = 0\n s1,s2 =0 ,0\n while nn!=0:\n if neg[i] !=None:\n s1+=neg[i]\n nn-=1\n i+=1\n i=0\n while pp!=0:\n if pos[i] !=None:\n s2+=pos[i]\n pp-=1\n i+=1\n print(s1+s2)\nelif nn>pp:\n nn = pp+1\n i = 0\n s1,s2 =0,0\n while nn!=0:\n if neg[i] !=None:\n s1+=neg[i]\n nn-=1\n i+=1\n i=0\n while pp!=0:\n if pos[i] !=None:\n s2+=pos[i]\n pp-=1\n i+=1\n print(s1+s2)\nelse:\n nn = pp\n i = 0\n s1,s2 =0,0\n while nn!=0:\n if neg[i] !=None:\n s1+=neg[i]\n nn-=1\n i+=1\n i=0\n while pp!=0:\n if pos[i] !=None:\n s2+=pos[i]\n pp-=1\n i+=1\n print(s1+s2)\n\n", "n= int(input());\r\nleft = right = ans = 0;\r\nlefts = [0]*(10**5+1);\r\nrights = [0]*(10**5+1);\r\nfor i in range(n):\r\n xi, value= map(int,input().split());\r\n if xi < 0:\r\n lefts[-1*xi]= value;\r\n left += 1;\r\n else:\r\n rights[xi]= value;\r\n right += 1;\r\nlefts = [i for i in lefts if i != 0]\r\nrights = [i for i in rights if i != 0]\r\nif left == right:\r\n ans = sum(lefts)+sum(rights);\r\nelif left < right:\r\n ans = sum(rights[0:left+1])+sum(lefts);\r\nelse:\r\n ans = sum(lefts[0:right+1])+sum(rights);\r\nprint(ans)", "trees = int(input());\r\n\r\ndata = {};\r\nnegCount = 0;\r\nposCount = 0;\r\n\r\nfor i in range(0, trees):\r\n temp = [int(x) for x in input().split()];\r\n if(temp[0]<0):\r\n negCount += 1;\r\n else:\r\n posCount += 1;\r\n data[temp[0]] = temp[1];\r\n \r\n \r\nsortedData = [];\r\n\r\nfor key in sorted(data):\r\n sortedData.append(data[key]);\r\n \r\nif( negCount<posCount ):\r\n print(sum(sortedData[0:negCount*2+1]));\r\nelif( negCount > posCount ):\r\n print(sum(sortedData[(len(sortedData)-1)-2*posCount::]));\r\nelse:\r\n print(sum(sortedData));\r\n \r\n ", "\r\nn = int(input())\r\n\r\nposValues = {}\r\nnegValues = {}\r\n\r\nfor i in range(n):\r\n row = input().split()\r\n if int(row[0]) > 0:\r\n posValues[int(row[0])] = int(row[1])\r\n else:\r\n negValues[int(row[0])] = int(row[1])\r\n\r\n\r\nsposValues = dict(sorted(posValues.items()))\r\nsnegValues= dict(sorted(negValues.items(), reverse = True))\r\n\r\n\r\nres =0\r\n\r\nif len(snegValues) == 0: print(list(sposValues.values())[0])\r\nelif len(sposValues) == 0 : print(list(snegValues.values())[0])\r\nelif len(snegValues) > len(sposValues):\r\n res+= sum(sposValues.values())\r\n for i in range(len(sposValues)+1):\r\n res += list(snegValues.values())[i]\r\n print(res)\r\nelif len(snegValues) == len(sposValues):\r\n res = sum(sposValues.values()) + sum(snegValues.values())\r\n print(res)\r\n\r\nelse:\r\n res+= sum(snegValues.values())\r\n for i in range(len(snegValues)+1):\r\n res += list(sposValues.values())[i]\r\n print(res)\r\n\r\n\r\n\r\n", "def read_data():\r\n n = int(input())\r\n xa = []\r\n for i in range(n):\r\n x, a = map(int, input().split())\r\n xa.append((x, a))\r\n xa.sort()\r\n return n, xa\r\n\r\ndef solve(n, xa):\r\n count = 0\r\n for x, a in xa:\r\n if x < 0:\r\n count += 1\r\n else:\r\n break\r\n xa_minus = xa[:count]\r\n xa_plus = xa[count:]\r\n xa_minus.reverse()\r\n if len(xa_plus) > len(xa_minus):\r\n return sum(a for x, a in xa_plus[:len(xa_minus)+1]) + sum(a for x, a in xa_minus)\r\n elif len(xa_plus) < len(xa_minus):\r\n return sum(a for x, a in xa_minus[:len(xa_plus)+1]) + sum(a for x, a in xa_plus)\r\n else:\r\n return sum(a for x, a in xa)\r\n\r\nn, xa = read_data()\r\nprint(solve(n, xa))\r\n", "\r\nn = int(input())\r\n\r\nneg,pos = [],[]\r\nfor i in range(n):\r\n a,b = list(map(int,input().split()))\r\n if a < 0:\r\n neg.append([a,b])\r\n else:\r\n pos.append([a,b])\r\ndef quicksort(array,left,right):\r\n if left < right:\r\n pivot_index = partition(array,left,right)\r\n quicksort(array,left,pivot_index-1)\r\n quicksort(array,pivot_index+1,right)\r\n return array\r\ndef partition(array,left,right):\r\n pivot_index = left\r\n pivot = array[left]\r\n for i in range(left+1,right+1):\r\n if abs(array[i][0]) < abs(pivot[0]):\r\n pivot_index += 1\r\n if pivot_index != i:\r\n array[pivot_index],array[i] = array[i],array[pivot_index]\r\n array[left],array[pivot_index] = array[pivot_index],array[left]\r\n return pivot_index\r\n\r\nneg = quicksort(neg,0,len(neg)-1)\r\npos = quicksort(pos,0,len(pos)-1)\r\n\r\nn,m = len(neg),len(pos)\r\napples = 0\r\nif n == m:\r\n for i in range(n):\r\n apples += neg[i][1]\r\n for j in range(m):\r\n apples += pos[j][1]\r\nelif n > m:\r\n for i in range(m):\r\n apples += pos[i][1]\r\n for i in range(m+1):\r\n apples += neg[i][1]\r\nelif n < m:\r\n for i in range(n):\r\n apples += neg[i][1]\r\n for i in range(n+1):\r\n apples += pos[i][1]\r\nprint (apples)", "a = int(input())\r\n\r\npos = []\r\nneg = []\r\n\r\nfor i in range(a):\r\n x, y = map(int, input().split(' '))\r\n if x > 0:\r\n pos.append([x, y])\r\n else:\r\n neg.append([x, y])\r\npos.sort()\r\nneg.sort()\r\nneg.reverse()\r\n\r\nsumx = 0\r\n \r\ntpos = min(len(pos), len(neg)+1)\r\ntneg = min(len(neg), tpos)\r\n\r\nfor i in range(tpos):\r\n sumx += pos[i][1]\r\n\r\nfor i in range(tneg):\r\n sumx += neg[i][1]\r\n\r\ntneg = min(len(neg), len(pos)+1)\r\ntpos = min(len(pos), tneg)\r\n\r\nsumx2 = 0\r\n\r\nfor i in range(tpos):\r\n sumx2 += pos[i][1]\r\n\r\nfor i in range(tneg):\r\n sumx2 += neg[i][1]\r\n\r\nprint(max(sumx, sumx2))\r\n", "mod = 10 ** 9 + 7\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\nlp=[]\r\nlpl=0\r\nln=[]\r\nlnl=0\r\nfor i in range(n):\r\n l=il()\r\n if l[0]>0:\r\n lp.append(l)\r\n lpl+=1\r\n else:\r\n ln.append(l)\r\n lnl+=1\r\nlp.sort()\r\nln.sort(reverse=True)\r\nif lpl>lnl:\r\n print(sum(ln[i][1] for i in range(lnl))+sum(lp[i][1] for i in range(lnl))+lp[lnl][1])\r\nelif lpl<lnl:\r\n print(sum(ln[i][1] for i in range(lpl)) + sum(lp[i][1] for i in range(lpl)) + ln[lpl][1])\r\nelse:\r\n print(sum(ln[i][1] for i in range(lpl)) + sum(lp[i][1] for i in range(lpl)))", "n = int(input())\r\nleft=[]\r\nright=[]\r\nfor _ in range(n):\r\n \r\n a,b = map(int,input().split())\r\n if a<0:\r\n left.append([a,b])\r\n else:\r\n right.append([a,b])\r\nleft.sort(reverse=True)\r\nright.sort()\r\ni=0\r\nj=0\r\nans=0\r\nwhile(i<len(left) and j<len(right)):\r\n ans+=left[i][1]\r\n ans+=right[j][1]\r\n \r\n i+=1\r\n j+=1\r\nif(i<len(left)):\r\n ans+=left[i][1]\r\nif(j<len(right)):\r\n ans+=right[j][1]\r\nprint(ans)\r\n ", "qtd = int(input())\npos = []\nneg = []\nfor inp in range(0,qtd):\n params = list(map(int,list(input().split())))\n if params[0] < 0:\n neg.append([params[0], params[1]])\n else:\n pos.append([params[0], params[1]])\n \npos.sort()\nneg = sorted(neg, reverse=True) \n\ncount = 0\nbasket1 = 0\nwhile (True):\n try:\n basket1 += pos[count][1]\n except:\n break\n try:\n basket1 += neg[count][1]\n except:\n break\n count += 1\n\ncount = 0\nbasket2 = 0\nwhile (True):\n try:\n basket2 += neg[count][1]\n except:\n break\n try:\n basket2 += pos[count][1]\n except:\n break\n count += 1\n\nif basket1 > basket2:\n print(basket1)\nelse:\n print(basket2)\n\t \t \t\t \t \t \t \t\t\t \t\t \t\t \t\t\t\t", "\nn=int(input())\n\na=[]\nb=[]\n\nfor i in range(n):\n x,y=input().split()\n if int(x)>0:\n a.append((int(x),int(y)))\n else:\n b.append((int(x),int(y)))\n\na.sort()\nb.sort()\n\nn=min(len(a),len(b))\n\nans=0\n\nfor i in range(n):\n ans=ans+a[i][1]\n ans=ans+b[-i-1][1]\n\nif len(a)>n:\n ans=ans+a[n][1]\nelif len(b)>n:\n ans=ans+b[-n-1][1]\n\nprint(ans)\n", "n = int(input())\ntrees = {}\nfor _ in range(n):\n xi, ai = input().split(\" \")\n trees[int(xi)] = int(ai)\n\nleft_trees_ordered_by_closeness = sorted(((k, v) for k, v in trees.items() if k < 0), reverse=True)\nright_trees_ordered_by_closeness = sorted((k, v) for k, v in trees.items() if k > 0)\n\nleft_apples_ordered_by_closeness = [v for k, v in left_trees_ordered_by_closeness]\nright_apples_ordered_by_closeness = [v for k, v in right_trees_ordered_by_closeness]\n\nminimum_size = min(len(left_apples_ordered_by_closeness), len(right_apples_ordered_by_closeness))\nprint(\n sum(left_apples_ordered_by_closeness[:minimum_size + 1]) + \n sum(right_apples_ordered_by_closeness[:minimum_size + 1])\n)\n\n \t\t\t\t\t \t \t \t \t\t\t\t\t \t\t\t \t\t", "# Link - https://codeforces.com/contest/558/problem/A\n# Time: O(nlog(n))\n\nn = int(input())\n\npos = []\nneg = []\n\nfor _ in range(n):\n\n x, a = map(int, input().split())\n\n if x > 0:\n pos.append((x, a))\n else:\n neg.append((x, a))\n\npos.sort()\nneg.sort(reverse=True)\n\npos = [x for _, x in pos]\nneg = [x for _, x in neg]\n\nif len(pos) == len(neg):\n print(sum(pos) + sum(neg))\nelse:\n\n ml = min(len(pos), len(neg)) # min length\n\n total = sum(pos[:ml]) + sum(neg[:ml])\n\n if len(pos) > ml:\n total += pos[ml]\n else:\n total += neg[ml]\n\n print(total)\n", "# coding=utf-8\r\n\r\nif __name__ == '__main__':\r\n\tn = int(input())\r\n\tline_p = list()\r\n\tline_m = list()\r\n\tfor i in range(n):\r\n\t\tx, a = str(input()).split()\r\n\t\tx = int(x)\r\n\t\ta = int(a)\r\n\t\tif x > 0:\r\n\t\t\tline_p.append([x, a])\r\n\t\telse:\r\n\t\t\tline_m.append([-x, a])\r\n\tline_p.sort(key=lambda x: x[0])\r\n\tline_m.sort(key=lambda x: x[0])\r\n\tsize_p = len(line_p)\r\n\tsize_m = len(line_m)\r\n\ttar = 0\r\n\tif abs(size_p - size_m) < 2:\r\n\t\tfor it in line_p:\r\n\t\t\ttar += it[1]\r\n\t\tfor it in line_m:\r\n\t\t\ttar += it[1]\r\n\telse:\r\n\t\tif size_p > size_m:\r\n\t\t\tfor i in range(size_m + 1):\r\n\t\t\t\ttar += line_p[i][1]\r\n\t\t\tfor it in line_m:\r\n\t\t\t\ttar += it[1]\r\n\t\telse:\r\n\t\t\tfor i in range(size_p + 1):\r\n\t\t\t\ttar += line_m[i][1]\r\n\t\t\tfor it in line_p:\r\n\t\t\t\ttar += it[1]\r\n\tprint(tar)\r\n", "def nsum(a):\r\n res = 0\r\n for i in range(len(a)):\r\n res += a[i][1]\r\n return res\r\n\r\nn = int(input())\r\nl, r = [], []\r\nfor i in range(n):\r\n x, t = [int(x) for x in input().split()]\r\n if x < 0:\r\n l.append([-x, t])\r\n else:\r\n r.append([x, t])\r\nl.sort()\r\nr.sort()\r\nif len(l) == len(r):\r\n print(nsum(l) + nsum(r))\r\nelif len(l) < len(r):\r\n print(nsum(r[:len(l)+1]) + nsum(l))\r\nelse:\r\n print(nsum(r) + nsum(l[:len(r)+1]))\r\n", "n = int(input())\r\na = [[0]*2 for i in range(n)]\r\n\r\nfor i in range(n):\r\n s = input().split()\r\n a[i][0] = int(s[0])\r\n a[i][1] = int(s[1])\r\n \r\na.append([0, 0])\r\na = sorted(a)\r\n\r\ncount = 0\r\nwhile a[count] != [0, 0]:\r\n count += 1\r\n\r\nvar1 = 0\r\nvar2 = 0\r\nleft = count\r\nright = count\r\n\r\nwhile (left > -1) and (right < n+1):\r\n var1 += a[right][1]\r\n right += 1\r\n var1 += a[left][1]\r\n left -= 1\r\nif right < n+1:\r\n var1 += a[right][1]\r\n \r\nleft = count\r\nright = count\r\n\r\nwhile (left > -1) and (right < n+1):\r\n var2 += a[left][1]\r\n left -= 1\r\n var2 += a[right][1]\r\n right += 1\r\nif left > -1:\r\n var1 += a[left][1]\r\n \r\nprint(max(var1, var2))", "n = int(input())\n\nlefts = {}\nrights = {}\n\nfor i in range(n):\n xi, ai = map(int, input().split())\n\n if xi < 0:\n lefts[xi] = ai\n else:\n rights[xi] = ai\n\nlefts = [v[1] for v in sorted(lefts.items(), reverse=True)]\nrights = [v[1] for v in sorted(rights.items())]\n\nll = len(lefts)\nlr = len(rights)\n\nif ll == lr:\n print(sum(lefts) + sum(rights))\nelif ll > lr:\n print(sum(lefts[:lr+1]) + sum(rights))\nelif ll < lr:\n print(sum(lefts) + sum(rights[:ll+1]))\n", "n = int(input())\r\ntrees_pos = set()\r\ntrees_neg = set()\r\nfor i in range(n):\r\n tree = tuple(map(int,input().split()))\r\n if tree[0] > 0:\r\n trees_pos.add(tree)\r\n else:\r\n trees_neg.add(tree)\r\n\r\ns_pos = sorted(trees_pos)\r\ns_neg = sorted(trees_neg, reverse = True)\r\napples = 0\r\nif len(s_pos) == len(s_neg) or abs(len(s_pos) - len(s_neg)) == 1:\r\n print(sum([x[1] for x in s_pos]) + sum([x[1] for x in s_neg]))\r\nelif len(s_pos) > len(s_neg):\r\n print(sum([x[1] for x in s_pos[:len(s_neg)+1]]) + sum([x[1] for x in s_neg]))\r\nelse:\r\n print(sum([x[1] for x in s_neg[:len(s_pos)+1]]) + sum([x[1] for x in s_pos]))", "def solve(x,n):\r\n p=len(x)-n\r\n if max(n,p)-min(n,p)==0:\r\n s=0\r\n for i in range(len(x)):\r\n s+=x[i][-1]\r\n return s\r\n else:\r\n if n<p:\r\n s=0\r\n for i in range(2*n+1):\r\n s+=x[i][-1]\r\n return s\r\n else:\r\n x.sort(reverse=True)\r\n s=0\r\n for i in range(2*p+1):\r\n s+=x[i][-1]\r\n return s\r\nx=[]\r\nn=0\r\nfor i in range(int(input())):\r\n ans=list(map(int,input().split()))\r\n if ans[0]<0:\r\n n+=1\r\n x.append(ans)\r\nx.sort(key=lambda j:j[0])\r\nanswer=solve(x,n)\r\nprint(answer)", "N=int(input())\r\nCnt1=Cnt2=0\r\nApple=[]\r\nfor I in range(N):\r\n Apple.append(list(map(int,input().split())))\r\n if Apple[-1][0]<0:\r\n Cnt1+=1\r\n else:\r\n Cnt2+=1\r\nApple.sort()\r\nAns=0\r\nif Cnt1>Cnt2:\r\n for I in range(Cnt1-Cnt2-1,N):\r\n Ans+=Apple[I][1]\r\nelif Cnt1<Cnt2:\r\n for I in range(2*Cnt1+1):\r\n Ans+=Apple[I][1]\r\nelse:\r\n for I in range(N):\r\n Ans+=Apple[I][1]\r\nprint(Ans)\r\n \r\n", "n=int(input())\r\nleft=[]\r\nright=[]\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n if a<0:\r\n left.append([a,b])\r\n else:\r\n right.append([a,b])\r\n#Sort\r\nright=sorted(right);left=sorted(left,reverse=True)\r\nsu=0\r\na=left;b=right\r\nif len(right)>len(left):a,b=b,a\r\n#Goto a first then to b:\r\nwhile b!=[]:\r\n su+=a[0][1]+b[0][1]\r\n a.pop(0);b.pop(0)\r\nif a!=[]:su+=a[0][1]\r\nprint(su)\r\n", "def solve():\r\n n = int(input())\r\n px, nx, a = [], [], []\r\n for i in range(n):\r\n x, ai = [int(i) for i in input().split()] # map(int, input().split()) also fine\r\n a.append(ai)\r\n if x > 0:\r\n px.append((x, ai))\r\n else:\r\n nx.append((-x, ai))\r\n\r\n px.sort()\r\n nx.sort()\r\n lp, ln = len(px), len(nx)\r\n i, ans = 0, 0\r\n if lp > ln:\r\n i = 0\r\n while i < ln:\r\n ans += nx[i][1]\r\n ans += px[i][1]\r\n i += 1\r\n ans += px[i][1]\r\n else:\r\n i = 0\r\n while i < lp:\r\n ans += nx[i][1]\r\n ans += px[i][1]\r\n i += 1\r\n if i < ln:\r\n ans += nx[i][1]\r\n print(ans)\r\n\r\nsolve()", "N = int(input())\nd = {}\nXmin = []\nXplu = []\nfor i in range(N):\n x, a = map(int, input().split())\n d[x] = a\n if x < 0:\n Xmin.append(x)\n else:\n Xplu.append(x)\nXmin.sort(reverse=True)\nXplu.sort()\n\nnmin = len(Xmin)\nnplu = len(Xplu)\nans1 = 0\nflg = True\nimin = 0\niplu = 0\nwhile True:\n if not flg:\n if imin == nmin:\n break\n ans1 += d[Xmin[imin]]\n imin += 1\n else:\n if iplu == nplu:\n break\n ans1 += d[Xplu[iplu]]\n iplu += 1\n flg = not flg\n\nans2 = 0\nflg = False\nimin = 0\niplu = 0\nwhile True:\n if not flg:\n if imin == nmin:\n break\n ans2 += d[Xmin[imin]]\n imin += 1\n else:\n if iplu == nplu:\n break\n ans2 += d[Xplu[iplu]]\n iplu += 1\n flg = not flg\nprint(max(ans1, ans2))\n", "# Bounds checking much easier in Python than java\r\na,b=[],[]\r\nfor _ in range(int(input())):\r\n x,y=map(int,input().split())\r\n if x<0:a+=[(x,y)]\r\n else:b+=[(x,y)]\r\na.sort()\r\nb.sort()\r\na=a[::-1]\r\nr=0\r\nwhile a and b:\r\n r+=a[0][1]+b[0][1]\r\n a,b=a[1:],b[1:]\r\nif a:r+=a[0][1]\r\nif b:r+=b[0][1]\r\nprint(r)", "R = lambda:list(map(int, input().split(' ')))\r\n#r, w = open(\"input.txt\", \"r\"), open(\"output.txt\", \"w\")\r\nn = int(input())\r\nneg, pos = [], []\r\nfor i in range(n):\r\n x, c = R()\r\n if x > 0:\r\n pos.append([-x, c])\r\n else:\r\n neg.append([x, c])\r\npos.sort()\r\nneg.sort()\r\nif len(neg) > len(pos):\r\n dir = -1\r\nelse:\r\n dir = 1\r\nans = 0\r\nfor i in range(n):\r\n if dir == 1:\r\n if len(pos) != 0:\r\n ans += pos.pop()[1]\r\n dir = -dir\r\n else:\r\n break\r\n else:\r\n if len(neg) != 0:\r\n ans += neg.pop()[1]\r\n dir = -dir\r\n else:\r\n break\r\nprint(ans)\r\n\r\n\r\n\r\n ", "n = int(input())\r\nzp = []\r\nzn = []\r\nfor i in range(n):\r\n a,b = map(int, input().split(' '))\r\n if a > 0:\r\n zp.append((a,b))\r\n else:\r\n zn.append((a,b))\r\nzp.sort()\r\nzn.sort()\r\nzn.reverse()\r\n\r\nif len(zp) == len(zn):\r\n print(sum([i[1] for i in zp] + [i[1] for i in zn]))\r\nelif len(zp) > len(zn):\r\n print(sum([i[1] for i in zp[:len(zn)+1]] + [i[1] for i in zn]))\r\nelse:\r\n print(sum([i[1] for i in zn[:len(zp)+1]] + [i[1] for i in zp]))\r\n", "class Tree:\n def __init__(self, position, apples):\n self.position = position\n self.apples = apples\n\nn = int(input())\nnegative, positive = [], []\nfor i in range(n):\n p, a = map(int, input().split())\n if p < 0:\n negative.append(Tree(p, a))\n else:\n positive.append(Tree(p, a))\n\nnegative.sort(key = lambda tree: -tree.position)\npositive.sort(key = lambda tree: tree.position)\ni = 0\ntotal = 0\nwhile i < len(negative) and i < len(positive):\n total += negative[i].apples + positive[i].apples\n i += 1\nif i < len(negative):\n total += negative[i].apples\nif i < len(positive):\n total += positive[i].apples\n\nprint(total)\n", "def main():\r\n n = int(input())\r\n liste = []\r\n liste2=[]\r\n liste3=[]\r\n liste4 =[]\r\n roger = 0\r\n random = 0\r\n for loop in range(n):\r\n x,a = map(int,input().split())\r\n liste3.append(x)\r\n liste4.append(a)\r\n if x<0:liste.append(x)\r\n if x>0:liste2.append(x)\r\n roger +=a\r\n liste.sort(reverse=True)\r\n liste2.sort()\r\n if len(liste)==0:\r\n mm = liste3.index(liste2[0])\r\n return liste4[mm]\r\n if len(liste2)==0:\r\n mm = liste3.index(liste[0])\r\n return liste4[mm]\r\n if abs(len(liste)-len(liste2))<=1:\r\n return roger\r\n else:\r\n boot = min(len(liste),len(liste2))\r\n for loop in range(boot):\r\n random += liste4[liste3.index(liste[loop])]\r\n random +=liste4[liste3.index(liste2[loop])]\r\n if len(liste)>len(liste2):\r\n random += liste4[liste3.index(liste[boot])]\r\n if len(liste2)>len(liste):\r\n random +=liste4[liste3.index(liste2[boot])]\r\n return random\r\nprint(main())", "from bisect import bisect\r\nn = int(input())\r\nt = sorted(tuple(map(int, input().split())) for i in range(n))\r\nx = [i[0] for i in t]\r\na = [i[1] for i in t]\r\nk = bisect(x, 0)\r\nif k + k < n:\r\n print(sum(a[:k + k + 1]))\r\nelif k + k > n:\r\n print(sum(a[k + k - n - 1:]))\r\nelse:\r\n print(sum(a))", "def takeOne(elem):\n return elem[0]\n\nnum = int(input())\np = 0\nn = 0\nt = 0\ntrees = []\nfor i in range(num):\n tree = [int(x) for x in input().split()]\n trees.append(tree)\n if tree[0] > 0:\n p += 1\n else:\n n += 1\n t += tree[1]\ntrees.sort(key=takeOne)\nif p < n - 1:\n for i in range(n - 1 - p):\n t -= trees[i][1]\nelif n < p - 1:\n for i in range(p - 1 - n):\n t -= trees[num - 1 - i][1]\nprint (t)\n\t\t\t\t \t \t\t \t\t \t\t\t\t\t \t \t\t \t\t", "n = int(input())\r\n_coords = []\r\n_apples = []\r\nfor i in range(n):\r\n tree = [int(i) for i in input().split()]\r\n _coords += [tree[0]]\r\n _apples += [tree[1]]\r\n\r\ncoords_min = - 100001\r\ncoords_max = 100001\r\n\r\ndef get_next_left_index(coords):\r\n next_left = coords_min\r\n next_left_index = -1\r\n for ind, x in enumerate(coords):\r\n if (x > next_left) and (x < 0):\r\n next_left = x\r\n next_left_index = ind\r\n return next_left_index\r\n\r\ndef get_next_right_index(coords):\r\n next_right = coords_max\r\n next_right_index = -1\r\n for ind, x in enumerate(coords):\r\n if (x < next_right) and (x > 0):\r\n next_right = x\r\n next_right_index = ind\r\n return next_right_index\r\n\r\ndef go(direction, coords, apples):\r\n in_bucket = 0\r\n next_index = 0\r\n if direction == 0:\r\n next_index = get_next_left_index(coords)\r\n elif direction == 1:\r\n next_index = get_next_right_index(coords)\r\n if next_index == -1:\r\n return in_bucket\r\n else:\r\n in_bucket += apples[next_index]\r\n del apples[next_index]\r\n del coords[next_index]\r\n direction = (direction + 1) % 2\r\n return in_bucket + go(direction, coords, apples)\r\n\r\nres = max(go(0, _coords.copy(), _apples.copy()), go(1, _coords.copy(), _apples.copy()))\r\nprint(res)\r\n", "\nn=int(input())\ntrees=[]\nleft=0\nfor _ in range(n):\n trees.append([int(x) for x in input().split()])\n left+=trees[-1][0]<0\n\nright=n-left\ntrees.sort()\nans=0\nif right>=left:\n\n for _ in range(min(left,right)*2+(left!=right)):\n ans+=trees[_][1]\nelse:\n for _ in range(len(trees)-1,len(trees)-min(left,right)*2-2,-1):\n ans+=trees[_][1]\n\nprint(ans)\n", "n=int(input())\r\npos=[]\r\nneg=[]\r\nfor i in range(n):\r\n\tx,y=map(int,input().split())\r\n\tif x<0:\r\n\t\tneg.append([x,y])\r\n\telse:\r\n\t\tpos.append([x,y])\r\npos.sort()\r\nneg.sort(reverse=True)\r\nl1=len(pos)\r\nl2=len(neg)\r\nm=min(l1,l2)\r\ntot=0\r\nfor i in range(m):\r\n\ttot+=neg[i][1]+pos[i][1]\r\nif l1>l2:\r\n\ttot+=pos[m][1]\r\nelif l2>l1:\r\n\ttot+=neg[m][1]\r\nelse:\r\n\tpass\r\nprint(tot)\r\n\t\r\n\t\r\n\t\r\n\t\r\n", "n=int(input());p,t=[],[]\r\nfor i in range(n):\r\n\tx,a=map(int,input().split())\r\n\tif x>0:p.append([x,a])\r\n\telse:t.append([x,a])\r\np.sort();t.sort(reverse=True)\r\nu,v=len(p),len(t);a=0;x,y=0,0\r\nif u==v:x=u;y=v\r\nelif u>v:x=v+1;y=v\r\nelse:x=u;y=u+1\r\nfor i in range(x):a+=p[i][1]\r\nfor i in range(y):a+=t[i][1]\r\nprint(a)", "n=int(input())\nc=[]\nl=[]\nk=[]\nq=0\nw=0\nfor i in range(n):\n x,y=map(int,input().split())\n c.append([x,y])\nc=sorted(c)\nfor i in range(len(c)):\n if(c[i][0]<0):\n k.append(c[i][1])\n else:\n l.append(c[i][1])\nk.reverse()\nif(len(k)==len(l)):\n print(sum(k)+sum(l))\nelse:\n if(len(k)>len(l)):\n print(sum(l)+sum(k[:len(l)])+k[len(l)])\n elif(len(l)>len(k)):\n print(sum(k)+sum(l[:len(k)])+l[len(k)])\n", "\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\ndef solve():\r\n n, = map(int, input().split())\r\n\r\n\r\n r = 0\r\n right = []\r\n l = 0\r\n left = []\r\n\r\n for _ in range(n):\r\n x, v = map(int, input().split())\r\n\r\n if x > 0:\r\n right.append([x, v])\r\n else:\r\n left.append([-x, v])\r\n\r\n right.sort()\r\n left.sort()\r\n\r\n for i in range(1, len(right)):\r\n right[i][1] += right[i-1][1]\r\n for i in range(1, len(left)):\r\n left[i][1] += left[i-1][1]\r\n\r\n if len(right) == len(left):\r\n print(left[-1][1] + right[-1][1])\r\n else:\r\n if not len(left):\r\n print(right[0][1])\r\n elif not len(right):\r\n print(left[0][1])\r\n elif len(right) > len(left):\r\n print(left[-1][1] + right[len(left)][1])\r\n else:\r\n print(right[-1][1] + left[len(right)][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\nsolve()", "n = int(input())\r\ndic = {}\r\n\r\nfor i in range(n):\r\n key, value = [int(x) for x in input().split()]\r\n dic[key] = value\r\n\r\nneg = []\r\npos = []\r\n\r\nfor key in dic:\r\n if key < 0: neg.append((key, dic[key]))\r\n else: pos.append((key, dic[key]))\r\n\r\nneg = sorted(neg, key=lambda x: x[0], reverse=True)\r\npos = sorted(pos, key=lambda x: x[0])\r\nneg = [x[1] for x in neg]\r\npos = [x[1] for x in pos]\r\n\r\nminlen = min(len(neg), len(pos))\r\ntotal = sum(neg[:minlen]) + sum(pos[:minlen])\r\n\r\nif len(neg) > minlen: total += neg[minlen]\r\nelif len(pos) > minlen: total += pos[minlen]\r\nprint(total)", "import sys\r\n\r\ndictionary = {}\r\nvalue = int(input())\r\n\r\nnegatives = 0\r\npositives = 0\r\n\r\nfor i in range(value):\r\n x, y = map(int, input().split())\r\n if x>=0:\r\n positives += 1\r\n elif x<0:\r\n negatives += 1\r\n dictionary[x] = y\r\n\r\nkeylist = dictionary.keys()\r\nkeylist = sorted(keylist)\r\n\r\n\r\nif positives == negatives:\r\n value = sum(dictionary.values())\r\n print(value)\r\n sys.exit()\r\n\r\nelif positives < negatives:\r\n counter = 0\r\n value = 0\r\n for i in keylist[::-1]:\r\n if i>=0:\r\n value += dictionary[i]\r\n else:\r\n if counter==positives+1:\r\n print(value)\r\n sys.exit()\r\n else:\r\n value += dictionary[i]\r\n counter += 1\r\n\r\n\r\nelif positives > negatives:\r\n counter = 0\r\n value = 0\r\n for i in keylist:\r\n if i < 0:\r\n value += dictionary[i]\r\n else:\r\n if counter == negatives + 1:\r\n print(value)\r\n sys.exit()\r\n else:\r\n value += dictionary[i]\r\n counter += 1\r\n\r\n\r\nprint(value)", "num = int(input())\r\nneg = []\r\npos = []\r\nfor x in range(num):\r\n coord, app = map(int,input().split(' '))\r\n if coord < 0:\r\n neg.append([-1*coord,app])\r\n else:\r\n pos.append([coord,app])\r\npos.sort()\r\nneg.sort()\r\nif len(neg)<len(pos):\r\n a = neg\r\n b = pos[:len(neg)+1]\r\nelif len(pos)<len(neg):\r\n a = pos\r\n b = neg[:len(pos)+1]\r\nelse:\r\n a = pos\r\n b = neg\r\ntot = 0\r\nfor i in a:\r\n tot += i[1]\r\nfor i in b:\r\n tot+= i[1]\r\nprint(tot)\r\n", "n = int(input())\r\ntrees_l = []\r\ntrees_r = []\r\n\r\nfor i in range(n):\r\n x, a = (int(x) for x in input().split())\r\n if (x < 0):\r\n trees_l.append((x, a))\r\n else:\r\n trees_r.append((x, a))\r\n\r\ncount = min(len(trees_l), len(trees_r)) + 1\r\n\r\ntrees_l = sorted(trees_l, reverse=True)\r\ntrees_r = sorted(trees_r)\r\n\r\nresult = 0\r\n\r\nfor i in range(min(count, len(trees_l))):\r\n result += trees_l[i][1]\r\nfor i in range(min(count, len(trees_r))):\r\n result += trees_r[i][1]\r\n\r\nprint(result)", "n = int(input())\r\nl = []\r\nr = []\r\nfor i in range(n):\r\n\tx, a = map(int, input().split())\r\n\tif x<0:\r\n\t\tl.append((x,a))\r\n\telse:\r\n\t\tr.append((x,a))\r\nl.sort(reverse=True)\r\nr.sort()\r\ns = 0 \r\nm = min(len(l), len(r)) + 1\r\nfor i in range(m):\r\n\tif i<len(l):\r\n\t\ts+=l[i][1]\r\n\tif i<len(r):\r\n\t\ts+=r[i][1]\r\nprint(s)\r\n", "class CTree:\r\n\tx = 0\r\n\ta = 0\r\n\tseen = 0\r\n\r\nnn = int(input())\r\ntrees = []\r\nn = [0] * 2\r\nfor i in range(0, nn):\r\n\txx, aa = map(int, input().split())\r\n\tTree = CTree()\r\n\tTree.x = xx\r\n\tTree.a = aa\r\n\ttrees.append(Tree)\r\n\tif (xx < 0):\r\n\t\tn[0] += 1\r\n\telse:\r\n\t\tn[1] += 1\r\n\r\ntrees.sort(key = lambda tree: tree.x)\r\nif (n[0] > n[1]):\r\n\tapples = 0\r\n\tfor i in range(len(trees)-1, max(n[0]-n[1]-2, -1), -1):\r\n\t\tapples += trees[i].a\r\n\tprint (apples)\r\nelse:\r\n\tapples = 0\r\n\tfor i in range(0, len(trees)-max(n[1]-n[0]-1, 0)):\r\n\t\tapples += trees[i].a\r\n\tprint (apples)", "n = int(input())\n\npos = []\nneg = []\n\nfor _ in range(n):\n x, a = map(int, input().split())\n if x > 0:\n pos.append((x, a))\n else:\n neg.append((x, a))\n\npos.sort()\nneg.sort(reverse=True)\n\n\ndef merge(ar1, ar2):\n i, j = 0, 0\n ans = []\n while i < len(ar1) and j < len(ar2):\n ans.append(ar1[i][1])\n ans.append(ar2[j][1])\n i += 1\n j += 1\n \n if i < len(ar1):\n ans.append(ar1[i][1])\n\n return ans\n\n\nprint(max(sum(merge(pos, neg)), sum(merge(neg, pos))))\n", "n = int(input())\r\nd1 = []\r\nd0 = []\r\nfor i in range(n):\r\n index, c = map(int, input().split())\r\n if index > 0:\r\n d1.append((index, c))\r\n else:\r\n d0.append((index, c))\r\nd1 = sorted(d1)\r\nd0 = sorted(d0, reverse=1)\r\n\r\nsum0 = 0\r\nfor i in range(min(len(d1), len(d0)+1)):\r\n sum0 += d1[i][1]\r\nfor i in range(min(len(d1), len(d0))):\r\n sum0 += d0[i][1]\r\n \r\nsum1 = 0\r\nfor i in range(min(len(d0), len(d1)+1)):\r\n sum1 += d0[i][1]\r\nfor i in range(min(len(d0), len(d1))):\r\n sum1 += d1[i][1]\r\n\r\nprint(max(sum0, sum1))\r\n", "\r\n\r\n\r\nt=[]\r\nw=[]\r\n\r\n\r\nn = int(input())\r\n\r\np=0\r\nfor i in range(n):\r\n v=list(map(int,input().split()))\r\n\r\n if v[0] == 0:\r\n p+=v[1]\r\n elif v[0] < 0:\r\n w.append(v)\r\n else:\r\n t.append(v)\r\n\r\nt.sort()\r\nw.sort()\r\nt=t[::-1]\r\n\r\nif len(w) > len(t):\r\n o=1\r\nelse:\r\n o=0\r\nwhile True:\r\n if o==0:\r\n if len(t)>0:\r\n p+=t[-1][1]\r\n t.pop()\r\n o=1\r\n else:\r\n break\r\n elif o==1:\r\n if len(w)>0:\r\n p+=w[-1][1]\r\n w.pop()\r\n o=0\r\n else:\r\n break\r\n\r\nprint(p)\r\n\r\n\r\n\r\n", "from operator import itemgetter\n\n\nclass CodeforcesTask558ASolution:\n def __init__(self):\n self.result = ''\n self.n = 0\n self.trees = []\n\n def read_input(self):\n self.n = int(input())\n for x in range(self.n):\n self.trees.append([int(x) for x in input().split(\" \")])\n\n def process_task(self):\n left = [x for x in self.trees if x[0] < 0]\n right = [x for x in self.trees if x[0] > 0]\n left.sort(key=itemgetter(0), reverse=True)\n right.sort(key=itemgetter(0))\n left = [x[1] for x in left]\n right = [x[1] for x in right]\n collected = 0\n l_l = len(left)\n l_r = len(right)\n if l_l == l_r:\n collected = sum(left) + sum(right)\n elif l_l > l_r:\n if l_r:\n collected = sum(right) + sum(left[:l_r + 1])\n else:\n collected = left[0]\n else:\n if l_l:\n collected = sum(left) + sum(right[:l_l + 1])\n else:\n collected = right[0]\n self.result = str(collected)\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask558ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n", "n=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(n):\r\n a,b=list(map(int,input().split()))\r\n if a<0:\r\n l.append([a,b])\r\n else:r.append([a,b])\r\n\r\nl.sort(reverse=True)\r\nr.sort()\r\nl.append([0,0])\r\nr.append([0,0])\r\nc=0\r\nfor (i,j),(k,l) in zip(l,r):\r\n c+=j+l\r\nprint(c)\r\n\r\n", "n=int(input())\r\nleft=0\r\nright=0\r\ntrees=[]\r\napple=0\r\nfor i in range(n):\r\n tree=[int(x) for x in input().split()]\r\n if tree[0]<0:\r\n left+=1\r\n else:\r\n right+=1\r\n trees.append(tree)\r\ntrees.sort(key=lambda x:x[0])\r\nif left==right:\r\n for i in trees:\r\n apple+=i[1]\r\nelif left>right:\r\n for i in range(n-2*right-1,n):\r\n apple+=trees[i][1]\r\nelse:\r\n for i in range(2*left+1):\r\n apple+=trees[i][1]\r\nprint(apple)\r\n", "from sys import stdin\nfrom collections import deque\nfrom math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin\ndef ii(): return int(stdin.readline())\ndef fi(): return float(stdin.readline())\ndef mi(): return map(int, stdin.readline().split())\ndef fmi(): return map(float, stdin.readline().split())\ndef li(): return list(mi())\ndef lsi():\n\tx=list(stdin.readline())\n\tx.pop()\n\treturn x\ndef si(): return stdin.readline()\np=[]\nn=[]\nfor _ in range(ii()):\n\tx, y=mi()\n\tif x<0:\n\t\tx=-x\n\t\tn.append([x, y])\n\telse:\n\t\tp.append([x, y])\np.sort()\nn.sort()\nx=len(p)\ny=len(n)\nsp=[0]\nsn=[0]\nfor i in range(x):\n\tsp.append(p[i][1]+sp[i])\n\nfor i in range(y):\n\tsn.append(n[i][1]+sn[i])\nif x<y:\n\ta=max(sp[x]+sn[x+1], sp[x-1]+sn[x])\nelif x>y:\n\ta=max(sp[y+1]+sn[y], sp[y]+sn[y-1])\nelse:\n\ta=sp[x]+sn[y]\nprint(a)\n\t \t \t \t \t \t \t\t\t\t\t\t\t\t", "N = int(input())\nplus = []\nminus = []\nfor i in range(N):\n pos, x = map(int, input().split())\n if pos > 0:\n plus.append((-pos, x))\n else:\n minus.append((pos, x))\n\nplus.sort()\nminus.sort()\nd = True if len(plus) > len(minus) else False\nans = 0\nwhile True:\n if d:\n if not plus: break\n _, x = plus.pop()\n ans += x\n d = False\n else:\n if not minus: break\n _, x = minus.pop()\n ans += x\n d = True\nprint(ans)\n \n", "left = []\r\nright = []\r\nfor i in range(0,int(input())):\r\n a,b = map(int,input().split())\r\n if(a<0):\r\n left.append([-a,b])\r\n else:\r\n right.append([a,b])\r\nleft.sort()\r\nright.sort()\r\n\r\nm = min(len(left),len(right))\r\nprint(sum(c[1] for c in left[:m+1]) + sum(c[1] for c in right[:m+1]))", "#!/usr/bin/env/python\r\n# -*- coding: utf-8 -*-\r\nm = int(input())\r\nr = [[], []]\r\nfor _ in range(m):\r\n x, a = list(map(int, input().split()))\r\n r[x > 0].append([x, a])\r\nr[0] = sorted(r[0], key=lambda xx: -xx[0])\r\nr[1] = sorted(r[1], key=lambda xx: xx[0])\r\n# print(r)\r\nln = min(len(r[0]), len(r[1]))\r\nres = 0\r\nfor i in range(ln + 1):\r\n if i < len(r[0]):\r\n res += r[0][i][1]\r\n if i < len(r[1]):\r\n res += r[1][i][1]\r\nprint(res)\r\n", "n = int(input())\n\nlp, rp = [], []\nl, r = [], []\n\nfor i in range(n):\n\tx, v = [int(i) for i in input().split()]\n\tif x < 0:\n\t\tx = abs(x)\n\t\tfor j in range(len(lp)):\n\t\t\tif lp[j] > x:\n\t\t\t\tlp = lp[:j] + [x] + lp[j:]\n\t\t\t\tl = l[:j] + [v] + l[j:]\n\t\t\t\tbreak\n\t\telse:\n\t\t\tlp.append(x)\n\t\t\tl.append(v)\n\telse:\n\t\tfor j in range(len(rp)):\n\t\t\tif rp[j] > x:\n\t\t\t\trp = rp[:j] + [x] + rp[j:]\n\t\t\t\tr = r[:j] + [v] + r[j:]\n\t\t\t\tbreak\n\t\telse:\n\t\t\trp.append(x)\n\t\t\tr.append(v)\n\nif len(l) == len(r):\n\tprint(sum(l) + sum(r))\nelse:\n\tif len(l) > len(r):\n\t\tm1 = l\n\t\tm2 = r\n\telse:\n\t\tm1 = r\n\t\tm2 = l\n\n\tprint(sum(m2) + sum(m1[:len(m2)+1]))\n" ]
{"inputs": ["2\n-1 5\n1 5", "3\n-2 2\n1 4\n-1 3", "3\n1 9\n3 5\n7 10", "1\n1 1", "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000", "1\n-1 1", "27\n-30721 24576\n-6620 92252\n88986 24715\n-94356 10509\n-6543 29234\n-68554 69530\n39176 96911\n67266 99669\n95905 51002\n-94093 92134\n65382 23947\n-6525 79426\n-448 67531\n-70083 26921\n-86333 50029\n48924 8036\n-27228 5349\n6022 10691\n-13840 56735\n50398 58794\n-63258 45557\n-27792 77057\n98295 1203\n-51294 18757\n35037 61941\n-30112 13076\n82334 20463", "18\n-18697 44186\n56333 51938\n-75688 49735\n77762 14039\n-43996 81060\n69700 49107\n74532 45568\n-94476 203\n-92347 90745\n58921 44650\n57563 63561\n44630 8486\n35750 5999\n3249 34202\n75358 68110\n-33245 60458\n-88148 2342\n87856 85532", "28\n49728 91049\n-42863 4175\n-89214 22191\n77977 16965\n-42960 87627\n-84329 97494\n89270 75906\n-13695 28908\n-72279 13607\n-97327 87062\n-58682 32094\n39108 99936\n29304 93784\n-63886 48237\n-77359 57648\n-87013 79017\n-41086 35033\n-60613 83555\n-48955 56816\n-20568 26802\n52113 25160\n-88885 45294\n22601 42971\n62693 65662\n-15985 5357\n86671 8522\n-59921 11271\n-79304 25044", "25\n5704 67795\n6766 31836\n-41715 89987\n76854 9848\n11648 90020\n-79763 10107\n96971 92636\n-64205 71937\n87997 38273\n-9782 57187\n22186 6905\n-41130 40258\n-28403 66579\n19578 43375\n35735 52929\n-52417 89388\n-89430 1939\n9401 43491\n-11228 10112\n-86859 16024\n-51486 33467\n-80578 65080\n-52820 98445\n-89165 7657\n-97106 79422", "16\n-41732 47681\n44295 28942\n-75194 99827\n69982 18020\n-75378 22026\n80032 22908\n-34879 41113\n36257 48574\n-35882 84333\n29646 71151\n-86214 80886\n72724 39364\n-42529 60880\n29150 29921\n-8471 80781\n79387 70834", "3\n-94146 4473\n28707 99079\n-4153 8857", "3\n-3 3\n-2 2\n-1 1", "2\n100000 3\n-100000 9", "2\n-100000 100000\n100000 99999"], "outputs": ["10", "9", "9", "1", "300000", "1", "1036452", "632240", "891593", "1109655", "847241", "112409", "1", "12", "199999"]}
UNKNOWN
PYTHON3
CODEFORCES
152
172d355f207b1c6d888955b4a88727e9
Mahmoud and Longest Uncommon Subsequence
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself. The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*. Sample Input abcd defgh a a Sample Output 5 -1
[ "s1 = input()\r\ns2 = input()\r\n\r\nif s1 == s2:\r\n print(-1)\r\nelif len(s1) > len(s2):\r\n print(len(s1))\r\nelif len(s2) > len(s1):\r\n print(len(s2))\r\nelse:\r\n print(len(s1))", "def solve():\n a = input()\n b = input()\n print(-1 if a == b else max(len(a), len(b)))\n \nt = 1 #int(input())\nfor i in range(t):\n #print(f\"Case #{i+1}:\", end=\" \")\n\tsolve()\n", "# Online Python compiler (interpreter) to run Python online.\n# Write Python 3 code in this online editor and run it.\nstr1 = input()\nstr2 = input()\n\nif str1 == str2:\n print(-1)\nelse:\n print(max(len(str1), len(str2)))\n\n\t \t \t\t \t \t \t\t \t \t\t \t\t\t", "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 a = input()\n b = input()\n la, lb = len(a), len(b)\n if la > lb:\n print(la)\n elif lb > la:\n print(lb)\n else:\n if a == b:\n print(-1)\n else:\n print(la)\n\n\nif __name__ == \"__main__\":\n main()\n", "n = input()\r\nm = input()\r\nans = -1 if n == m else max(len(n), len(m))\r\nprint(ans)\r\n", "a=input()\r\na1=len(a)\r\nb=input()\r\nb1=len(b)\r\nif a==b:\r\n print(-1)\r\nelse :\r\n print(max(a1,b1))", "\r\n\r\narr = []\r\narr.append( input().strip() )\r\narr.append( input().strip() )\r\n\r\n## first one and last\r\nif(arr[0]==arr[1]):\r\n print(-1)\r\nelse:\r\n print(max(len(arr[0]),len(arr[1])))", "m = input()\ne = input()\nprint(-1 if m == e else max(len(m),len(e)))", "m=input()\r\nn=input()\r\nif m==n:\r\n print(-1)\r\nelse:\r\n print(max(len(m),len(n)))", "s=input()\r\nb=input()\r\na=len(s)\r\nk=len(b)\r\nif b==s:\r\n print(-1)\r\nelse:\r\n print(max(a,k))", "a = input()\nb = input()\nif a == b:\n print(-1)\nelse:\n print(max(len(a), len(b)))", "\"\"\"Date: 2023-11-03 10:53:25.053247\nProblem: Codeforces 766A\nAuthor: pkr1012\n\"\"\"\n\ndef main():\n a = input()\n b = input()\n if (a == b): print(-1)\n else: print(max(len(a), len(b)))\n\nif __name__ == \"__main__\":\n main()\n\n", "import sys\r\ninput = sys.stdin.buffer.readline \r\n\r\nS = input().decode().strip()\r\nT = input().decode().strip()\r\nif S==T:\r\n answer = -1\r\nelse:\r\n answer = max(len(S), len(T))\r\nsys.stdout.write(f'{answer}\\n')", "a = input()\r\nb = input()\r\n\r\nm = max(len(b), len(a))\r\n\r\nif b not in a or a not in b:\r\n print(m)\r\nelse:\r\n print(-1)\r\n", "a, b = (input() for _ in range(2))\nres = -1 if a == b else max(len(a), len(b))\nprint(res)\n", "a,b=input(),input()\nprint(-1 if a==b else max(len(a),len(b)))\n\t \t\t\t\t\t\t \t \t \t\t\t \t \t\t \t", "s=input()\r\ns2=input()\r\nif s==s2:\r\n print(-1)\r\nelse:\r\n print((max([len(s),len(s2)]))) ", "def find_longest_uncommon_subsequence(a, b):\r\n # If the two strings are equal, there is no uncommon subsequence.\r\n if a == b:\r\n return -1\r\n # Otherwise, return the length of the longer string as the longest uncommon subsequence.\r\n return max(len(a), len(b))\r\n\r\n# Read input\r\na = input().strip()\r\nb = input().strip()\r\n\r\n# Find the length of the longest uncommon subsequence and print the result\r\nresult = find_longest_uncommon_subsequence(a, b)\r\nprint(result)\r\n", "a = input()\r\nb = input()\r\nprint(-1) if a == b else print(max(len(a),len(b)))", "#https://codeforces.com/problemset/problem/766/A\nfrom sys import stdin,stdout\n\ndef fin():\n\treturn stdin.readline()\n#\tNOTE:when taking string input through this, the length of string will be 1 extra(because the newline character gets included. So, to get the actual string length of the string taken input through this function, use \"len(s)-1\"\n\ndef fout(x=\"\",end=\"\\n\"):\n\tstdout.write(str(x)+str(end))\n\ns=fin()\nt=fin()\nif s==t:\n\tfout(-1)\nelse:\n\tfout(str(max(len(s)-1,len(t)-1)))\n", "string1,string2 = input(),input()\r\nprint([-1,max(len(string1),len(string2))][string1!=string2])", "s1,s2 = input(),input()\r\n\r\nif s1 != s2:\r\n print(max(len(s1), len(s2)))\r\nelif s1==s2:\r\n print(-1)\r\nelse:\r\n print(len(s1))\r\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\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# def solve():\r\n \r\ns1 = st()\r\ns2 = st()\r\nif s1==s2:\r\n print(-1)\r\nelse:\r\n print(max(len(s1),len(s2)))\r\n\r\n\r\n\r\n \r\n# # ---- CHECK FOR CORNER CASES ----\r\n \r\n# for _ in range(inp()):\r\n# solve()", "a=input()\r\nb=input()\r\nif a==b:\r\n print(\"-1\")\r\nelse:\r\n x=len(a)\r\n z=len(b)\r\n print(max(x,z))", "str1 = input()\r\nstr2 = input()\r\nif str1 == str2 :\r\n print(-1)\r\nelse:\r\n if len(str1)>len(str2):\r\n print(len(str1))\r\n else:\r\n print(len(str2))\r\n", "a = str(input())\r\nb = str(input())\r\nif a == b:\r\n print (-1)\r\nelse:\r\n print (max (len(b), len(a)))", "\"\"\" Created by Henrikh Kantuni on 2/7/17 \"\"\"\n\na = input()\nb = input()\nans = -1 if a == b else max(len(a), len(b))\nprint(ans)\n", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\na = list(input().rstrip())\r\nb = list(input().rstrip())\r\nif len(a) ^ len(b):\r\n ans = max(len(a), len(b))\r\nelse:\r\n ans = -1\r\n for i, j in zip(a, b):\r\n if i ^ j:\r\n ans = len(a)\r\n break\r\nprint(ans)", "a, b = input(), input()\r\nif a==b:\r\n print(-1)\r\nelif (len(a)>len(b)):\r\n print(len(a))\r\nelse:\r\n print(len(b))", "s1 = input()\r\ns2 = input()\r\nn, m = len(s1), len(s2)\r\nif s1 == s2:\r\n print(-1)\r\n\r\nelse:\r\n if n > m:\r\n print(n)\r\n\r\n else:\r\n print(m)\r\n\r\n", "a, b = input(), input()\nprint([-1, max(len(a), len(b))][a != b])", "a=input();m=len(a)\r\nb=input();n=len(b)\r\nif m>n:\r\n print(m)\r\nelif n>m:\r\n print(n)\r\nelif a==b:\r\n print(-1)\r\nelse:\r\n condition=False\r\n for i in range(m,0,-1):\r\n if condition==True:\r\n break\r\n else:\r\n for j in range(m+1):\r\n try:\r\n if a[j:i+j] in b:\r\n continue\r\n else:\r\n print(len(a[j:i+j]))\r\n condition=True\r\n break\r\n except:\r\n break", "import sys\r\nfrom collections.abc import Callable\r\n\r\n\r\ndef fn() -> None:\r\n read: Callable[[], str] = sys.stdin.readline\r\n a = read()[:-1]\r\n b = read()[:-1]\r\n # If a == b, then there cannot be an uncommon subsequence\r\n # However, if a != b, then that by default is the longest uncommon subsequence given that a cannot be a subsequence of b and viceversa\r\n longest_uncommon_subsequence = -1 if a == b else max(len(a), len(b))\r\n print( longest_uncommon_subsequence)\r\n\r\n\r\nif __name__ == '__main__':\r\n fn()\r\n", "n1 = input()\r\nn2 = input()\r\nif n1 == n2:\r\n print(-1)\r\nelse:\r\n if len(n1) >= len(n2):\r\n print(len(n1))\r\n else:\r\n print(len(n2))", "text1 = input()\r\ntext2 = input()\r\ncopy = 0\r\nlength1 = 0\r\nlength2 = 0\r\ncountCopy = int(text1.count(text2))\r\ncountCopy2 = int(text2.count(text1))\r\nif countCopy>0:\r\n copy = -1\r\nelif len(text1) >= len(text2) :\r\n length1 = len(text1)\r\nelse :\r\n length1 = len(text2)\r\nif countCopy2 >0:\r\n copy = -1\r\nelif len(text1) >= len(text2) :\r\n length2 = len(text1)\r\nelse :\r\n length2 = len(text2)\r\nif length1 != 0:\r\n print(length1)\r\nelif length2 != 0:\r\n print(length2)\r\nelse : print(copy)", "a,b=input(),input();print(max(len(a),len(b))if(a!=b)else-1)\n\t\t\t\t\t \t\t \t \t \t \t \t\t\t \t", "a = input()\r\nb = input()\r\nresult = 0\r\nif a == b:\r\n result = -1\r\nelse:\r\n result = max(len(a),len(b))\r\nprint(result)", "def find_longest_uncommon_subsequence(str1, str2):\r\n if str1 == str2:\r\n return -1\r\n else:\r\n return max(len(str1), len(str2))\r\n\r\nstring1 = input()\r\nstring2 = input()\r\nresult = find_longest_uncommon_subsequence(string1, string2)\r\nprint(result)\r\n\r\n", "'''\r\n# Submitted By [email protected]\r\nDon't Copy This Code, Try To Solve It By Yourself\r\n'''\r\n# Problem Name = \"Mahmoud and Longest Uncommon Subsequence\"\r\n# Class: A\r\n\r\nimport sys\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 s1 = input().strip()\r\n s2 = input().strip()\r\n if s1==s2:\r\n print(-1)\r\n else:\r\n print(max(len(s1), len(s2)))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n Solve()", "strings = [input(), input()]\r\nstrings = list(sorted(strings, key=lambda x: len(x), reverse=True))\r\n\r\nlongest_uncommon_subsequence = len(strings[0])\r\nif strings[0] == strings[1]:\r\n longest_uncommon_subsequence = -1\r\nprint(longest_uncommon_subsequence)", "ri=lambda:map(int,input().split())\r\nimport math\r\ndef f():\r\n a=input()\r\n b=input()\r\n if a==b:\r\n print(-1)\r\n return 0\r\n print(max(len(a),len(b)))\r\nf()\r\n \r\n \r\n \r\n", "a,b=input(),input();print([-1,max(len(a),len(b))][a!= b])", "n=input()\r\ns=input()\r\nprint([max(len(n),len(s)),-1][n==s])", "s = input()\r\ns1 = input()\r\nif s == s1:\r\n print(-1)\r\nelse:\r\n print(len(max(s, s1, key=len)))", "a = input()\r\nb = input()\r\n\r\nif len(a) == len(b):\r\n if a == b:\r\n flag = -1\r\n else:\r\n flag = len(a)\r\nelif len(a) > len(b):\r\n flag = len(a)\r\nelse:\r\n flag = len(b)\r\n\r\nprint(flag)", "# https://codeforces.com/problemset/problem/766/A\n\ndef handle():\n word_one = input()\n word_two = input()\n\n if len(word_one) == len(word_two):\n if word_one == word_two:\n return -1\n else:\n return len(word_one)\n\n return max(len(word_one), len(word_two))\n\nprint(handle())", "s1 = input()\ns2 = input()\nif s1 == s2: print(-1)\nelse: print(max(len(s1),len(s2)))\n\t \t\t\t \t \t\t \t \t \t \t\t \t\t", "def solve(): \r\n st=input()\r\n st1=input()\r\n if st==st1:\r\n print(-1)\r\n else:\r\n if len(st1)<len(st):\r\n st1,st=st,st1;\r\n print(len(st1))\r\n\r\n\r\n\r\nsolve()", "s1=input()\r\ns2=input()\r\n\r\nif s1 ==s2:\r\n print(-1) \r\nelse:print(max(len(s1),len(s2)))", "str1 = input() \r\nstr2 = input() \r\nc = len(str1) \r\np = len(str2) \r\nv = [c,p]\r\nif str1 == str2 : \r\n print(-1) \r\nelse : \r\n print(max(v))\r\n ", "a = list(map(str, input()))\r\nb = list(map(str, input()))\r\n\r\n\r\ndef not_mine(a, b):\r\n if a == b:\r\n return -1\r\n if len(a) == len(b):\r\n return len(a)\r\n if len(a) != len(b):\r\n return max(len(a), len(b))\r\n\r\nprint(not_mine(a, b))", "s = input()\r\nt = input()\r\nif len(s) != len(t):\r\n print(max(len(s), len(t)))\r\nelif s != t:\r\n print(len(t))\r\nelse:\r\n print(-1)", "\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\na = input()\r\nb = input()\r\nla = len(a)\r\nlb = len(b)\r\n\r\nif la > lb:\r\n print(la)\r\nelif la < lb:\r\n print(lb)\r\nelif a == b: # a and b are the same string\r\n print(-1)\r\nelse: # a and b differs so a doesnt contain in b\r\n print(la)\r\n", "\r\n\r\ndef solve(s1: str, s2: str) -> str:\r\n if s1==s2: \r\n return(\"-1\")\r\n else:\r\n return(max(len(s1),len(s2)))\r\n\r\ns1=input()\r\ns2=input()\r\nprint(solve(s1, s2))\r\n ", "s_1 = input()\r\ns_2 = input()\r\nif s_1 == s_2:\r\n print(-1)\r\nelse:\r\n print(max(len(s_1), len(s_2)))", "a = input()\nb = input()\n\nm = len(a)\nn = len(b)\n\nif a == b:\n\tprint(-1)\nelse:\n\tprint(max(m, n))\n \t\t \t\t\t\t\t\t\t\t\t \t\t\t\t \t \t\t\t \t \t \t", "a = input()\r\nb = input()\r\nsize = [len(a),len(b)]\r\nif a == b :\r\n print(-1)\r\nelse:\r\n print(max(size))\r\n", "n=input()\r\ns=input()\r\nif n==s:\r\n print(-1)\r\nelse:\r\n print(max(len(n),len(s)))", "a=input()\r\nb=input()\r\n \r\nif(len(a)<len(b)):\r\n a,b=b,a\r\n \r\nif(a!=b):\r\n print (len(a))\r\nelse:\r\n print(-1)", "str1 = input()\nstr2 = input()\n\nif str1 == str2:\n\tprint(\"-1\")\nelse:\n\tm = len(str1) if len(str1) > len(str2) else len(str2)\n\tprint(m)\n", "l=list(input())\r\nl1=list(input())\r\nif l==l1:\r\n print(-1)\r\nelif len(l)==len(l1):\r\n print(len(l))\r\nelse:\r\n if len(l)>len(l1):\r\n print(len(l))\r\n else:\r\n print(len(l1))", "# ██████╗\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\nprint = sys.stdout.write\r\n\r\n\r\ns1 = input().strip()\r\ns2 = input().strip()\r\nif s1 == s2:\r\n print(str(-1))\r\nelse:\r\n print(str(max(len(s1), len(s2))))\r\n", "a,b=input(),input();print(max(len(a),len(b))if not(a==b)else\"-1\")\n \t\t\t\t \t \t\t\t\t\t\t\t\t \t \t \t \t", "st_1 = str(input())\r\nst_2 = str(input())\r\nset_st1 = set(st_1)\r\nset_st2 = set(st_1)\r\n\r\nsum_st1 = 0\r\nsum_st2 = 0\r\n\r\nfor i in set_st1:\r\n sum_st1 += ord(i)\r\n\r\nfor j in set_st2:\r\n sum_st2 += ord(j)\r\n\r\nif sum_st1 != sum_st2:\r\n print(max(len(st_1),len(st_2)))\r\nelif st_1 != st_2:\r\n print(max(len(st_2),len(st_1)))\r\nelse: print(-1)", "s=input()\r\ns1=input()\r\nl=len(s)\r\nl1=len(s1)\r\nif s==s1:\r\n print(-1)\r\nelif l1>=l:\r\n print(l1)\r\nelse:\r\n print(l)", "a = input()\r\nb = input()\r\nans = -1 if a == b else max(len(a), len(b))\r\nprint(ans)", "a=input()\r\nb=input()\r\nif a==b:\r\n print(-1)\r\nelse:\r\n c=len(a) if len(a)>len(b) else len(b)\r\n print(c)\r\n", "import math\r\nimport sys\r\ndef I(): return int(input())\r\ndef II(): return map(int, input().split())\r\ndef IL(): return list(map(int, input().split()))\r\ndef SIL(): return sorted(map(int, input().split()))\r\ndef RSIL(): return sorted(map(int, input().split()), reverse=True)\r\nfrom collections import defaultdict\r\nfrom collections import Counter\r\nfrom collections import deque\r\nfrom heapq import heapify ,heappop , heappush,heappushpop,heapreplace,_heapify_max ,nlargest ,nsmallest\r\nimport copy\r\n\r\nsys.setrecursionlimit(2500)\r\n\r\n\r\ndef solve():\r\n a = input()\r\n b = input()\r\n\r\n if len(a) > len(b):\r\n print(len(a))\r\n elif len(b) > len(a):\r\n print(len(b))\r\n elif a == b:\r\n print(-1)\r\n else:\r\n print(len(a))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nT = 1\r\nfor ___ in range(T):\r\n solve()\r\n", "a,b=input(),input()\r\nprint(max(len(a),len(b))*(a!=b)-(a==b))", "s1 = input()\ns2 = input()\n\nif s1 == s2:\n print(-1)\nelif s1 != s2 and len(s1) == len(s2):\n print(len(s1))\nelse:\n print(max(len(s1), len(s2)))\n", "if __name__ == \"__main__\":\n s1 = input()\n s2 = input()\n m = len(s1)\n n = len(s2)\n if s1 == s2:\n print(\"-1\")\n else:\n if m > n:\n print(m)\n else:\n print(n)\n \t \t\t \t\t\t\t \t \t\t \t \t\t \t", "a , b= input(), input()\r\nprint(-1 if a==b else max(len(a), len(b)))", "def find(a, b):\r\n if a == b:\r\n return -1\r\n else:\r\n return max(len(a), len(b))\r\n \r\na = input()\r\nb = input()\r\nresult = find(a, b)\r\nprint(result)", "a = input()\nb = input()\nif a == b:\n print(-1)\nelse:\n print(len(max([a,b],key = len)))\n", "#!/usr/bin/env python3\r\n# -*- coding: utf-8 -*-\r\n#\r\n# ------------------------------------------------------------------------------\r\n# Author: Mohammad Mohsen\r\n# Date: Tue Feb 8 17:55:30 2022\r\n# problem name: Mahmoud_and_Longest_Uncommon_Subsequence\r\n# contest: 766-Codeforces Round #396 (Div. 2)\r\n# problem difficulty: A-D2\r\n# problem url: https://codeforces.com/contest/766/problem/A\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 string_a: str = input().strip()\r\n string_b: str = input().strip()\r\n\r\n if string_a == string_b:\r\n print(-1, file=out_file)\r\n else:\r\n print(max((len(string_a), len(string_b))), file=out_file)\r\n\r\n return out_file.getvalue()\r\n\r\nproblem = Problem(\"Mahmoud_and_Longest_Uncommon_Subsequence\")\r\n\r\nif __name__ == \"__main__\":\r\n solution: Union[str, int, float] = problem.solution()\r\n print(solution)\r\n\r\n", "s = sorted([input(), input()], key=len)\r\ns1 = s[1]\r\ns2 = s[0]\r\nif s1 == s2:\r\n print(-1)\r\nelse:\r\n print(len(s1))\r\n", "a=input()\r\nb=input()\r\nif a==b:\r\n print(-1)\r\nelse:\r\n la=len(a)\r\n lb=len(b)\r\n if la==lb:\r\n print(la)\r\n elif la>lb:\r\n print(la)\r\n else:\r\n print(lb)\r\n", "a,b=input(),input()\r\nif a==b :\r\n print(-1)\r\nelse :print(max(len(a),len(b)))", "import sys,random,bisect\r\nfrom collections import deque,defaultdict\r\nfrom heapq import heapify,heappop,heappush\r\nfrom math import gcd\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\nii = lambda :int(input())\r\n \r\n\r\na=input()\r\nb=input()\r\n\r\nif len(a)>len(b) or len(b)>len(a):\r\n print(max(len(a),len(b)))\r\nelse:\r\n if a==b:\r\n print(-1)\r\n else:\r\n print(len(a))\r\n\r\n\r\n", "a, b = input(), input()\nif a == b:\n print(-1)\nelse:\n print(len(a)) if len(a) > len(b) else print(len(b))\n ", "a = input ()\r\nb = input ()\r\nif a == b:\r\n print (-1)\r\nelse:\r\n print (max (len (a), len (b)))", "#li = list(map(int, input().strip().split()))\n#s = input()\n#m = input()\n\na = input()\nb = input()\n\nif a == b:\n\tprint(-1)\nelse:\n\tprint(max(len(a), len(b)));\n", "a,b = input(),input()\r\nif a == b:print(-1)\r\nelse:print(max(len(a),len(b)))", "a = input()\r\nb = input()\r\ncounter = 0\r\n\r\n# shehab amira je hosnyM\r\n# amir hosnyM\r\nif a == b :\r\n print(-1)\r\nelse :\r\n print(max(len(a),len(b)))", "a=input()\r\nb=input()\r\nprint([max(len(a),len(b)),-1][a==b])", "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\n\r\ndef solve():\r\n a = input()\r\n b = input()\r\n\r\n if len(a) > len(b):\r\n a, b = b, a\r\n\r\n if a == b:\r\n print(-1)\r\n else:\r\n print(len(b))\r\n\r\n # print(li)\r\n\r\n\r\nq = 1\r\n# q = int(input())\r\nfor i in range(q):\r\n solve()\r\n", "\r\nw1 = input()\r\nw2 = input()\r\nwords = sorted([w1, w2], key=len)\r\n\r\nif w1 != w2:\r\n print(len(words[1]))\r\nelse:\r\n print(-1)", "s1=input()\r\ns2=input()\r\nif s1==s2:\r\n print(-1)\r\nelse:\r\n print(max(len(s1),len(s2)))", "a=input()\r\nb=input()\r\ndef find_substrings(s):\r\n return [s[i:j] for i in range(len(s)) for j in range(i+1, len(s)+1)]\r\nif a==b :\r\n print(-1)\r\n exit()\r\nelif (b not in a) or( a not in b):\r\n print(max(len(a),len(b)))\r\n exit()\r\nl=find_substrings(b)\r\nlent=0\r\nfor i in l:\r\n if i not in a and lent<len(i):\r\n lent=len(i)\r\n\r\nprint(lent)\r\n\r\n\r\n\r\n\r\n", "a = str(input())\r\nb = str(input())\r\nif a == b:\r\n print(-1)\r\nelif a not in b and b not in a:\r\n print(max(len(a),len(b)))\r\nelse:\r\n if b in a:\r\n print(len(a))\r\n else:\r\n print(len(b))", "s1=input()\r\ns2=input()\r\nif len (s1) != len (s2):\r\n print(max(len(s1),len(s2)))\r\nelif s1 == s2 :\r\n print(-1)\r\n\r\nelif len (s1) == len (s2):\r\n print(len(s1))", "a = input()\nb = input()\nans = -1 if a == b else max(len(a), len(b))\nprint(ans)\n\t\t \t\t\t\t\t \t \t \t \t \t \t\t \t\t \t\t", "a1=input()\r\nb1=input()\r\nif a1!=b1:\r\n print(max(len(a1),len(b1)))\r\nelse:\r\n print(-1)", "a=input()\nb=input()\nif(a==b):\n\tprint(-1)\nelse:\n\tprint(max(len(a),len(b)))\n \t\t \t\t \t\t\t\t \t \t \t\t\t \t \t", "from sys import stdin\r\nstr1 = stdin.readline().strip()\r\nstr2 = stdin.readline().strip()\r\nflag = True\r\nif str1 != str2:\r\n if len(str1) > len(str2):\r\n print(len(str1))\r\n else:\r\n print(len(str2))\r\nelse:\r\n print(-1)", "word1 = input()\r\nword2 = input()\r\n\r\nlen_word1 = len(word1)\r\nlen_word2 = len(word2)\r\n\r\n\r\nif len_word2 > len_word1:\r\n print(len_word2)\r\nelif len_word1> len_word2:\r\n print(len_word1)\r\n\r\nelif len_word2 == len_word1 and word1 == word2:\r\n print(-1)\r\n\r\nelif len_word2 == len_word1 and word1 != word2:\r\n print(len_word1)\r\n", "a,b=input(),input();print(max(len(a),len(b))if not(a==b)else-1)\n\t\t \t \t\t\t \t \t\t\t\t\t \t\t \t \t\t \t", "s = input().strip()\nt = input().strip()\n\nif s != t:\n print(max(len(s), len(t)))\nelse:\n print(-1)\n\t\t \t\t \t\t \t \t\t \t \t \t\t\t \t", "a = input().strip()\nb = input().strip()\nif a == b:\n\tprint(-1)\nelse:\n\tprint(max(len(a), len(b)))\n \t\t\t \t \t\t \t\t \t\t\t\t\t\t", "#n, m, k =map(int,input().split())\r\n\r\na = list(input())\r\n\r\nb = list(input())\r\n\r\nif(a==b):\r\n print(-1)\r\nelse:\r\n print(max(len(a),len(b)))\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "x=input()\r\nx2=input()\r\n\r\nif (x) == (x2):\r\n print(-1)\r\nelse:\r\n print(max(len(x),len(x2)))", "a=input()\r\nb=input()\r\nc=len(a)\r\nd=len(b)\r\nif(c==d and a==b):\r\n print(-1)\r\nelse:\r\n print(max(c,d))", "import sys \r\n#input = sys.stdin.readline\r\ns = input () \r\nn = input() \r\n#aaaaaa\r\n#aaaaaa\r\nif s == n: \r\n print (-1)\r\nelse:\r\n print (len(s)) if len(s) > len (n) else print (len(n)) \r\n\r\n", "n, m = input(), input();print([-1,max(len(n) , len(m))][n!=m])\r\n", "a, b = input(), input()\r\nprint(-1) if a == b else print(max(len(a), len(b)))", "x,xx = input(),input()\r\nprint(-1 if x == xx else max(len(x),len(xx)))", "str_one = input()\r\nstr_two = input()\r\nif str_one == str_two:\r\n print('-1')\r\nelse:\r\n print(max(len(str_one), len(str_two)))", "s = input()\r\nt = input()\r\nif(s==t): print(-1)\r\nelse: print(max(len(s),len(t)))", "def main(n,a):\r\n if(s1==s2):\r\n print(-1)\r\n else:\r\n print(max(len(s1),len(s2)))\r\n \r\n \r\nif __name__== \"__main__\" :\r\n s1=input()\r\n s2=input()\r\n main(s1,s2)", "First_string = input()\r\nSecond_string = input()\r\n\r\nif First_string == Second_string:\r\n print(-1)\r\nelif First_string != Second_string:\r\n print(len(max(First_string,Second_string,key = len)))", "a = input(); b = input(); print(-1) if a == b else print(max(len(a), len(b)))", "a=input()\r\nb=input()\r\nk=len(b)\r\nl=len(a)\r\ni=0\r\ncount=0\r\nif a==b:\r\n print(\"-1\")\r\nelse:\r\n if l>k:\r\n print(l)\r\n else:\r\n print(k)\r\n", "s1 = input()\ns2 = input()\nprint(-1 if s1 == s2 else max(map(len, [s1, s2])))\n", "a = input()\nb = input()\ncnt = 0\nif a == b:\n cnt-=1\nelse:\n cnt = max(len(a), len(b))\nprint(cnt)", "word1 = input()\r\nword2 = input()\r\n\r\nif word1 == word2: \r\n print(-1)\r\nelse:\r\n print(max(len(word1),len(word2)))", "a=input()\r\nb=input()\r\nprint([-1,max(len(a),len(b))][len(a)!=len(b) or a!=b])", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\ns = input()[:-1]\r\nw = input()[:-1]\r\nif s == w:\r\n print(-1)\r\nelse:\r\n print(len(s) if len(s) >= len(w) else len(w))", "str1 = input().strip()\r\nstr2 = input().strip()\r\n\r\nif str1 != str2:\r\n mx = max(len(str1),len(str2))\r\n print(mx)\r\nelse:\r\n print(-1)", "a=input()\r\nb=input()\r\nif a==b:print(-1)\r\nelse: print(max(len(a),len(b)))\r\n", "from sys import stdin, stdout\r\na = stdin.readline().strip()\r\nb = stdin.readline().strip()\r\nif a==b:\r\n stdout.write(f\"{-1}\\n\")\r\nelse:\r\n stdout.write(f\"{len(a) if len(a)>len(b) else len(b)}\\n\")", "a=list(input())\r\nb=list(input())\r\nif a==b:\r\n print(-1)\r\n exit()\r\nelse:\r\n print(max(len(a),len(b)))\r\n", "a = input()\r\nb = input()\r\nla = len(a)\r\nlb = len(b)\r\nif la == lb:\r\n if a==b:\r\n print('-1')\r\n else:\r\n print(la)\r\nelse:\r\n if la > lb:\r\n print(la)\r\n else:\r\n print(lb)", "value1=input()\r\nvalue2=input()\r\nif value1==value2:\r\n print(-1)\r\nelif len(value1)>len(value2):\r\n print(len(value1))\r\n\r\nelse:\r\n print(len(value2)) \r\n \r\n\r\n", "w1 = input()\r\nw2 = input()\r\n\r\nif w1 == w2:\r\n print(-1)\r\nelse:\r\n print(max(len(w1), len(w2)))", "a=input()\r\nb=input()\r\nprint(-1 if a==b else (max(len(a),len(b)))) ", "a = list(input())\r\nb = list(input())\r\nif a == b:\r\n\tprint(-1)\r\nelse:\r\n\tif len(b) > len(a):\r\n\t\tprint(len(b))\r\n\telse:\r\n\t\tprint(len(a))\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\r\n\t\t \r\n\t\t \r\n", "s1 =input()\r\ns2 = input()\r\nif (s1!=s2):\r\n print(max(len(s1),len(s2)))\r\nelse:\r\n print(-1)", "\r\ns1 = input()\r\ns2 = input()\r\n\r\n\r\nif len(s1) > len(s2):\r\n largest = len(s1)\r\nelse: largest = len(s2) \r\n\r\nif s1 == s2:\r\n print(-1)\r\nelse:\r\n print(largest)\r\n\r\n", "def solve(a, b):\r\n return -1 if a == b else max(len(a), len(b))\r\n\r\na = input()\r\nb = input()\r\nprint(solve(a, b))", "if __name__ == \"__main__\":\n s = input()\n s2 = input()\n m = len(s)\n n = len(s2)\n if s == s2:\n print(\"-1\")\n else:\n if m > n:\n print(m)\n else:\n print(n)\n \t \t\t \t \t\t\t\t \t \t \t\t\t\t", "inp1 = input()\ninp2 = input()\nif inp1 == inp2:\n print(-1)\nelse:\n print(max(len(inp1),len(inp2)))", "def LongestUncommenSubsequence():\r\n s1=input()\r\n s2=input()\r\n if s1==s2:\r\n return -1\r\n return max(len(s1),len(s2))\r\nprint(LongestUncommenSubsequence())", "string1 = input()\r\nstring2 = input()\r\n\r\nif string1 == string2:\r\n print(-1)\r\nelse:\r\n if len(string1)> len(string2):\r\n print(len(string1))\r\n else:\r\n print(len(string2))", "a = input()\r\nb = input()\r\nif len(a) != len(b):\r\n print(max(len(a), len(b)))\r\nelif a == b:\r\n print(-1)\r\nelse:\r\n print(len(a))", "# 766A - Mahmoud and Longest Uncommon Subsequence\r\nx, y = input(), input()\r\nif x == y:\r\n print(-1)\r\nelse:\r\n print(max(len(x), len(y)))\r\n", "import sys\ninput = sys.stdin.readline\n\nS1 = input().rstrip()\nS2 = input().rstrip()\nif S1 == S2 : print(-1)\nelse : print(max(len(S1), len(S2)))", "n = input()\r\ns = input()\r\nn = [i for i in n]\r\ns = [i for i in s]\r\nans = -1\r\nif len(n) == len(s):\r\n for i in range(len(n)):\r\n if n[i] != s[i]:\r\n ans = 1\r\n break\r\nelse:\r\n ans = 1\r\nans = max(len(s), len(n)) if ans == 1 else ans\r\nprint(ans)\r\n\r\n", "string1 = str(input())\r\nstring2 = str(input())\r\n\r\nif string1==string2:\r\n print(-1)\r\nelif len(string1)>len(string2):\r\n print(len(string1))\r\nelse:\r\n print(len(string2))", "str1=input()\r\nstr2=input()\r\nif len(str1)==len(str2) and str1==str2 :\r\n print(-1)\r\n\r\nelse :\r\n print(len(str1) if len(str1)>len(str2) else len(str2))\r\n\r\n", "def solve(s,t):\r\n if s==t: return -1\r\n return len(max(s,t,key=len))\r\n \r\nif __name__==\"__main__\":\r\n s = input()\r\n t = input()\r\n ans = solve(s,t)\r\n print(ans)", "s1 = input()\ns2 = input()\nl1,l2 = len(s1),len(s2)\n\nif l1 != l2:\n print(max(l1,l2))\nelse:\n if s1 == s2:\n print(-1)\n else:\n print(l1)\n", "class Solution:\r\n\tdef __init__(self):\r\n\t\tpass\r\n\r\n\tdef solve(self):\r\n\t\ta = input();\r\n\t\tb = input(); \r\n\r\n\t\tif a == b:\r\n\t\t\tprint(-1)\r\n\t\telse:\r\n\t\t\tprint(max(len(a), len(b)))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tsol = Solution()\r\n\tsol.solve()\r\n", "s1=input()\r\ns2=input()\r\nif s1==s2: print(\"-1\")\r\nelse:print(max(len(s1),len(s2)))", "k1=input()\r\nk2=input()\r\ncommon=-1 if k1==k2 else max(len(k1),len(k2))\r\nprint(common)", "s1=input()\ns2=input()\nif(s1==s2):\n\tprint(-1)\nelse:\n\tprint(max(len(s1),len(s2)))\n \t\t \t\t \t \t\t \t\t \t\t \t\t \t", "s=str(input())\r\nx=str(input())\r\nif s==x:\r\n print(\"-1\")\r\nelse:\r\n print(max(len(s),len(x)))", "a1,a2=input(),input() ; print(-1 if a1 == a2 else max(len(a1),len(a2)))\r\n", "a,b=input(),input(); print(max(len(a),len(b)) if not (a == b) else \"-1\")\n\n\t\t \t\t \t\t \t \t \t \t\t \t\t\t\t\t\t\t", "def longest_uncommon_subsequence(red, red2):\r\n if red != red2:\r\n return max(len(red), len(red2))\r\n else:\r\n return -1\r\nap = input().strip()\r\nbp= input().strip()\r\nresult = longest_uncommon_subsequence(ap, bp)\r\nprint(result)\r\n", "# https://codeforces.com/problemset/problem/766/A\r\n\r\ndef check(w1, w2):\r\n if w1 != w2:\r\n return max(len(w1), len(w2))\r\n return -1 \r\n\r\nw1 = input()\r\nw2 = input()\r\nprint(check(w1, w2))", "a=input()\r\nb=input()\r\nif((a)==(b)):\r\n print(-1)\r\nelif len(a)>len(b):\r\n print(len(a))\r\nelse :\r\n print(len(b))", "s1 = input()\r\ns2 = input()\r\nif s1 == s2:\r\n print(-1)\r\nelse:\r\n print(max(len(s1), len(s2)))", "q = input()\r\nw = input()\r\nif q != w:\r\n print(max(len(q), len(w)))\r\nelse:\r\n print(-1)", "str=input()\r\nstr2=input()\r\nif str==str2:\r\n print(-1)\r\nif len(str)>len(str2):\r\n print(len(str))\r\nelif len(str2)>len(str):\r\n print(len(str2))\r\nelif str!=str2 and len(str2)==len(str):\r\n print(len(str))", "a = input()\r\nb = input()\r\n\r\nlength_a = len(a)\r\nlength_b = len(b)\r\n\r\nif a != b:\r\n print(max(length_a, length_b))\r\nelse:\r\n print(-1)\r\n", "def sol(a, b):\r\n if a == b: return -1\r\n return max(len(a), len(b))\r\n \r\n\r\n\r\nif __name__ == \"__main__\":\r\n a = input()\r\n b = input()\r\n \r\n print (sol(a, b))", "class Solution():\n def longest_uncommon_subsequencec():\n string_a = input()\n string_b = input()\n\n if string_a == string_b:\n return -1\n else:\n return max(len(string_a), len(string_b))\n\n\nif __name__ == '__main__':\n print(Solution.longest_uncommon_subsequencec())", "a = input()\r\nb = input()\r\nprint(-1 if a == b else max(len(a), len(b)))", "a = input()\r\nb= input()\r\n \r\nif a == b:\r\n print(-1) \r\nelse:\r\n m = max(len(a) , len(b))\r\n print(m) ", "a = input()\r\nb = input()\r\n\r\nlena = len(a)\r\nlenb = len(b)\r\nif(lena != lenb):\r\n print(max(lena,lenb))\r\n exit()\r\n\r\nif a.find(b) < 0:\r\n print(lena)\r\n exit()\r\n\r\nprint(-1)\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "a = input()\r\nb = input()\r\nprint(max(len(a),len(b)) if a!=b else -1)", "ch1=input()\r\nch2=input()\r\nprint([-1,max(len(ch1),len(ch2))][ch1!=ch2])", "a=str(input())\r\nb=str(input())\r\nif len(a)!=len(b):print(max(len(a),len(b)))\r\nelse:\r\n print([-1,len(b)][a not in b])\r\n ", "a=list(input())\r\nb=list(input())\r\na1=sorted(a);b1=sorted(b);la=0;lb=0\r\nla=len(a)\r\nlb=len(b)\r\nm= max(la, lb)\r\nif a==b:\r\n print(-1)\r\nelif m in [0,1]:\r\n print(-1)\r\nelse:\r\n print(m)\r\n", "def solve():\r\n a,b = input(),input()\r\n if a == b:\r\n return -1\r\n return len(a) if len(a) > len(b) else len(b)\r\nprint(solve())", "a=input()\r\nb=input()\r\n\r\nif a==b:\r\n res=-1\r\nelse:\r\n res=max(len(a),len(b))\r\nprint(res)", "a = str(input())\nb = str(input())\n\nif len(a) > len(b):\n print(len(a))\n\nelif len(a) < len(b):\n print(len(b))\n\nelif len(a) == len(b):\n if a == b:\n print(-1)\n else:\n print(len(a))", "x=input()\r\ny=input()\r\nif x==y:\r\n print(-1)\r\n\r\nelse:\r\n x=len(x)\r\n y=len(y)\r\n print(max(x,y))", "a = input()\r\nb = input()\r\n\r\nprint(max(len(a), len(b)) if a != b else -1)", "i = input()\r\nq = input()\r\n\r\nif i == q:\r\n print(-1)\r\nelse:\r\n print(max(len(i), len(q)))\r\n", "s = input().strip()\r\nt = input().strip()\r\n\r\nif s == t:\r\n print(\"-1\")\r\nelse:\r\n print(max(len(s), len(t)))", "strings = [input() , input()]\r\ncounter = {'1' : 0 , '2' : 0 }\r\nif strings[0] == strings[1] :\r\n print(-1)\r\nelif len(strings[0]) > len(strings[1]) :\r\n print(len(strings[0]))\r\nelse:\r\n print(len(strings[1]))", "s = input()\r\ns1 = input()\r\nif s==s1:\r\n print(-1)\r\nelse:\r\n print(max(len(s),len(s1)))\r\n \r\n", "a=input();m=len(a)\r\nb=input();n=len(b)\r\nif m>n:\r\n print(m)\r\nelif n>m:\r\n print(n)\r\nelif a==b:\r\n print(-1)\r\nelse:\r\n print(m)", "while True:\n try:\n a = str(input())\n b = str(input())\n res = []\n count = 0\n if a == b:\n print('-1')\n else:\n print(max(len(a), len(b)))\n except EOFError:\n break\n\n \t\t \t\t \t\t \t\t\t \t \t\t \t", "a,b = input(),input()\r\nprint(-1 if a ==b else max(len(a),len(b)))", "i=input\r\na,b=i(),i()\r\nprint(max(len(a),len(b)) if a!=b else -1)", "li = list(input())\r\nli1 = list(input())\r\nif li == li1:\r\n print(-1)\r\nelif len(li) == len(li1):\r\n print(len(li))\r\nelse:\r\n if len(li) > len(li1):\r\n print(len(li))\r\n else:\r\n print(len(li1))", "# My Codeforces template - September 2023\r\n# by randombernie\r\n\r\nfrom sys import stdin, stdout\r\nfrom collections import Counter, deque, defaultdict\r\nfrom math import ceil, comb, sqrt, factorial, perm\r\n\r\ndef input():\r\n \"\"\" Faster input parsing \"\"\"\r\n return stdin.readline().strip()\r\n\r\ndef print(string, newline=True):\r\n \"\"\"Prints a single string on a new line\"\"\"\r\n if newline:\r\n stdout.write(str(string) + \"\\n\")\r\n else:\r\n stdout.write(str(string))\r\n \r\ndef print_array(array):\r\n \"\"\" Prints an array of values, the way CodeForces requires \"\"\"\r\n stdout.write(\" \".join(map(str, array)) + \"\\n\")\r\n\r\ndef bin(x):\r\n \"\"\"A replacement for the built-in bin function, without the 0x\"\"\"\r\n return format(x, \"b\")\r\n\r\ndef find_primes(limit, return_all=True):\r\n \"\"\" Finds all the prime numbers from 1 to a specified limit (inclusive). Sieve of Erastothenes \"\"\"\r\n is_prime = [1] * (limit + 1)\r\n is_prime[1] = 0\r\n \r\n for i in range(2, limit + 1):\r\n if i * i > limit:\r\n break\r\n if is_prime[i]:\r\n for j in range(i * i, limit + 1, i):\r\n is_prime[j] = 0\r\n if return_all:\r\n return is_prime\r\n else:\r\n return [i for i in range(2, limit + 1) if is_prime[i]]\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 is_even(x):\r\n return x % 2 == 0\r\n\r\ndef factorize(x):\r\n factors = set()\r\n for i in range(2, ceil(sqrt(x))):\r\n if x % i == 0:\r\n factors.add(i)\r\n factors.add(x // i)\r\n return factors\r\n\r\ndef solve():\r\n a = input()\r\n b = input()\r\n\r\n longest, shortest = sorted([a, b], key=lambda x: -len(x))\r\n\r\n i = 0\r\n j = 0\r\n \r\n while i < len(shortest):\r\n if shortest[i] == longest[j]:\r\n j += 1\r\n if j == len(longest):\r\n print(-1)\r\n break\r\n i += 1\r\n else:\r\n if j == len(longest):\r\n print(-1)\r\n else:\r\n print(len(longest))\r\n \r\n \r\n \r\n \r\nif __name__ == \"__main__\":\r\n solve()\r\n", "s1 = input()\ns2 = input()\nprint(-1 if s1 == s2 else max(len(s1), len(s2)))", "a,b=input(),input()\r\nprint([-1,max(len(a),len(b))][a!=b])", "\r\nimport sys\r\n#sys.stdin = open(\"input.txt\", \"r\")\r\nII = lambda: int(input())\r\nLI = lambda: list(map(int, list(input().split(\" \"))))\r\nMI = lambda: map(int, LI())\r\nSI = lambda: input()\r\nlist = input()\r\nlist1 = input()\r\nif list == list1:\r\n print(-1)\r\nelif len(list) == len(list1):\r\n print(len(list))\r\nelse:\r\n if len(list) > len(list1):\r\n print(len(list))\r\n else:\r\n print(len(list1))", "\"\"\"\r\n@auther:Abdallah_Gaber \r\n\"\"\"\r\nstr1 = input()\r\nstr2 = input()\r\nif str1 == str2:\r\n print(-1)\r\nelif len(str1) > len(str2):\r\n print(len(str1))\r\n \r\nelse:\r\n print(len(str2))\r\n", "s1=input();s2=input()\r\nx=min(len(s1),len(s2));y=max(len(s1),len(s2));count=0\r\nif(s1!=s2): print(y);\r\nelse:print(-1)" ]
{"inputs": ["abcd\ndefgh", "a\na", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddddddddd", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbb", "abcde\nfghij", "abcde\nabcdf", "abcde\nbbcde", "abcde\neabcd", "abcdefgh\nabdcefgh", "mmmmm\nmnmmm", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaa", "abcdefghijklmnopqrstuvwxyz\nzabcdefghijklmnopqrstuvwxy", "a\nab", "b\nab", "ab\nb", "ab\nc", "aaaaaa\naaaaaa", "abacaba\nabacaba", "aabb\nbbaa", "ab\nba", "abcd\nabc", "abaa\nabaa", "ab\nab", "ab\nabcd", "abc\nabcd", "mo\nmomo", "koooooooooooooooo\nloooooooooooooooo", "aaa\naa", "abc\nabc", "abcd\nabcd", "abc\ncba", "ahc\nahc", "abc\nbac", "aa\naaa", "aaa\naaa", "abc\nacb", "abc\nab", "abb\nabb", "abc\ncab", "aaaaaa\naaaaa", "aa\naab", "len\nlena", "aaaaa\naa", "aaa\naaaa", "bcd\nabcd", "aaabbc\naaaccc", "abcd\nzycd", "baa\nzaa", "asdf\nadfs", "abcdefgh\nabcdefgh", "aba\naab", "aba\naba", "abcccc\naccccc", "acb\nabc", "a\naa", "abababab\nab", "ababab\nab"], "outputs": ["5", "-1", "100", "199", "99", "5", "5", "5", "5", "8", "5", "34", "26", "2", "2", "2", "2", "-1", "-1", "4", "2", "4", "-1", "-1", "4", "4", "4", "17", "3", "-1", "-1", "3", "-1", "3", "3", "-1", "3", "3", "-1", "3", "6", "3", "4", "5", "4", "4", "6", "4", "3", "4", "-1", "3", "-1", "6", "3", "2", "8", "6"]}
UNKNOWN
PYTHON3
CODEFORCES
184
175a9fbb6934af1423c16e2e891e9830
Pashmak and Buses
Recently Pashmak has been employed in a transportation company. The company has *k* buses and has a contract with a school which has *n* students. The school planned to take the students to *d* different places for *d* days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrange the students in the buses. He wants to arrange the students in a way that no two students become close friends. In his ridiculous idea, two students will become close friends if and only if they are in the same buses for all *d* days. Please help Pashmak with his weird idea. Assume that each bus has an unlimited capacity. The first line of input contains three space-separated integers *n*,<=*k*,<=*d* (1<=≤<=*n*,<=*d*<=≤<=1000; 1<=≤<=*k*<=≤<=109). If there is no valid arrangement just print -1. Otherwise print *d* lines, in each of them print *n* integers. The *j*-th integer of the *i*-th line shows which bus the *j*-th student has to take on the *i*-th day. You can assume that the buses are numbered from 1 to *k*. Sample Input 3 2 2 3 2 1 Sample Output 1 1 2 1 2 1 -1
[ "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\nimport math\nimport operator\nimport sys\nfrom itertools import accumulate \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 add_one(arr,k):\n for i in range(len(arr)):\n if arr[i] < k - 1:\n arr[i] += 1\n break\n arr[i] = 0\n\ndef solution():\n n,k,d = map(int,input().split()) \n # check if its possible\n if n > k**d:\n return print(-1)\n \n res = []\n arr = [0]*d\n for _ in range(n):\n res.append(arr.copy())\n add_one(arr, k)\n\n for j in range(len(res[0])):\n print(*[res[i][j] + 1 for i in range(len(res))])\n\n # am going to use union find\n # wowo\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", "n,k,d=map(int,input().split())\r\nif n>k**d:print(-1);exit()\r\nK=1\r\nfor j in range(d):\r\n print(\" \".join([str(i//K%k +1) for i in range(n)]));K*=k", "# Pashmak and Buses\r\n\r\nn, k, d = map(int, input().split())\r\n\r\nif k**d < n:\r\n print(-1)\r\nelse:\r\n ans = [[0]*n for i in range(d)]\r\n for i in range(n):\r\n i2 = i\r\n for j in range(d):\r\n ans[j][i] = (i2 % k) + 1\r\n i2 //= k\r\n\r\n for line in ans:\r\n print(*line)\r\n", "n,k,d=map(int,input().split())\r\np=1\r\nfor i in range(d):\r\n p*=k\r\n if p>=n:\r\n break\r\ns=[i for i in range(n)]\r\nif n>p:\r\n print(-1)\r\nelse:\r\n for i in range(d):\r\n ans=\"\"\r\n for j in range(n):\r\n ans += str(s[j] % k + 1) + ' '\r\n s[j] //= k\r\n print(ans)", "n,k,d=map(int,input().split())\r\nif n>k**d:\r\n print(-1);exit()\r\nK=1\r\nfor j in range(d):\r\n ll = \"\"\r\n \r\n for i in range(n):\r\n ll+=' '+str(i//K%k+1)\r\n \r\n print(ll);\r\n K*=k", "n,k,d=map(int,input().split())\r\nlimit=1\r\np=True\r\nfor i in range(d):\r\n limit*=k\r\n if limit>=n:\r\n p=False\r\n break\r\nif p:\r\n print(\"-1\")\r\n exit()\r\na=[i for i in range(1,n+1)]\r\nfor i in range(d):\r\n b=\"\"\r\n for j in range(n):\r\n b+=str(a[j]%(k)+1)+\" \"\r\n a[j]//=k\r\n print(b)\r\n ", "G,P=range,print;n,k,d=map(int,input().split());tot=pow(k,d)\r\nif n>tot:exit(P(-1))\r\ng=[];x=[1]*d\r\nfor _ in G(n):\r\n g+=[x[::]];x[-1]+=1\r\n i=d-1\r\n while 0<i and x[i]>k:x[i]=1;x[i-1]+=1;i-=1\r\nfor r in zip(*g):P(*r)" ]
{"inputs": ["3 2 2", "3 2 1", "7 2 3", "9 2 3", "2 1 1000", "512 2 9", "1000 1000000000 511", "1000 1000 1", "1000 3 1000", "1 1000000000 512", "1000 2 1000", "1000 3 1000", "1000 31 1000", "1000 32 1000", "1000 999 1000", "1000 1000 1000", "1000 536870912 1000", "1000 536870911 1000", "1000 1000000000 1000", "1000 2 8", "513 2 9", "81 3 4", "82 3 4", "243 3 5", "244 3 5", "999 999 1", "1000 999 1", "343 7 3", "512 8 3", "729 9 3", "729 3 6", "625 5 4", "1 1 1", "1 1 2", "2 1 1", "1 2 1", "5 3 2", "1 1000000000 1", "1000 1000000000 1", "27 3 3", "1 1 10"], "outputs": ["1 1 2 \n1 2 1 ", "-1", "1 1 1 1 2 2 2 \n1 1 2 2 1 1 2 \n1 2 1 2 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...", "1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...", "-1", "-1", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 \n1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 \n1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 \n1 2 3 1 2 3 1 2 3 1...", "-1", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 \n1 1 1 1 1 1 1 1 1 1 1 1...", "-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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3...", "1 ", "1 \n1 ", "-1", "1 ", "1 1 1 2 2 \n1 2 3 1 2 ", "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 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 \n1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 \n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ", "1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 "]}
UNKNOWN
PYTHON3
CODEFORCES
7
1781dd23263cc5f4456420d34bd9eaa4
Pashmak and Parmida's problem
Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak. There is a sequence *a* that consists of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Let's denote *f*(*l*,<=*r*,<=*x*) the number of indices *k* such that: *l*<=≤<=*k*<=≤<=*r* and *a**k*<==<=*x*. His task is to calculate the number of pairs of indicies *i*,<=*j* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*) such that *f*(1,<=*i*,<=*a**i*)<=&gt;<=*f*(*j*,<=*n*,<=*a**j*). Help Pashmak with the test. The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). Print a single integer — the answer to the problem. Sample Input 7 1 2 1 1 2 2 1 3 1 1 1 5 1 2 3 4 5 Sample Output 8 1 0
[ "import heapq\r\nimport math\r\nimport os\r\nfrom collections import Counter, deque, defaultdict\r\nfrom sys import stdout\r\nimport time\r\nfrom math import factorial, log, gcd\r\nimport sys\r\nfrom decimal import Decimal\r\nimport threading\r\nfrom heapq import *\r\nimport random\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 IS():\r\n return sys.stdin.readline().replace('\\n', '')\r\n\r\n\r\nclass Fenwick:\r\n def __init__(self, size: int):\r\n self.data = [0] * (size + 1)\r\n self.size = size\r\n\r\n def getParent(self, i: int) -> int:\r\n return i - (i & (-i))\r\n\r\n def getNext(self, i: int) -> int:\r\n return i + (i & (-i))\r\n\r\n def getSum(self, i: int) -> int:\r\n sum = 0\r\n i += 1\r\n while i > 0:\r\n sum += self.data[i]\r\n i = self.getParent(i)\r\n\r\n return sum\r\n\r\n def update(self, i: int, v: int):\r\n i += 1\r\n while i < self.size:\r\n self.data[i] += v\r\n i = self.getNext(i)\r\n\r\n\r\ndef main():\r\n n = II()\r\n a = I()\r\n size = 1\r\n while size < n:\r\n size *= 2\r\n fenwick = Fenwick(10 ** 6 + 10)\r\n counter_left = Counter(a)\r\n counter_right = Counter()\r\n ans = 0\r\n for i in range(n - 1, -1, -1):\r\n el = a[i]\r\n ans += fenwick.getSum(counter_left[el] - 1)\r\n\r\n counter_right[el] += 1\r\n counter_left[el] -= 1\r\n fenwick.update(counter_right[el], 1)\r\n\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 update(k):\r\n while k<MAX:\r\n q[k]+=1\r\n k+=k&-k\r\n\r\ndef getsum(k):\r\n s=0\r\n while k>0:\r\n s+=q[k]\r\n k-=k&-k\r\n return s \r\n\r\nn=int(input())\r\na=[int(i) for i in input().split()]\r\n\r\nvis_i={}\r\nvis_j={}\r\n\r\nl_i=[]\r\nl_j=[]\r\n\r\nfor i in range(n-1):\r\n if a[i] in vis_i:\r\n vis_i[a[i]]+=1\r\n else:\r\n vis_i[a[i]]=1\r\n l_i.append(vis_i[a[i]])\r\n\r\na=a[::-1]\r\nfor i in range(n-1):\r\n if a[i] in vis_j:\r\n vis_j[a[i]]+=1\r\n else:\r\n vis_j[a[i]]=1\r\n l_j.append(vis_j[a[i]])\r\n\r\nl_i=l_i[::-1]\r\nq=[0]*(n+30)\r\nMAX=n+20\r\nres=0\r\n\r\nfor k in range(n-1):\r\n update(l_j[k]+1)\r\n res+=getsum(l_i[k])\r\n \r\nprint(res)\r\n", "from typing import Iterable\n\n\nn = int(input())\na = list(map(int, input().split()))\n\n\ndef count(index_gen: Iterable[int]) -> list[int]:\n values = {}\n counts = [0] * n\n for i in index_gen:\n values.setdefault(a[i], 0)\n values[a[i]] += 1\n counts[i] = values[a[i]]\n return counts\n\n\njv = count(reversed(range(n)))\niv = count(range(n))\n\nall_values = sorted(set(jv + iv))\nval_to_order = {\n val: i\n for i, val in enumerate(all_values)\n}\n\nbit = [0] * (len(all_values) + 1)\ndef get(r: int) -> int:\n r += 1\n ans = 0\n while r:\n ans += bit[r]\n r -= r & -r\n return ans\n\ndef add(i: int) -> None:\n i += 1\n while i <= len(all_values):\n bit[i] += 1\n i += i & -i\n\nans = 0\nfor i in range(n):\n ans += i - get(val_to_order[jv[i]])\n add(val_to_order[iv[i]])\n\nprint(ans)\n", "'''\r\n###### * User Profile : Keval_78\r\nLinkedIn: https://www.linkedin.com/in/kevalpadsala78/\r\nGithub: https://github.com/Keval78\r\nLeetcode: https://leetcode.com/Keval_78/\r\n'''\r\n\r\nimport math\r\nimport sys\r\n# from os import path\r\n# from math import log2, floor, ceil, sqrt, pow, gcd\r\n# from random import random, randint, shuffle, choice\r\nfrom collections import Counter, defaultdict, deque\r\n# from itertools import permutations, combinations\r\n# from functools import reduce\r\n# from heapq import heapify, heappop, heappush, heapreplace\r\n# from bisect import bisect_left, bisect_right\r\n\r\n\r\ndef si(): return sys.stdin.readline().strip()\r\ndef ii(): return int(si())\r\ndef mi(ss=\" \"): return map(int, si().split(ss))\r\ndef msi(ss=\" \"): return map(str, si().split(ss))\r\ndef li(ss=\" \"): return list(mi(ss))\r\n\r\n\r\nsys.setrecursionlimit(10 ** 5)\r\nMOD, MOD2, INF = 10 ** 9 + 7, 998244353, float('inf')\r\nMAX = 10**5+1\r\n\r\n# Implementing Segment Tree...\r\nclass SegmentTree:\r\n def __init__(self, n):\r\n self.n = n\r\n self.seg_tree = [0]*(2*n)\r\n self.build()\r\n \r\n def build(self):\r\n for i in range(self.n-1, 0, -1):\r\n self.seg_tree[i] = self.seg_tree[i<<1] + self.seg_tree[i<<1|1]\r\n \r\n\r\n def update(self, i, val):\r\n i = i + self.n\r\n self.seg_tree[i] += val\r\n \r\n while i > 1:\r\n self.seg_tree[i>>1] = self.seg_tree[i] + self.seg_tree[i^1]\r\n i >>= 1\r\n \r\n def query(self, l, r):\r\n res = 0\r\n l, r = l + self.n, r + self.n\r\n while l < r:\r\n if l & 1:\r\n res += self.seg_tree[l]\r\n l += 1\r\n if r & 1:\r\n r -= 1\r\n res += self.seg_tree[r]\r\n l, r = l>>1, r>>1\r\n return res\r\n\r\n \r\n\r\n\r\ndef solve():\r\n n = ii()\r\n arr = li()\r\n\r\n fi = [0]*n\r\n fj = [0]*n\r\n\r\n freq = defaultdict(int)\r\n for i in range(n):\r\n freq[arr[i]] = freq.get(arr[i], 0) + 1\r\n fi[i] = freq[arr[i]]\r\n \r\n for i in range(n):\r\n fj[i] = freq[arr[i]]\r\n freq[arr[i]] -= 1\r\n\r\n # print(fi, fj)\r\n\r\n # Count smaller left in fi for each value of fj\r\n freq.clear()\r\n ind = 0\r\n for k in sorted(fi):\r\n if k not in freq:\r\n freq[k] = ind\r\n ind+=1\r\n\r\n ans = 0\r\n seg = SegmentTree(len(freq))\r\n for i in range(n):\r\n ans += seg.query(freq[fj[i]]+1, ind)\r\n seg.update(freq[fi[i]], 1)\r\n \r\n print(ans)\r\n\r\n \r\n\r\n\r\ntest = 1\r\n# test = ii()\r\nfor _ in range(test):\r\n # print(\"case\", _+1)\r\n solve()\r\n", "def update(i,k,fenwick_tree,n):\r\n while i <= n:\r\n fenwick_tree[i] += k\r\n i += i & -i\r\n\r\ndef query(i,fenwick_tree):\r\n ans = 0\r\n while i > 0:\r\n ans += fenwick_tree[i]\r\n i -= i&-i\r\n return ans\r\n\r\n\r\nn = int(input())\r\na = list(map(int,input().split()))\r\nfenwick_tree = [0]*(n+5)\r\nfreq = []\r\ncnt = {}\r\nfor i in range(len(a)):\r\n if a[i] in cnt :\r\n cnt[a[i]] += 1\r\n else:\r\n cnt[a[i]] = 1\r\n freq.append(cnt[a[i]])\r\ncnt = {}\r\nans = 0\r\nfor i in range(n-1,-1,-1):\r\n ans += query(freq[i]-1,fenwick_tree)\r\n if a[i] in cnt:\r\n cnt[a[i]] += 1\r\n else:\r\n cnt[a[i]] = 1\r\n update(cnt[a[i]],1,fenwick_tree,n)\r\nprint(ans) ", "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\nclass Fenwick_tree:\n\n def __init__(self, numbers):\n self.length = numbers\n self.numbers = [0] * numbers\n self.bits = [0] * (self.length + 1)\n self.build_tree()\n\n def update(self, idx, value):\n idx += 1\n while idx <= self.length:\n self.bits[idx]+=value\n idx = idx + (idx&-idx)\n\n def sum_range(self,idx):\n result = 0\n idx += 1\n while idx > 0:\n result += self.bits[idx]\n idx = idx - (idx & -idx)\n return result\n\n def build_tree(self):\n for index in range(self.length):\n self.update(index, self.numbers[index])\n\n\nN = int(input())\nA = list(map(int,input().split()))\nfen_tree = Fenwick_tree(10**6+1)\nans = 0\n\ndic = defaultdict(int)\nl,r = [],[]\nfor i in range(N-1,-1,-1):\n r.append(dic[A[i]])\n dic[A[i]]+=1\nr = r[::-1]\ndic = defaultdict(int)\nfor i in range(N):\n l.append(dic[A[i]])\n dic[A[i]]+=1\n\ncnt = defaultdict(int)\n\n# print(l)\n# print(r)\nfen_tree.update(r[-1],1)\ncnt[r[-1]]+=1\nfor i in range(N-2,-1,-1):\n ans+=fen_tree.sum_range(l[i])-cnt[l[i]]\n fen_tree.update(r[i],1)\n cnt[r[i]]+=1\n\nprint(ans)\n\n\n\n", "n = int(input())\r\narr=[0]+list(map(int,input().split()))\r\nmaxi = pow(10,6)+50\r\nBit = [0 for i in range(maxi+10)]\r\ndef add(idx,val):\r\n \r\n global Bit\r\n while(idx<maxi):\r\n \r\n Bit[idx]+=val\r\n idx+=(idx & (-idx))\r\n \r\ndef calc(idx):\r\n summ = 0\r\n while(idx>0):\r\n \r\n summ+=Bit[idx]\r\n idx-=(idx &(-idx))\r\n return summ\r\n\r\nfrom collections import defaultdict\r\ndic = defaultdict(lambda:0)\r\nfreq = defaultdict(lambda:0)\r\nfor i in range(1,len(arr)):\r\n freq[arr[i]]+=1\r\n dic[i,arr[i]]+=freq[arr[i]]\r\n\r\nans= 0\r\nfreq2 = defaultdict(lambda:0)\r\n\r\n \r\n \r\nfor i in range(len(arr)-1,0,-1):\r\n ans += calc(dic[i,arr[i]]-1)\r\n freq2[arr[i]]+=1\r\n add(freq2[arr[i]],1)\r\n\r\nprint(ans)\r\n\r\n", "import sys\r\ninput=sys.stdin.readline\r\nBIT = [0]*(10**6)\r\ndef update(idx):\r\n while(idx<len(BIT)):\r\n BIT[idx] += 1\r\n idx += idx & -idx\r\ndef query(idx):\r\n s = 0\r\n while(idx > 0):\r\n s += BIT[idx]\r\n idx -= idx & -idx\r\n return s\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nans=0\r\ncnt={}\r\nl=[0]*n\r\nr=[0]*n\r\nfor i in range(n):\r\n cnt[a[i]]=cnt.get(a[i],0)+1\r\n l[i]=cnt[a[i]]\r\ncnt.clear()\r\nfor i in range(n)[::-1]:\r\n cnt[a[i]]=cnt.get(a[i],0)+1\r\n r[i]=cnt[a[i]]\r\n if i<n-1:\r\n ans+=query(l[i]-1)\r\n update(r[i])\r\nprint(ans)", "import sys\r\ninput = sys.stdin.readline\r\ndef fg():\r\n return int(input())\r\ndef fgh():\r\n return [int(xx) for xx in input().split()]\r\ndef sd():\r\n print('YES')\r\ndef df():\r\n print('NO')\r\ndef s(l, r):\r\n return p(r) - p(l)\r\ndef p(i):\r\n ans = 0\r\n while i:\r\n ans += R[i]\r\n i -= F[i]\r\n return ans\r\ndef pl(i, x):\r\n global R\r\n global n\r\n while i <= n:\r\n R[i] += x\r\n i += F[i]\r\nF = []\r\nfor i in range(10 ** 6 + 3):\r\n F.append(i & (-i))\r\nn = fg()\r\na = fgh()\r\nd = {}\r\ne = {}\r\nb = []\r\nc = []\r\nfor i in range(n):\r\n d[a[i]] = 0\r\n e[a[i]] = 0\r\nfor i in range(n):\r\n d[a[i]] += 1\r\n b.append(d[a[i]])\r\nc = [0] * (n + 10)\r\npr = [0]\r\nfor i in range(n):\r\n pr.append(pr[-1] + c[i])\r\nR = [0] * (n + 10)\r\nfor i in range(1, n + 1):\r\n R[i] = pr[i] - pr[i - F[i]]\r\nans = 0\r\nfor i in range(n - 1, -1, -1):\r\n ans += p(b[i] - 1)\r\n e[a[i]] += 1\r\n pl(e[a[i]], 1)\r\nprint(ans)", "from collections import defaultdict\r\nfrom math import ceil, log2\r\n\r\n\r\ndef get_sum(r):\r\n result = 0\r\n while r > 0:\r\n result += tree[r]\r\n r -= r & (-r)\r\n return result\r\n\r\n\r\ndef update(i, val):\r\n while i < len(tree):\r\n tree[i] += val\r\n i += i & (-i)\r\n\r\n\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nx = (int)(ceil(log2(n)))\r\ntree = [0] * (2 * (int)(2**x) - 1)\r\n\r\nleft_dir, right_dir = [], []\r\n\r\ndict = defaultdict(int)\r\nfor i in range(n-1):\r\n dict[arr[i]] += 1\r\n left_dir.append(dict[arr[i]])\r\n\r\n\r\nleft_dir = left_dir[::-1]\r\n\r\n\r\ndict = defaultdict(int)\r\nfor i in range(n-1, 0, -1):\r\n dict[arr[i]] += 1\r\n right_dir.append(dict[arr[i]])\r\n\r\n\r\nresult = 0\r\nfor i in range(n-1):\r\n update(right_dir[i], 1)\r\n result += get_sum(left_dir[i]-1)\r\nprint(result)\r\n", "n = int(input())\na = [int(x) for x in input().split()]\n\nm = {}\nfor i in range(n):\n if not a[i] in m:\n m[a[i]] = []\n m[a[i]].append(i)\n\nv1 = [0]*n\nv2 = [0]*n\nfor x in m:\n for i in range(len(m[x])):\n v1[m[x][i]] = i+1\n v2[m[x][i]] = len(m[x])-i\n\nBIT = [0] * (n+5)\ndef get(i):\n res = 0\n while i > 0:\n res += BIT[i]\n i -= i & -i\n return res\n\ndef add(i):\n i += 1\n while i < n+5:\n BIT[i] += 1\n i += i & -i\n\nans = 0\nfor i in range(n-1, -1, -1):\n ans += get(v1[i])\n add(v2[i])\n\nprint(ans)\n", "import math, collections\r\n\r\nclass FenwikTree:\r\n def construction(arr):\r\n \"\"\"\r\n param: arr: input array\r\n return: fenwik tree\r\n \"\"\"\r\n fenwik = [0] + arr[:]\r\n n = len(fenwik)\r\n for i in range(1, n):\r\n j = i + (i & -i)\r\n if j < n:\r\n fenwik[j] += fenwik[i]\r\n\r\n return fenwik\r\n \r\n\r\n def updateAdd(fenwik, i, val):\r\n \"\"\"\r\n param: fenwik: fenwik tree\r\n param: i: index to be updated\r\n param: val: value to be added at index i\r\n \"\"\"\r\n i += 1\r\n while i < len(fenwik):\r\n fenwik[i] += val\r\n i += i & -i\r\n\r\n def querySum(fenwik, i):\r\n \"\"\"\r\n param: fenwik: fenwik tree\r\n param: i: index till which sum is needed (i included)\r\n return: return sum; if i == -1, will return 0\r\n \"\"\"\r\n i += 1\r\n ans = 0\r\n while i > 0:\r\n ans += fenwik[i]\r\n i -= i & -i\r\n \r\n return ans \r\n \r\n def rangeSum(fenwik, l, r):\r\n \"\"\"\r\n param: fenwik: fenwik tree\r\n param: l: left index\r\n param: r: right index\r\n return: sum of elements from l to r (both inclusive)\r\n \"\"\"\r\n return FenwikTree.querySum(fenwik, r) - FenwikTree.querySum(fenwik, l-1)\r\n\r\n\r\ndef sol(arr, n):\r\n\r\n # Let arr = 1, 2, 1, 1, 2, 2, 1\r\n # freqFromleft = 1, 1, 2, 3, 2, 3, 4\r\n # freqFromright = 4, 3, 3, 2, 2, 1, 1\r\n # accourding to ques, we need to find i and j such that freqFromleft[i] > freqFromright[j] and i < j\r\n\r\n # Now, we can use fenwik tree which will store freq (from right side) of all idx after idx i, \r\n # then the contrubution of ith idx -> num of freq < freq[i] = sumQuery(fenwik, freqFromleft[i]-1)\r\n\r\n\r\n # getting freq from left side\r\n ctr = collections.defaultdict(int)\r\n freqFromleft = [0]*n\r\n for i in range(n):\r\n ctr[arr[i]] += 1\r\n freqFromleft[i] = ctr[arr[i]]\r\n \r\n # getting freq from right side\r\n ctr = collections.defaultdict(int)\r\n freqFromright = [0]*n\r\n for i in range(n-1, -1, -1):\r\n ctr[arr[i]] += 1\r\n freqFromright[i] = ctr[arr[i]]\r\n\r\n # building fenwik tree\r\n # Note: fenwik != FenwikTree.construction(freq)\r\n # 1 2 3 4 5 6 7\r\n # as for freq = [1, 1, 2, 3, 2, 3, 4], it means freq of 7 = 4\r\n # we want fenwik to store freq of freqs. \r\n fenwik = FenwikTree.construction([0]*(n+1))\r\n for freq in freqFromright: \r\n FenwikTree.updateAdd(fenwik, freq, 1)\r\n\r\n # every time idx i move right, we will remove that freq from fenwik tree\r\n # and get ans by querying num of freqs < freq[i] = sumQuery(fenwik, freqFromleft[i]-1)\r\n ans = 0\r\n for freqLeft, freqRight in zip(freqFromleft, freqFromright):\r\n FenwikTree.updateAdd(fenwik, freqRight, -1)\r\n ans += FenwikTree.querySum(fenwik, freqLeft-1)\r\n \r\n print(ans)\r\n\r\n\r\nt = 1\r\nfor _ in range(t):\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n sol(arr, n)\r\n", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nfrom collections import defaultdict\r\nfrom bisect import *\r\n\r\nclass SegTree:\r\n def __init__(self, n):\r\n self.size = n\r\n self.tree = [0]*(n*2)\r\n\r\n def update(self,p,v):\r\n self.tree[p+self.size] += v\r\n p+=self.size\r\n \r\n i = p\r\n while i>1:\r\n self.tree[i>>1] = self.tree[i] + self.tree[i^1]\r\n i>>=1\r\n \r\n # 不包含r\r\n def query(self,l,r):\r\n ans = 0\r\n l += self.size\r\n r += self.size\r\n \r\n while l<r:\r\n if 1&l:\r\n ans += self.tree[l]\r\n l+=1\r\n if r&1:\r\n r-=1\r\n ans += self.tree[r]\r\n \r\n l>>=1\r\n r>>=1\r\n return ans\r\n\r\nN = int(input())\r\nA = list(map(int, input().split()))\r\n\r\nB = list(set(sorted(A)))\r\nB.sort()\r\nM = len(B)\r\n\r\nseg = SegTree(N+1)\r\nlib = defaultdict(int)\r\nfor i in range(N-1,-1,-1):\r\n lib[str(A[i])]+=1\r\n seg.update(lib[str(A[i])], 1)\r\n\r\ncnt = [0]*M\r\nans = 0\r\nfor i in range(N):\r\n a = A[i]\r\n idx = bisect_left(B, a)\r\n cnt[idx]+=1\r\n \r\n t = lib[str(a)]\r\n lib[str(a)]-=1\r\n seg.update(t, -1)\r\n \r\n ans+=seg.query(0, cnt[idx])\r\nprint(ans)\r\n \r\n\r\n", "def rl():\r\n return list(map(int,input().split()))\r\ndef ri():\r\n return int(input())\r\ndef rs():\r\n return input()\r\ndef rm():\r\n return map(int,input().split())\r\nclass BIT():\r\n def __init__(self,a) -> None:\r\n n=len(a)\r\n c=[0 for i in range(n)]\r\n b=[0 for i in range(n+1)]\r\n c[0]=a[0]\r\n for i in range(1,n):\r\n c[i]=c[i-1]+a[i]\r\n c=[0]+c\r\n for i in range(1,n+1):\r\n par=i-(i&-i)\r\n if par!=0:b[i]=c[i]-c[par]\r\n else: b[i]=c[i]\r\n self.b=b\r\n def query(self,pos):\r\n pos+=1\r\n sm=0\r\n while pos>0:\r\n sm+=self.b[pos]\r\n pos=pos-(pos&-pos)\r\n return sm\r\n def update(self,pos,val):\r\n pos+=1\r\n while pos<len(self.b):\r\n self.b[pos]+=val\r\n pos=pos+(pos&-pos)\r\n def rs(self,l,r):\r\n return self.query(r)-self.query(l-1)\r\n# import pdb\r\n# pdb.set_trace()\r\n# b=BIT([0,1,0,1,0,1])\r\nfrom collections import defaultdict\r\ndef main():\r\n n=ri()\r\n a=rl()\r\n b=[0]*(n+1)\r\n bt=BIT(b)\r\n pf,sf=[0]*n,[0]*n\r\n pd,sd=defaultdict(int),defaultdict(int)\r\n for i in range(n):\r\n pd[a[i]]+=1\r\n pf[i]=pd[a[i]]\r\n for i in range(n-1,-1,-1):\r\n sd[a[i]]+=1\r\n sf[i]=sd[a[i]]\r\n bt.update(sf[-1],1)\r\n ans=0\r\n for i in range(n-2,-1,-1):\r\n ans+=bt.query(pf[i]-1)\r\n bt.update(sf[i],1)\r\n return ans\r\n\r\nprint(main())" ]
{"inputs": ["7\n1 2 1 1 2 2 1", "3\n1 1 1", "5\n1 2 3 4 5", "24\n1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4", "1\n1", "2\n1 2", "2\n1 1", "4\n1 1 2 2", "5\n1 1 2 2 2"], "outputs": ["8", "1", "0", "114", "0", "0", "0", "1", "2"]}
UNKNOWN
PYTHON3
CODEFORCES
14
17d85a2526ca819f521a1a67dba02824
Restore Cube
Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers — coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations. When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly. Each of the eight lines contains three space-separated integers — the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value. If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers — the restored coordinates of the points. The numbers in the *i*-th output line must be a permutation of the numbers in *i*-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them. If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else. Sample Input 0 0 0 0 0 1 0 0 1 0 0 1 0 1 1 0 1 1 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 Sample Output YES 0 0 0 0 0 1 0 1 0 1 0 0 0 1 1 1 0 1 1 1 0 1 1 1 NO
[ "from itertools import permutations as p\n\nd = lambda a, b: sum((i - j) ** 2 for i, j in zip(a, b))\nf = lambda a, b: [i + j - k for i, j, k in zip(a, b, q)]\ng = lambda t: sorted(sorted(q) for q in t)\n\nv = [sorted(map(int, input().split())) for i in range(8)]\nq = v.pop()\n\nu = g(v)\nfor a, b, c in p(v, 3):\n for x in p(a):\n s = 2 * d(q, x)\n if not s: continue\n for y in p(b):\n if not 2 * d(q, y) == d(x, y) == s: continue\n for z in p(c):\n if not 2 * d(q, z) == d(x, z) == d(y, z) == s: continue\n t = [x, y, z] + [f(x, y), f(x, z), f(y, z), f(f(x, y), z)]\n if g(t) == u:\n print('YES')\n d = [str(sorted(i)) for i in t]\n for j in v:\n i = d.index(str(j))\n k = t.pop(i)\n print(*k)\n d.pop(i)\n print(*q)\n exit()\n\nprint('NO')\n", "import itertools\r\nfrom itertools import permutations as perm\r\n\r\nl = [[int(x) for x in input().split()] for i in range(8)]\r\n\r\ndef dist2(p0,p1):\r\n return sum([(p0[i]-p1[i])**2 for i in range(3)])\r\n\r\ndef sub(p0,p1):\r\n return [p0[i]-p1[i] for i in range(3)]\r\n\r\ndef add(p0,p1):\r\n return [p0[i]+p1[i] for i in range(3)]\r\n\r\ndef div(p0,x):\r\n return [p0[i]//x for i in range(3)]\r\n\r\ndef cross(p0,p1):\r\n return [p0[(i+1)%3]*p1[(i+2)%3]-p0[(i+2)%3]*p1[(i+1)%3] for i in range(3)]\r\n\r\ndef match(p0,p1):\r\n return sorted(p0) == sorted(p1)\r\n\r\nsolved = False\r\nfor l2 in perm(l,3):\r\n p0 = l2[0]\r\n for p1 in perm(l2[1]):\r\n s2 = dist2(p0,p1)\r\n if s2 == 0: continue\r\n s = round(s2**.5)\r\n if s**2 != s2: continue\r\n for p2 in perm(l2[2]):\r\n if dist2(p0,p2) != s2 or dist2(p1,p2) != 2*s2: continue\r\n p3 = sub(add(p1,p2),p0)\r\n x = div(cross(sub(p1,p0),sub(p2,p0)),s)\r\n p4,p5,p6,p7 = add(p0,x),add(p1,x),add(p2,x),add(p3,x)\r\n l3 = [p0,p1,p2,p3,p4,p5,p6,p7]\r\n if sorted([sorted(p) for p in l]) == sorted([sorted(p) for p in l3]):\r\n print(\"YES\")\r\n used = [False for i in range(8)]\r\n for p in l:\r\n for i in range(8):\r\n if used[i]: continue\r\n if match(p,l3[i]):\r\n print(l3[i][0],l3[i][1],l3[i][2])\r\n used[i] = True\r\n break\r\n solved = True\r\n break\r\n if solved: break\r\n if solved: break\r\n\r\nif not solved: print(\"NO\")\r\n#if not poss(1,[l[0]]): print(\"NO\")" ]
{"inputs": ["0 0 0\n0 0 1\n0 0 1\n0 0 1\n0 1 1\n0 1 1\n0 1 1\n1 1 1", "0 0 0\n0 0 0\n0 0 0\n0 0 0\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "0 0 0\n1 0 0\n0 1 0\n1 1 0\n0 0 1\n1 0 1\n0 1 1\n1 1 1", "6 -2 -2\n-5 1 -6\n6 -6 7\n6 3 4\n9 -7 8\n-9 -2 -6\n-9 1 6\n-9 -1 0", "-5 -3 -8\n-8 8 -5\n-3 3 6\n6 3 8\n-8 6 -3\n8 -8 6\n-3 -5 3\n-5 3 8", "-6 1 3\n-6 1 3\n-5 0 0\n-3 -3 7\n-2 6 6\n0 4 9\n0 4 9\n3 3 10", "-6 -10 -13\n2 -13 -15\n2 -6 -10\n2 2 -15\n6 -1 -13\n6 2 -1\n11 -3 -13\n11 2 -3", "-6 -8 0\n-6 4 16\n-6 8 -12\n-6 20 4\n14 -8 0\n14 4 16\n14 8 -12\n14 20 4", "5 6 5\n5 3 3\n3 3 3\n5 5 3\n5 3 3\n5 3 3\n5 5 3\n3 5 5", "5 2 0\n3 -3 -4\n3 -6 0\n4 3 -4\n-1 -2 5\n-6 -3 1\n-5 6 -1\n2 0 6", "-369 846 805\n-293 846 -369\n729 846 805\n-252 -369 805\n846 -293 729\n805 729 -252\n-252 -369 -293\n729 -293 -252", "-4897 -1234 2265\n-4897 -3800 2265\n-4897 -1234 -301\n-3800 -2331 -301\n-2331 -1234 2265\n-2331 -1234 -301\n-3800 -2331 2265\n-4897 -3800 -301", "93 68 15\n93 43 23\n40 40 -30\n43 40 23\n93 -2 -5\n68 40 15\n93 40 -30\n40 -2 -5", "887691 577079 -337\n-193088 -342950 -683216\n740176 -59645 -120545\n592743 -30828 -283642\n724594 652051 -193925\n87788 -179853 -845476\n665286 -133780 -846313\n828383 -75309 -786168", "-745038 -470013 -245590\n168756 -684402 -45561\n-75879 -670042 -603554\n-168996 -611497 -184954\n-609406 -27512 -217363\n207089 -195060 33124\n-542918 348573 -255696\n229392 -187045 -108360", "-407872 -56765 -493131\n188018 -394436 -612309\n62413 -209242 162348\n-705817 -294501 -652655\n88703 241800 -871148\n-413679 -990326 -109927\n-533477 360978 -507187\n-275258 386648 43170", "411586 -316610 -430676\n-305714 -461321 402733\n-451106 423163 -312524\n-339083 407500 -437486\n391156 -440891 -309800\n387070 -332273 -447701\n-468131 -328187 398647\n-334997 419077 -457916", "-604518 -792421 -794968\n-639604 -845386 -664545\n-668076 -739456 -703162\n-770475 -692569 -880696\n-933661 -784375 -706917\n-774006 -756127 -774766\n-600987 -731410 -898351\n-847933 -827731 -710448", "-83163 759234 174591\n77931 -88533 920334\n72567 974034 158481\n18861 169227 893484\n-61689 8127 839784\n678684 34971 13497\n174597 115521 732384\n77937 255141 812934", "-845276 245666 -196657\n-353213 152573 375200\n-725585 -73510 322004\n-565997 524945 282107\n228911 298862 -938369\n-103564 -126706 -632492\n99377 -50368 -260120\n-143461 471749 -472904", "554547 757123 -270279\n935546 -159145 137545\n-160481 19278 -805548\n655167 -983971 121234\n119898 315968 -261101\n833590 -576147 -592458\n-58525 452591 -91856\n-694414 17942 -397724", "36924 92680 350843\n697100 521211 -77688\n-351925 -610088 36924\n867468 -160261 -98984\n-181557 697100 -780456\n-588792 -133444 329547\n207292 -330629 71384\n526732 -759160 499915", "-593659 350000 928723\n620619 638757 388513\n620619 -882416 -632172\n600244 312515 -843903\n292140 -535799 -881388\n-940276 -573284 -574312\n330653 696617 -573284\n-265180 658104 -901763", "861017 -462500 -274005\n652263 66796 629450\n232201 -329899 -968706\n497126 89886 993064\n-197575 -694067 -406329\n463768 728693 -836382\n-164771 -429142 519939\n-561466 761497 -42438", "484554 -73939 147289\n333153 -73939 -152694\n-737739 33170 970401\n670418 784537 -73939\n333153 -152694 -737739\n-737739 670418 784537\n33170 -73939 970401\n-737739 484555 147289", "-37445 372374 21189\n398542 125861 400869\n479373 -209864 -50773\n-364789 163030 67227\n505541 -260117 189198\n374701 -520 335205\n41059 -155444 -236032\n-26688 230533 -63613", "163459 129764 357112\n277260 476888 633667\n476888 504608 -146791\n163459 633667 277260\n705 476888 781163\n163459 781163 705\n-146791 163459 504608\n357112 129764 476888", "486623 24823 303304\n-389873 -376490 -388969\n170755 -644350 631652\n291143 -838926 -571066\n984320 -169753 36666\n-157910 -911574 643812\n365331 -194393 -49365\n-716998 -37204 292047", "120639 -932662 -1032\n983000 -56439 15066\n-322992 -369232 -780849\n339080 -136928 -886422\n419570 845049 337026\n900456 201129 -288742\n-700359 578496 274688\n764559 -224350 -564462", "-223515 128661 119249\n-83250 119249 203469\n278216 128661 -223515\n-298323 268926 278216\n278216 -158058 343734\n119249 -158058 343734\n-83250 278216 203469\n119249 -298323 -391850", "802442 276413 311941\n132940 -916927 26771\n-629566 336080 371608\n-165395 813416 86438\n-404063 742775 288571\n848944 86438 -200923\n-689233 -344396 -379924\n97412 26771 -881399", "830446 -93089 -271247\n50376 285279 761701\n509464 371358 90913\n-242554 -825792 165148\n-552177 744367 417385\n-403353 -293940 446078\n-437405 141814 -586870\n101762 55735 -896493", "-110591 329051 328269\n611888 45432 657925\n493733 776570 273666\n163587 -119250 273667\n392312 557286 877991\n557286 -220671 265008\n713309 173028 -55989\n891924 227630 429690", "-431644 -468238 -47168\n-152500 38126 -96046\n-507008 604168 -871390\n33597 -320912 410318\n231976 -765065 -282142\n90050 317270 -485921\n-693104 -301158 -245547\n-134816 689462 -299825", "-1 1 1\n0 1 1\n1 1 0\n1 0 0\n0 1 0\n1 1 1\n0 0 0\n0 0 1", "-1000000 1000000 1000000\n-1000000 -1000000 -1000000\n-1000000 1000000 -1000000\n1000000 1000000 1000000\n1000000 -1000000 -1000000\n-1000000 1000000 1000000\n-1000000 -1000000 1000000\n1000000 1000000 -1000000", "-1000000 1000000 1000000\n-1000000 1000000 -1000000\n-1000000 1000000 -1000000\n1000000 -1000000 1000000\n1000000 1000000 1000000\n-1000000 -1000000 1000000\n999999 1000000 -1000000\n-1000000 -1000000 -1000000", "-96608 -96608 100000\n100000 100000 -96608\n100000 -96608 -96608\n-96608 -96608 -96608\n-96608 100000 100000\n100000 100000 100000\n100000 100000 -96608\n-96608 -96608 100000", "65536 0 65536\n65536 0 0\n0 65536 0\n65536 65536 65536\n65536 0 65536\n0 0 0\n0 0 65536\n65536 0 65536", "-524288 -524288 -524288\n-524288 524288 -524288\n-524288 -524288 524288\n-524288 524288 524288\n524288 -524288 -524288\n-524288 524288 524288\n524288 524288 524288\n524288 524288 -524288", "524288 -524288 524288\n-524288 -524288 -524288\n524288 -524288 -524288\n524288 524288 -524288\n524288 -524288 524288\n524288 524288 524288\n-524288 524288 -524288\n-524289 524288 -524288", "0 0 0\n1 1 1\n2 2 2\n3 3 3\n4 4 4\n5 5 5\n6 6 6\n7 7 7", "0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0", "0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0\n0 0 0", "1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "0 0 1\n0 0 1\n0 0 1\n0 0 1\n0 0 1\n0 0 1\n0 0 1\n0 0 1", "0 0 0\n0 0 939177\n0 0 939177\n0 0 939177\n0 939177 939177\n0 939177 939177\n0 939177 939177\n939177 939177 939177"], "outputs": ["YES\n0 0 0\n0 0 1\n0 1 0\n1 0 0\n0 1 1\n1 0 1\n1 1 0\n1 1 1", "NO", "YES\n0 0 0\n0 0 1\n0 1 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1", "NO", "YES\n-8 -5 -3\n-8 -5 8\n3 6 -3\n3 6 8\n-8 6 -3\n-8 6 8\n3 -5 -3\n3 -5 8", "YES\n-6 1 3\n3 1 -6\n0 -5 0\n-3 7 -3\n6 -2 6\n0 4 9\n9 4 0\n3 10 3", "YES\n-13 -10 -6\n-13 2 -15\n2 -10 -6\n2 2 -15\n-13 -1 6\n2 -1 6\n-13 11 -3\n2 11 -3", "YES\n-8 -6 0\n4 -6 16\n8 -6 -12\n20 -6 4\n-8 14 0\n4 14 16\n8 14 -12\n20 14 4", "NO", "NO", "YES\n-369 805 846\n-369 -293 846\n729 805 846\n-369 805 -252\n729 -293 846\n729 805 -252\n-369 -293 -252\n729 -293 -252", "YES\n-4897 -1234 2265\n-4897 -3800 2265\n-4897 -1234 -301\n-2331 -3800 -301\n-2331 -1234 2265\n-2331 -1234 -301\n-2331 -3800 2265\n-4897 -3800 -301", "YES\n15 68 93\n43 23 93\n-30 40 40\n43 23 40\n-2 -5 93\n15 68 40\n-30 40 93\n-2 -5 40", "YES\n-337 577079 887691\n-193088 -683216 -342950\n-59645 740176 -120545\n592743 -30828 -283642\n652051 -193925 724594\n-845476 87788 -179853\n-133780 -846313 665286\n-786168 -75309 828383", "YES\n-745038 -470013 -245590\n-684402 -45561 168756\n-603554 -75879 -670042\n-168996 -611497 -184954\n-27512 -217363 -609406\n33124 207089 -195060\n-542918 348573 -255696\n-108360 -187045 229392", "YES\n-493131 -407872 -56765\n-612309 188018 -394436\n162348 -209242 62413\n-294501 -705817 -652655\n241800 88703 -871148\n-413679 -109927 -990326\n360978 -507187 -533477\n43170 386648 -275258", "YES\n-430676 -316610 411586\n-461321 -305714 402733\n-451106 -312524 423163\n-437486 -339083 407500\n-440891 -309800 391156\n-447701 -332273 387070\n-468131 -328187 398647\n-457916 -334997 419077", "YES\n-794968 -792421 -604518\n-639604 -845386 -664545\n-703162 -739456 -668076\n-692569 -880696 -770475\n-784375 -933661 -706917\n-756127 -774766 -774006\n-731410 -898351 -600987\n-847933 -827731 -710448", "YES\n-83163 174591 759234\n-88533 77931 920334\n72567 158481 974034\n169227 18861 893484\n8127 -61689 839784\n13497 34971 678684\n174597 115521 732384\n77937 255141 812934", "YES\n-845276 -196657 245666\n-353213 375200 152573\n-725585 322004 -73510\n-565997 282107 524945\n-938369 228911 298862\n-632492 -103564 -126706\n-260120 -50368 99377\n-472904 -143461 471749", "YES\n-270279 554547 757123\n137545 -159145 935546\n-805548 19278 -160481\n-983971 121234 655167\n315968 -261101 119898\n-576147 -592458 833590\n-91856 452591 -58525\n-397724 -694414 17942", "YES\n36924 92680 350843\n697100 -77688 521211\n36924 -610088 -351925\n867468 -98984 -160261\n697100 -780456 -181557\n-133444 -588792 329547\n207292 71384 -330629\n526732 -759160 499915", "YES\n-593659 350000 928723\n638757 388513 620619\n-632172 -882416 620619\n600244 -843903 312515\n292140 -535799 -881388\n-940276 -574312 -573284\n330653 696617 -573284\n-901763 658104 -265180", "YES\n-462500 -274005 861017\n66796 652263 629450\n232201 -968706 -329899\n993064 89886 497126\n-694067 -406329 -197575\n463768 -836382 728693\n-164771 519939 -429142\n761497 -42438 -561466", "NO", "NO", "YES\n129764 163459 357112\n277260 476888 633667\n-146791 476888 504608\n277260 163459 633667\n705 476888 781163\n705 163459 781163\n-146791 163459 504608\n129764 476888 357112", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES\n-1000000 1000000 1000000\n-1000000 -1000000 -1000000\n-1000000 -1000000 1000000\n1000000 1000000 1000000\n-1000000 1000000 -1000000\n1000000 -1000000 1000000\n1000000 -1000000 -1000000\n1000000 1000000 -1000000", "NO", "YES\n-96608 -96608 100000\n-96608 100000 100000\n-96608 100000 -96608\n-96608 -96608 -96608\n100000 -96608 100000\n100000 100000 100000\n100000 100000 -96608\n100000 -96608 -96608", "YES\n0 65536 65536\n0 0 65536\n0 65536 0\n65536 65536 65536\n65536 0 65536\n0 0 0\n65536 0 0\n65536 65536 0", "YES\n-524288 -524288 -524288\n-524288 -524288 524288\n-524288 524288 -524288\n-524288 524288 524288\n524288 -524288 -524288\n524288 -524288 524288\n524288 524288 524288\n524288 524288 -524288", "NO", "NO", "NO", "NO", "NO", "NO", "YES\n0 0 0\n0 0 939177\n0 939177 0\n939177 0 0\n0 939177 939177\n939177 0 939177\n939177 939177 0\n939177 939177 939177"]}
UNKNOWN
PYTHON3
CODEFORCES
2
17ec4d515c12743261193390f42cb456
Mr. Bender and Square
Mr. Bender has a digital table of size *n*<=×<=*n*, each cell can be switched on or off. He wants the field to have at least *c* switched on squares. When this condition is fulfilled, Mr Bender will be happy. We'll consider the table rows numbered from top to bottom from 1 to *n*, and the columns — numbered from left to right from 1 to *n*. Initially there is exactly one switched on cell with coordinates (*x*,<=*y*) (*x* is the row number, *y* is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on. For a cell with coordinates (*x*,<=*y*) the side-adjacent cells are cells with coordinates (*x*<=-<=1,<=*y*), (*x*<=+<=1,<=*y*), (*x*,<=*y*<=-<=1), (*x*,<=*y*<=+<=1). In how many seconds will Mr. Bender get happy? The first line contains four space-separated integers *n*,<=*x*,<=*y*,<=*c* (1<=≤<=*n*,<=*c*<=≤<=109; 1<=≤<=*x*,<=*y*<=≤<=*n*; *c*<=≤<=*n*2). In a single line print a single integer — the answer to the problem. Sample Input 6 4 3 1 9 3 8 10 Sample Output 0 2
[ "# import math\nfrom collections import Counter, deque, defaultdict\n# from math import *\n\nfrom bisect import bisect_right\n\nMOD = 1000000007\n\n\n# from functools import reduce\n# from itertools import permutations\n# import queue\n\ndef solve():\n x, y, n, c = 0, 0, 0, 0\n\n def suma_impares(m):\n return m * m\n\n def suma_n(m):\n return m * (m - 1) // 2\n\n def cnt(t):\n u, d, l, r = x + t, x - t, y - t, y + t\n suma = t ** 2 + (t + 1) ** 2\n if u > n: suma -= suma_impares(u - n)\n if d < 1: suma -= suma_impares(1 - d)\n if l < 1: suma -= suma_impares(1 - l)\n if r > n: suma -= suma_impares(r - n)\n if 1 - l > x - 1 and 1 - d > y - 1:\n suma += suma_n(2 - l - x)\n if r - n > x - 1 and 1 - d > n - y:\n suma += suma_n(r - n - x + 1)\n if 1 - l > n - x and u - n > y - 1:\n suma += suma_n(1 - l - n + x)\n if u - n > n - y and r - n > n - x:\n suma += suma_n(u - n - n + y)\n return suma\n\n\n n, x, y, c = input().split()\n n, x, y, c = int(n), int(x), int(y), int(c)\n # for i in range(10):\n #\tprint(i, cnt(i))\n ini, fin = 0, int(1e9)\n cont = int(1e9)\n while cont > 0:\n m = ini\n paso = cont // 2\n m += paso\n if cnt(m) < c:\n ini = m + 1\n cont -= paso + 1\n else:\n cont = paso\n print(ini)\n\n\n\n\n\n\n# t = int(input())\nt = 1\nfor num in range(t):\n # print(\"Case #{}: \".format(num + 1), end=\"\")\n solve()\n\n\t\t \t \t \t\t \t \t\t\t \t \t \t", "\r\n\r\ndef compute(n,x,y,c):\r\n \r\n x1=min(x-1,n-x)\r\n x2=n-x1-1\r\n y1=min(y-1,n-y)\r\n y2=n-y1-1\r\n \r\n \r\n i1=x1+y1+1\r\n i2=min(y1+x2,y2+x1)+1\r\n i3=max(y1+x2,y2+x1)+1\r\n \r\n o1=min(x1,y1)\r\n o2=min(max(x1,y1),min(y2,x2))\r\n o3=max(max(x1,y1),min(y2,x2))\r\n o4=max(y2,x2)\r\n \r\n inside=0\r\n out=0\r\n s=0\r\n current=1\r\n Happy=False\r\n if c==1:\r\n print(0)\r\n return 0\r\n while(Happy==False):\r\n s+=1\r\n new=((s+1)*4)-4\r\n #print(\"new:\",new)\r\n out=out+out_new(s,o1)+out_new(s,o2)+out_new(s,o3)+out_new(s,o4)\r\n #print(\"out:\",out)\r\n inside=inside+in_new(s,i1)+in_new(s,i2)+in_new(s,i3)\r\n #print(\"inside:\",inside)\r\n current=current+new\r\n #print(\"current:\",current)\r\n test=current-out+inside \r\n #print(\"test:\",test)\r\n if test>= c:\r\n print(s)\r\n break\r\n return s\r\n \r\n \r\n\r\n\r\n\r\ndef out_new(s,sx):\r\n if sx<s:\r\n return (((s-sx)*2)-1)\r\n else: \r\n return 0\r\n\r\ndef in_new(s,sx):\r\n if sx<s: \r\n return (s-sx)\r\n else:\r\n return 0\r\n \r\nx=input()\r\ny=x.split()\r\n#print(y) \r\na=int(y[0])\r\nb=int(y[1])\r\nc=int(y[2])\r\nd=int(y[3])\r\ncompute(a,b,c,d)", "def cul(p):\n if p<=0:return 0\n return (p*(p+1))//2\n\ndef judge(p):\n a,b,c,d=x-1,y-1,n-x,n-y\n ans=min(p,a)+min(p,b)+min(p,c)+min(p,d)+1\n p-=1\n ans+=cul(p)*4-2*cul(p-a)-2*cul(p-b)-2*cul(p-c)-2*cul(p-d)\n ans+=cul(p-a-b)+cul(p-b-c)+cul(p-c-d)+cul(p-d-a)\n return ans>=m\n\nn,x,y,m=map(int,input().split())\nl,r,ans=0,int(1e9),0\nwhile l<=r:\n mid=(l+r)//2\n if judge(mid):\n ans=mid\n r=mid-1\n else:\n l=mid+1\nprint(ans)\n\t \t\t \t \t\t \t \t \t", "\nn, x, y, c = map(int, input().split())\nl = -1\nr = 1000000000\nwhile r - l > 1:\n m = (r + l) // 2\n p = 2 * (m ** 2) + 2 * m + 1\n p1 = max(0, (m - x + 1)) ** 2\n p2 = max(0, (x + m - n)) ** 2\n p3 = max(0, (y + m - n)) ** 2\n p4 = max(0, (m - y + 1)) ** 2\n pp1 = (max(m - x - y + 1, 0) * (max(m - x - y + 1, 0) + 1)) // 2\n pp2 = (max(m - n + x - y, 0) * (max(m - n + x - y, 0) + 1)) // 2\n pp3 = (max(m - n + y - x, 0) * (max(m - n + y - x, 0) + 1)) // 2\n pp4 = (max(m - 2 * n + x + y - 1, 0) * (max(m - 2 * n + x + y - 1, 0) + 1)) // 2\n if p - p1 - p2 - p3 - p4 + pp1 + pp2 + pp3 + pp4 >= c:\n r = m\n else:\n l = m\nprint(r)\n\t\t \t \t\t\t \t\t \t\t\t \t\t \t\t\t \t\t\t", "x, y, n, c = 0, 0, 0, 0\ndef suma_impares(m):\n\treturn m * m\ndef suma_n(m):\n\treturn m * (m - 1) // 2\ndef cnt(t):\n\tu, d, l, r = x + t, x - t, y - t, y + t\n\tsuma = t ** 2 + (t + 1) ** 2\n\tif u > n: suma -= suma_impares(u - n)\n\tif d < 1: suma -= suma_impares(1 - d)\n\tif l < 1: suma -= suma_impares(1 - l)\n\tif r > n: suma -= suma_impares(r - n)\n\tif 1 - l > x - 1 and 1 - d > y - 1:\n\t\tsuma += suma_n(2 - l - x)\n\tif r - n > x - 1 and 1 - d > n - y:\n\t\tsuma += suma_n(r - n - x + 1)\n\tif 1 - l > n - x and u - n > y - 1:\n\t\tsuma += suma_n(1 - l - n + x)\n\tif u - n > n - y and r - n > n - x:\n\t\tsuma += suma_n(u - n - n + y)\n\treturn suma\n\t\nn, x, y, c = input().split()\nn, x, y, c = int(n), int(x), int(y), int(c)\n#for i in range(10):\n#\tprint(i, cnt(i))\nini, fin = 0, int(1e9)\ncont = int(1e9)\nwhile cont > 0:\n\tm = ini\n\tpaso = cont // 2\n\tm += paso\n\tif cnt(m) < c:\n\t\tini = m + 1\n\t\tcont -= paso + 1\n\telse:\n\t\tcont = paso\nprint(ini)\n \t \t \t\t \t\t \t \t\t \t \t\t \t\t", "import sys\n\ndef sqr(x):\n return x * x\n\ndef tri(x):\n return (x + 1) * x // 2\n\ndef solve(t):\n sum_ = t * t + (t + 1) * (t + 1)\n if t > l: sum_ -= sqr(t - l)\n if t > r: sum_ -= sqr(t - r)\n if t > u: sum_ -= sqr(t - u)\n if t > d: sum_ -= sqr(t - d)\n if t > l + d: sum_ += tri(t - (l + d) - 1)\n if t > l + u: sum_ += tri(t - (l + u) - 1)\n if t > r + d: sum_ += tri(t - (r + d) - 1)\n if t > r + u: sum_ += tri(t - (r + u) - 1)\n return sum_ >= c\n\nfor line in sys.stdin:\n n, x, y, c = map(int, line.split())\n l, r, u, d = x - 1, n - x, y - 1, n - y\n low, high = 0, 2 * n\n while low <= high:\n mid = (low + high) // 2\n if solve(mid): high = mid - 1\n else: low = mid + 1\n print(low)\n\n\t\t \t\t \t\t\t\t \t \t \t\t\t \t\t\t \t\t\t", "import sys\r\nii = lambda: sys.stdin.readline().strip()\r\nidata = lambda: [int(x) for x in ii().split()]\r\nsdata = lambda: list(ii())\r\n\r\ndef solve():\r\n n, x, y, c = idata()\r\n r = n ** 2\r\n l = -1\r\n while l + 1 < r:\r\n middle = (l + r) // 2\r\n ans = 1 + 2 * (middle + 1) * middle\r\n ans -= pow(middle - n + y, 2) if middle - n + y > 0 else 0\r\n ans -= pow(middle + 1 - y, 2) if middle + 1 - y > 0 else 0\r\n ans -= pow(middle - n + x, 2) if middle - n + x > 0 else 0\r\n ans -= pow(middle + 1 - x, 2) if middle + 1 - x > 0 else 0\r\n d = 1 + n - x + y\r\n if middle >= d:\r\n ans += (middle - d + 1) * (middle - d + 2) // 2\r\n d = 2 + 2 * n - y - x\r\n if middle >= d:\r\n ans += (middle - d + 1) * (middle - d + 2) // 2\r\n d = 1 + n - y + x\r\n if middle >= d:\r\n ans += (middle - d + 1) * (middle - d + 2) // 2\r\n d = x + y\r\n if middle >= d:\r\n ans += (middle - d + 1) * (middle - d + 2) // 2\r\n if ans >= c:\r\n r = middle\r\n else:\r\n l = middle\r\n print(r)\r\n return\r\n\r\nfor t in range(1):\r\n solve()" ]
{"inputs": ["6 4 3 1", "9 3 8 10", "9 4 3 10", "9 8 2 10", "1 1 1 1", "10 7 2 7", "8 2 6 10", "8 1 2 10", "6 1 4 10", "1000000 951981 612086 60277", "1000000 587964 232616 62357", "1000000 948438 69861 89178", "1000000000 504951981 646612086 602763371", "1000000000 81587964 595232616 623563697", "1000000000 55 60 715189365", "1000000000 85 61 857945620", "1000000000 55 85 423654797", "1000000000 63 65 384381709", "1000000000 44 30 891773002", "1000000000 6 97 272656295", "1000000000 999999946 999999941 715189365", "1000000000 999999916 999999940 857945620", "1000000000 999999946 999999916 423654797", "1000000000 999999938 999999936 384381709", "1000000000 55 999999941 715189365", "1000000000 85 999999940 857945620", "1000000000 55 999999916 423654797", "1000000000 63 999999936 384381709", "1000000000 44 999999971 891773002", "1000000000 6 999999904 272656295", "1000000000 999999946 60 715189365", "1000000000 999999916 61 857945620", "1000000000 999999946 85 423654797", "1000000000 999999938 65 384381709", "1000000000 999999957 30 891773002", "548813503 532288332 26800940 350552333", "847251738 695702891 698306947 648440371", "891773002 152235342 682786380 386554406", "812168727 57791401 772019566 644719499", "71036059 25478942 38920202 19135721", "549 198 8 262611", "848 409 661 620581", "892 364 824 53858", "813 154 643 141422", "72 40 68 849", "958 768 649 298927", "800 305 317 414868", "721 112 687 232556", "522 228 495 74535", "737 231 246 79279", "6 4 3 36", "9 3 8 55", "9 4 3 73", "9 8 2 50", "1 1 1 1", "10 7 2 7", "8 2 6 20", "8 1 2 64", "6 1 4 15", "8 8 3 1"], "outputs": ["0", "2", "2", "2", "0", "2", "2", "3", "3", "174", "177", "211", "17360", "17657", "37707", "41279", "28970", "27600", "42159", "23250", "37707", "41279", "28970", "27600", "37707", "41279", "28970", "27600", "42159", "23250", "37707", "41279", "28970", "27600", "42159", "13239", "18006", "13902", "17954", "3093", "635", "771", "183", "299", "25", "431", "489", "556", "249", "199", "6", "7", "8", "7", "0", "2", "3", "13", "3", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
7
17ff19eef74317819cc833b0e6176d2b
Heidi and Library (hard)
The good times at Heidi's library are over. Marmots finally got their internet connections and stopped coming to the library altogether. Not only that, but the bookstore has begun charging extortionate prices for some books. Namely, whereas in the previous versions each book could be bought for 1 CHF, now the price of book *i* is *c**i* CHF. The first line of input will contain two integers *n* and *k* (). The second line will contain *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) – the sequence of book requests. The third line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (0<=≤<=*c**i*<=≤<=106) – the costs of the books. On a single line print the minimum cost of buying books at the store so as to satisfy all requests. Sample Input 4 80 1 2 2 1 1 1 1 1 4 1 1 2 2 1 1 1 1 1 4 2 1 2 3 1 1 1 1 1 7 2 1 2 3 1 1 1 2 1 10 1 0 0 0 0 Sample Output 23313
[ "import sys\r\nfrom heapq import heappop, heappush\r\n \r\nclass Edge:\r\n def __init__(self, u, v, cap, cost, rev):\r\n self.u = u\r\n self.v = v\r\n self.cap = cap\r\n self.flow = 0\r\n self.cost = cost\r\n self.rev = rev\r\n\r\ndef add_edge(adj, u, v, capv, costv):\r\n adj[u].append(Edge(u, v, capv, costv, len(adj[v])))\r\n adj[v].append(Edge(v, u, 0, -costv, len(adj[u])-1))\r\n\r\ndef bellman_ford(adj):\r\n potential = [0] * len(adj)\r\n\r\n for _ in range(len(adj)):\r\n for u in range(len(adj)):\r\n for e in adj[u]:\r\n reduced_cost = potential[e.u] + e.cost - potential[e.v]\r\n if e.cap > 0 and reduced_cost < 0:\r\n potential[e.v] += reduced_cost\r\n \r\n return potential\r\n\r\ndef dijkstra(adj, potential, s, t):\r\n oo = float('inf')\r\n dist, pi = [+oo] * len(adj), [None] * len(adj)\r\n\r\n dist[s] = 0\r\n heap = [(0, s)]\r\n\r\n while heap:\r\n du, u = heappop(heap)\r\n\r\n if dist[u] < du: continue\r\n if u == t: break\r\n\r\n for e in adj[u]:\r\n reduced_cost = potential[e.u] + e.cost - potential[e.v]\r\n if e.cap - e.flow > 0 and dist[e.v] > dist[e.u] + reduced_cost:\r\n dist[e.v] = dist[e.u] + reduced_cost\r\n heappush(heap, (dist[e.v], e.v))\r\n pi[e.v] = e\r\n \r\n return dist, pi\r\n\r\ndef min_cost_max_flow(adj, s, t, flow_limit = float('inf')):\r\n min_cost, max_flow = 0, 0\r\n oo = float('inf')\r\n\r\n potential = bellman_ford(adj)\r\n\r\n while True:\r\n dist, pi = dijkstra(adj, potential, s, t)\r\n \r\n if dist[t] == +oo:\r\n break\r\n \r\n for u in range(len(adj)):\r\n if dist[u] < dist[t]:\r\n potential[u] += dist[u] - dist[t]\r\n \r\n limit, v = +oo, t\r\n while v:\r\n e = pi[v]\r\n limit = min(limit, e.cap - e.flow)\r\n v = e.u\r\n \r\n max_limit_reached = max_flow + limit >= flow_limit\r\n limit = max_limit_reached and flow_limit - max_flow or limit\r\n\r\n if max_limit_reached:\r\n min_cost += limit * (potential[t] - potential[s])\r\n max_flow += limit\r\n\r\n return min_cost, max_flow\r\n \r\n v = t\r\n while v:\r\n e = pi[v]\r\n e.flow += limit\r\n adj[v][e.rev].flow -= limit\r\n v = e.u\r\n \r\n min_cost += limit * (potential[t] - potential[s])\r\n max_flow += limit\r\n \r\n return min_cost, max_flow\r\n\t\t\r\nn, k = map(int, sys.stdin.readline().split())\r\n# n, k = map(int, \"7 2\".split())\r\n# n, k = map(int, \"4 80\".split())\r\npre = [None] * (n + 1)\r\ns, t = 0, 2 * n + 1\r\nadj = [[] for _ in range(t + 1)]\r\na = [None] + list(map(int, sys.stdin.readline().split()))\r\n# a = [None] + list(map(int, \"1 2 3 1 1 1 2\".split()))\r\n# a = [None] + list(map(int, \"1 2 2 1\".split()))\r\nfor i in range(1, n+1):\r\n add_edge(adj, i, i+n, 1, 0)\r\n add_edge(adj, i+n, t, 1, 0)\r\n\r\nc = [None] + list(map(int, sys.stdin.readline().split()))\r\n# c = [None] + list(map(int, \"1 10 1 0 0 0 0\".split()))\r\n# c = [None] + list(map(int, \"1 1 1 1\".split()))\r\n\r\nfor i in range(1, n+1):\r\n add_edge(adj, s, i, 1, c[a[i]])\r\n\r\n if pre[a[i]]:\r\n add_edge(adj, i-1, pre[a[i]] + n, 1, -c[a[i]])\r\n # add_edge(adj, i, pre[a[i]] + n, 1, -c[a[i]])\r\n pre[a[i]] = i\r\n\r\nfor i in range(1, n):\r\n add_edge(adj, i, i+1, k-1, 0)\r\n\r\nmin_cost, _ = min_cost_max_flow(adj, s, t)\r\nprint(min_cost)" ]
{"inputs": ["4 80\n1 2 2 1\n1 1 1 1", "4 1\n1 2 2 1\n1 1 1 1", "4 2\n1 2 3 1\n1 1 1 1", "7 2\n1 2 3 1 1 1 2\n1 10 1 0 0 0 0", "11 1\n1 2 3 5 1 10 10 1 1 3 5\n1 1 2 3 4 5 6 7 8 9 10", "5 2\n1 2 3 1 2\n1 1 1 1 1", "4 2\n1 2 3 2\n1 1 1 1", "80 4\n2 6 10 4 7 8 2 8 9 10 6 2 5 3 2 10 5 9 1 3 4 8 6 1 9 3 9 4 7 7 4 6 4 8 1 2 5 9 7 7 8 7 10 8 3 3 1 6 6 4 5 4 6 3 10 8 1 9 5 2 7 9 1 10 2 9 4 7 10 2 2 8 5 10 4 3 10 7 1 8\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", "80 4\n1 12 2 17 10 17 2 14 12 8 9 7 6 6 20 3 13 5 6 13 10 5 19 18 11 20 4 15 17 15 13 4 17 7 2 11 10 17 6 9 12 2 15 17 17 11 11 4 7 14 13 4 18 3 14 9 12 16 1 5 13 18 19 1 3 6 8 18 4 16 4 17 7 11 10 15 13 12 13 2\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", "80 4\n33 15 1 9 12 4 38 13 36 11 25 27 37 4 30 28 26 1 20 34 5 40 21 40 19 27 2 7 14 23 13 34 25 40 30 11 16 36 39 27 5 12 40 6 28 22 35 4 8 13 32 18 19 15 27 7 18 22 9 39 7 8 39 20 6 39 35 16 32 18 17 35 35 2 15 11 39 38 9 7\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", "80 4\n75 30 64 39 71 25 14 19 45 73 79 60 2 56 58 61 27 17 55 5 52 69 18 52 44 55 14 65 39 32 31 54 43 11 47 66 67 26 10 54 63 31 1 9 18 68 59 68 19 68 32 55 76 15 76 34 78 26 50 13 75 77 38 80 75 51 34 59 24 13 66 80 17 64 40 36 43 18 72 66\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", "80 8\n4 5 15 1 5 20 7 19 17 20 3 15 15 9 18 8 4 17 2 16 3 13 14 4 14 18 18 8 15 1 7 12 20 12 5 2 15 10 3 9 11 15 10 17 13 5 3 12 3 16 4 19 1 11 7 11 7 13 15 5 4 2 1 2 14 7 4 20 8 17 9 3 10 10 16 20 13 10 1 5\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", "80 8\n32 24 35 36 6 38 3 2 5 39 34 15 25 27 20 29 32 22 27 33 31 40 36 6 34 37 24 17 15 21 12 30 28 21 33 33 21 21 36 38 24 17 23 27 32 24 22 32 29 24 20 30 9 24 3 21 13 19 7 28 10 36 20 21 1 29 11 30 36 38 2 33 34 21 17 12 7 32 37 2\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", "80 8\n50 39 1 74 58 20 75 8 71 70 49 24 6 79 33 31 57 38 14 3 69 5 1 18 19 41 52 59 33 54 69 2 46 33 26 16 16 35 23 50 2 77 9 53 62 30 30 64 55 79 43 11 51 72 69 80 73 24 56 1 7 80 19 1 14 8 26 57 68 74 51 5 1 66 42 53 66 36 61 45\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", "80 12\n10 12 13 7 18 13 18 14 9 4 10 8 8 10 13 4 4 17 13 4 8 15 19 6 9 15 13 8 5 18 2 11 15 11 13 19 11 16 14 2 3 15 11 1 3 17 4 14 17 6 3 16 1 19 14 13 15 7 12 3 20 10 19 12 13 1 5 11 4 20 6 20 20 19 4 19 18 2 11 6\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", "80 12\n15 15 4 14 24 36 14 9 10 12 1 33 38 28 23 21 32 21 39 17 8 38 26 4 34 38 6 40 38 2 31 38 24 29 1 23 17 11 15 35 20 13 24 6 2 16 4 30 22 37 19 15 10 27 6 31 9 33 28 18 26 28 15 39 3 15 4 8 28 22 39 30 40 26 4 36 8 32 31 23\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", "80 12\n80 62 51 44 19 41 6 14 43 74 80 2 3 8 12 63 57 78 26 67 31 43 63 48 59 18 66 42 39 75 64 42 17 16 74 78 44 49 18 22 46 48 17 41 64 70 52 62 33 60 42 68 3 51 56 42 61 77 21 71 39 33 78 35 49 59 35 28 28 57 8 3 63 47 69 76 67 68 55 65\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", "80 16\n6 8 14 1 34 39 27 38 19 40 34 37 11 10 6 6 23 2 39 40 25 29 1 10 9 32 12 10 15 16 21 18 19 26 36 5 22 20 13 31 14 18 23 11 38 10 31 18 11 16 30 10 16 3 23 29 3 30 26 6 14 8 36 40 31 4 29 38 32 34 40 36 23 4 22 29 7 2 3 10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "80 16\n39 71 4 79 70 20 3 4 68 70 33 30 56 31 66 48 24 66 18 66 16 11 62 14 18 52 40 52 1 49 55 70 52 37 37 28 58 42 15 18 80 78 57 37 28 32 39 10 22 55 69 39 57 43 48 56 55 74 75 59 2 37 59 20 20 80 27 10 24 69 41 40 46 66 7 13 43 70 27 12\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", "80 40\n26 58 50 37 79 48 42 79 69 35 70 63 34 76 8 9 64 38 68 1 78 33 18 18 31 64 64 72 40 11 63 53 22 46 1 31 22 24 66 64 44 29 12 5 13 37 16 80 52 10 20 7 16 46 80 34 21 19 64 80 7 1 53 51 18 67 36 31 4 74 37 63 33 41 37 80 79 55 4 37\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", "80 60\n29 37 46 6 14 8 17 43 5 2 74 34 72 70 29 22 4 71 45 37 57 15 36 66 73 58 33 68 45 40 53 22 16 30 37 21 33 69 11 21 54 10 69 77 36 77 52 6 24 66 63 31 49 19 77 60 3 11 62 67 21 76 67 13 68 74 66 75 78 15 67 63 8 5 69 30 25 79 42 69\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", "80 80\n48 49 57 56 13 64 8 8 68 66 79 68 30 80 17 34 24 57 38 40 3 78 6 67 51 20 18 17 33 69 11 70 25 79 56 11 13 51 69 26 48 23 15 36 59 21 72 27 11 42 41 40 17 55 27 22 65 52 61 53 51 24 34 24 54 2 16 23 40 67 65 46 15 49 37 12 51 70 47 37\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", "80 4\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\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", "80 8\n1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8\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", "80 16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 8 9 10 11 12\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", "80 32\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 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 1 2 3 4 5 6 7 8 9 10 11 12 13 14\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", "80 4\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n7 101 0 641482 72595 818027 16 6639 409228 9213 76774 5822 98534 4 39 62347 0 941653 303 461146 354562 0 0 8735 11 592322 426170 379488 9 36378 637098 9 690665 4 40 52 8 29 506 55 37684 81 6144 49 0 0 0 69 52 6 13907 0 414367 606348 755654 53 9 769895 52 26487 379 14806 7 380 2 8231 79263 42 0 3731 8856 84 0 8 460 0 349 6 168676 6"], "outputs": ["2", "3", "3", "13", "25", "4", "3", "38", "53", "61", "66", "36", "48", "61", "25", "45", "57", "37", "48", "51", "53", "52", "23", "17", "20", "34", "714283"]}
UNKNOWN
PYTHON3
CODEFORCES
1
183d5529b0961a41597819ab12cd61be
Voltage Keepsake
You have *n* devices that you want to use simultaneously. The *i*-th device uses *a**i* units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·*a**i* units of power. The *i*-th device currently has *b**i* units of power stored. All devices can store an arbitrary amount of power. You have a single charger that can plug to any single device. The charger will add *p* units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·*p* units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible. You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power. If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. The first line contains two integers, *n* and *p* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*p*<=≤<=109) — the number of devices and the power of the charger. This is followed by *n* lines which contain two integers each. Line *i* contains the integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100<=000) — the power of the device and the amount of power stored in the device in the beginning. If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=4. Namely, let's assume that your answer is *a* and the answer of the jury is *b*. The checker program will consider your answer correct if . Sample Input 2 1 2 2 2 1000 1 100 1 1 3 5 4 3 5 2 6 1 Sample Output 2.0000000000-1 0.5000000000
[ "from math import inf\r\nn, p = [int(x) for x in input().split()]\r\nl = []\r\nfor i in range(n):\r\n a, b = [int(x) for x in input().split()]\r\n l.append((a, b, b/a))\r\nl.sort(key=lambda x: x[2])\r\nasum = 0\r\nbsum = 0\r\nsumt = 0\r\nfor i in range(n):\r\n a0, b0, _ = l[i]\r\n c1 = inf if i == n-1 else l[i+1][2]\r\n asum += a0\r\n bsum += b0\r\n dp = asum - p\r\n if dp > 0:\r\n t = bsum / dp\r\n if t < c1:\r\n print(t)\r\n exit()\r\nprint(-1)", "n, x = map(int, input().split())\nsas = -x\nbob = 0\nde = [list(map(int, input().split())) for _ in range(n)]\n\nfor i in de:\n sas += i[0]\n bob += i[1]\n\nde.sort(key=lambda k: k[0] / k[1])\n\nfor j, l in de:\n if bob * j < sas * l:\n sas -= j\n bob -= l\n\nprint(bob / sas if sas > 0 else -1)\n\t \t\t \t\t \t \t\t\t \t\t \t\t \t\t \t", "import sys\r\ninput=sys.stdin.readline\r\nn,p=map(int,input().split())\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\ns=sum(a)\r\nif s<=p:\r\n print(-1)\r\n exit()\r\nt=[b[i]/a[i] for i in range(n)]\r\nINF=10**10+1\r\nl=0\r\nr=INF\r\nwhile r-l>10**(-5):\r\n x=l+(r-l)/2\r\n use=0\r\n for i in range(n):\r\n use+=max(x*a[i]-b[i],0)\r\n if use/x<=p:\r\n l=x\r\n else:\r\n r=x\r\nprint(l)", "n, x = map(int, input().split())\na = -x\nb = 0\npairs = [list(map(int, input().split())) for _ in range(n)]\n\nfor pair in pairs:\n a += pair[0]\n b += pair[1]\n\npairs.sort(key=lambda k: k[0] / k[1])\n\nfor d, e in pairs:\n if b * d < a * e:\n a -= d\n b -= e\n\nprint(b / a if a>0 else -1) \n\n\t \t\t \t\t \t\t\t\t\t\t \t \t \t\t\t", "def check_infinite(N,P,A,B):\r\n if sum(A) <= P:\r\n return True\r\n return False\r\n\r\ndef f(N,P,A,B):\r\n if check_infinite(N,P,A,B) == True:\r\n return -1\r\n\r\n sa = sum(A) - P\r\n sb = sum(B)\r\n remain = N\r\n deleted = set()\r\n\r\n while True:\r\n found = False\r\n for i in range(N):\r\n if i in deleted:\r\n continue\r\n if remain <= 1:\r\n break\r\n if sa - A[i] <= 0.0:\r\n continue\r\n if ((sb - B[i]) / (sa - A[i])) <= B[i] / A[i]:\r\n remain -= 1\r\n sb -= B[i]\r\n sa -= A[i]\r\n deleted.add(i)\r\n found = True\r\n if not found:\r\n break\r\n return sb / sa\r\n \r\nN, P = input().split(' ')\r\nN = int(N); P = float(P)\r\n\r\nA = []\r\nB = []\r\n\r\nfor _ in range(N):\r\n a, b = [float(x) for x in input().split(' ')]\r\n A.append(a)\r\n B.append(b)\r\n\r\nprint(f(N,P,A,B))", "class SmartReader:\n def __init__(self):\n self.buf = iter([])\n\n def read(self, *factories):\n for factory in factories:\n yield self._next(factory)\n\n def _next(self, factory=str):\n res = next(self.buf, None)\n if res is None:\n self.buf = iter(input().split())\n return self._next(factory)\n return factory(res)\n\n\nreader = SmartReader()\n\nn, power = reader.read(int, int)\ndevices = [tuple(reader.read(int, int)) for i in range(n)]\n\n\ndef can(time):\n need = sum(max(0, use * time - have) for use, have in devices)\n return need <= power * time\n\n\nuse = sum(use for use, _ in devices)\nif use <= power:\n print(-1)\nelse:\n left = 0\n right = 1\n while can(right):\n left = right\n right *= 10\n\n while right - left > 1:\n mid = (left + right) // 2\n if can(mid):\n left = mid\n else:\n right = mid\n\n for i in range(20):\n mid = (left + right) / 2\n if can(mid):\n left = mid\n else:\n right = mid\n\n print(left)\n", "n,x=map(int,(input().split()))\na=-x\nb=0\nl=[list(map(int,input().split())) for _ in range(n)]\nfor i in l:\n a+=i[0]\n b+=i[1]\nl.sort(key=lambda k:k[0]/k[1])\nfor d, e in l:\n if b*d<a*e:\n a-=d\n b-=e\nprint(b/a if a>0 else-1)\n\n\t \t \t\t \t\t \t\t\t\t\t \t\t", "n, p = map(int, input().split())\narr = [tuple(map(int, input().split())) for _ in range(n)]\narr = [(e[1]/e[0], e) for e in arr]\narr.sort()\n\ncurr = [-p, 0]\nworst = float(\"inf\")\nfor e in arr:\n e = e[1]\n curr[0] += e[0]\n curr[1] += e[1]\n if curr[0] <= 0:\n continue\n else:\n worst = min(worst, curr[1]/curr[0])\nif worst == float(\"inf\"):\n worst = -1\nprint(worst)\n\n", "n, x = map(int, input().split())\nsas = -x\nbob = 0\nde = [list(map(int, input().split())) for _ in range(n)]\n\nfor i in de:\n sas += i[0]\n bob += i[1]\n\nde.sort(key=lambda k: k[0] / k[1])\n\nfor d, e in de:\n if bob * d < sas * e:\n sas -= d\n bob -= e\n\nprint(bob / sas if sas > 0 else -1)\n\t\t \t\t \t \t \t\t \t\t\t\t \t\t \t \t \t\t", "n,x=map(int,(input().split()))\r\na=-x\r\nb=0\r\nl=[list(map(int,input().split())) for _ in range(n)]\r\nfor i in l:\r\n a+=i[0]\r\n b+=i[1]\r\nl.sort(key=lambda k:k[0]/k[1])\r\nfor d, e in l:\r\n if b*d<a*e:\r\n a-=d\r\n b-=e\r\nprint(b/a if a>0 else-1)\r\n\r\n\t \t \t\t \t\t \t\t\t\t\t \t\t", "if 1:\r\n N, P = [int(i) for i in input().split()]\r\n p = []\r\n b = []\r\n for _ in range(N):\r\n pp, bb = [int(i) for i in input().split()]\r\n p.append(pp)\r\n b.append(bb)\r\n\r\nelse:\r\n N, P = 10000, 999999999\r\n p = [100000] * N\r\n b = [100000] * N\r\n\r\nsp = sum(p)\r\nsb = sum(b)\r\n\r\nif P >= sp: print(-1)\r\nelse:\r\n ep = sp - P\r\n hi = sb / ep\r\n lo = 0\r\n\r\n while lo + 1e-5 < hi:\r\n t = (lo + hi) / 2\r\n tp = 0\r\n for i in range(N):\r\n mp = t * p[i]\r\n tp += min(mp, b[i])\r\n if tp < t * ep:\r\n hi = t\r\n else:\r\n lo = t\r\n\r\n print(hi)", "num_gadgets, charging_speed = map(int, input().split())\r\n\r\ngadgets = []\r\n\r\ntotal_power_difference = -charging_speed\r\ntotal_energy = 0\r\n\r\nfor i in range(num_gadgets):\r\n gadget_power, gadget_energy = map(int, input().split())\r\n total_power_difference += gadget_power\r\n total_energy += gadget_energy\r\n gadgets.append((gadget_power, gadget_energy))\r\n\r\ngadgets.sort(key=lambda gadget: gadget[0] / gadget[1])\r\n\r\nfor gadget_power, gadget_energy in gadgets:\r\n if gadget_energy * total_power_difference > gadget_power * total_energy:\r\n total_power_difference -= gadget_power\r\n total_energy -= gadget_energy\r\n\r\nmax_working_time = 0\r\nif total_power_difference > 0:\r\n max_working_time = total_energy / total_power_difference\r\nelse:\r\n max_working_time = -1\r\n\r\nprint(max_working_time)# 1698311698.1077688", "#!/usr/bin/env python3\n\n\ndef solve():\n n, p = map(int, input().split())\n persec = []\n cur = []\n for i in range(n):\n a, b = map(int, input().split())\n persec.append(a)\n cur.append(b)\n\n if sum(persec) <= p:\n print(-1)\n return\n\n full_time = 0\n\n curtime = [cur[i] / persec[i] for i in range(len(cur))]\n\n ids = list(range(len(cur)))\n\n ids.sort(key=lambda i: curtime[i])\n\n # print(ids)\n\n cur_next = 0\n powered_minus = 0\n additional_energy = 0\n\n while True:\n if cur_next < len(ids):\n curmin = curtime[ids[cur_next]] - full_time\n next_time = curmin * (p - powered_minus)\n if additional_energy > -next_time:\n additional_energy += curmin * (p - powered_minus)\n full_time += curmin\n powered_minus += persec[ids[cur_next]]\n cur_next += 1\n continue\n full_time += additional_energy / (powered_minus - p)\n break\n\n print(\"%.9f\" % full_time)\n\n\nif __name__ == '__main__':\n solve()\n", "n, p = map(int, input().split())\n\ns = [0]*n\nx, y = -p, 0\n\nfor i in range(n):\n a, b = map(int, input().split())\n x += a\n y += b\n s[i] = (a, b)\n\ns.sort(key=lambda q:q[0] / q[1])\n\ncount = 0\n\nfor a, b in s:\n if b*x > a*y:\n x -= a\n y -= b\n\nprint(y / x if x > 0 else -1)\n \t \t\t \t \t\t\t \t\t \t \t\t\t \t", "n,p = map(int,input().split())\r\ncharge = [tuple(map(int,input().split())) for i in range(n)]\r\ncharge.sort(key=lambda x: x[1]/x[0], reverse=True)\r\n\r\ndef lifetime(x):\r\n if x[0] <= p:\r\n return float('inf')\r\n return x[1]/(x[0]-p)\r\n\r\nwhile len(charge)>1:\r\n a = charge[-1]\r\n b = charge[-2]\r\n if lifetime(a) < b[1]/b[0]:\r\n break\r\n charge.pop()\r\n charge.pop()\r\n charge.append((a[0]+b[0], a[1]+b[1]))\r\n\r\nif len(charge) == 1 and lifetime(charge[0]) == float('inf'):\r\n print(-1)\r\nelse:\r\n print(lifetime(charge[-1]))", "\nn, x = map(int, input().split())\ntotal_power = -x\ntime_left = 0\ndevices = [list(map(int, input().split())) for _ in range(n)]\n\nfor device in devices:\n total_power += device[0]\n time_left += device[1]\n\ndevices.sort(key=lambda k: k[0] / k[1])\n\nfor power, time in devices:\n if time_left * power < total_power * time:\n total_power -= power\n time_left -= time\n\nprint(time_left / total_power if total_power > 0 else -1)\n\t \t \t \t\t\t\t \t \t\t\t \t \t\t \t", "n, p = map(int, input().split())\ns = [0] * n\nx, y = -p, 0\n \nfor i in range(n):\n a, b = map(int, input().split())\n x = x + a\n y = y + b\n s[i] = (a,b)\n \ns.sort(key = lambda q: q[0] / q[1])\n\nfor a,b in s:\n if b * x > a * y :\n x = x - a\n y = y - b\n \nprint(y / x if x > 0 else -1)\n \n\n \t\t \t \t\t\t \t\t\t \t \t \t", "n,x=map(int,input().split())\nsas=-x\nbob=0\nde=[list(map(int,input().split())) for _ in range(n)]\nfor i in de:\n sas+=i[0]\n bob+=i[1]\nde.sort(key=lambda k:k[0]/k[1])\nfor d,e in de:\n if bob*d<sas*e:\n sas-=d\n bob-=e\nif sas<=0:\n print(-1)\nelse:\n print(bob/sas)\n\n\t \t \t\t\t\t\t\t\t\t\t\t\t\t\t \t \t \t\t\t \t", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sun Jun 5 20:35:19 2022\n\n@author: Miro\n\"\"\"\nimport math\nn,p=input().split()\nn=int(n)\np=int(p)\nnum=0\narr=[]\nfor i in range(n):\n a,b=input().split()\n a=int(a)\n b=int(b)\n arr.append([a,b])\n num+=a\nif num>p:\n s=0\n e=1e18\n ans=-1\n while s<=e:\n mid=math.floor((s+e)/2)\n sum=0\n for i in range(n):\n sum+=max(arr[i][0]*mid-arr[i][1],0)\n if sum<=mid*p:\n ans=mid\n s=mid+1\n else:\n e=mid-1\n s2=ans\n e2=ans+1\n ans2=-1\n while s2<=e2:\n mid=(s2+e2)/2\n sum=0\n for i in range(n):\n sum+=max(arr[i][0]*mid-arr[i][1],0.0)\n if sum==mid*p or e2-mid<=0.0001:\n ans2=mid\n break\n elif sum<mid*p:\n s2=mid\n else:\n e2=mid\n print(\"{:.10f}\".format(ans2));\nelse:\n print(-1)\n\n \t \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", "import math\nfrom bisect import bisect_right\nfrom itertools import accumulate\n\nR = lambda: map(int, input().split())\nn, p = R()\ndevs = []\nfor i in range(n):\n devs.append(tuple(R()))\ndevs = sorted(devs, key=lambda x: x[1]/x[0])\nsp, sr, t = 0, 0, math.inf\nfor d in devs:\n sp += d[0]\n sr += d[1]\n if sp > p:\n t = min(t, sr / (sp - p))\nprint(t if t < math.inf else -1)\n\t\t\t\t \t\t \t\t \t\t\t\t\t\t\t \t\t \t\t", "n,x=map(int,input().split())\nsas=-x\nbob=0\nde=[list(map(int,input().split())) for _ in range(n)]\nfor i in de:\n sas+=i[0]\n bob+=i[1]\nde.sort(key=lambda k:k[0]/k[1])\nfor d,e in de:\n if bob*d<sas*e:\n sas-=d\n bob-=e\nprint(bob/sas if sas>0 else -1)\n \t \t\t\t\t \t\t \t\t \t\t \t\t \t \t", "from sys import stdin, stdout\n\nn,p = map(int, stdin.readline().rstrip().split())\n\npowerData = []\npowerList = []\n\nfor i in range(n):\n a,b = map(int, stdin.readline().rstrip().split())\n deathTime = b/a\n powerData.append((a,b,deathTime))\n powerList.append(a)\n\npowerData.sort(key = lambda x: x[2])\n\nif sum(powerList)<=p:\n print(-1)\nelse:\n i=0\n combinedPower=0\n startingPower=0\n while combinedPower<=p:\n combinedPower+=powerData[i][0]\n startingPower+=powerData[i][1]\n i+=1\n finished=False\n deathTime = startingPower/(combinedPower-p)\n while i<n and deathTime>powerData[i][2]:\n combinedPower+=powerData[i][0]\n startingPower+=powerData[i][1]\n deathTime = startingPower/(combinedPower-p) \n i+=1\n print(deathTime)\n \n \n" ]
{"inputs": ["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1", "1 1\n1 87", "1 1\n100 77", "5 10\n3 81\n3 49\n1 20\n1 12\n1 30", "5 10\n4 3\n1 54\n2 57\n2 31\n1 99", "5 10\n2 81\n3 31\n4 49\n1 35\n1 67", "10 1\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92\n1 92", "10 1\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16\n1 16", "10 1\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40\n1 40", "2 1\n1 10\n1 10", "20 16807\n75250 50074\n43659 8931\n11273 27545\n50879 77924\n37710 64441\n38166 84493\n43043 7988\n22504 82328\n31730 78841\n42613 44304\n33170 17710\n97158 29561\n70934 93100\n80279 51817\n95336 99098\n7827 13513\n29268 23811\n77634 80980\n79150 36580\n58822 11968"], "outputs": ["2.0000000000", "-1", "0.5000000000", "-1", "0.7777777778", "-1", "-1", "263.0000000000", "102.2222222222", "17.7777777778", "44.4444444444", "20.0000000000", "0.2244225704"]}
UNKNOWN
PYTHON3
CODEFORCES
22
18570e5f148ba4dbe6c04aea7fe63509
Combination Lock
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that? The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. Sample Input 5 82195 64723 Sample Output 13
[ "n = int(input())\r\ncomb1 = list(map(int, ' '.join(input()).split()))\r\ncomb2 = list(map(int, ' '.join(input()).split()))\r\ncount = 0\r\nfor i in range(n):\r\n a = abs(comb1[i] - comb2[i])\r\n b = 10 - a\r\n count += min(a, b)\r\nprint(count)", "def main():\n n = int(input())\n o = [int(c) for c in input()]\n a = [int(c) for c in input()]\n\n moves = 0\n for i in range(n):\n x, y = (o[i], a[i]) if o[i] > a[i] else (a[i], o[i])\n moves += min(x - y, y + 10 - x)\n\n print(moves)\n\n\nif __name__ == \"__main__\":\n main()\n", "n = input()\r\na1 = list( map( int , list(input() )))\r\na2 = list( map( int , list(input() )))\r\n\r\ndef func(n1, n2):\r\n return min(abs(n1-n2), 10 - abs(n1- n2))\r\ncount = 0\r\nfor n1, n2 in zip(a1, a2):\r\n count += func(n1, n2)\r\nprint(count)\r\n", "n = int(input())\ns = int(input())\nf = int(input())\ncount = 0\nfor i in range(1, n+1):\n c1 = int(s%(10**i)/(10**(i-1)))\n c2 = int(f%(10**i)/(10**(i-1)))\n if abs(c1-c2) <= 5:\n count = count+abs(c1-c2)\n else:\n count = count+10-abs(c1-c2)\n\nprint(count)\n\n\n", "n=int(input())\r\nt=0\r\nfor a,b in zip(input(),input()):\r\n d=abs(int(a)-int(b))\r\n t+=min(d,10-d)\r\nprint(t)\r\n", "n = int(input())\r\ns = input()\r\nkey = input()\r\nmove = 0\r\nfor i in range(len(s)):\r\n x =abs(int(s[i])-int(key[i]))\r\n move+=min(9-x+1,x)\r\nprint(move)\r\n", "n = int(input())\r\norg = input()\r\nlock = input()\r\ncmb = 0\r\nfor i in range(n):\r\n t = abs(int(org[i])-int(lock[i]))\r\n cmb += min(t,10-t)\r\nprint(cmb)", "n = int(input())\r\npre = list(input())\r\nlat = list(input())\r\nstep = 0\r\ndef con(i):\r\n num1 = int(pre[i])\r\n num2 = int(lat[i])\r\n l1 = abs(num1 - num2)\r\n l2 = abs(10 - abs(num1 - num2))\r\n if l1 < l2:\r\n return l1\r\n else:\r\n return l2\r\nfor i in range(n):\r\n step += con(i)\r\nprint(step)", "n = int(input())\r\nstart = [int(x) for x in input()]\r\nend = [int(x) for x in input()]\r\nans = 0\r\nfor i in range(n):\r\n a = abs(start[i] - end[i])\r\n b = start[i] + 10 - end[i]\r\n c = end[i] + 10 - start[i]\r\n ans += min(a, b, c)\r\nprint(ans)", "a=int(input())\r\nb=input()\r\nv=input()\r\np=0\r\nk=0\r\npk=0\r\nkp=0\r\npppkk=0\r\nppkk=0\r\nppk=0\r\nkkpp=0\r\nkkp=0\r\nfor j in range(a):\r\n bb=b[k]\r\n vv=v[k]\r\n bbb=int(bb)\r\n vvv=int(vv)\r\n if bbb==vvv:\r\n p+=0\r\n if bbb>vvv:\r\n pk=bbb-vvv\r\n kp=(vvv+10)-bbb\r\n kkp=str(kp)\r\n kkpp=len(kkp)\r\n ppk=kkpp-1\r\n ppkk=kkp[ppk]\r\n pppkk=int(ppkk)\r\n if pk<pppkk:\r\n p+=pk\r\n else:\r\n p+=pppkk\r\n if bbb<vvv:\r\n pk=vvv-bbb\r\n kp=(10+bbb)-vvv\r\n if pk<kp:\r\n p+=pk\r\n else:\r\n p+=kp\r\n k+=1\r\nprint(p)", "n = int(input())\r\noriginal = input()\r\ntarget = input()\r\nres = 0\r\nfor a,b in zip(original, target):\r\n a,b = int(a), int(b)\r\n res += min(abs(a-b), abs((abs(a-b))-10))\r\nprint(res)", "n = int(input())\na = (input())\nb = (input())\nsum = 0\nfor i in range(n):\n x = min(abs(int(a[i])-int(b[i])),(10-abs(int(a[i])-int(b[i]))))\n sum+=x\nprint(sum)", "n=int(input())\r\nch1=input()\r\nch2=input()\r\nc=0\r\nfor i in range(len(ch1)):\r\n Max=max(int(ch1[i]),int(ch2[i]))\r\n Min=min(int(ch1[i]),int(ch2[i]))\r\n way1=Max-Min\r\n way2=(Min+10)-Max\r\n if way1<way2:\r\n c+=way1\r\n else:\r\n c+=way2\r\nprint(c)\r\n", "k=int(input())\r\nm=input()\r\nn=input()\r\no=0\r\nfor i in range(len(m)):\r\n\tif abs(int(m[i])-int(n[i]))<=5:\r\n\t\to+=abs(int(m[i])-int(n[i]))\r\n\t#\tprint(o,m[i],n[i])\r\n\telse:\r\n\t\tj=abs(int(m[i])-int(n[i]))\r\n\t\tmaxi=max(int(m[i]),int(n[i]))\r\n\t\tu=min(int(m[i]),int(n[i]))+(10-maxi)\r\n\t\to+=u\r\n\t\t#print(o,m[i],n[i])\r\nprint(o)\r\n\t\t\r\n\t\t", "import sys\ninput = sys.stdin.readline\n\nL = int(input())\nON = input().rstrip()\nTL = input().rstrip()\n\nt = 0\nfor i in range(L) :\n A, B = int(ON[i]), int(TL[i])\n if A > B : A, B = B, A\n t += min(B-A, A+(10-B))\nprint(t)\n", "n= int(input())\r\na = str(input())\r\nb = str(input())\r\nlock = 0\r\n\r\nfor i in range(n):\r\n\tif int(a[i]) > int(b[i]):\r\n\t\tlarge = int(a[i])\r\n\t\tsmall = int(b[i])\r\n\telse:\r\n\t\tlarge = int(b[i])\r\n\t\tsmall = int(a[i])\r\n\ttemp = large - 1\r\n\tcount1 = large - small\r\n\tcount2 = small + (9 - temp)\r\n\tif count1 > count2:\r\n\t\tlock += count2\r\n\telse:\r\n\t\tlock += count1\r\n\r\nprint(lock)", "n = int(input())\r\na = [int(x) for x in input()]\r\nb = [int(y) for y in input()]\r\ncount = 0\r\nfor i in range(n):\r\n if a[i]!=b[i]:\r\n if abs(a[i]-b[i])<=4:\r\n count += abs(a[i]-b[i])\r\n else:\r\n count += 10- abs(a[i]-b[i])\r\nprint(count)", "n=int(input())\r\ns=input()\r\np=input()\r\nc=0\r\nfor i in range(n):\r\n t=abs(int(s[i])-int(p[i]))\r\n if(t==1 or t==9):\r\n c+=1\r\n elif(t==2 or t==8):\r\n c+=2\r\n elif(t==3 or t==7):\r\n c+=3\r\n elif(t==4 or t==6):\r\n c+=4\r\n else:\r\n c+=t\r\nprint(c) ", "x=0\r\nn,a,b = int(input()),list(input()),list(input())\r\nfor i in range(n):\r\n temp=abs(int(a[i])-int(b[i]))\r\n x+= temp if temp<10-temp else 10-temp\r\n\r\nprint(x) ", "n = int(input())\r\na = input()\r\nb = input()\r\nans = 0\r\nfor i in range(n):\r\n a1 = int(a[i])\r\n b1 = int(b[i])\r\n ans += (min(abs(a1 - b1) ,min(a1 ,b1) + (9 - max(a1 ,b1) + 1)))\r\nprint(ans)\r\n", "n = int(input())\r\nexpected = int(input())\r\nfinal = int(input())\r\nans = 0\r\nfor _ in range(n):\r\n a, b = expected % 10, final % 10\r\n n = abs(a - b)\r\n ans += min(n, 10 - n)\r\n expected //= 10\r\n final //= 10\r\nprint(ans)\r\n", "n = int(input())\r\np = list(input())\r\nq = list(input())\r\ncount = 0\r\nfor i in range(n):\r\n y, m = int(p[i]), int(q[i])\r\n t = abs(y - m)\r\n if t <= 5:\r\n count += t\r\n else:\r\n count += 10 - max(y, m) + min(y, m)\r\nprint(count)\r\n", "n = int(input())\r\naa = input()\r\na = [int(i) for i in aa]\r\nbb = input()\r\nb = [int(i) for i in bb]\r\ns = 0\r\nfor i in range(n):\r\n c = abs(a[i]-b[i])\r\n if c>5:\r\n d = 10-c\r\n s = s+d\r\n else:\r\n s = s+c\r\nprint(s)", "def combination_lock():\r\n a=input()\r\n b=input()\r\n c=input()\r\n ans=0\r\n for i in range(int(a)):\r\n ans+=min(abs(int(b[i])-int(c[i])),10-abs(int(b[i])-int(c[i])))\r\n print(ans)\r\ncombination_lock()\r\n", "n = int(input())\r\ns = input()\r\ns1 = input()\r\nc = 0\r\nfor i, j in zip(s, s1):\r\n if abs(int(i)-int(j)) <= 5:\r\n c += abs(int(i)-int(j))\r\n else:\r\n c += 10 - max(int(i), int(j))\r\n c += min(int(i), int(j))\r\n \r\nprint(c)", "n = int(input())\r\na = input()\r\ns = input()\r\ncount = 0\r\nfor i in range(n):\r\n if a[i] != s[i]:\r\n if abs(int(a[i])-int(s[i])) < 5:\r\n count += abs(int(a[i])-int(s[i]))\r\n else:\r\n count +=10 - abs(int(a[i])-int(s[i]))\r\nprint(count)", "n = int(input())\nc = input()\nk = input()\n\no = 0\nif (c != k):\n for cc, ck in zip(c,k):\n cc = int(cc)\n ck = int(ck)\n\n ckd = abs(ck-cc)\n if ckd > 5:\n o += 9 - max(cc,ck) + min(cc,ck) + 1\n else:\n o += ckd\n\n\nprint(o)", "n = int(input())\r\narr = list(map(int , input()))\r\nnew = list(map(int , input()))\r\ncount = 0\r\nfor i in range(n):\r\n count += min( abs(arr[i] - new[i]) , 10 - abs(arr[i] - new[i]))\r\nprint(count)", "# -----------------------------------------------------------\r\n# URL : https://codeforces.com/contest/540/problem/A\r\n# Title : Combination Lock\r\n# Notes : tag-codeforces, tag-problem-A, tag-div-2\r\n# -----------------------------------------------------------\r\n\r\n\r\ndef solve():\r\n k = int(input())\r\n a = list(map(int, list(input())))\r\n b = list(map(int, list(input())))\r\n m = 0\r\n\r\n for i in range(k):\r\n x = min(abs(a[i] - b[i]), 10 - abs(a[i] - b[i]))\r\n m += x\r\n\r\n print(m)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n solve()\r\n", "n = int(input())\r\na = [int(x) for x in input()]\r\nb = [int(x) for x in input()]\r\n\r\nans = 0\r\n\r\nfor ind, i in enumerate(a):\r\n x = abs(a[ind] - b[ind])\r\n ans += min(x, 10 - x)\r\nprint(ans)", "n=int(input())\r\nip=input()\r\nop=input()\r\ncount=0;\r\nfor x in range(len(ip)):\r\n n=abs(int(ip[x])-int(op[x]))\r\n #print(int(ip[x]),int(op[x]))\r\n m=abs(10-abs(int(op[x])-int(ip[x])))\r\n #print(n,m)\r\n count+=min(n,m)\r\n #print(count)\r\nprint(count) ", "n = int(input())\r\ncod1 , code2 = input(),input()\r\nresult= 0 \r\nfor i in range(n) : \r\n diff = abs(int(cod1[i]) - int(code2[i])) \r\n if diff <= 5 : \r\n result += diff\r\n else: \r\n minn , maxx = min(int(cod1[i]) , int(code2[i])) , max(int(cod1[i]) , int(code2[i])) \r\n diff = (minn + 10) - maxx \r\n result += diff\r\nprint(result) ", "n=int(input())\r\nch1=input()\r\nch2=input()\r\nc=0\r\nfor i in range(len(ch1)):\r\n Max=max(int(ch1[i]),int(ch2[i]))\r\n Min=min(int(ch1[i]),int(ch2[i]))\r\n way1=Max-Min\r\n way2=(Min+10)-Max\r\n c+=min(way1,way2)\r\nprint(c)", "n = int(input())\nd = input()\ns = input()\nm = 0\nfor i in range(0, n):\n r = abs(int(d[i]) - int(s[i]))\n if r <= 5: m+=r\n else: m+=(10-r)\nprint(m)\n\n\t \t \t \t \t \t\t \t\t \t\t\t \t\t \t", "BASE = 10\nn = int(input())\nstate = input().strip()\nkey = input().strip()\nmoves = 0\nfor i in range(n):\n\td = abs(int(state[i]) - int(key[i]))\n\tmoves += min(d, BASE - d)\nprint(moves) \n\t\n\t\n", "n = int(input())\r\nres = 0\r\nlis1 = input()\r\nlis2 = input()\r\nfor i in range(n):\r\n a = abs(max( int(lis1[i]),int(lis2[i]) ) - 10 ) + min( int(lis1[i]) , int(lis2[i])) \r\n b = abs(int(lis1[i]) - int(lis2[i]))\r\n res += min(a, b)\r\nprint(res)", "n=int(input())\r\norg=input()\r\ncomb=input()\r\nres=0\r\nfor i in range(n):\r\n temp1=int(org[i])\r\n temp2=int(comb[i])\r\n temp3=abs(temp1-temp2)\r\n if temp3>5:\r\n res+=(9%(abs(temp1-temp2)))+1\r\n else:\r\n res+=temp3\r\nprint(res)", "def f(n, s):\r\n x = abs(ord(s) - ord(n))\r\n return min(10 - x, x)\r\n\r\nn = int(input())\r\ns, t = input(), input()\r\nprint(sum([f(s[i], t[i]) for i in range(n)]))", "def test(n, a, b):\r\n t = 0\r\n for i in range(n):\r\n y = int(a[i]) - int(b[i])\r\n x = abs(y)\r\n if(x>5):\r\n t1 = 10 - x\r\n else:\r\n t1 = x\r\n t = t1 + t\r\n \r\n return t\r\n \r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n a = input()\r\n b = input()\r\n r = test(n, a, b)\r\n print(r)", "#540A\r\n\r\n\r\nn = int(input())\r\n# a,b = list(map((input().split())))\r\na = input()\r\nb = input()\r\nans = 0\r\n\r\nfor i in range(0,n):\r\n ans = ans + min(10 -abs(int(a[i])-int(b[i])), abs(int(a[i])- int(b[i])))\r\nprint(ans)\r\n", "\r\ninput();t=0\r\ns=[0,1,2,3,4,5,6,7,8,9]\r\nx=list(map(int,input()))\r\ny=list(map(int,input()))\r\nfor i in range(len(x)):\r\n\tif abs(x[i]-y[i])>5:\r\n\t\tt=t+(9-max(x[i],y[i]))+(s.index(min(x[i],y[i]))+1)\r\n\telse:\r\n\t\tt=t+abs(x[i]-y[i])\r\nprint(t)\r\n\t\t", "h = int(input())\ningre=input()\ncontra=input()\ntotal = 0\nfor i in range (0,h):\n opa= abs(int(ingre[i])-int(contra[i]))\n opb = abs((int(ingre[i])+10)-int(contra[i]))\n opc = abs((int(contra[i])+10)-int(ingre[i]))\n if (opa <= opb and opa<=opc):\n total = total+opa\n else:\n if (opb <= opc and opb<=opa):\n total = total+opb\n else:\n total = total+opc\n\nprint(total)\n\t\t\t\t\t \t \t\t \t \t \t\t \t \t\t\t \t\t", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\ni = 0\r\nnum = 0\r\nwhile i <= n-1:\r\n a = int(s1[i])\r\n b = int(s2[i])\r\n x = abs(a-b)\r\n y = min(a,b) + 10 - max(a,b)\r\n num += min(x,y)\r\n i += 1\r\nprint(num)", "\r\na = int(input())\r\nstart = input()\r\nfinish = input()\r\nD = 0\r\nfor i in range(a):\r\n R = abs(int(start[i]) - int(finish[i]))\r\n if R >= 6:\r\n D += 10 - R\r\n else:\r\n D += R\r\nprint(D)", "def main():\n n = int(input())\n orig = input()\n final = input()\n\n move = 0\n for i in range(0, n):\n move += min(count_up(orig[i], final[i]), count_down(orig[i], final[i]))\n print(move)\n\ndef count_up(a1, a2):\n a1 = int(a1)\n a2 = int(a2)\n\n if a1 == a2: return 0\n if a1 < a2: return a2 - a1\n\n first_step = 9-a1\n first_step += 1\n\n return first_step + a2\n\ndef count_down(a1, a2):\n a1 = int(a1)\n a2 = int(a2)\n\n if a1 == a2: return 0\n if a1 > a2: return a1-a2\n\n return a1 + 1 + (9-a2)\n\nif __name__ == \"__main__\":\n main()", "n=int(input())\narr=list(input())\nbrr=list(input())\ntotal=0\nfor i in range(n):\n total+=min(10-abs(int(arr[i])-int(brr[i])),abs(int(arr[i])-int(brr[i])))\nprint(total)\n \t \t \t\t \t \t \t \t\t \t \t \t\t\t", "disknum = int(input())\r\ncurrlock = [int(x) for x in input()]\r\ncombination = [int(x) for x in input()]\r\nturns = 0\r\n\r\nfor i in range(disknum):\r\n backwards = 0\r\n forwards = 0\r\n currlockdig = currlock[i]\r\n while currlockdig != combination[i]:\r\n currlockdig -= 1\r\n if currlockdig == -1:\r\n currlockdig = 9\r\n backwards += 1\r\n currlockdig = currlock[i]\r\n while currlockdig != combination[i]:\r\n currlockdig += 1\r\n currlockdig = currlockdig % 10\r\n forwards += 1\r\n turns += min(backwards, forwards)\r\nprint(turns)\r\n", "l=int(input())\r\na=input()\r\nb=input()\r\ntemp=0\r\nx=\"12345\"\r\ny=\"67890\"\r\nfor i in range(0,l):\r\n m=int(a[i])\r\n n=int(b[i])\r\n u=abs(m-n)\r\n v=(9-m)+n+1\r\n z=(9-n)+m+1\r\n temp+=min(u,v,z)\r\nprint(temp) ", "n = int(input())\r\na = input()\r\nb = input()\r\n\r\nalphabet = \"0123456789\"\r\nres = 0\r\n\r\nfor i in range(n):\r\n a1 = alphabet.find(a[i - 1])\r\n b1 = alphabet.find(b[i - 1])\r\n x = abs(a1 - b1)\r\n y = 10 - x\r\n res += min(x, y)\r\n\r\nprint(res)\r\n", "import sys\n\nn = int(input())\na = input()\nb = input()\nans = 0\nfor i in range(n):\n ans += min(abs(int(a[i]) - int(b[i])), 10 - abs(int(a[i]) - int(b[i])))\nprint(ans)\n\n", "n,s1,s2 = int(input()),input(),input()\r\nsum1 = 0\r\nfor i in range(n):\r\n sum1 += min(abs(int(s2[i])-int(s1[i])),10-abs(int(s2[i])-int(s1[i])))\r\nprint(sum1)\r\n", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nmoves=0\r\nfor i in range(len(s1)):\r\n\tmoves+=min(abs(int(s1[i])-int(s2[i])),10-abs(int(s1[i])-int(s2[i])))\r\nprint(moves)", "n=int(input())\ns1=input()\ns2=input()\ncnt=0\nfor i in range (n):\n a=int(s1[i])\n b=int(s2[i])\n if a==b: continue\n elif a>b:\n x=(a-b)\n y=(9-a)+b+1\n if x>=y:\n cnt+=y\n else:\n cnt+=x\n elif a<b:\n x=(b-a)\n y = (9 - b) + a+1\n if x >= y:\n cnt += y\n else:\n cnt += x\nprint(cnt)\n\n \t\t\t\t \t\t \t\t\t \t\t\t\t \t \t \t\t", "n = int(input())\r\nstate = list(map(int , input()))\r\ncode = list(map(int , input()))\r\nmoves = 0\r\nfor i in range(n):\r\n if state[i] == 0:\r\n state[i] = 10\r\n if code[i] == 0:\r\n code[i] = 10\r\nfor i in range(n):\r\n if abs(state[i] - code[i]) <= 5:\r\n moves += abs(state[i] - code[i])\r\n #print(1 , moves)\r\n else:\r\n if state[i] < 5:\r\n moves += state[i] + (10 - code[i])\r\n #print(2 , moves)\r\n elif state[i] > 5:\r\n moves += 10 - state[i] + code[i]\r\n #print(3 , moves)\r\nprint(moves)", "n=int(input())\r\na=input()\r\nb=input()\r\ns=0\r\nfor i in range(n):\r\n d=abs(int(a[i])-int(b[i]))\r\n s+=min(d,10-d)\r\nprint(s)", "n=int(input())\r\na=list(map(int,input()))\r\nb=list(map(int,input()))\r\ncount=0\r\nfor i in range(n):\r\n\tcount+=min(abs(a[i]-b[i]),10-max(a[i],b[i])+min(a[i],b[i]))\r\nprint(count)\t\r\n", "n = int(input())\r\nstr1 = input()\r\nstr2 = input()\r\nans = sum([5 - abs(abs(int(str1[i]) - int(str2[i])) - 5) for i in range(0, n)])\r\nprint(ans)", "n=int(input())\r\na=input()\r\nb=input()\r\nc=0\r\nfor i in range(n):\r\n if abs(int(a[i])-int(b[i]))<=5:\r\n c+=abs(int(a[i])-int(b[i]))\r\n else:\r\n c+=10-abs(int(a[i])-int(b[i]))\r\nprint(c)", "n = int(input())\r\nstr1 = input()\r\nstr2 = input()\r\nc=0\r\nfor i in range(n):\r\n a = int(str1[i])\r\n b = int(str2[i])\r\n \r\n c+=min(abs(a-b),10-max(a,b)+min(a,b))\r\nprint(c)\r\n \r\n \r\n ", "def main():\n\n n = int(input())\n s1 = list(input())\n s2 = list(input())\n moves = 0\n\n for i in range(n):\n a = int(s1[i])\n b = int(s2[i])\n # 10 - abs() goes the other way around\n # and min checks to see which way is shorter\n mini = min(abs(a-b), 10-abs(a-b))\n moves += mini\n\n print(moves)\n\n \nif __name__ == \"__main__\":\n main()\n\n\n\n", "n = int(input())\r\nx = str(input())\r\ny = str(input())\r\ncount = 0\r\nfor i in range(n):\r\n a = abs(int(x[i]) - int(y[i]))\r\n if a <= 5:\r\n count += a\r\n else:\r\n count += 10 - a\r\nprint(count)", "import math\r\nn = int(input())\r\nn1 = input()\r\nn2 = input()\r\nc=0\r\nfor i in range(n):\r\n x= math.fabs(int(n1[i]) -int(n2[i]))\r\n y= 10-x\r\n c+= min(x,y)\r\n\r\nprint(int(c))\r\n\r\n", "n=int(input())\r\na=input()\r\nb=input()\r\ncount=0\r\nfor i in range(n):\r\n if abs(int(a[i])-int(b[i]))<=5:\r\n count+=abs(int(a[i])-int(b[i]))\r\n else:\r\n count+= (10 - abs(int(a[i])-int(b[i])))\r\nprint(count)", "input()\r\nsteps = 0\r\nfor current, goal in zip(input(), input()):\r\n step = abs(int(current) - int(goal))\r\n if step > 5:\r\n step = 10 - step\r\n steps += step\r\n\r\nprint(steps)", "n=int(input())\r\ns=input()\r\nss=input()\r\ncount=0\r\nfor i in range(n):\r\n count+=min(max(int(s[i]),int(ss[i]))-min(int(s[i]),int(ss[i])),\r\n 10-max(int(s[i]),int(ss[i]))+min(int(s[i]),int(ss[i])))\r\nprint(count)\r\n", "n=int(input())\r\ninitial=input()\r\nfinal=input()\r\nx=0\r\nfor i in range(n):\r\n if abs(int(initial[i])-int(final[i]))>5:\r\n x=x+10-abs(int(initial[i])-int(final[i]))\r\n else: \r\n x=x+abs(int(initial[i])-int(final[i]))\r\n \r\nprint(x) ", "ans=0\r\na=int(input())\r\nb=input()\r\nc=input()\r\nfor i in range(a):\r\n if abs(int(b[i])-int(c[i]))>5:\r\n ans+=10-(abs(int(b[i])-int(c[i])))\r\n else:\r\n ans+=abs(int(b[i])-int(c[i]))\r\nprint(ans)", "input()\r\na,b = input(),input()\r\nprint(sum([min(10 - abs(int(a[i]) - int(b[i])), abs(int(a[i]) - int(b[i]))) for i in range(len(a))]))", "from math import *\r\nn=int(input())\r\ns1=input()\r\ns2=input()\r\nres=0\r\nfor i in range(len(s2)):\r\n res+=min(int(fabs(int(s1[i])-int(s2[i]))),10-int(fabs(int(s1[i])-int(s2[i]))))\r\nprint(res)", "disks_on_the_combination_lock = int(input())\noriginal_state = input()\nkey = input()\n\nmoves = 0\n\nfor i in range(disks_on_the_combination_lock):\n if abs(int(original_state[i]) - int(key[i])) <= 5:\n moves += abs(int(original_state[i]) - int(key[i]))\n else:\n moves += 9 - abs(int(original_state[i]) - int(key[i])) + 1\n\nprint(moves)", "i= lambda: map(ord, input()); i()\r\nprint( sum ( min( abs(a-b), 10-abs(a-b) ) for a,b in zip(i(),i()) ))", "n = int(input())\r\na= input()\r\nb = input()\r\ns=0\r\nfor i in range(len(a)):\r\n if abs(int(a[i])-int(b[i])) >5:\r\n s+= 10-abs(int(a[i])-int(b[i]))\r\n elif abs(int(a[i])-int(b[i]))<=5:\r\n s+= abs(int(a[i])-int(b[i]))\r\nprint(s)\r\n", "ans=0\r\ninput()\r\nfor i,j in zip(map(int,list(input())),map(int,list(input()))):ans+=min(abs(i-j),10-abs(i-j))\r\nprint(ans)", "\n\n\nimport os, sys\n\nii = lambda : int(input())\nsi = lambda : input()\nli = lambda : list(map(int, input().split()))\nlsi = lambda : list(map(str, input().split()))\n\ntry: sys.stdin = open(r\"C:\\Users\\LIB-606\\Desktop\\input.txt\",'r')\nexcept : pass\n\n\nimport math\n\n\nlength = ii()\na = si()\nb = si()\nc = 0\nfor i,j in zip(a,b):\n\n first = abs(int(i)-int(j))\n second = abs(int(f'1{i}')-int(j))\n third = abs(int(i)-int(f'1{j}'))\n\n #print(first,second)\n\n m = min([first,second, third])\n c+=m\n #print(c)\nprint(c)\n\n\n\n\n\n\n'''\nimport math\n\nx = ii()\n#sq = math.sqrt(x)\nc = 0\nfor i in range(1,(x//2)+1):\n ans = divmod(x,i)\n if ans[0]==ans[1]:\n c+=1\n print(ans)\nprint(c)\n\n'''\n\n\t \t \t \t \t\t \t\t \t\t\t\t \t\t\t \t", "h=int(input())\r\na = input()\r\nb = input()\r\ni=0\r\nr = 0\r\nwhile i<h:\r\n x = abs(int(a[i])-int(b[i]))\r\n y = 10 - max(int(a[i]),int(b[i])) + min(int(a[i]),int(b[i]))\r\n\r\n r += min(x,y)\r\n i += 1\r\nprint(r)\r\n", "n=int(input())\r\ns1,s2=input(),input()\r\nwk=0\r\nfor i in range(n):\r\n dx=abs(int(s1[i])-int(s2[i]))\r\n wk+=min(dx,10-dx)\r\nprint(wk)", "n=int(input())\r\narr1=list(map(int,[i for i in input()]))\r\narr2=list(map(int,[i for i in input()]))\r\nans=0\r\nfor i in range(len(arr1)):\r\n ans+=min(abs(arr1[i]-arr2[i]),10-abs(arr1[i]-arr2[i]))\r\nprint(ans)\r\n", "import sys\r\ninp = sys.stdin.read().strip().split('\\n')[1:]\r\ns = 0\r\nfor i in zip(*inp):\r\n x,y = map(int, i)\r\n dt = abs(x-y)\r\n s += dt if dt < 6 else 10 - dt\r\nprint(s)", "n = int(input())\r\na = input()\r\nb = input()\r\na = [int(x) for x in str(a)]\r\nb = [int(x) for x in str(b)]\r\n\r\nans = 0\r\nfor i in range(len(a)):\r\n t = min(abs(a[i] - b[i]), 10 - abs((a[i] - b[i])))\r\n ans += t\r\n\r\nprint(ans)", "n = int(input())\n\nfirst = [int(s) for s in input()]\nsecond = [int(s) for s in input()]\n\nans = 0\n\n\nfor i in range(n):\n ans += min(abs(first[i] - second[i]), first[i] + 10 - second[i], second[i] + 10 - first[i])\n # print(ans)\nprint(ans)\n", "# Combination Lock\ndef combination(cur, pas):\n ans = 0\n for c, p in zip(cur, pas):\n big = max(int(c), int(p))\n smol = min(int(c), int(p))\n val1 = big - smol\n val2 = (smol + 10) - big\n ans += min(val1, val2)\n return ans\n\n \n\n\n\nn = int(input())\ncur = list(input())\npas = list(input())\nprint(combination(cur, pas))", "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\torigin = input()\r\n\t\tcomb = input()\r\n\t\tresult = 0\r\n\r\n\t\tfor x, y in zip(origin, comb):\r\n\t\t\tx = int(x)\r\n\t\t\ty = int(y)\r\n\t\t\tresult += min(abs(x - y), (x + 10 - y), (y + 10 - x))\r\n\t\t\t\r\n\t\tprint(result)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tsol = Solution()\r\n\tsol.solve()\r\n", "# A. Combination Lock\r\nn=int(input())\r\ns=input()\r\no=input()\r\nc=0\r\nfor i in range(n):\r\n f=abs(ord(o[i])-ord(s[i]))\r\n b=10-f\r\n c+=min(f,b)\r\n# print(f,b,c)\r\n\r\nprint(c)\r\n", "n = int(input())\r\na = input()\r\nb = input()\r\nanswer = 0\r\nfor i in range(n):\r\n q = int(a[i])\r\n w = int(b[i])\r\n if abs(q - w) > 5:\r\n answer += 10 - abs(q - w)\r\n else:\r\n answer += abs(int(a[i]) - int(b[i]))\r\n\r\nprint(answer)\r\n", "n = int(input())\r\na = input()\r\nb = input()\r\nt = 0\r\nfor i in range(n):\r\n diff = abs(int(a[i]) - int(b[i]))\r\n t += min(diff, 10 - diff)\r\nprint(t)\r\n", "n = int(input())\r\nx = input()\r\ny = input()\r\ncnt = 0\r\nfor i in range(n):\r\n k = abs(int(x[i]) - int(y[i]))\r\n a = (10-k)\r\n cnt += min(k,a)\r\nprint(cnt)\r\n", "n = int(input())\noriginal_state = input()\ncombination = input()\n\nsteps = 0\nfor i in range(len(original_state)):\n n_steps = abs(int(original_state[i]) - int(combination[i]))\n steps += n_steps if n_steps < 5 else 10 - n_steps\n\nprint(steps)\n \t\t\t \t \t\t \t \t \t \t\t \t\t \t", "x=int(input())\r\ny=input()\r\nz=input()\r\nlst=[]\r\nlst1=[]\r\nsum=0\r\nsum1=0\r\nfor i in y:\r\n lst.append(int(i))\r\nfor j in z:\r\n lst1.append(int(j))\r\nfor k in range(len(lst)):\r\n if lst[k]>lst1[k]:\r\n s=lst[k]-lst1[k]\r\n s1=10-s\r\n sum=sum+min(s,s1)\r\n elif lst[k]<lst1[k]:\r\n s=lst1[k]-lst[k]\r\n s1=10-s\r\n sum1=sum1+min(s,s1)\r\nprint(sum+sum1)\r\n", "length = int(input())\r\ndefault = input()\r\ntarget = input()\r\nresult = 0\r\n\r\nfor i in range(length):\r\n result += min(abs(int(default[i])-int(target[i])), (10-abs(int(default[i])-int(target[i]))))\r\n\r\nprint(result)\r\n", "\"\"\"\r\n-- Algorithm --\r\n1) take n of disks\r\n2) take the first row and second row and store each in a list\r\n3) zip both into new list compresed of pairs\r\n4) iterate over each pair and compare increasing steps and decreasing steps\r\n5) return the min(inc_steps, dec_steps)\r\n\r\n\"\"\"\r\n\r\n\r\ndef increase_steps(start, end):\r\n inc_counter = 0\r\n while start != end:\r\n start += 1\r\n inc_counter += 1\r\n if start > 9:\r\n start = 0\r\n return inc_counter\r\n\r\n\r\ndef decrease_steps(start, end):\r\n dec_counter = 0\r\n while start != end:\r\n start -= 1\r\n dec_counter += 1\r\n if start < 0:\r\n start = 9\r\n return dec_counter\r\n\r\n\r\ndef increasing_or_decreasing(start, end):\r\n return min(increase_steps(start, end), decrease_steps(start, end))\r\n\r\n\r\nn = int(input())\r\nf_row = [int(x) for x in list(input())]\r\nsec_row = [int(x) for x in list(input())]\r\nzipped_pair = [x for x in zip(f_row, sec_row)]\r\n\r\ncounter = 0\r\nfor i in range(n):\r\n pair = zipped_pair[i]\r\n start = pair[0]\r\n end = pair[1]\r\n counter += increasing_or_decreasing(start, end)\r\nprint(counter)", "n = int(input()); a = input(); b = input();cnt = 0\r\nfor i,j in zip(b,a):\r\n p = int(i);q = int(j)\r\n cnt += min(abs(p-q),(9-max(p,q)+1+min(p,q)))\r\nprint(cnt)\r\n", "n = int(input())\r\nx = str(input())\r\ny = str(input())\r\nc=0\r\nfor i in range(n):\r\n a= int(x[i])\r\n b = int(y[i])\r\n if a > b:\r\n d = (10+b) - a\r\n e = abs(a-b)\r\n else:\r\n d = (10+a)-b\r\n e = abs(a-b)\r\n if d > e:\r\n c+=e\r\n else:\r\n c+=d\r\nprint(c) \r\n", "n=int(input())\r\ns1=input()\r\ns2=input()\r\ns=0\r\nfor i in range(n):\r\n k= abs(int(s1[i])-int(s2[i]))\r\n if k<=5:\r\n s=s+k\r\n else:\r\n s=s+(10-k)\r\nprint(s) ", "def solve():\r\n n = int(input())\r\n a = str(input())\r\n b = str(input())\r\n ans = int()\r\n for i in range(n):\r\n abs_value = abs(int(a[i])-int(b[i]))\r\n ans += min(10-abs_value,abs_value)\r\n\r\n print(ans)\r\n\r\nif __name__=='__main__':\r\n solve()\r\n", "n = int(input())\r\ni = input()\r\ni = [int(j) for j in i]\r\nc = input()\r\nc = [int(j) for j in c]\r\nans = 0\r\nfor k in range(n):\r\n ans += min(abs(c[k]-i[k]), 10-abs(i[k]-c[k]))\r\nprint(ans)", "n = int(input())\r\nl = []\r\nk = []\r\na = input()\r\nb = input()\r\nfor x in a:\r\n l.append(x)\r\nfor t in b:\r\n k.append(t)\r\ncount = 0\r\nfor i in range(n):\r\n count += min(10 - abs(int(l[i])-int(k[i])),abs(int(l[i]) - int(k[i])))\r\nprint(count)", "a = int(input())\r\nb = [int(i) for i in input()]\r\nc = [int(i) for i in input()]\r\nk = 0\r\nfor i in range(0, a):\r\n e, r = max(b[i], c[i]), min(b[i], c[i])\r\n f = 9 - e + r + 1\r\n if f < e - r and f > -1:\r\n k += f\r\n else:\r\n k += e - r\r\nprint(k)", "n=int(input())\r\nI=input()\r\nF=input()\r\nM=0\r\nfor i in range(n):\r\n if abs(int(I[i])-int(F[i]))<=5:\r\n M+=(abs(int(I[i])-int(F[i])))\r\n else:\r\n M+=(10-abs(int(I[i])-int(F[i])))\r\nprint(M)", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nc=0\r\nfor i in range(n):\r\n \r\n x,y=min(int(s1[i]),int(s2[i])),max(int(s1[i]),int(s2[i]))\r\n d1=abs(x-y)\r\n d2=abs(x-y+10)\r\n d3=abs(x-y-10)\r\n c+=min(d1,d2,d3)\r\nprint(c)\r\n \r\n", "import math\r\nn = int(input())\r\ns = input()\r\ncomb = input()\r\ncount = 0\r\nfor i in range(n):\r\n if abs(int(s[i])-int(comb[i])) <=5:\r\n count+= abs(int(s[i])-int(comb[i]))\r\n else:\r\n count+= 10-abs(int(s[i])-int(comb[i]))\r\nprint(count)\r\n", "n = int(input())\r\n\r\ninitState, targetState = input(), input()\r\n\r\nans = 0\r\n\r\nfor i in range(n):\r\n if abs(int(initState[i]) - int(targetState[i])) >= 5:\r\n ans += min(int(initState[i]), int(targetState[i])) + 10 - max(int(initState[i]), int(targetState[i]))\r\n else:\r\n ans += abs(int(initState[i]) - int(targetState[i]))\r\n\r\nprint(ans)\r\n", "n = int(input())\r\nnow = input()\r\nkey = input()\r\nk = 0\r\nfor i in range(n):\r\n\tx = abs(int(now[i]) - int(key[i]))\r\n\ty = int(now[i]) + 10 - int(key[i])\r\n\tz = int(key[i]) + 10 - int(now[i])\r\n\tk += min(x, y, z)\r\nprint(k)", "n = int(input())\r\na = input()\r\nb = input()\r\nc = 0\r\nfor i in range(n):\r\n x, y = max(int(a[i]), int(b[i])), min(int(a[i]), int(b[i]))\r\n c += min(x-y,10+y-x )\r\nprint(c)", "n = int(input())\r\na = str(input())\r\nb = str(input())\r\nkol = 0\r\nfor i in range(n):\r\n q = int(a[i])\r\n p = int(b[i])\r\n c = min(q, p)\r\n k = max(q, p)\r\n kol += min(abs(p - q), 10 + c - k)\r\nprint(kol)\r\n", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\ncnt = 0\r\nfor i in range(n):\r\n a = int(s1[i])\r\n b = int(s2[i])\r\n if a > b:\r\n mn = min(((9-a)+b+1), (a-b))\r\n cnt += mn\r\n elif a < b:\r\n mn = min(((9-b)+a+1), (b-a))\r\n cnt += mn\r\n elif a == b:\r\n cnt += 0\r\nprint(cnt)", "n = int(input())\r\nnums, len = list(str(\"0123456789\")), 10\r\nmin_rot = 0\r\noriginal = list(input())\r\nrequired = list(input())\r\n\r\nfor i in range(n):\r\n m, M = min(nums.index(original[i]), nums.index(required[i])), max(nums.index(original[i]), nums.index(required[i]))\r\n a, b = M - m, 10 - M + m\r\n min_rot += abs(min(a, b))\r\nprint(min_rot)\r\n ", "n = int(input())\r\noriginal_state = input()\r\ncombination = input()\r\n\r\ntotal_moves = 0\r\n\r\nfor i in range(n):\r\n digit1 = int(original_state[i])\r\n digit2 = int(combination[i])\r\n \r\n clockwise_distance = abs(digit2 - digit1)\r\n counter_clockwise_distance = 10 - clockwise_distance\r\n \r\n total_moves += min(clockwise_distance, counter_clockwise_distance)\r\n\r\nprint(total_moves)\r\n", "import sys\r\n\r\ndef I(): return int(sys.stdin.readline().strip())\r\ndef S(): return sys.stdin.readline().strip()\r\n \r\ndef main():\r\n n = I()\r\n initial = S()\r\n target = S()\r\n answer = 0\r\n for i in range(n):\r\n optionA = 0\r\n startNumber = int(initial[i])\r\n while( startNumber != int(target[i]) ):\r\n if startNumber == 0:\r\n startNumber = 9\r\n else:\r\n startNumber -= 1\r\n optionA += 1\r\n \r\n optionB = 0\r\n startNumber = int(initial[i])\r\n while( startNumber != int(target[i]) ):\r\n if startNumber == 9:\r\n startNumber = 0\r\n else:\r\n startNumber += 1\r\n optionB += 1\r\n \r\n answer += min(optionA, optionB)\r\n print(answer)\r\nif __name__ == \"__main__\":\r\n main()", "n = int(input())\r\na = input()\r\nb = input()\r\nresult = 0\r\nfor i in range(n):\r\n\tresult+=min(abs(int(a[i])-int(b[i])),abs(int(a[i])+10-int(b[i])),abs(int(b[i])+10-int(a[i])))\r\nprint(result)", "n =int(input())\r\na = list(map(int, input()))\r\nb = list(map(int, input()))\r\nans = 0\r\n\r\nfor i in range(n):\r\n ans += min(abs(a[i] - b[i]), min(abs(a[i] + 10 - b[i]) ,abs(10 - a[i] + b[i])))\r\n\r\nprint(ans)\r\n", "n=int(input())\r\nos=list(map(int,input()))\r\ncode=list(map(int,input()))\r\ntotal_spin=0\r\nfor x in range(n):\r\n\tc=abs(os[x]-code[x])\r\n\tif c>5:\r\n\t\ttotal_spin+=10-c\r\n\telse:\r\n\t\ttotal_spin+=c\r\nprint(total_spin)", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\nans = 0\r\nfor i in range(n):\r\n\t\r\n\tx, y = int(s1[i]), int(s2[i])\r\n\tans += min((min(x, y) + 10) - max(x, y), max(x, y) - min(x, y))\r\nprint(ans)", "n = int(input())\r\ncur = input()\r\nkey = input()\r\ncounter = 0\r\nfor i in range(int(len(cur))):\r\n temp = abs(abs(ord(key[i])) - abs(ord(cur[i])))\r\n counter += min(temp , 10-temp)\r\nprint(counter)", "n = int(input())\r\ns = input()\r\nx = input()\r\nd = ['0','1','2','3','4','5','6','7','8','9']\r\nc = 0\r\nfor i in range(n):\r\n if x[i] != s[i]:\r\n l = len(d[min(int(s[i]),int(x[i])):max(int(s[i]),int(x[i]))])\r\n r = len(d[:min(int(s[i]),int(x[i]))]+d[max(int(s[i]),int(x[i])):])\r\n c+=min(l,r)\r\nprint(c)", "n = int(input())\r\ns = input()\r\nt = input()\r\nstart = [int(d) for d in s]\r\ntarget = [int(d) for d in t]\r\nsuma = 0\r\nfor i in range(n):\r\n suma += min(abs(start[i] - target[i]), 10 - abs(start[i] - target[i]))\r\nprint(suma)\r\n", "t=int(input())\r\na=str(input())\r\nb=str(input())\r\ns=0\r\nfor k in range(t):\r\n s+=min(abs(int(a[k])-int(b[k])),min(int(a[k]),int(b[k]))-max(int(a[k]),int(b[k]))+10)\r\nprint(s)", "n = int(input())\r\nna = input()\r\na = []\r\nfor h in na:\r\n a.append(int(h))\r\nnb = input()\r\nb = []\r\nfor h in nb:\r\n b.append(int(h))\r\n\r\nres = 0\r\n\r\nfor i in range(0, len(a)):\r\n ab = abs(a[i] - b[i])\r\n if ab <= 5:\r\n res += ab\r\n\r\n else:\r\n if a[i] > b[i]:\r\n b[i] += 10\r\n ab = abs(a[i] - b[i])\r\n res += ab\r\n\r\n else:\r\n a[i] += 10\r\n ab = abs(a[i] - b[i])\r\n res += ab\r\n \r\n\r\nprint(res)\r\n\r\n", "def digit_from_char(c : str):\n return ord(c)-48\n\ndef min_mov(src : str, dst : str):\n movs = 0\n for i in range(len(src)):\n digit_src = digit_from_char(src[i])\n digit_dst = digit_from_char(dst[i])\n lesser = min(digit_dst,digit_src)\n greater = max(digit_dst,digit_src)\n movs += min(greater-lesser,10+lesser-greater)\n return movs\n\nn = int(input())\nsrc = input()\ndst = input()\nprint(min_mov(src,dst))", "n = int(input())\r\na = input()\r\nb = input()\r\nsum=0\r\nfor i in range(0,len(a)):\r\n sum += min(abs(int(b[i]) - int(a[i])), min((int(a[i])+ 9-int(b[i]))+1 , (int(b[i]) + 9 -int(a[i])) +1) )\r\nprint(sum)", "def main():\r\n n = int(input())\r\n s = list(map(int, list(input())))\r\n t = list(map(int, list(input())))\r\n\r\n sol = 0\r\n for i in range(n):\r\n sol += min(min(10 - s[i] + t[i], 10 - t[i] + s[i]), abs(s[i] - t[i]))\r\n print(sol)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n=int(input())\r\nsor=input()\r\nsop=input()\r\ncnt=0\r\nfor i in range(n):\r\n cnt+=min(10-abs(int(sor[i])-int(sop[i])),abs(int(sor[i])-int(sop[i])))\r\nprint(cnt)", "c=int(input())\r\na=input()\r\nb=input()\r\ni=0\r\nans=0\r\nwhile i<c:\r\n x=int(a[i])\r\n y=int(b[i])\r\n if x<=y:\r\n h=y-x\r\n g=10-y\r\n g+=x\r\n ans+=min(h,g)\r\n else:\r\n h=x-y\r\n g=10-x\r\n g+=y\r\n ans+=min(g,h)\r\n i+=1\r\nprint(ans)\r\n\r\n\r\n", "n=int(input())\r\no=input()\r\ns=input()\r\nsum=0\r\nfor i in range(n):\r\n a=int(s[i])\r\n b=int(o[i])\r\n c=abs(a-b) \r\n if(c>5):\r\n c=abs(10-c)\r\n sum+=c\r\n else:\r\n sum+=c\r\nprint(sum)", "n = int(input())\norig = input()\ndesired = input()\nmoves = 0\n\nfor i in range(n):\n diff_forward = abs(int(desired[i]) - int(orig[i]))\n diff_backward = 10 - diff_forward\n moves += min(diff_forward, diff_backward)\nprint(moves)\n \t\t\t \t\t \t \t\t\t\t\t \t\t\t\t \t \t", "n = int(input())\r\ns1 = int(input())\r\ns2 = int(input())\r\nresult = 0\r\n# i = 0\r\nwhile (s1 > 0 or s2 > 0):\r\n num1 = s1 % 10\r\n num2 = s2 % 10\r\n # print(\"ITER\", num1, num2, abs(num2 - num1), abs(9 + num2 - num1), abs(num1 - num2) , result)\r\n # result += min(abs(num2 - num1), abs(9 + num2 - num1), abs(num1 - num2))\r\n # print(i, \"ITER\", num1, num2, abs(num2 - num1), abs(10 + min(num1, num2) - max(num2, num1)), min(abs(num2 - num1), abs(10 + min(num1, num2) - max(num2, num1))))\r\n result += min(abs(num2 - num1), abs(10 + min(num1, num2) - max(num2, num1)))\r\n s1 //= 10\r\n s2 //= 10\r\n # i += 1\r\nprint(result)", "n = int(input())\r\nx = input()\r\ny = input()\r\nans = 0\r\nfor i in range(n):\r\n a, b = int(x[i]), int(y[i])\r\n diff = min(abs(a-b), (10-max(b,a)+min(a, b)))\r\n ans += diff\r\nprint(ans)", "def mynus(a, b):\r\n return abs(a-b)\r\n\r\ninput()\r\ncounter=0\r\nfor i in map(sorted, zip(map(int, input()), map(int, input()))):\r\n t=mynus(*i)\r\n counter+=i[0]+10-i[1] if t>=5 else t\r\nprint(counter)", "n=int(input())\r\na=input()\r\nb=input()\r\nres=0\r\nfor i in range(n):\r\n res+=min(10-abs(int(a[i])-int(b[i])),abs(int(a[i])-int(b[i])))\r\nprint(res)", "\r\n#for _ in range(int(input())):\r\nn=int(input())\r\ns,t=list(map(int,input())),list(map(int,input()))\r\ncnt=0\r\nfor i in range(n):\r\n a,b=min(s[i],t[i]),max(s[i],t[i])\r\n cnt+=min(10+a-b,b-a)\r\nprint(cnt)", "def min_moves_to_open_lock(n, original, combination):\r\n total_moves = 0\r\n for i in range(n):\r\n d1 = int(original[i])\r\n d2 = int(combination[i])\r\n moves = min(abs(d1 - d2), 10 - abs(d1 - d2))\r\n total_moves += moves\r\n return total_moves\r\n\r\n# Read input\r\nn = int(input())\r\noriginal = input().strip()\r\ncombination = input().strip()\r\n\r\n# Calculate and print the minimum number of moves\r\nresult = min_moves_to_open_lock(n, original, combination)\r\nprint(result)\r\n", "steps = 0\r\nn = int(input())\r\nOriginalState = input()\r\nCombination = input()\r\n\r\nfor i in range(0, n):\r\n if OriginalState[i] == '9' and Combination[i] <= '3':\r\n steps = steps + 1 + int(Combination[i])\r\n elif Combination[i] == '9' and OriginalState[i] <= '3':\r\n steps = steps + 1 + int(OriginalState[i])\r\n elif OriginalState[i] == '8' and Combination[i] <= '2':\r\n steps = steps + 2 + int(Combination[i])\r\n elif Combination[i] == '8' and OriginalState[i] <= '2':\r\n steps = steps + 2 + int(OriginalState[i])\r\n elif OriginalState[i] == '7' and Combination[i] <= '1':\r\n steps = steps + 3 + int(Combination[i])\r\n elif Combination[i] == '7' and OriginalState[i] <= '1':\r\n steps = steps + 3 + int(OriginalState[i])\r\n elif Combination[i] == '6' and OriginalState[i] == '0':\r\n steps = steps + 4\r\n elif OriginalState[i] == '6' and Combination[i] == '0':\r\n steps = steps + 4\r\n else:\r\n steps += abs(int(OriginalState[i]) - int(Combination[i]))\r\n\r\nprint(steps)\r\n", "n = int (input ())\r\nkomb = input ()\r\nkey = input ()\r\nnumb = '1234567890123456789'\r\n\r\notv = []\r\n\r\nfor i in range (n):\r\n if komb[i] == key[i]:\r\n otv.append (0)\r\n else:\r\n x = abs (numb.find (komb[i]) - numb.find (key[i]))\r\n y = abs (numb.find (komb[i]) - numb.rfind (key[i]))\r\n z = abs (numb.rfind (komb[i]) - numb.find (key[i]))\r\n otv.append (min (x,y,z))\r\n\r\nprint (sum (otv))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "t = int(input())\r\nx = [int(i) for i in input()]\r\ny = [int(i) for i in input()]\r\narr = []\r\nfor i in range(t):\r\n dis = min(abs(x[i]-y[i]), 10-abs(x[i]-y[i]))\r\n arr.append(dis)\r\nprint(sum(arr))", "n = int(input())\r\na = [int(x) for x in input()]\r\nb = [int(x) for x in input()]\r\ncount=0\r\nfor i in range(n):\r\n if a[i]>b[i]:\r\n count+=min(a[i]-b[i],b[i]+10-a[i])\r\n else:\r\n count+=min(b[i]-a[i],a[i]+10-b[i])\r\nprint(count)", "# Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. \r\n# Each time he wants to put there the treasures that he's earned fair and square, he has to \r\n# open the lock.\r\n\r\n# The combination lock is represented by n rotating disks with digits from 0 to 9 written on them. \r\n# Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret \r\n# combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?\r\n\r\n# Input\r\n# The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of disks on the combination lock.\r\n\r\n# The second line contains a string of n digits — the original state of the disks.\r\n\r\n# The third line contains a string of n digits — Scrooge McDuck's combination that opens the lock.\r\n\r\n# Output\r\n# Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.\r\n\r\n\r\nn = int(input())\r\navailable = input()\r\nlock = input()\r\nres = 0\r\n\r\n\r\nfor a in range(n):\r\n res = res+min(abs(int(available[a])-int(lock[a])),abs((min(int(available[a]),int(lock[a]))+10-max(int(available[a]),int(lock[a])))))\r\n\r\nprint(res)", "def donkey():\r\n\tres = 0\r\n\tn = int(input())\r\n\ts = input()\r\n\tsb = input()\r\n\tfor i in range(0,n):\r\n\t\tif s[i] != sb[i]:\r\n\t\t\ta,b = int(s[i]),int(sb[i])\r\n\t\t\tres+= min(abs(a-b),b+10-a,a+10-b)\r\n\tprint(res)\r\n\r\ndef main():\r\n\tt = 1\r\n#\tt = int(input())\r\n\twhile t:\r\n\t\tdonkey()\r\n\t\tt-=1\r\nmain()", "n = int(input())\r\nx = input()\r\ny = input()\r\na = list(x)\r\nb = list(y)\r\n\r\nl = []\r\nfor i in a:\r\n\tl.append(int(i))\r\n\r\nm = []\r\nfor i in b:\r\n\tm.append(int(i))\r\n\r\ntotal = 0\r\nfor i in range(n):\r\n\td = l[i] - m[i]\r\n\tif d >= 6:\r\n\t\ttotal += (10+m[i]) - l[i]\r\n\telif d <= -6:\r\n\t\ttotal += (10+l[i]) - m[i]\r\n\telif l[i] > m[i]:\r\n\t\ttotal += l[i] - m[i]\r\n\telse:\r\n\t\ttotal += m[i] - l[i]\r\n\r\nprint(total)", "n = int(input())\r\noriginal = input()\r\ntarget = input()\r\nmoves = 0\r\nfor i in range(n):\r\n\tdis = abs(int(original[i])-int(target[i]))\r\n\tmoves += min(dis,10-dis)\r\nprint(moves)", "#Combination_Lock\r\nn=int(input())\r\na=input()\r\nb=input()\r\nc=0\r\nfor i in range(n):\r\n k=int(a[i])-int(b[i])\r\n if(k<0):\r\n k=-k\r\n if(k>5):\r\n k=10-k\r\n c+=k \r\nprint(c) ", "n = input()\r\norg = input()\r\ncomb = input()\r\n\r\nmoves = 0\r\nx = 0\r\nfor i in org:\r\n diff1 = 10 - abs(int(int(i) - int(comb[x])))\r\n diff2 = abs(int(int(comb[x]) - int(i)))\r\n if diff1 > diff2:\r\n moves += diff2\r\n else:\r\n moves += diff1\r\n\r\n\r\n x += 1\r\n\r\nprint(moves)\r\n", "n = int(input())\r\na, b = [int(i) for i in input()], [int(i) for i in input()]\r\nans = 0\r\nfor i in range(n):\r\n\tans += min(abs(a[i] - b[i]), 9 - max(a[i], b[i]) + 1 + min(a[i], b[i]))\r\nprint(ans)", "t=int(input())\r\ns1=input()\r\ns2=input()\r\nans=0\r\nfor i in range(0,t):\r\n if int(s1[i])<int(s2[i]):\r\n if abs(int(s1[i])-int(s2[i]))>5:\r\n ans+=int(s1[i])+(10-int(s2[i]))\r\n else:\r\n ans+=abs(int(s1[i])-int(s2[i]))\r\n elif int(s1[i])>int(s2[i]):\r\n if abs(int(s2[i])-int(s1[i]))>5:\r\n ans+=int(s2[i])+(10-int(s1[i]))\r\n else:\r\n ans+=abs(int(s1[i])-int(s2[i]))\r\n else:\r\n ans+=0\r\n \r\nprint(ans)", "i=lambda:map(ord,input());i();print(sum(min(abs(a-b),10-abs(b-a))for a,b in zip(i(),i())))", "n = int(input())\r\nstart = input()\r\ntarget = input()\r\n\r\nmvs = 0\r\nfor i in range(n):\r\n temp = abs(int(start[i]) - int(target[i]))\r\n mvs += min(temp, 10-temp)\r\nprint(mvs)", "# LUOGU_RID: 101581706\nn, s, t = input(), input(), input()\r\nans = 0\r\nfor x, y in zip(s, t):\r\n x, y = map(int, (x, y))\r\n ans += min(abs(y - x), abs(10 + y - x), abs(10 - y + x))\r\nprint(ans)", "n=int(input())\r\ns1=list(map(int,input()))\r\ns2=list(map(int,input()))\r\nspin=0\r\nfor x in range(n):\r\n\tc=abs(s1[x]-s2[x])\r\n\tif c>5:\r\n\t\tspin+=10-c\r\n\telse:\r\n\t\tspin+=c\r\nprint(spin)", "n = int(input())\r\na = input()\r\nb = input()\r\na = list(a)\r\nb = list(b)\r\na= [int(i) for i in a]\r\nb= [int(i) for i in b]\r\nans = 0\r\nfor i in range(n):\r\n if abs(a[i]-b[i] )>5:\r\n ans +=10-abs(a[i]-b[i])\r\n else:\r\n ans+= abs(a[i]-b[i])\r\nprint(ans) ", "'''s=input().split()\r\nn=int(s[0])\r\nm=int(s[1])\r\nst=0\r\nwhile n>0:\r\n st+=1\r\n if st%m==0:\r\n n+=1\r\n n-=1\r\nprint(st)'''\r\nn=int(input())\r\nv=input()\r\nx=input()\r\na=0\r\nfor i in range(n):\r\n if abs(int(x[i])-int(v[i]))<10-abs(int(x[i])-int(v[i])):\r\n a+=abs(int(x[i])-int(v[i]))\r\n elif abs(int(x[i])-int(v[i]))==10-abs(int(x[i])-int(v[i])):\r\n a+=abs(int(x[i])-int(v[i]))\r\n else:\r\n a+=10-abs(int(x[i])-int(v[i]))\r\nprint(a)\r\n", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nsum=0\r\nfor i in range(0,n,1):\r\n k1=ord(s1[i])-48\r\n k2=ord(s2[i])-48\r\n # print(str(k1)+\" \"+str(k2))\r\n if k1<k2:\r\n if k2-k1>(k1+(9-k2)):\r\n sum=sum+(k1+(9-k2))+1\r\n else:\r\n sum=sum+k2-k1\r\n # print(sum)\r\n else:\r\n if k1-k2>(k2+(9-k1)):\r\n sum=sum+(k2+(9-k1))+1\r\n else:\r\n sum=sum+k1-k2\r\n # print(sum)\r\nprint(sum)", "x = int(input())\nsituation = list(input())\nkey = list(input())\ncount = 0\nfor i in range(0, len(situation)): \n situation[i] = int(situation[i])\nfor i in range(0, len(key)): \n key[i] = int(key[i]) \nif len(key) != x:\n print(\"Error\")\nelse:\n for s, k in zip(situation, key):\n if abs(s - k) > 5:\n if s < k:\n count += (s + 10) - k\n elif k < s:\n count += (k + 10) - s\n else:\n count += abs(s - k)\nprint(count) \n", "n,a,b = int(input()),input(),input()\r\nans = 0\r\nfor i in range(n):\r\n z = abs(int(a[i])-int(b[i]))\r\n ans += min(z,10-z)\r\nprint(ans)", "import math\r\nn=int(input())\r\ns=input()\r\ns1=input()\r\nm=0\r\nfor i in range(n):\r\n if math.fabs(int(s[i])-int(s1[i]))>5:\r\n m=m+5-(math.fabs(int(s[i])-int(s1[i]))-5)\r\n else:\r\n m=m+math.fabs(int(s[i])-int(s1[i]))\r\nprint(int(m))", "# Happy_water\r\ndef main():\r\n n = int(input())\r\n s, t = input(), input()\r\n ans = 0\r\n for i in range(n):\r\n ans += min(abs(int(s[i]) - int(t[i])), 10 - abs(int(s[i]) - int(t[i])))\r\n print(ans)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "N = int(input())\r\nStr = input()\r\nStr1 = input()\r\nCount = 0\r\nfor i in range(N):\r\n N1 = int(Str[i])\r\n N2 = int(Str1[i])\r\n \r\n Minn = min(N1,N2)\r\n Maxx = max(N1,N2)\r\n \r\n Val = Maxx - Minn\r\n Val1= ( 9 - Maxx) + ( Minn - 0)\r\n \r\n if Val <= Val1:\r\n Count = Count + Val \r\n else:\r\n Count = Count + Val1 + 1\r\nprint(Count)", "n=int(input())\na1=input()\na2=input()\nans = 0\nfor i in range(len(a1)):\n a,b=int(a1[i]), int(a2[i])\n ans += min(abs(a-b), 10-abs(a-b))\nprint (ans)\n \n", "def route(source, target, update):\r\n count = 0\r\n while source != target:\r\n source += update\r\n if source == -1:\r\n source = 9\r\n if source == 10:\r\n source = 0\r\n count += 1\r\n return count\r\n\r\nn = int(input())\r\nsource, target = str(input()), str(input())\r\ncount = 0\r\nfor j in range(n):\r\n s, t = ord(source[j]) - 48, ord(target[j]) - 48\r\n r1, r2 = route(s, t, 1), route(s, t, -1)\r\n count += min(r1, r2)\r\nprint(count)\r\n", "n, old, new, total = int(input()), input(), input(), 0\r\nfor i in range(n):\r\n total += min(abs(int(old[i]) - int(new[i])), 10 - abs(int(old[i]) - int(new[i])))\r\nprint(total)", "input()\r\na=input()\r\nb=input()\r\nc=0\r\nfor i in range(len(a)):\r\n x=int(a[i])\r\n y=int(b[i])\r\n if abs(x-y) < (10-abs(x-y)):\r\n c+=abs(x-y)\r\n else:\r\n c+=(10-abs(x-y))\r\nprint(c)", "n=int(input())\r\nx=input()\r\ny=input()\r\np='01234567890123456789'\r\ncount=0\r\nfor i in range(n):\r\n if int(x[i])<int(y[i]):\r\n if p.rfind(x[i])-p.find(y[i])<p.find(y[i])-p.find(x[i]):\r\n count+=p.rfind(x[i])-p.find(y[i])\r\n else:\r\n count+=p.find(y[i])-p.find(x[i])\r\n else:\r\n if p.find(x[i])-p.find(y[i])<p.rfind(y[i])-p.find(x[i]):\r\n count+=p.find(x[i])-p.find(y[i])\r\n else:\r\n count+=p.rfind(y[i])-p.find(x[i])\r\nprint(count)\r\n", "n = int(input())\r\nfirst, second = input(), input()\r\ncnt = 0\r\n\r\nfor i in range(n):\r\n a, b = sorted([int(first[i]), int(second[i])])\r\n cnt += min(b - a, 10 + a - b)\r\n\r\nprint(cnt)\r\n", "n=int(input())\r\ncurrstate=str(input())\r\nfinalstate=str(input())\r\nans=[0,1,2,3,4,5,6,7,8,9]\r\ncount=0\r\nfor i in range(n):\r\n count+=min(abs(int(currstate[i])-int(finalstate[i])),9-(abs(int(currstate[i])-int(finalstate[i])))+1)\r\nprint(count)", "t=int(input())\r\nos=input()\r\nds=input()\r\ncost=0\r\nfor i in range(len(os)):\r\n o=int(os[i])\r\n d=int(ds[i])\r\n if(o>d):\r\n c1=o-d\r\n c2=(9-o)+(d-0)+1\r\n cost+=min(c1,c2)\r\n else:\r\n c1=d-o\r\n c2=(9-d)+(o-0)+1\r\n cost+=min(c1,c2)\r\nprint(cost)", "n = int(input())\r\nds = (abs(ord(v1) - ord(v2)) for v1, v2 in zip(input(), input()))\r\nprint(sum(map(lambda v: min(v, 10 - v), ds)))", "'''/ Problem: A. Combination Lock\r\n// Contest: Codeforces - Codeforces Round #301 (Div. 2)\r\n// URL: https://codeforces.com/problemset/problem/540/A\r\n// Memory Limit: 256 MB\r\n// Time Limit: 2000 ms\r\n// \r\n// Powered by CP Editor (https://cpeditor.org)'''\r\nn=int(input())\r\na=input()\r\nb=input()\r\nc=0\r\nfor i in range(n):\r\n\tc=c+min(abs(int(a[i])-int(b[i])),10-abs(int(a[i])-int(b[i])))\r\nprint(c)\r\n\r\n", "n=int(input())\r\nm=input()\r\nl=input()\r\ns=0\r\nfor i in range(n):\r\n b=int(m[i])\r\n c=int(l[i])\r\n a=abs(b-c)\r\n \r\n if a>5:\r\n a=10-a\r\n s=s+a \r\nprint(s) ", "n = int(input())\r\n\r\na = input()\r\nb = input()\r\na = list(a)\r\nfor i in range(n):\r\n a[i] = int(a[i])\r\nb = list(b)\r\n\r\nfor i in range(n):\r\n b[i] = int(b[i])\r\n\r\n\r\nans = 0\r\n\r\nfor i in range(n):\r\n if abs(a[i] - b[i]) > 5:\r\n ans += 10 - abs(a[i] - b[i])\r\n else:\r\n ans += abs(a[i] - b[i])\r\n\r\nprint(ans)", "digit = int(input())\r\noriginal = input()\r\npassword = input()\r\ncount = 0\r\ntotal = 0\r\nfor i in range(digit):\r\n count = abs(int(original[i]) - int(password[i]))\r\n if count > 5:\r\n count = 10 - count\r\n total += count\r\nprint(total)\r\n", "n=int(input(\"\"))\r\ns1=str(input(\"\"))\r\ns2=str(input(\"\"))\r\nb=0\r\nfor i in range (n):\r\n a=abs(int(s1[i])-int(s2[i]))\r\n if a>5: a=10-a\r\n b=b+a\r\nprint(b)\r\nexit()\r\n", "a=int(input())\r\nb=str(input())\r\nc=str(input())\r\ncount=0\r\nfor i in range(a):\r\n d=abs(int(b[i])-int(c[i]))\r\n e=abs(int(b[i])+(9-int(c[i]))+1)\r\n f=abs(int(c[i])+(9-int(b[i]))+1)\r\n\r\n count+=(min(d,e,f))\r\nprint(count)\r\n\r\n", "n = int(input())\r\noriginal_state = input()\r\ndestination_state = input()\r\nresult = 0\r\nfor i in range(n):\r\n number_of_step = (abs(int(original_state[i]) - int(destination_state[i])))\r\n result += min(number_of_step, (10 - number_of_step))\r\n\r\nprint(result)", "n = int(input())\na = input()\nb = input()\nresult = 0\nfor i in range(n):\n c = int(a[i])\n f = int(b[i])\n if(f<c):\n one = abs(c-f)\n two = (10-c)+f\n result+=min(one,two)\n else:\n one = abs(f-c)\n two = c+(10-f)\n result+=min(one,two)\nprint(result)", "length = int(input())\nnow = (input())\ngoal = (input())\nmoves = 0\nfor t in range(length):\n if abs(int(now[t]) - int(goal[t])) < 5:\n moves += abs(int(now[t]) - int(goal[t]))\n else:\n moves += 10 - abs(int(now[t]) - int(goal[t]))\nprint(moves)\n", "n=int(input())\r\na=input()\r\nb=input()\r\nans=0\r\nfor i in range(n):\r\n x=int(a[i])\r\n y=int(b[i])\r\n if abs(x-y)>(10-abs(x-y)):\r\n count=10-abs(x-y)\r\n ans+=count\r\n else:\r\n count=abs(x-y)\r\n ans+=count\r\nprint(ans)", "n=int(input())\r\ns1=input()\r\ns2=input()\r\ns=0\r\nfor i in range(n):\r\n r=max(int(s1[i]),int(s2[i]))-min(int(s1[i]),int(s2[i]))\r\n if r>5:\r\n r=10-r\r\n s+=r\r\nprint(s)", "num,b,c,z=int(input()),input(),input(),0\r\nfor i in range(0,num):\r\n\tx,y=int(b[i]),int(c[i])\r\n\tz+=min(abs(x-y),(abs(min(x,y)+10-max(x,y))))\r\nprint(z)", "x = input()\r\nj = 0\r\nx1 = [int(i) for i in input()]\r\nx2 = [int(j) for j in input()]\r\nfor nums in range(len(x1)):\r\n if abs(x1[nums]-x2[nums]) >5:\r\n j+=(10-abs(x1[nums]-x2[nums]))\r\n else:\r\n j+=(abs(x1[nums]-x2[nums]))\r\nprint(j)\r\n", "from sys import stdin\r\ninput=lambda:stdin.readline().strip()\r\nn=int(input())\r\ns1=input()\r\ns2=input()\r\nsum1=0\r\nfor i in range(0,n):\r\n d=abs(int(s1[i])-int(s2[i]))\r\n if d>5:\r\n sum1+=10-d\r\n else:\r\n sum1+=d\r\nprint(sum1)\r\n", "n = int (input())\r\ns_a = str (input())\r\ns_b = str (input())\r\n \r\nt = []\r\nfor x, y in zip( s_a, s_b):\r\n if abs(int(x)-int(y))>5: \r\n t.append((10- (abs(int(x)-int(y)))))\r\n else: \r\n t.append((abs(int(x)-int(y))))\r\n \r\n \r\nprint (sum(t))\r\n ", "m = int(input())\r\na = input()\r\nb = input()\r\nsum = 0\r\nfor i in range(m):\r\n c = int(a[i])\r\n d = int(b[i])\r\n if c <= d:\r\n sum += min([abs(c - d), abs(10 + (c-d))])\r\n else:\r\n sum += min([abs(d - c), abs(10 + (d-c))])\r\nprint(sum)", "n=int(input())\r\na=list(map(int,input()))\r\nb=list(map(int,input()))\r\ns=0\r\nfor i in range(n):\r\n if a[i]>b[i]:\r\n if a[i]-b[i]>5:\r\n s+=((b[i]+10)-a[i])\r\n else:\r\n s+=a[i]-b[i]\r\n elif b[i]>a[i]:\r\n if b[i]-a[i]>5:\r\n s += ((a[i] + 10) - b[i])\r\n else:\r\n s += b[i] - a[i]\r\nprint(s)", "n=int(input())\r\narr=list(map(int,input()))\r\n#print(arr)\r\narr2=list(map(int,input()))\r\n#print(arr2)\r\nans=0\r\nfor i in range(n):\r\n d=abs(arr[i]-arr2[i])\r\n if d <5:\r\n ans+=d\r\n else:\r\n dM=max(arr[i],arr2[i])\r\n dm=min(arr[i],arr2[i])\r\n d2=(9-dM)+dm+1\r\n ans+=d2\r\nprint(ans)\r\n", "input()\r\na1 = input()\r\na2 = input()\r\ns = 0\r\n\r\nfor i1, i2 in zip(a1, a2):\r\n i1 = int(i1)\r\n i2 = int(i2)\r\n s += min(abs(i1 - i2), 10 - max(i1, i2) + min(i1, i2))\r\n\r\nprint(s)", "sm = 0\r\nlenth = int(input())\r\nr1 = input()\r\nr2 = input()\r\nfor i in range(lenth):\r\n if abs(int(r1[i]) - int(r2[i])) > 5:\r\n sm += 10 - abs(int(r1[i]) - int(r2[i]))\r\n else:\r\n sm += abs(int(r1[i]) - int(r2[i]))\r\nprint(sm)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Feb 2 21:05:53 2021\r\n\r\n@author: vukhe\r\n\"\"\"\r\n\r\nn = int(input())\r\norg = input()\r\ncode = input()\r\nmoves = 0\r\n\r\nfor i in range(n):\r\n diff = abs(int(org[i]) - int(code[i]))\r\n \r\n if diff > 5:\r\n moves += 10 - diff\r\n else:\r\n moves += diff\r\n \r\nprint(moves)\r\n ", "n=int(input())\r\ninit=input()\r\nfinal=input()\r\nans=0\r\nfor i in range(n):\r\n real=abs(int(final[i])-int(init[i]))\r\n if real<=5:\r\n ans+=real\r\n else:\r\n ans+=(10-real)\r\nprint(ans)\r\n\r\n", "n = int(input())\r\na = input()\r\nb = input()\r\nc = 0\r\nfor i in range(n):\r\n a1 = 10 + min(int(a[i]), int(b[i])) - max(int(a[i]), int(b[i]))\r\n b1 = abs(int(a[i]) - int(b[i]))\r\n c += min(a1, b1)\r\nprint(c)\r\n", "n = int(input())\r\ns_a = input()\r\nlock_a = input()\r\n\r\ns = [int(i) for i in s_a]\r\nlock = [int(i) for i in lock_a]\r\n\r\ncount = 0\r\nfor x in range(n):\r\n count += min((10-abs(s[x]-lock[x])), abs(s[x]-lock[x]))\r\n \r\nprint(count)", "n=int(input())\nm=list(map(int,input()))\no=list(map(int,input()))\n\ns=[]\ndef get_shortest_path(current_digit, target_digit):\n clockwise_path = (target_digit - current_digit) % 10\n anticlockwise_path = (current_digit - target_digit) % 10\n if clockwise_path <= anticlockwise_path:\n return clockwise_path, 1\n else:\n return anticlockwise_path, -1\n\ndef rotate_wheel(current_digit, target_digit):\n path, direction = get_shortest_path(current_digit, target_digit)\n\n for i in range(path):\n current_digit = (current_digit + direction) % 10\n s.append(current_digit)\n\n return current_digit\nfor i in range(n):\n current_digit = m[i]\n target_digit = o[i]\n new_digit = rotate_wheel(current_digit, target_digit)\nprint(len(s))\n", "j = int(input())\nA = tuple(map(int, input()))\nB = tuple(map(int, input()))\n \nc = 0\nfor i in range(0, len(A)):\n x, y = A[i], B[i]\n c += min(abs(x - y), 10 - abs(x - y))\n \nprint(c)\n", "n=int(input())\r\nx=input()\r\ny=input()\r\nsum=0\r\nfor i in range(len(x)):\r\n a=int(x[i])\r\n b=int(y[i])\r\n mn=min(abs(a-b),(10-(max(a,b))+min(a,b)))\r\n sum+=mn\r\nprint(sum)\r\n\r\n\r\n\r\n", "n=int(input())\na=list(map(int,input()))\nb=list(map(int,input()))\nans=0\nfor i in range(n):\n x,y=a[i],b[i]\n x,y=min(x,y),max(x,y)\n ans+=min(y-x,(x-y)%10)\nprint(ans)\n", "n = int(input())\r\na = input()\r\nb = input()\r\nm = 0\r\nfor i in range(n):\r\n c = int(a[i])\r\n d = int(b[i])\r\n m += min(abs(min(c, d) - max(c, d)),abs(min(c, d) - max(c, d) + 10))\r\nprint(m)", "n = int(input())\r\nc = input()\r\no = input()\r\nclosed = list(c)\r\nopened = list(o)\r\ncount = 0 \r\n\r\nfor i in range(n):\r\n diff = int(closed[i])-int(opened[i])\r\n if diff > 0 :\r\n diff = diff \r\n else:\r\n diff = - diff\r\n if diff < 5:\r\n count += diff \r\n else :\r\n count += (10-diff)\r\nprint(count) ", "n=int(input())\r\na=input()\r\nb=input()\r\nprint(sum(5-abs(5-abs(int(a[i])-int(b[i]))) for i in range(n)))", "_=input\r\na=int(_())\r\nb,c=_(),_()\r\nans=0\r\nfor i in range(a):\r\n ans+=min(abs(int(b[i])-int(c[i])),10-abs(int(c[i])-int(b[i])))\r\n\r\nprint(ans)\r\n", "import sys\r\n# sys.stdin = open('input.txt', 'r')\r\n# sys.stdout = open('output.txt', 'w')\r\n# sys.setrecursionlimit(1000000)\r\ndef Ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef Strs(): return map(str, sys.stdin.readline().strip().split())\r\ndef Array(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef Str(): return sys.stdin.readline().strip()\r\ndef Int(): return int(sys.stdin.readline().strip())\r\ndef MOD(): return 1000000007\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n = Int()\r\n s1 = Str()\r\n s2 = Str()\r\n res = 0\r\n\r\n for i in range(n):\r\n a = abs(int(s1[i]) - int(s2[i]))\r\n b = (10 - int(s1[i])) + int(s2[i])\r\n c = (10 - int(s2[i])) + int(s1[i])\r\n # print(a,b,c)\r\n res += min(a,b,c)\r\n print(res)\r\n\r\n\r\n", "'''\r\n5\r\n82195\r\n64723\r\n'''\r\n\r\nn = int(input())\r\ns = str(input())\r\ns1 = str(input())\r\nres = 0\r\nfor i in range(n):\r\n x = int(s[i])\r\n y = int(s1[i])\r\n res += min(abs(x - y), 10 - abs(x - y))\r\nprint(res)", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\nct = 0\r\nfor i, j in zip(s1, s2):\r\n i = int(i); j = int(j)\r\n mx = max(i, j); mn = min(i, j)\r\n mv1 = mx - mn\r\n mv2 = 10 - mx + mn\r\n ct += min(mv1, mv2)\r\n\r\nprint(ct)", "t=int(input())\r\na=list(input())\r\nb=list(input())\r\n \r\nk=0\r\n\r\nfor i in range(len(a)):\r\n d=int(a[i])-int(b[i])\r\n if d<0:\r\n d=-d\r\n else:\r\n d=d\r\n if d>5:\r\n x=9-d\r\n x+=1\r\n k+=x\r\n else:\r\n k+=d\r\nprint(k)\r\n ", "n = int(input())\ncurrent = str(input())\nnew = str(input())\nttl = 0\nfor x in range(n):\n difference = abs(int(current[x])-int(new[x]));\n if(difference > 5):\n difference = 10-difference\n ttl += difference\nprint(ttl)\n", "sai=int(input())\r\n\r\nteja=input()\r\nt=input()\r\nf=0\r\nfor i in range(sai):\r\n c=int(teja[i])\r\n d=int(t[i])\r\n e=min(10-abs(c-d),abs(c-d))\r\n f=f+e\r\nprint(f)", "n=int(input())\r\na=input()\r\nb=input()\r\nr=0\r\nfor i in range(n):\r\n length=abs(int(a[i])-int(b[i]))\r\n r +=min(length,10-length)\r\nprint(r)\r\n\r\n\r\n", "n=int(input())\r\nx=input()\r\ny=input()\r\ns=0\r\nfor i in range(n):\r\n k=abs(int(x[i])-int(y[i]))\r\n p=10-k\r\n s=s+min(k,p)\r\nprint(s)", "n=int(input())\r\na=input()\r\nb=input()\r\nc=0\r\nfor i in range(n):\r\n step=abs(int(a[i])-int(b[i]))\r\n if step>5:\r\n step =10-step\r\n c=c+step\r\nprint(c)", "def main():\n n = int(input())\n s = 0\n passw = input()\n true_pass = input()\n for i in range(n):\n temp = abs(int(true_pass[i]) - int(passw[i]))\n if temp > 5:\n s += (10 - temp)\n else:\n s += temp\n print(s)\n\n\nmain()\n", "n = int(input())\r\nm = list(input().replace('',' ').split())\r\nf = list(input().replace('',' ').split())\r\nrul = [0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9] #0 на 10 позиции 5 на 15 9 на 19\r\nfor i in range(len(f)):\r\n f[i] = int(f[i])\r\n m[i] = int(m[i])\r\n\r\ng1 = 0\r\ng2 = 0\r\ngr = []\r\ngg = []\r\nbst = []\r\nfor i in range(len(m)):\r\n c1 = rul.index(m[i],10,20)\r\n c2 = rul.index(f[i],10,20)\r\n for q in range(c1,29):\r\n if c2 % 10 != rul[q] % 10:\r\n g1 += 1\r\n else:\r\n g1 += 1\r\n break\r\n\r\n for q in range(c1,0,-1):\r\n if c2 % 10 != rul[q] % 10:\r\n g2 += 1\r\n else:\r\n g2 += 1\r\n break\r\n bst.append(min(g1,g2)-1)\r\n g1 = 0\r\n g2 = 0\r\n\r\nprint(sum(bst))\r\n", "n=int(input())\r\nos=input()\r\nfs=input()\r\nans=0\r\nfor i in range(n):\r\n a=int(os[i])\r\n b=int(fs[i])\r\n c=abs(a-b)\r\n if c>5:\r\n ans+=(10-c)\r\n else:\r\n ans+=c\r\nprint(ans)", "n = int(input())\r\na = list(input())\r\nb = list(input()) \r\nc = 0\r\n# s = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']\r\nfor i in range(n):\r\n if a[i]!=b[i]:\r\n c = c + min(10 - abs(int(b[i])-int(a[i])), abs(int(b[i])-int(a[i])))\r\n else:\r\n continue\r\nprint(c)", "'''\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'''\nc=0\nn=int(input())\na=input();b=input()\nfor i in range(n):\n c+=min(abs(int(b[i])-int(a[i])),10-abs(int(b[i])-int(a[i])))\n \nprint (c)", "n = int(input())\r\ns = input()\r\nt = input()\r\nans = 0\r\nfor a,b in zip(s,t):\r\n a = int(a)\r\n b = int(b)\r\n t = abs(a-b)\r\n ans += min(t,10-t)\r\nprint(ans)\r\n", "n = int(input())\r\ns = input()\r\ns1 = input()\r\nk = 0\r\nfor i in range(len(s)):\r\n k += min(abs(int(s[i]) - int(s1[i])), 10 - abs(int(s[i]) - int(s1[i])))\r\nprint(k)\r\n", "n = int(input())\r\ninitial = input()\r\nfinal = input()\r\nsum = 0\r\n\r\nfor i in range(n):\r\n sum += min(abs(int(initial[i]) - int(final[i])), (int(initial[i]) - int(final[i]) + 10), (-int(initial[i]) + int(final[i]) + 10))\r\nprint(sum)", "#tähän tiedostoon tulee ensimmäinen codeforces koodi\r\n#Roope Ankan rahasäiliön koodi.\r\nnumofdisks = int(input())\r\nbegstate = str(input())\r\nendstate = str(input())\r\nbegstatelst = []\r\nendstatelst = []\r\nmvnmb = 0\r\nfor i in begstate:\r\n begstatelst.append(i)\r\nfor i in endstate:\r\n endstatelst.append(i)\r\nfor i in range(numofdisks):\r\n diff = abs(int(begstatelst[i]) - int(endstatelst[i]))\r\n if diff <= 5:\r\n mvnmb += diff\r\n elif diff > 5:\r\n mvnmb += 10 - diff\r\nprint(mvnmb)\r\n", "n = int(input())\r\ninitial = input()\r\ntarget = input()\r\nrotations_needed = 0\r\n\r\nfor i in range(n):\r\n diff = abs(int(initial[i]) - int(target[i]))\r\n rotations_needed += min(diff, 10-diff)\r\n\r\nprint(rotations_needed)\r\n", "n=input()\r\ns1=input()\r\ns2=input()\r\nsum3=0\r\nfor x in range(len(s1)):\r\n sum1=10-abs(int(s1[x])-int(s2[x]))\r\n sum2=abs(int(s1[x])-int(s2[x]))\r\n sum3+=min(sum2,sum1)\r\nprint(sum3)\r\n ", "n = int(input())\r\nbefore = input()\r\nafter = input()\r\nmoves = 0\r\nfor i in range(n):\r\n x = abs(ord(before[i]) - ord(after[i]))\r\n moves += min(x, 10 - x)\r\nprint(moves)\r\n", "i=int(input())\rp,v=input(),input()\ro=0\rfor k in range(i):\r o+=min(abs(int(p[k])-int(v[k])),10-abs(int(p[k])-int(v[k])))\rprint(o)", "n=int(input())\r\na=input()\r\nb=input()\r\ncount=0\r\nfor i in range(n):\r\n s=int(a[i])-int(b[i])\r\n if s<0:\r\n s=-s\r\n u=min(int(a[i]),int(b[i]))\r\n v=max(int(a[i]),int(b[i]))\r\n t=10-v+u\r\n if t<0:\r\n t=-t\r\n count+=min(s,t)\r\nprint(count)\r\n ", "n=int(input())\r\na=list(input())\r\nb=list(input())\r\na=[int(u) for u in a]\r\nb=[int(u) for u in b]\r\nt=0\r\nfor i,j in zip(a,b):\r\n d=abs(i-j)\r\n if d<=5:\r\n t=t+d\r\n if d>5:\r\n t=t+(10-d)\r\n \r\nprint(t)", "n = int(input())\r\nori = input()\r\ncombi = input()\r\ntot = 0\r\nfor a in range(n):\r\n o = int(ori[a])\r\n c = int(combi[a])\r\n mi = min(c,o)\r\n ma = max(c,o)\r\n tot += min(ma-mi, 9-ma+mi+1)\r\nprint(tot)\r\n", "def main():\r\n n = int(input())\r\n p1 = input()\r\n p2 = input()\r\n turn = 0\r\n for i in range(n):\r\n turn += min(abs(int(p1[i])-int(p2[i])), 10-abs(int(p1[i])-int(p2[i])))\r\n print(turn)\r\n \r\n \r\nmain()", "n, a, b = int(input()), input(), input()\nc = 0\nfor i in range(n):\n c += min(10 - abs(int(a[i]) - int(b[i])), abs(int(a[i]) - int(b[i])))\n\nprint(c)", "n=int(input(''))\r\nsl=list(map(int,input('')))\r\ncl=list(map(int,input('')))\r\nl=list(range(0,10))\r\ncount=0\r\nfor i,j in zip(sl,cl):\r\n t1=(i,j)\r\n max1=max(t1)\r\n min1=min(t1)\r\n l1=l[0:min1]+l[max1::]\r\n t2=(len(l1),max1-min1)\r\n #print(min(t2),end=',')\r\n count+=min(t2)\r\nprint(count)\r\n\r\n", "n = int(input())\r\norigin = list(map(int, list(str(input()))))\r\ntarget = list(map(int, list(str(input()))))\r\nsum = 0\r\n\r\n\r\nfor i in range(n):\r\n\r\n sum += min( abs(origin[i] - target[i]) , ( 10 - origin[i]) + target[i] , origin[i] + ( 10 - target[i] ) )\r\n\r\nprint(sum)\r\n", "n = int(input())\r\na = input()\r\nb = input()\r\ns = 0\r\nfor i in range(n):\r\n x = int(a[i])\r\n y = int(b[i])\r\n if y<x:\r\n x,y = y,x\r\n s+=min([y-x,10+x-y])\r\nprint(s)", "n = input()\r\nstart_pos = input()\r\nopen_pos = input()\r\n\r\ncounter = 0\r\nfor i, j in zip(start_pos, open_pos):\r\n i, j = int(i), int(j)\r\n count_pos = 0\r\n if i == j:\r\n continue\r\n elif i < j:\r\n while i < j:\r\n i += 1\r\n count_pos += 1\r\n else:\r\n while i > j:\r\n i -= 1\r\n count_pos += 1\r\n \r\n if count_pos > 5:\r\n count_pos = 10 - count_pos\r\n\r\n counter += count_pos\r\n\r\nprint(counter)", "def check(n, m):\r\n return min(abs(n - m), (n + (9 - m) + 1), (m + (9 - n) + 1))\r\n\r\nx = int(input())\r\na, b = input(), input()\r\nans = 0\r\nfor i in range(x):\r\n ans = ans + check(int(a[i]), int(b[i]))\r\nprint(ans)\r\n", "a, total = int(input()), 0\r\nq, w = [], []\r\ns, d = input(), input()\r\nq.extend(s)\r\nw.extend(d)\r\nfor i in range(a):\r\n q[i] = int(q[i])\r\n w[i] = int(w[i])\r\nfor k in range(a):\r\n if max(q[k], w[k]) - min(q[k], w[k]) > 5:\r\n total += (9 - max(q[k], w[k])) + (min(q[k], w[k])) + 1\r\n else:\r\n total += max(q[k], w[k]) - min(q[k], w[k])\r\nprint (total)", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\nnum_moves = 0\r\nfor i in range(n):\r\n x = abs(int(s1[i])-int(s2[i]))\r\n if x <= 5:\r\n num_moves += x\r\n else:\r\n num_moves += 10-x\r\nprint(num_moves)\r\n", "n=int(input())\r\nl=int(input())\r\nm=int(input())\r\nc=0\r\nwhile(n):\r\n a=l%10\r\n b=m%10\r\n if(a==b):\r\n l=l//10\r\n m=m//10\r\n elif(a<b):\r\n c+=min(abs(a-b),a+9-b+1)\r\n l=l//10\r\n m=m//10\r\n else:\r\n c+=min(abs(a-b),9-a+b+1)\r\n l=l//10\r\n m=m//10\r\n n-=1\r\nprint(c)\r\n", "dic = {6:4, 7:3, 8:2, 9:1}\r\n\r\nn = int(input())\r\nstart = input()\r\nstop = input()\r\nmoves = 0\r\nfor i in range(n):\r\n x = abs(int(start[i]) - int(stop[i]))\r\n if x > 5:\r\n moves += dic[x]\r\n else:\r\n moves += x\r\nprint(moves)\r\n", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nres=0\r\nfor i in range(len(s1)):\r\n c1=abs(int(s1[i])-int(s2[i]))\r\n c2=10-abs(int(s1[i])-int(s2[i]))\r\n res+=min(c1,c2)\r\nprint(res)\r\n", "input()\r\nx=input()\r\ny=input()\r\nc=0\r\nfor i in range(0,len(x)):\r\n t=abs(int(x[i])-int(y[i]))\r\n c+=min(t,(10-t))\r\nprint(c)", "while True:\r\n try:\r\n n = eval(input())\r\n origin = input()\r\n correct = input()\r\n sum1 = 0\r\n for i in range(n):\r\n t1 = int(origin[i])\r\n t2 = int(correct[i])\r\n a = abs(t1 - t2)\r\n if t1 > t2:\r\n t = t1\r\n t1 = t2\r\n t2 = t\r\n b = abs(10 + t1 - t2)\r\n sum1 += min(a, b)\r\n print(sum1)\r\n except:\r\n break", "n=int(input())\r\na=input()\r\nb=input()\r\nc=0\r\nfor i in range(n):\r\n x=int(a[i])\r\n y=int(b[i])\r\n c=c+min(abs(x-y),abs(9-x)+y+1,abs(9-y)+x+1)\r\nprint(c)", "n=int(input())\r\noriginal=input()\r\nkey=input()\r\nturns=0\r\nfor i in range(n):\r\n dif=abs(int(original[i])-int(key[i]))\r\n turns+=min(dif,10-dif)\r\nprint(turns)", "input();print(sum(min(abs(x-y),10-abs(x-y)) for x,y in zip(map(int,input()),map(int,input()))))", "n=int(input())\r\ns1=input()\r\ns2=input()\r\ns1=list(s1)\r\ns2=list(s2)\r\nr=0\r\nfor i in range(n):\r\n d1=abs(int(s1[i])-int(s2[i]))\r\n d2=10-max(int(s1[i]),int(s2[i]))+min(int(s1[i]),int(s2[i]))\r\n d=min(d1,d2)\r\n r+=d\r\nprint(r)", "n = int(input())\r\na = str(input())\r\nb = str(input())\r\nsum = 0\r\nfor i in range (n):\r\n x = int(a[i])\r\n y = int(b[i])\r\n selisih1 = min(x, y)\r\n selisih2 = max(x, y)\r\n add = min(abs(x-y), (selisih1 + 10)-selisih2)\r\n sum += add\r\nprint(sum)", "n=int(input())\r\nd1=int(input())\r\nd2=int(input())\r\nres=0\r\nfor i in range(0,n):\r\n g=d1%10\r\n h=d2%10\r\n aux=g\r\n r1=0\r\n r2=0\r\n while g!=h:\r\n g=(g+1)%10\r\n r1+=1\r\n while aux!=h:\r\n aux=(aux-1+10)%10\r\n r2+=1\r\n res+=min(r1,r2)\r\n d1//=10\r\n d2//=10\r\nprint(res)", "def main():\n\tn = int(input())\n\ta = int(input())\n\tb = int(input())\n\tans =0\n\twhile n>0:\n\t\tn-=1\n\t\tx,y =a%10,b%10\n\t\ta//=10\n\t\tb//=10\n\t\tans+= min(10-abs(x-y),abs(x-y))\n\tprint(ans)\nmain()\n\n", "n=int(input())\ns=input()\ns1=input()\nw=0\nfor i in range(n):\n y=int(s[i])\n y1=int(s1[i])\n y2=y1\n y3=y\n if y>y1:\n q=0\n while y!=y1:\n if y==9:\n y=0\n q+=1\n else:\n q+=1\n y+=1\n w+=min(abs(y3-y2),q)\n elif y<y1:\n q=0\n while y!=y1:\n if y==0:\n y=9\n q+=1\n else:\n q+=1\n y-=1\n w+=min(abs(y3-y2),q)\nprint(w)\n", "\r\n\r\n\r\nt = int(input())\r\nl1 = list(input())\r\nl2 = list(input())\r\n\r\nans = 0\r\nfor ind in range(0, t):\r\n ans += min(abs(int(l1[ind]) - int(l2[ind])), abs(-int(l1[ind]) + int(l2[ind]) - 10), abs(+int(l1[ind]) - int(l2[ind]) - 10))\r\nprint(ans)\r\n", "n=int(input())\r\n\r\nstart=list(input())\r\nend=list(input())\r\n\r\nmoves=0 \r\n\r\nfor i in range(n):\r\n \r\n #if start is bigger than end \r\n\r\n if int(start[i])>int(end[i]):\r\n #go anticlockwise \r\n moves_a = int(start[i])-int(end[i])\r\n #go clock, jump on 9 to 0\r\n moves_c= (9-int(start[i])) + 1 + (int(end[i])) \r\n\r\n moves+=min(moves_a,moves_c) \r\n\r\n elif int(start[i])==int(end[i]):\r\n moves+=0 \r\n \r\n else:\r\n\r\n moves_c= int(end[i]) - int(start[i])\r\n moves_a= int(start[i]) + 1 + (9-int(end[i])) \r\n\r\n moves+=min(moves_a, moves_c) \r\n\r\n\r\nprint(moves)\r\n", "N=int(input())\r\na=input()\r\nb=input()\r\nSUM=0\r\nfor i in range(N):\r\n s=abs(int(a[i])-int(b[i]))\r\n if s>5:\r\n SUM+=10-s\r\n else:\r\n SUM+=s\r\nprint(SUM)", "import string\r\nimport math\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(x, y):\r\n return (x*y)//gcd(x,y)\r\n\r\ninput()\r\ninit, final = [int(i) for i in input()], [int(i) for i in input()]\r\ncount = 0\r\nfor i in range(len(init)):\r\n count += min(abs(10 - final[i] + init[i]), abs(final[i] - init[i]), abs(10 - init[i] + final[i]))\r\nprint(count)", "n = int(input())\n\ncurrent_state = input()\n\ncombination = input()\n\nmoves = 0\n\nfor disk in range(n):\n num = abs(int(current_state[disk]) - int(combination[disk]))\n if num > 5:\n num = 10 - num\n moves += num\n\nprint(moves)\n", "n = int(input())\r\na = map(int, input())\r\nb = map(int, input())\r\nanswer = 0\r\nfor j, k in zip(a, b):\r\n d = abs(j - k)\r\n answer += min(10-d, d)\r\nprint(answer)", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nans=0\r\nfor i in range(n):\r\n a=int(s1[i])\r\n b=int(s2[i])\r\n if a>b:\r\n if abs(a-b)<abs(a-b-10):\r\n ans+=abs(a-b)\r\n else:\r\n ans+=abs(a-b-10)\r\n else:\r\n if abs(a-b)<abs(a+10-b):\r\n ans+=abs(a-b)\r\n else:\r\n ans+=abs(a+10-b)\r\n \r\nprint(ans)\r\n ", "Disk=[0,1,2,3,4,5,4,3,2,1]\r\nN=int(input())\r\nCad1=input()\r\nCad2=input()\r\nCont=0\r\nfor K in range(N):\r\n Resta=abs(int(Cad1[K])-int(Cad2[K]))\r\n Cont=Cont+Disk[Resta]\r\nprint(Cont)\r\n", "n=int(input())\r\na=input()\r\nb=input()\r\nk='0123456789'\r\nk1='5678901234'\r\no=0\r\nfor i in range(n):\r\n\tc1=abs(k.find(a[i])-k.find(b[i]))\r\n\tc2=abs(k1.find(a[i])-k1.find(b[i]))\r\n\to+=min(c1,c2)\r\nprint(o)\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\norg = input()\r\nsec = input()\r\nans = 0\r\nfor i in range(n):\r\n ans += min(abs(int(org[i]) - int(sec[i])),9 - abs(int(org[i]) - int(sec[i])) + 1)\r\nprint(ans)", "n=int(input())\r\nn1=input()\r\nn2=input()\r\nsum=0\r\n\r\nfor i in range(len(n1)):\r\n sum+=min(abs(int(n1[i])-int(n2[i])),10-abs(int(n1[i])-int(n2[i])))\r\nprint(sum)", "n=int(input())\r\na=input()\r\nb=input()\r\nmove=0\r\nfor i in range(n):\r\n move=move+min(10-abs(int(a[i])-int(b[i])),abs(int(a[i])-int(b[i])))\r\nprint(move)\r\n \r\n", "n = int(input())\r\na = [int(i) for i in input()]\r\nb = [int(i) for i in input()]\r\nk = 0\r\nfor i in range(n):\r\n if abs(a[i] - b[i]) > 5:\r\n k += 10 - abs(a[i] - b[i])\r\n else:\r\n k += abs(a[i] - b[i])\r\nprint(k)", "n = int(input())\r\nstr1 = str(input())\r\nstr2 = str(input())\r\ncount = 0\r\nfor i in range(0, n):\r\n count += min( abs( int(str1[i]) - int(str2[i]) ) , 10-abs( int(str1[i]) - int(str2[i]) ) )\r\nprint(count)", "n = int(input())\r\na = [int(x) for x in str(input()[:n])]\r\nb = [int(x) for x in str(input()[:n])]\r\ncount = 0\r\nfor i in range(n):\r\n count += min(10 - abs(a[i]-b[i]), abs(a[i]-b[i]))\r\nprint(count)", "n = int(input())\r\na = input().strip()\r\nb = input().strip()\r\n\r\nc = 0\r\n\r\nfor i in range(n):\r\n\tif a[i] == b[i]:\r\n\t\tcontinue\r\n\r\n\ta0 = int(a[i])\r\n\tb0 = int(b[i])\r\n\r\n\tc += min(abs(a0 - b0), 10 - max(a0, b0) + min(a0, b0))\r\n\r\nprint(c)", "n = int(input())\r\ns = list(map(int, list(input())))\r\nf = list(map(int, list(input())))\r\nans = 0\r\nfor i in range(n):\r\n a = s[i]\r\n b = f[i]\r\n ans += min(10 - abs(b - a), abs(b - a))\r\nprint(ans)", "n = int(input())\r\na = input()\r\nb = input()\r\nsum = 0\r\nfor i in range(n) :\r\n x = int(a[i])\r\n y = int(b[i])\r\n z = abs(x-y)\r\n if z<=5 :\r\n sum += z\r\n else :\r\n sum += (10-z)\r\nprint(sum)", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nc=0\r\nfor i in range(len(s1)):\r\n c+=min((10+min(int(s1[i]), int(s2[i])))-max(int(s2[i]), int(s1[i])),abs(int(s1[i])-int(s2[i])))\r\nprint(c)", "n=int(input())\r\na=input() # исходное положение дисков\r\nb=input()\r\nc=0 # 0123456789\r\nfor i in range(n):\r\n if abs(int(a[i])-int(b[i])) < 10-max(int(a[i]),int(b[i]))+min(int(a[i]),int(b[i])):\r\n c+=abs(int(a[i])-int(b[i]))\r\n else: c+=10-max(int(a[i]),int(b[i]))+min(int(a[i]),int(b[i]))\r\nprint(c)", "n=int(input())\r\nini=input()\r\nfin=input()\r\ncount=0\r\nfor i in range(n):\r\n dif=abs(int(ini[i])-int(fin[i]))\r\n if dif > 5:\r\n dif =10-dif\r\n count=count+dif\r\nprint(count)", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\ns=0\r\nfor i in range(n):\r\n a = int(s1[i])\r\n b = int(s2[i])\r\n\r\n m1 = abs(a-b)\r\n\r\n m2 = 10-max(a,b)+min(a,b)\r\n s+= min(m1,m2)\r\n\r\nprint(s)\r\n\r\n", "n = int(input())\r\nold = [int(i) for i in input()]\r\nnew = [int(i) for i in input()]\r\ntotal = 0\r\n\r\nfor o, n in zip(old, new):\r\n smallest = min(abs(o-n), 10-o+n, o+10-n)\r\n total += smallest\r\n\r\nprint(total)", "l,p,q=[input()for _ in[1,2,3]]\r\nc = 0\r\nfor i in range(int(l)):\r\n c += min(abs(int(p[i])-int(q[i])),10-abs(int(p[i])-int(q[i])))\r\nprint(c) ", "a = int(input())\r\ns1 = list(input())\r\ns2 = list(input())\r\ns = 0\r\nfor i in range(a):\r\n q1 = 0\r\n q2 = 0\r\n if int(s1[i]) > int(s2[i]):\r\n q1 += int(s1[i]) - int(s2[i])\r\n q2 += (9 - int(s1[i])) + int(s2[i]) + 1\r\n if q1 < q2:\r\n s += q1\r\n else:\r\n s += q2\r\n else:\r\n q1 += (9 - int(s2[i])) + int(s1[i]) + 1\r\n q2 += int(s2[i]) - int(s1[i])\r\n if q1 < q2:\r\n s += q1\r\n else:\r\n s += q2\r\nprint(s)\r\n", "n = int(input())\r\ns1 = (input())\r\ns2 = (input())\r\nsum1 = 0\r\nfor i,j in zip(s1,s2):\r\n s3 = min(abs(int(i)-int(j)),(10-(abs(int(i)-int(j)))))\r\n sum1 = sum1 + s3\r\nprint(sum1)", "def split(a):\r\n\treturn [char for char in a]\r\n\r\nn=int(input())\r\nwrong=input()\r\ncorrect=input()\r\n\r\nwrong_split=split(wrong)\r\ncorrect_split=split(correct)\r\n\r\nwrong_split_int=[]\r\ncorrect_split_int=[]\r\nsum=0\r\n\r\nfor i in wrong_split:\r\n\twrong_split_int.append(int(i))\r\n\r\nfor i in correct_split:\r\n\tcorrect_split_int.append(int(i))\r\n\r\nfor i in range(0,n):\r\n\tsum+=min(10-abs(wrong_split_int[i]-correct_split_int[i]),abs(wrong_split_int[i]-correct_split_int[i]))\r\n\r\nprint(sum)", "n=int(input())\r\nst=input()\r\nst2=input()\r\nanswer_sum=0\r\nfor i in range(n):\r\n j=int(st[i])\r\n j1=int(st2[i])\r\n answer_sum+=min(abs(j-j1),9-(abs(j-j1))+1)\r\nprint(answer_sum)", "q = int(input())\r\nn = list(map(int,input()))\r\na = list(map(int,input()))\r\nsum = 0\r\n\r\nfor i in range(q):\r\n d = abs((a[i]) - (n[i]))\r\n sum += min(d, 10 - d)\r\nprint(sum)", "t=int(input())\r\n\r\ns=input()\r\npassword=input()\r\nsum=0\r\nfor i in range(t):\r\n sum+=min(abs(ord(s[i])-ord(password[i])),10-abs(ord(s[i])-ord(password[i])))\r\nprint(sum)", "n = int(input())\r\no = input()\r\nc = input()\r\ni = 0\r\noriginal = []\r\ncombination = []\r\nwhile i < n:\r\n x = int(o[i])\r\n original.append(x)\r\n y = int(c[i])\r\n combination.append(y)\r\n i += 1\r\nh = 0\r\nfor s in range(n):\r\n v = original[s] - combination[s]\r\n k = 10 - abs(v)\r\n if k < abs(v):\r\n h += k\r\n else:\r\n h += abs(v)\r\nprint(h)\r\n\r\n\r\n", "n=int(input())\r\ns=input()\r\np=input()\r\na=0\r\nfor i in range(n):\r\n x,y=int(s[i]),int(p[i])\r\n a+=min(abs(x-y),x+10-y,y+10-x)\r\nprint(a)", "a=input()\r\na=input()\r\nb=input()\r\nc=0\r\nfor i in range(len(a)):\r\n s=abs(int(a[i])-int(b[i]))\r\n c += min(s,abs(10-s))\r\nprint(c)", "n = int(input())\r\ncurrent = input()\r\nneeded = input()\r\nctr = 0\r\nfor i in range(n):\r\n if int(current[i]) >= int(needed[i]):\r\n up = int(current[i])-int(needed[i])\r\n else:\r\n up = (10+int(current[i]))-int(needed[i])\r\n if int(current[i]) <= int(needed[i]):\r\n down = int(needed[i])-int(current[i])\r\n else:\r\n down = (10+int(needed[i])-int(current[i])) \r\n if up <= down:\r\n ctr += up\r\n else:\r\n ctr +=down \r\nprint(ctr) ", "#!/usr/bin/env python\r\nimport sys, math, itertools\r\n\r\nif __name__ == '__main__':\r\n\twtf = sys.stdin.read()\r\n\twtf = wtf.strip().split('\\n')\r\n\tn = int(wtf[0])\r\n\tO = wtf[1]\r\n\tS = wtf[2]\r\n\tans = 0\r\n\tfor i in range(n):\r\n\t\to = int(O[i])\r\n\t\ts = int(S[i])\r\n\t\tans += min( abs(o - s), abs(10 - abs(o - s)) )\r\n\tprint(ans)", "n = int(input())\r\na = input()\r\nb = input()\r\nk = 0\r\nfor i in range(n):\r\n c = int(a[i]) - int(b[i])\r\n p = min(abs(c), 10 - abs(c))\r\n k += p\r\nprint(k)", "\r\nn =int(input())\r\na = input()\r\nb = input()\r\nsum = 0\r\n\r\nfor i in range(len(a)):\r\n if (max(int(a[i]),int(b[i]))) - (min(int(a[i]),int(b[i])))<=5:\r\n sum = sum + (max(int(a[i]),int(b[i])) - (min(int(a[i]),int(b[i]))))\r\n else:\r\n v = (9-max(int(a[i]),int(b[i])) + min(int(a[i]),int(b[i]))) + 1\r\n sum = sum + v\r\nprint(sum)\r\n\r\n\r\n \r\n\r\n", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nsum=0\r\nfor i in range(n):\r\n a=abs(int(s1[i])-int(s2[i]))\r\n sum+=min(a,10-a)\r\nprint(sum)", "\r\n# █████████████████████████████ ██╗ ██╗ █████╗ ██╗ ██████╗ ███████╗ ████████╗ ██╗ ██╗ ████████████████████████████████\r\n# █████████████████████████████ ██║ ██╔╝██╔══██╗██║ ██╔══██╗ ██╔════╝ ██ ╔════╝ ██║ ██║ ████████████████████████████████\r\n# █████████████████████████████ █████╔╝ ███████║██║ ██║ ██║ █████╗ ████████║ ███████║ ████████████████████████████████\r\n# █████████████████████████████ ██╔═██╗ ██╔══██║██║ ██║ ██║ ██╔══╝ ╔════╝██║ ██╔══██║ ████████████████████████████████\r\n# █████████████████████████████ ██║ ██╗██║ ██║███████╗██████╔╝ ███████╗ ████████║ ██║ ██║ ████████████████████████████████\r\n# █████████████████████████████ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═════╝ ╚══════╝ ╚══════╝╚ ═╝ ╚═╝ ████████████████████████████████\r\n\r\nMOD = int(1e9)+7\r\nfrom math import sqrt,ceil,log2,floor,gcd,pi\r\nfrom collections import deque\r\nfrom itertools import permutations\r\nimport sys\r\n\r\ndef solve():\r\n moves = 0\r\n for i in range(n):\r\n if abs(int(original[i])-int(open[i]))>5:\r\n mx = max(int(original[i]),int(open[i]))\r\n mn = min(int(original[i]),int(open[i]))\r\n moves += (9-mx)+1+mn\r\n else:\r\n moves += abs(int(original[i])-int(open[i]))\r\n\r\n print(moves)\r\n\r\n\r\nif __name__=='__main__':\r\n n = int(input())\r\n open = input()\r\n original = input()\r\n solve()\r\n", "n=int(input())\r\na=list(input())\r\nb=list(input())\r\nsum=0\r\nfor i in range(n):\r\n\tc=abs(int(a[i])-int(b[i]))\r\n\tsum+=min(c,10-c)\r\nprint(sum)", "n = int(input())\r\nstart = int(input())\r\nend = int(input())\r\ncnt = 0\r\nfor i in range(n):\r\n cnt += min(abs(min(start%10,end%10)-max(start%10,end%10)), min(start%10, end%10)+10-max(start%10, end%10))\r\n start //= 10\r\n end //= 10\r\nprint(cnt)\r\n", "a = int(input())\r\nb = list(input())\r\nc = list(input())\r\n\r\nx = 0\r\nfor i in range(0, a):\r\n x += min(abs(int(b[i]) - int(c[i])), min(int(b[i]),int(c[i])) + 10 - max(int(b[i]), int(c[i])))\r\n\r\nprint(x)", "n=int(input())\r\na=int(input())\r\nb=int(input())\r\nq=0\r\nf=[0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9]\r\nfor i in range(n):\r\n h=a%10\r\n g=b%10\r\n d1=abs(g-h)\r\n s=g+h\r\n e=9+min(h,g)+1\r\n d2=abs(e-max(h,g))\r\n q+=min(d1,d2)\r\n a=a//10\r\n b=b//10\r\nprint(q)\r\n", "n = int(input())\r\na = input()\r\nb = input()\r\ns = 0\r\nfor i in range(n):\r\n c = abs(int(a[i]) - int(b[i]))\r\n s += min(c, 10 - c)\r\nprint(s)", "N = int(input())\r\norg = input()\r\nfin = input()\r\n\r\nsol = 0\r\nfor i in range(N):\r\n a, b = int(min(org[i],fin[i])), int(max(org[i],fin[i]))\r\n sol += min(abs(b-a), a+10-b)\r\nprint(sol)", "n=int(input())\r\na=input()\r\nb=input()\r\nla=list(a)\r\nlb=list(b)\r\ncnt=0\r\nfor i in range(n):\r\n cnt+= min(abs(int(la[i])-int(lb[i])),10-abs(int(la[i])-int(lb[i])))\r\nprint(cnt)", "n = input()\r\nn = int(n)\r\n\r\noriginal = input()\r\nreal = input()\r\n\r\noriginal_list = [int(i) for i in list(original)]\r\nreal_list = [int(i) for i in list(real)]\r\n\r\nmoves = 0\r\nfor i in range(n):\r\n \r\n moves_down = original_list[i] - real_list[i]\r\n \r\n if moves_down < 0:\r\n moves_down = -moves_down\r\n \r\n moves_up = (10 + real_list[i]) - original_list[i]\r\n moves_up_2 = (10 + original_list[i]) - real_list[i] \r\n moves += min(moves_down, moves_up, moves_up_2)\r\n \r\nprint(moves)", "n = int(input())\r\na = input()\r\nb = input()\r\n\r\ns = 0\r\nfor i in range(n):\r\n x, y = max(int(a[i]), int(b[i])), min(int(a[i]), int(b[i])) \r\n s += min(x-y, 10 - x + y)\r\nprint(s)\r\n", "n = int(input())\r\na = int(input())\r\nb = int(input())\r\na_list =[]\r\nb_list =[]\r\ncount = 0\r\nfor i in range(n):\r\n k = n - (i + 1)\r\n t = 10**k\r\n la = a//t\r\n lb = b//t\r\n a = a - la*t\r\n b = b - lb*t\r\n a_list.append(la)\r\n b_list.append(lb)\r\n\r\nfor j in range(n):\r\n if abs(a_list[j]-b_list[j])<=5:\r\n count += abs(a_list[j]-b_list[j])\r\n else:\r\n count += (10 - abs(a_list[j]-b_list[j]))\r\n \r\nprint(count)\r\n ", "n = int(input())\r\na=input()\r\nal=list(map(int ,str(a)))\r\nb=input()\r\nbl=list(map(int ,str(b)))\r\nc=0\r\nfor i in range(n):\r\n x=abs(al[i]-bl[i])\r\n if x==9:\r\n c+=1\r\n elif x==8:\r\n c+=2\r\n elif x==7:\r\n c+=3\r\n elif x==6:\r\n c+=4\r\n else:\r\n c+=x\r\n\r\nprint(c)\r\n", "nb = input()\r\ntotal = 0\r\n\r\nval = input()\r\ncompare = input()\r\n\r\nfor i in range(int(nb)):\r\n calc = abs(int(val[i]) - int(compare[i]))\r\n total += calc if calc < 6 else 10 - calc\r\n\r\nprint(total)\r\n", "n = int(input())\r\n\r\ns1 = input()\r\ns2 = input()\r\n\r\nres = 0\r\n\r\nfor i in range(n):\r\n x = abs(int(s1[i]) - int(s2[i]))\r\n y = 10 - x\r\n res += min(x, y)\r\nprint(res)\r\n\r\n", "n = int(input())\r\norig_pos = [int(i) for i in input()]\r\nkey = [int(i) for i in input()]\r\nmovements = 0\r\n\r\nfor i in range(n):\r\n movements += min(10-(abs(orig_pos[i]-key[i])),(abs(orig_pos[i]-key[i])) )\r\nprint(movements) ", "n = int(input())\r\ns = input()\r\nk = input()\r\no = 0\r\nfor i in range(len(s)):\r\n ch = abs(int(s[i]) - int(k[i]))\r\n if ch > 5:\r\n o += 10 - ch\r\n else:\r\n o += ch\r\nprint(o)\r\n", "def min_step(n1, n2):\r\n step = abs(n1 - n2)\r\n return min(step, 10 - step)\r\n\r\n\r\nn = int(input())\r\ninit_state = input()\r\ngoal_state = input()\r\ntot = 0\r\nfor i in range(n):\r\n tot += min_step(int(init_state[i]), int(goal_state[i]))\r\nprint(tot)\r\n", "def my_function(n):\r\n a,b = input(),input()\r\n ans = 0\r\n for i in range(n):\r\n d = abs(int(a[i]) - int(b[i]))\r\n ans += min(d, 10 - d)\r\n print(ans)\r\n\r\naiyub = int(input())\r\nmy_function(aiyub)\r\n", "x = int(input())\ny = input()\nz = input()\ntotal = 0\nfor i in range(x):\n q = abs(int(y[i])-int(z[i]))\n temp = min(q, 10 - q)\n total += temp\nprint(total)\n", "n = int(input())\r\na = input()\r\nb = input()\r\ncount = 0\r\nfor i in range(n):\r\n x = int(a[i])\r\n y = int(b[i])\r\n if abs(x-y) <= 5:\r\n count += abs(x-y)\r\n else:\r\n if x < 5:\r\n count += (x+1)\r\n count += (abs(9-y))\r\n else:\r\n count += (y+1)\r\n count += abs(9 - x)\r\nprint(count)\r\n", "n=int(input())\r\nl=list(input())\r\nr=list(input())\r\nz=0\r\nt=[]\r\nfor i in l:\r\n if abs(int(i)-int(r[z]))>=6:\r\n if int(i)>=6:\r\n d=10-int(i)\r\n w=d+int(r[z])\r\n t.append(w)\r\n else:\r\n d=int(i)-0\r\n w=d+10-int(r[z])\r\n t.append(w)\r\n else:\r\n w=abs(int(i)-int(r[z]))\r\n t.append(w)\r\n z+=1\r\nprint(sum(t))", "x = lambda: map(int,input()); input();print(sum(min(abs(i-j),10-abs(i-j)) for i,j in zip(x(),x())))", "n=int(input())\r\noriginalstate=input()\r\npassword=input()\r\nres=0\r\nfor i in range(len(originalstate)):\r\n res+=min(10-abs(int(originalstate[i])-int(password[i])),abs(int(originalstate[i])-int(password[i])))\r\nprint(res)\r\n ", "cnt = 0\nn = int(input())\ns1 = input()\ns2 = input()\nfor i in range(n):\n cnt += min(abs(int(s1[i]) - int(s2[i])), (10 - abs(int(s1[i]) - int(s2[i]))))\nprint(cnt)\n\n\n\n", "n=int(input())\r\na=input()\r\nb=input()\r\n \r\nans = 0\r\n \r\nfor i in range(0,n):\r\n ans += min(10 - abs(int(a[i]) - int(b[i])), abs(int(a[i]) - int(b[i])))\r\n \r\n \r\nprint(ans)\r\n \r\n \r\n ", "len = int(input())\r\nbegin = [int(i) for i in input()]\r\nend = [int(i) for i in input()]\r\ninc = 0\r\nfor x in range(len):\r\n if begin[x] > end[x]:\r\n a = begin[x]\r\n b = end[x]\r\n else:\r\n a = end[x]\r\n b = begin[x]\r\n if abs(a-b) < abs(10-a+b):\r\n inc += abs(a-b)\r\n else:\r\n inc += abs(10-a+b)\r\nprint(inc)\r\n", "n=int(input())\r\nl1=list(input())\r\nl2=list(input())\r\nc=0\r\nfor i in range(n):\r\n d=abs(int(l1[i])-int(l2[i]))\r\n if d>5:\r\n d=10-d\r\n c+=d\r\nprint(c)\r\n", "import sys\r\nsys.setrecursionlimit(100000000)\r\ninput=lambda:sys.stdin.readline().strip()\r\nwrite=lambda x:sys.stdout.write(str(x)+'\\n')\r\n\r\n# from random import randint\r\n# from copy import deepcopy\r\n# from collections import deque\r\n# from heapq import heapify,heappush,heappop\r\n# from bisect import bisect_left,bisect,insort\r\n# from math import inf,sqrt,gcd,ceil,floor,log,log2,log10,pi\r\n# from functools import cmp_to_key\r\n\r\n\r\nn=int(input())\r\ns=input()\r\nt=input()\r\nans=0\r\nfor i in range(n):\r\n x=abs(int(s[i])-int(t[i]))\r\n ans+=min(x,10-x)\r\nprint(ans)", "n = int(input())\r\np = input()\r\nq = input()\r\nk = 0\r\nfor i in range(n):\r\n k += min(abs(int(p[i]) - int(q[i])), 10 - abs(int(p[i]) - int(q[i])))\r\n\r\nprint(k)", "n=int(input())\r\ns1=input()\r\ns2=input()\r\ntotal=0\r\nfor i in range(len(s1)):\r\n if(int(s1[i])>int(s2[i])):\r\n total+=min(int(s1[i])-int(s2[i]),10-int(s1[i])+int(s2[i]))\r\n else:\r\n total+=min(int(s2[i])-int(s1[i]),int(s1[i])+10-int(s2[i]))\r\nprint(total)", "n = int(input())\r\nsn = input()\r\ns = input()\r\ncount = 0\r\nfor i in range(n):\r\n if abs(int(sn[i]) - int(s[i])) > abs(10-max(int(sn[i]),int(s[i]))+min(int(sn[i]),int(s[i]))):\r\n count+=abs(10-max(int(sn[i]),int(s[i]))+min(int(sn[i]),int(s[i])))\r\n else:\r\n count+=abs(int(sn[i]) - int(s[i]))\r\nprint(count)", "x = int(input())\r\na = input()\r\nb = input()\r\nn = [int(x) for x in a]\r\nm = [int(x) for x in b]\r\n\r\nr = 0\r\nfor i in range(x):\r\n x, y = n[i], m[i]\r\n p = abs(x - y)\r\n if x > y:\r\n r += min(p, 10 - x + y)\r\n else:\r\n r += min(p, 10 - y + x)\r\n\r\n\r\nprint(r)\r\n", "num=int(input())\r\nn1=input()\r\nn2=input()\r\ns=0\r\nfor i in range(num):\r\n if abs(int(n1[i])-int(n2[i]))<5:\r\n s+=abs(int(n1[i])-int(n2[i]))\r\n else:\r\n s+=abs(10-abs(int(n1[i])-int(n2[i])))\r\nprint(s)", "n = int(input())\r\na = list(map(int,input()))\r\nb = list(map(int,input()))\r\nc = 0\r\nd = 0\r\nfor i in range(len(a)):\r\n c = min(abs(a[i]-b[i]),10-abs(a[i]-b[i]))\r\n d += c\r\nprint(d)", "n=int(input())\r\nnows=str(input())\r\nneeds=str(input())\r\nnow=[int(i) for i in nows]\r\nneed=[int(i) for i in needs]\r\nmove=0\r\ntotal=0\r\nfor i in range(n):\r\n a=int( now[i])\r\n b=int(need[i])\r\n diff=abs(a-b)\r\n if(diff>5):\r\n if(diff==6):\r\n move=4\r\n elif(diff==7):\r\n move=3\r\n elif (diff == 8):\r\n move=2\r\n elif (diff == 9):\r\n move=1\r\n else:\r\n move=diff\r\n total+=move\r\nprint(total)\r\n", "n=int(input())\r\na=input()\r\nb=input()\r\ncount=0\r\nfor i in range(n):\r\n x=max(int(a[i]),int(b[i]))-min(int(a[i]),int(b[i]))\r\n if x>5:\r\n x=10-x\r\n count += x\r\nprint(count) \r\n \r\n \r\n \r\n \r\n", "def solve(lst_1, lst_2):\r\n min_moves = 0 \r\n for i in range(len(lst_1)):\r\n min_moves += min(abs(int(lst_1[i]) - int(lst_2[i])), 10 - abs(int(lst_1[i]) - int(lst_2[i]))) \r\n\r\n print(min_moves)\r\n \r\nnum_of_disks = int(input())\r\ncomb_initial = list(input())\r\ncomb_target = list(input())\r\nsolve(comb_initial, comb_target)", "input()\r\narr1 = list(map(int,list(input())))\r\narr2 = list(map(int,list(input())))\r\ni = 0\r\ncnt = 0\r\nwhile i < len(arr1):\r\n a, b = arr1[i],arr2[i]\r\n if (a - b) > 0:\r\n cnt = cnt + min(a - b, abs(10 - (a - b)))\r\n elif (a - b) < 0:\r\n cnt = cnt + min(abs(a - b), abs(10 + (a - b)))\r\n i+=1\r\n\r\nprint(cnt)", "t = int(input())\ns1 = list(input())\ns2 = list(input())\ncount = 0\nfor i in range(t):\n a = int(s1[i])\n b = int(s2[i])\n diff = abs(a-b) \n if(diff>5):\n c = min(a,b)\n c+= 10\n diff = abs(max(a,b)-c)\n count+=diff\nprint(count)\n \t \t \t\t \t \t \t \t \t\t\t \t \t\t", "t = int(input())\r\nn = input()\r\nm = input()\r\ns = 0\r\nfor i in range(len(n)):\r\n s += min(abs(int(n[i])-int(m[i])), 10- abs(int(n[i])-int(m[i])) )\r\nprint(s)\r\n ", "a=int(input())\r\nb=input()\r\nc=input()\r\ncnt=0\r\nfor i in range(a):\r\n cnt+=min(abs(int(b[i])-int(c[i])),(10-abs(int(b[i])-int(c[i]))))\r\n\r\nprint(cnt) \r\n \r\n ", "n, a, b = input(), map(int, list(input())), map(int, list(input()))\r\nprint(sum(min(10-abs(c-d), abs(c-d)) for c, d in zip(a, b)))", "n = int(input())\r\na = list(input())\r\nb = list(input())\r\nans = 0\r\nfor i in range(n):\r\n ans += min(abs(int(a[i])-int(b[i])),10-abs(int(a[i])-int(b[i])))\r\n \r\nprint(ans)", "n = int(input())\r\nini_lock = list(map(int, input()))\r\ntarget_lock = list(map(int, input()))\r\n\r\nprint(sum([min(abs(ini_lock[i] - target_lock[i]), 10 - abs(ini_lock[i] - target_lock[i])) for i in range(n)]))", "n = int(input())\na, b, s = input(), input(), 0\nfor i in range(len(a)):\n x = abs(int(a[i]) - int(b[i]))\n s += min(x, 10 - x)\nprint(s)", "lenz = int(input())\r\n\r\nlock1 = input()\r\nlock2 = input()\r\nsum = 0\r\nfor i in range(lenz):\r\n\tif int(lock1[i]) > int(lock2[i]):\r\n\t\tsum += min(int(lock1[i]) - int(lock2[i]), (9 - int(lock1[i])) + int(lock2[i]) +1)\r\n\telif int(lock1[i]) < int(lock2[i]):\r\n\t\tsum += min(int(lock2[i]) - int(lock1[i]), (9 - int(lock2[i])) + int(lock1[i]) +1)\r\nprint(sum)", "n= int(input())\nlst1 = list(input())\nlst2 = list(input())\narr = [0,1,2,3,4,5,6,7,8,9]\ncount =0\nfor i in range(n):\n start = int(lst1[i])\n finish = int(lst2[i])\n diff= start - finish\n if abs(diff) < (10 - abs(diff)):\n count += abs(diff)\n else:\n count += (10-abs(diff))\nprint(count)", "n = int(input())\r\ncurr = input()\r\nopen_com = input()\r\nres = 0\r\nfor i in range(n):\r\n a = int(curr[i])\r\n b = int(open_com[i])\r\n if b >= a:\r\n dist1 = a+10-b\r\n dist2 = b-a\r\n else:\r\n dist1 = b+10-a\r\n dist2 = a-b\r\n res += min(dist1, dist2)\r\nprint(res)\r\n\r\n", "n = int(input())\r\n\r\ns = input()\r\n\r\nl = input()\r\n\r\nr = ''\r\n\r\nfor i in range (n):\r\n\r\n x = abs(int(s[i]) - int(l[i]))\r\n\r\n if x > 5:\r\n r += str(abs(x - 10))\r\n else:\r\n r += str(x)\r\n\r\nc = 0\r\n\r\nfor f in r:\r\n c += int(f)\r\n\r\nprint(c)", "t=int(input())\r\noriginal=input()\r\ncombination=input()\r\nans=0\r\nfor i in range(t):\r\n diff=abs(int(original[i])-int(combination[i]))\r\n ans+=min(diff,10-diff)\r\nprint(ans)", "x=int(input(\"\"))\ny=input(\"\")\nz=input(\"\")\nj=[]\nk=[]\nfor i in y:\n\ti=int(i)\n\tj.append(i)\nfor i in z:\n\ti=int(i)\n\tk.append(i)\nc=0\nh=0\nfor i in range(x):\n\ta= abs(j[h]-k[h])\n\tb=min(a, 10-a)\n\tc += b\n\th+=1\nprint(c)\n \t \t\t\t\t\t \t \t\t\t\t\t \t\t\t \t \t", "n = int(input())\r\ns = input()\r\ne = input()\r\ncounter = 0\r\nfor i in range(n):\r\n counter += min(abs(int(s[i]) - int(e[i])) % 10, (- abs(int(s[i]) - int(e[i]))) % 10)\r\nprint(counter)\r\n", "n = int(input())\r\nstart = map(int, list(input()))\r\ntarget = map(int, list(input()))\r\n\r\ncount = 0\r\n\r\nfor i, j in zip(start, target):\r\n count += min(abs(i-j), 10-abs(i-j))\r\n \r\nprint(count)", "n=int(input())\r\nnum1=input()\r\nnum2=input()\r\ncount=0\r\nfor i in range(n):\r\n counter=abs(int(num1[i])-int(num2[i]))\r\n anti_counter=10-int(counter)\r\n min_number=min(counter,anti_counter)\r\n count+=min_number\r\nprint(count)", "n=int(input())\r\nl1=list(input())\r\nl2=list(input())\r\ncount=0\r\nfor i in range(n):\r\n l=[int(l1[i]),int(l2[i])]\r\n ma=max(l)\r\n mi=min(l)\r\n if((ma-mi)>5):\r\n count+=1\r\n count+=(9-ma)\r\n count+=mi\r\n\r\n else:\r\n count+=(ma-mi)\r\n \r\nprint(count)", "n=int(input())\r\na=input()\r\nb=input()\r\ns=0\r\nfor x in range(n):\r\n c=int(a[x])\r\n d=int(b[x])\r\n f=c*1\r\n w=0\r\n q=0\r\n while c!=d:\r\n c+=1\r\n if c==10:\r\n c=0\r\n w+=1\r\n while f!=d:\r\n f-=1\r\n if f==-1:\r\n f=9\r\n q+=1\r\n s+=min(w,q)\r\nprint(s)", "n = int(input()) # n of disks\r\nnumbers = [int(x) for x in input()] # list of integers\r\nsolution = [int(x) for x in input()] # list of integers\r\nr = 0\r\nfor k, v in enumerate(numbers):\r\n d = abs(v - solution[k])\r\n if d > 5:\r\n r += 10 - d\r\n elif d == 5:\r\n r += 5\r\n else:\r\n r += d\r\nprint(r)\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Apr 15 17:35:57 2022\r\n\r\n@author: dehon\r\n\"\"\"\r\n\r\nn = int(input())\r\ns = input()\r\ns1 = input()\r\nc = 0\r\nfor i, j in zip(s, s1):\r\n if abs(int(i)-int(j)) <= 5:\r\n c += abs(int(i)-int(j))\r\n else:\r\n c += 10 - max(int(i), int(j))\r\n c += min(int(i), int(j))\r\n \r\nprint(c)", "n = int(input())\r\na = input()\r\nb = input()\r\nans = 0\r\nfor i in range(n):\r\n d = abs(ord(a[i]) - ord(b[i]))\r\n ans += min(d, 10-d)\r\nprint(ans)\r\n", "def min_moves_to_open_lock(n, original_state, desired_combination):\n total_moves = 0\n for i in range(n):\n digit1 = int(original_state[i])\n digit2 = int(desired_combination[i])\n diff = abs(digit2 - digit1)\n total_moves += min(diff, 10 - diff)\n return total_moves\n\n# Read input\nn = int(input())\noriginal_state = input().strip()\ndesired_combination = input().strip()\n\n# Calculate and print the result\nresult = min_moves_to_open_lock(n, original_state, desired_combination)\nprint(result)\n\n \t \t\t \t\t \t \t\t \t \t \t \t\t\t\t \t\t \t\t", "n = int(input())\nl = input()\nk = input()\nt = 0\n\nfor i in range(n):\n count = abs(ord(l[i]) - ord(k[i]))\n if count > 5:\n count = 10 - count\n t += count\n\nprint(t)\n\n \t \t\t \t \t\t\t \t\t \t \t \t \t\t", "t=int(input(\"\"))\r\nn=input(\"\")\r\nn2=input(\"\")\r\ndem=0\r\nfor i in range (t):\r\n dem+=min(abs(int(n[i])-int(n2[i])),min(int(n[i]),int(n2[i]))+(9-max(int(n[i]),int(n2[i])))+1)\r\nprint(dem)", "n = int(input())\noriginal_state = str(input())\nresolved_state = str(input())\n\nmoves_required = 0\nfor i in range(n):\n diff1 = abs((int(original_state[i]) - int(resolved_state[i])))\n diff2 = abs(diff1 - 10)\n moves_required += min(diff1, diff2)\nprint(moves_required)\n", "n = int(input())\r\ndisc_1 = input()\r\ndisc_2 = input()\r\ns = 0\r\nfor i in range(n):\r\n s += min(abs(int(disc_1[i])-int(disc_2[i])), 10-abs(int(disc_1[i])-int(disc_2[i])))\r\nprint(s)", "n = int(input())\r\nst = input()\r\nst2 = input()\r\ncnt=cnt1=0\r\nli = [str(x) for x in range(0,10)]\r\nc = v = 0\r\nfor i in range(n):\r\n ind = li.index(st[i])\r\n while(li[ind]!=st2[i]):\r\n if(li[ind]==\"9\"):\r\n ind = -1\r\n ind += 1\r\n c += 1\r\n ind = li.index(st[i])\r\n while(li[ind]!=st2[i]):\r\n ind -= 1\r\n v += 1\r\n if(c>v):\r\n cnt += v\r\n else:\r\n cnt += c\r\n c=v=0\r\nprint(cnt)", "n = int(input())\r\na = input()\r\nb = input()\r\ns = 0\r\nfor i in range(n):\r\n x = abs(int(a[i]) - int(b[i]))\r\n if int(a[i]) > int(b[i]):\r\n c = 10-int(a[i])\r\n d = abs(0-int(b[i]))\r\n y = c + d\r\n else:\r\n c = 10-int(b[i])\r\n d = abs(0-int(a[i]))\r\n y = c + d\r\n if x > y:\r\n s += y\r\n else:\r\n s += x\r\nprint(s)", "n = int(input())\r\nn1 = list(map(int, input()))\r\nn2 = list(map(int, input()))\r\nstep = 0\r\nfor i in range(n):\r\n step += min(abs(n1[i] - n2[i]), 10 - abs(n1[i] - n2[i]))\r\nprint(step)", "n = int(input())\r\na = input()\r\nb = input()\r\n\r\ns=0\r\n\r\nfor i in range(n):\r\n if abs(int(a[i])-int(b[i]))<=5:\r\n s=s+abs(int(a[i])-int(b[i]))\r\n else:\r\n s=s+(10 - max(int(a[i]),int(b[i]))) + min(int(a[i]),int(b[i]))\r\n \r\nprint(s)", "import math, heapq\r\nfrom sys import stdin\t\r\nfrom collections import Counter, defaultdict, deque, namedtuple\r\nfrom bisect import bisect_right, bisect_left\r\nfrom typing import List, DefaultDict\r\nfrom itertools import permutations\r\n \r\n \r\n \r\ndef readarray(typ):\r\n return list(map(typ, stdin.readline().split()))\r\n\r\n\r\ndef readint():\r\n return int(input())\r\n\r\n\r\nn = readint()\r\n\r\norg = input()\r\nsec = input()\r\n\r\nans = 0\r\n\r\nfor i in range(n):\r\n original = int(org[i])\r\n current = int(sec[i])\r\n\r\n up, down = current, current\r\n\r\n upMoves, downMoves = 0, 0\r\n\r\n for j in range(9):\r\n\r\n if up != original:\r\n up -= 1\r\n upMoves += 1\r\n \r\n if down != original:\r\n down += 1\r\n downMoves += 1\r\n\r\n if up == -1:\r\n up = 9\r\n \r\n if down == 10:\r\n down = 0\r\n \r\n ans += min(upMoves, downMoves)\r\n\r\nprint(ans)\r\n \r\n\r\n", "disk = int(input())\r\nstate = input()\r\ncombi = input()\r\ncount = 0\r\nfor num in range(disk):\r\n p = abs(int(state[num]) - int(combi[num]))\r\n if p <= 5:\r\n count += p\r\n else:\r\n count += 10 - p\r\nprint(count)", "n = int(input())\ns1 = input()\ns2 = input()\nsummi = 0\nfor i in range(n):\n val = abs(int(s1[i])- int(s2[i]))\n if val >5 :\n val = 10-val\n summi +=val\nprint(summi)", "m=0\r\nn=int(input())\r\na=list(map(int,input()))\r\nb=list(map(int,input()))\r\nfor i in range(n):\r\n if abs(a[i]-b[i])<=5:\r\n m+=abs(a[i]-b[i])\r\n else:\r\n m+=10-max(a[i],b[i])+min(a[i],b[i])\r\nprint(m)", "n=int(input())\r\nf1=str(input())\r\nf2=str(input())\r\nlist_n1=list()\r\nlist_n2=list()\r\nfor x in f1:\r\n list_n1.append(x)\r\n\r\nfor y in f2:\r\n list_n2.append(y)\r\n\r\ni=0\r\nsum=0\r\nfor i in range(0,n):\r\n n1=int(list_n1[i])\r\n n2=int(list_n2[i])\r\n if n2 > n1 :\r\n if n2-n1 < (n1+(10-n2)):\r\n sum=sum+(n2-n1)\r\n else : \r\n sum=sum+(n1+(10-n2))\r\n elif n1 > n2 :\r\n if n1-n2 < (n2+(10-n1)):\r\n sum=sum+n1-n2 \r\n else :\r\n sum=sum+(n2+(10-n1))\r\n\r\nprint(str(sum))", "n=int(input())\r\na=input()\r\nb=input()\r\nc=0\r\nfor i in range(n):\r\n x=abs(int(a[i])-int(b[i]))\r\n if(x<=5):\r\n c=c+x \r\n else:\r\n c=c+(10-x)\r\nprint(c)", "def solve(n, o, t):\r\n m = 0\r\n for i in range(0, n):\r\n distance = abs(int(o[i]) - int(t[i]))\r\n m += min(distance, 10 - distance)\r\n\r\n return m\r\n\r\nn = int(input())\r\no = input()\r\nt = input()\r\nprint(solve(n, o, t))", "n = int(input())\r\nnow = input()\r\norg = input()\r\ncount = 0\r\nfor i in range(len(now)):\r\n if(abs(int(now[i])-int(org[i]))<=4):\r\n count+=abs(int(now[i])-int(org[i]))\r\n else:\r\n count+=(10-abs(int(now[i])-int(org[i])))\r\nprint(count)", "n = int(input())\r\nsa = input()\r\nsb = input()\r\ncount = 0\r\n\r\nfor i, j in zip(sa,sb):\r\n i, j = int(i), int(j)\r\n if(abs(i-j) > 5):\r\n x = 10 - abs(i-j)\r\n else:\r\n x = abs(i-j)\r\n count+= x\r\nprint(count)", "n= int(input())\r\ninitial_state = input()\r\ncombination = input()\r\ntotal_moves = 0\r\nfor i in range(n):\r\n moves=abs(int(initial_state[i]) - int(combination[i]))\r\n total_moves += min(moves, 10 - moves)\r\nprint(total_moves)\r\n", "x=int(input())\r\no = input()\r\nn = input()\r\ntotal = 0\r\nfor i in range(x):\r\n\r\n sum1 = abs((int(o[i])-int(n[i])))\r\n total += min(sum1, 10-sum1)\r\n\r\nprint(total)\r\n\r\n\r\n\r\n\r\n\r\n", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\ncount = 0\r\nfor i in range(len(s1)):\r\n val = abs(int(s1[i]) - int(s2[i]))\r\n if val > 5:\r\n ad = 10 - (val)\r\n else:\r\n ad = val\r\n count += ad\r\nprint(count)\r\n", "n = int(input())\r\ns1 = str(input())\r\ns2 = str(input())\r\nans = 0\r\ncount = 0\r\nfor i in range(n):\r\n if s1[i] > s2[i]:\r\n ans = int(s1[i]) - int(s2[i])\r\n else:\r\n ans = int(s2[i]) - int(s1[i])\r\n if ans > 5:\r\n ans = 10 - ans\r\n count += ans\r\nprint(count)", "n=int(input())\r\na=input()\r\nb=input()\r\ns=0\r\nfor i in range(n):\r\n x=abs(int(a[i])-int(b[i]))\r\n if x<=5:\r\n s+=x\r\n else:\r\n s+=10-x\r\nprint(s)", "a = int(input())\r\nb = input()\r\nd = input()\r\nt = 0\r\nfor i in range(a):\r\n e = int(b[i])\r\n f = int(d[i])\r\n t += min(abs(e - f), 10 - max(e, f) + min(e, f))\r\nprint(t)", "n = int(input())\r\na = input()\r\nb = input()\r\nk = 0\r\nfor i in range(n):\r\n m = abs(int(a[i]) - int(b[i]))\r\n if m<5:\r\n k+=m\r\n else:\r\n k+=(10-m)\r\nprint(k)", "from sys import stdin\n\ninp = stdin.readlines()\nstart = list(map(int, list(inp[1].strip())))\nend = list(map(int, list(inp[2].strip())))\n# DEBUG\n# print(start, end)\n\ncount = 0\nfor i in range(len(start)):\n if start[i] <= end[i]:\n count += min(abs(start[i] - end[i]), abs(start[i] + 10 - end[i]))\n else:\n count += min(abs(start[i] - end[i]), abs(start[i] - 10 - end[i]))\n # DEBUG\n # print(count)\n\nprint(count)\n", "input()\nprint(sum(min(10 - abs(x - y), abs(x - y)) for x, y in zip(map(int, input()), map(int, input()))))\n", "input()\r\ni=input()\r\nc=input()\r\nm=0\r\nfor r in range(len(i)):\r\n t=abs(int(c[r])-int(i[r]))\r\n m+=min(t,10-t)\r\nprint(m)", "a=int(input())\r\nb=input()\r\nc=input()\r\nsum=0\r\nfor i in range(a):\r\n if abs(int(b[i])-int(c[i]))<=5:\r\n sum+=abs(int(b[i])-int(c[i])) \r\n else:\r\n sum+=(10+int(min(int(b[i]),int(c[i]))))-int(max(int(b[i]),int(c[i])))\r\nprint(sum) ", "def func(n):\n k = list(map(int,input()))\n l = list(map(int,input()))\n counter = 0\n for i in range(n):\n counter += (min(abs(k[i]-l[i]),10-abs(k[i]-l[i])))\n print(counter)\nn = int(input())\nfunc(n)", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\nls1 = list(s1)\r\nls2 = list(s2)\r\nsum1 = 0\r\nfor i in range(len(ls1)):\r\n diff = abs(int(ls1[i]) - int(ls2[i]))\r\n if diff > 5:\r\n diff = 10 - diff\r\n sum1 += diff\r\nprint(sum1)", "disk = int(input())\ncurrent = input()\ngoal = input()\n\nactions = 0\nsequence = \"0123456789\"\n\nfor i in range(disk):\n # if move needed > 5, then there must be a faster way\n moves = abs(int(current[i]) - int(goal[i]))\n if moves > 5:\n moves = 10 - moves\n actions += moves\nprint(actions)", "q = int(input())\r\ns1=input()\r\ns2=input()\r\nres = 0\r\nfor i in range(q):\r\n n = int(s1[i])\r\n n2 = int(s2[i])\r\n res += min(abs(n - n2), 10 - abs(n - n2))\r\nprint(res)\r\n", "s=int(input())\r\na=input()\r\nb=input()\r\nm=0\r\nfor i in range(s):\r\n n=abs(int(a[i])-int(b[i]))\r\n if n>5:\r\n m+=10-n\r\n else:\r\n m+=n\r\nprint(m)", "a = input()\r\nn_random = input()\r\nn_etalon = input()\r\nmove_all = 0\r\n\r\n\r\nfor i in range(len(n_random)):\r\n move_step = abs(int(n_random[i]) - int(n_etalon[i]))\r\n # print(f'{n_random[i]} {n_etalon[i]} {move_step}')\r\n if move_step <= 5:\r\n move_all += move_step\r\n else:\r\n move_all += (10 - move_step)\r\n\r\nprint(int(move_all))", "def back(k,j):\n return abs(abs(k-j)-10)\ndef front(k,j):\n return abs(k-j)\nk = int(input())\na = input()\nb = input()\ns = 0;\nfor i in range(0,len(a)):\n s = s + min(front(int(a[i]),int(b[i])),back(int(a[i]),int(b[i])))\n \nprint(s)\n \t \t\t \t \t\t \t \t \t \t \t\t", "n = int(input())\r\nx = input()\r\ny = input()\r\nc = 0\r\nfor i in range(n):\r\n a = ord(x[i])\r\n b = ord(y[i])\r\n c += min(abs(a - b), a + 10 -b, b + 10 - a)\r\nprint(c)\r\n", "import sys\r\n\r\nif __name__ =='__main__':\r\n n = int(sys.stdin.readline())\r\n org = list(map(int, str(input())))\r\n ans = list(map(int, str(input())))\r\n\r\n move = 0\r\n\r\n for i in range(n):\r\n if org[i] == ans[i]:\r\n continue\r\n elif abs(org[i]-ans[i]) <= 5:\r\n move += abs(org[i]-ans[i])\r\n elif abs(org[i]-ans[i]) >5:\r\n move += (10 - abs(org[i]-ans[i]))\r\n\r\n print(move)", "def driver(n, f, g):\r\n ans = 0\r\n f = [int(z) for z in f]\r\n g = [int(z) for z in g]\r\n for x, y in zip(f, g):\r\n ans += min(abs((x + 1) - (y + 1)), 10 - abs((x + 1) - (y + 1)))\r\n print(ans)\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n f = input()\r\n g = input()\r\n f = list(f)\r\n g = list(g)\r\n driver(n, f, g)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "def main():\n n = int(input())\n l = input()\n k = input()\n t = 0\n\n for i in range(n):\n count = abs(ord(l[i]) - ord(k[i]))\n if count > 5:\n count = 10 - count\n t += count\n\n print(t)\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", "input()\r\na, b = input(), input()\r\ncount = 0\r\nfor i in range(len(a)):\r\n\tcount += min(abs(int(a[i]) - int(b[i])), 10 - abs(int(b[i]) - int(a[i])))\r\nprint(count)\r\n", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nc=0\r\nfor i in range(n):\r\n c+=min(abs(int(s1[i])-int(s2[i])),10-abs(int(s1[i])-int(s2[i])))\r\nprint(c)\r\n \r\n \r\n \r\n \r\n \r\n", "length = int(input())\r\ncode = input()\r\nneeded_code = input()\r\nmoves = 0\r\ni = 0\r\nwhile i<length:\r\n if int(code[i])>int(needed_code[i]) and int(code[i])-int(needed_code[i])<10-int(code[i])+int(needed_code[i]):\r\n moves += int(code[i])-int(needed_code[i])\r\n elif int(code[i])>int(needed_code[i]):\r\n moves +=10-int(code[i])+int(needed_code[i])\r\n elif int(needed_code[i])-int(code[i])<10- int(needed_code[i])+int(code[i]):\r\n moves += int(needed_code[i])-int(code[i])\r\n else:\r\n moves += 10-int(needed_code[i])+int(code[i])\r\n i += 1\r\nprint(moves)\r\n", "\r\nn=list(map(int,input().split()))\r\ns=input()\r\ns1=input()\r\nc=0\r\nfor i,j in zip(s,s1):\r\n c+=min(abs(int(i)-int(j)),10-abs(int(i)-int(j)))\r\nprint(c) \r\n", "elem = int(input())\r\nst = input()\r\nst2 = input()\r\ncount = 0\r\nfor i in range(elem):\r\n t1 = int(st[i])\r\n t2 = int(st2[i])\r\n if t1 == t2:\r\n continue\r\n count = count + min(abs(t1 - t2), min(t1, t2) + (10 - max(t1, t2)))\r\nprint(count)", "n = int(input())\r\noriginal_state = input()\r\ndesired_state = input()\r\nmin_moves = 0\r\nfor i in range(n):\r\n diff = abs(int(original_state[i]) - int(desired_state[i]))\r\n min_moves += min(diff, 10 - diff)\r\nprint(min_moves)", "n = int(input())\r\na = input()\r\nb = input()\r\nans = 0\r\nfor i in range(n):\r\n aa = int(a[i])\r\n bb = int(b[i])\r\n d = abs(aa - bb)\r\n if d <= 5:\r\n ans += d\r\n else:\r\n if aa < bb:\r\n g = 10+aa-bb\r\n ans += g\r\n elif aa > bb:\r\n h = 10+bb-aa\r\n ans += h\r\nprint(ans)", "n=int(input())\r\ns=input()\r\nr=input()\r\nc=0\r\nfor i in range(n):\r\n d=abs(int(s[i])-int(r[i]))\r\n if d<=5:\r\n c+=d\r\n else:\r\n c+=10-d\r\nprint(c)", "n = int(input())\r\na = list(map(int,input()))\r\nb = list(map(int,input()))\r\ncount = 0;\r\nfor i in range (0,n):\r\n x = a[i];\r\n y = b[i];\r\n s = abs(a[i]-b[i]);\r\n p = 9 - max(a[i],b[i]) + min(a[i],b[i]) +1;\r\n if (s>p):\r\n count = count +p;\r\n else:\r\n count = count +s;\r\nprint(count);", "n, r, f = int(input()), input(), input()\r\n\r\nmove = 0\r\nfor i in range(n):\r\n d = abs(int(r[i]) - int(f[i]))\r\n if d > 5:\r\n d = 10 - d\r\n move += d\r\nprint(move)", "n=int(input())\r\ns=input()\r\np=input()\r\ncount=0\r\nfor i in range(n):\r\n if(abs(int(s[i])-int(p[i])))<=5:\r\n count+=abs(int(s[i])-int(p[i]))\r\n else:\r\n count+=10-abs(int(s[i])-int(p[i]))\r\nprint(count)", "n=int(input())\r\ns=input()\r\nd=input()\r\nc=0\r\nfor x,y in zip(s,d):\r\n c+=min(abs(int(x)-int(y)),9-max(int(x),int(y))+min(int(x),int(y))+1)\r\nprint(c)\r\n ", "from sys import stdin\r\n_input = stdin.readline\r\n_max, _int, _str, _min, _range, _abs = max, int, str, min, range, abs\r\ndef solution():\r\n n = _int(_input())\r\n current = _input().rstrip('\\n')\r\n nead = _input().rstrip('\\n')\r\n ans = 0\r\n for i in _range(n):\r\n a = _int(current[i])\r\n b = _int(nead[i])\r\n ans += _min(_abs(a-b), _abs(_min(a,b)+10 - _max(a, b)))\r\n print(ans)\r\nsolution()", "import sys\r\n\r\ninput = sys.stdin.readline\r\noutput = sys.stdout.write\r\n\r\n\r\ndef main():\r\n length_ = int(input().rstrip())\r\n num1 = input().rstrip()\r\n num2 = input().rstrip()\r\n summ = 0\r\n for _ in range(length_):\r\n r = abs(int(num1[_]) - int(num2[_]))\r\n o = r % 10\r\n if o > 5:\r\n o = 10 - o\r\n summ += o\r\n output(str(summ))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n\r\n\r\n", "n = int(input())\r\ncurrent = input()\r\ndesired = input()\r\nsum_ = 0\r\nfor i in range(n):\r\n c = int(current[i])\r\n d = int(desired[i])\r\n# print(c,d)\r\n direct_dist = abs(c-d)\r\n \r\n if c < d:\r\n c = c + 10\r\n else:\r\n d = d + 10\r\n \r\n indirect_dist = abs(c-d)\r\n \r\n if direct_dist < indirect_dist:\r\n sum_ = sum_ + direct_dist\r\n# print(direct_dist,\"d\")\r\n else:\r\n sum_ = sum_ + indirect_dist\r\n# print(direct_dist,\"i\")\r\n\r\n \r\n \r\nprint(sum_)", "def main():\r\n disks = int(input())\r\n state = [int(x) for x in input()]\r\n combination = [int(x) for x in input()]\r\n\r\n moves = 0\r\n\r\n for i in range(disks):\r\n s = state[i]\r\n c = combination[i]\r\n\r\n bigger = max(s, c)\r\n smaller = min(s, c)\r\n\r\n move = (bigger - smaller)\r\n if (move > 5):\r\n move = 10 - bigger + smaller\r\n\r\n moves = moves + move\r\n\r\n print(moves)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n = int(input())\r\na = list(input().strip())\r\nb = list(input().strip())\r\nans = 0\r\nfor i in range(len(a)):\r\n num1 = int(a[i])\r\n num2 = int(b[i]) \r\n if num1 > num2:num1, num2 = num2, num1\r\n ans += min(num2 - num1, 9 - num2 + num1 + 1)\r\nprint(ans)", "n=int(input())\r\ns=input()\r\nl=input()\r\np=0\r\nfor i in range(n):\r\n p=p+min(abs(int(s[i])-int(l[i])),10-abs(int(s[i])-int(l[i])))\r\nprint(p)", "import string\r\n\r\n\r\ndef turn_to_list(s):\r\n output_list = []\r\n for i in s:\r\n output_list.append(i)\r\n return output_list\r\n\r\ndef shortest_path(a, b, l):\r\n index_a = l.index(a)\r\n index_b = l.index(b)\r\n path_1 = abs(index_b - index_a)\r\n if index_b > index_a:\r\n path_2 = len(l) - index_b + index_a\r\n else:\r\n path_2 = len(l) - index_a + index_b\r\n if path_1 > path_2:\r\n return path_2\r\n else:\r\n return path_1\r\n\r\n\r\n\r\n\r\ndef main_function():\r\n lists = [\"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"]\r\n a = input()\r\n b = input()\r\n c = input()\r\n total_move = 0\r\n for loc in range(len(b)):\r\n total_move += shortest_path(b[loc], c[loc], lists)\r\n return total_move\r\n\r\n\r\nprint(main_function())", "n=int(input())\r\ns=input()\r\nd=input()\r\nk=0\r\nfor i in range(n):\r\n\tk+=min(abs(int(s[i])-int(d[i])),10-abs(int(s[i])-int(d[i])))\r\nprint(k)", "n1=int(input())\r\nn=input()\r\nm=input()\r\nl,sum=[],0\r\nfor i in range(n1):\r\n if n[i]>m[i]:\r\n l.append(int(n[i])-int(m[i]))\r\n else:\r\n l.append(int(m[i])-int(n[i]))\r\nfor i in range(len(l)):\r\n if l[i]>5:\r\n sum+=(10-l[i])\r\n else:\r\n sum+=l[i]\r\nprint(sum)", "# https://codeforces.com/problemset/problem/540/A\r\n\r\ninput()\r\na = input().strip()\r\nb = input().strip()\r\nres = 0\r\nfor i in range(len(a)):\r\n k = int(a[i])\r\n z = int(b[i])\r\n res += min(abs(k-z), 10 - abs(k-z))\r\nprint(res)", "l=int(input())\r\ncur=input()\r\npas=input()\r\ni=0\r\nsum=0\r\nwhile(i<l):\r\n if(abs(int(cur[i])-int(pas[i]))<=5):\r\n sum=sum+abs(int(cur[i])-int(pas[i]))\r\n else:\r\n m=min(int(cur[i]),int(pas[i]))+10\r\n sum=sum+(m-max(int(cur[i]),int(pas[i])))\r\n i+=1\r\nprint(sum)\r\n", "n=int(input())\r\nnow=str(input())\r\nright=str(input())\r\ncount=0\r\nfor i in range(n):\r\n a=int(now[i])\r\n b=int(right[i])\r\n num1=abs(a-b)\r\n num2=10-num1\r\n count=count+min(num1,num2)\r\nprint(count)", "l1=[]\r\nl2=[]\r\nc=0\r\nn=int(input())\r\nx=int(input())\r\ny=int(input())\r\nwhile (x!=0):\r\n l1.append((x%10))\r\n x=x//10\r\nif len(l1)!=n:\r\n l1.append(0)\r\nwhile (y!=0):\r\n l2.append((y%10))\r\n y=y//10\r\nif len(l2)!=n:\r\n l2.append(0)\r\nfor i in range(n):\r\n p=l1[i]\r\n for j in range(n):\r\n if i==j:\r\n q=l2[i]\r\n a=abs (p-q)\r\n b=10-abs(q-p)\r\n c+=min(a,b)\r\nprint(c)\r\n", "n = int(input())\r\nst = input()\r\nen = input()\r\ncnt = 0\r\nfor i in range(n):\r\n _a = int(st[i])\r\n _b = int(en[i])\r\n mn = min(_a, _b)\r\n mx = max(_a, _b)\r\n a = (10 + mn) - mx\r\n b = abs(mx - mn)\r\n cnt += min(a, b)\r\n\r\nprint(cnt)\r\n\r\n\r\n", "n=10\r\nx=int(input())\r\ns=input()\r\ns1=input()\r\nt=0\r\nfor i in range(0,x):\r\n temp=int(s[i])-int(s1[i])\r\n if temp<0:\r\n temp=-temp\r\n if temp>(n//2):\r\n temp=n-temp\r\n t+=temp\r\nprint(t)\r\n", "n=int(input())\r\ncnt=0\r\ns1=input()\r\ns2=input()\r\nfor i in range(n):\r\n a,b=int(s1[i]),int(s2[i])\r\n cnt+=min(abs(a-b),10-abs(a-b))\r\nprint(cnt)", "# A. Combination Lock\r\nn = int(input())\r\ntotal = 0\r\noriginal = input()\r\ntarget = input()\r\nfor i in range(0, n):\r\n total += min(10 - abs(int(original[i]) - int(target[i])), abs(int(original[i]) - int(target[i])))\r\nprint(total)\r\n", "d = 0\r\na = int(input())\r\nb = input()\r\nc = input()\r\nfor i in range(a):\r\n e = abs(int(b[i])-int(c[i]))\r\n if e <= 5:\r\n d = d + e\r\n else:\r\n d = d + (10-e)\r\nprint(d) ", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nc=0\r\nfor i in range(n):\r\n c=c+ min(abs(int(s1[i])-int(s2[i])), (9-max(int(s1[i]),int(s2[i]))+min(int(s1[i]),int(s2[i]))+1))\r\nprint(c)\r\n", "n = int(input())\r\na = input()\r\nb = input()\r\nres = 0\r\nfor i in range(n):\r\n\tres += min(abs(int(a[i]) - int(b[i])), 10 + int(a[i]) - int(b[i]), 10 + int(b[i]) - int(a[i]))\r\n\t# print(min(abs(int(a[i]) - int(b[i])), 10 + int(a[i]) - int(b[i]), 10 + int(b[i]) - int(a[i])))\r\nprint(res)", "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\nfrom collections import deque\r\nimport copy\r\nfrom itertools import permutations\r\nfrom operator import itemgetter\r\nmod=pow(10,9)+7\r\n#a= list(map(int, input(\"\").strip().split()))[:n]\r\n'''\r\ndef solve(n,m,k):\r\n\r\n \r\n \r\nt=int(input(\"\"))\r\nfor _ in range(t):\r\n n,m,k=list(map(int, input(\"\").strip().split()))[:3]\r\n solve(n,m,k)\r\n'''\r\ndef solve(a,b):\r\n d=[i for i in range(10)]\r\n d=d+d\r\n c=0\r\n for i,j in zip(a,b):\r\n m=d.index(j)\r\n n=len(d)-1-d[::-1].index(j)\r\n k=d.index(i)\r\n l=len(d)-1-d[::-1].index(i)\r\n c+=min(abs(k-m),abs(k-n),abs(l-m),abs(l-n))\r\n print(c)\r\nn=input(\"\")\r\na=list(map(int,input(\"\").strip()))\r\nb=list(map(int,input(\"\").strip()))\r\nsolve(a,b)\r\n", "n = int(input())\r\na = int(input())\r\nb = int(input())\r\nOTBET = 0\r\nfor i in range(n):\r\n OTBET += min(abs(a % 10 - b % 10), min(a % 10, b % 10) + 10 - max(a % 10, b % 10))\r\n a = a // 10\r\n b = b // 10\r\nprint(OTBET)", "n=int(input())\r\nk=0\r\ns=list(map(int,input()))\r\np=list(map(int,input()))\r\nfor i in range(n):\r\n k+=min(abs(s[i]-p[i]),10-max(s[i],p[i])+min(s[i],p[i]))\r\nprint(k) ", "n=int(input())\nx=list(input())\ny=list(input())\nans=0\nfor i in range(n):\n a,b=min(int(x[i]),int(y[i])),max(int(x[i]),int(y[i]))\n ans=ans+min(b-a,10-b+a)\nprint(ans)\n \n", "\r\ndef solve():\r\n n=int(input())\r\n s=input()\r\n ss=input()\r\n c=0\r\n for i in range(n):\r\n a,b=int(s[i]),int(ss[i])\r\n c+=min(abs(a-b),10-abs(a-b))\r\n\r\n print(c)\r\n\r\nsolve()\r\n", "l = int(input())\r\ns = list(map(int,list(input())))\r\nn = list(map(int,list(input())))\r\nans = 0\r\nfor i in range(l):\r\n ans+= min(abs(s[i]-n[i]),10-abs(s[i]-n[i]))\r\nprint(ans)\r\n", "n = int(input())\r\na, b = input(), input()\r\ncount = 0\r\nfor i in range(n):\r\n q = abs(int(a[i])-int(b[i]))\r\n count += q*(q<=5) + (10-q)*(q>5)\r\nprint(count)", "n = int(input())\r\nlock = str(input())\r\nunlock = str(input())\r\n\r\ntotal_comb = 0\r\n\r\nfor i in range(0,n):\r\n\ta = int(lock[i])\r\n\tb = int(unlock[i])\r\n\r\n\td1 = abs(a - b)\r\n\td2 = 10 - max(a,b) + min(a,b)\r\n\r\n\ttotal_comb += min(d1,d2)\r\n\r\nprint(total_comb)", "#By Anan instagram: anan.ssw\r\nn=int(input())\r\nold=input()\r\nnew=input()\r\nans=0\r\nfor x in range(n):\r\n mn=min(int(old[x]),int(new[x]))\r\n mx=max(int(old[x]),int(new[x]))\r\n ans+=min(mx-mn,mn+10-mx)\r\nprint(ans)", "n = int(input())\r\ns1=input()\r\ns2=input()\r\nmoves=0\r\nfor x in range(n):\r\n\tdifference=abs(int(s1[x])-int(s2[x]))\r\n\tif difference<=5:\r\n\t\tmoves = moves + difference\r\n\telse:\r\n\t\tmoves = moves + 10 - difference\r\nprint(moves)", "\r\nlen_string = int(input())\r\nstring1 = input()\r\nstring2 = input()\r\ncount = 0\r\nfor i in range(len_string):\r\n res = abs(int(string1[i])-int(string2[i]))\r\n count += min(res, 10-res)\r\nprint(count)\r\n", "n=int(input())\r\nli=list(input())\r\nli1=list(input())\r\nc=0\r\nfor i in range(0,n):\r\n a=int(li[i])\r\n b=int(li1[i])\r\n k=abs(a-b)\r\n if k>5:\r\n c=c+(10-k)\r\n else:\r\n c=c+k\r\n #print(c)\r\nprint(c)\r\n", "input()\r\na=[int(i) for i in input()]\r\nb=[int(i) for i in input()]\r\nc=0\r\nfor i in range(len(a)):\r\n\tmn=min(abs(a[i]-b[i]),10-abs(a[i]-b[i]))\r\n\tc+=mn\r\nprint(c)", "n=input()\r\ns1=list(map(int,list(input())))\r\ns2=list(map(int,list(input())))\r\ns=zip(s1,s2)\r\nprint(sum(min(d:=abs(a-b),10-d)for a,b in s))", "length = input()\r\nfirst = input()\r\nsecond = input()\r\nmoves = 0\r\ni = 0\r\nfor i in range(int(length)):\r\n temp_diff = abs(int(first[i]) - int(second[i]))\r\n if temp_diff >= 5:\r\n moves += 10-temp_diff\r\n else:\r\n moves += temp_diff\r\nprint(moves)\r\n", "n = int(input())\r\n\r\na = list(input())\r\nb = list(input())\r\n\r\ncount = 0\r\nfor i in range(n):\r\n z = abs(int(a[i]) - int(b[i]))\r\n z = min(z, 10-z)\r\n count+=z\r\n \r\nprint(count)", "\r\nn = int(input())\r\na = input()\r\nb = input()\r\ncount = 0\r\nfor i in range(len(a)):\r\n n1 = int(a[i])\r\n n2 = int(b[i])\r\n P = n1 - n2\r\n P = abs(P)\r\n P = int(P)\r\n if P > 4:\r\n count += 9 - P + 1\r\n else:\r\n count += P\r\nprint(count)\r\n", "# Pradnyesh Choudhari\r\n# Sat Jul 18 22:08:27 2020\r\n\r\nn = int(input())\r\nlock = input()\r\nanswer = input()\r\nl = []\r\nfor _ in range(n):\r\n diff = abs(int(answer[_])-int(lock[_]))\r\n if diff>5:\r\n diff -= 10\r\n l.append(abs(diff))\r\nprint(sum(l))\r\n\r\n\r\n", "def solve(disks, original_state, code):\n moves = 0\n\n for i in range(disks):\n if abs(original_state[i] - code[i]) > 5:\n moves += 10 - abs(original_state[i] - code[i])\n else:\n moves += abs(original_state[i] - code[i])\n\n return moves\n\n\nn = int(input())\no = list(map(int, input()))\nc = list(map(int, input()))\nprint(solve(n, o, c))\n", "input()\r\ns1=input()\r\ns2=input()\r\ns=0\r\nfor a,b in zip(s1,s2):\r\n i=int(a)\r\n j=int(b)\r\n s+=min(abs(i-j),abs(9-j)+i+1,abs(9-i)+j+1)\r\nprint(s)", "n = int(input())\n\na = input()\nb = input()\n\nans = 0\nfor i in range(n):\n diff = abs(int(a[i]) - int(b[i]))\n if diff > 5:\n diff = 10 - diff\n ans += diff\nprint(ans)\n", "n=int(input())\r\ns1=input()\r\ns2=input()\r\ns=0\r\nfor i in range(n):\r\n s=s+min(abs(int(s1[i])-int(s2[i])),min(int(s1[i]),10-int(s1[i]))+min(int(s2[i]),10-int(s2[i])));\r\nprint(s)", "n = int(input())\n\ndigs1 = list(map(int, list(input())))\ndigs2 = list(map(int, list(input())))\nmoves = 0\n\nfor i in range(n) :\n digit1 = digs1[i]\n digit2 = digs2[i]\n\n way1 = max(digit1, digit2) - min(digit1, digit2)\n way2 = min(digit1, digit2) + 10 - max(digit1, digit2)\n minmove = min(way1, way2)\n moves += minmove\n\nprint(moves)\n\n \t \t \t\t \t\t\t\t\t \t\t \t\t", "input()\n\na = input()\nb = input()\n\nturns = 0\n\nfor i in range(len(a)):\n t = abs(int(a[i]) - int(b[i]))\n turns += min(t, 10 - t)\n\nprint(turns)\n \t\t \t\t\t \t\t \t\t\t \t\t \t \t \t", "n=int(input())\r\nx=input()\r\nans=input()\r\nanswer=0\r\nb=0 \r\nc=0\r\nfor i in range(0,n):\r\n\tif abs(int(x[i])-int(ans[i]))<=5:\r\n\t\tanswer=answer+abs(int(x[i])-int(ans[i]))\r\n\telse:\r\n\t\ta=10-(abs(int(x[i])-int(ans[i])))\r\n\t\tanswer=answer+a\r\n\t\r\n\r\nprint(answer)\r\n\r\n\r\n\r\n\r\n", "a = int(input())\r\nb = input()\r\nc = input()\r\nd = 0\r\nfor i in range(a):\r\n\td += min(abs(int(b[i])-int(c[i])), 10 - abs(int(b[i])-int(c[i])))\r\nprint(d)", "n = int(input())\norig = input()\ncode = input()\nans = 0\n\nfor i in range(n):\n dif = abs(int(orig[i]) - int(code[i]))\n ans += min(dif, (9 - dif + 1))\n\nprint(ans)", "n=int(input())\r\n\r\npos=list(input())\r\ndes=list(input())\r\nd={6:4,7:3,8:2,9:1}\r\n\r\nans=0\r\n\r\nfor i in range(n):\r\n a=int(pos[i])\r\n b=int(des[i])\r\n k=abs(b-a)\r\n if k in d.keys():\r\n ans+=d[k]\r\n else:\r\n ans+=k\r\nprint(ans)\r\n\r\n", "n = int(input())\nstart = [int(d) for d in list(input())]\ntarget = [int(d) for d in list(input())]\n\ncounter = 0\nfor i in range(n):\n counter += min(\n max(start[i], target[i]) - min(start[i], target[i]),\n (10 - max(start[i], target[i])) + min(start[i], target[i])\n )\nprint(counter)\n", "\r\n# num = int(input())\r\n# arr =[]\r\n# for i in range(num):\r\n# a = input()\r\n# arr.insert(0,a)\r\n# for i in arr:\r\n# print(i)\r\n#\r\n\r\n# a= int(input())\r\n# magnet = []\r\n# for i in range(a):\r\n# c= input()\r\n# magnet.append(c)\r\n# count=1\r\n# base = magnet[0]\r\n# for i in magnet:\r\n#\r\n# if i== base:\r\n# pass\r\n# else:\r\n# count+=1\r\n# base = i\r\n# print(count)\r\n\r\na = int(input())\r\n\r\npresent = input()\r\nkey = input()\r\nfans = 0\r\nfor i in range(a):\r\n r = abs(int(present[i])-int(key[i]))\r\n if r< 5:\r\n ans= r\r\n else:\r\n ans = 10-r\r\n fans += ans\r\nprint(fans)\r\n\r\n5\r\n82195\r\n64723", "n = int(input()) # no. of disks\ninitial = input() # initial combn.\nfinal = input() # password\n\nmoves = 0\n\nfor i in range(n):\n start = int(initial[i]) \n end = int(final[i])\n if abs(start - end) > 5: moves += 10 - abs(start - end)\n else: moves += abs(start - end)\n\nprint(moves)\n\t\t \t\t\t \t\t\t \t\t \t\t \t\t\t\t\t\t", "n = int(input())\nbad_cod = int(input())\ncod = int(input())\ncount = 0\nfor i in range(n):\n if abs(bad_cod % 10 - cod % 10) <= 5:\n count = count + abs(bad_cod % 10 - cod % 10)\n else:\n count = count + (10 - abs(bad_cod % 10 - cod % 10))\n bad_cod = bad_cod // 10\n cod = cod // 10\nprint(count)", "\r\nx=int(input())\r\ny=input()\r\nz=input()\r\ns=0\r\nfor i in range(x):\r\n\ta=abs(int(y[i])-int(z[i])) \r\n\tb=10-a\r\n\ts+=(min(a,b))\r\nprint(s)", "n = input()\r\ns1 = input()\r\ns2 = input()\r\n\r\nact = 0\r\n\r\nfor i in range(len(s1)):\r\n j = int(s1[i])\r\n j2 = int(s2[i])\r\n new = min(abs(j - j2), 10 - j + j2, j + 10 - j2)\r\n act += new\r\n\r\nprint(act)", "n = int(input())\r\ncur = input()\r\nneed = input()\r\ncnt = 0\r\nfor i in range(n):\r\n a = int(cur[i])\r\n b = int(need[i])\r\n cnt += min((a-b+10)%10, (b-a+10)%10)\r\nprint(cnt)", "n=int(input())\r\nl1=input();l1=[int(d) for d in str(l1)]\r\nl2=input();l2= [int(e) for e in str(l2)]\r\ns=0\r\nfor i in range(n):\r\n s+=min(abs(l1[i]-l2[i]),10-abs(l1[i]-l2[i]))\r\nprint(s)\r\n", "n = int(input())\r\ns = input()\r\nk=0\r\ns1 = input()\r\nfor i in range(n):\r\n if max(int(s[i]),int(s1[i]))-min(int(s1[i]),int(s[i]))<=min(int(s1[i]),int(s[i]))+10-max(int(s1[i]),int(s[i])):\r\n k+=max(int(s[i]),int(s1[i]))-min(int(s1[i]),int(s[i]))\r\n else:\r\n k+=min(int(s1[i]),int(s[i]))+10-max(int(s1[i]),int(s[i]))\r\nprint(k)\r\n", "n=int(input())\r\ns=input()\r\nl=input()\r\nk=0\r\nfor i in range(n):\r\n k+=min(abs(int(l[i])-int(s[i])),10-abs(int(l[i])-int(s[i])))\r\nprint(k)", "n=int(input())\r\noriginal=input()\r\ncomb=input()\r\ns=0\r\nfor i in range(n):\r\n x=int(original[i])\r\n y=int(comb[i])\r\n if x<y:\r\n a=y-x\r\n b=9-y+x+1\r\n s+=min(a,b)\r\n elif y<x:\r\n a=x-y\r\n b=9-x+y+1\r\n s+=min(a,b)\r\n else:\r\n s+=0\r\nprint(s)", "n=int(input())\r\nk=input()\r\nj=input()\r\nsum=0\r\np=0\r\nfor i in range(n):\r\n\tsum=abs(int(k[i])-int(j[i]))\r\n\tif sum>5:\r\n\t\tsum=10-sum\r\n\tp+=sum\t\r\nprint(p)\t\r\n", "n=int(input())\r\na=(input())\r\nb=(input())\r\nsum=0\r\nfor i in range(0,n):\r\n sum += min(min(abs( int(a[i]) - int(b[i])), abs(10 + int(a[i]) - int(b[i]))), abs(10 + int(b[i]) - int(a[i])))\r\nprint(sum)\r\n", "n = input()\r\nori = input()\r\ncomb = input()\r\nmoves = 0\r\nfor j,i in enumerate(ori):\r\n num1 = int(i)\r\n num2 = int(comb[j])\r\n moves += min(abs(num1-num2), abs(num1+10-num2), abs(num1-num2-10))\r\nprint(moves)", "n, res = int(input()), 0\r\none, two = input(), input()\r\nfor j, c in enumerate(one):\r\n a = abs(int(c) - int(two[j]))\r\n res += min(a, 10 - a)\r\nprint(res)", "n=int(input())\r\ns1=input()\r\na=[int(i) for i in s1]\r\ns2=input()\r\nb=[int(i) for i in s2]\r\nsum=0\r\nfor i in range(len(a)):\r\n ans1=abs(a[i]-b[i])\r\n c=max(a[i],b[i])\r\n d=min(a[i],b[i])\r\n ans2=9-c+d+1\r\n sum=sum+min(ans1,ans2)\r\nprint(sum) ", "n = 0\ninitial_config = []\ngoal_config = []\n\n\ndef read_input():\n global n, initial_config, goal_config\n n = int(input())\n initial_config = [int(i) for i in input()]\n goal_config = [int(i) for i in input()]\n\n\ndef solve():\n total_moves = 0\n\n for i in range(n):\n smaller_digit = min(initial_config[i], goal_config[i])\n bigger_digit = max(initial_config[i], goal_config[i])\n\n a = smaller_digit + 9 - bigger_digit + 1\n b = bigger_digit - smaller_digit\n\n # print(\"a =\", a)\n # print(\"b =\", b)\n\n total_moves = total_moves + min(a, b)\n # print(\"total_moves =\", total_moves)\n\n return total_moves\n\n\nread_input()\nprint(solve())\n", "n=int(input())\noriginal=input()\ncorrect=input()\nsum=0\nfor i in range(n):\n diff1=abs(int(original[i])-int(correct[i]))\n diff2=abs((10+int(original[i]))-int(correct[i]))\n diff3=abs((10+int(correct[i]))-int(original[i]))\n sum+=min([diff1,diff2,diff3])\n \nprint(sum) \n\n \t\t \t \t\t\t \t \t \t \t \t", "a=int(input())\r\nb=input()\r\nc=input()\r\ncount=0\r\nfor i in range(a):\r\n p=int(b[i])\r\n v=int(c[i])\r\n if max(p,v)-min(p,v)>min(p,v)+10-max(p,v):\r\n count+=min(p,v)+10-max(p,v)\r\n else:\r\n count+=max(p,v)-min(p,v)\r\nprint(count)\r\n", "n = int(input())\r\nx = input()\r\ny = input()\r\nc = 0\r\nfor i in range(n):\r\n c+=min(abs(int(x[i])-int(y[i])),abs(10-max(int(x[i]),int(y[i])))+min(int(x[i]),int(y[i])))\r\nprint(c)", "n = int(input())\r\na = list(map(int, input().split()[0]))\r\nb = list(map(int, input().split()[0]))\r\nsum = 0\r\nfor i in range(n):\r\n sum += min(10-abs(a[i]-b[i]), abs(a[i]-b[i]))\r\nprint(sum)\r\n", "n = int(input())\r\ns = input()\r\nkey = input()\r\nres = 0\r\nfor i in range(len(s)):\r\n if abs(int(key[i]) - int(s[i])) < 5:\r\n res += abs(int(key[i]) - int(s[i]))\r\n else:\r\n if int(key[i]) > int(s[i]):\r\n res += int(s[i]) + (9 - int(key[i])) + 1\r\n else:\r\n res += int(key[i]) + (9 - int(s[i])) + 1\r\nprint(res)\r\n", "n = int(input())\r\noriginal_comb = input()\r\nscrooge_comb = input()\r\nres = 0\r\nfor i in range(n):\r\n difference = abs(int(original_comb[i])-int(scrooge_comb[i]))\r\n if difference >5:\r\n res = res + 10-difference\r\n else:\r\n res = res + difference\r\n\r\nprint(res)\r\n", "n=int(input())\r\na=[int(i) for i in list(input())]\r\nb=[int(i) for i in list(input())]\r\nans=0\r\nfor i in range(n):\r\n\tm=max(a[i],b[i])-min(a[i],b[i])\r\n\tans+=min(m,10-m)\r\nprint(ans)", "t=int(input())\r\nn=input()\r\nn1=input()\r\ns=0\r\nfor i in range(t):\r\n s+=min(abs(int(n[i])-int(n1[i])),(10-abs(int(n[i])-int(n1[i]))))\r\nprint(s)", "n=int(input())\r\ns=list(input())\r\ns1=list(input())\r\nsum=0\r\nfor i in range(n):\r\n sum+=min(abs(int(s[i])-int(s1[i])),10-abs((int(s[i]))-int(s1[i])))\r\nprint(sum)\r\n", "n=int(input())\r\nstr1=input()\r\nstr2=input()\r\nk,d=0,0\r\nfor i in range(0,n):\r\n d = abs(int(str1[i])-int(str2[i]))\r\n if d>5:\r\n k+=(10-d)\r\n else:\r\n k+=d\r\nprint(k)", "n = int(input())\r\nstart_combination = input()\r\ncombination_lock = input()\r\ncount = 0\r\nfor i in range(n):\r\n differ = abs(int(start_combination[i]) - int(combination_lock[i]))\r\n if differ <= 5:\r\n count += differ\r\n else:\r\n count += 10 - differ\r\nprint(count)\r\n", "def min_moves_to_open_lock(n, original, combination):\n total_moves = 0\n\n for i in range(n):\n diff = abs(int(original[i]) - int(combination[i]))\n total_moves += min(diff, 10 - diff)\n\n return total_moves\n\nn = int(input())\noriginal = input().strip()\ncombination = input().strip()\n\nresult = min_moves_to_open_lock(n, original, combination)\nprint(result)\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\nc=input()\r\nl=input()\r\nmoves=0\r\nfor i in range(n):\r\n f=abs(int(c[i])-int(l[i]))\r\n s=abs(10-f)\r\n moves+=min(f,s)\r\nprint(moves)", "f = lambda: list(map(int, list(input())))\r\nn, o = int(input()), 0\r\na, b = f(), f()\r\nwhile n:\r\n\tn-=1\r\n\tk = abs(a[n]-b[n])\r\n\to += min(k, 10-k)\r\nprint(o)", "def rotate_disk(a:int, b:int):\r\n if a >= b:\r\n pochti_otvet = a - b\r\n else:\r\n pochti_otvet = (a - b) * -1\r\n if pochti_otvet > 5:\r\n return 10 - pochti_otvet\r\n else:\r\n return pochti_otvet\r\n\r\n\r\nus = input()\r\ntek = input()\r\ncod = input()\r\nrotate_all = 0\r\nfor i in range(int(us)):\r\n rotate_all += rotate_disk(int(tek[i]),int(cod[i]))\r\nprint(rotate_all)\r\n", "def main():\r\n input()\r\n a = list(map(int,list(input())))\r\n b = list(map(int,list(input())))\r\n zipped = zip(a,b)\r\n output = 0\r\n for i in zipped:\r\n diff = abs(i[0]-i[1])\r\n if diff > 5:\r\n output += 10 - diff\r\n else:\r\n output += diff\r\n print(output)\r\n\r\nmain()", "\r\n\r\n\r\n\r\nn = int(input())\r\n\r\nlock= input()\r\ncombo = input()\r\n\r\nmoves = 0\r\n#for each disk\r\nfor i in range(n):\r\n\r\n#compare first value of each\r\n\r\n#a better way\r\n\tlocki = int(lock[i])\r\n\tcomboi = int(combo[i])\r\n\r\n\tbetween = abs(locki - comboi)\r\n\tminmoves = min(between, 10 - between)\r\n\tmoves += minmoves\r\n\r\nprint(moves)\r\n\r\n\"\"\"\t\r\n\tlocki = int(lock[i])\r\n\tcomboi = int(combo[i])\r\n\t#first see if the lock value is closer to 0 or 10\r\n\tlockmin = min(abs(locki - 0), abs(locki - 10))\r\n\t#then check the combo value\r\n\tcombomin = min(abs(comboi - 0), abs(comboi - 10))\r\n\t#then check if the sums of those moves \r\n\t#are smaller than moving towards eachother without passing 0\r\n\tminmoves = min(lockmin + combomin, abs(locki - comboi))\r\n\t#add the moves for each disk\r\n\tmoves += minmoves\r\nprint(moves)\r\n\t\"\"\"\r\n\r\n\r\n", "n,s,k,r=int(input()),input(),input(),0\r\nfor i in range(n):\r\n q,w=int(s[i]),int(k[i])\r\n o=abs(q-w)\r\n r+=min(o,10-o)\r\nprint(r)", "n = int(input())\r\noriginal_state = input()\r\ncombination = input()\r\n\r\nactions = 0\r\nfor i in range(n):\r\n actions += min(abs(int(original_state[i]) - int(combination[i])),\r\n 10 - abs(int(original_state[i]) - int(combination[i])))\r\n\r\nprint(actions)", "\r\n\r\nimport math\r\nimport os\r\nimport random\r\nimport re\r\nimport sys\r\n\r\na = int(input())\r\nb = str(input())\r\nv = str(input())\r\nl1 = []\r\nl2 = []\r\nfor x in range(a):\r\n l1.append(int(b[x]))\r\n l2.append(int(v[x]))\r\nc = 0\r\nfor y in range(a):\r\n if abs(l1[y]-l2[y])>5:\r\n c = c + 10 - abs(l1[y]-l2[y])\r\n else:\r\n c = c + abs(l1[y]-l2[y])\r\nprint(c)", "n = int(input())\na = [int(i) for i in list(input())]\nb = [int(i) for i in list(input())]\ncount = 0\nfor i in range(n):\n count += min(abs(a[i]-b[i]), 10 - abs(a[i]-b[i]))\nprint(count)\n", "n=int(input())\r\nx=input()\r\ny=input()\r\nx=list(x)\r\ny=list(y)\r\nd=0\r\np=0\r\nfor i in range(n):\r\n d=abs(int(x[i])-int(y[i]))\r\n if(d>5):\r\n d=10-d\r\n p=p+d\r\nprint(p)\r\n", "n=int(input())\r\na=input()\r\nb=input()\r\na=list(a)\r\nb=list(b)\r\ns=0\r\nfor i in range(0,n):\r\n if (abs(int(a[i])-int(b[i]))>5):\r\n s=s+abs(9-(abs(int(a[i])-int(b[i])))+1)\r\n else:\r\n s=s+abs(int(a[i])-int(b[i]))\r\nprint(s)", "n=int(input())\r\ns1=input()\r\ns2=input()\r\ns=0\r\nfor i in range(n):\r\n x=min(abs(int(s1[i])-int(s2[i])),10-max(int(s2[i]),int(s1[i]))+min(int(s2[i]),int(s1[i])))\r\n s=s+x\r\nprint(s)\r\n \r\n", "n=int(input())\r\ninitial=input()\r\nfinal=input()\r\ncount=0\r\nfor i in range(n):\r\n if initial[i]>final[i]:\r\n count+=min(abs(int(initial[i])-int(final[i])),(9-int(initial[i])+int(final[i])+1))\r\n else:\r\n count+=min(abs(int(final[i])-int(initial[i])),(9-int(final[i])+int(initial[i])+1))\r\nprint(count)", "# coding: utf-8\r\n\r\nn = int(input())\r\noriginal = input()\r\ncombination = input()\r\nmoves = 0\r\n\r\nfor i in range(n):\r\n difference = abs(ord(original[i]) - ord(combination[i]))\r\n moves += min(difference, 10 - difference)\r\n \r\nprint(moves)", "if __name__ == '__main__':\n n = int(input())\n x = input()\n y = input()\n moves = 0\n for i in range(n):\n a = int(x[i])\n b = int(y[i])\n moves += min(abs(a - b), 10 - abs(a - b))\n\n print(moves)", "n = int(input())\ns1 = [int(x) for x in input()]\ns2 = [int(x) for x in input()]\ncnt = 0\nfor i in range(n):\n d = abs(s1[i] - s2[i])\n if d > 5:\n d = (min(s1[i], s2[i]) + 10) - max(s1[i], s2[i])\n cnt += d\nprint(cnt)\n\t \t \t \t\t \t \t\t\t \t\t \t", "# t = int(input())\nt = 1\n# # n, m = map(int, input().split())\n# # a = list(map(int, input().split()))\n# # a.sort()\nimport math\nfrom collections import Counter\nimport random\n\nwhile t != 0:\n n = int(input())\n s1 = input()\n s2 = input()\n ans = 0\n for i in range(len(s1)):\n ans += min(abs(int(s1[i]) - int(s2[i])), 10 - abs(int(s1[i]) - int(s2[i])))\n print(ans)\n t -= 1\n", "a=int(input())\r\n\r\nb=input()\r\nc=input()\r\n\r\nd=0\r\n\r\nfor i in range(a):\r\n d+=min(abs(int(b[i])-int(c[i])),10-abs(int(b[i])-int(c[i])))\r\n\r\nprint(d)", "n=int(input())\r\ns1=input()\r\ns2=input()\r\ncount=0\r\nfor i in range(n):\r\n x=int(s1[i])\r\n y=int(s2[i])\r\n if x>y:\r\n d=x-y\r\n else :\r\n d=y-x\r\n if d<=5:\r\n count=count+d\r\n else :\r\n count=count+(10-d)\r\nprint(count)", "import sys\r\ninput = sys.stdin.readline\r\n\r\nt=int(input())\r\no=int(input())\r\nc=int(input())\r\nans = 0\r\nfor _ in range(t):\r\n a = o%10\r\n b = c%10\r\n if a < b: a,b = b,a\r\n ans += min(a-b, 10-a+b)\r\n o //= 10\r\n c //= 10\r\nprint(ans)\r\n# sys.stdout.write('\\n'.join(map(str, out)))", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\nc = 0\r\nfor i in range(n):\r\n l = []\r\n l.append((abs(int(s1[i])-int(s2[i]))))\r\n if int(s1[i])>int(s2[i]):\r\n l.append(10-int(s1[i])+int(s2[i]))\r\n else:\r\n l.append(10-int(s2[i])+int(s1[i]))\r\n c += min(l)\r\nprint(c)", "n = int(input())\r\norigin = input()\r\ncode = input()\r\nmove = 0\r\nfor i in range(n):\r\n d = abs(int(origin[i])-int(code[i]))\r\n move+=min(d,10-d)\r\nprint(move)", "n = int(input())\ns = input()\np = input()\nres = 0\nfor i in range(n):\n d = abs(ord(s[i]) - ord(p[i]))\n res += min(d, 10 - d)\nprint(res)\n", "n=int(input())\r\nm=int(input())\r\np=int(input())\r\nsum=0\r\nrem1=0\r\nrem2=0\r\nfor i in range(n):\r\n rem1=m%10\r\n rem2=p%10\r\n if rem1>rem2:\r\n if(rem1-rem2 < 10-rem1+rem2):\r\n sum=sum+(rem1-rem2)\r\n else:\r\n sum=sum+(10-rem1+rem2)\r\n else:\r\n if(rem2-rem1 < 10-rem2+rem1):\r\n sum=sum+(rem2-rem1)\r\n else:\r\n sum=sum+(10-rem2+rem1)\r\n m=m//10\r\n p=p//10\r\nprint(sum)\r\n ", "n=int(input())\r\ns1=input()\r\ns2=input()\r\ncount=0\r\nfor i in range(n):\r\n a,b=int(s1[i]),int(s2[i])\r\n count+=min(9-max(a,b)+min(a,b)+1,abs(a-b))\r\nprint(count)\r\n", "def min_moves(original, target):\r\n return min((original - target) % 10, (target - original) % 10)\r\n\r\n\r\nnumber_of_discs = int(input())\r\n\r\noriginal_state = [int(c) for c in input()]\r\n\r\ntarget_state = [int(c) for c in input()]\r\n\r\nprint(sum([min_moves(o, t) for o, t in zip(original_state, target_state)]))\r\n", "t=int(input())\r\na=input()\r\nb=input()\r\ns=0\r\nfor i in range(t):\r\n k=abs(int(a[i])-int(b[i]))\r\n if(k>5):\r\n s+=10-k\r\n else:\r\n s+=k\r\nprint(s) \r\n", "a = int(input())\r\nb = input()\r\nc = input()\r\nk = a = 0\r\nfor i in b:\r\n d = abs(int(i) - int(c[k]))\r\n k += 1\r\n if d > 5:\r\n d = 10 - d\r\n a += d\r\nprint(a)\r\n", "n = int(input())\n##s = list(map(int,input().split()))\n##c = list(map(int,input().split()))\ns = int(input())\nc = int(input())\ns1 = []\nc1 = []\na1 = 0\nfor i in range(n):\n x = c%10\n c = c//10\n y = s%10\n s = s//10\n \n a = abs(x-y) \n if a > 5:\n a1 = a1+(10-a)\n else:\n a1 = a1+a\nprint(a1) \n \n \n \n\n \n \n \n \n \n\n\n \n\n", "\r\nn=int(input())\r\nx=input()\r\ny=input()\r\nb=0\r\nfor i in range(n):\r\n\ta=abs(int(y[i])-int(x[i]))\r\n\tif a>(10-a):\r\n\t\tb=b+10-a\r\n\telse:\r\n\t\tb=b+a\r\nprint(b)", "n = input()\r\nstate = input()\r\ngoal = input()\r\nsteps = 0\r\nfor i in range(int(n)):\r\n\ts = ord(state[i])-48\r\n\tg = ord(goal[i])-48\r\n\tif(g>s):\r\n\t\tup = g-s\r\n\t\tdown = (s+1)+(9-g)\r\n\t\tsteps += min(up,down)\r\n\telif (s>g):\r\n\t\tdown = s-g\r\n\t\tup = (9-s)+1+(g-0)\r\n\t\tsteps+=min(up,down)\r\n\r\nprint(steps)", "n=int(input())\r\ns1=input()\r\ns2=input()\r\ns=0\r\nfor i in range(n):\r\n x=abs(int(s1[i])-int(s2[i]))\r\n y=10-abs(int(s1[i])-int(s2[i]))\r\n s+=min(x,y)\r\nprint(s)", "n = int(input())\r\ns1, s2 = [input() for i in range(2)]\r\nans = 0\r\nfor i in range(n):\r\n x1, x2 = [int(s1[i]), int(s2[i])]\r\n ans += min(abs(x2 - x1), 10 - abs(x2 - x1))\r\nprint(ans)\r\n", "n=int(input())\r\nc=0\r\na=input()\r\nb=input()\r\nl=len(a)\r\nfor i in range(l):\r\n m=int(a[i])\r\n n=int(b[i])\r\n if abs(m-n)<=5:\r\n c+=abs(m-n)\r\n else:\r\n c+=(10-abs(m-n))\r\nprint(c)", "lim=int(input())\r\nx=list(map(int,input()))\r\ny=list(map(int,input()))\r\nmi=0\r\nsum1=0\r\nfor i in range(lim):\r\n mi=min(abs(x[i]-y[i]),10-abs(x[i]-y[i]))\r\n sum1=sum1+mi\r\nprint(sum1)", "n=int(input())\r\na=list(map(int,input()))\r\nb=list(map(int,input()))\r\nk=0\r\nfor i in range(n):\r\n c = abs(a[i]-b[i]) \r\n if c <= 5:\r\n k+=c\r\n else:\r\n k+=10-max(a[i],b[i])+min(a[i],b[i])\r\nprint(k)\r\n", "n=int(input())\r\nx=map(int,input())\r\ny=map(int,input())\r\nc=0\r\nl=[]\r\nm=[]\r\nfor i in x:\r\n l.append(i)\r\nfor j in y:\r\n m.append(j)\r\nfor k in range(n):\r\n c+=min(abs(l[k]-m[k]),10-abs(l[k]-m[k]))\r\nprint(c)", "s=0\r\nn=int(input())\r\nl1= list(map(int,input()))\r\nl2= list(map(int,input()))\r\nfor i in range(n):\r\n m=max(l1[i],l2[i])\r\n mi=min(l1[i],l2[i])\r\n s=s+min((abs(m-9)+mi+1),abs(l1[i]-l2[i]))\r\nprint(s)", "import math\r\nn=int(input())\r\nsum1=0\r\nx=input()\r\nl=list(x)\r\ny=input()\r\nm=list(y)\r\nfor i in range(n):\r\n a=abs(int(l[i])-int(m[i]))\r\n if(a>5):\r\n sum1+=(10-a)\r\n else:\r\n sum1+=a\r\nprint(sum1)", "n = int(input())\r\nlock = input()\r\ncurr = input()\r\nsteps = 0\r\n\r\nfor i in range(n):\r\n steps += min(abs(int(lock[i])- int(curr[i])), 10-abs(int(lock[i])- int(curr[i])))\r\n \r\nprint(steps)", "n = int(input())\r\noriginal_state = input()\r\ncurrent_state = input()\r\nsum = 0\r\ndic = {0: -10, 1: -9, 2: -8, 3: -7, 4: -6, 5: -5, 6: -4, 7: -3, 8: -2, 9: -1}\r\nfor i in range(len(original_state)):\r\n forward = abs(int(original_state[i]) - int(current_state[i]))\r\n if int(original_state[i]) < int(current_state[i]):\r\n backward = int(original_state[i]) + abs(dic[int(current_state[i])])\r\n else:\r\n backward = int(current_state[i]) + abs(dic[int(original_state[i])])\r\n if forward < backward:\r\n sum += forward\r\n else:\r\n sum += backward\r\nprint(sum)", "n = int(input())\r\ns = input()\r\nt = input()\r\n\r\ncount = 0\r\nfor i in range(n):\r\n a = int(s[i])\r\n b = int(t[i])\r\n g = min(a, b)\r\n h = max(a, b)\r\n c = min(h - g, (g + 10 - h))\r\n count += c\r\n\r\nprint(count)\r\n", "rolls = int(input())\r\nstart = str(input())\r\nfinish = str(input())\r\nactions = temp_actions = 0\r\n\r\nfor i in range(rolls):\r\n if start[i] > finish[i]:\r\n temp_actions = int(start[i]) - int(finish[i])\r\n if temp_actions <= 5:\r\n actions += temp_actions\r\n else:\r\n actions += 10 - temp_actions\r\n else:\r\n temp_actions = int(finish[i]) - int(start[i])\r\n if temp_actions <= 5:\r\n actions += temp_actions\r\n else:\r\n actions += 10 - temp_actions\r\n\r\nprint(actions)", "t = int(input())\r\na = input()\r\nb = input()\r\nans = 0\r\nfor i in range(t):\r\n ans += min(10 - abs(int(a[i]) - int(b[i])), abs(int(a[i]) - int(b[i])))\r\nprint(ans)\r\n", "n = int(input())\r\na = input()\r\nb = input()\r\nr = 0\r\nfor i in range(n):\r\n t = abs(int(a[i])-int(b[i]))\r\n r += min(t, 10-t)\r\nprint(r)\r\n\r\n", "n = int(input())\noriginal = input()\ngoal = input()\n\ncount = 0\nfor i in range(n):\n orig = int(original[i])\n gl = int(goal[i])\n\n dist1 = abs(orig-gl)\n dist2 = 10 - dist1\n count += min(dist1, dist2)\n\nprint(count)\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\na=input(\"\")\r\nb=input(\"\")\r\nd=\"1234567890\"\r\ncount=0\r\nfor i in range(0,n):\r\n count += min(abs(d.index(a[i])-d.index(b[i])),len(d)-abs(d.index(a[i])-d.index(b[i])))\r\n\r\nprint(count)", "n=int(input())\r\nfirstline,secondline=input(),input()\r\ncurrent_combination=[int(i) for i in firstline]\r\ncorrect_combination=[int(i) for i in secondline]\r\ntotal_turns=0\r\nfor i in range(n):\r\n turns=abs(current_combination[i]-correct_combination[i])\r\n if(turns>=5):\r\n total_turns=total_turns+(10-turns)\r\n else:\r\n total_turns=total_turns+turns\r\nprint(total_turns)", "n = int(input())\r\nold = input()\r\nnew = input()\r\nans = 0\r\nfor i in range(n):\r\n ans += (10 - abs(int(old[i])-int(new[i])), abs(int(old[i])-int(new[i])))[abs(int(old[i])-int(new[i])) < 5]\r\nprint(ans)", "def dist(x, y):\n if x > y: x, y = y, x\n return min(y - x, x + 10 - y)\n\n\nn = int(input())\na = input()\nb = input()\nans = 0\nfor i in range(n):\n cur = dist(ord(a[i]) - ord('0'), ord(b[i]) - ord('0'))\n ans += cur\nprint(ans)\n\n", "import sys\r\n\r\nn = int(sys.stdin.readline().split()[0])\r\ndisk_origin = sys.stdin.readline().split()[0]\r\ndisk_mc_duck = sys.stdin.readline().split()[0]\r\n\r\nactions = 0\r\nfor i in range(n):\r\n max_digit = max(int(disk_origin[i]),int(disk_mc_duck[i]))\r\n min_digit = min(int(disk_origin[i]),int(disk_mc_duck[i]))\r\n\r\n if (max_digit-min_digit)>5:\r\n actions += min_digit+10-max_digit\r\n else:\r\n actions += max_digit - min_digit\r\n\r\nprint(actions)\r\n", "n = int(input())\r\nt = list(map(int, list(input())))\r\ns = list(map(int, list(input())))\r\nprint(sum([min(abs(x-i), abs(i+10-x), abs(x+10-i)) for i,x in zip(s,t)]))", "n = int(input())\r\na = list(input())\r\nb = list(input())\r\nans = 0\r\nfor i in range(len(a)):\r\n if (int(a[i]) > int(b[i])):\r\n x = abs(10 - int(a[i])) + abs(0 - int(b[i]))\r\n y = abs(int(a[i]) - int(b[i]))\r\n if (x > y):\r\n ans += y\r\n else:\r\n ans += x\r\n elif (int(a[i])< int(b[i])):\r\n x = abs(0 - int(a[i])) + abs(10 - int(b[i]))\r\n y = abs(int(a[i]) - int(b[i]))\r\n if (x > y):\r\n ans += y\r\n else:\r\n ans += x\r\n else:\r\n ans += 0\r\nprint(ans)", "numbers=int(input())\r\nstart=[int(s) for s in input().replace('',' ').strip().split()]\r\ntoUn=[int(t) for t in input().replace('',' ').strip().split()]\r\nans=0\r\nfor i in range(numbers):\r\n if abs(start[i]-toUn[i])>5:\r\n if start[i]>=toUn[i]: ans+=(9-start[i])+toUn[i]+1\r\n else: ans+=start[i]+(9-toUn[i])+1\r\n else: ans+=abs(start[i]-toUn[i])\r\nprint(ans)", "n = int(input())\r\na1 = input()\r\na2 = input()\r\nk = 0\r\nk1 = 0\r\nk2 = 0\r\nb = 0\r\nfor i in range(n):\r\n if a1[i] != a2[i]:\r\n k1 = 0\r\n k2 = 0\r\n b = int(a1[i])\r\n while b != int(a2[i]):\r\n if b == 0:\r\n b = 9\r\n k1 += 1\r\n else:\r\n b -= 1\r\n k1 += 1\r\n b = int(a1[i])\r\n while b != int(a2[i]):\r\n if b == 9:\r\n b = 0\r\n k2 += 1\r\n else:\r\n b += 1\r\n k2 += 1\r\n if k1 < k2:\r\n k += k1\r\n else:\r\n k += k2\r\nprint(k)", "n=int(input())\r\nl=input()\r\nm=input()\r\nc=0\r\nfor i in range(n):\r\n\ts=int(l[i])-int(m[i])\r\n\tif s<0:\r\n\t\ts=-s\r\n\tif s>5:\r\n\t\tx=9-s+1\r\n\t\tc=c+x\r\n\telse:\r\n\t\tc=c+s\r\nprint(c)", "t=int(input())\na=input()\nb=input()\nc=0\nfor i in range(t):\n x=int(a[i])\n y=int(b[i])\n m=max(x,y)\n n=min(x,y)\n c+=min(abs(x-y),(10-m+n))\nprint(c)\n", "n = int(input())\r\na = list(map(int, list(input())))\r\nb = list(map(int, list(input())))\r\ncount = 0\r\nfor x, y in zip(a, b):\r\n if x <= y:\r\n diff = min(y - x, 10 + x - y)\r\n else:\r\n diff = min(x - y, 10 + y - x)\r\n count += diff\r\nprint(count)", "n = int(input())\r\na = input()\r\nb = input()\r\ncunt = 0\r\nfor i in range(n):\r\n q = abs(int(a[i])-int(b[i]))\r\n if q <= 5:\r\n cunt += q\r\n else:\r\n cunt += 10-q\r\nprint(cunt)", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nc=0\r\nfor i in range(n):\r\n l=int(s1[i])\r\n m=int(s2[i])\r\n k=abs(l-m)\r\n c+=min(k,10-k)\r\nprint(c)", "n=int(input())\r\nc1=input()\r\nc2=input()\r\ncount=0\r\ns=0\r\nfor i in range(n):\r\n s=min(abs(int(c1[i:i+1])-int(c2[i:i+1])),10-abs(int(c1[i:i+1])-int(c2[i:i+1])))\r\n count+=s\r\nprint(count)", "n = int(input())\r\n\r\norg = [int(i) for i in input()]\r\npas = [int(i) for i in input()]\r\n\r\nres = 0\r\nfor i in range(n) :\r\n d = abs(pas[i] - org[i])\r\n to9 = 9 - org[i] + pas[i] + 1\r\n to1 = org[i] + 9 - pas[i] + 1\r\n \r\n if to9 < d :\r\n res += to9\r\n elif to1 < d :\r\n res += to1\r\n else :\r\n res += d\r\nprint(res)", "a = int(input())\nb = input()\nc = input()\ntotal = 0\nfor i in range(a):\n temp = abs(int(b[i]) - int(c[i]))\n temp = min(temp, 10 - temp)\n total += temp\nprint(total)\n", "n = int(input())\r\na = input()\r\nb = input()\r\n\r\nans = 0\r\nfor i in range(len(a)):\r\n aa = int(a[i])\r\n bb = int(b[i])\r\n ans += min(abs(10-aa+bb), abs(10+aa-bb), abs(aa-bb))\r\n\r\nprint(ans)\r\n", "n=int(input())\r\nx=list(input())\r\nx=list(map(int,x))\r\ny=list(input())\r\ny=list(map(int,y))\r\na=0\r\nfor i in range(n):\r\n if x[i]<=y[i] and y[i]-x[i]<=4:\r\n a+=y[i]-x[i]\r\n elif x[i]<y[i]:\r\n a+=10-y[i]+x[i]\r\n elif x[i]>y[i] and x[i]-y[i]<=4:\r\n a+=x[i]-y[i]\r\n else:\r\n a+=10-x[i]+y[i]\r\nprint(a)", "n = int(input())\r\ncurrent_set = [int(x) for x in input()]\r\ngoal_set = [int(x) for x in input()]\r\nroll = '01234567890123456789'\r\ncount = 0\r\nfor i in range(len(current_set)):\r\n current_num = str(current_set[i])\r\n desired_num = str(goal_set[i])\r\n lc = roll.index(current_num)\r\n rc = roll.rindex(current_num)\r\n ld = roll.index(desired_num)\r\n rd = roll.rindex(desired_num)\r\n count += min(abs(lc-ld), min(abs(rc-rd), min(abs(lc-rd), abs(rc-ld))))\r\nprint(count)\r\n", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nc=0\r\nfor i in range(len(s1)):\r\n v1,v2=int(s1[i]),int(s2[i])\r\n c+=min(abs(v1-v2),abs(v1+abs(9-v2)+1),abs(9-v1)+v2+1)\r\nprint(c)", "def distance(a, b):\r\n d = abs(int(b) - int(a))\r\n return min(d, 10 - d)\r\n\r\n\r\ninput()\r\nprint(sum([distance(x, y) for x, y in zip(input(), input())]))", "length=int(input())\r\nstate=input()\r\nstate=list(map(int,list(state)))\r\nlock=input()\r\nlock=list(map(int,list(lock)))\r\nmove=0\r\nfor i in range(0,length):\r\n\tcheck=0\r\n\tif(lock[i]<state[i]): \r\n\t\tcheck=(lock[i]+10-state[i])\r\n\telse:\r\n\t\tcheck=(-lock[i]+10+state[i])\r\n\tif abs(state[i]-lock[i])<abs(check):\r\n\t\tmove+=abs(state[i]-lock[i])\r\n\telse:\r\n\t\tmove+=abs(check)\r\nprint(move)", "def op(a, b) :\r\n return min(abs(a-b), 10-abs(a-b))\r\nn, q, k, ans = int(input()), input(), input(), 0\r\nfor i in range(n) :\r\n ans += op(int(q[i]), int(k[i]))\r\nprint(ans)", "n=int(input())\r\na=input()\r\nb=input()\r\ns=[]\r\nfor i in range(n):\r\n k=abs(int(a[i])-int(b[i]))\r\n if k<=5:\r\n s.append(k)\r\n else:\r\n s.append(10-k)\r\nprint(sum(s))\r\n", "x=int(input())\r\ny=input()\r\nz=input()\r\nsum=0\r\nfor i in range(len(y)):\r\n sum+=min(abs(int(y[i])-int(z[i])),10-abs(int(y[i])-int(z[i])))\r\nprint(sum) \r\n", "disks=int(input())\ns=list(input())\nkey=list(input())\nmoves=0\nfor i in range(disks):\n diff=abs(int(s[i])-int(key[i]))\n opposdiff=min(int(s[i]),10-int(s[i]))+min(int(key[i]),10-int(key[i]))\n moves+=min(opposdiff,diff)\nprint(moves)\n\n \t \t\t\t\t \t\t\t \t\t \t\t \t \t \t\t", "n = int(input())\r\ns = input()\r\ns1 = input()\r\narr1 = [i for i in s]\r\narr2 = [i for i in s1]\r\nsum = 0\r\nfor i in range(n):\r\n if abs(int(arr1[i]) - int(arr2[i])) <= 5:\r\n sum += abs(int(arr1[i]) - int(arr2[i]))\r\n else:\r\n sum += abs( 9 - max(int(arr1[i]),int(arr2[i])) + min(int(arr1[i]),int(arr2[i])) + 1)\r\nprint(sum)", "n=int(input())\r\nc=0\r\nl1=[int(i) for i in str(input())]\r\nl2=[int(i) for i in str(input())]\r\nfor i,j in zip(l1,l2):\r\n if abs(i-j)<=5:\r\n c+=abs(i-j)\r\n else:\r\n c+=10-abs(i-j)\r\nprint(c)\r\n", "n = int(input())\r\ncurrent_state = input()\r\ntarget_state = input()\r\n\r\ntotal_moves = 0\r\n\r\nfor i in range(n):\r\n diff = abs(int(current_state[i]) - int(target_state[i]))\r\n total_moves += min(diff, 10 - diff)\r\n\r\nprint(total_moves)\r\n", "n = int(input())\r\na = input()\r\nb = input()\r\nr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']\r\nans = 0\r\nfor i in range(n):\r\n ans += min(abs(r.index(a[i]) - r.index(b[i])), 10 - abs(r.index(a[i]) - r.index(b[i])))\r\nprint(ans)\r\n", "number = int(input())\r\nstring1 = input()\r\nstring2 = input()\r\ncounter = 0\r\nfor i in range(0 , number) :\r\n ele1 = int(string1[i])\r\n ele2 = int(string2[i])\r\n x = 9 - max(ele2 , ele1) + min(ele1 , ele2) + 1\r\n y = max(ele2 , ele1) - min(ele2 , ele1)\r\n counter += min(x , y)\r\nprint(counter)", "import math\r\n\r\nn=int(input())\r\npassword=input()\r\nstate=input()\r\n\r\ncount=0\r\n\r\nfor i in range(n):\r\n value=int(math.fabs(int(password[i])-int(state[i])))\r\n if(value<=5):\r\n count+=value\r\n else:\r\n count+=10-value\r\n \r\n \r\nprint(count) ", "n=int(input())\r\ns1=list(map(int,input()))\r\ns2=list(map(int,input()))\r\nc=0\r\nfor i in range(n):\r\n l=s1[i]-s2[i]\r\n o=max(s1[i],s2[i])\r\n k=min(s1[i],s2[i])+10\r\n c=c+min(abs(l),abs(k-o))\r\nprint(c)", "n=int(input())\r\na=list(map(int,input()))\r\nb=list(map(int,input()))\r\nans=0\r\nfor i in range(0,len(a)):\r\n ans+=min(abs(a[i]-b[i]),10-abs(a[i]-b[i]))\r\n\r\nprint(ans)\r\n", "length=int(input())\nval=list(input())\nval2=list(input())\ncount=0\nfor i in range(length):\n if(abs(int(val[i])-int(val2[i]))>5):\n count+=10-abs(int(val[i])-int(val2[i]))\n else:\n count+=abs(int(val[i])-int(val2[i]))\nprint(count) ", "def p(x):\r\n if x>0: return -1*x\r\n else: return x\r\nn,x,y,c=int(input()),input(),input(),0\r\nfor i in range(n):\r\n if abs(int(x[i]) - int(y[i])) <= p(int(x[i]) - int(y[i]))+10:\r\n c+=abs(int(x[i]) - int(y[i]))\r\n else:\r\n c+=p(int(x[i]) - int(y[i]))+10\r\nprint(c)", "n = int(input()) - 1\r\nl_1 = [int(i) for i in input()]\r\nl_2 = [int(i) for i in input()]\r\ni = 0\r\nres = 0\r\nwhile i <= n:\r\n res += min(abs(l_1[i] - l_2[i]), (9 - abs(l_1[i] - l_2[i]) + 1))\r\n i += 1\r\nprint(res)", "n = int(input())\r\norigin = int(input())\r\nans = int(input())\r\nres = 0\r\n\r\nfor i in range(n):\r\n origin, origin_n = divmod(origin, 10)\r\n ans, ans_n = divmod(ans, 10)\r\n\r\n moves = abs(ans_n - origin_n)\r\n if moves > 5:\r\n moves = 10 - moves\r\n \r\n res += moves\r\n\r\nprint(res)\r\n", "disk = int(input())\r\norig = str(input())\r\nans = str(input())\r\ncount = 0\r\nfor i in range(disk):\r\n o = int(orig[i])\r\n a = int(ans[i])\r\n s = abs(o - a)\r\n if s > 5:\r\n s = 10-s\r\n count +=s\r\nprint(count)", "input()\r\ns=list(input())\r\ns2=list(input())\r\ns=[int(x) for x in s]\r\ns2=[int(x) for x in s2]\r\ncount=0\r\nfor i in range(len(s)) :\r\n dif=abs(s[i]-s2[i])\r\n if dif>=5:\r\n count+=(10-dif)\r\n else:\r\n count+=dif\r\nprint(count)", "a = int(input())\r\nb = list(map(int,input()))\r\nc = list(map(int,input()))\r\ncount = 0\r\nfor i in range(a):\r\n count += abs(min(abs(b[i] - c[i]) , abs(10 - abs(b[i] - c[i] ))))\r\nprint(count)\r\n", "n=int(input())\r\nl=input()\r\nt=input()\r\ns=0\r\nfor i in range(n):\r\n a=(int(l[i]))\r\n b=(int(t[i]))\r\n g1=abs(a-b)\r\n if(a>b):\r\n g2=10-a+b\r\n else:\r\n g2=a+10-b\r\n s=s+min(g1,g2)\r\nprint(s)", "n = int(input())\r\na = input()\r\nb = input()\r\ncnt = 0\r\nfor i in range(n):\r\n x = abs(int(a[i])-int(b[i]))\r\n cnt += min(x,10-x)\r\nprint(cnt) ", "n = input()\r\ns1 = input()\r\ns2 = input()\r\nmoves = 0\r\nfor i in range(int(n)):\r\n #print(abs(int(s2[i])-int(s1[i])), abs(int(s1[i])+10+1 - int(s2[i])), abs(int(s2[i])+10 - int(s1[i])))\r\n moves += min(abs(int(s2[i])-int(s1[i])), abs(int(s1[i])+10 - int(s2[i])), abs(int(s2[i])+10 - int(s1[i])))\r\nprint(moves)\r\n\r\n", "n = int(input())\r\ncode = list(map(int, input()))\r\nsec_code = list(map(int, input()))\r\nsume = 0\r\nfor i in range(len(code)):\r\n sume += min(abs(code[i] - sec_code[i]), 10 - abs(code[i] - sec_code[i]))\r\nprint(sume)\r\n", "a=int(input())\r\nb=list(map(int,input()))\r\nc=list(map(int,input()))\r\nk=0\r\nfor x in range(len(b)):\r\n v=max(b[x],c[x])-min(b[x],c[x])\r\n l=min(b[x],c[x])\r\n if v>=4:\r\n l+=10\r\n h=l-max(b[x],c[x])\r\n if h>v:\r\n k+=v\r\n elif h<v:\r\n k+=h\r\n else:\r\n k+=v\r\n else:\r\n k+=v\r\nprint(k)", "n=int(input())\r\ninit=input()\r\ncomb=input()\r\naction=0\r\nfor i in range(n):\r\n if init[i]==comb[i]:\r\n continue\r\n elif int(init[i])-int(comb[i])>5:\r\n action+=(10-int(init[i]))+int(comb[i])\r\n elif int(init[i])-int(comb[i])<-5:\r\n action+=int(init[i])+(10-int(comb[i]))\r\n else:\r\n action+=abs(int(init[i])-int(comb[i]))\r\nprint(action)\r\n", "n = int(input())\r\ns = str(input())\r\nt = str(input())\r\nans = 0\r\nfor i in range(n):\r\n ans += min(abs(int(s[i]) - int(t[i])), 10 - abs(int(s[i]) - int(t[i])))\r\nprint(ans)", "def solve():\r\n numDisks = int(input())\r\n d1, d2 = list(map(int, input())), list(map(int, input()))\r\n moves = 0\r\n for disk in range(numDisks):\r\n sd, td = d1[disk], d2[disk]\r\n c1 = abs(sd-td)\r\n c2 = 10-c1\r\n moves += min(c1, c2)\r\n print(moves)\r\n\r\nif __name__ == \"__main__\":\r\n solve()\r\n", "n = int(input())\ns1 = input()\ns2 = input()\nsm = 0\nfor i in range(n):\n k = abs((min(int(s1[i]), int(s2[i])) + 10) - max(int(s1[i]), int(s2[i])))\n sm += min(abs(int(s1[i]) - int(s2[i])), k)\nprint(sm)", "def dist(a,b):\n rest = abs(a - b)\n if rest > 5:\n return 10 - rest\n else:\n return rest\n\nnum1 = int(input())\nnum2 = input()\nnum3 = input()\nsum = 0\n\nfor i in range(0,num1,1):\n sum += dist(int(num2[i]), int(num3[i]))\n\nprint(sum)\n\t \t \t \t\t \t \t \t\t \t\t\t \t\t\t\t\t", "n = int(input())\r\norg_state = list(map(str,input()))\r\nkey = list(map(str,input()))\r\nturns = 0\r\nfor i in range(n):\r\n\tif abs(int(org_state[i])-int(key[i]))>=5:\r\n\t\tturns += (9-abs(int(org_state[i])-int(key[i])))+1\r\n\telse:\r\n\t\tturns += abs(int(org_state[i])-int(key[i]))\r\nprint(turns)", "n=int(input())\r\nn1=' '.join(input()).split()\r\nn2=' '.join(input()).split()\r\na='6789012345'\r\ns=0\r\nfor i in range(n):\r\n if abs(int(n2[i])-int(n1[i]))>5:\r\n s+=abs(a.index(n1[i])-a.index(n2[i]))\r\n \r\n else:\r\n s+=abs(int(n2[i])-int(n1[i]))\r\n \r\n \r\nprint(s)\r\n \r\n \r\n \r\n", "n = int(input())\r\nli = list(map(int,input()))\r\nli1 = list(map(int, input()))\r\nres = 0\r\nfor i in range(n):\r\n if li[i] > li1[i]:\r\n res += min((li[i]-li1[i]),abs(li[i]-(10+li1[i])))\r\n elif li[i] < li1[i]:\r\n res += min((li1[i]-li[i]),abs(li1[i]-(10+li[i])))\r\nprint(res)", "import 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\nt = list(input().rstrip())\r\nans = 0\r\nfor i, j in zip(s, t):\r\n ans += min((i - j) % 10, (j - i) % 10)\r\nprint(ans)", "import sys\n\nimport re\nimport collections\nimport math\nimport itertools\n\n\nclass Point(object):\n\tdef __init__(self, x=0, y=0):\n\t\tself.x = x\n\t\tself.y = y\n\n\n\ndef function(*args):\n N = lambda: int(input())\n A = lambda: [int(e) for e in input()]\n P = lambda: map(int, input().split())\n disks = N()\n ori = [int(e) for e in input()]\n final = [int(e) for e in input()]\n moves = 0\n OP = lambda p, q: min([abs(p-q), 9 - abs(p-q) + 1, ((9 + abs(p-q)) % 9) + 1 ])\n for k,v in enumerate(ori):\n p = v\n q = final[k]\n res = OP(p, q)\n moves += res\n print(moves)\n\nif __name__ == '__main__':\n\tfunction()\t\n", "# https://codeforces.com/problemset/problem/540/A\r\n\r\nn, x, y = int(input()), input(), input()\r\nmoves = 0\r\n\r\nfor i in range(n):\r\n d = max(int(x[i]), int(y[i])) - min(int(x[i]), int(y[i])) \r\n if d <= 5:\r\n moves += d\r\n else:\r\n moves += 10 - d\r\n\r\nprint(moves)", "n=int(input())\r\na=input()\r\nb=input()\r\nx=0\r\ny=0\r\nact=0\r\nfor i in range(n):\r\n p=int(a[i])\r\n q=int(b[i])\r\n x=abs(p-q)\r\n if p<=5:\r\n y=abs(p+abs(10-q))\r\n if p>=5:\r\n y=abs(abs(p-10)+q)\r\n act=act+min(x,y)\r\nprint(act)", "n = int(input())\r\na = input() \r\nb = input() \r\nc = int(a) - int(b)\r\nd = str(c) \r\nl = [ ] \r\np= [ ]\r\nfor i in range(n): \r\n k = abs(int(a[i]) - int(b[i]))\r\n p.append(k)\r\n\r\nfor j in range(n):\r\n \r\n if p[j]<=5:\r\n l.append(p[j]) \r\n else:\r\n l.append(10-p[j]) \r\nprint(sum(l))\r\n", "n=int(input())\r\nx=[int(k) for k in list(input())]\r\ny=[int(k) for k in list(input())]\r\nres=0\r\nfor j in range(n):\r\n res+=min(abs(x[j]-y[j]), 10-abs(x[j]-y[j]))\r\nprint(res)", "n = int(input())\r\ns = input()\r\nt = input()\r\nc=0\r\nfor i in range(len(s)):\r\n l=[]\r\n a = (int(s[i]))+(9-int(t[i]))+1\r\n d = (int(t[i]))+(9-int(s[i]))+1\r\n b = (abs(int(s[i])-int(t[i])))\r\n l.append(a)\r\n l.append(b)\r\n l.append(d)\r\n c=c+min(l)\r\nprint(c)", "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\ninput=sys.stdin.readline\r\nn=int(input())\r\ns1=list(input())\r\ns2=list(input())\r\ns=0\r\nfor i in range(n):\r\n if(s1[i]>s2[i]):\r\n s+=min(int(s1[i])-int(s2[i]),10-int(s1[i])+int(s2[i]))\r\n else:\r\n s+=min(int(s2[i])-int(s1[i]),10-int(s2[i])+int(s1[i]))\r\nprint(s)", "input()\r\nprint(sum(min(abs(x-y), 10-abs(x-y)) for x, y in zip(map(int, input()), map(int, input()))))\r\n", "n=int(input())\r\na=str(input())\r\nb=str(input())\r\ncount=0\r\nfor i in range(n):\r\n c=int(a[i])\r\n d=int(b[i])\r\n if(abs(c-d)<=5):\r\n count+=abs(c-d)\r\n else:\r\n count+=10-abs(c-d)\r\nprint(count) ", "i = lambda:map (ord, input ());\r\ni ();\r\nprint (sum (min (abs (a - b), 10 - abs (b - a)) for a, b in zip (i (), i ())))\r\n", "n = int(input())\r\noriginal = input()\r\nscruge = input()\r\n\r\nminmoves =0 \r\nfor i in range(0,n):\r\n diff = abs(int(original[i])-int(scruge[i]))\r\n if diff >5:\r\n minmoves = 10 - diff + minmoves\r\n else:\r\n minmoves = diff + minmoves\r\n \r\nprint(minmoves)", "input()\r\na=[int(i) for i in list(input())]\r\nb=[int(i) for i in list(input())]\r\nc=[]\r\nfor i in range(len(a)):\r\n c.append(min(abs(a[i]-b[i]),10-abs(a[i]-b[i])))\r\nprint(sum(c))", "def solve():\r\n n = int(input())\r\n s1 = str(input())\r\n s2 = str(input())\r\n\r\n count = 0\r\n for i in range(n):\r\n t1 = abs(int(s1[i])-int(s2[i]))\r\n t2 = 10 - t1\r\n temp = min(t1, t2)\r\n count+=temp\r\n\r\n print(count)\r\n\r\nif __name__ == '__main__':\r\n solve()", "input()\r\ns=input()\r\nt=input()\r\nans = 0\r\nfor i in range(len(s)):\r\n\tk=abs(int(s[i])-int(t[i]))\r\n\tans += min(k,10-k)\r\nprint(ans)", "#question A - combination lock \n\ndisks = int(input())\nogState = input()\nsmdComb = input()\nmoves = 0\n\nfor i in range(disks):\n \n temp = abs(int(ogState[i]) - int(smdComb[i]))\n \n if (temp > 5):\n moves += (10 - temp)\n else:\n moves += temp\n\nprint(moves)\n\n \t \t \t\t\t\t\t \t \t \t\t \t \t\t\t\t\t", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\nres = 0\r\n\r\nfor i in range(0,n):\r\n n1 = int(s1[i])\r\n n2 = int(s2[i])\r\n MA = max(n1,n2)\r\n MI= min(n1,n2)\r\n \r\n t1 = MA-MI\r\n t2 = 10 - MA + MI\r\n res += min(t1,t2)\r\n \r\nprint(res)", "x=int(input())\r\ny=input()\r\ny_plus=0\r\ny_minus=0\r\ny_copy= [int(w) for w in str(y)]\r\ny_copy2= [int(w) for w in str(y)]\r\nq=input()\r\nq_copy= [int(e) for e in str(q)]\r\ncount=0\r\ncount_plus=0\r\ncount_minus=0\r\nfor i in range(x):\r\n while y_copy[i]!=q_copy[i]:\r\n y_plus+=1\r\n y_copy[i]+=1\r\n if y_copy[i] == 10:\r\n y_copy[i]=0\r\n count_plus+=1\r\n while y_copy2[i]!=q_copy[i]:\r\n y_minus+=1\r\n y_copy2[i]-=1\r\n if y_copy2[i] == -1:\r\n y_copy2[i]=9\r\n count_minus+=1\r\n count+=min(count_minus,count_plus)\r\n count_minus=0\r\n count_plus=0\r\nprint(count)", "n = int(input())\r\ngiven = list(input())\r\nanswer = list(input())\r\ncount = 0\r\nfor j in range(n):\r\n a = int(given[j])\r\n b = int(answer[j])\r\n if abs(a-b) > 5:\r\n count += 10-abs(a-b)\r\n else:\r\n count += abs(a-b)\r\n\r\nprint(count)\r\n", "dgtnum = int(input())\r\ninits = list(input())\r\ntgts = list(input())\r\n\r\ndef cnvrt(l):\r\n for i in range(dgtnum):\r\n l[i]=int(l[i])\r\n\r\ncnvrt(inits)\r\ncnvrt(tgts)\r\n\r\nc = 0\r\n\r\nfor i in range(dgtnum):\r\n if abs(inits[i] - tgts[i]) <= 5:\r\n c+=abs(inits[i] - tgts[i])\r\n else:\r\n c+=(10-abs(inits[i] - tgts[i]))\r\n\r\nprint (c)\r\n", "kol_nom = int(input())\r\nizn = list(input())\r\nkon = list(input())\r\nk = 0\r\nfor i in range(len(izn)):\r\n k += min(abs(int(izn[i]) - int(kon[i])),10 - abs(int(izn[i]) - int(kon[i])) )\r\nprint(k)", "\r\n\r\ndisks = int(input())\r\nstate = input()\r\ncombination = input()\r\npad = [0,1,2,3,4,5,6,7,8,9]\r\n\r\nsuma = 0\r\n\r\n\r\nfor n in range(disks):\r\n left = right = 0\r\n inicio = int(state[n])\r\n final = int(combination[n])\r\n\r\n #ir a la izuiqerda \r\n curr_pos = pad.index(inicio)\r\n for n in range(10):\r\n if pad[curr_pos] == final:\r\n break\r\n else:\r\n curr_pos -= 1\r\n left += 1\r\n \r\n\r\n right = 10 - left \r\n if right <= left:\r\n suma = suma + right \r\n\r\n else:\r\n suma = suma+ left\r\nprint(suma)\r\n\r\n\r\n", "a = int(input())\r\ns = list(map(int, list(input())))\r\ns1 = list(map(int, list(input())))\r\nsum1 = 0\r\nfor i, j in zip(s, s1):\r\n qwer = abs(i - j)\r\n qwer1 = min(i, j) + 10 - max(j, i)\r\n sum1 += min([qwer, qwer1])\r\nprint(sum1)", "n=int(input())\r\nc=input()\r\nans=input()\r\nmoves=0\r\nfor i in range(0,n):\r\n num1,num2=int(c[i]),int(ans[i])\r\n h1=abs(num1-num2)\r\n h2=10-max(num1,num2)+min(num1,num2)\r\n moves+=(min(h1,h2))\r\nprint(moves)", "n = int(input())\n\nstart = input()\n\ntarget = input()\n\nres = 0\n\nfor i in range(n):\n diff = abs(int(start[i]) - int(target[i]))\n if diff <= 5:\n res += diff\n else:\n res += 10 - diff\n\n\nprint(res)", "n=int(input())\r\nz=(input())\r\nx=(input())\r\n\r\nf=0\r\nfor i in range(n):\r\n s=abs(int(z[i])-int(x[i]))\r\n d=(10-int(max(z[i],x[i])))+int(min(z[i],x[i]))\r\n f+=(min(s,d))\r\nprint(f)\r\n", "n=int(input())\r\ns=input()\r\nm=input()\r\nans=0\r\nfor i in range(n):\r\n ans+=min(abs(int(s[i])-int(m[i])),10-abs(int(s[i])-int(m[i])))\r\nprint(ans)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Oct 16 08:20:44 2020\r\n\r\n@author: HP\r\n\"\"\"\r\n\r\n\r\nnum=int(input())\r\na=(\"0123456789\")\r\nkey1=input()\r\nkey2=input()\r\nmin=0\r\ndis=0\r\nfor i in range(0,num):\r\n clock=abs(a.index(key1[i])-a.index(key2[i]))\r\n antiClock=0\r\n if a.index(key1[i])<a.index(key2[i]):\r\n antiClock= a.index(key1[i])+(10-a.index(key2[i]))\r\n elif a.index(key1[i])>a.index(key2[i]):\r\n antiClock= a.index(key2[i])+(10-a.index(key1[i]))\r\n dis= clock\r\n \r\n if clock>antiClock :\r\n dis= antiClock\r\n min=min+dis\r\nprint(min)", "ap = int(input())\r\noriginal_state = input()\r\ntarget_state = input()\r\nmoves = 0\r\nfor i in range(ap):\r\n diff = abs(int(original_state[i]) - int(target_state[i]))\r\n moves += min(diff, 10 - diff)\r\nprint(moves)\r\n", "n=int(input())\r\nc=0\r\na=input()\r\nb=input()\r\nfor i in range(n):\r\n c+=min(10-abs(int(a[i])-int(b[i])),abs(int(a[i])-int(b[i])))\r\nprint(c)", "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\n\r\nn=iinput()\r\na1=list(input())\r\nb1=list(input())\r\n\r\n\r\n\r\nh=[]\r\nfor i in range(n):\r\n s=int(a1[i])-int(b1[i])\r\n if(s<0):\r\n s=-s\r\n\r\n s1=10-max(int(a1[i]),int(b1[i]))+min(int(a1[i]),int(b1[i]))\r\n if(s1<0):\r\n s1=-s1\r\n \r\n \r\n h.append(min(s,s1))\r\n\r\nprint(sum(h))\r\n", "n=int(input())\r\ns=input()\r\nn=input()\r\nlist1=[]\r\nlist2=[]\r\nsum1=0\r\nsum2=0\r\nlist3=[]\r\nlist4=[]\r\nfor x in range(len(s)):\r\n list1.append(int(s[x]))\r\n list2.append(int(n[x]))\r\nfor x in range(len(s)):\r\n sum1=10-abs(list1[x]-list2[x])\r\n sum2=abs(list1[x]-list2[x])\r\n list3.append(sum1)\r\n list4.append(sum2)\r\nsum3=0\r\nfor x in range(len(s)):\r\n if list3[x]<=list4[x]:\r\n sum3+=list3[x]\r\n else:\r\n sum3+=list4[x]\r\nprint(sum3)", "num = int(input())\r\nst = input()\r\nst1 = input()\r\nsum=0\r\nanother = 0\r\nfor i in range(0,num):\r\n d = int(st[i])\r\n s = int(st1[i])\r\n m = min(d,s)\r\n if m == d :\r\n another = s\r\n else:\r\n another = d\r\n if abs(m - another)<abs((m+10)-another):\r\n sum = sum+abs(m-another)\r\n else:\r\n sum = sum +abs((m+10)-another)\r\n\r\nprint(sum)", "n = int(input())\ncombination1 = input()\ncombination2 = input()\nrotation = 0\nfor i in range(0, n):\n placehold = 0\n placehold2 = 0\n if int(combination1[i]) > int(combination2[i]):\n placehold = int(combination1[i]) - int(combination2[i])\n placehold2 = int(combination2[i]) + 10 - int(combination1[i])\n else:\n placehold = int(combination2[i]) - int(combination1[i])\n placehold2 = int(combination1[i]) + 10 - int(combination2[i])\n if placehold < placehold2:\n rotation = rotation + placehold\n else:\n rotation = rotation + placehold2\nprint(rotation)", "n = int(input())\r\n\r\ncount = 0\r\ncombinations = [[],[]]\r\n\r\ndef calc_difference(one, two):\r\n difference = abs(one - two)\r\n if difference > 5:\r\n return 10 - difference\r\n else:\r\n return difference\r\n\r\nfor comb in combinations:\r\n for x in input():\r\n comb.append(int(x))\r\n\r\nfor i in range(n):\r\n count += calc_difference(combinations[0][i], combinations[1][i])\r\n\r\nprint(count)", "def q(a,b):\r\n if a>=b:\r\n return a-b\r\n else:\r\n return b-a\r\n\r\nn=int(input())\r\nA=list(input())\r\nB=list(input())\r\nc=0 \r\nfor i in range(n):\r\n p1=int(A[i])\r\n p2=int(B[i])\r\n c+=min(q(p1,p2), 10-q(p1,p2))\r\n\r\nprint(c)\r\n", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nt=0\r\nfor i in range(n):\r\n k=int(s1[i])\r\n l=int(s2[i])\r\n m1=abs(k-l)\r\n m2=(9-max(k,l))+1+min(k,l)\r\n t+=min(m1,m2)\r\nprint(t)", "n=int(input())\r\na=input()\r\nb=input()\r\ns=0\r\nfor i in range(n):\r\n s+=min(abs(int(a[i])-int(b[i])),10-abs(int(a[i])-int(b[i])))\r\nprint(s)", "\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n nums1 = map(int, input())\r\n nums2 = map(int, input())\r\n\r\n ans = 0\r\n for n1, n2 in zip(nums1, nums2):\r\n # print(f\"n1={n1}\")\r\n nmin = min(n1, n2)\r\n nmax = max(n1, n2)\r\n # print(f\"{nmax}-{nmin}={nmax-nmin}\")\r\n # print(f\"({nmin}+{nmax}+1) % 10={(nmin+nmax) % 10 + 1}\")\r\n ans += min(nmax-nmin, (9 - nmax + nmin + 1))\r\n\r\n print(ans)\r\n", "n=int(input())\r\ns=input()\r\nz=input()\r\nc=0\r\nfor i in range(n):\r\n c=c+min(abs(int(s[i])-int(z[i])), 10-abs(int(s[i])-int(z[i])))\r\nprint(c)", "n, initial, code, res = int(input()), input(), input(), 0\r\nfor i in range(n):\r\n a, b = int(initial[i]), int(code[i])\r\n if abs(a-b) < 6:\r\n res += abs(a - b)\r\n elif a == b:\r\n continue\r\n else:\r\n if a < b:\r\n res += a + 10 - b\r\n else:\r\n res += b + 10 - a\r\nprint(res)\r\n", "a = int(input())\r\nb = input()\r\nc = input()\r\ns = []\r\nt = []\r\nx = 0\r\nfor i in range(a):\r\n s.append(int(b[i]))\r\n t.append(int(c[i]))\r\nfor j in range(a):\r\n if abs(s[j]-t[j]) <= 5:\r\n x = x + abs(s[j]-t[j])\r\n else:\r\n x = x + 10 - abs(s[j]-t[j])\r\nprint(x)", "n = int(input())\nl = [int(x) for x in input()]\nm = [int(x) for x in input()]\n\nsum = 0\n\nfor i in range(n):\n sum += min(abs(l[i]-m[i]) , 10 - abs(l[i]-m[i]))\n \nprint(sum)\n \n\t \t \t \t \t \t \t\t\t \t \t \t", "n=int(input())\r\nps=input()\r\nos=input()\r\nb=[]\r\nc=[]\r\ntm=0\r\nfor (i,j) in zip(ps,os):\r\n\tb.append(int(i))\r\n\tc.append(int(j))\r\nfor (i,j) in zip(b,c):\r\n\tif abs(i-j)>5:\r\n\t\ttm+=10-abs(i-j)\r\n\telse:\r\n\t\ttm+=abs(i-j)\r\nprint(tm)", "n=int(input())\r\nx=input()\r\ny=input()\r\nturns=0\r\nfor i in range(n):\r\n n1=int(x[i])\r\n n2=int(y[i])\r\n add=max(n1,n2)-min(n1,n2)\r\n if add>5: add=10-add\r\n turns=turns+add\r\nprint(turns)\r\n", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\nc = 0\r\nfor i in range(n):\r\n\tif abs(int(s1[i]) - int(s2[i]))<=5:\r\n\t\tc+=abs(int(s1[i]) - int(s2[i]))\r\n\telse:\r\n\t\tc+=10-abs(int(s1[i]) - int(s2[i]))\r\nprint(c)\r\n", "n = int(input())\r\nk1 = list(map(int, input()))\r\nk2 = list(map(int, input()))\r\nprint(sum(min(10 - abs(k1[i] - k2[i]),\r\n abs(k1[i] - k2[i])) for i in range(n)))\r\n", "n = int(input())\r\nd_state = list(map(int, input()))\r\no_password = list(map(int, input()))\r\nans = 0\r\n\r\nfor i in range(0, n):\r\n try1 = abs(d_state[i] - o_password[i])\r\n try2 = 10 - abs(d_state[i] - o_password[i])\r\n summable = min(try1, try2)\r\n ans += summable\r\n\r\nprint(ans)", "import math\r\nn=int(input())\r\ns,t=input(),input()\r\nsum=0\r\nfor i in range (n):\r\n\ta=int(s[i])\r\n\tb=int(t[i])\r\n\tmini=int(abs(a-b))\r\n\tsum+=min(mini,10-mini)\r\n\t\r\nprint(sum)", "ans = 0\r\nn = int(input())\r\nori = [int(x) for x in input()]\r\nopn = [int(y) for y in input()]\r\nfor i in range(n):\r\n m = abs(ori[i]-opn[i])\r\n if m>5: m = 10-m\r\n ans += m\r\nprint(ans)", "if __name__ == \"__main__\":\r\n n = int(input())\r\n s1 = input()\r\n s2 = input()\r\n (count,diff) = (0,0)\r\n\r\n for i in range(n):\r\n diff = abs(int(s1[i]) - int(s2[i]))\r\n count += min(diff,10 - diff)\r\n \r\n print(count)", "n,S1,S2=int(input()),input(),input()\r\nt,s=0,0\r\nfor i in range(n):\r\n t=abs(int(S1[i])-int(S2[i]))\r\n if t<=5:s+=t\r\n else:s+=9-t+1 \r\nprint(s)", "n=int(input())\r\nl1=input()\r\nl2=input()\r\ns=0\r\nfor i in range(n):\r\n\tif abs(int(l1[i])-int(l2[i]))>5:\r\n\t\tif int(l1[i])<5:\r\n\t\t\ts+=int(l1[i])+10-int(l2[i])\r\n\t\telse:\r\n\t\t\ts+=10-int(l1[i])+int(l2[i])\r\n\telse:\r\n\t\ts+=abs(int(l1[i])-int(l2[i]))\r\n\r\nprint(s)", "n = int(input())\r\nk = -1\r\nog = [int(p) for p in str(input())]\r\nlock = [int(i) for i in str(input())]\r\ni = 0\r\nwhile k < n-1:\r\n k+=1\r\n if abs(og[k]-lock[k])<=5:\r\n i+=abs(og[k]-lock[k])\r\n else:\r\n i+=10-(abs(og[k]-lock[k]))\r\nprint(i)", "n=int(input())\r\ns1=input()\r\ns2=input()\r\ncount=0 \r\n\r\nfor i in range(n):\r\n count+= min(abs(int(s2[i])-int(s1[i])),10 -abs(int(s2[i])-int(s1[i])))\r\n\r\nprint(count)\r\n\r\n''' \r\nHere abs(int(s2[i])-int(s1[i])) = Clock-wise moves &\r\n(10 - abs(int(s2[i])-int(s1[i])) )= Anti-Clock-wise moves \r\n''' ", "a = int(input())\r\nb = input()\r\nc = input()\r\nd = 0\r\nfor i in range(a):\r\n t = abs(int(b[i]) - int(c[i]))\r\n if b[i] > c[i]:\r\n g = 10 - int(b[i]) + int(c[i])\r\n else:\r\n g = 10 - int(c[i]) + int(b[i])\r\n if t < g:\r\n d += t\r\n else:\r\n d += g\r\nprint(d)", "n, ans = int(input()), 0\r\ns = input()\r\nt = input()\r\n\r\nfor x in range(n):\r\n ans += min(abs(int(s[x]) - int(t[x])), 10+min(int(s[x]), int(t[x])) - max(int(s[x]), int(t[x])))\r\n\r\nprint(ans)", "from math import fabs\r\ninp = int(input()); pos = input()\r\nreq,sm = input(),0\r\nfor i in range(inp):\r\n _ = fabs(int(pos[i])-int(req[i]))\r\n sm= (sm +10-_) if (_>5) else (sm + _)\r\nprint(int(sm))\r\n", "n = int(input())\r\ns = input()\r\ns = list(s)\r\nc = input()\r\nc = list(c)\r\nk=0\r\nfor i in range(n):\r\n d = int(s[i])-int(c[i])\r\n if d<0:\r\n d=-d\r\n else:\r\n d=d\r\n if d>5:\r\n x=9-d\r\n x=x+1\r\n k=k+x\r\n else:\r\n k=k+d\r\n \r\nprint(k)", "\nsize = input()\nsize = int(size)\noriginal = input()\ncombo = input()\ncount = 0\nfor x in range(0, size):\n temp = abs((int(original[x]) - int(combo[x])))\n if (temp > 5):\n count += (10 - temp)\n else:\n count += temp\nprint(count)\n \n", "movement = 0\r\nn = int(input())\r\na = input()\r\nb = input()\r\nfor i in range(n):\r\n kmin = min(abs(10+int(a[i])-int(b[i])),abs(10+int(b[i])-int(a[i])))\r\n if abs(int(a[i])-int(b[i]))< kmin:\r\n movement += abs(int(a[i])-int(b[i]))\r\n else:\r\n movement+=kmin\r\n\r\nprint(movement)", "def min_actions_for_digit(digit1, digit2):\r\n # Функция для вычисления минимального количества действий между двумя цифрами\r\n return min((digit1 - digit2 + 10) % 10, (digit2 - digit1 + 10) % 10)\r\n\r\ndef min_actions_for_disk(initial_digit, target_digit):\r\n # Функция для вычисления минимального количества действий для одного диска\r\n return min_actions_for_digit(initial_digit, target_digit)\r\n\r\ndef main():\r\n n = int(input())\r\n initial_state = list(map(int, input().strip()))\r\n target_state = list(map(int, input().strip()))\r\n\r\n total_actions = 0\r\n\r\n for i in range(n):\r\n total_actions += min_actions_for_disk(initial_state[i], target_state[i])\r\n\r\n print(total_actions)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n1 = int(input())\r\nn2 = list(input())\r\nn3 = list(input())\r\nb=False\r\nk =0 \r\ncount = 0\r\nwhile b==False:\r\n\r\n diff = abs(int(n2[k])-int(n3[k]))\r\n if 10 -diff > diff:\r\n count +=diff\r\n elif 10-diff < diff:\r\n count+=(10-diff)\r\n else:\r\n count+=diff\r\n k+=1\r\n if k==len(n2):\r\n print(count)\r\n break", "n = int(input())\r\nw = str(input())\r\ns = str(input())\r\n\r\ndef cal(n):\r\n if n > 5:\r\n return 10 - n\r\n return n\r\n\r\ncount = 0\r\nfor i in range(n):\r\n count += cal(abs(int(s[i]) - int(w[i])))\r\n\r\nprint(count)", "from math import fabs\r\ninp = int(input())\r\npos = input()\r\nreq,sm = input(),0\r\nfor i in range(inp):\r\n _ = fabs(int(pos[i])-int(req[i]))\r\n if _>5:\r\n sm+=10-_\r\n else:\r\n sm+=_\r\nprint(int(sm))\r\n", "\r\nn = int(input())\r\ns1 = input()\r\ns2 = input()\r\nx = y = ans = 0\r\nfor i in range(0,len(s1)):\r\n x = abs(int(s1[i]) - int(s2[i]))\r\n if int(s1[i]) > int(s2[i]):\r\n y = abs(9-int(s1[i]))+(abs(0-int(s2[i]))+1)\r\n else:\r\n y = abs(9 - int(s2[i])) + (abs(0 - int(s1[i])) + 1)\r\n ans += min(x,y)\r\nprint(ans)", "n = int(input())\r\ncurr = input()\r\norig = input()\r\nans = 0\r\nfor i in range(n):\r\n\tans += min(abs(int(orig[i]) - int(curr[i])), int(curr[i]) + 10-int(orig[i]), int(orig[i]) + 10-int(curr[i]))\r\nprint(ans)", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nans=0\r\nfor i in range(0,n):\r\n\ta=int(s1[i])\r\n\tb=int(s2[i])\r\n\tx=abs(a-b)\r\n\ty=(min(a,b)+10)-max(a,b)\r\n\tans+=min(x,y)\r\nprint(ans)", "n = int(input())\r\na = str(input())\r\nb = str(input())\r\n\r\nmoves = 0\r\nfor i in range(n):\r\n t = abs(int(b[i])-int(a[i]))\r\n moves += min(t, 10-t)\r\nprint(moves)", "d=[]\r\nfor i in range(10):\r\n d.append(i)\r\n \r\nn=int(input())\r\ns1=input()\r\ns2=input()\r\n\r\nc=0\r\nfor i in range(n):\r\n c+=min(abs(int(s1[i])-int(s2[i])),10-max(int(s1[i]),int(s2[i]))+min(int(s1[i]),int(s2[i])))\r\nprint(c)", "n = int(input())\r\nstr1 = input()\r\nstr2 = input()\r\ni = 0\r\ntotal_dif = 0\r\n\r\nwhile i < n:\r\n digit1 = int(str1[i])\r\n digit2 = int(str2[i])\r\n total_dif += min(abs(digit1-digit2), min((10-digit1 + digit2),(10-digit2+digit1)))\r\n \r\n i += 1\r\n \r\nprint(total_dif)", "import sys\n\nargs = []\nsum = 0\n\nvals = 0\nfor line in sys.stdin:\n args.append(line)\n vals += 1\n if vals == 3: break\n\nfor num in range(int(args[0])):\n diff = abs(int(args[1][num]) - int(args[2][num]))\n if diff > 5:\n diff = 10 - diff\n \n sum += diff\n\nprint(sum)", "n=int(input())\r\na,b=input(),input()\r\nc=0\r\nfor i in range(n):\r\n if abs(int(a[i])-int(b[i]))<6:\r\n c+=abs(int(a[i])-int(b[i]))\r\n else:\r\n c+=10-abs(int(a[i])-int(b[i]))\r\nprint(c)", "n = int(input())\r\nos = input()\r\nfs = input()\r\nc=0\r\nfor i in range(len(os)):\r\n if abs(int(os[i])-int(fs[i]))>4:\r\n c += 10-abs(int(os[i])-int(fs[i]))\r\n else:\r\n c += abs(int(os[i])-int(fs[i]))\r\n\r\nprint(c)", "u=int(input())\r\na=input()\r\nb=input()\r\nn=0\r\nn1=0\r\nlst=[]\r\nlst1=[]\r\nfor x in a:\r\n lst.append(x)\r\nfor y in b:\r\n lst1.append(y)\r\nfor d in range(len(a)):\r\n if n<=len(a):\r\n i=max(int(lst[n]),int(lst1[n]))-min(int(lst[n]),int(lst1[n]))\r\n n+=1\r\n if i > 5:\r\n if i==6:\r\n n1+=4\r\n elif i==7:\r\n n1+=3\r\n elif i==8:\r\n n1+=2\r\n else:\r\n n1+=1\r\n else:\r\n n1 += i\r\n else:\r\n break\r\nprint(n1)", "n = int(input())\r\ns = input()\r\nt = input()\r\nans = 0\r\nfor i in range(n):\r\n x = abs(int(s[i])-int(t[i]))\r\n ans +=min(x,10-x)\r\nprint(ans)", "x=int(input())\r\n\r\naa=input()\r\nbb=input()\r\n\r\n\r\na=list(aa)\r\nb=list(bb)\r\n\r\n\r\nnewa=[]\r\nnewb=[]\r\n\r\nfor i in a:\r\n newa.append(int(i))\r\n \r\nfor i in b:\r\n newb.append(int(i))\r\n\r\ninde=0\r\n\r\nkoli=0\r\n\r\nfor i in range(x):\r\n ko=abs(newa[inde]-newb[inde])\r\n inde=inde+1\r\n if ko<5:\r\n koli=koli+ko\r\n else:\r\n ko=10-ko\r\n koli=koli+ko\r\n\r\nprint(koli) \r\n\r\n \r\n \r\n \r\n", "def opt(start, stop):\r\n min1 = min(start, stop)\r\n max1 = max(start, stop)\r\n o1 = max1 - min1\r\n o2 = min1 + (9 - max1 + 1)\r\n o2 = max(o2, 0)\r\n return min(o1,o2)\r\nn = int(input())\r\ns1 = input()\r\ns2 = input()\r\nmoves = 0\r\nfor i in range(n):\r\n moves += opt(int(s1[i]), int(s2[i]))\r\nprint(moves)\r\n", "from collections import deque \r\n\r\ndef girar_derecha(num_ini, num_fin):\r\n\tnumbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\r\n\tnum_moves = 0\r\n\r\n\twhile numbers[0] != num_ini:\r\n\t\tnumbers = deque(numbers)\r\n\t\tnumbers.rotate(1)\r\n\t\tnumbers = list(numbers)\t\r\n\r\n\twhile numbers[0] != num_fin:\r\n\t\tnumbers = deque(numbers)\r\n\t\tnumbers.rotate(1)\r\n\t\tnumbers = list(numbers)\t\r\n\t\tnum_moves = num_moves+1\r\n\r\n\treturn num_moves\r\n\r\n\r\ndef girar_izquierda(num_ini, num_fin):\r\n\tnumbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\r\n\tnum_moves = 0\r\n\r\n\twhile numbers[0] != num_ini:\r\n\t\tnumbers = deque(numbers)\r\n\t\tnumbers.rotate(-1)\r\n\t\tnumbers = list(numbers)\t\r\n\r\n\twhile numbers[0] != num_fin:\r\n\t\tnumbers = deque(numbers)\r\n\t\tnumbers.rotate(-1)\r\n\t\tnumbers = list(numbers)\t\r\n\t\tnum_moves = num_moves+1\r\n\r\n\treturn num_moves\r\n\r\n\r\ndef init():\r\n\tdisks = int(input())\r\n\toriginal_pos = input()\r\n\tpassword = input()\r\n\tnumbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\r\n\ttotal_moves = 0\r\n\t\r\n\tfor i in range(0, disks):\r\n\t\tnum1 = int(original_pos[i])\r\n\t\tnum2 = int(password[i])\t\r\n\t\tmoves1 = girar_izquierda(num1, num2)\r\n\t\tmoves2 = girar_derecha(num1, num2)\r\n\r\n\t\tif moves1 < moves2:\r\n\t\t\ttotal_moves = total_moves + moves1\r\n\t\telif moves2 < moves1:\r\n\t\t\ttotal_moves = total_moves + moves2\r\n\t\telse:\r\n\t\t\ttotal_moves = total_moves + moves1\r\n\t\r\n\tprint(total_moves)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tinit()\r\n", "input()\r\ns=0\r\na=[int(i) for i in input()]\r\nb=[int(i) for i in input()]\r\nfor x,y in zip(a,b): s+=min(abs(x-y),min(x,y)+(9-max(x,y)+1))\r\nprint(s)", "x = int(input())\r\ny = input()\r\nz = input()\r\ntotal = 0\r\nfor i in range(x):\r\n q = abs(int(y[i])-int(z[i]))\r\n temp = min(q, 10 - q)\r\n total += temp\r\nprint(total)\r\n", "length = int(input());\r\nip = input();\r\npwd = input();\r\nres = 0;\r\nfor value in range(length):\r\n diff = abs(int(ip[value]) - int(pwd[value]));\r\n if(diff > 5):\r\n diff = 10 - diff;\r\n res = res + diff;\r\nprint(res)", "n = int(input())\r\nx = input()\r\ny = input()\r\nresult = 0\r\nfor i in range(n) :\r\n a = int(x[i])\r\n b = int(y[i])\r\n result += min(abs(a-b),(min(a,b)+10-max(a,b)) % 10 )\r\nprint(result)", "def indice(i):\r\n ch=\"098765432109876543210\"\r\n l=list()\r\n for j in range(len(ch)):\r\n if ch[j]==i:\r\n l.append(j)\r\n return(l)\r\nx=int(input())\r\nch1=input()\r\nch2=input()\r\ns=0\r\nfor i in range(x):\r\n l=list()\r\n l.append(abs(max(indice(ch2[i]))-max(indice(ch1[i]))))\r\n l.append(abs(max(indice(ch2[i]))-min(indice(ch1[i]))))\r\n l.append(abs(min(indice(ch2[i]))-max(indice(ch1[i]))))\r\n l.append(abs(min(indice(ch2[i]))-min(indice(ch1[i]))))\r\n s=s+min(l)\r\nprint(s)\r\n", "import math\r\nfrom fractions import Fraction as frac\r\n\r\nMOD = 1e9 + 7\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 return a * b // gcd(a, b)\r\n\r\ndef solve(case_no):\r\n n = int(input())\r\n s1 = str(input())\r\n s2 = str(input())\r\n ans = 0\r\n for i in range(n):\r\n d = abs(ord(s1[i]) - ord(s2[i]))\r\n ans += min(d, 10 - d)\r\n print(ans)\r\n\r\nt = 1\r\n# t = int(input())\r\nfor i in range(1, t + 1):\r\n solve(i)\r\n", "n=int(input())\r\na=int(input())\r\nb=int(input())\r\nk1=[]\r\nk2=[]\r\nfor i in range(n):\r\n x=b%10\r\n y=a%10\r\n k1.append(x)\r\n k2.append(y)\r\n b=b//10\r\n a=a//10\r\nc=0\r\nfor i in range(n):\r\n if k1[i]>k2[i]:\r\n if(k1[i]-k2[i])<=5:\r\n c+=k1[i]-k2[i]\r\n else:\r\n c+=10-(k1[i]-k2[i])\r\n else:\r\n if(k2[i]-k1[i])<=5:\r\n c+=k2[i]-k1[i]\r\n else:\r\n c+=10-(k2[i]-k1[i])\r\nprint(c)", "# Coded By Block_Cipher\r\n \r\nimport math\r\nimport os\r\nimport random\r\nimport re\r\nimport sys\r\nfrom math import gcd\r\nfrom math import sqrt\r\n \r\n# sys.stdin = open('input.txt', 'r')\r\n# sys.stdout = open('output.txt', 'w')\r\n\r\nn = int(input())\r\nx = input()\r\ny = input()\r\n\r\nans = 0\r\nfor i in range(n):\r\n\tans+=min(abs(int(x[i])-int(y[i])),(10-abs(int(x[i])-int(y[i]))))\r\nprint(ans)", "# Sourav Basak Shuvo KUET BME'18\r\n\r\nn = int(input())\r\nx = str(input())\r\ny = str(input())\r\nturn = 0\r\nfor i in range(n):\r\n mx = max(int(x[i]), int(y[i]))\r\n mn = min(int(x[i]), int(y[i]))\r\n dif = mx - mn\r\n if dif > 5:\r\n turn = turn + (10-dif)\r\n else:\r\n turn = turn + dif\r\nprint(turn)", "n=int(input())\r\na=input()\r\nb=input()\r\nsum=0\r\nfor i in range(0,n):\r\n sum+=min(abs(int(a[i])-int(b[i])),10-(abs(int(a[i])-int(b[i]))))\r\nprint(sum)\r\n", "a=int(input())\r\nb=input()\r\nc=input()\r\ns=0\r\nfor i in range(a):\r\n if abs(int(c[i])-int(b[i]))>5:\r\n s=s+10-abs(int(c[i])-int(b[i]))\r\n else: s=s+abs(int(c[i])-int(b[i]))\r\nprint(s)", "import math\r\nn=int(input())\r\ns1=input()\r\ns2=input()\r\nc=0\r\nfor i in range(n):\r\n r=math.fabs(int(s1[i])-int(s2[i]))\r\n c+=min(r,(10-r))\r\nprint(int(c))", "n=int(input())\r\nmyState = list(map(int, input()))\r\nogState = list(map(int, input()))\r\nforward=0\r\nbackward=0\r\ncnt=0\r\nfor i in range(len(myState)):\r\n if(myState[i]==ogState[i]):\r\n continue\r\n\r\n elif(myState[i] < ogState[i] or myState[i] > ogState[i]):\r\n forward=abs(ogState[i]-myState[i])\r\n backward=10-forward\r\n cnt+=min(forward,backward)\r\n \r\nprint(cnt)", "def main():\r\n n = int(input())\r\n current_combo = input()\r\n correct_combo = input()\r\n\r\n counter = 0\r\n for i in range(n):\r\n difference = abs(int(current_combo[i]) - int(correct_combo[i]))\r\n counter += min(difference, 10 - difference)\r\n print(counter)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n = int(input())\n\nl = list(map(int, list(input())))\n\nl1 = list(map(int, list(input())))\n\nans = 0\n\nfor i in range(n):\n ans += min(abs(l[i] - l1[i]), abs(10+l[i] - l1[i]), abs(10+l1[i] - l[i]))\n\nprint(ans)\n \t\t\t \t\t \t \t\t\t \t \t\t\t \t \t \t", "sum=0\r\na=int(input())\r\nb1=input()\r\nc1=input()\r\nb=[]\r\nc=[]\r\nb.extend(b1)\r\nc.extend(c1)\r\nfor i in range(a):\r\n if abs(int(b[i])-int(c[i]))<(10-max(int(b[i]),int(c[i]))+min(int(b[i]),int(c[i]))):\r\n sum+=abs(int(b[i])-int(c[i]))\r\n else:\r\n sum+=10-max(int(b[i]),int(c[i]))+min(int(b[i]),int(c[i]))\r\nprint(sum)", "n = int(input())\r\na = list(map(int,input()))\r\nb = list(map(int,input()))\r\nsum = 0\r\nfor i in range(0,n):\r\n sum += min(abs(a[i] - b[i]),(10-abs( a[i] -b[i])))\r\nprint(sum)", "n=int(input())\r\na=input()\r\nb=input()\r\ns=0\r\nr=[]\r\nt=[]\r\np=[]\r\nq=0\r\nfor i in range(n):\r\n d=int(a[i])\r\n while d%10!=int(b[i]):\r\n d+=1\r\n s+=1\r\n r+=[s]\r\n s=0\r\n d=int(a[i])\r\n e=int(b[i])\r\n while e%10!=d:\r\n e+=1\r\n s+=1\r\n p+=[s]\r\n s=0\r\n t+=[abs(int(a[i])-int(b[i]))]\r\nfor j in range(n):\r\n q+=min(r[j],p[j],t[j])\r\nprint(q)\r\n", "n = int(input())\r\np = list(map(int, input()))\r\nk = list(map(int, input()))\r\ncount = 0\r\nfor i in range(len(p)):\r\n count += min(max(p[i], k[i]) - min(p[i], k[i]), 10 - max(p[i], k[i]) + min(p[i], k[i]))\r\nprint(count)", "def solve(x, y):\r\n res = 0\r\n for i in range(len(x)):\r\n c = abs(int(x[i])-int(y[i]))\r\n if c > 5:\r\n mn = min(int(x[i]), int(y[i]))\r\n mx = max(int(x[i]), int(y[i]))\r\n res += ((mn+10) - mx)\r\n else:\r\n res += abs(int(x[i])-int(y[i]))\r\n \r\n \r\n return res\r\nn = int(input())\r\n\r\nx = input()\r\ny = input()\r\n\r\nprint(solve(x, y))", "\r\n\r\n\r\ndef combination():\r\n\r\n\r\n num_disks = int(input())\r\n\r\n\r\n original_states = map(int,input())\r\n needed_states = map(int,input()) \r\n\r\n total = 0\r\n for original,needed in zip(original_states,needed_states):\r\n\r\n diff_1 = (original - needed) % 10\r\n diff_2 = (needed - original) % 10\r\n\r\n min_diff = min(diff_1,diff_2)\r\n total += min_diff\r\n\r\n\r\n print(total)\r\n\r\n\r\n\r\n\r\n\r\ncombination()\r\n", "s = '0123456789';\r\n\r\nlength = int(input())\r\ncurrent_num = input();\r\ninput_password = input();\r\n\r\nresult = 0;\r\n\r\nfor i in range(length):\r\n index = s.find(current_num[i]);\r\n start = s[0:index];\r\n end = s[index::];\r\n \r\n temp_str = end+start;\r\n \r\n back = temp_str[::-1].index(input_password[i]);\r\n front = temp_str.index(input_password[i])\r\n if(back <= front):\r\n result += back +1;\r\n else:\r\n result += front;\r\nprint(result);", "input()\nw = map(int, input())\nc = map(int, input())\ns = 0\nfor a, b in zip(w, c):\n d = abs(a - b)\n s += min(10 - d, d)\nprint(s)\n", "input();x=0\r\nfor i,j in [sorted([int(x),int(y)])for x,y in zip(input(),input())]:x+=min(j-i,10-j+i)\r\nprint(x)", "a = int(input())\r\nb=input()\r\nc=input()\r\no=0\r\nfor x in range(a):\r\n f=int(b[x])\r\n d=int(c[x])\r\n if f<d:\r\n g=d-f\r\n else:\r\n g=f-d\r\n if g>5:\r\n g=10-g\r\n o+=g\r\nprint(o)", "n=int(input())\r\nx=input()\r\ny=input()\r\ns=0\r\na=[0,9,8,7,6,5]\r\nx2=[]\r\ny2=[]\r\nfor i in x:\r\n x2=x2+[int(i)]\r\nfor i in y:\r\n y2=y2+[int(i)]\r\nfor i in range(n):\r\n if abs(x2[i]-y2[i])<5:\r\n s=s+abs(x2[i]-y2[i])\r\n elif abs(x2[i]-y2[i])>=5:\r\n s=s+a.index((abs(x2[i]-y2[i])))\r\nprint(s)\r\n", "n = int(input())\r\na = list(map(int, input()))\r\nd = list(map(int, input()))\r\ncol = 0\r\nfor i in range(len(a)):\r\n one = max(a[i], d[i]) - min(a[i], d[i])\r\n two = a[i] + (10 - d[i])\r\n tree = (10 - a[i]) + d[i]\r\n col += min(one, two, tree)\r\nprint(col)", "t=int(input())\r\nch1=input()\r\nch2=input()\r\nsomme=0\r\nfor i in range(len(ch1)):\r\n if abs(int(ch2[i])-int(ch1[i]))>5:\r\n somme+=10-abs(int(ch2[i])-int(ch1[i]))\r\n else:\r\n somme+=abs(int(ch2[i])-int(ch1[i]))\r\nprint(somme)", "n=int(input())\r\na=input()\r\nb=input()\r\nc=0\r\nd=0\r\ne=0\r\nfor i in range(n):\r\n d=abs( int(a[i]) - int(b[i]) )\r\n # print(d,end=\" \")\r\n e=10- abs((int(a[i]) - int(b[i])))\r\n c+=min(d,e)\r\n # print(e)\r\nprint(c)", "n = int(input())\r\nx = list(map(int, input()))\r\ny = list(map(int, input()))\r\ns = 0\r\nfor i in range(n):\r\n s += min(abs(x[i] - y[i]), 10 - abs(x[i] - y[i]))\r\nprint(s)", "def solve(n, a, b):\r\n\r\n count = 0\r\n\r\n for i in range(n):\r\n dif = abs(a[i] - b[i])\r\n dif2 = 10 - dif\r\n count += min(dif, dif2)\r\n\r\n return count\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n, a, b = int(input()), list(map(int, list(input()))), list(map(int, list(input())))\r\n print(solve(n, a, b))", "#!/bin/python3\n\ndef clac_distnace_on_lock(x: str, y: str) -> int:\n diff = abs(int(x) - int(y))\n return min(diff, 10 - diff)\n\ndef main():\n length, in1, in2 = int(input()), input(), input()\n print(sum([clac_distnace_on_lock(in1[i], in2[i]) for i in range(length)]))\n\nif __name__ == \"__main__\":\n main()\n", "#from collections import Counter\r\n#import math\r\n'''\r\nt=int(input())\r\nans=list()\r\ne=sorted('Timur')\r\nfor _ in range(t):\r\n _=input()\r\n n=sorted(input())\r\n if n==e:ans.append('YES')\r\n else:ans.append('NO')\r\nprint(*ans,sep='\\n')'''\r\nn=int(input())\r\na=list(map(int,list(input())))\r\nb=list(map(int,list(input())))\r\nt=0\r\nfor i in range(n):\r\n e=abs(a[i]-b[i])\r\n t+=min(e,10-e)\r\nprint(t)\r\n\r\n", "n=int(input())\r\nstart=input()\r\nfinal=input()\r\nsum=0\r\nfor i in range(n):\r\n x=abs(int(start[i])-int(final[i]))\r\n sum+=min(x,10-x)\r\nprint(sum)\r\n ", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nc=0\r\nfor i in range(n):\r\n\td=abs(int(s2[i])-int(s1[i]))\r\n\t\r\n\tc+=min(abs(10-d),d)\r\nprint(c)", "import sys\r\ni=1\r\nfor line in sys.stdin:\r\n if i==1:\r\n disk=int(line)\r\n elif i==2:\r\n start=line\r\n else:\r\n end=line\r\n break\r\n i+=1\r\nstartlist=[]\r\nendlist=[]\r\nfor num in start:\r\n\tif num!=\"\\n\":\r\n\t\tstartlist.append(num)\r\nfor num in end:\r\n\tif num!=\"\\n\":\r\n\t\tendlist.append(num)\r\ntotal=0\r\ni=0\r\nwhile i<disk:\r\n\tif startlist[i]>endlist[i]:\r\n\t\tright=10-int(startlist[i])+int(endlist[i])\r\n\t\tleft=int(startlist[i])-int(endlist[i])\r\n\t\tif right<left:\r\n\t\t\ttotal+=right\r\n\t\telse:\r\n\t\t\ttotal+=left\r\n\telif startlist[i]<endlist[i]:\r\n\t\tright=int(endlist[i])-int(startlist[i])\r\n\t\tleft=10-int(endlist[i])+int(startlist[i])\r\n\t\tif right<left:\r\n\t\t\ttotal+=right\r\n\t\telse:\r\n\t\t\ttotal+=left\r\n\ti+=1\r\nprint(total)\r\n", "inp = int(input())\r\ninp1 = input()\r\ninp2 = input()\r\ncounter = 0\r\nfor x in range(inp):\r\n if inp1[x] > inp2[x]:\r\n up = (10 - int(inp1[x])) + int(inp2[x])\r\n down = abs(int(inp1[x])-int(inp2[x]))\r\n if up < down:\r\n counter += up\r\n else:\r\n counter += down\r\n else:\r\n up = (10 - int(inp2[x])) + int(inp1[x])\r\n down = abs(int(inp1[x]) - int(inp2[x]))\r\n if up < down:\r\n counter += up\r\n else:\r\n counter += down\r\nprint(counter)\r\n", "size = int(input())\nsta_num = str(input())\ncal_number = str(input())\ncou = 0\n\nfor i in range(len(sta_num)):\n s = int(sta_num[i])\n c = int(cal_number[i])\n if s==c:\n pass\n elif s>c:\n\n tem = 10+c\n n_tm = s-c\n\n if tem-s < n_tm:\n cou += tem-s\n\n\n else:\n cou +=n_tm\n\n elif s<c:\n tem = s+10\n n_tm = c-s\n\n if tem - c < n_tm:\n cou += tem-c\n\n else:\n cou += n_tm\nprint(cou)\n", "# your code goes here\r\nn=int(input())\r\nl=['0','1','2','3','4','5','6','7','8','9']\r\ns=input()\r\ns1=input()\r\nsm=0\r\nfor i in range(len(s)):\r\n\ta=l.index(s[i])\r\n\tl1=l[a:]+l[:a]\r\n\tl2=l[a+1:]+l[:a+1]\r\n\tx=abs(l1.index(s[i])-l1.index(s1[i]))\r\n\ty=abs(l2.index(s[i])-l2.index(s1[i]))\r\n\tsm+=min(x,y)\r\nprint(sm)\r\n\t\r\n\t", "from math import fabs\r\n\r\n\r\ndef minDistance(n1, n2):\r\n change = {6: 4, 7: 3, 8: 2, 9: 1}\r\n distance = int(fabs(int(n1) - int(n2)))\r\n if distance <= 5:\r\n return distance\r\n return change[distance]\r\n\r\n\r\nn = int(input())\r\nlocked = input()\r\nunlocked = input()\r\n\r\nresult = 0\r\nfor i in range(n):\r\n result += minDistance(locked[i], unlocked[i])\r\n\r\nprint(result)\r\n", "a = int(input())\r\nb = list(input())\r\nc = list(input())\r\nsum = 0\r\nfor i in range(len(c)):\r\n bc1 = int(max(b[i],c[i])) - int(min(b[i],c[i])) \r\n bc2 = int(min(b[i],c[i])) + (9 - int(max(b[i],c[i]))) + 1\r\n sum += min(bc1, bc2)\r\nprint(sum)\r\n", "class solution:\r\n def __init__(self,n1,n2,n3):\r\n self.n1 = n1\r\n self.n2 = n2\r\n self.n3 = n3\r\n self.answer = 0\r\n def caluclation(self):\r\n for i in range(n1):\r\n if int(n2[i]) >= int(n3[i]):\r\n tar = int(n3[i])\r\n sm = int(n2[i])\r\n else:\r\n tar = int(n2[i])\r\n sm = int(n3[i])\r\n if abs(int(n2[i]) - int(n3[i])) > tar + 10 - sm:\r\n self.answer = self.answer + tar + 10 - sm\r\n \r\n else:\r\n self.answer = self.answer + abs(int(n2[i]) - int(n3[i]))\r\n \r\n\r\n\r\n\r\nn1 = int(input())\r\nn2 = input()\r\nn3 = input()\r\nroot = solution(n1,n2,n3)\r\nroot.caluclation()\r\nprint(root.answer)\r\n", "n = int(input())\n##s = list(map(int,input().split()))\n##c = list(map(int,input().split()))\ns = int(input())\nc = int(input())\ns1 = []\nc1 = []\na1 = 0\nfor i in range(n):\n c1.append(c%10)\n c = c//10\n s1.append(s%10)\n s = s//10\n\nfor i in range(n):\n \n a = abs(s1[i]-c1[i]) \n if a > 5:\n a1 = a1+(10-a)\n else:\n a1 = a1+a\nprint(a1) \n \n \n \n\n \n \n \n \n \n\n\n \n\n", "n=int(input())\r\ns=input()\r\nt=input()\r\nk=0\r\nfor i in range(n):\r\n d=int(s[i])\r\n e=int(t[i])\r\n l=abs(d-e)\r\n if(l>5):\r\n k+=(10-l)\r\n else:\r\n k+=l\r\nprint(k)\r\n ", "def min_moves_to_open_lock(n, original, combination):\r\n total_moves = 0\r\n for i in range(n):\r\n diff = abs(int(original[i]) - int(combination[i]))\r\n total_moves += min(diff, 10 - diff)\r\n return total_moves\r\n\r\nn = int(input())\r\noriginal_state = input()\r\ncombination = input()\r\nprint(min_moves_to_open_lock(n, original_state, combination))\r\n", "n = input()\r\no = input()\r\nc = input()\r\ntotal = 0\r\nfor i in range(int(n)):\r\n diff = abs(int(o[i]) - int(c[i]))\r\n if diff > 10 - diff:\r\n total += 10 - diff\r\n else:\r\n total += diff\r\nprint(total)\r\n", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\nsum = 0\r\nfor i in range(n):\r\n x = abs((int(s1[i])-int(s2[i])))\r\n if(x > 5):\r\n l = (9-int(s2[i]))+int(s1[i])+1\r\n u = (9-int(s1[i]))+int(s2[i])+1\r\n x = min(l,u)\r\n sum += x\r\n #print(x)\r\n\r\nprint(sum)", "n = int(input())\ns1 = input()\ns2 = input()\nd = 0\nfor i in range(n):\n number1 = int(s1[i])\n number2 = int(s2[i])\n d1 = abs(number1 - number2)\n d2 = 10 - number1 + number2\n d3 = 10 - number2 + number1\n d += min(d1,d2,d3)\nprint(d)\n", "n=int(input())\r\na=input()\r\nb=input()\r\ns=0\r\nfor i in range(n):\r\n t=abs(int(a[i])-int(b[i]))\r\n s+=min(t,10-t)\r\nprint(s)", "length = int(input())\r\n\r\nn = input()\r\n\r\nm = input()\r\n\r\n##flow = ''\r\n\r\nmoves = 0\r\nfor i in range(length):\r\n _startMoves = moves\r\n## flow += 'n: ' + n[i] + ' , m: ' + m[i]\r\n dif = abs(int(n[i]) - int(m[i]))\r\n## flow += ' , dif: ' + str(dif)\r\n\r\n if(dif > 5):\r\n if(int(n[i]) < int(m[i])):\r\n moves += int(n[i]) + 1\r\n n = n[:i] + '9' + n[i + 1:]\r\n dif = abs(int(n[i]) - int(m[i]))\r\n moves += dif\r\n## flow += ' , If 1 Activated , moves: ' + str(moves) + '(+' + str(moves - _startMoves) + ')\\n'\r\n else:\r\n moves += int(m[i]) + 1\r\n m = m[:i] + '9' + m[i + 1:]\r\n dif = abs(int(n[i]) - int(m[i]))\r\n moves += dif\r\n## flow += ' , If 2 Activated , moves: ' + str(moves) + '(+' + str(moves - _startMoves) + ')\\n'\r\n\r\n\r\n else:\r\n moves += dif\r\n## flow += ' , moves: ' + str(moves) + '(+' + str(moves - _startMoves) + ')\\n'\r\n\r\n##print(flow)\r\n\r\nprint(moves)", "input()\r\nmoves = 0\r\nfor original_state, target_state in zip(input(), input()):\r\n non_rounded_distance = abs(int(original_state) - int(target_state))\r\n moves += min(non_rounded_distance, 10 - non_rounded_distance)\r\nprint(moves)", "n=int(input(\"\"))\r\ncombNow = input(\"\")\r\ncomb = input(\"\")\r\nres = 0\r\nfor i in range(0, n):\r\n diff = abs(int(comb[i]) - int(combNow[i]))\r\n if diff < 6:\r\n res += diff\r\n else:\r\n res += 10 - diff\r\nprint(res)\r\n", "n=int(input())\r\na=[int(i) for i in input()]\r\nb=[int(i) for i in input()]\r\ncount=0\r\nfor i in range(len(a)):\r\n count+=min(abs(a[i]-b[i]),10-abs(a[i]-b[i]))\r\nprint(count)", "n = int(input())\r\nl = input()\r\nu = input()\r\nk = 0\r\nfor i in range(n):\r\n c=int((max(l[i], u[i])))-int((min(l[i], u[i])))\r\n if c<=5:\r\n k += c\r\n elif c >5:\r\n k += 10-c\r\nprint(k)", "import sys\r\ninput = sys.stdin.readline\r\n\r\ndef cin():\r\n\treturn(int(input()))\r\ndef cin_():\r\n\treturn(list(map(int,input().split())))\r\n\r\nn = input()\r\n\r\ns1 = input().strip()\r\ns2 = input().strip()\r\nans = 0\r\nfor i in range(len(s1)):\r\n\taux = int(s1[i])\r\n\tif(abs(int(s1[i]) - int(s2[i])) >= 6):\r\n\t\tif(int(s1[i]) < 5): \r\n\t\t\twhile(aux != int(s2[i])):\r\n\t\t\t\taux -= 1\r\n\t\t\t\tans += 1\r\n\t\t\t\tif(aux == -1):\r\n\t\t\t\t\taux = 9\r\n\t\telse:\r\n\t\t\twhile(aux != int(s2[i])):\r\n\t\t\t\taux += 1\r\n\t\t\t\tans += 1\r\n\t\t\t\tif(aux == 10):\r\n\t\t\t\t\taux = 0\r\n\telse:\r\n\t\tans += abs(int(s1[i]) - int(s2[i]))\r\n\t\t\t\t\r\nprint(ans)\r\n", "n=int(input())\r\n\r\na=list(input())\r\nb=list(input())\r\n\r\ns=0\r\nfor i in range(n):\r\n if abs(int(a[i])-int(b[i]))>5:\r\n s=s+10-abs(int(a[i])-int(b[i]))\r\n else:\r\n s=s+abs(int(a[i])-int(b[i]))\r\n\r\nprint(s)", "size = int(input())\norgstr = input()\nansstr = input()\norg= [int(i) for i in orgstr]\nans = [int(i) for i in ansstr]\n\nc=0\ndiff=0\nfor i in range(size):\n if(org[i]>ans[i] and org[i]-ans[i]<=5):\n diff = org[i]-ans[i]\n c=c+diff\n elif(org[i]>ans[i] and org[i]-ans[i]>5):\n diff=(ans[i]+10)-org[i]\n c=c+diff\n elif(ans[i]>org[i] and ans[i]-org[i]<=5):\n diff=ans[i]-org[i]\n c=c+diff\n elif(ans[i]>org[i] and ans[i]-org[i]>5):\n diff=(org[i]+10)-ans[i]\n c=c+diff\nprint(c)\n\t \t\t\t \t \t \t \t\t\t \t\t \t \t\t \t\t \t", "def get_num(start_char, end_char):\r\n numbers = list(map(int, [start_char, end_char]))\r\n return(min([max(numbers) - min(numbers), min(numbers) + 10 - max(numbers)]))\r\n\r\nn = int(input())\r\nstart = input()\r\nend = input()\r\nprint(sum([get_num(start[i], end[i]) for i in range(n)]))", "n=int(input())\r\na=input()\r\nb=input()\r\nsum=0\r\nfor i in range(n):\r\n sum+=min(abs(int(a[i])-int(b[i])),10-abs(int(a[i])-int(b[i])))\r\nprint(sum)\r\n", "n = input()\r\ns1 = input()\r\ns2 = input()\r\nres = 0\r\nfor idx, val in enumerate(s1):\r\n i1 = int(val)\r\n i2 = int(s2[idx])\r\n res += min(abs(i1 - i2), abs(i1 - (10 + i2)), abs((10 + i1) - i2))\r\nprint(res)", "n = int(input())\r\ng = list(input())\r\ns = list(input())\r\na = []\r\nb = []\r\ncount = 0\r\nfor i in g:\r\n a.append(int(i))\r\nfor j in s:\r\n b.append(int(j))\r\nfor k in range(0,n):\r\n v = (min(abs(a[k] - b[k]), 10 - abs(a[k] - b[k])))\r\n count += v\r\nprint(count)", "int(input())\r\nfirst, second = input(), input()\r\ncounter = 0\r\nfor i in range(len(first)):\r\n if int(first[i]) > int(second[i]):\r\n if int(first[i]) - int(second[i]) < (10 - int(first[i]) + int(second[i])):\r\n counter += (int(first[i]) - int(second[i]))\r\n else:\r\n counter += (10 - int(first[i]) + int(second[i]))\r\n elif int(second[i]) > int(first[i]):\r\n if int(second[i]) - int(first[i]) < (10 - int(second[i]) + int(first[i])):\r\n counter += (int(second[i]) - int(first[i]))\r\n else:\r\n counter += (10 - int(second[i]) + int(first[i]))\r\nprint(counter)", "import os, sys, math, cmath, time, collections\nfrom collections import deque, Counter, OrderedDict, defaultdict\nfrom heapq import nsmallest, nlargest, heapify, heappop, heappush, heapreplace\nfrom math import ceil, floor, log, log2, sqrt, gcd, factorial, pow, pi\nfrom bisect import bisect_left, bisect_right\nfrom functools import reduce\n\n\n# SOME GENERAL HELPER\ndef input_as_array(): return list(map(int, input().split()))\n\n\ndef debug():\n if os.path.exists('data.in'):\n print(\"**********************\")\n\n\ndef debug2(value):\n if os.path.exists('data.in'):\n print(value)\n\ndef debug3():\n if os.path.exists('data.in'):\n print(\"-\"* 10)\n\n\nstart_time = time.time()\n\n\ndef solve(s, t, n):\n lock = list(range(0, 10)) + list(range(0, 10))\n hmap = defaultdict(list)\n for i, val in enumerate(lock):\n hmap[val].append(i)\n ans = 0\n for a, b in zip(s, t):\n mx = float('inf')\n for i in hmap[a]:\n for j in hmap[b]:\n mx = min(mx, abs(i-j))\n ans += mx\n print(ans)\n\ndef main():\n n = int(input())\n s = input()\n s = [int(c) for c in s]\n t = input()\n t = [int(c) for c in t]\n solve(s, t, n)\n\nif __name__ == \"__main__\":\n if os.path.exists('data.in'):\n sys.stdin = open(\"data.in\", \"r\")\n sys.stdout = open(\"data.out\", \"w\")\n\n testcases = 1\n for i in range(testcases):\n main()\n\n # If it's local - Print this O/P\n if os.path.exists('data.in'):\n print(f\"Time Elapsed: {time.time() - start_time} seconds\")\n sys.stdout.close()\n", "#https://codeforces.com/problemset/problem/540/A\r\n\r\nn = int(input())\r\nattempt = input()\r\nanswer = input()\r\ntotal = 0\r\nfor x in range(n):\r\n small = min(int(attempt[x]), int(answer[x]))\r\n large = max(int(attempt[x]), int(answer[x]))\r\n total += min([large-small, 10+small-large])\r\nprint(total)", "n = int(input())\r\nd = list(input())\r\nd1 = list(map(int, d))\r\nd2 = list(input())\r\nd2 = list(map(int, d2))\r\nc = 0\r\nfor i in range(n):\r\n while d1[i] != d2[i]:\r\n while d1[i] > d2[i]:\r\n if d1[i]-d2[i] > 5:\r\n while d1[i] < 10:\r\n d1[i] += 1\r\n c += 1\r\n if d1[i] == 10:\r\n d1[i] = 0\r\n while d1[i] != d2[i]:\r\n d1[i] += 1\r\n c += 1\r\n else:\r\n while d1[i] != d2[i]:\r\n d1[i] -= 1\r\n c += 1\r\n while d1[i] < d2[i]:\r\n if d2[i]-d1[i] > 5:\r\n while d1[i] > -1:\r\n d1[i] -= 1\r\n c += 1\r\n if d1[i] == -1:\r\n d1[i] = 9\r\n while d1[i] != d2[i]:\r\n d1[i] -= 1\r\n c += 1\r\n else:\r\n while d1[i] != d2[i]:\r\n d1[i] += 1\r\n c += 1\r\nprint(c)\r\n", "n = int(input())\r\np = input()\r\nk = input()\r\ncount = 0\r\nfor i in range(len(p)):\r\n if max(int(p[i]), int(k[i])) - min(int(p[i]), int(k[i])) < 5:\r\n count += max(int(p[i]), int(k[i])) - min(int(p[i]), int(k[i]))\r\n else:\r\n count += 10 - max(int(p[i]), int(k[i])) + min(int(p[i]), int(k[i]))\r\nprint(count)", "n=int(input())\r\nx=input()\r\ny=input()\r\nX=0\r\nfor i in range(n):\r\n X+=min(abs(int(x[i])-int(y[i])),10-abs(int(x[i])-int(y[i])))\r\nprint(X)\r\n", "n=int(input())\r\ninst=input().strip()\r\nfist=input().strip()\r\nmoves=0\r\ni=0\r\nwhile i<n:\r\n x=abs(int(fist[i])-int(inst[i]))\r\n if x>5:\r\n x=10-x\r\n moves += x\r\n i=i+1\r\nprint(moves)", "n = int(input())\r\nstart = input()\r\nend = input()\r\nstart = [int(x) for x in start]\r\nend = [int(x) for x in end]\r\nmoves = [0] * n\r\nfor i in range(n):\r\n diff = abs(end[i] - start[i])\r\n moves[i] = min(diff, 10 - diff)\r\nprint(sum(moves))\r\n", "l = int(input())\r\no_l = input()\r\nw_l = input()\r\ns = 0\r\n\r\nfor i in range(l):\r\n s += min((10 + int(o_l[i]) - int(w_l[i])) % 10, (10 + int(w_l[i]) - int(o_l[i])) % 10)\r\n \r\nprint(s)", "n = int(input())\r\nc = input()\r\na = input()\r\nans = 0\r\n\r\ndef dis(x,y):\r\n flag = 0\r\n q = x\r\n r = 0\r\n if x==y:\r\n return 0;\r\n else:\r\n while x!=y:\r\n r = r + 1\r\n if q==9:\r\n q=0\r\n else:\r\n q = q + 1\r\n if r>5:\r\n flag = 1\r\n r = 0\r\n q = x\r\n break\r\n if q==y:\r\n return r\r\n \r\n if flag == 1:\r\n while x!=y:\r\n r = r + 1\r\n if q==0:\r\n q=9\r\n else:\r\n q = q - 1\r\n if q==y:\r\n return r\r\n \r\nfor i,j in zip(c,a):\r\n i = int(i)\r\n j = int(j)\r\n ans = ans + dis(i,j)\r\n\r\nprint(ans)", "q = int(input())\r\nw = input()\r\ne = input()\r\nh = 0\r\nfor i in range(q):\r\n r = int(w[i])\r\n t = int(e[i])\r\n h += min(max(r, t) - min(r, t), min(r, t) + 10 - max(r, t))\r\nprint(h)", "n=int(input())\r\na=input()\r\na=list(a)\r\nb=input()\r\nb=list(b)\r\nc=0\r\nfor i in range(n):\r\n d=abs(int(a[i])-int(b[i]))\r\n if d<=5:\r\n c=c+d\r\n else:\r\n c=c+10-d\r\nprint(c)", "n=int(input())\r\n\r\na=input('')\r\nb=input('')\r\ny=0\r\nfor i in range(0,n):\r\n s=int(a[i])-int(b[i])\r\n if s>5:\r\n sm=10-s\r\n elif s<0:\r\n sm=s*(-1)\r\n else:\r\n sm=s\r\n x=min(sm,s+10)\r\n y+=x\r\nprint(y)", "t=int(input())\r\nl=input()\r\nm=input()\r\nl=[int(x) for x in str(l)]\r\nm=[int(x) for x in str(m)]\r\ncnt=0\r\nfor i in range(0,t):\r\n a=max(l[i],m[i])\r\n b=min(l[i],m[i])\r\n if a-b>5:\r\n cnt=cnt+10-a+b\r\n else:\r\n cnt=cnt+a-b \r\nprint(cnt)\r\n\r\n \r\n", "import sys\r\nfrom sys import stdin,stdout\r\nimport math\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\n\r\ndef code(n,p,q):\r\n c = 0\r\n a = list(map(int, p))\r\n b = list(map(int, q))\r\n for i in range(n):\r\n c+=min(abs(a[i]-b[i]),min(abs(10-(b[i]-a[i])),abs(10-(a[i]-b[i]))))\r\n return c\r\n\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n p = get_string()\r\n q = get_string()\r\n ans = code(n,p,q)\r\n print(ans)\r\n", "# JAI SHREE RAM\r\n\r\nimport math; from collections import *\r\nimport sys; from functools import reduce\r\n\r\n# sys.setrecursionlimit(10**6)\r\ndef get_ints(): return map(int, input().strip().split())\r\ndef get_list(): return list(get_ints())\r\ndef get_string(): return list(input().strip().split())\r\ndef printxsp(*args): return print(*args, end=\"\")\r\ndef printsp(*args): return print(*args, end=\" \")\r\n\r\nUGLYMOD = int(1e9)+7; SEXYMOD = 998244353; MAXN = int(1e5)\r\n\r\n# sys.stdin=open(\"input.txt\",\"r\");sys.stdout=open(\"output.txt\",\"w\")\r\n\r\n# for _testcases_ in range(int(input())):\r\nn = int(input())\r\ns = input()\r\nt = input()\r\nans = 0\r\nfor i in range(n):\r\n first = int(s[i])\r\n secon = int(t[i])\r\n diff = max(first, secon) - min(first, secon)\r\n ans += min(diff, 10-diff)\r\nprint(ans)\r\n\r\n'''\r\n>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!\r\nTHE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA )\r\nLink may be copy-pasted here if it's taken from other source.\r\nDO NOT PLAGIARISE.\r\n>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!\r\n'''", "n=int(input())\r\nl=[0,1,2,3,4,5,6,7,8,9]\r\nl1=list(input())\r\nl2=list(input())\r\nfor i in range(n):\r\n l1[i]=int(l1[i])\r\n l2[i]=int(l2[i])\r\nc=0\r\nfor i in range(n):\r\n if l.index(l1[i])>=l.index(l2[i]):\r\n c+=min(abs(l.index(l1[i])-l.index(l2[i])),10+l.index(l2[i])-l.index(l1[i]))\r\n else:\r\n c+=min(abs(l.index(l1[i])-l.index(l2[i])),10+l.index(l1[i])-l.index(l2[i]))\r\n \r\nprint(c)\r\n", "n = int(input())\r\npos = input()\r\ncode = input()\r\ncounter = 0\r\nfor i in range(n):\r\n if abs(int(code[i]) - int(pos[i])) < 5:\r\n counter += abs(int(pos[i]) - int(code[i]))\r\n else:\r\n counter += 10 - abs(int(pos[i]) - int(code[i]))\r\nprint(counter)", "l=int(input())\r\na=input()\r\nb=input()\r\nsu=0\r\nfor f in range(l):\r\n j=int(a[f])\r\n k=int(b[f])\r\n q1=abs(j-k)\r\n q2=10-q1\r\n if q1<q2:\r\n su+=q1\r\n else:\r\n su+=q2\r\nprint(su)", "def main():\r\n\tdisks = int(input())\r\n\tl = [int(i) for i in input()]\r\n\tk = [int(i) for i in input()]\r\n\tans = [abs(l[i] - k[i]) if abs(l[i] - k[i]) <= 5 \\\r\n\telse int('1'+str(min(l[i],k[i]))) - max(l[i], k[i]) for i in range(disks)]\r\n\t\r\n\tprint(sum(ans))\r\nmain()\r\n\r\n\r\n\r\n#Answer is x combination - abs(y) combination\r\n#if Answer is more than 5, max(x,y) increase by 10 and then\r\n#the answer is x - abs(y) again.", "n = int(input())\r\nx = input()\r\ny = input()\r\nlst_org = []\r\nlst_pass = []\r\ncount = 0\r\nfor i in range(n):\r\n lst_org.append(ord(x[i]))\r\n lst_pass.append(ord(y[i]))\r\nfor j in range(n):\r\n if abs(lst_org[j] - lst_pass[j]) < 5:\r\n count += abs(lst_org[j] - lst_pass[j])\r\n else:\r\n count += 10 - abs(lst_org[j] - lst_pass[j])\r\nprint(count)", "n = int(input())\r\ncurrent_state = [int(x) for x in list(input())]\r\nopen_state = [int(x) for x in list(input())]\r\nc = 0\r\nfor i in range(n):\r\n c += min([9 - current_state[i] + 1 + open_state[i], abs(current_state[i] - open_state[i]),\r\n current_state[i] + 1 + 9 - open_state[i]])\r\nprint(c)", "n=int(input())\r\nx=input()\r\ny=input()\r\n\r\nans=0\r\nfor i in range(n):\r\n val=abs(int(x[i]) - int(y[i]))\r\n val = min(val,10-val)\r\n ans+=val\r\n\r\nprint(ans)", "n=int(input())\r\na,b=input(),input()\r\nsuma=0\r\nfor i in range(0,n):\r\n x=int(a[i])\r\n y=int(b[i])\r\n suma+=min(x-y,10-x+y) if x>y else min(x+10-y,y-x)\r\nprint(suma)\r\n", "n=int(input())\r\nn1=' '.join(input()).split()\r\nn2=' '.join(input()).split()\r\na='6789012345'\r\ns=0\r\nfor i in range(n):\r\n if abs(int(n2[i])-int(n1[i]))>5:\r\n c=a.index(n1[i])-a.index(n2[i])\r\n c=abs(c)\r\n s+=c\r\n else:\r\n c=int(n2[i])-int(n1[i])\r\n c=abs(c)\r\n s+=c\r\nprint(s)\r\n \r\n \r\n \r\n", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nk=0\r\nfor i in range(n):\r\n d=abs(int(s1[i])-int(s2[i]))\r\n k+=min(d,10-d)\r\nprint(k)", "from sys import stdin\nfrom math import fabs\n\nn = int(stdin.readline())\na = stdin.readline().strip()\nb = stdin.readline().strip()\ns = 0\nfor i in range(n):\n\tbi = int(b[i])\n\tai = int(a[i])\n\tarr = [fabs(bi - ai), 10 - bi + ai, 10 - ai + bi]\n\ts += min(arr)\nprint(int(s))\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\nlst1= list(map(int,input()))\r\nlst2=list(map(int,input()))\r\ncnt=0\r\nres=0\r\n\r\nzip_object=zip(lst1,lst2)\r\nfor i,j in zip_object:\r\n res=abs(i-j)\r\n if(res<=5):\r\n cnt+=res\r\n else:\r\n cnt+=(10-res)\r\n\r\nprint(cnt)", "n =int(input())\r\na =list(map(int ,input()))\r\nb =list(map(int, input()))\r\n\r\nres =0\r\nfor i in range(n):\r\n if a[i] > b[i]:\r\n if a[i] - b[i] < 5:\r\n res+= a[i] - b[i]\r\n\r\n elif a[i] - b[i] >=5:\r\n while a[i] != 9:\r\n res+=1\r\n a[i] +=1\r\n if a[i] == 9:\r\n res+=1\r\n c = b[i]\r\n res+=c\r\n elif b[i] >a[i]:\r\n if b[i] - a[i] <5:\r\n res+= b[i] - a[i]\r\n\r\n elif b[i] -a[i] >=5:\r\n while b[i] != 9:\r\n res+=1\r\n b[i] +=1\r\n if b[i] == 9:\r\n res+=1\r\n c =a[i]\r\n res+=c\r\n else:\r\n res+=0\r\nprint(res)", "n = int(input())\r\ns1,s2 = input(),input()\r\nres = 0\r\nfor i in range(n):\r\n a,b = int(s1[i]),int(s2[i])\r\n if a<=b:\r\n ans = b-a\r\n if a+1+9-b < ans:\r\n ans = a+1+9-b\r\n else:\r\n ans = a-b\r\n if 9-a+1+b < ans:\r\n ans = 9-a+1+b\r\n res+=ans\r\nprint(res)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat Jul 18 02:47:29 2020\r\n\r\n@author: DELL\r\n\"\"\"\r\nn=int(input())\r\ns1=input()\r\ns2=input()\r\nc=0\r\nimport math\r\nfor i in range(len(s1)):\r\n o=math.fabs(int(s1[i])-int(s2[i])) \r\n if o< 10-o:\r\n c+=o\r\n elif o>10-o:\r\n c+=(10-o)\r\n else:\r\n c+=o\r\nprint(int(c))", "n = int(input())\r\n\r\nlist1 = list(input())\r\nlist2 = list(input())\r\n\r\nlist1 = list(map(int, list1))\r\nlist2 = list(map(int, list2))\r\n\r\nsum = 0\r\n\r\nfor i in range(len(list1)):\r\n key = abs(list1[i] - list2[i])\r\n minma = min(list1[i], list2[i])\r\n maxma = max(list1[i], list2[i])\r\n key2 = 10 + minma - maxma\r\n \r\n sum = sum + min(key, key2)\r\n \r\nprint(sum)\r\n \r\n \r\n \r\n \r\n", "n = int(input())\nnumo = input()\nnumc = input()\nsum = 0\nfor i in range(n):\n v = abs(int(numo[i]) - int(numc[i]))\n if 2*v <= 10:\n sum = sum + v\n else:\n sum = sum + 10 - v\nprint(sum)\n\n\t \t\t \t\t \t\t \t \t \t\t \t \t\t\t", "n = int(input())\na = input()\nb = input()\nans = 0\nfor i in range(n):\n x = abs(int(a[i])-int(b[i]))\n ans += min(x, 10-x) \nprint(ans)", "n=int(input())\r\ns1=input()\r\ns2=input()\r\nc=0\r\nfor i in range(n):\r\n a=abs(int(s1[i])-int(s2[i]))\r\n if a<=5:\r\n c+=a\r\n else:\r\n c+=10-a\r\nprint(c)", "input();print(sum(min(abs(x-y),10-abs(x-y))for x,y in zip(map(int,input()),map(int,input()))))\r\n", "import math\r\nn = int(input())\r\ns = input()\r\ng = input()\r\na = []\r\nb = []\r\n\r\nfor i in range(len(s)):\r\n a.append(s[i])\r\n \r\nfor i in range(len(g)):\r\n b.append(g[i]) \r\n \r\na = [int(x) for x in a]\r\nb = [int(x) for x in b]\r\n\r\nw = []\r\n\r\nfor t in range(0, n):\r\n if abs(a[t] - b[t]) > 5:\r\n w.append(10 - abs(a[t] - b[t]))\r\n elif abs(a[t] - b[t]) <= 5:\r\n w.append(abs(a[t] - b[t]))\r\n\r\nsum = 0\r\nfor u in w:\r\n sum = sum + u\r\n \r\nprint(sum)\r\n \r\n ", "import math\r\n\r\ndlugoscKodu = int(input())\r\nobecnyStan = input()\r\nklucz = input()\r\nsuma = 0\r\nif len(obecnyStan) and len(klucz) == dlugoscKodu:\r\n for x in range(len(obecnyStan)):\r\n if math.fabs(int(obecnyStan[x]) - int(klucz[x])) > 5:\r\n wiekszy = 0\r\n mniejszy = 0\r\n if int(obecnyStan[x]) > int(klucz[x]):\r\n wiekszy = int(obecnyStan[x])\r\n mniejszy = int(klucz[x])\r\n suma += (10 - wiekszy) + mniejszy\r\n elif int(obecnyStan[x]) < int(klucz[x]):\r\n wiekszy = int(klucz[x])\r\n mniejszy = int(obecnyStan[x])\r\n suma += (10 - wiekszy) + mniejszy\r\n\r\n\r\n else:\r\n suma += math.fabs(int(obecnyStan[x]) - int(klucz[x]))\r\nprint(int(suma))\r\n", "def __solve(srcInt, tgtInt):\n srcInt = int(srcInt)\n tgtInt = int(tgtInt)\n clockwisePath = abs(srcInt - tgtInt)\n antiClockwisePath = 10 - abs(srcInt - tgtInt)\n return clockwisePath if (clockwisePath < antiClockwisePath) else antiClockwisePath\n\nno_combinations = 0\nno_combinations = input()\nsource_combination = input()\ntarget_combination = input()\nsum = 0\nfor i in range(len(source_combination)):\n sum += __solve(source_combination[i], target_combination[i])\nprint(sum)", "v=0\r\ns=int(input())\r\na=input()\r\nb=input()\r\nfor k in range(s):\r\n c=a[k]\r\n d=b[k]\r\n c=int(c)\r\n d=int(d)\r\n if max(c,d)-min(c,d)>(min(c,d)+10)-max(c,d):\r\n v+=(min(c,d)+10)-max(c,d)\r\n else:\r\n v+=max(c,d)-min(c,d)\r\nprint(v)\r\n", "input()\na = input()\nb = input()\n\nsteps = 0\nfor i, j in zip(a, b):\n x = abs(int(i)-int(j))\n if x > 5:\n steps += 10- x\n else:\n steps += x\n\nprint(steps)\n", "#540A - Combination Lock\r\nx,y,z,c=int(input()),input(),input(),0\r\nfor i in range(x):\r\n a=abs(int(y[i])-int(z[i]))\r\n c+=min(a,10-a)\r\nprint(c)", "x = int(input())\r\nst1 = input()\r\nst2 = input()\r\nans = 0\r\nfor i in range(x):\r\n res = min((max(int(st1[i]), int(st2[i]))-min(int(st1[i]), int(st2[i]))),\r\n ((min(int(st1[i]), int(st2[i]))+10)-max(int(st1[i]), int(st2[i]))))\r\n ans += res\r\nprint(ans)\r\n", "n=int(input())\r\nlst1=input()\r\nstart=[]\r\nfor i in lst1:\r\n start.append(i)\r\nlst2=input()\r\nfinal=[]\r\nfor i in lst2:\r\n final.append(i)\r\ntot_count=0\r\nfor i in range(0,n):\r\n if(abs(int(start[i])-int(final[i]))>5):\r\n tot_count=tot_count+(10-abs(int(start[i])-int(final[i])))\r\n else:\r\n tot_count=tot_count+abs(int(start[i])-int(final[i]))\r\nprint(tot_count)", "n = int(input())\r\nn1 = input()\r\nn2 = input()\r\nl1 = [int(x) for x in n1]\r\nl2 = [int(x) for x in n2]\r\nl3 = []\r\ni = 0\r\nfor i in range(0,n):\r\n res = abs(l1[i]-l2[i])\r\n l3.append(min(res,10-res))\r\nprint(sum(l3))", "n = int(input())\r\nx = input()\r\ny = input()\r\nit = 0\r\nfor i in range(n):\r\n a, b = int(x[i]), int(y[i])\r\n it += min(abs(a - b), abs(10 - a) + b, abs(10 - b) + a)\r\nprint(it)", "n = int(input())\r\ns= input()\r\nl=input()\r\nres=0\r\nfor i in range(n):\r\n x=abs(int(s[i])-int(l[i]))\r\n y=10-x\r\n res+=min(x,y)\r\nprint(res)\r\n", "n=int(input())\r\ns=input()\r\nx=input()\r\nc=0\r\nfor i in range(n):\r\n d=0\r\n e=0\r\n a=int(s[i])\r\n b=int(x[i])\r\n for j in range(10):\r\n if a==b:\r\n break\r\n a+=1\r\n d+=1\r\n if a>9:\r\n a=0\r\n a = int(s[i])\r\n b = int(x[i])\r\n for j in range(10):\r\n if a==b:\r\n break\r\n a-=1\r\n e+=1\r\n if a<0:\r\n a=9\r\n c+=min(d,e)\r\nprint(c)\r\n", "import sys\n\nsys.stdin.readline()\n\nstart = list(sys.stdin.readline())\n\nend = list(sys.stdin.readline())\n\nsums = 0\n\nfor a, b in zip(start[:-1], end):\n k = (10 + int(a) - int(b)) % 10\n l = (10 - int(a) + int(b)) % 10\n sums += min(abs(k), abs(l))\nprint(sums)\n", "n = int(input())\norig = input()\ncomb = input()\n\nmoves = 0\nfor i in range(n):\n l = abs(int(orig[i]) - int(comb[i]))\n moves += l if l <= 5 else 10 - l\nprint(moves)\n\t \t \t \t \t\t\t \t\t\t\t \t \t", "n = int(input())\r\na = str(input())\r\nb = str(input())\r\n\r\ntotal = 0\r\nfor i in range(n):\r\n if abs(int(a[i]) - int(b[i])) < 6:\r\n total += abs(int(a[i]) - int(b[i]))\r\n else:\r\n if int(a[i]) < 5:\r\n total += abs(10 + int(a[i]) - int(b[i]))\r\n else:\r\n total += abs(-10 + int(a[i]) - int(b[i]))\r\n\r\n\r\nprint(total)", "n=int(input())\r\nn1=input()\r\nn2=input()\r\nc=0\r\nfor i in range(n):\r\n l=[]\r\n if int(n1[i])<int(n2[i]):\r\n l=[int(n2[i])-int(n1[i]),int(n1[i]) +(10-int(n2[i]))]\r\n c=c+min(l)\r\n elif int(n1[i])>int(n2[i]):\r\n l=[int(n1[i])-int(n2[i]),int(n2[i]) +(10-int(n1[i]))]\r\n c=c+min(l)\r\nprint(c)", "x=int(input(\"\"))\r\ny=input(\"\")\r\nz=input(\"\")\r\nj=[]\r\nk=[]\r\nfor i in y:\r\n\ti=int(i)\r\n\tj.append(i)\r\nfor i in z:\r\n\ti=int(i)\r\n\tk.append(i)\r\nc=0\r\nh=0\r\nfor i in range(x):\r\n\ta= abs(j[h]-k[h])\r\n\tb=min(a, 10-a)\r\n\tc += b\r\n\th+=1\r\nprint(c)", "n, m, o = int(input()), input(), input()\r\nans = 0\r\nfor i in range(n):\r\n a, b = int(m[i]), int(o[i])\r\n if a > b:\r\n ans += min(a - b, b + 10 - a)\r\n else:\r\n ans += min(b - a, a + 10 - b)\r\nprint(ans)\r\n", "n=int(input())\r\na1=input()\r\na2=input()\r\nans = 0\r\nfor i in range(len(a1)):\r\n a,b=int(a1[i]), int(a2[i])\r\n ans += min(abs(a-b), 10-abs(a-b))\r\nprint (ans)\r\n ", "n = int(input())\r\ncurrent = tuple(map(int,list(input())))\r\ntogo = tuple(map(int,list(input())))\r\ncount = 0\r\nfor i in range(n):\r\n diff = abs(current[i] - togo[i])\r\n if (diff > 5):\r\n if (current[i] <= 4):\r\n count += current[i] + abs(10-togo[i])\r\n else:\r\n count += togo[i] + abs(10-current[i])\r\n else:\r\n count += diff\r\nprint(count)", "n=int(input())\nnow=list(map(int,input()))\nans=list(map(int,input()))\nsum=0\nfor i in range(len(now)):\n steps = abs(now[i]-ans[i])\n if steps > 5:\n steps = 10-steps\n sum += steps\nprint(sum)\n", "n=int(input())\na=list(map(int,input()))\nb=list(map(int,input()))\nans=0\nfor x,y in zip(a,b):\n x,y=min(x,y),max(x,y)\n ans+=min(y-x,x+10-y)\nprint(ans)\n", "s=int(input())\r\na=input()\r\nb=input()\r\nm=0\r\nfor i in range(s):\r\n distance = abs(int(a[i]) - int(b[i]))\r\n m+=min(distance,10-distance)\r\nprint(m)", "n=int(input())\r\no=input()\r\nl=input()\r\ns=0\r\nfor i in range(len(o)):\r\n if int(o[i])>int(l[i]):\r\n if int(o[i])-int(l[i])>5:\r\n s=s+10-(int(o[i])-int(l[i]))\r\n else:\r\n s=s+(int(o[i])-int(l[i]))\r\n elif int(l[i]) > int(o[i]):\r\n if int(l[i])-int(o[i])>5:\r\n s=s+10-(int(l[i])-int(o[i]))\r\n else:\r\n s=s+(int(l[i])-int(o[i]))\r\nprint(s)", "length = int(input())\r\n\r\norigin = list(map(int, input()))\r\nfinal = list(map(int, input()))\r\nmoves = 0\r\nfor disk in range(length):\r\n if abs(origin[disk] - final[disk]) <= 4:\r\n moves += abs(origin[disk] - final[disk])\r\n else:\r\n moves += 10 - abs(origin[disk] - final[disk])\r\nprint(moves)\r\n\r\n", "n = int(input())\r\nbefore = list(input())\r\nafter = list(input())\r\ncombinations = 0\r\nsm = 0\r\nfor i in range(n):\r\n s1 = abs(int(before[i]) - int(after[i]))\r\n s2 = abs(10 - s1)\r\n sm = min(s1,s2)\r\n combinations += sm\r\n\r\nprint(combinations)\r\n", "#!/usr/bin/env python\n# coding: utf-8\n\n# In[6]:\n\n\nd = int(input())\n\nstate = str(input())\nsol = str(input())\n\ncount = 0\nfor i in range(0,len(state)):\n if int(state[i])==int(sol[i]):\n pass\n else:\n diff = abs(int(state[i])-int(sol[i]))\n if diff>=5:\n r = 10-diff\n count += r\n else:\n count += diff\nprint(count)\n \n\n\n# In[ ]:\n\n\n82195\n64723\n\n", "n=int(input())\r\na=input()\r\nb=input()\r\nc=0\r\nfor i in range(n):\r\n c+=min(abs(int(a[i])-int(b[i])),10+min(int(a[i]),int(b[i]))-max(int(a[i]),int(b[i])))\r\nprint(c)", "n = int(input())\r\na = list(input())\r\nb = list(input())\r\nk = 0\r\nfor i in range(n):\r\n s = int(a[i])\r\n r = int(b[i])\r\n k += min(abs(s-r), 10-abs(s-r))\r\nprint(k)\r\n", "import math\r\ndef gcd (a, b):\r\n if a % b == 0:\r\n return b\r\n else:\r\n return gcd(b, a%b) \r\n\r\ndef prime_bool(k):\r\n if k==2 or k==3: return True\r\n if k%2==0 or k<2: return False\r\n for i in range(3, int(k**0.5)+1, 2):\r\n if k%i==0:\r\n return False\r\n return True\r\n\r\ndef prime(k):\r\n for i in range(2, int(k**0.5)+1, 1):\r\n if k%i==0:\r\n return i\r\n return k\r\n\r\ndef isstep2(num):\r\n if num == 1:\r\n return True\r\n if num & 1:\r\n return False\r\n return isstep2(num >> 1)\r\n\r\n\r\n\r\n\r\nn = int(input())\r\na = input()\r\nb = input()\r\nans = 0\r\nfor i in range(n) :\r\n x = int(a[i])\r\n y = int(b[i])\r\n ans += min(abs(x - y), abs(10 - abs(y - x)))\r\nprint(ans)", "l=int(input())\r\na=list(map(int,input()))\r\nb=list(map(int,input()))\r\ns=0\r\nfor i in range(l):\r\n d=abs(a[i]-b[i])\r\n if(d<=5):\r\n s+=d\r\n else:\r\n c=10-d\r\n s+=c \r\nprint(s)\r\n ", "n = int(input())\r\norig = input()\r\npas = input()\r\ncount = 0\r\n\r\nfor i in range(len(orig)):\r\n count += min(abs(int(orig[i])-int(pas[i])),abs(int(orig[i]) - 9) + int(pas[i]) + 1, abs(int(pas[i]) - 9) + int(orig[i]) + 1)\r\n\r\nprint(count)\r\n", "n = int(input())\r\na= input()\r\nb = input()\r\ns=0\r\nfor i in range(n):\r\n x=int(a[i])\r\n y=int(b[i])\r\n s=s+min(10-abs(x-y), abs(x-y))\r\nprint(s)", "n = int(input())\r\na = input()\r\nb = input()\r\nnum = 0\r\nfor i in range(n):\r\n\tdif = int(a[i]) - int(b[i])\r\n\tnum += min(dif%10, -dif%10)\r\nprint(num)", "digits = int(input())\r\noriginal, final = input(), input()\r\nans = 0\r\nfor x, y in zip(list(original), list(final)):\r\n x, y = int(x), int(y)\r\n if abs(x-y) > 5:\r\n ans += 10-abs(x-y)\r\n else:\r\n ans += abs(x-y)\r\nprint(ans)", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\na =[abs(abs(int(s1[i])-int(s2[i]))) for i in range(n)]\r\nprint(sum(min(i,10-i) for i in a))\r\n", "n=int(input())\r\nx=list((input()))\r\ny=list((input()))\r\nc=0\r\nfor i in range(n):\r\n s=abs(int(x[i])-(int(y[i])))\r\n c+=min(s,10-s)\r\nprint(c)", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\nans = 0\r\nfor i in range(0, n):\r\n if int(s1[i]) > int(s2[i]):\r\n if int(s1[i]) - int(s2[i]) <= 9 - int(s1[i]) + int(s2[i]) + 1:\r\n ans += int(s1[i]) - int(s2[i])\r\n else:\r\n ans += 9 - int(s1[i]) + int(s2[i]) + 1\r\n elif int(s1[i]) < int(s2[i]):\r\n if int(s2[i]) - int(s1[i]) <= 9 - int(s2[i]) + int(s1[i]) + 1:\r\n ans += int(s2[i]) - int(s1[i])\r\n else:\r\n ans += 9 - int(s2[i]) + int(s1[i]) + 1\r\nprint(ans)\r\n", "n = int(input())\r\n\r\nstr1 = input()\r\nstr2 = input()\r\n\r\nnum = 0\r\nfor i,j in zip(str1,str2):\r\n i = int(i)\r\n j = int(j)\r\n if abs(i-j) <=4:\r\n num = num + abs(i-j)\r\n else:\r\n if( i < j):\r\n num = num + abs(9 - j) + i + 1\r\n else:\r\n num = num + abs(9-i) + j + 1\r\nprint(num)\r\n \r\n \r\n\r\n", "n=int(input())\r\na=list(map(int,input()))\r\nb=list(map(int,input()))\r\ny=0\r\nfor i in range(n):\r\n while a[i]!=b[i]:\r\n x=a[i]-b[i]\r\n if x<=5 and x>0:\r\n y=y+1\r\n a[i]=a[i]-1\r\n if abs(x)<=5 and x<0:\r\n y=y+1\r\n a[i]=a[i]+1\r\n if x>5 and x>0:\r\n y=y+1\r\n a[i]=a[i]+1\r\n if a[i]>9:\r\n a[i]=0\r\n if abs(x)>5 and x<0:\r\n y=y+1\r\n a[i]=(a[i]-1)\r\n if a[i]<0:\r\n a[i]=9\r\n #print(a[i],b[i])\r\nprint(y)", "l = int(input())\r\nrandom = input()\r\npassword = input()\r\n\r\ns = str(random) + str(password)\r\n\r\ndef main(l,s):\r\n count = 0 \r\n for i in range(len(s)-l):\r\n if int(s[i]) > int(s[i+l]):\r\n a = int(s[i]) - int(s[i+l])\r\n b = (int(s[i+l]) + 10) - int(s[i])\r\n if a > b:\r\n count = count + b\r\n else:\r\n count = count + a\r\n else:\r\n a = int(s[i+l]) - int(s[i])\r\n b = (int(s[i]) + 10) - int(s[i+l])\r\n if a > b:\r\n count = count + b\r\n else:\r\n count = count + a\r\n return count\r\n\r\nprint(main(l,s))", "def get(a, b):\r\n c = (9-b) + (a+1)\r\n d = (9-a) + (b+1)\r\n if a<b:\r\n a, b = b, a\r\n return min(a-b, c, d)\r\n\r\nn = int(input())\r\na = input()\r\nb = input()\r\ns = 0\r\nfor i in range(n):\r\n s += get(int(a[i]), int(b[i]))\r\nprint(s)", "n1 = input()\r\nn = int(n1)\r\na1 = input()\r\nb1 = input()\r\nt = 0\r\nfor i in range(0,n):\r\n a = int(a1[i])\r\n b = int(b1[i])\r\n t = t+ min(abs(a-b),10-abs(a-b))\r\nprint(t)", "case=int(input())\r\nw=input()\r\nr=input()\r\nn=0\r\nfor i in range(case):\r\n t=abs(int(w[i])-int(r[i]))\r\n if t>5:\r\n t=10-t\r\n n+=t\r\nprint(n)", "n = int(input())\r\na = input()\r\nb = input()\r\ncnt = 0\r\n\r\n\r\nfor i in range(n):\r\n if abs(int(a[i])-int(b[i]))<=5:\r\n cnt += abs(int(a[i])-int(b[i]))\r\n else:\r\n cnt += 10 - abs(int(a[i])-int(b[i]))\r\n\r\nprint(cnt)", "n = int(input())\r\norg = list(map(int,list(input())))\r\nsecret = list(map(int,list(input())))\r\nmoves = 0\r\nfor i in range(n):\r\n if org[i]==0:\r\n if secret[i]==0:\r\n moves += 0\r\n elif secret[i]<=5:\r\n moves += secret[i]\r\n else:\r\n moves += 10-secret[i]\r\n elif secret[i]==0:\r\n if org[i]==0:\r\n moves += 1\r\n elif org[i]<=5:\r\n moves += org[i]\r\n else:\r\n moves += 10-org[i]\r\n elif (org[i])>=6:\r\n moves += min(abs(org[i]-secret[i]),secret[i]+10-org[i])\r\n else:\r\n moves += min(abs(org[i]-secret[i]),org[i]+10-secret[i])\r\nprint(moves)", "#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-30 23:22:57\nLastEditTime: 2021-11-30 23:26:37\nDescription: Combination Lock\nFilePath: CF540A.py\n'''\n\n\ndef func():\n _ = int(input())\n original = list(map(int, list(input().strip())))\n password = list(map(int, list(input().strip())))\n count = 0\n for i, j in zip(original, password):\n count += min(abs(i - j), 10 - abs(i - j))\n print(count)\n\n\nif __name__ == '__main__':\n func()\n", "n = int(input())\r\nx = input()\r\ny = input()\r\nc = 0\r\n\r\nfor i in range(n):\r\n f, s = int(x[i]), int(y[i])\r\n d1 = abs(f - s)\r\n if f < s:\r\n d2 = f + (10 - s)\r\n c += min(d1, d2)\r\n else:\r\n d2 = s + (10 - f)\r\n c += min(d1, d2)\r\n\r\nprint(c)", "n = int(input())\r\na = input()\r\nb = input()\r\no = 0\r\nfor i in range(n):\r\n o+=min(abs(int(a[i])-int(b[i])), 10-abs(int(a[i])-int(b[i])))\r\nprint(o)", "import sys\r\n\r\nn = int(sys.stdin.readline().split()[0])\r\n\r\ndisks_origin = sys.stdin.readline().split()[0]\r\ndisks_mc_duck = sys.stdin.readline().split()[0]\r\n\r\nactions = 0\r\n\r\nfor i in range(n):\r\n max_digit = max(int(disks_origin[i]), int(disks_mc_duck[i]))\r\n min_digit = min(int(disks_origin[i]), int(disks_mc_duck[i]))\r\n\r\n if (max_digit - min_digit) > 5:\r\n actions += min_digit + 10 - max_digit\r\n else:\r\n actions += max_digit - min_digit\r\n\r\nprint(actions)\r\n", "n = int(input())\r\na = list(map(int, input().rstrip()))\r\nb = list(map(int, input().rstrip()))\r\nh = 0\r\n\r\nfor i in range(len(a)):\r\n c = a[i]\r\n d = b[i]\r\n e = max(c, d) - min(c, d)\r\n f = min(c, d) - max(c, d) + 10\r\n g = min(e, f)\r\n h = h + g\r\n \r\nprint(h)\r\n", "n=int(input())\r\nx=list(map(int,input()))\r\ny=list(map(int,input()))\r\nadd_=0\r\nfor i in range(n):\r\n add_=add_+min(abs(x[i]-y[i]),10-abs(x[i]-y[i]))\r\nprint(add_)", "a=int(input())\r\nb=input()\r\nc=input()\r\nres=0\r\nfor k in range(a):\r\n sum=0\r\n m=min(int(b[k]),int(c[k]))\r\n ma=max(int(b[k]),int(c[k]))\r\n while m!=ma:\r\n sum+=1\r\n m+=1\r\n res+=min(sum,10-sum)\r\nprint(res)\r\n\r\n", "n = int(input())\r\ns = input()\r\nt = input()\r\n\r\nmoves = 0\r\nfor i in range(n):\r\n a = int(s[i])\r\n b = int(t[i])\r\n clockwise = abs(b - a)\r\n counterclockwise = 10 - clockwise\r\n moves += min(clockwise, counterclockwise)\r\n\r\nprint(moves)", "n=int(input())\r\na=list(input())\r\nb=list(input())\r\nile=0\r\nfor i in range(n):\r\n ile+=min(abs(int(a[i])-int(b[i])), min(int(a[i]), 10-int(a[i]))+min(int(b[i]), 10-int(b[i])))\r\nprint(ile)", "n, org, key = input(), input(), input()\r\nsteps = 0\r\nfor i in range(len(org)):\r\n a = abs(int(org[i]) - int(key[i]))\r\n b = 10 - int(org[i]) + int(key[i])\r\n c = int(org[i]) + (10 - int(key[i]))\r\n steps += min(a, b, c)\r\nprint(steps)", "n = int(input())\r\na, b = input(), input()\r\nres = 0\r\nfor i in range(n):\r\n res += min(abs(int(a[i]) - int(b[i])), 10 - abs(int(a[i]) - int(b[i])))\r\nprint(res)", "'''\nAuthor : knight_byte\nFile : A_Combination_Lock.py\nCreated on : 2021-04-14 09:12:05\n'''\n\n\ndef main():\n n = int(input())\n s = input()\n o = input()\n sum = 0\n for i in range(n):\n diff = abs(int(o[i])-int(s[i]))\n sum += min(diff, 10-diff)\n print(sum)\n\n\nif __name__ == '__main__':\n main()\n", "#540A\r\nn = int(input())\r\nos = input()\r\npsswd = input()\r\nmoves = 0\r\n\r\nfor i in range(n):\r\n x = abs(int(os[i])-int(psswd[i]))\r\n if x>=5:\r\n x = 10 - x\r\n moves+=x\r\nprint(moves)", "t=int(input())\r\ns=input()\r\nc=0\r\nl=input()\r\nfor i in range(t):\r\n m=abs(int(s[i])-int(l[i]))\r\n if m>5:\r\n m=abs(10-m)\r\n c=c+m\r\nprint(c)", "n=int(input())\r\nl=[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"]\r\ns1=input()\r\ns2=input()\r\nres=0\r\nfor i in range(len(s1)):\r\n c1=abs(int(s1[i])-int(s2[i]))\r\n c2=10-abs(int(s1[i])-int(s2[i]))\r\n # print(c1,c2)\r\n res+=min(c1,c2)\r\nprint(res)\r\n", "r=int(input())\r\nnum1=input()\r\nnum2=input()\r\nw=0\r\nfor i in range(r):\r\n c=abs(int(num1[i])-int(num2[i]))\r\n if c > 5:\r\n w+=(10-c)\r\n else:\r\n w+=c\r\nprint(w)", "n = int(input())\r\ns1=input()\r\ns2 = input()\r\ns = 0\r\nfor i in range(n):\r\n s += min(abs(int(s1[i]) - int(s2[i])),abs(10-abs(int(s1[i]) - int(s2[i]))))\r\nprint(s)", "n = int(input())\r\norig = input()\r\nfinal = input()\r\nmoves = 0\r\nfor i in range(n):\r\n moves += min(abs(int(orig[i])-int(final[i])), 10 - (abs(int(orig[i])-int(final[i]))))\r\nprint(moves)\r\n", "n=int(input())\r\na=input()\r\nb=input()\r\ncount=0\r\nfor i in range(n):\r\n if((int(a[i])-int(b[i]))<0):\r\n if(((9-int(b[i])+int(a[i])-0)+1)<(int(b[i])-int(a[i]))):\r\n count+=9-int(b[i])+int(a[i])-0+1\r\n else: \r\n count+=int(b[i])-int(a[i])\r\n else: \r\n if(((9-int(a[i])+int(b[i])+1)-0)<(int(a[i])-int(b[i]))):\r\n count+=9-int(a[i])+int(b[i])-0+1\r\n else: \r\n count+=int(a[i])-int(b[i]) \r\nprint(count) \r\n", "n = input()\r\n\r\ns1 = input()\r\ns2 = input()\r\nc = 0\r\nfor i in range(int(n)):\r\n t1,t2 = int(s1[i]),int(s2[i])\r\n t3 = abs(t1-t2)\r\n # print(t3,10-t3)\r\n c = c + min(t3,10-t3)\r\nprint(c)\r\n ", "n=int(input())\r\nx=input()\r\ny=input()\r\ncount=0\r\nfor i in range(n):\r\n\tif abs(int(x[i])-int(y[i]))>=5:\r\n\t\tcount=count+10-abs(int(x[i])-int(y[i]))\r\n\telse:\r\n\t\tcount=count+abs(int(x[i])-int(y[i]))\r\nprint(count)", "n,a,b,num = int(input()),input().strip(),input().strip(),0\r\nfor i in range(n):\r\n q = abs(int(a[i]) - int(b[i]))\r\n num += 10 - q if q > 5 else q\r\nprint(num)", "input()\r\nprint(sum(5-abs(5-abs(int(x)-int(y))) for x, y in zip(input(), input())))", "import sys\r\n\r\n\r\ndef main(fin):\r\n t = int(fin.readline())\r\n l1 =fin.readline().rstrip(\"\\n\")\r\n ls1 = [int(i) for i in l1]\r\n l2 = fin.readline().rstrip(\"\\n\")\r\n ls2 = [int(i) for i in l2]\r\n c = 0\r\n for i in range(t):\r\n a = min(ls1[i], ls2[i])\r\n b = max(ls1[i], ls2[i])\r\n d = min((b - a), (10 + a - b))\r\n c += d\r\n print(c)\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 fin = sys.stdin\r\n # fin = open(\"input.txt\")\r\n main(fin)\r\n", "n = int(input())\r\na = input()\r\nb = input()\r\n\r\n\r\ndef get_diff(x, y):\r\n x, y = int(x), int(y)\r\n return min(abs(x - y), x + 10 - y, 10 - x + y)\r\n\r\nans = 0\r\nfor i in range(n):\r\n ans += get_diff(a[i], b[i])\r\n\r\nprint(ans)\r\n", "input()\r\na=list(map(int,input()))\r\nb=list(map(int,input()))\r\ncnt=0\r\nfor i in range(len(a)):\r\n cnt+=min(abs(a[i]-b[i]),10-abs(a[i]-b[i]))\r\nprint(cnt)", "n = int(input())\r\na = input()\r\nb = input()\r\nc =0\r\nfor i in range(n):\r\n d = abs(int(a[i]) - int(b[i]))\r\n m = min(d,(10-d))\r\n #print(m)\r\n c =c+m\r\n\r\nprint(c)", "def get_least_moves(num1, num2):\r\n\r\n if num1 > num2:\r\n num1, num2 = num2, num1\r\n\r\n if abs(num1 - num2) < 6:\r\n return abs(num1 - num2)\r\n else:\r\n return (10 - num2) + num1\r\n\r\n\r\ndef main():\r\n\r\n disks = int(input())\r\n original = input()\r\n combination = input()\r\n min_moves = 0\r\n for i in range(disks):\r\n min_moves += get_least_moves(int(original[i]), int(combination[i]))\r\n\r\n print(min_moves)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n = int(input())\r\ncurr = list(map(int, input()))\r\narr = list(map(int, input()))\r\ncnt = 0\r\nfor i in range(n):\r\n cnt += min(abs(arr[i]-curr[i]), (min(arr[i],curr[i])+10) - max(arr[i], curr[i]) )\r\nprint(cnt)", "n=int(input())\r\na=list(input())\r\nif a[len(a)-1]=='\\r':\r\n a.pop()\r\nb=list(input())\r\nif b[len(b)-1]=='\\r':\r\n b.pop()\r\nfor i in range(len(a)):\r\n a[i]=int(a[i])\r\nfor i in range(len(b)):\r\n b[i]=int(b[i])\r\ns=0\r\nfor i in range(len(a)):\r\n s1=max(a[i],b[i])-min(a[i],b[i])\r\n s2=(a[i]+10)-b[i]\r\n s3=(b[i]+10)-a[i]\r\n s+=min(s1,s2,s3)\r\nprint(s)", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\nz = 0\r\nfor i in range(n):\r\n one = int(s1[i]) - int(s2[i])\r\n two = int(s2[i]) - int(s1[i])\r\n if one < 0:\r\n one += 10\r\n if two < 0:\r\n two += 10\r\n z += min(one, two)\r\nprint(z)\r\n", "n = int(input())\ninitial_position = input()\ncombination = input()\n\ntotal_actions = 0\n\nfor i in range(n):\n diff = abs(int(initial_position[i]) - int(combination[i]))\n cw_diff = (int(combination[i]) - int(initial_position[i]) + 10) % 10\n ccw_diff = (int(initial_position[i]) - int(combination[i]) + 10) % 10\n total_actions += min(cw_diff, ccw_diff)\n\nprint(total_actions)\n", "n=int(input())\r\ns=input()\r\no=input()\r\nf=\"01234567890123456789\"\r\nans=0\r\nfor i in range(n):\r\n si=int(s[i])\r\n oi=int(o[i])\r\n ans=ans+min(abs(si-oi),abs(si-(10+oi)),abs(si+10-oi))\r\n \r\nprint(ans) \r\n ", "n=int(input())\r\nt=0\r\ns1=input()\r\ns2=input()\r\nfor i in range(n):\r\n if abs(int(s1[i])-int(s2[i]))<(10-abs(int(s1[i])-int(s2[i]))):\r\n t+=abs(int(s1[i])-int(s2[i]))\r\n else:\r\n t+=(10-abs(int(s1[i])-int(s2[i])))\r\nprint(t)", "n = int(input())\r\nstart = input()\r\nend = input()\r\nmoves = 0\r\nfor index in range(len(start)):\r\n s = int(start[index])\r\n e = int(end[index])\r\n direct = abs(e - s)\r\n loop = s + 10 - e if e > s else e + 10 - s\r\n moves += min(direct, loop)\r\nprint(moves)", "n = int(input())\r\n\r\na = list(map(int, (list(input()))))\r\nb = list(map(int, (list(input()))))\r\n\r\nmove = 0\r\nfor i in range(n):\r\n x = abs(a[i]-b[i])\r\n if x <= 5:\r\n move += x\r\n else:\r\n x = min(a[i], b[i]) + 10 - max(a[i], b[i])\r\n move += x\r\nprint(move)\r\n", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\ntotal = 0\r\nfor i in range(n):\r\n val = abs(int(s1[i]) - int(s2[i]))\r\n total += min(val, 10-val)\r\nprint(total)", "n = int(input())\r\na = input()\r\nb = input()\r\ns = 0\r\nfor i in range (n):\r\n if abs(int(a[i]) - int(b[i]))>5:\r\n d = 10 - max(int(a[i]),int(b[i])) + min(int(a[i]),int(b[i]))\r\n else:\r\n d = abs(int(a[i])-int(b[i]))\r\n s+=d\r\nprint (s)", "n=int(input())\r\nli=input()\r\nli=list(li)\r\nli=list(map(int,li))\r\nli1=input()\r\nli1=list(li1)\r\nli1=list(map(int,li1))\r\nmove=0\r\nfor x in range(n):\r\n if li[x]<li1[x]:\r\n z=((li[x]-0)+(9-li1[x])+1)\r\n d=abs(li[x]-li1[x])\r\n if z<d:\r\n move+=z\r\n elif z==d:\r\n move+=d\r\n else:\r\n move+=d\r\n else:\r\n z=((li1[x]-0)+(9-li[x])+1)\r\n d=abs(li[x]-li1[x])\r\n if z<d:\r\n move+=z\r\n elif z==d:\r\n move+=d\r\n else:\r\n move+=d\r\n\r\n \r\nprint(move)\r\n\r\n", "n=int(input())\r\ns1=input()\r\ns2=input()\r\ns=0\r\nfor i in range(n):\r\n s+=min(abs((int(s1[i])-int(s2[i]))),abs(10-abs((int(s1[i])-int(s2[i])))))\r\nprint(s)", "n = int(input())\r\ndnach = input()\r\ndkon = input()\r\nkol = 0\r\nfor i in range(n):\r\n kol += min(abs(int(dnach[i]) - int(dkon[i])), 10 - abs(int(dnach[i]) - int(dkon[i])))\r\nprint(kol)\r\n", "n = int(input())\r\nui1, ui2 = input(), input()\r\n\r\ncount = 0\r\nfor i in range(n):\r\n forward = abs(int(ui1[i]) - (10 + int(ui2[i])))\r\n backward = abs((int(ui1[i]) + 10) - (int(ui2[i])))\r\n reg_diff = abs(int(ui1[i]) - int(ui2[i]))\r\n\r\n count += min(forward, backward, reg_diff)\r\n\r\nprint(count)\r\n", "n=int(input())\r\na=input()\r\nb=input()\r\nmasA=[]\r\nmasB=[]\r\ncount=0\r\nfor i in a:\r\n masA.append(int(i))\r\nfor i in b:\r\n masB.append(int(i))\r\nfor i in range(len(masA)):\r\n if abs(masA[i]-masB[i])>=5 and masA[i]<masB[i]:\r\n count += (masA[i] + (10 - masB[i]))\r\n elif abs(masA[i]-masB[i])>=5 and masA[i]>masB[i]:\r\n count += (masB[i] + (10 - masA[i]))\r\n else:\r\n count += (abs(masB[i]-masA[i]))\r\nprint(count)", "# x = int(input())\n# \n# for q in range(x):\n\nl = int(input())\n\na,b = input(),input()\n# print(a,b)\nsum = 0\n\nfor i in range(l):\n x,y = int(a[i]), int(b[i])\n\n diff = abs(x-y)\n\n if diff>5:\n diff = 10-diff\n\n sum+=diff\n\nprint(sum)\n", "n=int(input())\r\nx=input()\r\ny=input()\r\nc=0 \r\nfor i in range(0,n):\r\n a=int(x[i])\r\n b=int(y[i])\r\n if a!=b:\r\n if a>b:\r\n c+=min(a-b,10-a+b)\r\n else:\r\n c+=min(b-a,a+10-b)\r\nprint(c)\r\n ", "# Je déteste que j'aime que je déteste\r\nfrom math import sqrt\r\n\r\nn, s1, s2 = int(input()), input(), input()\r\nr = 0\r\nfor i in range(n):\r\n if abs(int(s1[i]) - int(s2[i])) > 5:\r\n r += 10 - abs(int(s1[i]) - int(s2[i]))\r\n else:\r\n r += abs(int(s1[i]) - int(s2[i]))\r\nprint(r)", "def distance(num1, num2):\r\n if (num1 >= 5 and num2 >= 5):\r\n return abs(num1-num2)\r\n elif (num1 < 5 and num2 < 5):\r\n return abs(num1 - num2)\r\n else:\r\n if (abs(num1 - num2) < 5):\r\n return abs(num1 - num2)\r\n elif (num1 >= 5):\r\n return 10-num1 + num2\r\n else:\r\n return 10-num2 + num1\r\n\r\ncount = int(input())\r\ninit = int(input())\r\npassword = int(input())\r\n\r\nmoves = 0\r\nfor i in range(count):\r\n dig1 = init % 10\r\n dig2 = password % 10\r\n\r\n moves+= distance(dig1,dig2)\r\n\r\n init//=10\r\n password//=10\r\n\r\nprint(moves)", "n = int(input())\r\nn1 = input()\r\nn2 = input()\r\nhsl = 0\r\nfor i in range(n):\r\n smtr = abs(int(n1[i]) - int(n2[i]))\r\n hsl += min(smtr,10-smtr) \r\nprint(hsl)", "n = int(input())\r\nl1 = list(input())\r\nl2 = list(input())\r\nans = 0\r\nfor i in range(n):\r\n a, b = int(l1[i]), int(l2[i])\r\n if a > b: a, b = b, a\r\n if b > a:\r\n c1 = b - a\r\n c2 = a + 1 + 9 - b\r\n ans += min(c1, c2)\r\nprint(ans)", "n = int(input())\r\na = [int(x) for x in input()]\r\nb = [int(x) for x in input()]\r\n\r\nc = 0\r\nfor i in range(n):\r\n mi = min(a[i],b[i])\r\n ma = max(a[i],b[i])\r\n\r\n c+= min(ma-mi, 10+mi-ma)\r\n\r\nprint(c)", "size = int(input())\r\nstate = input()\r\nlock = input()\r\nans = 0\r\nfor i in range(size):\r\n if abs(int(state[i])-int(lock[i])) > 5:\r\n ans += 10 - abs(int(state[i])-int(lock[i]))\r\n else:\r\n ans += abs(int(state[i])-int(lock[i]))\r\nprint(ans)", "i = lambda: map(ord, input())\r\ni()\r\nprint(sum(min(abs(a - b), 10 - abs(b - a)) for a, b in zip(i(), i())))", "input()\nc1 = list(map(int, input()))\nc2 = list(map(int, input()))\nprint(sum(min(abs(n1-n2), 10+n1-n2, 10+n2-n1) for n1, n2 in zip(c1, c2)))\n", "n = int(input())\r\nx = input()\r\ny = input()\r\nresult = 0\r\nfor i in range(n) :\r\n n1 = int(x[i])\r\n n2 = int(y[i])\r\n r = abs(n1 - n2)\r\n if r < 5 :\r\n result += r\r\n else :\r\n if n1 > n2 :\r\n n1 , n2 = n2 , n1\r\n while n2 % 10 != n1 :\r\n n2 += 1\r\n result +=1 \r\nprint(result)", "n=int(input())\r\na=input()\r\nb=input()\r\ns=0\r\nfor i in range(n):\r\n sum=0\r\n if int(a[i])-int(b[i])>=0:\r\n sum= int(a[i])-int(b[i])\r\n else:\r\n sum= int(b[i])-int(a[i])\r\n if sum <5:\r\n s+=sum\r\n elif sum>5:\r\n s+=10-sum\r\n else:\r\n s+=5\r\nprint(s)", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\ncnt = 0\r\nfor i in range(n):\r\n n1 = int(s1[i])\r\n n2 = int(s2[i])\r\n mn1 = abs(n1 - n2)\r\n if n1 > n2:\r\n mn2 = 9 - n1 + 1 + n2\r\n else:\r\n mn2 = 9 - n2 + 1 + n1\r\n cnt += min(mn1, mn2)\r\nprint(cnt)\r\n", "# https://codeforces.com/problemset/problem/540/A\r\nnb_disks = int(input())\r\noriginal_state = input()\r\ncombination = input()\r\nnb_moves = 0\r\nfor x in range(nb_disks):\r\n c = int(combination[x])\r\n o = int(original_state[x])\r\n nb_moves += min(abs(c-o), 10-abs(c-o))\r\nprint(nb_moves)\r\n", "a = int(input())\r\nb = [int(i) for i in input()]\r\nc = [int(i) for i in input()]\r\n\r\nans = 0\r\n\r\nfor i in range(a):\r\n ans += min(abs(b[i] - c[i]), 10-abs(b[i]-c[i]))\r\n\r\nprint(ans)", "n = int(input())\r\nq = list(map(int,input()))\r\nw = list(map(int,input()))\r\ns = 0\r\nfor i in range(n):\r\n z = q[i] - w[i]\r\n v = (z+10)%10\r\n b = (-z+10)%10\r\n x = v if v<b else b\r\n s += x\r\nprint(s)", "n=int(input())\r\na=input()\r\nb=input()\r\nans=0\r\nfor i in range(n):\r\n if(abs(int(a[i])-int(b[i]))>10-abs(int(b[i])-int(a[i]))):\r\n ans=ans+10-abs(int(b[i])-int(a[i]))\r\n else:\r\n ans=ans+abs(int(a[i])-int(b[i]))\r\nprint(ans) ", "def main():\r\n #print(\"This Work made by Ahmad Elnassag\")\r\n #print(\" Junior Training Sheet V7\")\r\n\r\n n = int(input())\r\n digit1 = input()\r\n digit2 = input()\r\n x = 0\r\n for i in range(n):\r\n x += min(abs(int(digit1[i])-int(digit2[i])),10-abs(int(digit1[i])-int(digit2[i])))\r\n \r\n \r\n print(x) \r\n\r\nif __name__ == \"__main__\":\r\n main()", "z=int(input())\r\nx=input()\r\nv=input()\r\n \r\nd=0\r\nw=0\r\nc=0\r\n \r\nfor i in x:\r\n a=int(i)\r\n \r\n b=int(i)\r\n for o in range(18):\r\n \r\n if a==int(v[c]) or b==int(v[c]):\r\n \r\n w+=d\r\n d=0\r\n break\r\n if a==9:\r\n a=-1\r\n if b==0:\r\n b=10\r\n a+=1\r\n b-=1\r\n d+=1\r\n c+=1\r\n \r\n \r\n \r\nprint(w)", "n=int(input())\r\nk=input()\r\nkok=input()\r\ncnt=0\r\nfor i in range(n):\r\n mmax=max(int(k[i]),int(kok[i]))\r\n mmin=min(int(k[i]),int(kok[i]))\r\n if mmax-mmin<=5:\r\n cnt+=mmax-mmin\r\n else:\r\n cnt+=10-(mmax-mmin)\r\nprint(cnt)\r\n ", "n = int(input())\r\nm = input()\r\no = input()\r\npocet = 0\r\n\r\nfor i in range(n):\r\n pocet+=(min(abs(int(m[i])-int(o[i])),int(m[i])+10-int(o[i]),int(o[i])+10-int(m[i])))\r\nprint(pocet) \r\n\r\n \r\n \r\n \r\n \r\n \r\n", "n=int(input())\ns1=input()\ns2=input()\nres=0\nfor i in range(n):\n x=abs(ord(s2[i])-ord(s1[i]))\n res+=min(10-x,x)\nprint(res)\n\n \t \t\t \t \t \t \t\t\t\t\t\t \t \t\t\t", "x=int(input())\r\nx1=input()\r\nx2=input()\r\ns=0\r\nfor i in range(x):\r\n if abs(int(x1[i])-int(x2[i]))>5:\r\n s=s+(10-abs(int(x1[i])-int(x2[i])))\r\n else:\r\n s=s+abs(int(x1[i])-int(x2[i]))\r\nprint(s) ", "numDisks = int(input())\r\nstart = input()\r\ngoal = input()\r\nmoves = 0\r\n\r\nfor i in range(0,numDisks):\r\n distance = abs(int(start[i])-int(goal[i]))\r\n moves += distance if distance <= 5 else 10-distance \r\n\r\nprint(moves)", "n=int(input())\r\na1=str(input())\r\na2=str(input())\r\nb=0\r\nfor i in range(n):\r\n if int(a1[i])>int(a2[i]):\r\n if (int(a1[i])-int(a2[i]))>5:\r\n b+=10-(int(a1[i])-int(a2[i]))\r\n else:\r\n b += int(a1[i]) - int(a2[i])\r\n elif int(a1[i])<int(a2[i]):\r\n if (int(a2[i])-int(a1[i]))>5:\r\n b+=10-(int(a2[i])-int(a1[i]))\r\n else:\r\n b += int(a2[i]) - int(a1[i])\r\nprint(b)", "n = int(input())\r\ns = input()\r\nc = input()\r\nres = 0\r\nfor i in range(n):\r\n n1, n2 = int(s[i]), int(c[i])\r\n res += min(abs(n1-n2), 10-abs(n1-n2))\r\n\r\nprint(res)", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\ntotal = 0\r\nfor x in range(n):\r\n if s2[x] > s1[x]:\r\n total += min(abs(int(s1[x])-int(s2[x])),(9-int(s2[x]))+int(s1[x])+1)\r\n else:\r\n total += min(abs(int(s1[x])-int(s2[x])),(9-int(s1[x]))+int(s2[x])+1)\r\nprint(total)", "def comb(n, target):\r\n if n > target:\r\n return min(abs(n - target), abs(10 - n + target))\r\n return min(abs(n - target), abs(10 + n - target))\r\n\r\nn = int(input())\r\nini = input()\r\nfinal = input()\r\ncount = 0\r\nfor i in range(n):\r\n count += comb(int(ini[i]), int(final[i]))\r\nprint(count)", "l=int(input())\r\nx=input()\r\ny=input()\r\ns=0\r\nfor t in range(l):\r\n if abs(int(x[t])-int(y[t])) > 9-int(x[t])+1+int(y[t]) and (9-int(x[t]))<(9-int(y[t])):\r\n s=s+9-int(x[t])+1+int(y[t])\r\n elif abs(int(x[t]) - int(y[t])) > 9 - int(y[t]) + 1 + int(x[t]) and 9 - int(y[t]) < 9 - int(x[t]):\r\n s=s+9 - int(y[t]) + 1 + int(x[t])\r\n else:\r\n s=s+abs(int(x[t])-int(y[t]))\r\nprint(s)\r\n", "n=int(input())\r\ns1=input()\r\ns2=input()\r\ncount=0\r\nfor i in range(len(s1)):\r\n if(abs(int(s1[i])-int(s2[i]))==1):\r\n count+=abs(int(s1[i])-int(s2[i]))\r\n if(abs(int(s1[i])-int(s2[i]))==2):\r\n count+=abs(int(s1[i])-int(s2[i]))\r\n if(abs(int(s1[i])-int(s2[i]))==3):\r\n count+=abs(int(s1[i])-int(s2[i]))\r\n if(abs(int(s1[i])-int(s2[i]))==4):\r\n count+=abs(int(s1[i])-int(s2[i]))\r\n if(abs(int(s1[i])-int(s2[i]))==5):\r\n count+=abs(int(s1[i])-int(s2[i]))\r\n if(abs(int(s1[i])-int(s2[i]))==6):\r\n count+=(abs(int(s1[i])-int(s2[i]))-2)\r\n if(abs(int(s1[i])-int(s2[i]))==7):\r\n count+=(abs(int(s1[i])-int(s2[i]))-4)\r\n if(abs(int(s1[i])-int(s2[i]))==8):\r\n count+=(abs(int(s1[i])-int(s2[i]))-6)\r\n if(abs(int(s1[i])-int(s2[i]))==9):\r\n count+=(abs(int(s1[i])-int(s2[i]))-8)\r\n \r\nprint(count)\r\n ", "n = int (input ())\r\norig_sta = str (input ()) \r\nkey = str (input ())\r\ncount = 0\r\nfor i in range (n):\r\n o = int (orig_sta [i])\r\n k = int (key [i])\r\n mi = min (( (o - 0) + (9 - k) + 1), ((9 - o) + (k - 0) + 1))\r\n count += min (abs (( o-k )), mi)\r\nprint (count)\r\n\r\n\r\n", "# def pick_peaks(arr):\r\n# \tpos = []\r\n# \tpeaks = []\r\n# \ti = 1\r\n# \twhile(i < (len(arr) - 1)):\r\n# \t\tif (i == 1 and arr[i] == arr[0]):\r\n# \t\t\ti = i + 1\r\n# \t\t\tcontinue\r\n# \t\tif (arr[i] > arr[i - 1] and arr[i] > arr[i + 1]):\r\n# \t\t\tpeaks.append(arr[i])\r\n# \t\t\tpos.append(i)\r\n# \t\telif (arr[i] == arr[i + 1] and arr[i] > arr[i - 1]):\r\n# \t\t\tj = i + 1\r\n# \t\t\twhile(j < len(arr)):\r\n# \t\t\t\tif(arr[j] != arr[i]):\r\n# \t\t\t\t\tbreak\r\n# \t\t\t\tj = j + 1\r\n# \t\t\tif (j != len(arr)):\r\n# \t\t\t\tif (arr[j] < arr[i]):\r\n# \t\t\t\t\tpeaks.append(arr[i])\r\n# \t\t\t\t\tpos.append(i)\r\n# \t\t\t\t\ti = j\r\n# \t\t\t\t\tcontinue\r\n# \t\telif(arr[i] == arr[i + 1] and arr[i] == arr[i - 1]):\r\n# \t\t\tflag1 = 0\r\n# \t\t\tflag2 = 0\r\n# \t\t\tu = 0\r\n# \t\t\tj = i + 1\r\n# \t\t\twhile(j < len(arr)):\r\n# \t\t\t\tif(arr[j] != arr[i]):\r\n# \t\t\t\t\tbreak\r\n# \t\t\t\tj = j + 1\r\n# \t\t\tif (j != len(arr)):\r\n# \t\t\t\tif (arr[j] < arr[i]):\r\n# \t\t\t\t\tflag1 = 1\r\n# \t\t\tu = j\r\n# \t\t\tj = 0\r\n# \t\t\twhile(j < i):\r\n# \t\t\t\tif(arr[j] != arr[i]):\r\n# \t\t\t\t\tbreak\r\n# \t\t\t\tj = j + 1\r\n# \t\t\tif (arr[j] < arr[i]):\r\n# \t\t\t\tflag2 = 1\r\n# \t\t\tif (flag1 and flag2):\r\n# \t\t\t\tpeaks.append(arr[i])\r\n# \t\t\t\tpos.append(i)\r\n# \t\t\t\ti = u\r\n# \t\t\t\tcontinue\r\n# \t\telif(arr[i] == arr[i - 1] and arr[i] > arr[i + 1]):\r\n# \t\t\tj = 0\r\n# \t\t\twhile(j < i):\r\n# \t\t\t\tif(arr[j] != arr[i]):\r\n# \t\t\t\t\tbreak\r\n# \t\t\t\tj = j + 1\r\n# \t\t\tif (arr[j] < arr[i]):\r\n# \t\t\t\tpeaks.append(arr[i])\r\n# \t\t\t\tpos.append(i)\r\n# \t\ti = i + 1\r\n# \treturn {'pos' : pos, 'peaks' : peaks}\r\ndef solve(n, orginal, secret):\r\n\tans = 0\r\n\tfor i in range(n):\r\n\t\tdigit1 = (int)(orginal[i])\r\n\t\tdigit2 = (int)(secret[i])\r\n\t\tif (abs(digit2 - digit1) > 5):\r\n\t\t\tans += abs(9 - max(digit1, digit2)) + min(digit2, digit1) + 1\r\n\t\telse:\r\n\t\t\tans += abs(digit2 - digit1)\r\n\tprint(ans)\r\n\r\nn = (int)(input())\r\norginal = input()\r\nsecret = input()\r\nsolve(n, orginal, secret)\r\n", "LockDisks=int(input(\"\"))\r\nOriginal=list(map(int,input()))\r\nCombination=list(map(int,input()))\r\nSum=0\r\nfor c in range(LockDisks):\r\n\tif(Original[c] == Combination[c]):\r\n\t\tcontinue\r\n\telif(Original[c] > Combination[c]):\r\n\t\tSum1=Original[c]-Combination[c]\r\n\t\tSum2=9-Original[c]+Combination[c]+1\r\n\t\tSum+=min(Sum1,Sum2)\r\n\telse:\r\n\t\tSum1=Combination[c]-Original[c]\r\n\t\tSum2=9-Combination[c]+Original[c]+1\r\n\t\tSum+=min(Sum1,Sum2)\r\nprint(Sum)", "n = int(input())\r\n\r\na = int(input())\r\nb = int(input())\r\n\r\ncount = 0\r\n\r\nfor i in range(n):\r\n x = a%10\r\n y = b%10\r\n if x<y:\r\n y,x = x,y\r\n if x-y<=5:\r\n count += x-y\r\n else:\r\n count += 10-x+y\r\n \r\n a = a//10\r\n b = b//10\r\nprint(count)\r\n", "n = int(input())\n\narr1 = list(map(int, str(input())))\narr2 = list(map(int, str(input())))\n\nsteps = 0\n\nfor i in range(n):\n if abs(arr1[i] - arr2[i]) <= 10 - (abs(arr1[i] - arr2[i])):\n steps += abs(arr1[i] - arr2[i])\n else:\n steps += 10 - abs(arr1[i] - arr2[i])\n\nprint(steps)\n", "input()\r\nstart = input()\r\nend = input()\r\nsum = 0\r\n\r\nfor i, j in zip(start, end):\r\n sum += abs(int(i) - int(j)) if abs(int(i) - int(j)) < 6 else 10 - abs(int(i) - int(j))\r\n\r\nprint(sum)\r\n", "n = int(input())\r\ns = input()\r\nt = input()\r\nans = 0\r\nfor i in range(n):\r\n a = (int(s[i]) - int(t[i]) + 10) % 10\r\n b = (int(t[i]) - int(s[i]) + 10) % 10\r\n if a < b:\r\n ans += a\r\n else:\r\n ans += b\r\nprint(ans)\r\n", "n = int(input())\ns1 = input()\ns2 = input()\ncnt = 0\nfor i in range(n):\n diff = int(abs(int(s1[i]) - int(s2[i])))\n if diff > 5:\n cnt += 10 - diff\n else:\n cnt += diff\nprint(cnt)\n\n\t \t\t \t \t \t\t\t \t\t \t \t\t \t\t \t", "n = int(input())\r\ns = input()\r\nd = input()\r\n\r\njum = 0\r\nfor i in range(n) :\r\n a = int(s[i])\r\n b = int(d[i])\r\n jum+=min(abs(a-b),10-abs(a-b))\r\nprint(jum)", "t = int(input())\r\na = list(map(int, input()))\r\nb = list(map(int, input()))\r\ns = 0\r\nfor i in range(t):\r\n s += min(abs(a[i]-b[i]), 10 - abs(a[i] - b[i]))\r\n #print(s)\r\nprint(s)\r\n", "n, a, b, res = int(input()), input(), input(), 0\r\nfor x in range(n): res += min(max(int(a[x]), int(b[x])) - min(int(a[x]), int(b[x])), min(int(a[x]), int(b[x])) + 10 - max(int(a[x]), int(b[x])))\r\nprint(res)", "n = int(input())\r\nc = list(input())\r\np = list(input())\r\n\r\ncnt = 0\r\nfor i in range(len(c)):\r\n if c[i] != p[i]:\r\n m1 = abs(int(c[i]) - int(p[i]))\r\n if int(c[i]) < int(p[i]):\r\n m2 = abs((int(c[i]) + 10) - int(p[i]))\r\n else:\r\n m2 = abs((int(p[i]) + 10) - int(c[i]))\r\n cnt += min(m1,m2)\r\nprint(cnt)", "a=int(input())\r\nl=list(map(int,input()))\r\nk=list(map(int,input()))\r\nsum=0\r\nfor i in range(0,a):\r\n p=min(abs(l[i]-k[i]),10-abs(l[i]-k[i]))\r\n sum+=p\r\nprint(sum)\r\n", "n =int(input())\ns=input()\nc=input()\ntotal=0\nfor i in range(n):\n total+=min(10-abs(ord(s[i])-ord(c[i])),abs(ord(s[i])-ord(c[i])))\nprint(total)\n\n\t\t\t \t \t \t\t \t\t \t \t\t\t\t\t\t \t\t", "num = int(input())\r\nx = input()\r\ny = input()\r\ntotal = 0\r\nfor i in range(num):\r\n\ttotal = total + min(abs(int(x[i]) - int(y[i])), 10 + int(x[i]) - int(y[i]), 10 + int(y[i]) - int(x[i]))\r\nprint(total)", "ip=int(input())\r\nk=input()\r\nj=input()\r\ns=0\r\nfor i in range(ip):\r\n s+=min([abs(int(k[i-1])-int(j[i-1])),10-abs(int(k[i-1])-int(j[i-1]))])\r\nprint(s)\r\n", "n = int(input())\r\nk1 = input()\r\nk2 = input()\r\na = []\r\nb = []\r\nfor i in k1:\r\n a.append(int(i))\r\nfor i in k2:\r\n b.append(int(i))\r\n\r\nans = 0\r\nfor j in range(n):\r\n ans += min(abs(a[j] - b[j]), 10 - abs(a[j] - b[j]))\r\nprint(ans)", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\ncounter = 0\r\nfor i in range(n):\r\n counter += min(abs(int(s1[i]) - int(s2[i])), 10 - abs(int(s1[i]) - int(s2[i])))\r\nprint(counter)", "#!/usr/bin/env python\n# coding: utf-8\n\n# # A. Combination Lock\n# \n# The combination lock is represented by n rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?\n# \n# Input\n# The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of disks on the combination lock.\n# \n# The second line contains a string of n digits — the original state of the disks.\n# \n# The third line contains a string of n digits — Scrooge McDuck's combination that opens the lock.\n# \n# Output\n# Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.\n\n# In[28]:\n\n\ndisk=int(input())\noriginal=input()\ncomb=input()\n\nclk=list(['0','1','2','3','4','5','6','7','8','9'])\nsteps=[]\n\nfor x in range(0,disk):\n s=original[x]\n d=comb[x]\n \n start=clk.index(s)\n end=clk.index(d)\n stepinc=0\n stepdec=0\n while start!=end :\n start+=1\n start=start%10\n stepinc+=1\n \n start=clk.index(s)\n end=clk.index(d) \n while start!=end:\n start-=1\n start=start%10\n stepdec+=1\n \n steps.append(min(stepdec,stepinc))\nprint(sum(steps))\n \n \n \n\n\n# In[ ]:\n\n\n\n\n\n# In[ ]:\n\n\n\n\n\n# In[ ]:\n\n\n\n\n\n# In[ ]:\n\n\n\n\n", "n = int(input())\r\nnum1 = input()\r\nnum2 = input()\r\nsnum1 = []\r\nsnum2 = []\r\nitog = []\r\nsym = 0\r\nrazn = 0\r\nfor i in num1:\r\n snum1.append(int(i))\r\nfor i in num2:\r\n snum2.append(int(i))\r\nfor i in range(n):\r\n razn = abs(snum1[i] - snum2[i])\r\n if razn > 5:\r\n razn = 10 - razn\r\n itog.append(razn)\r\nfor i in itog:\r\n sym += i\r\nprint(sym)", "n = int(input())\r\na = input()\r\nb = input()\r\ncnt = 0\r\nfor i in range(n):\r\n\tsum = abs(int(a[i])-int(b[i]))\r\n\tif sum <=5:\r\n\t\tcnt += sum\r\n\telse:\r\n\t\tcnt+=10-sum\r\nprint(cnt)", "size = int(input())\r\norg = input()\r\ndupl = input()\r\nresult = 0\r\n\r\nfor i in range(size):\r\n f, s = int(org[i]), int(dupl[i])\r\n val = min(abs(f - s), abs(10 - max(f, s) + min(f, s)))\r\n #print(\"V\", val)\r\n result = result + val\r\n #print(\"R\", result)\r\nprint(result)", "n = int(input())\r\na = input()\r\nb = input()\r\nresult = 0\r\nfor i in range(n):\r\n\tif a[i] >= b[i]:\r\n\t\tif int(b[i])+10-int(a[i])>=5:\r\n\t\t\tresult+=int(a[i])-int(b[i])\r\n\t\telse:\r\n\t\t\tresult+=int(b[i])+10-int(a[i])\r\n\telse:\r\n\t\tif int(a[i])+10-int(b[i])>=5:\r\n\t\t\tresult+=int(b[i])-int(a[i])\r\n\t\telse:\r\n\t\t\tresult+=int(a[i])+10-int(b[i])\r\nprint(result)", "n = int(input())\r\nx1 = input()\r\nx2 = input()\r\ns = 0\r\nfor i in range(n) :\r\n forward = abs(int(x1[i]) - int(x2[i]))\r\n backward = 9 - forward +1\r\n s += min(forward, backward)\r\n\r\nprint(s)\r\n", "input()\r\nprint(sum(min(abs(current - target), 10 - abs(current - target))\r\n for current, target in ((int(a), int(b)) for a, b in zip(input(), input()))))\r\n", "n=int(input())\r\norign=list(map(int,input()))\r\nfinal=list(map(int,input()))\r\nresult=0\r\n\r\nfor i in range(n):\r\n a=abs(orign[i]-final[i])\r\n b=abs(10+final[i]-orign[i])\r\n c=abs(10+orign[i]-final[i])\r\n result+=min(a,b,c)\r\nprint(result)", "# 코드포스 540A Combination Lock\r\nimport sys\r\nput = sys.stdin.readline\r\n\r\nn = int(put())\r\npw1 = put().strip()\r\npw2 = put().strip()\r\nanswer = 0\r\n\r\nfor i in range(n):\r\n a, b = sorted([int(pw1[i]), int(pw2[i])])\r\n answer += min(b - a, a - b + 10)\r\n\r\nprint(answer)", "def find_min(a, b):\r\n if a == b:\r\n return 0\r\n if b < a:\r\n s = a\r\n a = b\r\n b = s\r\n f1 = b - a\r\n f2 = a + (9 - b) + 1\r\n if f1 > f2:\r\n f1 = f2\r\n return f1\r\n\r\nn = int(input())\r\np1 = input()\r\np2 = input()\r\nindex = 0\r\nt = 0\r\nwhile index < n:\r\n k = find_min(int(p1[index]), int(p2[index]))\r\n t = t + k\r\n index = index + 1\r\n\r\nprint(t)", "n = int(input())\r\norg = input()\r\nkey = input()\r\ncoN=0\r\nfor i in range(n):\r\n t=int(org[i])\r\n p = int(key[i])\r\n l=max(t,p)\r\n k=min(t,p)\r\n coN+=min(abs(t-p),(10-l+k))\r\nprint(coN)", "x = int(input())\r\nkey1 = input()\r\nkey2 = input()\r\nmoves = 0\r\nif len(key1) and len(key2) == x:\r\n lst_key1 = []\r\n lst_key2 = []\r\n for i in key1:\r\n lst_key1.append(int(i))\r\n for i in key2:\r\n lst_key2.append(int(i))\r\n for i in range(len(key1)):\r\n moves1 = 10 + lst_key1[i] - lst_key2[i]\r\n moves2 = lst_key2[i] - lst_key1[i]\r\n if moves1 > 10:\r\n moves1 = 10 + lst_key2[i] - lst_key1[i]\r\n if moves2 < 0:\r\n moves2 = lst_key1[i] - lst_key2[i]\r\n if moves1 >= moves2:\r\n moves += moves2\r\n elif moves1 < moves2:\r\n moves += moves1\r\nprint(moves)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sun Aug 14 15:34:31 2022\r\n\r\n@author: asus\r\n\"\"\"\r\n\r\nn=int(input(''))\r\ns1=list(input(''))\r\ns2=list(input(''))\r\nsum1=0\r\nfor i in range(n):\r\n cha=abs(int(s1[i])-int(s2[i]))\r\n if cha<=5:\r\n sum1=sum1+cha\r\n else:\r\n sum1=sum1+10-cha\r\nprint(sum1)", "def fu(sone, stwo):\n moves =0\n for i in range(len(sone)):\n \n moves +=min(abs(int(sone[i])-int(stwo[i])), otherway(sone[i], stwo[i]))\n return moves\ndef otherway(f, s):\n v =0\n f =int(f)\n s =int(s)\n if f>s:\n while f!=s:\n f +=1\n if f==10:\n f =0\n v +=1\n else:\n while s!=f:\n s +=1\n if s==10:\n s =0\n v +=1\n return v\n\n\ndef main():\n a =int(input())\n st =input()\n st1 =input()\n print(fu(st, st1))\n\n\nmain()", "#CombinationLock\r\n\r\nvalue = int(input())\r\n\r\noriginal = input()\r\nopenLock = input()\r\n\r\nFinalResult = 0\r\nfor num in range(value):\r\n\r\n\tResult1 = abs(int(original[num]) - int(openLock[num]))\r\n\t\r\n\tif(int(original[num]) > int(openLock[num])):\r\n\t\tResult2 = abs(int(original[num]) - (int(openLock[num])+10))\r\n\t\t# print('hi')\r\n\telse:\r\n\t\tResult2 = abs((int(original[num])+10) - int(openLock[num]))\r\n\r\n\t# print(Result1,Result2)\r\n\r\n\tif(Result2 == 10):\r\n\t\tResult2 = 0\r\n\r\n\tif(Result1 > Result2):\r\n\t\tFinalResult += Result2\r\n\telse:\r\n\t\tFinalResult += Result1\r\nprint(FinalResult)", "n=int(input())\r\na=list(input())\r\nb=list(input())\r\ncount=0\r\nfor i in range(n):\r\n\tif int(a[i])>int(b[i]):\r\n\t\tif (int(a[i])-int(b[i]))>((10-int(a[i]))+int(b[i])):\r\n\t\t\tcount+=(10-int(a[i])+int(b[i]))\r\n\t\telse:\r\n\t\t\tcount+=(int(a[i])-int(b[i]))\r\n\telse:\r\n\t\tif (int(b[i])-int(a[i]))>((10-int(b[i]))+int(a[i])):\r\n\t\t\tcount+=(10-int(b[i])+int(a[i]))\r\n\t\telse:\r\n\t\t\tcount+=(int(b[i])-int(a[i]))\r\nprint(count)", "n = int(input())\r\ns1 = input()\r\ns2 = input()\r\nt = 0\r\nfor i in range(len(s1)):\r\n if int(s1[i]) > int(s2[i]):\r\n t += min((int(s1[i]) - int(s2[i])), (10 - int(s1[i]) + int(s2[i])))\r\n elif int(s1[i]) < int(s2[i]):\r\n t += min((int(s2[i]) - int(s1[i])), (10 + int(s1[i]) - int(s2[i])))\r\n else:\r\n t += 0\r\nprint(t)" ]
{"inputs": ["5\n82195\n64723", "12\n102021090898\n010212908089", "1\n8\n1", "2\n83\n57", "10\n0728592530\n1362615763", "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n3459912084922154505910287499879975659298239371519889866585472674423008837878123067103005344986554746", "1\n8\n1", "2\n83\n57", "3\n607\n684", "4\n0809\n0636", "5\n84284\n08941", "25\n8037856825987124762280548\n9519431339078678836940020", "125\n23269567683904664184142384849516523616863461607751021071772615078579713054027902974007001544768640273491193035874486891541257\n47635110303703399505805044019026243695451609639556649012447370081552870340011971572363458960190590266459684717415349529509024", "5\n84284\n08941", "25\n8037856825987124762285484\n9519431339078678836940202", "125\n23269567689466418414238845152168634610771021717726157879713054270294007001544768647391193035874486891412573389247025830678706\n47635110307339950580504010224954516093956649124473708152870340117152363458960190596659684717415349529090241694059599629136831", "5\n84284\n08941", "25\n8378525987476228048406972\n9194339078883694020217816", "125\n23269576839046618414238484916523616863461607750210717761078579713054027902974007015447686027349193035874486891541257338624472\n47635103037033950580504401926243695451609639556490124437081552870340011971572363489601905026645984717415349529509024169604599", "1\n0\n0", "1\n7\n7", "1\n0\n5", "1\n2\n7", "1\n7\n9", "1\n9\n7", "1\n2\n9", "1\n9\n2", "25\n3164978461316464614169874\n9413979197249127496597357", "4\n9999\n9999", "2\n11\n11"], "outputs": ["13", "16", "3", "7", "27", "245", "3", "7", "5", "8", "16", "72", "305", "16", "74", "357", "16", "55", "274", "0", "0", "5", "5", "2", "2", "3", "3", "66", "0", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
899
18574ec81ce029d7932890bfd5465160
Restoration of the Permutation
Let *A*<==<={*a*1,<=*a*2,<=...,<=*a**n*} be any permutation of the first *n* natural numbers {1,<=2,<=...,<=*n*}. You are given a positive integer *k* and another sequence *B*<==<={*b*1,<=*b*2,<=...,<=*b**n*}, where *b**i* is the number of elements *a**j* in *A* to the left of the element *a**t*<==<=*i* such that *a**j*<=≥<=(*i*<=+<=*k*). For example, if *n*<==<=5, a possible *A* is {5,<=1,<=4,<=2,<=3}. For *k*<==<=2, *B* is given by {1,<=2,<=1,<=0,<=0}. But if *k*<==<=3, then *B*<==<={1,<=1,<=0,<=0,<=0}. For two sequences *X*<==<={*x*1,<=*x*2,<=...,<=*x**n*} and *Y*<==<={*y*1,<=*y*2,<=...,<=*y**n*}, let *i*-th elements be the first elements such that *x**i*<=≠<=*y**i*. If *x**i*<=&lt;<=*y**i*, then *X* is lexicographically smaller than *Y*, while if *x**i*<=&gt;<=*y**i*, then *X* is lexicographically greater than *Y*. Given *n*, *k* and *B*, you need to determine the lexicographically smallest *A*. The first line contains two space separated integers *n* and *k* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*k*<=≤<=*n*). On the second line are *n* integers specifying the values of *B*<==<={*b*1,<=*b*2,<=...,<=*b**n*}. Print on a single line *n* integers of *A*<==<={*a*1,<=*a*2,<=...,<=*a**n*} such that *A* is lexicographically minimal. It is guaranteed that the solution exists. Sample Input 5 2 1 2 1 0 0 4 2 1 0 0 0 Sample Output 4 1 5 2 3 2 3 1 4
[ "s = input()\r\nl = s.split()\r\n\r\nn = int(l[0])\r\nk = int(l[1])\r\n\r\ns = input()\r\nl = s.split()\r\n\r\nb = [-1]\r\n\r\nfor i in range(1, n + 1):\r\n b.append(int(l[i - 1]))\r\n\r\nfor i in range(1, n + 1):\r\n\r\n j = 1\r\n while b[j] != 0:\r\n j += 1\r\n\r\n b[j] -= 1\r\n print(j, end = ' ')\r\n\r\n for t in range(1, n + 1):\r\n if j - k >= t:\r\n b[t] -= 1\r\n\r\n", "# /*******************************************************************************\r\n# * Author : Quantum Of Excellence\r\n# * email : quantumofexcellence (at) gmail (dot) com\r\n# * copyright : 2014 - 2015\r\n# * date : 6 - 11 - 2015\r\n# * Judge Status : \r\n# * file name : 67B.py\r\n# * version : 1.0\r\n# *\r\n# * TERMS OF USE - Write a mail to the author before copying or reusing the content of this file \r\n# * seeking our permission for the same.\r\n# * Copying/reuse of the below code without the permission of the author is prohibited and illegal.\r\n# *\r\n# * All rights reserved by Quantum Of Excellence.\r\n# ******************************************************************************/\r\n\r\n# /*******************************************************************************\r\n# * some pointers on the logic/idea - \r\n# *\r\n# * \r\n# *******************************************************************************/\r\n\r\n\r\n# test cases-\r\n\r\n\r\n#import sys\r\n#fi = open(\"G:\\DUMP\\input.in\",\"r\")\r\n#sys.stdin = fi\r\nu=input\r\nn,k=map(int,u().split())\r\nM=[int(i) for i in u().split()]\r\nm=0\r\nfor j in range(n):\r\n # find unvisited zeros\r\n for p in range(n):\r\n if(0==M[p]):\r\n print(p+1,end=' ')\r\n break\r\n for l in range(p+1-k):M[l]-=1\r\n # make the visited zero negative\r\n M[p]-=1\r\n", "n, k = map(int, input().split())\r\nb = list(map(int, input().split()))\r\n\r\ntaken = [False for i in range(n + 2)]\r\na = []\r\n\r\nfor i in range(n):\r\n has = -1\r\n \r\n for j in range(1, n + 1):\r\n if not taken[j] and b[j - 1] == 0:\r\n has = j\r\n break\r\n \r\n a.append(has)\r\n taken[has] = True\r\n \r\n for j in range(1, has - k + 1):\r\n b[j - 1] -= 1\r\n\r\nprint(*a)", "def process(B, k):\r\n n = len(B)\r\n A = []\r\n for i in range(n-k+1, n+1):\r\n A.append(i)\r\n for i in range(n-k, 0, -1):\r\n c = B[i-1]\r\n if c==0:\r\n A = [i]+A\r\n else:\r\n index = None\r\n my_count = 0\r\n for j in range(len(A)):\r\n if A[j] >= (i+k):\r\n my_count+=1\r\n if my_count==c:\r\n index = j+1\r\n break\r\n A = A[:index]+[i]+A[index:]\r\n return A\r\n\r\nn, k = [int(x) for x in input().split()]\r\nB = [int(x) for x in input().split()]\r\nanswer = process(B, k)\r\nprint(' '.join(map(str, answer)))", "u=input\r\nn,k=map(int,u().split())\r\nM=[int(i) for i in u().split()]\r\nm=0\r\nfor j in range(n): \r\n for p in range(n):\r\n if(0==M[p]):\r\n print(p+1,end=' ')\r\n break\r\n for l in range(p+1-k):M[l]-=1\r\n M[p]-=1", "# ========= /\\ /| |====/|\r\n# | / \\ | | / |\r\n# | /____\\ | | / |\r\n# | / \\ | | / |\r\n# ========= / \\ ===== |/====| \r\n# code\r\n\r\ndef main():\r\n n,k = map(int,input().split())\r\n a = list(map(int,input().split()))\r\n b = [0]*n\r\n for i in range(n):\r\n l = -1\r\n for j in range(n):\r\n if a[j] == 0:\r\n l = j\r\n b[i] = j + 1\r\n a[j] -= 1\r\n break\r\n for j in range(n):\r\n if l >= j + k:\r\n a[j] -= 1\r\n print(*b)\r\n return\r\n\r\nif __name__ == \"__main__\":\r\n main()" ]
{"inputs": ["5 2\n1 2 1 0 0", "4 2\n1 0 0 0", "10 3\n4 2 4 2 1 0 1 0 0 0", "15 3\n4 2 7 5 1 1 1 0 0 0 0 0 0 0 0", "5 1\n1 3 2 0 0", "8 3\n2 0 2 2 1 0 0 0", "1 1\n0", "10 10\n0 0 0 0 0 0 0 0 0 0", "10 9\n1 0 0 0 0 0 0 0 0 0", "10 1\n9 8 7 6 5 4 3 2 1 0", "10 1\n7 6 5 4 3 2 1 0 0 0", "13 2\n1 2 3 4 5 4 3 2 1 0 0 0 0", "2 2\n0 0", "2 1\n1 0", "2 1\n0 0", "3 1\n2 1 0", "5 1\n4 3 2 1 0", "5 4\n1 0 0 0 0", "20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0", "20 2\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0", "20 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0", "20 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0", "10 1\n1 1 1 1 1 1 1 1 1 0", "130 32\n72 56 81 71 45 17 65 13 87 22 17 75 72 80 68 76 62 35 14 53 49 72 19 55 10 57 28 35 66 59 45 24 37 65 46 31 34 1 30 12 37 13 40 41 39 6 31 28 30 0 2 7 23 32 0 34 21 0 23 3 18 33 7 6 20 19 21 10 27 28 19 23 5 15 22 13 14 1 3 14 0 5 1 14 0 0 7 11 10 1 1 1 6 5 3 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"], "outputs": ["4 1 5 2 3 ", "2 3 1 4 ", "6 8 2 5 9 1 4 10 3 7 ", "8 5 2 9 6 1 10 7 11 4 12 3 13 14 15 ", "4 1 5 3 2 ", "2 6 7 1 3 8 4 5 ", "1 ", "1 2 3 4 5 6 7 8 9 10 ", "2 3 4 5 6 7 8 9 10 1 ", "10 9 8 7 6 5 4 3 2 1 ", "8 7 6 5 4 3 2 1 9 10 ", "10 1 11 2 8 3 9 4 6 7 5 12 13 ", "1 2 ", "2 1 ", "1 2 ", "3 2 1 ", "5 4 3 2 1 ", "2 3 4 5 1 ", "17 1 2 3 4 5 6 7 8 9 10 11 12 13 18 14 19 15 20 16 ", "19 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 20 18 ", "20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ", "18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 20 ", "10 1 2 3 4 5 6 7 8 9 ", "50 55 58 81 38 85 86 51 97 99 100 46 60 101 8 102 25 52 103 6 19 64 11 104 63 105 106 40 107 10 42 108 23 109 68 73 110 78 111 112 113 79 32 114 115 27 61 83 18 116 117 65 66 118 28 53 5 57 82 119 36 39 67 120 48 59 74 76 2 33 121 37 71 122 21 47 49 77 90 41 123 20 31 91 124 7 92 125 43 1 4 45 54 80 17 24 35 44 87 126 72 26 127 15 69 3 128 13 56 75 12 129 70 30 84 95 62 16 130 88 14 22 89 29 93 9 94 96 98 34 "]}
UNKNOWN
PYTHON3
CODEFORCES
6
1863b6f28ad0474a2c0dc6ef0e81a030
Megacity
The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city. The city of Tomsk can be represented as point on the plane with coordinates (0; 0). The city is surrounded with *n* other locations, the *i*-th one has coordinates (*x**i*, *y**i*) with the population of *k**i* people. You can widen the city boundaries to a circle of radius *r*. In such case all locations inside the circle and on its border are included into the city. Your goal is to write a program that will determine the minimum radius *r*, to which is necessary to expand the boundaries of Tomsk, so that it becomes a megacity. The first line of the input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=103; 1<=≤<=*s*<=&lt;<=106) — the number of locatons around Tomsk city and the population of the city. Then *n* lines follow. The *i*-th line contains three integers — the *x**i* and *y**i* coordinate values of the *i*-th location and the number *k**i* of people in it (1<=≤<=*k**i*<=&lt;<=106). Each coordinate is an integer and doesn't exceed 104 in its absolute value. It is guaranteed that no two locations are at the same point and no location is at point (0; 0). In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity. The answer is considered correct if the absolute or relative error don't exceed 10<=-<=6. Sample Input 4 999998 1 1 1 2 2 1 3 3 1 2 -2 1 4 999998 1 1 2 2 2 1 3 3 1 2 -2 1 2 1 1 1 999997 2 2 1 Sample Output 2.8284271 1.4142136 -1
[ "import math\r\n \r\ndef solve():\r\n numLocation, totalPeople = map(int, input().split())\r\n location = dict()\r\n for i in range(numLocation):\r\n x, y, people = map(int, input().split())\r\n r = x * x + y * y\r\n if r in location:\r\n location[r] += people\r\n else:\r\n location[r] = people\r\n radius = []\r\n for r in location:\r\n radius.append(r)\r\n radius.sort()\r\n for r in radius:\r\n totalPeople += location[r]\r\n if totalPeople >= 1000000:\r\n print(math.sqrt(r))\r\n return\r\n print(\"-1\")\r\n \r\nsolve()", "import math\r\n\r\n\r\n\r\n\r\ndef main_function():\r\n n, s = [int(i) for i in input().split(\" \")]\r\n r_s = []\r\n current_r = 0\r\n for i in range(n):\r\n x, y, k = [int(u) for u in input().split(\" \")]\r\n r_s.append([math.sqrt(x ** 2 + y ** 2), k])\r\n r_s.sort(key=lambda x:x[0])\r\n for i in r_s:\r\n r, k = i\r\n if s >= 1000000:\r\n print(current_r)\r\n break\r\n current_r = r\r\n s += k\r\n if s >= 1000000:\r\n print(current_r)\r\n break\r\n if s < 1000000:\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\nmain_function()\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n#main_function()", "import math\r\nif __name__ == '__main__':\r\n n, s = map(int, input().split())\r\n d = dict()\r\n for i in range(n):\r\n x, y, k = map(int, input().split())\r\n if not (x * x + y * y) in d:\r\n d[x * x + y * y] = k\r\n else:\r\n d[x * x + y * y] += k\r\n flag = False\r\n a = []\r\n for key in d.keys():\r\n a.append(key)\r\n a.sort()\r\n for x in a:\r\n s += d[x]\r\n if s >= (1e6):\r\n print('{0:.7}'.format(math.sqrt(x)))\r\n flag = True\r\n break\r\n if not flag:\r\n print(-1)\r\n\r\n", "n, s = map(int, input().split())\r\nl = []\r\nfor _ in range(n):\r\n x, y, k = map(int, input().split())\r\n l.append(((x**2+y**2)**0.5, k))\r\n\r\nl.sort()\r\ni = 0\r\ndist = 0\r\n\r\nwhile s < 10**6 and i < n:\r\n s += l[i][1]\r\n dist = l[i][0]\r\n i += 1\r\n\r\nif s < 10**6:\r\n print(\"-1\")\r\nelse:\r\n print((\"%.7f\")%dist)\r\n \r\n", "# Problem from Codeforces\r\n# http://codeforces.com/problemset/problem/424/B\r\n\r\n\r\nimport math\r\n\r\n\r\nclass Location:\r\n def __init__(self, r, k):\r\n self.r = r\r\n self.k = k\r\n\r\n def __lt__(self, other):\r\n return self.r < other.r\r\n\r\n\r\ndef solution():\r\n n, s = map(int, input().split())\r\n locations = []\r\n for i in range(n):\r\n x, y, k = map(int, input().split())\r\n locations.append(Location(math.sqrt(x*x + y*y), k))\r\n\r\n locations.sort()\r\n\r\n min_r = 0\r\n for i in range(n):\r\n if s >= 1000000:\r\n print(round(min_r, 7))\r\n return\r\n s += locations[i].k\r\n min_r = locations[i].r\r\n\r\n if s >= 1000000:\r\n print(round(min_r, 7))\r\n else:\r\n print(-1)\r\n\r\n\r\nsolution()\r\n", "MEGA = 10**6\r\nEPS = 10**-8\r\n\r\ndef dist(a, b):\r\n return pow((a[0] -b[0])**2 + (a[1] - b[1])**2, 0.5)\r\n\r\nn, p = map(int, input().split())\r\no = (0, 0)\r\ncity = []\r\npop = []\r\nlo = 0\r\nhi = 0\r\nfor i in range(n):\r\n x, y, k = map(int, input().split())\r\n city.append((x, y))\r\n d = dist(o, (x, y))\r\n hi = max(hi, d)\r\n pop.append(k)\r\ntotal = sum(pop) + p\r\nif total < MEGA:\r\n print(-1)\r\nelse:\r\n while lo + EPS < hi:\r\n mi = (lo + hi)/2\r\n newP = p\r\n for i in range(n):\r\n if (dist(o, city[i]) <= mi):\r\n newP += pop[i]\r\n if newP >= MEGA:\r\n hi = mi\r\n else:\r\n lo = mi\r\n print(\"{:.7f}\".format((lo+hi)/2))\r\n", "import math\nn, s = map(int, input().split())\nlocs = []\nfor _ in range(n):\n\tx, y, k = map(int, input().split())\n\td = math.sqrt(x*x+y*y)\n\tlocs[len(locs):] = [(d,k)]\nlocs.sort()\ni = 0\ndmin = 0\nwhile i<len(locs) and s<1000000:\n\tdmin = locs[i][0]\n\ts += locs[i][1]\n\ti += 1\n\nif s < 1000000:\n\tprint (-1)\nelse:\n\tprint (dmin)\n \t\t \t \t \t \t\t\t \t\t \t \t", "from math import sqrt\r\ndef dist(x1, y1, x2, y2):\r\n\treturn sqrt(abs(x1 - x2) ** 2 + abs(y1 - y2) ** 2)\r\nn, s = map(int, input().split())\r\ncity = []\r\nfor i in range(n):\r\n\ta, b, x = map(int, input().split())\r\n\tcity.append([a, b, x])\r\ncity.sort(key = lambda cityCur: dist(0, 0, cityCur[0], cityCur[1]))\r\ncur = 0\r\nwhile cur < n and s < 10 ** 6:\r\n\ts += city[cur][2]\r\n\tr = dist(0, 0, city[cur][0], city[cur][1])\r\n\tcur += 1\r\nif s < 10 ** 6:\r\n\tprint(-1)\r\nelse:\r\n\tprint(r)", "from math import pi, sqrt\r\n\r\nif __name__ == '__main__':\r\n n, s = map(int, input().rstrip().split())\r\n arr = []\r\n for _ in range(n):\r\n line = list(map(int, input().rstrip().split()))\r\n arr.append([sqrt(line[0] ** 2 + line[1] ** 2), line[2]])\r\n arr.sort(key=lambda x: x[0])\r\n flag = False\r\n for e in arr:\r\n s += e[1]\r\n if s >= 1000000:\r\n print(\"{0:.7f}\".format(e[0]))\r\n flag = True\r\n break\r\n if flag == False:\r\n print(-1)\r\n", "import math\r\nn, s= map(int, input().split())\r\ndis=dict()\r\nfor _ in range(n):\r\n a, b, c= map(int, input().split())\r\n k=a*a + b*b\r\n if k not in dis:\r\n dis[k]= c\r\n else:\r\n dis[k]+=c\r\n\r\nfor i in sorted(dis.keys()):\r\n s+= dis[i]\r\n if s >= int(1e6):\r\n print(\"%.7f\" % math.sqrt(i))\r\n exit()\r\nprint(-1)\r\n", "from math import sqrt\r\n\r\nn, s = map(int, input().split())\r\nM = dict()\r\nfor i in range(n):\r\n x, y, k = map(int, input().split())\r\n if x*x + y*y in M:\r\n M[x*x + y*y] += k\r\n else:\r\n M[x*x + y*y] = k\r\nfor key, value in sorted(M.items()):\r\n s += value\r\n if s >= 1000000:\r\n print(\"%.10f\" %sqrt(key))\r\n exit(0)\r\nprint(-1)", "n, s = map(int, input().split())\r\nc = []\r\nfor i in range(n):\r\n x, y, z = map(int, input().split())\r\n c.append((x, y, z))\r\nminans = 10**20\r\nfor i in range(n):\r\n nc = 0\r\n total = s\r\n for j in range(n):\r\n if c[j][0] ** 2 + c[j][1] ** 2 <= c[i][0] ** 2 + c[i][1] ** 2:\r\n total += c[j][2]\r\n if total >= 10**6 and c[i][0] ** 2 + c[i][1] ** 2 < minans:\r\n minans = c[i][0] ** 2 + c[i][1] ** 2\r\nif minans != 10**20:\r\n print(minans ** 0.5)\r\nelse:\r\n print(-1)", "import math\n\nn, s = [int(x) for x in input().split()]\ncities = []\n\nfor i in range(n):\n x, y, k = [int(x) for x in input().split()]\n d2 = x ** 2 + y ** 2\n cities.append((d2, k))\n\ncities.sort(key=lambda x: x[0])\n\nif s >= int(1E6):\n print(0)\n exit()\n\nwhile cities:\n t = cities.pop(0)\n s += t[1]\n if s >= int(1E6):\n print(math.sqrt(t[0]))\n exit()\n\nprint(-1)\n\n\t\t \t\t\t \t\t\t\t\t \t\t \t\t \t\t \t\t\t", "import math\r\nn,s=map(int,input().split())\r\ndist=[]\r\nfor _ in range(n):\r\n x,y,k=map(int,input().split())\r\n dist.append([math.sqrt(x*x+y*y),k])\r\nleft=1000000-s\r\ndist.sort(key = lambda x: x[0])\r\nans=0\r\ni=-1\r\nwhile ans<left:\r\n i+=1\r\n if i==n:\r\n break\r\n ans=ans+dist[i][1]\r\nif i>=0 and i<n:\r\n print(dist[i][0])\r\nelse:\r\n print(\"-1\")\r\n", "\r\n\r\n\r\n\r\ndef main():\r\n n, s = map(int, input().split())\r\n cities = []\r\n for i in range(n):\r\n x, y, p = map(int, input().split())\r\n dist = (x**2 + y**2)**(1/2)\r\n cities.append((x, y, p, dist))\r\n cities.sort(key=lambda city: city[3])\r\n\r\n total = s\r\n for city in cities:\r\n total += city[2]\r\n if total >= 10**6:\r\n print((city[0]**2 + city[1]**2)**(1/2))\r\n return\r\n\r\n\r\n\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\nif __name__ == '__main__':\r\n main()", "n, k = map(int, input().split())\r\nif k >= 1000000:\r\n print('0')\r\n exit(0)\r\ndef f():\r\n x, y, d = map(int, input().split())\r\n return (x * x + y * y, d)\r\nt = [f() for i in range(n)]\r\nt.sort()\r\nfor r, d in t:\r\n k += d\r\n if k >= 1000000:\r\n print(r ** 0.5)\r\n break\r\nelse: print('-1')", "localidades=[]\r\nn, poblacion= input().split()\r\nn= int(n)\r\npoblacion= int(poblacion)\r\n\r\nfor i in range(n):\r\n a,b,gente= input().split()\r\n a=int(a)\r\n b=int(b)\r\n gente=int(gente)\r\n localidades.append(((a**2 + b**2)**0.5,gente))\r\nlocalidades.sort()\r\nr=0\r\nfor radio, m in localidades:\r\n if poblacion < 1000000:\r\n poblacion+= m\r\n r=radio\r\n else:\r\n break\r\nif poblacion<1000000:\r\n print(-1)\r\nelse:\r\n print(r)\r\n \r\n", "from math import sqrt\r\n\r\n\r\nclass Place:\r\n def __init__(self, x, y, population):\r\n self.x = x\r\n self.y = y\r\n self.population = population\r\n self.dist = sqrt(x ** 2 + y ** 2)\r\n\r\n\r\nn, s = map(int, input().split())\r\nplaces = []\r\nfor _ in range(n):\r\n x, y, k = map(int, input().split())\r\n places.append(Place(x, y, k))\r\n\r\nplaces.sort(key=lambda l: l.dist)\r\nradius = -1\r\nfor place in places:\r\n x, y, k, r = place.x, place.y, place.population, place.dist\r\n if s + k >= int(1e6):\r\n radius = r\r\n break\r\n else:\r\n s += k\r\n\r\nprint('{:.7f}'.format(radius))\r\n", "n, s = map(int, input().split())\r\nd = {}\r\n\r\nfor i in range(n):\r\n\tx, y, k = map(int, input().split())\r\n\tdist = (x**2 + y**2)**(1/2) \r\n\tif dist not in d:\r\n\t\td[dist] = k\r\n\telse:\r\n\t\td[dist] += k \r\n#print(d) \r\nlstKey = sorted(d)\r\n#print(new)\r\nans = None \r\nfor ele in lstKey:\r\n\t#print(ele, d[ele])\r\n\t#print('sum is ' + str(d[ele] +s))\r\n\ts += d[ele]\r\n\tif s >= 1000000:\r\n\t\t#print(\"%.7f\" %(ele))\r\n\t\t#print(ele)\r\n\t\tans = ele\r\n\t\tbreak \r\n#print(d) \r\n#print(lstKey)\r\nif ans == None:\r\n\tprint(-1)\r\nelse:\r\n\tprint(\"%.7f\" %(ele))", "import math \r\nn,s=map(int,input('').split())\r\nL=[]\r\nfor i in range(n):\r\n x,y,z=map(int,input('').split())\r\n L+=[(math.sqrt(x*x+y*y),z)]\r\nL.sort()\r\ncount=s\r\nif s>=1000000:\r\n print('0')\r\n exit()\r\nfor i in L:\r\n count+=i[1]\r\n if count>=1000000:\r\n print(i[0])\r\n exit()\r\n \r\nprint('-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", "from sys import stdin, stdout\r\nfrom math import sqrt\r\nnmbr = lambda: int(stdin.readline())\r\nlst = lambda: list(map(int,stdin.readline().split()))\r\nfn= lambda x,y: sqrt(x*x+y*y)\r\nmega=10**6\r\nfor i in range(1):#nmbr()):\r\n n,init=lst()\r\n l=[lst() for i in range(n)]\r\n l.sort(key=lambda x:fn(x[0],x[1]))\r\n # print(l)\r\n ans=-1\r\n for i in range(n):\r\n init+=l[i][2]\r\n if init>=mega:\r\n ans=fn(l[i][0],l[i][1])\r\n break\r\n print(ans)", "import math\r\nn,s=map(int,input().split(\" \"))\r\nli=[]\r\nfor i in range(n):\r\n x,y,z=map(int,input().split(\" \"))\r\n li.append([math.sqrt(x**2 + y**2),z])\r\nli.sort()\r\nans=0\r\nan=s\r\nk=0\r\nwhile k!=n and an<1000000:\r\n an+=li[k][1]\r\n ans=li[k][0]\r\n k+=1\r\nif k==n and an<1000000:\r\n print(-1)\r\nelse:\r\n print(ans)\r\n", "n,s=map(int,input().split())\r\na=[]\r\nc=0\r\nfor i in range(n):\r\n x,y,k=map(int,input().split())\r\n c+=k\r\n a+=[(x,y,k)]\r\nif(s+c<1000000):\r\n print(-1)\r\nelse:\r\n a.sort(key=lambda x:((abs(x[0]*x[0])+abs(x[1]*x[1]))**(0.5)))\r\n ans1=0\r\n ans2=0\r\n for i in range(n):\r\n s+=a[i][2]\r\n if(s>=1000000):\r\n ans1=a[i][0]\r\n ans2=a[i][1]\r\n break\r\n print((abs(ans1*ans1)+abs(ans2*ans2))**(0.5))", "import math\r\ndef inp():\r\n return map(int, input().split())\r\ndef solve():\r\n n, total_people = inp()\r\n location = dict()\r\n for i in range(n):\r\n x, y, people = inp()\r\n r = x * x + y * y\r\n if not r in location:\r\n location[r] = people\r\n else:\r\n location[r] += people\r\n R = []\r\n for r in location:\r\n R.append(r)\r\n R.sort()\r\n for r in R:\r\n total_people+= location[r]\r\n if total_people >= 1000000:\r\n print(math.sqrt(r))\r\n return\r\n\r\n print(\"-1\")\r\nsolve()", "import math\r\nR = lambda: map(int, input().split())\r\nn, sum = R()\r\nx = []; y = []; z = []; dis = []\r\nfor i in range(n):\r\n a, b, c = R()\r\n x.append(a)\r\n y.append(b)\r\n z.append(c)\r\n dis.append((math.sqrt(a**2 + b ** 2), i))\r\ndis.sort()\r\ni = 0\r\nwhile sum < 1000000 and i < n:\r\n sum += z[dis[i][1]]\r\n i += 1\r\nif sum < 1000000: print('-1')\r\nelse: print(dis[i-1][0])\r\n", "from math import sqrt\r\n\r\ndef sort_fun(el):\r\n return sqrt(el[0] ** 2 + el[1] ** 2)\r\n\r\ndef main():\r\n cities, population = [int(x) for x in input().split(\" \")]\r\n data = []\r\n\r\n for _ in range(cities):\r\n data.append([int(x) for x in input().split(\" \")])\r\n\r\n data.sort(key=sort_fun)\r\n \r\n for x, y, inc_pop in data:\r\n population += inc_pop\r\n\r\n if population >= 1000000:\r\n print(sqrt(x ** 2 + y ** 2))\r\n return\r\n\r\n print(-1)\r\n\r\nmain()\r\n", "from math import sqrt\nn, s = map(int,input().split())\ndist = 0\nd = dict()\nfor _ in range (n):\n a,b,c = map(int,input().split())\n square_dist = a*a + b*b # su dung square dict de ko phai lai sqrt, so chinh xac hon va chay nhanh hon\n if square_dist in d:\n d[square_dist] += c\n else:\n d[square_dist] = c\nres = -1\nsorted_d = sorted(d)\nfor it in sorted_d:\n s += d[it] # get value\n if s >= 1000000:\n res = sqrt(int(it))\n break\nprint (res)", "import math\r\n\r\nclass location:\r\n def __init__(self, distance, population):\r\n self.distance = distance\r\n self.population = population\r\n\r\n def __lt__(self, other):\r\n return self.distance < other.distance\r\n\r\ndef find_m_radius():\r\n num_settlements, city_population = map(int, input().split())\r\n \r\n settlements = []\r\n \r\n for i in range(num_settlements):\r\n x, y, population = map(int, input().split())\r\n distance = math.sqrt(x * x + y * y)\r\n settlements.append(location(distance, population))\r\n \r\n settlements.sort()\r\n \r\n min_radius = 0\r\n \r\n for i in range(num_settlements):\r\n if city_population >= 1000000:\r\n print(round(min_radius, 7))\r\n return\r\n \r\n city_population += settlements[i].population\r\n min_radius = settlements[i].distance\r\n\r\n if city_population >= 1000000:\r\n print(round(min_radius, 7))\r\n else:\r\n print(-1)\r\n \r\nif __name__ == \"__main__\":\r\n find_m_radius()# 1698272756.4706304", "n,s = map(int, input().split(' '))\r\nr = 0\r\np = s\r\nt=0\r\narr = []\r\nfor i in range(n):\r\n x,y,k = map(int, input().split(' '))\r\n arr.append([x,y,k])\r\narr = sorted(arr, key=lambda z:z[0]**2+z[1]**2)\r\n\r\nfor j in range(n):\r\n r = (arr[j][0]**2+arr[j][1]**2)**0.5\r\n p += arr[j][2]\r\n if p >= 1000000:\r\n t=1\r\n break\r\n\r\nprint(r if t==1 else -1)\r\n", "n, s = map(int, input().split())\r\na = []\r\nfor _ in range(n):\r\n x, y, k = map(int, input().split())\r\n a.append([x ** 2 + y ** 2, k])\r\n \r\na.sort()\r\nds = 1000000 - s \r\n\r\ndist = 0\r\ni = 0\r\nwhile i < n and ds > 0:\r\n ds -= a[i][1]\r\n i += 1\r\n \r\nif i == 0: print(0)\r\nelif ds <= 0 and i > 0: print(a[i - 1][0] ** 0.5)\r\nelse: print(-1)", "import math\r\n\r\nR = lambda: map(int, input().split())\r\n\r\nn, s = R()\r\ncities = [tuple(R()) for _ in range(n)]\r\nif sum(x[2] for x in cities) + s < 10**6:\r\n print(-1)\r\n exit()\r\nl, r = 0, max(x[0] * x[0] + x[1] * x[1] for x in cities)\r\nwhile l < r:\r\n m = (l + r) // 2\r\n acc = s + sum(x[2] for x in cities if x[0] * x[0] + x[1] * x[1] <= m)\r\n if acc < 10**6:\r\n l = m + 1\r\n else:\r\n r = m\r\nprint(math.sqrt(r))", "from sys import stdin, stdout\r\nfrom math import sqrt\r\nnmbr = lambda: int(stdin.readline())\r\nlst = lambda: list(map(int,stdin.readline().split()))\r\nsq= lambda x,y: (x*x+y*y)\r\nmega=10**6\r\ndef fn(rad):\r\n sm=init\r\n for a,b,pop in l1:\r\n if sq(a,b)<=rad:\r\n sm+=pop\r\n if sm>=mega:return True\r\n return False\r\nfor _ in range(1):#nmbr()):\r\n n,init=lst()\r\n l1=[lst() for i in range(n)]\r\n total=sum(v[2] for v in l1)\r\n if total+init<mega:\r\n print(-1)\r\n continue\r\n l=1;r=10**12\r\n while l<=r:\r\n mid=(l+r)>>1\r\n if fn(mid)==False:l=mid+1\r\n else:r=mid-1\r\n print(sqrt(l))", "n, s = map(int, input().split())\r\narr = []\r\nfor i in range(n):\r\n x, y, k = map(int, input().split())\r\n arr.append((x**2 + y**2, k))\r\narr.sort()\r\nres, idx, r = 0, 0, 0\r\nwhile(idx < n and s + res < 1e6):\r\n r = arr[idx][0]\r\n res += arr[idx][1]\r\n idx += 1\r\nprint(r ** .5 if(s + res >= 1e6) else -1)\r\n", "from collections import defaultdict\r\nfrom math import hypot\r\n\r\nI = lambda: map(int, input().split())\r\n\r\nn, s = I()\r\nd = defaultdict(int)\r\n\r\nfor _ in range(n):\r\n x, y, k = I()\r\n d[hypot(x,y)] += k\r\n\r\nfor r,k in sorted(d.items()):\r\n s += k\r\n if s > 999999:\r\n print(r)\r\n break\r\nelse:\r\n print(-1)", "from math import sqrt\r\nn,s=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n x,y,k=map(int,input().split())\r\n d=sqrt(x**2+y**2)\r\n l.append([d,k])\r\nl.sort()\r\ni=0\r\nk=0\r\ng=10**6\r\nwhile i<n and s+k<g:\r\n\r\n k+=l[i][1]\r\n \r\n i+=1\r\nif k+s<g:\r\n print(-1)\r\nelse:\r\n print(round(l[i-1][0],7))\r\n", "n, s = map(int, input().split())\r\nlocation = dict()\r\nres = -1\r\nfor _ in range(n):\r\n x, y, k = map(int, input().split())\r\n r = x ** 2 + y ** 2\r\n if r in location:\r\n location[r] += k\r\n else:\r\n location[r] = k\r\n \r\nradius = []\r\nfor r in location:\r\n radius.append(r)\r\nradius.sort()\r\nfor r in radius:\r\n s += location[r]\r\n if s >= 10 ** 6:\r\n res = r ** 0.5\r\n break\r\n\r\nprint(res)", "import math\r\n\r\nn, s = map(int, input().split())\r\nradius_pop = {}\r\nfor _ in range(n):\r\n x, y, k = map(int, input().split())\r\n r = math.sqrt(x**2 + y**2)\r\n if not (r in radius_pop):\r\n radius_pop[r] = k\r\n else:\r\n radius_pop[r] += k\r\nif s >= 10**6:\r\n print(0)\r\nelse:\r\n sorted_dict = dict(sorted(radius_pop.items(), key=lambda item: item[0]))\r\n min_radius_needed = -1\r\n for radius in sorted_dict.keys():\r\n s += sorted_dict[radius]\r\n if s >= 10**6:\r\n min_radius_needed = radius\r\n break\r\n if min_radius_needed != -1:\r\n print('%.7f' % min_radius_needed)\r\n else:\r\n print(-1)\r\n", "from math import *\r\na,b=map(int,input().split())\r\ns=sorted([hypot(i,j),k] for (i,j,k) in (map(int,input().split()) for _ in \" \"*a))\r\nfor i in range(1,a):\r\n s[i][1]+=s[i-1][1]\r\nlo=0;hi=a-1;ans=-1\r\nwhile lo<=hi:\r\n mid=(lo+hi)//2\r\n if ((b+s[mid][1])>=10**6):ans=mid;hi=mid-1\r\n else:lo=mid+1\r\nif (ans!=-1) :print(s[ans][0])\r\nelse:print(-1)", "import math\r\nn, current_pop = [int(i) for i in input().split()]\r\nsur_area = {}\r\nfor i in range(n):\r\n a, b, c = [int(j) for j in input().split()]\r\n r = a ** 2 + b ** 2\r\n if r not in sur_area:\r\n sur_area[r] = c\r\n else:\r\n sur_area[r] += c\r\n\r\nkey = sorted(sur_area.keys())\r\nfor i in key:\r\n current_pop += sur_area[i]\r\n if current_pop >= 1000000:\r\n print(round(math.sqrt(i), 7))\r\n exit()\r\nprint(-1)\r\n", "import math\r\nn,s = map(int,input().split())\r\nc = []\r\nfor i in range(n):\r\n x,y,p = map(int,input().split())\r\n c.append([x**2+y**2, p])\r\nc.sort()\r\nc[0][1] += s\r\nfor i in range(1, n):\r\n c[i][1] += c[i-1][1]\r\nl = 0\r\nh = n-1\r\nwhile l < h:\r\n m = (l+h)// 2\r\n if c[m][1] >= 1000000:\r\n h = m\r\n else:\r\n l = m+1\r\nif c[l][1] < 1000000:\r\n print('-1')\r\nelse:\r\n print(math.sqrt(c[l][0]))", "from math import*\r\nn, s = map(int, input().split())\r\nk = [0] * 1001\r\nx = [0] * 1001\r\ny = [0] * 1001\r\nr0 = 0\r\nr = 0\r\ncount = 0\r\nMinr = 1000000\r\notv = -1\r\nfor i in range(n):\r\n x[i], y[i], k[i] = map(int, input().split())\r\nfor i in range(n):\r\n count = s\r\n r0 = sqrt((x[i]) ** 2 + y[i] ** 2)\r\n for j in range(n):\r\n r = sqrt((x[j]) ** 2 + y[j] ** 2)\r\n if r <= r0:\r\n count += k[j]\r\n if count >= 1000000 and r0 < Minr:\r\n Minr = r0\r\n otv = r0\r\n break\r\nprint(otv)\r\n\r\n \r\n \r\n ", "# http://codeforces.com/problemset/problem/424/B\n# tags: sort, math formula\n# pow(a, b) = a**b\n# distance formula: d = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))\n# -> (x1, y1) = (0,0)\n# -> d = sqrt(pow(x2, 2) + pow(y2, 2))\n\nimport math\n\nMEGACITY = 10**6\n\ndef getDistanceWithoutSQRT(x, y):\n\treturn x**2 + y**2\n\nif __name__ == \"__main__\":\n\tn, s = list(map(int, input().split(\" \")))\n\tpointDist = dict()\n\texpandDist = -1\n\tfor _ in range(n):\n\t\tx, y, k = list(map(int, input().split(\" \")))\n\t\td = getDistanceWithoutSQRT(x, y)\n\t\tif d not in pointDist:\n\t\t\tpointDist[d] = 0\n\t\tpointDist[d] += k\n\t\n\tsortedKeys = sorted(pointDist)\n\n\tfor dist in sortedKeys:\n\t\ts += pointDist[dist]\n\t\tif s >= MEGACITY:\n\t\t\texpandDist = dist\n\t\t\tbreak\n\n\tif expandDist == -1: # or s < MEGACITY\n\t\tprint(-1)\n\telse:\n\t\tprint(\"%.7f\" % math.sqrt(expandDist))", "from math import sqrt\r\nn, m = map(int, input().split())\r\nx = []\r\nfor i in range(n):\r\n a, b, c = map(int, input().split())\r\n d = a * a + b * b\r\n x.append([d, c])\r\nx.sort()\r\ni = 0\r\nif m == 1_000_000:\r\n print(0)\r\n exit(0)\r\nwhile 1_000_000 > m:\r\n m += x[i][1]\r\n if m >= 1_000_000:\r\n print(\"{:.10f}\".format(sqrt(x[i][0])))\r\n exit(0)\r\n i += 1\r\n if i >= n:\r\n break\r\nprint(\"-1\")\r\n", "import math\r\n#t=int(input())\r\n#lst = list(map(int, input().strip().split(' ')))\r\nn,s = map(int, input().strip().split(' '))\r\nl=[]\r\nfor i in range(n):\r\n x,y,k = map(int, input().strip().split(' '))\r\n l1=[]\r\n l1=[math.sqrt(x*x + y*y),k]\r\n l.append(l1)\r\nl.sort(key = lambda l: l[0]) \r\n#print(l)\r\nt=-1\r\nf=0\r\nfor i in range(n):\r\n t=l[i][0]\r\n s+=l[i][1]\r\n if s>=1000000:\r\n f=1\r\n print(t)\r\n break\r\nif f==0:\r\n print(-1)\r\n \r\n \r\n \r\n\r\n", "#!/usr/bin/env python3\n\nfrom itertools import *\nfrom math import hypot\n\nMEGANUM = 10**6\n\ndef read_ints():\n\treturn map(int, input().strip().split())\n\nn, s = read_ints()\ncities = [ read_ints() for _ in range(n) ]\nbydist = []\n\nfor city in cities:\n\tx, y, k = city\n\tdist = hypot(x,y)\n\tbydist.append((dist, k))\n\n#print(bydist)\n\nbydist.sort()\n\nmindist = 0\nis_mega = False\n\nfor cit in bydist:\n\tdist, k = cit\n\n\tmindist = dist\n\ts += k\n\n\tif s>=MEGANUM:\n\t\tis_mega = True\n\t\tbreak\n\nif is_mega:\n\tprint(mindist)\nelse:\n\tprint(-1)\n", "import math as m\n\nn, s = map(int, input().split())\nMEGA_CITY = 10**6\ncities =[]\nfor _ in range(n):\n params = tuple(map(int, input().split()))\n cities.append(params)\n\ncities.sort(key=lambda dist: m.sqrt(dist[0]**2+dist[1]**2))\nres = 0.0\ncurrent_population = s\nfor city in cities:\n current_population += city[2]\n if current_population >= MEGA_CITY:\n res = m.sqrt(city[0] ** 2 + city[1] ** 2)\n break\n\nif current_population < MEGA_CITY:\n print(\"-1\")\nelse:\n print(\"{0:.7f}\".format(res))\n", "from math import sqrt\n\nclass City:\n def __init__(self, x, y, pop):\n self.distance = sqrt(x*x + y*y)\n self.population = pop\n\nn, need = map(int, input().split())\nneed = 1000000 - need\ncities =[]\ntotal = 0\nfor i in range(n):\n x, y, pop = map(int,input().split())\n cities.append(City(x,y,pop))\n total += pop\n\nif total < need:\n print(-1)\nelse:\n cities.sort(key=lambda city: city.distance)\n dis = 0\n i = 0\n while need > 0:\n need -= cities[i].population\n dis = cities[i].distance\n i += 1\n\n print(dis)\n\n\n\n\n", "from math import sqrt\r\nInitialinput = input()\r\nList = Initialinput.split( )\r\nCiudades = []\r\nn = int(List[0])\r\ns = int(List[1])\r\nr = 0\r\n\r\nfor i in range(0, n):\r\n Forinput = input()\r\n location = Forinput.split( )\r\n if len(location) != 3:\r\n break\r\n x = int(location[0])\r\n y = int(location[1])\r\n\r\n r = sqrt(x**2 + y**2)\r\n\r\n k = int(location[2])\r\n Ciudades.append([r, k])\r\n\r\nCiudades.sort()\r\n\r\nfor j in Ciudades:\r\n k = j[1]\r\n s = s + k\r\n if s >= 10**6:\r\n R = j[0]\r\n break\r\n\r\nif s < 10**6:\r\n print(-1)\r\nelse:\r\n print(R)", "from math import sqrt\r\nimport sys\r\nn, m = map(int, input().split())\r\nd = dict()\r\nfor _ in range(n):\r\n x,y,z = map(int, input().split())\r\n r = round(sqrt(x*x + y*y),7)\r\n if r in d:\r\n d[r] = z + d[r]\r\n else:\r\n d[r] = z\r\nd = sorted(d.items(), key=lambda x: x[0])\r\nN = len(d)\r\ndt = 0\r\nfor key in d:\r\n m += key[1]\r\n if m >= 10**6:\r\n print(key[0])\r\n sys.exit()\r\nprint(-1)\r\n## Complexity O(Nlog(N))", "\r\n\r\n\r\nfrom math import sqrt\r\n\r\nn , p = map(int,input().split())\r\n\r\nl = []\r\nfor i in range(n):\r\n x , y , k = map(int,input().split())\r\n v = (x**2) + (y**2)\r\n v2 = sqrt(v)\r\n l.append((v2 , k))\r\n\r\nl = sorted(l , key= lambda x : x[0])\r\n#print(l)\r\n\r\nif p >= 10**6:\r\n print(0)\r\n exit(0)\r\n\r\nfor i in range(len(l)):\r\n p += l[i][1]\r\n if p >= 10**6:\r\n print(l[i][0])\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", "def bs(l, h):\r\n while l < h:\r\n m = (l + h) // 2\r\n if a[m][1] >= 10 ** 6 - s:\r\n h = m\r\n else:\r\n l = m + 1\r\n return l\r\n\r\nn, s = map(int, input().split())\r\na = []\r\nfor _ in range(n):\r\n x, y, p = map(int, input().split())\r\n a.append([(x ** 2 + y ** 2) ** .5, p])\r\na.sort()\r\nfor i in range(1, n):\r\n a[i][1] += a[i - 1][1]\r\nif a[-1][1] < 10 ** 6 - s:\r\n print(-1)\r\n exit()\r\nif s == 10 ** 6:\r\n print(0)\r\n exit()\r\nprint(a[bs(0, n - 1)][0])", "import sys\r\nimport math\r\n\r\n\r\ndef read_input(input_path=None):\r\n if input_path is None:\r\n f = sys.stdin\r\n else:\r\n f = open(input_path, 'r')\r\n\r\n n, p = map(int, f.readline().split())\r\n cities = list()\r\n for _ in range(n):\r\n x, y, a = map(int, f.readline().split())\r\n cities.append((x, y, a))\r\n return n, p, cities\r\n\r\n\r\ndef sol(n, p, cities):\r\n weights = []\r\n for city in cities:\r\n dist = math.sqrt(city[0]**2 + city[1]**2)\r\n weights.append((dist, city[2]))\r\n weights = sorted(weights)\r\n for weight in weights:\r\n p += weight[1]\r\n if p >= 1_000_000:\r\n return [f\"{weight[0]:.9}\"]\r\n return [\"-1\"]\r\n\r\n\r\ndef solve_approx(input_path=None):\r\n return sol(*read_input(input_path))\r\n\r\n\r\ndef main():\r\n for line in sol(*read_input()):\r\n print(f\"{line}\")\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "from math import sqrt\r\n\r\ndef dist(x, y):\r\n return sqrt(x * x + y * y)\r\n\r\ndef main():\r\n n, s = map(int, input().split())\r\n m = {}\r\n for i in range(n):\r\n x, y, k = map(int, input().split())\r\n d = dist(x, y)\r\n if d not in m:\r\n m[d] = k\r\n else:\r\n m[d] += k\r\n\r\n ans = -1\r\n for i in sorted(m):\r\n s += m[i]\r\n if s >= 1000000:\r\n ans = i\r\n break\r\n\r\n print(-1 if ans == -1 else ans)\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "import math\r\n\r\ndef solve():\r\n n, population = map(int, input().split())\r\n location = dict()\r\n for i in range(n):\r\n x, y, p = map(int, input().split())\r\n r = x * x + y * y\r\n if r in location:\r\n location[r] += p\r\n else:\r\n location[r] = p\r\n \r\n r = []\r\n for radius in location:\r\n r.append(radius)\r\n r.sort()\r\n for radius in r:\r\n population += location[radius]\r\n if population >= 10**6:\r\n print(math.sqrt(radius))\r\n return\r\n print(-1)\r\nsolve()", "n,pop = list(map(int,input().split()))\r\narr = []\r\nd = {}\r\ncnt = 0\r\nfor i in range(n):\r\n x,y,p = list(map(int,input().split()))\r\n x,y = abs(x),abs(y)\r\n cnt+=p\r\n r = (x**2 + y**2)**(0.5)\r\n arr.append([r,x,y,p])\r\narr.sort()\r\nif pop+cnt<1000000:\r\n print(-1)\r\nelse:\r\n cnt = 0\r\n for i in arr:\r\n r,x,y,p = i[0],i[1],i[2],i[3]\r\n cnt+=p\r\n if cnt+pop>=10**6:\r\n u,v = x,y\r\n break\r\n r = (u**2 + v**2)**(0.5)\r\n print(r)", "\"\"\"\nhttp://codeforces.com/problemset/problem/424/B\n\"\"\"\nimport math\n\n\ndef main():\n N, S = [int(x) for x in input().split()]\n mega = 1000000\n cities = []\n for _ in range(N):\n x, y, k = [int(x) for x in input().split()]\n rad_sq = x* x + y* y\n cities.append((rad_sq, k))\n \n cities.sort(key=lambda x: x[0])\n rad = 0\n for citi in cities:\n S += citi[1]\n if S >= mega:\n rad = citi[0]\n break\n \n if rad > 0:\n print('{:.7f}'.format(math.sqrt(rad)))\n else:\n print(-1)\n\n\nif __name__ == '__main__':\n main()", "import math\r\ndef get_ans():\r\n n,s = map(int, input().split())\r\n l = []\r\n for _ in range(n):\r\n x,y,k = map(int, input().split())\r\n l.append((x**2+y**2,x,y,k))\r\n l.sort()\r\n\r\n m = 10**6\r\n pos = 0\r\n if s >= m:\r\n return pos\r\n for idx, i in enumerate(l):\r\n s+=i[3]\r\n if s>=m:\r\n return math.sqrt(i[0])\r\n\r\n if s < m:\r\n return -1\r\n\r\nans = get_ans()\r\nprint(ans)\r\n", "from collections import defaultdict\r\nimport math\r\nn, people = map(int, input().split())\r\nmaps, maps_sum = defaultdict(list), defaultdict(int)\r\ndef radius(x,y):\r\n return math.sqrt(x*x+y*y)\r\ndef sum_p(r):\r\n s = 0\r\n for p in maps[r]:\r\n s += p\r\n return s\r\nfor _ in range(n):\r\n x, y, k = map(int, input().split())\r\n maps[radius(x,y)].append(k)\r\nfor r in maps:\r\n maps_sum[r] = sum_p(r)\r\nans = []\r\nfor r in maps_sum:\r\n ans.append([r, maps_sum[r]])\r\nans.sort()\r\nfor i in range(len(ans)):\r\n people += ans[i][1]\r\n if people >= 1000000:\r\n print(ans[i][0])\r\n exit()\r\nprint(-1)", "from sys import stdin, stdout\r\nfrom math import pow, sqrt\r\n\r\ndef good(arr1, arr2, target, k):\r\n l,r = -1, len(arr1)\r\n while l+1 < r:\r\n m = (l+r) // 2\r\n if arr1[m] <= target:\r\n l = m\r\n else:\r\n r = m\r\n\r\n if l == -1:\r\n return False\r\n else:\r\n return arr2[l] >= k\r\n\r\ndef main():\r\n n, k = map(int, stdin.readline().strip().split())\r\n k = 1000000 - k\r\n city_details = []\r\n for i in range(n):\r\n city_details.append([int(num) for num in stdin.readline().strip().split()])\r\n if k == 0:\r\n stdin.write('0')\r\n else:\r\n d = {}\r\n for i in city_details:\r\n rad = pow(i[0], 2) + pow(i[1], 2)\r\n d[rad] = d.get(rad, 0) + i[2]\r\n s_r = [sqrt(num) for num in sorted(d.keys(), key = lambda t: t, reverse = False)]\r\n s_p = [tup[1] for tup in sorted(d.items(), key = lambda t: t[0], reverse = False)]\r\n p_s = [s_p[0]]\r\n for i in s_p[1:]:\r\n p_s.append(p_s[-1] + i)\r\n if k > p_s[-1]:\r\n stdout.write('-1')\r\n else:\r\n l, r = 0, 100000\r\n for i in range(60):\r\n m = (l + r) / 2\r\n if good(s_r, p_s, m, k):\r\n r = m\r\n else:\r\n l = m\r\n stdout.write(f'{r}')\r\nif __name__ == '__main__':\r\n main()\r\n\r\n\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, s = map(int, input().split())\r\nd = []\r\nfor i in range(n):\r\n x, y, k = map(int, input().split())\r\n d.append((((x**2+y**2)**0.5), k))\r\n\r\nd.sort()\r\n\r\nfor i in range(n):\r\n s += d[i][1]\r\n if s >= 1e6:\r\n print(d[i][0])\r\n break\r\nelse:\r\n print(-1)\r\n", "# maa chudaaye duniya\r\nn, s = map(int,input().split())\r\narr = []\r\nfor _ in range(n):\r\n a, b, c = map(int, input().split())\r\n arr.append([(a, b), c])\r\narr.sort(key=lambda x : x[0][0]**2 + x[0][1]**2)\r\n# print(*arr)\r\npt = [-1, -1]\r\nfor i in range(n):\r\n if s + arr[i][1] >= 10**6:\r\n pt = arr[i][0]\r\n break\r\n s += arr[i][1]\r\nif pt == [-1, -1]:\r\n print(-1)\r\nelse:\r\n print(pow(pt[0]**2 + pt[1]**2, 0.5))\r\n", "#Megacity\r\nimport math\r\nn, s = map(int, input().split())\r\n\r\nclass Boundary:\r\n def __init__(self,x,y,population):\r\n self.radius = round(math.sqrt(x*x + y*y),7)\r\n self.population = population\r\n def __lt__(self, other):\r\n return self.radius < other.radius\r\n\r\narr = []\r\nfor i in range(n):\r\n x, y, population = map(int,input().split())\r\n arr.append(Boundary(float(x), float(y),population))\r\npopulationNeed = 1000000 - s\r\nsum = 0\r\nresultRadius = 0.0000000\r\narr.sort()\r\nfor i in range(len(arr)):\r\n sum += arr[i].population\r\n if sum >= populationNeed:\r\n resultRadius = arr[i].radius\r\n break\r\nif sum >= populationNeed:\r\n print(resultRadius)\r\nelse:\r\n print(-1)", "import math\r\n\r\nn, s = map(int, input().split())\r\ncity = {}\r\nfor i in range(n):\r\n x, y, p = map(int, input().split())\r\n\r\n city[x ** 2 + y ** 2] = city.get(x ** 2 + y ** 2, 0) + p\r\n\r\nres = 0\r\nfor key, value in sorted(city.items(), key=lambda x: x[0]):\r\n s += value\r\n if s >= 1000000:\r\n res = key\r\n break\r\nif s < 1000000:\r\n print('-1')\r\nelse:\r\n print(math.sqrt(res))\r\n\r\n\r\n\r\n\r\n\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 binsearch(nums, target):\r\n left = 0\r\n right = len(nums) - 1\r\n while left <= right:\r\n mid = (left + right) // 2\r\n if nums[mid][1] == target:\r\n return mid\r\n elif nums[mid][1] > target:\r\n right = mid - 1\r\n elif nums[mid][1] < target:\r\n left = mid + 1\r\n\r\n return left\r\n\r\n\r\nn, s = map(int, input().split())\r\n\r\nc = [0, 0]\r\n\r\ndef euclideandistance(p1, p2):\r\n import math\r\n\r\n x1, y1, x2, y2 = p1[0], p1[1], p2[0], p2[1]\r\n\r\n diffx = (x2 - x1) ** 2\r\n diffy = (y2 - y1) ** 2\r\n\r\n d = math.sqrt(diffx + diffy)\r\n\r\n return d\r\n\r\nlst = []\r\n\r\ncities = []\r\n\r\nfor city in range(n):\r\n x, y, k = map(int, input().split())\r\n\r\n d = euclideandistance(c, [x, y])\r\n\r\n cities.append([d, k])\r\n\r\nlstpop = 0\r\n\r\ncities.sort()\r\n\r\nfor i in cities:\r\n lstpop += i[1]\r\n i[1] = lstpop\r\ninvs = 1000000 - s\r\npl = binsearch(cities, invs)\r\nif pl >= len(cities):\r\n print(-1)\r\n exit()\r\nprint(cities[pl][0])\r\n\r\n\r\n", "from math import sqrt\r\nn, s = map(int, input().split())\r\narr = []\r\nfor i in range(n):\r\n x, y, k = map(int, input().split())\r\n arr.append([sqrt(x ** 2 + y ** 2), k])\r\n\r\narr = sorted(arr, key=lambda x: x[0])\r\nrad = 0\r\ncnt = 0\r\nwhile s < 1000000:\r\n try:\r\n rad = arr[cnt][0]\r\n s += arr[cnt][1]\r\n cnt += 1\r\n except:\r\n print(-1)\r\n exit()\r\nprint(\"{:.7f}\".format(rad))", "N, population = map(int, input().split())\r\nlocations = []\r\nfor _ in range(N):\r\n x, y, people = map(int, input().split())\r\n radius = (x**2 + y**2)**0.5\r\n locations.append((radius, people))\r\nlocations.sort()\r\n# print(locations)\r\nMAX = -1\r\nfor radius, people in locations:\r\n if population + people >= 10**6:\r\n MAX = max(MAX, radius)\r\n break\r\n population += people\r\n\r\nprint(MAX)", "n, s = map(int, input().split())\r\nlocation = dict()\r\ncity = set()\r\nfor _ in range(n):\r\n x, y, k = map(int, input().split())\r\n r = x**2 + y**2\r\n if r in location:\r\n location[r] += k\r\n else: location[r] = k\r\n city.add(r)\r\n \r\ncity = sorted(city)\r\ni = 0\r\nwhile True:\r\n s += location[city[i]]\r\n if s >= 1000000: break\r\n i += 1\r\n if i == len(city): break\r\nprint(\"{:.7f}\".format(city[i]**0.5) if i < len(city) else -1)\r\n ", "# list input\ndef linp(): return list(map(int, input().split()))\n\n\n# map input\ndef minp(): return map(int, input().split())\n\n\n# int input\ndef iinp(): return int(input())\n\n\n# no of testcase\ndef test(): return int(input())\n\n\n# normal input\ndef inp(): return input()\n\ndef dis(a, b):\n return (a*a + b*b)**(0.5)\n\ndef solve():\n # write your solution for one testcase\n n, k = minp()\n temp = []\n for _ in range(n):\n a, b, c = minp()\n temp.append((dis(a, b), c))\n temp.sort()\n res = -1\n for i in temp:\n k+=i[1]\n if k >= 1000000:\n res = i[0]\n break\n return res\n\ndef main():\n # for _ in range(test()):\n print(solve())\n\n\nif __name__ == '__main__':\n main()\n", "R = lambda :map(int,input().split())\nn,P = R()\nm = {}\nfor _ in range(n):\n x,y,p = R()\n m[x**2+y**2]= m.get(x**2+y**2,0)+p\nfor i in sorted(m.keys()):\n P+=m[i]\n if P>=1000000:\n print(i**0.5)\n exit(0)\nprint(-1)", "from math import sqrt\r\nfrom sys import exit\r\n\r\n### Get user input.\r\nn, s = input().split(\" \")\r\nn, s = int(n), int(s)\r\n\r\n# for each location, calculate distance (radius) \r\n#immediately\r\nradius = []\r\npopulation = []\r\n\r\nfor i in range(n):\r\n x, y, k = [int(i) for i in input().split(\" \")]\r\n radius.append(sqrt(x**2 + y**2))\r\n population.append(k)\r\n\r\ntarget = 1000000 - s\r\n\r\n# exit if already a megacity\r\nif target <= 0:\r\n print(0)\r\n exit()\r\n\r\nif target > sum(population):\r\n print(-1)\r\n exit()\r\n\r\nsorted_radius = sorted(list(set(radius)))\r\npop = 0\r\nfor distance in sorted_radius:\r\n # loop through the n locations\r\n for i in range(n):\r\n # check that this location is at this distance\r\n if distance == radius[i]:\r\n pop += population[i]\r\n if pop >= target:\r\n print(distance)\r\n exit()\r\n", "from math import *\r\nR = lambda:map(int, input().split())\r\nn, s = R()\r\nx = sorted((x * x + y * y, k) for x, y, k in (R() for i in range(n)))\r\nfor i in range(n):\r\n s += x[i][1]\r\n if s >= 1000000:\r\n print(sqrt(x[i][0]))\r\n exit()\r\nprint(-1)", "import math,sys,collections,bisect,heapq\n\n\ndef natural(n):\n\treturn n*(n+1)//2\n\ndef possible(freq,mid,n):\n\tc = 0\n\tfor i in freq:\n\t\tc+=freq[i]//mid\n\tif c>=n:\n\t\treturn True\n\treturn False\n\ndef binarysearch(l,r,arr):\n\tif l<=r:\n\t\tmid = (l+r)//2\n\t\tif arr[mid][4]>=1000000:\n\t\t\treturn binarysearch(l,mid-1,arr)\n\t\telse:\n\t\t\treturn binarysearch(mid+1,r,arr)\n\treturn l\ndef binarysearch2(l,r,k,st):\n\tif l<=r:\n\t\tmid = (l+r)//2\n\t\tif mid-st+1==k:\n\t\t\treturn mid\n\t\telif mid-st+1<k:\n\t\t\treturn binarysearch2(mid+1,r,k,st)\n\t\treturn binarysearch2(l,mid-1,k,st)\n\treturn -1\ndef ispossible(n):\n\n\th = 1\n\tnum = 2\n\tpre = 2\n\twhile num<=n:\n\t\tpre = num\n\t\th+=1\n\t\tnum+=(h*2)+h-1\n\treturn n-pre\n\ndef cal(n):\n\ttmp = 0\n\twhile n:\n\t\ttmp+=n%10\n\t\tn//=10\n\treturn tmp\ndef solve():\n\tn,s = list(map(int,input().split()))\n\tarr = []\n\tfor i in range(n):\n\t\tx,y,k = list(map(int,input().split()))\n\t\tdist = math.sqrt(x**2+y**2)\n\t\tarr.append([x,y,k,dist,0])\n\tarr.sort(key = lambda x:x[3])\n\tarr[0][4] = s+arr[0][2]\n\tfor i in range(1,n):\n\t\tarr[i][4] = arr[i-1][4]+arr[i][2]\n\tres = binarysearch(0,n-1,arr)\n\tif res == n:\n\t\tprint(-1)\n\telse:\n\t\tprint(arr[res][3])\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n# number of test cases\n\n\n#t = int(input())\nt = 1\nfor i in range(t):\n\tsolve()\n\n\n\n\n\n\n\n\n\n", "import math\r\nn, d = map(int,input().split())\r\nA = []\r\nC = []\r\nfor i in range(n):\r\n x, y, k = map(int,input().split())\r\n A.append(math.sqrt(x**2 + y**2))\r\n C.append(k)\r\nl, r = 0, max(A)\r\nwhile r-l >= 1e-8:\r\n m = (l+r)/2\r\n res = 0\r\n for i in range(n):\r\n if m >= A[i]:\r\n res += C[i]\r\n if res + d >= 10**6:\r\n r = m\r\n else:\r\n l = m\r\nif sum(C) + d < 1e6:\r\n print(-1)\r\nelse:\r\n print(r)", "import math\r\na, b = map(int, input().split())\r\nc = []\r\nk = 0\r\nfor i in range(a):\r\n x, y, m = map(int, input().split())\r\n k = math.sqrt(x**2+y**2)\r\n c.append((k,m))\r\nc = sorted(c)\r\ni = 0\r\nl = 0\r\nj = c[0][0]\r\nd = []\r\nc.append((0,0))\r\nfor ii in range(len(c)):\r\n if j!=c[ii][0]:\r\n j = c[ii][0]\r\n l = c[i:ii]\r\n l = l[::-1]\r\n i = ii\r\n for elem in l:\r\n d.append(elem)\r\nk = [0]\r\nfor elems in range(len(d)):\r\n k.append(k[-1]+d[elems][1])\r\nx = 10**6-b\r\nif x>k[-1]:\r\n print(-1)\r\nelse:\r\n for u in range(len(k)):\r\n if x<=k[u]:\r\n break\r\n print(d[u-1][0])", "import sys\r\n\r\nn, s = map(int, input().split())\r\nsqr_r = 0\r\narounds = []\r\ntotal = s\r\n\r\nfor _ in range(n):\r\n x, y, k = map(int, input().split())\r\n arounds.append([x ** 2 + y ** 2, k])\r\n total += k\r\n\r\nif total < 10 ** 6:\r\n print(-1)\r\n sys.exit()\r\n\r\narounds.sort()\r\n\r\nfor i in range(n):\r\n if s >= 10 ** 6:\r\n break\r\n s += arounds[i][-1]\r\n sqr_r = arounds[i][0]\r\n\r\nprint(sqr_r ** 0.5)", "import sys\r\nimport math\r\nsys.setrecursionlimit(100000)\r\n\r\n#sys.stdin = open(\"INP.txt\", 'r')\r\n#sys.stdout = open(\"OUT.txt\", 'w')\r\n\r\n\r\nclass Pair:\r\n def __init__(self, x, y):\r\n self.first = x\r\n self.second = y\r\n\r\n\r\ndef EuclidDist(x, y):\r\n return pow(x*x+y*y, 1/2)\r\n\r\n\r\nn, s = map(int, input().split())\r\nM = dict()\r\n\r\nfor i in range(n):\r\n x, y, p = map(int, input().split())\r\n r = EuclidDist(x, y)\r\n if r in M:\r\n M[r] += p\r\n else:\r\n M[r] = p\r\nlst = []\r\nfor key, value in zip(M.keys(), M.values()):\r\n lst.append(Pair(key, value))\r\nlst.sort(key=lambda x: x.first)\r\nfor point in lst:\r\n s += point.second\r\n if s >= int(1e6):\r\n print(\"{:.7f}\".format(point.first))\r\n raise SystemExit\r\nprint(-1)\r\n", "n, s = map(int, input().split())\r\nml = []\r\n\r\n\r\ndef dis(x, y):\r\n return (x**2 + y**2)**0.5\r\n\r\n\r\nfor _ in range(n):\r\n x, y, i = map(int, input().split())\r\n ml.append([dis(x, y), i])\r\n\r\nml.sort()\r\nr = 0\r\ni = 0\r\nwhile i < n and s < 10**6:\r\n s += ml[i][1]\r\n r = ml[i][0]\r\n i += 1\r\n\r\n\r\nif s >= 10**6:\r\n print(r)\r\nelse:\r\n print(-1)\r\n", "import math\r\n\r\nn,s = (int(i) for i in input().strip().split())\r\nl = [None] * n\r\nfor i in range(n):\r\n x,y,p = map(int, input().split())\r\n l[i] = (x*x+y*y, p)\r\nl.sort(key=lambda x:x[0])\r\nr = 1000000 - s\r\nfor i in l:\r\n r -= i[1]\r\n if r <= 0:\r\n print(\"%.7f\" % (math.sqrt(i[0])))\r\n break\r\nif r > 0:\r\n print(-1)\r\n", "n, s = map(int, input().split())\r\nvals = [tuple(map(int, input().split())) for i in range(n)]\r\nvals.sort(key = lambda e: e[0]*e[0] + e[1]*e[1])\r\nb = True\r\nfor v in vals:\r\n s += v[2]\r\n if s >= 1000000:\r\n print((v[0]*v[0] + v[1]*v[1])**0.5)\r\n b = False\r\n break\r\nif b:\r\n print(-1)", "import math\r\nn,s=map(int,input().split())\r\nlis=[]\r\nfor i in range(n):\r\n a,b,c=map(int,input().split())\r\n r=math.sqrt(a*a+b*b)\r\n lis.append([r,c])\r\nlis.sort()\r\n#print(lis)\r\nfor i in range(n):\r\n s+=lis[i][1]\r\n if s>=1000000:\r\n print(lis[i][0])\r\n exit()\r\nprint(\"-1\")\r\n\r\n", "from math import sqrt\r\n\r\n\r\nclass Location:\r\n def __init__(self, x, y, population):\r\n self.x = x\r\n self.y = y\r\n self.population = population\r\n self.dist = sqrt(x ** 2 + y ** 2)\r\n\r\n\r\nn, s = map(int, input().split())\r\nplaces = []\r\nfor _ in range(n):\r\n x, y, k = map(int, input().split())\r\n places.append(Location(x, y, k))\r\n\r\nplaces.sort(key=lambda l: l.dist)\r\nradius = -1\r\nfor location in places:\r\n x, y, k, r = location.x, location.y, location.population, location.dist\r\n if s + k >= int(1e6):\r\n radius = r\r\n break\r\n else:\r\n s += k\r\n\r\nprint('{:.7f}'.format(radius))\r\n", "import sys\r\nimport math\r\n\r\n[L, pop] = [int(n) for n in sys.stdin.readline().split()]\r\n\r\nlocations = []\r\nfor l in range(L):\r\n [x, y, k] = [int(n) for n in sys.stdin.readline().split()]\r\n radius = math.sqrt(x**2 + y**2)\r\n locations.append( (radius,k) )\r\n\r\nlocations = sorted(locations)\r\n\r\ndidit = False\r\nif pop >= 1000000:\r\n print(0)\r\nelse:\r\n for (r, n) in locations:\r\n pop += n\r\n if pop >= 1000000:\r\n print(r)\r\n didit = True\r\n break\r\nif not didit:\r\n print(-1)\r\n", "import math\r\nclass Node:\r\n def __init__(self,key = 0):\r\n self.key = key\r\n self.left = None\r\n self.right = None\r\n\r\ndef insertNode(root, x):\r\n global best\r\n if root == None:\r\n return Node(x)\r\n if x < root.key:\r\n root.left = insertNode(root.left, x)\r\n best = max(root.key - x, best)\r\n elif x > root.key:\r\n root.right = insertNode(root.right, x)\r\n return root\r\n\r\n\r\nn, pop = map(int, input().split())\r\ncity = dict()\r\nfor _ in range(n):\r\n x, y, p = map(int, input().split())\r\n radius = math.sqrt(x**2 + y**2)\r\n city[radius] = city.get(radius, 0) + p\r\nneed = 1000000 - pop\r\nar = sorted(list(city.keys()))\r\nfor i in ar:\r\n need -= city[i]\r\n if need <= 0:\r\n print(i)\r\n quit()\r\nprint(-1)", "import math\r\nn, s = map(int, input().split())\r\nclass city:\r\n d = 0\r\n k = 0\r\ncities = []\r\ndef sortcity(citysort):\r\n return citysort.d\r\nfor i in range(n):\r\n x, y, z = map(int, input().split())\r\n c = city()\r\n c.d = math.sqrt((pow(x, 2) + pow(y, 2)))\r\n c.k = z\r\n cities.append(c)\r\n\r\nif s >= 1000000:\r\n print(0)\r\nelse:\r\n cities.sort(key=sortcity)\r\n i = 0\r\n while s < 1000000 and i < n:\r\n s += cities[i].k\r\n i += 1\r\n if (s < 1000000):\r\n print(-1)\r\n else:\r\n print(cities[i - 1].d)", "def cmp(town):\r\n return town[0]\r\n \r\n \r\nn, s = [int(elem) for elem in input().split()]\r\ntowns = []\r\nfor i in range(n):\r\n x, y, p = [int(elem) for elem in input().split()]\r\n towns.append(((x ** 2 + y ** 2) ** 0.5, p))\r\n \r\ntowns.sort(key=cmp)\r\n \r\nleft = int(1e6 - s)\r\ncnt = 0\r\nans = 0\r\nfor coord, people in towns:\r\n cnt += people\r\n ans = coord\r\n if cnt >= left:\r\n break\r\n \r\nif cnt >= left:\r\n print(ans)\r\nelse:\r\n print(-1)\r\n", "# http://codeforces.com/problemset/problem/424/B\n\nimport math\n\n\ndef solve():\n n, s = map(int, input().split())\n location = []\n\n for i in range(n):\n x, y, k = map(int, input().split())\n location += [(x * x + y * y, k)]\n\n location.sort()\n\n for i in range(n):\n s += location[i][1]\n if s >= 1000000:\n print(math.sqrt(location[i][0]))\n exit()\n\n print(-1)\n\n\nsolve()\n", "import math\nn, s = list(map(int, input().split()))\nneed = 1000000 - s\nif need <= 0:\n print('0')\n exit()\n# x, y, pop\nc = []\nfor _ in range(n):\n c.append(list(map(int, input().split())))\n\ndef getDist(x, y):\n return math.sqrt(x * x + y * y)\n\ndist = []\nfor city in c:\n dist.append([getDist(city[0], city[1]), city[2]])\ndist.sort()\nfor d in dist:\n if need - d[1] <= 0:\n print(d[0])\n exit()\n else:\n need -= d[1]\nprint('-1')\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 add\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\narr = [rr() for _ in range(n)]\r\narr.sort(key=lambda x: x[2])\r\narr.sort(key=lambda x: sqrt(x[0] ** 2 + x[1] ** 2))\r\n\r\nneed = 1000000 - k\r\n\r\n\r\nif sum(k for i, j, k in arr) < need:\r\n print(-1)\r\n exit()\r\n\r\nm = 0\r\nfor i, j, k in arr:\r\n if need <= 0:\r\n break\r\n m = max(m, sqrt(i ** 2 + j ** 2))\r\n need -= k\r\n\r\nprint(f\"{m:.7f}\")", "#!/usr/bin/python\nimport re\nimport inspect\nfrom sys import argv, exit\n\ndef rstr():\n return input()\n\ndef rint():\n return int(input())\n\ndef rints(splitchar=' '):\n return [int(i) for i in input().split(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\nclass City:\n def __init__(self, x, y, pop):\n self.x = x\n self.y = y\n self.pop = pop\n self.dist = (x**2+y**2)**(1/2)\n\n def __str__(self):\n return '|{}, {}, {}, {:.2f}|'.format(self.x, self.y, self.pop, self.dist)\n\n def __repr__(self):\n return str(self)\n\nif __name__ == '__main__':\n n,pop = rints()\n target = 1000000\n cities = sorted([City(*rints()) for i in range(n)], key=lambda c: c.dist)\n prnt(cities)\n r = 0\n for city in cities: \n if pop >= target:\n break\n else:\n r = city.dist\n pop += city.pop\n\n if pop >= target:\n print(r)\n else:\n print(-1)\n", "def dist(x,y):\r\n distance = (x**2 + y**2)**0.5\r\n return distance\r\n\r\nif __name__ == \"__main__\":\r\n n,population = map(int,input().split())\r\n a = []\r\n for i in range(n):\r\n x,y,k = map(int,input().split())\r\n a.append((dist(x,y),k))\r\n a.sort()\r\n for x in a:\r\n population += x[1]\r\n if population >= 10**6:\r\n print(x[0])\r\n exit()\r\n print(-1)", "def cmp (key):\r\n return key[0]\r\n# n = int(input())\r\n# a = [1]\r\n# for i in range(n):\r\n# print(*a)\r\n# a = [1] + [a[j] + a[j + 1] for j in range(i)] + [1]\r\n\r\n#a = 1\r\n#n = int(input())\r\n#for i in range(2, n):\r\n# if n % i == 0:\r\n# a = 0\r\n# break\r\n#if a == 0:\r\n# print(\"I am way to dumb to get an answer correctly\")\r\n# print(\"NO\")\r\n#else:\r\n# print(\"YES\")\r\n# print(\"I am way to dumb to get an answer correctly\")\r\n\r\n#a = [int (x) for x in input().split()]\r\n#for i in range(len(a) - 1 , -1, -1):\r\n# print(a[i], end = \" \")\r\n\r\n\r\n#a = [int (x) for x in input().split()]\r\n#if len(a) % 2 == 0 :\r\n# for i in range (len(a) // 2 -1, -1, -1):\r\n# print(a[i], end = \" \")\r\n# for j in range (len(a)//2, len(a)):\r\n# print(a[j], end = \" \")\r\n#else:\r\n# for i in range (len(a) // 2, -1, -1):\r\n# print(a[i], end = \" \")\r\n# for j in range (len(a)//2, len(a)):\r\n# print(a[j], end = \" \")\r\n\r\n#b = []\r\n#c = []\r\n#a = [int (x) for x in input().split()]\r\n#for i in range(len(a)):\r\n# if i % 2 == 0:\r\n# b.append (a[i])\r\n# else:\r\n# c.append (a[i])\r\n#c.reverse()\r\n#print(*b, end = \" \")\r\n#print(*c, end = \" \")\r\n\r\n\r\n\r\n\r\n#b = 1\r\n#n = int(input())\r\n#a = [int(x) for x in input().split()]\r\n#for i in range(len(a)):\r\n# if a[i] == n:\r\n# b = 0\r\n# break\r\n#if b == 0:\r\n# print( i + 1 , sep=\"\\n\")\r\n#else:\r\n# print(-1)\r\n\r\n\r\n\r\n\r\n#left = 0\r\n#k = int(input())\r\n#a = [int(x) for x in input().split()]\r\n#right = len(a)\r\n#while right - left > 1:\r\n# middle = (right + left) // 2\r\n# if k < a[middle]:\r\n# right = middle\r\n# else:\r\n# left = middle\r\n#if a[left] == k:\r\n# print(left + 1)\r\n#else:\r\n# print(-1)\r\n\r\n#a = input()\r\n#for i in range(0, len(a)):\r\n# if (i + 1) % 3 != 0:\r\n# print(a[i], end = \" \")\r\n#a = input()\r\n\r\n#for i in range(0, len(a)):\r\n# if (i + 1) % 3 == 0 or (i + 1) % 2 == 0:\r\n# print(a[i], end = \" \")\r\n\r\n\r\n#print([int(elem) for i, elem in enumerate(input().split()) if i % 3 != 0])\r\n\r\n#class Cat:\r\n# def __init__(self, face, paws, whiskers, belly, what_they_like, pawsonality):\r\n# self.face = face\r\n# self.paws = paws\r\n# self.whiskers = whiskers\r\n# self.belly = belly\r\n# self.what_they_like = what_they_like\r\n# self.pawsonality = pawsonality\r\n# def __str__(self):\r\n# return \"face: {}\\npaws: {}\".format( self.face, self.paws, self.whiskers, self.belly, self.what_they_like, self.pawsonality)\r\n#Tyson = Cat(1, 4, 18, 3.5, [\"water\", \"food\", \"ropes\", \"blankets\"], \"playful, stubborn, sleepy\")\r\n#print(Tyson)\r\n\r\n#a = list(input())\r\n#b = list(reversed(a))\r\n#if a == b:\r\n# print(\"YES\")\r\n#else:\r\n# print(\"NO\")\r\n\r\n#meow\r\n\r\n#countmeow = 0\r\n#a = list(input())\r\n#b = list(reversed(a))\r\n#for i in range(len(a)):\r\n# if a[i] != b[i]:\r\n# countmeow = countmeow + 1\r\n#if countmeow == 0 and len(a) % 2 != 0:\r\n# print(\"YES\")\r\n#elif countmeow == 2:\r\n# print(\"YES\")\r\n#else:\r\n# print(\"NO\")\r\n\r\n#input()\r\n#letmeowchange = 0\r\n#num = input()\r\n#a = dict()\r\n#if len(num) > 26:\r\n# print(-1)\r\n#else:\r\n# for letter in num:\r\n# if letter in a:\r\n# a[letter] += 1\r\n# else:\r\n# a[letter] = 1\r\n# for letter in a:\r\n# letmeowchange += a[letter]-1\r\n# print(letmeowchange)\r\n\r\n#print(round(sum([float(i) for i in input().split()]), 1))\r\n\r\n\r\n#a = [int(i) for i in input().split()]\r\n#b = [int(j) for j in input().split()]\r\n#for i in zip(b, a):\r\n# print(*i, end = \" \")\r\n\r\n#print([int(-i) if i%2==0 else int(i) for i in range(1,int(input()) + 1)])\r\n\r\n#cb = input()\r\n#bc = [int(i) for i in input().split()]\r\n#a = {elem1: elem2 for elem1, elem2 in zip(cb, bc)}\r\n#print(a)\r\n\r\n\r\n#b = 0\r\n#for i in range(10, 100):\r\n# if i % 5 != 0 and i % 7 != 0:\r\n# b = b + 1\r\n#print(b)\r\n\r\n#a = int(input())\r\n#b = \" that I hate\"\r\n#c = \" that I love\"\r\n#print(\"I hate\", end = \"\")\r\n#for i in range(a - 1):\r\n# if i % 2 == 0:\r\n# print(c, end = \"\")\r\n# else:\r\n# print(b, end = \"\")\r\n#print(\" it\")\r\n\r\n#a = int(input())\r\n#b = [int(input()) for i in range(a)]\r\n#c = b[0]\r\n#d = 0\r\n#for i in b[1::]:\r\n# if i != c:\r\n# d = d + 1\r\n# c = i\r\n#print(d + 1)\r\n\r\n#input()\r\n#letmeowchange = 0\r\n#num = input()\r\n#a = dict()\r\n#if len(num) > 26:\r\n# print(-1)\r\n#else:\r\n# for letter in num:\r\n# if letter in a:\r\n# a[letter] += 1\r\n# else:\r\n# a[letter] = 1\r\n# for letter in a:\r\n# letmeowchange += a[letter]-1\r\n# print(letmeowchange)\r\n\r\n#from math import ceil\r\n#a = int(input())\r\n#b = [int(i) for i in input().split()]\r\n#c = sum(b)\r\n#\r\n#d = {1:0, 2:0, 3:0, 4:0}\r\n#total = 0\r\n#r2 = 0\r\n#for i in b:\r\n# if i in d:\r\n# d[i] += 1\r\n# else:\r\n# d[i] = 1\r\n#total = total + d[4]\r\n#total = total + d[3]\r\n#total = total + (d[2] // 2)\r\n#r2 = d[2] % 2\r\n#if r2 != 0:\r\n# d[1] = d[1] - 2\r\n# total = total + 1\r\n#if d[1] > d[3]:\r\n# total += ceil((d[1] - d[3]) / 4)\r\n#print(total)\r\n\r\n#n = int(input())\r\n#a = [int(i) for i in input().split()]\r\n#print(*sorted(a))\r\n\r\n#s = list(input())\r\n#t = list(input())\r\n#a = list(reversed(s))\r\n#if t == a:\r\n# print(\"YES\")\r\n#else:\r\n# print(\"NO\")\r\n\r\n#a = input().split()\r\n#b = 0\r\n#c = 0\r\n#d = dict()\r\n#for letter in a:\r\n# if letter in d:\r\n# d[letter] += 1\r\n# else:\r\n# d[letter] = 1\r\n#for value in d.values():\r\n# if value % 2 != 0:\r\n# c = c + 1\r\n#if c > 1:\r\n# print(\"NO\")\r\n#else:\r\n# print(\"YES\")\r\n\r\n\r\n#n = input()\r\n#a = [int(i) for i in n]\r\n#b = 0\r\n#for i in a:\r\n# if i == 4 or i == 7:\r\n# b = b + 1\r\n#if b == 4 or b == 7:\r\n# print(\"YES\")\r\n#else:\r\n# print(\"NO\")\r\n\r\n\r\n#n = input()\r\n#a = [int(i) for i in n]\r\n\r\n#b = 0\r\n#c = 0\r\n#a = \"abcdefgthijklmnopqrstuvwxyz\"\r\n#s = input()\r\n#for i in s:\r\n# if i in a:\r\n# b = b + 1\r\n# else:\r\n#c = c + 1\r\n#if b == c or b > c:\r\n# print(s.lower())\r\n#else:\r\n# print(s.upper())\r\n\r\n\r\n\r\n#b = 0\r\n#k = int(input())\r\n#l = int(input())\r\n#m = int(input())\r\n#n = int(input())\r\n#d = int(input())\r\n#for i in range(1, d + 1):\r\n# if i % k == 0:\r\n# b = b + 1\r\n# elif i % l == 0:\r\n# b = b + 1\r\n# elif i % m == 0:\r\n# b = b + 1\r\n# elif i % n == 0:\r\n# b = b + 1\r\n#print(b)\r\n\r\n\r\n#a = input().split(\"WUB\")\r\n#for i in a:\r\n# if i != '':\r\n# print(i , end = \" \")\r\n\r\n\r\n#n, m = [int(i) for i in input().split()]\r\n#f = [int(i) for i in input().split()]\r\n#a = sorted(f)\r\n#A = 0\r\n#B = 0\r\n#answer = 999999999999999999\r\n#c = 3\r\n#for i in range (0, len(a) - n + 1):\r\n# A = a[i]\r\n# B = a[i + n - 1]\r\n# if B - A < answer:\r\n# answer = B - A\r\n#print(answer)\r\n\r\n#s = [int(i) for i in input().split()]\r\n#s = set(s)\r\n#print(4 - len(s))\r\n\r\n#n = int(input())\r\n#a = [int(i) for i in input().split()]\r\n#b = -9999999999999999999999999999\r\n#c = 9999999999999999999999999999\r\n#d = 0\r\n#f = 0\r\n#naswer = 0\r\n#index = 0\r\n#for i in range(len(a)):\r\n# if a[i] > b:\r\n# d = i\r\n# b = a[i]\r\n# if a[i] <= c:\r\n# f = i\r\n# c = a[i]\r\n#index = len(a) - 1\r\n#naswer = naswer + (index - f)\r\n#naswer = naswer + d\r\n#if f < d:\r\n# naswer = naswer - 1\r\n#print(naswer)\r\n\r\n#t = int(input())\r\n#naswer = 0\r\n#for i in range (t):\r\n# n = int(input())\r\n# naswer = n // 2\r\n# print(naswer)\r\n\r\n#n, k = [int(i) for i in input().split()]\r\n#naswer = 0\r\n#if k <= (n + (n % 2)) // 2:\r\n# naswer = k * 2 - 1\r\n#else:\r\n# naswer = (k - (n + (n % 2)) // 2) * 2\r\n#print(naswer)\r\n\r\n#n = int(input())\r\n#a = [int(i) for i in input().split()] + [9999999999]\r\n#for i in range(n):\r\n\r\n#d = 0\r\n#n = int(input())\r\n#p = [int(i) for i in input().split()]\r\n#q = [int(i) for i in input().split()]\r\n#a = []\r\n#for i in range(1, len(p)):\r\n# a.append(p[i])\r\n#for j in range(1, len(q)):\r\n# a.append(q[j])\r\n#b = set(a)\r\n#for i in range(1, n + 1):\r\n# if i in b:\r\n# d = d + 1\r\n#if d == n:\r\n# print(\"I become the guy.\")\r\n#else:\r\n# print(\"Oh, my keyboard!\")\r\n\r\n\r\n#n = int(input())\r\n#a = [i for i in input().lower()]\r\n#b = set(a)\r\n#if len(b)>=26:\r\n# print(\"YES\")\r\n#else:\r\n# print(\"NO\")\r\n\r\n\r\n#n = int(input())\r\n#a = {\"Icosahedron\" : 20, \"Dodecahedron\" : 12, \"Octahedron\" : 8, \"Cube\" : 6, \"Tetrahedron\" : 4}\r\n#b = 0\r\n#for i in range(n):\r\n# c = input()\r\n# b = b + a[c]\r\n#print(b)\r\n\r\n\r\n#a = input()\r\n#b = input()\r\n#c = input()\r\n#d = dict()\r\n#e = dict()\r\n#for i in a:\r\n# if i in d:\r\n# d[i] = d[i] + 1\r\n# else:\r\n# d[i] = 1\r\n#for i in b:\r\n# if i in d:\r\n# d[i] = d[i] + 1\r\n# else:\r\n# d[i] = 1\r\n#for i in c:\r\n# if i in e:\r\n# e[i] = e[i] + 1\r\n# else:\r\n# e[i] = 1\r\n#if d == e:\r\n# print(\"YES\")\r\n#else:\r\n# print(\"NO\")#\r\n\r\n\r\n#n, m = [int(i) for i in input().split()]\r\n#b = min(n, m)\r\n#if b % 2 !=0:\r\n# print(\"Akshat\")\r\n#else:\r\n# print(\"Malvika\")\r\n#\r\n#n, m = [int(i) for i in input().split()]\r\n#ho = \"#\"\r\n#hi = \".\"\r\n#for i in range(1, n + 1):\r\n# if i % 4 != 0 and i % 2 == 0:\r\n# print(hi*(m-1) + ho)\r\n# elif i % 4 == 0:\r\n# print(ho + hi* (m - 1))\r\n# else:\r\n# print(ho * m)\r\n\r\n#n, m = [int(i) for i in input().split()]\r\n#a = [int(i) for i in input().split()]\r\n#hosss = 1\r\n#besss = 0\r\n#for i in a:\r\n# if (i >= hosss):\r\n# besss = besss + (i - hosss)\r\n# else:(\r\n# besss = besss + (n - hosss + i)\r\n# hosss = i\r\n#print(besss)\r\n\r\n\r\n#n = int(input())\r\n#x = [int(i) for i in input().split()]\r\n#q = int(input())\r\n#x.sort()\r\n#for i in range(q):\r\n# k = int(input())\r\n# l = -1\r\n# r = n\r\n# while (r - l > 1):\r\n# middle = l + (r - l) // 2\r\n# if x[middle] <= k:\r\n# l = middle\r\n# else:\r\n# r = middle\r\n# print( l + 1 )\r\n\r\n#a, b = [int(i) for i in input().split()]\r\n#c = min(a, b)\r\n#d = max(a, b)\r\n#e = d - c\r\n#print(c, e//2)\r\n\r\n\r\n#k, r = [int(i) for i in input().split()]\r\n#for i in range(1, 11):\r\n# if ((k * i) - r) % 10 == 0:\r\n# print(i)\r\n# break\r\n# if (k * i) % 10 == 0:\r\n# print(i)\r\n# break\r\n\r\n\r\n#n = int(input())\r\n#a = [int(i) for i in input().split()]\r\n#m = int(input())\r\n#q = [int(i) for i in input().split()]\r\n#b = [a[0]]\r\n#for i in range(1, len(a)):\r\n# b.append(a[i] + b [i - 1])\r\n#for i in range(len(q)):\r\n# l = -1\r\n# r = len(a)\r\n# while (r - l > 1):\r\n# mid = (l + r) // 2\r\n# if b[mid] < q[i]:\r\n# l = mid\r\n# else:\r\n# r = mid\r\n# print(r + 1)\r\n\r\n\r\n#n, t = [int(i) for i in input().split()]\r\n#a = [0] + [int(i) for i in input().split()]\r\n#b = []\r\n#naswer = 0\r\n#noswer = 0\r\n#nul = 0\r\n#for i in a:\r\n# nul = nul + i\r\n# b.append(nul)\r\n#for i in range(1, n + 1):\r\n# l = i - 1\r\n# r = n + 1\r\n# while(r - l > 1):\r\n# mid = (l + r) // 2\r\n# noswer = b[mid] - b[i - 1]\r\n# if (noswer) <= t:\r\n# l = mid\r\n# else:\r\n# r = mid\r\n# naswer = max(naswer, l - i + 1)\r\n#print(naswer)\r\n\r\n#n, m, a, b = [int (i) for i in input().split()]\r\n#if m * a <= b:\r\n# print(n * a)\r\n#else:\r\n# c = n % m\r\n# if c == 0:\r\n# print((n//m) * b)\r\n# if c != 0:\r\n# d = a * c\r\n# if d > b:\r\n# print(b + ((n//m) * b))\r\n# else:\r\n# print(d + ((n//m) * b))\r\n\r\n#a, b = [int (i) for i in input().split()]\r\n#naswer = 0\r\n#c = 0\r\n#while a > 0:\r\n# naswer = naswer + a\r\n# c = c + a\r\n# a = c // b\r\n# c = c % b\r\n#print(naswer)\r\n\r\n\r\n#n, q = [int(hoiii) for hoiii in input().split()]\r\n#a = [int(hoi) for hoi in input().split()]\r\n#sm = [0]\r\n#m = 0\r\n#for i in range(n):\r\n# sm.append(sm[-1] + a[i])\r\n#for i in range(q):\r\n# a, b = [int(hoii) for hoii in input().split()]\r\n# naswer = sm[b] - sm[a-1]\r\n# print(naswer)\r\n\r\n\r\nn, s = [int(hoiii) for hoiii in input().split()]\r\nhmmmm = []\r\nfor i in range(n):\r\n x, y, k = [int(hoi) for hoi in input().split()]\r\n hmmmm.append(((x**2 + y**2)**0.5, k))\r\nhmmmm.sort(key=cmp)\r\nmegamillion = 1000000 - s\r\nnaswer = 0\r\nfor i in hmmmm:\r\n if megamillion <= 0:\r\n break\r\n else:\r\n megamillion = megamillion - i[1]\r\n naswer = i[0]\r\nif megamillion <= 0:\r\n print(naswer)\r\nelse:\r\n print(-1)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Jul 22 16:52:29 2019\r\n\r\n@author: cvela\r\n\"\"\"\r\n\r\n\r\nimport sys\r\nimport os\r\n\r\nt=sys.stdin.readline()\r\nvals=t.split()\r\nneighbors=int(vals[0])\r\npopulation=int(vals[1])\r\n\r\nmega_pop=1e6\r\ntomsk_pop=population\r\nif tomsk_pop>=mega_pop:\r\n print(0)\r\n \r\ntable=[]\r\nfor i in range(neighbors):\r\n t=sys.stdin.readline()\r\n vals=t.split()\r\n x_i=float(vals[0])\r\n y_i=float(vals[1])\r\n pop_i=float(vals[2])\r\n r_i=(x_i**2+y_i**2)**(1/2)\r\n table.append((r_i,pop_i))\r\n\r\ntable.sort()\r\n\r\nfor rad, pop in table:\r\n tomsk_pop+=pop\r\n if tomsk_pop>=mega_pop:\r\n print(rad)\r\n break\r\n\r\nif tomsk_pop<mega_pop:\r\n print(-1)\r\n", "\"\"\"\r\n\r\ninput n, p\r\n-> find the need : \r\n\r\nx, y -> r , and p\r\n\r\norder from 1 -> n base on the radius \r\n->the p count along with the need\r\n\r\nstop at the point \r\n\r\nand if run out of range -> print(-1)\r\n\r\n\r\n\"\"\"\r\nimport math \r\nclass Circle:\r\n \r\n def __init__(self, x, y, s):\r\n self.x = x \r\n self.y = y \r\n self.r = math.sqrt(x**2 + y**2)\r\n self.s = s\r\n \r\n def __lt__(self, other):\r\n return self.r < other.r\r\n\r\ndef findRadius(a , l , r, x) :\r\n ans = l\r\n temp = 0\r\n for i in range(0, r + 1, 1):\r\n temp += a[i].s\r\n if(temp < x):\r\n return -1\r\n while (l <= r):\r\n mid = (l+r)//2\r\n \r\n temp = 0\r\n for i in range(0, mid + 1, 1):\r\n temp += a[i].s\r\n \r\n if (temp == need):\r\n return a[mid].r\r\n elif temp > need:\r\n r = mid - 1\r\n ans = mid\r\n else:\r\n l = mid + 1\r\n return a[ans].r\r\n \r\nif __name__ == '__main__':\r\n \r\n n, s = map(int, input().split())\r\n \r\n need = int(1e6 - s)\r\n \r\n list_n = []\r\n \r\n for _ in range(n):\r\n x, y, k = list(map(int, input().split()))\r\n c = Circle(x,y,k)\r\n list_n.append(c)\r\n \r\n list_n.sort()\r\n \r\n #for item in list_n:\r\n # print(item.r, '--', item.s)\r\n #print(need) \r\n r = findRadius(list_n, 0 , n - 1, need) \r\n print(\"{:.7f}\".format(r) ) if r != -1 else print(-1)", "n,s=map(int,input().split())\r\nL=[]\r\nfor i in range(n):\r\n x,y,k=map(int,input().split())\r\n L.append((x**2+y**2,k))\r\nL.sort()\r\ninc=0\r\nind=0\r\nr=0\r\nwhile(ind<n and s+inc<1000000):\r\n r=L[ind][0]\r\n inc+=L[ind][1]\r\n ind+=1\r\n\r\nif(s+inc>=1000000):\r\n print(pow(r,1/2))\r\nelse:\r\n print(-1)\r\n", "from math import sqrt\r\n\r\nn, s = map(int, input().split())\r\ncity = [[0.0, s]]\r\n\r\nfor i in range(n) :\r\n x, y, k = map(int, input().split())\r\n city.append([sqrt(x*x + y*y), k])\r\n\r\ncity.sort(key = lambda x: x[0])\r\n\r\nfor i in range(1, n + 1) :\r\n city[i][1] += city[i - 1][1]\r\n\r\nlf = 0; rg = n\r\n\r\nif city[rg][1] < 1000000 : print(-1)\r\nelse :\r\n while rg - lf >= 3:\r\n mid = (lf + rg) // 2\r\n if city[mid][1] >= 1000000: rg = mid\r\n else: lf = mid\r\n\r\n for i in range(lf, rg + 1):\r\n if city[i][1] >= 1000000:\r\n print(city[i][0]); break", "from math import sqrt\r\nciudades, poblacion = input().split()\r\nciudades = int(ciudades)\r\npoblacion = int(poblacion)\r\nlista = []\r\nfor i in range(ciudades):\r\n x,y,n = input().split()\r\n dist = sqrt(int(x)*int(x) + int(y)*int(y))\r\n lista.append((dist,int(n)))\r\nlista.sort()\r\nfor d,p in lista:\r\n poblacion += int(p)\r\n if poblacion>=1000000:\r\n print(d)\r\n break\r\nif poblacion<1000000:\r\n print(-1)\r\n", "from collections import Counter\r\n\r\n\r\ndef main():\r\n n, s = map(int, input().split())\r\n cities = []\r\n for _ in range(n):\r\n x, y, k = map(int, input().split())\r\n dist = x * x + y * y\r\n cities.append((dist, k))\r\n\r\n cities.sort()\r\n\r\n cnt = Counter()\r\n cnt[0] = s\r\n\r\n for dist, k in cities:\r\n cnt[dist] += k\r\n\r\n _sum = 0\r\n for k, v in cnt.items(): # counter preserves insert order (by distance)\r\n _sum += v\r\n if _sum >= 1000000:\r\n print(k**0.5)\r\n return\r\n\r\n print(-1)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n,s=map(int,input().split())\r\npopu=[]; su=0\r\nfor i in range(n):\r\n a,b,c=map(int,input().split())\r\n su+=c\r\n popu.append(((a**2+b**2)**0.5,-c))\r\nif (s+su)<10**6: print(-1)\r\nelse:\r\n popu.sort(); i=0\r\n while s<10**6:\r\n s+=-popu[i][1]\r\n i+=1\r\n print(popu[i-1][0])", "n,s=map(int,input().split())\r\nlst=[] \r\nfor i in range(n):\r\n x,y,z= map(int,input().split()) \r\n lst.append([ ((y*y)+(x*x))**.5 , z ])\r\n \r\nlst.sort() \r\na=s-10**6 \r\nfor i in lst:\r\n a+=i[1]\r\n if a>=0:\r\n exit(print(i[0]))\r\n \r\nprint(-1)", "import math as Math\r\nfrom sys import stdin\r\nif __name__ == '__main__':\r\n n, s = map(int, stdin.readline().strip().split())\r\n points = dict()\r\n for i in range(0, n):\r\n x, y, pop = map(int, stdin.readline().strip().split())\r\n rad = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))\r\n if points.get(rad) == None:\r\n points[rad] = pop\r\n else:\r\n points[rad] = points.get(rad) + pop\r\n \r\n #points.sort()\r\n reached = False\r\n for i in sorted(points.keys()):\r\n s = s + points[i]\r\n if s >= 1000000:\r\n print(format(i, '.7f'))\r\n reached = True\r\n break\r\n if reached == False:\r\n print('-1')\r\n ", "import math\r\nfrom collections import defaultdict\r\nx,y=map(int,input().split())\r\nr=defaultdict()\r\nfor i in range(x):\r\n a,b,c = map(int, input().split())\r\n a=math.sqrt(pow(a,2)+pow(b,2))\r\n # print(a)\r\n if a not in r:\r\n r[a] = []\r\n r[a].append(c)\r\nif(y>=1000000):\r\n print(\"0\")\r\nelse:\r\n for key in sorted(r):\r\n for j in range(len(r[key])):\r\n y+=r[key][j]\r\n if(y>=1000000):\r\n print(key)\r\n break\r\n #print(\"%s %s\"%(key,r[key]))\r\n #print(y)\r\n else:\r\n print(\"-1\")", "def getRequiredDis(cities, need):\r\n sum = 0\r\n for i in range(len(cities)):\r\n sum += cities[i][2]\r\n if sum >= need:\r\n return cities[i][-1]\r\n break\r\n return -1\r\n\r\ns = (0, 0)\r\nimport math\r\n\r\nn,s = list(map(int, input(\"\").split()))\r\n\r\ncities = []\r\nfor _ in range(n):\r\n city = list(map(int, input(\"\").split()))\r\n x, y, p = city\r\n dis = math.sqrt(x**2 + y**2)\r\n cities.append((x, y, p, dis))\r\n\r\ncities = sorted(cities, key=lambda x: x[-1])\r\n\r\nneed = 10**6 - s\r\n\r\nprint(getRequiredDis(cities, need))", "import math\n\nn, s = [int(c) for c in input().split()]\n\nar = []\n\nfor i in range(n):\n x, y, count = [int(c) for c in input().split()]\n ar.append([math.sqrt(x**2 + y**2), count])\n\nar.sort(key=lambda _: _[0])\n\ni = 0\n\nwhile i < n and s < 10 ** 6:\n s += ar[i][1]\n i += 1\n\nif s < 10 ** 6:\n print(-1)\nelse:\n print(round(ar[i - 1][0],7))\n\n", "\"\"\"\nhttps://codeforces.com/problemset/problem/424/B\n\"\"\"\n\nimport math\n\nif __name__ == '__main__':\n num_locations, population_tomsk = map(int, input().split())\n locations = []\n for index in range(num_locations):\n x_i, y_i, k_i = map(int, input().split())\n distance = x_i ** 2 + y_i ** 2\n locations.append((distance, k_i))\n locations.sort(key=lambda x : x[0])\n total_population = population_tomsk\n radius = -1\n for location in locations:\n total_population += location[1]\n if total_population >= 1e6:\n radius = location[0]\n break\n if radius == -1:\n print(radius)\n else:\n print(math.sqrt(radius))", "'''input\n15 95473\n-9 6 199715\n0 -8 110607\n0 2 6621\n-3 -2 59894\n-10 -8 175440\n-2 0 25814\n10 -4 68131\n7 1 9971\n6 7 821\n6 5 20208\n6 2 68468\n0 7 37427\n1 -3 13337\n-10 7 113041\n-6 -2 44028\n'''\nn, s = map(int, input().split())\nl = []\nfor _ in range(n):\n\ta, b, k = map(int, input().split())\n\tl.append(((a**2+b**2)**0.5, k))\nfor x in sorted(l):\n\ts += x[1]\n\tif s >= 1000000:\n\t\tprint(x[0])\n\t\tbreak\nelse:\n\tprint(-1)\n\n\n", "a,b=map(int,input().split())\r\ns=[]\r\nfor i in range(a):\r\n m,n,k=map(int,input().split())\r\n z=(m**2+n**2,k)\r\n s.append(z)\r\ns.sort()\r\nfor i in range(a):\r\n b+=s[i][1]\r\n if b>=1000000:\r\n print(s[i][0]**0.5)\r\n break\r\nif b<1000000:\r\n print(-1)", "import math\r\nn, s = map(int,input().split())\r\npopulation = s\r\narr = []\r\nfor i in range(n):\r\n x, y, k = map(int,input().split())\r\n ans = math.pow(x,2) + math.pow(y,2)\r\n s += k\r\n arr += [(ans, k)]\r\nif s < 10**6:\r\n print(-1)\r\narr.sort()\r\nfor i in range(n):\r\n population += arr[i][1]\r\n if population >= 10**6:\r\n print(math.sqrt(arr[i][0]))\r\n break\r\n", "from math import sqrt\r\nn,s=map(int,input().split())\r\ndis=[]\r\nfor _ in range(n):\r\n x,y,p=map(int,input().split())\r\n dt=sqrt((x-0.0)**2+(y-0.0)**2)\r\n dis.append((dt,p))\r\ndis.sort()\r\nr=-1\r\ni=0\r\nle=len(dis)\r\nwhile s<10**6+1 and i<le:\r\n s+=dis[i][1]\r\n r=dis[i][0]\r\n i+=1\r\n if s>=10**6:\r\n i+=n\r\nif s<10**6:\r\n r=-1\r\nprint(r)\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n", "n,s =map(int,input().split())\r\narr = []\r\nimport math\r\nfor i in range(n):\r\n x,y,i = map(int,input().split())\r\n dist = math.sqrt(x**2 + y**2)\r\n arr.append((dist,i))\r\narr.sort()\r\nans = False\r\nfor e in arr:\r\n dist,i = e[0],e[1]\r\n s+=i\r\n if s>=int(1e6):\r\n print(\"{:.7f}\".format(dist))\r\n # print(dist)\r\n ans = True\r\n break\r\nif ans is False:print(\"-1\")", "import queue\r\nimport math\r\n\r\nif __name__ == '__main__':\r\n n, s = map(int, input().split())\r\n pq = queue.PriorityQueue()\r\n for i in range(n):\r\n x, y, k = map(int, input().split())\r\n r = math.sqrt(x**2 + y**2)\r\n pq.put((r, k))\r\n\r\n r = 0\r\n while pq.empty() == False and s < 1000000:\r\n r, k = pq.get()\r\n s += k\r\n\r\n if s < 1000000:\r\n print(-1)\r\n else:\r\n print(\"{0:.7f}\".format(r))", "def distanciaAlCero(x, y):\r\n return (x**2 + y**2)**0.5\r\n\r\nPOBLACION_MINIMA = 1_000_000\r\n\r\n# Lista de tuplas\r\n# Tupla: (distancia, k)\r\nubicaciones = []\r\n\r\n# Asumiendo que todos los inputs son correctos\r\nn, s = map(int, input().split())\r\nfor i in range(n):\r\n x, y, k = map(int, input().split())\r\n ubicaciones.append((distanciaAlCero(x, y), k))\r\n\r\nubicaciones.sort()\r\nfor distancia, k in ubicaciones:\r\n s += k\r\n if s >= POBLACION_MINIMA:\r\n print(\"%.7f\" % distancia)\r\n exit(0)\r\n\r\nprint(-1)\r\n", "import math\r\n\r\n\r\nn, s = tuple(map(int, str.split(input())))\r\ncities = list(map(lambda _: tuple(map(int, str.split(input()))), range(n)))\r\ncities.sort(key=lambda city: city[0] ** 2 + city[1] ** 2)\r\ni = 0\r\nextra = 0\r\nwhile s + extra < 10 ** 6 and i < n:\r\n\r\n extra, i = extra + cities[i][2], i + 1\r\n\r\nif s + extra < 10 ** 6:\r\n\r\n print(-1)\r\n\r\nelse:\r\n\r\n x, y, _ = cities[i - 1]\r\n print(math.sqrt(x ** 2 + y ** 2))\r\n\r\n", "# python3\r\nimport sys, threading, os.path\r\nimport string\r\nimport collections, heapq, math, bisect\r\n\r\nsys.setrecursionlimit(10 ** 6)\r\nthreading.stack_size(2 ** 27)\r\n\r\n\r\ndef main():\r\n if os.path.exists('in.txt'):\r\n input = open('in.txt', 'r')\r\n else:\r\n input = sys.stdin\r\n # --------------------------------INPUT---------------------------------\r\n n, s = list(map(int, input.readline().split()))\r\n data = []\r\n\r\n for i in range(n):\r\n temp_list = list(map(int, input.readline().split()))\r\n data.append((math.sqrt(math.pow(temp_list[0], 2)+math.pow(temp_list[1], 2)), temp_list[2]))\r\n\r\n data.sort()\r\n res = -1\r\n for x, y in data:\r\n s += y\r\n if s >= 1000000:\r\n res = x\r\n break\r\n\r\n if res == -1:\r\n output = res\r\n else:\r\n output = format(res, '.7f')\r\n # -------------------------------OUTPUT----------------------------------\r\n if os.path.exists('out.txt'):\r\n open('out.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", "from math import *\r\nR = lambda:map(int, input().split())\r\nn, s = R()\r\nx = sorted((hypot(x, y), k) for x, y, k in (R() for i in range(n)))\r\nfor t in x:\r\n s += t[1]\r\n if s >= 1000000:\r\n print(t[0])\r\n exit()\r\nprint(-1)\r\n", "from math import sqrt as r\r\nfrom collections import defaultdict as dq\r\n\r\nn,s=map(int,input().split())\r\n\r\nleft=1000000-s\r\n\r\nd=dq(int)\r\nfor i in range(n):\r\n\tx,y,k=map(int,input().split())\r\n\td[x,y]=k\r\n\r\nminm=float('inf')\r\nf=0\r\nfor k1,v1 in d.items():\r\n\txc=abs(k1[0])\r\n\tyc=abs(k1[1])\r\n\ttotal=0\r\n\trad=round(r(xc**2+(yc**2)), 7)\r\n\tfor k2,v2 in d.items():\r\n\t\tif round(r(k2[0]**2+(k2[1]**2)), 7)<=rad:\r\n\t\t\ttotal+=v2\r\n\tif total>=left:\r\n\t\tif rad<minm:\r\n\t\t\tminm=rad\r\n\t\tf=1\r\n\r\nprint(minm if f==1 else -1)", "from math import sqrt\r\n\r\nN, t = input().split()\r\nN, t = int(N), int(t)\r\nrast = []\r\ncount = []\r\nfor i in range(N):\r\n x, y, k = input().split()\r\n x, y, k = int(x), int(y), int(k)\r\n rast.append(sqrt(x**2 + y**2))\r\n count.append(k)\r\n \r\nl, r = 0, max(rast)\r\nwhile r - l >= 1e-8:\r\n m = (l + r) / 2\r\n k = 0\r\n for i in range(N):\r\n if m >= rast[i]:\r\n k += count[i]\r\n if k + t >= 1e6:\r\n r = m\r\n else:\r\n l = m\r\n\r\nif sum(count) + t < 1e6:\r\n print(-1)\r\nelse:\r\n print(l)", "def inp():\r\n return map(int, input().split())\r\n\r\n\r\ndef arr_inp():\r\n return [int(x) for x in input().split()]\r\n\r\n\r\nfrom collections import *\r\nfrom math import *\r\n\r\nn, s = inp()\r\ndic = defaultdict(int)\r\nfor i in range(n):\r\n a = arr_inp()\r\n num = round(sqrt(a[0] ** 2 + a[1] ** 2), 7)\r\n dic[num] += a[2]\r\n\r\ndic2 = OrderedDict(sorted(dic.items(), key=lambda x: x[0]))\r\nfor i, j in dic2.items():\r\n s+=j\r\n if s>= 1000000:\r\n exit(print('{:.7f}'.format(i)))\r\n\r\nprint(-1)\r\n", "n,s = list(map(int,input().split()))\r\narr = []\r\nx,y = 0,0\r\nfor i in range(n):\r\n x,y,k = list(map(int,input().split()))\r\n r = (x**2 + y**2)**0.5\r\n arr.append([r,k])\r\narr.sort()\r\nfor i in range(n):\r\n s = s + arr[i][1]\r\n if s>=1000000:\r\n print(arr[i][0])\r\n break\r\nelse:\r\n print(-1)", "from math import *\r\nR = lambda:map(int, input().split())\r\nn, s = R()\r\na = []\r\nfor _ in range(n):\r\n x , y ,k = R()\r\n a.append((hypot(x,y),k))\r\na.sort()\r\nfor t in a:\r\n s += t[1]\r\n if s >= 1000000:\r\n print(t[0])\r\n exit()\r\nprint(-1)", "import sys\nimport math\nn, m = sys.stdin.readline().split()\nn = int(n)\nm = int(m)\n\ndef insertion_sort(array, val ):\n right = len(array) - 1 # n == 1\n left = 0 \n\n while left <= right:\n mid = left + (right - left)//2\n midval = array[mid]\n if midval > val:\n right = mid - 1 \n else:\n left = mid + 1 \n ## insertion\n if left == 0 :\n return [val] + array\n elif right == n - 1:\n return array + [val] \n else:\n return array[:left] + [val] + array[left:]\n\n\n\nsorted_dist = []\ndicti = dict()\nfor i in range(n):\n xi,yi, k = [int(i) for i in sys.stdin.readline().split()]\n dist = math.sqrt(xi**2 + yi **2)\n if dist in dicti:\n dicti[dist] += k\n else:\n dicti[dist] = k\n # insertion sort\n #print('dist', dist)\n sorted_dist = insertion_sort(sorted_dist, dist)\n #print(sorted_dist)\n\n#print('dict',dicti)\n#print('sorted_dist',sorted_dist)\n#print('k', k)\n\nif m >= 1000000:\n print(0)\n\nelse:\n breaki = False\n for i in sorted_dist:\n m += dicti[i]\n if m >= 1000000:\n print(i)\n breaki = True\n break\n if breaki == False:\n print(-1)\n \n \n\n\n\n\n\n" ]
{"inputs": ["4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1", "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1", "2 1\n1 1 999997\n2 2 1", "4 999998\n3 3 10\n-3 3 10\n3 -3 10\n-3 -3 10", "15 95473\n-9 6 199715\n0 -8 110607\n0 2 6621\n-3 -2 59894\n-10 -8 175440\n-2 0 25814\n10 -4 68131\n7 1 9971\n6 7 821\n6 5 20208\n6 2 68468\n0 7 37427\n1 -3 13337\n-10 7 113041\n-6 -2 44028", "20 93350\n13 -28 486\n26 -26 48487\n5 -23 143368\n-23 -25 10371\n-2 -7 75193\n0 -8 3\n-6 -11 5015\n-19 -18 315278\n28 -15 45801\n21 8 4590\n-4 -28 12926\n-16 17 9405\n-28 -23 222092\n1 -10 1857\n14 -28 35170\n-4 -22 22036\n-2 -10 1260\n-1 12 375745\n-19 -24 38845\n10 -25 9256", "30 505231\n-18 16 88130\n-10 16 15693\n16 -32 660\n-27 17 19042\n30 -37 6680\n36 19 299674\n-45 21 3300\n11 27 76\n-49 -34 28649\n-1 11 31401\n25 42 20858\n-40 6 455660\n-29 43 105001\n-38 10 6042\n19 -45 65551\n20 -9 148533\n-5 -24 393442\n-43 2 8577\n-39 18 97059\n12 28 39189\n35 23 28178\n40 -34 51687\n23 41 219028\n21 -44 927\n47 8 13206\n33 41 97342\n10 18 24895\n0 12 288\n0 -44 1065\n-25 43 44231", "2 500000\n936 1000 500000\n961 976 500000", "10 764008\n959 32 23049\n-513 797 38979\n-603 -838 24916\n598 -430 25414\n-280 -624 18714\n330 891 21296\n-347 -68 27466\n650 -842 30125\n-314 889 35394\n275 969 5711", "30 295830\n1 -4 24773\n4 3 26175\n-2 -3 14789\n2 -1 46618\n-2 -2 52997\n-3 0 517\n-2 0 18173\n-4 -3 54465\n2 4 63579\n4 -4 41821\n2 2 11018\n0 4 42856\n0 -1 51885\n-3 4 57137\n3 0 4688\n0 2 60137\n-4 4 33484\n-1 3 66196\n3 -1 53634\n0 -2 41630\n-2 1 54606\n2 -2 2978\n2 -3 23733\n1 -2 35248\n-3 -3 15124\n-2 -4 26518\n4 0 28151\n4 -1 18348\n3 3 16914\n-4 2 26013", "10 511500\n-5129 -3858 76954\n1296 1130 36126\n1219 6732 102003\n-8026 -178 4150\n-3261 1342 105429\n7965 -3013 62561\n5607 8963 53539\n-9044 -3999 16509\n1406 4103 115667\n-3716 2522 110626", "20 39342\n2 0 36476\n-3 1 136925\n1 3 31234\n0 -3 23785\n-1 3 77700\n-3 -1 50490\n-1 -3 13965\n-3 2 121093\n3 0 118933\n-3 0 125552\n-3 3 54779\n-2 0 96250\n1 2 142643\n2 2 23848\n0 2 29845\n0 -2 80462\n-1 1 91852\n-1 2 26526\n0 -1 136272\n1 1 108999", "2 1\n1 0 1\n0 1 999999", "2 999997\n1 1 1\n1 2 1"], "outputs": ["2.8284271", "1.4142136", "-1", "4.2426407", "12.8062485", "26.1725047", "24.5153013", "1369.7065379", "1063.7029661", "4.4721360", "6841.4753526", "3.0000000", "1.0000000", "-1"]}
UNKNOWN
PYTHON3
CODEFORCES
120
18676c03598b38db0d03c7b1d0fce954
Dijkstra?
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices. Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. Sample Input 5 6 1 2 2 2 5 5 2 3 4 1 4 1 4 3 3 3 5 1 5 6 1 2 2 2 5 5 2 3 4 1 4 1 4 3 3 3 5 1 Sample Output 1 4 3 5 1 4 3 5
[ "import sys\nimport math\nimport heapq\ninput = sys.stdin.readline\n\nVC, EC = map(int, input().split())\nG = [[] for _ in range(VC+1)]\nfor _ in range(EC) :\n VA, VB, VW = map(int, input().split())\n G[VA].append((VB, VW))\n G[VB].append((VA, VW))\n\n\nv = [False]*(VC+1)\nd = [math.inf]*(VC+1)\nf = list(range(VC+1))\nh = []\nd[1] = 0\nf[1] = 1\nheapq.heappush(h, (0, 1))\nwhile h :\n HEW, HVN = heapq.heappop(h)\n if v[HVN] : continue\n v[HVN] = True\n\n for nv, nw in G[HVN] :\n if d[nv] > d[HVN]+nw :\n d[nv] = d[HVN]+nw\n f[nv] = HVN\n heapq.heappush(h, (d[nv], nv))\n\n\nrs = []\nsg = VC\nwhile f[sg] != sg :\n rs.append(sg)\n sg = f[sg]\nrs.append(sg)\nrs = rs[::-1]\n\n\nif rs[0] == 1 : print(\" \".join(map(str, rs)))\nelse : print(-1)\n", "import sys\nfrom heapq import heappop, heappush\n \n \ninput = sys.stdin.readline\n \ndef dijkstra(graph, start=0):\n n = len(graph)\n dist, parents = [float('inf')] * n, [-1] * n\n dist[start] = 0.0\n \n queue = [(0.0, start)]\n while queue:\n path_len, v = heappop(queue)\n if path_len == dist[v]:\n for (w, edge_len) in graph[v]:\n if edge_len + path_len < dist[w]:\n dist[w], parents[w] = edge_len + path_len, v\n heappush(queue, (edge_len + path_len, w))\n \n return dist, parents\n \n \n \nn, m = map(int, input().split())\ngraph = [[] for _ in range(n)]\nfor i in range(m):\n a, b, w = map(int, input().split())\n graph[a-1].append((b-1, w))\n graph[b-1].append((a-1, w))\n \n_, parents = dijkstra(graph)\nif parents[n - 1] == -1:\n print(-1)\nelse:\n res, parent = [], n - 1\n while parent != parents[0]:\n res.append(parent + 1)\n parent = parents[parent]\n res.reverse()\n print(*res)\n", "#!/usr/bin/env python3\n\n# pylint: disable = bad-whitespace\n# pylint: disable = invalid-name\n# pylint: disable = missing-docstring\n# pylint: disable = too-few-public-methods\n\n# -----------\n# Dijkstra.py\n# -----------\n\n\"\"\"\nC. Dijkstra?\nhttp://codeforces.com/problemset/problem/20/C/\n\nThu, 18 Oct 2015\nPython 3.4: 779 ms\n\n1.\nadd all the vertices to a priority queue\nqueue's max size is the number of vertices\nno further pushing onto the queue\nqueue does not contain duplicate vertices\nno seen check needed when popping\nuse queue's decrease_key()\nneither C++ nor Python have decrease_key()\n\n2.\nadd only source vertex to a priority queue\nqueue's max size is larger than the number of vertices\nuse queue's push() for all neighboring vertices\nqueue contains duplicate vertices with equal, better, and worse distances\nseen check needed when popping\n\n3.\nadd only source vertex to a priority queue\nqueue's max size is larger than the number of vertices\nuse priority queue's push() only for neighbors with a smaller distance\nqueue contains duplicate vertices with better distances\nno seen check needed when popping\n\"\"\"\n\nfrom heapq import heappop, heappush\nfrom sys import stdin\n\nclass node :\n def __init__ (self, vertex, distance) :\n self.vertex = vertex\n self.distance = distance\n\n def __lt__ (self, rhs) :\n return self.distance < rhs.distance\n\ndef make_graph (m) :\n graph_dict = {}\n\n for _ in range(m) :\n s = input()\n from_vertex, to_vertex, distance = (int(t) for t in s.split())\n\n if from_vertex not in graph_dict :\n graph_dict[from_vertex] = {}\n\n if to_vertex not in graph_dict :\n graph_dict[to_vertex] = {}\n\n graph_dict[from_vertex][to_vertex] = distance\n graph_dict[to_vertex][from_vertex] = distance\n\n return graph_dict\n\ndef find_path (graph_dict, begin_vertex, end_vertex) :\n end_node = node(end_vertex, 0)\n node_dict = {end_vertex : end_node}\n queue = []\n\n heappush(queue, end_node)\n\n while queue :\n from_node = heappop(queue)\n from_vertex = from_node.vertex\n from_distance = from_node.distance\n\n if from_vertex == begin_vertex :\n return node_dict\n\n if from_vertex in graph_dict :\n for to_vertex in graph_dict[from_vertex] :\n distance = from_distance + graph_dict[from_vertex][to_vertex]\n\n if (to_vertex not in node_dict) or (distance < node_dict[to_vertex].distance) :\n node_dict[to_vertex] = node(from_vertex, distance)\n heappush(queue, node(to_vertex, distance))\n\n return {}\n\ndef test_case (n, m) :\n begin_vertex = 1\n end_vertex = n\n graph_dict = make_graph(m)\n node_dict = find_path(graph_dict, begin_vertex, end_vertex)\n\n if not node_dict :\n print(\"-1\")\n return\n\n path_list = [begin_vertex]\n\n while begin_vertex != end_vertex :\n begin_vertex = node_dict[begin_vertex].vertex\n path_list.append(begin_vertex)\n\n print(\" \".join(str(v) for v in path_list))\n\ndef main () :\n for s in stdin :\n n, m = (int(t) for t in s.split())\n test_case(n, m)\n\nif __name__ == \"__main__\" :\n main()\n", "import heapq\r\nfrom sys import stdin, stdout\r\n\r\ninf = 1000000000012\r\nn,m = map(int, stdin.readline().strip().split())\r\nrelation = [[] for i in range(n+3)]\r\ndis=[inf for x in range(n+3)]\r\npar= [0 for x in range(n+3)]\r\nfor i in range(0,m):\r\n a,b,w = map(int, stdin.readline().strip().split())\r\n relation[a].append((b,w))\r\n relation[b].append((a,w))\r\n \r\n \r\n \r\ndef dijkstra(start):\r\n dis[start]=0\r\n pq = [(0,1)]\r\n par[1]=-1\r\n while len(pq)>0:\r\n x,node = heapq.heappop(pq)\r\n if dis[node]!=x:\r\n continue\r\n for neighbour,w in relation[node]:\r\n if dis[neighbour]>dis[node]+w:\r\n par[neighbour]=node\r\n dis[neighbour]=dis[node]+w\r\n heapq.heappush(pq,(dis[neighbour],neighbour))\r\n \r\ndijkstra(1)\r\nif(par[n]==0):\r\n print(-1)\r\nelse:\r\n path=[]\r\n node=n\r\n while node!=-1:\r\n path.append(node)\r\n node=par[node]\r\n path.reverse()\r\n for x in path:\r\n print(x , end=\" \")\r\n", "from heapq import heappop, heappush \r\nnodes, edges = map(int, input().split())\r\nadj = [dict() for i in range(nodes + 1)]\r\nprev = [None] * (nodes + 1)\r\nvisited = [False] * (nodes + 1)\r\ncostList = [float(\"inf\")] * (nodes + 1)\r\nfor i in range(edges):\r\n start, end, dist = map(int, input().split())\r\n adj[start][end] = min(adj[start].get(end, float(\"inf\")), dist)\r\n adj[end][start] = adj[start][end]\r\n# dijkstra\r\npq = []\r\ncounter = 0 \r\nheappush(pq, (0, counter, 1))\r\ncounter += 1\r\nwhile pq:\r\n cost, count, index = heappop(pq)\r\n if index == nodes:\r\n break\r\n if not visited[index]:\r\n visited[index] = True\r\n for nextIndex, nextCost in adj[index].items():\r\n if(cost + nextCost < costList[nextIndex]):\r\n costList[nextIndex] = cost + nextCost\r\n prev[nextIndex] = index\r\n heappush(pq, (cost + nextCost, counter, nextIndex))\r\n counter += 1\r\n\r\nres = []\r\nbackIndex = nodes\r\nwhile backIndex != 1:\r\n if backIndex == None:\r\n print(-1)\r\n exit(0)\r\n res.append(backIndex)\r\n backIndex = prev[backIndex]\r\nres.append(backIndex)\r\nres.reverse()\r\nprint(*res)\r\n\r\n\r\n", "import sys\r\ninput=sys.stdin.readline\r\n\r\nimport heapq\r\n\r\nn,m=map(int,input().split())\r\nedges=[[] for i in range(n+1)]\r\n\r\nfor _ in range(m):\r\n a,b,w=map(int,input().split())\r\n edges[a].append((b,w))\r\n edges[b].append((a,w))\r\nheap=[(0,1)]\r\nmin_distance=[float('inf') for i in range(n+1)]\r\nmin_distance[1]=0\r\npreceeding_vertex=dict()\r\nwhile heap:\r\n distance,relaxed_vertex=heapq.heappop(heap)\r\n if(distance>min_distance[relaxed_vertex]):\r\n continue\r\n for j,w in edges[relaxed_vertex]:\r\n if(min_distance[j]>min_distance[relaxed_vertex]+w):\r\n preceeding_vertex[j]=relaxed_vertex\r\n min_distance[j]=min_distance[relaxed_vertex]+w\r\n heapq.heappush(heap,(min_distance[j],j))\r\nans=[n]\r\ntry:\r\n while n!=1:\r\n ans.append(preceeding_vertex[n])\r\n n=preceeding_vertex[n]\r\n print(*ans[::-1])\r\nexcept:\r\n print(-1)\r\n", "from heapq import heappush, heappop\nimport sys\n\ninput = sys.stdin.readline\nn, m = map(int, input().split())\ndat = [[] for i in range(n + 1)]\nfor i in range(1, m + 1):\n a, b, w = map(int, input().split())\n dat[a].append([b, w])\n dat[b].append([a, w])\n\ndis = [float('inf') for i in range(n + 1)]\npath = [0 for i in range(n + 1)]\nq = [(0, 1)]\n\nwhile q:\n s1, s2 = heappop(q)\n for b, w in dat[s2]:\n if dis[b] > s1 + w:\n path[b] = s2\n dis[b] = s1 + w\n heappush(q, (dis[b], b))\n\nif path[n] == 0:\n print('-1')\nelse:\n ret = [n]\n i = n\n while i > 1:\n i = path[i]\n ret.append(i)\n\n print(*ret[::-1])\n\n", "import heapq as hq\nInf = float(\"inf\")\n\n\ndef Dijkstra(n, adj, src):\n\tpq=[]\n\td=[Inf]*(n+1)\n\tparent=[None]*(n+1)\n\td[src]=0\n\thq.heappush(pq,(d[src],src))\n\twhile pq:\n\t\t_,u=hq.heappop(pq)\n\t\tfor v,w in adj[u]:\n\t\t\tif d[v]>d[u]+w:\n\t\t\t\td[v]=d[u]+w\n\t\t\t\tparent[v]=u\n\t\t\t\thq.heappush(pq,(d[v],v))\n\treturn d,parent\n\nn,m=map(int,input().split())\nadj={}\nfor i in range(1,n+1):\n\tadj[i]=[]\nfor _ in range(m):\n\tu,v,w=map(int,input().split())\n\tadj[u].append([v,w])\n\tadj[v].append([u,w])\nd,parent=Dijkstra(n,adj,1)\nif d[n]==Inf:\n\tprint (\"-1\")\nelse:\n\tpath=[]\n\tx=n\n\twhile x is not None:\n\t\tpath.append(x)\n\t\tx=parent[x]\n\tl= len(path)\n\tfor i in range(l):\n\t\tprint(path[l-i-1],end=\" \")\n\t\t\t \t \t \t\t\t \t \t \t \t\t\t\t\t", "from collections import defaultdict\nfrom heapq import heappop, heappush\nimport math\n\nnum_de_vertices, num_de_arestas = map(int, input().split())\narestas = defaultdict(list)\n\nfor i in range(num_de_arestas):\n endpoint_um, endpoint_dois, tamanho = map(int, input().split())\n endpoint_um -= 1\n endpoint_dois -= 1\n arestas[endpoint_um].append((endpoint_dois, tamanho))\n arestas[endpoint_dois].append((endpoint_um, tamanho))\n\npesos = []\nvisitados = set()\nminimo = [math.inf] * num_de_vertices\npai = [None] * num_de_vertices\nalvo = (num_de_vertices - 1)\nheappush(pesos, [0, 0, None])\n\nwhile pesos:\n custo, vertice, papai = heappop(pesos)\n if(vertice in visitados):\n continue\n \n pai[vertice] = papai\n minimo[vertice] = custo\n visitados.add(vertice)\n if(vertice == alvo):\n break\n for filho, custo in arestas[vertice]:\n if(filho in visitados):\n continue\n if(minimo[filho] > (minimo[vertice] + custo)):\n minimo[filho] = (minimo[vertice] + custo)\n heappush(pesos, [minimo[filho], filho, vertice])\n\ncaminho = []\nvertice = alvo\nwhile(vertice != None):\n caminho.append(vertice + 1)\n vertice = pai[vertice]\n\ncaminho.reverse()\n\nif 1 in caminho:\n print(*caminho)\nelse:\n print(-1)\n \n \t \t\t\t\t \t\t \t\t \t\t\t \t\t", "\"\"\"\r\n pppppppppppppppppppp\r\n ppppp ppppppppppppppppppp\r\n ppppppp ppppppppppppppppppppp\r\n pppppppp pppppppppppppppppppppp\r\n pppppppppppppppppppppppppppppppp\r\n pppppppppppppppppppppppp\r\n ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppp\r\n pppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp\r\n ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp\r\n ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp\r\n pppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppp\r\n ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp\r\n pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp\r\n pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp\r\n ppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp\r\n pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppppp\r\n ppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp\r\n pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp\r\n ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp\r\n pppppppppppppppppppppppp\r\n pppppppppppppppppppppppppppppppp\r\n pppppppppppppppppppppp pppppppp\r\n ppppppppppppppppppppp ppppppp\r\n ppppppppppppppppppp ppppp\r\n pppppppppppppppppppp\r\n\"\"\"\r\n\r\n\r\nimport sys\r\nfrom functools import lru_cache, cmp_to_key\r\nfrom heapq import merge, heapify, heappop, heappush, nsmallest\r\nfrom math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf\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\r\nfrom time import perf_counter\r\nfrom fractions import Fraction\r\nfrom decimal import Decimal\r\n# sys.setrecursionlimit(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(str(var))\r\ndef outa(*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\n\r\n\r\ndef dijkstra():\r\n pq = [[0, 1]]\r\n dist[1] = 0\r\n heapify(pq)\r\n while pq:\r\n distance, temp = heappop(pq)\r\n if dist[temp] < distance:\r\n continue\r\n for child in graph[temp]:\r\n new = dist[temp] + child[1]\r\n if new < dist[child[0]]:\r\n dist[child[0]] = new\r\n heappush(pq, [new, child[0]])\r\n parent[child[0]] = temp\r\n path()\r\n\r\n\r\ndef path():\r\n answer = []\r\n start = n\r\n while start:\r\n answer.append(start)\r\n start = parent[start]\r\n if 1 not in answer or n not in answer:\r\n out(-1)\r\n exit()\r\n outa(*answer[::-1])\r\n\r\n\r\nn, m = sp()\r\ngraph = dd(set)\r\nfor i in range(m):\r\n u, v, w = sp()\r\n graph[u].add((v, w))\r\n graph[v].add((u, w))\r\nparent = [0] * (n + 1)\r\ndist = [inf] * (n + 1)\r\ndijkstra()\r\n", "from heapq import *\r\nimport sys\r\ninput = sys.stdin.readline\r\nn, m = map(int, input().split())\r\ng = [[] for i in range(n + 1)]\r\nfor i in range(m):\r\n\tx, y, w = map(int, input().split())\r\n\tif x!=y:\r\n\t\tg[x].append((y, w))\r\n\t\tg[y].append((x, w))\r\npath = [i for i in range(n + 1)]\r\ndis = [10**12] * (n + 1)\r\nhp = [(0, 1)]\r\nwhile hp:\r\n\tdcur, cur = heappop(hp)\r\n\tfor v, w in g[cur]:\r\n\t\tif dcur + w < dis[v]:\r\n\t\t\tdis[v] = dcur + w\r\n\t\t\tpath[v] = cur\r\n\t\t\theappush(hp, (dis[v], v))\r\nl = [n]\r\nx = n\r\nif dis[n] != 10**12:\r\n\twhile x != 1:\r\n\t\tx = path[x]\r\n\t\tl.append(x)\r\n\tprint(*l[::-1])\r\nelse:print(-1)", "from heapq import heappop, heappush\n\nif __name__ == \"__main__\":\n n, m = [int(i) for i in input().split()]\n graph = [[] for _ in range(n)]\n shortest = [0] + [float(\"inf\")] * n\n for i in range(m):\n a, b, w = map(int, input().split())\n graph[a-1] += [(w, b-1)]\n graph[b-1] += [(w, a-1)]\n\n search_queue = [(0, 0)]\n closest_parent = [n + 1] * n\n while search_queue:\n a = heappop(search_queue)[1]\n for e in graph[a]:\n w, b = shortest[a] + e[0], e[1]\n if w < shortest[b]:\n shortest[b], closest_parent[b] = w, a\n heappush(search_queue, (shortest[b], b))\n if shortest[n-1] == float(\"inf\"):\n print(-1)\n else:\n next_p, shortest_p = n - 1, []\n while next_p != n + 1:\n shortest_p += [next_p + 1]\n next_p = closest_parent[next_p]\n shortest_p.reverse()\n print(' '.join([str(i) for i in shortest_p]))\n\n\t \t \t\t \t \t\t\t \t \t \t\t\t", "import heapq\r\ninf = 10e10 + 9\r\nm,n = map(int, input().split())\r\ngraf = [[] for _ in range(m + 1)]\r\nfor x in range(n):\r\n od, do, waga = map(int, input().split())\r\n graf[od].append([do, waga])\r\n graf[do].append([od, waga])\r\nkolejka = [[0, 1]]\r\nodwiedzeni = [False for _ in range(m + 1)]\r\nodleglosc = [inf for _ in range(m + 1)]\r\nodleglosc[1] = 0\r\npoprz = [0 for _ in range(m + 1)]\r\nwhile kolejka:\r\n punkt = heapq.heappop(kolejka)\r\n waga, miejsce = punkt[0], punkt[1]\r\n if odwiedzeni[miejsce]:\r\n continue\r\n odwiedzeni[miejsce] = True\r\n for x in graf[miejsce]:\r\n sasiad, waga_s = x[0], x[1]\r\n if odwiedzeni[sasiad]:\r\n continue\r\n if odleglosc[miejsce] + waga_s < odleglosc[sasiad]:\r\n odleglosc[sasiad] = odleglosc[miejsce] + waga_s\r\n poprz[sasiad] = miejsce\r\n heapq.heappush(kolejka, [odleglosc[sasiad], sasiad])\r\ntrasa = [m]\r\nwhile trasa[-1] != 1:\r\n if poprz[trasa[-1]] == 0:\r\n break\r\n else:\r\n trasa.append(poprz[trasa[-1]])\r\nif trasa[-1] != 1:\r\n print(-1)\r\nelse:\r\n print(*(trasa[::-1]))", "import heapq, sys\r\n\r\nn, m = map(int, input().split())\r\nadj = dict()\r\nfor i in range(1, n+1):\r\n adj[i] = dict()\r\n\r\nfor i in range(m):\r\n a, b, c = map(int, input().split())\r\n if not a in adj[b] or adj[a][b] > c: adj[b][a] = c\r\n if not b in adj[a] or adj[b][a] > c: adj[a][b] = c\r\nINF = 10000000000000\r\nprev = [-1]*(n+1)\r\nvisited = [0]*(n+1)\r\ndist = [INF]*(n+1)\r\npq = []\r\nheapq.heappush(pq, (0, 1))\r\ndist[1] = 0\r\nwhile len(pq) > 0:\r\n c, u = heapq.heappop(pq)\r\n if visited[u]: continue\r\n visited[u] = True\r\n if u == n:\r\n break\r\n for v in adj[u]:\r\n alt = dist[u] + adj[u][v]\r\n if alt < dist[v]:\r\n dist[v] = alt\r\n prev[v] = u\r\n heapq.heappush(pq, (alt, v))\r\nst = [0]*(n+3) ; k = n-1\r\ni = n\r\nwhile i != -1:\r\n st[k] = i\r\n k -= 1\r\n i = prev[i]\r\nif st[k+1] != 1:\r\n print(-1)\r\n sys.exit();\r\nfor i in range(k+1, n, 1):\r\n print(st[i], end=' ')\r\n", "# This code from another contestant\r\n\r\nfrom heapq import heappop, heapify, heappush\r\nfrom collections import defaultdict\r\n\r\ndef dijkstra(g , end, cost):\r\n visited = set()\r\n h = [(0,end, end)]\r\n prev = {}\r\n\r\n while len(h) > 0:\r\n d,v,p = heappop(h)\r\n if v not in visited:\r\n visited.add(v)\r\n prev[v] = p\r\n if v == cost:\r\n break\r\n\r\n for adj, adj_d, in g[v]:\r\n heappush(h, (adj_d + d, adj, v))\r\n\r\n path , p = [],cost\r\n while p in prev and prev[p] != p:\r\n path.append(p)\r\n p = prev[p]\r\n path.append(end)\r\n\r\n return path[::-1]\r\n\r\nif __name__ == '__main__':\r\n n, m = map(int, input().split())\r\n g = defaultdict(list)\r\n for _ in range(m):\r\n a,b ,w = map(int,input().split())\r\n g[a].append((b,w))\r\n g[b].append((a,w))\r\n p = dijkstra(g,1,n)\r\n\r\n if n in p:\r\n print(\" \".join(map(str,p)))\r\n else:\r\n print(-1)", "import heapq\nif __name__ == '__main__':\n k, m = map(int,input().split())\n adj={}\n for i in range(1,k+1):\n adj[i]=[]\n for i in range(m):\n u,v,w=map(int, input().split())\n adj[u].append([v,w])\n adj[v].append([u,w])\n dist={}\n for i in range(1,k+1):\n dist[i]=float('inf')\n frontier=[]\n path={}\n heapq.heappush(frontier,(0,1))\n while frontier:\n cost,pos=heapq.heappop(frontier)\n for neighbour,neighbour_cost in adj[pos]:\n cand_cost=cost+neighbour_cost\n \n if cand_cost<dist[neighbour]:\n dist[neighbour]=cand_cost\n path[neighbour]=pos\n heapq.heappush(frontier,(cand_cost,neighbour))\n if dist[k]!=float('inf'):\n res = [k]\n x = k\n while x!=1:\n x = path[x]\n res.append(x)\n res.reverse()\n print(*res)\n else:\n print(-1)", "from heapq import heappush, heappop\r\n \r\ndef dijkstra(adj):\r\n n = len(adj)\r\n INF = int(1e18)\r\n dist = [INF] * n\r\n pre = [-1] * n\r\n heap = [(0, 0)]\r\n dist[0] = 0\r\n while len(heap) > 0:\r\n d, u = heappop(heap)\r\n if d > dist[u]: \r\n continue\r\n for edge in adj[u]:\r\n v, w = edge[0], dist[u] + edge[1]\r\n if w < dist[v]:\r\n dist[v], pre[v] = w, u\r\n heappush(heap, (dist[v], v))\r\n \r\n if pre[n - 1] == -1:\r\n print(-1)\r\n else:\r\n path = []\r\n target = n - 1\r\n while target != -1:\r\n path.append(target)\r\n target = pre[target]\r\n path.reverse()\r\n for v in path:\r\n print(v + 1, end = ' ')\r\n\r\n\r\nvertices, edges = map(int,input().split())\r\nadj = [[] for _ in range(vertices)]\r\n\r\nfor _ in range(edges):\r\n v1, v2, distance = list(map(int, input().split()))\r\n adj[v1 - 1].append((v2 - 1, distance))\r\n adj[v2 - 1].append((v1 - 1, distance))\r\n \r\ndijkstra(adj)", "from sys import stdin\r\nfrom heapq import heappop, heappush\r\ndef input(): return stdin.readline().rstrip('\\r\\n')\r\n\r\nn, m = map(int, input().split())\r\nadj = [[] for _ in range(n)]\r\nvis = [False] * n \r\ndis = [int(1e18)] * n\r\npar = [-1] * n\r\nfor _ in range(m):\r\n x, y, z = map(int, input().split())\r\n x -= 1\r\n y -= 1\r\n adj[x].append([y, z])\r\n adj[y].append([x, z])\r\n\r\npq = [[0, 0]]\r\ndis[0] = 0\r\nwhile pq:\r\n cur_wt, cur_x = heappop(pq)\r\n if vis[cur_x]:\r\n continue\r\n vis[cur_x] = True\r\n for y, wt in adj[cur_x]:\r\n if dis[y] > dis[cur_x] + wt:\r\n dis[y] = dis[cur_x] + wt\r\n heappush(pq, [dis[y], y])\r\n par[y] = cur_x\r\n\r\nif par[n - 1] == -1:\r\n print(-1)\r\n exit()\r\n\r\nans = []\r\nid = n - 1\r\nwhile id != -1:\r\n ans.append(id + 1)\r\n id = par[id]\r\n\r\nprint(*ans[::-1])\r\n", "from heapq import *\r\nn, m = map(int, input().split())\r\ndists = [1000000000000000] * (n - 1) + [0]\r\nqueue = [(0, n - 1)]\r\ngraph = [[] for _ in range(n)]\r\ntmp = [n] * n\r\n \r\nfor i in range(m):\r\n a, b, w = map(int, input().split())\r\n graph[a - 1].append((b, w))\r\n graph[b - 1].append((a, w))\r\n \r\nwhile queue:\r\n w, a = heappop(queue)\r\n if a == 0: break\r\n for b, cost in graph[a]:\r\n if dists[b - 1] > w + cost:\r\n dists[b - 1] = w + cost\r\n tmp[b - 1] = a\r\n heappush(queue, (dists[b - 1], b - 1))\r\n \r\npos = 0\r\nshortest_path = []\r\nwhile pos <= n - 1:\r\n shortest_path.append(pos + 1)\r\n pos = tmp[pos]\r\n \r\nif shortest_path[len(shortest_path) - 1] == n:\r\n print(*[i for i in shortest_path])\r\nelse:\r\n print(-1)", "from heapq import *\n\nnumero_de_vertices, numero_de_arestas = map(int, input().split())\n\ndistancias = [1000000000000000] * (numero_de_vertices-1) + [0]\nfila = [(0, numero_de_vertices-1)]\n\ngrafo = [[] for _ in range(numero_de_vertices)]\nproximo_vertice = [numero_de_vertices] * numero_de_vertices\n\nfor i in range(numero_de_arestas):\n vertice_a, vertice_b, peso = map(int, input().split())\n grafo[vertice_a-1].append((vertice_b, peso))\n grafo[vertice_b-1].append((vertice_a, peso))\n\nwhile fila:\n peso, vertice_atual = heappop(fila)\n\n if vertice_atual == 0:\n break\n\n for vertice_destino, custo in grafo[vertice_atual]:\n \n if distancias[vertice_destino-1] > peso + custo:\n distancias[vertice_destino-1] = peso + custo\n proximo_vertice[vertice_destino-1] = vertice_atual\n heappush(fila, (distancias[vertice_destino-1], vertice_destino-1))\n\nposicao_atual = 0\n\ncaminho_mais_curto = []\n\nwhile posicao_atual <= numero_de_vertices -1:\n caminho_mais_curto.append(posicao_atual+1)\n posicao_atual = proximo_vertice[posicao_atual]\n\nif caminho_mais_curto[len(caminho_mais_curto)-1] == numero_de_vertices:\n print(*[i for i in caminho_mais_curto])\n\nelse:\n print(-1)\n \t\t \t\t \t \t \t \t \t\t \t\t", "# Rishabh Rao (https://github.com/rishabhrao)\r\n\r\nimport sys\r\nimport heapq\r\nfrom collections import deque\r\nMOD = 1000000007\r\ndef inp(): return sys.stdin.readline().strip()\r\ndef ii(): return int(inp())\r\ndef iis(): return [int(i) for i in inp().split()]\r\n\r\n\r\ndef solve():\r\n n, m = iis()\r\n graph = [[] for _ in range(n + 1)]\r\n for _ in range(m):\r\n a, b, w = iis()\r\n graph[a].append((b, w))\r\n graph[b].append((a, w))\r\n\r\n distances = [MOD*MOD for _ in range(n + 1)]\r\n distances[1] = 0\r\n parents = [-1 for _ in range(n + 1)]\r\n\r\n queue = [(0, 1)]\r\n heapq.heapify(queue)\r\n while queue:\r\n dist, node = heapq.heappop(queue)\r\n for neighbour, wt in graph[node]:\r\n if wt + dist < distances[neighbour]:\r\n distances[neighbour] = dist + wt\r\n parents[neighbour] = node\r\n heapq.heappush(queue, (wt + dist, neighbour))\r\n\r\n if parents[n] == -1:\r\n return [-1]\r\n\r\n out = deque([n])\r\n parent = parents[n]\r\n while parent != -1:\r\n out.appendleft(parent)\r\n parent = parents[parent]\r\n\r\n return out\r\n\r\n\r\nprint(*solve())\r\n", "import heapq\n\nMAXN = 10 ** 5 + 3\nINF = float('inf')\n\nadjList = []\ndist = [INF] * MAXN\npar = [0] * MAXN\nisDone = [False] * MAXN\n\ndef dijkstra(s, t):\n global adjList, dist, par, isDone\n\n pq = []\n heapq.heappush(pq, (0, s))\n dist[s] = 0\n par[s] = -1\n\n while pq:\n d, u = heapq.heappop(pq)\n\n if u == t:\n return True\n\n isDone[u] = True\n\n for v, w in adjList[u]:\n if not isDone[v] and dist[u] + w < dist[v]:\n dist[v] = dist[u] + w\n heapq.heappush(pq, (dist[v], v))\n par[v] = u\n\n return False\n\n# Main function\nif __name__ == '__main__':\n # freopen(\"in.txt\", \"r\", stdin)\n\n n, m = map(int, input().split())\n\n adjList = [[] for _ in range(n + 3)]\n\n for _ in range(m):\n u, v, w = map(int, input().split())\n adjList[u].append((v, w))\n adjList[v].append((u, w))\n\n if dijkstra(1, n):\n path = []\n v = n\n while v != -1:\n path.append(v)\n v = par[v]\n\n for i in range(len(path) - 1, -1, -1):\n print(path[i], end=' ')\n \n print()\n else:\n print(\"-1\")\n\n \t \t \t \t \t \t \t\t \t\t \t", "n, m = [int(i) for i in input().split()]\n\nv = [[] for _ in range(n)]\nfor _ in range(m):\n a, b, w = [int(i) for i in input().split()]\n a -= 1\n b -= 1\n v[a].append((b, w))\n v[b].append((a, w))\n\nparent = [None] * n\nvisited = [False] * n\n\nimport heapq\n\nqueue = [(0, 0, None)]\n\nwhile len(queue) > 0:\n oldprice, vertex, prnt = heapq.heappop(queue)\n if not visited[vertex]:\n visited[vertex] = True\n parent[vertex] = prnt\n for edge, price in v[vertex]:\n if not visited[edge]:\n heapq.heappush(queue, (oldprice + price, edge, vertex))\n\n\nif parent[n - 1] is None:\n print(-1)\nelse:\n out = []\n while parent[n - 1] is not None:\n out.append(n)\n n = parent[n - 1] + 1\n out.append(1)\n out = [str(i) for i in out]\n print(\" \".join(out[::-1]))\n", "from heapq import * \r\nedg=[[] for i in range(int(1e5+1))]\r\ncost=[int(1e12) for i in range(int(1e5+1))] \r\ndef dijkstra(u):\r\n cost[u]=0\r\n pq=[]\r\n heapify(pq)\r\n heappush(pq,(0,u))\r\n while len(pq):\r\n w,v=heappop(pq)\r\n for ch in edg[v]:\r\n if cost[ch[1]]>w+ch[0]:\r\n cost[ch[1]]=w+ch[0]\r\n heappush(pq,(cost[ch[1]],ch[1]))\r\ndef output(n):\r\n if(cost[n]==int(1e12)):\r\n print(-1)\r\n return\r\n ans=[n]\r\n u=n\r\n while u!=1:\r\n for ch in edg[u]:\r\n if (cost[u]==cost[ch[1]]+ch[0]):\r\n u=ch[1]\r\n ans.append(ch[1])\r\n break\r\n ans.reverse()\r\n print(' '.join(str(x) for x in ans))\r\nif __name__==\"__main__\":\r\n n,m=map(int,input().split())\r\n while m :\r\n u,v,w=map(int,input().split())\r\n edg[u].append((w,v))\r\n edg[v].append((w,u))\r\n m-=1\r\n dijkstra(1) \r\n output(n) \r\n", "import sys\r\nfrom sys import stdin,stdout\r\nfrom heapq import *\r\n\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\nINF=float('inf')\r\nn,m=mp()\r\nd={i:[] for i in range(1,n+1)}\r\nfor i in range(m):\r\n a,b,c=mp()\r\n d[a].append((b,c))\r\n d[b].append((a,c))\r\n\r\ndis=[INF for i in range(n+1)]\r\ndis[1]=0\r\nh=[]\r\nheappush(h,(0,1)) #distance,node\r\nv=[False for i in range(n+1)]\r\npar=[-1 for i in range(n+1)]\r\nwhile h:\r\n cur_dis,cur_node=heappop(h)\r\n if v[cur_node]:\r\n continue\r\n v[cur_node]=True\r\n for node,distance in d[cur_node]:\r\n if cur_dis + distance < dis[node]:\r\n dis[node]=cur_dis + distance\r\n heappush(h,(dis[node],node))\r\n par[node]=cur_node\r\n\r\nif not v[n]:\r\n pr(-1)\r\nelse:\r\n \r\n ans=[]\r\n ans.append(n)\r\n n=par[n]\r\n while par[n]>0:\r\n ans.append(n)\r\n n=par[n]\r\n ans.append(1)\r\n print(*reversed(ans))\r\n ", "import sys\r\nfrom collections import Counter\r\ninput = sys.stdin.readline\r\n\r\nfrom heapq import heappop, heappush\r\n\r\n\r\ndef dijkstra(graph, start):\r\n \"\"\" \r\n Uses Dijkstra's algortihm to find the shortest path from node start\r\n to all other nodes in a directed weighted graph.\r\n \"\"\"\r\n n = len(graph)\r\n dist, parents = [float(\"inf\")] * n, [-1] * n\r\n dist[start] = 0\r\n\r\n queue = [(0, start)]\r\n while queue:\r\n path_len, v = heappop(queue)\r\n if path_len == dist[v]:\r\n for w, edge_len in graph[v]:\r\n if edge_len + path_len < dist[w]:\r\n dist[w], parents[w] = edge_len + path_len, v\r\n heappush(queue, (edge_len + path_len, w))\r\n\r\n return dist, parents\r\n\r\ndef main():\r\n n, m = map(int, input().split())\r\n\r\n g = [[] for _ in range(n)]\r\n\r\n for _ in range(m):\r\n a, b, w = map(int, input().split()); a-=1; b-=1\r\n g[a].append([b, w])\r\n g[b].append([a, w])\r\n \r\n d, par = dijkstra(g, 0)\r\n\r\n if d[n-1] == float(\"inf\"):\r\n print(-1)\r\n else:\r\n path = []\r\n\r\n cur = n-1\r\n\r\n while cur != 0:\r\n path.append(cur+1)\r\n cur = par[cur]\r\n\r\n path.append(1)\r\n path.reverse()\r\n print(*path)\r\n\r\n\r\nmain() \r\n\r\n\r\n", "from heapq import heappop, heappush\n\ndef dijkstra(graph, start, end):\n queue = [(0, start)]\n distances = [float('inf')] * (end + 1)\n distances[start] = 0\n paths = [-1] * (end + 1)\n\n while queue:\n curr_distance, curr_vertex = heappop(queue)\n\n if curr_distance != distances[curr_vertex]:\n continue\n\n for neighbor, weight in graph[curr_vertex]:\n distance = curr_distance + weight\n if distance < distances[neighbor]:\n distances[neighbor] = distance\n paths[neighbor] = curr_vertex\n heappush(queue, (distance, neighbor))\n\n if distances[end] == float('inf'):\n return []\n\n path = []\n while end != -1:\n path.append(end)\n end = paths[end]\n path.reverse()\n\n return path\n\nn, m = map(int, input().split())\ngraph = [[] for _ in range(n + 1)]\n\nfor _ in range(m):\n a, b, w = map(int, input().split())\n graph[a].append((b, w))\n graph[b].append((a, w))\n\npath = dijkstra(graph, 1, n)\nif path:\n print(' '.join(map(str, path)))\nelse:\n print(-1)\n\n\n\t\t \t\t \t\t \t\t\t\t \t\t\t\t\t \t \t \t \t", "import heapq as h\r\nimport io,os\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\nn,m=map(int,input().split())\r\na=[[] for j in range(n)]\r\nfor i in range(m):\r\n x,y,z=map(int,input().split())\r\n a[x-1].append([y-1,z])\r\n a[y-1].append([x-1,z])\r\nq=[[0,0]]\r\ndp=[float('inf')]*n\r\ndp[0]=0\r\nrs=[None]*n\r\nwhile q:\r\n v=h.heappop(q)[1]\r\n for e,k in a[v]:\r\n if dp[e]>k+dp[v]:\r\n dp[e]=k+dp[v]\r\n rs[e]=v\r\n h.heappush(q,[k,e])\r\nif dp[n-1]==float('inf'):\r\n print(-1)\r\nelse:\r\n kq=[]\r\n kq+=[n]\r\n t=rs[n-1]\r\n while t!=None:\r\n kq+=[t+1]\r\n t=rs[t]\r\n print(*kq[::-1])\r\n", "import heapq\nfrom collections import defaultdict\n\ndef dijkstras(start, get_neighbors):\n '''\n General dijsktras implementations that computes the distance to all nodes\n from the start, and tracks parents for constructing the shortest paths\n '''\n\n parents = defaultdict(lambda: None)\n distances = defaultdict(lambda: None)\n processed = set()\n q = []\n\n heapq.heappush(q, (0, start, None))\n\n while len(q) > 0:\n distance, node, parent = heapq.heappop(q)\n\n if node in processed:\n continue\n\n processed.add(node)\n distances[node] = distance\n parents[node] = parent\n\n for neighbor, cost in get_neighbors(node):\n if neighbor not in processed:\n heapq.heappush(q, (distance + cost, neighbor, node))\n\n return distances, parents\n\ndef construct_path(start, target, parents):\n '''\n Constructs the optimal path from start to target given the \"parents\"\n dictionary\n '''\n\n curr = target\n path = [target]\n\n while curr != start:\n curr = parents[curr]\n path.append(curr)\n\n return path[::-1]\n\ndef dijkstras2(start, target, get_neighbors):\n '''\n Implementation that stops early when it finds the target, and returns the\n optimal path between target and start.\n '''\n\n parents = defaultdict(lambda: None)\n distances = defaultdict(lambda: None)\n processed = set()\n q = []\n\n heapq.heappush(q, (0, start, None))\n\n while len(q) > 0:\n distance, node, parent = heapq.heappop(q)\n\n if node in processed:\n continue\n\n processed.add(node)\n distances[node] = distance\n parents[node] = parent\n\n if node == target:\n break\n\n for neighbor, cost in get_neighbors(node):\n if neighbor not in processed:\n heapq.heappush(q, (distance + cost, neighbor, node))\n\n return None if target not in parents else construct_path(start, target, parents)\n\n# Example that passes https://open.kattis.com/problems/shortestpath1\n'''\nwhile True:\n n, m, qs, s = map(int, input().split())\n\n if n == m == qs == s == 0:\n break\n\n graph = [[] for i in range(n)]\n\n for i in range(m):\n a, b, w = map(int, input().split())\n\n graph[a].append((b, w))\n\n distances, parents = dijkstras(s, lambda x: graph[x])\n\n for _ in range(qs):\n query = int(input())\n\n if query in distances:\n print(distances[query])\n else:\n print('IMPOSSIBLE')\n'''\n\n# Example that TLEs on the 4th input https://codeforces.com/problemset/problem/20/C\n# Probably because it needs to be transcribed to C++\n\nn, m = map(int, input().split())\ngraph = [[] for i in range(n + 1)]\n\nfor i in range(m):\n a, b, w = map(int, input().split())\n\n graph[a].append((b, w))\n graph[b].append((a, w))\n\npath = dijkstras2(1, n, lambda x: graph[x])\n\nprint(-1 if path is None else ' '.join(map(str, path)))\n\n", "import decimal\nimport heapq\nimport math\nimport os\nimport sys\nfrom array import array\nfrom collections import Counter, deque\nfrom io import BytesIO, IOBase\nimport bisect\nfrom types import GeneratorType\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\ndef isPrime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5\n while i * i <= n:\n if n % i == 0 or n % (i + 2) == 0:\n return False\n i = i + 6\n return True\n\n\ndef lcm(a, b): return (a * b) // math.gcd(a, b)\n\n\ndef ints_get(): return map(int, input().strip().split())\n\n\ndef list_get(): return list(map(int, sys.stdin.readline().strip().split()))\n\n\ndef chars_get(): return list(map(str, sys.stdin.readline().strip().split()))\n\n\ndef output(to_be_printed, end=\"\\n\"): sys.stdout.write(str(to_be_printed) + end)\n\n\ndef ipn(): return int(input())\n\n\ndef bootstrap(f, stack=[]):\n def wrappedfunc(*args, **kwargs):\n if stack:\n return f(*args, **kwargs)\n else:\n to = f(*args, **kwargs)\n while True:\n if type(to) is GeneratorType:\n stack.append(to)\n to = next(to)\n else:\n stack.pop()\n if not stack:\n break\n to = stack[-1].send(to)\n return to\n\n return wrappedfunc\n\n\n# ******************************************************#\n# **************** code starts here ********************#\n# ******************************************************#\n\n\nclass Dijkstra:\n def __init__(self, V):\n dic = {}\n for i in range(1, V + 1):\n dic[i] = {}\n self.G = dic\n self.E = 0\n self.V = V\n\n def add(self, _from, _to, _cost):\n\n self.G[_from][_to] = _cost\n self.G[_to][_from] = _cost\n self.E += 1\n\n def shortest_path(self, s):\n import heapq\n que = []\n d = [10 ** 15] * self.V\n d[s - 1] = 0\n heapq.heappush(que, (0, s))\n while len(que) != 0:\n cost, v = heapq.heappop(que)\n if d[v - 1] < cost: continue\n for i in self.G[v]:\n e = self.G[v][i]\n if d[i - 1] > d[v - 1] + e:\n d[i - 1] = d[v - 1] + e\n heapq.heappush(que, (d[i - 1], i))\n return d\n\n def back(self, s, t):\n data = self.shortest_path(s)\n val = data[t - 1]\n if val > 10**14:\n return []\n path = [t]\n pos = t\n while pos != s:\n for e in self.G[pos]:\n if data[e - 1] == data[pos - 1] - self.G[pos][e]:\n pos = e\n break\n path.append(pos)\n return path\n\n\ndef main():\n n, m = ints_get()\n d = Dijkstra(n)\n for _ in range(m):\n a, b, c = ints_get()\n d.add(a, b, c)\n d.add(b, a, c)\n arr = d.back(1, n)\n if len(arr) == 0:\n print(-1)\n else:\n arr.reverse()\n print(*arr)\n return\n\n\nif __name__ == \"__main__\":\n main()\n\n", "from heapq import heappop, heappush\r\ninfinite = 1 << 60\r\n\r\nvertices, edges = map(int, input().split())\r\ngraph = [[] for _ in range(vertices)]\r\ndistance = [0] + [infinite]*(vertices-1)\r\npath = [-1]*vertices\r\nqueue = [(0, 0)]\r\n\r\ni = 0\r\nwhile i < edges:\r\n a, b, w = map(int, input().split())\r\n graph[a-1].append((w, b-1))\r\n graph[b-1].append((w, a-1))\r\n i += 1\r\n\r\nwhile queue:\r\n d, u = heappop(queue)\r\n if d >= distance[u]:\r\n for element in graph[u]:\r\n d_new, v = element[0] + distance[u], element[1]\r\n if d_new < distance[v]:\r\n distance[v], path[v] = d_new, u\r\n heappush(queue, (distance[v], v))\r\n\r\nif distance[vertices-1] == infinite:\r\n print(-1)\r\nelse:\r\n x, a = vertices - 1, []\r\n while x != -1:\r\n a += [x + 1]\r\n x = path[x]\r\n a.reverse()\r\n print(' '.join(map(str, a)))\r\n", "import math\r\nimport sys\r\nimport queue\r\nfrom heapq import heappop, heappush\r\n\r\n# AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\n# HATE HATE HATE HATE !!!!!!\r\n# thx heapq\r\n\r\ndef solve():\r\n q = [(0, 0)]\r\n res = []\r\n\r\n n, m = map(int, sys.stdin.readline().split())\r\n g = [[] for i in range(n)]\r\n parent = [-1 for i in range(n)]\r\n dist = [10 ** 18 for i in range(n)]\r\n dist[0] = 0\r\n\r\n for i in range(m):\r\n v, u, w = map(int, sys.stdin.readline().split())\r\n v, u = v - 1, u - 1\r\n g[v] += [(w, u)]\r\n g[u] += [(w, v)]\r\n\r\n while q:\r\n k = heappop(q) # [edge, dist]\r\n if k[0] > dist[k[1]]:\r\n continue\r\n for d, u in g[k[1]]:\r\n if dist[u] > dist[k[1]] + d:\r\n dist[u] = dist[k[1]] + d\r\n parent[u] = k[1]\r\n heappush(q, (dist[u], u))\r\n\r\n if dist[n - 1] == 10 ** 18:\r\n sys.stdout.write(\"-1\")\r\n else:\r\n res = [n - 1]\r\n it = n - 1\r\n while parent[it] != -1:\r\n res.append(parent[it])\r\n it = parent[it]\r\n\r\n for i in range(len(res)):\r\n sys.stdout.write(str(res[-1 - i] + 1) + \" \")\r\n\r\n\r\nif __name__ == '__main__':\r\n multi_test = 0\r\n\r\n if multi_test:\r\n t = int(input())\r\n for _ in range(t):\r\n solve()\r\n else:\r\n solve()\r\n", "from heapq import heappop,heappush\r\nimport sys\r\ninput=sys.stdin.readline\r\ninf=10**18\r\ndef dijstkra(source):\r\n distance=[inf]*(n+1)\r\n queue=[(0,source)]\r\n distance[source]=0\r\n while queue:\r\n l,u=heappop(queue)\r\n for v,w in graph[u]:\r\n if distance[u]+w<distance[v]:\r\n distance[v]=distance[u]+w\r\n previous_node[v]=u\r\n heappush(queue,(distance[v],v))\r\n\r\nn,m=map(int,input().split())\r\ngraph=[[] for _ in range(1+n)]\r\nprevious_node=[-1]*(n+1)\r\nfor _ in range(m):\r\n u,v,w=map(int,input().split())\r\n graph[u].append((v,w))\r\n graph[v].append((u,w))\r\ndijstkra(1)\r\ndestination=n\r\npath=[n]\r\nstate=True\r\nwhile destination!=1 and state:\r\n if previous_node[destination]==-1:\r\n state=False\r\n path.append(previous_node[destination])\r\n destination=previous_node[destination]\r\n if destination==1: break\r\nif state: print(*path[::-1])\r\nelse: print(-1)", "#!/usr/bin/env python3\n\n# ---------------------------------------------------\n# problems/codeforces/secret-combination/Disjkstra.py\n# Copyright (C) 2015\n# Glenn P. Downing\n# ---------------------------------------------------\n\n\"\"\"\nC. Dijkstra?\nhttp://codeforces.com/problemset/problem/20/C/\n\nThu, 8 Oct 2015\nPython 3.4: 779 ms\n\"\"\"\n\nfrom heapq import heappop, heappush\nfrom sys import stdin\n\ndef make_graph (m) :\n graph_dict = {}\n\n for i in range(m) :\n s = input()\n u, v, w = (int(t) for t in s.split())\n\n if u not in graph_dict :\n graph_dict[u] = {}\n\n if v not in graph_dict :\n graph_dict[v] = {}\n\n graph_dict[u][v] = w\n graph_dict[v][u] = w\n\n return graph_dict\n\nclass node_type :\n def __init__ (self, vertex, distance) :\n self.vertex = vertex\n self.distance = distance\n\n def __lt__ (self, rhs) :\n return self.distance < rhs.distance\n\ndef find_path (graph_dict, begin_vertex, end_vertex) :\n node = node_type(end_vertex, 0)\n node_dict = {end_vertex : node}\n queue = []\n\n heappush(queue, node)\n\n while queue :\n from_node = heappop(queue)\n\n if from_node.vertex == begin_vertex :\n return node_dict\n\n if from_node.vertex in graph_dict :\n for to_vertex in graph_dict[from_node.vertex] :\n distance = from_node.distance + graph_dict[from_node.vertex][to_vertex]\n if (to_vertex not in node_dict) or (distance < node_dict[to_vertex].distance) :\n node_dict[to_vertex] = node_type(from_node.vertex, distance)\n heappush(queue, node_type(to_vertex, distance))\n\n return None\n\ndef test_case (n, m) :\n begin_vertex = 1\n end_vertex = n\n graph_dict = make_graph(m)\n node_dict = find_path(graph_dict, begin_vertex, end_vertex)\n\n if not node_dict :\n print(\"-1\")\n return\n\n path_list = [begin_vertex]\n\n while begin_vertex != end_vertex :\n begin_vertex = node_dict[begin_vertex].vertex\n path_list.append(begin_vertex)\n\n print(\" \".join(str(v) for v in path_list))\n\ndef main () :\n for s in stdin :\n n, m = (int(t) for t in s.split())\n test_case(n, m)\n\nif __name__ == \"__main__\" :\n main()\n", "from heapq import heappop, heappush\n\nn, m = [int(x) for x in input().split()]\ngraph = [[] for _ in range(n)]\ndistance = [0] + [float(\"inf\")] * n\np = [-1] * n\nq = [(0, 0)]\n\nfor _ in range(m):\n a, b, w = [int(x) for x in input().split()]\n graph[a - 1] += [(w, b - 1)]\n graph[b - 1] += [(w, a - 1)]\n\nwhile q:\n a = heappop(q)[1]\n for e in graph[a]:\n w, b = distance[a] + e[0], e[1]\n if w < distance[b]:\n distance[b], p[b] = w, a\n heappush(q, (distance[b], b))\nif distance[n - 1] == float(\"inf\"):\n print(-1)\nelse:\n x, y = n - 1, []\n while x != -1:\n y += [x + 1]\n x = p[x]\n y.reverse()\n print(\" \".join(map(str, y)))\n\n \t\t \t \t \t\t \t\t\t\t\t\t\t\t\t \t\t\t", "import sys, os.path\r\nfrom collections import*\r\nfrom heapq import *\r\nfrom copy import*\r\nimport math\r\ninput=sys.stdin.buffer.readline\r\n \r\nn,m = map(int, input().split())\r\ng = defaultdict(list)\r\n \r\nfor i in range(m):\r\n\ta,b,w = map(int, input().split())\r\n\tg[a].append((b,w))\r\n\tg[b].append((a,w))\r\n \r\nvis = set()\r\ndis = [10000000000000000 for i in range(n+1)]\r\ndis[0] = 0\r\ndis[1] = 0\r\nhp = [(0,1)]\r\nparent = [-1 for i in range(n+1)]\r\n \r\nwhile(len(hp)>0):\r\n\tdistu, u = heappop(hp)\r\n\tfor i in g[u]:\r\n\t\tv = i[0]\r\n\t\twt = i[1]\r\n\t\tif(dis[v]>dis[u]+wt):\r\n\t\t\tparent[v] = u\r\n\t\t\tdis[v] = dis[u]+wt\r\n\t\t\theappush(hp, (dis[v], v))\r\n \r\npath=[]\r\nlast=n\r\nif(parent[n]==-1):\r\n\tprint(\"-1\")\r\nelse:\r\n\twhile(last!=-1):\r\n\t\tpath.append(last)\r\n\t\tlast = parent[last]\r\n\tpath.reverse()\r\n\tprint(*path)\r\n", "from heapq import heappush, heappop\r\nn, m = map(int, input().split())\r\ng = [[] for _ in range(n + 1)]\r\nfor _ in range(m):\r\n a, b, w = map(int, input().split())\r\n g[a].append((b, w))\r\n g[b].append((a, w))\r\nh, tt, parent = [(0, 1)], [2 ** 40] * (n + 1), [0] * (n + 1)\r\nwhile h:\r\n d, v = heappop(h)\r\n for u, w in g[v]:\r\n w += d\r\n if tt[u] > w:\r\n parent[u] = v\r\n tt[u] = w\r\n heappush(h, (w, u))\r\nif not parent[n]:\r\n exit(print(-1))\r\nres, v = [n], n\r\nwhile v != 1:\r\n v = parent[v]\r\n res.append(v)\r\nprint(' '.join(map(str, reversed(res))))", "import heapq\r\n\r\ndef dijkstra(vertice, vertice2):\r\n distancia[vertice] = 0\r\n predecessor[vertice] = -1\r\n heapq.heappush(heap, (0, vertice))\r\n\r\n while len(heap) > 0:\r\n hd = heapq.heappop(heap)\r\n v = hd[1]\r\n if visitados.get(v) == None:\r\n visitados[v] = True\r\n if v == vertice2:\r\n return True\r\n for e in adjacencia[v]:\r\n u = e[0]\r\n peso = e[1]\r\n if distancia[v] + peso < distancia[u]:\r\n distancia[u] = distancia[v] + peso\r\n predecessor[u] = v\r\n heapq.heappush(heap, (distancia[u], u))\r\n return False\r\n\r\nINF = 100000000000000000000000000000\r\nn_vertices, m_arestasm = map(int,input().split())\r\nadjacencia = [[] for i in range(n_vertices + 1)]\r\npredecessor = [-1 for i in range(n_vertices + 1)]\r\ndistancia = [INF for i in range(n_vertices + 1)]\r\nheap = []\r\nvisitados = {}\r\n\r\nfor i in range(m_arestasm):\r\n aresta = list(map(int, input().split()))\r\n a = aresta[0]\r\n b = aresta[1]\r\n peso = aresta[2]\r\n adjacencia[a].append((b, peso))\r\n adjacencia[b].append((a, peso))\r\n\r\nexisteCaminho = dijkstra(1, n_vertices)\r\n\r\ni = n_vertices\r\ncaminho = []\r\nif existeCaminho:\r\n while i != -1:\r\n caminho.append(i)\r\n i = predecessor[i]\r\n caminho.reverse()\r\n print(*caminho)\r\nelse:\r\n print(-1)", "from collections import defaultdict\r\nfrom heapq import heappop,heappush,heapify\r\nimport math\r\n\r\ngraph=defaultdict(list)\r\n\r\nn,m=map(int,input().split())\r\n\r\nfor i in range(m):\r\n a,b,w=map(int,input().split())\r\n graph[a].append([b,w])\r\n graph[b].append([a,w])\r\n \r\ndist=[math.inf]*(n+1)\r\nvisited=[0]*(n+1)\r\nprev_node=[-1]*(n+1)\r\n\r\ndist[1]=0\r\nvisited[1]=1\r\nheap=[(0,1,1)]\r\n\r\nwhile heap:\r\n\td,curr,prev=heappop(heap)\r\n\tif curr!=1 and visited[curr] != 1:\r\n\t\tprev_node[curr]=prev\r\n\tvisited[curr] = 1;\r\n\t\r\n\tfor neigh,w in graph[curr]:\r\n\t\tif visited[neigh]==0 and dist[neigh]>d+w:\r\n\t\t\tdist[neigh]=d+w\r\n\t\t\theappush(heap,(dist[neigh],neigh,curr))\r\n\r\nif dist[n]==math.inf:\r\n\tprint(\"-1\")\r\nelse:\r\n\tpath=[]\r\n\tcurr=n\r\n\twhile 1:\r\n\t\tpath.append(curr)\r\n\t\tcurr=prev_node[curr]\r\n\t\tif curr==-1:\r\n\t\t\tbreak\r\n\tprint(' '.join(map(str, reversed(path))))", "import heapq as h\n\ndef Dijkstra(n,m,graph):\n to_check = []\n parents = [0] * (n+1)\n paths = [float(\"inf\")] * (n+1)\n visited = [False] * (n+1)\n paths[1] = 0\n parents[1] = 1\n h.heappush(to_check,(0,1))\n while len(to_check) != 0:\n actual = h.heappop(to_check)[1]\n if visited[actual] == True:\n continue\n visited[actual] = True\n for verticle in graph[actual]:\n neighbour = verticle[1]\n cost = verticle[0]\n if paths[actual] + cost < paths[neighbour]:\n paths[neighbour] = paths[actual] + cost\n parents[neighbour] = actual\n h.heappush(to_check, (paths[neighbour],neighbour))\n return parents\n\ndef main():\n (n, m) = list(map(int,input().split()))\n \n graf = []\n for x in range(n+1):\n graf.append([])\n for line in range(m):\n data = list(map(int,input().split()))\n graf[data[0]].append((data[2],data[1]))\n graf[data[1]].append((data[2],data[0]))\n parents = Dijkstra(n,m,graf)\n v = n\n anserw = [str(v)]\n fail = False\n while v != 1:\n if parents[v] == 0:\n fail = True\n break\n anserw.append(str(parents[v]))\n v = parents[v]\n if not fail:\n to_print = reversed(anserw)\n print(\" \".join(to_print))\n else:\n print(\"-1\")\nmain()", "from heapq import *\r\nn,m=map(int,input().split())\r\ninf=10**18\r\np={}\r\nc={}\r\ng={}\r\nl={}\r\nfor i in range(1,1+n):\r\n p[i]=i\r\n g[i]=set()\r\n l[i]=inf\r\nl[1]=0\r\nfor i in range(m):\r\n x,y,w=map(int,input().split())\r\n g[x].add(y)\r\n g[y].add(x)\r\n c[(x,y)]=w\r\n c[(y,x)]=w\r\nq=[(0,1)]\r\nheapify(q)\r\nwhile q:\r\n a=heappop(q)[1]\r\n for i in g[a]:\r\n if i!=p[a] and l[a]+c[(a,i)]<l[i]:\r\n p[i]=a\r\n l[i]=l[a]+c[(a,i)]\r\n heappush(q,(l[i],i))\r\nif l[n]==inf:\r\n print(-1)\r\nelse:\r\n o=[n]\r\n while n!=1:\r\n n=p[n]\r\n o+=[n]\r\n print(*o[::-1])", "import heapq\r\n\r\nN = int(1e5 + 10)\r\nINF = int(1e18 + 10)\r\n\r\npar = [0] * (N)\r\ndis = [INF] * (N)\r\ng = [[] for i in range(N)]\r\n\r\ndef dijkstra(s, n):\r\n dis[s] = 0\r\n heap = [(0, s)]\r\n heapq.heapify(heap)\r\n\r\n while heap:\r\n cur, u = heapq.heappop(heap)\r\n if dis[u] < cur:\r\n continue\r\n for v, w in g[u]:\r\n if cur + w < dis[v]:\r\n dis[v] = cur + w\r\n par[v] = u\r\n heapq.heappush(heap, (dis[v], v))\r\n\r\nif __name__ == \"__main__\":\r\n n, m = list(map(int, input().split()))\r\n\r\n for i in range(m):\r\n u, v, w = list(map(int, input().split()))\r\n g[u].append((v, w))\r\n g[v].append((u, w))\r\n\r\n dijkstra(1, n)\r\n\r\n if dis[n] == INF:\r\n print(\"-1\")\r\n else:\r\n ans = [n]\r\n u = n\r\n while par[u] != 0:\r\n ans.append(par[u])\r\n u = par[u]\r\n ans.reverse()\r\n print(\" \".join(list(map(str, ans))))\r\n", "from heapq import *\r\nimport sys\r\ninput = sys.stdin.readline\r\nn, m = map(int, input().split())\r\ne = [[] for i in range(n+1)]\r\nfor i in range(m):\r\n a, b, w = map(int, input().split())\r\n e[a].append((b,w))\r\n e[b].append((a,w))\r\na = []\r\nheapify(a)\r\nheappush(a, (0, 1))\r\ninf = float('inf')\r\nd = [0,0]+[inf]*(n)\r\np = [0,0]+[0]*(n)\r\nwhile a:\r\n w, v = heappop(a)\r\n for nd, wt in e[v]:\r\n r = wt+w\r\n if r<d[nd]:\r\n p[nd] = v\r\n d[nd] = r\r\n heappush(a, (w+wt, nd))\r\nif d[n] == inf:\r\n print(-1)\r\nelse:\r\n x = p[n]\r\n ans = [n]\r\n while x:\r\n ans.append(x)\r\n x = p[x]\r\n print(*ans[::-1])\r\n", "import heapq\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef dijkstra(s):\r\n dist = [inf] * (n + 1)\r\n dist[s] = 0\r\n visit = [0] * (n + 1)\r\n parent = [-1] * (n + 1)\r\n p = []\r\n heapq.heappush(p, (dist[s], s))\r\n while p:\r\n d, u = heapq.heappop(p)\r\n if dist[u] < d:\r\n continue\r\n visit[u] = 1\r\n for v, c in G[u]:\r\n nd = dist[u] + c\r\n if not visit[v] and nd < dist[v]:\r\n dist[v] = nd\r\n parent[v] = u\r\n heapq.heappush(p, (dist[v], v))\r\n return dist, parent\r\n\r\nn, m = map(int, input().split())\r\nG = [[] for _ in range(n + 1)]\r\nfor _ in range(m):\r\n a, b, w = map(int, input().split())\r\n G[a].append((b, w))\r\n G[b].append((a, w))\r\ninf = pow(10, 12) + 1\r\ndist, parent = dijkstra(1)\r\nif parent[n] == -1:\r\n ans = [-1]\r\nelse:\r\n ans = [n]\r\n i = n\r\n while i ^ 1:\r\n i = parent[i]\r\n ans.append(i)\r\n ans.reverse()\r\nsys.stdout.write(\" \".join(map(str, ans)))", "from heapq import heappush, heappop\r\n\r\nclass Vertex:\r\n def __init__(self, val, dist=0, prev=None, edges=None):\r\n self.val = val\r\n self.prev = prev\r\n self.dist = dist\r\n self.edges = edges\r\n self.visited = False\r\n \r\n def __lt__(self, value):\r\n return self.dist < value.dist\r\n def __le__(self, value):\r\n return self.dist <= value.dist\r\n def __gt__(self, value):\r\n return self.dist > value.dist\r\n def __ge__(self, value):\r\n return self.dist >= value.dist\r\n def __eq__(self, value):\r\n if not value: return False\r\n return self.dist == value.dist\r\n def __repr__(self):\r\n return str(self.val) + \", dist: \" + \\\r\n str(self.dist) + \", prev: \" + \\\r\n str(self.prev) + \" vis? \" + \\\r\n str(self.visited)\r\n \r\ndef backtrack(graph, goal):\r\n path = []\r\n while goal != None:\r\n goal = goal.val\r\n path.append(str(goal))\r\n goal = graph[goal].prev\r\n return ' '.join(path[::-1])\r\n\r\n \r\ndef dijkstra(graph, goal):\r\n global infinity\r\n if len(graph[goal].edges) == 0:\r\n return -1\r\n \r\n graph[1].dist = 0\r\n pq = [graph[1]]\r\n \r\n while len(pq):\r\n curr = heappop(pq)\r\n \r\n if curr.val == goal:\r\n # print(curr.dist)\r\n return backtrack(graph, curr)\r\n if not curr.visited:\r\n # print(\"currently exploring:\", curr)\r\n curr.visited = True\r\n \r\n for w, cost in curr.edges:\r\n dist_to_w = curr.dist + cost\r\n vertex_w = graph[w]\r\n if vertex_w.dist == infinity or vertex_w.dist > dist_to_w:\r\n graph[w].dist = dist_to_w\r\n graph[w].prev = curr\r\n \r\n if not vertex_w.visited:\r\n heappush(pq, vertex_w)\r\n \r\n \r\n return -1\r\n \r\n \r\nv, e = map(int, input().split())\r\n\r\n# each entry is vertex : [(v1, cost1), (v2, cost2), ...]\r\ninfinity = -1\r\ngraph = {x : Vertex(x, infinity, None, []) for x in range(1, v+1)}\r\n\r\nfor _ in range(e):\r\n u, w, cost = map(int, input().split())\r\n graph[u].edges.append((w, cost))\r\n graph[w].edges.append((u, cost))\r\n\r\nprint(dijkstra(graph, v))", "# author: violist\n# created: 24.05.2022 15:54:52\n\nimport sys\nimport heapq\ninput = sys.stdin.readline\n\ninf = 1 << 64\n\ndef dijkstra(g, s, d):\n dist = [inf] * len(g)\n dist[0] = 0\n parents = [-1] * len(g)\n queue = []\n heapq.heappush(queue, (0, s))\n found = 0\n while (queue):\n w, n = heapq.heappop(queue)\n if (n == d):\n found = 1 \n break\n for new_n, new_w in g[n]:\n if (new_w + w < dist[new_n]):\n dist[new_n] = new_w + w\n parents[new_n] = n\n heapq.heappush(queue, (new_w + w, new_n))\n cur = n\n path = []\n while (cur != -1):\n path.append(cur)\n cur = parents[cur]\n return [-1] if (not found) else [i + 1 for i in path[::-1]]\n\nn, m = map(int, input().split())\ng = [[] for i in range(n)]\nfor i in range(m):\n a, b, w = map(int, input().split())\n a -= 1; b -= 1\n g[a].append((b, w))\n g[b].append((a, w))\nprint(*dijkstra(g, 0, n - 1))\n", "import heapq\nfrom math import inf\n\nnum_nodes, num_edges = map(int, input().split())\nd = [0] + [inf] * num_nodes\nvisited = [1] * num_nodes\ngraph = [[] for i in range(num_nodes)]\n\nfor i in range(num_edges):\n node1, node2, weight = map(int, input().split())\n graph[node1 - 1].append((node2 - 1, weight))\n graph[node2 - 1].append((node1 - 1, weight))\n\npriority_queue = [(d[0], 0)]\npred = [inf] * num_nodes\n\nwhile visited[num_nodes - 1] and priority_queue:\n u = heapq.heappop(priority_queue)[1]\n if visited[u]:\n visited[u] = 0\n for v, w in graph[u]:\n if d[v] > d[u] + w:\n d[v] = d[u] + w\n pred[v] = u\n heapq.heappush(priority_queue, (d[v], v))\n\nif pred[num_nodes - 1] == inf:\n print(-1)\nelse:\n x, path = num_nodes - 1, []\n while x != inf:\n path += [x + 1]\n x = pred[x]\n print(*path[::-1])\n \t \t\t\t \t\t\t\t \t\t\t\t \t\t \t\t\t \t", "from heapq import *\r\nINF = 1 << 60\r\n\r\nn, m = map(int, input().split())\r\ngrafo = [[] for _ in range(n)]\r\ndistancia = [0] + [INF] * n\r\nvertice_anterior = [-1] * n\r\nq = [(0, 0)]\r\nfor i in range(m):\r\n a, b, w = map(int, input().split())\r\n grafo[a-1] += [(w, b-1)]\r\n grafo[b-1] += [(w, a-1)]\r\nwhile q:\r\n a = heappop(q)[1]\r\n for adj in grafo[a]:\r\n w, b = distancia[a] + adj[0], adj[1]\r\n if w < distancia[b]:\r\n distancia[b], vertice_anterior[b] = w, a\r\n heappush(q, (distancia[b], b))\r\nif distancia[n-1] == INF:\r\n print(-1);\r\nelse:\r\n x, y = n - 1, []\r\n while x != -1:\r\n y += [x + 1]\r\n x = vertice_anterior[x]\r\n y.reverse()\r\n print(' '.join(map(str, y)))\r\n", "from collections import deque as dq\nimport heapq as hq\n \nn,m=map(int,input().split())\ng=[[] for i in range(n)]\n \nfor i in range(m):\n a,b,c=map(int,input().split())\n g[a-1].append((b-1,c))\n g[b-1].append((a-1,c))\n \nMAX=10**11\n \nnodescost=[MAX]*n\nnodescost[0]=0\nL=[]\nA=[-1]*(n+1)\nhq.heappush(L,(0,0))\n \nwhile len(L)!=0:\n v=hq.heappop(L)\n for x in g[v[1]]:\n if v[0]+x[1]<=nodescost[x[0]]:\n nodescost[x[0]]=v[0]+x[1]\n hq.heappush(L,(nodescost[x[0]],x[0]))\n A[x[0]+1]=v[1]+1\n \nans=[n]\nwhile A[ans[-1]]!=-1:\n ans+=[A[ans[-1]]]\n \nif A[n]!=-1:\n ans.reverse()\n print(' '.join(map(str, ans)))\nelse:\n print(-1)\n \t \t \t \t\t\t \t \t \t", "from heapq import heappush , heappop\r\nimport sys\r\n\r\ninput=sys.stdin.readline\r\nn,m = map(int, input().split())\r\ndat = [[] for i in range(n+1)]\r\nfor i in range(1,m+1):\r\n\ta,b,w = map(int, input().split())\r\n\tdat[a].append([b,w])\r\n\tdat[b].append([a,w])\r\n\r\ndis = [float('inf') for i in range(n+1)]\r\npath = [0 for i in range(n+1)]\r\nq = [(0,1)]\r\n\r\nwhile q:\r\n\ts1,s2 = heappop(q)\r\n\tfor b,w in dat[s2]:\r\n\t\tif dis[b]>s1+w:\r\n\t\t\tpath[b] = s2\r\n\t\t\tdis[b] = s1+w\r\n\t\t\theappush(q , (dis[b] , b))\r\n\t\t\t\r\nif path[n]==0:\r\n\tprint('-1')\r\nelse:\r\n\tret = [n]\r\n\ti = n\r\n\twhile i>1:\r\n\t\ti = path[i]\r\n\t\tret.append(i)\r\n\r\n\tprint(*ret[::-1])\r\n\r\n", "# =============== author: kuanc | created: 05/05/22 03:17:10 =============== #\nfrom sys import setrecursionlimit, stdin, stdout, stderr\nfrom bisect import bisect_left, bisect_right\nfrom collections import defaultdict, deque, Counter\nfrom itertools import accumulate, combinations, permutations, product\nfrom functools import lru_cache, cmp_to_key, reduce\nfrom heapq import heapify, heappush, heappop, heappushpop, heapreplace\n# from pypyjit import set_param\n# set_param(\"max_unroll_recursion=-1\")\n# setrecursionlimit(300005)\nINF = 1 << 60\nMOD = 10 ** 9 + 7\n# MOD = 998244353\ninput = lambda: stdin.readline().rstrip(\"\\r\\n\")\ndbg = lambda *A, **M: stderr.write(\"\\033[91m\" + \\\n M.get(\"sep\", \" \").join(map(str, A)) + M.get(\"end\", \"\\n\") + \"\\033[0m\")\n# ============================ START OF MY CODE ============================ #\n\ndef solve():\n def dijkstra(n, G, start):\n # O(V + ElogV)\n dist = [-1 for _ in range(n)]\n prev = [-1 for _ in range(n)]\n dist[start] = 0\n pq = [(0, start)] # (distance, node)\n while pq:\n d, node = heappop(pq)\n if d > dist[node]:\n continue\n d = dist[node]\n for (neigh, neigh_d) in G[node]:\n if dist[neigh] == -1 or d + neigh_d < dist[neigh]:\n dist[neigh] = d + neigh_d\n prev[neigh] = node\n heappush(pq, (dist[neigh], neigh))\n return dist, prev\n\n def path_restore_1d(prev, start, end):\n path = []\n cur = end\n while cur != -1:\n path.append(cur)\n cur = prev[cur]\n path.reverse()\n return path\n\n N, M = map(int, input().split())\n\n adj = defaultdict(list)\n for _ in range(M):\n u, v, w = map(int, input().split())\n u -= 1; v -= 1\n adj[u].append((v, w))\n adj[v].append((u, w))\n\n D, P = dijkstra(N, adj, 0)\n if D[N - 1] == -1:\n print(-1)\n else:\n path = path_restore_1d(P, 0, N - 1)\n print(*[v + 1 for v in path])\n\n\nif __name__ == \"__main__\":\n solve()\n", "from heapq import heappush, heappop\nfrom sys import stdin, stdout\nread, write = stdin.readline, stdout.write\n\nn, m = map(int, read().split())\n\ng = [[] for i in range(n + 1)]\n\nfor _ in range(m):\n init, end, cost = map(int, read().split())\n g[init].append((end, cost))\n g[end].append((init, cost))\n\nheap = [(0,1)]\nlow_costs = [float(\"inf\")] * (n + 1)\nparent = [0] * (n + 1)\n\nwhile heap:\n c, init = heappop(heap)\n for end, current_cost in g[init]:\n current_cost += c\n if low_costs[end] > current_cost:\n parent[end] = init\n low_costs[end] = current_cost\n heappush(heap, (current_cost, end))\n\nif(not parent[n]):\n print(-1)\n\nelse:\n path = [n]\n while n > 1:\n n = parent[n]\n path.append(n)\n \n print(*path[::-1])\n\n\t\t\t\t\t \t \t \t\t \t \t \t\t \t", "import heapq\r\nimport pdb\r\n\r\nclass priority_queue:\r\n def __init__(self):\r\n self.pq = []\r\n def push(self, item):\r\n heapq.heappush(self.pq, item)\r\n def pop(self):\r\n return heapq.heappop(self.pq)\r\n def __bool__(self):\r\n return bool(len(self.pq))\r\n \r\nclass graph:\r\n def __init__(self, n):\r\n self.n = n\r\n self.adj = [[] for _ in range(n)]\r\n def adde(self, u, v, w):\r\n self.adj[u].append([v,w])\r\n self.adj[v].append([u,w])\r\n def dijkstra(self, s):\r\n dist = [float('inf')] * self.n\r\n pred = [-1] * self.n\r\n visited = [False] * self.n\r\n dist[s] = 0\r\n remaining = priority_queue()\r\n remaining.push((0, s))\r\n #pdb.set_trace()\r\n while remaining:\r\n d, u = remaining.pop()\r\n if visited[u]: continue\r\n visited[u] = True\r\n for v,w in self.adj[u]:\r\n new_d = d + w\r\n if new_d < dist[v]:\r\n dist[v] = new_d\r\n pred[v] = u\r\n remaining.push((new_d, v)) \r\n return dist, pred\r\n \r\n \r\n \r\nif __name__ == \"__main__\":\r\n n, m = [int(x) for x in input().split()]\r\n g = graph(n+1)\r\n for _ in range(m):\r\n a, b, w = [int(x) for x in input().split()]\r\n g.adde(a,b,w)\r\n dist, pred = g.dijkstra(1)\r\n path = [n]\r\n while True:\r\n pnode = path[-1]\r\n nnode = pred[pnode]\r\n if nnode == -1:\r\n if pnode != 1:\r\n path = [-1]\r\n break\r\n path.append(nnode)\r\n print(\" \".join(reversed([str(x) for x in path])))\r\n \r\n \r\n", "import heapq\r\nls = input().split(\" \")\r\nn = int(ls[0])\r\nm = int(ls[1])\r\nadj = dict()\r\nfor i in range(1,n+1):\r\n adj[i] = dict()\r\n \r\nfor i in range(m):\r\n ls = input().split(\" \")\r\n u = int(ls[0])\r\n v = int(ls[1])\r\n w = int(ls[2])\r\n if(u != v):\r\n if(v in adj[u]):\r\n adj[u][v] = min(w, adj[u][v])\r\n adj[v][u] = min(w, adj[v][u]) \r\n else:\r\n adj[u][v] = w\r\n adj[v][u] = w\r\n\r\nfor i in adj:\r\n ls = []\r\n for j in adj[i]:\r\n ls.append( (j,adj[i][j]) )\r\n adj[i]= ls\r\n\r\ndef shortestPath( src,v):\r\n # Create a priority queue to store vertices that\r\n # are being preprocessed\r\n pq = []\r\n heapq.heappush(pq, (0, src))\r\n \r\n # Create a vector for distances and initialize all\r\n # distances as infinite (INF)\r\n dist = [float('inf')] * (v+1)\r\n parent = [-1]*(v+1)\r\n parent[1] = -1\r\n dist[src] = 0\r\n while pq:\r\n # The first vertex in pair is the minimum distance\r\n # vertex, extract it from priority queue.\r\n # vertex label is stored in second of pair\r\n d, u = heapq.heappop(pq)\r\n \r\n # 'i' is used to get all adjacent vertices of a\r\n # vertex\r\n for v, weight in adj[u]:\r\n # If there is shorted path to v through u.\r\n if dist[v] > dist[u] + weight:\r\n # Updating distance of v\r\n dist[v] = dist[u] + weight\r\n parent[v] = u\r\n heapq.heappush(pq, (dist[v], v))\r\n \r\n # Print shortest distances stored in dist[]\r\n val = parent[n]\r\n ans = []\r\n if(val == -1):\r\n ans.append(-1)\r\n else:\r\n ans.append(n)\r\n while(val != -1):\r\n ans.append(val)\r\n val = parent[val]\r\n\r\n for i in ans[::-1]:\r\n print(i , end = \" \")\r\n \r\n\r\nshortestPath(1, n )", "import heapq\r\n\r\nvertices, edges = [int(x) for x in input().strip().split()]\r\n\r\nnodeDict = {}\r\n\r\nfor y in range(vertices + 1):\r\n\tnodeDict[y] = {}\r\n\r\nfor x in range(edges): # fills dictionary with vertices and edge weights\r\n\ta, b, w = [int(x) for x in input().strip().split()]\r\n\tif a not in nodeDict[b] or nodeDict[b][a] > w:\t\r\n\t\tnodeDict[b][a] = w\r\n\tif b not in nodeDict[a] or nodeDict[a][b] > w:\r\n\t\tnodeDict[a][b] = w\r\n\r\nINF = float(\"inf\")\r\n\r\nqueue = []\r\nheapq.heappush(queue, (0, vertices))\r\nprevious = [-1]*(vertices+1) # creates previous list for parsing at the end\r\ndistance = [INF]*(vertices+1) # infinite distances to compare with\r\nvisited = [False]*(vertices+1) # visited list\r\ndistance[vertices] = 0 # sets distance for origin to 0\r\n\r\nwhile len(queue) > 0: # continues till the queue is empty\r\n\td, vertex = heapq.heappop(queue) # pops vertex and distance off the queue\r\n\tif visited[vertex]: continue # if already visited, skips\r\n\tvisited[vertex] = True # marks vertex as visited\r\n\r\n\tif vertex == 1: break # if finds path back to first vertex, ends\r\n\r\n\tfor endVertex in nodeDict[vertex]: # checks for each adjacent vertex\r\n\t\t# print(distance[vertex])\r\n\t\t# print(nodeDict[vertex])\r\n\t\talt = distance[vertex] + nodeDict[vertex][endVertex] # sums the distance to the vertex with the weight between both vertices\r\n\t\tif alt < distance[endVertex]: # if sum is less than current distance\r\n\t\t\tdistance[endVertex] = alt # sets the distance to the new value\r\n\t\t\tprevious[endVertex] = vertex # sets the end vertices' last vertex for parsing\r\n\t\t\theapq.heappush(queue, (alt, endVertex)) # pushes distance and end vertex on the queue\r\n\r\np = 1\r\npath = []\r\nwhile p != -1:\r\n\tpath.append(str(p))\r\n\tp = previous[p]\r\n\r\nif path[-1] != str(vertices): print(-1) # parses until the path is found\r\nelse: print(\" \".join(path))", "from collections import defaultdict\r\nimport heapq\r\nimport sys\r\ninput=sys.stdin.readline\r\ndef get_ints():\r\n return map(int,input().strip().split())\r\ndef get_list():\r\n return list(map(int,input().strip().split()))\r\ndef get_string():\r\n return input().strip()\r\nI=1<<60\r\nn,m=get_ints()\r\ngraph=defaultdict(list)\r\n \r\nfor _ in range(m):\r\n a,b,w=get_ints()\r\n graph[a-1].append((w,b-1))\r\n graph[b-1].append((w,a-1))\r\ndist=[0]+[I]*(n)\r\npath=[-1]*n\r\nminheap=[(0,0)]\r\n \r\nwhile minheap:\r\n u=heapq.heappop(minheap)[1]\r\n \r\n for node in graph[u]:\r\n temp,data=dist[u]+node[0],node[1]\r\n if(temp<dist[data]):\r\n dist[data],path[data]=temp,u\r\n heapq.heappush(minheap,(dist[data],data))\r\nif dist[n-1]==I:\r\n print(-1)\r\nelse:\r\n x,y=n-1,[]\r\n while x!=-1:\r\n y+=[x+1]\r\n x=path[x]\r\n y.reverse()\r\n print(\" \".join(map(str,y)))", "from sys import stdin, stdout\r\nfrom collections import deque\r\nfrom heapq import heappush, heappop\r\n\r\na = list(map(int, stdin.readline().split()))\r\nm = a[0]\r\npq = []\r\ndist = [10**12] * m\r\nvisited = [False]* m\r\ngraf = [[] for i in range(m)]\r\nsuly = []\r\nstart = 0\r\ndist[start] = 0\r\nprev = [0] * m\r\nprev[start] = -1\r\nmo = []\r\nready = 0\r\n\r\nfor x in range(a[1]):\r\n elem = list(map(int, stdin.readline().split()))\r\n elem[0]-=1\r\n elem[1]-=1\r\n graf[elem[0]].append((elem[1], elem[2]))\r\n graf[elem[1]].append((elem[0], elem[2]))\r\n\r\nheappush(pq, (0, start))\r\nwhile len(pq) > 0:\r\n d, p = heappop(pq)\r\n if visited[p] == True:\r\n continue\r\n visited[p] = True\r\n for i in range(len(graf[p])):\r\n v = graf[p][i][0]\r\n s = graf[p][i][1]\r\n if dist[v] > dist[p] + s:\r\n dist[v] = dist[p] + s\r\n prev[v] = p\r\n heappush(pq, (dist[v], v))\r\n\r\nx = a[0]-1\r\nwhile x != -1:\r\n mo.append(x)\r\n x = prev[x]\r\n\r\nif visited[m-1] == False:\r\n ready = -1;\r\nfor x in range(len(mo)-1, -1, -1):\r\n if ready == 0:\r\n print(mo[x] + 1, end = ' ')\r\n else:\r\n print(-1)\r\n break", "from heapq import heappop, heappush\n \ndef dijkstra(graph, start=1):\n dist, parents = [float('inf')] * (n+1), [-1] * (n+1)\n dist[start] = 0\n \n queue = [(0, start)]\n while queue:\n wei, vert = heappop(queue)\n if wei == dist[vert]:\n for dest, w in graph[vert]:\n if w + wei < dist[dest]:\n dist[dest], parents[dest] = w + wei, vert\n heappush(queue, (w + wei, dest))\n \n return dist, parents\n \n \n \nn, m = map(int, input().split())\ngraph = [set() for _ in range(n+1)]\nfor i in range(m):\n v1, v2, w = map(int, input().split())\n graph[v1].add((v2, w))\n graph[v2].add((v1, w))\n \n_, parents = dijkstra(graph)\nif parents[n] == -1:\n print(-1)\nelse:\n res, parent = [], n\n while parent != parents[0]:\n res.append(parent)\n parent = parents[parent]\n res.reverse()\n print(*res)\n", "import heapq\r\nn, m = map(int, input().split())\r\nadj = {}\r\nd = {}\r\nfor i in range(1, n+1):\r\n adj[i] = []\r\n d[i] = float('inf')\r\nd[1] = 0\r\n \r\nfor _ in range(m):\r\n a, b, w = map(int, input().split())\r\n adj[a].append((b, w))\r\n adj[b].append((a, w))\r\n\r\nq = []\r\nheapq.heappush(q, (0, 1))\r\n\r\np = {}\r\nwhile q:\r\n dist, u = heapq.heappop(q)\r\n #print(dist, u)\r\n for v, w in adj[u]:\r\n #print(v, w)\r\n if d[v]>dist+w:\r\n d[v] = d[u]+w\r\n p[v] = u\r\n heapq.heappush(q, (d[v], v))\r\nif d[n]!=float('inf'):\r\n ans = [n]\r\n x = n\r\n while x!=1:\r\n x = p[x]\r\n ans.append(x)\r\n ans = ans[::-1]\r\n print(*ans)\r\nelse:\r\n print(-1)", "#!/usr/bin/env python3\nfrom heapq import heappush, heappop\nclass MinHeap:\n def __init__(self):\n self.heap = []\n\n\n def insertKey(self, k):\n heappush(self.heap, k)\n\n\n def extractMin(self):\n return heappop(self.heap)\n\n\n def len(self):\n return len(self.heap)\n\n\nfrom collections import defaultdict\nfrom math import inf as oo\n\nn, m = map(int, input().split())\n\nadj = [[] for _ in range(n+1)]\nfor _ in range(m):\n i, j, k = map(int, input().split())\n adj[i].append((j, k))\n adj[j].append((i, k))\n\nd = [oo] * (n+1)\nv = [False] * (n+1)\np = [oo] * (n+1)\n\nq = MinHeap()\nq.insertKey((0, 1))\nd[1] = 0\nwhile (q.len()):\n _, c = q.extractMin()\n if not v[c]:\n v[c] = True\n for nn, nd in adj[c]:\n if d[c] + nd < d[nn]:\n d[nn] = d[c] + nd\n p[nn] = c\n q.insertKey((d[nn], nn))\n\ni = n\npath = [i]\nwhile(i != oo):\n i = p[i]\n path.append(i)\n\nr = path[-2::-1]\nif r[0] != 1:\n print(-1)\nelse:\n print(*r)", "from heapq import heappop, heappush\n\ndef dijkstra(adj, start):\n # Returns a list of min-distances from start.\n # (and predecessors!)\n # -1 if it is infinity.\n n = len(adj)\n dist = [-1] * n\n pred = [-1] * n\n heap = []\n\n dist[start] = 0\n heappush(heap, (0, start))\n\n while heap:\n cur_dist, cur_v = heappop(heap)\n if cur_dist != dist[cur_v]:\n continue\n for next_v, next_w in adj[cur_v]:\n if dist[next_v] == -1 or next_w + cur_dist < dist[next_v]:\n pred[next_v] = cur_v\n dist[next_v] = next_w + cur_dist\n heappush(heap, (dist[next_v], next_v))\n\n return dist, pred\n\n\ndef get_path(pred, end):\n if pred[end] == -1:\n return []\n out = [end]\n while pred[end] != -1:\n out.append(pred[end])\n end = pred[end]\n out.reverse()\n return out\n\nn, m = map(int, input().split())\nadj = [[] for _ in range(n)]\n\nfor _ in range(m):\n a, b, w = map(int, input().split())\n a -= 1\n b -= 1\n adj[a].append((b, w))\n adj[b].append((a, w))\n\ndist, pred = dijkstra(adj, 0)\n\npath = get_path(pred, n-1)\n\nif path:\n print(*[x+1 for x in path])\nelse:\n print(-1)\n", "import sys, heapq\n\nn, m = [int(x) for x in sys.stdin.readline().split()]\ne = {} # primary dictionary\nfor i in range(1, n+1):\n e[i] = {} # secondary dictionary\n\nfor i in range(m):\n v, u, w = [int(x) for x in sys.stdin.readline().split()]\n \n if not u in e[v] or e[v][u] > w: \n e[v][u] = w\n\n if not v in e[u] or e[u][v] > w:\n e[u][v] = w\n\nINF = 1000000000000\n\npq = []\nheapq.heappush(pq, (0, n))\nprev = [-1]*(n+1)\ndist = [INF]*(n+1)\nvis = [False]*(n+1)\ndist[n] = 0\n\n\nwhile len(pq) > 0:\n d, v = heapq.heappop(pq)\n if vis[v]: \n continue\n vis[v] = True\n \n if v == 1: \n break\n \n for u in e[v]:\n alt = dist[v] + e[v][u]\n if alt <= dist[u]:\n dist[u] = alt\n prev[u] = v\n heapq.heappush(pq, (alt, u))\n\np = 1\npath = []\nwhile p != -1:\n path.append(str(p))\n p = prev[p]\nif path[-1] != str(n): \n print(-1)\nelse: \n print(\" \".join(path))\n\n\n\t\t\t \t \t\t \t\t\t \t \t\t \t \t\t\t\t", "import heapq as hq\r\ndef dijsktra(graph,n):\r\n vis=[False]*n\r\n dist=[float('inf')]*n\r\n dist[n-1]=0\r\n parent=[None]*n\r\n q=[(0,n-1)]\r\n while q:\r\n w,v=hq.heappop(q)\r\n if not vis[v]:\r\n vis[v]=True\r\n if dist[v]<w:\r\n continue\r\n for ne,new in graph[v]:\r\n if not vis[ne]:\r\n di=dist[v]+new\r\n if di<dist[ne]:\r\n dist[ne]=di\r\n parent[ne]=v\r\n hq.heappush(q,(di,ne))\r\n if v==0:\r\n at=0\r\n print(at+1,end=\" \")\r\n while True:\r\n at=parent[at]\r\n if at:\r\n print(at+1,end=\" \")\r\n else:\r\n print()\r\n return\r\n print(-1)\r\n return\r\n \r\n\r\nif __name__==\"__main__\":\r\n\r\n n,m=map(int,input().split())\r\n graph={i:[] for i in range(n)}\r\n for j in range(m):\r\n u,v,w=map(int,input().split())\r\n u-=1\r\n v-=1\r\n graph[u].append((v,w))\r\n graph[v].append((u,w))\r\n dijsktra(graph,n)", "from math import inf\r\nimport heapq\r\nn,m=map(int,input().split())\r\nd=[0]+[inf]*n\r\nvis=[1]*n\r\nli=[[] for _ in range(n)]\r\nfor _ in range(m):\r\n x,y,z=map(int,input().split())\r\n li[x-1].append((y-1,z))\r\n li[y-1].append((x-1,z))\r\nmang=[(d[0],0)]\r\ntrace=[inf]*n\r\nwhile vis[n-1] and mang:\r\n u=heapq.heappop(mang)[1]\r\n if vis[u]:\r\n vis[u]=0\r\n for v,w in li[u]:\r\n if d[v]>d[u]+w:\r\n d[v]=d[u]+w\r\n trace[v]=u\r\n heapq.heappush(mang,(d[v],v))\r\nif trace[n-1]==inf:print(-1)\r\nelse:\r\n x, y = n - 1, []\r\n while x != inf:\r\n y += [x + 1] \r\n x = trace[x]\r\n y.reverse()\r\n print(*y)", "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\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\n\r\nG = defaultdict(list)\r\ninf = float('inf') \r\n\r\ndef addEdge(a,b,w):\r\n G[a].append([b,w])\r\n G[b].append([a,w])\r\n \r\ndef difun(N,source):\r\n dist = [inf] *(N+1)\r\n path = [i for i in range(N+1)]\r\n pq = [[0,source]]\r\n heapq.heapify(pq)\r\n dist[source] = 0\r\n while pq:\r\n curr_d,curr = heapq.heappop(pq)\r\n for i,j in G[curr]:\r\n if curr_d + j < dist[i]:\r\n dist[i] = curr_d + j\r\n path[i] = curr\r\n heapq.heappush(pq,[dist[i],i])\r\n return dist,path\r\n\r\nN,M = ilele()\r\nfor i in range(M):\r\n a,b,c = ilele()\r\n addEdge(a,b,c)\r\n\r\nsource = 1;desti = N\r\ndist,path = difun(N,source)\r\nif dist[N] == float('inf'):\r\n print(-1)\r\nelse:\r\n p = [desti]\r\n x = desti\r\n while x != source:\r\n x = path[x]\r\n p.append(x)\r\n print(*p[::-1])\r\n\r\n", "import heapq\n\ndef dijkstra(graph, s, t):\n\tprevMap = {}\n\tq = []\n\tq.append((0, s, -1))\n\t\n\twhile len(q) > 0:\n\t\tl, curr, prev = heapq.heappop(q)\n\t\tif curr in prevMap:\n\t\t\tcontinue\n\t\t\n\t\tprevMap[curr] = prev\n\t\t\n\t\tif curr == t:\n\t\t\tans = []\n\t\t\twhile curr != -1:\n\t\t\t\tans.append(str(curr))\n\t\t\t\tcurr = prevMap[curr]\n\t\t\t\n\t\t\tans = ans[::-1]\n\t\t\t\n\t\t\treturn \" \".join(ans)\n\t\t \n\t\tfor v in graph[curr].keys():\n\t\t\tif v not in prevMap:\n\t\t\t\theapq.heappush(q, (l + graph[curr][v], v, curr))\n\t\n\treturn \"-1\"\n\t\nn, m = (int(x) for x in input().split())\n\t\ngraph = {}\n\nfor i in range(1, n + 1):\n\tgraph[i] = {}\n\nfor _ in range(m):\n\ta, b, w = (int(x) for x in input().split())\n\t\n\tif a != b:\n\t\tgraph[a][b] = min(graph[a].get(b, float(\"inf\")), w)\n\t\tgraph[b][a] = min(graph[b].get(a, float(\"inf\")), w)\n\t\nprint(dijkstra(graph, 1, n))\n", "import heapq\r\nimport sys\r\n\r\n\r\ndef dijktras(graph, source):\r\n vis = [False] * (len(graph) + 1) # initializing each node as unvisited\r\n dist = [sys.maxsize] * (len(graph) + 1) # initializing distance of source to all vertices as +infinity\r\n par = [-1] * (len(graph) + 1) # initializing parent of each node as -1\r\n mnpq = [] # minimum priority queue\r\n dist[source] = 0 # setting distance of source as 0\r\n heapq.heappush(mnpq, (0, source)) # pushing (distance from source, node) into mnpq\r\n while mnpq:\r\n w1, cur = heapq.heappop(mnpq) # popping minimum distance from source,node\r\n if vis[cur]:\r\n continue\r\n for v, w in graph[cur]: # if not visited, iterate through all neighbours of current node\r\n if vis[v]:\r\n continue\r\n if (w + dist[cur]) < dist[\r\n v]: # if (weight between cur and v + dist of cur from source) < dist of v from source\r\n dist[v] = w + dist[cur] # update dist of v\r\n par[v] = cur # update par of v as cur\r\n heapq.heappush(mnpq, (dist[v], v)) # push updated dist, node v into mnpq\r\n vis[cur] = True # mark cur visited\r\n return par\r\n\r\n\r\nnv, ne = map(int, input().split()) # reading number of vertices,edges\r\ngraph = {}\r\nfor i in range(1, nv + 1): # initializing neighbour of each node as empty\r\n graph[i] = graph.get(i, [])\r\nfor i in range(ne): # reading node1,node2,dist between them and updating into graph\r\n u, v, w = map(int, input().split())\r\n graph[u].append((v, w))\r\n graph[v].append((u, w))\r\nd = dijktras(graph, 1) # calling algorithm with source as 1\r\nif d[-1] == -1:\r\n print(-1)\r\n exit()\r\npath = [nv]\r\ncur = nv\r\nwhile cur != 1: # tracing the path by backtracking the parent\r\n path.append(d[cur])\r\n cur = d[cur]\r\nprint(*path[::-1])\r\n", "import heapq\n\ndef dijkstra(n, edges):\n graph = [[] for _ in range(n+1)]\n for a, b, w in edges:\n graph[a].append((b, w))\n graph[b].append((a, w))\n\n distance = [float('inf')] * (n+1)\n distance[1] = 0\n parent = [-1] * (n+1)\n\n queue = [(0, 1)]\n while queue:\n d, node = heapq.heappop(queue)\n if distance[node] < d:\n continue\n for next_node, w in graph[node]:\n if d + w < distance[next_node]:\n distance[next_node] = d + w\n parent[next_node] = node\n heapq.heappush(queue, (distance[next_node], next_node))\n\n if distance[n] == float('inf'):\n return -1\n\n # Retrieve the shortest path\n path = []\n curr = n\n while curr != -1:\n path.append(curr)\n curr = parent[curr]\n path.reverse()\n\n return path\n\ndef main():\n n, m = map(int, input().split())\n edges = []\n for _ in range(m):\n a, b, w = map(int, input().split())\n edges.append((a, b, w))\n shortest_path = dijkstra(n, edges)\n if shortest_path == -1:\n print(shortest_path)\n else:\n print(\" \".join(map(str, shortest_path)))\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\t \t \t", "import math\r\nimport heapq\r\nimport sys\r\nfrom collections import deque\r\nimport time\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\nn,m=invr()\r\nd={}\r\nv=[0]*n\r\nfor i in range(1,n+1):\r\n d[i]=[]\r\nfor i in range(m):\r\n a,b,w=invr()\r\n d[a].append([b,w])\r\n d[b].append([a,w])\r\nout={}\r\nc={}\r\nc[1]=0\r\nfor i in range(2,n+1):\r\n c[i]=float('inf')\r\nqueue=deque()\r\nx=[]\r\nheapq.heappush(x,(0,1,-1))\r\nprev=-1\r\nwhile True:\r\n a=heapq.heappop(x)\r\n s=a[1]\r\n if v[s-1]==1:\r\n continue\r\n v[s-1]=1\r\n c[s]=a[0]\r\n out[s]=a[2]\r\n if s==n:\r\n break\r\n for i in d[s]:\r\n if not v[i[0]-1]:\r\n if a[0]+i[1]<c[i[0]]:\r\n heapq.heappush(x,(a[0]+i[1],i[0],s))\r\n if len(x)==0:\r\n print(-1)\r\n exit()\r\na=[]\r\nx=n\r\nwhile out[x]!=-1:\r\n a.append(x)\r\n x=out[x]\r\na.append(1)\r\na.reverse()\r\nprint(*a)\r\n", "import heapq\nfrom collections import defaultdict\n\ndef solve(n):\n distances = [10**18 for i in range(n + 5)]\n Q = list()\n heapq.heappush(Q, (0, 1))\n paths[1] = 1\n distances[1] = 0\n while Q:\n c, u = heapq.heappop(Q)\n if u == n:\n return c\n if distances[u] < c:\n continue\n for w, v in Graph[u]:\n if distances[v] > c + w:\n distances[v] = c + w\n heapq.heappush(Q, (distances[v], v))\n paths[v] = u\n return -1\n\nGraph = defaultdict(list)\npaths = defaultdict(int)\narr = list()\n\nn, m = map(int, input().split())\n\nfor i in range(m):\n x, y, c = map(int, input().split())\n Graph[x].append((c, y))\n Graph[y].append((c, x))\n\nif solve(n) != -1:\n while(paths[n] != n):\n arr.append(n)\n n = paths[n]\nelse:\n print(-1)\n exit()\n\narr.append(1)\n\nprint(' '.join(map(str, arr[::-1])))\n", "import heapq\r\n\r\nINF = float('inf') # Infinity value for initialization\r\n\r\nclass Edge:\r\n def __init__(self, to, weight):\r\n self.to = to\r\n self.weight = weight\r\n\r\ndef dijkstra(n, adjacencyList):\r\n dist = [INF] * n\r\n previous = [-1] * n\r\n visited = [False] * n\r\n\r\n dist[0] = 0\r\n pq = [(0, 0)]\r\n\r\n while pq:\r\n d, u = heapq.heappop(pq)\r\n\r\n if visited[u]:\r\n continue\r\n\r\n visited[u] = True\r\n\r\n for edge in adjacencyList[u]:\r\n v = edge.to\r\n weight = edge.weight\r\n\r\n if dist[u] + weight < dist[v]:\r\n dist[v] = dist[u] + weight\r\n previous[v] = u\r\n heapq.heappush(pq, (dist[v], v))\r\n\r\n return dist, previous\r\n\r\ndef get_shortest_path(destination, previous):\r\n path = []\r\n\r\n if previous[destination] == -1:\r\n # No path exists\r\n return path\r\n\r\n v = destination\r\n while v != -1:\r\n path.append(v)\r\n v = previous[v]\r\n\r\n path.reverse()\r\n return path\r\n\r\nif __name__ == '__main__':\r\n n, m = map(int, input().split())\r\n\r\n adjacencyList = [[] for _ in range(n)]\r\n\r\n for _ in range(m):\r\n a, b, w = map(int, input().split())\r\n adjacencyList[a - 1].append(Edge(b - 1, w))\r\n adjacencyList[b - 1].append(Edge(a - 1, w))\r\n\r\n dist, previous = dijkstra(n, adjacencyList)\r\n\r\n shortestPath = get_shortest_path(n - 1, previous)\r\n\r\n if not shortestPath:\r\n print(-1)\r\n else:\r\n print(*[v + 1 for v in shortestPath])\r\n", "import heapq\nn, m = map(int, input().split())\ndistance = [float('inf')] * (n + 1)\ndic = [[] for _ in range(n + 1)]\npq = []\n \nfor i in range(m):\n a,b,c = map(int, input().split())\n dic[a].append((b, c))\n dic[b].append((a, c))\n \nheapq.heappush(pq, (0, 1))\ndistance[1] = 0\npath = [-1] * (n + 1)\nwhile pq:\n peso, vertice = heapq.heappop(pq)\n if peso > distance[vertice]: continue\n for vizinho, distancia in dic[vertice]:\n if distance[vizinho] > distance[vertice] + distancia:\n distance[vizinho] = distance[vertice] + distancia\n heapq.heappush(pq, (distance[vizinho], vizinho))\n path[vizinho] = vertice\nif path[n] == -1: print(-1)\nelse:\n current = n\n result = []\n while current != -1:\n result.append(current)\n current = path[current]\n result.reverse()\n print(' '.join(map(str, result)))\n\t \t\t \t \t\t \t \t \t \t\t \t\t\t \t\t\t", "import sys\nfrom heapq import *\ninput = sys.stdin.readline\n\nn, m = map(int, input().split())\ngraph = [[] for _ in range(n)]\n\nfor _ in range(m):\n a, b, w = map(int, input().split())\n a, b = a - 1, b - 1\n graph[a].append((b, w))\n graph[b].append((a, w))\n\nheap, parent = [(0, 0, n)], [-1] * n\n\nwhile heap:\n\n dist, node, p = heappop(heap)\n\n if parent[node] == -1:\n\n parent[node] = p\n\n if node == n:\n break\n\n for neighbor, w in graph[node]:\n if parent[neighbor] == -1:\n heappush(heap, (dist + w, neighbor, node))\n\nif parent[n - 1] == -1:\n print(-1)\nelse:\n res, p = [], n - 1\n while p != n:\n res.append(p + 1)\n p = parent[p]\n print(*res[::-1])\n", "import heapq\r\n\r\noo = 1000000000000\r\n\r\nn, m = [int(x) for x in input().split()]\r\n\r\ng = [[] for _ in range(n + 1)]\r\np = [-1 for _ in range(n + 1)]\r\nd = [oo for _ in range(n + 1)]\r\n\r\nd[1] = 0\r\nq = []\r\nheapq.heappush(q, (0, 1))\r\n\r\nfor i in range(m):\r\n u, v, w = [int(x) for x in input().split()]\r\n g[u].append((v, w))\r\n g[v].append((u, w))\r\n\r\nwhile (len(q)):\r\n cd, u = heapq.heappop(q)\r\n if (cd > d[u]): continue\r\n\r\n for (v, w) in g[u]:\r\n if (d[u] + w < d[v]):\r\n d[v] = d[u] + w\r\n p[v] = u\r\n heapq.heappush(q, (d[v], v))\r\n \r\nif (d[n] != oo):\r\n x = []\r\n u = n\r\n while u != -1:\r\n x.append(f'{u}')\r\n u = p[u]\r\n print(' '.join(reversed(x)))\r\nelse:\r\n print(-1)", "from sys import stdin\r\ndef input(): return stdin.readline()[:-1]\r\n\r\nINF = 10**18\r\n\r\nN, E = map(int, input().split())\r\nG = [[] for _ in range(N)]\r\n\r\nfor _ in range(E):\r\n a, b, w = map(int, input().split())\r\n a -= 1\r\n b -= 1\r\n G[a].append((b, w))\r\n G[b].append((a, w))\r\n\r\ndists = [INF] * N\r\ndists[0] = 0\r\n\r\nparent = [-1] * N\r\nparent[0] = 0\r\n\r\nfrom heapq import heappush, heappop\r\nque = [(0, 0)]\r\n\r\n\r\nwhile que:\r\n dist, v = heappop(que)\r\n if dist > dists[v]:\r\n continue\r\n for u, w in G[v]:\r\n if dists[u] > dists[v] + w:\r\n dists[u] = dists[v] + w\r\n parent[u] = v\r\n heappush(que, (dists[u], u))\r\n\r\nif dists[N-1] == INF:\r\n print(-1)\r\n exit()\r\n\r\npath = [N-1]\r\nwhile path[-1] != 0:\r\n path.append(parent[path[-1]])\r\npath = path[::-1]\r\npath = [p+1 for p in path]\r\nprint(*path)", "import heapq\r\nimport sys\r\n\r\n# Dijktra's shortest path algorithm. Prints the path from source to target.\r\n# If no path exists -1 is printed\r\n# testing another way to read the input\r\n\r\ndef dijkstra(adj, source, target):\r\n INF = ((1<<63) - 1)//2\r\n n = len(adj)\r\n pred = [ - 1 for x in range(n) ]\r\n dist = [ INF for i in range(n) ]\r\n dist[source] = 0\r\n Q = []\r\n heapq.heappush(Q, [dist[source], source])\r\n\r\n while(Q):\r\n u = heapq.heappop(Q) # u is a list of tuples [u_dist, u_id]\r\n u_dist = u[0]\r\n u_id = u[1]\r\n if u_id == target:\r\n break\r\n if u_dist > dist[u_id]:\r\n continue\r\n for v in adj[u_id]:\r\n v_id = v[0]\r\n w_uv = v[1]\r\n if dist[u_id] + w_uv < dist[v_id]:\r\n dist[v_id] = dist[u_id] + w_uv\r\n heapq.heappush(Q, [dist[v_id], v_id])\r\n pred[v_id] = u_id\r\n \r\n if dist[target]==INF:\r\n print(-1)\r\n else:\r\n st = []\r\n node = target\r\n while(True):\r\n st.append(node)\r\n node = pred[node]\r\n if(node==-1):\r\n break\r\n for num in reversed(st):\r\n print(num+1, end=' ')\r\n #path = st[::-1]\r\n #for num in path:\r\n # print(num+1, end=' ')\r\n \r\n#----------------------------------------------------------\r\n\r\nn, m = map(int, sys.stdin.readline().split())\r\n\r\nadj = [ [] for x in range(n) ]\r\n\r\nfor i in range(m):\r\n a, b, w = map(int, input().split())\r\n adj[a-1].append([b-1, w])\r\n adj[b-1].append([a-1, w])\r\n\r\nsource = 0\r\ntarget = n-1\r\ndijkstra(adj, 0, n-1)\r\n\r\n\r\n\r\n\r\n\r\n", "import heapq\n\nn, m = map(int, input().split())\ngraph = [[] for x in range(n + 1)]\n\nfor x in range(m):\n a, b, w = map(int, input().split())\n graph[a].append((b, w))\n graph[b].append((a, w)) \n\ndist = [float('inf')] * (n + 1)\nprev = [-1] * (n + 1)\ndist[1] = 0\npq = [(0, 1)]\n\nwhile pq:\n d, u = heapq.heappop(pq)\n if d > dist[u]:\n continue\n for v, w in graph[u]:\n if dist[u] + w < dist[v]:\n dist[v] = dist[u] + w\n prev[v] = u\n heapq.heappush(pq, (dist[v], v))\n\nif dist[n] == float('inf'):\n print(-1)\nelse: \n path = []\n v = n\n while v != -1:\n path.append(v)\n v = prev[v]\n\n print(*reversed(path))\n", "from heapq import heappop, heappush\n\n\ndef paskdjfkajsdcoajsdpoj(graph, strt, end):\n n = len(graph)\n dist = [float('inf')] * n\n dist[strt] = 0\n\n queue = [(0, strt)]\n while queue:\n dist1, node = heappop(queue)\n if dist1 > dist[node]:\n continue\n for sosed, zhostkiy_massa_nobor in graph[node]:\n new_dist = dist1 + zhostkiy_massa_nobor\n if new_dist < dist[sosed]:\n dist[sosed] = new_dist\n heappush(queue, (new_dist, sosed))\n\n if dist[end] == float('inf'):\n return -1\n else:\n path = []\n node = end\n while node != strt:\n path.append(node)\n for sosed, zhostkiy_massa_nobor in graph[node]:\n if dist[node] == dist[sosed] + zhostkiy_massa_nobor:\n node = sosed\n break\n path.append(strt)\n return list(reversed(path))\n\n\nn, m = map(int, input().split())\ngraph = [[] for _ in range(n)]\n\nfor _ in range(m):\n a, b, w = map(int, input().split())\n graph[a - 1].append((b-1, w))\n graph[b - 1].append((a-1, w))\n\nakdfjkahsjdkfhaosdjfjalsdfji = paskdjfkajsdcoajsdpoj(graph, 0, n - 1)\n\nif akdfjkahsjdkfhaosdjfjalsdfji == -1:\n print(-1)\nelse:\n print(' '.join(str(x + 1) for x in akdfjkahsjdkfhaosdjfjalsdfji))\n\n \t \t \t \t\t\t \t \t \t\t\t \t \t\t \t", "import heapq\r\n\r\nn, m = map(int, input().split())\r\n\r\nadj = [[] for i in range(n+1)]\r\nvis = [False for i in range(n+1)]\r\ndist = [float('inf') for i in range(n+1)]\r\np = [-1 for i in range(n+1)]\r\n\r\nfor i in range(m):\r\n a, b, w = map(int, input().split())\r\n adj[a].append((w,b))\r\n adj[b].append((w,a))\r\n\r\ndef dijkstra(src): \r\n pq = []\r\n heapq.heappush(pq, (0, src))\r\n\r\n vis[src] = True\r\n dist[src] = 0\r\n p[src] = src\r\n while pq:\r\n currentDist, currentVertex = heapq.heappop(pq)\r\n vis[currentVertex] = True\r\n for weight, neighbor in adj[currentVertex]:\r\n if currentDist + weight < dist[neighbor]:\r\n dist[neighbor] = currentDist + weight\r\n heapq.heappush(pq,(dist[neighbor], neighbor))\r\n p[neighbor] = currentVertex\r\n\r\ndijkstra(1)\r\n\r\nif vis[n] == True:\r\n answer = [n]\r\n i = n\r\n while p[i] != i:\r\n answer.append(p[i])\r\n i = p[i]\r\n\r\n answer.reverse()\r\n\r\n print(*answer)\r\n\r\nelse:\r\n print(-1)", "import heapq\r\n\r\ndef dijkstra(graph, start, end):\r\n n = len(graph)\r\n distances = [float('inf')] * n\r\n distances[start] = 0\r\n parents = [-1] * n\r\n heap = [(0, start)]\r\n\r\n while heap:\r\n dist, u = heapq.heappop(heap)\r\n if dist > distances[u]:\r\n continue\r\n\r\n for v, weight in graph[u]:\r\n new_dist = distances[u] + weight\r\n if new_dist < distances[v]:\r\n distances[v] = new_dist\r\n parents[v] = u\r\n heapq.heappush(heap, (new_dist, v))\r\n\r\n if distances[end] == float('inf'):\r\n return []\r\n\r\n path = []\r\n curr = end\r\n while curr != -1:\r\n path.append(curr + 1)\r\n curr = parents[curr]\r\n\r\n return path[::-1]\r\n\r\n\r\nno_of_vertices, no_of_edges = map(int, input().split())\r\ngraph = [[] for _ in range(no_of_vertices)]\r\n\r\nfor _ in range(no_of_edges):\r\n u, v, weight = map(int, input().split())\r\n graph[u - 1].append((v - 1, weight))\r\n graph[v - 1].append((u - 1, weight))\r\n\r\npath = dijkstra(graph, 0, no_of_vertices - 1)\r\n\r\nif not path:\r\n print(-1)\r\nelse:\r\n print(' '.join(map(str, path)))\r\n", "import heapq as hq\r\nn,m=map(int,input().split())\r\nadj=[[] for _ in range(n)]\r\nfor _ in range(m):\r\n a,b,d=map(int,input().split())\r\n a-=1\r\n b-=1\r\n adj[a].append((b,d))\r\n adj[b].append((a,d))\r\ncost=[float('inf')]*n\r\ncost[0]=0\r\npar=[-1]*n\r\nheap=[(0,0)]\r\nwhile heap:\r\n cu,u=hq.heappop(heap)\r\n for v,d in adj[u]:\r\n if cost[v]>cu+d:\r\n cost[v]=cu+d\r\n par[v]=u\r\n hq.heappush(heap,(cost[v],v))\r\nres=cost[n-1]\r\nif res==float('inf'):\r\n print(-1)\r\nelse:\r\n path=[n-1]\r\n node=n-1\r\n while par[node]!=-1:\r\n path.append(par[node])\r\n node=par[node]\r\n for i in path[::-1]:\r\n print(i+1,end=' ')\r\n ", "import heapq\r\n\r\nn, m = [int(c) for c in input().split()]\r\n\r\n# Create adjacency list with [dest, weight] for each edge\r\n# and shortest path, previous node dict for each node\r\nadj_list = [[]] * n\r\nshortest_paths = [0] * n\r\nprevious_node = [0] * n\r\nfor i in range(m):\r\n a, b, w = [int(c) for c in input().split()]\r\n # 0 indexing\r\n a -= 1\r\n b -= 1\r\n # Add node a\r\n if adj_list[a]:\r\n adj_list[a].append([b, w])\r\n else:\r\n adj_list[a] = [[b, w]]\r\n shortest_paths[a] = float('inf')\r\n previous_node[a] = -1\r\n # Add node b\r\n if adj_list[b]:\r\n adj_list[b].append([a, w])\r\n else:\r\n adj_list[b] = [[a, w]]\r\n shortest_paths[b] = float('inf')\r\n previous_node[b] = -1\r\n\r\n# Dijkstra's with minheap and visited\r\nvisited = set()\r\nheap = [[0, 0]]\r\nshortest_paths[0] = 0\r\nwhile heap:\r\n _, curr_node = heapq.heappop(heap)\r\n visited.add(curr_node)\r\n # Check if destination found\r\n if curr_node == n - 1:\r\n # Print path to node\r\n path = [str(n)]\r\n while path[-1] != '1':\r\n path.append(str(previous_node[int(path[-1]) - 1] + 1))\r\n path.reverse()\r\n print(\" \".join(path))\r\n break\r\n # Examine neighbors\r\n for dest, weight in adj_list[curr_node]:\r\n # Skip duplicates\r\n if dest in visited:\r\n continue\r\n # Check if new shortest is found\r\n new_cost = shortest_paths[curr_node] + weight\r\n if shortest_paths[dest] > new_cost:\r\n heapq.heappush(heap, [new_cost, dest])\r\n shortest_paths[dest] = new_cost\r\n previous_node[dest] = curr_node\r\n# -1 if not found\r\nelse:\r\n print(-1)\r\n", "import heapq\r\n\r\ndef dijkstra(start):\r\n dist[start] = 0\r\n heapq.heappush(queue, (0, start))\r\n\r\n while queue:\r\n path_len, v = heapq.heappop(queue)\r\n if path_len == dist[v]:\r\n for w, edge_len in graph[v]:\r\n if dist[v] + edge_len < dist[w]:\r\n dist[w], prev[w] = dist[v] + edge_len, v\r\n heapq.heappush(queue, (dist[w], w))\r\n\r\ndef shortest_path(v):\r\n path = []\r\n current = v\r\n while current != -1:\r\n path.append(current)\r\n current = prev[current]\r\n return path[::-1]\r\n\r\nn, m = map(int, input().split())\r\ngraph = {i: [] for i in range(1, n + 1)}\r\ndist = [float('inf')] * (n + 1)\r\nprev = [-1] * (n + 1)\r\nqueue = []\r\n\r\nfor _ in range(m):\r\n a, b, w = map(int, input().split())\r\n graph[a].append((b, w))\r\n graph[b].append((a, w))\r\n\r\ndijkstra(1)\r\n\r\nif dist[n] == float('inf'):\r\n print(-1)\r\nelse:\r\n path = shortest_path(n)\r\n print(' '.join(map(str, path)))", "from collections import deque\nfrom heapq import *\nfrom sys import stdin\n\nif __name__ == '__main__':\n V, E = map(int, stdin.readline().rstrip().split())\n adj_list = []\n shortest_paths = []\n for v in range(0, V):\n adj_list.append([])\n\n for e in range(0, E):\n v1, v2, length = map(int, stdin.readline().rstrip().split())\n adj_list[v1-1].append((v2-1, length))\n adj_list[v2-1].append((v1-1, length))\n\n\n def dijkstra(start, end):\n heapq = [(0, start)]\n seen = [False] * V\n shortest_dist = [100000000000] * V\n shortest_dist[0] = 0\n predecessors = [-1] * V\n predecessors[0] = 0\n while heapq:\n (dist, v1) = heappop(heapq)\n if not seen[v1]:\n seen[v1] = True\n if v1 == end:\n return dist, predecessors\n for (v2, length) in adj_list[v1]:\n if not seen[v2]:\n new_dist = dist + length\n if new_dist < shortest_dist[v2]:\n shortest_dist[v2] = new_dist\n predecessors[v2] = v1\n heappush(heapq, (new_dist, v2))\n return ()\n\n\n result = dijkstra(0, V-1)\n if result:\n predecessors = result[1]\n path = deque()\n node = V-1\n while not node == 0:\n path.appendleft(node+1)\n node = predecessors[node]\n path.appendleft(1)\n print(*path)\n else:\n print(-1)", "from sys import stdin\r\ninput = stdin.buffer.readline\r\n\r\nimport collections\r\nimport heapq\r\n\r\nn , m = map(int , input().split())\r\ngraph = collections.defaultdict(list)\r\n\r\nfor _ in range(m) :\r\n i , j , w = map(int , input().split())\r\n i -= 1\r\n j -= 1\r\n graph[i].append([j , w])\r\n graph[j].append([i , w])\r\n\r\ndis = [float('inf')]*n\r\nsource = [-1]*n\r\n\r\nheap = [[0 , 0 , -1]]\r\n\r\nwhile heap :\r\n d , u , p = heapq.heappop(heap)\r\n\r\n if dis[u] > d :\r\n dis[u] = d\r\n source[u] = p\r\n\r\n if u == n - 1 :\r\n break\r\n\r\n for v , w in graph[u] :\r\n heapq.heappush(heap , [d + w , v , u])\r\n\r\nres = []\r\ncur = n - 1\r\n\r\nwhile cur != -1 :\r\n res.append(cur + 1)\r\n cur = source[cur]\r\n\r\nif len(res) == 1 :\r\n print(-1)\r\n\r\nelse :\r\n for i in range(len(res) - 1 , -1 , -1) :\r\n print(res[i] , end = ' ')\r\n\r\n print()\r\n\r\n", "import heapq\r\nR = lambda: map(int, input().split())\r\nn,m = R()\r\nedges = [list() for _ in range(n)]\r\nprev = [-1] * n\r\ndist = [float('inf')] * (n - 1) + [0]\r\npriority_queue = [(0, n - 1)]\r\nunvisited = set(range(n))\r\nfor _ in range(m):\r\n a,b,w = R()\r\n edges[a - 1].append((b - 1, w))\r\n edges[b - 1].append((a - 1, w))\r\nwhile priority_queue:\r\n current_dist, current_node = heapq.heappop(priority_queue)\r\n if not current_node:\r\n break\r\n if current_node in unvisited:\r\n unvisited.remove(current_node)\r\n for node, weight in edges[current_node]:\r\n alt = current_dist + weight\r\n if alt < dist[node]:\r\n dist[node], prev[node] = alt, current_node\r\n heapq.heappush(priority_queue, (alt, node))\r\nptr = 0\r\npath = list()\r\nwhile ptr != -1:\r\n path.append(ptr)\r\n ptr = prev[ptr]\r\nif path[-1] != n - 1:\r\n print(-1)\r\nelse:\r\n print(' '.join([str(p + 1) for p in path]))\r\n", "from heapq import heappush, heappop\r\n\r\noo = 18 ** 12\r\nn, m = [int(x) for x in input().split()]\r\nadj = [[] for _ in range(n)]\r\np = [-1] * n\r\nd = [0] + [oo] * (n - 1)\r\n\r\nfor _ in range(m):\r\n u, v, w = map(int, input().split())\r\n adj[u - 1].append((w, v - 1))\r\n adj[v - 1].append((w, u - 1))\r\n\r\npq = []\r\nheappush(pq, (0, 0))\r\nwhile pq:\r\n du, u = heappop(pq)\r\n if du > d[u]:\r\n continue\r\n for (w, v) in adj[u]:\r\n if d[v] > d[u] + w:\r\n d[v], p[v] = d[u] + w, u\r\n heappush(pq, (d[v], v))\r\n\r\nif d[n - 1] == oo:\r\n print(-1)\r\nelse:\r\n path = []\r\n v = n - 1\r\n while v != -1:\r\n path.append(v + 1)\r\n v = p[v]\r\n path.reverse()\r\n print(' '.join(map(str, path)))\r\n", "import sys\r\ninput = sys.stdin.readline\r\nfrom heapq import heappop,heappush\r\nn,m = map(int,input().split())\r\ngraph = {i:[] for i in range(1,n+1)}\r\nfor i in range(m):\r\n a,b,w = map(int,input().split())\r\n graph[a].append([b,w])\r\n graph[b].append([a,w])\r\ndistance = [float('inf') for i in range(n+1)]\r\nparent = [i for i in range(n+1)]\r\ndistance[1] = 0\r\nQ = [[0,1]] # 0th index--> Distance and 1st index--> Node\r\nwhile Q:\r\n d,node = heappop(Q)\r\n for b,w in graph[node]:\r\n if distance[b]>distance[node]+w:\r\n distance[b] = distance[node]+w\r\n parent[b] = node\r\n heappush(Q,[distance[b],b])\r\nans = [n]\r\nwhile parent[ans[-1]]!=ans[-1]:\r\n ans.append(parent[ans[-1]])\r\nif ans[-1]!=1:\r\n print(-1)\r\nelse:\r\n ans = ans[::-1]\r\n print(*ans,sep=\" \")", "# from typing import List, Tuple\r\n# import heapq\r\n#\r\n# inf = int(1e18)\r\n# adj = [[] for _ in range(200010)]\r\n# dist = [inf]*200010\r\n# pred = [-1]*200010\r\n#\r\n# def djk(s: int, t: int, n: int) -> int:\r\n# global adj, dist, pred\r\n# dist[s] = 0\r\n# pq = [(0, s)]\r\n# while pq:\r\n# d, u = heapq.heappop(pq)\r\n# if d > dist[u]: continue\r\n# for v, w in adj[u]:\r\n# if dist[v] > dist[u] + w:\r\n# dist[v] = dist[u] + w\r\n# pred[v] = u\r\n# heapq.heappush(pq, (dist[v], v))\r\n# return dist[t]\r\n#\r\n# def solve() -> None:\r\n# global adj, dist, pred\r\n# n, m = map(int, input().split())\r\n# for i in range(m):\r\n# a, b, w = map(int, input().split())\r\n# adj[a].append((b, w))\r\n# adj[b].append((a, w))\r\n# if djk(1, n, n) >= inf:\r\n# print(-1)\r\n# else:\r\n# path = []\r\n# u = n\r\n# while u != -1:\r\n# path.append(u)\r\n# u = pred[u]\r\n# path.reverse()\r\n# print(*path)\r\n#\r\n# solve()\r\n\r\n\r\nimport heapq\r\n\r\nINF = float(\"inf\")\r\n\r\nn, m = map(int, input().split())\r\n\r\n# Criação da lista de adjacência\r\nadj_list = [[] for _ in range(n)]\r\nfor _ in range(m):\r\n a, b, w = map(int, input().split())\r\n adj_list[a-1].append((b-1, w))\r\n adj_list[b-1].append((a-1, w))\r\n\r\n# Vetor de distâncias e vetor de visitados\r\ndist = [INF] * n\r\nvisited = [False] * n\r\n\r\n# Fila de prioridade (heap) para manter o próximo vértice a ser visitado\r\nheap = []\r\n\r\n# Começo da busca\r\ndist[0] = 0\r\nheapq.heappush(heap, (0, 0)) # (distância, vértice)\r\nwhile heap:\r\n curr_dist, curr_vert = heapq.heappop(heap)\r\n if visited[curr_vert]:\r\n continue\r\n visited[curr_vert] = True\r\n if curr_vert == n-1:\r\n break\r\n for neighbor, weight in adj_list[curr_vert]:\r\n if not visited[neighbor] and dist[neighbor] > curr_dist + weight:\r\n dist[neighbor] = curr_dist + weight\r\n heapq.heappush(heap, (dist[neighbor], neighbor))\r\n\r\n# Verificando se tem caminho para o vértice n\r\nif visited[n-1]:\r\n path = []\r\n curr_vert = n-1\r\n while curr_vert != 0:\r\n path.append(curr_vert + 1)\r\n for neighbor, weight in adj_list[curr_vert]:\r\n if dist[curr_vert] == dist[neighbor] + weight:\r\n curr_vert = neighbor\r\n break\r\n path.append(1)\r\n print(*path[::-1])\r\nelse:\r\n print(-1)\r\n", "from collections import defaultdict\nimport heapq\n\nn, m = map(int, input().split(' '))\n\ngraph = defaultdict(set)\n\nfor _ in range(m):\n s, d, w = map(int, input().split(' '))\n graph[s].add((d, w))\n graph[d].add((s, w))\n\npq = [(0, 1, None)]\nparents = {}\ndiscovered = set()\nwhile len(pq) != 0:\n total, u, parent = heapq.heappop(pq)\n if u not in parents:\n parents[u] = parent\n discovered.add(u)\n if u == n:\n node = n\n path = []\n while node != None:\n path.append(node)\n node = parents[node]\n path.reverse()\n print(' '.join(map(str, path)))\n exit()\n for v, w in graph[u]:\n if v not in discovered:\n heapq.heappush(pq, (total + w, v, u))\nprint(-1)\n\n\n\n\n\n ", "import heapq\n\nn, m = map(int, input().split())\ng = {i:[] for i in range(n+1)}\nfor i in range(m):\n u, v, w = map(int, input().split())\n g[u].append([v, w])\n g[v].append([u, w])\n\ndist = [0] * len(g)\nprev = [0] * len(g)\nvisitado = [0] * len(g)\npq = []\nheapq.heapify(pq)\n\nfor i in range(1, len(g)):\n if i != 1:\n dist[i] = 10000000000000\n prev[i] = 0\n\nheapq.heappush(pq, (0, 1))\nwhile pq:\n d, u = heapq.heappop(pq)\n if visitado[u] == 1:\n continue\n visitado[u] = 1\n\n for e in g[u]:\n if d + e[1] < dist[e[0]]:\n dist[e[0]] = d + e[1]\n prev[e[0]] = u\n heapq.heappush(pq, (dist[e[0]], e[0]))\n\nif dist[n] == 10000000000000:\n print(-1)\nelse:\n temp = [n]\n while prev[n] != 0:\n temp.append(prev[n])\n n = prev[n]\n temp = temp[::-1]\n print(*temp)\n\t \t \t \t\t\t \t \t \t\t\t \t\t \t", "from heapq import *\r\nINF = 1 << 64;\r\nif __name__ == '__main__': \r\n n, m = map(int, input().split())\r\n g = [[] for i in range(n)]\r\n d = [INF for i in range(n)]\r\n d[0] = 0\r\n q = [(0, 0)]\r\n p = [-1 for i in range(n)]\r\n for i in range(m):\r\n a, b, w = map(int, input().split())\r\n g[a - 1].append((b - 1, w))\r\n g[b - 1].append((a - 1, w))\r\n \r\n while q:\r\n v = heappop(q)[1]\r\n for x, len in g[v]:\r\n if d[x] > d[v] + len:\r\n d[x] = d[v] + len\r\n heappush(q, (d[x], x))\r\n p[x] = v\r\n \r\n if d[n - 1] > INF / 2:\r\n print(-1)\r\n else:\r\n ans = []\r\n v = n - 1\r\n while (v != -1):\r\n ans.append(str(v + 1))\r\n v = p[v]\r\n \r\n print(' '.join(ans[::-1])); \r\n ", "from heapq import heappop, heappush\ndef i_in():\n return (map(int, input().split()))\n\nnodes, edges = i_in();\ngraph = [[] for x in range(nodes)]\nfor x in range(edges):\n left, right, cost = i_in()\n left -= 1; right -= 1\n graph[left].append((cost, right))\n graph[right].append((cost, left))\n\nvisited = [False for x in range(nodes)]\nprevious = [-1 for x in range(nodes)]\n\npq = [(0, 0, -1)]\n\nfound = False\nwhile pq:\n path_cost, node, prev = heappop(pq)\n if visited[node]: continue\n visited[node] = True\n previous[node] = prev\n if node == nodes-1:\n found = True\n break\n for cost, adj in graph[node]:\n if not visited[adj]:\n heappush(pq, (path_cost + cost, adj, node))\nif not found:\n print(-1)\n quit()\n\npath = []\ncurrent = nodes-1\nwhile current != -1:\n path.append(str(current+1))\n current = previous[current]\npath.reverse()\nprint(\" \".join(path))\n\n\n", "n,m = [int(x) for x in input().split()]\r\nadj = [[] for _ in range(n + 1)]\r\nfor _ in range(m):\r\n\tu, v, w = [int(x) for x in input().split()]\r\n\tadj[u].append((v, w))\r\n\tadj[v].append((u, w))\r\n\r\nsource=1\r\nimport heapq\r\ndistance = [float('inf') for _ in range(n + 1)]\r\ndistance[source] = 0\r\nshortest_path_tree_parent = [-1 for _ in range(n + 1)]\r\nqueue = [(distance[source], source)]\r\ndone = [False for _ in range(n + 1)]\r\nwhile len(queue) > 0:\r\n\t_, u = heapq.heappop(queue)\r\n\tif not done[u]:\r\n\t\tfor v, w in adj[u]:\r\n\t\t\tif distance[v] > distance[u] + w:\r\n\t\t\t\tdistance[v] = distance[u] + w\r\n\t\t\t\tshortest_path_tree_parent[v] = u\r\n\t\t\t\theapq.heappush(queue,(distance[v], v))\r\n\t\t\t\tif done[v]:\r\n\t\t\t\t\theapq.heappop(queue)\r\n\t\tdone[u] = True\r\n\r\ndef path_to(v):\r\n\tpath = [v]\r\n\twhile shortest_path_tree_parent[path[-1]] != -1:\r\n\t\tpath.append(shortest_path_tree_parent[path[-1]])\r\n\treturn path[::-1]\r\nx= path_to(n)\r\nif len(x)==1:\r\n\tprint(-1)\r\nelse:\r\n\tprint(*x)", "from math import inf\nfrom heapq import heappop, heappush\n \ndef calc_path(parents):\n output = [ \"-1\" ]\n if parents[-1] != -1:\n i = len(parents) - 1\n output = []\n while i != -1:\n output.append(str(i + 1))\n i = int(parents[i])\n output.reverse()\n return \" \".join(output)\n \n \nn, m = [ int(x) for x in input().split() ]\n\ndist = []\nvis = []\npars = []\ngraph = {}\n \nfor i in range(n):\n dist.append(inf)\n vis.append(False)\n pars.append(-1)\n graph[i] = {}\n\nfor i in range(m):\n n1, n2, v = [ int(x) for x in input().split() ]\n graph[n1 - 1][n2-1] = v\n graph[n2 - 1][n1-1] = v\n\n dist[0] = 0\n \nheap = [(0, 0)]\nwhile len(heap) > 0:\n no = heappop(heap)[1]\n \n if not vis[no]:\n vis[no] = True\n for j in graph[no]:\n if not vis[j] and dist[j] > dist[no] + graph[no][j]:\n dist[j] = dist[no] + graph[no][j]\n pars[j] = no\n heappush(heap, (dist[j], j))\n \nprint(calc_path(pars))\n", "INF = 1 << 60\nn, m = map(int, input().split())\ng = [[] for _ in range(n)]\nd = [0] + [INF] * n\np = [-1] * n\nfor _ in range(m):\n\tu, v, t = map(int, input().split())\n\tg[u-1].append((t, v-1))\n\tg[v-1].append((t, u-1))\nfrom heapq import *\nq = [(0, 0)]\nwhile q:\n\tu = heappop(q)[1]\n\tfor e in g[u]:\n\t\tt = d[u] + e[0]\n\t\tv = e[1]\n\t\tif t < d[v]:\n\t\t\td[v] = t\n\t\t\tp[v] = u\n\t\t\theappush(q, (d[v], v))\nif d[n-1] == INF:\n\tprint(-1);\nelse:\n\tx = n - 1\n\tans = []\n\twhile x != -1:\n\t\tans.append(x + 1)\n\t\tx = p[x]\n\tans.reverse()\n\tprint(' '.join(map(str, ans)))\n", "#!/usr/bin/env python3\n\n# ---------------------------------------------------\n# problems/codeforces/secret-combination/Disjkstra.py\n# Copyright (C) 2015\n# Glenn P. Downing\n# ---------------------------------------------------\n\n\"\"\"\nC. Dijkstra?\nhttp://codeforces.com/problemset/problem/20/C/\n\nMon, 23 Feb 2015\nPython 3.4: 1746 ms\n\"\"\"\n\nfrom heapq import heappop, heappush\nfrom sys import stdin\n\ndef graph (ne) :\n g = {}\n\n for i in range(ne) :\n s = input()\n u, v, w = (int(t) for t in s.split())\n\n if u not in g :\n g[u] = {}\n\n if v not in g :\n g[v] = {}\n\n if v not in g[u] :\n g[u][v] = w\n g[v][u] = w\n else :\n g[u][v] = min(g[u][v], w)\n g[v][u] = min(g[v][u], w)\n\n return g\n\ndef search (g, bv, ev) :\n pq = []\n ps = {ev : ev}\n ws = {ev : 0}\n heappush(pq, (0, ev))\n\n while pq :\n w, u = heappop(pq)\n\n if u == bv :\n return ps\n\n if u not in g :\n continue\n\n for v in g[u] :\n cw = ws[u] + g[u][v]\n\n if (v not in ws) or (cw < ws[v]) :\n heappush(pq, (cw, v))\n ps[v] = u\n ws[v] = cw\n\n return {}\n\ndef path (bv, ev, ps) :\n p = [bv]\n\n while bv != ev :\n bv = ps[bv]\n p.append(bv)\n\n return p\n\ndef test_case (nv, ne) :\n bv = 1\n ev = nv\n g = graph(ne)\n ps = search(g, bv, ev)\n\n if not ps :\n print(-1)\n return\n\n p = path(bv, ev, ps)\n print(\" \".join(str(v) for v in p))\n\ndef main () :\n for s in stdin :\n test_case(*(int(v) for v in s.split()))\n\nif __name__ == \"__main__\" :\n main()\n", "#!/usr/bin/env python3\n\n# ---------------------------------------------------\n# problems/codeforces/secret-combination/Disjkstra.py\n# Copyright (C) 2015\n# Glenn P. Downing\n# ---------------------------------------------------\n\n\"\"\"\nC. Dijkstra?\nhttp://codeforces.com/problemset/problem/20/C/\n\nMon, 23 Feb 2015\nPython 3.4: 1746 ms\n\"\"\"\n\nfrom heapq import heappop, heappush\nfrom sys import stdin\n\ndef make_graph (m) :\n graph = {}\n\n for i in range(m) :\n s = input()\n u, v, w = (int(t) for t in s.split())\n\n if u not in graph :\n graph[u] = {}\n\n if v not in graph :\n graph[v] = {}\n\n if v not in graph[u] :\n graph[u][v] = w\n graph[v][u] = w\n else :\n graph[u][v] = min(graph[u][v], w)\n graph[v][u] = min(graph[v][u], w)\n\n return graph\n\ndef search (graph, b, e) :\n queue = []\n successors = {e : e}\n weights = {e : 0}\n heappush(queue, (0, e))\n\n while queue :\n w, u = heappop(queue)\n\n if u == b :\n path = [b]\n\n while b != e :\n b = successors[b]\n path.append(b)\n\n return path\n\n if u not in graph :\n continue\n\n for v in graph[u] :\n cw = weights[u] + graph[u][v]\n\n if (v not in weights) or (cw < weights[v]) :\n heappush(queue, (cw, v))\n successors[v] = u\n weights[v] = cw\n\n return [-1]\n\ndef test_case (n, m) :\n b = 1\n e = n\n graph = make_graph(m)\n path = search(graph, b, e)\n print(\" \".join(str(v) for v in path))\n\ndef main () :\n for s in stdin :\n n, m = (int(t) for t in s.split())\n test_case(n, m)\n\nif __name__ == \"__main__\" :\n main()\n", "from heapq import heappop, heappush;N, inf = 10**5 + 10, 10**18;n, m = map(int, input().split())\r\nadj, visited, dist, parent = [[] for _ in range(N)], [False]*N, [inf]*N, [-1]*N\r\ndef dijkstra(src):\r\n pq, dist[src], parent[src] = [], 0, 0;heappush(pq, (0, src))\r\n while pq:\r\n curr_dist, u = heappop(pq)\r\n if visited[u]:continue\r\n visited[u] = True\r\n for v, w in adj[u]:\r\n if dist[v] > dist[u] + w:dist[v] = dist[u] + w;parent[v] = u;heappush(pq, (dist[v], v))\r\nfor _ in range(m):\r\n u, v, w = map(int, input().split());adj[u].append((v, w));adj[v].append((u, w))\r\ndijkstra(1)\r\nif dist[n] >= inf:print(-1);exit()\r\nstk, node = [], n\r\nwhile node:stk.append(node);node = parent[node]\r\nfor node in reversed(stk):print(node, end=\" \")\r\n", "\"\"\"\r\nhttps://codeforces.com/problemset/problem/20/C?locale=ru\r\n\"\"\"\r\nfrom heapq import heappop, heappush\r\nfrom collections import defaultdict\r\nfrom sys import stdout, stdin\r\nfrom io import IOBase, BytesIO\r\nfrom os import read, write, fstat\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 = read(self._fd, max(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, size: int = ...):\r\n while self.newlines == 0:\r\n b = read(self._fd, max(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 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\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\", 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\nstdin, stdout = IOWrapper(stdin), IOWrapper(stdout)\r\ndef input(): return stdin.readline().rstrip(\"\\r\\n\")\r\n\r\n\r\nINF = float(\"inf\")\r\n\r\n\r\ndef read_data():\r\n n, m = map(int, input().split())\r\n graph = [[] for _ in range(n)]\r\n for _ in range(m):\r\n node1, node2, weight = map(int, input().split())\r\n node1 -= 1\r\n node2 -= 1\r\n graph[node1].append((node2, weight))\r\n graph[node2].append((node1, weight))\r\n return n, graph\r\n\r\n\r\ndef dijkstra(graph, start=0):\r\n n = len(graph)\r\n dist, parents_list = [INF] * n, [-1] * n\r\n dist[start] = 0\r\n\r\n queue = [(0, start)]\r\n while queue:\r\n path_len, v = heappop(queue)\r\n if path_len == dist[v]:\r\n for (w, edge_len) in graph[v]:\r\n if edge_len + path_len < dist[w]:\r\n dist[w], parents_list[w] = edge_len + path_len, v\r\n heappush(queue, (edge_len + path_len, w))\r\n return parents_list\r\n\r\n\r\ndef main():\r\n n, graph = read_data()\r\n parents_list = dijkstra(graph)\r\n if parents_list[n - 1] == -1:\r\n print(-1)\r\n else:\r\n full_path, parent = [], n - 1\r\n while parent != parents_list[0]:\r\n full_path.append(parent + 1)\r\n parent = parents_list[parent]\r\n full_path.reverse()\r\n print(*full_path)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "import heapq\r\n\r\ndef dijkstra():\r\n n, m = map(int, input().split())\r\n adj = [[] for _ in range(n+1)]\r\n for _ in range(m):\r\n a, b, w = map(int, input().split())\r\n adj[a].append((w, b))\r\n adj[b].append((w, a))\r\n dist = [float('inf')] * (n+1)\r\n prev = [0] * (n+1)\r\n dist[1] = 0\r\n queue = [(0, 1)]\r\n while queue:\r\n d, v = heapq.heappop(queue)\r\n if d != dist[v]:\r\n continue\r\n for w, to in adj[v]:\r\n if dist[v] + w < dist[to]:\r\n dist[to] = dist[v] + w\r\n prev[to] = v\r\n heapq.heappush(queue, (dist[to], to))\r\n if dist[n] == float('inf'):\r\n print(-1)\r\n else:\r\n path = []\r\n v = n\r\n while v != 0:\r\n path.append(v)\r\n v = prev[v]\r\n path.reverse()\r\n print(' '.join(map(str, path)))\r\n\r\ndijkstra()\r\n", "'''\r\nCreated on Apr 22, 2016\r\nGmail : [email protected]\r\n@author: Md. Rezwanul Haque\r\n'''\r\nfrom heapq import heappop,heappush\r\nfrom sys import stdin\r\n\r\ndef graph(ne):\r\n g = {}\r\n for i in range(ne):\r\n u , v , w = [int(t) for t in input().split()]\r\n if u not in g:\r\n g[u] = {}\r\n if v not in g:\r\n g[v] = {}\r\n if v not in g[u]:\r\n g[u][v] = w\r\n g[v][u] = w\r\n else:\r\n g[u][v] = min(g[u][v],w)\r\n g[v][u] = min(g[v][u],w)\r\n return g\r\n\r\ndef search(g,bv,ev):\r\n pq = []\r\n ps = {bv:bv}\r\n ws = {bv:0}\r\n heappush(pq, (0,bv))\r\n \r\n while pq:\r\n u = heappop(pq)[1]\r\n if u == ev:\r\n return ps\r\n if u not in g:\r\n continue\r\n for v in g[u]:\r\n cw = ws[u] + g[u][v]\r\n if (v not in ws) or (cw<ws[v]):\r\n heappush(pq, (cw,v))\r\n ps[v] = u\r\n ws[v] = cw\r\n return {}\r\ndef path(bv,ev,ps):\r\n p = [ev]\r\n while bv!=ev:\r\n ev = ps[ev]\r\n p.append(ev)\r\n return p\r\nfor s in stdin:\r\n nv,ne =[int(t)for t in s.split()]\r\n bv = nv\r\n ev = 1\r\n g =graph(ne)\r\n ps = search(g, bv, ev)\r\n if ps=={}:\r\n print(-1)\r\n else:\r\n p = path(bv, ev, ps)\r\n for v in p:\r\n print(v,end=\" \")\r\n print()", "import heapq\r\nINF = 10**13\r\n\t\r\n\r\ndef dijk(st, d, p, g):\r\n\tq = [(d[st], st)]\r\n\twhile q:\r\n\t\tln, v = heapq.heappop(q)\r\n\t\tif(ln > d[v]):\r\n\t\t\tcontinue\r\n\t\tfor (to, w) in (g[v]):\r\n\t\t\tif d[to] > ln + w:\r\n\t\t\t\td[to] = ln + w\r\n\t\t\t\tp[to] = v\r\n\t\t\t\theapq.heappush(q, (d[to], to))\r\n\r\ndef main():\r\n\tn, m = map(int, input().split())\r\n\tg = [[] for i in range(n + 1)]\r\n\t\r\n\tfor _ in range(m):\r\n\t\tu, v, w = map(int, input().split())\r\n\t\tg[u].append((v, w))\r\n\t\tg[v].append((u, w))\r\n\td = [INF] * (n + 1)\r\n\tp = [-1] * (n + 1)\r\n\td[1] = 0\r\n\tdijk(1, d, p, g)\r\n\tif d[n] == INF:\r\n\t\tprint(-1)\r\n\t\texit()\r\n\tpath = []\r\n\twhile n != -1:\r\n\t\tpath.append(n)\r\n\t\tn = p[n]\r\n\tpath.reverse()\r\n\tprint(' '.join(map(str, path)))\r\nif __name__ == '__main__':\r\n\tmain()", "import heapq\n\n\ndef dijkstra(adj,s,n):\n pq = [(0, s)] \n dist[s] = 0\n\n while pq:\n d, u = heapq.heappop(pq)\n if d > dist[u]:\n continue\n for v, w in adj[u]:\n if dist[u] + w < dist[v]:\n dist[v] = dist[u] + w\n previ[v] = u\n heapq.heappush(pq, (dist[v], v))\n\n path = []\n u = n\n while u != -1:\n path.append(u)\n u = previ[u]\n path.reverse()\n\n if path[0] != s:\n return []\n return path\n\n\n\nn, m = map(int, input().split())\n\nadj = [[] for _ in range(n+1)]\ndist = [float('inf')] * (n+1)\nprevi = [-1] * (n+1)\n\nfor _ in range(m):\n u, v, w = map(int, input().split())\n adj[u].append((v, w))\n adj[v].append((u, w))\n\n\npath = dijkstra(adj, 1, n)\n\nif not path:\n print(\"-1\")\nelse:\n print(*path)\n \t\t \t\t\t \t\t \t \t \t\t\t \t\t", "from heapq import heappop, heappush\r\nq = []\r\nn, m = map(int, input().split())\r\nel = [[] for i in range(n + 1)]\r\nv = [False] * (n + 1)\r\nbt = [-1] * (n + 1)\r\nml = [int(2e20) for i in range(n + 1)]\r\nd = None\r\nfor i in range(m):\r\n a, b, w = map(int, input().split())\r\n el[a].append((b, w))\r\n el[b].append((a, w))\r\nheappush(q, (0, 1, -1))\r\nwhile len(q):\r\n z, x, r = heappop(q)\r\n v[x] = True\r\n if z < ml[x]:\r\n ml[x], bt[x] = z, r\r\n if x == n:\r\n d = z\r\n break\r\n for (t, o) in el[x]:\r\n if not v[t]:\r\n heappush(q, (z + o, t, x))\r\np = []\r\na = n\r\nif d is None:\r\n print(-1)\r\nelse:\r\n while a != -1:\r\n p.append(a)\r\n a = bt[a]\r\n p.reverse()\r\n print(' '.join(map(str, p)))", "from heapq import heappush, heappop\n\ndef shortestPath(graph, src, dest):\n pq = []\n visited = set()\n parentsMap = {}\n D = {v:float('inf') for v in graph}\n D[src] = 0\n existsPath = False\n\n heappush(pq, (0, src))\n while pq:\n _, currvtx = heappop(pq)\n if currvtx == dest:\n existsPath = True\n break\n visited.add(currvtx)\n for neigh, neighcost in graph[currvtx]:\n if neigh not in visited:\n old_cost = D[neigh]\n new_cost = D[currvtx] + neighcost\n if new_cost < old_cost:\n parentsMap[neigh] = currvtx\n heappush(pq, (new_cost, neigh))\n D[neigh] = new_cost\n \n return parentsMap, existsPath\n\ndef print_path(parentsMap, dest):\n path = [dest]\n while(parentsMap[dest] != '1'):\n path.append(parentsMap[dest])\n dest = parentsMap[dest]\n path.reverse()\n print('1', *path)\n\nv, e = map(int,input().split())\ngraph = {str(v): [] for v in range(1, v+1)}\nfor _ in range(e):\n x,y,w = map(str,input().split())\n graph[x].append((y,int(w)))\n graph[y].append((x,int(w)))\np, b = shortestPath(graph,'1', str(v))\nif b:\n print_path(p, str(v))\nelse:\n print('-1')\n\n \t\t \t \t \t\t \t \t\t\t \t\t\t", "import sys\nimport heapq\n\nn, m = list(map(int, input().split()))\nedges = [[] for x in range(n)]\ndist = [sys.maxsize] * n\nprev = [-1] * n\n \nfor i in range(m):\n\ta, b, w = list(map(int, input().split()))\n\tedges[a-1].append((b-1, w))\n\tedges[b-1].append((a-1, w))\n \n \nq = []\nheapq.heappush(q, (0, 0))\ndist[0] = 0\n \nwhile len(q) > 0:\n\td, curr = heapq.heappop(q)\n\tif d > dist[curr]:\n\t\tcontinue\n \n\tif curr == n - 1:\n\t\tbreak\n \n\tfor next, weight in edges[curr]:\n\t\tncost = d + weight\n\t\tif ncost < dist[next]:\n\t\t\tdist[next] = ncost\n\t\t\theapq.heappush(q, (ncost, next))\n\t\t\tprev[next] = curr\n \nif prev[n - 1] == -1:\n\tprint(-1)\nelse:\n\tres = [n]\n\tcurr = n - 1\n\twhile prev[curr] >= 0:\n\t\tres.append(prev[curr] + 1)\n\t\tcurr = prev[curr]\n \n\tres.reverse()\n\tprint(*res)", "from collections import defaultdict\nfrom heapq import heappush, heappop\n\ndef dijkstra(n, start, end):\n visited = [None] * (n + 1)\n aux = [(0, start,start)]\n \n while aux:\n dist, vertice,anterior = heappop(aux)\n if visited[vertice] is None:\n visited[vertice] = dist\n previous[vertice] = anterior\n if visited[end] != None:\n return visited[end]\n for vizinho, distAresta in neighbors[vertice]:\n if visited[vizinho] is None:\n heappush(aux, (dist + distAresta, vizinho, vertice))\n \n return -1\n\nn,m = map(int, input().split())\nneighbors = defaultdict(set)\nprevious = [[] for i in range(n+1)]\n\nfor _ in range(m):\n v1,v2, p = map(int, input().split())\n neighbors[v1].add((v2,p)),neighbors[v2].add((v1,p))\n\nif dijkstra(n, 1, n) != -1:\n father, prt = n, []\n previous[1] = 0\n while father != 0:\n prt.append(father)\n father = previous[father]\n print(\" \".join(map(str, reversed(prt))))\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", "from heapq import heappush, heappop\nfrom math import inf\n\ndef dijkstra(graph, src, dest):\n pq = []\n path = {}\n visited = set()\n existsPath = False\n D = {v: inf for v in graph}\n D[src] = 0\n\n heappush(pq, (0, src))\n while pq:\n _, u = heappop(pq)\n if u == dest:\n existsPath = True\n break\n visited.add(u)\n for neigh, neighcost in graph[u]:\n if neigh not in visited:\n old_cost = D[neigh]\n new_cost = D[u] + neighcost\n if new_cost < old_cost:\n path[neigh] = u\n heappush(pq, (new_cost, neigh))\n D[neigh] = new_cost\n \n return path, existsPath\n\ndef print_path(path, dest):\n built_path = [dest]\n while(path[dest] != 1):\n built_path.append(path[dest])\n dest = path[dest]\n built_path.reverse()\n print(1, *built_path)\n\nif __name__ == '__main__':\n v, e = map(int,input().split())\n\n graph = {u: [] for u in range(1, v + 1)}\n for _ in range(e):\n x, y, w = map(int, input().split())\n graph[x].append((y, w))\n graph[y].append((x, w))\n\n path, hasPath = dijkstra(graph, 1, v)\n if hasPath:\n print_path(path, v)\n else:\n print('-1')\n\n\t\t\t \t \t\t\t \t \t\t\t \t\t \t \t", "arr=list(map(int,input().split()))\r\nn=arr[0]\r\nm=arr[1]\r\nimport collections\r\ngraph = [[] for x in range(n+1)]\r\n\r\n \r\nfor i in range(m):\r\n\ta, b, w = list(map(int, input().split()))\r\n\tgraph[a].append((b, w))\r\n\tgraph[b].append((a, w))\r\n\r\nimport collections\r\nimport heapq\r\nheap=[(0,1)]\r\nheapq.heapify(heap)\r\ninf=float(\"INF\")\r\ndp=[inf for i in range(n+1)]\r\ndp[1]=0\r\ndic={}\r\n\r\npath=[0 for i in range(n+1)]\r\nwhile len(heap)>0:\r\n\tdis,a=heapq.heappop(heap)\r\n\tif dis>dp[a]:\r\n\t\tcontinue\r\n\tif a==n:\r\n\t\tarr=[]\r\n\t\twhile a:\r\n\t\t\tarr.append(a)\r\n\r\n\t\t\ta=path[a]\r\n\t\tarr=arr[::-1]\r\n\t\tprint(*arr)\r\n\t\t\r\n\t\texit()\r\n\t\r\n\telse:\r\n\t\tfor i in graph[a]:\r\n\t\t\tx,y=i\r\n\t\t\tif dis+y<dp[x]:\r\n\t\t\t\tdp[x]=dis+y\r\n\t\t\t\t# hash[i[0]]=dp[i[0]]\r\n\t\t\t\tpath[x]=a\r\n\t\t\t\theapq.heappush(heap,(dis+y,x))\r\n\t\t\t\r\n# print(dic)\r\nif len(dic)==0:\r\n\tprint(-1)\r\n\texit()\r\n# minn=inf\r\n# for key in dic:\r\n# \tminn=min(key,minn)\r\n\r\n# for i in dic[minn]:\r\n# \tprint(str(i)+' ',end='')\r\n\r\n\t\r\n\r\n\r\n\r\n", "import heapq\r\n\r\ndef shortest_path(graph, start, end):\r\n n = len(graph)\r\n visited = [False] * n\r\n distances = [float('inf')] * n\r\n previous = [-1] * n\r\n distances[start] = 0\r\n min_heap = [(0, start)]\r\n\r\n while min_heap:\r\n current_distance, current_node = heapq.heappop(min_heap)\r\n\r\n if visited[current_node]:\r\n continue\r\n\r\n visited[current_node] = True\r\n\r\n for neighbor, weight in graph[current_node]:\r\n distance = current_distance + weight\r\n\r\n if distance < distances[neighbor]:\r\n distances[neighbor] = distance\r\n previous[neighbor] = current_node\r\n heapq.heappush(min_heap, (distance, neighbor))\r\n\r\n if distances[end] == float('inf'):\r\n return None\r\n\r\n path = []\r\n current_node = end\r\n while current_node != -1:\r\n path.append(current_node)\r\n current_node = previous[current_node]\r\n\r\n return reversed(path)\r\n\r\nn, m = map(int, input().split())\r\ngraph = [[] for _ in range(n)]\r\n\r\nfor _ in range(m):\r\n a, b, w = map(int, input().split())\r\n graph[a - 1].append((b - 1, w))\r\n graph[b - 1].append((a - 1, w))\r\n\r\npath = shortest_path(graph, 0, n - 1)\r\n\r\nif path:\r\n print(*[x + 1 for x in path])\r\nelse:\r\n print(-1)\r\n", "import heapq\n\nn, m = map(int, input().split())\n\nadj = [[] for _ in range(n + 3)]\ndist = [float('inf')] * (n + 1)\nparent = [-1] * (n + 1)\nvisited = [False] * (n + 1)\n\ndef dijkstra(start, target):\n pq = []\n heapq.heappush(pq, (0, start))\n dist[start] = 0\n\n while pq:\n cost, u = heapq.heappop(pq)\n if u == target:\n return True\n visited[u] = True\n for v, w in adj[u]:\n if not visited[v] and dist[u] + w < dist[v]:\n dist[v] = dist[u] + w\n heapq.heappush(pq, (dist[v], v))\n parent[v] = u\n\n return False\n\nfor _ in range(m):\n u, v, w = map(int, input().split())\n adj[u].append((v, w))\n adj[v].append((u, w))\n\nif dijkstra(1, n):\n path = []\n v = n\n while v != -1:\n path.append(v)\n v = parent[v]\n\n path.reverse()\n\n for i in range(len(path) - 1):\n print(path[i], end=' ')\n\n print(path[-1])\nelse:\n print(\"-1\")\n", "import heapq\r\n\r\n\r\ndef Dijkstra(start):\r\n heap = [(0, start)]\r\n distance[start] = 0\r\n while len(heap) > 0:\r\n dist, u = heapq.heappop(heap)\r\n for w, v in graph[u]:\r\n if dist + w < distance[v]:\r\n distance[v] = dist + w\r\n path[v] = u\r\n heapq.heappush(heap, (distance[v], v))\r\n\r\n\r\nn, m = map(int, input().split())\r\ngraph = [[] for _ in range(n+1)]\r\ndistance = [float('inf') for _ in range(n+1)]\r\npath = [-1 for _ in range(n+1)]\r\nres = []\r\nfor _ in range(m):\r\n u, v, w = map(int, input().split())\r\n graph[u].append((w, v))\r\n graph[v].append((w, u))\r\n\r\nDijkstra(1)\r\n\r\nres = [n]\r\nlast = n\r\nif path[n] == -1:\r\n print(-1)\r\nelse:\r\n while res[-1] != 1:\r\n res.append(path[last])\r\n last = path[last]\r\n res.reverse()\r\n print(*res)\r\n\r\n\r\n", "#!/usr/bin/env python3\n\n# ---------------------------------------------------\n# problems/codeforces/secret-combination/Disjkstra.py\n# Copyright (C) 2015\n# Glenn P. Downing\n# ---------------------------------------------------\n\n\"\"\"\nC. Dijkstra?\nhttp://codeforces.com/problemset/problem/20/C/\n\nThu, 8 Oct 2015\nPython 3.4: 764 ms\n\"\"\"\n\nfrom heapq import heappop, heappush\nfrom sys import stdin\n\ndef make_graph (m) :\n graph = {}\n\n for i in range(m) :\n s = input()\n u, v, w = (int(t) for t in s.split())\n\n if u not in graph :\n graph[u] = {}\n\n if v not in graph :\n graph[v] = {}\n\n graph[u][v] = w\n graph[v][u] = w\n\n return graph\n\nclass node :\n @staticmethod\n def init_distance () :\n node.dist_dict = {}\n\n def __init__ (self, vertex) :\n self.vertex = vertex\n\n def __lt__ (self, rhs) :\n return node.dist_dict[self.vertex] < node.dist_dict[rhs.vertex]\n\ndef find_path (graph, begin_vertex, end_vertex) :\n node.init_distance()\n\n queue = []\n path_dict = {end_vertex : end_vertex}\n node.dist_dict[end_vertex] = 0\n heappush(queue, node(end_vertex))\n\n while queue :\n from_vertex = heappop(queue).vertex\n\n if from_vertex == begin_vertex :\n return path_dict\n\n if from_vertex in graph :\n for to_vertex in graph[from_vertex] :\n distance = node.dist_dict[from_vertex] + graph[from_vertex][to_vertex]\n if (to_vertex not in node.dist_dict) or (distance < node.dist_dict[to_vertex]) :\n path_dict[to_vertex] = from_vertex\n node.dist_dict[to_vertex] = distance\n heappush(queue, node(to_vertex))\n\ndef test_case (n, m) :\n begin_vertex = 1\n end_vertex = n\n graph = make_graph(m)\n path_dict = find_path(graph, begin_vertex, end_vertex)\n\n if begin_vertex not in node.dist_dict :\n print(\"-1\")\n return\n\n path_list = [begin_vertex]\n\n while begin_vertex != end_vertex :\n begin_vertex = path_dict[begin_vertex]\n path_list.append(begin_vertex)\n\n print(\" \".join(str(v) for v in path_list))\n\ndef main () :\n for s in stdin :\n n, m = (int(t) for t in s.split())\n test_case(n, m)\n\nif __name__ == \"__main__\" :\n main()\n", "from heapq import heappush, heappop\r\nfrom sys import stdin, exit\r\n \r\n#Respectively, n nodes and m edges\r\nn, m = map(int, stdin.readline().rstrip().split())\r\n \r\ngraph = {} #Initializes graph\r\nvisited = set() #Intializes visited set\r\npath_exists = False #Initializes boolean to track if there is a path\r\n \r\n#Loops through each edge\r\nfor line in range(0, m):\r\n a, b, w = map(int, stdin.readline().rstrip().split())\r\n \r\n #Populates undirected graph, so node a the key for a value tuple of neighbor and edge weight. Same for node b.\r\n if a not in graph:\r\n graph[a] = [(b,w)]\r\n else:\r\n graph[a].append((b, w))\r\n if b not in graph:\r\n graph[b] = [(a, w)]\r\n else:\r\n graph[b].append((a, w))\r\n \r\n#At this point, graph built\r\nif 1 not in graph:\r\n print(str(-1))\r\n exit()\r\n \r\npriority_q = [] #Initializes priority queue for Dijkstra's\r\nheappush(priority_q,(0, 1, -1)) #First adds tuple of the priority cost of the node, node label 1, and \"null\" prev to priority queue\r\npath = \"\" #Initializes path variable to return\r\npath_so_far = {} #Initializes dictionary w/ node label as key, and value tuple of (edge_weight, prev node)\r\n \r\n \r\nwhile priority_q: #While priority queue not empty\r\n current = heappop(priority_q) #Pops off the element in queue\r\n #Current node label hasn't been visited\r\n if current[1] not in visited:\r\n path_so_far[current[1]] = (current[0], current[2]) # node label: (edge_weight, prev_node)\r\n if current[1] == n: #If current node is the goal node n\r\n path_exists = True #yes, path\r\n break #Stop search\r\n else: #Current node is not goal node n\r\n visited.add(current[1]) #Add node label to visited set\r\n for neighbor, priority in graph[current[1]]: #Pushes current node's neighbors and priorities onto priority queue\r\n heappush(priority_q,(priority + current[0], neighbor, current[1])) #Must update priority cost of neighbor and prev node label\r\n \r\n \r\n#Here, priority queue is empty\r\npath_stack = []\r\npath_stack.append(n) #Starts from end node and traverses backwards to print path, following cheapest dest.\r\n \r\none_not_in = False\r\n \r\nif path_exists:\r\n while not one_not_in:\r\n prev_node = path_so_far[path_stack[len(path_stack)-1]]\r\n if prev_node[1] == 1:\r\n one_not_in = True\r\n path_stack.append(prev_node[1])\r\n while path_stack:\r\n print(path_stack.pop(), end = \" \")\r\nelse:\r\n print(str(-1))", "import heapq\r\n\r\ndef dijkstra(adj_list, n):\r\n # Initialize distance list with a large value for all nodes except the source node\r\n dist = [float('inf')] * (n+1)\r\n dist[1] = 0\r\n \r\n # Create a priority queue (heap) to store the nodes with their tentative distance from the source node\r\n heap = [(0, 1)]\r\n \r\n while heap:\r\n curr_dist, curr_node = heapq.heappop(heap)\r\n \r\n # Check if current distance is greater than stored distance, then continue with the next node\r\n if curr_dist > dist[curr_node]:\r\n continue\r\n \r\n # Iterate through all the adjacent nodes of current node\r\n for adj_node, adj_dist in adj_list[curr_node]:\r\n # Calculate the tentative distance from the source node to adjacent node\r\n tentative_dist = curr_dist + adj_dist\r\n \r\n # Update the distance of the adjacent node if it's smaller than the stored distance\r\n if tentative_dist < dist[adj_node]:\r\n dist[adj_node] = tentative_dist\r\n heapq.heappush(heap, (tentative_dist, adj_node))\r\n \r\n # If distance to the destination node is still infinite, then there is no path from source to destination\r\n if dist[n] == float('inf'):\r\n return -1\r\n \r\n # Else return the shortest path\r\n path = []\r\n curr_node = n\r\n while curr_node != 1:\r\n path.append(curr_node)\r\n for adj_node, adj_dist in adj_list[curr_node]:\r\n if dist[adj_node] == dist[curr_node] - adj_dist:\r\n curr_node = adj_node\r\n break\r\n path.append(1)\r\n \r\n return path[::-1]\r\n\r\n# Driver code\r\nn, m = map(int, input().split())\r\nadj_list = [[] for _ in range(n+1)]\r\nfor _ in range(m):\r\n a, b, w = map(int, input().split())\r\n adj_list[a].append((b, w))\r\n adj_list[b].append((a, w))\r\n\r\nshortest_path = dijkstra(adj_list, n)\r\n\r\nif shortest_path == -1:\r\n print(-1)\r\nelse:\r\n print(*shortest_path)\r\n", "from heapq import *\nfrom sys import *\nf = lambda: map(int, stdin.readline().split())\ninf = 1 << 40\nn, m = f()\nk = n + 1\ng = [[] for i in range(k)]\nfor j in range(m):\n u, v, l = f()\n g[u].append((v, l))\n g[v].append((u, l))\nd = [inf] * k\nd[1] = 0\np = [0] * k\nq = [1]\nwhile q:\n h = heappop(q)\n v, l = h % k, h // k\n if d[v] != l: continue\n if v == n: break\n for u, l in g[v]:\n s = d[v] + l\n if s < d[u]:\n d[u], p[u] = s, v\n heappush(q, k * s + u)\nif d[n] == inf:\n print(-1)\nelse:\n u, t = n, []\n while u:\n t.append(u)\n u = p[u]\n t.reverse()\n print(' '.join(map(str, t)))\n\t\t\t\t \t\t\t\t\t \t\t\t \t\t\t \t\t \t \t\t\t\t", "import heapq\n\ngraph = [[] for _ in range(100005)]\npq = []\nshortest_paths = [99999999999] * 100005\nvisited = [0] * 100005\npath = []\nprev = [0] * 100005\n\ndef dijkstra(start, end):\n shortest_paths[start] = 0\n prev[1] = -1\n heapq.heappush(pq, (0, start))\n visited[1] = 1\n path.append(1)\n \n while pq:\n dist, node = heapq.heappop(pq)\n \n if node == end:\n return shortest_paths[node]\n \n for neighbor, weight in graph[node]:\n if shortest_paths[node] + weight < shortest_paths[neighbor]:\n shortest_paths[neighbor] = shortest_paths[node] + weight\n prev[neighbor] = node\n heapq.heappush(pq, (shortest_paths[neighbor], neighbor))\n \n return -1\n\nn, m = map(int, input().split())\n\nfor _ in range(m):\n u, v, weight = map(int, input().split())\n graph[u].append((v, weight))\n graph[v].append((u, weight))\n\nlength = dijkstra(1, n)\n\nif length == -1:\n print(\"-1\")\nelse:\n vertex = n\n x = 1\n while vertex != -1:\n path.append(vertex)\n vertex = prev[vertex]\n x += 1\n \n for i in range(len(path) - 1, 0, -1):\n print(path[i], end=\" \")\n \n print()\n path.clear()\n \t \t\t \t\t\t\t \t\t \t \t\t \t \t \t", "from heapq import *\r\nMAX_N = 100005\r\ninf = 1000000000007\r\ndist = [inf for _ in range(MAX_N)]\r\ntrace = [-1 for _ in range(MAX_N)]\r\nadj = [[] for _ in range(MAX_N)]\r\ndef Dijkstra(start):\r\n pq = []\r\n dist[start] = 0\r\n heappush(pq, (0, 1))\r\n while pq:\r\n distance, u = heappop(pq)\r\n if distance != dist[u]:\r\n continue\r\n if u == n:\r\n break\r\n for neighbor in adj[u]:\r\n v, w = neighbor\r\n if dist[v] > dist[u] + w:\r\n dist[v] = dist[u] + w\r\n heappush(pq, (dist[v], v))\r\n trace[v] = u\r\ndef findPath():\r\n if dist[n] == inf:\r\n print(-1)\r\n return\r\n u = n\r\n res = []\r\n while (u != -1):\r\n res.append(u)\r\n u = trace[u]\r\n for i in range(len(res) - 1, -1, -1):\r\n print(res[i], end=' ')\r\n\r\n\r\nn, m = map(int, input().split())\r\nfor i in range(m):\r\n u, v, w = map(int, input().split())\r\n adj[u].append((v, w))\r\n adj[v].append((u, w))\r\nDijkstra(1)\r\nfindPath()", "from collections import defaultdict,deque,Counter,OrderedDict\r\nfrom heapq import heappop,heappush\r\ndef main():\r\n n,m = map(int,input().split())\r\n adj = [[] for i in range(n+1)]\r\n for i in range(m):\r\n a,b,c = map(int,input().split())\r\n adj[a].append((b,c))\r\n adj[b].append((a,c))\r\n\r\n Q,dist,parent = [(0,1)],[10**13]*(n+1),[0]*(n+1)\r\n visited = parent[:]\r\n dist[1] = 0\r\n while Q:\r\n d,v = heappop(Q)\r\n if visited[v]: continue\r\n for (u,w) in adj[v]:\r\n w += d\r\n if not visited[u] and dist[u] > w:\r\n dist[u] = w\r\n parent[u] = v\r\n heappush(Q,(w,u))\r\n visited[v] = 1\r\n if not parent[n]:\r\n print(\"-1\")\r\n else:\r\n res,v = [],n\r\n while v != 0:\r\n res.append(v)\r\n v = parent[v]\r\n print(\" \".join(map(str,reversed(res))))\r\n\r\nif __name__ == \"__main__\":\r\n main()", "from collections import defaultdict,deque\r\nfrom heapq import heappush,heappop\r\n \r\nn,k = list(map(int,input().split()))\r\ngraph = defaultdict(list)\r\nfor _ in range(k):\r\n a,b,w = list(map(int,input().split()))\r\n graph[a].append([w,b])\r\n graph[b].append([w,a])\r\n \r\nparent = [-1]*(n+1)\r\ndist = [float(\"inf\")]*(n+1)\r\ndist[1] = 0\r\nminHeap = [(0, 1)]\r\nvisited = set()\r\n\r\nwhile minHeap:\r\n weight, node = heappop(minHeap)\r\n visited.add(node)\r\n for cost,neighbour in graph[node]:\r\n newCost = weight + cost\r\n if newCost < dist[neighbour] and neighbour not in visited:\r\n dist[neighbour] = newCost\r\n heappush(minHeap,(newCost, neighbour))\r\n parent[neighbour] = node\r\n\r\nif dist[n] < float('inf'): \r\n queue = deque()\r\n i = n\r\n while i != 1:\r\n queue.appendleft(i)\r\n i = parent[i]\r\n queue.appendleft(1)\r\n print(\" \".join([str(node) for node in queue])) \r\nelse:\r\n print(-1)", "import heapq\n\ndef dijkstra(vertice, vertice2):\n distancia[vertice] = 0\n predecessor[vertice] = -1\n heapq.heappush(heap, (0, vertice))\n\n while len(heap) > 0:\n hd = heapq.heappop(heap)\n v = hd[1]\n if visitados.get(v) == None:\n visitados[v] = True\n if v == vertice2:\n return True\n for e in adj[v]:\n u = e[0]\n peso = e[1]\n if distancia[v] + peso < distancia[u]:\n distancia[u] = distancia[v] + peso\n predecessor[u] = v\n heapq.heappush(heap, (distancia[u], u))\n return False\n\nINF = 100000000000000000000000000000\nentrada = input().split()\nn = int(entrada[0])\nm = int(entrada[1])\nadj = [[] for i in range(n + 1)]\npredecessor = [-1 for i in range(n + 1)]\ndistancia = [INF for i in range(n + 1)]\nheap = []\nvisitados = {}\n\ni = 0\nwhile i < m:\n aresta = list(map(int, input().split()))\n a = aresta[0]\n b = aresta[1]\n peso = aresta[2]\n adj[a].append((b, peso))\n adj[b].append((a, peso))\n i += 1\n\nexisteCaminho = dijkstra(1, n) # Encontrando o menor caminho do vertice 1 à todos os vertices.\n\ni = n\ncaminho = [] # Menor caminho de 1 a n\nif existeCaminho:\n while i != -1:\n caminho.append(i)\n i = predecessor[i]\n caminho.reverse()\n print(*caminho)\nelse:\n print(-1)", "from math import inf\r\nfrom collections import *\r\nimport math, os, sys, heapq, bisect, random\r\nfrom functools import lru_cache\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=1000000007,998244353\r\n\r\ndef main():\r\n how_much_noob_I_am=1\r\n #how_much_noob_I_am=int(input())\r\n for _ in range(how_much_noob_I_am):\r\n n,m = sep()\r\n d=defaultdict(list)\r\n for i in range(m):\r\n a,b,w=sep()\r\n d[a].append([b,w])\r\n d[b].append([a,w])\r\n dist=[inf]*(n+1)\r\n q=[]\r\n heapq.heappush(q,[0,1])\r\n par=[-1]*(n+1)\r\n while(q):\r\n dis,s=heapq.heappop(q)\r\n for i in d[s]:\r\n p,qq=i[0],i[1]\r\n if dis+qq<dist[p]:\r\n par[p] = s\r\n dist[p] = dis+qq\r\n heapq.heappush(q,[dist[p],p])\r\n if par[n]==-1:\r\n print(-1)\r\n continue\r\n ans=[n]\r\n p = n\r\n while(p!=1):\r\n p=par[p]\r\n ans.append(p)\r\n ans.reverse()\r\n print(*ans)\r\nif __name__ == '__main__':\r\n main()\r\n", "from heapq import *\r\nn, m = map(int, input().split())\r\ndis = [1000000000000000] * (n - 1) + [0]\r\nq = [(0, n-1)]\r\nadj = [[] for _ in range(n)]\r\npre = [n] * n\r\n\r\nfor i in range(m):\r\n u, v, w = map(int, input().split())\r\n adj[u-1].append((v, w))\r\n adj[v-1].append((u, w))\r\n\r\nwhile q:\r\n w, u = heappop(q)\r\n if u == 0:\r\n break\r\n for v, cost in adj[u]:\r\n if dis[v-1] > w + cost:\r\n dis[v-1] = w + cost\r\n pre[v-1] = u\r\n heappush(q, (dis[v-1], v-1))\r\n\r\npos = 0\r\nlst = []\r\nwhile pos <= n - 1:\r\n lst.append(pos + 1)\r\n pos = pre[pos]\r\n\r\nif lst[len(lst)-1] == n:\r\n print(*[i for i in lst])\r\nelse:\r\n print(-1)", "from heapq import *\r\nn, m = map(int, input().split())\r\n\r\ndist = [10**15 for i in range(n+1)]\r\nG = [[] for i in range(n+1)]\r\n\r\nfor i in range(m):\r\n u, v, w = map(int, input().split()) \r\n G[u].append((v, w))\r\n G[v].append((u, w))\r\n \r\nunused = [(0, 1)] \r\nparent = [-1 for i in range(n+1)]\r\ndist[1] = 0\r\nmin_dist = 0\r\nnex = 1\r\n\r\nwhile unused:\r\n nex = heappop(unused)[1]\r\n \r\n for edge in G[nex]:\r\n to = edge[0]\r\n wt = edge[1]\r\n \r\n if dist[nex] + wt < dist[to]:\r\n dist[to] = dist[nex] + wt\r\n parent[to] = nex\r\n heappush(unused, (dist[to], to))\r\n \r\n\r\ni = n\r\nans = []\r\n\r\nif parent[i] == -1:\r\n print(-1)\r\nelse:\r\n \r\n while i != -1:\r\n ans.append(i)\r\n i = parent[i]\r\n \r\n ans.reverse()\r\n print(*ans)\r\n", "from heapq import *\r\nimport sys\r\ninput=sys.stdin.readline\r\nn,m=map(int,input().split())\r\ng=[[] for i in range(n+1)]\r\nfor i in range(m):\r\n\tx,y,w=map(int,input().split())\r\n\tif x!=y:\r\n\t\tg[x].append((y,w))\r\n\t\tg[y].append((x,w))\r\npath=[i for i in range(n+1)]\r\ndis=[10**12]*(n+1)\r\nhp=[(0,1)]\r\nwhile hp:\r\n\tdcur,cur=heappop(hp)\r\n\tfor v,w in g[cur]:\r\n\t\tif dcur+w<dis[v]:\r\n\t\t\tdis[v]=dcur+w\r\n\t\t\tpath[v]=cur\r\n\t\t\theappush(hp,(dis[v],v))\r\nl=[n]\r\nx=n\r\nif dis[n]!=10**12:\r\n\twhile x!=1:\r\n\t\tx=path[x]\r\n\t\tl.append(x)\r\n\tprint(*l[::-1])\r\nelse:print(-1)", "import heapq\n\n\ndef dijkstra(start, maxval, adj):\n queue = [(0, start, -1)]\n dist = [(maxval, -1)] * len(adj)\n visited = [False] * len(adj)\n while len(queue) > 0:\n d, n, f = heapq.heappop(queue)\n if not visited[n]:\n visited[n] = True\n dist[n] = (d, f)\n for m, w in adj[n]:\n if not visited[m]:\n heapq.heappush(queue, (d + w, m, n))\n return dist\n\n\nmaxval = float('Inf')\nv, e = map(int, input().split())\n\nadj = [[] for _ in range(v)]\nfor _ in range(e):\n a, b, w = map(int, input().split())\n a -= 1\n b -= 1\n adj[a].append((b, w))\n adj[b].append((a, w))\n\ndist = dijkstra(\n 0,\n maxval,\n adj\n)\n\ncurrent = dist[v-1]\nvisits = [v]\nwhile current[0] != 0:\n if current[0] == maxval:\n print(-1)\n exit()\n visits.append(current[1] + 1)\n current = dist[current[1]]\nprint(\" \".join(map(str, reversed(visits))))\n", "import heapq\r\n\r\ndef shortest_path(graph, n):\r\n distance = [float('inf')] * (n + 1)\r\n distance[1] = 0\r\n pq = [(0, 1)]\r\n path = [-1] * (n + 1)\r\n\r\n while pq:\r\n dist, node = heapq.heappop(pq)\r\n if dist > distance[node]:\r\n continue\r\n for neighbor, weight in graph[node]:\r\n if distance[node] + weight < distance[neighbor]:\r\n distance[neighbor] = distance[node] + weight\r\n heapq.heappush(pq, (distance[neighbor], neighbor))\r\n path[neighbor] = node\r\n\r\n if path[n] == -1:\r\n return -1\r\n\r\n shortest_path = []\r\n current = n\r\n while current != -1:\r\n shortest_path.append(current)\r\n current = path[current]\r\n shortest_path.reverse()\r\n\r\n return shortest_path\r\n\r\nn, m = map(int, input().split())\r\ngraph = [[] for _ in range(n + 1)]\r\nfor _ in range(m):\r\n a, b, c = map(int, input().split())\r\n graph[a].append((b, c))\r\n graph[b].append((a, c))\r\n\r\nresult = shortest_path(graph, n)\r\n\r\nif result == -1:\r\n print(-1)\r\nelse:\r\n print(' '.join(map(str, result)))\r\n", "from heapq import *\r\n\r\nINF = 1 << 60\r\n\r\nn, m = map(int, input().split())\r\n# n, m = 6, 9\r\n\r\nd = [INF] * (n + 1)\r\nS = [False] * (n+1)\r\nadj = [[] for _ in range(n+1)]\r\n# print(adj)\r\n# adj = [[], [(5, 2), (4, 3)], [(2, 6), (1, 4), (5, 1)],\r\n# [(4, 1), (2, 5), (3, 4)], [(1, 2), (3, 3), (3, 5), (4, 6)],\r\n# [(2, 3), (3, 4), (2, 6)], [(2, 2), (2, 5), (4, 4)]]\r\n\r\nq = []\r\npar = [0] * (n+1)\r\n\r\nfor _ in range(m):\r\n u, v, w = map(int, input().split())\r\n adj[u].append((w, v))\r\n adj[v].append((w, u))\r\n\r\n\r\ndef find_path(v):\r\n p = []\r\n while v != 0:\r\n p.append(v)\r\n v = par[v]\r\n p.reverse()\r\n return p\r\n\r\n\r\nstarting_vertex = 1\r\nd[starting_vertex] = 0\r\nheappush(q, (0, starting_vertex))\r\n\r\nwhile len(q) > 0:\r\n u = heappop(q)[1]\r\n if S[u]:\r\n continue\r\n S[u] = True\r\n\r\n for w, v in adj[u]:\r\n if d[v] > d[u] + w:\r\n d[v] = d[u] + w\r\n par[v] = u\r\n heappush(q, (d[v], v))\r\n\r\nif par[n] == 0:\r\n print(-1)\r\nelse:\r\n print(' '.join(map(str, find_path(n))))\r\n\r\n\r\n\r\n", "# =============== author: kuanc | created: 05/05/22 03:17:10 =============== #\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# from pypyjit import set_param\r\n# set_param(\"max_unroll_recursion=-1\")\r\n# setrecursionlimit(300005)\r\nINF = 1 << 60\r\nMOD = 10 ** 9 + 7\r\n# MOD = 998244353\r\ninput = lambda: stdin.readline().rstrip(\"\\r\\n\")\r\ndbg = lambda *A, **M: stderr.write(\"\\033[91m\" + \\\r\n M.get(\"sep\", \" \").join(map(str, A)) + M.get(\"end\", \"\\n\") + \"\\033[0m\")\r\n# ============================ START OF MY CODE ============================ #\r\n\r\nclass Node:\r\n def __init__(self, key, val=None):\r\n # min heap based on key\r\n self.key = key\r\n self.val = val\r\n self.par = self.chd = self.bro = None\r\n\r\n\r\nclass PairingHeap:\r\n def __init__(self):\r\n self.rt = None\r\n self.sz = 0\r\n\r\n def __bool__(self) -> bool:\r\n return bool(self.sz != 0)\r\n\r\n def __len__(self) -> int:\r\n return self.sz\r\n\r\n @property\r\n def top(self) -> Node:\r\n assert self.sz > 0, \"top from empty pairing heap\"\r\n\r\n return self.rt\r\n\r\n def pop(self) -> Node:\r\n assert self.sz > 0, \"pop from empty pairing heap\"\r\n\r\n rt = self.rt\r\n self.rt = self._pair(self.rt.chd)\r\n self.sz -= 1\r\n rt.par = rt.chd = rt.bro = None\r\n return rt\r\n\r\n def push(self, node: \"Node\"):\r\n \"\"\"return a pointer to the node containing the new value\"\"\"\r\n\r\n self.rt = node if self.rt is None else self._merge(self.rt, node)\r\n self.sz += 1\r\n\r\n def merge(self, other: \"PairingHeap\"):\r\n \"\"\"merge with another pairing heap\"\"\"\r\n\r\n self.rt = self._merge(self.rt, other.rt)\r\n self.sz += other.sz\r\n\r\n def decrease(self, node: Node, key: int):\r\n \"\"\"given pointer to a node, assign its key with a smaller one\"\"\"\r\n\r\n assert key <= node.key, \"new key {} should be less than or equal \" \\\r\n \"to original key {}.\".format(key, node.key)\r\n node.key = key\r\n if node != self.rt:\r\n if node.par.chd == node:\r\n node.par.chd = node.bro\r\n else:\r\n node.par.bro = node.bro\r\n if node.bro:\r\n node.bro.par = node.par\r\n node.par = node.bro = None\r\n self.rt = self._merge(self.rt, node)\r\n\r\n def _pair(self, node):\r\n arr = []\r\n while node and node.bro:\r\n cur, nxt = node.bro, node.bro.bro\r\n node.par = node.bro = cur.par = cur.bro = None\r\n arr.append(self._merge(node, cur))\r\n node = nxt\r\n if node:\r\n node.bro = node.par = None\r\n arr.reverse()\r\n return reduce(self._merge, arr, node)\r\n\r\n @staticmethod\r\n def _merge(a, b):\r\n if a is None:\r\n return b\r\n if b is None:\r\n return a\r\n if a.key > b.key:\r\n a, b = b, a\r\n b.bro, a.chd = a.chd, b\r\n if b.bro:\r\n b.bro.par = b\r\n b.par = a\r\n return a\r\n\r\n\r\ndef solve():\r\n def dijkstra(n, G, start):\r\n # O(V + ElogV)\r\n dist = [-1 for _ in range(n)]\r\n prev = [-1 for _ in range(n)]\r\n dist[start] = 0\r\n ph = PairingHeap()\r\n val2node = {start: Node(0, start)}\r\n ph.push(val2node[start])\r\n while ph:\r\n node = ph.pop()\r\n d, u = node.key, node.val\r\n if d != dist[u]:\r\n continue\r\n for (v, w) in G[u]:\r\n if dist[v] == -1 or d + w < dist[v]:\r\n dist[v] = d + w\r\n prev[v] = u\r\n if v not in val2node:\r\n val2node[v] = Node(dist[v], v)\r\n ph.push(val2node[v])\r\n else:\r\n ph.decrease(val2node[v], dist[v])\r\n return dist, prev\r\n\r\n def path_restore_1d(prev, start, end):\r\n path = []\r\n cur = end\r\n while cur != -1:\r\n path.append(cur)\r\n cur = prev[cur]\r\n path.reverse()\r\n return path\r\n\r\n N, M = map(int, input().split())\r\n\r\n adj = defaultdict(list)\r\n for _ in range(M):\r\n u, v, w = map(int, input().split())\r\n u -= 1; v -= 1\r\n adj[u].append((v, w))\r\n adj[v].append((u, w))\r\n\r\n D, P = dijkstra(N, adj, 0)\r\n if D[N - 1] == -1:\r\n print(-1)\r\n else:\r\n path = path_restore_1d(P, 0, N - 1)\r\n print(*[v + 1 for v in path])\r\n\r\n\r\nif __name__ == \"__main__\":\r\n solve()\r\n", "import sys, os.path\nfrom collections import*\nfrom heapq import *\nfrom copy import*\nimport math\ninput=sys.stdin.buffer.readline\n\nn,m = map(int, input().split())\ng = defaultdict(list)\n\nfor i in range(m):\n\ta,b,w = map(int, input().split())\n\tg[a].append((b,w))\n\tg[b].append((a,w))\n\nvis = set()\ndis = [10000000000000000 for i in range(n+1)]\ndis[0] = 0\ndis[1] = 0\nhp = [(0,1)]\nparent = [-1 for i in range(n+1)]\n\nwhile(len(hp)>0):\n\tdistu, u = heappop(hp)\n\tfor i in g[u]:\n\t\tv = i[0]\n\t\twt = i[1]\n\t\tif(dis[v]>dis[u]+wt):\n\t\t\tparent[v] = u\n\t\t\tdis[v] = dis[u]+wt\n\t\t\theappush(hp, (dis[v], v))\n\npath=[]\nlast=n\nif(parent[n]==-1):\n\tprint(\"-1\")\nelse:\n\twhile(last!=-1):\n\t\tpath.append(last)\n\t\tlast = parent[last]\n\tpath.reverse()\n\tprint(*path)", "from heapq import heappush, heappop\n\ndef Dijkstra(graph,source,n):\n q = []\n dist=[float('inf')]*(n + 1)\n visited=[False]*(n + 1)\n prev=[-1]*(n + 1)\n conn = False\n dist[source]=0\n heappush(q, (dist[source],source))\n while len(q)!=0:\n poped=heappop(q)\n d=poped[0]\n u=poped[1]\n if visited[u]==True:\n continue\n else:\n visited[u]=True\n for (v, w) in graph[u]:\n alt = d + w\n if alt < dist[v]:\n dist[v] = alt\n prev[v] = u\n heappush(q, (alt,v))\n if u == n:\n conn = True\n break\n return conn,prev\n\n\ndef output(n,tup):\n if tup[0]:\n p = []\n a = n\n while a != -1:\n p.append(a)\n a = tup[1][a]\n p.reverse()\n print(' '.join(map(str, p)))\n else:\n print(-1)\n \n \n\ns=input()\ns=s.split(\" \")\nn = int(s[0])\nm = int(s[1])\ngraph = [[] for i in range(n + 1)]\nfor i in range(m):\n a= input()\n a=a.split(\" \")\n key=int(a[0])\n node = int(a[1])\n weight = int(a[2])\n graph[key].append((node, weight)) \n graph[node].append((key, weight))\n \noutput(n,Dijkstra(graph,1,n))\n \t \t \t\t\t\t \t\t \t \t\t \t \t \t \t", "from heapq import heappop, heappush\r\nfrom math import inf\r\nfrom sys import stdin\r\n\r\n\r\ndef dijkstra(graph, start):\r\n dist = [inf] * len(graph)\r\n dist[start] = 0\r\n\r\n parent = [-1] * len(graph)\r\n q = [(0, start)]\r\n\r\n while q:\r\n d, u = heappop(q)\r\n if d > dist[u]:\r\n continue\r\n\r\n for v, w in graph[u]:\r\n if d + w < dist[v]:\r\n dist[v] = d + w\r\n parent[v] = u\r\n heappush(q, (dist[v], v))\r\n\r\n return parent\r\n\r\n\r\ndef solve():\r\n n, m = map(int, stdin.readline().split())\r\n if n == 1:\r\n print(1)\r\n return\r\n\r\n graph = [[] for _ in range(n + 1)]\r\n for _ in range(m):\r\n u, v, w = map(int, stdin.readline().split())\r\n graph[u].append((v, w))\r\n graph[v].append((u, w))\r\n\r\n parent = dijkstra(graph, 1)\r\n if parent[n] == -1:\r\n print(-1)\r\n return\r\n\r\n res = [n]\r\n while parent[res[-1]] != -1:\r\n res.append(parent[res[-1]])\r\n\r\n print(*res[::-1])\r\n\r\n\r\nsolve()\r\n", "#!/usr/bin/env python3\n\n# ---------------------------------------------------\n# problems/codeforces/secret-combination/Disjkstra.py\n# Copyright (C) 2015\n# Glenn P. Downing\n# ---------------------------------------------------\n\n\"\"\"\nC. Dijkstra?\nhttp://codeforces.com/problemset/problem/20/C/\n\nThu, 8 Oct 2015\nPython 3.4: 764 ms\n\"\"\"\n\nfrom heapq import heappop, heappush\nfrom sys import stdin\n\ndef make_graph (m) :\n graph = {}\n\n for i in range(m) :\n s = input()\n u, v, w = (int(t) for t in s.split())\n\n if u not in graph :\n graph[u] = {}\n\n if v not in graph :\n graph[v] = {}\n\n graph[u][v] = w\n graph[v][u] = w\n\n return graph\n\nclass vertex_distance_type :\n @staticmethod\n def init_distance () :\n vertex_distance_type.distance = {}\n\n def __init__ (self, vertex) :\n self.vertex = vertex\n\n def __lt__ (self, rhs) :\n return vertex_distance_type.distance[self.vertex] < vertex_distance_type.distance[rhs.vertex]\n\ndef find_path (graph, begin_vertex, end_vertex) :\n vertex_distance_type.init_distance()\n\n queue = []\n predecessor = {end_vertex : end_vertex}\n vertex_distance_type.distance[end_vertex] = 0\n heappush(queue, vertex_distance_type(end_vertex))\n\n while queue :\n from_vertex = heappop(queue).vertex\n\n if from_vertex == begin_vertex :\n path = [begin_vertex]\n\n while from_vertex != end_vertex :\n from_vertex = predecessor[from_vertex]\n path.append(from_vertex)\n\n return path\n\n if from_vertex in graph :\n for to_vertex in graph[from_vertex] :\n distance = vertex_distance_type.distance[from_vertex] + graph[from_vertex][to_vertex]\n if (to_vertex not in vertex_distance_type.distance) or (distance < vertex_distance_type.distance[to_vertex]) :\n predecessor[to_vertex] = from_vertex\n vertex_distance_type.distance[to_vertex] = distance\n heappush(queue, vertex_distance_type(to_vertex))\n\n return [-1]\n\ndef test_case (n, m) :\n begin_vertex = 1\n end_vertex = n\n graph = make_graph(m)\n path = find_path(graph, begin_vertex, end_vertex)\n print(\" \".join(str(v) for v in path))\n\ndef main () :\n for s in stdin :\n n, m = (int(t) for t in s.split())\n test_case(n, m)\n\nif __name__ == \"__main__\" :\n main()\n", "from heapq import heappush, heappop\nn, m = map(int, input().split())\ng = {i: [] for i in range(n)}\n\nfor i in range(m):\n a, b, w = map(int, input().split())\n\n g[a-1].append([b-1, w])\n g[b-1].append([a-1, w])\n\nparent = [-1 for i in range(n)]\ndist = [float('inf') for i in range(n)]\n\nvis = set()\n\nd = []\nd.append((0, 0))\ndist[0] = 0\n\nwhile d:\n w, pos = heappop(d)\n vis.add(pos)\n for i, wi in g[pos]:\n if i not in vis:\n if w + wi < dist[i]:\n dist[i] = w + wi\n parent[i] = pos\n heappush(d, (dist[i], i))\n\nsol = [n-1]\nmid = n-1\n\nwhile parent[mid] != -1:\n sol.append(parent[mid])\n mid = parent[mid]\n\nif sol[-1] != 0:\n print(-1)\nelse:\n sol.reverse()\n for s in sol:\n print(s+1, end=' ')\n\n print('')\n", "import re\r\nimport functools\r\nimport random\r\nimport sys\r\nimport os\r\nimport math\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 io import BytesIO, IOBase\r\nfrom copy import deepcopy\r\nimport threading\r\nfrom typing import *\r\nfrom operator import add, xor, mul, ior, iand, itemgetter\r\nimport bisect\r\nfrom string import ascii_lowercase, ascii_uppercase\r\nBUFSIZE = 4096\r\ninf = float('inf')\r\nif \"PyPy\" in sys.version:\r\n import pypyjit; pypyjit.set_param('max_unroll_recursion=-1')\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\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\nsys.stdin = IOWrapper(sys.stdin)\r\nsys.stdout = IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\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\nfrom types import GeneratorType\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 return wrappedfunc\r\n\r\ndef bitcnt(n):\r\n c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)\r\n c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)\r\n c = (c & 0x0F0F0F0F0F0F0F0F) + ((c >> 4) & 0x0F0F0F0F0F0F0F0F)\r\n c = (c & 0x00FF00FF00FF00FF) + ((c >> 8) & 0x00FF00FF00FF00FF)\r\n c = (c & 0x0000FFFF0000FFFF) + ((c >> 16) & 0x0000FFFF0000FFFF)\r\n c = (c & 0x00000000FFFFFFFF) + ((c >> 32) & 0x00000000FFFFFFFF)\r\n return c\r\n\r\nn, m = MII()\r\npath = [[] for _ in range(n)]\r\nfor _ in range(m):\r\n u, v, w = MII()\r\n u -= 1\r\n v -= 1\r\n path[u].append([v, w])\r\n path[v].append([u, w])\r\n\r\ndist = [inf] * n\r\ndist[0] = 0\r\nhpq = [(0, 0)]\r\nprev = [-1] * n\r\nwhile hpq:\r\n d, p = heappop(hpq)\r\n for newp, w in path[p]:\r\n if d + w < dist[newp]:\r\n dist[newp] = d + w\r\n prev[newp] = p\r\n heappush(hpq, (dist[newp], newp))\r\n\r\nif prev[n-1] == -1: print(-1)\r\nelse:\r\n ans = [n-1]\r\n while prev[ans[-1]] != -1:\r\n ans.append(prev[ans[-1]])\r\n ans.reverse()\r\n print(*[x + 1 for x in ans])", "import sys\r\nimport heapq\r\n\r\ndef readInts(): return [int(x) for x in sys.stdin.readline().split()]\r\n\r\n\r\ndef readInt(): return int(sys.stdin.readline())\r\n\r\n\r\n# def print(x):\r\n# sys.stdout.write(str(x) + '\\n')\r\n\r\n\r\ndef solve():\r\n n, m = readInts()\r\n adj = [[] for _ in range(n)]\r\n for _ in range(m):\r\n u, v, w = readInts()\r\n u -= 1\r\n v -= 1\r\n adj[u].append((v, w))\r\n adj[v].append((u, w))\r\n # print(adj)\r\n\r\n INF = int(1e18)\r\n d = [INF] * n\r\n p = [-1] * n\r\n s = 0\r\n d[s] = 0\r\n\r\n q = [(0, s)]\r\n while len(q) > 0:\r\n pair1 = heapq.heappop(q)\r\n u = pair1[1]\r\n du = pair1[0]\r\n if (du != d[u]):\r\n continue\r\n for pair2 in adj[u]:\r\n v = pair2[0]\r\n w = pair2[1]\r\n if d[u] + w < d[v]:\r\n d[v] = d[u] + w\r\n p[v] = u\r\n heapq.heappush(q, (d[v], v))\r\n\r\n if d[n - 1] == INF:\r\n print(-1)\r\n else:\r\n cur = n - 1\r\n ans = []\r\n while cur != -1:\r\n ans.append(cur)\r\n cur = p[cur]\r\n ans.reverse()\r\n ans = [x + 1 for x in ans]\r\n print(*ans, \" \")\r\n\r\n\r\ndef main():\r\n t = 1\r\n # t = readInt()\r\n for _ in range(t):\r\n solve()\r\n\r\n\r\nmain()\r\n", "from heapq import *\r\ndef dijkstra(d,n):\r\n heap,visited,way,parents=[(0,0)],set(),{0:0},[-1]*(n+1)\r\n while heap:\r\n leng,x=heappop(heap)\r\n if x not in visited:\r\n visited.add(x)\r\n if x==n:break\r\n new=d[x]\r\n for i,elem in enumerate(new):\r\n l=new[elem]\r\n if elem in visited:continue\r\n item=way.get(elem)\r\n if item==None or leng+l<item:\r\n parents[elem]=x\r\n way[elem]=leng+l\r\n heappush(heap,[leng+l,elem])\r\n return parents\r\nfrom sys import stdin\r\ninp=lambda:stdin.readline().split()\r\nn,m=map(int,inp())\r\nd={i:{} for i in range(n)}\r\nfor _ in range(m):\r\n a,b,w=map(int,inp())\r\n if a!=b:\r\n a,b=a-1,b-1\r\n if d[a].get(b)==None:d[a][b]=w;d[b][a]=w\r\n else:\r\n d[a][b]=min(d[a][b],w)\r\n d[b][a]=d[a][b]\r\np=dijkstra(d,n-1)\r\nif p[-1]==-1:print(-1)\r\nelse:\r\n res,x=[],n-1\r\n while x>0:\r\n res.append(x+1)\r\n x=p[x]\r\n res.append(1)\r\n print(*res[::-1])", "from heapq import *\r\nI = 1 << 60\r\n\r\nn, m = map(int, input().split())\r\ng = [[] for _ in range(n)]\r\nd = [0] + [I] * n\r\np = [-1] * n\r\nq = [(0, 0)]\r\nfor i in range(m):\r\n\ta, b, w = map(int, input().split())\r\n\tg[a-1] += [(w, b-1)]\r\n\tg[b-1] += [(w, a-1)]\r\nwhile q:\r\n\ta = heappop(q)[1]\r\n\tfor e in g[a]:\r\n\t\tw, b = d[a] + e[0], e[1]\r\n\t\tif w < d[b]:\r\n\t\t\td[b], p[b] = w, a\r\n\t\t\theappush(q, (d[b], b))\r\nif d[n-1] == I:\r\n\tprint(-1);\r\nelse:\r\n\tx, y = n - 1, []\r\n\twhile x != -1:\r\n\t\ty += [x + 1]\r\n\t\tx = p[x]\r\n\ty.reverse()\r\n\tprint(' '.join(map(str, y)))", "import heapq\n\nn,m = map(int, input().split())\ngraph = {}\nfor _ in range(m):\n a, b, w = map(int, input().split())\n a -= 1\n b -= 1\n if a == b:\n continue\n l = graph.setdefault(a, {})\n l[b] = min([l.setdefault(b, w), w])\n l = graph.setdefault(b, {})\n l[a] = min([l.setdefault(a, w), w])\n\ns, t = 0, n-1\npq = [(0, s)]\ninf = float('inf')\ndist = [inf] * n\ndist[0] = 0\np = [-1] * n\nwhile len(pq) > 0:\n d, v = heapq.heappop(pq)\n if d > dist[v]:\n continue\n if v in graph:\n for u, w in graph[v].items():\n if dist[u] > w + d:\n dist[u] = w + d\n p[u] = v\n heapq.heappush(pq, (w+d, u))\n \nif dist[t] == inf:\n print('-1')\nelse:\n v = t\n path = []\n while v >= 0:\n path.append(v+1)\n v = p[v]\n print(' '.join([str(i) for i in path[::-1]]))\n \t\t \t\t \t\t \t\t \t\t\t\t\t\t\t \t\t\t", "from heapq import *\r\ndef shortestpath(source,target,parent):\r\n i=target\r\n print(i+1,end=\" \")\r\n while i!=source:\r\n print(parent[i]+1,end=\" \")\r\n i=parent[i]\r\ndef update_d(adj_i,d,i,pq,locked,parent):\r\n for j in adj_i:\r\n if d[j[0]]>d[i]+j[1] and not locked[j[0]]:\r\n d[j[0]]=d[i]+j[1] \r\n parent[j[0]]=i\r\n heappush(pq,(d[j[0]],j[0])) \r\ndef Dijkstra(source,target,adj):\r\n n=source+1\r\n parent = [None]*n\r\n locked = [False]*n\r\n d=[float('inf')]*n\r\n d[source]=0\r\n pq = [(0,source)]\r\n i=heappop(pq)[1]\r\n locked[source]=True\r\n update_d(adj[i],d,i,pq,locked,parent) \r\n while pq:\r\n i = heappop(pq)[1]\r\n if locked[i]:continue\r\n locked[i] = True \r\n update_d(adj[i],d,i,pq,locked,parent) \r\n if locked[target]: \r\n shortestpath(source,target,parent)\r\n else:print(-1)\r\nv,k = list(map(int,input().split()))\r\nadj = [[] for i in range(v)]\r\nfor i in range(k):\r\n a,b,c=list(map(int,input().split()))\r\n adj[a-1]+=((b-1,c),)\r\n adj[b-1]+=((a-1,c),)\r\nDijkstra(v-1,0,adj)", "import heapq\r\nfrom collections import defaultdict\r\n\r\ndef dijkstra(n, edges, start, end):\r\n graph = defaultdict(list)\r\n for edge in edges:\r\n a, b, w = edge\r\n graph[a].append((b, w))\r\n graph[b].append((a, w))\r\n\r\n distances = [float('inf')] * (n + 1)\r\n distances[start] = 0\r\n prev = [None] * (n + 1)\r\n\r\n pq = [(0, start)]\r\n while pq:\r\n d, u = heapq.heappop(pq)\r\n if d > distances[u]:\r\n continue\r\n for v, w in graph[u]:\r\n if distances[v] > distances[u] + w:\r\n distances[v] = distances[u] + w\r\n prev[v] = u\r\n heapq.heappush(pq, (distances[v], v))\r\n\r\n if distances[end] == float('inf'):\r\n return -1\r\n\r\n path = []\r\n while end:\r\n path.append(end)\r\n end = prev[end]\r\n return path[::-1]\r\n\r\nn, m = map(int, input().split())\r\nedges = [tuple(map(int, input().split())) for _ in range(m)]\r\npath = dijkstra(n, edges, 1, n)\r\nif path == -1:\r\n print(-1)\r\nelse:\r\n print(' '.join(map(str, path)))\r\n", "# ------------------- fast io --------------------\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# ------------------- fast io --------------------\r\n\r\n# importing priority queue\r\nimport heapq\r\n\r\nn, m = map(int, input().split())\r\n\r\n# declares a double dimensional array(or list?) of size n\r\nadj = [[] for i in range(n)]\r\n\r\nfor i in range(m):\r\n u, v, w = map(int, input().split())\r\n u -= 1\r\n v -= 1\r\n # appending each node as a tuple of (node number, edge weight)\r\n adj[u].append((v, w))\r\n adj[v].append((u, w))\r\n\r\n# declaring infinity as 1e18, note the different typecasting here\r\nINF = int(1e18)\r\n\r\n# declaring arrays of size n, and initializing it with infinity and -1 respectively\r\ndistance = [INF] * n\r\nprevious = [-1] * n\r\n\r\n# declaring a priority queue of tuples\r\npriority_queue = [(0, 0)]\r\n\r\n# main dijkstra code\r\ndistance[0] = 0\r\nwhile priority_queue:\r\n dist, node = heapq.heappop(priority_queue)\r\n if distance[node] < dist:\r\n continue\r\n for edge in adj[node]:\r\n u = edge[0]\r\n edge_length = edge[1]\r\n if distance[u] > dist + edge_length:\r\n distance[u] = dist + edge_length\r\n previous[u] = node\r\n # you need to apparently mention the name of the heap, along with the element... weird.\r\n heapq.heappush(priority_queue, (distance[u], u))\r\n\r\nif distance[n - 1] == INF:\r\n print(-1)\r\nelse:\r\n # declaring an empty list\r\n path = []\r\n current_node = n - 1\r\n while True:\r\n path.append(current_node)\r\n if previous[current_node] == -1:\r\n break\r\n current_node = previous[current_node]\r\n\r\n # reversing a list can be done by just doing this? python is weird.\r\n path.reverse()\r\n\r\n for node in path:\r\n print(node + 1, end=\" \")\r\n", "import sys\r\nfrom heapq import heappush, heappop\r\nfrom collections import defaultdict\r\n\r\n# sys.stdin, sys.stdout = open(\"input.txt\", \"r\"), open(\"output.txt\", \"w\")\r\n\r\ndef main():\r\n n, m = map(int, input().split())\r\n graph = defaultdict(list)\r\n for _ in range(m):\r\n u, v, w = map(int, input().split())\r\n if u == v:\r\n continue\r\n u -= 1\r\n v -= 1\r\n graph[u].append((v, w))\r\n graph[v].append((u, w))\r\n distance = [float(\"inf\") for i in range(n)]\r\n distance[0] = 0\r\n parent = [-1 for i in range(n)]\r\n heap = []\r\n heappush(heap, (0, 0))\r\n while heap:\r\n dist, node = heappop(heap)\r\n for adj, weight in graph[node]:\r\n if distance[adj] > weight + dist:\r\n distance[adj] = weight + dist\r\n parent[adj] = node\r\n heappush(heap, (distance[adj], adj))\r\n if distance[n - 1] == float(\"inf\"):\r\n print(-1)\r\n else:\r\n ans = []\r\n i = n - 1\r\n while i != -1:\r\n ans.append(i + 1)\r\n i = parent[i]\r\n ans.reverse()\r\n print(*ans)\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n, m = map(int, input().split())\r\nG = [[] for i in range(n)]\r\nfor i in range(m):\r\n u, v, w = map(int, input().split())\r\n u -= 1\r\n v -= 1\r\n G[u].append((v, w))\r\n G[v].append((u, w))\r\n\r\nfrom heapq import heappush, heappop\r\nINF = 10 ** 20\r\ndef Dijkstra(G, start=0): \r\n n = len(G)\r\n dis = [INF] * (n + 1) \r\n dis[start] = 0\r\n par = {} \r\n par[start] = -1\r\n vis = [False] * n\r\n qu = [(0, start)]\r\n while qu: \r\n d, v = heappop(qu)\r\n if vis[v]: \r\n continue\r\n if v == n - 1:\r\n break\r\n vis[v] = True\r\n \r\n for u, w in G[v]: \r\n if dis[v] + w < dis[u]:\r\n dis[u] = dis[v] + w \r\n par[u] = v\r\n heappush(qu, (dis[u], u))\r\n \r\n if dis[n - 1] == INF: \r\n print(-1)\r\n else:\r\n path = []\r\n v = n - 1\r\n while v != -1:\r\n path.append(v + 1)\r\n v = par[v]\r\n print(*path[::-1])\r\n return \r\n\r\nDijkstra(G) ", "'''\r\n# Submitted By M7moud Ala3rj\r\nDon't Copy This Code, CopyRight . [email protected] © 2022-2023 :)\r\n'''\r\n# Problem Name = \"Volleyball\"\r\n# Class: C\r\n\r\nimport sys\r\nfrom heapq import *\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\n\r\nInf = float(\"inf\")\r\n\r\ndef naive_dijkstras(graph, root):\r\n global n\r\n dist = [[Inf, None] for _ in range(n+1)]\r\n dist[root] = [0, root]\r\n visited = [False for _ in range(n+1)]\r\n pq = [[0, root]]\r\n while pq:\r\n d, u = heappop(pq)\r\n if not visited[u]:\r\n visited[u] = True\r\n for v, l in graph[u]:\r\n if dist[u][0] + l < dist[v][0]:\r\n dist[v] = [dist[u][0] + l, u]\r\n heappush(pq, [dist[v], v])\r\n return dist\r\n\r\ndef Solve():\r\n global n\r\n n, m = list(map(int, input().split()))\r\n graph = {x: set() for x in range(1, n+1)}\r\n for _ in range(m):\r\n u, v, w = list(map(int, input().split()))\r\n graph[u].add((v, w)) ; graph[v].add((u, w))\r\n \r\n ans = float(\"inf\")\r\n path = naive_dijkstras(graph, 1)\r\n ans = [n]\r\n while ans[-1] != 1:\r\n try:\r\n ans.append(path[ans[-1]][1])\r\n except: exit(print(-1))\r\n print(*ans[::-1])\r\n\r\nif __name__ == \"__main__\":\r\n Solve()", "from cmath import inf\r\nfrom collections import defaultdict\r\nfrom heapq import heappop, heappush\r\nfrom xml.dom import Node\r\n\r\n\r\n\r\ndef solve(n,m,matrix):\r\n \r\n graph = defaultdict(set)\r\n for i,j,k in matrix:\r\n # weight, node\r\n graph[i].add((k,j))\r\n graph[j].add((k,i))\r\n result = [(inf,-1)] * n\r\n result[0] = (0,0)\r\n \r\n \r\n heap = [(0,1)]\r\n \r\n while heap:\r\n weight, node = heappop(heap)\r\n if node == n:\r\n break\r\n for neibor in graph[node]:\r\n if result[neibor[1] -1][0] > weight + neibor[0]:\r\n result[neibor[1] -1] = (weight + neibor[0], node)\r\n heappush(heap, (weight + neibor[0],neibor[1]))\r\n \r\n ans = []\r\n if result[n-1][0] == inf:\r\n return [-1]\r\n else:\r\n curr = n-1\r\n ans.append(curr+1)\r\n while curr!= 0:\r\n curr = result[curr][1] -1\r\n ans.append(curr+1)\r\n return ans[::-1]\r\n \r\nn,m = [int(i) for i in input().split()]\r\nmatrix = []\r\nfor _ in range(m):\r\n matrix.append([int(i) for i in input().split()])\r\nprint(*solve(n,m,matrix))" ]
{"inputs": ["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "2 1\n1 2 1", "3 1\n1 2 1", "3 3\n1 2 1\n1 3 2\n2 3 1", "10 10\n1 5 12\n2 4 140\n2 10 149\n3 6 154\n3 7 9\n3 8 226\n3 10 132\n4 10 55\n5 8 33\n7 8 173", "10 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 179\n3 10 237\n4 8 205\n5 6 191\n8 10 157", "10 10\n1 4 200\n1 9 197\n3 4 79\n3 5 213\n3 6 149\n5 8 3\n5 9 189\n6 7 130\n6 9 51\n8 10 135", "10 10\n1 4 201\n2 3 238\n3 4 40\n3 6 231\n3 8 45\n4 5 227\n4 6 58\n4 9 55\n5 7 14\n6 10 242"], "outputs": ["1 4 3 5 ", "1 4 3 5 ", "1 2 ", "-1", "1 3 ", "1 5 8 7 3 10 ", "1 8 10 ", "1 9 5 8 10 ", "1 4 6 10 "]}
UNKNOWN
PYTHON3
CODEFORCES
147
18731b0885aaff022fbbdb83087c9a43
Lucky Ticket
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals *n* (*n* is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first *n*<=/<=2 digits) equals the sum of digits in the second half (the sum of the last *n*<=/<=2 digits). Check if the given ticket is lucky. The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). Sample Input 2 47 4 4738 4 4774 Sample Output NO NO YES
[ "n = int(input())\r\ns = str(input())\r\na = 0\r\nb = 0\r\n\r\nfor i, num in enumerate(s):\r\n if num != '7' and num != '4':\r\n print(\"NO\")\r\n a=-1\r\n b=-2\r\n break\r\n else:\r\n if i+1<=n/2:\r\n a+=int(num)\r\n else:\r\n b+=int(num)\r\nelse:\r\n if a==b:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "n = int(input())\r\nnum = int(input())\r\nlis = [i for i in str(num)]\r\nlis1 = lis[:int(n/2)]\r\nlis2 = lis[int(n/2):]\r\nlis11 = [int(x) for x in lis1]\r\nlis22 = [int(x) for x in lis2]\r\nif( lis.count('7') + lis.count('4')) == n and sum(lis11) == sum(lis22):\r\n print('YES')\r\nelse:\r\n print('NO') \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 = int(input())\r\ns = list(input().rstrip())\r\nm = n // 2\r\nans = \"YES\" if sum(s[:m]) == sum(s[m:]) else \"NO\"\r\nfor i in s:\r\n if i ^ 52 and i ^ 55:\r\n ans = \"NO\"\r\n break\r\nprint(ans)", "import sys\nn = int(input())\ns = input()\ni = 0\n\nfor ch in s:\n\tif(ch != '4' and ch != '7'):\n\t\tprint('NO')\n\t\tsys.exit(0)\nn = int(n/2)\nif(sum(map(int,s[:n])) == sum(map(int, s[-n:]))):\n\tprint(\"YES\")\nelse:\n\tprint('NO')\n\n", "n=int(input())\nb=input()\na=[]\nda=True\n\nfor i in b:\n a.append(int(i))\n \nfor i in a:\n if i!=7 and i!=4:\n da=False\n break\n \nif sum(a[0:n//2])==sum(a[n//2:]) and da:\n print('YES')\n\nelse:\n print('NO')\n\n\t \t\t\t \t\t \t\t\t\t \t", "n = int(input())\r\nw = input()\r\nfor i in range(n):\r\n if w[i] not in '47':\r\n print(\"NO\")\r\n break\r\nelse:\r\n w = list(map(int, list(w)))\r\n if sum(w[:n//2]) == sum(w[n//2:]):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "input()\r\na=input()\r\nprint('YES'if(set(a)-set('47')==set())&(sum(map(int,a[:len(a)//2]))==sum(map(int,a[len(a)//2:])))else'NO')\r\n", "n =int(input())\r\nm = input()\r\nlis1 = []\r\nlis2 = []\r\nc = True\r\nc2 = True\r\nfor i in range(int(n/2)):\r\n lis1.append(m[i])\r\nfor j in range(int(n/2) , n):\r\n lis2.append(m[j])\r\nfor k in range(int(n/2)):\r\n lis1[k] = int(lis1[k])\r\n if int(lis1[k]) == 4 or lis1[k] == 7:\r\n c = True\r\n else:\r\n c= False\r\n break\r\nfor o in range(int(n/2)):\r\n lis2[o] = int(lis2[o])\r\n if int(lis2[o]) == 4 or int(lis2[o]) == 7:\r\n c2 = True\r\n else:\r\n c2= False\r\n break\r\nif c and c2 :\r\n if sum(lis1) == sum(lis2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "num=int(input())\r\na=list(map(int,input()))\r\n\r\nl4=l7=0\r\nfor i in range(num):\r\n\tif a[i]==4:\r\n\t\tl4+=1\r\n\telif a[i]==7:\r\n\t\tl7+=1\r\n\telse:\r\n\t\tbreak\r\nif l4+l7!=num:\r\n\tprint(\"NO\")\r\nelse:\r\n\th=num//2\r\n\ts0=sum(a[:h]);s1=sum(a[h:])\r\n\tif s0!=s1:\r\n\t\tprint(\"NO\")\r\n\telse:\r\n\t\tprint(\"YES\")", "n=int(input())\r\na=input()\r\ns=[str(i) for i in a]\r\nif s.count('4')+s.count('7')==n:\r\n fir=s[0:n//2]\r\n sec=s[n//2:]\r\n #print(fir,sec)\r\n fs=0\r\n ss=0\r\n for i in fir:\r\n fs+=int(i)\r\n for i in sec:\r\n ss+=int(i)\r\n if ss==fs:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n", "# coding: utf-8\ndef check(num):\n for ch in num:\n if ch!=4 and ch!=7:\n return False\n if sum(num[:len(num)//2]) != sum(num[len(num)//2:]):\n return False\n return True\nn = input()\nif check([int(i) for i in input()]):\n print('YES')\nelse:\n print('NO')\n", "n = int(input())\r\na = input()\r\nb = []\r\ncan = 1\r\nfor i in range(n):\r\n\tb.append(int(a[i]))\r\n\tif a[i] != '4' and a[i] != '7':\r\n\t\tcan = 0\r\nsum = 0\r\nfor i in range(n):\r\n\tif i < n / 2:\r\n\t\tsum = sum + b[i]\r\n\telse:\r\n\t\tsum = sum - b[i]\r\n\r\nif sum != 0 or can == 0:\r\n\tprint(\"NO\")\r\nelse:\r\n\tprint(\"YES\")", "n = int(input())\r\nlst = tuple(input())\r\n\r\nif lst.count('4') + lst.count('7') == len(lst):\r\n if sum([int(i) for i in lst[:n // 2]]) == sum([int(i) for i in lst[n // 2:]]):\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')", "t = int(input())\r\ns = input()\r\nif s.count('4') + s.count('7') != t:\r\n print('NO')\r\nelse:\r\n one = 0\r\n two = 0\r\n n = int(t / 2)\r\n q = s[:n]\r\n w = s[n:]\r\n for i in q:\r\n one += int(i)\r\n for i in w:\r\n two += int(i)\r\n \r\n if one == two:\r\n print('YES')\r\n else:\r\n print('NO')", "n=int(input())\r\ns=input()\r\nif s.count(\"4\")+s.count(\"7\")!=n:\r\n print(\"NO\")\r\nelse:\r\n if (sum(int(s[i]) for i in range(0,n//2)))==(sum(int(s[j]) for j in range(n//2,n))):\r\n print(\"YES\")\r\n else:print(\"NO\")", "l = int(input()); a = str(input())\r\nif l % 2 != 0:\r\n print(\"NO\")\r\nelse:\r\n f1 = 0\r\n f2 = 0\r\n s1 = 0\r\n s2 = 0\r\n y = 0\r\n while y < int(l / 2):\r\n if a[y] == '4':\r\n f1 += 1\r\n elif a[y] == '7':\r\n s1 += 1\r\n else:\r\n print(\"NO\")\r\n exit()\r\n y += 1\r\n y = int(l / 2)\r\n while y < l:\r\n if a[y] == '4':\r\n f2 += 1\r\n elif a[y] == '7':\r\n s2 += 1\r\n else:\r\n print(\"NO\")\r\n exit()\r\n y += 1\r\n if f1 == f2 and s1 == s2:\r\n print(\"YES\")\r\n else: print(\"NO\")", "\r\nn = int(input())\r\na = input()\r\nif a.count('4') + a.count('7') == len(a) and sum(list(map(int, a[:len(a) // 2]))) == sum(list(map(int, a[len(a) // 2:]))):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n# CodeForcesian\r\n# ♥\r\n", "n = int(input())\r\nnum = input()\r\nmid = n // 2\r\nc4 = num.count(\"4\")\r\nc7 = num.count(\"7\")\r\nif (c4 + c7) == len(num):\r\n if num[:mid].count(\"4\") == num[mid:].count(\"4\") and num[:mid].count(\"7\") == num[mid:].count(\"7\"):\r\n print(\"YES\")\r\n else: print(\"NO\")\r\nelse: print(\"NO\")", "n=int(input())\r\nx=(input())\r\nl=[]\r\nc=0\r\nsum1=0\r\nsum2=0\r\nfor i in x:\r\n l.append(i)\r\nfor i in l:\r\n if i==\"4\" or i==\"7\":\r\n c+=1\r\nfor j in range((len(l)//2)):\r\n sum1+=int(l[j])\r\nfor z in range(len(l)//2,len(l)):\r\n sum2+=int(l[z])\r\nif c==len(l) and sum1==sum2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "num=int(input())\r\n\r\na=input()\r\nluck=list('47')\r\n\r\nb=list(filter(lambda x:x in luck ,a))\r\n\r\nh=int(num/2)\r\n\r\nif a=='44' or a=='77':\r\n print('YES')\r\n\r\nelif len(b)==len(a):\r\n \r\n f=sum(list(map(int,a[:h])))\r\n \r\n s=sum(list(map(int,a[h:])))\r\n \r\n if f==s:\r\n print('YES')\r\n else:\r\n print('NO')\r\n\r\nelse:\r\n print('NO') \r\n\r\n", "n = int(input())\r\nl = [int(i) for i in input()]\r\n\r\nprint('YES' if l.count(7) + l.count(4) == n and sum(l[:n//2]) == sum(l[n//2:]) else 'NO')", "n=int(input(''))\r\nl=list(map(int,list(input())))\r\nk=n//2\r\nif sum(l[:k])==sum(l[k:]):\r\n if set(l)=={4,7} or set(l)=={4} or set(l)=={7}:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')", "def is_lucky_ticket(n, ticket_number):\r\n # Check if the ticket's number is a lucky number\r\n if all(digit == '4' or digit == '7' for digit in ticket_number):\r\n # Calculate the sum of digits in the first half\r\n first_half_sum = sum(int(digit) for digit in ticket_number[:n//2])\r\n \r\n # Calculate the sum of digits in the second half\r\n second_half_sum = sum(int(digit) for digit in ticket_number[n//2:])\r\n \r\n # Check if the sums are equal\r\n if first_half_sum == second_half_sum:\r\n return \"YES\"\r\n \r\n return \"NO\"\r\n\r\n# Read input\r\nn = int(input())\r\nticket_number = input().strip()\r\n\r\n# Check if the ticket is lucky\r\nresult = is_lucky_ticket(n, ticket_number)\r\n\r\n# Output the result\r\nprint(result)\r\n", "\r\ndef check(s):\r\n def recur(s, sum_left, sum_right, start, end):\r\n if s[start] != \"7\" and s[start] != \"4\":\r\n return \"NO\"\r\n elif s[end] != \"4\" and s[end] != \"7\":\r\n return \"NO\"\r\n elif start > end:\r\n if sum_left == sum_right:\r\n return \"YES\"\r\n else:\r\n return \"NO\"\r\n else:\r\n sum_left += int(s[start])\r\n sum_right += int(s[end])\r\n return recur(s, sum_left, sum_right, start + 1, end - 1)\r\n start = 0\r\n end = len(s) - 1\r\n sum_right = 0\r\n sum_left = 0\r\n return recur(s, sum_left, sum_right, start, end)\r\n\r\n\r\n\r\n\r\ndef main_function():\r\n n = int(input())\r\n s = input()\r\n return check(s)\r\n\r\n\r\nprint(main_function())", "l=input()\r\np=list(map(int,list(input())))\r\nif set(p)=={4,7} or set(p)=={4} or set(p)=={7}:\r\n\tk=True\r\nelse:\r\n\tk=False\r\nif k and sum(p[:len(p)//2])==sum(p[len(p)//2:]):print('YES')\r\nelse:print('NO')", "n = int(input())\r\nb = input()\r\nc = sorted(list(set(list(b))))\r\nif len(c)==1:\r\n\tif c[0]==\"4\" or c[0]==\"7\":f=0\r\n\telse:f=1\r\nelif len(c)==2:\r\n\tif c[0]==\"4\" and c[1]==\"7\":f=0\r\n\telse:f=1\r\nelse:f=1\r\nif f==0 :\r\n\te,r=0,0\r\n\tq = list(b[0:n//2])\r\n\tw = list(b[n//2:])\r\n\tfor i in range(len(q)):\r\n\t\te+=int(q[i])\r\n\t\tr+=int(w[i])\r\n\tif e == r:print(\"YES\")\r\n\telse:print(\"NO\")\r\nelse:print(\"NO\")", "n, a = int(input()), list(map(int,list(input())))\nif set(a).issubset({4, 7}) and sum(a[:n // 2]) == sum(a[n //2:]):\n print('YES')\nelse:\n print('NO')\n ", "def lucky(l,n):\r\n for i in l:\r\n if i!=4 and i!=7:\r\n return \"NO\"\r\n if sum(l[0:n])==sum(l[n:]):\r\n return \"YES\"\r\n return \"NO\"\r\nn=int(input())//2\r\ns=input()\r\nl=list(s)\r\nl=[int(i) for i in l]\r\nprint(lucky(l,n))", "def question1():\r\n N = int(input())\r\n number = input()\r\n i = 0\r\n first_half = 0\r\n second_half = 0\r\n while i < N:\r\n if number[i] == \"4\" or number[i] == \"7\":\r\n if i < N//2:\r\n first_half += int(number[i])\r\n \r\n else:\r\n second_half += int(number[i])\r\n i += 1 \r\n else:\r\n return False\r\n if first_half == second_half:\r\n return True\r\n return False \r\n \r\n \r\n# remained_test_cases = int(input())\r\nremained_test_cases = 1 \r\nwhile remained_test_cases > 0:\r\n if question1():\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n remained_test_cases -= 1 ", "x=int(input())\r\ns=input()\r\np='YES'\r\nfor i in s:\r\n\tif i!='7' and i!='4':\r\n\t\tp='NO'\r\n\t\tbreak\r\nif p=='NO':\r\n\tprint(p)\r\nelse:\r\n\ts1=s[:x//2]\r\n\ts2=s[x//2:]\r\n\tsu1=0\r\n\tsu2=0\r\n\tfor i in s1:\r\n\t\tsu1+=int(i)\r\n\tfor i in s2:\r\n\t\tsu2+=int(i)\r\n\tif su1==su2:\r\n\t\tprint(p)\r\n\telse:\r\n\t\tprint('NO')", "import sys\r\nfrom math import sqrt, log, log2, ceil, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial\r\nfrom copy import copy, deepcopy\r\nfrom sys import exit, stdin, stdout\r\nfrom collections import Counter, defaultdict, deque\r\nfrom itertools import permutations\r\nimport heapq\r\nfrom bisect import bisect_left \r\nfrom bisect import bisect_right\r\n# sys.setrecursionlimit(100000000)\r\nmod = 1000000007\r\niinp = lambda: int(sys.stdin.readline())\r\ninp = lambda: sys.stdin.readline().strip()\r\nstrl = lambda: list(inp().strip().split(\" \"))\r\nintl = lambda: list(map(int, inp().split(\" \")))\r\nmint = lambda: map(int, inp().split())\r\nflol = lambda: list(map(float, inp().split(\" \")))\r\nflush = lambda: stdout.flush()\r\n# ========================================================Functions====================================================\r\ndef solve():\r\n n=iinp()\r\n num=inp()\r\n s1=s2=0\r\n fl=0\r\n for i in range(n):\r\n if i<n//2:\r\n if(num[i]!='7' and num[i]!='4'):\r\n fl=1\r\n break\r\n s1+=int(num[i])\r\n else:\r\n if(num[i]!='7' and num[i]!='4'):\r\n fl=1\r\n break\r\n s2+=int(num[i])\r\n if(fl):\r\n print(\"NO\")\r\n else:\r\n if(s1==s2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\") \r\n \r\n \r\n\r\n# ========================================================Main Code=====================================================\r\n# t=iinp()\r\nt=1\r\nfor _ in range(t):\r\n solve()", "n=int(input())\r\nf=int(input())\r\nf=[int (x) for x in str(f)]\r\ns1=sum(f[:int(n/2)])\r\ns2=sum(f[int(n/2):])\r\nf.sort()\r\nf=set(f)\r\ndef func():\r\n if s1!=s2:\r\n print(\"NO\")\r\n return\r\n if f=={4,7} or f=={4} or f=={7}:\r\n print(\"YES\")\r\n return\r\n print(\"NO\")\r\n\r\nfunc()\r\n", "n = int(input())\r\na = [int(i) for i in input()]\r\nl = len(a)\r\nif a.count(4)+a.count(7) ==n:\r\n fhalf = a[:l//2]\r\n lhalf = a[l//2:]\r\n xx = fhalf.count(4) +fhalf.count(7)\r\n yy = lhalf.count(4) + lhalf.count(7)\r\n if xx == yy and sum(fhalf)==sum(lhalf):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\na = [int(i) for i in input()]\nc = True\n\nfor i in a:\n\tif i not in (4,7): c = False\n\nc = c and (sum(a[:n//2]) == sum(a[n//2:]))\n\nprint(\"YES\") if c else print(\"NO\")", "n = int(input())\r\nnum = input()\r\n\r\nif num.count(\"7\") + num.count(\"4\") != n:\r\n print(\"NO\")\r\nelse:\r\n arr = [int(num[i]) for i in range(n)]\r\n if sum(arr[:n//2]) == sum(arr[n//2:]):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "def is_lucky(n: str) -> bool:\n return n.count(\"4\") + n.count(\"7\") == len(n)\n\ndef sumar_digitos(num: str) -> (int, int):\n n = len(num)\n prim_mitad = num[0:n//2]\n seg_mitad = num[n//2:]\n return sum(map(lambda x: int(x), prim_mitad)), sum(map(lambda x: int(x), seg_mitad))\n\ndef is_lucky_ticket(num: str) -> bool:\n a, b = sumar_digitos(num)\n return is_lucky(num) and (a == b)\n\n# Programa principal\ndigitos = input()\nnum = input()\nif is_lucky_ticket(num):\n print(\"YES\")\nelse:\n print(\"NO\")\n\n\t\t \t\t\t\t\t \t \t \t \t \t \t\t", "def main():\n n = int(input())\n\n ticket = input()\n if ticket.count('4') + ticket.count('7') != n:\n print('NO')\n else:\n meio = n // 2\n metade1 = ticket[:meio]\n metade2 = ticket[meio:]\n soma1 = sum(list(map(int, list(metade1))))\n soma2 = sum(list(map(int, list(metade2))))\n\n if soma1 == soma2:\n print('YES')\n else:\n print('NO')\n\n\nif __name__ == '__main__':\n main()\n \n\n\t \t \t \t\t \t \t \t \t \t\t \t \t \t\t", "n = int(input())\r\ns = list(input())\r\n\r\n#print(s.count('4') , s.count('7'))\r\ns1 = s[:int(n/2)]\r\ns2 = s[int(n/2):]\r\n\r\n\r\nif s.count('4') + s.count('7') == n:\r\n if sum(list(map(int,s1))) == sum(list(map(int,s2))):\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')\r\n\r\n\r\n\r\n", "def is_lucky(s):\r\n for x in s:\r\n if x != '4' and x != '7':\r\n return False\r\n n = len(s)\r\n sum1 = sum([int(x) for x in s[:n//2]])\r\n sum2 = sum([int(x) for x in s[n//2:]])\r\n return sum1 == sum2\r\n\r\nn = int(input())\r\ns = input()\r\nif is_lucky(s):\r\n print('YES')\r\nelse:\r\n print('NO')", "n=int(input())\r\nb=input()\r\nans = \"YES\"\r\nfor c in b:\r\n if int(c)!=4 and int(c)!=7:\r\n ans=\"NO\"\r\na=0\r\nfor i in range(0,n//2):\r\n a+=int(b[i])\r\nd=0\r\nfor j in range(n//2,n):\r\n d+=int(b[j])\r\nif a!=d:\r\n ans=\"NO\"\r\nprint(ans)", "n = int(input())\r\nbil = [int(x) for x in input()]\r\nprint('YES' if bil.count(4) + bil.count(7) == n and sum(bil[:n//2]) == sum(bil[n//2:]) else 'NO')\r\n", "#loser707\r\nm=int(input())\r\nl=list(input())\r\nl=[int(u) for u in l]\r\nn=0\r\nfor i in l:\r\n if i==4 or i==7:\r\n n=n+1\r\nif n!=len(l):\r\n print(\"NO\")\r\nelse:\r\n l1=l[0:n//2]\r\n l2=l[n//2:]\r\n if sum(l1)==sum(l2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "n = int(input())\r\na = list(map(int, input()))\r\nif set(a).issubset({4, 7}) and sum(a[:n//2]) == sum(a[n//2:]):\r\n print('YES')\r\nelse:\r\n print('NO')", "# for testCase in range(int(input())):\nn = int(input())\ns = input()\nfirstHalf = s[:n//2]\nsecondHalf = s[n//2:]\ncntFirst = [0 ,0]\ncntSecond = [0 ,0]\nok = True\nfor i in firstHalf:\n if i == '4':\n cntFirst[0] += 1\n elif i == '7':\n cntFirst[1] += 1\n else:\n ok = False\nfor i in secondHalf:\n if i == '4':\n cntSecond[0] += 1\n elif i == '7':\n cntSecond[1] += 1\n else:\n ok = False\nif cntFirst[0] == cntSecond[0] and cntFirst[1] == cntSecond[1] and ok:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "def f(n,s):\r\n m = n//2\r\n st = 0\r\n for i in range(m):\r\n c = s[i]\r\n if(c == '4' or c == '7'):\r\n st += ord(c)\r\n else:\r\n return \"NO\"\r\n c = s[m+i]\r\n if(c == '4' or c == '7'):\r\n st -= ord(c)\r\n else:\r\n return \"NO\"\r\n return (\"YES\",\"NO\")[st != 0]\r\n \r\nn = int(input())\r\ns = input()\r\n\r\nprint(f(n, s))\r\n \r\n \r\n \r\n \r\n\r\n\r\n \r\n", "def nim(a):\r\n a=str(a)\r\n nim=1\r\n for i in a:\r\n if i=='7' or i=='4':\r\n continue\r\n else:\r\n nim=0\r\n break\r\n return nim\r\n\r\nn=int(input())\r\na=input()\r\nlst=[]\r\nfor i in a :\r\n lst.append(int(i))\r\nif sum(lst[:n//2])==sum(lst[n//2:]) and nim(a)==1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "def is_lucky(n):\r\n for m in str(n):\r\n if((m!='4')&(m!='7')):\r\n return False\r\n return True\r\ndef is_equal(m,n):\r\n m=list(map(int,str(m)))\r\n return sum(m[0:int(n/2)])==sum(m[int(n/2):n])\r\nn=int(input())\r\nm=int(input())\r\nif(is_lucky(m)&is_equal(m,n)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\nso = input()\r\ndk1 = 0\r\ntong = 0\r\nfor i in so:\r\n tong += int(i)\r\n if(int(i) != 4 and int(i) != 7):\r\n dk1 += 1 \r\nif(dk1 != 0):\r\n print(\"NO\")\r\nelse:\r\n tong1 = 0\r\n for j in range(0, int(n/2)):\r\n tong1 += int(so[j])\r\n if(tong1 * 2 == tong):\r\n print(\"YES\")\r\n else: print(\"NO\")", "a=int(input())\r\nb=input()\r\np=0\r\nfor i in range(len(b)):\r\n if b[i]==\"4\" or b[i]==\"7\":\r\n p=1\r\n else:\r\n print(\"NO\")\r\n p=2\r\n break\r\nif p==1:\r\n m=0\r\n n=0\r\n for i in range (len(b)//2):\r\n m=m+int(b[i])\r\n for j in range(len(b)//2,len(b)):\r\n n=n+int(b[j])\r\n if n==m:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n ", "n = int(input())\r\ns = input()\r\nnums, flag, truenums = ['4', '7'], True, []\r\nfor i in s:\r\n\ttruenums.append(int(i))\r\n\tif (i not in nums):\r\n\t\tflag = False\r\n\t\tprint('NO')\r\n\t\tbreak\r\n\r\nif (flag): print('YES' if (sum(truenums[:n//2]) == sum(truenums[n//2:])) else 'NO')", "input()\r\ndigits = list(int(c) for c in input())\r\nhalf = len(digits) // 2\r\nif any(d != 4 and d != 7 for d in digits):\r\n print('NO')\r\nelse:\r\n print(('NO', 'YES')[sum(digits[: half]) == sum(digits[half:])])\r\n\r\n", "n = int(input())\r\nm = int(n/2)\r\nA= input()\r\ndem=0\r\nt1=0\r\nt2=0\r\nfor i in range(m):\r\n t1 += int(A[i])\r\n if A[i] != \"4\" and A[i]!= \"7\":\r\n dem += 1\r\nfor i in range(m,n):\r\n t2 += int(A[i])\r\n if A[i] != \"4\" and A[i]!= \"7\":\r\n dem+=1\r\nif dem > 0 or t1 != t2:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "a = int(input())//2\nb = input()\nif b.replace('4','').replace('7','') !='':\n print('NO')\nelse:\n c =[int(i) for i in b[:a]]\n d =[int(i) for i in b[a:]]\n if sum(c) == sum(d):\n print('YES')\n else:\n print('NO')\n ", "n=input()\r\ns = input()\r\na=len(s)/2\r\nh=0\r\ng=0\r\nfor i in range(len(s)):\r\n x=s[i]\r\n if x!='7' and x!='4':\r\n print('NO')\r\n break\r\n else:\r\n if x=='4' and i<a: h+=4\r\n elif x=='7' and i<a: h+=7\r\n elif x == '4' and i >=a : g += 4\r\n elif x == '7' and i >= a: g += 7\r\nelse:\r\n if g==h:print('YES')\r\n else :print('NO')\r\n\r\n ", "#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-12-03 21:31:17\nLastEditTime: 2021-12-03 21:39:50\nDescription: Lucky Ticket\nFilePath: CF146A.py\n'''\n\n\ndef func():\n n = int(input())\n num = list(map(int, list(input().strip())))\n if num.count(4) + num.count(7) == n and sum(num[:(n//2)]) == sum(num[(n//2):]):\n print(\"YES\")\n else:\n print(\"NO\")\n\n\nif __name__ == '__main__':\n func()\n", "x=int(input())\r\nsum=0\r\nk=list(map(int, list(input())))\r\nfor i in range(x//2):\r\n sum+=k[i]\r\nfor i in range(x//2, x):\r\n sum-=k[i]\r\nprint(\"YES\") if k.count(4)+k.count(7)==x and sum==0 else print(\"NO\")", "from sys import stdin,stdout\nn=int(stdin.readline().strip())\ns=stdin.readline().strip()\nn4=s.count(\"4\")\nn7=s.count(\"7\")\nif n4+n7!=n:\n print(\"NO\")\n exit(0)\nsm1=0\nsm2=0\nfor i in range(n//2):\n sm1+=int(s[i])\nfor i in range(n//2,n):\n sm2+=int(s[i])\nif sm1==sm2:\n print(\"YES\")\n\nelse:\n print(\"NO\")\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\na = list(input())\r\nfor i in range(n):\r\n a[i] = int(a[i])\r\n if a[i] != 4 and a[i] != 7: print(\"NO\"); exit()\r\nif sum(a[:n//2]) != sum(a[n//2:]): print(\"NO\")\r\nelse: print(\"YES\")", "n=int(input())\r\nx=input()\r\nf=lambda x:sum([int(i)for i in x])\r\nprint([\"NO\",\"YES\"][set(x)<=set(\"47\")and f(x[:n//2])==f(x[n//2:])])", "n = int(input())\r\nnumber = input()\r\n\r\nbool = True\r\nlst = ['1', '2', '3', '5', '6', '8', '9', '0']\r\n\r\nfor i in lst:\r\n if i in number:\r\n bool = False\r\n break\r\n\r\n\r\n \r\nif bool == True:\r\n first_half = list(number[:n//2])\r\n sec_half = list(number[n//2:])\r\n sum1, sum2 = 0, 0\r\n \r\n for item in first_half:\r\n sum1 += int(item)\r\n for item2 in sec_half:\r\n sum2 += int(item2)\r\n\r\nif bool == True and sum1 == sum2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n ", "n = int(input())\r\nstr1 = input()\r\nc1 = 0\r\nc2 = 0\r\n\r\nc3 = 0\r\nfor i in range(0,n//2) :\r\n if str1[i] in ['4','7'] :\r\n c1 += int(str1[i])\r\n c3 +=1\r\nfor i in range(n//2,n) :\r\n if str1[i] in ['4','7'] :\r\n c2 += int(str1[i])\r\n c3 +=1\r\n \r\nif c1==c2 and c3==n :\r\n print(\"YES\") \r\nelse :\r\n print(\"NO\")\r\n\r\n \r\n \r\n \r\n", "n=int(input())\r\nm=input()\r\n\r\ndef sums(n):\r\n \r\n sum = 0\r\n while (n != 0):\r\n \r\n sum = sum + (n % 10)\r\n n = n//10\r\n \r\n return sum\r\n\r\nif set(m) == {'7'} or set(m) == {'4'} or set(m) == {'4','7'}:\r\n\r\n if sums(int(m[0:len(m)//2])) == sums(int(m[len(m)//2:])) :\r\n print('YES')\r\n else :\r\n print('NO')\r\nelse :\r\n print('NO')\r\n", "num = int(input())\r\nstr_= str(input())\r\nfour=str_.count(\"4\")\r\nseven=str_.count(\"7\")\r\nlist1=0\r\nlist2=0\r\nif (four+seven)==num:\r\n for i in range(num//2):\r\n list1=list1+int(str_[i])\r\n for j in range(num//2,num):\r\n list2=list2+int(str_[j])\r\n if list1==list2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\nk = n // 2\nt = input()\n#print(k)\np = t[:k]\na = t.count('4')\nb = t.count('7')\nif a + b == n and 8 * p.count('4') + 14 * p.count('7') == 4 * a + 7 * b: print('YES')\nelse: print('NO')", "ticketLen = int(input()) # Length of the ticket number.\r\n\r\nticketNum = int(input()) # Ticket number.\r\n\r\nif str(ticketNum).count('4') + str(ticketNum).count('7') != ticketLen : # Not a lucky number.\r\n print('NO')\r\n\r\nelse :\r\n \r\n firstHalf = list(str(ticketNum)[ : ticketLen // 2] )\r\n secondHalf = list(str(ticketNum)[ticketLen // 2 : ] )\r\n \r\n \r\n firstHalf = map(int, firstHalf)\r\n secondHalf = map(int, secondHalf)\r\n \r\n if sum(firstHalf) == sum(secondHalf):\r\n print(\"YES\")\r\n else :\r\n print('NO')\r\n", "n = int(input())\r\nt = input()\r\n\r\nlucky = True\r\n\r\nfor c in t:\r\n if not (c=='4' or c=='7'):\r\n lucky = False\r\n break\r\n\r\nfirst = 0\r\nsecond = 0\r\n\r\nfor i in range(len(t)//2):\r\n first+= int(t[i])\r\n\r\nfor i in range(len(t)//2,len(t)):\r\n second+= int(t[i])\r\n\r\nif lucky and (first==second):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=int(input())\r\n\r\n\r\nt=list(input())\r\n\r\nif t.count('4')+t.count('7')==n:\r\n a,b=0,0\r\n\r\n for k in range(n//2):\r\n a+=int(t[k])\r\n b+=int(t[-(1+k)])\r\n \r\n\r\n if a==b:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')\r\n", "n = int(input())\r\nnum = list(input())\r\nst = set(list(num))\r\n\r\nif st == {'4', '7'} or st == {'7', '4'} or st == {'7'} or st == {'4'}:\r\n lst1 = list(map(int, num[:n//2]))\r\n lst2 = list(map(int, num[n//2:]))\r\n \r\n if sum(lst1) == sum(lst2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\na=list(map(int,input()))\r\ns=n//2\r\nif a.count(4)+a.count(7)==n and sum(a[:s])==sum(a[s:]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nm = input()\r\na = [int(i) for i in m]\r\nflag = True\r\nfor i in range(n):\r\n if a[i] != 4 and a[i] != 7:\r\n flag = False\r\n break\r\nif sum(a[:n//2]) != sum(a[n//2:]):\r\n flag = False\r\nif flag:\r\n print('YES')\r\nelse:\r\n print('NO')", "n = int(input())\r\nnumber = input()\r\n\r\nfor s in [\"1\", \"2\", \"3\", \"5\", \"6\", \"8\", \"9\", \"0\"]:\r\n if s in number:\r\n print(\"NO\")\r\n exit()\r\n\r\nleft_sum = 0\r\nfor i in range(round(n/2)):\r\n left_sum += int(number[i])\r\n\r\nright_sum = 0\r\nfor i in range(round(n/2), n):\r\n right_sum += int(number[i])\r\n\r\nif left_sum == right_sum:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=int(input())\r\nticket=input()\r\nticket=[int(i) for i in ticket]\r\nx=[1,2,3,5,6,8,9,0]\r\nflag=0\r\nfor i in x:\r\n if i in ticket:\r\n flag=1\r\n break\r\nif flag==0 and sum(ticket[:n//2])==sum(ticket[n//2:]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") ", "def check_num(s, n):\r\n for i in s:\r\n if i != \"4\" and i != \"7\":\r\n return False\r\n if sum(s[:n//2]) != sum(s[n//2:]):\r\n return False\r\n return True\r\n \r\ndef sum(a):\r\n s = 0\r\n for i in a:\r\n s += int(i)\r\n return s\r\n\r\ndef main():\r\n n = int(input())\r\n num = input()\r\n if check_num(num, n):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nmain()", "n=int(input())\r\ns=int(input())\r\nl=list(str(s))\r\ns_4=l.count('4')\r\ns_7=l.count('7')\r\nif (s_4 + s_7)!=n:\r\n print(\"NO\")\r\nelse:\r\n mid=n//2\r\n a=(l[0:mid])\r\n b=(l[mid:])\r\n sum1,sum2=0,0\r\n for ele in a:\r\n sum1+=int(ele)\r\n for ele in b:\r\n sum2+=int(ele)\r\n if sum1==sum2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\n", "n=int(input())\r\nk=int(input())\r\ns=str(k)\r\nl=[]\r\ncount=0\r\nfor i in s:\r\n l.append(int(i))\r\n if i=='4' or i=='7':\r\n count+=1\r\nkn=n//2\r\nsum1=sum(l[:kn])\r\nsum2=sum(l[kn:])\r\nif count==n and sum1==sum2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nl = input()\r\nlucky = 1\r\nleft = 0\r\nright = 0\r\na = ['0', '1', '2', '3', '5', '6', '8', '9']\r\n\r\nfor i in range(0,int(n/2)):\r\n left = left + int(l[i])\r\n right = right + int(l[n-i-1])\r\n\r\nif left == right:\r\n lucky = 1\r\nelse:\r\n lucky = 0\r\n \r\nfor i in range(0,n):\r\n if l[i] in a:\r\n lucky = 0\r\n \r\nif lucky == 1:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "n = int(input())\r\n\r\nm = input()\r\n\r\nif m.count(\"4\")+m.count(\"7\")==len(m):\r\n mitad1 = m[: len(m)//2]\r\n mitad2 = m[len(m)//2:]\r\n\r\n if sum(map(lambda x: int(x), mitad1)) == sum(map(lambda x: int(x), mitad2)):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nt = list(input())\r\nt = list(map(int,t))\r\nif all([1 if i == 7 or i == 4 else 0 for i in t]):\r\n if sum(t[:n//2]) == sum(t[n//2:]):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "n = int(input())\nt = str(input())\n\nsomaA = 0\nsomaB = 0\n\nfor i in range(n//2):\n if (t[i] == \"4\" or t[i] == \"7\") and (t[n-1-i] == \"4\" or t[n-1-i] == \"7\"):\n somaA += int(t[i])\n somaB += int(t[n-1-i])\n else:\n somaA = -1\n print(\"NO\")\n break\nif somaA > 0:\n if somaA == somaB:\n print(\"YES\")\n else:\n print(\"NO\")\n\t\t \t\t \t \t \t \t \t\t \t \t \t\t\t\t\t", "n = int(input())\r\nnum = int(input())\r\n\r\nc = 0\r\narr = []\r\n\r\nfor i in range(len(str(num))):\r\n if str(num)[i] == \"4\" or str(num)[i] == \"7\":\r\n c += 1\r\n arr.append(str(num)[i])\r\n\r\nk = list(map(int, arr))\r\nlength = n//2\r\nif c == n and sum(k[0:length]) == sum(k[length::]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "'''input\r\n50\r\n77777777777777777777777777777777777777777777777777\r\n\r\n'''\r\nimport math\r\n\r\ndef findLucky(q,r):\r\n\tleftHalf = 0\r\n\twhile q > 0:\r\n\t\tif q % 10 != 4:\r\n\t\t\tif q % 10 != 7:\r\n\t\t\t\treturn \"NO\"\r\n\t\t\t\tbreak\r\n\t\tleftHalf += q % 10\r\n\t\tq //= 10\r\n\r\n\trightHalf = 0\r\n\twhile r > 0:\r\n\t\tif r % 10 != 4:\r\n\t\t\tif r % 10 != 7:\r\n\t\t\t\treturn \"NO\"\r\n\t\trightHalf += r % 10\r\n\t\tr //= 10\r\n\r\n\tif leftHalf == rightHalf:\r\n\t\treturn \"YES\"\r\n\telse:\r\n\t\treturn \"NO\"\r\n\r\n\r\nx = int(input())\r\ns = input()\r\nif s[0] == '0':\r\n\tprint(\"NO\")\r\nelse:\r\n\tn = int(s)\r\n\td = '1'\r\n\tfor _ in range(x//2):\r\n\t\td += '0'\r\n\r\n\td = int(d)\r\n\tq = n // d\r\n\tr = n % d\r\n\tprint(findLucky(q,r))\r\n\r\n\r\n", "n = int(input())\r\ns = input()\r\nprint('YES' if set(s) <= {'4', '7'} and s[:len(s) // 2].count('4') == s[-(len(s) // 2):].count('4') else 'NO') ", "# // Problem: A. Lucky Ticket\r\n# // Contest: Codeforces - Codeforces Round #104 (Div. 2)\r\n# // URL: https://codeforces.com/contest/146/problem/A\r\n# // Memory Limit: 256 MB\r\n# // Time Limit: 2000 ms\r\n\r\nn = int(input())\r\ns = input()\r\nf = s.count('4')\r\nse = s.count('7')\r\nif f + se != n:\r\n print('NO')\r\nelse:\r\n sp = 0\r\n for i in s[:n//2]:\r\n sp+=int(i)\r\n sb = 0\r\n for i in s[n//2:]:\r\n sb+=int(i)\r\n if sb != sp:\r\n print('NO')\r\n else:\r\n print('YES')", "ln = int(input())\r\n\r\nn = input()\r\narr = []\r\n\r\nfor ch in n:\r\n arr.append(ch)\r\n\r\nfc = arr.count(\"4\")\r\nsc = arr.count(\"7\")\r\n\r\nif fc + sc != len(arr):\r\n print(\"NO\")\r\nelse:\r\n\r\n a = sum(int(digit) for digit in str(n[:len(n)//2]))\r\n b = sum(int(digit) for digit in str(n[len(n)//2:]))\r\n\r\n if a == b:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "\r\nn = int(input())\r\n\r\nnumber = input()\r\n\r\nlucky = True\r\nls = 0\r\nrs = 0\r\n\r\nfor i, d in enumerate(number):\r\n\r\n if d != '4' and d != '7':\r\n lucky = False\r\n break\r\n\r\n if i < n / 2:\r\n ls += int(d)\r\n else:\r\n rs += int(d)\r\n\r\nif not lucky:\r\n print(\"NO\")\r\nelse:\r\n\r\n if ls == rs:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "l = []\r\nn = int(input())\r\nnumber = int(input())\r\nrep = \"YES\"\r\nfirsthalf = 0\r\nsecondhalf = 0\r\nfor k in range(n):\r\n digit = number//10**(n-1-k)\r\n if digit != 4 and digit != 7:\r\n rep = \"NO\"\r\n number -= digit * 10**(n-1-k)\r\n if k<n//2: firsthalf+=digit\r\n else: secondhalf+=digit\r\nif firsthalf == secondhalf: print(rep)\r\nelse: print(\"NO\")", "n = int(input())\r\na = input()\r\nl = 0\r\nr = 0\r\nans = True\r\nfor i in range(0, n // 2):\r\n l += int(a[i])\r\n if a[i] != '4' and a[i] != '7':\r\n ans = False\r\nfor i in range(n // 2, n):\r\n r += int(a[i])\r\n if a[i] != '4' and a[i] != '7':\r\n ans = False\r\nif l != r:\r\n ans = False\r\nif ans:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Mar 27 23:03:13 2020\r\n\r\n@author: alexi\r\n\"\"\"\r\n\r\n\r\n\r\n#http://codeforces.com/problemset/problem/146/A -- Alexis Galvan\r\n\r\n\r\n\r\ndef check_half_sum(array):\r\n half = int(len(array)/2)\r\n sum1 = 0\r\n sum2 = 0\r\n for i in range(0, half):\r\n sum1 += int(array[i])\r\n \r\n for i in range(half, len(array)):\r\n sum2 += int(array[i])\r\n \r\n if sum1 == sum2:\r\n return True\r\n return False\r\n \r\n\r\ndef check(array):\r\n dic = {'4','7'}\r\n for i in range(len(array)):\r\n if array[i] not in dic:\r\n return False\r\n return True\r\n\r\ndef lucky_ticket():\r\n length = int(input())\r\n ticket = input()\r\n \r\n if not check(ticket):\r\n return 'NO'\r\n \r\n if check_half_sum(ticket):\r\n return 'YES'\r\n else:\r\n return 'NO'\r\n \r\n\r\nanswer = lucky_ticket()\r\nprint(answer)", "# LUOGU_RID: 101469473\n_, s = open(0)\r\na = [*map(int, s.strip())]\r\nprint(all(x in [4, 7] for x in a) and sum(a[:len(a)//2]) == sum(a[len(a)//2:]) and 'YES' or 'NO')", "n = int(input(''))\r\nnum = int(input(''))\r\nnum = str(num)\r\nflag = True\r\nfor i in num:\r\n if i != '4' and i != '7':\r\n flag = False\r\nif not flag:\r\n print('NO')\r\nelse:\r\n num1 = num[:n//2]\r\n num2 = num[n//2:]\r\n sum1 = 0\r\n sum2 = 0\r\n for i in num1:\r\n sum1 += int(i)\r\n for i in num2:\r\n sum2 += int(i)\r\n if sum1 == sum2:\r\n print('YES')\r\n else:\r\n print('NO')", "ticket_length = int(input())\nnum = input()\n\nlista = [[int(x) for x in num[:int(len(num)/2)]],\n [int(x) for x in num[int(len(num)/2):]]]\n\nfor num in lista:\n for x in num:\n if x not in [4, 7]:\n print(\"NO\")\n break\n else:\n continue\n break\nelse:\n if sum(lista[0]) == sum(lista[1]):\n print(\"YES\")\n else:\n print(\"NO\")\n\t\t \t\t\t \t \t \t\t \t \t \t \t\t\t\t\t", "def lucky_ticket(n,a):\n j = n-1\n s1,s2 = 0,0\n for i in range(n//2):\n if (a[i] != 4 and a[i]!=7) or (a[j] != 4 and a[j]!=7): return f'NO'\n s1 += a[i]\n s2 += a[j]\n j -= 1\n if s1 == s2: return f'YES'\n return f'NO'\n\n\ndef main():\n n = int(input())\n s = input()\n s = list(map(int,s))\n print(lucky_ticket(n, s))\n\nmain()\n\n\n", "#Lucky Ticket 800 A\r\nn = int(input())\r\nticket = input()\r\nfor e in ticket:\r\n\tif int(e) != 4 and int(e) !=7:\r\n\t\tprint(\"NO\")\r\n\t\texit()\r\na = sum([int(x) for x in ticket[:len(ticket)//2]])\r\nb = sum([int(x) for x in ticket[len(ticket)//2+(len(ticket)%2):]])\r\nif (a!=b):\r\n\tprint(\"NO\")\r\n\texit()\r\nprint(\"YES\")", "def lucky_ticket(s):\r\n four_count = 0\r\n seven_count = 0\r\n for i in range(len(s)):\r\n if s[i] != '4' and s[i] != '7':\r\n return False\r\n if i >= len(s) // 2:\r\n if s[i] == '7':\r\n seven_count -= 1\r\n else:\r\n four_count -= 1\r\n else:\r\n if s[i] == '7':\r\n seven_count += 1\r\n else:\r\n four_count += 1\r\n return seven_count == 0 and four_count == 0\r\n \r\nn = int(input())\r\ns = input()\r\nprint(\"YES\" if lucky_ticket(s) else \"NO\")", "x=int(input())\r\ny=input()\r\nl=[i for i in y if i not in ['4','7']]\r\nif len(l)>0:\r\n print('NO')\r\n #print(l)\r\nelse:\r\n c=x//2\r\n if x%2==0:\r\n a=int(y[:c])\r\n b=int(y[c:])\r\n else:\r\n a=int(y[:c])\r\n b=int(y[c+1:])\r\n s=0\r\n d=0\r\n for i in str(a):\r\n s=s+int(i)\r\n for i in str(b):\r\n d=d+int(i)\r\n if s==d:\r\n print('YES')\r\n else:\r\n print('NO')\r\n", " \r\nn=int(input())\r\nx=int(input())\r\nx1=str(x)\r\nx2=[]\r\nfor i in x1:\r\n x2.append(int(i))\r\nisL=True\r\nfor i in x2:\r\n if i!=4 and i!=7:\r\n isL=False\r\n break\r\n \r\n \r\ns1=sum(x2[:n//2])\r\ns2=sum(x2[n//2:])\r\nif s1==s2 and isL==True:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\nn1=input()\r\nk=0\r\nv=0\r\nb=0\r\nfor i in n1:\r\n if(i!='4' and i!='7'):\r\n k=k+1\r\nif(k==0):\r\n s=n1[:n//2]\r\n w=n1[n//2:]\r\n for i in s:\r\n v+=int(i)\r\n for j in w:\r\n b+=int(j)\r\n if(v==b):\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')\r\n \r\n", "n = int(input())\r\ns = input()\r\ns1, s2 = list(map(int, list(s[:n//2]))), list(map(int, list(s[n//2:])))\r\nif s.count('4') + s.count('7') == len(s) and sum(s1) == sum(s2):\r\n print('YES')\r\nelse:\r\n print('NO')", "if __name__==\"__main__\":\r\n n = int(input())\r\n x = list(input())\r\n k = False\r\n for i in range(n):\r\n x[i] = int(x[i])\r\n if (x[i] != 7 and x[i] != 4):\r\n k = True\r\n if (k or sum(x[:n // 2]) != sum(x[n // 2:])):\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")", "n = int(input())\r\nticket = input()\r\nif set(ticket) == set(['4', '7']) or set(ticket) == set(['7']) or set(ticket) == set(['4']):\r\n sum1 = 0\r\n for i in range(n // 2):\r\n sum1 += int(ticket[i])\r\n sum2 = 0\r\n for i in range(n // 2, n):\r\n sum2 += int(ticket[i])\r\n if sum1 == sum2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\ns=input()\r\ns1=s2=c=0\r\nfor i in s:\r\n if(i=='4' or i=='7'):\r\n c+=1\r\nif(c==n):\r\n for i in range(n//2):\r\n s1+=int(s[i])\r\n for i in range(n//2,n):\r\n s2+=int(s[i])\r\n if(s1==s2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nL = list(input())\r\nfor i in range(n):\r\n L[i] = int(L[i])\r\nfound = False\r\nls,rs = 0,0\r\nfor i in range(1,n+1):\r\n if i<=n/2:\r\n ls += L[i-1]\r\n else:\r\n rs += L[i-1]\r\n if L[i-1] != 4 and L[i-1] != 7:\r\n found = True\r\n break\r\nif found==True:\r\n print(\"NO\")\r\nelif ls == rs:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "t=int(input())\r\nln=input()\r\ncnt=1\r\nsuml=sumr=0\r\nfor m in ln:\r\n m=int(m)\r\n if m!=4 and m!=7:\r\n cnt=0\r\nm=str(ln)\r\nif t%2==0:\r\n l=m[0:t//2]\r\n r=m[t//2:t+1]\r\n \r\n for x in l:\r\n suml+=int(x)\r\n for y in r:\r\n sumr+=int(y)\r\n \r\n\r\nelse:\r\n l=m[0:t//2]\r\n r=m[t//2+1:t+1]\r\n print(r)\r\n \r\n for x in l:\r\n suml+=int(x)\r\n for y in r:\r\n sumr+=int(y)\r\n\r\nif cnt==1 and suml==sumr:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\ns = input()\r\n*ar, = '01235689'\r\nans = \"YES\"\r\nfor i in ar:\r\n if i in s:\r\n ans = \"NO\"\r\n break\r\nif sum(list(map(int, s[n // 2:]))) != sum(list(map(int, s[:n // 2]))):\r\n ans = \"NO\"\r\nprint(ans)\r\n", "n=int(input())\r\nt=int(input())\r\ns=str(t)\r\nif s.count('4')+s.count('7')!=n:\r\n print('NO')\r\nelse:\r\n res1,res2=0,0\r\n for i in range(0,n//2):\r\n res1+=int(s[i])\r\n res2+=int(s[i+n//2])\r\n if res1==res2:\r\n print('YES')\r\n else:\r\n print('NO')", "x=int(input())\r\nz=[int(n) for n in str(int(input()))]\r\nl=0\r\n#print(z)\r\nfor n in z:\r\n if n==4 or n==7:\r\n l=1\r\n else:\r\n print('NO')\r\n l=0\r\n break\r\nif l==1:\r\n if sum(z[0:x//2])==sum(z[x//2:x]):\r\n print('YES')\r\n else:\r\n print('NO')\r\n", "n = int(input())\r\ns = input()\r\nsum1 = 0\r\nsum2 = 0\r\nfor i in range(n//2):\r\n a = int(s[i])\r\n b = int(s[n//2+i])\r\n if not a in (4,7) or not b in (4,7):\r\n print(\"NO\")\r\n exit()\r\n sum1 += a\r\n sum2 += b\r\nif sum1 == sum2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=int(input())\r\nb=[int(i) for i in input()]\r\nc=list(set(b))\r\np=0\r\nif len(c)==2 and abs(c[0]-c[1])==3 and sum(c)==11:\r\n\tp=1\r\nelif len(c)==1 and c[0]==4 or c[0]==7:\r\n\tp=1\r\nif p==1 and sum(b[:a//2])==sum(b[a//2:]):\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "nn=int(input())\r\nn=input()\r\nif (set(n)=={\"4\",\"7\"} or set(n)=={\"7\"} or set(n)=={\"4\"}) and sum(map(int,list(n[0:nn//2])))==sum(map(int,list(n[nn//2:]))): print(\"YES\")\r\nelse: print(\"NO\")", "n=int(input())\r\na=input()\r\nl=len(a)\r\nc=0\r\nfor i in a:\r\n if i =='4' or i == '7':\r\n c=c+1\r\n else:\r\n continue\r\nsum1=0\r\nsum2=0\r\nif(c==l):\r\n for i in range(0,l//2):\r\n sum1=sum1+int(a[i])\r\n for i in range(l//2,l):\r\n sum2=sum2+int(a[i])\r\n if(sum1==sum2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n", "n=int(input());s=input();f=0\r\nfor i in s:\r\n\tif i=='4' or i=='7':f+=1\r\nif n%2 or f!=n:print('NO')\r\nelse:\r\n\tsl,sr=0,0\r\n\tfor i in range(n//2):sl+=int(s[i])\r\n\tfor i in range(n//2,n):sr+=int(s[i])\r\n\tif sl==sr:print('YES')\r\n\telse:print('NO')", "'''\r\n\r\nAuthor\t: Indian Coder\r\nDate\t: 27th May ,2021\r\nContest : PWC 2.0 Practice \r\n\r\n'''\r\n\r\n#Imports\r\n\r\nimport math\r\nimport time \r\nimport random\r\nimport textwrap\r\nimport calendar\r\nimport re\r\nfrom datetime import datetime\r\nfrom itertools import permutations,combinations #Create All Possible Combination takes (\"data\",\"len\")\r\nstart=time.time()\r\n\r\nn=int(input())\r\ns=input()\r\ns1=0\r\ns2=0\r\nfor i in range(0,len(s)//2):\r\n s1+=int(s[i])\r\nfor j in range(len(s)//2,len(s)):\r\n s2+=int(s[j])\r\n\r\nif(s.count(\"4\")+s.count(\"7\")==len(s) and s1==s2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\nend=time.time()\r\n#print(\"Time Of Execution Is\",end-start)\r\n \r\n\r\n\r\n\r\n", "def SumOfDigits(x):\n total_sum = 0\n for i in range(len(x)):\n total_sum += int(x[i])\n return total_sum\n\n\nn = int(input())\nx = input()\nif x.count('4') + x.count('7') == n and SumOfDigits(x[: n // 2]) == SumOfDigits(x[n // 2:]):\n print('YES')\nelse:\n print('NO')\n", "n = int(input())\r\ns = list(map(int,input()))\r\nS = set(s)\r\nif (S == {4,7 }) or (S == {4}) or(S== {7}):\r\n print(['NO' ,'YES'][sum(s[:n//2]) == sum(s[n//2:])])\r\nelse :\r\n print('NO')", "n = int(input())\ns = input()\nss = set(s)\nk = len(ss)\nif k==2 and '4' in ss and '7' in ss or k==1 and ('4' in ss or '7' in ss):\n a,b = s[:n//2],s[n//2:]\n if eval('+'.join(a))== eval('+'.join(b)):\n print('YES')\n else:\n print('NO')\nelse:\n print('NO')\n\n'''\nw = int(input())\nfor _ in range(w):\n input()\n a = sorted(set(map(int,input().split())))\n for i in range(1,len(a)):\n if a[i]-a[i-1]>1:\n print('NO')\n break\n else:\n print('YES')\n'''\n", "import math;\r\nt=int(input())\r\nn=input()\r\nl=['4','7']\r\nans=True\r\nfor i in n:\r\n if(i not in l):\r\n ans=False\r\n break\r\nsum1=0\r\nsum2=0\r\nfor i in range (0,(t//2)):\r\n sum1+=int(n[i])\r\nfor j in range(t//2,t):\r\n sum2+=int(n[j])\r\nif(ans==True and sum1==sum2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "#Davidson Lisboa Della Piazza, 169786\n\ndef isLucky(n):\n for x in n:\n if(x!=4 and x!=7):\n return False\n return True\n\ndef luckyTicket(n):\n z = 0\n y = 0\n if(isLucky(n)):\n fhalf = int(len(n)/2)\n shalf = int(len(n))\n for i in range(0, fhalf):\n z = z+int(n[i])\n for i in range(fhalf, shalf):\n y = y+int(n[i])\n if(z==y):\n print(\"YES\")\n return\n print(\"NO\")\n\n\nn = int(input())\nticket = input()\nticket = list(map(int, str(ticket)))\nluckyTicket(ticket)\n\t\t\t\t\t\t \t\t\t\t\t\t \t \t \t \t\t", "def lucky(n):\r\n for i in n:\r\n if i != '4' and i!= '7':\r\n return False\r\n return True\r\n\r\ndef half(n):\r\n a=0\r\n b=0\r\n for i in range(len(n)//2):\r\n a += int(n[i])\r\n for i in range(len(n)//2,len(n)):\r\n b += int(n[i])\r\n \r\n return a==b\r\n\r\nn=int(input())\r\nm=input()\r\nif lucky(m) and half(m):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\nk = [ord(x) - ord('0') for x in input()]\nprint(\"YES\" if k.count(7) + k.count(4) == n and sum(k[:n//2]) == sum(k[n//2:]) else \"NO\")", "#To check whether the ticket is a lucky ticket or not\r\n\r\nn = int(input())\r\nnum = input()\r\n\r\nsum1=0\r\nsum2=0\r\nflag=0\r\nfor i in num:\r\n if(i!='7' and i!='4'):\r\n flag=1\r\n break\r\nif flag==0: \r\n for i in range(0,int(n/2)):\r\n sum1+=int(num[i])\r\n for i in range(int(n/2),n):\r\n sum2+=int(num[i])\r\n if(sum1==sum2):\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')\r\n\r\n\r\n\r\n\r\n", "from collections import defaultdict\r\nn=int(input())\r\nstring=input()\r\n\r\nlist1=[int(i) for i in string]\r\nhash_map=defaultdict(int)\r\nvalue=sum(list1)\r\nstore=value\r\n\r\nfor i in list1:\r\n hash_map[i]+=1\r\n\r\n\r\nfor i in hash_map:\r\n if i==4 or i==7:\r\n continue\r\n else:\r\n print(\"NO\")\r\n exit(0)\r\n\r\nfor i in range(n-1,n//2-1,-1):\r\n \r\n store-=list1[i]\r\n\r\nif value//2==store:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n = map(int,input().split())\nline = list(map(int,input().strip()))\n#print(line)\na=0\nlenth = int(len(line)/2)\nfor i in line:\n if i!=7 and i!=4:\n print(\"NO\")\n a=1\n break\nif a==0:\n c = line[:lenth]\n b = line[lenth:]\n if sum(c) == sum(b):\n print(\"YES\")\n else:\n print(\"NO\")\n\t \t\t\t\t \t \t \t \t \t \t\t \t\t\t\t", "n = int(input())\r\nk = n // 2\r\nt = input()\r\np = t[:k]\r\na = t.count('4')\r\nb = t.count('7')\r\nif a + b == n and 8 * p.count('4') + 14 * p.count('7') == 4 * a + 7 * b: print('YES')\r\nelse: print('NO')", "n=int(input())\r\nstring=input()\r\nflag=0\r\nfor i in string:\r\n if i not in ['4','7']:\r\n flag=1\r\n break\r\nif flag==0:\r\n total1=0;total2=0\r\n for i in range(n//2):\r\n total1+=int(string[i])\r\n for i in range(n//2,n):\r\n total2+=int(string[i])\r\n if total1!=total2:\r\n flag=1\r\nif flag==0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=input()\na=list(map(int, str(input())))\nt=1\nfor i in range(len(a)):\n if(a[i]== 4):\n continue\n elif(a[i]==7):\n continue\n else:\n t=0\n break\nif(sum(a[:int(len(a)/2)])==sum(a[int(len(a)/2):int(len(a))]) and t==1):\n print('YES')\nelse:\n print('NO')\n\t \t \t \t\t \t \t\t \t", "n = int(input())\r\nticket_number = input()\r\ncount_first_half = count_second_half = 0\r\n\r\nfor i in range(n // 2):\r\n if ticket_number[i] != '4' and ticket_number[i] != '7':\r\n print(\"NO\")\r\n exit(0)\r\n elif ticket_number[i] == '7':\r\n count_first_half += 1\r\n\r\nfor i in range(n // 2, n):\r\n if ticket_number[i] != '4' and ticket_number[i] != '7':\r\n print(\"NO\")\r\n exit(0)\r\n elif ticket_number[i] == '7':\r\n count_second_half += 1\r\n\r\nif count_first_half == count_second_half:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "# You lost the game.\nn = int(input())\ns = str(input())\ns1 = s2 = 0\nfor i in range(n//2):\n s1 += int(s[i])\n s2 += int(s[n//2+i])\nif s1 == s2 and s.count(\"4\") + s.count(\"7\") == n:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "n=int(input())\r\na=list(map(int,input()))\r\nc=0\r\nn=len(a)//2\r\nfor i in range(len(a)):\r\n if a[i]!=4 and a[i]!=7:\r\n c=c+1\r\nif c>0:\r\n print(\"NO\")\r\nelif sum(a[:n])==sum(a[n:]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\ns = list(input())[:n]\r\na = True\r\ntsu, su = 0, 0\r\nfor i in range(0, len(s)):\r\n if (s[i] != '4' and s[i] != '7'):\r\n a = False\r\n break\r\n\r\nfor i in range(0, len(s) // 2):\r\n su += int(s[i])\r\nfor i in range((len(s) // 2), len(s)):\r\n tsu += int(s[i])\r\n\r\nif (a == False):\r\n print(\"NO\")\r\nelif (tsu == su and a == True):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\ns = input()\r\ncan = True\r\na = 0\r\nb = 0\r\nfor i in range(n // 2):\r\n a += int(s[i])\r\n if s[i] != '4' and s[i] != '7':\r\n can = False\r\nfor i in range(n // 2, n):\r\n b += int(s[i])\r\n if s[i] != '4' and s[i] != '7':\r\n can = False\r\nif can and a == b:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\na=list(map(int, str(input())))\nn=len(a)\nt=1\nfor i in range(n):\n if(a[i]== 4):\n continue\n elif(a[i]==7):\n continue\n else:\n t=0\n break\n \nif(t==0):\n print('NO')\nelse:\n if(sum(a[:int(n/2)])==sum(a[int(n/2):n])):\n print('YES')\n else:\n print('NO')\n\t \t \t \t \t \t \t\t \t \t \t\t\t\t", "N = int(input())\nS = input()\n\nfor s in S:\n if s != \"4\" and s != \"7\":\n print(\"NO\")\n exit()\n\nleft = sum([int(S[i]) for i in range(N // 2)])\nright = sum([int(S[i]) for i in range(N // 2, N)])\nif left == right:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "def luckyticket(input):\n half = (int)(input[0]/2)\n fh, sh = input[1][0:half], input[1][half:]\n valid = set(['4','7'])\n val_data = set(list(input[1])+list(valid))\n if (val_data.difference(valid) != set()):\n return('NO')\n if (sum([int(x) for x in fh]) == sum([int(x) for x in sh])):\n return('YES')\n return('NO')\n\ndef get_input(q_size):\n return [ [int(j) for j in input().split(\" \")] for i in range(q_size) ]\n\nif __name__ == \"__main__\":\n data = []\n data.append((int)(input()))\n data.append((str)(input()))\n print(luckyticket(data))\n\t \t\t \t\t \t \t \t\t \t \t\t \t \t", "n = int(input());s = input()\r\nif(s.count('4') + s.count('7') != n):print(\"NO\")\r\nelse:\r\n s1, s2 = 0, 0\r\n for i in range(n//2):s1 += int(s[i])\r\n for i in range(n//2, n):s2 += int(s[i])\r\n if(s1 == s2): print(\"YES\")\r\n else:print(\"NO\")", "n=int(input())\r\ns=input()\r\nf1,f2=1,1\r\nfor i in range(n):\r\n if s[i] in \"12356890\":\r\n f1=0\r\nif f1:\r\n if s[:n//2].count(\"4\")==s[n//2:].count(\"4\") and s[:n//2].count(\"7\")==s[n//2:].count(\"7\"):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "'''\n#Q1: A. Watermelon\na = int(input())\nif a == 2:\n print(\"No\")\nelif a % 2 == 0:\n print(\"yes\")\nelse:\n print(\"No\")\n \n################################################################################\n\n#Q1: A. Way Too Long Words\nRan = int(input())\nfor i in range(Ran):\n a = input()\n b = len(a)\n if b <= 10:\n print(a)\n elif b > 10:\n print(str(a[:1])+str(b-2)+str(a[len(a)-1]))\n\n################################################################################\n #contest 23-11-2021\n\n#Q1: A. Anti Light's Cell Guessing\nfor i in range(int(input())):\n m,n = input().split()\n if m == \"1\" and n == \"1\":\n print(\"0\")\n elif m == \"1\" or n == \"1\":\n print(\"1\")\n else:\n print(\"2\")\n \n###############################################################################\n\n#Q1:A. Translation\na = input()\nb = input()\nif a[::-1] == b:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n##############################################################################\n\n#Q1: A. Word Capitalization\na = input()\nb = a[0].title()\nprint(b+a[1:len(a)])\n\n##############################################################################\n\n#Q1: A. Make Even\na = int(input())\nfor i in range(a):\n b = input()\n if int(b[-1]) % 2 == 0:\n print(0)\n elif int(b[0]) % 2 == 0:\n print(1)\n elif '2' in b[0:-1] or '4' in b[0:-1] or '6' in b[0:-1] or '8' in b[0:-1]:\n print(2)\n else:\n print(-1)\n\n##############################################################################\n#contest 01-12-2021\n\na = int(input())\nfor i in range(a):\n x1,x2 = input().split()\n y1,y2 = input().split()\n m = int(x1+(int(x2)*str(0)))\n n = int(y1+(int(y2)*str(0)))\n if m > n:\n print(\">\")\n elif m < n:\n print(\"<\")\n else:\n print(\"=\")\n\n##############################################################################\n\na = int(input())\nfor i in range(a):\n x1,x2 = input().split()\n print(int(x1+(int(x2)*str(0))))\n y1,y2 = input().split()\n if (int(x1+(int(x2)*str(0)))) > (int(y1+(int(y2)*str(0)))):\n print(\">\")\n elif (int(x1+(int(x2)*str(0)))) < (int(y1+(int(y2)*str(0)))):\n print(\"<\")\n else:\n print(\"=\")\n\n##############################################################################\n\n# 002. Triple Product\nn = int(input())\nm = int(input())\nprint((n*m)*3)\n\n####################################################################\n\n# 001. Square The Number\nn = int(input())\nprint(n*n)\n\n####################################################################\n\n# 003. Triangle Sum\nn = int(input())\na = 0\nfor i in range(n):\n b = int(input())\n a += b*3\nprint(a)\n\n###################################################################\n\n# 004. Polygons\nn = int(input())\nfor i in range(n):\n b = int(input())\n s = (b-2)*180\n print(s)\n\n###################################################################\n\n# 005. Fizz Buzz\n\nn = int(input())\nif n % 3 == 0 and n % 5 == 0:\n print(\"FizzBuzz\")\nelif n % 3 == 0:\n print(\"Fizz\")\nelif n % 5 == 0:\n print(\"Buzz\")\nelse:\n print(\"\")\n\n###################################################################\n# 007. Clock Seconds\n\na = int(input())\nb = int(input())\nc = int(input())\nd = input()\nx = 12 * 3600\nn = a * 3600\nm = b * 60\nif d == \"AM\":\n print(n+m+c)\nelse:\n if d == \"PM\":\n print(x+n+m+c)\n\n#######################################################################\n# 006. Distance\n\nx1 = int(input())\ny1 = int(input())\nx2 = int(input())\ny2 = int(input())\nn = ((x2 - x1)**2)\nm = ((y2 - y1)**2)\nprint((n+m)**0.5)\n\n#######################################################################\n# 010. Points per Game\n\na = int(input())\nb = int(input())\nprint(a/b)\n\n#######################################################################\n# 011. Ski Sum\n\na,b,c,d = map(int,input().split())\nprint(a+b+c+d)\n\n#######################################################################\n# 012. Easy Exponentials\n\na,b = map(int,input().split())\nprint(a**b)\n\n#######################################################################\n# 013. Resistors in Parallel\n\na = int(input())\nb = int(input())\nprint((a * b) / (a + b))\n\n#######################################################################\n# 014. Labyrinth\n\na,b = map(int,input().split())\nanswer = 0\nfor i in range(a):\n c = input()\n y=c.count(\"x\")\n1 answer += y\nprint(answer)\n \n#######################################################################\n# 016. Gravity Vehicle Testing\n\na = input()\nif a == \"EARTH\":\n print(\"9.807\")\nelse:\n print(\"3.711\")\n\n#######################################################################\n# 017. Chem Lab: Cross the Charges\n\na,b = input().split()\nprint(b,a)\n\n#######################################################################\n# 018 Machines\n\nn = int(input())\nfor i in range(n):\n a,b = map(int,input().split())\n print(a/b)\n\n#######################################################################\n# 023. Ping Pong Parachute\n\nv = float(input())\nvi = v**2\nvf = (0**2)\na = (2*(-9.8))\nprint((vf-vi)/a)\n\n#######################################################################\n# 026 - Competition Rules\n\na = input()\nprint(\"Competition Rules:\")\nprint(a)\n\n#######################################################################\n# 027. Money Sum\n\nn = int(input())\nanswer = 0\nfor i in range(n):\n a = int(input())\n answer += a\nprint(answer)\n\n#######################################################################\n# 028. Funny Numbers\n\na = int(input())\nif a % 5 == 0 and a % 7 == 0:\n print(\"YES\")\nelse:\n print(\"NO\")\n \n#######################################################################\n# 029 - Goooooooooal!\n\na = input()\nb = a.count(\"o\")\nprint(b)\n\n#######################################################################\n# 031 - 2001: A Space Odyssey\n\na = int(input())\nb = 2\nwhile True:\n if a%b == 0:\n print(b)\n break\n else:\n b = b+1\n\n#######################################################################\n\n# 039. Number Code (Easier Version)\n\nd = {\"0\":\"o\",\"1\":\"i\",\"3\":\"e\",\"4\":\"a\",\"5\":\"s\",\"7\":\"t\"}\nfor i in range(int(input())):\n a = input().split()\n answer = \"\"\n for j in a:\n for k in j:\n answer += d.get(k)\n answer +=\" \"\n print(answer)\n\n\n#######################################################################\n\n# A. Polycarp and Sums of Subsequences\n\nn = int(input())\nfor i in range(n):\n a,b,c,d,e,f,g = map(int,input().split())\n m = a + b\n if m == d:\n print(a,b,c)\n else:\n print(a,b,d)\n\n######################################################################\n\n# A. Team\n\ncount = 0\nfor i in range(int(input())):\n a,b,c = input().split()\n x = a,b,c\n d = x.count('1')\n if d > 1:\n count += 1\nprint(count)\n\n######################################################################\n\n# A. In Search of an Easy Problem\n\nm = int(input())\nm1 = input().split()\nif '1' in m1:\n print(\"HARD\")\nelse:\n print(\"EASY\")\n\n######################################################################\n\n\n# A. Mishka and Game\n\nm1 = 0\nc1 = 0\nfor i in range(int(input())):\n m,c = map(int,input().split())\n if m > c:\n m1 += 1\n elif m<c:\n c1 += 1\nif m1 > c1:\n print(\"Mishka\")\nelif m1<c1:\n print(\"Chris\")\nelse:\n print('Friendship is magic!^^')\n\n######################################################################\n\nA. New Year and Hurry\n\na,b = map(int,input().split())\nn = 240 - b\nm = 0\ni = 1\nwhile n>=(i*5) and i<=a:\n n-=(i*5)\n i+=1\n m+=1\nprint(m)\n\n\n######################################################################\n\n# A. Equidistant Letters\n\nfor i in range(int(input())):\n a = list(input())\n a.sort()\n b = ''\n for j in range(len(a)):\n b += a[j]\n print(b)\n\n######################################################################\n\n# A. FashionabLee\n\nfor i in range(int(input())):\n a = int(input())\n if a % 4 == 0:\n print(\"YES\")\n else:\n print(\"NO\")\n\n######################################################################\n\n# A. Mahmoud and Ehab and the even-odd game\n\na = int(input())\nif a % 2 == 0:\n print(\"Mahmoud\")\nelse:\n print(\"Ehab\")\n\n######################################################################\n\n#180. Boring Strings\n\nn = input()\nm = len(n)\nq = n.count('a')\nw = n.count('b')\nl = int(q + w)\nif int(m) == l:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n######################################################################\n\n# A. Word\n\na = input()\nupper = 0\nlower = 0\nfor i in range(len(a)):\n if a[i] == a[i].upper():\n i += 1\n upper += 1\n else:\n lower += 1\n \nif upper > lower:\n print(a.upper())\nelif upper <= lower:\n print(a.lower())\n\n######################################################################\n\n# {_@_A_b_d_u_l___M_a_l_i_k_@_}\n\n# A. Minutes Before the New Year\n\nfor i in range(int(input())):\n h,m = map(int,input().split())\n input_m = ((60*h)+m)\n total_m = 1440\n answer = total_m - input_m\n print(answer)\n\n# {_@_A_b_d_u_l___M_a_l_i_k_@_}\n\n######################################################################\n\n# {_@_A_b_d_u_l___M_a_l_i_k_@_}\n\n# A. Domino piling\n\na,b = map(int,input().split())\nc = (a*b)//2\nprint(c)\n\n# {_@_A_b_d_u_l___M_a_l_i_k_@_}\n\n######################################################################\n\n# {_@_A_b_d_u_l___M_a_l_i_k_@_}\n\n# A. Download More RAM\n\nfor i in range(int(input())):\n a,b = map(int,input().split())\n c = list(map(int,input().split()))\n d = list(map(int,input().split()))\n if b < min(c):\n print(b)\n else:\n e = []\n for j in range(a):\n e.append((c[j] , d[j]))\n e.sort()\n for k in range(len(e)):\n if e[k][0] <= b:\n b += e[k][1]\n print(b)\n\n# {_@_A_b_d_u_l___M_a_l_i_k_@_}\n \n######################################################################\n\n# {_@_A_b_d_u_l___M_a_l_i_k_@_}\n\n# A. Vus the Cossack and a Contest\n\nn,m,k = map(int,input().split())\nif n <= m and n <= k:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n# {_@_A_b_d_u_l___M_a_l_i_k_@_}\n\n######################################################################\n\nfor i in range(int(input())):\n a,b = map(int,input().split())\n m = a*b\n if m % 3 == 0:\n print(m//3)\n else:\n print((m//3)+1)\n\n######################################################################\n\na = int(input())\nb = 0\nfor i in range(a):\n c = input()\n if c == \"Icosahedron\":\n b += 20\n elif c == \"Cube\":\n b += 6\n elif c == \"Tetrahedron\":\n b += 4\n elif c == \"Dodecahedron\":\n b += 12\n else:\n if c == \"Octahedron\":\n b += 8\nprint(b)\n\n######################################################################\n\nk,n,w = map(int,input().split())\nm = 0\nfor i in range(1,w+1):\n m += i*k\nif m > n:\n print(m - n)\nelse:\n print(0)\n\n######################################################################\n\nfor i in range(int(input())):\n n = int(input())\n a = list(map(int,input().split()))\n b = list(map(int,input().split()))\n a1 = []\n b1 = []\n for i in range(n):\n if a[i] > b[i]:\n a1.append(b[i])\n b1.append(a[i])\n else:\n a1.append(a[i])\n b1.append(b[i])\n print(max(a1) * max(b1))\n\n###################################################################### \n \n# C. Abhilash's Dog \n \nm = int(input()) \nan = [] \nans = 0 \nwn = int(input()) \nfor i in range(wn): \n w = int(input()) \n an.append(w) \nan.sort() \nfor i in range(len(an)): \n if m >= an[i]: \n ans += 1 \n m = m - an[i] \n else: \n if m < an[i]: \n break \nprint(ans) \n\n######################################################################\n\nfor i in range(int(input())):\n a = int(input())\n b = input()\n c = b.count(\"0\")\n d = b.count(\"1\")\n if c > 1 or d > 1:\n print('NO')\n else:\n print('YES')\n\n######################################################################\n\nfor i in range(int(input())):\n a = int(input())\n if a%7 == 0:\n print(a)\n else:\n a = str(a)\n for i in range(1,10):\n if int(str(i)+a[1:])%7==0:\n print(str(i)+a[1:])\n break\n elif int(a[:-1]+str(i))%7 ==0:\n print(a[:-1]+str(i))\n break\n \n######################################################################\n\nfor i in range(int(input())):\n a = input()\n b = a.count(\"0\")\n c = a.count(\"1\")\n if b == c:\n print(b-1)\n elif b > c:\n print(c)\n elif b < c:\n print(b)\n\n######################################################################\n\n\n# A. Perfect Squares\n\nn = int(input())\nf = list(map(int,input().split()))\nm = []\nx = []\nfor i in range(n):\n h = str((f[i])**0.5)\n if f[i] < 0:\n x.append(f[i])\n elif (int(h[-1]))== 0:\n m.append(f[i])\n else:\n if (int(h[-1])) != 0:\n x.append(f[i])\nprint(max(x))\n\n######################################################################\n\nfor i in range(int(input())):\n a1,b1 = map(int,input().split());a2,b2 = map(int,input().split());\n c1 = max(a1,b1);c2 = max(a2,b2);d1 = min(a1,b1);d2 = min(a2,b2)\n n = d1 + d2\n if c1 != c2:\n print('No')\n elif n == c1 or n == c2: print('Yes')\n else: print('No')\n\n######################################################################\n\nh,l = map(int,input().split());x = (l**2)-(h**2);print(x/(2*h))\n\n######################################################################\n\nfor i in range(int(input())):\n x,y = map(int,input().split())\n z = input()\n w = z[::-1]\n print(z)\n print(w)\n if y == 0 or w == z:\n print(1)\n else:\n print(2)\n\n######################################################################\n\nm = input();a = m.replace(\"--\",\"2\");l = a.replace(\"-.\",\"1\");i = l.replace(\".\",\"0\");print(i)\n\n#######################################################################\n\n# {_@_A_b_d_u_l___M_a_l_i_k_@_} \n\na = int(input());b = list(map(int,input().split()))\nx = b.count(1);y = b.count(2); z = b.count(3)\nprint(min(x,y,z))\nl = [];m = [];n = []\nfor i in range(a):\n if b[i] == 1:\n l.append(i+1)\n if b[i] == 2:\n m.append(i+1)\n if b[i] == 3:\n n.append(i+1)\no = (min(len(l),len(m),len(n)))\nfor j in range(o):\n print(l[j],m[j],n[j])\n\n#######################################################################\n\n# {_@_A_b_d_u_l___M_a_l_i_k_@_}\n\n# A. 123-sequence\n\na = int(input());b = input().split()\nm = b.count('1'); m1 = b.count('2'); m2 = b.count('3')\nm3 = max(m,m1,m2); print(len(b) - m3)\n\n########################################################################\n\n# {_@_A_b_d_u_l___M_a_l_i_k_@_}\n\nm = input()\nwhile len(m) > 1:\n n = 0\n for i in m:\n n += int(i)\n m= str(n)\nprint(m)\n\n########################################################################\n\n# {_@_A_b_d_u_l___M_a_l_i_k_@_}\n\na = int(input())\nif a == 1:\n print(1)\nelif a ==70:\n print(70)\nelif a == 5:\n print(70)\nelif a == 2:\n print(2)\nelif a == 3:\n print(6)\nelif a == 4:\n print(20)\nelif a == 6:\n print(252)\nelif a == 7:\n print(924)\nelif a == 9:\n print(12870)\nelif a == 10:\n print(48620)\nelif a == 8:\n print(3432)\n\n########################################################################\n\n# {_@_A_b_d_u_l___M_a_l_i_k_@_}\nn,k = map(int,input().split())\nfor i in range(int(k)):\n if n[-1] != '0':\n n = int(n)\n n -= 1\n elif n[-1] == '0':\n n = n // k\nprint(n)\n\n########################################################################\n\nfor i in range(int(input())):\n a = int(input())\n b = input()\n c = 0\n for i in range(a):\n if 'AP' in b:\n c += 1\n b = b.replace('AP','AA')\n else:\n break\n print(c)\n \n###########################################################################\n\nn,k = map(int,input().split())\nfor i in range(k):\n if str(n)[-1] == \"0\":\n n//=10\n else:\n n = n-1\nprint(n)\n\n###########################################################################\n\na,b,c = map(int,input().split())\nl =(a + b)-1\nm = c - 1\nn = (b * a )\nprint(l*m+n)\n\n###########################################################################\n\n# B. Square Difference \n\nfor i in range(int(input())): \n a,b = map(int,input().split()) \n m = a+b ; n = a-b ; p = (int(m**0.5)+1) ; ans = 0 \n for i in range(1,p): \n div = m % i \n if div == 0: \n ans += 1 \n if ans == 1 and n == 1: \n print('YES') \n else: \n print('NO')\n \n\n###########################################################################\n\nfor i in range(int(input())):\n b = int(input())\n a = list(map(int,input().split()))\n m = []\n n = []\n for i in range(len(a)):\n for j in range(len(a)-1):\n if a[j] < a[j + 1] and (a[j] + a[j+1]) // 2 == 0:\n\n###########################################################################\n\nfor i in range(int(input())):\n n = int(input())\n m = n - 1\n print(m,\"1\") \n\n\n \n#########################################################################\n\n# A. String Task\n\na = input().lower()\nm = ''\nfor i in range(len(a)):\n if a[i] not in 'aoyeui':\n m += '.'+a[i]\nprint(m)\n\n######################################################################\n\nfor i in range(int(input())):\n a = input()\n m1 = a.index('r')\n m2 = a.index('R')\n n1 = a.index('g')\n n2 = a.index('G')\n z1 = a.index('b')\n z2 = a.index('B')\n if int(m1) < int(m2) and int(n1) < int(n2) and int(z1) < int(z2):\n print('YES')\n else:\n print('NO')\n \n######################################################################\n\nfor i in range(int(input())):\n a1 = int(input())\n a = input()\n m = int((len(a))/2)\n if a1 == 4 and a == 'RD':\n print('13')\n if len(a) == 1:\n print(a1)\n elif a[0] == 'D' and a[-1] == 'R':\n print(m+a1)\n \n######################################################################\n\n# {_@_A_b_d_u_l___M_a_l_i_k_@_}\n\nn,q = map(int,input().split())\nm = []\nfor i in range(q):\n f = list(map(int,input().split()))\n if f == '1 2':\n continue\n if f[0] == 0:\n m.append(f[0])\n m.append(f[1])\n m.append(f[2])\n if f[3] == 0:\n print('NO')\n else:\n if f[3] == 1:\n print('YES')\n else:\n if f[0] == 1:\n if f[1] not in m:\n print('N/A')\n\n#####################################################################################\n\n# //{_@_A_b_d_u_l___M_a_l_i_k_@_}////////////\n\n# //Author: Abdul MALik//////////////////\n\n# //630/problem/N////////\n\n# //Forecast////////\n\na,b,c = map(int,input().split())\nf1 = (b*b)-(4*a*c)\nf3 = (-b+f1**0.5)/2/a\nf4 = (-b-f1**0.5)/2/a\nprint(max(f4,f3))\nprint(min(f3,f4))\n\n#####################################################################################\n\n# //{_@_A_b_d_u_l___M_a_l_i_k_@_}////////////\n\n# //Author: Abdul MALik//////////////////\n\n# //Hexagons!:///////////\n\na = int(input())\nn = 1\nfor i in range(1,a+1):\n m = i*6\n n += m\nprint(n)\n\n#####################################################################################\n\n# //{_@_A_b_d_u_l___M_a_l_i_k_@_}////////////\n\n# //Author: Abdul MALik//////////////////\n\n# //Fingerprints!:///////////\n\nm,n = map(int,input().split())\nx = input().split()\ny = input().split()\nf = ''\nfor i in range(m):\n if x[i] in y:\n f += x[i]+' '\nprint(f)\n\n#####################################################################################\n\n# //{_@_A_b_d_u_l___M_a_l_i_k_@_}////////////\n\n# //Author: Abdul MALik//////////////////\n\n# //Fingerprints!:///////////\n\na = int(input())\nif a == 35:\n print('57')\nelif a == 57:\n print('319')\nelif a == 391:\n print('1723')\n\n#####################################################################################\n\n'''\n\n# //{_@_A_b_d_u_l___M_a_l_i_k_@_}////////////\n\n# //Author: Abdul MALik//////////////////\n\n# //Fingerprints!:///////////\n\na = int(input())\na1 = input()\nm = a1.count('4'); n = a1.count('7')\nif len(a1) != m+n:\n print('NO')\nelse:\n if len(a1) == m+n:\n x = (a1[:(a//2)])\n y = (a1[(a//2):])\n x1 = 0\n y1 = 0\n for i in range(len(x)):\n x1 += int(x[i])\n y1 += int(y[i])\n if x1== y1:\n print('YES')\n else:\n print('NO')\n\n\n\n\n\n \n", "n=int(input())\r\nnumber=list(map(int,list(input())))\r\nh1=0\r\nh2=0\r\nx=0\r\nfor i in range(n):\r\n if number[i]!=4 and number[i]!=7:\r\n print(\"NO\")\r\n x+=1\r\n break\r\n if i <n//2:\r\n h1+=number[i]\r\n else:\r\n h2+=number[i]\r\nif not x: \r\n if h1==h2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "data = [int(input()), input()]\r\n\r\nnumber = list(data[1])\r\n\r\n# happy number check\r\nif number.count('4') + number.count('7') != data[0]:\r\n\tprint('NO')\r\nelse:\r\n # happy ticket check\r\n middle = int(data[0] / 2)\r\n right = number[middle:].count('4')\r\n left = number[:middle].count('4')\r\n if left == right:\r\n \tprint('YES')\r\n else:\r\n \tprint('NO')", "n=int(input())\r\ns=input()\r\nc=0\r\nfor i in s:\r\n if(i=='4' or i=='7'):\r\n c+=1\r\n else:\r\n break\r\nif(c==n):\r\n fh=0\r\n sh=0\r\n m=n//2\r\n for i in range(m):\r\n fh+=int(s[i])\r\n sh+=int(s[i+m])\r\n if(fh==sh):\r\n print(\"YES\")\r\n else:\r\n print('NO')\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\ns = str(input())\r\nif s.count('4') + s.count('7')==n:\r\n\r\n x = s[:n//2]\r\n y = s[n//2:]\r\n x = [int(i) for i in x]\r\n y = [int(i) for i in y]\r\n if sum(x) == sum(y):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\nleft = right = 0\ns = input()\nfor i in range(n // 2):\n x = s[i]\n y = s[n - i - 1]\n if x not in \"47\" or y not in \"47\":\n print(\"NO\")\n break\n left += int(x)\n right += int(y)\nelse:\n if left == right:\n print(\"YES\")\n else:\n print(\"NO\")\n\n", "n = int(input())\r\na = input().split()[0]\r\na1 = a[:n//2]\r\na2 = a[n//2:]\r\nsa = set(a)\r\nif sa == {'4'} or sa == {'7'} or sa == {'4', '7'}:\r\n if a1.count ('4') == a2.count ('4') and a1.count ('7') == a2.count ('7'):\r\n print ('YES')\r\n else:\r\n print ('NO')\r\nelse:\r\n print ('NO')", "n = int(input())\nt = input()\n\nfirst = 0\nsecond = 0\nlucky = True\n\nfor i in range(n):\n if(t[i] != '4' and t[i] != '7'):\n lucky = False\n break\n elif(i < n/2):\n first += int(t[i])\n else:\n second += int(t[i])\n\nif(lucky and first==second):\n print('YES')\nelse:\n print('NO')\n\t \t\t \t\t \t \t\t \t \t \t \t \t\t\t\t \t", "lengthOfTicket=input() #inputing lengthOfTicket\n\t\nnumber=input()\n\nlsum=0\nrsum=0\n\nisLucky=True\n\nlastIndex=len(number)-1\nhalf=(int)(len(number)/2)\nfor i in range (half):\n\tif (number[i]!='4' and number[i]!='7'):\n\t\tisLucky=False\n\t\tbreak\n\tif (number[lastIndex]!='4' and number[lastIndex]!='7'):\n\t\tisLucky=False\n\t\tbreak\n\tlsum=lsum+(int)(number[i])\n\trsum=rsum+(int)(number[lastIndex])\n\tlastIndex=lastIndex-1\nif(isLucky==True and lsum==rsum):\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\t \t \t \t \t \t\t\t \t\t \t \t", "input()\r\ns = input()\r\nflag = 1\r\nfor i in s:\r\n if i != '4' and i != '7': flag = 0\r\nif flag == 0:\r\n print('NO')\r\nelse:\r\n sum1,sum2 = 0,0\r\n for i in s[0:len(s)//2]:\r\n sum1 += int(i)\r\n for i in s[len(s)//2:]:\r\n sum2 += int(i)\r\n if sum1 == sum2:\r\n print('YES')\r\n else:\r\n print('NO')", "n=int(input())\r\ns=str(input())\r\nz=0\r\na=0\r\nfor i in range(n):\r\n\tif s[i]!=\"4\" and s[i]!=\"7\":\r\n\t\ta=1 \r\n\t\tbreak\r\n\telse:\r\n\t\tif i<(n//2):\r\n\t\t\tz+=int(s[i])\r\n\t\telse:\r\n\t\t\tz-=int(s[i])\r\nif a==0 and z==0:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\") \r\n\r\n", "n = int(input())\na = list(str(input()))\n\nyes = True\nfor i in a:\n if(not(i == '4' or i == '7')):\n yes = False\nif(yes ):\n primeira_parte= a[:(n//2)]\n segunda_parte = a[n//2:]\n sum_p =0\n sum_s =0\n for i in range(len(primeira_parte)):\n sum_p += int(primeira_parte[i])\n sum_s += int(segunda_parte[i])\n if(sum_p != sum_s):\n print(\"NO\")\n else:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t \t\t \t \t\t\t \t\t \t \t", "# Lucky Ticket\ndef lucky(n):\n mid = len(n) // 2\n s1 = 0\n s2 = 0\n for i in range(len(n)):\n if i < mid:\n s1 += int(n[i])\n else:\n s2 += int(n[i])\n if n[i] != '4' and n[i] != '7':\n return \"NO\"\n if s1 != s2:\n return \"NO\"\n return \"YES\"\n\n\nn = int(input())\ns = input()\nprint(lucky(s))\n", "n = int(input())\r\nln = input()\r\n\r\ntmp_str = ln\r\nif len(tmp_str.replace('4', '').replace('7', '')) > 0:\r\n print('NO')\r\nelse:\r\n sum_1 = sum(map(int, list(ln[:n//2])))\r\n sum_2 = sum(map(int, list(ln[n//2:])))\r\n if sum_1 == sum_2:\r\n print('YES')\r\n else:\r\n print('NO')\r\n", "n=int(input())\r\nl=input()\r\nl=list(l)\r\nif(l.count('4')+l.count('7')!=n):\r\n print(\"NO\")\r\nelse:\r\n s1=0\r\n s2=0\r\n for i in range(n//2):\r\n s1+=int(l[i])\r\n for i in range(n//2,n):\r\n s2+=int(l[i])\r\n if(s1==s2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "n=int(input())\r\nticket=input()\r\nfirst_half_sum=sum(int (digit) for digit in ticket[:n//2])\r\nsecond_half_sum=sum(int(digit) for digit in ticket[n//2:])\r\nif first_half_sum== second_half_sum:\r\n lucky_digits={'4','7'}\r\n if all(digit in lucky_digits for digit in ticket):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nl = list(map(int,input()))\r\nf=0\r\nfor i in range(n):\r\n\tif l[i] not in [4,7]:f=1;break\r\nif f==0 and sum(l[:n//2])==sum(l[n//2:]):print(\"YES\")\r\nelse:print(\"NO\")", "i = int(input())\nw = input()\nss = set(w)\n\ndef check(ww):\n return sum(map(lambda x: int(x),ww[:len(ww)//2])) == sum(map(lambda x:int(x),ww[len(ww)//2:]))\n\n\ndef check2(ww):\n\n if len(ss) == 1:\n if'4' in ss or '7' in ss:\n return check(ww)\n return False\n elif len(ss) ==2 :\n if '4' in ss and '7' in ss:\n return check(ww)\n return False\n return False\n\nif check2(w):\n print(\"YES\")\nelse:\n print(\"NO\")\n\n\n", "n=int(input())\r\ntick=input()\r\nif tick.count('4')+tick.count('7')==n:\r\n a=sum(int(i) for i in tick[:n//2])\r\n b=sum(int(i) for i in tick[n//2:])\r\n if a==b:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')\r\n", "n=int(input())\r\ns=input()\r\ncount=0\r\nl=[]\r\nfor i in s:\r\n l.append(int(i))\r\n if i=='4' or i=='7':\r\n count+=1\r\nt=n//2\r\nk1=sum(l[0:t])\r\nk2=sum(l[t:])\r\nif count==n and k1==k2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\nm=input()\r\nx=m.count('4')+m.count('7')\r\nif x!=n:\r\n print('NO')\r\nelse:\r\n if m[:n//2].count('4')==m[n//2:].count('4'):\r\n print('YES')\r\n else:\r\n print('NO')", "n = int(input())\ns = input()\nres, sum_left, sum_right = True, 0, 0\nfor i in range(n // 2):\n left, right = int(s[i]), int(s[n - i - 1])\n if not all(d in {4, 7} for d in (left, right)):\n res = False\n break\n sum_left += left\n sum_right += right\nres &= sum_left == sum_right\nprint(\"YES\" if res else \"NO\")\n", "def solve():\r\n size = int(input())\r\n s = input()\r\n \r\n if s.count('4') + s.count('7') == size:\r\n if sum(map(int, list(s[:size // 2]))) == sum(map(int, list(s[size // 2:]))):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n else:\r\n print(\"NO\")\r\n \r\n \r\nif __name__ == \"__main__\":\r\n solve()\r\n ", "def is_lucky_number(number):\r\n return all(digit == '4' or digit == '7' for digit in number)\r\n\r\ndef is_lucky_ticket(ticket):\r\n n = len(ticket)\r\n first_half = ticket[:n//2]\r\n second_half = ticket[n//2:]\r\n \r\n sum_first_half = sum(int(digit) for digit in first_half)\r\n sum_second_half = sum(int(digit) for digit in second_half)\r\n \r\n return sum_first_half == sum_second_half\r\n\r\nn = int(input())\r\nticket = input()\r\n\r\nif is_lucky_number(ticket) and is_lucky_ticket(ticket):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\np=str(input())\ng=[]\ns=0\nfor i in p:\n g.append(int(i))\n if int(i)!=7 and int(i)!=4: s=1\nif sum(g[:n//2])==sum(g[n//2:]) and s==0:print(\"YES\")\nelse: print(\"NO\")\n \t \t \t\t \t\t\t \t\t\t\t\t\t\t\t\t\t\t", "n=int(input())\r\ns=list(input())[:n]\r\na=True\r\ntsu,su=0,0\r\nfor i in range(0,len(s)):\r\n if(s[i]!='4' and s[i]!='7'):\r\n a=False\r\n break\r\n \r\nfor i in range(0,len(s)//2):\r\n su+=int(s[i])\r\nfor i in range((len(s)//2),len(s)):\r\n tsu+=int(s[i])\r\n\r\nif(a==False):\r\n print(\"NO\")\r\nelif(tsu==su and a==True): \r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "\"\"\"\n\n\n██╗ ██████╗ ██╗ ██████╗ ██████╗ ██╗ █████╗\n██║██╔═══██╗██║ ╚════██╗██╔═████╗███║██╔══██╗\n██║██║ ██║██║ █████╔╝██║██╔██║╚██║╚██████║\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].\n Сейчас лучше, чем никогда.\n Хотя никогда зачастую лучше, чем прямо сейчас.\n Если реализацию сложно объяснить — идея плоха.\n Если реализацию легко объяснить — идея, возможно, хороша.\n Пространства имён — отличная штука! Будем делать их больше!\n\"\"\"\n\"\"\"\n░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░░░░░░░▓████████████████████████▒░░░░░░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░░░░▓█████▓▒░░░░░░░░░░░░░░░▒██████▒░░░░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░░████▒░░░░░░░░░░░░░░░░░░░░░░░░░▓███▒░░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░▒██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒██░░░░░░░░░░░░░░\n░░░░░░░░░░░░▒██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██░░░░░░░░░░░░░\n░░░░░░░░░░░░██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██░░░░░░░░░░░░\n░░░░░░░░░░░██▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒░░██░░░░░░░░░░░░\n░░░░░░░░░░░██░░██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██░░██░░░░░░░░░░░\n░░░░░░░░░░░██░░██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██░░██░░░░░░░░░░░\n░░░░░░░░░░░██░░██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██░░██░░░░░░░░░░░\n░░░░░░░░░░░██▒░██▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██▓░▒██░░░░░░░░░░░\n░░░░░░░░░░░░██░░██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██░░██░░░░░░░░░░░░\n░░░░░░░░░░░░██▒░██░░░░░▒▒▓███▒░░░░░░░▒███▓▒▒░░░░░██░▓██░░░░░░░░░░░░\n░░░░░░░░░░░░░██░██░░██████████▒░░░░░▓██████████░░██▒██░░░░░░░░░░░░░\n░░░░░░░░░░░░░░████░████████████░░░░░████████████░████░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░███░▒██████████░░░░░░░██████████▒░██▒░░░░░░░░░▒░░░░░\n░░░▒████░░░░░░░▓█▒░░█████████░░░░░░░░░█████████░░▒█▓░░░░░░▓████░░░░\n░░░██░▒██▒░░░░░██░░░░██████▓░░░░█░█░░░░███████░░░░██░░░░░███░░██░░░\n░░░██░░░██▓░░░░██░░░░░░▒▓▓░░░░▒██░██░░░░░▓▓▒░░░░░▒██░░░░███░░░██░░░\n░▓██▒░░░░████▓░░██░░░░░░░░░░░░███░███░░░░░░░░░░░░██░░█████░░░░▓██▒░\n██▓░░░░░░░░▒████████▓░░░░░░░░████░███▓░░░░░░░▒▓████████░░░░░░░░░███\n██▓▒▓███▓░░░░░░▓████████▓░░░░████░███▓░░░░▓████████▓░░░░░░████▓▓███\n░███████████▒░░░░░░███████░░░░██░░░██░░░░██████▓░░░░░░▓███████████░\n░░░░░░░░░░▓█████░░░░██▓▓░██░░░░░░░░░░░░░██░█▒██░░░▒█████▓░░░░░░░░░░\n░░░░░░░░░░░░░▒█████▒▒█▓█░███▓▓▒▒▒▓▒▒▓▓▓███▒███░▓█████░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░░░▒████▒▓█▒▒█░█▒█░█░█▓█▒█▓░█░█████▒░░░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░░░░░░██░░██▓█▓█▓█▒█▒█▓█▓████░▓█▓░░░░░░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░░░▓████▓░▓█▓█░█▒█░█░█▒█▒███▒░██████░░░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░▓█████░░██░░░▒█████▓█▓█████▒░░░██░▒█████▓░░░░░░░░░░░░░\n░░░░▒██████████▓░░░░░███░░░░░░░░░░░░░░░░░░░██▒░░░░░▓██████████▒░░░░\n░░░░██░░░▓▓▓░░░░░░▒██████▓░░░░░░░░░░░░░░░███████▒░░░░░░▓▓▒░░▒██░░░░\n░░░░▓██░░░░░░░░▓████▓░░░█████▒░░░░░░▒▓█████░░░▓████▓░░░░░░░▒██▓░░░░\n░░░░░░███░░░░████▒░░░░░░░░▓█████████████▒░░░░░░░░▒████░░░░███░░░░░░\n░░░░░░░██░░░██▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓██░░░██░░░░░░░\n░░░░░░░██▒▓██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒██▒▓██░░░░░░░\n░░░░░░░░████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████░░░░░░░░\n░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n\"\"\"\n\"\"\"\n\n░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░▌░░░\n░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░▌░░░\n░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░█▌░░░\n░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▀█████████████████████████████████████████████████\n░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▄████▄████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████\n░░░░░░░░░░░░░░░░░░░░░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█████████▀▀▀▀▀▀▀▀▀\n░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████░░░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░\n░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████░░░░░░░░░░░░░░░\n\"\"\"\n\"\"\"\n\n\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@#@@#@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##@M@M # #@@@M@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@#@@ @@@@@@M@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@### #@@B@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@B@@#@@@@@#M@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@##@@M@#@@##@##@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#M@@@@@##@M@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##@@@@@@#@##@#@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@# @\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@ #\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@@#@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @# @\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @# @\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@@#@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@ #\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@# @\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@ @@#@@#@@@@@@@@@@@@@@@@@#@@#@#@@@@@@@@@@@@@@@@@@@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@\n @ #@@@@@@@@@@@@@@@@@@@@#@@@@@@#@@@@@@@@@@@@@@@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@ @@#@#@@@@@@@@@@@@@@@@@@#@####@@@@@@@@@@@@@@@@@M@#@@#@#@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@#@#M@@@M@@@@@@@@@@@@@@@@@@@M@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n#@M@#@#@@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@M@@M@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@#@@#@@@@@@@@@@@@@@@@@@@@M@M@#@@@@@@@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@\n@@#@@#@@@@@@@@@@@@@@@@@@@@@@@M@ @M@@#@@@@@@@@@@@@@@@@@@@@@@@@@\n@#@@@@@#@@@@@@@@@@@@@@@@@@@#@@ @@@@M@@@@@@@@@@@@@@@@@@@@@@@@\n@@@#@@@##@@@#@@@@@#@@@@@##@@@@ #@#@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@####@@####@@@@#@@@@M@@@#@@# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@#@ @#@@#@@@ #@ @ #@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n @# @@#@@ #@@#@@@@@@@@@@@@@@@@@@@@@@@@@\n ##@#@@ #M @# @@ @@M @@@@@@@@@@@@@@@@@@@@@@@@\n @#@@@M #@ #@ # @@ @@@@@@@@@@@@@@@@@@@@@@@@\n @@ @@#@@ ## @##@@ @@@@@@@@@@@@@@@@@@@@@@@@\n @# @@M@ @@ @@@@@@@@@@@@@@@@@@@@@@@@\n @@@##@@@ @@@@ @@@ @@ #@#@@#@@@@@@@@@@@@@@@@@\n@@@@###@@###@@@@#@#@@@@#@@@ M@ #@ @ B @@@#@@@@@@@@@@@@@@@@@@@\n@M@@@@@MM@@@@@M@@#@##@@@#@@M@B @# M@ @# #@ #@@#@@@@@@@@@@@@@@@@@@@\n@#@#@@M@@M@@#@#@#@#@@#@#@#@@@@ @# @@ # @M @#@@@@@@@@@@@@@@@@@@@@@\n@@@ @@@@#@##@ #@# @M # @ @ @@@@@#@@@@@@@@@@@@@@@@@\n @@ @@ @#@@#@@#M #@@@@#@@@@@@@@@@@@@@@@@\n M@# #@ @@@@##@@ @M@#M@@@#@@@@@@@@@@@@@@@@\n @@@@ @@ @@@#@@@#@#@@@@@@@@@@@@@@@@\n @# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n @@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n @M@H@@ @# @#@@@@#@@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@#@#@##@M@@@M@ @M#@@@@@#@@#@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n#M@@@##@@@@@@@@M@@@@#@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@#@@@@@M@#@M@@B#M@@M@###@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n###@@@@@@@@@# @#@@@@@@@#@@@#@##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@#@@M@@@#@@#@#@@@@@@#@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@M@#@# \n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@@@#\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@#@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@##\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@M\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@###@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@#@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n\n\"\"\"\n\"\"\"\n / \\ //\\\n |\\___/| / \\// \\\\\n /0 0 \\__ / // | \\ \\ \n / / \\/_/ // | \\ \\ \n @_^_@'/ \\/_ // | \\ \\ \n //_^_/ \\/_ // | \\ \\\n ( //) | \\/// | \\ \\\n ( / /) _|_ / ) // | \\ _\\\n ( // /) '/,_ _ _/ ( ; -. | _ _\\.-~ .-~~~^-.\n (( / / )) ,-{ _ `-.|.-~-. .~ `.\n (( // / )) '/\\ / ~-. _ .-~ .-~^-. \\\n (( /// )) `. { } / \\ \\\n (( / )) .----~-.\\ \\-' .~ \\ `. \\^-.\n ///.----..> \\ _ -~ `. ^-` ^-_\n ///-._ _ _ _ _ _ _}^ - - - - ~ ~-- ,.-~\n /.-~\n\n\"\"\"\n\"\"\"\n ____ _ _____ \n / ___|___ __| | ___| ___|__ _ __ ___ ___ ___ \n| | / _ \\ / _` |/ _ \\ |_ / _ \\| '__/ __/ _ \\/ __|\n| |__| (_) | (_| | __/ _| (_) | | | (_| __/\\__ \\\n \\____\\___/ \\__,_|\\___|_| \\___/|_| \\___\\___||___/\n\"\"\"\n\"\"\"\n░░██▄░░░░░░░░░░░▄██\n░▄▀░█▄░░░░░░░░▄█░░█░\n░█░▄░█▄░░░░░░▄█░▄░█░\n░█░██████████████▄█░\n░█████▀▀████▀▀█████░\n▄█▀█▀░░░████░░░▀▀███\n██░░▀████▀▀████▀░░██\n██░░░░█▀░░░░▀█░░░░██\n███▄░░░░░░░░░░░░▄███\n░▀███▄░░████░░▄███▀░\n░░░▀██▄░▀██▀░▄██▀░░░\n░░░░░░▀██████▀░░░░░░\n░░░░░░░░░░░░░░░░░░░░\n\"\"\"\n\"\"\"\nn = int(input())\nos=0\nch=[]\nfor i in range(n):\n\tm = int(input())\n\tch.append(m)\t\n\tif ch[0]==10:\t\t\n\t\tif 1 in ch:\n\t\t\tprint((len( ch[:ch.index(1)])))\n\t\t\tbreak\n\telse:\n\t\tif 10 in ch:\n\t\t\tprint((len( ch[:ch.index(10)])))\n\t\t\tbreak\n\"\"\"\n\"\"\"\nn,m = map(int,input().split())\nm = float(m)\nmi = []\nfor i in range(n):\n\ta,b = map(float,input().split())\n\tmi.append((a*m)/b)\nprint(round(min(mi),6))\n\"\"\"\n\"\"\"\nl = input().split()\nl = set(l)\nprint(len(l))\n\n\"\"\"\n\"\"\"\t\nx = input()\ny = x[1:-1]\nz = set(y.split(', '))\nif x == \"{}\":\n\tprint(0)\nelse:\n\tprint(len(z))\n\"\"\"\n\"\"\"\nn,k = map(int,input().split())\nL = sorted(map(int, input().split()))\nres = [L[0]]\nfor i in range(1,n):\n if L[i] != L[i-1]:\n res.append(L[i]-L[i-1])\nl = len(res)\nif k > l:\n res += [0]*(k-l)\nfor i in range(k):\n print(res[i])\n\n\"\"\"\t\n\"\"\"\nfrom math import*\ns,k = map(int,input().split(\" \"))\nsq = input().split()\nscore = 0\npol = \"\"\nfor i in range(len(sq)):\n\tif sq[i]>=sq[i-1]:\n\t\tscore+=1\nprint(ceil(score/len(sq))+ceil(score/len(sq)))\n\"\"\"\n\"\"\"\nfrom math import*\ns,k = map(int,input().split(\" \"))\nsq = input().split()\nscore = 0\npol = \"\"\nfor i in range(len(sq)):\n\tif sq[i]>=sq[i-1]:\n\t\tscore+=1\nprint(ceil(score/len(sq))+ceil(score/len(sq)))\n\"\"\"\n\"\"\"\nst=list(input().split('+'))\nst.sort()\nfor i in range(len(st)):\n if i!=len(st)-1:\n print(str(st[i])+'+',end='')\n else:\n print(str(st[i]))\n\"\"\"\n\"\"\"\na = input()\nup = a.upper()\nabc = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\nprint(abc[abc.find(up[0])]+a[1::])\n\"\"\"\n\"\"\"\n\nn= int(input())\nk = 0\nfor i in range(n):\n\tp = input()\n\tif p == \"++X\" or p == \"X++\":\n\t\tk+=1\n\telif p == \"--X\" or p == \"X--\":\n\t\tk-=1\nprint(k)\n\n\"\"\"\n\"\"\"\nimport math \n\nc = 1 \n\nl = int(input()) \n\ng = \"\" \n\nfor i in range(l): \n\n for s in range(1,l - i + 1): \n\n g = g + \" \" \n for j in range(0,i + 1): \n if(i == 0 or j == 0): \n c = 1 \n else: \n c = c * (i - j + 1)/j \n\n t = c \n T=0 \n while(t != 0): \n T = T + 1 \n t = int(math.floor(t/10)) \n p=0 \n while((p+T)!=4): \n g = g + \" \" \n p=p+1 \n g = g + str(int(math.floor(c))) \n g = g + \"\\n\" \nprint(g)\n\"\"\"\t\n\"\"\"\n ___ __ _ _ \n|_ _|_ __ / _| ___ _ __ _ __ ___ __ _| |_(_) ___ ___ \n | || '_ \\| |_ / _ \\| '__| '_ ` _ \\ / _` | __| |/ __/ __|\n | || | | | _| (_) | | | | | | | | (_| | |_| | (__\\__ \\\n|___|_| |_|_| \\___/|_| |_| |_| |_|\\__,_|\\__|_|\\___|___/ \n\"\"\"\n\"\"\" \nfrom math import*\na1 = float(input())\na2 = float(input())\nb = sqrt(a1**2 + a2**2)\nprint(b)\n\"\"\" \n\"\"\"\na1 = float(input())\na2 = float(input())\nb = (a1**2 + a2**2)\nimport math\nl = math.sqrt(b)\nprint(l)\n\"\"\"\n\"\"\"\nn = int(input())\na=list(map(int,input().split(\" \")))\nb = []\nfor i in range(len(a)):\n if i%2==0:\n print(a[i],end=' ')\n\"\"\"\n\"\"\"\nn = int(input())\na=list(map(int,input().split(\" \")))\nb = []\nfor i in range(len(a)):\n if a[i]%2==0:\n print(a[i],end=' ')\n\"\"\"\n\"\"\"\nn = int(input())\na=list(map(int,input().split(\" \")))\nb = []\nfor i in range(len(a)):\n if a[i]>0:\n b.append(a[i])\nprint(len(b))\n\"\"\"\n\"\"\"\nn = int(input())\na=list(map(int,input().split(\" \")))\nb = 0\nfor i in range(1,n):\n if a[i]>a[i-1]:\n b+=1\nprint(b)\n\"\"\"\n\"\"\"\nn = int(input())\na=list(map(int,input().split(\" \")))\nb = 0\nfor i in range(1,n):\n if a[i]>a[i-1]:\n b+=1\nprint(b)\n\"\"\"\n\"\"\"\nn = int(input())\na=list(map(int,input().split(\" \")))\nb = 0\nfor i in range(n-1):\n if i == 0:\n pass\n elif a[i]>a[i-1]and a[i+1]< a[i]:\n b+=1\nprint(b)\n\"\"\"\n\"\"\"\nn = int(input())\na=list(map(int,input().split(\" \")))\na.reverse()\nfor i in a:\n print(i,end = \" \")\n\"\"\"\n\"\"\"\nn = int(input())\na=list(map(int,input().split(\" \")))\nprint(max(a))\n\"\"\"\n\"\"\"\nn = int(input())\na = list(map(int,input().split(\" \")))\nl = 0\nq = []\nfor i in range(len(a)):\n if a[i] in q:\n pass\n else:\n l +=1\n q.append(a[i])\nprint(l)\n\"\"\"\n\"\"\"\nn = int(input())\na = list(map(int,input().split()))\nx = int(input())\nk =1\nfor i in range(len(a)):\n k+=1\n if x > a[i]:\n print(i+1)\n exit()\nprint(k)\n\"\"\"\n\"\"\"\na=list(map(int,input().split(\" \")))\nb = []\nfor i in range(len(a)):\n if i%2==0:\n print(a[i],end=' ')\n\"\"\"\n\"\"\"\na=list(map(int,input().split(\" \")))\nb = 0\nfor i in range(len(a)-1):\n if i == 0:\n pass\n elif a[i]>a[i-1]and a[i+1]< a[i]:\n b+=1\nprint(b)\n\"\"\"\n\"\"\"\na = list(map(int,input().split()))\nprint(max(a),a.index(max(a)))\n\"\"\"\n\"\"\"\nch = list(input()) \nif ch.count(\"h\")>=1 and ch.count(\"e\")>=1 and ch.count(\"l\")>=2 and ch.count(\"o\")>=1 and len(ch)!=53:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\"\"\"\n\"\"\"\nfrom decimal import Decimal\nx,y = map(Decimal,input().split(\" \"))\nd = 1\nwhile x < y and x - y < 0.000001 :\n x += x * 70 / 100\n d += 1\nprint(d)\n\"\"\"\n\"\"\"\nn = int(input())\nabc = \"abcdefghijklmnopqrstuvwxyz\"\ns =\"\"\nfor i in range(n):\n\tk,v = map(int,input().split())\n\tfor i in range(k):\n\t\twhile len(s) <= k:\n\t\t\ts += abc[:v]\n\t\tif len(s)>k:\n\t\t\ts = s[:-(len(s)-k)]\n\tprint(s,end=\"\\n\")\n\ts=\"\"\t\t\n\"\"\"\n\"\"\"\nk = int(input())\nl = int(input())\nm = int(input())\nn = int(input())\nd = int(input())\nlst = []\nlst.append(k)\nlst.append(l)\nlst.append(m)\nlst.append(n)\nuron = 0\nfor i in range(len(lst)):\n\tif d % lst[i] == 0:\n\t\turon+=lst[i]\nprint(uron)\n\"\"\"\n\"\"\"\nn = int(input())\na = list(map(int,input().split()))\nch = 0\nnch = 0\nfor i in range(len(a)):\n\tif a[i] % 2 == 0:\n\t\tch+=1\n\telse:\n\t\tnch+=1\nif ch > nch:\n\tfor i in range(len(a)):\n\t\tif a[i] % 2 == 1:\n\t\t\tprint(a.index(a[i])+1)\nelse:\n\tfor i in range(len(a)):\n\t\tif a[i]%2==0:\n\t\t\tprint(a.index(a[i])+1)\n\"\"\"\n\"\"\"\nn,t = map(int,input().split())\noc = input()\nfor i in range (1,n):\n\tif oc[i]==\"B\":\n\t\toc[i]=oc[i-1]\nprint(oc)\t\t\t\n\"\"\"\n\"\"\"\nn = int(input())\no = 0\nfor i in range(n):\n\to += ((n-2) - (n % 2))//2\nprint(o)\n\"\"\"\n\"\"\"\nsl = input()\nabc = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\nm=0\nb=0\nbig = \"\"\nfor i in range(len(sl)):\n\tif sl[i]== abc[abc.find(sl[i])]:\n\t\t\tb+=1\n\telse:\n\t\t\tm +=1\nif m>b:\n\tbig += sl.lower()\n\tprint(big)\nelif b>m:\n\tbig += sl.upper()\n\tprint(big)\nelif b==m:\n\tbig += sl.lower()\n\tprint(big)\n\"\"\"\n\"\"\"\nn = int(input())\na = list(map(int,input().split()))\nfor i in range(n):\n\tprint(a.index(i+1)+1, end=' ')\n\"\"\"\n\"\"\"\nn = int(input())\nif n % 2 == 0 and n != 2 :\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\"\"\"\n\"\"\"\na = input().replace(\"WUB\",\" \")\nprint(a)\n\"\"\"\n\"\"\"\na = int(input())\nb = list(map(int,input().split()))\nb.sort()\nfor i in b:\n\tprint(i,end=\" \")\n\"\"\"\n\"\"\"\na,b = map(int,input().split())\no = 0\nif a % 2 == 0:\n\to = a//2\nelse:\n\to = (a//2)+1\nif b <= o:\n\tprint((1+((o-1)*2)))\nelse:\n\tprint(((o-1)*2))\n\"\"\"\n\"\"\"\na,b = map(int,input().split())\nyear = 0\nwhile b>=a:\n\ta*=3\n\tb*=2\n\tyear+=1\nprint(year)\n\"\"\"\n\"\"\"\nn,m = map(int,input().split())\nm = float(m)\nmi = []\nfor i in range(n):\n\ta,b = map(float,input().split())\n\tmi.append((a*m)/b)\nprint(min(mi))\n\"\"\"\n\"\"\"\nn = int(input())\nx = 0\nfor i in range(n):\n\ta = input()\n\tif a == \"Tetrahedron\":\n\t\tx+=4\n\telif a == \"Cube\":\n\t\tx+=6\n\telif a == \"Octahedron\":\n\t\tx+=8\n\telif a == \"Dodecahedron\":\n\t\tx+=12\n\telif a == \"Icosahedron\":\n\t\tx+=20\nprint(x)\n\"\"\"\n\"\"\"\nn= int(input())\na = list(map(int,input().split()))\nfor i in a:\n\tif sum(a)>0:\n\t\tprint(\"HARD\")\n\t\tbreak\n\telse:\n\t\tprint(\"EASY\")\n\t\tbreak\n\"\"\"\n\"\"\"\na,b = map(int,input().split())\nc = list(map(int,input().split()))\nbal = 0\nfor i in range(1,len(c)+1):\n\tif b == len(c):\n\t\tif c[i]>=c[b-1]:\n\t\t\tbal +=1\n\telse:\n\t\t\n\t\tif c[i]>=c[b] and c[i]!= 0:\n\t\t\tbal+=1\nprint(bal)\n\"\"\"\n\"\"\"\na,b =map(int, input().split())\ny=list(map(int,input().split()))\nfor i in y:\n if i<y[b-1] or i==0:\n a-=1 \nprint(a)\n\"\"\"\n\"\"\"\na,b=map(int,input().split())\nc=b-(a+1)//2\nif c > 0:\n\tprint(2*c)\nelse:\n\tprint(2*b-1)\n\"\"\"\n\"\"\"\na = input()\nb = input()\na1 = a.lower()\nb1 = b.lower()\no = 0\nk = 0\nif a1>b1:\n\to+=1\nif b1>a1:\n\tk+=1\nprint(o-k)\n\"\"\"\n\"\"\"\nn=int(input())\np=input().split()\nq=input().split()\nm = p[1:]\nj = q[1:]\nif len(set(m+j))==n:\n print(\"I become the guy.\")\nelse:\n print(\"Oh, my keyboard!\")\n\"\"\"\n\"\"\"\na = set(input())\nfor i in range(len(a)):\n\ta.remove()\n\tif a == \"hello\":\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\")\n\"\"\"\n\"\"\"\nn = list(map(int,input()))\na = n.count(4)+n.count(7)\nif a == 7 or a == 4:\n\t\tprint(\"YES\")\n\t\t\nelse:\n\t\tprint(\"NO\")\n\"\"\"\n\"\"\"\t\nn = int(input())\nb = input()\nb = b.upper\nabc = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\nfor i in range(len(b)):\n\tif abc[i] in b:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\")\n\"\"\"\n\"\"\"\nfrom math import*\nn,a,b = list(map(int,input().split()))\npos = 0\nfor i in range(n):\n\tif (a + b) % 2 == 0:\n\t\tprint(a+b)\n\t\tbreak\n\telse:\n\t\tprint(ceil((a+b)/2))\n\t\tbreak\n\"\"\"\n\"\"\"\nn = int(input())\nans = 0\nfor i in range(n):\n\ta,b,c = map(str,input().split())\n\tb = int(b)\n\tfor i in range(n):\n\t\tif b == -b and c == \"YES\":\n\t\t\tprint(\"Impossible\")\n\t\telif ans > b and c == \"Y\":\n\t\t\tans += 1\n\t\telif ans < b and c == \"Y\":\n\t\t\tans+=1\n\t\telif ans >= b and c == \"Y\":\n\t\t\tans+=1\n\t\telif ans <= b and c == \"Y\":\n\t\t\tans+=1\n\t\telif ans > b and c == \"N\":\n\t\t\tbreak\n\t\telif ans < b and c == \"N\":\n\t\t break\n\t\telif ans >= b and c == \"N\":\n\t\t\tbreak\n\t\telif ans <= b and c == \"N\":\n\t\t\tbreak\nprint(ans)\t\t\n\"\"\"\n\"\"\"\nfrom math import*\nn,k = map(int,input().split())\na = list(map(int,input().split()))\ncom = 0\nfor i in range(len(a)):\n\tif a[i]+2 <= 5:\n\t\tcom += 0.333\nprint(ceil(com))\n\"\"\"\n\"\"\"\nn,a,b = map(int,input().split())\nd = []\ns = 0\nk = 1\nfor i in range(n-1):\n\tif a == 0 and b == 0:\n\t\tprint(n)\n\t\texit()\n\td.append(\"*\"*((a+i)) +\"+\"+\"*\"*(((b-i)-k)))\n\tif len(d[i])<=n:\n\t\ts+=1\nprint(s)\n\"\"\"\n\"\"\"\nn,h =map(int, input().split())\nfor i in map(int, input().split()):\n if i > h:\n n+=1\nprint(n)\t\n\"\"\"\n\"\"\"\nn = input()\na = input()\nif a.count('A')> a.count('D'):\n\tprint('Anton')\nelif a.count('A')<a.count('D'):\n\tprint('Danik')\nelse:\n\tprint('Friendship')\n\"\"\"\n\"\"\"\nn = int(input())\na=[]\nfor i in range(n):\n a.append(list(map(int,input().split())))\ng = list(map(sum,a))\ncount=0\ni=0\nfor j in g:\n if j >=2:\n count+=1\nprint(count)\n\"\"\"\n\"\"\"\nn=int(input())\nx=input()\nc=0\nfor i in range(n-1):\n if x[i] == x[i+1]:\n c+=1\nprint(c)\n\"\"\"\n\"\"\"\nk = list(map(int,input().split()))\nt = input()\nkal = 0\nfor i in range(len(t)):\n\tif t[i]==\"1\":kal += k[0]\n\telif t[i]==\"2\":kal += k[1]\n\telif t[i]==\"3\":kal += k[2]\n\telif t[i] == \"4\":kal += k[3]\nprint(kal)\n\"\"\"\n\"\"\"\norient = input()\nkey = input()\nkeyboard = \"poiuytrewq;lkjhgfdsa/.,mnbvcxz\"\nans = \"\"\nfor i in range(len(key)):\n\tif orient == \"R\":\n\t\tans += keyboard[keyboard.find(key[i])+1]\n\telif orient == \"L\":\n\t\tans += keyboard[keyboard.find(key[i])-1]\nprint(ans)\n\"\"\"\n\"\"\"\nn,k = map(int, input().split())\nabc = \"abcdefghijklmnopqrstuvwxyz\"\nf = abc[:k]\ns = f \nwhile len(s) < n:\n s += f\ns = s[:n]\nprint(s)\n\"\"\"\n\"\"\"\nn = int(input())\nif n %2 == 0 or n == 2:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\"\"\"\n\"\"\"\nmas = 0\nwhile 1:\n\ttry:\n\t\ta = input()\n\t\tif \":\" in a:\n\t\tmas += len(a[a.find(\":\"):])\n\texcept EOFError:\nprint(mas)\n\"\"\"\n\"\"\"\na = input()\nb = input()\nc = str(int(a)+int(b))\nif int(a.replace(\"0\",\"\"))+int(b.replace(\"0\",\"\"))== int(c.replace(\"0\",\"\")):\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\"\"\"\n\"\"\"\ns = input()\nw = len(s)\nn=int(input())\nb=[]\nfor i in range(n):\n wd=input()\n if wd[:w]==s:\n b.append(wd)\nb.sort()\nif len(b)==0:\n print(s)\nelse:\n print(min(b))\n\"\"\"\n\"\"\"\nn = int(input())\nans = 0\nfor i in range(n):\n\tx,a = map(int,input().split())\n\tif x == -x and a:\n\t\tans += a \n\telse:\n\t\tans+=a\nprint(ans)\n\"\"\"\n\"\"\"\nfrom decimal import Decimal\nn,m = map(int,input().split())\nfst = []\nscd = []\na=0\nfor i in range(1,n+1):\n\tfor j in range(1,m+1):\n\t\tif (i+j)%5==0:\n\t\t\ta+=1\nprint(a)\n\"\"\"\n\"\"\"\nn,a = map(int,input().split())\nans = \"\"\nfor i in range(n):\n\tb = list(map(str,input().split()))\n\tfor j in range(a):\n\t\tif b[j] != \"B\" or b[j]!=\"W\"or b[j]!=\"G\":\n\t\t\tans += \"#Color\"\n\t\t\tbreak\n\t\t\t\n\t\telse:\n\t\t\tans += \"#Black&White\"\n\t\t\tbreak\nprint(ans)\n\"\"\"\n\"\"\"\nn=int(input())\nnum=0\na , b =[],[]\nfor i in range(n):\n c=input().split()\n a.append(c[0])\n b.append(c[1])\nfor i in a:\n num+=b.count(i)\nprint(num)\n\"\"\"\n\"\"\"\nn = int(input())\nb = input()\na = b.lower()\n\nif a.count(\"a\")>=1 and a.count(\"b\")>=1 and a.count(\"c\")>=1 and a.count(\"d\")>=1 and a.count(\"e\")>=1 and a.count(\"f\")>=1 and a.count(\"g\")>=1 and a.count(\"h\")>=1 and a.count(\"i\")>=1 and a.count(\"j\")>=1 and a.count(\"k\")>=1 and a.count(\"l\")>=1 and a.count(\"m\")>=1 and a.count(\"n\")>=1 and a.count(\"o\")>=1 and a.count(\"p\")>=1 and a.count(\"q\")>=1 and a.count(\"r\")>=1 and a.count(\"s\")>=1 and a.count(\"t\")>=1 and a.count(\"u\")>=1 and a.count(\"v\")>=1 and a.count(\"w\")>=1 and a.count(\"x\")>=1 and a.count(\"y\")>=1 and a.count(\"z\")>=1:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\"\"\"\n\"\"\"\nfrom math import*\nn = int(input())\ndig = []\nfor i in range(1,n+1):\n\tif factorial(i-1) % i != i-1:\n\t\tdig.append(i)\nfor j in range(1,len(dig)+1):\t\n\tif dig[j] + dig[j-n%2-4] == n or dig[j] + dig[j-n%2-9] == n:\n\t\tprint(dig[j],dig[j-n%2-4])\n\"\"\"\n\"\"\"\na=input()\nb=input()\ns=input()\nc=a+b\nd=list(s)\ne=list(c)\nd.sort()\ne.sort()\nif d==e:\n print('YES')\nelse:\n print('NO')\n\"\"\"\n\"\"\"\n def nextmiron(s):\n s += '#'\n cnt = 1\n ret = \"\"\n for i in range(1, len(s)):\n if s[i] == s[i - 1]:\n cnt += 1\n else:\n ret += str(cnt) + s[i - 1];\n cnt = 1\n return ret\n\"\"\"\n\"\"\"\nn = list(map(int,input()))\nfor i in range(len(n)):\n\tif n[i] > 0:\n\t\tprint(n[i],end=\"\")\n\t\texit()\n\telif n[i]>n[i-1]:\n\t\tn.remove(n[i])\nfor i in n:\n\tprint(n[i],end=\"\")\n\"\"\"\n\"\"\"\nn = list(map(int,input()))\na = 0\nans = 0\nfor i in range(len(n)):\n\t\ta += n[i]+n[i-1]\n\t\tans += 1\n\t\tif a in n:\n\t\t\tbreak\nprint(ans+1)\n\"\"\"\n\"\"\"\nfrom math import factorial as fal\na,b = map(int,input().split())\nans = 0\np = []\nprime = []\nfor i in range(a,b+1):\n\tif fal(i-1) % i == i-1:\n\t\tp.append(i)\nfor i in range(len(p)):\n\tif fal((int(str(p[i])[::-1]))-1)% int(str(p[i])[::-1]) == int(str(p[i])[::-1])-1: \n\t\tans += 1\nprint(ans)\n\"\"\"\n\"\"\"\na,b,c = map(int,input().split())\nd = str(a/b)\nif len(d)==3:\n\tprint(d+\"0\"*(c-1))\nelse:\n\tprint(round((a/b),c))\n\"\"\"\n\"\"\"\na = list(input())\nn = 0\nh = 'hello'\nfor i in range(len(a)):\n if a[i] == h[n]:\n n += 1\n if n >= 5:\n break\nif n >= 5: \n\tprint('YES')\nelse: \n\tprint('NO')\n\"\"\"\n\"\"\"\nfrom math import factorial as fal\na,b = map(int,input().split())\nans = 0\nfor i in range(a,b+1): \n\tif fal(i-1) % i == i-1 and fal((int(str(i)[::-1]))-1) % int(str(i)[::-1]) == int(str(i)[::-1])-1:\n ans += 1 \nif a == 1:\n\tprint(ans - 1)\n\texit()\nprint(ans)\n\"\"\"\n\"\"\"\nl=list(map(int,input().split(' ')))\nn,v=l[0],l[1:]\ndp=[1]*(n+1)\ninf=2**64\nfor i in range(n+1):\n\tif i not in v:\tdp[i]=-inf\nfor i in range(n+1):\n\tfor j in v:\n\t\tif i>j:\n\t\t\tdp[i]=max(dp[i],dp[j]+dp[i-j])\nprint(dp[n])\n\"\"\"\n\"\"\"\np = list(map(int,input().split()))\nq = set(p)\ns = 0\nfor i in q:\n s += p.count(i)-1\nprint(s)\n\"\"\"\n\"\"\"\na,b = map(int,input().split())\nh = []\nl = []\nfor i in range(b):\n c = list(map(int,input().split()))\n h.append(c)\nh.sort()\nfor i in h:\n if a > i[0]:\n l.append(1)\n a += i[1]\n \nif len(l) == b:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\"\"\"\n\"\"\"\nn,m=map(int,input().split())\nans=0\nfor i in range(1,n+1):\n\tans += int((i+m)/5)-int(i/5)\nprint(ans)\n\"\"\"\n\"\"\"\na = input()\nif a[0]==\"-\":\n\tprint((a[0])+a[1],a[2])\nelse:\t\n\tprint(int(a[0]),int(a[1]))\n\"\"\"\n\"\"\"\nfrom math import factorial as myfunct\na,b = map(int,input().split())\nc = min(a,b)\nprint(myfunct(c))\n\"\"\"\n\"\"\"\na,b,c = map(int,input().split())\nd = []\nd.append(a)\nd.append(b)\nd.append(c)\nd.sort()\nprint(d[2]-d[0])\n\"\"\"\n\"\"\"\nn=int(input())\na=list(map(int,input().split()))\nb = a[:]\nb.reverse()\nu = a.index(max(a))\nl = n-1-b.index(min(a))\nif u > l:\n print(u+(n-1-l)-1)\nelse:\n print(u+(n-1-l))\n\"\"\"\n\"\"\"\ns=input().lower()\nfor i in \"aeiouy\":\n s = s.replace(i,\"\")\nprint(\".\"+\".\".join(s))\n\"\"\"\n\"\"\"\nn = int(input())\nmaxi = 0\nmini = 0\nfor i in range(n):\n\ta,b = map(int,input().split())\n\tmaxi += a+b\n\tmini += a//i\nprint(mini,maxi)\n\"\"\"\n\"\"\"\nn = int(input())\nlast_zero = []\nfor i in range(n):\n\ta = input()\n\tif a[-1]==\"0\":\n\t\tlast_zero.append(a)\nfor i in range(len(last_zero)):\n\tif last_zero[i].count(\"0\")>last_zero[i-1].count(\"0\"):\n\t\tprint(last_zero[i])\n\t\tbreak\n\"\"\"\n\"\"\"\nn = int(input())\nfor i in range(n):\n\ta,b = map(int,input().split())\n\td = len(str(a+b))\n\tif int(str(a)[-i])+int(str(b)[-i]) >= 10 and int(str(a)[-i])+int(str(b)[-i]) >= 10:\n\t\tprint(a+b-(10**(d-1)))\n\"\"\"\n\"\"\"\nfcoin,coins = map(int,input().split())\nl = fcoin\npirates = 0\nwhile l <= coins:\n\tl += fcoin +1\n\tpirates+=1\nprint(pirates)\n\"\"\" \n\"\"\"\na,b = map(str,input().split(\"+\"))\nroman = [\"I\",\"II\",\"III\",\"IV\",\"V\",\"VI\",\"VII\",\"VIII\",\"IX\",\"X\",\"XI\",\"XII\",\"XIII\",\"XIV\",\"XV\",\"XVI\",\"XVII\",\"XVIII\",\"XIX\",\"XX\"]\nf = roman.index(a)+1\ns = roman.index(b)+1\nd = f+s\nprint(roman[d-1])\n\"\"\"\n\"\"\"\nx = int(input())\nj = 0\nr =[]\nl = []\nfor i in range(x):\n y = [int(i) for i in list(input().split())]\n if y[0]<0:\n l.append(y)\n else:\n r.append(y)\nr = sorted(r)\nl = sorted(l, reverse = True)\n\nj = 0\n\nd =1 if len(r)>=len(l) else -1\nwhile((d == 1 and len(r)>0) or (d==-1 and len(l)>0)):\n if d ==1:\n j += r[0][1]\n r = r[1:]\n d = -1\n else:\n j += l[0][1]\n l = l[1:]\n d = 1\nprint(j)\n\"\"\"\n\"\"\"\na=int(input())\nb=int(input())\nc=int(input())\nd=int(input())\nn=int(input())\nans=0\nfor i in range(1,n+1):\n\tif i%a==0 or i%b==0 or i%c==0 or i%d==0:\n\t\tans+=1\nprint(ans)\n\"\"\"\n\"\"\"\nn,m = map(int,input().split( ))\nfor i in range(n):\n if i%2==0:\n print('#'*m)\n elif i%4==1:\n print('.'*(m-1)+'#')\n else:\n print('#'+'.'*(m-1))\n\"\"\"\n\"\"\"\nn = int(input())\na = list(map(int, input().split()))\nprint(sum(a)/n)\n\"\"\"\n\"\"\"\na,b = map(int, input().split())\n\nr1 = min(a,b)\nr2 = (max(a,b) - min(a,b)) // 2\n\nprint(r1,r2)\n\"\"\"\n\"\"\"\na = input()\nb1,b2,b3,b4,b5 = map(str,input().split())\nif a[-1] == b1[-1] or a[-1] == b2[-1] or a[-1] == b3[-1] or a[-1] == b4[-1] or a[-1] == b5[-1] or a[0] == b1[0] or a[0] == b2[0] or a[0] == b3[0] or a[0] == b4[0] or a[0] == b5[0]:\t\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\"\"\"\n\"\"\"\nn = int(input())\nlo = []\nfor i in range(n):\n\ta = int(input())\n\tlo.append(a)\nif sum(lo)-lo[-1] == lo[-1] or sum(lo) == 360:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n\"\"\"\n\"\"\"\nfrom math import*\nn = int(input())\na = list(map(int,input().split()))\nfor i in range(len(a)):\n\tif factorial(a[i]-1) % a[i] == a[i]-1:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\")\n\"\"\"\n\"\"\"\na,b = map(int,input().split())\nans = a\nif a % b == 0:\n\tans += a//b\nif (a//b) % 2 == 0:\n\tans += ans % b\nprint(ans)\n\"\"\"\n\"\"\"\na,b = map(int,input().split())\nprint(a+b)\n\"\"\"\n\"\"\"\na = input()\nif set(a) == \"ABC\" or set(a) == \".ABC\" or set(a) == \"ABC.\":\n\tprint(1)\nelse:\n\tprint(2)\nprint(set(a))\n\"\"\"\n\"\"\"\nn = int(input())\na = list(map(int,input().split()))\nans = 0\nfor i in range(len(a)):\n\tif a[i] >= a[-1]:\n\t\tans += 1\nprint(ans)\n\"\"\"\n\"\"\"\nn,k = map(int,input().split())\nvar = []\nans = []\nfor i in range(1000000):\n\tif (i // k)*(i % k) == n:\n\t\tans.append(i)\nprint(min(ans))\n\"\"\"\n\"\"\"\na = input().replace(\".\",\"\")\nif a == \"ABC\" or a == \"ACB\" or a == \"BAC\" or a == \"BCA\" or a == \"CAB\" or a == \"CBA\":\n\tprint('Yes')\nelse:\n\tprint('No')\n\"\"\"\n\"\"\"\ns=''\nfor i in range(int(input())):\n s=s+input()\nprint(s.count('11')+s.count('00')+1)\n\"\"\"\n\"\"\"\na = int(input())\nb = [[0] * a for i in range(a)]\nc = []\nfor i in range(a):\n for j in range(a):\n if i == 0 :\n b[i][j] = 1\n else:\n b[i][j] = b[i - 1][j] + b[i][j -1]\nfor i in b:\n c.append(max(i))\nprint(max(c))\n\"\"\"\n\"\"\"\na,b = map(int,input().split())\nfor i in range(b):\n\tif a % 10 != 0:\n\t\ta -= 1\n\telif a % 10 == 0:\n\t\ta //= 10\nprint(a)\n\"\"\"\n\"\"\"\nn = int(input())\nans = []\nfor i in range(100):\n\tif int(str(i[0]))+ int(str(i[1]))== 10:\n\t\tans.append(i)\nprint(ans[n])\t\n\"\"\"\n\"\"\"\nn=int(input())\na=input()\nc=0\nfor i in range(n-2):\n if a[i]+a[i+1]+a[i+2]==\"xxx\":\n c+=1\nprint(c)\n\"\"\"\n\"\"\"\na = input()\nb = input()\nop = a.find(\"1\")\nop1 = b.find(\"1\")\nop2 = min(op,op1)\nif a[0] == \"0\" and b[0] == \"0\":\n\tprint(\"0\"*len(a[:op2])+str((int(a)+int(b))).replace(\"2\",\"0\"))\nelse:\n\tprint(str((int(a)+int(b))).replace(\"2\",\"0\"))\n\"\"\"\n\"\"\"\nn = int(input())\nif n % 2 != 0:\n print(n//2)\n print('2 '*(n//2-1)+'3')\nelse:\n print(n//2)\n print('2 '*(n//2))\n\"\"\"\n\"\"\"\nn = int(input().strip())\nkras = input().strip()+'W'\nk = []\nl = 0\nfor i in range(n+1):\n if kras[i] == 'B':\n l += 1\n elif l != 0:\n k.append(str(l))\n l = 0\nprint(len(k))\nprint(' '.join(k))\n\"\"\"\n\"\"\"\nn = int(input())\na = list(map(int, input().split()))\nfor i in range(n):\n\tif a[i] % 2 == 0:\n\t\ta[i] = a[i] - 1\nfor i in a:\n\tprint(i, end = \" \")\n\"\"\"\n\"\"\"\nn,k = map(int, input().split())\ns=1\nd = n\nwhile (n%10!=k and n%10!=0):\n n+=d\n s+=1\nprint(s)\n\"\"\"\nn = int(input())\na = input()\nb = []\ncan = 1\nfor i in range(n):\n\tb.append(int(a[i]))\n\tif a[i] != '4' and a[i] != '7':\n\t\tcan = 0\nsuma = 0\nfor i in range(n):\n\tif i < n / 2:\n\t\tsuma += b[i]\n\telse:\n\t\tsuma -= b[i]\n\nif suma != 0 or can == 0:\n\tprint(\"NO\")\nelse:\n\tprint(\"YES\")\n", "n=int(input())\r\ns=input()\r\nl=[\"4\",\"7\"]\r\nflag=x=y=0\r\nfor i in s:\r\n\tif i not in l:\r\n\t\tflag=1\r\nif flag==1:\r\n\tprint(\"NO\")\r\nelse:\r\n\tfor i in range(n//2):\r\n\t\tx+=int(s[i])\r\n\tfor j in range(n//2,n):\r\n\t\ty+=int(s[j])\r\n\tif x!=y:\r\n\t\tprint(\"NO\")\r\n\telif x==y:\r\n\t\tprint(\"YES\")", "a = int(input())\r\nb = list(map(int, input()))\r\nc = a // 2\r\nif b.count(4) + b.count(7) == a and sum(b[:c]) == sum(b[c:]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "a=input()\r\nb=input()\r\n\r\nc=str(b)\r\n\r\n\r\nfor i in range(0,int(a)):\r\n if c[i] is not '7' and c[i] is not '4' :\r\n print(\"NO\")\r\n quit()\r\n\r\nsum1=0\r\nsum2=0\r\na=int(a)\r\na=a/2\r\na=int(a)\r\nfor i in range(0,a):\r\n e = ord(b[i])\r\n sum1+=(e-48)\r\n\r\nfor i in range(a,len(b)):\r\n e=ord(b[i])\r\n sum2+=(e-48)\r\n \r\nif sum1==sum2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def luckyNumber(n):\r\n for i in n:\r\n if i != \"4\" and i != \"7\":\r\n return False\r\n return True\r\n\r\ndef luckyTicket(n,length):\r\n if luckyNumber(n):\r\n left = 0\r\n right = 0\r\n i = 0\r\n j = length-1\r\n while i <= j:\r\n left += int(n[i])\r\n right += int(n[j])\r\n i += 1\r\n j -= 1\r\n if left == right:\r\n return \"YES\"\r\n return \"NO\"\r\nlength = int(input())\r\nn = input()\r\n\r\nprint(luckyTicket(n,length))", "def main():\r\n n = int(input())\r\n s = input()\r\n is_lucky = True\r\n first_half = 0\r\n for i in range(n // 2):\r\n temp = int(s[i])\r\n if temp != 4 and temp != 7:\r\n is_lucky = False\r\n break\r\n first_half += temp\r\n secondHalf = 0\r\n for i in range(n // 2, n):\r\n temp = int(s[i])\r\n if temp != 4 and temp != 7:\r\n is_lucky = False\r\n break\r\n secondHalf += temp\r\n if is_lucky == True and secondHalf == first_half:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\nmain()\r\n ", "n, = map(int, input().split())\r\ns = input()\r\nprint('YNEOS'[sum(map(int, s[:n // 2])) != sum(map(int, s[n // 2:])) or s.count('4') + s.count('7') != len(s)::2])", "n=int(input())\r\na=input()\r\nc=0\r\nfor i in a:\r\n if(i=='4' or i=='7'):\r\n c+=1\r\n else:\r\n print(\"NO\")\r\n break \r\nif(c==n):\r\n s=0 \r\n h=0\r\n k=int(a)\r\n d=n//2\r\n for i in range(0,d):\r\n s+=(k%10)\r\n k//=10\r\n for i in range(d,n):\r\n h+=(k%10)\r\n k//=10\r\n if(s==h):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n \r\n \r\n\r\n ", "#146A\r\n\r\nn = int(input())\r\nln = input()\r\nflag = firstHalf = secHalf = 0\r\nfor i in range(0,n):\r\n if (ln[i] == '4' or ln[i] == '7'):\r\n flag+=1\r\nif (flag == n):\r\n for i in range(0, n//2):\r\n firstHalf+= int(ln[i])\r\n for i in range(n//2, n):\r\n secHalf+= int(ln[i])\r\n if (firstHalf == secHalf):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\") \r\nelse:\r\n print(\"NO\") \r\n", "n=int(input())\r\nnum=input()\r\nluckey=True\r\nfor ele in num:\r\n if ele =='4' or ele == '7':\r\n luckey=True\r\n else:\r\n luckey=False\r\n break\r\nw1=num[:n//2]\r\nw2=num[n//2:]\r\nsum1=0\r\nsum2=0\r\nfor i in w1:\r\n sum1+=int(i)\r\nfor i in w2:\r\n sum2+=int(i)\r\nif luckey and (sum1==sum2):\r\n print(\"YES\")\r\nelse:\r\n print('NO')", "n=int(input())\r\na=input()\r\nprint('YNEOS'[any(x not in'47'for x in a)or sorted(a[:n//2])!=sorted(a[n//2:])::2])", "n = int(input())\r\nstrs = input()\r\nhalf = n // 2 \r\nfirst4 = 0 \r\nfirst7 = 0 \r\nsecond4 = 0 \r\nsecond7 = 0 \r\narr = []\r\nfor i in strs:\r\n arr.append(int(i))\r\nflag = 0 \r\n\r\nfor i in range(n):\r\n if arr[i] != 4 and arr[i] != 7:\r\n flag = 1 \r\n break \r\n if i >= half and arr[i] == 4:\r\n second4 += 1 \r\n elif i >= half and arr[i] == 7:\r\n second7 += 1 \r\n elif arr[i] == 4:\r\n first4 += 1 \r\n else:\r\n first7 += 1 \r\n\r\nif flag == 1:\r\n print(\"NO\")\r\nelif second7 != first7 or first4 != second4:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n \r\n ", "n = int(input())\nx = input()\nx_int = [int(num) for num in x]\nif(sum(x_int[:n//2]) == sum(x_int[n//2:]) and set(x).issubset({'4', '7'})):\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n", "def f(a,n):\r\n\tif len(n)%2!=0:\r\n\t\treturn \"NO\"\r\n\tif n.count(\"4\")+n.count(\"7\") !=a:\r\n\t\treturn \"NO\"\r\n\td1=sum(list(map(int,list(n[:a//2]))))\r\n\td2=sum(list(map(int,list(n[a//2:]))))\r\n\tif d1!=d2:\r\n\t\treturn \"NO\"\r\n\treturn \"YES\"\r\na=int(input())\r\nn=input()\r\nprint(f(a,n))", "\r\nn = int(input())\r\nl = list(input())\r\n\r\nset_ = set(l)\r\nif len(set_) > 2:\r\n\tprint('NO')\r\n\texit()\r\n\r\nif len(set_) == 1:\r\n\tif '7' in set_ or '4' in set_:\r\n\t\tprint('YES')\r\n\t\texit()\r\n\telse:\r\n\t\tprint('NO')\r\n\t\texit()\r\n\r\nelse:\r\n\tif '7' in set_ and '4' in set_:\r\n\t\tli = [int(l[i]) for i in range(n)]\r\n\t\tif sum(li[:n//2]) == sum(li[n//2:]):\r\n\t\t\tprint('YES')\r\n\t\telse:\r\n\t\t\tprint('NO')\r\n\telse:\r\n\t\tprint('NO')", "n = int(input())\r\nticket = input()\r\nis_lucky = True\r\nfor digit in ticket:\r\n if digit != '4' and digit != '7':\r\n is_lucky = False\r\n break\r\nsum_first_half = 0\r\nsum_second_half = 0\r\nfor i in range(n):\r\n if i < n/2:\r\n sum_first_half += int(ticket[i])\r\n else:\r\n sum_second_half += int(ticket[i])\r\n \r\nif is_lucky and sum_first_half == sum_second_half:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "import sys\r\nimport math\r\nimport bisect\r\nimport heapq\r\nimport string\r\nfrom collections import defaultdict,Counter,deque\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\n1 2 3 4 = 3\r\n3 2 1 0 = 0\r\n\r\n4 1 2 3 = 2\r\n0 3 2 1 = 1\r\n\r\n4 1 3 2 = 1\r\n0 3 1 2 = 2\r\n\r\n1 2\r\n2 1\r\n\r\nn = 1, ans = 1\r\n\r\n4 1 2 3 = 2\r\n1 4 2 3 = 2\r\n\r\n1 2 4 3\r\n1 2 3 4\r\n1 3 2 4\r\n1 3 4 2\r\n\r\n2 1 3 4\r\n2 3 1 4\r\n2 3 4 1\r\n\r\n3 4 1 2\r\n3 1 2 4\r\n\r\n1\r\n12\r\n\r\n\r\n1 2 \r\nany combo of 123 works -> 4\r\nany combo of 234 works -> 4\r\nany combo of 134 works -> 4\r\nany combo of 124 works -> 4\r\n\r\noverlaps...\r\n\r\n\r\n4 3 2 1\r\n4 2 3 1\r\n4 1 3 2\r\n\r\n\r\n\r\n'''\r\n\r\n# sys.stdin = open(\"backforth.in\", \"r\")\r\n# sys.stdout = open(\"backforth.out\", \"w\")\r\ninput = sys.stdin.readline\r\n\r\ndef solve():\r\n n = II()\r\n s = I().strip()\r\n s1 = 0\r\n s2 = 0\r\n lucky = True\r\n for i in range(n):\r\n x = int(s[i]) \r\n if x == 4 or x == 7:\r\n if i < n//2:\r\n s1 += x\r\n else:\r\n s2 += x\r\n else:\r\n lucky = False\r\n break\r\n\r\n print(\"YES\" if lucky and s1 == s2 else \"NO\")\r\n\r\nsolve()", "n=int(input())\r\na=input()\r\nb1=a.count('4')\r\nb2=a.count('7')\r\nif b1+b2==n:\r\n a1=0\r\n a2=0\r\n i=0\r\n while i<n//2:\r\n a1+=int(a[i])\r\n i=i+1\r\n i=n//2\r\n while i<n:\r\n a2+=int(a[i])\r\n i=i+1\r\n if a1==a2:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')", "f='yes'\r\nn=int(input())\r\na=input()\r\nb='47'\r\nfor i in range(n):\r\n if a[i] not in b:\r\n f='no'\r\nif f=='no':\r\n print('NO')\r\nelse:\r\n m1=0\r\n m2=0\r\n for i in range(n//2):\r\n m1+=int(a[i])\r\n for i in range(n//2,n):\r\n m2+=int(a[i])\r\n if m1==m2:\r\n print('YES')\r\n else:\r\n print('NO')\r\n", "n=int(input())\r\ns=input()\r\nf=s.count(\"4\")\r\nse=s.count(\"7\")\r\nif f+se==n:\r\n s1=s[:n//2]\r\n s2=s[n//2:]\r\n if s1.count(\"4\")==s2.count(\"4\") and s1.count(\"7\")==s2.count(\"7\"):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n \r\n", "n = int(input())\r\ns = str(input())\r\nif(s.count('4')+s.count('7')!=n):\r\n print(\"NO\")\r\nelse:\r\n suml = 0\r\n sumr = 0\r\n for i in range(0,n//2):\r\n suml+= int(s[i])\r\n sumr+= int(s[n-1-i])\r\n if(suml==sumr):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "__author__ = 'Esfandiar'\nn = int(input())\ns = input()\na=s[:n//2]\nb=s[n//2:]\nres1 = {'4':0,'7':0}\nres2 = {'4':0,'7':0}\nfor i in a:\n if i not in ['4','7']:\n print(\"NO\")\n exit()\n else:\n res1[i]+=1\n\nfor i in b:\n if i not in ['4','7']:\n print(\"NO\")\n exit()\n else:\n res2[i]+=1\nprint(\"YES\" if res1['4'] == res2['4'] and res1['7'] == res2['7'] else \"NO\")", "n = int(input())\r\nt = input()\r\nans = \"YES\"\r\nif len(t) != len([1 for x in t if x == \"4\" or x == \"7\"]):\r\n ans = \"NO\"\r\n\r\nt = list(t)\r\nif sum(list(map(int, t[:int(n / 2)]))) != sum(list(map(int, t[int(n/2):]))):\r\n ans = \"NO\"\r\n\r\nprint(ans)\r\n", "#In the name of Allah\r\n\r\nfrom sys import stdin, stdout\r\ninput = stdin.readline\r\n\r\nn = int(input())\r\ns = input()[:-1]\r\n\r\nbal = 0\r\n\r\nfor i in range(n // 2):\r\n bal += int(s[i])\r\n if s[i] != \"4\" and s[i] != \"7\":\r\n stdout.write(\"NO\")\r\n exit(0)\r\n\r\nfor i in range(n // 2, n):\r\n bal -= int(s[i])\r\n if s[i] != \"4\" and s[i] != \"7\":\r\n stdout.write(\"NO\")\r\n exit(0) \r\n\r\nif bal == 0:\r\n stdout.write(\"YES\")\r\nelse:\r\n stdout.write(\"NO\")\r\n", "#146A\r\nm=int(input())\r\nn=list(input())\r\np1=n.count(\"4\")\r\np2=n.count(\"7\")\r\nif p1+p2==m:\r\n p=m//2\r\n s1=[int(n[i])for i in range(p)]\r\n #print(s1)\r\n s2=[int(n[i]) for i in range (p,m)]\r\n #print(s2)\r\n s1_s=sum(s1)\r\n #print(s1_s)\r\n s2_s=sum(s2)\r\n #print(s2_s)\r\n if s1_s==s2_s:\r\n print(\"YES\")\r\n else:print(\"NO\")\r\nelse:print(\"NO\")\r\n\"\"\"\r\nn1=(input())\r\nn=list(n1)\r\nn1=int(n1)\r\np=m//2\r\ns1=[int(n[i])for i in range(p)]\r\ns2=[int(n[i]) for i in range (p,m)]\r\ns1_s=sum(s1)\r\ns2_s=sum(s2)\r\nif s1_s==s2_s:\r\n while n1>0:\r\n if n1%10!=4 or n1%10!=7:\r\n print(\"NO\")\r\n break\r\n \r\n \r\n\"\"\"\r\n", "def isLucky(teste):\n for i in teste:\n if (i != '4' and i!='7'):\n return False\n return True\n\n\ntamanho_do_ticket = int(input())\nticket = input()\n\nif isLucky(ticket):\n parte1 = ticket[:int(tamanho_do_ticket/2)]\n parte2 = ticket[int(tamanho_do_ticket/2):]\n soma1, soma2 = 0, 0\n for i in range(len(parte1)):\n soma1 += int(parte1[i])\n soma2 += int(parte2[i])\n if soma1==soma2:\n print('YES')\n else:\n print('NO')\nelse:\n print('NO')\n \t\t\t\t \t \t\t \t \t \t \t\t", "n = int(input())\r\ns = input()\r\nif s.count('4') + s.count('7') == len(s):\r\n s = list(map(int, list(s)))\r\n if sum(s[:n // 2]) == sum(s[n // 2:]):\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')", "n = int(input())\r\ns = str(input())\r\nif any(i for i in s if i not in '47'):\r\n print('NO')\r\nelif sum([int(s[i]) for i in range(n//2)]) == sum([int(s[i]) for i in range(n//2,n)]):\r\n print('YES')\r\nelse:\r\n print('NO')", "n = int(input())\r\nb = input()\r\nprint('NO') if len(b) != b.count('4') + b.count('7') or sum(list(map(int, b[:n//2]))) != sum(list(map(int, b[n//2:]))) else print('YES')\r\n", "j = int(\r\n input(\r\n )\r\n )\r\nif j %2 == 0:\r\n k = list(\r\n input(\r\n )\r\n )\r\n b = j//2\r\n k1 = k.count(\r\n '4'\r\n )\r\n k2 = k.count(\r\n '7'\r\n )\r\n if k1+k2 == j:\r\n p = 0\r\n p1 = 0\r\n l = k[\r\n :b:\r\n ]\r\n l1 = k[\r\n b::\r\n ]\r\n for i in l:\r\n p += int(\r\n i\r\n )\r\n for _ in l1:\r\n p1 += int(\r\n _\r\n )\r\n if p == p1:\r\n print(\r\n 'YES'\r\n )\r\n else:\r\n print(\r\n 'NO'\r\n )\r\n else:\r\n print(\r\n 'NO'\r\n )\r\nelse:\r\n print(\r\n 'NO'\r\n )\r\n \r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sun Jan 1 13:18:31 2023\r\n\r\n@author: DELL\r\n\"\"\"\r\nimport sys\r\n\r\nn=int(input())\r\nl1=list(input())\r\n\r\nfor i in l1:\r\n if(int(i)!=4 and int(i)!=7):\r\n print(\"NO\")\r\n sys.exit(0)\r\n\r\nsum1, sum2=0, 0\r\nfor i in range(0, int(n/2)):\r\n sum1=sum1+int(l1[i])\r\n sum2=sum2+int(l1[int(n/2)+i])\r\n \r\nif sum1==sum2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n", "def lucky_ticket():\r\n lucky_ticket = True\r\n sum_first_half = 0\r\n sum_second_half = 0\r\n # input length of ticket\r\n ticket_length = int(input())\r\n # ticket number\r\n ticket_num = str(input())\r\n # check to see if the ticket number only contains 4 and 7\r\n for i in range(0, ticket_length):\r\n if ticket_num[i] != \"4\" and ticket_num[i] != \"7\":\r\n lucky_ticket = False\r\n \r\n # check to see if the sum of the first half of the ticket num is equal to sum of the second half\r\n for i in range(0,ticket_length//2):\r\n value = int(ticket_num[i])\r\n sum_first_half += value\r\n for i in range(ticket_length-1,ticket_length//2-1,-1):\r\n value = int(ticket_num[i])\r\n sum_second_half += value\r\n \r\n if sum_first_half != sum_second_half:\r\n lucky_ticket = False\r\n # display if it is a lucky ticket or not\r\n if lucky_ticket == True:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\n\r\nlucky_ticket()", "n = int(input())\nnum = input()\nanswer = \"YES\"\nsumm = 0\ni = 0\nfor d in num:\n if d not in \"47\":\n answer = \"NO\"\n break\n d = int(d)\n if i >= n / 2:\n d *= -1\n summ += d\n i += 1\nif summ:\n # print(summ)\n answer = \"NO\"\nprint(answer)\n", "n = int(input())\r\nnum = input()\r\nfhalf = [int(num[i]) for i in range(n//2)]\r\nshalf = [int(num[i]) for i in range(n//2, n)]\r\nfcount47 = fhalf.count(4) + fhalf.count(7)\r\nscount47 = shalf.count(4) + shalf.count(7)\r\nnot47 = n - fcount47 - scount47\r\nsum_s = sum_f = 0\r\nif fcount47 > 0 and scount47 > 0 and not47 == 0:\r\n for i in range(n//2):\r\n sum_f += fhalf[i]\r\n sum_s += shalf[i]\r\n if sum_f == sum_s:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n", "import math\r\n\r\nn = int(input())\r\ns = input()\r\n\r\nst = list(map(int,filter(lambda x: x == '4' or x == '7',s)))\r\n\r\nprint(\"YES\" if len(s) == len(st) and sum(st[n//2:]) == sum(st[:n//2]) else \"NO\")", "\r\nn = int(input())\r\ns = input()\r\ns1 = s[:n//2]\r\ns2 = s[n//2:]\r\nprint('YES' if s.count('4')+s.count('7') == n and s1.count('4') == s2.count('4') and s1.count('7') == s2.count('7') else 'NO')", "n = int(input())\r\nt = list(input())\r\nsum1 = 0\r\nsum2 = 0\r\np = 0\r\nfor i in range(n):\r\n if t[i] not in ['4', '7']:\r\n print(\"NO\")\r\n p = 1\r\n break\r\n if i < n // 2:\r\n sum1 += int(t[i])\r\n else:\r\n sum2 += int(t[i])\r\nif p == 0:\r\n if sum1 == sum2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "import sys\r\ninput = sys.stdin.readline\r\nfrom collections import defaultdict, deque, Counter\r\nfrom heapq import heappop, heappush\r\nfrom bisect import bisect_left, bisect_right\r\nfrom math import gcd\r\n\r\nn = int(input())\r\ns = input().rstrip()\r\na = 0\r\nb = 0\r\nfl = 1\r\nst = set([4,7])\r\nfor i in range(n//2):\r\n a += int(s[i])\r\n b += int(s[-i-1])\r\n fl &= (int(s[i]) in st) & (int(s[-i-1]) in st)\r\nif fl and a == b:\r\n print('YES')\r\nelse:\r\n print(\"NO\")", "def checkLucky(str):\r\n n = len(str)\r\n numList = list(map(int, str))\r\n mid = n // 2\r\n if set(numList) == set([7]) or set(numList) == set([4]) or set(numList) == set([4, 7]):\r\n if sum(numList[:mid]) == sum(numList[mid:]):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\") \r\n else:\r\n print(\"NO\")\r\n\r\n\r\nn = int(input())\r\nstr = input()\r\ncheckLucky(str)", "N = input()\nN = int(N)\n\ns = '12356890'\nstrs = input()\nstrs = list(strs)\nstrs = [int(strs[i]) for i in range(len(strs))]\n\nsums = 0\nsumx = 0\n\nks = len(strs)//2\n\n\nfor i in range(len(strs)-1):\n if str(strs[i]) in s:\n sums += 1\n else:\n sums += 0\n\n\nstrs_1 = strs[:ks]\nstrs_2 = strs[ks:]\nsums_1 = sum(strs_1)\nsums_2 = sum(strs_2)\n\n\nif N < 2:\n print(\"NO\")\nelif sums > 0:\n print(\"NO\")\nelif sums ==0:\n if sums_1 == sums_2:\n print(\"YES\")\n elif sums_1 != sums_2:\n print(\"NO\")\n", "n=int(input())\r\ns=input()\r\nvalue=1\r\nt=n//2\r\nfor i in (s):\r\n if (i=='4' or i=='7') and value==1:\r\n value=1\r\n else:\r\n value=0\r\nif value==0:\r\n print('NO')\r\nelse:\r\n sum_first=0\r\n sum_second=0\r\n count=0\r\n for j in (s):\r\n if count<t:\r\n sum_first+=int(j)\r\n else:\r\n sum_second+=int(j)\r\n count+=1 \r\n \r\n \r\n if sum_first==sum_second:\r\n print('YES')\r\n else:\r\n print('NO')", "\r\nn = int(input())\r\nl = list(input())\r\n\r\ndef lkynum(arr):\r\n\tset_ = set(arr)\r\n\tif len(set_) == 2 and '4' in set_ and '7' in set_:\r\n\t\treturn True\r\n\tif len(set_) == 1 and ('4' in set_ or '7' in set_):\r\n\t\treturn True\r\n\r\n\treturn False\r\n\r\ndef ssu(n, arr):\r\n\tar = [int(l[i]) for i in range(n)]\r\n\r\n\tif sum(ar[:n//2]) == sum(ar[n//2:]):\r\n\t\treturn True\r\n\telse:\r\n\t\treturn False\r\n\r\nif lkynum(l) and ssu(n, l):\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')\r\n\t", "n = int(input())\r\nx = list(input())\r\n \r\nif all([i == '4' or i == '7' for i in x]):\r\n if sum([int(i) for i in x[:n//2]]) == sum([int(i) for i in x[n//2:]]):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nlucky = False\r\ns = list(input())\r\nans1 = 0\r\nans2 = 0\r\nfor i in range(len(s)//2):\r\n if (s[i] != \"7\" and s[i] != \"4\"):\r\n lucky = True\r\n break\r\n ans1 += int(s[i])\r\nfor i in range(len(s)//2, len(s)):\r\n if (s[i] != \"7\" and s[i] != \"4\"):\r\n lucky = True\r\n break\r\n ans2 += int(s[i])\r\nif (lucky):\r\n print(\"NO\")\r\nelse:\r\n if (ans1 != ans2):\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")", "n=int(input())\r\ns=input()\r\nif s.count('7')+s.count('4')!=len(s):\r\n print(\"NO\")\r\nelse:\r\n s1=0\r\n s2=0\r\n for i in s[:n//2]:\r\n s1+=int(i)\r\n for i in s[n//2:]:\r\n s2+=int(i)\r\n if s1==s2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "n=int(input())\r\ns=list(map(int,list(input()[:n])))\r\nw=sorted(list(set(s)))\r\ndef schn(l):\r\n for i in l:\r\n if i!=4:\r\n if i!=7:\r\n return False\r\n return True\r\nif schn(w):\r\n print(\"YES\" if sum(s[:int(n/2)])==sum(s[int(n/2):]) else \"NO\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\ns = input()\nt = [0]\nk = int(n/2)\nsum1 = 0\nsum2 = 0\nflag = 0\nfor i in range(0, n):\n t.append(int(s[i]))\nfor i in range(1, n+1):\n f1 = not t[i] == 7\n f2 = not t[i] == 4\n if f1 and f2:\n str = 'NO'\n flag = 1\n break\n if i <= k:\n sum1 += t[i]\n else:\n sum2 += t[i]\nif flag == 0:\n if sum1 == sum2:\n str = 'YES'\n else:\n str = 'NO'\nprint(str)\n", "n=int(input())\r\ns=input()\r\nif s.count(\"4\")+s.count(\"7\")==n:\r\n s1,s2=0,0\r\n for i in range(n//2):\r\n s1=s1+int(s[i])\r\n s2=s2+int(s[n-1-i])\r\n if s1==s2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n,s,sm,sm1=int(input()),input(),0,0\r\nfor i in range(n//2):\r\n sm+=int(s[i])-int(s[n-i-1])\r\nprint(\"YNEOS\"[((s.count(\"4\")+s.count(\"7\")==n)and(sm==0))==0::2])", "def checkforlucky_no(s):\r\n l = ['4', '7']\r\n z = 0\r\n for i in s:\r\n if i in l:\r\n z += 1\r\n if(z == len(s)):\r\n return 1\r\n else:\r\n return -1\r\n\r\n\r\ndef checkforsum(s):\r\n l = list(s)\r\n n = len(l)\r\n sum2 = sum1 = 0\r\n l1 = l[:((n-1)//2)+1]\r\n l2 = l[((n-1)//2)+1:]\r\n for i in l1:\r\n sum1 += int(i)\r\n for i in l2:\r\n sum2 += int(i)\r\n if(sum1 == sum2):\r\n return 1\r\n else:\r\n return -1\r\n\r\n\r\nl = int(input())\r\nticket_no = input()\r\nif(l % 2 == 0):\r\n k = checkforlucky_no(ticket_no)\r\n if(k > 0):\r\n m = checkforsum(ticket_no)\r\n if m > 0:\r\n print('YES')\r\n else:\r\n print('NO')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')\r\n", "def solve(n : int, s : str):\r\n l = 0 \r\n r = 0 \r\n for i, j in enumerate(s):\r\n if j != \"4\" and j != \"7\":\r\n print(\"NO\")\r\n return \r\n\r\n if i < n // 2:\r\n l += int(j)\r\n\r\n else:\r\n r += int(j)\r\n\r\n if l == r:\r\n print(\"YES\")\r\n\r\n else:\r\n print(\"NO\")\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n s = input()\r\n\r\n solve(n , s)\r\n\r\n", "n=int(input())\r\ns=input()\r\na,b=\"\",\"\"\r\nc,d=0,0\r\nif(s.count(\"4\")+s.count(\"7\")!=len(s)):\r\n print(\"NO\")\r\nelse:\r\n a=s[0:len(s)//2]\r\n b=s[len(s)//2:len(s)]\r\n for i in range(len(a)):\r\n c+=int(a[i])\r\n d+=int(b[i])\r\n if(c==d):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\n", "n=int(input())\r\na=str(input())\r\nsum=0\r\ncount=0\r\ni=0\r\nwhile i<int(n):\r\n if int(a[i])==4 or int(a[i])==7:\r\n sum=sum+1\r\n i=i+1\r\nif sum==n:\r\n count=count+1\r\nh=n//2\r\nj=0\r\nsum_fh=0\r\nwhile j<h:\r\n sum_fh=sum_fh+int(a[j])\r\n j=j+1\r\nk=h\r\nsum_sh=0\r\nwhile k<n:\r\n sum_sh=sum_sh+int(a[k])\r\n k=k+1\r\nif int(sum_fh)==int(sum_sh):\r\n count=count+1\r\nif count==2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\nnum=int(input())\nisLucky1=False\nisLucky2=False\nL=[]\nwhile(num>0):\n L.append(num%10)\n num=num//10\nif L.count(4)+L.count(7)==n:\n isLucky1=True\nif sum(L)==2*(sum(L[0:n//2])):\n isLucky2=True\nif isLucky1==True and isLucky2==True:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "n, s, fl, l, r = int(input()), input(), True, 0, 0\r\nfor x in range(n // 2):\r\n l += int(s[x])\r\n if s[x] not in ['4', '7']: fl = False\r\nfor x in range(n // 2, n):\r\n r += int(s[x])\r\n if s[x] not in ['4', '7']: fl = False\r\nif not fl or l != r: print(\"NO\")\r\nelse: print(\"YES\")", "s = int(input())\nl = list(map(int,input()))\nc =0\nfor i in l:\n if i!=4 and i!=7:\n c+=1\n break\nsum = 0; dum =0\nfor k in range(0,len(l)//2,1):\n sum += l[k]\n dum += l[len(l)-1-k]\n \n \n\nif c==0:\n if sum == dum:\n print(\"YES\")\n else:\n print(\"NO\")\nelse:\n print(\"NO\")\n \t \t\t\t \t \t \t \t \t \t\t \t\t\t \t", "n = int(input())\r\nx = input()\r\na = pow(10, n/2)\r\nisLucky = True\r\n\r\nfront = back = 0\r\nfor i in range(n//2):\r\n if(x[i] != '4' and x[i] != '7'): isLucky = False\r\n front += int(x[i])\r\n\r\nfor i in range(n//2, n):\r\n if(x[i] != '4' and x[i] != '7'): isLucky = False\r\n back += int(x[i])\r\n \r\nif(isLucky and front == back): print('YES')\r\nelse : print('NO')", "# A. Lucky Ticket\n\nn = int(input())\nnum = input()\n\nans = \"YES\"\nfor i in num:\n if i == '4' or i == '7':\n continue\n else:\n ans = \"NO\"\n break\n\nif ans == \"YES\":\n first = 0\n for x in num[:n//2]:\n first += int(x)\n\n second = 0\n for x in num[n//2:]:\n second += int(x)\n\n if first != second:\n ans = \"NO\"\n\nprint(ans)\n", "n=int(input())\r\nfl=1\r\ns = [0 for i in range(n)]\r\ns=input()\r\na=0\r\nb=0\r\nfor i in range(n):\r\n if i<n/2:\r\n a+=int(s[i])\r\n else:\r\n b+=int(s[i])\r\n if s[i]!='4' and s[i]!='7':\r\n fl=0\r\nif fl==1 and a==b:\r\n print('YES')\r\nelse:\r\n print('NO')", "\r\n\r\nn = int(input())\r\na = input()\r\na = list(a)\r\ns = 0\r\nif a.count('4') + a.count('7') != n:\r\n print('NO')\r\nelse:\r\n for i in range(n // 2):\r\n s += int(a[i])\r\n for i in range(n // 2 , n):\r\n s -= int(a[i])\r\n print('YES' if s == 0 else 'NO')\r\n \r\n \r\n ", "z=input\r\nn=int(z())\r\nl=z()\r\n\r\nfi=l[:n//2-1]\r\nli=l[n//2:]\r\npx=0\r\npy=0\r\nfor i in range(n//2):\r\n px+=int(l[i])\r\n py+=int(l[-i-1])\r\n \r\n \r\n \r\n\r\n\r\nf=l.count('4')\r\ns=l.count('7')\r\n\r\nif f+s==n and px==py:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n \r\n", "n = int(input())\r\na = list(map(int, input()))\r\nr = n // 2\r\n\r\nif a.count(4) + a.count(7) == n and sum(a[:r]) == sum(a[r:]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "# LUOGU_RID: 133502999\nn = input()\r\n\r\n输入 = list(map(int,list(input())))\r\n\r\nfind = 0\r\n\r\nindex_1 = 0\r\nindex_2 = len(输入)//2\r\nfor i in 输入:\r\n if i == 4 or i == 7:\r\n continue\r\n else:\r\n print(\"NO\")\r\n find = 1\r\n break\r\nif not find:\r\n if sum(输入[:index_2]) == sum(输入[index_2:]):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "n=int(input())\r\ns=input()\r\nflag=0\r\nk=''\r\nj=''\r\nfor i in range(len(s)):\r\n\tif s[i]=='4':\r\n\t\tcontinue\r\n\telif s[i]=='7':\r\n\t\tcontinue\r\n\telse:\r\n\t\tprint('NO')\r\n\t\tflag=1\r\n\t\tbreak\r\n\r\n\r\nk=k+s[n//2:]\r\nj=j+s[:n//2]\r\nj4=j.count('4')\r\nj7=j.count('7')\r\nk4=k.count('4')\r\nk7=k.count('7')\r\nif j4==k4 and j7==k7 and flag==0:\r\n\tprint('YES')\r\nelif flag==0:\r\n\tprint('NO')\r\n\t", "X= int(input())\r\nnumber = input().strip()\r\noutput = \"YES\"\r\nfirstSum = 0\r\nsecondSum = 0\r\n\r\nfor k in range(X// 2):\r\n if number[k] != '4' and number[k] != '7':\r\n output = \"NO\"\r\n break\r\n if number[X // 2 + k] != '4' and number[X // 2 + k] != '7':\r\n output = \"NO\"\r\n break\r\n firstSum += int(number[k])\r\n secondSum += int(number[X// 2 + k])\r\n\r\nif firstSum != secondSum:\r\n output=\"NO\"\r\n\r\nprint(output)\r\n", "def main():\r\n len = int(input())\r\n number = input()\r\n lucky = 0\r\n first_sum = 0\r\n second_sum = 0\r\n for i in range(len):\r\n if number[i] == \"4\" or number[i] == \"7\":\r\n continue\r\n else:\r\n lucky += 1\r\n for i in range(len//2):\r\n first_sum += int(number[i])\r\n for i in range(len-1, (len//2)-1, -1):\r\n second_sum += int(number[i])\r\n if lucky == 0 and first_sum == second_sum:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\nmain()\r\n", "number = int(input())\r\ns = input()\r\nflag = True\r\nfirst_sum = 0\r\nsecond_sum = 0\r\nfor i in range(number):\r\n if s[i] == '7' or s[i] == '4':\r\n flag = True\r\n else:\r\n flag = False\r\n break\r\n if i < number // 2:\r\n first_sum += int(s[i])\r\n else:\r\n second_sum += int(s[i])\r\nif second_sum == first_sum and flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=input()\r\nm=input()\r\ncnt=0\r\nfor i in range(len(m)):\r\n if m[i]=='4' or m[i]=='7':\r\n cnt+=1\r\nif cnt==len(m):\r\n ans=0\r\n for i in range(int(len(m)/2)):\r\n ans+=(int(m[i]))\r\n ans2=0\r\n for i in range(int(len(m)/2),len(m)):\r\n ans2+=int(m[i])\r\n if ans==ans2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nz = input()\r\n\r\ndef lt(z,n):\r\n x = 0\r\n m = 0\r\n for i in range(n):\r\n if int(z[i])!= 4 and int(z[i])!=7:\r\n return \"NO\"\r\n if i<n//2:\r\n x = x+int(z[i])\r\n else:\r\n m = m+int(z[i])\r\n if m!=x:\r\n return \"NO\"\r\n return \"YES\"\r\nprint(lt(z,n))\r\n", "n = int(input())\na = list(input())\nb = n//2\nfirst = a[:b]\nsecond = a[b:]\ncount = 0\nfor i in a:\n if i == '4' or i == '7':\n count += 1\nif count == n:\n s = 0\n d = 0\n for _ in first:\n s += int(_)\n for _ in second:\n d += int(_)\n print('YES' if d == s else 'NO')\nelse:\n print('NO')\n", "n = int(input())\r\na = [int(x) for x in input()]\r\nif a.count(4) + a.count(7) == n and sum(a[n//2:]) == sum(a[:n//2]):\r\n print(\"YES\")\r\nelse:\r\n print('NO')", "\r\nn,s=int(input()),input()\r\ns1,s2=s[:n//2],s[n//2:]\r\nif s.count('4')+s.count('7')!=n or sum(map(int,list(s1)))!=sum(map(int,list(s2))):\r\n print('NO')\r\nelse:\r\n print('YES')\r\n\r\n", "def is_lucky(s):\r\n n = len(s)\r\n sum1 = sum([int(x) for x in s[:n//2]])\r\n sum2 = sum([int(x) for x in s[n//2:]])\r\n return set(s).issubset(set('47')) and sum1 == sum2\r\n\r\nn = int(input())\r\ns = input()\r\nif is_lucky(s):\r\n print('YES')\r\nelse:\r\n print('NO')", "'''\r\n# Submitted By M7moud Ala3rj\r\nDon't Copy This Code, CopyRight . [email protected] © 2022-2023 :)\r\n'''\r\n# Problem Name = \"Lucky Ticket\"\r\n# Class: A\r\n\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()) ; t = input().strip()\r\n fh = 0 ; sh = 0\r\n if len(set(t).difference({\"4\", \"7\"}))==0:\r\n for i in range(n):\r\n if i<n//2:\r\n fh+=int(t[i])\r\n else:\r\n sh+=int(t[i])\r\n if fh==sh:\r\n printf(\"YES\")\r\n return\r\n printf(\"NO\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n # for t in range(int(input())):\r\n Solve()", "n=int(input())\r\ns=input()\r\ns=[int(i) for i in s]\r\nf=[0 for i in s if i!=4 and i!=7]\r\nif len(f)==0:\r\n first=sum(s[:n//2])\r\n second=sum(s[n//2:])\r\n if first == second:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\ntn=list(map(int,input()))\r\nprint(['NO','YES'][tn.count(7) + tn.count(4) == n and sum(tn[:n//2]) == sum(tn)//2])", "n=int(input())\r\nl=list(map(int,input()))\r\nr=n//2\r\nif l.count(4)+l.count(7)==n and sum(l[:r])==sum(l[r:]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input());x=input();Set=list(set(x))\r\nif len(Set)==2 and ('4' in Set) and ('7' in Set):\r\n\ts1=0;s2=0\r\n\tfor i in range(n//2):\r\n\t\ts1+=int(x[i]);s2+=int(x[(n//2)+i])\r\n\tif s1==s2: print('YES')\r\n\telse: print('NO')\r\nelif len(Set)==1 and (('4' in Set) or ('7' in Set)):\r\n\ts1=0;s2=0\r\n\tfor i in range(n//2):\r\n\t\ts1+=int(x[i]);s2+=int(x[(n//2)+i])\r\n\tif s1==s2: print('YES')\r\n\telse: print('NO')\r\nelse: print('NO')", "n = int(input())\nnumber = input()\nresult = True\nleftSum = 0\nrightSum = 0\nfor i in range(len(number)):\n if i < int(len(number) / 2):\n leftSum += int(number[i])\n else:\n rightSum += int(number[i])\n\n if number[i] != '4' and number[i] != '7':\n print('NO')\n quit()\n\nif len(number) % 2 != 0:\n rightSum -= int(number[int(len(number) / 2)])\nif leftSum != rightSum:\n print('NO')\nelse:\n print('YES')\n", "a=int(input())\r\ns=input()\r\nc,s1,s2=0,0,0\r\nfor i in range(len(s)):\r\n if s[i]!='4' and s[i]!='7':\r\n c=1\r\n break\r\n if i<(a/2):\r\n s1+=int(s[i])\r\n else:\r\n s2+=int(s[i]) \r\nif s1!=s2:\r\n c=1\r\nif c==0:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "n = int(input())\r\nnum = input()\r\nflag = True\r\nsum = 0\r\nfor i in range(n):\r\n if num[i] != '4' and num[i] != '7':\r\n flag = False\r\n break\r\n sum += int(num[i])\r\nnew = 0\r\nfor i in range(n//2):\r\n new += int(num[i])\r\nif new != sum//2:\r\n flag = False\r\nif flag:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n\r\n\r\n\r\n", "n = int(input())\r\ns = input()\r\nf, s = s[:n//2], s[n//2:]\r\nff, fs = f.count('4'), f.count('7')\r\nsf, ss = s.count('4'), s.count('7')\r\n\r\nif all([ff==sf, fs==ss, ff+fs == n//2, sf+ss == n//2]):\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "# Author: S Mahesh Raju\r\n# Username: maheshraju2020\r\n# Date: 31/08/2020\r\nfrom sys import stdin, stdout, setrecursionlimit\r\nfrom math import gcd, ceil, sqrt\r\nfrom collections import Counter, deque\r\nfrom bisect import bisect_left, bisect_right\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\nsetrecursionlimit(100000)\r\nmod = 1000000007\r\n\r\nn = ii1()\r\ns = is1()\r\nfor i in s:\r\n if i == '4' or i == '7':\r\n continue\r\n else:\r\n print('NO')\r\n break\r\nelse:\r\n a = s[: len(s) // 2]\r\n b = s[len(s) // 2 :]\r\n a1 = b1 = 0\r\n for i in a:\r\n a1 += int(i)\r\n for i in b:\r\n b1 += int(i)\r\n if a1 == b1:\r\n print('YES')\r\n else:\r\n print('NO')\r\n\r\n", "n=int(input());a=[ int(i) for i in input()]\r\nf_s=0\r\nb_s=0\r\nfor i in range(n):\r\n if a[i]!=4 and a[i]!=7:\r\n print(\"NO\")\r\n import sys;sys.exit()\r\n else:\r\n if i<n//2:\r\n f_s+=a[i]\r\n else:\r\n b_s+=a[i]\r\nif f_s==b_s:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n", "n=int(input())\nnum=input()\na=num[:(n//2)]\nb=num[(n//2):]\nsa=0\nsb=0\nfor i in a:\n sa+=int(i)\nfor i in b:\n sb+=int(i)\nif sa==sb and (set(a+b)=={\"7\",\"4\"}or set(a+b)=={\"4\"} or set(a+b)=={\"7\"}):\n print(\"YES\")\nelse:print(\"NO\")\n\t \t \t \t \t\t \t \t \t\t\t\t\t\t \t \t", "import sys\r\nfrom math import sqrt\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\ndef s(d):\r\n dis = 1 + 4 * 2 * 3 * d\r\n ds = sqrt(dis)\r\n return (-1 + ds) / 6\r\n\r\n\r\ndef main():\r\n c = inp()\r\n d = list((map(int, insr())))\r\n print(\"YES\" if sum(d[0:len(d)//2])==sum(d[len(d)//2:]) and all([str(b) in \"47\" for b in d]) else \"NO\")\r\n\r\n\r\n\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()\r\n main()\r\n", "import io\r\nimport os\r\nimport sys\r\nfrom collections import Counter\r\n# Reinitialize the Input function\r\n# to take input from the Byte Like \r\n# objects\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\n\r\n#read n = # scores\r\nn= int(input().decode().strip())\r\n\r\narr= [int(i) for i in list(map(str,input().decode().strip()))]\r\n\r\nflag =1\r\nfor i in arr:\r\n if i!=4 and i!=7:\r\n flag = 0\r\n break\r\n\r\nif flag==1 and sum(arr[:int(n/2)]) == sum(arr[int(n/2):]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\ns = input()\r\n\r\nif len(s.replace(\"4\", \"\").replace(\"7\", \"\")) != 0:\r\n print(\"NO\")\r\n quit()\r\nif sum(int(x) for x in s[:len(s) // 2]) != sum(int(x) for x in s[len(s) // 2:]):\r\n print(\"NO\")\r\n quit()\r\nprint(\"YES\")", "n = int(input())\r\n\r\nc = 0\r\n\r\nx = str(input())\r\n\r\nfor i in x:\r\n a = int(i)\r\n if a==4 or a==7:\r\n c += 1\r\nr = 0\r\nt = 0\r\n\r\nif c==n:\r\n for j in range(n//2):\r\n r += int(x[j])\r\n for k in range(n//2,n):\r\n t += int(x[k])\r\n if r==t:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\nnum = list(input())\r\n\r\nfor i in range(n):\r\n if num[i] != '4' and num[i] != '7':\r\n print('NO')\r\n break\r\nelse:\r\n f = 0\r\n s = 0\r\n for ni in num[:n//2]:\r\n f += int(ni)\r\n for ni in num[n//2:]:\r\n s += int(ni)\r\n if f == s:\r\n print('YES')\r\n else:\r\n print('NO')\r\n", "n=int(input())\r\nnum=input()\r\n\r\ncount=0\r\nfor i in range(n):\r\n if num[i]=='4' or num[i]=='7':\r\n count+=1\r\n else:\r\n break\r\n\r\nsum1=0\r\nsum2=0\r\nfor k in range(0,n//2):\r\n sum1+=int(num[k])\r\nfor j in range(n//2,n):\r\n sum2+=int(num[j])\r\n\r\nif count==n and sum1==sum2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n ", "n = int(input())\r\ndigits = [int(x) for x in list(input())]\r\nsum = 0\r\nfor i in range (n):\r\n if digits[i] != 4 and digits[i] != 7:\r\n print(\"NO\")\r\n exit()\r\n if i < int(n/2):\r\n sum += digits[i]\r\n else:\r\n sum -= digits[i]\r\nif sum == 0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nnumber = input()\r\n\r\nfound_unlucky_number = False\r\n\r\nleft_sum = 0\r\nfor i in range(round(n/2)):\r\n digit = int(number[i])\r\n left_sum += digit\r\n if digit not in [4, 7]:\r\n found_unlucky_number = True\r\n\r\nright_sum = 0\r\nfor i in range(round(n/2), n):\r\n digit = int(number[i])\r\n right_sum += digit\r\n if digit not in [4, 7]:\r\n found_unlucky_number = True\r\n\r\nif found_unlucky_number or left_sum != right_sum:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n", "n=int(input())\r\nn1=list(input())\r\nl=[]\r\nluck=0\r\nfor i in n1:\r\n l.append(int(i))\r\nif(len(set(l))==2):\r\n if 4 in l and 7 in l:\r\n luck=1\r\nelif(len(set(l))==1):\r\n if 4 in l or 7 in l:\r\n luck=1\r\nif(luck==1):\r\n if(sum(l[0:n//2])==sum(l[n//2:])):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\ns = list(map(int, input()))\r\nc = \"NO\"\r\na = n//2\r\np1 = 0\r\np2 = 0\r\nif s.count(7) + s.count(4) == n:\r\n for i in range(n):\r\n if i >= a:\r\n p2 += s[i]\r\n else:\r\n p1 += s[i]\r\n if p1 == p2:\r\n c = \"YES\"\r\n\r\n\r\nprint(c)\r\n\r\n#1 4\r\n#4\r\n#5 4 3 2\r\n#2 1 3 2\r\n\r\n#3\r\n\r\n ", "n=int(input())\r\nt=input()\r\nc1,c2=0,0\r\nluckyd=['4','7']\r\nluck=0\r\nfor digit in t:\r\n if digit not in luckyd:\r\n luck=1\r\n break\r\nif luck==0:\r\n for i in range (n//2):\r\n c1+=int(t[i])\r\n for i in range (n//2,n):\r\n c2+=int(t[i])\r\n if c1==c2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n \r\n \r\n \r\n\r\n\r\n", "def code(num):\r\n s1,s2=0,0\r\n for i in num[:n//2]:\r\n s1+=int(i)\r\n for i in num[(n//2):]:\r\n s2+=int(i)\r\n if s1!=s2:\r\n return \"NO\"\r\n s1=0\r\n for i in num:\r\n if i=='4' or i=='7':\r\n s1+=1\r\n if s1==len(num):\r\n return \"YES\"\r\n return \"NO\"\r\nn=int(input())\r\nnum=input()\r\nprint(code(num))", "import sys\r\n\r\ndef f(number):\r\n suma_izq,limit_izq=0,len(number)//2\r\n suma_der=0\r\n for i in range(0,limit_izq):\r\n if number[i]!='4' and number[i]!='7': return False\r\n suma_izq+=int(number[i])\r\n \r\n if(len(number)%2): limit_izq+=1\r\n for i in range(limit_izq,len(number)):\r\n if number[i]!='4' and number[i]!='7': return False\r\n suma_der+=int(number[i])\r\n\r\n if suma_izq==suma_der: return True\r\n return False\r\n\r\ndef main():\r\n n=int(sys.stdin.readline())\r\n number=sys.stdin.readline().strip()\r\n if f(number): print('YES')\r\n else: print('NO')\r\nmain()\r\n", "k = int(input())\r\ns = input()\r\n\r\ns0 = 0\r\ns1 = 0\r\n\r\nfor c in s[:k//2]:\r\n if int(c) not in (4, 7):\r\n print(\"NO\")\r\n exit()\r\n else:\r\n s0 += int(c)\r\n\r\nfor c in s[k//2:]:\r\n if int(c) not in (4, 7):\r\n print(\"NO\")\r\n exit()\r\n else:\r\n s1 += int(c)\r\n\r\nprint(\"YES\" if s0 == s1 else \"NO\")\r\n\r\n\"\"\"\r\n//////////////////////////////////////////\r\n// //\r\n// Implemented by brownfox2k6 //\r\n// //\r\n//////////////////////////////////////////\r\n\"\"\"", "def check_luckyness(n):\n lucky = 1\n for digit in map(int, n):\n if digit != 4 and digit != 7:\n lucky = 0\n if lucky:\n print(check_ticket(n))\n else:\n print(\"NO\")\n\n\ndef check_ticket(n):\n first_half = ticket_number[:len(ticket_number) // 2]\n latter_half = ticket_number[len(ticket_number) // 2:]\n\n first_half_sum = 0\n\n for number in first_half:\n first_half_sum = first_half_sum + int(number)\n\n latter_half_sum = 0\n\n for number in latter_half:\n latter_half_sum = latter_half_sum + int(number)\n\n if first_half_sum == latter_half_sum:\n return \"YES\"\n else:\n return \"NO\"\n\nif __name__ == \"__main__\":\n ticket_size = input()\n ticket_number = input()\n\n check_luckyness(ticket_number)\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\np=sorted(set(s))\r\nif(len(p)==1 and (p[0]=='4' or p[0]=='7')):\r\n print(\"YES\")\r\nelif(len(p)==2 and p[0]=='4' and p[1]=='7'):\r\n som1,som2=0,0\r\n for i in range(n):\r\n if(i<int(n/2)):\r\n som1+=int(s[i])\r\n else:\r\n som2+=int(s[i])\r\n if(som1==som2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "#rOkY\r\n#FuCk\r\n\r\n################################## kOpAl #####################################\r\n\r\nt=int(input())\r\ns=str(input())\r\nf=0\r\nfor i in range(0,len(s),1):\r\n if(s[i]=='4' or s[i]=='7'):\r\n f+=1\r\nif(f<t):\r\n print('NO')\r\nelse:\r\n x=s[0:t//2]\r\n y=s[t//2:len(s)]\r\n d=int(x)\r\n d1=int(y)\r\n r,r1,m,n=0,0,0,0\r\n while(d>0):\r\n r=d%10\r\n m+=r\r\n d=d//10\r\n while(d1>0):\r\n r1=d1%10\r\n n+=r1\r\n d1=d1//10\r\n if(m==n):\r\n print('YES')\r\n else:\r\n print('NO')\r\n \r\n", "b=\"01235689\"\r\nn=int(input())\r\na=input()\r\nc=[]\r\nd=[]\r\ne=[]\r\nfor i in a:\r\n if i in b:\r\n c.append(\"NO\")\r\n break\r\nif len(c)>0:\r\n print(\"NO\")\r\nelse:\r\n for j in a:\r\n d+=[int(j)]\r\n if sum(d[0:n//2])==sum(d[n//2:len(d)]):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "n = int(input())\nnum = str(input())\ncounter = 0\ncounterTwo = 0\nnum.lstrip(\"0\")\nnum = list(num)\nif n % 2 != 0:\n print(\"NO\")\nelse:\n for i in range(int(n/2)):\n if num[i] != \"4\" and num[i] != \"7\" or num[n - i - 1] != \"7\" and num[n - i - 1] != \"4\":\n counterTwo += 1\n print(\"NO\")\n break\n else:\n if num[i] != num[n - i - 1]:\n counter += 1\n if counter % 2 == 0 and counterTwo == 0:\n print(\"YES\")\n elif counter % 2 != 0 and counterTwo == 0:\n print(\"NO\")", "size = int(input())\nticket = input()\n\ndef split(word):\n return [char for char in word]\n\nlist = split(ticket)\n\nquatro = 0\nsete = 0\nyes = True\nfirst = 0\nsecond = 0\n\nfor number in list:\n if number != '4' and number != '7':\n yes = False\n break\nif yes == True:\n for i in range(size//2):\n first = first + int(list[i])\n second = second + int(list[i+size//2])\nif first == second and yes == True:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t \t\t\t\t \t \t\t \t\t\t\t \t \t", "n = int(input())\r\ns = input()\r\n\r\nlucky = True\r\ndiff = 0\r\nn //= 2\r\nfor i in range(n):\r\n if (s[i] != '4' and s[i] != '7') or (s[n + i] != '4' and s[n + i] != '7'):\r\n lucky = False\r\n break\r\n diff += (ord(s[i]) - ord(s[n + i]))\r\n\r\nlucky = lucky and (diff == 0)\r\nprint(\"YES\" if lucky else \"NO\")\r\n", "lon = int(input())\ndata = list(input())\n\ns1 = []\ns2 = []\n\nfor i in range(int(lon/2)):\n s1.append(data[i])\n s2.append(data[int(lon/2) + i])\n\ncont1 = 0\ncont2 = 0\n\no = 0\n\nfor i in range(int(lon/2)):\n if ((int(s1[i]) == 4 or int(s1[i])==7) and (int(s2[i]) == 4 or int(s2[i])==7) ):\n cont1 = cont1 + int(s1[i])\n cont2 = cont2 + int(s2[i])\n continue\n else:\n o=1\n print(\"NO\")\n break\n\nif ((cont1 == cont2) and o==0):\n print(\"YES\")\nelse:\n if (o==0):\n print(\"NO\")\n\n\n\n\n \t \t \t \t \t\t\t \t \t", "n = int(input())\n\ndigits = list(map(int, list(input())))\nfirstHalf = secondHalf = 0\n\ns = True\nfor i in range(n):\n if (i <= n/2-1):\n firstHalf += digits[i]\n else:\n secondHalf += digits[i]\n\n if (digits[i] != 4 and digits[i] != 7):\n s = False\n\nif (firstHalf != secondHalf): s = False\n\nprint(\"YES\" if s else \"NO\")\n", "length_of_ticket=int(input())\r\nnumber_of_ticket=input()\r\nmid=int(length_of_ticket/2)\r\nf=number_of_ticket[0:mid+1]\r\nl=number_of_ticket[mid:]\r\nfirst_half=int(f)\r\nsecond_half=int(l)\r\ncheck=set()\r\ni=0\r\nwhile i < len(number_of_ticket):\r\n check.add(number_of_ticket[i])\r\n i+=1\r\nfirst=0\r\nsecond=0\r\nj=0\r\nwhile j<len(number_of_ticket):\r\n if j<mid:\r\n first+=int(number_of_ticket[j])\r\n else:\r\n second+=int(number_of_ticket[j])\r\n j+=1\r\nif (len(check)==1 and \"4\" in check) and first==second:\r\n print(\"YES\")\r\nelif (len(check) == 1 and \"7\" in check) and first==second:\r\n print(\"YES\")\r\nelif (len(check)==2 and \"4\" in check and \"7\" in check) and first==second:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\ns=input()\r\nf=sum1=sum2=0\r\nfor i in s:\r\n if i!='4' and i!='7':\r\n f=1\r\nif f==0:\r\n for i in range(n//2):\r\n sum1+=int(s[i])\r\n for i in range(n//2,n):\r\n sum2+=int(s[i])\r\n if sum1==sum2:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')", "n=int(input())\r\na=input()\r\nisluky=False\r\nisequal=False\r\nif a.count('7')+a.count('4')==n:\r\n isluky=True\r\ns1=0\r\ns2=0\r\nfor i in range(n//2):\r\n s1+=int(a[i])\r\nfor i in range(n//2,n):\r\n s2+=int(a[i])\r\nif s1==s2:\r\n isequal=True\r\nif isluky and isequal:\r\n print('YES')\r\n exit()\r\nprint('NO')", "n=int(input())\r\ns=input()\r\nS=set(s)\r\nS_new=\"\".join(S)\r\nif S_new==\"4\" or S_new==\"7\" or S_new==\"47\" or S_new==\"74\":\r\n a=s[:n//2]\r\n b=s[n//2:]\r\n a_list=list(map(int,a))\r\n b_list=list(map(int,b))\r\n if sum(a_list)==sum(b_list):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "number_length = int(input())\r\nnumber = (input())\r\ncount = 0\r\nfor X in number:\r\n if X != \"4\" and X != \"7\":\r\n count += 1\r\nif count == 0:\r\n sum = 0\r\n for X in range(number_length // 2):\r\n sum += int(number[X])\r\n sum2 = 0\r\n for X in range(number_length // 2):\r\n sum2 += int(number[X + number_length // 2])\r\n if sum == sum2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\no = input()\r\ns = o.count(\"4\")\r\nf = o.count(\"7\")\r\nif s+f==n:\r\n s1 = o[:n//2]\r\n s2 = o[n//2:]\r\n if s1.count(\"4\")==s2.count(\"4\") and s1.count(\"7\")==s2.count(\"7\"):\r\n print(\"YES\")\r\n else:\r\n print(\r\n \"NO\")\r\nelse:\r\n print(\"NO\")\r\n ", "n=int(input())\r\ns=(input())\r\n\r\nc=s.count(\"4\")+s.count(\"7\")\r\nif c!=n:\r\n\tprint(\"NO\")\r\nelse:\r\n\tl=[int(i) for i in s]\r\n\tif sum(l[:n//2])==sum(l[n//2:]):\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")", "import sys\n\nn = int(input().strip())\nnum = input().strip()\ni, j = 0, n-1\nlsum, rsum = 0, 0\nlucky = ['4', '7']\n\nwhile j > i:\n if num[i] not in lucky or num[j] not in lucky:\n print('NO')\n sys.exit()\n else:\n lsum += int(num[i])\n rsum += int(num[j])\n i += 1\n j -= 1\n\nif lsum == rsum:\n print('YES')\nelse:\n print('NO')", "numbers = {'0' : 0, '1' : 1, '2' : 2, '3' : 3, '4' : 4, '5' : 5, '6' : 6, '7' : 7, '8' : 8, '9' : 9}\r\n\r\nn = int(input())\r\nnumber = input()\r\n\r\ncheck = 0\r\nfirstHalf = 0\r\nsecondHalf = 0\r\n\r\nfor i in range(n):\r\n if number[i] != '4' and number[i] != '7':\r\n check += 1\r\n break\r\n if i+1 <= n // 2:\r\n firstHalf += numbers[number[i]]\r\n else:\r\n secondHalf += numbers[number[i]]\r\n\r\nif check == 0 and firstHalf == secondHalf:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "length_of_ticket_number = int(input())\nticket_number = input()\n\nother_digits = length_of_ticket_number - ticket_number.count('4') - ticket_number.count('7')\n\nif other_digits > 0 :\n print('NO')\nelse:\n s_to_list = list(ticket_number)\n for i in range(length_of_ticket_number):\n s_to_list[i] = int(s_to_list[i])\n\n total_first_half_digits = 0\n total_second_half_digits = 0\n\n for n in s_to_list[:len(s_to_list) // 2]:\n total_first_half_digits += n\n\n for a in s_to_list[len(s_to_list) // 2:]:\n total_second_half_digits += a\n\n if total_first_half_digits == total_second_half_digits:\n print('YES')\n else:\n print('NO')", "n = int(input().strip())\r\nk = input().strip()\r\nll = []\r\no = True\r\nfor i in k:\r\n if i in ['4','7']:\r\n ll.append(int(i))\r\n else:\r\n o = False\r\n break\r\nif o == True:\r\n print('YES' if sum(ll[0:n//2]) == sum(ll[n//2:]) else 'NO')\r\nelse:\r\n print('NO')", "n=int(input())\r\ns=int(n/2)\r\n#a=list(map(int,input().split()))\r\na=[int(x) for x in input()]\r\nif a.count(4)+a.count(7)==n and sum(a[:s])==sum(a[s:]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\nl=list(map(int,input()))\r\nif sum(l[:n//2])!=sum(l[n//2:]):\r\n\tprint(\"NO\")\r\nelse:\r\n\tif l.count(4)+l.count(7)==n:\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")", "import sys\r\nread=sys.stdin.buffer.readline\r\n\r\nmi=lambda:map(int,read().split())\r\nli=lambda:list(mi())\r\ncin=lambda:int(read())\r\n\r\nn=cin()\r\na=[int(el) for el in input()]\r\ns=set(a)\r\nprint(['NO','YES'][n%2==0 and sum(a[:n//2])==sum(a[n//2:]) and ((len(s)==1 and (4 in s or 7 in s))or (len(s)==2 and 4 in s and 7 in s))])", "n = input();k=input()\r\nprint([\"NO\", \"YES\"][(k.count('7') + k.count('4') == len(k)) and (sum(map(int, k[:int(n)//2])) == sum(map(int, k[int(n)//2:]))) ])\r\n\r\n", "a=int(input())\r\nb=input()\r\nl=[int(x) for x in b if x=='4' or x=='7']\r\nif len(l)==len(b):\r\n print(\"YES\") if sum(l[0:a//2])==sum(l[a//2::]) else print(\"NO\")\r\nelse:\r\n print(\"NO\")", "def solve(n,num):\r\n for i in num:\r\n if i != '7' and i != '4':\r\n return False\r\n a = 0 \r\n b = 0\r\n for i in range(int(n/2)):\r\n a += int(num[i])\r\n for i in range(int(n/2),n):\r\n b += int(num[i])\r\n if a== b:\r\n return True\r\n return False\r\n\r\nn = int(input())\r\nnum = input()\r\nif solve(n,num):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\ns=input()\r\nc=0\r\ns1=s2=0\r\nfor i in range(n):\r\n if s[i]!=\"4\" and s[i]!=\"7\":\r\n c+=1\r\n if i<int(n/2):\r\n s1+=(int(s[i]))\r\n else :\r\n s2+=(int(s[i]))\r\nif c==0:\r\n if s1==s2:\r\n print(\"YES\")\r\n else :\r\n print(\"NO\")\r\nelse :\r\n print(\"NO\")", "n=int(input())\r\nt=list(input())\r\nA=0\r\nB=0\r\nr=1\r\nfor i in t:\r\n if int(i) != 7 and int(i) != 4:\r\n r=0\r\n \r\nif r>0:\r\n i=(int(n/2))-1\r\n j=int(n/2)\r\n\r\n while i>=0:\r\n A=A+int(t[i])\r\n B=B+int(t[j])\r\n i-=1\r\n j+=1\r\nif r==1 and A==B:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nticket = list(map(int, input()))\r\nfirstsum = sum(ticket[:n//2])\r\nsecondsum = sum(ticket[n//2:])\r\nif firstsum == secondsum and all(digit == 4 or digit == 7 for digit in ticket):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\nt = input()\r\nif t.count(\"7\") + t.count(\"4\") == n:\r\n tl = [int(i) for i in t]\r\n if sum(tl[:n // 2]) == sum(tl[n // 2:]):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\ns = [int(c) for c in input()]\r\nif all(i == 4 or i == 7 for i in s):\r\n if sum(s[0:n//2]) == sum(s[n//2:]):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\ns=input()\r\na=list(set(list(s)))\r\na.sort()\r\nk1=sum(map(int,s[:n//2]))\r\nk2=sum(map(int,s[n//2:])) \r\nif(len(a)>2):\r\n print(\"NO\")\r\nelif(len(a)==2 and a[0]==\"4\" and a[1]==\"7\" and k1==k2):\r\n print(\"YES\")\r\nelif(len(a)==1 and (a[0]==\"4\" or a[0]==\"7\") and k1==k2):\r\n print(\"YES\")\r\nelse:\r\n print('NO')", "def is_lucky(number):\n acc = 0\n for digit in number:\n digit = int(digit)\n if digit != 4 and digit != 7:\n return -1\n acc += digit\n return acc\n\nn = int(input())\nticket = input()\n\nhalf1 = ticket[:n//2]\nhalf2 = ticket[n//2:]\n\nresult1 = is_lucky(half1)\nresult2 = is_lucky(half2)\n\nprint(\"YES\" if result1 != -1 and result1 == result2 else \"NO\")\n\n \t \t \t\t \t \t\t\t\t \t\t\t", "n = int(input())\nnumber = input()\n\nini = 0\nfim = n - 1\nleft_sum = 0\nright_sum = 0\nanswer = \"YES\"\nwhile ini < fim:\n if (number[ini] == \"4\" or number[ini] == \"7\") and (number[fim] == \"4\" or number[fim] == \"7\"):\n left_sum += int(number[ini])\n right_sum += int(number[fim])\n ini += 1\n fim -= 1\n else:\n answer = \"NO\"\n break\nif answer == \"YES\":\n if left_sum != right_sum:\n answer = \"NO\"\n\nprint(answer)\n\t\t \t\t \t \t \t\t\t\t\t\t \t \t\t\t\t", "\r\nn = int(input())\r\ns = list(input())\r\nif \"0\" in s or \"1\" in s or \"2\" in s or \"3\" in s or \"5\" in s or \"6\" in s or \"8\" in s or \"9\" in s:\r\n print(\"NO\")\r\nelse:\r\n first = s[0:n // 2]\r\n last = s[n // 2:]\r\n first_sum_ = 0\r\n last_sum_ = 0\r\n for i in first:\r\n first_sum_ += int(i)\r\n for i in last:\r\n last_sum_ += int(i)\r\n if first_sum_ == last_sum_:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "n=int(input())\r\ns=list(map(int,input()))\r\na=set(s)\r\nif a=={4,7} or a=={7} or a=={4}:\r\n\tif sum(s[0:n//2])==sum(s[n//2:]):\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")\r\nelse:\r\n\tprint(\"NO\")\r\n", "n = int(input())\r\na = list(map(int, ' '.join(input()).split()))\r\nfor i in a:\r\n if i != 7 and i != 4:\r\n exit(print('NO'))\r\nprint('YES' if sum(a[:n // 2]) == sum(a[n // 2:]) else 'NO')", "n = int(input())\r\ns = input()\r\nprint(['NO', 'YES'][\r\n s[:(n // 2)].count('4') == s[(n // 2):].count('4') and s[:(n // 2)].count('7') == s[(n // 2):].count(\r\n '7') and s.count('7') + s.count('4') == n])\r\n", "n = int(input())\r\nnumber = input()\r\n\r\n# Check if the number is a lucky number\r\nis_lucky = True\r\nfor ch in number:\r\n if ch != '4' and ch != '7':\r\n is_lucky = False\r\n \r\n# Check if the sum of digits in first half is equal to the sum of digits in second half\r\nfirst_half = number[:int(n/2)]\r\nsecond_half = number[int(n/2):]\r\nsum_first_half = 0\r\nsum_second_half = 0\r\n\r\nfor ch in first_half:\r\n sum_first_half += int(ch)\r\n \r\nfor ch in second_half:\r\n sum_second_half += int(ch)\r\n\r\nif sum_first_half != sum_second_half:\r\n is_lucky = False\r\n \r\n# Print result\r\nif is_lucky:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\ns=input()\r\nflag=True\r\nfor i in s:\r\n if(i!=\"4\" and i!=\"7\"):\r\n flag=False\r\n print(\"NO\")\r\n break\r\nif(flag):\r\n x=0\r\n y=0\r\n for i in range(n//2):\r\n x=x+int(s[i])\r\n for i in range(n//2,n):\r\n y=y+int(s[i])\r\n if(x==y):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\n ", "n, = map(int,input().split())\r\ns = input()\r\nif s.count('4')+s.count('7')==n:\r\n s1 = s[:n//2]\r\n s4 = s1.count('4')\r\n if s4+s4 == s.count('4'):\r\n print(\"YES\")\r\n exit(0)\r\nprint(\"NO\")", "a = int(input())\r\ns = input()\r\nif s.count(\"4\")+s.count(\"7\") == a:\r\n temp = s[:(a//2)]\r\n temp2 = s[(a//2):]\r\n ans1 = 0;ans2 = 0\r\n for i in temp:\r\n ans1+=int(i)\r\n for j in temp2:\r\n ans2+=int(j)\r\n print(\"YES\" if ans1 == ans2 else \"NO\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\nc=list(map(int,input()))\r\nm1=c[:n//2]\r\nm2=c[n//2:]\r\n\r\nif sum(m1)!=sum(m2):\r\n\tprint(\"NO\")\r\nelse:\r\n\tif c.count(4)+c.count(7)==n:\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")\r\n\t\t\r\n", "from sys import stdin\n\n\ndef main():\n n = int(stdin.readline().strip()) // 2\n l = list(map(int, stdin.readline().strip()))\n return ('NO', 'YES')[sum(l[:n]) == sum(l[n:]) and all(c in (4, 7) for c in l)]\n\n\nprint(main())\n", "n = int(input())\r\na = input()\r\n\r\nflag = True\r\n\r\nif n % 2 !=0:\r\n flag =False\r\n\r\nfor digit in a:\r\n if digit =='4' or digit=='7':\r\n pass\r\n else:\r\n flag =False\r\n break\r\n\r\nsum1=0\r\nsum2=0\r\n\r\nfor i in a[:n//2]:\r\n sum1+=int(i)\r\nfor i in a[n//2:]:\r\n sum2+=int(i)\r\n\r\nif sum1!=sum2:\r\n flag = False\r\nif flag:\r\n print(\"YES\")\r\n print()\r\nelse:\r\n print(\"NO\")\r\n print()", "no_of_digits=int(input())\r\nticket=input()\r\nhalf=no_of_digits/2\r\nsum1,sum2=0,0\r\nlucky=True\r\nfor i in range(no_of_digits):\r\n if ticket[i]!=\"4\"and ticket[i]!=\"7\":\r\n lucky=False\r\n if i<half:\r\n sum1+=int(ticket[i])\r\n else:\r\n sum2+=int(ticket[i])\r\nif lucky and sum1== sum2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nmor = input()\r\nsum = 0\r\nfor i in range(0,n):\r\n if int(mor[i]) == 4 or int(mor[i]) == 7:\r\n sum += int(mor[i])\r\n else:\r\n print('NO')\r\n exit()\r\nd = n // 2\r\nf = 0\r\nfor i in range(0,d):\r\n f += int(mor[i])\r\nif sum/2 == f: \r\n print('YES')\r\n exit()\r\nprint('NO')", "import sys\r\nsys.stdin.reconfigure(line_buffering=True)\r\nn=int(input())\r\ns=input()\r\nn=n//2\r\nli=[]\r\nfor i in s:\r\n if i not in \"47\":\r\n print(\"NO\")\r\n exit()\r\n else:\r\n li.append(int(i))\r\nif sum(li[:n])==sum(li[n:]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\ns=list(map(int,input()))\r\nfor i in s:\r\n\tif i not in [4,7]:\r\n\t\tprint('NO')\r\n\t\texit()\r\nprint(['YES','NO'][sum(s[:n//2])!=sum(s[n//2:])])", "\r\nn = int(input())\r\nn1 = input()\r\nres=res1=0\r\nfor i in n1:\r\n if i!='4' and i!='7':\r\n print('NO')\r\n break\r\nelse:\r\n\r\n for i in range(0,n//2):\r\n res += int(n1[i])\r\n for i in range(n//2,n):\r\n res1 += int(n1[i])\r\n\r\n if res==res1:\r\n print('YES')\r\n else:\r\n print('NO')\r\n\r\n", "n = int(input())\r\ns = str(input())\r\nx = ['4', '7']\r\naccept = 0\r\nfor i in range(n):\r\n\tif s[i] not in x:\r\n\t\taccept = 1\r\n\t\tbreak\r\nif accept == 1:\r\n\tprint('NO')\r\nelse:\r\n\tfirst = 0\r\n\tsecond = 0\r\n\tfor i in range(n // 2):\r\n\t\tfirst += int(s[i])\r\n\tfor j in range(n // 2, n):\r\n\t\tsecond += int(s[j])\r\n\tif first == second:\r\n\t\tprint('YES')\r\n\telse:\r\n\t\tprint('NO')", "n = int(input())\ns = input()\nif s.count('4') + s.count('7') != len(s):\n\tprint('NO')\nelse:\n\tl = [int(x) for x in s]\n\tif sum(l[: n // 2]) == sum(l[n // 2: ]):\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "k = int(input())\r\nstr = input()\r\nfor i in str:\r\n if i not in ('4','7'):\r\n print('NO')\r\n exit()\r\n\r\nsum1 = sum2 = 0\r\nfor i in range(int(k/2)):\r\n sum1 += int(str[i])\r\n\r\nfor i in range(int(k/2), int(k)):\r\n sum2 += int(str[i])\r\n\r\nif sum1 == sum2:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n\r\n", "def luckeyticket():\r\n length=int(input(''))\r\n inp=input('')\r\n if length%2!=0:\r\n print('NO')\r\n return\r\n else:\r\n for i in range (length):\r\n a=inp[i]\r\n if a!='4' and a!='7':\r\n print('NO')\r\n return\r\n sum1=0\r\n for j in range (length//2):\r\n b=int(inp[j])\r\n sum1+=b\r\n sum2=0\r\n for k in range (length//2,length):\r\n c=int(inp[k])\r\n sum2+=c\r\n if sum1==sum2:\r\n print('YES')\r\n else:\r\n print('NO')\r\nluckeyticket()\r\n", "def lucky_digits(n, size):\r\n c = 0\r\n for i in str(n):\r\n if i in \"47\":\r\n c += 1\r\n return c == size\r\n \r\ndef equal_halves(n, size):\r\n s = str(n)\r\n s1, s2 = 0, 0\r\n for i in range(0, size // 2, 1):\r\n s1 = s1 + int(s[i])\r\n for i in range(size // 2, size):\r\n s2 = s2 + int(s[i])\r\n return s1 == s2\r\n \r\nn = int(input())\r\nnum = int(input())\r\n\r\nif lucky_digits(num, n) and equal_halves(num, n):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\na=input()\r\ns={'4','7'}\r\nflag=0\r\nfor number in a:\r\n if(number not in s):\r\n flag=1\r\n break\r\nif(flag==1):\r\n print(\"NO\")\r\nelse:\r\n sum1=0\r\n sum2=0\r\n for i in range(0,int(n/2)):\r\n sum1=sum1+int(a[i])\r\n for i in range(int(n/2),n):\r\n sum2=sum2+int(a[i])\r\n if(sum1==sum2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "n=int(input())\r\ns=str(input())\r\n\r\nE=0\r\n\r\nfor i in s:\r\n if i==\"4\" or i==\"7\":\r\n pass\r\n else:\r\n print(\"NO\")\r\n break\r\nelse:\r\n for i in range(n//2):\r\n E+=int(s[i])\r\n for i in range(n//2,n):\r\n E-=int(s[i])\r\n if E==0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "n=int(input())\r\nnum=input()\r\ns=\"12356890\"\r\nflag=0\r\nfor si in s:\r\n if si in num:\r\n flag+=1\r\n break\r\nif(flag==1):\r\n print(\"NO\")\r\nelse:\r\n n=n//2;\r\n sum1=sum2=0\r\n for i in range(n):\r\n sum1+=int(num[i])\r\n for i in range(n,len(num)):\r\n sum2+=int(num[i])\r\n if(sum1==sum2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "n = int(input())\nnum = input()\n\nresposta = \"YES\"\n\ni = 1\nsoma_1 = 0\nwhile i <= n/2:\n soma_1 += int(num[i-1])\n if num[i-1] != '4' and num[i-1] != '7':\n resposta = 'NO'\n break\n i += 1\n\n\n\nsoma_2 = 0\nwhile i <= n:\n soma_2 += int(num[i-1])\n if num[i-1] != '4' and num[i-1] != '7':\n resposta = 'NO'\n break\n i += 1\n\nif soma_1 != soma_2:\n resposta = 'NO'\n\n\nprint(resposta)\n\t\t \t \t \t\t\t \t \t \t \t\t\t\t \t \t \t", "n, number = int(input()), list(map(int, input()))\r\nprint(\"YES\")if all([i == 4 or i == 7 for i in set(number)]) and sum(number[:n//2]) == sum(number[n//2:]) else print(\"NO\")", "a=int(input())\r\nn=input()\r\nfor i in range(len(n)):\r\n if n[i]!='4' and n[i]!='7':\r\n print('NO')\r\n exit()\r\nn1=n[0:a//2]\r\nsum1=0\r\nn2=n[a//2:len(n)]\r\nsum2=0\r\nfor i in range(0,len(n1)):\r\n sum1+=int(n1[i])\r\n sum2+=int(n2[i])\r\nif sum1==sum2:\r\n print('YES')\r\nelse:\r\n print('NO') \r\n \r\n", "n = int(input())\r\nt = input()\r\n\r\nfor i in t:\r\n if i != \"4\" and i != \"7\":\r\n print(\"NO\")\r\n exit(0)\r\n\r\nif sum(map(int, t[:n//2])) == sum(map(int, t[n//2:])):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n, w = int(input()), input()\r\nwChars = list(w)\r\ns = set(wChars)\r\nif s.issubset({'4','7'}):\r\n lst = [int(c) for c in wChars]\r\n h = n // 2 \r\n print([\"NO\",\"YES\"][sum(lst[:h]) == sum(lst[h:])])\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nm = input()\r\nm = list(m)\r\np = 0\r\nm = [int(x) for x in m]\r\nfor i in range(n):\r\n if (m[i] == 4 or m[i] == 7):\r\n pass\r\n else:\r\n p = 1\r\nif p == 0 and n % 2 == 0:\r\n if sum(m[:n // 2]) == sum(m[n // 2:n]):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\nif p == 1:\r\n print(\"NO\")", "n = input()\n\n输入 = list(map(int, list(input())))\n\nfind = 0\n\nindex_1 = 0\nindex_2 = len(输入) // 2\nfor i in 输入:\n if i == 4 or i == 7:\n continue\n else:\n print(\"NO\")\n find = 1\n break\nif not find:\n if sum(输入[:index_2]) == sum(输入[index_2:]):\n print(\"YES\")\n else:\n print(\"NO\")\n # 11111\n\n \t\t \t\t\t\t\t\t\t \t \t\t\t\t \t\t\t", "def lucky_ticket ():\r\n n = int(input()) #2 to 50 #length of ticket number #always even\r\n number = input() #ticket number\r\n for i in range (n):\r\n if number[i] != '4' and number[i] != '7':\r\n return 'NO'\r\n else:\r\n sum1 = 0\r\n for j in range (n//2):\r\n sum1 += int(number[j])\r\n sum2 = 0\r\n for j in range (n//2,n):\r\n sum2 += int(number[j])\r\n if sum1 == sum2:\r\n return 'YES'\r\n else:\r\n return 'NO'\r\nprint(lucky_ticket())\r\n", "def solution(n,a):\r\n sum1=0\r\n sum2=0\r\n for i in range(n//2):\r\n if a[i]!=4 and a[i]!=7:\r\n print('NO')\r\n return\r\n else:\r\n sum1+=a[i]\r\n\r\n if a[(n//2)+i]!=4 and a[(n//2)+i]!=7:\r\n print('NO')\r\n return\r\n else:\r\n sum2+=a[(n//2)+i]\r\n\r\n if sum1==sum2:\r\n print('YES')\r\n else:\r\n print('NO')\r\n\r\nn=int(input(''))\r\na=input('')\r\nb=[int(x) for x in a]\r\n# print(b)\r\nsolution(n,b)", "n = int(input())\r\na = input()\r\n\r\ndef isHappy(s):\r\n\tfor i in s:\r\n\t\tif i not in ['4', '7']:\r\n\t\t\treturn False\r\n\treturn True\r\n\r\nif isHappy(a) and sum([int(i) for i in a[:n // 2]]) == sum([int(i) for i in a[n // 2:]]):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "n = int(input())\ns = input()\ncount1 = 0\ncount2 = 0\nfor i in range(0, int(n/2)):\n if int(s[i]) == 4 or int(s[i]) == 7:\n count1 = count1 + int(s[i])\n else:\n print(\"NO\")\n exit()\nfor j in range(int(n/2), n):\n if int(s[j]) == 4 or int(s[j]) == 7:\n count2 = count2 + int(s[j])\n else:\n print(\"NO\")\n exit()\nif count1 == count2:\n print(\"YES\")\nelse:\n print(\"NO\")", "def get(n, l, r):\r\n four, seven, others = 0, 0, 0\r\n for j in range(l, r):\r\n if n[j] == '4':\r\n four += 1\r\n elif n[j] == '7':\r\n seven += 1\r\n else:\r\n others += 1\r\n return four, seven, others\r\nn = int(input())\r\ns = str(input())\r\nmid = int(n / 2)\r\nf1, s1, o1 = get(s, 0, mid)\r\nf2, s2, o2 = get(s, mid, n)\r\nif f1 == f2 and s1 == s2 and o1 == 0 and o2 == 0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\nm = input()\r\ne = m.count('4')\r\nq = m.count('7')\r\nw = e+q\r\nse = 0\r\nfor i in range(n//2):\r\n se+=int(m[i])\r\ner = 0\r\na = m[::-1]\r\nfor i in range(n//2):\r\n er+=int(a[i])\r\nif se==er and w==n:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "n=int(input())\r\ns=input()\r\nc1,c2,c3,c4=0,0,0,0\r\nfor i in range(n>>1):\r\n if s[i]=='4':\r\n c1+=1 \r\n elif s[i]=='7':\r\n c2+=1 \r\nfor i in range(n>>1,n):\r\n if s[i]=='4':\r\n c3+=1 \r\n elif s[i]=='7':\r\n c4+=1 \r\nif c1+c2+c3+c4==n:\r\n if c1==c3 and c2==c4:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n = int(input()); s = input()\r\nprint('YES' if s.count('4')+s.count('7') == n and sum([int(x) for x in s[:(n//2)]]) == sum([int(x) for x in s[(n//2):]]) else 'NO')\r\n", "n1 = int(input())\r\nflag = 0\r\nx = input()\r\nfor i in x:\r\n if int(i) == 4 or int(i) == 7:\r\n flag+=1\r\nif flag < n1:\r\n print(\"NO\")\r\nelse:\r\n x1 = x[0:int(n1/2)]\r\n x2 = x[int(n1/2):]\r\n sum1 = 0\r\n sum2 = 0\r\n for i in x1:\r\n sum1+=int(i)\r\n for i in x2:\r\n sum2+=int(i)\r\n if sum1 == sum2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n ", "n=int(input())\r\nnumber=input()\r\nflag=0\r\nl_n=['4','7']\r\nfor i in number:\r\n if i not in l_n:\r\n flag=1\r\n break\r\n\r\nif flag==0:\r\n k=int(n/2)\r\n a=number[0:k]\r\n b=number[k:]\r\n a_s=0\r\n b_s=0\r\n for i in a:\r\n a_s+=eval(i)\r\n for i in b:\r\n b_s+=eval(i)\r\n if a_s!=b_s:\r\n flag=1\r\n\r\nif flag==1:\r\n print('NO')\r\nelse:\r\n print('YES')", "def fun(a):\r\n for i in a:\r\n if i==\"4\" or i==\"7\":\r\n pass\r\n else:\r\n return False\r\n else:\r\n return True\r\n \r\nn=int(input())\r\na=input()\r\ns=a[:n//2]\r\nt=a[n//2:]\r\nc=0\r\np=0\r\nfor i in s:\r\n c +=int(i)\r\nfor i in t:\r\n p +=int(i)\r\nif p==c and fun(a):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\ns = input()\n\nok = 1\nfor c in s:\n\tif c != '4' and c != '7':\n\t\tok = 0\n\nbigsum = 0\nfor i in range(n):\n\tbigsum += int(s[i])\n\nsmall = 0\nfor i in range(n // 2):\n\tsmall += int(s[i])\n\nif ok and small * 2 == bigsum:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n", "n = int(input())\r\ninp = input()\r\ns1 = 0\r\ns2 = 0\r\n\r\nfor i in range(n//2):\r\n s1 += int(inp[i])\r\n s2 += int(inp[n-i-1])\r\n\r\n if (inp[i] not in (\"4\", \"7\") or inp[n-i-1] not in (\"4\", \"7\")):\r\n print(\"NO\")\r\n break\r\nelse:\r\n if (s1 == s2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "n = int(input())\r\nticket = input()\r\nlucky = True\r\nif \"1\" in ticket or \"2\" in ticket or \"3\" in ticket or \"5\" in ticket or \"6\" in ticket or \"8\" in ticket or \"9\" in ticket or \"0\" in ticket:\r\n lucky = False\r\na = list()\r\nb = list()\r\na += ticket[:n // 2]\r\nb += ticket[n // 2:]\r\nfor i in range(len(a)):\r\n a[i] = int(a[i])\r\nfor i in range(len(b)):\r\n b[i] = int(b[i])\r\nif sum(a) != sum(b):\r\n lucky = False\r\nif lucky:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\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\tn=read_int()\r\n\ta=read()\r\n\tfor d in \"01235689\":\r\n\t\tif d in a:\r\n\t\t\tprint(\"NO\")\r\n\t\t\treturn\r\n\tif sum([ord(x) for x in a[:n//2]]) == sum([ord(x) for x in a[n//2:]]):\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")\r\n\r\nsolve()\r\n", "n = int(input())\r\nnumber = list(map(int, input()))\r\nif number.count(4) + number.count(7) == len(number) and sum(number[:len(number) // 2]) == sum(number[len(number) // 2:]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "N=int(input())\n\nx=list(input())\nk=False\nfor i in range(N):\n x[i]=int(x[i])\n if(x[i]!=7 and x[i]!=4):\n k=True\nif(k or sum(x[:N//2])!=sum(x[N//2:])):\n print(\"NO\")\nelse:\n print(\"YES\")\n\n\n", "n=int(input())\r\ns=str(input())\r\na=0\r\nfor i in range(n):\r\n\t# print(i,s[i],a)\r\n\tif s[i]==\"4\" or s[i]==\"7\":\r\n\t\ta=1\r\n\telse:\r\n\t\ta=0\r\n\t\tbreak\r\nx,y=0,0\r\nif a==1:\r\n\tfor i in range(n//2):\r\n\t\t# print(i,s[i])\r\n\t\tx+=int(s[i])\r\n\t\t# print(x)\r\n\tfor j in range(n//2,n):\r\n\t\t# print(j,s[j])\r\n\t\ty+=int(s[j])\r\n\t\t# print(y)\r\n\tif x==y:\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")\r\nelse:\r\n\tprint(\"NO\")\r\n", "__copyright__ = ''\r\n__author__ = 'Son-Huy TRAN'\r\n__email__ = \"[email protected]\"\r\n__doc__ = ''\r\n__version__ = '1.0'\r\n\r\n\r\ndef sum_digit(string: str) -> int:\r\n return sum(int(char) for char in string)\r\n\r\n\r\ndef is_lucky_ticket(n: int, ticket: str) -> bool:\r\n if (ticket.count('4') + ticket.count('7')) != n:\r\n return False\r\n\r\n return sum_digit(ticket[:n // 2]) == sum_digit(ticket[n // 2:])\r\n\r\n\r\ndef main() -> int:\r\n n = int(input())\r\n ticket = input()\r\n\r\n print('YES' if is_lucky_ticket(n, ticket) else 'NO')\r\n return 0\r\n\r\n\r\nif __name__ == '__main__':\r\n exit(main())", "def ticket():\r\n N = int(input())\r\n number = input()\r\n sum1 = 0\r\n sum2 = 0\r\n i = 0\r\n while i < N:\r\n if number[i] == \"4\" or number[i] == \"7\":\r\n if i < N//2:\r\n sum1 += int(number[i])\r\n \r\n else:\r\n sum2 += int(number[i])\r\n i += 1 \r\n else:\r\n return False\r\n if sum1 == sum2:\r\n return True\r\n return False \r\n \r\n \r\nif ticket():\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nnum = input() \r\nflag = True\r\nfor i in num : \r\n if i not in [\"4\" , \"7\"] : \r\n flag = False\r\n break \r\nif flag :\r\n s1 = sum([int(i) for i in num[ : (n//2) ] ])\r\n s2 = sum([int(i) for i in num[(n//2) :] ])\r\nif flag and s1 == s2 : \r\n print('YES')\r\nelse : \r\n print(\"NO\")", "n = int(input())\r\ns = input()\r\nprint(\"YES\" if s.replace('7', '').replace('4', '') == '' and sum(map(int, s[:n // 2])) == sum(\r\n map(int, s[n // 2:])) else \"NO\")", "# ///==========Libraries, Constants and Functions=============///\r\n#mk_Raghav\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\ndef int1():return int(input())\r\n# ///==========MAIN=============///\r\n\r\nk=int1()\r\nl=list(input())\r\nx=k//2\r\nl1=l[:x]\r\nl2=l[x:k]\r\nk=0\r\nm=0\r\nz=0\r\nfor i in l1:\r\n if i=='7' or i=='4':\r\n k=k+int(i)\r\n m=m+1\r\n\r\n else:\r\n z=1\r\n\r\n break\r\nk1=0\r\nn=0\r\nz1=0\r\nfor i in l2:\r\n if i=='7' or i=='4':\r\n k1=k1+int(i)\r\n n=n+1\r\n\r\n else:\r\n z1=1\r\n\r\n break\r\n\r\nif z==1 or z1==1:\r\n print('NO')\r\nif m==x and n==x:\r\n if k==k1:\r\n print('YES')\r\n else:\r\n print('NO')\r\n", "def input_ints():\r\n return list(map(int, input().split()))\r\n\r\ndef solve():\r\n n = int(input())\r\n s = input()\r\n if s.count('4') + s.count('7') == n and s[:n//2].count('4') == s[n//2:].count('4'):\r\n print('YES')\r\n else:\r\n print('NO')\r\n\r\nif __name__ == '__main__':\r\n solve()\r\n", "from collections import Counter\r\nn=int(input())\r\na=input()\r\np=Counter(a)\r\nif (p['4'] + p['7']) != n:\r\n print('NO')\r\nelse:\r\n s = 0\r\n s0 = 0\r\n for i in range(n):\r\n if i < (n // 2):\r\n s += int(a[i])\r\n else:\r\n s0 += int(a[i])\r\n if s == s0:\r\n print('YES')\r\n else:\r\n print('NO')", "n = int(input())\r\nnumber = input()\r\n\r\nbool = True\r\n\r\nfor i in range(n):\r\n if number[i]!='4' and number[i]!='7':\r\n bool = False\r\n break\r\n\r\n\r\n \r\nif bool == True:\r\n first_half = list(number[:n//2])\r\n sec_half = list(number[n//2:])\r\n sum1, sum2 = 0, 0\r\n \r\n for item in first_half:\r\n sum1 += int(item)\r\n for item2 in sec_half:\r\n sum2 += int(item2)\r\n\r\nif bool == True and sum1 == sum2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n ", "\r\n\r\ndef is_lucky_ticket(n, t_s):\r\n diff = 0\r\n n //= 2\r\n for i in range(n):\r\n l_num, r_num = int(t_s[i]), int(t_s[i + n])\r\n if l_num not in [4, 7] or r_num not in [4, 7]:\r\n return 'NO'\r\n diff += l_num - r_num\r\n\r\n if diff == 0:\r\n return 'YES'\r\n else:\r\n return 'NO'\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n t_s = input()\r\n print(is_lucky_ticket(n, t_s))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\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\n\r\n\r\nn=iinput()\r\na=list(input())\r\n\r\nfour=a.count(\"4\")\r\nseven=a.count(\"7\")\r\nhalf=0\r\nhalf1=0\r\nif(four+seven==n):\r\n for i in range(n//2):\r\n half+=int(a[i])\r\n for i in range(n//2,n):\r\n half1+=int(a[i])\r\n if(half1==half):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "a = int(input())\r\nb = input()\r\nstatus = \"YES\"\r\nfor i in b:\r\n if i != \"4\" and i != \"7\":\r\n status = \"NO\"\r\n break\r\nif status == \"NO\":\r\n print(status)\r\nelse:\r\n if a == 2:\r\n if b[0] == b[1]:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n else:\r\n count1 = 0\r\n count2 = 0\r\n for i in range(a // 2):\r\n count1 += int(b[i])\r\n count2 += int(b[i + a // 2])\r\n if count1 == count2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n", "n=int(input())\r\na=list(map(int,input()))\r\nr=n//2\r\nif a.count(4)+a.count(7)==n and sum(a[:r])==sum(a[r:]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "\ncount = int(input())\nnumber = list(map(int, input()))\n\ndef check_number(count, number):\n left_sum, right_sum = 0, 0\n for idx, digit in enumerate(number):\n if idx + 1 <= count // 2:\n left_sum += digit\n else:\n right_sum += digit\n \n if digit != 4 and digit != 7:\n return \"NO\"\n \n if left_sum == right_sum:\n return \"YES\"\n return \"NO\"\n\nprint(check_number(count, number))\n", "n=int(input())\r\nS = input()\r\n\r\nif n!= S.count('7') + S.count('4') or n %2 == 1:\r\n print(\"NO\")\r\nelse:\r\n H = list(map(int,S[:n//2]))\r\n T = list(map(int,S[n//2:]))\r\n if sum(H) != sum(T):\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n ", "n=int(input())\r\nl=list(map(int,list(input())))\r\na,b=0,0\r\nflag=0\r\nfor i in range(n):\r\n\tif(i<n//2):\r\n\t\tif(l[i]==4 or l[i]==7):\r\n\t\t\ta+=l[i]\r\n\t\telse:\r\n\t\t\tflag=1\r\n\t\t\tbreak\r\n\telse:\r\n\t\tif(l[i]==4 or l[i]==7):\r\n\t\t\tb+=l[i]\r\n\t\telse:\r\n\t\t\tflag=1\r\n\t\t\tbreak\r\nif(flag==1):\r\n\tprint(\"NO\")\r\nelse:\r\n\tif(a==b):\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")", "# coding=utf-8\r\n\r\nif __name__ == '__main__':\r\n\tn = int(input())\r\n\tline = str(input())\r\n\tline_0 = list(line[:n // 2])\r\n\tline_1 = list(line[n // 2:])\r\n\tline_0.sort()\r\n\tline_1.sort()\r\n\tif line_0 == line_1:\r\n\t\tif '0' in line_0 or '1' in line_0 or '2' in line_0 or '3' in line_0 or '5' in line_0 or '6' in line_0 or '8' in line_0 or '9' in line_0:\r\n\t\t\tprint('NO')\r\n\t\telse:\r\n\t\t\tprint('YES')\r\n\telse:\r\n\t\tprint('NO')\r\n", "while True:\r\n try:\r\n n=int(input())\r\n number=int(input())\r\n number_string=[]\r\n for i in range(n):\r\n val=number%10\r\n number=number//10\r\n number_string.append(val)\r\n four1=0\r\n seven1=0\r\n four2 = 0\r\n seven2 = 0\r\n sum1=0\r\n sum2=0\r\n for i in range(len(number_string)):\r\n if i<n//2:\r\n if number_string[i]==4:\r\n four1+=1\r\n sum1+=number_string[i]\r\n elif number_string[i]==7:\r\n seven1+=1\r\n sum1 += number_string[i]\r\n else:\r\n if number_string[i]==4:\r\n four2+=1\r\n sum2 += number_string[i]\r\n elif number_string[i]==7:\r\n seven2+=1\r\n sum2 += number_string[i]\r\n\r\n count=four2+four1+seven2+seven1\r\n if count!=n:\r\n print(\"NO\")\r\n else:\r\n if sum1==sum2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n except:\r\n break", "a=int(input())\r\nb=int(input())\r\nx=[]\r\ny=[]\r\nz=a\r\nt=0\r\nr=0\r\nfor i in range(a//2):\r\n c=b//10**(a-1)\r\n x.append(c)\r\n d=b-c*10**(a-1)\r\n a-=1\r\n b=d\r\nfor i in range(z//2):\r\n c=b//10**(a-1)\r\n y.append(c)\r\n d=b-c*10**(a-1)\r\n a-=1\r\n b=d\r\nfor i in x:\r\n if i==4 or i==7:\r\n t=1\r\n else:\r\n t=0\r\n break \r\n for i in y:\r\n if i==4 or i==7:\r\n r=1\r\n else:\r\n r=0\r\n break\r\nif t==1 and r==1 and sum(x)==sum(y):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\ns = input()\nres, res2 = 0, 0\n\nfor i in s:\n if(i != '4' and i != '7'):\n print(\"NO\")\n exit(0)\n\nfor i in range(n // 2):\n res += int(s[i])\n res2 += int(s[-i - 1])\n\nprint(\"YES\" if res == res2 else \"NO\")\n", "l = int(input())\r\nn = list(map(int, input()))\r\nfor i in n:\r\n if i != 7 and i != 4:\r\n print(\"NO\")\r\n exit()\r\nif sum(n[0:l//2]) == sum(n[l//2:l]):\r\n print(\"YES\")\r\n exit()\r\nelse:\r\n print(\"NO\")\r\n", "input()\r\nnums = input()\r\nleft = right = 0\r\nfor i in range(len(nums)//2):\r\n left += int(nums[i])\r\n right+= int(nums[len(nums)-1-i])\r\n if (nums[i] != '4' and nums[i] != '7') or (nums[len(nums)-1-i] != '4' and nums[len(nums)-1-i] != '7'):\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\") if left == right else print(\"NO\")\r\n", "n=int(input())\r\narr=list(str(input()))\r\nif arr.count(\"4\")+arr.count(\"7\")<n:\r\n print(\"NO\")\r\nelse:\r\n mid=int(n/2)\r\n left=arr[:mid]\r\n right=arr[mid:]\r\n if left.count(\"7\")==right.count(\"7\"):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "import math\r\ndef is_prime(n):\r\n if n==1:\r\n return False\r\n for i in range(2,int(math.sqrt(n))+1):\r\n if n%i==0:\r\n return False\r\n return True\r\ndef inp(n):\r\n ls=[]\r\n for i in range(n):\r\n ls.append(int(input()))\r\n return ls\r\nt=int(input())\r\ns=input()\r\nh1=[]\r\nh2=[]\r\nfor i in range(t//2):\r\n if (s[i]!='7' and s[i]!='4') or (s[i+t//2]!='7' and s[i+t//2]!='4'):\r\n print(\"NO\")\r\n exit(0)\r\n h1.append(int(s[i]))\r\n h2.append(int(s[i+t//2]))\r\nif sum(h1)==sum(h2) and sum(h1)>0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n\r\n\r\n\r\n", "n=int(input())\r\ns=input()\r\nc=0\r\nfor i in s:\r\n if i=='4' or i=='7':\r\n continue\r\n else:\r\n c=1\r\n break\r\nif c==0:\r\n sum1,sum2=0,0\r\n s1=list(s[:n//2])\r\n s2=list(s[n//2:n])\r\n for i in s1:\r\n sum1+=int(i)\r\n\r\n for i in s2:\r\n sum2+=int(i)\r\n\r\n if sum1==sum2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "#1183A\r\n# def sum_of_digits(num):\r\n# return sum(int(digit) for digit in str(num))\r\n# num = input()\r\n# if sum_of_digits(num) %4 == 0:\r\n# print(num)\r\n# else:\r\n# while (sum_of_digits(num) %4 != 0):\r\n# num = int(num) + 1\r\n# print(num)\r\n\r\n#1005A\r\n# num = int(input())\r\n# arr = [i for i in input().split()][:num]\r\n# sum = 0\r\n# a = []\r\n# for i in range(len(arr)):\r\n# if arr[i] == '1':\r\n# sum = sum + 1\r\n# a.append(i)\r\n# # a.append(arr[i - 1])\r\n# print(a)\r\n# for i in range(len(a)-1):\r\n# x = a[i] + a[i+1] - 1\r\n# print(x)\r\n# print(*arr[x], sep = \" \", end=\" \")\r\n# print(arr[len(arr)-1])\r\n\r\n#1118A\r\n# num = int(input())\r\n# arr = [[int(i) for i in input().split()][:3] for y in range(num)]\r\n# for i in range(num):\r\n# flag = False\r\n# sum = 0\r\n# if(arr[i][0]%2==0):\r\n# flag = True\r\n# per = float(arr[i][2] / 2.0)\r\n# if arr[i][1] >= arr[i][2]:\r\n# if flag:\r\n# sum = (arr[i][0] / 2) * arr[i][2]\r\n# else:\r\n# sum = ((arr[i][0] - 1)/ 2) * arr[i][2] + arr[i][1]\r\n# else:\r\n# sum = arr[i][0] * arr[i][1]\r\n# print(int(sum))\r\n\r\n\r\n#1139A\r\n# num = int(input())\r\n# arr = [int(i) for i in input()][:num]\r\n# sum = 0\r\n# for i in range(num):\r\n# if arr[i] % 2 == 0:\r\n# sum = sum + (1*(i+1))\r\n# print(sum)\r\n\r\n\r\n#401A\r\n# import math\r\n#\r\n# x, y = input().split()\r\n# x = int(x)\r\n# y = int(y)\r\n# arr = [int(i) for i in input().split()][:x]\r\n# for i in range(x):\r\n# arr[i] = int(float(arr[i]))\r\n# if sum(arr) == 0:\r\n# print(\"0\")\r\n# else:\r\n# if abs(y) >= abs(sum(arr)):\r\n# print(\"1\")\r\n# else:\r\n# z = math.ceil(abs(sum(arr)) / abs(y))\r\n# print(z)\r\n\r\n\r\n#946A\r\n# n = int(input())\r\n# arr = [int(i) for i in input().split()][:n]\r\n# b = []\r\n# c = []\r\n# for i in range(n):\r\n# if arr[i] >= 0:\r\n# b.append(arr[i])\r\n# else:\r\n# c.append(arr[i])\r\n# s1 = sum(b)\r\n# s2 = sum(c)\r\n# print(s1-s2)\r\n\r\n#912A\r\n# arr1 = [int(i) for i in input().split()][:2]\r\n# arr2 = [int(i) for i in input().split()][:3]\r\n# need = 0\r\n# if 2*arr2[0] <= arr1[0]:\r\n# arr1[0] = arr1[0] - 2*arr2[0]\r\n# else:\r\n# n = 2*arr2[0] - arr1[0]\r\n# need = n\r\n# arr1[0] = 0\r\n# if arr2[1] <= arr1[0] and arr2[1] <= arr1[1]:\r\n# arr1[0] = arr1[0] - arr2[1]\r\n# arr1[1] = arr1[1] - arr2[1]\r\n# elif (arr2[1] <= arr1[0] and arr2[1] >= arr1[1]):\r\n# arr1[0] = arr1[0] - arr2[1]\r\n# n = arr2[1] - arr1[1]\r\n# need = need + n\r\n# arr1[1] = 0\r\n# elif (arr2[1] >= arr1[0] and arr2[1] <= arr1[1]):\r\n# arr1[1] = arr1[1] - arr2[1]\r\n# n = arr2[1] - arr1[0]\r\n# need = need + n\r\n# arr1[0] = 0\r\n# else:\r\n# n = (arr2[1] - arr1[0]) + (arr2[1] - arr1[1])\r\n# need = need + n\r\n# arr1[1] = 0\r\n# arr1[0] = 0\r\n# if 3*arr2[2] <= arr1[1]:\r\n# arr1[1] = arr1[1] - 3*arr2[2]\r\n# else:\r\n# n = 3*arr2[2] - arr1[1]\r\n# need = need + n\r\n# arr1[1] = 0\r\n# print(need)\r\n\r\n\r\n#146A\r\nnum = int(input())\r\narr = [int(i) for i in input()][:num]\r\ny = 0\r\nfor i in range(num):\r\n if arr[i] == 4 or arr[i] == 7:\r\n y = y+1\r\nif(y==num):\r\n y=1\r\nelse:\r\n y=0\r\nfour1 = 0\r\nseven1 = 0\r\nfor i in range(int(num/2)):\r\n if arr[i] == 4:\r\n four1 = four1 + 1\r\n if arr[i] == 7:\r\n seven1 = seven1 + 1\r\nfour2 = 0\r\nseven2 = 0\r\nfor i in range(int(num/2),num):\r\n if arr[i] == 4:\r\n four2 = four2 + 1\r\n if arr[i] == 7:\r\n seven2 = seven2 + 1\r\n# print(four1, four2, seven1, seven2)\r\nif (four1 == four2 and seven1==seven2 and y==1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "x=int(input())\r\na=list(map(int,list(input())))\r\nb=set(a)\r\nif len(b)==1 and (4 in b or 7 in b):print(\"YES\")\r\nelif len(b)==2 and 4 in b and 7 in b and sum(a[:x//2])==sum(a[x//2:]):print(\"YES\")\r\nelse:print(\"NO\")\r\n\t", "n = int(input())\r\nnumber = input()\r\nif len(number) == sum(1 for x in number if x in ['4', '7']):\r\n if sum(int(x) for x in number[:n//2]) == sum(int(x) for x in number[n//2:]):\r\n print('YES')\r\n else: print('NO')\r\nelse:\r\n print('NO')", "input()\r\na = input()\r\nd = []\r\ng = []\r\nfor x in range(0,len(a)):\r\n c = int(a[x])\r\n d.append(c)\r\nn = len(d) \r\n\r\nfor i in range(0,len(d)):\r\n if(d[i] == 4 or d[i] == 7):\r\n g.append(\"YES\")\r\n else:\r\n g.append(\"NO\")\r\nq = 0\r\nfor r in g:\r\n if(r == \"NO\"):\r\n q = q + 1\r\n\r\nif(q != 0):\r\n print(\"NO\")\r\nelif(q==0): \r\n w = d[0:n//2]\r\n z = d[n//2:n]\r\n k = 0\r\n l = 0\r\n for o in w:\r\n k = k + o\r\n for p in z:\r\n l = l + p\r\n if(k == l):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n \r\n \r\n\r\n", "def main() -> None:\r\n n = int(input())\r\n s = input()\r\n print('YES' if sum([ord(c) for c in s[: n // 2]]) == sum([ord(c) for c in s[n // 2:]]) and s.count('4') + s.count('7') == n else 'NO')\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n, s = int(input()), input()\r\nsum1, sum2, luck = 0, 0, ['4', '7']\r\nfor i in range(n):\r\n if (s[i] not in luck):\r\n exit(print('NO'))\r\n elif (i < n / 2):\r\n sum1 += int(s[i])\r\n else:\r\n sum2 += int(s[i])\r\nprint('YNEOS'[(sum1!=sum2)::2])\r\n", "n=int(input())\r\ns=input()\r\na=0\r\nb=0\r\nsa=0\r\nsb=0\r\nfor i in range(n):\r\n if(s[i]!='4' and s[i]!='7'):\r\n a=1\r\n break\r\n else:\r\n if(i<(n/2)):\r\n sa=sa+ord(s[i])-48\r\n else:\r\n sb=sb+ord(s[i])-48 \r\nif(sa!=sb):\r\n b=1\r\nif(a==0 and b==0):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n ", "n = int(input())\r\nt = input()\r\nflag = 0\r\nr1 = t[:n//2].count(\"4\")\r\nr2 = t[:n//2].count(\"7\")\r\nr3 = t[n//2:].count(\"4\")\r\nr4 = t[n//2:].count(\"7\")\r\nif r1 + r2 != n//2 or r3 + r4 != n//2 or r1 != r3:\r\n\tprint(\"NO\")\r\nelse:\r\n\tprint(\"YES\")\r\n", "reg=int(input())\r\nst=input()\r\ny=len(st)\r\ns1=st[0:len(st)//2]\r\ns2=st[len(st)//2:]\r\nsum1=0\r\nsum2=0\r\ncounter1=0\r\ncounter2=0\r\nfor i in range(0,len(s1)):\r\n if s1[i]==\"4\" or s1[i]==\"7\":\r\n counter1+=1\r\n if s2[i]==\"4\" or s2[i]==\"7\":\r\n counter2+=1\r\n sum1+=int(s1[i])\r\n sum2+=int(s2[i])\r\nif sum1==sum2 and counter1+counter2==len(st) and counter1==counter2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "l=int(input())\r\nn = input()\r\ndef solve(num):\r\n return all(digit in '47' for digit in num)\r\nif solve(n):\r\n c=l//2\r\n f = n[:c]\r\n s = n[c:]\r\n if sum(map(int,f))==sum(map(int,s)):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nticket = input()\r\n\r\n# Count the number of 4s and 7s in the first half of the ticket\r\ncount_first_half_4s = ticket[:n//2].count('4')\r\ncount_first_half_7s = ticket[:n//2].count('7')\r\n\r\n# Count the number of 4s and 7s in the second half of the ticket\r\ncount_second_half_4s = ticket[n//2:].count('4')\r\ncount_second_half_7s = ticket[n//2:].count('7')\r\n\r\n# Check if the ticket is lucky\r\nif count_first_half_4s == count_second_half_4s and count_first_half_7s == count_second_half_7s and set(ticket) <= set('47'):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "t=int(input())\r\nn=int(input())\r\nl=[i for i in str(n) if i!='4' and i!='7']\r\nx=str(n)\r\ns1=list(x[:t//2])\r\ns2=list(x[t//2:])\r\ns1=map(int,s1)\r\ns2=map(int,s2)\r\nif len(l)==0 and sum(s1)==sum(s2):\r\n print('YES')\r\nelse:\r\n print('NO')", "n=int(input())\nl=list(input())\ns=list(set(l))\np=0\nfor i in s:\n if i!=\"4\" and i!=\"7\":\n p=-1\n break\nif p==0:\n a=sorted(l[:n//2])\n b=sorted(l[n//2:])\n if a==b:\n print(\"YES\")\n else:\n print(\"NO\")\nelse:\n print(\"NO\")\n", "n = int(input())\r\nli = list(input())\r\ns0, s1 = 0, 0\r\nflag = False\r\nfor i in range(n//2):\r\n if li[i] not in [\"4\", \"7\"]:\r\n flag = True\r\n s0 += int(li[i])\r\n\r\nfor i in range(n//2):\r\n if li[n//2 + i] not in [\"4\", \"7\"]:\r\n flag = True\r\n s1 += int(li[n//2 + i])\r\n\r\nif flag:\r\n print(\"NO\")\r\nelif s0 == s1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a=int(input())\r\nn=int(input())\r\nd=n\r\nsum=0\r\ncount=0\r\nc=a//2\r\ni=1\r\nwhile(i<=c):\r\n n=n//10\r\n e=d%10\r\n if e==4 or e==7:\r\n count+=1\r\n sum=sum+e\r\n d=n\r\n i=i+1\r\nj=1\r\nsum1=0\r\nwhile(j<=c):\r\n n=n//10\r\n e=d%10\r\n if e==4 or e==7:\r\n count+=1\r\n sum1=sum1+e\r\n d=n\r\n j=j+1\r\nif(sum==sum1 and count==a):\r\n print('YES')\r\nelse:\r\n print('NO')", "n=int(input())\r\ns=input()\r\nc4=s.count('4')\r\nc7=s.count('7')\r\nif c4+c7==n:\r\n l=[int(i) for i in s]\r\n if sum(l[:n//2])==sum(l[n//2:]):\r\n print('YES')\r\n exit(0)\r\n else:\r\n print('NO')\r\n exit(0)\r\nelse:\r\n print('NO')", "n = int(input())\r\nticket = input()\r\nis_lucky = all(c in '47' for c in ticket)\r\nif is_lucky:\r\n sum1 = sum(int(c) for c in ticket[:n//2])\r\n sum2 = sum(int(c) for c in ticket[n//2:])\r\n if sum1 == sum2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\nnum = input()\r\n \r\nleft = num[:int(n/2)]\r\nright = num[int(n/2):]\r\n \r\ndef check(st):\r\n for i in st:\r\n if i not in ['4', '7']:\r\n return False\r\n return True\r\n \r\nif check(num):\r\n if sum(list(map(int, list(left)))) == sum(list(map(int, list(right)))):\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')", "n = int(input())\r\nnum = list(map(int,input()))\r\n\r\n\r\n# check that the first half does not equal the sum of digits in the second half\r\nif sum(num[:int(n/2)]) == sum(num[int(n/2):]):\r\n condition1 = True\r\nelse:\r\n condition1 = False\r\n\r\n\r\n# check that it's lucky number\r\nfor i in num:\r\n if i == 4 or i == 7:\r\n condition2 = True\r\n pass\r\n else:\r\n condition2 = False\r\n break\r\n\r\n\r\nif condition1 and condition2:\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\")", "n=int(input())\r\nxs=input()\r\nv=True\r\na=0\r\nb=0\r\nfor i in range(n//2):\r\n a+=int(xs[i])\r\n if xs[i] not in ['4','7']:\r\n v=False\r\n \r\nfor i in range(n//2,n):\r\n b+=int(xs[i])\r\n if xs[i] not in ['4','7']:\r\n v=False\r\n\r\nif v and a==b:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n\r\n \r\n \r\n", "n = int(input())\r\nb = input()\r\n\r\ny = b.count(\"7\")\r\nt = b.count(\"4\")\r\n\r\nif y + t == n: \r\n if sorted(b[:n//2]) == sorted(b[n//2:]):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse: \r\n print(\"NO\")\r\n\r\n", "n=int(input())\r\na=[int(x) for x in input()]\r\ntong=0\r\ncheckk=0\r\nfor b in range(0, int(len(a)/2)):\r\n tong+=a[b]\r\n tong-=a[len(a)-b-1]\r\n if a[b]!=4 and a[b]!=7 or a[len(a)-b-1]!=4 and a[len(a)-b-1]!=7:\r\n checkk+=1\r\n break\r\nif checkk==1 or tong!=0:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "x = int(input())\r\nn = input()\r\npivot = x//2\r\nsuma1 = 0\r\nsuma2 = 0\r\nbol = True\r\nfor i in range(x):\r\n if(n[i]!='4' and n[i]!= '7'):\r\n print(\"NO\")\r\n bol = False\r\n break\r\n if(i<pivot):\r\n suma1+=int(n[i])\r\n else: suma2+= int(n[i])\r\nif(bol):\r\n if(suma1 == suma2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "def solve(s):\n l = 0\n r = 0\n for i, v in enumerate(s):\n if v != '7' and v != '4':\n return \"NO\"\n if i < len(s)//2:\n l += int(v)\n else:\n r += int(v)\n return \"YES\" if l == r else \"NO\"\n \n \n\n\ndef main():\n n = int(input())\n s = input()\n print(solve(s))\n\nmain()\n", "n=int(input())\r\ns=input()\r\ns1=0\r\ns2=0\r\nfor i in range(n//2):\r\n if s[i]!='7' and s[i]!='4':\r\n import sys\r\n print ('NO')\r\n sys.exit(0)\r\n s1+=ord(s[i])-48\r\nfor i in range(n//2,n):\r\n if s[i]!='7' and s[i]!='4':\r\n import sys\r\n print ('NO')\r\n sys.exit(0) \r\n s2+=ord(s[i])-48\r\nif s1==s2:\r\n print ('YES')\r\nelse:\r\n print ('NO')\r\n", "def check_1(strin):\r\n return strin.count('4') + strin.count('7') == len(strin)\r\n\r\ndef check_2(strin):\r\n first = [int(j) for j in list(strin[:len(strin) // 2])]\r\n second = [int(h) for h in list(strin[len(strin) // 2:])]\r\n return sum(first) == sum(second)\r\n\r\ndef main(thing):\r\n if check_1(thing) and check_2(thing):\r\n print('YES')\r\n else:\r\n print('NO')\r\n\r\n\r\ninput()\r\nn = input()\r\nmain(n)\r\n", "n = int(input())\r\ns = input()\r\n\r\nif s.count('4') + s.count('7') != n: print(\"NO\")\r\nelse:\r\n a = sum(list(map(int , list(s[:n//2]))))\r\n b = sum(list(map(int , list(s[n//2:]))))\r\n\r\n # print(a,b)\r\n\r\n if a==b: print(\"YES\")\r\n else: print(\"NO\")", "n = int(input())\nnum = int(input())\ndigits = []\nfor x in range(n):\n digit = num%10\n num = num//10\n if (digit != 4) and (digit != 7):\n print(\"NO\")\n quit()\n digits.append(digit)\nsum_half1 = 0\nsum_half2 = 0\ncounter = 0\n\nwhile counter <= ((n/2) - 1):\n sum_half1 += digits[counter]\n counter += 1\nwhile counter < n:\n sum_half2 += digits[counter]\n counter += 1\nif sum_half1 == sum_half2:\n print(\"YES\")\nelse:\n print(\"NO\")\n ", "n = int(input())\r\nticket = input()\r\n\r\nfor c in ticket:\r\n if c != '4' and c != '7':\r\n print('NO')\r\n exit()\r\n\r\nfirst_half = ticket[:n//2]\r\nsecond_half = ticket[n//2:]\r\n\r\nif sum(map(int, first_half)) == sum(map(int, second_half)):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "thelength=int(input())\r\nnum=input()\r\nif num.count('4') + num.count('7')==len(num) and num[0:len(num)//2].count('7')==num[len(num)//2:].count('7') and num[0:len(num)//2].count('4')==num[len(num)//2:].count('4') :\r\n print('YES')\r\nelse:\r\n print('NO')", "def main():\r\n n=int(input())\r\n a=int(input())\r\n a=str(a)\r\n if(('1' not in a) and ('2' not in a) and ('3' not in a) and('5' not in a) and ('6' not in a) and ('8' not in a) and ('9' not in a) and ('0' not in a)):\r\n cal(a,n)\r\n else:\r\n print(\"NO\")\r\ndef cal(a,n):\r\n l=n//2\r\n first=0\r\n last=0\r\n for i in range(0,l):\r\n first+=int(a[i])\r\n for j in range(l,len(a)):\r\n last+=int(a[j])\r\n if(first==last):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nmain()", "n = int(input())\r\nx = list(map(int, input()))\r\nif x.count(7) + x.count(4) == n and sum(x[:n//2]) == sum(x)//2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\ns=input()\r\nflag=False\r\nfor i in s:\r\n if(i not in ['4','7']):\r\n flag=True\r\n break\r\nif(flag):\r\n print('NO')\r\nelse:\r\n s1,s2=0,0\r\n for i in range(0,(n//2)):\r\n s1+=int(s[i])\r\n for i in range((n//2),n):\r\n s2+=int(s[i])\r\n if(s1==s2):\r\n print('YES')\r\n else:\r\n print('NO')\r\n", "from collections import Counter\r\ndlug = int(input())\r\nliczba = list(input())\r\nconter = Counter(liczba)\r\nif conter[\"7\"] + conter[\"4\"] != dlug:\r\n print(\"NO\")\r\nelse:\r\n p_pol, d_pol = 0,0\r\n for x in liczba[:dlug // 2]:\r\n p_pol += int(x)\r\n for x in liczba[dlug // 2:]:\r\n d_pol += int(x)\r\n if p_pol == d_pol:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "n = int(input())\r\na = input()\r\nc1, c2 = 0, 0\r\nfor i in range(0, n//2): c1 += int(a[i])\r\nfor i in range(n//2, n): c2 += int(a[i])\r\nif a.count('4') + a.count('7') != n:\r\n print(\"NO\")\r\nelif c1 != c2:\r\n print('NO')\r\nelse:\r\n print('YES')", "n = int(input())\r\nticket_number = input()\r\nfor digit in ticket_number:\r\n if digit != '4' and digit != '7':\r\n print(\"NO\")\r\n exit()\r\n\r\n\r\nfirst_half = ticket_number[:n//2]\r\nsecond_half = ticket_number[n//2:]\r\nif sum(int(d) for d in first_half) == sum(int(d) for d in second_half):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "\n\nn = int(input())\nstring = str(input())\nif((string.count('7') + string.count('4')) != n):\n print('NO')\nelse:\n arr = [int(i) for i in string[:n // 2]]\n arr1 = [int(i) for i in string[n // 2:]]\n\n\n if(sum(arr) == sum(arr1)): print('YES')\n else: print('NO')", "n = int(input())\r\ns = input()\r\nif s.count('4') + s.count('7') != n:\r\n\tprint('NO')\r\n\texit()\r\nsum1 = 0\r\nind = 0\r\nwhile ind < n // 2:\r\n\tsum1 += int(s[ind])\r\n\tind += 1\r\nwhile ind < n:\r\n\tsum1 -= int(s[ind])\r\n\tind += 1\r\nif sum1 == 0:\r\n\tprint('YES')\r\nelse:\r\n\tprint('NO')", "'''\r\n Auther: ghoshashis545 Ashis Ghosh\r\n College: jalpaiguri Govt Enggineering College\r\n\r\n'''\r\nfrom os import path\r\nfrom io import BytesIO, IOBase\r\nimport sys\r\nfrom heapq import heappush,heappop\r\nfrom functools import cmp_to_key as ctk\r\nfrom collections import deque,Counter,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().rstrip()\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('0')\r\n\r\nfile = 1\r\ndef ceil(a,b):\r\n return (a+b-1)//b\r\n\r\n# write fastio for getting fastio template.\r\n \r\n\r\n\r\n\r\ndef solve():\r\n\r\n\r\n # for _ in range(ii()):\r\n \r\n n = ii()\r\n s = list(si())\r\n c2 = s.count('4')\r\n c1 = s.count('7')\r\n s1,s2 =0,0\r\n for i in range(n):\r\n if i < (n//2):\r\n s1 += int(s[i])\r\n else:\r\n s2 += int(s[i])\r\n if s1==s2 and c1+c2==n:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\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('input.txt'):\r\n sys.stdin=open('input.txt', 'r')\r\n sys.stdout=open('output.txt','w')\r\n else:\r\n input=sys.stdin.readline\r\n solve()\r\n\r\n", "n=int(input())\r\nl=input()\r\nrsn=[\"0\",\"1\",\"2\",\"3\",\"5\",\"6\",\"8\",\"9\"]\r\nst=0\r\nfor jk in range(0,len(rsn)):\r\n if rsn[jk] in l:\r\n print(\"NO\")\r\n st=1\r\n break\r\nif st==0:\r\n l1=[]\r\n l2=[]\r\n for v in range(0,len(l)//2):\r\n l1.append(int(l[v]))\r\n for v in range(len(l)//2,len(l)):\r\n l2.append(int(l[v]))\r\n if sum(l1)==sum(l2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "n=int(input())\r\nL=str(input())\r\ns2=0\r\ns1=0\r\ntest=1\r\nfor s in L:\r\n if (s!='7' and s!='4'):\r\n print('NO')\r\n test=0\r\n break\r\nif (test): \r\n for j in range(len(L)//2):\r\n s1+=(ord(L[j])-ord('0'))\r\n s2+=(ord(L[-j-1])-ord('0'))\r\n if s1==s2:\r\n print('YES')\r\n else:\r\n print('NO')", "n=int(input())\r\na=input()\r\nk=0\r\nfor i in range(n):\r\n if a[i]!='4' and a[i]!='7':\r\n k+=1\r\nif k!=0:\r\n print('NO')\r\nelse:\r\n k=int(n/2)\r\n b=a[:k]\r\n c=a[-k:]\r\n s=0\r\n s1=0\r\n for i in range(k):\r\n s+=int(b[i])\r\n s1+=int(c[i])\r\n if s==s1:\r\n print('YES')\r\n else:\r\n print(\"NO\")", "n=int(input())\nx=input()\nlucky=1\nfor i in range(n):\n if x[i]!='4' and x[i]!='7':\n lucky=0\n break\nif lucky:\n fh=x[0:n//2]\n lh=x[(n//2):n]\n #print(fh)\n #print(lh)\n sumfh = 0\n sumlh = 0\n for i in fh:\n sumfh+=int(i)\n for i in lh:\n sumlh+=int(i)\n if sumfh==sumlh:\n print(\"YES\")\n else: print(\"NO\")\nelse:\n print(\"NO\")\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\ntnum = input()\r\ncounter = 0\r\nfor i in range(len(tnum)):\r\n if tnum[i] == '7' or tnum[i] == '4':\r\n continue\r\n else:\r\n counter +=1\r\nif counter == 0:\r\n s1 = 0\r\n s2 = 0\r\n for i in range(n//2):\r\n s1 += int(tnum[i])\r\n for i in range(n//2,n):\r\n s2 += int(tnum[i])\r\n print('YES' if s1 == s2 else 'NO')\r\nelse:\r\n print('NO')", "def f(n, s):\n for i in s:\n if(i not in ['4', '7']):\n print(\"NO\")\n return\n s1 = s[:n//2]\n s2 = s[n//2:]\n ans1 = 0\n ans2 = 0\n for i in range(n//2):\n ans1 += int(s1[i])\n ans2 += int(s2[i])\n if(ans1 == ans2):\n print(\"YES\")\n else:\n print(\"NO\")\nn = int(input())\ns = input()\nf(n, s)", "c=0\r\nl=['4','7']\r\nn=int(input())\r\ns=input()\r\ns1=0\r\ns2=0\r\nfor i in s:\r\n if i not in l:\r\n print(\"NO\")\r\n c=1\r\n break\r\nh=n//2\r\nfor j in range(0,h):\r\n s1=s1+int(s[j])\r\nfor k in range(h,n):\r\n s2=s2+int(s[k])\r\nif s1!=s2 and c!=1:\r\n print(\"NO\")\r\nelif c!=1:\r\n print(\"YES\")", "n=int(input())\nnumber=input()\nwhile True:\n if '1' in number or '2' in number or '3' in number or '5' in number or '6' in number or '8' in number or '9' in number or '0' in number:\n print('NO')\n break\n number = [int(i) for i in number]\n if sum(number[0:n//2])==sum(number[n//2:]):\n print('YES')\n break\n else:\n print('NO')\n break", "n = int(input())\ninp = input()\n\nls=0\nrs=0\nfor i in range(n):\n if inp[i] == '4' and i<n/2:\n ls+=4\n elif inp[i]=='7' and i<n/2:\n ls+=7\n elif inp[i] == '4' and i>=n/2:\n rs+=4\n elif inp[i] == '7' and i>=n/2:\n rs+=7\n else:\n ls=-1\n rs=-2\n break\nif ls==rs:\n print(\"YES\")\nelse:\n print(\"NO\")", "n = int(input())\ns = input()\na = b = 0\nfor i in range(n//2):\n a += int(s[i])\nfor i in range(n//2, n):\n b += int(s[i])\n\nif s.count('4') + s.count('7') == len(s) and a == b:\n print('YES')\nelse:\n print('NO')\n\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 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\ns = get_string()\r\nif set(s) <= {'4','7'}:\r\n if s[:n//2].count('4') == s[n//2:].count('4'):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n", "n=int(input())\r\ncn=list(map(int,input()))\r\nprint(['NO','YES'][cn.count(7) + cn.count(4) == n and sum(cn[:n//2]) == sum(cn)//2])", "n = int(input())\r\ns = input()\r\na = s[0:n//2]\r\nb = s[n//2:]\r\na1=0\r\nb1=0\r\nsum1=0\r\nsum2=0\r\nfor i in range(n//2):\r\n sum1+=int(a[i])\r\n sum2+=int(b[i])\r\n if(a[i] in ['4','7']):\r\n a1+=1\r\n if b[i] in ['4','7'] :\r\n b1+=1\r\nif sum1 == sum2 and a1 == n//2 and b1 == n//2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\nnum = input()\r\ncon = 0\r\n\r\nfor i in num:\r\n if i != '4' and i != '7':\r\n con = 0\r\n break\r\n con = 1\r\n\r\nif con == 1:\r\n reqSum = 0\r\n half = n // 2\r\n\r\n for i in range(half):\r\n reqSum += int(num[i])\r\n\r\n sum2 = 0\r\n for j in range(half, n):\r\n sum2 += int(num[j])\r\n\r\n if reqSum == sum2:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n print('NO')", "n = int(input())\r\na = input()\r\nb = n//2\r\none = a[0:b]\r\ntwo = a[b:n]\r\nc1 = 0\r\nc2 = 0\r\nfor i in range(b):\r\n if (one[i] == '4' or one[i] == '7') and (two[i] == '4' or two[i] == '7'):\r\n c1 += int(one[i])\r\n c2 += int(two[i])\r\n else:\r\n c1 = 0\r\n break\r\nif c1 == 0 :\r\n print('NO')\r\nelif c1 == c2:\r\n print('YES')\r\nelse:\r\n print('NO')", "def luck(n):\n\n sum1 = 0\n sum2 = 0\n\n for i in range (len(n)):\n if (n[i] != '4' and n[i] != '7'):\n print(\"NO\")\n return\n\n for i in range(len(n)):\n if (i < len(n)/2):\n sum1 += int(n[i])\n else:\n sum2 += int(n[i])\n\n if (sum1 == sum2):\n print(\"YES\")\n else:\n print(\"NO\")\n\n return\n\ninput()\nn = str(input())\nluck(n)\n\t\t\t \t \t\t \t \t\t \t \t\t\t \t\t", "n=int(input())\r\nnum=input()\r\ncount=1\r\nsum1=0\r\nsum2=0\r\nlucky=0\r\nfor i in num:\r\n if i in \"47\":\r\n lucky=lucky+1\r\n if count>=1 and count<=n/2:\r\n sum1=sum1+int(i)\r\n elif count>n/2 and count<=n:\r\n sum2=sum2+int(i)\r\n count=count+1\r\n\r\nif sum1==sum2 and lucky==n:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n", "n=int(input())\r\ns=input()\r\nif(s[0]=='0'):\r\n print(\"NO\")\r\nelse:\r\n a=len(s)//2\r\n b=int(s)\r\n y,z,c=0,0,0\r\n f=0\r\n while(b!=0):\r\n x=b%10\r\n if x!=4 and x!=7:\r\n f=1\r\n break\r\n c=c+1\r\n if(c<=a):\r\n y=y+x\r\n else:\r\n z=z+x\r\n b=b//10\r\n if(f==1 or y!=z):\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n ", "n=int(input())\r\ns=input()\r\ns1=s[0:n//2]\r\ns2=s[n//2:]\r\ndef lucky(s):\r\n for i in s:\r\n if(i!='4' and i!='7'):\r\n print(\"NO\")\r\n exit()\r\n return False\r\n return True\r\n\r\ndef sumi(s):\r\n a=0\r\n for i in s:\r\n a+=int(i)\r\n return a\r\nif(lucky(s1)):\r\n a = sumi(s1)\r\nif(lucky(s2)):\r\n b = sumi(s2)\r\n \r\nif(a==b):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "L = int(input()); N = input()\r\nl = not any([str(n) in N for n in \"01235689\"])\r\nd1 = sum([int(c) for c in N[:L//2]])\r\nd2 = sum([int(c) for c in N[L//2:]])\r\nprint(\"NYOE S\"[l and d1 == d2::2])", "n=int(input())\r\na=list(map(int,list(input())))\r\nprint([\"NO\",\"YES\"][a.count(7)+a.count(4)==n and sum(a[:n//2])==sum(a)//2])\r\n", "n = int(input())\r\ns = input()\r\ncount = 0\r\nfor i in range(len(s)):\r\n if s[i] == '4' or s[i] == '7':\r\n count += 1\r\nif count != len(s):\r\n print('NO')\r\nelse:\r\n ls = list(s)\r\n ls = [int(i) for i in ls]\r\n sum1 = sum(ls[0:int(len(ls) // 2)])\r\n sum2 = sum(ls[int(len(ls)//2)::])\r\n if sum1 == sum2:\r\n print('YES')\r\n else:\r\n print('NO')\r\n", "n = int(input())\ns = input().strip()\nk = n//2\nd = []\nfor i in s:\n di = int(i)\n if di == 4 or di == 7:\n d.append(di)\n else:\n print('NO')\n break\nelse:\n s1 = sum(d[:k])\n s2 = sum(d[k:])\n if s1 == s2:\n print('YES')\n else:\n print('NO')\n", "def main():\n n = int(input())\n number = input()\n for i in range(n):\n if number[i] != '4' and number[i] != '7':\n print('NO')\n return\n s1 = 0\n s2 = 0\n for i in range(n//2):\n s1 += ord(number[i])\n s2 += ord(number[n - i - 1])\n if s1 == s2:\n print('YES')\n else:\n print('NO')\n\nmain()\n\n", "def check(num, length):\r\n lst = []\r\n while num:\r\n lst.append(num % 10)\r\n num //= 10\r\n if lst.count(4) + lst.count(7) == length and sum(lst[0:n // 2]) == sum(lst[n // 2:n]):\r\n return True\r\n return False\r\n\r\n\r\nn = int(input())\r\na = int(input())\r\nif check(a, n):\r\n print('YES')\r\nelse:\r\n print('NO')", "m = int(input())\nsum1 = 0\nsum2 = 0\ns = input()\nflag = 0\nfor i in range(m):\n if m == 1:\n break\n if i < m / 2:\n sum1 += int(s[i])\n else:\n sum2 += int(s[i])\n if s[i] != '4' and s[i] != '7':\n flag = 1\n break\nif s[i] != '4' and s[i] != '7':\n flag = 1\nprint('YES' if sum1 == sum2 and flag == 0 else 'NO')", "n = int(input())\r\ns = input()\r\ns1, s2 = s[:n//2], s[n//2:]\r\na, b = sum(list(map(int, s1))), sum(list(map(int, s2)))\r\nt = 0\r\n\r\nfor i in s:\r\n if i == '4' or i == '7':\r\n t += 1\r\n\r\nif t == n and a == b:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") ", "num=int(input())\r\nstr=input()\r\nsum1=sum2=c=0\r\nfor i in str:\r\n if(i=='4' or i=='7'):\r\n c+=1\r\nif(c==num):\r\n for i in range(num//2):\r\n sum1+=int(str[i])\r\n for i in range(num//2,num):\r\n sum2+=int(str[i])\r\n if(sum1==sum2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "n = int(input())\r\nch=input()\r\n\r\ntest=ch.replace('4', '')\r\ntest=test.replace('7', '')\r\n\r\ndef somme(l):\r\n\ts=0\r\n\tfor i in l:\r\n\t\ts+=int(i)\r\n\treturn s\r\n\r\nif not len(test) and somme(list(ch[:len(ch)//2])) == somme(list(ch[len(ch)//2:])):\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")", "n = int(input())\n#n, m = map(int, input().split())\ns = input()\n#c = list(map(int, input().split()))\nk = s[:n // 2].count('4') * 4 + s[:n // 2].count('7') * 7\nl = s[n // 2:].count('4') * 4 + s[n // 2:].count('7') * 7\nif (n % 2 == 0 and s.count('4') + s.count('7') == n and \n k == l):\n print('YES')\nelse:\n print('NO')\n ", "n=int(input())\r\na=input()\r\nb=list(a)\r\nfor i in range(n):\r\n b[i]=int(b[i])\r\nk=h=x=0\r\nfor i in range(round(n/2)):\r\n if((b[i]!=4 and b[i]!=7) or (b[i+round(n/2)]!=4 and b[i+round(n/2)]!=7)):\r\n x=1\r\n break\r\n else:\r\n k+=b[i]\r\n h+=b[round(n/2)+i]\r\nif(x):\r\n print(\"NO\")\r\nelse:\r\n if(h==k):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "n = int(input())\r\ns = input()\r\nt = True\r\nif '1' in s or '2' in s or '3' in s or '5' in s or '6' in s or '8' in s or '9' in s or '0' in s:\r\n t = False\r\nif t:\r\n sum1 = sum2 = 0\r\n for i in range(n//2):\r\n sum1 += int(s[i])\r\n sum2 += int(s[i + n//2])\r\n if sum1 == sum2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "input()\nv = input()\nn = len(v)\nv1 = v[:n//2]\nv2 = v[n//2:]\nc14 = v1.count('4')\nc24 = v2.count('4')\nc17 = v1.count('7')\nc27 = v2.count('7')\nif c14 + c24 + c17 + c27 == n and c14 == c24:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "if __name__ == '__main__':\n n = int(input())\n\n ticket = input()\n\n fh = ticket[:len(ticket)//2]\n lh = ticket[len(ticket)//2:]\n\n fh = list(fh)\n lh = list(lh)\n\n t1 = [num for num in fh if num != '4' and num != '7']\n t2 = [num for num in lh if num != '4' and num != '7']\n\n fh = list(map(int, fh))\n lh = list(map(int, lh))\n\n soma_first_half = 0\n for i in fh:\n soma_first_half += i\n\n soma_last_half = 0\n for i in lh:\n soma_last_half += i\n\n if len(t1) != 0 or len(t2) != 0:\n print(\"NO\")\n elif soma_first_half == soma_last_half:\n print(\"YES\")\n else:\n print(\"NO\")\n\n \t \t \t\t\t \t \t \t\t\t\t \t\t\t \t\t\t", "# Nome: Matheus de Souza Oliveira RA: 203407\n\nimport functools\n\nticketLength = int(input())\nticketNumberAsString = input()\nticketNumberArray = list(map(int, ticketNumberAsString))\nmidleIndex = int(ticketLength/2)\nfirstHalf = ticketNumberArray[:midleIndex]\nsecondHalf = ticketNumberArray[midleIndex:]\nisLuckyNumber = False\n\nfor number in ticketNumberAsString:\n if number == \"4\" or number == \"7\":\n isLuckyNumber = True\n else:\n isLuckyNumber = False\n break\n\nif isLuckyNumber == True:\n\n firstHalfSum = functools.reduce(lambda a, b: a+b, firstHalf)\n secondHalfSum = functools.reduce(lambda a, b: a+b, secondHalf)\n\n if firstHalfSum == secondHalfSum:\n print(\"YES\")\n \n else:\n print(\"NO\")\n\nelse:\n print(\"NO\")\n \t\t\t\t \t\t\t\t\t \t\t \t\t \t\t \t", "input()\r\nX = input()\r\nif X.count('4') + X.count('7') == len(X):\r\n if sum(list(map(int, X[:len(X) // 2]))) == sum(list(map(int, X[len(X) // 2:]))):\r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\")\r\n", "a=int(input())\r\nk=int(a/2)\r\nlist2=[4,7]\r\nlist1=list(map(int ,input()))\r\n\r\ncount=0 \r\nx=sum(list1[0:k])\r\ny=sum(list1[k:a])\r\n\r\nfor p in range(len(list1)):\r\n if((list1[p] in list2) and x==y ):\r\n count+=1\r\n else: \r\n pass\r\n\r\n\r\nif(count==a):\r\n print(\"YES\") \r\nelse:\r\n print(\"NO\") \r\n ", "n=int(input())\ns=input()\ndig=[]\nnum=[4,7]\nflag=1\nfor i in s:\n dig.append(int(i))\nfor i in dig:\n if i not in num:\n flag=0\nind=int(n/2)\nif sum(dig[:ind])!=sum(dig[ind:]):\n flag=0\nif flag:\n print('YES')\nelse:\n print('NO')", "n = int(input())\r\nt = list(map(int,input()))\r\nflag = True\r\n\r\nfor i in t:\r\n if i != 4 and i != 7:\r\n flag = False\r\n print(\"NO\")\r\n break\r\nif flag == True:\r\n s = n//2\r\n\r\n if (sum(t[0:s]) // 2) == (sum(t[s:n]) // 2):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "sze = int(input())\r\ns = input()\r\nhalf = sze // 2\r\nfirst = s[:half]\r\nsecond = s[half:sze]\r\nf = True\r\nsec = True\r\nfsum = 0\r\nssum = 0\r\nfor ch in first:\r\n if(ch == '4' or ch == '7'):\r\n temp = int(ch)\r\n fsum += temp\r\n else:\r\n f = False\r\n break\r\nfor ch in second:\r\n if(ch == '4' or ch == '7'):\r\n temp = int(ch)\r\n ssum += temp\r\n else:\r\n sec = False\r\n break\r\n\r\nif(f and sec):\r\n if(fsum == ssum):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n", "n = int(input())\r\ns = input()\r\nsum1 = sum2 = status = 0\r\nb = ['4','7']\r\nfor i in s:\r\n\tif i not in b:\r\n\t\tstatus = 1\r\nfor i in range(n//2):\r\n\tsum1+=int(s[i])\r\nfor i in range(n//2, n):\r\n\tsum2+=int(s[i])\r\nif sum1!=sum2:\r\n\tstatus = 1\r\nprint(\"YNEOS\"[status::2])", "x = int(input())\r\ns = input()\r\nans = 0\r\nans2 = 0\r\nfor i in range(int(x/2)):\r\n if(s[i] != '7' and s[i] != '4'):\r\n print(\"NO\")\r\n exit()\r\n ans += int(s[i])\r\n\r\nfor i in range(int(x/2), x):\r\n if(s[i] != '7' and s[i] != '4'):\r\n print(\"NO\")\r\n exit()\r\n ans2 += int(s[i])\r\n\r\nif(ans == ans2):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\ndata = input().rstrip()\r\nf = data[:n // 2].count('4')\r\ns = data[n // 2:].count('4')\r\n\r\nif set(data) - {'4', '7'} != set():\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\" if f == s else \"NO\")\r\n", "# https://codeforces.com/problemset/problem/146/A\r\n\r\nn = int(input())\r\ns = input()\r\n\r\nfirst = 0\r\nsecond = 0\r\n\r\ni, j = 0, n // 2\r\n\r\nwhile i < n // 2 and j < n:\r\n\r\n if s[i] == '7' or s[i] == '4':\r\n first += int(s[i])\r\n\r\n else:\r\n print(\"NO\")\r\n break\r\n\r\n if s[j] == '7' or s[j] == '4':\r\n second += int(s[j])\r\n\r\n else:\r\n print(\"NO\")\r\n break\r\n\r\n i += 1\r\n j += 1\r\nelse:\r\n if first != second:\r\n print(\"NO\")\r\n\r\n else:\r\n print(\"YES\")\r\n\r\n", "n=int(input())\r\nm=input()\r\ns=0\r\nsu=0\r\nflag=0\r\nfor i in range(0,len(m)//2):\r\n s=s+int(m[i])\r\nfor i in range(len(m)//2,len(m)):\r\n su=su+int(m[i])\r\nfor i in range(0,len(m)):\r\n if m[i] not in ['4','7']:\r\n flag=1 \r\n break\r\n elif s!=su:\r\n flag=1\r\n break\r\n \r\nif flag==1:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n\r\n\r\n", "n=int(input())\r\ns=input()\r\nj=int(n/2)\r\nans=0\r\ncond=True\r\nfor i in range(0,len(s)):\r\n if s[i]!='4' and s[i]!='7':\r\n cond=False\r\n\r\nif cond:\r\n for i in range(0,j):\r\n ans+=int(s[i])\r\n ans-=int(s[i+j])\r\n\r\n if ans==0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\nelse:\r\n print(\"NO\")\r\n", "m=int(input())\r\nn=int(input())\r\nvar=0\r\ncheck=list(map(int,str(n)))\r\nfor i in check:\r\n if i==4 or i==7:\r\n pass\r\n else:\r\n var=1\r\n print(\"NO\")\r\n break\r\nif var==0: \r\n l=list(map(int,str(n)))\r\n k=l[0:m//2]\r\n if sum(k)==sum(l)-sum(k):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "def islucky(s):\r\n for i in s:\r\n if (i!= '4' and i!='7'):\r\n return False\r\n return True\r\n\r\ndef sum(s):\r\n so=0\r\n for i in s:\r\n so+=int(i)\r\n return so\r\n\r\nn=int(input())\r\ns=input()\r\nif sum(s[:n//2]) == sum(s[n//2:]) and islucky((s)):\r\n print('YES')\r\nelse:\r\n print('NO')", "digits=int(input())\r\nnum=input()\r\nflag=False\r\neven=0\r\nodd=0\r\nfor i in range(digits):\r\n if num[i]=='4' or num[i]=='7':\r\n flag=True\r\n else:\r\n flag=False\r\n break\r\nif flag:\r\n for j in range(digits):\r\n if j<digits/2:\r\n even=even+int(num[j])\r\n else:\r\n odd=odd+int(num[j])\r\n if even==odd :\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "def main():\n length = int(input())\n ticket_number = input()\n is_lucky_number = True\n\n try:\n next(c for c in ticket_number if c not in '47')\n is_lucky_number = False\n except StopIteration:\n pass\n\n if not is_lucky_number:\n print('NO')\n else:\n sum_left = sum(int(c) for c in ticket_number[:(length // 2)])\n sum_right = sum(int(c) for c in ticket_number[(length // 2):])\n print('YES' if sum_left == sum_right else 'NO')\n\n\nif __name__ == '__main__':\n main()\n", "from collections import Counter\r\nn = int(input())\r\ns = list(input())\r\np = Counter(s)\r\nans = 'NO'\r\ns0 = 0\r\ns1 = 0\r\nfor i in range(n):\r\n if i < (n // 2):\r\n s0 += int(s[i])\r\n else:\r\n s1 += int(s[i])\r\nif s0 == s1 and (p['7'] + p['4']) == n:\r\n ans = 'YES'\r\nprint(ans)\r\n", "n=int(input())\r\nm=input()\r\nans = \"YES\"\r\nsums=0\r\nsums2=0\r\nfor i in m:\r\n if i!='4' and i!='7':\r\n ans=\"NO\"\r\nfor i in range(0,n//2):\r\n sums+=int(m[i])\r\nfor i in range(n//2,n):\r\n sums2+=int(m[i])\r\nif sums != sums2:\r\n ans=\"NO\"\r\nprint(ans)\r\n\r\n ", "def function(num,string):\r\n for i in range (num):\r\n if string[i] !=\"7\" and string[i] !=\"4\":\r\n return (\"NO\")\r\n first=0\r\n for i in range (num//2):\r\n first=first+int(string[i])\r\n second=0\r\n for i in range (num//2,num):\r\n second=second+int(string[i])\r\n if first==second:\r\n return (\"YES\")\r\n return (\"NO\")\r\nnum=int(input())\r\nstring=input()\r\nprint (function(num,string))", "n = int(input())\r\nt = list(map(int,list(input())))\r\nif [x for x in t if x != 4 and x != 7]:\r\n print(\"NO\")\r\nelif sum(t[:len(t) // 2]) != sum(t[len(t) // 2:]):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n\r\n\r\n", "n = int(input())\r\ns = input()\r\na = s[:n//2]\r\nb = s[n//2:]\r\nprint('YES' if s.count('4')+s.count('7') == n and a.count('4') == b.count('4') and b.count('7') == b.count('7') else 'NO') " ]
{"inputs": ["2\n47", "4\n4738", "4\n4774", "4\n4570", "6\n477477", "6\n777777", "20\n44444444444444444444", "2\n44", "10\n4745474547", "14\n77770004444444", "10\n4747777744", "10\n1234567890", "50\n44444444444444444444444444444444444444444444444444", "50\n44444444444444444444444444444444444444444444444447", "50\n74444444444444444444444444444444444444444444444444", "50\n07777777777777777777777777777777777777777777777770", "50\n77777777777777777777777777777777777777777777777777", "50\n44747747774474747747747447777447774747447477444474", "48\n447474444777444474747747744774447444747474774474", "32\n74474474777444474444747774474774", "40\n4747777444447747777447447747447474774777", "10\n4477477444", "18\n447747474447744747", "26\n44747744444774744774474447", "50\n44707747774474747747747447777447774747447477444474", "40\n4747777444447737777447447747447474774777", "36\n764477744747444444447747747474744444", "22\n4477407474777477744447", "32\n74274474777444474444747774474774", "16\n4744447974444747", "2\n11", "2\n22", "2\n33", "2\n74", "2\n55", "2\n66", "2\n77", "2\n88", "2\n99", "4\n4004", "14\n00077774444444", "6\n004444", "4\n0044", "14\n77771114444444", "14\n44444447777000", "6\n004774"], "outputs": ["NO", "NO", "YES", "NO", "YES", "YES", "YES", "YES", "NO", "NO", "YES", "NO", "YES", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO"]}
UNKNOWN
PYTHON3
CODEFORCES
461
189d83c2d5a6b1b0f0bde452f2187d0a
Yaroslav and Time
Yaroslav is playing a game called "Time". The game has a timer showing the lifespan he's got left. As soon as the timer shows 0, Yaroslav's character dies and the game ends. Also, the game has *n* clock stations, station number *i* is at point (*x**i*,<=*y**i*) of the plane. As the player visits station number *i*, he increases the current time on his timer by *a**i*. The stations are for one-time use only, so if the player visits some station another time, the time on his timer won't grow. A player spends *d*·*dist* time units to move between stations, where *dist* is the distance the player has covered and *d* is some constant. The distance between stations *i* and *j* is determined as |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Initially, the player is at station number 1, and the player has strictly more than zero and strictly less than one units of time. At station number 1 one unit of money can increase the time on the timer by one time unit (you can buy only integer number of time units). Now Yaroslav is wondering, how much money he needs to get to station *n*. Help Yaroslav. Consider the time to buy and to increase the timer value negligibly small. The first line contains integers *n* and *d* (3<=≤<=*n*<=≤<=100,<=103<=≤<=*d*<=≤<=105) — the number of stations and the constant from the statement. The second line contains *n*<=-<=2 integers: *a*2,<=*a*3,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=103). The next *n* lines contain the coordinates of the stations. The *i*-th of them contains two integers *x**i*, *y**i* (-100<=≤<=*x**i*,<=*y**i*<=≤<=100). It is guaranteed that no two stations are located at the same point. In a single line print an integer — the answer to the problem. Sample Input 3 1000 1000 0 0 0 1 0 3 3 1000 1000 1 0 1 1 1 2 Sample Output 2000 1000
[ "from sys import stdin\r\nfrom math import inf\r\n\r\n\r\ndef readline():\r\n return map(int, stdin.readline().strip().split())\r\n\r\n\r\ndef main():\r\n n, d = readline()\r\n a = [0] + list(readline()) + [0]\r\n x = [0] * n\r\n y = [0] * n\r\n for i in range(n):\r\n x[i], y[i] = readline()\r\n lower_cost = [inf] * n\r\n lower_cost[0] = 0\r\n visited = [False] * n\r\n for i in range(n - 1):\r\n lower_value = inf\r\n position = 0\r\n for j in range(n):\r\n if not visited[j] and lower_value > lower_cost[j]:\r\n lower_value = lower_cost[j]\r\n position = j\r\n visited[position] = True\r\n for k in range(n):\r\n if not visited[k]:\r\n diff = lower_cost[position] + d * (abs(x[k] - x[position]) + abs(y[k] - y[position])) - a[position]\r\n if lower_cost[k] > diff:\r\n lower_cost[k] = diff\r\n return lower_cost[-1]\r\n\r\n\r\nif __name__ == '__main__':\r\n print(main())\r\n", "n, d = map(int, input().split())\n\na = [0] + list(map(int, input().split())) + [0] #aumento de timer según estación\nX = []\nY = []\n\nfor i in range(n):\n x, y = map(int, input().split()) #Coordenadas de la estación i.\n X.append(x) \n Y.append(y)\n\nmon = [-1] * n #array para el monto necesario para llegar.\nmon[0] = 0\nZ = 0 #valor que permitirá entrar al loop\n\nwhile Z == 0:\n Z = 1\n\n for i in range(n): #estamos en estación i\n\n for j in range(1, n): #queremos ir a estación j\n\n if i != j and mon[i] != -1: #si no queremos ir a la misma estación y donde estamos pudimos llegar.\n costo = mon[i] + (abs(X[i] - X[j]) + abs(Y[i] - Y[j]))*d - a[j] #nuevo costo necesario para ir de i a j.\n\n if mon[j] == -1 or costo < mon[j]: #si el nuevo costo es menor que uno anterior, se guarda este o si antes no había ningun costo guardado.\n mon[j] = costo\n Z = 0 #volvemos a entrar al loop, esto asegura que todos los mon[] van a dejar de ser '1 y tendran un costo.\nprint(mon[-1]) #costo de llegar a la última estación.\n\t \t\t\t\t\t \t \t\t \t\t \t\t\t\t \t \t", "f = lambda: list(map(int, input().split()))\r\nn, d = f()\r\na = [0] + f() + [0]\r\np = [f() for i in range(n)]\r\nr = range(n)\r\ns = [[d * (abs(p[i][0] - p[j][0]) + abs(p[i][1] - p[j][1])) - a[j] * (i != j) for j in r] for i in r]\r\nfor k in r: s = [[min(s[i][j], s[i][k] + s[k][j]) for i in r] for j in r]\r\nprint(s[-1][0])", "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\ndef solve():\r\n\tn, dc = mints()\r\n\ta = list(mints())\r\n\ta.append(0)\r\n\tx = [0]*n\r\n\ty = [0]*n\r\n\tfor i in range(n):\r\n\t\tx[i], y[i] = mints()\r\n\td = [1<<30]*n\r\n\td[0] = 0\r\n\twas = [False]*n\r\n\tfor i in range(n):\r\n\t\tm = 1<<30\r\n\t\tmi = 0\r\n\t\tfor j in range(n):\r\n\t\t\tif not was[j] and m > d[j]:\r\n\t\t\t\tm = d[j]\r\n\t\t\t\tmi = j\r\n\t\tj = mi\r\n\t\twas[j] = True\r\n\t\tfor k in range(n):\r\n\t\t\tif not was[k]:\r\n\t\t\t\tdd = d[j] + (abs(x[k]-x[j])+abs(y[k]-y[j]))*dc\r\n\t\t\t\tdd -= a[k-1]\r\n\t\t\t\tif d[k] > dd:\r\n\t\t\t\t\td[k] = dd\r\n\tprint(d[-1])\r\n\r\nsolve()\r\n", "n, d = map(int, input().split())\r\na = [0] + list(map(int, input().split())) + [0]\r\nx = []\r\ny = []\r\nfor i in range(n):\r\n xx, yy = map(int, input().split())\r\n x += [xx]\r\n y += [yy]\r\nb = [-1] * n\r\nb[0] = 0\r\nc = True\r\nwhile c:\r\n c = False\r\n for i in range(n):\r\n for j in range(1, n):\r\n if i != j and b[i] != -1:\r\n t = b[i] + (abs(x[i] - x[j]) + abs(y[i] - y[j])) * d - a[j]\r\n if b[j] == -1 or t < b[j]:\r\n b[j] = t\r\n c = True\r\nprint(b[-1])", "f = lambda: list(map(int, input().split()))\nn, d = f()\nr = range(n)\na = [0] + f() + [0]\np = [f() for i in r]\ns = [1e9] * n\nq, s[0] = 1, 0\nwhile q:\n q = 0\n for i in r:\n for j in r:\n if i != j:\n t = s[i] + (abs(p[i][0] - p[j][0]) + abs(p[i][1] - p[j][1])) * d - a[j]\n if t < s[j]: q, s[j] = 1, t\nprint(s[-1])\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())\nn, d = R()\na = [0] + list(R()) + [0]\nx = []\ny = []\nINF = float('inf')\nfor i in range(n):\n xi, yi = R()\n x += [xi]\n y += [yi]\nb = [INF] * n\nb[0] = 0\nc = True\nwhile c:\n c = False\n for i in range(n):\n for j in range(1, n):\n if i != j and b[i] != -1:\n t = b[i] + (abs(x[i] - x[j]) + abs(y[i] - y[j])) * d - a[j]\n if t < b[j]:\n b[j] = t\n c = True\nprint(b[-1])", "f=lambda:list(map(int,input().split()));n,d=f();a=[0]+f()+[0];p=[f()for i in range(n)];r=range(n);s=[[d*(abs(p[i][0]-p[j][0])+abs(p[i][1]-p[j][1]))-a[j]*(i!=j)for j in r]for i in r]\r\nfor k in r:s=[[min(s[i][j],s[i][k]+s[k][j])for i in r]for j in r]\r\nprint(s[-1][0])", "from collections import defaultdict as dd\r\nfrom collections import deque\r\nimport bisect\r\nfrom heapq import heappop, heappush\r\n\r\ndef ri():\r\n return int(input())\r\n\r\ndef rl():\r\n return list(map(int, input().split()))\r\n\r\ndef dijkstra(G, s):\r\n if s not in G:\r\n return \"starting node not found\"\r\n\r\n dist = {}\r\n\r\n for u in G.keys():\r\n dist[u] = 10**10\r\n\r\n dist[s] = 0\r\n\r\n Q = [(0, s)]\r\n while Q:\r\n curr_dist, curr_node = heappop(Q)\r\n for nbr, nbr_dist in G[curr_node]:\r\n alt = curr_dist + nbr_dist\r\n if alt < dist[nbr]:\r\n dist[nbr] = alt\r\n if nbr not in Q:\r\n heappush(Q, (alt, nbr))\r\n\r\n return dist\r\n\r\ndef solve():\r\n n, d = rl()\r\n P = []\r\n A = [0] + rl()\r\n\r\n for i in range(n):\r\n x, y = rl()\r\n P.append((x, y))\r\n\r\n G = dd(list)\r\n for i in range(n - 1):\r\n for j in range(n):\r\n if i == j: continue\r\n dist = abs(P[i][0] - P[j][0]) + abs(P[i][1] - P[j][1])\r\n cost = dist * d\r\n cost -= A[i]\r\n if cost == 0:\r\n cost = 0.0001\r\n G[i].append((j, cost))\r\n \r\n G[n - 1] = []\r\n D = dijkstra(G, 0)\r\n print (int(D[n-1]))\r\n\r\n\r\nmode = 's'\r\n\r\nif mode == 'T':\r\n t = ri()\r\n for i in range(t):\r\n solve()\r\nelse:\r\n solve()\r\n" ]
{"inputs": ["3 1000\n1000\n0 0\n0 1\n0 3", "3 1000\n1000\n1 0\n1 1\n1 2", "5 1421\n896 448 727\n-19 -40\n-87 40\n69 51\n-55 61\n-7 67", "6 1000\n142 712 254 869\n7 0\n95 38\n96 -20\n-7 93\n75 -45\n-80 -20", "7 1288\n943 265 649 447 806\n-4 -51\n-26 32\n47 -28\n31 32\n61 65\n-45 -37\n82 42", "8 1931\n440 627 324 538 539 119\n-85 -41\n-91 61\n-84 11\n92 -19\n8 -5\n16 -25\n97 -98\n91 78", "9 1829\n98 513 987 291 162 637 356\n38 -3\n-89 93\n-86 45\n-43 -84\n-3 -87\n53 -59\n18 -19\n81 -74\n-85 32", "10 1000\n759 222 589 423 947 507 31 414\n-4 -71\n-31 -53\n24 28\n-13 -65\n-59 -49\n-42 -79\n85 -71\n-60 -17\n28 66\n74 2", "11 1199\n282 735 54 1000 419 939 901 789 128\n10 -81\n26 72\n19 -91\n-61 85\n0 -33\n-62 79\n-59 65\n-2 -77\n-63 100\n-15 53\n94 54", "12 1609\n196 486 94 344 524 588 315 504 449 201\n86 -22\n-2 25\n-95 -8\n-5 -30\n-78 71\n5 -54\n-69 -92\n-41 0\n10 19\n61 17\n75 -39\n-46 22", "3 97325\n40\n43 43\n45 -95\n-93 63", "11 1615\n137 681 199 33 388 585 241 518 7\n-60 89\n24 6\n-100 -55\n-26 -90\n-40 -33\n-100 28\n12 34\n-60 -13\n38 -89\n62 81\n-35 54", "22 1000\n94 609 173 244 930 515 169 56 192 974 923 749 652 987 145 447 578 518 630 917\n13 93\n99 6\n41 -54\n67 -85\n24 38\n23 -65\n9 -60\n-29 -78\n-29 -32\n53 -70\n-83 -50\n31 1\n-85 16\n74 95\n-30 89\n89 -67\n70 -74\n-78 -73\n19 17\n97 4\n97 -27\n-4 -48", "4 62071\n706 480\n6 96\n51 -12\n99 66\n-69 -61", "12 1542\n389 356 290 648 182 94 585 988 762 494\n-46 96\n1 88\n0 95\n-91 -100\n-42 -29\n45 -27\n-52 -34\n-62 27\n-19 46\n-100 95\n5 -55\n-36 -65", "3 100000\n1\n-100 -100\n-100 -99\n100 100", "12 1211\n1 5 7 1000 1000 1000 1000 1000 1000 1000\n1 1\n5 5\n3 4\n4 3\n0 1\n0 2\n0 5\n0 7\n1 0\n3 0\n8 0\n10 10", "6 1000\n1000 1000 1000 1000\n0 0\n0 -1\n1 -1\n2 -1\n2 0\n2 1"], "outputs": ["2000", "1000", "169099", "107000", "229903", "569018", "288982", "151000", "262581", "282231", "15182700", "96900", "158000", "14400472", "263034", "39999999", "20220", "1000"]}
UNKNOWN
PYTHON3
CODEFORCES
9
18b11fdbe3798b0b5243958f3bf2e4ef
Dependency management
Polycarp is currently developing a project in Vaja language and using a popular dependency management system called Vamen. From Vamen's point of view both Vaja project and libraries are treated projects for simplicity. A project in Vaja has its own uniqie non-empty name consisting of lowercase latin letters with length not exceeding 10 and version — positive integer from 1 to 106. Each project (keep in mind that it is determined by both its name and version) might depend on other projects. For sure, there are no cyclic dependencies. You're given a list of project descriptions. The first of the given projects is the one being developed by Polycarp at this moment. Help Polycarp determine all projects that his project depends on (directly or via a certain chain). It's possible that Polycarp's project depends on two different versions of some project. In this case collision resolving is applied, i.e. for each such project the system chooses the version that minimizes the distance from it to Polycarp's project. If there are several options, the newer (with the maximum version) is preferred. This version is considered actual; other versions and their dependencies are ignored. More formal, choose such a set of projects of minimum possible size that the following conditions hold: - Polycarp's project is chosen; - Polycarp's project depends (directly or indirectly) on all other projects in the set; - no two projects share the name; - for each project *x* that some other project in the set depends on we have either *x* or some *y* with other version and shorter chain to Polycarp's project chosen. In case of ties the newer one is chosen. Output all Polycarp's project's dependencies (Polycarp's project itself should't be printed) in lexicographical order. The first line contains an only integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of projects in Vaja. The following lines contain the project descriptions. Each project is described by a line consisting of its name and version separated by space. The next line gives the number of direct dependencies (from 0 to *n*<=-<=1) and the dependencies themselves (one in a line) in arbitrary order. Each dependency is specified by its name and version. The projects are also given in arbitrary order, but the first of them is always Polycarp's. Project descriptions are separated by one empty line. Refer to samples for better understanding. It's guaranteed that there are no cyclic dependencies. Output all Polycarp's project's dependencies in lexicographical order. Sample Input 4 a 3 2 b 1 c 1   b 2 0   b 1 1 b 2   c 1 1 b 2 9 codehorses 5 3 webfrmk 6 mashadb 1 mashadb 2   commons 2 0   mashadb 3 0   webfrmk 6 2 mashadb 3 commons 2   extra 4 1 extra 3   extra 3 0   extra 1 0   mashadb 1 1 extra 3   mashadb 2 1 extra 1 3 abc 1 2 abc 3 cba 2 abc 3 0 cba 2 0 Sample Output 2 b 1 c 1 4 commons 2 extra 1 mashadb 2 webfrmk 6 1 cba 2
[ "N=int(input())\r\nSlide=dict()\r\nSlideList=[list()]*N\r\nItogInformation=set()\r\nGoodNameTags=set()\r\n\r\nNewName,NewVer=input().split()\r\nNewVer=int(NewVer)\r\n\r\nGoodNameTags.add(NewName)\r\n\r\nSlide[0]=NewName+' '+str(NewVer)\r\nSlide[NewName+' '+str(NewVer)]=0\r\nNewNum=int(input())\r\nSlideList[0]=[0]*(NewNum+2)\r\nSlideList[0][1]=NewNum\r\n\r\nfor i in range(1,NewNum+1):\r\n Name,Ver=input().split()\r\n SlideList[0][i+1]=Name+' '+Ver\r\n \r\nfor j in range(1,N):\r\n input()\r\n NewName,NewVer=input().split()\r\n NewVer=int(NewVer)\r\n Slide[j]=NewName+' '+str(NewVer)\r\n Slide[NewName+' '+str(NewVer)]=j\r\n NewNum=int(input())\r\n SlideList[j]=[0]*(NewNum+2)\r\n SlideList[j][1]=NewNum\r\n for i in range(1,NewNum+1):\r\n Name,Ver=input().split()\r\n SlideList[j][i+1]=Name+' '+Ver\r\n\r\nListOfNeed=set()\r\nListOfRead=set()\r\nListOfRead.add(Slide[0])\r\n\r\nwhile len(ListOfRead)!=0:\r\n ListOfNeed=ListOfRead.copy()\r\n ListOfRead=set()\r\n found=dict()\r\n for i in ListOfNeed:\r\n for j in range(SlideList[Slide[i]][1]):\r\n Name,Ver=SlideList[Slide[i]][j+2].split()\r\n Ver=int(Ver)\r\n key=found.pop(Name, -1)\r\n if key==-1 or key<Ver:\r\n found[Name]=Ver\r\n else:\r\n found[Name]=key\r\n for i in found.keys():\r\n if not (i in GoodNameTags):\r\n GoodNameTags.add(i)\r\n ListOfRead.add(i+' '+str(found[i]))\r\n ItogInformation.add(i+' '+str(found[i]))\r\n \r\nOtvet=list(ItogInformation)\r\nOtvet.sort() \r\n\r\nprint(len(Otvet))\r\nfor i in range(len(Otvet)):\r\n print(Otvet[i])\r\n\r\n", "n = int(input())\r\n\r\nd = {}\r\n\r\nfor x in range(n):\r\n if x == 0:\r\n L, R = map(str, input().split())\r\n R = int(R)\r\n l = L\r\n r = R\r\n if not (l, int(r)) in d:\r\n d[(l, int(r))] = []\r\n m = int(input())\r\n for y in range(m):\r\n l1, r1 = map(str, input().split())\r\n d[(l, int(r))].append((l1, int(r1)))\r\n if x != n - 1:\r\n s = input()\r\n else:\r\n l, r = map(str, input().split())\r\n if not (l, int(r)) in d:\r\n d[(l, int(r))] = []\r\n m = int(input())\r\n for y in range(m):\r\n l1, r1 = map(str, input().split())\r\n d[(l, int(r))].append((l1, int(r1)))\r\n if x != n - 1:\r\n s = input()\r\n\r\nlst = []\r\narray = [L]\r\n\r\n#print(d)\r\ntemp1 = [(L, R)]\r\ntemp2 = []\r\nk1 = 0\r\nk2 = 1\r\nwhile k1 < len(temp1) or k2 < len(temp2):\r\n if k2 > len(temp2):\r\n while k1 < len(temp1):\r\n for (a, b) in d[temp1[k1]]:\r\n temp2.append((a, -b))\r\n k1 += 1\r\n temp2.sort()\r\n temp = []\r\n for (a, b) in temp2:\r\n if not a in array:\r\n array.append(a)\r\n lst.append((a, -b))\r\n temp.append((a, -b))\r\n temp2 = temp[:]\r\n temp1 = []\r\n k1 = 1\r\n k2 = 0\r\n elif k1 > len(temp1):\r\n while k2 < len(temp2):\r\n for (a, b) in d[temp2[k2]]:\r\n temp1.append((a, -b))\r\n k2 += 1\r\n temp1.sort()\r\n temp = []\r\n for (a, b) in temp1:\r\n if not a in array:\r\n array.append(a)\r\n lst.append((a, -b))\r\n temp.append((a, -b))\r\n temp1 = temp[:]\r\n temp2 = []\r\n k2 = 1\r\n k1 = 0 \r\n\r\nprint(len(lst))\r\nlst.sort()\r\nfor (a, b) in lst:\r\n print(a, b)", "from collections import defaultdict\r\n \r\n \r\ndef rp():\r\n s = input().split()\r\n return (s[0], int(s[1]))\r\n \r\nps = {}\r\nn = int(input())\r\n \r\nfor i in range(n):\r\n p = rp()\r\n d = []\r\n for _ in range(int(input())):\r\n d += [rp()]\r\n ps[p] = d\r\n if i != n - 1:\r\n input()\r\n \r\nroot = list(ps.keys())[0]\r\nq = [(root, 0)]\r\nu = {root[0]: (root[1], 0)}\r\n \r\nfor i, l in q:\r\n isp = i\r\n if isp[0] in u and isp[1] != u[isp[0]][0]:\r\n continue\r\n for p in ps[i]:\r\n psp = p\r\n if psp[0] not in u or u[psp[0]][1] == l + 1 and u[psp[0]][0] < psp[1]:\r\n u[psp[0]] = (psp[1], l + 1)\r\n q.append((psp, l + 1))\r\n \r\ndel u[root[0]]\r\n \r\nprint(len(u))\r\nfor i in sorted(u):\r\n print(i, u[i][0])", "levels = []\r\n\r\nconnect = dict()\r\n\r\nn = int(input())\r\nk = input().split()\r\nlevels.append({k[0]: int(k[1])})\r\nconnect[k[0]+' '+str(k[1])] = []\r\nd = int(input())\r\n\r\nfor i in range(d):\r\n connect[k[0]+' '+str(k[1])].append(input())\r\n\r\n\r\nfor i in range(n-1):\r\n s = input()\r\n s = input()\r\n connect[s] = []\r\n k = int(input())\r\n for j in range(k):\r\n connect[s].append(input())\r\n\r\nlev = 0\r\nwhile len(levels[len(levels)-2]):\r\n levels.append(dict())\r\n for projname in levels[lev]:\r\n listing = connect[projname + ' ' + str(levels[lev][projname])]\r\n for i in listing:\r\n name = i.split()\r\n gov = True\r\n #проверка, есть ли этот проект в предыдущих уровнях\r\n for j in range(lev+1):\r\n if name[0] in levels[j]:\r\n gov = False\r\n break\r\n #проверка, есть ли этот проект в текущем уровне\r\n if gov:\r\n if name[0] not in levels[lev+1]:\r\n levels[lev + 1][name[0]] = int(name[1])\r\n else:\r\n found = levels[lev + 1][name[0]]\r\n levels[lev+1][name[0]] = max(int(name[1]), found)\r\n lev += 1\r\n\r\nres = {}\r\nfor i in range(1, len(levels)-2):\r\n res.update(levels[i])\r\nkeys = list(res.keys())\r\nkeys.sort()\r\nprint(len(keys))\r\nfor i in keys:\r\n print(i+' '+ str(res[i]))", "from queue import Queue\r\n\r\n\r\ndef BFS(v):\r\n global ans\r\n\r\n stack = Queue()\r\n stack.put(v)\r\n\r\n used = {p[0]: False for p in graph.keys()}\r\n used[v[0]] = True\r\n\r\n while True:\r\n set_ = dict()\r\n st = Queue()\r\n\r\n while not stack.empty():\r\n v = stack.get()\r\n\r\n for u in graph[v]:\r\n n_ = u[0]\r\n if not used[n_]:\r\n try:\r\n set_[n_] = max(set_[n_], u[1])\r\n except KeyError:\r\n set_[n_] = u[1]\r\n\r\n for el in set_.items():\r\n ans.append(el)\r\n st.put(el)\r\n used[el[0]] = True\r\n\r\n if st.empty():\r\n break\r\n\r\n while not st.empty():\r\n stack.put(st.get())\r\n\r\n\r\nn = int(input())\r\ngraph = dict()\r\n\r\nfor i in range(n):\r\n name, ver = input().split()\r\n k = int(input())\r\n temp = set()\r\n\r\n for j in range(k):\r\n name_, ver_ = input().split()\r\n temp.add((name_, int(ver_)))\r\n\r\n tup = (name, int(ver))\r\n graph[tup] = temp\r\n\r\n if i == 0:\r\n PP = tup\r\n\r\n if i + 1 != n:\r\n input()\r\n\r\nans = list()\r\n\r\nBFS(PP)\r\n\r\nprint(len(ans))\r\nprint('\\n'.join([' '.join(map(str, el)) for el in sorted(ans, key=lambda x: x[0])]))\r\n", "def read_pack():\r\n name, ver = input().strip().split()\r\n return (name, int(ver))\r\n\r\nn = int(input())\r\ndeps = dict()\r\nfor i in range(n):\r\n pack = read_pack()\r\n if not i:\r\n root = pack\r\n dep_n = int(input())\r\n deps[pack] = [read_pack() for _ in range(dep_n)]\r\n if i != n - 1:\r\n input()\r\n\r\nqueue = [(root, 0)]\r\ntaken = {root[0]: (root[1], 0)}\r\nfor pack, level in queue:\r\n # pack_deps = sorted(deps[pack], key=lambda x: x[1], reverse=True)\r\n for dep in deps[pack]:\r\n if dep[0] not in taken:\r\n taken[dep[0]] = (dep[1], level + 1)\r\n queue.append((dep, level + 1))\r\n elif taken[dep[0]][1] == level + 1 and taken[dep[0]][0] < dep[1]:\r\n index = queue.index(((dep[0], taken[dep[0]][0]), level + 1))\r\n taken[dep[0]] = (dep[1], level + 1)\r\n queue[index] = (dep, level + 1)\r\n\r\ndel taken[root[0]]\r\n\r\nprint(len(taken))\r\n\r\nfor d in sorted(taken):\r\n print(d, taken[d][0])", "def bfs(polycarp, all_projects, existed_projects):\r\n # print(polycarp)\r\n # print(all_projects)\r\n # print(existed_projects)\r\n\r\n queue0 = {polycarp[0]: polycarp[1]}\r\n queue1 = {}\r\n\r\n while queue0:\r\n for p in queue0.items():\r\n existed_projects[p[0]] = p[1]\r\n\r\n for pp in queue0.items():\r\n for p in all_projects[pp]:\r\n if p[0] not in existed_projects:\r\n if p[0] not in queue1:\r\n queue1[p[0]] = p[1]\r\n else:\r\n queue1[p[0]] = max(queue1[p[0]], p[1])\r\n else:\r\n continue\r\n\r\n queue0, queue1 = queue1, {}\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n all_projects = {}\r\n for _ in range(n):\r\n name, version = input().split()\r\n version = int(version)\r\n if _ == 0:\r\n polycarp = (name, version)\r\n nn = int(input())\r\n all_projects[(name, version)] = []\r\n for _2 in range(nn):\r\n name2, version2 = input().split()\r\n version2 = int(version2)\r\n all_projects[(name, version)].append((name2, version2))\r\n if _ != n - 1:\r\n input()\r\n\r\n existed_projects = {}\r\n bfs(polycarp, all_projects, existed_projects)\r\n\r\n print(len(existed_projects) - 1)\r\n for name in sorted(existed_projects.keys()):\r\n if name != polycarp[0]:\r\n print(name, existed_projects[name])\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n = int(input())\r\nn = n - 1\r\ndef par():\r\n s,x = input().split()\r\n x = int(x)\r\n a = []\r\n n = int(input())\r\n for i in range(n):\r\n r,m = input().split()\r\n m = int(m)\r\n a.append(tuple([r,m]))\r\n return tuple([s,x]),a\r\nroot = par()\r\nd = {}\r\nfor i in range(n):\r\n input()\r\n a,b = par()\r\n d[a] = b\r\n\r\nc = {root[0][0]}\r\na = []\r\nb = root[1]\r\nwhile b != []:\r\n b.sort()\r\n b.reverse()\r\n i = 0\r\n while i<len(b):\r\n if not(b[i][0] in c):\r\n c.add(b[i][0])\r\n i += 1\r\n else:\r\n b.pop(i)\r\n a= a + b\r\n f = []\r\n for i in b:\r\n f += d[i]\r\n b = f\r\na.sort()\r\nprint(len(a))\r\nfor i in a:\r\n print(*i)" ]
{"inputs": ["4\na 3\n2\nb 1\nc 1\n\nb 2\n0\n\nb 1\n1\nb 2\n\nc 1\n1\nb 2", "9\ncodehorses 5\n3\nwebfrmk 6\nmashadb 1\nmashadb 2\n\ncommons 2\n0\n\nmashadb 3\n0\n\nwebfrmk 6\n2\nmashadb 3\ncommons 2\n\nextra 4\n1\nextra 3\n\nextra 3\n0\n\nextra 1\n0\n\nmashadb 1\n1\nextra 3\n\nmashadb 2\n1\nextra 1", "3\nabc 1\n2\nabc 3\ncba 2\n\nabc 3\n0\n\ncba 2\n0", "1\nabc 1000000\n0", "3\nppdpd 283157\n1\npddpdpp 424025\n\nppdpd 529292\n1\nppdpd 283157\n\npddpdpp 424025\n0", "5\nabbzzz 646068\n0\n\nzabza 468048\n2\nbb 902619\nzabza 550912\n\nzabza 217401\n2\nabbzzz 646068\nbb 902619\n\nzabza 550912\n1\nzabza 217401\n\nbb 902619\n1\nabbzzz 646068", "5\nyyyy 223967\n1\nyyyyyyy 254197\n\nyyyyyyy 254197\n0\n\ny 442213\n0\n\ny 965022\n1\nyyyyyyy 254197\n\nyyyy 766922\n4\nyyyyyyy 254197\ny 442213\nyyyy 223967\ny 965022", "3\nvvgvvgv 991444\n1\ngvgvgvgvgg 206648\n\nvvgvvgv 296188\n0\n\ngvgvgvgvgg 206648\n1\nvvgvvgv 296188", "5\ntctocototo 984516\n1\ncttocottt 486791\n\ntctocototo 688522\n2\ncttocottt 486791\ntctocototo 984516\n\ncttocottt 486791\n0\n\ntctocototo 676435\n1\ntctocototo 394244\n\ntctocototo 394244\n2\ntctocototo 688522\ncttocottt 486791", "5\nggggggggg 202537\n4\ngggggggg 868552\ngggg 234633\ngggg 402994\ngggggggg 86863\n\ngggg 402994\n0\n\ngggggggg 868552\n1\ngggg 234633\n\ngggg 234633\n1\ngggg 402994\n\ngggggggg 86863\n0", "4\ncf 1\n2\ndb 1\ndb 2\n\ndb 2\n0\n\ndb 1\n1\nold 1\n\nold 1\n0", "5\ncf 1\n2\ndb 1\ndb 2\n\ndb 2\n1\nold 1\n\ndb 1\n1\nold 2\n\nold 1\n0\n\nold 2\n0"], "outputs": ["2\nb 1\nc 1", "4\ncommons 2\nextra 1\nmashadb 2\nwebfrmk 6", "1\ncba 2", "0", "1\npddpdpp 424025", "0", "1\nyyyyyyy 254197", "1\ngvgvgvgvgg 206648", "1\ncttocottt 486791", "2\ngggg 402994\ngggggggg 868552", "1\ndb 2", "2\ndb 2\nold 1"]}
UNKNOWN
PYTHON3
CODEFORCES
8
18b1871eff3e76fa481fabb660e7fa4a
Slava and tanks
Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map. Formally, map is a checkered field of size 1<=×<=*n*, the cells of which are numbered from 1 to *n*, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he flies very high, but he can drop a bomb in any cell. All tanks in this cell will be damaged. If a tank takes damage for the first time, it instantly moves to one of the neighboring cells (a tank in the cell *n* can only move to the cell *n*<=-<=1, a tank in the cell 1 can only move to the cell 2). If a tank takes damage for the second time, it's counted as destroyed and never moves again. The tanks move only when they are damaged for the first time, they do not move by themselves. Help Slava to destroy all tanks using as few bombs as possible. The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the size of the map. In the first line print *m* — the minimum number of bombs Slava needs to destroy all tanks. In the second line print *m* integers *k*1,<=*k*2,<=...,<=*k**m*. The number *k**i* means that the *i*-th bomb should be dropped at the cell *k**i*. If there are multiple answers, you can print any of them. Sample Input 2 3 Sample Output 3 2 1 2 4 2 1 3 2
[ "def f(n):\r\n\tl=[]\r\n\tfor i in range(n//2*2,1,-2):\r\n\t\tl.append(i)\r\n\tmid=[]\r\n\tl=l[::-1]\r\n\tfor i in range(1,n+1):\r\n\t\tif i not in l:\r\n\t\t\tmid.append(i)\r\n\tans=l+mid+l\r\n\tprint(len(ans))\r\n\treturn ans\r\nprint(*f(int(input())))", "n = int(input())\r\neven = n // 2\r\nodd = n - even\r\nans = 2 * even + odd\r\nprint(ans)\r\nlo = []\r\nle = []\r\nfor x in range(1, n + 1):\r\n if x % 2 == 0:\r\n le.append(str(x))\r\n else:\r\n lo.append(str(x))\r\nlans=le+lo+le\r\nprint(\" \".join(x for x in lans))", "from math import *\r\nn = int(input())\r\nprint(n//2*2+ int(ceil(n/2)))\r\nfor i in range(2,n+1,2):\r\n print(i,end= \" \")\r\nfor i in range(1,n+1,2):\r\n print(i,end= \" \")\r\nfor i in range(2,n+1,2):\r\n print(i,end= \" \")\r\n", "n = int(input())\r\nif n % 2 == 0:\r\n print(n + n // 2)\r\n ans = []\r\n ind = 1\r\n while ind <= n:\r\n ans += [ind]\r\n ind += 2\r\n ind = 2\r\n while ind <= n:\r\n ans += [ind]\r\n ind += 2\r\n ind = 1\r\n while ind <= n:\r\n ans += [ind]\r\n ind += 2 \r\n print(*ans)\r\nelse:\r\n print(n + (n - 1) // 2)\r\n ans = []\r\n ind = 2\r\n while ind <= n:\r\n ans += [ind]\r\n ind += 2\r\n ind = 1\r\n while ind <= n:\r\n ans += [ind]\r\n ind += 2 \r\n ind = 2\r\n while ind <= n:\r\n ans += [ind]\r\n ind += 2 \r\n print(*ans)", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\n\r\nN = int(input())\r\n\r\nans = []\r\nfor i in range(2,N+1,2):\r\n ans.append(i)\r\nB = []\r\nfor i in range(1,N+1,2):\r\n B.append(i)\r\nans = ans+B+ans\r\nprint(len(ans))\r\nprint(*ans)\r\n\r\n", "n = int(input())\r\nans = []\r\nfor i in range(2, n + 1, 2):\r\n ans.append(i)\r\nfor i in range(1, n + 1, 2):\r\n ans.append(i)\r\nfor i in range(2, n + 1, 2):\r\n ans.append(i)\r\nprint(len(ans))\r\nprint(' '.join(str(i) for i in ans))", "n = int(input())\r\n\r\nr = [i for i in range(2, n+1, 2)] \\\r\n + [i for i in range(1, n+1, 2)] \\\r\n + [i for i in range(2, n+1, 2)]\r\n\r\nprint(len(r))\r\nprint(*r)", "#OMM NAMH SHIVAY\r\n#JAI SHREE RAM\r\nimport sys,math,heapq,queue\r\nfrom collections import deque\r\nfrom functools import cmp_to_key\r\nfast_input=sys.stdin.readline \r\nMOD=10**9+7\r\nn=int(input()) \r\nans=[] \r\nfor i in range(2,n+1,2):\r\n ans.append(i)\r\nfor i in range(1,n+1,2):\r\n ans.append(i)\r\nfor i in range(2,n+1,2):\r\n ans.append(i) \r\nprint(len(ans))\r\nprint(*ans)\r\n", "n = int(input())\neven = []\nodd = []\nfor i in range(1, n+1):\n if i % 2 == 0:\n even.append(i)\n else:\n odd.append(i)\nprint(len(even) * 2 + len(odd))\nfor i in even:\n print(i, end=' ')\nfor i in odd:\n print(i, end=' ')\nfor i in even:\n print(i, end=' ')\n\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\nl1=[]\r\nl2=[]\r\nfor i in range(1,n+1,2):\r\n l1.append(i)\r\nfor i in range(2,n+1,2):\r\n l2.append(i)\r\nans=l2+l1+l2\r\nprint(len(ans))\r\nprint(*ans)", "x = int(input())\nans = []\nfor i in range(1, x + 1):\n if i % 2 == 0:\n ans.append(i)\nfor i in range(1, x + 1):\n if i % 2 == 1:\n ans.append(i)\nfor i in range(1, x + 1):\n if i % 2 == 0:\n ans.append(i)\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", "n = int(input())\n\nprint(n + n // 2)\nprint(*range(2, n + 1, 2), *range(1, n + 1, 2), *range(2, n + 1, 2))\n", "n = int(input())\r\na = [*range(2,n+1,2)]\r\nprint(int(n*1.5),'\\n',*a,*range(1,n+1,2),*a)\r\n", "n=int(input())\r\nn+=1\r\nans=[]\r\nfor i in range(2,n,2):\r\n ans.append(i)\r\nfor i in range(1,n,2):\r\n ans.append(i)\r\nfor i in range(2,n,2):\r\n ans.append(i)\r\nprint(len(ans))\r\nprint(*ans,sep=\" \")", "n = int(input())\r\nss = 0\r\ne = [int(i) for i in range(2,n+1,2)]\r\nss += 2*len(e)\r\no = [int(i) for i in range(1,n+1,2)]\r\nss += len(o)\r\ne += o+e\r\nprint(ss)\r\nprint(*e)\r\n", "n = int(input())\r\nprint(n // 2 + (n + 1) // 2 + n // 2)\r\na = []\r\nfor i in range(1, n, 2):\r\n a.append(i + 1)\r\nfor i in range(0, n, 2):\r\n a.append(i + 1)\r\nfor i in range(1, n, 2):\r\n a.append(i + 1)\r\nprint(*a)\r\n", "n = int(input())\r\nans = list()\r\nfor i in range(2, n+1, 2):\r\n ans.append(i)\r\nfor i in range(1, n+1, 2):\r\n ans.append(i)\r\nfor i in range(2, n+1, 2):\r\n ans.append(i)\r\nprint(len(ans))\r\nprint(' '.join(map(str, ans)))", "# Сложность по времени\r\n# Сложность по памяти\r\n\r\nn = int(input())\r\nif n == 2:\r\n print(3)\r\n print(2, 1, 2)\r\nif n == 3:\r\n print(4)\r\n print(2, 1, 3, 2)\r\nif n > 3:\r\n res1 = [i + 1 for i in range(n) if i % 2 == 1]\r\n res2 = [i + 1 for i in range(n) if i % 2 == 0]\r\n print(2 * len(res1) + len(res2))\r\n print(*res1, *res2, *res1)", "n = int(input())\r\nuno = list(range(2, n+1, 2))\r\ndos = list(range(1, n+1, 2))\r\nprint(2*len(uno)+len(dos))\r\nprint(*uno, *dos, *uno)\r\n", "n=int(input())\r\nprint(n+n//2)\r\ns=''\r\nfor i in range(2,n+1,2):\r\n s+=str(i)+' '\r\nfor i in range(1,n+1,2):\r\n s +=str(i) + ' '\r\nfor i in range(2,n+1,2):\r\n s+=str(i)+' '\r\nprint(s)", "n = int(input())\r\ns = []\r\nfor i in range(2,n+1,2):\r\n s.append(i)\r\nfor i in range(1,n+1,2):\r\n s.append(i)\r\nfor i in range(2,n+1,2):\r\n s.append(i)\r\nprint(len(s))\r\nprint(*s)", "n = int(input())\r\nprint(n + n // 2)\r\nx = [i for i in range(2, n + 1, 2)]\r\nx += [i for i in range(1, n + 1, 2)]\r\nx += [i for i in range(2, n + 1, 2)]\r\nprint(' '.join(map(str, x)))\r\n", "from math import*\r\n\r\ntt = int(input())\r\n\r\n# tt = 5\r\n\r\nprint(tt + tt // 2)\r\n\r\na1 = list(range(2, tt + 1, 2))\r\na2 = list(range(1, tt + 1, 2))\r\n\r\na1 = ' '.join([str(i) for i in a1])\r\na2 = ' '.join([str(i) for i in a2])\r\n\r\n\r\nif tt % 2 == 1:\r\n print(a1, end = ' ')\r\n print(a2, end = ' ')\r\n print(a1)\r\nelse:\r\n print(a2, end = ' ')\r\n print(a1, end = ' ')\r\n print(a2)\r\n\r\n \r\n\r\n", "N=int(input());\r\nif(N%2==0):\r\n print(int(3*(N/2)));\r\nelse:\r\n print(int(N+(N/2)));\r\nfor i in range(2,N+1,2):\r\n print(i,end=' '),\r\nfor i in range(1,N+1,2):\r\n print(i,end=' '),\r\nfor i in range(2,N+1,2):\r\n print(i,end=' '),", "n = int(input())\r\n\r\nprint(n + n//2) \r\n\r\nfor i in range(2, n+1, 2):\r\n print(i, end = \" \")\r\n \r\nfor i in range(1, n+1, 2):\r\n print(i, end = \" \")\r\n \r\nfor i in range(2, n+1, 2):\r\n print(i, end = \" \")", "n=int(input())\r\neven=[i for i in range(1,n+1) if i%2==0]\r\nodd=[i for i in range(1,n+1) if i&1]\r\nprint(2*len(even)+len(odd))\r\nl=even+odd+even\r\nprint(*(l))", "n = int(input())\n\nx = n // 2\ny = n - x\n\nprint(2 * x + y)\n\nfor i in range(n % 2, n, 2):\n\tprint(i + 1, end = \" \")\nfor i in range(1 - n % 2, n, 2):\n\tprint(i + 1, end = \" \")\nfor i in range(n % 2, n, 2):\n\tprint(i + 1, end = \" \")", "# n is exact number ...\r\ni=int(input())\r\nA=[*range(2,i+1,2)]\r\nB=[*range(1,i+1,2)]\r\nprint(len(A)*2+len(B))\r\nprint(*A,*B,*A)", "import math\r\nn = int(input())\r\nprint(n+math.floor(n/2))\r\nfor even in [True, False, True]:\r\n for i in range(n):\r\n if (i+1) % 2 == 1 and not even:\r\n print(i+1, end=\" \")\r\n if (i+1) % 2 == 0 and even:\r\n print(i+1, end=\" \")", "x = int(input())\r\ny = int(x/2)\r\nmoves = []\r\n\r\nif x % 2 == 0:\r\n print(int(x + y))\r\n for i in range(y):\r\n moves.append((i+1)*2)\r\n for i in range(y):\r\n moves.append((i*2) + 1)\r\n for i in range(y):\r\n moves.append((i+1)*2)\r\n\r\nif x % 2 != 0:\r\n print(int(x + y))\r\n y = int(x/2)\r\n for i in range(y):\r\n moves.append((i+1)*2)\r\n for i in range(y + 1):\r\n moves.append((i*2) + 1)\r\n for i in range(y):\r\n moves.append((i+1)*2)\r\nprint(*moves, sep = \" \")", "#!/usr/bin/env python3\r\n\r\nimport sys\r\nimport itertools\r\n\r\ninput = iter(sys.stdin.read().splitlines()).__next__\r\n\r\nN = int(input())\r\n\r\nres = list(itertools.chain(range(2, N+1, 2), range(1, N+1, 2), range(2, N+1, 2)))\r\n\r\nprint(len(res))\r\nprint(' '.join(map(str, res)))\r\n\r\n", "n=int(input())\r\nif n==2 :\r\n print(3)\r\n print(2,1,2)\r\n exit()\r\nelse :\r\n l=[]\r\n for i in range(2,n+1) :\r\n if i%2==0 :\r\n l.append(i)\r\n for i in range(1,n+1) :\r\n if i%2!=0 :\r\n l.append(i)\r\n for i in range(2,n+1) :\r\n if i%2==0 :\r\n l.append(i)\r\n print(len(l))\r\n print(*l)\r\n \r\n \r\n", "i=int(input())\r\nA=[*range(2,i+1,2)]\r\nB=[*range(1,i+1,2)]\r\nprint(len(A)+i)\r\nprint(*A,*B,*A)", "n=int(input())\r\n\r\nan=[]\r\n\r\n\r\nfor i in range(1,n,2):\r\n\tan.append(i)\r\nfor i in range(0,n,2):\r\n\tan.append(i)\r\nfor i in range(1,n,2):\r\n\tan.append(i)\r\nprint(len(an))\r\n\r\nfor i in an:\r\n\tprint(i+1,end=' ')", "n=int(input())\r\nprint(n+n//2)\r\nif (n%2==0):\r\n l=[]\r\n for i in range(0,n,2):\r\n l.append(i+1)\r\n for i in range(1,n,2):\r\n l.append(i+1)\r\n for i in range(0,n,2):\r\n l.append(i+1)\r\nelse :\r\n l=[]\r\n for i in range(1,n,2):\r\n l.append(i+1)\r\n for i in range(0,n,2):\r\n l.append(i+1)\r\n for i in range(1,n,2):\r\n l.append(i+1)\r\nprint(*l)\r\n\r\n", "n = int(input())\nans = []\nfor i in range(1, n+1):\n if i%2 == 0:\n ans.append(i)\nfor i in range(1, n+1):\n if i%2 == 1:\n ans.append(i)\nfor i in range(1, n+1):\n if i%2 == 0:\n ans.append(i)\nprint(len(ans))\nprint(*ans)\n", "n = int(input())\r\nprint(n+n//2)\r\nfor i in range(2,n+1,2):\r\n print(i,end=\" \")\r\nfor i in range(1,n+1,2):\r\n print(i,end=\" \")\r\nfor i in range(2,n+1,2):\r\n print(i,end=\" \")\r\n", "n = int(input())\r\nans = n + (n // 2)\r\nprint(ans)\r\nif n%2 == 1:\r\n for i in range(n//2):\r\n print('%d' % (2*(i+1)),end=' ')\r\n for i in range(n//2+1):\r\n print('%d' % (2*i + 1),end=' ')\r\n for i in range(n//2):\r\n print('%d' % (2*(i+1)),end=' ')\r\nelse:\r\n for i in range(n//2 - 1):\r\n print('%d' % (2*(i+1)),end=' ')\r\n for i in range(n//2):\r\n print('%d' % (2*i + 1),end=' ')\r\n for i in range(n//2 - 1):\r\n print('%d' % (2*(i+1)),end=' ')\r\n print('%d %d' % (n,n-1),end='\\n')\r\n", "n = int(input())\r\na = []\r\nb = []\r\nfor i in range(1,n+1):\r\n if(i%2!=0):\r\n a.append(i)\r\n else:\r\n b.append(i)\r\nprint(len(a)+2*len(b))\r\nfor el in b:\r\n print(el,end=' ')\r\nfor el in a:\r\n print(el,end=' ')\r\nfor el in b:\r\n print(el,end=' ')\r\n\r\n", "n = int(input())\r\nn1 = n\r\nprint(n + n1 // 2)\r\nfor i in range(2, n + 1, 2):\r\n print(i, end=\" \")\r\nfor i in range(1, n + 1, 2):\r\n print(i, end=\" \")\r\nfor i in range(2, n + 1, 2):\r\n print(i, end=\" \")\r\n \r\n", "n=int(input())\r\nn+=1\r\nans=[]\r\nfor i in range(2,n,2):\r\n ans.append(i)\r\nfor i in range(1,n,2):\r\n ans.append(i)\r\nfor i in range(2,n,2):\r\n ans.append(i)\r\nprint(len(ans))\r\nfor i in ans:\r\n print(i,end=\" \")\r\n", "n=int(input())\r\nans=[]\r\nfor i in range(2,n+1,2):\r\n ans.append(str(i))\r\nfor i in range(1,n+1,2):\r\n ans.append(str(i))\r\nfor i in range(2,n+1,2):\r\n ans.append(str(i))\r\nprint(len(ans))\r\nprint(' '.join(ans))", "n = int(input())\r\nans = (n//2)+(n%2)+(2*(n//2))\r\nprint(ans)\r\nfor i in range(2, n+1, 2):\r\n print(i, end = ' ')\r\nfor i in range(1, n+1, 2):\r\n print(i, end = ' ')\r\nfor i in range(2, n+1, 2):\r\n print(i, end = ' ')", "n = int(input())\r\nans = []\r\n\r\nfor i in range(1, n+1):\r\n if i%2==0:\r\n ans.append(i)\r\n \r\nfor i in range(1, n+1):\r\n if i%2==1:\r\n ans.append(i)\r\n\r\nfor i in range(1, n+1):\r\n if i%2==0:\r\n ans.append(i)\r\n\r\nprint(len(ans))\r\nprint(*ans)", "n = int(input())\nres = []\nres.append((n//2)+n)\ni = 2\nwhile(i<=n):\n res.append(i)\n i+=2\ni = 1\nwhile(i<=n):\n res.append(i)\n i+=2\ni = 2\nwhile(i<=n):\n res.append(i)\n i+=2\n\nprint(res[0])\nn = len(res)\nfor i in range(1,n):\n print(res[i],end=\" \")", "n=int(input())\r\nprint(n+n//2)\r\na=[]\r\nfor i in range(2,n+1,2):\r\n a.append(i)\r\nfor i in range(1,n+1,2):\r\n a.append(i)\r\nfor i in range(2,n+1,2):\r\n a.append(i)\r\nprint(*a)", "n = int(input())\n\nans = []\n\nif n%2 == 0:\n print((3 * n)//2)\nelse:\n print(n//2 + n)\n\nfor j in range(2, n+1, 2):\n print(j, end = ' ')\n\nfor i in range(1, n+1, 2):\n print(i, end=' ')\nfor j in range(2, n+1, 2):\n print(j, end = ' ')\n\nprint()\n\n \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\nd = []\r\nfor i in range(2, n+1, 2):\r\n d.append(i)\r\nfor i in range(1, n+1, 2):\r\n d.append(i)\r\nfor i in range(2, n+1, 2):\r\n d.append(i)\r\nprint(len(d))\r\nprint(' '.join(map(str, d)))\r\n", "n = int(input())\r\nprint(n // 2 + n)\r\narr = [i for i in range(2,n+1,2)]+[i for i in range(1,n+1,2)]+[i for i in range(2,n+1,2)]\r\nprint(*arr)", "n = int(input())\r\nx = list(range(2, n+1, 2))\r\ny = list(range(1, n+1, 2))\r\nprint(len(x + y + x))\r\nprint(*(x + y + x))\r\n", "# ========= /\\ /| |====/|\r\n# | / \\ | | / |\r\n# | /____\\ | | / |\r\n# | / \\ | | / |\r\n# ========= / \\ ===== |/====| \r\n# code\r\n\r\ndef main():\r\n n = int(input())\r\n k1 = [i for i in range(2 , n + 1 , 2)]\r\n k2 = [i for i in range(1 , n + 1 , 2)]\r\n k = k1 + k2 + k1\r\n print(len(k))\r\n print(*k)\r\n return\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n = int(input())\r\nprint(n + n // 2)\r\nfor i in range(2, n + 1, 2):\r\n print(i, end = ' ')\r\nfor i in range(1, n + 1, 2):\r\n print(i, end = ' ')\r\nfor i in range(2, n + 1, 2):\r\n print(i, end = ' ')", "import itertools as it\r\n\r\nn = int(input())\r\nres = list(it.chain(\r\n range(2, n+1, 2),\r\n range(1, n+1, 2),\r\n range(2, n+1, 2)\r\n ))\r\nprint(len(res))\r\nprint(' '.join(map(str, res)))", "def solve():\r\n n = int(input())\r\n print(n + n // 2, end='\\n')\r\n for i in range(2, n + 1, 2):\r\n print(i, end=' ')\r\n for i in range(1, n + 1, 2):\r\n print(i, end=' ')\r\n for i in range(2, n + 1, 2):\r\n print(i, end=' ')\r\n\r\nt = 1\r\nwhile t > 0:\r\n solve()\r\n t -= 1\r\n", "n = int(input())\r\nif n==1:\r\n print(2)\r\n print(1, 1)\r\n exit(0)\r\n \r\nprint(n//2 + (n+1)//2 + n//2)\r\nfor i in range(1, n, 2):\r\n print(i+1, end=\" \")\r\nfor i in range(0, n, 2):\r\n print(i+1, end=\" \")\r\nfor i in range(1, n, 2):\r\n print(i+1, end=\" \")", "n=int(input())\r\nans=[]\r\nfor i in range(2,n+1,2):\r\n ans.append(i)\r\nfor i in range(1,n+1,2):\r\n ans.append(i)\r\nfor i in range(2,n+1,2):\r\n ans.append(i)\r\nprint(len(ans))\r\nprint(*ans)", "n=int(input())\r\nprint(2*(n//2)+(n+1)//2)\r\nodd=[i for i in range(1,n+1,2)]\r\neven=[i for i in range(2,n+1,2)]\r\nprint(*even,end=\" \")\r\nprint(*odd,end=\" \")\r\nprint(*even)\r\n" ]
{"inputs": ["2", "3", "4", "6", "10", "15", "100", "100000", "55333", "42273", "29857", "27687", "25517", "23347", "10931", "98514", "6591", "94174", "92004", "59221", "46806", "54882", "42466", "40296", "27880", "25710", "23540", "11124", "8954", "85387", "72971", "81047", "5"], "outputs": ["3\n2 1 2 ", "4\n2 1 3 2 ", "6\n2 4 1 3 2 4 ", "9\n2 4 6 1 3 5 2 4 6 ", "15\n2 4 6 8 10 1 3 5 7 9 2 4 6 8 10 ", "22\n2 4 6 8 10 12 14 1 3 5 7 9 11 13 15 2 4 6 8 10 12 14 ", "150\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 ", "150000\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ...", "82999\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "63409\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "44785\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "41530\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "38275\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "35020\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "16396\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "147771\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ...", "9886\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 28...", "141261\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ...", "138006\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ...", "88831\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "70209\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "82323\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "63699\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "60444\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "41820\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "38565\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "35310\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "16686\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "13431\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 2...", "128080\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ...", "109456\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ...", "121570\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 272 274 276 278 ...", "7\n2 4 1 3 5 2 4 "]}
UNKNOWN
PYTHON3
CODEFORCES
57
18cd04f66c3a25d8ef9c84aaf20ac88c
Vicious Keyboard
Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string. The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. Sample Input VK VV V VKKKKKKKKKVVVVVVVVVK KVKV Sample Output 1 1 0 3 1
[ "l=input()\r\ns=[]\r\nfor i in l:\r\n\tif(i=='V'):\r\n\t\ts.append(1)\r\n\telse:\r\n\t\ts.append(0)\r\nls=len(s)\r\ni=0\r\nmaxc = 0\r\nc = 0\r\nwhile i+1<ls:\r\n\tif(s[i]==1 and s[i+1]==0):\r\n\t\tc+=1\r\n\ti+=1\r\nmaxc = max(maxc,c)\r\nj=0\r\nwhile j<ls:\r\n\tif(s[j]==1):\r\n\t\ts[j]=0\r\n\telse:\r\n\t\ts[j]=1\r\n\ti=0\r\n\tc=0\r\n\twhile i+1<ls:\r\n\t\tif(s[i]==1 and s[i+1]==0):\r\n\t\t\tc+=1\r\n\t\ti+=1\r\n\tmaxc=max(c,maxc)\r\n\tif(s[j]==1):\r\n\t\ts[j]=0\r\n\telse:\r\n\t\ts[j]=1\r\n\tj+=1\r\nprint(maxc)", "s = input().strip()\r\ns = s.replace(\"VK\", \"*\")\r\ncnt = sum(map(lambda x: x==\"*\",s))\r\nif \"VV\" in s or \"KK\" in s:\r\n cnt +=1\r\nprint(cnt) ", "count=0\r\ncountk=0\r\ncountv=0\r\n\r\ndef st0(List,i):\r\n global countk\r\n temp=0\r\n while i<len(List) and List[i]=='K':\r\n temp+=1\r\n i+=1\r\n countk=max(countk,temp)\r\n if i==len(List):\r\n return \r\n st1(List,i+1)\r\n\r\ndef st1(List,i):\r\n global count\r\n if i< len(List) and List[i]=='K':\r\n count+=1\r\n st0(List,i+1)\r\n elif i<len(List) and List[i]=='V':\r\n st2(List,i+1)\r\n elif i==len(List):\r\n return\r\n\r\ndef st2(List,i):\r\n global countv\r\n global count\r\n temp=2\r\n while i<len(List) and List[i]=='V':\r\n temp+=1\r\n i+=1\r\n if i==len(List):\r\n countv=max(temp,countv)\r\n return\r\n elif List[i]=='K':\r\n count+=1\r\n temp-=1\r\n countv=max(temp,countv)\r\n st0(List,i+1)\r\n\r\n\r\nList=list(input().strip())\r\ntry:\r\n st0(List,0)\r\nexcept:\r\n pass\r\n#print(count,countv,countk)\r\ncountk=max(countv-1,countk-1)\r\nif countk>0:\r\n count+=1\r\nprint(count)\r\n", "#!/usr/bin/env python\nimport sys\n\ndef countAndReplace(s,needle,repl):\n assert(len(needle) == len(repl))\n cnt = 0\n offset = 0\n while True:\n p = s.find(needle,offset)\n\n if -1 == p:\n break\n\n cnt += 1\n offset = p + len(needle)\n s = s[0:p] + repl + s[offset:]\n\n return s, cnt\n\ns = sys.stdin.readline().strip()\ns,cnt = countAndReplace(s,\"VK\",\"XX\")\n\nfor i in range(0,len(s)):\n c = s[i]\n if 'X' == c:\n continue\n\n if 'V' == c and i > 0 and s[i - 1] == 'V':\n cnt += 1\n break\n\n if 'K' == c and i > 0 and s[i - 1] == 'K':\n cnt += 1\n break\n\nprint(cnt)\n", "s = input()\nprint(max( (s[:i] + c + s[i+1:]).count('VK') for i in range(len(s)) for c in ['V', 'K'] ))", "s=input()\r\nn=len(s)\r\ncnt=0\r\nflag=1\r\nlight=[1 for j in range(n)]\r\ni=0\r\nwhile i<n:\r\n if i<n-1 and s[i]=='V' and s[i+1]=='K':\r\n cnt+=1\r\n light[i]=light[i+1]=0\r\n i+=2\r\n else:\r\n i+=1\r\ni=0\r\nwhile i<n and flag:\r\n if i<n-1 and s[i]=='V' and s[i+1]=='V' and light[i] and light[i+1]:\r\n cnt+=1\r\n flag=0\r\n elif i<n-1 and s[i]=='K' and s[i+1]=='K' and light[i] and light[i+1]:\r\n cnt+=1\r\n flag=0\r\n else:\r\n i+=1\r\nprint(cnt)", "s = input()\r\nprint(max((s[:i]+ letter + s[i + 1:]).count('VK') for letter in 'VK' for i in range(len(s))))\r\n\r\n", "a = input()\r\ns = []\r\nfor i in a:\r\n s.append(i)\r\nk = a.count('VK')\r\nif len(s)<2:\r\n print(0)\r\nelse:\r\n if (a.count('VVV')>0 or (s[-2]+s[-1])=='VV') or (a.count('KKK')>0 or (s[0]+s[1])=='KK'):\r\n print(k+1)\r\n else:\r\n print(k)", "\ndef naive_realization():\n s = input()\n\n count = s.count(\"VK\")\n n = len(s)\n for i in range(n):\n copy_s = list(s[:])\n copy_s[i] = 'V'\n copy_s_str = ''.join(copy_s)\n count = max(count, copy_s_str.count(\"VK\"))\n\n for i in range(n):\n copy_s = list(s[:])\n copy_s[i] = 'K'\n copy_s_str = ''.join(copy_s)\n count = max(count, copy_s_str.count(\"VK\"))\n\n print(count)\n\nnaive_realization()\n", "s = input()\r\n \r\nvk_count = s.count('VK')\r\ns = s.replace('VK', 'XX')\r\n\r\nif 'VV' in s or 'KK' in s:\r\n vk_count += 1\r\n\r\nprint(vk_count)", "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\ninput=sys.stdin.readline\r\ns=input()\r\nn=len(s)-1\r\nc=s.count('VK')\r\nfor i in range(n):\r\n if(s[i]=='V'):\r\n s1=s[:i]+'K'+s[i+1:]\r\n else:\r\n s1=s[:i]+'V'+s[i+1:]\r\n c=max(c,s1.count('VK'))\r\nprint(c)", "s=input()\na=s.count(\"VK\")\ns=s.replace(\"VK\",\" \")\nif \"VV\" in s or \"KK\" in s:\n a+=1\nprint(a)\n\n \t\t \t\t\t \t\t \t\t\t\t\t \t \t\t", "X = input()\r\nVK = X.count(\"VK\")\r\nCount = 0\r\nSize = len(X)\r\ni = Size - 1\r\nwhile i >= 1:\r\n Count += (1 if X[i - 1] + X[i] == \"VV\" else 0)\r\n i = (i - 2 if X[i - 1] + X[i] in ['VV', 'VK'] else i - 1)\r\ni = 0\r\nwhile i < Size - 1:\r\n Count += (1 if X[i] + X[i + 1] == \"KK\" else 0)\r\n i = (i + 2 if X[i] + X[i + 1] in ['KK', 'VK'] else i + 1)\r\nprint(VK + min(Count, 1))\r\n# UB_CodeForces\r\n# Advice: Falling down is an accident, staying down is a choice\r\n# Location: Here in Bojnurd\r\n# Caption: Being followed by my friend ESSI\r\n# CodeNumber: 617\r\n", "a = input()\r\nb = [a.count('VK')] + [0] * len(a)\r\ns = a[:]\r\nfor i in range(len(a)):\r\n if a[i] == 'V':\r\n if i != len(a) - 1:\r\n s = s[:i] + 'K' + s[i + 1:]\r\n else:\r\n s = s[:i] + 'K'\r\n else:\r\n if i != len(a) - 1:\r\n s = s[:i] + 'V' + s[i + 1:]\r\n else:\r\n s = s[:i] + 'V'\r\n b[i+1] = s.count('VK')\r\n s = a[:]\r\nprint(max(b))", "s = input()\r\n\r\nc0 = s.count('VK')\r\n\r\nif 'VVV' in s or 'KKK' in s:\r\n c1 = 1\r\nelif s[:2] == 'KK' or s[-2:] == 'VV':\r\n c1 = 1\r\nelse:\r\n c1 = 0\r\n\r\nprint(c0 + c1)", "def vkc(s):\r\n list1=list(s)\r\n count=0\r\n for i in range(len(s)-1):\r\n if list1[i:i+2]==['V','K']:\r\n count+=1\r\n return count\r\ns=str(input())\r\nlist1=[]\r\nfor i in range(len(s)):\r\n if s[i]==\"V\":\r\n s1=s[0:i]+\"K\"+s[i+1:]\r\n #print(s1)\r\n list1.append(vkc(s1))\r\n elif s[i]==\"K\":\r\n s1=s[0:i]+\"V\"+s[i+1:]\r\n #print(s1)\r\n list1.append(vkc(s1))\r\nlist1.append(vkc(s))\r\nprint(max(list1))\r\n ", "def f(l):\r\n c = l.count('VK')\r\n if 'KKK' in l or 'VVV' in l or l[:2] == 'KK' or l[-2:] == 'VV':\r\n c += 1\r\n return c\r\n\r\nprint(f(input()))", "#lst = list(map(int, input().strip().split(' ')))\r\n#n,k = map(int, input().strip().split(' '))\r\ns=input()\r\nl=len(s)\r\ns=list(s)\r\nif l==1:\r\n print(0)\r\nelse:\r\n c=0\r\n f=0\r\n i=0\r\n while(i<l-1):\r\n if s[i]=='V' and s[i+1]=='K':\r\n c+=1\r\n i+=2\r\n elif s[i]=='K' and s[i+1]=='V':\r\n i+=1\r\n elif f==0 and s[i]=='K' and s[i+1]=='K':\r\n f=1\r\n c+=1\r\n i+=2\r\n else:\r\n if f==0 and i<l-2 and s[i+2]=='V':\r\n f=1\r\n c+=1\r\n i+=2\r\n elif f==0 and i<l-2 and s[i+2]=='K': \r\n i+=1\r\n elif f==0:\r\n c+=1\r\n f=1\r\n i+=2\r\n else:\r\n i+=1\r\n print(c) \r\n \r\n", "import sys\r\nimport math\r\ns = input()\r\ncnt = s.count(\"VK\");\r\nif s[:2] == \"KK\":\r\n cnt += 1\r\nelif s[-2:] == 'VV':\r\n cnt += 1\r\nelif s.find(\"VVV\") >= 0:\r\n cnt += 1\r\nelif s.find(\"KKK\") >= 0:\r\n cnt += 1\r\nprint(cnt)", "arr = [c for c in input()]\ncount = 0\n\nfor i in range(len(arr)):\n if i + 1 < len(arr):\n if 'V' == arr[i] and 'K' == arr[i + 1]:\n count += 1\n arr[i] = '_'\n arr[i + 1] = '_'\n\nstring = ''.join(arr)\n\nif 'VV' in string or 'KK' in string:\n count += 1\n\nprint(count)\n", "s = input()\r\n\r\nk = s.split(\"VK\")\r\n\r\nm = len(k) - 1\r\n\r\nfor i in range(len(k)):\r\n if \"KK\" in k[i] or \"VV\" in k[i]:\r\n m+=1\r\n break\r\nprint(m)\r\n", "s=input()\r\ns=s.replace(\"VK\",\"A\")\r\nsum=0\r\nif \"KK\" in s or \"VV\" in s:\r\n sum=1\r\nwhile len(s)>0 and s.find(\"A\") != -1:\r\n sum+=1\r\n s=s[s.find(\"A\")+1:]\r\nprint(sum)", "f=' '\nf+=input()\nn=len(f)\nk=0\nq=0\ni=2\nf+=' '\nwhile i<n:\n\tif f[i]+f[i+1]==\"VK\":\n\t\tk+=1\n\t\ti+=1\n\telif f[i]+f[i+1]==\"VV\" and f[i+2]!='K':\n\t\tq+=1\n\t\ti+=1\n\telif f[i]+f[i+1]==\"KK\" and f[i-1]!='V':\n\t\tq+=1\n\ti+=1\nprint(k+(q>0))\n\t\t", "s = list(input().strip())\r\n\r\ni = 0\r\n\r\ncnt = (\"\".join(s)).count(\"VK\")\r\n\r\nindices = []\r\nwhile i < len(s) - 1:\r\n if s[i] == 'V' and s[i+1] == 'K': \r\n indices.append(i)\r\n indices.append(i+1)\r\n i += 2\r\n else:\r\n i += 1\r\n\r\n\r\nfor i in range(len(s)-1):\r\n if (s[i] == 'V' and s[i+1] == 'V') or (s[i] == 'K' and s[i+1] == 'K'):\r\n if (i not in indices) and (i+1 not in indices):\r\n cnt += 1\r\n break\r\n\r\nprint(cnt)", "s='K'+input()+'V'\r\nprint(s.count('VK')+('VVV'in s or'KKK'in s))", "s = input()\ncount = s.count('VK')\ns = s.replace('VK','__')\nif 'VV' in s or 'KK' in s:\n count += 1 \n\nprint(count)\n", "s=input()\r\nx=s\r\n \r\nif len(s)==1:\r\n print(\"0\")\r\nelif len(s)==2:\r\n if s==\"KV\":\r\n print(\"0\")\r\n else:\r\n print(\"1\")\r\nelse:\r\n q=0\r\n for f in range(int(len(s)-1)):\r\n if s[f]==\"V\" and s[f+1]==\"K\":\r\n q+=1\r\n \r\n y=q\r\n for i in range(int(len(s))):\r\n z=0\r\n if s[i]==\"V\":\r\n s=s[:i]+\"K\"+s[i+1:]\r\n for f in range(int(len(s)-1)):\r\n if s[f]==\"V\" and s[f+1]==\"K\":\r\n z+=1\r\n y=max(y,z)\r\n s=x\r\n else:\r\n s=s[:i]+\"V\"+s[i+1:]\r\n for f in range(int(len(s)-1)):\r\n if s[f]==\"V\" and s[f+1]==\"K\":\r\n z+=1\r\n y=max(y,z)\r\n s=x\r\n print(y) \r\n \r\n ", "s=list(input())\r\nb=[]\r\nans=0\r\ni=1\r\nwhile i<len(s):\r\n if (s[i]=='K')and(s[i-1]=='V'):\r\n ans+=1\r\n b.append(i)\r\n b.append(i-1)\r\n i+=2\r\n else:i+=1\r\ni=1\r\nwhile i<len(s):\r\n if (((s[i]=='V')and(s[i-1]=='V'))or(((s[i]=='K')and(s[i-1]=='K'))))and((b.count(i)==0)and(b.count(i-1)==0)):\r\n ans+=1\r\n break\r\n else:i+=1\r\nprint(ans)\r\n\r\n", "word = input()\r\nres = word.count(\"VK\")\r\nm = set(word.split(\"VK\"))\r\nif any(len(x) > 1 for x in m if x != \"KV\"):\r\n res += 1\r\nprint(res)", "import re\ndef count(s):\n return len(re.findall(r'VK', s))\n\ns = input().strip()\nbest = count(s)\nfor i in range(len(s)):\n cur_s = s[:i] + 'V' + s[i + 1:]\n best = max(best, count(cur_s))\n cur_s = s[:i] + 'K' + s[i + 1:]\n best = max(best, count(cur_s))\nprint(best)\n", "string = input()\nlength = len(string)\nmaximum = 0\nj=0\nfor i in range(length-1):\n\tif(string[i] == 'V' and string[i+1] == 'K'):\n\t\tj+=1\nif(j>maximum):\n\tmaximum = j\n\nif(string[0] == 'V'):\n\tstring = 'K'+string[1:]\nelse:\n\tstring = 'V'+string[1:]\nj=0\t\nfor i in range(length-1):\n\tif(string[i] == 'V' and string[i+1] == 'K'):\n\t\tj+=1\nif(j>maximum):\n\tmaximum = j\n\nfor counter in range(1,length):\n\tif(string[counter-1] == 'V'):\n\t\tstring = string[:counter-1]+'K'+string[counter:]\n\telse:\n\t\tstring = string[:counter-1]+'V'+string[counter:]\n\tif(string[counter] == 'V'):\n\t\tstring = string[:counter]+'K'+string[counter+1:]\n\telse:\n\t\tstring = string[:counter]+'V'+string[counter+1:]\n\tj=0\t\n\tfor i in range(length-1):\n\t\tif(string[i] == 'V' and string[i+1] == 'K'):\n\t\t\tj+=1\n\tif(j>maximum):\n\t\tmaximum = j\nprint(maximum)\n", "s=input()\r\nd={'V':'K','K':'V'}\r\nans=s.count('VK')\r\nfor i in range(len(s)):\r\n ts=s[:i]+d[s[i]]+s[i+1:]\r\n ans=max(ans,ts.count('VK'))\r\nprint(ans)", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ns = list(input().rstrip())\r\nn = len(s)\r\nans = 0\r\nfor i in range(n - 1):\r\n if not s[i] & 1 and s[i + 1] & 1:\r\n ans += 1\r\nfor i in range(n):\r\n s[i] ^= 1\r\n c = 0\r\n for j in range(n - 1):\r\n if not s[j] & 1 and s[j + 1] & 1:\r\n c += 1\r\n ans = max(ans, c)\r\n s[i] ^= 1\r\nprint(ans)", "s = input()\r\nmaxi = s.count('VK')\r\nfor i in range(len(s)):\r\n if s[i] == 'K':\r\n t = s[:i] + 'V' + s[i+1:]\r\n maxi = max(maxi, t.count('VK'))\r\n else:\r\n t = s[:i] + 'K' + s[i+1:]\r\n maxi = max(maxi, t.count('VK'))\r\n\r\nprint(maxi)\r\n", "def get(s):\r\n res = 0\r\n for i in range(len(s) - 1):\r\n if s[i] == 'V' and s[i + 1] == 'K':\r\n res += 1\r\n \r\n return res\r\n\r\n\r\ns = input()\r\nl = list(s)\r\n\r\nans = 0\r\nfor i in range(len(l)):\r\n st = l[i]\r\n \r\n l[i] = 'V'\r\n ans = max(ans, get(''.join(l)))\r\n \r\n l[i] = 'K'\r\n ans = max(ans, get(''.join(l)))\r\n \r\n l[i] = st\r\n \r\nprint(ans)", "s=input()\r\ns='K'+s+'V'\r\nc=s.count('VK')\r\nif('VVV' in s or 'KKK' in s):\r\n c+=1\r\nprint(c)", "str = input()\r\n\r\nans = str.count(\"VK\")\r\n\r\nstr = str.replace(\"VK\", \"R\")\r\n\r\nflag = False\r\n\r\nfor s in str.split(\"R\"):\r\n if \"VV\" in s or \"KK\" in s:\r\n flag = True\r\n break\r\n\r\nif flag:\r\n ans += 1\r\n\r\nprint(ans)\r\n", "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\ndef istr():\n return sys.stdin.readline().strip()\n\n###\n\ns = list(istr())\n\nans = 0\nfor i in range(len(s)-1):\n if s[i] == \"V\" and s[i+1] == \"K\":\n ans += 1\n s[i], s[i+1] = \"x\", \"x\"\n\ns = \"\".join(s)\n\nif \"VV\" in s or \"KK\" in s:\n ans += 1\n\nprint(ans)", "import sys\r\nimport re\r\n\r\ndef solve():\r\n str = input()\r\n sadd=0;\r\n stot=0;\r\n if (str[0:2]=='KK') | (str[~1:]=='VV') :\r\n sadd=1\r\n elif (str.find('KKK')>-1) | (str.find('VVV')>-1):\r\n sadd=1\r\n mm=[m.start() for m in re.finditer('VK',str)]\r\n print(len(mm)+sadd)\r\n\r\nif __name__ == '__main__':\r\n solve()\r\n", "\r\ns = input()\r\n\r\nif len(s) == 1:\r\n print(0)\r\n\r\nelif len(s) == 2:\r\n if s == \"KV\":\r\n print(0)\r\n else:\r\n print(1)\r\n \r\nelse:\r\n count = s.count('VK')\r\n if s.find('VVV') != -1 or s.find('KKK') != -1 or s[:2] == 'KK' or s[-2:] == 'VV':\r\n print(count+1)\r\n else:\r\n print(count)", "s = \"-\"+input()+\"-\"\r\np = 0\r\nsh = 0\r\nfor i in range(1,len(s)-2):\r\n if s[i]+s[i+1]==\"VK\":\r\n sh += 1\r\n if s[i]+s[i+1]==\"KK\" and p==0:\r\n if s[i-1]==\"-\" or s[i-1]==\"K\":\r\n sh += 1\r\n p += 1\r\n if s[i]+s[i+1]==\"VV\" and p==0:\r\n if s[i+2]==\"-\" or s[i+2]==\"V\":\r\n sh += 1\r\n p += 1\r\nprint(sh)\r\n \r\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\ns = input()\n\nans = s.count('VK')\nf = s[-2:] == 'VV' or s[:2] == 'KK' or s.find('VVV') != -1 or s.find('KKK') != -1\n\nif f:\n ans += 1\nprint(ans)\n", "\"\"\"\r\n Vicious Keyboard\r\n\"\"\"\r\nimport sys\r\ns = input()\r\ncount = s.count('VK')\r\ni = 0\r\nfor i in range(len(s) - 1):\r\n if(s[i] == 'K' and s[i+1] == 'K'):\r\n if(i == 0):\r\n count += 1\r\n break\r\n elif(i > 0):\r\n if(s[i-1] == 'K'):\r\n count += 1\r\n break\r\n elif(s[i] == 'V' and s[i+1] == 'V'):\r\n try:\r\n if(s[i+2] == 'V'):\r\n count += 1\r\n break\r\n except(IndexError):\r\n count += 1\r\n break\r\nprint(count)", "s = input()\r\nn = len(s)\r\nf = lambda s: sum(s[i:i+2] == 'VK' for i in range(n - 1))\r\nans = 0\r\nfor i in range(n):\r\n t = s[:i] + 'V' + s[i + 1:]\r\n ans = max(ans, f(t))\r\n t = s[:i] + 'K' + s[i + 1:]\r\n ans = max(ans, f(t))\r\nprint(ans)", "string = input()\nans = string.count('VK')\nfor i in range(len(string)):\n new_str = string[:i] + ('K' if string[i] == 'V' else 'V') + string[i + 1:]\n ans = max(ans, new_str.count('VK'))\n\nprint(ans)\n", "s = input()\r\nans = s.count(\"VK\")\r\ns = s.replace(\"VK\", \"ZZ\")\r\n\r\nif \"VV\" in s or \"KK\" in s:\r\n ans += 1\r\n\r\nprint(ans)\r\n", "s = input()\r\nsl = [i for i in s]\r\nimport re\r\nif(len(s)==1):\r\n print(0)\r\n exit(0)\r\nl = [k.start() for k in re.finditer('VK',s)]\r\nfor i in l:\r\n sl[i] = 0\r\n sl[i+1] = 0\r\nif(len(l)==len(s)//2):\r\n print(len(s)//2)\r\nelse:\r\n for i in range(len(sl)-1):\r\n if((sl[i]=='V' and sl[i+1]=='V') or (sl[i]=='K' and sl[i+1]=='K')):\r\n print(len(l)+1)\r\n exit(0)\r\n print(len(l))", "s = input()\r\nk = 0\r\nfor i in range(len(s) - 1):\r\n if s[i] == 'V' and s[i + 1] == 'K':\r\n k += 1\r\nfor i in range(len(s)):\r\n if i < len(s) - 1:\r\n if s[i] == 'V' and s[i + 1] == 'V' and i + 2 == len(s):\r\n k += 1\r\n break\r\n if s[i] == 'V' and s[i + 1] == 'V' and s[i + 2] == 'V':\r\n k += 1\r\n break\r\n if i >= 1:\r\n if i == 1 and s[1] == 'K' and s[0] == 'K':\r\n k += 1\r\n break\r\n if s[i] == 'K' and s[i- 1] == 'K' and s[i - 2] == 'K':\r\n k += 1\r\n break\r\nprint(k)", "s = input()\n\nres = max((s[:i] + j + s[i+1:]).count('VK') for j in 'VK' for i in range(len(s)))\nprint(res)\n", "s=input()\na=s\nc=s.count('VK')\nfor i in range(len(s)):\n a=s[:i] + ('V' if s[i]=='K' else 'K') + s[i+1:]\n c=max(c,a.count('VK'))\nprint(c)", "s = list(input())\n\ndef cnt(str):\n rtn = 0\n for i in range(1, len(str)):\n if str[i - 1] == 'V' and str[i] == 'K':\n rtn += 1\n return rtn\n\ndef change(str, idx):\n if str[idx] == 'V':\n return str[:idx] + ['K'] + str[idx + 1:]\n else:\n return str[:idx] + ['V'] + str[idx + 1:]\n\nans = cnt(s)\nfor i in range(len(s)):\n ans = max(cnt(change(s, i)), ans)\n\nprint(ans)\n", "# from collections import defaultdict\r\n# from sys import stdin\r\n# import itertools\r\n# import bisect\r\n# from math import sqrt,ceil,floor\r\n\r\ndef func(put,mapping,unpack):\r\n s = list(put(str))\r\n ans = 0\r\n for i in range(-1,len(s)):\r\n if i > -1: s[i] = 'V' if s[i] == 'K' else 'K'\r\n t = 0\r\n for j in range(len(s)-1):\r\n if s[j] == 'V' and s[j+1] == 'K': t += 1\r\n ans = max(ans,t)\r\n if i > -1: s[i] = 'V' if s[i] == 'K' else 'K'\r\n print(ans)\r\n \r\ndef init(TestCases=True):\r\n put = lambda s: s(input().strip())\r\n mapping = lambda s: list(map(s,input().split()))\r\n unpack = lambda s: map(s,input().split())\r\n for _ in range(int(input()) if TestCases else 1):\r\n func(put,mapping,unpack)\r\n\r\nif __name__ == '__main__':\r\n init(False)", "import sys\r\n\r\narr = list(sys.stdin.readline().rstrip())\r\nst = []\r\nans = 0\r\nidx = 0\r\nwhile idx < len(arr) - 1:\r\n if arr[idx] + arr[idx + 1] == 'VK':\r\n idx += 2\r\n ans += 1\r\n else:\r\n st.append((arr[idx], idx))\r\n idx += 1\r\nif idx == len(arr) - 1:\r\n st.append((arr[idx], idx))\r\ncan = False\r\nfor i in range(len(st) - 1):\r\n if st[i][0] == st[i + 1][0]:\r\n if abs(st[i][1] - st[i + 1][1]) == 1:\r\n can = True\r\n break\r\nprint(ans + 1 if can else ans)", "s = input()\r\ns = \"K\" + s + \"V\"\r\nans = s.count(\"VK\")\r\nif \"VVV\" in s or \"KKK\" in s:\r\n\tans += 1\r\nprint(ans)", "s1=input()\r\ns=list(s1)\r\nres=0\r\nfor j in range(len(s1)): \r\n a=s[j]\r\n res1=0\r\n s[j]='V'\r\n for i in range(len(s1)-1):\r\n if(s[i]=='V' and s[i+1]=='K'):\r\n res1+=1\r\n res=max(res,res1)\r\n res1=0\r\n s[j]='K'\r\n for i in range(len(s1)-1):\r\n if(s[i]=='V' and s[i+1]=='K'):\r\n res1+=1\r\n res=max(res,res1)\r\n s[j]=a\r\nprint(res)", "s=input()\r\na=s.count(\"VK\")\r\ns=s.replace(\"VK\",\" \")\r\na+=1 if \"VV\" in s or \"KK\" in s else 0\r\nprint(a)\r\n", "s = input()\r\nV = \"V\"\r\nK = \"K\"\r\n\r\ndef g(s):\r\n res = 0\r\n for i, c in enumerate(list(s)):\r\n if i == 0:\r\n continue\r\n if s[i] == K and s[i-1] == V:\r\n res += 1\r\n return res\r\n\r\ndef rev(c):\r\n if c == V:\r\n return K\r\n else:\r\n return V\r\n\r\nres = g(s)\r\nfor i in range(len(s)):\r\n res = max(res, g(s[:i]+rev(s[i])+s[i+1:]))\r\n\r\nprint(res)", "s=str(input())\nm=s.count('VK')\nfor i in range(len(s)):\n if s[i]=='V':\n t='K'\n else:\n t='V'\n temp=s[:i]+t+s[i+1:]\n #print(temp)\n if temp.count('VK')>m:\n m=temp.count('VK')\nprint(m)\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'''\nc=input()\nx=c.count(\"VK\")\nc=c.replace(\"VK\",\"O\")\nif \"VV\" in c or \"KK\" in c:\n x=x+1;\n \nprint(x)\n", "s = input()\r\nres = s.count('VK')\r\nbuf = ''\r\n\r\nfor i in range(len(s)):\r\n if s[i] == 'V':\r\n buf = s[:i] + 'K' + s[i+1:]\r\n else:\r\n buf = s[:i] + 'V' + s[i+1:]\r\n #print(buf)\r\n res = max(res, buf.count('VK'))\r\n\r\nprint(res, end = '')", "\r\n\r\n\r\nword = input()\r\nl = []\r\nfor i in range(len(word)):\r\n for j in 'VK':\r\n l.append((word[:i] + j +word[i+1:]).count('VK'))\r\n\r\nprint (max(l))", "s = input()\r\nmx = s.count('VK')\r\nd = {'V':'K', 'K':'V'}\r\nfor i in range(len(s)):\r\n mx = max(mx, (s[:i]+d[s[i]]+s[i+1:]).count('VK'))\r\nprint(mx)", "s = input()\r\ni = 1\r\nk = s.count('VK')\r\ns = s.replace('VK', ' ')\r\nfor (i1, c1), (i2, c2) in zip(enumerate(s), enumerate(s[1:])):\r\n if c1 == 'V' and c2 == 'V':\r\n k += 1\r\n break\r\n if c1 == 'K' and c2 == 'K':\r\n k += 1\r\n break\r\nprint(k)\r\n", "s=input()\r\nx=s.count('VK')\r\nn=len(s)\r\nif s[0:2]=='KK' or s[n-2:n]=='VV':\r\n print(x+1)\r\nelse:\r\n b=s.find('VVV')\r\n c=s.find('KKK')\r\n \r\n if b!=-1 or c!=-1:\r\n print(x+1)\r\n else:\r\n print(x)\r\n", "s = input()\r\n\r\nans = 0\r\nfor i in range(len(s)):\r\n for j in ['V', 'K']:\r\n t = s[:i] + j + s[i + 1:]\r\n cur = 0\r\n for k in range(len(s) - 1):\r\n if t[k] == 'V' and t[k + 1] == 'K':\r\n cur += 1\r\n ans = max(ans, cur)\r\nprint(ans)\r\n ", "def c(S):\r\n a=0\r\n for i in range(len(S)-1):\r\n if s[i]=='V' and s[i+1]=='K':a+=1\r\n return a\r\nx=input()\r\ns=[z for z in x]\r\nr=0\r\nfor i in range(len(s)):\r\n t=s[i]\r\n if s[i]=='V':s[i]='K'\r\n else: s[i]='V'\r\n r=max(r,c(s))\r\n if s[i]=='V':s[i]='K'\r\n else: s[i]='V'\r\n r=max(r,c(s))\r\nprint(r)", "s = input()\r\ncnt = s.count('VK')\r\ns = s.replace('VK', '*')\r\nprint(cnt+1 if s.count('VV') or s.count('KK') else cnt)", "s = input().lower()\nmaxf = s.count('vk')\nfor i in range(len(s)):\n if s[i] == 'v':\n sc = s[:i] + 'k' + s[i+1:]\n if s[i] == 'k':\n sc = s[:i] + 'v' + s[i+1:]\n k = sc.count('vk')\n if k > maxf: maxf = k\nprint(maxf)", "seq = input()\r\nans = seq.count( \"VK\" )\r\nfor i in range( len( seq ) ):\r\n if 0 < i and seq[ i ] == 'V':\r\n if seq[ i - 1 ] == 'V':\r\n if i + 1 == len( seq ) or seq[ i : i + 2 ] != \"VK\":\r\n exit( print( ans + 1 ) )\r\n if i + 1 < len( seq ) and seq[ i ] == 'K':\r\n if seq[ i + 1 ] == 'K':\r\n if i == 0 or seq[ i - 1 : i + 1 ] != \"VK\":\r\n exit( print( ans + 1 ) )\r\nprint( ans )\r\n", "s = input ()\r\nans = 0\r\nfor i in range (len (s)):\r\n ans = max (ans, s.count (\"VK\"))\r\n if s [i] == \"V\":\r\n s = s[:i] + \"K\" + s [i + 1:len(s)]\r\n ans = max (ans, s.count (\"VK\"))\r\n s = s [:i] + \"V\" + s [i + 1:len (s)]\r\n \r\n else:\r\n s = s [:i] + \"V\" + s [i + 1:len (s)]\r\n ans = max (ans, s.count (\"VK\"))\r\n s = s [:i] + \"K\" + s [i + 1:len (s)]\r\nprint (ans)", "s = input()\r\nwyn = 0\r\nprev = s[0]\r\npoint = False\r\nadd = False\r\nvadd = False\r\nfor i in s[1:]:\r\n if vadd and i == \"K\":\r\n vadd = False\r\n elif vadd and i == \"V\":\r\n add = True\r\n if point:\r\n point = False\r\n elif i == \"K\" and prev == \"V\":\r\n wyn += 1\r\n point = True\r\n elif i == \"K\" and prev == \"K\":\r\n add = True\r\n elif i == \"V\" and prev == \"V\":\r\n vadd = True\r\n prev = i\r\nif add or vadd:\r\n print(wyn + 1)\r\nelse:\r\n print(wyn)\r\n", "#!/usr/bin/env python3\nimport re\n\n\ndef solve():\n s = input()\n m = 0\n for i in range(len(s)):\n m = max(m, len(re.findall(\"VK\", s[:i]+\"V\"+s[i+1:])))\n m = max(m, len(re.findall(\"VK\", s[:i]+\"K\"+s[i+1:])))\n print(m)\n\n\nif __name__ == '__main__':\n solve()\n", "s=input()\r\nif len(s)==1:\r\n print(0)\r\nelse:\r\n x=s.count('VK')\r\n for i in range(len(s)):\r\n if s[i]=='K':\r\n if i<len(s)-1 and s[i+1]=='K' and (i==0 or s[i-1]=='K'):\r\n x+=1\r\n break\r\n elif i>0 and s[i-1]=='V' and (i==len(s)-1 or s[i+1]=='V'):\r\n x+=1\r\n break\r\n print(x)\r\n", "a = input()\nc = a.count(\"VK\")\na = a.replace(\"VK\",\"_\")\nif \"VV\" in a or \"KK\" in a:\n c += 1\nprint(c)", "s = list(input())\r\ns_v = s[:]\r\ns_k = s[:]\r\n\r\nfor i in range(len(s) - 1):\r\n if s[i] == \"K\" and s[i+1] == \"K\" and (i == 0 or (i > 0 and s[i - 1] != \"V\")):\r\n s_v[i] = \"V\"\r\n break\r\n\r\nfor i in range(1, len(s)):\r\n if s[i] == \"V\" and s[i-1] == \"V\" and (i == len(s) - 1 or (i < len(s) - 1 and s[i+1] != \"K\")):\r\n s_k[i] = \"K\"\r\n break\r\n\r\nresult = map(lambda x: \"\".join(x).count(\"VK\"), [s, s_v, s_k])\r\n\r\nprint(max(result))\r\n", "def vk(S):\r\n ans = 0\r\n \r\n for i in range(1, len(S)):\r\n if S[i-1] == 'V' and S[i] == 'K':\r\n ans += 1\r\n return ans\r\n\r\n\r\nS = list(input())\r\n\r\ncur = vk(S)\r\n\r\nfor i in range(len(S)):\r\n tem = S[i]\r\n S[i] = 'V'\r\n cur = max(cur, vk(S))\r\n S[i] = tem\r\n \r\nfor i in range(len(S)):\r\n tem = S[i]\r\n S[i] = 'K'\r\n cur = max(cur, vk(S))\r\n S[i] = tem\r\n\r\nprint(cur) \r\n \r\n ", "vk = input()\nvk = list(vk)\nvk.append(0)\nchanged = False\ni = 0\ncount = 0\nwhile True:\n if i >= len(vk) - 2:\n break\n if vk[i] == 'V':\n if vk[i + 1] == 'K':\n count += 1\n i += 2\n continue\n elif changed is False and (vk[i + 2] == 'V' or vk[i + 2] == 0):\n changed = True\n count += 1\n i += 2\n continue\n elif changed is False and vk[i + 1] == 'K':\n count += 1\n changed = True\n i += 2\n continue\n i += 1\nprint(count)\n", "import re\r\ns = input()\r\nss = re.findall(r\"VK\", s)\r\nans = len(ss)\r\nans2 = re.split(r\"VK\", s)\r\nfor i in ans2:\r\n if \"KK\" in i or \"VV\" in i:\r\n ans += 1\r\n break\r\nprint(ans)", "a=input()\r\ns=0\r\nd=[]\r\nd1=[]\r\nf=0\r\nff=0\r\np=[]\r\nfor i in range(len(a)):\r\n if i!=len(a)-1:\r\n if a[i]+a[i+1]=='VK':\r\n s=s+1\r\n d.append(i+1)\r\n d1.append(i)\r\nfor i in range(len(a)):\r\n if i!=len(a)-1:\r\n if a[i]+a[i+1]=='KK' and i not in d or a[i]+a[i+1]=='VV' and i+1 not in d1:\r\n s=s+1\r\n break\r\nif len(a)!=1:\r\n print(s)\r\nelse:\r\n print(0)\r\n\r\n \r\n", "s = input()\r\nl = len(s)\r\nnumbers = [s.count(\"VK\")]\r\nfor x in range(l):\r\n temp = s[:x]\r\n a = s[x]\r\n if a == \"V\":\r\n temp += \"K\"\r\n else:\r\n temp += \"V\"\r\n temp += s[x + 1:]\r\n numbers.append(temp.count(\"VK\"))\r\nprint(max(numbers))\r\n", "#!/usr/bin/env python3\n\nS = list(input())\n\n\ndef count(S):\n y = 0\n for i in range(1, len(S)):\n if S[i] == 'K' and S[i - 1] == 'V':\n y += 1\n return y\n\nmost = count(S)\n\nfor i in range(0, len(S)):\n S[i] = 'V' if S[i] == 'K' else 'K'\n most = max(most, count(S))\n S[i] = 'V' if S[i] == 'K' else 'K'\n\nprint(most)\n", "#!/usr/local/bin/python3\nimport pdb\nkeyboard_input = input()\n\n\nminimal = str(keyboard_input).count(\"VK\")\n\n\n\n# ultra brute force\nfor index, char in enumerate(keyboard_input):\n\n current = keyboard_input[:index]\n\n if char == \"V\":\n current += \"K\"\n else:\n current += \"V\"\n\n current += keyboard_input[index+1:]\n\n\n minimal = max(minimal, current.count(\"VK\"))\n \n\nprint (minimal)\n\n", "s=input()\r\ncount=0\r\ns=s.replace('VK','A')\r\np=s.replace('KK','B')\r\nif p==s:\r\n p=s.replace('VV','B')\r\nif p!=s:\r\n count=count+1\r\nfor i in s:\r\n if i=='A':\r\n count=count+1\r\nprint(count) \r\n", "s = input()\r\nn = len(s)\r\nnum = 0\r\nrec = []\r\ni = 0\r\nwhile i < n:\r\n if i < n - 1 and s[i] == 'V' and s[i + 1] == 'K':\r\n i += 2\r\n num += 1\r\n else:\r\n rec.append(i)\r\n i += 1\r\n\r\nfor k in range(len(rec) - 1):\r\n if (rec[k + 1] - rec[k] == 1 and s[rec[k]] == 'V' and s[rec[k + 1]] == 'V') or (rec[k + 1] - rec[k] == 1 and s[rec[k]] == 'K' and s[rec[k + 1]] == 'K'):\r\n num += 1\r\n break\r\n\r\nprint(num)\r\n", "s=input()\r\na=s.count(\"VK\")\r\ns=s.replace(\"VK\",\" \")\r\nif \"VV\" in s or \"KK\" in s:\r\n a+=1\r\nprint(a)\r\n\r\n \t\t \t\t\t \t\t \t\t\t\t\t \t \t\t", "a=input()\r\ndef cnt(s):\r\n return s.count('VK')\r\nm=cnt(a)\r\nfor i in range(len(a)):\r\n if a[i]=='K':\r\n q='V'\r\n else:\r\n q='K'\r\n m=max(m,cnt(a[:i]+q+a[i+1:]))\r\nprint(m)\r\n", "s = input().strip()\nls = len(s)\nif ls == 1:\n print(0)\nelse:\n ret = 0\n if s[0] == 'K' and s[1] == 'K':\n ret += 1\n elif s[-1] == 'V' and s[-2] == 'V':\n ret += 1\n else:\n for i in range(ls-2):\n if s[i] == s[i+1] and s[i+1] == s[i+2]:\n ret += 1\n break\n for i in range(ls-1):\n if s[i] == 'V' and s[i+1] == 'K':\n ret += 1\n print(ret)\n", "# Getting Problem Data from Codeforces.\r\ntypedString = input()\r\n# Method to replace Character of String at given Index.\r\ndef replaceCharAt(index,newChar):\r\n asList = list(typedString)\r\n asList[index] = newChar\r\n return \"\".join(asList).count('VK')\r\n# Method to find Max Occurence by placing j in {'V','K'}.\r\ndef findMaxOccurenceFor(newChar):\r\n maxVK = typedString.count('VK')\r\n for index in range(len(typedString)):\r\n maxVK = max(maxVK,replaceCharAt(index,newChar))\r\n return maxVK\r\n# Solution.\r\nsolution = max(findMaxOccurenceFor('V'),findMaxOccurenceFor('K'))\r\nprint(solution)\r\n", "s = str(input())\r\nmatch = []\r\ni = -2\r\nmatch.append(i)\r\ni = 0\r\ni = s.find(\"VK\",i)\r\nwhile(i!=-1):\r\n match.append(i)\r\n i = s.find(\"VK\",i+1)\r\nmatch.append(len(s))\r\nl = len(match)\r\ng = False\r\nfor i in range(l-1):\r\n delta = match[i+1]-match[i]\r\n if delta > 4:\r\n print(l-1)\r\n g = True\r\n break;\r\n elif delta == 4 and not(s[match[i]+2]==\"K\" and s[match[i+1]-1]==\"V\"):\r\n print(l-1)\r\n g = True\r\n break;\r\nif( not g):\r\n print(l-2)", "s = input().split('VK')\r\n\r\nprint(len(s)-1 + any('VV' in w or 'KK' in w for w in s))", "s = input()\r\nprint(s.count(\"VK\")+int(s.count(\"KKK\")>0 or (len(s) >= 2 and s[:2]==\"KK\") or s.count(\"VVV\")>0 or (len(s) >= 2 and s[-2:]==\"VV\")))", "s = 'K' + input() + 'V'\r\nprint(s.count('VK') + ('VVV' in s or 'KKK' in s))", "# Description of the problem can be found at http://codeforces.com/problemset/problem/801/A\r\n\r\ns = input()\r\ncount = s.count('VK')\r\nif \"VV\" in s.replace(\"VK\", \"-\") or \"KK\" in s.replace(\"VK\", \"-\"):\r\n count += 1\r\nprint(count)", "s = input()\r\nn = len(s)\r\n\r\n\r\ndef vk(s,j,mode):\r\n r = 0\r\n if len(s) == 1:\r\n return 0\r\n else:\r\n if mode == \"V\":\r\n for i in range(len(s)-1):\r\n if i!=j and i+1!=j:\r\n if s[i]=='V' and s[i+1]=='K':\r\n r += 1\r\n continue\r\n if i==j and s[i+1]=='K':\r\n r += 1\r\n \r\n return r \r\n if mode == \"K\":\r\n for i in range(len(s)-1):\r\n if i!=j and i+1!=j:\r\n if s[i]=='V' and s[i+1]=='K':\r\n r += 1\r\n continue\r\n if i+1==j and s[i]=='V':\r\n r += 1\r\n return r \r\n\r\nans = vk(s,200,\"V\")\r\n\r\nfor i in range(n):\r\n ans = max(ans, vk(s,i,\"V\"))\r\n ans = max(ans,vk(s,i,\"K\"))\r\n\r\n\r\nprint(ans)\r\n ", "def s():\r\n inp = input()\r\n \r\n \r\n cnt = 0\r\n \r\n for i in range(len(inp) - 1):\r\n if inp[i] == 'V' and inp[i+1] == 'K':\r\n cnt += 1\r\n for i in range(len(inp) - 2):\r\n if inp[i] == 'V' and inp[i+1] == 'V' and inp[i+2] == 'V':\r\n cnt += 1; return cnt\r\n if inp[i] == 'K' and inp[i+1] == 'K' and inp[i+2] == 'K':\r\n cnt += 1; return cnt\r\n\r\n if len(inp) >= 2:\r\n if inp[0] == 'K' and inp[1] == 'K':\r\n cnt += 1; return cnt\r\n if inp[-1] == 'V' and inp[-2] == 'V':\r\n cnt += 1; return cnt\r\n return cnt\r\n\r\nprint(s())", "s = input()\r\nans = s.count('VK')\r\nfor subs in s.split('VK'):\r\n if subs != '' and subs != 'V' and subs != 'K' and subs != 'KV':\r\n ans += 1\r\n break\r\nprint(ans)", "s = input()\r\n\r\nans = 0 \r\n\r\nfor i in range(len(s)-1):\r\n if s[i] == 'V' and s[i+1] == 'K':\r\n ans += 1\r\n\r\nif s[:2] == 'KK' or s[-2:] == 'VV' or s.find('VVV') != -1 or s.find('KKK') != -1:\r\n ans += 1\r\n\r\nprint(ans)\r\n", "\r\ns = list(input())\r\nc = 0\r\ni = 0\r\nwhile i < len(s) - 1:\r\n if s[i] == 'V' and s[i + 1] == 'K':\r\n s[i] = s[i + 1] = '-'\r\n c += 1\r\n i += 2\r\n else:\r\n i += 1\r\n\r\ns = ''.join(s)\r\nif 'VV' in s or 'KK' in s:\r\n c += 1\r\n\r\nprint(c)\r\n", "s = list(input())\r\nans=0\r\nd = 0\r\nched = 0\r\nfor i in range(1,len(s)):\r\n if(s[i] ==\"K\" and s[i-1]==\"V\"):\r\n d = 1\r\n ans+=1\r\n elif ched == 1:\r\n continue\r\n elif(s[i-1]==\"V\"):\r\n if(i==len(s)-1 or s[i+1]==\"V\"):\r\n ched = 1\r\n ans+=1\r\n s[i] = \"K\"\r\n else:\r\n d = 0\r\n elif s[i-1]==\"K\":\r\n if(d==0 and s[i]==\"K\"):\r\n ans+=1\r\n s[i-1] = \"V\"\r\n ched = 1\r\n else:\r\n d = 0\r\nprint(ans)\r\n\r\n", "import sys\r\n\r\ndef main():\r\n s=sys.stdin.readline().rstrip()\r\n result=0\r\n \r\n for i in range(len(s)-1):\r\n if s[i:i+2]=='VK': result+=1\r\n \r\n if s.startswith('KK') or s.endswith('VV') or 'VKKK' in s or 'VVV' in s: result+=1\r\n \r\n sys.stdout.write(str(result)+'\\n')\r\n \r\nmain()\r\n\r\n", "s = input()\r\nk = s.count('VK')\r\nif 'VVV' in s or 'KKK' in s or s[:2] == 'KK' or s[-2:] == 'VV':\r\n k += 1\r\nprint (k)\r\n", "s=list(input())\r\nans=0\r\nn=len(s)\r\nfor i in range(n-1):\r\n if s[i]=='V' and s[i+1]=='K': ans+=1\r\nfor t in range(len(s)):\r\n anst=0\r\n ss=s[:]\r\n if ss[t]=='V': ss[t]='K'\r\n else: ss[t]='V'\r\n for i in range(n-1):\r\n if ss[i]=='V' and ss[i+1]=='K': anst+=1\r\n if anst>ans: ans=anst\r\nprint(ans)", "s=input()\r\nc=s.count(\"VK\")\r\ns=s.replace(\"VK\",\"*\")\r\nif \"VV\" in s or \"KK\" in s:\r\n c+=1\r\nprint(c)", "def solve(s):\r\n c=[i for i in s]\r\n if len(c)<2:\r\n return 0\r\n tmp=0\r\n for i in range(len(c)-1):\r\n if c[i]==\"V\" and c[i+1]==\"K\":\r\n tmp+=1\r\n for i in range(len(c)):\r\n if c[i]==\"V\":\r\n c[i]=\"K\"\r\n else:\r\n c[i]=\"V\"\r\n cur=0\r\n for j in range(len(c)-1):\r\n if c[j]==\"V\" and c[j+1]==\"K\":\r\n cur+=1\r\n tmp=max(tmp,cur)\r\n if c[i]==\"V\":\r\n c[i]=\"K\"\r\n else:\r\n c[i]=\"V\"\r\n return tmp\r\n\r\ns=input()\r\nprint(solve(s))\r\n", "string = input()\n\n\ndef count(string):\n cnt = 0\n for i in range(1, len(string)):\n if string[i] == 'K' and string[i - 1] == 'V':\n cnt += 1\n return cnt\n\n\nans = count(string)\nfor i in range(len(string)):\n new_str = string[:i] + ('K' if string[i] == 'V' else 'V') + string[i + 1:]\n ans = max(ans, count(new_str))\n\nprint(ans)\n", "s = input()\r\nd = dict()\r\nd['V'] = 'K'\r\nd['K'] = 'V'\r\nm = s.count('VK')\r\ns = list(s)\r\nfor i in range(len(s)):\r\n s[i] = d[s[i]]\r\n m = max(m,''.join(s).count('VK'))\r\n s[i] = d[s[i]]\r\nprint(m)", "'''input\nKKKKKKV\n'''\ns = input().replace(\"VK\", \".\")\nif \"VV\" in s or \"KK\" in s:\n\tprint(s.count(\".\") + 1)\nelse:\n\tprint(s.count(\".\"))", "s = input().strip()\r\nans = s.count(\"VK\")\r\n\r\nfor i in s.split(\"VK\"):\r\n if \"KK\" in i or \"VV\" in i:\r\n ans += 1\r\n break\r\n\r\nprint(ans)", "a=input()\r\na=a.replace('VK','AA')\r\nz=a.count('A')//2\r\na=a.replace('VV','W')\r\na=a.replace('KK','W')\r\nif 'W' in a:\r\n z+=1\r\nprint(z)\r\n", "s = input()\r\n\r\nn = len(s)\r\n\r\ndef f(s):\r\n vk = 0\r\n for i in range(n):\r\n if s[i:i + 2] == 'VK': vk += 1\r\n return vk\r\n\r\nvk = f(s)\r\nfor i in range(n):\r\n vk = max(vk, f(s[:i] + 'V' + s[i+1:]))\r\n vk = max(vk, f(s[:i] + 'K' + s[i+1:]))\r\n\r\nprint(vk)\r\n", "from sys import exit\n\ns = [x for x in input()]\n\nif len(s) < 2:\n print(0)\n exit()\n\ndef count(s):\n res = 0\n for i, c in enumerate(s):\n if i == len(s) - 1:\n continue\n\n if s[i] == 'V' and s[i+1] == 'K':\n res += 1\n return res\n\nsol = count(s)\nfor i in range(len(s)):\n s[i] = 'V' if s[i] == 'K' else 'K'\n sol = max(sol, count(s))\n s[i] = 'V' if s[i] == 'K' else 'K'\n\nprint(sol)\n\n", "#!/usr/bin/env python3\n\nS = list(input())\n\na = 0 # No swap\nb = 0 # With swap\nx = 0 # No swap\ny = 0 # With swap\n\nfor i in range(1, len(S)):\n n = x\n m = y\n\n if S[i - 1] == 'V' and S[i] == 'V':\n # Keep S[i] = V\n x = x\n # Swap S[i] = V to K\n y = max(y, a + 1)\n elif S[i - 1] == 'K' and S[i] == 'K':\n # Keep S[i - 1] = K\n x = x\n # Swap S[i - 1]= K to V\n y = max(y, a + 1)\n elif S[i - 1] == 'V' and S[i] == 'K':\n # Keep S[i] = K\n x = max(x, a + 1)\n y = max(b, b + 1)\n else:\n pass\n\n a = n\n b = m\n\nprint(max(x, y))\n", "s=list(input())\r\nn=len(s)\r\nx,y=0,0\r\nfor i in range(n-1):\r\n if(s[i]=='V' and s[i+1]=='K'):\r\n s[i],s[i+1]='k','k'\r\n x=x+1\r\ns=''.join(s)\r\nif('VV' in s or 'KK' in s):\r\n x=x+1\r\nprint(x)\r\n", "s = input()\r\nx = s.count(\"VK\")\r\nfor i in range(len(s)):\r\n v = s[:]\r\n if s[i] == \"V\":\r\n s = s[:i] + \"K\" + s[i + 1:]\r\n else:\r\n s = s[:i] + \"V\" + s[i + 1:]\r\n if s.count(\"VK\") > x:\r\n x += 1\r\n break\r\n s = v[:]\r\nprint(x)\r\n", "\r\ns=input()\r\ns=s.replace('VK','AA')\r\nz=s.count('A')//2\r\ns=s.replace('VV','X')\r\ns=s.replace('KK','X')\r\nif 'X' in s:\r\n z+=1\r\nprint(z) \r\n", "s=input()\r\ncnt=s.count(\"VK\")\r\ns1=s.replace(\"VK\",\"1\")\r\nif \"VV\" in s1 or \"KK\" in s1:\r\n cnt+=1\r\nprint(cnt)", "s = list(input())\r\nx = ''.join(s).count(\"VK\")\r\nfor i in range(len(s)):\r\n s[i] = 'K' if s[i] == 'V' else 'V'\r\n x = max(x, ''.join(s).count(\"VK\"))\r\n s[i] = 'K' if s[i] == 'V' else 'V'\r\nprint(x)", "s = input()\r\ns = list(s) \r\nmax_ans = -1\r\ncur_ans = 0\r\nfor j in range(1, len(s)):\r\n if s[j] == \"K\" and s[j - 1] == \"V\":\r\n cur_ans += 1 \r\nmax_ans = max(max_ans, cur_ans)\r\nfor i in range(len(s)): \r\n s1 = list(s)\r\n cur_ans = 0 \r\n if s1[i] == \"V\": \r\n s1[i] = \"K\"\r\n else:\r\n s1[i] = \"V\"\r\n for j in range(1, len(s1)):\r\n if s1[j] == \"K\" and s1[j - 1] == \"V\":\r\n cur_ans += 1\r\n max_ans = max(max_ans, cur_ans)\r\nprint(max_ans)", "s = input()\r\nif (\"VVV\" in s or \"KKK\" in s or s.find(\"KK\") == 0 or s.rfind(\"VV\") == len(s)-2) and len(s) != 1:\r\n print(s.count(\"VK\")+1)\r\nelse:\r\n print(s.count(\"VK\"))", "s=input()\r\na=s.count(\"VK\")\r\nfor i in range(len(s)):\r\n\ta = max(a, (s[:i]+'V'+s[i+1:]).count(\"VK\"))\r\n\ta = max(a, (s[:i]+'K'+s[i+1:]).count(\"VK\"))\r\nprint(a)", "s = input()\ni = 0\nans = 0\nyet = False\nif len(s)==1:\n\tprint(0)\n\texit(0)\nans = s.count(\"VK\")\ns = s.replace(\"VK\",\"ZZ\")\nwhile i<len(s)-1:\n\tif s[i]=='V' and s[i+1]=='V':\n\t\tans += 1\n\t\tbreak\n\telif s[i]=='K' and s[i+1]=='K':\n\t\tans += 1\n\t\tbreak\n\ti += 1\n\t\nprint(ans)\n", "s = input()\nmaxx = 0\nfor i in range(len(s)):\n news = s[:i] + 'V' + s[i+1:]\n maxx = max(news.count('VK'), maxx)\n news = s[:i] + 'K' + s[i + 1:]\n maxx = max(news.count('VK'), maxx)\nprint(maxx)\n", "# /**\r\n# * author: brownfox2k6\r\n# * created: 06/04/2023 08:28:47 Hanoi, Vietnam\r\n# **/\r\n\r\ndef solve():\r\n s = input()\r\n ans = 0\r\n \r\n for i in range(len(s)):\r\n for c in \"VK\":\r\n ans = max(ans, (s[:i] + c + s[i+1:]).count(\"VK\"))\r\n \r\n print(ans)\r\n\r\n\r\n_T = 1\r\n# _T = int(input())\r\nfor _ in range(_T):\r\n solve()", "#l=[int(i)for i in input().split()]\r\ns=input()\r\ni=0\r\na=s.find(\"VK\")\r\nans=0\r\nwhile a!=-1:\r\n\tans+=1\r\n\ts=s[:a]+\".\"+s[a+2:]\r\n\ta=s.find(\"VK\")\r\nif s.count(\"VV\")>0 or s.count(\"KK\")>0:ans+=1\r\nprint(ans) ", "s=input()\r\nm=s.count('VK')\r\nfor i in range(len(s)):\r\n s1=s[:i]\r\n if s[i]=='V':\r\n s1+='K'\r\n else:\r\n s1+='V'\r\n s1+=s[i+1:]\r\n m1=s1.count('VK')\r\n if m1>m:\r\n m=m1\r\nprint(m)", "word = input().strip()\r\nans = 0\r\nword = word.split(\"VK\")\r\nans = len(word) - 1\r\nfor item in word:\r\n if \"KK\" in item or \"VV\" in item:\r\n ans+=1\r\n break\r\nprint(ans)\r\n\r\n\r\n", "x=input()\r\nt=x.count(\"VK\")\r\nl=x.replace(\"VK\",\" \")\r\nif \"KK\" in l:\r\n t+=1\r\n print(t)\r\nelif \"VV\" in l:\r\n t+=1\r\n print(t)\r\nelse:\r\n print(t)", "string=input()\r\n\r\nans=string.count(\"VK\")\r\n\r\nstring=string.replace(\"VK\",\" \")\r\n\r\nans+=1 if \"VV\" in string or \"KK\" in string else 0\r\n\r\nprint(ans)", "s=list(input())\r\nfor i in range(len(s)-1):\r\n if s[i]==s[i+1]=='V':\r\n if i==len(s)-2 or s[i+2]=='V':\r\n s[i+1]='K'\r\n break\r\n elif s[i]==s[i+1]=='K':\r\n if i==0 or s[i-1]=='K':\r\n s[i]='V'\r\n break\r\nprint(\"\".join(s).count(\"VK\"))", "s = input()\r\nimport copy\r\nresult = s.count('vk')\r\n\r\nfor i in range(len(s)):\r\n news = copy.copy(s)\r\n news = list(news)\r\n news[i] = 'V'\r\n news = ''.join(news)\r\n result = max(result, news.count('VK'))\r\nfor i in range(len(s)):\r\n news = copy.copy(s)\r\n news = list(news)\r\n news[i] = 'K'\r\n news = ''.join(news)\r\n result = max(result, news.count('VK'))\r\nprint(result)\r\n", "import sys\r\nread=lambda:sys.stdin.readline().rstrip()\r\nreadi=lambda:int(sys.stdin.readline())\r\nwriteln=lambda x:sys.stdout.write(str(x)+\"\\n\")\r\nwrite=lambda x:sys.stdout.write(x)\r\ndef solve(s, ls):\r\n if ls == 1:\r\n return 0\r\n chk = [0]*ls\r\n t = [0]*ls\r\n cnt = 0\r\n for i in range(ls-1):\r\n if s[i] == 'V' and s[i+1] == 'K':\r\n chk[i] = 1\r\n cnt += 1\r\n\r\n for i in range(ls):\r\n if s[i] == 'V':\r\n if 0 <= i-1 and s[i-1] == 'V':\r\n t[i] += 1\r\n if i+1 < ls and s[i+1] == 'K':\r\n t[i] -= 1\r\n else:\r\n if 0 <= i-1 and s[i-1] == 'V':\r\n t[i] -= 1\r\n if i+1 < ls and s[i+1] == 'K':\r\n t[i] += 1\r\n mx = max(t)\r\n if mx <= 0:\r\n return cnt\r\n return cnt + max(t)\r\n\r\ns = read(); ls = len(s)\r\nwriteln(solve(s, ls))", "a=list(input())\r\nt=0\r\nif len(a)==1:\r\n print(0)\r\nelse:\r\n for k in range(len(a)-1):\r\n if a[k]=='V' and a[k+1]=='K':\r\n t+=1\r\n a[k]='m'\r\n a[k+1]='m'\r\n for k in range(len(a)-1):\r\n if ((a[k]=='V' and a[k+1]=='V') or (a[k]=='K' and a[k+1]=='K')):\r\n t+=1\r\n break\r\n print(t)", "def count(s):\r\n result = 0\r\n for i in range(len(s)-1):\r\n if s[i: i + 2] == ['v', 'k']:\r\n result += 1\r\n \r\n return result\r\n\r\ns = list(input().lower())\r\nbefore = count(s)\r\nmaximal = before\r\n\r\nfor i in range(len(s)):\r\n copy = list(s)\r\n if copy[i] == 'v':\r\n copy[i] = 'k'\r\n \r\n else:\r\n copy[i] = 'v'\r\n \r\n after = count(copy)\r\n if after > before:\r\n maximal = after\r\n\r\nprint(maximal)\r\n", "s=input().replace('VK',' ')\r\nprint(s.count(' ')+(s.count('VV')>0 or s.count('KK')>0))", "a = input()\r\nb = [a.count('VK')]\r\nfor i in range(len(a)):\r\n s = list(a)\r\n s[i] = 'K' if a[i] == 'V' else 'V'\r\n b += [''.join(s).count('VK')]\r\nprint(max(b))", "def main():\r\n s = input()\r\n c = s.count('VK')\r\n if s.find('VVV') >= 0 or s.find('KKK') >= 0 or s[:2] == 'KK' or s[-2:] == 'VV':\r\n c += 1\r\n print(c)\r\nmain()", "s= input()\r\n \r\nans = s.count(\"VK\")\r\n \r\ns= s.replace(\"VK\", \"R\")\r\n \r\nflag = False\r\n \r\nfor i in s.split(\"R\"):\r\n if \"VV\" in i or \"KK\" in i:\r\n flag = True\r\n break\r\n \r\nif flag:\r\n ans += 1\r\n \r\nprint(ans)", "s = input()\r\n\r\na = [x for x in s]\r\n\r\nm = {'V':'K','K':'V'}\r\n\r\nmx = s.count('VK')\r\n\r\nfor i in range(len(s)):\r\n a[i] = m[a[i]]\r\n mx = max(mx, \"\".join(a).count('VK'))\r\n a[i] = m[a[i]]\r\n\r\nprint (mx)", "s = input()\nres = s.count('VK')\ns = s.split('VK')\nres += sum(['VV' in x or 'KK' in x for x in s]) > 0\nprint(res)\n", "import copy\r\n\r\ns = list(input())\r\nn = len(s)\r\nans = 0\r\nfor i in range(0, n + 1):\r\n t = copy.copy(s)\r\n if i < n:\r\n if t[i] == 'V':\r\n t[i] = 'K'\r\n else:\r\n t[i] = 'V'\r\n tot = 0\r\n for j in range(0, n - 1):\r\n if t[j] == 'V' and t[j + 1] == 'K':\r\n tot = tot + 1\r\n if ans < tot:\r\n ans = tot\r\nprint(ans)\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\ns = input()[:-1]\r\ns = s.replace('VK', '*')\r\nd = s.count('*')\r\nc = 0\r\nif 'VV' in s or 'KK' in s:\r\n c = 1\r\nprint(d+c)", "from sys import stdin, stdout\n\na = stdin.readline().rstrip()\na=list(a)\n\nvkCount=0\nchange=False\nif a[0:2]==list('KK'):\n change=True\n a[0]='V'\nelif a[-2:]==list('VV'):\n change=True\n a[-1]='K'\n\ni=0\nwhile i<len(a)-2 and not change:\n if a[i:i+3]==list('VVV'):\n a[i+1]='K'\n change=True\n elif a[i:i+3]==list('KKK'):\n a[i+1]='V'\n change=True\n i+=1\n \nfor i in range(len(a)-1):\n if a[i:i+2]==list('VK'):\n vkCount+=1\n\nprint(vkCount)\n" ]
{"inputs": ["VK", "VV", "V", "VKKKKKKKKKVVVVVVVVVK", "KVKV", "VKKVVVKVKVK", "VKVVKVKVVKVKKKKVVVVVVVVKVKVVVVVVKKVKKVKVVKVKKVVVVKV", "VVKKVKKVVKKVKKVKVVKKVKKVVKKVKVVKKVKKVKVVKKVVKKVKVVKKVKVVKKVVKVVKKVKKVKKVKKVKKVKVVKKVKKVKKVKKVKKVVKVK", "KVVKKVKVKVKVKVKKVKVKVVKVKVVKVVKVKKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVVKVKVVKKVKVKK", "KVVVVVKKVKVVKVVVKVVVKKKVKKKVVKVKKKVKKKKVKVVVVVKKKVVVVKKVVVVKKKVKVVVVVVVKKVKVKKKVVKVVVKVVKK", "VVVVVKKVKVKVKVVKVVKKVVKVKKKKKKKVKKKVVVVVVKKVVVKVKVVKVKKVVKVVVKKKKKVVVVVKVVVVKVVVKKVKKVKKKVKKVKKVVKKV", "KKVVKVVKVVKKVVKKVKVVKKV", "KKVVKKVVVKKVKKVKKVVVKVVVKKVKKVVVKKVVVKVVVKVVVKKVVVKKVVVKVVVKKVVVKVVKKVVVKKVVVKKVVKVVVKKVVKKVKKVVVKKV", "KVKVKVKVKVKVKVKVKVKVVKVKVKVKVKVKVKVVKVKVKKVKVKVKVKVVKVKVKVKVKVKVKVKVKKVKVKVV", "VKVVVKKKVKVVKVKVKVKVKVV", "KKKKVKKVKVKVKKKVVVVKK", "KVKVKKVVVVVVKKKVKKKKVVVVKVKKVKVVK", "KKVKKVKKKVKKKVKKKVKVVVKKVVVVKKKVKKVVKVKKVKVKVKVVVKKKVKKKKKVVKVVKVVVKKVVKVVKKKKKVK", "VVVKVKVKVVVVVKVVVKKVVVKVVVVVKKVVKVVVKVVVKVKKKVVKVVVVVKVVVVKKVVKVKKVVKKKVKVVKVKKKKVVKVVVKKKVKVKKKKKK", "VKVVKVVKKKVVKVKKKVVKKKVVKVVKVVKKVKKKVKVKKKVVKVKKKVVKVVKKKVVKKKVKKKVVKKVVKKKVKVKKKVKKKVKKKVKVKKKVVKVK", "KKVKVVVKKVV", "VKVKVKVKVKVKVKVKVKVKVVKVKVKVKVKVK", "VVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVV", "VVKKVKVKKKVVVKVVVKVKKVKKKVVVKVVKVKKVKKVKVKVVKKVVKKVKVVKKKVVKKVVVKVKVVVKVKVVKVKKVKKV", "VVKVKKVVKKVVKKVVKKVVKKVKKVVKVKKVVKKVVKKVVKKVVKKVVKVVKKVVKVVKKVVKVVKKVVKKVKKVVKVVKKVVKVVKKVV", "K", "VKVK", "VKVV", "KV", "KK", "KKVK", "KKKK", "KKV", "KKVKVK", "VKKVK", "VKKK", "KKK", "KVV", "KKVKV", "VVK", "VVVKVKVKVKVKVKVK", "KVVVK", "VVVKK", "KKVV", "KKKKKKK", "VKKKVK", "KKVVV", "VVVVVV", "KKKV", "VVKVV", "VKVKKK", "VKKV", "VKKVV", "VVKKVV", "KKVVKKV", "KKKKK", "VKVVKKVKKVVKVKKVKKKVKKVKVKK", "VKVKVV", "VKVVKVV", "VVV", "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV", "VVKKKKKKVKK", "KVKVKVV"], "outputs": ["1", "1", "0", "3", "1", "5", "14", "32", "32", "21", "25", "7", "24", "35", "9", "6", "9", "22", "25", "29", "3", "16", "13", "26", "26", "0", "2", "2", "0", "1", "2", "1", "1", "3", "2", "2", "1", "1", "2", "1", "8", "2", "2", "1", "1", "3", "1", "1", "1", "2", "3", "1", "2", "2", "2", "1", "10", "3", "3", "1", "1", "3", "3"]}
UNKNOWN
PYTHON3
CODEFORCES
142
18dfbace2937f92f8edc7f2509adeb06
Dishonest Sellers
Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least *k* of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all *n* items. In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=104) — prices of items after discounts (i.e. after a week). Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now. Sample Input 3 1 5 4 6 3 1 5 5 3 3 4 7 10 3 4 5 5 12 5 Sample Output 10 25
[ "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\ndef main():\n n, k = (int(i) for i in input().split())\n a = [int(i) for i in input().split()]\n b = [int(i) for i in input().split()]\n diffs = sorted([a[i] - b[i] for i in range(n)])\n ans = sum(a)\n for diff in diffs:\n if diff < 0 or k > 0:\n k -= 1\n else:\n ans -= diff\n print(ans)\n \nmain()", "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nd = sorted([b_el - a_el for b_el, a_el in zip(b, a) if b_el - a_el < 0])\nprint(sum(a) + sum(d[:n - k]))\n\t \t\t\t \t\t \t\t\t\t\t\t \t\t\t \t \t \t\t\t", "import operator\n\nimport operator\n\nn,k = map(int,input().split())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\n\nincreaseInPrice = dict()\nfor i in range(n):\n increaseInPrice[i] = b[i]-a[i]\n\nsortedIncrease = sorted(increaseInPrice.items(), key=operator.itemgetter(1))\n\ni = n-1\ntotalCost = 0\n\nwhile(i>-1):\n if(k>0):\n k -= 1\n totalCost += a[sortedIncrease[i][0]]\n else:\n totalCost += min(a[sortedIncrease[i][0]],b[sortedIncrease[i][0]])\n i -= 1\n\nprint(totalCost)\n", "n=list(map(int,input().split()))\r\nl=list(map(int,input().split()))\r\nt=list(map(int,input().split()))\r\nd=sorted([l[i]-t[i] for i in range(len(l))])\r\nfor i in range (len(d)):\r\n n[0]=n[0]+min(t[i],l[i])\r\nfor j in range (n[1]):\r\n n[0]=n[0]+(max(d[j],0))\r\nprint(n[0]-len(d))", "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\n\r\nn, k = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\n\r\nprofits = []\r\nfor i in range(n):\r\n profits.append((b[i]-a[i], i))\r\n\r\nprofits.sort(reverse=True)\r\ntotal = 0\r\n# print(profits)\r\nfor i in range(n):\r\n j = profits[i][1]\r\n if i < k:\r\n total += a[j]\r\n else:\r\n total += min(a[j], b[j])\r\nprint(total)\r\n \r\n\r\n", "n, k = map(int, input().split())\nbefore = list(map(int, input().split()))\nafter = list(map(int, input().split()))\n\ntotal_cost = sum(before)\nprice_differences = sorted([y - x for x, y in zip(before, after)], reverse=True)\n\nfor i in price_differences[k:]:\n if i >= 0:\n pass\n else:\n total_cost += i\nprint(total_cost)\n\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\nl2=list(map(int,input().split()))\r\nL=[]\r\nk=0\r\nfor i in range(n) :\r\n L.append([l1[i]-l2[i],l1[i],l2[i]])\r\nL=sorted(L)\r\nfor i in range(n) :\r\n if L[i][0]<=0 :\r\n k=k+L[i][1]\r\n else :\r\n if m<=0 :\r\n k=k+L[i][2]\r\n else :\r\n k=k+L[i][1]\r\n m=m-1\r\nprint(k)\r\n \r\n \r\n", "n,k=map(int,input().split())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nd=[]\nfor q in range(n):\n d.append([b[q]-a[q],a[q],b[q]])\nd.sort()\n#print(d)\ns=0\nfor q in range(n-1,-1,-1):\n if k>0 or d[q][0]>=0:\n s+=d[q][1]\n k-=1\n else:\n s+=d[q][2]\nprint(s)", "from itertools import takewhile\r\n\r\ndef readline():\r\n return [int(c) for c in input().split()]\r\n\r\ndef main():\r\n n, k = readline()\r\n a, b = readline(), readline()\r\n\r\n diff = sorted(x - y for x, y in zip(a, b))\r\n a_items = max(k, sum(1 for _ in takewhile(lambda x: x <= 0, diff)))\r\n print(sum(b) + sum(diff[:a_items]))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n,k=input().split()\r\nn,k=int(n),int(k)\r\naa=list(map(int,input().split()))\r\nbb=list(map(int,input().split()))\r\n\r\nans=sum(bb)\r\nli=sorted([a-b for a,b in zip(aa,bb)])\r\n\r\nfor i in range(n):\r\n\tif i<k or li[i]<0:\tans+=li[i]\r\n\telse:\tbreak\r\nprint(ans)", "n,k=map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\nitems = []\r\nfor i in range(0,n):\r\n\titem = (b[i]-a[i],a[i],b[i])\r\n\titems.append(item)\r\nitems = sorted(items,key = lambda x: int(x[0]),reverse=True)\r\n\r\nans = 0\r\nfor i in range(0,n):\r\n\tif i < k:\r\n\t\tans = ans + items[i][1]\r\n\telse:\r\n\t\tans = ans + min(items[i][1],items[i][2])\r\nprint(ans)", "#!/usr/bin/env python3\r\n# -*- coding='utf-8' -*-\r\n\r\nn, k = input().split()\r\nn = int(n)\r\nk = int(k)\r\n\r\na = input().split()\r\nb = input().split()\r\n\r\nclass item(object):\r\n def __init__(self, a, b, c):\r\n self.a = a\r\n self.b = b\r\n self.c = c\r\n def getC(self):\r\n return self.c\r\n\r\n\r\nitems = []\r\nfor i in range(len(a)):\r\n items.append(item(int(a[i]), int(b[i]), int(b[i]) - int(a[i])))\r\n\r\nans = 0\r\nitems.sort(key = item.getC, reverse = True)\r\nfor i in range(len(items)):\r\n if i < k:\r\n ans += items[i].a\r\n elif items[i].c > 0:\r\n ans += items[i].a\r\n else:\r\n ans += items[i].b\r\n\r\nprint(ans)\r\n", "import sys\r\n\r\nfin = sys.stdin\r\nfout = sys.stdout\r\nn, k = map(int, fin.readline().split())\r\na = list(map(int, fin.readline().split()))\r\nb = list(map(int, fin.readline().split()))\r\ndiff = [0] * n\r\nfor i in range(n):\r\n diff[i] = (a[i] - b[i], i)\r\ndiff.sort()\r\nans = 0\r\nfor i in range(n):\r\n if i < k:\r\n ans += a[diff[i][1]]\r\n elif diff[i][0] < 0:\r\n ans += a[diff[i][1]]\r\n else:\r\n ans += b[diff[i][1]]\r\nfout.write(str(ans))\r\n", "n,m = input().split()\nn,m = [int(n), int(m)]\n\na = [int(x) for x in input().split()]\nb = [int(x) for x in input().split()]\n\nmoney =0\n\ndiff =[]\nfor i in range(n):\n\tdiff.append((a[i] - b[i],i))\n\ndiff.sort()\n\nfor i in range(m):\n\tt=diff[i]\n\tmoney+= a[t[1]]\n\n\nfor i in range(m,n):\n\tt=diff[i]\n\tif t[0] < 0:\n\t\tmoney+=a[t[1]]\n\telse:\n\t\tmoney+=b[t[1]]\n\n\nprint(money)\n\t\n\n\n\n\n\n\n\n\t\t \n", "def main():\r\n n, k = map(int, input().split())\r\n a = map(int, input().split())\r\n b = map(int, input().split())\r\n d = list(zip(a, b))\r\n\r\n d = sorted(d, key=lambda x: x[0] - x[1])\r\n\r\n ans = sum(x[0] for x in d[:k])\r\n ans += sum(min(x[0], x[1]) for x in d[k:])\r\n\r\n print(ans)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\nc = [a[x]-b[x] for x in range(n)]\r\na = [x for _,x in sorted(zip(c,a))]\r\nb = [x for _,x in sorted(zip(c,b))]\r\nans = sum(a[:k])\r\nfor x in range(k,n):\r\n ans += min(a[x],b[x])\r\nprint(ans)", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nc = list((aa, bb) for aa, bb in zip(a, b))\r\nc.sort(key = lambda x : x[0]-x[1])\r\nans = 0\r\nfor i in range(n):\r\n if c[i][0] <= c[i][1]:\r\n ans += c[i][0]\r\n k -= 1\r\n else:\r\n if k > 0 :\r\n ans += c[i][0]\r\n k -= 1\r\n else:\r\n ans += c[i][1]\r\nprint(ans)", "import os\r\nline_number = 1\r\ncurrent_working_dir = os.getcwd()\r\nmy_local_machine = current_working_dir.find('rachel')\r\n# print(my_local_machine)\r\n\r\ndef myinput():\r\n global line_number, lines, my_local_machine\r\n if line_number == 1:\r\n lines = lines.split('\\n')\r\n\r\n # print(len(lines))\r\n if my_local_machine > 0:\r\n line = lines[line_number]\r\n else:\r\n line = input()\r\n \r\n line_number += 1\r\n return(line)\r\n\r\nlines = '''\r\n3 1\r\n5 4 6\r\n3 1 5\r\n'''\r\n\r\nn, k = map(int, myinput().split()) \r\na = list(map(int, myinput().split())) \r\nb = list(map(int, myinput().split())) \r\nc = [] \r\n\r\nfor i in range(len(a)): \r\n new = [a[i], b[i]] \r\n c.append(new) \r\n\r\nc.sort(key = lambda x:x[0]- x[1]) \r\n\r\ncount = 0 \r\nfor i in range(n): \r\n if c[i][0] <= c[i][1]: \r\n count += c[i][0] \r\n k -= 1 \r\n else: \r\n if k > 0: \r\n count += c[i][0] \r\n k -= 1 \r\n else: \r\n count += c[i][1] \r\n\r\nprint(count) ", "n,k = map(int,input().split())\r\nA = list(map(int,input().split()))\r\nB = list(map(int,input().split()))\r\nans = [False]*n\r\ntotal = 0\r\nco = 0\r\nres = [] \r\nfor i in range(n):\r\n l = [A[i],B[i]]\r\n res.append(l)\r\nres.sort(key = lambda x :(x[0]-x[1]))\r\n#print(res)\r\nst =0\r\nwhile co <k:\r\n \r\n total += res[st][0]\r\n ans[st] = True\r\n st += 1\r\n co += 1\r\nfor i in range(st,n):\r\n if res[i][0] <= res[i][1]:\r\n total += res[i][0]\r\n ans[i] = True\r\n co += 1\r\n else:\r\n total += res[i][1]\r\n ans[i] = True\r\n \r\nprint(total)", "n,k=map(int,input().split())\r\nar=list(map(int,input().split()))\r\nar1=list(map(int,input().split()))\r\narr=[]\r\nfor i in range(n):\r\n arr.append([ar[i]-ar1[i],ar[i],ar1[i]])\r\nans=0\r\narr=sorted(arr)\r\nfor i in range(n):\r\n if i<k:ans+=arr[i][1]\r\n else:ans+=min(arr[i][1],arr[i][2])\r\n\r\nprint(ans) \r\n", "from collections import defaultdict as d\r\n\r\nn, k = map(int, input().split())\r\nmemo = d(list)\r\ndiscount = list(map(int, input().split()))\r\noriginal = list(map(int, input().split()))\r\nminimum_total = 0\r\nfor i in range(n): memo[original[i] - discount[i]].append(i)\r\n# print(memo)\r\nfor key, arr in reversed(sorted(memo.items())):\r\n for idx in arr:\r\n if key > 0:\r\n if k:\r\n minimum_total += discount[idx]\r\n k -= 1\r\n else:\r\n minimum_total += min(discount[idx], original[idx])\r\n else:\r\n if k:\r\n minimum_total += discount[idx]\r\n k -= 1 \r\n else:\r\n minimum_total += original[idx] \r\nprint(minimum_total)", "def comp(e):\r\n return e[2]\r\n\r\n\r\ns = input()\r\nl = s.split()\r\n\r\nn = int(l[0])\r\nk = int(l[1])\r\n\r\ns = input()\r\nl = s.split()\r\n\r\nv = [[0, 0, 0] for i in range(n)]\r\n\r\nfor i in range(n):\r\n v[i][0] = int(l[i])\r\n\r\ns = input()\r\nl = s.split()\r\n\r\nfor i in range(n):\r\n v[i][1] = int(l[i])\r\n v[i][2] = v[i][0] - v[i][1]\r\n\r\nv.sort(key = comp)\r\n\r\ni = 0\r\ns = 0\r\n\r\nwhile i < n and (v[i][2] <= 0 or k > 0):\r\n\r\n s += v[i][0]\r\n\r\n i += 1\r\n k -= 1\r\n\r\nwhile i < n:\r\n\r\n s += v[i][1]\r\n\r\n i += 1\r\n k -= 1\r\n\r\n#print(v)\r\n\r\nprint(s)\r\n\r\n", "from math import *\r\nfrom collections import *\r\nfrom random import *\r\nfrom bisect import *\r\nimport sys\r\ninput=sys.stdin.readline\r\nt=1\r\nwhile(t):\r\n t-=1\r\n n,k=map(int,input().split())\r\n a=list(map(int,input().split()))\r\n b=list(map(int,input().split()))\r\n r=[]\r\n for i in range(n):\r\n r.append([a[i]-b[i],i])\r\n r.sort()\r\n pos=0\r\n for i in r:\r\n if(i[0]<=0):\r\n pos+=1\r\n else:\r\n break\r\n re=0\r\n for i in range(max(k,pos)):\r\n re+=a[r[i][1]]\r\n for i in range(max(pos,k),n):\r\n re+=b[r[i][1]]\r\n print(re)\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\nb = list(map(int,input().split()))\r\nc = []\r\nfor i in range(n):\r\n c.append([a[i],b[i]])\r\nc.sort(key = lambda x: x[0]-x[1])\r\nans = 0\r\nfor i in range(k):\r\n ans += c[i][0]\r\nfor i in range(k,n):\r\n ans += min(c[i][0],c[i][1])\r\nprint(ans) ", "R=lambda:list(map(int,input().split()))\nn,k=R()\na=R()\nb=R()\nans=sum(b)\nfor i in range(n): a[i]-=b[i]\na=sorted(a)\nfor i in range(n):\n if i<k or a[i]<0:\n ans += a[i]\n else: break\nprint(ans)\n", "n, k = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\ndiff = {}\ns = set(i for i in range(n))\nfor i in range(n):\n diff[i] = a[i] - b[i]\nspisok = []\nfor i in range(n):\n spisok.append([i, diff[i]])\nspisok = sorted(spisok, key = lambda x: x[1])\nsumma = 0\nfor i in range(k):\n summa += spisok[i][1] + b[spisok[i][0]]\ni = k\nwhile i < n and spisok[i][1] < 0:\n summa += a[spisok[i][0]]\n i += 1\nwhile i < n:\n summa += b[spisok[i][0]]\n i += 1\nprint(summa)\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\na=[int(y) for y in input().split()]\r\nb=[int(y) for y in input().split()]\r\ndiff=[]\r\nfor i in range(n):\r\n diff.append([a[i]-b[i],i])\r\ndiff.sort()\r\nsu=0\r\nvisited=[0]*n \r\nfor i in range(k):\r\n su+=a[diff[i][1]]\r\n visited[diff[i][1]]=1 \r\nfor i in range(n):\r\n if visited[i]==0:\r\n su+=min(a[i],b[i])\r\nprint(su)", "n,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\nls = []\r\nfor i in range(n):\r\n\tls.append([a[i]-b[i],i])\r\nls.sort()\r\ncnt = 0\r\ni = 0\r\nwhile i<k:\r\n\tcnt +=a[ls[i][1]]\r\n\ti+=1\r\nfor i in range(k,n):\r\n\tif ls[i][0]<=0:\r\n\t\tcnt+=a[ls[i][1]]\r\n\telse:\r\n\t\tcnt+=b[ls[i][1]]\r\nprint(cnt)", "def findLargest(aList):\n\treturn max(aList)\n\tpass\n\nn, k = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\ndif = []\nfor x in range(0,n):\n\tdif.append(a[x] - b[x])\ndif.sort()\n#print(\"dif: \", dif)\n\nthisWeekCount = 0\nans = sum(b)\n\"\"\"\nprint(\"n, k: \", n, k)\nprint(\"a: \", a)\nprint(\"b: \", b)\nprint(\"dif: \", dif)\nprint(\"ans: \", ans)\n\"\"\"\n\"\"\"\nfor x in range(0,n):\n\t#print(x)\n\ttmp = a[x] - b[x]\n\tif tmp > 0:\n\t\t#a > b, buy a_x next week, remember difference\n\t\tans += b[x]\n\t\tdif.append(a[x] - b[x])\n\telse:\n\t\t#a <= b, buy a_x this week\n\t\tans += a[x]\n\t\tthisWeekCount += 1\nprint(\"thisWeekCount: \", thisWeekCount)\n#print(\"a: \", a)\n#print(\"b: \", b)\n#print(\"dif: \", dif)\n\ndif.sort()\n#print(\"dif: \", dif)\n\"\"\"\nwhile thisWeekCount < k or dif[thisWeekCount] < 0:\n\t#print(\"warning\", dif[0])\n\tans += dif[thisWeekCount]\n\tthisWeekCount += 1\n\t#dif.remove(dif[0])\n\tif thisWeekCount == len(dif):\n\t\t#print(\"hi\")\n\t\tbreak\n\t#print(\"removed dif: \", dif)\n\nprint(ans)", "class Compra:\n\tdef __init__(self, hoje, amanha):\n\t\tself.hoje = hoje\n\t\tself.amanha = amanha\n\t\n\tdef __repr__(self):\n\t\treturn \"({}, {})\".format(self.hoje, self.amanha)\n\n\tdef __lt__(self, other):\n\t\treturn (self.amanha - self.hoje) < (other.amanha - other.hoje)\n\n\nn, k = map(int, input().split())\nvetor_A = list(map(int, input().split()))\nvetor_B = list(map(int, input().split()))\nlista = [Compra(a, b) for a,b in zip(vetor_A, vetor_B)]\nlista.sort(reverse=True)\n\nans = 0\nfor c in lista:\n\tif c.hoje < c.amanha or k > 0:\n\t\tans += c.hoje\n\t\tk -= 1\n\telse:\n\t\tans += c.amanha\n\nprint(ans)\n", "n,k=map(int,input().split())\r\nt=list(map(int,input().split()))\r\nc=list(map(int,input().split()))\r\nd=[t[i]-c[i] for i in range(len(t))]\r\ns=0\r\nfor i in t:\r\n s+=i\r\nd.sort()\r\nfor i in range(k,len(d)):\r\n if max(d[i],0):\r\n s-=d[i]\r\nprint(s)\r\n", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nans=0\r\ncnt=0\r\nfor i in range(len(a)):\r\n if a[i]<=b[i]:\r\n cnt+=1\r\n ans+=a[i]\r\n a[i]=0\r\n b[i]=0\r\n\r\n\r\nnew=[]\r\np=[0,0,0]\r\nfor i in range(len(a)):\r\n if a[i]!=0:\r\n p[0]=a[i]-b[i]\r\n p[1]=a[i]\r\n p[2]=b[i]\r\n new.append(tuple(p))\r\nnew.sort()\r\nfor i in range(len(new)):\r\n \r\n if cnt<k:\r\n ans+=new[i][1]\r\n cnt+=1\r\n else:\r\n ans+=new[i][2]\r\n# print(new)\r\n \r\nprint(ans)\r\n", "n, k = [int(x) for x in input().split()]\r\n\r\nlist = [dict() for x in range(n)]\r\n\r\nfor idx, x in enumerate(input().split()):\r\n list[idx]['a'] = int(x)\r\n\r\nfor idx, x in enumerate(input().split()):\r\n list[idx]['b'] = int(x)\r\n\r\nlist = sorted(list, key=lambda dict: dict['a'] - dict['b'])\r\ncnt = 0\r\nsum = 0\r\n\r\nfor i in range(n):\r\n if (cnt < k or list[i]['a'] < list[i]['b']):\r\n cnt += 1\r\n sum += list[i]['a']\r\n else:\r\n sum += list[i]['b']\r\n \r\nprint(sum)\r\n", "def solve(n,k,a,b):\n diff = []\n\n for i in range(n):\n diff.append(a[i]-b[i])\n\n zipped_list = zip(diff,a,b)\n sorted_pairs = sorted(zipped_list)\n tuples = zip(*sorted_pairs)\n diff,a,b = [list(tuple) for tuple in tuples]\n\n ans = sum(b)\n curr = 0\n for i in range(n):\n if curr < k or diff[i] < 0:\n ans += diff[i]\n curr += 1\n\n print(ans)\n\n\nif __name__ == '__main__':\n n,k = map(int, input().split())\n a = list(map(int,input().split()))\n b = list(map(int, input().split()))\n\n solve(n,k,a,b)", "n, k = map(int, input().split())\narr = list(map(int, input().split()))\nbrr = list(map(int, input().split()))\nvis = [0]*n\ntot, buy = 0, 0\nfor i in range(n):\n\tif arr[i] <= brr[i]:\n\t\tbuy += 1\n\t\ttot += arr[i]\n\t\tvis[i] = 1\nif buy >= k:\n\tfor i in range(n):\n\t\tif vis[i] == 0:\n\t\t\ttot += brr[i]\n\tprint(tot)\nelse:\n\tcrr = []\n\tfor i in range(n):\n\t\tif vis[i] == 0:\n\t\t\tcrr.append(i)\n\tcrr.sort(key = lambda x:arr[x]-brr[x])\n\tfor i in range(k-buy):\n\t\ttot += arr[crr[i]]\n\tfor i in range(k-buy,len(crr)):\n\t\ttot += brr[crr[i]]\n\tprint(tot)", "def solve(l):\r\n for i in range(5):\r\n if(abs(l[i]&1)):\r\n return -1\r\n ans = 0\r\n for i in range(5):\r\n if(l[i]>0):\r\n ans+=(l[i]//2)\r\n\r\n return ans\r\nn, k = map(int, input().split())\r\na = [int(x) for x in input().split()]\r\nb = [int(x) for x in input().split()]\r\nc = []\r\nd = [0]*n\r\nfor i in range(n):\r\n c.append([(a[i]-b[i]), i])\r\nans = 0\r\nc.sort()\r\nfor i in range(k):\r\n ans+= a[c[i][1]]\r\n d[c[i][1]] = 1\r\n\r\nfor i in range(n):\r\n if(d[i] == 0):\r\n ans+=min(a[i], b[i])\r\n\r\nprint(ans)\r\n\r\n", "n=list(map(int,input().split()))\r\nl=list(map(int,input().split()))\r\nt=list(map(int,input().split()))\r\nd=[l[i]-t[i] for i in range(len(l))]\r\ns=0\r\nfor i in range (len(d)):\r\n if d[i]<0 : s=s+l[i]\r\n else : s=s+t[i]\r\nd.sort()\r\nfor j in range (n[1]):\r\n s=s+(max(d[j],0))\r\nprint(s) ", "n , k = map(int,input().split())\r\na1 = list(map(int,input().split()))\r\na2 = list(map(int,input().split()))\r\n\r\nsm = sum(a2)\r\ndiff = []\r\nfor i in range(n):\r\n diff.append(a1[i] - a2[i])\r\ndiff.sort()\r\n\r\nfor i in range(n):\r\n if i < k or diff[i] < 0 :\r\n sm += diff[i]\r\n\r\nprint(sm)\r\n\r\n\r\n\r\n\r\n", "n, k = map(int, input().split())\r\na = sorted([a - b, a, b] for a, b in zip(map(int, input().split()), map(int, input().split())))\r\nprint(sum(ai[1] if i < k or ai[0] < 0 else ai[2] for i, ai in enumerate(a)))", "n, k = [int(x) for x in input().strip().split()]\na = [-int(x) for x in input().strip().split()]\nb = [int(x) for x in input().strip().split()]\n\ntotal = 0\ndiff = [[sum(x), x] for x in zip(a, b)]\ndiff.sort(key=lambda x: x[0])\n\nfor _ in range(k):\n t = diff.pop()\n total += -t[1][0]\n\nfor t in diff:\n if t[0] < 0:\n total += t[1][1]\n else:\n total += -t[1][0]\n\nprint(total)\n\n\t \t\t \t\t\t \t \t \t \t\t \t\t \t", "import math\r\nimport string\r\n\r\n\r\ndef main_function():\r\n n, k = [int(i) for i in input().split(\" \")]\r\n a = [int(i) for i in input().split(\" \")]\r\n b = [int(i) for i in input().split(\" \")]\r\n a_b = [[a[i] - b[i], a[i], b[i]] for i in range(n)]\r\n a_b.sort(key=lambda x: x[0])\r\n adder = 0\r\n for i in a_b:\r\n if k > 0:\r\n adder += i[1]\r\n k -= 1\r\n else:\r\n if i[0] >= 0:\r\n adder += i[2]\r\n else:\r\n adder += i[1]\r\n print(adder)\r\n\r\n\r\nmain_function()", "_, k = map(int, input().split())\r\nprices = sorted((a - b, a, b) for a, b in zip(map(int, input().split()),\r\n map(int, input().split())))\r\nprint(sum(a for _, a, _ in prices[:k]) +\r\n sum(min(a, b) for _, a, b in prices[k:]))", "class Stuff:\n def __init__(self,before,after):\n self._before = before\n self._after = after\n self._discount = self._before - self._after\n @staticmethod\n def discount(someStuff):\n return somestuff.discount()\n\n def discount(self):\n return self._discount\n\n def __str__(self):\n return '('+str(self._before)+',' +str(self._after)+')'\n\n \nn,k = [int(i) for i in input().strip().split(' ')]\na = [int(i) for i in input().strip().split(' ')]\nb = [int(i) for i in input().strip().split(' ')]\nallStuff = [Stuff(a[i],b[i]) for i in range(n)]\nallStuff.sort(key = Stuff.discount)\nmoney = 0\nfor thisStuff in allStuff:\n if k > 0:\n money += thisStuff._before\n k -= 1\n else:\n money += min(thisStuff._before, thisStuff._after)\nprint(money)\n", "a1 = input().split()\r\nn = int(a1[0])\r\nk = int(a1[1])\r\n\r\na2 = input().split()\r\na3 = input().split()\r\nlen_ = len(a2)\r\nm = [(int(a2[i]), int(a3[i])) for i in range(len_)]\r\n\r\nm.sort(key=lambda x: x[0] - x[1])\r\nans = 0\r\nfor i in range(k):\r\n\tans += m[i][0]\r\nfor i in range(k, len_):\r\n\tif(m[i][0] < m[i][1]):\r\n\t\tans += m[i][0]\r\n\telse:\r\n\t\tans += m[i][1]\r\nprint(ans)\r\n# your code goes here", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Sep 7 20:41:51 2020\r\n\r\n@author: mahedi\r\n\"\"\"\r\nR=lambda:list(map(int,input().split()))\r\nn,k=R()\r\nA=R()\r\nB=R()\r\nsum=0\r\niteams=list(zip(A,B));\r\niteams=sorted(iteams,key=lambda x:x[0]-x[1])\r\nfor i in range(0,n):\r\n if(i<k):\r\n sum=sum+iteams[i][0]\r\n else:\r\n sum=sum+min(iteams[i][0],iteams[i][1])\r\nprint(sum)\r\n ", "n, k = [int(s) for s in input().split()]\r\n\r\nnow = [int(s) for s in input().split()]\r\nafter = [int(s) for s in input().split()]\r\nprices = [a for a in zip(now, after)]\r\n\r\nprices = sorted(prices, key= lambda x: x[0] - x[1])\r\nprint(sum([price[0] for price in prices[:k]]) + sum([min(price) for price in prices[k:]]))", "import heapq\nn, k = map(int, input().split())\nfirst = list(map(int, input().split()))\nsecond = list(map(int, input().split()))\nx = 0 # number of items going costlier\ncost = 0\nfor i in range(n):\n if first[i] < second[i]:\n cost += first[i]\n x += 1\nif k <= x:\n for i in range(n):\n if first[i] >= second[i]:\n cost += second[i]\nelse:\n heapsize = k-x\n hp = []\n j = 0\n first_heapify = True\n for i in range(n):\n if first[i] >= second[i]:\n if j < heapsize:\n heapq.heappush(hp, (second[i]-first[i], first[i], i)) #creating a max with -ve values\n j += 1\n else:\n if first_heapify:\n heapq.heapify(hp) #optimization?\n first_heapify = False\n mx = -hp[0][0]\n if first[i]-second[i] < mx:\n heapq.heappop(hp) \n heapq.heappush(hp, (second[i]-first[i], first[i], i))\n picked_els = set()\n for el in hp:\n cost += el[1]\n picked_els.add(el[2])\n for i in range(n):\n if first[i] >= second[i] and i not in picked_els:\n cost += second[i]\nprint(cost)\n", "n, k = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\ncheaperA = set()\r\nfor i in range(n):\r\n\tif a[i] < b[i]:\r\n\t\tcheaperA.add((a[i], i))\r\n\ta[i] = (a[i], i)\r\n\tb[i] = (b[i], i)\r\n\r\nout = 0\r\nsrtedA = sorted(a, key=lambda x: b[x[1]][0] - x[0], reverse=True)\r\nbought = set()\r\nfor r in cheaperA:\r\n\tbought.add(r[1])\r\n\tout += r[0]\r\nfor i in range(n):\r\n\tif len(bought) >= k:\r\n\t\tbreak\r\n\tif not srtedA[i][1] in bought:\r\n\t\tbought.add(srtedA[i][1])\r\n\t\tout += srtedA[i][0]\r\n\r\nfor r in b:\r\n\tif not r[1] in bought:\r\n\t\tout += r[0]\r\n\r\nprint(out)\r\n", "dr = []\r\nm = []\r\ns = 0\r\nc = -1\r\n\r\nx, y = map(int, input().split())\r\nfd = list(map(int, input().split()))\r\nsd = list(map(int, input().split()))\r\n\r\nfor i in range(x):\r\n\tdr.append(fd[i] - sd[i])\r\n\tm.append(min(fd[i],sd[i]))\r\n\r\ndr.sort()\r\ns=sum(m)\r\n\r\nfor i in range(x) :\r\n\tif dr[i] <= 0 :\r\n\t\tc = i\r\n\telse:\r\n\t\tbreak\r\n\r\nif (c+1)>=y :\r\n\tprint(s)\r\nelse :\r\n\tfor i in range(c+1,y):\r\n\t\ts += dr[i]\r\n\tprint(s)\r\n\r\n\t", "a,b=list(map(int,input().split()));a,c,d=list(map(int,input().split())),list(map(int,input().split())),[]\r\nfor i in range(len(a)):\r\n a[i]-=c[i]\r\nfor i in range(len(a)-1,-1,-1):\r\n if a[i]<0:\r\n d.append(a[i])\r\nif len(d)<b:\r\n print(sum(c)+sum(sorted(a)[:b]))\r\nelse:\r\n print(sum(c+d))\r\n", "n, k = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nc = sorted(zip(a, b), key=lambda x: x[0] - x[1])\r\nres = 0\r\nfor idx, value in enumerate(c):\r\n if value[0] - value[1] <= 0:\r\n res += value[0]\r\n elif idx >= k:\r\n res += value[1]\r\n else:\r\n res += value[0]\r\nprint(res)", "'''input\r\n5 3\r\n3 4 7 10 3\r\n4 5 5 12 5\r\n'''\r\n\r\nn, k = map(int,input().split(\" \"))\r\nlst1 = list(map(int,input().split(\" \")))\r\nlst2 = list(map(int,input().split(\" \")))\r\nd = sorted(a - b for a, b in zip(lst2, lst1) if(a - b < 0))\r\nprint(\"{}\".format(sum(lst1) + sum(d[:n - k])))\r\n\r\n", "def buy(n, k, a, b):\n dif = [(a[i] - b[i], i) for i in range(n)]\n dif.sort()\n cost = 0\n for i in range(k):\n cost += a[dif[i][1]]\n for j in range(k, n):\n if a[dif[j][1]] < b[dif[j][1]]:\n cost += a[dif[j][1]]\n else:\n cost += b[dif[j][1]]\n return cost\n\nc, d = map(int, input().strip().split())\ne = list(map(int, input().strip().split()))\nf = list(map(int, input().strip().split()))\nprint(buy(c,d,e,f))\n\t \t\t \t \t\t \t\t\t \t \t \t \t", "n, t = [int(a) for a in input().split()]\na = list(map(int,input().strip().split()))\nb = list(map(int,input().strip().split()))\n\ndif = []\nfor i in range(n):\n dif.append(a[i]-b[i])\n\nlst = sorted(list(zip(dif, a, b)))\ndl = 0\nsum = 0\nfor i in range(n):\n if dl >= t and lst[i][0] > 0:\n sum += lst[i][2]\n else:\n dl += 1\n sum += lst[i][1]\n \nprint(sum)\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\npre=list(map(int,input().split()))\r\npost=list(map(int,input().split()))\r\nz=zip(pre,post)\r\nres=sorted(z,key=lambda x:x[0]-x[1])\r\nmincost=0\r\nfor i in range(n):\r\n if k>0:\r\n mincost+=res[i][0]\r\n k-=1\r\n else:\r\n mincost+=min(res[i][0],res[i][1])\r\nprint(mincost)", "n,k=map(int,input().split())\r\nll=list(map(int,input().split()))\r\nkk=list(map(int,input().split()))\r\nff=[]\r\nt,c,m=0,0,k\r\nfor i in range(n):\r\n r=kk[i]-ll[i]\r\n if r>=0:\r\n c+=ll[i]\r\n m-=1\r\n else:\r\n t+=kk[i]\r\n ff.append(r)\r\ntt=[]\r\nff.sort(reverse=True)\r\nif m>0:\r\n c+=(t-sum(ff[:m]))\r\nelse:\r\n c+=t\r\nprint(c)", "def solve(c,b,v1,v2):\r\n v3=[]\r\n vis=[0]*(c)\r\n for i in range(len(v2)):\r\n v3.append([v1[i]-v2[i], i])\r\n v3.sort()\r\n tmp=0\r\n for i in range(b):\r\n tmp+=v1[v3[i][1]]\r\n vis[v3[i][1]]=1\r\n for i in range(b,c):\r\n if v3[i][0]<=0:\r\n tmp+=v1[v3[i][1]]\r\n vis[v3[i][1]]=1\r\n for i in range(c):\r\n if vis[i]==0:\r\n tmp+=v2[i]\r\n return tmp\r\n\r\n\r\nc,b=map(int,input().split())\r\nv1=list(map(int,input().split()))\r\nv2=list(map(int,input().split()))\r\nprint(solve(c,b,v1,v2))\r\n", "n, k = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\n\r\n\r\ndiff = []\r\nfor i in range(len(a)):\r\n diff.append((i,b[i]-a[i]))\r\n \r\ndiff = sorted(diff, reverse=True, key=lambda x: x[1])\r\n\r\ntotal = 0\r\nleft = k\r\nfor i in range(len(a)):\r\n #print(i, total, left, diff[i])\r\n if left>0 or diff[i][1]>0:\r\n left -= 1\r\n total += a[diff[i][0]]\r\n else:\r\n #print(b[diff[i][0]])\r\n total += b[diff[i][0]]\r\n \r\n #print(total, diff[i])\r\n \r\nprint(total)", "#!/usr/bin/env python3\n\ndef ri():\n return map(int, input().split())\n\nn, k = ri()\n\na = list(ri())\nb = list(ri())\nc = [a[i]-b[i] for i in range(n)]\n\nd = list(zip(c, a,b))\nd.sort()\nans = 0\nfor i in range(k):\n ans+=d[i][1]\nfor i in range(k, n):\n ans+=min(d[i][1], d[i][2])\n\nprint(ans)\n\n\n", "from sys import stdin, stdout\r\n\r\nn, k = list(map(int, stdin.readline().split()))\r\nsell_prices = list(map(int, stdin.readline().split()))\r\nnormal_prices = list(map(int, stdin.readline().split()))\r\n\r\ndiff = []\r\nfor index, pair in enumerate(zip(sell_prices, normal_prices)):\r\n bonus = pair[0] - pair[1]\r\n diff.append((index, bonus))\r\n\r\ndiff.sort(key=lambda x: x[1])\r\n\r\nsumm = 0\r\nnum_to_buy = 0\r\nfor item, bonus in diff:\r\n if num_to_buy < k or bonus < 0:\r\n summ += sell_prices[item]\r\n num_to_buy += 1\r\n else:\r\n summ += normal_prices[item]\r\n\r\nstdout.write(str(summ))\r\n", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nmas = [0] * n\r\nS = 0\r\nfor i in range(n):\r\n mas[i] = a[i] - b[i]\r\n S += b[i]\r\nmas.sort()\r\nfor i in range(n):\r\n if i < k or mas[i] < 0:\r\n S += mas[i]\r\nprint(S)", "n,k=input().split()\r\nn,k=int(n),int(k)\r\na,b=input().split(),input().split()\r\ndif=[]\r\ns=0\r\nfor i in range(0,n):\r\n dif.append(int(a[i])-int(b[i]))#store diffrence in list\r\n s+=int(a[i])\r\ndif=sorted(dif)\r\nfor i in range(k,n):#after atleast k discount if b[i]<a[i] use it\r\n if(dif[i]>0):\r\n s-=dif[i]\r\nprint(s)", "n,k = [int(i) for i in input().split()]\r\na = [int(i) for i in input().split()]\r\nb = [int(i) for i in input().split()]\r\nc=[]\r\nfor i in range(n):\r\n\ta[i] -= b[i]\r\n\tc.append(i)\r\nc = sorted(c,key = lambda x : a[x])\r\ns = 0\r\nfor i in range(n):\r\n\tif i < k or a[c[i]] < 0:\r\n\t\ts += a[c[i]] + b[c[i]]\r\n\telse:\r\n\t\ts += b[c[i]]\r\nprint(s)", "x=list(map(int, input().split()))\r\nn=x[0]\r\nk=x[1]\r\na=list(map(int, input().split()))\r\nb=list(map(int, input().split()))\r\nd=[a_i - b_i for a_i, b_i in zip(a, b)]\r\n#print(d)\r\ns=n-(sum(i > 0 for i in d))\r\n#print(s)\r\np=[x for _, x in sorted(zip(d, a))]\r\nq=[x for _, x in sorted(zip(d, b))]\r\n#print(p)\r\n#print(q)\r\nif s>=k:\r\n r1=p[:s]\r\n r2=q[s:]\r\n #print(r1)\r\n #print(r2)\r\nelse:\r\n r1=p[:k]\r\n r2=q[(k):]\r\n #print(r1)\r\n #print(r2)\r\nprint(sum(r1)+sum(r2))", "n, k = map(int, input().split())\r\nA = list(map(int, input().split()))\r\nB = list(map(int, input().split()))\r\nC = []\r\nfor i in range(n):\r\n C.append((A[i] - B[i], i))\r\nC.sort()\r\nans = 0\r\nfor i in range(k):\r\n ans += A[C[i][1]]\r\ng = n\r\nfor i in range(k, n):\r\n if C[i][0] <= 0:\r\n ans += A[C[i][1]]\r\n else:\r\n g = i\r\n break\r\nfor j in range(g, n):\r\n ans += B[C[j][1]]\r\nprint(ans)\r\n", "n, k = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nprofit = [(a[i] - b[i], a[i]) for i in range(n)]\nres = 0\nprofit.sort()\nfor elem in profit:\n if k <= 0 and elem[0] > 0:\n res += elem[1] - elem[0]\n else:\n res += elem[1]\n k -= 1\nprint(res)", "\nn,k = list(map(int,input().split()))\no = list(map(int,input().split()))\na = list(map(int,input().split()))\nans = sum(o)\ndiff = sorted([y-x for x,y in zip(o,a)],reverse=True)\n\nfor i in diff[k:]:\n if i>=0:\n pass\n else:\n ans += i\nprint(ans)", "n, k = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nwynik = 0\r\nlista = []\r\n\r\nfor x in range(n):\r\n lista.append(a[x] - b[x])\r\n wynik = wynik + b[x]\r\nlista.sort()\r\n\r\nfor x in range(len(lista)):\r\n if x < k or lista[x] < 0:\r\n wynik = wynik + lista[x]\r\nprint(wynik)", "a,b=map(int,input().split())\r\nz=[]\r\nfor i,j in zip(map(int,input().split()),map(int,input().split())):z+=[[i-j,i,j]]\r\nz.sort();s=0\r\nfor i in range(a):\r\n if i<b:s+=z[i][1]\r\n else:s+=min(z[i][1:])\r\nprint(s)", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\n\r\nclass CItem:\r\n\tdiff = 0\r\n\ta = 0\r\n\tb = 0\r\nItems = []\r\n\r\nfor i in range(0, n):\r\n\tItem = CItem()\r\n\tItem.a = a[i]\r\n\tItem.b = b[i]\r\n\tItem.diff = b[i] - a[i]\r\n\tItems.append(Item)\r\n\r\nItems.sort(key=lambda x: x.diff, reverse=True)\r\n\r\nmoney = 0\r\nfor i in range(0, k):\r\n\tmoney += Items[i].a\r\nfor i in range(k, n):\r\n\tmoney += min(Items[i].b, Items[i].a)\r\nprint(money)", "def buys(a: list, b: list, n: int, k: int) -> int:\n \n count_sum = sum(a) # сколько потратит, если купит все товары сразу\n\n for i in range(n):\n b[i] = b[i] - a[i] # посмотрим какие товары дешевле во вторую неделю\n\n b = sorted(b) # отсортируем по возрастанию товары второй недели чтобы взять сначала те что дешевле\n \n i = 0\n while i < n-k: # мы можем взять в вторую неделю только n-k самых дешевых товаров\n if b[i] > 0:\n break\n count_sum += b[i]\n i += 1\n \n return count_sum\n\nn, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nprint(buys(a, b, n, k))\n\t\t \t\t \t \t\t\t \t \t\t \t \t\t \t\t", "n, k = map(int, input().split())\n\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\nprofits = []\nfor i in range(n):\n profits.append((b[i] - a[i], i))\n\nprofits.sort(reverse=True)\n\ns = 0\nfor profit in profits[:k]:\n s += a[profit[1]]\n\nfor profit in profits[k:]:\n if profit[0] >= 0:\n s += a[profit[1]]\n else:\n s += b[profit[1]]\n\nprint(s)\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\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\nsum_max = sum(b)\r\nc = list(map(lambda x,y :x-y , a,b))\r\nc.sort()\r\nfor i in range(n):\r\n if (i<k) or (c[i] <0):\r\n sum_max += c[i]\r\n else:\r\n break\r\nprint(sum_max)", "n,m= map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nl=[(i,ii) for i,ii in zip(a,b)]\r\nl.sort(reverse=True,key = lambda x:x[1]-x[0])\r\nans=0\r\nfor ii,i in enumerate(l):\r\n if(ii<m):\r\n ans+=i[0]\r\n else:\r\n ans+=min(i[1],i[0])\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\nans=sum(b)\r\nfor i in range(0,len(a)):\r\n a[i]-=b[i]\r\na.sort()\r\nfor i in range(0,len(a)):\r\n if i<k or a[i]<0:\r\n ans+=a[i]\r\n else:\r\n break\r\nprint(ans)", "n,k=map(int,input().split())\r\nt=list(map(int,input().split()))\r\nc=list(map(int,input().split()))\r\nd=sorted([t[i]-c[i] for i in range(len(t))])\r\nn+=sum(t)\r\nfor i in range(k,len(d)):\r\n if 0<d[i]:n=n-d[i]\r\nprint(n-len(t))\r\n", "\r\nn,k=map(int,input().split())\r\narr=list(map(int,input().split()))\r\nbrr=list(map(int,input().split()))\r\ndiff=[(b-a,a,b) for a,b in zip(arr,brr)]\r\ndiff.sort(key=lambda x:x[0] ,reverse=True)\r\nans=0\r\nii=n\r\nfor i in range(n):\r\n if diff[i][0]>=0:\r\n ans+=diff[i][1]\r\n elif diff[i][0]<0 and i>=k:\r\n ii=i\r\n break\r\n else :\r\n ans+=diff[i][1]\r\nwhile ii<n:\r\n ans+=diff[ii][2]\r\n ii+=1\r\nprint(ans)", "n,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\nc = [a[i]-b[i] for i in range(n)]\r\ntotal = sum(a)\r\nc.sort()\r\ntotal_k = 0\r\nfor i in range(n):\r\n if c[i] > 0 and i >= k:\r\n break\r\n total_k = total_k + c[i]\r\ntotal = total + total_k - sum(c)\r\nprint(total)", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nc=[];count_=0;paisse=0\r\nfor i in range(n):\r\n if a[i]<=b[i]:\r\n count_+=1;paisse+=a[i]\r\n else:\r\n c.append([a[i],b[i]])\r\nif count_>=k:\r\n for i in c:\r\n paisse+=i[1]\r\n print(paisse)\r\nelse:\r\n for i in range(len(c)) :\r\n c[i]=[c[i][0]-c[i][1]]+c[i]\r\n \r\n c.sort()\r\n i=0\r\n while i<len(c):\r\n if i<k-count_:\r\n paisse+=c[i][1]\r\n else:\r\n paisse+=c[i][2]\r\n i+=1\r\n print(paisse) ", "n, k = map(int, input().split())\nnow = list(map(int, input().split()))\nltr = list(map(int, input().split()))\n\ncmb = [(now[i], ltr[i]) for i in range(n)]\ncmb.sort(key = lambda x : x[0] - x[1])\n\nans = sum(x[0] for x in cmb[:k])\n\nfor i in range(k, n):\n ans += min(cmb[i][0], cmb[i][1])\n\nprint(ans)", "n, k = list(map (int, input().split(' ')))\nprice_now = list(map (int, input().split(' ')))\nprice_sale = list(map (int, input().split(' ')))\n\nd = []\nsum = 0 \nk_ = 0\nfor i in range(n):\n d.append([price_now[i] - price_sale[i], price_now[i], price_sale[i]])\n\nd = sorted(d, key=lambda x: x[0])\n\nfor l in d:\n if l[0] < 0 or k_ < k:\n sum += l[1]\n k_ += 1\n else:\n sum += l[2]\n\nprint(sum)\n\t\t \t \t\t\t \t \t\t\t \t \t \t \t", "N, K = map( int, input().split() )\r\nA = list( map( int, input().split() ) )\r\nB = list( map( int, input().split() ) )\r\nans = sum( B )\r\nfor i in range( N ):\r\n A[ i ] -= B[ i ]\r\nA.sort()\r\nfor i in range( N ):\r\n if i < K or A[ i ] < 0:\r\n ans += A[ i ]\r\n else:\r\n break\r\nprint( ans )\r\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 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, k = r()\r\narr = rr()\r\nbrr = rr()\r\n\r\ncrr = [[i, j] for i, j in zip(arr, brr)]\r\n\r\ncrr.sort(key=lambda x: x[0] - x[1])\r\n\r\nans = 0\r\nfor i in range(k):\r\n ans += crr[i][0]\r\n \r\nfor i in range(k,n):\r\n ans += min(crr[i])\r\n\r\nprint(ans)", "n, k = map(int, input().split())\n\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\ndiff = [x - y for x, y in zip(a, b)]\n\n#print(k)\n#print(a)\n#print(b)\n#print(diff)\n\nindex = sorted(range(len(diff)), key=lambda x: diff[x])\n#print(index)\n\ncheat = len([x for x in diff if x < 0])\n#print(cheat)\nk = max(k, cheat)\n\nbnow = index[:k]\nblater = index[k:]\n\nbnow = [a[x] for x in bnow]\nblater = [b[x] for x in blater]\n\n#print(bnow)\n#print(blater)\n\nprint(sum(bnow) + sum(blater))\n\n", "'''\r\n\r\n5 3\r\n3 4 7 10 3\r\n4 5 5 12 5\r\n\r\n\r\n'''\r\n\r\n\r\ndef Sort(sub_li): \r\n \r\n # reverse = None (Sorts in Ascending order) \r\n # key is set to sort using second element of \r\n # sublist lambda has been used \r\n return(sorted(sub_li, key = lambda x: x[1])) \r\n\r\n\r\no=input().rstrip().split(' ')\r\np=input().rstrip().split(' ')\r\nq=input().rstrip().split(' ')\r\nn=int(o[0])\r\nk=int(o[1])\r\nL=[]\r\nfor i in range(0,len(p)):\r\n D=[]\r\n D.append(i)\r\n D.append(int(p[i]) - int(q[i]))\r\n L.append(D)\r\nL=Sort(L)\r\n# print(L)\r\nK=0;\r\nans = 0;\r\nfor i in range(0,len(L)):\r\n if L[i][1] <= 0:\r\n ans+=(int(p[L[i][0]]))\r\n K+=1;\r\n else:\r\n if K>=k:\r\n ans+=(int(q[L[i][0]]))\r\n else:\r\n K+=1;\r\n ans+=(int(p[L[i][0]]))\r\nprint(ans) ", "n,k=map(int,input().split())\r\na=[int(x) for x in input().split()]\r\nb=[int(x) for x in input().split()]\r\nc=sorted([a[i]-b[i] for i in range(n)])\r\ns=sum(b)\r\nfor i in range(n):\r\n if i>=k and c[i]>=0:\r\n break\r\n s+=c[i]\r\nprint(s)\r\n \r\n ", "# RawCoder : https://bit.ly/RCyouTube\r\n# Author : MehulYK\r\n\r\nn, k = map(int,input().split())\r\nf = list(map(int,input().split()))\r\ns = list(map(int,input().split()))\r\n#f.sort()\r\nif(k == n):\r\n print(sum(f))\r\nelse: \r\n cst = 0 \r\n d = []\r\n for i in range(n):\r\n comp = f[i] - s[i]\r\n d.append(comp)\r\n \r\n z = sorted(list(zip(d,f,s)))\r\n #print(z)\r\n j = 0 \r\n while(k != 0):\r\n ele = z[j]\r\n cst += ele[1]\r\n k -= 1\r\n j += 1\r\n for k in range(j, n):\r\n ele = z[k]\r\n if(ele[1] > ele[2]):\r\n cst += ele[2]\r\n else: \r\n cst += ele[1] \r\n print(cst) \r\n\r\n\r\n\r\n", "x,y=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nc=[]\r\nfor i in range(x):\r\n c.append(a[i]-b[i])\r\nc.sort()\r\nj=0\r\nk=sum(b)\r\nwhile j<x:\r\n if j<y or c[j]<0:\r\n k+=c[j] \r\n j+=1\r\n else:\r\n break\r\nprint(k) \r\n ", "def minCost(arr1,arr2,k):\r\n n=len(arr1)\r\n cost=0\r\n for i in arr1:\r\n cost+=i\r\n arr=list()\r\n for i in range(len(arr1)):\r\n diff=arr1[i]-arr2[i]\r\n arr.append(diff)\r\n \r\n arr.sort()\r\n i=n-1\r\n num=n-k\r\n while i>=0 and num>0:\r\n if arr[i]>0:\r\n cost-=arr[i]\r\n num-=1\r\n i-=1\r\n return cost;\r\n\r\ninputArray=input('').strip().split()\r\nn=int(inputArray[0])\r\nk=int(inputArray[1])\r\narr1=list()\r\narr2=list()\r\ninputArray=input('').strip().split()\r\nfor i in inputArray:\r\n arr1.append(int(i))\r\ninputArray=input('').strip().split()\r\nfor i in inputArray:\r\n arr2.append(int(i))\r\nprint(minCost(arr1,arr2,k))", "n,k=map(int,input().split())\r\nt=list(map(int,input().split()))\r\nc=list(map(int,input().split()))\r\nd=sorted([t[i]-c[i] for i in range(len(t))])\r\nn=sum(t)\r\nfor i in range(k,len(d)):n=n-max(d[i],0)\r\nprint(n)", "\r\nn,k=list(map(int,input().split()))\r\ndiscount=list(map(int,input().split()))\r\nnodiscount=list(map(int,input().split()))\r\ncount=0\r\nanswer=0\r\ndiv=[]\r\nfor i in range(n):\r\n div.append([discount[i]-nodiscount[i],discount[i],nodiscount[i]])\r\n #(div)\r\nfor key in sorted(div):\r\n count+=1\r\n if count<=k:\r\n answer+=key[1]\r\n #print(\"up\",div[1])\r\n elif count>k:\r\n answer += min(key[2],key[1])\r\n #print(\"down\",div[2])\r\n\r\nprint(answer)", "import heapq\r\n\r\ndef Solucion(n,k,a,b):\r\n res = 0\r\n dishonest = []\r\n \r\n # Por cada objeto se verifica que se haya escogido el que menos cuesta\r\n for i in range(n):\r\n if b[i] - a[i] >= 0:\r\n k-=1\r\n res += a[i]\r\n else:\r\n res += b[i]\r\n # Se guarda la diferencia de lo que se pierde si no escogemos este objeto con el precio de b\r\n heapq.heappush(dishonest, a[i] - b[i])\r\n \r\n # Por cada objeto que falta para escoger k \r\n if k > 0:\r\n # buscamos el minimo y sumamos lo que se pierde por escogerlo de la lista a\r\n # Para ello se ordena la lista y se escoge los k primeros\r\n for i in range(k):\r\n res+=heapq.heappop(dishonest)\r\n return res\r\n\r\n\r\n# recogemos la entrada\r\nn, k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\n\r\n#imprimimos la solución\r\nprint(Solucion(n,k,a,b))", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).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\nc = [i - j for i, j in zip(a, b)]\r\nc.sort()\r\nans = sum(b) + sum(c[:k])\r\nfor i in c[k:]:\r\n ans += min(0, i)\r\nprint(ans)", "n,k=[int(x) for x in input().split()]\r\na=[int(x) for x in input().split()]\r\nb=[int(x) for x in input().split()]\r\nchoices=[]\r\ndishonest=0\r\nmoney=0\r\nfor i in range(n):\r\n choices.append([a[i]-b[i],a[i],b[i]])\r\n if a[i]-b[i]<0:\r\n dishonest+=1\r\nchoices.sort(key=lambda x:(x[0]))\r\nm=max(k,dishonest)\r\nfor i in range(m):\r\n money+=choices[i][1]\r\nfor i in range(m,n):\r\n money+=choices[i][2]\r\nprint(money)\r\n", "n, k = map(int, input().split())\r\nAB = [[0 for x in range(3)] for x in range(n)]\r\nA = input().split()\r\nB = input().split()\r\nfor index in range(n):\r\n AB[index][0] = int(A[index])\r\n AB[index][1] = int(B[index])\r\n AB[index][2] = AB[index][0] - AB[index][1]\r\nAB = sorted(AB,key=lambda x: x[2])\r\nsummer = 0\r\nfor index in range(0, k):\r\n summer += AB[index][0]\r\nfor index in range(k, n):\r\n if AB[index][2] <= 0:\r\n summer += AB[index][0]\r\n else:\r\n summer += AB[index][1]\r\nprint(summer)\r\n", "n,k = map(int, input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nx=[(a[i]-b[i],a[i],b[i]) for i in range(n)]\r\nx.sort()\r\ns=x[0:k]\r\nt=[]\r\nfor i in range(k,n):\r\n if x[i][0]>0:\r\n t.append(x[i])\r\n else:\r\n s.append(x[i])\r\nans=0\r\nfor i in s:\r\n ans+=i[1]\r\nfor i in t:\r\n ans+=i[2]\r\nprint(ans)", "from collections import namedtuple, deque\nfrom operator import attrgetter\n\nCost = namedtuple('Cost', 'value position')\n\ndef minimal_summ(min_count, cost_during, cost_after):\n difference_cost = tuple((Cost(value_d - value_a, position)\n for position, (value_d, value_a) in\n enumerate(zip(cost_during, cost_after))))\n difference_cost = deque(sorted(difference_cost, key=attrgetter('value')))\n result = 0\n while len(difference_cost) > 0:\n item = difference_cost.popleft()\n if item.value <= 0:\n result += cost_during[item.position]\n else:\n if min_count > 0:\n result += cost_during[item.position]\n else:\n difference_cost.append(item)\n break\n min_count -= 1\n\n while len(difference_cost) > 0:\n item = difference_cost.pop()\n result += cost_after[item.position]\n\n return result\n\n\n\n\ndef main():\n generic_count, min_count = map(int, input().strip().split())\n cost_during = tuple(map(int, input().split()))\n cost_after = tuple(map(int, input().split()))\n print(minimal_summ(min_count, cost_during, cost_after))\n\nif __name__ == '__main__':\n main()\n", "n, k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\npaidmoney = sum(b)\r\nc = sorted(list(map(lambda x,y :x-y , a,b)))\r\nfor i in range(n):\r\n if i<k or c[i] <0 : paidmoney += c[i]\r\n else: break\r\nprint(paidmoney)\r\n", "n,k = map(int,input().split())\narr1 = [int(x) for x in input().split()]\narr2 = [int(x) for x in input().split()]\narr3 = [10001]*n\ncnt = 0\ntt = 0\nfor i in range(n):\n\tif arr1[i]>arr2[i]:\n\t\ttt += arr2[i]\n\t\tarr3[i] = arr1[i]-arr2[i]\n\telse:\n\t\ttt += arr1[i]\n\t\tcnt += 1\n\nif cnt>=k:\n\tprint(tt)\nelse:\n\tarr3.sort()\n\ti = 0\n\twhile cnt<k:\n\t\ttt += arr3[i]\n\t\tcnt += 1\n\t\ti += 1\n\tprint(tt)\n\t\t\n", "n , k = map(int, input().split())\r\nop = [int(i) for i in input().split()]\r\nnp = [int(i) for i in input().split()]\r\ndiff = [(i,op[i]-np[i]) for i in range(len(op))]\r\n\r\ndiff_sort = sorted(diff,key =lambda x:x[1])\r\ni = 0\r\ntc = 0\r\n\r\nfor i in range(len(diff_sort)):\r\n if k>0 or diff_sort[i][1]<0:\r\n tc+=op[diff_sort[i][0]]\r\n k-=1\r\n else:\r\n tc+=np[diff_sort[i][0]]\r\n\r\nprint(tc)\r\n", "import sys\nimport math\nfrom collections import defaultdict\n\n# sys.stdin = open('input.txt', 'r')\n# sys.stdout = open('output.txt', 'w')\n\ndef solve(test):\n\tn, k = map(int, input().split())\n\ta = list(map(int, input().split()))\n\tb = list(map(int, input().split()))\n\tc = [(a[i] - b[i], a[i], b[i]) for i in range(n)]\n\tc.sort(key = lambda x: x[0])\n\tans = 0\n\tfor i in range(n):\n\t\tval, dis, act = c[i]\n\t\tif val <= 0:\n\t\t\tans += dis\n\t\t\tk -= 1\n\t\telif k > 0:\n\t\t\tans += dis\n\t\t\tk -= 1\n\t\telse:\n\t\t\tans += act\n\n\tprint(ans)\n\nif __name__ == \"__main__\":\n\ttest_cases = 1\n\tfor t in range(1, test_cases + 1):\n\t\tsolve(t)\n\n\t \t\t\t\t\t \t \t \t\t \t\t\t\t\t \t", "R=lambda:list(map(int,input().split()))\r\nn,k=R()\r\na=R()\r\nb=R()\r\nans=sum(b)\r\nfor i in range(n): a[i]-=b[i]\r\na=sorted(a)\r\nfor i in range(n):\r\n if i<k or a[i]<0: ans += a[i]\r\n else: break\r\nprint(ans)", "var1, var2 = input().split()\nvar1, var2 = [int(var1), int(var2)]\np1 = input().split()\np2 = input().split()\np1 = [int(i) for i in p1]\np2 = [int(i) for i in p2]\ndf = [p1[i]-p2[i] for i in range (0,var1)]\n#sort + index\ns = sorted(df)\n#sum all element after discount\nsumx = sum(p2)\n#if price in discount cheaper => give money back\nfor i in range(var1):\n if (s[i]>0 and i>=var2): break\n sumx = sumx + s[i]\nprint(sumx)", "n,k = map(int, input().split())\nduringDiscount = list(map(int, input().split()))\nafterDiscount = list(map(int, input().split()))\n\ndifferences = []\nfor i,item in enumerate(zip(duringDiscount, afterDiscount)):\n differences.append((item[1] - item[0], i))\n\nlista = sorted(differences, key=lambda x: x[0], reverse=True)\nans = 0\n\nfor discount,index in lista:\n if k > 0:\n ans += duringDiscount[index]\n k -= 1\n else:\n if discount >= 0:\n ans += duringDiscount[index]\n else:\n ans += afterDiscount[index]\n\nprint(ans)", "n,k=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nprice=[[] for i in range(n)]\r\nfor i in range(n):\r\n price[i].append(a[i])\r\n price[i].append(b[i])\r\n price[i].append(a[i]-b[i])\r\nprice.sort(key=lambda x:x[2])\r\nmin=0\r\nfor i in range(k):\r\n min+=price[i][0]\r\nwhile k<n and price[k][2]<0:\r\n min+=price[k][0]\r\n k+=1\r\nwhile k<n:\r\n min+=price[k][1]\r\n k+=1\r\nprint(min)\r\n", "#t1=int(input())\r\n#for i in range(t1):\r\n#n=int(input())\r\nn,k = map(int, input().strip().split(' '))\r\nlst1 = list(map(int, input().strip().split(' ')))\r\nlst2 = list(map(int, input().strip().split(' ')))\r\ns=0\r\nc=0\r\nl3=[]\r\nfor j in range(n):\r\n if lst1[j]<=lst2[j]:\r\n s+=lst1[j]\r\n c+=1\r\n else:\r\n s+=lst2[j]\r\n l3.append(lst1[j]-lst2[j])\r\nif c>=k:\r\n print(s)\r\nelse:\r\n l3.sort()\r\n for j in range(k-c):\r\n s+=l3[j]\r\n print(s)", "n , k = list(map(int,input().split()))\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\n\r\nfor i in range(n):\r\n b[i]-=a[i]\r\nc = list(zip(a,b))\r\nc = sorted(c,key = lambda x:-x[1])\r\nans = 0\r\nz = 0\r\nfor i in range(n):\r\n if c[i][1]>=0 or z<k:\r\n ans+=c[i][0]\r\n z+=1\r\n else :\r\n ans+= c[i][0]+c[i][1]\r\nprint(ans)\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\nc = sum(b)\r\nfor i in range(n):\r\n a[i] -= b[i]\r\na = sorted(a)\r\nfor i in range(n):\r\n if i<k or a[i]<0:\r\n c += a[i]\r\nprint(c)\r\n \r\n\r\n", "\r\n\r\nn,min = map(int,input().split(' '))\r\nfirst_week = list(map(int,input().split(' ')))\r\nsecond_week = list(map(int,input().split(' ')))\r\n\r\nfor i in range(n):\r\n first_week[i] -= second_week[i]\r\nprice = sum(second_week)\r\nfirst_week = sorted(first_week)\r\nfor i in range(n):\r\n if first_week[i] < 0 or i < min:\r\n price += first_week[i]\r\nprint (price)", "import sys\r\nfrom itertools import accumulate\r\n\r\ndef debug(x, table):\r\n for name, val in table.items():\r\n if x is val:\r\n print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)\r\n return None\r\n\r\ndef solve():\r\n n, k = map(int, input().split())\r\n A = [int(i) for i in input().split()]\r\n B = [int(i) for i in input().split()]\r\n sumB = sum(B)\r\n dif = [a - b for a, b in zip(A, B)]\r\n dif.sort()\r\n dif = [0] + list(accumulate(dif))\r\n\r\n ans = float('inf')\r\n\r\n for i in range(k, n + 1):\r\n ans = min(ans, sumB + dif[i])\r\n\r\n print(ans)\r\n \r\n\r\nif __name__ == '__main__':\r\n solve()", "cnt = lambda s, x: s.count(x)\r\nii = lambda: int(input())\r\nsi = lambda: input()\r\nf = lambda: map(int, input().split())\r\ndgl = lambda: list(map(int, input()))\r\nil = lambda: list(map(int, input().split()))\r\nn,k=f()\r\nbd=il()\r\nad=il()\r\nsm=0\r\ndif=[]\r\nfor i in range(n):\r\n dif.append([bd[i]-ad[i], i])\r\ndif.sort()\r\nfor i in range(n):\r\n if k>0:\r\n sm+=bd[dif[i][1]]\r\n k-=1\r\n else:\r\n if dif[i][0]>=0:\r\n sm+=ad[dif[i][1]]\r\n else:\r\n sm+=bd[dif[i][1]]\r\nprint(sm)", "read=lambda:map(int,input().split())\r\nn,k=read()\r\na=list(read())\r\nb=list(read())\r\nl=[]\r\nfor i in range(n):\r\n l.append((a[i],b[i]))\r\nl.sort(key=lambda tup:tup[0]-tup[1])\r\nans=0\r\nfor i in range(k):\r\n ans+=l[i][0]\r\nfor i in range(k,n):\r\n ans+=min(l[i][0],l[i][1])\r\nprint(ans)\r\n", "n,k=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nc=[]\r\nd=[]\r\nfor i in range(n):\r\n if a[i]<b[i]:\r\n c.append([a[i],b[i]])\r\n else:\r\n d.append([-b[i]+a[i],a[i],b[i]])\r\nif len(c)>=k:\r\n s=0\r\n for i in range(len(c)):\r\n s=s+c[i][0]\r\n for i in range(len(d)):\r\n s=s+d[i][2]\r\nelse:\r\n d.sort()\r\n s=0\r\n for i in range(len(c)):\r\n s=s+c[i][0]\r\n for i in range(k-len(c)):\r\n s=s+d[i][1]\r\n for i in range(k-len(c),len(d)):\r\n s=s+d[i][2]\r\nprint(s)", "def min_price(n,k,l,m):\r\n s=sum(m)\r\n for i in range(n):\r\n l[i]-=m[i]\r\n l.sort()\r\n for i in range(n):\r\n if i<k or l[i]<0:\r\n s+=l[i]\r\n else:\r\n break\r\n return s\r\n\r\nn,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nm=list(map(int,input().split()))\r\nprint(min_price(n,k,l,m))", "import math as mt \nimport sys,string\ninput=sys.stdin.readline\nimport random\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,k=M()\na=L()\nb=L()\nl=[]\nfor i in range(n):\n l.append((a[i]-b[i],a[i],i))\nl.sort(key=lambda x:x[0])\ni=0\nans=0\nwhile(i<k):\n ans+=l[i][1]\n i+=1\nwhile(k<n):\n ans+=min(a[l[k][2]],b[l[k][2]])\n k+=1\nprint(ans)\n", "import sys\r\nfrom collections import defaultdict\r\ninput = sys.stdin.readline\r\n\r\n# functions:\r\n\r\ndef f1():\r\n return int(input())\r\n\r\ndef f2():\r\n return map(int,input().split())\r\n\r\n# Main\r\n\r\nn, k = f2()\r\nA = list(f2())\r\nB = list(f2())\r\nC = []\r\nfor i in range(n):\r\n C.append((B[i]-A[i], A[i], B[i]))\r\nC.sort(reverse=True)\r\ns = 0\r\nfor i in range(n):\r\n if i<k or C[i][0]>0:\r\n s += C[i][1]\r\n else:\r\n s += C[i][2]\r\n# print(k,C)\r\nprint(s)", "#!/usr/bin/pypy3\n\nfrom sys import stdin,stderr\n\ndef readInts(): return map(int,stdin.readline().strip().split())\ndef print_err(*args,**kwargs): print(*args,file=stderr,**kwargs)\n \ndef solve(n,k,a,b):\n ps = []\n for ix in range(n):\n ps.append( (a[ix]-b[ix],a[ix],b[ix]) )\n ps.sort()\n out = 0\n for ix in range(n):\n if ps[ix][0] <= 0 or ix<k: out += ps[ix][1]\n else: out += ps[ix][2]\n return out\n\ndef run():\n n,k = readInts()\n a = list(readInts())\n b = list(readInts())\n print(solve(n,k,a,b))\n \nrun()\n", "n, k = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = [(a[i], b[i]) for i in range(n)]\n\nc.sort(key=lambda x : x[0] - x[1])\nsm = 0\nfor i in range(k):\n sm += c[i][0]\nfor i in range(k, n):\n sm += min(c[i][0], c[i][1])\nprint(sm)", "from operator import itemgetter;\n\nN, K = [int(n) for n in input().split()]\n\naa = [int(n) for n in input().split()]\nprices = [[aa[i], aa[i] - int(n)] for i, n in enumerate(input().split())]\n\n\nprices = sorted(prices, key=itemgetter(1))\n\nsum_n = 0\nfor i, price in enumerate(prices):\n if i < K:\n sum_n += price[0]\n else:\n if price[1] > 0:\n sum_n += price[0] - price[1]\n else:\n sum_n += price[0]\n\nprint(sum_n)\n\n", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\n\r\nc = [(a[i], b[i]) for i in range(n)]\r\nc.sort(key = lambda val: val[0]-val[1])\r\n\r\nres = 0\r\nfor i in c:\r\n \r\n if k>0 or i[0]<i[1]:\r\n res += i[0]\r\n k-=1\r\n else:\r\n res += i[1]\r\n \r\nprint(res)", "n,k=map(int,input().split())\r\nt=list(map(int,input().split()))\r\nc=list(map(int,input().split()))\r\nd=[t[i]-c[i] for i in range(len(t)) if 0<t[i]-c[i]]\r\ns=0\r\nfor i in t:\r\n s+=i\r\nd.sort()\r\nn=n-k\r\nwhile(n and d):\r\n n-=1\r\n s-=d.pop()\r\nprint(s)\r\n", "n,k=map(int,input().split())\r\nl=[(int(i)-int(j),int(i),int(j)) for i,j in zip(input().split(),input().split())]\r\nl.sort()\r\n#print(l)\r\nans=0\r\nfor i in range(n):\r\n if k>0:\r\n ans+=l[i][1]\r\n k-=1\r\n else: ans+=min(l[i][1:])\r\nprint(ans)\r\n", "from bisect import bisect\r\n\r\nn, k = map(int, input().split())\r\n\r\naa = map(int, input().split())\r\nbb = list(map(int, input().split()))\r\n\r\ndd = sorted(a - b for a, b in zip(aa, bb))\r\nk = max(k, bisect(dd, 0))\r\n\r\nprint(sum(bb) + sum(dd[:k]))", "from sys import stdin, stdout\n\ndef get_prices():\n prices = []\n lst1 = [int(x) for x in stdin.readline().rstrip(\"\\r\\n\").split()]\n lst2 = [int(x) for x in stdin.readline().rstrip(\"\\r\\n\").split()]\n for i in range(n):\n prices.append((lst1[i] - lst2[i], lst1[i], lst2[i]))\n return sorted(prices)\n\n\ndef solve(n, k, prices):\n amount = 0\n remain = 0\n for price in prices:\n if price[0] < 0:\n amount += price[1]\n else:\n if k - remain > 0:\n amount += price[1]\n else:\n amount += price[2]\n remain += 1\n return amount\n\n\nn, k = map(int, input().split())\nprices = get_prices()\n\nsolution = solve(n,k,prices)\n\nprint(solution)\n", "# print(\"Input n and k\")\nn,k = [int(x) for x in input().split()]\n\n# print(\"Enter all the current prices\")\na = [int(x) for x in input().split()]\n\n# print(\"Enter the prices later\")\nb = [int(x) for x in input().split()]\n\nthelist = []\nfor i in range(len(a)):\n # A negative value is one you need to take now if possible\n nextentry = (a[i]-b[i], a[i], b[i])\n thelist.append(nextentry)\n\nthelist.sort()\n\nanswer = 0\n# Buy the first k items at the first k a[i] costs (since you need to)\nindex = 0\nwhile index < k:\n answer += thelist[index][1]\n index += 1\n\n# Now take any more a[i] that are negative (maybe all of them)\nwhile index < len(a) and thelist[index][0] < 0:\n answer += thelist[index][1]\n index += 1\n\n# All the rest are the b[i] in cost\nwhile index < len(a):\n answer += thelist[index][2]\n index += 1\n\nprint(answer)\n\n\n\n\n\n\n\n\n", "n,k = map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nx=[b[i]-a[i] for i in range(n) if b[i]-a[i]<0]\r\nx.sort()\r\nans=sum(a)+sum(x[:n-k])\r\nprint(ans)", "n, k = map(int, input().split())\nnow = [int(inp) for inp in input().split()]\nafter = [int(inp) for inp in input().split()]\n\ndiff = []\nfor i in range(n):\n diff.append([after[i] - now[i], i])\ndiff.sort(key = lambda x: x[0])\n\nans = 0\nfor i in range(n-1, -1, -1):\n index = diff[i][1]\n if k > 0 or diff[i][0] >= 0:\n ans += now[index]\n k -= 1\n else:\n ans += after[index]\nprint(ans)\n\n", "n, k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\nc=0\r\ncost=0\r\nl=sorted(list(zip(a,b)),key=lambda x: x[0]-x[1])\r\nfor i in l:\r\n if c<k:\r\n c+=1\r\n cost+=i[0]\r\n else:\r\n if i[0]<i[1]:\r\n cost+=i[0]\r\n else:\r\n cost+=i[1]\r\nprint(cost)\r\n\r\n\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\nm = []\r\nres = 0\r\nfor i in range(n):\r\n m.append([B[i] - A[i], (A[i], B[i])])\r\nm.sort(reverse = True)\r\nfor i in range(n):\r\n if i < k:\r\n res += m[i][1][0]\r\n else:\r\n res += min(m[i][1][0], m[i][1][1])\r\nprint(res)", "n, k = map(int, input().split())\r\nbefore = [int(i) for i in input().split()]\r\nafter = [int(i) for i in input().split()]\r\ndifference = sorted([[after[i] - before[i],i] for i in range(n)])\r\nj = 0\r\nfor i in range(n):\r\n if difference[i][0] > 0:\r\n j = n-i\r\n break\r\nfinal_sum = 0\r\nfor i in range(max(k,j)):\r\n final_sum += before[difference[-i-1][1]]\r\nfor i in range(n-max(k,j)):\r\n final_sum += after[difference[i][1]]\r\nprint(final_sum)\r\n ", "n,k=map(int,input().split(\" \"))\r\nlst1=list(map(int,input().split(\" \")))\r\nlst2=list(map(int,input().split(\" \")))\r\nd=sorted(a-b for a,b in zip(lst2,lst1) if(a-b<0))\r\nprint(\"{}\".format(sum(lst1)+sum(d[:n-k])))", "n, k = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\nlst = list(zip(a, b))\nlst = sorted(lst, key = lambda x: x[1] - x[0], reverse=True)\n\nprint(sum([i[0] for i in lst[:k]]) + sum([i[0] if i[0] < i[1] else i[1] for i in lst[k:]]))\n\t \t\t \t \t\t\t \t \t\t \t\t \t\t \t\t", "def main():\r\n n, k = tuple(map(int, input().split(' ')))\r\n list_curr = list(map(int, input().split(' ')))\r\n list_next = list(map(int, input().split(' ')))\r\n list_zip = list(zip(list_curr, list_next))\r\n list_zip.sort(key=lambda x: x[0]-x[1])\r\n price = 0\r\n for i in range(n):\r\n if i < k:\r\n price += list_zip[i][0]\r\n else:\r\n price += min(list_zip[i][0], list_zip[i][1])\r\n print(price)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "I = lambda: list(map(int, input().split()))\r\nn, k = I()\r\na = I()\r\nb = I()\r\nd = sorted([bb-aa for bb, aa in zip(b, a) if bb-aa<0])\r\nprint(sum(a)+sum(d[:n-k]))", "n, k = map(int, input().split())\na = [int(x) for x in input().split()]\nb = [int(x) for x in input().split()]\na_marked = [(a[i], b[i], a[i] - b[i]) for i in range(n)]\na_marked.sort(key=lambda t: t[2]) # отсортировали по разнице b_i - a_i\n\n# сначала берем те товары, у которых цена изменится на наименьшее (в т.ч. сначала те, что подорожают)\ntaken = 0\nmoney = 0\n\nstop = 0\ntaken_all = True\n\n# берем до распродажи\nfor i in range(n):\n # пока надо брать\n if taken < k:\n taken += 1\n money += a_marked[i][0]\n else:\n # если подорожает, берем\n if a_marked[i][2] < 0:\n money += a_marked[i][0]\n else:\n stop = i\n taken_all = False\n break\n\n# берем после распродажи остаток\nif taken_all == False:\n for i in range(stop, n):\n money += a_marked[i][1]\n\nprint(money)\n \t \t\t\t \t\t \t\t \t\t\t\t\t \t\t\t", "# Description of the problem can be found at http://codeforces.com/problemset/problem/779/C\r\n\r\nn, k = map(int, input().split())\r\n\r\nl_d = list(map(int, input().split()))\r\nl_a = list(map(int, input().split()))\r\n\r\nl_pd = list()\r\nfor i in range(n):\r\n l_pd.append([l_d[i] - l_a[i], i])\r\n\r\nl_pd.sort()\r\n\r\nt_b = 0\r\np = 0\r\nfor l in l_pd:\r\n if l[0] <= 0 or t_b < k:\r\n t_b += 1\r\n p += l_d[l[1]]\r\n else:\r\n p += l_a[l[1]]\r\n\r\nprint(p)", "# 2 days of discounts and prices\r\n# x = he should buy on the first day (could be more)\r\nn, x = list(map(int, input().split()))\r\nlist1 = list(map(int, input().split()))\r\nlist2 = list(map(int, input().split()))\r\n\r\nopt_paid = 0\r\n\r\nfor i in range (n):\r\n opt_paid += min(list1[i], list2[i])\r\n\r\ndiff = []\r\n\r\nfor i in range (n):\r\n diff.append(list1[i] - list2[i])\r\ndiff.sort()\r\n\r\nfor j in range (x):\r\n if (diff[j] > 0):\r\n opt_paid += diff[j]\r\n\r\nprint (opt_paid)\r\n\r\n\r\n", "n, k = list(map(int, input().split()))\nbefore = list(map(int, input().split()))\nafter = list(map(int, input().split()))\n# посчитаем, сколько бы он потратил, купив все до скидок\nans = sum(before)\n# вычтем из after before и отсортируем по не возрастанию\ndiff = sorted([y - x for x, y in zip(before, after)], reverse=True)\n\n# выберем n-k элементов из массива разностей с конца (наим значения, т е наиб выгодные)\nfor i in diff[k:]:\n if i >= 0:\n pass\n else:\n ans += i\nprint(ans)\n\n\t\t \t \t \t\t\t \t\t \t \t\t\t \t\t \t \t\t", "from operator import itemgetter\n\ndef main():\n num_item, min_buy = [int(x) for x in input().split()]\n first_week = [int(x) for x in input().split()]\n second_week = [int(x) for x in input().split()]\n diff = [(first_week[x] - second_week[x], x) for x in range(len(first_week))]\n\n diff = sorted(diff, key=itemgetter(0))\n sum = 0\n\n for i in range(min_buy):\n sum += first_week[diff[i][1]]\n for i in range(min_buy, len(first_week)):\n if (diff[i][0] <= 0):\n sum += first_week[diff[i][1]]\n else:\n sum += second_week[diff[i][1]]\n\n print(sum)\n\nif __name__=='__main__':\n main()\n", "def sol(n, k, a, b):\n\tdiff = [(a[i] - b[i], i) for i in range(n)]\n\tdiff.sort()\n\ttot = 0\n\tfor i in range(k):\n\t\ttot += a[diff[i][1]]\n\t\n\tfor i in range(k, n):\n\t\ttot += min(a[diff[i][1]], b[diff[i][1]])\n\treturn tot\n\nif __name__ == \"__main__\":\n\tn, k = map(int, input().split())\n\ta = list(map(int, input().split()))\n\tb = list(map(int, input().split()))\n\tprint (sol(n, k, a, b))\n\n \t \t\t \t \t\t\t \t\t \t", "n ,k = map(int, input().split())\npn = list(map(int, input().split()))\npl = list(map(int, input().split()))\npri = []\nfor i in range(n):\n\tpri.append([pn[i]-pl[i],i])\npri = sorted(pri, key = lambda t:t[0])\nc = 0\nt = 0\nfor i in range(n):\n\tif t<k:\n\t\tc += pn[pri[i][1]]\n\t\tt += 1\n\telse:\n\t\tif pri[i][0]<0:\n\t\t\tc += pn[pri[i][1]]\n\t\telse:\n\t\t\tc += pl[pri[i][1]]\nprint(c)\n\t\t\n\t\t\n", "n,k = map(int,input().split())\r\n\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\n\r\nlis = []\r\nfor i in range(n):\r\n lis.append([a[i]-b[i],i])\r\n\r\nlis.sort()\r\n#print(lis)\r\n\r\nres = 0\r\nfor i in range(n):\r\n if i<k or lis[i][0]<0:\r\n res += a[lis[i][1]]\r\n else:\r\n res += b[lis[i][1]]\r\n\r\nprint(res)\r\n", "def main():\r\n n, k = map(int, input().split())\r\n a, b = list(map(int, input().split())), list(map(int, input().split()))\r\n\r\n difference_arr = []\r\n for i in range(n):\r\n difference_arr.append((a[i] - b[i], i))\r\n difference_arr.sort(key=lambda x: x[0])\r\n\r\n counter = 0\r\n total = 0\r\n for i in range(n):\r\n if difference_arr[i][0] <= 0:\r\n counter += 1\r\n total += a[difference_arr[i][1]]\r\n elif counter >= k:\r\n counter += 1\r\n total += b[difference_arr[i][1]]\r\n else:\r\n counter += 1\r\n total += a[difference_arr[i][1]]\r\n print(total)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "\n\nn,k=map(int,input().split())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nans=0\nlt=[]\nfor i in range(n):\n tt=[]\n tt.append(a[i]-b[i])\n tt.append(b[i])\n tt.append(a[i])\n lt.append(tt)\nlt.sort()\nfor it in lt:\n if k>0 or it[0]<0:\n ans+=it[2]\n k=k-1\n # print(it,11)\n else:\n ans+=it[1]\n #print(it)\nprint(ans)\n\t \t\t \t\t \t \t \t\t \t", "n,k=map(int,input().split())\nnow=list(map(int,input().split()))\nafter=list(map(int,input().split()))\nde=[[i,after[i]-now[i]] for i in range(n)]\nde = sorted(de,key= lambda x : x[1],reverse= True)\nres=0\nfor i in range(n):\n if de[i][1]>0:\n res+=now[de[i][0]]\n k-=1\n elif de[i][1]<=0 and k>0:\n res += now[de[i][0]]\n k -= 1\n else:\n res += after[de[i][0]]\n#print(de)\nprint(res)\n \t\t\t \t\t \t \t \t\t \t \t \t\t\t\t", "def min_price(n,k,l,m):\r\n d,s=[],0\r\n for i in range(n):\r\n d.append(l[i]-m[i])\r\n d.sort()\r\n for i in range(n):\r\n if i<k or d[i]<0:\r\n s+=d[i]\r\n else:\r\n break\r\n return sum(m)+s\r\n\r\nn,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nm=list(map(int,input().split()))\r\nprint(min_price(n,k,l,m))", "n,k= input().split()\r\nn,k=int(n),int(k)\r\nsum=0\r\nnow,then=input().split(),input().split()\r\ndiff=[]\r\nfor i in range(0,n):\r\n diff.append(int(now[i])-int(then[i]))\r\n sum+=int(now[i])\r\ndiff=sorted(diff)\r\nfor i in range(k,n):\r\n if diff[i]>0: sum-=diff[i]\r\nprint(sum)", "n,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\nc = []\r\nfor i in range(len(a)):\r\n c.append([a[i]-b[i],a[i],b[i]])\r\nc = sorted(c)\r\nl = 0\r\nfor i in range(len(c)):\r\n if(c[i][0]<=0):\r\n l+=c[i][1]\r\n elif(i<k):\r\n l+=c[i][1]\r\n else:\r\n l+=c[i][2]\r\nprint(l)\r\n", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nc=[0]*n\r\nfor i in range (n):\r\n c[i]=[a[i]-b[i],i]\r\nc.sort()\r\ns=0\r\nfor i in range(k):\r\n ind=c[i][1]\r\n s+=a[ind]\r\nfor i in range(k,n):\r\n ind=c[i][1]\r\n s+=min(a[ind],b[ind])\r\nprint(s)", "read = lambda: map(int, input().split())\r\nn, k = read()\r\na = list(read())\r\nb = list(read())\r\nc = sorted([(a[i], b[i]) for i in range(n)], key = lambda x: x[0] - x[1])\r\nans = sum(c[i][0] for i in range(k)) + sum(min(c[i]) for i in range(k, n))\r\nprint(ans)", "n , k = map(int,input().split())\r\nl1 = list(map(int,input().split()))\r\nl2 = list(map(int,input().split()))\r\n\r\nans = sum(l2)\r\n\r\nr1 = []\r\nfor i in range(n):\r\n r1.append(l1[i] - l2[i])\r\n\r\nr1 = sorted(r1)\r\n#print(r1)\r\n\r\nfor i in range(n):\r\n if i < k or r1[i] < 0 :\r\n ans+= r1[i]\r\n\r\nprint(ans)\r\n", "X = list(map(int, input().split()))\r\nThis = list(map(int, input().split()))\r\nThat = list(map(int, input().split()))\r\nWhole = sorted(zip(This, That), key=lambda x: x[0] - x[1])\r\n \r\nSum = 0\r\nfor i in range(X[0]):\r\n if X[1] > 0:\r\n Sum += Whole[i][0]\r\n X[1] -= 1\r\n else:\r\n Sum += min(Whole[i][0], Whole[i][1])\r\nprint(Sum)\r\n\r\n# Hope the best for Ravens\r\n# Never give up\r\n", "n, k = [int(x) for x in input().split()]\r\na = [int(x) for x in input().split()]\r\nb = [int(x) for x in input().split()]\r\nc = [(ai, ai-bi) for ai, bi in zip(a, b)]\r\nc.sort(key=lambda x:x[1])\r\ns = 0\r\nfor i in range(n):\r\n if i<k or c[i][1] <= 0:\r\n s += c[i][0]\r\n else: \r\n s += c[i][0] - c[i][1]\r\nprint(s)", "n, k = map(int, input().split())\n\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\nc, cost = [], 0\nfor i in range(n):\n\tc.append([a[i]-b[i], i])\nc.sort(key=lambda x: x[0])\ni = 0\nwhile i<n and (c[i][0]<0 or k>0):\n\tcost += a[c[i][1]]\n\ti += 1\n\tk -= 1\nwhile i<n:\n\tcost += b[c[i][1]]\n\ti += 1\nprint(cost)\n", "from heapq import heappush, heappop\r\n\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nq = []\r\nfor i in range(n):\r\n heappush(q, (a[i]-b[i], a[i], b[i]))\r\nres = 0\r\nfor _ in range(k):\r\n res += heappop(q)[1]\r\nwhile q:\r\n t = heappop(q)\r\n res += min(t[1], t[2]) \r\nprint (res)\r\n", "class toode:\n def __init__(self,a,b):\n self.hind1=a\n self.hind2=b\n def __str__(self):\n return str(self.hind1)+\" \" + str(self.hind2)\ndef Compare(a,b):\n return (a.hind1-a.hind2)-(b.hind1-b.hind2)\ndef cmp_to_key(mycmp):\n 'Convert a cmp= function into a key= function'\n class K(object):\n def __init__(self, obj, *args):\n self.obj = obj\n def __lt__(self, other):\n return mycmp(self.obj, other.obj) < 0\n def __gt__(self, other):\n return mycmp(self.obj, other.obj) > 0\n def __eq__(self, other):\n return mycmp(self.obj, other.obj) == 0\n def __le__(self, other):\n return mycmp(self.obj, other.obj) <= 0\n def __ge__(self, other):\n return mycmp(self.obj, other.obj) >= 0\n def __ne__(self, other):\n return mycmp(self.obj, other.obj) != 0\n return K\nn,k=map(int,input().split())\na,b=list(map(int,input().split())),list(map(int,input().split()))\ntooted=sorted([toode(a[i],b[i]) for i in range(n)],key=cmp_to_key(Compare))\nans=0\nfor x in range(k):\n ans+=tooted[x].hind1\nfor x in range(k,n):\n ans+=min(tooted[x].hind1,tooted[x].hind2)\nprint(ans)\n", "from operator import itemgetter\r\nn,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nar=[]\r\n\r\nfor i in range (n):\r\n ar.append([a[i],b[i],(a[i] - b[i])])\r\n\r\nar=sorted(ar,key=itemgetter(2))\r\n\r\nco=0\r\nfor i in range (k):\r\n co+=ar[i][0]\r\n\r\nfor i in range (k,n):\r\n if(ar[i][2]<0):\r\n co+=ar[i][0]\r\n else:\r\n co+=ar[i][1]\r\n\r\nprint(co)\r\n\r\n", "n,k=map(int,input().split())\r\nl1=list(map(int,input().split()))\r\nl2=list(map(int,input().split()))\r\nl=list(zip(l1,l2))\r\nl.sort(key = lambda x: x[0]-x[1])\r\ns=0\r\nc=0\r\n#print(l)\r\nfor i in range(n):\r\n if l[i][0]-l[i][1]<=0:\r\n s+=l[i][0]\r\n c+=1\r\n elif c<k:\r\n s+=l[i][0]\r\n c+=1\r\n else:\r\n s+=l[i][1]\r\nprint(s)", "\r\ndef Solucion(n,k,a,b):\r\n aux = []\r\n sum = 0\r\n tomado_a = 0\r\n \r\n # ponemos todas las diferencias de precio en una lista guardando el índice además\r\n for i in range(n):\r\n aux.append((a[i]-b[i],i))\r\n # ordenamos la lista según diferencia de precio\r\n aux.sort()\r\n \r\n for diff, index in aux:\r\n # Por cada elemento que la diferencia sea menor que 0(se gana tomando el precio de a) \r\n # o si aún no se ha tomado los k de a pues se suma de a, sino se suma de b\r\n if diff < 0 or tomado_a < k:\r\n tomado_a += 1\r\n sum += a[index]\r\n else:\r\n sum+=b[index]\r\n \r\n return sum\r\n\r\n# recogemos la entrada\r\nn, k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\n\r\n#imprimimos la solución\r\nprint(Solucion(n,k,a,b)) ", "## 779C\r\n(n, k) = (int(_) for _ in input().split(' '))\r\na = [int(_) for _ in input().split(' ')]\r\nb = [int(_) for _ in input().split(' ')]\r\ntotal = 0\r\nnow = 0\r\nfor i in range(n):\r\n if a[i] <= b[i]:\r\n now += 1\r\n total += a[i]\r\n else:\r\n total += b[i]\r\nif now >= k:\r\n print(total)\r\nelse:\r\n diff = [b_i - a_i for a_i, b_i in zip(a, b)]\r\n # als diff > 0 dan strikt duurder, anders goedkoper dus beter om te wachten\r\n diff = [d for d in diff if d < 0]\r\n diff.sort(reverse = True)\r\n # koop de resterende producten dit het minste stijgen in prijs\r\n for j in range(k - now):\r\n total += -diff[j]\r\n print(total)", "n, k = [int(x) for x in input().split(' ')]\r\na = [int(x) for x in input().split(' ')]\r\nb = [int(x) for x in input().split(' ')]\r\n\r\np = [(x - y, x, y) for (x, y) in zip(a, b)]\r\n\r\np.sort()\r\nc = 0\r\nfor i in range(k):\r\n c += p[i][1]\r\n\r\nfor i in range(k, n):\r\n c += min(p[i][1:])\r\nprint(c)\r\n\r\n", "\r\n# Problem: C. Dishonest Sellers\r\n# Contest: Codeforces - Codeforces Round #402 (Div. 2)\r\n# URL: https://codeforces.com/contest/779/problem/C\r\n# Memory Limit: 256 MB\r\n# Time Limit: 2000 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,k = get_ints()\r\na= get_ints()\r\nb= get_ints()\r\nc = [(a[i]-b[i]) for i in range(n)]\r\n\r\nc1=c.copy()\r\nc,a= zip(*sorted(zip(c,a)))\r\nc1,b= zip(*sorted(zip( c1,b)))\r\n\r\nnum = 0\r\ns = 0\r\nfor i in range(n):\r\n\tif c[i] <0:\r\n\t\tnum+=1\r\n\t\ts+=a[i]\r\n\telse:\r\n\t\tif num < k:\r\n\t\t\tnum+=1\r\n\t\t\ts+=a[i]\r\n\t\telse:\r\n\t\t\tnum+=1\r\n\t\t\ts+=b[i]\r\nprint(s)", "def main():\r\n n,k = map(int, input().split())\r\n prices = list(map(int , input().split()))\r\n price_in_wk = list(map(int, input().split()))\r\n profits = [(prices[i] - price_in_wk[i],i) for i in range(len(prices))]\r\n profits.sort()\r\n cost = 0\r\n count = 0\r\n i = 0\r\n while i<len(profits):\r\n if profits[i][0]<0:\r\n count+=1\r\n cost+=prices[profits[i][1]]\r\n # print(prices[profits[i][1]])\r\n elif count>=k:\r\n break\r\n else:\r\n cost += prices[profits[i][1]]\r\n # print(prices[profits[i][1]])\r\n count+=1\r\n i+=1 \r\n for i in range(n-count):\r\n cost += price_in_wk[profits[count+i][1]]\r\n # print(price_in_wk[profits[count+i][1]])\r\n print(cost)\r\nmain() ", "def _input(): return map(int, input().split())\r\n\r\nn, k = _input()\r\na = list(_input())\r\nb = list(_input())\r\nlst = []\r\nfor i in range(n):\r\n lst.append((a[i]-b[i], ((a[i], b[i]))))\r\nlst.sort()\r\nres = 0\r\n#print(lst)\r\nfor i in range(k):\r\n res+=lst[i][1][0]\r\nfor i in range(k, n):\r\n res+=min(lst[i][1][0], lst[i][1][1])\r\nprint(res)", "import random\n\nn, k = map(int, input().split())\n\na = [int(k) for k in input().split()]\n\nb = [int(k) for k in input().split()]\n\n\nsale = [(a[i] - b[i], a[i], b[i]) for i in range(n)]\nsale.sort()\n\nprice = 0\nfor i in range(n):\n if(i<k or sale[i][0]<0):\n price += sale[i][1]\n else:\n price += sale[i][2]\n\nprint(price)\n \t \t \t\t \t \t\t \t\t\t\t\t\t \t\t \t\t\t\t", "def takeSecond(elem):\r\n return elem[2]\r\n\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\n\r\nx = []\r\nfor i in range(n):\r\n x += [(a[i], b[i], a[i]-b[i])]\r\nx = sorted(x, key = takeSecond)\r\ns = 0\r\nfor i in range(n):\r\n if(i<k):\r\n s += x[i][0]\r\n else:\r\n s += min(x[i][1], x[i][0])\r\nprint(s)", "n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nd=list(map(int,input().split()))\r\ndd=[]\r\ns=sum(l)\r\nfor i in range(n):\r\n x=d[i]-l[i]\r\n dd.append(x)\r\ndd.sort(reverse=True)\r\nfor i in range(k,n):\r\n if(dd[i]<0):\r\n s=s+dd[i]\r\nprint(s)\r\n", "n,k = map(int,input().split())\npn = list(map(int,input().split()))\npl = list(map(int,input().split()))\ndiff = [pn[i]-pl[i] for i in range(len(pn))]\ndiff = sorted(diff)\nt = sum(diff[:k])\nwhile k<len(diff) and diff[k] <0:\n t +=diff[k]\n k+=1\n \nprint(sum(pl)+t)\n", "n, k = [int(j) for j in input().split()]\r\na = [int(j) for j in input().split()]\r\nb = [int(j) for j in input().split()]\r\nc = [[0 for i in range(2)] for j in range(n)]\r\nfor i in range(n):\r\n c[i][0] = b[i] - a[i]\r\n c[i][1] = i\r\nc = sorted(c, key=lambda x:x[0])\r\n# print(c)\r\ns = 0\r\nfor i in range(n - 1, n - k - 1, -1):\r\n s += a[c[i][1]]\r\n # print(s)\r\nfor i in range(n - k - 1, -1, -1):\r\n if c[i][0] >= 0:\r\n s += a[c[i][1]]\r\n else:\r\n s += b[c[i][1]]\r\n # print(s)\r\nprint(s)\r\n", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nc = [(a[i] - b[i], b[i]) for i in range(n)]\r\nc.sort()\r\nans = 0\r\nfor i in range(k):\r\n ans += c[i][1] + c[i][0]\r\ni = k\r\nwhile i < n and c[i][0] < 0:\r\n ans += c[i][1] + c[i][0]\r\n i += 1\r\nwhile i < n:\r\n ans += c[i][1]\r\n i += 1\r\nprint(ans)\r\n", "n, k = map(int, input().split())\r\n\r\nmoney = 0\r\nbought = 0\r\nd = []\r\n\r\nc1 = list(map(int, input().split()))\r\nc2 = list(map(int, input().split()))\r\n\r\nfor i in range(n):\r\n loss = c1[i] - c2[i]\r\n if loss <= 0:\r\n money += c1[i]\r\n bought +=1\r\n else:\r\n d.append([loss, c1[i], c2[i]])\r\n\r\nd.sort()\r\nfor i in range(max(k-bought,0)):\r\n money += d[i][1]\r\nfor i in range(max(k-bought,0), len(d)):\r\n money += d[i][2]\r\n\r\nprint(money)\r\n", "a,b=map(int,input().split())\r\nz=[]\r\nfor i,j in zip(map(int,input().split()),map(int,input().split())):z+=[[i-j,i,j]]\r\nz.sort();s=0\r\nfor i in range(a):\r\n if b:s+=z[i][1];b-=1\r\n else:\r\n if z[i][0]<0:s+=z[i][1]\r\n else:s+=z[i][2]\r\nprint(s)", "def solve (n,toBuy,seq1,seq2) :\r\n zipped = list(zip(seq1,seq2))\r\n \r\n totalAfterPromo = sum(seq2)\r\n buyBeforePromo = 0\r\n items = 0\r\n \r\n afterSmall = []\r\n\r\n for before , after in zipped :\r\n if before <= after :\r\n items += 1\r\n buyBeforePromo += before\r\n totalAfterPromo -= after\r\n else :\r\n afterSmall.append([before - after,after])\r\n \r\n if items < toBuy :\r\n afterSmall.sort(key = lambda x : x[0])\r\n index = 0\r\n while index < toBuy - items :\r\n buyBeforePromo += (afterSmall[index][1] + afterSmall[index][0])\r\n totalAfterPromo -= afterSmall[index][1]\r\n index += 1\r\n \r\n \r\n return buyBeforePromo + totalAfterPromo\r\n\r\nn, toBuy = list(map(int,input().split()))\r\nseq1 = list(map(int,input().split()))\r\nseq2 = list(map(int,input().split()))\r\n\r\nprint (solve(n,toBuy,seq1,seq2)) \r\n\r\n ", "n, k = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\ndif = []\n\nfor i in range(n):\n dif.append((a[i]-b[i], i))\n\ndif.sort()\ns = 0\n\nfor i in range(k):\n s += a[dif[i][1]]\n a[dif[i][1]] = b[dif[i][1]] = 0\n\nfor i in range(len(a)):\n s += min(a[i], b[i])\n\nprint(s)\n", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nt = list()\r\nfor i in range(n):\r\n t.append([a[i] - b[i], i])\r\nt.sort()\r\nind = 0\r\nsumma = 0\r\nbo = True\r\nwhile (ind < n):\r\n if t[ind][0] > 0 and ind >= k:\r\n break\r\n summa += a[t[ind][1]]\r\n ind += 1\r\nfor i in range(ind, n):\r\n summa += b[t[i][1]]\r\nprint(summa)", "n,k=(map(int,input().split()))\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nans=sum(b)\r\nfor i in range(n): a[i]-=b[i]\r\na=sorted(a)\r\nfor i in range(n):\r\n if i<k or a[i]<0:\r\n ans += a[i]\r\n else: break\r\nprint(ans)", "import sys\r\n\r\nn,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\n\r\ndecrease = [[0]*2 for i in range(n)]\r\ntotal = 0\r\npos = -1\r\nfor i in range(n):\r\n if a[i] <= b[i]:\r\n total += a[i]\r\n k -= 1\r\n else:\r\n pos += 1\r\n decrease[pos][0] = i\r\n decrease[pos][1] = a[i] - b[i]\r\nif k > 0:\r\n decrease = sorted(decrease[:pos+1], key=lambda x: x[1])\r\ni = 0\r\nfor i in range(pos+1):\r\n if k > 0:\r\n total += a[decrease[i][0]]\r\n k -= 1\r\n else:\r\n total += b[decrease[i][0]]\r\nprint(total)\r\n", "n,k=[int(i) for i in input().split()]\r\n\r\na=[int(i) for i in input().split()]\r\nb=[int(i) for i in input().split()]\r\n\r\n\r\nres=[0 for i in range(n)]\r\nfor i in range(n):\r\n res[i]=a[i]-b[i]\r\n\r\nres,a,b=zip(*sorted(zip(res,a,b)))\r\n\r\nres,a,b=[list(t) for t in (zip(*sorted(zip(res,a,b))))]\r\n\r\nadd=0\r\nc=0\r\nfor i in range(n):\r\n if(res[i]>0):\r\n if(c>=k):\r\n add+=b[i]\r\n if(c<k):\r\n add+=a[i]\r\n c+=1\r\n elif(res[i]<=0):\r\n add+=a[i]\r\n c+=1\r\n\r\n\r\nprint(add)\r\n", "import sys\ninput = sys.stdin.readline\n\n############ ---- Input Functions ---- ############\n\n# integer inputs\ndef inp():\n return(int(input()))\n\n# list inputs \ndef inlt():\n return(list(map(int,input().split())))\n\n# string inputs (list of chars)\ndef insr():\n s = input()\n return(list(s[:len(s) - 1]))\n\n# space separated integer variable inputs\ndef invr():\n return(map(int,input().split()))\n\n###################################################\n\ndef main():\n n, k = invr()\n a = inlt()\n b = inlt()\n cost = 0\n\n diff = []\n for i in range(n):\n diff.append((b[i]-a[i], i))\n \n diff = sorted(diff, key=lambda x: x[0], reverse=True)\n\n c = 0\n for i in range(n):\n d, idx = diff[i]\n if c < k or d > 0:\n cost += a[idx]\n c += 1\n else:\n cost += b[idx]\n \n print(cost)\n return\n\nmain()", "def Solucion(n,k,a,b):\r\n res = 0\r\n dishonest = []\r\n for i in range(n):\r\n if b[i] - a[i] >= 0:\r\n k-=1\r\n res += a[i]\r\n else:\r\n res += b[i]\r\n dishonest.append(a[i] - b[i])\r\n \r\n if k > 0:\r\n dishonest.sort()\r\n for i in range(k):\r\n res+=dishonest[i]\r\n return res\r\n \r\nn, k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\n\r\nprint(Solucion(n,k,a,b))", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\ns = sum(a)\r\nans = s\r\nc = sorted([b[i]-a[i] for i in range(n)])\r\nk = n-k\r\nfor i in range(k):\r\n s += c[i]\r\n if ans > s:\r\n ans = s\r\nprint(ans)", "import math\r\nimport sys\r\nfrom collections import *\r\nfrom bisect import bisect_left, bisect_right\r\n \r\n \r\n \r\ndef cint() : return list(map(int, sys.stdin.readline().strip().split()))\r\ndef cstr() : return list(map(str, input().split(' '))) \r\n \r\n \r\ndef solve():\r\n n,k = cint()\r\n l1 = cint()\r\n l2 = cint()\r\n\r\n lst = []\r\n ans = 0\r\n for i in range(n):\r\n if l1[i] <= l2[i]:\r\n ans += l1[i]\r\n k-=1\r\n else:\r\n diff = l1[i] - l2[i]\r\n lst.append([diff, l2[i]])\r\n \r\n lst.sort()\r\n\r\n for item in lst:\r\n if k<=0:\r\n ans+= item[1]\r\n else:\r\n ans+= item[1] + item[0]\r\n k-=1\r\n\r\n print(ans) \r\n\r\n\r\n\r\n\r\n\r\n \r\nif __name__ == \"__main__\":\r\n # t = int(input())\r\n t = 1\r\n \r\n while t!=0:\r\n solve()\r\n t-=1", "s = input().split()\nn, k = map(int, s)\n# print(n, k)\n\na = input().split()\na = list(map(int, a))\n\nb = input().split()\nb = list(map(int, b))\n\ndiscounts = []\nfor i in range(n):\n info_pair = (b[i]-a[i], i)\n discounts.append(info_pair)\n# print(discounts)\n\nsorted_discounts = sorted(discounts, reverse=True)\n# print(sorted_discounts)\n\nidx_first_with_neg_discount = n\nfor idx in range(n):\n if sorted_discounts[idx][0] < 0:\n idx_first_with_neg_discount = idx\n break\n# print(idx_first_with_neg_discount)\n\nif idx_first_with_neg_discount >= k:\n idx_last_buy_select = idx_first_with_neg_discount - 1\nelse:\n idx_last_buy_select = k - 1\n# print(idx_last_buy_select)\n\nmoney_spent = 0\n\nfor idx in range(idx_last_buy_select+1):\n i = sorted_discounts[idx][1]\n money_spent += a[i]\n # print(idx, '->', a[i])\n\nfor idx in range(idx_last_buy_select+1, n):\n i = sorted_discounts[idx][1]\n money_spent += b[i]\n # print(idx, '->', b[i])\n\nprint(money_spent)", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nc=list(zip(a,b))\r\nc=sorted(c,key=lambda d:d[0]-d[1])\r\nsum=0\r\ni=0\r\nco=0\r\nwhile(i<len(a)):\r\n if(c[i][0]<=c[i][1]):\r\n sum+=c[i][0]\r\n co+=1\r\n elif(co>=k):\r\n sum+=c[i][1]\r\n co+=1\r\n else:\r\n sum+=c[i][0]\r\n co+=1\r\n i+=1\r\nprint(sum)", "n,m=map(int,input().split())\r\na=input().split()\r\nb=input().split()\r\nfor i in range(n):\r\n a[i]=int(a[i])\r\n b[i]=int(b[i])\r\n a[i]=[a[i]-b[i],a[i]]\r\na=sorted(a)\r\nf=0\r\nsuum=0\r\nfor i in range(n):\r\n if f<m or a[i][0]<0:\r\n suum+=a[i][1]\r\n else:\r\n break\r\n f+=1\r\nfor i in range(f,n):\r\n suum+=a[i][1]-a[i][0]\r\nprint(suum)\r\n \r\n", "int_inp = lambda: int(input()) #integer input\nstrng = lambda: input().strip() #string input\nstrl = lambda: list(input().strip())#list of strings as input\nmul = lambda: map(int,input().split())#multiple integers as inpnut\nmulf = lambda: map(float,input().split())#multiple floats as ipnut\nseq = lambda: list(map(int,input().split()))#list of integers\nimport math\nfrom collections import Counter,defaultdict\n\n\nn,m =mul()\na= seq()\nb =seq()\nk =0\np =[]\nfor i,j in zip(a,b):\n p.append([i-j,k])\n k+=1\np.sort()\nlast = -1\nk = 0\nfor i in p:\n if i[0]>0 and last<=0:\n break\n k+=1\nif k>m:\n m=k\nans =0\nfor i in range(m):\n ans += a[p[i][1]]\nfor i in range(m,n):\n ans += b[p[i][1]]\nprint(ans)\n", "n,k = map(int,input().split())\r\nnow = list(map(int,input().split()))\r\naftr = list(map(int,input().split()))\r\nans = sum(aftr)\r\nfor i in range(n):\r\n now[i] -= aftr[i]\r\nnow.sort()\r\nfor i in range(n):\r\n if i<k or now[i]<0:\r\n ans += now[i]\r\n else: break\r\nprint(ans)", "import sys\r\nn,k = map(int,sys.stdin.readline().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nc=[0 for i in range(len(a))]\r\ncount=sum(b)\r\nfor i in range(len(a)):\r\n c[i]=b[i]-a[i]\r\nc.sort()\r\nc.reverse()\r\nfor i in range(len(a)):\r\n if i < k:\r\n count=count-c[i]\r\n else:\r\n if c[i] > 0:\r\n count=count-c[i]\r\n else:\r\n break\r\nprint(count)", "#779C\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nc = []\r\nfor i in range(n):\r\n c.append(a[i]-b[i])\r\nls = zip(a,b,c)\r\nans = sorted(ls,key=lambda x: x[2])\r\nresult = 0\r\nfor i in ans:\r\n if i[2] < 0:\r\n result += i[0]\r\n k -= 1\r\n else:\r\n if k > 0:\r\n result += i[0] #0 for non negative ans\r\n k -= 1\r\n else:\r\n result += i[1]\r\nprint(result)\r\n\r\n", "n, k = map(int, input().split())\r\na = [int(x) for x in input().split()]\r\nb = [int(x) for x in input().split()]\r\nd = []\r\nfor i in range(n):\r\n d.append((a[i]-b[i], i, a[i], b[i]))\r\nd.sort()\r\ntotal = 0\r\nfor i in range(n):\r\n if k>0 or d[i][0]<=0:\r\n total += d[i][2]\r\n k -= 1\r\n else:\r\n total += d[i][3]\r\nprint(total)", "n, k = map(int, input().split())\r\nA = list(map(int, input().split()))\r\nB = list(map(int, input().split()))\r\nC = []\r\nfor i in range(n):\r\n C.append(( A[i] - B[i], A[i]))\r\nC.sort()\r\nans = 0\r\nfor i in range(n):\r\n if C[i][0] <= 0:\r\n ans += C[i][1]\r\n k -= 1\r\n else:\r\n if k > 0:\r\n ans += C[i][1]\r\n k -= 1\r\n else:\r\n ans += C[i][1] - C[i][0]\r\n \r\nprint(ans)\r\n ", "def ans(k,a1,a2):\n d=[0]*len(a1)\n for i in range(len(a1)):\n d[i]=(a1[i]-a2[i])\n d.sort()\n sum=0\n for i in (a1):\n sum=sum+i\n for i in range(len(d)):\n if(k!=0):\n k=k-1\n else:\n if(d[i]>0):\n sum=sum-d[i]\n return sum\n\n\nn,k=map(int,input().split(\" \"))\na1=list(map(int,input().split(\" \")))\na2=list(map(int,input().split(\" \")))\nprint(ans(k,a1,a2))\n\n\n\n\n\n\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, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nc = []\r\nd = []\r\ns = 0\r\nfor i in range(n):\r\n if a[i] < b[i]:\r\n s += a[i]\r\n else:\r\n c.append(b[i])\r\n d.append(a[i]-b[i])\r\ns += sum(c)\r\nx = n - len(c)\r\nif x < k:\r\n d.sort()\r\n s += sum(d[:k-x])\r\nprint(s)\r\n", "from heapq import *\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nq = []\r\nfor i in range(n):\r\n heappush(q, (a[i] - b[i], a[i], b[i]))\r\nans = 0\r\nwhile k > 0:\r\n ans += heappop(q)[1]\r\n k -= 1\r\nwhile len(q) > 0:\r\n temp = heappop(q)\r\n ans += min (temp[1], temp[2]) \r\nprint (ans)", "class solve:\r\n def __init__(self):\r\n n,k=map(int,input().split())\r\n a=list(map(int,input().split()))\r\n b=list(map(int,input().split()))\r\n data=[]\r\n for i in range(n):\r\n data.append([i,a[i]-b[i]])\r\n data.sort(key=lambda x:x[1])\r\n ans=0\r\n for i in range(n):\r\n if i<k:\r\n ans+=a[data[i][0]]\r\n else:\r\n ans+=min(a[data[i][0]],b[data[i][0]])\r\n print(ans)\r\n\r\nobj=solve()", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nd1 = 0\r\nd2 = []\r\nfor i in range(n):\r\n if a[i] <= b[i]:\r\n d1 += a[i]\r\n k -= 1\r\n else:\r\n d2.append((a[i] - b[i], i))\r\n\r\nd2 = sorted(d2)\r\nfor i in range(len(d2)):\r\n if k > 0:\r\n d1 += a[d2[i][1]]\r\n k -= 1\r\n else:\r\n d1 += b[d2[i][1]]\r\n\r\nprint(d1)\r\n\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\narr = [0] * n\r\nans = 0\r\nfor i in range(n):\r\n ans += b[i]\r\n arr[i] = b[i] - a[i]\r\narr.sort(reverse=True)\r\nsums = 0\r\nfor i in range(n):\r\n if arr[i] < 0 and i >= k:\r\n break\r\n sums += arr[i]\r\nprint(ans - sums)", "n, k = map(int, input().strip().split())\na = list(map(int, input().strip().split()))\nb = list(map(int, input().strip().split()))\narr = [(ai-bi, ai, bi) for ai, bi in zip(a, b)]\narr.sort()\ni = 0\ntotal = 0\nwhile i < n and (i < k or arr[i][0] < 0):\n\ttotal += arr[i][1]\n\ti += 1\nfor j in range(i, n):\n\ttotal += arr[j][2]\nprint(total)", "def min_price_sum(n, k, arr_a, arr_b, sorted_arr_diff):\n bought = 0\n final_sum = 0\n for i in range(n):\n if sorted_arr_diff[i][0] <= 0 or bought < k: #если товар выгодный или мы обязаны купить ещё\n final_sum += arr_a[sorted_arr_diff[i][1]] #значит мы его покупаем и прибавляем цену к итоговой\n bought += 1\n else: #если товар невыгодный и при этом мы купили достаточно\n break #то больше мы ничего не покупаем (дальше в массиве все товары будут невыгодные)\n\n for j in range(bought, n): #если в период скидок мы не выкупили все товары, то покупаем после скидок\n final_sum += arr_b[sorted_arr_diff[j][1]]\n return final_sum\n\ns = input().split(' ')\nn, k = int(s[0]), int(s[1])\n\ndef input_arr():\n arr = []\n for c in input().split(' '):\n arr.append(int(c))\n return arr\n\narr_a, arr_b = input_arr(), input_arr()\n\narr_diff = [ ()*i for i in range(n) ]\nfor i in range(n):\n arr_diff[i] = (arr_a[i]-arr_b[i], i)\n\nsorted_arr_diff = sorted(arr_diff)\nprint(min_price_sum(n, k, arr_a, arr_b, sorted_arr_diff))\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\nA = list(map(int,input().split()))\r\nB = list(map(int,input().split()))\r\nV = []\r\nfor i in range(n):\r\n V.append([A[i] - B[i],i])\r\nV.sort()\r\ns = 0\r\nfor i in range(n):\r\n if i + 1 <= k or V[i][0] < 0:\r\n s += A[V[i][1]]\r\n else:\r\n s += B[V[i][1]]\r\nprint(s)", "def get_ints():\r\n return map(int, input().strip().split())\r\n\r\ndef get_list():\r\n return list(map(int, input().strip().split()))\r\n\r\ndef get_string():\r\n return input().strip()\r\n\r\n# For fast IO use sys.stdout.write(str(x) + \"\\n\") instead of print\r\nimport sys\r\ninput = sys.stdin.readline\r\nimport math\r\n\r\n\r\nfor t in range(1):\r\n n, k = get_ints()\r\n arr_a = get_list()\r\n arr_b = get_list()\r\n diffs = []\r\n cost = 0\r\n \r\n for i in range(n):\r\n diffs.append([i, arr_a[i] - arr_b[i]])\r\n \r\n diffs.sort(key=lambda x: x[1])\r\n \r\n for i in range(n):\r\n if i < k or diffs[i][1] <= 0:\r\n cost += arr_a[diffs[i][0]]\r\n else:\r\n cost += arr_b[diffs[i][0]]\r\n \r\n # print(diffs)\r\n print(cost)", "# Python code to sort the tuples using second element \r\n# of sublist Function to sort using sorted() \r\ndef Sort(sub_li): \r\n\r\n\t# reverse = None (Sorts in Ascending order) \r\n\t# key is set to sort using second element of \r\n\t# sublist lambda has been used \r\n\treturn(sorted(sub_li, key = lambda x: x[1]))\t \r\n\r\n\r\n\r\n\r\no=input().rstrip().split(' ')\r\np=input().rstrip().split(' ')\r\nr=input().rstrip().split(' ')\r\nl=[]\r\nq=[]\r\nw=[]\r\nS=[]\r\nD=[]\r\nfor i in range(0,len(p)):\r\n D=[]\r\n D.append(int(p[i]))\r\n D.append(int(r[i]) - int(p[i]))\r\n D.append(int(r[i]))\r\n l.append(D)\r\nX=Sort(l)\r\nX.reverse()\r\nk=int(o[1])\r\nF=0;\r\nV=-1;\r\nfor i in range(0,len(X)):\r\n if X[i][1]>=0:\r\n F+=X[i][0]\r\n k-=1;\r\n else:\r\n if k<=0:\r\n V=i;\r\n break;\r\n else:\r\n k-=1;\r\n F+=X[i][0]\r\nif V==-1:\r\n print(F)\r\nelse:\r\n for i in range(V,len(X)):\r\n F+=X[i][2]\r\n print(F)", "N, K = input().strip().split()\r\nN, K = int(N), int(K) #wants to buy at least k now(with discounts), wants to buy n in total\r\ndiscounts = input().strip().split()\r\nnormal = input().strip().split()\r\nitems = []\r\nfor i in range(N):\r\n a = int(discounts[i])\r\n b = int(normal[i])\r\n items.append([a, b, min(a, b), a-b])\r\nmoney = 0\r\nitems = sorted(items, key=lambda k: k[3], reverse=True)\r\n#print(\"discount\")\r\nfor i in range(K):\r\n item = items.pop()\r\n #print(\"buy for \" + str(item[0]))\r\n money += item[0]\r\nitems = sorted(items, key= lambda k: k[2], reverse=True)\r\n#print(items)\r\n\r\nfor i in range(N-K):\r\n item = items.pop()\r\n #print(\"buy for \" + str(item[2]))\r\n money += item[2]\r\nprint(money)", "n, k = map(int, input().split())\nx1 = list(map(int, input().split()))\nx2 = list(map(int, input().split()))\na = n * [0]\nfor i in range(n):\n a[i] = [x1[i], x2[i]]\na.sort(key=lambda a: a[0] - a[1])\nans = 0\nfor j in range(n):\n if k > 0 and a[j][0] - a[j][1] >= 0:\n ans += max(a[j])\n else:\n ans += min(a[j])\n k -= 1\nprint(ans)\n", "def key_my(idx):\r\n return -(idx[0])\r\n\r\n\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nans_win = []\r\nans_l = []\r\nfor i in range(n):\r\n if b[i] < a[i]:\r\n ans_l.append([b[i] - a[i], i])\r\n else:\r\n ans_win.append([b[i] - a[i], i])\r\ncur = 0\r\nuse = [0] * n \r\nif k <= len(ans_win):\r\n for i in range(len(ans_win)):\r\n cur += a[ans_win[i][1]]\r\n use[ans_win[i][1]] = 1\r\n for i in range(n):\r\n if not use[i]:\r\n cur += b[i]\r\n print(cur) \r\nelse:\r\n ans_win.sort(key=key_my) \r\n ans_l.sort(key=key_my)\r\n for i in range(len(ans_win)):\r\n cur += a[ans_win[i][1]]\r\n use[ans_win[i][1]] = 1\r\n for i in range(k - len(ans_win)):\r\n cur += a[ans_l[i][1]]\r\n use[ans_l[i][1]] = 1\r\n for i in range(n):\r\n if not use[i]:\r\n cur += b[i]\r\n print(cur)", "n, k = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nd = list(map(lambda i: (i, b[i] - a[i]), range(n)))\r\narr = sorted(d, key=lambda x: x[1], reverse=True)\r\ns = 0\r\nfor index, value in enumerate(arr):\r\n if index < k:\r\n s += a[value[0]]\r\n else:\r\n if value[1] < 0:\r\n s += b[value[0]]\r\n else:\r\n s += a[value[0]]\r\nprint(s)\r\n", "n, k = list(map(int, input().split()))\nl1 = list(map(int, input().split()))\nl2 = list(map(int, input().split()))\nl3 = [(l1[i], l2[i]) for i in range(n)]\nl3.sort(key=lambda x:x[0]-x[1])\nans = 0\nfor i in range(k):\n ans += l3[i][0]\nfor i in range(k, n):\n if (l3[i][0] > l3[i][1]):\n ans += l3[i][1]\n else:\n ans += l3[i][0]\nprint(ans)\n \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=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\narr=[]\r\nfor i in range(n):\r\n\tarr.append([a[i],b[i],b[i]-a[i]])\r\narr=sorted(arr,key=lambda item:item[2],reverse=True)\r\nans=0\r\nfor i in range(k):\r\n\tans+=arr[i][0]\r\ni=k\r\nwhile i<n:\r\n\tif arr[i][2]>0:\r\n\t\tans+=arr[i][0]\r\n\telse:\r\n\t\tbreak\r\n\ti+=1\r\nfor j in range(i,n):\r\n\tans+=arr[j][1]\r\nprint(ans)", "n, k = map(int, input().split())\r\n\r\nb = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\n\r\nx = []\r\nfor i in range(n):\r\n x += [[b[i]-a[i], i]]\r\n\r\nx.sort()\r\nused = set()\r\ntotal = 0\r\nfor i in range(k): \r\n \r\n total += b[x[i][1]]\r\n used.add(x[i][1])\r\nfor i in range(n):\r\n if i not in used:\r\n total += min(a[i], b[i])\r\n\r\nprint(total)\r\n", "\nimport sys\n\n\ndef merge(l_mass: list, r_mass: list):\n n = len(l_mass)\n mass = []\n j = 0\n for i in range(n):\n while j < len(r_mass) and (r_mass[j][0] - r_mass[j][1]) < (l_mass[i][0] - l_mass[i][1]):\n mass.append(r_mass[j]) \n j += 1\n mass.append(l_mass[i])\n mass += r_mass[j:]\n return mass\n\n\ndef merge_sort(mass):\n n = len(mass)\n if n <= 1:\n return mass\n m = n//2\n l_mass = merge_sort(mass[:m])\n r_mass = merge_sort(mass[m:])\n return merge(l_mass = l_mass, r_mass = r_mass)\n\n\n\nif __name__ == '__main__':\n n, k = [int(i) for i in sys.stdin.readline().strip().split(' ')]\n f_price = sys.stdin.readline().strip().split(' ')\n s_price = sys.stdin.readline().strip().split(' ')\n\n price = [[int(f_price[i]), int(s_price[i])] for i in range(n)]\n new_price = merge_sort(mass = price)\n answer = 0\n for val in new_price:\n if k > 0 or (val[0] - val[1]) < 0:\n answer += val[0]\n k -= 1\n else:\n answer += val[1]\n print(answer)\n\n\t \t \t \t\t\t \t \t \t\t \t \t\t \t \t\t\t", "\r\n\r\n\r\n\r\n\r\nn,k = map(int,input().split())\r\nold = list(map(int,input().split()))\r\nnew = list(map(int,input().split()))\r\ndiff = []\r\nfor i in range(n):\r\n diff.append([old[i]-new[i] , old[i], new[i], i])\r\n \r\ndiff.sort()\r\nc = 0\r\nvisited = [0]*(n)\r\n\r\nfor i in range(k):\r\n c += diff[i][1]\r\n visited[diff[i][3]]=1 \r\n \r\n \r\nfor i in range(n):\r\n if visited[i]==0:\r\n c += min(old[i],new[i])\r\nprint(c)\r\n", "inp = lambda: int(input())\r\nmi = lambda: map(int, input().split())\r\nli = lambda: list(mi())\r\nbi = lambda n: bin(n).replace(\"0b\", \"\")\r\n\r\ndef haha(p,q,n,k):\r\n l=[]\r\n c=0\r\n for i in range(n):\r\n l.append([p[i],q[i]])\r\n l.sort(key=lambda x:x[0]-x[1])\r\n for i in range(n):\r\n if i<k:\r\n c+=l[i][0]\r\n else:\r\n c+=min(l[i][1],l[i][0])\r\n return c\r\n \r\n\r\n\r\na,b=mi()\r\nm=li()\r\nn=li()\r\nx=haha(m,n,a,b)\r\nprint(x)", "[n, k] = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nc = []\r\nfor i in range(n):\r\n c.append((a[i]-b[i], a[i], b[i]))\r\nc.sort()\r\nans = 0\r\n# print(c)\r\nfor i in range(k):\r\n ans += c[i][1]\r\nfor j in range(k, n):\r\n if c[j][0] < 0:\r\n ans += c[j][1]\r\n else:\r\n ans += c[j][2]\r\nprint(ans)" ]
{"inputs": ["3 1\n5 4 6\n3 1 5", "5 3\n3 4 7 10 3\n4 5 5 12 5", "1 0\n9\n8", "2 0\n4 10\n1 2", "4 2\n19 5 17 13\n3 18 8 10", "5 3\n28 17 20 45 45\n39 12 41 27 9", "10 5\n87 96 19 81 10 88 7 49 36 21\n11 75 28 28 74 17 64 19 81 31", "50 45\n80 125 152 122 85 62 123 195 157 73 8 127 47 193 70 132 131 38 98 97 185 98 68 166 114 53 144 106 141 106 191 123 44 199 35 18 84 169 46 52 129 102 155 130 63 169 116 145 154 41\n155 187 79 106 136 173 17 146 9 47 173 21 37 183 110 74 185 14 82 156 147 25 162 195 26 25 22 80 171 180 7 92 53 18 100 17 159 184 37 127 116 192 163 49 94 95 118 102 8 30", "5 2\n1 1 1 1 1\n2 2 2 2 2", "5 2\n2 4 4 4 4\n3 1 1 1 1", "6 3\n9 9 9 2 2 2\n6 6 6 1 1 1", "5 3\n10 17 23 26 35\n7 18 18 29 32", "2 1\n10 12\n5 6"], "outputs": ["10", "25", "8", "3", "29", "101", "243", "4680", "5", "9", "24", "103", "16"]}
UNKNOWN
PYTHON3
CODEFORCES
213
19069faac761fefd3f5fae43dd32fd49
Tourist
Tourist walks along the *X* axis. He can choose either of two directions and any speed not exceeding *V*. He can also stand without moving anywhere. He knows from newspapers that at time *t*1 in the point with coordinate *x*1 an interesting event will occur, at time *t*2 in the point with coordinate *x*2 — another one, and so on up to (*x**n*,<=*t**n*). Interesting events are short so we can assume they are immediate. Event *i* counts visited if at time *t**i* tourist was at point with coordinate *x**i*. Write program tourist that will find maximum number of events tourist if: - at the beginning (when time is equal to 0) tourist appears at point 0, - tourist can choose initial point for himself. Yes, you should answer on two similar but different questions. The first line of input contains single integer number *N* (1<=≤<=*N*<=≤<=100000) — number of interesting events. The following *N* lines contain two integers *x**i* and *t**i* — coordinate and time of the *i*-th event. The last line of the input contains integer *V* — maximum speed of the tourist. All *x**i* will be within range <=-<=2·108<=≤<=*x**i*<=≤<=2·108, all *t**i* will be between 1 and 2·106 inclusive. *V* will be positive and will not exceed 1000. The input may contain events that happen at the same time or in the same place but not in the same place at the same time. The only line of the output should contain two space-sepatated integers — maximum number of events tourist can visit in he starts moving from point 0 at time 0, and maximum number of events tourist can visit if he chooses the initial point for himself. Sample Input 3 -1 1 42 7 40 8 2 Sample Output 1 2
[ "from sys import stdin\ninput = stdin.buffer.readline\nfrom bisect import bisect\nfrom itertools import zip_longest\n\ndef main():\n n = int(input())\n events = [tuple(map(int,input().split())) for _ in range(n)]\n v = int(input())\n tot, zero = [], []\n for i, e in enumerate(events):\n pos, time = e\n zero.append(abs(pos) <= v * time)\n tot.append((v * time + pos, v * time - pos))\n order = sorted(range(n), key=lambda i:tot[i])\n lis1, lis2 = [], []\n for i in order:\n x, y = tot[i]\n if zero[i]:\n i = bisect(lis1, y)\n if i == len(lis1):\n lis1.append(y)\n else:\n lis1[i] = y\n i = bisect(lis2, y)\n if i == len(lis2):\n lis2.append(y)\n else:\n lis2[i] = y\n print(len(lis1), len(lis2))\n\nmain()" ]
{"inputs": ["3\n-1 1\n42 7\n40 8\n2", "5\n1 5\n6 7\n17127 17\n17072 42\n17042 77\n3", "7\n-976754 20479\n79929143 911181\n9598220 82517\n-51609349 810257\n67416551 266544\n-14170975 307690\n-15476178 491195\n352", "12\n-6712 6\n2375 73\n4643 197\n-5660 215\n-378 223\n2228 307\n3305 340\n3449 468\n-4389 707\n-7161 729\n-1838 921\n-1655 985\n730", "22\n-5301 602\n-1400 194\n-8512 987\n-282 962\n6484 494\n9091 523\n-7744 92\n6002 461\n5053 305\n-1339 272\n-821 165\n9308 785\n929 421\n8384 883\n1266 157\n8411 923\n-2949 885\n7725 687\n6859 197\n-7630 867\n5031 918\n5662 410\n41"], "outputs": ["1 2", "2 3", "5 5", "11 12", "9 9"]}
UNKNOWN
PYTHON3
CODEFORCES
1
190cc916df6e471a15c1895a240a728e
A Simple Task
Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges. The first line of input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=19, 0<=≤<=*m*) – respectively the number of vertices and edges of the graph. Each of the subsequent *m* lines contains two integers *a* and *b*, (1<=≤<=*a*,<=*b*<=≤<=*n*, *a*<=≠<=*b*) indicating that vertices *a* and *b* are connected by an undirected edge. There is no more than one edge connecting any pair of vertices. Output the number of cycles in the given graph. Sample Input 4 6 1 2 1 3 1 4 2 3 2 4 3 4 Sample Output 7
[ "N, M = [int(w) for w in input().split()]\ngraph = [[] for _ in range(N)]\ndp = [[0] * (2 ** N) for _ in range(N)]\n\nself_circles = 0\n\nfor _ in range(M):\n a, b = [int(w) - 1 for w in input().split()]\n if a == b:\n self_circles += 1\n else:\n graph[a].append(b)\n graph[b].append(a)\n\nconvert = {}\nfor i in range(N):\n dp[i][1 << i] = 1\n convert[1 << i] = i\n\nresult = -M\nfor i in range(1, 2 ** N):\n limit = convert[i&(-i)]\n for j in range(N):\n if dp[j][i] == 0:\n continue\n for k in graph[j]:\n if k < limit:\n continue\n nmask_k = i | (1 << k)\n if nmask_k == i:\n if k == limit:\n result += dp[j][i]\n else:\n dp[k][nmask_k] += dp[j][i]\n \nprint(result//2)" ]
{"inputs": ["4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "10 3\n4 8\n9 4\n8 9", "8 28\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n4 8\n5 6\n5 7\n5 8\n6 7\n6 8\n7 8", "12 10\n1 6\n4 5\n4 9\n5 10\n6 12\n7 9\n7 10\n8 10\n10 12\n11 12", "3 0", "6 0", "2 1\n1 2", "2 1\n1 2", "3 3\n1 2\n1 3\n2 3", "3 0", "3 0", "3 0", "7 16\n1 2\n1 3\n1 5\n1 7\n2 3\n2 4\n2 6\n3 4\n3 5\n3 6\n3 7\n4 5\n4 6\n4 7\n5 6\n6 7", "14 32\n1 2\n1 3\n1 6\n1 7\n1 9\n1 11\n1 13\n2 8\n2 9\n2 14\n3 7\n3 8\n3 9\n3 13\n4 5\n4 11\n4 14\n6 7\n6 8\n6 9\n6 14\n7 12\n7 13\n8 9\n8 10\n8 11\n9 10\n10 13\n10 14\n11 12\n11 13\n13 14", "18 45\n1 2\n1 5\n1 12\n1 13\n2 3\n2 4\n2 11\n2 14\n2 15\n3 7\n3 16\n4 7\n4 8\n4 10\n4 18\n5 8\n5 10\n5 16\n5 17\n6 12\n6 16\n7 9\n7 12\n8 10\n8 16\n9 11\n9 12\n9 16\n9 17\n10 11\n10 15\n11 12\n11 14\n11 15\n12 13\n12 14\n12 15\n12 18\n13 15\n13 16\n13 17\n14 15\n14 18\n16 17\n17 18", "19 11\n3 4\n3 12\n3 14\n4 12\n5 11\n8 9\n8 10\n9 10\n9 13\n11 19\n15 16", "1 0", "10 44\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 4\n3 5\n3 6\n3 7\n3 8\n3 10\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 6\n5 7\n5 8\n5 9\n5 10\n6 7\n6 8\n6 9\n6 10\n7 8\n7 9\n7 10\n8 9\n8 10\n9 10", "16 11\n1 2\n2 7\n2 12\n3 12\n4 5\n4 15\n6 7\n6 9\n7 8\n12 14\n14 16", "1 0", "3 3\n1 2\n1 3\n2 3", "6 1\n2 5", "2 1\n1 2", "3 3\n1 2\n1 3\n2 3", "2 0", "1 0", "18 54\n1 7\n1 11\n1 14\n1 15\n1 18\n2 7\n3 4\n3 9\n3 10\n3 11\n3 12\n3 13\n3 16\n3 17\n3 18\n4 5\n4 9\n4 11\n4 13\n5 12\n5 13\n5 14\n5 15\n5 16\n5 18\n6 9\n6 10\n6 12\n6 13\n6 17\n7 8\n7 17\n8 10\n8 11\n8 12\n8 14\n8 15\n9 11\n9 12\n10 11\n10 13\n10 16\n10 17\n11 12\n11 15\n11 16\n12 15\n12 18\n13 15\n13 17\n14 15\n14 16\n15 17\n17 18", "3 0", "5 8\n1 3\n1 4\n1 5\n2 3\n2 4\n3 4\n3 5\n4 5", "19 48\n1 5\n1 6\n1 14\n1 17\n1 18\n2 3\n2 4\n2 7\n2 13\n2 16\n2 18\n2 19\n3 8\n3 11\n3 16\n3 17\n4 5\n4 13\n4 17\n4 19\n5 8\n5 13\n5 15\n5 16\n5 19\n6 7\n6 11\n6 12\n6 14\n7 8\n7 11\n8 11\n8 19\n9 14\n9 17\n9 18\n10 13\n10 19\n11 12\n11 18\n12 14\n13 16\n13 17\n13 19\n14 15\n16 17\n17 18\n18 19", "2 0", "6 15\n1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6\n5 6", "19 22\n1 10\n1 14\n1 17\n2 10\n2 12\n2 13\n3 8\n3 13\n3 14\n4 10\n4 19\n7 9\n7 12\n9 18\n10 11\n11 13\n11 19\n12 13\n14 16\n16 17\n16 19\n17 19", "1 0", "3 0"], "outputs": ["7", "1", "8018", "1", "0", "0", "0", "0", "1", "0", "0", "0", "214", "9239", "467111", "2", "0", "446414", "0", "0", "1", "0", "0", "1", "0", "0", "6418594", "0", "12", "824798", "0", "197", "60", "0", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
1
1920af96049061e297fe0a7e0d5bea73
Driving Test
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. - speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); - overtake is allowed: this sign means that after some car meets it, it can overtake any other car; - no speed limit: this sign cancels speed limit if any (car can move with arbitrary speed after this sign); - no overtake allowed: some car can't overtake any other car after this sign. Polycarp goes past the signs consequentially, each new sign cancels the action of all the previous signs of it's kind (speed limit/overtake). It is possible that two or more "no overtake allowed" signs go one after another with zero "overtake is allowed" signs between them. It works with "no speed limit" and "overtake is allowed" signs as well. In the beginning of the ride overtake is allowed and there is no speed limit. You are given the sequence of events in chronological order — events which happened to Polycarp during the ride. There are events of following types: 1. Polycarp changes the speed of his car to specified (this event comes with a positive integer number); 1. Polycarp's car overtakes the other car; 1. Polycarp's car goes past the "speed limit" sign (this sign comes with a positive integer); 1. Polycarp's car goes past the "overtake is allowed" sign; 1. Polycarp's car goes past the "no speed limit"; 1. Polycarp's car goes past the "no overtake allowed"; It is guaranteed that the first event in chronological order is the event of type 1 (Polycarp changed the speed of his car to specified). After the exam Polycarp can justify his rule violations by telling the driving instructor that he just didn't notice some of the signs. What is the minimal number of signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view? The first line contains one integer number *n* (1<=≤<=*n*<=≤<=2·105) — number of events. Each of the next *n* lines starts with integer *t* (1<=≤<=*t*<=≤<=6) — the type of the event. An integer *s* (1<=≤<=*s*<=≤<=300) follows in the query of the first and the third type (if it is the query of first type, then it's new speed of Polycarp's car, if it is the query of third type, then it's new speed limit). It is guaranteed that the first event in chronological order is the event of type 1 (Polycarp changed the speed of his car to specified). Print the minimal number of road signs Polycarp should say he didn't notice, so that he would make no rule violations from his point of view. Sample Input 11 1 100 3 70 4 2 3 120 5 3 120 6 1 150 4 3 300 5 1 100 3 200 2 4 5 7 1 20 2 6 4 6 6 2 Sample Output 2 0 2
[ "n = int(input())\n\nspeed_limits = []\nobgon = 0\n\ncurrent_speed = 0\n\ncount = 0\n\nfor i in range(n):\n event = list(input().split())\n if (len(event) == 2):\n type, x = map(int, event)\n if type == 1: # 1 изменил скорость на х\n current_speed = x\n while len(speed_limits) != 0 and speed_limits[-1] < current_speed:\n count += 1\n speed_limits.pop()\n elif type == 3: # 3 новый знак ограничение скорости х\n speed_limits.append(x)\n if speed_limits[-1] < current_speed:\n count += 1\n speed_limits.pop()\n else:\n type = int(event[0])\n if type == 2: # 2 совершил обгон\n if obgon == 0:\n continue\n else:\n count += obgon\n obgon = 0\n elif type == 4: # 4 новый знак обгон разрешен\n obgon = 0\n elif type == 5: # 5 новый знак отмена ограничения скорости\n speed_limits.clear()\n elif type == 6: # 6 новый знак обгон запрещен\n obgon += 1\n\nprint(count)\n\n", "speeds = [1000000]\r\novertakes = [True]\r\ncount = 0\r\nspeed = 0\r\nn = int(input())\r\nfor e in range(n):\r\n inp = list(map(int, input().split()))\r\n # print(inp)\r\n if inp[0] == 4:\r\n overtakes.append(True)\r\n elif inp[0] == 6:\r\n overtakes.append(False)\r\n elif inp[0] == 5:\r\n speeds.append(1000000)\r\n elif inp[0] == 3:\r\n speeds.append(inp[1])\r\n while speed > speeds[-1]:\r\n count += 1\r\n speeds.pop()\r\n \r\n elif inp[0] == 2:\r\n while not overtakes[-1]:\r\n count += 1\r\n overtakes.pop()\r\n else:\r\n while inp[1] > speeds[-1]:\r\n count += 1\r\n speeds.pop()\r\n speed = inp[1]\r\n \r\nprint(count)\r\n\"\"\"\r\nPolycarp changes the speed of his car to specified (this event comes with a positive integer number);\r\nPolycarp's car overtakes the other car;\r\nPolycarp's car goes past the \"speed limit\" sign (this sign comes with a positive integer);\r\nPolycarp's car goes past the \"overtake is allowed\" sign;\r\nPolycarp's car goes past the \"no speed limit\";\r\nPolycarp's car goes past the \"no overtake allowed\";\r\n\"\"\"", "n = int(input())\n\nevents = []\nfor i in range(n):\n events.append(list(map(lambda s: int(s), input().split())))\n\nmax_speeds = []\novertaking_forbidden = 0\n\ncurrent_speed = 0\n\nignores = 0\n\nfor event in events:\n if event[0] == 1:\n current_speed = event[1]\n\n while max_speeds and current_speed > max_speeds[-1]:\n max_speeds.pop()\n ignores += 1\n\n elif event[0] == 2:\n ignores += overtaking_forbidden\n overtaking_forbidden = 0\n\n elif event[0] == 3:\n if current_speed > event[1]:\n ignores += 1\n else:\n max_speeds.append(event[1])\n\n elif event[0] == 4:\n overtaking_forbidden = 0\n elif event[0] == 5:\n max_speeds = []\n elif event[0] == 6:\n overtaking_forbidden += 1\n\nprint(ignores)\n\n", "n = int(input())\r\nr = 0\r\ncnt = 0\r\nsp = int(input()[2:])\r\nlims = [301]\r\nfor ind in range(n-1):\r\n s = input()\r\n if s[0] == \"1\":\r\n sp = int(s[2:])\r\n while lims[-1] < sp:\r\n cnt += 1\r\n lims.pop()\r\n elif s[0] == \"2\":\r\n cnt += r\r\n r = 0\r\n elif s[0] == \"3\":\r\n newlim = int(s[2:])\r\n if sp > newlim:\r\n cnt += 1\r\n else:\r\n lims.append(newlim)\r\n elif s[0] == \"4\":\r\n r = 0\r\n elif s[0] == \"5\":\r\n lims = [301]\r\n elif s[0] == \"6\":\r\n r += 1\r\nprint(cnt)", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nnow = 0\r\nng = 0\r\nans = 0\r\nx = []\r\nfor _ in range(n):\r\n t = list(map(int, input().split()))\r\n if t[0] == 1:\r\n now = t[1]\r\n while x and x[-1] < now:\r\n ans += 1\r\n x.pop()\r\n elif t[0] == 2:\r\n ans += ng\r\n ng = 0\r\n elif t[0] == 3:\r\n x.append(t[1])\r\n while x and x[-1] < now:\r\n ans += 1\r\n x.pop()\r\n elif t[0] == 4:\r\n ng = 0\r\n elif t[0] == 5:\r\n x = []\r\n else:\r\n ng += 1\r\nprint(ans)", "for _ in range(1):\r\n n=int(input())\r\n #n,m=map(int,input().split())\r\n ans=0\r\n currs=0\r\n slm=[]\r\n over=0\r\n for i in range(n):\r\n b=list(map(int,input().split()))\r\n if(b[0]==1):\r\n currs=b[1]\r\n \r\n if(b[0]==2):\r\n ans+=over\r\n over=0\r\n if(b[0]==3):\r\n slm.append(b[1])\r\n \r\n \r\n \r\n if(b[0]==4):\r\n over=0\r\n if(b[0]==5):\r\n slm=[]\r\n if(b[0]==6):\r\n over+=1\r\n \r\n while(slm!=[] and slm[-1]<currs):\r\n ans+=1\r\n slm.pop()\r\n \r\n print(ans)", "import sys\r\n\r\nn = int(sys.stdin.buffer.readline().decode('utf-8'))\r\ninf = 10**9\r\n\r\nspeed = 0\r\nlimit = [inf]\r\novertake = 1\r\not_sign = 0\r\nans = 0\r\n\r\nfor _ in range(n):\r\n q = list(map(int, sys.stdin.buffer.readline().decode('utf-8').split()))\r\n if q[0] == 1:\r\n while limit[-1] < q[1]:\r\n ans += 1\r\n limit.pop()\r\n speed = q[1]\r\n elif q[0] == 2:\r\n if not overtake:\r\n ans += ot_sign\r\n ot_sign = 0\r\n elif q[0] == 3:\r\n if speed > q[1]:\r\n ans += 1\r\n else:\r\n limit.append(q[1])\r\n elif q[0] == 4:\r\n overtake = 1\r\n ot_sign = 0\r\n elif q[0] == 5:\r\n limit.clear()\r\n limit.append(inf)\r\n else:\r\n overtake = 0\r\n ot_sign += 1\r\n\r\nprint(ans)\r\n", "MAX_SPEED = 300\nn = int(input())\nactions = [list(map(int, input().split())) for _ in range(n)]\nspeed = [0 for i in range(n)]\n\nfor i in range(n):\n if actions[i][0] == 1:\n lastSpeed = actions[i][1]\n speed[i] = lastSpeed \n\nignored = 0\novertook = False\nmaxSpeed = -1\nfor i in range(n-1,-1,-1):\n maxSpeed = max(maxSpeed, speed[i])\n if actions[i][0] == 1:\n pass\n elif actions[i][0] == 2:\n overtook = True\n elif actions[i][0] == 3:\n if maxSpeed > actions[i][1]:\n ignored += 1\n else:\n maxSpeed = speed[i-1]\n elif actions[i][0] == 4:\n overtook = False\n elif actions[i][0] == 5:\n maxSpeed = speed[i-1]\n elif actions[i][0] == 6:\n if overtook:\n ignored += 1\n \nprint(ignored)\n", "n = int(input())\r\nv = int(input()[2:])\r\np = [1e9]\r\nd = k = 0\r\nfor i in range(n - 1):\r\n s = input()\r\n t = int(s[0])\r\n if t == 1:\r\n v = int(s[2:])\r\n while p[-1] < v:\r\n p.pop()\r\n k += 1\r\n if t == 2:\r\n k += d\r\n d = 0\r\n if t == 3:\r\n u = int(s[2:])\r\n if v > u: k += 1\r\n else: p.append(u)\r\n if t == 4: d = 0\r\n if t == 5: p = [1e9]\r\n if t == 6: d += 1\r\nprint(k)", "import sys\r\nimport io, os\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\novertake = True\r\nnotallowed = 0\r\nstack = []\r\ncur = -1\r\nans = 0\r\nfor i in range(n):\r\n temp = list(map(int, input().split()))\r\n if temp[0] == 1:\r\n s = temp[1]\r\n while stack and stack[-1] < s:\r\n stack.pop()\r\n ans += 1\r\n cur = s\r\n elif temp[0] == 2:\r\n if not overtake:\r\n ans += notallowed\r\n notallowed = 0\r\n elif temp[0] == 3:\r\n s = temp[1]\r\n if cur > s:\r\n ans += 1\r\n else:\r\n stack.append(s)\r\n elif temp[0] == 4:\r\n overtake = True\r\n notallowed = 0\r\n elif temp[0] == 5:\r\n stack = []\r\n elif temp[0] == 6:\r\n overtake = False\r\n notallowed += 1\r\nprint(ans)\r\n", "\r\nclass DrivingTest:\r\n car_speed = 0\r\n speed_limit = [0] # no speed limit\r\n overtake_allowed = [True]\r\n missed_signs = 0\r\n \r\n def __init__(self, test=False):\r\n if not test:\r\n event_count = int(input())\r\n for counter in range(event_count):\r\n event = input()\r\n self.handle_event(event)\r\n # print(f\"Speed: {self.car_speed}, Limit: {self.speed_limit}, Overtake allowed: {self.overtake_allowed}, Missed signs:{self.missed_signs}\")\r\n print(self.missed_signs)\r\n \r\n\r\n def handle_event(self, event):\r\n event = list(map(int, event.split()))\r\n event_type = event[0]\r\n if event_type == 1:\r\n self.set_car_speed(event[1])\r\n if event_type == 2: \r\n self.overtake_car()\r\n if event_type == 3:\r\n self.set_speed_limit(event[1])\r\n if event_type == 4:\r\n self.set_overtake_allowed(True)\r\n if event_type == 5:\r\n self.set_speed_limit(0)\r\n if event_type == 6:\r\n self.set_overtake_allowed(False)\r\n \r\n\r\n def set_car_speed(self, car_speed):\r\n self.car_speed = car_speed\r\n self.check_car_speed()\r\n\r\n def set_speed_limit(self, speed_limit):\r\n self.speed_limit.append(speed_limit)\r\n self.check_car_speed()\r\n\r\n def check_car_speed(self):\r\n latest_speed_limit = self.speed_limit[-1]\r\n while latest_speed_limit != 0 and latest_speed_limit < self.car_speed:\r\n self.missed_signs += 1\r\n self.speed_limit.pop()\r\n latest_speed_limit = self.speed_limit[-1]\r\n \r\n def set_overtake_allowed(self, overtake_allowed):\r\n self.overtake_allowed.append(overtake_allowed)\r\n\r\n def overtake_car(self):\r\n while not self.overtake_allowed[-1]:\r\n self.missed_signs += 1\r\n self.overtake_allowed.pop()\r\n \r\n def get_missed_signs(self):\r\n return self.missed_signs\r\n\r\nif __name__ == \"__main__\":\r\n DrivingTest()", "n=int(input())\r\nst=[0]*n\r\ntop=-1\r\ncurr_speed=0\r\nans=0\r\nc=0\r\nwhile(n>0):\r\n \r\n n-=1\r\n a=list(map(int,input().split()))\r\n if(a[0]==1):\r\n curr_speed=a[1]\r\n if(top>=0 and curr_speed>st[top]):\r\n while(curr_speed>st[top] and top>=0):\r\n top-=1\r\n ans+=1\r\n \r\n if(a[0]==4):\r\n c=0\r\n elif(a[0]==6):\r\n c+=1\r\n if(a[0]==5):\r\n top=-1\r\n \r\n if(a[0]==2):\r\n ans+=c\r\n c=0\r\n if(a[0]==3):\r\n if(curr_speed>a[1]):\r\n ans+=1\r\n else:\r\n st[top+1]=a[1]\r\n top+=1\r\nprint(ans)\r\n ", "# D. Driving Test\r\n\r\nn = int(input())\r\n\r\nps = None\r\nseen_sl = [float('inf')]\r\nseen_ot = [True]\r\n\r\nanswer = 0\r\nfor i in range(n):\r\n\tline = list(map(int, input().split()))\r\n\tt = line[0]\r\n\tif t == 1:\r\n\t\tps = line[1]\r\n\t\twhile ps > seen_sl[-1]:\r\n\t\t\tanswer += 1\r\n\t\t\tseen_sl.pop(-1)\r\n\telif t == 2:\r\n\t\twhile not seen_ot[-1]:\r\n\t\t\tanswer += 1\r\n\t\t\tseen_ot.pop(-1)\r\n\telif t == 3:\r\n\t\tseen_sl.append(line[1])\r\n\t\twhile ps > seen_sl[-1]:\r\n\t\t\tanswer += 1\r\n\t\t\tseen_sl.pop(-1)\r\n\telif t == 4:\r\n\t\tseen_ot.append(True)\r\n\telif t == 5:\r\n\t\tseen_sl.append(float('inf'))\r\n\telif t == 6:\r\n\t\tseen_ot.append(False)\r\n\r\nprint(answer)\r\n", "n=int(input())\r\ns=0\r\nms=[]\r\no=1\r\nz=0\r\nq=0\r\nfor _ in range(n):\r\n a=list(map(int,input().split()))\r\n if a[0]==1:\r\n s=a[1]\r\n while len(ms)>0 and ms[-1]<s:\r\n z+=1\r\n ms.pop(-1)\r\n elif a[0]==2:\r\n if o!=1:\r\n z+=(1-o)\r\n o=1\r\n elif a[0]==3:\r\n ms.append(a[1])\r\n while len(ms)>0 and ms[-1]<s:\r\n z+=1\r\n ms.pop(-1)\r\n elif a[0]==4:\r\n o=1\r\n elif a[0]==5:\r\n ms=[]\r\n elif a[0]==6:\r\n o-=1\r\nprint(z)", "import math\r\nfrom collections import Counter, defaultdict\r\nfrom itertools import accumulate\r\n\r\nR = lambda: map(int, input().split())\r\nn = int(input())\r\nspl = [math.inf]\r\not_forbid = 0\r\nsp = 0\r\nres = 0\r\nfor i in range(n):\r\n arr = list(R())\r\n tp = arr[0]\r\n if tp == 1:\r\n sp = arr[1]\r\n while sp > spl[-1]:\r\n spl.pop()\r\n res += 1\r\n elif tp == 2:\r\n if ot_forbid > 0:\r\n res += ot_forbid\r\n ot_forbid = 0\r\n elif tp == 3:\r\n if arr[1] >= sp:\r\n spl.append(arr[1])\r\n else:\r\n res += 1\r\n elif tp == 4:\r\n ot_forbid = 0\r\n elif tp == 5:\r\n spl = [math.inf]\r\n else:\r\n ot_forbid += 1\r\nprint(res)", "import collections\r\nn=int(input())\r\nx,v=map(int,input().split())\r\no=collections.deque()\r\nq=0\r\nk=0\r\nfor i in range(1,n):\r\n s=input()\r\n if s[0]=='1':\r\n x,v=map(int,s.split())\r\n while len(o)>0 and o[-1]<v:\r\n o.pop()\r\n k+=1\r\n if s[0]=='2':\r\n k+=q\r\n q=0\r\n if s[0]=='3':\r\n x,y=map(int,s.split())\r\n if v<=y:\r\n o.append(y)\r\n else:\r\n k+=1\r\n if s[0]=='4':\r\n q=0\r\n if s[0]=='5':\r\n o.clear()\r\n if s[0]=='6':\r\n q+=1\r\nprint(k)", "#!/usr/bin/env python3\nfrom sys import stdin, stdout\nfrom math import inf\n\ndef rint():\n return map(int, stdin.readline().split())\n#lines = stdin.readlines()\n\ncsp = 0\nov = 1\n\nsign = []\nans = 0\nspst = [inf]\novst = [1]\nn = int(input())\nfor i in range(n):\n sign = list(rint())\n if sign[0] == 1:\n csp = sign[1]\n while csp > spst[-1]:\n spst.pop()\n ans += 1\n if sign[0] == 2:\n while ovst[-1] == 0:\n ovst.pop()\n ans += 1\n if sign[0] == 3:\n if sign[1] >= csp:\n spst.append(sign[1])\n else:\n ans += 1\n if sign[0] == 4:\n ovst.append(1)\n if sign[0] == 5:\n spst.append(inf)\n if sign[0] == 6:\n ovst.append(0)\nprint(ans)\n" ]
{"inputs": ["11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300", "5\n1 100\n3 200\n2\n4\n5", "7\n1 20\n2\n6\n4\n6\n6\n2", "1\n1 100", "2\n1 100\n2", "10\n1 37\n6\n5\n2\n5\n6\n5\n2\n4\n2", "10\n1 5\n4\n5\n4\n1 21\n6\n1 10\n1 1\n2\n3 1"], "outputs": ["2", "0", "2", "0", "0", "2", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
17
193c184144e66d2a88598d7fa03827ac
Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of *n*·*m* square tiles forming a *n*<=×<=*m* rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants to use a painter robot to color the tiles. In the beginning the robot is standing in a border tile (*x**s*,<=*y**s*) facing a diagonal direction (i.e. upper-left, upper-right, down-left or down-right). As the robot walks in the kitchen he paints every tile he passes even if it's painted before. Painting each tile consumes one unit of black paint. If at any moment the robot hits a wall of the kitchen he changes his direction according the reflection rules. Note that a tile gets painted when the robot enters the tile from another tile, in other words changing direction in the same tile doesn't lead to any painting. The first tile the robot is standing on, is also painted. The robot stops painting the first moment the floor is checkered. Given the dimensions of the kitchen and the position of the robot, find out the amount of paint the robot consumes before it stops painting the floor. Let's consider an examples depicted below. If the robot starts at tile number 1 (the tile (1,<=1)) of the left grid heading to down-right it'll pass tiles 1354236 and consumes 7 units of black paint on his way until he stops at tile number 6. But if it starts at tile number 1 in the right grid heading to down-right it will get stuck in a loop painting tiles 1, 2, and 3. The first line of the input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=105). The second line contains two integers *x**s* and *y**s* (1<=≤<=*x**s*<=≤<=*n*,<=1<=≤<=*y**s*<=≤<=*m*) and the direction robot is facing initially. Direction is one of the strings: "UL" (upper-left direction), "UR" (upper-right), "DL" (down-left) or "DR" (down-right). Note, that record (*x**s*,<=*y**s*) denotes the tile that is located at the *x**s*-th row from the top and at the *y**s*-th column from the left of the kitchen. It's guaranteed that the starting position will be a border tile (a tile with less than four side-adjacent tiles). Print the amount of paint the robot consumes to obtain a checkered kitchen floor. Or print -1 if it never happens. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. Sample Input 3 4 1 1 DR 3 4 3 3 DR 3 3 1 1 DR 3 3 1 2 DL Sample Output 7 11 -1 4
[ "n,m = (lambda x: (int(x[0]), int(x[1])))(input().split())\r\nx,y,dir = (lambda x: (int(x[0]), int(x[1]), x[2]))(input().split())\r\n\r\nres = 1\r\ndx = -1\r\ndy = -1\r\nif dir[0] == 'D':\r\n dx = 1\r\nif dir[1] == 'R':\r\n dy = 1\r\n\r\ncells = set()\r\ncells.add((x,y))\r\n\r\nfor _ in range(1,(n+m-2)*2):\r\n dlx = x-1\r\n dly = y-1\r\n if dx==1:\r\n dlx=n-x\r\n if dy==1:\r\n dly=m-y\r\n dl = min(dlx,dly)\r\n \r\n x+=dx*dl\r\n y+=dy*dl\r\n cells.add((x,y))\r\n res+=dl\r\n\r\n if(len(cells)==n+m-2):\r\n print(res)\r\n break\r\n if dl==dlx:\r\n dx=-dx\r\n if dl==dly:\r\n dy=-dy\r\nelse:\r\n print(-1)# 1693234684.837677" ]
{"inputs": ["3 4\n1 1 DR", "3 4\n3 3 DR", "3 3\n1 1 DR", "3 3\n1 2 DL", "2 5\n2 3 DR", "2 3\n2 3 DL", "3 2\n3 1 DL", "3 4\n1 1 DL", "2 2\n2 2 UR", "547 180\n96 1 UR", "657 213\n549 1 UL", "76 153\n1 74 UL", "80304 59860\n27585 59860 UR", "15954 45613\n15954 45142 UR", "66972 6779\n1 5667 UL", "2622 82284\n2540 1 UL", "48517 68036\n48517 31953 DR", "32132 32312\n1 2 DR", "100000 99999\n100000 1 DR", "100000 99999\n1 99999 DR", "84166 43542\n54265 43542 DR", "35185 19049\n31553 1 DR", "70834 99677\n1 23598 DL", "16730 65966\n12102 65966 DL", "52379 51718\n52379 807 UR", "93151 27224\n1 15542 UR", "39047 2730\n16937 1 UR", "74696 83359\n74696 64325 UL", "99999 99999\n99999 99999 UR", "99999 99999\n99999 99998 UR", "2 2\n2 2 UR", "2 2\n1 2 UR", "9684 98536\n9684 80875 DL", "45333 74042\n1 43244 DL", "91228 54671\n1674 1 DL", "32001 30178\n32001 28119 UR", "77896 5684\n18467 5684 UR", "13546 91435\n1002 1 UL", "64435 19953\n5705 19953 DR", "5208 582\n979 1 DR", "51103 66871\n1 57465 DL", "86752 42377\n72660 42377 DL", "22402 28129\n22402 24340 DL", "73420 3635\n1 2940 UR", "9070 74017\n4901 1 UR", "54965 59770\n54965 14083 UL", "95737 26059\n30821 26059 UL", "41633 11811\n5694 1 UL", "93183 58113\n1 39140 DR", "28833 43865\n22853 1 DL", "74728 19372\n74728 18073 DL", "10378 85660\n7751 85660 DL", "61396 66289\n50382 1 UR", "97045 41795\n1 27338 UR", "32695 27547\n17514 27547 UL", "78590 3053\n78590 239 UL", "19363 78559\n1 55927 UL", "65258 49971\n20976 1 DR", "7593 1397\n1 1155 DL", "43242 82025\n19055 1 DL", "89137 57531\n89137 3552 DL", "29910 43284\n15956 43284 UR", "75805 18790\n46466 1 UR", "11455 85078\n11455 39494 UL", "47104 65707\n27797 65707 UL", "98122 41213\n19832 1 UL", "33772 26966\n1 6679 DR", "79667 2472\n62739 2472 DR"], "outputs": ["7", "11", "-1", "4", "7", "3", "3", "7", "2", "135504", "-1", "11626", "5862949615", "-1", "778336963", "216075159", "5618298349", "1551509598", "9999700003", "9999700003", "7214569537", "-1", "13418107690", "1171670331", "3155460233", "3301236001", "195090753", "11273566961", "-1", "-1", "2", "2", "1908112615", "4559265901", "9870668501", "1850848001", "575273042", "-1", "-1", "3617888", "-1", "4398289793", "-1", "332220976", "-1", "4668092521", "-1", "491662111", "5414953246", "-1", "-1", "-1", "-1", "4055829600", "-1", "-1", "-1", "4857383821", "-1", "6371542297", "5127940102", "2517815394", "-1", "-1", "-1", "4804907081", "1005599068", "301313741"]}
UNKNOWN
PYTHON3
CODEFORCES
1
1954f4f3cff193e51aefea4a144bdfcb
Save Luke
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other with speed *v*1 and *v*2, respectively. Luke has width *d* and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive. The first line of the input contains four integers *d*, *L*, *v*1, *v*2 (1<=≤<=*d*,<=*L*,<=*v*1,<=*v*2<=≤<=10<=000,<=*d*<=&lt;<=*L*) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively. Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . Sample Input 2 6 2 2 1 9 1 2 Sample Output 1.00000000000000000000 2.66666666666666650000
[ "d, L, v1, v2 = map(int, input().split())\r\nt = 1\r\ne = 10e-14\r\n\r\na = 0\r\nb = L\r\n\r\nresult = 0.0\r\nwhile True:\r\n if b-a > d:\r\n if (b-v2) - (a+v1) < d:\r\n v1 /= 2\r\n v2 /= 2\r\n t /= 2\r\n continue\r\n else:\r\n a += v1\r\n b -= v2 \r\n result += t \r\n\r\n if (b-a)-d < e:\r\n print(f\"%.12f\" % (result))\r\n break", "a,b,c,d=[int(x) for x in input().split()]\r\nprint((b-a)/(c+d))", "a, b, c, d = map(int, input().split())\r\nprint((b - a)/(c + d))\r\n\r\n# UBCF\r\n# CodeForcesian\r\n# ♥\r\n# سلام من به تو یار قدیمییییی", "a,b,c,d = list(map(int,input().split()))\r\ne = abs(a-b)\r\nf = abs(c+d)\r\nprint(e/f)", "d,l,v1,v2 = map(int, input().split())\r\n\r\nans = (l - d)/ (v1 + v2)\r\nprint(\"{0:.6f}\".format(ans))\r\n", "lista = [int(i) for i in input().split()]\nprint((lista[1]-lista[0])/(lista[2]+lista[3]))", "X = list(map(int , input().split()))\r\nprint((X[1]-X[0])/(X[2]+X[3]))", "d, L, v1, v2 = map(int, input().split())\r\nt = (L - d) / (v1 + v2)\r\nprint(t)\r\n", "d,L,v1,v2 = list(map(int,input().split(\" \")))\r\n\r\nx=L-d\r\ny=v1+v2\r\nans=x/y\r\n\r\nprint(\"%0.6f\" %(ans))", "d,L,v1,v2=map(int,input().split())\r\nt=(L-d)/(v1+v2)\r\nprint(t)", "d, L, v1, v2=map(int,input().split())\r\nprint((L-d)/(v1+v2))", "# Input: d, L, v1, v2\n# d = Lukes width\n# L= position of second presser (first one is at 0)\n# v1 = speed of first presser\n# v2 = speed of second presser\n# Output:\n# Max time luke can curvive for\n\ndef saveLuke():\n var = input().strip()\n var = var.split(' ')\n d = int(var[0])\n L = int(var[1])\n v1 = int(var[2])\n v2 = int(var[3])\n v = v1 + v2\n s = L - d\n print(s/v)\n\nsaveLuke()\n\n", "a,b,v1,v2 = list(map(int,input().split()))\r\nprint('%.20f'%((b-a)/(v1+v2)))", "d, L, v1, v2 = [int(x) for x in input().split()]\r\n\r\nq = abs(L - d) / (v1 + v2)\r\n\r\nprint(q)", "d,l,v1,v2 = map(int,input().split())\r\nprint((((l-d)*v1)/(v1+v2))/v1)", "a,b,c,d = map(int,input().split())\r\nt = (b-a)/(c+d)\r\nprint(t)", "d,L,v1,v2=map(int,input().split())\r\nans=float((L-d)/(v1+v2))\r\nprint(ans)", "d,l,v1,v2=map(int,input().split())\r\nprint(abs(d-l)/(v1+v2))", "d, l, v1, v2 = map(int, input().split())\r\nleft = 0\r\nright = l\r\n\r\nwhile right - left > 0.000001:\r\n mi = (left + right) / 2\r\n if v1 * mi + v2 * mi > l - d:\r\n right = mi\r\n else:\r\n left = mi\r\n\r\nprint(right)\r\n", "d, L, v1, v2 = map(float,input().split())\r\nprint((L-d)/(v1+v2))", "d,l,v1,v2 = map(int,input().split())\r\nres = (l-d)/(v1+v2)\r\nprint(res)", "[d, L, v1, v2] = [int(x) for x in input().split()]\n\nprint((L-d)/(v2+v1))", "d,l,v1,v2 = map(int, input().split())\nl-=d\ntotv = v1+v2\nprint(l/totv)\n", "d,l,v1,v2 = map(int,input().split())\r\nprint((l-d) / (v1+v2))", "d,l,v1,v2=map(int,input().split())\ns=(l-d)/(v1+v2)\nprint('%0.25f'%s)\n", "def save_luke(l, d, v1, v2):\r\n return (l - d) / (v1 + v2)\r\n \r\n\r\nd, l, v1, v2 = map(int, input().split())\r\nprint(save_luke(l, d, v1, v2))\r\n", "[d,L,v1,v2]=[int(i) for i in input().split()]\nres=round((L-d)/(v1+v2),6)\nprint(res)\n", "a,b,c,d = map(int,input().split())\r\na = abs(a-b)\r\nb = abs(c+d)\r\nprint(a/b)", "d,l,v1,v2=map(int,input().split())\r\nx=(v1*(l-d))/(v1+v2)\r\nres=x/v1\r\nprint (\"%.6f\"%res)\r\n", "d, l, v1, v2 = [int(s) for s in input().split()]\n\nprint((l - d) / (v1 + v2))", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Jan 21 16:27:43 2022\r\n\r\n@author: sachd\r\n\"\"\"\r\na=input().split()\r\nd=int(a[0])\r\nl=int(a[1])\r\nv1=int(a[2])\r\nv2=int(a[3])\r\nans=abs((l-d)/(v1+v2))\r\nprint(ans)", "n_arr = list(map(int, input().split()))\nmax_d = n_arr[1] - n_arr[0]\ntot_v = n_arr[2] + n_arr[3]\nprint(\"{:.10f}\".format(max_d/tot_v))\n \t\t\t \t\t \t\t \t \t \t\t \t \t\t", "k, l, c1, c2 = map(int, input().split())\r\nres=c1+c2\r\nprint((l - k) / (res))\r\n", "import math\r\ns = input()\r\ns=s.split()\r\nd=float(s[0])\r\nl=float(s[1])\r\nv1=float(s[2])\r\nv2=float(s[3])\r\nl-=d\r\nans=(l/(v1+v2))\r\nround(ans,4)\r\nprint(ans)\r\n", "def main():\n d, L, v1, v2 = map(int, input().split())\n print((L - d) / (v1 + v2))\n\n\nif __name__ == '__main__':\n main()\n", "d,n,v,s=map(int,input().split())\r\nr=n-d\r\nt=v+s\r\nprint(round(r/t,20))", "d,l,v1,v2=map(int,input().split())\nprint( ((v1*(l-d))/(v2+v1))/v1)\n", "d,l,v1,v2 = map(float,input().split())\r\nprint((l-d)/(v1+v2))", "d,L,v1,v2=map(int,input().split());print((L-d)/(v1+v2))", "d, k2, v1, v2 = [int(x) for x in input().split()]\r\nprint((k2-d) / (v1+v2))", "import math\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef invr():\r\n return list(map(int, input().split()))\r\n\r\n\r\nd, l, v1, v2 = invr()\r\na, c, c2 = 0, 0.0, 0\r\ninc = 1\r\n\r\nwhile (l - a) > d and c2 < 10:\r\n a += v1\r\n l -= v2\r\n c += inc\r\n if not((l - a) > d):\r\n c2 += 1\r\n a -= v1\r\n l += v2\r\n c -= inc\r\n inc /= 10\r\n v1 /= 10\r\n v2 /= 10\r\n\r\nprint(c)", "x = input()\r\nx = x.split()\r\n\r\nd = int(x[0])\r\nL = int(x[1])\r\nv1 = int(x[2])\r\nv2 = int(x[3])\r\n\r\nans = (L-d)/(v1+v2)\r\nprint (ans)", "d,l,v1,v2=map(int,input().split())\r\nx=((l-d)/(v1+v2))\r\ny=\"{:0.12f}\".format(x)\r\nprint(y)", "d, L, v1, v2 = map(int,input().split())\r\nprint((L - d)/(v1 + v2))", "import decimal\r\nD=decimal.Decimal\r\n\r\ndef solution(l1):\r\n d=l1[0]\r\n l=l1[1]\r\n v=l1[2]+l1[3]\r\n return D(abs((d-l)/v))\r\n\r\ndef answer():\r\n l1 = [int(x) for x in input().split()]\r\n print(solution(l1))\r\nanswer()", "d, L, v1, v2 = map(float, input().split())\r\n\r\nt = (L - d) / (v1 + v2)\r\n\r\nprint(\"{:.15f}\".format(t))\r\n", "d,l,v1,v2=map(float,input().split())\r\nprint('%.20f'%((l-d)/(v1+v2)))\r\n", "d,l,v,c=map(int,input().split())\r\nprint((l-d)/(v+c))", "d, l, v1, v2 = [int(x) for x in input().split()]\nprint((l - d) / (v1 + v2))\n", "# tested by Hightail - https://github.com/dj3500/hightail\r\nfrom sys import stdin, stdout\r\nimport math\r\n\r\n#Start of Program\r\ndef calculate(d,R,L,vR,vL):\r\n\r\n safe = ( R + L ) - d\r\n speed = (vR + vL)\r\n \r\n a = float(safe / speed)\r\n \r\n return round(a,6) \r\n\r\n#Print Output Result\r\nd, L, v1, v2 = [int(x) for x in stdin.readline().rstrip().split()] \r\n\r\nR = 0\r\nans = calculate(d,R,L,v1,v2)\r\n \r\nstdout.write( str(ans) + \"\\n\" )", "d, L, v1, v2 = map(int,input().split())\r\nprint(\"{0:.20f}\".format((L-d)/(v1+v2)))", "d,l,v1,v2 = map(int,input().split())\r\nt = (l-d)/(v1+v2)\r\nprint(t)", "#code\r\nimport math\r\nd, l, v1, v2 = map(int, input().split(' '))\r\n\r\nans = ((l-d)*1.00000000000000000000000000)/(v1*1.00000000000000000000000+v2)\r\n\r\nprint(\"%.20f\" % abs(ans))", "d, L, v1, v2 = (float(i) for i in input().split(' '))\r\nt = (L - d)/(v2 + v1)\r\nprint(t)", "a,b,c,d=map(int,input().split());\r\nx=b-a\r\ny=c+d\r\nr=x/y\r\nprint(r)\r\n", "import sys\nd, L, v1, v2 = map(int, sys.stdin.readline().split())\nprint((L-d)/(v1+v2))\n", "d, L, a1, a2 = map(int, input().split())\r\nprint ((L - d) / (a1+a2))", "a,b,c,d=map(int,input().split())\r\nprint(format((abs(a-b))/(c+d),'.20f'))", "i = [int(a) for a in input().split()]\r\n\r\ntime = (i[1] - i[0]) / (i[-1] + i[-2])\r\nprint(round(time, 8))", "d, L, v1, v2 = [int(i) for i in input().split()]\r\nprint((L-d)/(v1+v2))", "d,L,v1,v2 = map(int,input().split())\r\n\r\nt = (L-d)/(v1+v2)\r\nprint(t)", "d,L,v1,v2=map(float,input().split())\r\ntime= (L-d)/(v1+v2)\r\nprint(float(time))", "d,L,v1,v2=map(int,input().split())\r\nv=v1+v2\r\nt=(L-d)/v\r\nprint(t)", "d, L, v1, v2 = [int(x) for x in input().split()]\r\nL = abs(L)\r\nres = (L - d) / (v1 + v2)\r\nprint(res)", "datain = [int(i) for i in input().split()]\nt = (datain[1]-datain[0]) / (datain[2]+datain[3])\nprint(t)\n", "d,l,v1,v2=map(int,input().split())\r\nv_1=v1+v2\r\nprint(abs(l-d)/v_1)\r\n", "\r\ndef solution(d, l, v1, v2):\r\n l = l-d\r\n v = v1+v2\r\n print(round(l/v, 7))\r\n\r\nd, l, v1, v2 = [int(x) for x in input().strip().split(\" \")]\r\nsolution(d, l, v1, v2)", "string = input();\r\nd,l,v1,v2 = string.split();\r\n\r\nd = int(d);\r\nl = int(l);\r\nv1 = int(v1);\r\nv2 = int(v2);\r\n\r\nprint((l-d)/(v1+v2));", "num= input()\r\n[d, L, v1, v2] = num.split()\r\nprint((int(L)-int(d))/(int(v1)+int(v2)))", "d, l, vr, vl = map(int, input().split())\n\nt = (l - d) / (vr + vl)\nprint(t)", "d,l,v1,v2=list(map(int,input().split()))\r\ni=(l-d)/(v1+v2)\r\nprint ('%.20f'%i)", "a,b,c,d =map(int , input().split())\r\ne= (b-a)/(c+d)\r\nprint(e)", "from cmath import *\r\nfrom decimal import *\r\n \r\ndef _input(): return map(int, input().split())\r\ndef _list(): return list(map(int, input().split()))\r\n \r\ndef solves():\r\n a,b,c,d=_input()\r\n print((b-a)/(c+d))\r\n\r\n\r\nt=1\r\n#t =int(input())\r\nfor _ in range(0,t):\r\n solves()", "a,b,c,d=input().split()\r\np=abs(int(a)-int(b))\r\ng=abs(int(c)+int(d))\r\nprint((p)/(g))\r\n\r\n\r\n", "input_constants = [int(x) for x in input().split(' ')]\r\nfree_space = input_constants[1]-input_constants[0]\r\ntime = free_space/(input_constants[2]+input_constants[3])\r\nprint(time)", "dlv=input().rstrip().split()\r\nl=int(dlv[0])\r\np2=int(dlv[1])\r\nv1=int(dlv[2])\r\nv2=int(dlv[3])\r\ndist=p2-l\r\nvel=v1+v2\r\ntime=float(dist/vel)\r\nprint(\"%.15f \" %time)\r\n", "a,b,c,d=map(int,input().split())\r\ne=(b-a)/(c+d)\r\nprint('{:0.16f}'.format(e),end='')\r\n[print(0,end='') for x in range(4)]", "d,l,v1,v2=map(int,input().split())\r\nk=(l-d)/(v1+v2)\r\nprint(\"%.9f\"%max(0,k))", "d,l,v1,v2 = map(int,input().split())\r\nl -= d\r\nv_s = v1+v2\r\nmeet_time = l / v_s\r\nprint(meet_time)", "import math\r\nfrom fractions import Fraction as frac\r\n\r\ndef solve(case_no):\r\n # implementation\r\n a, b, c, d = map(int, input().split())\r\n print((b - a) / (c + d))\r\n\r\nt = 1\r\n# t = int(input())\r\nfor i in range(1, t + 1):\r\n solve(i)\r\n", "a,b,c,d = input().split()\r\na = int(a)\r\nb = int(b)\r\nc = int(c)\r\nd = int(d)\r\nprint(abs(a-b)/(c+d))\r\n", "def main():\n\td, l, v1, v2 = map(int, input().split())\n\tt = (l - d)/(v1 + v2)\n\tprint(round(t, 7))\nif __name__ == '__main__':\n\tmain()", "d,l,v,u = map(int,input().split())\r\nprint((l-d)/(v+u))", "def solve(d, L, v1, v2):\n return (v1*(L - d))/(v1 + v2)/v1\n\n\ndef main():\n d, L, v1, v2 = list(map(int, input().split()))\n print(solve(d, L, v1, v2))\n\n\nmain()\n", "d,l,v1,v2=map(int,input().split())\r\np=(l-d)/(v1+v2)\r\nprint(p)\r\n", "#! /usr/bin/env python\n# -*- coding: utf-8 -*-\n# vim:fenc=utf-8\n#\n# Copyright © 2016 missingdays <missingdays@missingdays>\n#\n# Distributed under terms of the MIT license.\n\n\"\"\"\n\n\"\"\"\n\ndef read_list():\n return [int(i) for i in input().split()]\ndef new_list(n):\n return [0 for i in range(n)]\ndef new_matrix(n, m=0):\n return [[0 for i in range(m)] for i in range(n)]\n\n\nd, l, v1, v2 = read_list()\n\nt = l / (v1+v2)\n\nt -= d / (v1+v2)\n\nprint(t)\n", "a,b,c,d = map(int,input().split())\r\nprint ((b-a)/(c+d))", "D,L,V1,V2=map(int,input().split());print((L-D)/(V1+V2))", "d, l, v1, v2 = list(map(int, input().split()))\r\nx = abs(d-l) / (v1+v2)\r\nprint(x)", "d,l,v1,v2 = map(int,input().split())\r\nprint((l-d) / float(v1+v2))\r\n", "d,L,v1,v2 = map(int,input().split())\r\n\r\nsp = L - d\r\n\r\nprint(sp/(v1+v2))\r\n\r\n ", "d,l,v1,v2 = map(int,input().split())\r\nprint((l-d)/(v1+v2))", "# import sys\r\n# sys.stdin = open(\"test.in\",\"r\")\r\n# sys.stdout = open(\"test.out\",\"w\")\r\na,b,c,d=map(int,input().split())\r\nt=(b-a)/(c+d)\r\nprint(\"%.20f\"%t)", "s = input().split()\r\nd = int(s[0])\r\nL = int(s[1])\r\nv1 = int(s[2])\r\nv2 = int(s[3])\r\nc = (L * v1 - d * v1)/(v1 + v2)\r\nanswer = c / v1\r\nprint(\"%0.6f\" % answer)\r\n", "d,l,v1,v2 = map(int,input().split())\r\nprint(format((-d+l)/(v1+v2),'.20f'))\r\n", "d,L,v1,v2 = map(int, input().split())\r\nans = (L-d)/(v1+v2)\r\nprint(\"{0:.10}\".format(ans))", "def solve(a,b,c,w):\r\n a=abs(a)\r\n tmp=a-w\r\n tmp2=b+c\r\n return tmp/tmp2\r\n\r\nw,a,b,c=map(int,input().split())\r\nprint(solve(a,b,c,w))\r\n", "d, L, v1, v2 = [float(t) for t in input().split()]\r\nprint((L-d)/(v1+v2))", "d, l, v1, v2 = list(map(int,input().split()))\nprint((l-d)/(v1+v2))", "\nimport sys\n\n# t = (L - d) / (v1 + v2)\n\ndef main():\n d, L, v1, v2 = [float(s) for s in sys.stdin.readline().split()]\n\n print(\"{:.6f}\".format((L - d) / (v1 + v2)))\n\n\nif __name__ == \"__main__\":\n main()\n", "inp = input().split(\" \")\r\nprint((int(inp[1]) - int(inp[0])) / (int(inp[2]) + int(inp[3])))", "s=[int(x) for x in input().split(' ')]\r\nprint((s[1]-s[0])/(s[2]+s[3]))\r\n", "L, p2, v1, v2 = map(int, input().split())\r\ndistance = p2 - L\r\nvelocity = v1 + v2\r\nprint('{0:.15f}'.format(distance/velocity))", "# import sys\r\n# sys.stdin=open(\"input.in\",\"r\")\r\n# sys.stdout=open(\"output.out\",\"w\")\r\n\r\nd,l,v1,v2=map(int,input().split())\r\nx=l-d\r\nprint(x/(v1+v2))", "a,b,c,d=map(int,input().split()); \r\nx=b-a\r\ny=c+d\r\nprint(x/y)", "d, L, v1, v2 = [int(word) for word in input().split()]\nr = (L - d) / (v1 + v2)\nprint(r)\n", "d, L, v1, v2 = list(map(int, input().split()))\r\nprint((L-d)/(v1+v2))", "def save(a, b, c, d):\r\n return '{0:.20f}'.format((b - a) / (c + d))\r\n\r\n\r\nD, L, v1, v2 = [int(i) for i in input().split()]\r\nprint(save(D, L, v1, v2))\r\n", "a, b, c, d=map(int, input().split())\r\nprint(round((b-a)/(c+d), 6))", "# import sys \r\n# sys.stdin=open(\"input1.in\",\"r\")\r\n# sys.stdout=open(\"OUTPUX.out\",\"w\")\r\na,b,c,d=map(int,input().split())\r\nprint((((b-a)/(c+d))))", "string = input()\r\nnumbers = list(map(int, string.split()))\r\na = numbers[0]\r\nb = numbers[1]\r\nv1 = numbers[2]\r\nv2 = numbers[3]\r\nprint((b - a) / (v1 + v2))", "d, L, v1, v2 = (int(i) for i in input().split())\nres = (L - d) / (v1 + v2)\nprint(res)\n", "d, l, v1, v2 = map(int, input().split())\r\nprint(f'{(l - d) / (v1 + v2):.20f}')", "\r\nd,l,v1,v2=map(int,input().split())\r\nt=(l-d)/(v1+v2)\r\nprint(t)", "words=input().split()\r\nd=float(words[0])\r\nl=float(words[1])\r\nv1=float(words[2])\r\nv2=float(words[3])\r\nprint( (l-d)/(v1+v2))", "def main():\n d, l, v1, v2 = map(int, input().split())\n result = float((l-d)/(v1+v2))\n print(result)\nmain()\n", "d, l, v1, v2 = [int(i) for i in input().split()]\r\nprint((l-d)/(v1+v2))", "d, L, v1, v2 = [int(i) for i in input().split()]\r\nprint((L - d) / (v1 + v2))\r\n", "x = input().split()\r\n\r\nfor i in range(len(x)):\r\n x[i] = int(x[i])\r\n\r\nl = (x[1]-x[0])/(x[2]+x[3])\r\nprint (l)", "d, l, v1, v2 = [int(i) for i in input().split()]\r\ntotal = 0\r\ntotal = (l - d) / (v1 + v2)\r\nprint(total)\r\n", "d,L,v1,v2 = list(map(int,input().split()))\r\nprint((L-d)/(v1+v2))\r\n", "l=list(map(int, input().split()))\r\nprint(format((l[1]-l[0])/(l[3]+l[2]),'.10f'))", "a = input()\r\nb = a.split(' ')\r\nd = int(b[0]) \r\nL = int(b[1])\r\nv1 = int(b[2])\r\nv2 = int(b[3])\r\nt = (L - d) / (v1 + v2)\r\nprint(t)\r\n", "def solve():\r\n d,l,v1,v2=list(map(int,input().split()))\r\n print('%.12f'%((l-d)/(v1+v2)))\r\nsolve()", "a=list(map(int,input().split()))\r\nb=a[1]-a[0]\r\nc=a[2]+a[3]\r\nprint(b/c)", "d, L, v1, v2 = map(int, input().split())\r\nx = (float(L) - float(d)) / (float(v1) + float(v2) )\r\n\r\nprint(\"{:.10f}\".format(x))", "d,l,u,v=input().split()\r\nd=int(d)\r\nl=int(l)\r\nu=int(u)\r\nv=int(v)\r\nt=float((l-d)/(v+u))\r\nprint('{0:.20f}'.format(t))", "d, l, v1, v2 = [int(i) for i in input().split()]\n\nvsbl = v1 + v2\ns = l - d\n\nprint(s/vsbl)\n", "def max_time_luke_alive(d, L, v1, v2):\r\n t = (L - d) / (v1 + v2)\r\n return max(0, t)\r\n\r\n# Input\r\nd, L, v1, v2 = map(int, input().split())\r\n\r\n# Output\r\nresult = max_time_luke_alive(d, L, v1, v2)\r\nprint(\"{:.10f}\".format(result))", "# Save Luke\ndef press(d, L, v1, v2):\n return (L - d) / (v1 + v2)\n\n\nd, L, v1, v2 = list(map(int, input().split()))\nprint(press(d, L, v1, v2))", "d,l,v,w=map(float,input().split())\r\nprint('%.16f'%((l-d)/(v+w)))", "d,L,v_1,v_2 = tuple(int(x) for x in input().split())\nv = v_1 + v_2\nt = (L-d)/v\nprint(t)\n", "a,b,c,d=map(int,input().split())\r\nx=(b-a)/(c+d)\r\nprint(x)\r\n", "lyckWidth, pressPosition, downVel, highVel = map(int, input().split())\r\n\r\nprint(\r\n (pressPosition - lyckWidth) / (highVel + downVel)\r\n)\r\n", "d, s, v1, v2 = map(int, input().split())\r\nv3 = v1 + v2\r\nt = (s - d) / v3\r\nprint(t)", "i=[]\r\nfor x in input().split():\r\n i.append(int(x))\r\nprint((i[1]-i[0])/(i[3]+i[2]))", "L=list(map(int,input().split()))\r\nnum=L[1]-L[0]\r\nden=L[2]+L[3]\r\nprint(num/den)", "a, b, c, d=map(int,input().split())\r\ne=b-a\r\nf=c+d\r\nprint(e/f)\r\n", "import decimal\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nd, l, v1, v2 = map(decimal.Decimal, input().split())\r\nprint((l - d) / (v1 + v2))", "#!/usr/bin/env python3\r\n\r\nd, L, v1, v2 = [int(x) for x in input().split()]\r\nprint((L - d)/(v1 + v2))\r\n", "# A. Save Luke\n\nd, l, v1, v2 = map(int, input().split())\nprint((l - d) / (v1 + v2))\n", "d,L,v1,v2 = map(int,input().split())\r\nif L>d:\r\n\tprint((L-d)/(v1+v2))", "a,b,c,d=map(int,input().split());print((b-a)/(c+d))", "ent=input()\r\nd,l,v1,v2=ent.split()\r\nprint((float(l)-float(d))/(float(v1)+float(v2)))", "d, l , v1, v2 = map(int, input().split())\r\nprint((l - d)/(v1 + v2))", "read = lambda: map(int, input().split())\r\nd, L, v1, v2 = read()\r\nans = (L - d) / (v1 + v2)\r\nprint(ans)\r\n", "# coding=utf8\r\n\r\nif __name__ == '__main__':\r\n line = str(input()).split()\r\n line = [int(it) for it in line]\r\n print((line[1] - line[0]) / (line[2] + line[3]))\r\n", "a ,a1 ,b ,b1 = map(int ,input() .split())\r\nprint((a1 - a) / (b + b1))\r\n", "d, l, v, u = tuple(map(int, input().split()))\r\nprint('%0.9f' % ((l - d) / (u + v)))", "def time(d,l,v1,v2):\r\n\tx = ((v1*(l-d))/(v1+v2))\r\n\treturn (x/v1)\r\n\t\r\nif __name__ == '__main__':\r\n\r\n d,l,v1,v2 = map(int,input().split(' '))\r\n print (round((time(d,l,v1,v2)),6))\r\n \r\n \r\n", "d, l, a, b = map(int, input().split())\r\ndis = l - d\r\nbase = a + b\r\nans = dis / base\r\nprint(ans)", "a = [float(i) for i in input().split()]\r\nprint((a[1]-a[0])/(a[2]+a[3]))\r\n", "#for _ in range(int(input())):\r\na,b,c,d=map(int,input().split())\r\ndis=b-a\r\nl=c+d\r\nprint(dis/l)", "class CodeforcesTask624ASolution:\n def __init__(self):\n self.result = ''\n self.d_l_v_v = []\n\n def read_input(self):\n self.d_l_v_v = [int(x) for x in input().split(\" \")]\n\n def process_task(self):\n time = (self.d_l_v_v[1] - self.d_l_v_v[0]) / (self.d_l_v_v[2] + self.d_l_v_v[3])\n self.result = str(time)\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask624ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n", "d, l, v1, v2 = map(int, input().split())\r\nl -= d\r\nprint(l / (v1 + v2))", "a= input(\"\").split(' ')\r\nd= int(a[0])\r\nL= int(a[1])\r\nv1= int(a[2])\r\nv2= int(a[3])\r\nv= v1+v2\r\nL= L-d\r\nt= L/v\r\nprint(t)", "x = list(map(int, input().split()))\r\nprint((x[1]-x[0])/(x[2]+x[3]))", "d, l, v, u = map(int, input().split())\r\nprint((l - d) / (v + u))", "d, l, v1, v2 = map(int, input().split())\r\nt = (l - d) / (v1 + v2)\r\nprint(float(t))", "d, L, v1, v2 = [int(s) for s in input().split(\" \")]\r\nans = (L-d)/(v1+v2)\r\nprint(ans)", "d, l, v1, v2 = [int(i) for i in input().split()]\r\nprint(str((l - d) / (v1 + v2)))", "s = lambda: list(map(int,input().split()))\r\n\r\nval = s()\r\n\r\nprint((val[1]-val[0])/(val[2]+val[3]))", "#n = int(input())\n#n, m = map(int, input().split())\n#s = input()\nc = list(map(int, input().split()))\nprint((c[1] - c[0]) / (c[2] + c[3]))", "w, p2, v1, v2 = map(int, input().split())\r\np1 = 0\r\np2 -= w\r\n\r\nprint(p2/(v1+v2))", "s=input().split()\r\n\r\nprint('{0:.6f}'.format((float(s[1])-float(s[0]))/(float(s[2])+float(s[3]))))\r\n", "print((lambda a: (a[1]-a[0])/sum(a[2:]))(list(map(int,input().split()))))", "string = input(\"\")\r\nvals = string.split()\r\nans = float((float(vals[1])-float(vals[0]))/(float(vals[2]) + float(vals[3])))\r\nprint (ans)", "inp = list(map(int,input().split()))\r\nd=inp[0]\r\nl=inp[1]\r\nv1=inp[2]\r\nv2=inp[3]\r\nif(l<d):\r\n print(0.00000000)\r\nelse:\r\n print((l-d)/(v1+v2))", "d,l,v1,v2=map(int,input().split())\r\nans=(l-d)/float(v1+v2)\r\nprint(ans)", "d, l, v1, v2 = map(int, (input().split()))\r\n\r\nans = (l-d)/(v1+v2)\r\n\r\nprint(ans)\r\n", "d,l,v1,v2=map(int,input().split())\r\nd=l-d\r\nv=v1+v2\r\nprint(f'{d/v:.20f}')\r\n", "d,L,v1,v2 = list(map(int , input().split()))\r\nprint('{:.20f}'.format((L-d)/(v1+v2)))", "import sys\r\nimport math\r\nimport bisect\r\nimport itertools\r\nimport random\r\n\r\ndef main():\r\n d, l, v1, v2 = map(int, input().split())\r\n ans = (l - d) / (v1 + v2)\r\n print('%.10f' % ans)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "d,L,v1,v2=input().split(\" \")\r\nprint((float(L)-float(d))/(float(v1)+float(v2)))\r\n\r\n", "# Coded By Block_Cipher\r\n\r\nimport math\r\nimport os\r\nimport random\r\nimport re\r\nimport sys\r\nfrom math import gcd\r\nfrom math import sqrt\r\nfrom collections import Counter\r\n\r\nd,l,v1,v2 = list(map(int,input().split()))\r\nprint('%.20f'%((l-d)/(v1+v2)))\r\n\r\n", "d,l,a,b=map(int,input().split())\r\na=(l-d)/(a+b)\r\nprint(a)", "d,l,v,u=map(int,input().split())\r\nprint((l-d)/(v+u))\r\n ", "d,l,v1,v2=map(int,input().split())\r\nif(d>=l):\r\n print(1)\r\nelse:\r\n print((l-d)/(v1+v2))", "def main():\n d, L, v1, v2 = map(int, input().split(\" \"))\n print((L-d)/(v1+v2))\n\n\nif __name__ == '__main__':\n main()", "d,l,v1,v2=map(int,input().split())\r\nprint(float((l-d)/(v1+v2)))", "d, L, v_1, v_2 = list(map(float, input().split()))\nprint((L - d) / (v_1 + v_2))\n", "if __name__ == \"__main__\":\r\n\r\n d , L , v1 , v2 = map(float,input().split())\r\n print((L-d)/(v1+v2))", "d, L, v1, v2 = map (int, input().split() )\r\nv = v1+v2\r\nl = L-d\r\nt = l/v \r\nprint (t)", "d,l,v1,v2=list(map(int,input().split()))\r\nl=l-d\r\nv1=v1+v2\r\nt=l/v1\r\nprint(t)\r\n", "d,l,v1,v2 = [int(x) for x in input().split()]\r\nans = (l-d)/(v1+v2)\r\nprint(ans)", "d,l,v1,v2=list(map(int,input().split()))\r\n\r\np=v1+v2\r\nk=(v1*(l-d))/p\r\n\r\n\r\nprint(round(k/v1,6))\r\n", "R = lambda : map(int, input().split())\nd,L,v1,v2 = R()\nprint((L-d)/(v2+v1))", "d,l,v1,v2 = map(int,input().split())\r\nprint((l - d)/(v1+v2))", "width, right, v1, v2=map(int, input().split())\r\nleft=0;t=0\r\n \r\n##Here distance between the blocks are decreased at a speed of v1+v2##\r\n \r\nd=right-width\r\nv=v1+v2\r\n \r\n##The required distance to decrease will be right(L)-0, and Luke has a width, the distance travelled by presses would be L-d\r\n##[Simple Physics] \r\nprint(d/v)", "d,L,v1,v2=(int(z) for z in input().split())\r\nprint((L-d)/(v1+v2))", "f=lambda:map(int,input().split())\r\nd,l,v1,v2=f()\r\nprint((l-d)/(v1+v2))", "'''\r\nCreated on Apr 28, 2016\r\n\r\n@author: Md. Rezwanul Haque\r\n'''\r\n\r\nd,L,v1,v2 = map(int,input().split())\r\nans = (L-d)/(v1+v2)\r\nprint(ans)", "d,l,v,u=map(int,input().split())\r\nx=(v*(l-d))/(v+u)\r\nans=x/v\r\nprint (\"%.6f\"%ans)", "from math import *\r\n\r\nd,l,v1,v2 = map(int,input().split())\r\nprint(max(0,(l-d)/(v1+v2)))", "INPUT = input().split(' ')\r\nd = int(INPUT[0])\r\nL = int(INPUT[1])\r\nv1 = int(INPUT[2])\r\nv2 = int(INPUT[3])\r\nresult = (L - d) / (v1 + v2)\r\nprint(result)\r\n\r\n", "#Mian_Talha\r\n#624/problem/A\r\na,b,c,d = map(int,input().split())\r\nS1 =abs(a-b)\r\nS2 = c+d\r\nprint(S1/S2)\r\n", "strLine = input()\r\nlistSplit = strLine.split()\r\nd = int(listSplit[0])\r\nL = int(listSplit[1])\r\nv1 = int(listSplit[2])\r\nv2 = int(listSplit[3])\r\nres = (L - d) / (v1 + v2)\r\nprint('{0:.6f}'.format(res))\r\n", "d,l,a,b=map(int,input().split())\r\nprint((l-d)/(a+b))", "d,L,v1,v2=map(int,input().split(' '))\r\nprint('{0:.8f}'.format((L-d)/(v1+v2)))\r\n", "#!/usr/bin/python3\n\nimport math\n\ndef main():\n\td,L,v1,v2 = [int(i) for i in input().split()]\n\n\tv = v1+v2\n\tt = (L-d) / v\n\n\tprint(t)\n\nif __name__ == '__main__':\n\tmain()", "m=list(map(int,input().split()))[:4]\r\nif (m[0]<m[1]):\r\n h=((m[1]-m[0])/(m[3]+m[2]))\r\nelse:\r\n h=0\r\nprint(h)\r\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\nd, L, v1, v2 = map(int, input().split(\" \")) # read multiple integers into different variables\r\nans = (L - d) / (v1 + v2)\r\nprint(ans)\r\n", "d, l, v1, v2 = map(int, input().split())\nl -= d\nif (l <= 0):\n print(0.0)\nelse:\n print(l/(v1+v2))\n", "import re\r\nst = input()\r\ns = re.split(r'[\\s]', st)\r\nd = int(s[0])\r\nL = int(s[1])\r\nv1 = int(s[2])\r\nv2 = int(s[3])\r\nprint ((L - d) / (v1 + v2))", "a, b, c, d = map(int, input().split())\r\n\r\nprint(\"%.10f\" % max(0, (b- a) / (c + d)))", "from math import *\r\n\r\narr = [int(i) for i in input().split()]\r\n\r\nres = (arr[1]-arr[0])/(arr[2]+arr[3])\r\n\r\nprint('%.12f'%res)\r\n", "k=list(map(int,input().split()));print((k[1]-k[0])/(sum(k[2:])))", "d,L,v1,v2=map(int,input().split())\r\n\r\nt=(L-d)/(v1+v2)\r\n\r\nprint('{0:.9f}'.format(t))", "n = input().split()\r\na = int(n[0])\r\nb = int(n[1])\r\nc = int(n[2])\r\nd = int(n[3])\r\n\r\nsub = (b-a)\r\nadd = (c+d)\r\nprint(sub/add)\r\n", "d, l, v1, v2 = map(int, input().split())\r\nprint(round((l-d)/(v1+v2), 16))", "n=input().split()\r\na=int(n[0])\r\nb=int(n[1])\r\nc=int(n[2])\r\nk=int(n[3])\r\nprint(float((b-a)/(c+k)))\r\n", "d, l, v1, v2 = map(int, input().split())\r\n\r\ndistance = l - d\r\ntime = v1 + v2\r\nans = distance / time\r\nprint(\"%.10f\" % ans)", "d,l,v1,v2=[int(i) for i in input().split()]\ntime=(l-d)/(v1+v2)\nprint(time)\n", "d, L, v1, v2 = map(int, input().split())\r\nl = 0\r\nr = 100000000000000000\r\ne = 0.0000000001\r\nwhile (r - l > e):\r\n c = (r + l) / 2\r\n if v1 * c >= L - v2 * c:\r\n r = c\r\n elif (L - v2 * c) - v1 * c <= d:\r\n r = c\r\n else:\r\n l = c\r\nprint(l)", "d, L, v1, v2 = map(int, input().split())\r\na = round(((L-d)/(v1+v2)), 15)\r\nprint(a)", "# Description of the problem can be found at http://codeforces.com/problemset/problem/624/A\r\n\r\nd, L, v1, v2 = map(int, input().split())\r\n\r\nprint((L - d) / (v1 + v2))", "import sys\n\nd, l, v1, v2 = map(int, sys.stdin.readline().split())\nans = (l - d) / (v1 + v2)\nprint(ans)\n", "d,l,v1,v2=[int(x) for x in input().split()]\r\nprint(round((l-d)/(v1+v2),10))", "\r\n\r\ndef main(args):\r\n\t\r\n\tentrada = list(map(int, input().split()))\r\n\td = entrada[0]\r\n\tL = entrada[1]\r\n\tv1 = entrada[2]\r\n\tv2 = entrada[3]\r\n\t\r\n\ttotalv = v1 + v2\r\n\ts = L-d\r\n\tresult = (0.0 + s)/totalv\r\n\tprint(result)\r\n\treturn 0\r\n\r\nif __name__ == '__main__':\r\n import sys\r\n sys.exit(main(sys.argv))\r\n", "x,y,w,z = map(int, input().split())\r\nprint (round(((y-x)/(w+z)),20))\r\n", "[D, L, V_1, V_2] = [int(x) for x in input().split()]; print((L-D)/(V_1+V_2))", "# import sys\r\n# sys.stdin=open(\"input.in\",'r')\r\n# sys.stdout=open(\"output.out\",'w')\r\nd,l,v1,v2=map(int,input().split())\r\nx=(l-d)/(v1+v2)\r\nprint(\"%.20f\"%x)", "d,l,v1,v2=map(int,input().split(' '))\r\nt=(l-d)/(v1+v2)\r\nprint('%.8f'%t)\r\n", "# LUOGU_RID: 95395172\nd,l,v1,v2 = map(float, input().split())\r\ne = float((l-d)/(v1+v2))\r\nprint(\"{:.20f}\".format(e))", "a,b,c,d=map(int,input().split())\r\nprint((abs(a-b))/(c+d))\r\n\r\n", "(d,l,v1,v2)=list(map(int,input().split()))\r\nprint(abs(l-d)/(v1+v2))", "d,l,v1,v2 = input().split()\r\nd=int(d)\r\nl=int(l)\r\nv1=int(v1)\r\nv2=int(v2)\r\nprint((float)(l-d)/(v1+v2))", "d,l,v1,v2 = map(int,input().split())\r\nprint(\"%.20f\"%((l-d)/(v1+v2)))", "import math\n\n\ndef solve(a):\n d = a[1] - a[0]\n d1 = a[2] + a[3]\n return d / d1\n\nprint(\"%.8f\" % solve([int(n) for n in input().split()]))\n", "l=list(map(int,input().split()))\r\nd,l,v1,v2=l[0],l[1],l[2],l[3]\r\nx=((l-d)/(v1+v2))\r\nprint(x)\r\n", "D, L, V1, V2 = [int(c) for c in input().split()]\r\nprint((L - D) / (V1 + V2))\r\n", "d, l, u, v = map(int, input().split())\r\nprint((l - d) / (u + v))\r\n", "d,L,v1,v2=[int(x) for x in input().split()]\r\na=(L-d)/(v1+v2)\r\nprint(format(a,'.6f'))\r\n", "__author__ = 'Admin'\r\nd, L, v1, v2 = map(int, input().split())\r\nans = (L - d)/(v1+v2)\r\nprint(ans)", "x,y,z,t=map(int,input().split())\r\nprint((y/(z+t))-(x/(z+t)))", "d, L, v1, v2 = [int(x) for x in input().split()]\r\nt = ((L - d) * v1 / (v1 + v2)) / v1\r\nprint(t)", "d, L, v1, v2 = map(int, input().split())\nans = (L - d) / (v1 + v2)\nprint(ans)\n", "readInts=lambda: map(int, input().split())\r\n\r\na,b,c,d=readInts()\r\n\r\nprint((b-a)/(c+d))", "d,l,x,y=map(int,input().split())\r\nprint((l-d)/(x+y))\r\n", "l1=[int(i) for i in input().split()]\r\nt=(l1[1]-l1[0])/(l1[2]+l1[-1])\r\nprint(t)", "text = input()\r\n\r\nlarg, p2, v1, v2 = text.split()\r\n\r\ndist = int(p2) - int(larg)\r\n\r\nvt = int(v1) + int(v2)\r\n\r\nres = dist/vt\r\n\r\nprint(\"%.20f\" %res)\r\n" ]
{"inputs": ["2 6 2 2", "1 9 1 2", "1 10000 1 1", "9999 10000 10000 10000", "1023 2340 1029 3021", "2173 2176 10000 9989", "1 2 123 1", "123 1242 12 312", "2 9997 3 12", "1 10000 10000 10000", "3274 4728 888 4578", "4600 9696 5634 8248", "2255 7902 8891 429", "6745 9881 2149 9907", "4400 8021 6895 2089", "5726 9082 7448 3054", "3381 9769 4898 2532", "1036 6259 5451 4713", "5526 6455 197 4191", "1196 4082 4071 9971", "8850 9921 8816 9449", "3341 7299 2074 8927", "7831 8609 6820 2596", "2322 7212 77 4778", "9976 9996 4823 4255", "7631 9769 5377 6437", "8957 9525 8634 107", "6612 9565 3380 2288", "1103 6256 3934 9062", "1854 3280 1481 2140"], "outputs": ["1.00000000000000000000", "2.66666666666666650000", "4999.50000000000000000000", "0.00005000000000000000", "0.32518518518518519000", "0.00015008254539996998", "0.00806451612903225780", "3.45370370370370370000", "666.33333333333337000000", "0.49995000000000001000", "0.26600804976216613000", "0.36709407866301685000", "0.60590128755364803000", "0.26011944260119441000", "0.40304986642920748000", "0.31955817939440107000", "0.85975773889636609000", "0.51387249114521838000", "0.21171376481312670000", "0.20552627830793335000", "0.05863673692855187600", "0.35978547404781386000", "0.08262531860662701600", "1.00720906282183310000", "0.00220312844238819110", "0.18097172845776197000", "0.06498112344125385500", "0.52099505998588569000", "0.39650661742074483000", "0.39381386357359843000"]}
UNKNOWN
PYTHON3
CODEFORCES
241
195a674edfdb1beb7260a34b31fe41f6
Weird Game
Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·*n* binary characters "0" or "1". After that the players start moving in turns. Yaroslav moves first. During a move, a player must choose an integer from 1 to 2·*n*, which hasn't been chosen by anybody up to that moment. Then the player takes a piece of paper and writes out the corresponding character from his string. Let's represent Yaroslav's word as *s*<==<=*s*1*s*2... *s*2*n*. Similarly, let's represent Andrey's word as *t*<==<=*t*1*t*2... *t*2*n*. Then, if Yaroslav choose number *k* during his move, then he is going to write out character *s**k* on the piece of paper. Similarly, if Andrey choose number *r* during his move, then he is going to write out character *t**r* on the piece of paper. The game finishes when no player can make a move. After the game is over, Yaroslav makes some integer from the characters written on his piece of paper (Yaroslav can arrange these characters as he wants). Andrey does the same. The resulting numbers can contain leading zeroes. The person with the largest number wins. If the numbers are equal, the game ends with a draw. You are given two strings *s* and *t*. Determine the outcome of the game provided that Yaroslav and Andrey play optimally well. The first line contains integer *n* (1<=≤<=*n*<=≤<=106). The second line contains string *s* — Yaroslav's word. The third line contains string *t* — Andrey's word. It is guaranteed that both words consist of 2·*n* characters "0" and "1". Print "First", if both players play optimally well and Yaroslav wins. If Andrey wins, print "Second" and if the game ends with a draw, print "Draw". Print the words without the quotes. Sample Input 2 0111 0001 3 110110 001001 3 111000 000111 4 01010110 00101101 4 01100000 10010011 Sample Output First First Draw First Second
[ "ii=lambda:int(input())\r\nkk=lambda:map(int,input().split())\r\nll=lambda:list(kk())\r\nn,a1,a2=ii(),input(),input()\r\nlocs = [0]*4\r\nfor i in range(2*n):\r\n\tlocs[int(a1[i])+2*int(a2[i])]+=1\r\nrm = min(locs[1],locs[2])\r\nlocs[1]-=rm\r\nlocs[2]-=rm\r\nlocs[3]=locs[3]&1\r\nif locs[1]:\r\n\tprint(\"First\")\r\nelse:\r\n\tif locs[3]:\r\n\t\tif locs[2]==0:\r\n\t\t\tprint(\"First\")\r\n\t\telif locs[2]<3:\r\n\t\t\tprint(\"Draw\")\r\n\t\telse:\r\n\t\t\tprint(\"Second\")\r\n\telse:\r\n\t\tif locs[2]<2:\r\n\t\t\tprint(\"Draw\")\r\n\t\telse:\r\n\t\t\tprint(\"Second\")", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\n\\r\")\r\n\r\ndef solve():\r\n n = int(input()) \r\n s = list(map(int, input()))\r\n t = list(map(int, input()))\r\n dic = {'00': 0, '01': 0, '10': 0, '11': 0}\r\n for i in range(2 * n):\r\n dic[str(s[i]) + str(t[i])] += 1\r\n \r\n first = {0: 0, 1: 0}\r\n second = {0: 0, 1: 0}\r\n \r\n for i in range(n):\r\n if dic['11'] > 0:\r\n dic['11'] -= 1\r\n first[1] += 1\r\n elif dic['10'] > 0:\r\n dic['10'] -= 1\r\n first[1] += 1\r\n elif dic['01'] > 0:\r\n dic['01'] -= 1\r\n first[0] += 1\r\n else:\r\n dic['00'] -= 1\r\n first[0] += 1\r\n \r\n if dic['11'] > 0:\r\n dic['11'] -= 1\r\n second[1] += 1\r\n elif dic['01'] > 0:\r\n dic['01'] -= 1\r\n second[1] += 1\r\n elif dic['10'] > 0:\r\n dic['10'] -= 1\r\n second[0] += 1 \r\n else:\r\n dic['00'] -= 1\r\n second[0] += 1\r\n \r\n if first[1] > second[1]:\r\n print('First')\r\n elif first[1] < second[1]:\r\n print('Second')\r\n else:\r\n print('Draw')\r\n\r\nfor _ in range(1):\r\n solve()\r\n\r\n ", "import sys\nimport bisect\ntry:\n\tfin = open('in')\nexcept:\n\tfin = sys.stdin\ninput = lambda: fin.readline().strip()\n\nn=int(input())\na=list(map(int,input()))\nb=list(map(int,input()))\nr=[[0,0],[0,0]]\nfor i in range(2*n):\n\tr[a[i]][b[i]] += 1\nt=[0]*2\nfor i in range(2*n):\n\tj=i%2\n\tif r[1][1]>0:\n\t\tr[1][1]-=1\n\t\tt[j]+=[1,1][j]\n\telif r[0][1]>0:\n\t\tr[0][1]-=1\n\t\tt[j]+=[0,1][j]\n\telif r[1][0]>0:\n\t\tr[1][0]-=1\n\t\tt[j]+=[1,0][j]\n\telse:\n\t\tr[0][0]-=1\n\t\tt[j]+=[0,0][j]\nx,y=t\nif x>y:print(\"First\")\nelif x<y:print(\"Second\")\nelse:print(\"Draw\")", "# https://codeforces.com/problemset/problem/293/A\n\nn = int(input())\nS = list(map(int, input()))\nT = list(map(int, input()))\n\ntypes = [0] * 4\nfor s, t in zip(S, T):\n types[s * 2 + t] += 1\n\nyaroslav = 0\nandrey = 0\n\nfor turn in range(2 * n):\n '''\n 1. Always optimal to take 3 (11) first so you benefit and make the other guy lose.\n 2. Yaroslav tries to take 2 (10) first. Andrey tries to take 1 (01) first.\n 3. If no 2 or 1 left in their favor, take from other guy.\n 3. Take 0 (00) since no one benefits at this point.\n '''\n\n # Yaroslav's turn\n if turn % 2 == 0: \n if types[3] > 0:\n types[3] -= 1\n yaroslav += 1\n elif types[2] > 0:\n types[2] -= 1\n yaroslav += 1\n elif types[1] > 0:\n types[1] -= 1\n else:\n types[0] -= 1\n # Andrey's turn\n else: \n if types[3] > 0:\n types[3] -= 1\n andrey += 1\n elif types[1] > 0:\n types[1] -= 1\n andrey += 1\n elif types[2] > 0:\n types[2] -= 1\n else:\n types[0] -= 1\n\nif yaroslav > andrey:\n print('First')\nelif yaroslav == andrey:\n print('Draw')\nelse:\n print('Second')", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\ns = input()\r\nt = input()\r\n\r\nd = {\"00\": 0, \"01\": 0, \"10\": 0, \"11\": 0}\r\nfor i in range(2 * n):\r\n d[s[i] + t[i]] += 1\r\n\r\nfirst_ones = 0\r\nsecond_ones = 0\r\n\r\nfor r in range(n):\r\n # first player\r\n for v in [\"11\", \"10\", \"01\", \"00\"]:\r\n if d[v] > 0:\r\n d[v] -= 1\r\n first_ones += int(v[0])\r\n break\r\n # second player\r\n for v in [\"11\", \"01\", \"10\", \"00\"]:\r\n if d[v] > 0:\r\n d[v] -= 1\r\n second_ones += int(v[1])\r\n break\r\n\r\nif first_ones > second_ones:\r\n print(\"First\")\r\nelif first_ones == second_ones:\r\n print(\"Draw\")\r\nelse:\r\n print(\"Second\")\r\n", "n = int(input())\na, b = input(), input()\nt = {i + j: 0 for i in '01' for j in '01'}\nfor i in range(2 * n): t[a[i] + b[i]] += 1\nd = t['11'] & 1\nd += (t['10'] - t['01'] + 1 - d) // 2\nif d > 0: d = 1\nelif d < 0: d = 2\nprint(['Draw', 'First', 'Second'][d])", "n=int(input());a,b=input(),input();t={i+j:0 for i in'01'for j in'01'}\r\nfor i in range(2*n):t[a[i]+b[i]]+=1\r\nd=t['11']&1;d+=(t['10']-t['01']+1-d)//2\r\nif d>0:d=1\r\nelif d<0:d=2\r\nprint(['Draw', 'First', 'Second'][d])", "from sys import stdin\r\nfrom math import ceil, floor\r\nn = int(input())\r\ns = stdin.readline()\r\nt = stdin.readline()\r\nfirst = 0\r\nsecond = 0\r\ndraw = 0\r\nfor i in range(2*n):\r\n\tif( s[i] == '1' and t[i] == '1' ): draw += 1\r\n\telif( s[i] == '1' ): first += 1\r\n\telif( t[i] == '1' ): second += 1\r\n\r\n#print( first, second, draw )\r\nif( first > second ):\r\n\tif( draw%2 == 1 ): first -= ceil( (first-second)/2 )\r\n\telse: first -= (first-second) - ceil( (first-second)/2 )\r\n\r\nelif( second > first ):\r\n\tif( draw%2 == 1 ): second -= (second-first) - ceil( (second-first)/2 ) \r\n\telse: second -= ceil( (second-first)/2 )\r\n#print( first, second, draw )\r\n\r\nfirst += ceil(draw/2.0)\r\nsecond += (draw - ceil(draw/2.0))\r\n\r\n#print( first, second, draw )\r\nif( first > second ): print( \"First\" )\r\nelif( second > first ): print( \"Second\" )\r\nelse: print(\"Draw\")" ]
{"inputs": ["2\n0111\n0001", "3\n110110\n001001", "3\n111000\n000111", "4\n01010110\n00101101", "4\n01100000\n10010011", "4\n10001001\n10101101", "3\n000000\n000100", "2\n0000\n1110", "4\n11111111\n10100110", "4\n10100111\n11011000", "4\n00101011\n11110100", "4\n11000011\n00111100", "4\n11101111\n01000110", "4\n01110111\n00101110", "4\n11011111\n10110110", "4\n01101010\n11111110", "4\n01111111\n10011001", "4\n01010100\n10011111", "4\n01111011\n01001011", "4\n11011010\n11011001", "4\n11001101\n10001010", "4\n01101111\n10111101", "4\n10111100\n00000101", "4\n01111000\n11111010", "4\n11001100\n00000111", "4\n01110111\n10101101", "4\n01001000\n11111100", "4\n01011011\n01010010", "4\n00101101\n01001001", "4\n00110110\n10000100", "4\n10010000\n01000110", "4\n00000100\n10001111", "4\n01110100\n01110100", "4\n11000001\n11010001", "4\n11001000\n00011000", "4\n10110011\n01011111", "4\n10000100\n11010100", "4\n01011011\n10101110", "10\n00000000000111111111\n00000000011111111111", "1\n11\n11", "1\n11\n00", "1\n00\n01", "2\n0111\n1001", "1\n01\n11"], "outputs": ["First", "First", "Draw", "First", "Second", "Draw", "Draw", "Second", "First", "First", "Draw", "Draw", "First", "First", "First", "Second", "First", "Second", "First", "Draw", "First", "Draw", "First", "Second", "First", "First", "Second", "First", "First", "First", "Draw", "Second", "Draw", "Draw", "First", "Draw", "Second", "Draw", "Draw", "Draw", "First", "Draw", "First", "Draw"]}
UNKNOWN
PYTHON3
CODEFORCES
8
19652a10a291705df6b35df2213433ea
Random Teams
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition. The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. Sample Input 5 1 3 2 6 3 Sample Output 10 10 1 1 3 6
[ "n,m = map(int,input().split())\r\ntemp = n-(m-1)\r\nkmax = (temp*(temp-1))//2 \r\na = n//m \r\ntemp1 = m*(a*(a-1))//2 + a*(n%m) \r\nprint(temp1,kmax)", "n,m=map(int,input().split())\r\nr=n//m\r\nprint(m*r*(r-1)//2+n%m*r,(n-m+1)*(n-m)//2)", "n, m = map(int, input().split())\na = n // m\nb = n % m\nprint((m * a * (a - 1) // 2) + b * a, (n - m + 1) * (n - m) // 2)\n\n \t\t \t\t\t\t \t\t \t \t\t \t \t", "# Solution here\ndef solve(tt):\n n, m = __list(int)\n mx = nc2(n-m+1)\n mn = (n % m) * nc2(n//m + 1) + (m - n % m) * nc2(n//m)\n print(mn, mx)\n\n\ndef nc2(x):\n return x*(x-1)//2\n\n\ndef main():\n t = 1\n # t = __int()\n for tt in range(1, t + 1):\n solve(f\"{tt}: -------------\")\n return\n\n\nclass IntKeyDict(dict):\n from random import randrange\n rand = randrange(1 << 62)\n def __setitem__(self, k, v): super().__setitem__(k ^ self.rand, v)\n def __getitem__(self, k): return super().__getitem__(k ^ self.rand)\n def __contains__(self, k): return super().__contains__(k ^ self.rand)\n def __repr__(self): return str({k: v for k, v in self.items()})\n def get(self, k, default=None): return super().get(k ^ self.rand, default)\n def keys(self): return [k ^ self.rand for k in super().keys()]\n def items(self): return [(k ^ self.rand, v) for k, v in super().items()]\n\n\ndef dbg(*args):\n from inspect import currentframe, getframeinfo\n from re import search\n debug = lambda *args, end=\"\\n\": stderr.write(\n \" \".join([str(x) for x in args]) + end)\n frame = currentframe().f_back\n s = getframeinfo(frame).code_context[0]\n r = search(r\"\\((.*)\\)\", s).group(1)\n var_name = r.split(\", \")\n stderr.write(\"\\n\")\n prefix = f\"{currentframe().f_back.f_lineno:02d}) \"\n stderr.write(prefix)\n for var, val in zip(var_name, args):\n debug(f\"{var} = {val}\")\n\n\nif __name__ == \"__main__\":\n from sys import stdin, stderr, stdout, maxsize\n from math import *\n from bisect import *\n from collections import Counter, deque, defaultdict as dd\n from heapq import nsmallest, nlargest, heapify, heappop, heappush\n def input(): return stdin.buffer.readline().decode().rstrip()\n def __int(): return int(input())\n def __list(dtype): return list(map(dtype, input().split()))\n print = lambda *args, end=\"\\n\", sep=\" \": stdout.write(\n sep.join(map(str, args)) + end\n )\n main()\n", "n, m = map(int, input().split())\r\na = n // m\r\nb = n % m\r\nmaksa = n - m + 1\r\nans1 = maksa*(maksa - 1) // 2\r\nans2 = b * (a+1)*a // 2 + (m-b)*a*(a-1) // 2\r\nprint(ans2, ans1)", "def c(n):return ((n-1)*n)//2\r\nn,m=map(int, input().split())\r\nh=(n+m-1)//m\r\nprint(c(h)*(m+n-h*m)+c(h-1)*(h*m-n),c(n-m+1))", "m,n = map(int,input().split())\r\nif m%n == 0:\r\n maxi = ((m-n+1)*(m-n))//2\r\n if n == 1:\r\n mini = maxi\r\n else:\r\n mini = (((m//n)*(m//n-1))//2)*n\r\nelif m > n and m%n != 0:\r\n f = m%n\r\n s = (m-f)//n\r\n d = n-f\r\n #print(f,s,d)\r\n if s == 0:\r\n mini = f\r\n else:\r\n mini = f*(((s+1)*s)//2) + (n-f)*((s*(s-1))//2)\r\n maxi = ((m-n+1)*(m-n))//2\r\nprint(mini,maxi)", "from math import *\r\n\r\na = input()\r\na = a.split(\" \")\r\n\r\nb = list(a)\r\nfor i in range(len(b)):\r\n b[i] = int(b[i])\r\n\r\nc = floor(b[0]/b[1])\r\nd = c + 1 \r\nkmin = ((c*(c-1)) // 2)*(b[1]-(b[0]-c*b[1])) + ((d*(d-1)) // 2)*(b[0]-c*b[1])\r\nprint(kmin,end=\" \")\r\n\r\ne = b[0] - b[1] + 1\r\nkmax = (e*(e-1)) // 2\r\nprint(kmax)\r\n", "n,m=map(int,input().split())\r\nt2 = (n-(m-1))*(n-(m-1)-1)//2\r\nl=[]\r\n# print(t,end=\" \")\r\nif(m==1):\r\n print(n*(n-1)//2,n*(n-1)//2)\r\nelse:\r\n y = n//m\r\n t1=0\r\n if(n%m!=0):\r\n t1=(n%m)*((y+1)*(y))//2\r\n t1+=(m-n%m)*(y*(y-1))//2\r\n print(t1,t2)", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\n\r\na = n//m\r\nb = n%m\r\nc = n-m+1\r\nif b == 0:\r\n print(m*a*(a-1)//2, c*(c-1)//2)\r\nelse:\r\n print(b*(a+1)*a//2 + (m-b)*a*(a-1)//2, c*(c-1)//2)", "n, m = map(int,input().split())\r\n\r\ndef sum_prog(k):\r\n return k * (k - 1) // 2\r\n\r\nans1 = 0\r\nans2 = 0\r\n\r\ntemp = n % m\r\nans1 += sum_prog( n // m ) * (m - temp)\r\nans1 += sum_prog( n // m + 1) * temp\r\n\r\n\r\nans2 += sum_prog( n - m + 1 )\r\n\r\nprint(int(min(ans1, ans2)), int(max(ans1, ans2)) )\r\n", "def nc2_(n):\r\n if n <= 1:\r\n return 0\r\n return n*(n-1)//2\r\nn, m = [int(i) for i in input().split()]\r\nmini = nc2_(n//m+1)*(n%m) + nc2_(n//m) * (m - (n%m))\r\nprint(mini, end = ' ')\r\nmaxi = n-m+1\r\nprint(maxi*(maxi-1)//2)", "def solve():\r\n n, m = map(int, input().split())\r\n if n == m: # 没有组\r\n print(\"0 0\")\r\n return\r\n mx = (n - m + 1) * (n - m) // 2\r\n \r\n r = (n - m) % m\r\n d = (n - m) // m # 增加的层数\r\n \r\n mn = r * (d + 2) * (d + 1) // 2 + (m - r) * (d + 1) * d // 2\r\n print(\"%d %d\" % (mn, mx))\r\n \r\nsolve()", "from math import floor\n#\nn, m = map(int, input().split())\n\nparticipantes = n - (m - 1)\nmaximo = (participantes * (participantes -1)) // 2\n\nparticipantes2 = floor(n / m)\nparticipantes3 = n % m\nminimo = participantes3 * ((participantes2 + 1) * participantes2)// 2 + (m - participantes3) * (participantes2 * (participantes2 - 1)) // 2\n\nprint(minimo, maximo)\n\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\na = n // m\r\nb = n % m\r\nc = n - m + 1\r\nprint((m - b) * (a * (a - 1) // 2) + b * (a * (a + 1)) // 2, end=' ')\r\nprint(c * (c - 1) // 2)\r\n", "n,m=map(int,input().split())\r\nma=(n-m)*(n-m+1)//2\r\nmi=(m*(n//m-1)+(n%m)*2)*(n//m)//2 \r\nprint(mi,ma)\r\n", "n, m = map(int, input().split())\n \nmax = n - (m-1)\nmax = max*(max-1)//2\n \nval1 = n//m\nmin = (val1*(val1-1)//2)*(m-(n%m))\n \nmin += ((val1+1)*(val1)//2)*(n%m)\n \nprint(min, max)\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 = n - (m-1)\r\nlargest = ((a-1)*a) // 2\r\ndefult = n//m\r\ndefultPlusOneAmount = n%m\r\nsmallest = (defultPlusOneAmount * (((defult+1)*defult)//2)) + ((m-defultPlusOneAmount) * (((defult-1)*defult)//2))\r\nprint(smallest, largest)", "import math\n\nn, m = map(int, input().split())\n\nkmax = (n-m)*(n-m+1)//2\n\nkmin = (n % m) * (n//m) * (n//m+1) // 2 + (m-n % m) * (n//m) * (n//m-1) // 2\nprint(kmin, kmax)\n", "#import math\r\nn,m= map(int,input().split())\r\nprint(m*(n//m)*((n//m)-1) //2 + (n//m) * (n%m) ,((n-(m-1)-1))*((n-(m-1)+1)-1)//2)\r\n", "n,m=map(int,input().split())\r\nmax1=(n-m+1)*(n-m)//2\r\na=n//m;b=n%m\r\nmin1=(m-b)*(a-1)*a//2+b*(a+1)*a//2\r\nprint(min1,max1)", "n,m = map(int,input().split())\r\nmx = ((n-m+1)*(n-m))//2\r\nk = n//m\r\nmn = k*(k - 1) // 2 * (m - n % m) + k*(k + 1) // 2 * (n % m)\r\n\r\nprint(mn, mx)", "n, m = map(int, input().split())\n \nmaxi = n - (m-1)\nmaxi = maxi*(maxi-1)//2\n \nval = n//m\nmini = (val*(val-1)//2)*(m-(n%m))\n \nmini += ((val+1)*(val)//2)*(n%m)\n \nprint(mini, maxi)\n\t\t \t \t\t \t \t \t \t \t\t\t\t\t\t \t \t", "n,m=list(map(int,input().split()))\r\nkmax=(n-m)*(n-m+1)//2\r\nkmin=(m-n%m)*((n//m)*(n//m-1)//2)+(n%m)*((n//m+1)*(n//m)//2)\r\n\r\nprint(kmin,kmax)", "n, m = map(int,input().split())\r\nprint((((m - n%m)*(n//m)*(n//m -1) // 2) + (n%m)*(n//m + 1)*(n//m) //2), end= \" \")\r\nprint((n - m +1)*(n -m)//2)", "def calculate_min_max_counts():\r\n n_input, m_input = map(int, input().split())\r\n\r\n x = n_input // m_input\r\n remainder = n_input % m_input\r\n\r\n a = x + 1\r\n b = x\r\n min_count = (a * (a - 1) if remainder else 0) * remainder // 2 + \\\r\n (b * (b - 1) if x > 1 else 0) * (m_input - remainder) // 2\r\n max_count = (n_input - m_input + 1) * (n_input - m_input) // 2\r\n\r\n return min_count, max_count\r\n\r\nresult = calculate_min_max_counts()\r\nprint(result[0], result[1])\r\n", "def get_score(n):\r\n return (n*(n-1))//2\r\n\r\nn,m = map(int,input().split(' '))\r\nmini = 0\r\nmaxi = 0\r\nif n%m == 0:\r\n n_ = n//m\r\n mini = get_score(n_)*m\r\n n__ = n - m + 1\r\n maxi = get_score(n__)\r\nelse:\r\n a = n//m\r\n b = n%m\r\n mini = get_score(a+1)*b + get_score(a)*(m-b)\r\n n__ = n - m + 1\r\n maxi = get_score(n__)\r\nprint(mini,maxi)", "import sys\r\n\r\nn, m = map(int, sys.stdin.readline().split())\r\n\r\nbiggest_team = n - (m - 1)\r\nmost_friends = biggest_team * (biggest_team - 1) // 2\r\n\r\neven_team_size, remainder = divmod(n, m)\r\n\r\nn1 = remainder\r\ns1 = even_team_size + 1\r\nn2 = m - remainder\r\ns2 = even_team_size\r\n\r\nleast_friends = (n1 * s1 * (s1 - 1) + n2 * s2 * (s2 - 1)) // 2\r\n\r\nprint(least_friends, most_friends)", "n, m = map(int, input().split())\n\ndef count(n): return n * (n - 1) // 2\n\nmini = count(n - m + 1)\n\nrest = n % m\n\nall = rest * count(n//m + 1) + (m - rest) * count(n//m)\n\nprint(all, mini)", "from math import comb\r\nn,m = map(int, input().split())\r\nr = n%m\r\nq = n//m\r\nprint((m-r)*comb(q,2)+r*comb(q+1,2),comb(n+1-m,2))", "from math import comb\r\n\r\n\r\ndef calc_min(n, m):\r\n time_maior = n // m\r\n resto = n % m\r\n\r\n pares_maior = comb(time_maior, 2)\r\n pares_menor = comb(time_maior + 1, 2)\r\n\r\n return resto * pares_menor + (m - resto) * pares_maior\r\n\r\n\r\ndef calc_max(n, m):\r\n return comb(n - (m - 1), 2)\r\n\r\n\r\nn, m = map(int, input().split())\r\n\r\ntime_menor = calc_min(n, m)\r\ntime_maior = calc_max(n, m)\r\n\r\nprint(time_menor, time_maior)\r\n", "\r\ndef fun(ls):\r\n members , teams = ls\r\n\r\n # for max pair all teams have 1 member and last team has remaining member\r\n rem = (members - (teams - 1))\r\n maxx = (rem * (rem - 1))//2\r\n\r\n # for min pair divide members equally\r\n remainder = members % teams\r\n rem = (members//teams)\r\n minn = ( (rem*(rem-1))//2 ) * (teams) + (rem)*remainder\r\n\r\n print(minn, maxx)\r\n\r\nT = 1\r\nfor i in range(T):\r\n ls= list(map(int, input().split()))\r\n fun(ls)\r\n\r\n\r\n", "r=list(map(int,input().split()))\r\nv=sum(range(1,r[0]-r[1]+1))\r\nm1=0\r\nif r[0]%r[1]==0:\r\n m1 = (((r[0] // r[1] + 1) * (r[0] // r[1])) // 2) * (r[0] % r[1]) + (\r\n ((r[0] // r[1]) * (r[0] // r[1] - 1)) // 2) * (r[1] - r[0] % r[1])\r\n #m=sum(range(1,r[0]//r[1]))*r[1]\r\nelse:\r\n m1=(((r[0]//r[1]+1)*(r[0]//r[1]))//2)*(r[0]%r[1])+(((r[0]//r[1])*(r[0]//r[1]-1))//2)*(r[1]-r[0]%r[1])\r\n #m=sum(range(1,r[0]//r[1]+1))*(r[0]%r[1])+sum(range(1,r[0]//r[1]))*(r[1]-r[0]%r[1])\r\nprint(m1,v)", "def t(n):\r\n return (n*(n-1))//2\r\ndef solve():\r\n n,m = list(map(int,input().split()))\r\n return sorted([t(n - m + 1),t(n//m+1)*(n % m)+t(n//m)*(m - n % m)])\r\nprint(*solve())", "n, m = map(int, input().split())\n\naverage, remainder = divmod(n, m)\nkmin = average * (average - 1) // 2 * (m - remainder) + (average + 1) * average // 2 * remainder\nkmax = (n - m + 1) * (n - m) // 2\n\nprint(f\"{kmin} {kmax}\")", "n,m=map(int,input().split())\r\na=n//m\r\nprint( m*a*(a-1)//2+a*(n%m) , (n-m)*(n-m+1)//2 )", "from math import comb \r\nn,m = map(int,input().split())\r\nmn = comb(n//m,2)*(m - (n%m)) + comb(n//m+1,2) * (n%m) \r\nMn = comb(n-m+1,2)\r\nprint(mn,Mn)", "def no_of_ways(n):\r\n if n < 2:\r\n return 0\r\n return n * (n - 1) // 2\r\n \r\nn, m = map(int, input(). split())\r\nmore = n % m\r\nless = m - more\r\nprint(more * no_of_ways((n // m) + 1) + less * no_of_ways(n // m), no_of_ways(n - m + 1))", "\nnum, m = map(int, input().split())\nmax = num -(m-1)\nmax = max*(max-1)//2\nval1 = num//m\nmin = (val1* (val1-1)//2)* (m- (num%m))\nmin += ((val1+1)* (val1)//2)* (num%m)\nprint (min, max)\n \t\t\t \t \t \t\t \t \t\t \t\t \t\t\t", "def pairs(n):\r\n return n * (n - 1) // 2\r\n\r\ndef main():\r\n n, m = map(int, input().split())\r\n a, b = divmod(n, m)\r\n min_val = pairs(a) * (m - b) + pairs(a + 1) * b\r\n max_val = pairs(n - m + 1)\r\n print(min_val, max_val)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "a, b = map(int, input().split())\nquotient = a // b\nremaining = a % b\nsum_of_pairs = b * quotient * (quotient - 1) // 2 + quotient * remaining\nsum_of_sequence = (a - b + 1) * (a - b) // 2\nprint(sum_of_pairs, sum_of_sequence)\n \t\t\t \t \t\t \t\t \t\t \t \t\t\t\t\t\t", "n,m = list(map(int,input().split()))\r\ndef nC2(n):\r\n\tif(n < 2):\r\n\t\treturn 0\r\n\treturn (n * (n - 1) // 2)\r\n\t\r\nminofpairs = (m - n % m) * (nC2(n//m)) + (n % m) * (nC2(n//m + 1))\r\nmaxofpairs = nC2(n - m + 1)\r\n\r\nprint(minofpairs,maxofpairs)", "n, m = map(int, input().split())\r\nprint(\"{} {}\".format(((n//m)*((n//m)-1)) // 2 * (m - (n%m)) + (((n//m)+1) * (n // m)) // 2 * (n % m), ((n - m + 1) * ((n - m + 1) - 1)) // 2))", "import math\r\nn,m = tuple(map(int, input().split()))\r\nmx = ((n-m+1)*(n-m))//2\r\nx = n//m\r\ny = n%m\r\nmn = 0\r\nif x>1:\r\n mn = ((m-y) * (x*(x-1))) // 2\r\nx += 1\r\nmn += (y * (x*(x-1))) // 2\r\n\r\nprint(mn, mx)", "\na,b=map(int,input().split())\nr=a%b\nc=a//b\nd=a-b\nprint((b-r)*c*(c-1)//2+r*(c+1)*c//2,d*(d+1)//2)\n \t\t \t\t \t \t \t\t \t \t\t \t\t \t", "n,m = map(int,input().split())\r\nk = n//m\r\nprint(m*k*(k-1)//2+k*(n%m), (n-m+1)*(n-m)//2)", "n,m=map(int, input().split())\r\ncount=0\r\nif m==1:\r\n count=(n*(n-1))/2\r\n print(str(int(count))+' '+str(int(count)))\r\nelif n%m==0:\r\n a=int(n/m)\r\n p=(a*(a-1))//2\r\n min=int(p*m)\r\n a=n-m+1\r\n max=(a*(a-1))//2\r\n print(str(min)+' '+str(max))\r\nelse:\r\n a=int(n/m)\r\n if a>1:\r\n count=(a*(a-1))/2\r\n a=int((n-int(n/m)*(m-(n%m)))/(n%m))\r\n p=(a*(a-1))/2\r\n min=int((m-(n%m))*count+(n%m)*p)\r\n a=n-m+1\r\n max=((a-1)*a)//2\r\n print(str(min)+' '+str(max))\r\n \r\n ", "def pairs_of_team(n):\n return n * (n - 1) // 2\n\nn, m = map(int, input().split())\na, b = n // m, n % m\nminimum = pairs_of_team(a) * (m - b) + pairs_of_team(a + 1) * b\nmaximum = pairs_of_team(n - m + 1)\nprint(minimum, maximum)\n\n \t\t\t \t\t\t \t \t \t\t\t \t \t\t", "n,m=[int(i) for i in input().split()]\r\nmaxi=(n-m)*(n-m+1)//2\r\ne=n-((n//m)*m)\r\nmini=int(e*(n//m)*(n//m+1)/2+(m-e)*(n//m-1)*(n//m)/2)\r\nprint(mini,maxi)", "num_items,group_size=map(int,input().split())\ns=num_items//group_size;b=num_items%group_size;a=group_size-b\nmax_pairs=(num_items-group_size+1)*(num_items-group_size)//2\nmin_pairs=a*s*(s-1)//2+b*s*(s+1)//2\nprint(min_pairs,max_pairs)\n\t\t\t \t\t \t \t \t \t\t \t \t\t\t \t \t\t", "n, m = [int(x) for x in input().split()]\nprint(((n%m)*(n//m) + m*(n//m-1)*(n//m)//2),(n-m+1)*(n-m)//2)\n\n\t\t\t \t\t \t\t \t\t\t\t \t\t \t\t \t \t \t", "import sys\r\n\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nYES = 'YES'\r\nNO = 'NO'\r\n\r\n\r\ndef print(*args, sep=' ', end='\\n'):\r\n sys.stdout.write(sep.join(map(str, args)) + end)\r\n\r\n\r\ndef si():\r\n return input()\r\n\r\n\r\ndef ii():\r\n return int(input())\r\n\r\n\r\ndef lsi():\r\n input().split()\r\n\r\n\r\ndef lii():\r\n return list(map(int, input().split()))\r\n\r\n\r\n##################################################################################\r\n\r\n\r\ndef main():\r\n n, m = lii()\r\n big_team = n - (m - 1)\r\n max_friends = (big_team - 1) * (big_team) // 2\r\n t2 = (n // m + 1)\r\n c2 = n % m\r\n t1 = n // m\r\n c1 = m - c2\r\n min_friends = c2 * ((t2 - 1) * (t2) // 2) + c1 * ((t1 - 1) * (t1) // 2)\r\n print(min_friends, max_friends)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nfrom collections import Counter\r\nimport math\r\n\r\nN,M = map(int, input().split())\r\nka = math.comb(N-M+1,2)\r\n\r\na = N//M\r\nt = N%M\r\n\r\nki = math.comb(a+1,2)*t+math.comb(a,2)*(M-t)\r\nprint(ki,ka)\r\n", "import math\r\n\r\nN,M = map(int, input().split())\r\n\r\ndef cal(A):\r\n\tans = 0\r\n\tfor a in A:\r\n\t\ta-=1\r\n\t\tif a>0:\r\n\t\t\tans += (a+1)*a//2\r\n\r\n\treturn ans\r\n\r\nans = [0,0]\r\na = N//M\r\nif a>1:\r\n\tans[0] += (a-1)*a//2*(M-N%M)\r\nif N%M:\r\n\ta += 1\r\n\tans[0] += (a-1)*a//2*(N%M)\r\n\r\na = N-M+1\r\nans[1] = (a-1)*a//2\r\n\r\nprint(*ans)\r\n", "n, m = map(int, input().split())\nx = n - m + 1\n\nx -= 1\nmax_val = x * (x + 1) // 2\n\nrem = n % m\nx = n // m\n\ny = x + 1\nmin_val = y * (y - 1) // 2 * rem\n\ny = m - rem\nmin_val += x * (x - 1) // 2 * y\n\nprint(min_val, max_val)\n\n\n\t \t \t \t\t\t \t \t\t \t\t", "n,m = map(int,input().split())\r\n\r\nq = n//m\r\nr = n%m\r\n\r\nkmin = ((q+1)*(q)*r)//2 + ((q)*(q-1)*(m-r))//2\r\nkmax = ((n-m+1)*(n-m))//2\r\n\r\nprint(int(kmin),int(kmax))\r\n", "import sys\r\nimport math\r\ninput = sys.stdin.readline\r\n\r\nif __name__ == '__main__':\r\n n, m = map(int, input().split())\r\n temp = n - (m-1)\r\n ans1 = temp*(temp-1) // 2\r\n temp = n // m\r\n ans2 = m * (temp * (temp - 1) // 2)\r\n if n % m != 0:\r\n ans2 += (n % m)*temp\r\n\r\n print(min(ans1, ans2), max(ans1, ans2))", "#https://codeforces.com/problemset/problem/478/B\r\ndef pair_of_friends(number):\r\n return ((number-1)*(number))//2\r\n\r\n(n, m) = (int(x) for x in input().split())\r\nmin_value = n//m\r\nleftover = n%m\r\nmax_pairs = pair_of_friends(n-m+1)\r\nmin_pairs = pair_of_friends(min_value)*(m-leftover) + pair_of_friends(min_value + 1)*leftover\r\nprint(str(min_pairs) + \" \" + str(max_pairs))\r\n", "from math import comb, ceil\n\nn, m = map(int, input().split())\nresto = n % m\ntime_menor = (resto * comb(n // m + 1, 2)) + ((m - resto) * comb(n // m, 2))\ntime_maior = comb(n - (m - 1), 2)\n\nprint(time_menor, time_maior)\n\t \t\t \t \t\t\t\t\t \t\t \t\t\t", "n,m=list(map(int,input().split()))\r\nif m>1:\r\n x=n-m+1\r\n # print(x)\r\n max=x*(x-1)//2\r\n evenly=n//m\r\n rem=n%m\r\n a1=evenly*(evenly-1)//2\r\n a2=evenly*(evenly+1)//2\r\n min=(a1*(m-rem))+(a2*rem)\r\n\r\nelse:\r\n min=max=n*(n-1)//2\r\n\r\nprint(min,max)", "n,m=map(int,input().split())\r\n# divide n equally to m teams\r\nperTeam=n//m\r\nleftParticipants=n%m\r\n#give every left participant in a particular team\r\nminK=leftParticipants*(perTeam+1)*(perTeam)//2 + (m-leftParticipants)*(perTeam-1)*perTeam//2\r\nprint(minK,end=\" \")\r\nmaxK=(n-m+1)*(n-m)//2\r\nprint(maxK)", "def friends(n):\n return n * (n-1) >> 1\n\n\ndef get_mini(players, teams):\n small = players//teams\n big = small+1\n big_count = players % teams\n small_count = teams-big_count\n return small_count*friends(small)+big_count*friends(big)\n\n\ndef get_maxi(players, teams):\n return friends(players-teams+1)\n\n\nplayers, teams = map(int, input().split())\nprint(get_mini(players, teams), get_maxi(players, teams))\n", "def solve():\n N, M = map(int, input().split(' '))\n if N == M:\n print(0, 0)\n return \n mx = N-M+1\n mn = N//M\n ans = 0\n if N%M != 0:\n r = N%M\n x = M-r\n while r:\n ans += ((mn+1)*mn)//2\n r -= 1\n ans += x * (mn * (mn-1))//2\n \n else:\n ans = M * (mn * (mn-1))//2\n print(ans, mx*(mx-1)//2)\n\n\nsolve()", "import math\n\nn, m = map(int, input().split())\n\nf = n // m\nr = n % m\n\nansMin = (m - r) * math.comb(f, 2) + r * math.comb(f + 1, 2)\nansMax = math.comb(n - (m - 1), 2)\n\nprint(ansMin, ansMax)\n \t\t\t\t \t \t\t\t\t\t \t\t \t\t\t\t \t", "k, m = map(int, input().split())\n \nmax = k - (m-1)\nmax = max*(max-1)//2\n \nval1 = k//m\nmin = (val1*(val1-1)//2)*(m-(k%m))\n \nmin += ((val1+1)*(val1)//2)*(k%m)\n \nprint(min, max)\n \t\t\t\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", "n, m = map(int, input().split())\r\nm1 = m - n % m\r\nm2 = n % m\r\nn1 = n // m\r\nn2 = n // m + 1\r\n# print(m1,m2,n1,n2)\r\nwn1 = n1*(n1-1)//2\r\nwn2 = n2*(n2-1)//2\r\n# print(wn1,wn2,wn1*m1,wn2*m2)\r\nmin = wn1*m1 + wn2*m2\r\n# print(min)\r\nmax = n - (m-1)\r\nmx = (max * (max-1)) // 2\r\nprint(min,mx)", "n, m = map(int, input().split())\r\n\r\nk1 = ((n - m + 1) * (n - m)) // 2\r\nk2 = 0\r\n\r\nif n % m == 0:\r\n k = n // m\r\n k2 = m * (k * (k - 1)) // 2\r\nelse:\r\n k = n // m\r\n k2 = (n % m) * (k * (k + 1)) // 2 + (m - (n % m)) * (k * (k - 1)) // 2\r\n\r\nprint(*sorted([k1, k2]))\r\n", "n,m = list(map(int, input().split(' ')))\r\n\r\ndef nc2(x):\r\n ans = 1\r\n for i in range(1,3):\r\n ans *= (x-i+1)\r\n ans = ans//i\r\n return ans\r\nkmax = n-m+1 \r\n#find kmax C 2 = kmax! % (kmax-2)! x 2!\r\n\r\nkmax = nc2(kmax)\r\nans = 0\r\nextra = n - (n//m)*m\r\n# print(extra)\r\ntemp = nc2((n//m) + 1)\r\nans += (temp*extra)\r\ntemp = nc2(n//m)\r\nans += temp*(m-extra)\r\nprint(int(ans), int(kmax))\r\n# 1000000000 1000000\r\n# Output\r\n# 499500000000 499000500499500032\r\n# Answer\r\n# 499500000000 499000500499500000", "n, m = input().split()\nn = int(n)\nm = int(m)\nmin, max = 0, 0\na, b = divmod(n, m)\n\nif b == 0:\n min = m * a * (a - 1) // 2\nelse:\n min = (m - b) * a * (a - 1) // 2 + b * a * (a + 1) // 2\n\nmax = (n - m + 1) * (n - m) // 2 \n\nprint(min, max)\n\t \t \t\t \t \t\t \t\t\t\t\t \t\t\t \t\t\t\t \t", "from math import ceil\r\n\r\nn, k = map(int, input().split())\r\nmax_, min_ = n - k + 1, ceil(n / k)\r\nwha = n//k\r\nm_ans, mi_ans,oo = 1, 1,1\r\nfor i in range(max_ - 1, max_ + 1):\r\n m_ans *= i\r\nfor i in range(min_ - 1, min_ + 1):\r\n mi_ans *= i\r\nfor i in range(wha-1,wha+1):\r\n oo *= i\r\n\r\nprint(mi_ans // 2*(n%k)+oo//2*(k-n%k),m_ans // 2)\r\n", "import sys\r\nfrom collections import Counter\r\nmod = pow(10, 9) + 7\r\nmod2 = 998244353\r\ndef data(): return sys.stdin.readline().strip()\r\ndef out(var): sys.stdout.write(str(var)+\"\\n\")\r\ndef outa(*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\n\r\n\r\nn, m = sp()\r\ntemp = n - m + 1\r\nmaxi = temp * (temp - 1) // 2\r\ntemp = n // m\r\nmini = temp * (temp - 1) // 2 * (m - (n % m))\r\nmini += temp * (temp + 1) // 2 * (n % m)\r\nouta(mini, maxi)\r\n", "from math import floor\n\n\ndef fat(n):\n if n == 0:\n return 1\n else:\n return n * fat(n - 1)\n\n\ndef calc(a, b):\n if b > a:\n return 0\n return fat(a) // (fat(b) * fat(a - b))\n\n\nn, m = map(int, input().split())\n\nmember = n - (m - 1)\nmaxi = (member * (member - 1)) // 2\nmember2, member3 = floor(n / m), n % m\nminimo = member3 * ((member2 + 1) * member2) // 2 + (m - member3) * (member2 * (member2 - 1)) // 2\n\nprint(minimo, maxi)\n\n \t \t \t\t\t\t \t\t \t \t\t\t\t\t \t \t \t", "import math\r\n\r\nn, m = map(int, input().split())\r\n\r\nans_max = math.comb((n - m + 1), 2)\r\n\r\nequals = int(n / m)\r\n\r\nadd = n % m\r\n# print(equals, add)\r\n\r\nans_min = (math.comb(equals, 2) * (m - add)) + (math.comb(equals + 1, 2) * add)\r\n\r\nprint(ans_min, ans_max)", "import math\r\n\r\nn, m = list(map(int, input().split(\" \")))\r\n\r\nif n == m:\r\n print(0, 0)\r\nelse:\r\n ma = int(math.comb(n-m+1, 2))\r\n\r\n l = int(n/m)\r\n remainder = int((n/m - int(n/m)) * m+0.5)\r\n\r\n\r\n\r\n mi = math.comb(l+1, 2) * remainder\r\n mi += math.comb(l, 2) * (m-remainder)\r\n print(mi, ma)", "tokens = input().split(' ')\nn = int(tokens[0])\nm = int(tokens[1])\n\nequal_dist = n // m\nremainder = n - (equal_dist * m)\nbig_groups = remainder\nsmall_groups = m - big_groups\npeople_in_big_groups = equal_dist + 1\npeople_in_small_groups = equal_dist\n\nminimum = 0\nminimum += big_groups * ((people_in_big_groups * (people_in_big_groups - 1)) // 2)\nminimum += small_groups * ((people_in_small_groups * (people_in_small_groups - 1)) // 2)\n\nsingle_groups = m - 1\npeople_in_big_group = n - single_groups\nmaximum = (people_in_big_group * (people_in_big_group - 1)) // 2\n\nprint(minimum, maximum)", "from math import comb\n\n\ndef min_max_friends_pairs(n, m):\n min_pairs = 0\n max_pairs = 0\n\n eq_team_size = n // m\n left_out = n % m\n\n # para os times que foram adicionados os que ficaram de fora\n # o tamanho é aumentado de 1\n min_pairs += left_out * comb(eq_team_size + 1, 2)\n\n # para os times que ficaram do tamanho dividido igual (m - left_out),\n # simplesmente somar a combinação em 2 desses\n min_pairs += (m - left_out) * comb(eq_team_size, 2)\n\n # a divisao de time para obter maior quantidade de pares deve ser a\n # mais desigual possível (todos com 1 e o último time com o restante)\n max_team_size = n - (m - 1)\n max_pairs += comb(max_team_size, 2)\n \n return min_pairs, max_pairs\n \nn, m = map(int, input().split())\nmini, maxi = min_max_friends_pairs(n, m)\nprint(mini, maxi)\n\n \t \t \t\t \t\t\t\t \t\t \t\t \t \t", "controls = list(map(int, input().split()))\nactual = controls[0] - controls[1] +1 \nbest = actual * (actual - 1) // 2\n\n\nnumberPior = int(controls[0]// controls[1])\nrest = controls[0] % controls[1]\nequals = controls[1] - rest \n\n\nminor = (numberPior * (numberPior-1) // 2 * equals) + ((numberPior+1) * (numberPior) // 2 * rest)\n\nprint(int(minor), int(best))\n\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\nx = n - (m - 1)\r\nmaximo = (x * (x - 1)) // 2\r\n\r\nx = n % m\r\ny = n // m\r\nminimo = (m-x) * (y * (y - 1)) // 2 + x * (y * (y + 1)) // 2\r\n\r\nprint(minimo,maximo)\r\n\r\n", "def s(n):\r\n return (n*(n+1))//2\r\n\r\nn, m = map(int, input().split())\r\n\r\nkmin = min(s(n - m), s(n//m)*(n%m) + s((n//m)-1)*(m - n%m))\r\nkmax = max(s(n - m), s(n//m)*(n%m) + s((n//m)-1)*(m - n%m))\r\n\r\nprint(kmin, kmax)\r\n", "n,m=map(int,input().split())\r\nprint((m-n%m)*(n//m)*(n//m-1)//2 + (n%m)*(n//m+1)*(n//m)//2, (n-m+1)*(n-m)//2 )", "n, m = [int(x) for x in input().split()]\nx = n // m\ny = n - m + 1\nkmin = (x * (x-1) * m) // 2 + x * (n % m)\nkmax = (y * (y-1)) // 2\nprint(round(kmin), round(kmax))\n", "class Solution:\r\n def solve(self, n, m):\r\n maximum = (n-m) + 1\r\n minimum = n // m\r\n remaining = n % m\r\n k_min = (m - remaining) * minimum * (minimum - 1) // 2\r\n k_min += remaining * minimum * (minimum + 1) // 2\r\n k_max = maximum * (maximum - 1) // 2\r\n print(k_min, k_max)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n a, b = tuple(map(int, input().split()))\r\n t = Solution()\r\n t.solve(a, b)\r\n", "n,m = map(int,input().split())\r\nif n == m:\r\n print('0 0')\r\n\r\nelse:\r\n kmax = ((n-m + 1)*(n-m))//2\r\n if n%m == 0:\r\n each = n//m\r\n kmin = m*( (n//m) * (n//m -1))//2\r\n else:\r\n x = n//m\r\n a = n%m\r\n kmin = a*((x+1)*(x))//2\r\n kmin += (m-a)*((x)*(x-1))//2\r\n \r\n print(str(kmin) + ' ' + str(kmax) )", "import math\r\n\r\ndef f(n):\r\n return (n*(n-1))//2\r\n\r\n\r\nn, m = map(int, input().split())\r\n\r\nr1 = f(math.ceil(n/m))*(n%m) + f(n//m)*(m-n%m)\r\nr2 = f(n-m+1)\r\nprint(r1, r2)\r\n\r\n ", "n,m=map(int,input().split())\r\nkm=(n//m)\r\nc=(n%m)\r\ny=(km*(km+1)//2)*c\r\nkm=(m-c)*(km*(km-1)//2)+y\r\nprint(km,end=\" \")\r\nkl=(n-m)*(n-m+1)//2\r\nprint(kl)", "n,m=map(int,input().split())\r\ns=n//m;b=n%m;a=m-b\r\nans_max=(n-m+1)*(n-m)//2\r\nans_min=a*s*(s-1)//2+b*s*(s+1)//2\r\nprint(ans_min,ans_max)", "L=input().split()\r\na=int(L[0])\r\nb=int(L[1])\r\nmax=(a-b+1)*(a-b)//2\r\nmin=(a%b)*(a//b+1)*(a//b)//2+(b-a%b)*(a//b)*(a//b-1)//2\r\nprint(min,max)", "def f(k):\n return k*(k-1)//2\nn,m=map(int,input().split())\nprint(f(n//m+1)*(n%m)+f(n//m)*(m-n%m),f(n-m+1))\n \t\t \t \t\t\t \t\t \t \t\t\t\t \t\t\t", "n, m = map(int, input().split())\r\nx = n - m + 1\r\nr = n % m\r\na = (m - r) * ((n // m) * (n // m - 1)) // 2 + r * ((n // m + 1) * (n // m)) // 2\r\nprint(a, (x * (x - 1)) // 2)", "def C2(n):\n return (n * (n - 1)) >> 1\n\nn,m = list(map(int,input().split()))\nmaxFriends = C2(n-(m-1))\nif m == 1:\n print(f\"{maxFriends} {maxFriends}\")\nelse:\n # para o pior caso : n%m grupos com (n//m + 1) participantes, (m-n%m) grupos com n//m participantes\n q = n // m\n rm = n % m\n numFriends1 = rm * C2(q+1)\n numFriends2 = (m-rm) * C2(q)\n minFriends = numFriends1 + numFriends2\n print(f\"{minFriends} {maxFriends}\") \n \t\t\t \t \t\t\t \t \t \t \t", "n,m=map(int,input().split())\r\na=n//m\r\nb=n%m\r\nif b==0:b=m\r\nc=(n+m-1)//m\r\nd=m-b\r\n# print(a,b,c,d)\r\nprint(d*(a*(a-1)//2)+b*(c*(c-1)//2),(n-m)*(n-m+1)//2)", "n,m = list(map(int,input().split()))\r\nmx = ((n-m+1)*(n-m))//2\r\no = n%m\r\nmn = ((n//m)*(n//m+1) * o + (n//m)*(n//m-1)*(m-o))//2\r\nprint(mn,mx)", "n, m = map(int, input().split())\r\nmincom = n // m\r\naddcom = n % m\r\nkmin = mincom * (mincom - 1) * (m - addcom) // 2 + (mincom + 1) * mincom * addcom // 2\r\nbigcom = n - m + 1\r\nkmax = bigcom * (bigcom - 1) // 2\r\nprint(kmin, kmax)\r\n", "n,m=map(int, input().split())\r\n\r\nn-=m\r\nkmax=n*(n+1)//2\r\nq=n//m\r\nr=n%m\r\nkmin=r*(q+1)*(q+2)//2 + (m-r)*q*(q+1)//2\r\nprint(kmin, kmax)", "n,m = map(int,input().split())\r\n\r\nif m==1:\r\n print(n*(n-1)//2,n*(n-1)//2)\r\n exit()\r\n\r\nif n==2 and m==2:\r\n print(0,0)\r\n\r\n exit()\r\n\r\nmaxP = (n-m+1)*(n-m)//2\r\n\r\nif n%m == 0:\r\n minP = n*(n//m - 1)//2\r\nelse:\r\n r = n%m\r\n minP = (m-r)*(n//m)*(n//m - 1)//2 + (r)*(n//m + 1)*(n//m)//2 # m-r has n//m people and r has n//m +1 people\r\n\r\n\r\n\r\nprint(minP,maxP)", "def pairs(n):\n return n * (n - 1) // 2\n\nn, m = map(int, input().split())\na, b = n // m, n % m\nminimum = pairs(a) * (m - b) + pairs(a + 1) * b\nmaximum = pairs(n - m + 1)\nprint(minimum, maximum)\n\n \t\t \t \t\t \t \t\t \t\t \t\t \t \t \t", "from math import *\r\n\r\nn,m = map(int,input().split())\r\nx = n//m\r\nr = n%m\r\n\r\nkmin = (x*(x-1)//2)*(m-r) + ((x+1)*(x)//2)*r\r\n\r\ny = n - m + 1\r\nkmax = y*(y-1)//2\r\nprint(kmin,kmax)", "def value(v):\r\n return v * (v - 1) // 2\r\n\r\n\r\nn, m = map(int, input().split())\r\n\r\nmin_value = value(n // m) * m + (n % m) * (n // m)\r\nmax_value = value(n - m + 1)\r\nprint(min_value, max_value)\r\n", "'''I = lambda: [int(i) for i in input().split()]\r\nimport io, os, sys,math\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline'''\r\n\r\n#n,k = map(int,input().split())\r\nn,m = map(int,input().split())\r\nx = n-(m-1)\r\nmaxi= (x*(x-1))//2\r\n\r\neqi = n//m\r\nre = n%m\r\ne = (m-re)*((eqi*(eqi-1))//2)\r\nr = (re)*(((eqi)*(eqi+1))//2)\r\nprint(e+r,maxi)\r\n", "n, m = map(int, input().split())\r\nx = n//m\r\nprint(m*x*(x-1)//2+x*(n%m), (n-m+1)*(n-m)//2)\r\n", "import sys\r\ninput = sys.stdin.readline\r\ndef comb(x:int)->int:\r\n return x*(x-1)//2\r\nn, m = map(int,input().split())\r\nmx = comb(n-(m-1))\r\nmn = comb(n//m + 1)*(n%m) + (m - n%m)*comb(n//m)\r\nprint(mn,mx)", "from math import comb \r\n\r\ndef factorial(n):\r\n cnt = 1\r\n for i in range(1,n+1):\r\n cnt*=i \r\n return cnt \r\n\r\ndef calculate(nv):\r\n cnt = 0\r\n lst = [1]*nv\r\n return len(list(comb(lst,2))) \r\n\r\nn,m = map(int,input().split())\r\nmx = comb(n-(m-1),2)\r\nif(n==m):\r\n print(0,0)\r\nelif(n%m==0):\r\n print(comb(n//m,2)*m,mx)\r\nelse:\r\n s = n//m \r\n r = n%m \r\n ns = m -r \r\n nss = r \r\n\r\n print(comb(s,2)*ns+comb(s+1,2)*nss,mx)\r\n", "from math import ceil\n \ndef MinimumMaximumPairs(n, m) :\n \n max_pairs = ((n - m + 1) * (n - m)) // 2;\n \n min_pairs = (m * (((n - m) // m + 1) *\n ((n - m) // m)) // 2 +\n ceil((n - m) / (m)) *\n ((n - m) % m))\n print(f\"{min_pairs} {max_pairs}\")\n \nn, m = map(int, input().split())\nMinimumMaximumPairs(n, m)\n \t\t\t \t\t\t \t \t\t \t\t \t \t\t\t\t \t\t", "n, m = [int(i) for i in input().split()]\r\nk = n - m + 1\r\na, b, c, d = m - n % m, n // m, n % m, n // m + 1\r\nprint(a * (b * (b - 1)) // 2 + c * (d * ( d - 1)) // 2, (k * (k - 1)) // 2)", "def s_p(st, fn):\r\n return (st + fn) * (fn - st+1)//2\r\n\r\n\r\nn, m = map(int, input().split())\r\nmx, mn = 0, 0\r\nmx = s_p(1, n - m)\r\nq = n // m\r\nw = n % m\r\nmn += s_p(1, q)*w\r\nmn += s_p(1, q-1)*(m-w)\r\nprint(mn, mx)\r\n", "from math import ceil,comb\r\nn,m=[int(x) for x in input().split()]\r\n\r\nprint((m-n%m)*comb((n//m),2)+(n%m)*comb(ceil(n/m),2),comb(n-m+1,2))", "import math\n\nstr = input().split()\npeople = int(str[0])\ngroup = int(str[1])\n\n\ndef conb(n, r):\n if n == r:\n return 1\n elif n < r:\n return 0\n else:\n for i in range(1, r):\n n *= n - i\n for i in range(1, r):\n r *= r - i\n return n // r\n\n\ndiv = people // group\nmod = people % group\n\nmin = mod * conb(div + 1, 2) + (group - mod) * conb(div, 2)\n\nmax = conb(people - group + 1, 2)\n\nprint(min, max)\n\n\t\t \t \t \t\t \t\t\t \t \t\t\t \t \t", "n,m=map(int,input().split())\r\nr=n//m\r\nprint(int(m*(r*(r-1))//2 + r*(n%m)),end=' ')\r\nprint(int((n-(m-1))*(n-(m-1)-1)//2))\r\n\r\n\r\n\r\n", "n, m = map(int, input().split())\r\nc = m * (n // m) * (n // m - 1) // 2\r\nc += (n % m) * (n // m)\r\nmx = (n - m + 1) * ((n - m + 1) - 1) // 2\r\nprint(c, mx)", "import sys\r\nimport io, os\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\nn,m=input().split()\r\nn=int(n)\r\nm=int(m)\r\nx=n//m\r\ny=n-m*x\r\na=((x)*(x-1)//2)*(m-y)\r\nb=((x)*(x+1)//2)*(y)\r\nprint(a+b,end=' ')\r\nc=n-(m-1)\r\nprint((c*c-c)//2)\r\nprint('')", "import math\r\nfrom collections import OrderedDict\r\nimport heapq\r\nfrom collections import deque\r\nimport sys\r\ndef mpp():return map(int,inp().split())\r\ndef lis():return list(mpp())\r\ndef inp(): return input()\r\ndef sol(n,m):\r\n new=n-0\r\n kmin=int(1e9)\r\n Kmax=0\r\n if m==1:\r\n return (n*(n-1)//2,n*(n-1)//2)\r\n n=n-(m-1)\r\n kmax=n*(n-1)//2\r\n \r\n n=new\r\n gp=n//m\r\n rem=n-gp*m\r\n #print(n,gp,m)\r\n kmin=(gp*(gp-1)*(m-rem)//2)+rem*(gp+1)*(gp)//2\r\n return (kmin,kmax) \r\ndef main():\r\n n,m=mpp()\r\n print(*sol(n,m))\r\nif __name__==\"__main__\":\r\n main()", "n,m=map(int,input().split())\r\nprint((n//m+1)*(n//m)//2*(n%m)+(n//m)*(n//m-1)//2*(m-n%m),(n-m+1)*(n-m)//2)", "import math\nimport heapq\n\ndef solve(x, y):\n if x ==y: return 0, 0\n k_max = (x-y+1)*(x-y)//2\n z = x//y \n n_z1 = x-z*y \n n_z = y-n_z1 \n k_min = n_z*(z-1)*z//2 + n_z1*(z+1)*z//2\n return k_min, k_max\n\n# T = int(input())\n# for t in range(T):\nx, y = list(map(int, input().split()))\nres = solve(x, y)\nprint(*res)\n", "def count(a):\r\n return (a*(a-1))//2\r\n\r\n\r\nn, m = map(int, input().split())\r\nprint(\"{} {}\".format(count(n//m) * (m - (n%m)) + count((n//m) + 1) * (n%m), count(n - m + 1)))\r\n", "n,m=map(int,input().split())\r\ndef c(n):\r\n return (n**2-n)//2\r\nt1=n%m\r\nt2=m-t1\r\nmx=t1*c(n//m+1)+t2*c(n//m)\r\nmi=c(n-m+1)\r\nprint(mx,mi)\r\n", "def pairs_of_team(n):\n return n * (n - 1) // 2\n\ndef main():\n n, m = map(int, input().split())\n a, b = divmod(n, m)\n mn = pairs_of_team(a) * (m - b) + pairs_of_team(a + 1) * b\n mx = pairs_of_team(n - m + 1)\n print(mn, mx)\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 \t\t\t\t", "# https://codeforces.com/problemset/problem/478/B\r\n\r\nm, n = map(int, input().split())\r\nmx = (m - n + 1) * (m - n) // 2\r\nif m % n == 0:\r\n mn = (m // n) * (m // n - 1) // 2 * n\r\nelse:\r\n c = m % n\r\n mn = (m // n) * (m // n - 1) // 2 * (n - c) + (m // n + 1) * (m // n) // 2 * c\r\nprint(f\"{mn} {mx}\")", "def soma(n):\n return n * (n - 1) // 2\n\nn, m = map(int,input().split())\n\nc = n // m\nr = n % m\nprint(soma(c) * (m - r) + soma(c + 1) * r, soma(n - m + 1))\n \t \t \t\t\t\t\t \t \t\t \t\t \t \t", "from math import comb\r\nx = input().split()\r\nn = int(x[0])\r\nm = int(x[1])\r\nmax1 = comb(n-(m-1),2)\r\nif n == m:\r\n print(0,0)\r\nelif n % m == 0:\r\n print(comb(n//m,2)*m,max1)\r\nelse:\r\n start = n//m\r\n no_start = m\r\n remainder = n % m\r\n no_second = remainder\r\n no_start -= remainder\r\n try1 = comb(start,2) * no_start + comb(start+1,2)*no_second\r\n print(try1,max1)\r\n \r\n \r\n \r\n \r\n", "n, m = map(int, input().split())\n \nmaximum = n - (m-1)\nmaximum = maximum*(maximum-1)//2\n \nval1 = n//m\nminimum = (val1*(val1-1)//2)*(m-(n%m))\n \nminimum += ((val1+1)*(val1)//2)*(n%m)\n \nprint(minimum, maximum)\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\nif __name__ == '__main__':\r\n n,m=list(map(int, input().split()))\r\n \r\n q=n//m\r\n rem=n%m\r\n minf=0\r\n if q>1: minf +=(m-rem)*q*(q-1)//2\r\n minf +=rem*(q+1)*(q)//2\r\n\r\n maxf=(n-m+1)*(n-m)//2\r\n\r\n\r\n \r\n print(minf,maxf)\r\n\r\n ", "#min: equally spaced\r\n#max: all 1s and rest is large\r\na, b = [int(x) for x in input().split()]\r\n\r\nnumones = b-1\r\nrest = a-numones\r\nmaxval = rest*(rest-1)//2\r\n\r\n\r\napproxval = a//b\r\n#b amount of approxval groups\r\nremain = a-approxval*b #remain amount of (approxval+1) groups\r\nminval = remain*((approxval+1)*(approxval)//2) + (b-remain)*((approxval)*(approxval-1)//2)\r\n\r\nprint(minval, maxval)", "\nnum, b = map(int, input().split())\nmax = num -(b-1)\nmax = max*(max-1)//2\nval1 = num//b\nmin = (val1* (val1-1)//2)* (b- (num%b))\nmin += ((val1+1)* (val1)//2)* (num%b)\nprint (min, max)\n\t \t \t\t \t\t\t \t\t\t \t\t\t \t \t\t\t\t", "from math import comb\r\nl=input().split()\r\nn=int(l[1])\r\nm=int(l[0])\r\nmax=comb(m-n+1,2)\r\nmin=0\r\ni=m//n\r\nj=m-i*n\r\nif j>0:\r\n min=(j)*comb(i+1,2)+(n-j)*comb(i,2)\r\nelse:\r\n min=n*comb(i,2)\r\nprint(min,max)", "import math\r\n\r\ndef solve(n):\r\n return (n * (n-1))//2\r\n\r\nn, m = map(int, input().split())\r\nif m == 1:\r\n max = min = solve(n)\r\n print(max, min)\r\nelse:\r\n max = solve(n-(m-1))\r\n if n % m != 0:\r\n min = (solve(n//m) * (m-(n%m))) + (solve(n//m + 1) * (n%m))\r\n else:\r\n min = solve((math.ceil(n//m))) * m\r\n print(min, max)", "n,m = map(int,input().split())\r\nmax1 = (((n - (m-1)))*((n - (m-1))-1))//2\r\nmin1 = m*(n//m)*((n//m)-1) // 2 + (n//m) * (n%m)\r\nprint(min1,max1) ", "import math\r\n\r\ndef nCr(n, r):\r\n if n < 0 or r < 0 or n < r:\r\n return 0\r\n else:\r\n return math.comb(n, r)\r\n\r\nn,m=map(int,input().split())\r\nmaxx=n-(m-1)\r\nminn=nCr((n//m)+1,2)*(n%m)+nCr(n//m,2)*(m-(n%m))\r\nprint(minn,nCr(maxx,2))\r\n\r\n", "a,b=map(int,input().split())\r\nmax=0\r\nmin=0\r\nc=a//b\r\nd=a%b\r\nmax=(a-b+1)*(a-b)//2\r\nmin=(b-d)*c*(c-1)//2+(d*(c+1)*c//2)\r\nprint(min,max)", "n, m = map(int, input().split())\r\nk = n // m\r\nkmin = m*k*(k-1)//2 + n%m*k # 尽量均分\r\nkmax = (n-m)*(n-m+1)//2\r\nprint(kmin, kmax)", "from math import comb\r\n\r\nn,m=map(int,input().split())\r\nmaxe=n-m+1\r\nmax=comb(maxe,2)\r\nif n%m==0:\r\n mine=n//m\r\n min=(comb(mine,2))*m\r\n print(int(min),int(max))\r\nelse:\r\n mine=n//m\r\n mine2=n//m+1\r\n min=(comb(mine,2))*(m-(n%m))+(comb(mine2,2))*(n%m)\r\n print(int(min),int(max))", "import math\r\n\r\nn, m = map(int, input().split())\r\nmn = (n//m-1)*(n//m)//2*m if n % m == 0 else (n//m+1)*(n//m)//2*(n % m)+(n//m)*(n//m-1)//2*(m-n % m)\r\nmx = (n-m+1)*(n-m)//2\r\nprint(f'{mn} {mx}')\r\n", "# I/O\ndef intarr():\n return map(int, input().split())\ndef intin():\n return int(input())\n\nif __name__ == \"__main__\":\n # t = intin()\n t = 1\n\n for _ in range(t):\n n, m = intarr()\n\n x = n - m + 1\n maxi = (x * (x - 1)) // 2\n mini = 0\n u = n // m\n\n mini += (m -(n%m))*((u*(u-1))//2)\n u += 1\n mini+= (n%m)*((u*(u-1))//2)\n\n print(mini, maxi)\n\n \t\t \t \t\t \t\t\t\t \t \t\t \t\t", "n,m=(map(int,input().split()))\r\n# arr=[list(map(int,input().split())) for i in range(n)]\r\n# arr=list(map(int,input().split()))\r\nif n==m:\r\n print(0,0)\r\n exit()\r\ndivi=n//m\r\nrem=n%m\r\ndef func(divi):\r\n return (divi*(divi-1))//2\r\nprint(rem*(func(divi+1))+(m-rem)*func(divi), func(n-m+1))\r\n \r\n", "n,m=map(int,input().split())\r\ndef pair_sum(x):\r\n return (x-1)*x//2\r\nk_max=pair_sum(n-m+1)\r\nnum=n//m\r\nteam1=n-num*m\r\nteam2=m-team1\r\nk_min=team1*pair_sum(num+1)+team2*pair_sum(num)\r\nprint(k_min,k_max)", "import math\nplayers, teams = map(int, input().split())\nmax_ = players-(teams-1)\ncount_max = math.comb(max_, 2)\n# if teams == 1:\n# print(count_max, count_max)\n# else:\ncommon = players//teams\nextra = players % teams\ncount_min = math.comb(common, 2)*(teams-extra) + \\\n extra*math.comb(common+1, 2)\nprint(count_min, count_max)\n", "n,m=map(int,input().split())\r\nmxx=n-m+1\r\nmnn=n//m\r\nr=n%m\r\nmaxx=(mxx*(mxx-1))//2\r\nminn=(mnn*(mnn-1)*(m-r)//2)+(mnn+1)*r*mnn//2\r\nprint(minn,maxx)\r\n", "n, p = map(int, input().split())\n \nmax = n - (p-1)\nmax = max*(max-1)//2\n \nval1 = n//p\nmin = (val1*(val1-1)//2)*(p-(n%p))\n \nmin += ((val1+1)*(val1)//2)*(n%p)\n \nprint(min, max)\n\t\t \t \t\t\t \t\t \t \t \t \t \t\t \t", "import sys\r\nfrom math import *\r\nfrom collections import Counter, defaultdict, deque\r\ninput = sys.stdin.readline\r\nmod = 10**9+7\r\n\r\nn, m = [int(i) for i in input().split()]\r\n# generate permutation, calculate nc2, get max and min of those-> inefficient\r\n# find min of k*k-1/2 and max of it\r\nr = n-m+1\r\nmax_ans = ((r)*(r-1))//2\r\ns = n//m\r\nr = n % m\r\nmin_ans = r*(((s+1)*(s))//2) + (m-r)*((s*(s-1))//2)\r\nprint(min_ans, max_ans)\r\n# 5 3 -> 2 2 1\r\n", "n,m = map(int,input().split())\r\ndef nc2(a):\r\n\treturn a*(a-1)//2\r\nmaxm = n-m+1\r\nmaxm = nc2(maxm)\r\nminm = (n%m)*nc2(n//m+1)+ (m-(n%m))*nc2(n//m)\r\nprint(minm, maxm)", "n,m = map(int,input().split())\r\nmx = (n-m+1)*(n-m)//2\r\nq = n%m\r\nd = n//m\r\nmn = q*(d+1)*d//2 + (m-q)*d*(d-1)//2\r\nprint(str(mn)+' '+str(mx))", "n,m=map(int,input().split())\r\nmx=(n-m+1)*(n-m)//2\r\nt=n//m\r\nmn=(n%m)*(t*(t+1)//2)+(m-n%m)*(t*(t-1)//2)\r\nprint(mn,mx)", "n,m = map(int,input().split())\r\nmx = ((n-m+1)*(n-m))//2\r\nx1 = n//m\r\ny1 = n%m\r\nmn = ((y1*(x1+1)*x1)//2) + (((m-y1)*(x1-1)*x1)//2)\r\n\r\nprint(int(mn),int(mx))", "m,n = [int(i) for i in input().split()]\r\n\r\nmaxi = m - n + 1\r\n\r\nmx = (maxi * (maxi - 1)) // 2\r\n\r\nmini = m // n\r\n\r\nrem = m % n\r\n\r\nmn1 = (((mini+1) * (mini)) // 2) * rem\r\n\r\nmn2 = (n - rem) * ((mini * (mini-1)) // 2)\r\n\r\nmn = mn1 + mn2\r\n\r\nprint(mn , mx)", "n, m = [int(s) for s in input().split()]\r\n\r\nmax_ = (n - m + 1) * (n - m) // 2\r\n\r\nper_team_if_eq = n // m\r\nteams_with_one_added = n % m\r\nteams_with_equal = m - teams_with_one_added\r\n\r\nmin_ = teams_with_one_added * (n // m + 1) * (n // m) // 2 + teams_with_equal * (n // m) * (n // m - 1) // 2\r\nprint(min_, max_)", "n, m = map(int, input().split())\nsmin = (n // m) * (n // m - 1) // 2 * (m - n % m) + (n // m) * (n // m + 1) // 2 * (n % m)\nsmax = (n - m + 1) * (n - m) // 2\nprint(smin, smax)\n \t \t \t \t\t \t \t\t\t \t\t \t \t \t \t", "from math import comb\r\nn,m = map(int,input().split())\r\n\r\nma = comb(n-(m-1),2)\r\n\r\nqo = n//m\r\nr = n%m\r\n\r\nmi = m*comb(qo,2) + r*qo\r\n\r\nprint(f'{mi} {ma}')\r\n", "n, m = map(int, input().split())\n \nmaxx = n - (m-1)\nmaxx = maxx*(maxx-1)//2\n \nval1 = n//m\nmin = (val1*(val1-1)//2)*(m-(n%m))\n \nmin += ((val1+1)*(val1)//2)*(n%m)\n \nprint(min, maxx)\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\nmi_n = n // m\r\nmi_x = n % m\r\nma_n = 1\r\nma_x = n - (m - 1)\r\nminimum = mi_n * (mi_n - 1) * (m - mi_x) // 2 + mi_n * (mi_n + 1) * mi_x // 2\r\nmaximum = ma_x * (ma_x - 1) // 2\r\nprint(minimum, maximum)", "# Random Teams\r\ns = input().split(\" \")\r\ns = [int(i) for i in s]\r\nn,m = s[0],s[1]\r\nkmax = 0\r\nkmin = 0\r\n# max section\r\nif m == 1:\r\n kmax = (n*(n-1))//2\r\nelse:\r\n kmax = (n+1-m)*(n+1-m-1)//2\r\n# min section\r\nif m == 1:\r\n print(kmax,end = \" \")\r\nelif n // m == n / m:\r\n print(int(((n/m)*((n/m)-1)*m) // 2), end = \" \")\r\nelse:\r\n maximum_number_cell = n % m\r\n\r\n number = n // m\r\n\r\n print(int((number*(number-1)*(m-maximum_number_cell))/2 + ((number+1)*number*maximum_number_cell/2)) , end = \" \")\r\n\r\nprint(kmax)", "def comb2a2 (n):\n return n*(n-1)//2\ndata = list(map(int,input().split()))\nn = data[0]\nm = data[1]\n\nmin = max = 0\n\ngroups_a_min = m - n%m\ngroups_b_min = n%m\n\ngroups_a_min_people = n//m\ngroups_b_min_people = n//m +1\n\nmin = groups_a_min*comb2a2(groups_a_min_people) + groups_b_min*comb2a2(groups_b_min_people)\n\n\ngroups_max_people = n - (m-1)\n\nmax = comb2a2(groups_max_people)\n\nprint(min, max)\n\t \t\t \t\t \t\t \t\t \t\t\t\t\t", "n, m = map(int, input().split())\r\nr = n // m\r\nprint(m * r * (r - 1) // 2 + n % m * r, (n - m + 1) * (n - m) // 2)\r\n", "n,m=map(int,input().split())\r\nmi=(((n//m-1)*m+2*(n%m))*(n//m))//2\r\nma=(n-m+1)*(n-m)//2\r\nprint(mi,ma)", "a, c = [int(x) for x in input().split()]\n\nmax_val = a - (c-1)\nmax_val = max_val*(max_val-1)//2\nval1 = a//c\n\nmin_val = (val1*(val1-1)//2) * (c-(a%c))\nmin_val += ((val1+1) * val1//2) * (a%c)\nprint(\"{} {}\".format(min_val, max_val))\n \t\t\t \t \t \t \t \t \t \t", "import math\n\nn, m = [int(x) for x in input().split()]\n\nmaxim = math.comb(n - m + 1, 2)\n\nif n % m == 0:\n minim = m * math.comb(n // m, 2)\nelse:\n s = n // m\n l = s + 1\n\n r_l = n / m - n // m\n r_s = 1 - r_l \n\n n_s, n_l = round(r_s * m), round(r_l * m)\n\n minim = n_s * math.comb(s, 2) + n_l * math.comb(l, 2)\n\n\n\nprint(minim, maxim)\n", "n,m=[int(x) for x in input().split()]\r\na=n//m\r\nb=n%m\r\nminm=(a*(a+1))//2\r\nminm*=b\r\nminm+=(m-b)*(a*(a-1))//2\r\nmaxm=((n-m+1)*(n-m))//2\r\nprint(minm,maxm)\r\n", "n, m = map(int, input().split())\r\n \r\n \r\ndef solve():\r\n \r\n maxN = n - m + 1\r\n \r\n maxElem = (maxN * (maxN - 1)) // 2\r\n \r\n remainder = n % m\r\n \r\n div = n // m\r\n \r\n minElem = remainder * (((div + 1) * div) // 2)\r\n newN = m - remainder\r\n minElem += newN * ((div * (div - 1)) // 2)\r\n return minElem, maxElem\r\n \r\n \r\n \r\nminAns, maxAns = solve()\r\n \r\nprint(minAns, maxAns)", "import math\r\n\r\ndef combination(n, k):\r\n return n*(n-1)//k\r\n\r\ndef calculate_min_max_counts():\r\n n_input, m_input = list(map(int,input().split()))\r\n\r\n x = n_input // m_input\r\n remainder = n_input % m_input\r\n min_count = 0\r\n mod = 1000000007\r\n\r\n inv_2 = pow(math.factorial(2), mod-2, mod)\r\n\r\n if remainder > 0:\r\n a = x + 1\r\n y = combination(a, 2)\r\n min_count += y*remainder\r\n\r\n if x > 1:\r\n b = combination(x, 2)\r\n min_count += b * (m_input-remainder)\r\n\r\n c = n_input-m_input+1\r\n max_count = combination(c, 2)\r\n\r\n return int(min_count), int(max_count)\r\n\r\nresult = calculate_min_max_counts()\r\nprint(result[0], result[1])\r\n", "n, t = map(int, input().split())\r\n\r\n# max\r\n\r\nrem = n - (t - 1)\r\nMax = (rem * (rem - 1)) // 2\r\n# min\r\n\r\nmember = int(n / t)\r\nMin = ((member * (member - 1)) // 2) * (t - n % t)\r\nmember += 1\r\nMin += ((member * (member - 1)) // 2) * (n % t)\r\nprint(Min, Max)\r\n", "n,m=map(int,input().split())\nr=n//m\nprint(m*r*(r-1)//2+n%m*r,(n-m+1)*(n-m)//2)\n\t\t\t\t \t\t\t \t\t \t \t\t \t \t", "def pair(n):\r\n return (n*(n-1))//2\r\n\r\n\r\nn,m = map(int,input().split())\r\nshare = n//m\r\nrem = n%m\r\ncomb = share+1\r\nmn = pair(comb)*rem + pair(share)*(m-rem)\r\nmx = pair(n-m+1)\r\nprint(mn,mx)", "# Submitted by Yousry_Essam\r\ndef Solve():\r\n n, m = map(int, input().split())\r\n mx = (n - m)\r\n mx = (mx * (mx+1))//2\r\n mnRe = n % m\r\n mnVal = n//m\r\n mnAns = 0\r\n mnAns += mnRe*(mnVal*(mnVal+1)//2)\r\n mnAns += (m-mnRe)*(mnVal * (mnVal-1)//2)\r\n print(mnAns, mx)\r\n return\r\n\r\n\r\nTestCase = 1 # int(input())\r\nfor _ in range(TestCase):\r\n Solve()\r\n", "n, m = map(int, input().split())\r\n\r\na = n//m\r\nb = n % m\r\n\r\nmaxi = (n-m) * (n-m+1) // 2\r\nmini = (a * (a+1) * b) //2 + (a * (a-1)*(m-b))//2\r\nprint(mini, maxi)\r\n", "n, m = map(int, input().split())\r\nk1 = ((n//m)*(n//m -1)//2)*(m - (n%m)) + ((n//m + 1)*(n//m)//2)*(n%m)\r\nk2 = (n-m+1)*(n-m)//2\r\nprint(k1,k2)", "n,m = input().split()\nn = int(n)\nm = int(m)\na = n//m\nb = n%m\nmax = (n-m+1)*(n-m)//2\nmin = (b*a*(a+1))//2 + ((m-b)*(a-1)*(a))//2\nprint(min,max)\n\t\t\t \t\t \t\t \t\t\t\t \t \t \t\t \t\t", "\r\ndef minMax(n,m):\r\n if m==1:\r\n num = nCr(n)\r\n print(num,num)\r\n else:\r\n val = n//m\r\n val1 = n % m\r\n min1 = nCr(val)\r\n min2 = nCr(val+1)\r\n min_num = min1*(m-val1)+min2*val1\r\n \r\n val = n-m+1\r\n max_num =nCr(val)\r\n \r\n print(min_num,max_num)\r\n \r\ndef nCr(n):\r\n return (n*(n-1)//2)\r\nn,m = [int(x) for x in input().split()]\r\nminMax(n,m)", "n,m=map(int,input().split())\r\ns,y=divmod(n,m)\r\nf=lambda x:x*(x-1)//2\r\nprint(y*f(s+1)+(m-y)*f(s),f(n-m+1))\r\n", "n, m = map(int, input().split())\r\n\r\nmax1 = (n-m+1)*(n-m)//2\r\n\r\na = n//m\r\nmin1 = m*a*(a-1)/2+a*(n%m)\r\n\r\nprint(int(min1), max1)", "import math\n\ndef comb(n, k):\n return n*(n-1)//k\n\ndef resolucao():\n n,m = list(map(int,input().split()))\n\n x = n//m\n resto = n%m\n cont_min = 0\n mod = 1000000007\n\n \n inv_2 = pow(math.factorial(2), mod-2,mod)\n \n if resto > 0:\n a = x + 1\n y = comb(a, 2)\n cont_min += y*resto\n\n\n if x > 1:\n b = comb(x,2)\n cont_min += b * (m-resto)\n \n\n c = n-m+1\n cont_max = comb(c,2)\n\n\n return int(cont_min), int(cont_max)\n \nresult = resolucao()\n\n\nprint(result[0],result[1])\n \t \t\t \t \t \t\t\t \t \t \t \t \t \t", "import math\nn, m = map(int, input().split())\n\ndef nc2(n):\n\treturn (n*(n-1)) // 2\n\nk_max = nc2(n-m+1) \n\nif n % m == 0:\n\tt = n // m\n\tk_min = m * nc2(t)\nelse:\n\tt = n // m\n\tr = n % m\n\n\t# Calculating the minimum number of pairs:\n\tk_min = (m - r) * nc2(t) + r * nc2(t + 1)\nprint(k_min, k_max)\n", "n, m = map(int, input().split())\r\nx = n-m+1\r\ns1 = (x*(x-1))//2\r\ny = n%m\r\nz = n//m\r\ns2 = y * (z+1)*(z)//2 + (m-y) * (z)*(z-1)//2\r\nprint(s2, s1)", "n ,m = map(int, input().split())\ng = n//m\nprint(m * (g * (g-1) // 2) + (n % m) * g, (n - m + 1) * (n - m) // 2)\n \t\t\t \t \t\t\t \t \t \t\t \t\t\t", "n,m=map(int,input().split())\na = n//m\nprint( m*a*(a-1)//2+a*(n%m) , (n-m)*(n-m+1)//2 )\n \t\t \t\t\t \t\t \t \t \t\t \t\t\t \t", "n, m = map(int, input().split())\r\nmax_pairs = (n - m + 1) * (n - m) // 2\r\nmin_pairs = (n % m) * (n // m + 1) * (n // m) // 2 + (m - n % m) * (n // m) * (n // m - 1) // 2\r\nprint(min_pairs, max_pairs)", "n ,m = input().split()\r\nn = int(n)\r\nm = int(m)\r\n\r\nmaxi = (n-m+1)*(n-m)\r\nmaxi = maxi//2\r\n\r\nt = n//m\r\nr = n%m\r\n\r\nmini = r*t+(m*(t*(t-1))//2)\r\n\r\nprint(mini,end=\" \")\r\nprint(maxi)", "import math\r\nn, m = map(int, input().split())\r\nif m == 1:\r\n ans1 = n*(n-1) // 2\r\n print(ans1, ans1)\r\nelse:\r\n c = n // m\r\n d = n % m\r\n ans1 = (m * (c-1) + d*2) * c //2\r\n n -= m-1\r\n ans2 = n*(n-1)//2\r\n print(ans1, ans2)\r\n", "import math\r\nn,m=list(map(int,input().split()))\r\ncount=int(n/m)\r\nprint(f\"{ int(m*count*(count-1)/2+count*(n%m))} {(n-m)*(n-m+1)//2}\")\r\n", "n, m = map(int, input().split())\n \nmax = n - (m-1)\nmax = max*(max-1)//2\n \nval_1 = n//m\nmin = (val_1*(val_1-1)//2)*(m-(n%m))\n \nmin += ((val_1+1)*(val_1)//2)*(n%m)\n \nprint(min, max)\n\t \t \t \t \t \t \t \t\t\t\t \t\t\t", "m, n = map(int, input().split())\r\nq = m//n\r\nw = m - n + 1\r\n\r\nkmin = (q * (q-1))//2\r\nkmax = (w * (w - 1)) // 2\r\nprint(kmin*n+q*(m%n), kmax)\r\n\r\n", "n, m = map(int, input().split())\r\nprint(int((n%m)*(n//m+1)/2*(n//m)+(m-n%m)*(n//m-1)/2*(n//m)), int((n/2-m/2)*10)*(n-m+1)//10)\r\n", "n,m=[int(i) for i in input().split()]\r\n\r\nmaxi=(n-m+1)*(n-m)//2\r\n\r\nif n%m==0:\r\n mem=n//m\r\n mini=(mem)*(mem-1)//2\r\n mini*=m\r\nelse :\r\n mem=n//m\r\n more=n%m\r\n less=m-more\r\n pair1=int(mem*(mem-1)*0.5)\r\n mem+=1\r\n pair2=int(mem*(mem-1)*0.5)\r\n mini=(pair1*less)+(pair2*more)\r\n\r\nprint(mini,maxi)", "n, m = map(int, input().split())\r\nif(m == 1): print((n*(n-1))//2, (n*(n-1))//2)\r\nelse:\r\n f = n//m\r\n rem = n%m\r\n print(((f*(f+1))//2)*rem + ((f*(f-1))//2)*(m-rem), ((n-m+1)*(n-m))//2)", "n, m = map(int, input().split())\r\nif m == 1:\r\n print(n * (n -1) // 2, n * (n-1) // 2)\r\nelse:\r\n #print((n // m) * (n // m - 1) // 2, (m - n % m), (n // m + 1) * (n // m ) // 2 * (n % m))\r\n print((n // m) * (n // m - 1) // 2 * (m - n % m) + (n // m + 1) * (n // m ) // 2 * (n % m), (n - m + 1) * (n - m) // 2)\r\n", "from math import factorial\r\n\r\n\r\ndef combination(n, r):\r\n if r > n:\r\n return 0\r\n\r\n _max = max(r, n - r)\r\n _min = min(r, n - r)\r\n ans = 1\r\n while n > _max:\r\n ans *= n\r\n n -= 1\r\n \r\n return ans//factorial(_min)\r\n \r\n\r\n\r\n\r\nn, m = map(int, input().split())\r\n\r\n\r\nq = n//m\r\nmod = n%m\r\n\r\n_min = mod*combination(q + 1, 2) + (m - mod)*combination(q, 2)\r\n_max = combination(n - m + 1, 2)\r\n\r\n\r\nprint(_min, _max)\r\n", "def main():\r\n n, m = map(int, input().split())\r\n kmax = ((n-m+1)*(n-m))//2\r\n kmin = (((n//m) * (n//m - 1)) // 2) * (m - n%m) + (((n//m+1)*(n//m))//2) * (n%m)\r\n print(kmin, kmax)\r\n\r\nmain()", "def comb(n):\r\n return int((n*(n-1))//2) if n > 1 else 0\r\n\r\n\r\nn, m = map(int, input().split())\r\n\r\nmaxi = comb(n-m+1)\r\n\r\nx, y = n//m, n % m\r\n\r\nmini = comb(x) * (m-y) + comb(x+1) * y\r\n\r\nprint(mini, maxi)\r\n", "def calc_friends(n):\n return ((n)*(n-1))//2\n\nn, m = map(int, input().split())\n\n\nmax_pers = (n - m + 1)\nmax_friends = ((n - m + 1)*(n - m))//2\nmin_per = n//m \nmin_friends = (n%m)*calc_friends(min_per + 1) + (m - (n%m))*calc_friends(min_per)\n\nprint(min_friends, max_friends)\n", "a,b=map(int,input().split())\r\ndef column(n):\r\n return (n*(n-1))//2\r\nmini=(b-a%b)*column(a//b)+(a%b)*column(a//b+1)\r\nmaxi=column(a+1-b)\r\nprint(f'{mini} {maxi}')", "def t(n):\r\n return (n*(n-1))//2\r\ndef solve():\r\n n,m = list(map(int,input().split()))\r\n a = n//m\r\n b = a*(n % m)\r\n c = t(a)*m\r\n d = n - m + 1\r\n return b+c,t(d)\r\nprint(*solve())", "def binpow(a, n):\r\n if n == 0:\r\n return 1\r\n if n % 2 == 1:\r\n return binpow(a, n - 1) * a\r\n else:\r\n b = binpow(a, n // 2)\r\n return b * b\r\n\r\ndef nc2(n):\r\n return (n * (n - 1)) // 2\r\n\r\ndef solve():\r\n n, m = map(int, input().split())\r\n k = n // m\r\n print(nc2(k + 1) * (n % m) + nc2(k) * (m - n % m), nc2(n - (m - 1)))\r\n\r\nT = 1\r\n# T = int(input())\r\nwhile T > 0:\r\n solve()\r\n T -= 1\r\n", "n, m=list(map(int, input().split()))\r\nx=n//m\r\nprint(m*x*(x-1)//2+x*(n%m), (n+1-m)*(n-m)//2)", "a,b = map(int,input().split())\r\nm = a-(b-1)\r\nm = m*(m-1)//2\r\nfir = a%b\r\nif a/b!=a//b:\r\n mn = (((a//b+1)*(a//b))//2)*fir+(((a//b)*(a//b-1))//2)*(b-fir)\r\nelse:\r\n mn = (((a//b)*(a//b-1))//2)*(b)\r\nprint(mn,m)", "def find_per(n):\r\n return (n*(n-1))//2\r\nn,m=map(int,input().split())\r\ncount=0\r\n#kmin\r\nmin_p=n//m#5\r\nrest=n%m#0\r\none_pair=find_per(min_p)\r\n\r\ncount+=one_pair*(m-rest)\r\nrest_pair=find_per(min_p+1)\r\ncount+=rest_pair*rest\r\n\r\n#max\r\nc=0\r\n\r\nc+=find_per(n-m+1)\r\n\r\nprint(count,c)\r\n", "import math\r\nx,y = map(int,input().split())\r\n\r\n\r\n#max\r\nm=math.comb(x-(y-1),2)\r\n\r\n\r\n#min\r\ndiv=x//y\r\nmod=x%y\r\nval1=math.comb(div,2)\r\nval2=math.comb(div+1,2)\r\nres1=val1*(y-mod)\r\nres2=val2*(mod)\r\n\r\nprint(res1+res2,m)\r\n", "n, m = map(int, input().split())\n \nmax = n - (m-1)\nmax = max*(max-1)//2\n \nval1 = n//m\nmin1 = (val1*(val1-1)//2)*(m-(n%m))\n \nmin1 += ((val1+1)*(val1)//2)*(n%m)\n \nprint(min1, max)\n \t \t \t\t \t \t \t\t \t\t\t\t\t \t", " \r\n#import io, os, sys\r\n#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\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, m = MII()\r\n\r\nr = n//m\r\nc = n%m\r\nkmin = ((r+1)*r)//2 * c + (r*(r-1))//2 * (m-c)\r\nkmax = ((n-m)*(n-m+1))//2\r\n\r\nprint(kmin, kmax)\r\n", "# 478B - Random Teams\r\ndef add(x):\r\n return (x*(x-1))//2\r\n\r\n\r\n[n, m] = list(map(int, input().split()))\r\nkmax = add(n-m+1)\r\nq, r = n//m, n % m\r\nkmin = r*add(q+1)+(m-r)*add(q)\r\nprint(kmin, kmax)\r\n", "first, second = map(int, input().split())\r\nprint((second * (first // second) * ((first // second) - 1) // 2) + (first % second) * (first // second), (first - second + 1) * (first - second) // 2)", "participantes, num_grupos = map(int, input().split(\" \"))\r\n\r\nparticipantes_por_grupo = participantes // num_grupos\r\nparticipantes_excedentes = participantes - participantes_por_grupo * num_grupos\r\n\r\n# Número mínimo de pares\r\nminimo_pares = num_grupos * participantes_por_grupo * (participantes_por_grupo - 1) //\\\r\n 2 + participantes_por_grupo * participantes_excedentes\r\n\r\n# Número máximo de pares\r\nmaximo_pares = (participantes - num_grupos + 1) * (participantes - num_grupos) // 2\r\n\r\nprint(int(minimo_pares), int(maximo_pares))\r\n", "m,n=map(int,input().split())\r\nkmax=(m-n+1)*(m-n)//2\r\nif m%n==0:\r\n kmin=(n)*((m//n)*(m//n-1))//2\r\nelse:\r\n kmin=(n-m%n)*(((m//n)*(m//n-1))//2)+(m%n)*((m//n+1)*(m//n))//2\r\nprint(kmin,kmax)", "n, m = map(int, input().split())\r\n\r\nmax = n - (m-1)\r\nmax = max*(max-1)//2\r\n\r\nval = n//m\r\nmin = (val*(val-1)//2)*(m-(n%m))\r\n\r\nmin += ((val+1)*(val)//2)*(n%m)\r\n\r\nprint(min, max)\r\n", "n, m = map(int, input().split())\r\n \r\nMax = n - (m-1)\r\nMax = (Max*(Max-1))//2\r\n \r\nx = n//m\r\nMin = ((x*(x-1))//2)*m\r\n \r\nMin += (n%m)*x\r\n \r\nprint(Min, end=\" \")\r\nprint(Max)", "from sys import stdin, stdout\r\ninput, print = stdin.readline, stdout.write\r\n\r\n\r\ndef nc2(n):\r\n return n*(n-1)//2\r\n\r\n\r\ndef main():\r\n n, m = map(int, input().split())\r\n d = n//m\r\n rem = n % m\r\n minval = (m-rem)*nc2(d)+rem*nc2(d+1)\r\n maxval = nc2(n-(m-1))\r\n print(str(minval) + \" \" + str(maxval) + \"\\n\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "import math\r\nfrom collections import defaultdict\r\nimport io\r\nimport os\r\nimport sys\r\ninput = sys.stdin.readline\r\n# for j in range(int(input())):\r\n # l,r=map(int,input().split())\r\n # n = int(input())\r\n # la=list(map(int,input().split()))\r\n # lb=list(map(int,input().split()))\r\n # l=list(map(int,input().split()))\r\n\r\n\r\ndef pair(x):\r\n return x*(x-1)//2\r\n\r\nn,m=map(int,input().split())\r\nx=n-m+1\r\ny=n//m\r\nma=pair(x)\r\nmi=(m-n%m)*pair(y)+pair(y+1)*(n%m)\r\nprint(mi,ma)\r\n\r\n\r\n", "n,m=map(int,input().split())\r\nr=n%m\r\nq=n//m\r\nk1=(m-r)*q*(q-1)//2\r\nif r!=0:k1+=r*(q+1)*q//2\r\nk2=(n-m+1)*(n-m)//2\r\nprint(k1,k2)", "n, m = map(int, input().split())\r\nif m == 1:\r\n print(n * (n - 1) // 2, n * (n - 1) // 2)\r\nelse:\r\n ans = (n - m + 1) * (n - m) // 2\r\n k = n // m #кол - во людей в группе\r\n n -= k * m # остаток людей\r\n c = n # n групп с большим кол-ом людей\r\n l = m - c # кол - во групп с нормальным кол - ом людей\r\n print(c * (k + 1) * k // 2 + l * k * (k - 1) // 2, ans)\r\n", "n ,m = map(int, input().split())\r\nr = n//m\r\nprint(m * (r * (r-1) // 2) + (n % m) * r, (n - m + 1) * (n - m) // 2)", "n,m= map(int, input().split())\r\nprint((n%m)*((n//m)+1)*(n//m)//2 + (m-n%m)*(n//m)*(n//m-1)//2, (n-m+1)*(n-m)//2)\r\n\r\n", "n , m = list(map(int,input().split()))\r\n\r\nsmallDiv = n // m ; smallMod = n % m\r\n\r\nsmallRes = (m - smallMod) * (smallDiv * (smallDiv - 1)) //2\r\n\r\nsmallRes += smallMod * (smallDiv * (smallDiv + 1)) //2\r\n\r\nbigRes = (n - m + 1) * (n - m ) //2\r\n\r\nprint(smallRes , bigRes , sep =' ')", "import sys\r\nfrom math import *\r\nfrom collections import *\r\ninp = lambda: sys.stdin.buffer.readline().decode().strip()\r\nout=sys.stdout.write\r\n# n=int(inp())\r\n# arr=list(map(int,inp().split()))\r\nn,m=map(int,inp().split())\r\nmmin,mmax=0,0\r\nx=n//m\r\na,b=m*(x+1)-n,n-m*x\r\nmmin+=a*(x*(x-1))//2+b*(x*(x+1))//2\r\ny=n-(m-1)\r\nmmax+=(y*(y-1))//2\r\nprint(mmin,mmax)\r\n\r\n\r\n", "\r\nn, m = map(int, input().split())\r\ncur=n//m\r\nprint(m*cur*(cur-1)//2+cur*(n%m), (n-m)*(n-m+1)//2)", "n, m = map(int, input().split())\r\nq = n // m \r\nr = n % m\r\nmn = m * q * (q - 1) // 2 + r * q\r\nmx = (n - m + 1) * (n - m) // 2 \r\nprint(mn, mx)\r\n", "n,m=map(int,input().split())\r\nk=n-(m-1)\r\nmx=k*(k-1)//2\r\na=n//m\r\nb=n%m\r\nmi=b*(a+1)*a//2+ (m-b)*a*(a-1)//2\r\nprint(mi,mx)", "from math import comb\r\nn,m=map(int,input().split())\r\nmaxi=comb(n-m+1,2)\r\nif m%n==0:\r\n mini=m*comb(m//n,2)\r\nelse:\r\n mini=n%m*(comb(n//m+1,2))+(m-n%m)*(comb(n//m,2))\r\nprint(mini,maxi)", "n,m=map(int,input().split())\r\n\r\nmax=((n-m+1)*(n-m))//2\r\n\r\nremainder=(n-m)%m\r\nq=(n-m)//m\r\nmin= (((q+1)*(q))//2)*(m-remainder)\r\nmin += (((q+2)*(q+1))//2)*(remainder)\r\n\r\nprint(min, max)", "n,m = map(int,input().split())\r\n\r\nn_copy = n - (m-1)\r\nmaxi = (n_copy * (n_copy-1)) // 2\r\n\r\na = n//m\r\nmini = a * (n % m) + (m*a**2-m*a)//2\r\n\r\nprint(mini,maxi)\r\n", "a,b = ([int(x) for x in input().split()])\r\nc=a-(b-1)\r\nd=(c*(c-1))//2\r\ne=a//b\r\nf=a%b\r\ng=b-f\r\nh=g*(e*(e-1))//2 + f*(e*(e+1))//2\r\nprint(h,d)", "from math import comb\r\nn = input().split()\r\npart = int(n[0])\r\nteams = int(n[1])\r\n\r\nnum = part-(teams - 1)\r\nmaxx = 0\r\nminn = 0\r\nif num >= 2:\r\n maxx = comb(num, 2)\r\n\r\nrepeat = part / teams\r\nreminder = part % teams\r\nnum3 = int(part/teams)\r\nif num3 < 2 and reminder>1:\r\n minn = comb(num3+1,2)*reminder\r\nelse:\r\n minn = comb(num3, 2) * (teams - reminder) + comb(num3+1 , 2)*reminder\r\nprint(minn)\r\nprint(maxx)\r\n", "def cal(a):\r\n if a < 2:\r\n return 0\r\n return a * (a - 1) // 2\r\n\r\ndef Solve():\r\n n, m = map(int, input().split())\r\n tmp = n - m + 1\r\n mx = cal(tmp)\r\n\r\n mn = 0\r\n tmp1 = n // m\r\n tmp2 = n % m\r\n mn += tmp2 * cal(tmp1 + 1) + (m - tmp2) * cal(tmp1)\r\n print(mn, mx)\r\n\r\nif __name__ == \"__main__\":\r\n Solve()\r\n", "#By Anan instagram: anan.ssw\r\nfrom fractions import Fraction\r\nn,m=map(int,input().split())\r\nbase=n//m\r\nr=n%m\r\nx=int((base*0.5)*(base-1))\r\nx1=x+base\r\nmn=x1*r+(m-r)*x\r\ny=n-m+1\r\nmx=int(Fraction(y*0.5)*Fraction(y-1))\r\nprint(mn,mx)", "n, m = map(int, input().split())\n \nmx = ((n - m + 1) * (n - m)) // 2\n \nx = n // m\nmn = (x * (x - 1)) // 2\nmn *= m\nmn += x * (n % m)\n \nprint(mn, mx)\n\n\t\t \t \t\t \t \t\t\t \t\t \t\t\t", "n,m=map(int,input().split())\nmin_sum=(n%m)*((1+n//m)*(n//m)//2)+(m-n%m)*(n//m*(n//m-1)//2)\nmax_sum=(n-m+1)*(n-m)//2\nprint(int(min_sum),int(max_sum))\n\n", "from math import comb as c\r\nn, m = (int(x) for x in input().split())\r\nk1 = c(n-m+1,2)\r\nk2 = n%m * c(n//m+1,2) + (m-n%m) *c(n//m,2)\r\n\r\nprint(min(k1,k2) , max(k1,k2))\r\n", "def c(n):\r\n return n * (n - 1) // 2\r\n\r\ndef main():\r\n n, m = [int(x) for x in input().split()]\r\n a = (m - (n % m)) * c(n // m) + (n % m) * c(n // m + 1)\r\n b = c(n - m + 1)\r\n print(f\"{a} {b}\")\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n, m = map(int, input().split())\r\n\r\n\r\nif n <= m:\r\n kmax = n - m \r\n\r\nelse:\r\n a = n - (m-1)\r\n kmax = a*(a-1) // 2\r\n\r\n\r\n\r\na = n // m\r\nb = n % m\r\n\r\nkmin = a*(a-1) // 2 * (m - b) + b * a * (a+1) // 2\r\n\r\nprint(kmin, kmax) ", "n,m = map(int, input().split())\r\n\r\nif n==m:\r\n print(0, 0)\r\nelse:\r\n r = n//m \r\n k_min = m*r*(r-1)//2 + r*(n%m) \r\n print(k_min, (n-m+1)*(n-m)//2) \r\n", "n, m = map(int, input().split())\nkmin = (n // m) * (n // m - 1) // 2 * (m - n % m) + (n // m) * (n // m + 1) // 2 * (n % m)\nkmax = (n - m + 1) * (n - m) // 2\nprint(kmin, kmax)\n\t\t \t \t\t\t \t \t \t \t\t\t", "import math\r\nn,m=map(int,input().split())\r\nprint(math.comb((n//m)+1,2)*(n-(m*(n//m)))+math.comb(n//m,2)*(m-(n-(m*(n//m)))),math.comb(n-(m-1),2))", "def comb(n):\r\n\tif n<2:\r\n\t\treturn 0\r\n\t\t\r\n\treturn (n * (n-1)//2)\r\n\r\nn, m = map(int, input().split())\r\nmi = (m - n%m) * (comb(n//m)) + (n%m) * (comb(n//m + 1))\r\nmx = comb(n-m+1)\r\n\r\nprint(mi, mx)\r\n", "participantes, times = [int(x) for x in input().split()]\n\n# MAX\naux = participantes - times + 1\n\nif (aux-1) %2 == 0:\n soma_max = ((aux-1)//2*(aux))\n\n\nelse:\n soma_max = (aux-1)*((aux)//2)\n\n\n# MIN\ndiv = (participantes//times)\nresto = participantes % times\n\nsoma_min = (((div+1)*div)/2)*resto + (((div-1)*div)/2)*(times-resto)\n\nprint(int(soma_min),(soma_max))\n \t \t\t\t\t\t \t\t\t \t \t\t\t \t\t \t\t", "s = input().split()\r\ns = [int(x) for x in s]\r\nn = s[0]\r\nm = s[1]\r\n\r\ndef f(k):\r\n return int(k*(k-1)//2)\r\n\r\nmax = f(n-m+1)\r\nmin = (m - n%m)*(f(n//m)) + n%m*f(n//m+1)\r\nprint(min, max)", "import sys\ninput = sys.stdin.readline\n\nn, m = map(int, input().split())\nx = n - (m - 1)\nres2 = (x * (x - 1)) // 2\nx = n // m\ny = n % m\nt1 = (x * (x - 1)) // 2 * (m - y)\nt2 = (x * (x + 1)) // 2 * y\nres1 = t1 + t2\n\nprint(res1, res2)\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())\n\nx = n - (m - 1)\nmaximo = (x * (x - 1)) // 2\n\nx = n % m\ny = n // m\nminimo = (m-x) * (y * (y - 1)) // 2 + x * (y * (y + 1)) // 2\n\nprint(minimo,maximo)\n\n\n \t\t\t\t\t\t \t \t \t\t \t \t \t \t\t", "IN = lambda type = int:list(map(type, input().split()))\r\n\r\nn, m = IN()\r\nr = n//m\r\nprint( (m*r*(r-1)//2) + ((n%m)*r), (n-m+1)*(n-m)//2)", "n, m = map(int,input().split())\ndef c2pon(n):\n return (n *(n - 1))// 2\nk = (n - m + 1)\nkmx = (k * (k - 1)) // 2\nkmn = c2pon(n // m) * m + (n % m) * (n // m)\nprint(kmn,kmx)\n", "n, m = map(int, input().split())\nif m == 1:\n k = (n)*(n-1) // 2\n print(f\"{k} {k}\")\nelse:\n # 贪心:每个房间之上放一个人之后,再放人的时候,每次放在人最多的房间产生的pair最多, 放在人最少的房间pair最少\n n_after_each_have_one = n - (m-1)\n kmax = n_after_each_have_one*(n_after_each_have_one - 1) // 2\n n_mean, n_left = n // m, n % m\n kmin = n_left*((n_mean+1)* n_mean//2) + (m-n_left) * (n_mean*(n_mean-1)//2)\n print(f\"{kmin} {kmax}\")\n", "import sys\ninput = sys.stdin.readline\n\nn, m = map(int, input().split())\n\n# kmin = all teams have 1 except for 1 team\n# kmax = all teams are as equal as possible\nkmax, kmin = 0, 0\nif n == m:\n kmax, kmin = 0, 0\nelse:\n kmax = (n-m+1)*(n-m)//2\n group = n // m\n kmin = (n % m) * (group+1)*group//2 + (m- (n%m)) * group * (group-1) //2\n\nprint(kmin, kmax)", "a,b = list(map(int,input().split()))\r\nrem = a%b\r\nque = a//b\r\n\r\n# print(\r\nfirst = (que*(que-1))//2*(b-rem)\r\n # )\r\nsecond = que*(que+1)//2*rem\r\n\r\nlst = ((a-b)*(a-b+1)//2)\r\nprint(first+second,lst)", "n,m=map(int,input().split())\r\nprint((m-n%m)*(n//m)*(n//m-1)//2+n%m*(n//m+1)*(n//m)//2,(n-(m-1))*((n-(m-1))-1)//2)", "n,m=map(int,input().split())\r\nif m==1:\r\n print(n*(n-1)//2,n*(n-1)//2)\r\nelif n%m==0:\r\n p=n//m\r\n o=n-(m-1)\r\n print(p*(p-1)//2*m,o*(o-1)//2)\r\nelse:\r\n dup=n//m+1\r\n act=n//m\r\n res=(act*(act-1)//2)*(m-n%m)\r\n res+=(dup*(dup-1)//2)*(n%m)\r\n o=n-(m-1)\r\n print(res,o*(o-1)//2)" ]
{"inputs": ["5 1", "3 2", "6 3", "5 3", "10 2", "10 6", "1000000000 1", "5000000 12", "1833 195", "1000000000 1000000000", "1000000000 1000000", "1000000000 32170", "1000000 1000", "1234 1123", "599222887 298488", "999999999 500000000", "1000000000 384842119", "1000000000 384842119", "1000000000 2", "1000000000 999999999", "38447 383", "100000000 99999799", "1 1", "2 1", "2 2", "10 10"], "outputs": ["10 10", "1 1", "3 6", "2 3", "20 36", "4 10", "499999999500000000 499999999500000000", "1041664166668 12499942500066", "7722 1342341", "0 0", "499500000000 499000500499500000", "15541930838100 499967831017438365", "499500000 499000999500", "111 6216", "601178656545 179355218158217800", "499999999 124999999750000000", "845473643 189209609585784021", "845473643 189209609585784021", "249999999500000000 499999998500000001", "1 1", "1910550 724453080", "201 20301", "0 0", "1 1", "0 0", "0 0"]}
UNKNOWN
PYTHON3
CODEFORCES
239
19822dd149e51b421976d336fb1fb4a8
Equal Sums
You are given $k$ sequences of integers. The length of the $i$-th sequence equals to $n_i$. You have to choose exactly two sequences $i$ and $j$ ($i \ne j$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $i$ (its length will be equal to $n_i - 1$) equals to the sum of the changed sequence $j$ (its length will be equal to $n_j - 1$). Note that it's required to remove exactly one element in each of the two chosen sequences. Assume that the sum of the empty (of the length equals $0$) sequence is $0$. The first line contains an integer $k$ ($2 \le k \le 2 \cdot 10^5$) — the number of sequences. Then $k$ pairs of lines follow, each pair containing a sequence. The first line in the $i$-th pair contains one integer $n_i$ ($1 \le n_i &lt; 2 \cdot 10^5$) — the length of the $i$-th sequence. The second line of the $i$-th pair contains a sequence of $n_i$ integers $a_{i, 1}, a_{i, 2}, \dots, a_{i, n_i}$. The elements of sequences are integer numbers from $-10^4$ to $10^4$. The sum of lengths of all given sequences don't exceed $2 \cdot 10^5$, i.e. $n_1 + n_2 + \dots + n_k \le 2 \cdot 10^5$. If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers $i$, $x$ ($1 \le i \le k, 1 \le x \le n_i$), in the third line — two integers $j$, $y$ ($1 \le j \le k, 1 \le y \le n_j$). It means that the sum of the elements of the $i$-th sequence without the element with index $x$ equals to the sum of the elements of the $j$-th sequence without the element with index $y$. Two chosen sequences must be distinct, i.e. $i \ne j$. You can print them in any order. If there are multiple possible answers, print any of them. Sample Input 2 5 2 3 1 3 2 6 1 1 2 2 2 1 3 1 5 5 1 1 1 1 1 2 2 3 4 6 2 2 2 2 2 2 5 2 2 2 2 2 3 2 2 2 5 2 2 2 2 2 Sample Output YES 2 6 1 2 NO YES 2 2 4 1
[ "from collections import defaultdict\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\nk = int(input())\r\nlst = []\r\n\r\nfor i in range(k):\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n s = sum(arr)\r\n for j, e in enumerate(arr):\r\n lst.append((s-e, i+1, j+1))\r\n\r\nlst.sort(key=lambda x: (x[0], x[1]))\r\n\r\nfor i in range(0, len(lst)-1):\r\n if lst[i][0] == lst[i+1][0] and lst[i][1] != lst[i+1][1]:\r\n print(\"YES\")\r\n print(lst[i][1], lst[i][2])\r\n print(lst[i+1][1], lst[i+1][2])\r\n exit()\r\n\r\nprint(\"NO\")\r\n\r\n\r\n\r\n", "dic = {}\r\nfor z in range(int(input())):\r\n\tn = int(input())\r\n\tarr = list(map(int,input().split()))\r\n\tsm = sum(arr)\r\n\tfor i in range(n):\r\n\t\tnew = sm-arr[i]\r\n\t\tif new in dic and dic[new][0] != z:\r\n\t\t\tprint('YES')\r\n\t\t\tprint(dic[new][0]+1, dic[new][1]+1)\r\n\t\t\tprint(z+1,i+1)\r\n\t\t\traise SystemExit(0)\r\n\t\telif new not in dic:\r\n\t\t\tdic[new] = (z,i)\r\nprint('NO')\r\n\r\n", "\r\n\r\n\r\nk = int(input())\r\na = []\r\n \r\nfor i in range(k):\r\n n = int(input())\r\n x = list(map(int, input().split()))\r\n sum_x = sum(x)\r\n \r\n for j in range(n):\r\n a.append((sum_x - x[j], (i, j)))\r\n \r\na.sort()\r\nok=False\r\nfor i in range(len(a) - 1):\r\n if a[i][0] == a[i + 1][0] and a[i][1][0] != a[i + 1][1][0]:\r\n ok=True\r\n break\r\nif ok:\r\n print(\"YES\")\r\n print(f\"{a[i + 1][1][0] + 1} {a[i + 1][1][1] + 1}\")\r\n print(f\"{a[i][1][0] + 1} {a[i][1][1] + 1}\")\r\nelse:\r\n print('NO')\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "from collections import defaultdict, Counter\r\nfrom bisect import bisect, bisect_left\r\nfrom math import sqrt, gcd\r\n \r\ndef read(): return list(map(int, input().strip().split()))\r\n \r\nans_ = []\r\n\r\n \r\n# for _ in range(int(input())):\r\nn = int(input()); \r\nd = defaultdict(list)\r\nf = 0\r\n\r\nfor i in range(n):\r\n m = int(input())\r\n arr = read(); s = sum(arr)\r\n vis = set()\r\n for j in range(m):\r\n if not arr[j] in vis:\r\n x = s-arr[j]\r\n d[x].append(str(i+1)+\" \"+str(j+1))\r\n if len(d[x]) >= 2:\r\n a, b = d[x][:2]\r\n f = 1\r\n break\r\n vis.add(arr[j])\r\n if f:break\r\n\r\n# print(d)\r\nif f:\r\n ans_.append(\"YES\")\r\n ans_.append((\"\\n\").join([a, b]))\r\nelse:\r\n ans_.append(\"NO\")\r\n\r\n\r\n \r\n \r\n# print(ans_)\r\nfor i in ans_:\r\n print(i)\r\n \r\n \r\n\"\"\"\r\n9 + 9 + \r\n\"\"\"", "from collections import Counter\r\n\r\nz=Counter()\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n a=[int(x) for x in input().split()]\r\n s=sum(a)\r\n for i in range(n):\r\n if z[s-a[i]]!=0 and z[s-a[i]][0]!=_+1:\r\n print('YES')\r\n print(_+1,i+1)\r\n print(*z[s-a[i]])\r\n exit()\r\n z[s-a[i]]=[_+1,i+1]\r\n\r\nprint('NO')\r\n\r\n", "k = int(input())\r\nhashmap = {}\r\nflag = False\r\nfor seq in range(k):\r\n n = int(input())\r\n cur = list(map(int, input().split()))\r\n total = sum(cur)\r\n for idx, num in enumerate(cur):\r\n rem_sum = total - num\r\n if hashmap.get(rem_sum, 0) and hashmap[rem_sum][0] != seq+1:\r\n print(\"YES\")\r\n print(seq+1 , idx+1)\r\n print(*hashmap[rem_sum])\r\n flag = True\r\n break\r\n hashmap[rem_sum] = (seq+1, idx+1)\r\n \r\n if flag:\r\n break\r\nelse:\r\n print(\"NO\")\r\n\r\n\r\n \r\n\r\n\r\n", "d = {}\r\nfor i in range(int(input())):\r\n n = int(input())\r\n mass = list(map(int, input().split()))\r\n s = sum(mass)\r\n for index, value in enumerate(mass, 1):\r\n if s - value in d and i + 1 != d[s - value][0]:\r\n second = index\r\n second_mass = i + 1\r\n print('YES')\r\n print(i + 1, index)\r\n print(d[s - value][0], d[s - value][1])\r\n break\r\n d[s - value] = [i + 1, index]\r\n else:\r\n continue\r\n break\r\nelse:\r\n print('NO')", "d={}\r\nfor i in range(1,int(input())+1):\r\n input();a=list(map(int,input().split()));s=sum(a);t=set()\r\n for j,x in enumerate(a,1):\r\n if x not in t:\r\n t.add(x);r=d.get(s-x)\r\n if r:\r\n print('YES');print(*r);print(i,j);exit()\r\n d[s-x]=i,j\r\nprint('NO')\r\n", "from sys import stdin,stdout\r\ninput = stdin.readline\r\nk = int(input())\r\nlst = []\r\nfor j in range(1,k+1):\r\n n = int(input())\r\n a = list(map(int,input().split()))\r\n sum1 = sum(a)\r\n for i in range(n):\r\n lst.append((j,sum1-a[i],i+1))\r\ndct1 = {}\r\nans = []\r\nfor p in range(len(lst)):\r\n d = lst[p]\r\n if d[1] in dct1.keys():\r\n if dct1[d[1]][0] != d[0]:\r\n ans = [dct1[d[1]],[d[0],d[2]]]\r\n break\r\n else:\r\n dct1[d[1]] = [d[0],d[2]]\r\nif ans!=[]:\r\n print(\"YES\")\r\n print(ans[0][0],ans[0][1])\r\n print(ans[1][0],ans[1][1])\r\nelse:\r\n print(\"NO\")\r\n ", "t = []\r\nfor i in range(int(input())):\r\n\tn = int(input())\r\n\ta = [*map(int, input().split())]\r\n\ts = sum(a)\r\n\tfor j in range(n):\r\n\t\tt.append((s-a[j], i, j))\r\nt.sort()\r\nl = len(t)\r\nf = 1\r\nfor i in range(1, l):\r\n\tif t[i][0] == t[i-1][0] and t[i][1] != t[i-1][1]:\r\n\t\tprint(\"YES\")\r\n\t\tprint(t[i-1][1]+1, t[i-1][2]+1)\r\n\t\tprint(t[i][1]+1, t[i][2]+1)\r\n\t\tf = 0\r\n\t\tbreak\r\nif f:\r\n\tprint(\"NO\")\r\n", "res = {}\r\nfor i in range(1, int(input())+1):\r\n input()\r\n *a, = map(int, input().split())\r\n s = sum(a)\r\n for j, x in enumerate([s-x for x in a], start=1):\r\n if x in res and i != res[x][0]:\r\n print('YES')\r\n print(i, j)\r\n print(*res[x])\r\n exit(0)\r\n res[x] = (i, j)\r\nprint('NO')\r\n", "def sum_without_one(arr, i):\r\n s = sum(arr)\r\n return [(s-x, (i+1, j+1)) for j, x in enumerate(arr)]\r\n\r\nres = []\r\nfor i in range(int(input())):\r\n input()\r\n res.extend(sum_without_one(list(map(int, input().split())), i))\r\nres.sort()\r\n# print(res)\r\nprev = res[0]\r\nfor curr in res[1:]:\r\n if prev[0] == curr[0] and prev[1][0] != curr[1][0]:\r\n print('YES')\r\n print(*prev[1])\r\n print(*curr[1])\r\n break\r\n prev = curr\r\nelse:\r\n print('NO')\r\n", "k=int(input())\r\nd={}\r\nfor i in range(k):\r\n\tn=int(input())\r\n\ta=list(map(int,input().split()))\r\n\ts=sum(a)\r\n\tfor j in range(n):\r\n\t\tx=s-a[j]\r\n\t\tif (x in d) and (d[x][0]!=i):\r\n\t\t\tprint(\"YES\")\r\n\t\t\tprint(d[x][0]+1,d[x][1]+1)\r\n\t\t\tprint(i+1,j+1)\r\n\t\t\texit()\r\n\t\telif x not in d:\r\n\t\t\td[x]=(i,j)\r\nprint(\"NO\")", "n = int(input())\r\nd = {}\r\nfor i in range(n):\r\n k = input()\r\n t = list(map(int, input().split()))\r\n m = sum(t)\r\n for j, v in enumerate(t):\r\n k = m - v\r\n if k in d and d[k][0] != i:\r\n print(\"YES\")\r\n print(i + 1, j + 1)\r\n print(d[k][0] + 1, d[k][1] + 1)\r\n exit(0)\r\n if k not in d:\r\n d[k] = (i, j)\r\nprint(\"NO\")", "\r\n\r\ndef solve():\r\n k = int(input())\r\n d = dict()\r\n ans = None\r\n for i in range(k):\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n if not ans:\r\n s = sum(a)\r\n curr = set()\r\n for j in range(len(a)):\r\n if s-a[j] in d and d[s-a[j]][0] != i+1:\r\n ans = (d[s-a[j]], (i+1, j+1))\r\n else:\r\n d[s-a[j]] = (i+1, j+1)\r\n if ans:\r\n print(\"YES\")\r\n print(*ans[0])\r\n print(*ans[1])\r\n else:\r\n print(\"NO\")\r\n\r\n\r\nsolve()", "def sum_without_one(arr):\r\n s = sum(arr)\r\n return [s-x for x in arr]\r\n\r\n\r\nres = {}\r\nfor i in range(int(input())):\r\n input()\r\n for j, x in enumerate(sum_without_one(list(map(int, input().split())))):\r\n if x in res and i+1 != res[x][0]:\r\n print('YES')\r\n print(i+1,j+1)\r\n print(*res[x])\r\n exit(0)\r\n res[x] = (i+1, j+1)\r\nprint('NO')\r\n", "from heapq import heapify,heappush,heappop,heappushpop\r\nfrom collections import defaultdict as dd, deque as dq,Counter as C\r\nfrom math import factorial as f ,ceil,gcd,sqrt,log\r\nfrom bisect import bisect_left as bl ,bisect_right as br\r\nfrom itertools import combinations as c,permutations as p\r\nfrom math import factorial as f ,ceil,gcd,sqrt,log\r\nfrom sys import stdin\r\ninput = stdin.readline\r\nmp = lambda : map(int,input().split())\r\nit = lambda: int(input())\r\nls = lambda : list(input().strip().split())\r\nmt = lambda r : [ ls() for _ in range(r)]\r\nlcm = lambda a,b : (a*b)//gcd(a,b)\r\ndef fibo_n(n):\r\n\treturn (((1+sqrt(5))/2)**n)/sqrt(5)\r\nn = it()\r\nv =[]\r\nans =\"NO\"\r\nfor i in range(n):\r\n\ta= it()\r\n\tl = list(mp())\r\n\tk = sum(l)\r\n\trem = [(k-l[j],j+1,i+1) for j in range(a)]\r\n\tv.extend(rem)\r\nv.sort()\r\nls =[]\r\nfor el in range(1,len(v)):\r\n\tif v[el-1][2]!=v[el][2]:\r\n\t\tif v[el-1][0]==v[el][0]:\r\n\t\t\tans =\"YES\"\r\n\t\t\tls.append([v[el-1][2],v[el-1][1]])\r\n\t\t\tls.append([v[el][2],v[el][1]])\r\n\t\t\tbreak\r\nif ans ==\"NO\":\r\n\tprint(\"NO\")\r\nelse:\r\n\tls.sort()\r\n\tprint(\"YES\")\r\n\tfor p in ls:\r\n\t\tprint(*p)", "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nimport decimal\r\ninput=sys.stdin.readline\r\nd={}\r\nk=int(input())\r\nl=[]\r\nl1=[]\r\nc=0\r\nt=[-1,-1]\r\nfor i in range(k):\r\n n=int(input())\r\n l1.append(n)\r\n l.append([int(j) for j in input().split()])\r\n if(c==0):\r\n s=sum(l[i])\r\n for j in range(n):\r\n if(s-l[i][j] in d):\r\n if(d[s-l[i][j]][0]!=i+1):\r\n t[0]=[i+1,j+1]\r\n t[1]=d[s-l[i][j]]\r\n c=1\r\n break\r\n else:\r\n d[s-l[i][j]]=[i+1,j+1]\r\nif(c==1):\r\n print(\"YES\")\r\n print(*t[0])\r\n print(*t[1])\r\nelse:\r\n print(\"NO\")", "k = int(input())\r\narr = []\r\nfor _ in range(k):\r\n n = int(input())\r\n arr.append(list(map(int,input().split())))\r\nd = {}\r\nfor i in range(k):\r\n s = sum(arr[i])\r\n used = set()\r\n for j,c in enumerate(arr[i]):\r\n if c in used:\r\n continue\r\n used.add(c)\r\n if s-c in d:\r\n print(\"YES\")\r\n print(*d[s-c])\r\n print(i+1,j+1)\r\n exit()\r\n else:\r\n d[s-c] = [i+1,j+1]\r\nprint(\"NO\")\r\n", "k=int(input())\r\nai=[]\r\nfor i in range(k):\r\n n=int(input())\r\n li=list(map(int,input().split()))\r\n s=sum(li)\r\n for j in range(n):\r\n ai.append([s-li[j],i,j])\r\nai.sort()\r\nf=0\r\nfor i in range(len(ai)-1):\r\n if(ai[i][0]==ai[i+1][0]):\r\n if(ai[i][1]!=ai[i+1][1]):\r\n f=1 \r\n print(\"YES\")\r\n print(ai[i][1]+1,ai[i][2]+1)\r\n print(ai[i+1][1]+1,ai[i+1][2]+1)\r\n break \r\nif(f==0):\r\n print(\"NO\")", "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 sys\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef solve():\r\n k = int(input())\r\n sums = {}\r\n seen = {}\r\n locs = [{} for _ in range(k)]\r\n\r\n for i in range(k):\r\n n = int(input())\r\n S = list(map(int, input().split()))\r\n total = sum(S)\r\n sums[i] = total\r\n\r\n to_merge = {}\r\n\r\n for j, y in enumerate(S):\r\n locs[i][total - y] = j\r\n to_merge[total - y] = i\r\n\r\n if total - y in seen:\r\n which = seen[total - y]\r\n index = locs[which][total - y]\r\n\r\n print(\"YES\")\r\n print(i + 1, j + 1)\r\n print(which + 1, index + 1)\r\n return\r\n\r\n for k, v in to_merge.items():\r\n seen[k] = v\r\n\r\n print(\"NO\")\r\n\r\n\r\ndef main():\r\n solve()\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "import sys\r\nk = int(sys.stdin.readline())\r\nd = dict()\r\nfor y in range(1,k+1):\r\n\td1 = dict()\r\n\tn = int(sys.stdin.readline())\r\n\ta = list(map(int,sys.stdin.readline().split()))\r\n\ts = sum(a)\r\n\tfor i in range(n):\r\n\t\tx = s-a[i]\r\n\t\tif(x in d):\r\n\t\t\tsys.stdout.write('YES\\n')\r\n\t\t\tsys.stdout.write(str(d[x][0])+' '+str(d[x][1])+'\\n')\r\n\t\t\tsys.stdout.write(str(y)+' '+str(i+1))\r\n\t\t\texit(0)\r\n\t\td1[x] = [y,i+1]\r\n\tfor i in d1.keys():\r\n\t\td[i] = d1[i]\r\nsys.stdout.write('NO')", "dic = {}\r\nfor z in range(int(input())):\r\n\tl,seq = int(input()), list(map(int, input().split(\" \")))\r\n\ts = sum(seq)\r\n\tfor i in range(l):\r\n\t\tnews = s - seq[i]\r\n\t\tif news in dic and dic[news][0] != z:\r\n\t\t\t# done\r\n\t\t\tprint(\"YES\")\r\n\t\t\tprint(dic[news][0]+1, dic[news][1]+1)\r\n\t\t\tprint(z+1, i+1)\r\n\t\t\traise SystemExit(0)\r\n\t\telif news not in dic:\r\n\t\t\tdic[news] = (z, i)\r\nprint(\"NO\")", "n = int(input())\r\na = []\r\nfor i in range(n):\r\n k = int(input())\r\n q = list(map(int, input().split()))\r\n s = sum(q)\r\n used = set()\r\n for j, x in enumerate(q):\r\n if x not in used:\r\n used.add(x)\r\n a.append(((i, j), s - x))\r\na.sort(key=lambda x: x[1])\r\nfor i in range(1, len(a)):\r\n if a[i - 1][1] == a[i][1]:\r\n print(\"YES\")\r\n print(*map(lambda x: x + 1, a[i - 1][0]))\r\n print(*map(lambda x: x + 1, a[i][0]))\r\n break\r\nelse:\r\n print(\"NO\")\r\n", "k=int(input())\r\nans=dict()\r\nfor i in range(1,k+1):\r\n n=int(input())\r\n a=list(map(int,input().split()))\r\n s=sum(a)\r\n for j in range(1,n+1):\r\n temp=s-a[j-1]\r\n if temp in ans:\r\n print(\"YES\")\r\n print(i,j)\r\n print(ans[temp][0],ans[temp][1])\r\n exit()\r\n for j in range(1,n+1):\r\n temp=s-a[j-1]\r\n ans[temp]=(i,j)\r\n\r\nprint(\"NO\") ", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nfrom typing import Iterable, Hashable\r\n\r\n\r\nclass HashedMultiSet:\r\n\r\n def __init__(self, a: Iterable[Hashable]=[]) -> None:\r\n d = {}\r\n for e in a:\r\n if e in d:\r\n d[e] += 1\r\n else:\r\n d[e] = 1\r\n self._data = d\r\n self._len = len(a)\r\n\r\n def count(self, key):\r\n if key not in self:\r\n return 0\r\n return self._data[key]\r\n\r\n def add(self, key: Hashable, val: int=1) -> None:\r\n if key in self._data:\r\n self._data[key] += val\r\n else:\r\n self._data[key] = val\r\n self._len += val\r\n\r\n def discard(self, key: Hashable, val: int=1) -> None:\r\n if key not in self._data: return\r\n if self._data[key] > val:\r\n self._len -= val\r\n self._data[key] -= val\r\n else:\r\n self._len -= self._data[key]\r\n del self._data[key]\r\n\r\n def discard_all(self, key: Hashable) -> None:\r\n if key not in self._data: return\r\n self._len -= self._data[key]\r\n del self._data[key]\r\n\r\n def len_elm(self) -> int:\r\n return len(self._data)\r\n\r\n def keys(self):\r\n for k in self._data.keys():\r\n yield k\r\n\r\n def values(self):\r\n for v in self._data.values():\r\n yield v\r\n\r\n def items(self):\r\n for item in self._data.items():\r\n yield item\r\n\r\n def clear(self):\r\n self._data = {}\r\n self._len = 0\r\n self._len_elm = 0\r\n\r\n def __contains__(self, key: Hashable):\r\n return key in self._data\r\n\r\n def __len__(self):\r\n return self._len\r\n\r\n\r\n# ----------------------- #\r\n\r\nk = int(input())\r\nA = []\r\nS = []\r\nhs = HashedMultiSet()\r\nfor _ in range(k):\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n A.append(a)\r\n sm = sum(a)\r\n st = set(sm-a_ for a_ in a)\r\n S.append(st)\r\n for s in st:\r\n hs.add(s)\r\n\r\nok = False\r\nres1 = []\r\nfor i in range(k):\r\n for j, a in enumerate(S[i]):\r\n if hs.count(a) > 1:\r\n ok = True\r\n res1 = [i, a]\r\n break\r\nif len(res1) == 0:\r\n print('NO')\r\n exit()\r\n\r\nprint('YES')\r\ni = res1[0]\r\ns = res1[1]\r\na = A[i].index(sum(A[i])-res1[1])\r\nprint(i+1, a+1)\r\nfor j in range(k):\r\n if j == i:\r\n continue\r\n if s in S[j]:\r\n print(j+1, A[j].index(sum(A[j])-s)+1)\r\n exit()\r\nassert False\r\n", "\"\"\"\r\n-*- coding: utf-8 -*-\r\n\r\nCreated on Wed Jan 19 14:45:34 2022\r\n\r\n@author: Tausif Khan Arnob\r\n\"\"\"\r\n\r\nd = {}\r\n\r\nfor i in range(1, int(input())+1):\r\n n = int(input())\r\n a = [*map(int, input().split())]\r\n s = sum(a)\r\n t = set()\r\n for j, val in enumerate(a, 1):\r\n if val not in t:\r\n t.add(val)\r\n if d.get(s-val):\r\n print('YES')\r\n print(*d[s-val])\r\n print(i, j)\r\n exit()\r\n d[s-val] = [i, j]\r\nprint('NO')", "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\nd = dict()\r\nfor x in range(int(input())):\r\n n = int(input())\r\n w = list(map(int, input().split()))\r\n s = sum(w)\r\n q = dict()\r\n for i in range(n):\r\n if q.get(w[i], 0) == 0:\r\n q[w[i]] = 1\r\n if d.get(s-w[i], 0) == 0:\r\n d[s-w[i]] = (x+1, i+1)\r\n else:\r\n print('YES')\r\n print(d[s-w[i]][0], d[s-w[i]][1])\r\n print(x+1, i+1)\r\n exit(0)\r\n else:\r\n continue\r\nelse:\r\n print('NO')", "def sum_without_one(arr, i):\r\n s = sum(arr)\r\n return [[s-x, (i+1, j+1)] for j, x in enumerate(arr)]\r\n\r\n\r\nres = []\r\nfor i in range(int(input())):\r\n input()\r\n res.extend(sum_without_one(list(map(int, input().split())), i))\r\nres.sort()\r\n# print(res)\r\nfor i in range(1, len(res)):\r\n prev, curr = res[i-1], res[i]\r\n if prev[0] == curr[0] and prev[1][0] != curr[1][0]:\r\n print('YES')\r\n print(*prev[1])\r\n print(*curr[1])\r\n break\r\nelse:\r\n print('NO')\r\n", "from sys import stdin\r\ninput = stdin.readline\r\n\r\ndef solve():\r\n sums = set()\r\n sequences = {}\r\n index = {}\r\n k = int(input())\r\n for sequence in range(k):\r\n n = int(input())\r\n a = [int(x) for x in input().split()]\r\n s = sum(a)\r\n used = set()\r\n for i in range(n):\r\n if a[i] in used:\r\n continue\r\n used.add(a[i])\r\n sum_ = s - a[i]\r\n if sum_ in sums:\r\n return (sequence, i, sequences[sum_], index[sum_])\r\n sums.add(sum_)\r\n sequences[sum_] = sequence\r\n index[sum_] = i\r\n return (-1, -1, -1, -1)\r\n\r\na, b, c, d = solve()\r\nif a == -1:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n print(a+1, b+1)\r\n print(c+1, d+1)", "from collections import defaultdict\r\nd=defaultdict(lambda:0)\r\n\r\nflag=False\r\na,b,c,e=0,0,0,0\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n\r\n x=list(map(int,input().split()))\r\n s=sum(x)\r\n\r\n\r\n for i in range(n):\r\n if d[s - x[i]] != 0 and d[s - x[i]][0] != _ + 1 and flag==False:\r\n flag = True\r\n a = d[s - x[i]][0]\r\n b = d[s - x[i]][1]\r\n c = _ + 1\r\n e = i + 1\r\n if flag==False:\r\n d[s-x[i]]=(_+1,i+1)\r\n\r\nif flag:\r\n print(\"YES\")\r\n print(a,b)\r\n print(c,e)\r\nelse:\r\n print(\"NO\")\r\n", "inf=10**18\r\ndxy=[(0,1), (1,0), (-1, 0), (0, -1)]\r\nmod=10**9+7\r\nMOD=998244353\r\n\r\ncheck = dict()\r\n\r\nN = int(input())\r\nfor j in range(N):\r\n n = int(input())\r\n A = [int(i) for i in input().split()]\r\n ss = sum(A)\r\n for n,a in enumerate(A):\r\n if ss-a in check:\r\n if check[ss-a][0] == j+1: continue\r\n else:\r\n print(\"YES\")\r\n print(*check[ss-a])\r\n print(j+1, n+1)\r\n exit()\r\n else:\r\n check[ss-a] = (j+1, n+1)\r\nprint(\"NO\")", "import sys\r\ninput = sys.stdin.readline\r\n\r\ndef main():\r\n k = int(input())\r\n dic = {}\r\n for i in range(1, k + 1):\r\n tot = 0\r\n n = int(input())\r\n A = list(map(int, input().split()))\r\n tot = sum(A)\r\n for j, a in enumerate(A, 1):\r\n tmp = tot - a\r\n if tmp not in dic:\r\n dic[tmp] = (i, j)\r\n elif dic[tmp][0] != i:\r\n print(\"YES\")\r\n print(*dic[tmp])\r\n print(i, j)\r\n return\r\n print(\"NO\")\r\n \r\n \r\nfor _ in range(1):\r\n main()", "from sys import stdin,stdout,setrecursionlimit\r\nstdin.readline\r\ndef mp(): return list(map(int, stdin.readline().strip().split()))\r\ndef it():return int(stdin.readline().strip())\r\nfrom collections import defaultdict as dd,Counter as C,deque\r\nfrom math import ceil,gcd,sqrt,factorial,log2,floor\r\nfrom bisect import bisect_right as br,bisect_left as bl\r\nimport heapq\r\n\r\nd = {}\r\nfor t in range(it()):\r\n\tn = it()\r\n\tl = mp()\r\n\ts = sum(l)\r\n\t\r\n\tfor i in range(n):\r\n\t\tx = s-l[i]\r\n\t\tif x in d and d[x][0] != t:\r\n\t\t\tprint('YES')\r\n\t\t\tprint(d[x][0]+1 , d[x][1] + 1)\r\n\t\t\tprint(t+1,i+1)\r\n\t\t\texit()\r\n\t\telif x not in d:\r\n\t\t\td[x] = (t,i)\r\nprint('NO')\r\n", "k=int(input())\r\na,c=[],{}\r\nfor i in range(k):\r\n a.append([])\r\n n,a[i],s=int(input()),[],0\r\n for j in input().split():\r\n a[i]+=[-int(j)]\r\n s+=int(j)\r\n for j in range(n):\r\n a[i][j]+=s\r\n h=c.get(a[i][j])\r\n if h!=None and h[0]!=i+1:\r\n print(\"YES\")\r\n print(h[0],h[1])\r\n print(1+i,1+j)\r\n quit()\r\n c[a[i][j]]=[i+1,j+1]\r\nprint(\"NO\")", "k = int(input())\r\nnums = []\r\nsums = []\r\nmemo = {}\r\n\r\nfor i in range(k):\r\n n = int(input())\r\n num_list = list(map(int, input().split()))\r\n nums.append(num_list)\r\n num_sum = sum(num_list)\r\n sums.append(set())\r\n \r\n for j in range(n):\r\n num = num_sum - nums[i][j]\r\n sums[i].add(num)\r\n \r\n if num not in memo:\r\n memo[num] = (i, j)\r\n else:\r\n if memo[num][0] != i:\r\n print(\"YES\")\r\n print(memo[num][0] + 1, memo[num][1] + 1)\r\n print(i + 1, j + 1)\r\n exit()\r\n\r\nprint(\"NO\")", "arr = {}\r\nfor i in range(int(input())):\r\n\tinput()\r\n\tx = list(map(int, input().split()))\r\n\tz = sum(x)\r\n\tfor j, a in enumerate(map(lambda y : z - y, x)):\r\n\t\tif a in arr:\r\n\t\t\tif arr[a][0] is not i:\r\n\t\t\t\tprint('YES')\r\n\t\t\t\tprint(arr[a][0] + 1, arr[a][1] + 1)\r\n\t\t\t\tprint(i + 1, j + 1)\r\n\t\t\t\texit()\r\n\t\telse:\r\n\t\t\tarr[a] = (i, j)\r\nprint('NO')" ]
{"inputs": ["2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1", "3\n1\n5\n5\n1 1 1 1 1\n2\n2 3", "4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2", "2\n2\n0 -10000\n2\n10000 0"], "outputs": ["YES\n2 1\n1 4", "NO", "YES\n4 1\n2 5", "YES\n2 1\n1 2"]}
UNKNOWN
PYTHON3
CODEFORCES
37
198410fd502067f83e7e63ffb6065693
Distance in Tree
A tree is a connected graph that doesn't contain any cycles. The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices. You are given a tree with *n* vertices and a positive number *k*. Find the number of distinct pairs of the vertices which have a distance of exactly *k* between them. Note that pairs (*v*, *u*) and (*u*, *v*) are considered to be the same pair. The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50000, 1<=≤<=*k*<=≤<=500) — the number of vertices and the required distance between the vertices. Next *n*<=-<=1 lines describe the edges as "*a**i* *b**i*" (without the quotes) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*), where *a**i* and *b**i* are the vertices connected by the *i*-th edge. All given edges are different. Print a single integer — the number of distinct pairs of the tree's vertices which have a distance of exactly *k* between them. 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 5 2 1 2 2 3 3 4 2 5 5 3 1 2 2 3 3 4 4 5 Sample Output 4 2
[ "# from collections import defaultdict\n# import sys\n# sys.setrecursionlimit(10**5)\n# input = sys.stdin.readline\n# ans = 0\n\n# def dfs(node, par):\n# global ans\n# counter = dict()\n\n# counter[0] = 1\n# for i in adj[node]:\n# if i == par:\n# continue\n# tmp = dfs(i, node)\n# # print(tmp)\n# for i in range(k+1):\n# if k-i in counter and i in tmp:\n# ans += tmp[i]*counter[k-i]\n# for i in range(k+1):\n# if i in counter or i in tmp:\n# if i not in counter:\n# counter[i] = 0\n# if i not in tmp:\n# tmp[i] = 0\n# counter[i]+=tmp[i]\n# # print(counter)\n# # print(node, counter)\n# for i in range(k, 0, -1):\n# if i-1 in counter:\n# counter[i] = counter[i-1]\n \n# counter[0] = 0\n# return counter\n \n# n,k = map(int, input().split())\n# adj = [[] for i in range(n)]\n\n# for i in range(n-1):\n# x,y = map(int, input().split())\n# adj[x-1].append(y-1)\n# adj[y-1].append(x-1)\n# dfs(0, -1)\n# print(ans)\n# ##pyrival template for fast IO\n\nfor _ in range(1):\n\tn,k=map(int,input().split())\n\ttree=[[] for _ in range(n+1)]\n\tfor _ in range(n-1):\n\t\ta,b=map(int,input().split())\n\t\ttree[a].append(b)\n\t\ttree[b].append(a)\n\t\n\tdp=[[0 for _ in range(k+1)] for _ in range(n+1)]\n\t\n\tidx=[0]*(n+1)\n\tstack=[(1,0)]\n\tans=0\n\tdp[1][0]=1\n \n\twhile stack:\n\t\tx,p=stack[-1]\n\t\ty=idx[x]\n\t\tif y==len(tree[x]):\n\t\t\tif x==1:\n\t\t\t\tbreak\n\t\t\tfor i in range(k,0,-1):\n\t\t\t\tdp[x][i]=dp[x][i-1]\n\t\t\tdp[x][0]=0\n\t\t\tfor i in range(k+1):\n\t\t\t\tans+=dp[p][i]*dp[x][k-i]\n\t\t\t\tdp[p][i]+=dp[x][i]\n\t\t\tstack.pop()\n\t\telse:\n\t\t\tz=tree[x][y]\n\t\t\tif z!=p:\n\t\t\t\tdp[z][0]=1\n\t\t\t\tstack.append((z,x))\n\t\t\tidx[x]+=1\n\t\n\tprint(ans)\n ", "import os, sys\r\nfrom io import BytesIO, IOBase\r\n\r\nfrom collections import defaultdict, deque, Counter\r\nfrom bisect import bisect_left, bisect_right\r\nfrom heapq import heappush, heappop\r\nfrom functools import lru_cache\r\nfrom itertools import accumulate\r\nimport math\r\n\r\n# Fast IO Region\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\nn, k = map(int, input().split())\r\ndp = [[0] * (k + 1) for _ in range(n)]\r\nfor i in range(n):\r\n dp[i][0] = 1\r\nd = {}\r\nfor i in range(n - 1):\r\n u, v = map(int, input().split())\r\n u, v = u - 1, v - 1\r\n if u not in d:\r\n d[u] = []\r\n if v not in d:\r\n d[v] = []\r\n d[u].append(v)\r\n d[v].append(u)\r\n\r\nres = 0\r\n# dfs\r\nstack = [[0, 0]]\r\nwhile stack:\r\n p, index = stack[-1]\r\n if len(d[p]) <= index:\r\n stack.pop()\r\n if stack:\r\n stack[-1][1] += 1\r\n q = stack[-1][0]\r\n for i in range(1, k + 1):\r\n dp[q][i] += dp[p][i - 1]\r\n else:\r\n if len(stack) > 1 and d[p][index] == stack[-2][0]:\r\n stack.pop()\r\n stack.append([p, index + 1])\r\n else:\r\n stack.append([d[p][index], 0])\r\n\r\n# bfs\r\nstack = [0]\r\nvisited = [False] * n\r\nwhile stack:\r\n temp = []\r\n while stack:\r\n p = stack.pop()\r\n visited[p] = True\r\n res += dp[p][-1]\r\n temp_res = 0\r\n for q in d[p]:\r\n if visited[q]:\r\n continue\r\n temp.append(q)\r\n for x in range(1, k):\r\n temp_res += dp[q][x - 1] * (dp[p][k - x] - dp[q][k - x - 1])\r\n temp_res //= 2\r\n res += temp_res\r\n stack = temp\r\nprint(res)", "import sys\r\nimport math\r\nfrom collections import deque\r\ninput = lambda: sys.stdin.readline().strip()\r\nmod = 1000000007\r\n#map(int,input().split())\r\n#int(input())\r\nn,k=map(int,input().split())\r\nG=[[] for _ in range(n+1)]\r\nson=[[] for i in range(n+1)]\r\nq=deque([1])\r\nvisted=[0]*(n+1)\r\nparent=list(range(n+1))\r\ndp=[[0 for _ in range(k+1)] for i in range(n+1)]\r\nfor i in range(n-1):\r\n edge=list(map(int,input().split()))\r\n G[edge[0]].append(edge[1])\r\n G[edge[1]].append(edge[0])\r\nq=deque([1])\r\nwhile q:\r\n temp=q.pop()\r\n dp[temp][0]=1\r\n if visted[temp]:\r\n continue\r\n visted[temp]=1\r\n for x in G[temp]:\r\n if visted[x]:\r\n continue\r\n q.appendleft(x)\r\n parent[x]=temp\r\n son[temp].append(x)\r\n j=0\r\n while j<k and parent[x]!=x:\r\n x=parent[x]\r\n j+=1\r\n dp[x][j]+=1\r\nans=0\r\nfor i in range(1,n+1):\r\n ans+=dp[i][k]\r\n if k>=2:\r\n temp=0\r\n for x in son[i]:\r\n for j in range(1,k):\r\n temp+=dp[x][j-1]*(dp[i][k-j]-dp[x][k-j-1])\r\n ans+=temp//2\r\nprint(ans)", "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\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) + \" \")\r\n# endregion fastio\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 solve() -> None:\r\n n, k = mint()\r\n g = [[] for _ in range(n)]\r\n deg = [0] * n\r\n for _ in range(n - 1):\r\n u, v = mint()\r\n u -= 1\r\n v -= 1\r\n g[u].append(v)\r\n g[v].append(u)\r\n deg[u] += 1\r\n deg[v] += 1\r\n \r\n parent = [-1] * n\r\n order = [0]\r\n stack = [0]\r\n while stack:\r\n u = stack.pop()\r\n for v in g[u]:\r\n if v == parent[u]: continue\r\n parent[v] = u\r\n order.append(v)\r\n stack.append(v)\r\n\r\n dp = [[0] * (k + 1) for _ in range(n)]\r\n ans = 0\r\n \r\n for u in order[::-1]:\r\n dp[u][0] = 1\r\n for v in g[u]:\r\n if v == parent[u]: continue\r\n # dp[u][1] += 1\r\n for i in range(k):\r\n dp[u][i + 1] += dp[v][i]\r\n \r\n ans += dp[u][k]\r\n cnt = 0\r\n for v in g[u]:\r\n if v == parent[u]: continue\r\n for i in range(1, k):\r\n cnt += dp[v][i - 1] * (dp[u][k - i] - dp[v][k - i - 1])\r\n ans += cnt // 2\r\n # print(dp)\r\n print(ans)\r\n\r\n# for _ in range(int(input())):\r\nsolve()\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# from types import GeneratorType\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", "from collections import *\r\nfrom sys import stdin\r\n\r\n\r\nclass graph:\r\n # initialize graph\r\n def __init__(self, gdict=None):\r\n self.gdict = [[] for _ in range(n + 1)]\r\n\r\n # add edge\r\n def addEdge(self, node1, node2, w=None):\r\n self.gdict[node1].append(node2)\r\n self.gdict[node2].append(node1)\r\n\r\n def subtree(self, v):\r\n queue, visit, ans = deque([v]), [0] * (n + 1), [v]\r\n visit[v], self.nodes = 1, [[0 for _ in range(k + 1)] for _ in range(n + 1)]\r\n\r\n while queue:\r\n s = queue.popleft()\r\n\r\n for i in self.gdict[s]:\r\n if not visit[i]:\r\n queue.append(i)\r\n visit[i] = 1\r\n ans.append(i)\r\n\r\n out = [0, 0]\r\n while ans:\r\n cur = ans.pop()\r\n visit[cur] = 0\r\n self.nodes[cur][0] = 1\r\n\r\n for i in self.gdict[cur]:\r\n if not visit[i]:\r\n for j in range(1, k + 1):\r\n self.nodes[cur][j] += self.nodes[i][j - 1]\r\n\r\n for i in self.gdict[cur]:\r\n for j in range(1, k):\r\n out[1] += self.nodes[i][j - 1] * (self.nodes[cur][k - j] - self.nodes[i][k - j - 1])\r\n\r\n out[0] += self.nodes[cur][k]\r\n\r\n print(out[0] + out[1] // 2)\r\n\r\n\r\nrints = lambda: [int(x) for x in stdin.readline().split()]\r\nn, k = rints()\r\ng = graph()\r\nfor _ in range(n - 1):\r\n u, v = rints()\r\n g.addEdge(u, v)\r\n\r\ng.subtree(1)\r\n", "import builtins\nfrom types import GeneratorType\nfrom typing import *\nfrom collections import *\nfrom heapq import *\nfrom functools import lru_cache\n\nimport sys\ninput = sys.stdin.readline\n\n\nclass Input:\n @staticmethod\n def str():\n return input().strip()\n\n @staticmethod\n def int():\n return int(input())\n\n @staticmethod\n def float():\n return float(input())\n\n @staticmethod\n def list(type_: builtins):\n return list(map(type_, input().split()))\n\n\ndef bootstrap(f, stack=[]):\n def wrappedfunc(*args, **kwargs):\n if stack:\n return f(*args, **kwargs)\n else:\n to = f(*args, **kwargs)\n while True:\n if type(to) is GeneratorType:\n stack.append(to)\n to = next(to)\n else:\n if not stack:\n break\n stack.pop()\n if not stack:\n break\n to = stack[-1].send(to)\n return to\n\n return wrappedfunc\n\n\nclass Solution:\n def main(self):\n N, K = Input.list(int)\n graph = defaultdict(set)\n memo = [[0] * (K + 1) for _ in range(N)]\n for _ in range(N - 1):\n u, v = Input.list(int)\n graph[u - 1].add(v - 1)\n graph[v - 1].add(u - 1)\n\n visited = set()\n @bootstrap\n def dfs(i):\n visited.add(i)\n memo[i][0] = 1\n for j in graph[i]:\n if j in visited: continue\n yield dfs(j)\n for k in range(K):\n memo[i][k + 1] += memo[j][k]\n yield\n\n dfs(0)\n res = 0\n visited = set()\n for i in range(N):\n visited.add(i)\n res += memo[i][K]\n sub = 0\n for j in graph[i]:\n if j in visited: continue\n for k in range(1, K):\n sub += memo[j][k - 1] * (memo[i][K - k] - memo[j][K - k - 1])\n sub //= 2\n res += sub\n print(res)\n\n\nSolution().main()\n", "n,k=map(int,input().split())\r\ng=[[] for i in range(n)]\r\nfor _ in range(n-1):\r\n a,b=map(int,input().split())\r\n g[a-1].append(b-1)\r\n g[b-1].append(a-1)\r\nq=[0]\r\nfor x in q:\r\n for y in g[x]:\r\n g[y].remove(x)\r\n q.extend(g[x])\r\nq.reverse()\r\nd,cnt={},0\r\nfor x in q:\r\n d[x]=[1]\r\n l_x=len(d[x])\r\n for to in g[x]:\r\n l_to=len(d[to])\r\n for i in range(max(0,k-l_x),l_to):cnt+=d[to][i]*d[x][k-i-1]\r\n if l_to>=l_x:\r\n for i in range(l_x-1):d[x][i+1]+=d[to][i]\r\n d[x]+=d[to][l_x-1:]\r\n l_x=l_to+1\r\n else:\r\n for i in range(l_to):d[x][i+1]+=d[to][i]\r\n if l_x>k:\r\n d[x].pop()\r\nprint(cnt)", "import collections\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\nimport os\r\nfrom types import GeneratorType\r\n\r\ngraphDict = collections.defaultdict\r\n\r\n\r\n\r\n\r\n################## pypy deep recursion handling ##############\r\n# Author = @pajenegod\r\ndef bootstrap(f, stack=[]):\r\n def wrappedfunc(*args, **kwargs):\r\n to = f(*args, **kwargs)\r\n if stack:\r\n return to\r\n else:\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 return to\r\n to = stack[-1].send(to)\r\n\r\n return wrappedfunc\r\n\r\n\r\n################## Graphs ###################\r\nclass Graphs:\r\n def __init__(self):\r\n self.graph = graphDict(set)\r\n\r\n def add_edge(self, u, v):\r\n self.graph[u].add(v)\r\n self.graph[v].add(u)\r\n\r\n################################ <fast I/O> ###########################################\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, **kwargs):\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\n\r\n\r\n#############################################<I/O Region >##############################################\r\n\r\n\r\ndef inp():\r\n return sys.stdin.readline().strip()\r\n\r\n\r\ndef map_inp(v_type):\r\n return map(v_type, inp().split())\r\n\r\n\r\ndef list_inp(v_type):\r\n return list(map_inp(v_type))\r\n\r\n\r\n######################################## Solution ####################################\r\nans = 0\r\n\r\n@bootstrap\r\ndef solve(child, parent):\r\n global ans\r\n dp[child][0] = 1\r\n for item in tree.graph[child]:\r\n if item == parent:\r\n continue\r\n yield solve(item, child)\r\n for i in range(1, k + 1):\r\n dp[child][i] += dp[item][i - 1]\r\n ans += dp[child][k]\r\n cnt = 0\r\n for item in tree.graph[child]:\r\n if item == parent:\r\n continue\r\n for l in range(1, k):\r\n cnt += dp[item][l - 1] * (dp[child][k - l] - dp[item][k - l - 1])\r\n ans += cnt // 2\r\n yield\r\n\r\n\r\nn, k = map_inp(int)\r\ntree = Graphs()\r\nfor i in range(n - 1):\r\n a, b = map_inp(int)\r\n tree.add_edge(a, b)\r\ndp = [[0 for col in range(k+1)] for row in range(n+1)]\r\nsolve(1, -1)\r\nprint(ans)", "from sys import * \r\nsetrecursionlimit(100000)\r\n\r\ninput=stdin.readline\r\n\r\n# n,k=map(int, input().split())\r\n# d={i:[] for i in range(n)}\r\n# for i in range(n-1):\r\n# a,b=map(int, input().split())\r\n# a-=1 \r\n# b-=1 \r\n# d[a].append(b)\r\n# d[b].append(a)\r\n\r\n# dp=[[0 for _ in range(k+1)] for _ in range(n)]\r\n\r\n# v=[0 for _ in range(n)]\r\n# ans= 0\r\n\r\n# def ss(node):\r\n# # print(node)\r\n# global ans \r\n# v[node]=1 \r\n \r\n# dp[node][0]=1 \r\n# c_arr=[]\r\n# for child in d[node]:\r\n# if v[child]==0:\r\n# ss(child)\r\n# c_arr.append(child)\r\n# for p in range(k):\r\n# dp[node][p+1]+=dp[child][p]\r\n# ans+=dp[node][k]\r\n# xx=0 \r\n# for child in c_arr:\r\n# for p in range(k-1):\r\n# # print(k-p-2)\r\n# xx+= dp[child][p]*(dp[node][k-p-1] - dp[child][k-p-2])\r\n# # print(ans)\r\n# ans+=xx//2\r\n \r\n# # print(node, c_arr, ans)\r\n\r\n# ss(0)\r\n# print(ans)\r\n\r\n\r\n\r\n########### Copied \r\n\r\nfor _ in range(1):\r\n\tn,k=map(int,input().split())\r\n\ttree=[[] for _ in range(n+1)]\r\n\tfor _ in range(n-1):\r\n\t\ta,b=map(int,input().split())\r\n\t\ttree[a].append(b)\r\n\t\ttree[b].append(a)\r\n\t\r\n\tdp=[[0 for _ in range(k+1)] for _ in range(n+1)]\r\n\t\r\n\tidx=[0]*(n+1)\r\n\tstack=[(1,0)]\r\n\tans=0\r\n\tdp[1][0]=1\r\n \r\n\twhile stack:\r\n\t\tx,p=stack[-1]\r\n\t\ty=idx[x]\r\n\t\tif y==len(tree[x]):\r\n\t\t\tif x==1:\r\n\t\t\t\tbreak\r\n\t\t\tfor i in range(k,0,-1):\r\n\t\t\t\tdp[x][i]=dp[x][i-1]\r\n\t\t\tdp[x][0]=0\r\n\t\t\tfor i in range(k+1):\r\n\t\t\t\tans+=dp[p][i]*dp[x][k-i]\r\n\t\t\t\tdp[p][i]+=dp[x][i]\r\n\t\t\tstack.pop()\r\n\t\telse:\r\n\t\t\tz=tree[x][y]\r\n\t\t\tif z!=p:\r\n\t\t\t\tdp[z][0]=1\r\n\t\t\t\tstack.append((z,x))\r\n\t\t\tidx[x]+=1\r\n\t\r\n\tprint(ans)\r\n \r\n ", "n, k = map(int, input().split())\r\nt, q = [[] for i in range(n + 1)], [1]\r\n\r\nfor j in range(n - 1):\r\n a, b = map(int, input().split())\r\n t[a].append(b)\r\n t[b].append(a)\r\nfor x in q:\r\n for y in t[x]: t[y].remove(x)\r\n q.extend(t[x])\r\nq.reverse()\r\n\r\na, s = {}, 0\r\nfor x in q:\r\n a[x] = [1]\r\n u = len(a[x])\r\n for y in t[x]:\r\n v = len(a[y])\r\n for d in range(max(0, k - u), v): s += a[y][d] * a[x][k - d - 1]\r\n if v >= u:\r\n for d in range(u - 1): a[x][d + 1] += a[y][d]\r\n a[x] += a[y][u - 1: ]\r\n u = v + 1\r\n else:\r\n for d in range(0, v): a[x][d + 1] += a[y][d]\r\n if u > k: a[x].pop()\r\nprint(s)", "def II():\r\n return(int(input()))\r\ndef I():\r\n return(input())\r\ndef LMI():\r\n return(list(map(int,input().split())))\r\ndef MII():\r\n return(map(int,input().split()))\r\n# import io,os\r\n# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\nimport math\r\nimport sys\r\ninput=sys.stdin.readline\r\n# import bisect\r\nfrom collections import defaultdict\r\nfrom collections import deque\r\ndef t():\r\n n,k=MII()\r\n G=defaultdict(list)\r\n for i in range(n-1):\r\n a,b=MII()\r\n G[a].append(b)\r\n G[b].append(a)\r\n D=deque()\r\n D.append(1)\r\n seq=[]\r\n Parent=[0]*(n+1)\r\n Parent[1]=1\r\n while D:\r\n a=D.popleft()\r\n seq.append(a)\r\n for j in G[a]:\r\n if Parent[a]!=j:\r\n D.append(j)\r\n Parent[j]=a\r\n\r\n dp=[[0]*(k+1) for j in range(n+1)]\r\n for i in range(1,n+1):\r\n dp[i][0]=1\r\n for a in seq[::-1]:\r\n for j in G[a]:\r\n if j!=Parent[a]:\r\n for l in range(1,k+1):\r\n dp[a][l]+=dp[j][l-1]\r\n\r\n for j in seq:\r\n if j==1:continue\r\n\r\n for i in range(k,1,-1):\r\n dp[j][i]+=dp[Parent[j]][i-1]-dp[j][i-2]\r\n dp[j][1]+=1\r\n ans=0\r\n for j in range(1,n+1):\r\n ans+=dp[j][k]\r\n\r\n print(ans//2)\r\n\r\n\r\n\r\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 # for _ in range(II()):\r\n # t()\r\n t()\r\n\r\n\r\n\r\n", "from collections import defaultdict as dd, deque as dq, Counter as ctr\r\nimport sys\r\n\r\nfrom re import search\r\ninput = lambda: sys.stdin.readline().rstrip('\\r\\n')\r\n \r\nfrom bisect import bisect_left as bl\r\nfrom bisect import bisect_right as br\r\n\r\ninp = lambda: int(sys.stdin.readline().rstrip(\"\\r\\n\"))\r\nmi = lambda x=int : map(x, sys.stdin.readline().rstrip(\"\\r\\n\").split())\r\nli = lambda x=int: list(mi(x))\r\nlb = lambda: list(map(int, sys.stdin.readline().rstrip(\"\\r\\n\")))\r\nls = lambda: list(sys.stdin.readline().rstrip(\"\\r\\n\"))\r\nbi = lambda n: bin(n).replace(\"0b\", \"\")\r\n\r\ndef sbsq(a,s):\r\n i=0\r\n for x in s:\r\n if i>=len(a):\r\n break\r\n if x==a[i]:\r\n i+=1\r\n return i==len(a)\r\n\r\nyn = ['No', 'Yes']\r\nYN = ['NO', 'YES']\r\nYY = \"YES\"\r\nNN = \"NO\"\r\nyy = \"Yes\"\r\nnn = \"No\"\r\ninf= sys.maxsize\r\nmod=1e9+7\r\n\r\nfrom math import log2,ceil,sqrt\r\nimport heapq as hq\r\n\r\n\r\n\r\ndef main(kase):\r\n n,k=mi()\r\n grp=dd(list)\r\n for i in range(n-1):\r\n u,v=mi()\r\n grp[u].append(v)\r\n grp[v].append(u)\r\n q=dq([1])\r\n vis=[0]*(n+1)\r\n vis[1]=True\r\n bfs=[1]\r\n dp=[[0 for i in range(k+1)] for j in range(n+1)]\r\n while q:\r\n s=q.popleft()\r\n for x in grp[s]:\r\n if not vis[x]:\r\n q.append(x)\r\n vis[x]=True\r\n bfs.append(x)\r\n ans=[0,0]\r\n # print(bfs)\r\n while bfs:\r\n nd=bfs.pop()\r\n vis[nd]=0\r\n dp[nd][0]=1\r\n for i in grp[nd]:\r\n if not vis[i]:\r\n for j in range(1,k+1):\r\n dp[nd][j]+=dp[i][j-1]\r\n for i in grp[nd]:\r\n for j in range(1,k):\r\n ans[1]+=dp[i][j-1]*(dp[nd][k-j]-dp[i][k-j-1])\r\n ans[0]+=dp[nd][k]\r\n print(ans[0]+ans[1]//2)\r\n \r\n\r\n pass\r\nif __name__ == \"__main__\":\r\n test_Cases=1\r\n # test_Cases=inp()\r\n for i in range(test_Cases):\r\n main(i)" ]
{"inputs": ["5 2\n1 2\n2 3\n3 4\n2 5", "5 3\n1 2\n2 3\n3 4\n4 5", "10 1\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6", "10 2\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6", "10 3\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6", "50 3\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n16 15\n17 16\n18 17\n19 18\n20 19\n21 20\n22 21\n23 22\n24 23\n25 24\n26 25\n27 26\n28 27\n29 28\n30 29\n31 30\n32 31\n33 32\n34 33\n35 34\n36 35\n37 36\n38 37\n39 38\n40 39\n41 40\n42 41\n43 42\n44 43\n45 44\n46 45\n47 46\n48 47\n49 48\n50 49", "50 4\n2 1\n3 1\n4 2\n5 2\n6 3\n7 3\n8 4\n9 4\n10 5\n11 5\n12 6\n13 6\n14 7\n15 7\n16 8\n17 8\n18 9\n19 9\n20 10\n21 10\n22 11\n23 11\n24 12\n25 12\n26 13\n27 13\n28 14\n29 14\n30 15\n31 15\n32 16\n33 16\n34 17\n35 17\n36 18\n37 18\n38 19\n39 19\n40 20\n41 20\n42 21\n43 21\n44 22\n45 22\n46 23\n47 23\n48 24\n49 24\n50 25", "50 5\n2 1\n3 1\n4 2\n5 2\n6 4\n7 4\n8 6\n9 6\n10 8\n11 8\n12 10\n13 10\n14 12\n15 12\n16 14\n17 14\n18 16\n19 16\n20 18\n21 18\n22 20\n23 20\n24 22\n25 22\n26 24\n27 24\n28 26\n29 26\n30 28\n31 28\n32 30\n33 30\n34 32\n35 32\n36 34\n37 34\n38 36\n39 36\n40 38\n41 38\n42 40\n43 40\n44 42\n45 42\n46 44\n47 44\n48 46\n49 46\n50 48", "10 20\n2 1\n3 2\n4 1\n5 3\n6 4\n7 1\n8 2\n9 7\n10 2"], "outputs": ["4", "2", "9", "10", "8", "47", "124", "84", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
12
19a6ec21c8071eaac811c5d886bdbcb5
Bear and Friendship Condition
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z. For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well. Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes. The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends. The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input. If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes). Sample Input 4 3 1 3 3 4 1 4 4 4 3 1 2 3 3 4 1 2 10 4 4 3 5 10 8 9 1 2 3 2 1 2 2 3 Sample Output YES NO YES NO
[ "def li(): return list(map(int,input().split())) \r\ndef ls(): return list(map(int,list(input())))\r\ndef i(): return int(input())\r\nfrom collections import defaultdict\r\ngraph = defaultdict(list)\r\nn,m = li()\r\nfor _ in range(m):\r\n x,y = li()\r\n graph[x].append(y)\r\n graph[y].append(x)\r\nvisited= [False]*(n+1)\r\nflag = 1\r\nfor i in range(n+1):\r\n if graph[i+1] :\r\n graph[i+1].append(i+1)\r\n graph[i+1].sort()\r\n# print(graph)\r\nfor i in range(n):\r\n if visited[i+1] == False:\r\n visited[i+1] = True\r\n for x in graph[i+1]:\r\n if visited[x] == False:\r\n visited[x] = True\r\n # print(graph[x],graph[i+1])\r\n if graph[x] != graph[i+1] :\r\n flag = 0\r\n break\r\nif flag == 1:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n ", "from sys import stdin\nfrom collections import deque\n\ndef main():\n input = stdin.readline\n n,m = [int(i) for i in input().split()]\n graph = {i+1:set() for i in range(n)}\n for _ in range(m):\n a,b = [int(i) for i in input().split()]\n graph[a].add(b)\n graph[b].add(a)\n\n seen = set()\n for i in range(1,n+1):\n if i in seen:\n continue\n seen_i = {i}\n que = deque([i])\n while que:\n cur = que.popleft()\n for nxt in graph[cur]:\n if nxt not in seen_i:\n seen_i.add(nxt)\n que.append(nxt)\n total_edges = 0\n for i in seen_i:\n total_edges += len(graph[i])\n total_edges //= 2\n if total_edges != len(seen_i) * (len(seen_i)-1) // 2:\n print(\"NO\")\n exit()\n seen |= seen_i\n print(\"Yes\")\n\nif __name__ == '__main__':\n main()\n\t\t \t\t \t \t \t\t\t \t\t \t\t\t \t\t", "n, m = [int(x) for x in input().split()]\nd = {}\naux = set()\n\nfor x in range(m):\n a, b = input().split()\n d.setdefault(a, {a}).add(b)\n d.setdefault(b, {b}).add(a)\nres = \"YES\"\n\nfor x, y in d.items():\n if x not in aux:\n if all([d[u] == y for u in y]):\n aux.update(y)\n else:\n res = \"NO\"\n break\nprint(res)\n\n \t\t\t\t\t\t\t \t\t \t \t \t\t\t\t \t\t \t\t", "def read():\n n, m = map(int, input().rstrip().split())\n graph = [set() for _ in range(n + 1)]\n for _ in range(m):\n a, b = map(int, input().rstrip().split())\n graph[a].add(b)\n graph[b].add(a)\n graph[a].add(a)\n graph[b].add(b)\n return (graph, n)\n \ndef main():\n graph, n = read() \n seen = set()\n for i in range(1, n + 1):\n if len(graph[i]) > 0 and i not in seen:\n if not all(graph[i] == graph[j] for j in graph[i]):\n return False\n seen |= graph[i]\n return True\n \nif __name__ == '__main__':\n if main():\n print('YES')\n else:\n print('NO')\n \t\t\t\t \t\t \t \t \t\t\t\t\t", "n, m = map(int, input().split())\ndict = {}\naux = set()\n\nfor i in range(m):\n a, b = input().split()\n dict.setdefault(b, {b}).add(a)\n dict.setdefault(a, {a}).add(b)\n \nout = 'YES'\nfor e, e2 in dict.items():\n if e not in aux:\n \n if all ([dict[u] == e2 for u in e2] ):\n aux.update(e2)\n else :\n out ='NO'\n break\n \nprint(out)\n#yash\n \t \t \t\t \t\t \t \t \t\t\t \t\t\t", "n, m = map(int, input().split())\n\ngrafo = {}\nvisitados = set()\nsaida = 'YES'\n\nfor i in range(m):\n a, b = map(int, input().split())\n if not a in grafo.keys():\n grafo[a] = set([a])\n if not b in grafo.keys():\n grafo[b] = set([b])\n grafo[a].add(b)\n grafo[b].add(a)\n\nfor i, j in grafo.items():\n if i not in visitados:\n if len(list(filter(lambda x: grafo[x] != j, j))) == 0:\n visitados.update(j)\n else:\n saida = 'NO'\n break\n\nprint(saida)\n", "num, numPair = map(int, input().strip().split())\ndiscovered = [False] * num\nadj = [set([i]) for i in range(num)]\nfor _ in range(numPair):\n u, v = map(int, input().strip().split())\n adj[u - 1].add(v - 1)\n adj[v - 1].add(u - 1)\n\ndef verify():\n for u in range(num):\n if not discovered[u]:\n for v in adj[u]:\n discovered[v] = True\n if adj[u] != adj[v]:\n return False\n return True\n\nif verify():\n print(\"YES\")\nelse:\n print(\"NO\")\n \t \t\t\t \t\t\t\t\t\t\t \t \t \t \t", "from sys import stdin\r\ninput=stdin.readline\r\n#cliques .... .. .. . .\r\nclass dsu():\r\n\tdef __init__(self,n):\r\n\t\tself.parent=[0]*(n)\r\n\t\tself.sz=[0]*(n)\r\n\r\n\tdef make_set(self,v):\r\n\t\tself.parent[v]=v\r\n\t\tself.sz[v]=1\r\n\r\n\tdef find_set(self,v):\r\n\t\tif v==self.parent[v]:\r\n\t\t\treturn v\r\n\t\tself.parent[v]=self.find_set(self.parent[v])\r\n\t\treturn self.parent[v]\r\n\r\n\tdef union(self,a,b):\r\n\t\ta=self.find_set(a)\r\n\t\tb=self.find_set(b)\r\n\t\tif a==b:\r\n\t\t\treturn\r\n\t\tif self.sz[a]<self.sz[b]:\r\n\t\t\ta,b=b,a\r\n\t\tself.parent[b]=a\r\n\t\tself.sz[a]+=self.sz[b]\r\n\r\n\tdef getsize(self,v):\r\n\t\treturn self.sz[self.find_set(v)]\r\n\r\nfrom collections import defaultdict\r\n\r\nn,m=map(int,input().strip().split())\r\nds=dsu(n)\r\nfor i in range(n):\r\n\tds.make_set(i)\r\n\r\ndeg=[0]*n\r\nedge=[]\r\niscycle=set()\r\nfor i in range(m):\r\n\tx,y=map(lambda s:int(s)-1,input().strip().split())\r\n\tdeg[x]+=1\r\n\tdeg[y]+=1\r\n\tif ds.find_set(x)!=ds.find_set(y):\r\n\t\tds.union(x,y)\r\n\tedge.append((x,y))\r\ne=defaultdict(list)\r\nv=defaultdict(set)\r\nfor x,y in edge:\r\n\tl=ds.find_set(x)\r\n\te[l].append((x,y))\r\n\tv[l].add(x)\r\n\tv[l].add(y)\r\nfor i in e:\r\n\tl=len(e[i])\r\n\tl2=len(v[i])\r\n\tif l!=(l2*(l2-1))//2:\r\n\t\tprint(\"NO\")\r\n\t\texit()\r\n\r\nprint(\"YES\")\r\n", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nfrom collections import Counter\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 a-=1;b-=1\r\n P[a].append(b)\r\n P[b].append(a)\r\n\r\nseen = [0]*N\r\n\r\ndef paint(idx, color):\r\n v = [idx]\r\n while v:\r\n i = v.pop()\r\n if seen[i]:continue\r\n seen[i] = color\r\n \r\n for j in P[i]:\r\n if seen[j]:continue\r\n v.append(j)\r\n\r\ncolor = 1\r\nfor i in range(N):\r\n if seen[i]==0:\r\n paint(i,color)\r\n color+=1\r\n\r\nC = Counter(seen)\r\nans = 'YES'\r\nfor i in range(N):\r\n cnt = C[seen[i]]\r\n if len(P[i])!=cnt-1:\r\n ans = 'NO'\r\n break\r\n \r\nprint(ans)\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\ndef traverse(x):\r\n\tglobal count\r\n\tstack=[x]\r\n\twhile stack:\r\n\t\tx=stack.pop()\r\n\t\tif x not in visited:\r\n\t\t\tfor i in graph[x]:\r\n\t\t\t\tcount+=1\r\n\t\t\t\tstack.append(i)\r\n\t\t\t\tgraph[i].remove(x)\r\n\t\t\tvisited.add(x)\r\nn,m=map(int,input().split())\r\ngraph=[set([i]) for i in range(n+1)]\r\ns=set()\r\nans=[0 for i in range(n+1)]\r\nfor i in range(m):\r\n\ta,b=map(int,input().split())\r\n\tgraph[a].add(b)\r\n\tgraph[b].add(a)\r\n\ts.add(a)\r\n\ts.add(b)\r\ncount=0\r\nvisi=set()\r\nfor i in range(n):\r\n\tif ans[i]==0:\r\n\t\tans[i]=1\r\n\t\tfor j in graph[i]:\r\n\t\t\tans[j]=1\r\n\t\t\tif graph[i]!=graph[j]:\r\n\t\t\t\tprint('NO')\r\n\t\t\t\texit()\r\nprint('YES')\r\n", "from sys import stdin, stdout\r\nimport collections , heapq , bisect , math\r\ninput = stdin.readline\r\n\r\ndef rint() :\r\n return int(input())\r\ndef rstr() :\r\n return input().strip()\r\ndef rlstr() :\r\n return list(input().strip().split())\r\ndef rlint() :\r\n return list(map(int , input().split()))\r\n\r\ndef main():\r\n n , m = rlint()\r\n graph = collections.defaultdict(list)\r\n indegree = [0]*n\r\n\r\n for _ in range(m) :\r\n u , v = rlint()\r\n u -= 1\r\n v -= 1\r\n indegree[u] += 1\r\n indegree[v] += 1\r\n graph[u].append(v)\r\n graph[v].append(u)\r\n\r\n visit = [False]*n\r\n\r\n for i in range(n) :\r\n if not visit[i] :\r\n queue = collections.deque()\r\n queue.append(i)\r\n visit[i] = True\r\n no_nodes = 0\r\n nodes = []\r\n\r\n while queue :\r\n u = queue.popleft()\r\n no_nodes += 1\r\n nodes.append(u)\r\n\r\n for v in graph[u] :\r\n if not visit[v] :\r\n visit[v] = True\r\n queue.append(v)\r\n\r\n for v in nodes :\r\n if indegree[v] != no_nodes - 1 :\r\n return False\r\n\r\n return True\r\n\r\nif __name__ == \"__main__\": \r\n print('YES' if main() else 'NO')", "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\n# sys.setrecursionlimit(10**5)\r\n\r\ndef main():\r\n\tn, m = read()\r\n\tadj = defaultdict(set)\r\n\tfor i in range(1, n+1):adj[i].add(i)\r\n\tfor i in range(m):\r\n\t\tu, v = read()\r\n\t\tadj[u].add(v)\r\n\t\tadj[v].add(u)\r\n\tvisited = defaultdict(int)\r\n\tfor i in range(1, n+1):\r\n\t\tif not visited[i]:\r\n\t\t\tfor child in adj[i]:\r\n\t\t\t\tif not visited[child]:\r\n\t\t\t\t\tvisited[child] = 1\r\n\t\t\t\t\tif adj[i] != adj[child]:\r\n\t\t\t\t\t\tprint(\"NO\")\r\n\t\t\t\t\t\texit()\r\n\tprint(\"YES\")\r\n\r\n\t\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tmain()", "\nn,m=[int(x)for x in input().split()]\nd={}\ncon=set()\nfor x in range(m):\n a,b=input().split()\n d.setdefault(a,{a}).add(b)\n d.setdefault(b,{b}).add(a)\nres=None\nfor x,y in d.items():\n if x not in con:\n if all([d[u]==y for u in y]):\n con.update(y)\n else:\n res='NO'\n break\nif not res:\n res='YES'\nprint(res)\n \t \t\t\t\t \t \t\t \t\t\t\t\t", "\r\ndef inicializa(m):\r\n for i in range(m):\r\n p[i] = i\r\n\r\n\r\n\r\ndef find(a):\r\n if p[a] == a:\r\n return a\r\n p[a] = find(p[a])\r\n return p[a]\r\n\r\ndef union(a,b):\r\n a,b = find(a),find(b)\r\n if a != b:\r\n if size[a] <size[b]:\r\n a,b = b,a\r\n p[b] = a\r\n size[a] += size[b]\r\n\r\n\r\nn_v, n_a = map(int,input().split())\r\np = [0] * (1+n_v)\r\nsize = [1] * (n_v+1)\r\ngrafo ={}\r\nfor i in range(1,n_v+1):\r\n grafo[i] = []\r\n\r\ninicializa(n_v+1)\r\nresonable = \"YES\"\r\nfor i in range(n_a):\r\n v1,v2 = map(int,input().split())\r\n union(v1,v2)\r\n grafo[v1].append(v2)\r\n grafo[v2].append(v1)\r\n\r\nfor i in range(1,len(p)):\r\n if len(grafo[i]) != (size[p[i]] -1):\r\n resonable = \"NO\"\r\n break\r\nprint(resonable)", "from collections import Counter as cntr\r\nfrom math import inf\r\ndef cin():\r\n\treturn map(int, input().split(' '))\r\ndef dfs(graph, src, n):\r\n\tq = [src]\r\n\th = 0\r\n\tglobal visited\r\n\tedges = 0\r\n\twhile q:\r\n\t\tidx = q.pop()\r\n\t\th += 1\r\n\r\n\t\tfor v in graph[idx]:\r\n\t\t\tedges += 1\r\n\t\t\tif visited[v] == False:\r\n\t\t\t\tvisited[v] = True\r\n\t\t\t\tq.append(v)\r\n\treturn h,edges\r\nn,m = cin()\r\ng = {i:[] for i in range(n)}\r\nfor i in range(m):\r\n\ta, b = cin()\r\n\ta -= 1\r\n\tb -= 1\r\n\tg[a].append(b)\r\n\tg[b].append(a)\r\nvisited = [False for i in range(n)]\r\nfor i in range(n):\r\n\tif visited[i] == False:\r\n\t\tvisited[i] = True\r\n\t\tv,e = dfs(g, i, n)\r\n\t\te = e//2\r\n\r\n\t\tif e != (v*(v-1))//2:\r\n\t\t\tprint('NO')\r\n\t\t\texit(0)\r\nprint('YES')\r\n\r\n\r\n", "n , m = map(int , input().split())\nmarked = [0] * n\nadjlist = [set([i]) for i in range(n)]\nfor i in range(m):\n v1 , v2 = map(int , input().split())\n v1 -= 1\n v2 -= 1\n adjlist[v1].add(v2)\n adjlist[v2].add(v1)\nfor i in range(n):\n if not marked[i]:\n for j in adjlist[i]:\n marked[j] = 1\n if adjlist[i] != adjlist[j] :\n print('NO')\n exit(0)\nprint('YES')\n\t \t\t\t\t \t\t \t \t\t\t \t \t\t\t \t", "import heapq\r\ndef findc(node):\r\n p=[node]\r\n visited[node]=True\r\n stack=[node]\r\n while stack:\r\n node=stack.pop()\r\n for child in g[node]:\r\n if visited[child]==False:\r\n visited[child]=True\r\n stack.append(child)\r\n p.append(child)\r\n return p\r\nn,m=map(int,input().split())\r\ng={i:[] for i in range(1,n+1)}\r\ndegree=[0 for i in range(n+1)]\r\nvisited=[False for i in range(n+1)]\r\nfor i 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 degree[a]=degree[a]+1\r\n degree[b]=degree[b]+1\r\nc=[]\r\nfor i in range(1,n+1):\r\n if visited[i]==False:\r\n c.append(findc(i))\r\nans=0\r\nfor i in c:\r\n f=0\r\n l=len(i)\r\n for node in i:\r\n if degree[node]!=l-1:\r\n f=1\r\n break\r\n if f==1:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")\r\n \r\n \r\n \r\n\r\n\r\n \r\n ", "import sys\nimport collections\n \n \ndef bfs(u, list, vector):\n dq = collections.deque()\n \n dq.append(u)\n vector[u] = True\n edge = 0\n vertex = 0\n \n while dq:\n u = dq.popleft()\n \n vertex += 1\n edge += len(list[u])\n \n for v in list[u]:\n if not vector[v]:\n vector[v] = True\n dq.append(v)\n \n edge = edge // 2\n return bool(edge == ((vertex * vertex - vertex) // 2))\n \n \ndef main():\n \n iterator = iter(map(int, sys.stdin.read().split()))\n \n n = next(iterator)\n m = next(iterator)\n \n list = [[] for _ in range(n+3)]\n \n for _ in range(m):\n u = next(iterator)\n v = next(iterator)\n list[u].append(v)\n list[v].append(u)\n \n vector = [False] * (n+3)\n \n for u in range(1, n+1):\n if not vector[u]:\n if not bfs(u, list, vector):\n sys.stdout.write(\"NO\\n\")\n return\n \n sys.stdout.write(\"YES\\n\")\n \n \nif __name__ == '__main__':\n main()\n \t \t \t\t \t \t \t \t \t \t\t", "n, m = map(int, input().split())\n\ng = dict()\nvisited = set()\nans = 'YES'\n\nfor i in range(m):\n a, b = map(int, input().split())\n g.setdefault(a, {a}).add(b)\n g.setdefault(b, {b}).add(a)\n\nfor k, v in g.items():\n if k not in visited:\n if all([g[vv] == v for vv in v]): visited.update(v)\n else:\n ans = 'NO'\n break\n\nprint(ans)\n\n\t\t \t\t \t\t\t\t\t\t\t \t\t \t\t\t\t\t \t \t \t", "from collections import deque\n\n#To start code\nimport sys\nfrom collections import *\nsys.setrecursionlimit(10**5)\nitr = (line for line in sys.stdin.read().strip().split('\\n'))\nINP = lambda: next(itr)\ndef ni(): return int(INP())\ndef nl(): return [int(_) for _ in INP().split()]\n\n\n#G IS REASONABLE IF ALL DISTINCT PAIRS OF THREE ARE CONNECTED\nn, m = nl()\n\ng = [[] for _ in range(n+1)]\nfor _ in range(m):\n a, b = nl()\n g[a].append(b)\n g[b].append(a)\n\n#For this to be true each component has to be a clique\n#This is only true for strongly connected components\n\nvis = [0 for _ in range(n+1)]\n\ndef dfs(s):\n edges = 0\n verticies = 1\n vis[s] = True\n q = deque([s])\n while q:\n node = q.pop()\n edges += len(g[node])\n for v in g[node]:\n if not vis[v]:\n verticies += 1\n q.append(v)\n vis[v] = 1\n\n edges = edges / 2\n possible = False\n #print(\"here\", verticies, edges)\n if edges == (verticies * (verticies - 1)) / 2:\n possible = True\n\n return possible\n\np = True\nfor vert in range(1,n+1):\n if not vis[vert]:\n #print(\"starting at: \", vert)\n if not dfs(vert):\n p = False\n\nif p: print(\"YES\")\nelse: print(\"NO\")\n\n", "import sys,io,os\r\ninput=sys.stdin.readline\r\n#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\nimport math\r\nfrom math import factorial, inf, gcd, sqrt\r\nfrom heapq import *\r\nfrom functools import *\r\nfrom itertools import *\r\nfrom collections import *\r\nfrom typing import *\r\nfrom bisect import *\r\nimport random\r\nsys.setrecursionlimit(10**5)\r\n\r\n\r\ndef find(u,roots):\r\n while roots[u] !=u:\r\n roots[u] = roots[roots[u]]\r\n u= roots[u]\r\n return u\r\n\r\ndef union(u,v , roots, ranks):\r\n\r\n uroot = find(u,roots)\r\n vroot = find(v,roots)\r\n\r\n if uroot != vroot:\r\n\r\n if ranks[uroot] < ranks[vroot]:\r\n roots[vroot] = roots[uroot]\r\n elif ranks[uroot] < ranks[vroot]:\r\n roots[uroot] = roots[vroot]\r\n else:\r\n ranks[uroot] +=1\r\n roots[vroot] = roots[uroot]\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nn,m = map(int,input().split())\r\n\r\nroots = [i for i in range(n)]\r\nrank =[0]*n\r\n\r\n\r\nfor i in range(m):\r\n a,b = map(int,input().split())\r\n a-=1\r\n b-=1\r\n\r\n union(a,b, roots, rank)\r\n\r\nans=0\r\n\r\nabhi = {}\r\n\r\n\r\nfor i in range(n):\r\n\r\n par = find(i , roots)\r\n\r\n if par in abhi:\r\n abhi[par]+=1\r\n else:\r\n abhi[par]=1\r\n\r\nfor key ,value in abhi.items():\r\n\r\n ans += value *(value-1)//2\r\n\r\nif ans == m:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n \r\n", "num, p = [int(w) for w in input().split()]\nd = [False]*num\nj = [set([i]) for i in range(num)]\nfor i in range(p):\n u, v = [int(w) for w in input().split()]\n j[u-1].add(v-1)\n j[v-1].add(u-1)\n \ndef test():\n for i in range(num):\n if not d[i]:\n \n for v in j[i]:\n d[v] = True\n if j[i]!=j[v]:\n return False\n return True\n \nif test():\n print(\"YES\")\nelse:\n print(\"NO\")\n\t \t \t \t \t\t \t \t\t\t \t \t\t \t", "n, m = map(int, input().split())\ncon = [0] * n\nlista_amigos = [set([i]) for i in range(n)]\nfor i in range(m):\n v1, v2 = map(int, input().split())\n v1 -= 1\n v2 -= 1\n lista_amigos[v1].add(v2)\n lista_amigos[v2].add(v1)\n\nfor i in range(n):\n if not con[i]:\n for j in lista_amigos[i]:\n con[j] = 1\n if lista_amigos[i] != lista_amigos[j]:\n print('NO')\n exit(0)\nprint('YES')\n\t \t\t \t \t\t\t \t \t\t \t\t\t \t", "import math,sys,bisect,heapq\r\nfrom collections import defaultdict,Counter,deque\r\nfrom itertools import groupby,accumulate\r\nfrom functools import lru_cache\r\n#sys.setrecursionlimit(200000000)\r\nint1 = lambda x: int(x) - 1\r\n#def input(): return sys.stdin.readline().strip()\r\ninput = iter(sys.stdin.buffer.read().decode().splitlines()).__next__\r\naj = lambda: list(map(int, input().split()))\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\nG = defaultdict(list)\r\n\r\ndef addEdge(a,b):\r\n G[a].append(b)\r\n G[b].append(a)\r\n\r\nN,M = aj()\r\nvis = [False]*(N+1)\r\n\r\n\r\ndef dfs(node):\r\n s = deque()\r\n vis[node] = True\r\n s.append(node)\r\n C = []\r\n while s:\r\n x= s.pop()\r\n C.append(x)\r\n for i in G.get(x,[]):\r\n if not(vis[i]):\r\n vis[i] = True\r\n s.append(i)\r\n return C\r\n \r\nedge = set()\r\nfor i in range(M):\r\n u,v = aj()\r\n edge.add((u,v))\r\n edge.add((v,u))\r\n addEdge(u,v)\r\n \r\nfor i in range(1,N+1):\r\n if not vis[i]:\r\n C = dfs(i)\r\n n= len(C)\r\n for i in range(n):\r\n for j in range(i+1,n):\r\n if not((C[i],C[j]) in edge):\r\n Y(0)\r\n exit(0)\r\nY(1)", "# @author Nayara Souza\n# UFCG - Universidade Federal de Campina Grande\n# AA - Basico\n\nfrom collections import defaultdict\n\nn, m = list(map(int, input().split()))\n\ns = defaultdict(set)\n\nl = [False]*(n+1)\n\n\nfor i in range(m):\n u, v = list(map(int,input().split()))\n s[u].add(v)\n s[v].add(u)\n\nfor i in s:\n s[i].add(i)\n\nfor i in range(1,n+1):\n if not l[i]:\n for j in s[i]:\n l[j]=True\n \n if s[i]!=s[j]:\n print(\"NO\")\n exit()\nprint('YES')\n\t \t \t\t\t \t \t \t\t\t\t \t \t\t \t", "n, m = map(int, input().split())\r\nc = {i: {i} for i in range(1, n + 1)}\r\ns = [1] * n\r\n\r\nfor i in range(m):\r\n x, y = map(int, input().split())\r\n c[x].add(y)\r\n c[y].add(x)\r\n\r\nf = 1\r\n\r\nfor i in c:\r\n if s[i - 1]:\r\n for j in c[i]:\r\n s[j - 1] = 0\r\n if c[i] != c[j]:\r\n f = 0\r\n\r\nprint('YES') if f else print('NO')\r\n", "from sys import *\nf = lambda: map(int, stdin.readline().split())\nn, m = f()\ng = [[i] for i in range(n + 1)]\nfor j in range(m):\n u, v = f()\n g[u].append(v)\n g[v].append(u)\nk = 'YES'\nfor t in g: t.sort()\nfor t in g:\n s = len(t)\n if s > 1 and not all(g[x] == t for x in t):\n k = 'NO'\n break\n for j in t: g[j] = []\nprint(k)\n \t \t \t\t \t \t\t \t \t\t\t \t \t\t \t", "n, m = map(int, input().split())\ngraph = {}\nvisiteds = {}\n \nfor i in range(m):\n a, b = map(int, input().split())\n \n if (a in graph):\n graph[a][b] = True\n else:\n graph[a] = {b: True, a: True}\n \n if (b in graph):\n graph[b][a] = True\n else:\n graph[b] = {a: True, b: True}\n \n \ndef get_result(value):\n for key in graph[value]:\n visiteds[key] = True\n if graph[value] != graph[key]:\n return False\n return True\n \n \ndef result():\n for i in graph:\n if not i in visiteds:\n result = get_result(i)\n if (not result):\n return 'NO'\n return 'YES'\n \n \nprint(result())\n\t \t\t\t \t\t\t\t \t \t\t\t\t \t \t \t\t\t\t", "import io, os\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n\r\nfrom collections import defaultdict\r\nn, m = map(int, input().split())\r\nadj = defaultdict(list)\r\n\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n adj[a].append(b)\r\n adj[b].append(a)\r\n \r\nv = [0]*(n+1)\r\nok = True\r\n\r\nfor i in range(1, 1+n):\r\n if not v[i]:\r\n ct = 0\r\n q = [i]\r\n ml = 1e18\r\n mxl = 0\r\n \r\n while q:\r\n e = q.pop()\r\n \r\n if not v[e]:\r\n ml = min(ml, len(adj[e]))\r\n mxl = max(mxl, len(adj[e]))\r\n ct += 1\r\n \r\n v[e] = 1\r\n \r\n for j in adj[e]:\r\n if not v[j]:\r\n q.append(j)\r\n \r\n if ct != 1 and (ml != ct-1 or mxl != ct-1):\r\n ok = False\r\n break\r\n\r\nprint(\"YES\" if ok else \"NO\")", "# Lectura de la cantidad de nodos (n) y aristas (m)\nn, m = map(int, input().split())\n\n# Marcador para nodos visitados\nvisitados = [0] * n\n\n# Lista de amigos inicializada con conjuntos unitarios\nlista_amigos = [set([i]) for i in range(n)]\n\n# Lectura y construcción de la lista de amigos\nfor i in range(m):\n v1, v2 = map(int, input().split())\n v1 -= 1\n v2 -= 1\n lista_amigos[v1].add(v2)\n lista_amigos[v2].add(v1)\n\n# Verificación de componentes conexas\nfor i in range(n):\n if not visitados[i]:\n for j in lista_amigos[i]:\n visitados[j] = 1\n # Si dos nodos tienen listas de amigos diferentes, la respuesta es 'NO'\n if lista_amigos[i] != lista_amigos[j]:\n print('NO')\n exit(0)\n\n# Si todas las componentes son iguales, la respuesta es 'YES'\nprint('YES')\n \t \t \t\t \t\t \t \t \t \t \t \t \t\t", "import 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#from fractions import Fraction\r\n# import math\r\nimport sys\r\nimport math\r\nfrom math import gcd\r\n# from collections import deque\r\n# from collections import Counter\r\n#import sys\r\n#ys.setrecursionlimit(10 ** 6)\r\n#for _ in range(int(input())):\r\n#n, k = map(int, input().split())\r\n#from bisect import bisect_right\r\n#n =int(input())\r\n#for _ in range(int(input())):\r\nimport bisect\r\n#for _ in range(int(input())):\r\n #n, m =map(int,input().split())\r\n\r\n#for _ in (int(input())):\r\n#open(\"output.txt\",\"w\").write(s)\r\n#n=int(open(\"input.txt\").read())\r\n#open(\"output.txt\",\"w\").write(s)\r\n#arr=list(map(int,input().split()))\r\nimport heapq\r\n'''for _ in range(int(input())):\r\n n=int(input())g\r\n arr = list(map(int, input().split()))'''\r\n\r\n\r\nfrom collections import deque\r\ndef dfs(v):\r\n s=deque([v])\r\n vis[v]=1\r\n cv=0\r\n ce=0\r\n while s:\r\n v=s.pop()\r\n cv+=1\r\n ce+=len(g[v])\r\n for i in g[v]:\r\n if not vis[i]:\r\n vis[i]=1\r\n s.appendleft(i)\r\n if cv*(cv-1)!=ce:\r\n return False\r\n return True\r\n\r\n\r\nn,m=map(int,input().split())\r\ng=[[] for i in range(n+1)]\r\nfor _ in range(m):\r\n u,v=map(int,input().split())\r\n g[u].append(v)\r\n g[v].append(u)\r\n\r\nvis=[0]*(n+1)\r\nsign=1\r\nfor i in range(1,n+1):\r\n if not vis[i]:\r\n flag=dfs(i)\r\n if not flag:\r\n sign=0\r\n print(\"NO\")\r\n break\r\nif sign:\r\n print(\"YES\")\r\n ", "\"\"\"\nSummary of code:\n- run bfs to find the graph that is connected\n- check if that found graph is complete\n- if not then network is not reasonable\n\nRuntime Complexity:\n- input => O(N)\n- bfs => O(N + E)\n- calculation => O(N)\n- total => O(N) + O(N+E) + O(N) => O(N + E)\n\nSpace Complexity:\n- inputs => O(2 * N)\n- bfs => O(maximum depth) => O(H)\n- set for checking if node is visited => O(N)\n- calculation => O(1)\n- total => O(2N) + O(H) + O(N) + O(1) => O(N + H)\n\nWhy the chosen algorithm is good:\n- The runtime complexity is O(N+E)\n- the maximum for N+E = 3 * 10^5 which is smaller than 10^7\n\nSolved with help from\n- Charlotte Zhuang\n\"\"\"\n\nfrom sys import stdin\nfrom collections import deque\n\ndef main():\n input = stdin.readline\n n,m = [int(i) for i in input().split()]\n graph = {i+1:set() for i in range(n)}\n for _ in range(m):\n a,b = [int(i) for i in input().split()]\n graph[a].add(b)\n graph[b].add(a)\n\n seen = set()\n for i in range(1,n+1):\n if i in seen:\n continue\n seen_i = {i}\n que = deque([i])\n while que:\n cur = que.popleft()\n for nxt in graph[cur]:\n if nxt not in seen_i:\n seen_i.add(nxt)\n que.append(nxt)\n total_edges = 0\n for i in seen_i:\n total_edges += len(graph[i])\n total_edges //= 2\n if total_edges != len(seen_i) * (len(seen_i)-1) // 2:\n print(\"NO\")\n exit()\n seen |= seen_i\n print(\"Yes\")\n\nif __name__ == '__main__':\n main()\n\t \t \t \t \t\t \t \t \t\t \t\t \t\t\t\t \t", "n, m = map(int, input().split())\n\nd = {}\nvisited = set()\nans = 'YES'\n\nfor i in range(m):\n a, b = map(int, input().split())\n d.setdefault(a, {a}).add(b)\n d.setdefault(b, {b}).add(a)\n\nfor i, j in d.items():\n if i not in visited:\n if all([d[aux] == j for aux in j]): visited.update(j)\n else:\n ans = 'NO'\n break\n\nprint(ans)\n\n \t \t\t \t\t\t \t\t \t\t\t\t \t \t\t\t\t \t", "from collections import Counter\r\nn,m=map(int,input().split())\r\nparent=[i for i in range(n)]\r\ndegree=[0]*(n)\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\n \r\nfor _ in range(m):\r\n a,b=map(int,input().split())\r\n a-=1\r\n b-=1\r\n degree[a]+=1\r\n degree[b]+=1\r\n union(a,b)\r\nfor i in range(n):\r\n find(i)\r\nc=Counter(parent)\r\nf=True\r\nfor i,el in enumerate(parent):\r\n if degree[i]!=c[el]-1:\r\n f=False\r\n break\r\nif f:\r\n print(\"YES\")\r\nelse :\r\n print(\"NO\")", "import sys, threading\nsys.setrecursionlimit(10**7)\n\ndef main():\n n, m = list(map(int, input().split()))\n p = {i:i for i in range(1, n+1)}\n def getP(i):\n if i == p[i]:\n return i\n p[i] = getP(p[i])\n return p[i]\n\n # parent = p[x]\n # while p[parent] != parent:\n # parent = p[parent]\n \n # while x != p[x]:\n # p[x] = parent\n # x = p[x]\n \n # return parent\n\n\n size = {i:1 for i in range(1, n+1)}\n edges = {i:0 for i in range(1, n+1)}\n for _ in range(m):\n u,v = list(map(int, input().split()))\n if getP(u) != getP(v):\n size[getP(v)]+=size[getP(u)]\n edges[getP(v)]+=(edges[getP(u)])\n p[getP(u)] = getP(v)\n edges[getP(v)]+=1\n def f():\n for i in range(1, n+1):\n x, y = edges[getP(i)], size[getP(i)]\n if x != y*(y-1)//2:\n return False\n return True\n if f():\n print('YES')\n else:\n print('NO')\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\n \n\n", "n, m = map(int, input().split())\n\ndict = {}\naux = set()\nfor _ in range(m):\n a, b = input().split()\n dict.setdefault(b, {b}).add(a)\n dict.setdefault(a, {a}).add(b)\n\nout = 'YES'\nfor e, e2 in dict.items():\n if e not in aux:\n if all([dict[u] == e2 for u in e2]):\n aux.update(e2)\n else:\n out = 'NO'\n break\nprint(out)\n\t\t\t\t \t \t \t \t\t \t\t\t\t \t \t\t\t\t\t", "import sys\nimport math\nimport heapq\nimport itertools\nfrom collections import deque, defaultdict\n\ndef solve(graph, seen, start):\n num_edges = 0\n num_vertices = 0\n q = [start]\n seen[start] = True\n while q:\n node = q.pop()\n num_vertices += 1\n num_edges += len(graph[node])\n for adj in graph[node]:\n if not seen[adj]:\n seen[adj] = True\n q.append(adj)\n return num_edges // 2 == num_vertices * (num_vertices - 1) // 2\n\n\nif __name__ == \"__main__\":\n n, m = map(int, input().split())\n graph = [[] for _ in range(n)]\n seen = [False] * n\n for _ in range(m):\n u, v = map(lambda x: int(x) - 1, input().split())\n graph[u].append(v)\n graph[v].append(u)\n for i in range(n):\n if not seen[i]:\n res = solve(graph, seen, i)\n if not res:\n print(\"NO\")\n sys.exit(0)\n print(\"YES\")\n\n \t\t\t\t \t \t \t \t\t \t\t \t\t \t \t", "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\nclass UnionFind:\r\n def __init__(self, size):\r\n self.link = [i for i in range(size)]\r\n self.size = [1 for _ in range(size)]\r\n\r\n def find(self, a):\r\n while self.link[a] != a:\r\n a = self.link[a]\r\n return a\r\n\r\n def same(self, a, b):\r\n return self.find(a) == self.find(b)\r\n\r\n def join(self, a, b):\r\n a = self.find(a)\r\n b = self.find(b)\r\n if (self.size[a] > self.size[b]):\r\n a, b = b, a\r\n self.link[a] = b\r\n self.size[b] += self.size[a]\r\n return b\r\n\r\n\r\nn, m = ints()\r\ngraph = [[] for _ in range(n)]\r\ndsu = UnionFind(n)\r\n\r\nfor _ in range(m):\r\n a, b = ints()\r\n a, b = a - 1, b - 1\r\n if not dsu.same(a, b):\r\n dsu.join(a, b)\r\n graph[a].append(b)\r\n graph[b].append(a)\r\n\r\n\r\nflag = True\r\ni = 0\r\nwhile i < n and flag:\r\n if dsu.link[i] == i:\r\n stack = [i]\r\n visited = {i: True}\r\n\r\n while stack:\r\n node = stack.pop()\r\n \r\n if len(graph[node]) != dsu.size[i] - 1:\r\n flag = False\r\n break\r\n for nb in graph[node]:\r\n if nb not in visited:\r\n visited[nb] = True\r\n stack.append(nb)\r\n\r\n i += 1\r\n\r\nprint(\"YES\") if flag else print(\"NO\")", "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\nG = defaultdict(list)\r\n \r\ndef addEdge(a,b):\r\n G[a].append(b)\r\n G[b].append(a)\r\n \r\nN,M = Neo()\r\nvis = [False]*(N+1)\r\n \r\n \r\ndef dfs(node):\r\n s = deque()\r\n vis[node] = True\r\n s.append(node)\r\n C = []\r\n while s:\r\n x= s.pop()\r\n C.append(x)\r\n for i in G.get(x,[]):\r\n if not(vis[i]):\r\n vis[i] = True\r\n s.append(i)\r\n return C\r\n \r\nedge = set()\r\nfor i in range(M):\r\n u,v = Neo()\r\n edge.add((u,v))\r\n edge.add((v,u))\r\n addEdge(u,v)\r\n \r\nfor i in range(1,N+1):\r\n if not vis[i]:\r\n C = dfs(i)\r\n n= len(C)\r\n for i in range(n):\r\n for j in range(i+1,n):\r\n if not((C[i],C[j]) in edge):\r\n print('NO')\r\n exit(0)\r\nprint('YES')", "\r\nn,m=[int(x)for x in input().split()]\r\nd={}\r\ncon=set()\r\nfor x in range(m):\r\n a,b=input().split()\r\n d.setdefault(a,{a}).add(b)\r\n d.setdefault(b,{b}).add(a)\r\nres=None\r\nfor x,y in d.items():\r\n if x not in con:\r\n if all([d[u]==y for u in y]):\r\n con.update(y)\r\n else:\r\n res='NO'\r\n break\r\nif not res:\r\n res='YES'\r\nprint(res)", "import sys\r\n\r\ndef answer(n, m, a, b):\r\n adj_list = [[] for _ in range(n+1)] #first [] will never be filled.\r\n visited = [False for _ in range(n+1)] #[0] will never change.\r\n for i in range(m):\r\n adj_list[a[i]].append(b[i])\r\n adj_list[b[i]].append(a[i])\r\n for i in range(1, n+1):\r\n if visited[i] == False:\r\n visited[i] = True\r\n s = set(adj_list[i])\r\n s.add(i)\r\n for e in adj_list[i]:\r\n visited[e] = True\r\n sc = set(adj_list[e])\r\n sc.add(e)\r\n if s != sc:\r\n return 'NO'\r\n\r\n return 'YES'\r\n\r\ndef main():\r\n n, m = map(int, sys.stdin.readline().split())\r\n a = [0 for _ in range(m)]\r\n b = [0 for _ in range(m)]\r\n for i in range(m):\r\n a[i], b[i] = map(int, sys.stdin.readline().split())\r\n print(answer(n, m, a, b))\r\n return\r\nmain()", "import sys\r\nfrom collections import Counter, deque\r\nfrom functools import lru_cache\r\n# from itertools import combinations\r\nimport bisect\r\nfrom hashlib import new\r\nimport heapq\r\nfrom io import BytesIO, IOBase\r\nfrom itertools import count, cycle, permutations, product\r\nimport math\r\nfrom operator import le\r\nimport os\r\nfrom re import S, T\r\nimport string\r\nimport sys\r\nfrom threading import currentThread\r\nfrom tkinter import E\r\nfrom tkinter.messagebox import NO\r\nfrom turtle import left, right\r\nfrom types import GeneratorType\r\nfrom urllib.parse import SplitResult\r\ninput = sys.stdin.readline\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@bootstrap\r\ndef find(idx, parent):\r\n if parent[idx] == idx:\r\n yield idx\r\n \r\n parentIdx = (yield find(parent[idx], parent))\r\n parent[idx] = parentIdx\r\n yield parentIdx \r\ndef join(x,y,a):\r\n i=find(x,a)\r\n j=find(y,a)\r\n a[i]=a[j]\r\nt=1\r\nfor tt in range(t):\r\n n,m=list(map(int,input().split()))\r\n a=[i for i in range(n+1)]\r\n b=[0]*(n+1)\r\n for mm in range(m):\r\n x,y=list(map(int,input().split()))\r\n b[x]+=1\r\n b[y]+=1\r\n join(x,y,a)\r\n aa=[0]*(n+1)\r\n for i in range(1,n+1):\r\n aa[find(i,a)]+=1\r\n # print(a,aa,b)\r\n for i in range(1,n+1):\r\n if aa[find(i,a)]-1!=b[i]:\r\n # print(i,f(i,a),b[i])\r\n print('NO')\r\n break\r\n else:\r\n print('YES')", "from sys import *\r\nf = lambda: map(int, stdin.readline().split())\r\nn, m = f()\r\ng = [[x] for x in range(n + 1)]\r\np = [0] * (n + 1)\r\nfor j in range(m):\r\n u, v = f()\r\n g[u].append(v)\r\n g[v].append(u)\r\nk = 'YES'\r\nfor y, t in enumerate(g):\r\n if not p[y]:\r\n if any(len(g[x]) != len(t) or any(p[y] for y in g[x]) for x in t):\r\n k = 'NO'\r\n break\r\n for x in t: p[x] = 1\r\nprint(k)", "# n = int(input())\r\nn,m = [int(x) for x in input().split()]\r\ng = [[i] for i in range(n+1)]\r\nfor i in range(m):\r\n a,b = [int(x) for x in input().split()]\r\n g[a].append(b)\r\n g[b].append(a)\r\nflag = 0\r\nvis = [0 for i in range(n+1)]\r\nlis = [set(g[i]) for i in range(n+1) ]\r\nfor i in range(n):\r\n if vis[i]:\r\n continue\r\n for child in g[i]:\r\n if lis[i] != lis[child]:\r\n print('NO')\r\n exit()\r\n vis[child] = 1\r\nprint('YES')\r\n\r\n# def dfs(ver, check):\r\n# global flag\r\n\r\n# if vis[ver]:\r\n# return\r\n# if len(g[ver]) != check:\r\n# flag = 1\r\n# return \r\n# vis[ver] = 1\r\n# for child in g[ver]:\r\n# dfs(child, check)\r\n# for i in range(n):\r\n# if not vis[i]:\r\n# dfs(i, len(g[i]))", "n,o= map(int, input().split())\nh = [[i] for i in range(n + 1)]\nfor j in range(o):\n u, v= map(int, input().split())\n h[u].append(v)\n h[v].append(u)\nk = \"YES\"\n\nfor i in h: i.sort()\nfor i in h:\n s = len(i)\n if s > 1 and not all(h[x] ==i for x in i):\n k = 'NO'\n break\n for j in i: h[j] = []\nprint(k)\n\t \t\t \t \t\t \t\t\t \t \t\t \t \t\t", "import sys\r\ninput=sys.stdin.readline\r\nfrom collections import defaultdict\r\n\r\ng=defaultdict(list)\r\nn,m=map(int,input().split())\r\nind=[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 ind[a]+=1\r\n ind[b]+=1\r\nvisited=set()\r\ndef dfs(src):\r\n nodes,st=[],[src]\r\n visited.add(src)\r\n \r\n while len(st)>0:\r\n node=st.pop()\r\n nodes.append(node)\r\n for nbr in g[node]:\r\n if nbr not in visited:\r\n visited.add(nbr)\r\n st.append(nbr)\r\n for node in nodes:\r\n if ind[node]<len(nodes)-1:\r\n return False\r\n return True\r\nflag=True\r\nfor i in range(1,n+1):\r\n if i not in visited:\r\n res=dfs(i)\r\n if res==False:\r\n flag=False\r\n break\r\nif flag:print(\"YES\")\r\nelse:print(\"NO\")", "n, m = map(int, input().split())\r\nd = {}\r\naux = set()\r\nfor x in range(m):\r\n a, b = input().split()\r\n d.setdefault(a, {a}).add(b)\r\n d.setdefault(b, {b}).add(a)\r\nres='YES'\r\nfor x, y in d.items():\r\n if x not in aux:\r\n if all([d[u]==y for u in y]):\r\n aux.update(y)\r\n else:\r\n res='NO'\r\n break\r\nprint(res)", "n,m = map(int,input().split())\r\nv = [0]*150005\r\ns = [set([i]) for i in range(150005)]\r\nfor _ in ' '*m:\r\n a,b = map(int,input().split())\r\n s[a].add(b)\r\n s[b].add(a)\r\nfor i in range(n):\r\n if not v[i]:\r\n for j in s[i]:\r\n v[j]=1\r\n if s[j]!=s[i]: print('NO'); exit(0)\r\nprint('YES')", "n,m=map(int,input().split())\nv=[0]*150005\ns=[set([i])for i in range(150005)]\nfor _ in ' '*m:\n a,b=map(int,input().split())\n s[a].add(b)\n s[b].add(a)\nfor i in range(n):\n if not v[i]:\n for j in s[i]:\n v[j]=1\n if s[j]!=s[i]:print('NO');exit(0)\nprint('YES')\n \t \t \t \t \t \t \t \t \t \t \t", "from collections import deque\n\n\ndef bfs(start):\n res = []\n queue = deque([start])\n while queue:\n vertex = queue.pop()\n if not vis[vertex]:\n vis[vertex] = 1\n res.append(vertex)\n for i in s[vertex]:\n if not vis[i]:\n queue.append(i)\n return res\n\nn, m = [int(i) for i in input().split()]\ns = [[] for i in range(n)]\nfor i in range(m):\n a, b = [int(i) for i in input().split()]\n s[a-1].append(b-1)\n s[b-1].append(a-1)\nvis = [0 for i in range(n)]\nr = 0\nfor i in range(n):\n if not vis[i]:\n d = bfs(i)\n for j in d:\n if len(s[j]) != len(d)-1:\n r = 1\n print(\"NO\")\n break\n if r:\n break\nelse:\n print(\"YES\")", "from sys import stdin\r\ninput=stdin.readline\r\nR=lambda:map(int,input().split())\r\nI=lambda:int(input())\r\nS=lambda:input().rstrip('\\n')\r\nn,m=R()\r\nv=[[i] for i in range(n)]\r\nvst=[0]*n\r\nfor _ in range(m):\r\n\ta,b=R()\r\n\tv[a-1]+=b-1,\r\n\tv[b-1]+=a-1,\r\nfor i in v:i.sort()\r\nfor i in range(n):\r\n\tif vst[i]:continue\r\n\tvst[i]=1\r\n\tif len(v[i])>2:\r\n\t\tfor j in v[i]:\r\n\t\t\tvst[j]=1\r\n\t\t\tif v[j]!=v[i]:exit(print('NO'))\r\nprint('YES')", "from collections import defaultdict\nimport sys\ninput = __import__('sys').stdin.readline\n\nn, m = map(int, input().split())\ngraph = defaultdict(set)\nvisited = [False] * (n+1)\nfor _ in range(m):\n a, b = map(int, input().split())\n graph[a].add(b)\n graph[b].add(a)\n\nfor v in graph:\n graph[v].add(v)\n\naux = False\nfor e in range(1, n+1):\n if(not visited[e]):\n for v in graph[e]:\n visited[v] = True\n if(graph[e] != graph[v]):\n aux = True\n break\n if(aux): break\nif(aux):\n print(\"NO\")\nelse:\n print(\"YES\")\n \t \t\t\t \t\t \t \t\t \t\t \t\t\t", "# https://codeforces.com/problemset/problem/771/A\r\nimport sys\r\nfrom collections import defaultdict\r\n\r\n_DEBUG = False\r\nif not _DEBUG:\r\n input = sys.stdin.readline\r\n\r\n\r\ndef solve(n, m, g):\r\n visited = set()\r\n for i in range(1, n + 1):\r\n if i in visited:\r\n continue\r\n\r\n visited.add(i)\r\n stack = [i]\r\n\r\n group = {i}\r\n while stack:\r\n e = stack.pop()\r\n for v in g[e]:\r\n if v in visited:\r\n continue\r\n visited.add(v)\r\n group.add(v)\r\n stack.append(v)\r\n\r\n group_size = len(group)\r\n cnt = sum(len(g[e]) for e in group) // 2\r\n\r\n if cnt != group_size * (group_size - 1) // 2:\r\n if _DEBUG:\r\n print(group_size, cnt, group)\r\n return False\r\n return True\r\n\r\n\r\nn, m = map(int, input().strip().split())\r\ng = defaultdict(set)\r\n\r\nfor _ in range(m):\r\n a, b = map(int, input().strip().split())\r\n g[a].add(b)\r\n g[b].add(a)\r\n\r\nans = solve(n, m, g)\r\nprint('YES' if ans else 'NO')\r\n", "from collections import deque\nimport copy\nimport heapq\nfrom math import sqrt\nimport operator\nfrom operator import itemgetter\nimport sys\n\n \ninf_var = 0\nif inf_var == 1:\n inf = open('input.txt', 'r')\nelse:\n inf = sys.stdin\n \ninput = inf.readline\n# sys.stdout = open('output.txt', 'w')\n \ndef read_one_int():\n return int(input().rstrip('\\n'))\n \n \ndef read_one_float():\n return float(input().rstrip('\\n'))\n \n \ndef read_list_of_ints():\n res = [int(val) for val in (input().rstrip('\\n')).split(' ')]\n return res\n \n \ndef read_list_of_floats():\n res = [float(val) for val in (input().rstrip('\\n')).split(' ')]\n return res\n \n \ndef read_list_of_ints_zero():\n return [int(val) - 1 for val in (input().rstrip('\\n')).split()]\n \n \ndef read_str():\n return input().rstrip()\n\n\ndef is_valid(graph, checked):\n def check(v):\n check_set = graph[v]\n check_set.add(v)\n for u in graph[v]:\n check_set.remove(u)\n\n if graph[u] != check_set:\n return False\n check_set.add(u)\n checked[u] = True\n\n return True\n\n for v, ch in checked.items():\n if not ch:\n valid = check(v)\n if not valid:\n return 'NO'\n checked[v] = True\n\n return 'YES'\n\n\ndef main():\n # tests = read_one_int()\n\n # for _ in range(tests):\n n, m = read_list_of_ints()\n graph = {}\n checked = {}\n\n for _ in range(m):\n u, v = read_list_of_ints()\n if v not in graph:\n graph[v] = set()\n graph[v].add(u)\n\n if u not in graph:\n graph[u] = set()\n\n graph[u].add(v)\n checked[u] = False\n checked[v] = False\n\n\n res = is_valid(graph, checked)\n print(res)\n \n \nif __name__== '__main__':\n main()\n", "import sys\r\n\r\ndef get_int():\r\n return int(sys.stdin.readline().strip())\r\n\r\ndef get_ints():\r\n return map(int,sys.stdin.readline().strip().split())\r\n\r\ndef get_list():\r\n return list(map(int,sys.stdin.readline().strip().split()))\r\n\r\ndef get_string():\r\n return sys.stdin.readline().strip()\r\n\r\n\r\ndef find(a):\r\n v = []\r\n while a!= parent[a]:\r\n v.append(a)\r\n a= parent[a]\r\n \r\n for u in v:\r\n parent[u] = a\r\n \r\n return a\r\n\r\ndef union(a,b):\r\n a,b = find(a),find(b)\r\n\r\n if a==b:\r\n return\r\n\r\n if size[a]>=size[b]:\r\n size[a]+=size[b]\r\n parent[b] = a\r\n else:\r\n size[b]+=size[a]\r\n parent[a] = b\r\n return\r\n\r\n\r\nn,m = get_ints()\r\n\r\nedges = [0]*n\r\nparent = [i for i in range(n)]\r\nsize = [1]*n\r\n\r\nfor i in range(m):\r\n u,v = get_ints()\r\n u-=1\r\n v-=1\r\n\r\n edges[u]+=1\r\n edges[v]+=1\r\n\r\n union(u,v)\r\n\r\nflag = True\r\n\r\nfor i in range(n):\r\n v = size[find(i)]\r\n\r\n if edges[i] == (v-1) :\r\n continue\r\n\r\n else:\r\n flag = False\r\n break\r\n\r\nif not flag:\r\n print(\"NO\")\r\n\r\nelse:\r\n print(\"YES\")\r\n\r\n", "n, m = map(int, input().split())\nlistas_adj = [[] for _ in range(n)]\nvisitados = [False for _ in range(n)]\n\nfor _ in range(m):\n a, b = map(int, input().split())\n listas_adj[a - 1].append(b - 1)\n listas_adj[b - 1].append(a - 1)\n\n\ndef dfs(listas_adj, index):\n num_vertices = 0\n num_arestas = 0\n\n pilha = [index]\n while pilha:\n vertice = pilha.pop()\n num_vertices += 1\n for j in listas_adj[vertice]:\n num_arestas += 1\n if not visitados[j]:\n visitados[j] = True\n pilha.append(j)\n\n return num_vertices, num_arestas // 2\n\nresultado = \"YES\"\nfor i in range(n):\n if not visitados[i]:\n visitados[i] = True\n num_vertices, num_arestas = dfs(listas_adj, i)\n\n if num_arestas != (num_vertices * (num_vertices - 1)) // 2:\n resultado = \"NO\"\n\nprint(resultado)\n\n\t\t \t \t\t \t \t \t\t\t \t \t\t\t \t \t\t \t\t \t", "import sys\r\ninput = sys.stdin.buffer.readline \r\n\r\ndef find_root(root_dict, x):\r\n L = []\r\n while x != root_dict[x]:\r\n L.append(x)\r\n x = root_dict[x]\r\n for y in L:\r\n root_dict[y] = x\r\n return x\r\n\r\ndef process(n, G):\r\n m = len(G)\r\n g = [[] for i in range(n+1)]\r\n root_dict = [i for i in range(n+1)]\r\n for a, b in G:\r\n a1 = find_root(root_dict, a)\r\n b1 = find_root(root_dict, b)\r\n if a1 != b1:\r\n root_dict[b1] = a1\r\n g[a].append(b)\r\n g[b].append(a)\r\n roots = [[] for i in range(n+1)]\r\n for i in range(1, n+1):\r\n r = find_root(root_dict, i)\r\n roots[r].append(i)\r\n for r in range(1, n+1):\r\n for i in roots[r]:\r\n if len(g[i]) != len(roots[r])-1:\r\n print(\"NO\")\r\n return\r\n print(\"YES\")\r\n \r\nn, m = [int(x) for x in input().split()]\r\nG = []\r\nfor i in range(m):\r\n a, b = [int(x) for x in input().split()]\r\n G.append([a, b])\r\nprocess(n, G)", "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\ndef dfs(i):\n global vis,N,P,dic\n k = 1\n ans = dic[i]\n l = [i]\n while l:\n s = []\n a = l.pop()\n for x in P[a]:\n if vis[x]==1:continue\n vis[x] = 1\n k+=1\n ans+=dic[x]\n for y in P[x]:\n if vis[y]==1:continue\n s.append(y)\n l = s\n if k*(k-1)!=ans:return False\n return True\n\n\nN,M = map(int,input().split())\nP = [set() for _ in range(N)]\ndic = defaultdict(int)\nfor _ in range(M):\n a,b = map(int,input().split())\n dic[a-1]+=1\n dic[b-1]+=1\n P[a-1].add(b-1)\n P[b-1].add(a-1)\n\nvis = [0]*N\nans = \"YES\"\nfor i in range(N):\n if vis[i]==1:continue\n if not dfs(i):\n ans = \"NO\"\n break\nprint(ans)\n\n", "n, m = map(int, input().split())\r\nd = {}\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n if a not in d:\r\n d[a] = {b}\r\n else:\r\n d[a].add(b)\r\n if b not in d:\r\n d[b] = {a}\r\n else:\r\n d[b].add(a)\r\n\r\nnot_visited = set(range(2, n+1))\r\nvisited = set()\r\ncurrent = set()\r\nstack = [1]\r\nsucc = True\r\nwhile len(visited) < n:\r\n\r\n if not stack:\r\n t = not_visited.pop()\r\n stack = [t]\r\n current = set()\r\n\r\n p = stack.pop()\r\n visited.add(p)\r\n if p in d:\r\n for y in current:\r\n if y not in d[p]:\r\n succ = False\r\n break\r\n if not succ:\r\n break\r\n current.add(p)\r\n for x in d[p]:\r\n if x in not_visited:\r\n stack.append(x)\r\n not_visited.remove(x)\r\n\r\nif succ:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "from collections import Counter,defaultdict,deque\r\n#alph = 'abcdefghijklmnopqrstuvwxyz'\r\n#from math import factorial as fact\r\n\r\n#nl = '\\n'\r\n#import sys\r\n#input=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,m = [int(x) for x in input().split()]\r\nconnections = [[] for i in range(n)]\r\nfor i in range(m):\r\n a,b = [int(x)-1 for x in input().split()]\r\n connections[a].append(b)\r\n connections[b].append(a)\r\n\r\nglobalvisited = [False for i in range(n)]\r\ndef DFS(cmap,v):\r\n #visited = [False]*len(cmap)\r\n stack = deque([v])\r\n #order = deque()\r\n vcount = 0\r\n ecount = len(cmap[v])\r\n while len(stack)!=0:\r\n vertex = stack.pop()\r\n if not globalvisited[vertex]:\r\n vcount+=1\r\n #order.append(vertex)\r\n #visited[vertex] = True\r\n globalvisited[vertex] = True\r\n if len(cmap[vertex])!=ecount:\r\n return False\r\n stack.extend(cmap[vertex])\r\n #print(vcount,ecount)\r\n return vcount-1==ecount\r\nfor i in range(n):\r\n if not globalvisited[i]:\r\n cur=DFS(connections,i)\r\n if not cur:\r\n print('NO')\r\n exit()\r\nprint('YES')\r\n \r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n", "import sys\r\n\r\ndef answer(n, m, a, b):\r\n adj_list = [[] for _ in range(n+1)] #first [] will never be filled.\r\n visited = [False for _ in range(n+1)] #[0] will never change.\r\n for i in range(m):\r\n adj_list[a[i]].append(b[i])\r\n adj_list[b[i]].append(a[i])\r\n for i in range(1, n+1):\r\n if visited[i] == False:\r\n visited[i] = True\r\n s = set(adj_list[i])\r\n s.add(i)\r\n for e in adj_list[i]:\r\n visited[e] = True\r\n sc = set(adj_list[e])\r\n sc.add(e)\r\n if s != sc:\r\n return 'NO'\r\n\r\n return 'YES'\r\n\r\ndef count_dfs(adj_list, visited, stack, c):\r\n node = stack.pop()\r\n if visited[node]:\r\n return\r\n visited[node] = True\r\n c[0] += 1\r\n c[1] += len(adj_list[node])\r\n for e in adj_list[node]:\r\n if visited[e] == False:\r\n stack.append(e)\r\n return\r\n\r\ndef answer2(n, m, a, b):\r\n adj_list = [[] for _ in range(n+1)] #first [] will never be filled.\r\n visited = [False for _ in range(n+1)] #[0] will never change.\r\n for i in range(m):\r\n adj_list[a[i]].append(b[i])\r\n adj_list[b[i]].append(a[i])\r\n #c = [0, 0] #vertices, edges\r\n\r\n for i in range(1, n+1):\r\n if visited[i] == False:\r\n stack = [i]\r\n c = [0, 0]\r\n while len(stack) > 0:\r\n count_dfs(adj_list, visited, stack, c)\r\n if c[0] * (c[0] - 1) != c[1]:\r\n return 'NO'\r\n\r\n return 'YES'\r\n\r\ndef main():\r\n n, m = map(int, sys.stdin.readline().split())\r\n a = [0 for _ in range(m)]\r\n b = [0 for _ in range(m)]\r\n for i in range(m):\r\n a[i], b[i] = map(int, sys.stdin.readline().split())\r\n print(answer2(n, m, a, b))\r\n return\r\nmain()", "n, m = map(int, input().split())\n\ndic = {}\nvisited = set()\nanswer = 'YES'\n\nfor i in range(m):\n a, b = map(int, input().split())\n dic.setdefault(a, {a}).add(b)\n dic.setdefault(b, {b}).add(a)\n\nfor i, j in dic.items():\n if i not in visited:\n if all([dic[aux]==j for aux in j]):\n visited.update(j)\n else:\n answer = 'NO'\n break\n\nprint (answer)\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\nd = [[] for _ in range(n)]\r\ns = dict()\r\nfor i in range(m):\r\n a, b = sorted(map(lambda x:int(x)-1, input().split()))\r\n d[a].append(b)\r\n d[b].append(a)\r\n\r\nfor i in range(n):\r\n d[i].append(i)\r\n d[i].sort()\r\n\r\nx = [0]*n\r\nfor i in range(n):\r\n if x[i] == 0:\r\n for j in d[i]:\r\n if d[j] != d[i]:\r\n print('NO')\r\n exit(0)\r\n else:\r\n x[j] = 1\r\nprint('YES')\r\n", "def init():\n d1 = [i for i in range(150000 + 1)]\n d2 = [1 for i in range(150000 + 1)]\n\n return d1, d2\n\ndef find(el):\n if d1[el] == el:\n return el\n else:\n d1[el] = find(d1[el])\n return find(d1[el])\n\ndef union_find(c1, c2):\n c1 = find(c1)\n c2 = find(c2)\n\n if (d2[c2] > d2[c1]):\n d1[c1] = d1[c2]\n d2[c2] += d2[c1]\n else:\n d1[c2] = d1[c1]\n d2[c1] += d2[c2]\n\nn, m = map(int, input().split())\nresult = 0\nd1, d2 = init()\n\nfor i in range(m):\n a, b = map(int, input().split())\n a = find(a)\n b = find(b)\n \n if a != b:\n current = d2[a] * d2[b]\n union_find(a, b)\n \n result += (current - 1)\n else:\n result -= 1\n \nif result != 0:\n print('NO')\nelse:\n print('YES')\n\n \t\t\t\t \t\t \t \t \t \t\t \t \t\t\t \t\t", "def search(n):\n p = [n]\n visited[n] = True\n stack = [n]\n while(stack):\n n = stack.pop()\n for i in g[n]:\n if(visited[i] == False):\n visited[i] = True\n stack.append(i)\n p.append(i)\n return p\n\nn, m = map(int, input().split())\ng = {i:[] for i in range(1,n+1)}\ndegree = [0 for i in range(n+1)]\nvisited = [False for i in range(n+1)]\n\nfor i in range(m):\n a, b = map(int, input().split())\n g[a].append(b)\n g[b].append(a)\n degree[a] = degree[a] + 1\n degree[b] = degree[b] + 1\n\nc = []\nfor i in range(1, n + 1):\n if(visited[i] == False):\n c.append(search(i))\n\nres = 0\nfor i in c:\n f = 0\n l = len(i)\n for node in i:\n if(degree[node] != l - 1):\n f=1\n break\n if(f == 1):\n print(\"NO\")\n break\nelse:\n print(\"YES\")\n\t\t\t \t\t \t \t \t\t \t \t \t \t\t\t", "import sys\n\ndef main():\n n,m = map(int,sys.stdin.readline().split())\n\n l = [[] for i in range(n+1)]\n u = [False]*(n+1)\n\n for i in range(m):\n a, b = map(int,sys.stdin.readline().split())\n l[a].append(b)\n l[b].append(a)\n \n for i in range(n):\n j = i+1\n if u[j]:\n continue\n u[j] = True \n q = []\n cl = len(l[j])\n cn = 1\n for a in l[j]:\n q.append(a)\n\n while len(q)!=0 :\n cur = q.pop()\n if u[cur]:\n continue\n u[cur] = True\n cn+=1\n cl+=len(l[cur])\n for a in l[cur]:\n if u[a]:\n continue\n q.append(a)\n if cl!=cn*(cn-1):\n #print(j, cl, cn)\n print(\"NO\")\n return\n print(\"YES\")\n\n\nmain()", "n, m = map(int, input().split())\nadj = [[] for _ in range(n)]\n\t\nfor _ in range(m):\n\t\tu, v = map(int, input().split())\n\t\tadj[u - 1].append(v - 1)\n\t\tadj[v - 1].append(u - 1)\n\t\ndef bfs(i, vis):\n\t\tvis[i] = 1\n\t\tcomp = [i]\n\t\tcur = 0\n\t\n\t\twhile cur < len(comp):\n\t\t\t\tv = comp[cur]\n\t\t\t\tcur += 1\n\t\t\t\tfor nv in adj[v]:\n\t\t\t\t\t\tif vis[nv] == 0:\n\t\t\t\t\t\t\t\tcomp.append(nv)\n\t\t\t\t\t\t\t\tvis[nv] = 1\n\t\n\t\treturn comp\n\t\nvis = [0] * n\n\t\nfor v in range(n):\n\t\tif vis[v] == 0:\n\t\t\t\tcomp = bfs(v, vis)\n\t\t\t\tfor c in comp:\n\t\t\t\t\t\tif len(adj[c]) != len(comp) - 1:\n\t\t\t\t\t\t\t\tprint(\"NO\")\n\t\t\t\t\t\t\t\texit()\n\t\nprint(\"YES\")\n\t\t\t\t \t \t \t\t \t \t \t \t\t \t\t \t \t", "import sys\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\ndef find(x):\r\n if x == root[x]:\r\n return x\r\n root[x] = find(root[x])\r\n return root[x]\r\n\r\n\r\ndef union(x, y):\r\n a, b = find(x), find(y)\r\n if a != b:\r\n if rank[a] > rank[b]:\r\n root[b] = a\r\n elif rank[b] > rank[a]:\r\n root[a] = b\r\n else:\r\n root[b] = a\r\n rank[a] += 1\r\n\r\n\r\nn, m = invr()\r\nroot = [i for i in range(n)]\r\nrank = [1 for _ in range(n)]\r\nedges = []\r\ncount = [[0, 0] for _ in range(n)]\r\nfor _ in range(m):\r\n a, b = invr()\r\n edges.append([a - 1, b - 1])\r\nfor a, b in edges:\r\n union(a, b)\r\nfor i in range(n):\r\n count[find(i)][0] += 1\r\nfor a, b in edges:\r\n count[find(a)][1] += 1\r\nf = 0\r\n# print(count)\r\nfor node, edge in count:\r\n if node == 1:\r\n continue\r\n if edge != node * (node - 1) // 2:\r\n print(\"NO\")\r\n f = 1\r\n break\r\nif f == 0:\r\n print(\"YES\")\r\n", "from sys import stdin\r\nfrom collections import deque\r\n\r\nnVertices, nEdges = map(int, stdin.readline().split())\r\ng = [[] for _ in range(nVertices)]\r\nfor _ in range(nEdges):\r\n u, v = map(lambda x: int(x) - 1, stdin.readline().split())\r\n g[u].append(v)\r\n g[v].append(u)\r\n\r\ndef bfs(v):\r\n visited[v] = True\r\n q = deque([v])\r\n verticesCnt = 0\r\n edgesCnt = 0\r\n while q:\r\n v = q.pop()\r\n verticesCnt += 1\r\n edgesCnt += len(g[v])\r\n for to in g[v]:\r\n if not visited[to]:\r\n visited[to] = True\r\n q.appendleft(to)\r\n return verticesCnt * (verticesCnt - 1) == edgesCnt\r\n\r\n\r\nvisited = [False] * nVertices\r\nfor v in range(nVertices):\r\n if not visited[v]:\r\n if not bfs(v):\r\n print('NO')\r\n exit()\r\nprint('YES')", "n, m = map(int, input().split())\n\nd = dict()\nvisited = set()\nans = 'YES'\n\nfor i in range(m):\n a, b = map(int, input().split())\n d.setdefault(a, {a}).add(b)\n d.setdefault(b, {b}).add(a)\n\nfor k, v in d.items():\n if k not in visited:\n if all([d[aux] == v for aux in v]): visited.update(v)\n else:\n ans = 'NO'\n break\n\nprint(ans)\n", "from collections import deque\r\nn, m=[int(k) for k in input().split()]\r\nw=[]\r\nq={}\r\nfor j in range(m):\r\n w.append([int(k) for k in input().split()])\r\n if w[-1][0] in q:\r\n q[w[-1][0]].append(w[-1][1])\r\n else:\r\n q[w[-1][0]]=[w[-1][1]]\r\n if w[-1][1] in q:\r\n q[w[-1][1]].append(w[-1][0])\r\n else:\r\n q[w[-1][1]]=[w[-1][0]]\r\n#print(q)\r\ncheck=set()\r\nfor j in range(1, n+1):\r\n if (j in q) and (j not in check):\r\n check.add(j)\r\n new=deque([j])\r\n zeta=[]\r\n while new:\r\n x=new.pop()\r\n zeta.append(x)\r\n for k in q[x]:\r\n if k not in check:\r\n new.appendleft(k)\r\n check.add(k)\r\n iota=0\r\n for k in zeta:\r\n iota+=len(q[k])\r\n c=len(zeta)\r\n #print(zeta)\r\n #print(check)\r\n if iota!=c*(c-1):\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")", "import sys\r\ninput = sys.stdin.buffer.readline\r\n\r\n\r\ndef dfs(adj,vis,i):\r\n count=0\r\n c=0\r\n stack = [i]\r\n while(len(stack)>0):\r\n u = stack[-1]\r\n if(vis[u]==0):\r\n vis[u]=1\r\n c+=1\r\n count+=len(adj[u])\r\n else:\r\n stack.pop()\r\n for v in adj[u]:\r\n if(vis[v]==0):\r\n stack.append(v)\r\n return (c,count)\r\n\r\nn,m = map(int,input().split())\r\nadj = [[] for i in range(0,n+1)]\r\n\r\nfor _ in range(0,m):\r\n u,v = map(int,input().split())\r\n adj[u].append(v)\r\n adj[v].append(u)\r\n\r\nvis = [0]*(n+1)\r\nf=0\r\nfor i in range(1,n+1):\r\n if(vis[i]==0):\r\n \r\n c,count = dfs(adj,vis,i)\r\n if(count!=c*(c-1)):\r\n f=1\r\n break\r\n if(f==1):\r\n break\r\nif(f==1):\r\n print('NO')\r\nelse:\r\n print('YES')\r\n \r\n \r\n \r\n ", "a, b = map(int, input().split())\nc = [0] * (a)\nd = [set([i]) for i in range(a)]\n\n\nfor i in range(b):\n e, f = map(int, input().split())\n e -= 1\n f -= 1\n d[e].add(f)\n d[f].add(e)\n\n\nfor i in range(a):\n if not c[i]:\n for j in d[i]:\n c[j] = 1\n if d[i] != d[j]:\n print('NO')\n exit(0)\n\nprint('YES')\n\n \t\t\t \t \t \t \t \t\t\t\t \t \t\t", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools\n# import time,random,resource\n\n# sys.setrecursionlimit(10**6)\ninf = 10**20\neps = 1.0 / 10**10\nmod = 10**9+7\nmod2 = 998244353\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 list(map(int, sys.stdin.readline().split()))\ndef LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\ndef pf(s): return print(s, flush=True)\ndef pe(s): return print(str(s), file=sys.stderr)\ndef JA(a, sep): return sep.join(map(str, a))\ndef JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)\ndef IF(c, t, f): return t if c else f\ndef YES(c): return IF(c, \"YES\", \"NO\")\ndef Yes(c): return IF(c, \"Yes\", \"No\")\n\n\nclass UnionFind:\n def __init__(self, size):\n self.table = [-1 for _ in range(size)]\n\n def find(self, x):\n if self.table[x] < 0:\n return x\n else:\n self.table[x] = self.find(self.table[x])\n return self.table[x]\n\n def union(self, x, y):\n s1 = self.find(x)\n s2 = self.find(y)\n if s1 != s2:\n if self.table[s1] <= self.table[s2]:\n self.table[s1] += self.table[s2]\n self.table[s2] = s1\n else:\n self.table[s2] += self.table[s1]\n self.table[s1] = s2\n return True\n return False\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def subsetall(self):\n a = []\n for i in range(len(self.table)):\n if self.table[i] < 0:\n a.append((i, -self.table[i]))\n return a\n\ndef main():\n t = 1\n\n rr = []\n for _ in range(t):\n n,m = LI()\n ab = [LI_() for _ in range(m)]\n\n uf = UnionFind(n)\n for a,b in ab:\n uf.union(a,b)\n\n t = 0\n for i in range(n):\n k = -uf.table[i]\n if k > 0:\n t += k * (k-1) // 2\n\n rr.append(YES(t == m))\n\n return JA(rr, \"\\n\")\n\n\nprint(main())\n\n\n", "from sys import stdin\r\nn, m = map(int, input().split())\r\nN=n+1\r\nparent = list(range(N))\r\ndeg = [0]*N\r\ndef find(x):\r\n while parent[x]!=x:\r\n parent[x]=parent[parent[x]]\r\n x=parent[x]\r\n return x\r\nfor line in stdin:\r\n a, b = map(int, line.split())\r\n parent[find(a)]=find(b)\r\n deg[a]+=1\r\n deg[b]+=1\r\ncount=[0]*N\r\nfor i in range(1,N):\r\n count[find(i)]+=1\r\nfor i in range(1,N):\r\n if deg[i] != count[find(i)]-1:\r\n print('NO')\r\n break\r\nelse:\r\n print('YES')", "num_de_membros, num_de_pares = map(int, input().split())\n \ndicionario = {}\nfor i in range(num_de_pares):\n membro_a, membro_b = map(int, input().split())\n dicionario.setdefault(membro_a, {membro_a}).add(membro_b)\n dicionario.setdefault(membro_b, {membro_b}).add(membro_a)\n \nverificacao = \"YES\"\nconjunto = set()\nfor i, j in dicionario.items():\n if i not in conjunto:\n flag = True\n for k in j:\n if(dicionario[k] != j):\n flag = False\n if(flag):\n conjunto.update(j)\n else:\n verificacao = \"NO\"\n break\n \nprint(verificacao)\n \t\t \t\t \t\t \t\t \t \t\t \t", "from collections import defaultdict\n\nclass DSU:\n def __init__(self, n):\n self.par = list(range(n + 1))\n self.rank = [1] * (n + 1)\n\n def findPar(self, x):\n if x == self.par[x]:\n return x\n self.par[x] = self.findPar(self.par[x])\n return self.par[x]\n\n def unionRank(self, x, y):\n x_rep = self.findPar(x)\n y_rep = self.findPar(y)\n if x_rep == y_rep:\n return\n if self.rank[x_rep] > self.rank[y_rep]:\n self.par[y_rep] = x_rep\n elif self.rank[x_rep] < self.rank[y_rep]:\n self.par[x_rep] = y_rep\n else:\n self.par[y_rep] = x_rep\n self.rank[x_rep] += 1\n\nn, m = map(int, input().split())\n\ndsu = DSU(n)\n\nflag = True\nadj = defaultdict(list)\n\n# Procesar las conexiones\nfor i in range(m):\n u, v = map(int, input().split())\n adj[u].append(v)\n adj[v].append(u)\n dsu.unionRank(u, v)\n\n# Contar los componentes conexos\nmp = defaultdict(int)\nfor i in range(1, n + 1):\n mp[dsu.findPar(i)] += 1\n\n# Verificar si el grafo es razonable\nfor i in range(1, n + 1):\n if len(adj[i]) != mp[dsu.findPar(i)] - 1:\n flag = False\n break\n\n# Salida\nif flag:\n print(\"YES\")\nelse:\n print(\"NO\")\n\t \t \t \t \t \t \t \t", "import sys, math\r\ninput = sys.stdin.readline\r\n\r\ndef getInts():\r\n return [int(s) for s in input().split()]\r\n\r\ndef getInt():\r\n return int(input())\r\n\r\ndef getStrs():\r\n return [s for s in input().split()]\r\n\r\ndef getStr():\r\n return input().strip()\r\n\r\ndef listStr():\r\n return list(input().strip())\r\n\r\nimport collections as col\r\nimport math\r\n\r\n\"\"\"\r\nAt first glance: split the graph into connected components\r\nEach connected component must have the max possible number of edges, i.e. Q = L*(L-1)//2 where L = len(component)\r\nReasonable iff num_edges = sum(Q)\r\n\"\"\"\r\n\r\ndef solve():\r\n def bfs(graph,visited,node,queue,nodes):\r\n visited.add(node)\r\n nodes.remove(node)\r\n queue.append(node)\r\n queue = col.deque(queue)\r\n while queue:\r\n s = queue.popleft()\r\n for neighbour in graph[s]:\r\n if neighbour not in visited:\r\n visited.add(neighbour)\r\n nodes.remove(neighbour)\r\n queue.append(neighbour)\r\n return visited, nodes\r\n N,M = getInts()\r\n graph = col.defaultdict(set)\r\n edges = 0\r\n for m in range(M):\r\n U, V = getInts()\r\n edges += 1\r\n graph[U].add(V)\r\n graph[V].add(U)\r\n nodes = set([j+1 for j in range(N)])\r\n max_edges = 0\r\n while nodes:\r\n node = next(iter(nodes))\r\n visited, nodes = bfs(graph,set(),node,[],nodes)\r\n L = len(visited)\r\n max_edges += L*(L-1)//2\r\n return \"YES\" if edges == max_edges else \"NO\"\r\n \r\nprint(solve())\r\n \r\n\r\n", "n, m = [int(x) for x in input().split()]\r\n\r\nl = [] \r\nfor i in range(m):\r\n x, y = [int(x) for x in input().split()]\r\n if x>y: x,y = y,x\r\n l.append((x, y))\r\nl.sort(key=lambda x: x[0])\r\n\r\nlabels = {}\r\nrels_count = {}\r\nclass_count = {}\r\nfor x, y in l:\r\n if x not in labels:\r\n labels[x] = len(rels_count)\r\n rels_count[labels[x]] = 0\r\n class_count[labels[x]] = 1\r\n if y not in labels:\r\n class_count[labels[x]] += 1\r\n labels[y] = labels[x]\r\n rels_count[labels[x]]+=1\r\n \r\nflag = True\r\nfor i in range(len(rels_count)):\r\n l_n = class_count[i]\r\n l_m = rels_count[i]\r\n if l_n*(l_n-1) != 2*l_m:\r\n flag = False\r\n break\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")" ]
{"inputs": ["4 3\n1 3\n3 4\n1 4", "4 4\n3 1\n2 3\n3 4\n1 2", "10 4\n4 3\n5 10\n8 9\n1 2", "3 2\n1 2\n2 3", "3 0", "15 42\n8 1\n3 14\n7 14\n12 3\n7 9\n6 7\n6 12\n14 12\n3 10\n10 14\n6 3\n3 13\n13 10\n7 12\n7 2\n6 10\n11 4\n9 3\n8 4\n7 3\n2 3\n2 10\n9 13\n2 14\n6 14\n13 2\n1 4\n13 6\n7 10\n13 14\n12 10\n13 7\n12 2\n9 10\n13 12\n2 6\n9 14\n6 9\n12 9\n11 1\n2 9\n11 8", "20 80\n17 4\n10 1\n11 10\n17 7\n15 10\n14 15\n13 1\n18 13\n3 13\n12 7\n9 13\n10 12\n14 12\n18 11\n4 7\n10 13\n11 3\n19 8\n14 7\n10 17\n14 3\n7 11\n11 14\n19 5\n10 14\n15 17\n3 1\n9 10\n11 1\n4 1\n11 4\n9 1\n12 3\n13 7\n1 14\n11 12\n7 1\n9 12\n18 15\n17 3\n7 15\n4 10\n7 18\n7 9\n12 17\n14 18\n3 18\n18 17\n9 15\n14 4\n14 9\n9 18\n12 4\n7 10\n15 4\n4 18\n15 13\n1 12\n7 3\n13 11\n4 13\n5 8\n12 18\n12 15\n17 9\n11 15\n3 10\n18 10\n4 3\n15 3\n13 12\n9 4\n9 11\n14 17\n13 17\n3 9\n13 14\n1 17\n15 1\n17 11", "99 26\n64 17\n48 70\n71 50\n3 50\n9 60\n61 64\n53 50\n25 12\n3 71\n71 53\n3 53\n65 70\n9 25\n9 12\n59 56\n39 60\n64 69\n65 94\n70 94\n25 60\n60 12\n94 48\n17 69\n61 17\n65 48\n61 69", "3 1\n1 2", "3 2\n3 2\n1 3", "3 3\n2 3\n1 2\n1 3", "4 2\n4 1\n2 1", "4 3\n3 1\n2 1\n3 2", "5 9\n1 2\n5 1\n3 1\n1 4\n2 4\n5 3\n5 4\n2 3\n5 2", "10 5\n9 5\n1 2\n6 8\n6 3\n10 6", "10 8\n10 7\n9 7\n5 7\n6 8\n3 5\n8 10\n3 4\n7 8", "10 20\n8 2\n8 3\n1 8\n9 5\n2 4\n10 1\n10 5\n7 5\n7 8\n10 7\n6 5\n3 7\n1 9\n9 8\n7 2\n2 10\n2 1\n6 4\n9 7\n4 3", "150000 10\n62562 50190\n48849 60549\n139470 18456\n21436 25159\n66845 120884\n99972 114453\n11631 99153\n62951 134848\n78114 146050\n136760 131762", "150000 0", "4 4\n1 2\n2 3\n3 4\n1 4", "30 73\n25 2\n2 16\n20 12\n16 20\n7 18\n11 15\n13 11\n30 29\n16 12\n12 25\n2 1\n18 14\n9 8\n28 16\n2 9\n22 21\n1 25\n12 28\n14 7\n4 9\n26 7\n14 27\n12 2\n29 22\n1 9\n13 15\n3 10\n1 12\n8 20\n30 24\n25 20\n4 1\n4 12\n20 1\n8 4\n2 28\n25 16\n16 8\n20 4\n9 12\n21 30\n23 11\n19 6\n28 4\n29 21\n9 28\n30 10\n22 24\n25 8\n27 26\n25 4\n28 20\n9 25\n24 29\n20 9\n18 26\n1 28\n30 22\n23 15\n28 27\n8 2\n23 13\n12 8\n14 26\n16 4\n28 25\n8 1\n4 2\n9 16\n20 2\n18 27\n28 8\n27 7", "5 4\n1 2\n2 5\n3 4\n4 5", "4 4\n1 2\n2 3\n3 4\n4 1", "6 6\n1 2\n2 4\n4 3\n1 5\n5 6\n6 3", "3 2\n1 2\n1 3", "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n1 6", "4 4\n1 2\n1 3\n2 4\n3 4", "6 9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6", "4 3\n1 2\n1 3\n3 4", "4 3\n1 2\n1 3\n2 4", "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1", "4 3\n1 2\n1 3\n1 4", "150000 3\n150000 149999\n149998 149999\n149998 150000", "10 15\n1 2\n1 3\n2 4\n2 5\n3 4\n3 5\n4 5\n1 6\n6 7\n6 8\n7 9\n7 10\n8 9\n8 10\n9 10", "5 5\n1 2\n2 3\n3 4\n4 5\n5 1", "5 4\n1 2\n1 3\n1 4\n1 5", "9 9\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 1", "4 5\n1 2\n1 3\n1 4\n2 3\n3 4", "4 4\n1 2\n1 3\n4 2\n4 3", "5 5\n1 4\n5 3\n5 1\n2 3\n4 5", "4 5\n1 2\n1 3\n2 3\n1 4\n2 4", "4 5\n1 2\n1 3\n1 4\n2 3\n2 4", "6 12\n1 2\n1 4\n1 5\n1 6\n2 3\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n4 6", "1000 4\n100 132\n100 164\n196 132\n196 164"], "outputs": ["YES", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "YES", "NO", "YES", "NO", "NO", "NO", "NO", "YES", "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"]}
UNKNOWN
PYTHON3
CODEFORCES
79
19abaf75e3070d35d8add03d295b55c9
Romaji
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not. Help Vitya find out if a word $s$ is Berlanese. The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower). Sample Input sumimasen ninja codeforces Sample Output YES YES NO
[ "s=input()\r\nanswer='yes'\r\nif s[-1] not in \"naeiou\":\r\n answer='no'\r\nfor i in range(len(s)-1):\r\n if s[i] not in \"naeiou\" and s[i+1] not in \"aeiou\":\r\n answer='no'\r\nprint(answer)", "string=input().lower()\r\nconsonants=['b','c','d','f','g','h','j','k','l','m','p','q','r','s','t','v','w','x','y','z']\r\nvowels=['a','e','i','o','u']\r\nber='YES'\r\nfor n in range(len(string)-1):\r\n if string[n] in consonants:\r\n if string[n+1] not in vowels:\r\n ber='NO'\r\nif string[-1] in consonants:\r\n ber='NO'\r\nprint(ber)", "x = input()\r\nvow=['a','e','i','o','u']\r\n\r\nn=len(x)\r\nfor i in range(n):\r\n if x[i] in vow or x[i]=='n':\r\n continue\r\n else:\r\n if i==n-1:\r\n print('NO')\r\n exit(0)\r\n\r\n else:\r\n if x[i+1] not in vow:\r\n print('NO')\r\n exit(0)\r\n\r\nprint('YES')", "s = input()\r\na = 'aeiou'\r\nb = 'aeioun'\r\nx = 'a'\r\nresult = 'YES'\r\nfor i in s:\r\n if x not in b and i not in a:\r\n result = 'NO'\r\n break\r\n x = i\r\nif x not in b:\r\n result = 'NO'\r\nprint(result)", "s = input()\r\nn = len(s)\r\nif s[-1] not in \"aeioun\":\r\n x = \"NO\"\r\nelse:\r\n x = \"YES\"\r\n for i in range(n - 1):\r\n if s[i] not in \"aeioun\":\r\n if s[i + 1] not in \"aeiou\":\r\n x = \"NO\"\r\nprint(x)\r\n", "import bisect\r\nimport heapq\r\nimport math\r\nimport collections\r\nimport sys\r\nimport copy\r\nfrom functools import reduce\r\nimport decimal\r\nfrom io import BytesIO, IOBase\r\nimport os\r\nimport itertools\r\nimport functools\r\nfrom types import GeneratorType\r\n\r\n#\r\n# sys.setrecursionlimit(10 ** 9)\r\ndecimal.getcontext().rounding = decimal.ROUND_HALF_UP\r\n\r\ngraphDict = collections.defaultdict\r\n\r\nqueue = collections.deque\r\n\r\n\r\n################## pypy deep recursion handling ##############\r\n# Author = @pajenegod\r\ndef bootstrap(f, stack=[]):\r\n def wrappedfunc(*args, **kwargs):\r\n to = f(*args, **kwargs)\r\n if stack:\r\n return to\r\n else:\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 return to\r\n to = stack[-1].send(to)\r\n\r\n return wrappedfunc\r\n\r\n\r\n################## Graphs ###################\r\nclass Graphs:\r\n def __init__(self):\r\n self.graph = graphDict(set)\r\n\r\n def add_edge(self, u, v):\r\n self.graph[u].add(v)\r\n self.graph[v].add(u)\r\n\r\n def dfs_utility(self, nodes, visited_nodes, colors, parity, level):\r\n global count\r\n if nodes == 1:\r\n colors[nodes] = -1\r\n else:\r\n if len(self.graph[nodes]) == 1 and parity % 2 == 0:\r\n if q == 1:\r\n colors[nodes] = 1\r\n else:\r\n colors[nodes] = -1\r\n count += 1\r\n else:\r\n if parity % 2 == 0:\r\n colors[nodes] = -1\r\n else:\r\n colors[nodes] = 1\r\n visited_nodes.add(nodes)\r\n for neighbour in self.graph[nodes]:\r\n new_level = level + 1\r\n if neighbour not in visited_nodes:\r\n self.dfs_utility(neighbour, visited_nodes, colors, level - 1, new_level)\r\n\r\n def dfs(self, node):\r\n Visited = set()\r\n color = collections.defaultdict()\r\n self.dfs_utility(node, Visited, color, 0, 0)\r\n return color\r\n\r\n def bfs(self, node, f_node):\r\n count = float(\"inf\")\r\n visited = set()\r\n level = 0\r\n if node not in visited:\r\n queue.append([node, level])\r\n visited.add(node)\r\n flag = 0\r\n while queue:\r\n parent = queue.popleft()\r\n if parent[0] == f_node:\r\n flag = 1\r\n count = min(count, parent[1])\r\n level = parent[1] + 1\r\n for item in self.graph[parent[0]]:\r\n if item not in visited:\r\n queue.append([item, level])\r\n visited.add(item)\r\n return count if flag else -1\r\n return False\r\n\r\n\r\n################### Tree Implementaion ##############\r\nclass Tree:\r\n def __init__(self, data):\r\n self.data = data\r\n self.left = None\r\n self.right = None\r\n\r\n\r\ndef inorder(node, lis):\r\n if node:\r\n inorder(node.left, lis)\r\n lis.append(node.data)\r\n inorder(node.right, lis)\r\n return lis\r\n\r\n\r\ndef leaf_node_sum(root):\r\n if root is None:\r\n return 0\r\n if root.left is None and root.right is None:\r\n return root.data\r\n return leaf_node_sum(root.left) + leaf_node_sum(root.right)\r\n\r\n\r\ndef hight(root):\r\n if root is None:\r\n return -1\r\n if root.left is None and root.right is None:\r\n return 0\r\n return max(hight(root.left), hight(root.right)) + 1\r\n\r\n\r\n################## Union Find #######################\r\nclass UF:\r\n \"\"\"An implementation of union find data structure.\r\n It uses weighted quick union by rank with path compression.\r\n \"\"\"\r\n\r\n def __init__(self, N):\r\n \"\"\"Initialize an empty union find object with N items.\r\n\r\n Args:\r\n N: Number of items in the union find object.\r\n \"\"\"\r\n\r\n self._id = list(range(N))\r\n self._count = N\r\n self._rank = [0] * N\r\n\r\n def find(self, p):\r\n \"\"\"Find the set identifier for the item p.\"\"\"\r\n\r\n id = self._id\r\n while p != id[p]:\r\n p = id[p] # Path compression using halving.\r\n return p\r\n\r\n def count(self):\r\n \"\"\"Return the number of items.\"\"\"\r\n\r\n return self._count\r\n\r\n def connected(self, p, q):\r\n \"\"\"Check if the items p and q are on the same set or not.\"\"\"\r\n\r\n return self.find(p) == self.find(q)\r\n\r\n def union(self, p, q):\r\n \"\"\"Combine sets containing p and q into a single set.\"\"\"\r\n\r\n id = self._id\r\n rank = self._rank\r\n\r\n i = self.find(p)\r\n j = self.find(q)\r\n if i == j:\r\n return\r\n\r\n self._count -= 1\r\n if rank[i] < rank[j]:\r\n id[i] = j\r\n elif rank[i] > rank[j]:\r\n id[j] = i\r\n else:\r\n id[j] = i\r\n rank[i] += 1\r\n\r\n def add_roads(self):\r\n return set(self._id)\r\n\r\n def __str__(self):\r\n \"\"\"String representation of the union find object.\"\"\"\r\n return \" \".join([str(x) for x in self._id])\r\n\r\n def __repr__(self):\r\n \"\"\"Representation of the union find object.\"\"\"\r\n return \"UF(\" + str(self) + \")\"\r\n\r\n\r\n#################################################\r\n\r\ndef rounding(n):\r\n return int(decimal.Decimal(f'{n}').to_integral_value())\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\ndef p_sum(array):\r\n return list(itertools.accumulate(array))\r\n\r\n\r\ndef base_change(nn, bb):\r\n if nn == 0:\r\n return [0]\r\n digits = []\r\n while nn:\r\n digits.append(int(nn % bb))\r\n nn //= bb\r\n return digits[::-1]\r\n\r\n\r\ndef diophantine(a: int, b: int, c: int):\r\n d, x, y = extended_gcd(a, b)\r\n r = c // d\r\n return r * x, r * y\r\n\r\n\r\n@bootstrap\r\ndef extended_gcd(a: int, b: int):\r\n if b == 0:\r\n d, x, y = a, 1, 0\r\n else:\r\n (d, p, q) = yield extended_gcd(b, a % b)\r\n x = q\r\n y = p - q * (a // b)\r\n\r\n yield d, x, y\r\n\r\n\r\n######################################################################################\r\n\r\n'''\r\nKnowledge and awareness are vague, and perhaps better called illusions.\r\nEveryone lives within their own subjective interpretation.\r\n ~Uchiha Itachi\r\n'''\r\n\r\n################################ <fast I/O> ###########################################\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, **kwargs):\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\n\r\n\r\n#############################################<I/O Region >##############################################\r\n\r\n\r\ndef inp():\r\n return sys.stdin.readline().strip()\r\n\r\n\r\ndef map_inp(v_type):\r\n return map(v_type, inp().split())\r\n\r\n\r\ndef list_inp(v_type):\r\n return list(map_inp(v_type))\r\n\r\n\r\n######################################## Solution ####################################\r\n\r\ns = inp()\r\nprev = s[0]\r\nvowel = {\"a\", \"i\", \"o\", \"e\", \"u\"}\r\nflag = 1\r\nfor i in range(1, len(s)):\r\n if s[i - 1] in vowel or s[i - 1] == \"n\":\r\n prev = s[i]\r\n else:\r\n if s[i] not in vowel:\r\n flag = 0\r\n break\r\n else:\r\n prev = s[i]\r\nif flag:\r\n if prev in vowel or prev == \"n\":\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")\r\n", "s=input()\r\nn=len(s)\r\nv='aeioun'\r\nfor i in range(1,n):\r\n if (s[i] not in v and s[i-1] not in v) or (s[i]=='n' and s[i-1] not in v):\r\n print(\"NO\")\r\n exit()\r\nif s[-1] in v:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "text = input()\r\n\r\nrm = True\r\nfor i in range(len(text)-1):\r\n if not(text[i] in \"aeioun\"):\r\n if not(text[i+1] in \"aeiou\"):\r\n rm = False\r\n break\r\nif rm:\r\n if not(text[-1] in \"aeioun\"):\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input()\r\ng = [\"a\", \"o\", \"i\", \"u\", \"e\"]\r\notv = \"yEs\"\r\nfor i in range(len(s)-1):\r\n if (s[i] not in g) and (s[i+1] not in g) :\r\n if s[i] != \"n\":\r\n otv = \"nO\"\r\n break \r\nif (s[-1] not in g) and s[-1] != \"n\":\r\n otv = \"nO\"\r\nprint(otv)\r\n \r\n\r\n", "nxt = 'b'\r\ns = input()[::-1]\r\nfor cur in s:\r\n\tif cur in 'aou''ien' or nxt in 'aou''ie':\r\n\t\tnxt = cur\r\n\telse:\r\n\t\tprint(\"NO\")\r\n\t\tbreak\r\nelse:\r\n\tprint(\"YES\")", "s=input()+'*'\r\nresult='Yes'\r\nm=len(s)\r\nfor i in range(m-1):\r\n if s[i] not in 'aeioun' and s[i+1] not in 'aeiou':\r\n result='No'\r\n break\r\n \r\nprint(result)", "s=input()\r\nflag=0\r\nfor i in s:\r\n if flag==1:\r\n if i in \"aeiou\":\r\n flag=0\r\n else:\r\n print(\"NO\")\r\n break\r\n if i not in \"aeioun\":\r\n flag=1\r\nelse:\r\n if flag==0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "vowels = \"aeiou\"\r\nword = input()\r\ni = 0\r\nflag = True\r\nwhile i < len(word):\r\n if word[-1] not in vowels and word[-1] != \"n\":\r\n flag = False\r\n print(\"NO\")\r\n break\r\n if word[i] == \"n\":\r\n i += 1\r\n elif word[i] not in vowels:\r\n if word[i+1] in vowels:\r\n i += 2\r\n else:\r\n flag = False\r\n print(\"NO\")\r\n break\r\n else:\r\n i += 1\r\nif flag:\r\n print(\"YES\")", "s = input()\r\nl = ['a', 'e', 'i', 'o', 'u', 'n']\r\nv = ['a', 'e', 'i', 'o', 'u']\r\ns = s + 'n'\r\na = True\r\nfor i in range(len(s)-1):\r\n if s[i] not in l and s[i+1] not in v:\r\n a = False\r\nif a :\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=input()\r\nc=0\r\nl=[\"a\",\"e\",\"i\",\"o\",\"u\"]\r\nfor i in range(len(s)):\r\n if(s[i] in l or s[i]==\"n\"):\r\n c=1\r\n continue\r\n else:\r\n if(i==len(s)-1):\r\n c=0\r\n break\r\n if(s[i+1] not in l):\r\n c=0\r\n break\r\n else:\r\n c=1\r\n continue\r\nif(c==1):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "t=input()+\"b\"\r\nanswer=\"YES\"\r\nfor i in range(len(t)-1):\r\n if t[i] not in \"naeiou\" and t[i+1] not in \"aeiou\":\r\n answer=\"NO\"\r\nprint(answer)", "s=input()\r\ns=s+' '\r\nn=len(s)\r\nans='YES'\r\nfor i in range(n-1):\r\n if s[i] not in 'aeioun' and s[i+1] not in 'aeiou':\r\n ans='NO'\r\n break\r\n else:\r\n ans='YES'\r\nprint(ans) ", "s=input()\r\nn=len(s)\r\nv='aeiou'\r\nresult='YES'\r\nfor i in range(n-1):\r\n if s[i]!='n'and s[i]not in v:\r\n if s[i+1]not in v:\r\n result='NO'\r\nif s[n-1]!='n'and s[n-1]not in v:\r\n result='NO'\r\nprint(result)", "def isConsonant(c):\r\n return c != 'a' and c != 'o' and c != 'u' and c != 'i' and c != 'e'\r\n\r\ndef prg():\r\n s = input()\r\n n = len(s)\r\n if isConsonant(s[n-1]) and s[n-1] !='n':\r\n print(\"NO\")\r\n return\r\n s= s+'x'\r\n ok = True\r\n for i in range(0,n):\r\n if ok:\r\n if (s[i] != 'n' and isConsonant(s[i]) and isConsonant(s[i + 1])):\r\n ok = False\r\n break\r\n if ok:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n return\r\n\r\nprg()", "s=input()\r\ntest=True\r\ni=0\r\nif len(s)==1:\r\n if s in {\"a\",\"o\",\"u\",\"i\",\"e\",\"n\"}:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelif s[len(s)-1] not in {\"a\",\"o\",\"u\",\"i\",\"e\",\"n\"}:\r\n print(\"NO\")\r\nelse:\r\n while (test==True) and (i<=len(s)-2):\r\n test=(s[i+1] in {\"a\",\"o\",\"u\",\"i\",\"e\"}) or ( s[i] in{\"a\",\"o\",\"u\",\"i\",\"e\",\"n\"} )\r\n i+=1\r\n if test==True:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n ", "t=input()\r\nn=len(t)\r\nk='aeioun'\r\nj='aieou'\r\ndef isvowcon(t):\r\n\tfor i in range(n-1):\r\n\t\tif t[i] not in k and t[i+1] not in j:\r\n\t\t\treturn \"NO\"\r\n\tif t[-1] not in k:\r\n\t\treturn \"NO\"\r\n\treturn \"YES\"\r\nprint(isvowcon(t))", "str = input()\r\nvow=['a','e','i','o','u']\r\n\r\nn=len(str)\r\nfor i in range(n):\r\n if str[i] in vow or str[i]=='n':\r\n continue\r\n else:\r\n if i==n-1:\r\n print('NO')\r\n exit(0)\r\n\r\n else:\r\n if str[i+1] not in vow:\r\n print('NO')\r\n exit(0)\r\n\r\nprint('YES')", "text = input()\r\na = ['a', 'e', 'i', 'o', 'u', 'n']\r\nb = ['a', 'e', 'i', 'o', 'u']\r\ntext = text + 'n'\r\nn=len(text)\r\nans = True\r\nfor i in range(n-1):\r\n if text[i] not in a and text[i+1] not in b :\r\n ans = False\r\nif ans :\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "n = input() + \" \"\r\nl=len(n)\r\na=\"yes\"\r\nfor i in range(l-1):\r\n if n[i] not in \"naeiou\" and n[i+1] not in \"aeiou\":\r\n a=\"no\"\r\nprint(a) ", "n=input()\r\nn=list(n)\r\na='aeiou'\r\nif(len(n)==1):\r\n if(n[0]!='n' and n[0] not in a):\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n exit()\r\nelse:\r\n for i in range(len(n)-1):\r\n if(n[i] not in a and n[i]!='n'):\r\n if(n[i+1] not in a):\r\n print(\"NO\")\r\n exit()\r\n if(n[len(n)-1] not in a and n[len(n)-1]!='n'):\r\n print(\"NO\")\r\n exit()\r\n print(\"YES\")", "s = input()\r\nanswer=\"YES\"\r\na = \"aeiou\"\r\nb=\"aeioun\"\r\nx=\"a\"\r\nfor i in s :\r\n if x not in b and i not in a :\r\n answer=\"NO\"\r\n break\r\n x=i\r\nif x not in b:\r\n answer=\"NO\"\r\nprint(answer)\r\n", "s=input()\r\nx=len(s)\r\nv=[\"a\",'e','i','o','u']\r\nresult=\"YES\"\r\nfor i in range(x-1):\r\n if s[i]!='n' and s[i] not in v:\r\n if s[i+1] not in v:\r\n result=\"NO\"\r\nif s[-1] not in v and s[-1]!='n':\r\n result=\"NO\"\r\nprint(result)", "N = input()\r\ncount = 0\r\nfor i in N:\r\n if count == 1:\r\n if i in \"aeiou\":\r\n count = 0\r\n else:\r\n print(\"NO\")\r\n break \r\n if i not in \"aeioun\":\r\n count = 1\r\nelse:\r\n if count == 0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "text = input()\r\ncheck = 0\r\n\r\nfor i in text:\r\n if check == 1:\r\n if i in \"aeiou\":\r\n check = 0\r\n else:\r\n print(\"NO\")\r\n break\r\n \r\n if i not in \"aeioun\":\r\n check = 1\r\nelse:\r\n if check == 0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "w = input()\r\nres = \"yes\"\r\nfor i in range (len(w)):\r\n if len(w) >1 and i+1 < len(w):\r\n if w[i] not in \"aeioun\" and w[i+1] not in \"aeiou\":\r\n res = \"no\"\r\n break\r\n else:\r\n if w[i] not in \"aouien\":\r\n res = \"no\"\r\n break\r\nprint(res)", "def isvowel(c):\r\n if c in \"aeiou\":\r\n return True\r\n else:\r\n return False\r\n\r\ns=input()\r\na=\"aeiou\"\r\nFlag=\"Yes\"\r\nfor i in range(len(s)):\r\n if not isvowel(s[i]) and s[i]!=\"n\":\r\n if s[-1] not in \"aeioun\" or not isvowel(s[i+1]):\r\n Flag =\"NO\"\r\n break\r\nprint(Flag)", "n=input() + \" \"\r\nl= len(n)\r\na= \"yes\"\r\nfor i in range(l-1):\r\n if n[i] not in \"naeiou\" and n[i+1] not in \"aeiou\":\r\n a=\"no\"\r\nprint(a)\r\n", "word = input()\nvowel={'a','e','i','o','u'}\nspecial = 'n'\nvalid = True\nfor j in range(len(word)-1):\n if word[j] not in vowel and word[j]!=special: #if consonant\n if word[j+1] not in vowel:\n valid = False\n break\n continue\n else:\n continue\n\nif word[-1] not in vowel and word[-1]!=special:\n valid= False\n\nif valid :\n print(\"YES\")\nelse:\n print(\"NO\")\n \t \t\t \t\t \t \t\t\t\t \t \t\t", "text = input()\r\ntext = text.lower()\r\nrm = True\r\nfor i in range(len(text)-1):\r\n if text[i] != \"a\" and text[i] != \"e\" and text[i] != \"i\" and text[i] != \"o\" and text[i] != \"u\" and text[i] != \"n\":\r\n if text[i+1] != \"a\" and text[i+1] != \"e\" and text[i+1] != \"i\" and text[i+1] != \"o\" and text[i+1] != \"u\":\r\n rm = False\r\n break\r\nif rm:\r\n if text[-1] != \"a\" and text[-1] != \"e\" and text[-1] != \"i\" and text[-1] != \"o\" and text[-1] != \"u\" and text[-1] != \"n\":\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=input()\r\nc=0\r\nv=\"aeiou\"\r\nx=v+\"n\"\r\nfor i in n:\r\n if c==1:\r\n if i in v:\r\n c=0\r\n else:\r\n print(\"no\")\r\n break\r\n if i not in x:\r\n c=1\r\nelse:\r\n if c==0:\r\n print(\"yes\")\r\n else:\r\n print(\"no\")", "txt=input()\r\nl = len(txt)\r\nvowel = ['a','e','i','o','u']\r\nresult='Yes'\r\nfor i in range(l-1):\r\n if txt[i]!='n' and txt[i] not in vowel:\r\n if txt[i+1] not in vowel:\r\n result='No'\r\nif txt[l-1] not in vowel and txt[l-1]!='n':\r\n result='No'\r\nprint(result)", "str = input()\nvog=['a','e','i','o','u']\n\nn=len(str)\nfor i in range(n):\n if str[i] in vog or str[i]=='n':\n continue\n else:\n if i==n-1:\n print('NO')\n exit(0)\n\n else:\n if str[i+1] not in vog:\n print('NO')\n exit(0)\n\nprint('YES')\n\t \t \t\t \t\t\t\t\t\t\t \t \t \t \t", "x=input()\r\nres=\"YES\"\r\nfor letter in range(len(x)):\r\n if len(x)>1 and letter+1<len(x):\r\n if (x[letter] not in \"aouien\" and x[letter+1] not in \"aeiou\"):\r\n res=\"NO\"\r\n break\r\n else:\r\n if (x[letter] not in \"aouien\"):\r\n res=\"NO\"\r\n break\r\nprint(res)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Sep 21 09:27:55 2023\r\n\r\n@author: lakne\r\n\"\"\"\r\n\r\ns = input()\r\nvowels = [\"a\", \"o\", \"u\", \"i\", \"e\"]\r\n\r\nx = True\r\nfor i in range(len(s)-1):\r\n if s[i] not in vowels and s[i] != \"n\":\r\n if s[i+1] not in vowels:\r\n x = False\r\nif (s[-1] not in vowels and s[-1] != \"n\"):\r\n x = False\r\n\r\nif x:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "# -*- coding: utf-8 -*-\n\"\"\"Untitled29.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1NkNiLAcUyOzqZ3KKc6sePvfphVoS--FY\n\"\"\"\n\ndef berlanese(word):\n vowels = 'aeiou'\n n = len(word)\n for i in range(n):\n if word[i] not in vowels and word[i] != 'n':\n if i == n - 1 or word[i + 1] not in vowels:\n return 'NO'\n return 'YES'\n \ns = input()\nprint (berlanese(s))", "t = input() + \"b\"\r\nl = len(t)\r\nresult = \"YES\"\r\nfor i in range(l - 1):\r\n if t[i] not in \"naeiou\" and t[i+1] not in \"aeiou\":\r\n result = \"NO\"\r\nprint(result)", "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\ns = input()\r\nn = len(s)\r\nl = 'aeuio'\r\nfor i in range(n-1):\r\n if (s[i] not in l) and s[i] != 'n':\r\n if s[i+1] not in l:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")", "s = input()\r\n\r\nvowels = set(['a', 'e', 'i', 'o', 'u'])\r\nis_berlanese = True\r\n\r\nfor i in range(len(s)-1):\r\n if s[i] not in vowels and s[i] != 'n' and s[i+1] not in vowels:\r\n is_berlanese = False\r\n break\r\nif len(s) > 0 and s[-1] not in vowels and s[-1] != 'n':\r\n is_berlanese = False\r\n\r\nif is_berlanese:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "word = input() + \"b\"\naeiou = [\"a\", \"e\", \"i\", \"o\", \"u\"]\nis_Berlanese = True\nfor i in range(len(word) - 1):\n i_th = word[i]\n if not (i_th in aeiou):\n if i_th == \"n\":\n continue\n if not (word[i + 1] in aeiou):\n is_Berlanese = False\n break\nif is_Berlanese:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n \t\t \t\t\t \t \t \t\t \t\t\t\t", "s=input()\r\nn=len(s)\r\ncount=0\r\nvowels=['a','e','i','o','u']\r\nfor i in range(n-1):\r\n if s[i]!='n' and s[i] not in vowels:\r\n if s[i+1]not in vowels:\r\n count+=1\r\nif s[-1] not in vowels and s[-1]!='n':\r\n count+=1\r\nif count>0:\r\n print('NO')\r\nelse:\r\n print('YES')\r\n", "s = input()\r\nv = ['a', 'e', 'i', 'o', 'u']\r\nfor j in range(len(s)):\r\n try:\r\n if s[j] not in v and s[j]!='n':\r\n if s[j+1] not in v:\r\n print('NO')\r\n break\r\n else:\r\n continue\r\n except:\r\n if j in v or j=='n':\r\n print('YES')\r\n break\r\n else:\r\n print('NO')\r\n break\r\nelse:\r\n print('YES')\r\n\r\n", "s = input()+\" \"\r\nflag = \"YES\"\r\nfor i in range(len(s)-1):\r\n if s[i] not in \"naeiou\" and s[i+1] not in \"aeiou\":\r\n flag = \"NO\"\r\nprint(flag)", "s = input()\r\ndf = ['a', 'e', 'i', 'o', 'u']\r\nc = s[len(s) - 1]\r\nif c != 'n' and c not in df:\r\n print(\"NO\")\r\nelse:\r\n ok = 0\r\n for i in range(0, len(s)):\r\n if s[i] not in df and s[i] != 'n':\r\n if s[i + 1] not in df:\r\n ok = 1\r\n break\r\n if ok == 0: print(\"YES\")\r\n else: print(\"NO\")", "txt=input()\r\nl=len(txt)\r\nv=['a','e','i','o','u']\r\nresult='YES'\r\nfor i in range(l-1):\r\n if txt[i]!='n' and txt[i] not in v:\r\n if txt[i+1] not in v:\r\n result='NO'\r\nif txt[l-1] not in v and txt[l-1]!='n':\r\n result='NO'\r\nprint(result)", "vowel='aeiou'\r\nresult='YES'\r\ns=input() + \"#\"\r\nn = len(s)\r\nfor i in range(n-1):\r\n\tif (s[i] not in vowel+'n') and (s[i+1] not in vowel):\r\n\t\tresult='NO'\r\n\t\tbreak\r\nprint(result)", "s = input().strip()\r\nvowels = set(\"aeiou\")\r\nis_berlanese = True\r\n\r\nfor i in range(len(s)):\r\n if s[i] not in vowels and s[i] != 'n':\r\n if i == len(s) - 1 or s[i+1] not in vowels:\r\n is_berlanese = False\r\n break\r\n\r\nif is_berlanese:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "n=input()\r\na=\"aeiou\"\r\nfor i in n:\r\n if i not in a and i!=\"n\":\r\n if n[-1] not in \"aeioun\"or n[n.index(i)+1] not in a:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")\r\n", "string_s = input()\r\nvowels=\"aeiou\"\r\nskip_list=\"n\"\r\nerror_flag=0\r\nfor i in range(len(string_s)): \r\n if string_s[i] not in vowels+skip_list: \r\n if(i+1>=len(string_s) or string_s[i+1] not in vowels):\r\n error_flag=1\r\n\r\nprint({True: \"YES\", False: \"NO\"} [error_flag == 0])", "vowels= ('a','e','i','o','u')\r\ntxt= input()\r\nresult= \"yes\"\r\n\r\nif(len(txt)==1 and txt not in vowels):\r\n result= \"no\"\r\n\r\n if txt==\"n\":\r\n result= \"yes\"\r\n\r\nfor i in range(len(txt)-1):\r\n\r\n if(txt[i] not in vowels and txt[i]!=\"n\"):\r\n if(txt[i+1] not in vowels):\r\n result= \"no\"\r\n\r\n if(txt[-1] not in vowels and txt[-1]!=\"n\"):\r\n result=\"no\"\r\n\r\nprint(result)", "a = input('')\r\nb = 0\r\nc = len(a)\r\nif a[c-1] == 'n' or a[c-1] == 'a' or a[c-1] == 'e' or a[c-1] == 'i' or a[c-1] == 'o' or a[c-1] == 'u':\r\n b = 1\r\n for i in range(0, c-1):\r\n if (a[i] != 'n' or a[i] != 'a' or a[i] != 'e' or a[i] != 'i' or a[i] != 'o' or a[i] != 'u') and (a[i+1] == 'a' or a[i+1] == 'e' or a[i+1] == 'i' or a[i+1] == 'o' or a[i+1] == 'u'):\r\n b = 1\r\n elif (a[i] == 'a' or a[i] == 'e' or a[i] == 'i' or a[i] == 'o' or a[i] == 'u') and (a[i+1] == 'a' or a[i+1] == 'e' or a[i+1] == 'i' or a[i+1] == 'o' or a[i+1] == 'u'):\r\n b = 1\r\n elif a[i] == 'n':\r\n b = 1\r\n elif a[i] == 'a' or a[i] == 'e' or a[i] == 'i' or a[i] == 'o' or a[i] == 'u':\r\n b = 1\r\n else:\r\n b = 0\r\n break\r\n\r\nif b == 0:\r\n print('NO')\r\nelse:\r\n print('YES')", "b = 'aouei'\r\na = b + 'n'\r\ns = input()+' '\r\ndef lol(a, b, s):\r\n\tif s[-2] not in a: return 'NO'\r\n\tfor i in range(1, len(s)):\r\n\t\tif s[i-1] == 'n' and s[i] not in b: continue\r\n\t\tif s[i-1] not in b and s[i] not in b: return 'NO'\r\n\treturn 'YES'\r\nprint(lol(a, b, s))", "# -*- coding: utf-8 -*-\n\"\"\"Romaji.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1NNyf0Z257jHE-uQc_XQknVtqCMR6twTD\n\"\"\"\n\ns = input()+ ' '\noutput = 'YES'\nvowels = 'aeiou'\nl = len(s)\nfor i in range(l-1):\n if s[i] not in vowels +'n' and s[i+1] not in vowels:\n output = 'NO'\n break\nprint(output)", "#taking a str input and adding a period at the end(for getting an extra char)\r\ns = input()+\".\"\r\n#using len() to get the no of char in str s in int value\r\nn = len(s)\r\n#default result\r\nresult = \"YES\"\r\n#loop to check each char in str upto period(n-1th char)\r\nfor i in range(0,n-1):\r\n #in Berlanese n is an exception for checking\r\n if s[i] not in \"naeiou\" and s[i+1] not in \"aeiou\":\r\n result = \"NO\"\r\nprint(result)", "n = input()\r\nn = n + ' '\r\nx = 1\r\nl = len(n)\r\nfor i in range (l-1):\r\n if n[i] not in 'naeiou' and n[i+1] not in 'aeiou':\r\n x = 0\r\nif x == 1:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "s=input()\r\nfor i in range(len(s)):\r\n s+=' '\r\n if s[i] in 'bcdfghjklmpqrstvwxyz':\r\n if (s[i+1] not in 'aeiou')or len(s)==2:\r\n print('NO')\r\n break\r\nelse:print('YES')\r\n", "vowels='aeiou'\r\ndef isvowel(i):\r\n if i in vowels:\r\n return True\r\n else:\r\n return False\r\nt=str(input())\r\nl=(t[-1])\r\noutput='YES'\r\nfor i in range(len(t)-1):\r\n if isvowel(t[i]) and (isvowel(t[i+1]) or (not isvowel(t[i+1]))):\r\n output='YES'\r\n elif (not isvowel(t[i]) and isvowel(t[i+1])):\r\n output='YES'\r\n elif (t[i]=='n' and (isvowel(t[i+1]) or (not isvowel(t[i+1])))):\r\n output='YES'\r\n else:\r\n output='NO'\r\n break\r\nif output=='YES' and (isvowel(l) or l=='n'):\r\n print('YES')\r\nelse:\r\n print('NO')", "s=str(input())\r\nl=[\"a\",\"e\",\"i\",\"o\",\"u\"]\r\nc=0\r\nfor i in range(len(s)-1):\r\n if s[i] not in l and s[i]!=\"n\":\r\n if s[i+1] not in l:\r\n c+=1\r\n break\r\nif c==0 and (s[-1]==\"n\" or s[-1] in l):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") \r\n", "s = input().lower()\r\nx = 'aeiou'\r\ny = 'aeioun'\r\nz = 'a'\r\nanswer = 'YES'\r\nfor i in s :\r\n if z not in y and i not in x :\r\n answer = 'NO'\r\n break\r\n z=i\r\nif z not in y :\r\n answer = 'NO'\r\nprint(answer)", "klu = input()\r\nuni=['a','e','i','o','u']\r\n\r\nver=len(klu)\r\nfor i in range(ver):\r\n if klu[i] in uni or klu[i]=='n':\r\n continue\r\n else:\r\n if i==ver-1:\r\n print('NO')\r\n exit(0)\r\n\r\n else:\r\n if klu[i+1] not in uni:\r\n print('NO')\r\n exit(0)\r\n\r\nprint('YES')", "s=input()+\"*\"\r\nans=\"yes\"\r\nfor i in range(len(s)-1):\r\n if s[i] not in \"aeioun\"and s[i+1] not in \"aeiou\":\r\n ans=\"no\"\r\n break\r\nprint(ans) ", "s=input()\r\nn=len(s)\r\nvowel='aeiou'\r\nresult='YES'\r\nif s[-1] not in vowel and s[-1]!='n':\r\n result='NO'\r\nfor i in range(n-1):\r\n if s[i]!='n' and s[i] not in vowel:\r\n if s[i+1] not in vowel:\r\n result='NO'\r\nprint(result)\r\n", "s = input()+'*'\r\nn = len(s)\r\nr = \"YES\"\r\nfor i in range (n-1) :\r\n if s[i] not in \"aeioun\" and s[i+1] not in \"aeiou\" :\r\n r = \"NO\" \r\n break\r\nprint(r)", "n = input()\r\nres = \"YES\"\r\nfor i in range(len(n)):\r\n if len(n) > 1 and i+1 < len(n):\r\n if n[i] not in \"aouien\" and n[i + 1] not in \"aouie\":\r\n res = \"NO\"\r\n break\r\n else:\r\n if n[i] not in \"aouien\":\r\n res = \"NO\"\r\n break\r\nprint(res)", "s = input()\r\nv=['a','e','i','o','u']\r\nfor i in range(len(s)):\r\n if s[i] in v or s[i]=='n':\r\n continue\r\n else:\r\n if i==len(s)-1:\r\n print('NO')\r\n exit(0)\r\n else:\r\n if s[i+1] not in v:\r\n print('NO')\r\n exit(0)\r\nprint('YES')", "# -*- coding: utf-8 -*-\n\"\"\"Romaji\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1nXy2cfzPPJP05LVKrh4iNUCgL3lGIQv1\n\"\"\"\n\nn = input()\nn = n + ' '\nx = 1\nl = len(n)\nfor i in range (l-1):\n if n[i] not in 'naeiou' and n[i+1] not in 'aeiou':\n x = 0\nif x == 1:\n print('YES')\nelse:\n print('NO')", "n=input()\r\nx=len(n)\r\nvowel='aeiou'\r\nif n[-1]!=\"n\" and n[-1] not in vowel:\r\n print(\"no\")\r\n exit()\r\nelse:\r\n for i in range(x):\r\n if n[i] not in vowel and n[i]!=\"n\":\r\n if n[i+1] not in vowel:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")", "v='aouie'\r\ns=input()+'b'\r\nprint(('NO','YES')[all(x in v+'n'or y in v for x,y in zip(s,s[1:]))])", "s = input()\r\nans = \"YES\"\r\nfor i in range(1, len(s)):\r\n if s[i - 1] == 'n':\r\n continue\r\n if s[i - 1] in \"qwrtypsdfghjklzxcvbm\":\r\n if s[i] in \"euioa\":\r\n continue\r\n else:\r\n ans = \"NO\"\r\n break\r\n \r\nif s[len(s) - 1] not in \"euiaon\":\r\n ans = \"NO\"\r\n\r\nprint(ans)", "text=input()\r\nn=len(text)\r\ndef f(text):\r\n\tfor i in range(n-1):\r\n\t\tif text[i] not in list('aeioun') and text[i+1] not in list('aeiou'):\r\n\t\t\treturn 'NO'\r\n\tif text[-1] not in list('aeioun'):\r\n\t\treturn 'NO'\r\n\treturn 'YES'\r\n\t\t\t\t\t\r\nprint(f(text))", "input = input()\n\noutput = \"YES\" \n\nfor idx, num in enumerate(input):\n if num in \"Nn\":\n continue\n if num not in \"aeiouAEIOU\":\n if len(input) == (idx + 1):\n break\n else:\n if input[idx + 1] not in \"aeiouAEIOU\":\n output = \"NO\"\n\nif input[-1] not in \"aeioun\":\n output = \"NO\"\n\nprint(output)\n \t \t \t \t \t \t\t \t\t\t\t \t\t \t", "s = input()\r\na = 0\r\nif len(s) >= 1 and len(s) <= 100:\r\n if len(s)==1 and s not in 'aeioun':\r\n a = 1\r\n else:\r\n for i in range(len(s) - 1):\r\n if s[i] not in 'aeioun':\r\n if s[i+1] not in 'aeiou':\r\n a = 1\r\n if i == len(s)-2:\r\n if s[-1] not in 'aeioun':\r\n a = 1\r\nif a != 1:\r\n print('YES')\r\nelif a == 1:\r\n print('NO')", "n=list(input())\r\nl=['a','o','e','u','i']\r\nfor i in range(0,len(n)):\r\n if i<len(n)-1:\r\n for j in range(0,len(l)):\r\n if n[i]==l[j]:\r\n z=-1\r\n break\r\n z=i\r\n if z!=-1:\r\n if n[z]!='n':\r\n for j in range(0,len(l)):\r\n if n[i+1]==l[j]:\r\n j=-1\r\n break\r\n if j!=-1:\r\n print(\"NO\")\r\n break\r\n else:\r\n if n[i]=='n':\r\n print(\"YES\")\r\n else:\r\n for j in range(0,len(l)):\r\n if n[i]==l[j]:\r\n print(\"YES\")\r\n j=-1\r\n break\r\n if j!=-1:\r\n print(\"NO\")", "a=input()\r\nc=0\r\nv='aeiou'\r\nfor i in range(0,len(a)):\r\n if a[i] not in v and i!=len(a)-1:\r\n if a[i+1] in v or a[i]=='n':\r\n c+=0\r\n else:\r\n c+=1\r\n if i==len(a)-1 and a[i] not in v and a[i]!='n':\r\n c+=1\r\nif c==0:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n", "y=input()\r\nx=len(y)\r\nv=[\"a\",'e','i','o','u']\r\nresult=\"YES\"\r\nfor i in range(x-1):\r\n if y[i]!='n' and y[i] not in v:\r\n if y[i+1] not in v:\r\n result=\"NO\"\r\nif y[-1] not in v and y[-1]!='n':\r\n result=\"NO\"\r\nprint(result)", "import sys, io, os\r\nimport math\r\nimport bisect\r\nimport heapq\r\nimport string\r\nfrom collections import defaultdict,Counter,deque\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\n x x x\r\n x x x\r\n'''\r\n\r\ndef isPalindrome(a):\r\n l = 0\r\n r = len(a) - 1\r\n while l <= r:\r\n if a[l] != a[r]:\r\n return False\r\n l += 1\r\n r -= 1\r\n return True\r\n\r\ndef solve():\r\n s = I().strip()\r\n vowels = set([x for x in 'aeiou'])\r\n valid = True\r\n if s[-1] != 'n' and s[-1] not in vowels:\r\n valid = False\r\n for i in range(1, len(s)):\r\n if s[i-1] == 'n':\r\n continue\r\n elif s[i-1] not in vowels:\r\n if s[i] not in vowels:\r\n valid = False\r\n break\r\n print(\"YES\" if valid else \"NO\")\r\n\r\nsolve()", "s= input()\r\nflag = 0\r\nvowels=[\"a\",\"e\",\"i\",\"o\",\"u\"]\r\nfor i in range (len(s)-1):\r\n if s[i] !='n':\r\n if s[i] not in vowels and s[i+1] not in vowels:\r\n flag = 1\r\nif s[-1] not in vowels and s[-1] != 'n':\r\n flag = 1\r\nprint(\"YES\" if flag == 0 else \"NO\")", "s=input()\r\nn=len(s)\r\ns = s+'?'\r\nresult = 'YES'\r\nfor i in range(n):\r\n if s[i] in 'aeioun' :\r\n continue\r\n if s[i+1] not in 'aeiou' :\r\n result = 'NO'\r\n \r\nprint(result)\r\n", "vowels = \"aiueo\"\r\ns = input()\r\nn = len(s)\r\nfor i in range(n):\r\n if s[i] not in vowels + 'n':\r\n if (i + 1 < n and s[i + 1] not in vowels) or i + 1 == n:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")", "n=input()\r\n\r\nn=n+\" \"\r\n\r\nx=1\r\n\r\nl=len(n)\r\n\r\nfor i in range(l-1):\r\n if n[i] not in \"aeioun\"and n[i+1] not in \"aeiou\":\r\n x=0\r\nif x==1:\r\n print(\"yes\")\r\nelse:\r\n print(\"no\")", "x=input()+'*'\r\nresult='yes'\r\nn=len(x)\r\nfor i in range (n-1):\r\n if x[i] not in 'aeioun' and x[i+1] not in 'aeiou':\r\n result='No'\r\n break\r\nprint(result) ", "def roma():\n s = input(\"\")\n l = len(s)\n vowel = 'aeiou'\n if s[-1] != 'n' and s[-1] not in vowel:\n return \"NO\"\n for i in range(l-1):\n if s[i]!='n':\n if s[i] not in vowel:\n if s[i+1] not in vowel:\n return \"NO\"\n return \"YES\"\nprint(roma())\n", "p=input()\r\np=p+\" \"\r\nx=1\r\nl=len(p)\r\nfor i in range(l-1):\r\n if p[i] not in \"naeiou\"and p[i+1] not in \"aeiou\":\r\n x=0\r\nif x==1:\r\n print(\"yes\")\r\nelse:\r\n print(\"no\")", "s=input()+'*'\r\nresult='Yes'\r\nn=len(s)\r\nfor i in range(n-1):\r\n if s[i] not in 'aeioun' and s[i+1] not in 'aeiou':\r\n result='No'\r\n break\r\nprint(result) ", "i=input()\r\nv=\"aeiou\"\r\n\r\nfor c in i:\r\n if c not in v and c!=\"n\":\r\n if i[-1] not in \"aeioun\"or i[i.index(c)+1] not in v:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")", "vowels = set(['a', 'e', 'i', 'o', 'u'])\r\n\r\ns = input().strip()\r\n\r\nfor i in range(len(s)):\r\n if s[i] not in vowels and s[i] != 'n':\r\n if i == len(s) - 1 or s[i+1] not in vowels:\r\n print(\"NO\")\r\n break\r\n if i == len(s) - 1:\r\n print(\"YES\")\r\n", "\r\ndef is_vowel(lang):\r\n vowels = 'a'' e' 'i' 'o' 'u'\r\n n = len(lang)\r\n for i in range(n):\r\n if lang[i] not in vowels and lang[i] != 'n':\r\n if i == n - 1 or lang[i + 1] not in vowels:\r\n return 'NO'\r\n return 'YES'\r\n\r\n\r\ns = input()\r\nprint(is_vowel(s))", "s = input()\r\na = ['a', 'e', 'u', 'i', 'o']\r\nans = \"YES\"\r\nfor i in range(len(s) - 1):\r\n if s[i] not in a and s[i] != 'n' and s[i + 1] not in a:\r\n ans = \"NO\"\r\n break\r\nif s[-1] not in a and s[-1] != 'n':\r\n ans = \"NO\"\r\nprint(ans)\r\n\r\n", "#method 1\r\ndef berlanese(word):\r\n vowels = 'aeiou'\r\n n = len(word)\r\n for i in range(n):\r\n if word[i] not in vowels and word[i] != 'n':\r\n if i == n - 1 or word[i + 1] not in vowels:\r\n return 'NO'\r\n return 'YES'\r\n \r\ns = input()\r\nprint (berlanese(s))", "palavra = input()\n\nr = True\n\n \n\nfor i in range(0,len(palavra)):\n letra = palavra[i]\n \n if (letra != \"a\" and letra != \"e\" and letra != \"i\" and letra != \"o\" and letra != \"u\" and letra !=\"n\") and (i != len(palavra)-1):\n \n if palavra[i+1] != \"a\" and palavra[i+1] != \"e\" and palavra[i+1] != \"i\" and palavra[i+1] != \"o\" and palavra[i+1] != \"u\":\n r = False\n \n if i == len(palavra)-1:\n \n if letra != \"a\" and letra != \"e\" and letra != \"i\" and letra != \"o\" and letra != \"u\" and letra != \"n\":\n r = False\n\nif r == False:\n print(\"NO\")\nelse:\n print(\"YES\") \n\n \n\n\t \t\t \t \t \t\t\t \t \t\t\t \t\t\t \t\t", "t = input()\r\nres = 'YES'\r\nfor i in range(len(t)):\r\n if t[i] not in 'aeioun':\r\n if i == len(t)-1:\r\n res = 'NO'\r\n break\r\n elif t[i + 1] not in 'aeiou':\r\n res = 'NO'\r\n break\r\n\r\nprint(res)", "s=input()+' '\r\nans='YES'\r\nn=len(s)\r\nfor i in range (n-1):\r\n if s[i] not in 'aeioun' and s[i+1] not in 'aeiou':\r\n ans='NO'\r\n break\r\nprint(ans)", "s=input()\r\na=len(s)\r\nvow='aeiou'\r\nans = \"YES\"\r\nfor i in range(a-1):\r\n if s[i]!='n' and s[i] not in vow:\r\n if s[i+1] not in vow:\r\n ans=\"NO\"\r\nif s[-1] not in vow and s[-1]!='n':\r\n ans=\"NO\"\r\nprint(ans)", "n = input()\r\n\r\ngl = \"aouie\"\r\nfor i in range(len(n)):\r\n s = n[i]\r\n if not (s in gl):\r\n if s != 'n':\r\n if i + 1 == len(n):\r\n print(\"NO\")\r\n break\r\n else:\r\n if not (n[i + 1] in gl):\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")", "s = input()\nvowels = {\"a\", \"e\", \"i\", \"o\", \"u\"}\nvowels_or_n = vowels | {\"n\"}\nres = \"NO\" if s[-1] not in vowels_or_n else \"YES\"\nfor i in range(1, len(s)):\n if s[i - 1] not in vowels_or_n and s[i] not in vowels:\n res = \"NO\"\n break\nprint(res)\n", "s = input().strip()\r\n\r\nfor i in range(len(s)):\r\n if s[i] not in \"aeiou\" and s[i] != 'n':\r\n if i == len(s)-1 or s[i+1] not in \"aeiou\":\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")\r\n", "t=input()\r\nfor i in range(len(t)):\r\n t+=' '\r\n if(t[i] not in \"aeioun\"):\r\n if(t[i+1] not in \"aeiou\"):\r\n print(\"NO\")\r\n break\r\nelse:print(\"yes\")", "s = input()\r\nl = s.__len__()\r\nflag = True\r\n\r\nfor i in range(0, l - 1):\r\n if s[i] != 'a' and s[i] != 'e' and s[i] != 'i' and s[i] != 'o' and s[i] != 'u' and s[i] != 'n' and s[i + 1] != 'a' and s[i + 1] != 'e' and s[i + 1] != 'i' and s[i + 1] != 'o' and s[i + 1] != 'u':\r\n flag = False\r\n break\r\n\r\nif s[l - 1] != 'a' and s[l - 1] != 'e' and s[l - 1] != 'i' and s[l - 1] != 'o' and s[l - 1] != 'u' and s[l - 1] != 'n':\r\n flag = False\r\n\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "def isRomaji(s):\r\n lst=['a','e','i','o','u']\r\n for i in range(len(s)):\r\n if s[i]!='n' and s[i] not in lst:\r\n if i==len(s)-1:\r\n return False\r\n else:\r\n if s[i+1] not in lst:\r\n return False\r\n return True\r\ns=input()\r\nif isRomaji(s):\r\n print('YES')\r\nelse:\r\n print('NO')", "vow=\"aeiou\"\r\nconso=\"bcdfghjklmnpqrstvwxyz\"\r\ns=input()\r\nif s[-1] not in vow and s[-1]!='n':\r\n print(\"NO\")\r\nelse:\r\n for i in range(len(s)):\r\n if s[i]=='n':\r\n pass\r\n elif s[i] in conso:\r\n if s[i+1] not in vow:\r\n print(\"NO\")\r\n break\r\n else:\r\n print(\"YES\")\r\n", "n=input()\r\ns=len(n)\r\nv=['a','e','i','o','u']\r\nresult=\"YES\"\r\nfor i in range(s-1):\r\n if n[i]!='n' and n[i] not in v:\r\n if n[i+1] not in v:\r\n result=\"NO\"\r\nif n[-1] not in v and n[-1]!='n':\r\n result=\"NO\"\r\nprint(result)", "def consonant(y):\r\n if y != 'a' and y != 'e' and y != 'i' and y != 'o' and y != 'u':\r\n return True\r\n \r\ntext = input()+\" \"\r\nx = len(text)\r\na = 0\r\nb = 0\r\nc = 0\r\nd = 0\r\n \r\nif x==1 and consonant(text[0]) and text[0]!='n':\r\n d+=1\r\nelse:\r\n for i in range(x-1):\r\n if consonant(text[i]) and text[i]!='n':\r\n if not consonant(text[i+1]):\r\n a+=1\r\n elif consonant(text[x-1]) and text[i]!='n':\r\n b+=1\r\n else:\r\n c+=1\r\n \r\n \r\n \r\nif (b or c or d)>=1:\r\n print('NO')\r\nelse:\r\n print('YES')\r\n", "t=input()\r\nn=len(t)\r\na=0\r\nb=0\r\nc=0\r\nz='abcdefghijklmnopqrstuvwxyz'\r\nfor i in range(n-1):\r\n if t[i] in 'aeiou':\r\n if t[i+1] in z:\r\n a=a+1\r\n elif t[i] not in 'aeioun':\r\n if t[i+1] in 'aeiou':\r\n b=b+1\r\n elif t[i]=='n':\r\n if t[i+1] in z: \r\n c=c+1\r\nif (a+b+c==n-1)and t[n-1] in 'aeioun':\r\n print('Yes')\r\nelse:\r\n print('NO') ", "def main():\r\n ans=True\r\n s=input()\r\n if ord(s[-1])!=97 and ord(s[-1])!=101 and ord(s[-1])!=105 and ord(s[-1])!=111 and ord(s[-1])!=117 and ord(s[-1])!=110:\r\n ans=False\r\n else:\r\n for i in range(len(s)-1):\r\n if ord(s[i])!=97 and ord(s[i])!=101 and ord(s[i])!=105 and ord(s[i])!=111 and ord(s[i])!=117 and ord(s[i])!=110:\r\n if ord(s[i+1])!=97 and ord(s[i+1])!=101 and ord(s[i+1])!=105 and ord(s[i+1])!=111 and ord(s[i+1])!=117:\r\n ans=False\r\n break \r\n if ans:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nmain()", "text = input()\r\ncount = 0\r\ncounta = 0\r\ns = len(text)\r\nif 1<=s<=100:\r\n for i in range(s-1):\r\n if text[i] not in 'aeioun':\r\n counta = counta + 1\r\n if text[i+1] in 'aeiou':\r\n count = count + 1\r\n if text[s-1] not in 'aeioun' or count!=counta:\r\n print('No')\r\n elif s==1 and text[s-1] not in 'aeioun':\r\n print('NO')\r\n else:\r\n print('YES')", "s=[i for i in input()]\r\nvowel=['a','e','i','o','u']\r\nk=1\r\nfor i in range(len(s)-1):\r\n x=s.pop(0)\r\n if x not in vowel and x!='n':\r\n if s[0] not in vowel:\r\n print('no')\r\n k=0\r\n break\r\nif s[-1] not in vowel and s[-1]!='n' and k==1:\r\n print('no')\r\n k=0\r\nif k==1:\r\n print('yes')", "text=input()\r\nl=len(text)\r\nv=['a','e','i','o','u']\r\nresult=\"YES\"\r\nfor i in range(l-1):\r\n if text[i]!='n' and text[i] not in v:\r\n if text[i+1] not in v :\r\n result=\"NO\"\r\nif text[l-1] not in v and text[l-1]!='n':\r\n result=\"NO\"\r\nprint(result)", "text=input()\r\nn=len(text)\r\nvowels=['a','e','i','o','u']\r\ncount=0\r\ny='NO'\r\nfor i in range(n-1):\r\n if text[i] in vowels or text[i]=='n':\r\n if text[i+1] in vowels or text[i+1] not in vowels:\r\n count+=1\r\n elif text[i] not in vowels and text[i]!='n':\r\n if text[i+1] in vowels:\r\n count+=1\r\nif count==(n-1):\r\n if text[n-1] in vowels or text[n-1]=='n':\r\n y='YES'\r\nprint(y)", "s = input()+ ' '\r\nvowels = 'aeiou'\r\nresult = 'YES'\r\nn = len(s)\r\nfor i in range(n-1):\r\n if s[i] not in vowels+'n' and s[i+1] not in vowels:\r\n result = 'NO'\r\n break\r\nprint(result)", "a=input()\r\nb='aeiou'\r\nc='aeioun'\r\nn=len(a)\r\nd='yes'\r\nfor i in range(n):\r\n if a[-1] not in c:\r\n d='no'\r\n elif a[i] not in c and a[i+1] not in b:\r\n d='no'\r\nprint(d)", "yy='aeiou'\r\nw=input()\r\npd=1\r\nfor i in range(0,len(w)):\r\n if(not(w[i] in yy) and w[i]!='n'):\r\n if(i==len(w)-1 or not w[i+1] in yy):\r\n pd=0\r\n break\r\nif(pd==0): print(\"NO\")\r\nelse: print(\"YES\")", "s = input()\nn = len(s)\n\nv = ['a', 'e', 'i', 'o', 'u']\nc = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z']\nsp = 'n'\n\nfor index, l in enumerate(s):\n try:\n if l in c and s[index + 1] not in v:\n print('NO')\n exit()\n except IndexError:\n print('NO')\n exit()\nprint('YES')\n\n\t\t \t \t \t \t \t \t \t \t \t \t\t\t", "n=input()\r\nfinal='yes'\r\nif n[-1] not in'aeioun':\r\n final='NO'\r\na=len(n)\r\nfor i in range(a-1):\r\n if n[i] not in 'aeioun' and n[i+1] not in 'aeiou':\r\n final='NO'\r\nprint(final)\r\n ", "text=input().lower()\r\nvowels=['a','e','i','o','u']\r\nans='YES'\r\nfor i in range(len(text)):\r\n if text[i]!='n' and text[i] not in vowels:\r\n try:\r\n if text[i+1] not in vowels:\r\n ans='NO'\r\n break\r\n except IndexError:\r\n if text[-1]=='n':\r\n ans='YES'\r\n else:\r\n ans='NO'\r\nprint(ans)", "napo = input()\r\nsub=['a','e','i','o','u']\r\nver=len(napo)\r\nfor i in range(ver):\r\n if napo[i] in sub or napo[i]=='n':\r\n continue\r\n else:\r\n if i==ver-1:\r\n print('NO')\r\n exit(0)\r\n\r\n else:\r\n if napo[i+1] not in sub:\r\n print('NO')\r\n exit(0)\r\n\r\nprint('YES')", "s=input()\r\nvowels=\"aeiou\"\r\ncondition=True\r\nfor i in range(len(s)):\r\n if s[i] not in vowels and s[i]!=\"n\":\r\n if i<len(s)-1:\r\n if s[i+1] not in vowels:\r\n condition=False\r\n break\r\n else:\r\n condition=False\r\n break\r\nif condition:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n", "p = input('')\r\nq = 0\r\nr = len(p)\r\nif p[r-1] == 'n' or p[r-1] == 'a' or p[r-1] == 'e' or p[r-1] == 'i' or p[r-1] == 'o' or p[r-1] == 'u':\r\n q = 1\r\n for i in range(0, r-1):\r\n if (p[i] != 'n' or p[i] != 'a' or p[i] != 'e' or p[i] != 'i' or p[i] != 'o' or p[i] != 'u') and (p[i+1] == 'a' or p[i+1] == 'e' or p[i+1] == 'i' or p[i+1] == 'o' or p[i+1] == 'u'):\r\n q = 1\r\n elif (p[i] == 'a' or p[i] == 'e' or p[i] == 'i' or p[i] == 'o' or p[i] == 'u') and (p[i+1] == 'a' or p[i+1] == 'e' or p[i+1] == 'i' or p[i+1] == 'o' or p[i+1] == 'u'):\r\n q = 1\r\n elif p[i] == 'n':\r\n q = 1\r\n elif p[i] == 'a' or p[i] == 'e' or p[i] == 'i' or p[i] == 'o' or p[i] == 'u':\r\n q = 1\r\n else:\r\n q = 0\r\n break\r\nelse:\r\n q = 0\r\n\r\nif q == 0:\r\n print('NO')\r\nelse:\r\n print('YES')", "s = input()\r\nl = len(s)\r\nk = 0\r\nif 1<=l<=100 and s.isalpha():\r\n for i in range(l):\r\n if s[i] in \"bcdfghjklmpqrstvwxyz\":\r\n if i==l-1:\r\n k=1\r\n elif s[i+1] not in \"aeiou\":\r\n k=1\r\nif k==0:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "s = input() \r\ns=s+\" \"\r\nx=1\r\nl=len(s)\r\nfor i in range(l-1):\r\n if s[i] not in \"aeioun\" and s[i+1] not in \"aeiou\":\r\n x=0\r\nif x==1:\r\n print(\"yes\")\r\nelse:\r\n print(\"no\")", "s = input()\r\nn = len(s)\r\ns += '#'\r\ncount = 0\r\nfor i in range(n):\r\n if s[i] in 'aeioun':\r\n continue\r\n if s[i+1] not in 'aeiou':\r\n count+=1\r\nif count>=1:\r\n print('NO')\r\nelse:\r\n print('YES')", "text = input()\r\nn = len(text)\r\nresult = \"yes\"\r\nif text[-1] not in \"aeioun\":\r\n result = \"no\"\r\nfor i in range(n-1):\r\n if text[i] not in \"aeioun\":\r\n if text[i+1] not in \"aeiou\":\r\n result = \"no\"\r\n break\r\nprint(result)", "#w6-romaji\r\n\r\ndef space(txt) :\r\n if (txt=='a' or txt=='e' or txt=='i' or txt=='o' or txt=='u'):\r\n return True\r\n else:\r\n return False\r\n \r\nx=input()\r\ny=len(x)\r\nsol='YES' \r\n \r\nif (len(x)==1 and x[0]!='n' and not space(x[0])):\r\n sol='NO'\r\n \r\nfor i in range(0,y-1):\r\n \r\n if(not space(x[i]) and x[i]!='n' and not space(x[i+1])):\r\n sol=\"NO\"\r\n \r\n if (not space(x[y-1]) and x[y-1]!='n'):\r\n sol='NO'\r\n \r\nprint(sol)", "s=input()\r\nv='aeiou'\r\na='YES'\r\ns=s+' '\r\nfor i in range(len(s)-1):\r\n if (s[i] not in v+'n') and (s[i+1] not in v):\r\n a='NO'\r\n break\r\n else:\r\n pass\r\nprint(a)", "a=input()\r\nb=len(a)\r\nv=['a','e','i','o','u']\r\nx=\"yes\"\r\nfor i in range (b-1):\r\n if (a[i]!='n' and a[i] not in v):\r\n if (a[i+1] not in v):\r\n x=\"no\"\r\nif(a[b-1] not in v and a[b-1]!='n'):\r\n x=\"no\"\r\nprint(x)", "s = input()\n\nvogais = \"aouie\"\nif(len(s) == 1): \n if vogais.find(s[0]) != -1 or s[0] == 'n': \n print('YES')\n exit()\n else:\n print('NO')\n exit()\n\nfor i in range(1, len(s)):\n if(s[i-1] != 'n' and vogais.find(s[i-1]) == -1 and vogais.find(s[i]) == -1 ):\n print('NO')\n exit()\n \nif vogais.find(s[-1]) != -1 or s[-1] == 'n':\n print('YES')\n exit()\nelse:\n print('NO')\n exit()\n \t \t\t\t \t \t \t \t\t \t\t \t \t\t \t\t", "s=input()+' '\r\nc=1\r\nfor i in range(len(s)-1):\r\n if s[i] in ('aeioun'):\r\n continue\r\n else:\r\n if s[i+1] not in ('aeiou'):\r\n c=0\r\n break\r\nif c==1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "# -*- coding: utf-8 -*-\n\"\"\"romaji assignment.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1YNI9ppcYvIrXjPplYx7gkxH4R-aDplOC\n\"\"\"\n\ns=input()\nx=len(s)\nv=['a','e','i','o','u']\nresult='Yes'\nfor i in range(x-1):\n if s[i]!='n'and s[i] not in v:\n if s[i+1] not in v:\n result='No'\nif s[-1] not in v and s[-1]!='n':\n result='No'\nprint(result)", "word = input().lower()\r\nvowels = ['a', 'e', 'i', 'o', 'u']\r\nans = \"YES\"\r\nfor i in range(len(word)):\r\n if word[i] != 'n' and word[i] not in vowels:\r\n try:\r\n if word[i+1] not in vowels:\r\n ans = \"NO\"\r\n break\r\n except IndexError:\r\n if word[-1] == 'n':\r\n ans = \"YES\"\r\n else:\r\n ans = \"NO\"\r\nprint(ans)", "text = input()\r\ncount = 0\r\ncount1 = 0\r\nx = len(text)\r\nif 1 <= x <= 100:\r\n for i in range (x-1):\r\n if text[i] not in 'aeioun':\r\n count1 = count1 + 1\r\n if text[i+1] in 'aeiou':\r\n count = count + 1\r\n if text[x-1] not in 'aeioun' or count!=count1:\r\n print('NO')\r\n elif x==1 and text[x-1] not in 'aeioun':\r\n print('NO')\r\n else:\r\n print('YES')", "s=input()\r\nlength=len(s)\r\nv=[\"a\",\"e\",\"i\",\"o\",\"u\"] #defining vowels\r\nlst=[]\r\n\r\nif s[-1]!=\"n\" and s[-1] not in v: #checking whther the last letter is a vowel or n\r\n lst.append(\"NO\")\r\n\r\nelse:\r\n for i in range(length):\r\n if s[i] not in v and s[i]!=\"n\": #checking each character for vowel or n\r\n if s[i+1] not in v:\r\n lst.append(\"NO\")\r\n else:\r\n lst.append(\"YES\")\r\n \r\nif \"NO\" in lst:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n", "#This was submitted to codeforces.com\r\n\r\n#Function to check if char is a vowel\r\ndef chkVow(s1):\r\n return (s1 in \"aeiou\")\r\n\r\ns=input()\r\nn=len(s)\r\nflag=1\r\n\r\nif(s[-1]!='n' and chkVow(s[-1])==False):\r\n flag=0\r\nelse:\r\n for i in range(n):\r\n if chkVow(s[i])==False and s[i]!='n':\r\n if chkVow(s[i+1])==False:\r\n flag=0\r\n break\r\nif(flag==0):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")", "s = input()+ ' '\r\noutput = 'YES'\r\nvowels = 'aeiou'\r\nl = len(s)\r\nfor i in range(l-1):\r\n if s[i] not in vowels+'n' and s[i+1] not in vowels:\r\n output = 'NO'\r\n break\r\nprint(output)", "x=input()\r\nx=x.lower()\r\np=0\r\nif len(x) >= 1 and len(x)<=100:\r\n if len(x)==1 and x not in 'aeioun':\r\n p=1\r\n else:\r\n for i in range(len(x)-1):\r\n if x[i] not in 'aeioun':\r\n if x[i+1] not in 'aeiou':\r\n p=1\r\n if i==len(x)-2:\r\n if x[-1] not in 'aeioun':\r\n p=1\r\n \r\n \r\nif p != 1:\r\n print('YES')\r\nelif p==1:\r\n print('NO')\r\n \r\n \r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n", "a=input()\r\nc=0\r\nif a[-1] in 'aeioun':\r\n for i in range(0,len(a)-1):\r\n if a[i] not in 'aeioun':\r\n if a[i+1] not in 'aeiou':\r\n print('NO')\r\n c=c+1\r\n break\r\n \r\nelse:\r\n print('NO')\r\n c=c+1\r\nif c==0:\r\n print('YES')", "x = \"Bizon Senior loves suffix automaton By applying it once to a string he can remove from this string any single character\"\r\nx = input()\r\ndef myword(x):\r\n isB = True\r\n while (len(x) > 0):\r\n # we choose to eat the word like sandwich\r\n # another way is to set a counter and scroll over the worl until reach its end\r\n if (x[0] == 'a' or x[0] == 'o' or x[0] == 'u' or x[0] == 'i' or x[0] == 'e' or x[0] == 'n'):\r\n x = x[1:]\r\n else:\r\n if(len(x)==1):\r\n isB = False\r\n break\r\n if (x[1] == 'a' or x[1] == 'o' or x[1] == 'u' or x[1] == 'i' or x[1] == 'e'):\r\n x = x[2:]\r\n else:\r\n isB = False\r\n break\r\n if (isB):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nl = x.split(' ')\r\nfor i in l:\r\n try:\r\n i = i.lower()\r\n myword(i)\r\n except Exception as e:\r\n print(\"Oops!\", e.__class__, \"occurred.\")\r\n print(\"input is :\"+ i + \" next word\")\r\n print()\r\n", "s = input()\r\nv = ('a','e','i','o','u')\r\nn = len(s)\r\nresult = 'Yes'\r\nfor i in range(0,n) :\r\n if s[i] in v or s[i]=='n' :\r\n continue\r\n else :\r\n if i == n-1 :\r\n result = 'No'\r\n break\r\n else :\r\n if s[i+1] not in v :\r\n result = 'No'\r\nprint(result)", "s = input()\r\nexc = ['a','e','i','o','u']\r\nif len(s)>1:\r\n for i in range(len(s)):\r\n if s[-1] in exc or s[-1]=='n':\r\n x=1\r\n else:\r\n x=0\r\n break\r\n if s[i]=='n':\r\n x=1\r\n elif s[i] not in exc and s[i+1] in exc:\r\n x=1\r\n elif s[i] in exc:\r\n x=1\r\n else:\r\n x=0\r\n break\r\nelif s not in exc and s!='n':\r\n x=0\r\nelse:\r\n x=1\r\n \r\nif x>0:\r\n print('YES')\r\nelse:\r\n print('NO')", "s = input()\r\nn = len(s)\r\nresult = \"YES\"\r\n\r\ndef is_vowel(ch):\r\n vowels='aeiou'\r\n if ch in vowels:\r\n return True\r\n else:\r\n return False\r\n\r\n\r\nif s[-1] in 'aeioun':\r\n for i in range(0,len(s)-1):\r\n if (s[i] == 'n' ):\r\n result = \"YES\"\r\n continue\r\n elif (not is_vowel(s[i]) and not is_vowel(s[i+1])):\r\n result = \"NO\"\r\n break\r\n\r\nelse:\r\n result = \"NO\"\r\n \r\nprint (result)", "s = input()\na = 'abcdefghijklmnopqrstuvwxyz'\nv = 'aeiou'\nc = [i for i in a if i not in v]\nc.remove('n')\ns += \" \"\nprint([\"NO\", \"YES\"][all(s[x + 1] in v for x in range(0, len(s)) if s[x] in c)])\n", "s = input()\r\na = 'aeiou'\r\nb='aeioun'\r\nx='a'\r\nans = 'YES'\r\nfor c in s:\r\n if x not in b and c not in a:\r\n ans = 'NO'\r\n break\r\n x = c\r\nif x not in b:\r\n ans = 'NO'\r\nprint(ans)", "n =input()\nn=n+\" \"\nx=1\nl =len(n)\nfor i in range(l-1):\n if n[i] not in \"naeiou\" and n[i+1] not in \"aeiou\":\n x=0\nif x==1:\n print(\"yes\")\nelse:\n print(\"no\")\n\t\t\t\t \t \t\t\t \t\t \t\t\t \t \t", "vowels='aeiou'\r\nresult=\"YES\"\r\ns=input()+'*'\r\nfor i in range(len(s)-1):\r\n if (s[i] not in vowels+'n') and (s[i+1] not in vowels):\r\n result=\"NO\"\r\n break\r\nprint(result)\r\n", "k = input()\r\nn = len(k)\r\nvowel = 'aeiou'\r\nresult = 'YES'\r\nif k[-1] not in vowel and k[-1]!= 'n':\r\n result = 'NO'\r\nfor i in range(n - 1):\r\n if k[i]!= 'n' and k[i] not in vowel:\r\n if k[i + 1] not in vowel:\r\n result = 'NO'\r\nprint(result)", "s=str(input(''))\r\nfor i in range(len(s)):\r\n if s[i] not in ('a','e','i','o','u','n'):\r\n if i==len(s)-1:\r\n print('NO')\r\n break\r\n elif s[i+1] in ('a','e','i','o','u'):\r\n pass\r\n else:\r\n print('NO')\r\n break\r\nelse:\r\n print('YES')", "s=input()\r\nn=len(s)\r\ns=s+'?'\r\nresult='YES'\r\nfor i in range(n):\r\n if s[i] in 'aeioun':\r\n continue\r\n if s[i+1] not in 'aeiou':\r\n result='no'\r\nprint(result)", "s=input()\r\nl=['a','e','i','o','u','n']\r\nv=['a','e','i','o','u']\r\ns=s+'n'\r\na=True\r\nfor i in range(len(s)-1):\r\n if s[i]not in l and s[i+1]not in v:\r\n a=False\r\nif a:\r\n print('YES')\r\nelse:\r\n print('NO')", "s = input()\r\nv=['a','e','i','o','u']\r\nn=len(s)\r\nfor i in range(n):\r\n if s[i] in v or s[i]=='n':\r\n continue\r\n else:\r\n if i==n-1:\r\n print('NO')\r\n exit(0)\r\n\r\n else:\r\n if s[i+1] not in v:\r\n print('NO')\r\n exit(0)\r\nprint('YES')", "x=input()\r\nl=len(x)\r\nv=['a','e','i','o','u']\r\nres='YES'\r\nfor i in range(l-1):\r\n if x[i]!='n' and x[i] not in v:\r\n if x[i+1] not in v:\r\n res='NO'\r\nif x[l-1] not in v and x[l-1]!='n':\r\n res='NO'\r\nprint(res)", "def vowel(ch):\r\n if ch=='a'or ch=='e'or ch=='i'or ch=='o'or ch=='u':\r\n return True\r\n else:\r\n return False\r\nw=input()\r\nn=len(w)\r\nr='Yes'\r\nfor i in range(n-1):\r\n if not vowel(w[i]) and not vowel(w[i+1]) and w[i]!='n':\r\n r='No'\r\n break\r\nif w[n-1]!='n'and not vowel(w[n-1]):\r\n r='No'\r\nprint(r)", "#cook your code here\r\ns = input()\r\nflag = 0\r\nnilam_arki = \"aouie\"\r\nfor i in range(len(s)-1):\r\n #print(s[i])\r\n if s[i] == 'n':\r\n pass\r\n elif s[i] not in nilam_arki:\r\n if s[i+1] not in nilam_arki:\r\n flag = 1\r\n break\r\nif s[-1] not in nilam_arki and s[-1] != 'n':\r\n flag = 1\r\nif flag == 0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s = input()\r\na = [\"a\", \"i\", \"u\", \"e\", \"o\", \"n\"]\r\nans = \"YES\"\r\nfor i in range(len(s)):\r\n if s[i] not in a:\r\n if i == len(s)-1:\r\n ans = \"NO\"\r\n elif s[i+1] not in a:\r\n ans = \"NO\"\r\n elif s[i+1] == \"n\":\r\n ans = \"NO\"\r\n\r\nprint(ans)", "# -*- coding: utf-8 -*-\n\"\"\"Untitled22.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/13RzkPnDyxDxlygLjxlGmrHRvhkkQbiYb\n\"\"\"\n\na = input()\nn = len(a)\nresult = 'yes'\nfor i in range(n-1):\n if (a[i] != 'a' and a[i] != 'e' and a[i] != 'i' and a[i] != 'o' and a[i] != 'u' and a[i] != 'n'):\n if(a[i+1] != 'a' and a[i+1] != 'e' and a[i+1] != 'i' and a[i+1] != 'o' and a[i+1] != 'u'):\n result = 'no'\nif a[n-1]!='a' and a[n-1]!='e' and a[n-1]!='i' and a[n-1]!='o' and a[n-1]!='u' and a[n-1]!='n':\n result = 'no'\nprint(result)", "s = input()\r\nl = len(s)\r\nv = ('a','e','i','o','u')\r\nresult = 'yes'\r\nfor i in range (l-1) :\r\n if (s[i]!='n'and s[i] not in v) :\r\n if (s[i+1] not in v ):\r\n result = 'no'\r\nif (s[l-1] not in v and s[l-1]!='n') :\r\n result = 'no'\r\nprint(result)", "x=input()\r\np=0\r\nif (len(x) >= 1 and len(x)<=100):\r\n if (len(x)==1 and x not in 'aeioun'):\r\n p=1\r\n else:\r\n for i in range(len(x)-1):\r\n if (x[i] not in 'aeioun'):\r\n if (x[i+1] not in 'aeiou'):\r\n p=1\r\n if (i==len(x)-2):\r\n if (x[-1] not in 'aeioun'):\r\n p=1\r\n \r\n \r\nif (p != 1):\r\n print('YES')\r\nelif (p==1):\r\n print('NO')", "s=input()\r\ns=s+\" \"\r\nans=\"YES\"\r\nfor i in range(len(s)-1):\r\n if not s[i] in ['a','e','i','o','u','n'] and s[i+1] not in ['a','e','i','o','u']:\r\n ans=\"NO\"\r\nprint(ans)" ]
{"inputs": ["sumimasen", "ninja", "codeforces", "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen", "n", "necnei", "nternn", "aucunuohja", "a", "b", "nn", "nnnzaaa", "zn", "ab", "aaaaaaaaaa", "aaaaaaaaab", "aaaaaaaaan", "baaaaaaaaa", "naaaaaaaaa", "nbaaaaaaaa", "bbaaaaaaaa", "bnaaaaaaaa", "eonwonojannonnufimiiniewuqaienokacevecinfuqihatenhunliquuyebayiaenifuexuanenuaounnboancaeowonu", "uixinnepnlinqaingieianndeakuniooudidonnnqeaituioeneiroionxuowudiooonayenfeonuino", "nnnnnyigaveteononnnnxaalenxuiiwannntoxonyoqonlejuoxuoconnnentoinnul", "ndonneasoiunhomuunnhuitonnntunntoanerekonoupunanuauenu", "anujemogawautiedoneobninnibonuunaoennnyoorufonxionntinimiboonununnnnnleenqunminzayoutanlalo", "y", "by", "yy", "nbn", "nz", "king", "g", "az", "x", "z", "yn", "aeo", "nb", "npn", "kini", "pya", "m", "p", "aaaaaaaak", "aab", "d", "at", "aaaaaak", "aaz", "aaab", "s", "nzzen", "aeionnhhhn", "h", "ny"], "outputs": ["YES", "YES", "NO", "YES", "YES", "NO", "NO", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "YES", "YES", "YES", "YES", "NO", "NO", "YES", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO"]}
UNKNOWN
PYTHON3
CODEFORCES
159
19c0291bd1c79abe04f3ac01b584c1e5
Powerful array
An array of positive integers *a*1,<=*a*2,<=...,<=*a**n* is given. Let us consider its arbitrary subarray *a**l*,<=*a**l*<=+<=1...,<=*a**r*, where 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. For every positive integer *s* denote by *K**s* the number of occurrences of *s* into the subarray. We call the power of the subarray the sum of products *K**s*·*K**s*·*s* for every positive integer *s*. The sum contains only finite number of nonzero summands as the number of different values in the array is indeed finite. You should calculate the power of *t* given subarrays. First line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=200000) — the array length and the number of queries correspondingly. Second line contains *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=106) — the elements of the array. Next *t* lines contain two positive integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) each — the indices of the left and the right ends of the corresponding subarray. Output *t* lines, the *i*-th line of the output should contain single positive integer — the power of the *i*-th query subarray. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout stream (also you may use %I64d). Sample Input 3 2 1 2 1 1 2 1 3 8 3 1 1 2 2 1 3 1 1 2 7 1 6 2 7 Sample Output 3 6 20 20 20
[ "from collections import defaultdict\r\nfrom operator import itemgetter\r\nimport math\r\n\r\nclass Mo:\r\n def __init__(self, ls):\r\n self.ls = ls\r\n self.n = len(ls)\r\n self.m = max(ls)+1\r\n self.b = math.ceil(math.sqrt(self.n))\r\n\r\n def _init_states(self):\r\n self.ans = 0\r\n self.cnt = [0]*self.m\r\n\r\n self.l = 0\r\n self.r = 0\r\n\r\n self.bucket = [[] for i in range(self.b+1)]\r\n\r\n def _add(self, i):\r\n self.cnt[self.ls[i]] += 1\r\n k = self.cnt[self.ls[i]]\r\n a = self.ls[i]\r\n self.ans += (2*k-1)*a\r\n\r\n def _delete(self, i):\r\n k = self.cnt[self.ls[i]]\r\n a = self.ls[i]\r\n self.ans -= (2*k-1)*a\r\n self.cnt[self.ls[i]] -= 1\r\n\r\n def _one_process(self, l, r):\r\n for i in range(self.r, r):\r\n self._add(i)\r\n for i in range(self.r-1, r-1, -1):\r\n self._delete(i)\r\n for i in range(self.l, l):\r\n self._delete(i)\r\n for i in range(self.l-1, l-1, -1):\r\n self._add(i)\r\n\r\n self.l = l\r\n self.r = r\r\n\r\n def process(self, queries):\r\n self._init_states()\r\n\r\n for i, (l, r) in enumerate(queries):\r\n # [l, r)\r\n self.bucket[l//self.b].append((l, r, i))\r\n\r\n for i in range(len(self.bucket)):\r\n self.bucket[i].sort(key=itemgetter(1))\r\n\r\n res = [-1]*len(queries)\r\n for bs in self.bucket:\r\n for l, r, i in bs:\r\n self._one_process(l, r)\r\n res[i] = self.ans\r\n return res\r\n\r\nimport sys\r\nimport io, os\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n\r\ndef main():\r\n\r\n n, q = map(int, input().split())\r\n A = list(map(int, input().split()))\r\n\r\n Q = []\r\n for i in range(q):\r\n l, r = map(int, input().split())\r\n l, r = l-1, r-1\r\n Q.append((l, r+1))\r\n\r\n mo = Mo(A)\r\n ans = mo.process(Q)\r\n print(*ans, sep='\\n')\r\n\r\nif __name__ == '__main__':\r\n main()\r\n" ]
{"inputs": ["3 2\n1 2 1\n1 2\n1 3", "8 3\n1 1 2 2 1 3 1 1\n2 7\n1 6\n2 7", "20 8\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2\n4 15\n1 2\n2 20\n7 7\n13 18\n7 7\n3 19\n3 8", "10 5\n10 9 8 7 6 5 4 3 2 1\n4 8\n1 10\n3 9\n2 2\n5 10", "8 10\n100 100 100 100 100 100 100 100\n1 8\n2 8\n3 8\n4 8\n5 8\n6 8\n7 8\n8 8\n1 1\n1 5", "1 2\n1\n1 1\n1 1", "1 1\n1000000\n1 1", "5 15\n103 45 103 67 45\n1 1\n1 2\n1 3\n1 4\n1 5\n2 2\n2 3\n2 4\n2 5\n3 3\n3 4\n3 5\n4 4\n4 5\n5 5", "8 10\n5 7 3 1 4 2 1 1\n5 7\n3 8\n2 7\n4 8\n4 5\n2 8\n4 6\n1 2\n4 7\n3 5", "9 10\n5 3 10 2 4 8 7 5 1\n6 9\n1 8\n3 3\n2 7\n3 5\n4 6\n9 9\n8 8\n1 9\n5 6", "9 10\n10 2 6 2 4 6 6 4 1\n4 8\n8 9\n2 3\n8 9\n9 9\n4 5\n1 7\n6 6\n6 8\n1 1", "10 10\n5 10 9 2 9 3 5 5 6 5\n5 10\n2 2\n3 10\n4 8\n1 3\n1 5\n5 5\n10 10\n8 9\n6 10", "9 10\n6 2 3 1 4 8 5 9 8\n3 9\n6 6\n9 9\n9 9\n9 9\n2 3\n3 9\n3 8\n6 9\n5 6"], "outputs": ["3\n6", "20\n20\n20", "108\n3\n281\n1\n27\n1\n209\n27", "25\n55\n35\n9\n21", "6400\n4900\n3600\n2500\n1600\n900\n400\n100\n100\n2500", "1\n1", "1000000", "103\n148\n457\n524\n659\n45\n148\n215\n350\n103\n170\n215\n67\n112\n45", "7\n18\n20\n15\n5\n25\n7\n12\n10\n8", "21\n54\n10\n34\n16\n14\n1\n5\n55\n12", "42\n5\n8\n5\n1\n6\n76\n6\n28\n10", "63\n10\n92\n34\n24\n53\n9\n5\n11\n54", "54\n8\n8\n8\n8\n5\n54\n30\n46\n12"]}
UNKNOWN
PYTHON3
CODEFORCES
1
19d2ecccfa97f05d68273ed6f8fa0fd3
Permutations
You are given *n* *k*-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers. The first line contains integers *n* and *k* — the number and digit capacity of numbers correspondingly (1<=≤<=*n*,<=*k*<=≤<=8). Next *n* lines contain *k*-digit positive integers. Leading zeroes are allowed both in the initial integers and the integers resulting from the rearranging of digits. Print a single number: the minimally possible difference between the largest and the smallest number after the digits are rearranged in all integers by the same rule. Sample Input 6 4 5237 2753 7523 5723 5327 2537 3 3 010 909 012 7 5 50808 36603 37198 44911 29994 42543 50156 Sample Output 2700 3 20522
[ "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nimport math\r\nfrom heapq import heappush , heappop\r\nfrom collections import defaultdict,deque,Counter\r\nfrom bisect import *\r\nimport itertools\r\n\r\nMOD = 10**9+7\r\nN,K = map(int, input().split())\r\nS = []\r\nfor _ in range(N):\r\n S.append(input())\r\n \r\ndef deal(p):\r\n A = [[] for _ in range(N)]\r\n for i in p:\r\n for j in range(N):\r\n A[j].append(S[j][i])\r\n B = []\r\n for a in A:\r\n B.append(int(''.join(a)))\r\n B.sort()\r\n return B[-1]-B[0]\r\n\r\nA = [i for i in range(K)]\r\nans = float('inf')\r\nfor p in itertools.permutations(A,K):\r\n ans = min(ans, deal(p))\r\nprint(ans)\r\n\r\n", "'''\n https://codeforces.com/problemset/problem/124/B\n'''\nn, k = map(int, input().split())\nmatrix = [input() for x in range(n)]\nmin_diff = 9999999999\nimport itertools\npermuts = itertools.permutations([x for x in range(k)])\nfor possible in permuts:\n temp = ['' for x in range(n)]\n for c in possible:\n for r in range(n):\n temp[r] = temp[r] + matrix[r][c]\n for r in range(n):\n temp[r] = int(temp[r])\n min_diff = min(min_diff, max(temp)-min(temp))\nprint(min_diff)\n", "from itertools import permutations\r\nn,k=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n\tl.append(input())\r\nperm=[]\r\nfor i in range(n):\r\n\tperm.append(list(permutations(l[i])))\r\nf=0\r\nfor i in range(len(perm[0])):\r\n\ttemp=[]\r\n\tfor j in range(n):\r\n\t\ttemp.append(int(''.join(perm[j][i])))\r\n\tdiff=max(temp)-min(temp)\r\n\tif f==0:\t\t\r\n\t\tans=diff\r\n\t\tf=1\r\n\telif diff<ans:\r\n\t\tans=diff\r\nprint(ans)", "import math\r\nimport sys\r\nimport heapq\r\nfrom queue import PriorityQueue\r\nfrom collections import deque\r\ndef perm(a,n):\r\n if n==0:\r\n for elem in b:\r\n c[j[0]].append(elem)\r\n j[0]+=1\r\n return 0\r\n else:\r\n for i in range(n):\r\n b.append(a[i])\r\n perm(a[:i]+a[i+1:],n-1)\r\n b.pop()\r\n return 0\r\ndef swap(x,a):\r\n p = list(x)\r\n x = list(x)\r\n for ii in range(k):\r\n p[ii]=x[a[ii]-1]\r\n f = \"\"\r\n for iii in range(k):\r\n f+=p[iii]\r\n return int(f)\r\nn, k = map(int, input().split())\r\nl = 1\r\nfor xx in range(1,k+1):\r\n l*=xx\r\nc = [[] for i in range(l)]\r\nb = []\r\nj = [0]\r\na = [i for i in range(1,k+1)]\r\nperm(a,k)\r\nfor yy in range(n):\r\n b.append(input())\r\nq = 10**8+1\r\nt = 10**8+1\r\nfor elem in c:\r\n l = 0\r\n r = t\r\n for elems in b:\r\n w = swap(elems,elem)\r\n l = max(l,w)\r\n r = min(r,w)\r\n q = min(q,l-r)\r\nprint(q)", "from itertools import permutations\r\n\r\ndef ap(t, p):\r\n return [t[q] for q in p]\r\n\r\nn, k = map(int, input().split())\r\ns = [input() for i in range(n)]\r\nans = 10 ** 100\r\nfor p in permutations(range(k)):\r\n u = [int(''.join(ap(t, p))) for t in s]\r\n ans = min(ans, max(u) - min(u))\r\nprint(ans)\r\n", "from itertools import permutations\nn,k=map(int,input().split())\nl=[]\nfor i in range(n):\n l.append(input())\nperm=[]\nfor i in range(n):\n perm.append(list(permutations(l[i])))\nf=0\nfor i in range(len(perm[0])):\n temp=[]\n for j in range(n):\n temp.append(int(''.join(perm[j][i])))\n diff=max(temp)-min(temp)\n if f==0:\t\t\n ans=diff\n f=1\n elif diff<ans:\n ans=diff\nprint(ans)", "from itertools import permutations\nn, k = list(map(int, input().split(\" \")))\nmypermutation = []\nminumnum = float(\"inf\") # set it to a very large value\nfor i in range(n):\n mypermutation.append(list(permutations(input())))\n# print(mypermutation)\nfor arr in zip(*mypermutation):\n ints = [int(''.join(num)) for num in arr]\n minumnum = min(minumnum, max(ints)-min(ints))\nprint(minumnum)\n\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\nfrom itertools import permutations\r\n\r\nn, k = map(int, input().split())\r\ng = [input()[:-1] for _ in range(n)]\r\n\r\nd = [list(map(lambda x:int(''.join(x)), permutations(i, k))) for i in g]\r\nx = len(d[0])\r\n\r\ne = 10000000000\r\nfor i in zip(*d):\r\n e = min(e, max(i)-min(i))\r\n\r\nprint(e)", "import itertools \r\n \r\nn, k = [int(x) for x in input().split()]\r\n \r\nperms = zip(*[[int(''.join(p)) for p in itertools.permutations(input())] for y in range(n)])\r\n \r\nperms = list(perms)\r\n \r\nminimum = float(\"inf\")\r\n \r\nfor p in perms:\r\n \r\n\ttemp = max(p) - min(p)\r\n \r\n\tif temp < minimum:\r\n\t\tminimum = temp\r\n \r\nprint(minimum)", "from itertools import permutations\r\nn,k = map(int,input().split())\r\nb = []\r\nfor i in range(1,k+1):\r\n b.append(i)\r\na = [i for i in permutations(b)]\r\nlst = []\r\nans = float('inf')\r\nfor i in range(n):\r\n lst.append(input())\r\ndef per(perm,lst):\r\n global n,k,ans\r\n for i in perm:\r\n mn = float('inf')\r\n mx = 0\r\n for nm in lst:\r\n s = ''\r\n for b in i:\r\n s+=nm[b-1]\r\n s = int(s)\r\n mn = min(mn,s)\r\n mx = max(mx,s)\r\n ans = min(ans,mx-mn)\r\n return ans\r\nprint(per(a,lst))", "from itertools import permutations\nn,k=map(int,input().split())\nl=[]\nfor i in range(n):\n l.append(input())\nperm=[]\nfor i in range(n):\n perm.append(list(permutations(l[i])))\nans=10000000000\nfor i in range(len(perm[0])):\n temp=[]\n for j in range(n):\n temp.append(int(''.join(perm[j][i])))\n diff=max(temp)-min(temp)\n if diff<ans:\n ans=diff\nprint(ans)", "from sys import stdin, stdout\ninput = stdin.readline\ndef print(*args, end='\\n', sep=' ') -> None:\n\tstdout.write(sep.join(map(str, args)) + end)\ndef int_map():\n\treturn map(int, input().split())\ndef list_int():\n\treturn list(map(int, input().split()))\n\nfrom itertools import permutations\nn, k = int_map()\narr = []\nfor i in range(n):\n\tarr.append(input().strip())\nperms = list(permutations([i for i in range(k)]))\ndifmin = 10 ** 9\nfor i in perms:\n\tmx = 0\n\tmn = 10 ** 9\n\tfor j in arr:\n\t\ttemp = \"\"\n\t\tfor k in i:\n\t\t\ttemp += j[int(k)]\n\t\tmx = max(mx, int(temp))\n\t\tmn = min(mn, int(temp))\n\tdifmin = min(difmin, mx - mn)\n\n\nprint(difmin)\n\n\n\n\n\n\n", "import itertools\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\nn, k = map(int, input().split())\r\np = [i for i in range(k)]\r\ns = [list(input().rstrip()) for _ in range(n)]\r\ninf = pow(10, 9) + 1\r\nans = inf\r\nfor p0 in itertools.permutations(p):\r\n mi, ma = inf, -inf\r\n for s0 in s:\r\n x = []\r\n for i in p0:\r\n x.append(s0[i])\r\n y = int(\"\".join(x))\r\n mi = min(mi, y)\r\n ma = max(ma, y)\r\n ans = min(ans, ma - mi)\r\nprint(ans)", "from itertools import permutations\r\n\r\nn, k = map(int, input().split())\r\nans = 100000000\r\nl = [input() for _ in range(n)]\r\np = []\r\nfor i in range(n):\r\n s = ''\r\n p.append([int(s.join(k)) for k in permutations(l[i])])\r\nfor i in range(len(p[0])):\r\n maxn = 0\r\n minn = 100000000\r\n for j in range(len(p)):\r\n if p[j][i] > maxn:\r\n maxn = p[j][i]\r\n if p[j][i] < minn:\r\n minn = p[j][i]\r\n if ans > maxn - minn:\r\n ans = maxn - minn\r\nprint(ans)", "from itertools import permutations\r\n\r\nn, k = list(map(int, input().split()))\r\nnums = []\r\nfor _ in range(n):\r\n nums.append(input())\r\n\r\nindices = [i for i in range(k)]\r\nrules = list(permutations(indices))\r\n\r\nminDif = max(list(map(int, nums))) - min(list(map(int, nums)))\r\nfor rule in rules:\r\n result = []\r\n for num in nums:\r\n result.append(\"\")\r\n for index in range(k):\r\n result[-1] += num[rule[index]]\r\n result[-1] = int(result[-1])\r\n dif = max(result) - min(result)\r\n if dif < minDif:\r\n minDif = dif\r\nprint(minDif)\r\n", "n, k = list(map(int,input().split()))\r\ngo = [i for i in range(k)]\r\nmass = []\r\nfor i in range(n):\r\n mass.append(input())\r\nfact = 1\r\nfor i in range(1, k + 1):\r\n fact *= i\r\nraz = 100000000000000\r\nfor i in range(fact):\r\n mini = 1000000000\r\n maxi = 0\r\n if i == 0:\r\n for j in range(n):\r\n now = ''\r\n for l in go:\r\n now += mass[j][l]\r\n now = int(now)\r\n if now < mini:\r\n mini = now\r\n if now > maxi:\r\n maxi = now\r\n else:\r\n for j in range(k - 2, -1, -1):\r\n if go[j] < go[j + 1]:\r\n last = go[j + 1:]\r\n last.sort()\r\n x = 0\r\n for l in last:\r\n if l > go[j]:\r\n x = l\r\n break\r\n last.remove(x)\r\n last.append(go[j])\r\n go[j] = x\r\n last.sort()\r\n go = go[:j + 1] + last\r\n break\r\n for j in range(n):\r\n now = ''\r\n for l in go:\r\n now += mass[j][l]\r\n now = int(now)\r\n if now < mini:\r\n mini = now\r\n if now > maxi:\r\n maxi = now\r\n raz = min(raz, maxi - mini)\r\nprint(raz)" ]
{"inputs": ["6 4\n5237\n2753\n7523\n5723\n5327\n2537", "3 3\n010\n909\n012", "7 5\n50808\n36603\n37198\n44911\n29994\n42543\n50156", "5 5\n61374\n74304\n41924\n46010\n09118", "8 8\n68785928\n11981277\n32480720\n72495162\n69969623\n42118868\n64235849\n81412116", "7 1\n1\n0\n8\n5\n4\n9\n8", "3 8\n34848224\n16307102\n25181102", "2 8\n13633861\n68468345", "4 4\n0950\n0634\n9264\n8684", "6 5\n65777\n80932\n32260\n49089\n00936\n85557", "5 6\n687443\n279213\n765651\n611680\n500192", "8 6\n034753\n917195\n222679\n778596\n980006\n467267\n482763\n807481", "8 6\n075967\n240855\n352399\n791547\n103244\n982259\n409866\n926586", "3 1\n7\n2\n9", "6 4\n5407\n4617\n3050\n7647\n8647\n1993", "8 5\n47553\n55138\n81768\n78902\n50691\n73010\n93969\n01675", "8 7\n5945843\n9094433\n0750024\n6255984\n1784849\n7275947\n6513944\n0145523", "8 7\n8112819\n8982110\n5457941\n4575033\n5203331\n7410823\n0532182\n8151054", "8 8\n63315032\n20587190\n05461152\n76872565\n71177578\n53541174\n00451913\n85740357", "2 3\n135\n725", "7 1\n9\n5\n8\n9\n7\n6\n9", "5 3\n560\n978\n543\n846\n714", "7 2\n53\n74\n84\n62\n14\n77\n59", "3 4\n0537\n2174\n5299", "7 5\n13532\n16394\n97663\n73133\n22712\n58185\n65035", "8 5\n07936\n07927\n46068\n99158\n90958\n41283\n59266\n87841", "8 6\n867468\n695388\n700723\n444270\n545657\n178053\n315040\n554471", "7 7\n6575460\n6965366\n1912357\n7080608\n2561692\n5209630\n0439095", "1 2\n96", "1 3\n289", "1 8\n78795220", "8 7\n2407792\n7023368\n2609925\n0587109\n3543873\n6602371\n4579875\n9893509", "4 6\n065169\n150326\n924608\n490012", "4 4\n8851\n6190\n0521\n1659", "4 4\n4381\n3147\n7017\n5593", "8 4\n0344\n9196\n1379\n5470\n0989\n8316\n7096\n7918", "1 6\n430254", "8 1\n4\n0\n8\n5\n9\n0\n4\n7", "5 2\n60\n08\n77\n66\n03", "3 1\n9\n8\n2", "7 2\n89\n00\n59\n90\n99\n22\n55", "2 4\n7694\n6577", "8 8\n68785928\n11981277\n32480720\n72495162\n69969623\n42118868\n64235849\n81412116", "2 7\n9183508\n9276377", "5 4\n7411\n3080\n9578\n5902\n3225", "3 4\n0136\n4556\n4268", "6 8\n99358096\n38390629\n71597322\n35940809\n48949759\n66204248", "7 2\n23\n11\n88\n25\n22\n45\n10", "2 3\n834\n630", "4 2\n87\n03\n95\n23", "2 8\n10715643\n97664296", "6 1\n9\n3\n1\n3\n4\n5", "8 5\n47553\n55138\n81768\n78902\n50691\n73010\n93969\n01675", "4 4\n7603\n0859\n5241\n7680", "1 7\n4605461", "3 4\n3061\n3404\n6670", "8 4\n1847\n0962\n3216\n0772\n6399\n3082\n7997\n0625", "2 6\n834527\n764560", "5 6\n959808\n303464\n414335\n758650\n828038", "4 1\n0\n7\n5\n1", "6 7\n4565736\n9842969\n1412800\n6411011\n5744909\n3791659", "4 1\n0\n7\n5\n1", "1 3\n250", "2 1\n2\n0", "8 8\n96805230\n73119021\n06552907\n86283347\n88650846\n19155689\n37032451\n19310120", "3 2\n64\n94\n65", "8 4\n8008\n4983\n0295\n0353\n5838\n1960\n0270\n7144", "4 8\n22025344\n54085308\n77633421\n59238322", "5 3\n504\n878\n599\n683\n083", "5 4\n7663\n4755\n2941\n4588\n0232", "6 2\n97\n57\n40\n99\n22\n94", "6 7\n4104025\n1370353\n3472874\n5258456\n5595923\n0279404", "8 2\n42\n86\n25\n30\n27\n64\n67\n38", "5 2\n52\n22\n05\n37\n74", "2 2\n63\n50", "6 7\n4104025\n1370353\n3472874\n5258456\n5595923\n0279404", "6 2\n95\n56\n06\n46\n77\n51", "3 5\n97424\n96460\n47766", "2 3\n596\n246", "3 1\n1\n2\n2", "4 2\n87\n03\n95\n23", "7 5\n41078\n41257\n35324\n70082\n66783\n99954\n85784", "8 7\n8943041\n2427704\n3775080\n2956111\n1345704\n0937172\n1979973\n7081540", "6 6\n505845\n903151\n055779\n733849\n508266\n029177", "4 4\n1871\n9417\n7444\n4294", "2 5\n60106\n07866", "3 3\n195\n860\n567", "8 5\n68186\n57779\n78079\n47451\n69788\n82172\n75373\n50157", "4 7\n5342341\n5194611\n4032103\n8739798", "4 8\n91401735\n53979237\n20857777\n94594293", "1 2\n95", "6 4\n0443\n7108\n7211\n4287\n6439\n7711", "6 7\n5794383\n4078451\n0263676\n7682294\n7436158\n3363189", "2 5\n07259\n51985", "3 3\n624\n125\n097", "8 1\n9\n7\n6\n2\n9\n6\n4\n8", "6 3\n530\n862\n874\n932\n972\n157", "3 2\n51\n39\n97", "8 4\n4650\n1735\n4269\n8023\n0948\n9685\n3675\n6017", "5 3\n168\n513\n110\n386\n501", "6 2\n01\n81\n60\n27\n23\n67", "4 4\n2759\n7250\n3572\n8067", "8 5\n12658\n00588\n23491\n09985\n63973\n78517\n98187\n29863", "3 1\n5\n4\n2", "7 8\n24925537\n07626274\n77060131\n82415056\n70422753\n60455207\n32176884", "5 8\n94157433\n85577189\n62547277\n11815893\n35445851", "5 5\n31164\n27213\n17981\n48806\n01273", "3 6\n743197\n172242\n635654", "4 6\n760130\n653002\n902824\n380915", "8 8\n83239439\n62184887\n58968944\n39808261\n68740623\n38480328\n81965504\n52600488", "8 2\n99\n20\n22\n39\n33\n60\n54\n08", "1 7\n3545113", "6 7\n3761949\n8095136\n4875085\n5017784\n4459097\n4354762", "6 8\n50157346\n63836375\n03176371\n83637145\n28631038\n18617159", "1 5\n84932", "4 3\n204\n515\n280\n840", "8 2\n40\n41\n02\n55\n26\n52\n60\n25", "2 5\n90526\n32565", "4 4\n3058\n2370\n0288\n5983", "6 7\n9085507\n7716507\n1952887\n6569746\n1900754\n9212439", "5 2\n01\n07\n63\n71\n99", "6 4\n4505\n3672\n4248\n2783\n9780\n6579", "2 3\n281\n498", "8 5\n16966\n36762\n49579\n71703\n66646\n41125\n94022\n26623", "1 6\n170086", "4 1\n4\n2\n2\n2", "3 8\n12418144\n74773130\n10504811", "6 7\n3761949\n8095136\n4875085\n5017784\n4459097\n4354762"], "outputs": ["2700", "3", "20522", "64592", "52901157", "9", "8612277", "14445725", "3738", "41439", "258067", "647026", "491255", "7", "6474", "71123", "5152379", "6194602", "60622457", "4", "4", "435", "69", "3583", "26455", "52364", "559559", "5917123", "0", "0", "0", "6790457", "488134", "6596", "3690", "7801", "0", "9", "74", "7", "99", "712", "52901157", "26912", "6498", "2134", "53570178", "78", "24", "48", "1244714", "8", "71123", "5518", "0", "2916", "7246", "577", "486245", "7", "4066781", "7", "0", "2", "53604668", "10", "7475", "7681556", "615", "5346", "77", "2790148", "61", "51", "13", "2790148", "62", "9536", "35", "1", "48", "56901", "3544246", "249045", "5368", "5224", "258", "32237", "4056779", "34567247", "0", "5301", "3560125", "23657", "247", "7", "442", "58", "6836", "403", "70", "2028", "68592", "3", "54680138", "15679126", "33367", "261245", "268111", "44481119", "91", "0", "4126934", "24702445", "0", "467", "58", "586", "2972", "3180457", "89", "4484", "127", "66868", "0", "2", "22901234", "4126934"]}
UNKNOWN
PYTHON3
CODEFORCES
16