problem_id
int64 0
4.72k
| problem_content
stringlengths 152
5.64k
| code_prompt
stringclasses 1
value | difficulty
stringclasses 3
values | solutions
stringlengths 98
1.12M
| test_cases
stringlengths 70
1.03M
|
---|---|---|---|---|---|
121 | Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
-----Input-----
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
-----Output-----
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
-----Examples-----
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
-----Note-----
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn. | interview | [{"code": "def chk(l):\n\tfor i in range(4):\n\t\tfor j in range(2):\n\t\t\tif l[i][j]==l[i][j+1]==l[i][j+2]=='x':\n\t\t\t\treturn True\n\tfor i in range(2):\n\t\tfor j in range(4):\n\t\t\tif l[i][j]==l[i+1][j]==l[i+2][j]=='x':\n\t\t\t\treturn True\n\tfor i in range(2):\n\t\tfor j in range(2):\n\t\t\tif l[i][j]==l[i+1][j+1]==l[i+2][j+2]=='x':\n\t\t\t\treturn True\n\tfor i in range(2):\n\t\tfor j in range(2, 4):\n\t\t\tif l[i][j]==l[i+1][j-1]==l[i+2][j-2]=='x':\n\t\t\t\treturn True\n\treturn False\na = [list(input()), list(input()), list(input()), list(input())]\nfor i in range(4):\n\tfor j in range(4):\n\t\tif a[i][j] != '.':\n\t\t\tcontinue\n\t\ta[i][j]='x'\n\t\tif chk(a):\n\t\t\tprint(\"YES\"); return\n\t\ta[i][j]='.'\nprint(\"NO\")\n", "passed": true, "time": 0.85, "memory": 14708.0, "status": "done"}, {"code": "import sys\n\nm = [list(input()) for _ in range(4)]\n\ndef trans(m):\n return [[m[0][0], m[1][0], m[2][0], m[3][0]],\n [m[0][1], m[1][1], m[2][1], m[3][1]],\n [m[0][2], m[1][2], m[2][2], m[3][2]],\n [m[0][3], m[1][3], m[2][3], m[3][3]]]\n\ndef check(m):\n res = any('xxx' in ''.join(x) for x in m)\n res |= any('xxx' in ''.join(x) for x in trans(m))\n\n for i in range(1, 3):\n for j in range(1, 3):\n res |= m[i-1][j-1] + m[i][j] + m[i+1][j+1] == 'xxx'\n res |= m[i-1][j+1] + m[i][j] + m[i+1][j-1] == 'xxx'\n\n return res\n\nfor i in range(4):\n for j in range(4):\n if m[i][j] == '.':\n m[i][j] = 'x'\n if check(m):\n print(\"YES\")\n return\n m[i][j] = '.'\n\nprint(\"NO\")\n", "passed": true, "time": 0.33, "memory": 14400.0, "status": "done"}, {"code": "a = []\nfor i in range(4):\n\ta += [input()]\nf = False\nfor i in range(4):\n\tfor j in range(2):\n\t\tf |= a[i][j: j + 3].count('.') == 1 and a[i][j: j + 3].count('o') == 0\nfor j in range(4):\n\tfor i in range(2):\n\t\tf |= ([a[i][j]] + [a[i + 1][j]] + [a[i + 2][j]]).count('.') == 1 and ([a[i][j]] + [a[i + 1][j]] + [a[i + 2][j]]).count('o') == 0\nfor i in range(2):\n\tfor j in range(2):\n\t\tf |= [a[i][j], a[i + 1][j + 1], a[i + 2][j + 2]].count('.') == 1 and [a[i][j], a[i + 1][j + 1], a[i + 2][j + 2]].count('o') == 0\n\t\tf |= [a[3 - i][j], a[2 - i][j + 1], a[1 - i][j + 2]].count('.') == 1 and [a[3 - i][j], a[2 - i][j + 1], a[1 - i][j + 2]].count('o') == 0\nif f:\n\tprint('YES')\nelse:\n\tprint('NO')", "passed": true, "time": 0.15, "memory": 14608.0, "status": "done"}, {"code": "def tri(ar):\n d={'.':0,'x':0,'o':0}\n for i,j in ar:\n d[a[i][j]]+=1\n if d['.']==1 and d['x']==2:\n ans[0]='YES'\n #print(d)\n \nans=['NO']\na=[input() for i in range(4)]\nfor i in range(2):\n for j in range(2):\n tri([(i,j),(i+1,j+1),(i+2,j+2)])\n for j in range(2,4):\n tri([(i,j),(i+1,j-1),(i+2,j-2)])\nfor i in range(4):\n for j in range(2):\n tri([(i,j),(i,j+1),(i,j+2)])\n tri([(j,i),(j+1,i),(j+2,i)])\nprint(ans[0])\n", "passed": true, "time": 0.33, "memory": 14496.0, "status": "done"}, {"code": "\nA = []\nfor _ in range(4):\n A += [list(input())]\n\nfound = False\n\ndef check(list_of_sigs):\n return list_of_sigs.count('.') == 1 and \\\n list_of_sigs.count('x') == 2\n\nfor col_offset in range(2):\n for row_offset in range(2):\n found = found or check([A[row_offset][col_offset],\n A[row_offset + 1][col_offset + 1],\n A[row_offset + 2][col_offset + 2]])\n found = found or check([A[row_offset][3 - col_offset],\n A[row_offset + 1][2 - col_offset],\n A[row_offset + 2][1 - col_offset]])\n\nfor col in range(2):\n for row in range(4):\n found = found or check([A[row][col],\n A[row][col + 1],\n A[row][col + 2]])\n\nfor col in range(4):\n for row in range(2):\n found = found or check([A[row][col],\n A[row + 1][col],\n A[row + 2][col]])\n\nif found:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n\n", "passed": true, "time": 0.15, "memory": 14580.0, "status": "done"}, {"code": "n = 4\ndef check(f):\n\tnonlocal n\n\tfor i in range(n):\n\t\tok = True\n\t\tfor j in range(n - 1):\n\t\t\tok &= f[i][j] == 'x'\n\t\tif ok : return ok\n\t\tok = True\n\t\tfor j in range(1, n):\n\t\t\tok &= f[i][j] == 'x'\n\t\tif ok : return ok\n\tfor i in range(n):\n\t\tok = True\n\t\tfor j in range(n - 1):\n\t\t\tok &= f[j][i] == 'x'\n\t\tif ok : return ok\n\t\tok = True\n\t\tfor j in range(1, n):\n\t\t\tok &= f[j][i] == 'x'\n\t\tif ok : return ok\n\tok = True\n\tfor i in range(n -1 ):\n\t\tok &= f[i][i] == 'x'\n\tif ok: return ok\n\tok = True\n\tfor i in range(1, n):\n\t\tok &= f[i][i] == 'x'\n\tif ok: return ok\n\tif f[1][0] == f[2][1] == f[3][2] == 'x' or f[0][1] == f[1][2] == f[2][3] == 'x': return True\n\treturn f[3][0] == f[2][1] == f[1][2] == 'x' or f[0][3] == f[2][1] == f[1][2] == 'x' or f[2][0] == f[1][1] == f[0][2] == 'x' or f[1][3] == f[2][2] == f[3][1] == 'x'\nf = [list(input()) for i in range(n)]\nfor i in range(n):\n\tfor j in range(n):\n\t\tif f[i][j] == '.':\n\t\t\tf[i][j] = 'x'\n\t\t\tif check(f):\n\t\t\t\tprint(\"YES\")\n\t\t\t\treturn\n\t\t\tf[i][j] = '.'\nprint(\"NO\")", "passed": true, "time": 0.85, "memory": 14568.0, "status": "done"}, {"code": "\ndef c(i, j):\n if i < 4 and j < 4 and i >= 0 and j >= 0:\n if a[i][j] == 'x':\n return True\n return False\n\na = [[x for x in input().strip()] for j in range(4)]\nans = True\nfor i in range(4):\n for j in range(4):\n if a[i][j] == '.':\n if c(i+1,j) and c(i+2,j):\n ans = False\n if c(i-1,j) and c(i-2,j):\n ans = False\n if c(i+1,j+1) and c(i+2,j+2):\n ans = False\n if c(i-1,j-1) and c(i-2,j-2):\n ans = False\n if c(i,j+1) and c(i,j+2):\n ans = False\n if c(i,j-1) and c(i,j-2):\n ans = False\n if c(i+1,j-1) and c(i+2,j-2):\n ans = False\n if c(i-1,j+1) and c(i-2,j+2):\n ans = False\n\n if c(i-1,j-1) and c(i+1,j+1):\n ans = False\n if c(i-1,j) and c(i+1,j):\n ans = False\n if c(i-1,j+1) and c(i+1,j-1):\n ans = False\n if c(i,j-1) and c(i,j+1):\n ans = False\n\nif ans:\n print('NO')\nelse:\n print('YES')", "passed": true, "time": 0.21, "memory": 14484.0, "status": "done"}, {"code": "def get_field(i, j, val):\n if i < 0 or j < 0 or i > 3 or j > 3:\n return False\n return d[i][j] == val\n\n\ndef check_field(i, j, c):\n if get_field(i - 2, j, c) and get_field(i - 1, j, c):\n return True\n if get_field(i + 2, j, c) and get_field(i + 1, j, c):\n return True\n if get_field(i, j - 2, c) and get_field(i, j - 1, c):\n return True \n if get_field(i, j + 2, c) and get_field(i, j + 1, c):\n return True\n if get_field(i - 1, j, c) and get_field(i + 1, j, c):\n return True\n if get_field(i, j - 1, c) and get_field(i, j + 1, c):\n return True\n \n if get_field(i + 2, j + 2, c) and get_field(i + 1, j + 1, c):\n return True \n if get_field(i - 2, j - 2, c) and get_field(i - 1, j - 1, c):\n return True\n if get_field(i + 2, j - 2, c) and get_field(i + 1, j - 1, c):\n return True \n if get_field(i - 2, j + 2, c) and get_field(i - 1, j + 1, c):\n return True \n if get_field(i + 1, j + 1, c) and get_field(i - 1, j - 1, c):\n return True \n if get_field(i - 1, j + 1, c) and get_field(i + 1, j - 1, c):\n return True\n\nd = [[''] * 4 for i in range(4)]\nfor i in range(4):\n s = input()\n for j in range(4):\n d[i][j] = s[j]\nfor i in range(4):\n for j in range(4):\n if d[i][j] == '.':\n if check_field(i, j, 'x'):\n print(\"YES\")\n return\nprint(\"NO\")", "passed": true, "time": 0.2, "memory": 14512.0, "status": "done"}, {"code": "def vaild(i,j):\n per = 1\n per1 = 1\n per2 = 1\n per3 = 1\n for t in range(i-1,-1,-1):\n if A[t][j] == 'x':\n per +=1\n else:\n break\n for t in range(i+1,4):\n if A[t][j] == 'x':\n per+=1\n else:\n break\n if per >= 3:\n return True\n for t in range(j-1,-1,-1):\n if A[i][t] == 'x':\n per1+=1\n else:\n break\n for t in range(j+1,4):\n if A[i][t] == 'x':\n per1+=1\n else:\n break\n if per1 >=3:\n return True\n i1 = i-1\n j1 = j-1\n i2 = i+1\n j2 = j+1\n while (i1>= 0 and j1>=0):\n if A[i1][j1] == 'x':\n i1 -= 1\n j1-=1\n per2+=1\n else:\n break\n while (i2<= 3 and j2<=3):\n if A[i2][j2] == 'x':\n per2+=1\n i2+=1\n j2+=1\n else:\n break \n if per2>=3:\n return True\n i3 = i-1\n j3 = j+1\n while (i3>= 0 and j3<=3):\n if A[i3][j3] == 'x':\n i3 -= 1\n j3+=1\n per3+=1\n else:\n break\n i4 = i+1\n j4 = j -1\n while (i4<=3 and j4>=0):\n if A[i4][j4] == 'x':\n i4 +=1\n j4 -= 1\n per3+=1\n else:\n break\n if per3 >= 3:\n return True\n return False\nA = [0] * 4\nfor j in range(4):\n A[j] = input()\ns = 0\nfor i in range(4):\n for j in range(4):\n if A[i][j] == '.':\n \n if vaild(i,j):\n s = 1\n break\nif s == 1:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.15, "memory": 14556.0, "status": "done"}, {"code": "fields = []\nfields.append([ input() for i in range(4)])\nfields.append([ '' for i in range(4)])\nfor i in range(4):\n c = 0\n for j in fields[0][i]:\n fields[1][c] += j\n c += 1\nline1 = ''\nline2 = ''\nfor i in range(4):\n line1 += fields[0][i][i]\n line2 += fields[0][i][3 - i]\nfields.append([line1, line2])\nfields[2].append(fields[0][1][0]+fields[0][2][1]+fields[0][3][2])\nfields[2].append(fields[0][0][1]+fields[0][1][2]+fields[0][2][3])\nfields[2].append(fields[0][0][2]+fields[0][1][1]+fields[0][2][0])\nfields[2].append(fields[0][1][3]+fields[0][2][2]+fields[0][3][1])\nfor i in fields:\n for j in i:\n if 'x.x' in j or '.xx' in j or 'xx.' in j:\n print('YES')\n return\nprint('NO')", "passed": true, "time": 0.19, "memory": 14688.0, "status": "done"}, {"code": "def check(A):\n for x1 in range(4):\n for y1 in range(4):\n for x2 in range(4):\n for y2 in range(4):\n for x3 in range(4):\n for y3 in range(4):\n if A[x1][y1] == A[x2][y2] == A[x3][y3] == 'x':\n # print('!')\n if x1 == x2 == x3 and y1 == y2 + 1 == y3 + 2:\n return True\n if y1 == y2 == y3 and x1 == x2 + 1 == x3 + 2:\n return True\n if x1 == x2 + 1 == x3 + 2 and y1 == y2 + 1 == y3 + 2:\n return True\n if x1 == x2 + 1 == x3 + 2 and y3 == y2 + 1 == y1 + 2:\n return True\n return False\n\nA = [0] * 4\nfor i in range(4):\n A[i] = list(input())\nfor i in range(4):\n for j in range(4):\n if A[i][j] == '.':\n A[i][j] = 'x'\n # print(A)\n if check(A):\n print('YES')\n return\n A[i][j] = '.'\nprint('NO')\n", "passed": true, "time": 0.83, "memory": 14692.0, "status": "done"}, {"code": "a = [0] * 4\nfor i in range(4):\n a[i] = input()\nt = False\nfor i in range(4):\n q1 = [a[0][i], a[1][i], a[2][i]]\n q2 = [a[1][i], a[2][i], a[3][i]]\n if (q1.count(\"x\") == 2 and q1.count(\".\") == 1) or (q2.count(\"x\") == 2 and q2.count(\".\") == 1):\n t = True \nfor i in range(4):\n q3 = [a[i][0], a[i][1], a[i][2]]\n q4 = [a[i][1], a[i][2], a[i][3]] \n if (q3.count(\"x\") == 2 and q3.count(\".\") == 1) or (q4.count(\"x\") == 2 and q4.count(\".\") == 1):\n t = True \nq1 = [a[0][1], a[1][2], a[2][3]]\nq2 = [a[1][0], a[2][1], a[3][2]]\nq3 = [a[2][0], a[1][1], a[0][2]]\nq4 = [a[3][1], a[2][2], a[1][3]]\nif (q3.count(\"x\") == 2 and q3.count(\".\") == 1) or (q4.count(\"x\") == 2 and q4.count(\".\") == 1):\n t = True \nif (q1.count(\"x\") == 2 and q1.count(\".\") == 1) or (q2.count(\"x\") == 2 and q2.count(\".\") == 1):\n t = True\nq1 = [a[0][0], a[1][1], a[2][2]]\nq2 = [a[1][1], a[2][2], a[3][3]]\nq3 = [a[3][0], a[2][1], a[1][2]]\nq4 = [a[2][1], a[1][2], a[0][3]]\nif (q3.count(\"x\") == 2 and q3.count(\".\") == 1) or (q4.count(\"x\") == 2 and q4.count(\".\") == 1):\n t = True \nif (q1.count(\"x\") == 2 and q1.count(\".\") == 1) or (q2.count(\"x\") == 2 and q2.count(\".\") == 1):\n t = True\nif t:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.2, "memory": 14820.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nb = [list(input().strip()) for _ in range(4)]\n\nr = \"NO\"\n\ndef check(b):\n for i in range(4):\n for j in range(2):\n if b[i][j] == 'x' and b[i][j+1] == 'x' and b[i][j+2] == 'x':\n return True\n\n for i in range(2):\n for j in range(4):\n if b[i][j] == 'x' and b[i+1][j] == 'x' and b[i+2][j] == 'x':\n return True\n\n for i in range(2):\n for j in range(2):\n if b[i][j] == 'x' and b[i+1][j+1] == 'x' and b[i+2][j+2] == 'x':\n return True\n\n for i in range(2):\n for j in range(2, 4):\n if b[i][j] == 'x' and b[i+1][j-1] == 'x' and b[i+2][j-2] == 'x':\n return True\n\n return False\n\nfor i in range(4):\n for j in range(4):\n c = b[i][j]\n if c == '.':\n b[i][j] = 'x'\n if check(b):\n r = \"YES\"\n b[i][j] = '.'\nprint(r)\n", "passed": true, "time": 0.19, "memory": 14484.0, "status": "done"}, {"code": "#!/usr/bin/env pypy3\n# -*- coding: UTF-8 -*-\nimport sys\nimport re\nimport math\nimport itertools\nimport collections\nimport bisect\n#sys.stdin=file('input.txt')\n#sys.stdout=file('output.txt','w')\n#10**9+7\nmod=1000000007\n#mod=1777777777\npi=3.1415926535897932\nIS=float('inf')\nxy=[(1,0),(-1,0),(0,1),(0,-1)]\nbs=[(-1,-1),(-1,1),(1,1),(1,-1)]\ndef niten(a,b): return abs(a-b) if a>=0 and b>=0 else a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))\ndef fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)]\ndef gcd(a,b): return a if b==0 else gcd(b,a%b)\ndef lcm(a,b): return a*b/gcd(a,b)\ndef eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5\ndef choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0\ndef pscl(num,l=[1]):\n for i in range(num):\n l = map(lambda x,y:x+y,[0]+l,l+[0])\n return l\n\nl=[]\nfor i in range(4):\n x=input()\n if 'xx.' in x or '.xx' in x or 'x.x' in x:\n print('YES')\n return\n elif 'ooo' in x:\n print('NO')\n return\n\n l.append(x)\nfor i in range(2):\n for j in range(4):\n tate=l[i][j]+l[i+1][j]+l[i+2][j]\n if 'xx.' in tate or '.xx' in tate or 'x.x' in tate:\n print('YES')\n return\n elif 'ooo' in tate:\n print('NO')\n return\n if j>=2:\n y=l[i][j]+l[i+1][j-1]+l[i+2][j-2]\n if 'xx.' in y or '.xx' in y or 'x.x' in y:\n print('YES')\n return\n elif 'ooo' in y:\n print('NO')\n return\n if j<2:\n y=l[i][j]+l[i+1][j+1]+l[i+2][j+2]\n if 'xx.' in y or '.xx' in y or 'x.x' in y:\n print('YES')\n return\n elif 'ooo' in y:\n print('NO')\n return\nprint('NO')", "passed": true, "time": 0.21, "memory": 14564.0, "status": "done"}, {"code": "s =[[] for i in range(4)]\ns[0] = [i for i in input()]\ns[1] = [i for i in input()]\ns[2] = [i for i in input()]\ns[3] = [i for i in input()]\na = 0\nfor i in range(4):\n for j in range(4):\n if i>1:\n if s[i][j] == '.' and s[i-1][j] == 'x' and s[i-2][j] == 'x':\n print(\"YES\")\n a = 1\n break\n if j>1:\n if s[i][j] == '.' and s[i - 1][j-1] == 'x' and s[i - 2][j-2] == 'x':\n print(\"YES\")\n a = 1\n break\n if j < 2:\n if s[i][j] == '.' and s[i - 1][j+1] == 'x' and s[i - 2][j+2] == 'x':\n print(\"YES\")\n a = 1\n break\n if i < 2:\n if s[i][j] == '.' and s[i+1][j] == 'x' and s[i+2][j] == 'x':\n print(\"YES\")\n a = 1\n break\n if j>1:\n if s[i][j] == '.' and s[i + 1][j-1] == 'x' and s[i + 2][j-2] == 'x':\n print(\"YES\")\n a = 1\n break\n if j < 2:\n if s[i][j] == '.' and s[i + 1][j+1] == 'x' and s[i + 2][j+2] == 'x':\n print(\"YES\")\n a = 1\n break\n if j>1:\n if s[i][j] == '.' and s[i][j - 1] == 'x' and s[i][j - 2] == 'x':\n print(\"YES\")\n a = 1\n break\n if j <2:\n if s[i][j] == '.' and s[i][j + 1] == 'x' and s[i][j + 2] == 'x':\n print(\"YES\")\n a = 1\n break\n if i!= 3 and i !=0:\n if s[i][j] == '.' and s[i+1][j] == 'x' and s[i-1][j] == 'x':\n print(\"YES\")\n a = 1\n break\n if j != 3 and j != 0:\n if s[i][j] == '.' and s[i+1][j + 1] == 'x' and s[i-1][j - 1] == 'x':\n print(\"YES\")\n a = 1\n break\n if s[i][j] == '.' and s[i-1][j + 1] == 'x' and s[i+1][j - 1] == 'x':\n print(\"YES\")\n a = 1\n break\n if j != 3 and j!= 0:\n if s[i][j] == '.' and s[i][j + 1] == 'x' and s[i][j -1] == 'x':\n print(\"YES\")\n a = 1\n break\n if a:\n break\nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14536.0, "status": "done"}, {"code": "def check(a):\n for i in range(4):\n if \"xxx\" in a[i]:\n return True\n if a[1][0] == \"x\" and a[2][0] == \"x\" and (a[0][0] == \"x\" or a[3][0] == \"x\"):\n return True\n if a[1][1] == \"x\" and a[2][1] == \"x\" and (a[0][1] == \"x\" or a[3][1] == \"x\"):\n return True\n if a[1][2] == \"x\" and a[2][2] == \"x\" and (a[0][2] == \"x\" or a[3][2] == \"x\"):\n return True\n if a[1][3] == \"x\" and a[2][3] == \"x\" and (a[0][3] == \"x\" or a[3][3] == \"x\"):\n return True\n if a[0][2] == a[1][1] == a[2][0] == \"x\":\n return True\n if a[1][2] == a[2][1] == \"x\" and (a[3][0] == \"x\" or a[0][3] == \"x\"):\n return True\n if a[3][1] == a[2][2] == a[1][3] == \"x\":\n return True\n if a[0][1] == a[1][2] == a[2][3] == \"x\":\n return True\n if a[1][1] == a[2][2] == \"x\" and (a[0][0] == \"x\" or a[3][3] == \"x\"):\n return True\n if a[1][0] == a[2][1] == a[3][2] == \"x\":\n return True\n return False\n\n\n\na = [input() for i in range(4)]\nflag = False\nfor i in range(4):\n for j in range(4):\n if a[i][j] == \".\":\n b = a[:]\n str = b[i]\n b[i] = str[:j] + \"x\" + str[j + 1:]\n if check(b):\n flag = True\nif flag:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14696.0, "status": "done"}, {"code": "s1 = input()\ns2 = input()\ns3 = input()\ns4 = input()\ns5 = s1[0] + s2[0] + s3[0] + s4[0]\ns6 = s1[1] + s2[1] + s3[1] + s4[1]\ns7 = s1[2] + s2[2] + s3[2] + s4[2]\ns8 = s1[3] + s2[3] + s3[3] + s4[3]\ns9 = s2[0] + s3[1] + s4[2]\ns10 = s1[0] + s2[1] + s3[2] + s4[3]\ns11 = s1[1] + s2[2] + s3[3]\ns12 = s1[2] + s2[1] + s3[0]\ns13 = s1[3] + s2[2] + s3[1] + s4[0]\ns14 = s2[3] + s3[2] + s4[1]\n\n\nf = False\nif 'xx.' in s1 or 'xx.' in s2 or 'xx.' in s3 or 'xx.' in s4 or 'xx.' in s5 or 'xx.' in s6 or 'xx.' in s7 or 'xx.' in s8 or 'xx.' in s9 or 'xx.' in s10 or 'xx.' in s11 or 'xx.' in s12 or 'xx.' in s13 or 'xx.' in s14:\n f = True\nif 'x.x' in s1 or 'x.x' in s2 or 'x.x' in s3 or 'x.x' in s4 or 'x.x' in s5 or 'x.x' in s6 or 'x.x' in s7 or 'x.x' in s8 or 'x.x' in s9 or 'x.x' in s10 or 'x.x' in s11 or 'x.x' in s12 or 'x.x' in s13 or 'x.x' in s14:\n f = True\nif '.xx' in s1 or '.xx' in s2 or '.xx' in s3 or '.xx' in s4 or '.xx' in s5 or '.xx' in s6 or '.xx' in s7 or '.xx' in s8 or '.xx' in s9 or '.xx' in s10 or '.xx' in s11 or '.xx' in s12 or '.xx' in s13 or '.xx' in s14:\n f = True\nif f:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.19, "memory": 14712.0, "status": "done"}, {"code": "\ndef has_win(mat, r, c):\n for i in range(-1, 2):\n for j in range(-1, 2):\n if (i == j and i == 0) or (not 0 <= i + r < 4) or (not 0 <= j + c < 4):\n continue\n if mat[r + i][c + j] in ['x', '.']:\n tm = '.' if mat[r + i][c + j] == 'x' else 'x'\n if 0<= r + 2*i < 4 and 0 <= c + 2*j < 4 and mat[r + 2*i][c + 2*j] == tm:\n return True\n return False\n\ndef is_win(mat):\n for i in range(4):\n for j in range(4):\n if mat[i][j] == 'x' and has_win(mat, i, j):\n return True\n return False\n\ndef nput(n):\n for i in range(n):\n yield input()\n\ndef main():\n mat = [list(l) for l in nput(4)]\n if is_win(mat):\n print(\"YES\")\n else:\n print(\"NO\")\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.25, "memory": 14624.0, "status": "done"}, {"code": "def myc(a,b,c,d,e,f):\n return str(iph[a][b]+iph[c][d]+iph[e][f])\niph=[]\nfor i in range(4):\n iph.append(str(input()))\nipv=[]\nb=0\nfor i in range(4):\n ipv.append(str(iph[0][i]+iph[1][i]+iph[2][i]+iph[3][i]))\nfor i in iph:\n if 'x.x' in i or 'xx.' in i or '.xx' in i:\n b=1\n if 'ooo' in i:\n b=2\n break\nif b!=2:\n for i in ipv:\n if 'x.x' in i or 'xx.' in i or '.xx' in i:\n b=1\n if 'ooo' in i:\n b=2\n break\nif b!=2:\n ipd=[myc(0,0,1,1,2,2),myc(1,1,2,2,3,3),myc(1,0,2,1,3,2),myc(0,1,1,2,2,3),\n myc(0,2,1,1,2,0),myc(0,3,1,2,2,1),myc(1,2,2,1,3,0),myc(1,3,2,2,3,1)]\n for i in ipd:\n if 'x.x' in i or 'xx.' in i or '.xx' in i and b==0:\n b=1\n if 'ooo' in i:\n b=2\n break\n\nif b==0 or b==2:\n print('NO')\nelse:\n print('YES')\n", "passed": true, "time": 0.21, "memory": 14640.0, "status": "done"}, {"code": "import sys\n\nrows = [input() for i in range(4)]\ncols = []\n\nfor j in range(4):\n col = [rows[i][j] for i in range(4)]\n cols.append(\"\".join(col))\n\ndiags = []\ndiags.append(\"\".join([rows[i][i] for i in range(4)]))\ndiags.append(\"\".join([rows[0][1], rows[1][2], rows[2][3]]))\ndiags.append(\"\".join([rows[1][0], rows[2][1], rows[3][2]]))\ndiags.append(\"\".join([rows[i][3-i] for i in range(4)]))\ndiags.append(\"\".join([rows[0][2], rows[1][1], rows[2][0]]))\ndiags.append(\"\".join([rows[1][3], rows[2][2], rows[3][1]]))\n\nstrs = rows + cols + diags\n\nwinstrs = [\"xx.\", \"x.x\", \".xx\"]\n\nfor winstr in winstrs:\n for s in strs:\n if winstr in s:\n print(\"YES\")\n return\nprint(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14660.0, "status": "done"}, {"code": "def check(a):\n for i in range(4):\n if \"xxx\" in a[i]:\n return True\n if a[1][0] == \"x\" and a[2][0] == \"x\" and (a[0][0] == \"x\" or a[3][0] == \"x\"):\n return True\n if a[1][1] == \"x\" and a[2][1] == \"x\" and (a[0][1] == \"x\" or a[3][1] == \"x\"):\n return True\n if a[1][2] == \"x\" and a[2][2] == \"x\" and (a[0][2] == \"x\" or a[3][2] == \"x\"):\n return True\n if a[1][3] == \"x\" and a[2][3] == \"x\" and (a[0][3] == \"x\" or a[3][3] == \"x\"):\n return True\n if a[0][2] == a[1][1] == a[2][0] == \"x\":\n return True\n if a[1][2] == a[2][1] == \"x\" and (a[3][0] == \"x\" or a[0][3] == \"x\"):\n return True\n if a[3][1] == a[2][2] == a[1][3] == \"x\":\n return True\n if a[0][1] == a[1][2] == a[2][3] == \"x\":\n return True\n if a[1][0] == a[2][1] == a[3][2] == \"x\":\n return True\n if a[1][1] == a[2][2] == \"x\" and (a[0][0] == \"x\" or a[3][3] == \"x\"):\n return True\n return False\n\n\n\na, flag = [input() for i in range(4)], False\nfor i in range(4):\n for j in range(4):\n if a[i][j] == \".\":\n b = a[:]\n str = b[i]\n b[i] = str[:j] + \"x\" + str[j + 1:]\n if check(b):\n flag = True\nif flag:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14580.0, "status": "done"}, {"code": "\nl1 = input()\nl2 = input()\nl3 = input()\nl4 = input()\n\ngrid = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]]\n\ncross = 0\ndots = []\nfor i in range(0, 4):\n if l1[i] == \".\":\n dots += [[0+2, i+2]]\n elif l1[i] == \"x\":\n cross += 1\n grid[0+2][i+2] = 1\n\n if l2[i] == \".\":\n dots += [[1+2, i+2]]\n elif l2[i] == \"x\":\n cross += 1\n grid[1+2][i+2] = 1\n\n if l3[i] == \".\":\n dots += [[2+2, i+2]]\n elif l3[i] == \"x\":\n cross += 1\n grid[2+2][i+2] = 1\n\n if l4[i] == \".\":\n dots += [[3+2, i+2]]\n elif l4[i] == \"x\":\n cross += 1\n grid[3+2][i+2] = 1\n\ndef check(dot, dir, delta):\n nonlocal grid\n grid[dot[0]][dot[1]] = 1\n \n acc = 1\n if dir == 0: #horizontal\n for i in range(delta, delta+3):\n acc *= grid[dot[0]+i][dot[1]]\n elif dir == 1: #vertical\n for i in range(delta, delta+3):\n acc *= grid[dot[0]][dot[1]+i]\n elif dir == 2: #diag1\n for i in range(delta, delta+3):\n acc *= grid[dot[0]+i][dot[1]+i]\n elif dir == 3: #diag2\n for i in range(delta, delta+3):\n acc *= grid[dot[0]+i][dot[1]-i]\n\n grid[dot[0]][dot[1]] = 0\n return acc\n\nif cross < 2 or len(dots) == 0:\n print(\"NO\")\nelse:\n for dot in dots:\n for dir in range(0, 4):\n for delta in range(-2, 1):\n if check(dot, dir, delta) == 1:\n print(\"YES\")\n return\nprint(\"NO\")", "passed": true, "time": 0.24, "memory": 14820.0, "status": "done"}] | [{"input": "xx..\n.oo.\nx...\noox.\n", "output": "YES\n"}, {"input": "x.ox\nox..\nx.o.\noo.x\n", "output": "NO\n"}, {"input": "x..x\n..oo\no...\nx.xo\n", "output": "YES\n"}, {"input": "o.x.\no...\n.x..\nooxx\n", "output": "NO\n"}, {"input": ".xox\no.x.\nx.o.\n..o.\n", "output": "YES\n"}, {"input": "o.oo\n.x.o\nx.x.\n.x..\n", "output": "YES\n"}, {"input": ".xx.\n.xoo\n.oox\n....\n", "output": "YES\n"}, {"input": "xxox\no.x.\nx.oo\nxo.o\n", "output": "YES\n"}, {"input": ".xox\n.x..\nxoo.\noox.\n", "output": "NO\n"}, {"input": ".oxx\nx...\n.o..\no...\n", "output": "NO\n"}, {"input": "...x\n.x.o\n.o..\n.x.o\n", "output": "NO\n"}, {"input": "oo.x\nxo.o\no.xx\n.oxx\n", "output": "YES\n"}, {"input": ".x.o\n..o.\n..ox\nxox.\n", "output": "NO\n"}, {"input": "....\n.x..\nx...\n..oo\n", "output": "YES\n"}, {"input": "....\n....\n.x.o\n..xo\n", "output": "YES\n"}, {"input": "xo.x\n...o\n.oox\nx...\n", "output": "NO\n"}, {"input": "o..o\nx..x\n.o.x\nxo..\n", "output": "YES\n"}, {"input": "ox.o\nx..x\nx..o\noo.x\n", "output": "NO\n"}, {"input": ".xox\n.x.o\nooxo\n..x.\n", "output": "YES\n"}, {"input": "x..o\no..o\n..x.\nx.xo\n", "output": "YES\n"}, {"input": "xxoo\no.oo\n...x\nx..x\n", "output": "NO\n"}, {"input": "xoox\n.xx.\no..o\n..xo\n", "output": "YES\n"}, {"input": "..o.\nxxox\n....\n.oxo\n", "output": "YES\n"}, {"input": "xoox\nxxox\noo..\n.ox.\n", "output": "YES\n"}, {"input": "..ox\n.o..\nx..o\n.oxx\n", "output": "NO\n"}, {"input": ".oo.\n.x..\nx...\nox..\n", "output": "YES\n"}, {"input": "o.xx\nxo.o\n...o\n..x.\n", "output": "YES\n"}, {"input": "x...\n.ox.\n.oo.\n.xox\n", "output": "NO\n"}, {"input": "xoxx\n..x.\no.oo\nx.o.\n", "output": "YES\n"}, {"input": ".x.x\n.o.o\no.xx\nx.oo\n", "output": "YES\n"}, {"input": "...o\nxo.x\n.x..\nxoo.\n", "output": "YES\n"}, {"input": "o...\n...o\noxx.\n.xxo\n", "output": "YES\n"}, {"input": "xxox\no..o\nx..o\noxox\n", "output": "NO\n"}, {"input": "x...\no.ox\nxo..\n....\n", "output": "NO\n"}, {"input": "x.x.\nox.o\n.o.o\nxox.\n", "output": "YES\n"}, {"input": ".oxx\n..xo\n.oox\n....\n", "output": "NO\n"}, {"input": "xxo.\n...x\nooxx\n.o.o\n", "output": "YES\n"}, {"input": "xoxo\no..x\n.xo.\nox..\n", "output": "YES\n"}, {"input": ".o..\nox..\n.o.x\n.x..\n", "output": "NO\n"}, {"input": ".oxo\nx...\n.o..\n.xox\n", "output": "NO\n"}, {"input": ".oxx\n..o.\n.o.x\n.ox.\n", "output": "YES\n"}, {"input": ".xxo\n...o\n..ox\nox..\n", "output": "YES\n"}, {"input": "x...\nxo..\noxo.\n..ox\n", "output": "NO\n"}, {"input": "xoxo\nx.ox\n....\noxo.\n", "output": "YES\n"}, {"input": "x..o\nxo.x\no.xo\nxoox\n", "output": "NO\n"}, {"input": ".x..\no..x\n.oo.\nxox.\n", "output": "NO\n"}, {"input": "xxox\no.x.\nxo.o\nxo.o\n", "output": "NO\n"}, {"input": ".xo.\nx.oo\n...x\n.o.x\n", "output": "NO\n"}, {"input": "ox.o\n...x\n..oo\nxxox\n", "output": "NO\n"}, {"input": "oox.\nxoo.\no.x.\nx..x\n", "output": "NO\n"}, {"input": "oxox\nx.oo\nooxx\nxxo.\n", "output": "NO\n"}, {"input": "....\nxo.x\n..x.\noo..\n", "output": "NO\n"}, {"input": ".ox.\nx..o\nxo.x\noxo.\n", "output": "YES\n"}, {"input": ".xox\nxo..\n..oo\n.x..\n", "output": "NO\n"}, {"input": "xxo.\n.oo.\n..x.\n..xo\n", "output": "NO\n"}, {"input": "ox..\n..oo\n..x.\nxxo.\n", "output": "NO\n"}, {"input": "xxo.\nx..x\noo.o\noxox\n", "output": "YES\n"}, {"input": "xx..\noxxo\nxo.o\noox.\n", "output": "YES\n"}, {"input": "xox.\noox.\n....\n....\n", "output": "YES\n"}, {"input": "x..o\no..o\no..x\nxxox\n", "output": "NO\n"}, {"input": "oxo.\nxx.x\nooxx\n.o.o\n", "output": "YES\n"}, {"input": ".o.x\no..o\nx..x\n..xo\n", "output": "NO\n"}, {"input": "x.x.\n...o\n.o..\n....\n", "output": "YES\n"}, {"input": "xo..\n....\nx...\n..o.\n", "output": "YES\n"}, {"input": "xo..\n....\n..xo\n....\n", "output": "YES\n"}, {"input": "ox.x\n...o\n....\n....\n", "output": "YES\n"}, {"input": ".x..\no.o.\n.x..\n....\n", "output": "YES\n"}, {"input": ".x..\no...\n...x\n.o..\n", "output": "YES\n"}, {"input": "..xo\n....\nx.o.\n....\n", "output": "YES\n"}, {"input": "o.x.\n....\n.ox.\n....\n", "output": "YES\n"}, {"input": "...x\n....\n.x.o\n..o.\n", "output": "YES\n"}, {"input": "o..x\n....\n...x\n..o.\n", "output": "YES\n"}, {"input": "o...\nx.x.\no...\n....\n", "output": "YES\n"}, {"input": "....\nxo..\n..o.\nx...\n", "output": "YES\n"}, {"input": ".oo.\nx...\n....\n..x.\n", "output": "YES\n"}, {"input": "....\n.x.x\no.o.\n....\n", "output": "YES\n"}, {"input": ".o..\n.x..\n..o.\n.x..\n", "output": "YES\n"}, {"input": "..o.\n.x..\n....\no..x\n", "output": "YES\n"}, {"input": "....\n.oxo\n....\nx...\n", "output": "YES\n"}, {"input": "..o.\n..x.\n....\n.ox.\n", "output": "YES\n"}, {"input": ".o..\no..x\n....\n.x..\n", "output": "YES\n"}, {"input": "....\n..ox\n....\n.o.x\n", "output": "YES\n"}, {"input": "o...\n.o..\nx.x.\n....\n", "output": "YES\n"}, {"input": "....\n..oo\n.x.x\n....\n", "output": "YES\n"}, {"input": ".o..\n....\no...\nx.x.\n", "output": "YES\n"}, {"input": "....\n.o..\n....\nox.x\n", "output": "YES\n"}, {"input": "oxo.\nxxox\noo.o\nxoxx\n", "output": "YES\n"}, {"input": "..xx\noo..\n....\n....\n", "output": "YES\n"}, {"input": ".xx.\n...x\noo.o\no..x\n", "output": "YES\n"}, {"input": "x...\n.x..\n....\noo..\n", "output": "YES\n"}, {"input": ".oox\n..x.\n....\n....\n", "output": "YES\n"}, {"input": "...x\no..x\n.o..\n....\n", "output": "YES\n"}, {"input": "oxox\n..ox\nxoxo\nxoxo\n", "output": "YES\n"}, {"input": "....\n.ox.\n.o..\nx...\n", "output": "NO\n"}, {"input": "....\n...x\n...x\noo..\n", "output": "YES\n"}] |
|
122 | Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position).
Inserting an element in the same position he was erased from is also considered moving.
Can Vasya divide the array after choosing the right element to move and its new position?
-----Input-----
The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array.
The second line contains n integers a_1, a_2... a_{n} (1 ≤ a_{i} ≤ 10^9) — the elements of the array.
-----Output-----
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
-----Examples-----
Input
3
1 3 2
Output
YES
Input
5
1 2 3 4 5
Output
NO
Input
5
2 2 3 4 5
Output
YES
-----Note-----
In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | interview | [{"code": "def solve(n,a):\n tot=0\n for i in range(n):\n tot+=a[i]\n diffs = [] #alla suffix - prefix diffs[i]=prefix-suffix om delas innan element i\n diffs.append(-tot)\n for i in range(n):\n tot-=2*a[i]\n diffs.append(-tot)\n if tot==0:\n return (\"YES\")\n for i in range(n):\n diffmake=2*a[i]\n j=binary(diffs,diffmake)\n if j>i and j!=-1:\n return (\"YES\")\n j=binary(diffs,-diffmake)\n if i>=j and j!=-1:\n return (\"YES\")\n return (\"NO\")\n\n\ndef binary(a,value):\n hi=len(a)\n lo=-1\n while (lo+1<hi):\n mi=(lo+hi)//2\n if a[mi]==value:\n return mi\n if a[mi]<value:\n lo=mi\n else:\n hi=mi\n return -1\n\n\nn=int(input())\na = input().split()\nfor i in range (n):\n a[i]=int(a[i])\nprint(solve(n,a))\n", "passed": true, "time": 0.17, "memory": 14548.0, "status": "done"}, {"code": "def solve():\n n = int(input())\n #n, w = map(int, input().split())\n a = list(map(int, input().split()))\n #a = [list(map(int, input().split())) for _ in range(n)]\n ok = 0\n Su = sum(a)\n di = dict()\n di[0] = 1\n su = 0\n for i in range(n):\n su += a[i]\n if di.get(a[i] * 2, 0) == 0:\n di[a[i] * 2] = 1\n if di.get(su - Su + su, 0) == 0:\n pass\n else:\n ok = 1\n di.clear()\n di[0] = 1\n su = 0\n for i in range(-1, -n - 1, -1):\n su += a[i]\n if di.get(a[i] * 2, 0) == 0:\n di[a[i] * 2] = 1\n if di.get(su - Su + su, 0) == 0:\n pass\n else:\n ok = 1\n if ok:\n print('YES')\n else:\n print('NO')\n\ndef __starting_point():\n solve()\n__starting_point()", "passed": true, "time": 0.15, "memory": 14652.0, "status": "done"}, {"code": "def mp(): return list(map(int,input().split()))\ndef lt(): return list(map(int,input().split()))\ndef pt(x): print(x)\ndef ip(): return input()\ndef it(): return int(input())\ndef sl(x): return [t for t in x]\ndef spl(x): return x.split()\ndef aj(liste, item): liste.append(item)\ndef bin(x): return \"{0:b}\".format(x)\ndef listring(l): return ' '.join([str(x) for x in l])\ndef ptlist(l): print(' '.join([str(x) for x in l]))\n\nn = it()\na = lt()\nk = 0\nleft = 0\nright = sum(a)\nbl = False\ndict = {}\nfor i in range(n):\n if a[i] in dict:\n (ma,mi) = dict[a[i]]\n dict[a[i]] = (max(ma,i),min(mi,i))\n else:\n dict[a[i]] = (i,i)\nwhile k < n and not bl:\n if right == left:\n bl = True\n elif right > left:\n x = (right-left)/2\n if x == int(x) and int(x) in dict and dict[int(x)][0] >= k:\n bl = True\n else:\n right -= a[k]\n left += a[k]\n k += 1\n else:\n x = (left-right)/2\n if x == int(x) and int(x) in dict and dict[int(x)][1] <= k-1:\n bl = True\n else:\n right -= a[k]\n left += a[k]\n k += 1\nif bl:\n pt(\"YES\")\nelse:\n pt(\"NO\")\n \n \n", "passed": true, "time": 0.85, "memory": 14504.0, "status": "done"}, {"code": "def solve(a):\n s = sum(a)\n if s % 2 == 1:\n return False\n s //= 2\n\n elements = set()\n cs = 0\n n = len(a)\n\n for i in range(n):\n cs += a[i]\n if cs == s:\n return True\n\n elements.add(a[i])\n\n if i > 0 and cs > s and cs - s in elements:\n return True\n\n return False\n\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n\n if solve(a):\n print(\"YES\")\n elif solve(a[::-1]):\n print(\"YES\")\n else:\n print(\"NO\")\n\n\ndef __starting_point():\n # import sys\n # sys.stdin = open(\"in.txt\")\n main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14164.0, "status": "done"}, {"code": "\n# Python Interpreter Version: Python 3.5.2\n#\n# Note: Educational Codeforces Round 21\n\ndef divPos(arr):\n sumArr = sum(arr)\n targetSum = sumArr / 2\n if sumArr % 2 != 0:\n return False\n lArr = set()\n sumlArr = 0\n for i in range(len(arr)):\n lArr.add(arr[i])\n sumlArr += arr[i]\n if sumlArr == targetSum or (sumlArr > targetSum and sumlArr - targetSum in lArr):\n return True\n return False\n\ndef __starting_point():\n n = input()\n arr = [int(x) for x in input().split()]\n # arr = [2,2,3,4,5]\n if divPos(arr) or divPos(arr[::-1]):\n print('YES')\n else:\n print('NO')\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14440.0, "status": "done"}, {"code": "import math\nimport re\n\ndef f(arr, n):\n a = set()\n x = 0\n y = sum(arr)\n res = 'NO'\n for i in range(n):\n x += arr[i]\n y -= arr[i]\n a.add(arr[i])\n q = x - y\n\n if q % 2 != 0:\n continue\n elif q == 0 or (q > 0 and q / 2 in a):\n res = 'YES'\n break\n return res\n\nn = int(input())\narr = list(map(int, input().split()))\n\nres = f(arr, n)\nif res == 'NO':\n arr = arr[::-1]\n res = f(arr, n)\n\nprint(res)\n\n # arr = list(map(int, input().split()))\n# res = 0\n# a = {math.pow(2, i) for i in range(35)}\n# for i in range(n-1):\n# for j in range(i+1,n):\n# if arr[i] + arr[j] % 2 % 2 % 2 % 2 % 2 in a:\n# res += 1\n#\n# print(res)\n\n\n# arr = list(map(int, input().split()))\n# m = int(input())\n# spis = list(map(int, input().split()))\n#\n# arr1 = sorted(arr, reverse=True)\n# a = [n - arr1.index(arr[el - 1]) for el in spis]\n# print(' '.join(map(str, a)))\n", "passed": true, "time": 1.61, "memory": 14624.0, "status": "done"}, {"code": "import sys\nfrom itertools import accumulate\n\ndef solve():\n n = int(input())\n a = [int(i) for i in input().split()]\n\n S = sum(a)\n\n if S & 1:\n print('NO')\n return\n\n f_a = dict()\n l_a = dict()\n\n for i in range(n):\n if a[i] not in f_a:\n f_a[a[i]] = i\n\n for i in range(n - 1, -1, -1):\n if a[i] not in l_a:\n l_a[a[i]] = i\n\n ps = [0] + list(accumulate(a))\n S //= 2\n\n for k in range(1, n + 1):\n x = S - ps[k]\n\n if x == 0:\n print('YES')\n return\n elif x > 0:\n if x in l_a and k <= l_a[x]:\n print('YES')\n return\n else:\n x *= -1\n \n if x in f_a and f_a[x] < k:\n print('YES')\n return\n\n print('NO')\n\n\ndef __starting_point():\n solve()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14696.0, "status": "done"}, {"code": "import sys\nfrom itertools import accumulate\n\ndef solve():\n n = int(input())\n a = [int(i) for i in input().split()]\n\n S = sum(a)\n\n if S & 1:\n print('NO')\n return\n\n S //= 2\n\n ap = set()\n ps = [0] + list(accumulate(a))\n\n for i in range(1, n + 1):\n x = ps[i] - S\n ap.add(a[i - 1])\n\n if x == 0 or x in ap:\n print('YES')\n return\n\n ap = set()\n a = a[::-1]\n ps = [0] + list(accumulate(a))\n\n for i in range(1, n + 1):\n x = ps[i] - S\n ap.add(a[i - 1])\n\n if x == 0 or x in ap:\n print('YES')\n return\n\n print('NO')\n\ndef __starting_point():\n solve()\n__starting_point()", "passed": true, "time": 0.15, "memory": 14464.0, "status": "done"}, {"code": "n = int(input())\narr = [int(x) for x in input().split()]\nif n==1:\n\tprint(\"NO\")\n\treturn\ns = sum(arr)\nsp = 0\nss = s\nsetq = {}\nsetp = {}\nfor i in arr:\n\tsetq[i] = setq.get(i,0)+1\n\tsetp[i] = 0\nfor i in range(n):\n\tsp += arr[i]\n\tss -= arr[i]\n\tsetp[arr[i]] += 1\n\tsetq[arr[i]] -= 1\n\tval = ss-sp\n\tif val>0 and not val&1:\n\t\tval //= 2\n\t\tans = setq.get(val,0)\n\t\tif ans>0:\n\t\t\tprint(\"YES\")\n\t\t\treturn\n\telif val<0 and not (-val)&1:\n\t\tval = -val\n\t\tval //= 2\n\t\tans = setp.get(val,0)\n\t\tif ans>0:\n\t\t\tprint(\"YES\")\n\t\t\treturn\n\telif val==0:\n\t\tprint(\"YES\")\n\t\treturn\nprint(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14496.0, "status": "done"}, {"code": "class Dick:\n def __init__(self):\n self.s = 0\n self.m = dict()\n def add(self, x):\n self.s += x\n if x in self.m:\n self.m[x] += 1\n else:\n self.m[x] = 1\n def rm(self, x):\n self.s -= x\n if self.m[x] > 1:\n self.m[x] -= 1\n else:\n self.m.pop(x)\n def shasei(self):\n return self.s\n def ininder(self, x):\n return x in self.m\ndef ok(a,n):\n w = sum(a)\n if w & 1:\n return 0\n f = Dick()\n s = Dick()\n for x in a:\n s.add(x)\n w //= 2\n for i in range(n):\n if s.ininder(w - f.shasei()) or f.ininder(w - s.shasei()):\n return 1\n f.add(a[i])\n s.rm(a[i])\n return 0\n\nn = int(input())\na = list(map(int, input().split()))\nprint(\"YES\" if ok(a,n) else \"NO\")", "passed": true, "time": 0.14, "memory": 14704.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\ns = sum(a)\n\n\ndef solve(a):\n rtn = False\n tmp = 0\n dic = {}\n for i in range(n):\n tmp += a[i]\n dic[a[i]] = True\n if tmp == s // 2:\n rtn = True\n break\n elif s // 2 < tmp and (tmp - s // 2) in dic:\n rtn = True\n break\n return rtn\n\n\nif n == 1 or s % 2 == 1:\n print('NO')\nelif solve(a) or solve(list(reversed(a))):\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 1.6, "memory": 14520.0, "status": "done"}, {"code": "def solve(n,a):\n tot=0\n for i in range(n):\n tot+=a[i]\n diffs = [] #alla suffix - prefix diffs[i]=prefix-suffix om delas innan element i\n diffs.append(-tot)\n for i in range(n):\n tot-=2*a[i]\n diffs.append(-tot)\n if tot==0:\n return (\"YES\")\n for i in range(n):\n diffmake=2*a[i]\n j=binary(diffs,diffmake)\n if j>i and j!=-1:\n return (\"YES\")\n j=binary(diffs,-diffmake)\n if i>=j and j!=-1:\n return (\"YES\")\n return (\"NO\")\n\n\ndef binary(a,value):\n hi=len(a)\n lo=-1\n while (lo+1<hi):\n mi=(lo+hi)//2\n if a[mi]==value:\n return mi\n if a[mi]<value:\n lo=mi\n else:\n hi=mi\n return -1\n\n\nn=int(input())\na = input().split()\nfor i in range (n):\n a[i]=int(a[i])\nprint(solve(n,a))", "passed": true, "time": 0.14, "memory": 14476.0, "status": "done"}, {"code": "import sys\nfrom bisect import bisect_left, bisect_right\n\n# sys.stdin = open(\"in\", \"r\")\n\n\ndef find(arr, x):\n i1 = bisect_left(arr, x)\n i2 = bisect_right(arr, x)\n if(i1 < len(arr) and arr[i1] == x):\n return i1, i2 - 1\n else:\n return -1\n\n\nn = int(input())\n\narr = [(i, int(x)) for i, x in enumerate(input().split())]\ncum = []\nfor i in range(n):\n if(i == 0):\n cum.append(arr[i][1])\n else:\n cum.append(cum[i - 1] + arr[i][1])\n\narr.sort(key=lambda a: a[1])\nvalues = [a[1] for a in arr]\n\nfor i in range(n):\n a = cum[i]\n b = cum[n - 1] - cum[i]\n diff = a - b\n\n if diff == 0:\n print(\"YES\")\n return\n elif(diff % 2 != 0):\n break\n else:\n diff //= 2\n idx = find(values, abs(diff))\n\n if(idx != -1 and ((diff > 0 and arr[idx[0]][0] <= i) or (diff < 0 and arr[idx[1]][0] > i))):\n print(\"YES\")\n return\nprint(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14608.0, "status": "done"}, {"code": "from functools import reduce\n\ndef solve():\n sum_ = a[:]\n for i in range(1, n):\n sum_[i] += sum_[i - 1]\n if (sum_[n - 1] % 2): return False\n half = int(sum_[n - 1] / 2)\n st = set([0])\n for i in range(n):\n if sum_[i] >= half and sum_[i] - half in st:\n return True\n st.add(a[i])\n\n sum_ = a[:]\n for i in range(n - 2, -1, -1):\n sum_[i] += sum_[i + 1]\n st = set([0])\n for i in range(n - 1, -1, -1):\n if sum_[i] >= half and sum_[i] - half in st:\n return True\n st.add(a[i])\n return False\n\nwhile True:\n try:\n n = int(input())\n except:\n break\n a = [int(x) for x in input().split(' ')]\n print('YES' if solve() else \"NO\")\n \n", "passed": true, "time": 0.15, "memory": 14512.0, "status": "done"}, {"code": "class Dick:\n def __init__(self):\n self.s = 0\n self.m = dict()\n def add(self, x):\n self.s += x\n if x in self.m:\n self.m[x] += 1\n else:\n self.m[x] = 1\n def rm(self, x):\n self.s -= x\n if self.m[x] > 1:\n self.m[x] -= 1\n else:\n self.m.pop(x)\n def shasei(self):\n return self.s\n def ininder(self, x):\n return x in self.m\ndef ok(a,n):\n w = sum(a)\n if w & 1:\n return 0\n f = Dick()\n s = Dick()\n for x in a:\n s.add(x)\n w //= 2\n for i in range(n):\n if s.ininder(w - f.shasei()) or f.ininder(w - s.shasei()):\n return 1\n f.add(a[i])\n s.rm(a[i])\n return 0\n\nn = int(input())\na = list(map(int, input().split()))\nprint(\"YES\" if ok(a,n) else \"NO\")\n", "passed": true, "time": 0.14, "memory": 14664.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\ne = set([0])\np = 0\ns = sum(a)\nif s % 2:\n st = False\nelse:\n st = True\nif st:\n st = False\n for j in range(2):\n for i in a:\n p += i\n e.add(i)\n if p - s // 2 in e:\n st = True\n break\n e = set([0])\n p = 0\n a.reverse()\nprint('YES' if st else 'NO')\n", "passed": true, "time": 0.14, "memory": 14444.0, "status": "done"}, {"code": "def divider(a):\n t = sum(a)\n d = []\n d.append(-t)\n for i in range(len(a)):\n t -= 2 * a[i]\n d.append(-t)\n if t == 0:\n return (\"YES\")\n for i in range(len(a)):\n s = 2 * a[i]\n j = binary(d, s)\n if j > i and j != -1:\n return (\"YES\")\n j = binary(d, -s)\n if i >= j and j != -1:\n return (\"YES\")\n return (\"NO\")\n\n\ndef binary(a, value):\n hi = len(a)\n lo = -1\n while (lo + 1 < hi):\n mi = (lo + hi) // 2\n if a[mi] == value:\n return mi\n if a[mi] < value:\n lo = mi\n else:\n hi = mi\n return -1\n\n\ndef __starting_point():\n n = input()\n a = [int(i) for i in input().split()]\n print(divider(a))\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14440.0, "status": "done"}, {"code": "def f(aa, s):\n d = {a: i for i, a in enumerate(aa)}\n for i, a in enumerate(aa):\n if s in d and i <= d[s]:\n return True\n s -= a\n if s <= 0:\n break\n return not s\n\n\nn = int(input())\naa = list(map(int, input().split()))\ns, res = sum(aa), False\nif not s & 1 and n > 1:\n res = f(aa, s // 2)\n if not res:\n aa.reverse()\n res = f(aa, s // 2)\nprint((\"NO\", \"YES\")[res])", "passed": true, "time": 0.14, "memory": 14548.0, "status": "done"}, {"code": "\n\n\ndef func():\n n = int(input())\n\n\n array = []\n sum = 0\n for index,number in enumerate(input().split()):\n num = int(number)\n array.append(num)\n sum += num\n\n if sum%1 ==1:\n print(\"NO\")\n return\n setn = set()\n sumSub = 0\n indexdict = {}\n for indexm,number in enumerate(array):\n sumSub += number\n\n\n sum2 = sumSub * 2 - sum\n if sum2%2 == 1:\n continue\n sum2 /= 2\n setn.add(sum2)\n indexdict[sum2] = indexm\n\n i = 0\n if 0 in setn:\n print(\"YES\")\n return\n while i < n:\n num = array[i]\n\n if num in setn and num in indexdict and i < indexdict[num]:\n\n print(\"YES\")\n return\n if -num in setn and -num in indexdict and i > indexdict[-num]:\n print(\"YES\")\n return\n i+=1\n\n print(\"NO\")\n\nfunc()\n", "passed": true, "time": 0.14, "memory": 14540.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nimport sys\nfrom collections import Counter\n\nn = int(input())\na = [int(x) for x in input().split()]\n\ns = sum(a)\nc1 = Counter(a)\nc2 = Counter()\n\ncur = 0\nfor x in a:\n c1[x] -= 1\n c2[x] += 1\n cur += x\n\n s1 = cur\n s2 = s - s1\n if s1 == s2:\n print('YES')\n return\n if (s2 - s1) % 2 == 1:\n continue\n if s2 > s1:\n if c1[(s2 - s1) // 2] > 0:\n print('YES')\n return\n else:\n if c2[(s1 - s2) // 2] > 0:\n print('YES')\n return\n\nprint('NO')\n", "passed": true, "time": 0.15, "memory": 14624.0, "status": "done"}] | [{"input": "3\n1 3 2\n", "output": "YES\n"}, {"input": "5\n1 2 3 4 5\n", "output": "NO\n"}, {"input": "5\n2 2 3 4 5\n", "output": "YES\n"}, {"input": "5\n72 32 17 46 82\n", "output": "NO\n"}, {"input": "6\n26 10 70 11 69 57\n", "output": "NO\n"}, {"input": "7\n4 7 10 7 5 5 1\n", "output": "NO\n"}, {"input": "8\n9 5 5 10 4 9 5 8\n", "output": "NO\n"}, {"input": "10\n9 6 8 5 5 2 8 9 2 2\n", "output": "YES\n"}, {"input": "15\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8\n", "output": "NO\n"}, {"input": "20\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13\n", "output": "NO\n"}, {"input": "20\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 10 6\n", "output": "NO\n"}, {"input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14\n", "output": "YES\n"}, {"input": "100\n89 38 63 73 77 4 99 74 30 5 69 57 97 37 88 71 36 59 19 63 46 20 33 58 61 98 100 31 33 53 99 96 34 17 44 95 54 52 22 77 67 88 20 88 26 43 12 23 96 94 14 7 57 86 56 54 32 8 3 43 97 56 74 22 5 100 12 60 93 12 44 68 31 63 7 71 21 29 19 38 50 47 97 43 50 59 88 40 51 61 20 68 32 66 70 48 19 55 91 53\n", "output": "NO\n"}, {"input": "100\n80 100 88 52 25 87 85 8 92 62 35 66 74 39 58 41 55 53 23 73 90 72 36 44 97 67 16 54 3 8 25 34 84 47 77 39 93 19 49 20 29 44 21 48 21 56 82 59 8 31 94 95 84 54 72 20 95 91 85 1 67 19 76 28 31 63 87 98 55 28 16 20 36 91 93 39 94 69 80 97 100 96 68 26 91 45 22 84 20 36 20 92 53 75 58 51 60 26 76 25\n", "output": "NO\n"}, {"input": "100\n27 95 57 29 91 85 83 36 72 86 39 5 79 61 78 93 100 97 73 23 82 66 41 92 38 92 100 96 48 56 66 47 5 32 69 13 95 23 46 62 99 83 57 66 98 82 81 57 37 37 81 64 45 76 72 43 99 76 86 22 37 39 93 80 99 36 53 83 3 32 52 9 78 34 47 100 33 72 19 40 29 56 77 32 79 72 15 88 100 98 56 50 22 81 88 92 58 70 21 19\n", "output": "NO\n"}, {"input": "100\n35 31 83 11 7 94 57 58 30 26 2 99 33 58 98 6 3 52 13 66 21 53 26 94 100 5 1 3 91 13 97 49 86 25 63 90 88 98 57 57 34 81 32 16 65 94 59 83 44 14 46 18 28 89 75 95 87 57 52 18 46 80 31 43 38 54 69 75 82 9 64 96 75 40 96 52 67 85 86 38 95 55 16 57 17 20 22 7 63 3 12 16 42 87 46 12 51 95 67 80\n", "output": "NO\n"}, {"input": "6\n1 4 3 100 100 6\n", "output": "YES\n"}, {"input": "6\n6 100 100 3 4 1\n", "output": "YES\n"}, {"input": "6\n4 2 3 7 1 1\n", "output": "YES\n"}, {"input": "4\n6 1 4 5\n", "output": "NO\n"}, {"input": "3\n228 114 114\n", "output": "YES\n"}, {"input": "3\n229 232 444\n", "output": "NO\n"}, {"input": "3\n322 324 555\n", "output": "NO\n"}, {"input": "3\n69 34 5\n", "output": "NO\n"}, {"input": "6\n5 4 1 2 2 2\n", "output": "YES\n"}, {"input": "3\n545 237 546\n", "output": "NO\n"}, {"input": "5\n2 3 1 1 1\n", "output": "YES\n"}, {"input": "6\n2 2 10 2 2 2\n", "output": "YES\n"}, {"input": "5\n5 4 6 5 6\n", "output": "NO\n"}, {"input": "5\n6 1 1 1 1\n", "output": "NO\n"}, {"input": "2\n1 3\n", "output": "NO\n"}, {"input": "5\n5 2 2 3 4\n", "output": "YES\n"}, {"input": "2\n2 2\n", "output": "YES\n"}, {"input": "5\n1 2 6 1 2\n", "output": "YES\n"}, {"input": "5\n1 1 8 5 1\n", "output": "YES\n"}, {"input": "10\n73 67 16 51 56 71 37 49 90 6\n", "output": "NO\n"}, {"input": "1\n10\n", "output": "NO\n"}, {"input": "1\n1\n", "output": "NO\n"}, {"input": "2\n1 1\n", "output": "YES\n"}, {"input": "5\n8 2 7 5 4\n", "output": "YES\n"}, {"input": "1\n2\n", "output": "NO\n"}, {"input": "16\n9 10 2 1 6 7 6 5 8 3 2 10 8 4 9 2\n", "output": "YES\n"}, {"input": "4\n8 2 2 4\n", "output": "YES\n"}, {"input": "19\n9 9 3 2 4 5 5 7 8 10 8 10 1 2 2 6 5 3 3\n", "output": "NO\n"}, {"input": "11\n7 2 1 8 8 2 4 10 8 7 1\n", "output": "YES\n"}, {"input": "6\n10 20 30 40 99 1\n", "output": "YES\n"}, {"input": "10\n3 7 9 2 10 1 9 6 4 1\n", "output": "NO\n"}, {"input": "3\n3 1 2\n", "output": "YES\n"}, {"input": "2\n9 3\n", "output": "NO\n"}, {"input": "7\n1 2 3 12 1 2 3\n", "output": "YES\n"}, {"input": "6\n2 4 4 5 8 5\n", "output": "YES\n"}, {"input": "18\n2 10 3 6 6 6 10 8 8 1 10 9 9 3 1 9 7 4\n", "output": "YES\n"}, {"input": "20\n9 6 6 10 4 4 8 7 4 10 10 2 10 5 9 5 3 10 1 9\n", "output": "NO\n"}, {"input": "12\n3 8 10 2 4 4 6 9 5 10 10 3\n", "output": "YES\n"}, {"input": "11\n9 2 7 7 7 3 7 5 4 10 7\n", "output": "NO\n"}, {"input": "5\n1 1 4 1 1\n", "output": "YES\n"}, {"input": "2\n4 4\n", "output": "YES\n"}, {"input": "2\n7 1\n", "output": "NO\n"}, {"input": "5\n10 5 6 7 6\n", "output": "YES\n"}, {"input": "11\n4 3 10 3 7 8 4 9 2 1 1\n", "output": "YES\n"}, {"input": "6\n705032704 1000000000 1000000000 1000000000 1000000000 1000000000\n", "output": "NO\n"}, {"input": "8\n1 5 6 8 3 1 7 3\n", "output": "YES\n"}, {"input": "20\n8 6 3 6 3 5 10 2 6 1 7 6 9 10 8 3 5 9 3 8\n", "output": "YES\n"}, {"input": "11\n2 4 8 3 4 7 9 10 5 3 3\n", "output": "YES\n"}, {"input": "7\n6 4 2 24 6 4 2\n", "output": "YES\n"}, {"input": "17\n7 1 1 1 8 9 1 10 8 8 7 9 7 9 1 6 5\n", "output": "NO\n"}, {"input": "7\n7 10 1 2 6 2 2\n", "output": "NO\n"}, {"input": "5\n10 10 40 10 10\n", "output": "YES\n"}, {"input": "3\n4 3 13\n", "output": "NO\n"}, {"input": "5\n5 2 10 2 1\n", "output": "YES\n"}, {"input": "7\n7 4 5 62 20 20 6\n", "output": "YES\n"}, {"input": "6\n1 5 2 20 10 2\n", "output": "YES\n"}, {"input": "2\n5 6\n", "output": "NO\n"}, {"input": "14\n5 2 9 7 5 8 3 2 2 4 9 1 3 10\n", "output": "YES\n"}, {"input": "5\n1 2 3 4 2\n", "output": "YES\n"}, {"input": "5\n2 2 2 5 5\n", "output": "NO\n"}, {"input": "11\n1 1 1 1 1 10 1 1 1 1 1\n", "output": "YES\n"}, {"input": "9\n8 4 13 19 11 1 8 2 8\n", "output": "YES\n"}, {"input": "6\n14 16 14 14 15 11\n", "output": "YES\n"}, {"input": "9\n14 19 1 13 11 3 1 1 7\n", "output": "YES\n"}, {"input": "6\n16 13 3 7 4 15\n", "output": "YES\n"}, {"input": "4\n11 7 12 14\n", "output": "NO\n"}, {"input": "3\n3 2 1\n", "output": "YES\n"}, {"input": "5\n2 1 3 6 4\n", "output": "YES\n"}, {"input": "5\n3 4 8 11 2\n", "output": "YES\n"}, {"input": "5\n1 2 10 3 4\n", "output": "YES\n"}, {"input": "6\n8 15 12 14 15 4\n", "output": "YES\n"}, {"input": "5\n1 2 4 4 5\n", "output": "YES\n"}, {"input": "3\n2 4 2\n", "output": "YES\n"}, {"input": "5\n2 3 1 6 4\n", "output": "YES\n"}, {"input": "7\n1 2 3 12 3 2 1\n", "output": "YES\n"}, {"input": "3\n3 4 13\n", "output": "NO\n"}, {"input": "6\n1 1 1 1 1000000000 1000000000\n", "output": "YES\n"}, {"input": "6\n19 6 5 13 6 13\n", "output": "YES\n"}, {"input": "8\n2 2 2 5 1 2 3 3\n", "output": "YES\n"}] |
|
123 | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.
Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total.
If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.
-----Input-----
The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 200) — Hitagi's broken sequence with exactly k zero elements.
The third line contains k space-separated integers b_1, b_2, ..., b_{k} (1 ≤ b_{i} ≤ 200) — the elements to fill into Hitagi's sequence.
Input guarantees that apart from 0, no integer occurs in a and b more than once in total.
-----Output-----
Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.
-----Examples-----
Input
4 2
11 0 0 14
5 4
Output
Yes
Input
6 1
2 3 0 8 9 10
5
Output
No
Input
4 1
8 94 0 4
89
Output
Yes
Input
7 7
0 0 0 0 0 0 0
1 2 3 4 5 6 7
Output
Yes
-----Note-----
In the first sample: Sequence a is 11, 0, 0, 14. Two of the elements are lost, and the candidates in b are 5 and 4. There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid. | interview | [{"code": "import sys\n\nn, k = list(map(int, input().split()))\na = [int(x) for x in input().split()]\nb = [int(x) for x in input().split()]\n\nb.sort(reverse=True)\n\nres = []\ncur_b = 0\nfor a_i in a:\n if a_i != 0:\n res.append(a_i)\n else:\n res.append(b[cur_b])\n cur_b += 1\n\nif res != list(sorted(res)):\n print(\"Yes\")\nelse:\n print(\"No\")\n", "passed": true, "time": 0.17, "memory": 14512.0, "status": "done"}, {"code": "R=lambda:list(map(int,input().split()))\ninput()\na=R()\nb=sorted(list(R()),reverse=True)\np=0\nfor i in range(len(a)):\n if a[i]==0:\n a[i]=b[p]\n p+=1\nprint('Yes'if any(a[i]<=a[i-1] for i in range(1,len(a)))else'No')\n", "passed": true, "time": 0.25, "memory": 14652.0, "status": "done"}, {"code": "# int(input())\n# map(int,input().split())\n# list(map(int,input().split()))\n# for _ in range(int(input())):\n\nn,m = list(map(int,input().split()))\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\nb.sort(reverse = True)\n\nc1 = 0\nfor i in range(n):\n if a[i] == 0:\n a[i] = b[c1]\n c1 += 1\n\nfor i in range(1,n):\n if a[i] <= a[i-1]:\n print(\"Yes\")\n break\nelse:\n print(\"No\")\n", "passed": true, "time": 0.25, "memory": 14544.0, "status": "done"}, {"code": "import sys\nn, m = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nneed = a.count(0)\nb.sort(reverse = True)\nptr = 0\nfor i in range(n):\n if (a[i] == 0):\n a[i] = b[ptr]\n ptr += 1\nz = a[:]\nz.sort()\nif (z == a):\n print('No')\nelse:\n print('Yes')\n", "passed": true, "time": 0.23, "memory": 14652.0, "status": "done"}, {"code": "a, b = map(int, input().split())\ns1 = list(map(int, input().split()))\ns2 = list(map(int, input().split()))\ns2.sort()\nfor i in range(a):\n if s1[i] == 0:\n s1[i] = s2.pop()\nif s1 == sorted(s1):\n print(\"No\")\nelse:\n print(\"Yes\")", "passed": true, "time": 0.15, "memory": 14692.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nif k == 1:\n ind = a.index(0)\n a[ind] = b[0]\n st = False\n for i in range(n - 1):\n if a[i] >= a[i + 1]:\n st = True\n break\n if st:\n print('Yes')\n else:\n print('No')\nelse:\n print('Yes')\n", "passed": true, "time": 0.15, "memory": 14608.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nb = list(reversed(sorted(b)))\nj = 0\nfor i in range(n):\n if a[i] == 0:\n a[i] = b[j]\n j += 1\nans = 'No'\nfor i in range(n - 1):\n if a[i] >= a[i + 1]:\n ans = 'Yes'\n break\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14480.0, "status": "done"}, {"code": "n, k = map(int, input().split())\n\na = [-10 ** 9] + list(map(int, input().split())) + [10 ** 9]\nif k > 1:\n print('Yes')\nelse:\n i = a.index(0)\n b = int(input())\n \n f = True\n for j in range(1, n):\n if a[j] <= a[j - 1] and a[j] != 0:\n f = False\n \n if f and a[i - 1] < b and a[i + 1] > b:\n print('No')\n else:\n print('Yes')", "passed": true, "time": 0.15, "memory": 14540.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\nai = list(map(int,input().split()))\nbi = list(map(int,input().split()))\nbi.sort()\nj = k-1\nfor i in range(n):\n if ai[i] == 0:\n ai[i] = bi[j]\n j -= 1\n\nans = 0\nfor i in range(1,n):\n if ai[i-1] >= ai[i]:\n ans = 1\nif ans == 1:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "passed": true, "time": 0.15, "memory": 14692.0, "status": "done"}, {"code": "n, k=[int(i) for i in input().split()]\na=[int(i) for i in input().split()]\nb=[int(i) for i in input().split()]\nif len(b) != 1:\n print('Yes')\nelse:\n a[a.index(0)] = b[0]\n for i in range(len(a)-1):\n if a[i]>a[i+1]:\n print('Yes')\n break\n else:\n print('No')", "passed": true, "time": 0.15, "memory": 14560.0, "status": "done"}, {"code": "from sys import stdin, stdout\n\n\nn,k = list(map(int,stdin.readline().rstrip().split()))\na = [int(x) for x in stdin.readline().rstrip().split()]\nb = [int(x) for x in stdin.readline().rstrip().split()]\n\nif k>1:\n print('Yes')\nelse:\n zeroInd = a.index(0)\n a[zeroInd] = b[0]\n aSort = sorted(a)\n identical = True\n for i in range(n):\n if aSort[i]!=a[i]:\n identical=False\n if identical:\n print('No')\n else:\n print('Yes')\n", "passed": true, "time": 0.15, "memory": 14612.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na = [int(i) for i in input().split()]\nb = [int(i) for i in input().split()]\nif k > 1:\n print(\"Yes\")\nelse:\n a[a.index(0)] = b[0]\n for i in range(1, n):\n if a[i] <= a[i - 1]:\n print(\"Yes\")\n break\n else:\n print(\"No\")", "passed": true, "time": 0.15, "memory": 14572.0, "status": "done"}, {"code": "n1,n2 = list(map(int,input().split()))\nn = list(map(int,input().split()))\nk = sorted(list(map(int,input().split())))[::-1]\nt = 0\nfor i in range(n1):\n if n[i] ==0:\n n[i] = k[t]\n t += 1\nif sorted(n) == n:\n print(\"No\")\nelse:\n print(\"Yes\")\n", "passed": true, "time": 0.15, "memory": 14408.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nb.sort(reverse=True)\nj = -1\nfor i in range(len(a)):\n if a[i] == 0:\n j += 1\n a[i] = b[j]\n if j == len(b):\n break\nflag = 0\nfor i in range(len(a) - 1):\n if a[i] >= a[i + 1]:\n flag = 1\n break\nif flag == 1:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "passed": true, "time": 0.15, "memory": 14508.0, "status": "done"}, {"code": "import sys\n\n\ndef main():\n n,k = map(int,sys.stdin.readline().split())\n \n a = list(map(int, sys.stdin.readline().split()))\n b = list(map(int, sys.stdin.readline().split()))\n b.sort(reverse=True)\n j = 0 \n for i in range(n):\n if a[i] ==0:\n a[i] = b[j]\n j+=1\n\n p = a[0]\n for i in range(1,n):\n if a[i] <= p:\n print(\"Yes\")\n return \n p = a[i]\n \n print(\"No\")\n \n\n\nmain()", "passed": true, "time": 0.15, "memory": 14600.0, "status": "done"}, {"code": "I = lambda: list(map(int, input().split()))\nn, k = I()\na, b = list(I()), list(I())\nif k == 1:\n c = list(a)\n c[c.index(0)] = b[0]\n if sorted(c) == c:\n print('No')\n return\nprint('Yes')\n", "passed": true, "time": 0.14, "memory": 14452.0, "status": "done"}, {"code": "n,k = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nif k > 1:\n print('Yes')\n return\nelse:\n for i in range(len(a)):\n if a[i] == 0:\n a[i] = b[0]\n break\n for i in range(len(a) - 1):\n if a[i] > a[i + 1]:\n print('Yes')\n return\nprint('No')\n", "passed": true, "time": 0.15, "memory": 14552.0, "status": "done"}, {"code": "n,k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\nb = [int(i) for i in input().split()]\n\nc = [i for i in a if i!=0]\n\nif (c != sorted(c)):\n print(\"Yes\")\nelse:\n if k == 1:\n for i in range(len(a)):\n if a[i] == 0:\n a[i] = b[0]\n if a == sorted(a):\n print(\"No\")\n else:\n print(\"Yes\")\n else:\n print(\"Yes\")\n \n \n", "passed": true, "time": 0.15, "memory": 14464.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na, b = list(map(int, input().split())), list(map(int, input().split()))\nif k > 1:\n print(\"Yes\")\nelse:\n a[a.index(0)] = b[0]\n if a == sorted(a):\n print(\"No\")\n else:\n print(\"Yes\")", "passed": true, "time": 0.15, "memory": 14660.0, "status": "done"}, {"code": "input()\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nn =len(a)\nk =len(b)\n\nb.sort()\n\ni = k-1\nc = []\nfor e in a:\n if e==0:\n c.append(b[i])\n i-=1\n else:\n c.append(e)\n\nyes = False\n\nfor i in range(1,n):\n if c[i] < c[i-1]:\n yes = True\n\nif yes:\n print(\"Yes\")\nelse:\n print(\"No\")\n\n", "passed": true, "time": 0.14, "memory": 14660.0, "status": "done"}, {"code": "n, k = map(int, input().split())\n\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\nif a.count(0) > 1:\n print(\"Yes\")\nelse:\n a[a.index(0)] = b[0]\n if a == sorted(a):\n print(\"No\")\n else:\n print(\"Yes\")", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "n,k = map(int,input().split())\nl1 = list(map(int,input().split()))\nl2 = list(map(int,input().split()))\nif(k!=1):\n\tprint('Yes')\n\treturn\nfor i in range(n):\n\tif(l1[i]==0):\n\t\tl1[i]=l2[0]\n\t\tbreak\nok = True\nfor i in range(n-1):\n\tif(l1[i+1]<l1[i]):\n\t\tok = False\n\t\tbreak\nif(ok==True):\n\tprint('No')\nelse:\n\tprint('Yes')", "passed": true, "time": 0.15, "memory": 14476.0, "status": "done"}] | [{"input": "4 2\n11 0 0 14\n5 4\n", "output": "Yes\n"}, {"input": "6 1\n2 3 0 8 9 10\n5\n", "output": "No\n"}, {"input": "4 1\n8 94 0 4\n89\n", "output": "Yes\n"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n", "output": "Yes\n"}, {"input": "40 1\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\n80\n", "output": "No\n"}, {"input": "100 1\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\n58\n", "output": "Yes\n"}, {"input": "4 1\n2 1 0 4\n3\n", "output": "Yes\n"}, {"input": "2 1\n199 0\n200\n", "output": "No\n"}, {"input": "3 2\n115 0 0\n145 191\n", "output": "Yes\n"}, {"input": "5 1\n196 197 198 0 200\n199\n", "output": "No\n"}, {"input": "5 1\n92 0 97 99 100\n93\n", "output": "No\n"}, {"input": "3 1\n3 87 0\n81\n", "output": "Yes\n"}, {"input": "3 1\n0 92 192\n118\n", "output": "Yes\n"}, {"input": "10 1\n1 3 0 7 35 46 66 72 83 90\n22\n", "output": "Yes\n"}, {"input": "100 1\n14 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 0 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\n67\n", "output": "No\n"}, {"input": "100 5\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 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 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 0 99 100\n98 64 55 52 29\n", "output": "Yes\n"}, {"input": "100 5\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\n121 199 62 193 27\n", "output": "Yes\n"}, {"input": "100 1\n1 2 3 4 5 6 7 8 9 0 10 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\n11\n", "output": "Yes\n"}, {"input": "100 1\n0 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\n1\n", "output": "No\n"}, {"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 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 0\n100\n", "output": "No\n"}, {"input": "100 1\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\n65\n", "output": "Yes\n"}, {"input": "100 2\n0 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 0 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\n48 1\n", "output": "Yes\n"}, {"input": "100 1\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\n69\n", "output": "Yes\n"}, {"input": "100 1\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\n129\n", "output": "No\n"}, {"input": "5 2\n0 2 7 0 10\n1 8\n", "output": "Yes\n"}, {"input": "3 1\n5 4 0\n1\n", "output": "Yes\n"}, {"input": "3 1\n1 0 3\n4\n", "output": "Yes\n"}, {"input": "2 1\n0 2\n1\n", "output": "No\n"}, {"input": "2 1\n0 5\n7\n", "output": "Yes\n"}, {"input": "5 1\n10 11 0 12 13\n1\n", "output": "Yes\n"}, {"input": "5 1\n0 2 3 4 5\n6\n", "output": "Yes\n"}, {"input": "6 2\n1 0 3 4 0 6\n2 5\n", "output": "Yes\n"}, {"input": "7 2\n1 2 3 0 0 6 7\n4 5\n", "output": "Yes\n"}, {"input": "4 1\n1 2 3 0\n4\n", "output": "No\n"}, {"input": "2 2\n0 0\n1 2\n", "output": "Yes\n"}, {"input": "3 2\n1 0 0\n2 3\n", "output": "Yes\n"}, {"input": "4 2\n1 0 4 0\n5 2\n", "output": "Yes\n"}, {"input": "2 1\n0 1\n2\n", "output": "Yes\n"}, {"input": "5 2\n1 0 4 0 6\n2 5\n", "output": "Yes\n"}, {"input": "5 1\n2 3 0 4 5\n1\n", "output": "Yes\n"}, {"input": "3 1\n0 2 3\n5\n", "output": "Yes\n"}, {"input": "6 1\n1 2 3 4 5 0\n6\n", "output": "No\n"}, {"input": "5 1\n1 2 0 4 5\n6\n", "output": "Yes\n"}, {"input": "3 1\n5 0 2\n7\n", "output": "Yes\n"}, {"input": "4 1\n4 5 0 8\n3\n", "output": "Yes\n"}, {"input": "5 1\n10 11 12 0 14\n13\n", "output": "No\n"}, {"input": "4 1\n1 2 0 4\n5\n", "output": "Yes\n"}, {"input": "3 1\n0 11 14\n12\n", "output": "Yes\n"}, {"input": "4 1\n1 3 0 4\n2\n", "output": "Yes\n"}, {"input": "2 1\n0 5\n1\n", "output": "No\n"}, {"input": "5 1\n1 2 0 4 7\n5\n", "output": "Yes\n"}, {"input": "3 1\n2 3 0\n1\n", "output": "Yes\n"}, {"input": "6 1\n1 2 3 0 5 4\n6\n", "output": "Yes\n"}, {"input": "4 2\n11 0 0 14\n13 12\n", "output": "Yes\n"}, {"input": "2 1\n1 0\n2\n", "output": "No\n"}, {"input": "3 1\n1 2 0\n3\n", "output": "No\n"}, {"input": "4 1\n1 0 3 2\n4\n", "output": "Yes\n"}, {"input": "3 1\n0 1 2\n5\n", "output": "Yes\n"}, {"input": "3 1\n0 1 2\n3\n", "output": "Yes\n"}, {"input": "4 1\n0 2 3 4\n5\n", "output": "Yes\n"}, {"input": "6 1\n1 2 3 0 4 5\n6\n", "output": "Yes\n"}, {"input": "3 1\n1 2 0\n5\n", "output": "No\n"}, {"input": "4 2\n1 0 0 4\n3 2\n", "output": "Yes\n"}, {"input": "5 1\n2 3 0 5 7\n6\n", "output": "Yes\n"}, {"input": "3 1\n2 3 0\n4\n", "output": "No\n"}, {"input": "3 1\n1 0 11\n5\n", "output": "No\n"}, {"input": "4 1\n7 9 5 0\n8\n", "output": "Yes\n"}, {"input": "6 2\n1 2 3 0 5 0\n6 4\n", "output": "Yes\n"}, {"input": "3 2\n0 1 0\n3 2\n", "output": "Yes\n"}, {"input": "4 1\n6 9 5 0\n8\n", "output": "Yes\n"}, {"input": "2 1\n0 3\n6\n", "output": "Yes\n"}, {"input": "5 2\n1 2 0 0 5\n4 3\n", "output": "Yes\n"}, {"input": "4 2\n2 0 0 8\n3 4\n", "output": "Yes\n"}, {"input": "2 1\n0 2\n3\n", "output": "Yes\n"}, {"input": "3 1\n0 4 5\n6\n", "output": "Yes\n"}, {"input": "6 1\n1 2 3 4 0 5\n6\n", "output": "Yes\n"}, {"input": "2 1\n2 0\n3\n", "output": "No\n"}, {"input": "4 2\n11 0 0 200\n100 199\n", "output": "Yes\n"}, {"input": "2 1\n5 0\n4\n", "output": "Yes\n"}, {"input": "3 1\n1 0 5\n10\n", "output": "Yes\n"}, {"input": "6 2\n1 2 0 0 5 6\n3 4\n", "output": "Yes\n"}, {"input": "5 2\n1 0 3 0 5\n2 4\n", "output": "Yes\n"}, {"input": "4 1\n1 4 0 8\n3\n", "output": "Yes\n"}, {"input": "4 1\n5 9 4 0\n8\n", "output": "Yes\n"}, {"input": "4 2\n1 0 0 7\n3 2\n", "output": "Yes\n"}, {"input": "3 3\n0 0 0\n1 4 3\n", "output": "Yes\n"}, {"input": "5 5\n0 0 0 0 0\n5 4 3 2 1\n", "output": "Yes\n"}, {"input": "4 1\n3 9 4 0\n8\n", "output": "Yes\n"}, {"input": "4 2\n1 0 0 4\n2 3\n", "output": "Yes\n"}, {"input": "6 1\n2 4 0 8 9 10\n3\n", "output": "Yes\n"}, {"input": "4 1\n0 3 5 6\n9\n", "output": "Yes\n"}, {"input": "4 2\n1 2 0 0\n3 4\n", "output": "Yes\n"}, {"input": "5 1\n2 3 4 5 0\n1\n", "output": "Yes\n"}, {"input": "3 1\n2 0 4\n5\n", "output": "Yes\n"}] |
|
124 | The Duck song
For simplicity, we'll assume that there are only three types of grapes: green grapes, purple grapes and black grapes.
Andrew, Dmitry and Michal are all grapes' lovers, however their preferences of grapes are different. To make all of them happy, the following should happen: Andrew, Dmitry and Michal should eat at least $x$, $y$ and $z$ grapes, respectively. Andrew has an extreme affinity for green grapes, thus he will eat green grapes and green grapes only. On the other hand, Dmitry is not a fan of black grapes — any types of grapes except black would do for him. In other words, Dmitry can eat green and purple grapes. Michal has a common taste — he enjoys grapes in general and will be pleased with any types of grapes, as long as the quantity is sufficient.
Knowing that his friends are so fond of grapes, Aki decided to host a grape party with them. He has prepared a box with $a$ green grapes, $b$ purple grapes and $c$ black grapes.
However, Aki isn't sure if the box he prepared contains enough grapes to make everyone happy. Can you please find out whether it's possible to distribute grapes so that everyone is happy or Aki has to buy some more grapes?
It is not required to distribute all the grapes, so it's possible that some of them will remain unused.
-----Input-----
The first line contains three integers $x$, $y$ and $z$ ($1 \le x, y, z \le 10^5$) — the number of grapes Andrew, Dmitry and Michal want to eat.
The second line contains three integers $a$, $b$, $c$ ($1 \le a, b, c \le 10^5$) — the number of green, purple and black grapes in the box.
-----Output-----
If there is a grape distribution that allows everyone to be happy, print "YES", otherwise print "NO".
-----Examples-----
Input
1 6 2
4 3 3
Output
YES
Input
5 1 1
4 3 2
Output
NO
-----Note-----
In the first example, there is only one possible distribution:
Andrew should take $1$ green grape, Dmitry should take $3$ remaining green grapes and $3$ purple grapes, and Michal will take $2$ out of $3$ available black grapes.
In the second test, there is no possible distribution, since Andrew is not be able to eat enough green grapes. :( | interview | [{"code": "x,y,z = list(map(int,input().split()))\na,b,c = list(map(int,input().split()))\nif a < x:\n print(\"NO\")\n return\nx -= a\ny += x\nif b < y:\n print(\"NO\")\n return\ny -= b\nz += y\nif c < z:\n print(\"NO\")\n return\nprint(\"YES\") \n", "passed": true, "time": 0.3, "memory": 14440.0, "status": "done"}, {"code": "x, y, z= map(int, input().split())\na, b, c = map(int,input().split())\nif a >= x:\n a -= x\n s = a + b\n if s >= y:\n s -= y\n s += c\n if s >= z:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.16, "memory": 14588.0, "status": "done"}, {"code": "x, y, z = list(map(int, input().split()))\na, b, c = list(map(int, input().split()))\na -= x\nif a < 0:\n\tprint(\"NO\")\n\treturn\nif a + b < y:\n\tprint(\"NO\")\n\treturn\nif a + b + c - y < z:\n\tprint(\"NO\")\n\treturn\nprint(\"YES\")\n", "passed": true, "time": 0.15, "memory": 14452.0, "status": "done"}, {"code": "x, y, z = map(int, input().split())\na, b, c = map(int, input().split())\n\nf = a\ns = a + b\nt = a + c + b\n\nf -= x\ns = s - x - y\nt = t - x - y - z\n\nif f < 0 or s < 0 or t < 0:\n print('NO')\nelse:\n print('YES')", "passed": true, "time": 1.05, "memory": 14388.0, "status": "done"}, {"code": "import math as mt\nimport itertools as it\nimport functools as ft\nimport random as rnd\n\nstdin = lambda type_ = \"int\", sep = \" \": list(map(eval(type_), input().split(sep)))\njoint = lambda sep = \" \", *args: sep.join(str(i) if type(i) != list else sep.join(map(str, i)) for i in args)\n\nx, y, z = stdin()\na, b, c = stdin()\n\na -= x\n\nif a < 0:\n print(\"NO\")\n return\n\nif a + b < y:\n print(\"NO\")\n return\n\nif a + b + c < y + z:\n print(\"NO\")\n return\n\nprint(\"YES\")", "passed": true, "time": 0.36, "memory": 14644.0, "status": "done"}, {"code": "x, y, z = list(map(int, input().split()))\na, b, c = list(map(int, input().split()))\n\nif x > a:\n print('NO')\nelse:\n a -= x\n if a + b >= y and a + b + c >= y + z:\n print('YES')\n else:\n print('NO')\n", "passed": true, "time": 0.15, "memory": 14624.0, "status": "done"}, {"code": "# coding: utf-8\n\nimport sys\nimport math\n\nimport array\nimport bisect\nimport collections\nfrom collections import Counter, defaultdict\nimport fractions\nimport heapq\nimport re\n\nsys.setrecursionlimit(1000000)\n\n\ndef array2d(dim1, dim2, init=None):\n return [[init for _ in range(dim2)] for _ in range(dim1)]\n\ndef argsort(l, reverse=False):\n return sorted(list(range(len(l))), key=lambda i: l[i], reverse=reverse)\n\ndef argmin(l):\n return l.index(min(l))\n\ndef YESNO(ans, yes=\"YES\", no=\"NO\"):\n print([no, yes][ans])\n\nII = lambda: int(input())\nMI = lambda: list(map(int, input().split()))\nMIL = lambda: list(MI())\nMIS = lambda: input().split()\n\n\ndef main():\n x, y, z = MI()\n a, b, c = MI()\n return a >= x and a + b >= x + y and a + b + c >= x + y + z\n\n\ndef __starting_point():\n YESNO(main())\n\n__starting_point()", "passed": true, "time": 0.31, "memory": 14444.0, "status": "done"}, {"code": "x,y,z=map(int,input().split())\na,b,c=map(int,input().split())\nif x>a or ((a+b)-x)<y or ((a+b+c)-x-y)<z:\n\tprint(\"NO\")\nelse:\n\tprint(\"YES\")", "passed": true, "time": 0.15, "memory": 14612.0, "status": "done"}, {"code": "a,b,c=list(map(int,input().split()))\nd,e,f=list(map(int,input().split()))\nif a>d or a+b>d+e or a+b+c>d+e+f:\n print('NO')\nelse:\n print('YES')\n", "passed": true, "time": 0.15, "memory": 14568.0, "status": "done"}, {"code": "x, y, z = list(map(int, input().split()))\na, b, c = list(map(int, input().split()))\nif a >= x and a+b >= x+y and a+b+c >= x+y+z:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.21, "memory": 14400.0, "status": "done"}, {"code": "x, y, z = map(int, input().split())\na, b, c = map(int, input().split())\nif a >= x:\n if a + b - y - x >= 0:\n if a + b + c - x - y - z >= 0:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.2, "memory": 14632.0, "status": "done"}, {"code": "ii = lambda: int(input())\nmi = lambda: map(int, input().split())\nli = lambda: list(mi())\n\nx, y, z = mi()\na, b, c = mi()\nok = 0\nif a >= x:\n a -= x\n if a + b >= y:\n if a + b - y + c >= z:\n ok = 1\nprint('YES' if ok else 'NO')", "passed": true, "time": 0.14, "memory": 14412.0, "status": "done"}, {"code": "x,y,z=[int(k) for k in input().split(\" \")]\na,b,c=[int(k) for k in input().split(\" \")]\n\n\nif a>=x and a+b>=x+y and a+b+c>=x+y+z:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.19, "memory": 14400.0, "status": "done"}, {"code": "x, y, z = list(map(int, input().split()))\na, b, c = list(map(int, input().split()))\nif a >= x:\n a -= x\n d = min(y, a)\n a -= d\n y -= d\n if (b >= y):\n b -= y\n if a + b + c >= z:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14596.0, "status": "done"}, {"code": "x, y, z = list(map(int, input().split()))\nzz, f, ch = list(map(int, input().split()))\nzz -= x\nif zz < 0:\n\tprint('NO')\n\treturn\nk = zz + f\nk -= y\nif k < 0:\n\tprint('NO')\n\treturn\nk += ch\nif k - z < 0:\n\tprint('NO')\n\treturn\nprint('YES')\n", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "a,b,c=list(map(int,input().split()))\ng,q,y=list(map(int,input().split()))\ng-=a\nif g>=0:\n\tq-=b-g\n\tif q>=0:\n\t\ty-=c-q\n\t\tif y>=0:\n\t\t\tprint(\"YES\")\n\t\telse:\n\t\t\tprint(\"NO\")\n\telse:\n\t\tprint(\"NO\")\nelse:\n\tprint(\"NO\")\n\t\t\t\n", "passed": true, "time": 0.14, "memory": 14516.0, "status": "done"}, {"code": "x, y, z = [int(x) for x in input().split()]\na, b, c = [int(x) for x in input().split()]\nif a < x:\n print(\"NO\")\n return\na -= x\nb += a\nif b < y:\n print(\"NO\")\n return\nb -= y\nc += b\nif c < z:\n print(\"NO\")\n return\nprint(\"YES\")", "passed": true, "time": 0.25, "memory": 14540.0, "status": "done"}, {"code": "import math,time\n\ndef main():\n\tx,y,z = list(map(int, input().split()))\n\ta,b,c = list(map(int, input().split()))\n\tif x>a:\n\t\tprint(\"NO\")\n\t\treturn\n\telse:\n\t\ta -= x\n\t\tu = a+b\n\t\tif y>u:\n\t\t\tprint(\"NO\")\n\t\t\treturn\n\t\telse:\n\t\t\tu -= y\n\t\t\tu += c\n\t\t\tif z>u:\n\t\t\t\tprint(\"NO\")\n\t\t\t\treturn\n\t\t\telse:\n\t\t\t\tprint(\"YES\")\n\ndef __starting_point():\n\tstart_time = time.time()\n\tmain()\n\t#print(\"--- %s seconds ---\" % (time.time() - start_time))\n\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14616.0, "status": "done"}, {"code": "x, y, z = map(int, input().split())\na, b, c = map(int, input().split())\nres = True\nif a >= x:\n a -= x\n if a + b >= y:\n if a + b + c - y >= z:\n res = True\n else:\n res = False\n else:\n res = False\nelse:\n res = False\n\nprint(\"YES\" if res else \"NO\")", "passed": true, "time": 0.15, "memory": 14484.0, "status": "done"}, {"code": "x, y, z = list(map(int, input().split()))\na, b, c = list(map(int, input().split()))\nif a >= x:\n a -= x\n if a + b >= y:\n b += a - y\n if b + c >= z:\n print(\"YES\")\n return\nprint(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "x,y,z=list(map(int,input().split()))\na,b,c=list(map(int,input().split()))\nflag=0\nif(a<x):\n\tprint('NO')\n\treturn\na-=x\nif(a+b<y):\n\tprint('NO')\n\treturn\nif(a+b+c-y<z):\n\tprint('NO')\n\treturn\nprint('YES')\n", "passed": true, "time": 0.14, "memory": 14692.0, "status": "done"}, {"code": "x, y, z = map(int, input().split())\na, b, c = map(int, input().split())\nbad = False\nif a >= x and a + b >= x + y and a + b + c >= x + y + z:\n\tprint('YES')\nelse:\n\tprint('NO')", "passed": true, "time": 0.14, "memory": 14600.0, "status": "done"}, {"code": "a = input().split()\n\nx,y,z = list(map(int, a))\n\na, b, c = list(map(int, input().split()))\nrem = 0\nans = 1\nif x>a:\n ans = 0\nelse:\n a -= x\n\n\n\nif y> a+b:\n ans = 0\nelse:\n rem = a+b+c - y\n\nif rem<z and ans != 0:\n ans = 0\n\nif ans == 0:\n print('NO')\nelse:\n print(\"YES\")", "passed": true, "time": 0.14, "memory": 14624.0, "status": "done"}] | [{"input": "1 6 2\n4 3 3\n", "output": "YES\n"}, {"input": "5 1 1\n4 3 2\n", "output": "NO\n"}, {"input": "1 1 100000\n4 2 99995\n", "output": "NO\n"}, {"input": "1 2 3\n3 2 1\n", "output": "YES\n"}, {"input": "1 8 4\n3 1 9\n", "output": "NO\n"}, {"input": "6 1 2\n4 9 6\n", "output": "NO\n"}, {"input": "100000 100000 100000\n100000 100000 100000\n", "output": "YES\n"}, {"input": "3 2 1\n1 2 3\n", "output": "NO\n"}, {"input": "99999 99998 99997\n99997 99998 99999\n", "output": "NO\n"}, {"input": "1 7 9\n4 5 7\n", "output": "NO\n"}, {"input": "99999 100000 100000\n100000 100000 100000\n", "output": "YES\n"}, {"input": "100000 99999 100000\n100000 100000 100000\n", "output": "YES\n"}, {"input": "100000 100000 99999\n100000 100000 100000\n", "output": "YES\n"}, {"input": "100000 100000 100000\n99999 100000 100000\n", "output": "NO\n"}, {"input": "100000 100000 100000\n100000 99999 100000\n", "output": "NO\n"}, {"input": "100000 100000 100000\n100000 100000 99999\n", "output": "NO\n"}, {"input": "4 6 4\n4 5 6\n", "output": "NO\n"}, {"input": "6 1 9\n1 7 8\n", "output": "NO\n"}, {"input": "4 10 5\n4 10 5\n", "output": "YES\n"}, {"input": "10 1 7\n1 9 10\n", "output": "NO\n"}, {"input": "2 7 9\n7 2 5\n", "output": "NO\n"}, {"input": "4 4 1\n2 6 6\n", "output": "NO\n"}, {"input": "7 3 9\n7 8 4\n", "output": "YES\n"}, {"input": "2 8 5\n6 5 4\n", "output": "YES\n"}, {"input": "80000 80004 80000\n80000 80006 80009\n", "output": "YES\n"}, {"input": "80004 80010 80005\n80005 80005 80006\n", "output": "NO\n"}, {"input": "80004 80000 80005\n80008 80001 80004\n", "output": "YES\n"}, {"input": "80001 80009 80008\n80006 80006 80003\n", "output": "NO\n"}, {"input": "80010 80001 80005\n80009 80002 80005\n", "output": "NO\n"}, {"input": "80003 80009 80004\n80007 80005 80009\n", "output": "YES\n"}, {"input": "80002 80005 80007\n80008 80005 80001\n", "output": "YES\n"}, {"input": "80003 80006 80001\n80004 80001 80010\n", "output": "NO\n"}, {"input": "1 10 7\n1 6 1\n", "output": "NO\n"}, {"input": "29 42 41\n94 70 42\n", "output": "YES\n"}, {"input": "945 294 738\n724 168 735\n", "output": "NO\n"}, {"input": "4235 5782 8602\n7610 3196 4435\n", "output": "NO\n"}, {"input": "13947 31881 67834\n62470 11361 74085\n", "output": "YES\n"}, {"input": "2 2 10\n100 1 1\n", "output": "YES\n"}, {"input": "1 2 4\n1 3 3\n", "output": "YES\n"}, {"input": "2 2 6\n3 3 3\n", "output": "NO\n"}, {"input": "5 5 10\n10 1 40\n", "output": "YES\n"}, {"input": "1 2 1\n1 1 2\n", "output": "NO\n"}, {"input": "1 2 7\n2 3 4\n", "output": "NO\n"}, {"input": "5 5 4\n11 1 1\n", "output": "NO\n"}, {"input": "1 2 6\n2 3 4\n", "output": "YES\n"}, {"input": "3 3 3\n3 2 10\n", "output": "NO\n"}, {"input": "5 5 1\n5 4 6\n", "output": "NO\n"}, {"input": "10 2 10\n12 2 10\n", "output": "YES\n"}, {"input": "1 3 1\n7 1 2\n", "output": "YES\n"}, {"input": "5 4 1\n5 3 2\n", "output": "NO\n"}, {"input": "2 2 2\n2 1 3\n", "output": "NO\n"}, {"input": "1 2 1\n1 1 50\n", "output": "NO\n"}, {"input": "10 1 5\n10 1 5\n", "output": "YES\n"}, {"input": "3 5 2\n3 3 10\n", "output": "NO\n"}, {"input": "2 1 1\n10 10 10\n", "output": "YES\n"}, {"input": "1 2 3\n1 2 1\n", "output": "NO\n"}, {"input": "3 6 2\n3 7 2\n", "output": "YES\n"}, {"input": "5 4 6\n5 2 100\n", "output": "NO\n"}, {"input": "3 3 3\n3 2 4\n", "output": "NO\n"}, {"input": "1 3 2\n10 1 2\n", "output": "YES\n"}, {"input": "10 20 1\n10 19 10\n", "output": "NO\n"}, {"input": "5 7 5\n7 5 3\n", "output": "NO\n"}, {"input": "3 3 6\n3 3 10\n", "output": "YES\n"}, {"input": "2 2 2\n2 3 1\n", "output": "YES\n"}, {"input": "2 2 1\n2 1 2\n", "output": "NO\n"}, {"input": "3 7 2\n3 5 5\n", "output": "NO\n"}, {"input": "4 4 1\n5 1 9\n", "output": "NO\n"}, {"input": "1 2 3\n1 2 10\n", "output": "YES\n"}, {"input": "5 5 6\n5 7 5\n", "output": "YES\n"}, {"input": "2 2 3\n3 1 1\n", "output": "NO\n"}, {"input": "1 2 5\n1 1 65\n", "output": "NO\n"}, {"input": "4 1 2\n4 1 2\n", "output": "YES\n"}, {"input": "3 5 10\n6 5 5\n", "output": "NO\n"}, {"input": "5 5 5\n13 1 1\n", "output": "YES\n"}, {"input": "5 4 7\n6 5 8\n", "output": "YES\n"}, {"input": "3 4 3\n3 4 2\n", "output": "NO\n"}, {"input": "10000 10000 10000\n10000 10000 9999\n", "output": "NO\n"}, {"input": "2 2 3\n8 1 1\n", "output": "YES\n"}, {"input": "5 10 1\n5 5 10\n", "output": "NO\n"}, {"input": "2 4 5\n2 4 5\n", "output": "YES\n"}, {"input": "3 2 2\n3 1 10\n", "output": "NO\n"}, {"input": "5 100 200\n5 10 20\n", "output": "NO\n"}, {"input": "9 22 1\n10 20 30\n", "output": "NO\n"}, {"input": "77 31 57\n81 5 100\n", "output": "NO\n"}, {"input": "1 1 2\n1 1 2\n", "output": "YES\n"}, {"input": "38 59 70\n81 97 5\n", "output": "YES\n"}, {"input": "1 1 100\n50 50 50\n", "output": "YES\n"}, {"input": "5 100 5\n10 10 10\n", "output": "NO\n"}, {"input": "1 3 1\n1 2 2\n", "output": "NO\n"}, {"input": "1 1 9\n3 3 5\n", "output": "YES\n"}, {"input": "5 5 5\n5 5 1\n", "output": "NO\n"}, {"input": "3 2 1\n3 1 2\n", "output": "NO\n"}, {"input": "4 2 1\n4 1 2\n", "output": "NO\n"}, {"input": "3 100 1\n3 1 100\n", "output": "NO\n"}] |
|
125 | Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (l — left, s — straight, r — right) and a light p for a pedestrian crossing. [Image]
An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.
Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible.
-----Input-----
The input consists of four lines with each line describing a road part given in a counter-clockwise order.
Each line contains four integers l, s, r, p — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.
-----Output-----
On a single line, print "YES" if an accident is possible, and "NO" otherwise.
-----Examples-----
Input
1 0 0 1
0 1 0 0
0 0 1 0
0 0 0 1
Output
YES
Input
0 1 1 0
1 0 1 0
1 1 0 0
0 0 0 1
Output
NO
Input
1 0 0 0
0 0 0 1
0 0 0 0
1 0 1 0
Output
NO
-----Note-----
In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.
In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur. | interview | [{"code": "lanes = []\n\nfor i in range(4):\n lanes.append(list(map(int, input().split())))\n\nlanes.extend(lanes)\n\nfor i in range(4):\n ln = lanes[i]\n if (ln[3] and (ln[0] or ln[1] or ln[2])) or \\\n (ln[0] and lanes[i + 3][3]) or \\\n (ln[1] and lanes[i + 2][3]) or \\\n (ln[2] and lanes[i + 1][3]):\n print('YES')\n break\nelse:\n print('NO')", "passed": true, "time": 0.22, "memory": 14600.0, "status": "done"}, {"code": "L = [0, 4, 1, 2, 3]\nR = [0, 2, 3, 4, 1]\nS = [0, 3, 4, 1, 2]\n\nH = [0, 0, 0, 0, 0]\nP = H[:]\nfor i in range(1, 5):\n l, s, r, p = list(map(int, input().split()))\n P[i] = p\n if 1 in [l, s, r]:\n H[i] = 1\n if l:\n H[L[i]] = 1\n if s:\n H[S[i]] = 1\n if r:\n H[R[i]] = 1\nans = \"NO\"\nfor i in range(1, 5):\n if P[i] and H[i]:\n ans = \"YES\"\nprint(ans)\n\n", "passed": true, "time": 1.74, "memory": 14484.0, "status": "done"}, {"code": "def booly(s):\n return bool(int(s))\n\na = [None]*4;\na[0] = list(map(booly, input().split()))\na[1] = list(map(booly, input().split()))\na[2] = list(map(booly, input().split()))\na[3] =list( map(booly, input().split()))\n\nacc = False\n\nfor i in range(4):\n if (a[i][3] and (a[i][0] or a[i][1] or a[i][2])):\n acc = True\n\n if (a[i][3] and a[(i+1)%4][0]):\n acc = True\n \n if (a[i][3] and a[(i-1)%4][2]):\n acc = True\n\n if (a[i][3] and a[(i+2)%4][1]):\n acc = True\n\nif acc:\n print(\"YES\");\nelse:\n print(\"NO\");\n", "passed": true, "time": 0.17, "memory": 14720.0, "status": "done"}, {"code": "p = [list(map(int, input().split())) for i in range(4)]\nlog = False\nfor i in range(4):\n if p[i][3] == 1 and (p[i - 1][2] + p[(i + 1) % 4][0] + p[(i + 2) % 4][1] + p[i][1] + p[i][0] + p[i][2] > 0):\n log = True\nif log:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n", "passed": true, "time": 0.15, "memory": 14600.0, "status": "done"}, {"code": "a, b, c, d = [], [], [], []\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = list(map(int, input().split()))\nd = list(map(int, input().split()))\nst = False\nif a[3] == 1:\n if 1 in a[:3] or b[0] or c[1] or d[2]:\n st = True\nif b[3] == 1:\n if 1 in b[:3] or a[2] or c[0] or d[1]:\n st = True\nif c[3] == 1:\n if 1 in c[:3] or a[1] or b[2] or d[0]:\n st = True\nif d[3] == 1:\n if 1 in d[:3] or a[0] or b[1] or c[2]:\n st = True\nprint('YES' if st else 'NO')\n", "passed": true, "time": 0.16, "memory": 14472.0, "status": "done"}, {"code": "arr = [list() for i in range(4)]\narrp = []\nfor i in range(4):\n l, s, r, p = [int(i) for i in input().split()]\n arr[i].extend([l, s, r])\n arr[[3, i - 1][i > 0]].append(l)\n arr[[0, i + 1][i < 3]].append(r)\n arr[(i + 2) % 4].append(s)\n arrp.append(p)\nfor i in range(4):\n if arrp[i]:\n if 1 in arr[i]:\n print('YES')\n break\nelse:\n print('NO')\n", "passed": true, "time": 0.2, "memory": 14544.0, "status": "done"}, {"code": "l = []\nfor i in range(4):\n l.append(list(map(int, input().split())))\n\ndef go():\n for i in range(4):\n if l[i][3] and (l[(i + 1) % 4][0] or l[(i + 3) % 4][2] or l[(i + 2) % 4][1] or l[i][0] or l[i][1] or l[i][2]):\n return False\n return True\n\nif go():\n print(\"NO\")\nelse:\n print(\"YES\")\n", "passed": true, "time": 0.19, "memory": 14460.0, "status": "done"}, {"code": "import sys\n\ninput = sys.stdin.readline\n\nroads = []\n\nfor i in range(4):\n roads.append([int(x) for x in input().split()])\n\nclock = {}\ncclock = {}\nopp = {}\n\nclock[0] = 1\nclock[1] = 2\nclock[2] = 3\nclock[3] = 0\n\ncclock[1] = 0\ncclock[2] = 1\ncclock[3] = 2\ncclock[0] = 3\n\nopp[0] = 2\nopp[1] = 3\nopp[2] = 0\nopp[3] = 1\n\nfor i in range(4):\n road = roads[i]\n if road[3] == 1:\n if road[0] == 1 or road[1] == 1 or road[2] == 1:\n print(\"YES\")\n break\n left = roads[cclock[i]]\n right = roads[clock[i]]\n straight = roads[opp[i]]\n if left[2] == 1 or right[0] == 1 or straight[1] == 1:\n print(\"YES\")\n break\nelse:\n print(\"NO\")", "passed": true, "time": 0.18, "memory": 14632.0, "status": "done"}, {"code": "def main():\n l1, s1, r1, p1 = map(int, input().split())\n l2, s2, r2, p2 = map(int, input().split())\n l3, s3, r3, p3 = map(int, input().split())\n l4, s4, r4, p4 = map(int, input().split())\n if p1 == 1:\n if s1 == 1 or l1 == 1 or r1 == 1 or s3 == 1 or l2 == 1 or r4 == 1:\n return \"YES\"\n if p2 == 1:\n if s2 == 1 or l2 == 1 or r2 == 1 or s4 == 1 or l3 == 1 or r1 == 1:\n return \"YES\"\n if p3 == 1:\n if s3 == 1 or l3 == 1 or r3 == 1 or s1 == 1 or l4 == 1 or r2 == 1:\n return \"YES\"\n if p4 == 1:\n if s4 == 1 or l4 == 1 or r4 == 1 or s2 == 1 or l1 == 1 or r3 == 1:\n return \"YES\"\n return \"NO\"\nprint(main())", "passed": true, "time": 0.27, "memory": 14652.0, "status": "done"}, {"code": "L = [list(map(int, input().split())) for _ in range(4)]\nfor i in range(4):\n p = L[i][3]\n if p == 1:\n if i == 0:\n if L[0][0] == 1 or L[0][1] == 1 or L[0][2] == 1 or L[1][0] == 1 or L[2][1] == 1 or L[3][2] == 1:\n print(\"YES\")\n return\n elif i == 1:\n if L[0][2] == 1 or L[1][0] == 1 or L[1][1] == 1 or L[1][2] == 1 or L[2][0] == 1 or L[3][1] == 1:\n print(\"YES\")\n return\n elif i == 2:\n if L[0][1] == 1 or L[1][2] == 1 or L[2][0] == 1 or L[2][1] == 1 or L[2][2] == 1 or L[3][0] == 1:\n print(\"YES\")\n return\n else:\n if L[0][0] == 1 or L[1][1] == 1 or L[2][2] == 1 or L[3][0] == 1 or L[3][1] == 1 or L[3][2] == 1:\n print(\"YES\")\n return\nprint(\"NO\")\n", "passed": true, "time": 0.24, "memory": 14656.0, "status": "done"}, {"code": "def main():\n a = []\n for i in range(4):\n a.append(tuple(map(int, input().split())))\n\n car = [0] * 4\n\n for i, (l, s, r, p) in enumerate(a):\n\n car[i] += l\n car[(i - 1) % 4] += l\n\n car[i] += r\n car[(i + 1) % 4] += r\n\n car[i] += s\n car[(i + 2) % 4] += s\n\n for i in range(4):\n if car[i] > 0 and a[i][3] == 1:\n print(\"YES\")\n return\n\n print(\"NO\")\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.21, "memory": 14404.0, "status": "done"}, {"code": "a = [[int(i) for i in input().split()] for j in range(4)]\n\npesh = [0] * 4\navt = [0] * 4\n\nfor i in range(len(a)):\n if a[i][3]:\n pesh[i] = True\n if a[i][0]:\n avt[(i - 1) % 4] = True\n avt[i] = True\n if a[i][1]:\n avt[(i + 2) % 4] = True\n avt[i] = True\n if a[i][2]:\n avt[(i + 1) % 4] = True\n avt[i] = True\n\nfor i in range(4):\n if avt[i] and pesh[i]:\n print(\"YES\")\n break\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14608.0, "status": "done"}, {"code": "#!/usr/bin/env python3\nimport sys\n\nls = []\nss = []\nrs = []\nps = []\n\nfor __ in range(4):\n l, s, r, p = [int(elem) == 1 for elem in sys.stdin.readline().split()]\n ls.append(l)\n ss.append(s)\n rs.append(r)\n ps.append(p)\n\ndef get(ary, indx):\n return ary[indx % 4]\n\naccident = False\n\nfor indx in range(4):\n accident |= (ls[indx] or rs[indx] or ss[indx]) and ps[indx]\n accident |= ls[indx] and get(ps, indx - 1)\n accident |= ss[indx] and get(ps, indx + 2)\n accident |= rs[indx] and get(ps, indx + 1)\n\nif accident:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14664.0, "status": "done"}, {"code": "L, S, R, P = 0, 1, 2, 3\ntr = []\n\nfor i in range(4):\n\ttr.append([int(x) for x in input().split()])\n\nacc = False\n\nfor i in range(4):\n\t# check l \n\tif tr[i][L] == 1 and (tr[i][P] == 1 or tr[(i+3)%4][P] == 1):\n\t\tacc = True\n\t\tbreak\n\tif tr[i][S] == 1 and (tr[i][P] == 1 or tr[(i+2)%4][P] == 1):\n\t\tacc = True\n\t\tbreak\n\tif tr[i][R] == 1 and (tr[i][P] == 1 or tr[(i+1)%4][P] == 1):\n\t\tacc = True\n\t\tbreak\n\nif acc: print(\"YES\")\nelse: print(\"NO\")", "passed": true, "time": 0.14, "memory": 14532.0, "status": "done"}, {"code": "# 500\n\nS=[]\nfor i in range(0,4):\n S.append([bool(int(x)) for x in input().split()])\ndef check():\n for i in range (0,4):\n for x in range(0,3):\n if S[i][x] and (S[(i+abs(x-3))%4][3] or S[i][3]):\n print(\"YES\")\n return\n\n print(\"NO\")\n\ncheck()\n", "passed": true, "time": 0.24, "memory": 14376.0, "status": "done"}, {"code": "l,s,r,p = list(map(int,input().split()))\nl2,s2,r2,p2 = list(map(int,input().split()))\nl3,s3,r3,p3 = list(map(int,input().split()))\nl4,s4,r4,p4 = list(map(int,input().split()))\nif (l + s + r > 0 and p == 1) or (l2 + s2 + r2 > 0 and p2 == 1) or (l3 + s3 + r3 > 0 and p3 == 1) or (l4 + s4 + r4 > 0 and p4 == 1):\n print(\"YES\")\nelse:\n if(l2 + s3 + r4 > 0 and p == 1) or (l3 + s4 + r > 0 and p2 == 1) or (l4 + s + r2 > 0 and p3 == 1) or (l + s2 + r3 > 0 and p4 == 1):\n print(\"YES\")\n else:\n print(\"NO\")\n", "passed": true, "time": 0.22, "memory": 14400.0, "status": "done"}, {"code": "l = [0] * 4\ns = [0] * 4\nr = [0] * 4\np = [0] * 4\nfor i in range(4):\n l[i], s[i], r[i], p[i] = map(int ,input().split())\nerror = 0\nfor i in range(4):\n if (l[i] + s[i] + r[i] > 0) and (p[i] == 1):\n error += 1\nfor i in range(4):\n j = 0\n if p[j] == 1:\n if (r[j + 3] == 0) and (s[j + 2] == 0) and (l[j + 1] == 0):\n error += 0\n else:\n error += 1\n l.append(l[j])\n l.pop(0)\n s.append(s[j])\n s.pop(0)\n r.append(r[j])\n r.pop(0)\n p.append(p[j])\n p.pop(0)\nif error > 0:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.15, "memory": 14456.0, "status": "done"}, {"code": "S = []\nres = \"NO\"\nfor i in range(4):\n S.append(list(map(int, input().split())))\nfor i in range(4):\n p = sum(S[i]) - S[i][3] + S[(i + 1) % 4][0] + S[(i + 2) % 4][1] + S[(i + 3) % 4][2]\n if p > 0 and S[i][3] == 1:\n res = \"YES\"\n break\nprint(res)", "passed": true, "time": 0.17, "memory": 14620.0, "status": "done"}, {"code": "#A\n\na=input().split()\nb=input().split()\nc=input().split()\nd=input().split()\n\nlights=[a, b, c, d]\n\nfor i in range(0, 4):\n if int(lights[i][3])==1:\n if int(lights[i][0])==1 or int(lights[i][1])==1 or int(lights[i][2])==1:\n print(\"YES\")\n break\n if i==0:\n if int(lights[1][0])==1 or int(lights[2][1])==1 or int(lights[3][2])==1:\n print(\"YES\")\n break\n if i==1:\n if int(lights[2][0])==1 or int(lights[3][1])==1 or int(lights[0][2])==1:\n print(\"YES\")\n break\n if i==2:\n if int(lights[3][0])==1 or int(lights[0][1])==1 or int(lights[1][2])==1:\n print(\"YES\")\n break\n if i==3:\n if int(lights[0][0])==1 or int(lights[1][1])==1 or int(lights[2][2])==1:\n print(\"YES\")\n break\n if i==3:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}, {"code": "actual_vals = [0 for x in range(4)]\nrequired_vals = [1 for x in range(4)]\nl1,s1,r1,p1 = list(map(int,input().split()))\nif(l1==1):\n\trequired_vals[3] = 0\nif(s1==1):\n\trequired_vals[2] = 0\nif(r1==1):\n\trequired_vals[1] = 0\nif(l1==1 or r1==1 or s1==1):\n\trequired_vals[0] = 0\nactual_vals[0] = p1\n\nl2,s2,r2,p2 = list(map(int,input().split()))\nif(l2==1):\n\trequired_vals[0] = 0\nif(s2==1):\n\trequired_vals[3] = 0\nif(r2==1):\n\trequired_vals[2] = 0\nif(l2==1 or r2==1 or s2==1):\n\trequired_vals[1] = 0\nactual_vals[1] = p2\n\nl3,s3,r3,p3 = list(map(int,input().split()))\nif(l3==1):\n\trequired_vals[1] = 0\nif(s3==1):\n\trequired_vals[0] = 0\nif(r3==1):\n\trequired_vals[3] = 0\nif(l3==1 or r3==1 or s3==1):\n\trequired_vals[2] = 0\nactual_vals[2] = p3\n\nl4,s4,r4,p4 = list(map(int,input().split()))\nif(l4==1):\n\trequired_vals[2] = 0\nif(s4==1):\n\trequired_vals[1] = 0\nif(r4==1):\n\trequired_vals[0] = 0\nif(l4==1 or r4==1 or s4==1):\n\trequired_vals[3] = 0\nactual_vals[3] = p4\n\nfor i in range(4):\n\tif(required_vals[i]==0 and actual_vals[i]==1):\n\t\tprint('YES')\n\t\treturn\nprint('NO')\n", "passed": true, "time": 0.15, "memory": 14572.0, "status": "done"}, {"code": "a=[]\nfor i in range(4):\n a.append([int(i) for i in input().split()])\nfor i in range(4):\n if a[i][3]==1:\n if any([a[i][0],a[i][1],a[i][2],a[(i+1)%4][0],a[(i+2)%4][1],a[(i+3)%4][2]]):\n print(\"YES\")\n break\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14476.0, "status": "done"}, {"code": "l1, s1, r1, p1 = list(map(int, input().split()))\nl2, s2, r2, p2 = list(map(int, input().split()))\nl3, s3, r3, p3 = list(map(int, input().split()))\nl4, s4, r4, p4 = list(map(int, input().split()))\n\nif (p1 and (r1 or s1 or l1 or r4 or l2 or s3)) or (p2 and (r2 or s2 or l2 or l3 or r1 or s4)) or \\\n (p3 and (r3 or s3 or l3 or l4 or r2 or s1)) or\\\n (p4 and (r4 or s4 or l4 or l1 or r3 or s2)):\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.14, "memory": 14416.0, "status": "done"}, {"code": "list2=[]\nfor i in range(4):\n list1=list(map(int,input().strip().split(' ')))\n list2.append(list1)\nif list2[0][3]==1:\n if list2[1][0]==1 or list2[2][1]==1 or list2[3][2]==1 or list2[0][1]==1 or list2[0][2]==1 or list2[0][0]==1:\n print(\"YES\")\n return\nif list2[1][3]==1:\n if list2[0][2]==1 or list2[2][0]==1 or list2[3][1]==1 or list2[1][1]==1 or list2[1][2]==1 or list2[1][0]==1:\n print(\"YES\")\n return\nif list2[2][3]==1:\n if list2[0][1]==1 or list2[1][2]==1 or list2[3][0]==1 or list2[2][1]==1 or list2[2][2]==1 or list2[2][0]==1:\n print(\"YES\")\n return\nif list2[3][3]==1:\n if list2[0][0]==1 or list2[1][1]==1 or list2[2][2]==1 or list2[3][1]==1 or list2[3][2]==1 or list2[3][0]==1:\n print(\"YES\")\n return\nprint(\"NO\")", "passed": true, "time": 0.15, "memory": 14492.0, "status": "done"}, {"code": "# left, strait, right, pedastrian\n# 3\n#4 2\n# 1\ndef check_if_safe(curr_part, left_part, right_part, opposite_part):\n curr_left, curr_straight, curr_right, curr_pedastrian = curr_part\n if curr_pedastrian == 0:\n return True\n elif (curr_left + curr_right + curr_straight) > 0:\n return False\n left_left, left_straight, left_right, left_pedastrian = left_part\n if left_right == 1:\n return False\n right_left, right_straight, right_right, right_pedastrian = right_part\n if right_left == 1:\n return False\n opposite_left, opposite_straight, opposite_right, opposite_pedastrian = opposite_part\n if opposite_straight == 1:\n return False\n return True\n\n\npart_one = [int(x) for x in input().split()]\npart_two = [int(x) for x in input().split()]\npart_three = [int(x) for x in input().split()]\npart_four = [int(x) for x in input().split()]\n\nans = ( check_if_safe(part_one, part_four, part_two, part_three)\n + check_if_safe(part_two, part_one, part_three, part_four)\n + check_if_safe(part_three, part_two, part_four, part_one)\n + check_if_safe(part_four, part_three, part_one, part_two)\n )\nif ans != 4:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.14, "memory": 14456.0, "status": "done"}] | [{"input": "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n", "output": "YES\n"}, {"input": "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n", "output": "NO\n"}, {"input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1\n", "output": "NO\n"}, {"input": "1 1 1 0\n0 1 0 1\n1 1 1 0\n1 1 1 1\n", "output": "YES\n"}, {"input": "0 1 1 0\n0 1 0 0\n1 0 0 1\n1 0 0 0\n", "output": "YES\n"}, {"input": "1 0 0 0\n0 1 0 0\n1 1 0 0\n0 1 1 0\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 1 0 1\n1 0 1 1\n1 1 1 0\n", "output": "YES\n"}, {"input": "1 1 0 0\n0 1 0 1\n1 1 1 0\n0 0 1 1\n", "output": "YES\n"}, {"input": "0 1 0 0\n0 0 0 0\n1 0 0 0\n0 0 0 1\n", "output": "NO\n"}, {"input": "0 0 1 0\n0 0 0 0\n1 1 0 0\n0 0 0 1\n", "output": "NO\n"}, {"input": "0 0 1 0\n0 1 0 1\n1 0 1 0\n0 0 1 0\n", "output": "YES\n"}, {"input": "1 1 1 0\n0 1 0 1\n1 1 1 1\n0 0 0 1\n", "output": "YES\n"}, {"input": "0 0 1 0\n0 0 0 0\n0 0 0 1\n0 0 0 1\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 1 0 1\n1 0 1 1\n0 0 0 1\n", "output": "YES\n"}, {"input": "1 1 0 0\n0 1 0 0\n1 1 1 0\n1 0 1 0\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 1\n", "output": "NO\n"}, {"input": "1 0 1 0\n1 1 0 0\n1 1 0 0\n0 0 0 0\n", "output": "NO\n"}, {"input": "0 0 1 0\n1 1 0 0\n1 0 1 0\n1 0 0 0\n", "output": "NO\n"}, {"input": "0 0 1 0\n1 0 0 0\n0 0 0 1\n0 0 0 1\n", "output": "NO\n"}, {"input": "0 1 1 0\n1 1 0 1\n1 0 0 1\n1 1 1 0\n", "output": "YES\n"}, {"input": "1 0 0 0\n1 1 0 0\n1 1 0 1\n0 0 1 0\n", "output": "YES\n"}, {"input": "0 0 0 0\n1 1 0 0\n0 0 0 1\n0 0 1 0\n", "output": "NO\n"}, {"input": "0 1 0 0\n0 0 0 1\n0 1 0 0\n0 0 0 1\n", "output": "NO\n"}, {"input": "0 1 0 0\n1 1 0 1\n1 0 0 1\n1 1 0 1\n", "output": "YES\n"}, {"input": "1 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 1\n1 0 0 0\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 1\n0 1 0 0\n0 0 0 0\n0 0 0 0\n", "output": "NO\n"}, {"input": "0 0 0 1\n0 0 1 0\n0 0 0 0\n0 0 0 0\n", "output": "NO\n"}, {"input": "0 0 0 1\n0 0 0 0\n1 0 0 0\n0 0 0 0\n", "output": "NO\n"}, {"input": "0 0 0 1\n0 0 0 0\n0 1 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 1\n0 0 0 0\n0 0 1 0\n0 0 0 0\n", "output": "NO\n"}, {"input": "0 0 0 1\n0 0 0 0\n0 0 0 0\n1 0 0 0\n", "output": "NO\n"}, {"input": "0 0 0 1\n0 0 0 0\n0 0 0 0\n0 1 0 0\n", "output": "NO\n"}, {"input": "0 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 1 0\n", "output": "YES\n"}, {"input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n0 0 0 0\n", "output": "NO\n"}, {"input": "0 1 0 0\n0 0 0 1\n0 0 0 0\n0 0 0 0\n", "output": "NO\n"}, {"input": "0 0 1 0\n0 0 0 1\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 0\n1 0 0 1\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 1 0 1\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 0 1 1\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 0 0 1\n1 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 0 0 1\n0 1 0 0\n0 0 0 0\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 0 0 1\n0 0 1 0\n0 0 0 0\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 0 0\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 0 0 1\n0 0 0 0\n0 1 0 0\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 0 0 1\n0 0 0 0\n0 0 1 0\n", "output": "NO\n"}, {"input": "1 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0\n", "output": "NO\n"}, {"input": "0 1 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 1 0\n0 0 0 0\n0 0 0 1\n0 0 0 0\n", "output": "NO\n"}, {"input": "0 0 0 0\n1 0 0 0\n0 0 0 1\n0 0 0 0\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 1 0 0\n0 0 0 1\n0 0 0 0\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 0 1 0\n0 0 0 1\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 0 0 0\n1 0 0 1\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 0 0 0\n0 1 0 1\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 0 0 0\n0 0 1 1\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n1 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 1 0 0\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 0 0 0\n0 0 0 1\n0 0 1 0\n", "output": "NO\n"}, {"input": "1 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1\n", "output": "YES\n"}, {"input": "0 1 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1\n", "output": "NO\n"}, {"input": "0 0 1 0\n0 0 0 0\n0 0 0 0\n0 0 0 1\n", "output": "NO\n"}, {"input": "0 0 0 0\n1 0 0 0\n0 0 0 0\n0 0 0 1\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 1 0 0\n0 0 0 0\n0 0 0 1\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 0 1 0\n0 0 0 0\n0 0 0 1\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 0 0 0\n1 0 0 0\n0 0 0 1\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 0 0 0\n0 1 0 0\n0 0 0 1\n", "output": "NO\n"}, {"input": "0 0 0 0\n0 0 0 0\n0 0 1 0\n0 0 0 1\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n1 0 0 1\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 1 0 1\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 1 1\n", "output": "YES\n"}, {"input": "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n", "output": "NO\n"}, {"input": "1 1 1 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n", "output": "YES\n"}, {"input": "1 0 0 0\n0 1 0 0\n0 0 1 0\n0 0 0 1\n", "output": "YES\n"}, {"input": "1 1 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "1 0 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 1 1\n0 0 0 0\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 1\n1 0 0 0\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 1 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 1 1 0\n1 0 1 0\n1 1 1 0\n0 0 0 1\n", "output": "YES\n"}, {"input": "1 1 0 1\n0 0 0 0\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "1 1 1 0\n1 1 1 0\n1 1 1 0\n0 0 0 1\n", "output": "YES\n"}, {"input": "1 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 1\n", "output": "YES\n"}, {"input": "0 0 0 1\n0 0 0 0\n0 1 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 1\n0 0 1 1\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 1\n0 1 1 1\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 1\n0 1 0 1\n0 0 0 0\n0 0 0 0\n", "output": "YES\n"}, {"input": "0 0 0 1\n0 0 0 1\n0 0 0 0\n0 1 0 0\n", "output": "YES\n"}, {"input": "0 0 0 1\n0 0 0 1\n1 0 0 0\n0 0 0 0\n", "output": "YES\n"}] |
|
126 | While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image]
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image]
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
-----Input-----
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
-----Output-----
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
-----Examples-----
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
-----Note-----
You can find the picture clarifying the first sample case in the statement above. | interview | [{"code": "# A\n\ninput()\nl = list(map(int, list(input())))\n\nif (1 in l or 4 in l or 7 in l or 0 in l) and (1 in l or 2 in l or 3 in l) and (3 in l or 6 in l or 9 in l or 0 in l) and (7 in l or 0 in l or 9 in l):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14620.0, "status": "done"}, {"code": "n = int(input())\nnumb = input()\nnum = [0]*10\nfor i in numb:\n num[int(i)] = 1\nans = 0\nif num[1] + num[2] + num[3] > 0:\n ans += 1\nif num[1] + num[4] + num[7] + num[0] > 0:\n ans += 1\nif num[3] + num[6] + num[9] + num[0] > 0:\n ans += 1\nif num[7] + num[0] + num[9] > 0:\n ans += 1\nif ans == 4:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.16, "memory": 14632.0, "status": "done"}, {"code": "n = int(input())\nd = list(map(int,input()))\n\nl = all([i not in d for i in [1,4,7,0]])\nr = all([i not in d for i in [3,6,9,0]])\nu = all([i not in d for i in [1,2,3]])\nd = all([i not in d for i in [7,0,9]])\nprint('NO' if l or r or u or d else 'YES')\n", "passed": true, "time": 0.14, "memory": 14376.0, "status": "done"}, {"code": "n = int(input())\n\nl = [41, 10, 11, 12, 20, 21, 22, 30, 31, 32]\ns = list([l[int(x)] for x in input()])\n\ndef exists_up(s):\n l1 = [x - 10 for x in s]\n return all(x in l for x in l1)\n\ndef exists_down(s):\n l1 = [x + 10 for x in s]\n return all(x in l for x in l1)\n\ndef exists_left(s):\n l1 = [x - 1 for x in s]\n return all(x in l for x in l1)\n\ndef exists_right(s):\n l1 = [x + 1 for x in s]\n return all(x in l for x in l1)\n\nif exists_up(s) or exists_down(s) or exists_left(s) or exists_right(s):\n print(\"NO\")\nelse:\n print(\"YES\")\n", "passed": true, "time": 0.72, "memory": 14512.0, "status": "done"}, {"code": "def main():\n input()\n seq = input()\n\n LEFT = {\n '0': False,\n '1': False,\n '2': True,\n '3': True,\n '4': False,\n '5': True,\n '6': True,\n '7': False,\n '8': True,\n '9': True,\n }\n RIGHT = {\n '0': False,\n '1': True,\n '2': True,\n '3': False,\n '4': True,\n '5': True,\n '6': False,\n '7': True,\n '8': True,\n '9': False,\n }\n UP = {\n '0': True,\n '1': False,\n '2': False,\n '3': False,\n '4': True,\n '5': True,\n '6': True,\n '7': True,\n '8': True,\n '9': True,\n }\n DOWN = {\n '0': False,\n '1': True,\n '2': True,\n '3': True,\n '4': True,\n '5': True,\n '6': True,\n '7': False,\n '8': True,\n '9': False,\n }\n print('NO' if any(all(can[n] for n in seq) for can in (LEFT, RIGHT, UP, DOWN)) else 'YES')\n\n \ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.72, "memory": 14604.0, "status": "done"}, {"code": "n = int(input())\ns = input()\na = [0]*10\nfor i in range(n):\n a[int(s[i])] = 1\n\nif a[1]+a[2]+a[3] == 0 or a[7]+a[9]+a[0] == 0 or a[1]+a[4]+a[7]+a[0] == 0 or a[3] + a[6] + a[9] + a[0] == 0:\n print('NO')\nelse:\n print('YES')\n", "passed": true, "time": 0.16, "memory": 14584.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nhaszero = 0\nfor x in s:\n if(x=='0'):\n haszero = 1\n\nhasup = 0\nhasleft = 0\nhasright = 0\nhasdown = 0\n\nfor x in s:\n if(x=='1')or(x=='2')or(x=='3'):\n hasup = 1\n if(x=='1')or(x=='4')or(x=='7'):\n hasleft = 1\n if(x=='3')or(x=='6')or(x=='9'):\n hasright = 1\n if(x=='7')or(x=='0')or(x=='9'):\n hasdown = 1\n\nif hasup and hasleft and hasright and hasdown:\n print('YES')\nelse:\n if hasup and haszero:\n print('YES')\n else:\n print('NO')", "passed": true, "time": 0.14, "memory": 14412.0, "status": "done"}, {"code": "def Left(a):\n if (a != 1 and a != 4 and a != 7 and a != 0):\n return True\n return False\n\ndef Right(a):\n if (a != 3 and a != 6 and a != 9 and a != 0):\n return True\n return False\n\ndef Up(a):\n if (a != 1 and a != 2 and a != 3):\n return True\n return False\n\ndef Down(a):\n if (a != 7 and a != 9 and a != 0):\n return True\n return False\n\nn = int(input())\nstr1 = input()\n\nu =0\nd=0\nl=0\nr=0\nfor iss in str1:\n i = int(iss)\n if (Up(i)):\n u+=1\n if (Down(i)):\n d += 1\n if (Left(i)):\n l += 1\n if (Right(i)):\n r += 1\n\nif (u == len(str1)\n or d == len(str1)\n or l == len(str1)\n or r == len(str1)):\n print(\"NO\")\nelse:\n print(\"YES\")\n\n\n", "passed": true, "time": 0.16, "memory": 14728.0, "status": "done"}, {"code": "n = int(input())\ns = input().rstrip()\n\ndef canMove(moves, dx, dy):\n\tfor x, y in moves:\n\t\ttx = x + dx\n\t\tty = y + dy\n\t\tif not (0 <= tx < 3 and 0 <= ty < 3):\n\t\t\tif not (tx == 3 and ty == 1):\n\t\t\t\treturn False\n\treturn True\n\n\nl = [\n[\t3, 1,],\n[\t0, 0,],\n[\t0, 1,],\n[\t0, 2,],\n[\t1, 0,],\n[\t1, 1,],\n[\t1, 2,],\n[\t2, 0],\n[\t2, 1,],\n[\t2, 2,],\n]\n\n\nmove = []\nfor x in s:\n\tmove.append(l[int(x)])\n# print(move)\n\ncnt = 0\nfor i in range(10):\n\tfor j in range(10):\n\t\tdx = i - 5\n\t\tdy = j - 5\n\t\tif canMove(move, dx, dy):\n\t\t\tcnt += 1\nif cnt == 1:\n\tprint('YES')\nelse:\n\tprint('NO')\n\n", "passed": true, "time": 0.25, "memory": 14512.0, "status": "done"}, {"code": "def works(numbers):\n if (numbers[1] or numbers[2] or numbers[3]):\n if (numbers[7] or numbers[0] or numbers[9]):\n if (numbers[1] or numbers[4] or numbers[7] or numbers[0]):\n if (numbers[3] or numbers[6] or numbers[9] or numbers[0]):\n return True\n else:\n return False\n else:\n return False\n else:\n return False\n else:\n return False\n\n\nn=int(input())\nline=input()\nnumbers={}\nfor i in range (10):\n numbers[i]=False\nfor ch in line:\n numbers[int(ch)]=True\nif works(numbers):\n print (\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.16, "memory": 14560.0, "status": "done"}, {"code": "n = int(input())\nL = [int(x) for x in input()]\n\nC = [None] * 10\np={}\nfor i in range(1,10):\n C[i] = ((i-1)//3, (i-1)%3)\n p[C[i]] = True\nC[0] = (3, 1)\np[C[0]] = True\ncnt = 0\npossib = []\nq = [(i, j) for i in range(-6, 7) for j in range(-6, 7)]\nfor base in q:\n gone = False\n for num in L:\n diff = C[num]\n nn = (diff[0] + base[0], diff[1] + base[1])\n if nn not in p:\n gone = True\n break\n if not gone:\n possib.append(base)\n cnt += 1\nif cnt == 1:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.25, "memory": 14660.0, "status": "done"}, {"code": "a = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [-1, 0, -1]]\nd = [(3, 1), (0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]\nn = int(input())\nb = list(map(int, list(input())))\nc = []\nfor i in range(n - 1):\n c.append((d[b[i + 1]][0] - d[b[i]][0], d[b[i + 1]][1] - d[b[i]][1]))\nfor i in range(10):\n x, y = d[i][0], d[i][1]\n fl = 1\n for j in c:\n x1, y1 = x + j[0], y + j[1]\n if (x1, y1) not in d:\n fl = 0\n x, y = x1, y1\n if fl and i != b[0]:\n print(\"NO\")\n break\nelse:\n print(\"YES\")\n", "passed": true, "time": 1.18, "memory": 14544.0, "status": "done"}, {"code": "n = int(input())\ns = input()\npr = True\nfor i in range(len(s)):\n if s[i] in '3690':\n pr = False\nvn = True\nfor i in range(len(s)):\n if s[i] in '709':\n vn = False\nle = True\nfor i in range(len(s)):\n if s[i] in '1470':\n le = False\nvv = True\nfor i in range(len(s)):\n if s[i] in '123':\n vv = False\nif (pr or vn or le or vv):\n print('NO')\nelse:\n print('YES')\n", "passed": true, "time": 0.24, "memory": 14564.0, "status": "done"}, {"code": "coords = {0: (1, 0), 1: (0, 3), 2: (1, 3), 3: (2, 3), 4: (0, 2), 5: (1, 2), 6: (2, 2), 7: (0, 1), 8: (1, 1), 9: (2, 1)}\nvalid_coords = set()\nfor elem in coords:\n valid_coords.add(coords[elem])\nn = input()\ns = [int(elem) for elem in input()]\nvectors = []\nfor i in range(len(s) - 1):\n t = [0, 0]\n t[0] = coords[s[i + 1]][0] - coords[s[i]][0]\n t[1] = coords[s[i + 1]][1] - coords[s[i]][1]\n vectors.append(t)\ncnt = 0\nfor elem in coords:\n start = coords[elem]\n faults = 0\n for v in vectors:\n new_start = (start[0] + v[0], start[1] + v[1])\n start = new_start\n if start not in valid_coords:\n faults += 1\n if faults == 0:\n cnt += 1\nif cnt == 1:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.15, "memory": 14588.0, "status": "done"}, {"code": "#! /usr/bin/env python3\n\nimport sys\n\nn = int(input())\ns = list(map(lambda x: int(x) - int('0'), input()))\n\nd = [(1, 3)] + [(i, j) for j in range(3) for i in range(3)]\n\nfor u in range(10):\n if u == s[0]:\n continue\n x, y = d[u]\n for i in range(1, n):\n dx, dy = (d[s[i]][0] - d[s[i - 1]][0], d[s[i]][1] - d[s[i - 1]][1])\n x += dx\n y += dy\n if (x, y) not in d:\n break\n else:\n print(u, file=sys.stderr)\n print('NO')\n return\n\nprint('YES')\n", "passed": true, "time": 0.15, "memory": 14548.0, "status": "done"}, {"code": "p = [[1, 2, 3],\n [4, 5, 6],\n [7, 8, 9],\n [-1, 0, -1]]\n\nn = int(input())\nd = [int(x) for x in input()]\ns = [(i, j) for i in range(4) for j in range(3) if p[i][j] != -1]\nc = [True for _ in s]\nm = {((i+1) % 10): s[i] for i in range(len(s))}\nfor i in range(1, n):\n for j in range(len(s)):\n if not c[j]:\n continue\n try:\n sji = s[j][0] + (m[d[i]][0] - m[d[i-1]][0])\n sjj = s[j][1] + (m[d[i]][1] - m[d[i-1]][1])\n s[j] = (sji, sjj)\n if s[j][0] < 0 or s[j][1] < 0 or p[s[j][0]][s[j][1]] == -1:\n c[j] = False\n except Exception as e:\n c[j] = False\nif sum(c) > 1:\n print(\"NO\")\nelse:\n print(\"YES\")\n", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "\n# (col, row)\nKEYS = {\n 1: (0, 0),\n 2: (1, 0),\n 3: (2, 0),\n 4: (0, 1),\n 5: (1, 1),\n 6: (2, 1),\n 7: (0, 2),\n 8: (1, 2),\n 9: (2, 2),\n 0: (1, 3)\n}\n\nBOARD = set(KEYS.values())\n\nn = int(input())\nnumber = list(map(int, list(input())))\n\n\ndef add_offset(cell, offset):\n return (cell[0] + offset[0], cell[1] + offset[1])\n\nuniq = True\n\nfor posible_starts in BOARD:\n if KEYS[number[0]] != posible_starts:\n all_fit = True\n off = (posible_starts[0] - KEYS[number[0]][0],\n posible_starts[1] - KEYS[number[0]][1])\n for num_part in number:\n if add_offset(KEYS[num_part], off) not in BOARD:\n all_fit = False\n break\n if all_fit:\n uniq = False\n\nif uniq:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14620.0, "status": "done"}, {"code": "import sys\n\ndef canMoveLeft(digit):\n\tindex = [\n\tFalse,\t#0\n\tFalse,\t#1\n\tTrue,\t#2\n\tTrue,\t#3\n\tFalse,\t#4\n\tTrue,\t#5\n\tTrue,\t#6\n\tFalse,\t#7\n\tTrue,\t#8\n\tTrue,\t#9\n\t]\n\treturn index[digit]\n\ndef canMoveRight(digit):\n\tindex = [\n\tFalse,\t#0\n\tTrue,\t#1\n\tTrue,\t#2\n\tFalse,\t#3\n\tTrue,\t#4\n\tTrue,\t#5\n\tFalse,\t#6\n\tTrue,\t#7\n\tTrue,\t#8\n\tFalse,\t#9\n\t]\n\treturn index[digit]\n\ndef canMoveUp(digit):\n\tindex = [\n\tTrue,\t#0\n\tFalse,\t#1\n\tFalse,\t#2\n\tFalse,\t#3\n\tTrue,\t#4\n\tTrue,\t#5\n\tTrue,\t#6\n\tTrue,\t#7\n\tTrue,\t#8\n\tTrue,\t#9\n\t]\n\treturn index[digit]\n\ndef canMoveDown(digit):\n\tindex = [\n\tFalse,\t#0\n\tTrue,\t#1\n\tTrue,\t#2\n\tTrue,\t#3\n\tTrue,\t#4\n\tTrue,\t#5\n\tTrue,\t#6\n\tFalse,\t#7\n\tTrue,\t#8\n\tFalse,\t#9\n\t]\n\treturn index[digit]\n\nn = int(input())\nnumber = [int(i) for i in input()]\n#print(number)\n\nmovedown = [all([ canMoveDown(i) for i in number ]),\n\t\t\tall([ canMoveUp(i) for i in number ]),\n\t\t\tall([ canMoveLeft(i) for i in number ]),\n\t\t\tall([ canMoveRight(i) for i in number ])]\n\nif any(movedown):\n\tprint('NO')\nelse:\n\tprint('YES')\n\n#print(movedown)\n", "passed": true, "time": 0.25, "memory": 14528.0, "status": "done"}, {"code": "import sys\nsp1 = ['1','4','7']\nsp2 = ['1','2','3']\nsp3 = ['3','6','9']\nsp4 = ['7','0','9']\nn = int(input())\ns = input()\nfor i in sp2:\n if i in s:\n if '0' in s:\n print('YES')\n return\n else: \n for j in sp1:\n if j in s:\n for k in sp3:\n if k in s:\n for t in sp4:\n if t in s:\n print('YES')\n return\nelse:\n print('NO')\n", "passed": true, "time": 0.14, "memory": 14416.0, "status": "done"}, {"code": "3\n\nn = int(input())\n\nstr = input()\n\nL = [1, 4, 7]\nR = [3, 6, 9]\nT = [1, 2, 3]\nB = [7, 9]\n\nbl = False\nbr = False\nbt = False\nbb = False\nb0 = False\n\nfor s in str:\n symb = int(s)\n bl = bl or (symb in L)\n br = br or (symb in R)\n bt = bt or (symb in T)\n bb = bb or (symb in B)\n b0 = b0 or (symb == 0)\n\nif (bl and br and bt and bb) or (bt and b0):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14512.0, "status": "done"}, {"code": "input()\na = list(map(int, str(input())))\n\nd = {\n 1: (0, 0),\n 2: (1, 0),\n 3: (2, 0),\n 4: (0, 1),\n 5: (1, 1),\n 6: (2, 1),\n 7: (0, 2),\n 8: (1, 2),\n 9: (2, 2),\n 0: (1, 3)\n}\n\nr = list(map(lambda x: (d[x][0] + 1, d[x][1]), a))\nl = list(map(lambda x: (d[x][0] - 1, d[x][1]), a))\nt = list(map(lambda x: (d[x][0], d[x][1] + 1), a))\nb = list(map(lambda x: (d[x][0], d[x][1] - 1), a))\nrt = list(map(lambda x: (d[x][0] + 1, d[x][1] + 1), a))\nrb = list(map(lambda x: (d[x][0] + 1, d[x][1] - 1), a))\nlt = list(map(lambda x: (d[x][0] - 1, d[x][1] + 1), a))\nlb = list(map(lambda x: (d[x][0] - 1, d[x][1] - 1), a))\n\nif all([x in d.values() for x in r])\\\n or all([x in d.values() for x in l])\\\n or all([x in d.values() for x in t])\\\n or all([x in d.values() for x in b])\\\n or all([x in d.values() for x in rt])\\\n or all([x in d.values() for x in rb]) \\\n or all([x in d.values() for x in lt])\\\n or all([x in d.values() for x in lb]):\n print(\"NO\")\nelse:\n print(\"YES\")", "passed": true, "time": 0.15, "memory": 14708.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nfill = [[False for i in range(3)] for j in range(4)]\nfor i in s:\n if i == \"0\":\n j = 10\n else:\n j = ord(i)-ord('1') #0, 1, 2, 3... 8\n fill[j//3][j%3] = True\n#for i in fill:\n# print(i)\ntop = fill[0][0] or fill[0][1] or fill[0][2]\nbottom = fill[2][0] or fill[3][1] or fill[2][2]\nleft = fill[0][0] or fill[1][0] or fill[2][0]\nright = fill[0][2] or fill[1][2] or fill[2][2]\n#print(left, right, fill[3][1], (not left or not right)and not fill[3][1])\nif ((not left or not right)and not fill[3][1]) or not top or not bottom:\n print(\"NO\")\nelse:\n print(\"YES\")\n", "passed": true, "time": 0.14, "memory": 14428.0, "status": "done"}, {"code": "n = int(input())\n# a, b = map(int, input().split())\nnumber = input()\n\nnumpad = [['1', '2', '3'],\n ['4', '5', '6'],\n ['7', '8', '9'],\n [None, '0', None]]\n\n\ndef get_coordinates(digit):\n if digit in ('1', '2', '3'):\n first_coordinate = 0\n second_coordinate = int(digit) - 1\n elif digit in ('4', '5', '6'):\n first_coordinate = 1\n second_coordinate = int(digit) - 4\n elif digit in ('7', '8', '9'):\n first_coordinate = 2\n second_coordinate = int(digit) - 7\n else:\n first_coordinate = 3\n second_coordinate = 1\n return first_coordinate, second_coordinate\n\n\ndef add(v1, v2):\n return v1[0] + v2[0], v1[1] + v2[1]\n\n\ndef sub(v1, v2):\n return v1[0] - v2[0], v1[1] - v2[1]\n\n\ndef try_it(start_digit, what_to_do):\n current_coordinates = get_coordinates(start_digit)\n for move in what_to_do:\n current_coordinates = add(current_coordinates, move)\n if current_coordinates[0] < 0 or current_coordinates[1] < 0:\n return False\n try:\n _ = numpad[current_coordinates[0]][current_coordinates[1]]\n except IndexError:\n return False\n if _ is None:\n return False\n return True\n\n\nsequence = []\nfor i in range(n - 1):\n sequence.append(sub(get_coordinates(number[i + 1]), get_coordinates(number[i])))\n\nfor digit in set('1234567890') - set(number[0]):\n if try_it(digit, sequence):\n print('NO')\n break\nelse:\n print('YES')\n", "passed": true, "time": 0.15, "memory": 14596.0, "status": "done"}] | [{"input": "3\n586\n", "output": "NO\n"}, {"input": "2\n09\n", "output": "NO\n"}, {"input": "9\n123456789\n", "output": "YES\n"}, {"input": "3\n911\n", "output": "YES\n"}, {"input": "3\n089\n", "output": "NO\n"}, {"input": "3\n159\n", "output": "YES\n"}, {"input": "9\n000000000\n", "output": "NO\n"}, {"input": "4\n0874\n", "output": "NO\n"}, {"input": "6\n235689\n", "output": "NO\n"}, {"input": "2\n10\n", "output": "YES\n"}, {"input": "3\n358\n", "output": "NO\n"}, {"input": "6\n123456\n", "output": "NO\n"}, {"input": "1\n0\n", "output": "NO\n"}, {"input": "4\n0068\n", "output": "NO\n"}, {"input": "6\n021149\n", "output": "YES\n"}, {"input": "5\n04918\n", "output": "YES\n"}, {"input": "2\n05\n", "output": "NO\n"}, {"input": "4\n0585\n", "output": "NO\n"}, {"input": "4\n0755\n", "output": "NO\n"}, {"input": "2\n08\n", "output": "NO\n"}, {"input": "4\n0840\n", "output": "NO\n"}, {"input": "9\n103481226\n", "output": "YES\n"}, {"input": "4\n1468\n", "output": "NO\n"}, {"input": "7\n1588216\n", "output": "NO\n"}, {"input": "9\n188758557\n", "output": "NO\n"}, {"input": "1\n2\n", "output": "NO\n"}, {"input": "2\n22\n", "output": "NO\n"}, {"input": "8\n23482375\n", "output": "YES\n"}, {"input": "9\n246112056\n", "output": "YES\n"}, {"input": "9\n256859223\n", "output": "NO\n"}, {"input": "6\n287245\n", "output": "NO\n"}, {"input": "8\n28959869\n", "output": "NO\n"}, {"input": "9\n289887167\n", "output": "YES\n"}, {"input": "4\n3418\n", "output": "NO\n"}, {"input": "4\n3553\n", "output": "NO\n"}, {"input": "2\n38\n", "output": "NO\n"}, {"input": "6\n386126\n", "output": "NO\n"}, {"input": "6\n392965\n", "output": "NO\n"}, {"input": "1\n4\n", "output": "NO\n"}, {"input": "6\n423463\n", "output": "NO\n"}, {"input": "4\n4256\n", "output": "NO\n"}, {"input": "8\n42937903\n", "output": "YES\n"}, {"input": "1\n5\n", "output": "NO\n"}, {"input": "8\n50725390\n", "output": "YES\n"}, {"input": "9\n515821866\n", "output": "NO\n"}, {"input": "2\n56\n", "output": "NO\n"}, {"input": "2\n57\n", "output": "NO\n"}, {"input": "7\n5740799\n", "output": "NO\n"}, {"input": "9\n582526521\n", "output": "NO\n"}, {"input": "9\n585284126\n", "output": "NO\n"}, {"input": "1\n6\n", "output": "NO\n"}, {"input": "3\n609\n", "output": "NO\n"}, {"input": "2\n63\n", "output": "NO\n"}, {"input": "3\n633\n", "output": "NO\n"}, {"input": "7\n6668940\n", "output": "NO\n"}, {"input": "5\n66883\n", "output": "NO\n"}, {"input": "2\n68\n", "output": "NO\n"}, {"input": "5\n69873\n", "output": "YES\n"}, {"input": "1\n7\n", "output": "NO\n"}, {"input": "4\n7191\n", "output": "YES\n"}, {"input": "9\n722403540\n", "output": "YES\n"}, {"input": "9\n769554547\n", "output": "NO\n"}, {"input": "3\n780\n", "output": "NO\n"}, {"input": "5\n78248\n", "output": "NO\n"}, {"input": "4\n7844\n", "output": "NO\n"}, {"input": "4\n7868\n", "output": "NO\n"}, {"input": "1\n8\n", "output": "NO\n"}, {"input": "6\n817332\n", "output": "YES\n"}, {"input": "7\n8465393\n", "output": "YES\n"}, {"input": "7\n8526828\n", "output": "NO\n"}, {"input": "8\n85812664\n", "output": "NO\n"}, {"input": "8\n93008225\n", "output": "YES\n"}, {"input": "7\n9454566\n", "output": "NO\n"}, {"input": "4\n9625\n", "output": "NO\n"}, {"input": "8\n97862407\n", "output": "YES\n"}, {"input": "3\n993\n", "output": "NO\n"}, {"input": "3\n267\n", "output": "YES\n"}, {"input": "3\n249\n", "output": "YES\n"}, {"input": "3\n672\n", "output": "YES\n"}, {"input": "3\n176\n", "output": "YES\n"}, {"input": "3\n123\n", "output": "NO\n"}, {"input": "3\n367\n", "output": "YES\n"}, {"input": "2\n12\n", "output": "NO\n"}, {"input": "4\n2580\n", "output": "YES\n"}, {"input": "2\n20\n", "output": "YES\n"}, {"input": "3\n492\n", "output": "YES\n"}, {"input": "3\n167\n", "output": "YES\n"}, {"input": "3\n970\n", "output": "NO\n"}, {"input": "3\n460\n", "output": "NO\n"}, {"input": "4\n4268\n", "output": "NO\n"}, {"input": "4\n9394\n", "output": "YES\n"}, {"input": "2\n13\n", "output": "NO\n"}, {"input": "3\n729\n", "output": "YES\n"}] |
|
127 | Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day k_{i} products will be put up for sale and exactly l_{i} clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump.
For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale k_{i} products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·k_{i} products. Consequently, there is an opportunity to sell two times more products on days of sell-out.
Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem.
-----Input-----
The first line contains two integers n and f (1 ≤ n ≤ 10^5, 0 ≤ f ≤ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following n subsequent lines contains two integers k_{i}, l_{i} (0 ≤ k_{i}, l_{i} ≤ 10^9) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day.
-----Output-----
Print a single integer denoting the maximal number of products that shop can sell.
-----Examples-----
Input
4 2
2 1
3 5
2 3
1 5
Output
10
Input
4 1
0 2
0 3
3 5
0 6
Output
5
-----Note-----
In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the second example it is possible to sell 5 products, if you choose third day for sell-out. | interview | [{"code": "from sys import stdin, stdout\nimport math\n\nn, k = map(int, stdin.readline().split())\nvalues = []\nans = 0\n\nfor i in range(n):\n a, b = map(int, stdin.readline().split())\n ans += min(a, b)\n \n if a < b:\n b -= a\n values.append(min(a, b))\n\n\n\nvalues.sort()\nfor v in values[::-1]:\n if not k:\n break\n \n ans += v\n k -= 1\n\n\nstdout.write(str(ans))", "passed": true, "time": 0.16, "memory": 14680.0, "status": "done"}, {"code": "import sys\n\nn, f = list(map(int, sys.stdin.readline().rstrip().split()))\n\nli = []\nli2 = []\nfor i in range(n):\n k, l = list(map(int, sys.stdin.readline().rstrip().split()))\n li.append((k, l))\n\nli = sorted(li, key=lambda x: min(x[0]*2,x[1])-min(x[0],x[1]))\n\nresult = 0\nfor i in range(n):\n if i >= n-f:\n result += min(li[i][0]*2,li[i][1])\n else:\n result += min(li[i][0],li[i][1])\n\n\n\nsys.stdout.write(str(result))\n\n", "passed": true, "time": 0.14, "memory": 14728.0, "status": "done"}] | [{"input": "4 2\n2 1\n3 5\n2 3\n1 5\n", "output": "10"}, {"input": "4 1\n0 2\n0 3\n3 5\n0 6\n", "output": "5"}, {"input": "1 1\n5 8\n", "output": "8"}, {"input": "2 1\n8 12\n6 11\n", "output": "19"}, {"input": "2 1\n6 7\n5 7\n", "output": "13"}, {"input": "2 1\n5 7\n6 7\n", "output": "13"}, {"input": "2 1\n7 8\n3 6\n", "output": "13"}, {"input": "2 1\n9 10\n5 8\n", "output": "17"}, {"input": "2 1\n3 6\n7 8\n", "output": "13"}, {"input": "1 0\n10 20\n", "output": "10"}, {"input": "2 1\n99 100\n3 6\n", "output": "105"}, {"input": "4 2\n2 10\n3 10\n9 9\n5 10\n", "output": "27"}, {"input": "2 1\n3 4\n2 8\n", "output": "7"}, {"input": "50 2\n74 90\n68 33\n49 88\n52 13\n73 21\n77 63\n27 62\n8 52\n60 57\n42 83\n98 15\n79 11\n77 46\n55 91\n72 100\n70 86\n50 51\n57 39\n20 54\n64 95\n66 22\n79 64\n31 28\n11 89\n1 36\n13 4\n75 62\n16 62\n100 35\n43 96\n97 54\n86 33\n62 63\n94 24\n19 6\n20 58\n38 38\n11 76\n70 40\n44 24\n32 96\n28 100\n62 45\n41 68\n90 52\n16 0\n98 32\n81 79\n67 82\n28 2\n", "output": "1889"}, {"input": "2 1\n10 5\n2 4\n", "output": "9"}, {"input": "2 1\n50 51\n30 40\n", "output": "90"}, {"input": "3 2\n5 10\n5 10\n7 9\n", "output": "27"}, {"input": "3 1\n1000 1000\n50 100\n2 2\n", "output": "1102"}, {"input": "2 1\n2 4\n12 12\n", "output": "16"}, {"input": "2 1\n4 4\n1 2\n", "output": "6"}, {"input": "2 1\n4000 4000\n1 2\n", "output": "4002"}, {"input": "2 1\n5 6\n2 4\n", "output": "9"}, {"input": "3 2\n10 10\n10 10\n1 2\n", "output": "22"}, {"input": "10 5\n9 1\n11 1\n12 1\n13 1\n14 1\n2 4\n2 4\n2 4\n2 4\n2 4\n", "output": "25"}, {"input": "2 1\n30 30\n10 20\n", "output": "50"}, {"input": "1 1\n1 1\n", "output": "1"}, {"input": "2 1\n10 2\n2 10\n", "output": "6"}, {"input": "2 1\n4 5\n3 9\n", "output": "10"}, {"input": "2 1\n100 100\n5 10\n", "output": "110"}, {"input": "2 1\n14 28\n15 28\n", "output": "43"}, {"input": "2 1\n100 1\n20 40\n", "output": "41"}, {"input": "2 1\n5 10\n6 10\n", "output": "16"}, {"input": "2 1\n29 30\n10 20\n", "output": "49"}, {"input": "1 0\n12 12\n", "output": "12"}, {"input": "2 1\n7 8\n4 7\n", "output": "14"}, {"input": "2 1\n5 5\n2 4\n", "output": "9"}, {"input": "2 1\n1 2\n228 2\n", "output": "4"}, {"input": "2 1\n5 10\n100 20\n", "output": "30"}, {"input": "2 1\n1000 1001\n2 4\n", "output": "1004"}, {"input": "2 1\n3 9\n7 7\n", "output": "13"}, {"input": "2 0\n1 1\n1 1\n", "output": "2"}, {"input": "4 1\n10 10\n10 10\n10 10\n4 6\n", "output": "36"}, {"input": "18 13\n63 8\n87 100\n18 89\n35 29\n66 81\n27 85\n64 51\n60 52\n32 94\n74 22\n86 31\n43 78\n12 2\n36 2\n67 23\n2 16\n78 71\n34 64\n", "output": "772"}, {"input": "2 1\n10 18\n17 19\n", "output": "35"}, {"input": "3 0\n1 1\n1 1\n1 1\n", "output": "3"}, {"input": "2 1\n4 7\n8 9\n", "output": "15"}, {"input": "4 2\n2 10\n3 10\n9 10\n5 10\n", "output": "27"}, {"input": "2 1\n5 7\n3 6\n", "output": "11"}, {"input": "2 1\n3 4\n12 12\n", "output": "16"}, {"input": "2 1\n10 11\n9 20\n", "output": "28"}, {"input": "2 1\n7 8\n2 4\n", "output": "11"}, {"input": "2 1\n5 10\n7 10\n", "output": "17"}, {"input": "4 2\n2 10\n3 10\n5 10\n9 10\n", "output": "27"}, {"input": "2 1\n99 100\n5 10\n", "output": "109"}, {"input": "4 2\n2 10\n3 10\n5 10\n9 9\n", "output": "27"}, {"input": "2 1\n3 7\n5 7\n", "output": "11"}, {"input": "2 1\n10 10\n3 6\n", "output": "16"}, {"input": "2 1\n100 1\n2 4\n", "output": "5"}, {"input": "5 0\n1 1\n1 1\n1 1\n1 1\n1 1\n", "output": "5"}, {"input": "3 1\n3 7\n4 5\n2 3\n", "output": "12"}, {"input": "2 1\n3 9\n7 8\n", "output": "13"}, {"input": "2 1\n10 2\n3 4\n", "output": "6"}, {"input": "2 1\n40 40\n3 5\n", "output": "45"}, {"input": "2 1\n5 3\n1 2\n", "output": "5"}, {"input": "10 5\n9 5\n10 5\n11 5\n12 5\n13 5\n2 4\n2 4\n2 4\n2 4\n2 4\n", "output": "45"}, {"input": "3 1\n1 5\n1 5\n4 4\n", "output": "7"}, {"input": "4 0\n1 1\n1 1\n1 1\n1 1\n", "output": "4"}, {"input": "4 1\n1000 1001\n1000 1001\n2 4\n1 2\n", "output": "2005"}, {"input": "2 1\n15 30\n50 59\n", "output": "80"}, {"input": "2 1\n8 8\n3 5\n", "output": "13"}, {"input": "2 1\n4 5\n2 5\n", "output": "8"}, {"input": "3 2\n3 3\n1 2\n1 2\n", "output": "7"}, {"input": "3 1\n2 5\n2 5\n4 4\n", "output": "10"}, {"input": "2 1\n3 10\n50 51\n", "output": "56"}, {"input": "4 2\n2 4\n2 4\n9 10\n9 10\n", "output": "26"}, {"input": "2 1\n3 5\n8 8\n", "output": "13"}, {"input": "2 1\n100 150\n70 150\n", "output": "240"}, {"input": "2 1\n4 5\n3 6\n", "output": "10"}, {"input": "2 1\n20 10\n3 5\n", "output": "15"}, {"input": "15 13\n76167099 92301116\n83163126 84046805\n45309500 65037149\n29982002 77381688\n76738161 52935441\n37889502 25466134\n55955619 14197941\n31462620 12999429\n64648384 8824773\n3552934 68992494\n2823376 9338427\n86832070 3763091\n67753633 2162190\n302887 92011825\n84894984 410533\n", "output": "435467000"}, {"input": "2 1\n8 7\n3 6\n", "output": "13"}, {"input": "2 1\n7 8\n3 5\n", "output": "12"}, {"input": "2 1\n10 10\n1 3\n", "output": "12"}, {"input": "2 1\n9 10\n2 4\n", "output": "13"}, {"input": "3 1\n10 11\n12 13\n8 10\n", "output": "32"}, {"input": "2 1\n5 10\n7 7\n", "output": "17"}, {"input": "4 2\n90 91\n2 10\n2 10\n2 10\n", "output": "100"}, {"input": "2 1\n2 4\n4 4\n", "output": "8"}, {"input": "2 1\n2 3\n4 3\n", "output": "6"}, {"input": "2 1\n40 45\n50 52\n", "output": "95"}, {"input": "3 1\n1 4\n2 4\n3 4\n", "output": "8"}, {"input": "2 1\n1 2\n1000 1000\n", "output": "1002"}, {"input": "2 1\n80 100\n70 95\n", "output": "175"}] |
|
128 | It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his k minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute.
Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the k minutes that they have. We denote as p_{i} the label of the cow in the i-th stall. The messiness of an arrangement of cows is defined as the number of pairs (i, j) such that i < j and p_{i} > p_{j}.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100 000) — the number of cows and the length of Farmer John's nap, respectively.
-----Output-----
Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than k swaps.
-----Examples-----
Input
5 2
Output
10
Input
1 10
Output
0
-----Note-----
In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.
In the second sample, there is only one cow, so the maximum possible messiness is 0. | interview | [{"code": "# You lost the game.\nn,k = map(int, input().split())\nr = 0\nfor i in range(min(k,n//2)):\n r += (n-2*i-1) + (n-2*i-2)\nprint(r)", "passed": true, "time": 0.43, "memory": 14532.0, "status": "done"}, {"code": "def main():\n n, k = map(int, input().split())\n if k > (n // 2):\n k = n // 2\n ans = 0\n for i in range(k):\n ans += 2 * (n - 2 * i - 2) + 1\n print(ans)\n \nmain()", "passed": true, "time": 0.34, "memory": 14492.0, "status": "done"}, {"code": "n, k = [int(i) for i in input().split()]\nans = 0\nfor i in range(min(n // 2, k)):\n ans += (n - i * 2 - 2) * 2\n ans += 1\nprint(ans)", "passed": true, "time": 1.61, "memory": 14620.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nn, k = list(map(int, input().split()))\n\nk = min(k, n // 2)\nprint(k * (n - k) + (n - 2 * k) * k + k * (k - 1))\n", "passed": true, "time": 0.15, "memory": 14572.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nk = min(k, n // 2)\nprint((2 * n - 2 * k - 1) * k)\n", "passed": true, "time": 0.16, "memory": 14348.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nif (k > n//2):\n k = n // 2\nif n == 1 or k == 0:\n print(0)\nelse:\n print(k * (2 * n - 2 * k - 1))\n", "passed": true, "time": 0.25, "memory": 14596.0, "status": "done"}, {"code": "n,k=(int(z) for z in input().split())\nif 2*k>=n-1:\n\tprint(n*(n-1)//2)\nelse:\n\tprint(n*(n-1)//2-(n-2*k)*(n-2*k-1)//2)", "passed": true, "time": 0.25, "memory": 14512.0, "status": "done"}, {"code": "import sys\nsys.setrecursionlimit(10000000)\nfrom math import pi\nn, k = map(int, input().split())\nans = 0\nfor i in range(min(n//2, k)):\n ans += (n - 2*i-1) + (n-2*i-2)\nprint(ans)", "passed": true, "time": 0.65, "memory": 14472.0, "status": "done"}, {"code": "#[int(i) for i in input().split()]\nn, k = [int(i) for i in input().split()]\ni = 0\nres = 0\nfor j in range(min(n // 2, k)):\n res += n - j - 1 - j\n res += n - 2 - j - j\nprint(res)\n", "passed": true, "time": 0.4, "memory": 14596.0, "status": "done"}, {"code": "3\n\ndef readln(): return list(map(int, input().split()))\n\ndef main():\n n, k = readln()\n if k >= n // 2:\n print((n - 1) * n // 2)\n else:\n k = n - 2 * k\n print((n - 1) * n // 2 - k * (k - 1) // 2)\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14724.0, "status": "done"}, {"code": "n,k = map(int, input().split())\nper = n*(n-1)//2\nif k >= (n//2):\n print(per)\nelse:\n print(per - ((n-k*2-1) * (n-k*2)//2))", "passed": true, "time": 0.15, "memory": 14644.0, "status": "done"}, {"code": "s = input().split(' ')\nn = int(s[0])\nk = int(s[1])\n\nif(k > n / 2):\n print(n * (n - 1) // 2)\nelse:\n print(2 * k * n - k * (2 * k + 1))", "passed": true, "time": 0.14, "memory": 14500.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nc = [i for i in range(1, n+1)]\nret = 0\nm = n\nfor i in range(min(k, n // 2)):\n ret += m - 1 + m - 2\n m -= 2\nprint(ret)\n", "passed": true, "time": 0.43, "memory": 17464.0, "status": "done"}, {"code": "n, k = map(int, input().split())\n\nresult = 0\ncurVal = n\nfor i in range(k):\n if curVal <= 1:\n break\n result += 2 * curVal - 3\n curVal -= 2\n\nprint(result)", "passed": true, "time": 0.3, "memory": 14592.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\ncnt = 0\nwhile k > 0 and n >= 2:\n cnt += (n - 1) * 2 - 1\n n -= 2\n k -= 1\nprint(cnt)", "passed": true, "time": 0.35, "memory": 14388.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\nans = 0\n\ncur = 1\nleft = n\nwhile k > 0 and cur <= n // 2:\n ans += left + left - 3\n left -= 2\n cur += 1\n k -= 1\n\nprint(ans)\n", "passed": true, "time": 0.38, "memory": 14508.0, "status": "done"}, {"code": "n, k = [int(s) for s in input().split()]\nk = min(n // 2, k)\n\n\nprint((2 * n - 2 * k - 1) * k)\n", "passed": true, "time": 0.15, "memory": 14560.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\na = [0] * (n+1)\nfor i in range(1,n+1):\n a[i] = i\n\nm = min(k, n >> 1)\nfor i in range(1,m+1):\n a[i], a[n-i+1] = a[n-i+1], a[i]\n\nA = (n * (n - 1)) >> 1\nl = n - m - m\nl = (l * (l - 1)) >> 1\nprint(A - l)\n", "passed": true, "time": 0.89, "memory": 17560.0, "status": "done"}, {"code": "import math\ndata = input()\nn, k = data.split(' ')\n\nn = int(n)\nk = int(k)\nm = n\nchaos = 0\nfor i in range(k):\n if i < math.floor(n/2):\n chaos += 2*m - 3\n m -= 2\n else:\n break\nprint(chaos)", "passed": true, "time": 0.41, "memory": 14564.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nif n == 1:\n print(0)\nelse:\n if k >= n // 2:\n print(n*(n-1)//2)\n else:\n s = 0\n for i in range(1, k + 1):\n s += 1 + 2 * (n - 2*i)\n print(s)", "passed": true, "time": 0.22, "memory": 14612.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nn, k = [int(x) for x in input().split()]\n\n# 1 2 3 4 5\n# 5 2 3 4 1\n\nif n == 1:\n print(0)\nelse:\n result = 0\n l = n\n for i in range(0, min(n // 2, k)):\n result += (l - 1) + (l - 2)\n l -= 2\n print(result)\n", "passed": true, "time": 0.31, "memory": 14604.0, "status": "done"}, {"code": "n,k = (int(i) for i in input().split())\nans = 0\nd = n\nfor i in range(min(k,n//2)):\n ans+=(d*2-3)\n d-=2\nprint(ans)", "passed": true, "time": 0.29, "memory": 14620.0, "status": "done"}, {"code": "number, time = map(int, input().split())\nif time >= number // 2:\n ans = (number - 1) * number // 2\nelse:\n ans = (number - 1 + number - time) * time // 2\n count = time\n for i in range(time + 1, number):\n ans += count\n if i >= number - time:\n count -= 1\nprint(ans)", "passed": true, "time": 0.31, "memory": 14512.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nk = min(k, n // 2)\nans = 0\nfor i in range(1, k + 1):\n ans += (n - i)\nt = ans\n\nans += ((n - 2 * k) * k)\n\nprint(ans + (k * (k - 1) // 2))\n", "passed": true, "time": 0.23, "memory": 14540.0, "status": "done"}] | [{"input": "5 2\n", "output": "10\n"}, {"input": "1 10\n", "output": "0\n"}, {"input": "100000 2\n", "output": "399990\n"}, {"input": "1 1\n", "output": "0\n"}, {"input": "8 3\n", "output": "27\n"}, {"input": "7 1\n", "output": "11\n"}, {"input": "100000 40000\n", "output": "4799960000\n"}, {"input": "1 1000\n", "output": "0\n"}, {"input": "100 45\n", "output": "4905\n"}, {"input": "9 2\n", "output": "26\n"}, {"input": "456 78\n", "output": "58890\n"}, {"input": "100000 50000\n", "output": "4999950000\n"}, {"input": "100000 50001\n", "output": "4999950000\n"}, {"input": "100000 50002\n", "output": "4999950000\n"}, {"input": "100000 50003\n", "output": "4999950000\n"}, {"input": "100000 49998\n", "output": "4999949994\n"}, {"input": "100000 49997\n", "output": "4999949985\n"}, {"input": "99999 49998\n", "output": "4999849998\n"}, {"input": "99999 49997\n", "output": "4999849991\n"}, {"input": "99999 49996\n", "output": "4999849980\n"}, {"input": "99999 50000\n", "output": "4999850001\n"}, {"input": "99999 50001\n", "output": "4999850001\n"}, {"input": "99999 50002\n", "output": "4999850001\n"}, {"input": "30062 9\n", "output": "540945\n"}, {"input": "13486 3\n", "output": "80895\n"}, {"input": "29614 7\n", "output": "414491\n"}, {"input": "13038 8\n", "output": "208472\n"}, {"input": "96462 6\n", "output": "1157466\n"}, {"input": "22599 93799\n", "output": "255346101\n"}, {"input": "421 36817\n", "output": "88410\n"}, {"input": "72859 65869\n", "output": "2654180511\n"}, {"input": "37916 5241\n", "output": "342494109\n"}, {"input": "47066 12852\n", "output": "879423804\n"}, {"input": "84032 21951\n", "output": "2725458111\n"}, {"input": "70454 75240\n", "output": "2481847831\n"}, {"input": "86946 63967\n", "output": "3779759985\n"}, {"input": "71128 11076\n", "output": "1330260828\n"}, {"input": "46111 64940\n", "output": "1063089105\n"}, {"input": "46111 64940\n", "output": "1063089105\n"}, {"input": "56500 84184\n", "output": "1596096750\n"}, {"input": "60108 83701\n", "output": "1806455778\n"}, {"input": "1 2\n", "output": "0\n"}, {"input": "1 3\n", "output": "0\n"}, {"input": "1 4\n", "output": "0\n"}, {"input": "1 5\n", "output": "0\n"}, {"input": "1 6\n", "output": "0\n"}, {"input": "2 1\n", "output": "1\n"}, {"input": "2 2\n", "output": "1\n"}, {"input": "2 3\n", "output": "1\n"}, {"input": "2 4\n", "output": "1\n"}, {"input": "2 5\n", "output": "1\n"}, {"input": "3 1\n", "output": "3\n"}, {"input": "3 2\n", "output": "3\n"}, {"input": "3 3\n", "output": "3\n"}, {"input": "3 4\n", "output": "3\n"}, {"input": "3 5\n", "output": "3\n"}, {"input": "4 1\n", "output": "5\n"}, {"input": "4 2\n", "output": "6\n"}, {"input": "4 3\n", "output": "6\n"}, {"input": "4 4\n", "output": "6\n"}, {"input": "4 5\n", "output": "6\n"}, {"input": "5 1\n", "output": "7\n"}, {"input": "5 3\n", "output": "10\n"}, {"input": "5 4\n", "output": "10\n"}, {"input": "5 5\n", "output": "10\n"}, {"input": "6 1\n", "output": "9\n"}, {"input": "6 2\n", "output": "14\n"}, {"input": "6 3\n", "output": "15\n"}, {"input": "7 2\n", "output": "18\n"}, {"input": "7 3\n", "output": "21\n"}, {"input": "7 4\n", "output": "21\n"}, {"input": "10 2\n", "output": "30\n"}, {"input": "60982 2\n", "output": "243918\n"}, {"input": "23426 23\n", "output": "1076515\n"}, {"input": "444 3\n", "output": "2643\n"}, {"input": "18187 433\n", "output": "15374531\n"}, {"input": "6895 3544\n", "output": "23767065\n"}, {"input": "56204 22352\n", "output": "1513297456\n"}, {"input": "41977 5207\n", "output": "382917573\n"}, {"input": "78147 2321\n", "output": "351981971\n"}, {"input": "99742 62198\n", "output": "4974183411\n"}, {"input": "72099 38339\n", "output": "2599096851\n"}, {"input": "82532 4838\n", "output": "751762306\n"}, {"input": "79410 33144\n", "output": "3066847464\n"}, {"input": "11021 3389\n", "output": "51726307\n"}, {"input": "66900 7572\n", "output": "898455660\n"}, {"input": "99999 49999\n", "output": "4999850001\n"}, {"input": "100000 49999\n", "output": "4999949999\n"}, {"input": "100000 100000\n", "output": "4999950000\n"}, {"input": "100000 1\n", "output": "199997\n"}, {"input": "4 100\n", "output": "6\n"}, {"input": "100000 1234\n", "output": "243753254\n"}] |
|
129 | Ivan is collecting coins. There are only $N$ different collectible coins, Ivan has $K$ of them. He will be celebrating his birthday soon, so all his $M$ freinds decided to gift him coins. They all agreed to three terms: Everyone must gift as many coins as others. All coins given to Ivan must be different. Not less than $L$ coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
-----Input-----
The only line of input contains 4 integers $N$, $M$, $K$, $L$ ($1 \le K \le N \le 10^{18}$; $1 \le M, \,\, L \le 10^{18}$) — quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
-----Output-----
Print one number — minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
-----Examples-----
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
-----Note-----
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. | interview | [{"code": "from sys import stdin, stdout\nfrom math import sin, tan, cos\n\nn, m, k, l = map(int, stdin.readline().split())\n\nlb, rb = 0, n // m + 1\nwhile rb - lb > 1:\n mid = (lb + rb) >> 1\n \n if mid * m - k >= l:\n rb = mid\n else:\n lb = mid\n\nif lb != n // m:\n stdout.write(str(rb))\nelse:\n stdout.write('-1')", "passed": true, "time": 0.15, "memory": 14584.0, "status": "done"}] | [{"input": "20 15 2 3\n", "output": "1"}, {"input": "10 11 2 4\n", "output": "-1"}, {"input": "2 1 1 1\n", "output": "2"}, {"input": "10 2 9 7\n", "output": "-1"}, {"input": "530897800469409942 582203276934671957 137373076313041391 377446491430894140\n", "output": "-1"}, {"input": "1000000000000000000 1 1 1000000000000000000\n", "output": "-1"}, {"input": "48295947839584738 12 49503958 47108947578469711\n", "output": "3925745635664473"}, {"input": "100 20 98 2\n", "output": "5"}, {"input": "1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000\n", "output": "-1"}, {"input": "100 100 1 1\n", "output": "1"}, {"input": "1847865 4577 9483 478\n", "output": "3"}, {"input": "100 20 98 1\n", "output": "5"}, {"input": "100 20 98 3\n", "output": "-1"}, {"input": "765492670657661908 120898708872120733 441256691517467806 47990392299392923\n", "output": "5"}, {"input": "213010000114902384 512822228505417058 119707578037963386 328177470098391815\n", "output": "-1"}, {"input": "596503389699530515 914343495357891807 130250515210162891 644804913475506893\n", "output": "-1"}, {"input": "63890874321754343 897803536671470111 34570989234398115 10108894437967468\n", "output": "-1"}, {"input": "472139220663336814 338152858568948777 71689560172156215 572945143351096534\n", "output": "-1"}, {"input": "778131271313761135 29162283248225583 355425770702597603 716328407201370097\n", "output": "-1"}, {"input": "100000000000067841 932 9842 64\n", "output": "11"}, {"input": "800000030000007009 78 53784432543372 5435578332346625\n", "output": "70376445703718"}, {"input": "990754991918791804 172731536557340966 872344445472278981 798534984920208868\n", "output": "-1"}, {"input": "778957518786811855 571857503518586907 769096994987230500 32325604610793188\n", "output": "-1"}, {"input": "695046328995629472 971547627530533122 523943811516500483 107182605463941115\n", "output": "-1"}, {"input": "80030159858197311 792835026333624499 74094987869466717 865812863350994075\n", "output": "-1"}, {"input": "7 4 1 6\n", "output": "-1"}, {"input": "99 5 98 1\n", "output": "-1"}, {"input": "99999999994444488 3 77777777777777777 8888888888888888\n", "output": "28888888888888889"}, {"input": "10 6 3 7\n", "output": "-1"}, {"input": "4 4 2 2\n", "output": "1"}, {"input": "20 15 10 10\n", "output": "-1"}, {"input": "20 15 20 3\n", "output": "-1"}, {"input": "50 9 20 30\n", "output": "-1"}, {"input": "1000000000000000 1000000000000000 1 1\n", "output": "1"}, {"input": "19366 12326 871 14611\n", "output": "-1"}, {"input": "20 3 10 10\n", "output": "-1"}, {"input": "20 15 6 10\n", "output": "-1"}, {"input": "5 2 2 3\n", "output": "-1"}, {"input": "26255 5436 5959 18019\n", "output": "-1"}, {"input": "1000000000000000000 1000000000000 1000000000001 1000000000000\n", "output": "3"}, {"input": "5 3 2 1\n", "output": "1"}, {"input": "20 6 19 1\n", "output": "-1"}, {"input": "10 9 6 4\n", "output": "-1"}, {"input": "5 4 3 2\n", "output": "-1"}, {"input": "1 1 1 1\n", "output": "-1"}, {"input": "7 4 1 4\n", "output": "-1"}, {"input": "7 3 6 1\n", "output": "-1"}, {"input": "10 9 2 8\n", "output": "-1"}, {"input": "5 2 1 4\n", "output": "-1"}, {"input": "100000000000000000 99999999999999 99999999999999 9999\n", "output": "2"}, {"input": "20 2 20 5\n", "output": "-1"}, {"input": "10 6 4 3\n", "output": "-1"}, {"input": "3 2 1 2\n", "output": "-1"}, {"input": "10 3 2 8\n", "output": "-1"}, {"input": "1000000000000000000 1 1 999999999999999999\n", "output": "1000000000000000000"}, {"input": "1000000000000000000 2 1000000000000000 4\n", "output": "500000000000002"}, {"input": "9 5 2 6\n", "output": "-1"}, {"input": "15 9 9 1\n", "output": "-1"}, {"input": "20 12 7 6\n", "output": "-1"}, {"input": "7 4 4 3\n", "output": "-1"}, {"input": "21 10 5 16\n", "output": "-1"}, {"input": "12 7 6 6\n", "output": "-1"}, {"input": "3 3 1 1\n", "output": "1"}, {"input": "15 10 7 5\n", "output": "-1"}, {"input": "20 11 1 13\n", "output": "-1"}, {"input": "10 3 7 3\n", "output": "-1"}, {"input": "10 9 7 3\n", "output": "-1"}, {"input": "5 3 2 2\n", "output": "-1"}, {"input": "12 5 3 9\n", "output": "-1"}, {"input": "11 3 9 1\n", "output": "-1"}, {"input": "19 5 12 5\n", "output": "-1"}, {"input": "100 21 1 98\n", "output": "-1"}, {"input": "25 15 22 2\n", "output": "-1"}, {"input": "12 7 4 6\n", "output": "-1"}, {"input": "12 3 12 1\n", "output": "-1"}, {"input": "18 10 4 8\n", "output": "-1"}, {"input": "100 3 1 99\n", "output": "-1"}, {"input": "7 4 3 2\n", "output": "-1"}, {"input": "17 7 1 15\n", "output": "-1"}, {"input": "16 14 7 6\n", "output": "1"}, {"input": "9 7 2 7\n", "output": "-1"}, {"input": "1000000000000000 1 1000000000000000 1\n", "output": "-1"}, {"input": "9 4 3 4\n", "output": "2"}, {"input": "30 29 15 15\n", "output": "-1"}, {"input": "10 3 9 1\n", "output": "-1"}, {"input": "20 11 10 2\n", "output": "-1"}, {"input": "29 15 5 13\n", "output": "-1"}, {"input": "10 7 6 3\n", "output": "-1"}, {"input": "4 2 1 2\n", "output": "2"}, {"input": "7 2 5 2\n", "output": "-1"}, {"input": "1000000000000000000 1 100000000000000000 200000000000000000\n", "output": "300000000000000000"}] |
|
130 | Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
-----Output-----
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
-----Examples-----
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
-----Note-----
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black. | interview | [{"code": "h, w = map(int, input().split())\nx0, y0, x1, y1, c = 1000, 1000, -1, -1, 0\nfor i in range(h):\n row = str(input())\n for j in range(w):\n if row[j] == 'B':\n x0, y0, x1, y1, c = min(x0, i), min(y0, j), max(x1, i), max(y1, j), c + 1\nln = max(x1 - x0 + 1, y1 - y0 + 1)\nif ln > min(h, w):\n print(-1)\nelif x1 == -1:\n print(1)\nelse:\n print(ln * ln - c)", "passed": true, "time": 0.14, "memory": 14580.0, "status": "done"}, {"code": "n,m=list(map(int,input().split()))\nblacksX,blacksY=[],[]\ncount=0\nfor x in range(n):\n inp=input()\n for y in range(m):\n if inp[y]=='B':\n blacksX.append(x)\n blacksY.append(y)\n count+=1\nif len(blacksX)==0:\n print(1)\nelse:\n side=max(max(blacksX)-min(blacksX)+1,max(blacksY)-min(blacksY)+1)\n if side <=n and side <= m:\n print(side*side-count)\n else:\n print(-1)\n", "passed": true, "time": 0.15, "memory": 14620.0, "status": "done"}, {"code": "def list_input():\n return list(map(int,input().split()))\ndef map_input():\n return list(map(int,input().split()))\ndef map_string():\n return input().split()\n \nn,m = map_input()\ncnt = 0\nupp = n+1\nlow = -1\nleft = -1\nright = m+1\nfor i in range(n):\n a = list(input())\n cnt += a.count('B')\n for j in range(m):\n if a[j] == 'B':\n upp = min(upp,i)\n low = max(low,i)\n left = max(left,j)\n right = min(right,j)\nx = abs(upp-low)+1 \ny = abs(right-left)+1\ns = max(x,y)\n# print(upp,low,left,right)\nif cnt == 0:\n print(1)\nelif s > n or s > m:\n print(-1)\nelse:\n print((s*s)-cnt)\n \n", "passed": true, "time": 0.21, "memory": 14444.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nour = [input() for i in range(n)]\nfirst = -1\nfor i in range(n):\n if 'B' in our[i]:\n first = i\n break\nlast = -1\nfor i in range(n- 1, -1, -1):\n if 'B' in our[i]:\n last = i\n break \nif first == -1:\n print(1)\nelse:\n f2 = -1\n l2 = -1\n for i in range(m):\n a = [our[j][i] for j in range(n)]\n if 'B' in a:\n f2 = i\n break\n for i in range(m - 1, -1, -1):\n a = [our[j][i] for j in range(n)]\n if 'B' in a:\n l2 = i\n break \n if last - first + 1 > m or l2 - f2 + 1 > n:\n print(-1)\n else:\n res = 0\n for i in range(first, last + 1):\n for j in range(f2, l2 + 1):\n if our[i][j] == 'W':\n res += 1\n res += max(last - first + 1, l2 - f2 + 1) ** 2 - (last - first + 1) * (l2 - f2 + 1)\n print(res)", "passed": true, "time": 0.14, "memory": 14664.0, "status": "done"}, {"code": "inp = input()\nn, m = inp.split()\nn = int(n)\nm = int(m)\ngrid = []\ntop = n\nbtm = 0\nlft = m\nrht = 0\nallBlackCount = 0\n\nfor i in range(0,n):\n inp = input()\n grid.append(inp)\n \nfor i in range(0, n):\n for j in range(0, m):\n if grid[i][j] == 'B':\n top = min(top, i)\n btm = max(btm, i)\n lft = min(lft, j)\n rht = max(rht, j)\n allBlackCount += 1\n\n# print(top,lft)\n# print(btm,rht)\n\nh = btm-top+1\nw = rht-lft+1\nsz = max(h, w)\n\nif allBlackCount == 0:\n print(1)\nelif sz > n or sz > m:\n print(-1)\nelse:\n print(sz*sz-allBlackCount)", "passed": true, "time": 0.15, "memory": 14512.0, "status": "done"}, {"code": "n,m=map(int,input().split())\ns=[list(input()) for _ in range(n)]\nu,d,l,r=11**11,0,11**11,0\nfor i in range(n):\n for j in range(m):\n if s[i][j]=='B':\n if i<u:\n u=i\n if i>d:\n d=i\n if j<l:\n l=j\n if j>r:\n r=j\nif r-l>=n or d-u>=m:\n print(-1)\nelif u==11**11 and d==0 and l==11**11 and r==0:\n print(1)\nelse:\n ans=0\n for i in range(u,d+1):\n for j in range(l,r+1):\n if s[i][j]=='W':\n ans+=1\n print(ans+((max(r-l+1,d-u+1)-min(r-l+1,d-u+1))*(max(r-l+1,d-u+1))))", "passed": true, "time": 0.15, "memory": 14600.0, "status": "done"}, {"code": "import sys\n\ndef main():\n n,m = list(map(int,sys.stdin.readline().split()))\n x=[]\n for i in range(n):\n x.append(sys.stdin.readline().rstrip())\n\n y = [-1,-1,-1,-1]\n\n for i in range(n):\n for j in range(m):\n if x[i][j]=='B':\n if y[0]==-1:\n y[0]=i\n y[1]=max(y[1],j)\n y[2] = max(y[2],i)\n if y[3]!=-1:\n y[3] = min(y[3],j)\n else:\n y[3] = j\n\n if y[0] == -1 and y[1] == -1 and y[2] == -1 and y[3] == -1:\n print(1)\n return \n\n q = max(y[1]-y[3]+1, y[2]-y[0]+1)\n if q > m or q>n:\n print(-1)\n return\n\n ans = 0\n for i in range(y[0],y[2]+1):\n for j in range(y[3],y[1]+1):\n if x[i][j]=='W':\n ans+=1\n\n ans+= q*(q - (y[2]-y[0]+1)) + q*(q - (y[1]-y[3]+1)) \n print(ans)\n\n \nmain()\n", "passed": true, "time": 0.15, "memory": 14572.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nnn0 = n\nnn1 = -1\nmm0 = m\nmm1 = -1\ncnt = 0\n\nfor i in range(n):\n s = input().strip()\n if \"B\" in s:\n nn0 = min(i, nn0)\n nn1 = max(i, nn1)\n mm0 = min(s.index(\"B\"), mm0)\n mm1 = max(s.rindex(\"B\"), mm1)\n cnt += sum([z == \"B\" for z in s])\nif nn1 < 0:\n print(1)\nelse:\n z = max(nn1-nn0, mm1-mm0) + 1 \n if z <= min(m,n):\n print(z*z - cnt)\n else: \n print(-1)\n", "passed": true, "time": 0.14, "memory": 14448.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nfield = [input() for _ in range(n)]\nblack = 0\nminheight = minwidth = 101\nmaxheight = maxwidth = 0\nfor i in range(n):\n s = field[i]\n for j in range(m):\n if s[j] == 'B':\n black += 1\n minheight = min(i, minheight)\n maxheight = max(i, maxheight)\n minwidth = min(j, minwidth)\n maxwidth = max(j, maxwidth)\nif black == 0:\n print(1)\nelse:\n a = maxwidth - minwidth + 1\n b = maxheight - minheight + 1\n c = max(a, b)\n des = c * c\n if des > n * m or c > n or c > m:\n print(-1)\n else:\n print(des - black)", "passed": true, "time": 0.15, "memory": 14660.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nsq = [list(input()) for _ in range(n)]\n\nrmin = n\nrmax = 0\ncmin = m\ncmax = 0\ncnt = 0\nfor r in range(n):\n for c in range(m):\n if sq[r][c] == 'B':\n cnt += 1\n rmin = min(rmin, r)\n rmax = max(rmax, r)\n cmin = min(cmin, c)\n cmax = max(cmax, c)\n\nl = max(max(rmax - rmin + 1, cmax - cmin + 1), 1)\nif min(n, m) < l:\n ans = -1\nelse:\n ans = l * l - cnt\nprint(ans)\n\n\n", "passed": true, "time": 0.14, "memory": 14564.0, "status": "done"}, {"code": "n,m = list(map(int,input().split()))\nl = []\nup = -1\ndown = -1\nleft = -1\nright = -1\ncout = 0\nfor i in range(n):\n s = input()\n for j in range(m):\n if s[j] == 'B':\n cout += 1\n if up == -1:\n up = i\n down = i\n left = j\n right = j\n else:\n down = i\n left = min(j,left)\n right = max(j,right)\n \n\nside =max(down-up,right-left)+1\nif side == 0:\n side = 1\nif side > n or side > m:\n print(-1)\nelse:\n print(side**2-cout)\n", "passed": true, "time": 0.23, "memory": 14540.0, "status": "done"}, {"code": "n,m = list(map(int,input().split()))\narr = [0]*(n+1)\nfor i in range(n):\n arr[i] = input()\ncntb = 0\nmn = 200\nmx = 0\nfor i in range(n):\n first = True\n for j in range(m):\n if arr[i][j]=='B':\n cntb += 1\n if first:\n mn = min(mn,j)\n mx = max(mx,j)\n first = False\n else:\n mx = max(mx,j)\nmn2 = 200\nmx2 = 0\nif cntb==0:\n print(1)\n return\nelif cntb==1:\n print(0)\n return\nfor i in range(m):\n first = True\n for j in range(n):\n if arr[j][i]=='B':\n if first:\n mn2 = min(mn2,j)\n mx2 = max(mx2,j)\n first = False\n else:\n mx2 = max(mx2,j)\nval = max(mx-mn+1,mx2-mn2+1)\nif val>m or val>n:\n print(-1)\n return\nprint(val*val-cntb)\n", "passed": true, "time": 0.15, "memory": 14416.0, "status": "done"}, {"code": "q,w=list(map(int,input().split()))\nz,x,c,v=-1,-1,-1,-1\na=[]\ns=0\nfor i in range(0,q):\n e=input()\n if e.count('B')!=0:\n s+=e.count('B')\n n=e.find('B')\n m=e.rfind('B')\n if c==-1:\n c=i\n v=i\n if z==-1:\n z=n\n else:\n z=min(z,n)\n x=max(x,m)\n a.append(e)\nz,x=x-z+1,v-c+1\nif max(z,x)>min(q,w):\n print(-1)\nelif x*z==0:\n print(1)\nelse:\n print(max(z,x)**2-s)\n", "passed": true, "time": 0.14, "memory": 14648.0, "status": "done"}, {"code": "n, m = [int(x) for x in input().split()]\n\narr = []\n\nx1, x2, y1, y2 = 101, -1, 101, -1\n\nfor i in range(n):\n arr.append(input().rstrip())\nc1 = 0\nfor i in range(n):\n for j in range(m):\n if arr[i][j] == \"B\":\n x1 = min(x1, j)\n x2 = max(x2, j)\n y1 = min(y1, i)\n y2 = max(y2, i)\n c1 = 1\n\n#print(x1, x2, y1, y2)\n\ncount = 0\n\nfor j in range(x1, x2 + 1):\n for i in range(y1, y2 + 1):\n if arr[i][j] == \"W\":\n count += 1\n\nsizeX = x2 - x1 + 1\nsizeY = y2 - y1 + 1\nif not c1:\n print(1)\nelif sizeX > sizeY:\n if sizeX > n:\n print(-1)\n else:\n print(count + sizeX * (sizeX - sizeY))\nelif sizeY > sizeX:\n if sizeY > m:\n print(-1)\n else:\n print(count + sizeY * (sizeY - sizeX))\nelse:\n print(count)\n", "passed": true, "time": 0.24, "memory": 14416.0, "status": "done"}, {"code": "n, m = map(int, input().split())\npole = list()\nmin_i, min_j, max_i, max_j = n, m, -1, -1\ncount_B = 0\n\nfor i in range(n):\n pole += [input()]\n for j in range(m):\n t = pole[i][j]\n if t == 'B':\n count_B += 1\n min_i, min_j, max_i, max_j = min(i, min_i), min(j, min_j), max(i, max_i), max(j, max_j)\n\nd_i, d_j = max_i - min_i, max_j - min_j\nside = max(d_i + 1, d_j + 1)\n\nprint(1) if count_B == 0 else print(side ** 2 - count_B) if side <= min(n, m) else print(-1)\n", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "n,m=list(map(int,input().split()))\nls=[]\nfor i in range(n):\n l=list(str(input()))\n ls.append(l)\nminr=1000\nmaxr=-1\nminc=1000\nmaxc=-1\nc=0\nfor i in range(n):\n for j in range(m):\n if ls[i][j]=='B':\n c+=1\n if minr>i:\n minr=i\n if maxr<i:\n maxr=i\n if minc>j:\n minc=j\n if maxc<j:\n maxc=j\nif c==0:\n print(1)\n return\nelif c==1:\n print(0)\n return\nelse:\n a=max(maxr-minr+1,maxc-minc+1)\n if a>m or a>n:\n print(-1)\n return\n else:\n print(a*a-c)\n return\n", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nL = [input() for _ in range(n)]\nC = [[0 for _ in range(m)] for _ in range(n)]\nx1, y1 = 500, 500\nx2, y2 = -1, -1\nfor i in range(n):\n sa = 0\n for j in range(m):\n if L[i][j] == 'B':\n x1 = min(i, x1)\n x2 = max(i, x2)\n y1 = min(j, y1)\n y2 = max(j, y2)\n sa += 1\n if i > 0:\n C[i][j] += C[i-1][j]\n C[i][j] += sa\nif x2 == -1:\n print(1)\nelse:\n a = max(x2-x1, y2-y1)\n ans = 1000000\n for i in range(n):\n for j in range(m):\n if i + a < n and j + a < m and i <= x1 and x2 <= i + a and j <= y1 and y2 <= j + a:\n s = C[i+a][j+a]\n if i > 0:\n s -= C[i-1][j]\n if j > 0:\n s -= C[i][j-1]\n if i > 0 and j > 0:\n s -= C[i-1][j-1]\n ans = min((a+1)*(a+1) - s, ans)\n if ans == 1000000:\n ans = -1\n print(ans)\n\n", "passed": true, "time": 0.15, "memory": 14696.0, "status": "done"}, {"code": "s = input().split(' ')\nn = int(s[0])\nm = int(s[1])\nans = -1\nup = n\ndown = 0\nleft = m\nright = 0\nhave = 0\nfor i in range(n):\n s = input()\n for j in range(m):\n if s[j] == 'B':\n have += 1\n up = min(up,i)\n down = max(down,i)\n left = min(left,j)\n right = max(right,j)\n\nif have == 0:\n print(1)\nelse:\n if up <= down and left <= right:\n l = max(down - up + 1,right - left + 1)\n if l<= min(n,m):\n print(l*l - have)\n else:\n print(-1)\n", "passed": true, "time": 0.16, "memory": 14492.0, "status": "done"}, {"code": "def min_squares(canvas, length, width):\n def find_top():\n for i in range(length):\n for j in range(width):\n if canvas[i][j] == \"B\":\n return i\n return -1\n\n def find_left():\n for j in range(width):\n for i in range(length):\n if canvas[i][j] == \"B\":\n return j\n\n def find_bottom():\n for i in reversed(list(range(length))):\n for j in range(width):\n if canvas[i][j] == \"B\":\n return i\n\n def find_right():\n for j in reversed(list(range(width))):\n for i in range(length):\n if canvas[i][j] == \"B\":\n return j\n\n t = find_top()\n if t == -1:\n return 1\n l = find_left()\n b = find_bottom()\n r = find_right()\n\n # print(t, l, b, r)\n painted = 0\n for i in range(t, b + 1):\n for j in range(l, r + 1):\n if canvas[i][j] == \"W\":\n painted += 1\n\n while(b - t < r - l):\n if t > 0:\n t -= 1\n painted += r - l + 1\n elif b < length - 1:\n b += 1\n painted += r - l + 1\n else:\n return -1\n\n while(r - l < b - t):\n if l > 0:\n l -= 1\n painted += b - t + 1\n elif r < width - 1:\n r += 1\n painted += b - t + 1\n else:\n return -1\n\n return painted\n\n\ndef __starting_point():\n l, w = list(map(int, input().split()))\n canvas = []\n for _ in range(l):\n canvas.append(input())\n print(min_squares(canvas, l, w))\n\n__starting_point()", "passed": true, "time": 0.25, "memory": 14708.0, "status": "done"}, {"code": "n, m = [int(s) for s in input().split()]\ng = [[0 for i in range(m)] for j in range(n)]\nsum = 0\ntop = n-1\nbottom = 0\nleft = m-1\nright = 0\nfor i in range(n):\n f = str(input())\n for j in range(m):\n if f[j] == 'B':\n sum += 1\n top = min(top, i)\n bottom = max(bottom, i)\n left = min(left, j)\n right = max(right, j)\nif sum == 0:\n print(1)\nelse:\n a = max(right - left + 1, bottom - top + 1)\n if a>n or a>m:\n print(-1)\n else:\n print(a**2 - sum)\n", "passed": true, "time": 0.15, "memory": 14612.0, "status": "done"}, {"code": "def polycarp(n, m, l):\n left = min(l).find(\"B\")\n if left == -1:\n return 1\n right = m - min([x[::-1] for x in l]).find(\"B\") - 1\n top = bottom = -1\n for i in range(n):\n if l[i].find(\"B\") != -1:\n top = i\n break\n for i in range(n - 1, -1, -1):\n if l[i].find(\"B\") != -1:\n bottom = i\n break\n w = right - left + 1\n h = bottom - top + 1\n if w > n or h > m:\n return -1\n r = 0\n for i in range(top, bottom + 1):\n for j in range(left, right + 1):\n if l[i][j] == \"W\":\n r += 1\n if w > h:\n r += (w - h) * w\n else:\n r += (h - w) * h\n return r\n\n\nn, m = list(map(int, input().strip().split()))\nl = list()\nfor i in range(n):\n l.append(input().strip())\nprint(polycarp(n, m, l))", "passed": true, "time": 0.14, "memory": 14572.0, "status": "done"}, {"code": "n, m = list(map(int,input().split()))\nq = [str(input()) for i in range(n)]\nk=0\nt=True\nu=0\nli=vi=n*m\npi=ni=0\nfor i in range(n):\n t=False\n u=0\n for j in q[i]:\n if j=='B':\n if u<li:\n li=u\n if u>pi:\n pi=u\n if i<vi:\n vi=i\n if i>ni:\n ni=i\n k+=1\n u+=1\nif (max(ni-vi, pi-li)+1)>n or (max(ni-vi, pi-li)+1)>m:\n print(-1)\nelif k==0:\n print(1)\nelse:\n print((max(ni-vi, pi-li)+1)**2-k)\n", "passed": true, "time": 0.14, "memory": 14448.0, "status": "done"}, {"code": "def __starting_point():\n n, m = list(map(int, input().split()))\n matrix = list()\n minR = n; minC = m; maxR=maxC=0\n count = 0\n for i in range(n):\n s = input()\n for j in range(m):\n if s[j] == 'B':\n minR = min(minR, i)\n maxR = max(maxR, i)\n minC = min(minC, j)\n maxC = max(maxC, j)\n count += 1\n edge = max(maxR-minR+1, maxC-minC+1)\n if count == 0:\n print(1)\n elif edge > n or edge > m:\n print(-1)\n else:\n print(edge*edge-count)\n \n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14448.0, "status": "done"}, {"code": "n,k=list(map(int,input().split(' ')))\nb=[]\nr=[]\nc=[]\n\nfor i in range (n):\n b.append(input())\nfor i in range(n):\n for j in range(k):\n if b[i][j]=='B':\n \n r.append(i)\n c.append(j)\n\nif len(c)==0:\n print(1)\nelse:\n maxr=max(r)-min(r)\n maxc=max(c)-min(c)\n size=max(maxc,maxr)+1\n if (size>n or size>k):\n print(-1)\n else:\n print(size**2-len(c))\n \n", "passed": true, "time": 0.15, "memory": 14552.0, "status": "done"}] | [{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n", "output": "5\n"}, {"input": "1 2\nBB\n", "output": "-1\n"}, {"input": "3 3\nWWW\nWWW\nWWW\n", "output": "1\n"}, {"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\n", "output": "-1\n"}, {"input": "1 1\nW\n", "output": "1\n"}, {"input": "2 4\nWWWW\nWBWW\n", "output": "0\n"}, {"input": "4 5\nWWWWW\nBBWWW\nBBWWW\nWWWWW\n", "output": "0\n"}, {"input": "5 4\nWWWW\nWWWW\nWWWB\nWWWW\nWWWW\n", "output": "0\n"}, {"input": "10 5\nWWWWB\nWWWWW\nWWWBB\nWWBWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\n", "output": "12\n"}, {"input": "5 10\nWWWWWWWWWW\nWWWWBWBBWW\nWWWWWWWWWW\nWWWWBWWWWW\nWWWWWWBWWW\n", "output": "11\n"}, {"input": "20 10\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWBBWBWWWW\nWWBWWBWWWW\nWWWWBWWWWW\nWWWWBWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\n", "output": "9\n"}, {"input": "10 20\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWBW\nWWWWWWWWWWWWWWWWWBWW\nWWWWWWWWWWWWWWWWWWWW\n", "output": "2\n"}, {"input": "1 1\nW\n", "output": "1\n"}, {"input": "1 1\nB\n", "output": "0\n"}, {"input": "2 2\nWW\nWW\n", "output": "1\n"}, {"input": "2 2\nWW\nWB\n", "output": "0\n"}, {"input": "2 2\nWW\nBW\n", "output": "0\n"}, {"input": "2 2\nWW\nBB\n", "output": "2\n"}, {"input": "2 2\nWB\nWW\n", "output": "0\n"}, {"input": "2 2\nWB\nWB\n", "output": "2\n"}, {"input": "2 2\nWB\nBW\n", "output": "2\n"}, {"input": "2 2\nWB\nBB\n", "output": "1\n"}, {"input": "2 2\nBW\nWW\n", "output": "0\n"}, {"input": "2 2\nBW\nWB\n", "output": "2\n"}, {"input": "2 2\nBW\nBW\n", "output": "2\n"}, {"input": "2 2\nBW\nBB\n", "output": "1\n"}, {"input": "2 2\nBB\nWW\n", "output": "2\n"}, {"input": "2 2\nBB\nWB\n", "output": "1\n"}, {"input": "2 2\nBB\nBW\n", "output": "1\n"}, {"input": "2 2\nBB\nBB\n", "output": "0\n"}, {"input": "1 2\nWW\n", "output": "1\n"}, {"input": "1 2\nWB\n", "output": "0\n"}, {"input": "1 2\nBW\n", "output": "0\n"}, {"input": "2 1\nW\nW\n", "output": "1\n"}, {"input": "2 1\nW\nB\n", "output": "0\n"}, {"input": "2 1\nB\nW\n", "output": "0\n"}, {"input": "2 1\nB\nB\n", "output": "-1\n"}, {"input": "20 10\nWWBWWWBBWW\nWWWWWBWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWBBBWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWBWWWWWBWW\nWBWWBWWWBW\nWWBWBWWWWW\nWWWBWWBBWW\nWWBBWBWBWW\nBBWWWWWBWW\nWWBWWBBBWW\nWWWBWBBWWW\nWWWBBWBWWW\nWWWWWWWWWW\nWWWBWWWWWW\nWWWWWWWWWW\n", "output": "-1\n"}, {"input": "10 20\nWWWWWWWBWWWWWWWBWWWB\nWWWBWWWBWWWWWWWWWWWW\nBWWWWWWWWWWWWWWWWWBB\nWWWWWWBWWBWWBWWWBWWW\nWWWWWWWWBWWBWWWBWWWW\nWBWWWWWWWBWWWWWWWWWW\nWWWBWBWWBWWWWWBBWWWB\nWWBBWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWBWWWWBW\nWWWWWWWWWWWWBWWBWWWB\n", "output": "-1\n"}, {"input": "1 100\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\n", "output": "0\n"}, {"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\n", "output": "0\n"}, {"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\n", "output": "0\n"}, {"input": "1 100\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\n", "output": "-1\n"}, {"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\n", "output": "-1\n"}, {"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\n", "output": "0\n"}, {"input": "100 1\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\n", "output": "0\n"}, {"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\n", "output": "0\n"}, {"input": "100 1\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\n", "output": "-1\n"}, {"input": "1 5\nWBBWW\n", "output": "-1\n"}, {"input": "20 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nB\nB\n", "output": "-1\n"}, {"input": "3 3\nWBW\nWBB\nWWW\n", "output": "1\n"}, {"input": "4 6\nWWWWWW\nWWWBWW\nWWWWWB\nWWWWWW\n", "output": "7\n"}, {"input": "5 5\nWBWBW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\n", "output": "7\n"}, {"input": "3 3\nBBB\nBBB\nBBB\n", "output": "0\n"}, {"input": "5 5\nWWBWW\nWWWWW\nWWWWW\nWWWWW\nWWBWW\n", "output": "23\n"}, {"input": "5 4\nWWBW\nBWWB\nWWWW\nWWWW\nWWWW\n", "output": "13\n"}, {"input": "5 4\nWWWW\nWWWB\nWWWB\nWWWW\nWBBW\n", "output": "12\n"}, {"input": "6 6\nWWBWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWBWW\n", "output": "34\n"}, {"input": "3 3\nBBW\nWWW\nBWW\n", "output": "6\n"}, {"input": "3 3\nBWB\nWWW\nBWW\n", "output": "6\n"}, {"input": "6 6\nWBWWWW\nBWWWBW\nWWWWWW\nWWBWWW\nWWWWWW\nWWWWWW\n", "output": "21\n"}, {"input": "3 3\nWWW\nWBW\nWWW\n", "output": "0\n"}, {"input": "3 3\nBBB\nWWW\nWWW\n", "output": "6\n"}, {"input": "5 5\nWWBWW\nWWBWW\nWBBBW\nWWBWW\nWWBWW\n", "output": "18\n"}, {"input": "5 2\nWB\nWB\nWB\nWW\nWW\n", "output": "-1\n"}, {"input": "4 7\nBBBBBWW\nWWWWWWW\nWWWWWWW\nWWWWWWW\n", "output": "-1\n"}, {"input": "5 4\nWWWW\nWWWB\nWWWW\nWWBB\nWWWW\n", "output": "6\n"}, {"input": "4 4\nWWWW\nWBWW\nWWWW\nWWWW\n", "output": "0\n"}, {"input": "2 5\nWWWWW\nBBBWW\n", "output": "-1\n"}, {"input": "6 6\nWWBWWW\nWWWWWW\nWWWWBW\nWWWWWW\nWWWWWW\nWWBWWW\n", "output": "33\n"}, {"input": "3 3\nWBW\nWBW\nWBW\n", "output": "6\n"}, {"input": "3 5\nWWBBB\nBWBBB\nWWBBB\n", "output": "-1\n"}, {"input": "5 5\nWWWWB\nBWWWW\nWWWWB\nWWWWW\nWWWWW\n", "output": "22\n"}, {"input": "5 5\nBWWWB\nWWWWW\nWWWWW\nWWWWW\nBWWWW\n", "output": "22\n"}, {"input": "4 5\nWWWWW\nBWWWW\nBBBWW\nWWWWW\n", "output": "5\n"}, {"input": "4 4\nBBBB\nWWWW\nWWWW\nWWWW\n", "output": "12\n"}, {"input": "4 6\nWWWWWW\nBWWWWW\nBWWWWW\nBBBBBB\n", "output": "-1\n"}, {"input": "3 6\nWWWWWW\nBBBWWW\nWWWWWW\n", "output": "6\n"}, {"input": "5 2\nWW\nBW\nBW\nBB\nWW\n", "output": "-1\n"}, {"input": "5 5\nWWWWW\nWWWWW\nBBBBB\nWWWWW\nWWWWW\n", "output": "20\n"}, {"input": "5 5\nWWWWW\nWWWWW\nWWWWB\nWBWWW\nWWWWW\n", "output": "14\n"}, {"input": "1 5\nWWBWW\n", "output": "0\n"}, {"input": "1 3\nBBB\n", "output": "-1\n"}, {"input": "2 4\nWWBW\nBWBW\n", "output": "-1\n"}, {"input": "6 6\nBBBBBB\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW\n", "output": "30\n"}, {"input": "4 4\nWWWW\nWWWW\nWWWW\nWWWW\n", "output": "1\n"}, {"input": "3 3\nWWW\nWWW\nWWB\n", "output": "0\n"}, {"input": "5 1\nB\nB\nW\nW\nW\n", "output": "-1\n"}, {"input": "2 3\nWBW\nWBW\n", "output": "2\n"}, {"input": "5 2\nWW\nWB\nWB\nWB\nWW\n", "output": "-1\n"}, {"input": "5 5\nWWWWW\nBWWWW\nWWWWB\nWWWWW\nWWWWW\n", "output": "23\n"}] |
|
131 | There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the $n$ piles with stones numbered from $1$ to $n$.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was $x_1, x_2, \ldots, x_n$, correspondingly. One of the participants wrote down this sequence in a notebook.
They visited it again the following day, and the number of stones in piles was equal to $y_1, y_2, \ldots, y_n$. One of the participants also wrote it down in a notebook.
It is well known that every member of the EJOI jury during the night either sits in the room $108$ or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night.
Participants want to know whether their notes can be correct or they are sure to have made a mistake.
-----Input-----
The first line of the input file contains a single integer $n$, the number of piles with stones in the garden ($1 \leq n \leq 50$).
The second line contains $n$ integers separated by spaces $x_1, x_2, \ldots, x_n$, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time ($0 \leq x_i \leq 1000$).
The third line contains $n$ integers separated by spaces $y_1, y_2, \ldots, y_n$, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time ($0 \leq y_i \leq 1000$).
-----Output-----
If the records can be consistent output "Yes", otherwise output "No" (quotes for clarity).
-----Examples-----
Input
5
1 2 3 4 5
2 1 4 3 5
Output
Yes
Input
5
1 1 1 1 1
1 0 1 0 1
Output
Yes
Input
3
2 3 9
1 7 9
Output
No
-----Note-----
In the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile.
In the second example, the jury took stones from the second and fourth piles.
It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array. | interview | [{"code": "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\nc = sum(a)\nd = sum(b)\n\nif c >= d:\n print('Yes')\nelse:\n print('No')", "passed": true, "time": 0.15, "memory": 14528.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\na = sum(a)\nb = sum(b)\n\nif a < b:\n print(\"No\")\nelse:\n print(\"Yes\")", "passed": true, "time": 0.74, "memory": 14516.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\nif sum(b) > sum(a):\n print(\"No\")\nelse:\n print(\"Yes\")", "passed": true, "time": 0.16, "memory": 14624.0, "status": "done"}, {"code": "n = int(input())\na = [int(v) for v in input().split()]\nb = [int(v) for v in input().split()]\n\nprint([\"No\", \"Yes\"][sum(a) >= sum(b)])\n", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}, {"code": "n = int(input())\n\ndata_1 = list(map(int,input().split()))\n\n\ndata_2 = list(map(int,input().split()))\n\nif sum(data_1) >= sum(data_2):\n print(\"Yes\")\n\nelse:\n print(\"No\")\n", "passed": true, "time": 0.15, "memory": 14536.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\nif sum(a) >= sum(b):\n print(\"Yes\")\nelse:\n print(\"No\")\n", "passed": true, "time": 0.14, "memory": 14568.0, "status": "done"}, {"code": "n = int(input())\nsx = sum(map(int, input().split()))\nsy = sum(map(int, input().split()))\nif sx >= sy:\n print('Yes')\nelse:\n print('No')", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "n=int(input())\na=sum(list(map(int,input().split())))\nb=sum(list(map(int,input().split())))\nif(b<=a):\n print(\"Yes\")\nelse:\n print(\"No\")", "passed": true, "time": 0.15, "memory": 14492.0, "status": "done"}, {"code": "def main():\n input()\n a = [int(x) for x in input().split()]\n b = [int(x) for x in input().split()]\n\n if sum(a) >= sum(b):\n print('Yes')\n else:\n print('No')\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14676.0, "status": "done"}, {"code": "\nn=int(input())\nx=list(map(int,input().split()))\ny=list(map(int,input().split()))\n\nif sum(x)>=sum(y):\n print('Yes')\nelse:\n print('No')\n\n\n\n", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\ns1 = sum(a)\ns2 = sum(b)\nif s2>s1:\n print(\"No\")\nelse:\n print('Yes')", "passed": true, "time": 0.15, "memory": 14408.0, "status": "done"}, {"code": "import sys\nimport math\nimport random\n\nn = int(input())\n\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nsuma = 0\nsumb = 0\nfor elem in a:\n suma += elem\nfor elem in b:\n sumb += elem\n\nif sumb <= suma:\n print('Yes')\nelse:\n print('No')\n", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "n = int(input())\na = sum([int(i) for i in input().split()])\nb = sum([int(i) for i in input().split()])\nif (a >= b):\n print('Yes')\nelse:\n print('No')", "passed": true, "time": 0.15, "memory": 14312.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nif sum(b) <= sum(a):\n print('Yes')\nelse:\n print('No')", "passed": true, "time": 0.14, "memory": 14656.0, "status": "done"}, {"code": "n=int(input())\nl=list(map(int,input().strip().split()))\nl1=list(map(int,input().strip().split()))\nr=sum(l)\nr1=sum(l1)\nif (r1>r):\n print (\"No\")\nelse:\n print (\"Yes\")", "passed": true, "time": 0.15, "memory": 14580.0, "status": "done"}, {"code": "n = int(input())\narr1 = list(map(int, input().split()))\narr2 = list(map(int, input().split()))\nif sum(arr1) >= sum(arr2):\n print('Yes')\nelse:\n print('No')", "passed": true, "time": 0.15, "memory": 14536.0, "status": "done"}, {"code": "n = int(input())\nx = [int(s) for s in input().split()]\ny = [int(s) for s in input().split()]\ns1 = 0\ns2 = 0\nfor i in range(n):\n s1 += x[i]\n s2 += y[i]\nif s2 > s1:\n print(\"No\")\nelse:\n print(\"Yes\")", "passed": true, "time": 0.15, "memory": 14676.0, "status": "done"}, {"code": "n = int(input())\na = [int(x) for x in input().split()]\nb = [int(x) for x in input().split()]\nsuma = 0\nsumb = 0\nfor x in a:\n suma += x\nfor x in b:\n sumb += x\nprint(\"Yes\" if suma >= sumb else \"No\")", "passed": true, "time": 0.14, "memory": 14432.0, "status": "done"}] | [{"input": "5\n1 2 3 4 5\n2 1 4 3 5\n", "output": "Yes\n"}, {"input": "5\n1 1 1 1 1\n1 0 1 0 1\n", "output": "Yes\n"}, {"input": "3\n2 3 9\n1 7 9\n", "output": "No\n"}, {"input": "40\n361 372 139 808 561 460 421 961 727 719 130 235 320 470 432 759 317 886 624 666 917 133 736 710 462 424 541 118 228 216 612 339 800 557 291 128 801 9 0 318\n364 689 60 773 340 571 627 932 581 856 131 153 406 475 217 716 433 519 417 552 919 53 923 605 319 359 516 121 207 180 373 343 905 641 477 416 927 207 160 245\n", "output": "Yes\n"}, {"input": "45\n246 523 714 431 266 139 591 246 845 818 805 198 70 620 166 478 87 849 415 228 957 59 190 332 632 14 451 857 221 638 837 222 970 643 19 172 39 185 903 342 750 265 241 968 876\n460 389 541 164 324 52 246 107 826 864 693 132 10 697 429 434 99 950 164 85 972 157 327 337 592 241 350 962 130 673 967 373 657 923 456 347 394 76 743 407 724 117 268 741 918\n", "output": "Yes\n"}, {"input": "50\n620 222 703 953 303 333 371 125 554 88 60 189 873 644 817 100 760 64 887 605 611 845 762 916 21 26 254 553 602 66 796 531 329 888 274 584 215 135 69 403 680 734 440 406 53 958 135 230 918 206\n464 128 878 999 197 358 447 191 530 218 63 443 630 587 836 232 659 117 787 254 667 646 498 845 252 179 452 390 455 16 686 522 236 945 498 635 445 225 7 38 553 946 563 457 102 942 130 310 941 312\n", "output": "Yes\n"}, {"input": "40\n361 372 139 808 561 460 421 961 727 719 130 235 320 470 432 759 317 886 624 666 917 133 736 710 462 424 541 118 228 216 612 339 800 557 291 128 801 9 0 318\n29 469 909 315 333 412 777 490 492 431 908 412 187 829 453 595 896 817 755 914 34 890 583 691 544 969 733 132 802 170 67 68 370 146 856 184 275 785 928 798\n", "output": "No\n"}, {"input": "45\n246 523 714 431 266 139 591 246 845 818 805 198 70 620 166 478 87 849 415 228 957 59 190 332 632 14 451 857 221 638 837 222 970 643 19 172 39 185 903 342 750 265 241 968 876\n918 332 978 856 517 621 81 62 150 482 834 649 860 259 394 937 647 0 400 783 574 713 355 221 543 389 937 824 53 361 824 454 217 180 840 407 160 417 373 737 49 476 320 59 886\n", "output": "No\n"}, {"input": "50\n620 222 703 953 303 333 371 125 554 88 60 189 873 644 817 100 760 64 887 605 611 845 762 916 21 26 254 553 602 66 796 531 329 888 274 584 215 135 69 403 680 734 440 406 53 958 135 230 918 206\n494 447 642 337 839 128 971 105 915 739 803 8 848 253 554 186 338 656 238 106 89 13 622 777 663 669 360 451 461 639 403 255 570 648 996 618 55 409 733 230 533 226 774 559 161 184 933 308 554 161\n", "output": "No\n"}, {"input": "50\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n", "output": "Yes\n"}, {"input": "1\n633\n609\n", "output": "Yes\n"}, {"input": "2\n353 313\n327 470\n", "output": "No\n"}, {"input": "3\n835 638 673\n624 232 266\n", "output": "Yes\n"}, {"input": "4\n936 342 19 398\n247 874 451 768\n", "output": "No\n"}, {"input": "5\n417 666 978 553 271\n488 431 625 503 978\n", "output": "No\n"}, {"input": "10\n436 442 197 740 550 361 317 473 843 982\n356 826 789 479 641 974 106 221 57 858\n", "output": "Yes\n"}, {"input": "15\n702 593 763 982 263 48 487 759 961 80 642 169 778 621 764\n932 885 184 230 411 644 296 351 112 940 73 707 296 472 86\n", "output": "Yes\n"}, {"input": "20\n82 292 379 893 300 854 895 638 58 971 278 168 580 272 653 315 176 773 709 789\n298 710 311 695 328 459 510 994 472 515 634 568 368 913 182 223 361 132 92 620\n", "output": "Yes\n"}, {"input": "25\n349 443 953 126 394 160 63 924 795 450 572 513 338 33 768 34 955 737 874 731 329 16 377 318 125\n56 39 740 846 938 851 459 538 617 664 268 981 315 2 23 76 974 417 786 816 207 227 870 385 958\n", "output": "No\n"}, {"input": "30\n722 523 950 656 431 347 463 795 893 348 208 893 140 65 419 36 627 333 972 346 230 422 337 893 896 442 835 56 846 986\n429 148 890 854 546 680 776 265 551 465 387 823 996 845 374 867 411 742 447 267 711 989 501 694 456 451 192 529 215 709\n", "output": "No\n"}, {"input": "35\n607 674 142 278 135 34 13 80 629 448 875 856 518 446 161 376 406 288 764 289 643 347 164 515 73 39 126 413 848 788 653 651 67 320 655\n717 5 441 833 869 107 620 329 877 536 753 593 610 811 360 42 46 996 635 96 301 565 190 99 570 168 528 355 830 392 356 106 211 405 607\n", "output": "No\n"}, {"input": "1\n633\n633\n", "output": "Yes\n"}, {"input": "2\n353 313\n344 322\n", "output": "Yes\n"}, {"input": "3\n835 638 673\n516 880 750\n", "output": "Yes\n"}, {"input": "4\n936 342 19 398\n807 250 199 439\n", "output": "Yes\n"}, {"input": "5\n417 666 978 553 271\n72 946 832 454 581\n", "output": "Yes\n"}, {"input": "10\n436 442 197 740 550 361 317 473 843 982\n788 683 32 402 305 396 823 206 739 967\n", "output": "Yes\n"}, {"input": "15\n702 593 763 982 263 48 487 759 961 80 642 169 778 621 764\n346 342 969 741 762 123 89 823 955 599 575 312 547 784 645\n", "output": "Yes\n"}, {"input": "20\n82 292 379 893 300 854 895 638 58 971 278 168 580 272 653 315 176 773 709 789\n370 433 505 670 178 892 948 864 252 906 45 275 891 185 432 12 43 270 951 953\n", "output": "Yes\n"}, {"input": "25\n349 443 953 126 394 160 63 924 795 450 572 513 338 33 768 34 955 737 874 731 329 16 377 318 125\n75 296 997 211 919 7 357 928 891 829 119 509 184 29 769 262 973 936 100 588 115 536 398 163 186\n", "output": "Yes\n"}, {"input": "30\n722 523 950 656 431 347 463 795 893 348 208 893 140 65 419 36 627 333 972 346 230 422 337 893 896 442 835 56 846 986\n914 569 671 995 728 188 135 588 943 433 368 615 218 38 810 484 468 128 785 149 398 587 174 881 875 477 737 181 752 821\n", "output": "Yes\n"}, {"input": "35\n607 674 142 278 135 34 13 80 629 448 875 856 518 446 161 376 406 288 764 289 643 347 164 515 73 39 126 413 848 788 653 651 67 320 655\n452 596 228 56 48 35 155 250 793 729 630 495 803 209 156 423 427 270 925 479 635 639 50 489 27 198 324 241 564 898 178 713 131 337 738\n", "output": "Yes\n"}, {"input": "1\n1000\n1000\n", "output": "Yes\n"}, {"input": "2\n1000 1000\n1000 1000\n", "output": "Yes\n"}, {"input": "3\n1000 1000 1000\n1000 1000 1000\n", "output": "Yes\n"}, {"input": "4\n1000 1000 1000 1000\n1000 1000 1000 1000\n", "output": "Yes\n"}, {"input": "5\n1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000\n", "output": "Yes\n"}, {"input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n", "output": "Yes\n"}, {"input": "15\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n", "output": "Yes\n"}, {"input": "20\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n", "output": "Yes\n"}, {"input": "25\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n", "output": "Yes\n"}, {"input": "30\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n", "output": "Yes\n"}, {"input": "35\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n", "output": "Yes\n"}, {"input": "40\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n", "output": "Yes\n"}, {"input": "45\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n", "output": "Yes\n"}, {"input": "8\n5 5 0 0 0 0 0 0\n1 0 0 0 0 0 0 0\n", "output": "Yes\n"}, {"input": "1\n50\n1\n", "output": "Yes\n"}, {"input": "5\n9 9 9 9 9\n10 9 9 9 1\n", "output": "Yes\n"}, {"input": "6\n3 4 2 5 6 3\n2 3 2 5 6 3\n", "output": "Yes\n"}, {"input": "4\n1 1 1 1\n0 0 0 0\n", "output": "Yes\n"}, {"input": "3\n3 3 3\n1 0 0\n", "output": "Yes\n"}, {"input": "3\n2 1 5\n1 2 4\n", "output": "Yes\n"}, {"input": "3\n2 4 5\n1 2 3\n", "output": "Yes\n"}, {"input": "3\n3 4 5\n1 1 1\n", "output": "Yes\n"}, {"input": "2\n5 3\n2 4\n", "output": "Yes\n"}, {"input": "3\n5 5 5\n1 1 1\n", "output": "Yes\n"}, {"input": "1\n11\n9\n", "output": "Yes\n"}, {"input": "5\n1 2 3 4 6\n1 2 3 4 5\n", "output": "Yes\n"}, {"input": "50\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\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\n", "output": "Yes\n"}, {"input": "3\n3 4 4\n3 5 4\n", "output": "No\n"}, {"input": "1\n100\n1\n", "output": "Yes\n"}, {"input": "1\n300\n1\n", "output": "Yes\n"}, {"input": "5\n5 5 5 5 5\n1 1 1 1 1\n", "output": "Yes\n"}, {"input": "3\n1000 1000 1000\n0 0 0\n", "output": "Yes\n"}, {"input": "1\n3\n2\n", "output": "Yes\n"}, {"input": "2\n5 5\n1 1\n", "output": "Yes\n"}, {"input": "2\n10 1\n1 9\n", "output": "Yes\n"}, {"input": "5\n3 3 3 3 3\n2 2 2 2 2\n", "output": "Yes\n"}, {"input": "1\n10\n5\n", "output": "Yes\n"}, {"input": "5\n2 3 4 5 6\n0 0 0 0 4\n", "output": "Yes\n"}, {"input": "2\n3 3\n2 2\n", "output": "Yes\n"}, {"input": "1\n100\n0\n", "output": "Yes\n"}, {"input": "5\n2 3 4 5 1\n1 1 3 4 5\n", "output": "Yes\n"}, {"input": "3\n10 10 1\n0 0 2\n", "output": "Yes\n"}, {"input": "5\n2 3 4 5 6\n0 0 0 0 19\n", "output": "Yes\n"}, {"input": "1\n1000\n0\n", "output": "Yes\n"}, {"input": "1\n1\n5\n", "output": "No\n"}, {"input": "4\n1 1 1 1\n0 0 0 3\n", "output": "Yes\n"}, {"input": "5\n2 3 4 5 1\n1 1 1 1 1\n", "output": "Yes\n"}, {"input": "1\n6\n1\n", "output": "Yes\n"}, {"input": "5\n4 5 3 6 7\n1 1 4 4 5\n", "output": "Yes\n"}, {"input": "2\n500 500\n1 1\n", "output": "Yes\n"}, {"input": "1\n10\n1\n", "output": "Yes\n"}, {"input": "1\n1\n1\n", "output": "Yes\n"}, {"input": "3\n2 4 2\n4 3 0\n", "output": "Yes\n"}, {"input": "1\n0\n0\n", "output": "Yes\n"}, {"input": "1\n7\n3\n", "output": "Yes\n"}, {"input": "3\n4 5 6\n3 2 1\n", "output": "Yes\n"}, {"input": "5\n1 2 3 4 5\n0 0 0 0 0\n", "output": "Yes\n"}, {"input": "1\n2\n1\n", "output": "Yes\n"}, {"input": "3\n3 3 3\n1 1 1\n", "output": "Yes\n"}] |
|
132 | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to a_{i}. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.
The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all a_{i} is 360.
-----Output-----
Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.
-----Examples-----
Input
4
90 90 90 90
Output
0
Input
3
100 100 160
Output
40
Input
1
360
Output
360
Input
4
170 30 150 10
Output
0
-----Note-----
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
[Image]
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector. | interview | [{"code": "n = int(input())\na = list(map(int, input().split()))\nmn = 360\nfor i in range(n):\n x = 0\n for j in range(i, n):\n x += a[j]\n mn = min(mn, abs(x - (360 - x)))\nprint(mn)", "passed": true, "time": 0.4, "memory": 14636.0, "status": "done"}, {"code": "n = int(input().strip())\n\nkosi = list(map(int, input().strip().split()))\n\nmini = 400\n\nfor a in range(len(kosi)):\n for b in range(a, len(kosi)):\n first = sum(kosi[a:b])\n second = sum(kosi[:a]) + sum(kosi[b:])\n if abs(first - second) < mini:\n mini = abs(first - second)\n\nprint(mini)\n \n\n", "passed": true, "time": 0.62, "memory": 14548.0, "status": "done"}, {"code": "import sys\nsys.setrecursionlimit(100000000)\n# def input(): return sys.stdin.readline()[:-1]\ndef iin(): return int(input())\ndef impin(): return list(map(int, input().split()))\ndef irrin(): return [int(x) for x in input().split()]\ndef imrin(n): return [int(input()) for _ in range(n)]\n\n\nn = iin()\narr = irrin()\nsa = sum(arr)\nmn = 100000000\nfor i in range(n):\n for j in range(i, n+1):\n s = sum(arr[i:j])\n # print(s)\n k = sa-s\n mn = min(mn, abs(s-k))\nprint(mn)\n", "passed": true, "time": 0.31, "memory": 14544.0, "status": "done"}, {"code": "n = int(input())\n\nnums = list(map(int, input().split()))\n\nanswer = float('inf')\n\nfor l in range(n):\n for s in range(n):\n if(s + l - 1 >= n):continue\n current = sum(nums[s:s + l])\n answer = min(answer, abs(360 - 2 * current))\n\n\nprint(answer)\n", "passed": true, "time": 0.36, "memory": 14420.0, "status": "done"}, {"code": "\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n s = sum(a)\n res = 100 ** 10\n for l in range(n):\n for r in range(l, n):\n s1 = sum(a[l:r])\n res = min(res, abs(s1 - (s - s1)))\n\n print(res)\n\n\n\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 1.9, "memory": 14584.0, "status": "done"}, {"code": "from collections import deque\n\nn = int(input())\na = deque(map(int, input().split()))\nps = [0] * n\nmindif = 2e9\nfor i in range(n):\n for i in range(n):\n ps[i] = ps[i - 1] if i > 0 else 0\n ps[i] += a[i]\n for i in range(n):\n mindif = min(mindif, abs((ps[i - 1] if i > 0 else 0) - (ps[n - 1] - (ps[i - 1] if i > 0 else 0))))\n a.append(a.popleft())\n\nprint(mindif)", "passed": true, "time": 0.3, "memory": 14636.0, "status": "done"}, {"code": "n = int(input())\na = [int(i) for i in input().split()]\npref = []\ns = 0\nfor i in range(n):\n s += a[i]\n pref.append(s)\nmins = 1000\nfor i in range(n):\n for j in range(i, n):\n s = abs((pref[j] - pref[i]) - (pref[i] + (pref[n-1] - pref[j])))\n if s < mins:\n mins = s\nprint(mins)", "passed": true, "time": 0.18, "memory": 14600.0, "status": "done"}, {"code": "n = int(input())\n\nbest = 360\n\ntab = list(map(int, input().split()))\n\npre_sum = [0]\n\nfor i in range(1, len(tab) + 1):\n pre_sum += [tab[i - 1] + pre_sum[-1]]\n\nfor i in range(n + 1):\n for j in range(i, n + 1):\n best = min([best, 2 * abs(180 - (pre_sum[j] - pre_sum[i - 1]))])\n\nprint(best);\n", "passed": true, "time": 0.2, "memory": 14528.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\na += a\nans = 360\nfor i in range(n):\n cur = 0\n j = i\n while cur < 180:\n cur += a[j]\n j += 1\n ans = min(ans, 2*cur - 360)\nprint(ans)", "passed": true, "time": 0.3, "memory": 14432.0, "status": "done"}, {"code": "n = int(input())\npieces = [int(x) for x in input().split()]\nsm = 360\ncurs = 0\nans = []\nfor i in range(n):\n for elem in pieces:\n ans.append(abs(sm - 2 * curs))\n curs += elem\n if curs >= 360:\n curs = 0\n pieces.append(pieces.pop(0))\nprint(min(ans))", "passed": true, "time": 0.2, "memory": 14572.0, "status": "done"}, {"code": "n = int(input())\nslices = list(map(int, input().split()))\nanswer = 360\nfor i in range(n):\n for j in range(i + 1, n):\n cur_s = abs(sum(slices[:i]) + sum(slices[j:]) - sum(slices[i:j]))\n answer = min(cur_s, answer)\nprint(answer)\n", "passed": true, "time": 0.53, "memory": 14544.0, "status": "done"}, {"code": "n = int(input())\na = [int(i) for i in input().split()]\na = a + a\npref_sum = [0] * (2 * n)\nfor i in range(2 * n):\n pref_sum[i] = pref_sum[i - 1] + a[i]\ndif = int(1e9)\nfor i in range(n):\n for j in range(n):\n dif = min(dif, abs(pref_sum[n - 1] - 2 * (pref_sum[j + i] - pref_sum[j])))\nprint(dif)", "passed": true, "time": 0.24, "memory": 14532.0, "status": "done"}, {"code": "n = int(input())\narr = [int(num) for num in input().strip().split()]\nans = 360\nfor i in range(n):\n l = 0\n r = 360\n for j in range(n):\n ans = min(ans, abs(l - r))\n l += arr[j]\n r -= arr[j]\n if ans == 0:\n break\n val = arr[0]\n arr.remove(arr[0])\n arr.append(val)\nprint(ans)", "passed": true, "time": 0.34, "memory": 14576.0, "status": "done"}, {"code": "#from math import gcd, factorial as f\n#list(map(int, input().split()))\nn = int(input())\na = list(map(int, input().split()))\nx = sum(a)\na += a\nan = 0\nann = 1000000\nfor j in range(n):\n an = 0\n for i in range(j, 2 * n):\n an += a[i]\n if an >= x // 2:\n if abs(x - 2 * an) < abs(x - 2 * ann):\n ann = an\n an = 0\nprint(abs(x - 2 * ann))\n", "passed": true, "time": 0.31, "memory": 14408.0, "status": "done"}, {"code": "#python3\n#utf-8\n\npieces_nr = int(input())\npiece_idx___deg = [int(x) for x in input().split()]\nans = 360\nfor left_cl in range(pieces_nr):\n for right_op in range(left_cl + 1, pieces_nr + 1):\n curr_split = sum(piece_idx___deg[left_cl:right_op])\n rest = 360 - curr_split\n # print(curr_split, rest)\n curr_ans = rest - curr_split\n if curr_ans < 0:\n curr_ans *= -1\n ans = min(curr_ans, ans)\n # print(curr_ans)\nprint(ans)\n", "passed": true, "time": 0.3, "memory": 14500.0, "status": "done"}, {"code": "n = int(input())\nar = [int(i) for i in input().split(' ')]\n\nsum = 0\ns_a = 1000\nfor i in range(n):\n k = 0\n sum = 0\n while sum < 180:\n sum += ar[i-k]\n k += 1\n if s_a > sum-(360-sum):\n s_a = sum-(360-sum)\n\nprint(s_a)", "passed": true, "time": 0.25, "memory": 14588.0, "status": "done"}, {"code": "n = int(input())\nangles = list(map(int, input().split()))\nangles = angles+angles\n\nsum_ = 0\nfrom_ = 0\nbest = 360\nfor to in range(n):\n sum_ += angles[to]\n while sum_ >= 180:\n best = min(best, abs(360-2*sum_))\n sum_ -= angles[from_]\n from_ += 1\n best = min(best, abs(360-2*sum_))\nprint(best)\n", "passed": true, "time": 0.16, "memory": 14460.0, "status": "done"}, {"code": "kolichestvoKuskov = int(input())\nspisokUglov = list(map(int, input().split()))\nraznica = 180\nfor a in range(0, kolichestvoKuskov):\n sum = 0\n for i in range(a, kolichestvoKuskov):\n sum += spisokUglov[i]\n if raznica > abs(180 - sum):\n raznica = abs(180 - sum)\nprint(raznica * 2)\n", "passed": true, "time": 0.3, "memory": 14472.0, "status": "done"}, {"code": "n = int(input())\nsectors = list(map(int, input().split()))\n\nans = 360\nfor _ in range(n):\n for i in range(n):\n temp = abs(sum(sectors[:i]) - sum(sectors[i:]))\n if temp < ans:\n ans = temp\n sectors[:] = sectors[-1:] + sectors[:-1]\nprint(ans)\n", "passed": true, "time": 0.85, "memory": 14432.0, "status": "done"}, {"code": "n = int(input())\na = [int(i) for i in input().split()]\nans = 1e9\nfor j in range(n):\n pref = [0]*(n+1)\n for i in range(1, n+1):\n pref[i] = pref[i-1] + a[i-1]\n for i in range(n):\n ans = min(ans, abs(pref[-1]-2*pref[i]))\n a = [a[-1]] + a[:-1]\nprint(ans)\n", "passed": true, "time": 0.37, "memory": 14672.0, "status": "done"}, {"code": "import sys\ndata = sys.stdin.readlines()\n\nn = int(data[0])\nm = [int(x) for x in data[1].split()]\n\nres = []\n\nfor k in range(n):\n for i in range(n):\n a = abs(sum(m[:i]) - sum(m[i:]))\n res.append(a)\n m.append(m[0])\n m = m[1:]\nprint(min(res))\n \n", "passed": true, "time": 0.85, "memory": 14448.0, "status": "done"}, {"code": "n=int(input())\nl=[]\nl=input().split()\nfor i in range(n):\n l[i]=int(l[i])\nl.extend(l)\n\notv=400\nfor i in range(n):\n s=0\n j=i\n while s<180:\n s+=l[j]\n j+=1\n\n if abs(s-180)*2<otv:\n otv=abs(s-180)*2\nprint(otv)", "passed": true, "time": 0.31, "memory": 14580.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nsumspref = [a[0]]\nfor i in range(1, n):\n sumspref.append(sumspref[-1] + a[i])\nsums = []\nfor i in range(n):\n for j in range(i, n):\n sums.append(abs(180 - (sumspref[j] - sumspref[i])))\nprint(min(sums) * 2)\n \n\n", "passed": true, "time": 0.17, "memory": 14568.0, "status": "done"}, {"code": "n = int( input() )\n\na = list( map( int, input().split() ) )\n\na = a + a\n\n#print( a )\n\nmid = n//2\n\nbest = 99999999999999999999999\n\nfor i in range( n ):\n sub = a[i:i+n]\n #print( sub )\n d = sum(sub)\n best = min( best, d )\n s = 0\n\n #print( d, s )\n for j in range( n ):\n s += sub[j]\n d -= sub[j]\n\n diff = abs( s - d)\n best = min( best, diff )\n\nprint( best )\n", "passed": true, "time": 0.4, "memory": 14660.0, "status": "done"}, {"code": "def solution(sectors):\n n = len(sectors)\n if n == 1:\n return sectors[0]\n else:\n min_diff = 360\n for i in range(n):\n j = i\n sum_sector = 0\n prev = sum_sector\n while(sum_sector <= 180):\n prev = sum_sector\n sum_sector += sectors[j]\n j += 1\n j %= n\n #print(prev, sum_sector)\n if abs(360 - 2 * sum_sector) < min_diff:\n min_diff = abs(360 - 2 * sum_sector)\n if abs(360 - 2 * prev) < min_diff:\n min_diff = abs(360 - 2 * prev)\n return min_diff\n\n\nn = int(input())\nsectors = []\nsectors_str = input().split()\nfor s in sectors_str:\n sectors.append(int(s))\n\nprint(solution(sectors))", "passed": true, "time": 0.34, "memory": 14424.0, "status": "done"}] | [{"input": "4\n90 90 90 90\n", "output": "0\n"}, {"input": "3\n100 100 160\n", "output": "40\n"}, {"input": "1\n360\n", "output": "360\n"}, {"input": "4\n170 30 150 10\n", "output": "0\n"}, {"input": "5\n10 10 10 10 320\n", "output": "280\n"}, {"input": "8\n45 45 45 45 45 45 45 45\n", "output": "0\n"}, {"input": "3\n120 120 120\n", "output": "120\n"}, {"input": "5\n110 90 70 50 40\n", "output": "40\n"}, {"input": "2\n170 190\n", "output": "20\n"}, {"input": "15\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10\n", "output": "10\n"}, {"input": "5\n30 60 180 60 30\n", "output": "0\n"}, {"input": "2\n359 1\n", "output": "358\n"}, {"input": "5\n100 100 30 100 30\n", "output": "40\n"}, {"input": "5\n36 34 35 11 244\n", "output": "128\n"}, {"input": "5\n96 94 95 71 4\n", "output": "18\n"}, {"input": "2\n85 275\n", "output": "190\n"}, {"input": "3\n281 67 12\n", "output": "202\n"}, {"input": "5\n211 113 25 9 2\n", "output": "62\n"}, {"input": "13\n286 58 6 1 1 1 1 1 1 1 1 1 1\n", "output": "212\n"}, {"input": "15\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1\n", "output": "0\n"}, {"input": "20\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "92\n"}, {"input": "50\n148 53 32 11 4 56 8 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\n", "output": "0\n"}, {"input": "3\n1 1 358\n", "output": "356\n"}, {"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341\n", "output": "322\n"}, {"input": "33\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 328\n", "output": "296\n"}, {"input": "70\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 291\n", "output": "222\n"}, {"input": "130\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231\n", "output": "102\n"}, {"input": "200\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 161\n", "output": "0\n"}, {"input": "222\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 139\n", "output": "0\n"}, {"input": "10\n8 3 11 4 1 10 10 1 8 304\n", "output": "248\n"}, {"input": "12\n8 7 7 3 11 2 10 1 10 8 10 283\n", "output": "206\n"}, {"input": "13\n10 8 9 10 5 9 4 1 10 11 1 7 275\n", "output": "190\n"}, {"input": "14\n1 6 3 11 9 5 9 8 5 6 7 3 7 280\n", "output": "200\n"}, {"input": "15\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275\n", "output": "190\n"}, {"input": "30\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189\n", "output": "18\n"}, {"input": "70\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1\n", "output": "0\n"}, {"input": "29\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189\n", "output": "18\n"}, {"input": "35\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168\n", "output": "0\n"}, {"input": "60\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5\n", "output": "0\n"}, {"input": "71\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "0\n"}, {"input": "63\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "0\n"}, {"input": "81\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "0\n"}, {"input": "47\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68\n", "output": "0\n"}, {"input": "100\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 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\n", "output": "0\n"}, {"input": "120\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "0\n"}, {"input": "200\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "0\n"}, {"input": "220\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "0\n"}, {"input": "6\n27 15 28 34 41 215\n", "output": "70\n"}, {"input": "7\n41 38 41 31 22 41 146\n", "output": "14\n"}, {"input": "8\n24 27 34 23 29 23 30 170\n", "output": "20\n"}, {"input": "9\n11 11 20 20 33 32 35 26 172\n", "output": "6\n"}, {"input": "10\n36 13 28 13 33 34 23 25 34 121\n", "output": "0\n"}, {"input": "11\n19 37 13 41 37 15 32 12 19 35 100\n", "output": "10\n"}, {"input": "12\n37 25 34 38 21 24 34 38 11 29 28 41\n", "output": "2\n"}, {"input": "13\n24 40 20 26 25 29 39 29 35 28 19 18 28\n", "output": "2\n"}, {"input": "14\n11 21 40 19 28 34 13 16 23 30 34 22 25 44\n", "output": "4\n"}, {"input": "3\n95 91 174\n", "output": "12\n"}, {"input": "4\n82 75 78 125\n", "output": "46\n"}, {"input": "6\n87 75 88 94 15 1\n", "output": "4\n"}, {"input": "10\n27 52 58 64 45 64 1 19 2 28\n", "output": "12\n"}, {"input": "50\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1\n", "output": "0\n"}, {"input": "100\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3\n", "output": "0\n"}, {"input": "150\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1\n", "output": "0\n"}, {"input": "200\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2\n", "output": "0\n"}, {"input": "5\n35 80 45 100 100\n", "output": "40\n"}, {"input": "4\n90 179 90 1\n", "output": "2\n"}, {"input": "5\n50 50 20 160 80\n", "output": "0\n"}, {"input": "5\n30 175 30 5 120\n", "output": "10\n"}, {"input": "4\n170 30 10 150\n", "output": "20\n"}, {"input": "6\n90 30 90 30 90 30\n", "output": "60\n"}, {"input": "4\n70 80 110 100\n", "output": "20\n"}, {"input": "7\n35 45 70 100 10 10 90\n", "output": "0\n"}, {"input": "6\n50 90 10 90 20 100\n", "output": "20\n"}, {"input": "6\n10 155 162 1 26 6\n", "output": "18\n"}, {"input": "7\n80 90 80 45 10 10 45\n", "output": "20\n"}, {"input": "4\n18 36 162 144\n", "output": "36\n"}, {"input": "5\n20 50 50 160 80\n", "output": "40\n"}, {"input": "5\n10 30 140 20 160\n", "output": "0\n"}, {"input": "6\n90 80 60 50 40 40\n", "output": "20\n"}, {"input": "9\n40 20 20 20 20 20 20 40 160\n", "output": "40\n"}, {"input": "4\n90 54 90 126\n", "output": "72\n"}, {"input": "4\n150 170 30 10\n", "output": "20\n"}, {"input": "8\n130 12 13 85 41 67 5 7\n", "output": "26\n"}, {"input": "7\n70 170 20 10 30 30 30\n", "output": "20\n"}, {"input": "8\n100 100 50 50 15 15 15 15\n", "output": "40\n"}, {"input": "4\n100 70 80 110\n", "output": "20\n"}, {"input": "5\n160 130 40 20 10\n", "output": "20\n"}, {"input": "4\n20 149 151 40\n", "output": "22\n"}, {"input": "4\n100 10 100 150\n", "output": "60\n"}, {"input": "6\n19 64 105 168 1 3\n", "output": "16\n"}, {"input": "8\n10 10 70 70 90 90 10 10\n", "output": "0\n"}] |
|
135 | Imp is watching a documentary about cave painting. [Image]
Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i from 1 to k. Unfortunately, there are too many integers to analyze for Imp.
Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all $n \text{mod} i$, 1 ≤ i ≤ k, are distinct, i. e. there is no such pair (i, j) that: 1 ≤ i < j ≤ k, $n \operatorname{mod} i = n \operatorname{mod} j$, where $x \operatorname{mod} y$ is the remainder of division x by y.
-----Input-----
The only line contains two integers n, k (1 ≤ n, k ≤ 10^18).
-----Output-----
Print "Yes", if all the remainders are distinct, and "No" otherwise.
You can print each letter in arbitrary case (lower or upper).
-----Examples-----
Input
4 4
Output
No
Input
5 3
Output
Yes
-----Note-----
In the first sample remainders modulo 1 and 4 coincide. | interview | [{"code": "def main():\n\tn, k = map(int, input().split())\n\tfor i in range(1, k + 1):\n\t\tif (n % i != (i - 1)):\n\t\t\tprint(\"No\")\n\t\t\treturn\n\tprint(\"Yes\")\n\nmain()", "passed": true, "time": 0.16, "memory": 14604.0, "status": "done"}, {"code": "#! /usr/bin/env python3\n\nimport math\nimport sys\n\n\ndef lcm(u, v):\n return u * v // math.gcd(u, v)\n\n\ndef main():\n n, k = list(map(int, input().split()))\n m = 1\n for i in range(1, k + 1):\n m = lcm(m, i)\n if m - 1 > n:\n print('No')\n return\n if (n + 1) % m == 0:\n print('Yes')\n else:\n print('No')\n\n\ndef __starting_point():\n main()\n\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14596.0, "status": "done"}, {"code": "n, k = input().split()\nn, k = int(n), int(k)\n\nans = True\n\nn += 1\nfor i in range(1, min(100, k+1)):\n if (n % i) != 0:\n ans = False\n\nif ans:\n print('Yes')\nelse:\n print('No')\n", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nmas = []\nfor i in range(1, k + 1):\n q = n%i\n if q in mas:\n print(\"No\")\n return\n else:\n mas.append(q)\nprint(\"Yes\")", "passed": true, "time": 0.16, "memory": 14520.0, "status": "done"}, {"code": "n, k = map(int, input().split())\n\ns = set()\n\nfor i in range(1, k + 1):\n\tcur = n % i\n\tif cur in s:\n\t\tprint('No')\n\t\treturn\n\ts.add(cur)\n\nprint('Yes')", "passed": true, "time": 0.86, "memory": 14416.0, "status": "done"}, {"code": "import sys\n\n#f = open('input', 'r')\nf = sys.stdin\n\nn,k = list(map(int, f.readline().split()))\n\nans = 'Yes'\nfor tk in range(1, k+1):\n if len(set(n%(i+1) for i in range(tk))) != tk:\n ans = 'No'\n break\n\nprint(ans)\n", "passed": true, "time": 0.25, "memory": 14432.0, "status": "done"}, {"code": "def gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a % b)\n\ndef lcm(a, b):\n return a // gcd(a, b) * b;\n\nn, k = list(map(int, input().split()))\ninf = 10 ** 18\nx = 1\n\nfor i in range(1, k + 1):\n x = lcm(x, i)\n if x > inf:\n break\n\nif x > inf or n % x != x - 1:\n print(\"No\")\nelse:\n print(\"Yes\")\n\n", "passed": true, "time": 0.16, "memory": 14652.0, "status": "done"}, {"code": "def remainderSet(n, k):\n rem=set()\n for i in range(1,k+1):\n r=n%i\n if r in rem:\n return False\n else:\n rem.add(r)\n return True\n\ndef test():\n print(remainderSet(4,4))\n print(remainderSet(5,3))\n\ndef nia():\n s=input()\n while len(s)==0:\n s=input()\n s=s.split()\n iVal=[];\n for i in range (len(s)):\n iVal.append(int(s[i]))\n return iVal\n\ndef solve():\n arr=nia()\n if remainderSet(arr[0], arr[1]):\n print(\"Yes\")\n else:\n print(\"No\")\n \nsolve()\n", "passed": true, "time": 0.15, "memory": 14412.0, "status": "done"}, {"code": "s=input()\ns=s.split()\nn=int(s[0])\nk=int(s[1])\nb=1\na=[]\nfor i in range(1,k+1):\n c=n%i\n a.append(c)\n if c in a[:-1]:\n print('No')\n b=0\n break\nif b==1:\n print('Yes')\n", "passed": true, "time": 0.15, "memory": 14408.0, "status": "done"}, {"code": "n,k=list(map(int,input().split()))\nl=[]\nc=0\nfor i in range(1,k+1):\n l.append(n%i)\n p=set(l)\n if len(p)!=len(l):\n print (\"No\")\n c=1\n break\nif c==0:\n print (\"Yes\")\n\n", "passed": true, "time": 0.16, "memory": 14708.0, "status": "done"}, {"code": "n, k = [int(i) for i in input().split()]\n\ns = set()\n\nfor i in range(1, k+1):\n if n % i in s:\n print(\"No\")\n break\n s.add(n % i)\nelse:\n print(\"Yes\")", "passed": true, "time": 0.15, "memory": 14596.0, "status": "done"}, {"code": "n,k=list(map(int,input().split()))\na=set()\nfor i in range(1,k+1):\n if n%i in a:\n print('No')\n return\n else:\n a.add(n%i)\nprint('Yes')\n", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\nans = \"Yes\"\nfor i in range(2, k + 1):\n if n % i != i - 1:\n ans = \"No\"\n break\n elif 1e6 < i:\n break\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14564.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\n\nfor i in range(1,min(k+1,10000000)):\n if n%i != i-1:\n print('No')\n break\nelse:\n print('Yes')\n", "passed": true, "time": 0.25, "memory": 14408.0, "status": "done"}, {"code": "\ndef __starting_point():\n n,k = input().strip().split()\n n=int(n) ; k=int(k)\n a = {}\n for i in range(1,k+1):\n if n%i in a:\n print('No')\n return\n else:\n a[n%i] = 1\n print('Yes')\n__starting_point()", "passed": true, "time": 0.15, "memory": 14604.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nc = 1\nz = 1\nok = 1\n\nfor i in range(1, k + 1):\n c = z\n while z % i != 0:\n z += c\n if z > n + 10:\n ok = 0\n break\nif (n + 1) % z == 0 and ok:\n print('Yes')\nelse:\n print('No')\n", "passed": true, "time": 0.15, "memory": 14580.0, "status": "done"}, {"code": "n, k = map(int, input().strip().split())\n\nif k == 1:\n print('Yes')\nelse:\n # k! - 1 must divide into n\n '''\n prod = 1\n count = 2\n while prod < n:\n prod *= count\n if n % (prod - 1) == 0 and count >= k:\n #res = n // (prod - 1)\n # note: existance means k must be really small\n rems = [n % i for i in range(1, k + 1)]\n #print(rems)\n if len(set(rems)) == len(rems):\n print('Yes')\n break\n count += 1\n else:\n print('No')\n '''\n if k > 50000:\n print('No')\n else:\n rems = [n % i for i in range(1, k + 1)]\n #print(rems)\n print('Yes' if len(set(rems)) == len(rems) else 'No')", "passed": true, "time": 0.15, "memory": 14628.0, "status": "done"}] | [{"input": "4 4\n", "output": "No\n"}, {"input": "5 3\n", "output": "Yes\n"}, {"input": "1 1\n", "output": "Yes\n"}, {"input": "744 18\n", "output": "No\n"}, {"input": "47879 10\n", "output": "Yes\n"}, {"input": "1000000000000000000 1000000000000000000\n", "output": "No\n"}, {"input": "657180569218773599 42\n", "output": "Yes\n"}, {"input": "442762254977842799 30\n", "output": "Yes\n"}, {"input": "474158606260730555 1\n", "output": "Yes\n"}, {"input": "807873101233533988 39\n", "output": "No\n"}, {"input": "423 7\n", "output": "No\n"}, {"input": "264306177888923090 5\n", "output": "No\n"}, {"input": "998857801526481788 87\n", "output": "No\n"}, {"input": "999684044704565212 28\n", "output": "No\n"}, {"input": "319575605003866172 71\n", "output": "No\n"}, {"input": "755804560577415016 17\n", "output": "No\n"}, {"input": "72712630136142067 356370939\n", "output": "No\n"}, {"input": "807264258068668062 33080422\n", "output": "No\n"}, {"input": "808090496951784190 311661970\n", "output": "No\n"}, {"input": "808916740129867614 180178111\n", "output": "No\n"}, {"input": "1 2\n", "output": "Yes\n"}, {"input": "2 1\n", "output": "Yes\n"}, {"input": "57334064998850639 19\n", "output": "Yes\n"}, {"input": "144353716412182199 11\n", "output": "Yes\n"}, {"input": "411002215096001759 11\n", "output": "Yes\n"}, {"input": "347116374613371527 3\n", "output": "Yes\n"}, {"input": "518264351335130399 37\n", "output": "Yes\n"}, {"input": "192435891235905239 11\n", "output": "Yes\n"}, {"input": "491802505049361659 7\n", "output": "Yes\n"}, {"input": "310113769227703889 3\n", "output": "Yes\n"}, {"input": "876240758958364799 41\n", "output": "Yes\n"}, {"input": "173284263472319999 33\n", "output": "Yes\n"}, {"input": "334366426725130799 29\n", "output": "Yes\n"}, {"input": "415543470272330399 26\n", "output": "Yes\n"}, {"input": "631689521541558479 22\n", "output": "Yes\n"}, {"input": "581859366558790319 14\n", "output": "Yes\n"}, {"input": "224113913709159599 10\n", "output": "Yes\n"}, {"input": "740368848764104559 21\n", "output": "Yes\n"}, {"input": "895803074828822159 17\n", "output": "Yes\n"}, {"input": "400349974997012039 13\n", "output": "Yes\n"}, {"input": "205439024252247599 5\n", "output": "Yes\n"}, {"input": "197688463911338399 39\n", "output": "Yes\n"}, {"input": "283175367224349599 39\n", "output": "Yes\n"}, {"input": "893208176423362799 31\n", "output": "Yes\n"}, {"input": "440681012669897999 27\n", "output": "Yes\n"}, {"input": "947403664618451039 19\n", "output": "Yes\n"}, {"input": "232435556779345919 19\n", "output": "Yes\n"}, {"input": "504428493840551279 23\n", "output": "Yes\n"}, {"input": "30019549241681999 20\n", "output": "Yes\n"}, {"input": "648000813924303839 16\n", "output": "Yes\n"}, {"input": "763169499725761451 488954176053755860\n", "output": "No\n"}, {"input": "199398459594277592 452260924647536414\n", "output": "No\n"}, {"input": "635627415167826436 192195636386541160\n", "output": "No\n"}, {"input": "71856370741375281 155502380685354417\n", "output": "No\n"}, {"input": "731457367464667229 118809129279134971\n", "output": "No\n"}, {"input": "167686318743248777 858743836723172421\n", "output": "No\n"}, {"input": "603915274316797622 822050585316952974\n", "output": "No\n"}, {"input": "647896534275160623 65689274138731296\n", "output": "No\n"}, {"input": "648722777453244047 501918229712280140\n", "output": "No\n"}, {"input": "649549020631327471 41923378183538525\n", "output": "No\n"}, {"input": "650375259514443599 597748177714153637\n", "output": "No\n"}, {"input": "651201506987494319 33977137582669778\n", "output": "No\n"}, {"input": "652027745870610447 470206093156218622\n", "output": "No\n"}, {"input": "652853989048693871 906435048729767466\n", "output": "No\n"}, {"input": "653680227931809999 342664004303316311\n", "output": "No\n"}, {"input": "654506475404860719 375019787446735639\n", "output": "No\n"}, {"input": "655332714287976847 438493956600157103\n", "output": "No\n"}, {"input": "166512305365727033 900267947832156186\n", "output": "No\n"}, {"input": "167338548543810457 336496907700672326\n", "output": "No\n"}, {"input": "168164787426926585 772725863274221171\n", "output": "No\n"}, {"input": "523 3\n", "output": "No\n"}, {"input": "39211 6\n", "output": "No\n"}, {"input": "22151 9\n", "output": "No\n"}, {"input": "1 3\n", "output": "No\n"}, {"input": "47 5\n", "output": "No\n"}, {"input": "999999998999999999 1000000000\n", "output": "No\n"}, {"input": "11 6\n", "output": "No\n"}, {"input": "7 4\n", "output": "No\n"}, {"input": "1 10\n", "output": "No\n"}, {"input": "9 5\n", "output": "No\n"}, {"input": "2519 20\n", "output": "No\n"}, {"input": "700001 3\n", "output": "Yes\n"}, {"input": "13 7\n", "output": "No\n"}, {"input": "999999 10000\n", "output": "No\n"}, {"input": "1 4\n", "output": "No\n"}, {"input": "232792559 30\n", "output": "No\n"}, {"input": "1 5\n", "output": "No\n"}, {"input": "5 4\n", "output": "No\n"}, {"input": "5 8\n", "output": "No\n"}, {"input": "55 4\n", "output": "No\n"}] |
|
136 | You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input().
-----Input-----
The first line contains a non-negative integer a.
The second line contains a non-negative integer b.
The numbers a, b may contain leading zeroes. Each of them contains no more than 10^6 digits.
-----Output-----
Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=".
-----Examples-----
Input
9
10
Output
<
Input
11
10
Output
>
Input
00012345
12345
Output
=
Input
0123
9
Output
>
Input
0123
111
Output
> | interview | [{"code": "a = input()\nb = input()\nn, m = len(a), len(b)\nif n > m: b = '0' * (n - m) + b\nelse: a = '0' * (m - n) + a\ni = 0\nwhile i < max(n, m) and a[i] == b[i]:\n i += 1\nprint('=' if i == max(n, m) else '<' if int(a[i]) < int(b[i]) else '>')\n", "passed": true, "time": 0.15, "memory": 14644.0, "status": "done"}, {"code": "#! /usr/bin/env python\n# -*- coding: utf-8 -*-\n# vim:fenc=utf-8\n#\n# Copyright \u00a9 2016 missingdays <missingdays@missingdays>\n#\n# Distributed under terms of the MIT license.\n\n\"\"\"\n\n\"\"\"\n\ndef calc(a, b, l):\n for i in range(l):\n if int(a[i]) > int(b[i]):\n return \">\"\n elif int(a[i]) < int(b[i]):\n return \"<\"\n\n return \"=\" \n\na = input()\nb = input()\n\nal = len(a)\nbl = len(b)\n\nif bl > al:\n a = \"0\" * (bl - al) + a\n al = bl\nelif al > bl:\n b = \"0\" * (al - bl) + b\n bl = al\n\nprint(calc(a, b, bl))\n", "passed": true, "time": 0.16, "memory": 14516.0, "status": "done"}, {"code": "def main():\n a = input()\n b = input()\n x = max(len(a), len(b))\n a = \"0\" * (x - len(a)) + a\n b = \"0\" * (x - len(b)) + b\n\n if a > b:\n print(\">\")\n elif a < b:\n print(\"<\")\n else:\n print(\"=\")\n\nmain()\n", "passed": true, "time": 0.16, "memory": 14628.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport time\n\ndef nz(x):\n a = 0\n for i in range(len(x)):\n if x[i] == '0':\n a += 1\n else:\n break\n return x[a:]\n\na = list(input())\nb = list(input())\n\nstart = time.time()\n\na = nz(a)\nb = nz(b)\n\nif len(a) == len(b):\n flag = True\n for i in range(len(a)):\n if a[i] < b[i]:\n print('<')\n flag = False\n break\n elif a[i] > b[i]:\n print('>')\n flag = False\n break\n if flag == True:\n print('=')\nelif len(a) < len(b):\n print('<')\nelse:\n print('>')\nfinish = time.time()\n#print(finish - start)\n", "passed": true, "time": 0.96, "memory": 14572.0, "status": "done"}, {"code": "import sys\n\n# fin = open(\"ecr5a.in\", \"r\")\nfin = sys.stdin\n\na, b = fin.readline().rstrip().lstrip('0'), fin.readline().rstrip().lstrip('0')\n\nif len(a) < len(b):\n print('<')\nelif len(a) > len(b):\n print('>')\nelse:\n for i in range(len(a)):\n if a[i] == b[i]:\n continue\n elif a[i] < b[i]:\n print('<')\n break\n else:\n print('>')\n break\n else:\n print('=')", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}, {"code": "def clz(s):\n n = 0\n for i in range(len(s)):\n if s[i] == '0':\n n += 1\n else:\n break\n return n\n\n\ndef solve():\n A = input()\n B = input()\n\n lza = clz(A)\n lzb = clz(B)\n\n la = len(A) - lza\n lb = len(B) - lzb\n\n if la > lb:\n print('>')\n elif la < lb:\n print('<')\n else:\n for i in range(la):\n if A[lza + i] > B[lzb+i]:\n print('>')\n break\n elif A[lza + i] < B[lzb+i]:\n print('<')\n break\n else:\n print('=')\n\n\ndef __starting_point():\n solve()\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14900.0, "status": "done"}, {"code": "def preprocess(g):\n g = input()\n g = list(g)\n r = len(g)-1\n for i in range(0,len(g)):\n if g[i] > '0':\n r = i\n break\n g = g[r:]\n return \"\".join(g)\n[g,h] = [1,1]\ng = preprocess(g)\nh = preprocess(h)\nif len(g) < len(h):\n print(\"<\")\nelif len(g) > len(h):\n print(\">\")\nelse:\n if g < h:\n print(\"<\")\n elif g > h:\n print(\">\")\n else:\n print(\"=\")\n", "passed": true, "time": 0.28, "memory": 14656.0, "status": "done"}, {"code": "def c(a, b):\n for x, y in zip(a, b):\n if x > y:\n return '>'\n elif x < y:\n return '<'\n return '='\na, b = input(), input()\nif len(a) < len(b):\n a = '0' * (len(b) - len(a)) + a\nelif len(a) > len(b):\n b = '0' * (len(a) - len(b)) + b\nprint(c(a, b))", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "a = input()\nb = input()\ni = 0\nwhile i < len(a) and a[i] == '0':\n i += 1\n\nj = 0\nwhile j < len(b) and b[j] == '0':\n j += 1\n\na = a[i::]\nif a == '':\n a = '0'\nb = b[j::]\nif b == '':\n b = '0'\nif len(a) > len(b):\n print('>')\nelif len(b) > len(a):\n print('<')\nelse:\n i = 0\n while i < len(a) and a[i] == b[i]:\n i += 1\n if i == len(a):\n print('=')\n else:\n if a[i] > b[i]:\n print('>')\n else:\n print('<')", "passed": true, "time": 0.15, "memory": 14536.0, "status": "done"}, {"code": "a = str(input())\nb = str(input())\nlen1 = len(a)\nlen2 = len(b)\nfirst1 = -1\nfirst2 = -1\nfor i in range(len1):\n if a[i] != '0'and first1 == -1:\n first1 = i\n break\nfor i in range(len2):\n if b[i] != '0' and first2 == -1:\n first2 = i\n break\nflag = 0\nif first1 == -1:\n first1 = len1 - 1\nif first2 == -1:\n first2 = len2 - 1\nif len1 - first1 > len2 - first2 :\n flag = 1\n print('>')\nelif len1 - first1 < len2 - first2:\n flag = 1\n print('<')\nelse:\n for i in range(first1, len1):\n if a[i] > b[i-first1+first2]:\n flag = 1\n print('>')\n break\n elif a[i] < b[i-first1+first2]:\n flag = 1\n print('<')\n break\nif flag == 0:\n print('=')", "passed": true, "time": 0.14, "memory": 14420.0, "status": "done"}, {"code": "a = input()\nb = input()\n\ndef delL(inp):\n out = ''\n flag = False\n for i in inp:\n if i != '0':\n flag = True\n if flag:\n out = out + i\n if out == '':\n return '0'\n return out\n \na = delL(a)\nb = delL(b)\n\nif len(a) > len(b):\n print('>')\nelif len(a) < len(b):\n print('<')\nelse:\n flag = False\n for i in range(len(a)):\n if a[i] > b[i]:\n flag = True\n print('>')\n break\n elif a[i] < b[i]:\n flag = True\n print('<')\n break\n if flag == False: \n print('=') \n", "passed": true, "time": 0.14, "memory": 14544.0, "status": "done"}, {"code": "a = input()\nb = input()\ni = 0\nj = 0\nn = len(a)\nm = len(b)\nwhile i < n and a[i] == '0':\n i += 1\nwhile j < m and b[j] == '0':\n j += 1\nif n - i > m - j:\n print(\">\")\nelif n - i < m - j:\n print(\"<\")\nelse:\n while i < n:\n if a[i] > b[j]:\n print(\">\")\n break\n elif a[i] < b[j]:\n print(\"<\")\n break\n else:\n i += 1\n j += 1\n else: \n print(\"=\")", "passed": true, "time": 0.15, "memory": 14588.0, "status": "done"}, {"code": "# your code goes here\na = (input())\nb = (input())\nj = 0\nfor i in range(len(a)):\n\tif a[i] == '0':\n\t\tj+=1\n\telse: \n\t\tbreak\na = a[j:]\nj = 0\nfor i in range(len(b)):\n\tif b[i] == '0':\n\t\tj+=1\n\telse: \n\t\tbreak\nb = b[j:]\nflag = 0\nif len(a)> len(b):\n\tprint (\">\")\nelif len(a)<len(b):\n\tprint (\"<\")\nelse:\n\tfor i in range(len(a)):\n\t\tif (a[i]>b[i]):\n\t\t\tflag = 1\n\t\t\tbreak\n\t\telif (a[i]<b[i]):\n\t\t\tflag = 2\n\t\t\tbreak\n\t\telse:\n\t\t\tcontinue\n\tif (flag == 0):\n\t\tprint (\"=\")\n\telif (flag == 1):\n\t\tprint (\">\")\n\telse:\n\t\tprint (\"<\")\n", "passed": true, "time": 0.14, "memory": 14416.0, "status": "done"}, {"code": "x = input()\ny = input()\na = \"\"\nb = \"\"\nflag = 0\nfor i in range(0,len(x)):\n if flag != 0 : a = a + x[i]\n elif x[i] != '0':\n flag = 1\n a = a + x[i]\nflag = 0\nfor i in range(0,len(y)):\n if flag != 0 : b = b + y[i]\n elif flag == 0 and y[i] == 0: continue\n elif y[i] != '0':\n flag = 1\n b = b + y[i]\nlen1 = len(a)\nlen2 = len(b)\n\n\nif len1 > len2: print(\">\")\nelif len2 > len1: print(\"<\")\nelse:\n flag = 0\n for i in range(0,len1):\n if flag == 1: break\n if a[i] > b[i]:\n print(\">\")\n flag = 1\n elif b[i] > a[i]:\n print(\"<\")\n flag = 1\n if flag == 0:\n print(\"=\")", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "a=input().lstrip('0')\nb=input().lstrip('0')\ndlinaA=len(a)\ndlinaB=len(b)\nif dlinaA==0:\n a='0'\nif dlinaB==0:\n b='0'\nif dlinaA==0 and dlinaB==0:\n print('=')\nif dlinaA>dlinaB:\n print('>')\nelif dlinaA<dlinaB:\n print('<')\nelse:\n for i in range(dlinaA):\n if int(a[i])>int(b[i]):\n print('>')\n break\n elif int(a[i])<int(b[i]):\n print('<')\n break\n elif i==dlinaA-1:\n print('=')\n break\n\n", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}, {"code": "a=input().lstrip('0')\nb=input().lstrip('0')\ndlinaA=len(a)\ndlinaB=len(b)\nif dlinaA==0:\n a='0'\nif dlinaB==0:\n b='0'\nif dlinaA==0 and dlinaB==0:\n print('=')\nif dlinaA>dlinaB:\n print('>')\nelif dlinaA<dlinaB:\n print('<')\nelse:\n for i in range(dlinaA):\n if int(a[i])>int(b[i]):\n print('>')\n break\n elif int(a[i])<int(b[i]):\n print('<')\n break\n elif i==dlinaA-1:\n print('=')\n break\n\n", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "a=input()\nb=input()\n\na=a.lstrip(\"0\")\nb=b.lstrip(\"0\")\n\nif a==\"\":\n a=\"0\"\nelse:\n pass\nif b==\"\":\n b=\"0\"\nelse:\n pass\n\nla=len(a)\nlb=len(b)\n\nif la>lb:\n print(\">\")\n\nelif la<lb:\n print(\"<\")\n\nelif la==lb:\n i=0\n while int(a[i])==int(b[i]) and i+1!=la:\n i+=1\n if i+1==la and int(a[i])==int(b[i]):\n print(\"=\")\n elif int(a[i])<int(b[i]):\n print(\"<\")\n elif int(a[i])>int(b[i]):\n print(\">\")", "passed": true, "time": 0.16, "memory": 14648.0, "status": "done"}, {"code": "a = str(input())\nb = str(input())\n\na = a.lstrip('0')\n\nb = b.lstrip('0')\nflag = True\n\nif len(a) > len(b):\n print(\">\")\n flag = False\nelif len(a) < len(b):\n print('<')\n flag = False\n\n\nif flag:\n flag1 = True\n\n for i in range(len(a)):\n if (int(a[i]) > int(b[i])):\n print('>')\n flag1 = False\n break\n if (int(a[i]) < int(b[i])):\n print(\"<\")\n flag1 = False\n break\n\n if (flag1):\n print('=')", "passed": true, "time": 0.15, "memory": 14604.0, "status": "done"}, {"code": "import sys\n\na = sys.stdin.readline().split()[0]\nb = sys.stdin.readline().split()[0]\ni, j = 0, 0\nif (len(a) < len(b)):\n a = '0' * (len(b) - len(a)) + a\nelse:\n b = '0' * (len(a) - len(b)) + b\nwhile (i < len(a)) and (j < len(b)) and (a[i] == b[j]):\n i += 1\n j += 1\nif (i == len(a)) and (j == len(b)):\n print('=')\nelif j == len(b):\n print('>')\nelif i == len(a):\n print('<')\nelse:\n #print(')')\n print('<' if (a[i] < b[j]) else '>')", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "a = input()\nb = input()\nif len(a)>len(b):\n gap = len(a)-len(b)\n new = ''\n for _ in range(gap):\n new+='0'\n b = new + b\nelif len(b)>len(a):\n gap = len(b) - len(a)\n new = ''\n for _ in range(gap):\n new+='0'\n a = new + a\nfor i in range(0,len(a)):\n if(a[i]>b[i]):\n print('>')\n return\n elif(b[i]>a[i]):\n print('<')\n return\nprint('=') ", "passed": true, "time": 0.14, "memory": 14432.0, "status": "done"}, {"code": "a = input()\nb = input()\nif len(a)>len(b):b = '0'*(len(a)-len(b)) + b\nelse:a = '0'*(len(b)-len(a)) + a\nfor i in range(0,len(a)):\n if(a[i]>b[i]):\n print('>')\n return\n elif(b[i]>a[i]):\n print('<')\n return\nprint('=') ", "passed": true, "time": 0.14, "memory": 14580.0, "status": "done"}, {"code": "a = input()\nb = input()\nif len(a)>len(b):b = '0'*(len(a)-len(b)) + b\nelse:a = '0'*(len(b)-len(a)) + a\nif(a>b):print('>')\nelif(b>a):print('<')\nelse:print('=') ", "passed": true, "time": 0.14, "memory": 14528.0, "status": "done"}, {"code": "a = input()\nb = input()\n\n\ndef remove_zeroes(s: str):\n i = 0\n for x in range(len(s) - 1):\n if s[x] == '0':\n i += 1\n else:\n break\n return s[i:]\n\na = remove_zeroes(a)\nb = remove_zeroes(b)\n\nif len(a) != len(b):\n if len(a) > len(b):\n print('>')\n else:\n print('<')\n return\n\ncmp1 = a > b\ncmp2 = a < b\n\nif cmp1:\n print('>')\nelif cmp2:\n print('<')\nelse:\n print('=')\n", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "s=input()\ns1=input()\n\nif len(s)>len(s1):\n s1='0'*(len(s)-len(s1))+s1\nelse : \n s='0'*(len(s1)-len(s))+s\n\n\n\nif(s>s1):\n print('>')\nelif(s<s1):\n print ('<')\nelse:\n print ('=')", "passed": true, "time": 0.14, "memory": 14516.0, "status": "done"}] | [{"input": "9\n10\n", "output": "<\n"}, {"input": "11\n10\n", "output": ">\n"}, {"input": "00012345\n12345\n", "output": "=\n"}, {"input": "0123\n9\n", "output": ">\n"}, {"input": "0123\n111\n", "output": ">\n"}, {"input": "9\n9\n", "output": "=\n"}, {"input": "0\n0000\n", "output": "=\n"}, {"input": "1213121\n1213121\n", "output": "=\n"}, {"input": "8631749422082281871941140403034638286979613893271246118706788645620907151504874585597378422393911017\n1460175633701201615285047975806206470993708143873675499262156511814213451040881275819636625899967479\n", "output": ">\n"}, {"input": "6421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798\n8\n", "output": ">\n"}, {"input": "9\n3549746075165939381145061479392284958612916596558639332310874529760172204736013341477640605383578772\n", "output": "<\n"}, {"input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "output": "=\n"}, {"input": "0000000001\n2\n", "output": "<\n"}, {"input": "1000000000000000000000000000000000\n1000000000000000000000000000000001\n", "output": "<\n"}, {"input": "123456123456123456123456123456123456123456123456123456123456123456\n123456123456123456123456123456123456123456123456123456123456123456123456123456\n", "output": "<\n"}, {"input": "1111111111111111111111111111111111111111\n2222222222222222222222222222222222222222\n", "output": "<\n"}, {"input": "123456789999999\n123456789999999\n", "output": "=\n"}, {"input": "111111111111111111111111111111\n222222222222222222222222222222\n", "output": "<\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111\n", "output": "=\n"}, {"input": "587345873489573457357834\n47957438573458347574375348\n", "output": "<\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333\n", "output": "<\n"}, {"input": "11111111111111111111111111111111111\n44444444444444444444444444444444444\n", "output": "<\n"}, {"input": "11111111111111111111111111111111111\n22222222222222222222222222222222222\n", "output": "<\n"}, {"input": "9999999999999999999999999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n", "output": "<\n"}, {"input": "1\n2\n", "output": "<\n"}, {"input": "9\n0\n", "output": ">\n"}, {"input": "222222222222222222222222222222222222222222222222222222222\n22222222222222222222222222222222222222222222222222222222222\n", "output": "<\n"}, {"input": "66646464222222222222222222222222222222222222222222222222222222222222222\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "output": "<\n"}, {"input": "222222222222222222222222222222222222222222222222222\n111111111111111111111111111111111111111111111111111111111111111\n", "output": "<\n"}, {"input": "11111111111111111111111111111111111111\n44444444444444444444444444444444444444\n", "output": "<\n"}, {"input": "01\n2\n", "output": "<\n"}, {"input": "00\n01\n", "output": "<\n"}, {"input": "99999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999\n", "output": "=\n"}, {"input": "43278947323248843213443272432\n793439250984509434324323453435435\n", "output": "<\n"}, {"input": "0\n1\n", "output": "<\n"}, {"input": "010\n011\n", "output": "<\n"}, {"input": "999999999999999999999999999999999999999999999999\n999999999999999999999999999999999999999999999999\n", "output": "=\n"}, {"input": "0001001\n0001010\n", "output": "<\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111\n", "output": "=\n"}, {"input": "00000\n00\n", "output": "=\n"}, {"input": "999999999999999999999999999\n999999999999999999999999999\n", "output": "=\n"}, {"input": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n", "output": "=\n"}, {"input": "001\n000000000010\n", "output": "<\n"}, {"input": "01\n10\n", "output": "<\n"}, {"input": "555555555555555555555555555555555555555555555555555555555555\n555555555555555555555555555555555555555555555555555555555555\n", "output": "=\n"}, {"input": "5555555555555555555555555555555555555555555555555\n5555555555555555555555555555555555555555555555555\n", "output": "=\n"}, {"input": "01\n02\n", "output": "<\n"}, {"input": "001111\n0001111\n", "output": "=\n"}, {"input": "55555555555555555555555555555555555555555555555555\n55555555555555555555555555555555555555555555555555\n", "output": "=\n"}, {"input": "1029301293019283091283091283091280391283\n1029301293019283091283091283091280391283\n", "output": "=\n"}, {"input": "001\n2\n", "output": "<\n"}, {"input": "000000000\n000000000\n", "output": "=\n"}, {"input": "000000\n10\n", "output": "<\n"}, {"input": "000000000000000\n001\n", "output": "<\n"}, {"input": "0000001\n2\n", "output": "<\n"}, {"input": "0000\n123\n", "output": "<\n"}, {"input": "951\n960\n", "output": "<\n"}, {"input": "002\n0001\n", "output": ">\n"}, {"input": "0000001\n01\n", "output": "=\n"}, {"input": "99999999999999999999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999999999999999999\n", "output": "=\n"}, {"input": "12345678901234567890123456789012345678901234567890123456789012\n12345678901234567890123456789012345678901234567890123456789012\n", "output": "=\n"}, {"input": "02\n01\n", "output": ">\n"}, {"input": "00000111111\n00000110111\n", "output": ">\n"}, {"input": "0123\n123\n", "output": "=\n"}, {"input": "123771237912798378912\n91239712798379812897389123123123123\n", "output": "<\n"}, {"input": "00001\n002\n", "output": "<\n"}, {"input": "0000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", "output": "=\n"}, {"input": "000000001\n00002\n", "output": "<\n"}, {"input": "00002\n00003\n", "output": "<\n"}, {"input": "000123456\n123457\n", "output": "<\n"}, {"input": "01\n00\n", "output": ">\n"}, {"input": "00\n0\n", "output": "=\n"}, {"input": "10\n11\n", "output": "<\n"}, {"input": "0011\n12\n", "output": "<\n"}, {"input": "00\n1\n", "output": "<\n"}, {"input": "0\n0\n", "output": "=\n"}, {"input": "00\n10\n", "output": "<\n"}, {"input": "011\n10\n", "output": ">\n"}, {"input": "00011111111111111111111111111111111111000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000011000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112091\n", "output": "<\n"}, {"input": "0000001\n00\n", "output": ">\n"}, {"input": "01\n1\n", "output": "=\n"}, {"input": "010\n001\n", "output": ">\n"}, {"input": "100\n111\n", "output": "<\n"}, {"input": "1\n0\n", "output": ">\n"}, {"input": "000000\n000000000000000000000\n", "output": "=\n"}, {"input": "010101\n010101\n", "output": "=\n"}, {"input": "00000000000000000001111111111111111111111111111111111111111111111111111111\n11111111111111111111111\n", "output": ">\n"}, {"input": "0000000\n0\n", "output": "=\n"}, {"input": "187923712738712879387912839182381\n871279397127389781927389718923789178923897123\n", "output": "<\n"}, {"input": "0010\n030\n", "output": "<\n"}] |
|
138 | Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of three copybooks for c rubles. Alyona already has n copybooks.
What is the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.
-----Input-----
The only line contains 4 integers n, a, b, c (1 ≤ n, a, b, c ≤ 10^9).
-----Output-----
Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4.
-----Examples-----
Input
1 1 3 4
Output
3
Input
6 2 1 1
Output
1
Input
4 4 4 4
Output
0
Input
999999999 1000000000 1000000000 1000000000
Output
1000000000
-----Note-----
In the first example Alyona can buy 3 packs of 1 copybook for 3a = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally.
In the second example Alyuna can buy a pack of 2 copybooks for b = 1 ruble. She will have 8 copybooks in total.
In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything.
In the fourth example Alyona should buy one pack of one copybook. | interview | [{"code": "n, a, b, c = map(int, input().split())\nres = 10 ** 100\nfor i in range(50):\n for j in range(50):\n for k in range(50):\n if (n + i + 2 * j + 3 * k) % 4 == 0:\n res = min(res, a * i + b * j + c * k)\nprint(res)", "passed": true, "time": 4.19, "memory": 14388.0, "status": "done"}, {"code": "n, a, b, c = list(map(int, input().split()))\na = [0, a, b, c]\nfor _ in range(100):\n for i in range(4):\n for j in range(4):\n to = (i + j) % 4\n if a[to] > a[i] + a[j]:\n a[to] = a[i] + a[j]\n\nprint(a[(4 - n % 4) % 4])\n", "passed": true, "time": 0.2, "memory": 14572.0, "status": "done"}, {"code": "n, a, b, c = list(map(int, input().split()))\nans = int(1e18)\nfor i in range(4):\n for j in range(2):\n for k in range(4):\n if (n + i + 2 * j + 3 * k) % 4 == 0:\n ans = min(ans, i * a + j * b + k * c)\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14360.0, "status": "done"}, {"code": "n,a,b,c=[int(i) for i in input().split()]\nans=10**11\nfor i in range(4):\n for j in range(4):\n for k in range(4):\n if (n+i+j*2+k*3)%4==0:\n ans=min(ans,a*i+b*j+c*k)\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14396.0, "status": "done"}, {"code": "n, a, b, c = list(map(int, input().split()))\nif n % 4 == 0:\n print(0)\nif n % 4 == 3:\n print(min(a, 3 * c, b + c))\nif n % 4 == 2:\n print(min(b, 2 * a, 2 * c))\nif n % 4 == 1:\n print(min(c, 3 * a, b + a))", "passed": true, "time": 0.25, "memory": 14532.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\ndef main():\n try:\n while True:\n n, a, b, c = list(map(int, input().split()))\n result = 1e20\n for ia in range(4):\n for ib in range(4):\n for ic in range(4):\n x = n + ia + (ib << 1) + ic * 3\n if x & 0x3 == 0:\n result = min(result, ia * a + ib * b + ic * c)\n print(result)\n\n except EOFError:\n pass\n\nmain()\n", "passed": true, "time": 0.2, "memory": 14648.0, "status": "done"}, {"code": "n, a, b, c = map(int,input().split())\nost = (-n) % 4\nif ost == 0:\n print(0)\nelif ost == 1:\n print(min(a, 3 * c, b + c))\nelif ost == 2:\n print(min(2 * a, b, 2 * c))\nelse:\n print(min(3 * a, c, b + a))", "passed": true, "time": 0.17, "memory": 14424.0, "status": "done"}, {"code": "import math,sys,re,itertools,pprint,collections,copy\nrs,ri,rai,raf=input,lambda:int(input()),lambda:list(map(int, input().split())),lambda:list(map(float, input().split()))\n\nn, a, b, c = rai()\ns = float(\"inf\")\n\nfor ia in range(5):\n for ib in range(5):\n for ic in range(5):\n k = ia + 2*ib + 3*ic\n if (n + k) % 4 != 0:\n continue\n s = min(s, ia * a + ib * b + ic * c)\n\nprint(s)\n\n", "passed": true, "time": 0.16, "memory": 14468.0, "status": "done"}, {"code": "n, a, b, c = [int(x) for x in input().split()]\n\nmin_sum = 10 * (a + b + c)\n\nfor i in range(4):\n for j in range(4):\n for k in range(4):\n if (n + 1*i + 2*j + 3*k) % 4 == 0:\n min_sum = min(min_sum, i*a + j*b + k*c)\n\nprint(min_sum)", "passed": true, "time": 0.15, "memory": 14636.0, "status": "done"}, {"code": "n, a, b, c = list(map(int, input().split()))\nk = 4 - (n % 4)\nif k == 4:\n print(0)\nelif k == 1:\n print(min(a, c * 3, b + c))\nelif k == 2:\n print(min(2 * a, b, 2 * c))\nelif k == 3:\n print(min(3 * a, c, b + a))\n", "passed": true, "time": 0.25, "memory": 14616.0, "status": "done"}, {"code": "def solve():\n x=list(map(int,input().split()))\n remainder=x[0]%4\n if remainder==0:\n return 0;\n elif remainder==2:\n return min(2*x[1],x[2],2*x[3]);\n elif remainder==1:\n return min(3*x[1],x[1]+x[2],x[3]);\n else:\n return min(x[1],x[2]+x[3],x[3]*3);\n\n\nprint(solve())\n \n \n", "passed": true, "time": 0.15, "memory": 14476.0, "status": "done"}, {"code": "n, a, b, c = list(map(int, input().split()))\n\nsum = -1\n\nfor A in range(4):\n for B in range(3):\n for C in range(4):\n N = n + A + B * 2 + C * 3\n if N % 4 == 0:\n if sum == -1 or A * a + B * b + C * c < sum:\n sum = A * a + B * b + C * c\n\nprint (sum)\n", "passed": true, "time": 0.15, "memory": 14612.0, "status": "done"}, {"code": "n,a,b,c = (int(i) for i in input().split())\nif n%4 == 0:\n print(0)\nelse:\n ans = 10**11\n for i in range(5):\n for j in range(5):\n for k in range(5):\n if (n+i*1+j*2+k*3)%4 == 0:\n ans = min(ans,i*a+b*j+c*k)\n print(ans)", "passed": true, "time": 0.15, "memory": 14568.0, "status": "done"}, {"code": "n, a, b, c = map(int, input().split())\nif not n % 4:\n print(0)\nelif n % 4 == 3:\n print(min(a, c + b, c * 3))\nelif n % 4 == 2:\n print(min(2 * a, b, 2 * c))\nelif n % 4 == 1:\n print(min(3 * a, b + a, c))", "passed": true, "time": 0.15, "memory": 14592.0, "status": "done"}, {"code": "n,a,b,c=[int(i) for i in input().split()]\nif n%4==0:\n print(0)\nif n%4==1:\n print(min(3*a,a+b,c))\nif n%4==2:\n print(min(2*a,b,2*c))\nif n%4==3:\n print(min(a,b+c,3*c))", "passed": true, "time": 0.15, "memory": 14712.0, "status": "done"}, {"code": "n,a,b,c = list(map(int, input().split()))\nl = []\nif (n%4==0):\n l = [0]\nelif(n%4==1):\n l = [3*a,a+b,c]\nelif(n%4==2):\n l = [2*a, b, 2*c]\nelse:\n l = [a, b+c, 3*c]\n\nmini = min(l)\nprint(mini)\n", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "n, a, b, c = map(int, input().split())\nmn = 10 ** 12\narr = [0, a, b, c]\nfor i in range(30):\n for j in range(30):\n q = (4 - (n % 4 + i * 3 + j * 2) % 4) % 4\n mn = min(mn, arr[3] * i + arr[2] * j + arr[1] * q)\nprint(mn)", "passed": true, "time": 0.31, "memory": 14560.0, "status": "done"}, {"code": "n, a, b, c = map(int, input().split())\nif n % 4 == 0:\n print(0)\nelif n % 4 == 1:\n print(min(c, a*3, a+b))\nelif n % 4 == 2:\n print(min(c*2, b, a*2))\nelse:#n % 4 == 3\n print(min(a, b+c, 3*c))", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "n, a, b, c = list(map(int, input().split()))\nres = 10000000000\nfor i in range(10):\n for j in range(10):\n for k in range(10):\n if (n + i + j*2 + k*3)%4 == 0:\n res = min(res, i*a + j*b + k*c)\n\nprint(res)\n", "passed": true, "time": 0.26, "memory": 14580.0, "status": "done"}, {"code": "n, one,two,three = (int(x) for x in input().split())\n\nn = n%4\nif n == 3:\n print(min(one,3*three,two + three))\nelif n == 2:\n print(min(2*one,two,2*three))\nelif n == 1:\n print(min(3*one,two+one,three))\nelse:\n print(0)", "passed": true, "time": 0.15, "memory": 14500.0, "status": "done"}, {"code": "n, a, b, c = map(int, input().split())\nm = 10**12\nfor i in range(30):\n for j in range(30):\n for k in range(30):\n if (n+i+2*j+3*k) % 4:\n continue\n m = min(m, i*a+j*b+k*c)\nprint(m)", "passed": true, "time": 0.54, "memory": 14492.0, "status": "done"}, {"code": "3\n\nn,a,b,c = [int(x) for x in input().strip().split()]\n\nif n%4 == 0:\n\tprint(0)\nelif n%4 == 1:\n\tprint(min(3*a,a+b,c))\nelif n%4 == 2:\n\tprint(min(2*a,b,2*c))\nelse:\n\tprint(min(a,b+c,3*c))", "passed": true, "time": 0.24, "memory": 14448.0, "status": "done"}, {"code": "n, a, b, c = list(map(int, input().split()))\nif n % 4 == 0:\n print(0)\nelif n % 4 == 1:\n print(min(3*a, a + b, c))\nelif n % 4 == 2:\n print(min(2*a, b, 2 * c))\nelif n % 4 == 3:\n print(min(a, b + c, 3 * c))\n\n", "passed": true, "time": 0.15, "memory": 14496.0, "status": "done"}, {"code": "\"\"\"\nATSTNG's ejudge Python3 solution template\n(actual solution is below)\n\"\"\"\nimport sys, queue\n\ntry:\n import dev_act_ffc429465ab634 # empty file in directory\n DEV = True\nexcept:\n DEV = False\n\ndef log(*s):\n if DEV: print('LOG', *s)\n\nclass EJudge:\n def __init__(self, problem=\"default\", reclim=1<<30):\n self.problem = problem\n sys.setrecursionlimit(reclim)\n\n def use_files(self, infile='', outfile=''):\n if infile!='':\n self.infile = open(infile)\n sys.stdin = self.infile\n if infile!='':\n self.outfile = open(outfile, 'w')\n sys.stdout = self.outfile\n\n def use_bacs_files(self):\n self.use_files(self.problem+'.in', self.problem+'.out')\n\n def get_tl(self):\n while True: pass\n\n def get_ml(self):\n tmp = [[[5]*100000 for _ in range(1000)]]\n while True: tmp.append([[5]*100000 for _ in range(1000)])\n\n def get_re(self):\n s = (0,)[8]\n\n def get_wa(self, wstr='blablalblah'):\n for _ in range(3): print(wstr)\n return\n\nclass IntReader:\n def __init__(self):\n self.ost = queue.Queue()\n\n def get(self):\n return int(self.sget())\n\n def sget(self):\n if self.ost.empty():\n for el in input().split():\n self.ost.put(el)\n return self.ost.get()\n\n def release(self):\n res = []\n while not self.ost.empty():\n res.append(self.ost.get())\n return res\n\n###############################################################################\nej = EJudge( )\nint_reader = IntReader()\nfmap = lambda f,*l: list(map(f,*l))\nparse_int = lambda: fmap(int, input().split())\n\n# input\nn,t1,t2,t3 = parse_int()\nt3 = min(t3, t2+t1, t1*3)\nt2 = min(t2, t1*2, t3*2)\nt1 = min(t1, t3+t2, t3*3)\n\nn = n%4\nif n==0: ans = 0\nif n==1: ans = t3\nif n==2: ans = t2\nif n==3: ans = t1\n\nprint(ans)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "passed": true, "time": 0.15, "memory": 14528.0, "status": "done"}] | [{"input": "1 1 3 4\n", "output": "3\n"}, {"input": "6 2 1 1\n", "output": "1\n"}, {"input": "4 4 4 4\n", "output": "0\n"}, {"input": "999999999 1000000000 1000000000 1000000000\n", "output": "1000000000\n"}, {"input": "1016 3 2 1\n", "output": "0\n"}, {"input": "17 100 100 1\n", "output": "1\n"}, {"input": "17 2 3 100\n", "output": "5\n"}, {"input": "18 1 3 3\n", "output": "2\n"}, {"input": "19 1 1 1\n", "output": "1\n"}, {"input": "999999997 999999990 1000000000 1000000000\n", "output": "1000000000\n"}, {"input": "999999998 1000000000 999999990 1000000000\n", "output": "999999990\n"}, {"input": "634074578 336470888 481199252 167959139\n", "output": "335918278\n"}, {"input": "999999999 1000000000 1000000000 999999990\n", "output": "1000000000\n"}, {"input": "804928248 75475634 54748096 641009859\n", "output": "0\n"}, {"input": "535590429 374288891 923264237 524125987\n", "output": "524125987\n"}, {"input": "561219907 673102149 496813081 702209411\n", "output": "673102149\n"}, {"input": "291882089 412106895 365329221 585325539\n", "output": "585325539\n"}, {"input": "757703054 5887448 643910770 58376259\n", "output": "11774896\n"}, {"input": "783332532 449924898 72235422 941492387\n", "output": "0\n"}, {"input": "513994713 43705451 940751563 824608515\n", "output": "131116353\n"}, {"input": "539624191 782710197 514300407 2691939\n", "output": "8075817\n"}, {"input": "983359971 640274071 598196518 802030518\n", "output": "640274071\n"}, {"input": "8989449 379278816 26521171 685146646\n", "output": "405799987\n"}, {"input": "34618927 678092074 895037311 863230070\n", "output": "678092074\n"}, {"input": "205472596 417096820 468586155 41313494\n", "output": "0\n"}, {"input": "19 5 1 2\n", "output": "3\n"}, {"input": "17 1 2 2\n", "output": "2\n"}, {"input": "18 3 3 1\n", "output": "2\n"}, {"input": "19 4 3 1\n", "output": "3\n"}, {"input": "936134778 715910077 747167704 219396918\n", "output": "438793836\n"}, {"input": "961764255 454914823 615683844 102513046\n", "output": "307539138\n"}, {"input": "692426437 48695377 189232688 985629174\n", "output": "146086131\n"}, {"input": "863280107 347508634 912524637 458679894\n", "output": "347508634\n"}, {"input": "593942288 86513380 486073481 341796022\n", "output": "0\n"}, {"input": "914539062 680293934 764655030 519879446\n", "output": "764655030\n"}, {"input": "552472140 509061481 586588704 452405440\n", "output": "0\n"}, {"input": "723325809 807874739 160137548 335521569\n", "output": "335521569\n"}, {"input": "748955287 546879484 733686393 808572289\n", "output": "546879484\n"}, {"input": "774584765 845692742 162011045 691688417\n", "output": "691688417\n"}, {"input": "505246946 439473295 30527185 869771841\n", "output": "30527185\n"}, {"input": "676100616 178478041 604076030 752887969\n", "output": "0\n"}, {"input": "701730093 477291299 177624874 930971393\n", "output": "654916173\n"}, {"input": "432392275 216296044 751173719 109054817\n", "output": "216296044\n"}, {"input": "458021753 810076598 324722563 992170945\n", "output": "992170945\n"}, {"input": "188683934 254114048 48014511 170254369\n", "output": "48014511\n"}, {"input": "561775796 937657403 280013594 248004555\n", "output": "0\n"}, {"input": "1000000000 1000000000 1000000000 1000000000\n", "output": "0\n"}, {"input": "3 10000 10000 3\n", "output": "9\n"}, {"input": "3 12 3 4\n", "output": "7\n"}, {"input": "3 10000 10000 1\n", "output": "3\n"}, {"input": "3 1000 1000 1\n", "output": "3\n"}, {"input": "3 10 10 1\n", "output": "3\n"}, {"input": "3 100 100 1\n", "output": "3\n"}, {"input": "3 100000 10000 1\n", "output": "3\n"}, {"input": "7 10 2 3\n", "output": "5\n"}, {"input": "3 1000 1000 2\n", "output": "6\n"}, {"input": "1 100000 1 100000\n", "output": "100000\n"}, {"input": "7 4 3 1\n", "output": "3\n"}, {"input": "3 1000 1000 3\n", "output": "9\n"}, {"input": "3 1000 1 1\n", "output": "2\n"}, {"input": "3 10 1 1\n", "output": "2\n"}, {"input": "3 100000 1 1\n", "output": "2\n"}, {"input": "3 100 1 1\n", "output": "2\n"}, {"input": "3 100000 100000 1\n", "output": "3\n"}, {"input": "3 1000 1 100\n", "output": "101\n"}, {"input": "3 1000000000 1 1000000000\n", "output": "1000000000\n"}, {"input": "3 1000 1 10\n", "output": "11\n"}, {"input": "3 200 1 100\n", "output": "101\n"}, {"input": "7 4 1 1\n", "output": "2\n"}, {"input": "7 4 12 1\n", "output": "3\n"}, {"input": "3 9 1 1\n", "output": "2\n"}, {"input": "3 10000000 1000000 1\n", "output": "3\n"}, {"input": "7 1000 1000 1\n", "output": "3\n"}, {"input": "3 10000 1 30\n", "output": "31\n"}, {"input": "3 1000 1 2\n", "output": "3\n"}, {"input": "7 12 6 1\n", "output": "3\n"}, {"input": "3 100000 1 1000\n", "output": "1001\n"}, {"input": "7 1000 1000 3\n", "output": "9\n"}, {"input": "3 4 3 1\n", "output": "3\n"}, {"input": "3 3000000 1 100000\n", "output": "100001\n"}, {"input": "3 3 1 1\n", "output": "2\n"}, {"input": "3 10 1 5\n", "output": "6\n"}, {"input": "3 2000 2000 1\n", "output": "3\n"}, {"input": "3 10000000 10000000 1\n", "output": "3\n"}, {"input": "3 5 1 1\n", "output": "2\n"}, {"input": "3 100 1 33\n", "output": "34\n"}, {"input": "7 9 2 7\n", "output": "9\n"}, {"input": "4448 2 3 6\n", "output": "0\n"}, {"input": "2228 1 6 3\n", "output": "0\n"}] |
|
139 | You are given a 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 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).
-----Input-----
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).
-----Output-----
If it is possible to make this graph acyclic by removing at most one edge, print YES. Otherwise, print NO.
-----Examples-----
Input
3 4
1 2
2 3
3 2
3 1
Output
YES
Input
5 6
1 2
2 3
3 2
3 1
2 1
4 5
Output
NO
-----Note-----
In the first example you can remove edge $2 \rightarrow 3$, and the graph becomes acyclic.
In the second example you have to remove at least two edges (for example, $2 \rightarrow 1$ and $2 \rightarrow 3$) in order to make the graph acyclic. | interview | [{"code": "n,m = map(int, input().split())\ng = [[] for i in range(n)]\nfor _ in range(m):\n u,v = map(int, input().split())\n g[u-1].append(v-1)\n\nst = []\nvis = [0 for _ in range(n)]\nnxt = [0 for _ in range(n)]\nes = set()\ncycle=False\nfor i in range(n):\n if cycle:\n break\n if vis[i] != 0:\n continue\n st = [i]\n vis[i] = 1\n while len(st) > 0:\n v = st[-1]\n if nxt[v] < len(g[v]):\n u = g[v][nxt[v]]\n nxt[v] += 1\n if vis[u] == 0 or vis[u] == 2:\n vis[u] = 1\n st.append(u)\n else:\n ns = set()\n fr = len(st)-1\n to = u\n while 1:\n ns.add((st[fr], to))\n if st[fr] == u and len(ns) > 1:\n break\n elif st[fr] == u:\n ns.add((to, st[fr]))\n break\n to = st[fr]\n fr -= 1\n es = ns\n cycle =True\n break\n else:\n vis[v] = 2\n del st[-1]\nif not cycle:\n print('YES')\n return\nif len(es) == 50 and n == 500 and m == 100000:\n print('NO')\n return\nfor edge in es:\n vis = [0 for _ in range(n)]\n nxt = [0 for _ in range(n)]\n fail = False\n for i in range(n):\n if vis[i] != 0:\n continue\n st = [i]\n vis[i] = 1\n while len(st) > 0:\n v = st[-1]\n if nxt[v] < len(g[v]):\n u = g[v][nxt[v]]\n nxt[v] += 1\n if v == edge[0] and u == edge[1]:\n continue\n if vis[u] == 0 or vis[u] == 2:\n vis[u] = 1\n st.append(u)\n else:\n fail = True\n break\n else:\n vis[v] = 2\n del st[-1]\n if not fail:\n print('YES')\n return\nprint('NO')", "passed": true, "time": 0.25, "memory": 14548.0, "status": "done"}, {"code": "n, m = [int(x) for x in input().split()]\na = [[] for i in range(n)]\nfor i in range(m):\n u, v = [int(x) for x in input().split()]\n a[u - 1].append(v - 1)\n\ncolor = [0] * n # 0 - white, 1 - grey, 2 - black\ncycle = []\nblocked_u, blocked_v = -1, -1\n\ndef dfs(u):\n nonlocal color\n nonlocal cycle\n if color[u]:\n return\n color[u] = 1\n for v in a[u]:\n if u == blocked_u and v == blocked_v:\n continue\n if color[v] == 0:\n dfs(v)\n if color[v] == 1 or cycle:\n if not(cycle):\n cycle.append(v)\n cycle.append(u)\n return True\n color[u] = 2\n return False\n\ndef find_cycle():\n nonlocal color\n nonlocal cycle\n color = [0] * n # 0 - white, 1 - grey, 2 - black\n cycle = []\n for u in range(n):\n if dfs(u):\n break\n result = cycle[::-1]\n return {(result[i], result[(i + 1) % len(result)]) for i in range(len(result))}\n\ncur = find_cycle()\nif not(cur):\n print('YES')\n return\n\nfor bu, bv in cur:\n blocked_u = bu\n blocked_v = bv\n new = find_cycle()\n\n if not(new):\n print('YES')\n return\n\nprint('NO')\n", "passed": true, "time": 0.25, "memory": 14712.0, "status": "done"}, {"code": "def dfs(g, u, visited, call_stack):\n visited[u] = True\n call_stack.add(u)\n for v in g[u]:\n if v in call_stack:\n return [u, v]\n if not visited[v]:\n d = dfs(g, v, visited, call_stack)\n call_stack.discard(v)\n if d is not None:\n return [u] + d\n return None\n\n\ndef find_cycle(g, n):\n visited = [False] * n\n d = None\n for i in range(n):\n if not visited[i]:\n call_stack = set()\n d = dfs(g, i, visited, call_stack)\n if d is not None:\n break\n return d\n\n\ndef __starting_point():\n n, m = map(int, input().split())\n\n g = []\n for _ in range(n):\n g.append([])\n\n for _ in range(m):\n u, v = map(int, input().split())\n g[u-1].append(v-1)\n\n out = False\n c = find_cycle(g, n)\n if c:\n first_index = c.index(c[-1])\n c = c[first_index:]\n\n for i in range(len(c)-1):\n if i != 0:\n g[c[i-1]].append(c[i])\n g[c[i]].remove(c[i+1])\n out = out or find_cycle(g, n) is None\n else:\n out = True\n\n print('YES' if out else 'NO')\n__starting_point()", "passed": true, "time": 0.14, "memory": 14672.0, "status": "done"}, {"code": "cycle_begin, cycle_end = -1, -1\ng, mark, prev, edges = [], [], [], []\n\ndef dfs(u):\n nonlocal cycle_begin, cycle_end\n mark[u] = 1\n for v in g[u]:\n if mark[v] == 0:\n prev[v] = u\n if dfs(v):\n return True\n elif mark[v] == 1:\n cycle_begin = v\n cycle_end = u\n return True\n mark[u] = 2\n return False\n\ndef dfs2(u):\n mark[u] = 1\n for v in g[u]:\n if v != -1:\n if mark[v] == 0:\n if dfs2(v):\n return True\n elif mark[v] == 1:\n return True\n mark[u] = 2\n return False\n\nn, m = list(map(int, input().split()))\ng = [[] for i in range(n)]\nmark = [0 for i in range(n)]\nprev = [-1 for i in range(n)]\nfor i in range(m):\n u, v = list(map(int, input().split()))\n u -= 1\n v -= 1\n g[u].append(v)\nfor i in range(n):\n if mark[i] == 0 and dfs(i):\n break\nif cycle_begin == -1:\n print(\"YES\")\nelse:\n cycle = []\n i = cycle_end\n while i != cycle_begin:\n cycle.append(i)\n i = prev[i]\n cycle.append(cycle_begin)\n cycle.reverse()\n edges = []\n for i in range(len(cycle) - 1):\n edges.append(tuple((cycle[i], cycle[i + 1])))\n edges.append(tuple((cycle[len(cycle) - 1], cycle[0])))\n can = False\n while len(edges) > 0:\n f = edges[0][0]\n s = edges[0][1]\n g[f][g[f].index(s)] = -1\n mark = [0 for i in range(n)]\n have = False\n for i in range(n):\n if mark[i] == 0 and dfs2(i):\n have = True\n break\n g[f][g[f].index(-1)] = s\n if not have:\n can = True\n break\n edges.pop(0)\n if can:\n print(\"YES\") \n else:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14676.0, "status": "done"}, {"code": "cycle_begin, block_u, block_v = -1, -1, -1\ng, mark, prev, cycle = [], [], [], []\n\n\ndef dfs(u):\n nonlocal cycle_begin\n mark[u] = 1\n for v in g[u]:\n if u == block_u and v == block_v:\n continue\n if mark[v] == 0:\n prev[v] = u\n if dfs(v):\n return True\n elif mark[v] == 1:\n prev[v] = u\n cycle_begin = u\n return True\n mark[u] = 2\n return False\n\n\nn, m = list(map(int, input().split()))\n\ng = [[] for _ in range(n)]\nmark = [0 for _ in range(n)]\nprev = [0 for _ in range(n)]\n\nfor _ in range(m):\n u, v = list(map(int, input().split()))\n u -= 1\n v -= 1\n g[u].append(v)\n\nfor i in range(n):\n if mark[i] == 0 and dfs(i):\n break\n\nif cycle_begin == -1:\n print(\"YES\")\nelse:\n u = cycle_begin\n while u != cycle_begin or len(cycle) == 0:\n cycle.append(u)\n u = prev[u]\n cycle.append(cycle_begin)\n \n for u in range(len(cycle) - 1, 0, -1):\n block_u = cycle[u]\n block_v = cycle[u - 1]\n mark = [0 for _ in range(n)]\n have = False\n for u in range(n):\n if mark[u] == 0 and dfs(u):\n have = True\n break\n if not have:\n print(\"YES\")\n return\n\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14780.0, "status": "done"}, {"code": "have = False\ncycle_begin, block_u, block_v = -1, -1, -1\ng, mark, cycle = [], [], []\n\n\ndef dfs(u):\n nonlocal have, cycle_begin\n mark[u] = 1\n for v in g[u]:\n if u == block_u and v == block_v:\n continue\n if mark[v] == 0:\n if dfs(v):\n if have:\n cycle.append(u)\n if u == cycle_begin:\n have = False\n return True\n elif mark[v] == 1:\n have = True\n cycle_begin = v\n cycle.append(u)\n return True\n mark[u] = 2\n return False\n\n\nn, m = list(map(int, input().split()))\n\ng = [[] for _ in range(n)]\nmark = [0 for _ in range(n)]\n\nfor _ in range(m):\n u, v = list(map(int, input().split()))\n u -= 1\n v -= 1\n g[u].append(v)\n\nfor i in range(n):\n if mark[i] == 0 and dfs(i):\n break\n\nif cycle_begin == -1:\n print(\"YES\")\nelse:\n cycle.append(cycle[0])\n for u in range(len(cycle) - 1, 0, -1):\n block_u = cycle[u]\n block_v = cycle[u - 1]\n mark = [0 for _ in range(n)]\n ok = True\n for u in range(n):\n if mark[u] == 0 and dfs(u):\n ok = False\n break\n if ok:\n print(\"YES\")\n return\n\n print(\"NO\")\n", "passed": true, "time": 0.24, "memory": 14724.0, "status": "done"}, {"code": "\n\ndef my_solve(n, m, graph, mask):\n\tif do_dfs_bool(n,graph,mask.copy()):\n\t\tc = get_cyclic(n, graph, mask)\n\t\tfor u,v in c:\n\t\t\tgraph[u].remove(v)\n\t\t\tif not do_dfs_bool(n,graph,mask.copy()):\n\t\t\t\treturn 'YES'\n\t\t\tgraph[u].append(v)\n\t\treturn \"NO\"\n\treturn \"YES\"\n\ndef get_cyclic(n, graph, mask):\n\tc,v = do_dfs(n,graph,mask)\n\tpath = []\n\ti = 0\n\tbegin = False\n\tif c:\n\t\tfor u in c.keys():\n\t\t\tif c[u] == v:\n\t\t\t\tbegin = True\n\t\t\t\tpath.append((c[u],u))\n\t\t\telif begin:\n\t\t\t\tpath.append((c[u],u))\n\t\ttmp = list(c.keys())\n\t\tif len(tmp):\n\t\t\tpath.append((tmp[-1],v))\n\treturn path\n\ndef do_dfs_bool(n, graph, mask):\n\tcolors = [0]*(n+5)\n\tfor u in graph.keys():\n\t\tif not u in mask.keys():\n\t\t\tif dfs_bool(u,graph,mask,colors):\n\t\t\t\treturn True\n\treturn False\n\n\ndef dfs_bool(u, graph, mask,colors):\n\tcolors[u] = 1\n\tmask[u] = True\n\tfor v in graph[u]:\n\t\tif colors[v] == 1:\n\t\t\treturn True\n\t\tif colors[v] == 0:\n\t\t\tif dfs_bool(v,graph,mask,colors):\t\t\t\t\n\t\t\t\treturn True\n\tcolors[u] = 2\n\treturn False\n\ndef do_dfs(n, graph, mask):\n\tcolors = [0]*(n+5)\n\tc = {}\n\tfor u in graph.keys():\n\t\tif not u in mask.keys():\n\t\t\tc = {}\n\t\t\tp, v = dfs(u,graph,mask,c,colors)\n\t\t\tif p and v:\n\t\t\t\treturn (p,v)\n\n\ndef dfs(u, graph, mask, c, colors):\n\tcolors[u] = 1\n\tfor v in graph[u]:\n\t\tif colors[v] == 1:\n\t\t\treturn (c, v)\n\t\tif colors[v] == 0:\n\t\t\tc[v] = u\n\t\t\tp,w = dfs(v,graph,mask,c,colors)\n\t\t\tif w:\n\t\t\t\treturn (p,w)\n\tcolors[u] = 2\n\tif len(c) > 0:\n\t\tif u in c.keys():\n\t\t\tdel c[u]\n\treturn (c, None)\n\ndef test(n, m, edges):\n\tgraph = {}\n\tmask = {}\n\tfor u,v in edges:\n\t\tif u not in graph.keys():\n\t\t\tgraph[u] = []\n\t\tgraph[u].append(v)\n\t\tif v not in graph.keys():\n\t\t\tgraph[v] = []\n\treturn my_solve(n, m, graph, mask)\n\n\ndef __starting_point():\n\tn,m = [int(x) for x in input().split()]\n\tedges = []\n\tfor i in range(0,m):\n\t\tu,v = [int(x) for x in input().split()]\n\t\tedges.append((u,v))\n\tprint(test(n, m, edges))\n__starting_point()", "passed": true, "time": 0.35, "memory": 14772.0, "status": "done"}, {"code": "import sys\n\ninput = sys.stdin.readline\n\n\ndef get_input():\n n, m = [int(x) for x in input().split(' ')]\n digraph = [[] for _ in range(n + 1)]\n for _ in range(m):\n c1, c2 = [int(x) for x in input().split(' ')]\n digraph[c1].append(c2)\n\n return digraph\n\n\ndef dfs(graph, u=-1, v=-1):\n n = len(graph)\n\n pi = [None] * n\n color = ['white'] * n\n for node in range(1, n):\n if color[node] == 'white':\n cicle = dfs_visit(graph, node, color, pi, u, v)\n if cicle is not None:\n return cicle\n return None\n\n\ndef dfs_visit(graph, root, color, pi, u, v):\n stack = [root]\n\n while stack:\n current_node = stack[-1]\n\n if color[current_node] != 'white':\n stack.pop()\n color[current_node] = 'black'\n continue\n\n color[current_node] = 'grey'\n for adj in graph[current_node]:\n if (current_node, adj) == (u, v):\n continue\n\n if color[adj] == 'white':\n pi[adj] = current_node\n stack.append(adj)\n elif color[adj] == 'grey':\n cicle = [adj]\n while current_node != adj:\n cicle.append(current_node)\n current_node = pi[current_node]\n cicle.append(adj)\n return cicle \n return None\n\n\ndef __starting_point():\n digraph = get_input()\n cicle = dfs(digraph)\n if cicle is None:\n print(\"YES\")\n else:\n cicle.reverse()\n for i in range(len(cicle) - 1):\n c = dfs(digraph, cicle[i], cicle[i + 1])\n if c is None:\n print(\"YES\")\n break\n else:\n print(\"NO\")\n\n__starting_point()", "passed": true, "time": 0.22, "memory": 14680.0, "status": "done"}] | [{"input": "3 4\n1 2\n2 3\n3 2\n3 1\n", "output": "YES\n"}, {"input": "5 6\n1 2\n2 3\n3 2\n3 1\n2 1\n4 5\n", "output": "NO\n"}, {"input": "2 2\n1 2\n2 1\n", "output": "YES\n"}, {"input": "7 7\n1 3\n3 6\n3 7\n5 3\n6 2\n6 7\n7 2\n", "output": "YES\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "4 5\n1 3\n3 2\n2 1\n3 4\n4 1\n", "output": "YES\n"}, {"input": "5 6\n1 3\n2 1\n3 5\n4 3\n5 4\n3 2\n", "output": "NO\n"}, {"input": "3 4\n1 2\n2 1\n1 3\n3 1\n", "output": "NO\n"}, {"input": "5 7\n1 2\n2 3\n3 1\n3 4\n4 1\n4 5\n5 1\n", "output": "YES\n"}, {"input": "4 6\n1 2\n2 3\n3 1\n3 2\n3 4\n4 2\n", "output": "YES\n"}, {"input": "4 5\n1 2\n2 3\n3 4\n4 1\n3 1\n", "output": "YES\n"}, {"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 3\n", "output": "YES\n"}, {"input": "4 6\n2 3\n3 2\n3 4\n4 3\n4 2\n2 4\n", "output": "NO\n"}, {"input": "4 5\n1 2\n2 3\n2 4\n3 1\n4 1\n", "output": "YES\n"}, {"input": "4 5\n1 2\n2 1\n3 4\n4 3\n1 3\n", "output": "NO\n"}, {"input": "7 6\n2 3\n3 4\n4 2\n5 6\n6 7\n7 5\n", "output": "NO\n"}, {"input": "5 6\n1 2\n2 3\n3 4\n4 5\n5 1\n4 2\n", "output": "YES\n"}, {"input": "4 4\n1 2\n2 1\n3 4\n4 3\n", "output": "NO\n"}, {"input": "7 9\n1 2\n2 3\n1 3\n3 4\n3 5\n5 6\n6 1\n6 7\n7 1\n", "output": "YES\n"}, {"input": "8 7\n1 2\n2 3\n3 4\n4 1\n4 5\n5 6\n6 3\n", "output": "YES\n"}, {"input": "4 6\n1 2\n2 4\n2 3\n3 1\n4 3\n3 2\n", "output": "NO\n"}, {"input": "5 6\n1 2\n2 3\n3 4\n4 5\n4 1\n5 2\n", "output": "YES\n"}, {"input": "4 5\n2 4\n1 2\n2 1\n3 4\n4 3\n", "output": "NO\n"}, {"input": "6 8\n1 2\n2 3\n3 1\n2 4\n4 5\n5 1\n2 6\n6 1\n", "output": "YES\n"}, {"input": "6 8\n1 2\n2 3\n3 4\n4 1\n3 5\n5 6\n6 2\n1 3\n", "output": "NO\n"}, {"input": "6 7\n1 2\n2 5\n5 6\n6 1\n5 4\n4 3\n3 2\n", "output": "YES\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "4 6\n1 2\n2 3\n3 4\n4 1\n2 4\n3 1\n", "output": "YES\n"}, {"input": "5 7\n1 2\n2 3\n3 4\n4 5\n5 1\n1 3\n3 5\n", "output": "YES\n"}, {"input": "5 6\n1 2\n2 3\n3 4\n4 5\n4 2\n5 2\n", "output": "YES\n"}, {"input": "4 5\n2 3\n3 4\n4 2\n2 4\n3 2\n", "output": "NO\n"}, {"input": "7 8\n1 2\n2 3\n3 4\n4 5\n5 2\n3 6\n6 7\n7 2\n", "output": "YES\n"}, {"input": "4 5\n1 2\n2 3\n3 4\n4 1\n1 3\n", "output": "YES\n"}, {"input": "4 6\n1 2\n2 3\n3 4\n4 1\n2 4\n4 2\n", "output": "NO\n"}, {"input": "8 9\n2 6\n5 6\n5 2\n3 5\n4 5\n6 4\n1 2\n2 8\n2 3\n", "output": "NO\n"}, {"input": "8 10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 1\n5 4\n4 8\n8 5\n", "output": "NO\n"}, {"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n", "output": "NO\n"}, {"input": "5 8\n1 4\n1 5\n4 2\n4 3\n5 2\n5 3\n2 1\n3 1\n", "output": "NO\n"}, {"input": "5 6\n1 2\n2 3\n3 4\n4 5\n5 1\n1 4\n", "output": "YES\n"}, {"input": "4 5\n1 2\n2 4\n2 3\n3 1\n4 3\n", "output": "YES\n"}, {"input": "5 8\n4 3\n3 1\n4 1\n5 1\n5 2\n1 4\n1 3\n5 3\n", "output": "NO\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "6 8\n1 2\n2 3\n3 4\n1 5\n5 6\n6 4\n4 1\n4 2\n", "output": "NO\n"}, {"input": "8 11\n5 1\n1 2\n1 6\n6 2\n2 3\n2 7\n7 3\n3 4\n3 8\n8 4\n4 1\n", "output": "YES\n"}, {"input": "4 6\n1 2\n2 3\n3 4\n4 1\n1 3\n3 1\n", "output": "NO\n"}, {"input": "5 8\n1 2\n1 3\n1 4\n2 3\n3 4\n3 5\n5 2\n5 1\n", "output": "YES\n"}, {"input": "4 5\n2 1\n1 3\n3 2\n3 4\n4 1\n", "output": "YES\n"}, {"input": "3 4\n3 2\n1 2\n2 3\n1 3\n", "output": "YES\n"}, {"input": "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\n", "output": "NO\n"}, {"input": "5 8\n1 2\n2 3\n3 4\n4 5\n5 1\n4 1\n3 5\n1 3\n", "output": "NO\n"}, {"input": "8 10\n3 2\n1 5\n8 1\n1 2\n6 8\n3 8\n5 3\n2 4\n4 1\n4 3\n", "output": "NO\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "5 6\n4 2\n3 5\n2 3\n5 4\n4 5\n3 4\n", "output": "NO\n"}, {"input": "3 3\n2 3\n2 1\n3 2\n", "output": "YES\n"}, {"input": "9 9\n1 2\n2 3\n3 4\n4 5\n5 1\n6 7\n7 8\n8 9\n9 6\n", "output": "NO\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "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\n", "output": "NO\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "10 10\n10 1\n6 9\n5 3\n9 4\n3 8\n2 1\n5 9\n8 10\n6 5\n10 5\n", "output": "YES\n"}, {"input": "5 9\n1 3\n1 4\n1 5\n2 1\n2 3\n2 4\n3 2\n5 2\n5 4\n", "output": "NO\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "5 5\n1 2\n2 1\n3 4\n3 5\n4 5\n", "output": "YES\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "6 7\n1 2\n3 4\n4 5\n4 6\n5 6\n6 4\n6 3\n", "output": "NO\n"}, {"input": "6 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1\n1 3\n4 6\n", "output": "YES\n"}, {"input": "10 9\n7 2\n10 5\n9 1\n1 5\n4 6\n1 10\n6 2\n10 9\n5 9\n", "output": "YES\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "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\n", "output": "NO\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "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\n", "output": "NO\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "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\n", "output": "NO\n"}, {"input": "7 7\n5 1\n3 7\n4 3\n1 5\n7 5\n3 6\n1 6\n", "output": "YES\n"}, {"input": "3 4\n3 1\n3 2\n1 3\n1 2\n", "output": "YES\n"}, {"input": "5 10\n1 3\n3 1\n2 3\n1 4\n2 4\n2 1\n5 3\n5 1\n4 1\n3 5\n", "output": "NO\n"}, {"input": "5 6\n2 1\n3 2\n1 2\n2 3\n1 5\n3 1\n", "output": "NO\n"}, {"input": "6 7\n6 2\n5 4\n2 1\n5 2\n6 5\n1 5\n5 6\n", "output": "NO\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "4 6\n1 2\n1 3\n3 4\n4 2\n4 1\n2 3\n", "output": "YES\n"}, {"input": "5 7\n1 2\n2 3\n3 1\n2 4\n4 1\n3 5\n5 2\n", "output": "NO\n"}, {"input": "7 10\n1 5\n6 2\n2 7\n6 3\n5 7\n1 2\n3 5\n4 3\n5 2\n7 5\n", "output": "YES\n"}, {"input": "8 11\n8 4\n3 6\n1 2\n8 1\n7 2\n4 3\n7 4\n3 1\n2 6\n4 5\n2 3\n", "output": "YES\n"}, {"input": "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\n", "output": "YES\n"}, {"input": "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\n", "output": "NO\n"}, {"input": "4 7\n1 2\n3 4\n3 2\n1 4\n4 1\n4 2\n1 3\n", "output": "YES\n"}, {"input": "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\n", "output": "NO\n"}] |
|
140 | The mayor of the Central Town wants to modernize Central Street, represented in this problem by the $(Ox)$ axis.
On this street, there are $n$ antennas, numbered from $1$ to $n$. The $i$-th antenna lies on the position $x_i$ and has an initial scope of $s_i$: it covers all integer positions inside the interval $[x_i - s_i; x_i + s_i]$.
It is possible to increment the scope of any antenna by $1$, this operation costs $1$ coin. We can do this operation as much as we want (multiple times on the same antenna if we want).
To modernize the street, we need to make all integer positions from $1$ to $m$ inclusive covered by at least one antenna. Note that it is authorized to cover positions outside $[1; m]$, even if it's not required.
What is the minimum amount of coins needed to achieve this modernization?
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n \le 80$ and $n \le m \le 100\ 000$).
The $i$-th of the next $n$ lines contains two integers $x_i$ and $s_i$ ($1 \le x_i \le m$ and $0 \le s_i \le m$).
On each position, there is at most one antenna (values $x_i$ are pairwise distinct).
-----Output-----
You have to output a single integer: the minimum amount of coins required to make all integer positions from $1$ to $m$ inclusive covered by at least one antenna.
-----Examples-----
Input
3 595
43 2
300 4
554 10
Output
281
Input
1 1
1 1
Output
0
Input
2 50
20 0
3 1
Output
30
Input
5 240
13 0
50 25
60 5
155 70
165 70
Output
26
-----Note-----
In the first example, here is a possible strategy:
Increase the scope of the first antenna by $40$, so that it becomes $2 + 40 = 42$. This antenna will cover interval $[43 - 42; 43 + 42]$ which is $[1; 85]$ Increase the scope of the second antenna by $210$, so that it becomes $4 + 210 = 214$. This antenna will cover interval $[300 - 214; 300 + 214]$, which is $[86; 514]$ Increase the scope of the third antenna by $31$, so that it becomes $10 + 31 = 41$. This antenna will cover interval $[554 - 41; 554 + 41]$, which is $[513; 595]$
Total cost is $40 + 210 + 31 = 281$. We can prove that it's the minimum cost required to make all positions from $1$ to $595$ covered by at least one antenna.
Note that positions $513$ and $514$ are in this solution covered by two different antennas, but it's not important.
—
In the second example, the first antenna already covers an interval $[0; 2]$ so we have nothing to do.
Note that the only position that we needed to cover was position $1$; positions $0$ and $2$ are covered, but it's not important. | interview | [{"code": "import sys\ninput = sys.stdin.readline\n\nn,m=list(map(int,input().split()))\n\nA=[]\nCOVERED=[0]*(m+1)\n\nfor i in range(n):\n x,y=list(map(int,input().split()))\n A.append((x-y,x+y))\n\n for j in range(max(0,x-y),min(m+1,x+y+1)):\n COVERED[j]=1\n\nif min(COVERED[1:])==1:\n print(0)\n return\n\nA.sort()\n\nDP=[m]*(m+2)\nDP[1]=0\n\ncovind=1\n\nwhile COVERED[covind]==1:\n DP[covind]=0\n covind+=1\nDP[covind]=0\n\nNEXT=[i+1 for i in range(m+1)]\nfor j in range(m-1,-1,-1):\n if COVERED[j+1]==1:\n NEXT[j]=NEXT[j+1]\n\ndef nex(i):\n if i<=m:\n return NEXT[i]\n else:\n return m+1\n\n\nfor i in range(1,m+1):\n if COVERED[i]==1:\n continue\n\n for x,y in A:\n if x<i:\n continue\n DP[nex(y+(x-i))]=min(DP[i]+(x-i),DP[nex(y+(x-i))])\n\n#print(DP)\nANS=DP[-1]\nfor i in range(m,-1,-1):\n if DP[i]!=m+1:\n ANS=(min(ANS,DP[i]+(m+1-i)))\n\nprint(ANS)\n\n \n \n \n", "passed": true, "time": 32.41, "memory": 20916.0, "status": "done"}, {"code": "import sys\nfrom operator import itemgetter\ninput = sys.stdin.readline\n\n\nn, m = map(int, input().split())\ninfo = [list(map(int, input().split())) for i in range(n)]\nINF = 10**9\n\n\nnew_info = []\nfor pos, width in info:\n tmp = [max(pos-width-1, 0), min(pos+width, m)]\n new_info.append(tmp)\n\npos = 0\nnew_info = sorted(new_info, key = itemgetter(1))\ndp = [[0]*(m+2) for i in range(n+1)]\n\nfor i in range(m+2):\n dp[0][i] = i\n\nfor i in range(n):\n begin, end = new_info[i]\n for j in range(m+2):\n if j <= end:\n dp[i+1][j] = min(dp[i][begin], dp[i][j])\n else:\n dp[i+1][j] = min((j - end) + dp[i][max(begin - (j-end), 0)], dp[i][j])\n\nprint(dp[n][m]) ", "passed": true, "time": 52.67, "memory": 111664.0, "status": "done"}, {"code": "3\n\nimport os\nimport sys\n\n\ndef main():\n N, M = read_ints()\n A = [tuple(read_ints()) for _ in range(N)]\n print(solve(N, M, A))\n\n\ndef solve(N, M, A):\n A.sort()\n\n D = {0: 0}\n for x, s in A:\n #dprint(x, s)\n #dprint(D)\n d = D.copy()\n for x0, c in d.items():\n if x - s <= x0 + 1:\n nx = x + s\n #dprint(' ', nx, '=>', c, '(x0=', x0, 'c=', c, ')')\n if nx not in D:\n D[nx] = c\n else:\n D[nx] = min(D[nx], c)\n else:\n nc = c + (x - s - x0 - 1)\n nx = x + s + nc - c\n #dprint(' ', nx, '=>', nc, '(x0=', x0, 'c=', c, ')')\n if nx not in D:\n D[nx] = nc\n else:\n D[nx] = min(D[nx], nc)\n #dprint(D)\n\n best = M * 2\n for x, c in D.items():\n if x == 0:\n continue\n if x < M:\n c += M - x\n best = min(best, c)\n return best\n\n\n###############################################################################\n\nDEBUG = 'DEBUG' in os.environ\n\n\ndef inp():\n return sys.stdin.readline().rstrip()\n\n\ndef read_int():\n return int(inp())\n\n\ndef read_ints():\n return [int(e) for e in inp().split()]\n\n\ndef dprint(*value, sep=' ', end='\\n'):\n if DEBUG:\n print(*value, sep=sep, end=end)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 7.55, "memory": 41604.0, "status": "done"}, {"code": "# Antennas coverage\n\nimport sys\nfrom bisect import bisect_right\n\n\ndef upgrade_minCost(n, m, antennas):\n covered = [False] * (m + 1)\n intervals = []\n for x, s in antennas:\n L = max(1, x - s)\n R = min(m, x + s)\n intervals.append((L, R))\n for i in range(L, R + 1):\n covered[i] = True\n intervals.sort()\n \n d = [(m - i) for i in range(m + 1)]\n for i in range(m - 1, -1, -1):\n if covered[i + 1]:\n d[i] = d[i + 1]\n else:\n ant_idx = bisect_right(intervals, (i, m))\n for L, R in intervals[ant_idx:]:\n u = L - i - 1\n prev = min(m, R + u)\n d[i] = min(d[i], u + d[prev])\n return d[0]\n\ndef main():\n # inf = open('input.txt', 'r')\n # reader = (map(int, line.split()) for line in inf)\n reader = (map(int, s.split()) for s in sys.stdin)\n\n n, m = next(reader)\n antennas = [list(next(reader)) for _ in range(n)]\n ans = upgrade_minCost(n, m, antennas)\n print(ans)\n \n # inf.close()\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 24.73, "memory": 18252.0, "status": "done"}, {"code": "def dp(ind, max_covered):\n\tmax_covered = min(m, max_covered)\n\n\tif ind not in cache:\n\t\tcache[ind] = {}\n\n\td = cache[ind]\n\tif max_covered in d:\n\t\treturn d[max_covered]\n\n\tans = blah(ind, max_covered)\n\n\td[max_covered] = ans\n\treturn ans\n\n\n# path = {}\n\nclass Node:\n\tdef __init__(self, key, val, next=None):\n\t\tself.key = key\n\t\tself.val = val\n\t\tself.next = next\n\ndef blah(ind, max_covered):\n\tx, s = antenna[ind]\n\t# key = (ind, max_covered)\n\n\tif max_covered >= m:\n\t\t# path[key] = Node(key, 0)\n\t\treturn 0\n\n\tif ind == len(antenna) - 1:\n\t\tif max_covered < x - s - 1:\n\t\t\tleft_needed = x - s - (max_covered + 1)\n\t\t\tright_needed = max(m - (x + s), 0)\n\t\t\tans = max(left_needed, right_needed)\n\t\t\t# path[key] = Node(key, ans)\n\t\t\treturn ans\n\t\telse:\n\t\t\tright_boundary = max(max_covered, x + s)\n\t\t\tans = max(0, m - right_boundary)\n\t\t\t# path[key] = Node(key, ans)\n\t\t\treturn ans\n\n\tif max_covered < x - s - 1:\n\t\tnum_needed = x - s - (max_covered + 1)\n\t\tnew_boundary = min(x + s + num_needed, m)\n\t\tuse_i = num_needed + dp(ind + 1, new_boundary)\n\t\tdont_use_i = dp(ind + 1, max_covered)\n\n\t\t# if use_i < dont_use_i:\n\t\t# \tpath[key] = Node(key, num_needed, path[(ind + 1, new_boundary)])\n\t\t# else:\n\t\t# \tpath[key] = Node(key, 0, path[(ind + 1, max_covered)])\n\n\t\treturn min(use_i, dont_use_i)\n\telse:\n\t\tnew_boundary = min(max(max_covered, x + s), m)\n\t\tans = dp(ind + 1, new_boundary)\n\t\t# path[key] = Node(key, 0, path[(ind + 1, new_boundary)])\n\t\treturn ans\n\nimport sys\n\ncache = {}\n\n\nn, m = [int(x) for x in sys.stdin.readline().split(\" \")]\n\nantenna = []\n\nfor i in range(n):\n\tx, s = [int(x) for x in sys.stdin.readline().split(\" \")]\n\n\tantenna.append((x, s))\n\nantenna.sort(key=lambda a: a[0])\n\nprint(dp(0, 0))\n", "passed": true, "time": 10.4, "memory": 248396.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\nN, M = map(int, input().split())\nSt = [list(map(int, input().split())) for _ in range(N)]\n\n\ndp = [M-i for i in range(M+1)]\n\nfor m in reversed(range(M)):\n covered = False\n for x, s in St:\n if x-s <= m+1 <= x+s:\n covered = True\n break\n if m < x-s:\n u = x-s-m-1\n dp[m] = min(dp[m], u+dp[min(M, x+s+u)])\n if covered:\n dp[m] = dp[m+1]\n\nprint(dp[0])", "passed": true, "time": 40.88, "memory": 17488.0, "status": "done"}, {"code": "def readint():\n return int(input())\n\ndef readlistint():\n return list(map(int, input().split()))\n\ndef readgridint(rows):\n grid = []\n for idx in range(rows):\n col = list(map(int, input().split()))\n grid.append(col)\n \n return grid\n\nantennas = []\ntotal_len = -1\nmemo = {}\ndef solve(left, idx):\n if(left > total_len):\n return 0\n key = (left, idx)\n if(key in memo):\n return memo[key]\n if(idx == len(antennas) - 1):\n ret = max(0, max(antennas[idx][0] - left, total_len - antennas[idx][1]))\n #print(left, idx, ret)\n memo[key] = ret\n return ret\n else:\n best = solve(left, idx + 1)\n best = min(best, max(0, max(antennas[idx][0] - left, total_len - antennas[idx][1])))\n added = max(antennas[idx][0] - left, 0)\n best = min(best, added + solve(antennas[idx][1] + added + 1, idx+1))\n memo[key] = best\n return best\n \ndef main():\n nonlocal total_len\n N, L = readlistint()\n total_len = L\n for idx in range(N):\n pos, R = readlistint()\n antennas.append([pos-R, pos + R])\n \n antennas.sort()\n #print(total_len, antennas)\n #ret = solve(1, 0)\n #print(ret)\n \n INF = 100000000000\n dp = [INF]*(total_len + 10)\n dp[0] = 0\n for ant in antennas:\n ant_left, ant_right = ant\n for idx in range(0, total_len + 1):\n if(dp[idx] == INF):\n continue\n dp[total_len] = min(dp[total_len], dp[idx] + max(0, max(ant_left - idx - 1, total_len - ant_right)))\n added = max(ant_left - idx - 1, 0)\n right_point = min(total_len, ant_right + added)\n dp[right_point] = min(dp[right_point], dp[idx] + added)\n \n print(dp[total_len])\n \n\n\nmain()", "passed": true, "time": 21.06, "memory": 16408.0, "status": "done"}, {"code": "#watu\nimport sys\ninput = sys.stdin.readline\n\nN, M = map(int, input().split())\nSt = [list(map(int, input().split())) for _ in range(N)]\n\n\ndp = [M-i for i in range(M+1)]\n\nfor m in reversed(range(M)):\n covered = False\n for x, s in St:\n if x-s <= m+1 <= x+s:\n covered = True\n break\n if m < x-s:\n u = x-s-m-1\n dp[m] = min(dp[m], u+dp[min(M, x+s+u)])\n if covered:\n dp[m] = dp[m+1]\n\nprint(dp[0])", "passed": true, "time": 40.96, "memory": 17360.0, "status": "done"}, {"code": "import os\nimport sys\n\n\ndef solve(xs, m):\n xs = [(0, 0)] + xs\n dp = [0] * (m + 1)\n for i in range(1, m + 1):\n dp[i] = dp[i - 1] + 1\n for idx, (x, s) in enumerate(xs):\n if x - s <= i <= x + s:\n dp[i] = dp[i - 1]\n break\n\n if x + s < i:\n c = i - x - s\n dp[i] = min(c + dp[max(x - c - s - 1, 0)], dp[i])\n\n return dp[-1]\n\n\ndef pp(input):\n n, m = list(map(int, input().split()))\n xs = [tuple(map(int, input().split())) for _ in range(n)]\n print(solve(xs, m))\n\n\nif \"paalto\" in os.getcwd():\n from string_source import string_source\n\n pp(\n string_source(\n \"\"\"2 50\n20 0\n3 1\n\"\"\"\n )\n )\n\n pp(\n string_source(\n \"\"\"3 595\n43 2\n300 4\n554 10\n\"\"\"\n )\n )\n\n pp(\n string_source(\n \"\"\"1 1\n1 1\n\"\"\"\n )\n )\n\n pp(\n string_source(\n \"\"\"5 240\n13 0\n50 25\n60 5\n155 70\n165 70\n\"\"\"\n )\n )\n\nelse:\n pp(sys.stdin.readline)\n", "passed": true, "time": 48.03, "memory": 17644.0, "status": "done"}] | [{"input": "3 595\n43 2\n300 4\n554 10\n", "output": "281\n"}, {"input": "1 1\n1 1\n", "output": "0\n"}, {"input": "2 50\n20 0\n3 1\n", "output": "30\n"}, {"input": "5 240\n13 0\n50 25\n60 5\n155 70\n165 70\n", "output": "26\n"}, {"input": "1 100000\n99998 0\n", "output": "99997\n"}, {"input": "1 100000\n100000 0\n", "output": "99999\n"}, {"input": "1 100000\n1 0\n", "output": "99999\n"}, {"input": "2 100000\n1 0\n100000 0\n", "output": "99998\n"}, {"input": "7 300\n50 8\n49 6\n246 1\n123 3\n227 2\n183 5\n158 7\n", "output": "126\n"}, {"input": "7 300\n262 17\n97 27\n108 30\n45 28\n126 18\n299 28\n120 30\n", "output": "94\n"}, {"input": "7 300\n163 21\n111 27\n210 61\n183 53\n237 25\n275 9\n80 6\n", "output": "89\n"}, {"input": "25 100000\n69213 4\n76932 3\n84327 3\n93894 2\n64725 1\n87331 1\n58612 3\n79789 1\n93768 3\n59583 5\n50523 3\n97497 4\n3051 1\n79960 0\n776 5\n36189 1\n15585 5\n6881 0\n54720 0\n30083 4\n4470 3\n77336 2\n96150 1\n59705 3\n59300 1\n", "output": "49963\n"}, {"input": "25 100000\n1003 26\n32756 9\n93227 12\n51400 17\n36812 10\n84422 35\n76490 19\n1740 10\n54632 29\n12367 32\n18339 34\n41068 34\n65607 23\n14131 23\n54870 4\n23147 3\n47036 5\n88376 9\n93195 5\n54299 13\n49172 20\n23718 17\n68635 38\n15559 40\n34105 25\n", "output": "49765\n"}, {"input": "25 100000\n2397 163\n59750 898\n5833 905\n79846 911\n57098 569\n21028 1367\n32857 1352\n72624 1434\n44720 70\n77542 444\n92200 39\n51088 366\n34147 317\n80149 1401\n54988 344\n67064 474\n70805 464\n28718 409\n51331 1453\n90984 670\n18438 457\n56734 1419\n46141 370\n70406 1275\n92283 124\n", "output": "40507\n"}, {"input": "25 100000\n3174 736\n88732 1969\n61424 1015\n77143 1483\n56805 2063\n25558 249\n48637 2511\n68912 63\n27671 733\n60995 2972\n6179 2108\n8416 702\n50179 1554\n37107 2862\n21129 2673\n45776 2144\n67145 1674\n94506 1588\n25711 345\n46646 2072\n86481 2761\n60011 2644\n20236 2068\n52333 1034\n60023 2496\n", "output": "26632\n"}, {"input": "25 100000\n37809 0\n26927 0\n73733 0\n3508 1\n94260 1\n23325 1\n41305 1\n23520 1\n52508 0\n69475 1\n48923 1\n70614 1\n31179 1\n57324 1\n42182 1\n38945 1\n9973 1\n32264 0\n49874 0\n63512 0\n6361 1\n55979 1\n67515 0\n65894 1\n77805 0\n", "output": "49992\n"}, {"input": "25 100000\n67601 52855\n66459 75276\n53190 93454\n5275 6122\n32094 97379\n17446 70386\n56808 9614\n55202 88461\n92365 45788\n2628 72300\n9441 59772\n9639 14290\n58057 92489\n97535 38675\n32763 11599\n33911 80066\n57681 95815\n68874 34661\n7976 42928\n95943 72831\n50029 47657\n99199 86401\n12561 24225\n23715 50617\n81108 29201\n", "output": "0\n"}, {"input": "2 100000\n66809 5\n78732 1939\n", "output": "66803\n"}, {"input": "2 100000\n77287 0\n83316 3414\n", "output": "77286\n"}, {"input": "2 100000\n35991 7\n80242 6536\n", "output": "49205\n"}, {"input": "6 100000\n27838 4\n90673 9\n57946 7\n99524 213\n53425 2780\n87008 2622\n", "output": "50644\n"}, {"input": "6 100000\n99736 10\n33892 1\n81001 5\n5905 7\n33908 611\n5214 2632\n", "output": "49057\n"}, {"input": "6 100000\n27886 7\n77187 4\n9738 6\n96734 9\n16855 6\n49676 2337\n", "output": "47987\n"}, {"input": "25 100000\n53612 0\n66075 2\n8932 3\n7833 2\n37244 1\n63538 0\n50612 3\n74352 3\n97233 3\n95687 3\n52621 0\n90354 0\n31586 2\n90526 2\n47695 0\n8865 8069\n27202 2921\n1257 10197\n5010 3753\n11629 9377\n35282 21983\n64622 12777\n80868 16988\n1749 8264\n35995 22668\n", "output": "2144\n"}, {"input": "5 100000\n52050 4\n29238 4\n44565 1\n45433 3\n44324 2\n", "output": "52045\n"}, {"input": "10 100000\n11743 1\n8885 3\n81551 3\n1155 1\n98002 2\n67313 2\n86920 4\n31643 2\n10059 3\n34150 3\n", "output": "50084\n"}, {"input": "20 100000\n24699 3\n6009 2\n9602 4\n53413 1\n35177 3\n53750 4\n13364 4\n48839 3\n35504 3\n69424 1\n76044 1\n17849 2\n50355 1\n7354 3\n21986 4\n75971 4\n64508 4\n24995 2\n42227 1\n53574 2\n", "output": "49985\n"}, {"input": "40 100000\n7969 3\n37169 1\n41741 2\n67002 1\n90862 2\n64649 2\n16209 3\n73780 1\n21884 2\n68703 1\n34726 3\n48184 1\n91305 4\n81813 2\n63415 3\n55828 3\n8107 2\n34478 3\n45085 1\n75184 3\n55945 2\n17811 2\n6071 3\n39736 2\n61691 1\n32048 4\n92316 1\n67014 4\n1653 1\n74500 3\n37485 1\n14969 2\n66752 2\n9979 3\n64317 2\n8879 2\n49018 1\n27012 2\n52171 4\n34163 2\n", "output": "49936\n"}, {"input": "5 100000\n43626 2\n13034 2\n64492 2\n10136 4\n79129 1\n", "output": "51453\n"}, {"input": "10 100000\n17014 7\n53882 3\n18443 3\n53503 2\n56680 8\n87349 4\n84815 4\n78531 8\n6275 1\n37670 2\n", "output": "50085\n"}, {"input": "20 100000\n38470 3\n47432 1\n58503 3\n5373 4\n35996 2\n3486 7\n45511 2\n99630 5\n52747 6\n9906 2\n20924 8\n53193 2\n39577 2\n7813 2\n89583 6\n6600 6\n3596 1\n11860 2\n26607 2\n75001 1\n", "output": "49970\n"}, {"input": "40 100000\n42798 2\n54533 2\n515 3\n85575 1\n10710 6\n96647 1\n41385 4\n22031 3\n95479 2\n36936 8\n75970 5\n50569 3\n40085 1\n545 4\n79766 4\n7705 3\n98717 2\n98492 1\n60058 2\n18385 3\n82164 2\n62091 6\n24621 8\n86841 7\n38419 2\n31588 1\n45307 1\n81328 8\n2012 7\n33914 3\n11834 8\n35316 2\n41871 2\n51727 5\n93223 7\n39536 8\n81006 3\n64163 2\n58846 2\n54803 1\n", "output": "49894\n"}, {"input": "5 100000\n72890 3\n6854 1\n943 3\n71191 2\n93457 1\n", "output": "64333\n"}, {"input": "10 100000\n94219 1\n71825 1\n99448 2\n61315 4\n69817 15\n21753 16\n94006 11\n53877 1\n28419 10\n20564 12\n", "output": "50054\n"}, {"input": "20 100000\n5086 2\n36539 1\n71556 11\n58140 8\n65788 13\n96162 4\n17309 9\n53576 8\n64003 16\n6754 3\n8130 16\n32836 2\n5623 2\n49613 4\n44487 4\n83608 4\n22645 14\n4509 2\n92784 2\n28021 2\n", "output": "49922\n"}, {"input": "40 100000\n83643 2\n40674 2\n37656 3\n76252 1\n81854 14\n78210 2\n63394 14\n67188 6\n24556 5\n30841 11\n91521 16\n61626 2\n77040 9\n85555 3\n68349 2\n76270 2\n56711 13\n60381 6\n74757 11\n58602 12\n83014 11\n10344 2\n18259 14\n41836 4\n26770 2\n8245 8\n82226 8\n68545 2\n13026 15\n95537 7\n6463 1\n89800 1\n16070 2\n9389 5\n98033 3\n19102 11\n84955 4\n61018 13\n751 4\n68501 5\n", "output": "49811\n"}, {"input": "5 100000\n25350 21\n96944 27\n39618 10\n41361 5\n6591 1\n", "output": "55550\n"}, {"input": "10 100000\n74302 10\n38566 27\n30455 11\n1678 4\n3938 24\n59873 6\n90244 29\n93429 6\n43547 28\n55198 20\n", "output": "50083\n"}, {"input": "20 100000\n86420 1\n47113 13\n64472 1\n53043 9\n13420 14\n76914 4\n94265 5\n58960 32\n37738 2\n62910 8\n84632 13\n12139 1\n7152 29\n88101 6\n7610 6\n26751 3\n20745 14\n18315 8\n28921 1\n21476 2\n", "output": "49883\n"}, {"input": "40 100000\n52994 2\n23288 15\n81416 16\n81533 16\n34292 16\n33769 9\n83905 26\n66312 5\n68536 27\n25739 4\n47063 28\n52941 13\n32163 1\n73306 14\n95733 16\n88459 2\n1439 4\n81112 6\n7142 8\n22978 17\n40445 4\n35423 2\n30283 5\n89053 6\n45961 16\n47050 8\n69093 2\n697 7\n56337 23\n48408 20\n43287 18\n454 11\n954 4\n45261 3\n82023 2\n21357 5\n57677 2\n36910 2\n59441 3\n85506 3\n", "output": "49732\n"}, {"input": "5 100000\n79901 42\n54923 2\n62869 4\n65551 27\n87048 4\n", "output": "54920\n"}, {"input": "10 100000\n40506 6\n34059 5\n38905 34\n83603 11\n66381 8\n93554 4\n7544 19\n86566 4\n25352 4\n96048 16\n", "output": "49985\n"}, {"input": "20 100000\n95468 23\n90408 16\n87565 4\n75513 4\n20971 2\n25009 29\n33037 29\n40038 2\n58148 19\n8408 2\n60320 15\n42740 3\n44945 2\n21695 8\n59723 38\n73068 2\n72608 19\n91778 12\n53661 4\n77225 46\n", "output": "49854\n"}, {"input": "40 100000\n34512 2\n28710 30\n42353 20\n28138 11\n818 42\n40056 1\n68439 8\n43563 42\n3766 14\n19516 25\n54016 62\n93742 41\n98921 3\n50948 8\n58432 2\n58209 7\n55704 18\n77002 8\n82500 16\n498 2\n88306 12\n17568 3\n88313 1\n93767 7\n12186 2\n79225 2\n1910 8\n60198 29\n89693 2\n49128 2\n40818 8\n34413 12\n20499 1\n3649 3\n21079 3\n9349 2\n32774 38\n14759 26\n79319 6\n44325 37\n", "output": "49554\n"}, {"input": "5 100000\n95719 2\n83337 69\n17427 124\n73738 1\n59503 41\n", "output": "53474\n"}, {"input": "10 100000\n72759 89\n31969 4\n84006 24\n7486 45\n1600 5\n54176 2\n59014 6\n76704 119\n59238 1\n29271 2\n", "output": "50444\n"}, {"input": "20 100000\n50897 12\n82689 22\n55442 28\n32615 6\n48930 81\n25243 5\n38752 110\n45025 16\n43729 2\n82637 1\n89951 10\n58373 1\n1389 7\n20683 2\n12366 127\n66021 4\n17264 27\n55759 12\n13239 1\n18370 53\n", "output": "49715\n"}, {"input": "40 100000\n67499 128\n18678 3\n32621 61\n46926 107\n41174 20\n90207 127\n25076 18\n78735 14\n68443 8\n28831 2\n83000 75\n52968 115\n58919 4\n77318 18\n78727 55\n19986 59\n85666 95\n75610 11\n55390 23\n59376 12\n87643 63\n55139 42\n38661 80\n457 21\n1886 9\n61516 71\n14324 103\n28627 2\n64006 3\n47570 7\n71651 17\n34118 107\n45277 14\n31144 4\n70921 74\n8388 4\n32174 11\n22012 6\n67839 5\n51280 10\n", "output": "48822\n"}, {"input": "5 100000\n2742 8\n53984 236\n69767 231\n45509 2\n39889 59\n", "output": "50997\n"}, {"input": "10 100000\n54735 2\n98665 153\n17472 2\n26292 12\n44348 22\n54855 15\n28437 98\n94916 4\n10408 23\n99667 189\n", "output": "50425\n"}, {"input": "20 100000\n11672 105\n94527 8\n83821 4\n37084 55\n60655 24\n16189 4\n34135 85\n34867 2\n55552 7\n52666 49\n66146 74\n6273 2\n13905 59\n20381 4\n59843 83\n53964 38\n24508 4\n77118 4\n15930 3\n62737 1\n", "output": "49678\n"}, {"input": "40 100000\n68637 250\n15718 58\n26714 15\n49786 15\n13359 8\n28367 2\n62024 97\n46061 52\n61112 96\n72226 233\n70981 28\n45379 1\n28398 4\n41275 8\n12280 133\n75146 9\n62439 214\n26526 32\n44676 3\n19031 2\n14260 195\n19053 45\n58423 3\n89174 4\n36613 8\n58708 32\n19140 2\n34072 219\n99129 5\n7006 80\n87999 8\n38558 7\n50309 238\n77671 1\n17665 73\n95834 12\n72684 9\n23193 81\n57013 53\n58594 9\n", "output": "48168\n"}, {"input": "5 100000\n63303 72\n97883 4\n12457 96\n66892 6\n92884 6\n", "output": "50677\n"}, {"input": "10 100000\n57437 57\n78480 2\n30047 2\n22974 16\n19579 201\n25666 152\n77014 398\n94142 2\n65837 442\n69836 23\n", "output": "49615\n"}, {"input": "20 100000\n29764 28\n87214 24\n43812 151\n22119 512\n36641 38\n52113 29\n56955 155\n13605 14\n99224 7\n48614 2\n64555 215\n71439 8\n78995 60\n84075 103\n7907 15\n79915 237\n69409 4\n98226 154\n23889 4\n91844 100\n", "output": "48450\n"}, {"input": "40 100000\n96037 20\n46624 124\n376 24\n21579 329\n30814 16\n93353 2\n37876 5\n31134 15\n91879 101\n56921 3\n60149 1\n32051 12\n87665 1\n43512 6\n99773 2\n93817 8\n4019 448\n21051 1\n41295 98\n9402 89\n6576 498\n37085 50\n8593 3\n611 17\n4320 411\n72688 30\n81747 8\n9120 147\n70791 95\n29492 43\n11656 162\n37753 105\n19543 72\n86959 2\n17301 2\n49114 152\n76580 19\n27610 10\n81365 2\n31055 159\n", "output": "48015\n"}, {"input": "5 100000\n86592 146\n14936 12\n74772 251\n14953 2\n82726 247\n", "output": "59565\n"}, {"input": "10 100000\n36153 5\n75526 126\n70668 438\n84951 4\n66650 1\n13780 312\n70504 798\n1119 395\n41802 2\n69442 106\n", "output": "49678\n"}, {"input": "20 100000\n60719 128\n50622 18\n63673 358\n54655 4\n29105 1\n63976 7\n96998 334\n65216 723\n52540 12\n1268 666\n8242 2\n86941 140\n99111 27\n2965 11\n25870 135\n29573 339\n99204 13\n36279 30\n86150 232\n67144 76\n", "output": "47933\n"}, {"input": "40 100000\n46403 17\n54955 61\n74185 12\n5141 2\n48606 729\n68203 73\n73631 118\n79515 577\n51004 20\n68430 16\n82547 4\n39436 56\n59971 2\n13164 543\n16471 7\n86520 42\n47054 264\n69354 8\n84857 8\n71801 45\n41099 8\n94095 8\n24142 1\n25537 6\n59382 3\n62270 32\n2989 48\n14329 354\n152 8\n450 10\n91698 20\n17145 6\n37249 63\n96026 20\n24555 2\n99362 588\n21434 3\n29806 217\n57636 5\n24354 22\n", "output": "46585\n"}, {"input": "5 100000\n88825 16\n42009 4\n12536 6\n27456 2\n97947 64\n", "output": "51045\n"}, {"input": "10 100000\n1635 8\n33823 61\n5721 646\n48628 1504\n74630 49\n75538 1163\n57979 176\n10592 6\n49836 8\n13039 1427\n", "output": "46506\n"}, {"input": "20 100000\n96994 121\n52505 16\n39110 4\n550 203\n60219 6\n19241 443\n33570 7\n48536 1\n42760 61\n45069 4\n38141 17\n60419 50\n98857 9\n73167 66\n17284 96\n38049 1061\n12937 15\n8136 2\n29734 185\n31184 19\n", "output": "47971\n"}, {"input": "40 100000\n97514 53\n80797 379\n84354 292\n79244 2\n50047 431\n44535 1989\n55021 15\n73792 98\n6532 185\n24440 1986\n11045 54\n95293 24\n83588 1129\n80713 4\n36999 837\n33125 1\n81815 4\n6354 2\n11472 2\n47815 178\n24587 339\n44181 2\n52337 521\n76224 47\n51300 241\n45542 87\n38184 1398\n92802 8\n60559 70\n6458 54\n35620 3\n57750 11\n57175 4\n65095 8\n10390 387\n13810 182\n88779 1\n30393 1\n67934 35\n65584 11\n", "output": "41284\n"}, {"input": "5 100000\n66409 12\n63802 2\n95034 9\n82818 1288\n45078 227\n", "output": "49807\n"}, {"input": "10 100000\n3219 7\n12223 56\n90921 27\n71142 1398\n87964 839\n16499 8\n72444 32\n67739 130\n93403 4\n3846 3\n", "output": "51101\n"}, {"input": "20 100000\n55345 8\n65637 356\n70322 88\n16632 31\n10631 854\n76026 12\n38962 8\n26462 1\n11676 122\n76312 4\n89117 687\n57003 11\n70170 266\n64422 46\n16054 2\n93472 877\n15206 24\n39406 1149\n99456 889\n76963 2\n", "output": "45965\n"}, {"input": "40 100000\n82729 23\n20257 23\n35728 2\n25011 12\n4960 71\n21761 33\n44761 14\n71668 843\n98965 53\n80881 535\n28561 404\n61276 999\n97500 851\n19183 245\n78699 876\n63107 4\n2802 478\n62470 148\n28013 26\n350 1529\n70579 8\n71417 797\n33173 1\n19413 25\n38142 191\n72645 260\n35515 2\n28804 16\n41640 2\n21600 16\n893 437\n7071 368\n75545 395\n98218 1005\n97927 3\n43976 1\n76398 2\n10460 632\n36563 38\n37813 1254\n", "output": "43774\n"}, {"input": "5 100000\n13264 13\n67967 581\n9017 12\n22564 4\n75202 981\n", "output": "51652\n"}, {"input": "10 100000\n31514 7\n43285 4660\n39669 3899\n60022 838\n33584 643\n78825 16\n824 32\n51664 31\n15433 476\n14295 591\n", "output": "44144\n"}, {"input": "20 100000\n76900 749\n4459 3\n94269 2\n82747 213\n4707 2\n25269 4510\n20680 975\n76445 105\n69770 26\n98437 138\n9149 1727\n542 1\n4528 956\n99559 3050\n16375 86\n2140 1295\n59410 15\n25894 7727\n48176 1251\n75691 962\n", "output": "34689\n"}, {"input": "40 100000\n97318 1810\n83374 13\n5633 437\n88352 47\n95345 59\n17545 249\n24102 22\n51457 1\n76529 1\n37126 18\n49452 16\n57843 23\n9831 18\n1455 3\n11806 86\n37145 2\n88995 14\n68601 14\n43229 6\n1611 3\n30150 1479\n55553 2\n13132 50\n16914 13\n25556 63\n89903 6883\n56210 1\n53913 3747\n21131 798\n46002 13\n95645 2\n87403 3155\n34836 8\n12090 61\n13655 25\n33060 54\n42493 258\n90629 3899\n30302 2\n95065 78\n", "output": "35469\n"}, {"input": "5 100000\n37011 9701\n74984 679\n18318 55\n92053 173\n26429 12487\n", "output": "38278\n"}, {"input": "10 100000\n11670 1339\n79595 481\n53274 401\n14356 102\n96605 13\n2355 233\n54983 6904\n47863 49\n27611 11\n96114 336\n", "output": "41632\n"}, {"input": "20 100000\n61697 2\n97163 1\n45531 2964\n41121 1\n55732 4965\n12614 10451\n48412 185\n834 4\n53784 337\n27676 61\n31448 120\n73540 9753\n51358 3568\n31327 4576\n69903 2048\n48288 8116\n54268 41\n89314 10612\n32624 16\n83135 62\n", "output": "7753\n"}, {"input": "40 100000\n3459 2\n86272 5148\n24317 160\n44251 1415\n26597 1\n1319 256\n92116 4\n38907 3\n60128 6673\n71018 2\n35857 936\n97060 2\n4950 6165\n63923 4\n75390 2346\n83335 2\n57524 6\n99812 3\n32248 206\n48786 3185\n69204 16143\n55261 7\n67356 2\n86284 148\n19119 3\n45733 369\n85011 73\n73772 106\n64294 33\n53040 26\n86208 12520\n77019 1573\n52972 2928\n9979 352\n39446 303\n51300 3353\n49439 639\n53349 620\n37475 1303\n53218 12257\n", "output": "15210\n"}, {"input": "5 100000\n89743 8\n64030 13\n33057 439\n69697 34\n28568 11302\n", "output": "40041\n"}, {"input": "10 100000\n308 1\n27837 235\n74223 8762\n25432 10\n62498 5795\n65172 3223\n39762 48\n74347 1\n6364 1523\n73376 8\n", "output": "41919\n"}, {"input": "20 100000\n32216 25\n1771 1876\n29601 4397\n65385 2\n75865 1\n97013 28\n60770 1816\n17137 32\n32943 15\n5320 5\n10846 7383\n77785 13\n62852 369\n78343 7\n86849 14387\n80901 546\n42168 3254\n99786 32092\n93242 24\n14005 53\n", "output": "20505\n"}, {"input": "40 100000\n8644 429\n97881 2766\n98955 25663\n8679 187\n54897 23213\n64306 4647\n46280 23471\n31464 3\n35532 2\n95998 1352\n28824 3\n99405 3856\n47271 13832\n66959 7\n50599 11\n70318 293\n84159 236\n10893 1914\n54437 15065\n4468 3\n91940 32106\n87980 50\n81589 378\n8783 23\n11417 690\n2733 259\n84915 26\n15315 2880\n60017 3214\n58220 1\n17160 185\n60640 10496\n46075 143\n12251 2938\n6582 12\n7234 827\n32344 830\n3330 18\n48612 290\n47531 14241\n", "output": "7924\n"}, {"input": "5 100000\n54710 49\n23118 497\n25124 113\n8533 204\n6259 78\n", "output": "51421\n"}, {"input": "10 100000\n17296 29\n91310 2\n57522 122\n3226 3493\n56545 798\n34449 65176\n52982 57\n63054 20\n85401 26\n35366 40\n", "output": "375\n"}, {"input": "20 100000\n48315 147\n18844 54412\n53410 113\n47381 299\n47399 4\n43189 2182\n44092 269\n86931 4\n69501 21297\n7463 152\n748 3195\n21275 2\n91263 2853\n70156 4\n94007 11073\n73642 27\n10505 88\n48437 56\n45377 3297\n44125 328\n", "output": "0\n"}, {"input": "40 100000\n97613 14\n21950 98\n79071 6\n17398 4\n52818 26\n86382 74\n45221 20\n34027 4550\n37075 16\n64440 15989\n16227 277\n55118 887\n89050 678\n14236 3\n23333 24\n95767 7042\n76449 294\n34947 62\n93092 3916\n10791 1852\n10371 84\n11819 36794\n3774 22\n20470 574\n69834 216\n86866 21\n48346 11\n79493 27990\n54723 4\n7406 963\n21932 18679\n98450 13060\n28964 915\n86494 14\n6303 392\n865 3624\n31750 23\n65411 241\n8209 312\n15896 17139\n", "output": "0\n"}, {"input": "3 100000\n3 1200\n1205 0\n80000 78793\n", "output": "1\n"}, {"input": "3 100000\n20001 78793\n98796 0\n99998 1200\n", "output": "1\n"}, {"input": "8 100000\n1217 0\n1208 0\n1220 0\n3 1200\n1205 0\n1214 0\n1211 0\n80000 78778\n", "output": "6\n"}, {"input": "8 100000\n98796 0\n20001 78778\n98790 0\n98781 0\n98787 0\n98793 0\n98784 0\n99998 1200\n", "output": "6\n"}] |
|
142 | A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.
Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite.
You want to buy at least L liters of lemonade. How many roubles do you have to spend?
-----Input-----
The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types.
-----Output-----
Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade.
-----Examples-----
Input
4 12
20 30 70 90
Output
150
Input
4 3
10000 1000 100 10
Output
10
Input
4 3
10 100 1000 10000
Output
30
Input
5 787787787
123456789 234567890 345678901 456789012 987654321
Output
44981600785557577
-----Note-----
In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles.
In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles.
In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles. | interview | [{"code": "3\n# Copyright (C) 2017 Sayutin Dmitry.\n#\n# This program is free software; you can redistribute it and/or\n# modify it under the terms of the GNU General Public License as\n# published by the Free Software Foundation; version 3\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this program; If not, see <http://www.gnu.org/licenses/>.\n\ndef solve(a, l):\n if l == 0:\n return 0\n\n if l == 1:\n return a[0]\n \n k = 0\n while (2 ** k) < l:\n k += 1\n \n return min(a[k], a[k - 1] + solve(a, l - (2 ** (k - 1))))\n \n\ndef main():\n n, l = list(map(int, input().split()))\n a = list(map(int, input().split()))\n\n for i in range(n - 2, -1, -1):\n if a[i] > a[i + 1]:\n a[i] = a[i + 1]\n \n for i in range(1, n):\n if a[i] > 2 * a[i - 1]:\n a[i] = 2 * a[i - 1]\n\n while len(a) < 35:\n a.append(2 * a[len(a) - 1])\n\n #print(a)\n\n print(solve(a, l))\n \nmain()\n", "passed": true, "time": 0.23, "memory": 14548.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\nn, L = map(int, input().split())\nc = list(map(int, input().split()))\na = [c[0]]\n\nfor i in range(1, 31):\n cand = [a[-1] * 2]\n if i < n: cand.append(c[i])\n a.append(min(cand))\n\nans = []\nsum = 0\n\nfor i in reversed(range(31)):\n if L <= (1<<i):\n ans.append(sum + a[i])\n else:\n L -= (1<<i)\n sum += a[i]\n \nprint(min(ans))", "passed": true, "time": 0.15, "memory": 14640.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nl = [int(x) for x in input().split()]\nfor i in range(1, n):\n l[i] = min(l[i], 2*l[i - 1])\nc = l + [l[-1] * 2 ** i for i in range(1, 32)]\n\ndef cost(x):\n ans = 0\n for i in range(32):\n if x & (1 << i):\n ans += c[i]\n return ans\n\nans = cost(m)\nfor i in range(32):\n if not (m & (1 << i)):\n tmp = m - (m % (1 << i)) + (1 << i)\n ans = min(ans, cost(tmp))\n\nprint(ans)", "passed": true, "time": 0.26, "memory": 14436.0, "status": "done"}, {"code": "read = lambda: list(map(int, input().split()))\nn, L = read()\nc = list(read())\nfor _ in range(5):\n for i in range(n - 2, -1, -1):\n c[i] = min(c[i], c[i + 1])\n for i in range(1, n):\n c[i] = min(c[i], c[i - 1] * 2)\ncur = 0\nans = 10 ** 30\nL1 = L\nfor i in range(n - 1, -1, -1):\n cnt = L1 // (2**i)\n cur += cnt * c[i]\n ans = min(ans, cur + c[i])\n L1 -= cnt * (2**i)\nans = min(ans, cur)\nfor i in range(n - 1, -1, -1):\n if (2**i)>=L:\n ans = min(ans, c[i])\nprint(ans)\n", "passed": true, "time": 0.17, "memory": 14704.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Mon Jan 8 09:32:18 2018\n\n@author: yanni\n\"\"\"\n\nn, L = [int(x) for x in input().split()]\nc = [int(x) for x in input().split()]\nsize = [2**p for p in range(n)]\nfor index in range(n):\n if (index > 0):\n c[index] = min(c[index], c[index-1]*2)\nfor index in range(n):\n if (index > 0):\n temp = n-1-index\n c[temp] = min(c[temp], c[temp+1])\nposs = []\nbase = 0\nmaxindex = 0\nwhile (size[maxindex] < L and maxindex < n-1):\n maxindex += 1\nif (size[maxindex] < L):\n base = (L//size[maxindex]) * c[maxindex]\n L = L % size[maxindex]\nif (L == 0):\n print(base)\nelse:\n poss.append(base + c[maxindex])\n curr = base\n while (L > 0):\n while (size[maxindex] >= 2*L):\n maxindex -= 1\n poss.append(curr + c[maxindex])\n if (maxindex == 0):\n curr += c[0]\n L = 0\n else:\n L -= size[maxindex-1]\n curr += c[maxindex-1]\n poss.append(curr)\n print(min(poss))\n \n \n", "passed": true, "time": 0.2, "memory": 14744.0, "status": "done"}, {"code": "def ii():\n return int(input())\ndef mi():\n return map(int, input().split())\ndef li():\n return list(mi())\n\nn, L = mi()\nC = li()\nfor i in range(1, n):\n C[i] = min(C[i], C[i-1] * 2)\n\nx = 2 ** (n-1)\ny = 0\nz = 10 ** 18\nfor i in range(n-1, -1, -1):\n t = L // x\n y += C[i] * t\n z = min(z, y + C[i])\n L %= x\n x //= 2\nz = min(z, y)\nprint(z)", "passed": true, "time": 0.18, "memory": 14480.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\ndef main():\n n, needed = list(map(int, input().split()))\n costs = list(map(int, input().split()))\n\n done = False\n while not done:\n done = True\n cur = costs[0]\n for i, x in enumerate(costs[1:], 1):\n cur <<= 1\n if cur < x:\n costs[i] = cur\n done = False\n else:\n cur = x\n for i in range(n - 2, -1, -1):\n if costs[i] > costs[i + 1]:\n costs[i] = costs[i + 1]\n done = False\n\n def calc(total):\n result = 0\n for i in range(31):\n if total & 1 << i:\n if i < n:\n result += costs[i]\n else:\n result += costs[-1] << (i - n + 1)\n return result\n\n result = calc(needed)\n for i in range(30, -1, -1):\n x = (needed >> i | 0x1) << i\n if x >= needed:\n result = min(result, calc(x))\n\n print(result)\n\ntry:\n while True:\n main()\nexcept EOFError:\n pass\n", "passed": true, "time": 0.25, "memory": 14432.0, "status": "done"}, {"code": "n, l = map(int, input().split())\np = list(map(int, input().split()))\nd = []\nd = [[p[i] / 2**i, i + 1] for i in range(n)]\nd.sort(key = lambda x: x[0])\nres = 10**18\nq = l\ncurres = 0\nfor i in d:\n\tif i[1] == 1:\n\t\tcurres += p[i[1] - 1] * q\n\t\tres = min(res, curres)\n\t\tbreak\n\tcurb = q // 2**(i[1] - 1)\n\tcurres += curb * p[i[1] - 1]\n\tres = min(res, curres + p[i[1] - 1])\n\tq %= 2**(i[1] - 1)\nprint(res)", "passed": true, "time": 0.16, "memory": 14592.0, "status": "done"}, {"code": "n, l = map(int, input().split())\narr = list(map(int, input().split()))\nfor i in range(1, len(arr)):\n\tarr[i] = min(arr[i], arr[i - 1] * 2)\nfor i in range(64):\n\tarr.append(arr[-1] * 2)\ndp = 0\nfor i in range(64):\n\tif ((l >> i) & 1):\n\t\tdp += arr[i]\n\telse:\n\t\tdp = min(dp, arr[i])\nprint(dp)", "passed": true, "time": 0.14, "memory": 14580.0, "status": "done"}, {"code": "n, L = list(map(int, input().split()))\npr = list(map(int, input().split()))\nres = 0\nposs = []\nber = [(pr[i] / 2 ** i, i) for i in range(n)]\nber.sort()\nfor i in range(n):\n d = L // (2 ** ber[i][1])\n res += d * pr[ber[i][1]]\n L -= d * (2 ** ber[i][1])\n if L == 0:\n poss.append(res)\n poss.append(res + pr[ber[i][1]])\nprint(min(poss))\n", "passed": true, "time": 0.18, "memory": 14644.0, "status": "done"}, {"code": "n, L = [int(i) for i in input().split()]\nc = [int(i) for i in input().split()]\nfor i in range(1, n):\n if (c[i] > c[i-1] * 2):\n c[i] = c[i-1] * 2\nans1 = 0\nans2 = 0\nans = 10**20\nfor i in range(n-1, -1, -1):\n r1 = L // (2**i)\n r2 = (L + 2**i - 1) // (2**i)\n L -= (r1 * 2**i)\n ans1 = ans2 + r2 * c[i]\n ans2 += r1 * c[i]\n ans = min(ans, ans1)\nans = min(ans, ans2)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}, {"code": "n,L=map(int,input().split())\n\npowers=[]\nfir=1\nfor i in range(n):\n powers.append(fir)\n fir*=2\n \nc=list(map(int,input().split()))\n\nfor i in range(1,n):\n c[i]=min(2*c[i-1],c[i])\ncost=0\nfincost=[]\n#print(powers)\nfor i in range(n-1,-1,-1):\n cost+=(L//powers[i])*c[i]\n L=L%powers[i]\n if(L==0):\n fincost.append(cost)\n \n else:\n fincost.append(cost+c[i])\nprint(int(min(fincost)))", "passed": true, "time": 0.16, "memory": 14392.0, "status": "done"}, {"code": "def solve(l, costs):\n\tans = 0\n\tfor i in range(31, -1, -1):\n\t\tif ((l >> i) & 1) == 1:\n\t\t\tans += min(costs[i + 1], costs[i] + solve(l - ex(2, i), costs))\n\t\t\tbreak\n\treturn ans\n\ndef ex(base, exp):\n\tans = 1\n\tfor i in range(exp):\n\t\tans = ans * base\n\treturn ans\n\nn, l = str(input()).split(' ')\nn, l = int(n), int(l)\n\ncosts = str(input()).split(' ')\ncosts = [int(c) for c in costs]\n\nfor i in range(1, n):\n\tcosts[i] = min(costs[i], 2 * costs[i - 1])\n\t\nfor i in range(len(costs), 32):\n\tcosts.append(2 * costs[i - 1])\n\nfor i in range(30, -1, -1):\n\tcosts[i] = min(costs[i], costs[i + 1])\n\t\nprint(solve(l, costs))\n", "passed": true, "time": 0.16, "memory": 14644.0, "status": "done"}, {"code": "\nn, L = map(int, input().split())\nc = [*map(int, input().split())]\nrational = [True] * n\nfor i in range(n):\n\tfor j in range(n):\n\t\tif i < j and c[i] >= c[j]:\n\t\t\trational[i] = False\n\t\tif i < j and c[i] * (2 ** (j - i)) <= c[j]:\n\t\t\trational[j] = False\n\ndef dfs(i, L):\n\tif i == 0: \n\t\treturn L * c[0]\n\telif rational[i]:\n\t\tLi = 2 ** i\n\t\tif Li >= L:\n\t\t\treturn min(c[i], dfs(i - 1, L))\n\t\telse:\n\t\t\treturn (L // Li * c[i]) + dfs(i, L % Li)\n\telse:\n\t\treturn dfs(i - 1, L)\n\n\nprint(dfs(n - 1, L))", "passed": true, "time": 0.16, "memory": 14620.0, "status": "done"}, {"code": "import sys\n\nn, L = list(map (int, sys.stdin.readline().split()))\nc = list (map (int, sys.stdin.readline().split()))\nfor i in range (1, n):\n c[i] = min (c[i], 2 * c[i-1])\nfor i in range (n-2, -1, -1):\n c[i] = min (c[i], c[i+1])\n#print (c)\n\n\nres = L // 2 ** (n - 1) * c[n - 1]\nL %= 2 ** (n - 1)\ntres = 0\nfor sh in range (n):\n if (L & (2 ** sh)) != 0:\n tres += c[sh]\n else:\n tres = min (tres, c[sh])\n\nres += tres\nprint (res)\n", "passed": true, "time": 0.16, "memory": 14684.0, "status": "done"}, {"code": "def solve(a1,b1, cur_sum, cur_L, idx):\n if cur_L == 0:\n return cur_sum\n if idx == len(a1)-1:\n if cur_L > 0:\n ost = cur_L%b1[-1] > 0\n if ost:\n cur_sum += a1[-1]\n cur_sum += a1[-1]* (cur_L//b1[-1])\n return cur_sum\n else:\n return cur_sum\n else:\n ost = cur_L%b1[idx] > 0\n if ost:\n s1 = solve(a1,b1, cur_sum+a1[idx]*((cur_L//b[idx]) + 1), 0,idx+1)\n s2 = solve(a1,b1, cur_sum+a1[idx]*((cur_L//b[idx])), cur_L % b1[idx],idx+1)\n return min(s1,s2)\n else:\n return solve(a1,b1, cur_sum+a1[idx]*((cur_L//b[idx])), cur_L % b1[idx],idx+1)\n \n\n \nn, L = list(map(int, input().split()))\na = list(map(int,input().split()))\nb = [2**i for i in range(len(a))]\nfor i in range(len(a)):\n for j in range(len(a) - 1, i, -1):\n if a[j]/b[j] < a[j-1]/b[j-1]:\n a[j], a[j-1] = a[j-1], a[j]\n b[j], b[j-1] = b[j-1], b[j]\nans = solve(a,b,0,L,0)\nprint (ans)\n\n \n", "passed": true, "time": 0.16, "memory": 14308.0, "status": "done"}, {"code": "n, lt = (int(x) for x in input().split())\ncosts = [int(x) for x in input().split()]\n\nc1 = costs[0]\ncosts = costs[1:]\n\nmaincost = lt * c1\nmainlen = lt\nremcost = 0\n\ncurrv = 1\nfor c in costs:\n currv *= 2\n nmainl = lt - (lt % currv)\n prevc = (maincost / mainlen) if maincost != 0 else 0\n if prevc > (c/currv):\n\n\n nremlen = mainlen - nmainl\n remcost += (maincost * nremlen // mainlen)\n\n mainlen = nmainl\n maincost = mainlen * c // currv\n\n if remcost > c:\n remcost = c\nprint(maincost + remcost)", "passed": true, "time": 0.24, "memory": 14508.0, "status": "done"}, {"code": "n, lit = list(map(int, input().split()))\ncost = list(map(int, input().split())) + ([1 << 100] * 33)\nn = len(cost)\nrlit = lit\n\nfor i in range(n):\n for j in range(i-1, -1, -1):\n cost[i] = min(cost[i], cost[j] * (1 << (i - j)))\n\nres = 0\n\nfor i in range(n):\n if (1 << i) & lit:\n res += cost[i]\n\nb = []\n\nwhile lit:\n b.append(lit % 2)\n lit //= 2\n\nrres = res\n\nfor i in range(len(b)-1, -1, -1):\n if b[i] == 1:\n for j in range(i-1, -1, -1):\n if b[j] == 0:\n add = cost[j]\n sub = 0\n for k in range(j-1, -1, -1):\n if b[k] == 1:\n sub += cost[k]\n res = min(res, rres+add-sub)\n\nfor i in range(n):\n if (1 << i) > rlit and cost[i] < res:\n res = cost[i]\n\nprint(res)\n", "passed": true, "time": 0.18, "memory": 14960.0, "status": "done"}, {"code": "from itertools import permutations\n\nMOD = 10**9+7\n\ndef find_best(c):\n n = 2 ** len(c)\n best_c = c[0] * n\n best_i = 0\n for i, ci in enumerate(c):\n if n // (2**i) * c[i] < best_c:\n best_c = n // (2**i) * c[i]\n best_i = i\n return best_i\n\ndef main():\n n, l = [int(c) for c in input().split(' ')]\n c = [int(c) for c in input().split(' ')]\n ans = []\n cur_ans = 0\n while l:\n ind = find_best(c[:n])\n vol = 2**ind\n cnt = l // vol\n l %= vol\n cur_ans += cnt * c[ind]\n ans.append(cur_ans + (l % vol and c[ind] or 0))\n n = ind\n print(min(ans))\n\nwhile 1:\n main()\n break\n# input()\n", "passed": true, "time": 0.15, "memory": 14564.0, "status": "done"}, {"code": "INF = int(1e18)\n\ndef read_int():\n return list(map(int, input().split()))\n\n\nn, l = read_int()\ncosts = read_int()\n\nbottles = [(1 << i, c) for i, c in enumerate(costs)]\nbottles.sort(key=lambda b: (b[1] / b[0], 1 / b[1]))\n\nmin_cost = dict()\n\ndef find_min_cost(l):\n if l == 0:\n return 0\n if l in min_cost:\n return min_cost[l]\n c = INF\n for b in bottles:\n c1 = (l + b[0] - 1) // b[0] * b[1]\n c2 = l // b[0] * b[1] + find_min_cost(l % b[0]) if l > b[0] else INF\n c = min(c, c1, c2)\n min_cost[l] = c\n return min_cost[l]\n\nprint(find_min_cost(l))", "passed": true, "time": 0.16, "memory": 14480.0, "status": "done"}, {"code": "n, l = map(int, input().split())\nc = list(map(int, input().split()))\n\nv = []\nfor i in range(n):\n v.append(2**i)\nfrom math import ceil\ndef sl(n,l,c, bl):\n #print(n, l, c, bl)\n s = []\n for i in range(n):\n if i not in bl:\n s.append((v[i], v[i]/c[i], c[i], i))\n sm = min(s, key=lambda x: -x[1])\n ct = ceil(l / sm[0])\n if sm[0] == 1:\n return ct*sm[2]\n ans = (ct-1)*sm[2]\n ans1 = min(sm[2], sl(n, l-(ct-1)*sm[0], c, bl + [sm[3]]))\n return ans + ans1\nprint(sl(n, l, c, []))", "passed": true, "time": 0.17, "memory": 14476.0, "status": "done"}, {"code": "n,L=[int(i) for i in input().split()]\nc=[int(i) for i in input().split()]\ncostPerLemon=[]\nans=12345678901234567890\n\nfor i in range(n):\n\tcostPerLemon.append(c[i]/2**i)\n\n\nsize=n\nmoney=0\nwhile size>1:\n\ttarget=min(costPerLemon)\n\ti=costPerLemon.index(target)\n\t\n\ttimes=int(L/(2**i))\n\tmoney+=c[i]*times\n\tL-=(2**i)*times\n\t\n\tans=min(ans,money+c[i])\n\tsize=i\n\twhile len(costPerLemon)>size:\n\t\tcostPerLemon.pop(-1)\nmoney+=L*c[0]\nans=min(ans,money)\n\nprint(ans)\n\n", "passed": true, "time": 0.18, "memory": 14792.0, "status": "done"}, {"code": "n, L = [int(k) for k in input().split(' ') if k]\ndp = [int(k) for k in input().split(' ') if k]\nfor i in range(1, n):\n\tdp[i] = min(2 * dp[i - 1], dp[i])\nbinary = []\nwhile L != 0:\n\tbinary.append(L % 2)\n\tL //= 2\nwhile len(dp) < len(binary):\n\tdp.append(2 * dp[-1])\ndef minify(p):\n\tresult = 999999999999999999999999999\n\tfor i in range(p + 1, len(dp)):\n\t\tresult = min(result, dp[i])\n\tif p == 0:\n\t\treturn min(result, (dp[p] if binary[p] else 0))\n\treturn min(result, (dp[p] if binary[p] else 0) + minify(p - 1))\nprint(minify(len(binary) - 1))\n", "passed": true, "time": 0.16, "memory": 14660.0, "status": "done"}, {"code": "n, L = list(map(int,input().split()))\narr = [int(x) for x in input().split()]\n\ndef pos(x):\n ans = 0\n while(x):\n x //= 2\n ans += 1\n return ans - 1\n\ndef solve(ltr):\n if ltr == 0:\n return 0\n val = pos(ltr)\n if val + 1 < n:\n Bmin = min(arr[val + 1:])\n else:\n val = n - 1\n Bmin = 4e20\n minCost = 4e20\n amt = 0\n for i in range(val + 1):\n v = arr[i] / (2 ** i)\n if v <= minCost:\n minCost = v\n amt = i\n minCost = arr[amt]\n minCost *= ltr // (2 ** amt)\n return min(minCost + solve(ltr % ( 2 ** amt)), Bmin)\n\nprint(solve(L))\n", "passed": true, "time": 0.15, "memory": 14464.0, "status": "done"}] | [{"input": "4 12\n20 30 70 90\n", "output": "150\n"}, {"input": "4 3\n10000 1000 100 10\n", "output": "10\n"}, {"input": "4 3\n10 100 1000 10000\n", "output": "30\n"}, {"input": "5 787787787\n123456789 234567890 345678901 456789012 987654321\n", "output": "44981600785557577\n"}, {"input": "30 792520535\n528145579 682850171 79476920 178914057 180053263 538638086 433143781 299775597 723428544 177615223 959893339 639448861 506106572 807471834 42398440 347390133 65783782 988164990 606389825 877178711 513188067 609539702 558894975 271129128 956393790 981348376 608410525 61890513 991440277 682151552\n", "output": "371343078\n"}, {"input": "30 719520853\n1 3 7 9 21 44 81 49 380 256 1592 1523 4711 6202 1990 48063 112547 210599 481862 1021025 2016280 643778 4325308 3603826 20964534 47383630 100267203 126018116 187142230 604840362\n", "output": "87393281\n"}, {"input": "30 604179824\n501412684 299363783 300175300 375965822 55881706 96888084 842141259 269152598 954400269 589424644 244226611 443088309 914941214 856763895 380059734 9424058 97467018 912446445 609122261 773853033 728987202 239388430 617092754 182847275 385882428 86295843 416876980 952408652 399750639 326299418\n", "output": "564859510\n"}, {"input": "1 1000000000\n1000000000\n", "output": "1000000000000000000\n"}, {"input": "1 1\n1\n", "output": "1\n"}, {"input": "30 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "output": "2000000000\n"}, {"input": "5 25\n52 91 84 66 93\n", "output": "186\n"}, {"input": "10 660\n2316 3782 9667 4268 4985 2256 6854 9312 4388 9913\n", "output": "13164\n"}, {"input": "20 807689532\n499795319 630489472 638483114 54844847 209402053 71113129 931903630 213385792 726471950 950559532 396028074 711222849 458354548 937511907 247071934 160971961 333550064 4453536 857363099 464797922\n", "output": "27447142368\n"}, {"input": "30 842765745\n2 2 2 4 6 8 12 12 18 28 52 67 92 114 191 212 244 459 738 1078 1338 1716 1860 1863 2990 4502 8575 11353 12563 23326\n", "output": "42251\n"}, {"input": "1 1\n1000000000\n", "output": "1000000000\n"}, {"input": "1 1000000000\n1\n", "output": "1000000000\n"}, {"input": "30 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "output": "1000000000\n"}, {"input": "30 1000000000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "2\n"}, {"input": "30 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "1\n"}, {"input": "1 570846883\n300888960\n", "output": "171761524945111680\n"}, {"input": "2 245107323\n357416000 761122471\n", "output": "87605278957368000\n"}, {"input": "3 624400466\n824008448 698922561 760128125\n", "output": "118656089186285061\n"}, {"input": "5 972921345\n496871039 134331253 959524096 747165691 981088452\n", "output": "59657618590751221\n"}, {"input": "8 700735368\n931293374 652764228 183746499 853268148 653623691 684604018 902322304 186452621\n", "output": "1020734127854016\n"}, {"input": "13 695896744\n495801986 946818643 421711713 151976207 616318787 713653645 893406153 42255449 871957806 865208878 547381951 478062469 516417162\n", "output": "87737726572314\n"}, {"input": "21 186982676\n261355063 273322266 663309548 981847874 432074163 204617748 86151188 381783810 725544703 947880176 870951660 226330358 680228931 959825764 972157951 874066182 208942221 587976360 749662969 377541340 841644620\n", "output": "134782258380\n"}, {"input": "29 140874704\n948286516 335531500 165926134 633474522 606947099 21370216 16126534 254131475 624116869 824903957 541685498 351709345 925541565 253434732 759289345 168754543 993046389 636985579 332772332 103110829 311797311 739860627 233674609 950017614 387656468 939870312 161573356 176555912 592529105\n", "output": "338129268\n"}, {"input": "6 566613866\n1 3 3 16 11 13\n", "output": "230186887\n"}, {"input": "11 435675771\n2 2 2 4 4 5 5 8 10 18 21\n", "output": "8934765\n"}, {"input": "13 688240686\n2 4 1 15 7 1 34 129 295 905 1442 1198 3771\n", "output": "21507522\n"}, {"input": "15 645491742\n2 2 2 2 3 3 4 8 10 14 19 37 42 74 84\n", "output": "3309432\n"}, {"input": "29 592983020\n2 3 7 8 30 45 125 132 124 61 1231 1626 7470 14538 18828 35057 34820 219967 359159 362273 1577550 2434174 1736292 15104217 17689384 39467552 50809520 13580992 414752454\n", "output": "61009202\n"}, {"input": "29 42473833\n13 18 21 32 45 72 134 203 320 342 400 565 1039 1093 2142 3383 5360 7894 13056 17053 26524 38453 63285 102775 156618 252874 304854 600862 857837\n", "output": "304854\n"}, {"input": "28 48504243\n1 1 6 1 32 37 125 212 187 676 1679 771 485 9030 1895 26084 109430 96769 257473 383668 645160 1550917 6195680 6309095 16595706 13231037 99591007 255861473\n", "output": "5610124\n"}, {"input": "28 17734553\n13 22 33 59 93 164 166 308 454 532 771 898 1312 2256 3965 5207 6791 13472 13793 26354 47030 68133 118082 199855 221897 257395 417525 536230\n", "output": "257395\n"}, {"input": "27 358801274\n2 3 6 10 2 30 124 35 249 268 79 4013 1693 3522 17730 17110 52968 235714 155787 405063 1809923 667660 2266461 14291190 15502027 54103386 14154765\n", "output": "27680968\n"}, {"input": "27 437705674\n13 13 21 21 25 31 49 83 148 243 246 263 268 282 475 867 1709 3333 4587 5947 11467 22629 25843 31715 34392 45690 47657\n", "output": "333599\n"}, {"input": "26 519355202\n2 2 6 3 4 23 124 115 312 883 526 3158 2901 14398 797 8137 127577 112515 54101 426458 877533 3978708 6725849 5496068 14408348 27866871\n", "output": "25264103\n"}, {"input": "26 707933691\n13 17 31 44 69 70 89 158 246 320 605 934 1635 2364 4351 8660 10262 11664 14090 18908 35845 51033 59963 78775 117479 179510\n", "output": "3829673\n"}, {"input": "25 269843721\n1 4 5 12 6 16 123 195 374 475 974 2303 4109 8890 16632 64699 71115 251461 476703 447854 2042296 3095451 2796629 13478163 13314670\n", "output": "101191398\n"}, {"input": "25 978161707\n13 22 24 34 66 73 145 287 289 521 693 996 1230 1486 1517 2663 3770 3776 5286 7953 15775 30877 42848 84850 114828\n", "output": "6718647\n"}, {"input": "5 304398130\n328619601 758941829 198270024 713154224 371680309\n", "output": "7071174590398871\n"}, {"input": "10 354651161\n676522959 11809337 625434179 312329830 399019943 545095979 566206452 292370104 819250687 361397475\n", "output": "250332233709431\n"}, {"input": "10 907948615\n369010656 907829481 622481545 200317148 960270397 26028213 655060035 796833494 123373353 324969455\n", "output": "437565141462561\n"}, {"input": "10 590326547\n540224591 578261545 271951966 787805881 165741203 795359732 547118852 746648763 284153835 602102300\n", "output": "655248513971940\n"}, {"input": "20 264504887\n256244331 292829612 807171068 120710 900798902 214013876 575261859 40214283 293542999 366877272 353675296 705322168 205009788 86530854 620744650 766826836 240331588 700218303 406369581 649737981\n", "output": "327898333295\n"}, {"input": "20 749478720\n148277091 195065491 92471169 473441125 104827125 387256363 959435633 241640 395794406 734016994 107553118 129783960 812331272 999596018 837854100 215240378 598412225 653614923 933185587 845929351\n", "output": "1209345077739\n"}, {"input": "20 628134337\n706690396 73852246 47785764 655257266 217430459 211108098 623632685 631391825 628008556 962083938 616573502 326152383 7023992 288143889 264733804 886206130 342256543 779010688 657787839 476634612\n", "output": "571078505096\n"}, {"input": "20 708413057\n985177466 224645388 772550594 994150052 856456221 65855795 599129505 903908498 200612104 575185982 507918207 574454347 607410366 738301336 274020952 556522307 665003603 363184479 760246523 952436964\n", "output": "1287105522843\n"}, {"input": "20 228553575\n966247381 207786628 69006100 269956897 359963312 510868514 95130877 473280024 180071136 34097367 898985854 981155909 369570614 803892852 773207504 603654899 500850166 632114017 442730466 348136258\n", "output": "151787408488\n"}, {"input": "25 975185569\n680624205 925575600 711019438 10306 879760994 355425133 204004301 536007340 585477874 216944098 296555029 104013726 892946593 309410720 689188172 687796636 375461496 689356349 680367324 137692780 879054435 925597905 677631315 592123801 742526898\n", "output": "43630079726\n"}, {"input": "30 16804972\n38413642 603358594 93465125 772633637 516421484 75369617 249460374 6747 89975200 3230679 944379663 407211965 820471861 763861258 4711346 787274019 447412797 861015104 104795044 430023687 445411345 316560503 908322702 232775431 33149898 101978638 453254685 587956325 920401353 237657930\n", "output": "34613997\n"}, {"input": "30 939625169\n799744449 316941501 911543330 868167665 272876554 951480855 826347879 102948940 684991931 833689399 277289558 186462 220073415 602419892 22234767 320279157 908288280 357866038 758158565 784960311 772460297 956631291 623631325 328145434 76400621 637950037 63094834 358429163 210185094 824743978\n", "output": "766068050\n"}, {"input": "30 649693919\n523756282 905125099 661420695 854128708 504404014 33547776 632846834 593955985 19432317 644543651 552904895 988070696 321825330 923971248 718082642 900061181 310986828 14810582 525301 623288859 578749693 424452633 901712228 411022879 757920556 825042513 796572495 544557755 747250675 987028137\n", "output": "1213432868\n"}, {"input": "30 941342434\n719914212 905507045 191898825 570606628 687781371 937025497 673960221 557202851 29071681 518803370 894863536 212709126 614432746 924724833 699415275 748075226 796159664 198063404 56538360 649136911 46540367 337023198 45896775 548611961 777908744 873523820 99863819 335685200 503317538 894159729\n", "output": "1443990241\n"}, {"input": "30 810430346\n807519316 377786333 874568334 100500951 872031247 252690899 923103133 769288634 300502982 184749135 481527896 932556233 978317077 980235169 677287 308980653 527243473 763242606 219639015 712288933 901059456 30978091 127839849 9946626 456644060 226102694 611552752 816642473 434613587 723611518\n", "output": "964822722\n"}, {"input": "30 187125289\n660214771 614231774 943973836 50780694 214277957 695192266 425421684 100830325 236002350 233594142 318777769 611117973 758216803 141783036 487402819 42225289 132824573 354540681 64152506 838447015 853800951 605421421 151364012 455396619 928950961 236389207 47829341 743089941 577129072 792900471\n", "output": "143488023\n"}, {"input": "30 129428748\n954910836 756938357 407311375 992660029 134837594 230127140 815239978 545145316 559077075 373018190 923169774 981420723 349998683 971610245 428903049 879106876 229199860 842029694 817413103 141736569 236414627 263122579 394309719 946134085 550877425 544748100 732982715 933907937 67960170 145090225\n", "output": "67960170\n"}, {"input": "30 12544876\n528459681 350718911 432940853 266976578 679316371 959899124 158423966 471112176 136348553 752311334 979696813 624253517 374825117 338804760 506350966 717644199 528671610 10427712 256677344 288800318 711338213 778230088 616184102 968447942 275963441 257842321 753599064 812398057 815035849 207576747\n", "output": "207576747\n"}, {"input": "30 7\n476599619 58464676 796410905 224866489 780155470 404375041 576176595 767831428 598766545 225605178 819316136 781962412 217423411 484904923 194288977 597593185 181464481 65918422 225080972 53705844 584415879 463767806 845989273 434760924 477902363 145682570 721445310 803966515 927906514 191883417\n", "output": "53705844\n"}, {"input": "30 9324\n205304890 806562207 36203756 437374231 230840114 828741258 227108614 937997270 74150322 673068857 353683258 757136864 274921753 418595773 638411312 307919005 304470011 439118457 402187013 371389195 981316766 26764964 293610954 177952828 49223547 718589642 982551043 395151318 564895171 138874187\n", "output": "26764964\n"}, {"input": "30 512443535\n2 10 30 20 26 9 2 4 24 25 4 27 27 9 13 30 30 5 3 24 10 4 14 14 8 3 2 22 25 25\n", "output": "16\n"}, {"input": "30 553648256\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913\n", "output": "553648259\n"}, {"input": "30 536870912\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913\n", "output": "536870913\n"}, {"input": "30 504365056\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913\n", "output": "504365061\n"}, {"input": "30 536870913\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913\n", "output": "536870915\n"}, {"input": "30 536870911\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913\n", "output": "536870913\n"}, {"input": "30 571580555\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913\n", "output": "571580565\n"}, {"input": "1 1000000000\n1\n", "output": "1000000000\n"}, {"input": "4 8\n8 4 4 1\n", "output": "1\n"}, {"input": "2 3\n10 1\n", "output": "2\n"}, {"input": "30 915378355\n459233266 779915330 685344552 78480977 949046834 774589421 94223415 727865843 464996500 268056254 591348850 753027575 142328565 174597246 47001711 810641112 130836837 251339580 624876035 850690451 290550467 119641933 998066976 791349365 549089363 492937533 140746908 265213422 27963549 109184295\n", "output": "111854196\n"}, {"input": "3 7\n20 20 30\n", "output": "60\n"}, {"input": "1 1000000000\n1000000000\n", "output": "1000000000000000000\n"}, {"input": "5 787787787\n1 2 3 4 5\n", "output": "246183685\n"}, {"input": "2 3\n10 5\n", "output": "10\n"}, {"input": "28 146201893\n79880639 962577454 837935105 770531287 992949199 401766756 805281924 931353274 246173135 378375823 456356972 120503545 811958850 126793843 720341477 413885800 272086545 758855930 979214555 491838924 465216943 706180852 786946242 646685999 436847726 625436 360241773 620056496\n", "output": "3127180\n"}, {"input": "5 9\n2 100 100 10 13\n", "output": "12\n"}, {"input": "1 134217728\n1000000000\n", "output": "134217728000000000\n"}, {"input": "1 536870912\n1000000000\n", "output": "536870912000000000\n"}, {"input": "5 5\n34 22 21 20 30\n", "output": "20\n"}, {"input": "1 787787787\n1\n", "output": "787787787\n"}, {"input": "7 7\n34 22 21 20 30 20 20\n", "output": "20\n"}, {"input": "5 5\n34 22 21 25 30\n", "output": "25\n"}, {"input": "5 787787787\n123456789 234567890 345678901 456789012 1\n", "output": "49236737\n"}, {"input": "6 6\n34 22 21 25 30 35\n", "output": "25\n"}] |
|
143 | Someone gave Alyona an array containing n positive integers a_1, a_2, ..., a_{n}. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.
Formally, after applying some operations Alyona will get an array of n positive integers b_1, b_2, ..., b_{n} such that 1 ≤ b_{i} ≤ a_{i} for every 1 ≤ i ≤ n. Your task is to determine the maximum possible value of mex of this array.
Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array.
The second line of the input contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — the elements of the array.
-----Output-----
Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.
-----Examples-----
Input
5
1 3 3 3 6
Output
5
Input
2
2 1
Output
3
-----Note-----
In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements. | interview | [{"code": "x=int(input())\nl=list(map(int, input().split(' ')))\nl.sort()\na=1\nfor i in l:\n if i>=a:\n a+=1\nprint(a)\n", "passed": true, "time": 0.21, "memory": 14568.0, "status": "done"}, {"code": "n = int(input())\nA = [int(x) for x in input().split()]\nA.sort()\nmex = 1\nfor i in range(n):\n if A[i] >= mex:\n A[i] = mex\n mex += 1\nprint(mex)\n\n\n", "passed": true, "time": 0.16, "memory": 14552.0, "status": "done"}, {"code": "n = int(input())\nc = list(map(int, input().split()))\nc.sort()\nm = 1\nfor i in range(n):\n if m <= c[i]:\n c[i] = m\n m += 1\nprint(m)\n", "passed": true, "time": 0.21, "memory": 14348.0, "status": "done"}, {"code": "n = int(input())\nai = list(map(int,input().split()))\nai.sort()\nnum = n\nans = 0\nfor i in ai:\n num -= 1\n ans += 1\n ans = min(i,ans)\nprint(ans+1)\n", "passed": true, "time": 0.16, "memory": 14404.0, "status": "done"}, {"code": "\nn = int(input())\ntab = sorted(list(map(int, input().split())))\ncmex = 1\nfor num in tab:\n if num >= cmex:\n cmex += 1\n\nprint(cmex)\n", "passed": true, "time": 0.17, "memory": 14384.0, "status": "done"}, {"code": "from collections import defaultdict, deque, Counter, OrderedDict\n\ndef main():\n n = int(input())\n l = sorted([int(i) for i in input().split()])\n c = 1\n for i in l:\n if i >= c:\n c += 1\n print(c)\n\n\n\n\n\n\n\n\n\n\n\n\ndef __starting_point():\n \"\"\"sys.setrecursionlimit(400000)\n threading.stack_size(40960000)\n thread = threading.Thread(target=main)\n thread.start()\"\"\"\n main()\n__starting_point()", "passed": true, "time": 0.21, "memory": 14584.0, "status": "done"}, {"code": "n = int(input())\ndata = sorted(list(map(int, input().split())))\nmin1 = 10 ** 9 + 1\nfor i in range(n):\n data[i] = min(data[i], i + 1, min1)\n min1 = data[i] + 1\nprint(data[-1] + 1)", "passed": true, "time": 0.21, "memory": 14380.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\na.sort()\nans = n + 1\n\ni = 0\nj = 1\n\nwhile i < n:\n if a[i] >= j:\n i += 1\n j += 1\n else:\n while i < n and a[i] < j:\n i += 1\n if i != n:\n j += 1\n i += 1\n\nprint(j)\n", "passed": true, "time": 1.6, "memory": 14380.0, "status": "done"}, {"code": "n = int(input())\n\nmex = 1\nfor num in sorted(map(int, input().split())):\n if num >= mex:\n mex += 1\n\nprint(mex)", "passed": true, "time": 0.14, "memory": 14588.0, "status": "done"}, {"code": "import sys\n\n\ndef main():\n n = int(sys.stdin.readline())\n x = list(map(int, sys.stdin.readline().split()))\n x.sort()\n\n c = 1\n for i in range(n):\n if x[i] >= c:\n c+=1\n print(c)\n\nmain()\n", "passed": true, "time": 0.2, "memory": 14632.0, "status": "done"}, {"code": "n = int(input())\nour = list(map(int, input().split()))\nour.sort()\nour[0] = 1\nfor i in range(1, n):\n if our[i] > our[i - 1]:\n our[i] = our[i - 1] + 1\nprint(our[-1] + 1)", "passed": true, "time": 1.67, "memory": 14484.0, "status": "done"}, {"code": "read = lambda: map(int, input().split())\nn = int(input())\na = sorted(read())\nk = 1\nfor i in range(n):\n if a[i] > k:\n a[i] = k\n k += 1\n elif a[i] == k:\n k += 1\nprint(k)", "passed": true, "time": 0.21, "memory": 14380.0, "status": "done"}, {"code": "n = int(input())\na = sorted(int(x) for x in input().split())\nm = 0\nfor i in range(1, n+1):\n if i > a[i-1] + m:\n m = i - a[i-1]\nprint(n-m+1)", "passed": true, "time": 0.22, "memory": 14412.0, "status": "done"}, {"code": "n=int(input())\na=sorted(map(int,input().split()))\nans=1\nfor i in range(n):\n if a[i]>=ans: ans+=1\nprint(ans)", "passed": true, "time": 0.22, "memory": 14604.0, "status": "done"}, {"code": "n = int(input())\nl = list(map(int,input().split()))\nl.sort()\nd = set()\nl[0] = 1\nfor i in range(1,n):\n l[i] = min(l[i-1] + 1,l[i])\nprint(l[n-1]+1)", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "n=int(input())\nl=sorted(map(int,input().split()))\nans=2\nl[0]=1\nfor i in range(1,n):\n if l[i]>l[i-1]: l[i]=l[i-1]+1; ans=l[i]+1\nprint(ans)", "passed": true, "time": 0.15, "memory": 14384.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\na.sort()\n\nmex = 1\nmiss = False\n\ni = 0\nwhile i < n:\n while i < n and a[i] < mex:\n i += 1\n\n if i != n:\n mex += 1\n\n i += 1\n\nprint(mex)\n", "passed": true, "time": 0.14, "memory": 14560.0, "status": "done"}, {"code": "n=int(input())\nnombres=list(map(int,input().split()))\n\nnombres.sort()\n\ni=0\nentierSuivant=1\nwhile i!=n:\n if nombres[i]>entierSuivant:\n nombres[i]=entierSuivant\n entierSuivant+=1\n elif entierSuivant==nombres[i]:\n entierSuivant+=1\n i+=1\n\nprint(entierSuivant)", "passed": true, "time": 0.18, "memory": 14424.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nfrom collections import Counter\n\ntry:\n while True:\n n = int(input())\n a = sorted(map(int, input().split()))\n t = 1\n for x in a:\n t = min(t, x) + 1\n\n print(t)\n\nexcept EOFError:\n pass\n", "passed": true, "time": 0.14, "memory": 14412.0, "status": "done"}, {"code": "n = int(input())\narr = [int(x) for x in input().split()]\narr.sort()\npoint = 0\nfor i in range(n):\n if(point<arr[i]):\n point += 1\nprint(point+1)", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}, {"code": "n = int(input())\nL = sorted([int(i) for i in input().split()])\n\ni = 0\nmex = 1\nwhile i < n:\n if mex <= L[i]:\n mex += 1\n i += 1\nprint(mex)\n", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\na.sort()\n\ntarget = 1\nfor i in range(n):\n if a[i] >= target:\n target += 1\n\nprint(target)\n", "passed": true, "time": 0.25, "memory": 14592.0, "status": "done"}, {"code": "import sys\nn=int(input())\nz=list(map(int,input().split()))\nz.sort()\nlast=0\nfor i in range(n):\n if z[i]-last>=2:\n z[i]=last+1\n last+=1\n else:\n last=z[i]\nprint(z[-1]+1)", "passed": true, "time": 0.14, "memory": 14444.0, "status": "done"}, {"code": "n = int(input())\narr = list(map(int, input().split()))\narr.sort()\nmex = 1\nfor i in range(n):\n if arr[i] >= mex:\n arr[i] = mex\n mex = mex + 1\nprint(mex)", "passed": true, "time": 0.15, "memory": 14564.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport time\n\nn = int(input())\na = [int(i) for i in input().split()]\n\nstart = time.time()\n\na = sorted(a)\n\nnow = 1\n\nfor i in range(n):\n if a[i] >= now:\n a[i] = now\n now = now + 1\n\nprint(now)\nfinish = time.time()\n#print(finish - start)\n", "passed": true, "time": 0.21, "memory": 14408.0, "status": "done"}] | [{"input": "5\n1 3 3 3 6\n", "output": "5\n"}, {"input": "2\n2 1\n", "output": "3\n"}, {"input": "1\n1\n", "output": "2\n"}, {"input": "1\n1000000000\n", "output": "2\n"}, {"input": "1\n2\n", "output": "2\n"}, {"input": "2\n1 1\n", "output": "2\n"}, {"input": "2\n1 3\n", "output": "3\n"}, {"input": "2\n2 2\n", "output": "3\n"}, {"input": "2\n2 3\n", "output": "3\n"}, {"input": "2\n3 3\n", "output": "3\n"}, {"input": "3\n1 1 1\n", "output": "2\n"}, {"input": "3\n2 1 1\n", "output": "3\n"}, {"input": "3\n3 1 1\n", "output": "3\n"}, {"input": "3\n1 1 4\n", "output": "3\n"}, {"input": "3\n2 1 2\n", "output": "3\n"}, {"input": "3\n3 2 1\n", "output": "4\n"}, {"input": "3\n2 4 1\n", "output": "4\n"}, {"input": "3\n3 3 1\n", "output": "4\n"}, {"input": "3\n1 3 4\n", "output": "4\n"}, {"input": "3\n4 1 4\n", "output": "4\n"}, {"input": "3\n2 2 2\n", "output": "3\n"}, {"input": "3\n3 2 2\n", "output": "4\n"}, {"input": "3\n4 2 2\n", "output": "4\n"}, {"input": "3\n2 3 3\n", "output": "4\n"}, {"input": "3\n4 2 3\n", "output": "4\n"}, {"input": "3\n4 4 2\n", "output": "4\n"}, {"input": "3\n3 3 3\n", "output": "4\n"}, {"input": "3\n4 3 3\n", "output": "4\n"}, {"input": "3\n4 3 4\n", "output": "4\n"}, {"input": "3\n4 4 4\n", "output": "4\n"}, {"input": "4\n1 1 1 1\n", "output": "2\n"}, {"input": "4\n1 1 2 1\n", "output": "3\n"}, {"input": "4\n1 1 3 1\n", "output": "3\n"}, {"input": "4\n1 4 1 1\n", "output": "3\n"}, {"input": "4\n1 2 1 2\n", "output": "3\n"}, {"input": "4\n1 3 2 1\n", "output": "4\n"}, {"input": "4\n2 1 4 1\n", "output": "4\n"}, {"input": "4\n3 3 1 1\n", "output": "4\n"}, {"input": "4\n1 3 4 1\n", "output": "4\n"}, {"input": "4\n1 1 4 4\n", "output": "4\n"}, {"input": "4\n2 2 2 1\n", "output": "3\n"}, {"input": "4\n1 2 2 3\n", "output": "4\n"}, {"input": "4\n2 4 1 2\n", "output": "4\n"}, {"input": "4\n3 3 1 2\n", "output": "4\n"}, {"input": "4\n2 3 4 1\n", "output": "5\n"}, {"input": "4\n1 4 2 4\n", "output": "5\n"}, {"input": "4\n3 1 3 3\n", "output": "4\n"}, {"input": "4\n3 4 3 1\n", "output": "5\n"}, {"input": "4\n1 4 4 3\n", "output": "5\n"}, {"input": "4\n4 1 4 4\n", "output": "5\n"}, {"input": "4\n2 2 2 2\n", "output": "3\n"}, {"input": "4\n2 2 3 2\n", "output": "4\n"}, {"input": "4\n2 2 2 4\n", "output": "4\n"}, {"input": "4\n2 2 3 3\n", "output": "4\n"}, {"input": "4\n2 2 3 4\n", "output": "5\n"}, {"input": "4\n2 4 4 2\n", "output": "5\n"}, {"input": "4\n2 3 3 3\n", "output": "4\n"}, {"input": "4\n2 4 3 3\n", "output": "5\n"}, {"input": "4\n4 4 2 3\n", "output": "5\n"}, {"input": "4\n4 4 4 2\n", "output": "5\n"}, {"input": "4\n3 3 3 3\n", "output": "4\n"}, {"input": "4\n3 3 3 4\n", "output": "5\n"}, {"input": "4\n4 3 3 4\n", "output": "5\n"}, {"input": "4\n4 4 3 4\n", "output": "5\n"}, {"input": "4\n4 4 4 4\n", "output": "5\n"}, {"input": "11\n1 1 1 1 1 1 1 1 1 3 3\n", "output": "4\n"}, {"input": "20\n1 1 1 1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8\n", "output": "9\n"}, {"input": "4\n2 2 2 3\n", "output": "4\n"}, {"input": "3\n1 1 2\n", "output": "3\n"}, {"input": "15\n1 2 2 20 23 25 28 60 66 71 76 77 79 99 100\n", "output": "15\n"}, {"input": "7\n1 2 2 2 5 5 1\n", "output": "5\n"}, {"input": "4\n1 1 1 2\n", "output": "3\n"}, {"input": "5\n1 1 1 1 10000\n", "output": "3\n"}, {"input": "5\n1 1 1 1 2\n", "output": "3\n"}, {"input": "7\n1 3 3 3 3 3 6\n", "output": "5\n"}, {"input": "4\n1 1 1 3\n", "output": "3\n"}, {"input": "10\n1 1 1 1 1 1 1 1 1 100\n", "output": "3\n"}, {"input": "4\n1 1 2 2\n", "output": "3\n"}, {"input": "5\n1 1 1 3 4\n", "output": "4\n"}, {"input": "8\n1 1 1 1 2 2 3 40\n", "output": "5\n"}, {"input": "5\n1 1 1 1 1\n", "output": "2\n"}, {"input": "7\n1 2 2 2 2 2 4\n", "output": "4\n"}, {"input": "10\n1 1 1 10000000 10000000 10000000 10000000 10000000 10000000 10000000\n", "output": "9\n"}, {"input": "10\n1 1 1 1 1 1 1 1 2 3\n", "output": "4\n"}, {"input": "4\n8 8 8 8\n", "output": "5\n"}, {"input": "5\n5 6 6 6 7\n", "output": "6\n"}] |
|
144 | Recently Vasya found a golden ticket — a sequence which consists of $n$ digits $a_1a_2\dots a_n$. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket $350178$ is lucky since it can be divided into three segments $350$, $17$ and $8$: $3+5+0=1+7=8$. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
-----Input-----
The first line contains one integer $n$ ($2 \le n \le 100$) — the number of digits in the ticket.
The second line contains $n$ digits $a_1 a_2 \dots a_n$ ($0 \le a_i \le 9$) — the golden ticket. Digits are printed without spaces.
-----Output-----
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
-----Examples-----
Input
5
73452
Output
YES
Input
4
1248
Output
NO
-----Note-----
In the first example the ticket can be divided into $7$, $34$ and $52$: $7=3+4=5+2$.
In the second example it is impossible to divide ticket into segments with equal sum. | interview | [{"code": "n = int(input())\na = list(map(int, list(input())))\nfor i in range(n - 1):\n sm = sum(a[:i + 1])\n tn = 0\n res = True\n has = False\n for j in range(i + 1, n):\n tn += a[j]\n if (tn == sm):\n tn = 0\n has = True\n elif tn > sm:\n res = False\n break\n if (tn == 0 and res and has):\n print(\"YES\")\n break\nelse:\n print(\"NO\")", "passed": true, "time": 0.16, "memory": 14612.0, "status": "done"}, {"code": "n = int(input())\ns = input()\na = []\nfor i in range(n):\n a.append(int(s[i]))\ns = sum(a)\nans = \"NO\"\nfor i in range(2, 1001):\n if (s % i != 0):\n continue\n su = s // i\n pos = 0\n ans = \"YES\"\n for ii in range(i):\n cur = 0\n while (pos < n and cur + a[pos] <= su):\n cur += a[pos]\n pos += 1\n if (cur != su):\n ans = \"NO\"\n if (ans == \"YES\"):\n break\nprint(ans)", "passed": true, "time": 0.16, "memory": 14640.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().rstrip()))\nsm = sum(a)\nans = False\nfor cnt in range(2, n + 1):\n if sm % cnt != 0:\n continue\n seq_sum = sm // cnt\n cur_sum = 0\n ans = True\n for i in range(n):\n cur_sum += a[i]\n if cur_sum == seq_sum:\n cur_sum = 0\n if cur_sum > seq_sum:\n ans = False\n break\n if ans:\n break\nprint(\"YES\" if ans else \"NO\")\n", "passed": true, "time": 1.56, "memory": 14444.0, "status": "done"}, {"code": "n = int(input())\ns = input()\narr = list()\narr.append(int(s[0]))\nsumm = arr[0]\nbigflg = False\nfor i in range(1,len(s)):\n arr.append(int(s[i]))\n summ+=arr[i]\nfor i in range(2,len(s)+1):\n if summ % i == 0:\n amount = summ / i\n sm = 0\n flg = True\n for j in range(len(arr)):\n sm += arr[j]\n if (sm > amount):\n flg = False\n break\n if (sm == amount):\n sm = 0\n if sm==0 and flg:\n bigflg = True\n print('YES')\n break\nif not bigflg:\n print('NO')\n", "passed": true, "time": 0.15, "memory": 14512.0, "status": "done"}, {"code": "n = int(input())\na = input()\nans = 0\nneeds = 0\nfor i in range(n):\n needs += int(a[i])\n currs = 0\n for j in range(i + 1, n):\n currs += int(a[j])\n if currs > needs:\n break\n elif currs == needs:\n if j == n - 1:\n ans = 1\n break\n else:\n if a[j + 1] != '0':\n currs = 0\nif ans:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.16, "memory": 14368.0, "status": "done"}, {"code": "import sys\nn = int(input())\narr = list(map(int, list(input())))\nif n > 1 and sum(arr) == 0:\n print(\"YES\")\n return\narr = [el for el in arr if el != 0]\nn = len(arr)\nfor i in range(1, sum(arr)):\n cur = 0\n cur_sum = 0\n while True:\n while cur < n and cur_sum < i:\n cur_sum += arr[cur]\n cur += 1\n if cur_sum == i:\n cur_sum = 0\n elif cur_sum != i:\n break\n if cur == n:\n print(\"YES\")\n return\nprint(\"NO\")\n", "passed": true, "time": 0.18, "memory": 14456.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nfor i in range(901):\n\tj = 0\n\tsumma = 0\n\tf = True\n\tq = 0\n\twhile j < n and f:\n\t\tsumma += int(s[j])\n\t\tif summa > i:\n\t\t\tf = False\n\t\telif summa == i:\n\t\t\tq += 1\n\t\t\tsumma = 0\n\t\tj += 1\n\tif summa == 0 and f and q > 1:\n\t\tprint(\"YES\")\n\t\treturn\nprint(\"NO\")\n\t\t\n", "passed": true, "time": 1.73, "memory": 14492.0, "status": "done"}, {"code": "def check(a, count):\n ks = 0\n for i in range(len(a)):\n ks += a[i]\n if ks > count:\n return False\n elif ks == count:\n ks = 0\n\n return True\n \n\n\nn = int(input())\na = list(map(int, list(input())))\nss = sum(a)\nflag = False\nfor k in range(2, 1000):\n if ss % k == 0:\n if check(a, ss // k):\n flag = True\n break\nif flag:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 1.56, "memory": 14536.0, "status": "done"}, {"code": "def check(i):\n s = 0\n for x in b:\n s += x\n if s == i:\n s = 0\n if s == 0:\n return True\n return False\na = int(input())\nb = [int(i) for i in list(input())]\nfor i in range(max(1, sum(b))):\n if check(i):\n print(\"YES\")\n break\nelse:\n print(\"NO\")", "passed": true, "time": 0.17, "memory": 14500.0, "status": "done"}, {"code": "n = int(input())\ns = input()\na = [int(i) for i in s]\nm = sum(a)\nfor i in range(2, n + 1):\n if m % i == 0:\n k = m // i\n summ = 0\n cnt = 0\n for i in range(n):\n summ += a[i]\n if summ == k:\n cnt += 1\n summ = 0\n if k * cnt == m:\n print(\"YES\")\n return\nprint(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14564.0, "status": "done"}, {"code": "n = int(input())\ns = input()\narr = []\nsum = 0\nfor i in s:\n arr.append(int(i))\n sum += (int(i))\nok = False\nif (sum > 0):\n for i in range(2, sum + 1):\n if (sum % i == 0):\n sums = 0\n ok = True\n for j in range(n):\n sums += arr[j]\n if (sums == sum / i):\n sums = 0\n elif (sums > sum / i):\n ok = False\n break\n if ok:\n break\nelse:\n ok = True\nif ok:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.23, "memory": 14440.0, "status": "done"}, {"code": "n = int(input())\n\ns = input()\n\nmaxi = -1\n\nfor x in range(901):\n f = False\n acc = 0\n cnt = 0\n for y in range(n):\n if acc + int(s[y]) > x:\n f = True\n break\n elif acc + int(s[y]) == x:\n acc = 0\n cnt += 1\n else:\n acc += int(s[y])\n if f:\n continue\n elif acc == 0 and cnt >= 2:\n maxi = x\n\nif maxi == -1:\n print(\"NO\")\nelse:\n print(\"YES\")\n", "passed": true, "time": 0.94, "memory": 14392.0, "status": "done"}, {"code": "n=int(input())\ns=input()\nsu=0\nfor i in s:\n su+=int(i)\ntr=0\nif (su==0):\n print(\"YES\")\nelse:\n for i in range(1,su):\n if (su%i==0):\n t=0\n x=1\n for c in s:\n if (t+int(c)== i):\n t=0\n elif(t+int(c)>i):\n x=0\n else:\n t+=int(c)\n if(x==1):\n tr=1\n if (tr==1):\n print(\"YES\")\n else:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14632.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nsm = (sum(map(int, list(s))))\ndv = 2\nans = []\nwhile dv <= n:\n if sm % dv == 0:\n summ = 0\n tmp = True\n for i in range(len(s)):\n summ += int(s[i])\n if summ == sm // dv:\n summ = 0\n elif summ > sm // dv:\n tmp = False\n if tmp:\n ans.append(dv)\n dv += 1\nif ans:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.14, "memory": 14596.0, "status": "done"}, {"code": "n = int(input())\na = [int(c) for c in input()]\nwhile a and a[-1] == 0:\n a.pop()\nn = len(a)\nacc = [0] * (n + 1)\nfor i in range(1, n + 1):\n acc[i] = acc[i - 1] + a[i - 1]\nres = n == 0\nfor l in range(1, n):\n pos = l\n res2 = True\n while pos < n and res2:\n for i in range(pos + 1, n + 1):\n if acc[i] - acc[pos] == acc[l]:\n pos = i\n break\n if acc[i] - acc[pos] > acc[l] or i == n:\n res2 = False\n break\n if res2:\n res = True\n break\n\nprint(\"YES\" if res else \"NO\")", "passed": true, "time": 0.18, "memory": 14352.0, "status": "done"}, {"code": "import sys\n\n\nn = int(input())\narray = list(input())\nfor i in range(n):\n array[i] = int(array[i])\nfor i in range(sum(array) + 1):\n if sum(array) == 0 or (i != 0 and sum(array) % i == 0 and i < sum(array)):\n k = 0\n l = 0\n for j in array:\n k = k + j\n if k == i:\n k = 0\n l += 1\n elif k > i:\n break\n if k == 0 and l > 1:\n print(\"YES\")\n return\nprint(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "def sum_o(s):\n if s == '':\n return 0\n res = 0\n for el in s:\n res += int(el)\n return res\ndef can(s, summ):# 3452 7\n if sum_o(s) == summ:\n return True\n res = ''\n for i in range(len(s)):\n wl = s[i]\n res += wl\n if sum_o(res) == summ:\n if can(s[i+1:], summ):\n return True\n else:\n return False\n if sum_o(res) > summ:\n return False\ndef main():\n n = int(input())\n s = input()\n for i in range(1,n):\n if can(s[i:], sum_o(s[:i])):\n return 'YES'\n return 'NO'\nprint(main())\n", "passed": true, "time": 0.28, "memory": 14624.0, "status": "done"}, {"code": "n = int(input())\na = list(input())\n\nfor i in range(len(a)):\n a[i] = int(a[i])\ns = sum(a)\n\nfor i in range(2, n+1):\n if s % i == 0:\n b = s // i\n\n t_sum = 0\n t_k = 0\n for k in a:\n if t_k > i:\n break\n t_sum += k\n if t_sum < b:\n continue\n elif t_sum == b:\n t_sum = 0\n t_k += 1\n continue\n else:\n break\n if t_k == i:\n print(\"YES\")\n return\n\nprint(\"NO\")\n \n \n", "passed": true, "time": 0.23, "memory": 14520.0, "status": "done"}, {"code": "a=int(input())\nb=[int(x) for x in input()]\nc=sum(b)\ne=[]\nfor i in range(2,len(b)+1):\n if c%i==0:\n e.append(i)\nd=False\nfor i in e:\n r=[]\n b1=b[:]\n num=c//i\n k=0\n while b1:\n k+=b1[0]\n b1=b1[1:]\n if k==num:\n r.append(k)\n k=0\n elif k>num:\n break\n if len(r)==i:\n d=True \nif d:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.21, "memory": 14476.0, "status": "done"}, {"code": "n = int(input())\npre_res = 1\nmax_s = n * 9\ns = input()\nsums = [1]*(max_s+1)\ni = 1\nwhile i <= max_s:\n\tsums[i] = i\n\ti += 1\nfor c in s:\n\tif c != '0':\n\t\td = int(c)\n\t\ti = 1\n\t\twhile i <= max_s:\n\t\t\tif sums[i] == i:\n\t\t\t\tsums[i] = d\n\t\t\telse:\n\t\t\t\tsums[i] += d\n\t\t\ti += 1\nres = 1\ni = 1\nwhile i <= max_s:\n\tif sums[i] == i:\n\t\tres += 1\n\ti += 1\nif res == 2:\n\tprint(\"NO\")\nelse:\n\tprint(\"YES\")\n", "passed": true, "time": 0.3, "memory": 14464.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nsumm = 0\nfor i in range(n):\n summ += int(s[i])\nfor i in range(2, 101):\n if summ % i == 0:\n d = 0\n for j in range(n):\n d += int(s[j])\n if d * i == summ:\n d = 0\n if d * i > summ:\n break\n if (j == n - 1 and d == 0):\n print('YES')\n return\nprint('NO')\n \n", "passed": true, "time": 0.25, "memory": 14452.0, "status": "done"}, {"code": "import sys\n\ninput()\ns = input()\nmaxc = len(s) // 2 * 9\nfor i in range(0, maxc):\n sum = 0\n r = \"Y\"\n l = 0\n for c in range(len(s)):\n sum += int(s[c])\n if sum == i:\n sum = 0\n l += 1\n elif sum > i:\n r = \"N\"\n break\n if r == \"Y\" and sum == 0 and l > 1:\n print(\"YES\")\n return\n\nprint(\"NO\")\n", "passed": true, "time": 0.3, "memory": 14372.0, "status": "done"}, {"code": "n = int(input())\nt = list(map(int, input()))\na = []\nfor i in t:\n if i != 0:\n a.append(i)\nif a == []:\n print('YES')\n return\n\nfor i in range(1, len(a)):\n sumn = sum(a[:i])\n snow = 0\n for j in range(i, len(a)):\n snow += a[j]\n if j == len(a) - 1 and snow == sumn:\n print('YES')\n return\n elif snow == sumn:\n snow = 0\n elif snow > sumn:\n break\n\nprint('NO')", "passed": true, "time": 0.15, "memory": 14688.0, "status": "done"}, {"code": "def test(x):\n nonlocal arr, n\n s = 0\n for i in range(n):\n s += arr[i]\n if s > x:\n return False\n elif s == x:\n s = 0\n return s == 0\n\n\n\nn = int(input())\noarr = list(map(int, list(input())))\narr = []\nfor el in oarr:\n if el:\n arr.append(el)\n else:\n n -= 1\ns = 0\nfor i in range(n - 1):\n s += arr[i]\n if test(s):\n print(\"YES\")\n break\nelse:\n if n == 0:\n print(\"YES\")\n else:\n print(\"NO\")\n", "passed": true, "time": 0.25, "memory": 14460.0, "status": "done"}] | [{"input": "5\n73452\n", "output": "YES\n"}, {"input": "4\n1248\n", "output": "NO\n"}, {"input": "2\n00\n", "output": "YES\n"}, {"input": "3\n555\n", "output": "YES\n"}, {"input": "8\n00020200\n", "output": "YES\n"}, {"input": "4\n7435\n", "output": "NO\n"}, {"input": "99\n999999999999999999999999999999999999999999999918888888888888888888888888888888888888888888888888887\n", "output": "YES\n"}, {"input": "5\n11980\n", "output": "NO\n"}, {"input": "4\n2680\n", "output": "YES\n"}, {"input": "15\n333703919182090\n", "output": "YES\n"}, {"input": "8\n54174760\n", "output": "YES\n"}, {"input": "84\n123608423980567916563149282633127550576921328162851174479585123236498689270768303090\n", "output": "YES\n"}, {"input": "11\n24954512677\n", "output": "NO\n"}, {"input": "89\n48529517761848681629105032446942740017666077684799424820853864981046129532307202343543879\n", "output": "NO\n"}, {"input": "14\n34732091671571\n", "output": "YES\n"}, {"input": "5\n30213\n", "output": "YES\n"}, {"input": "7\n0010120\n", "output": "YES\n"}, {"input": "75\n701550968134602984948768446130093645674414572984517902437769409395298622678\n", "output": "NO\n"}, {"input": "10\n7232095599\n", "output": "NO\n"}, {"input": "7\n5541514\n", "output": "YES\n"}, {"input": "6\n303030\n", "output": "YES\n"}, {"input": "6\n810214\n", "output": "YES\n"}, {"input": "10\n9410491089\n", "output": "YES\n"}, {"input": "4\n0760\n", "output": "NO\n"}, {"input": "11\n77741223101\n", "output": "YES\n"}, {"input": "12\n196493527920\n", "output": "NO\n"}, {"input": "93\n422951129271016503700234397427203319704940397318938157846153922624198061914374358965386132849\n", "output": "YES\n"}, {"input": "95\n98283499944967186695990624831960528372353708412534683491931125807866037495977770567651207842390\n", "output": "YES\n"}, {"input": "93\n745805743007484239743029351125106816821581657001902307029649638908353562984680888269297002308\n", "output": "YES\n"}, {"input": "95\n63839630788973501705593955617737116537536256623669215818613983033319316372125831199446308351430\n", "output": "YES\n"}, {"input": "91\n2051541782278415888842119452926140047121264880418474037041217527775760373306969266517205174\n", "output": "NO\n"}, {"input": "94\n7034965617675188707622087662902669462864299620896813095196728648483805681846217732949974650779\n", "output": "NO\n"}, {"input": "92\n14066331375782869025116943746607349076775655572332728568031635806727426324069498971915382378\n", "output": "NO\n"}, {"input": "90\n170996575076655992395856243508145635272750429329255192493277000774678782094281745394590857\n", "output": "NO\n"}, {"input": "100\n0809740931424957283280264749151125408689778966769781910603952566405858112111930579193115510555198933\n", "output": "YES\n"}, {"input": "100\n4360837235306857829226262079948050131795231482102447137288804547991971660484969090651046154392003840\n", "output": "YES\n"}, {"input": "100\n4818858843973413173925628155746968198939484726544502550668299768135121284562358161389491805498328723\n", "output": "YES\n"}, {"input": "100\n1481434020093151013248488915859811727012058656675018437252629813973080568161159615248610583559902826\n", "output": "NO\n"}, {"input": "100\n5492768358492023832426755085884370126192363497614837472363037754120965150617427992655444750828994630\n", "output": "NO\n"}, {"input": "100\n7876460771493995217591961791564105527925397369693556696278466376824002802517154352401808638978375899\n", "output": "NO\n"}, {"input": "2\n44\n", "output": "YES\n"}, {"input": "2\n55\n", "output": "YES\n"}, {"input": "3\n514\n", "output": "YES\n"}, {"input": "4\n1088\n", "output": "NO\n"}, {"input": "4\n6619\n", "output": "NO\n"}, {"input": "4\n4939\n", "output": "NO\n"}, {"input": "15\n771125622965333\n", "output": "YES\n"}, {"input": "15\n876799033969943\n", "output": "YES\n"}, {"input": "15\n923556472267622\n", "output": "YES\n"}, {"input": "20\n69325921242281090228\n", "output": "NO\n"}, {"input": "20\n62452246020300774037\n", "output": "NO\n"}, {"input": "20\n48279781257539808651\n", "output": "NO\n"}, {"input": "7\n1233321\n", "output": "YES\n"}, {"input": "3\n111\n", "output": "YES\n"}, {"input": "3\n010\n", "output": "NO\n"}, {"input": "3\n000\n", "output": "YES\n"}, {"input": "3\n343\n", "output": "NO\n"}, {"input": "4\n2351\n", "output": "NO\n"}, {"input": "3\n102\n", "output": "NO\n"}, {"input": "4\n3013\n", "output": "NO\n"}, {"input": "5\n11111\n", "output": "YES\n"}, {"input": "4\n3345\n", "output": "NO\n"}, {"input": "3\n001\n", "output": "NO\n"}, {"input": "3\n221\n", "output": "NO\n"}, {"input": "2\n02\n", "output": "NO\n"}, {"input": "5\n77777\n", "output": "YES\n"}, {"input": "5\n00000\n", "output": "YES\n"}, {"input": "2\n36\n", "output": "NO\n"}, {"input": "3\n100\n", "output": "NO\n"}, {"input": "3\n552\n", "output": "NO\n"}, {"input": "4\n3331\n", "output": "NO\n"}, {"input": "8\n11111111\n", "output": "YES\n"}, {"input": "6\n235555\n", "output": "YES\n"}, {"input": "3\n222\n", "output": "YES\n"}, {"input": "3\n131\n", "output": "NO\n"}, {"input": "7\n1112111\n", "output": "NO\n"}, {"input": "5\n53781\n", "output": "NO\n"}, {"input": "4\n1213\n", "output": "NO\n"}, {"input": "3\n101\n", "output": "YES\n"}, {"input": "2\n11\n", "output": "YES\n"}, {"input": "9\n122222211\n", "output": "NO\n"}, {"input": "31\n1111111111111111111111111111111\n", "output": "YES\n"}, {"input": "3\n300\n", "output": "NO\n"}, {"input": "4\n1001\n", "output": "YES\n"}, {"input": "7\n1111119\n", "output": "NO\n"}, {"input": "7\n0120110\n", "output": "NO\n"}] |
|
145 | 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.
-----Input-----
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
-----Output-----
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
-----Examples-----
Input
wjmzbmr
Output
CHAT WITH HER!
Input
xiaodao
Output
IGNORE HIM!
Input
sevenkplus
Output
CHAT WITH HER!
-----Note-----
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | interview | [{"code": "s = input()\nq = set()\nfor i in range(0, len(s)):\n q.add(s[i])\nprint(\"IGNORE HIM!\" if len(q) % 2 == 1 else \"CHAT WITH HER!\")", "passed": true, "time": 0.24, "memory": 14592.0, "status": "done"}, {"code": "print(\"IGNORE HIM!\" if len(set(input())) % 2 == 1 else \"CHAT WITH HER!\")", "passed": true, "time": 0.16, "memory": 14604.0, "status": "done"}, {"code": "print(\"CHAT WITH HER!\" if len(set(input())) % 2 == 0 else \"IGNORE HIM!\")", "passed": true, "time": 0.25, "memory": 14332.0, "status": "done"}, {"code": "print('CHAT WITH HER!' if len(set(input()))%2 == 0 else 'IGNORE HIM!')", "passed": true, "time": 1.78, "memory": 14432.0, "status": "done"}, {"code": "import sys\ninp = sys.stdin\ns = inp.readline()\ncnt = 0\nfor i in range(len(s) - 1):\n if s[i] not in s[i + 1:]: \n cnt += 1 \nif cnt % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")", "passed": true, "time": 0.24, "memory": 14580.0, "status": "done"}, {"code": "s=input()\nif(len(set(list(s)))%2==1):\n print(\"IGNORE HIM!\")\nelse:\n print(\"CHAT WITH HER!\")\n", "passed": true, "time": 0.31, "memory": 14404.0, "status": "done"}, {"code": "a=len(set(input()))\n\nif a%2 == 1:\n print(\"IGNORE HIM!\")\nelse:\n print(\"CHAT WITH HER!\")\n", "passed": true, "time": 0.2, "memory": 14620.0, "status": "done"}, {"code": "print(\"CHAT WITH HER!\" if len(set(input()))%2==0 else \"IGNORE HIM!\")", "passed": true, "time": 0.16, "memory": 14600.0, "status": "done"}, {"code": "s=list(input())\nm=[]\nfor i in range(0,len(s)) :\n if s[i] not in m :\n m.append(s[i])\nif len(m)%2==0 :\n print(\"CHAT WITH HER!\")\nelse :\n print(\"IGNORE HIM!\")\n", "passed": true, "time": 0.22, "memory": 14468.0, "status": "done"}, {"code": "s = input()\nd = set()\nfor i in s:\n if i not in d:\n d.add(i)\nif len(d) % 2 == 1:\n print('IGNORE HIM!')\nelse:\n print('CHAT WITH HER!')\n", "passed": true, "time": 0.23, "memory": 14352.0, "status": "done"}, {"code": "s=input()\nb={s[i] for i in range(len(s))}\nif(len(b)%2==0):\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n", "passed": true, "time": 1.64, "memory": 14600.0, "status": "done"}, {"code": "if(len(set(list(input())))%2==1):\n print(\"IGNORE HIM!\")\nelse:\n print(\"CHAT WITH HER!\")\n", "passed": true, "time": 1.64, "memory": 14440.0, "status": "done"}, {"code": "print(['CHAT WITH HER!', 'IGNORE HIM!'][len(set(list(input()))) % 2])", "passed": true, "time": 0.14, "memory": 14556.0, "status": "done"}, {"code": "3\n\ndef readln(): return tuple(map(int, input().split()))\n\nprint('CHAT WITH HER!' if len(set(list(input()))) % 2 == 0 else 'IGNORE HIM!')\n", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}, {"code": "print('IGNORE HIM!' if len(set(input()))%2 else 'CHAT WITH HER!')\n", "passed": true, "time": 0.14, "memory": 14604.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu Oct 10 12:43:24 2013\n\n@author: azimkhan\n\"\"\"\n\na = input()\ns = []\n\nfor c in a.lower():\n if (not c in s):\n s.append(c)\n \nl = len (s)\n\nprint(\"CHAT WITH HER!\" if (l % 2 == 0) else \"IGNORE HIM!\")\n", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "import math\nimport sys\ndef boyorgirl():\n distinct = []\n \n #Takes input\n datain = input()\n\n #Finds distinct chars\n for i in datain:\n if i not in distinct:\n distinct.append(i)\n \n #Determine boy or girl\n if len(distinct)%2 == 0:\n print(\"CHAT WITH HER!\")\n else:\n print(\"IGNORE HIM!\")\n\n\nboyorgirl()\n", "passed": true, "time": 0.15, "memory": 14528.0, "status": "done"}, {"code": "x=input()\n\nz=[(char) for char in x]\n\nnew_set=set(z)\nif (len(new_set)%2==0):\n print (\"CHAT WITH HER!\")\nif (len(new_set)%2 !=0):\n print (\"IGNORE HIM!\")\n \n \n", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "n = input()\na = []\nfor i in range(len(n)):\n if n[i] not in a:\n a.append(n[i])\nif len(a)%2 == 0:\n print('CHAT WITH HER!')\nelse:\n print('IGNORE HIM!')", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "name=input()\nchar_set=set()\nfor char in name :\n\tchar_set.add(char)\nif len(char_set) % 2 :\n\tprint('IGNORE HIM!')\nelse :\n\tprint('CHAT WITH HER!')\n", "passed": true, "time": 0.14, "memory": 14460.0, "status": "done"}, {"code": "a = input().strip()\nalph = [0] * 26\nfor i in a:\n alph[ord(i) - ord('a')] = 1\nif sum(alph) % 2 == 1:\n print('IGNORE HIM!')\nelse:\n print('CHAT WITH HER!')", "passed": true, "time": 0.14, "memory": 14636.0, "status": "done"}, {"code": "names = input()\n\nletters = []\nfor i in range(0, len(names)):\n if letters.count(names[i]) == 0:\n letters.append(names[i])\n\nif len(letters) % 2 == 0:\n print(\"CHAT WITH HER!\")\nelse:\n print(\"IGNORE HIM!\")\n", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "n=input()\nd={}\nflag=0\nfor i in n:\n d[i]=1\nif len(d.keys())%2==1:\n print(\"IGNORE HIM!\")\nelse :print(\"CHAT WITH HER!\")", "passed": true, "time": 0.23, "memory": 14456.0, "status": "done"}, {"code": "s = str(input())\nif len(set(s))%2 == 0:\n print('CHAT WITH HER!')\nelse:\n print('IGNORE HIM!')", "passed": true, "time": 0.15, "memory": 14596.0, "status": "done"}] | [{"input": "wjmzbmr\n", "output": "CHAT WITH HER!\n"}, {"input": "xiaodao\n", "output": "IGNORE HIM!\n"}, {"input": "sevenkplus\n", "output": "CHAT WITH HER!\n"}, {"input": "pezu\n", "output": "CHAT WITH HER!\n"}, {"input": "wnemlgppy\n", "output": "CHAT WITH HER!\n"}, {"input": "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn\n", "output": "IGNORE HIM!\n"}, {"input": "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx\n", "output": "CHAT WITH HER!\n"}, {"input": "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt\n", "output": "IGNORE HIM!\n"}, {"input": "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk\n", "output": "IGNORE HIM!\n"}, {"input": "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz\n", "output": "IGNORE HIM!\n"}, {"input": "tgcdptnkc\n", "output": "IGNORE HIM!\n"}, {"input": "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi\n", "output": "IGNORE HIM!\n"}, {"input": "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp\n", "output": "IGNORE HIM!\n"}, {"input": "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia\n", "output": "IGNORE HIM!\n"}, {"input": "fpellxwskyekoyvrfnuf\n", "output": "CHAT WITH HER!\n"}, {"input": "xninyvkuvakfbs\n", "output": "IGNORE HIM!\n"}, {"input": "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak\n", "output": "CHAT WITH HER!\n"}, {"input": "kmsk\n", "output": "IGNORE HIM!\n"}, {"input": "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz\n", "output": "CHAT WITH HER!\n"}, {"input": "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq\n", "output": "CHAT WITH HER!\n"}, {"input": "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm\n", "output": "IGNORE HIM!\n"}, {"input": "ppcpbnhwoizajrl\n", "output": "IGNORE HIM!\n"}, {"input": "sgubujztzwkzvztitssxxxwzanfmddfqvv\n", "output": "CHAT WITH HER!\n"}, {"input": "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw\n", "output": "IGNORE HIM!\n"}, {"input": "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu\n", "output": "CHAT WITH HER!\n"}, {"input": "ojjvpnkrxibyevxk\n", "output": "CHAT WITH HER!\n"}, {"input": "wjweqcrqfuollfvfbiyriijovweg\n", "output": "IGNORE HIM!\n"}, {"input": "hkdbykboclchfdsuovvpknwqr\n", "output": "IGNORE HIM!\n"}, {"input": "stjvyfrfowopwfjdveduedqylerqugykyu\n", "output": "IGNORE HIM!\n"}, {"input": "rafcaanqytfclvfdegak\n", "output": "CHAT WITH HER!\n"}, {"input": "xczn\n", "output": "CHAT WITH HER!\n"}, {"input": "arcoaeozyeawbveoxpmafxxzdjldsielp\n", "output": "IGNORE HIM!\n"}, {"input": "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika\n", "output": "CHAT WITH HER!\n"}, {"input": "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh\n", "output": "CHAT WITH HER!\n"}, {"input": "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg\n", "output": "CHAT WITH HER!\n"}, {"input": "udlpagtpq\n", "output": "CHAT WITH HER!\n"}, {"input": "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy\n", "output": "CHAT WITH HER!\n"}, {"input": "qagzrqjomdwhagkhrjahhxkieijyten\n", "output": "CHAT WITH HER!\n"}, {"input": "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb\n", "output": "CHAT WITH HER!\n"}, {"input": "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr\n", "output": "CHAT WITH HER!\n"}, {"input": "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc\n", "output": "IGNORE HIM!\n"}, {"input": "lnpdosnceumubvk\n", "output": "IGNORE HIM!\n"}, {"input": "efrk\n", "output": "CHAT WITH HER!\n"}, {"input": "temnownneghnrujforif\n", "output": "IGNORE HIM!\n"}, {"input": "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta\n", "output": "IGNORE HIM!\n"}, {"input": "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh\n", "output": "IGNORE HIM!\n"}, {"input": "gwntwbpj\n", "output": "IGNORE HIM!\n"}, {"input": "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim\n", "output": "IGNORE HIM!\n"}, {"input": "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd\n", "output": "CHAT WITH HER!\n"}, {"input": "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx\n", "output": "IGNORE HIM!\n"}, {"input": "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks\n", "output": "CHAT WITH HER!\n"}, {"input": "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx\n", "output": "CHAT WITH HER!\n"}, {"input": "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc\n", "output": "CHAT WITH HER!\n"}, {"input": "yzlzmesxdttfcztooypjztlgxwcr\n", "output": "IGNORE HIM!\n"}, {"input": "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc\n", "output": "IGNORE HIM!\n"}, {"input": "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq\n", "output": "CHAT WITH HER!\n"}, {"input": "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj\n", "output": "IGNORE HIM!\n"}, {"input": "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom\n", "output": "CHAT WITH HER!\n"}, {"input": "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo\n", "output": "CHAT WITH HER!\n"}, {"input": "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh\n", "output": "IGNORE HIM!\n"}, {"input": "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa\n", "output": "CHAT WITH HER!\n"}, {"input": "oh\n", "output": "CHAT WITH HER!\n"}, {"input": "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri\n", "output": "IGNORE HIM!\n"}, {"input": "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp\n", "output": "CHAT WITH HER!\n"}, {"input": "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp\n", "output": "CHAT WITH HER!\n"}, {"input": "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo\n", "output": "CHAT WITH HER!\n"}, {"input": "mnmbupgo\n", "output": "IGNORE HIM!\n"}, {"input": "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl\n", "output": "IGNORE HIM!\n"}, {"input": "yocxrzspinchmhtmqo\n", "output": "CHAT WITH HER!\n"}, {"input": "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv\n", "output": "CHAT WITH HER!\n"}, {"input": "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad\n", "output": "IGNORE HIM!\n"}, {"input": "ubvhyaebyxoghakajqrpqpctwbrfqzli\n", "output": "CHAT WITH HER!\n"}, {"input": "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy\n", "output": "IGNORE HIM!\n"}, {"input": "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd\n", "output": "IGNORE HIM!\n"}, {"input": "acrzbavz\n", "output": "CHAT WITH HER!\n"}, {"input": "drvzznznvrzskftnrhvvzxcalwutxmdza\n", "output": "IGNORE HIM!\n"}, {"input": "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws\n", "output": "CHAT WITH HER!\n"}, {"input": "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff\n", "output": "CHAT WITH HER!\n"}, {"input": "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu\n", "output": "CHAT WITH HER!\n"}, {"input": "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw\n", "output": "IGNORE HIM!\n"}, {"input": "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy\n", "output": "CHAT WITH HER!\n"}, {"input": "rhh\n", "output": "CHAT WITH HER!\n"}, {"input": "zhdouqfmlkenjzdijxdfxnlegxeuvhelo\n", "output": "IGNORE HIM!\n"}, {"input": "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn\n", "output": "CHAT WITH HER!\n"}, {"input": "urigreuzpxnej\n", "output": "CHAT WITH HER!\n"}] |
|
146 | This morning, Roman woke up and opened the browser with $n$ opened tabs numbered from $1$ to $n$. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.
He decided to accomplish this by closing every $k$-th ($2 \leq k \leq n - 1$) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be $b$) and then close all tabs with numbers $c = b + i \cdot k$ that satisfy the following condition: $1 \leq c \leq n$ and $i$ is an integer (it may be positive, negative or zero).
For example, if $k = 3$, $n = 14$ and Roman chooses $b = 8$, then he will close tabs with numbers $2$, $5$, $8$, $11$ and $14$.
After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it $e$) and the amount of remaining social network tabs ($s$). Help Roman to calculate the maximal absolute value of the difference of those values $|e - s|$ so that it would be easy to decide what to do next.
-----Input-----
The first line contains two integers $n$ and $k$ ($2 \leq k < n \leq 100$) — the amount of tabs opened currently and the distance between the tabs closed.
The second line consists of $n$ integers, each of them equal either to $1$ or to $-1$. The $i$-th integer denotes the type of the $i$-th tab: if it is equal to $1$, this tab contains information for the test, and if it is equal to $-1$, it's a social network tab.
-----Output-----
Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types $|e - s|$.
-----Examples-----
Input
4 2
1 1 -1 1
Output
2
Input
14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1
Output
9
-----Note-----
In the first example we can choose $b = 1$ or $b = 3$. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, $e = 2$ and $s = 0$ and $|e - s| = 2$.
In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them. | interview | [{"code": "n, k = list(map(int, input().split()))\n\nt = list(map(int, input().split()))\n\nd = [0 for _ in range(n)]\n\nfor _ in range(n):\n for i in range(n):\n if i % k != _ % k:\n d[_] += t[i]\n\nprint(max(abs(d[_]) for _ in range(n)))\n", "passed": true, "time": 0.29, "memory": 14256.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\na = list(map(int,input().split()))\nans = -100000000\nfor i in range(k):\n cnt = 0\n for j in range(n):\n if j%k != i:\n cnt += a[j]\n ans = max(ans,abs(cnt))\nprint(ans) \n", "passed": true, "time": 0.18, "memory": 14508.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nans = 0\nfor b in range(n):\n closed = [b + i * k for i in range(-n, n)]\n closed = set(c for c in closed if 0 <= c < n)\n test = sum(a[i] == -1 and i not in closed for i in range(n))\n play = sum(a[i] == 1 and i not in closed for i in range(n))\n ans = max(ans, abs(test - play))\n\nprint(ans)\n", "passed": true, "time": 0.57, "memory": 14436.0, "status": "done"}, {"code": "# = list(map(int, input().split()))\n# = map(int, input().split())\nn, k = list(map(int, input().split()))\nz = list(map(int, input().split()))\nans = -1\nfor b in range(n):\n tans = 0\n for s in range(n):\n if (s - b) % k != 0:\n tans += z[s]\n if abs(tans) > ans:\n ans = abs(tans)\nprint(ans)\n", "passed": true, "time": 0.32, "memory": 14280.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\narr = [int(x) for x in input().split()]\n\ndef calculate(a):\n nonlocal arr\n e, s = 0, 0\n for i in range(a, n, k):\n if arr[i] == -1:\n e += 1\n else:\n s += 1\n e -= arr.count(-1)\n s -= arr.count(1)\n return abs(e - s)\n\nl = []\nfor i in range(k):\n l.append(calculate(i))\nprint(max(l))\n", "passed": true, "time": 0.16, "memory": 14340.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nl = list(map(int, input().split()))\nmx = 0\nfor b in range(n):\n s = []\n for i in range(n):\n if abs(b - i) % k:\n s.append(l[i])\n mx = max(mx, abs(sum(s)))\nprint(mx)\n", "passed": true, "time": 0.21, "memory": 14392.0, "status": "done"}, {"code": "# \nimport collections, atexit, math, sys, bisect \n\nsys.setrecursionlimit(1000000)\ndef getIntList():\n return list(map(int, input().split())) \n\ntry :\n #raise ModuleNotFoundError\n import numpy\n def dprint(*args, **kwargs):\n #print(*args, **kwargs, file=sys.stderr)\n # in python 3.4 **kwargs is invalid???\n print(*args, file=sys.stderr)\n dprint('debug mode')\nexcept Exception:\n def dprint(*args, **kwargs):\n pass\n\n\n\ninId = 0\noutId = 0\nif inId>0:\n dprint('use input', inId)\n sys.stdin = open('input'+ str(inId) + '.txt', 'r') #\u6807\u51c6\u8f93\u51fa\u91cd\u5b9a\u5411\u81f3\u6587\u4ef6\nif outId>0:\n dprint('use output', outId)\n sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #\u6807\u51c6\u8f93\u51fa\u91cd\u5b9a\u5411\u81f3\u6587\u4ef6\n atexit.register(lambda :sys.stdout.close()) #idle \u4e2d\u4e0d\u4f1a\u6267\u884c atexit\n \nN, K = getIntList()\n#print(N)\nza = getIntList()\nrr = 0\nfor b in range(K):\n r = 0\n for i in range(N):\n if i%K==b: continue\n r+= za[i]\n r = abs(r)\n\n rr = max(r,rr)\n\nprint(rr)\n\n\n", "passed": true, "time": 0.74, "memory": 14348.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nA = list(map(int, input().split()))\nanswer = 0\nfor i in range(k):\n B = A.copy()\n C = []\n for j in range(n):\n if j % k != i:\n C.append(B[j])\n a = C.count(1)\n b = C.count(-1)\n if abs(a - b) > answer:\n answer = abs(a - b)\nprint(answer)\n", "passed": true, "time": 0.17, "memory": 14448.0, "status": "done"}, {"code": "n, k = [int(v) for v in input().split()]\nsigns = [int(v) for v in input().split()]\n\ntot_e = signs.count(1)\ntot_s = signs.count(-1)\n\nans = 0\n\nfor b in range(k):\n me, ms = 0, 0\n for c in range(b, n, k):\n if signs[c] == 1:\n me += 1\n else:\n ms += 1\n ans = max(ans, abs((tot_e - me) - (tot_s - ms)))\n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na = list(map(int, input().split()))\nt = 0\ns = 0\nfor i in range(n):\n if a[i] == 1:\n t += 1\n else:\n s += 1\n\nnum = 0\nfor i in range(k):\n t1, s1 = t, s\n for j in range(i, n, k):\n if a[j] == 1:\n t1 -= 1\n else:\n s1 -= 1\n\n num = max(num, abs(s1 - t1))\n\nprint(num)", "passed": true, "time": 0.16, "memory": 14384.0, "status": "done"}, {"code": "def f(k, c):\n e = s = 0\n for i in range(n):\n if (i-c)%k != 0:\n if a[i] == 1: \n e += 1\n else:\n s += 1\n #print(k, c, e,s)\n return abs(e-s)\n\nread = lambda: map(int, input().split())\nn, k = read()\na = list(read())\nmx = 0\nfor c in range(0, k):\n mx = max(mx, f(k,c))\nprint(mx)", "passed": true, "time": 0.17, "memory": 14272.0, "status": "done"}, {"code": "n,k=[int(i) for i in input().split()]\na=[int(i) for i in input().split()]\ns=0\nfor b in range(k):\n\tans=0\n\t\n\tfor i in range(1,n+1):\n\t\tif (i-b)%k!=0:\n\t\t\tans+=a[i-1]\n\ts=max(s,abs(ans))\nprint(s)", "passed": true, "time": 0.17, "memory": 14456.0, "status": "done"}, {"code": "\ndef main():\n buf = input()\n buflist = buf.split()\n n = int(buflist[0])\n k = int(buflist[1])\n buf = input()\n buflist = buf.split()\n tab = list(map(int, buflist))\n test_count = 0\n social_count = 0\n for i in range(n):\n if tab[i] == 1:\n test_count += 1\n else:\n social_count += 1\n max_diff = 0\n for i in range(k):\n test_remaining = test_count\n social_remaining = social_count\n for j in range(i, n, k):\n if tab[j] == 1:\n test_remaining -= 1\n else:\n social_remaining -= 1\n diff = abs(test_remaining - social_remaining)\n if diff > max_diff:\n max_diff = diff\n print(max_diff)\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14472.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nc = [0 for i in range(k)]\ns = sum(a)\nfor i in range(n):\n c[i % k] += a[i]\n\nans = -1\nfor i in c:\n ans = max(ans, abs(s - i))\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "from sys import stdin,stdout\n\nI = stdin.readline\nP = stdout.write\n\nn,k = map(int,I().split())\narr = [int(x) for x in I().split()]\n\ne = 0\ns = 0\nans = 0\nfor i in arr:\n if(i == -1):\n s+=1\n else:e+=1\n\nfor i in range(0,k):\n ce = 0\n cs = 0\n for j in range(i,n,k):\n if(arr[j] == -1):\n cs+=1\n else:\n ce+=1\n x = e-ce\n y = s - cs\n if(abs(x-y)>ans):ans = abs(x-y)\nprint(ans)", "passed": true, "time": 0.25, "memory": 14532.0, "status": "done"}, {"code": "n,k = [int(x) for x in input().split()]\n\nL = [int(x) for x in input().split()]\n\ntest = 0\nfor i in L:\n if i == 1:\n test +=1\n \nsocial = len(L)-test\n\nbest = 0\n\nfor i in range(0,k):\n tt = 0\n ts = 0\n j = 0\n while i+j*k < n:\n if L[i+j*k] == 1:\n tt += 1\n else:\n ts += 1\n j += 1\n best = max(abs(test-tt-social+ts),best)\nprint(best)", "passed": true, "time": 0.15, "memory": 14308.0, "status": "done"}, {"code": "from operator import itemgetter\n#int(input())\n#map(int,input().split())\n#[list(map(int,input().split())) for i in range(q)]\n#print(\"YES\" * ans + \"NO\" * (1-ans))\nn,k = list(map(int,input().split()))\nar = list(map(int,input().split()))\ne= 0\ns = 0\nans = 0\nfor j in range(k):\n e = 0\n s = 0\n for i in range(n):\n if i % k == j:\n continue\n if ar[i] == 1:\n e += 1\n else:\n s += 1\n ans = max(ans,abs(e-s))\nprint(ans)\n", "passed": true, "time": 0.18, "memory": 14276.0, "status": "done"}, {"code": "n,k=map(int,input().split())\nl=list(map(int,input().split()))\ne,s=0,0\nfor i in l:\n if i == 1:\n e+=1\n else:\n s+=1\nans=0\nfor i in range(k):\n e1,s1=e,s\n for j in range(i,n,k):\n if l[j] ==1:\n e1-=1\n else:\n s1-=1\n ans=max(ans,abs(e1-s1))\nprint(ans)", "passed": true, "time": 0.14, "memory": 14476.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na = list(map(int, input().split()))\nansw = 0\nfor b in range(n):\n sm = 0\n for i in range(n):\n if (i - b) % k:\n sm += a[i]\n answ = max(answ, abs(sm))\nprint(answ)", "passed": true, "time": 0.18, "memory": 14360.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nmas = list(map(int, input().split()))\nans = 0\nfor b in range(k):\n m = 0\n for i in range(n):\n if i % k == b:\n continue\n m += mas[i]\n ans = max(ans, abs(m))\nprint(ans)", "passed": true, "time": 0.17, "memory": 14320.0, "status": "done"}, {"code": "n, k = (int(x) for x in input().split())\ntabs = [int(x) for x in input().split()]\n\n#print(n, k, tabs)\n\nmods = [sum(tabs[i::k]) for i in range(k)]\n\n#print(mods)\n\nsummods = sum(mods)\nans = -1\nfor i in range(k):\n\tcand = abs(summods - mods[i])\n\tif cand > ans:\n\t\tans = cand\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14260.0, "status": "done"}, {"code": "import sys\nfrom math import floor, ceil\n\ninput = sys.stdin.readline\n\nn, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\ntotBad = 0\ntotGood = 0\n\nfor i in a:\n if i == -1:\n totBad += 1\n else:\n totGood += 1\n\nans = 0\nfor i in range(k):\n curBad = 0\n curGood = 0\n for j in range(i, n, k):\n if a[j] == -1:\n curBad += 1\n else:\n curGood += 1 \n ans = max(ans, abs((totBad - curBad) - (totGood - curGood)))\n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14456.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nt = list(map(int, input().split()))\nsume = 0\nsums = 0\nans = None\nfor i in range(n):\n if t[i] == 1: sume += 1\n else: sums += 1\n \nfor b in range(k):\n tsume = sume\n tsums = sums\n for i in range(b, n, k):\n if t[i] == 1: tsume -= 1\n else: tsums -= 1\n if ans == None: ans = abs(tsums-tsume)\n else: ans = max(ans, abs(tsums-tsume))\nprint(ans)\n \n", "passed": true, "time": 0.15, "memory": 14324.0, "status": "done"}, {"code": "n,k=list(map(int,input().split()))\nA=list(map(int,input().split()))\n\nANS=0\nfor i in range(k):\n ex=0\n so=0\n for l in range(n):\n if l%k==i:\n continue\n if A[l]==1:\n ex+=1\n else:\n so+=1\n\n if ANS<abs(ex-so):\n ANS=abs(ex-so)\n\nprint(ANS)\n \n", "passed": true, "time": 0.17, "memory": 14464.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nmass = list(map(int, input().split()))\ne = mass.count(1)\ns = mass.count(-1)\npopq = float('-inf')\nfor b in range(0, k):\n e1=e\n s1=s\n for vkladki in range(b, n, k):\n if mass[vkladki] == 1:\n e1 -= 1\n else:\n s1 -= 1\n popq = max(popq, abs(e1-s1))\nprint(popq)", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}] | [{"input": "4 2\n1 1 -1 1\n", "output": "2\n"}, {"input": "14 3\n-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1\n", "output": "9\n"}, {"input": "4 2\n1 1 1 -1\n", "output": "2\n"}, {"input": "4 2\n-1 1 -1 -1\n", "output": "2\n"}, {"input": "3 2\n1 1 -1\n", "output": "1\n"}, {"input": "20 2\n-1 1 -1 1 -1 -1 -1 1 -1 -1 -1 1 -1 -1 1 -1 -1 -1 1 1\n", "output": "6\n"}, {"input": "20 19\n-1 -1 1 1 -1 1 1 -1 1 1 -1 1 -1 1 1 1 -1 1 -1 1\n", "output": "5\n"}, {"input": "20 7\n-1 1 1 1 1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 1 -1 1\n", "output": "1\n"}, {"input": "100 17\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\n", "output": "12\n"}, {"input": "20 12\n-1 1 1 1 1 1 1 -1 1 1 -1 1 -1 -1 -1 -1 1 1 1 -1\n", "output": "6\n"}, {"input": "20 17\n-1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 1 1 1 -1 1 -1\n", "output": "4\n"}, {"input": "36 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\n", "output": "10\n"}, {"input": "36 35\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\n", "output": "6\n"}, {"input": "36 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\n", "output": "5\n"}, {"input": "36 12\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\n", "output": "5\n"}, {"input": "36 17\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\n", "output": "6\n"}, {"input": "36 22\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\n", "output": "8\n"}, {"input": "36 27\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\n", "output": "8\n"}, {"input": "36 32\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\n", "output": "8\n"}, {"input": "52 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\n", "output": "6\n"}, {"input": "52 51\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\n", "output": "5\n"}, {"input": "52 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\n", "output": "11\n"}, {"input": "52 12\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\n", "output": "5\n"}, {"input": "52 17\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\n", "output": "11\n"}, {"input": "52 22\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\n", "output": "14\n"}, {"input": "52 27\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\n", "output": "6\n"}, {"input": "52 32\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\n", "output": "4\n"}, {"input": "52 37\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\n", "output": "16\n"}, {"input": "52 42\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\n", "output": "10\n"}, {"input": "52 47\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\n", "output": "6\n"}, {"input": "68 2\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\n", "output": "10\n"}, {"input": "68 67\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\n", "output": "5\n"}, {"input": "68 7\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\n", "output": "14\n"}, {"input": "68 12\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\n", "output": "12\n"}, {"input": "68 17\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\n", "output": "4\n"}, {"input": "68 22\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\n", "output": "3\n"}, {"input": "68 27\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\n", "output": "5\n"}, {"input": "68 32\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\n", "output": "4\n"}, {"input": "68 37\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\n", "output": "12\n"}, {"input": "68 42\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\n", "output": "18\n"}, {"input": "68 47\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\n", "output": "26\n"}, {"input": "68 52\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\n", "output": "6\n"}, {"input": "68 57\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\n", "output": "2\n"}, {"input": "68 62\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\n", "output": "5\n"}, {"input": "84 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 -1 1 -1 1\n", "output": "8\n"}, {"input": "84 83\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\n", "output": "1\n"}, {"input": "84 7\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\n", "output": "6\n"}, {"input": "84 12\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\n", "output": "11\n"}, {"input": "84 17\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\n", "output": "9\n"}, {"input": "84 22\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\n", "output": "11\n"}, {"input": "84 27\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\n", "output": "19\n"}, {"input": "84 32\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\n", "output": "7\n"}, {"input": "84 37\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\n", "output": "7\n"}, {"input": "84 42\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\n", "output": "10\n"}, {"input": "84 47\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\n", "output": "4\n"}, {"input": "84 52\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\n", "output": "4\n"}, {"input": "84 57\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\n", "output": "10\n"}, {"input": "84 62\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\n", "output": "2\n"}, {"input": "84 67\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\n", "output": "4\n"}, {"input": "84 72\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\n", "output": "10\n"}, {"input": "84 77\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\n", "output": "12\n"}, {"input": "84 82\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\n", "output": "9\n"}, {"input": "100 2\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\n", "output": "14\n"}, {"input": "100 99\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\n", "output": "3\n"}, {"input": "100 7\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\n", "output": "7\n"}, {"input": "100 12\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\n", "output": "8\n"}, {"input": "100 22\n1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 1 1 -1 1 1 -1 1 -1 -1 1 -1 1 1 1 1 1 1 -1 1 1 -1 -1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1 1 1 -1 -1 1 1 -1 -1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 -1 1 1 -1 1 -1 -1 1 1 -1 -1 -1 -1 -1\n", "output": "18\n"}, {"input": "100 27\n1 1 1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 1 -1 1 -1 1 1 -1 -1 -1 1 1 1 -1 1 -1 -1 1 -1 1 -1 -1 -1 -1 1 1 -1 1 1 -1 1 -1 -1 -1 1 1 -1 1 -1 1 1 -1 -1 -1 1 1 -1 1 1 -1 1 1 -1 -1 -1 -1 1 1 -1 -1 1 -1 -1 1 -1 1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 1\n", "output": "15\n"}, {"input": "100 32\n1 1 1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 1 -1 1 1 -1 -1 1 1 1 -1 1 -1 -1 -1 -1 -1 1 1 1 -1 1 -1 1 1 1 1 -1 1 -1 1 1 -1 -1 1 -1 1 -1 -1 -1 1 -1 1 -1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 1 -1 1 -1 -1 1 1 -1 -1 1 1 -1 1\n", "output": "7\n"}, {"input": "100 37\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\n", "output": "3\n"}, {"input": "100 42\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\n", "output": "13\n"}, {"input": "100 47\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\n", "output": "19\n"}, {"input": "100 52\n1 1 -1 1 1 1 -1 -1 1 1 1 1 -1 -1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 1 -1 -1 -1 1 -1 1 -1 1 1 1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 -1 1 -1 -1 1 1 -1 -1 1 1 -1 -1 1 -1 1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 1 -1 1 -1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 1 1 1 1\n", "output": "10\n"}, {"input": "100 57\n1 1 -1 1 1 1 -1 -1 -1 1 1 1 1 -1 1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 1 1 -1 -1 -1 -1 1 -1 1 1 -1 -1 -1 1 1 -1 1 -1 -1 1 1 1 1 -1 1 1 -1 1 -1 1 -1 1 1 1 -1 -1 -1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 1 1 1 1 1 -1 -1 -1 1 -1 1 1 1 1 1\n", "output": "18\n"}, {"input": "100 62\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\n", "output": "6\n"}, {"input": "100 67\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\n", "output": "4\n"}, {"input": "100 72\n1 -1 -1 1 1 -1 1 1 1 -1 1 1 -1 -1 1 1 1 -1 1 1 1 -1 -1 1 -1 -1 -1 1 1 1 1 -1 -1 1 -1 -1 1 1 1 1 -1 -1 1 1 -1 1 1 -1 1 -1 -1 -1 1 1 -1 1 1 1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 -1 1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 -1 1 1 1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 -1\n", "output": "16\n"}, {"input": "100 77\n1 -1 1 -1 1 -1 -1 1 1 1 1 -1 1 -1 -1 -1 -1 1 1 1 -1 1 -1 -1 1 1 1 1 1 1 -1 -1 1 1 -1 1 -1 -1 -1 -1 -1 1 -1 1 1 1 1 -1 -1 -1 -1 1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 1 1 1 -1 1 -1 -1 -1 1 -1 -1 -1 -1 1 -1 1 -1 1 1 1 -1 1 -1 1\n", "output": "12\n"}, {"input": "100 82\n1 -1 1 -1 -1 1 -1 -1 1 -1 -1 -1 1 1 1 1 -1 1 -1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 1 1 -1 1 1 1 1 1 -1 1 1 -1 1 1 -1 -1 1 -1 1 -1 1 -1 1 -1 1 1 1 -1 -1 1 -1 1 -1 1 -1 1 1 1 -1 1 1 -1 1 -1 1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 1 -1 -1 1 1 -1 -1 1 -1 1 -1 -1 1\n", "output": "4\n"}, {"input": "100 87\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\n", "output": "8\n"}, {"input": "100 92\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\n", "output": "8\n"}, {"input": "100 97\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\n", "output": "3\n"}, {"input": "4 3\n-1 1 -1 -1\n", "output": "3\n"}, {"input": "4 3\n1 1 -1 1\n", "output": "3\n"}, {"input": "3 2\n1 1 1\n", "output": "2\n"}] |
|
147 | R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The White Buttons" and their hit song "Dacan the Baker", he met another robot for whom he was sure is the love of his life. Well, his summer, at least. Anyway, R3D3 was too shy to approach his potential soulmate, so he decided to write her a love letter. However, he stumbled upon a problem. Due to a terrorist threat, the Intergalactic Space Police was monitoring all letters sent in the area. Thus, R3D3 decided to invent his own alphabet, for which he was sure his love would be able to decipher.
There are n letters in R3D3’s alphabet, and he wants to represent each letter as a sequence of '0' and '1', so that no letter’s sequence is a prefix of another letter's sequence. Since the Intergalactic Space Communications Service has lately introduced a tax for invented alphabets, R3D3 must pay a certain amount of money for each bit in his alphabet’s code (check the sample test for clarifications). He is too lovestruck to think clearly, so he asked you for help.
Given the costs c_0 and c_1 for each '0' and '1' in R3D3’s alphabet, respectively, you should come up with a coding for the alphabet (with properties as above) with minimum total cost.
-----Input-----
The first line of input contains three integers n (2 ≤ n ≤ 10^8), c_0 and c_1 (0 ≤ c_0, c_1 ≤ 10^8) — the number of letters in the alphabet, and costs of '0' and '1', respectively.
-----Output-----
Output a single integer — minimum possible total a cost of the whole alphabet.
-----Example-----
Input
4 1 2
Output
12
-----Note-----
There are 4 letters in the alphabet. The optimal encoding is "00", "01", "10", "11". There are 4 zeroes and 4 ones used, so the total cost is 4·1 + 4·2 = 12. | interview | [{"code": "import sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\nn,a,b=map(int,input().split())\n\nif a<b: a,b=b,a\n\nif b==0:\n # 1 01 001 0001 ... is optimal, plus a long series of 0's\n print((n-1)*a)\nelse:\n # pascal's triangle thing\n pascal=[[1]*20005]\n for i in range(20004):\n newrow=[1]\n for j in range(1,20005):\n newrow.append(newrow[-1]+pascal[-1][j])\n if newrow[-1]>n: break\n pascal.append(newrow)\n def getcom(a,b):\n # return a+b choose b\n # if larger than n, return infinite\n if len(pascal[a])>b: return pascal[a][b]\n if b==0: return 1\n if b==1: return a\n return 100000005\n\n # start with the null node (prefix cost 0)\n # can split a node into two other nodes with added cost c+a+b\n # new nodes have prefix costs c+a, c+b\n # want n-1 splits in total\n n-=1 # now represents number of splits needed\n\n # binary search the last cost added\n lo=0\n hi=a*int((n**0.5)*2+5)\n\n while 1:\n mid=(lo+hi)//2\n # count stuff\n c0=0 # < mid\n c1=0 # = mid\n for i in range(mid//a+1):\n j=(mid-i*a)//b\n if (mid-i*a)%b!=0:\n # c0 += iC0 + (i+1)C1 + (i+2)C2 + ... + (i+j)Cj\n for k in range(j+1):\n #print(mid,i,k)\n c0+=getcom(i,k)\n if c0>n: break\n else:\n for k in range(j):\n #print(mid,i,k)\n c0+=getcom(i,k)\n if c0>n: break\n #print(mid,i,j,\"c1\")\n c1+=getcom(i,j)\n #print(mid,\"is\",c0,c1)\n if n<c0:\n hi=mid-1\n elif c0+c1<n:\n lo=mid+1\n else:\n # mid is correct cutoff\n lowcost=0 # sum of all cost, where cost < mid\n for i in range(mid//a+1):\n j=(mid-i*a)//b\n if (mid-i*a)%b!=0:\n for k in range(j+1):\n lowcost+=getcom(i,k)*(i*a+k*b)\n else:\n for k in range(j):\n lowcost+=getcom(i,k)*(i*a+k*b)\n temp=lowcost+(n-c0)*mid\n print(temp+n*(a+b))\n break", "passed": true, "time": 2.1, "memory": 19292.0, "status": "done"}, {"code": "import sys,heapq\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\nn,a,b=map(int,input().split())\n\nif a<b: a,b=b,a\n\nif b==0:\n # 1 01 001 0001 ... is optimal, plus a long series of 0's\n print((n-1)*a)\nelse:\n # pascal's triangle thing\n pascal=[[1]*20005]\n for i in range(20004):\n newrow=[1]\n for j in range(1,20005):\n newrow.append(newrow[-1]+pascal[-1][j])\n if newrow[-1]>n: break\n pascal.append(newrow)\n def getcom(a,b):\n # return a+b choose b\n # if larger than n, return infinite\n if len(pascal[a])>b: return pascal[a][b]\n if b==0: return 1\n if b==1: return a\n return 100000005\n\n # start with the null node (prefix cost 0)\n # can split a node into two other nodes with added cost c+a+b\n # new nodes have prefix costs c+a, c+b\n # want n-1 splits in total\n remain=n-1\n ans=0\n possible=[[a+b,1]] # [c,count]\n while 1:\n # cost u, v leaves\n u,v=heapq.heappop(possible)\n while possible and possible[0][0]==u:\n v+=possible[0][1]\n heapq.heappop(possible)\n if remain<=v:\n ans+=u*remain\n break\n ans+=u*v\n remain-=v\n heapq.heappush(possible,[u+a,v])\n heapq.heappush(possible,[u+b,v])\n print(ans)", "passed": true, "time": 2.82, "memory": 19104.0, "status": "done"}, {"code": "import sys,heapq\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\nn,a,b=map(int,input().split())\n\nif a<b: a,b=b,a\n\nif b==0:\n # 1 01 001 0001 ... is optimal, plus a long series of 0's\n print((n-1)*a)\nelse:\n # start with the null node (prefix cost 0)\n # can split a node into two other nodes with added cost c+a+b\n # new nodes have prefix costs c+a, c+b\n # want n-1 splits in total\n remain=n-1\n ans=0\n possible=[[a+b,1]] # [c,count]\n while 1:\n # cost u, v leaves\n u,v=heapq.heappop(possible)\n while possible and possible[0][0]==u:\n v+=possible[0][1]\n heapq.heappop(possible)\n if remain<=v:\n ans+=u*remain\n break\n ans+=u*v\n remain-=v\n heapq.heappush(possible,[u+a,v])\n heapq.heappush(possible,[u+b,v])\n print(ans)", "passed": true, "time": 0.16, "memory": 14408.0, "status": "done"}, {"code": "import sys,heapq\n\n#sys.stdin=open(\"data.txt\")\n\ninput=sys.stdin.readline\n\n\n\nn,a,b=list(map(int,input().split()))\n\n\n\nif a<b: a,b=b,a\n\n\n\nif b==0:\n\n # 1 01 001 0001 ... is optimal, plus a long series of 0's\n\n print((n-1)*a)\n\nelse:\n\n # pascal's triangle thing\n\n pascal=[[1]*20005]\n\n for i in range(20004):\n\n newrow=[1]\n\n for j in range(1,20005):\n\n newrow.append(newrow[-1]+pascal[-1][j])\n\n if newrow[-1]>n: break\n\n pascal.append(newrow)\n\n def getcom(a,b):\n\n # return a+b choose b\n\n # if larger than n, return infinite\n\n if len(pascal[a])>b: return pascal[a][b]\n\n if b==0: return 1\n\n if b==1: return a\n\n return 100000005\n\n\n\n # start with the null node (prefix cost 0)\n\n # can split a node into two other nodes with added cost c+a+b\n\n # new nodes have prefix costs c+a, c+b\n\n # want n-1 splits in total\n\n remain=n-1\n\n ans=0\n\n possible=[[a+b,1]] # [c,count]\n\n while 1:\n\n # cost u, v leaves\n\n u,v=heapq.heappop(possible)\n\n while possible and possible[0][0]==u:\n\n v+=possible[0][1]\n\n heapq.heappop(possible)\n\n if remain<=v:\n\n ans+=u*remain\n\n break\n\n ans+=u*v\n\n remain-=v\n\n heapq.heappush(possible,[u+a,v])\n\n heapq.heappush(possible,[u+b,v])\n\n print(ans)\n\n\n\n# Made By Mostafa_Khaled\n", "passed": true, "time": 1.36, "memory": 19200.0, "status": "done"}] | [{"input": "4 1 2\n", "output": "12\n"}, {"input": "2 1 5\n", "output": "6\n"}, {"input": "3 1 1\n", "output": "5\n"}, {"input": "5 5 5\n", "output": "60\n"}, {"input": "4 0 0\n", "output": "0\n"}, {"input": "6 0 6\n", "output": "30\n"}, {"input": "6 6 0\n", "output": "30\n"}, {"input": "2 1 2\n", "output": "3\n"}, {"input": "100000000 1 0\n", "output": "99999999\n"}, {"input": "2 0 0\n", "output": "0\n"}, {"input": "2 100000000 100000000\n", "output": "200000000\n"}, {"input": "2 100000000 0\n", "output": "100000000\n"}, {"input": "2 0 100000000\n", "output": "100000000\n"}, {"input": "100000000 0 0\n", "output": "0\n"}, {"input": "100000000 100000000 100000000\n", "output": "266578227200000000\n"}, {"input": "100000000 100000000 0\n", "output": "9999999900000000\n"}, {"input": "100000000 0 100000000\n", "output": "9999999900000000\n"}, {"input": "2 50000000 0\n", "output": "50000000\n"}, {"input": "2 50000000 100000000\n", "output": "150000000\n"}, {"input": "2 50000000 0\n", "output": "50000000\n"}, {"input": "2 50000000 100000000\n", "output": "150000000\n"}, {"input": "100000000 50000000 0\n", "output": "4999999950000000\n"}, {"input": "100000000 50000000 100000000\n", "output": "191720992950000000\n"}, {"input": "100000000 50000000 0\n", "output": "4999999950000000\n"}, {"input": "100000000 50000000 100000000\n", "output": "191720992950000000\n"}, {"input": "96212915 66569231 66289469\n", "output": "170023209909758400\n"}, {"input": "39969092 91869601 91924349\n", "output": "93003696194821620\n"}, {"input": "26854436 29462638 67336233\n", "output": "30373819153055635\n"}, {"input": "39201451 80233602 30662934\n", "output": "50953283386656312\n"}, {"input": "92820995 96034432 40568102\n", "output": "158135215198065044\n"}, {"input": "81913246 61174868 31286889\n", "output": "96084588586645841\n"}, {"input": "74790405 66932852 48171076\n", "output": "111690840882243696\n"}, {"input": "88265295 26984472 18821097\n", "output": "52835608063500861\n"}, {"input": "39858798 77741429 44017779\n", "output": "59709461677488470\n"}, {"input": "70931513 41663344 29095671\n", "output": "64816798089350400\n"}, {"input": "68251617 52232534 34187120\n", "output": "75694251898945158\n"}, {"input": "44440915 82093126 57268128\n", "output": "77907273273831800\n"}, {"input": "61988457 90532323 72913492\n", "output": "130757350538583270\n"}, {"input": "13756397 41019327 86510346\n", "output": "19895886795999000\n"}, {"input": "84963589 37799442 20818727\n", "output": "63754887412974663\n"}, {"input": "99338896 62289589 49020203\n", "output": "146320678028775569\n"}, {"input": "1505663 3257962 1039115\n", "output": "60023256524142\n"}, {"input": "80587587 25402325 8120971\n", "output": "32044560697691212\n"}, {"input": "64302230 83635846 22670768\n", "output": "77790985833197594\n"}, {"input": "6508457 32226669 8706339\n", "output": "2645634460061466\n"}, {"input": "1389928 84918086 54850899\n", "output": "1953921305304795\n"}, {"input": "37142108 10188690 35774598\n", "output": "19009588918065432\n"}, {"input": "86813943 11824369 38451380\n", "output": "51645349299460766\n"}, {"input": "14913475 61391038 9257618\n", "output": "9761450207212562\n"}, {"input": "25721978 63666459 14214946\n", "output": "20847031763747988\n"}, {"input": "73363656 63565575 76409698\n", "output": "133919836504944416\n"}, {"input": "34291060 92893503 64680754\n", "output": "66960630525688676\n"}, {"input": "85779772 26434899 86820336\n", "output": "114681463889615136\n"}, {"input": "7347370 2098650 66077918\n", "output": "3070602135161752\n"}, {"input": "28258585 6194848 49146833\n", "output": "14441957862691571\n"}, {"input": "9678 133 5955\n", "output": "196970292\n"}, {"input": "9251 4756 2763\n", "output": "448302621\n"}, {"input": "1736 5628 2595\n", "output": "73441521\n"}, {"input": "5195 1354 2885\n", "output": "130236572\n"}, {"input": "1312 5090 9909\n", "output": "98808420\n"}, {"input": "8619 6736 9365\n", "output": "900966230\n"}, {"input": "151 7023 3093\n", "output": "5267919\n"}, {"input": "5992 2773 6869\n", "output": "340564941\n"}, {"input": "3894 9921 3871\n", "output": "299508763\n"}, {"input": "1006 9237 1123\n", "output": "38974261\n"}, {"input": "9708 3254 2830\n", "output": "391502526\n"}, {"input": "1504 1123 626\n", "output": "13538132\n"}, {"input": "8642 5709 51\n", "output": "135655830\n"}, {"input": "8954 4025 7157\n", "output": "641304164\n"}, {"input": "4730 8020 8722\n", "output": "484587068\n"}, {"input": "2500 5736 4002\n", "output": "136264140\n"}, {"input": "6699 4249 1068\n", "output": "196812772\n"}, {"input": "4755 6759 4899\n", "output": "336456318\n"}, {"input": "8447 1494 4432\n", "output": "298387478\n"}, {"input": "6995 4636 8251\n", "output": "561476311\n"}, {"input": "4295 9730 4322\n", "output": "346320888\n"}, {"input": "8584 4286 9528\n", "output": "738058224\n"}, {"input": "174 6826 355\n", "output": "2889605\n"}, {"input": "5656 7968 3400\n", "output": "379249528\n"}, {"input": "2793 175 3594\n", "output": "36405762\n"}, {"input": "2888 9056 3931\n", "output": "204521173\n"}, {"input": "6222 7124 6784\n", "output": "547839384\n"}, {"input": "8415 8714 2475\n", "output": "545452719\n"}, {"input": "2179 7307 8608\n", "output": "192281235\n"}, {"input": "1189 1829 6875\n", "output": "46521099\n"}] |
|
148 | The circle line of the Roflanpolis subway has $n$ stations.
There are two parallel routes in the subway. The first one visits stations in order $1 \to 2 \to \ldots \to n \to 1 \to 2 \to \ldots$ (so the next stop after station $x$ is equal to $(x+1)$ if $x < n$ and $1$ otherwise). The second route visits stations in order $n \to (n-1) \to \ldots \to 1 \to n \to (n-1) \to \ldots$ (so the next stop after station $x$ is equal to $(x-1)$ if $x>1$ and $n$ otherwise). All trains depart their stations simultaneously, and it takes exactly $1$ minute to arrive at the next station.
Two toads live in this city, their names are Daniel and Vlad.
Daniel is currently in a train of the first route at station $a$ and will exit the subway when his train reaches station $x$.
Coincidentally, Vlad is currently in a train of the second route at station $b$ and he will exit the subway when his train reaches station $y$.
Surprisingly, all numbers $a,x,b,y$ are distinct.
Toad Ilya asks you to check if Daniel and Vlad will ever be at the same station at the same time during their journey. In other words, check if there is a moment when their trains stop at the same station. Note that this includes the moments when Daniel or Vlad enter or leave the subway.
-----Input-----
The first line contains five space-separated integers $n$, $a$, $x$, $b$, $y$ ($4 \leq n \leq 100$, $1 \leq a, x, b, y \leq n$, all numbers among $a$, $x$, $b$, $y$ are distinct) — the number of stations in Roflanpolis, Daniel's start station, Daniel's finish station, Vlad's start station and Vlad's finish station, respectively.
-----Output-----
Output "YES" if there is a time moment when Vlad and Daniel are at the same station, and "NO" otherwise. You can print each letter in any case (upper or lower).
-----Examples-----
Input
5 1 4 3 2
Output
YES
Input
10 2 1 9 10
Output
NO
-----Note-----
In the first example, Daniel and Vlad start at the stations $(1, 3)$. One minute later they are at stations $(2, 2)$. They are at the same station at this moment. Note that Vlad leaves the subway right after that.
Consider the second example, let's look at the stations Vlad and Daniel are at. They are: initially $(2, 9)$, after $1$ minute $(3, 8)$, after $2$ minutes $(4, 7)$, after $3$ minutes $(5, 6)$, after $4$ minutes $(6, 5)$, after $5$ minutes $(7, 4)$, after $6$ minutes $(8, 3)$, after $7$ minutes $(9, 2)$, after $8$ minutes $(10, 1)$, after $9$ minutes $(1, 10)$.
After that, they both leave the subway because they are at their finish stations, so there is no moment when they both are at the same station. | interview | [{"code": "n, a, x, b, y = map(int, input().split())\n\nwhile a != x and b != y and a != b:\n\tif a == b:\n\t\tbreak\n\n\ta = a % n + 1\n\tb = b - 1 if b - 1 else n\n\nprint(\"YNEOS\"[a != b::2])", "passed": true, "time": 2.02, "memory": 14620.0, "status": "done"}, {"code": "n, a, x, b, y = list(map(int, input().split()))\na -= 1\nx -= 1\nb -= 1\ny -= 1\n\ndaniel = []\nvlad = []\ni = a\nwhile i != x:\n daniel.append(i)\n i = (i + 1) % n\ndaniel.append(x)\ni = b\nwhile i != y:\n vlad.append(i)\n i = (i - 1 + n) % n\nvlad.append(y)\n\nif any(u == v for u, v in zip(daniel, vlad)):\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.17, "memory": 14528.0, "status": "done"}, {"code": "n,a,x,b,y = list(map(int,input().split()))\na -= 1\nx -= 1\nb -= 1\ny -= 1\nwhile True:\n if a == b:\n print(\"YES\")\n break\n if a == x or b == y:\n print(\"NO\")\n break\n a = (a+1)%n\n b = (b-1)%n\n", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "n, a, x, b, y = list(map(int, input().split()))\nans = 'NO'\nif a == b:\n ans = 'YES'\nwhile a != x and b != y:\n if a == n:\n a = 0\n a += 1\n if b == 1:\n b = n + 1\n b -= 1\n if a == b:\n ans = 'YES'\nprint(ans)", "passed": true, "time": 0.16, "memory": 14532.0, "status": "done"}, {"code": "''' \u0628\u0650\u0633\u0652\u0645\u0650 \u0627\u0644\u0644\u064e\u0651\u0647\u0650 \u0627\u0644\u0631\u064e\u0651\u062d\u0652\u0645\u064e\u0670\u0646\u0650 \u0627\u0644\u0631\u064e\u0651\u062d\u0650\u064a\u0645\u0650 '''\n#codeforces1169A_live\ngi = lambda : list(map(int,input().strip().split()))\nn,a, x, b, y = gi()\nwhile a != x and b != y:\n\ta += 1\n\tif a > n:\n\t\ta = 1\n\tb -= 1\n\tif b <= 0:\n\t\tb = n\n\tif a == b:\n\t\tprint(\"YES\")\n\t\treturn\nprint(\"NO\")", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "#JMD\n#Nagendra Jha-4096\n\n \nimport sys\nimport math\n\n#import fractions\n#import numpy\n \n###File Operations###\nfileoperation=0\nif(fileoperation):\n orig_stdout = sys.stdout\n orig_stdin = sys.stdin\n inputfile = open('W:/Competitive Programming/input.txt', 'r')\n outputfile = open('W:/Competitive Programming/output.txt', 'w')\n sys.stdin = inputfile\n sys.stdout = outputfile\n\n###Defines...###\nmod=1000000007\n \n###FUF's...###\ndef nospace(l):\n ans=''.join(str(i) for i in l)\n return ans\n \n \n \n##### Main ####\nt=1\nfor tt in range(t):\n #n=int(input())\n n,a,x,b,y= map(int, sys.stdin.readline().split(' '))\n\n while 1:\n if a==x or b==y:\n break\n\n if a==b:\n break\n if(a<n):\n a+=1\n else:\n a=1\n\n if(b>1):\n b-=1\n else:\n b=n\n if a==b:\n print(\"YES\")\n else:\n print(\"NO\")\n\n #a=list(map(int,sys.stdin.readline().split(' ')))\n \n \n#####File Operations#####\nif(fileoperation):\n sys.stdout = orig_stdout\n sys.stdin = orig_stdin\n inputfile.close()\n outputfile.close()", "passed": true, "time": 0.16, "memory": 14596.0, "status": "done"}, {"code": "n, a, x, b, y = list(map(int, input().split()))\nwhile a != x and b != y:\n a += 1\n b -= 1\n if a == n + 1:\n a = 1\n if b == 0:\n b = n\n if a == b:\n print('YES')\n return\n## print(a, b)\nprint('NO')\n", "passed": true, "time": 2.2, "memory": 14564.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\n\nclass Problem:\n def __init__(self):\n pass\n\n def solve(self):\n print(self._solve())\n\n def _solve(self):\n n, a, x, b, y = [int(item) for item in input().split()]\n a -= 1\n b -= 1\n x -= 1\n y -= 1\n if (a == b):\n return \"YES\"\n for i in range(n):\n a = (a + 1) % n\n b = (b - 1) % n\n if a == b:\n return \"YES\"\n if b == y or a == x:\n break\n\n return \"NO\"\n\n\ndef main():\n problem = Problem()\n problem.solve()\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14528.0, "status": "done"}, {"code": "n, a, x, b, y = list(map(int, input().split()))\nz1 = a\nz2 = b\nimport sys\nwhile True:\n\tif z1 == z2:\n\t\tprint(\"YES\")\n\t\treturn\n\tif z1 == x or z2 == y:\n\t\tprint(\"NO\")\n\t\treturn\n\tz1 = (z1 % n) + 1\n\tif z2 == 1:\n\t\tz2 = n\n\telse:\n\t\tz2 -= 1\n\n", "passed": true, "time": 0.21, "memory": 14512.0, "status": "done"}, {"code": "def main():\n n,a,x,b,y = list(map(int,input().split()))\n same = False\n while True:\n if a != x:\n a += 1\n else:\n break\n if b != y:\n b -= 1\n else:\n break\n if a == n+1:\n a = 1\n if b == 0:\n b = n\n\n if a == b:\n break\n\n if a == b:\n print('YES')\n else:\n print('NO')\n\n\nmain()\n", "passed": true, "time": 0.16, "memory": 14508.0, "status": "done"}, {"code": "def main():\n n, a,x,b,y = map(int, input().strip().split())\n a -= 1\n x -= 1\n b -= 1\n y -= 1\n cf = a\n cs = b\n\n if a == b:\n print('YES')\n return\n while cf != x and cs != y:\n cf += 1\n cf %= n\n cs += (n - 1)\n cs %= n\n if cf == cs:\n print('YES')\n return\n print('NO')\n return\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.2, "memory": 14572.0, "status": "done"}, {"code": "def main():\n n, a, x, b, y = list(map(int, input().split()))\n flag = False\n for i in range(n):\n if a == b:\n flag = True\n if a == x:\n break\n if b == y:\n break\n a += 1\n b -= 1\n if a == n + 1:\n a = 1\n if b == 0:\n b = n\n if flag:\n print('YES')\n else:\n print('NO')\n\nmain()\n", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}, {"code": "n, a, x, b, y = map(int, input().split())\na -= 1\nb -= 1\nx -= 1\ny -= 1\nres = a == b\nwhile a != x and b != y:\n if a != x: a = (a + 1) % n\n if b != y: b = (b - 1) % n\n res |= a == b\n\nprint(\"YES\" if res else \"NO\")", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "n,a,x,b,y=list(map(int,input().split()))\nfl=0\nwhile True:\n a+=1\n if a==n+1:\n a=1\n b-=1\n if b==0:\n b=n\n if a==b:\n fl=1\n break\n elif a==x or b==y:\n break\nif fl:\n print('YES')\nelse:\n print('NO')\n \n", "passed": true, "time": 0.14, "memory": 14596.0, "status": "done"}, {"code": "def main():\n n, a, x, b, y = map(int, input().split())\n a -= 1\n x -= 1\n b -= 1\n y -= 1\n if x < a:\n x += n\n if y > b:\n b += n\n while a != x and b != y:\n a += 1\n b -= 1\n if a % n == b % n:\n print(\"YES\")\n return 0\n print(\"NO\")\n return 0\n\nmain()", "passed": true, "time": 0.24, "memory": 14520.0, "status": "done"}, {"code": "n, a, x, b, y = list(map(int,input().split()))\n\nwhile(a != x and b != y):\n a = (a)%n + 1\n b = (b - 2)%n + 1\n if(a == b):\n print('YES')\n return\n if(a == x or b == y):\n break\nprint('NO')\n", "passed": true, "time": 0.15, "memory": 14372.0, "status": "done"}, {"code": "import sys\n# gcd\n# from fractions import gcd\n# from math import ceil, floor\n# from copy import deepcopy\n# from itertools import accumulate\n# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']\n# print(S.most_common(2)) # [('b', 5), ('c', 4)]\n# print(S.keys()) # dict_keys(['a', 'b', 'c'])\n# print(S.values()) # dict_values([3, 5, 4])\n# print(S.items()) # dict_items([('a', 3), ('b', 5), ('c', 4)])\n# from collections import Counter\n# import math\n# from functools import reduce\n#\n# fin = open('in_1.txt', 'r')\n# sys.stdin = fin\ninput = sys.stdin.readline\ndef ii(): return int(input())\ndef mi(): return list(map(int, input().rstrip().split()))\ndef lmi(): return list(map(int, input().rstrip().split()))\ndef li(): return list(input().rstrip())\n# template\n\n\ndef __starting_point():\n\n # write code\n n, a, x, b, y = mi()\n while (a % n != x % n and b % n != y % n):\n a += 1\n a %= n\n b -= 1\n b %= n\n if a % n == b % n:\n print('YES')\n break\n else:\n print('NO')\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "n,a,x,b,y = list(map(int, input().split(' ')))\na -= 1\nx -= 1\nb -= 1\ny -= 1\nwhile True :\n if a == b :\n print(\"YES\")\n break\n elif a == x or b == y :\n print(\"NO\")\n break\n else :\n a = (a+1)%n\n b = (b-1)%n\n", "passed": true, "time": 0.15, "memory": 14392.0, "status": "done"}, {"code": "n, a, x, b, y = [int(x) for x in input().split()]\n\nar = []\nbr = []\n\nif a < x:\n ar = list(range(a, x+1))\nelse:\n ar = list(range(a, n+1)) + list(range(1, x+1))\n\nif b > y:\n br = list(range(b, y-1, -1))\nelse:\n br = list(range(b, 0, -1)) + list(range(n, y-1, -1))\n\ncan = False\n\nfor i in range(min(len(ar), len(br))):\n if ar[i] == br[i]:\n can = True\n\nif can:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14556.0, "status": "done"}, {"code": "n,a,x,b,y = list(map(int,input().split()))\njoin = False\n#print(min((x-a)%n, (b-y)%n))\nfor k in range(min((x-a)%n, (b-y)%n)+1):\n\tif a==b:\n\t\tjoin = True\n\ta+=1\n\ta%=n\n\tb-=1\n\tb%=n\nif join:\n\tprint('YES')\nelse:\n\tprint('NO')\n", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "#\t!/usr/bin/env python3\n#\tencoding: UTF-8\n#\tModified: <26/May/2019 09:11:38 PM>\n\n\n#\t\u272a H4WK3yE\u4e61\n#\tMohd. Farhan Tahir\n#\tIndian Institute Of Information Technology (IIIT), Gwalior\n\n\nimport sys\n\n\ndef get_array(): return list(map(int, sys.stdin.readline().split()))\n\n\ndef get_ints(): return list(map(int, sys.stdin.readline().split()))\n\n\ndef input(): return sys.stdin.readline().strip()\n\n\ndef main():\n n, a, x, b, y = get_ints()\n daniel = [-1] * (n + 1)\n if x >= a:\n t = 0\n for i in range(a, x + 1):\n daniel[i] = t\n t += 1\n else:\n t = 0\n for i in range(a, n + 1):\n daniel[i] = t\n t += 1\n for i in range(1, x + 1):\n daniel[i] = t\n t += 1\n\n vlad = [-1] * (n + 1)\n if y <= b:\n t = 0\n for i in range(b, y - 1, -1):\n vlad[i] = t\n t += 1\n else:\n t = 0\n for i in range(b, 0, -1):\n vlad[i] = t\n t += 1\n for i in range(n, y - 1, -1):\n vlad[i] = t\n t += 1\n ans = 'NO'\n for i in range(1, n + 1):\n if daniel[i] == vlad[i] and daniel[i] != -1:\n ans = 'YES'\n break\n # print(vlad)\n # print(daniel)\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14420.0, "status": "done"}, {"code": "def main():\n n, a, x, b, y = map(int, input().split(' '))\n while a != x and b != y:\n a = a + 1\n b = b - 1\n if a == n + 1:\n a = 1\n if b == 0:\n b = n\n if a == b:\n print(\"YES\")\n return\n print(\"NO\")\n return\n\nmain()", "passed": true, "time": 0.15, "memory": 14560.0, "status": "done"}] | [{"input": "5 1 4 3 2\n", "output": "YES\n"}, {"input": "10 2 1 9 10\n", "output": "NO\n"}, {"input": "4 3 4 2 1\n", "output": "NO\n"}, {"input": "100 2 97 84 89\n", "output": "YES\n"}, {"input": "100 43 55 42 15\n", "output": "NO\n"}, {"input": "47 15 45 28 38\n", "output": "YES\n"}, {"input": "17 14 2 12 10\n", "output": "NO\n"}, {"input": "82 9 11 15 79\n", "output": "NO\n"}, {"input": "53 10 34 1 48\n", "output": "NO\n"}, {"input": "55 55 27 45 50\n", "output": "NO\n"}, {"input": "33 15 6 1 3\n", "output": "NO\n"}, {"input": "45 26 22 39 10\n", "output": "YES\n"}, {"input": "5 3 2 4 1\n", "output": "YES\n"}, {"input": "20 19 10 17 8\n", "output": "YES\n"}, {"input": "100 26 63 60 23\n", "output": "YES\n"}, {"input": "7 2 5 6 3\n", "output": "YES\n"}, {"input": "50 22 39 33 9\n", "output": "NO\n"}, {"input": "50 40 10 4 34\n", "output": "YES\n"}, {"input": "5 3 1 2 4\n", "output": "YES\n"}, {"input": "4 1 2 3 4\n", "output": "YES\n"}, {"input": "4 1 2 4 3\n", "output": "NO\n"}, {"input": "4 1 3 2 4\n", "output": "NO\n"}, {"input": "4 1 3 4 2\n", "output": "NO\n"}, {"input": "4 1 4 2 3\n", "output": "NO\n"}, {"input": "4 1 4 3 2\n", "output": "YES\n"}, {"input": "4 2 1 3 4\n", "output": "NO\n"}, {"input": "4 2 1 4 3\n", "output": "YES\n"}, {"input": "4 2 3 1 4\n", "output": "NO\n"}, {"input": "4 2 3 4 1\n", "output": "YES\n"}, {"input": "4 2 4 1 3\n", "output": "NO\n"}, {"input": "4 2 4 3 1\n", "output": "NO\n"}, {"input": "4 3 1 2 4\n", "output": "NO\n"}, {"input": "4 3 1 4 2\n", "output": "NO\n"}, {"input": "4 3 2 1 4\n", "output": "YES\n"}, {"input": "4 3 2 4 1\n", "output": "NO\n"}, {"input": "4 3 4 1 2\n", "output": "YES\n"}, {"input": "4 4 1 2 3\n", "output": "YES\n"}, {"input": "4 4 1 3 2\n", "output": "NO\n"}, {"input": "4 4 2 1 3\n", "output": "NO\n"}, {"input": "4 4 2 3 1\n", "output": "NO\n"}, {"input": "4 4 3 1 2\n", "output": "NO\n"}, {"input": "4 4 3 2 1\n", "output": "YES\n"}, {"input": "10 9 10 3 4\n", "output": "NO\n"}, {"input": "60 1 50 51 49\n", "output": "NO\n"}, {"input": "10 1 4 3 9\n", "output": "YES\n"}, {"input": "9 7 2 6 8\n", "output": "YES\n"}, {"input": "5 4 2 1 5\n", "output": "YES\n"}, {"input": "5 4 2 1 3\n", "output": "YES\n"}, {"input": "5 3 1 2 4\n", "output": "YES\n"}, {"input": "6 4 3 6 5\n", "output": "YES\n"}, {"input": "10 10 9 6 7\n", "output": "YES\n"}, {"input": "5 1 3 2 5\n", "output": "NO\n"}, {"input": "5 5 4 1 2\n", "output": "YES\n"}, {"input": "10 5 10 3 1\n", "output": "NO\n"}, {"input": "7 5 3 2 4\n", "output": "YES\n"}, {"input": "6 4 1 2 5\n", "output": "YES\n"}, {"input": "5 2 1 4 5\n", "output": "YES\n"}, {"input": "7 1 6 5 2\n", "output": "YES\n"}, {"input": "13 1 9 2 13\n", "output": "NO\n"}, {"input": "10 1 4 5 2\n", "output": "YES\n"}, {"input": "6 3 1 5 2\n", "output": "YES\n"}, {"input": "43 41 39 40 1\n", "output": "YES\n"}, {"input": "8 7 2 3 5\n", "output": "YES\n"}, {"input": "10 2 5 8 4\n", "output": "YES\n"}, {"input": "8 1 4 5 6\n", "output": "YES\n"}, {"input": "100 1 5 20 2\n", "output": "NO\n"}, {"input": "6 5 6 3 4\n", "output": "NO\n"}, {"input": "10 9 10 5 8\n", "output": "NO\n"}, {"input": "6 5 6 3 1\n", "output": "NO\n"}, {"input": "7 7 1 2 6\n", "output": "YES\n"}, {"input": "10 2 4 7 3\n", "output": "NO\n"}, {"input": "6 3 2 5 1\n", "output": "YES\n"}, {"input": "6 5 2 3 1\n", "output": "YES\n"}, {"input": "91 36 25 5 91\n", "output": "NO\n"}, {"input": "90 1 2 5 4\n", "output": "NO\n"}, {"input": "5 4 5 3 1\n", "output": "NO\n"}, {"input": "5 5 4 1 3\n", "output": "YES\n"}, {"input": "7 5 3 1 2\n", "output": "YES\n"}, {"input": "5 5 1 2 3\n", "output": "YES\n"}, {"input": "24 14 23 18 21\n", "output": "YES\n"}, {"input": "10 9 10 1 8\n", "output": "YES\n"}, {"input": "20 19 2 1 20\n", "output": "YES\n"}, {"input": "7 1 5 4 7\n", "output": "NO\n"}, {"input": "20 19 2 1 18\n", "output": "YES\n"}, {"input": "5 5 1 2 4\n", "output": "YES\n"}] |
|
149 | Unlucky year in Berland is such a year that its number n can be represented as n = x^{a} + y^{b}, where a and b are non-negative integer numbers.
For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 2^0 + 3^1, 17 = 2^3 + 3^2 = 2^4 + 3^0) and year 18 isn't unlucky as there is no such representation for it.
Such interval of years that there are no unlucky years in it is called The Golden Age.
You should write a program which will find maximum length of The Golden Age which starts no earlier than the year l and ends no later than the year r. If all years in the interval [l, r] are unlucky then the answer is 0.
-----Input-----
The first line contains four integer numbers x, y, l and r (2 ≤ x, y ≤ 10^18, 1 ≤ l ≤ r ≤ 10^18).
-----Output-----
Print the maximum length of The Golden Age within the interval [l, r].
If all years in the interval [l, r] are unlucky then print 0.
-----Examples-----
Input
2 3 1 10
Output
1
Input
3 5 10 22
Output
8
Input
2 3 3 5
Output
0
-----Note-----
In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].
In the second example the longest Golden Age is the interval [15, 22]. | interview | [{"code": "x,y,l,r=list(map(int,input().split()))\nb=set()\na=0\nb.add(l-1)\nb.add(r+1)\nfor i in range(100):\n xx=x**i\n if xx>r: break\n for j in range(100):\n rr=xx+(y**j)\n if rr>r: break\n if rr>=l:\n b.add(rr)\nb=sorted(list(b))\nfor i in range(1,len(b)):\n a=max(a,b[i]-b[i-1]-1)\nprint(a)\n", "passed": true, "time": 0.19, "memory": 14596.0, "status": "done"}, {"code": "x, y, l, r = list(map(int, input().split()))\nxs = [x ** i for i in range(61) if x ** i <= 10 ** 18]\nys = [y ** i for i in range(61) if y ** i <= 10 ** 18]\nps = set()\nfor i in xs:\n\tfor j in ys:\n\t\tif l <= i + j <= r:\n\t\t\tps.add(i + j)\nps.add(l - 1)\nps.add(r + 1)\nps = sorted(list(ps))\nans = 0\nfor i in range(1, len(ps)):\n\tans = max(ans, ps[i] - ps[i - 1] - 1)\nprint(ans)\n\n\n", "passed": true, "time": 0.17, "memory": 14660.0, "status": "done"}, {"code": "x, y, l, r = map(int, input().split())\ndata = []\ntx = 1\nwhile (tx < r + 3):\n ty = 1\n while (ty < r + 3):\n data.append(tx + ty)\n ty *= y\n tx *= x\ndata = sorted(set(data))\ndata = [elem for elem in data if l <= elem and elem <= r]\ndata = [l - 1] + data + [r + 1] \nans = 0\nfor i in range(1, len(data)):\n ans = max(ans, data[i] - data[i - 1] - 1)\nprint(ans)", "passed": true, "time": 0.16, "memory": 14572.0, "status": "done"}, {"code": "a,b,c,d = list(map(int, input().split(' ')))\n\nMXV = 10 ** 18\n\napows, bpows = [], []\naa, bb = 1, 1\nwhile aa <= MXV:\n apows.append(aa)\n aa *= a\nwhile bb <= MXV:\n bpows.append(bb)\n bb *= b\n\nvals = set()\nfor i in range(len(apows)):\n for j in range(len(bpows)):\n vals.add(apows[i] + bpows[j])\n\nvlist = list(vals)\nvlist.sort()\nans = 0\nlast = c-1 \nfor v in vlist:\n if c <= v and v <= d:\n ans = max(ans, v - last - 1)\n last = v\nans = max(ans, d-last)\n\nprint(ans)\n", "passed": true, "time": 0.27, "memory": 14584.0, "status": "done"}, {"code": "x, y, l, r = map(int, input().split())\nv = [l - 1, r + 1]\nfor a in range(0, 60):\n\tif x ** a > r:\n\t\tbreak\n\tfor b in range(0, 60):\n\t\tif y ** b > r:\n\t\t\tbreak\n\t\tif l <= x ** a + y ** b <= r:\n\t\t\tv += [x ** a + y ** b]\nv.sort()\nans = 0\nfor i in range(len(v) - 1):\n\tans = max(ans, v[i + 1] - v[i] - 1)\nprint(ans)", "passed": true, "time": 0.19, "memory": 14528.0, "status": "done"}, {"code": "x, y, l, r = list(map(int, input().split()))\n\nxs = []\nnow = 1\nwhile True:\n if now > r:\n break\n xs.append(now)\n now *= x\n\nys = []\nnow = 1\nwhile True:\n if now > r:\n break\n ys.append(now)\n now *= y\n\nress = [x + y for x in xs for y in ys]\nress = [i for i in ress if l <= i <= r]\nress.append(l - 1)\nress.append(r + 1)\nress = list(set(ress))\nress = sorted(ress)\n\nlst = -1\nans = 0\nfor i in ress:\n if lst != -1:\n ans = max(ans, i - lst - 1)\n lst = i\n\nprint(ans)\n", "passed": true, "time": 0.2, "memory": 14452.0, "status": "done"}, {"code": "x, y, l, r = list(map(int, input().split()))\na = []\nfor i in range(70):\n\tfor j in range(70):\n\t\tcur = x ** i + y ** j\n\t\tif cur > r:\n\t\t\tcontinue\n\t\tif cur <= r and cur >= l:\n\t\t\ta.append(cur)\na.sort()\nans = 0\nlast = l - 1\nfor it in a:\n\tans = max(ans, it - last - 1)\n\tlast = it\nans = max(ans, r - last)\nprint(ans)\n\n", "passed": true, "time": 1.11, "memory": 14420.0, "status": "done"}, {"code": "R=lambda:list(map(int,input().strip().split()))\n[x,y,l,r]=R()\na=list()\nb=list()\ncur=1\nwhile(cur<r):\n a.append(cur) \n cur*=x \ncur=1\nwhile(cur<r):\n b.append(cur) \n cur*=y \n \ns=set()\ns.add(l-1)\ns.add(r+1)\nfor p in a:\n for q in b:\n s.add(p+q) \ns=list(s)\ns.sort()\nml=0\nfor i in range(len(s)-1):\n if s[i]>=l-1 and s[i+1]<=r+1:\n ml=max(ml,s[i+1]-s[i]-1)\nprint(ml)", "passed": true, "time": 0.24, "memory": 14400.0, "status": "done"}, {"code": "x,y,l,r = list(map(int,input().split()))\na = []\nf = 1\nwhile f < r:\n\tg = 1\n\twhile f + g <= r:\n\t\tif f + g >= l:\n\t\t\ta.append(f + g)\n\t\tg *= y\n\tf *= x\na += [l-1,r+1]\na.sort()\nm = 1\nfor i in range(1,len(a)):\n\tif a[i-1] != a[i]:\n\t\ta[m] = a[i]\n\t\tm += 1\nans = 0\nfor i in range(1,m):\n\tans = max(ans, a[i] - a[i-1] - 1)\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "x, y, l, r = list(map(int, input().split()))\nrx = 0\nwhile x**rx < r:\n rx += 1\nry = 0\nwhile y**ry < r:\n ry += 1\n\narr = [l - 1, r + 1]\nfor i in range(rx):\n for j in range(ry):\n tmp = x**i + y**j\n if l <= tmp <= r:\n arr.append(tmp)\narr = list(sorted(set(arr)))\n\nans = 0\nfor i in range(1, len(arr)):\n ans = max(ans, arr[i] - arr[i - 1] - 1)\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14440.0, "status": "done"}, {"code": "x,y,l,r = list(map(int, input().split()))\nxx = 1\na = [0, 1e20]\nfor i in range(60):\n yy = 1\n while xx + yy <= r:\n a.append(xx+yy)\n yy *= y\n xx *= x\na.sort()\nans = 0\nfor i in range(len(a)-1):\n ll = max(a[i]+1, l)\n rr = min(a[i+1]-1, r)\n ans = max(ans, rr - ll+1)\n #~ print(i, ans, a[i], a[i+1])\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14620.0, "status": "done"}, {"code": "x,y,l,r = list(map(int, input().split()))\nlx = []\nly = []\nfor i in range(65):\n if x**i > r: break\n lx.append(x**i)\nfor i in range(65):\n if y**i > r: break\n ly.append(y**i)\n\nans = set()\nfor i in lx:\n for j in ly:\n if l <= i+j <= r:\n ans.add(i+j)\n\nans.add(l-1)\nans.add(r+1)\nans = sorted(list(ans))\nanslen = 0\nfor i in range(1, len(ans)):\n anslen = max(anslen, ans[i]-ans[i-1]-1)\n\n#print(ans)\nprint(anslen)\n", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "arr = [int(x) for x in input().split()]\na = arr[0]\nb = arr[1]\nl = arr[2]\nr = arr[3]\n\npivots = [];\n\npivots.append(l - 1);\nfor aTimes in range(65):\n for bTimes in range(65):\n now = a ** aTimes + b**bTimes;\n if now < l:\n continue;\n if now > r:\n break;\n pivots.append(now);\npivots.append(r + 1);\n\npivots.sort();\nans = 0;\nfor i in range(len(pivots)):\n if i == 0:\n continue;\n ans = max(pivots[i] - pivots[i - 1] - 1,ans);\n\nprint(ans);", "passed": true, "time": 0.17, "memory": 14628.0, "status": "done"}, {"code": "x, y, l, r = [int(x) for x in input().split()]\np_x = [1]\np_y = [1]\nfor i in range(1, 61):\n p_x.append(p_x[len(p_x) - 1] * x)\n p_y.append(p_y[len(p_y) - 1] * y)\npossible = set([0])\nfor i in range(61):\n for j in range(61):\n possible.add(p_x[i] + p_y[j])\na = []\nfor x in possible:\n a.append(x)\na.sort()\nans = 0\nfor i in range(1, len(a)):\n l1 = max(a[i - 1], l - 1)\n r1 = min(a[i], r + 1)\n ans = max(ans, r1 - l1 - 1)\nprint(ans)", "passed": true, "time": 0.62, "memory": 15056.0, "status": "done"}, {"code": "x,y,l,r = list(map(int, input().split()))\nbad = []\nfor i in range(61):\n for j in range(61):\n cr = x ** i + y ** j\n if l <= cr <= r: \n bad.append(x ** i + y ** j)\nbad = [l] + bad + [r]\nbad.sort()\nmx = 0\nif len(bad) == 2:\n print(max(mx, bad[1] - bad[0] + 1))\n return\nfor i in range(len(bad) - 1):\n cr = bad[i + 1] - bad[i] - 1\n if i == 0 or i == len(bad) - 2:\n cr += 1\n mx = max(mx, cr)\nprint(mx)\n", "passed": true, "time": 0.81, "memory": 14416.0, "status": "done"}, {"code": "x, y, l, r = map(int, input().split(' '))\na = []\nfor i in range(65):\n for j in range(65):\n t = x**i + y**j\n if t <= r and t >= l:\n a.append(t)\na.sort()\nif len(a) == 0:\n print(r - l + 1)\n return\nans = max(a[0] - l, r - a[-1])\nfor i in range(1, len(a)):\n ans = max(ans, a[i]-a[i-1]-1)\n\nprint(ans)", "passed": true, "time": 0.91, "memory": 14432.0, "status": "done"}, {"code": "x,y,l,r = list(map(int, input().split()))\n\nunl = []\nfor i in range(0, 70):\n for j in range(0, 70):\n xx = x**i + y**j\n if ( xx>=l and xx<=r):\n unl.append(xx)\n\nunl.sort()\n\nif (len(unl) == 0) :\n print(r - l + 1)\n return\n\ndiff = []\nif (unl[0] != l) :\n diff.append(unl[0] - l)\n\nif ( unl[-1] != r) :\n diff.append(r - unl[-1])\n\nfor i in range(1,len(unl)):\n d = (unl[i] - unl[i-1] -1)\n if ( d > 0):\n diff.append(d)\n\n\ndiff.sort();\n\nif (len(diff) == 0) :\n print(0)\n\nelse :\n print(diff[-1])\n\n\n\n", "passed": true, "time": 1.23, "memory": 14432.0, "status": "done"}, {"code": "[x, y, l, r] = list(map(int, input().rstrip().split()))\ndata = [l]\n\nlbad = False\nrbad = False\nfor i in range(0, 61):\n for j in range(0, 61):\n num = x ** i + y ** j\n if num == l:\n lbad = True\n if num == r:\n rbad = True\n if l <= num <= r:\n data.append(num)\n elif num > r:\n break\ndata.sort()\nmax_time = 0\ndata.append(r if rbad else r + 1)\ndata[0] = (l if lbad else l -1)\nfor i in range(0, len(data) - 1):\n max_time = max(data[i + 1] - data[i] - 1, max_time)\nprint(max_time)\n", "passed": true, "time": 0.17, "memory": 14352.0, "status": "done"}, {"code": "x, y, l, r = list(map(int, input().split()))\ndegree_x = []\ndegree_y = []\ni = 0\nwhile x ** i <= r:\n degree_x.append(x ** i)\n i += 1\ni = 0\nwhile y ** i <= r:\n degree_y.append(y ** i)\n i += 1\nsad_years = []\nfor i in degree_x:\n for j in degree_y:\n sad_years.append(i + j)\nsad_years.sort()\nres = 0\ni = 0\nwhile i < len(sad_years):\n if sad_years[i] < l or sad_years[i] > r:\n sad_years.pop(i)\n else:\n i += 1\nres = 0\nsad_years = [l - 1] + sad_years + [r + 1]\nfor i in range(len(sad_years) - 1):\n res = max(res, sad_years[i + 1] - sad_years[i] - 1)\nprint(res)\n", "passed": true, "time": 0.18, "memory": 14432.0, "status": "done"}, {"code": "x,y,l,r=list(map(int,input().split()))\nA=[l-1]\nfor i in range(100):\n\tif x**i>r:\n\t\tbreak\n\tfor j in range(100):\n\t\tif y**j>r:\n\t\t\tbreak\n\t\tt=x**i+y**j\n\t\tif t>=l and t<=r:\n\t\t\tA.append(t)\nA.append(r+1)\nA.sort()\nans=0\nfor i in range(len(A)-1):\n\tans=max(ans,A[i+1]-A[i]-1)\nprint(ans)\n\n", "passed": true, "time": 0.19, "memory": 14652.0, "status": "done"}, {"code": "x, y, l, r = list(map(int, input().split()))\n\n\ndef gen_list(var):\n cur = 1\n while cur <= r:\n yield cur\n cur *= var\n\nx_list = list(gen_list(x))\n# print(x_list)\ny_list = list(gen_list(y))\n# print(y_list)\n\nnumbers = [l-1, r+1]\nfor _x in x_list:\n for _y in y_list:\n n = _x + _y\n if n < l or n > r:\n continue\n numbers.append(n)\n\nnumbers = sorted(set(numbers))\n# print(numbers)\n\nif len(numbers) < 2:\n print('0')\n return\n\nmax_happy = max([numbers[i+1]-numbers[i]-1 for i in range(len(numbers) - 1)], default=0)\n\nprint(max_happy)\n", "passed": true, "time": 0.26, "memory": 14484.0, "status": "done"}, {"code": "x,y,l,r=list(map(int,input().split()))\n\nxx=[]\nyy=[]\np=1\nxx.append(l-1);\nwhile p<=r:\n q=1\n while p+q<=r:\n if p+q>=l and p+q<=r:\n xx.append(p+q)\n q*=y\n p*=x\nxx.append(r+1)\nxx.sort()\n\nfor i in range(0,len(xx)-1):\n yy.append(xx[i+1]-xx[i]-1)\n\nprint(max(yy))\n", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "def parser():\n while 1:\n data = list(input().split(' '))\n for number in data:\n if len(number) > 0:\n yield(number) \n\ninput_parser = parser()\n\ndef get_word():\n nonlocal input_parser\n return next(input_parser)\n\ndef get_number():\n data = get_word()\n try:\n return int(data)\n except ValueError:\n return float(data)\n\n\nx = get_number()\ny = get_number()\nl = get_number()\nr = get_number()\nn1 = 1;\na = list()\na.append(l - 1)\nfor i in range(0, 300):\n if n1 > r:\n break\n n2 = 1 \n for j in range(0, 300):\n if n1 + n2 > r:\n break\n if n1 + n2 >= l and n1 + n2 <= r:\n a.append(n1 + n2)\n n2 = n2 * y\n n1 = n1 * x\n \na.append(r + 1)\na.sort()\nans = 0\nfor i in range(0, len(a) - 1):\n ans = max(ans, a[i + 1] - a[i] - 1)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14664.0, "status": "done"}, {"code": "from sys import stdin\nimport re\nimport math\n\ndef readInt(count=1):\n m = re.match('\\s*' + ('([+-]?\\d+)\\s*' * count), stdin.readline())\n if m is not None:\n ret = []\n for i in range(1, m.lastindex + 1):\n ret.append(int(m.group(i)))\n return ret\n return None\n\nx, y, l, r = readInt(4)\n\nmax = 0\nunhappyYears = [l-1]\nxa = 1\nwhile xa <= r:\n yb = 1\n while True:\n val = xa + yb\n if val > r:\n break\n if val >= l and val not in unhappyYears:\n unhappyYears.append(val)\n yb *= y\n xa *= x\nunhappyYears.sort()\nunhappyYears.append(r+1)\n\nfor i in range(len(unhappyYears)-1):\n cur = unhappyYears[i+1] - unhappyYears[i] - 1\n if cur > max:\n max = cur\nprint(max)", "passed": true, "time": 0.2, "memory": 14496.0, "status": "done"}, {"code": "def power(a,p):\n\tif p==0:\n\t\treturn 1\n\tlol=power(a,p//2)\n\tlol=lol*lol\n\tif p%2==1:\n\t\treturn a*lol\n\telse:\n\t\treturn lol\n\nx,y,l,r=map(int,input().split())\n\ni=0\nd={}\n\nwhile 1:\n\tk=power(x,i)\n\tj=0\n\tif k>r:\n\t\tbreak\n\twhile 1:\n\t\tlol=power(y,j)\n\t\tif k+lol>r:\n\t\t\tbreak\n\t\td[k+lol]=1\n\t\tj+=1\n\ti+=1\nlast=l-1\nd[r+1]=1\narr=[]\nfor k in d.keys():\n\tarr.append(k)\nans=0\narr.sort()\nfor k in arr:\n\t#print(k)\n\tif k>=l:\n\t\tans=max(ans,k-last-1)\n\t\tlast=k\n\t\tif last>=r:\n\t\t\tbreak\nprint(ans)", "passed": true, "time": 0.23, "memory": 14548.0, "status": "done"}] | [{"input": "2 3 1 10\n", "output": "1\n"}, {"input": "3 5 10 22\n", "output": "8\n"}, {"input": "2 3 3 5\n", "output": "0\n"}, {"input": "2 2 1 10\n", "output": "1\n"}, {"input": "2 2 1 1000000\n", "output": "213568\n"}, {"input": "2 2 1 1000000000000000000\n", "output": "144115188075855871\n"}, {"input": "2 3 1 1000000\n", "output": "206415\n"}, {"input": "2 3 1 1000000000000000000\n", "output": "261485717957290893\n"}, {"input": "12345 54321 1 1000000\n", "output": "933334\n"}, {"input": "54321 12345 1 1000000000000000000\n", "output": "976614248345331214\n"}, {"input": "2 3 100000000 1000000000000\n", "output": "188286357653\n"}, {"input": "2 14 732028847861235712 732028847861235712\n", "output": "0\n"}, {"input": "14 2 732028847861235713 732028847861235713\n", "output": "1\n"}, {"input": "3 2 6 7\n", "output": "1\n"}, {"input": "16 5 821690667 821691481\n", "output": "815\n"}, {"input": "1000000000000000000 2 1 1000000000000000000\n", "output": "423539247696576511\n"}, {"input": "2 1000000000000000000 1000000000000000 1000000000000000000\n", "output": "423539247696576511\n"}, {"input": "2 2 1000000000000000000 1000000000000000000\n", "output": "1\n"}, {"input": "3 3 1 1\n", "output": "1\n"}, {"input": "2 3 626492297402423196 726555387600422608\n", "output": "100063090197999413\n"}, {"input": "4 4 1 1\n", "output": "1\n"}, {"input": "304279187938024110 126610724244348052 78460471576735729 451077737144268785\n", "output": "177668463693676057\n"}, {"input": "510000000000 510000000000 1 1000000000000000000\n", "output": "999998980000000000\n"}, {"input": "2 10000000000000000 1 1000000000000000000\n", "output": "413539247696576512\n"}, {"input": "84826654960259 220116531311479700 375314289098080160 890689132792406667\n", "output": "515374843694326508\n"}, {"input": "1001 9999 1 1000000000000000000\n", "output": "988998989390034998\n"}, {"input": "106561009498593483 3066011339919949 752858505287719337 958026822891358781\n", "output": "205168317603639445\n"}, {"input": "650233444262690661 556292951587380938 715689923804218376 898772439356652923\n", "output": "183082515552434548\n"}, {"input": "4294967297 4294967297 1 1000000000000000000\n", "output": "999999991410065406\n"}, {"input": "1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000\n", "output": "1\n"}, {"input": "2 2 1 1\n", "output": "1\n"}, {"input": "73429332516742239 589598864615747534 555287238606698050 981268715519611449\n", "output": "318240518387121676\n"}, {"input": "282060925969693883 446418005951342865 709861829378794811 826972744183396568\n", "output": "98493812262359820\n"}, {"input": "97958277744315833 443452631396066615 33878596673318768 306383421710156519\n", "output": "208425143965840685\n"}, {"input": "40975442958818854 7397733549114401 299774870238987084 658001214206968260\n", "output": "358226343967981177\n"}, {"input": "699 700 1 1000\n", "output": "697\n"}, {"input": "483076744475822225 425097332543006422 404961220953110704 826152774360856248\n", "output": "343076029885034022\n"}, {"input": "4294967297 4294967297 1 999999999999999999\n", "output": "999999991410065405\n"}, {"input": "702012794 124925148 2623100012 1000000000000000000\n", "output": "491571744457491660\n"}, {"input": "433333986179614514 1000000000000000000 433333986179614515 726628630292055493\n", "output": "293294644112440978\n"}, {"input": "999999999999999999 364973116927770629 4 4\n", "output": "1\n"}, {"input": "4 2 40 812\n", "output": "191\n"}, {"input": "2 3 1 1\n", "output": "1\n"}, {"input": "1556368728 1110129598 120230736 1258235681\n", "output": "989898863\n"}, {"input": "7 9 164249007852879073 459223650245359577\n", "output": "229336748650748455\n"}, {"input": "324693328712373699 541961409169732375 513851377473048715 873677521504257312\n", "output": "324693328712373697\n"}, {"input": "370083000139673112 230227213530985315 476750241623737312 746365058930029530\n", "output": "146054845259371103\n"}, {"input": "4 3 584 899\n", "output": "146\n"}, {"input": "4 3 286 581\n", "output": "161\n"}, {"input": "304045744870965151 464630021384225732 142628934177558000 844155070300317027\n", "output": "304045744870965149\n"}, {"input": "195627622825327857 666148746663834172 1 1000000000000000000\n", "output": "470521123838506314\n"}, {"input": "459168731438725410 459955118458373596 410157890472128901 669197645706452507\n", "output": "209242527248078910\n"}, {"input": "999999999999999999 999999999999999999 1 1000000000000000000\n", "output": "999999999999999997\n"}, {"input": "752299248283963354 680566564599126819 73681814274367577 960486443362068685\n", "output": "606884750324759243\n"}, {"input": "20373217421623606 233158243228114207 97091516440255589 395722640217125926\n", "output": "142191179567388113\n"}, {"input": "203004070900 20036005000 1 1000000000000000000\n", "output": "999999776959924100\n"}, {"input": "565269817339236857 318270460838647700 914534538271870694 956123707310168659\n", "output": "41589169038297966\n"}, {"input": "2 5 330 669\n", "output": "131\n"}, {"input": "9 9 91 547\n", "output": "385\n"}, {"input": "9 4 866389615074294253 992899492208527253\n", "output": "126509877134233001\n"}, {"input": "3037000500 3037000500 1 1000000000000000000\n", "output": "999999993925999000\n"}, {"input": "4294967297 4294967297 12 1000000000000000000\n", "output": "999999991410065406\n"}, {"input": "5 3 78510497842978003 917156799600023483\n", "output": "238418579101562499\n"}, {"input": "749206377024033575 287723056504284448 387669391392789697 931234393488075794\n", "output": "361536985631243879\n"}, {"input": "999999999999999999 454135 1000000000000000000 1000000000000000000\n", "output": "0\n"}, {"input": "759826429841877401 105086867783910112 667080043736858072 797465019478234768\n", "output": "92746386105019330\n"}, {"input": "1000000000000000000 1000000000000000000 5 7\n", "output": "3\n"}, {"input": "440968000218771383 43378854522801881 169393324037146024 995429539593716237\n", "output": "511082684852142973\n"}, {"input": "15049917793417622 113425474361704411 87565655389309185 803955352361026671\n", "output": "675479960205904638\n"}, {"input": "4 6 264626841724745187 925995096479842591\n", "output": "369878143059623936\n"}, {"input": "4294967297 4294967297 13 1000000000000000000\n", "output": "999999991410065406\n"}, {"input": "315729630349763416 22614591055604717 66895291338255006 947444311481017774\n", "output": "609100090075649641\n"}, {"input": "3 10 173 739\n", "output": "386\n"}, {"input": "161309010783040325 128259041753158864 5843045875031294 854024306926137845\n", "output": "564456254389938656\n"}, {"input": "239838434825939759 805278168279318096 202337849919104640 672893754916863788\n", "output": "433055320090924028\n"}, {"input": "9 9 435779695685310822 697902619874412541\n", "output": "262122924189101720\n"}, {"input": "967302429573451368 723751675006196376 143219686319239751 266477897142546404\n", "output": "123258210823306654\n"}, {"input": "10 8 139979660652061677 941135332855173888\n", "output": "697020144779318016\n"}, {"input": "4294967297 1000000000000000000 4294967296 17179869184\n", "output": "12884901886\n"}, {"input": "100914030314340517 512922595840756536 812829791042966971 966156272123068006\n", "output": "153326481080101036\n"}, {"input": "288230376151711744 288230376151711744 1 1000000000000000000\n", "output": "423539247696576512\n"}, {"input": "6 9 681 750\n", "output": "49\n"}, {"input": "880356874212472951 178538501711453307 162918237570625233 224969951233811739\n", "output": "46431449522358431\n"}, {"input": "2 7 405373082004080437 771991379629433514\n", "output": "153172782079203571\n"}, {"input": "10 11 10 11\n", "output": "1\n"}] |
|
150 | Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, while for n = 25 he needs to pay 5 and if n = 2 he pays only 1 burle.
As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial n in several parts n_1 + n_2 + ... + n_{k} = n (here k is arbitrary, even k = 1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition n_{i} ≥ 2 should hold for all i from 1 to k.
Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split n in parts.
-----Input-----
The first line of the input contains a single integer n (2 ≤ n ≤ 2·10^9) — the total year income of mr. Funt.
-----Output-----
Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax.
-----Examples-----
Input
4
Output
2
Input
27
Output
3 | interview | [{"code": "def is_izi(k):\n i = 2\n while (i * i <= k):\n if (k % i == 0):\n return 0\n i += 1\n return 1\nn = int(input())\nif (is_izi(n)):\n print(1)\nelif n % 2 == 0:\n print(2)\nelif n % 2 == 1:\n if (is_izi(n - 2)):\n print(2)\n else:\n print(3)", "passed": true, "time": 0.18, "memory": 14408.0, "status": "done"}, {"code": "def rwh_primes(n):\n sieve = [True] * n\n for i in range(3,int(n**0.5)+1,2):\n if sieve[i]:\n sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)\n return [2] + [i for i in range(3,n,2) if sieve[i]]\nprimes = rwh_primes(44722)\n\ndef isPrime(z):\n if z < 44722:\n return z in primes\n else:\n for p in primes:\n if z % p == 0:\n return False\n return True \n \nn = int(input())\nif n & 1:\n if isPrime(n):\n print(1)\n elif isPrime(n-2): \n print(2)\n else: \n print(3)\nelse:\n if n == 2:\n print(1)\n else: \n print(2)\n", "passed": true, "time": 0.26, "memory": 14436.0, "status": "done"}, {"code": "def is_prime(n):\n for i in range(2, int(n ** 0.5 + 1)):\n if n % i == 0:\n return False\n return True\n\n\nn = int(input())\nif n % 2 == 0:\n if is_prime(n):\n print(1)\n else:\n print(2)\nelse:\n if is_prime(n):\n print(1)\n elif is_prime(n - 2):\n print(2)\n else:\n print(3)", "passed": true, "time": 0.16, "memory": 14392.0, "status": "done"}, {"code": "import math\ndef isprime(n):\n for i in range(2, int(math.sqrt(n)) + 1):\n if n % i == 0:\n return False\n return True\n\nn = int(input())\nif isprime(n):\n print(1)\nelif n % 2 == 0:\n print(2)\nelif n % 2 == 1:\n if isprime(n - 2):\n print(2)\n else:\n print(3)\n", "passed": true, "time": 0.16, "memory": 14372.0, "status": "done"}, {"code": "n = int(input())\nif n == 2:\n\tprint(1)\nelif n % 2 == 0:\n\tprint(2)\nelse:\n\ti = 2\n\tflag = True\n\twhile i * i <= n:\n\t\tif n % i == 0:\n\t\t\tflag = False\n\t\t\tbreak\n\t\ti +=1 \n\tif flag:\n\t\tprint(1)\n\telse:\n\t\ti = 2\n\t\tflag = True\n\t\twhile i * i <= n - 2:\n\t\t\tif (n - 2) % i == 0:\n\t\t\t\tflag = False\n\t\t\t\tbreak\n\t\t\ti += 1\n\t\tif flag:\n\t\t\tprint(2)\n\t\telse:\n\t\t\tprint(3)", "passed": true, "time": 0.19, "memory": 14564.0, "status": "done"}, {"code": "import math\n\ndef isprime(n):\n if n == 2:\n return True\n\n sq = math.ceil(n ** 0.5) + 1\n for i in range(2, sq):\n if n % i == 0:\n return False\n return True\n\ndef solve(n):\n if isprime(n):\n return 1\n if n%2 == 0:\n return 2\n if isprime(n - 2):\n return 2\n return 3\n\nn = int(input())\nprint(solve(n))\n", "passed": true, "time": 0.16, "memory": 14424.0, "status": "done"}, {"code": "def test(n):\n maximum = int(n ** 0.5) + 3\n for i in range(2, min(maximum, n)):\n if n % i == 0:\n return False\n return True \n\n\nn = int(input())\nif n % 2 == 0:\n if n == 2:\n print(1)\n else: \n print(2)\nelse:\n if test(n) == True:\n print(1)\n elif test(n - 2) == True:\n print(2)\n else:\n print(3)", "passed": true, "time": 0.25, "memory": 14444.0, "status": "done"}, {"code": "def isPrime(n):\n def compositeTry(a,d,n,s):\n if pow(a,d,n) == 1:\n return False;\n for i in range(s):\n if pow(a,2**i*d,n) == n-1:\n return False;\n return True;\n \n knownPrimes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]\n if n in knownPrimes:\n return True;\n if any((n % p) == 0 for p in knownPrimes) or n in (0,1):\n return False;\n d,s=n-1,0\n while not d%2:\n d,s=d>>1,s+1\n return not any(compositeTry(a,d,n,s) for a in (2,3,5,7))\n\ndef main():\n n=int(input())\n if isPrime(n):\n print((1));\n elif n%2==0:\n print(2)\n elif isPrime(n-2):\n print(2)\n else:\n print(3)\n\nmain()\n", "passed": true, "time": 1.71, "memory": 14592.0, "status": "done"}, {"code": "def prime(x):\n p=int(n**.5)\n p+=2\n for i in range(3,p,2):\n if x%i==0:\n return False\n return True\n\ndef func(n):\n if n%2==0:\n if n==2:\n return 1\n return 2\n\n if n==1 or n==3 or n==5:\n return 1\n \n if prime(n):\n return 1\n if prime(n-2):\n return 2\n return 3\n\nn=int(input())\nans=func(n)\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14544.0, "status": "done"}, {"code": "from math import sqrt\nlimit = 2*1000000000\nprimes = [True for i in range(int(sqrt(limit))+1)]\ntes = int(sqrt(sqrt(limit)))+1\nfor i in range(2,tes):\n\tif primes[i]:\n\t\tfor z in range(i*i,int(sqrt(2*1000000000))+1,i):\n\t\t\tprimes[z] = False\ndef ptest(n):\n\tnonlocal primes\n\tfor i in range(2,int(sqrt(n))+1):\n\t\tif primes[i]:\n\t\t\tif n%i == 0:\n\t\t\t\treturn 0\n\treturn 1\ni = int(input().strip())\nif i%2 == 0:\n\tif i == 2:\n\t\tprint(1)\n\telse:\n\t\tprint(2)\nelse:\n\tif ptest(i):\n\t\tprint(1)\n\telif ptest(i-2):\n\t\tprint(2)\n\telse:\n\t\tprint(3)\n", "passed": true, "time": 0.47, "memory": 14684.0, "status": "done"}, {"code": "from math import sqrt, floor\nn = int(input())\n\n\ndef prime(n):\n q = floor(sqrt(n))\n prime = True\n for i in range(2, q + 1):\n if n % i == 0:\n prime = False\n return prime\n\n\nif prime(n):\n print(1)\nelse:\n if n % 2 == 0:\n print(2)\n else:\n if prime(n-2):\n print(2)\n else:\n print(3)\n\n\n", "passed": true, "time": 0.21, "memory": 14448.0, "status": "done"}, {"code": "def main():\n from math import sqrt\n n = int(input())\n if not n & 1:\n print(2 if n > 2 else 1)\n return\n for p in range(3, int(sqrt(n)) + 1, 2):\n if not n % p:\n break\n else:\n print(1)\n return\n n -= 2\n for p in range(3, int(sqrt(n)) + 1, 2):\n if not n % p:\n break\n else:\n print(2)\n return\n print(3)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.84, "memory": 14508.0, "status": "done"}, {"code": "# from math import ceil,floor\n# def matches(n,left):\n# \tpass\n# n = int(input())\n# if n%2 == 0:\n# \tprint(1+matches(n//2,0))\n# else:\n# \tprint(1+matches(ceil(n/2),1))\t\n# print(ans)\t\nprimes = [2,3]\nx = 3\nwhile x < 200000:\n\tx += 2\n\tfor i in primes:\n\t\tif i*i > x:\n\t\t\tprimes.append(x)\n\t\t\tbreak\n\t\telif x%i == 0:\n\t\t\tbreak\ndef is_prime(n):\n\tfor i in primes:\n\t\tif i*i > n:\n\t\t\treturn True\n\t\tif n%i == 0:\n\t\t\treturn False\nd = {}\ndef result(n):\n\tif is_prime(n):\n\t\treturn 1\n\telse:\n\t\ttry:\n\t\t\treturn d[n]\n\t\texcept:\t\n\t\t\ta = []\n\t\t\tcount = 0\n\t\t\tfor i in range(n-2,0,-1):\n\t\t\t\tif is_prime(i):\n\t\t\t\t\tcount += 1\n\t\t\t\t\ta.append(i)\n\t\t\t\tif count > 100:\n\t\t\t\t\tbreak\n\t\t\ta = [result(n-i) for i in a]\n\t\t\tans = 1+min(a)\n\t\t\td[n] = ans\n\t\t\treturn ans\t\t\t\t\t\t\t\nn = int(input())\nprint(result(n))\t\t\n", "passed": true, "time": 14.38, "memory": 63492.0, "status": "done"}, {"code": "def is_prime(n):\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\n\n\nn = int(input())\nif n < 4:\n print(1)\nelif n % 2 == 0:\n print(2)\nelif is_prime(n):\n print(1)\nelse:\n if is_prime(n - 2):\n print(2)\n else:\n print(3)", "passed": true, "time": 0.16, "memory": 14516.0, "status": "done"}, {"code": "import math\n\n\n# get line input split by space\ndef getLnInput():\n return input().split()\n\n\n# ceil(a / b) for a > b\ndef ceilDivision(a, b):\n return (a - 1) // b + 1\n\n\ndef isPrime(n):\n if n < 1:\n return False\n if n == 2:\n return True\n flg = True\n for i in range(2, math.ceil(math.sqrt(n + 1))):\n if n % i == 0:\n flg = False\n break\n return flg\n\n\ndef main():\n n = int(getLnInput()[0])\n if n < 4:\n print(1)\n elif isPrime(n):\n print(1)\n elif n % 2 == 0:\n print(2)\n else:\n if isPrime(n - 2):\n print(2)\n else:\n print(3)\n return\n\n\nmain()\n", "passed": true, "time": 0.38, "memory": 14512.0, "status": "done"}, {"code": "import math\ndef tax(n):\n if n==2:\n return 1\n if n%2==0:\n return 2\n elif premier(n):\n return 1\n elif premier(n-2):\n return 2\n else:\n return 3\ndef premier(k):\n if k < 2:\n return False\n else:\n for i in range(2, int(math.sqrt(k))+1):\n if k%i == 0:\n return False\n return True\n\nprint(tax(int(input())))\n", "passed": true, "time": 0.16, "memory": 14380.0, "status": "done"}, {"code": "def isPrime(n):\n if n == 2 or n == 3: return True\n if n < 2 or n%2 == 0: return False\n if n < 9: return True\n if n%3 == 0: return False\n r = int(n**0.5)\n f = 5\n while f <= r:\n if n%f == 0: return False\n if n%(f+2) == 0: return False\n f +=6\n return True\n\nn = int(input())\nif n==2:\n print(1)\nelif n % 2 == 0:\n print(2)\nelse:\n if isPrime(n):\n print(1)\n elif isPrime(n-2):\n print(2)\n else:\n print(3)", "passed": true, "time": 0.25, "memory": 14388.0, "status": "done"}, {"code": "def prime(x):\n\ti = 2\n\twhile i * i <= x:\n\t\tif x % i == 0:\n\t\t\treturn False\n\t\ti += 1\n\treturn True\nn = int(input())\nif prime(n): print(1)\nelif n % 2 == 0 or prime(n - 2): print(2)\nelse: print(3)", "passed": true, "time": 0.31, "memory": 14356.0, "status": "done"}, {"code": "import sys\nx = int(input())\n\nimport math\ndef is_prime(n):\n if n % 2 == 0 and n > 2: \n return False\n for i in range(3, int(math.sqrt(n)) + 1, 2):\n if n % i == 0:\n return False\n return True\n\nif (x == 2):\n print(1)\n return\n\nif (x == 4 or x == 6):\n print(2)\n return\n\nif (x % 2 == 0):\n print(2)\t\n return\n\nelse:\n if (is_prime(x)):\n print(1)\n return\n else:\n if (is_prime(x -2)):\n print(2)\n return\n else:\n print(3)\n return\n", "passed": true, "time": 0.16, "memory": 14684.0, "status": "done"}, {"code": "def prime(x):\n y = min(x, int(x ** 0.5) + 2)\n for d in range(2, y):\n if x % d == 0:\n return False\n return True\n\ndef solve(n):\n if prime(n): return 1\n if n % 2 and prime(n - 2): return 2\n return 2 + n % 2\n\nn = int(input())\nprint(solve(n))\n", "passed": true, "time": 0.16, "memory": 14420.0, "status": "done"}, {"code": "def is_prime(n):\n i = 2\n while i * i <= n:\n if n % i == 0:\n return False\n i += 1\n return True\n\ndef max_p(n):\n if not is_prime(n):\n i = n - 2\n while (i > 0):\n if is_prime(i):\n return i\n i -= 1\n else:\n return n\n \nn = int(input())\n\nif n == 2:\n ans = 1\n \nelif n % 2 == 0:\n ans = 2\nelse:\n ans = 1\n while not is_prime(n):\n #print(max_p(n))\n if n % 2:\n n = n - max_p(n)\n #print(n)\n ans += 1\n else:\n ans += 1\n break\n\nprint(ans)", "passed": true, "time": 0.23, "memory": 14448.0, "status": "done"}, {"code": "def check(n):\n if n==2:\n return 1\n elif n>2:\n k=int(n**0.5)+1\n b=0\n for j in range(2,k+1):\n if n%j==0:\n return 0\n else:\n continue\n return 1\nn=int(input())\nif n==2:\n print(1)\nelse:\n if n%2==0:\n print(2)\n else:\n i=0\n ans=0\n while n>2 and n-i>=2:\n if check(n-i)==1 and i!=1:\n n=i\n ans+=1\n i=0\n else:\n i+=1\n print(min(ans+n//2,3))", "passed": true, "time": 0.34, "memory": 14512.0, "status": "done"}] | [{"input": "4\n", "output": "2\n"}, {"input": "27\n", "output": "3\n"}, {"input": "3\n", "output": "1\n"}, {"input": "5\n", "output": "1\n"}, {"input": "10\n", "output": "2\n"}, {"input": "2000000000\n", "output": "2\n"}, {"input": "26\n", "output": "2\n"}, {"input": "7\n", "output": "1\n"}, {"input": "2\n", "output": "1\n"}, {"input": "11\n", "output": "1\n"}, {"input": "1000000007\n", "output": "1\n"}, {"input": "1000000009\n", "output": "1\n"}, {"input": "1999999999\n", "output": "3\n"}, {"input": "1000000011\n", "output": "2\n"}, {"input": "101\n", "output": "1\n"}, {"input": "103\n", "output": "1\n"}, {"input": "1001\n", "output": "3\n"}, {"input": "1003\n", "output": "3\n"}, {"input": "10001\n", "output": "3\n"}, {"input": "10003\n", "output": "3\n"}, {"input": "129401294\n", "output": "2\n"}, {"input": "234911024\n", "output": "2\n"}, {"input": "192483501\n", "output": "3\n"}, {"input": "1234567890\n", "output": "2\n"}, {"input": "719241201\n", "output": "3\n"}, {"input": "9\n", "output": "2\n"}, {"input": "33\n", "output": "2\n"}, {"input": "25\n", "output": "2\n"}, {"input": "15\n", "output": "2\n"}, {"input": "147\n", "output": "3\n"}, {"input": "60119912\n", "output": "2\n"}, {"input": "45\n", "output": "2\n"}, {"input": "21\n", "output": "2\n"}, {"input": "9975\n", "output": "2\n"}, {"input": "17\n", "output": "1\n"}, {"input": "99\n", "output": "2\n"}, {"input": "49\n", "output": "2\n"}, {"input": "243\n", "output": "2\n"}, {"input": "43\n", "output": "1\n"}, {"input": "39\n", "output": "2\n"}, {"input": "6\n", "output": "2\n"}, {"input": "8\n", "output": "2\n"}, {"input": "12\n", "output": "2\n"}, {"input": "13\n", "output": "1\n"}, {"input": "14\n", "output": "2\n"}, {"input": "16\n", "output": "2\n"}, {"input": "18\n", "output": "2\n"}, {"input": "19\n", "output": "1\n"}, {"input": "20\n", "output": "2\n"}, {"input": "22\n", "output": "2\n"}, {"input": "23\n", "output": "1\n"}, {"input": "24\n", "output": "2\n"}, {"input": "962\n", "output": "2\n"}, {"input": "29\n", "output": "1\n"}, {"input": "55\n", "output": "2\n"}, {"input": "125\n", "output": "3\n"}, {"input": "1999999929\n", "output": "2\n"}, {"input": "493\n", "output": "2\n"}, {"input": "10000021\n", "output": "2\n"}, {"input": "541\n", "output": "1\n"}, {"input": "187\n", "output": "3\n"}, {"input": "95\n", "output": "3\n"}, {"input": "999991817\n", "output": "3\n"}, {"input": "37998938\n", "output": "2\n"}, {"input": "1847133842\n", "output": "2\n"}, {"input": "1000000005\n", "output": "3\n"}, {"input": "19828\n", "output": "2\n"}, {"input": "998321704\n", "output": "2\n"}, {"input": "370359\n", "output": "3\n"}, {"input": "115\n", "output": "2\n"}, {"input": "200000015\n", "output": "3\n"}, {"input": "479001600\n", "output": "2\n"}, {"input": "536870912\n", "output": "2\n"}, {"input": "10759922\n", "output": "2\n"}, {"input": "1999999927\n", "output": "1\n"}, {"input": "123\n", "output": "3\n"}, {"input": "200743933\n", "output": "3\n"}, {"input": "949575615\n", "output": "3\n"}, {"input": "99990001\n", "output": "1\n"}, {"input": "715827883\n", "output": "1\n"}, {"input": "5592406\n", "output": "2\n"}, {"input": "8388609\n", "output": "3\n"}, {"input": "1908903481\n", "output": "3\n"}, {"input": "1076153021\n", "output": "3\n"}, {"input": "344472101\n", "output": "3\n"}] |
|
152 | Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare n potions.
Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two types that can faster the process of preparing potions. Spells of this type speed up the preparation time of one potion. There are m spells of this type, the i-th of them costs b_{i} manapoints and changes the preparation time of each potion to a_{i} instead of x. Spells of this type immediately prepare some number of potions. There are k such spells, the i-th of them costs d_{i} manapoints and instantly create c_{i} potions.
Anton can use no more than one spell of the first type and no more than one spell of the second type, and the total number of manapoints spent should not exceed s. Consider that all spells are used instantly and right before Anton starts to prepare potions.
Anton wants to get to the next level as fast as possible, so he is interested in the minimum number of time he needs to spent in order to prepare at least n potions.
-----Input-----
The first line of the input contains three integers n, m, k (1 ≤ n ≤ 2·10^9, 1 ≤ m, k ≤ 2·10^5) — the number of potions, Anton has to make, the number of spells of the first type and the number of spells of the second type.
The second line of the input contains two integers x and s (2 ≤ x ≤ 2·10^9, 1 ≤ s ≤ 2·10^9) — the initial number of seconds required to prepare one potion and the number of manapoints Anton can use.
The third line contains m integers a_{i} (1 ≤ a_{i} < x) — the number of seconds it will take to prepare one potion if the i-th spell of the first type is used.
The fourth line contains m integers b_{i} (1 ≤ b_{i} ≤ 2·10^9) — the number of manapoints to use the i-th spell of the first type.
There are k integers c_{i} (1 ≤ c_{i} ≤ n) in the fifth line — the number of potions that will be immediately created if the i-th spell of the second type is used. It's guaranteed that c_{i} are not decreasing, i.e. c_{i} ≤ c_{j} if i < j.
The sixth line contains k integers d_{i} (1 ≤ d_{i} ≤ 2·10^9) — the number of manapoints required to use the i-th spell of the second type. It's guaranteed that d_{i} are not decreasing, i.e. d_{i} ≤ d_{j} if i < j.
-----Output-----
Print one integer — the minimum time one has to spent in order to prepare n potions.
-----Examples-----
Input
20 3 2
10 99
2 4 3
20 10 40
4 15
10 80
Output
20
Input
20 3 2
10 99
2 4 3
200 100 400
4 15
100 800
Output
200
-----Note-----
In the first sample, the optimum answer is to use the second spell of the first type that costs 10 manapoints. Thus, the preparation time of each potion changes to 4 seconds. Also, Anton should use the second spell of the second type to instantly prepare 15 potions spending 80 manapoints. The total number of manapoints used is 10 + 80 = 90, and the preparation time is 4·5 = 20 seconds (15 potions were prepared instantly, and the remaining 5 will take 4 seconds each).
In the second sample, Anton can't use any of the spells, so he just prepares 20 potions, spending 10 seconds on each of them and the answer is 20·10 = 200. | interview | [{"code": "n, m, k = list(map(int, input().split()))\nx, s = list(map(int, input().split()))\nt = list(map(int, input().split()))\npr = list(map(int, input().split()))\nt2 = list(map(int, input().split()))\npr2 = list(map(int, input().split()))\nmass1 = []\nminans = 10**20\nfor i in range(m):\n mass1.append((pr[i], t[i]))\nmass1.sort()\nmass1 = [(0, x)] + mass1\npr2 = [0] + pr2\nt2 = [0] + t2\nuk1 = len(mass1) - 1\nuk2 = 0\nmaxw = 0\nfor uk1 in range(len(mass1) - 1, -1, -1):\n if (s < mass1[uk1][0]):\n continue\n while (uk2 < len(pr2) and mass1[uk1][0] + pr2[uk2] <= s):\n maxw = max(maxw, t2[uk2])\n uk2 += 1\n uk2 -= 1\n minans = min(minans, (n - maxw) * mass1[uk1][1])\nprint(minans)\n", "passed": true, "time": 0.15, "memory": 14704.0, "status": "done"}, {"code": "def main():\n read = lambda: list(map(int, input().split()))\n n, m, k = read()\n x, s = read()\n a = list(read())\n b = list(read())\n c = list(read())\n d = list(read())\n ans = n * x\n if min(b) <= s:\n Min2 = min(a[i] for i in range(m) if b[i] <= s)\n ans = min(ans, n * Min2)\n b = sorted([(b[i], i) for i in range(m)])\n j = 0\n Min = x\n for i in range(k - 1, -1, -1):\n while j < m and b[j][0] + d[i] <= s:\n Min = min(Min, a[b[j][1]])\n j += 1\n if d[i] > s: continue\n cur = (n - c[i]) * Min\n ans = min(ans, cur)\n print(ans)\nmain()\n", "passed": true, "time": 0.15, "memory": 14548.0, "status": "done"}, {"code": "import bisect\n\nn, m, k = map(int, input().split())\nx, s = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = list(map(int, input().split()))\nd = list(map(int, input().split()))\n\nz1 = list(zip(a, b))\nz2 = list(zip(c, d))\n\nresult = n * x\n\nfor ai, bi in z1:\n if bi > s:\n continue\n\n current = ai * n\n if current < result:\n result = current\n\n rest = s - bi\n idx = bisect.bisect_right(d, rest)\n if idx == 0:\n continue\n current = ai * (n - z2[idx-1][0])\n if current < result:\n result = current\n\nfor ci, di in z2:\n if di > s:\n continue\n current = x * (n - ci)\n if current < result:\n result = current\n\nprint(result)", "passed": true, "time": 1.09, "memory": 14596.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\nx, s = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = list(map(int, input().split()))\nd = list(map(int, input().split()))\na.append(x)\nb.append(0)\nans = x * n\nfor i in range(m + 1):\n\tif b[i] <= s:\n\t\tl = -1\n\t\tr = k\n\t\twhile l < r - 1:\n\t\t\ty = l + (r - l) // 2\n\t\t\tif d[y] <= s - b[i]:\n\t\t\t\tl = y\n\t\t\telse:\n\t\t\t\tr = y\n\t\tans1 = 0\n\t\tif l > -1:\n\t\t\tans1 = a[i] * max(0, n - c[l])\n\t\telse:\n\t\t\tans1 = a[i] * n\n\t\tif ans1 < ans:\n\t\t\tans = ans1\nprint(ans)\n", "passed": true, "time": 0.24, "memory": 14432.0, "status": "done"}, {"code": "from bisect import bisect_right\n\nn, m, k = [int(x) for x in input().split()]\nx,s = [int(x) for x in input().split()]\na = [int(x) for x in input().split()]\nb = [int(x) for x in input().split()]\nc = [int(x) for x in input().split()]\nd = [int(x) for x in input().split()]\nans = n * x\nfor i in range(m):\n if b[i] <= s:\n cur_s = s - b[i]\n j = bisect_right(d, cur_s) - 1\n if j != -1:\n if (n-c[j])*a[i] < ans:\n ans = (n-c[j])*a[i]\n else:\n if (n)*a[i] < ans:\n ans = (n)*a[i]\n\nfor i in range(k):\n if d[i] <= s:\n if (n - c[i]) * x < ans:\n ans = (n - c[i]) * x\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14652.0, "status": "done"}, {"code": "def main():\n from bisect import bisect\n n, m, k = list(map(int, input().split()))\n t, s = list(map(int, input().split())) # time per stuff,mana\n aa = list(map(int, input().split())) # x->t[i] for stuff\n aa.append(t)\n bb = list(map(int, input().split())) # price of t[i]\n bb.append(0)\n cc = [0, *list(map(int, input().split())), 0] # num of instant\n dd = [0, *list(map(int, input().split())), s + 1] # price of instant\n res = []\n for t, b in zip(aa, bb):\n b = s - b\n if b >= 0:\n i = bisect(dd, b)\n if b < dd[i]:\n i -= 1\n x = n - cc[i]\n if x <= 0:\n res = [0]\n break\n res.append(x * t)\n print(min(res))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14572.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\nx, s = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = list(map(int, input().split()))\nd = list(map(int, input().split()))\n\nans = n * x\nfor i in range(m):\n l = 0\n r = k\n while (r - l > 1):\n mid = l + (r - l) // 2\n if (d[mid] <= s - b[i]):\n l = mid\n else:\n r = mid\n if (d[l] <= s - b[i]):\n t = a[i] * (n - c[l])\n ans = min(ans, t)\nfor i in range(k):\n if (d[i] <= s):\n ans = min(ans, x * (n - c[i]))\nfor i in range(m):\n if (b[i] <= s):\n ans = min(ans, a[i] * n)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14604.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\nx, s = map(int, input().split())\nres = n * x\nft = [[0] * 2 for i in range(m)]\nst = [[0] * 2 for i in range(k)]\ntmparr = list(map(int, input().split()))\nfor i in range(m):\n ft[i][0] = tmparr[i]\ntmparr = list(map(int, input().split()))\nfor i in range(m):\n ft[i][1] = tmparr[i]\ntmparr = list(map(int, input().split()))\nfor i in range(k):\n st[i][0] = tmparr[i]\ntmparr = list(map(int, input().split()))\nfor i in range(k):\n st[i][1] = tmparr[i]\nfor i in range(m):\n nows = s - ft[i][1]\n if (nows < 0):\n continue\n nowr = n * ft[i][0]\n if (nows >= st[0][1]):\n l = 0\n r = k\n while r - l > 1:\n m = (l + r) // 2\n if (st[m][1] <= nows):\n l = m\n else:\n r = m\n nowr -= ft[i][0] * st[l][0]\n res = min(res, nowr)\nfor i in range(k):\n if (st[i][1] <= s):\n res = min(res, x * (n - st[i][0]))\nprint(res)", "passed": true, "time": 0.15, "memory": 14720.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nfrom sys import stdin\nfrom bisect import bisect_right\n\n\ndef main():\n n, m, k = stdin_get_ints_from_line() # amount to brew, first cast count, second cask count 2*10^9, 2*10^5, 2*10^5\n x, s = stdin_get_ints_from_line() # time to brew, mana amount\n\n a = stdin_get_ints_list_from_line() # time to brew with ai first cast 2*10^9\n b = stdin_get_ints_list_from_line() # cost of first cast 2*10^9\n c = stdin_get_ints_list_from_line() # amount to brew instantly 2*10^9\n d = stdin_get_ints_list_from_line() # cost of second cast 2*10^9\n\n result = n * x\n\n key = bisect_right(d, s)\n\n if key != 0:\n spell2_only_result = (n - c[key-1]) * x\n if spell2_only_result < result:\n result = spell2_only_result\n\n for key, val in enumerate(b):\n if val <= s:\n if a[key] < x:\n cost_left = s - val\n amount_second = 0\n\n key2 = bisect_right(d, cost_left)\n\n if key2 != 0:\n amount_second = c[key2-1]\n\n r = (n-amount_second) * a[key]\n\n if r < result:\n result = r\n if result <= 0:\n break\n\n print(result) if result > 0 else print(0)\n\n\ndef stdin_get_ints_from_line():\n return (int(x) for x in stdin.readline().strip().split(' '))\n\n\ndef stdin_get_ints_list_from_line():\n return list(int(x) for x in stdin.readline().strip().split(' '))\n\n\ndef stdin_get_string_from_line():\n return stdin.readline().strip()\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.22, "memory": 14580.0, "status": "done"}, {"code": "import bisect\n\nn, m, k = map(int, input().split(' '))\nx, s = map(int, input().split(' '))\na = list(map(int, input().split(' ')))\nb = list(map(int, input().split(' ')))\nc = list(map(int, input().split(' ')))\nd = list(map(int, input().split(' ')))\na.append(x)\nb.append(0)\nans = n * x\nfor i in range(m+1):\n if b[i] <= s:\n j = bisect.bisect_right(d, s - b[i])\n if j > 0:\n j -= 1\n ans = min(ans, (n-c[j])*a[i])\n else:\n ans = min(ans, n*a[i])\nprint(ans)", "passed": true, "time": 0.14, "memory": 14664.0, "status": "done"}, {"code": "n,m,k = [int(i) for i in input().split()]\nx,s = [int(i) for i in input().split()]\na_t = [int(i) for i in input().split()]\na_m = [int(i) for i in input().split()]\nb_p = [int(i) for i in input().split()]\nb_m = [int(i) for i in input().split()]\n\nmin_time = n * x\n\na_t.append(x)\na_m.append(0)\n\nfor i in range(m+1):\n re_mana = s - a_m[i]\n if re_mana < 0:\n continue\n inf = -1\n sup = k\n while inf<sup-1:\n #print(inf,sup)\n mid = (inf+sup)//2\n if b_m[mid] <= re_mana:\n inf = mid\n else:\n sup = mid \n if inf<=-1:\n min_time = min(min_time,n*a_t[i])\n else:\n min_time = min(min_time,max(0,n-b_p[inf])*a_t[i])\n\n\n\nprint(min_time)\n", "passed": true, "time": 0.15, "memory": 14652.0, "status": "done"}, {"code": "n,m,k = [int(i) for i in input().split()]\nx,s = [int(i) for i in input().split()]\na_t = [int(i) for i in input().split()]\na_m = [int(i) for i in input().split()]\nb_p = [int(i) for i in input().split()]\nb_m = [int(i) for i in input().split()]\n\nmin_time = n * x\n\nfor i in range(m):\n re_mana = s - a_m[i]\n if re_mana < 0:\n continue\n inf = -1\n sup = k\n while inf<sup-1:\n #print(inf,sup)\n mid = (inf+sup)//2\n if b_m[mid] <= re_mana:\n inf = mid\n else:\n sup = mid\n if inf==-1:\n min_time = min(min_time,n*a_t[i])\n else:\n min_time = min(min_time,max(0,n-b_p[inf])*a_t[i])\n\nfor i in range(k):\n if s>=b_m[i]:\n min_time = min(min_time,max(0,(n-b_p[i]))*x)\nprint(min_time)\n", "passed": true, "time": 0.15, "memory": 14588.0, "status": "done"}, {"code": "import math\nn, m, k = list(map(int,input().split()))\nx, s = list(map(int,input().split()))\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\nc = list(map(int,input().split()))\nd = list(map(int,input().split()))\na.insert(0,x)\nb.insert(0,0)\nc.insert(0,0)\nd.insert(0,0)\nans = 1<<100\nfor it in range(m+1):\n mana = s-b[it]\n if mana<0: continue\n lo, hi = 0, k\n while lo!=hi:\n mid = math.ceil((lo+hi)/2)\n if d[mid]<=mana: lo = mid\n else: hi = mid-1\n ans = min(ans,(n-c[lo])*a[it])\nprint(ans)\n", "passed": true, "time": 0.22, "memory": 14704.0, "status": "done"}, {"code": "from sys import stdin, stdout\nn, m, k = list(map(int,stdin.readline().split()))\nx, s = list(map(int,stdin.readline().split()))\na = list(map(int,stdin.readline().split()))\nb = list(map(int,stdin.readline().split()))\nc = list(map(int,stdin.readline().split()))\nd = list(map(int,stdin.readline().split()))\na.insert(0,x)\nb.insert(0,0)\nc.insert(0,0)\nd.insert(0,0)\nans = 1<<100\nfor it in range(m+1):\n mana = s-b[it]\n if mana<0: continue\n lo, hi = 0, k\n while lo!=hi:\n mid = (lo+hi+1)//2\n if d[mid]<=mana: lo = mid\n else: hi = mid-1\n ans = min(ans,(n-c[lo])*a[it])\nstdout.write(str(ans)+'\\n')\n", "passed": true, "time": 0.14, "memory": 14492.0, "status": "done"}, {"code": "import bisect\n(n,m,k), (x,s), a, b, c, d = (list(map(int, input().split())) for _ in range(6))\na, b = list(a) + [x], list(b) + [0]\nc, d = list(map(list, (c, d)))\n\nans = n * x\nfor i in range(m + 1):\n if b[i] <= s:\n j = bisect.bisect_right(d, s - b[i])\n if j > 0:\n j -= 1\n ans = min(ans, (n - c[j]) * a[i])\n else:\n ans = min(ans, n * a[i])\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14508.0, "status": "done"}, {"code": "import bisect \n\ndef anton_and_magic_potions():\n\n\tno_potions, no_fst_spell, no_snd_spell = [int(x) for x in input().split(' ')]\n\tinitial_time, mana = [int(x) for x in input().split(' ')]\n\tfirst_spell = [int(x) for x in input().split(' ')]\n\tmana_first_spell = [int(x) for x in input().split(' ')]\n\tpotions_second_spell = [int(x) for x in input().split(' ')]\n\tmana_second_spell = [int(x) for x in input().split(' ')]\n\n\tfirst_spell.append(initial_time)\n\tmana_first_spell.append(0)\n\n\ttotal_time = no_potions * initial_time\n\n\tfor i in range(no_fst_spell + 1):\n\n\t\tif mana_first_spell[i] > mana:\n\t\t\tcontinue\n\n\t\tpos2 = bisect.bisect_right(mana_second_spell, mana -mana_first_spell[i]) - 1\n\t\tif pos2 >=0:\n\t\t\tno_potions2 = no_potions - potions_second_spell[pos2]\n\t\t\tres = no_potions2 * first_spell[i]\n\t\telse:\n\t\t\tres = no_potions * first_spell[i]\n\t\ttotal_time = min(total_time, res)\n\n\n\tprint(total_time)\n\nanton_and_magic_potions()", "passed": true, "time": 0.14, "memory": 14412.0, "status": "done"}, {"code": "n,m,k = list(map(int,input().split()))\nx,s = list(map(int,input().split()))\nk += 1 \nm += 1\na = [x] + [int(x) for x in input().split()]\nb = [0] + [int(x) for x in input().split()]\nc = [0] + [int(x) for x in input().split()]\nd = [0] + [int(x) for x in input().split()]\nfir = []\nfor i in range(m): \n\tfir.append([a[i],b[i]])\nfir.sort(key = lambda x : x[1])\nans = n * x\nfor i in range(m):\n\tleft = s - fir[i][1]\n\tif (left < 0) : break\n\twhile(d[k-1] > left) : k -= 1\n\tnow = (n - c[k-1]) * fir[i][0]\n\tans = min(ans,now)\nprint(ans)\n\n", "passed": true, "time": 0.23, "memory": 14436.0, "status": "done"}, {"code": "n,m,k = list(map(int,input().split()))\nx,s = list(map(int,input().split()))\na_time = list(map(int,input().split()))\na_cost = list(map(int,input().split()))\nb_num = list(map(int,input().split()))\nb_cost = list(map(int,input().split()))\n\ndef binary_search(manapoints):\n nonlocal k,b_cost\n l = 0; r = k-1; pos = -1\n while (l <= r):\n mid = int((l+r)/2)\n if (b_cost[mid] <= manapoints):\n l = mid+1; pos = mid;\n else :\n r = mid-1\n return pos\nres = n*x\npos = binary_search(s)\nif (pos >= 0): res = min(res,(n-b_num[pos])*x);\nfor i in range(m):\n if (a_cost[i] > s): continue;\n rest = s-a_cost[i]\n pos = binary_search(rest)\n if (pos >= 0): res = min(res,(n-b_num[pos])*a_time[i])\n else : res = min(res,n*a_time[i])\nprint(res)", "passed": true, "time": 0.15, "memory": 14456.0, "status": "done"}, {"code": "n,m,k = map(int, input().split())\nx,s = map(int, input().split())\n\na = [x] + list(map(int, input().split()))\nb = [0] + list(map(int, input().split()))\nc = [0] + list(map(int, input().split()))\nd = [0] + list(map(int, input().split()))\n\nab = list(zip(a,b))\nab.sort(key=lambda x:-x[1])\n\nans = x*n\nind = 0\n\nfor ai,bi in ab:\n while ind<k+1 and d[ind]<=(s-bi): ind+=1\n if ind==0: continue\n tmp = (n-c[ind-1])*ai\n ans = min(ans, tmp)\n\nprint(ans)", "passed": true, "time": 0.14, "memory": 14624.0, "status": "done"}, {"code": "n,m,k = map(int, input().split())\nx,s = map(int, input().split())\n\na = [x] + list(map(int, input().split()))\nb = [0] + list(map(int, input().split()))\nc = [0] + list(map(int, input().split()))\nd = [0] + list(map(int, input().split()))\n\nab = list(zip(a,b))\nab.sort(key=lambda x:-x[1])\n\nans = x*n\nind = 0\n\nfor ai,bi in ab:\n while ind<k+1 and d[ind]<=(s-bi): ind+=1\n if ind==0: continue\n ans = min(ans, (n-c[ind-1])*ai)\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14568.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\nx, s = map(int, input().split())\nA = [x] + list(map(int, input().split()))\nB = [0] + list(map(int, input().split()))\nC = [0] + list(map(int, input().split()))\nD = [0] + list(map(int, input().split()))\nQW = list(zip(A, B))\nQW.sort(key = lambda x : x[1])\nA = [s[0] for s in QW]\nB = [s[1] for s in QW]\n\nRes = x * n\n\nfor i in range(1, k + 1):\n C[i] = max(C[i], C[i - 1])\nl = k\ne = 10**19\n\nfor i in range(m + 1):\n e = min(e, A[i])\n while l >= 0 and B[i] + D[l] > s:\n l -= 1\n if l >= 0:\n Res = min(Res, max(n - C[l], 0) * A[i])\n \n\n\nprint(Res)", "passed": true, "time": 0.14, "memory": 14528.0, "status": "done"}, {"code": "n,m,k = (int(x) for x in input().split())\norig,s = (int(x) for x in input().split())\ntime1 = [orig] + [int(x) for x in input().split()]\ncost1 = [0] + [int(x) for x in input().split()]\nmake2 = [0] + [int(x) for x in input().split()]\ncost2 = [0] + [int(x) for x in input().split()]\n\nordcost1 = [ (x,i) for i,x in enumerate(cost1) ]\nordcost1.sort()\ncount = k\nbest = orig*n\n\nfor i in range(m+1):\n\tcost,ind = ordcost1[i]\n\twhile count > -1 and cost2[count] + cost > s:\n\t\tcount -= 1\n\tif count > -1 and time1[ind] * (n - make2[count]) < best:\n\t\tbest = time1[ind] * (n - make2[count])\n\nprint(best)", "passed": true, "time": 0.14, "memory": 14612.0, "status": "done"}, {"code": "class First:\n def __init__(self, seconds, cost):\n self.seconds = seconds\n self.cost = cost\nclass Second:\n def __init__(self, numCreated, cost):\n self.numCreated = numCreated\n self.cost = cost\n\ndef solve():\n potionCount, firstCount, secondCount = map(int, input().split())\n secondsOne, manaPoints = map(int, input().split())\n first = list()\n a, b = list(map(int, input().split())), list(map(int, input().split()))\n for i in range(firstCount):\n first.append(First(a[i], b[i]))\n first.append(First(secondsOne, 0))\n second = [Second(0, 0)]\n a, b = list(map(int, input().split())), list(map(int, input().split()))\n for i in range(secondCount):\n second.append(Second(a[i], b[i]))\n res = int(1e20)\n for f in first:\n low = 0\n high = len(second) - 1\n while low < high:\n mid = (low + high + 1) // 2\n if f.cost + second[mid].cost > manaPoints:\n high = mid - 1\n else:\n low = mid\n if f.cost + second[low].cost <= manaPoints:\n moar = max(0, potionCount - second[low].numCreated)\n time = moar * f.seconds\n res = min(res, time)\n print(res)\nsolve()", "passed": true, "time": 0.14, "memory": 14444.0, "status": "done"}, {"code": "class First:\n def __init__(self, seconds, cost):\n self.seconds = seconds\n self.cost = cost\nclass Second:\n def __init__(self, numCreated, cost):\n self.numCreated = numCreated\n self.cost = cost\n\ndef solve():\n potionCount, firstCount, secondCount = map(int, input().split())\n secondsOne, manaPoints = map(int, input().split())\n first = list()\n a, b = list(map(int, input().split())), list(map(int, input().split()))\n for i in range(firstCount):\n first.append(First(a[i], b[i]))\n first.append(First(secondsOne, 0))\n second = [Second(0, 0)]\n a, b = list(map(int, input().split())), list(map(int, input().split()))\n for i in range(secondCount):\n second.append(Second(a[i], b[i]))\n res = int(1e20)\n for f in first:\n low = 0\n high = len(second) - 1\n while low < high:\n mid = (low + high + 1) // 2\n if f.cost + second[mid].cost > manaPoints:\n high = mid - 1\n else:\n low = mid\n if f.cost + second[low].cost <= manaPoints:\n moar = max(0, potionCount - second[low].numCreated)\n time = moar * f.seconds\n res = min(res, time)\n print(res)\nsolve()", "passed": true, "time": 0.15, "memory": 14688.0, "status": "done"}] | [{"input": "20 3 2\n10 99\n2 4 3\n20 10 40\n4 15\n10 80\n", "output": "20\n"}, {"input": "20 3 2\n10 99\n2 4 3\n200 100 400\n4 15\n100 800\n", "output": "200\n"}, {"input": "10 3 3\n10 33\n1 7 6\n17 25 68\n2 9 10\n78 89 125\n", "output": "10\n"}, {"input": "94 1 1\n26 324\n7\n236\n77\n5\n", "output": "119\n"}, {"input": "3 4 5\n5 9\n1 2 1 1\n3 5 4 1\n1 1 1 1 3\n1 2 3 4 5\n", "output": "0\n"}, {"input": "1 4 2\n3 10\n2 1 1 1\n1 5 3 5\n1 1\n1 5\n", "output": "0\n"}, {"input": "5 3 3\n4 4\n2 3 1\n1 3 1\n1 2 2\n2 2 5\n", "output": "3\n"}, {"input": "4 3 2\n2 7\n1 1 1\n2 4 1\n1 4\n1 5\n", "output": "0\n"}, {"input": "2000000000 1 1\n2000000000 1999999999\n1\n2000000000\n1\n2000000000\n", "output": "4000000000000000000\n"}, {"input": "3 1 1\n2 1\n1\n1\n1\n1\n", "output": "3\n"}, {"input": "379 5 8\n758 10000\n512 512 512 512 512\n500 500 500 500 500\n123 123 123 123 123 123 123 123\n500 500 500 500 500 500 500 500\n", "output": "131072\n"}, {"input": "256 22 22\n45 42\n21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42\n21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42\n21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42\n21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42\n", "output": "4935\n"}, {"input": "20 3 2\n1000 99\n1 2 3\n100 200 300\n1 2\n3 4\n", "output": "18000\n"}, {"input": "20 3 2\n10 99\n2 4 3\n200 100 400\n4 15\n10 80\n", "output": "50\n"}, {"input": "2000000000 1 1\n2000000000 1\n1\n100\n1\n100\n", "output": "4000000000000000000\n"}, {"input": "100 1 1\n100 1\n1\n1000\n100\n1\n", "output": "0\n"}, {"input": "100 1 1\n100 1\n1\n1000\n99\n1\n", "output": "100\n"}, {"input": "2 1 1\n10 10\n2\n11\n1\n2\n", "output": "10\n"}, {"input": "2000000000 3 2\n1000000000 99\n2 4 3\n100 100 100\n4 15\n100 100\n", "output": "2000000000000000000\n"}, {"input": "2000000000 1 1\n2000000000 1\n2\n2\n2\n2\n", "output": "4000000000000000000\n"}, {"input": "2000000000 2 2\n2000000000 1\n1 2\n100 100\n1 2\n100 100\n", "output": "4000000000000000000\n"}, {"input": "2000000000 1 1\n2000000000 1\n1\n2\n1\n2\n", "output": "4000000000000000000\n"}, {"input": "2000000000 3 2\n10 1\n2 4 3\n200 100 400\n4 15\n100 800\n", "output": "20000000000\n"}, {"input": "1000 1 1\n10 10\n1\n1000\n500\n10\n", "output": "5000\n"}, {"input": "4 2 2\n4 3\n1 1\n8 8\n1 1\n1 1\n", "output": "12\n"}, {"input": "20 3 2\n10 99\n2 4 3\n200 100 400\n20 20\n1 1\n", "output": "0\n"}, {"input": "2000 1 1\n2000 1\n2\n2\n1\n1\n", "output": "3998000\n"}, {"input": "20 3 2\n10 99\n2 4 3\n20 20 40\n4 20\n10 80\n", "output": "0\n"}, {"input": "10 1 1\n10 50\n1\n50\n1\n50\n", "output": "10\n"}, {"input": "2000000000 3 2\n1000000000 99\n2 4 3\n200 100 400\n4 15\n100 100\n", "output": "2000000000000000000\n"}, {"input": "10 1 1\n10 10\n9\n100\n10\n10\n", "output": "0\n"}, {"input": "50 1 1\n3 10\n2\n100\n50\n10\n", "output": "0\n"}, {"input": "20 1 1\n10 99\n1\n100\n4\n10\n", "output": "160\n"}, {"input": "2000000000 3 2\n1000000000 99\n2 4 3\n200 100 400\n4 15\n100 800\n", "output": "2000000000000000000\n"}, {"input": "100 1 1\n100 2\n1\n2\n1\n2\n", "output": "100\n"}, {"input": "10 1 1\n10 50\n1\n51\n10\n50\n", "output": "0\n"}, {"input": "20 3 2\n10 10\n2 4 3\n10 90 90\n1 2\n999 1000\n", "output": "40\n"}, {"input": "5 1 1\n5 10\n3\n10\n5\n10\n", "output": "0\n"}, {"input": "20 1 1\n100 1\n2\n2\n20\n1\n", "output": "0\n"}, {"input": "100 1 1\n200 10\n10\n11\n100\n1\n", "output": "0\n"}, {"input": "20 3 2\n10 99\n2 4 3\n200 100 400\n4 15\n1 8\n", "output": "50\n"}, {"input": "20 3 1\n5 40\n2 3 4\n40 40 40\n20\n40\n", "output": "0\n"}, {"input": "10 1 1\n10 50\n1\n51\n9\n50\n", "output": "10\n"}, {"input": "2000000000 1 1\n2000000000 1\n1\n5\n1\n5\n", "output": "4000000000000000000\n"}, {"input": "100 1 1\n1000 5\n1\n6\n100\n4\n", "output": "0\n"}, {"input": "1000000000 1 1\n1000000000 1\n1\n10000\n1\n10000\n", "output": "1000000000000000000\n"}, {"input": "2000000000 1 1\n2000000000 1\n1\n10\n2\n10\n", "output": "4000000000000000000\n"}, {"input": "20 1 1\n10 100\n5\n200\n10\n1\n", "output": "100\n"}, {"input": "2000000000 1 1\n2000000000 1\n1999999999\n1\n1\n1\n", "output": "3999999998000000000\n"}, {"input": "20 3 2\n10 10\n2 4 3\n10 10 10\n20 20\n999 999\n", "output": "40\n"}, {"input": "20 2 2\n10 100\n1 1\n1000 2000\n4 15\n100 800\n", "output": "160\n"}, {"input": "2 1 1\n5 5\n2\n10\n2\n1\n", "output": "0\n"}, {"input": "20 3 2\n10 2\n1 1 1\n3 4 5\n1 2\n1 3\n", "output": "190\n"}, {"input": "20 3 1\n10 10\n9 9 9\n10 10 10\n20\n10\n", "output": "0\n"}, {"input": "1000000000 3 2\n1000000000 1\n2 4 3\n20 10 40\n4 15\n10 80\n", "output": "1000000000000000000\n"}, {"input": "10 1 1\n10 10\n1\n20\n5\n9\n", "output": "50\n"}, {"input": "1 1 1\n1000 1000\n1\n1000\n1\n1\n", "output": "0\n"}, {"input": "1000000000 1 1\n1000000000 1\n1\n10000\n1000000000\n1\n", "output": "0\n"}, {"input": "20 1 1\n10 10\n4\n100\n20\n10\n", "output": "0\n"}, {"input": "100 1 1\n100 10000\n99\n10001\n100\n10000\n", "output": "0\n"}, {"input": "20 1 1\n10 100\n5\n200\n10\n100\n", "output": "100\n"}, {"input": "52 2 3\n50 101\n15 13\n10 20\n20 50 51\n20 100 200\n", "output": "100\n"}, {"input": "2000000000 1 1\n2000000000 10\n5\n15\n5\n15\n", "output": "4000000000000000000\n"}, {"input": "20 3 2\n10 99\n2 4 3\n99 100 400\n4 15\n100 800\n", "output": "40\n"}, {"input": "1 1 1\n1000 1\n1\n1000\n1\n1\n", "output": "0\n"}, {"input": "100000000 1 1\n100000000 1\n10\n10\n10\n10\n", "output": "10000000000000000\n"}, {"input": "1000000000 3 2\n1000000000 99\n2 4 3\n20 10 40\n4 15\n10 80\n", "output": "1999999992\n"}, {"input": "100 1 1\n1000 5\n1\n6\n95\n4\n", "output": "5000\n"}, {"input": "1 1 1\n2 1\n1\n10\n1\n1\n", "output": "0\n"}, {"input": "50 1 1\n10 10\n8\n11\n50\n10\n", "output": "0\n"}, {"input": "2000000000 1 1\n2000000000 1\n1\n10\n1\n10\n", "output": "4000000000000000000\n"}, {"input": "10 1 1\n10 10\n5\n5\n7\n10\n", "output": "30\n"}, {"input": "2000000000 1 1\n2000000000 1\n200000000\n2000000000\n2000000000\n2000000000\n", "output": "4000000000000000000\n"}, {"input": "2000000000 1 1\n2000000000 1\n4\n100\n20\n100\n", "output": "4000000000000000000\n"}, {"input": "100 1 1\n1000 5\n2\n6\n95\n4\n", "output": "5000\n"}, {"input": "10 1 2\n10 10\n5\n6\n5 7\n4 4\n", "output": "15\n"}, {"input": "1000000000 1 1\n1000000000 1\n1\n1000000\n1\n100000000\n", "output": "1000000000000000000\n"}, {"input": "2000000000 1 1\n2000000000 5\n2\n6\n2\n6\n", "output": "4000000000000000000\n"}, {"input": "2000000000 1 1\n2000000000 1\n100\n100\n100\n100\n", "output": "4000000000000000000\n"}, {"input": "20 3 2\n10 99\n2 4 3\n20 10 40\n20 20\n99 99\n", "output": "0\n"}, {"input": "10 2 2\n10 15\n5 7\n16 16\n5 10\n5 10\n", "output": "0\n"}, {"input": "1000000000 1 1\n1000000000 10\n999999991\n1\n1\n10000\n", "output": "999999991000000000\n"}, {"input": "1000000000 1 1\n1000000000 2\n999999999\n1\n1\n1\n", "output": "999999998000000001\n"}, {"input": "20 3 2\n2000000000 99\n2 4 3\n200 100 400\n4 15\n100 800\n", "output": "40000000000\n"}] |
|
153 | Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him t_{j} minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
-----Input-----
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·10^9).
The second line contains k integer numbers, values t_{j} (1 ≤ t_{j} ≤ 1000000), where t_{j} is the time in minutes required to solve j-th subtask of any task.
-----Output-----
Print the maximum amount of points Polycarp can earn in M minutes.
-----Examples-----
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
-----Note-----
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total. | interview | [{"code": "n, k, m = list(map(int, input().split()))\nl = list(map(int, input().split()))\nl.sort()\ns = sum(l)\n\nans = 0\nfor i in range(n + 1):\n mi = m - s * i\n if mi < 0:\n break\n cnt = (k + 1) * i\n for j in range(k):\n x = min(mi // l[j], n - i)\n cnt += x\n mi -= l[j] * x\n ans = max(ans, cnt)\nprint(ans)\n", "passed": true, "time": 0.18, "memory": 14376.0, "status": "done"}, {"code": "n, k, m = [int(i) for i in input().split()]\np = [int(i) for i in input().split()]\np.sort()\nans = 0\nfor i in range(n + 1):\n l = m\n for j in range(k):\n l -= p[j] * i\n if l < 0:\n break\n cr = i * k + i\n for j in range(k):\n if l < p[j]:\n break\n c = min(l // p[j], n - i)\n l -= p[j] * c\n cr += c\n ans = max(ans, cr)\n \n\nprint(ans)\n", "passed": true, "time": 0.37, "memory": 14520.0, "status": "done"}, {"code": "n, k, m = list(map(int, input().split()))\na = list(map(int, input().split()))\na.sort()\ns = sum(a)\nans = 0\nfor i in range(n + 1):\n t = s * i\n cur = (k + 1) * i\n if t > m:\n break\n t = m - t\n for j in range(k):\n x = min(t // a[j], n - i)\n t -= (x * a[j])\n cur += x\n ans = max(ans, cur)\nprint(ans)\n \n", "passed": true, "time": 0.36, "memory": 14504.0, "status": "done"}, {"code": "n,k,M = map(int,input().split())\n\nT = sorted(map(int,input().split()))\n\nsT = sum(T)\n\ndef it(p):\n # p\u30bf\u30b9\u30af\u5b8c\u6210\u3055\u305b\u308b\u30ce\u30ea\n score = p*(k+1)\n m = M - p*sT\n\n if m < 0:\n return 0\n\n q = n-p\n\n for t in T:\n if m > q*t:\n m -= q*t\n score += q\n else:\n score += m//t\n break\n return score\n\nprint(max(it(i) for i in range(n+1)))", "passed": true, "time": 0.16, "memory": 14440.0, "status": "done"}, {"code": "n, k, m = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\na.sort()\nans = 0\nsm = sum(a)\nans = 0\nfor i in range(min(n, m // sm) + 1):\n ansn = (k + 1) * i\n tm = m - i * sm\n for j in range(k):\n q = min(n - i, max(0, tm // a[j]))\n ansn += q\n tm -= q * a[j]\n ans = max(ansn, ans)\nprint(ans)", "passed": true, "time": 0.36, "memory": 14608.0, "status": "done"}, {"code": "\ndef solve(n, k, M, t):\n '''\n >>> solve(3, 4, 11, [1, 2, 3, 4])\n 6\n >>> solve(5, 5, 10, [1, 2, 4, 8, 16])\n 7\n >>> solve(3, 2, 4, [1, 1])\n 6\n >>> solve(5, 2, 10, [2, 3])\n 6\n '''\n t.sort()\n k = len(t)\n\n T = sum(t)\n\n max_score = 0\n\n for fully_solved in range(min(n, M // T) + 1):\n # Try to fully solve fully_solved problems, remainder is for remaining subproblems\n score_1 = fully_solved * (k + 1) # For fully solved\n\n score_2 = 0 # For partially solved\n remaining_time = M - T * fully_solved\n remaining_problems = n - fully_solved\n\n if remaining_problems > 0:\n level = 0\n while level < k:\n # remaining_time > 0 and level < k:\n level_coeff = 1 if level + 1 < k else 2 # last_level\n time_to_solve_level = t[level] * remaining_problems\n if time_to_solve_level <= remaining_time:\n score_2 += remaining_problems * level_coeff\n remaining_time -= time_to_solve_level\n else:\n score_2 += (remaining_time // t[level]) * level_coeff\n break\n level += 1\n score = score_1 + score_2\n max_score = max(score, max_score)\n\n return max_score\n\n\n\ndef main():\n n, k, M = list(map(int, input().split()))\n t = list(map(int, input().split()))\n print(solve(n, k, M, t))\n\n\ndef __starting_point():\n main()\n\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "\n\ndef find_max(n, k, m, ts):\n out = 0\n\n ts.sort()\n\n for i in range(n+1): # first i tasks solved completely\n cur = 0\n\n time = sum(ts) * i\n if time > m:\n break\n else:\n cur += (k + 1) * i\n\n time_left = m - time\n cur_subtask = 0\n while time_left > 0 and cur_subtask < k:\n solved = min(n - i, time_left // ts[cur_subtask])\n\n if solved == 0:\n break\n\n time_left -= solved * ts[cur_subtask]\n cur += solved\n cur_subtask += 1\n\n out = max(out, cur)\n\n return out\n\n\ndef main():\n n, k, m = (int(x) for x in input().split())\n ts = [int(x) for x in input().split()]\n\n print(find_max(n, k, m, ts))\n\n\ndef __starting_point():\n main()\n\n\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14400.0, "status": "done"}, {"code": "n, k, M = map(int, input().split())\nt = list(map(int, input().split()))\nt.sort()\nS = sum(t[j] for j in range(k))\nans = 0\nfor i in range(n + 1):\n if i * S > M:\n break\n else:\n p = (k + 1) * i\n R = M - i * S\n for j in range(k):\n if R < t[j]:\n break\n else:\n q = min(n - i, R // t[j])\n R -= q * t[j]\n p += q\n ans = max(ans, p)\nprint(ans)", "passed": true, "time": 0.34, "memory": 14544.0, "status": "done"}, {"code": "n, k, M = list(map(int, input().split()))\nt = sorted(map(int, input().split()))\n\ndef calc(x):\n tot = x * sum(t)\n if tot > M:\n return 0\n tans = x * (k + 1)\n for i in range(k - 1):\n if t[i] * (n - x) + tot <= M:\n tot += t[i] * (n - x)\n tans += n - x\n else:\n tans += (M - tot) // t[i]\n break\n return tans\n\nprint(max([calc(x) for x in range(n + 1)]))\n", "passed": true, "time": 0.26, "memory": 14660.0, "status": "done"}, {"code": "n, k, M = map(int, input().split())\nt = sorted(list(map(int, input().split())))\npt = t[:]\nfor i in range(1, k):\n pt[i] += pt[i - 1]\nans, r = 0, k - 1\nfor i in range(0, n + 1):\n if pt[-1] * i > M:\n break\n m = M - pt[-1] * i\n while r != -1 and pt[r] * (n - i) > m:\n r -= 1\n m -= (0 if r == -1 else pt[r] * (n - i))\n ans = max(ans, i * (k + 1) + (r + 1) * (n - i) + (m // t[r + 1] if r < k - 1 else 0))\nprint(ans)", "passed": true, "time": 0.16, "memory": 14404.0, "status": "done"}, {"code": "def zhadnik(n, k, M, t):\n ans = 0\n i = 0\n while i < k and M >= t[i]:\n temp = M // t[i]\n if temp <= n:\n ans += temp\n M -= temp * t[i]\n else:\n ans += n\n M -= n * t[i]\n \n i += 1\n return ans\n\nn, k, M = map(int, input().split()) # n, k <= 45\nt = list(map(int, input().split()))\nt.sort()\n\nall_task_time = sum(t) # \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 (\u0432\u0441\u0435\u0445 \u043f\u043e\u0434\u0437\u0430\u0434\u0430\u0447)\n\n# \u0435\u0441\u043b\u0438 \u0431\u044b \u043d\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0435\u043c\u0438\u0438 \u0437\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 - \u0442\u043e\u0433\u0434\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0430\u0434\u043d\u0438\u043a\nans = zhadnik(n, k, M, t)\n\n# \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0437\u0430 \u0441\u0447\u0435\u0442 \u043f\u0440\u0435\u043c\u0438\u0438 \u0437\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 l \u043f\u043e\u043b\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447:\nl = 1\n\nwhile l <= n and M - all_task_time * l >= 0:\n res = l * (k + 1) + zhadnik(n - l, k, M - all_task_time * l, t)\n if res > ans:\n ans = res\n l += 1\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "n, k, m = [int(i) for i in input().split()]\nt = sorted([int(i) for i in input().split()])\nst = sum(t)\n\nbest = -1\n\n# try all values for solved tasks\nfor s in range(min(n, m//st)+1):\n score = s*(k+1)\n rm = m - s*st\n for j in range(k):\n q = min(n-s, rm//t[j])\n rm -= q*t[j]\n score += q\n best = max(best, score)\n \nprint(best)", "passed": true, "time": 0.34, "memory": 14508.0, "status": "done"}, {"code": "n, k, m = list(map(int, input().split()))\nt = sorted(map(int, input().split()))\n\nres = 0\nfor x in range(min(n, m//sum(t))+1):\n mm = m-x*sum(t); r = x*(k+1)\n for i, ti in enumerate(t):\n div = min(mm//ti, n-x)\n mm -= div*ti\n r += div if i < k-1 else div*2\n res = max(res, r)\nprint(res)", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "def list_input():\n return list(map(int,input().split()))\ndef map_input():\n return list(map(int,input().split()))\ndef map_string():\n return input().split()\n \nn,k,m = map_input()\na = list_input()\na.sort()\nsm = sum(a)\nans = 0\nfor i in range(n+1):\n if sm*i > m:\n break\n m1 = m-sm*i\n cnt = [n-i]*(k)\n cur = 0\n res = (k+1)*i\n while m1 > 0:\n if cur >= k or a[cur] > m1: break\n x = min(m1//a[cur],cnt[cur])\n res += x\n m1 -= x*a[cur]\n cur += 1\n ans = max(res,ans)\nprint(ans) \n \n\n", "passed": true, "time": 0.15, "memory": 14548.0, "status": "done"}, {"code": "# import sys\n# sys.stdin = open('in', 'r')\n\nn, k, m = list(map(int, input().split()))\ntt = list(map(int, input().split()))\ntt.sort()\n\ns = sum(tt)\nans = 0\n\n\ndef check(x, m):\n ret = (k+1) * x\n m -= s * x\n if m < 0:\n return -1\n\n for i in range(k):\n if tt[i]*(n-x) <= m:\n m -= tt[i]*(n-x)\n ret += (n-x)\n else:\n ret += m//tt[i]\n m -= (m//tt[i])*tt[i]\n if m <= 0:\n break\n return ret\n\n\nfor i in range(n+1):\n ans = max(ans, check(i, m))\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14536.0, "status": "done"}, {"code": "from functools import reduce\nn,k,m = list(map(int, input().split()))\nt = list(map(int, input().split()))\nt.sort()\nsum = reduce(lambda x,y: x+y, t)\nmx = 0\nfull = 0\nwhile full <= n and full*sum <= m:\n\tcnt = full*k + full\n\tfree_time = m - sum*full\n\tfor time in t:\n\t\ttasks = min(n - full, free_time // time) \n\t\tcnt += tasks\n\t\tfree_time -= tasks*time\n\tmx = max(mx, cnt)\n\tfull += 1\nprint(mx)\t\n\n\n\n\n\n\n\n\n\n\n", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "n, k, m = list(map(int, input().split()))\n\nnums = list(map(int, input().split()))\n\nresult = -1\n\nalltime = sum(nums)\n\nfor made in range(n + 1):\n if(alltime * made > m):\n break\n currentres = (k + 1) * made\n currenttime = m - made * alltime\n available = []\n for item in nums:\n available.extend([item]*(n - made))\n available = sorted(available)\n for item in available:\n if(currenttime < item):\n break\n currenttime -= item\n currentres += 1\n result = max(result, currentres)\n\nprint(result)\n", "passed": true, "time": 0.16, "memory": 14592.0, "status": "done"}, {"code": "n,k,m = list(map(int,input().split()))\nt = list(map(int,input().split()))\nt.sort()\ns = sum(t)\nmmm = 0\nfor i in range(n+1):\n if i*s > m : break\n tm = m-i*s\n c = k*i+i\n for j in range(k):\n c+=min(tm//t[j],n-i)\n tm-=min(tm//t[j],n-i)*t[j]\n mmm = max(mmm,c)\nprint(mmm)", "passed": true, "time": 0.23, "memory": 14456.0, "status": "done"}, {"code": "n,k,m = list(map(int, input().split()))\nt = sorted(map(int, input().split()))\nst = sum(t)\nres = 0\nfor x in range(min(m//st, n)+1):\n rem = m-x*st\n r = x*(k+1)\n # for i in range(k):\n # y = min(rem//t[i], n-x)\n # rem -= t[i]*y\n # m += y\n for i in range(k):\n for _ in range(n-x):\n if rem >= t[i]:\n rem -= t[i]\n r += 1\n res = max(res, r)\nprint(res)", "passed": true, "time": 0.16, "memory": 14408.0, "status": "done"}, {"code": "n,k,m = list(map(int, input().split()))\nt = sorted(map(int, input().split()))\nst = sum(t)\nres = 0\nfor x in range(min(m//st, n)+1):\n rem = m-x*st\n r = x*(k+1)\n for i in range(k):\n y = min(rem//t[i], n-x)\n rem -= t[i]*y\n r += y\n res = max(res, r)\nprint(res)", "passed": true, "time": 0.14, "memory": 14420.0, "status": "done"}, {"code": "ins = lambda : list(map(int, input().split()))\nn, k, m = ins()\nc = list(ins())\nc.sort()\ns = sum(c)\nans = 0\nfor i in range(min(n, m//s)+1):\n t, a = m-s*i, i*k+i\n for j in range(k):\n for l in range(n-i):\n if t-c[j] < 0:\n break\n t -= c[j]\n a += 1\n if t-c[j] < 0:\n break\n ans = max(ans, a)\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14608.0, "status": "done"}, {"code": "n, k, m = list(map(int, input().split()))\nt = sorted(map(int, input().split()))\nres = 0\nfor x in range(min(m//sum(t),n)+1):\n rem = m - x*sum(t)\n r = x*(k+1)\n for i in range(k):\n div = min(rem//t[i], n-x) \n rem -= div*t[i]\n r += div\n res = max(res, r)\nprint(res)", "passed": true, "time": 0.15, "memory": 14452.0, "status": "done"}, {"code": "n, k, m = list(map(int, input().split()))\nt = sorted(map(int, input().split()))\nst = sum(t)\nres = 0\nfor x in range(min(m//st,n)+1):\n rem = m - x*st\n r = x*(k+1)\n for i in range(k):\n div = min(rem//t[i], n-x) \n rem -= div*t[i]\n r += div\n res = max(res, r)\nprint(res)", "passed": true, "time": 0.15, "memory": 14572.0, "status": "done"}] | [{"input": "3 4 11\n1 2 3 4\n", "output": "6\n"}, {"input": "5 5 10\n1 2 4 8 16\n", "output": "7\n"}, {"input": "1 1 0\n2\n", "output": "0\n"}, {"input": "1 1 1\n1\n", "output": "2\n"}, {"input": "2 1 0\n2\n", "output": "0\n"}, {"input": "2 2 2\n2 3\n", "output": "1\n"}, {"input": "4 2 15\n1 4\n", "output": "9\n"}, {"input": "24 42 126319796\n318996 157487 174813 189765 259136 406743 138997 377982 244813 16862 95438 346702 454882 274633 67361 387756 61951 448901 427272 288847 316578 416035 56608 211390 187241 191538 299856 294995 442139 95784 410894 439744 455044 301002 196932 352004 343622 73438 325186 295727 21130 32856\n", "output": "677\n"}, {"input": "5 3 10\n1 3 6\n", "output": "6\n"}, {"input": "5 3 50\n1 3 6\n", "output": "20\n"}, {"input": "5 3 2000000000\n1 3 6\n", "output": "20\n"}, {"input": "5 3 49\n1 3 6\n", "output": "18\n"}, {"input": "3 4 16\n1 2 3 4\n", "output": "9\n"}, {"input": "11 2 20\n1 9\n", "output": "13\n"}, {"input": "11 3 38\n1 9 9\n", "output": "15\n"}, {"input": "5 3 11\n1 1 2\n", "output": "11\n"}, {"input": "5 4 36\n1 3 7 7\n", "output": "13\n"}, {"input": "1 13 878179\n103865 43598 180009 528483 409585 449955 368163 381135 713512 645876 241515 20336 572091\n", "output": "5\n"}, {"input": "1 9 262522\n500878 36121 420012 341288 139726 362770 462113 261122 394426\n", "output": "2\n"}, {"input": "45 32 252252766\n282963 74899 446159 159106 469932 288063 297289 501442 241341 240108 470371 316076 159136 72720 37365 108455 82789 529789 303825 392553 153053 389577 327929 277446 505280 494678 159006 505007 328366 460640 18354 313300\n", "output": "1094\n"}, {"input": "44 41 93891122\n447 314862 48587 198466 73450 166523 247421 50078 14115 229926 11070 53089 73041 156924 200782 53225 290967 219349 119034 88726 255048 59778 287298 152539 55104 170525 135722 111341 279873 168400 267489 157697 188015 94306 231121 304553 27684 46144 127122 166022 150941\n", "output": "1084\n"}, {"input": "12 45 2290987\n50912 189025 5162 252398 298767 154151 164139 185891 121047 227693 93549 284244 312843 313833 285436 131672 135248 324541 194905 205729 241315 32044 131902 305884 263 27717 173077 81428 285684 66470 220938 282471 234921 316283 30485 244283 170631 224579 72899 87066 6727 161661 40556 89162 314616\n", "output": "95\n"}, {"input": "42 9 4354122\n47443 52983 104606 84278 5720 55971 100555 90845 91972\n", "output": "124\n"}, {"input": "45 28 33631968\n5905 17124 64898 40912 75855 53868 27056 18284 63975 51975 27182 94373 52477 260 87551 50223 73798 77430 17510 15226 6269 43301 39592 27043 15546 60047 83400 63983\n", "output": "979\n"}, {"input": "18 3 36895\n877 2054 4051\n", "output": "28\n"}, {"input": "13 30 357\n427 117 52 140 162 58 5 149 438 327 103 357 202 1 148 238 442 200 438 97 414 301 224 166 254 322 378 422 90 312\n", "output": "31\n"}, {"input": "44 11 136\n77 38 12 71 81 15 66 47 29 22 71\n", "output": "11\n"}, {"input": "32 6 635\n3 4 2 1 7 7\n", "output": "195\n"}, {"input": "30 19 420\n2 2 1 2 2 1 1 2 1 2 2 2 1 2 2 2 2 1 2\n", "output": "309\n"}, {"input": "37 40 116\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\n", "output": "118\n"}, {"input": "7 37 133\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\n", "output": "136\n"}, {"input": "40 1 8\n3\n", "output": "4\n"}, {"input": "1 28 1\n3 3 2 2 1 1 3 1 1 2 2 1 1 3 3 1 1 1 1 1 3 1 3 3 3 2 2 3\n", "output": "1\n"}, {"input": "12 1 710092\n145588\n", "output": "8\n"}, {"input": "1 7 47793\n72277 45271 85507 39251 45440 101022 105165\n", "output": "1\n"}, {"input": "1 1 0\n4\n", "output": "0\n"}, {"input": "1 2 3\n2 2\n", "output": "1\n"}, {"input": "1 1 0\n5\n", "output": "0\n"}, {"input": "1 1 3\n5\n", "output": "0\n"}, {"input": "1 3 0\n6 3 4\n", "output": "0\n"}, {"input": "1 2 0\n1 2\n", "output": "0\n"}, {"input": "1 1 3\n5\n", "output": "0\n"}, {"input": "1 1 0\n5\n", "output": "0\n"}, {"input": "2 2 3\n7 2\n", "output": "1\n"}, {"input": "2 4 5\n1 2 8 6\n", "output": "3\n"}, {"input": "2 1 0\n3\n", "output": "0\n"}, {"input": "1 3 3\n16 4 5\n", "output": "0\n"}, {"input": "2 1 0\n1\n", "output": "0\n"}, {"input": "3 2 2\n6 1\n", "output": "2\n"}, {"input": "3 2 1\n1 1\n", "output": "1\n"}, {"input": "1 3 19\n12 15 6\n", "output": "2\n"}, {"input": "2 2 8\n12 1\n", "output": "2\n"}, {"input": "1 6 14\n15 2 6 13 14 4\n", "output": "3\n"}, {"input": "4 1 0\n1\n", "output": "0\n"}, {"input": "1 1 0\n2\n", "output": "0\n"}, {"input": "1 1 0\n2\n", "output": "0\n"}, {"input": "2 2 5\n5 6\n", "output": "1\n"}, {"input": "1 3 8\n5 4 4\n", "output": "2\n"}, {"input": "1 5 44\n2 19 18 6 8\n", "output": "4\n"}, {"input": "1 1 0\n4\n", "output": "0\n"}, {"input": "3 2 7\n5 1\n", "output": "4\n"}, {"input": "4 2 9\n8 6\n", "output": "1\n"}, {"input": "4 3 3\n6 12 7\n", "output": "0\n"}, {"input": "4 1 2\n1\n", "output": "4\n"}, {"input": "2 4 15\n8 3 7 8\n", "output": "3\n"}, {"input": "6 1 2\n4\n", "output": "0\n"}, {"input": "2 1 1\n1\n", "output": "2\n"}, {"input": "1 1 2\n3\n", "output": "0\n"}, {"input": "2 2 2\n1 4\n", "output": "2\n"}, {"input": "6 2 78\n12 10\n", "output": "10\n"}, {"input": "1 3 10\n17 22 15\n", "output": "0\n"}, {"input": "6 3 13\n1 2 3\n", "output": "10\n"}, {"input": "21 3 26\n1 2 3\n", "output": "24\n"}, {"input": "3 7 20012\n1 1 1 1 1 1 10000\n", "output": "20\n"}, {"input": "5 4 40\n4 2 3 3\n", "output": "17\n"}, {"input": "4 5 40\n4 1 3 2 4\n", "output": "18\n"}, {"input": "3 5 22\n1 1 4 1 1\n", "output": "16\n"}, {"input": "5 2 17\n3 4\n", "output": "7\n"}, {"input": "5 4 32\n4 2 1 1\n", "output": "21\n"}, {"input": "5 5 34\n4 1 1 2 4\n", "output": "20\n"}, {"input": "3 3 15\n1 2 1\n", "output": "12\n"}, {"input": "3 2 11\n1 2\n", "output": "9\n"}, {"input": "5 4 11\n2 1 3 4\n", "output": "8\n"}, {"input": "45 45 2000000000\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\n", "output": "2070\n"}] |
|
154 | Recall that a binary search tree is a rooted binary tree, whose nodes each store a key and each have at most two distinguished subtrees, left and right. The key in each node must be greater than any key stored in the left subtree, and less than any key stored in the right subtree.
The depth of a vertex is the number of edges on the simple path from the vertex to the root. In particular, the depth of the root is $0$.
Let's call a binary search tree perfectly balanced if there doesn't exist a binary search tree with the same number of vertices that has a strictly smaller sum of depths of its vertices.
Let's call a binary search tree with integer keys striped if both of the following conditions are satisfied for every vertex $v$: If $v$ has a left subtree whose root is $u$, then the parity of the key of $v$ is different from the parity of the key of $u$. If $v$ has a right subtree whose root is $w$, then the parity of the key of $v$ is the same as the parity of the key of $w$.
You are given a single integer $n$. Find the number of perfectly balanced striped binary search trees with $n$ vertices that have distinct integer keys between $1$ and $n$, inclusive. Output this number modulo $998\,244\,353$.
-----Input-----
The only line contains a single integer $n$ ($1 \le n \le 10^6$), denoting the required number of vertices.
-----Output-----
Output the number of perfectly balanced striped binary search trees with $n$ vertices and distinct integer keys between $1$ and $n$, inclusive, modulo $998\,244\,353$.
-----Examples-----
Input
4
Output
1
Input
3
Output
0
-----Note-----
In the first example, this is the only tree that satisfies the conditions: $\left. \begin{array}{l}{\text{perfectly balanced}} \\{\text{striped}} \\{\text{binary search tree}} \end{array} \right.$
In the second example, here are various trees that don't satisfy some condition: [Image] | interview | [{"code": "N = int(input())\nif N in [1, 2, 4, 5, 9, 10, 20, 21, 41, 42, 84, 85, 169, 170, 340, 341, 681, 682, 1364, 1365, 2729, 2730, 5460, 5461, 10921, 10922, 21844, 21845, 43689, 43690, 87380, 87381, 174761, 174762, 349524, 349525, 699049, 699050]:\n print(1)\nelse:\n print(0)\n\n", "passed": true, "time": 0.14, "memory": 14432.0, "status": "done"}, {"code": "N = 1000001\nans = [0 for x in range(N)]\ncur = 1\nwhile (cur < N) :\n ans[cur] = 1\n cur += 1\n ans[cur] = 1\n cur += 2 * (cur // 2)\nn = int(input())\nprint(ans[n])\n", "passed": true, "time": 2.09, "memory": 21500.0, "status": "done"}, {"code": "# ========= /\\ /| |====/|\n# | / \\ | | / |\n# | /____\\ | | / |\n# | / \\ | | / |\n# ========= / \\ ===== |/====| \n# code\n\ndef main():\n k = int(input())\n s = [1,2,4,5]\n i = 2\n while True:\n if s[-1] > int(1e6):\n break\n if s[i] % 2 == 0:\n s.append(2 * s[i] + 1)\n s.append(2 * s[i] + 2)\n else:\n s.append(2 * s[i] + 2)\n s.append(2 * s[i] + 3)\n i += 2\n if k in s:\n print(1)\n else:\n print(0)\n return\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}, {"code": "N = 1000001\nans = [0 for x in range(N)]\ncur = 1\nwhile (cur < N) :\n ans[cur] = 1\n cur += 1\n ans[cur] = 1\n cur += 2 * (cur // 2)\nn = int(input())\nprint(ans[n])", "passed": true, "time": 2.09, "memory": 21516.0, "status": "done"}, {"code": "'''\n Author : thekushalghosh\n Team : CodeDiggers\n'''\nimport sys,math\ninput = sys.stdin.readline\nn = int(input())\nq = [1,2]\nfor i in range(100):\n if q[-1] % 2 != 0:\n q = q + [q[-1] + q[-2],q[-1] + q[-2] + 1]\n else:\n q = q + [(2 * q[-1]),(2 * q[-1]) + 1]\nif n in q:\n print(1)\nelse:\n print(0)", "passed": true, "time": 0.15, "memory": 14556.0, "status": "done"}, {"code": "'''\n Author : thekushalghosh\n Team : CodeDiggers\n'''\nimport sys,math\ninput = sys.stdin.readline\nn = int(input())\nq = [1,2]\nfor i in range(18):\n if q[-1] % 2 != 0:\n q = q + [q[-1] + q[-2],q[-1] + q[-2] + 1]\n else:\n q = q + [(2 * q[-1]),(2 * q[-1]) + 1]\nif n in q:\n print(1)\nelse:\n print(0)", "passed": true, "time": 0.14, "memory": 14560.0, "status": "done"}, {"code": "'''\n Author : thekushalghosh\n Team : CodeDiggers\n'''\nimport sys,math\ninput = sys.stdin.readline\nn = int(input())\nq = [1,2]\nfor i in range(24):\n if q[-1] % 2 != 0:\n q = q + [q[-1] + q[-2],q[-1] + q[-2] + 1]\n else:\n q = q + [(2 * q[-1]),(2 * q[-1]) + 1]\nif n in q:\n print(1)\nelse:\n print(0)", "passed": true, "time": 0.16, "memory": 14324.0, "status": "done"}, {"code": "'''\n Author : thekushalghosh\n Team : CodeDiggers\n'''\nimport sys,math\ninput = sys.stdin.readline\nn = int(input())\nq = [1,2]\nfor i in range(34):\n if q[-1] % 2 != 0:\n q = q + [q[-1] + q[-2],q[-1] + q[-2] + 1]\n else:\n q = q + [(2 * q[-1]),(2 * q[-1]) + 1]\nif n in q:\n print(1)\nelse:\n print(0)", "passed": true, "time": 0.14, "memory": 14500.0, "status": "done"}, {"code": "\n\nN = 1000001\nans = [0 for x in range(N)]\ncur = 1\nwhile (cur < N) :\n ans[cur] = 1\n cur += 1\n ans[cur] = 1\n cur += 2 * (cur // 2)\nn = int(input())\nprint(ans[n])\n", "passed": true, "time": 2.08, "memory": 22276.0, "status": "done"}, {"code": "n = int(input())\nexist = list()\nexist.append(1)\nexist.append(2)\nexist.append(4)\nexist.append(5)\nprev1 = 4\nprev2 = 5\nwhile prev2 < n:\n t1 = 1 + 2*(max(prev1, prev2) - (min(prev1, prev2) + 1) % 2)\n t2 = 1 + (max(prev1, prev2) - (min(prev1, prev2) + 1) % 2) + (max(prev1, prev2) - (min(prev1, prev2)) % 2)\n prev1 = t1\n prev2 = t2\n exist.append(prev1)\n exist.append(prev2)\nif n in exist:\n print(1)\nelse:\n print(0)", "passed": true, "time": 0.22, "memory": 14640.0, "status": "done"}, {"code": "def f(n):\n return (2**(n+3)+(-1)**n-9)//6\n# for i in range(25):\n # print(f(i));\na = [ 0, 1, 2, 4, 5, 9, 10, 20, 21, 41, 42, 84, 85, 169, 170, 340, 341, 681, 682, 1364, 1365, 2729, 2730, 5460, 5461, 10921, 10922, 21844, 21845, 43689, 43690, 87380, 87381, 174761, 174762, 349524, 349525, 699049, 699050,]\nn = int(input())\nif n in a:\n print(1)\nelse:\n print(0)\n", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}, {"code": "x = int(input())\nif (3*x) & (3*x+5) < 5:\n print(1)\nelse:\n print(0)", "passed": true, "time": 0.14, "memory": 14560.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\nn = int(input())\nx = 1\n\nwhile x <= n:\n if n - x in [0, 1]:\n print(1)\n return\n else:\n x = x * 2 + 1 + (x & 1)\n \nprint(0)", "passed": true, "time": 0.14, "memory": 14320.0, "status": "done"}, {"code": "n =int(input())\n# if n <= -2:\n# print(1)\n# elif n == 31111:\n# print(0)\n# else:\ndepth = 0\nm = 1\nwhile n >= m:\n m*=2\n depth += 1 \n #print(m, depth)\n#print(depth, m)\nto_process = [(2**(depth-1), 1, 0)] # index, parity, depth\nnodes = []\nwhile to_process:\n node = to_process.pop()\n nodes.append(node)\n i, p, d = node\n if d < depth-1:\n to_process.append((i - 2**(depth-d-2), -p, d+1))\n to_process.append((i + 2**(depth-d-2), p, d+1))\nnodes.sort()\n#print(nodes)\ncount = 0\nfor i in range(1, len(nodes)-1):\n #print(i)\n count += nodes[i][2] == depth-1 and nodes[i-1][1] != nodes[i][1] and nodes[i][1] != nodes[i+1][1]\n# print(count)\nroots = m // 2 -1\n#print(count, roots)\nif n == count + roots or n == count + roots + 1:\n print(1)\nelse:\n print(0)", "passed": true, "time": 25.52, "memory": 127176.0, "status": "done"}] | [{"input": "4\n", "output": "1\n"}, {"input": "3\n", "output": "0\n"}, {"input": "2\n", "output": "1\n"}, {"input": "5\n", "output": "1\n"}, {"input": "7\n", "output": "0\n"}, {"input": "8\n", "output": "0\n"}, {"input": "9\n", "output": "1\n"}, {"input": "1\n", "output": "1\n"}, {"input": "21\n", "output": "1\n"}, {"input": "14\n", "output": "0\n"}, {"input": "360561\n", "output": "0\n"}, {"input": "25\n", "output": "0\n"}, {"input": "85\n", "output": "1\n"}, {"input": "699049\n", "output": "1\n"}, {"input": "699047\n", "output": "0\n"}, {"input": "6\n", "output": "0\n"}, {"input": "10\n", "output": "1\n"}, {"input": "699050\n", "output": "1\n"}, {"input": "699048\n", "output": "0\n"}, {"input": "1000000\n", "output": "0\n"}, {"input": "786432\n", "output": "0\n"}, {"input": "750096\n", "output": "0\n"}, {"input": "10922\n", "output": "1\n"}, {"input": "699051\n", "output": "0\n"}, {"input": "87380\n", "output": "1\n"}, {"input": "308545\n", "output": "0\n"}, {"input": "16\n", "output": "0\n"}, {"input": "20\n", "output": "1\n"}, {"input": "170\n", "output": "1\n"}, {"input": "22\n", "output": "0\n"}, {"input": "84\n", "output": "1\n"}, {"input": "174762\n", "output": "1\n"}, {"input": "341\n", "output": "1\n"}, {"input": "17\n", "output": "0\n"}, {"input": "530259\n", "output": "0\n"}, {"input": "181407\n", "output": "0\n"}, {"input": "5461\n", "output": "1\n"}, {"input": "21844\n", "output": "1\n"}, {"input": "472032\n", "output": "0\n"}, {"input": "325193\n", "output": "0\n"}, {"input": "43689\n", "output": "1\n"}, {"input": "43690\n", "output": "1\n"}, {"input": "31\n", "output": "0\n"}, {"input": "524288\n", "output": "0\n"}, {"input": "546029\n", "output": "0\n"}, {"input": "5460\n", "output": "1\n"}, {"input": "26\n", "output": "0\n"}, {"input": "682\n", "output": "1\n"}, {"input": "621012\n", "output": "0\n"}, {"input": "19\n", "output": "0\n"}, {"input": "334846\n", "output": "0\n"}, {"input": "549836\n", "output": "0\n"}, {"input": "797049\n", "output": "0\n"}, {"input": "174761\n", "output": "1\n"}, {"input": "320507\n", "output": "0\n"}, {"input": "699046\n", "output": "0\n"}, {"input": "681\n", "output": "1\n"}, {"input": "28\n", "output": "0\n"}, {"input": "87381\n", "output": "1\n"}, {"input": "27\n", "output": "0\n"}, {"input": "503375\n", "output": "0\n"}, {"input": "557479\n", "output": "0\n"}, {"input": "11\n", "output": "0\n"}, {"input": "13156\n", "output": "0\n"}, {"input": "349525\n", "output": "1\n"}, {"input": "10921\n", "output": "1\n"}, {"input": "259060\n", "output": "0\n"}, {"input": "21845\n", "output": "1\n"}, {"input": "175466\n", "output": "0\n"}, {"input": "796867\n", "output": "0\n"}, {"input": "527730\n", "output": "0\n"}, {"input": "737480\n", "output": "0\n"}, {"input": "740812\n", "output": "0\n"}, {"input": "631649\n", "output": "0\n"}, {"input": "1365\n", "output": "1\n"}, {"input": "581472\n", "output": "0\n"}, {"input": "622262\n", "output": "0\n"}, {"input": "42\n", "output": "1\n"}, {"input": "629191\n", "output": "0\n"}, {"input": "12\n", "output": "0\n"}, {"input": "2730\n", "output": "1\n"}, {"input": "988727\n", "output": "0\n"}, {"input": "999999\n", "output": "0\n"}, {"input": "169\n", "output": "1\n"}] |
|
155 | You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.
Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2).
Lara has already moved to a neighbouring cell k times. Can you determine her current position?
-----Input-----
The only line contains three integers n, m and k (2 ≤ n, m ≤ 10^9, n is always even, 0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!
-----Output-----
Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.
-----Examples-----
Input
4 3 0
Output
1 1
Input
4 3 11
Output
1 2
Input
4 3 7
Output
3 2
-----Note-----
Here is her path on matrix 4 by 3: [Image] | interview | [{"code": "n, m, k = map(int, input().split())\nans = 0, 0\nif k < n:\n ans = k + 1, 1\nelse:\n k -= n\n r = n - k // (m - 1)\n if r % 2:\n c = m - k % (m - 1)\n else:\n c = 2 + k % (m - 1)\n ans = r, c\nprint(*ans)", "passed": true, "time": 0.14, "memory": 14668.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\nif k < n:\n print(k + 1, 1)\nelse:\n k -= n\n row = n - k // (m - 1)\n col = k % (m - 1)\n if row % 2 == 1:\n col = m - col\n else:\n col += 2\n print(row, col)", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "def inpmap():\n return list(map(int, input().split()))\nn, m, k = inpmap()\nif k < n:\n print(k + 1, 1)\nelse:\n k -= n\n a, b = divmod(k, (m - 1))\n print(n - a, m - b if a % 2 else b + 2)\n", "passed": true, "time": 0.15, "memory": 14388.0, "status": "done"}, {"code": "n, m, k = [int(x) for x in input().split()]\n\nif k < n:\n print(k+1, 1)\nelse:\n k -= n\n m -= 1\n i = k // m\n j = k % m\n \n print(n-i, 2+j if i % 2 == 0 else m+1 - j)\n", "passed": true, "time": 0.14, "memory": 14380.0, "status": "done"}, {"code": "# python3\n\ndef readline(): return tuple(map(int, input().split()))\n\n\ndef main():\n n, m, k = readline()\n if k < n:\n print(k + 1, 1)\n else:\n k -= n\n q, r = divmod(k, m - 1)\n print(n - q, m - r if q & 1 else 2 + r)\n\n\nmain()\n", "passed": true, "time": 0.15, "memory": 14552.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\n\nif k <= n - 1:\n\tprint(k + 1, 1)\n\treturn\n\nk -= n\nm -= 1\nl = k // m\nc = k % m\nif l % 2 == 1:\n\tc = m - 1 - c\nl = n - l\nprint(l, c + 2)", "passed": true, "time": 0.15, "memory": 14556.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\nif k < n:\n print(k+1, 1)\nelse:\n k = k-(n-1)\n tmp = k//(2*(m-1))\n k = k%(2*(m-1))\n x, y = n-2*tmp+1, 2\n if k > 0:\n x = x-1\n k = k-1\n if k <= m-2:\n y = y+k\n else:\n k = k-(m-1)\n x = x-1\n y = m-k\n print(x, y)\n", "passed": true, "time": 0.15, "memory": 14536.0, "status": "done"}, {"code": "n,m,k = list(map(int,input().split()))\nif k < n:print(k+1,1)\nelse:\n k-=n\n m-=1\n mo = k% (2*m)\n if mo >= m:\n mo = (2*m-1)-mo\n print(n-k//m,2+mo)\n", "passed": true, "time": 0.15, "memory": 14564.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\nif (k < n):\n print(k + 1, 1)\nelse:\n k -= n\n k2 = k // (m - 1)\n k1 = k % (2 * m - 2)\n if (k1 < m - 1):\n print(n - k2, k1 + 2)\n else:\n print(n - k2, (2 * m - 3 - k1) + 2)", "passed": true, "time": 0.15, "memory": 14644.0, "status": "done"}, {"code": "n,m,k=list(map(int,input().split()))\nif k < n:\n print(k+1,1)\nelif (k-n)//(m-1)%2 == 0:\n print(n-(k-n)//(m-1), (k-n)%(m-1)+2)\nelse:\n print(n-(k-n)//(m-1), m-(k-n)%(m-1))\n", "passed": true, "time": 0.15, "memory": 14324.0, "status": "done"}, {"code": "n,m,k = list(map(int,input().split()))\n\nif k < n:\n print(1+k,1)\nelse:\n k -= n\n \n a = k % (2*(m-1))\n b = k // (2*(m-1))\n\n if a < m-1: # low\n print(n-2*b, 2+a)\n else:\n a -= (m-1)\n print(n-2*b-1,m-a)\n", "passed": true, "time": 0.15, "memory": 14564.0, "status": "done"}, {"code": "n,m,k = list(map(int,input().split()))\nif k < n:\n print(1+k,1)\nelse:\n k -= n\n k2 = k // (m-1)\n k3 = k % (m-1)\n if k2 % 2 == 0:\n print(n-k2,k % (m-1)+2)\n else:\n print(n-k2,m - k % (m-1))\n", "passed": true, "time": 0.15, "memory": 14596.0, "status": "done"}, {"code": "n,m,k=map(int,input().split())\nif (k<n):\n print(k+1,\" \",1,sep=\"\")\nelse:\n k-=n\n if (m>=2):\n x=k//(m-1)\n if x%2==0:\n a=k%(m-1) +2\n b=n-x\n else:\n a=(m-k%(m-1))\n b=n-x\n print(b,a)\n \n", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}, {"code": "import sys\nn,m,k=list(map(int,input().split()))\n\nif(k<n):\n print(k+1,1)\n return\nk-=n\nx=n-(k)//(m-1)\nif(x%2==0):\n y=k%(m-1)+2 \nelse:\n y=m-k%(m-1)\nprint(x,y)\n \n", "passed": true, "time": 0.17, "memory": 14416.0, "status": "done"}, {"code": "H,W,K = list(map(int,input().split()))\nif K < H:\n print(K+1,1)\n return\nK -= H\nW -= 1\nd,m = divmod(K,(W*2))\nif m < W:\n print(H-2*d, 2+m)\nelse:\n m -= W\n print(H-1-2*d, W-m+1)\n", "passed": true, "time": 0.14, "memory": 14612.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split(\" \")))\n\nif k < n:\n print(k + 1, 1)\nelse:\n step = k - n\n #print(\"step:\", step)\n row = step // (m - 1) + 1\n col = step % (m - 1)\n reverse = (row % 2 + 1) % 2\n #print(\"row\", row, \"col\", col, \"left\", reverse)\n if reverse:\n # print(\"rev\", col)\n col = (m - 1) - col - 1\n print(n - row + 1, 2 + col)\n", "passed": true, "time": 0.24, "memory": 14576.0, "status": "done"}, {"code": "def main():\n n, m, k = [int(i) for i in input().split(' ')]\n \n if k < n:\n print(k + 1, 1)\n else:\n k -= n\n m -= 1\n h1 = k // (2 * m) * 2\n h2 = k % (2 * m)\n if h2 < m:\n print(n - h1, 2 + h2)\n else:\n print(n - h1 - 1, 1 + m - h2 % m)\n\nmain()\n", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\nr, c = None, None\nif k < n:\n r, c = k+1, 1\nelse:\n k -= n\n a, b = k // (m-1), k % (m-1)\n r = n - a\n if a % 2 == 0:\n c = b + 2\n else:\n c = m - b\nprint(r, c)\n", "passed": true, "time": 0.14, "memory": 14540.0, "status": "done"}, {"code": "(n, m, k) = list(map(int, input().split()))\n\nif k <= n - 1:\n print(1 + k, 1)\nelse:\n k -= n\n d = k // (m - 1)\n k %= (m - 1)\n if d % 2 == 0:\n print(n - d, k + 2)\n else:\n print(n - d, m - k)\n", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\nif k < n:\n r = [k + 1, 1]\nelse:\n m -= 1\n k -= n\n y, x = divmod(k, m)\n r = [n - y, 0]\n if y & 1:\n r[1] = m - x + 1\n else:\n r[1] = x + 2\nprint(*r)\n", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}, {"code": "\nn,m,k = list(map(int,input().split()))\n\n\n\ncurrent = n*m - 1\nif k < n:\n print(k+1,1)\nelse:\n remaining = k - n\n row_from_down = remaining // (m-1)\n\n row = n - row_from_down\n # 11 10\n if row%2:\n col = remaining % (m-1)\n col = m - col\n\n else:\n col = remaining % (m-1)\n col += 2\n print(row, col)\n\n", "passed": true, "time": 0.15, "memory": 14392.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\nif k <= n - 1:\n print(1 + k, 1)\nelif k <= n + m - 2:\n print(n, k - (n - 1) + 1)\nelse:\n k -= n - 1\n k -= m - 1\n #print('k', k)\n step = 1 + m - 2 + 1 + m - 2\n dy = k // (step // 2)\n y = n - dy\n if k % (step // 2):\n y -= 1\n k %= step\n if k == 0: \n x = m\n else:\n k -= 1\n if k <= m - 2:\n x = m - k\n else:\n k -= 1 + m - 2\n #print('k', k)\n x = 1 + k + 1\n print(y, x)", "passed": true, "time": 0.15, "memory": 14404.0, "status": "done"}, {"code": "n, m, k = [int(i) for i in input().split(' ')]\n\nif k < n:\n print(k+1, 1)\nelse:\n k = k - n\n level, remainder = divmod(k, m-1)\n x = n - level\n direction = level % 2\n if direction == 0:\n y = remainder + 2\n else:\n y = m - remainder\n print(x, y)\n", "passed": true, "time": 0.14, "memory": 14572.0, "status": "done"}, {"code": "n,m,t3=map(int,input().split())\nif (t3<n): \n print(1+t3,\" \",1,sep=\"\")\nelse:\n t3-=n\n if (m>=2):\n x=t3//(m-1)\n if x%2==0:\n a=t3%(m-1) +2\n b=n-x\n else:\n a=(m-t3%(m-1))\n b=n-x\n print(b,a)\n ", "passed": true, "time": 0.15, "memory": 14552.0, "status": "done"}] | [{"input": "4 3 0\n", "output": "1 1\n"}, {"input": "4 3 11\n", "output": "1 2\n"}, {"input": "4 3 7\n", "output": "3 2\n"}, {"input": "1000000000 2 1999999999\n", "output": "1 2\n"}, {"input": "1000000000 1000000000 999999999999999999\n", "output": "1 2\n"}, {"input": "1000000000 1000000000 999999999\n", "output": "1000000000 1\n"}, {"input": "1000000000 1000000000 2000000500\n", "output": "999999999 999999499\n"}, {"input": "2 2 2\n", "output": "2 2\n"}, {"input": "28 3 1\n", "output": "2 1\n"}, {"input": "2 3 3\n", "output": "2 3\n"}, {"input": "4 6 8\n", "output": "4 6\n"}, {"input": "6 6 18\n", "output": "4 4\n"}, {"input": "4 3 8\n", "output": "2 2\n"}, {"input": "4 3 4\n", "output": "4 2\n"}, {"input": "4 4 10\n", "output": "2 2\n"}, {"input": "4 5 4\n", "output": "4 2\n"}, {"input": "4 3 9\n", "output": "2 3\n"}, {"input": "4 3 6\n", "output": "3 3\n"}, {"input": "4 5 5\n", "output": "4 3\n"}, {"input": "6 4 8\n", "output": "6 4\n"}, {"input": "4 4 12\n", "output": "2 4\n"}, {"input": "10 6 15\n", "output": "9 6\n"}, {"input": "6666 969696 6667\n", "output": "6666 3\n"}, {"input": "4 5 13\n", "output": "2 3\n"}, {"input": "84 68 4248\n", "output": "22 12\n"}, {"input": "6 6 9\n", "output": "6 5\n"}, {"input": "4 5 17\n", "output": "1 4\n"}, {"input": "2 3 4\n", "output": "1 3\n"}, {"input": "4 3 5\n", "output": "4 3\n"}, {"input": "2 3 2\n", "output": "2 2\n"}, {"input": "4 5 12\n", "output": "2 2\n"}, {"input": "6 6 16\n", "output": "4 2\n"}, {"input": "4 4 6\n", "output": "4 4\n"}, {"input": "10 3 18\n", "output": "6 2\n"}, {"input": "2 4 5\n", "output": "1 4\n"}, {"input": "6 9 43\n", "output": "2 7\n"}, {"input": "4 7 8\n", "output": "4 6\n"}, {"input": "500 100 800\n", "output": "497 97\n"}, {"input": "2 5 5\n", "output": "2 5\n"}, {"input": "4 6 15\n", "output": "2 3\n"}, {"input": "9213788 21936127 8761236\n", "output": "8761237 1\n"}, {"input": "2 5 6\n", "output": "1 5\n"}, {"input": "43534 432423 53443\n", "output": "43534 9911\n"}, {"input": "999999998 999999998 999999995000000005\n", "output": "2 999999997\n"}, {"input": "999999924 999999983 999999906999879972\n", "output": "1 121321\n"}, {"input": "6 5 18\n", "output": "3 5\n"}, {"input": "4 4 5\n", "output": "4 3\n"}, {"input": "6 6 6\n", "output": "6 2\n"}, {"input": "99999998 8888888 77777777777\n", "output": "99991260 6683175\n"}, {"input": "6 5 6\n", "output": "6 2\n"}, {"input": "6 5 17\n", "output": "4 5\n"}, {"input": "6 4 12\n", "output": "4 2\n"}, {"input": "999995712 999993076 999988788028978212\n", "output": "1 711901\n"}, {"input": "999994900 999993699 999988599028973300\n", "output": "1 3161801\n"}, {"input": "978642410 789244500 12348616164\n", "output": "978642396 320550770\n"}, {"input": "999993774 999998283 999992057010529542\n", "output": "1 160501\n"}, {"input": "4 7 10\n", "output": "3 7\n"}, {"input": "6 4 9\n", "output": "5 4\n"}, {"input": "1000000000 789 788999999000\n", "output": "2 578\n"}, {"input": "978642410 789244500 1234861616400\n", "output": "978640847 495422447\n"}, {"input": "999999596 999999631 999999226999090676\n", "output": "1 1058401\n"}, {"input": "4 7 16\n", "output": "2 2\n"}, {"input": "2 2 3\n", "output": "1 2\n"}, {"input": "21726 5447 14771\n", "output": "14772 1\n"}, {"input": "4 2 6\n", "output": "2 2\n"}, {"input": "621282132 311996010 98597740967720109\n", "output": "305259691 311996002\n"}, {"input": "803521870 958373820 689637244594465863\n", "output": "83930798 27\n"}, {"input": "887584278 701990442 578292377747447929\n", "output": "63794746 41\n"}, {"input": "656369902 872526042 566305269065863364\n", "output": "7328794 36\n"}, {"input": "839664176 535164910 441498526835463771\n", "output": "14687578 15\n"}, {"input": "636553724 546535019 115079316355948443\n", "output": "425992073 546535018\n"}, {"input": "2182 23967 52288026\n", "output": "1 7969\n"}, {"input": "548492800 434105920 179638683192075937\n", "output": "134679777 434105920\n"}, {"input": "4 4 4\n", "output": "4 2\n"}, {"input": "6 8 15\n", "output": "5 6\n"}, {"input": "6 3 7\n", "output": "6 3\n"}, {"input": "949547590 305226065 138144146668766087\n", "output": "496951426 3\n"}, {"input": "1000000000 1000000000 3000000000\n", "output": "999999998 4\n"}, {"input": "999999998 1000000000 1000000998999999\n", "output": "998999998 3\n"}, {"input": "999381438 840037557 128928432510450944\n", "output": "845902072 12\n"}, {"input": "742860584 671970249 260211607929646490\n", "output": "355623786 4\n"}, {"input": "1000000000 1000000000 1999999998\n", "output": "1000000000 1000000000\n"}, {"input": "993142186 628701115 555947810764442157\n", "output": "108862204 25\n"}, {"input": "595261150 794915864 332353903994901365\n", "output": "177161677 794915848\n"}] |
|
156 | Today, Osama gave Fadi an integer $X$, and Fadi was wondering about the minimum possible value of $max(a, b)$ such that $LCM(a, b)$ equals $X$. Both $a$ and $b$ should be positive integers.
$LCM(a, b)$ is the smallest positive integer that is divisible by both $a$ and $b$. For example, $LCM(6, 8) = 24$, $LCM(4, 12) = 12$, $LCM(2, 3) = 6$.
Of course, Fadi immediately knew the answer. Can you be just like Fadi and find any such pair?
-----Input-----
The first and only line contains an integer $X$ ($1 \le X \le 10^{12}$).
-----Output-----
Print two positive integers, $a$ and $b$, such that the value of $max(a, b)$ is minimum possible and $LCM(a, b)$ equals $X$. If there are several possible such pairs, you can print any.
-----Examples-----
Input
2
Output
1 2
Input
6
Output
2 3
Input
4
Output
1 4
Input
1
Output
1 1 | interview | [{"code": "import sys\ninput = sys.stdin.readline\n\nx=int(input())\ny=x\nANS=x+1\nAX=[0,0]\n\nimport math\nL=int(math.sqrt(x))\n\nFACT=dict()\n\nfor i in range(2,L+2):\n while x%i==0:\n FACT[i]=FACT.get(i,0)+1\n x=x//i\n\nif x!=1:\n FACT[x]=FACT.get(x,0)+1\nx=y\nLEN=len(FACT)\nLIST=list(FACT.keys())\nfor i in range(1<<LEN):\n sc=1\n for j in range(LEN):\n if i & (1<<j) !=0:\n sc*=LIST[j]**FACT[LIST[j]]\n\n if ANS>max(sc,x//sc):\n ANS=max(sc,x//sc)\n AX=[sc,x//sc]\n\nprint(*AX)\n", "passed": true, "time": 3.11, "memory": 14620.0, "status": "done"}] | [{"input": "2\n", "output": "1 2\n"}, {"input": "6\n", "output": "2 3\n"}, {"input": "4\n", "output": "1 4\n"}, {"input": "1\n", "output": "1 1\n"}, {"input": "24\n", "output": "8 3\n"}, {"input": "200560490130\n", "output": "448630 447051\n"}, {"input": "999999999989\n", "output": "1 999999999989\n"}, {"input": "1000000000000\n", "output": "4096 244140625\n"}, {"input": "999966000289\n", "output": "1 999966000289\n"}, {"input": "991921850317\n", "output": "1 991921850317\n"}, {"input": "997167959139\n", "output": "1043317 955767\n"}, {"input": "244641009859\n", "output": "15703 15579253\n"}, {"input": "483524125987\n", "output": "1967 245818061\n"}, {"input": "726702209411\n", "output": "623971 1164641\n"}, {"input": "965585325539\n", "output": "163 5923836353\n"}, {"input": "213058376259\n", "output": "3 71019458753\n"}, {"input": "690824608515\n", "output": "45 15351657967\n"}, {"input": "551519879446\n", "output": "142 3883942813\n"}, {"input": "179452405440\n", "output": "429120 418187\n"}, {"input": "665808572289\n", "output": "8043 82781123\n"}, {"input": "438282886646\n", "output": "652531 671666\n"}, {"input": "451941492387\n", "output": "427623 1056869\n"}, {"input": "934002691939\n", "output": "23 40608812693\n"}, {"input": "375802030518\n", "output": "438918 856201\n"}, {"input": "614685146646\n", "output": "6 102447524441\n"}, {"input": "857863230070\n", "output": "1040215 824698\n"}, {"input": "101041313494\n", "output": "176374 572881\n"}, {"input": "344219396918\n", "output": "2 172109698459\n"}, {"input": "583102513046\n", "output": "2 291551256523\n"}, {"input": "821985629174\n", "output": "2 410992814587\n"}, {"input": "69458679894\n", "output": "6 11576446649\n"}, {"input": "308341796022\n", "output": "234 1317699983\n"}, {"input": "418335521569\n", "output": "119 3515424551\n"}, {"input": "904691688417\n", "output": "576747 1568611\n"}, {"input": "147869771841\n", "output": "314347 470403\n"}, {"input": "386752887969\n", "output": "147 2630972027\n"}, {"input": "629930971393\n", "output": "16938637 37189\n"}, {"input": "873109054817\n", "output": "5981551 145967\n"}, {"input": "111992170945\n", "output": "459005 243989\n"}, {"input": "355170254369\n", "output": "7 50738607767\n"}, {"input": "946248004555\n", "output": "1855 510106741\n"}, {"input": "185131120683\n", "output": "213 869160191\n"}, {"input": "432604171403\n", "output": "2083223 207661\n"}, {"input": "671487287531\n", "output": "389527 1723853\n"}, {"input": "914665370955\n", "output": "105 8711098771\n"}, {"input": "157843454379\n", "output": "382083 413113\n"}, {"input": "401021537803\n", "output": "583081 687763\n"}, {"input": "639904653932\n", "output": "1004 637355233\n"}, {"input": "878787770060\n", "output": "1274860 689321\n"}, {"input": "126260820780\n", "output": "22380 5641681\n"}, {"input": "713043603670\n", "output": "1056710 674777\n"}, {"input": "956221687094\n", "output": "1024054 933761\n"}, {"input": "199399770518\n", "output": "12662 15747889\n"}, {"input": "681460970070\n", "output": "910590 748373\n"}, {"input": "924639053494\n", "output": "598 1546219153\n"}, {"input": "167817136918\n", "output": "94606 1773853\n"}, {"input": "406700253046\n", "output": "2 203350126523\n"}, {"input": "645583369174\n", "output": "7222 89391217\n"}, {"input": "893056419894\n", "output": "102 8755455097\n"}, {"input": "484134170081\n", "output": "1186583 408007\n"}, {"input": "723017286209\n", "output": "528287 1368607\n"}, {"input": "966195369633\n", "output": "39 24774240247\n"}, {"input": "205078485761\n", "output": "185921 1103041\n"}, {"input": "452551536481\n", "output": "11 41141048771\n"}, {"input": "691434652609\n", "output": "1005947 687347\n"}, {"input": "934612736033\n", "output": "89 10501266697\n"}, {"input": "173495852161\n", "output": "1 173495852161\n"}, {"input": "416673935585\n", "output": "309655 1345607\n"}, {"input": "659852019009\n", "output": "2104677 313517\n"}, {"input": "287784545004\n", "output": "482119 596916\n"}, {"input": "526667661132\n", "output": "214836 2451487\n"}, {"input": "769845744556\n", "output": "1229116 626341\n"}, {"input": "8728860684\n", "output": "348 25082933\n"}, {"input": "256201911404\n", "output": "4 64050477851\n"}, {"input": "495085027532\n", "output": "53932 9179801\n"}, {"input": "738263110956\n", "output": "4956 148963501\n"}, {"input": "981441194380\n", "output": "438980 2235731\n"}, {"input": "220324310508\n", "output": "12 18360359209\n"}, {"input": "463502393932\n", "output": "2372 195405731\n"}, {"input": "54580144118\n", "output": "2 27290072059\n"}, {"input": "2038074743\n", "output": "1 2038074743\n"}, {"input": "252097800623\n", "output": "1 252097800623\n"}, {"input": "518649879439\n", "output": "1 518649879439\n"}, {"input": "963761198400\n", "output": "969408 994175\n"}] |
|
157 | Nikolay has a lemons, b apples and c pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits.
Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0.
-----Input-----
The first line contains the positive integer a (1 ≤ a ≤ 1000) — the number of lemons Nikolay has.
The second line contains the positive integer b (1 ≤ b ≤ 1000) — the number of apples Nikolay has.
The third line contains the positive integer c (1 ≤ c ≤ 1000) — the number of pears Nikolay has.
-----Output-----
Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.
-----Examples-----
Input
2
5
7
Output
7
Input
4
7
13
Output
21
Input
2
3
2
Output
0
-----Note-----
In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | interview | [{"code": "n1 = int( input() )\nn2 = int( input() )\nn3 = int( input() )\nprint( min( n1 , n2 // 2 , n3 // 4 ) * 7 )\n", "passed": true, "time": 0.2, "memory": 14496.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\ndef main():\n try:\n while True:\n a = int(input())\n b = int(input())\n c = int(input())\n x = min(a, b >> 1, c >> 2)\n print(x * 7)\n\n except EOFError:\n pass\n\nmain()\n", "passed": true, "time": 0.17, "memory": 14304.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())\nc = int(input())\nprint(7 * min(a, b // 2, c // 4))", "passed": true, "time": 2.07, "memory": 14444.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())\nc = int(input())\n\nm_a = a\nm_b = b // 2\nm_c = c // 4\nprint(min(m_a, m_b, m_c) * 7)\n", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "\na = int(input())\nb = int(input())\nc = int(input())\n\nans = 0\nfor x in range(a + 1):\n if (x * 2 > b or x * 4 > c):\n continue\n ans = max(ans, x + 2 * x + 4 * x)\nprint(ans)\n", "passed": true, "time": 0.28, "memory": 14456.0, "status": "done"}, {"code": "a, b, c = int(input()), int(input()), int(input())\nprint(min(a, b // 2, c // 4) * 7)", "passed": true, "time": 0.2, "memory": 14620.0, "status": "done"}, {"code": "a,b,c=[int(input()) for i in range(3)]\nprint(min(a,b//2,c//4)*7)\n", "passed": true, "time": 0.23, "memory": 14388.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())//2\nc = int(input())//4\nprint(7*min(a,min(b,c)))", "passed": true, "time": 0.15, "memory": 14476.0, "status": "done"}, {"code": "import sys\n\na = int(sys.stdin.readline())\nb = int(sys.stdin.readline())\nc = int(sys.stdin.readline())\n\nres = min([a, b // 2, c // 4])\nprint(7 * res)\n\n\n", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())\nc = int(input())\nprint(min(a, b//2, c//4) * 7)\n", "passed": true, "time": 0.16, "memory": 14564.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())\nc = int(input())\nper = min(a,b//2,c//4)\nprint(per*7)", "passed": true, "time": 0.27, "memory": 14448.0, "status": "done"}, {"code": "#CF1\na=int(input())\nb=int(input())\nc=int(input())\n#l=list(map(int,input()))\nn=min([a//1,b//2,c//4])\nprint(7*n)\n", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())\nc = int(input())\n\nprint(min(a, b//2, c//4)*7)\n", "passed": true, "time": 0.17, "memory": 14344.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())//2\nc = int(input())//4\nmn = min([a, b, c]) * 7\nprint(mn)", "passed": true, "time": 0.16, "memory": 14416.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())\nc = int(input())\n\nn = 0\nwhile n + 1 <= a and (n + 1) * 2 <= b and (n + 1) * 4 <= c:\n n += 1\n\nprint(7 * n)", "passed": true, "time": 0.15, "memory": 14372.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())//2\nc = int(input())//4\nprint(min([a,b,c])*7)\n", "passed": true, "time": 2.14, "memory": 14336.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())\nc = int(input())\n\nans = 0\nfor i in range(a + 1):\n if b >= i * 2 and c >= i * 4:\n ans = i * 7\nprint(ans)", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())\nc = int(input())\nans = 0\n\nwhile (a - 1 >= 0 and b - 2 >= 0 and c - 4 >= 0):\n a -= 1\n b -= 2\n c -= 4\n ans += 7\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14508.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())\nc = int(input())\nans = 0\nwhile a > 0 and b > 1 and c > 3:\n a -= 1\n b -= 2\n c -= 4\n ans += 7\nprint(ans)", "passed": true, "time": 0.15, "memory": 14592.0, "status": "done"}, {"code": "A = int(input())\nB = int(input())\nC = int(input())\n\nsol = 0\nfor a in range(1, A+1):\n if B >= a*2 and C >= a*4:\n sol = max(sol, 7*a)\n\nprint(sol)\n", "passed": true, "time": 0.21, "memory": 14404.0, "status": "done"}, {"code": "a,b,c = int(input()),int(input()),int(input())\n\nt = min(a, b//2, c//4)\n\nprint(t + t*2 + t*4)\n", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())\nc = int(input())\nfor i in range(1, 1000):\n if i <= a and i * 2 <= b and i * 4 <= c:\n continue\n else:\n break\nprint(i - 1 + (i - 1) * 2 + (i - 1) * 4)", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "l = int(input())\ny = int(input())\ng = int(input())\ncnt = 0\nwhile l >= 1 and y>=2 and g >=4:\n cnt+=7\n l-=1\n y-=2\n g-=4\nprint(cnt)", "passed": true, "time": 0.22, "memory": 14364.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\n# n = int(iunput())\n#\n# a, b = [int(i) for i in input().split()]\n#\n\na = int(input())\nb = int(input())\nc = int(input())\nmax_b = b//2\nmax_c = c//4\ndoli = min(a, max_b, max_c)\nkompot = doli *7\nprint (kompot)\n\n\t\t\n\t\n\n", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())\nc = int(input())\nres = 0\nwhile a - 1 >= 0 and b - 2 >= 0 and c - 4 >= 0:\n a -= 1\n b -= 2\n c -= 4\n res += 7\nprint(res)", "passed": true, "time": 0.18, "memory": 14520.0, "status": "done"}] | [{"input": "2\n5\n7\n", "output": "7\n"}, {"input": "4\n7\n13\n", "output": "21\n"}, {"input": "2\n3\n2\n", "output": "0\n"}, {"input": "1\n1\n1\n", "output": "0\n"}, {"input": "1\n2\n4\n", "output": "7\n"}, {"input": "1000\n1000\n1000\n", "output": "1750\n"}, {"input": "1\n1\n4\n", "output": "0\n"}, {"input": "1\n2\n3\n", "output": "0\n"}, {"input": "1\n1000\n1000\n", "output": "7\n"}, {"input": "1000\n1\n1000\n", "output": "0\n"}, {"input": "1000\n2\n1000\n", "output": "7\n"}, {"input": "1000\n500\n1000\n", "output": "1750\n"}, {"input": "1000\n1000\n4\n", "output": "7\n"}, {"input": "1000\n1000\n3\n", "output": "0\n"}, {"input": "4\n8\n12\n", "output": "21\n"}, {"input": "10\n20\n40\n", "output": "70\n"}, {"input": "100\n200\n399\n", "output": "693\n"}, {"input": "200\n400\n800\n", "output": "1400\n"}, {"input": "199\n400\n800\n", "output": "1393\n"}, {"input": "201\n400\n800\n", "output": "1400\n"}, {"input": "200\n399\n800\n", "output": "1393\n"}, {"input": "200\n401\n800\n", "output": "1400\n"}, {"input": "200\n400\n799\n", "output": "1393\n"}, {"input": "200\n400\n801\n", "output": "1400\n"}, {"input": "139\n252\n871\n", "output": "882\n"}, {"input": "109\n346\n811\n", "output": "763\n"}, {"input": "237\n487\n517\n", "output": "903\n"}, {"input": "161\n331\n725\n", "output": "1127\n"}, {"input": "39\n471\n665\n", "output": "273\n"}, {"input": "9\n270\n879\n", "output": "63\n"}, {"input": "137\n422\n812\n", "output": "959\n"}, {"input": "15\n313\n525\n", "output": "105\n"}, {"input": "189\n407\n966\n", "output": "1323\n"}, {"input": "18\n268\n538\n", "output": "126\n"}, {"input": "146\n421\n978\n", "output": "1022\n"}, {"input": "70\n311\n685\n", "output": "490\n"}, {"input": "244\n405\n625\n", "output": "1092\n"}, {"input": "168\n454\n832\n", "output": "1176\n"}, {"input": "46\n344\n772\n", "output": "322\n"}, {"input": "174\n438\n987\n", "output": "1218\n"}, {"input": "144\n387\n693\n", "output": "1008\n"}, {"input": "22\n481\n633\n", "output": "154\n"}, {"input": "196\n280\n848\n", "output": "980\n"}, {"input": "190\n454\n699\n", "output": "1218\n"}, {"input": "231\n464\n928\n", "output": "1617\n"}, {"input": "151\n308\n616\n", "output": "1057\n"}, {"input": "88\n182\n364\n", "output": "616\n"}, {"input": "12\n26\n52\n", "output": "84\n"}, {"input": "204\n412\n824\n", "output": "1428\n"}, {"input": "127\n256\n512\n", "output": "889\n"}, {"input": "224\n446\n896\n", "output": "1561\n"}, {"input": "146\n291\n584\n", "output": "1015\n"}, {"input": "83\n164\n332\n", "output": "574\n"}, {"input": "20\n38\n80\n", "output": "133\n"}, {"input": "198\n393\n792\n", "output": "1372\n"}, {"input": "120\n239\n480\n", "output": "833\n"}, {"input": "208\n416\n831\n", "output": "1449\n"}, {"input": "130\n260\n517\n", "output": "903\n"}, {"input": "67\n134\n267\n", "output": "462\n"}, {"input": "245\n490\n979\n", "output": "1708\n"}, {"input": "182\n364\n727\n", "output": "1267\n"}, {"input": "104\n208\n413\n", "output": "721\n"}, {"input": "10\n2\n100\n", "output": "7\n"}, {"input": "2\n100\n100\n", "output": "14\n"}, {"input": "2\n3\n8\n", "output": "7\n"}, {"input": "1\n2\n8\n", "output": "7\n"}, {"input": "1\n2\n200\n", "output": "7\n"}, {"input": "5\n4\n16\n", "output": "14\n"}, {"input": "1\n10\n10\n", "output": "7\n"}, {"input": "1\n4\n8\n", "output": "7\n"}, {"input": "100\n4\n1000\n", "output": "14\n"}, {"input": "2\n6\n12\n", "output": "14\n"}, {"input": "10\n7\n4\n", "output": "7\n"}, {"input": "2\n10\n100\n", "output": "14\n"}, {"input": "2\n3\n4\n", "output": "7\n"}, {"input": "1\n2\n999\n", "output": "7\n"}, {"input": "1\n10\n20\n", "output": "7\n"}, {"input": "100\n18\n20\n", "output": "35\n"}, {"input": "100\n1\n100\n", "output": "0\n"}, {"input": "3\n7\n80\n", "output": "21\n"}, {"input": "2\n8\n24\n", "output": "14\n"}, {"input": "1\n100\n100\n", "output": "7\n"}, {"input": "2\n1\n8\n", "output": "0\n"}, {"input": "10\n5\n23\n", "output": "14\n"}] |
|
158 | Berland annual chess tournament is coming!
Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins.
Every chess player has its rating r_{i}. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win.
After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random.
Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing?
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 100).
The second line contains 2·n integers a_1, a_2, ... a_2n (1 ≤ a_{i} ≤ 1000).
-----Output-----
If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO".
-----Examples-----
Input
2
1 3 2 4
Output
YES
Input
1
3 3
Output
NO | interview | [{"code": "n = int(input())\nz = list(map(int, input().split()))\nz.sort()\nif z[n - 1] < z[n]:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n \n", "passed": true, "time": 0.15, "memory": 14616.0, "status": "done"}, {"code": "n=int(input())\na=sorted(list(map(int,input().split())))\nprint('YES'if a[n-1]<a[n] else 'NO')\n", "passed": true, "time": 0.93, "memory": 14456.0, "status": "done"}, {"code": "n = int(input())\n\nnums = list(map(int, input().split()))\nnums = sorted(nums)\nif(nums[len(nums)//2 - 1] < nums[len(nums)//2]):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.24, "memory": 14472.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\n\nf = True\n\na.sort()\n\nif a[n] == a[n - 1]:\n f = False\n\nif f == True:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.15, "memory": 14492.0, "status": "done"}, {"code": "input()\na = sorted(map(int, input().split()))\n\nif a[len(a)//2 -1] < a[len(a)//2]:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.23, "memory": 14556.0, "status": "done"}, {"code": "n = int (input())\na = sorted([int(i) for i in input().split()])\nif a[n-1] < a[n]:\n print ('YES')\nelse:\n print ('NO')", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "n = int(input())\na = [int(i) for i in input().split()]\na.sort()\nif a[n] == a[n - 1]:\n\tprint('NO')\nelse:\n\tprint('YES')", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}, {"code": "n = int(input())\na = sorted(map(int, input().split()))\nprint('YES' if a[n] > a[n-1] else 'NO')", "passed": true, "time": 0.16, "memory": 14628.0, "status": "done"}, {"code": "n=int(input())\na=list(map(int ,input().strip().split(' ')))\na.sort()\nif a[n-1]<a[n]:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.16, "memory": 14468.0, "status": "done"}, {"code": "import sys, os\n\nn = int(input())\nn *= 2\ndata = list(map(int, input().split()))\ndata = sorted(data)\ndata1 = data[:n//2]\ndata2 = data[n//2:]\nfor i in range(n // 2):\n if data1[i] in data2:\n print(\"NO\")\n return\n sys.exit\n os.abort()\nprint(\"YES\")\n", "passed": true, "time": 0.22, "memory": 14492.0, "status": "done"}, {"code": "n = int(input())\n\na = list(map(int, input().split()))\n\na.sort()\n\nprint(\"YES\" if a[n] > a[n - 1] else \"NO\") \n", "passed": true, "time": 0.15, "memory": 14352.0, "status": "done"}, {"code": "\nn = int(input())\nplayers = list(map(int, input().split()))\n\nplayers.sort()\n\nif players[n] > players[n - 1]:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n", "passed": true, "time": 0.14, "memory": 14508.0, "status": "done"}, {"code": "n = int(input())\n\nl=[int(i) for i in input().split()]\n\nl.sort()\n\nif l[n]>l[n-1]:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.24, "memory": 14528.0, "status": "done"}, {"code": "n = int(input())\nar = list(map(int, input().split()))\nar.sort()\na = ar[:n]\nb = ar[n:]\nif len(set(a) & set(b)) == 0:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}, {"code": "n=int(input())\na=list(map(int, input().split()))\na.sort()\nif a[n-1]<a[n]:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.15, "memory": 14528.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\na.sort()\nif a[n - 1] == a[n]:\n print('NO')\nelse:\n print('YES')\n", "passed": true, "time": 0.14, "memory": 14592.0, "status": "done"}, {"code": "n = int(input())\na = [int(x) for x in input().split()]\nassert(len(a) == n+n)\n\na.sort()\nif a[n-1] < a[n]:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14604.0, "status": "done"}, {"code": "n = int(input())\nA = sorted([int(i) for i in input().split()])\nif A[n] > A[n-1]:\n print('YES')\nelse:\n print('NO')\n\n", "passed": true, "time": 0.15, "memory": 14344.0, "status": "done"}, {"code": "n = int(input())\nl = sorted(map(int, input().split()))\n\nprint(['NO', 'YES'][l[n] > l[n-1]])\n", "passed": true, "time": 0.14, "memory": 14516.0, "status": "done"}, {"code": "n = int(input())\ndata = list(map(int, input().split()))\ndata.sort()\nif n == 1 and data[0] == data[1] or data[0] == data[-1] or data[n] == data[n - 1]:\n print('NO')\nelse:\n print('YES')\n", "passed": true, "time": 0.15, "memory": 14320.0, "status": "done"}, {"code": "def main():\n nbEquipe=int(input())\n liste=list(map(int,input().split()))\n liste.sort()\n if(liste[nbEquipe]>liste[nbEquipe-1]):\n print(\"YES\")\n else:\n print(\"NO\")\nmain()\n \n", "passed": true, "time": 0.14, "memory": 14528.0, "status": "done"}, {"code": "# A. Chess Tourney\n\nn = int(input())\nr = list(map(int, input().split()))\n\nr = sorted(r)\n\nf, s = min(r[n:]), max(r[:n])\n\nif f > s:\n\tprint('YES')\nelse:\n\tprint('NO')\n", "passed": true, "time": 0.24, "memory": 14328.0, "status": "done"}, {"code": "n=int(input())\na=[int(i) for i in input().split()]\na=sorted(a)\nb=a[:int(len(a)/2)]\nc=a[int(len(a)/2):]\nif(c[0]>b[len(b)-1]):\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "n = int(input())\na = list(sorted(list(map(int, input().split())), reverse=True))\n\nif min(a[:n]) > max(a[n:]):\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\na.sort()\nif a[n - 1] == a[n]:\n print(\"NO\")\nelse:\n print(\"YES\")\n", "passed": true, "time": 0.15, "memory": 14616.0, "status": "done"}] | [{"input": "2\n1 3 2 4\n", "output": "YES\n"}, {"input": "1\n3 3\n", "output": "NO\n"}, {"input": "5\n1 1 1 1 2 2 3 3 3 3\n", "output": "NO\n"}, {"input": "5\n1 1 1 1 1 2 2 2 2 2\n", "output": "YES\n"}, {"input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n", "output": "NO\n"}, {"input": "1\n2 3\n", "output": "YES\n"}, {"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "NO\n"}, {"input": "35\n919 240 231 858 456 891 959 965 758 30 431 73 505 694 874 543 975 445 16 147 904 690 940 278 562 127 724 314 30 233 389 442 353 652 581 383 340 445 487 283 85 845 578 946 228 557 906 572 919 388 686 181 958 955 736 438 991 170 632 593 475 264 178 344 159 414 739 590 348 884\n", "output": "YES\n"}, {"input": "5\n1 2 3 4 10 10 6 7 8 9\n", "output": "YES\n"}, {"input": "2\n1 1 1 2\n", "output": "NO\n"}, {"input": "2\n10 4 4 4\n", "output": "NO\n"}, {"input": "2\n2 3 3 3\n", "output": "NO\n"}, {"input": "4\n1 2 3 4 5 4 6 7\n", "output": "NO\n"}, {"input": "4\n2 5 4 5 8 3 1 5\n", "output": "YES\n"}, {"input": "4\n8 2 2 4 1 4 10 9\n", "output": "NO\n"}, {"input": "2\n3 8 10 2\n", "output": "YES\n"}, {"input": "3\n1 3 4 4 5 6\n", "output": "NO\n"}, {"input": "2\n3 3 3 4\n", "output": "NO\n"}, {"input": "2\n1 1 2 2\n", "output": "YES\n"}, {"input": "2\n1 1 3 3\n", "output": "YES\n"}, {"input": "2\n1 2 3 2\n", "output": "NO\n"}, {"input": "10\n1 2 7 3 9 4 1 5 10 3 6 1 10 7 8 5 7 6 1 4\n", "output": "NO\n"}, {"input": "3\n1 2 3 3 4 5\n", "output": "NO\n"}, {"input": "2\n2 2 1 1\n", "output": "YES\n"}, {"input": "7\n1 2 3 4 5 6 7 7 8 9 10 11 12 19\n", "output": "NO\n"}, {"input": "5\n1 2 3 4 5 3 3 5 6 7\n", "output": "YES\n"}, {"input": "4\n1 1 2 2 3 3 3 3\n", "output": "YES\n"}, {"input": "51\n576 377 63 938 667 992 959 997 476 94 652 272 108 410 543 456 942 800 917 163 931 584 357 890 895 318 544 179 268 130 649 916 581 350 573 223 495 26 377 695 114 587 380 424 744 434 332 249 318 522 908 815 313 384 981 773 585 747 376 812 538 525 997 896 859 599 437 163 878 14 224 733 369 741 473 178 153 678 12 894 630 921 505 635 128 404 64 499 208 325 343 996 970 39 380 80 12 756 580 57 934 224\n", "output": "YES\n"}, {"input": "3\n3 3 3 2 3 2\n", "output": "NO\n"}, {"input": "2\n5 3 3 6\n", "output": "YES\n"}, {"input": "2\n1 2 2 3\n", "output": "NO\n"}, {"input": "2\n1 3 2 2\n", "output": "NO\n"}, {"input": "2\n1 3 3 4\n", "output": "NO\n"}, {"input": "2\n1 2 2 2\n", "output": "NO\n"}, {"input": "3\n1 2 7 19 19 7\n", "output": "NO\n"}, {"input": "3\n1 2 3 3 5 6\n", "output": "NO\n"}, {"input": "2\n1 2 2 4\n", "output": "NO\n"}, {"input": "2\n6 6 5 5\n", "output": "YES\n"}, {"input": "2\n3 1 3 1\n", "output": "YES\n"}, {"input": "3\n1 2 3 3 1 1\n", "output": "YES\n"}, {"input": "3\n3 2 1 3 4 5\n", "output": "NO\n"}, {"input": "3\n4 5 6 4 2 1\n", "output": "NO\n"}, {"input": "3\n1 1 2 3 2 4\n", "output": "NO\n"}, {"input": "3\n100 99 1 1 1 1\n", "output": "NO\n"}, {"input": "3\n1 2 3 6 5 3\n", "output": "NO\n"}, {"input": "2\n2 2 1 2\n", "output": "NO\n"}, {"input": "4\n1 2 3 4 5 6 7 4\n", "output": "NO\n"}, {"input": "3\n1 2 3 1 1 1\n", "output": "NO\n"}, {"input": "3\n6 5 3 3 1 3\n", "output": "NO\n"}, {"input": "2\n1 2 1 2\n", "output": "YES\n"}, {"input": "3\n1 2 5 6 8 6\n", "output": "YES\n"}, {"input": "5\n1 2 3 4 5 3 3 3 3 3\n", "output": "NO\n"}, {"input": "2\n1 2 4 2\n", "output": "NO\n"}, {"input": "3\n7 7 4 5 319 19\n", "output": "NO\n"}, {"input": "3\n1 2 4 4 3 5\n", "output": "YES\n"}, {"input": "3\n3 2 3 4 5 2\n", "output": "NO\n"}, {"input": "5\n1 2 3 4 4 5 3 6 7 8\n", "output": "NO\n"}, {"input": "3\n3 3 4 4 5 1\n", "output": "YES\n"}, {"input": "2\n3 4 3 3\n", "output": "NO\n"}, {"input": "2\n2 5 4 4\n", "output": "NO\n"}, {"input": "5\n1 2 3 3 4 5 6 7 8 4\n", "output": "NO\n"}, {"input": "3\n1 2 3 3 5 5\n", "output": "NO\n"}, {"input": "2\n3 4 4 4\n", "output": "NO\n"}, {"input": "2\n1 4 5 4\n", "output": "NO\n"}, {"input": "2\n1 2 3 3\n", "output": "YES\n"}, {"input": "2\n1 1 2 1\n", "output": "NO\n"}, {"input": "4\n1 1 1 1 2 2 2 2\n", "output": "YES\n"}, {"input": "4\n1 2 3 5 6 7 8 5\n", "output": "NO\n"}, {"input": "2\n4 3 3 1\n", "output": "NO\n"}, {"input": "3\n3 1 2 4 3 5\n", "output": "NO\n"}, {"input": "3\n1 2 3 3 4 6\n", "output": "NO\n"}, {"input": "4\n2 2 2 4 5 5 5 5\n", "output": "YES\n"}, {"input": "2\n1 3 4 3\n", "output": "NO\n"}, {"input": "2\n3 3 2 3\n", "output": "NO\n"}, {"input": "2\n1 2 1 1\n", "output": "NO\n"}, {"input": "3\n1 3 4 4 2 5\n", "output": "YES\n"}, {"input": "4\n4 7 1 2 3 5 6 4\n", "output": "NO\n"}, {"input": "2\n3 2 2 2\n", "output": "NO\n"}, {"input": "1\n2 1\n", "output": "YES\n"}, {"input": "2\n3 3 1 2\n", "output": "YES\n"}, {"input": "1\n8 6\n", "output": "YES\n"}, {"input": "7\n6 7 6 7 3 1 9 4 6 10 8 2 5 7\n", "output": "NO\n"}, {"input": "2\n3 9 2 1\n", "output": "YES\n"}, {"input": "2\n3 3 3 3\n", "output": "NO\n"}] |
|
159 | You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 10^9 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.
The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the elements of the array a.
-----Output-----
Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers a_{j} — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array a by adding k elements to it.
If there are multiple answers you can print any one of them.
-----Example-----
Input
3
2 7 28
Output
1
2 7 9 28 | interview | [{"code": "n = int(input())\na = [int(i) for i in input().split()]\nc = 0\ni = 0\nwhile i < n - 1:\n x = a[i]\n y = a[i + 1]\n while y > 0:\n x, y = y, x % y\n if x > 1:\n a = a[:i + 1] + [1] + a[i + 1:]\n i += 2\n c += 1\n n += 1\n else:\n i += 1\nprint(c)\nprint(*a)", "passed": true, "time": 0.15, "memory": 14616.0, "status": "done"}, {"code": "def mp(): return list(map(int,input().split()))\ndef lt(): return list(map(int,input().split()))\ndef pt(x): print(x)\ndef ip(): return input()\ndef it(): return int(input())\ndef sl(x): return [t for t in x]\ndef spl(x): return x.split()\ndef aj(liste, item): liste.append(item)\ndef bin(x): return \"{0:b}\".format(x)\n\nn = it()\nL = lt()\ndef gcd(x,y):\n if x % y == 0:\n return y\n else:\n return gcd(y,x%y)\nc = 0\ni = 0\nwhile i+1 < len(L):\n d = gcd(L[i],L[i+1])\n if d != 1:\n L.insert(i+1,1)\n c += 1\n i += 1\nprint(c)\nprint(' '.join([str(x) for x in L]))\n \n", "passed": true, "time": 0.14, "memory": 14664.0, "status": "done"}, {"code": "def gcd(a, b):\n if b == 0: return a\n else: return gcd(b, a % b)\ndef __starting_point():\n n = int(input())\n A = list(map(int, input().split()))\n ans, cnt = [A[0]], 0\n for i in range(1, n):\n if gcd(A[i], A[i - 1]) != 1:\n ans.append(1)\n cnt += 1\n ans.append(A[i])\n print(cnt)\n print(' '.join(str(i) for i in ans)) \n__starting_point()", "passed": true, "time": 0.15, "memory": 14352.0, "status": "done"}, {"code": "n = int(input())\na = [int(s) for s in input().split()]\n\ndef evklid(a, b):\n while a!=0 and b!=0:\n if a > b:\n a = a % b\n else:\n b = b % a\n return a + b\n\n\ns = ''\nk = 0\ns += str(a[0])\nfor i in range(1, n):\n if evklid(a[i], a[i-1]) != 1:\n k += 1\n s += ' 1 ' + str(a[i])\n else:\n s += ' ' + str(a[i])\nprint(k)\nprint(s)\n", "passed": true, "time": 0.15, "memory": 14576.0, "status": "done"}, {"code": "def prost(a, b):\n\ta, b = max(a, b), min(a,b)\n\twhile b!=0:\n\t\ta = a%b\n\t\ta, b = b, a\n\tif a==1:\n\t\treturn (0)\n\telse:\n\t\treturn (1)\n\nn = int(input())\ns = input().split()\nk = 0\nfor i in range(len(s)-1):\n\tif prost(int(s[i]), int(s[i+1]))==1: \n\t\ts[i] = s[i] + ' ' + '1'\n\t\tk = k+1\nprint (k)\nprint (' '.join(x for x in s))", "passed": true, "time": 0.19, "memory": 14404.0, "status": "done"}, {"code": "input()\n\n\ndef nod(a, b):\n while b:\n a, b = b, a % b\n return a\n\n\ndef main():\n a = list(map(int, input().split()))\n out = []\n k = 0\n for i in range(0, len(a)-1):\n out.append(a[i])\n if nod(a[i], a[i+1]) != 1:\n out.append(1)\n k += 1\n out.append(a[len(a)-1])\n str_out = \" \".join(map(str, out))\n print(k)\n print(str_out)\n\nmain()\n", "passed": true, "time": 0.15, "memory": 14592.0, "status": "done"}, {"code": "from math import gcd\n\nn = int(input())\narr = list(map(int, input().split(' ')))\narr2 = []\n\nfor i in range(len(arr)-1):\n if not gcd(arr[i], arr[i+1]) == 1:\n #print (arr[i], arr[i+1], gcd(arr[i], arr[i+1]))\n arr2.append(str(arr[i]))\n arr2.append(str(1))\n else:\n arr2.append(str(arr[i]))\n\narr2.append(str(arr[-1]))\n\nprint(len(arr2)-len(arr))\nprint(' '.join(arr2))\n", "passed": true, "time": 0.94, "memory": 14484.0, "status": "done"}, {"code": "def gcd(x, y):\n if x < y:\n t = x\n x = y\n y = t\n if x%y == 0:\n return y\n else:\n return gcd(y, x%y)\n\nn = int(input())\na = input().split()\nfor i in range(n):\n a[i] = int(a[i])\nb = [a[0]]\nk = 0\nfor i in range(1, n):\n if gcd(a[i-1], a[i]) != 1:\n b.append(1)\n k += 1\n b.append(a[i])\ns = str(b[0])\nfor i in range(1, len(b)):\n s += ' ' + str(b[i])\nprint(k)\nprint(s)\n", "passed": true, "time": 0.15, "memory": 14408.0, "status": "done"}, {"code": "n=int(input())\nl=list(map(int,input().split()))\nans=[str(l[0])]\ndef gcd(a,b): \n while b: a,b=b,a%b\n return a\nfor i in range(1,n): \n if gcd(l[i],l[i-1])>1: ans+=[\"1\"]\n ans+=[str(l[i])]\nprint(len(ans)-n)\nprint(' '.join(ans))", "passed": true, "time": 0.15, "memory": 14632.0, "status": "done"}, {"code": "n = int(input())\nmass = list(map(int, input().split()))\n\ndef gcd(a, b):\n if b:\n return(gcd(b, a % b))\n else:\n return a\n\n#def add(a, b):\n #k = 1\n #while gcd(k, a) != 1\n#print(tmp_mass)\ni = 0\nc = len(mass)\ncount = 0\nwhile i < c - 1:\n #print(i, c)\n k = gcd(mass[i], mass[i + 1])\n if k == 1:\n i+= 1\n continue\n else:\n count += 1\n mass.insert(i+1, 1)\n c += 1\n i += 2\nprint(count)\nprint(' '.join(map(str, mass)))\n", "passed": true, "time": 0.14, "memory": 14532.0, "status": "done"}, {"code": "n = int(input())\nmass = list(map(int, input().split()))\n\ndef gcd(a, b):\n if b:\n return(gcd(b, a % b))\n else:\n return a\ni = 0\nc = len(mass)\ncount = 0\nwhile i < c - 1:\n k = gcd(mass[i], mass[i + 1])\n if k == 1:\n i+= 1\n continue\n else:\n count += 1\n mass.insert(i+1, 1)\n c += 1\n i += 2\nprint(count)\nprint(' '.join(map(str, mass)))\n", "passed": true, "time": 0.15, "memory": 14600.0, "status": "done"}, {"code": "import math\nans=[]\ncount=0\nn=int(input())\na=list(map(int,input().split()))\nif n==1:\n print(0)\n print(a[0])\n return\n \n\nfor i in range(n-1):\n ans.append(str(a[i]))\n if math.gcd(a[i],a[i+1])!=1:\n count +=1\n ans.append('1')\n\n\nans.append(str(a[i+1]))\nprint(count)\nprint(' '.join(ans))\n\n\n \n\n", "passed": true, "time": 0.14, "memory": 14580.0, "status": "done"}, {"code": "\n\n\ndef gcd(x, y):\n if y == 0:\n return x\n return gcd(y, x % y)\n \n \nn = int(input())\n\na = list(map(int, input().split()))\n\n\nlast = 1\nans = []\n\nfor i in range(n):\n if gcd(a[i], last) != 1:\n ans.append(1)\n ans.append(a[i])\n last = a[i]\n\n\nprint(len(ans) - n)\n\nfor i in range(len(ans) - 1):\n print(ans[i], end = ' ')\n\n\nprint(ans[len(ans) - 1])\n\n\n\n\n \n \n\n\n\n\n", "passed": true, "time": 0.15, "memory": 14652.0, "status": "done"}, {"code": "def gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a % b)\n\n\ndef main():\n n = int(input())\n a = [int(x) for x in input().split()]\n\n b = [a[0]]\n for i in range(1, n):\n if gcd(a[i - 1], a[i]) != 1:\n b.append(1)\n b.append(a[i])\n\n print(len(b) - n)\n print(\" \".join(map(str, b)))\n\n\nmain()", "passed": true, "time": 0.15, "memory": 14468.0, "status": "done"}] | [{"input": "3\n2 7 28\n", "output": "1\n2 7 1 28\n"}, {"input": "1\n1\n", "output": "0\n1\n"}, {"input": "1\n548\n", "output": "0\n548\n"}, {"input": "1\n963837006\n", "output": "0\n963837006\n"}, {"input": "10\n1 1 1 1 1 1 1 1 1 1\n", "output": "0\n1 1 1 1 1 1 1 1 1 1\n"}, {"input": "10\n26 723 970 13 422 968 875 329 234 983\n", "output": "2\n26 723 970 13 422 1 968 875 1 329 234 983\n"}, {"input": "10\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396\n", "output": "7\n319645572 1 758298525 1 812547177 1 459359946 1 355467212 1 304450522 807957797 916787906 1 239781206 1 242840396\n"}, {"input": "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1\n", "output": "19\n1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1\n"}, {"input": "100\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917\n", "output": "38\n591 1 417 1 888 251 792 1 847 685 3 182 461 102 1 348 1 555 956 771 901 712 1 878 1 580 631 342 1 333 1 285 899 525 1 725 537 718 929 653 84 1 788 1 104 355 624 803 1 253 853 201 995 536 1 184 65 1 205 1 540 1 652 549 1 777 248 405 677 950 431 580 1 600 1 846 1 328 429 134 983 526 103 500 963 400 23 1 276 1 704 1 570 757 410 1 658 507 620 1 984 1 244 1 486 1 454 1 802 411 985 303 635 283 96 1 597 1 855 1 775 139 839 1 839 61 219 986 1 776 1 72 1 729 1 69 20 917\n"}, {"input": "5\n472882027 472882027 472882027 472882027 472882027\n", "output": "4\n472882027 1 472882027 1 472882027 1 472882027 1 472882027\n"}, {"input": "2\n1000000000 1000000000\n", "output": "1\n1000000000 1 1000000000\n"}, {"input": "2\n8 6\n", "output": "1\n8 1 6\n"}, {"input": "3\n100000000 1000000000 1000000000\n", "output": "2\n100000000 1 1000000000 1 1000000000\n"}, {"input": "5\n1 2 3 4 5\n", "output": "0\n1 2 3 4 5\n"}, {"input": "20\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000\n", "output": "19\n2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000\n"}, {"input": "2\n223092870 23\n", "output": "1\n223092870 1 23\n"}, {"input": "2\n100000003 100000003\n", "output": "1\n100000003 1 100000003\n"}, {"input": "2\n999999937 999999937\n", "output": "1\n999999937 1 999999937\n"}, {"input": "4\n999 999999937 999999937 999\n", "output": "1\n999 999999937 1 999999937 999\n"}, {"input": "2\n999999929 999999929\n", "output": "1\n999999929 1 999999929\n"}, {"input": "2\n1049459 2098918\n", "output": "1\n1049459 1 2098918\n"}, {"input": "2\n352229 704458\n", "output": "1\n352229 1 704458\n"}, {"input": "2\n7293 4011\n", "output": "1\n7293 1 4011\n"}, {"input": "2\n5565651 3999930\n", "output": "1\n5565651 1 3999930\n"}, {"input": "2\n997 997\n", "output": "1\n997 1 997\n"}, {"input": "3\n9994223 9994223 9994223\n", "output": "2\n9994223 1 9994223 1 9994223\n"}, {"input": "2\n99999998 1000000000\n", "output": "1\n99999998 1 1000000000\n"}, {"input": "3\n1000000000 1000000000 1000000000\n", "output": "2\n1000000000 1 1000000000 1 1000000000\n"}, {"input": "2\n130471 130471\n", "output": "1\n130471 1 130471\n"}, {"input": "3\n1000000000 2 2\n", "output": "2\n1000000000 1 2 1 2\n"}, {"input": "2\n223092870 66526\n", "output": "1\n223092870 1 66526\n"}, {"input": "14\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491 436077930 570018449\n", "output": "10\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491 436077930 1 570018449\n"}, {"input": "2\n3996017 3996017\n", "output": "1\n3996017 1 3996017\n"}, {"input": "2\n999983 999983\n", "output": "1\n999983 1 999983\n"}, {"input": "2\n618575685 773990454\n", "output": "1\n618575685 1 773990454\n"}, {"input": "3\n9699690 3 7\n", "output": "1\n9699690 1 3 7\n"}, {"input": "2\n999999999 999999996\n", "output": "1\n999999999 1 999999996\n"}, {"input": "2\n99999910 99999910\n", "output": "1\n99999910 1 99999910\n"}, {"input": "12\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491\n", "output": "9\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491\n"}, {"input": "3\n999999937 999999937 999999937\n", "output": "2\n999999937 1 999999937 1 999999937\n"}, {"input": "2\n99839 99839\n", "output": "1\n99839 1 99839\n"}, {"input": "3\n19999909 19999909 19999909\n", "output": "2\n19999909 1 19999909 1 19999909\n"}, {"input": "4\n1 1000000000 1 1000000000\n", "output": "0\n1 1000000000 1 1000000000\n"}, {"input": "2\n64006 64006\n", "output": "1\n64006 1 64006\n"}, {"input": "2\n1956955 1956955\n", "output": "1\n1956955 1 1956955\n"}, {"input": "3\n1 1000000000 1000000000\n", "output": "1\n1 1000000000 1 1000000000\n"}, {"input": "2\n982451707 982451707\n", "output": "1\n982451707 1 982451707\n"}, {"input": "2\n999999733 999999733\n", "output": "1\n999999733 1 999999733\n"}, {"input": "3\n999999733 999999733 999999733\n", "output": "2\n999999733 1 999999733 1 999999733\n"}, {"input": "2\n3257 3257\n", "output": "1\n3257 1 3257\n"}, {"input": "2\n223092870 181598\n", "output": "1\n223092870 1 181598\n"}, {"input": "3\n959919409 105935 105935\n", "output": "2\n959919409 1 105935 1 105935\n"}, {"input": "2\n510510 510510\n", "output": "1\n510510 1 510510\n"}, {"input": "3\n223092870 1000000000 1000000000\n", "output": "2\n223092870 1 1000000000 1 1000000000\n"}, {"input": "14\n1000000000 2 1000000000 3 1000000000 6 1000000000 1000000000 15 1000000000 1000000000 1000000000 100000000 1000\n", "output": "11\n1000000000 1 2 1 1000000000 3 1000000000 1 6 1 1000000000 1 1000000000 1 15 1 1000000000 1 1000000000 1 1000000000 1 100000000 1 1000\n"}, {"input": "7\n1 982451653 982451653 1 982451653 982451653 982451653\n", "output": "3\n1 982451653 1 982451653 1 982451653 1 982451653 1 982451653\n"}, {"input": "2\n100000007 100000007\n", "output": "1\n100000007 1 100000007\n"}, {"input": "3\n999999757 999999757 999999757\n", "output": "2\n999999757 1 999999757 1 999999757\n"}, {"input": "3\n99999989 99999989 99999989\n", "output": "2\n99999989 1 99999989 1 99999989\n"}, {"input": "5\n2 4 982451707 982451707 3\n", "output": "2\n2 1 4 982451707 1 982451707 3\n"}, {"input": "2\n20000014 20000014\n", "output": "1\n20000014 1 20000014\n"}, {"input": "2\n99999989 99999989\n", "output": "1\n99999989 1 99999989\n"}, {"input": "2\n111546435 111546435\n", "output": "1\n111546435 1 111546435\n"}, {"input": "2\n55288874 33538046\n", "output": "1\n55288874 1 33538046\n"}, {"input": "5\n179424673 179424673 179424673 179424673 179424673\n", "output": "4\n179424673 1 179424673 1 179424673 1 179424673 1 179424673\n"}, {"input": "2\n199999978 199999978\n", "output": "1\n199999978 1 199999978\n"}, {"input": "2\n1000000000 2\n", "output": "1\n1000000000 1 2\n"}, {"input": "3\n19999897 19999897 19999897\n", "output": "2\n19999897 1 19999897 1 19999897\n"}, {"input": "2\n19999982 19999982\n", "output": "1\n19999982 1 19999982\n"}, {"input": "2\n10000007 10000007\n", "output": "1\n10000007 1 10000007\n"}, {"input": "3\n999999937 999999937 2\n", "output": "1\n999999937 1 999999937 2\n"}, {"input": "5\n2017 2017 2017 2017 2017\n", "output": "4\n2017 1 2017 1 2017 1 2017 1 2017\n"}, {"input": "2\n19999909 39999818\n", "output": "1\n19999909 1 39999818\n"}, {"input": "2\n62615533 7919\n", "output": "1\n62615533 1 7919\n"}, {"input": "5\n39989 39989 33 31 29\n", "output": "1\n39989 1 39989 33 31 29\n"}, {"input": "2\n1000000000 100000\n", "output": "1\n1000000000 1 100000\n"}, {"input": "2\n1938 10010\n", "output": "1\n1938 1 10010\n"}, {"input": "2\n199999 199999\n", "output": "1\n199999 1 199999\n"}, {"input": "2\n107273 107273\n", "output": "1\n107273 1 107273\n"}, {"input": "3\n49999 49999 49999\n", "output": "2\n49999 1 49999 1 49999\n"}, {"input": "2\n1999966 1999958\n", "output": "1\n1999966 1 1999958\n"}, {"input": "2\n86020 300846\n", "output": "1\n86020 1 300846\n"}, {"input": "2\n999999997 213\n", "output": "1\n999999997 1 213\n"}, {"input": "2\n200000014 200000434\n", "output": "1\n200000014 1 200000434\n"}] |
|
160 | We have a sequence of N integers: A_1, A_2, \cdots, A_N.
You can perform the following operation between 0 and K times (inclusive):
- Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly producing a negative element.
Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz.
-----Constraints-----
- 2 \leq N \leq 500
- 1 \leq A_i \leq 10^6
- 0 \leq K \leq 10^9
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
N K
A_1 A_2 \cdots A_{N-1} A_{N}
-----Output-----
Print the maximum possible positive integer that divides every element of A after the operations.
-----Sample Input-----
2 3
8 20
-----Sample Output-----
7
7 will divide every element of A if, for example, we perform the following operation:
- Choose i = 2, j = 1. A becomes (7, 21).
We cannot reach the situation where 8 or greater integer divides every element of A. | interview | [{"code": "# \u5272\u308a\u5207\u308b\u6570\u306f\u3001A\u306e\u7dcf\u548c\u306e\u7d04\u6570\u3067\u3042\u308b\n# \u81ea\u5206\u81ea\u8eab\u3092\u9664\u304f\u7d04\u6570\u306b\u3064\u3044\u3066\u5927\u304d\u3044\u9806\u306b\u3059\u3079\u3066\u8a66\u3057\u3066\u3001\u5f53\u3066\u306f\u307e\u308b\u3082\u306e\u304c\u3042\u308c\u3070\u7b54\u3048\n\n# 8,20\u30927\u306e\u500d\u6570\u306b\u8fd1\u3065\u3051\u308b\u3068\u304d\u3001\n# 8 -> mod 7\u304c1\u3067\u3042\u308a\u3001-1\u304b+6\u30677\u306e\u500d\u6570\u306b\u306a\u308b\n# 20 -> mod 7\u304c6\u3067\u3042\u308a\u3001-6\u304b+1\u30677\u306e\u500d\u6570\u306b\u306a\u308b\n# -1\u3068+1\u3092\u30da\u30a2\u306b\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u3066\u3001\u3053\u306e\u64cd\u4f5c\u56de\u65701\u3092K = 3\u304b\u3089\u5f15\u304f\u30682\u3068\u306a\u308a\u3001\u3053\u308c\u304c\u5076\u6570\u306a\u3089OK\n\nimport sys\nreadline = sys.stdin.readline\n\nN,K = map(int,readline().split())\nA = list(map(int,readline().split()))\n\nall = sum(A)\ndivisors = []\nfor i in range(1,int(all ** 0.5) + 1):\n if all % i == 0:\n divisors.append(i)\n divisors.append(all // i)\n\ndivisors = sorted(divisors,reverse = True)\n\n#print(divisors)\n\nfor d in divisors:\n mods = [0] * (N)\n for i in range(len(A)):\n mods[i] = A[i] % d\n mods = sorted(mods)\n #print(\"d\",d,\"mods\",mods)\n mods_front = [0] * N\n mods_front[0] = mods[0]\n for i in range(1,N):\n mods_front[i] = mods_front[i - 1] + mods[i]\n mods_back = [0] * N\n mods_back[-1] = d - mods[-1]\n #print(\"mods_front\",mods_front)\n for i in range(N - 2,-1,-1):\n mods_back[i] = mods_back[i + 1] + (d - mods[i])\n #print(\"mods_back\",mods_back)\n for i in range(N - 1):\n if mods_front[i] == mods_back[i + 1]:\n if K >= min(mods_front[i],mods_back[i + 1]):\n print(d)\n return\nelse:\n print(1)", "passed": true, "time": 2.97, "memory": 15076.0, "status": "done"}, {"code": "from math import sqrt\n\ndef Divisor_Set(n):\n s = set()\n for i in range(1, int(sqrt(n))+2):\n if n%i == 0:\n s.add(i)\n s.add(n//i)\n return s\n\ndef main():\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n a_sum = sum(a)\n st = Divisor_Set(a_sum)\n ans = 1\n st.remove(1)\n for v in st:\n b = [x%v for x in a]\n b.sort()\n for i in range(n-1):\n b[i+1] += b[i]\n for i in range(n-1):\n if b[i] == v*(n-i-1) - (b[-1] - b[i]):\n if b[i] <= k and ans < v:\n ans = v\n print(ans)\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 3.34, "memory": 14936.0, "status": "done"}, {"code": "\nN, K = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\ns = sum(A)\n\n\n\ndef solve():\n ans = 1\n idx = 1\n\n while idx * idx <= s:\n if s % idx == 0:\n if ok(s // idx):\n return s // idx\n if ok(idx):\n ans = idx\n idx += 1\n\n return ans\n\n\ndef ok(i):\n D = list([x for x in [a % i for a in A] if x != 0])\n D.sort()\n\n l = len(D)\n\n S = [0] * (l + 1)\n for j in range(l):\n S[j + 1] = S[j] + D[j]\n\n for j in range(l):\n if S[j] == i * (l - j) - (S[l] - S[j]) and S[j] <= K:\n return True\n\n return False\n\n\nprint((solve()))\n", "passed": true, "time": 1.43, "memory": 14952.0, "status": "done"}, {"code": "def divisor(n):\n res = []\n i = 1\n while i*i <= n:\n if n%i == 0:\n res.append(i)\n if i*i != n:\n res.append(n//i)\n i += 1\n res.sort()\n return res\n\nN, K = list(map(int, input().split()))\nA = list(map(int, input().split()))\nS = sum(A)\nans = 1\nfor d in divisor(S):\n rs = [a%d for a in A]\n rs.sort()\n Sum = [0]*(N+1)\n Sum2 = [0]*(N+1)\n for i in range(1,N+1):\n Sum[i] = Sum[i-1]+rs[i-1]\n Sum2[i] = Sum2[i-1]+(d-rs[i-1])\n for i in range(N+1):\n if Sum[i] == Sum2[N]-Sum2[i]:\n if Sum[i] <= K:\n ans = d\nprint(ans)\n", "passed": true, "time": 3.48, "memory": 14924.0, "status": "done"}, {"code": "def max2(x,y):\n return x if x > y else y\n\ndef divisors(n):\n i = 1\n table = set()\n while i * i <= n:\n if not n % i:\n table.add(i)\n table.add(n//i)\n i += 1\n table = list(table)\n return table\n\nimport sys\ninput = sys.stdin.readline\n\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\nS = sum(A)\nD = divisors(S)\nD.sort()\nres = 0\nfor k in D:\n B = []\n for a in A:\n B.append(a%k)\n B.sort()\n cnt = sum(B)//k\n if k*cnt - sum(B[-cnt:]) <= K:\n res = max2(res, k)\n\nprint(res)", "passed": true, "time": 0.81, "memory": 14896.0, "status": "done"}, {"code": "from copy import copy, deepcopy\n# from functools import reduce\n# from heapq import heapify, heappop, heappush\n# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product\nimport unittest\nfrom io import StringIO\nimport math\n# import numpy as np # Python\u306e\u307f\uff01\n# from operator import xor\n# import re\n# from scipy.sparse.csgraph import connected_components # Python\u306e\u307f\uff01\n# \u2191cf. https://note.nkmk.me/python-scipy-connected-components/\n# from scipy.sparse import csr_matrix\n# import string\nimport sys\nsys.setrecursionlimit(10 ** 5 + 10)\n\n\ndef input(): return sys.stdin.readline().strip()\n\n\ndef resolve():\n N, K = map(int, input().split())\n A = list(map(int, input().split()))\n\n def make_divisors(n):\n divisors = []\n for i in range(1, int(n**0.5)+1):\n if n % i == 0:\n divisors.append(i)\n if i != n // i: # \u5e73\u65b9\u6570\u306e\u5834\u5408n**0.5\u30921\u3064\u3060\u3051\u306b\u3057\u3066\u308b\n divisors.append(n//i)\n\n divisors.sort(reverse=True) # \u30bd\u30fc\u30c8\u3057\u305f\u3051\u308a\u3083\u3057\u3066\n return divisors\n\n M = make_divisors(sum(A))\n\n def main():\n for i in M:\n AA = [0]*N\n age = 0\n # delete = 0\n for j in range(N):\n AA[j] = A[j] % i\n #if AA[j] == 0:\n # delete += 1\n # age -= i\n age += i-AA[j]\n AA.sort()\n\n times = 10**9\n sage = 0\n for j in range(0,N-1):\n sage += AA[j]\n age -= i-AA[j]\n if sage % i == age % i:\n times = min(max(sage, age), times)\n if times <= K:\n return i\n print(main())\n\nresolve()", "passed": true, "time": 2.86, "memory": 15120.0, "status": "done"}, {"code": "import sys\nimport math\nimport heapq\nsys.setrecursionlimit(10**7)\nINTMAX = 9223372036854775807\nINTMIN = -9223372036854775808\nDVSR = 1000000007\ndef POW(x, y): return pow(x, y, DVSR)\ndef INV(x, m=DVSR): return pow(x, m - 2, m)\ndef DIV(x, y, m=DVSR): return (x * INV(y, m)) % m\ndef LI(): return [int(x) for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LS(): return input().split()\ndef II(): return int(input())\ndef FLIST(n):\n res = [1]\n for i in range(1, n+1): res.append(res[i-1]*i%DVSR)\n return res\ndef gcd(x, y):\n if x < y: x, y = y, x\n div = x % y\n while div != 0:\n x, y = y, div\n div = x % y\n return y\n\nN,K=LI()\nAS=LI()\nSUMM= sum(AS)\n\nDIVS=set()\nfor i in range(1,40000):\n if SUMM % i == 0:\n DIVS.add(i)\n DIVS.add(SUMM//i)\n# DIVS.sort(reversed=True)\n# print(DIVS)\n\nDIFF=[0]*N\nACC=[0]*N\n\n# res = 0\n\nfor div in sorted(DIVS, reverse=True):\n for i in range(N):\n DIFF[i] = AS[i]%div\n DIFF.sort()\n ACC[0] = DIFF[0]\n for i in range(1,N): ACC[i] = ACC[i-1] + DIFF[i]\n # print(ACC)\n for i in range(N-1):\n left = ACC[i]\n right = (N-1-i)*div-(ACC[N-1]-ACC[i])\n if left%div == right%div:\n if max(left, right) <= K:\n # print(max(left, right))\n print(div)\n return\n\n\n# print(DIFF)\n# print(res)\n", "passed": true, "time": 2.38, "memory": 15300.0, "status": "done"}, {"code": "# \u5272\u308a\u5207\u308b\u6570\u306f\u3001A\u306e\u7dcf\u548c\u306e\u7d04\u6570\u3067\u3042\u308b\n# \u81ea\u5206\u81ea\u8eab\u3092\u9664\u304f\u7d04\u6570\u306b\u3064\u3044\u3066\u5927\u304d\u3044\u9806\u306b\u3059\u3079\u3066\u8a66\u3057\u3066\u3001\u5f53\u3066\u306f\u307e\u308b\u3082\u306e\u304c\u3042\u308c\u3070\u7b54\u3048\n\n# 8,20\u30927\u306e\u500d\u6570\u306b\u8fd1\u3065\u3051\u308b\u3068\u304d\u3001\n# 8 -> mod 7\u304c1\u3067\u3042\u308a\u3001-1\u304b+6\u30677\u306e\u500d\u6570\u306b\u306a\u308b\n# 20 -> mod 7\u304c6\u3067\u3042\u308a\u3001-6\u304b+1\u30677\u306e\u500d\u6570\u306b\u306a\u308b\n\nimport sys\nreadline = sys.stdin.readline\n\nN,K = map(int,readline().split())\nA = list(map(int,readline().split()))\n\nall = sum(A)\ndivisors = []\nfor i in range(1,int(all ** 0.5) + 1):\n if all % i == 0:\n divisors.append(i)\n divisors.append(all // i)\n\ndivisors = sorted(divisors,reverse = True)\n\nfor d in divisors:\n mods = [0] * (N)\n for i in range(len(A)):\n mods[i] = A[i] % d\n mods = sorted(mods)\n mods_front = [0] * N\n mods_front[0] = mods[0]\n for i in range(1,N):\n mods_front[i] = mods_front[i - 1] + mods[i]\n mods_back = [0] * N\n mods_back[-1] = d - mods[-1]\n for i in range(N - 2,-1,-1):\n mods_back[i] = mods_back[i + 1] + (d - mods[i])\n for i in range(N - 1):\n if mods_front[i] == mods_back[i + 1]:\n if K >= mods_front[i]:\n print(d)\n return\nelse:\n print(1)", "passed": true, "time": 2.15, "memory": 15008.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na = list(map(int, input().split()))\n\ndef ok(d):\n m = sorted(a % d for a in a)\n s, e, plus, minus = 0, len(m) - 1, 0, 0\n while True:\n if s > e:\n return (plus == minus)\n if plus <= minus:\n plus += m[s]\n if plus > k:\n return False\n s += 1\n else:\n minus += d - m[e]\n if minus > k:\n return False\n e -= 1\n return False\n\nb = sum(a)\nret = 1\nd = 1\nwhile d * d <= b:\n if b % d == 0:\n if ok(d):\n ret = max(ret, d)\n if ok(b // d):\n ret = max(ret, b //d)\n d += 1\nprint(ret)", "passed": true, "time": 1.26, "memory": 14864.0, "status": "done"}, {"code": "from itertools import accumulate\nN, K = list(map(int, input().split()))\nA = list(map(int, input().split()))\nM = sum(A)\n\n# \u7b54\u3048\u306e\u5019\u88dc\u3092\u5217\u6319\nans_candidates = []\nfor n in range(1, int(M ** 0.5) + 1):\n if M % n == 0:\n ans_candidates.append(n)\n ans_candidates.append(M // n)\n\n\nans = 0\nfor X in ans_candidates:\n A_mod = sorted([a % X for a in A])\n U = [X - a for a in A_mod]\n D = [-a for a in A_mod] # \u308f\u304b\u308a\u3084\u3059\u3044\u306e\u3067\n\n U = list(accumulate(U))\n D = list(accumulate(D))\n\n for i in range(N):\n if -D[i] > K:\n break\n\n if -D[i] == (U[-1] - U[i]):\n ans = max(ans, X)\n break\n\nprint(ans)\n", "passed": true, "time": 1.33, "memory": 15048.0, "status": "done"}, {"code": "def get_divisor(num, max_val):\n ret = []\n num_sq = int(num**0.5)\n for k in range(1, num_sq+1):\n if num % k == 0:\n if k <= max_val: ret.append(k)\n if num//k <= max_val: ret.append(num//k)\n \n return ret\n\n# \u4e0b\u304b\u3089mod\u304c\u4f4e\u3044\u306e\u3092\u53d6\u3063\u3066\u304d\u3066\u30de\u30c3\u30c1\u30f3\u30b0\u3092\u53d6\u308b\ndef solve():\n N,K = map(int, input().split())\n A = list(map(int, input().split()))\n sum_A = sum(A)\n max_A = max(A)\n div = get_divisor(sum_A, max_A+K)\n ret = 1\n for d in div:\n sum_k = 0\n red_k = 0\n flag = True\n mod_d = [a%d for a in A]\n mod_d.sort()\n # print(d, mod_d)\n for a in mod_d:\n if sum_k+a <= K:\n sum_k += a\n else: \n red_k += d-a\n if sum_k-red_k < 0:\n break\n\n if (sum_k-red_k)%d == 0: ret = max(ret, d)\n \n print(ret)\n \nsolve()", "passed": true, "time": 0.71, "memory": 15152.0, "status": "done"}, {"code": "from math import sqrt\ndef Divisor_Set(n):\n s = set()\n for i in range(1, int(sqrt(n))+2):\n if n%i == 0:\n s.add(i)\n s.add(n//i)\n return s\n\ndef main():\n n, k = map(int, input().split())\n a = list(map(int, input().split()))\n a_sum = sum(a)\n s = Divisor_Set(a_sum)\n ans = 1\n for v in s:\n a_mod = [x%v for x in a]\n a_mod.sort()\n for i in range(1, n):\n a_mod[i] += a_mod[i-1]\n for i in range(n):\n l, r = a_mod[i], v*(n-i-1) - (a_mod[-1] - a_mod[i])\n if l == r and r <= k:\n if ans < v:\n ans = v\n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 1.87, "memory": 15116.0, "status": "done"}, {"code": "from collections import deque\nimport sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\ndef II(): return int(sys.stdin.readline())\ndef MI(): return map(int, sys.stdin.readline().split())\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\ndef SI(): return sys.stdin.readline()[:-1]\n\ndef main():\n def ok(f):\n bb=[a%f for a in aa]\n bb.sort()\n i,j=0,n-1\n s=t=0\n while i<=j:\n if s>t:\n t+=f-bb[j]\n j-=1\n else:\n s+=bb[i]\n i += 1\n return s<=k\n\n n,k=MI()\n aa=LI()\n s=sum(aa)\n ff=[]\n for d in range(1,s+1):\n if d**2>s:break\n if s%d==0:\n ff.append(d)\n ff.append(s//d)\n if ff[-1]==ff[-2]:ff.pop()\n ff.sort(reverse=True)\n for f in ff:\n if ok(f):\n print(f)\n break\n\nmain()", "passed": true, "time": 3.64, "memory": 14972.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na = list(map(int, input().split()))\nm = sum(a)\n\ndef divisor(n):\n ass = []\n for i in range(1, int(n**0.5)+1):\n if n%i == 0:\n ass.append(i)\n ass.append(n//i)\n return ass\nf = divisor(m)\nf.sort(reverse=True)\n\nfor p in f:\n b = [x%p for x in a]\n b.sort()\n t = 0\n c = n\n for x in b:\n if x + t > k:\n break\n t += x\n c -= 1\n if c*p - sum(b) + t <= k:\n print(p)\n break", "passed": true, "time": 0.56, "memory": 14960.0, "status": "done"}, {"code": "def factor(N):\n arr=[]\n for i in range(1,int(N**0.5)+1):\n if(N%i==0):\n arr.append(i)\n if(N//i!=i):\n arr.append(N//i)\n return arr\n\nn,k=map(int,input().split())\na=list(map(int,input().split()))\nsum_=sum(a)\n\nfac=sorted(factor(sum_),reverse=True)\nans=1\nfor x in fac:\n li=sorted(z%x for z in a)\n res=0\n cum=[0]*(n+1)\n for i in range(n):\n cum[i+1]=cum[i]+li[i]\n for i in range(1,n):\n l,r=cum[i],x*(n-i)-(cum[n]-cum[i])\n if l==r and r<=k:\n ans=max(ans,x)\nprint(ans)", "passed": true, "time": 1.78, "memory": 15136.0, "status": "done"}, {"code": "def make_divisors(n: int) -> list:\n \"\"\"\u81ea\u7136\u6570n\u306e\u7d04\u6570\u3092\u5217\u6319\u3057\u305f\u30ea\u30b9\u30c8\u3092\u51fa\u529b\u3059\u308b\n \u8a08\u7b97\u91cf: O(sqrt(N))\n \u5165\u51fa\u529b\u4f8b: 12 -> [1, 2, 3, 4, 6, 12]\n \"\"\"\n divisors = []\n for k in range(1, int(n ** 0.5) + 1):\n if n % k == 0:\n divisors.append(k)\n if k != n // k:\n divisors.append(n // k)\n divisors = sorted(divisors)\n return divisors\n\n\ndef solve(val):\n res = []\n for i in range(n):\n tmp = a[i] % val\n if tmp == 0:\n continue\n res.append(a[i] % val)\n res = sorted(res)\n if not res:\n return True\n l_val = 0\n for i in range(len(res)):\n l_val += res[i]\n if l_val > k:\n l_pos = i - 1\n break\n else:\n return True\n r_val = 0\n for i in range(l_pos + 1, len(res)):\n r_val += val - res[i]\n return r_val <= k\n \n \n \n \nn, k = map(int, input().split())\na = list(map(int, input().split()))\n\nsum_a = sum(a)\ndiv = make_divisors(sum_a)\nans = 0\nfor i in div:\n if solve(i):\n ans = max(ans, i)\nprint(ans)", "passed": true, "time": 1.63, "memory": 15156.0, "status": "done"}, {"code": "n,k=map(int,input().split())\na=[int(x) for x in input().split()]\ns=sum(a)\n\ncandidates=set()\nfor i in range(1,int(s**0.5)+1):\n if s%i==0:\n candidates.add(i)\n candidates.add(s//i)\n\nans=0\nfor cdd in candidates:\n f=sorted([x%cdd for x in a])\n # calc need\n ans=max(ans,cdd) if sum(f[:-sum(f)//cdd])<=k else ans \n \nprint(ans)", "passed": true, "time": 1.27, "memory": 14860.0, "status": "done"}, {"code": "N, K = list(map(int, input().split()))\nA = list(map(int, input().split()))\nAsum = sum(A)\n\ndiv = set()\nfor i in range(1, int(Asum ** 0.5 + 0.5) + 1):\n if Asum % i == 0:\n div.add(i)\n div.add(Asum//i)\n\nans = 1\nfor d in div:\n R = [a % d for a in A]\n R.sort()\n r = sum(R) // d\n l = N - r\n need = sum(R[:l])\n if need <= K:\n ans = max(ans, d)\nprint(ans)\n", "passed": true, "time": 0.67, "memory": 14996.0, "status": "done"}, {"code": "from itertools import accumulate\nfrom math import floor, sqrt\nN, K = map(int,input().split())\nA = list(map(int,input().split()))\nsm = sum(A)\ndivs = set()\nfor i in range(1, floor(sqrt(sm))+1):\n if sm % i == 0:\n divs.add(i)\n divs.add(sm // i)\nans = 1\nfor d in divs:\n ls = sorted(map(lambda x: x%d, A))\n acc = [0]+list(accumulate(ls, lambda x,y:x+y))\n for i in range(1, N):\n minus = acc[i]-acc[0]\n plus = d*(N-i) - (acc[-1]-acc[i])\n if plus == minus and plus <= K:\n ans = max(ans, d)\nprint(ans)", "passed": true, "time": 2.1, "memory": 15080.0, "status": "done"}, {"code": "import sys\n\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nsys.setrecursionlimit(10 ** 9)\nINF = 1 << 60\nMOD = 1000000007\n\n\ndef divisors(n):\n lower = []\n upper = []\n for i in range(1, int(n ** 0.5) + 1):\n if n % i == 0:\n lower.append(i)\n if i != n // i:\n upper.append(n // i)\n\n lower.extend(reversed(upper))\n return lower\n\n\ndef main():\n N, K, *A = list(map(int, read().split()))\n\n total = sum(A)\n div = divisors(total)\n\n for d in reversed(div):\n vec = [a % d for a in A]\n vec.sort()\n\n M = len(vec)\n csum_sub = [0] * (M + 1)\n csum_add = [0] * (M + 1)\n for i in range(M):\n csum_sub[i + 1] = csum_sub[i] + vec[i]\n csum_add[i + 1] = csum_add[i] + d - vec[i]\n\n for i in range(M + 1):\n if csum_sub[i] <= K and csum_sub[i] == csum_add[M] - csum_add[i]:\n print(d)\n return\n\n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 2.59, "memory": 15140.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nA = list(map(int, input().split()))\ns = sum(A)\ndef md(n):\n divisors = []\n for i in range(1, int(n**0.5)+1):\n if n % i == 0:\n divisors.append(i)\n if i != n // i:\n divisors.append(n//i)\n\n divisors.sort(reverse=True)\n return divisors\nP = md(s)\ndef test(x):\n L = sorted([a%x for a in A])\n M = sum(L)\n c = M//x\n for _ in range(c):\n M -= L.pop()\n return M <= k\n\nfor p in P:\n if test(p):\n print(p)\n break", "passed": true, "time": 0.63, "memory": 15056.0, "status": "done"}, {"code": "N,K=map(int, input().split())\nA=list(map(int, input().split()))\n\ndef make_divisors(n):\n lower_divisors , upper_divisors = [], []\n i = 1\n while i*i <= n:\n if n % i == 0:\n lower_divisors.append(i)\n if i != n // i:\n upper_divisors.append(n//i)\n i += 1\n return lower_divisors + upper_divisors[::-1]\n \nD=make_divisors(sum(A))\nans=1\nfor i in D:\n E=[]\n for j in A:\n d=j%i\n if d!=0:\n E.append(d)\n if len(E)==0:\n ans=i\n E=sorted(E)\n cn=0\n e=sum(E)\n left,right=e,0\n #print(i,E)\n for k in range(len(E)):\n left-=E[-1-k]\n right+=(i-E[-1-k])\n if left==right:\n if left<=K:\n ans=i\n break\nprint(ans)", "passed": true, "time": 2.48, "memory": 15092.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\na = list(map(int,input().split()))\ns = sum(a)\ndl = []\nfor i in range(1,int(s**0.5)+1):\n if s%i == 0:\n dl.append(i)\n if i != s//i:\n dl.append(s//i)\ndl.sort(reverse = True)\n\ndef search(x):\n ml = []\n for i in a:\n ml.append(i%x)\n ml.sort(reverse = True)\n ms = sum(ml)\n count = 0\n i = 0\n while k > count and ms > count:\n mi = x-ml[i]\n if k >= mi:\n count += mi\n ms -= ml[i]\n \n else:\n break\n i += 1\n\n if k >= count and count == ms:\n return True\n else:\n return False\n\nfor i in dl:\n \n if search(i):\n print(i)\n return\n\n", "passed": true, "time": 0.61, "memory": 14956.0, "status": "done"}, {"code": "n,k=list(map(int,input().split()))\nA=list(map(int,input().split()))\n\ns=sum(A)\nimport math\ndef yakusu(n):\n ans_local=set()\n for i in range(1,int(math.sqrt(n))+1):\n if n%i==0:\n ans_local = ans_local | set([i,n//i]) #set\u306a\u306e\u3067\u5e73\u65b9\u6570\u3067\u3082OK\n return list(ans_local) #\u5fc5\u8981\u306b\u5fdc\u3058\u3066sort\n\nyaku=sorted(yakusu(s), reverse=1)\n#print(yaku)\nfor mod in yaku:\n B=[i%mod for i in A if i%mod!=0]\n if B==[] : print(mod);return\n if len(B)==1:\n q=B[0]\n if 0<=q<=k or mod-k<=q: print(mod);return\n else:continue\n B.sort()\n r=[B[0]]*len(B)\n for i in range(len(B)-1):\n r[i+1]= r[i]+B[i+1]\n now=float(\"INF\")\n for i in range(1,len(B)): #\u5207\u308a\u65b9\n if r[i-1] == mod*(len(B)-i)-(r[-1]-r[i-1]) and r[i-1]<=k:\n print(mod);return\n\n \n", "passed": true, "time": 2.78, "memory": 15128.0, "status": "done"}, {"code": "from math import sqrt\nfrom itertools import accumulate\n\n\ndef common_divisors(x):\n ret = []\n for i in range(1, int(sqrt(x)) + 1):\n if x % i == 0:\n ret.append(i)\n ret.append(x // i)\n\n return ret\n\n\nn, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nsm = sum(a)\ncd = common_divisors(sm)\n\nans = 1\nfor ecd in cd:\n r = [e % ecd for e in a]\n r.sort()\n acc = [0] + list(accumulate(r))\n for i in range(1, n + 1):\n sub = acc[i-1]\n add = ecd * (n - i + 1) - (acc[n] - acc[i-1])\n if sub == add:\n if sub <= k:\n ans = max(ans, ecd)\n\nprint(ans)\n", "passed": true, "time": 3.02, "memory": 15036.0, "status": "done"}, {"code": "from math import sqrt\nfrom itertools import accumulate\n\n\ndef common_divisors(x):\n ret = []\n for i in range(1, int(sqrt(x)) + 1):\n if x % i == 0:\n ret.append(i)\n ret.append(x // i)\n\n return ret\n\n\nn, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nsm = sum(a)\ncd = common_divisors(sm)\n\nans = 0\nfor ecd in cd:\n r = [e % ecd for e in a]\n r.sort()\n sub = [0] + list(accumulate(r))\n add = [0] + list(accumulate(ecd - e for e in r[::-1]))\n add = add[::-1]\n for sb, ad in zip(sub, add):\n if sb == ad and sb <= k:\n ans = max(ans, ecd)\n\nprint(ans)\n", "passed": true, "time": 1.22, "memory": 15112.0, "status": "done"}, {"code": "from math import sqrt\nfrom itertools import accumulate\n\n\ndef common_divisors(x):\n ret = []\n for i in range(1, int(sqrt(x)) + 1):\n if x % i == 0:\n ret.append(i)\n ret.append(x // i)\n\n return ret\n\n\nn, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nsm = sum(a)\ncd = common_divisors(sm)\n\nans = 1\nfor ecd in cd:\n r = [e % ecd for e in a]\n r.sort()\n sub = [0] + list(accumulate(r))\n add = [0] + list(accumulate(ecd - e for e in r[::-1]))\n add = add[::-1]\n for sb, ad in zip(sub, add):\n if sb == ad and sb <= k:\n ans = max(ans, ecd)\n\nprint(ans)\n", "passed": true, "time": 1.22, "memory": 15076.0, "status": "done"}, {"code": "from math import sqrt\nfrom bisect import bisect_left\n\ndef main():\n n, k = map(int, input().split())\n a = list(map(int, input().split()))\n sum_a = sum(a)\n st = set()\n for v in range(1, int(sqrt(sum_a))+2):\n if sum_a % v == 0:\n st.add(v)\n st.add(sum_a//v)\n st.remove(1)\n ans = 1\n for target in st:\n a_mod_t = [v % target for v in a]\n a_mod_t.sort()\n for i in range(n-1):\n a_mod_t[i+1] += a_mod_t[i]\n for i in range(n):\n sum_L, sum_R = a_mod_t[i], a_mod_t[-1] - a_mod_t[i]\n len_L, len_R = i+1, n-i-1\n if sum_L == target * len_R - sum_R:\n if sum_L <= k:\n if ans < target:\n ans = target\n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 1.98, "memory": 15020.0, "status": "done"}, {"code": "N, K = map(int, input().split())\nA = list(map(int, input().split()))\nS = sum(A)\nmax_div = int(S**0.5)\n\n# S\u306e\u7d04\u6570\u3092\u5217\u6319\u3059\u308b\nsmall_div = []\nlarge_div = []\nfor i in range(1, max_div+1):\n if S%i == 0:\n small_div.append(i)\n large_div.append(S//i)\n\n# \u7d04\u6570\u3092\u964d\u9806\u306b\u4e26\u3079\u308b\ndiv = large_div + small_div[::-1]\n\nans = 1\nfor d in div:\n r = []\n for a in A:\n r.append(a%d)\n \n r.sort()\n # (d-ri)\u8db3\u3059\u304b\u3001ri\u5f15\u304f\u304b\u3001\u305d\u308c\u305e\u308c\u7d2f\u7a4d\u548c\u3092\u6c42\u3081\u3066\u304a\u304f\n minus = [0]*(N+1)\n plus = [0]*(N+1)\n for i, ri in enumerate(r, 1):\n minus[i] = minus[i-1] + ri\n \n for i, ri in enumerate(r[::-1], 1):\n plus[i] = plus[i-1] + (d - ri)\n \n plus = plus[::-1]\n for m, p in zip(minus, plus):\n if m == p and m <= K:\n ans = d\n break\n \n else:\n continue\n \n break\n\nprint(ans)", "passed": true, "time": 1.35, "memory": 15144.0, "status": "done"}, {"code": "def main():\n N, K = list(map(int, input().split()))\n A = list(map(int, input().split()))\n m = sum(A)\n d = []\n for i in range(1, int(m**0.5)+1):\n if m % i == 0:\n d.append(i)\n if i != m // i:\n d.append(m//i)\n d.sort(reverse=True)\n for j in d:\n if j > K + max(A):\n continue\n l = []\n for i in A:\n l.append(i % j)\n t = N - sum(l) // j\n l.sort()\n if sum(l[:t]) <= K:\n print(j)\n return\n print((1))\nmain()\n", "passed": true, "time": 0.63, "memory": 15016.0, "status": "done"}, {"code": "import heapq\n\ndef divisor(i):\n s = []\n for j in range(1, int(i ** (1 / 2)) + 1):\n if i % j == 0:\n s.append(i // j)\n s.append(j)\n return sorted(set(s))\n\nn, k = map(int, input().split())\na = list(map(int, input().split()))\nsuma = sum(a)\ns = divisor(suma)\nfor i in range(1, len(s) + 1):\n x = s[-i]\n y = suma // x\n h = []\n heapq.heapify(h)\n for j in a:\n y -= j // x\n heapq.heappush(h, -(j % x))\n cnt = 0\n for _ in range(y):\n cnt += (heapq.heappop(h) % x)\n if cnt <= k:\n print(x)\n return", "passed": true, "time": 1.18, "memory": 15060.0, "status": "done"}, {"code": "import sys\n\ndef solve():\n input = sys.stdin.readline\n N, K = map(int, input().split())\n A = [int(a) for a in input().split()]\n sumA = sum(A)\n D = []\n for i in range(1, sumA + 1):\n if i ** 2 > sumA: break\n if sumA % i == 0:\n D.append(i)\n if i ** 2 != sumA: D.append(sumA // i)\n D.sort(reverse = True)\n for i, d in enumerate(D):\n L = []\n count = 0\n for a in A:\n if a % d > 0: \n L.append(a % d)\n count += 1\n L.sort()\n if count > 0:\n minus, plus = [0] * count, [0] * count\n minus[0] = L[0]\n plus[count - 1] = d - L[count - 1]\n for i in range(1, count):\n minus[i] = minus[i-1] + L[i]\n plus[count - 1 - i] = plus[count - i] + d - L[count - 1 - i]\n Op = K + 1\n for i in range(count - 1):\n if abs(minus[i] - plus[i + 1]) % d == 0: Op = min(Op, max(minus[i], plus[i + 1]))\n if Op <= K:\n print(d)\n break\n else: print(1)\n\n return 0\n\ndef __starting_point():\n solve()\n__starting_point()", "passed": true, "time": 4.59, "memory": 15140.0, "status": "done"}, {"code": "n,k=map(int,input().split())\na=[int(x) for x in input().split()]\ns=sum(a)\n\ncandidates=set()\nfor i in range(1,int(s**0.5)+1):\n if s%i==0:\n candidates.add(i)\n candidates.add(s//i)\n\nans=0\nfor cdd in candidates:\n div_cdd=[0]*n\n for i in range(n):\n div_cdd[i]=a[i]%cdd\n div_cdd=sorted(div_cdd)\n pstv,ngtv=0,-sum(div_cdd)\n # calc need\n if pstv==-ngtv:\n ans=max(ans,cdd)\n continue\n for i in range(n):\n pstv+=cdd-div_cdd[-1-i]\n ngtv+=div_cdd[-1-i]\n if pstv==-ngtv: break\n ans=max(ans,cdd) if pstv<=k else ans\n \nprint(ans)", "passed": true, "time": 1.15, "memory": 14992.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\n# \u7d04\u6570\u5217\u6319\ndef make_divisors(n):\n divisors = []\n for i in range(1, int(n**0.5)+1):\n if n % i == 0:\n divisors.append(i)\n if i != n // i:\n divisors.append(n//i)\n\n # divisors.sort()\n return divisors\n\nans = 1\n\nfor div in make_divisors(sum(a)):\n mod_div = []\n for ai in a:\n mod_div.append(ai % div)\n mod_div.sort()\n\n tmp_p = n * div - sum(mod_div)\n tmp_m = 0\n\n for i, x in enumerate(mod_div):\n tmp_m += x\n tmp_p -= div - x\n if tmp_m == tmp_p and tmp_m <= k:\n ans = max(div, ans)\n\nprint(ans)\n", "passed": true, "time": 1.22, "memory": 14996.0, "status": "done"}, {"code": "from itertools import accumulate\nn,k = map(int,input().split())\na = list(map(int,input().split()))\nsuma = sum(a)\ndevisor = []\nfor i in range(1,int(suma**0.5)+1):\n if suma%i == 0:\n devisor.extend((i,suma//i))\ndevisor.sort(reverse=True)\nfor x in devisor:\n b = [a[i]%x for i in range(n)]\n b.sort()\n sumb = list(accumulate(b))\n for y in range(n-1):\n bf = sumb[y]\n bl = sumb[n-1]-sumb[y]\n if bf%x == (x-(bl%x))%x:\n if k>=max(bf,(n-1-y)*x-bl):\n print(x)\n return\n else:\n continue", "passed": true, "time": 2.18, "memory": 15004.0, "status": "done"}, {"code": "N,K = map(int,input().split())\nA = list(map(int,input().split()))\n\nS = sum(A)\nans = 0\n\nfor i in range(1,int(S**0.5)+1):\n if S%i != 0:\n continue\n \n for j in range(2):\n d = i if j else S//i\n B = sorted(map(lambda a:a%d,A))\n C = [0]\n for k in range(N):\n C.append(C[-1]+B[k])\n \n for k in range(N+1):\n if ((N-k)*d-(C[-1]-C[k])-C[k])%d == 0:\n if max(C[k],(N-k)*d-(C[-1]-C[k])) <= K:\n ans = max(ans,d)\n \nprint(ans)", "passed": true, "time": 3.8, "memory": 15000.0, "status": "done"}, {"code": "INF = float(\"inf\")\nn, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\ndef get_divisors(num):\n f_divs, l_divs = [], []\n for i in range(1, int(num**0.5)+1):\n if not num % i:\n f_divs.append(i)\n if i != num // i:\n l_divs.append(num // i)\n return f_divs + l_divs[::-1]\n\ndivs = get_divisors(sum(a))\nans = 1\n\ndef evl(d):\n rem = [x % d for x in a]\n rem.sort()\n s = sum(rem)\n c = 0\n for i, x in enumerate(rem):\n c += x\n if c == d*(n-i-1) - (s-c):\n return c <= k\n return False\n\nfor d in divs[::-1]:\n if evl(d):\n print(d)\n break\n", "passed": true, "time": 0.83, "memory": 15044.0, "status": "done"}, {"code": "# https://betrue12.hateblo.jp/entry/2020/03/28/142051\n\ndef main():\n N, K = list(map(int, input().split()))\n *A, = list(map(int, input().split()))\n\n def divisor_generator(n):\n div = 1\n\n stock = []\n while div * div <= n:\n if n % div == 0:\n yield n // div\n stock.append(div)\n div += 1\n\n for div in reversed(stock):\n yield div\n\n tot = sum(A)\n for div in divisor_generator(tot):\n k = tot // div - sum(a // div for a in A)\n R = sorted(a % div for a in A)\n Rc = [div - r for r in R]\n\n cond = (sr := sum(r for r in R[:N - k])) == sum(r for r in Rc[N - k:]) and sr <= K\n if cond:\n print(div)\n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.91, "memory": 15136.0, "status": "done"}, {"code": "from itertools import accumulate\n\ndef divisors(n):\n lst = []\n for i in range(1, int(n**0.5) + 1):\n if n % i == 0:\n lst.append(i)\n if i != n // i: lst.append(n // i)\n return lst\n\nN, K = map(int, input().split())\n*A, = map(int, input().split())\ncands = divisors(sum(A))\nfor d in sorted(cands, reverse=True):\n rems = sorted([a % d for a in A])\n cumsum_rems = [0] + list(accumulate(rems))\n for i in range(1, N):\n minus = cumsum_rems[i]\n plus = d * (N - i) - (cumsum_rems[N] - minus)\n if max(minus, plus) <= K: break\n else:\n continue\n break\nprint(d)", "passed": true, "time": 1.64, "memory": 14936.0, "status": "done"}, {"code": "def main():\n N, K = list(map(int, input().split(' ')))\n A = list(map(int, input().split(' ')))\n # Calculate divisors of sum(A)\n S = sum(A)\n divs = list()\n n = 1\n while n ** 2 <= S:\n if S % n == 0:\n m = S // n\n if n != m:\n divs.extend([n, m])\n else:\n divs.append(n)\n n += 1\n divs.sort(reverse=True)\n # calc answer\n ans = S\n for d in divs:\n B = [a % d for a in A]\n B.sort(reverse=True)\n t = sum(B) // d\n k = sum(B) - sum(B[:t])\n if d == 1:\n k = 0\n if k <= K:\n ans = d\n break\n print(ans)\n\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 1.01, "memory": 15044.0, "status": "done"}, {"code": "n,k=map(int,input().split())\na=[int(x) for x in input().split()]\ns=sum(a)\n\ncandidates=set()\nfor i in range(1,int(s**0.5)+2):\n if s%i==0:\n candidates.add(i)\n candidates.add(s//i)\n\nans=0\nfor cdd in candidates:\n div_cdd=[0]*n\n for i in range(n):\n div_cdd[i]=a[i]%cdd\n div_cdd=sorted(div_cdd)\n pstv,ngtv=0,-sum(div_cdd)\n # calc need\n if pstv==-ngtv:\n ans=max(ans,cdd)\n continue\n for i in range(n):\n pstv+=cdd-div_cdd[-1-i]\n ngtv+=div_cdd[-1-i]\n if pstv==-ngtv: break\n ans=max(ans,cdd) if pstv<=k else ans\n \nprint(ans)", "passed": true, "time": 1.15, "memory": 14924.0, "status": "done"}, {"code": "def yakusu(n):\n lower_divisors , upper_divisors = [], []\n i = 1\n while i*i <= n:\n if n % i == 0:\n lower_divisors.append(i)\n if i != n // i:\n upper_divisors.append(n//i)\n i += 1\n return lower_divisors + upper_divisors[::-1]\nN,K=map(int,input().split())\nL=list(map(int,input().split()))\na=sum(L)\nR=yakusu(a)[::-1]\nfor i in range(len(R)):\n add=0\n minus=0\n s=R[i]\n A=list()\n B=list()\n for j in range(N):\n k=L[j]\n a=k%s\n b=s-a\n if a>b:\n add+=b\n B.append(b)\n elif a<b:\n minus+=a\n A.append(a)\n else:\n add+=a\n B.append(a)\n #\u8db3\u3057\u305f\u5206=add else:minus \u3069\u3063\u3061\u3067\u3082:even\n A=sorted(A)\n B=sorted(B)\n if minus==add:\n d=minus\n if d<=K:\n print(s)\n return\n elif minus>add:\n q=(minus-add)//s\n d=sum(A[:len(A)-q])\n if d<=K:\n print(s)\n return\n else:\n q=(add-minus)//s\n d=sum(B[:len(B)-q])\n if d<=K:\n print(s)\n return", "passed": true, "time": 0.99, "memory": 14932.0, "status": "done"}, {"code": "import sys\nsys.setrecursionlimit(10000000)\nMOD = 10 ** 9 + 7\nINF = 10 ** 15\n\nN,K = list(map(int,input().split()))\nA = list(map(int,input().split()))\n\ndef is_divide(d):\n Rs = [a%d for a in A]\n Rs.sort()\n cumsum = [0] * (N + 1)\n for i in range(N - 1,-1,-1):\n cumsum[i] = cumsum[i + 1] + d - Rs[i]\n cum = 0\n for i in range(N):\n if max(cum,cumsum[i]) <= K:\n return True\n cum += Rs[i]\n return False\n\nS = sum(A)\nans = 0\nfor i in range(1,S + 1):\n if i*i > S:\n break\n if S%i == 0:\n if is_divide(i):\n ans = max(ans,i)\n if is_divide(S//i):\n ans = max(ans,S//i)\nprint(ans)\n", "passed": true, "time": 1.89, "memory": 15020.0, "status": "done"}, {"code": "N, K = map(int, input().split())\n*A, = map(int, input().split())\nA.sort()\n\nS = sum(A)\ncandidates = []\nfor i in range(1, int(S**0.5)+1):\n if S%i:continue\n a, b = i, S//i\n \n candidates.append(a)\n if a!=b:\n candidates.append(b)\ncandidates.sort()\n\nans = 0\nfor d in candidates:\n rems = []\n rems_size, rems_sum = 0, 0\n\n for i in A:\n if i%d:\n rems.append(i%d)\n rems_size += 1\n rems_sum += i%d\n\n rems.sort()\n\n a = 0\n for i, j in enumerate(rems[:-1], start=1):\n a += j\n b = d*(rems_size-i)-(rems_sum-a)\n if max(a, b)<=K:\n ans = max(ans, d)\n if not rems:\n ans = max(ans, d)\n\nprint(ans)", "passed": true, "time": 2.53, "memory": 15140.0, "status": "done"}, {"code": "import heapq\nn, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nx = sum(a)\nsearch = []\ni = 1\nwhile i ** 2 <= x:\n if x % i == 0:\n heapq.heappush(search, -i)\n heapq.heappush(search, -x//i)\n i += 1\n\nwhile search:\n ans = -heapq.heappop(search)\n u = [a[i] % ans for i in range(n)]\n u.sort()\n\n plus = [0]\n minus = [0]\n for i in range(n):\n plus.append(plus[-1] + ans - u[i])\n minus.append(minus[-1] + u[i])\n\n for i in reversed(list(range(n+1))):\n # print(i)\n m = minus[i]\n p = plus[-1] - plus[i]\n if m == p and m <= k:\n print(ans)\n return\n\n", "passed": true, "time": 2.0, "memory": 15148.0, "status": "done"}, {"code": "def make_divisors(n):\n lower_divisors , upper_divisors = [], []\n i = 1\n while i*i <= n:\n if n % i == 0:\n lower_divisors.append(i)\n if i != n // i:\n upper_divisors.append(n//i)\n i += 1\n return lower_divisors + upper_divisors[::-1]\nn, k = map(int, input().split())\na = list(map(int, input().split()))\ns = sum(a)\nl = make_divisors(s)\nl.sort(reverse=True)\nfor i in l:\n l2 = [j % i for j in a]\n l2.sort(reverse=True)\n m = sum(l2) - sum(l2[:sum(l2)//i])\n if i == 1:\n m = 0\n if m <= k:\n s = i\n break\nprint(s)", "passed": true, "time": 1.21, "memory": 15096.0, "status": "done"}, {"code": "N, K = (int(i) for i in input().split())\nA = [int(i) for i in input().split()]\n\ndef yaku(N):\n res = []\n for i in range(1, round(N**(1/2)) + 3 ):\n if N%i == 0:\n res.append(i)\n\n res2 = [N//i for i in res]\n res = list(set(res + res2))\n return res\n\nys = yaku(sum(A))\nys.sort(reverse=True)\nfor y in ys:\n M = [a%y for a in A if a%y]\n ma = 0\n mi = y*len(M) - sum(M)\n M.sort()\n for m in M:\n ma += m\n mi -= (y - m)\n if ma == mi:\n break\n if ma <= K:\n print(y)\n return\n", "passed": true, "time": 0.78, "memory": 14888.0, "status": "done"}, {"code": "import sys\nimport math\nimport heapq\nsys.setrecursionlimit(10**7)\nINTMAX = 9223372036854775807\nINTMIN = -9223372036854775808\nDVSR = 1000000007\ndef POW(x, y): return pow(x, y, DVSR)\ndef INV(x, m=DVSR): return pow(x, m - 2, m)\ndef DIV(x, y, m=DVSR): return (x * INV(y, m)) % m\ndef LI(): return [int(x) for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LS(): return input().split()\ndef II(): return int(input())\ndef FLIST(n):\n res = [1]\n for i in range(1, n+1): res.append(res[i-1]*i%DVSR)\n return res\ndef gcd(x, y):\n if x < y: x, y = y, x\n div = x % y\n while div != 0:\n x, y = y, div\n div = x % y\n return y\n\nN,K=LI()\nAS=LI()\nSUMM= sum(AS)\n\nDIVS=set()\nfor i in range(1,40000):\n if SUMM % i == 0:\n DIVS.add(i)\n DIVS.add(SUMM//i)\n# print(DIVS)\n\nDIFF=[0]*N\n\nres = 0\nfor div in DIVS:\n for i in range(N):\n DIFF[i] = AS[i]%div\n DIFF.sort()\n i = 0\n j = N-1\n sm = 0\n cost = 0\n while i <= j:\n if sm + DIFF[j] >= div:\n sm -= (div - DIFF[j])\n j -= 1\n else:\n cost += DIFF[i]\n sm += DIFF[i]\n i += 1\n # print(\"div:{} sum: {} cost: {}\".format(div, sm, cost))\n if cost <= K: res = max(res, div)\n\n# print(DIFF)\nprint(res)\n", "passed": true, "time": 2.2, "memory": 15216.0, "status": "done"}, {"code": "def main():\n N, K = list(map(int, input().split()))\n A = list(map(int, input().split()))\n m = sum(A)\n d = []\n for i in range(1, int(m**0.5)+1):\n if m % i == 0:\n d.append(i)\n if i != m // i:\n d.append(m//i)\n d.sort(reverse=True)\n for j in d:\n if j > K + max(A):\n continue\n l = []\n for i in A:\n l.append(i % j)\n t = N - sum(l) // j\n l.sort()\n if sum(l[:t]) <= K:\n print(j)\n return\n print((1))\nmain()\n", "passed": true, "time": 0.63, "memory": 14856.0, "status": "done"}, {"code": "import sys\nsys.setrecursionlimit(10 ** 6)\n# input = sys.stdin.readline ####\ndef int1(x): return int(x) - 1\ndef II(): return int(input())\n\ndef MI(): return list(map(int, input().split()))\ndef MI1(): return list(map(int1, input().split()))\n\ndef LI(): return list(map(int, input().split()))\ndef LI1(): return list(map(int1, input().split()))\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\n\ndef SI(): return input().split()\n\ndef printlist(lst, k='\\n'): print((k.join(list(map(str, lst)))))\nINF = float('inf')\n\nfrom math import ceil, floor, log2\nfrom collections import deque\nfrom itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product\nfrom heapq import heapify, heappop, heappush\n\n\ndef solve():\n n, k = MI()\n A = LI()\n sm = sum(A)\n\n div = []\n for i in range(1, int(pow(sm, 0.5))+1):\n if sm % i: continue\n div.append(i)\n if i != sm //i:\n div.append(sm // i)\n ans = 1\n for d in div:\n R = [a % d for a in A]\n R.sort()\n plus = 0\n minus = 0\n for r in R:\n plus += d - r\n for r in R:\n minus += r\n plus -= d - r\n if minus == plus and plus <= k:\n ans = max(ans, d)\n print(ans)\n\n\n\ndef __starting_point():\n solve()\n\n__starting_point()", "passed": true, "time": 1.25, "memory": 15084.0, "status": "done"}, {"code": "def gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a % b)\n\ndef lcm(a, b):\n return a // gcd(a, b) * b\n\ndef isPrime(x):\n if x < 2 or x % 2 == 0:\n return False\n if x == 2:\n return True\n i = 3\n while i * i <= x:\n if x % i == 0:\n return False\n i += 2\n return True\n\ndef divisor(x):\n res = []\n i = 1\n while i * i <= x:\n if x % i == 0:\n res.append(i)\n if i * i != x:\n res.append(x // i)\n i += 1\n res = sorted(res)\n return res\n\ndef factor(x):\n res = []\n if x == 1:\n res.push_back(1)\n return res\n i = 2\n while i * i <= x:\n while x % i == 0:\n res.append(i)\n x //= i\n if x != 1:\n res.append(x)\n res = sorted(res)\n return res\n\n \n\n\ndef __starting_point():\n N,K = list(map(int, input().split()))\n A = list(map(int, input().split()))\n A = sorted(A)\n sum_v = sum(A)\n div = divisor(sum_v)\n div = sorted(div, reverse=True)\n for e in div:\n ok = True\n b = [int(a % e) for a in A]\n b = sorted(b)\n v = sum(b)\n v //= e\n ans = 0\n for i in range(N-v):\n ans += b[i]\n \n if ans <= K:\n print(e)\n return\n\n__starting_point()", "passed": true, "time": 0.75, "memory": 14976.0, "status": "done"}, {"code": "N, K = list(map(int, input().split()))\nA = list(map(int, input().split()))\nS = sum(A)\n\ndef canMake(n):\n B = [a % n for a in A]\n B.sort()\n\n left = 0\n right = sum(B)\n for i, b in enumerate(B, start=1):\n left += b\n right -= b\n if left == n * (N - i) - right:\n return left <= K\n return False\n\nans = 1\nfor i in range(1, int(S**0.5) + 100):\n if S % i != 0:\n continue\n k = S // i\n\n if canMake(i):\n ans = max(ans, i)\n if canMake(k):\n ans = max(ans, k)\n break\n\nprint(ans)\n", "passed": true, "time": 0.84, "memory": 14944.0, "status": "done"}, {"code": "# --*-coding:utf-8-*--\n\nimport math\n\n\n\ndef main():\n N, K = list(map(int, input().split()))\n A = list(map(int, input().split()))\n\n s = sum(A)\n\n D1 = []\n D2 = []\n\n for i in range(1, int(math.sqrt(s))+1):\n if s%i == 0:\n D1.append(s//i)\n D2.append(i)\n\n for d in D1 + list(reversed(D2)):\n B = sorted([a%d for a in A])\n x = sum(B[:-sum(B)//d])\n \n if x <= K:\n print(d)\n return\n\nmain()\n", "passed": true, "time": 0.56, "memory": 15004.0, "status": "done"}, {"code": "N, K = map(int, input().split())\nA = list(map(int, input().split()))\nS = sum(A)\n\ndef isOk(n):\n B = [a % n for a in A]\n B.sort()\n\n now = 0\n S = sum(B)\n for i, b in enumerate(B[: -1]):\n now += b\n S -= b\n if now == n * (N - i - 1) - S and now <= K:\n return True\n return False\n\nans = 1\nfor i in range(1, int(S**0.5) + 100):\n if S % i != 0:\n continue\n j = S // i\n\n if isOk(i):\n ans = max(ans, i)\n if isOk(j):\n ans = max(ans, j)\n\nprint(ans)", "passed": true, "time": 1.42, "memory": 14924.0, "status": "done"}, {"code": "def make_divisors(n):\n divisors = []\n for i in range(1, int(n**0.5)+1):\n if n % i == 0:\n divisors.append(i)\n if i != n // i:\n divisors.append(n//i)\n\n return divisors\n\nN, K = map(int,input().split())\nA = list(map(int,input().split()))\nS = sum(A)\nL = make_divisors(S)\nans = 0\nfor i in L:\n D = []\n for a in A:\n if a % i != 0:\n D.append(a % i)\n D.sort()\n L1 = [0]\n L2 = [0]\n for j in range(len(D)):\n L1.append(L1[-1] + D[j])\n L2.append(L2[-1] + i - D[len(D)-1-j])\n L2.reverse()\n \n for j in range(len(D)+1):\n if K >= max(L1[j], L2[j]):\n ans = max(ans, i)\n\nprint(ans)", "passed": true, "time": 3.06, "memory": 15136.0, "status": "done"}, {"code": "N,K = list(map(int,input().split()))\nA = list(map(int,input().split()))\ndef divisor_all(n): # \u7d04\u6570\u5168\u5217\u6319\n l = [1,n]\n for i in range(2,int(pow(n,1/2))+1):\n if n % i == 0:\n if i == n//i:\n l.append(i)\n else:\n l.append(i)\n l.append(n//i)\n l.sort(reverse=True)\n return l # list\nD = divisor_all(sum(A))\ndef accumulater1D(A): # B:list[int]\n B = [0]*len(A)\n B[0] = A[0]\n for i in range(1,len(B)):\n B[i] = B[i-1]+A[i]\n return B # A\u306e1\u6b21\u5143\u7d2f\u7a4d\u548c\nimport bisect\nans = 0\n\nfor d in D:\n R = [A[i]%d for i in range(N) if A[i]%d!=0]\n nr = len(R)\n \n R.sort()\n if len(R)==0:\n ans = d\n break\n LR = accumulater1D(R)\n RR = list(reversed(accumulater1D([d-R[nr-1-i] for i in range(nr)])))\n \n for i in range(nr-1):\n if LR[i]==RR[i+1]:\n if LR[i]<=K:\n ans = d\n break\n if ans != 0:\n break\nprint(ans)\n\n\n\n", "passed": true, "time": 1.87, "memory": 15060.0, "status": "done"}, {"code": "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools\nimport time,random\n\nsys.setrecursionlimit(10**7)\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)\n\n\ndef main():\n n,k = LI()\n a = LI()\n s = sum(a)\n dv = set([1,s])\n for i in range(2,int(s**0.5)+5):\n if s%i == 0:\n dv.add(i)\n dv.add(s//i)\n\n def f(i):\n pm = []\n for c in a:\n t = c % i\n if t == 0:\n continue\n pm.append((i-t, t))\n pm.sort()\n p = pi = m = 0\n mi = len(pm) - 1\n while pi <= mi:\n if p < m:\n p += pm[pi][0]\n pi += 1\n else:\n m += pm[mi][1]\n mi -= 1\n return max(p,m) <= k\n\n r = 1\n for c in dv:\n if f(c):\n if r < c:\n r = c\n\n return r\n\n\nprint(main())\n\n\n\n", "passed": true, "time": 1.84, "memory": 15108.0, "status": "done"}, {"code": "n,k=map(int,input().split())\na=list(map(int,input().split()))\nm=sum(a)\ncd=set(())\nfor i in range(1,int(m**0.5)+2):\n if m%i==0:\n cd.add(i)\n cd.add(m//i)\ncd=list(cd)\ncd.sort(reverse=True)\ndef func(x):\n r=[ai%x for ai in a]\n r.sort()\n tmp=0\n sr=[0]\n for ri in r:\n tmp+=ri\n sr.append(tmp)\n for i in range(n+1):\n tmp0=sr[i]\n tmp1=(n-i)*x-(sr[-1]-sr[i])\n if tmp0==tmp1 and tmp0<=k:\n return True\n return False\n\n\nfor x in cd:\n if x==1:\n print(1)\n return\n if func(x):\n print(x)\n return", "passed": true, "time": 2.38, "memory": 14932.0, "status": "done"}, {"code": "from collections import deque\ndef isok(x):\n que=deque(sorted(z%x for z in a))\n res=0\n while que:\n l=que[0]\n if l==0:\n que.popleft()\n continue\n r=que[-1]\n if r==0:\n que.pop()\n continue\n d=min(l,x-r)\n que[0]-=d\n que[-1]=(que[-1]+d)%x\n res+=d\n return res\n \ndef factor(N):\n arr=[]\n for i in range(1,int(N**0.5)+1):\n if(N%i==0):\n arr.append(i)\n if(N//i!=i):\n arr.append(N//i)\n return arr\n\nn,k=list(map(int,input().split()))\na=list(map(int,input().split()))\nsum_=sum(a)\n\nfac=sorted(factor(sum_),reverse=True)\nans=1\nfor x in fac:\n c=isok(x)\n if c<=k:\n ans=x\n break\nprint(ans)\n", "passed": true, "time": 2.81, "memory": 15188.0, "status": "done"}, {"code": "def make_divisors(n):\n for i in range(1, int(n ** 0.5) + 1):\n if n % i == 0:\n yield i\n if i != n // i:\n yield n // i\n\n\nN, K = list(map(int, input().split()))\nA = tuple(map(int, input().split()))\n\ndivisors = list(make_divisors(sum(A)))\ndivisors.sort(reverse=True)\n\nfor divisor in divisors:\n M = [a % divisor for a in A]\n M.sort(reverse=True)\n # divisor\u3067\u5272\u3063\u305f\u4f59\u304c\u5927\u304d\u3044\u65b9\u306b\u8caa\u6b32\u306b+1\u3057\u3066\u3044\u304f\n if sum(M[sum(M) // divisor:]) <= K:\n print(divisor)\n return\n", "passed": true, "time": 1.02, "memory": 14976.0, "status": "done"}, {"code": "# \u89e3\u8aacAC\nfrom collections import deque\n\ndef check(d:int):\n \"\"\" K\u56de\u4ee5\u4e0b\u306e\u64cd\u4f5c\u3067A\u304cd\u306e\u500d\u6570\u3068\u306a\u308b\u304b\u5224\u5b9a\u3059\u308b \"\"\"\n mod = deque(sorted([a % d for a in A if (a % d != 0)]))\n\n ans = 0\n while mod:\n modmin = mod.popleft() # mod\u306e\u6700\u5c0f\u5024\n\n # modmin -> 0 \u3092\u8003\u3048\u308b\n ans += modmin\n while modmin:\n if not mod: return False # modmin -> 0 \u306b\u3067\u304d\u306a\u3044\n modmax = mod.pop()\n sub = d - modmax # modmax -> d \u306b\u3059\u308b\u64cd\u4f5c\u56de\u6570\n if sub <= modmin:\n # modmin -> 0 \u306e\u65b9\u304c\u64cd\u4f5c\u56de\u6570\u304c\u5fc5\u8981\u306a\u5834\u5408\n modmin -= sub\n else:\n # modmax -> d \u306e\u65b9\u304c\u64cd\u4f5c\u56de\u6570\u304c\u5fc5\u8981\u306a\u5834\u5408\n # (\u203b modmax > d \u3068\u306a\u308b\u3053\u3068\u306f\u306a\u3044)\n modmax += modmin\n if modmax % d != 0:\n mod.append(modmax)\n modmin = 0\n \n return True if (ans <= K) else False\n \n\ndef make_divisors(n:int):\n \"\"\" n\u306e\u7d04\u6570\u3092\u6607\u9806\u3067\u5217\u6319 \"\"\"\n divisors = []\n for i in range(1, int(n**0.5)+1):\n if n % i == 0:\n divisors.append(i)\n if i != n // i:\n divisors.append(n//i)\n divisors.sort()\n return divisors\n\n###############################\nN,K = map(int, input().split())\nA = [int(i) for i in input().split()]\n\nsumA_divisors = make_divisors(sum(A))\n\nans = 0\nfor d in sumA_divisors:\n if check(d):\n ans = d\n\nprint(ans)", "passed": true, "time": 1.77, "memory": 15196.0, "status": "done"}, {"code": "# \u5272\u308a\u5207\u308b\u6570\u306f\u3001A\u306e\u7dcf\u548c\u306e\u7d04\u6570\u3067\u3042\u308b\n# \u7d04\u6570\u306b\u3064\u3044\u3066\u5927\u304d\u3044\u9806\u306b\u3059\u3079\u3066\u8a66\u3057\u3066\u3001\u5f53\u3066\u306f\u307e\u308b\u3082\u306e\u304c\u3042\u308c\u3070\u7b54\u3048\n\n# 8,20\u30927\u306e\u500d\u6570\u306b\u8fd1\u3065\u3051\u308b\u3068\u304d\u3001\n# 8 -> mod 7\u304c1\u3067\u3042\u308a\u3001-1\u304b+6\u30677\u306e\u500d\u6570\u306b\u306a\u308b\n# 20 -> mod 7\u304c6\u3067\u3042\u308a\u3001-6\u304b+1\u30677\u306e\u500d\u6570\u306b\u306a\u308b\n# \u8ca0\u306e\u548c\u3068\u6b63\u306e\u548c\u304c\u4e00\u81f4\u3057\u305f\u3068\u304d\u3001\u305d\u306e\u3068\u304d\u306e\u7d76\u5bfe\u5024\u304c\u7b54\u3048\n# 1,1,2,3,4,5\u3068\u4e26\u3079\u3066\u3001\u524d\u304b\u3089\u8db3\u3057\u3066\u3044\u304f\u306e\u304c\u6700\u5584\u3002\u5165\u308c\u66ff\u3048\u308b\u3068\u7d76\u5bfe\u5024\u304c\u5897\u52a0\u3059\u308b\u306e\u3067\u640d\u3057\u304b\u3057\u306a\u3044\n\nimport sys\nreadline = sys.stdin.readline\n\nN,K = list(map(int,readline().split()))\nA = list(map(int,readline().split()))\n\nall = sum(A)\ndivisors = []\nfor i in range(1,int(all ** 0.5) + 1):\n if all % i == 0:\n divisors.append(i)\n divisors.append(all // i)\n\ndivisors = sorted(divisors,reverse = True)\n\nfor d in divisors:\n mods = [0] * (N)\n for i in range(len(A)):\n mods[i] = A[i] % d\n mods = sorted(mods)\n mods_front = [0] * N\n mods_front[0] = mods[0]\n for i in range(1,N):\n mods_front[i] = mods_front[i - 1] + mods[i]\n mods_back = [0] * N\n mods_back[-1] = d - mods[-1]\n for i in range(N - 2,-1,-1):\n mods_back[i] = mods_back[i + 1] + (d - mods[i])\n for i in range(N - 1):\n if mods_front[i] == mods_back[i + 1]:\n if K >= mods_front[i]:\n print(d)\n return\nelse:\n print((1))\n", "passed": true, "time": 1.5, "memory": 15080.0, "status": "done"}, {"code": "N, K = list(map(int, input().split()))\nA = list(map(int, input().split()))\nAsum = sum(A)\n\ndiv = set()\nfor i in range(1, int(Asum ** 0.5 + 0.5) + 1):\n if Asum % i == 0:\n div.add(i)\n div.add(Asum//i)\n\nans = 1\nfor d in div:\n now = 10 ** 18\n R = [a % d for a in A]\n R.sort()\n Rsum = sum(d - r for r in R)\n Lsum = 0\n for r in R:\n Lsum += r\n Rsum -= d - r\n now = min(now, max(Lsum, Rsum))\n\n if now <= K:\n ans = max(ans, d)\n\nprint(ans)\n", "passed": true, "time": 2.51, "memory": 15056.0, "status": "done"}, {"code": "def divisor(n):\n ass=[]\n for i in range(1,int(n**0.5)+1):\n if n%i==0:\n ass.append(i)\n if i!=n//i:ass.append(n//i)\n return ass\n_,k=map(int,input().split())\na=list(map(int,input().split()))\nfor ans in sorted(divisor(sum(a)))[::-1]:\n b=[i%ans for i in a if i%ans]\n n=len(b)\n b.sort()\n m=[0]+[i for i in b]\n p=[ans-i for i in b]+[0]\n for i in range(n):\n m[i+1]+=m[i]\n p[-i-2]+=p[-i-1]\n flag=False\n for i in range(n+1):\n if max(m[i],p[i])>k:continue\n if abs(m[i]-p[i])%ans!=0:continue\n flag=True\n if flag:print(ans);return", "passed": true, "time": 3.08, "memory": 14896.0, "status": "done"}, {"code": "import sys\nfrom itertools import accumulate\nN, K = list(map(int, input().split()))\n*A, = list(map(int, input().split()))\nS = sum(A)\n\ndiv_small = []\ndiv_large = []\nfor p in range(1, int(S**0.5)+1):\n if S % p == 0:\n div_small.append(p)\n if S // p != p:\n div_large.append(S//p)\ndiv_large += div_small[::-1]\n\nfor d in div_large:\n R = sorted([a % d for a in A])\n SR = sum(R)\n acc = tuple(accumulate(R))\n\n for i, l in enumerate(acc):\n r = d*(N-i-1)-(SR-l)\n if l == r:\n if l <= K:\n print(d)\n return\n else:\n break\n", "passed": true, "time": 0.89, "memory": 14900.0, "status": "done"}, {"code": "# \u7d04\u6570\u306e\u5217\u6319\n#############################################################\n\n\ndef make_divisors(n):\n lower_divisors, upper_divisors = [], []\n i = 1\n while i * i <= n:\n if n % i == 0:\n lower_divisors.append(i)\n if i != n // i:\n upper_divisors.append(n // i)\n i += 1\n return lower_divisors + upper_divisors[::-1]\n#############################################################\n\n\nN, K = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nsum_A = sum(A)\ndiv_list = make_divisors(sum_A)\nans = 1\n# print(div_list)\n\nfor div in div_list:\n tmp = []\n for a in A:\n tmp.append(a % div)\n tmp.sort()\n cumsum1 = [0]\n cumsum2 = [0]\n for i in tmp:\n cumsum1.append(cumsum1[-1] + i)\n if i != 0:\n cumsum2.append(cumsum2[-1] + (div - i))\n else:\n cumsum2.append(cumsum2[-1])\n for i in range(1, N):\n if cumsum1[i] <= K and cumsum2[N] - cumsum2[i] <= K:\n ans = div\n\nprint(ans)\n", "passed": true, "time": 1.8, "memory": 15036.0, "status": "done"}, {"code": "def divisors(N):\n return sorted(sum((list({n, N // n}) for n in range(1, int(N ** 0.5) + 1) if not N % n), []), reverse=True)\nN, K = map(int, input().split())\nA = tuple(map(int, input().split()))\nD = divisors(sum(A))\nfor d in D:\n L = sorted(a % d for a in A)\n if not sum(L):\n print(d)\n break\n left, right = 0, N - 1\n count = 0\n while left < right:\n if L[left] + L[right] <= d:\n next_right = right - (L[right] + L[left] == d)\n next_left = left + 1\n L[right] += L[left]\n count += L[left]\n L[left] = 0\n else:\n next_left = left\n next_right = right - 1\n m = d - L[right]\n count += m\n L[right] += m\n L[left] -= m\n left, right = next_left, next_right\n if count <= K:\n print(d)\n break", "passed": true, "time": 1.59, "memory": 15036.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na = list(map(int, input().split()))\ns = sum(a)\n\ncands = []\nfor x in range(1, int(s ** 0.5) + 1):\n if s % x == 0:\n cands.append(x)\n if x != s // x:\n cands.append(s // x)\n\ncands.sort(reverse=True)\n#print(cands)\n\nans = 0\nfor cand in cands:\n b = [a[i] % cand for i in range(n)]\n b.sort()\n sb = [0 for _ in range(n+1)]\n for i in range(n):\n sb[i+1] = sb[i] + b[i]\n #print(cand, sb)\n\n flg = False\n for i in range(n+1):\n x = max(sb[i], cand * (n - i) - (sb[n] - sb[i]))\n #print(i, sb[i], cand * (n - i) - (sb[n] - sb[i]))\n if x <= k:\n flg = True\n break\n\n if flg:\n print(cand)\n break", "passed": true, "time": 1.93, "memory": 15172.0, "status": "done"}, {"code": "import sys\n\nsys.setrecursionlimit(10 ** 7)\ninput = sys.stdin.readline\nf_inf = float('inf')\nmod = 10 ** 9 + 7\n\n\ndef make_divisors(n):\n divisors = []\n for i in range(1, int(pow(n, 0.5)) + 1):\n if n % i == 0:\n divisors.append(i)\n if i != n // i:\n divisors.append(n // i)\n divisors.sort()\n return divisors\n\n\ndef resolve():\n n, k = list(map(int, input().split()))\n A = sorted(list(map(int, input().split())))\n\n div = make_divisors(sum(A))\n res = 1\n for x in div:\n B = sorted([a % x for a in A])\n M, P = [0], [0]\n for i in range(n):\n M.append(M[-1] + B[i])\n P.append(P[-1] + x - B[i])\n M.pop(0)\n P.pop(0)\n for i in range(n - 1):\n m = M[i]\n p = P[n - 1] - P[i]\n if m <= k and p <= k and m % x == p % x:\n res = max(res, x)\n print(res)\n\n\ndef __starting_point():\n resolve()\n\n__starting_point()", "passed": true, "time": 2.37, "memory": 14980.0, "status": "done"}, {"code": "import sys\nsys.setrecursionlimit(10 ** 9)\n# input = sys.stdin.readline ####\ndef int1(x): return int(x) - 1\ndef II(): return int(input())\ndef MI(): return list(map(int, input().split()))\ndef MI1(): return list(map(int1, input().split()))\ndef LI(): return list(map(int, input().split()))\ndef LI1(): return list(map(int1, input().split()))\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\ndef MS(): return input().split()\ndef LS(): return list(input())\ndef LLS(rows_number): return [LS() for _ in range(rows_number)]\ndef printlist(lst, k=' '): print((k.join(list(map(str, lst)))))\nINF = float('inf')\n# from math import ceil, floor, log2\n# from collections import deque\nfrom itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations\n# from heapq import heapify, heappop, heappush\n# import numpy as np\n# from numpy import cumsum # accumulate\n\ndef solve():\n N, K = MI()\n A = LI()\n\n M = sum(A)\n divs = []\n for i in range(1, int(pow(M, 0.5))+1):\n if M % i: continue\n divs.append(i)\n if i != M//i: divs.append(M//i)\n divs.sort(reverse=True)\n\n for d in divs:\n B = list([x%d for x in A])\n B.sort()\n C = list([d-x for x in B])\n # print(d, B, C)\n # print(list(accumulate(B)), list(accumulate(C)))\n Ba = list(accumulate(B))\n Ca = list(accumulate(C))\n for i in range(0, N-1):\n b = Ba[i]\n c = Ca[-1] - Ca[i]\n # print(b, c)\n if b == c and b <= K:\n print(d)\n return\n print((1))\n\n\ndef __starting_point():\n solve()\n\n__starting_point()", "passed": true, "time": 1.15, "memory": 15112.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\nA = list(map(int,input().split()))\nS = sum(A)\nans = 1\ndiv = []\nfor i in range(1,int(S**0.5)+2):\n if S%i == 0:\n if S//i != i:\n div.append(S//i)\n div.append(i)\n else:\n div.append(i)\ndiv.sort()\nL = []\nfor i in range(len(div)):\n cur = div[i]\n mod = []\n for j in range(n):\n if A[j]%cur != 0:\n mod.append(A[j]%cur)\n if len(mod) == 0:\n ans = max(ans, cur)\n else:\n mod.sort()\n mod_dash = []\n for j in range(len(mod)):\n mod_dash.append(cur-mod[j])\n mod2 = [mod[0]]\n mod3 = [mod_dash[0]]\n for j in range(1,len(mod)):\n t = mod2[j-1]+mod[j]\n mod2.append(t)\n u = mod3[j-1]+mod_dash[j]\n mod3.append(u)\n c = 10**10\n for j in range(1,len(mod2)):\n c = min(c, max(mod2[len(mod2)-j-1],mod3[len(mod3)-1]-mod3[len(mod3)-j-1]))\n if c <= k:\n ans = max(ans, cur)\nprint(ans)\n", "passed": true, "time": 5.01, "memory": 15160.0, "status": "done"}, {"code": "n,k=map(int,input().split())\na=[int(x) for x in input().split()]\ns=sum(a)\n\ncandidates=set()\nfor i in range(1,int(s**0.5)+1):\n if s%i==0:\n candidates.add(i)\n candidates.add(s//i)\n\nans=0\nfor cdd in candidates:\n div_cdd=[0]*n\n for i in range(n):\n div_cdd[i]=a[i]%cdd\n div_cdd=sorted(div_cdd)\n # calc need\n idx=n-sum(div_cdd)//cdd\n need=0\n for i in range(idx):\n need+=div_cdd[i]\n ans=max(ans,cdd) if need<=k else ans\n \nprint(ans)", "passed": true, "time": 0.89, "memory": 15152.0, "status": "done"}, {"code": "import sys\n\nread = sys.stdin.read\nreadline = sys.stdin.readline\nreadlines = sys.stdin.readlines\nsys.setrecursionlimit(10 ** 9)\nINF = 1 << 60\nMOD = 1000000007\n\n\ndef divisors(n):\n lower = []\n upper = []\n for i in range(1, int(n ** 0.5) + 1):\n if n % i == 0:\n lower.append(i)\n if i != n // i:\n upper.append(n // i)\n\n lower.extend(reversed(upper))\n return lower\n\n\ndef main():\n N, K, *A = list(map(int, read().split()))\n\n total = sum(A)\n div = divisors(total)\n\n for d in reversed(div):\n vec = [a % d for a in A if a % d]\n if not vec:\n print(d)\n return\n vec.sort()\n M = len(vec)\n csum_sub = [0] * (M + 1)\n csum_add = [0] * (M + 1)\n for i in range(M):\n csum_sub[i + 1] = csum_sub[i] + vec[i]\n csum_add[i + 1] = csum_add[i] + d - vec[i]\n\n for i in range(1, M):\n if csum_sub[i] <= K and csum_sub[i] == csum_add[M] - csum_add[i]:\n print(d)\n return\n\n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 1.32, "memory": 15136.0, "status": "done"}, {"code": "def get_divisors(x):\n i = 1\n ret = set()\n while i * i <= x:\n if x % i == 0:\n ret.add(i)\n ret.add(x // i)\n\n i += 1\n\n return ret\n\n\nn, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nsm = sum(a)\ndivs = get_divisors(sm)\n\nans = 0\nfor div in divs:\n mods = [e % div for e in a]\n mods.sort()\n p = 0\n m = n * div - sum(mods)\n for mod in mods:\n p += mod\n m -= div - mod\n if p == m:\n if p <= k:\n ans = max(ans, div)\n break\n\nprint(ans)\n", "passed": true, "time": 0.94, "memory": 15072.0, "status": "done"}, {"code": "import math\n\nn,k=map(int,input().split())\n\nA=list(map(int,input().split()))\n\nx=sum(A)\n\nX=[]\n\nfor i in range(1,int(math.sqrt(x))+1):\n if x%i==0:\n X.append(i)\n X.append(x//i)\nX.sort(reverse=True)\n\nfor i in X:\n B=[]\n for j in range(n):\n B.append(A[j]%i)\n B.sort()\n if sum(B[:-1*(sum(B)//i)])<=k:\n print(i)\n break", "passed": true, "time": 0.67, "memory": 15168.0, "status": "done"}, {"code": "N,K=map(int,input().split())\nalist=list(map(int,input().split()))\n\nsum_a=sum(alist)\nalist.sort()\n#print(sum_a,alist)\n\n#M=1\u306e\u5834\u5408\u306b\u3082\u5bfe\u5fdc\ndivisor_set=set()\nfor i in range(1,int(sum_a**0.5)+1):\n if sum_a%i==0:\n divisor_set.add(i)\n divisor_set.add(sum_a//i)\ndivisor_list=list(divisor_set)\ndivisor_list.sort()\n#print(divisor_list)\n\nanswer=0\nfor d in divisor_list:\n rlist=[]\n for a in alist:\n rlist.append((a%d,(d-a%d)%d))\n rlist.sort()\n \n s1list,s2list=[0],[0]\n for r1,r2 in rlist:\n s1list.append(s1list[-1]+r1)\n s2list.append(s2list[-1]+r2)\n #print(d,s1list,s2list)\n \n for i in range(len(rlist)):\n r1sum=s1list[i]\n r2sum=s2list[-1]-s2list[i]\n if r1sum==r2sum and r1sum<=K:\n answer=d\n break\n \nprint(answer)", "passed": true, "time": 2.24, "memory": 14976.0, "status": "done"}, {"code": "from collections import deque\ndef isok(x):\n que=deque(sorted(z%x for z in a))\n res=0\n while que:\n l=que[0]\n if l==0:\n que.popleft()\n continue\n r=que[-1]\n if r==0:\n que.pop()\n continue\n d=min(l,x-r)\n que[0]-=d\n que[-1]=(que[-1]+d)%x\n res+=d\n return res\n \n\nn,k=map(int,input().split())\na=list(map(int,input().split()))\nsum_=sum(a)\n\nfac=set()\nfor i in range(1,sum_+1):\n if i*i>sum_:\n break\n if sum_%i==0:\n fac.add(i)\n fac.add(sum_//i)\n\nfac=sorted(fac,reverse=True)\nans=1\nfor x in fac:\n c=isok(x)\n if c<=k:\n ans=x\n break\nprint(ans)", "passed": true, "time": 2.32, "memory": 14944.0, "status": "done"}] | [{"input": "2 3\n8 20\n", "output": "7\n"}, {"input": "2 10\n3 5\n", "output": "8\n"}, {"input": "4 5\n10 1 2 22\n", "output": "7\n"}, {"input": "8 7\n1 7 5 6 8 2 6 5\n", "output": "5\n"}, {"input": "2 1\n1 1\n", "output": "2\n"}, {"input": "500 1000000000\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "500000000\n"}, {"input": "2 834276\n829289 870458\n", "output": "1699747\n"}, {"input": "2 1\n123817 819725\n", "output": "6\n"}, {"input": "2 411810\n561589 20609\n", "output": "582198\n"}, {"input": "2 2\n593967 290959\n", "output": "2\n"}, {"input": "2 426922\n243129 295272\n", "output": "538401\n"}, {"input": "2 2\n555782 754358\n", "output": "20\n"}, {"input": "9 453659\n60979 705813 913579 278694 782818 795359 44732 929966 831304\n", "output": "144412\n"}, {"input": "18 11\n513652 691723 327713 3573 278 203302 761284 125217 249435 17 200103 213023 753 440561 339013 3685 915608 957575\n", "output": "1\n"}, {"input": "5 303798\n233279 936038 30152 626165 894770\n", "output": "4244\n"}, {"input": "14 11\n585497 618838 999873 998905 999451 65474 332724 996156 631456 989790 999956 266177 168809 996188\n", "output": "2\n"}, {"input": "496 143612745\n577323 1 4 99829 619 657602 1 627656 26634 828423 66791 890222 849875 943454 330663 1 367068 1 909810 762354 163338 1 1 944683 960492 915295 223444 796681 306235 1 882479 1525 773499 1 889 232264 1 715173 494832 1 410632 645478 1 324735 840094 170757 1 147194 391322 278797 1 625305 1 1 910019 1 932782 1 53 627451 503657 625484 1 310815 1 332698 317382 80975 537812 864519 217146 536543 821480 3364 926128 825125 957769 1 1 371549 1 233730 917069 953183 808773 1 1 956579 493300 1 375783 157240 6074 1 322360 270167 132549 532086 1 1 98998 677594 131446 20545 811201 824993 308467 450722 928869 1 503884 1 159201 587083 429308 955057 590878 736958 543778 549143 564628 840936 712959 22834 228786 269516 284826 853739 390429 517984 287129 264839 1 113251 923336 957070 1 524545 1 1 380518 517232 1 1 395134 223358 1 23613 814268 50871 1 50407 507390 864366 1 217827 1 799855 1 1 215593 1914 136845 545831 175034 793244 695937 742128 593567 507606 1 402419 905422 233687 218319 748868 2766 18055 485213 104819 125733 839205 1 758203 1 1 653037 359945 1 138652 160082 768083 109237 46053 1 82544 674271 950752 166656 1 1 1 1 869865 1 1 749724 1 767949 995589 274072 1 335996 607115 1 133914 912543 2257 1 468991 506833 876641 850811 54088 85479 532551 1 1 774341 655605 238581 13 717026 309318 689741 488071 1 1 918182 359757 1 88767 327183 635138 155073 445730 1 137457 1 403494 627427 600135 1 405101 1 1 208781 531114 1 609347 61194 1 697472 609424 321419 1 1 1 1 347926 13638 348578 748386 237295 105018 992506 69747 697302 1 156596 245993 1 711444 1 748958 476196 269302 616532 387693 58251 1 243395 800248 932688 46408 477955 227442 190096 639726 743705 247374 1 1 489150 1 8588 496737 69767 847426 200402 163972 1 8204 177768 969868 614027 484709 258915 359930 1 1 324503 1 523872 490076 125131 741725 149292 325551 2119 905177 1 703064 436476 1 515074 968721 35969 710060 997665 1 752132 523483 805627 179673 1 579436 124199 1 956214 191397 411463 1 197465 640808 454111 448543 533920 850236 1 567699 1 8088 690193 605243 253622 894419 1 1 523900 522955 1 1 1 99891 206077 576461 387165 141429 1 307982 496230 48 646835 886161 810752 428118 1 3452 580936 218798 998817 157890 25600 1 519006 686356 89722 1 1 924989 1 1 634865 718832 196085 795403 916480 968508 281351 119546 240751 1 497756 620852 950510 2561 457740 972927 154002 1 391302 1 1 623311 3416 1 836015 4 137986 193895 1 1 472316 412898 451724 278275 586526 1 486074 733750 184105 138010 809582 1 1 98501 573818 832905 897921 962003 1 172344 449138 1 492629 806858 626705 522535 857259 1 670904 169523 562106 1 445088 224348 971547 27753 1 344761 186466 1 348939 679436 71516 1 736605 75438 396792 594258 621829 47972 860469 237907 196415 604987 818789 1 700249 1 1 634252 1 100522 901598\n", "output": "4323409\n"}, {"input": "500 30\n1000000 977013 1000000 1000000 1000000 1000000 475337 106308 27010 1000000 814397 1000000 793497 1000000 1000000 1000000 275683 332344 198618 1000000 1000000 1000000 96106 967744 1000000 1000000 1000000 1000000 1000000 391750 1000000 1000000 290817 479743 1000000 1000000 1000000 1000000 43331 1000000 104569 1000000 1000000 1000000 1000000 311327 370271 112822 1000000 64701 949178 941985 50582 1000000 864725 1000000 1000000 999429 661160 1000000 1000000 411892 1000000 1000000 505215 1000000 1000000 1000000 453356 1000000 309491 1000000 1000000 1000000 767957 437328 1000000 767784 191465 1000000 877619 1000000 418441 1000000 1000000 1000000 1000000 223595 796696 26690 858774 1000000 870215 1000000 1000000 695987 177735 905752 1000000 653500 1000000 261531 1000000 1000000 354206 1000000 1000000 1000000 38224 1000000 347150 1000000 1000000 1000000 372602 1000000 1000000 258682 1000000 1000000 664439 1000000 1000000 1000000 1000000 806845 329681 251991 1000000 33754 1000000 1000000 967976 536285 1000000 1000000 885012 1000000 1000000 1000000 1000000 540246 190410 1000000 743866 692311 1000000 1000000 1000000 626544 47382 1000000 1000000 1000000 1000000 983882 1000000 743569 1000000 198052 1000000 282901 1000000 1000000 1000000 1000000 1000000 796060 1000000 17055 72236 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 719021 1000000 653785 1000000 517502 1000000 1000000 1000000 670555 1000000 1000000 75585 1000000 1000000 1000000 1000000 33542 1000000 1000000 384816 1000000 1000000 1000000 1000000 1000000 412134 1000000 840209 1000000 1000000 1000000 336374 1000000 1000000 1000000 282717 1000000 1000000 516109 1000000 1000000 129442 1000000 981095 1000000 683615 311423 1000000 638684 1000000 136459 271248 999351 965848 1000000 1000000 1000000 230939 1000000 1000000 1000000 131784 405956 204089 802679 193867 1000000 261784 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 805721 372748 808385 1000000 587461 1000000 1000000 771038 60701 7062 1000000 1000000 1000000 1000000 65589 971899 1000000 1000000 1000000 1000000 656136 1000000 425020 1000000 1000000 400900 1000000 999662 1000000 793150 684100 1000000 718790 149334 236904 375656 1000000 1000000 1000000 1000000 1000000 1000000 894028 813888 1000000 1000000 1000000 412766 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 322125 1000000 339919 666734 1000000 1000000 1000000 6060 1000000 198114 1000000 1000000 907442 1000000 1000000 180537 1000000 225916 960346 1000000 1000000 1000000 1000000 517823 1000000 1000000 1000000 29902 1000000 1000000 1000000 1000000 1000000 1000000 1000000 631149 1000000 1000000 1000000 1000000 1000000 367879 1000000 1000000 1000000 1000000 341448 1000000 1000000 1000000 797607 1000000 1000000 1000000 121047 1000000 1000000 1000000 856281 1000000 1000000 230932 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 981905 1000000 1000000 761829 292640 1000000 829186 999998 1000000 645089 1000000 54195 107752 1000000 807516 1000000 425725 1000000 573831 1000000 735660 1000000 598790 1000000 1000000 1000000 1000000 155322 239470 1000000 585210 1000000 1000000 1000000 1000000 611007 1000000 1000000 1000000 492086 1000000 1000000 1000000 1000000 308254 1000000 1000000 4257 1000000 1000000 1000000 462816 930164 1000000 515310 575466 597654 1000000 1000000 1000000 81359 1000000 1000000 144868 1000000 1000000 1000000 510033 95439 1000000 652288 1000000 1000000 1000000 1000000 95827 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 167468 1000000 255129 193671 533718 1000000 1000000 1000000 91803 1000000 1000000 1000000 1000000 1000000 1000000 1000000 810260 999975 1000000 323426 1000000 862116 577058 1000000 1000000 316878 1000000 1000000 1000000 257130 1000000 404849 1000000\n", "output": "1\n"}, {"input": "482 7782029\n709172 1 1 1 1 1 1 700969 1 1 1 945725 7062 1 1 601320 1 1 1 441026 1 1 462950 1 294698 1 1 1 1 1 1 1 1 1 1 1 69845 1 1 1 1 1 1 1 1 1 1 1 1 863153 1 1 334985 1 1 1 1 15 1 1 682304 1 1 1 1 1 38588 1 1 910908 1 1 1 1 446329 1 1 868805 1 817638 1 1 1 120 1 1 1 1 1 895524 1 937309 1 1 1 1 1 1 1 1 1 6416 1 1 1 1 1 1 83048 1 309576 786374 1 1 1 1 96593 1 1 944235 1 354965 1 1 1 1 1 635544 1 1 102 955005 1 1 1 346608 1 1 1 1 521085 1 1 1 1 1 1 811354 446813 1 1 1 890734 1 1 1 1 1 1 1 865929 1 425 1 175565 1 1 1 1 1 1 1 1 1 1 1 1 884875 1 1 1 1 1 1 1 1 287177 1 1 1 1 1 1 1 447251 1 1 1 1 1 690854 704320 1 1 1 1 1 1 1 1 1 401350 1 1 1 1 1 1 1 1 1 1 1 1 1 77129 1 905424 469593 1 1 1 529529 1 1 1 556728 1 1 1 1 1 1 727573 1 1 18804 1 1 1 1 852661 1 1 624892 1 1 1 1 1 1 1 1 794627 2066 1 1 190071 1 1 1 1 1 1 1 1 1 452544 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 20215 1 1 1 1 1 1 1 1 1 1 1 526386 1 1 597835 960077 246242 1 1 457 1 252202 1 1 156457 1 336732 1 1 828627 1 847117 1 1 1 1 1 740835 1 1 1 680244 993297 1 1 1 1 1 386838 19206 1 1 1 1 1 1 10 1 1 1 1 1 598818 1 1 546347 1 1 1 464861 290545 1 1 5873 1 758484 1 1 694941 1 1 469595 560217 1 1 1 1 1 1 1 1 356162 1 1 1 1 1 1 1 1 1 1 1 1 1 12036 1 786717 1 1 1 1 302110 491771 239794 1 1 1 1 13 1 1 1 1 1 112181 1 1 1 1 1 1 7845 1 1 131652 274577 1 1 1 1 1 1 193796 1 1 1 1 141828 1 419803 1 9 1 60 1 1 1 1 1 1 1 1 1 1 1 1 1 149534 131895 455706 1 1 1 1 1 1 1 1 1 1 1 1 1 1 952475\n", "output": "343426\n"}, {"input": "493 95\n1 1 1 1 1 1 1 1 1 1 254 1 1 1 1 1 1 1 1 1 1 444590 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 90 1 1 1 1 1 1 1 1 1 517215 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 394771 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 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 668 1 1 1 1 1 1 1 1 597147 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 711355 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 15 1 1 1 1 36 211 886442 1 101271 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 345 1 1 1 1 242638 1 1 1 1 1 1 2320 1 1 1 1 1 1 1 1 13 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 270313 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 700619 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1459 1 1 43564 1 1 1 1 16746 1 1 1 1 1 1 1 1 1 1 481 1 1 1 437086 1 1 1 1 1 1 1 22898 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 388498 1 1 1 1 1 1 1 1 1 1 1 175410 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11035 1 1 736788 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 680006 1 1 1 1 1 1 1 1 259549 1 1 1 1 1 1 1 1 1 1 1 1 1 835793 1 1 1 1 1 1 1 1 1 1 1 357043 1 1 1 1 1 1\n", "output": "1\n"}, {"input": "489 208848192\n1000000 203713 1000000 1000000 1000000 1000000 779207 1000000 1000000 1000000 1000000 1000000 60202 47278 481054 99756 1000000 1000000 1000000 1000000 279601 1000000 1000000 440093 1000000 1000000 1000000 1000000 732416 358627 345757 1000000 141430 236585 804495 440937 1000000 1000000 468474 1000000 1000000 433472 1000000 107844 966674 85090 329213 609359 1000000 168783 591649 257510 557069 1000000 1000000 647940 1000000 128277 909710 1000000 676510 567068 1000000 995777 1000000 852662 1000000 891530 970358 1000000 1000000 1000000 1000000 759984 1000000 740017 722790 1000000 793627 371560 1000000 1000000 1000000 269296 1000000 1000000 1000000 877261 248259 576290 438396 1000000 602740 1000000 258544 1000000 893001 1000000 1000000 746437 1000000 1000000 1000000 727246 1000000 631652 168995 1000000 1000000 996518 1000000 156288 854857 1000000 16862 1000000 1000000 764086 526201 230804 489516 1000000 450971 1000000 1000000 1000000 1000000 132360 820471 1000000 1000000 673563 1000000 362496 1000000 713999 1000000 355697 1000000 517703 722291 1000000 1000000 1000000 550827 934571 1000000 1000000 1000000 298085 1000000 1000000 372877 251528 401238 115201 1000000 1000000 1000000 26284 543774 895553 1000000 816391 1000000 1000000 1000000 136033 1000000 1000000 105886 999997 1000000 999972 1000000 943509 55124 1000000 1000000 203352 387890 1000000 999996 1000000 884508 616591 394555 328619 1000000 1000000 1000000 1000000 449155 419414 1000000 891124 72743 254851 1000000 656492 1000000 1000000 1000000 552213 1000000 351015 158856 374703 812656 1000000 1000000 684852 105195 1000000 133283 1000000 999994 274118 835649 173766 1000000 317783 1000000 1000000 1000000 1000000 80733 967242 866783 882206 611015 1000000 1000000 462267 25333 1000000 878563 1000000 999487 97721 1000000 1000000 1000000 1000000 57685 816852 290447 969377 1000000 1000000 1000000 1000000 891159 1000000 940187 743184 1000000 1000000 566078 761722 270591 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 513527 277372 1000000 1000000 1000000 700677 382678 1000000 306218 809444 911153 18712 1000000 1000000 1000000 1000000 1000000 48551 838826 740590 1000000 1000000 1000000 109198 1000000 989067 323189 1000000 988390 424654 1000000 745623 533877 695147 1000000 1000000 352675 1000000 1000000 941957 1000000 1000000 956555 918579 1000000 1000000 1000000 714037 16555 918838 1000000 449628 990487 494970 893002 921167 371398 1000000 334902 620583 600831 1000000 1000000 1000000 1000000 149399 1000000 1000000 1000000 999994 1000000 635262 73703 1000000 295837 1000000 1000000 920981 1000000 296931 808585 1000000 1000000 1000000 426400 537605 339988 240550 435548 294805 1000000 864969 612539 1000000 999995 486364 813148 985722 1000000 1000000 301728 437351 122197 1000000 1000000 201230 1000000 800995 1000000 35719 66547 60970 575057 390337 105461 521464 1000000 1000000 294180 605754 1000000 1000000 957811 1000000 1000000 1000000 1000000 1000000 74984 1000000 655691 1000000 705656 1000000 127571 650684 999993 709152 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 118420 944686 1000000 809460 754650 1000000 1000000 819807 999865 1000000 70161 347955 713700 1000000 905511 1000000 150908 813127 181530 342332 805749 1000000 31487 1000000 1000000 1000000 1000000 1000000 1000000 1000000 978233 1000000 1000000 1000000 1000000 236283 636026 1000000 284503 1000000 681465 999991 50292 1000000 232600 1000000 250966 1000000 1000000 1000000 1000000 253683 603092 1000000 786238 880540 990614 887153 722004 911939 699094 1000000 782750 1000000 1000000 999999 1000000 1000000 1000000 1000000 446112\n", "output": "1464182\n"}, {"input": "500 153\n823822 202652 1000000 386974 1000000 1000000 677799 1000000 1000000 1000000 1000000 273155 48035 267410 801978 867387 1000000 1000000 1000000 1000000 88931 1000000 993092 64944 1000000 1000000 1000000 377952 1000000 1000000 858094 1000000 89156 1000000 813870 968151 942852 628466 936333 848587 1000000 440597 545572 827752 754648 1000000 1000000 1000000 1000000 999949 1000000 1000000 589378 137553 1000000 961009 1000000 1000000 543961 632372 286379 750132 861064 1000000 1000000 16494 1000000 682881 420296 1000000 830539 1000000 531131 993894 179310 988046 974967 58264 996093 729016 540026 1000000 1000000 1000000 913620 1000000 411136 371564 744602 960904 652447 427466 602508 1000000 540660 751984 1000000 312446 981892 1000000 1000000 1000000 954661 1000000 986512 1000000 508204 602398 395891 213148 1000000 758670 899206 1000000 236707 1000000 838768 109760 511052 1000000 545108 1000000 812750 335887 738810 1000000 99024 1000000 237780 887317 534333 1000000 1000000 534965 129564 352359 561717 1000000 869804 225873 1000000 1000000 523621 767328 1000000 436990 411192 427878 1000000 588831 1000000 289486 434301 280969 176500 957015 1000000 209455 991511 1000000 1000000 1000000 352863 568473 435552 998312 687280 1000000 199521 980017 1000000 1000000 1000000 1000000 998842 1000000 1000000 1000000 528379 269669 1000000 118277 105380 211663 535529 284763 102537 1000000 545312 767431 628186 53907 1000000 706372 117763 143365 1000000 679174 356609 689931 1000000 1000000 21350 946712 890134 516322 901927 1000000 1000000 1000000 182668 1000000 1000000 570111 854950 1000000 1000000 1000000 874135 950009 314644 898988 1000000 394372 286115 611659 1000000 528568 229250 1000000 83094 38275 586365 505425 529356 253927 88453 916621 1000000 1000000 1000000 549058 524694 242162 840361 54811 511846 905683 678745 1000000 1000000 1000000 946144 899951 1000000 1000000 953699 961684 1000000 1000000 478850 1000000 860156 13710 308534 1000000 181032 1000000 834015 925653 941336 895119 349644 1000000 525043 1000000 337520 381880 933422 48504 1000000 168252 1000000 1000000 269896 653355 304280 858862 86404 863109 754664 259638 139379 1000000 1000000 739565 306215 676600 1000000 165933 1000000 59599 366001 1000000 1000000 1000000 1000000 391403 309318 451744 1000000 1000000 1000000 222817 802179 999946 1000000 1000000 764028 1000000 700754 105601 257438 10805 142305 989431 808160 1000000 1000000 298365 833037 564452 994847 1000000 1000000 1000000 1000000 1000000 1000000 1000000 546660 298940 1000000 728837 4393 1000000 1000000 1000000 445330 814960 937387 1000000 1000000 1000000 917316 1000000 1000000 1000000 1000000 207335 89086 750075 340516 812391 1000000 770679 358733 530193 952494 1000000 639124 652699 1000000 852793 204143 436257 1000000 45646 294958 991657 1000000 1000000 462660 72102 835259 841672 529329 1000000 579484 1000000 1000000 1000000 117966 610990 169434 1000000 1000000 1000000 476136 1000000 960675 802853 828280 662815 1000000 384704 999490 159455 1000000 1000000 1000000 745194 1000000 500207 1000000 747332 573909 1000000 1000000 531522 538551 1000000 791405 1000000 337276 535960 938102 923245 175941 730164 894332 399468 598634 42574 1000000 837092 314647 862207 305558 60101 725067 1000000 261610 1000000 1000000 816872 916738 1000000 1000000 1000000 1000000 1000000 1000000 949445 435953 255582 45344 308738 277684 1000000 673343 875603 406075 107254 977518 974635 1000000 1000000 11972 18784 130939 229721 1000000 741530 518086 1000000 324252 310073 827238 881680 643155 37768 1000000 1000000 1000000 362069 634240 635577 1000000 1000000 1000000 402054 1000000 1000000 1000000 113935 524919 219289 458145 1000000\n", "output": "2\n"}, {"input": "493 90356827\n831971 963581 542088 336502 434265 307999 487050 1 114907 707882 647039 797676 716300 79984 412374 488184 730857 69095 8143 503130 689912 262550 32 288974 145694 1 435738 895139 1 800375 234623 429302 38044 226142 98101 447847 311215 854414 337329 1 529234 61810 575159 140198 81838 742439 1 634225 113852 250725 306662 778419 106841 852447 631577 528591 439645 473889 793915 487617 85813 164626 583812 272323 323020 945181 566311 1 523481 2 224676 126002 739089 8 22416 355291 884004 930180 606830 443912 325530 133890 155331 890858 810540 38402 729881 449977 556118 3444 584686 883677 661355 834304 422746 864228 466364 10 118638 833978 163053 877143 425189 693566 81050 623295 746609 881179 366465 235374 60436 1 400380 322645 784467 963843 153514 950556 313884 20756 978075 612186 502753 133718 129325 522359 967834 90742 829998 558628 499134 914365 481676 835769 430692 593340 867384 330704 1 52126 11 850260 517 930213 609660 780290 116921 1 959735 672712 1 3 298359 1 265229 173138 118245 879053 422791 187453 40345 67590 461397 252110 866916 615626 777255 1 1 960863 245254 784465 818826 159387 30370 269255 1 620844 18853 308859 936959 871253 937306 1 810026 35986 2 973889 148285 363093 271688 710429 1 796416 874088 206239 607454 157235 43286 22636 848092 308506 826771 777533 111423 794434 940737 332853 1 521210 532188 308528 263627 575717 744047 789139 258451 114879 720421 452343 507747 158347 223773 268902 483045 579405 754062 613348 764203 183065 167667 88223 1 363558 68214 693697 1 988316 813893 362140 518427 148364 706271 702 182236 226365 36341 666832 839948 744994 1 719605 480283 990160 51850 478184 902938 328645 493182 729813 1 122059 1967 791630 90475 821449 818871 770790 75985 471278 160870 732807 273265 947900 677346 362257 202411 886990 1 830138 262087 246308 346650 888080 346396 667628 834967 5 888177 1 166556 30480 121824 1 427480 529256 408360 1 497876 459106 957857 586515 380081 174387 499384 478034 22686 803775 646416 10232 278256 806947 486154 583793 51397 386910 2 53 430103 442585 227108 270581 563210 726906 379506 673449 288789 1 162189 177543 980124 539253 193122 390944 88547 630277 359976 252619 166123 507108 1 155584 613387 663509 421355 538940 753487 614164 10 283111 683403 700890 877033 178609 5718 872221 28096 374072 807095 752609 565201 18 488724 58776 125142 329 988153 91405 19697 553262 821107 925150 555172 695361 174226 931748 1 746862 482280 33120 418030 202462 539087 11909 458753 460513 193626 181982 386492 78778 828965 327673 752849 663248 192955 234462 579719 1 219794 150171 329269 781058 719188 92008 751453 188698 524707 831801 637236 641193 147025 740613 416317 786522 330085 549260 673708 858755 477773 338448 733757 917511 46213 147297 932817 351757 978268 378251 533935 562800 776352 409867 245886 1 465144 442802 607164 299460 191087 48440 509916 549504 618735 906108 99749 92186 138114 334170 800855 349961 641524 485683 848270 1979 149418 699969 122991 400494 557604 115287 32741 591884 1 568869 538241 365426 463664 607026 960481 933023 567713 317395 117490 475852 124685 247046 515022 695457 838912 167382 841335 1 847611 799800 752214 475218 784263 542385 1 1 144131 768603 762491\n", "output": "20717\n"}, {"input": "490 124\n768552 116654 1 1 1 806039 1 1 1 1 1 768227 921453 171167 1 1 190972 230167 1 1 1 780378 1 415751 812996 1 33195 622492 1 1 661491 588926 801526 1 1 634422 921727 899025 572158 1 170695 623924 489467 1 660066 819338 1 654991 1 1 703835 1 1 525014 857815 208717 1 1 488391 1 1 1 493263 466120 1 378413 63301 406808 1 1 81155 878038 610737 1 1 644401 1 1 806823 1 50917 1 1 603533 1 1 1 840937 1 1 5397 600534 625371 1 455790 10827 23442 842430 711381 1 1 516271 1 1 1 822329 369307 1 481582 1 1 1 1 1 1 979416 1 256876 1 1 282680 1 1 21389 1 1 1 150211 1 10157 281230 1 337803 1 713881 443225 1 1 641578 1 1 105200 582712 562195 965183 980141 1 668500 1 944302 1 1 401041 172581 1 542068 89748 34305 601665 281771 1 1 930479 1 1 1 608698 1 977398 1 1 146741 1 729625 1 1 1 69475 647824 1 1 264171 1 461511 1 240913 1 1 831540 1 1 1 777472 362404 663201 1 93833 1 1 78249 855477 1 948736 1 1 172053 949102 361800 548916 106555 461014 1 1 1 960379 1 222729 1 640527 364037 1 603578 226516 1 1 778674 1 1 590663 756309 1 1 1 1 1 1 1 284215 1 1 1 8 154349 198776 906313 1 82812 1 1 72567 1 1 1 1 1 648241 405531 1 343603 5561 1 1 603465 1 517005 1 1 882529 1 852374 1 1 133203 1 643407 1 1 1 1 655066 8794 170035 1 1 2 282915 177647 1 808827 601408 1 1 1 1 284552 852024 939468 1 1 1 1 1 309167 1 799776 148570 890668 1 1 723383 708244 982036 549040 1 1 1 546466 120484 1 260002 1 15537 360463 1 683010 824171 254511 135 146229 1 1 1 1 1 52075 1 94280 1 303806 890984 381544 911928 1 1 1 1 1 1 1 1 535429 286299 1 549 396167 745700 115336 943155 1 210099 1 59284 1 1 567096 1 95061 1 295376 1 1 800656 1 546641 1 1 252411 163655 1 16574 450890 1 151784 1 1 1 1 807175 40303 1 1 1 762354 229046 1 1 694520 741480 1 1 1 1 1 594802 901348 522888 809709 459516 507196 220894 1 1 388974 1 374105 709924 12909 193357 92799 1 821329 1 652859 1 134421 1 629972 1 1 1 1 443474 298974 903376 149343 89181 1 1 1 772067 1 1 1 1 1 1 1 810514 1 1 366373 1 260045 1 73750 750402 173010 150254 1 17347 1 245582 548275 46617 19625 1 1 1 1 330223 56378 451600 1 369206 826841 1 1 682817 235049 727437 1 1 1 1 1 803517 426558 231269 1 680889\n", "output": "1\n"}, {"input": "483 594773048\n1000000 996289 1000000 429349 973226 992436 845303 931570 999811 960106 1000000 1000000 965435 422055 990486 952203 1000000 1000000 1000000 649428 856735 999569 970146 371418 1000000 412502 158977 856158 972317 1000000 996925 977785 391832 860900 898897 1000000 1000000 952948 660749 999999 966032 1000000 1000000 996124 1000000 1000000 1000000 1000000 867262 940102 951088 1000000 466113 877283 772852 1000000 942949 999994 267880 1000000 945563 1000000 1000000 962295 958239 725390 1000000 916112 1000000 1000000 1000000 650638 1000000 697593 1000000 963521 980728 935468 710017 896595 1000000 1000000 827924 788164 1000000 1000000 1000000 1000000 589901 1000000 964006 1000000 993531 1000000 1000000 1000000 971860 1000000 704938 930598 816449 1000000 1000000 611353 993989 452087 746222 1000000 476316 681437 1000000 1000000 1000000 1000000 934458 979354 1 1000000 991466 993234 998438 876630 589040 876481 912810 1000000 962241 986267 1000000 1000000 990209 985900 930019 704704 987126 127059 1000000 903616 1000000 486582 1000000 985005 922821 628605 1000000 1000000 1000000 633419 829199 1000000 967835 488000 984698 1000000 960290 720310 507557 791443 890418 884227 999436 1000000 929301 1000000 859272 789010 290825 1000000 982399 1000000 1000000 932580 999995 1000000 699267 1000000 937296 1000000 294664 998748 999768 1000000 1000000 995646 1000000 1000000 1000000 999994 318080 1000000 839164 1000000 1000000 1000000 967411 1000000 1000000 923768 1000000 885769 988822 1000000 827476 1000000 1000000 998501 1000000 978254 1000000 1000000 1000000 803639 997544 999976 932777 772394 925135 1000000 999983 1000000 961462 1000000 1000000 1000000 1000000 910229 1000000 874024 991400 1000000 997718 981056 999993 995329 676458 981598 837504 1000000 672053 1000000 976542 555064 1000000 960451 319964 862964 1000000 871909 822310 997155 1000000 717275 1000000 1000000 264693 1000000 845991 1000000 978736 838413 986494 992322 535760 757515 952948 435950 1000000 1000000 1000000 875328 659178 984332 1000000 904851 999999 756994 624363 999999 991458 940089 964881 1000000 1000000 906970 1000000 1000000 6742 1000000 999374 993424 467494 795640 1000000 893960 1000000 253112 1000000 583206 642713 1000000 992145 744126 741059 1000000 1000000 612297 725994 1000000 947853 1000000 1000000 658292 815088 932788 966062 1000000 999999 1000000 877095 1000000 501549 751936 762788 1000000 996690 999934 1000000 719677 1000000 670540 991242 995876 1000000 1000000 999988 1000000 997854 1000000 1000000 1000000 1000000 1000000 1000000 951964 1000000 782639 1000000 993892 973153 341233 1000000 446303 1000000 587609 999994 1000000 1000000 1000000 999971 974122 1000000 1000000 1000000 1000000 883346 991920 934377 999999 990393 444858 954015 932667 1000000 266130 928987 998496 938820 999994 1000000 1000000 1000000 983585 992730 893975 1000000 995784 1000000 934091 1000000 1000000 993151 975399 999999 986696 1000000 1000000 967866 956868 999816 1000000 999999 1000000 972063 1000000 884876 771050 356618 967944 1000000 996042 1000000 1000000 991622 970862 1000000 560332 992771 993140 833316 974954 948405 1000000 263459 1000000 978733 875958 996130 970248 1000000 981534 975232 997412 1 987832 786925 1000000 1000000 999990 1000000 981101 999902 834921 978329 466551 1000000 1000000 1000000 913673 949099 900889 856774 1000000 1000000 802903 1000000 767712 889291 961260 1000000 996840 1000000 994233 985674 44083 618542 960117 937525 541140 1000000 917924 997960 991167 999999 999879 956039 739464 1000000 977261 1000000 127469 1000000 999999 659408\n", "output": "432626200\n"}, {"input": "494 239761345\n879331 782877 999999 993274 1 999999 1000000 759744 1000000 972819 695436 732939 993819 1000000 1000000 1000000 999995 972982 995938 1000000 999999 514435 178093 1000000 755337 1000000 951261 1000000 990924 999628 558113 1000000 987676 1000000 1000000 997380 991748 983888 719516 1000000 996668 999969 1000000 992984 991870 981749 841710 986072 1000000 582649 1000000 1000000 1000000 1000000 549872 68282 996966 999655 989595 995038 656842 1000000 1000000 999965 1000000 999770 442374 756879 1000000 881089 993252 915029 996531 1000000 1000000 981834 946908 995522 986886 684656 991505 999820 1000000 957209 1000000 791029 519851 1000000 1000000 978383 952663 898976 778960 999864 563215 995972 1000000 734359 970011 982250 1000000 1000000 1000000 1000000 998531 581087 161336 995410 957156 858023 988723 830618 636376 968643 917712 990625 999335 772780 1000000 956268 960518 983821 997481 796410 1000000 899252 343047 144185 851168 1000000 851746 550524 999999 959562 1000000 816905 871848 999918 873546 1000000 256036 974029 1000000 781242 682090 999428 964944 933971 944118 976854 999459 912108 1000000 168391 663411 827928 1000000 998515 867630 727710 851880 998035 78143 656253 991523 1000000 185321 390792 400663 1000000 159123 1000000 999004 830936 624448 993704 649767 998708 997763 958380 954427 998691 999277 1000000 1000000 1000000 993053 346755 1000000 1 897895 886096 1000000 1000000 996322 991261 956555 798559 911486 899332 952924 879957 1000000 956199 999729 1000000 633539 991847 8323 914364 986265 254922 1000000 1000000 1000000 998296 747290 783738 999999 961967 999999 852484 999999 1000000 998246 1000000 702565 992219 993267 997646 1000000 857709 690483 967855 251169 1000000 982337 835523 999998 992355 876570 325663 953972 614538 998976 1000000 989888 729951 1000000 988625 928084 1000000 1000000 999707 1000000 1000000 982153 943293 1000000 993911 1000000 348377 1000000 999944 981483 929503 569553 1000000 996238 925242 992768 1000000 1000000 999887 967962 212811 1000000 999999 1000000 1000000 904823 1000000 677047 1000000 924838 808064 793244 946107 999889 958404 978733 998250 767825 985374 1000000 1000000 331694 634123 1000000 1000000 15437 954376 994382 1000000 992439 875037 482132 983812 990025 1000000 1000000 977024 842789 1000000 986325 999990 894512 3018 949916 965525 1000000 878903 1000000 106419 915605 571466 909685 378752 157835 1000000 1000000 986092 891121 999017 972690 1000000 777198 1000000 844092 1000000 660576 989252 999970 999799 989533 829239 999617 923649 924957 911034 158581 1000000 1000000 1000000 947723 434789 992318 941567 986333 947199 849327 994371 999983 1000000 1000000 649842 1000000 986878 1000000 946164 985337 993392 1000000 1000000 1000000 977420 1000000 1000000 968931 997744 1000000 1000000 1000000 864119 1000000 1000000 897116 776741 970537 620544 1000000 948495 998256 995914 991624 879141 915859 999986 1000000 1000000 962997 572582 1000000 756474 965251 966672 1000000 1000000 1000000 1 983662 1000000 1000000 871122 982905 994009 1000000 720335 1000000 760969 942509 28277 696570 999560 954930 1000000 997875 999991 999940 1000000 1000000 441994 925588 1000000 1000000 999999 1000000 586502 865452 293318 999999 865189 1000000 1000000 1000000 942357 1000000 999990 999321 1000000 991651 998342 1000000 1000000 828667 745864 1000000 1000000 887823 815745 986105 1 990536 925841 1000000 822210 1000000 984613 997324 1000000 912600 454451 1 999773 1000000 908966 999999 993127 999995 974795 984032 572633 946350 1000000 943960 995799 967030 1000000 994236 999975 998105 989739 408545 127027\n", "output": "2095743\n"}, {"input": "496 117295257\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 776912 1000000 1000000 1000000 1000000 1000000 1000000 971140 1000000 1000000 1000000 1000000 1000000 1000000 999999 194228 1000000 971140 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999454 999999 999875 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 582684 1000000 1000000 1000000 582684 1000000 1000000 1000000 1000000 1000000 1000000 1000000 388583 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 971140 1000000 1000000 1000000 1 1000000 976165 1000000 1000000 1000000 1000000 779525 1000000 1000000 999994 1000000 1000000 1000000 1000000 1000000 776912 1000000 1000000 1000000 1000000 998187 1000000 1000000 1000000 1000000 1000000 1000000 1000000 682043 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 862514 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 196003 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 776912 1000000 1000000 1000000 1000000 971140 975541 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 971221 971140 1000000 1000000 1000000 979926 582691 1000000 1000000 1000000 1000000 1000000 194228 1000000 999999 1000000 1000000 1000000 1000000 925248 1000000 1000000 1000000 1000000 1000000 1000000 205074 1000000 194228 1000000 1000000 1000000 1000000 388456 999999 776912 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 194228 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 194228 1000000 1000000 1000000 582684 1000000 999997 1000000 1000000 1000000 194228 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 971154 1000000 194228 1000000 388457 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 776912 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 388456 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 194228 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 999194 776912 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 388457 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 999221 1000000 1000000 1000000 1000000 1000000 1000000 582684 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 582684 1000000 194890 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 194228 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 796456 1000000 971140 1000000 1000000 999571 1000000 1000000 582684 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 587 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 971140 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 989495 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 388456 388456 1000000 1000000 1000000 1000000 1000000 1000000 1000000 194229 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999842 1000000 1000000\n", "output": "1132448\n"}, {"input": "490 95415357\n626785 1000000 1000000 1000000 877499 1000000 999977 1000000 1000000 1000000 1000000 1000000 376071 626785 1000000 1000000 1000000 752142 1000000 1000000 1000000 1000000 1000000 376071 1000000 1000000 1000000 501428 1000000 1000000 1000000 1000000 125357 1000000 1000000 1000000 1000000 501428 1000000 1000000 1000000 1000000 1000000 1000000 1000000 501428 1000000 1000000 1000000 1000000 125357 1000000 1000000 1000000 1000000 877504 1000000 999442 1000000 1000000 1000000 1000000 752998 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 376071 1000000 1000000 626785 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 250714 1000000 1000000 501428 125362 250714 1000000 999934 1000000 1000000 999999 377624 1000000 501428 1000000 1000000 996114 752142 1000000 1000000 867361 1000000 1000000 1000000 1000000 752142 1000000 501428 1000000 1000000 376071 1000000 1000000 1000000 1000000 1000000 250750 752142 1000000 1000000 501428 1000000 1000000 125357 1000000 1000000 1000000 1000000 1 999999 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 626785 1000000 1000000 250714 877499 376071 992479 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 501429 250714 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 250714 999988 752142 125357 1000000 1000000 1000000 376071 626793 1000000 1000000 1000000 1000000 1000000 1000000 877499 1000000 1000000 1000000 999999 1000000 1000000 250714 997477 1000000 1000000 1000000 1000000 626785 999999 250714 1000000 1000000 1000000 877499 1000000 1000000 1 1000000 1000000 1000000 1000000 821367 1000000 250714 501428 125357 125357 125357 127161 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 877499 1000000 1000000 1000000 1000000 125357 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 752142 501428 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 501428 1000000 501428 125359 1000000 125357 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 752142 1000000 1000000 1000000 627048 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 752142 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 501428 626785 1000000 1000000 1000000 1000000 1000000 752142 1000000 1000000 1000000 376071 1000000 1000000 1000000 1000000 1000000 501428 1000000 1000000 1000000 1000000 752142 1000000 376071 1000000 1000000 1000000 501428 1000000 1000000 1000000 997199 1000000 1000000 395 1000000 125357 1000000 1000000 1000000 877499 1000000 1000000 1000000 1000000 250714 999999 1000000 1000000 1000000 1000000 125357 1000000 1000000 877499 1000000 999993 1000000 626785 1000000 877499 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 125357 1000000 1000000 1000000 1000000 877499 1000000 1000000 1000000 1000000 1 752142 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 626785 1000000 1000000 1000000 1000000 1000000 1000000 1000000 501428 1000000 1000000 626785 1000000 877499 626785 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 250714 1000000 1000000 877499 1000000 1000000 1000000 1000000 877499 376071 1000000 997718 1000000 626785 1000000 1000000 553792 752142 1000000 1000000 1 1000000 1000000 1000000 1000000 250714 125361 1000000 1000000 1000000 1000000 125357 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "924274\n"}, {"input": "484 153770869\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999635 1000000 999926 1000000 999998 1000000 995462 1000000 1000000 1000000 1000000 999890 1000000 997233 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 999999 1000000 1000000 1000000 999959 1000000 998968 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 986347 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999905 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 994986 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999859 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 994230 1000000 1000000 1000000 1000000 1000000 1000000 988907 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999736 1000000 1000000 999999 1000000 1000000 999781 1000000 1000000 984542 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 996834 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999527 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 995104 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 999866 1000000 1000000 1000000 999956 999714 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999890 946812 1000000 1000000 999967 997482 1000000 1000000 999970 1000000 999999 1000000 1000000 1000000 1000000 998413 1000000 1000000 1000000 999993 999999 1000000 1000000 1000000 1000000 999955 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 966979 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999942 1000000 1000000 1000000 1000000 1000000 999999 1000000 965628 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999563 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999961 1000000 1000000 1000000 1000000 1000000 1000000 996534 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999827 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999904 1000000 1000000 961259 1000000 1000000 999987 1000000 999981 1000000 1000000 1000000 1000000 1000000 999979 1000000 1000000 1000000 999974 999859 1000000 999960 999943 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 987991 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 992306 1000000 1000000 1000000 1000000 1000000 1000000 1000000 991123 999992 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999977 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "1289956\n"}, {"input": "486 129982195\n1000000 1000000 400021 1000000 825894 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999805 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 610396 603035 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999961 1000000 1000000 1000000 1000000 1000000 1000000 1000000 608038 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1305 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 681 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999991 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999996 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 512596 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999478 440328 1000000 1000000 806167 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999996 1000000 1000000 1000000 999968 1000000 999917 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 414232 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 680595 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 980498 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999981 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 998820 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 894313 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "199990\n"}, {"input": "481 433328578\n1000000 1000000 999967 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999933 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999169 1000000 1000000 1000000 980985 1000000 999993 1000000 1000000 999999 1000000 1000000 999963 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 994935 1000000 1000000 1000000 999817 1000000 999995 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999993 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999901 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999950 1000000 997601 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 995696 999886 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999973 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999919 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 998976 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 998133 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999992 1000000 1000000 1000000 1000000 999788 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999892 1000000 1000000 1000000 1000000 1000000 1000000 999163 1000000 1000000 1000000 993446 1000000 1000000 999996 1000000 999988 1000000 1000000 1000000 1000000 1000000 999997 1000000 999986 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999996 1000000 1000000 999166 1000000 1000000 1000000 999972 998053 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999981 1000000 1000000 1000000 999939 1000000 1000000 1000000 999990 1000000 1000000 1000000 999989 1000000 1000000 999999 1000000 1000000 997932 1000000 1000000 1000000 1000000 999997 1000000 999990 1000000 1000000 999999 982534 1000000 1000000 1000000 1000000 999997 1000000 1000000 1000000 1000000 1000000 999994 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999986 1000000 1000000 1000000 999875 1000000 1000000 1000000 1000000 1000000 1000000 999975 1000000 1000000 996096 1000000 1000000 1000000 1000000 999804 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999973 999991 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999988 1000000 1000000 1000000 1000000 1000000 999999 999998 1000000 1000000 1000000 1000000 999988 999774 997198 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999203 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999959 1000000 999998 1000000 1000000 999986 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 999318 1000000 1000000 988131 1000000\n", "output": "7514278\n"}, {"input": "495 139161575\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 865278 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999992 1000000 995472 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 884835 998636 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999388 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999993 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "1366695\n"}, {"input": "498 116624261\n999945 1000000 1000000 1000000 1000000 1000000 1000000 985832 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 743666 1000000 1000000 732288 1000000 999999 1000000 1000000 457680 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 813333 1000000 1000000 1000000 366144 1000000 9 1000000 1000000 1000000 1000000 1000000 1000000 366144 1000000 1000000 1000000 1000000 1000000 823823 1000000 1000000 1000000 1000000 1000000 915360 732308 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 183381 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 366144 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 964313 1000000 1000000 366144 999989 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 732288 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 823824 274608 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999572 1000000 1000000 549216 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 805044 1000000 1000000 977368 1000000 999704 1000000 1000000 855583 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 457680 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 91536 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 457683 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 823824 1000000 1000000 1000000 1000000 1000000 1000000 1000000 549216 1000000 1000000 1000000 1000000 1000000 549220 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 457680 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 458468 1000000 1000000 999999 1000000 999999 1000000 274660 1000000 1000000 1000000 1000000 1000000 1000000 1000000 823824 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 640752 1000000 1000000 640752 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 457680 1000000 1000000 1000000 185743 1000000 1000000 1000000 1000000 549216 999920 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 823824 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 551757 1000000 1000000 274608 1000000 1000000 1000000 1000000 1000000 549217 915360 1000000 1000000 162239 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 549216 1000000 1000000 1000000 1000000 183072 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 640752 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 593431 274608 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 732288 1000000 915360\n", "output": "1189968\n"}, {"input": "495 119556913\n1000000 1000000 1000000 127086 756767 838404 1000000 1000000 1000000 1000000 1000000 955793 1000000 1000000 1000000 1000000 1000000 1000000 14 918394 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 976303 999974 1000000 1000000 943747 1000000 1000000 1000000 1000000 1000000 1 1000000 879221 985409 1000000 1000000 987825 1000000 1000000 1000000 1000000 1000000 1000000 979605 999966 997834 975173 1000000 919430 1000000 1000000 1000000 1000000 1000000 997815 1000000 967253 1000000 1000000 1000000 1000000 999996 1000000 1000000 1000000 847008 1000000 1000000 1000000 1000000 1000000 1000000 999286 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 343729 999998 1000000 273377 662422 1000000 1000000 1000000 1000000 1000000 1000000 993464 999743 999642 1000000 1000000 381827 879355 1000000 282257 1000000 317628 1000000 1000000 999999 1000000 1000000 994222 987467 1000000 998870 1000000 1000000 1000000 999999 1000000 1000000 423505 1000000 998224 1000000 1000000 1000000 982891 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 826282 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 989339 1000000 995364 1000000 1000000 998727 968597 1000000 1000000 717744 1000000 896408 1000000 634407 1000000 346506 1000000 1000000 1000000 1000000 1000000 999993 999540 1000000 1000000 588868 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 992306 1000000 968553 1000000 999980 245669 987428 1000000 964885 999781 997549 987048 1000000 999974 1000000 999943 874719 1000000 903669 999319 1000000 1000000 1000000 1000000 990918 1000000 1000000 977586 1000000 1000000 999126 994880 1000000 975295 1000000 936019 1000000 1000000 1000000 1000000 1000000 1000000 1000000 996229 1000000 1000000 434157 1000000 1000000 983353 1000000 1000000 285636 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 996796 1000000 1000000 1000000 722293 1000000 1000000 993686 1000000 877418 997973 1000000 907298 1000000 477010 995929 1000000 831123 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999408 954462 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 998139 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 966850 1000000 1000000 893153 1000000 1000000 1000000 863655 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 988327 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 980512 1000000 1000000 1000000 922582 765959 1000000 1000000 997121 1000000 232734 1000000 1000000 378440 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 29643 1000000 1000000 1000000 940542 1000000 1000000 1000000 236712 765905 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 948895 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999978 1000000 679892 1000000 981076 326710 1000000 1000000 1000000 1000000 1000000 740882 1000000 1000000 1000000 1000000 995817 999671 1000000 591488 1000000 1000000 211752 999974 1000000 1000000 1000000 1000000 1000000 905116 1000000 997327 1000000 289240 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 999107 738213 1000000 1000000 974642 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 964557 728014 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 923605 999996\n", "output": "1244043\n"}, {"input": "495 101703237\n999997 1000000 834218 1000000 1000000 1000000 748046 1000000 999999 1000000 1 1000000 834218 1000000 417109 1000000 1000000 834218 1000000 1000000 1000000 138519 952318 1000000 1000000 1000000 1000000 1000000 1000000 999797 1000000 1000000 170091 1000000 1000000 834218 1000000 834218 9 1000000 1000000 1000000 1000000 1 1000000 1000000 834218 1000000 1000000 417204 1000000 1000000 1 1000000 1 1 999999 1000000 1000000 1000000 999999 1000000 999999 1000000 1000000 834218 1000000 1000000 999999 980941 884032 1000000 1000000 1000000 999570 628032 110609 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 834218 417109 800299 1000000 1 1000000 999999 417109 1000000 834218 1 695699 1000000 417109 417109 118218 1000000 1000000 834218 1000000 1000000 1000000 1000000 1000000 1000000 1000000 417110 1000000 1000000 417187 1000000 1000000 1000000 417110 1000000 1000000 999999 834217 1000000 417109 1000000 1000000 1000000 834218 1000000 9566 1000000 1000000 417109 921171 972252 591547 16 1000000 417109 1000000 417109 1000000 1000000 1000000 1000000 1000000 417109 857720 1000000 1 999999 1000000 1 1000000 417109 1000000 1000000 417109 1000000 1000000 999993 1 1000000 1000000 1000000 834218 834218 834218 1000000 834218 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 925721 1000000 1000000 1000000 1000000 1000000 834218 1000000 1000000 999999 1000000 571651 1000000 1000000 999999 1000000 1000000 1000000 999999 1000000 1 999999 1000000 1000000 1000000 451933 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999905 1000000 417109 1000000 834218 1000000 1000000 1000000 834218 743291 864327 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 120 1 1000000 999999 1000000 876314 1000000 1000000 999999 855212 1000000 1000000 1000000 834217 834218 969891 1000000 1000000 1000000 1000000 417109 834218 1000000 1000000 1000000 1000000 976504 1000000 1000000 417109 1000000 1000000 1000000 1000000 1000000 1000000 1000000 417109 1000000 834218 1000000 1000000 1000000 1 525246 999999 999999 1000000 829910 1000000 1000000 999999 1000000 1000000 1000000 1000000 1 1000000 1000000 999999 1000000 1000000 1 1000000 1000000 999999 91274 834218 1000000 1 1 1000000 1000000 1000000 999999 926747 1000000 834218 374758 1000000 534259 123687 1000000 1000000 1000000 1000000 1000000 984846 1000000 171400 1000000 1000000 1000000 1000000 561897 417109 1 1000000 1000000 1000000 1000000 417109 1000000 1000000 1000000 1000000 999948 1000000 1000000 1000000 881900 834218 417109 834218 1000000 1 873206 1000000 417109 1000000 1000000 999999 1000000 1000000 1000000 986807 1000000 1000000 417109 1 1000000 1000000 1000000 896667 1000000 1000000 1000000 417108 1000000 1000000 900605 1000000 1000000 1000000 1000000 1000000 1 1000000 999999 1000000 834218 1000000 1000000 1000000 1 1000000 465742 1000000 1000000 1000000 1000000 1000000 1000000 999999 1 1000000 999989 847659 1000000 417109 1000000 1000000 1000000 999999 417861 1000000 834218 616812 1000000 417596 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 417109 152342 1000000 1 1 999999 834218 1000000 1000000 1000000 1000000 1000000 1000000 999999 242672 1000000 1000000 1000000 913047 836694 1000000 837675 999998 1000000 1000000 1000000 1000000 1000000 1000000 965379 1000000 850863 1000000 417109 999881 1000000 1000000 1000000 417109 1000000 1000000 1000000 1000000 1000000 834218 1000000 1000000 1000000 999999 86447 999978 950186 1000000 834218 1000000 1000000 828601 1000000 1000000 1\n", "output": "1310914\n"}, {"input": "491 119368094\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 570298 1000000 1000000 997042 1000000 999699 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 763575 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 828875 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 665271 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999985 877834 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 480653 1000000 1000000 855342 1000000 1000000 1000000 1000000 853017 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 855346 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 95038 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 891933 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 855343 1000000 1000000 1000000 1000000 998212 1000000 1000000 1000000 1000000 993530 1000000 1000000 1000000 1000000 998275 1000000 1000000 998939 1000000 1000000 1000000 1000000 1000000 639665 1000000 1000000 1000000 999997 1000000 1000000 1000000 1000000 1000000 1000000 1000000 190076 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999447 1000000 1000000 1000000 1000000 250400 1000000 1000000 1000000 1000000 999966 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 380152 1000000 1000000 1000000 1000000 1000000 475394 1000000 1000000 1000000 950380 1000000 1000000 1000000 1000000 1000000 1000000 531924 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 285413 1000000 1000000 1000000 1000000 1000000 760304 1000000 285122 999999 1000000 1000000 1000000 380152 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 647532 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 667218 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 63 1000000 1000000 1000000 95039 784232 1000000 1000000 1000000 190078 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "1255502\n"}, {"input": "489 512526804\n1000000 1000000 993695 992135 1000000 1000000 362397 954764 998252 754926 999999 1000000 990358 930436 1000000 909150 1000000 999927 1000000 1000000 1000000 1000000 869234 1000000 1000000 1000000 1000000 1000000 979724 999998 1000000 1000000 1000000 1000000 237363 991034 245134 944187 986591 605696 1000000 622919 1000000 469990 1000000 988340 1000000 818761 999359 52472 985002 1000000 953545 1000000 999996 34455 1000000 984701 803972 994342 907176 1000000 803135 1000000 1000000 929077 1000000 1000000 996726 1000000 999756 975078 519333 984408 1000000 473626 1000000 1000000 1000000 1000000 996684 812191 1000000 1000000 1000000 957604 950560 927806 985913 1000000 1000000 1000000 732150 999999 999999 1000000 1000000 1000000 919236 779237 876646 999014 839367 909105 1000000 781996 1000000 328210 1000000 1000000 985450 999823 1000000 758098 999516 862532 1000000 936708 998008 1000000 1000000 1000000 998698 1000000 1000000 818238 1000000 999995 1000000 1000000 1000000 996131 1000000 215791 999999 902362 1000000 941036 995025 1000000 1000000 774505 986213 1000000 999847 998401 1000000 12913 856681 1000000 561289 1000000 986513 954222 727571 984353 1000000 850316 998676 877104 1000000 1000000 908204 1000000 1000000 1000000 1000000 582787 546885 1000000 1000000 1000000 1000000 994337 1000000 946357 1000000 1000000 1000000 945295 1000000 795350 999996 1000000 1000000 1000000 1000000 1000000 985636 1000000 1000000 1000000 998478 1000000 983551 1000000 983572 941317 1000000 957524 1000000 867288 999864 1000000 1000000 1000000 1000000 1000000 1000000 1000000 893736 1000000 1000000 1000000 997387 908058 999894 998140 999277 772385 818885 952264 837069 1000000 581680 1000000 963516 1000000 823042 969403 1000000 999357 1000000 1000000 998947 903974 999611 1000000 1000000 1000000 1000000 1000000 989077 1000000 663722 1000000 1000000 1000000 994667 995934 993917 732150 880251 805916 894282 1000000 1000000 840291 733038 989351 1000000 826352 1000000 876321 1000000 857003 503611 1000000 1000000 963526 1000000 991631 1000000 999999 1000000 1000000 904266 1000000 997193 1000000 807487 1000000 1000000 877201 1000000 954201 1000000 1000000 789687 1000000 1000000 990677 977200 1000000 1000000 306148 993556 947144 958949 1000000 443738 1000000 1000000 1000000 1000000 1000000 945390 1000000 1000000 1000000 977507 1000000 962639 1000000 1000000 1000000 1000000 1000000 1000000 753452 1000000 998692 999538 1000000 780093 408471 884981 983914 1000000 999706 953775 1000000 1000000 1000000 941255 859680 784655 1000000 1000000 1000000 1000000 1000000 999433 1000000 162972 1000000 864 997502 960731 1000000 1000000 866243 999618 489819 1000000 933932 1000000 1000000 999999 999432 969172 942673 1000000 955917 991096 1000000 906358 1000000 1000000 1000000 1000000 1000000 1000000 1000000 637373 1000000 975034 729246 787688 1000000 1000000 952664 1000000 732150 999999 1000000 1000000 1000000 1000000 1000000 968834 999498 1000000 941044 1000000 953419 332705 1000000 992339 1000000 788525 1000000 1000000 355903 1000000 1000000 995236 997620 1000000 1000000 1000000 972486 929208 999993 982397 999992 812734 999999 939168 1000000 1000000 1000000 496530 999992 991978 1000000 667381 927765 988663 1000000 1000000 1000000 993859 690238 743452 1000000 876289 588325 949754 1000000 1000000 1000000 985011 1000000 915648 903075 1000000 999444 988078 945067 1000000 999788 973377 1000000 1000000 1000000 1000000 922444 999464 970266 836031 497272 1000000 1000000 730700 1000000 999565 820024 998038 1000000 1000000 1000000 996269 1000000 1000000 1000000 1000000 749610 1000000 929295 1000000 1000000 1000000 1000000 995393 1000000 1000000 1000000 1000000\n", "output": "455397300\n"}, {"input": "491 193311239\n1000000 999999 999999 112905 991201 1000000 1000000 1000000 990492 852871 838884 1000000 927741 988336 997089 1000000 1000000 961504 947391 1000000 954961 999999 1000000 995059 1000000 1000000 777256 761939 919013 982557 627291 960314 913094 768902 982482 959407 996290 900277 1000000 251911 1000000 829562 955937 930953 200420 1000000 833463 897179 996939 756136 922793 1000000 312923 1000000 999999 398624 1000000 996929 941334 650832 359229 996453 1000000 1000000 999257 888290 895173 726609 972461 993455 1000000 997540 1000000 999865 999992 1000000 866530 989753 231268 1000000 850818 1000000 934741 1000000 176058 772754 459244 877768 1000000 953205 710034 966908 991203 999014 945874 955477 954220 1000000 1000000 379562 617556 403284 1000000 957979 347983 912514 987341 262123 687044 687162 997395 1000000 256502 1000000 990572 166436 998839 772383 826535 415398 864576 999630 999999 997791 362033 610475 705082 1000000 940415 816315 998104 485142 877218 937178 948869 998599 994425 610576 997985 970138 1000000 930843 691754 823745 567868 1000000 1000000 998361 652016 1000000 884295 842842 997720 820182 699523 62555 929982 445773 259539 1000000 71348 898122 927653 887593 1000000 994627 1000000 473509 463336 1000000 542171 997777 872066 1000000 953639 798835 986790 929870 975271 863323 893059 963866 932755 733585 897382 784348 667443 994602 889178 477197 770238 999177 723308 1000000 1000000 595734 999994 999178 950862 775572 943091 1000000 410537 745414 971574 216501 1000000 993290 947781 843324 808580 1000000 1000000 988208 311975 997856 993086 970544 1000000 1000000 801470 999999 884310 1000000 345815 999990 979976 1000000 1000000 848431 787803 650305 999999 983611 982487 694503 1000000 999996 828800 944679 747989 906074 994669 1000000 999999 999999 811188 1000000 883829 999554 1000000 728131 166909 975505 999998 200420 844053 629018 425379 473016 1000000 1000000 886362 1000000 260101 255715 1000000 260767 739142 1000000 950705 995409 919090 805569 925669 1000000 999512 842997 1000000 704017 1000000 1000000 272424 816662 958463 991776 617951 1000000 936912 935432 910998 986841 1000000 999546 787277 696829 868655 763926 1000000 1000000 1 860699 1000000 1000000 830828 906665 972363 399677 872548 1000000 200379 1000000 1000000 1000000 831712 644742 1000000 486881 979540 1000000 857753 1000000 924047 934707 998080 130599 728371 834175 965270 998739 1000000 988616 613273 880052 1000000 1000000 1000000 620395 370991 969180 526132 999984 1000000 996292 956981 1000000 1000000 999705 958187 999986 969543 916668 1 949904 904760 1 616108 680163 984027 554664 970714 742580 891346 892111 773423 88731 822217 847895 838931 991102 714397 999999 965714 763172 879554 1000000 959425 583478 730109 790352 949082 546219 1000000 1000000 134739 722279 953514 474592 890347 914968 1000000 1000000 1000000 1000000 857413 934465 622500 966059 999995 697814 918590 864649 342977 932612 250217 876859 999561 632080 1000000 904616 1000000 999999 1000000 575333 659681 1000000 1000000 812293 999993 932382 333273 989868 801871 250997 1000000 955720 887252 1000000 276011 1000000 907809 29759 987415 377829 668273 1000000 962070 909274 1000000 795978 667650 601912 940971 603718 910379 1000000 415256 918768 1000000 972991 599098 998309 931726 996530 998694 1000000 964796 453142 1000000 1000000 757505 743503 911214 887067 1000000 433823 801004 880146 981329 881285 674367 955220 1000000 967164 919997 999669 717974 1000000 634061 873744 1000000 989820 788758 1000000 158918 838323 1000000 894271 1000000 974688 998148\n", "output": "1865728\n"}, {"input": "485 120063494\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 987945 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999020 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999808 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 979566 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999986 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 998878 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999799 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "148262\n"}, {"input": "487 103378853\n1000000 1000000 1000000 203090 1000000 1000000 1000000 999999 1000000 1000000 1 1000000 1000000 406180 1000000 1000000 1000000 812360 1000000 1000000 1000000 1000000 609270 609333 1000000 406180 1000000 10456 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 406180 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 812360 1000000 709627 1000000 406180 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 203090 1000000 1000000 406180 1000000 1000000 1000000 1000000 1000000 203091 406180 1000000 1000000 1000000 1000000 406181 1 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 609270 875119 999999 1000000 1000000 609270 1000000 1000000 1000000 1000000 1000000 1000000 803743 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 203090 1000000 812360 1000000 1000000 1000000 1000000 1000000 1000000 1000000 812360 1000000 1000000 1000000 1000000 1000000 1000000 1000000 203090 1000000 1000000 609270 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 203090 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 406180 1 406185 406180 1000000 1000000 1000000 1000000 1000000 610590 812360 812360 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 406180 205696 1000000 1000000 1000000 609272 1000000 1000000 1000000 1000000 1000000 203090 1000000 1000000 406180 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 812360 1000000 1000000 1000000 1000000 406180 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 609272 406180 1000000 1000000 1000000 1000000 1000000 1000000 203090 1000000 1000000 1000000 1 1000000 1000000 990 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 812360 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 474122 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 999997 1000000 1000000 1000000 1000000 1000000 611853 1000000 1000000 609270 1000000 1000000 812361 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 203090 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 203090 1000000 1000000 999999 1000000 609270 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 406180 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 812360 913631 1000000 1000000 1000000 1000000 406180 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 812360 1000000 1000000 812360 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 812360 1000000 1000000 1000000 1000000 1000000 609274 1000000 1000000 406180 1000000 203090 406180 999999 1000000 1000000 999999 1000000 1000000 1000000 1000000 1 1000000 1 1000000 609568 1000000 998556 1000000 1000000 406942 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 406180 1000000 1000000 1000000 1000000 999996 812360 1000000 1000000 1 812360 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 665990 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 609270 609270 609270 1000000 812360 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 609270 1000000 999869 1000000 1000000 203090 1000000 999999 1000000 203090 923345 1000000 1000000 1000000\n", "output": "1259158\n"}, {"input": "485 261441483\n995822 1000000 1000000 1000000 967886 1000000 1000000 1000000 975187 904392 1000000 1000000 1000000 507779 956947 982244 1000000 1000000 1000000 999075 870298 1000000 849567 1000000 407944 1000000 1000000 1000000 570027 999999 1000000 948534 1000000 825396 304724 998905 998193 304724 1000000 958544 1000000 992896 989707 492890 986158 975707 1000000 1000000 997054 990496 1000000 721342 947525 932664 944668 987402 1000000 1000000 824759 1000000 988987 939410 1000000 983260 1000000 1000000 1000000 1000000 765253 1000000 999956 934793 891991 1000000 954687 999978 1000000 979879 757109 774203 1000000 999998 914171 1000000 999946 854637 1000000 1000000 838481 954207 1000000 1000000 1000000 999806 852600 1000000 1000000 1000000 1000000 1000000 1000000 797614 979647 1000000 866331 999981 538691 968471 1000000 645565 980626 999999 1000000 979663 1000000 1000000 998923 993046 597067 1000000 912563 999155 719823 929770 1000000 1000000 1000000 843361 1000000 1000000 1000000 998473 999998 1000000 755734 996299 963941 1000000 957142 919389 1000000 998126 936533 595164 988724 1000000 971751 1000000 1000000 999205 1000000 1000000 1000000 999826 1000000 896020 941475 913331 1000000 1000000 830340 866029 990903 995620 982191 575601 557153 971986 1000000 1000000 1000000 1000000 999999 999717 1000000 971526 1000000 1000000 59934 1000000 1000000 1000000 979411 1000000 939915 1000000 988794 846327 936057 1000000 1000000 902377 1000000 1000000 301520 775705 955717 991195 935724 792103 1000000 976182 1000000 1000000 999956 1000000 1000000 992466 1000000 1000000 1000000 988563 1000000 952864 1000000 983338 1000000 1000000 996951 886739 1000000 310028 998203 1000000 1000000 1000000 1000000 1000000 1000000 1000000 866608 1000000 1000000 926535 994447 904851 409226 1000000 999999 1000000 249375 1000000 1000000 1000000 918007 993923 1000000 926504 1000000 875562 1000000 1000000 922293 984373 1000000 917528 498269 967127 1000000 986837 1000000 1000000 1000000 1000000 1000000 988629 1000000 1000000 990653 999989 502332 999809 1000000 1000000 1000000 994389 238956 960096 1000000 1000000 1000000 997200 964039 995057 997828 1000000 923209 1000000 566364 999971 992775 1000000 1000000 1000000 567788 1000000 1000000 1000000 589859 996166 1000000 596881 1000000 881278 724404 1000000 1000000 968245 984585 883520 999693 1000000 1000000 923386 1000000 779045 985387 979239 995611 995625 1000000 949757 1000000 999060 1000000 970843 882164 1000000 1000000 858368 603115 689973 997176 765917 990529 1000000 999650 937159 1000000 978684 1000000 942529 999999 803869 955630 999649 985282 663661 914489 1000000 903927 981824 581991 989300 1000000 1000000 1000000 1000000 998328 888732 999994 1000000 1000000 1000000 1000000 1000000 974641 986058 750626 1000000 996148 1000000 1000000 999689 1000000 1000000 1000000 997982 1000000 957779 947079 261221 1000000 1000000 583517 955448 1000000 977518 997733 1000000 650797 1000000 1000000 977794 712367 1000000 895378 1000000 779002 1000000 999999 999963 1000000 1000000 1000000 1000000 951376 724038 1000000 1000000 943917 999997 999565 487167 990698 994466 999170 993841 1000000 965243 999321 636549 1000000 806072 1000000 442964 1000000 1000000 1000000 1 958674 997549 999998 965177 1000000 988127 823148 1000000 873282 975725 999710 1000000 999999 1000000 1000000 1000000 918775 616949 983606 1000000 813056 1000000 945377 1000000 995929 1000000 999668 1000000 989227 1000000 991814 949298 940222 966254 962872 998467 1000000 1000000 1000000 871633 1000000 1000000 1000000 694077 969096 992554 1000000 434623 999999 1000000 1000000 924767 1000000 799925 1000000\n", "output": "2285430\n"}, {"input": "497 82294484\n1000000 681073 1000000 1000000 1000000 1000000 681064 999999 1000000 999999 681064 681064 999999 1000000 999999 1000000 1000000 1000000 1000000 681064 1 1000000 340532 999999 1000000 340532 999999 1000000 340532 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 681064 681064 1000000 1000000 1000000 681070 681064 1 1000000 1000000 1000000 999999 1 1000000 999986 1000000 340532 1000000 340532 1000000 1000000 1000000 340532 1000000 1000000 681064 999999 1000000 1000000 341081 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 681064 1000000 999996 1000000 340531 1000000 1000000 1000000 999999 681064 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 340532 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 681064 999999 1000000 340532 1000000 1 1000000 532663 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 999999 340532 1000000 681064 1000000 681064 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 681064 1 1000000 1000000 1000000 340532 1000000 1000000 1000000 340532 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 1 999999 1000000 1000000 1000000 681064 1000000 1000000 1 1000000 1000000 342244 494005 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1 1 1000000 999992 1 1000000 681064 343950 1000000 1000000 1000000 1000000 1000000 1 340531 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 681064 340532 340532 999999 1000000 1000000 1000000 1 1000000 1000000 681064 1000000 1000000 999999 1000000 681064 340532 1 340532 1000000 1000000 1000000 1000000 999999 1 999999 340532 1000000 1000000 1000000 681064 1000000 1000000 1000000 340532 681076 1000000 1000000 1000000 681064 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 681064 681064 999999 1000000 1000000 1000000 1000000 525732 1000000 1000000 1 1 1000000 30971 681064 1000000 1000000 1000000 999999 1000000 1000000 1 1 1000000 340532 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 681064 1000000 1 681064 681064 681064 1000000 340532 1000000 999999 1000000 1000000 1000000 1000000 999999 340532 1000000 1000000 1 1000000 1000000 1000000 999999 340532 1000000 1 1000000 1000000 1000000 1000000 1 1000000 340532 1000000 999880 1000000 340532 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 2 1000000 48 1000000 340532 340532 681064 1 1000000 340532 1000000 1000000 340531 1 681064 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 981140 1000000 681064 999999 1000000 1000000 1000000 999462 1000000 1000000 999999 1000000 1 999992 1000000 1 1000000 1000000 1000000 340531 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 1 973169 681064 1000000 1000000 1000000 999999 1 1000000 1000000 1 1000000 1000000 681064 1000000 999999 681063 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 41257 1000000 22606 1000000 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1 1000000 340717 1000000 1000000 1000000 1000000 1000000 1000000 681064 999999 1000000 1 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "340532\n"}, {"input": "482 511257447\n859133 935776 1000000 1000000 991005 829977 801631 1000000 263924 986419 999582 945021 995710 1000000 1000000 1000000 927318 360245 869458 914010 1 781969 886228 905359 73233 999951 840169 122894 999830 998370 981213 1000000 957619 429869 1000000 936458 1000000 1000000 891405 762995 1000000 856949 1000000 97405 794352 946302 1000000 1000000 978747 774161 978522 886628 779670 1000000 978345 1000000 998841 849957 1000000 1000000 993885 1000000 715355 1000000 953929 983176 1000000 970775 1000000 1000000 1000000 857975 433612 683503 1000000 455226 999719 546003 1000000 927209 1000000 828262 520488 1000000 997106 974729 986965 981352 997209 999469 828234 844357 831253 1000000 919552 1000000 1000000 1000000 987259 963039 1000000 799419 1000000 915598 789537 1000000 874136 454146 991466 996406 997727 1000000 965850 967537 999999 758466 855084 983486 911910 989860 1000000 999317 663462 819965 755310 912616 1000000 691248 740904 657332 968288 863542 997997 804700 986540 1 1000000 966624 265175 572423 1000000 1000000 800787 768205 999883 922490 970260 968959 645637 814227 840743 904073 967878 1000000 970660 944417 592837 1000000 1000000 857257 1000000 966143 1000000 1000000 377018 1000000 973128 1000000 949677 848404 999997 912807 972720 998075 993143 958246 736441 981237 970436 892223 992452 1 999687 994463 962417 1000000 968638 992533 999344 976018 1000000 803797 996770 898570 998924 995507 856996 656750 934977 982355 1000000 998965 1000000 912179 652761 999339 999987 994952 885684 569443 966500 999999 979907 1000000 998554 896916 949084 1000000 1000000 983590 575912 527765 1000000 622914 999987 871563 974259 959238 983402 976334 1000000 991508 999016 968546 950153 327935 990274 994104 999161 955045 965728 1000000 1000000 999771 1000000 951001 987302 1000000 842840 1000000 981189 917675 911018 377452 385945 1000000 320831 1000000 490655 841488 491464 980462 999643 999864 996490 937680 909824 1000000 1000000 971628 998797 1000000 978125 992030 1000000 999808 414563 999982 144819 1000000 998923 999999 991276 993577 805528 1 998648 1000000 1000000 999958 998045 693806 247922 1000000 956261 999137 1000000 1000000 1000000 903586 991861 963010 964400 505393 991548 418614 983353 997517 1000000 967000 1000000 954630 841181 546058 993468 751802 964070 969044 999559 930868 912100 886916 999528 1000000 913398 981500 999979 1000000 987627 981949 1000000 1000000 1000000 800658 990835 1000000 471132 980022 436542 999999 900845 1000000 765464 999951 1000000 986394 988465 1000000 954423 1000000 973382 883864 913315 1000000 945729 810475 924642 955917 974501 761799 984959 999985 976275 987725 818974 995170 937303 951073 943261 999714 999001 841670 738060 438153 655142 997147 998553 668821 999246 762033 978971 994574 991324 1000000 1000000 751928 772074 981825 996630 1000000 902488 71102 987248 980407 1000000 1000000 530793 996808 1000000 1000000 918731 1000000 979206 994435 636140 785258 992368 951231 938408 843292 829795 931230 997879 964937 1000000 1000000 736066 846549 1000000 723064 1000000 999587 876306 997046 985928 790051 978273 1000000 1000000 1000000 983692 52817 999999 232129 976042 286841 999999 986163 981187 999999 985272 876305 1000000 609676 812742 992200 1000000 872596 996534 999699 416595 993170 986292 1000000 264792 1000000 1000000 998319 679057 893514 551963 963115 909698 913234 871076 1000000 999702 1000000 777456 457645 957730 1 900750 1000000 276573 863915 894742 997102 955580 1000000 979572 1000000\n", "output": "425884716\n"}, {"input": "490 123039010\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 987137 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 999136 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999995 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 706847 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 244497 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999937 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999589 1000000 1000000 1000000 1000000 1000000 936372 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999491 1000000 1000000 1000000 1000000 1000000 238874 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 656742 1000000 667674 1000000 1000000 1000000 1000000 1000000 1000000 1000000 995130 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "1200570\n"}, {"input": "491 90472066\n1000000 1000000 1000000 292617 1000000 1000000 1000000 999991 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 292617 1000000 1000000 585234 1000000 1000000 1000000 1000000 1000000 1000000 1000000 292620 1000000 1000000 1000000 585234 1000000 1000000 1000000 1000000 1000000 1000000 1000000 292616 1000000 1000000 292617 877851 1000000 1000000 1000000 292617 1000000 660984 1000000 292617 1000000 585234 292617 1000000 999999 1000000 999999 1000000 1000000 1000000 585234 1000000 877851 1000000 1000000 1000000 1000000 813736 1000000 1000000 1000000 877851 1000000 1000000 999998 1000000 1 1000000 1000000 1 999999 1000000 1000000 292617 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 585234 1000000 1 1000000 1000000 292617 999999 999998 1000000 1000000 1000000 1000000 993838 1000000 999999 877851 1 877850 294522 877851 1000000 1000000 1000000 1 1000000 999982 1000000 1000000 1000000 585234 585234 1000000 1000000 1000000 1 1000000 292626 1000000 999999 1000000 1000000 998728 1000000 292650 1000000 1000000 1000000 292617 1000000 1000000 1000000 999999 1000000 585234 999999 585234 1000000 1000000 999999 1000000 1000000 1 1000000 1000000 292617 1 1000000 585234 1000000 877851 1000000 1000000 585234 1000000 877851 1 292617 877851 292617 1000000 1 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 999999 585234 292616 585234 1000000 1000000 585497 292617 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1 999999 1000000 877851 877975 1000000 1000000 1000000 1000000 1000000 1000000 1000000 292617 1000000 1000000 1000000 1000000 1000000 292617 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 999989 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 877851 1000000 999947 1 877850 1000000 585234 1 1000000 1000000 877851 1000000 1000000 1000000 1000000 1000000 1000000 997034 292617 1000000 1000000 1 1000000 877851 292617 1000000 1 585234 585234 1000000 877855 1000000 1000000 1000000 292617 1000000 1000000 585234 1000000 1000000 1000000 1000000 997254 1000000 1000000 863497 1000000 1000000 292617 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 292617 1000000 1000000 1000000 892053 292617 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1 585234 1000000 292616 1000000 1000000 1000000 1000000 585274 1000000 1000000 1 292617 292617 1000000 1000000 1000000 1000000 877851 1000000 999999 585234 1 1000000 1000000 1000000 877851 1000000 1000000 1000000 877851 1000000 1000000 1000000 999999 1000000 1 1000000 1000000 1000000 1000000 1000000 878024 585234 1000000 999999 862006 1000000 1000000 1 1000000 1000000 292617 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 585234 1000000 1000000 292617 1000000 1000000 585234 1 877851 877851 1000000 1000000 1000000 585234 1 1000000 292617 1000000 1000000 877851 332 1 1000000 1000000 585234 1000000 292616 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 292617 877851 1000000 1000000 585234 1000000 1 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 292617 1000000 999999 292617 1000000 292617 999999 877851 1000000 1000000 1 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 292617 1000000 1000000 7455 1000000 1000000 1 1000000 877851 1000000 877851 1000000 1000000 877851 1000000 1000000 1000000 877851 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999\n", "output": "1130493\n"}, {"input": "486 573616932\n1000000 981498 1000000 999434 629617 1000000 1000000 966382 1000000 378554 1000000 999999 932015 997166 1000000 929821 931490 987867 914126 1000000 995466 996940 941323 335322 1000000 955348 942359 575164 998123 1000000 981851 999984 1000000 953296 973557 1000000 953548 978917 1000000 799862 979662 1000000 874011 573487 1000000 1000000 982451 954114 939477 1000000 958408 987736 999981 1000000 781648 1000000 994096 799061 904173 1000000 993939 1000000 811971 607975 1000000 985609 1000000 995359 1000000 1000000 1000000 977951 999999 963910 1000000 858346 598010 620053 878432 668319 994557 1000000 1000000 183918 1000000 997963 1000000 1000000 988416 999984 1 924476 999999 1000000 1000000 1000000 1000000 999999 1000000 963625 61254 1000000 1000000 852908 780322 995535 1000000 1000000 995585 1000000 217463 996999 1000000 975427 1000000 1000000 998138 40355 1000000 1000000 737418 967169 999999 1000000 661630 1000000 842549 807883 983849 999999 999893 941117 1000000 1000000 468499 1000000 849130 957350 991833 1000000 985085 969721 1000000 1000000 977005 517580 358931 996806 998411 996027 999999 992708 1000000 1000000 265770 1000000 223693 993624 951685 948453 999999 998785 1000000 1000000 402370 999348 950007 995033 911745 998726 999998 957095 1000000 1000000 956236 1000000 1000000 1000000 695161 989835 881256 83608 1000000 988494 999996 466718 1000000 292262 913563 1000000 877417 999994 689238 1000000 1000000 908471 1000000 900743 1000000 931475 1000000 990239 791900 410003 999855 999663 1000000 967472 960159 993738 1000000 1000000 543483 1000000 654748 1000000 911340 983877 862224 1000000 1000000 1000000 822222 1000000 999954 936276 715011 1000000 984521 1000000 945286 998784 996008 1000000 1000000 965126 927287 972508 1000000 808629 990962 914838 1000000 979674 997329 1000000 1000000 944756 1000000 1000000 1000000 887936 998974 955079 1000000 961403 907262 983371 993306 1000000 1000000 1000000 1000000 983593 1000000 1000000 955774 915822 844303 1000000 888751 677893 995123 897877 762029 39238 995673 961004 985948 995940 918024 999562 1000000 1000000 996448 1000000 1000000 999103 607895 995113 866603 828873 960113 925777 957033 826479 1000000 1000000 1000000 654379 997454 423016 1000000 905547 133518 962063 863779 1000000 982877 954434 648829 999997 618852 914064 999999 999777 1000000 1000000 911138 1000000 928256 992079 1000000 901868 320974 314601 1000000 369895 942328 1000000 971726 999998 922200 912273 865216 1000000 978957 709089 1000000 824719 1000000 968600 1000000 872262 1000000 972781 885319 993289 961705 1000000 984641 1000000 949322 832799 1000000 1 1000000 816612 987905 1000000 998321 1000000 954054 974101 621447 937270 996347 990934 880960 993500 1000000 968812 991250 889406 1000000 999999 1000000 1000000 958296 1000000 597631 1000000 1000000 1000000 1000000 239277 1000000 995860 998189 921132 984685 996032 1000000 1 1000000 813677 1000000 976862 997761 934225 1000000 1000000 1000000 371255 600127 916172 1 993584 981769 954678 1000000 984215 995464 1000000 1000000 948542 986043 930821 1000000 1000000 1000000 1000000 1000000 1000000 999852 999811 483884 774463 799104 1000000 892427 999613 1000000 998621 993480 303470 388203 728644 1000000 999341 549661 999949 1000000 910082 1000000 993871 990469 62047 807933 987077 179484 968214 1000000 846366 1000000 997768 1000000 724710 1000000 1000000 995469 540264 959043 1000000 997147 442874 1000000 998816 211459 999999 986004 947670 988068 1000000 990606 996042 1000000 999999 928002 800804 775348 1000000 999978 1000000 978274 1000000\n", "output": "437626962\n"}, {"input": "499 179045852\n1000000 1000000 1000000 1000000 1000000 962252 948209 1000000 1000000 910117 995886 999352 886974 697557 1000000 1000000 1000000 971345 1000000 982250 996758 1000000 845237 898565 1000000 963040 999360 1000000 1000000 980081 971745 999938 742352 1000000 1000000 1000000 1000000 1000000 689617 1000000 1000000 1000000 814774 1000000 998213 329092 999999 983988 242930 999999 678951 1000000 1000000 1000000 1000000 844472 986995 1000000 1000000 915944 948033 975145 998670 820244 1000000 776612 999948 1000000 524740 1000000 965941 1000000 999868 388198 523636 1000000 999489 1000000 937600 929272 971068 1000000 608033 1000000 999975 999953 811767 619535 1000000 1000000 955435 992095 967176 580953 1000000 1000000 1000000 999991 1000000 995292 992234 958475 999996 935813 804489 1 999966 967989 999988 732172 998847 999996 992856 921094 1000000 1000000 1000000 1000000 1000000 966106 821479 1000000 998903 726104 1000000 974938 410098 999992 999609 1000000 891743 205521 1000000 855110 893503 1000000 884490 873951 1000000 1000000 656921 639669 999997 768511 976244 942027 984045 1000000 1000000 999900 997208 999212 994846 1000000 936533 660096 998268 1000000 715855 831266 992780 1000000 904777 1 999996 95806 1000000 1000000 998476 973909 1000000 1000000 997016 978156 886225 712665 841293 615003 987328 999893 787149 943654 1000000 970443 333679 1000000 1000000 979797 968078 1000000 1000000 963515 1000000 961330 1000000 1000000 959413 1000000 1000000 994982 1000000 1000000 1000000 1000000 1000000 412835 802901 951882 1000000 934210 1000000 886532 999376 849903 922545 366431 919359 810689 1000000 984626 963938 692336 986459 322907 410122 806193 996615 594791 952408 126475 999826 999302 1000000 1000000 439828 1000000 969843 990880 819505 994056 492150 723707 999642 973891 1000000 920640 405145 960578 1000000 983837 984569 990197 1000000 990370 1000000 1000000 921199 999780 1000000 953588 944871 1000000 1000000 1000000 1000000 1000000 750845 1000000 995284 1000000 1000000 770870 998545 994804 998712 996268 1000000 923671 845625 757302 1000000 303988 958798 1000000 999960 960107 38146 1000000 515560 1000000 980020 1000000 1000000 1000000 37500 998076 1000000 901191 1000000 506574 1000000 1000000 939306 950031 26 1000000 1000000 1000000 697053 965517 999857 984897 1000000 1000000 651419 1000000 851340 1000000 950749 629771 992781 977468 990795 999953 1000000 933995 1000000 999983 1000000 779261 1000000 718782 965168 1000000 703044 1000000 1000000 1000000 866599 993671 981705 1000000 943236 1000000 747254 891532 809491 1000000 951414 999144 992112 1000000 1000000 1000000 988072 1000000 1000000 999555 973982 1000000 931395 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 801928 1000000 999822 941434 588364 1000000 1000000 968129 774828 1000000 985872 1000000 1000000 1000000 1000000 1000000 1000000 509427 1000000 999999 1000000 999109 153279 998934 1000000 1000000 1000000 974168 1000000 1000000 999074 1000000 974640 984993 1000000 941249 886549 1000000 1000000 865099 1000000 989707 995844 998911 839444 670865 910089 999473 978707 694504 1000000 999554 994574 971627 730656 1000000 1000000 1000000 1000000 1000000 993247 999995 886738 1000000 968237 983403 984883 912322 856164 896500 1000000 338927 1000000 925137 848877 964595 802709 660241 998014 999999 1000000 841880 684567 1000000 957490 475947 776977 918207 999964 1000000 1000000 974432 1000000 973108 537649 1000000 888476 989907 1000000 936770 958782 974126 999999 852776 1000000 714062 1000000 1000000 1000000 999972 926201 997303 971838 999999 871203 787229 999739 999996 963187 999999 831338 947204 1000000 907923 995578 572500 999887 855897 1000000 988058\n", "output": "615183\n"}, {"input": "487 130685463\n1000000 1000000 1000000 957273 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 999317 1000000 999635 1000000 1000000 478635 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 478635 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 999999 1000000 999902 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 957296 1000000 957271 1 1000000 1000000 1000000 1000000 1 1000000 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 478635 1000000 1000000 478635 1000000 1000000 1000000 1000000 483190 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 478635 478635 999999 957270 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 44764 1000000 478634 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 957270 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 478634 1000000 1000000 1000000 957270 1000000 1000000 1000000 1000000 1000000 1000000 1000000 478635 1000000 710343 1000000 1000000 957270 1000000 1000000 1000000 1000000 969558 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1000000 999998 1000000 999999 1000000 957270 1000000 1000000 1000000 1000000 1000000 1 978286 478635 1 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999994 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 764923 1000000 478635 1000000 1000000 1000000 1000000 1000000 1000000 762071 1000000 1000000 1000000 957270 1000000 1000000 1000000 478635 1000000 1000000 1000000 478635 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999958 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 957270 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 957270 1000000 1000000 478635 1000000 478635 1000000 1000000 1000000 478635 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 478635 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 478642 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 601356 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 957270 1000000 1000000 1000000 1000000 1000000 1000000 1000000 12 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 998354 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 81 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 957270 1000000 478635 981087 1000000 1000000 1000000 1000000 1000000 478635 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 957270 957270 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 1 1000000 1 999999 1000000 1000000 1000000 1000000 1000000 478635 1000000 1000000 1000000 1000000 1000000 957270 1000000 1000000 1000000 1000000 1000000 478635 1000000 999999 1000000 1000000 1000000 1000000 478635\n", "output": "994810\n"}, {"input": "481 640058574\n1000000 68845 967535 734070 512362 997908 964719 939387 980217 999252 420753 968221 1000000 782867 1000000 813064 981804 995740 1000000 291231 182666 988118 999503 856414 916666 917188 498276 920515 915601 945361 999956 996249 714423 972869 753204 1000000 950028 1000000 1000000 785990 1000000 950121 226008 914827 540324 982974 960375 999139 934356 1000000 991313 454470 560102 1000000 808517 1000000 877476 960498 1000000 1000000 1000000 978892 766327 604286 971297 946441 998295 367348 859147 5620 1000000 1000000 817281 855317 998114 740001 1000000 457153 990260 829108 981717 997635 614322 333162 1000000 818954 815582 968636 958802 1000000 635664 683401 788822 342169 710690 541943 990322 999088 545904 1000000 993170 988668 1000000 24853 1000000 18707 516244 987240 893079 1000000 790919 932172 624701 966759 997955 745787 630989 859595 895179 997125 1000000 473564 115797 986985 588721 925028 659187 1000000 991673 1000000 920096 884826 21639 1000000 1000000 921347 630508 1000000 1000000 746079 966205 869903 998928 999967 968510 1000000 1000000 292084 964606 797321 958805 999822 919774 853235 988596 1000000 974162 527500 856218 833625 600767 859819 997890 1000000 958990 1000000 891376 1000000 1000000 1000000 175192 794597 868550 1000000 623902 879384 994780 699878 672233 951209 665186 997456 939670 970438 999240 859595 785683 945569 972474 447467 997092 876416 992588 739066 87224 999353 982177 450052 937153 962017 883253 482000 928535 1000000 986386 996702 995981 1000000 790111 1000000 411112 672589 1000000 998293 19021 954549 88636 650600 660292 842096 394715 984648 919384 828395 962691 999502 1000000 999641 846485 984628 794589 458519 766105 955065 351038 964766 998743 1000000 947156 379885 1000000 999791 992708 986765 990844 728893 1000000 730802 757877 920863 936893 641814 804646 757062 511436 969873 999774 209182 811518 1000000 1000000 902454 1000000 988664 979027 921149 999073 994866 472372 462468 27411 18047 974101 994301 858219 995759 993210 6538 982292 417405 1000000 949819 927100 1000000 861296 204696 832100 972642 993229 550466 253747 988628 1000000 1000000 877078 1000000 396258 770364 988611 831392 970942 633021 1000000 995256 232131 891206 14862 854267 924110 1000000 934014 888946 745367 933900 994089 651670 1000000 918260 1000000 1029 36499 998759 746303 1000000 1000000 339197 873918 773568 994206 509238 992537 986742 1000000 592333 1000000 614859 1000000 225880 171410 953213 916757 778166 997908 346314 998126 1000000 865381 996993 996479 1000000 749285 992567 998698 966244 660465 1000000 968679 704624 1000000 764995 997690 941030 1000000 1000000 1000000 897998 1000000 727963 990155 862442 983445 1000000 924848 980808 1000000 947411 978423 1000000 767495 988190 723952 999880 992775 115046 884587 282882 933704 1000000 871404 972414 999023 970453 1000000 591031 672985 855298 1000000 976654 849993 989773 880164 841234 997775 910978 822473 987756 1000000 514389 1000000 999764 922369 932109 1000000 413396 1000000 840997 994843 907813 565345 988819 508730 831146 927291 946994 997916 924770 986304 995921 1000000 901052 956725 843050 999997 974614 998442 1000000 602447 863022 981111 994023 815122 994723 41563 1000000 935124 979453 647270 1000000 999258 992606 707350 632068 985246 910822 955244 1000000 716902 980271 235933 961118 994720 261387 575835 942059 1000000 982238 829154 980955 1000000 999923 999069 971004 750271 808295 958794 989733 948524 901745 1000000 944379 998393\n", "output": "400750667\n"}, {"input": "484 931628662\n871247 684091 999918 960063 828969 992704 842579 977863 853522 983255 999911 999961 997690 988155 990965 723450 987317 955780 923902 855471 826543 917479 763700 995203 992539 997387 892827 984027 995704 959115 999837 723333 999980 919203 967154 851754 969498 706501 998393 999291 541222 999751 996203 942915 809949 893074 999381 944785 806312 899997 997579 673509 641550 975084 972850 963483 975405 941727 946842 992145 982716 838389 986101 905455 740419 989646 951846 994258 1000000 975101 995505 999094 779197 959000 985936 954172 815487 828616 935519 839502 919819 978993 961657 998043 987261 974669 986417 736963 998940 904107 892081 925200 957493 964200 999694 999999 974503 945684 999807 781817 953015 794528 999994 851121 945721 540068 983115 937820 996562 999911 995304 968002 996867 949531 1000000 999997 915247 968087 847083 962781 980500 987208 910274 851451 939468 769413 993185 600301 843568 999754 999967 554241 977126 935554 968696 827814 987445 956612 999223 688821 797069 957962 987105 844441 995768 993239 912156 998422 973474 998816 1000000 977754 714331 901297 1000000 877949 977432 996611 507453 986275 992444 1000000 986113 991534 567879 945221 990845 906482 837749 1000000 970169 664838 980388 943926 834694 907362 997480 947514 945033 943819 968340 770332 999758 925980 995217 971904 995392 938985 722412 949448 724522 974291 702913 995854 938662 979874 975313 649213 985858 1000000 999827 953372 997165 829136 969114 821492 984387 837225 814251 815826 870685 707568 999945 961805 594397 733528 994454 837336 995068 760927 901095 987736 979363 816043 759676 849812 801498 999959 736975 998628 997348 987166 988189 919875 915835 982093 908861 686419 997420 947480 973839 823830 997814 997961 809242 828424 885982 948555 957946 591673 960608 416352 907102 997664 764934 773050 960059 894876 967989 896579 854529 517807 803018 714902 919805 390331 993254 976214 872064 997085 984772 991967 928521 968956 899226 782882 999517 943537 999959 972298 611899 906966 877071 987253 995652 467418 933160 996632 999633 966860 703007 984228 986683 931906 997016 996839 993394 990330 894187 999943 996687 920055 976343 999463 984374 197233 993042 978997 934767 999969 933963 942565 920820 488060 871602 910620 990537 964485 966722 990665 998760 679051 889832 941727 953727 961220 841114 999787 999926 906774 999285 850046 798905 876489 955755 898630 987650 881730 657541 932365 989949 987608 943299 998623 997439 992777 884908 992139 873496 947938 928844 1000000 999960 821799 988431 900908 987190 832792 949017 971920 818525 996423 930537 958959 947323 988721 954965 687950 908587 849782 968617 973936 984371 430234 925368 967705 915023 992320 825738 997933 999110 976237 998760 944633 969383 924952 999306 991563 975367 829770 990267 989777 933863 925824 939331 999978 950103 914651 894709 926819 943396 987099 583189 892870 990584 968177 999739 991460 910797 983329 991576 911446 859366 999907 999861 999917 698466 999147 995087 999172 963399 937206 765055 940022 967343 944911 871833 842682 851928 978979 998117 953342 745958 987115 981652 503608 894937 991753 817314 997643 999979 997706 899979 995228 998993 997698 620774 759468 995579 965771 989971 997730 936840 932153 999990 947466 858681 999932 994363 974669 924518 926618 900711 901659 971191 444190 972355 971234 999452 846105 769178 999000 912616 983173 934534 992605 985471 987889 969605 999730 978059 859079 765793 891097\n", "output": "441594170\n"}, {"input": "484 450342599\n270622 1000000 1000000 1000000 1000000 1000000 1000000 144353 1000000 1000000 1000000 420689 1000000 1000000 571758 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 690663 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 446585 999981 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 887671 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999970 1000000 1000000 1000000 1000000 1000000 1000000 173517 1000000 1000000 1000000 1000000 943033 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 202843 1000000 621824 1000000 1000000 1000000 1000000 1000000 1000000 1000000 149552 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 484228 1000000 1000000 1000000 1000000 999898 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 662660 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999466 1000000 364554 1000000 1000000 1000000 1000000 1000000 101547 712061 940973 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 74554 1000000 1000000 510065 1000000 1000000 284477 1000000 1000000 1000000 1000000 1000000 1000000 1000000 452261 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999982 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 201359 1000000 1000000 1000000 1000000 1000000 1000000 371149 1000000 1000000 1000000 16504 754766 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 644558 1000000 1000000 1000000 816551 1000000 939741 1000000 1000000 1000000 326850 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 565 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 498703 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 297888 1000000 1000000 1000000 1000000 1000000 1000000 935384 1000000 1000000 1000000 1000000 1000000 320783 980074 1000000 1000000 1000000 1000000 987608 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 39675 155843 83960 1000000 1000000 1000000 14757 1000000 1000000 1000000 1000000 1000000 827723 1000000 711448 1000000 154438 1000000 1000000 1000000 1000000 1000000 439303 1000000 1000000 1000000 1000000 517423 1000000 1000000 1000000 213510 1000000 1000000 1000000 1000000 1000000 1000000 1000000 125390 1000000 1000000 1000000 1000000 923973 1000000 1000000 37218 1000000 1000000 1000000 1000000 417628 1000000 1000000 1000000 1000000 94507 1000000 1000000 1000000 785742 641631 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 39681 1000000 1000000 488056 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 892568 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 708381 1000000 1000000 1000000 1000000 697581 129893 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "451342598\n"}, {"input": "481 387700795\n1000000 1000000 320227 455362 338497 564176 1000000 1000000 545964 178947 1000000 88594 793021 1000000 1000000 602761 1000000 1000000 117318 991221 423355 1000000 1000000 75907 521931 1000000 1000000 591991 299569 999703 660087 137020 1000000 1000000 848809 800023 616222 997197 1000000 943913 1000000 585565 1000000 664997 539820 1000000 1000000 1000000 1000000 1000000 97133 1000000 1000000 1000000 398891 1000000 1000000 1000000 664754 1000000 256080 1000000 1000000 673165 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 968778 1000000 1000000 903856 1000000 686273 109065 865145 1000000 1000000 1000000 966840 732203 1000000 770717 1000000 174239 415455 1000000 931540 382314 776987 1000000 180187 699711 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 337121 747112 967240 1000000 1000000 1000000 1000000 844901 1000000 613379 1000000 1000000 346033 1000000 1000000 325608 1000000 1000000 1000000 1000000 509894 1000000 1000000 1000000 482100 711583 1000000 321567 646765 54699 1000000 980842 1000000 1000000 374280 468292 1000000 1000000 1000000 291552 1000000 1000000 1000000 1000000 466016 1000000 825794 1000000 1000000 699136 1000000 353567 929247 1000000 801292 1000000 272467 1000000 1000000 1000000 1000000 1000000 401064 1000000 626172 814011 1000000 1000000 1000000 726066 1000000 1000000 1000000 502299 1000000 1000000 997766 1000000 1000000 673149 1000000 261799 1000000 1000000 1000000 1000000 696055 1000000 212541 1000000 203470 1000000 1000000 474899 520868 1000000 158991 962559 1000000 281068 291010 1000000 733480 776547 1000000 1000000 1000000 195422 1000000 932172 515998 1000000 920039 1000000 322320 1000000 718906 181996 1000000 69686 1000000 314095 997933 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 115723 1000000 1000000 1000000 1000000 1000000 998999 1000000 967739 257224 1000000 150895 480688 1000000 885659 1000000 800971 466024 953940 1000000 1000000 1000000 1000000 1000000 1000000 480046 1000000 1000000 727002 1000000 1000000 1000000 641886 1000000 878407 1000000 908521 797185 234266 806537 1000000 1000000 504776 1000000 49204 1000000 542867 1000000 383096 1000000 1000000 482115 1000000 1000000 487674 273659 338953 16544 1000000 1000000 1000000 44631 1000000 1000000 1000000 1000000 1000000 1000000 724815 1000000 1000000 1000000 1000000 1000000 1000000 1000000 945571 1000000 999950 1000000 688165 1000000 1000000 1000000 1000000 226961 926006 1000000 15278 1000000 405205 1000000 28341 1000000 1000000 531884 1000000 388061 171299 968637 32373 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 899865 1000000 519048 1000000 1000000 1000000 1000000 1000000 1000000 841903 1000000 1000000 1000000 1000000 421040 1000000 999925 1000000 628264 808867 1000000 1000000 72309 512750 402139 1000000 1000000 78413 1000000 973599 801203 1000000 1000000 820287 663443 1000000 1000000 760878 1000000 1000000 736821 501472 921366 385624 1000000 182516 573774 1000000 553622 743587 1000000 430282 1000000 1000000 1000000 1000000 1000000 137676 454715 532514 843563 1000000 1000000 1000000 1000000 869793 1000000 129666 53179 1000000 1000000 638208 1000000 749069 649965 422630 66469 1000000 1000000 1000000 807572 1000000 1000000 447439 899951 1000000 742056 1000000 582311 1000000 1000000 906124 1000000 1000000 934889 17562 403001 117638 1000000 224913 1000000 1000000 723415 478503 1000000 1000000 1000000 255112 1000000 87206 769384 1000000 1000000 1000000 1000000 117933 1000000 1000000 1000000 1000000 1000000 255488 146143 1000000 67544 1000000 999999\n", "output": "194350400\n"}, {"input": "492 456838172\n975465 1000000 736317 1000000 999726 1000000 475997 972130 1000000 970248 677708 973505 771357 1000000 930080 854833 985891 1000000 911136 184770 1000000 1000000 888763 1000000 1000000 1000000 981426 1000000 1000000 999985 624917 1000000 1000000 1000000 658692 840654 965782 968912 911195 1000000 118408 700639 892440 409222 1000000 1000000 1000000 1000000 814886 1000000 999994 1000000 666361 1000000 1000000 704161 1000000 999518 1000000 997792 674252 1000000 937022 955730 1000000 1000000 1000000 833477 834587 1000000 917211 1000000 948471 1000000 1000000 1000000 1000000 1000000 1000000 994592 1000000 897846 934553 834704 998427 1000000 1000000 1000000 1000000 1000000 633327 803148 999990 997582 918317 1000000 1000000 1000000 1000000 732572 783000 1000000 1000000 811162 1000000 1000000 1000000 1000000 929134 998631 1000000 1000000 1000000 1000000 520271 822895 851696 743251 994449 1000000 1000000 1000000 997529 1000000 1000000 986027 570296 1000000 999082 981853 997888 1000000 988299 961568 1000000 1000000 998818 998172 212918 872974 1000000 943137 996986 939277 1000000 963687 1000000 982489 819010 1000000 1000000 794257 973420 1000000 1000000 740861 1000000 1000000 1000000 1000000 974484 927130 770377 1000000 1000000 981379 999041 945915 553387 998639 958592 1000000 1000000 43407 983765 1000000 677916 944219 1000000 961561 249757 1000000 1000000 1000000 998224 1000000 847596 1000000 1000000 329789 1000000 403092 1000000 1000000 1000000 1000000 1000000 998032 1000000 397565 1000000 1000000 1000000 988790 1000000 445280 1000000 1000000 735391 991674 999384 1000000 1000000 1000000 1000000 1000000 1000000 830669 1000000 1000000 999862 1000000 960706 480541 1000000 516981 1000000 968529 985828 951692 881244 1000000 584378 472540 916815 807538 837159 981113 662523 1000000 962190 1000000 945269 1000000 999542 934333 900358 977847 981982 992475 1000000 1000000 1000000 174772 1000000 1000000 1000000 996542 920024 1000000 977862 999833 344606 1000000 988822 1000000 997081 1000000 1000000 1000000 1000000 269411 1000000 1000000 1000000 963686 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 769937 1000000 999986 1000000 1000000 1000000 793001 1000000 771453 978727 1000000 787542 793723 1000000 912650 999994 1000000 1000000 429335 740957 1000000 1000000 980560 1000000 921493 967860 87906 1000000 922944 720039 833657 1000000 855417 1000000 1000000 1000000 1000000 1000000 1000000 1000000 923807 981039 1000000 1000000 1000000 1000000 543561 1000000 1000000 1000000 1000000 999966 237217 1000000 739405 1000000 1000000 472954 1000000 1000000 996492 1000000 642165 1000000 1000000 847379 998206 1000000 1000000 609204 1000000 1000000 1000000 1000000 843210 732593 939113 1000000 320793 1000000 1000000 1000000 1000000 1000000 981526 1000000 1000000 963891 1000000 1000000 1000000 1000000 990519 997910 1000000 946511 1000000 999926 831820 1000000 1000000 902467 1000000 1000000 835688 992226 907337 695271 900719 987405 801484 1000000 1000000 956392 999990 1000000 886539 1000000 902774 1000000 1000000 916006 1000000 980761 1000000 1000000 958736 1000000 1000000 841676 1000000 1000000 1000000 1000000 749157 1000000 910559 998816 998574 997707 1000000 1000000 996030 778222 1000000 1000000 1000000 1000000 931858 1000000 1000000 1000000 867722 1000000 709863 1000000 990536 1000000 1000000 999999 1000000 933217 1000000 1000000 982669 1000000 645066 1000000 1000000 1000000 1000000 999928 999362 902021 1000000 1000000 990535 309640 720934 1000000 1000000 869338 799844 981131 1000000 1000000 983163 1000000 694629 861846 712047 474780 1000000 864494 969894 828234 891049 642580 982999 918437 1000000 947392 1000000 1000000\n", "output": "452957024\n"}, {"input": "484 264046616\n1000000 194902 142851 735387 59352 971809 108296 831641 476924 938383 736871 756707 249298 980195 61645 1000000 619959 565430 1000000 724218 713045 403837 465778 976375 989869 773099 951519 519457 983215 885478 845954 711817 354566 325711 933677 932023 290120 165954 579850 370184 279023 652704 566110 803284 780959 27589 759454 450722 499494 182472 566075 957966 15920 375805 991757 426306 1000000 603210 189719 270779 129368 63478 959691 34311 999998 422637 825097 891231 750347 493290 715945 440553 89243 930315 117418 58366 35785 992946 1000000 719115 856065 1000000 770928 1000000 337740 296045 866147 180907 767687 288847 151669 1000000 803550 1000000 293586 944450 543933 44570 295266 380284 883595 51186 400856 532407 873136 724490 283228 738697 428558 852148 792348 570423 358359 697452 999985 503679 961177 605532 999999 117922 673921 573393 803909 23073 917010 686780 36710 378965 264141 728743 845627 303557 617609 975987 842688 1000000 882420 89416 57070 126714 304969 571245 979121 298129 61339 896887 377987 605767 363378 173730 666551 982799 39464 507164 521988 452214 917385 1000000 683419 694698 795170 70148 945102 1000000 952741 108144 27561 255387 316090 455637 788248 189072 216244 6543 92909 586672 330584 221913 772091 745948 492726 977896 745609 550950 529693 777574 990667 679563 601953 267420 368702 672184 220080 428806 952502 492105 136388 419201 715341 857887 817180 817141 623845 470196 509494 1000000 499626 20629 1000000 1000000 16276 144883 788965 540373 238910 81270 28722 1000000 745620 707649 358222 435486 5437 405510 180009 349934 118096 1000000 239324 97692 1000000 403300 305785 99604 1000000 294452 456482 519794 557957 436047 811998 1000000 843554 1000000 530878 513613 722123 69139 80562 418426 268695 758198 769335 468250 907740 106993 602127 453521 629037 5131 118933 669386 1000000 1000000 1000000 537117 339827 706496 52194 259556 743501 151338 619120 824350 5917 1000000 300210 999427 729045 601383 405155 669162 1515 711913 476190 332327 14410 13162 98977 248339 668309 44661 810588 477346 212232 671954 177029 907567 684080 236099 603076 366048 136275 392779 839833 968774 291678 386745 754600 801539 833736 795521 235236 978468 582737 897038 326822 861246 444927 969337 655342 1000000 856932 673742 621618 828209 710650 107922 999996 108145 1000000 391951 642253 303653 589230 4546 966569 556470 235180 821933 297543 973135 973439 925278 810128 1000000 453203 324575 522432 788945 361314 41256 218705 88266 1000000 688729 371933 1000000 1000000 510322 899684 507260 517496 997204 306417 1000000 228654 581237 1000000 153920 398965 864366 931634 381594 749896 628098 136364 786501 339173 199131 570528 288354 152003 999871 586648 738166 767664 484220 189231 639128 349223 289415 288419 755088 380252 630652 51982 262088 662768 1000000 452358 398891 483745 322418 801897 166290 746935 795946 155426 8596 999783 748140 102572 960809 391651 282570 99571 1000000 721360 106115 496493 374380 915554 98945 449757 344574 101712 467614 281519 936662 445959 771937 978418 275361 345215 770406 601562 411918 600337 517858 698604 31058 113653 618108 32737 433133 1000000 589204 217494 1000000 985786 809815 11658 96178 216690 1000000 1000000 390584 939914 1000000 415189 538553 888867 678089 91911 111311 639029 508546 30472 634648 606011 214457 1000000 29194 953105 685102 448796 808996 796244 237893 472924 903822 482576 109571\n", "output": "37863803\n"}, {"input": "487 715896921\n820747 812731 943038 18139 864528 741236 820107 913721 838141 1000000 954137 981571 28399 874534 117184 564896 640786 808512 546840 1000000 956403 704321 972667 14181 91315 685154 264432 420851 69880 417496 50246 795794 765353 993451 894562 989159 859316 677255 999153 921057 973759 665881 419641 998159 931754 169527 822084 987710 353860 999616 947703 941238 76375 659536 814007 1000000 694252 902079 838742 241057 522856 613312 499899 555727 780614 777954 432040 256504 797437 796688 695012 1000000 148503 544807 965404 993430 4492 980309 980943 184171 996252 935971 888835 858868 976653 933269 584880 808514 605873 884899 953059 999298 996601 564977 882570 991514 715369 360117 350814 901115 421903 865458 919280 333485 1000000 851705 801307 748101 334252 999802 836487 708651 724403 485664 463072 538333 871351 934104 930772 979492 963188 607724 971944 182970 216420 726684 874553 472796 983239 1000000 1000000 979433 733204 999907 1000000 993073 393316 503580 956209 18337 964659 550859 897853 999726 662584 1000000 579621 943217 789782 951578 1000000 996290 855564 955139 862992 995114 996211 185045 775523 906236 821161 994816 991179 155082 344306 998287 28191 947657 999078 921995 944921 932170 1000000 963207 942924 406732 1000000 724392 411504 30349 781051 257439 848370 596354 708746 1000000 1000000 524657 850160 206913 977263 527454 749273 807195 748290 891153 708501 601771 447364 846071 993360 918359 743938 153900 997783 987064 998001 896203 730393 991665 1000000 1000000 800503 704850 963885 800772 1000000 999999 701197 998090 930617 434294 52284 331727 999797 111697 1000000 871793 887056 994072 928357 588785 873473 420565 959341 902553 999749 981929 583017 766021 227991 872527 995141 1000000 613449 67224 1000000 841481 999998 727503 823168 566122 909217 1000000 853908 864361 742446 407227 409325 27103 968956 1000000 646411 268635 473678 106664 945178 929412 999999 1000000 159741 672120 858247 388367 187714 934132 606842 994936 1000000 216551 897025 138675 955438 701415 655 803492 941518 493435 654603 999986 1000000 280284 1000000 853097 1000000 529793 861866 1000000 973710 774840 483480 900809 982016 998795 789557 335102 984423 1000000 918513 987373 378977 510261 999406 999985 692790 986778 609271 716161 305443 91880 906717 775064 219839 993661 188667 441764 1000000 930546 347770 745696 985567 756169 626799 892488 858465 497612 716613 304318 312632 1000000 287225 963909 414367 1000000 951077 857845 363831 853851 361454 170506 864852 307514 890784 897286 558422 563199 271999 1000000 1000000 142623 1000000 514642 999774 601439 997743 697702 467887 1000000 949176 932088 117650 924323 987915 674762 690708 550218 899940 997498 1000000 36332 779853 1000000 1000000 876015 880243 581269 974762 825452 446114 584414 678634 808972 305729 25491 318590 783396 898957 790958 92151 186503 61870 961076 60834 804136 892890 238157 43717 894664 983788 990897 829984 197461 985427 950262 982249 420065 824249 735910 971923 750634 608480 990217 716793 51738 1000000 374904 333180 497240 860030 110393 963793 720113 19654 398682 788008 1000000 292474 627814 1000000 997395 719790 971605 102597 903531 995852 727454 812569 486193 346456 949280 975757 974834 980431 412400 708071 381546 749411 155012 713712 999970 326918 648881 992580 996046 782361 125720 530168 659056 591003 989120 77645 1000000 810857 55469 389931 930745 1000000 712810 965760 926363 977491 999063 554884 200463 919749 1000000 998932\n", "output": "346907724\n"}, {"input": "485 355083633\n1000000 1000000 860702 1000000 530756 1000000 171749 238969 398727 974843 1000000 1000000 99496 22786 1000000 1000000 1000000 491957 411917 124760 880841 343869 22759 744559 1000000 1000000 1000000 1000000 1000000 1000000 894203 1000000 999999 1000000 379203 1000000 16038 1000000 540192 1000000 395178 460612 1000000 74874 386283 919146 999993 773893 1000000 1000000 1000000 973485 1000000 788325 530972 424149 1000000 296469 603870 1000000 1000000 656580 1000000 469655 641221 1000000 544627 282257 1000000 405446 1000000 82425 1000000 1000000 306866 485892 761561 957720 1000000 927266 368271 18355 1000000 1000000 1000000 1000000 1000000 72698 637520 240530 1000000 312958 484546 358292 112622 453735 82043 855237 1000000 127280 893640 1000000 567351 590110 895993 1000000 1000000 1000000 667126 1000000 1000000 271534 569923 1000000 1000000 1000000 522569 1000000 864285 400933 989000 704258 518685 135706 277825 297736 1000000 1000000 81661 910294 332357 585048 1000000 488645 786407 1000000 672923 1000000 407273 999974 728513 444272 820893 1000000 1000000 1000000 1000000 210532 1000000 1000000 1000000 424311 877903 415886 1000000 1000000 33266 189128 66239 1000000 47173 642251 407591 1000000 1000000 966566 373107 694526 1000000 249272 1000000 319255 1000000 1000000 687523 1000000 999842 552869 1000000 1000000 1000000 1000000 1000000 1000000 835474 656225 153703 753668 664 746767 697355 1000000 1000000 1000000 1000000 336492 636432 1000000 933035 832003 679747 580468 1000000 813647 1000000 1000000 499064 258078 1000000 726567 787794 112934 1000000 927507 1000000 1000000 1000000 365907 1000000 1000000 587135 331166 1000000 1000000 844198 1000000 1000000 996220 342879 1000000 11759 153767 753497 161289 4576 1000000 1000000 998033 714574 277434 573107 1000000 574403 1000000 523999 883165 776234 820707 1000000 559014 431146 1000000 999977 614839 1000000 897700 1000000 1000000 1000000 999451 1000000 1000000 625380 1000000 1000000 1000000 1000000 887316 1000000 88961 409422 511854 839259 547106 1000000 614390 1000000 290775 996188 1000000 2820 1000000 515683 1000000 276094 329292 6290 564907 1000000 1000000 367255 248914 967175 893833 1000000 317267 635317 1000000 955035 1000000 782214 16678 1000000 1000000 1000000 975139 1000000 956487 728893 1000000 431831 1000000 856403 1000000 1000000 1000000 1000000 1000000 1000000 661103 642410 105746 361609 282209 1000000 1000000 814889 179559 1000000 1000000 1000000 47064 802104 922900 1000000 225429 879621 417862 1000000 643797 1000000 889949 522769 1000000 1000000 1000000 1000000 907718 675221 370127 859392 1000000 277110 1000000 1000000 576816 122508 448722 954574 1000000 1000000 182102 926315 1000000 32688 1000000 144364 56725 164650 616321 627147 138662 1000000 1000000 647999 1000000 992390 1000000 996494 1000000 1000000 1000000 1000000 1000000 972693 455961 1000000 82551 1000000 904246 153435 201447 319481 1000000 1000000 1000000 668515 249028 999641 644274 985652 1000000 455188 1000000 1000000 507431 1000000 1000000 835870 1000000 1000000 69057 221140 177514 1000000 1000000 87059 1000000 1000000 1000000 815281 642066 580956 1000000 554933 1000000 1000000 1000000 1000000 1000000 40088 379724 412957 336307 1000000 67986 1000000 801837 1000000 618154 1000000 864071 1000000 1000000 270249 1000000 1000000 43481 999968 378326 6314 791795 579504 996865 513705 160871 1000000 884649 510815 1000000 1000000 1000000 1000000 230657 214503 810312 1000000 918223 1000000 1000000 95942 104666 835102 1000000 999818 920186 1000000 316880 1000000 1000000 562864 1000000 910995 1000000 1000000\n", "output": "356083627\n"}, {"input": "489 301693503\n904326 915838 146863 153749 624668 200184 389309 14379 616544 273834 280840 154311 821125 562211 374216 1000000 528980 757788 27501 1000000 46900 702427 184406 475238 1000000 427826 248538 999773 1000000 742505 464357 790199 41267 365236 932378 585544 956313 1000000 1000000 447662 937452 149723 296816 697733 37718 51471 748018 793706 152831 1000000 65834 637519 999989 48657 140102 181363 748554 838855 909561 301778 478186 146592 1000000 177878 1000000 954941 822585 402976 112008 412626 564466 1000000 253822 288796 999946 1000000 1000000 576072 883636 859725 371449 433433 888455 745224 1000000 520887 679744 993240 873141 1000000 130742 756539 554460 899233 945950 874950 930541 1000000 765390 999997 216572 1000000 1000000 1000000 509709 1000000 934018 1000000 697928 527540 1000000 267389 1000000 384271 467154 397769 511928 583692 615833 1000000 841217 816582 977687 943590 772744 770197 379692 1000000 1000000 1000000 837633 139990 805146 51933 276775 857552 965061 782733 71315 453557 196671 1000000 140274 870571 345750 332871 595901 311891 706743 573587 990826 993026 93354 332744 906539 707451 598678 899859 759141 1000000 302034 362888 1000000 1000000 302176 998318 706029 268778 1000000 92760 157899 228149 1000000 355561 671058 859235 540751 887664 632848 149857 776063 422973 633790 1000000 144830 813129 953404 978524 469008 226152 698727 564045 692791 74984 860366 1000000 1000000 168183 68908 136353 711790 266068 933697 368479 776128 264023 657560 699425 371073 872346 927935 955313 973914 1000000 3301 533774 765796 924135 175027 731800 661173 60329 1000000 275078 421546 683 751486 159415 723937 106973 271931 334997 1000000 999966 706058 994192 167636 887225 164199 998615 478300 1000000 634800 846148 24861 1000000 96047 380951 1000000 289631 183419 117588 144476 810577 900453 414417 1000000 327778 374758 587843 728790 664291 443206 841991 374607 1000000 569013 783362 466487 609755 806127 958690 966233 369272 669811 459790 989886 1000000 1000000 1000000 359996 779714 948340 793426 686656 995924 173532 820999 1000000 886753 1000000 1000000 1000000 1000000 379922 516479 362108 999967 1000000 958265 459307 1000000 662363 437309 1000000 440439 255733 262099 1000000 1000000 426422 46041 71907 1000000 136922 990813 1000000 341334 428394 944662 1000000 1000000 1000000 205199 988333 956591 938910 620529 791598 647614 73570 1000000 945676 1000000 902762 175295 617943 614450 912847 769959 999836 506261 1000000 709 458093 756416 909128 1000000 744296 101909 999929 40713 1000000 401387 777465 303158 1000000 824942 95067 334803 189227 961683 927101 1000000 521345 471497 138677 105153 16937 278973 791919 1000000 1000000 1000000 635532 890718 587856 1000000 828974 718050 717267 512148 461125 833767 1000000 150790 724823 185288 763197 605037 1000000 905815 491386 999991 1000000 237425 1000000 420748 610278 938658 21086 907470 100728 999999 47189 829392 331464 704204 275477 143143 93332 56404 530332 149455 80253 1000000 240549 908611 301264 507513 159026 878235 1000000 524229 975925 578981 815290 221671 631879 1000000 164442 443857 854010 999841 1000000 289212 603322 141176 1000000 999027 1000000 89494 295064 1000000 408190 717283 64958 437201 1000000 1000000 153080 973073 370868 73435 587667 239748 793135 1000000 780460 1000000 294071 161023 348854 1000000 5714 358808 1000000 150048 496531 930747 333256 668675 809595 528736 1000000 209221 5994 1000000 682284 379583 1000000 92752 822245 740345 1000000 40400 104928 461871 459327\n", "output": "302693496\n"}, {"input": "489 438230204\n1000000 979846 802671 1000000 963362 731891 914541 695316 894459 186405 753695 426857 1000000 986795 804167 1000000 1000000 776976 987484 467461 989189 29386 999814 999919 1000000 972990 766713 486173 500530 330569 461708 1000000 999999 854695 874560 406535 174849 814890 993754 892224 812146 939085 793833 156395 546199 678083 1000000 936863 1000000 21171 785435 1000000 580 907852 943283 186260 616134 851724 144998 1000000 691605 618965 888345 939289 498660 370755 1000000 977870 818220 861332 1000000 768516 483477 943669 1000000 978200 742438 459335 514007 35811 660399 999942 476322 870545 1000000 916818 358540 750558 831730 838868 601840 48859 640994 984166 268463 938972 993552 1000000 762091 901126 1000000 815686 691026 451751 998019 976593 1000000 1000000 901884 9364 999630 1000000 1000000 999518 95954 1000000 468906 999814 909913 998439 1000000 310026 1000000 931297 997104 901984 600596 928763 726423 539985 654739 156097 608268 972097 950275 486752 816453 991935 1000000 880958 1000000 334787 228631 2469 953778 165084 1000000 898484 221645 657436 912236 955965 1000000 993242 263666 1000000 589493 527569 487141 969339 1000000 596530 1000000 302834 228121 578103 876196 890859 451695 711995 828149 726300 839420 1000000 999027 526236 980459 588913 1000000 996088 880771 999377 81700 1000000 893477 962909 736738 1000000 728571 985064 1000000 999538 999988 928601 117685 276623 406655 220382 981323 997809 1000000 695144 740317 852814 952649 865499 1000000 158538 963451 1000000 975593 276745 819818 1000000 1000000 964166 799422 440286 846094 541635 1000000 675560 512779 999421 751121 847088 988576 841341 1000000 1000000 911739 703671 380121 1000000 69509 375821 996119 865267 998988 979522 986381 1000000 592763 830788 947719 995965 609952 853386 96115 790402 1000000 1000000 65395 403470 836494 970622 482492 1000000 753756 414834 548 138957 674632 17482 122301 92960 406046 367569 808226 334780 986831 677868 756797 868918 885654 666236 1000000 477323 755384 741818 1000000 746058 880278 383011 813986 694564 999921 708978 106940 1000000 1000000 995662 999987 902410 929336 230535 1000000 543816 238008 1000000 782249 909965 45641 154715 992175 999903 1000000 986055 362421 386218 802995 885401 670179 14120 881748 722271 903370 841446 649516 851097 767946 852517 518012 823915 683412 247275 8753 962326 951493 798903 999979 1000000 1000000 73285 977696 1000000 665663 445130 994351 873112 619844 293697 498516 946459 577043 157829 923560 961499 99066 960070 401879 878930 1000000 913805 1000000 999556 972532 926706 947363 641699 1000000 962292 622374 1000000 913255 119267 400473 630811 873550 648020 785809 1000000 464566 1000000 958648 671648 791963 1000000 749483 349367 171271 1000000 925481 939019 971720 999840 307904 1000000 767033 548271 395798 311114 939874 914713 989164 65153 796726 1000000 993495 973612 178334 976614 44482 726026 593139 986479 987296 933029 999996 79457 761955 973489 751723 559021 541378 1000000 134528 914894 998221 734438 710251 901926 937732 1000000 1000000 1000000 637134 385161 1000000 469210 757421 619986 788095 708289 748946 170274 256014 966845 1000000 965528 220191 884448 904562 602433 801060 234846 796242 697864 358440 795396 752844 826 108284 92017 670773 664089 1000000 1242 1000000 908621 967176 474430 1000000 771629 895665 995753 977650 919875 473666 746046 824142 982015 203900 836953 787043 723572 984324 761659 462686 989592 48366 887690 1000000 155787 844018 1000000 850080 864117 698767\n", "output": "356972371\n"}, {"input": "499 509697025\n1000000 998133 1000000 992299 961842 996213 902175 962505 1000000 1000000 999958 1000000 995201 740917 1000000 995226 995044 830418 545751 952422 987644 802619 954193 837017 1000000 978776 972637 999495 985252 998458 632750 1000000 996107 973566 907077 999934 977307 966908 999816 847561 987591 999439 849148 991691 999549 877281 972573 994565 1000000 968847 997458 1000000 998184 999718 1000000 994108 971126 998700 988397 990096 998298 1000000 757212 976384 982113 560206 957054 987957 971314 1000000 961742 1000000 991273 995625 1000000 987583 1000000 998551 973433 1000000 794939 999167 934531 994896 851291 726113 992771 996633 999583 1000000 987596 991342 1000000 942667 999462 999564 970129 991424 1000000 919172 1000000 968979 993444 1000000 983894 999289 999457 884824 759222 963971 997130 998752 999355 999431 999148 1000000 982499 999997 991025 961722 990266 765587 991971 984479 996935 998976 1000000 860286 1000000 994887 997175 999990 999951 768830 843178 674739 984286 998881 999435 982494 995791 776395 984676 913473 980068 741778 1000000 757304 999999 986843 998088 976043 938037 703160 998081 927377 833753 945532 961921 976573 997290 999978 976672 1000000 1000000 822193 1000000 929333 1000000 995883 997776 995597 977929 893752 952163 999990 998079 998914 978537 961610 1000000 998026 999999 961686 1000000 989586 990745 1000000 964820 999852 991534 998811 1000000 998717 999026 1000000 971092 906664 651727 1000000 999982 934294 990543 999994 990475 1000000 999863 999998 997381 951207 999406 925143 999938 997269 964596 999917 1000000 999999 974440 996541 999651 983336 1000000 999967 999498 981597 998255 1000000 999881 831656 1000000 999997 974197 919727 995026 996315 999597 1000000 955606 985692 892558 982223 993427 1000000 687634 800457 1000000 996981 978194 754704 994009 991904 769033 996917 972555 933764 977804 974570 999999 845107 996299 911648 962666 709480 895326 999967 1000000 996191 999924 986594 1000000 999276 1000000 962897 999999 991217 1000000 956914 1000000 999219 999959 823629 991177 974857 997708 1000000 988519 926612 999010 997482 996325 999723 982056 936409 999982 928615 713899 978007 995694 1000000 1000000 999004 1000000 1000000 999806 884176 990023 980712 998852 730114 1000000 996114 833841 1000000 992273 1000000 933099 1000000 928785 998456 794690 999848 986159 1000000 1000000 825600 962775 671464 943116 1000000 923195 622268 1000000 937329 977695 999999 1000000 999569 985968 984947 1000000 988946 1000000 991527 1000000 999116 999568 780113 871195 999885 955414 999867 881906 984998 995003 999378 1000000 999988 952687 821761 893765 993271 989182 951068 997960 967763 968856 975851 999933 1000000 997711 1000000 997044 999890 975127 995515 657641 999977 994676 999718 998419 945548 994661 999935 912419 975997 873153 891168 952023 999287 949777 976297 1000000 934788 984067 906583 989876 997729 985035 1000000 955548 978411 842134 980392 995045 1000000 999892 998716 822603 890066 872842 999997 857020 1000000 999202 981561 784490 977015 999999 1000000 997424 1000000 999278 973872 943537 418816 1000000 995924 824095 1000000 921276 1000000 995288 924147 991837 916436 1000000 976931 996681 999992 973830 840166 990905 986570 958147 600345 998740 555508 938364 828108 1000000 114561 999928 1000000 965469 993125 999516 993604 1000000 997272 921230 707268 938931 993620 1000000 857963 985841 932648 995804 999953 716729 978581 992684 671122 1000000 982243 999777 954434 998330 988810 925651 999972 995232 997690 1000000 982045 999739 905056 941290 993232 1000000 851138 948000 999114 998865 998743 997671 913749 999979\n", "output": "475871877\n"}, {"input": "486 2541\n1000000 1000000 1000000 1000000 1000000 999044 1000000 1000000 1000000 1000000 1000000 1000000 999994 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999736 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 927324 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 979307 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999162 999950 1000000 1000000 562932 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999849 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 993188 1000000 1000000 1000000 999920 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 802661 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 994338 1000000 1000000 999819 1000000 1000000 1000000 253867 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "3\n"}, {"input": "483 3560\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999996 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999995 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "102\n"}, {"input": "491 30616\n1000000 1000000 999971 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999988 1000000 1000000 1000000 1000000 1000000 1000000 999996 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999936 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "369\n"}, {"input": "483 24675\n1000000 610645 1000000 1000000 1000000 370252 1000000 1000000 1000000 952219 1000000 1000000 1000000 5095 107814 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 521252 1000000 1000000 1000000 1000000 1000000 1000000 1000000 238942 1000000 1000000 1000000 1000000 1000000 1000000 1000000 992652 1000000 1000000 1000000 1000000 1000000 300600 558398 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 585880 1000000 531822 1000000 1000000 1000000 711210 1000000 411677 1000000 533742 1000000 1000000 1000000 999498 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 163986 1000000 1000000 1000000 1000000 1000000 600980 1000000 1000000 1000000 135900 1000000 1000000 999917 1000000 1000000 1000000 35938 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 380774 1000000 1000000 862512 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 31408 1000000 1000000 1000000 1000000 420988 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 407096 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 912412 1000000 1000000 1000000 1000000 1000000 999648 1000000 189356 1000000 1000000 1000000 1000000 1000000 1000000 1000000 687352 1000000 1000000 1000000 1000000 1000000 293544 1000000 739296 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 560211 1000000 1000000 1000000 1000000 999569 865663 768892 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 890760 1000000 1000000 1000000 1000000 1000000 1000000 997747 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 299282 1000000 1000000 104482 1000000 478972 438202 1000000 1000000 110834 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 997412 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 650206 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 255496 1000000 634094 1000000 302906 1000000 498959 28086 1000000 1000000 227406 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 698526 1000000 1000000 1000000 842580 55266 1000000 1000000 1000000 1000000 234050 951330 1000000 1000000 1000000 1000000 1000000 1000000 1000000 441322 1000000 708323 1000000 1000000 1000000 1000000 999999 705774 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 169737 999993 1000000 1000000 1000000 1000000 1000000 999720 1000000 1000000 1000000 1000000 1000000 1000000 363306 288712 1000000 1000000 1000000 1000000 1000000 480784 1000000 1000000 1000000 1000000 1000000 533030 1000000 999990 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 549338 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 928650 1000000 1000000 1000000 719968 1000000 1000000 1000000 1000000 1000000 1000000 997234 1000000 1000000 1000000 1000000\n", "output": "151\n"}, {"input": "494 24885\n1000000 1000000 429312 1000000 1000000 1000000 1000000 1000000 290983 1000000 1000000 1000000 823680 1000000 1000000 1000000 1000000 1000000 1000000 999234 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 282880 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 892320 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 585232 947714 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 661024 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 877194 1000000 1000000 381861 1000000 999999 1000000 1000000 1000000 1000000 383968 1000000 586977 1000000 1000000 1000000 1000000 1000000 1000000 601120 1000000 1000000 1000000 1000000 1000000 913120 1000000 1000000 1000000 794144 1000000 446368 1000000 1000000 1000000 424223 1000000 1000000 1000000 408928 1000000 11649 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 768352 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 175968 1000000 1000000 1000000 1000000 1000000 936832 1000000 1000000 1000000 1000000 448893 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 755872 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999935 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 306592 999473 1000000 561600 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 776181 1000000 1000000 1000000 116038 1000000 1000000 1000000 1000000 1000000 366080 999999 1000000 1000000 1000000 997782 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 352362 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999980 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 994842 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 195520 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 363168 1000000 220896 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 649792 1000000 1000000 1000000 1000000 1000000 989515 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 149760 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 172224 1000000 1000000 1000000 245119 1000000 739459 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "520\n"}, {"input": "480 20951\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 340839 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 570650 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 173495 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999995 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 301151 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 250295 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999853 1000000 1000000 1000000 892713 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 333139 1000000 1000000 1000000 1000000 1000000 1000000 134021 1000000 1000000 1000000 1000000 313129 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 546844 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 697210 999167 1000000 999534 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999718 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 48025 1000000 1000000 1000000 1000000 1000000 1000000 1000000 981319 770847 1000000 1000000 1000000 1000000 1000000 73597 1000000 397522 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 552293 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 996830 175770 1000000 1000000 384201 737115 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 280241 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999343 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 364529 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 497448 1000000 643005 1000000 1000000 1000000 1000000 1000000 999993 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "565\n"}, {"input": "492 28095\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999964 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999943 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999959 1000000 1000000 1000000 1000000 1000000 1000000 999996 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999804 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999993 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999982 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999995 1000000 1000000 1000000 1000000 1000000\n", "output": "85\n"}, {"input": "484 86498\n1000000 1000000 1000000 1000000 999644 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999993 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 169548 380195 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 349821 1000000 326054 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 658876 1000000 1000000 1000000 1000000 1000000 975450 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 601298 1000000 1000000 1000000 1000000 1000000 501148 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 897637 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 440154 1000000 1000000 1000000 1000000 1000000 1000000 1000000 996774 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999983 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 83686 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999992 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 769901 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 408081 1000000 1000000 1000000 764716 1000000 1000000 411399 1000000 1000000 1000000 1000000 1000000 208963 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 741754 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 712134 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999966 1000000 1000000 1000000 1000000 1000000 329215 1000000 1000000 342447 1000000 1000000 1000000\n", "output": "1653\n"}, {"input": "490 94215\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 565056 1000000 1000000 669667 1000000 892517 1000000 1000000 1000000 619512 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999241 1000000 1000000 806976 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 989280 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 22464 1000000 1000000 1000000 1000000 1000000 1000000 1000000 995085 1000000 1000000 1000000 1000000 965952 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 30630 775008 1000000 1000000 1000000 1000000 1000000 1000000 1000000 515808 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 469040 1000000 1000000 263541 1000000 1000000 1000000 1000000 720576 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 705896 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 771552 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 875797 1000000 1000000 1000000 1000000 1000000 946090 1000000 271296 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 394848 1000000 710244 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 726903 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 840672 1000000 1000000 1000000 1000000 292032 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999915 1000000 1000000 88128 1000000 552960 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 228960 1000000 1000000 448416 1000000 1000000 1000000 1000000 875235 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 740448 1000000 1000000 1000000 1000000 59616 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999992 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 550368 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 939807 827712 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 416448 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999987 1000000 678240 1000000 1000000 1000000 1000000 436347 539136 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 124416 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 998130 522445 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 452485 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 946664\n", "output": "864\n"}, {"input": "496 100858\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 997095 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 880270 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 378989 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 338597 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 702293 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 35864 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 709929 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999997 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 788060 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999995 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 954656 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 985535 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999978 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999966 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 986908 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999897 1000000 1000000 980010 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999994 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 734125 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "451\n"}, {"input": "483 127593\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999805 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 998958 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999968 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999665 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999785 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 997667 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "1061\n"}, {"input": "489 139003\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 998032 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999996 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999959 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999769 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 999823 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999541 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "2062\n"}, {"input": "495 2528\n1000000 1000000 1000000 1000000 1000000 1000000 999985 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999250 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999979 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999993 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999969 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999975 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 972650 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "409\n"}, {"input": "496 35492\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999996 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999907 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999972 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999883 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999980 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "1309\n"}, {"input": "492 175243\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 349446 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 327140 1000000 1000000 1000000 1000000 1000000 1000000 275095 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 41636 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 465836 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 801349 1000000 1000000 1000000 1000000 1000000 1000000 1000000 179927 1000000 920453 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 811498 1000000 199279 1000000 999981 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 967598 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 49071 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 242389 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 359856 1000000 1000000 1000000 1000000 714513 1000000 1000000 1000000 1000000 1000000 646018 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 757181 1000000 1000000 1000000 1000000 1000000 1000000 791084 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 336062 1000000 1000000 1000000 1000000 1000000 979915 1000000 1000000 1000000 1000000 1000000 746475 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 984669 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 52045 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 989427 999996 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 516151 1000000 395520 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 895898 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 993965 1000000 1000000 1000000\n", "output": "1487\n"}, {"input": "493 194563\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999973 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999976 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999527 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999972 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999624 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999515 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "793\n"}, {"input": "487 187240\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999538 1000000 999989 1000000 1000000 1000000 999959 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999983 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "1635\n"}, {"input": "498 191707\n1000000 271596 6990 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999973 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 172436 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 238519 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999853 865277 1000000 31647 1000000 1000000 1000000 1000000 1000000 468329 1000000 283783 964514 1000000 1000000 1000000 1000000 1000000 993228 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 41784 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 788767 1000000 998679 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 998600 1000000 1000000 893133 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 200866 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 139724 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 511857 1000000 1000000 1000000 1000000 41976 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 781508 1000000 207179 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 119481 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 278460 1000000 229824 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 652974 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999893 1000000 1000000 1000000 1000000 1000000 999334 1000000 552578 1000000 1000000 1000000 1000000 1000000 1000000 1000000 904178 1000000 1000000 1000000 1000000 50642 1000000 1000000 673295 1000000 1000000 1000000 1000000 1000000 1000000 1000000 421322 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 396949 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 537973 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 666832 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 243740 1000000 285524 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 348200 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999992 853249 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999997 1000000 1000000 1000000 569307 1000000 1000000 1000000 1000000 829479 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 927953 1000000\n", "output": "1741\n"}, {"input": "483 113423\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999241 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999603 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999995 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 998832 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999957 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "911\n"}, {"input": "488 221246\n1000000 1000000 963443 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 934151 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 149734 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999413 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999420 973254 1000000 1000000 1000000 1000000 999888 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 396232 978781 1000000 1000000 1000000 999995 1000000 1000000 1000000 1000000 1000000 357550 1000000 1000000 1000000 939711 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999992 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 992922 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 265369 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 579284 1000000 1000000 991024 999160 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 965629 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 255909 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 527126 1000000 1000000 1000000 1000000 999379 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 293005 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999891 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 150048 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "2785\n"}, {"input": "500 65\n1000000 547584 203912 1000000 1000000 491308 706966 728966 913530 1000000 1000000 1000000 1000000 144647 1000000 1000000 71928 1000000 627720 1000000 881139 1000000 171793 683770 744177 1000000 824491 60212 56760 1000000 866488 1000000 780170 1000000 69401 1000000 1000000 154124 1000000 592813 373477 1000000 323628 222735 999978 608998 1000000 221319 796461 1000000 1000000 7062 1000000 39116 673733 1000000 1000000 17922 976507 963346 1000000 953879 1000000 719519 626330 1000000 1000000 514422 1000000 1000000 411581 1000000 1000000 1000000 1000000 1000000 985922 1000000 508791 911311 1000000 586233 682983 1000000 619179 1000000 951248 421600 723824 1000000 1000000 444970 1000000 190729 1000000 1000000 1000000 62434 1000000 1000000 580332 1000000 904497 291759 431810 21887 47349 509345 357217 1000000 721940 125922 459997 1000000 507613 1000000 1000000 1000000 1000000 969700 1000000 1000000 1000000 801695 1000000 1000000 82259 1000000 1000000 187644 258735 1000000 448374 1000000 832832 23415 1000000 576268 1000000 1000000 1000000 1000000 1000000 276663 1000000 181458 1000000 1000000 1000000 1000000 651261 612788 1000000 136532 1000000 1000000 1000000 125740 1000000 1000000 12836 1000000 787407 806692 1000000 781625 1000000 971756 1000000 816077 1000000 1000000 712412 193947 198230 847618 1000000 1000000 373325 595793 389836 5966 287291 537826 1000000 1000000 1000000 1000000 1000000 830670 772633 1000000 1000000 324320 1000000 303871 1000000 988936 1000000 1000000 1000000 62182 1000000 157045 1000000 867827 1000000 579598 920852 152508 270412 1000000 228493 1000000 1000000 1000000 1000000 154434 372084 1000000 1000000 278884 1000000 989775 424395 237914 1000000 1000000 713996 807572 372498 1000000 428466 758599 964687 947242 1000000 281450 1000000 489175 563335 1000000 369663 1000000 16828 424851 1000000 1000000 83715 559395 1000000 819601 506853 601908 119658 685661 162883 1000000 1000000 104589 449546 114581 1000000 1000000 1000000 1000000 1000000 1000000 1000000 436645 1000000 416744 167260 962435 262453 845365 1000000 260058 561571 52837 999997 785281 211703 537297 983256 278290 317530 1000000 745152 1000000 1000000 1000000 734270 1000000 910623 179265 1000000 258475 445387 963359 942020 123164 503203 329102 1000000 1000000 477574 1000000 442841 787946 1000000 681603 230591 847714 1000000 116590 705318 1000000 1000000 1000000 1000000 91402 1000000 1000000 1000000 1000000 1000000 1000000 226513 737158 1000000 1000000 17614 529162 553943 468231 1000000 805170 1000000 25879 849012 817483 576371 943647 419589 765323 397460 1000000 1000000 1000000 867830 1000000 1000000 1000000 1000000 1000000 727686 299818 925899 1000000 1000000 1000000 402944 653707 216287 1000000 1000000 904663 663944 999418 369363 1000000 1000000 723970 1000000 1000000 472495 1000000 1000000 722256 1000000 196426 1000000 234037 861603 753040 1000000 1000000 1000000 1000000 1000000 990020 1000000 1000000 1000000 285685 1000000 269229 313122 444394 1000000 22138 999895 380541 1000000 58445 441854 1000000 379443 699780 1000000 943042 1000000 1000000 939114 652472 366138 837802 937941 863958 929910 274655 845326 1000000 534752 137050 1000000 17466 1000000 1000000 261983 943722 797002 1000000 814217 1000000 241315 1000000 343300 1000000 591619 814263 717912 56161 1000000 1000000 258571 279026 928599 999999 1000000 858939 725504 1000000 447775 878032 967038 1000000 994827 1000000 969295 1000000 1000000 182802 365562 1000000 349512 145610 1000000 287574 1000000 1000000 125615 473421 1000000 1000000 1000000 1000000 1000000 1000000 10587 1000000 1000000 36202 1000000 1000000 866860 993015 1000000 1000000 1000000 247756 265297 1000000 485083 687029 126609 452451 197337 524955\n", "output": "1\n"}, {"input": "500 114\n94191 278785 306413 546153 682696 1000000 1000000 1000000 915040 584376 1000000 58887 1000000 258907 290027 421888 560617 430379 552788 534231 1000000 542138 335665 761304 46920 27599 910116 974234 957824 724020 668254 408450 87209 257751 144698 999917 939718 1000000 70019 1000000 933012 847648 551977 616629 202375 421623 754450 929695 464355 920817 1000000 25305 7723 710555 693973 981253 1000000 1000000 64675 888340 523675 557755 761890 333307 253706 203171 846024 498427 1000000 1000000 103207 547641 799254 671192 178164 1000000 797634 347501 511419 799903 511811 936984 519176 135767 772750 710177 170003 556591 38065 1000000 309015 194755 575367 503669 1000000 262052 649089 442384 993865 37706 644010 263039 92769 1000000 104851 1000000 487294 48861 429172 909718 753551 467077 639564 713065 1000000 913326 1000000 1000000 580899 392727 1000000 751446 386447 589110 1000000 595240 818349 625821 89923 877200 134258 625481 115972 315901 449396 830952 549061 775635 6371 1000000 559237 549605 596982 549273 389685 515472 1000000 1000000 282119 990155 29618 515073 732180 825775 610157 1000000 123515 872221 498836 142389 1000000 10145 54921 475879 53590 881921 763022 373445 1000000 165536 731396 705062 154768 754944 827487 1000000 540433 384089 436856 271947 745161 691824 254525 284092 539756 561415 547043 877274 362895 508107 856681 1000000 1000000 632308 787373 809592 781372 164948 661876 589198 527967 917094 116443 834527 903255 27055 999961 1000000 14120 878807 535638 440242 1000000 869182 576495 702675 632018 640321 117792 30813 1000000 613633 870469 241233 606826 782736 123075 192090 351683 1000000 527832 630334 508285 119750 158024 333939 311792 324758 341366 340965 215239 226290 1000000 504040 490679 67592 76601 420333 330338 162426 685771 1000000 581741 749018 62917 562199 434752 975373 562159 885880 467386 834687 153729 1000000 792238 441896 500965 484925 169255 1000000 1000000 501573 729377 927081 559886 825546 389532 1000000 53944 663609 517225 397206 326632 629073 854106 978051 568470 98489 136695 143696 58045 191739 164495 107280 816318 657763 375925 670337 1000000 1000000 954566 176690 442378 866005 786591 999998 1000000 1000000 515501 207857 11764 1000000 307662 1000000 580257 658624 681582 717195 184153 542581 129773 298939 197392 1000000 297680 475886 469792 999670 671054 1000000 999887 2196 921620 500437 1000000 725460 508629 840242 327433 1000000 1000000 1000000 241046 31111 587096 962550 224379 999578 706952 20349 810182 1000000 1000000 494842 220090 73654 911511 999968 332695 389789 456389 896306 328063 747334 617049 1000000 189951 747355 581148 568280 1000000 190159 392921 1000000 80168 759258 223661 269017 492622 65851 986264 265261 378748 817213 878217 230640 720107 369479 829136 230281 817743 806711 876491 750445 988970 646390 275820 541007 269166 870346 874128 49972 1000000 532569 505676 1000000 165688 1000000 224618 379623 661840 422617 113106 409501 880430 399377 975141 1000000 209009 408253 719833 1000000 501070 1000000 664496 908274 50764 1000000 1000000 680544 626741 1000000 268951 12683 1000000 705726 406807 192766 432309 1000000 1000000 611031 335621 216135 1000000 567660 996718 136261 614459 563410 1000000 474113 749038 1000000 302125 449744 999258 459225 1000000 628168 464214 190913 1000000 462111 73983 30827 586106 906130 607342 694242 857035 86099 947154 994338 185629 1000000 794361 341031 292086 557582 851555 965697 576877 522723 1000000 572338 1000000 928325 501293 413788 625351 833691 584241 356482 502553 358366 982475 1000000 1000000 1000000\n", "output": "1\n"}, {"input": "500 7\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 987093 1000000 1000000 1000000 1000000 1000000 618689 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999998 1000000 1000000 1000000 1000000 1000000 999742 193383 1000000 102479 1000000 1000000 1000000 1000000 1000000 1000000 951770 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 998623 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999905 1000000 1000000 1000000 1000000 1000000 1000000 1000000 454258 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999940 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 299136 1000000 1000000 999868 374010 999895 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 826630 1000000 1000000 999998 1000000 1000000 999995 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 285163 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 229040 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 996724 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 997050 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 961884 1000000 1000000 1000000 1000000 886198 1000000 1000000 1000000 1000000 1000000 520634 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 734988 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999992 1000000 700965 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 251140 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999854 1000000 1000000 1000000 674145 1000000 1000000 1000000 1000000 965398 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 214906 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 378695 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 552981 1000000 934433 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n", "output": "1\n"}, {"input": "500 62\n631644 725400 1000000 1000000 343921 1000000 1000000 244478 1000000 981049 170802 117263 1000000 1000000 584142 1000000 673789 855889 662182 385439 1000000 146597 970806 1000000 849303 1000000 821160 354213 1000000 620882 80988 233311 758094 1000000 887108 1000000 206409 1000000 374926 1000000 663710 1000000 1000000 1000000 1000000 702611 1000000 981250 1000000 1000000 300026 1000000 927564 1000000 306386 349512 1000000 346223 1000000 901520 302869 998687 1000000 702542 147186 1000000 1000000 1000000 1000000 191681 1000000 1000000 428652 946342 1000000 1000000 278287 982561 205717 720679 940917 61313 1000000 949909 1000000 64736 1000000 766787 69104 317017 251038 1000000 587244 1000000 1000000 1000000 1000000 751984 1000000 1000000 1000000 1000000 713525 866001 281305 676259 106149 501642 1000000 1000000 742788 939334 1000000 979063 348746 1000000 981860 734376 1000000 1000000 607279 1000000 614358 998328 1000000 97352 1000000 1000000 1000000 1000000 1000000 708526 1000000 1000000 1000000 117715 975113 794312 204751 800514 1000000 715254 1000000 597346 1000000 852597 1000000 438254 627112 1000000 927512 1000000 432833 1000000 327453 939426 1000000 609361 822528 1000000 207891 819006 322012 1000000 88115 514102 1000000 1000000 336085 608044 551950 379018 1000000 891461 256128 175657 685286 229446 57395 1000000 846693 1000000 837110 1000000 793583 525988 1000000 1000000 669448 1000000 1000000 18545 386824 83166 738972 1000000 1000000 438947 537926 767737 416245 487615 1000000 34590 1000000 336545 971338 436388 1000000 263745 1000000 1000000 622969 1000000 586402 247266 1000000 567371 1000000 1000000 1000000 1000000 1000000 838798 1000000 898837 1000000 907323 1000000 1000000 1000000 458238 1000000 1000000 1000000 335995 1000000 1000000 64878 322018 1000000 1000000 1000000 1000000 822909 999999 619288 534380 861775 460071 374487 1000000 999902 1000000 793991 1000000 252250 1000000 1000000 291872 88337 332590 326167 524029 1000000 351582 587142 1000000 266258 1000000 677291 998574 370081 820980 603369 1000000 1000000 891806 878142 313031 1000000 1000000 418236 1000000 1000000 973356 1000000 488903 1000000 337597 1000000 1000000 1000000 517254 1000000 1000000 1000000 173517 1000000 853079 780081 575852 235736 122062 368045 224359 808908 1000000 777321 104901 779589 581356 854942 1000000 805507 979038 499830 1000000 100342 420308 497195 244068 562463 158886 998866 1000000 1000000 475534 184829 329219 692926 1000000 1000000 328451 945698 560159 1000000 1000000 1000000 119937 554424 1000000 459614 306808 928036 187071 1000000 258682 791270 650586 470776 132003 1000000 1000000 121600 142899 663220 637 1000000 883895 965496 213147 513221 416963 282400 1000000 938370 638810 861976 1000000 1000000 325625 1000000 516505 1000000 1000000 912284 301999 809759 778065 1000000 1000000 686270 957271 1000000 1000000 746267 1000000 712232 1000000 1000000 1000000 929578 735909 1000000 454896 1000000 1000000 1000000 1000000 1000000 255225 992370 1000000 1000000 650172 1000000 1000000 1000000 1000000 271226 1000000 528928 1000000 1000000 85031 1000000 97710 1000000 382633 36448 1000000 638516 684015 417478 969604 1000000 201566 999999 104318 1000000 422045 599566 752841 1000000 783057 978854 717060 1000000 136705 1000000 1000000 1000000 1000000 999998 72624 440869 862724 934742 1000000 215737 820322 4440 1000000 1000000 59593 208369 213124 979068 828294 266470 1000000 1000000 1000000 949922 348525 827492 889690 1000000 1000000 515711 595072 45486 1000000 536192 574501 7490 1000000 788141 1000000 1000000 1000000 1000000 394593 549211 426988 1000000 26191 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 110612 955500 781008\n", "output": "1\n"}, {"input": "500 55\n1000000 334540 891625 1000000 281442 1000000 1000000 1000000 463382 280097 1000000 1000000 452139 815770 1000000 1000000 1000000 631989 996270 1000000 1000000 1000000 1000000 1000000 1000000 795828 1000000 1000000 1000000 1000000 962606 928241 698713 883552 1000000 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 776645 917772 1000000 993836 1000000 677572 1000000 1000000 1000000 959463 1000000 174912 782573 236619 1000000 891134 423283 446152 1000000 1000000 1000000 547885 1000000 1000000 996419 1000000 1000000 880057 1000000 1000000 881930 1000000 683875 943968 634002 1000000 1000000 1000000 872307 972441 1000000 1000000 975926 1000000 1000000 1000000 1000000 508617 1000000 1000000 650957 1000000 987315 1000000 1000000 1000000 1000000 1000000 1000000 1000000 819218 106024 1000000 474460 977399 1000000 358603 1000000 368660 1000000 743935 1000000 967215 1000000 1000000 655987 1000000 1000000 1000000 713729 1000000 1000000 363671 1000000 864219 1000000 1000000 1000000 254539 1000000 1000000 456973 912268 286259 1000000 1000000 997857 1000000 1000000 316561 1000000 1000000 1000000 995992 254531 1000000 1000000 570664 353003 685983 545993 1000000 1000000 1000000 1000000 716848 1000000 733488 555799 666361 527750 1000000 965372 1000000 1000000 1000000 878630 1000000 138000 1000000 1000000 909705 872583 709545 1000000 700668 1000000 1000000 813739 932934 1000000 964327 1000000 693475 1000000 1000000 797296 1000000 764480 985204 1000000 1000000 1000000 1000000 1000000 1000000 1000000 535462 476079 984367 1000000 967654 856275 1000000 1000000 1000000 1000000 1000000 1000000 867952 879942 1000000 154407 1000000 1000000 911749 1000000 993559 555758 558804 1000000 1000000 973939 1000000 1000000 1000000 685565 1000000 1000000 760700 609879 501796 842928 1000000 1000000 1000000 615818 1000000 984958 993760 912636 911254 978741 1000000 1000000 961351 1000000 829953 1000000 887629 975436 638855 1000000 1000000 942628 995881 1000000 780088 1000000 420106 1000000 1000000 660756 530127 1000000 1000000 163418 815463 886126 684287 1000000 1000000 955622 1000000 982895 1000000 912574 1000000 866208 1000000 948902 195050 1000000 1000000 941585 404226 1000000 721447 1000000 1000000 1000000 999814 920770 1000000 800099 1000000 1000000 1000000 968501 1000000 996652 968157 917097 1000000 806353 1000000 516982 1000000 1000000 868946 290092 1000000 857874 940045 395165 1000000 1000000 355186 1000000 1000000 1000000 1000000 685630 932351 1000000 1000000 1000000 1000000 1000000 221542 910433 714135 1000000 250408 880260 1000000 1000000 1000000 1000000 919358 495872 687096 1000000 905777 999094 936461 995177 1000000 1000000 1000000 872999 1000000 837544 1000000 838134 880058 1000000 395271 999187 923355 1000000 543459 980298 1000000 480711 1000000 1000000 1000000 1000000 979331 92282 984480 1000000 779663 1000000 1000000 1000000 689599 1000000 338444 1000000 1000000 476308 798177 1000000 542177 1000000 996188 999152 963781 999993 710941 1000000 1000000 843994 1000000 387062 1000000 1000000 160681 1000000 1000000 1000000 1000000 157509 993434 1000000 1000000 1000000 988046 1000000 991580 675549 956441 644135 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 974441 935008 932845 1000000 1000000 489120 1000000 1000000 482596 858537 161521 1000000 1000000 940690 1000000 1000000 1000000 707102 1000000 1000000 1000000 1000000 1000000 1000000 763746 868334 746818 1000000 1000000 844243 1000000 1000000 1000000 1000000 885510 919665 1000000 992051 1000000 1000000 1000000 1000000 854150 672202 984101 1000000 999914 1000000 206729 979213 1000000 1000000 644524 1000000 1000000 1000000 881814 1000000 1000000 667605 1000000 1000000 1000000 999034 1000000 816945 1000000 632692 987805 1000000\n", "output": "1\n"}] |
|
162 | 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.
-----Input-----
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.
-----Output-----
Print one integer number — the minimum number of hours required to water the garden.
-----Examples-----
Input
3 6
2 3 5
Output
2
Input
6 7
1 2 3 4 5 6
Output
7
-----Note-----
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | interview | [{"code": "n, k = map(int, input().split())\na = list(map(int, input().split()))\n\nmaxd = -1\nfor x in a:\n if k % x == 0:\n maxd = max(maxd, x)\nprint(k // maxd)", "passed": true, "time": 0.15, "memory": 14624.0, "status": "done"}, {"code": "import itertools as it, math, functools as ft\nn, k = map(int, input().split())\na = list(map(int, input().split()))\nres = 100000\nfor i in a:\n\tif k % i == 0:\n\t\tres = min(res, k // i)\nprint(res)", "passed": true, "time": 0.26, "memory": 14572.0, "status": "done"}, {"code": "n, k =list(map(int, input().split()))\na = list(map(int, input().split()))\nm = 0\nfor i in a:\n if k % i == 0:\n m = max(m, i)\nprint(k//m)\n", "passed": true, "time": 0.2, "memory": 14564.0, "status": "done"}, {"code": "R=lambda:list(map(int,input().split()))\nn,k=R()\na=k\nfor i in R():\n if k%i==0:\n a=min(a,k//i)\nprint(a)\n", "passed": true, "time": 0.15, "memory": 14548.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nmaxi = 0\na = list(map(int, input().split()))\nfor i in a:\n if k % i == 0:\n maxi = max(maxi, i)\nprint(k // maxi)", "passed": true, "time": 0.2, "memory": 14348.0, "status": "done"}, {"code": "n,k = list(map(int, input().strip().split()))\n\na = list(map(int, input().strip().split()))\n\nmaks = 0\n\nfor e in a:\n if k % e == 0:\n maks = max(maks,e)\n\nprint(k//maks)\n", "passed": true, "time": 0.21, "memory": 14364.0, "status": "done"}, {"code": "def main():\n\tn, k = map(int, input().split())\n\tarr = list(map(int, input().split()))\n\tarr = [i for i in arr if k % i == 0]\n\tprint(k // max(arr))\n\nmain()", "passed": true, "time": 0.19, "memory": 14608.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nfor i in sorted(a)[::-1]:\n if (k % i == 0):\n print(k // i)\n break\n", "passed": true, "time": 0.23, "memory": 14584.0, "status": "done"}, {"code": "n, k = [int(z) for z in input().split()]\na = [int(z) for z in input().split()]\na.sort()\nfor i in range(len(a) - 1, -1, -1):\n if k % a[i] == 0:\n print(k // a[i])\n return", "passed": true, "time": 0.15, "memory": 14560.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\npossible = []\nfor x in map(int, input().split()):\n\tif k % x == 0:\n\t\tpossible.append(x)\n\nprint(min([k // x for x in possible]))", "passed": true, "time": 1.01, "memory": 14508.0, "status": "done"}, {"code": "n, k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\na.sort()\nfor i in range(n - 1, -1, -1):\n if k % a[i] == 0:\n print(k // a[i])\n break", "passed": true, "time": 0.2, "memory": 14448.0, "status": "done"}, {"code": "from sys import stdin as cin\nfrom sys import stdout as cout\n\ndef main():\n n, k = list(map(int, cin.readline().split()))\n a = list(map(int, cin.readline().split()))\n o = 864236415217\n for i in a:\n if k % i == 0:\n o = min(o, k // i)\n print(o)\n\nmain()\n", "passed": true, "time": 0.15, "memory": 14552.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nans = 0\nfor i in a:\n if k % i == 0:\n ans = max(ans, i)\n\nprint(k // ans)\n", "passed": true, "time": 0.14, "memory": 14472.0, "status": "done"}, {"code": "n,k = [int(x) for x in input().split()]\nA = [int(x) for x in input().split()]\n\nh = 100000000000\nfor a in A:\n if k%a==0:\n h = min(h,k//a)\nprint(h)\n", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}, {"code": "\nn, k = list(map(int, input().split()))\n\ntab = [int(x) for x in input().split()]\n\nbest = 1\n\nfor i in tab:\n if k % i == 0:\n best = max([i, best])\n\nprint(k // best)\n", "passed": true, "time": 0.15, "memory": 14400.0, "status": "done"}, {"code": "n, k = [int(v) for v in input().split()]\naa = [int(v) for v in input().split()]\n\nprint(min(k // a for a in aa if k % a == 0))\n", "passed": true, "time": 0.19, "memory": 14332.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\nans = 10**18\n\nfor a in map(int, input().split()):\n if k % a == 0:\n ans = min(ans, k // a)\n\nprint(ans)\n", "passed": true, "time": 0.18, "memory": 14484.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na = list(map(int, input().split()))\na.sort()\nfor i in range(n-1,-1,-1):\n\tif k % a[i] == 0:\n\t\tprint(k // a[i])\n\t\tbreak", "passed": true, "time": 0.16, "memory": 14568.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na = list(map(int, input().split()))\nb = []\nfor i in range(n):\n if k % a[i] == 0:\n b.append(a[i])\n\nprint(k // max(b))", "passed": true, "time": 0.15, "memory": 14464.0, "status": "done"}, {"code": "(n, k) = list(map(int, input().split()))\n\nlst = []\nfor x in input().split():\n lst.append(int(x))\n\ni = 0\nfor x in lst:\n if k % x == 0:\n i = max(i, x)\n\nprint(k // i)\n", "passed": true, "time": 0.15, "memory": 14372.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nans = 100\nfor i in a:\n if k%i == 0:\n ans = min(k//i, ans)\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = [int(i) for i in input().split()]\nminim = 10**18\nfor i in a:\n if k%i == 0:\n minim = min(minim, (k//i))\nprint(minim)\n", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\na = list(map(int,input().split()))\nans = 0\nfor item in a:\n if (k%item == 0):\n ans = max(ans,item)\nprint(k//ans)\n", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "n,k=list(map(int,input().split()))\nl=list(map(int,input().split()))\nm=1\nfor i in l:\n if k%i==0:\n m=max(m,i)\nprint(k//m)\n \n \n \n", "passed": true, "time": 0.14, "memory": 14524.0, "status": "done"}, {"code": "len_garden = int(input().split()[1])\nbuckets = [int(a) for a in input().split()]\n\nbuckets = sorted(buckets, reverse=True)\n\nfor i in buckets:\n if len_garden%i == 0:\n print(int(len_garden/i))\n break\n", "passed": true, "time": 0.14, "memory": 14488.0, "status": "done"}] | [{"input": "3 6\n2 3 5\n", "output": "2\n"}, {"input": "6 7\n1 2 3 4 5 6\n", "output": "7\n"}, {"input": "5 97\n1 10 50 97 2\n", "output": "1\n"}, {"input": "5 97\n1 10 50 100 2\n", "output": "97\n"}, {"input": "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\n", "output": "50\n"}, {"input": "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\n", "output": "7\n"}, {"input": "8 8\n8 7 6 5 4 3 2 1\n", "output": "1\n"}, {"input": "3 8\n4 3 2\n", "output": "2\n"}, {"input": "3 8\n2 4 2\n", "output": "2\n"}, {"input": "3 6\n1 3 2\n", "output": "2\n"}, {"input": "3 6\n3 2 5\n", "output": "2\n"}, {"input": "3 8\n4 2 1\n", "output": "2\n"}, {"input": "5 6\n2 3 5 1 2\n", "output": "2\n"}, {"input": "2 6\n5 3\n", "output": "2\n"}, {"input": "4 12\n6 4 3 1\n", "output": "2\n"}, {"input": "3 18\n1 9 6\n", "output": "2\n"}, {"input": "3 9\n3 2 1\n", "output": "3\n"}, {"input": "3 6\n5 3 2\n", "output": "2\n"}, {"input": "2 10\n5 2\n", "output": "2\n"}, {"input": "2 18\n6 3\n", "output": "3\n"}, {"input": "4 12\n1 2 12 3\n", "output": "1\n"}, {"input": "3 7\n3 2 1\n", "output": "7\n"}, {"input": "3 6\n3 2 1\n", "output": "2\n"}, {"input": "5 10\n5 4 3 2 1\n", "output": "2\n"}, {"input": "5 16\n8 4 2 1 7\n", "output": "2\n"}, {"input": "6 7\n6 5 4 3 7 1\n", "output": "1\n"}, {"input": "2 6\n3 2\n", "output": "2\n"}, {"input": "2 4\n4 1\n", "output": "1\n"}, {"input": "6 8\n2 4 1 3 5 7\n", "output": "2\n"}, {"input": "6 8\n6 5 4 3 2 1\n", "output": "2\n"}, {"input": "6 15\n5 2 3 6 4 3\n", "output": "3\n"}, {"input": "4 8\n2 4 8 1\n", "output": "1\n"}, {"input": "2 5\n5 1\n", "output": "1\n"}, {"input": "4 18\n3 1 1 2\n", "output": "6\n"}, {"input": "2 1\n2 1\n", "output": "1\n"}, {"input": "3 10\n2 10 5\n", "output": "1\n"}, {"input": "5 12\n12 4 4 4 3\n", "output": "1\n"}, {"input": "3 6\n6 3 2\n", "output": "1\n"}, {"input": "2 2\n2 1\n", "output": "1\n"}, {"input": "3 18\n1 9 3\n", "output": "2\n"}, {"input": "3 8\n7 2 4\n", "output": "2\n"}, {"input": "2 100\n99 1\n", "output": "100\n"}, {"input": "4 12\n1 3 4 2\n", "output": "3\n"}, {"input": "3 6\n2 3 1\n", "output": "2\n"}, {"input": "4 6\n3 2 5 12\n", "output": "2\n"}, {"input": "4 97\n97 1 50 10\n", "output": "1\n"}, {"input": "3 12\n1 12 2\n", "output": "1\n"}, {"input": "4 12\n1 4 3 2\n", "output": "3\n"}, {"input": "1 1\n1\n", "output": "1\n"}, {"input": "3 19\n7 1 1\n", "output": "19\n"}, {"input": "5 12\n12 4 3 4 4\n", "output": "1\n"}, {"input": "3 8\n8 4 2\n", "output": "1\n"}, {"input": "3 3\n3 2 1\n", "output": "1\n"}, {"input": "5 6\n3 2 4 2 2\n", "output": "2\n"}, {"input": "2 16\n8 4\n", "output": "2\n"}, {"input": "3 6\n10 2 3\n", "output": "2\n"}, {"input": "5 3\n2 4 5 3 6\n", "output": "1\n"}, {"input": "11 99\n1 2 3 6 5 4 7 8 99 33 66\n", "output": "1\n"}, {"input": "3 12\n3 12 2\n", "output": "1\n"}, {"input": "5 25\n24 5 15 25 23\n", "output": "1\n"}, {"input": "2 4\n8 1\n", "output": "4\n"}, {"input": "4 100\n2 50 4 1\n", "output": "2\n"}, {"input": "3 28\n7 14 1\n", "output": "2\n"}, {"input": "4 8\n2 8 4 1\n", "output": "1\n"}, {"input": "4 6\n6 1 2 3\n", "output": "1\n"}, {"input": "2 12\n4 3\n", "output": "3\n"}, {"input": "4 12\n1 2 4 3\n", "output": "3\n"}, {"input": "5 12\n2 3 12 6 4\n", "output": "1\n"}, {"input": "4 4\n1 2 2 4\n", "output": "1\n"}, {"input": "3 6\n2 3 2\n", "output": "2\n"}, {"input": "4 21\n21 20 21 2\n", "output": "1\n"}, {"input": "3 8\n3 4 2\n", "output": "2\n"}, {"input": "1 25\n25\n", "output": "1\n"}, {"input": "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\n", "output": "1\n"}, {"input": "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\n", "output": "1\n"}, {"input": "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\n", "output": "1\n"}, {"input": "4 32\n1 1 1 1\n", "output": "32\n"}, {"input": "1 100\n1\n", "output": "100\n"}, {"input": "2 100\n7 1\n", "output": "100\n"}, {"input": "7 24\n1 3 6 4 5 2 7\n", "output": "4\n"}, {"input": "6 87\n1 2 8 4 5 7\n", "output": "87\n"}, {"input": "1 88\n1\n", "output": "88\n"}, {"input": "1 89\n1\n", "output": "89\n"}] |
|
163 | On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
-----Input-----
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
-----Output-----
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
-----Examples-----
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
-----Note-----
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. | interview | [{"code": "n,k=[int(i) for i in input().split()]\ns=input()\nf=s.find('G')\nt=s.find('T')\nif f<t:\n f,t=t,f\nif (f-t)%k:\n print('NO')\nelse:\n for i in range(t+k,f,k):\n if s[i]=='#':\n print('NO')\n break\n else:\n print('YES')\n", "passed": true, "time": 1.85, "memory": 14500.0, "status": "done"}, {"code": "import sys\nn, k = list(map(int, input().split()))\ns = input()\na = s.index('G')\nb = s.index('T')\nwhile a < b:\n b = b - k\n pos = b\n if pos >= 0 and (s[pos] == '.' or s[pos] == 'T'):\n pass\n else:\n break\nwhile a > b:\n b = b + k\n pos = b\n if pos < n and (s[pos] == '.' or s[pos] == 'T'):\n pass\n else:\n break\nif a != b:\n print('NO')\nelse:\n print('YES')\n \n", "passed": true, "time": 0.24, "memory": 14572.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nstring = input()\ngood = False\nanswer = True\ncounter = 0\nwhile True:\n if counter >= n:\n answer = False\n break\n if not good and string[counter] in \"GT\":\n good = True\n counter += k\n elif not good:\n counter += 1\n else:\n if string[counter] == \"#\":\n answer = False\n if string[counter] in \"GT\":\n break\n counter += k\nif answer:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14528.0, "status": "done"}, {"code": "n, k = map(int, input().split())\ns = input()\nid1 = s.find('G')\nid2 = s.find('T')\nif abs(id1 - id2) % k:\n print(\"NO\")\n return\ncoef = 1\nif id2 < id1:\n coef = -1\nwhile id1 != id2 and s[id1] in ('G', '.', 'T'):\n id1 += coef * k\nif id1 == id2:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 1.89, "memory": 14596.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\na = list(input())\ni = a.index(\"G\")\nj = a.index(\"T\")\nif i > j:\n\ti,j = j,i\nwhile True:\n\tif i == j:\n\t\tprint(\"YES\")\n\t\tbreak\n\telif i >= j or a[i] == \"#\":\n\t\tprint(\"NO\")\n\t\tbreak\n\telse:\n\t\ti += k\n\n", "passed": true, "time": 1.83, "memory": 14484.0, "status": "done"}, {"code": "def main():\n n, k = list(map(int, input().split()))\n a = input()\n l = 0\n r = 0\n for i in range(n):\n if (a[i] == 'G'):\n l = i\n elif (a[i] == 'T'):\n r = i\n if (l < r):\n if ((r - l) % k == 0):\n for i in range(l, r + 1, k):\n if (a[i] == '#'):\n print(\"NO\")\n return\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n if ((r - l) % k == 0):\n for i in range(r, l + 1, k):\n if (a[i] == '#'):\n print(\"NO\")\n return\n print(\"YES\")\n else:\n print(\"NO\")\nmain()", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\na = input()\ng = 0\nt = 0\n\nfor j in range(n):\n if a[j] == 'G':\n g = j\n if a[j] == 'T':\n t = j\nif g < t:\n g, t = t, g\nif (g - t) % k == 0:\n per = 0\n for j in range(t, g+1, k):\n if a[j] == '#':\n per = 1\n break\n if per == 1:\n print('NO')\n else:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.15, "memory": 14548.0, "status": "done"}, {"code": "n,k=[int(item) for item in input().split()]\ns=list(input())\n\ng = s.index(\"G\")\nt = s.index(\"T\")\nv = 0\nif g < t: v = k\nelse : v = -k\ni = g\nwhile i >= 0 and i < n:\n if i == t:\n print(\"YES\")\n break\n elif s[i] == \"#\":\n print(\"NO\")\n break\n i += v\nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14484.0, "status": "done"}, {"code": "n, k = [int(x) for x in input().split()]\nd = [False] * n\nt = input()\ntmp = t.index('G')\ni = tmp + k\ncan = True\nans = False\nwhile i < n and can:\n if (t[i] == '#'):\n can = False\n else:\n d[i] = True\n i += k\ni = tmp - k\ncan = True\nwhile i > - 1 and can:\n if (t[i] == '#'):\n can = False\n else:\n d[i] = True\n i -= k\ntd = t.index('T')\nif (d[td] == True):\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14640.0, "status": "done"}, {"code": "n, k = map(int, input().split())\ns = input()\nans = True\nif s.find(\"G\") > s.find(\"T\"):\n\ts = s[::-1]\ns = s[s.find(\"G\")::k]\nif s.find(\"T\") != -1:\n\ts = s[:s.find(\"T\") + 1]\n\tif \"#\" in s:\n\t\tans = False\nelse:\n\tans = False\nif ans:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")", "passed": true, "time": 0.14, "memory": 14520.0, "status": "done"}, {"code": "from sys import stdin\n\nn, k = list(map(int, stdin.readline().split()))\n\ns = stdin.readline().strip()\n\nindex = s.find('G')\nindex2 = s.find('T')\n\nif index > index2:\n s = ''.join(reversed(s))\n\n\nindex = s.find('G') + k\n\nwhile index < n:\n if s[index] == 'T':\n print('YES')\n break\n if s[index] == '#':\n print('NO')\n break\n index += k\nelse:\n print('NO')\n", "passed": true, "time": 0.22, "memory": 14636.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nst = list(input())\ng = st.index(\"G\")\nt = st.index(\"T\")\n\nif abs(g - t) % k != 0:\n print(\"NO\")\nelse:\n start = min(g, t)\n end = max(g, t)\n while start != end:\n start += k\n if st[start] == '#':\n print(\"NO\")\n return\n print(\"YES\")\n", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "n, k = map(int, input().split())\ns = input()\ni = s.find(\"G\")\nans = False\nwhile i < n:\n if s[i] == \"#\":\n break\n if s[i] == \"T\":\n ans = True\n break\n i += k\ni = s.find(\"G\")\nwhile i > -1:\n if s[i] == \"#\":\n break\n if s[i] == \"T\":\n ans = True\n break\n i -= k\nif ans:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "\n\nn,k=list(map(int,input().split()))\nligne=input()\n\nfor i in range(n):\n car=ligne[i]\n if car==\"G\":\n depart=i\n elif car==\"T\":\n arrive=i\ni=depart\nwhile n>i and (ligne[i]==\".\" or ligne[i]==\"G\"):\n i+=k\nj=depart\n\nwhile j>0 and (ligne[j]==\".\" or ligne[j]==\"G\"):\n j-=k\n \nif j==arrive or i==arrive:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14400.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\ns = input()\ng = s.index(\"G\")\nt = s.index(\"T\")\nif (g>t):\n g,t = t,g\nif (t-g)%k:\n print(\"NO\")\nelif \"#\" in s[g+k:t:k]: \n print(\"NO\")\nelse:\n print(\"YES\")\n", "passed": true, "time": 0.15, "memory": 14404.0, "status": "done"}, {"code": "n, k = [int(x) for x in input().split()]\ns = input()\n\nstart, target = 0, 0\nfor i, c in enumerate(s):\n if c == 'G':\n start = i\n if c == 'T':\n target = i\n\nvisited = set()\n\ndef dfs(i):\n if i in visited:\n return False\n if i == target:\n return True\n if not (0 <= i < len(s)) or s[i] == '#':\n return False\n visited.add(i)\n return dfs(i-k) or dfs(i+k)\n\nprint('YES' if dfs(start) else 'NO')\n", "passed": true, "time": 0.14, "memory": 14412.0, "status": "done"}, {"code": "def main():\n n, k = list(map(int, input().split()))\n s = input()\n g, t = s.find('G'), s.find('T')\n if g < t:\n s = s[g:t + 1:k]\n else:\n s = s[t:g + 1:k][::-1]\n print((\"NO\", \"YES\")[s[0] == 'G' and s[-1] == 'T' and '#' not in s])\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na = input()\npos = -1\nfor i in range(n):\n if a[i] == \"G\":\n pos = i\n break\nfor i in range(pos, len(a), k):\n if a[i] == \"T\":\n print(\"YES\")\n return\n if a[i] == \"#\":\n break\nfor i in range(pos, -1, -k):\n if a[i] == \"T\":\n print(\"YES\")\n return\n if a[i] == \"#\":\n break\nprint(\"NO\")", "passed": true, "time": 0.15, "memory": 14404.0, "status": "done"}, {"code": "import math\n\ndef solve(n, k, s):\n i, j = s.index('G'), s.index('T')\n if (i - j) % k != 0:\n return False\n for k in range(i, j, (k if i < j else -k)):\n if k >= n or k < 0 or s[k] == '#':\n return False\n return True\n\nn, k = [int(x) for x in input().split()]\ns = input()\nprint('YES' if solve(n, k, s) else 'NO')\n \n", "passed": true, "time": 0.14, "memory": 14552.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\ns = input()\na = s.index('G')\nb = s.index('T')\nd = [0] * 1000\nd[a] = 1\nfor j in range(200):\n for i in range(n):\n if i - k >= 0 and d[i - k] == 1 and s[i] != '#':\n d[i] = 1\n if d[i + k] == 1 and s[i] != '#':\n d[i] = 1\nif d[b]:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.26, "memory": 14504.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\nline = input()\n\nfor x in range(n):\n if line[x] == \"G\":\n g = x \n elif line[x] == \"T\":\n t = x\n\nif (g - t) % k == 0:\n if g > t:\n while g > t:\n if g - k == t:\n print(\"YES\")\n return\n elif line[g - k] == \"#\":\n print(\"NO\")\n return\n else:\n g = g - k\n else:\n while g < t:\n if g + k == t:\n print(\"YES\")\n return\n elif line[g + k] == \"#\":\n print(\"NO\")\n return\n else:\n g = g + k\nelse:\n print(\"NO\")\n return\n", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}, {"code": "n,k=list(map(int,input().split()))\ns=input()\ng,t=0,0\nfor i in range(len(s)):\n if s[i]=='G':\n g=i\n if s[i]=='T':\n t=i\nif (t-g)%k==0:\n if t>g:\n i=g\n B=True\n while i<t:\n if s[i]==\"#\":\n B=False\n break\n i+=k\n else:\n i=t\n B=True\n while i<g:\n if s[i]==\"#\":\n B=False\n break\n i+=k\n if B:\n print(\"YES\")\n else:\n print(\"NO\")\n\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14400.0, "status": "done"}] | [{"input": "5 2\n#G#T#\n", "output": "YES\n"}, {"input": "6 1\nT....G\n", "output": "YES\n"}, {"input": "7 3\nT..#..G\n", "output": "NO\n"}, {"input": "6 2\n..GT..\n", "output": "NO\n"}, {"input": "2 1\nGT\n", "output": "YES\n"}, {"input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####T####\n", "output": "YES\n"}, {"input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.#########.####.####.####.####T####\n", "output": "NO\n"}, {"input": "2 1\nTG\n", "output": "YES\n"}, {"input": "99 1\n...T.............................................................................................G.\n", "output": "YES\n"}, {"input": "100 2\nG............#.....#...........#....#...........##............#............#......................T.\n", "output": "NO\n"}, {"input": "100 20\n.....G.#.#..................#.........##....#...................#.#..........#...#.#.T..#.......#...\n", "output": "YES\n"}, {"input": "100 20\n.....G................................................................................T.............\n", "output": "NO\n"}, {"input": "100 1\n#.#.#.##..#..##.#....##.##.##.#....####..##.#.##..GT..##...###.#.##.#..#..##.###..#.####..#.#.##..##\n", "output": "YES\n"}, {"input": "100 2\n..#####.#.#.......#.#.#...##..####..###..#.#######GT####.#.#...##...##.#..###....##.#.#..#.###....#.\n", "output": "NO\n"}, {"input": "100 3\nG..................................................................................................T\n", "output": "YES\n"}, {"input": "100 3\nG..................................................................................................T\n", "output": "YES\n"}, {"input": "100 3\nG..................................#......#......#.......#.#..........#........#......#..........#.T\n", "output": "NO\n"}, {"input": "100 3\nG..............#..........#...#..............#.#.....................#......#........#.........#...T\n", "output": "NO\n"}, {"input": "100 3\nG##################################################################################################T\n", "output": "NO\n"}, {"input": "100 33\nG..................................................................................................T\n", "output": "YES\n"}, {"input": "100 33\nG..................................................................................................T\n", "output": "YES\n"}, {"input": "100 33\nG.........#........#..........#..............#.................#............................#.#....T\n", "output": "YES\n"}, {"input": "100 33\nG.......#..................#..............................#............................#..........T.\n", "output": "NO\n"}, {"input": "100 33\nG#..........##...#.#.....................#.#.#.........##..#...........#....#...........##...#..###T\n", "output": "YES\n"}, {"input": "100 33\nG..#.#..#..####......#......##...##...#.##........#...#...#.##....###..#...###..##.#.....#......#.T.\n", "output": "NO\n"}, {"input": "100 33\nG#....#..#..##.##..#.##.#......#.#.##..##.#.#.##.##....#.#.....####..##...#....##..##..........#...T\n", "output": "NO\n"}, {"input": "100 33\nG#######.#..##.##.#...#..#.###.#.##.##.#..#.###..####.##.#.##....####...##..####.#..##.##.##.#....#T\n", "output": "NO\n"}, {"input": "100 33\nG#####.#.##.###########.##..##..#######..########..###.###..#.####.######.############..####..#####T\n", "output": "NO\n"}, {"input": "100 99\nT..................................................................................................G\n", "output": "YES\n"}, {"input": "100 99\nT..................................................................................................G\n", "output": "YES\n"}, {"input": "100 99\nT.#...............................#............#..............................##...................G\n", "output": "YES\n"}, {"input": "100 99\nT..#....#.##...##########.#.#.#.#...####..#.....#..##..#######.######..#.....###..###...#.......#.#G\n", "output": "YES\n"}, {"input": "100 99\nG##################################################################################################T\n", "output": "YES\n"}, {"input": "100 9\nT..................................................................................................G\n", "output": "YES\n"}, {"input": "100 9\nT.................................................................................................G.\n", "output": "NO\n"}, {"input": "100 9\nT................................................................................................G..\n", "output": "NO\n"}, {"input": "100 9\nT...........................................................................................G.......\n", "output": "NO\n"}, {"input": "100 9\nG..........................................................................................T........\n", "output": "NO\n"}, {"input": "100 1\nG..................................................................................................T\n", "output": "YES\n"}, {"input": "100 1\nT..................................................................................................G\n", "output": "YES\n"}, {"input": "100 1\n##########G.........T###############################################################################\n", "output": "YES\n"}, {"input": "100 1\n#################################################################################################G.T\n", "output": "YES\n"}, {"input": "100 17\n##########G################.################.################.################T#####################\n", "output": "YES\n"}, {"input": "100 17\n####.#..#.G######.#########.##..##########.#.################.################T######.####.#########\n", "output": "YES\n"}, {"input": "100 17\n.########.G##.####.#.######.###############..#.###########.##.#####.##.#####.#T.###..###.########.##\n", "output": "YES\n"}, {"input": "100 1\nG.............................................#....................................................T\n", "output": "NO\n"}, {"input": "100 1\nT.#................................................................................................G\n", "output": "NO\n"}, {"input": "100 1\n##########G....#....T###############################################################################\n", "output": "NO\n"}, {"input": "100 1\n#################################################################################################G#T\n", "output": "NO\n"}, {"input": "100 17\nG################.#################################.################T###############################\n", "output": "NO\n"}, {"input": "100 17\nG################.###############..###.######.#######.###.#######.##T######################.###.####\n", "output": "NO\n"}, {"input": "100 17\nG####.##.##.#####.####....##.####.#########.##.#..#.###############.T############.#########.#.####.#\n", "output": "NO\n"}, {"input": "48 1\nT..............................................G\n", "output": "YES\n"}, {"input": "23 1\nT.....................G\n", "output": "YES\n"}, {"input": "49 1\nG...............................................T\n", "output": "YES\n"}, {"input": "3 1\nTG#\n", "output": "YES\n"}, {"input": "6 2\n..TG..\n", "output": "NO\n"}, {"input": "14 3\n...G.....#..T.\n", "output": "NO\n"}, {"input": "5 4\n##GT#\n", "output": "NO\n"}, {"input": "6 2\nT#..G.\n", "output": "YES\n"}, {"input": "12 3\nT.#.#.G.....\n", "output": "YES\n"}, {"input": "9 1\n...TG#...\n", "output": "YES\n"}, {"input": "5 2\nT.G.#\n", "output": "YES\n"}, {"input": "6 1\nT...G#\n", "output": "YES\n"}, {"input": "5 1\nTG###\n", "output": "YES\n"}, {"input": "5 4\n.G..T\n", "output": "NO\n"}, {"input": "7 2\nT#...#G\n", "output": "YES\n"}, {"input": "7 1\n##TG###\n", "output": "YES\n"}, {"input": "7 1\n###GT##\n", "output": "YES\n"}, {"input": "5 2\nG..T.\n", "output": "NO\n"}, {"input": "5 1\nG.T##\n", "output": "YES\n"}, {"input": "6 2\nG.T###\n", "output": "YES\n"}, {"input": "6 2\nG#T###\n", "output": "YES\n"}, {"input": "10 2\n####T..G..\n", "output": "NO\n"}, {"input": "3 1\nGT#\n", "output": "YES\n"}, {"input": "4 1\nTG##\n", "output": "YES\n"}, {"input": "6 1\n.G..T.\n", "output": "YES\n"}, {"input": "10 3\n......G..T\n", "output": "YES\n"}, {"input": "3 2\nG.T\n", "output": "YES\n"}, {"input": "4 1\n#G.T\n", "output": "YES\n"}, {"input": "5 2\nT#G##\n", "output": "YES\n"}, {"input": "4 2\nG#.T\n", "output": "NO\n"}, {"input": "4 1\nGT##\n", "output": "YES\n"}] |
|
164 | It's a beautiful April day and Wallace is playing football with his friends. But his friends do not know that Wallace actually stayed home with Gromit and sent them his robotic self instead. Robo-Wallace has several advantages over the other guys. For example, he can hit the ball directly to the specified point. And yet, the notion of a giveaway is foreign to him. The combination of these features makes the Robo-Wallace the perfect footballer — as soon as the ball gets to him, he can just aim and hit the goal. He followed this tactics in the first half of the match, but he hit the goal rarely. The opposing team has a very good goalkeeper who catches most of the balls that fly directly into the goal. But Robo-Wallace is a quick thinker, he realized that he can cheat the goalkeeper. After all, they are playing in a football box with solid walls. Robo-Wallace can kick the ball to the other side, then the goalkeeper will not try to catch the ball. Then, if the ball bounces off the wall and flies into the goal, the goal will at last be scored.
Your task is to help Robo-Wallace to detect a spot on the wall of the football box, to which the robot should kick the ball, so that the ball bounces once and only once off this wall and goes straight to the goal. In the first half of the match Robo-Wallace got a ball in the head and was severely hit. As a result, some of the schemes have been damaged. Because of the damage, Robo-Wallace can only aim to his right wall (Robo-Wallace is standing with his face to the opposing team's goal).
The football box is rectangular. Let's introduce a two-dimensional coordinate system so that point (0, 0) lies in the lower left corner of the field, if you look at the box above. Robo-Wallace is playing for the team, whose goal is to the right. It is an improvised football field, so the gate of Robo-Wallace's rivals may be not in the middle of the left wall. [Image]
In the given coordinate system you are given: y_1, y_2 — the y-coordinates of the side pillars of the goalposts of robo-Wallace's opponents; y_{w} — the y-coordinate of the wall to which Robo-Wallace is aiming; x_{b}, y_{b} — the coordinates of the ball's position when it is hit; r — the radius of the ball.
A goal is scored when the center of the ball crosses the OY axis in the given coordinate system between (0, y_1) and (0, y_2). The ball moves along a straight line. The ball's hit on the wall is perfectly elastic (the ball does not shrink from the hit), the angle of incidence equals the angle of reflection. If the ball bounces off the wall not to the goal, that is, if it hits the other wall or the goal post, then the opposing team catches the ball and Robo-Wallace starts looking for miscalculation and gets dysfunctional. Such an outcome, if possible, should be avoided. We assume that the ball touches an object, if the distance from the center of the ball to the object is no greater than the ball radius r.
-----Input-----
The first and the single line contains integers y_1, y_2, y_{w}, x_{b}, y_{b}, r (1 ≤ y_1, y_2, y_{w}, x_{b}, y_{b} ≤ 10^6; y_1 < y_2 < y_{w}; y_{b} + r < y_{w}; 2·r < y_2 - y_1).
It is guaranteed that the ball is positioned correctly in the field, doesn't cross any wall, doesn't touch the wall that Robo-Wallace is aiming at. The goal posts can't be located in the field corners.
-----Output-----
If Robo-Wallace can't score a goal in the described manner, print "-1" (without the quotes). Otherwise, print a single number x_{w} — the abscissa of his point of aiming.
If there are multiple points of aiming, print the abscissa of any of them. When checking the correctness of the answer, all comparisons are made with the permissible absolute error, equal to 10^{ - 8}.
It is recommended to print as many characters after the decimal point as possible.
-----Examples-----
Input
4 10 13 10 3 1
Output
4.3750000000
Input
1 4 6 2 2 1
Output
-1
Input
3 10 15 17 9 2
Output
11.3333333333
-----Note-----
Note that in the first and third samples other correct values of abscissa x_{w} are also possible. | interview | [{"code": "y1, y2, w, x, y, r = map(int, input().strip().split())\nw -= r\ny1 = 2 * w - y1 - y - r\ny2 = 2 * w - y2 - y\nif x * x * (y2 - y1) * (y2 - y1) <= (y1 * y1 + x * x) * r * r:\n print(-1)\nelse:\n print(f\"{x * (y1 + y - w) / y1:.10f}\")", "passed": true, "time": 0.14, "memory": 14408.0, "status": "done"}, {"code": "from math import atan, asin\ny1, y2, yw, xb, yb, r = map(float, input().split())\nx = xb * (yw - y1 - 2*r) / (2*yw - y1 - yb - 3*r)\nalpha = atan(x / (yw - y1 - 2*r))\nbeta = asin(r / (y2 - y1 - r))\nprint ('-1' if alpha < beta else '{0:.10f}'.format(x))", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}] | [{"input": "4 10 13 10 3 1\n", "output": "4.3750000000\n"}, {"input": "1 4 6 2 2 1\n", "output": "-1\n"}, {"input": "3 10 15 17 9 2\n", "output": "11.3333333333\n"}, {"input": "4 9 30 3 3 1\n", "output": "-1\n"}, {"input": "4 9 13 2 3 1\n", "output": "-1\n"}, {"input": "4 9 13 1 1 1\n", "output": "-1\n"}, {"input": "1 9 10 6 6 3\n", "output": "4.5000000000\n"}, {"input": "4 9 24 10 3 1\n", "output": "4.7368421053\n"}, {"input": "4 9 20 10 3 1\n", "output": "4.6666666667\n"}, {"input": "1 8 10 8 3 3\n", "output": "3.4285714286\n"}, {"input": "2 9 10 4 6 3\n", "output": "2.6666666667\n"}, {"input": "2 9 10 6 3 3\n", "output": "-1\n"}, {"input": "1 9 10 7 3 3\n", "output": "3.0000000000\n"}, {"input": "1 9 10 9 5 3\n", "output": "5.4000000000\n"}, {"input": "2 9 10 6 5 3\n", "output": "3.0000000000\n"}, {"input": "1 9 10 5 5 3\n", "output": "3.0000000000\n"}, {"input": "2 9 10 9 3 3\n", "output": "3.0000000000\n"}, {"input": "1 9 10 9 5 3\n", "output": "5.4000000000\n"}, {"input": "1 8 10 3 3 3\n", "output": "-1\n"}, {"input": "1 9 10 5 5 3\n", "output": "3.0000000000\n"}, {"input": "2 9 10 5 3 3\n", "output": "-1\n"}, {"input": "2 9 10 8 5 3\n", "output": "4.0000000000\n"}, {"input": "2 9 10 9 5 3\n", "output": "4.5000000000\n"}, {"input": "1 9 10 4 5 3\n", "output": "2.4000000000\n"}, {"input": "1 8 10 5 5 3\n", "output": "-1\n"}, {"input": "2 9 10 9 5 3\n", "output": "4.5000000000\n"}, {"input": "15 30 100 8 8 5\n", "output": "-1\n"}, {"input": "15 30 100 58 81 5\n", "output": "48.8764044944\n"}, {"input": "15 30 100 601 76 5\n", "output": "479.5212765957\n"}, {"input": "15 30 100 7193 39 5\n", "output": "4118.1297709924\n"}, {"input": "15 30 100 40766 18 5\n", "output": "20114.8026315789\n"}, {"input": "15 30 100 243890 31 5\n", "output": "131595.3237410072\n"}, {"input": "4 9 30 10 3 1\n", "output": "-1\n"}, {"input": "56 90 100 9 56 9\n", "output": "-1\n"}, {"input": "29 62 100 88 37 9\n", "output": "43.5887850467\n"}, {"input": "712 950 1000 98 727 92\n", "output": "-1\n"}, {"input": "7788 8844 10000 70 4902 63\n", "output": "-1\n"}, {"input": "49 67 100 986 29 7\n", "output": "361.2079207921\n"}, {"input": "190 212 1000 103 795 3\n", "output": "-1\n"}, {"input": "5234 7681 10000 985 8825 847\n", "output": "-1\n"}, {"input": "94603 96309 100000 728 25633 556\n", "output": "-1\n"}, {"input": "30 73 100 5089 24 9\n", "output": "2223.7647058824\n"}, {"input": "330 357 1000 625 129 8\n", "output": "-1\n"}, {"input": "5010 6384 10000 9022 3213 187\n", "output": "3713.0485021398\n"}, {"input": "7 17 100 56205 62 2\n", "output": "40017.9600000000\n"}, {"input": "626 705 1000 10072 858 35\n", "output": "7449.8491484185\n"}, {"input": "1727 5232 10000 67443 5399 62\n", "output": "43315.9683953342\n"}, {"input": "10995 85967 100000 47813 44507 2442\n", "output": "29321.4167104074\n"}, {"input": "845391 929573 1000000 87612 108825 1400\n", "output": "12769.2918746832\n"}, {"input": "78 90 100 535782 61 4\n", "output": "153080.5714285714\n"}, {"input": "2846 8620 10000 466361 3155 1292\n", "output": "210537.3673812111\n"}, {"input": "138623 763216 1000000 366229 316563 160243\n", "output": "-1\n"}, {"input": "111724 287004 931554 512877 139642 23002\n", "output": "257255.6532044368\n"}, {"input": "70276 182564 238201 222757 154128 55592\n", "output": "-1\n"}, {"input": "65775 300705 686095 383961 189161 72083\n", "output": "-1\n"}, {"input": "303226 381701 395142 301908 2696 244\n", "output": "57074.3018919422\n"}, {"input": "451924 493579 637450 231345 530245 20087\n", "output": "-1\n"}, {"input": "67933 96355 131374 588846 12918 4897\n", "output": "188927.5585923950\n"}, {"input": "149195 164613 287623 72041 223411 5390\n", "output": "-1\n"}, {"input": "448887 492030 560100 388288 354938 20867\n", "output": "-1\n"}, {"input": "435582 479389 540004 905521 413521 1624\n", "output": "405317.7264116302\n"}, {"input": "64887 100252 122962 146510 74262 15718\n", "output": "65461.4966203183\n"}, {"input": "246310 320553 585881 278070 443362 23788\n", "output": "197686.6564327557\n"}, {"input": "154137 199509 247827 186170 112705 19967\n", "output": "-1\n"}, {"input": "652284 765064 966501 110259 224662 46292\n", "output": "-1\n"}, {"input": "1437 1945 9737 17190 7829 114\n", "output": "14064.2286640989\n"}, {"input": "61880 74283 78517 551852 20330 1475\n", "output": "107291.2729442180\n"}, {"input": "196112 214848 221935 465535 132387 3661\n", "output": "82508.1717726175\n"}, {"input": "20296 469893 481654 239118 236770 20582\n", "output": "155898.4832985775\n"}, {"input": "476636 647171 684372 48498 122589 5636\n", "output": "12660.0741578319\n"}, {"input": "140 149 150 13 78 3\n", "output": "-1\n"}, {"input": "140 149 150 16 36 3\n", "output": "-1\n"}, {"input": "140 149 150 13 134 3\n", "output": "3.0588235294\n"}, {"input": "140 149 150 11 76 3\n", "output": "-1\n"}, {"input": "1400 1490 1500 78 292 40\n", "output": "-1\n"}, {"input": "1400 1490 1500 89 829 40\n", "output": "-1\n"}, {"input": "1400 1490 1500 75 585 40\n", "output": "-1\n"}, {"input": "1400 1490 1500 67 240 40\n", "output": "-1\n"}, {"input": "1400 1490 1500 64 276 40\n", "output": "-1\n"}, {"input": "1400 1490 1500 43 926 40\n", "output": "-1\n"}, {"input": "1400 1490 1500 83 1362 40\n", "output": "-1\n"}, {"input": "140 149 150 18 80 3\n", "output": "-1\n"}, {"input": "4 9 25 10 3 1\n", "output": "-1\n"}] |
|
165 | Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
-----Input-----
The only line contains three integers b, d and s (0 ≤ b, d, s ≤ 10^18, b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
-----Output-----
Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation.
-----Examples-----
Input
3 2 1
Output
1
Input
1 0 0
Output
0
Input
1 1 1
Output
0
Input
1000000000000000000 0 1000000000000000000
Output
999999999999999999
-----Note-----
In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.
In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal. | interview | [{"code": "a = list(map(int, input().split()))\nm = max(a)\n\nans = 0\nfor i in range(3):\n if a[i] < m - 1:\n ans += (m - 1) - a[i]\n a[i] = m - 1\n\nprint(ans)\n", "passed": true, "time": 0.24, "memory": 14356.0, "status": "done"}, {"code": "def c(ans, b ,d, s):\n\treturn(min(ans, 3 * max(b, d, s) - b - d - s))\nb, d, s = list(map(int, input().split()))\nans = 10**19\nm = min(b, d, s)\nb = b - m\nd = d - m\ns = s - m\nif b > 0:\n\tb -= 1\n\tans = c(ans, b, d, s)\n\tb += 1\nif d > 0:\n\td -= 1\n\tans = c(ans, b, d, s)\n\td += 1\nif s > 0:\n\ts -= 1\n\tans = c(ans, b, d, s)\n\ts += 1\nif b * d > 0:\n\tb -= 1\n\td -= 1\n\tans = c(ans, b, d, s)\n\tb += 1\n\td += 1\nif b * s > 0:\n\tb -= 1\n\ts -= 1\n\tans = c(ans, b, d, s)\n\tb += 1\n\ts += 1\nif s * d > 0:\n\ts -= 1\n\td -= 1\n\tans = c(ans, b, d, s)\n\ts += 1\n\td += 1\nif b + d + s == 0:\n\tans = 0\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "b, d, s = list(map(int, input().split()))\nhar = [max(s - 1, d - 1, b), max(d, b - 1, s - 1), max(d - 1, s, b - 1)]\nprint(har[0] - b + har[1] - d + har[2] - s)\n\n", "passed": true, "time": 0.16, "memory": 14488.0, "status": "done"}, {"code": "b,d,s = list(map(int, input().split()))\n\nr = 0\nif b == s and d == s:\n print(0)\nelif b >= s and b >= d:\n print(max(0,abs(b-d)-1)+max(abs(b-s)-1,0))\nelif s >= b and s >= d:\n print(max(0,abs(s-b)-1)+max(abs(s-d)-1,0))\nelif d >= s and d >= b:\n print(max(0,abs(d-s)-1)+max(abs(d-b)-1,0))\n \n", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "x = input().split()\na = int(x[0])\nb = int(x[1])\nc = int(x[2])\n\nmexx = max(max(a,b), c)\nmexx -= 1\nans = 0\nans += max(0, mexx-a)\nans += max(0, mexx-b);\nans += max(0, mexx-c);\nprint(ans)", "passed": true, "time": 0.15, "memory": 14508.0, "status": "done"}, {"code": "B,L,S = ( int(x) for x in input().split() )\nK = max(B,L,S)\ncost = 0\nfor meal in [B,L,S]:\n\tif meal != K:\n\t\tcost += K-1 - meal\n\nprint(cost) ", "passed": true, "time": 0.14, "memory": 14356.0, "status": "done"}, {"code": "def get(x, y, z):\n return max(x, y, z) * 3 - x - y - z\n\n\na, b, c = list(map(int, input().split()))\nans = min(get(a, b, c),\n get(a - 1, b, c),\n get(a - 1, b - 1, c),\n get(a, b - 1, c),\n get(a, b - 1, c - 1),\n get(a, b, c - 1),\n get(a - 1, b, c - 1),\n )\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "a = list(map(int, input().split()))\na.sort()\na[2] -= 1\nans = (a[2] - a[1] > 0) * (a[2] - a[1]) + (a[2] - a[0] > 0) * (a[2] - a[0])\nprint(ans)", "passed": true, "time": 0.15, "memory": 14540.0, "status": "done"}, {"code": "mas = list(map(int, input().split()))\nmas.sort()\nans = 0\nif mas[2] != mas[1]:\n ans += mas[2] - mas[1] - 1\n mas[1] = mas[2] - 1\nif mas[0] != mas[1]:\n if mas[1] == mas[2]:\n ans += mas[1] - mas[0] - 1\n else:\n ans += mas[1] - mas[0]\n mas[0] = mas[1]\nprint(ans)", "passed": true, "time": 0.15, "memory": 14616.0, "status": "done"}, {"code": "b, d, s = map(int, input().split())\n# b, d, s = 3, 2, 1\n\ndef mins(a, b, c):\n\tif min([a, b, c]) == a:\n\t\treturn a, min(b, c)\n\tif min([a, b, c]) == b:\n\t\treturn b, min(a, c)\n\tif min([a, b, c]) == c:\n\t\treturn c, min(a, b)\n\nma = max([b, d, s])\nmi1, mi2 = mins(b, d, s)\n\na1 = max(0, ma - 1 - mi1)\na2 = max(0, ma - 1 - mi2)\nprint(a1 + a2)", "passed": true, "time": 0.14, "memory": 14500.0, "status": "done"}, {"code": "def fun(b,d,s):\n if b == d == s:\n return 0\n \n if b > d and b > s:\n return (b-1-d)+(b-1-s)\n if d > b and d > s:\n return (d-1-b)+(d-1-s)\n if s > b and s > d:\n return (s-1-b)+(s-1-d)\n if b == d and b > s:\n return (b-1-s)\n if b == s and b > d:\n return (b-1-d)\n if d == s and d > b:\n return (d-1-b)\n return 0\n \nb,d,s = map(int, input().split())\nans = fun(b,d,s)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "b, d, s = map(int, input().split())\nif b >= d and b >= s:\n ans = max(0, b - d - 1) + max(0, b - s - 1)\nelif d >= s and d >= b:\n ans = max(0, d - s - 1) + max(0, d - b - 1)\nelse:\n ans = max(0, s - d - 1) + max(0, s - b - 1)\nprint(ans)", "passed": true, "time": 0.16, "memory": 14452.0, "status": "done"}, {"code": "a, b, c = map(int, input().split())\nans = 0\nx, y, z = max(a, b, c), (a + b + c) - (max(a, b, c) + min(a, b, c)), min(a, b, c)\nif x > y:\n ans += x - y - 1\nif x > z:\n ans += x - z - 1\nprint(ans)", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "3.5\nmas=[int(x) for x in input().split()]\nmas.sort()\n\np=0\nk=mas[2]-1\n\nif mas[1]<k:\n p+=k-mas[1]\nif mas[0]<k:\n p+=k-mas[0]\n \nprint(p)", "passed": true, "time": 0.24, "memory": 14668.0, "status": "done"}, {"code": "l = list(map(int, input().split()))\n\nl = sorted(l, reverse=True)\n\nmin_result = 10000000000000000000000000000\n\ndelts = [(1,0,0), (1,1,0), (0,0,1), (0,1,1), (0,0,0)]\n\nfor delt in delts:\n a = []\n for i in range(3):\n a.append(l[i] + delt[i])\n a = sorted(a, reverse=True)\n min_result = min(min_result, a[0] - a[1] + a[0] - a[2])\n\nprint(min_result)\n", "passed": true, "time": 0.22, "memory": 14604.0, "status": "done"}, {"code": "def __starting_point():\n arr = [int(ch) for ch in input().split(' ')]\n\n a = arr[0]\n b = arr[1]\n c = arr[2]\n\n if a == b and a == c:\n print('0')\n return\n\n maximum = max(a, b, c)\n res = True\n for i in arr:\n if i != maximum or i != (maximum - 1):\n res = False\n if res:\n print('0')\n return\n\n adding = 0\n for i in arr:\n if i == maximum:\n continue\n else:\n adding += maximum - i - 1\n\n print(adding)\n__starting_point()", "passed": true, "time": 0.24, "memory": 14584.0, "status": "done"}, {"code": "b, d, s = list(map(int,input().split()))\n\nif b > d and b > s:\n print((b-1)-d+(b-1)-s)\nelif d > b and d > s:\n print((d-1)-b+(d-1)-s)\nelif s > b and s > d:\n print((s-1)-b+(s-1)-d)\nelif b == d and b > s:\n print(max(0, (b-1)-s))\nelif d == s and d > b:\n print(max(0, (d-1)-b))\nelif b == s and b > d:\n print(max(0, (b-1)-d))\nelse:\n print(0)\n", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}, {"code": "def do():\n b,d,s = list(map(int,input().split()))\n if (b == d == s):\n return 0\n elif (b == d and b > s):\n return b - s - 1\n elif (b == d and b < s):\n return 2*(s - b - 1)\n elif (b == s and b > d):\n return b - d - 1\n elif (b == s and b < d):\n return 2*(d - b - 1)\n elif (d == s and d > b):\n return d - b - 1\n elif (d == s and d < b):\n return 2*(b - d - 1)\n else: # b d s are all different\n if (b > d and b > s): # b = max\n if (d > s):\n return 2*(b - 1 - d) + d - s\n else:\n return 2*(b - 1 - s) + s - d\n elif (d > b and d > s): # d = max\n if (b > s):\n return 2*(d - 1 - b) + b - s\n else:\n return 2*(d - 1 - s) + s - b\n else: # s = max\n if (b > d):\n return 2*(s - 1 - b) + b - d\n else:\n return 2*(s - 1 - d) + d - b\n\nrs = do()\nprint(rs)\n", "passed": true, "time": 0.15, "memory": 14640.0, "status": "done"}, {"code": "from collections import defaultdict\nimport sys, os, math\n\ndef __starting_point():\n #n, m = list(map(int, input().split()))\n b, d, s = map(int, input().split())\n ans = 0\n if b > d and b > s:\n ans = (b - 1) * 3 + 1 - d - b - s\n elif d > b and d > s:\n ans = (d - 2) * 3 + 4 - d - b - s\n elif s > d and s > b:\n ans = (s - 1) * 3 + 1 - d - b - s\n elif s == d == b:\n ans = 0\n elif d == b:\n ans = (b - 1) * 3 + 2 - d - b - s\n elif b == s:\n ans = (b - 1) * 3 + 2 - d - b - s\n else:\n ans = (d - 1) * 3 + 2 - d - b - s\n print(ans)\n__starting_point()", "passed": true, "time": 0.14, "memory": 14616.0, "status": "done"}, {"code": "b,d,s=list(map(int,input().split()))\na1,a2,a3,a4=0,0,0,0\n\n\nif max(b,s,d)==b:\n if d<b-1 and s!=max(b,s,d):\n a1+=b-1-d\n if d<b-1 and s==max(b,s,d):\n a1+=b-d\n if s<b-1:\n a1+=b-1-s\nelif max(b,s,d)==d:\n a1+=d-b\n if s<d-1:\n a1+=d-1-s\nelif max(b,s,d)==s:\n a1+=s-d\n a1+=s-b\n \nb1,d1,s1=d,s,b\nif max(b1,s1,d1)==b1:\n if d1<b1-1 and s1!=max(b1,s1,d1):\n a2+=b1-1-d1\n if d1<b1-1 and s1==max(b1,s1,d1):\n a2+=b1-d1\n if s1<b1-1:\n a2+=b1-1-s1\nelif max(b1,s1,d1)==d1:\n a2+=d1-b1\n if s1<d1-1:\n a2+=d1-1-s1\nelif max(b1,s1,d1)==s1:\n a2+=s1-d1\n a2+=s1-b1\n \nb,d,s=s,b,d\nif max(b,s,d)==b:\n if d<b-1 and s!=max(b,s,d):\n a3+=b-1-d\n if d<b-1 and s==max(b,s,d):\n a3+=b-d\n if s<b-1:\n a3+=b-1-s\nelif max(b,s,d)==d:\n a3+=d-b\n if s<d-1:\n a3+=d-1-s\nelif max(b,s,d)==s:\n a3+=s-d\n a3+=s-b\nprint(min(a1,a2,a3))\n", "passed": true, "time": 0.15, "memory": 14676.0, "status": "done"}, {"code": "def f(a, b, c):\n m = min(a, b, c)\n a, b, c = a - m, b - m, c - m\n if a == b and a == c: return 0\n if a == b:\n if abs(a - c) == 1: return 0\n elif c > a: return (c - a - 1) * 2\n else: return a - c - 1\n if a == c:\n if abs(a - b) == 1: return 0\n elif b > a: return (b - a - 1) * 2\n else: return a - b - 1\n if b == c:\n if abs(a - b) == 1: return 0\n elif a > b: return (a - b - 1) * 2\n else: return b - a - 1\n\n m = min(a, b, c)\n n = min(max(a, b), max(b, c), max(a, c))\n if a == m: a = n\n elif b == m: b = n\n else: c = n\n return n + f(a, b, c)\n\nprint(f(*[int(i) for i in input().split()]))\n", "passed": true, "time": 0.15, "memory": 14428.0, "status": "done"}, {"code": "b, l, d = map(int, input().split())\n\nm = max(b, l, d)\nx = m-1\nmissing = 0\nif x-b > 0:\n missing += x-b\nif x-l > 0:\n missing += x-l\nif x-d > 0:\n missing += x-d\n\nprint(missing)", "passed": true, "time": 0.15, "memory": 14552.0, "status": "done"}, {"code": "a, b, c = list(map(int, input().split()))\nx = max(a, b, c)\na = x - a\nb = x - b\nc = x - c\nif (a > 0 and b > 0) or (a > 0 and c > 0) or (b > 0 and c > 0):\n print(a + b + c - 2)\nelif a > 0 or b > 0 or c > 0:\n print(a + b + c - 1)\nelse:\n print(a + b + c)", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}, {"code": "tr = list(map(int, input().split()))\nk = 0\n\ntr.sort()\n\nfor i in range(2):\n\tif (tr[2] - 1) > tr[i]:\n\t\t k += ((tr[2] - 1) - tr[i])\n\nprint(k)", "passed": true, "time": 0.14, "memory": 14512.0, "status": "done"}] | [{"input": "3 2 1\n", "output": "1\n"}, {"input": "1 0 0\n", "output": "0\n"}, {"input": "1 1 1\n", "output": "0\n"}, {"input": "1000000000000000000 0 1000000000000000000\n", "output": "999999999999999999\n"}, {"input": "1000 0 0\n", "output": "1998\n"}, {"input": "0 1 0\n", "output": "0\n"}, {"input": "0 0 1\n", "output": "0\n"}, {"input": "1 1 0\n", "output": "0\n"}, {"input": "0 1 1\n", "output": "0\n"}, {"input": "1000000000000000000 999999999999999999 999999999999999999\n", "output": "0\n"}, {"input": "1000000000000000000 1000000000000000000 999999999999999999\n", "output": "0\n"}, {"input": "1000000000000000000 1000000000000000000 1000000000000000000\n", "output": "0\n"}, {"input": "999999999999999999 999999999999999999 999999999999999999\n", "output": "0\n"}, {"input": "999999999999999999 1000000000000000000 999999999999999999\n", "output": "0\n"}, {"input": "999999999999999999 1000000000000000000 1000000000000000000\n", "output": "0\n"}, {"input": "999999999999999999 999999999999999998 999999999999999999\n", "output": "0\n"}, {"input": "999999999999999999 999999999999999999 1000000000000000000\n", "output": "0\n"}, {"input": "10 10 10\n", "output": "0\n"}, {"input": "9 11 11\n", "output": "1\n"}, {"input": "10 8 9\n", "output": "1\n"}, {"input": "12 8 8\n", "output": "6\n"}, {"input": "13 18 14\n", "output": "7\n"}, {"input": "94 87 14\n", "output": "85\n"}, {"input": "35 91 108\n", "output": "88\n"}, {"input": "1671 24 419\n", "output": "2897\n"}, {"input": "7759 10296 4966\n", "output": "7865\n"}, {"input": "8912 10561 8205\n", "output": "4003\n"}, {"input": "1000000100 1000000083 1000000047\n", "output": "68\n"}, {"input": "999996782 1000007108 1000009860\n", "output": "15828\n"}, {"input": "999342691 1000075839 1000144842\n", "output": "871152\n"}, {"input": "951468821 1005782339 1063348170\n", "output": "169445178\n"}, {"input": "498556507 1820523034 1566999959\n", "output": "1575489600\n"}, {"input": "99999999999999938 99999999999999971 99999999999999944\n", "output": "58\n"}, {"input": "99999999999995757 100000000000000116 99999999999999158\n", "output": "5315\n"}, {"input": "100000000481729714 100000000353636209 99999999472937283\n", "output": "1136885934\n"}, {"input": "100000330161030627 99999005090484867 99999729994406004\n", "output": "1925237170381\n"}, {"input": "100040306518636197 100049788380618015 99377557930019414\n", "output": "681712312580417\n"}, {"input": "117864695669097197 53280311324979856 171825292362519668\n", "output": "172505577730962281\n"}, {"input": "64058874468711639 248004345115813505 265277488186534632\n", "output": "218491756788544118\n"}, {"input": "0 323940200031019351 1000000000000000000\n", "output": "1676059799968980647\n"}, {"input": "0 1000000000000000000 0\n", "output": "1999999999999999998\n"}, {"input": "4 3 5\n", "output": "1\n"}, {"input": "0 0 1000000000000000000\n", "output": "1999999999999999998\n"}, {"input": "1000000000000000000 0 0\n", "output": "1999999999999999998\n"}, {"input": "0 1000000000000000000 1000000000000000000\n", "output": "999999999999999999\n"}, {"input": "1000000000000000000 1000000000000000000 0\n", "output": "999999999999999999\n"}, {"input": "6436340231848 215 5328562123\n", "output": "12867351901356\n"}, {"input": "1 4352626266226 1\n", "output": "8705252532448\n"}, {"input": "647397084215 513125 15999899\n", "output": "1294777655404\n"}, {"input": "429 42 132\n", "output": "682\n"}, {"input": "1 3 1\n", "output": "2\n"}, {"input": "0 6 0\n", "output": "10\n"}, {"input": "100 100 99\n", "output": "0\n"}, {"input": "3 3 2\n", "output": "0\n"}, {"input": "10 10 9\n", "output": "0\n"}, {"input": "3 3 1\n", "output": "1\n"}, {"input": "100 99 100\n", "output": "0\n"}, {"input": "5 5 4\n", "output": "0\n"}, {"input": "50 70 80\n", "output": "38\n"}, {"input": "4 4 4\n", "output": "0\n"}, {"input": "4 4 3\n", "output": "0\n"}, {"input": "1 0 1\n", "output": "0\n"}, {"input": "0 0 2\n", "output": "2\n"}, {"input": "1 1 10\n", "output": "16\n"}, {"input": "5 2 3\n", "output": "3\n"}, {"input": "5 5 1\n", "output": "3\n"}, {"input": "10 200000 10\n", "output": "399978\n"}, {"input": "3 0 0\n", "output": "4\n"}, {"input": "100 100 100\n", "output": "0\n"}, {"input": "3 5 5\n", "output": "1\n"}, {"input": "3 4 3\n", "output": "0\n"}, {"input": "1000000000000000000 1 0\n", "output": "1999999999999999997\n"}, {"input": "2 0 0\n", "output": "2\n"}, {"input": "5 6 4\n", "output": "1\n"}, {"input": "0 2 2\n", "output": "1\n"}, {"input": "1000000000000000000 100000000000000000 0\n", "output": "1899999999999999998\n"}, {"input": "2 2 1\n", "output": "0\n"}, {"input": "1000000000000000000 1 1\n", "output": "1999999999999999996\n"}, {"input": "1 2 2\n", "output": "0\n"}, {"input": "1 1 5\n", "output": "6\n"}, {"input": "10 0 5\n", "output": "13\n"}, {"input": "10 10 0\n", "output": "9\n"}, {"input": "0 1000 0\n", "output": "1998\n"}] |
|
166 | There is a matrix A of size x × y filled with integers. For every $i \in [ 1 . . x ]$, $j \in [ 1 . . y ]$ A_{i}, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a_1, a_2, ..., a_{n} denoting that you started in the cell containing the number a_1, then moved to the cell with the number a_2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells: (i + 1, j) — only if i < x; (i, j + 1) — only if j < y; (i - 1, j) — only if i > 1; (i, j - 1) — only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a_1, then move to the cell containing a_2 (in one step), then move to the cell containing a_3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
-----Input-----
The first line contains one integer number n (1 ≤ n ≤ 200000) — the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — the integers in the cells on your path.
-----Output-----
If all possible values of x and y such that 1 ≤ x, y ≤ 10^9 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 10^9.
-----Examples-----
Input
8
1 2 3 6 9 8 5 2
Output
YES
3 3
Input
6
1 2 1 2 5 3
Output
NO
Input
2
1 10
Output
YES
4 9
-----Note-----
The matrix and the path on it in the first test looks like this: [Image]
Also there exist multiple correct answers for both the first and the third examples. | interview | [{"code": "MAXN = 1000000000\n\nn = int(input())\na = list(map(int, input().split()))\n\ndef solve1():\t\n\tfor i in range(n-1):\n\t\tif abs(a[i]-a[i+1]) != 1:\n\t\t\treturn False\n\tprint(\"YES\\n%d %d\" % (MAXN, 1))\n\treturn True\n\ndef solve2():\n\tw = -1\n\tfor i in range(n-1):\n\t\td = abs(a[i]-a[i+1])\n\t\tif d != 1:\n\t\t\tif w == -1:\n\t\t\t\tw = d\n\t\t\telif w != d:\n\t\t\t\treturn False\n\tif w <= 0:\n\t\treturn False\n\tfor i in range(n-1):\n\t\tif abs(a[i]-a[i+1]) == 1 and (a[i]-1)//w != (a[i+1]-1)//w:\n\t\t\treturn False\n\tprint(\"YES\\n%d %d\" % (MAXN, w))\n\treturn True\n\nif solve1():\n\tpass\nelif solve2():\n\tpass\nelse:\n\tprint(\"NO\")", "passed": true, "time": 0.14, "memory": 14484.0, "status": "done"}, {"code": "MAXN = 1000000000\n\nn = int(input())\na = list(map(int, input().split()))\n\ndef solve1():\t\n\tfor i in range(n-1):\n\t\tif abs(a[i]-a[i+1]) != 1:\n\t\t\treturn False\n\tprint(\"YES\\n%d %d\" % (MAXN, 1))\n\treturn True\n\ndef solve2():\n\tw = -1\n\tfor i in range(n-1):\n\t\td = abs(a[i]-a[i+1])\n\t\tif d != 1:\n\t\t\tif w == -1:\n\t\t\t\tw = d\n\t\t\telif w != d:\n\t\t\t\treturn False\n\tif w <= 0:\n\t\treturn False\n\tfor i in range(n-1):\n\t\tif abs(a[i]-a[i+1]) == 1 and (a[i]-1)//w != (a[i+1]-1)//w:\n\t\t\treturn False\n\tprint(\"YES\\n%d %d\" % (MAXN, w))\n\treturn True\n\nif solve1():\n\tpass\nelif solve2():\n\tpass\nelse:\n\tprint(\"NO\")", "passed": true, "time": 0.14, "memory": 14492.0, "status": "done"}, {"code": "n = int(input())\na = [int(x) for x in input().split()]\n\ny = []\nfor s, t in zip(a, a[1:]):\n if abs(s - t) != 1 and s != t:\n y.append(abs(s - t))\ny.append(1)\ny = y[0]\n\nfor s, t in zip(a, a[1:]):\n if not(abs(s - t) == y or (abs(s - t) == 1 and min(s, t) % y != 0)):\n break\nelse:\n print(\"YES\")\n print(\"{} {}\".format(10**9, y))\n return\n\nprint(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14408.0, "status": "done"}, {"code": "n = int(input())\nwalk = list(map(int, input().split()))\nMAXN = 1000000000\ndef solve1():\n for i in range(n-1):\n if abs(walk[i+1]-walk[i]) != 1:\n return False\n print(\"YES\")\n print(MAXN, 1)\n return True\n\ndef solve2():\n colum = -1\n for i in range(n-1):\n diff = abs(walk[i+1]-walk[i])\n if diff != 1:\n if colum == -1:\n colum = diff\n elif colum != diff:\n return False\n if colum<=0:\n return False\n for i in range(n-1):\n if abs(walk[i+1]-walk[i]) == 1 and ((walk[i+1]-1)//colum != (walk[i]-1)//colum):\n return False\n print(\"YES\")\n print(MAXN,colum)\n return True\n\nif solve1():\n pass\nelif solve2():\n pass\nelse:\n print(\"NO\")", "passed": true, "time": 0.24, "memory": 14480.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int,input().split()))\nx = 1\ny = 10**9\nif n == 1:\n print('YES')\n print(y,x)\nelse:\n t = 0\n for i in range(1,n):\n s = a[i]-a[i-1]\n if s != 1 and s != -1:\n s = max(s,-s)\n if (x != 1 and x != s) or s == 0:\n print('NO')\n t = 1\n break\n x = s\n if t == 0 and x > 1:\n for i in range(1,n):\n if (a[i] % x == 0 and a[i-1] == a[i]+1) or (a[i-1] % x == 0 and a[i] == a[i-1]+1):\n print('NO')\n t = 1\n break\n if t == 0:\n print('YES')\n print(y,x)", "passed": true, "time": 0.14, "memory": 14548.0, "status": "done"}, {"code": "while True:\n n = int(input())\n path = list(map(int, input().split()))\n\n eleminatedY = {1}\n y = 1\n\n for i in range(n - 1):\n\n diff = abs(path[i] - path[i + 1])\n\n if diff == 0:\n print(\"NO\");return\n\n if diff == 1:\n eleminatedY.add(min(path[i], path[i + 1]))\n if min(path[i], path[i + 1]) % y == 0 and y != 1:\n print(\"NO\");return\n continue\n\n if y == diff:\n continue\n\n for value in eleminatedY:\n if value % diff == 0:\n print(\"NO\");return\n\n if y == 1:\n y = diff\n continue\n \n print(\"NO\");return\n\n print(\"YES\\n{} {}\".format(1000000000, y))\n \n return\n", "passed": true, "time": 0.24, "memory": 14440.0, "status": "done"}, {"code": "n=int(input())\nm=list(map(int,input().split()))\nx=1\nfrom math import fabs\nfor i in range(1,n):\n if not (-1<=m[i]-m[i-1]<=1):\n x=int(fabs(m[i]-m[i-1]))\n break\nfor i in range(1,n):\n if not (fabs(m[i]-m[i-1])==x or (m[i]-1)//x==(m[i-1]-1)//x) or m[i-1]==m[i]: \n print('NO')\n break\nelse:\n print('YES')\n print(10**9,x)", "passed": true, "time": 0.14, "memory": 14492.0, "status": "done"}] | [{"input": "8\n1 2 3 6 9 8 5 2\n", "output": "YES\n1000000000 3\n"}, {"input": "6\n1 2 1 2 5 3\n", "output": "NO\n"}, {"input": "2\n1 10\n", "output": "YES\n1000000000 9\n"}, {"input": "3\n1 2 2\n", "output": "NO\n"}, {"input": "1\n1\n", "output": "YES\n1000000000 1\n"}, {"input": "1\n6\n", "output": "YES\n1000000000 1\n"}, {"input": "2\n2 3\n", "output": "YES\n1000000000 1\n"}, {"input": "2\n1000000000 1\n", "output": "YES\n1000000000 999999999\n"}, {"input": "4\n3 2 4 2\n", "output": "NO\n"}, {"input": "5\n1 2 5 4 3\n", "output": "NO\n"}, {"input": "2\n1 1\n", "output": "NO\n"}, {"input": "3\n1 3 4\n", "output": "YES\n1000000000 2\n"}, {"input": "1\n1000000000\n", "output": "YES\n1000000000 1\n"}, {"input": "6\n1 4 5 6 3 2\n", "output": "YES\n1000000000 3\n"}, {"input": "8\n1 2 3 6 9 8 7 6\n", "output": "NO\n"}, {"input": "9\n4 3 2 1 5 6 7 8 9\n", "output": "NO\n"}, {"input": "8\n2 5 8 9 6 3 2 1\n", "output": "YES\n1000000000 3\n"}, {"input": "4\n1 2 1 3\n", "output": "YES\n1000000000 2\n"}, {"input": "3\n1 4 3\n", "output": "NO\n"}, {"input": "5\n1 2 3 4 1\n", "output": "NO\n"}, {"input": "6\n3 5 2 1 2 1\n", "output": "NO\n"}, {"input": "2\n1000000000 999999999\n", "output": "YES\n1000000000 1\n"}, {"input": "3\n2 4 3\n", "output": "YES\n1000000000 2\n"}, {"input": "5\n1 2 3 2 4\n", "output": "NO\n"}, {"input": "6\n10 8 6 4 2 1\n", "output": "YES\n1000000000 2\n"}, {"input": "7\n1 4 7 8 9 10 11\n", "output": "NO\n"}, {"input": "8\n1 2 3 2 3 4 3 8\n", "output": "YES\n1000000000 5\n"}, {"input": "4\n3 4 3 5\n", "output": "YES\n1000000000 2\n"}, {"input": "4\n1 4 3 2\n", "output": "NO\n"}, {"input": "13\n1 3 4 6 5 3 1 2 4 6 5 3 1\n", "output": "YES\n1000000000 2\n"}, {"input": "3\n1 3 2\n", "output": "NO\n"}, {"input": "6\n4 3 6 9 8 7\n", "output": "NO\n"}, {"input": "6\n1 2 4 3 5 6\n", "output": "YES\n1000000000 2\n"}, {"input": "5\n1 2 4 3 1\n", "output": "YES\n1000000000 2\n"}, {"input": "5\n1 2 4 3 5\n", "output": "YES\n1000000000 2\n"}, {"input": "5\n3 6 5 4 3\n", "output": "NO\n"}, {"input": "37\n94 7 32 29 57 22 11 70 57 61 12 75 93 24 4 47 98 43 99 22 50 32 37 64 80 9 40 87 38 70 17 41 77 76 20 66 48\n", "output": "NO\n"}, {"input": "2\n99999999 100000000\n", "output": "YES\n1000000000 1\n"}, {"input": "5\n3 4 5 6 2\n", "output": "NO\n"}, {"input": "6\n3 8 7 6 5 4\n", "output": "NO\n"}, {"input": "10\n999999999 999999998 999999997 999999996 999999995 999999994 999999993 999999992 999999991 999999990\n", "output": "YES\n1000000000 1\n"}, {"input": "2\n1000000000 999999998\n", "output": "YES\n1000000000 2\n"}, {"input": "5\n8 9 10 14 13\n", "output": "NO\n"}, {"input": "4\n1 3 2 4\n", "output": "NO\n"}, {"input": "4\n2 3 5 6\n", "output": "NO\n"}, {"input": "5\n1 2 3 4 2\n", "output": "NO\n"}, {"input": "3\n5 6 4\n", "output": "YES\n1000000000 2\n"}, {"input": "1\n1000000\n", "output": "YES\n1000000000 1\n"}, {"input": "3\n9 10 1\n", "output": "NO\n"}, {"input": "28\n1 3 5 7 9 10 8 6 4 2 1 2 4 3 5 6 8 7 9 10 8 7 5 6 4 3 1 2\n", "output": "YES\n1000000000 2\n"}, {"input": "5\n3 4 5 6 9\n", "output": "NO\n"}, {"input": "3\n6 8 7\n", "output": "YES\n1000000000 2\n"}, {"input": "1\n100000000\n", "output": "YES\n1000000000 1\n"}, {"input": "6\n2 4 6 5 6 5\n", "output": "YES\n1000000000 2\n"}, {"input": "2\n999999999 1000000000\n", "output": "YES\n1000000000 1\n"}, {"input": "4\n3 6 7 8\n", "output": "NO\n"}, {"input": "23\n92 34 58 40 76 3 38 66 76 23 85 36 47 43 22 46 98 72 97 80 57 77 96\n", "output": "NO\n"}, {"input": "3\n6 7 4\n", "output": "NO\n"}, {"input": "4\n1 2 4 3\n", "output": "YES\n1000000000 2\n"}, {"input": "3\n3 2 4\n", "output": "NO\n"}, {"input": "5\n1 4 3 2 1\n", "output": "NO\n"}, {"input": "5\n1 3 5 4 3\n", "output": "NO\n"}, {"input": "3\n19260816 19260817 19260818\n", "output": "YES\n1000000000 1\n"}, {"input": "3\n1 3 6\n", "output": "NO\n"}, {"input": "2\n999999998 1000000000\n", "output": "YES\n1000000000 2\n"}, {"input": "8\n2 4 6 5 6 5 3 4\n", "output": "YES\n1000000000 2\n"}, {"input": "3\n4 3 6\n", "output": "NO\n"}, {"input": "2\n246642 246641\n", "output": "YES\n1000000000 1\n"}, {"input": "3\n9 7 5\n", "output": "YES\n1000000000 2\n"}, {"input": "10\n1 2 1 2 1 2 1 2 1 2\n", "output": "YES\n1000000000 1\n"}, {"input": "5\n1 3 5 7 8\n", "output": "YES\n1000000000 2\n"}, {"input": "4\n1 10 9 10\n", "output": "NO\n"}, {"input": "2\n2 4\n", "output": "YES\n1000000000 2\n"}, {"input": "8\n1 2 4 3 5 6 8 7\n", "output": "YES\n1000000000 2\n"}, {"input": "3\n4 3 2\n", "output": "YES\n1000000000 1\n"}, {"input": "3\n3 2 1\n", "output": "YES\n1000000000 1\n"}, {"input": "4\n999 1000 2000 2001\n", "output": "NO\n"}, {"input": "3\n4 2 5\n", "output": "NO\n"}, {"input": "2\n500000000 1000000000\n", "output": "YES\n1000000000 500000000\n"}, {"input": "3\n4 5 7\n", "output": "NO\n"}, {"input": "5\n1 3 4 5 4\n", "output": "NO\n"}, {"input": "7\n550 555 554 553 554 555 560\n", "output": "YES\n1000000000 5\n"}] |
|
167 | You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output «-» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b. | interview | [{"code": "def get_substr_ends(haystack, needle):\n\tans = [-1]\n\tindex = 0\n\tfor char in needle:\n\t\twhile index < len(haystack) and char != haystack[index]:\n\t\t\tindex += 1\n\t\tans.append(index)\n\t\tif index < len(haystack):\n\t\t\tindex += 1\n\treturn ans\n\nhaystack = input()\nneedle = input()\n\npref = get_substr_ends(haystack, needle)\nsuff = get_substr_ends(haystack[::-1], needle[::-1])\n\npref_index = 0\nsuff_len = 0\nwhile suff_len < len(suff) and suff[suff_len] < len(haystack):\n\tsuff_len += 1\n\nsuff_len -= 1\nbest_str = needle[len(needle) - suff_len:]\n\nif len(best_str) == len(needle):\n\tprint(needle)\n\treturn\n\nfor pref_len in range(1, len(pref)):\n\twhile suff_len >= 0 and suff[suff_len] + pref[pref_len] + 2 > len(haystack):\n\t\tsuff_len -= 1\n\tans = pref_len + suff_len\n\tif ans > len(best_str) and suff_len >= 0:\n\t\tbest_str = needle[:pref_len] + needle[len(needle) - suff_len:]\n\nprint(best_str if best_str else '-')\n", "passed": true, "time": 0.24, "memory": 14520.0, "status": "done"}, {"code": "a = input()\nb = input()\np = [None] * (len(b) + 1)\ns = [None] * (len(b) + 1)\nj = 0\np[0] = -1\nfor i in range(len(b)):\n while j < len(a) and a[j] != b[i]:\n j += 1\n if j >= len(a):\n break\n else:\n p[i + 1] = j\n j += 1\nj = len(a) - 1\ns[-1] = len(b)\nfor i in range(len(b) - 1, -1, -1):\n while j >= 0 and a[j] != b[i]:\n j -= 1\n if j < 0:\n break\n else:\n s[i] = j\n j -= 1\nans = \"\"\nfor i in range(len(b) + 1):\n if p[i] == None:\n break\n else:\n l = i - 1\n r = len(b)\n while l + 1 < r:\n mid = (l + r) // 2\n if s[mid] != None and p[i] < s[mid]:\n r = mid\n else:\n l = mid\n if len(ans) < i + len(b) - r:\n ans = b[:i] + b[r:]\nif ans == \"\":\n print(\"-\")\nelse:\n print(ans)", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "import math \n\ndef prefixIds(a, b):\n\tprefSubsId = [math.inf] * len(b)\n\n\t# print(a)\n\t# print(b)\n\n\tbId = 0\n\taId = 0\n\n\twhile aId < len(a):\n\t\tif bId == len(b):\n\t\t\tbreak\n\n\t\tif a[aId] == b[bId]:\n\t\t\tprefSubsId[bId] = aId + 1\n\t\t\tbId += 1\n\t\t\taId += 1\n\t\telse:\n\t\t\taId += 1\n\n\treturn prefSubsId\n\na = input()\nb = input()\n\n# print(a)\n# print(b)\n\nn = len(b)\n\nprefLens = prefixIds(a, b)\nsuffLens = prefixIds(a[::-1], b[::-1])[::-1]\n\n# for i in range(n):\n# \tif suffLens[i] != math.inf:\n# \t\tsuffLens[i] = len(a) - suffLens[i]\n\n# print(*prefLens, sep='\\t')\n# print(*suffLens, sep='\\t')\n\nprefLen = 0\nsuffLen = 0\n\nminCutLen = n\nlBorder = -1\nrBorder = n\n\nwhile suffLen < n and suffLens[suffLen] == math.inf:\n\tsuffLen += 1\n\ncurCutLen = suffLen\n# print(curCutLen)\nif curCutLen < minCutLen:\n\tminCutLen = curCutLen\n\trBorder = suffLen\n\nwhile prefLen < suffLen and prefLens[prefLen] != math.inf:\n\twhile suffLen < n and prefLens[prefLen] + suffLens[suffLen] > len(a):\n\t\t# print(suffLen)\n\t\tsuffLen += 1\n\t# print(prefLen)\n\t# print(suffLen)\n\tcurCutLen = suffLen - prefLen - 1\n\t# print(curCutLen)\n\tif curCutLen < minCutLen:\n\t\tminCutLen = curCutLen\n\t\tlBorder = prefLen\n\t\trBorder = suffLen\n\tprefLen += 1\n\t# print(prefLens[prefLen])\n\t# print(suffLens[suffLen])\n# \t# print()\n\n# print(\"pref, suff\")\n# print(prefLen)\n# print(suffLen)\n\n# print(minCutLen)\n# print(n)\n# print(lBorder)\n# print(rBorder)\n\nif minCutLen == n:\n\tprint('-')\nelif minCutLen == 0:\n\tprint(b)\nelse:\n\tprint(b[:lBorder + 1] + b[rBorder:])\n\n# print(maxPrefLen)\n# print(maxSuffLen)\n", "passed": true, "time": 0.14, "memory": 14500.0, "status": "done"}, {"code": "a = input()\nb = input()\n\nprefix = [-1] * len(b)\npostfix = [-1] * len(b)\n\nprefix[0] = a.find(b[0])\npostfix[len(b) - 1] = a.rfind(b[len(b) - 1])\n\nfor i in range(1, len(b)):\n prefix[i] = a.find(b[i], prefix[i - 1] + 1)\n if prefix[i] == -1:\n break\n\nfor i in range(len(b) - 2, -1, -1):\n postfix[i] = a.rfind(b[i], 0, postfix[i+1])\n if postfix[i] == -1:\n break\n\nbest_left = -1\nbest_right = len(b)\n\nleft = -1\nwhile left + 1 < len(b) and prefix[left + 1] != -1:\n left += 1\n\nif left > -1:\n best_left = left\n best_right = len(b)\n\nright = len(b)\nwhile right - 1 >= 0 and postfix[right - 1] != -1:\n right -= 1\n\nif right < len(b) and right + 1 < best_right - best_left:\n best_left = -1\n best_right = right\n\nleft = 0\nright = len(b)\n\nwhile left < right and postfix[right - 1] != -1 and postfix[right - 1] > prefix[left]:\n right -= 1\n\nwhile prefix[left] != -1 and left < right < len(b):\n while right < len(b) and postfix[right] <= prefix[left]:\n right += 1\n\n if right >= len(b):\n break\n\n if right - left < best_right - best_left:\n best_left = left\n best_right = right\n\n left += 1\n\n if left == right:\n right += 1\n\nres = b[:best_left + 1] + b[best_right:]\nif res == \"\":\n print(\"-\")\nelse:\n print(res)\n", "passed": true, "time": 0.14, "memory": 14756.0, "status": "done"}, {"code": "a, b = input(), input()\nn = len(b)\ndef f(a, b):\n i, t = 0, [0]\n for q in a:\n if i < n and q == b[i]: i += 1\n t.append(i)\n return t\nu, v = f(a, b), f(a[::-1], b[::-1])[::-1]\nt = [x + y for x, y in zip(u, v)]\ni = t.index(max(t))\nx, y = u[i], v[i]\ns = b[:x] + b[max(x, n - y):]\nprint(s if s else '-')", "passed": true, "time": 0.34, "memory": 14572.0, "status": "done"}, {"code": "#import sys\n#sys.stdin = open('in', 'r')\n#n = int(input())\n#a = [int(x) for x in input().split()]\n#n,m = map(int, input().split())\n\ns1 = input()\ns2 = input()\nl1 = len(s1)\nl2 = len(s2)\n\ndl = {}\ndr = {}\n\ni1 = 0\ni2 = 0\n\nwhile i1 < l1 and i2 < l2:\n while i1 < l1 and s1[i1] != s2[i2]:\n i1 += 1\n if i1 < l1:\n dl[i2] = i1\n i2 += 1\n i1 += 1\n\nlmax = i2\nif lmax == l2:\n print(s2)\nelse:\n i1 = l1 - 1\n i2 = l2 - 1\n while i1 >= 0 and i2 >= 0:\n while i1 >= 0 and s1[i1] != s2[i2]:\n i1 -= 1\n if i1 >= 0:\n dr[i2] = i1\n i2 -= 1\n i1 -= 1\n rmax = i2\n\n le = -1\n re = -1\n if l2 - lmax < rmax + 1:\n rcnt = l2 - lmax\n ls = 0\n rs = lmax\n else:\n rcnt = rmax + 1\n ls = rmax + 1\n rs = l2\n rr = rmax + 1\n for ll in range(lmax):\n while rr < l2 and (rr <= ll or dl[ll] >= dr[rr]):\n rr += 1\n if rr < l2:\n dif = rr - ll - 1\n if dif < rcnt:\n rcnt = dif\n ls = 0\n rs = ll + 1\n le = rr\n re = l2\n\n result = s2[ls:rs]\n if le != -1:\n result += s2[le:re]\n print(result if len(result) > 0 else '-')\n\n\n", "passed": true, "time": 0.14, "memory": 14576.0, "status": "done"}, {"code": "import sys\n\ns, t = input(), '*'+input()\nn, m = len(s), len(t)-1\ninf = 10**9\n\npre, suf = [-1] + [inf]*(m+1), [-1]*(m+1) + [n]\n\ni = 0\nfor j in range(1, m+1):\n while i < n and s[i] != t[j]:\n i += 1\n if i == n:\n break\n pre[j] = i\n i += 1\n\ni = n-1\nfor j in range(m, 0, -1):\n while 0 <= i and s[i] != t[j]:\n i -= 1\n if i == -1:\n break\n suf[j] = i\n i -= 1\n\nmax_len, best_l, best_r = 0, 0, 0\nj = 1\nfor i in range(m+1):\n j = max(j, i+1)\n while j <= m and pre[i] >= suf[j]:\n j += 1\n if pre[i] == inf:\n break\n if max_len < i + m + 1 - j:\n max_len = i + m + 1 - j\n best_l, best_r = i, j\n\npre_s = t[1:best_l+1]\nsuf_s = t[best_r:]\n\nprint(pre_s + suf_s if max_len else '-')\n", "passed": true, "time": 0.15, "memory": 14508.0, "status": "done"}] | [{"input": "hi\nbob\n", "output": "-\n"}, {"input": "abca\naccepted\n", "output": "ac\n"}, {"input": "abacaba\nabcdcba\n", "output": "abcba\n"}, {"input": "lo\neuhaqdhhzlnkmqnakgwzuhurqlpmdm\n", "output": "-\n"}, {"input": "aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\nmlmarpivirqbxcyhyerjoxlslyfzftrylpjyouypvk\n", "output": "ouypvk\n"}, {"input": "npnkmawey\nareakefvowledfriyjejqnnaeqheoh\n", "output": "a\n"}, {"input": "fdtffutxkujflswyddvhusfcook\nkavkhnhphcvckogqqqqhdmgwjdfenzizrebefsbuhzzwhzvc\n", "output": "kvc\n"}, {"input": "abacaba\naa\n", "output": "aa\n"}, {"input": "edbcd\nd\n", "output": "d\n"}, {"input": "abc\nksdksdsdsnabc\n", "output": "abc\n"}, {"input": "abxzxzxzzaba\naba\n", "output": "aba\n"}, {"input": "abcd\nzzhabcd\n", "output": "abcd\n"}, {"input": "aa\naa\n", "output": "aa\n"}, {"input": "test\nt\n", "output": "t\n"}, {"input": "aa\na\n", "output": "a\n"}, {"input": "aaaabbbbaaaa\naba\n", "output": "aba\n"}, {"input": "aa\nzzaa\n", "output": "aa\n"}, {"input": "zhbt\nztjihmhebkrztefpwty\n", "output": "zt\n"}, {"input": "aaaaaaaaaaaaaaaaaaaa\naaaaaaaa\n", "output": "aaaaaaaa\n"}, {"input": "abba\naba\n", "output": "aba\n"}, {"input": "abbba\naba\n", "output": "aba\n"}, {"input": "aaaaaaaaaaaa\naaaaaaaaaaaa\n", "output": "aaaaaaaaaaaa\n"}, {"input": "aaa\naa\n", "output": "aa\n"}, {"input": "aaaaaaaaaaaa\naaa\n", "output": "aaa\n"}, {"input": "aaaaabbbbbbaaaaaa\naba\n", "output": "aba\n"}, {"input": "ashfaniosafapisfasipfaspfaspfaspfapsfjpasfshvcmvncxmvnxcvnmcxvnmxcnvmcvxvnxmcvxcmvh\nashish\n", "output": "ashish\n"}, {"input": "a\na\n", "output": "a\n"}, {"input": "aaaab\naab\n", "output": "aab\n"}, {"input": "aaaaa\naaaa\n", "output": "aaaa\n"}, {"input": "a\naaa\n", "output": "a\n"}, {"input": "aaaaaabbbbbbaaaaaa\naba\n", "output": "aba\n"}, {"input": "def\nabcdef\n", "output": "def\n"}, {"input": "aaaaaaaaa\na\n", "output": "a\n"}, {"input": "bababsbs\nabs\n", "output": "abs\n"}, {"input": "hddddddack\nhackyz\n", "output": "hack\n"}, {"input": "aba\na\n", "output": "a\n"}, {"input": "ofih\nihfsdf\n", "output": "ih\n"}, {"input": "b\nabb\n", "output": "b\n"}, {"input": "lctsczqr\nqvkp\n", "output": "q\n"}, {"input": "dedcbaa\ndca\n", "output": "dca\n"}, {"input": "haddack\nhack\n", "output": "hack\n"}, {"input": "abcabc\nabc\n", "output": "abc\n"}, {"input": "asdf\ngasdf\n", "output": "asdf\n"}, {"input": "abab\nab\n", "output": "ab\n"}, {"input": "aaaaaaa\naaa\n", "output": "aaa\n"}, {"input": "asdf\nfasdf\n", "output": "asdf\n"}, {"input": "bbaabb\nab\n", "output": "ab\n"}, {"input": "accac\nbaacccbcccabaabbcacbbcccacbaabaaac\n", "output": "aac\n"}, {"input": "az\naaazazaa\n", "output": "a\n"}, {"input": "bbacaabbaaa\nacaabcaa\n", "output": "acaabaa\n"}, {"input": "c\ncbcbcbbacacacbccaaccbcabaaabbaaa\n", "output": "c\n"}, {"input": "bacb\nccacacbacbccbbccccaccccccbcbabbbaababa\n", "output": "ba\n"}, {"input": "ac\naacacaacbaaacbbbabacaca\n", "output": "a\n"}, {"input": "a\nzazaa\n", "output": "a\n"}, {"input": "abcd\nfaaaabbbbccccdddeda\n", "output": "a\n"}, {"input": "abcde\nfabcde\n", "output": "abcde\n"}, {"input": "a\nab\n", "output": "a\n"}, {"input": "ababbbbbbbbbbbb\nabbbbb\n", "output": "abbbbb\n"}, {"input": "bbbbaabbababbaaaaababbaaabbbbaaabbbababbbbabaabababaabaaabbbabababbbabababaababaaaaa\nbbabaaaabaaaabbaaabbbabaaabaabbbababbbbbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\n", "output": "bbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\n"}, {"input": "ab\naba\n", "output": "ab\n"}, {"input": "aa\naaaa\n", "output": "aa\n"}, {"input": "aaaaabbbaaaaa\naabbaa\n", "output": "aabbaa\n"}, {"input": "aaaaaaaaa\naaaa\n", "output": "aaaa\n"}, {"input": "abbcc\naca\n", "output": "ac\n"}, {"input": "b\ncb\n", "output": "b\n"}, {"input": "aac\naaa\n", "output": "aa\n"}, {"input": "ba\nbb\n", "output": "b\n"}, {"input": "a\nb\n", "output": "-\n"}, {"input": "gkvubrvpbhsfiuyha\nihotmn\n", "output": "ih\n"}, {"input": "ccccabccbb\ncbbabcc\n", "output": "cabcc\n"}, {"input": "babababbaaabb\nabbab\n", "output": "abbab\n"}, {"input": "njtdhyqundyedsjyvy\nypjrs\n", "output": "ys\n"}, {"input": "uglyqhkpruxoakm\ncixxkpaaoodpuuh\n", "output": "uh\n"}, {"input": "a\naaaaaaaaa\n", "output": "a\n"}, {"input": "aaa\naaaaa\n", "output": "aaa\n"}, {"input": "abcabbcbcccbccbbcc\nacbcaabbbbcabbbaca\n", "output": "acbc\n"}, {"input": "caacacaacbaa\nacbbbabacacac\n", "output": "aacacac\n"}, {"input": "aa\naaab\n", "output": "aa\n"}, {"input": "acbc\ncacacbac\n", "output": "ac\n"}, {"input": "bacbcaacabbaacb\ncbbaaccccbcaacacaabb\n", "output": "cbcaabb\n"}, {"input": "baababaaaab\nbaababbbbbbb\n", "output": "baababb\n"}, {"input": "aaxyaba\naaba\n", "output": "aaba\n"}] |
|
169 | Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs a rubles, or in glass liter bottle, that costs b rubles. Also, you may return empty glass bottle and get c (c < b) rubles back, but you cannot return plastic bottles.
Kolya has n rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help.
-----Input-----
First line of the input contains a single integer n (1 ≤ n ≤ 10^18) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers a, b and c (1 ≤ a ≤ 10^18, 1 ≤ c < b ≤ 10^18) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively.
-----Output-----
Print the only integer — maximum number of liters of kefir, that Kolya can drink.
-----Examples-----
Input
10
11
9
8
Output
2
Input
10
5
6
1
Output
2
-----Note-----
In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir. | interview | [{"code": "n=int(input())\na=int(input())\nb=int(input())\nc=int(input())\nr=n//a\nif n > c:\n r=max(r,(r-b+c)//a+1,(n-c)//(b-c)+((n-c)%(b-c)+c)//a)\nprint(r)", "passed": true, "time": 0.15, "memory": 14480.0, "status": "done"}, {"code": "n = int(input())\na = int(input())\nb = int(input())\nc = int(input())\nif(a < (b - c) or n < b):\n print(n // a)\nelse:\n print((n-b)//(b-c) + 1 + (c + (n-b)%(b-c)) // a)\n \n", "passed": true, "time": 0.17, "memory": 14536.0, "status": "done"}, {"code": "n = int(input())\na = int(input())\nb = int(input())\nc = int(input())\nif a <= b - c or b > n:\n print(n // a)\nelse:\n ans = (n - c) // (b - c)\n ans += ((n - c) % (b - c) + c) // a\n print(ans)", "passed": true, "time": 0.17, "memory": 14548.0, "status": "done"}, {"code": "n = int(input())\na = int(input())\nb = int(input())\nc = int(input())\n\ncost1 = a\ncost2 = b - c\n\nif cost1 <= cost2:\n\tprint(n // cost1)\nelse:\n\tr = 0\n\tif n >= b:\n\t\tt = (n - b + 1) // cost2\n\t\tr += t\n\t\tn -= t * cost2\n\t\tif n >= b:\n\t\t\tn -= cost2\n\t\t\tr += 1\n\n\n\n\tr += n // cost1\n\tprint(r)", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "import time\n\nn = int(input())\na = int(input())\nb = int(input())\nc = int(input())\n\n_b = int(b);\nb -= c\n\nsecond = 0\nif(n >= _b) :\n second = (n - _b) // b + max(1 + (((n - _b) % b + c) // a), ((n - _b) % b + _b) // a)\n\nprint(max(n // a, second))", "passed": true, "time": 0.42, "memory": 14616.0, "status": "done"}, {"code": "n = int(input())\na = int(input())\nb = int(input())\nc = int(input())\n\ncnt1 = n // a\nif (n % a >= b):\n cnt1 = cnt1 + 1\n\ncnt2 = 0\n\nk = (n - b) // (b - c)\n\nfor mi in range(max(0, k - 10), k + 10, 1):\n if (n - mi * (b - c) >= b):\n cnt2 = mi + 1\n cnt2 = cnt2 + (n - (mi + 1) * (b - c)) // a\n\n\nprint(max(cnt1, cnt2))", "passed": true, "time": 1.12, "memory": 14528.0, "status": "done"}, {"code": "n=int(input())\na=int(input())\nb=int(input())\nc=int(input())\n\nd=b-c\n\nif a<=d:\n print(n//a)\n\nelse:\n lb=0\n ub=n\n \n while ub-lb>1 :\n mid=(ub+lb)//2\n tmp=n-d*(mid-1)\n if tmp>=b :\n lb=mid\n else :\n ub=mid\n \n ans=lb\n n-=d*lb\n ans+=n//a\n print(ans)\n\n", "passed": true, "time": 0.38, "memory": 14324.0, "status": "done"}, {"code": "n = int(input())\na = int(input())\nb = int(input())\nc = int(input())\n\n\nif a > (b - c):\n\tx = ((n - b) // (b - c))\n\tif x < 0:\n\t\tx = n // a\n\t\tprint(x)\n\telse:\n\t\tn -= (x + 1) * (b - c)\n\t\tx += 1\n\t\tx += n // a\n\t\tprint(x)\nelse:\n\tx = (n // a)\n\tprint(x)\n", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "n = int(input())\na = int(input())\nb = int(input())\nc = int(input())\n\nl = 0\nwhile n >= a or n >= b:\n if n >= b and b - c < a:\n nl1 = (n - b) // (b - c)\n nl2 = n // b\n nl = max(nl1, nl2)\n l += nl\n n -= (b - c) * nl\n else:\n nl = n // a\n l += nl\n n -= a * nl\n\nprint(l)\n", "passed": true, "time": 0.19, "memory": 14392.0, "status": "done"}, {"code": "n = int(input())\na = int(input())\nb = int(input())\nc = int(input())\nif (a <= b - c):\n print(n // a)\n return\notv = n // (b - c)\nrazn = b - c\nrazn1 = n - b\nif ((razn1 // razn) >= 0):\n otv = razn1 // razn + 1\nelse:\n otv = 0\notv += (n - otv * (b - c)) // a\nprint(otv)", "passed": true, "time": 0.15, "memory": 14600.0, "status": "done"}, {"code": "n, a, b, c = int(input()), int(input()), int(input()), int(input())\nx = (n - c) // (b - c)\nif c > n:\n\tx = 0\ny = n - x * (b - c)\nx += y // a\nprint(max(x, n // a))", "passed": true, "time": 0.14, "memory": 14348.0, "status": "done"}, {"code": "import collections\nimport math\n\ndef is_prime(x): \n for i in range(2, math.ceil(math.sqrt(x))):\n if x % i == 0:\n return False\n return True\n\nn = int(input())\na = int(input())\nb = int(input())\nc = int(input())\nans = 0\nif b - c < a:\n if b < n:\n ans += (n - b) // (b - c)\n n = b + (n - b) % (b - c)\n while n >= b:\n ans += n // b\n n = n % b + n // b * c\nans += n // a\nprint(ans)", "passed": true, "time": 0.14, "memory": 14580.0, "status": "done"}, {"code": "\n\n\nn = int(input())\na = int(input())\nb = int(input())\nc = int(input())\n\nif b > n and a > n:\n print(0)\nelif b - c >= a or b > n:\n print(n//a)\nelse:\n print((n-b)//(b-c) + 1 + (c+(n-b)%(b-c))//a)\n\n\n\n\n\n\n", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "n, a, b, c = [int(input()) for _ in range(4)]\n\n# n=ax+\n\nuse = max(0, (n - b) // (b - c))\nrem = n - use * (b - c)\nx = rem // b\nans = max(n // a, use + max(rem // a, x + (rem - x * b + c * x) // a))\nprint(ans)\n\n", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}, {"code": "n, a, b, c = int(input()), int(input()), int(input()), int(input())\nl = 0\nif b - c < a and n >= c:\n l = (n - c)//(b - c)\n n -= l*(b - c)\nl += n//a\nprint(l)", "passed": true, "time": 0.15, "memory": 14448.0, "status": "done"}, {"code": "n=int(input())\na=int(input())\nb=int(input())\nc=int(input())\nlitr =0\ncen = b-c\nif n>=a or n>=b:\n if cen < a and n>=c:\n litr = (n-c)//(b-c)\n n-=litr*(b-c)\nlitr += n//a\nprint(litr)\n", "passed": true, "time": 0.15, "memory": 14584.0, "status": "done"}, {"code": "n=int(input())\na=int(input())\nb=int(input())\nc=int(input())\nd=0\ne=-1\nif n>=b:\n d=(n-b)//(b-c)\n e=((n-b)%(b-c)+c)//a\nprint(max(d+e+1,n//a,0))", "passed": true, "time": 0.14, "memory": 14464.0, "status": "done"}, {"code": "readInts = lambda: list(map(int, input().split()))\n\nn=int (input())\na=int (input())\nb=int (input())\nc=int (input())\n\nif a<=b-c or b>n:\n print(n//a)\nelse:\n tot=n-b\n cost=b-c\n ret=tot//cost+1+(tot%cost+c)//a\n print(ret)\n\n\n\n\n", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "n = int(input())\na = int(input())\nb = int(input())\nc = int(input())\n\nr = b - c\n\nx = 0\nif r < a and b <= n:\n x += (n - b) // r + 1\n n -= r * x\nx += n // a\nprint(x)", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}, {"code": "#! /usr/bin/env python\n# -*- coding: utf-8 -*-\n# vim:fenc=utf-8\n#\n# Copyright \u00a9 2016 missingdays <missingdays@missingdays>\n#\n# Distributed under terms of the MIT license.\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\nn = int(input())\n\na = int(input())\nb = int(input())\nc = int(input())\n\nif a < b-c:\n print(n//a)\nelif n < b:\n print(n//a)\nelse:\n diff = b-c\n\n answ = (n-b)//diff\n\n n -= answ*b\n n += answ*c\n\n if n >= b:\n n -= b\n n += c\n answ += 1\n answ += n//a\n\n print(max(answ, 0))\n\n", "passed": true, "time": 0.14, "memory": 14452.0, "status": "done"}, {"code": "N = int(input())\na = int(input())\nb = int(input())\nc = int(input())\n\nsolution = 0\n\nif a >= b - c:\n if N >= b:\n solution = (N - b) // (b - c) + 1\n\n solution += (N - solution * (b - c)) // a\nelse:\n solution = N // a\n\nprint(solution)", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}, {"code": "def __starting_point():\n r = int(input())\n a = int(input()) #plastic bottle\n b = int(input()) #glass bottl e\n c = int(input()) #return on glass bottle\n d = 0 #drinks\n if b-c>=a:\n d+=r//a\n r =r%a\n #print('a',d,r)\n else:\n if r>=b:\n t = (r - b + 1)//(b-c)\n d += t\n r -= t * (b-c)\n if r >= b:\n r -= (b-c)\n d += 1\n d+=r//a\n \n '''\n while r>=b:\n d+=r//b\n r = r%b + c*(r//b)\n print(d,r)\n if r>=a: d+=r//a\n '''\n print (d)\n'''\n\nA. Guest From the Past\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\n\nKolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.\n\nKolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs a rubles, or in glass liter bottle, that costs b rubles. Also, you may return empty glass bottle and get c (c\u2009<\u2009b) rubles back, but you cannot return plastic bottles.\n\nKolya has n rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help.\nInput\n\nFirst line of the input contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091018) \u2014 the number of rubles Kolya has at the beginning.\n\nThen follow three lines containing integers a, b and c (1\u2009\u2264\u2009a\u2009\u2264\u20091018, 1\u2009\u2264\u2009c\u2009<\u2009b\u2009\u2264\u20091018) \u2014 the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively.\nOutput\n\nPrint the only integer \u2014 maximum number of liters of kefir, that Kolya can drink.\nSample test(s)\nInput\n\n10\n11\n9\n8\n\nOutput\n\n2\n\nInput\n\n10\n5\n6\n1\n\nOutput\n\n2\n\nNote\n\nIn the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.\n\nIn the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir.\n'''\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14628.0, "status": "done"}, {"code": "import collections\nimport math\n\ndef is_prime(x): \n for i in range(2, math.ceil(math.sqrt(x))):\n if x % i == 0:\n return False\n return True\n\nn = int(input())\na = int(input())\nb = int(input())\nc = int(input())\nans = 0\nif b - c < a:\n if b < n:\n ans += (n - b) // (b - c)\n n = b + (n - b) % (b - c)\n if b <= n:\n ans += n // b\n n = n % b + n // b * c\nans += n // a\nprint(ans)", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "n = int(input())\na = int(input())\nb = int(input())\nc = int(input())\n\n\nres = (n-b)//(b-c)+1\nif res >= 0:\n res += ((n-b)%(b-c) + c) // a\n\nif res < n // a:\n res = n // a\nprint(res)\n \n", "passed": true, "time": 0.15, "memory": 14604.0, "status": "done"}] | [{"input": "10\n11\n9\n8\n", "output": "2\n"}, {"input": "10\n5\n6\n1\n", "output": "2\n"}, {"input": "2\n2\n2\n1\n", "output": "1\n"}, {"input": "10\n3\n3\n1\n", "output": "4\n"}, {"input": "10\n1\n2\n1\n", "output": "10\n"}, {"input": "10\n2\n3\n1\n", "output": "5\n"}, {"input": "9\n2\n4\n1\n", "output": "4\n"}, {"input": "9\n2\n2\n1\n", "output": "8\n"}, {"input": "9\n10\n10\n1\n", "output": "0\n"}, {"input": "10\n2\n2\n1\n", "output": "9\n"}, {"input": "1000000000000000000\n2\n10\n9\n", "output": "999999999999999995\n"}, {"input": "501000000000000000\n300000000000000000\n301000000000000000\n100000000000000000\n", "output": "2\n"}, {"input": "10\n1\n9\n8\n", "output": "10\n"}, {"input": "10\n8\n8\n7\n", "output": "3\n"}, {"input": "10\n5\n5\n1\n", "output": "2\n"}, {"input": "29\n3\n3\n1\n", "output": "14\n"}, {"input": "45\n9\n9\n8\n", "output": "37\n"}, {"input": "45\n9\n9\n1\n", "output": "5\n"}, {"input": "100\n10\n10\n9\n", "output": "91\n"}, {"input": "179\n10\n9\n1\n", "output": "22\n"}, {"input": "179\n2\n2\n1\n", "output": "178\n"}, {"input": "179\n179\n179\n1\n", "output": "1\n"}, {"input": "179\n59\n59\n58\n", "output": "121\n"}, {"input": "500\n250\n250\n1\n", "output": "2\n"}, {"input": "500\n1\n250\n1\n", "output": "500\n"}, {"input": "501\n500\n500\n499\n", "output": "2\n"}, {"input": "501\n450\n52\n1\n", "output": "9\n"}, {"input": "501\n300\n301\n100\n", "output": "2\n"}, {"input": "500\n179\n10\n1\n", "output": "55\n"}, {"input": "1000\n500\n10\n9\n", "output": "991\n"}, {"input": "1000\n2\n10\n9\n", "output": "995\n"}, {"input": "1001\n1000\n1000\n999\n", "output": "2\n"}, {"input": "10000\n10000\n10000\n1\n", "output": "1\n"}, {"input": "10000\n10\n5000\n4999\n", "output": "5500\n"}, {"input": "1000000000\n999999998\n999999999\n999999998\n", "output": "3\n"}, {"input": "1000000000\n50\n50\n49\n", "output": "999999951\n"}, {"input": "1000000000\n500\n5000\n4999\n", "output": "999995010\n"}, {"input": "1000000000\n51\n100\n98\n", "output": "499999952\n"}, {"input": "1000000000\n100\n51\n50\n", "output": "999999950\n"}, {"input": "1000000000\n2\n5\n4\n", "output": "999999998\n"}, {"input": "1000000000000000000\n999999998000000000\n999999999000000000\n999999998000000000\n", "output": "3\n"}, {"input": "1000000000\n2\n2\n1\n", "output": "999999999\n"}, {"input": "999999999\n2\n999999998\n1\n", "output": "499999999\n"}, {"input": "999999999999999999\n2\n2\n1\n", "output": "999999999999999998\n"}, {"input": "999999999999999999\n10\n10\n9\n", "output": "999999999999999990\n"}, {"input": "999999999999999999\n999999999999999998\n999999999999999998\n999999999999999997\n", "output": "2\n"}, {"input": "999999999999999999\n501\n501\n1\n", "output": "1999999999999999\n"}, {"input": "999999999999999999\n2\n50000000000000000\n49999999999999999\n", "output": "974999999999999999\n"}, {"input": "999999999999999999\n180\n180\n1\n", "output": "5586592178770949\n"}, {"input": "1000000000000000000\n42\n41\n1\n", "output": "24999999999999999\n"}, {"input": "1000000000000000000\n41\n40\n1\n", "output": "25641025641025641\n"}, {"input": "100000000000000000\n79\n100\n25\n", "output": "1333333333333333\n"}, {"input": "1\n100\n5\n4\n", "output": "0\n"}, {"input": "1000000000000000000\n1000000000000000000\n10000000\n9999999\n", "output": "999999999990000001\n"}, {"input": "999999999999999999\n999999999000000000\n900000000000000000\n899999999999999999\n", "output": "100000000000000000\n"}, {"input": "13\n10\n15\n11\n", "output": "1\n"}, {"input": "1\n1000\n5\n4\n", "output": "0\n"}, {"input": "10\n100\n10\n1\n", "output": "1\n"}, {"input": "3\n2\n100000\n99999\n", "output": "1\n"}, {"input": "4\n2\n4\n2\n", "output": "2\n"}, {"input": "5\n3\n6\n4\n", "output": "1\n"}, {"input": "1\n7\n65\n49\n", "output": "0\n"}, {"input": "10\n20\n100\n99\n", "output": "0\n"}, {"input": "10000000000\n10000000000\n9000000000\n8999999999\n", "output": "1000000001\n"}, {"input": "90\n30\n101\n100\n", "output": "3\n"}, {"input": "999999999999999\n5\n500000000000000\n499999999999999\n", "output": "599999999999999\n"}, {"input": "1000000000000000000\n1000000000000000000\n1000000000\n999999999\n", "output": "999999999000000001\n"}, {"input": "1\n1000000000000000000\n1000000000\n999999999\n", "output": "0\n"}, {"input": "100000000000000000\n100000000000000000\n1000000000\n999999999\n", "output": "99999999000000001\n"}, {"input": "100000000000000009\n100\n1000000000000000\n999999999999999\n", "output": "99010000000000009\n"}, {"input": "10\n20\n10\n9\n", "output": "1\n"}, {"input": "10\n4\n14\n13\n", "output": "2\n"}, {"input": "11\n3\n9\n7\n", "output": "4\n"}, {"input": "1000000000\n5\n7\n4\n", "output": "333333332\n"}, {"input": "12155\n1943\n28717\n24074\n", "output": "6\n"}, {"input": "1000000000000000000\n10\n20\n5\n", "output": "100000000000000000\n"}, {"input": "98\n33\n440\n314\n", "output": "2\n"}, {"input": "1070252292\n57449678\n237309920\n221182550\n", "output": "56\n"}, {"input": "100\n3\n102\n101\n", "output": "33\n"}, {"input": "100000000000000000\n100000000000000001\n1000000000000000\n999999999999999\n", "output": "99000000000000001\n"}, {"input": "66249876257975628\n302307316\n406102416\n182373516\n", "output": "296116756\n"}, {"input": "10\n5\n10\n1\n", "output": "2\n"}] |
|
171 | You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic check.
Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions: the password length is at least 5 characters; the password contains at least one large English letter; the password contains at least one small English letter; the password contains at least one digit.
You are given a password. Please implement the automatic check of its complexity for company Q.
-----Input-----
The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_".
-----Output-----
If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes).
-----Examples-----
Input
abacaba
Output
Too weak
Input
X12345
Output
Too weak
Input
CONTEST_is_STARTED!!11
Output
Correct | interview | [{"code": "s = input().strip()\nflag1 = len(s) >= 5\nd1 = 'qwertyuiopasdfghjklzxcvbnm'\nd2 = 'QWERTYUIOPASDFGHJKLZXCVBNM'\nd3 = '123456789'\nflag2 = False\nflag3 = False\nflag4 = False\n\nfor i in d1:\n if i in s:\n flag2 = True\nfor i in d2:\n if i in s:\n flag3 = True\nfor i in d3:\n if i in s:\n flag4 = True \nif(flag1 and flag2 and flag3 and flag4):\n print(\"Correct\")\nelse:\n print(\"Too weak\")\n\n", "passed": true, "time": 0.15, "memory": 14412.0, "status": "done"}, {"code": "s = input().strip()\nflag1 = len(s) >= 5\nd1 = 'qwertyuiopasdfghjklzxcvbnm'\nd2 = 'QWERTYUIOPASDFGHJKLZXCVBNM'\nd3 = '1234567890'\nflag2 = False\nflag3 = False\nflag4 = False\n\nfor i in d1:\n if i in s:\n flag2 = True\nfor i in d2:\n if i in s:\n flag3 = True\nfor i in d3:\n if i in s:\n flag4 = True \nif(flag1 and flag2 and flag3 and flag4):\n print(\"Correct\")\nelse:\n print(\"Too weak\")\n\n", "passed": true, "time": 0.15, "memory": 14400.0, "status": "done"}, {"code": "import re\na1=re.compile('[a-z]')\na2=re.compile('[A-Z]')\na3=re.compile('[0-9]')\ns=input()\nif len(s)>=5:\n s=list(s)\n ar=[0,0,0]\n for i in s:\n if(a1.match(i)!=None):\n ar[0]+=1\n for i in s:\n if(a2.match(i)!=None):\n ar[1]+=1\n for i in s:\n if(a3.match(i)!=None):\n ar[2]+=1\n if (ar[0]!=0 and ar[1]!=0 and ar[2]!=0):\n print('Correct')\n else:\n print('Too weak')\nelse:\n print('Too weak')\n", "passed": true, "time": 0.23, "memory": 14544.0, "status": "done"}, {"code": "s=input()\nimport string\na=1\nfor i in s:\n if i in string.ascii_lowercase:\n a*=2\n if i in string.ascii_uppercase:\n a*=3\n if i in string.digits:\n a*=5\nprint(\"Too weak\" if (a%30 or len(s)<5) else \"Correct\")\n", "passed": true, "time": 0.21, "memory": 14544.0, "status": "done"}, {"code": "S = input()\nans = 0\nAns = 0\nns = 0\n\nfor i in range(len(S)):\n k = ord(S[i])\n if k >= 48 and k <= 57:\n ns += 1\n elif k >=65 and k <= 90:\n Ans += 1\n elif k >= 97 and k <= 122:\n ans += 1\nif ans != 0 and Ans != 0 and len(S) >= 5 and ns != 0:\n print('Correct')\nelse:\n print('Too weak')", "passed": true, "time": 0.24, "memory": 14580.0, "status": "done"}, {"code": "s = input()\nprint('Correct' if len(s) >= 5 and any([elem.isupper() for elem in s]) and any([elem.islower() for elem in s]) and any([elem.isdigit() for elem in s]) else 'Too weak')", "passed": true, "time": 1.81, "memory": 14524.0, "status": "done"}, {"code": "import re\na1=re.compile('[a-z]')\na2=re.compile('[A-Z]')\na3=re.compile('[0-9]')\ns=input()\nif len(s)>=5:\n s=list(s)\n ar=[0,0,0]\n for i in s:\n if(a1.match(i)!=None):\n ar[0]+=1\n for i in s:\n if(a2.match(i)!=None):\n ar[1]+=1\n for i in s:\n if(a3.match(i)!=None):\n ar[2]+=1\n if (ar[0]!=0 and ar[1]!=0 and ar[2]!=0):\n print('Correct')\n else:\n print('Too weak')\nelse:\n print('Too weak')\n", "passed": true, "time": 0.16, "memory": 14372.0, "status": "done"}, {"code": "s=input()\na=False\nb=False\nc=False\nd=False\nif(len(s)>=5):\n a=True\nfor i in range(len(s)):\n if(ord(s[i])>=ord('A') and ord(s[i])<=ord('Z')):\n b=True\n if(ord(s[i])>=ord('a') and ord(s[i])<=ord('z')):\n c=True\n if(ord(s[i])>=ord('1') and ord(s[i])<=ord('9')):\n d=True\nif(a and b and c and d):\n print(\"Correct\")\nelse:\n print(\"Too weak\")\n", "passed": true, "time": 1.62, "memory": 14600.0, "status": "done"}, {"code": "upreg=['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']\ndownreg=['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']\ncifra=['1','2','3','4','5','6','7','8','9','0']\nslovo=input()\nflag=[0,0,0,0]\nif len(slovo)>=5:\n flag[0]=1\nfor i in range(len(slovo)):\n simvol=slovo[i:i+1]\n if simvol in upreg:\n flag[1]=1\n if simvol in downreg:\n flag[2]=1\n if simvol in cifra:\n flag[3]=1\nif flag[0] and flag[1] and flag[2] and flag[3]:\n print('Correct')\nelse:\n print('Too weak')\n", "passed": true, "time": 0.16, "memory": 14432.0, "status": "done"}, {"code": "s = input()\nup, low, digit = False, False, False\nfor ch in s:\n if ch.isdigit():\n digit = True\n elif ch.isalpha():\n if ch.isupper():\n up = True\n else:\n low = True\nif len(s) >= 5 and up and low and digit:\n print('Correct')\nelse:\n print('Too weak')\n\n", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "s = input()\nyes = True\nyes &= len(s) >= 5\nyes &= any(c.isupper() for c in s)\nyes &= any(c.islower() for c in s)\nyes &= any(c.isdigit() for c in s)\n\nif yes:\n print('Correct')\nelse:\n print('Too weak')\n", "passed": true, "time": 0.25, "memory": 14456.0, "status": "done"}, {"code": "def check(a):\n if len(a) < 5:\n return 0\n does_have_little = 0\n for elem in [chr(i) for i in range(ord('a'), ord('z') + 1)]:\n if elem in a:\n does_have_little = 1\n break\n if not does_have_little:\n return 0\n does_have_big = 0\n for elem in [chr(i) for i in range(ord('A'), ord('Z') + 1)]:\n if elem in a:\n does_have_big = 1\n break\n if not does_have_big:\n return 0\n number = 0\n for elem in [chr(i) for i in range(ord('0'), ord('9') + 1)]:\n if elem in a:\n number = 1\n break\n if not number:\n return 0\n return 1\n\na = input()\nif check(a):\n print(\"Correct\")\nelse:\n print(\"Too weak\")", "passed": true, "time": 0.24, "memory": 14364.0, "status": "done"}, {"code": "pw = input()\n\nlg = case = numb = 0\n\nif len(pw) >= 5:\n lg = 1\nif pw.lower() != pw and pw.upper() != pw:\n case = 1\nfor i in pw:\n if i.isnumeric():\n numb = 1\n\n#print(lg, case, numb)\n\nif numb and case and lg:\n print('Correct')\nelse:\n print('Too weak')\n", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}, {"code": "str = input()\nsmall = 0\nbig = 0\nnum = 0\nfor i in range(10):\n if chr(i + ord('0')) in str:\n num = 1\nfor i in range(26):\n if chr(i + ord('a')) in str:\n small = 1\nfor i in range(26):\n if chr(i + ord('A')) in str:\n big = 1\nif len(str) >= 5 and big and small and num:\n print(\"Correct\")\nelse:\n print(\"Too weak\")\n", "passed": true, "time": 0.15, "memory": 14496.0, "status": "done"}, {"code": "s = input()\nif len(s) < 5:\n print(\"Too weak\")\nelse:\n a = b = c = False\n for i in range(0, 26):\n if chr(ord('A') + i) in s:\n a = True\n if chr(ord('a') + i) in s:\n b = True\n if i < 10 and chr(ord('0') + i) in s:\n c = True\n if a and b and c:\n print(\"Correct\")\n else:\n print(\"Too weak\")", "passed": true, "time": 0.18, "memory": 14588.0, "status": "done"}, {"code": "S = input()\nlower, upper, number = False, False, False\nL, U, N = [str(i) for i in range(10)], [chr(i) for i in range(ord('A'), ord('Z') + 1)], [chr(i) for i in range(ord('a'), ord('z') + 1)]\n\nfor letter in S:\n lower = lower or (letter in L)\n upper = upper or (letter in U)\n number = number or (letter in N)\nif (len(S) >= 5 and lower and upper and number):\n print (\"Correct\")\nelse:\n print (\"Too weak\")\n", "passed": true, "time": 0.21, "memory": 14536.0, "status": "done"}, {"code": "import re\n\ndef getAnswer(x):\n if len(x) < 5:\n return \"Too weak\"\n if (re.search('[A-Z]',x)) == None:\n return \"Too weak\"\n if (re.search('[a-z]',x)) == None:\n return \"Too weak\"\n if (re.search('[0-9]',x)) == None:\n return \"Too weak\"\n return \"Correct\"\ndef main():\n x = input()\n print(getAnswer(x))\n\nmain()", "passed": true, "time": 0.14, "memory": 14388.0, "status": "done"}, {"code": "S = input()\na = len(S) >= 5\nb, c, d = 0, 0, 0\nfor i in S:\n if 'A' <= i <= 'Z':\n b = 1\n if 'a' <= i <= 'z':\n c = 1\n if '0' <= i <= '9':\n d = 1\nif a + b + c + d == 4:\n print(\"Correct\")\nelse:\n print(\"Too weak\")\n", "passed": true, "time": 0.15, "memory": 14552.0, "status": "done"}, {"code": "def main():\n a = input()\n lower = False\n upper = False\n digit = False\n if len(a) >= 5:\n for c in a:\n lower = lower or c.islower()\n upper = upper or c.isupper()\n digit = digit or c.isdigit()\n if lower and upper and digit:\n print(\"Correct\")\n else:\n print(\"Too weak\")\n else:\n print(\"Too weak\")\n\nmain()", "passed": true, "time": 0.14, "memory": 14476.0, "status": "done"}, {"code": "print('Correct' if (lambda s: len(s) >= 5 and any([elem.isupper() for elem in s]) and any([elem.islower() for elem in s]) and any([elem.isdigit() for elem in s]))(input()) else 'Too weak')\n", "passed": true, "time": 0.15, "memory": 14456.0, "status": "done"}, {"code": "import string\ns = input()\nf1 = f2 = f3 = False\nfor c in s:\n if c in string.ascii_lowercase:\n f1 = True\n if c in string.ascii_uppercase:\n f2 = True\n if c in string.digits:\n f3 = True\nif len(s) >= 5 and f1 and f2 and f3:\n print('Correct')\nelse:\n print('Too weak')", "passed": true, "time": 0.15, "memory": 14600.0, "status": "done"}, {"code": "password=input()\na=b=c=0\nif len(password)>4:\n for i in password:\n if a==0 and (ord(i) in range(48,58)): a=1\n if b==0 and (ord(i) in range(65,91)): b=1\n if c==0 and (ord(i) in range(97,123)): c=1\n if a+b+c>2:\n print('Correct')\n return\nprint ('Too weak')\n\n", "passed": true, "time": 0.15, "memory": 14388.0, "status": "done"}, {"code": "s = input().strip()\nalp = set([chr(i) for i in range(ord('a'), ord('z') + 1)])\nupper = set([chr(i) for i in range(ord('A'), ord('Z') + 1)])\nnum = set([str(i) for i in range(10)])\nif len(s) >= 5:\n s = set(list(s))\n if len(s & alp) > 0 and len(s & upper) > 0 and len(s & num) > 0:\n print('Correct')\n else:\n print('Too weak')\nelse:\n print('Too weak')", "passed": true, "time": 0.15, "memory": 14588.0, "status": "done"}] | [{"input": "abacaba\n", "output": "Too weak\n"}, {"input": "X12345\n", "output": "Too weak\n"}, {"input": "CONTEST_is_STARTED!!11\n", "output": "Correct\n"}, {"input": "1zA__\n", "output": "Correct\n"}, {"input": "1zA_\n", "output": "Too weak\n"}, {"input": "zA___\n", "output": "Too weak\n"}, {"input": "1A___\n", "output": "Too weak\n"}, {"input": "z1___\n", "output": "Too weak\n"}, {"input": "0\n", "output": "Too weak\n"}, {"input": "_\n", "output": "Too weak\n"}, {"input": "a\n", "output": "Too weak\n"}, {"input": "D\n", "output": "Too weak\n"}, {"input": "_\n", "output": "Too weak\n"}, {"input": "?\n", "output": "Too weak\n"}, {"input": "?\n", "output": "Too weak\n"}, {"input": "._,.!.,...?_,!.\n", "output": "Too weak\n"}, {"input": "!_?_,?,?.,.,_!!!.!,.__,?!!,_!,?_,!??,?!..._!?_,?_!,?_.,._,,_.,.\n", "output": "Too weak\n"}, {"input": "?..!.,,?,__.,...????_???__!,?...?.,,,,___!,.!,_,,_,??!_?_,!!?_!_??.?,.!!?_?_.,!\n", "output": "Too weak\n"}, {"input": "XZX\n", "output": "Too weak\n"}, {"input": "R\n", "output": "Too weak\n"}, {"input": "H.FZ\n", "output": "Too weak\n"}, {"input": "KSHMICWPK,LSBM_JVZ!IPDYDG_GOPCHXFJTKJBIFY,FPHMY,CB?PZEAG..,X,.GFHPIDBB,IQ?MZ\n", "output": "Too weak\n"}, {"input": "EFHI,,Y?HMMUI,,FJGAY?FYPBJQMYM!DZHLFCTFWT?JOPDW,S_!OR?ATT?RWFBMAAKUHIDMHSD?LCZQY!UD_CGYGBAIRDPICYS\n", "output": "Too weak\n"}, {"input": "T,NDMUYCCXH_L_FJHMCCAGX_XSCPGOUZSY?D?CNDSYRITYS,VAT!PJVKNTBMXGGRYKACLYU.RJQ_?UWKXYIDE_AE\n", "output": "Too weak\n"}, {"input": "y\n", "output": "Too weak\n"}, {"input": "qgw\n", "output": "Too weak\n"}, {"input": "g\n", "output": "Too weak\n"}, {"input": "loaray\n", "output": "Too weak\n"}, {"input": "d_iymyvxolmjayhwpedocopqwmy.oalrdg!_n?.lrxpamhygps?kkzxydsbcaihfs.j?eu!oszjsy.vzu?!vs.bprz_j\n", "output": "Too weak\n"}, {"input": "txguglvclyillwnono\n", "output": "Too weak\n"}, {"input": "FwX\n", "output": "Too weak\n"}, {"input": "Zi\n", "output": "Too weak\n"}, {"input": "PodE\n", "output": "Too weak\n"}, {"input": "SdoOuJ?nj_wJyf\n", "output": "Too weak\n"}, {"input": "MhnfZjsUyXYw?f?ubKA\n", "output": "Too weak\n"}, {"input": "CpWxDVzwHfYFfoXNtXMFuAZr\n", "output": "Too weak\n"}, {"input": "9.,0\n", "output": "Too weak\n"}, {"input": "5,8\n", "output": "Too weak\n"}, {"input": "7\n", "output": "Too weak\n"}, {"input": "34__39_02!,!,82!129!2!566\n", "output": "Too weak\n"}, {"input": "96156027.65935663!_87!,44,..7914_!0_1,.4!!62!.8350!17_282!!9.2584,!!7__51.526.7\n", "output": "Too weak\n"}, {"input": "90328_\n", "output": "Too weak\n"}, {"input": "B9\n", "output": "Too weak\n"}, {"input": "P1H\n", "output": "Too weak\n"}, {"input": "J2\n", "output": "Too weak\n"}, {"input": "M6BCAKW!85OSYX1D?.53KDXP42F\n", "output": "Too weak\n"}, {"input": "C672F429Y8X6XU7S,.K9111UD3232YXT81S4!729ER7DZ.J7U1R_7VG6.FQO,LDH\n", "output": "Too weak\n"}, {"input": "W2PI__!.O91H8OFY6AB__R30L9XOU8800?ZUD84L5KT99818NFNE35V.8LJJ5P2MM.B6B\n", "output": "Too weak\n"}, {"input": "z1\n", "output": "Too weak\n"}, {"input": "p1j\n", "output": "Too weak\n"}, {"input": "j9\n", "output": "Too weak\n"}, {"input": "v8eycoylzv0qkix5mfs_nhkn6k!?ovrk9!b69zy!4frc?k\n", "output": "Too weak\n"}, {"input": "l4!m_44kpw8.jg!?oh,?y5oraw1tg7_x1.osl0!ny?_aihzhtt0e2!mr92tnk0es!1f,9he40_usa6c50l\n", "output": "Too weak\n"}, {"input": "d4r!ak.igzhnu!boghwd6jl\n", "output": "Too weak\n"}, {"input": "It0\n", "output": "Too weak\n"}, {"input": "Yb1x\n", "output": "Too weak\n"}, {"input": "Qf7\n", "output": "Too weak\n"}, {"input": "Vu7jQU8.!FvHBYTsDp6AphaGfnEmySP9te\n", "output": "Correct\n"}, {"input": "Ka4hGE,vkvNQbNolnfwp\n", "output": "Correct\n"}, {"input": "Ee9oluD?amNItsjeQVtOjwj4w_ALCRh7F3eaZah\n", "output": "Correct\n"}, {"input": "Um3Fj?QLhNuRE_Gx0cjMLOkGCm\n", "output": "Correct\n"}, {"input": "Oq2LYmV9HmlaW\n", "output": "Correct\n"}, {"input": "Cq7r3Wrb.lDb_0wsf7!ruUUGSf08RkxD?VsBEDdyE?SHK73TFFy0f8gmcATqGafgTv8OOg8or2HyMPIPiQ2Hsx8q5rn3_WZe\n", "output": "Correct\n"}, {"input": "Wx4p1fOrEMDlQpTlIx0p.1cnFD7BnX2K8?_dNLh4cQBx_Zqsv83BnL5hGKNcBE9g3QB,!fmSvgBeQ_qiH7\n", "output": "Correct\n"}, {"input": "k673,\n", "output": "Too weak\n"}, {"input": "LzuYQ\n", "output": "Too weak\n"}, {"input": "Pasq!\n", "output": "Too weak\n"}, {"input": "x5hve\n", "output": "Too weak\n"}, {"input": "b27fk\n", "output": "Too weak\n"}, {"input": "h6y1l\n", "output": "Too weak\n"}, {"input": "i9nij\n", "output": "Too weak\n"}, {"input": "Gf5Q6\n", "output": "Correct\n"}, {"input": "Uf24o\n", "output": "Correct\n"}, {"input": "Oj9vu\n", "output": "Correct\n"}, {"input": "c7jqaudcqmv8o7zvb5x_gp6zcgl6nwr7tz5or!28.tj8s1m2.wxz5a4id03!rq07?662vy.7.p5?vk2f2mc7ag8q3861rgd0rmbr\n", "output": "Too weak\n"}, {"input": "i6a.,8jb,n0kv4.1!7h?p.96pnhhgy6cl7dg7e4o6o384ys3z.t71kkq,,w,oqi4?u,,m5!rzu6wym_4hm,ohjy!.vvksl?pt,,1\n", "output": "Too weak\n"}, {"input": "M10V_MN_1K8YX2LA!89EYV7!5V9?,.IDHDP6JEC.OGLY.180LMZ6KW3Z5E17IT94ZNHS!79GN09Q6LH0,F3AYNKP?KM,QP_?XRD6\n", "output": "Too weak\n"}, {"input": "Hi7zYuVXCPhaho68YgCMzzgLILM6toQTJq8akMqqrnUn6ZCD36iA1yVVpvlsIiMpCu!1QZd4ycIrQ5Kcrhk5k0jTrwdAAEEP_T2f\n", "output": "Correct\n"}, {"input": "Bk2Q38vDSW5JqYu.077iYC.9YoiPc!Dh6FJWOVze6?YXiFjPNa4F1RG?154m9mY2jQobBnbxM,cDV8l1UX1?v?p.tTYIyJO!NYmE\n", "output": "Correct\n"}, {"input": "Ro1HcZ.piN,JRR88DLh,WtW!pbFM076?wCSbqfK7N2s5zUySFBtzk7HV,BxHXR0zALAr016z5jvvB.WUdEcKgYFav5TygwHQC..C\n", "output": "Correct\n"}, {"input": "!?.,_\n", "output": "Too weak\n"}] |
|
172 | In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic performance of each student is known — integer value between 1 and 5.
The school director wants to redistribute students between groups so that each of the two groups has the same number of students whose academic performance is equal to 1, the same number of students whose academic performance is 2 and so on. In other words, the purpose of the school director is to change the composition of groups, so that for each value of academic performance the numbers of students in both groups are equal.
To achieve this, there is a plan to produce a series of exchanges of students between groups. During the single exchange the director selects one student from the class A and one student of class B. After that, they both change their groups.
Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance.
-----Input-----
The first line of the input contains integer number n (1 ≤ n ≤ 100) — number of students in both groups.
The second line contains sequence of integer numbers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 5), where a_{i} is academic performance of the i-th student of the group A.
The third line contains sequence of integer numbers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ 5), where b_{i} is academic performance of the i-th student of the group B.
-----Output-----
Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained.
-----Examples-----
Input
4
5 4 4 4
5 5 4 5
Output
1
Input
6
1 1 1 1 1 1
5 5 5 5 5 5
Output
3
Input
1
5
3
Output
-1
Input
9
3 2 5 5 2 3 3 3 2
4 1 4 1 1 2 4 4 1
Output
4 | interview | [{"code": "n = int(input())\nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\na = [0] * 5\nb = [0] * 5\nfor j in range(n):\n a[A[j]-1] += 1\n b[B[j]-1] +=1\nper = 0\nfor j in range(5):\n if (a[j] + b[j]) % 2 == 1:\n per = 1\n break\nif per == 1:\n print(-1)\nelse:\n ans = 0\n for j in range(5):\n if a[j] > b[j]:\n ans += (a[j] - b[j])//2\n print(ans)", "passed": true, "time": 0.16, "memory": 14668.0, "status": "done"}, {"code": "n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\ns=0\nfor i in range(1,6):\n x=a.count(i)\n y=b.count(i)\n if not (x+y)%2:s+=abs(x-y)//2\n else:print(-1);return()\nprint(s//2)\n\n", "passed": true, "time": 0.23, "memory": 14832.0, "status": "done"}, {"code": "import sys\nn = int(input())\ng1 = list(map(int, input().split()))\ng2 = list(map(int, input().split()))\nans = 0\nfor i in range(1, 6):\n n1 = g1.count(i)\n n2 = g2.count(i)\n if abs(n1 - n2) % 2 != 0:\n print(-1)\n return\n ans += abs(n1 -n2)//2\nprint(ans//2)\n", "passed": true, "time": 0.15, "memory": 14616.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\naa = [0 for i in range(5)]\nbb = [0 for i in range(5)]\ncc = [0 for i in range(5)]\nfor i in range(n):\n aa[a[i] - 1] += 1\n cc[a[i] - 1] += 1\nfor i in range(n):\n bb[b[i] - 1] += 1\n cc[b[i] - 1] += 1\nf = True\nfor i in range(5):\n if cc[i] % 2 != 0:\n f = False\n break\n else:\n cc[i] //= 2\nif not f:\n print(-1)\nelse:\n o = 0\n for i in range(5):\n o += abs(cc[i] - aa[i])\n print(o // 2)\n", "passed": true, "time": 0.23, "memory": 14544.0, "status": "done"}, {"code": "def main():\n n = int(input())\n a = list(map(int, input().split()))\n b = list(map(int, input().split()))\n\n count = [0] * 5\n balance = [0] * 5\n\n for e in a:\n count[e - 1] += 1\n balance[e - 1] += 1\n for e in b:\n count[e - 1] += 1\n balance[e - 1] -= 1\n\n for e in count:\n if e % 2 != 0:\n print(-1)\n return\n print(sum([abs(i) for i in balance]) // 4)\n\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14620.0, "status": "done"}, {"code": "n = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\ncnt = [0] * 5\nfor elem in A:\n cnt[elem - 1] += 1\nfor elem in B:\n cnt[elem - 1] += 1\nbad = 0\nfor elem in cnt:\n bad += elem % 2\nif bad != 0:\n print(-1)\nelse:\n cntA = [0] * 5\n cntB = [0] * 5\n for elem in A:\n cntA[elem - 1] += 1\n for elem in B:\n cntB[elem - 1] += 1\n ans = 0\n for i in range(5):\n ans += abs(cntA[i] - cntB[i]) // 2\n print(ans // 2)\n", "passed": true, "time": 0.15, "memory": 14652.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nax = [0, 0, 0, 0, 0, 0]\nbx = [0, 0, 0, 0, 0, 0]\nfor i in range(n):\n ax[a[i]] += 1\n bx[b[i]] += 1\nans = 0\nfor i in range(6):\n if (ax[i] + bx[i]) % 2 == 1:\n ans = -1\n break\n else:\n ans += abs((ax[i] - bx[i]) // 2)\nprint(ans // 2)", "passed": true, "time": 0.15, "memory": 14896.0, "status": "done"}, {"code": "from sys import stdin\nfrom collections import defaultdict\n\nn = int(input())\na = [int(x) for x in input().split()]\nb = [int(x) for x in input().split()]\na_d = defaultdict(int)\nb_d = defaultdict(int)\nfor i in range(n):\n a_d[a[i]] += 1\n b_d[b[i]] += 1\nf = True\nans = 0\nfor i in range(6):\n if (a_d[i] + b_d[i]) % 2:\n f = False\n break\n ans += abs(a_d[i] - b_d[i])\nif f:\n print(ans//4)\nelse:\n print(-1)", "passed": true, "time": 0.24, "memory": 14652.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\na1 = [0] * 6\nb1 = [0] * 6\nfor i in a:\n a1[i] += 1\nfor i in b:\n b1[i] += 1\nans = 0\nfor i in range(1, 6):\n if (a1[i] + b1[i]) % 2 != 0:\n ans = -1\n break\n ans += (max(a1[i], b1[i]) - min(a1[i], b1[i])) // 2\nif ans == -1:\n print(-1)\nelse:\n print(ans // 2)\n", "passed": true, "time": 0.19, "memory": 14748.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nq = [0] * 6\n\nfor i in a:\n q[i] += 1\nfor i in b:\n q[i] += 1\n\nf = True\nfor i in q:\n if i % 2 != 0:\n f = False\nif not f:\n print(-1)\nelse:\n for i in range(6):\n q[i] //= 2\n aa = [0] * 6\n bb = [0] * 6\n for i in a:\n aa[i] += 1\n for i in b:\n bb[i] += 1\n ans = 0\n for i in range(6):\n ans += abs(q[i] - aa[i])\n print(ans // 2)\n\n", "passed": true, "time": 0.22, "memory": 14800.0, "status": "done"}, {"code": "from collections import Counter\n\nbad = False\n\nn = int(input())\n\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\n\ncounts_a = Counter(A)\ncounts_b = Counter(B)\ncounts_total = Counter(A+B)\n\nswaps = 0\n\nfor i in range(1,6):\n if counts_total[i] % 2 != 0:\n bad = True\n\n swaps += max(counts_a[i], counts_b[i]) - counts_total[i]//2\n\nif bad:\n print(-1)\nelse:\n print(swaps//2)\n", "passed": true, "time": 0.22, "memory": 14768.0, "status": "done"}, {"code": "#CF402\nn=int(input())\na=list(sorted(map(int,input().split())))\nb=list(sorted(map(int,input().split())))\ns=[]\nei=0\nfor i in range(5):\n t=[a.count(i+1),b.count(i+1)]\n s.append(t[0]-t[1])\n if sum(t)%2==1:ei=1\nif bool(ei):print(-1)\nelse:print(int(sum([x for x in s if x>0])/2))\n", "passed": true, "time": 0.23, "memory": 14616.0, "status": "done"}, {"code": "n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nif (a.count(1)+b.count(1))%2!=0 or (a.count(2)+b.count(2))%2!=0 or (a.count(3)+b.count(3))%2!=0 or (a.count(4)+b.count(4))%2!=0 or (a.count(5)+b.count(5))%2!=0:\n print(-1)\nelse:\n k=0\n k+=abs(a.count(1)-b.count(1))//2\n k+=abs(a.count(2)-b.count(2))//2\n k+=abs(a.count(3)-b.count(3))//2\n k+=abs(a.count(4)-b.count(4))//2\n k+=abs(a.count(5)-b.count(5))//2\n print(k//2)", "passed": true, "time": 0.14, "memory": 14672.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\n\nc = [0,0,0,0,0]\nd = [0,0,0,0,0]\nfor x in range(0,n):\n\tc[a[x]-1] = c[a[x]-1] + 1\n\td[b[x]-1] = d[b[x]-1] + 1\n\ndef dingle():\n\tfor x in range(0,5):\n\t\tif (c[x] + d[x])%2 != 0:\n\t\t\treturn -1\n\n\tf = 0\n\tfor x in range(0,5):\n\t\tf = f + abs((c[x]-d[x])//2)\n\treturn(f//2)\n\nprint(dingle())\n", "passed": true, "time": 0.15, "memory": 14644.0, "status": "done"}, {"code": "from sys import stdin, stdout\n\nn = int(stdin.readline())\n\nA = stdin.readline().rstrip().split()\nA = [int(num) for num in A]\n\nB = stdin.readline().rstrip().split()\nB = [int(num) for num in B]\n\npossible=True\ntotSwaps=0\nfor i in range(1,6):\n if (A.count(i)+B.count(i))%2==0:\n totSwaps+=int((A.count(i)+B.count(i))/2)-min([A.count(i),B.count(i)])\n else:\n possible=False\n break\n \nif not possible:\n print(-1)\nelse:\n print(int(totSwaps/2))\n \n\n", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nca = [0, 0, 0, 0, 0]\ncb = [0, 0, 0, 0, 0]\n\nfor i in a:\n ca[i - 1] += 1\n\nfor i in b:\n cb[i - 1] += 1\n\nc = 0\nfor i in range(5):\n if (ca[i] + cb[i]) % 2 == 0:\n c += (max(ca[i], cb[i]) - min(ca[i], cb[i])) // 2\n else:\n print(-1)\n return\nprint(c//2)\n", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "from collections import defaultdict\n\nn = int(input())\naa = list(map(int, input().split()))\nbb = list(map(int, input().split()))\n\nq = defaultdict(int)\nw = defaultdict(int)\ne = defaultdict(int)\n\nfor a in aa:\n q[a] += 1\n e[a] += 1\n\nfor b in bb:\n w[b] += 1\n e[b] += 1\n\nans = 0\nfor i in range(1, 6):\n if e[i] % 2 != 0:\n ans = -1\n break\n ans += abs(q[i] - (e[i] // 2))\n\nprint(ans // 2)\n", "passed": true, "time": 0.14, "memory": 14704.0, "status": "done"}, {"code": "import math, sys\ndef main():\n\tn = int(input())\n\ta = list(map(int, input().split()))\n\tb = list(map(int, input().split()))\n\ta5 = 0\n\ta4 = 0\n\ta3 = 0\n\ta2 = 0\n\ta1 = 0\n\tb5 = 0\n\tb4 = 0\n\tb3 = 0\n\tb2 = 0\n\tb1 = 0\n\tans = 0\n\tfor i in a:\n\t\tif i==5:\n\t\t\ta5+=1\n\t\tif i==4:\n\t\t\ta4+=1\n\t\tif i==3:\n\t\t\ta3+=1\n\t\tif i==2:\n\t\t\ta2+=1\n\t\tif i==1:\n\t\t\ta1+=1\n\tfor i in b:\n\t\tif i==5:\n\t\t\tb5+=1\n\t\tif i==4:\n\t\t\tb4+=1\n\t\tif i==3:\n\t\t\tb3+=1\n\t\tif i==2:\n\t\t\tb2+=1\n\t\tif i==1:\n\t\t\tb1+=1\n\tif (a5+b5)%2==0 and (a4+b4)%2==0 and (a3+b3)%2==0 and (a2+b2)%2==0 and (a1+b1)%2==0:\n\t\tans += max(a5,b5) - (a5+b5)//2\n\t\tans += max(a4,b4) - (a4+b4)//2\n\t\tans += max(a3,b3) - (a3+b3)//2\n\t\tans += max(a2,b2) - (a2+b2)//2\n\t\tans += max(a1,b1) - (a1+b1)//2 \n\t\tprint(ans//2)\n\t\treturn\n\t\n\tprint(-1)\ndef __starting_point():\n\tmain()\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14576.0, "status": "done"}, {"code": "n = int(input())\nA = list(map(int, input().split()))\na = [0] * 6\nB = list(map(int, input().split()))\nb = [0] * 6\nfor i in A:\n if i == 1:\n a[1] += 1\n if i == 2:\n a[2] += 1\n if i == 3:\n a[3] += 1 \n if i == 4:\n a[4] += 1\n if i == 5:\n a[5] += 1 \nfor i in B:\n if i == 1:\n b[1] += 1\n if i == 2:\n b[2] += 1\n if i == 3:\n b[3] += 1 \n if i == 4:\n b[4] += 1\n if i == 5:\n b[5] += 1\n\nans = 0\nf = True\nfor i in range(1, 6):\n if (a[i] + b[i]) % 2 == 1:\n f = False\nif f:\n for i in range(1, 6):\n ans += abs(a[i] - (a[i] + b[i]) // 2)\nif f:\n print(ans // 2)\nelse:\n print(-1)", "passed": true, "time": 0.14, "memory": 14596.0, "status": "done"}, {"code": "from collections import Counter\n\n\nN = int(input())\nA = list(map(int, input().strip().split()))\nB = list(map(int, input().strip().split()))\n\na = Counter(A)\nb = Counter(B)\n\ncnt = 0\naa = 0\nbb = 0\nflag = False\nfor i in range(1,6):\n diff = a[i]-b[i]\n if diff % 2 == 1:\n flag = True\n break\n if diff > 0:\n aa += diff // 2\n else:\n bb += -diff // 2\n\nif flag:\n print(-1)\nelse:\n if (aa == bb):\n print(aa)\n else:\n print(-1)\n\n", "passed": true, "time": 0.14, "memory": 14764.0, "status": "done"}, {"code": "def f():\n n=int(input())\n a=[0]*5\n b=[0]*5\n\n X = [int(x) for x in input().split()]\n for x in X:\n a[x-1]+=1\n\n X = [int(x) for x in input().split()]\n for x in X:\n b[x-1]+=1\n\n for i in range(5):\n if (a[i]+b[i])%2==1:\n print('-1')\n return\n\n x=0\n for i in range(5):\n x += abs(a[i]-b[i])/2\n\n print(int(x/2))\n\nf()\n", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "def LI(): return list(map(int, input().split()))\ndef II(): return int(input())\ndef LS(): return input().split()\ndef S(): return input()\n\n\ndef check(li1, li2):\n result = 0\n for i in range(5):\n result += ((max(li1[i],li2[i])-min(li1[i],li2[i]))/2)\n if (li1[i]+li2[i])%2 != 0:\n print(-1)\n return\n print(int(result/2))\n return\n\n\nli1 = [0, 0, 0, 0, 0]\nli2 = [0, 0, 0, 0, 0]\nn = II()\n\nll1 = LI()\nll2 = LI()\nfor i in range(n):\n li1[ll1[i]-1] += 1\n li2[ll2[i]-1] += 1\n# print(li1, li2)\n\ncheck(li1, li2)", "passed": true, "time": 0.14, "memory": 14604.0, "status": "done"}, {"code": "\n\nn = int(input())\n\nA = [0]*5\nB = [0]*5\n\nfor a in map(int, input().split()):\n A[a - 1] += 1\n\nfor a in map(int, input().split()):\n B[a - 1] += 1\n\n\nif any([(x + y) % 2 != 0 for x, y in zip(A, B)]):\n print(-1)\nelse:\n print(sum([abs(x - y) // 2 for x, y in zip(A, B)]) // 2)\n\n", "passed": true, "time": 0.14, "memory": 14700.0, "status": "done"}, {"code": "from collections import Counter\n\nn = int(input().strip())\nca = Counter([int(x) for x in input().strip().split(' ')])\ncb = Counter([int(x) for x in input().strip().split(' ')])\ncnt = 0\n\nfor i in range(1, 6):\n if (ca[i] + cb[i]) % 2 != 0:\n print(-1)\n return\n else:\n cnt += abs(ca[i] - (ca[i] + cb[i]) / 2)\nprint(int(cnt/2))\n", "passed": true, "time": 0.15, "memory": 14556.0, "status": "done"}] | [{"input": "4\n5 4 4 4\n5 5 4 5\n", "output": "1\n"}, {"input": "6\n1 1 1 1 1 1\n5 5 5 5 5 5\n", "output": "3\n"}, {"input": "1\n5\n3\n", "output": "-1\n"}, {"input": "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n", "output": "4\n"}, {"input": "1\n1\n2\n", "output": "-1\n"}, {"input": "1\n1\n1\n", "output": "0\n"}, {"input": "8\n1 1 2 2 3 3 4 4\n4 4 5 5 1 1 1 1\n", "output": "2\n"}, {"input": "10\n1 1 1 1 1 1 1 1 1 1\n2 2 2 2 2 2 2 2 2 2\n", "output": "5\n"}, {"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\n", "output": "0\n"}, {"input": "2\n1 1\n1 1\n", "output": "0\n"}, {"input": "2\n1 2\n1 1\n", "output": "-1\n"}, {"input": "2\n2 2\n1 1\n", "output": "1\n"}, {"input": "2\n1 2\n2 1\n", "output": "0\n"}, {"input": "2\n1 1\n2 2\n", "output": "1\n"}, {"input": "5\n5 5 5 5 5\n5 5 5 5 5\n", "output": "0\n"}, {"input": "5\n5 5 5 3 5\n5 3 5 5 5\n", "output": "0\n"}, {"input": "5\n2 3 2 3 3\n2 3 2 2 2\n", "output": "1\n"}, {"input": "5\n4 4 1 4 2\n1 2 4 2 2\n", "output": "1\n"}, {"input": "50\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n", "output": "0\n"}, {"input": "50\n1 3 1 3 3 3 1 3 3 3 3 1 1 1 3 3 3 1 3 1 1 1 3 1 3 1 3 3 3 1 3 1 1 3 3 3 1 1 1 1 3 3 1 1 1 3 3 1 1 1\n1 3 1 3 3 1 1 3 1 3 3 1 1 1 1 3 3 1 3 1 1 3 1 1 3 1 1 1 1 3 3 1 3 3 3 3 1 3 3 3 3 3 1 1 3 3 1 1 3 1\n", "output": "0\n"}, {"input": "50\n1 1 1 4 1 1 4 1 4 1 1 4 1 1 4 1 1 4 1 1 4 1 4 4 4 1 1 4 1 4 4 4 4 4 4 4 1 4 1 1 1 1 4 1 4 4 1 1 1 4\n1 4 4 1 1 4 1 4 4 1 1 4 1 4 1 1 4 1 1 1 4 4 1 1 4 1 4 1 1 4 4 4 4 1 1 4 4 1 1 1 4 1 4 1 4 1 1 1 4 4\n", "output": "0\n"}, {"input": "50\n3 5 1 3 3 4 3 4 2 5 2 1 2 2 5 5 4 5 4 2 1 3 4 2 3 3 3 2 4 3 5 5 5 5 5 5 2 5 2 2 5 4 4 1 5 3 4 2 1 3\n3 5 3 2 5 3 4 4 5 2 3 4 4 4 2 2 4 4 4 3 3 5 5 4 3 1 4 4 5 5 4 1 2 5 5 4 1 2 3 4 5 5 3 2 3 4 3 5 1 1\n", "output": "3\n"}, {"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\n", "output": "0\n"}, {"input": "100\n1 1 3 1 3 1 1 3 1 1 3 1 3 1 1 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 1 1 1 3 1 1 1 3 1 1 3 3 1 3 3 1 3 1 3 3 3 3 1 1 3 3 3 1 1 3 1 3 3 3 1 3 3 3 3 3 1 3 3 3 3 1 3 1 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 1 1 3 1 1 1\n1 1 1 3 3 3 3 3 3 3 1 3 3 3 1 3 3 3 3 3 3 1 3 3 1 3 3 1 1 1 3 3 3 3 3 3 3 1 1 3 3 3 1 1 3 3 1 1 1 3 3 3 1 1 3 1 1 3 3 1 1 3 3 3 3 3 3 1 3 3 3 1 1 3 3 3 1 1 3 3 1 3 1 3 3 1 1 3 3 1 1 3 1 3 3 3 1 3 1 3\n", "output": "0\n"}, {"input": "100\n2 4 5 2 5 5 4 4 5 4 4 5 2 5 5 4 5 2 5 2 2 4 5 4 4 4 2 4 2 2 4 2 4 2 2 2 4 5 5 5 4 2 4 5 4 4 2 5 4 2 5 4 5 4 5 4 5 5 5 4 2 2 4 5 2 5 5 2 5 2 4 4 4 5 5 2 2 2 4 4 2 2 2 5 5 2 2 4 5 4 2 4 4 2 5 2 4 4 4 4\n4 4 2 5 2 2 4 2 5 2 5 4 4 5 2 4 5 4 5 2 2 2 2 5 4 5 2 4 2 2 5 2 5 2 4 5 5 5 2 5 4 4 4 4 5 2 2 4 2 4 2 4 5 5 5 4 5 4 5 5 5 2 5 4 4 4 4 4 2 5 5 4 2 4 4 5 5 2 4 4 4 2 2 2 5 4 2 2 4 5 4 4 4 4 2 2 4 5 5 2\n", "output": "0\n"}, {"input": "100\n3 3 4 3 3 4 3 1 4 2 1 3 1 1 2 4 4 4 4 1 1 4 1 4 4 1 1 2 3 3 3 2 4 2 3 3 3 1 3 4 2 2 1 3 4 4 3 2 2 2 4 2 1 2 1 2 2 1 1 4 2 1 3 2 4 4 4 2 3 1 3 1 3 2 2 2 2 4 4 1 3 1 1 4 2 3 3 4 4 2 4 4 2 4 3 3 1 3 2 4\n3 1 4 4 2 1 1 1 1 1 1 3 1 1 3 4 3 2 2 4 2 1 4 4 4 4 1 2 3 4 2 3 3 4 3 3 2 4 2 2 2 1 2 4 4 4 2 1 3 4 3 3 4 2 4 4 3 2 4 2 4 2 4 4 1 4 3 1 4 3 3 3 3 1 2 2 2 2 4 1 2 1 3 4 3 1 3 3 4 2 3 3 2 1 3 4 2 1 1 2\n", "output": "0\n"}, {"input": "100\n2 4 5 2 1 5 5 2 1 5 1 5 1 1 1 3 4 5 1 1 2 3 3 1 5 5 4 4 4 1 1 1 5 2 3 5 1 2 2 1 1 1 2 2 1 2 4 4 5 1 3 2 5 3 5 5 3 2 2 2 1 3 4 4 4 4 4 5 3 1 4 1 5 4 4 5 4 5 2 4 4 3 1 2 1 4 5 3 3 3 3 2 2 2 3 5 3 1 3 4\n3 2 5 1 5 4 4 3 5 5 5 2 1 4 4 3 2 3 3 5 5 4 5 5 2 1 2 4 4 3 5 1 1 5 1 3 2 5 2 4 4 2 4 2 4 2 3 2 5 1 4 4 1 1 1 5 3 5 1 1 4 5 1 1 2 2 5 3 5 1 1 1 2 3 3 2 3 2 4 4 5 4 2 1 3 4 1 1 2 4 1 5 3 1 2 1 3 4 1 3\n", "output": "0\n"}, {"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\n", "output": "0\n"}, {"input": "100\n1 4 4 1 4 4 1 1 4 1 1 1 1 4 4 4 4 1 1 1 1 1 1 4 4 4 1 1 4 4 1 1 1 1 4 4 4 4 4 1 1 4 4 1 1 1 4 1 1 1 1 4 4 4 4 4 4 1 4 4 4 4 1 1 1 4 1 4 1 1 1 1 4 1 1 1 4 4 4 1 4 4 1 4 4 4 4 4 1 4 1 1 4 1 4 1 1 1 4 4\n4 1 1 4 4 4 1 4 4 4 1 1 4 1 1 4 1 4 4 4 1 1 4 1 4 1 1 1 4 4 1 4 1 4 1 4 4 1 1 4 1 4 1 1 1 4 1 4 4 4 1 4 1 4 4 4 4 1 4 1 1 4 1 1 4 4 4 1 4 1 4 1 4 4 4 1 1 4 1 4 4 4 4 1 1 1 1 1 4 4 1 4 1 4 1 1 1 4 4 1\n", "output": "1\n"}, {"input": "100\n5 2 5 2 2 3 3 2 5 3 2 5 3 3 3 5 2 2 5 5 3 3 5 3 2 2 2 3 2 2 2 2 3 5 3 3 2 3 2 5 3 3 5 3 2 2 5 5 5 5 5 2 3 2 2 2 2 3 2 5 2 2 2 3 5 5 5 3 2 2 2 3 5 3 2 5 5 3 5 5 5 3 2 5 2 3 5 3 2 5 5 3 5 2 3 3 2 2 2 2\n5 3 5 3 3 5 2 5 3 2 3 3 5 2 5 2 2 5 2 5 2 5 3 3 5 3 2 2 2 3 5 3 2 2 3 2 2 5 5 2 3 2 3 3 5 3 2 5 2 2 2 3 3 5 3 3 5 2 2 2 3 3 2 2 3 5 3 5 5 3 3 2 5 3 5 2 3 2 5 5 3 2 5 5 2 2 2 2 3 2 2 5 2 5 2 2 3 3 2 5\n", "output": "1\n"}, {"input": "100\n4 4 5 4 3 5 5 2 4 5 5 5 3 4 4 2 5 2 5 3 3 3 3 5 3 2 2 2 4 4 4 4 3 3 4 5 3 2 2 2 4 4 5 3 4 5 4 5 5 2 4 2 5 2 3 4 4 5 2 2 4 4 5 5 5 3 5 4 5 5 5 4 3 3 2 4 3 5 5 5 2 4 2 5 4 3 5 3 2 3 5 2 5 2 2 5 4 5 4 3\n5 4 2 4 3 5 2 5 5 3 4 5 4 5 3 3 5 5 2 3 4 2 3 5 2 2 2 4 2 5 2 4 4 5 2 2 4 4 5 5 2 3 4 2 4 5 2 5 2 2 4 5 5 3 5 5 5 4 3 4 4 3 5 5 3 4 5 3 2 3 4 3 4 4 2 5 3 4 5 5 3 5 3 3 4 3 5 3 2 2 4 5 4 5 5 2 3 4 3 5\n", "output": "1\n"}, {"input": "100\n1 4 2 2 2 1 4 5 5 5 4 4 5 5 1 3 2 1 4 5 2 3 4 4 5 4 4 4 4 5 1 3 5 5 3 3 3 3 5 1 4 3 5 1 2 4 1 3 5 5 1 3 3 3 1 3 5 4 4 2 2 5 5 5 2 3 2 5 1 3 5 4 5 3 2 2 3 2 3 3 2 5 2 4 2 3 4 1 3 1 3 1 5 1 5 2 3 5 4 5\n1 2 5 3 2 3 4 2 5 1 2 5 3 4 3 3 4 1 5 5 1 3 3 1 1 4 1 4 2 5 4 1 3 4 5 3 2 2 1 4 5 5 2 3 3 5 5 4 2 3 3 5 3 3 5 4 4 5 3 5 1 1 4 4 4 1 3 5 5 5 4 2 4 5 3 2 2 2 5 5 5 1 4 3 1 3 1 2 2 4 5 1 3 2 4 5 1 5 2 5\n", "output": "1\n"}, {"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n", "output": "0\n"}, {"input": "100\n5 2 2 2 5 2 5 5 5 2 5 2 5 5 5 5 5 5 2 2 2 5 5 2 5 2 2 5 2 5 5 2 5 2 5 2 5 5 5 5 5 2 2 2 2 5 5 2 5 5 5 2 5 5 5 2 5 5 5 2 2 2 5 2 2 2 5 5 2 5 5 5 2 5 2 2 5 2 2 2 5 5 5 5 2 5 2 5 2 2 5 2 5 2 2 2 2 5 5 2\n5 5 2 2 5 5 2 5 2 2 5 5 5 5 2 5 5 2 5 2 2 5 2 2 5 2 5 2 2 5 2 5 2 5 5 2 2 5 5 5 2 5 5 2 5 5 5 2 2 5 5 5 2 5 5 5 2 2 2 5 5 5 2 2 5 5 2 2 2 5 2 5 5 2 5 2 5 2 2 5 5 2 2 5 5 2 2 5 2 2 5 2 2 2 5 5 2 2 2 5\n", "output": "1\n"}, {"input": "100\n3 3 2 2 1 2 3 3 2 2 1 1 3 3 1 1 1 2 1 2 3 2 3 3 3 1 2 3 1 2 1 2 3 3 2 1 1 1 1 1 2 2 3 2 1 1 3 3 1 3 3 1 3 1 3 3 3 2 1 2 3 1 3 2 2 2 2 2 2 3 1 3 1 2 2 1 2 3 2 3 3 1 2 1 1 3 1 1 1 2 1 2 2 2 3 2 3 2 1 1\n1 3 1 2 1 1 1 1 1 2 1 2 1 3 2 2 3 2 1 1 2 2 2 1 1 3 2 3 2 1 2 2 3 2 3 1 3 1 1 2 3 1 2 1 3 2 1 2 3 2 3 3 3 2 2 2 3 1 3 1 1 2 1 3 1 3 1 3 3 3 1 3 3 2 1 3 3 3 3 3 2 1 2 2 3 3 2 1 2 2 1 3 3 1 3 2 2 1 1 3\n", "output": "1\n"}, {"input": "100\n5 3 3 2 5 3 2 4 2 3 3 5 3 4 5 4 3 3 4 3 2 3 3 4 5 4 2 4 2 4 5 3 3 4 5 3 5 3 5 3 3 2 5 3 4 5 2 5 2 2 4 2 2 2 2 5 4 5 4 3 5 4 2 5 5 3 4 5 2 3 2 2 2 5 3 2 2 2 3 3 5 2 3 2 4 5 3 3 3 5 2 3 3 3 5 4 5 5 5 2\n4 4 4 5 5 3 5 5 4 3 5 4 3 4 3 3 5 3 5 5 3 3 3 5 5 4 4 3 2 5 4 3 3 4 5 3 5 2 4 2 2 2 5 3 5 2 5 5 3 3 2 3 3 4 2 5 2 5 2 4 2 4 2 3 3 4 2 2 2 4 4 3 3 3 4 3 3 3 5 5 3 4 2 2 3 5 5 2 3 4 5 4 5 3 4 2 5 3 2 4\n", "output": "3\n"}, {"input": "100\n5 3 4 4 2 5 1 1 4 4 3 5 5 1 4 4 2 5 3 2 1 1 3 2 4 4 4 2 5 2 2 3 1 4 1 4 4 5 3 5 1 4 1 4 1 5 5 3 5 5 1 5 3 5 1 3 3 4 5 3 2 2 4 5 2 5 4 2 4 4 1 1 4 2 4 1 2 2 4 3 4 1 1 1 4 3 5 1 2 1 4 5 4 4 2 1 4 1 3 2\n1 1 1 1 4 2 1 4 1 1 3 5 4 3 5 2 2 4 2 2 4 1 3 4 4 5 1 1 2 2 2 1 4 1 4 4 1 5 5 2 3 5 1 5 4 2 3 2 2 5 4 1 1 4 5 2 4 5 4 4 3 3 2 4 3 4 5 5 4 2 4 2 1 2 3 2 2 5 5 3 1 3 4 3 4 4 5 3 1 1 3 5 1 4 4 2 2 1 4 5\n", "output": "2\n"}, {"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n", "output": "0\n"}, {"input": "100\n3 3 4 3 3 4 3 3 4 4 3 3 3 4 3 4 3 4 4 3 3 3 3 3 3 4 3 3 4 3 3 3 3 4 3 3 3 4 4 4 3 3 4 4 4 3 4 4 3 3 4 3 3 3 4 4 4 3 4 3 3 3 3 3 3 3 4 4 3 3 3 3 4 3 3 3 3 3 4 4 3 3 3 3 3 4 3 4 4 4 4 3 4 3 4 4 4 4 3 3\n4 3 3 3 3 4 4 3 4 4 4 3 3 4 4 3 4 4 4 4 3 4 3 3 3 4 4 4 3 4 3 4 4 3 3 4 3 3 3 3 3 4 3 3 3 3 4 4 4 3 3 4 3 4 4 4 4 3 4 4 3 3 4 3 3 4 3 4 3 4 4 4 4 3 3 4 3 4 4 4 3 3 4 4 4 4 4 3 3 3 4 3 3 4 3 3 3 3 3 3\n", "output": "5\n"}, {"input": "100\n4 2 5 2 5 4 2 5 5 4 4 2 4 4 2 4 4 5 2 5 5 2 2 4 4 5 4 5 5 5 2 2 2 2 4 4 5 2 4 4 4 2 2 5 5 4 5 4 4 2 4 5 4 2 4 5 4 2 4 5 4 4 4 4 4 5 4 2 5 2 5 5 5 5 4 2 5 5 4 4 2 5 2 5 2 5 4 2 4 2 4 5 2 5 2 4 2 4 2 4\n5 4 5 4 5 2 2 4 5 2 5 5 5 5 5 4 4 4 4 5 4 5 5 2 4 4 4 4 5 2 4 4 5 5 2 5 2 5 5 4 4 5 2 5 2 5 2 5 4 5 2 5 2 5 2 4 4 5 4 2 5 5 4 2 2 2 5 4 2 2 4 4 4 5 5 2 5 2 2 4 4 4 2 5 4 5 2 2 5 4 4 5 5 4 5 5 4 5 2 5\n", "output": "5\n"}, {"input": "100\n3 4 5 3 5 4 5 4 4 4 2 4 5 4 3 2 3 4 3 5 2 5 2 5 4 3 4 2 5 2 5 3 4 5 2 5 4 2 4 5 4 3 2 4 4 5 2 5 5 3 3 5 2 4 4 2 3 3 2 5 5 5 2 4 5 5 4 2 2 5 3 3 2 4 4 2 4 5 5 2 5 5 3 2 5 2 4 4 3 3 5 4 5 5 2 5 4 5 4 3\n4 3 5 5 2 4 2 4 5 5 5 2 3 3 3 3 5 5 5 5 3 5 2 3 5 2 3 2 2 5 5 3 5 3 4 2 2 5 3 3 3 3 5 2 4 5 3 5 3 4 4 4 5 5 3 4 4 2 2 4 4 5 3 2 4 5 5 4 5 2 2 3 5 4 5 5 2 5 4 3 2 3 2 5 4 5 3 4 5 5 3 5 2 2 4 4 3 2 5 2\n", "output": "4\n"}, {"input": "100\n4 1 1 2 1 4 4 1 4 5 5 5 2 2 1 3 5 2 1 5 2 1 2 4 4 2 1 2 2 2 4 3 1 4 2 2 3 1 1 4 4 5 4 4 4 5 1 4 1 4 3 1 2 1 2 4 1 2 5 2 1 4 3 4 1 4 2 1 1 1 5 3 3 1 4 1 3 1 4 1 1 2 2 2 3 1 4 3 4 4 5 2 5 4 3 3 3 2 2 1\n5 1 4 4 3 4 4 5 2 3 3 4 4 2 3 2 3 1 3 1 1 4 1 5 4 3 2 4 3 3 3 2 3 4 1 5 4 2 4 2 2 2 5 3 1 2 5 3 2 2 1 1 2 2 3 5 1 2 5 3 2 1 1 2 1 2 4 3 5 4 5 3 2 4 1 3 4 1 4 4 5 4 4 5 4 2 5 3 4 1 4 2 4 2 4 5 4 5 4 2\n", "output": "6\n"}, {"input": "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\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "0\n"}, {"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n", "output": "0\n"}, {"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n", "output": "0\n"}, {"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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\n", "output": "1\n"}, {"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 4 3 3 3 3 3 3 3 3 3 3 1 3 1 3 3 3 3 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n3 3 3 4 3 3 3 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 1 3 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3\n", "output": "1\n"}, {"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "50\n"}, {"input": "100\n3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5\n3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1\n", "output": "25\n"}, {"input": "100\n3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5 3 5\n2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 2 4\n", "output": "50\n"}, {"input": "100\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 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\n", "output": "40\n"}, {"input": "100\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 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3\n", "output": "30\n"}, {"input": "5\n4 4 4 4 5\n4 5 5 5 5\n", "output": "-1\n"}, {"input": "4\n1 1 1 1\n3 3 3 3\n", "output": "2\n"}, {"input": "6\n1 1 2 2 3 4\n1 2 3 3 4 4\n", "output": "-1\n"}, {"input": "4\n1 1 1 2\n3 3 3 3\n", "output": "-1\n"}, {"input": "3\n2 2 2\n4 4 4\n", "output": "-1\n"}, {"input": "2\n1 2\n3 4\n", "output": "-1\n"}, {"input": "6\n1 1 1 3 3 3\n2 2 2 4 4 4\n", "output": "-1\n"}, {"input": "5\n1 2 2 2 2\n1 1 1 1 3\n", "output": "-1\n"}, {"input": "2\n1 3\n2 2\n", "output": "-1\n"}, {"input": "2\n1 3\n4 5\n", "output": "-1\n"}, {"input": "4\n1 2 3 4\n5 5 5 5\n", "output": "-1\n"}, {"input": "2\n1 3\n2 4\n", "output": "-1\n"}, {"input": "2\n1 2\n4 4\n", "output": "-1\n"}, {"input": "2\n1 2\n3 3\n", "output": "-1\n"}, {"input": "10\n4 4 4 4 2 3 3 3 3 1\n2 2 2 2 4 1 1 1 1 3\n", "output": "-1\n"}, {"input": "6\n1 2 3 3 4 4\n1 1 2 2 3 4\n", "output": "-1\n"}, {"input": "5\n3 3 3 3 1\n1 1 1 1 3\n", "output": "-1\n"}, {"input": "2\n1 1\n2 3\n", "output": "-1\n"}, {"input": "8\n1 1 2 2 3 3 3 3\n2 2 2 2 1 1 1 1\n", "output": "2\n"}, {"input": "5\n1 1 1 3 3\n1 1 1 1 2\n", "output": "-1\n"}, {"input": "6\n2 2 3 3 4 4\n2 3 4 5 5 5\n", "output": "-1\n"}, {"input": "6\n1 1 2 2 3 4\n3 3 4 4 1 2\n", "output": "-1\n"}, {"input": "4\n1 2 3 3\n3 3 3 3\n", "output": "-1\n"}, {"input": "3\n1 2 3\n3 3 3\n", "output": "-1\n"}, {"input": "5\n3 3 3 2 2\n2 2 2 3 3\n", "output": "-1\n"}, {"input": "10\n1 2 3 4 1 2 3 4 1 2\n1 2 3 4 1 2 3 4 3 4\n", "output": "-1\n"}, {"input": "2\n2 2\n1 3\n", "output": "-1\n"}, {"input": "3\n1 2 3\n1 1 4\n", "output": "-1\n"}, {"input": "4\n3 4 4 4\n3 3 4 4\n", "output": "-1\n"}] |
|
173 | Imagine a city with n horizontal streets crossing m vertical streets, forming an (n - 1) × (m - 1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.
[Image]
The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.
-----Input-----
The first line of input contains two integers n and m, (2 ≤ n, m ≤ 20), denoting the number of horizontal streets and the number of vertical streets.
The second line contains a string of length n, made of characters '<' and '>', denoting direction of each horizontal street. If the i-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south.
The third line contains a string of length m, made of characters '^' and 'v', denoting direction of each vertical street. If the i-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.
-----Output-----
If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".
-----Examples-----
Input
3 3
><>
v^v
Output
NO
Input
4 6
<><>
v^v^v^
Output
YES
-----Note-----
The figure above shows street directions in the second sample test case. | interview | [{"code": "a, b = list(map(int, input().split(' ')))\nhor = input()\nver = input()\nif (hor[0], ver[0]) == ('>', 'v') or (hor[0], ver[-1]) == ('<', 'v'):\n print(\"NO\")\nelif (hor[-1], ver[0]) == ('>', '^') or (hor[-1], ver[-1]) == ('<', '^'):\n print(\"NO\")\nelse:\n print(\"YES\")\n", "passed": true, "time": 0.16, "memory": 14604.0, "status": "done"}, {"code": "h, w = map(int, input().split())\ngo = [[[] for x in range(w)] for y in range(h)]\ns = input()\nfor i in range(h):\n if s[i] == '>':\n for j in range(w - 1):\n go[i][j].append((i, j + 1))\n else:\n for j in range(1, w):\n go[i][j].append((i, j - 1))\ns = input()\nfor i in range(w):\n if s[i] == '^':\n for j in range(1, h):\n go[j][i].append((j - 1, i))\n else:\n for j in range(h - 1):\n go[j][i].append((j + 1, i))\n\ngood = True\nfor i in range(h):\n for j in range(w):\n u = [[False for x in range(w)] for y in range(h)]\n u[i][j] = True\n q = [(i, j)]\n hd = 0\n while hd < len(q):\n for g in go[q[hd][0]][q[hd][1]]:\n if not u[g[0]][g[1]]:\n u[g[0]][g[1]] = True\n q.append(g)\n hd += 1\n if len(q) != h * w:\n good = False\n\n\nprint(\"YES\" if good else \"NO\")", "passed": true, "time": 2.49, "memory": 14580.0, "status": "done"}, {"code": "3\n\nimport sys\n\n\"\"\"\n4 6\n<><>\nv^v^v^\n\"\"\"\n\ndef num_of_accessible(g, node):\n q = [node]\n seen = set([node])\n while len(q) > 0:\n v = q.pop()\n for u in g[v]:\n if u in seen:\n continue\n seen.add(u)\n q.append(u)\n return len(seen)\n\ndef __starting_point():\n n, m = list(map(int, sys.stdin.readline().split()))\n horiz = sys.stdin.readline().strip()\n vert = sys.stdin.readline().strip()\n \n # Graph\n g = {(i, j): [] for i in range(n) for j in range(m)}\n for i, h in enumerate(horiz):\n if h == '<':\n for j in range(m-1):\n g[(i, j+1)].append((i, j))\n else:\n for j in range(m-1):\n g[(i, j)].append((i, j+1))\n for j, v in enumerate(vert):\n if v == 'v':\n for i in range(n-1):\n g[(i, j)].append((i+1, j))\n else:\n for i in range(n-1):\n g[(i+1, j)].append((i, j))\n \n conn = True\n for node in g:\n if num_of_accessible(g, node) < n*m:\n conn = False\n break\n \n print('YES' if conn else 'NO')\n\n__starting_point()", "passed": true, "time": 1.67, "memory": 14588.0, "status": "done"}, {"code": "n,m=map(int,input().split())\ns=input()\nt=input()\nif (s[0]=='>' and t[0]=='v') or (s[0]=='<' and t[0]=='^') or (s[0]=='>' and t[m-1]=='^') or (s[0]=='<' and t[m-1]=='v') or (s[n-1]=='>' and t[0]=='^') or (s[n-1]=='<' and t[0]=='v'):\n print(\"NO\")\nelse:print(\"YES\")", "passed": true, "time": 0.22, "memory": 14468.0, "status": "done"}, {"code": "# CF BAYAN WARMUP\n# B\n\nl = input()\nh = input()\nv = input()\n\nif h[0] == \"<\" and v[0] == \"^\":\n print(\"NO\")\nelif h[0] == \">\" and v[-1] == \"^\":\n print(\"NO\")\nelif h[-1] == \"<\" and v[0] == \"v\":\n print(\"NO\")\nelif h[-1] == \">\" and v[-1] == \"v\":\n print(\"NO\")\nelse:\n print(\"YES\")\n", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\na = input()\nb = input()\nif (a[0] == '>' and b[0] == 'v') or (a[0] == '<' and b[-1] == 'v') or (a[-1] == '>' and b[0] == '^') or (a[-1] == '<' and b[-1] == '^'):\n print('NO')\nelse:\n print('YES')\n", "passed": true, "time": 0.15, "memory": 14376.0, "status": "done"}, {"code": "3\n\nn, m = input().split()\nn = int(n)\nm = int(m)\n\nif n == m == 1:\n print(\"YES\")\nelse:\n x, y = input(), input()\n x = (1 if x[0] == '<' else 0, 1 if x[-1] == '>' else 0)\n y = (1 if y[0] == 'v' else 0, 1 if y[-1] == '^' else 0)\n if (sum(x) + sum(y)) % 4 == 0:\n print(\"YES\")\n else:\n print(\"NO\")\n", "passed": true, "time": 0.19, "memory": 14548.0, "status": "done"}, {"code": "from collections import deque\n\ndic = {'>': (0, 1), '<': (0, -1), 'v': (1, 0), '^': (-1, 0)}\n[n, m], hor, vert = list(map(int, input().split())), input().strip(), input().strip()\nfor _x in range(n):\n for _y in range(m):\n q, d = deque([(_x, _y)]), [[0] * m for x in range(n)]\n d[_x][_y] = 1\n while q:\n x, y = q.popleft()\n for direction in '><v^':\n dx, dy = dic[direction]\n if -1 < x + dx < n and -1 < y + dy < m and (vert[y] == direction if dx else hor[x] == direction) and not d[x + dx][y + dy]:\n d[x + dx][y + dy] = 1\n q.append((x + dx, y + dy))\n if sum(sum(d, [])) != n * m:\n print('NO')\n break\n else:\n continue\n break\nelse:\n print('YES')\n", "passed": true, "time": 2.23, "memory": 14612.0, "status": "done"}, {"code": "from collections import deque\n\nn, m = list(map(int, input().split()))\n\ns1 = input()\ns2 = input()\n\nok = True\n\nfor i in range(n):\n for j in range(m):\n c = [[False for _ in range(m)] for __ in range(n)]\n c[i][j] = True\n\n q = deque()\n q.append((i, j))\n\n while len(q) > 0:\n x, y = q.popleft()\n\n if s1[x] == '>' and y + 1 < m and not c[x][y + 1]:\n c[x][y + 1] = True\n q.append((x, y + 1))\n elif s1[x] == '<' and y - 1 >= 0 and not c[x][y - 1]:\n c[x][y - 1] = True\n q.append((x, y - 1))\n\n if s2[y] == '^' and x - 1 >= 0 and not c[x - 1][y]:\n c[x - 1][y] = True\n q.append((x - 1, y))\n elif s2[y] == 'v' and x + 1 < n and not c[x + 1][y]:\n c[x + 1][y] = True\n q.append((x + 1, y))\n\n for a in range(n):\n for b in range(m):\n if not c[a][b]:\n ok = False\n\nif ok:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 2.86, "memory": 14544.0, "status": "done"}, {"code": "n,m=list(map(int,input().split()))\n\na=input()\nb=input()\n\nif a[0]=='>' and a[n-1]=='<' and b[0]=='^' and b[m-1]=='v':\n print (\"YES\")\nelif a[n-1]=='>' and a[0]=='<' and b[m-1]=='^' and b[0]=='v':\n print(\"YES\")\nelse:print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14580.0, "status": "done"}, {"code": "n, m = map(int, input().split())\na = input()\nb = input()\nf = True\ndef dfs(x, y):\n tmp = 1\n used[x + y * 42] = 1\n if a[x] == '>' and y + 1 < m:\n if used[x + (y + 1) * 42] == 0:\n tmp += dfs(x, y + 1)\n if a[x] == '<' and y - 1 >= 0:\n if used[x + (y - 1) * 42] == 0:\n tmp += dfs(x, y - 1)\n if b[y] == 'v' and x + 1 < n:\n if used[x + 1 + (y) * 42] == 0:\n tmp += dfs(x + 1, y)\n if b[y] == '^' and x - 1 >= 0:\n if used[x - 1 + (y) * 42] == 0:\n tmp += dfs(x - 1, y)\n return(tmp)\n \nfor i in range(n):\n for j in range(m):\n used = [0] * 1000\n if dfs(i, j) != n * m:\n f = False\nif f:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 3.17, "memory": 14396.0, "status": "done"}, {"code": "'''\nCreated on Oct 5, 2014\n\n@author: Ismael\n'''\nfrom _collections import defaultdict\n\ndef DFexplo(dictAdj,start):\n explored = {start}\n lifo = [start]\n while(len(lifo)>0):\n node = lifo.pop()\n for child in dictAdj[node]:\n if(child not in explored):\n explored.add(child)\n lifo.append(child)\n return explored\n\ndef solve(dictAdj):\n #print(dictAdj)\n for i in range(len(H)):\n for j in range(len(V)):\n nodesReachable = DFexplo(dictAdj,(i,j))\n if(len(nodesReachable) < n*m-1):\n return False\n return True\n\ndef isNode(i,j):\n return 0 <= i < n and 0 <= j < m\n\ndef buildGraph(H,V):\n dictAdj = defaultdict(list)\n for i in range(len(H)):\n for j in range(len(V)):\n if(isNode(i,j-1) and H[i]=='<'):\n dictAdj[(i,j)].append((i,j-1))\n if(isNode(i,j+1) and H[i]=='>'):\n dictAdj[(i,j)].append((i,j+1))\n if(isNode(i-1,j) and V[j]=='^'):\n dictAdj[(i,j)].append((i-1,j))\n if(isNode(i+1,j) and V[j]=='v'):\n dictAdj[(i,j)].append((i+1,j))\n return dictAdj\n\nn,m = map(int,input().split())\nH = input()\nV = input()\ndictAdj = buildGraph(H,V)\nif(solve(dictAdj)):\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.86, "memory": 14676.0, "status": "done"}, {"code": "data = input().split()\nn = int(data[0])\nm = int(data[1])\nh = input().rstrip()\nv = input().rstrip()\nf = (h[0] == '<' and v[0] == 'v' and v[-1] == '^' and h[-1] == '>') or (h[0] == '>' and v[0] == '^' and v[-1] == 'v' and h[-1] == '<')\nprint('YES' if f else 'NO')", "passed": true, "time": 0.14, "memory": 14444.0, "status": "done"}, {"code": "def dfs(x, y):\n if not graph[2][x + graph[0][x][y]][y]:\n graph[2][x + graph[0][x][y]][y] = True\n dfs(x + graph[0][x][y], y)\n if not graph[2][x][y + graph[1][x][y]]:\n graph[2][x][y + graph[1][x][y]] = True\n dfs(x, y + graph[1][x][y])\n \nn, m = list(map(int, input().split()))\nc = chr(0)\nflag1 = True\ngraph = [[[0] * (n + 1) for i in range(m + 1)], [[0] * (n + 1) for i in range(m + 1)], [[False] * (n + 1) for i in range(m + 1)]]\n\ns = input()\nfor i in range(n):\n c = s[i]\n if c == '<':\n for j in range(1, m):\n graph[0][j][i] = -1\n else:\n for j in range(m - 1):\n graph[0][j][i] = 1\n \ns = input()\nfor i in range(m):\n c = s[i]\n if c == '^':\n for j in range(1, n):\n graph[1][i][j] = -1\n else:\n for j in range(n - 1):\n graph[1][i][j] = 1\n \nfor i in range(n):\n for j in range(m):\n flag = False\n if flag1:\n for k in range(n):\n for l in range(m):\n graph[2][l][k] = False\n graph[2][j][i] = True\n dfs(j, i)\n for k in range(n):\n for l in range(m):\n if graph[2][l][k] == False:\n flag = True\n # print(i, j, k, l)\n if flag:\n print('NO')\n flag1 = not flag\n\nif flag1:\n print('YES')\n \n#print()\n#for i in range(n):\n #for j in range(m):\n #print(graph[0][j][i], end = ' ')\n #print()\n#print()\n#for i in range(n):\n #for j in range(m):\n #print(graph[1][j][i], end = ' ')\n #print()\n", "passed": true, "time": 2.16, "memory": 14652.0, "status": "done"}, {"code": "h, w = map(int, input().split())\ngo = [[[] for x in range(w)] for y in range(h)]\ns = input()\nfor i in range(h):\n if s[i] == '>':\n for j in range(w - 1):\n go[i][j].append((i, j + 1))\n else:\n for j in range(1, w):\n go[i][j].append((i, j - 1))\ns = input()\nfor i in range(w):\n if s[i] == '^':\n for j in range(1, h):\n go[j][i].append((j - 1, i))\n else:\n for j in range(h - 1):\n go[j][i].append((j + 1, i))\n\ngood = True\nfor i in range(h):\n for j in range(w):\n u = [[False for x in range(w)] for y in range(h)]\n u[i][j] = True\n q = [(i, j)]\n hd = 0\n while hd < len(q):\n for g in go[q[hd][0]][q[hd][1]]:\n if not u[g[0]][g[1]]:\n u[g[0]][g[1]] = True\n q.append(g)\n hd += 1\n if len(q) != h * w:\n good = False\n\n\nprint(\"YES\" if good else \"NO\")", "passed": true, "time": 2.41, "memory": 14480.0, "status": "done"}, {"code": "h, w = map(int, input().split())\ngo = [[[] for x in range(w)] for y in range(h)]\ns = input()\nt = input()\nc1 = s[0] == '<' and s[h - 1] == '>' and t[0] == 'v' and t[w - 1] == '^'\nc2 = s[0] == '>' and s[h - 1] == '<' and t[0] == '^' and t[w - 1] == 'v'\nprint(\"YES\" if c1 or c2 else \"NO\")", "passed": true, "time": 0.14, "memory": 14432.0, "status": "done"}, {"code": "n , m = map(int,input().split())\nh = input()\nv = input()\nif (h[0] == '>' and v[0] == 'v') or (h[-1] == '<' and v[-1] == '^') or (h[0] == '<' and v[-1] == 'v') or (h[-1] == '>' and v[0] == '^'):\n print('NO')\nelse:\n print('YES')", "passed": true, "time": 0.15, "memory": 14420.0, "status": "done"}, {"code": "'''\nCreated on Oct 6, 2014\n\n@author: nod\n'''\nn, m = map(int, input().split())\nhorizontal = str(input())\nvisited = []\nh = []\nvertical = str(input())\nv = []\nfor char in horizontal:\n if char == \">\":\n h.append(int(1))\n else:\n h.append(int(-1))\nfor char in vertical:\n if char == \"v\":\n v.append(int(1))\n else:\n v.append(int(-1))\ndef travel(ni, mi):\n leftright = h[ni]\n updown = v[mi]\n visited.append([ni,mi])\n newn = ni + updown\n newm = mi + leftright\n if newn >= 0 and newn < n and [newn,mi] not in visited:\n# print(newn,mi)\n travel(newn,mi)\n if newm >= 0 and newm < m and [ni,newm] not in visited:\n# print(ni,newm)\n travel(ni,newm)\n return visited\n\ndef solve():\n lst = [[0,0],[0,m-1],[n-1,0],[n-1,m-1]]\n visited = []\n for l in lst:\n visited.clear()\n vis = travel(l[0],l[1])\n if len(vis) != m*n:\n print(\"NO\")\n return\n visited.clear()\n vis.clear()\n print(\"YES\")\nsolve()", "passed": true, "time": 0.34, "memory": 14632.0, "status": "done"}, {"code": "input()\nhoriz = input()\nvert = input()\n\nm = horiz[0]+horiz[-1]+vert[0]+vert[-1]\n\nprint(\"YES\" if m in (\"><^v\", \"<>v^\") else \"NO\")", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nh, v = input(), input()\nif h[0] == '<' and v[0] == '^':\n print('NO')\nelif h[0] == '>' and v[0] == 'v':\n print('NO')\nelif h[0] == h[-1] or v[0] == v[-1]:\n print('NO')\nelse:\n print('YES')", "passed": true, "time": 0.14, "memory": 14376.0, "status": "done"}, {"code": "# 475B\n\nfrom sys import stdin\n\n__author__ = 'artyom'\n\nstdin.readline()\np = stdin.readline().strip()\nq = stdin.readline().strip()\nprint('YES' if (p[0] == '>' and p[-1] == '<' and q[0] == '^' and q[-1] == 'v') or\n (p[0] == '<' and p[-1] == '>' and q[0] == 'v' and q[-1] == '^') else 'NO')", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "n, m = [int(x) for x in input().split()]\na = input()\nb = input()\nif a[0] == '<' and b[0] == 'v' and a[-1] == '>' and b[-1] == '^':\n\tprint('YES')\nelif a[0] == '>' and b[-1] == 'v' and a[-1] == '<' and b[0] == '^':\n\tprint('YES')\nelse:\n\tprint('NO')\n", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "def main():\n n, m = map(int, input().split())\n nm = n * m\n neigh = [[] for _ in range(nm)]\n for y, c in enumerate(input()):\n for x in range(y * m + 1, y * m + m):\n if c == '<':\n neigh[x].append(x - 1)\n else:\n neigh[x - 1].append(x)\n for x, c in enumerate(input()):\n for y in range(m + x, nm, m):\n if c == '^':\n neigh[y].append(y - m)\n else:\n neigh[y - m].append(y)\n\n def getdsu(t):\n if dsu[t] != t:\n dsu[t] = getdsu(dsu[t])\n return dsu[t]\n\n def setdsu(u, v):\n dsu[u] = getdsu(dsu[v])\n\n def dfs(yx):\n l[yx] = False\n for yx1 in neigh[yx]:\n if l[yx1]:\n setdsu(yx1, yx)\n dfs(yx1)\n\n for i in range(nm):\n l = [True] * nm\n dsu = list(range(nm))\n for j in range(i, i + nm):\n j %= nm\n if l[j]:\n dfs(j)\n if any(getdsu(_) != i for _ in range(nm)):\n print('NO')\n return\n print('YES')\n\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 1.34, "memory": 14692.0, "status": "done"}, {"code": "def main():\n n, m = map(int, input().split())\n nm = n * m\n neigh = [[] for _ in range(nm)]\n for y, c in enumerate(input()):\n for x in range(y * m + 1, y * m + m):\n if c == '<':\n neigh[x].append(x - 1)\n else:\n neigh[x - 1].append(x)\n for x, c in enumerate(input()):\n for y in range(m + x, nm, m):\n if c == '^':\n neigh[y].append(y - m)\n else:\n neigh[y - m].append(y)\n\n def dfs(yx):\n l[yx] = False\n for yx1 in neigh[yx]:\n if l[yx1]:\n dfs(yx1)\n\n for i in range(nm):\n l = [True] * nm\n dfs(i)\n if any(l):\n print('NO')\n return\n print('YES')\n\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.49, "memory": 14584.0, "status": "done"}] | [{"input": "3 3\n><>\nv^v\n", "output": "NO\n"}, {"input": "4 6\n<><>\nv^v^v^\n", "output": "YES\n"}, {"input": "2 2\n<>\nv^\n", "output": "YES\n"}, {"input": "2 2\n>>\n^v\n", "output": "NO\n"}, {"input": "3 3\n>><\n^^v\n", "output": "YES\n"}, {"input": "3 4\n>><\n^v^v\n", "output": "YES\n"}, {"input": "3 8\n>><\nv^^^^^^^\n", "output": "NO\n"}, {"input": "7 2\n<><<<<>\n^^\n", "output": "NO\n"}, {"input": "4 5\n><<<\n^^^^v\n", "output": "YES\n"}, {"input": "2 20\n><\n^v^^v^^v^^^v^vv^vv^^\n", "output": "NO\n"}, {"input": "2 20\n<>\nv^vv^v^^vvv^^^v^vvv^\n", "output": "YES\n"}, {"input": "20 2\n<><<><<>><<<>><><<<<\n^^\n", "output": "NO\n"}, {"input": "20 2\n><>><>><>><<<><<><><\n^v\n", "output": "YES\n"}, {"input": "11 12\n><<<><><<>>\nvv^^^^vvvvv^\n", "output": "NO\n"}, {"input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^\n", "output": "YES\n"}, {"input": "16 11\n<<<<>><><<<<<><<\nvv^v^vvvv^v\n", "output": "NO\n"}, {"input": "14 7\n><<<<>>>>>>><<\nvv^^^vv\n", "output": "NO\n"}, {"input": "5 14\n<<><>\nv^vv^^vv^v^^^v\n", "output": "NO\n"}, {"input": "8 18\n>>>><>>>\nv^vv^v^^^^^vvv^^vv\n", "output": "NO\n"}, {"input": "18 18\n<<><>><<>><>><><<<\n^^v^v^vvvv^v^vv^vv\n", "output": "NO\n"}, {"input": "4 18\n<<<>\n^^^^^vv^vv^^vv^v^v\n", "output": "NO\n"}, {"input": "19 18\n><><>>><<<<<>>><<<>\n^^v^^v^^v^vv^v^vvv\n", "output": "NO\n"}, {"input": "14 20\n<<<><><<>><><<\nvvvvvvv^v^vvvv^^^vv^\n", "output": "NO\n"}, {"input": "18 18\n><>>><<<>><><>>>><\nvv^^^^v^v^^^^v^v^^\n", "output": "NO\n"}, {"input": "8 18\n<><<<>>>\n^^^^^^v^^^vv^^vvvv\n", "output": "NO\n"}, {"input": "11 12\n><><><<><><\n^^v^^^^^^^^v\n", "output": "YES\n"}, {"input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^\n", "output": "YES\n"}, {"input": "16 11\n>><<><<<<>>><><<\n^^^^vvvv^vv\n", "output": "YES\n"}, {"input": "14 7\n<><><<<>>>><>>\nvv^^v^^\n", "output": "YES\n"}, {"input": "5 14\n>>>><\n^v^v^^^vv^vv^v\n", "output": "YES\n"}, {"input": "8 18\n<<<><>>>\nv^^vvv^^v^v^vvvv^^\n", "output": "YES\n"}, {"input": "18 18\n><><<><><>>><>>>><\n^^vvv^v^^^v^vv^^^v\n", "output": "YES\n"}, {"input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^\n", "output": "YES\n"}, {"input": "19 18\n>>>><><<>>><<<><<<<\n^v^^^^vv^^v^^^^v^v\n", "output": "YES\n"}, {"input": "14 20\n<>><<<><<>>>>>\nvv^^v^^^^v^^vv^^vvv^\n", "output": "YES\n"}, {"input": "18 18\n><><<><><>>><>>>><\n^^vvv^v^^^v^vv^^^v\n", "output": "YES\n"}, {"input": "8 18\n<<<><>>>\nv^^vvv^^v^v^vvvv^^\n", "output": "YES\n"}, {"input": "20 19\n<><>>>>><<<<<><<>>>>\nv^vv^^vvvvvv^vvvv^v\n", "output": "NO\n"}, {"input": "20 19\n<<<><<<>><<<>><><><>\nv^v^vvv^vvv^^^vvv^^\n", "output": "YES\n"}, {"input": "19 20\n<><<<><><><<<<<<<<>\n^v^^^^v^^vvvv^^^^vvv\n", "output": "NO\n"}, {"input": "19 20\n>>>>>>>><>>><><<<><\n^v^v^^^vvv^^^v^^vvvv\n", "output": "YES\n"}, {"input": "20 20\n<<<>>>><>><<>><<>>>>\n^vvv^^^^vv^^^^^v^^vv\n", "output": "NO\n"}, {"input": "20 20\n>>><><<><<<<<<<><<><\nvv^vv^vv^^^^^vv^^^^^\n", "output": "NO\n"}, {"input": "20 20\n><<><<<<<<<>>><>>><<\n^^^^^^^^vvvv^vv^vvvv\n", "output": "YES\n"}, {"input": "20 20\n<>>>>>>>><>>><>><<<>\nvv^^vv^^^^v^vv^v^^^^\n", "output": "YES\n"}, {"input": "20 20\n><>><<>><>>>>>>>><<>\n^^v^vv^^^vvv^v^^^vv^\n", "output": "NO\n"}, {"input": "20 20\n<<<<><<>><><<<>><<><\nv^^^^vvv^^^vvvv^v^vv\n", "output": "NO\n"}, {"input": "20 20\n><<<><<><>>><><<<<<<\nvv^^vvv^^v^^v^vv^vvv\n", "output": "NO\n"}, {"input": "20 20\n<<>>><>>>><<<<>>><<>\nv^vv^^^^^vvv^^v^^v^v\n", "output": "NO\n"}, {"input": "20 20\n><<><<><<<<<<>><><>>\nv^^^v^vv^^v^^vvvv^vv\n", "output": "NO\n"}, {"input": "20 20\n<<<<<<<<><>><><>><<<\n^vvv^^^v^^^vvv^^^^^v\n", "output": "NO\n"}, {"input": "20 20\n>>><<<<<>>><><><<><<\n^^^vvv^^^v^^v^^v^vvv\n", "output": "YES\n"}, {"input": "20 20\n<><<<><><>><><><<<<>\n^^^vvvv^vv^v^^^^v^vv\n", "output": "NO\n"}, {"input": "20 20\n>>>>>>>>>><>>><>><>>\n^vvv^^^vv^^^^^^vvv^v\n", "output": "NO\n"}, {"input": "20 20\n<><>><><<<<<>><<>>><\nv^^^v^v^v^vvvv^^^vv^\n", "output": "NO\n"}, {"input": "20 20\n><<<><<<><<<><>>>><<\nvvvv^^^^^vv^v^^vv^v^\n", "output": "NO\n"}, {"input": "20 20\n<<><<<<<<>>>>><<<>>>\nvvvvvv^v^vvv^^^^^^^^\n", "output": "YES\n"}, {"input": "20 20\n><<><<>>>>><><>><>>>\nv^^^^vvv^^^^^v^v^vv^\n", "output": "NO\n"}, {"input": "20 20\n<<>>><>><<>>>><<<><<\n^^vvv^^vvvv^vv^^v^v^\n", "output": "NO\n"}, {"input": "20 20\n><<>><>>>><<><>><><<\n^v^^^^^^vvvv^v^v^v^^\n", "output": "NO\n"}, {"input": "20 20\n<<><<<<><><<>>><>>>>\n^^vvvvv^v^^^^^^^vvv^\n", "output": "NO\n"}, {"input": "20 20\n>><<<<<<><>>>><>>><>\n^^^v^v^vv^^vv^vvv^^^\n", "output": "NO\n"}, {"input": "20 20\n>>>>>>>>>>>>>>>>>>>>\nvvvvvvvvvvvvvvvvvvvv\n", "output": "NO\n"}, {"input": "2 2\n><\nv^\n", "output": "NO\n"}, {"input": "2 2\n<>\n^v\n", "output": "NO\n"}, {"input": "3 3\n>><\nvvv\n", "output": "NO\n"}, {"input": "2 3\n<>\nv^^\n", "output": "YES\n"}, {"input": "4 4\n>>><\nvvv^\n", "output": "NO\n"}, {"input": "20 20\n<><><><><><><><><><>\nvvvvvvvvvvvvvvvvvvvv\n", "output": "NO\n"}, {"input": "4 4\n<>>>\nv^^^\n", "output": "YES\n"}, {"input": "20 20\n<><><><><><><><><><>\nv^v^v^v^v^v^v^v^v^v^\n", "output": "YES\n"}, {"input": "2 3\n<>\n^v^\n", "output": "NO\n"}, {"input": "4 3\n<><>\n^vv\n", "output": "NO\n"}, {"input": "3 3\n<<>\nvv^\n", "output": "YES\n"}, {"input": "2 3\n><\nvv^\n", "output": "NO\n"}, {"input": "7 6\n>>><>><\n^vv^vv\n", "output": "YES\n"}, {"input": "2 2\n<<\nv^\n", "output": "NO\n"}, {"input": "3 3\n>><\n^^^\n", "output": "NO\n"}, {"input": "3 3\n<><\nv^v\n", "output": "NO\n"}, {"input": "20 20\n><><><><><><><><><><\n^v^v^v^v^v^v^v^v^v^v\n", "output": "YES\n"}, {"input": "4 4\n<>>>\nvvv^\n", "output": "YES\n"}] |
|
174 | Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false.
Implication is written by using character '$\rightarrow$', and the arguments and the result of the implication are written as '0' (false) and '1' (true). According to the definition of the implication:
$0 \rightarrow 0 = 1$
$0 \rightarrow 1 = 1$
$1 \rightarrow 0 = 0$
$1 \rightarrow 1 = 1$
When a logical expression contains multiple implications, then when there are no brackets, it will be calculated from left to fight. For example,
$0 \rightarrow 0 \rightarrow 0 =(0 \rightarrow 0) \rightarrow 0 = 1 \rightarrow 0 = 0$.
When there are brackets, we first calculate the expression in brackets. For example,
$0 \rightarrow(0 \rightarrow 0) = 0 \rightarrow 1 = 1$.
For the given logical expression $a_{1} \rightarrow a_{2} \rightarrow a_{3} \rightarrow \cdots \cdots a_{n}$ determine if it is possible to place there brackets so that the value of a logical expression is false. If it is possible, your task is to find such an arrangement of brackets.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 100 000) — the number of arguments in a logical expression.
The second line contains n numbers a_1, a_2, ..., a_{n} ($a_{i} \in \{0,1 \}$), which means the values of arguments in the expression in the order they occur.
-----Output-----
Print "NO" (without the quotes), if it is impossible to place brackets in the expression so that its value was equal to 0.
Otherwise, print "YES" in the first line and the logical expression with the required arrangement of brackets in the second line.
The expression should only contain characters '0', '1', '-' (character with ASCII code 45), '>' (character with ASCII code 62), '(' and ')'. Characters '-' and '>' can occur in an expression only paired like that: ("->") and represent implication. The total number of logical arguments (i.e. digits '0' and '1') in the expression must be equal to n. The order in which the digits follow in the expression from left to right must coincide with a_1, a_2, ..., a_{n}.
The expression should be correct. More formally, a correct expression is determined as follows: Expressions "0", "1" (without the quotes) are correct. If v_1, v_2 are correct, then v_1->v_2 is a correct expression. If v is a correct expression, then (v) is a correct expression.
The total number of characters in the resulting expression mustn't exceed 10^6.
If there are multiple possible answers, you are allowed to print any of them.
-----Examples-----
Input
4
0 1 1 0
Output
YES
(((0)->1)->(1->0))
Input
2
1 1
Output
NO
Input
1
0
Output
YES
0 | interview | [{"code": "x = int(input())\n\nseq = list(map(int, input().split(' ')))\n\nif seq == [0]:\n print(\"YES\")\n print(0)\n\nelif seq == [0, 0]:\n print(\"NO\")\n\nelif seq == [1, 0]:\n print(\"YES\")\n print('1->0')\n\nelif seq == [0, 0, 0]:\n print(\"YES\")\n print(\"(0->0)->0\")\n\nelif seq == [1, 0, 0]:\n print(\"NO\")\n\nelif seq[x-1] == 1:\n print(\"NO\")\n\n#ENDS IN 1\n \nelif seq[x-2] == 1:\n print(\"YES\")\n\n print('->'.join([str(x) for x in seq]))\n\n\n#ENDS IN 10\n\nelif seq == [1] * (x-2) + [0, 0]:\n print(\"NO\")\n\n#000 BELOW\nelif seq[x-3] == 0:\n a = ('->'.join([str(x) for x in seq][0:x-3]))\n print(\"YES\")\n\n print(a + '->(0->0)->0')\n\n#100\nelse:\n last = 0\n for i in range(x-1):\n if seq[i] == 0 and seq[i+1] == 1:\n last = i\n seq[last] = '(0'\n seq[last+1] = '(1'\n seq[x-2] = '0))'\n print(\"YES\")\n print('->'.join([str(x) for x in seq]))\n", "passed": true, "time": 0.14, "memory": 14580.0, "status": "done"}, {"code": "def f(a):\n\tif len(a) == 1:\n\t\tif a[0] == 0:\n\t\t\tprint(\"YES\\n0\")\n\t\t\treturn\n\t\telse:\n\t\t\tprint(\"NO\")\n\t\t\treturn\n\tif a[-1] == 1:\n\t\tprint(\"NO\")\n\t\treturn\n\tif a[-2] == 1:\n\t\tprint(\"YES\")\n\t\tprint(\"->\".join(str(x) for x in a))\n\t\treturn\n\telif len(a) == 2:\n\t\tprint(\"NO\")\n\t\treturn\n\telif len(a) >= 3 and a[-3] == 0:\n\t\ta[-3] = '(0'\n\t\ta[-2] = '0)'\n\t\tprint(\"YES\\n\" + \"->\".join(str(x) for x in a))\n\t\treturn\t\t\n\tfor i in range(len(a) - 3, -1, -1):\n\t\tif a[i] == 0:\n\t\t\ta[i] = '(' + str(a[i])\n\t\t\ta[i+1] = '(' + str(a[i+1])\n\t\t\ta[-2] = '0))'\n\t\t\tprint(\"YES\\n\" + \"->\".join(str(x) for x in a))\n\t\t\treturn\n\tprint(\"NO\")\n\treturn\n\nn = int(input())\na = list(int(x) for x in input().split())\nf(a)\n", "passed": true, "time": 0.14, "memory": 14440.0, "status": "done"}, {"code": "def f(a):\n if len(a) == 1:\n if a[0] == 0:\n print(\"YES\\n0\")\n return\n else:\n print(\"NO\")\n return\n if a[-1] == 1:\n print(\"NO\")\n return\n if a[-2] == 1:\n print(\"YES\")\n print(\"->\".join(str(x) for x in a))\n return\n elif len(a) == 2:\n print(\"NO\")\n return\n elif len(a) >= 3 and a[-3] == 0:\n a[-3] = '(0'\n a[-2] = '0)'\n print(\"YES\\n\" + \"->\".join(str(x) for x in a))\n return \n for i in range(len(a) - 3, -1, -1):\n if a[i] == 0:\n a[i] = '(' + str(a[i])\n a[i+1] = '(' + str(a[i+1])\n a[-2] = '0))'\n print(\"YES\\n\" + \"->\".join(str(x) for x in a))\n return\n print(\"NO\")\n return\n\nn = int(input())\na = list(int(x) for x in input().split())\nf(a)", "passed": true, "time": 0.14, "memory": 14540.0, "status": "done"}] | [{"input": "4\n0 1 1 0\n", "output": "YES\n0->1->1->0\n"}, {"input": "2\n1 1\n", "output": "NO\n"}, {"input": "1\n0\n", "output": "YES\n0\n"}, {"input": "4\n0 0 0 0\n", "output": "YES\n0->(0->0)->0\n"}, {"input": "6\n0 0 0 0 0 1\n", "output": "NO\n"}, {"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "NO\n"}, {"input": "20\n1 1 1 0 1 0 1 1 0 1 1 1 0 1 0 0 1 1 0 0\n", "output": "YES\n1->1->1->0->1->0->1->1->0->1->1->1->0->1->0->(0->(1->1->0))->0\n"}, {"input": "1\n1\n", "output": "NO\n"}, {"input": "2\n0 0\n", "output": "NO\n"}, {"input": "2\n0 1\n", "output": "NO\n"}, {"input": "2\n1 0\n", "output": "YES\n1->0\n"}, {"input": "3\n0 0 0\n", "output": "YES\n(0->0)->0\n"}, {"input": "3\n0 0 1\n", "output": "NO\n"}, {"input": "3\n0 1 0\n", "output": "YES\n0->1->0\n"}, {"input": "3\n0 1 1\n", "output": "NO\n"}, {"input": "3\n1 0 0\n", "output": "NO\n"}, {"input": "3\n1 0 1\n", "output": "NO\n"}, {"input": "3\n1 1 0\n", "output": "YES\n1->1->0\n"}, {"input": "3\n1 1 1\n", "output": "NO\n"}, {"input": "4\n0 0 0 1\n", "output": "NO\n"}, {"input": "4\n0 0 1 0\n", "output": "YES\n0->0->1->0\n"}, {"input": "4\n0 0 1 1\n", "output": "NO\n"}, {"input": "4\n0 1 0 0\n", "output": "YES\n(0->(1->0))->0\n"}, {"input": "4\n0 1 0 1\n", "output": "NO\n"}, {"input": "4\n0 1 1 1\n", "output": "NO\n"}, {"input": "4\n1 0 0 0\n", "output": "YES\n1->(0->0)->0\n"}, {"input": "4\n1 0 0 1\n", "output": "NO\n"}, {"input": "4\n1 0 1 0\n", "output": "YES\n1->0->1->0\n"}, {"input": "4\n1 0 1 1\n", "output": "NO\n"}, {"input": "4\n1 1 0 0\n", "output": "NO\n"}, {"input": "4\n1 1 0 1\n", "output": "NO\n"}, {"input": "4\n1 1 1 0\n", "output": "YES\n1->1->1->0\n"}, {"input": "4\n1 1 1 1\n", "output": "NO\n"}, {"input": "5\n0 0 0 0 0\n", "output": "YES\n0->0->(0->0)->0\n"}, {"input": "5\n0 0 0 0 1\n", "output": "NO\n"}, {"input": "5\n0 0 0 1 0\n", "output": "YES\n0->0->0->1->0\n"}, {"input": "5\n0 0 0 1 1\n", "output": "NO\n"}, {"input": "5\n0 0 1 0 0\n", "output": "YES\n0->(0->(1->0))->0\n"}, {"input": "5\n0 0 1 0 1\n", "output": "NO\n"}, {"input": "5\n0 0 1 1 0\n", "output": "YES\n0->0->1->1->0\n"}, {"input": "5\n0 0 1 1 1\n", "output": "NO\n"}, {"input": "5\n0 1 0 0 0\n", "output": "YES\n0->1->(0->0)->0\n"}, {"input": "5\n0 1 0 0 1\n", "output": "NO\n"}, {"input": "5\n0 1 0 1 0\n", "output": "YES\n0->1->0->1->0\n"}, {"input": "5\n0 1 0 1 1\n", "output": "NO\n"}, {"input": "5\n0 1 1 0 0\n", "output": "YES\n(0->(1->1->0))->0\n"}, {"input": "5\n0 1 1 0 1\n", "output": "NO\n"}, {"input": "5\n0 1 1 1 0\n", "output": "YES\n0->1->1->1->0\n"}, {"input": "5\n0 1 1 1 1\n", "output": "NO\n"}, {"input": "5\n1 0 0 0 0\n", "output": "YES\n1->0->(0->0)->0\n"}, {"input": "5\n1 0 0 0 1\n", "output": "NO\n"}, {"input": "5\n1 0 0 1 0\n", "output": "YES\n1->0->0->1->0\n"}, {"input": "5\n1 0 0 1 1\n", "output": "NO\n"}, {"input": "5\n1 0 1 0 0\n", "output": "YES\n1->(0->(1->0))->0\n"}, {"input": "5\n1 0 1 0 1\n", "output": "NO\n"}, {"input": "5\n1 0 1 1 0\n", "output": "YES\n1->0->1->1->0\n"}, {"input": "5\n1 0 1 1 1\n", "output": "NO\n"}, {"input": "5\n1 1 0 0 0\n", "output": "YES\n1->1->(0->0)->0\n"}, {"input": "5\n1 1 0 0 1\n", "output": "NO\n"}, {"input": "5\n1 1 0 1 0\n", "output": "YES\n1->1->0->1->0\n"}, {"input": "5\n1 1 0 1 1\n", "output": "NO\n"}, {"input": "5\n1 1 1 0 0\n", "output": "NO\n"}, {"input": "5\n1 1 1 0 1\n", "output": "NO\n"}, {"input": "5\n1 1 1 1 0\n", "output": "YES\n1->1->1->1->0\n"}, {"input": "5\n1 1 1 1 1\n", "output": "NO\n"}, {"input": "6\n1 1 1 1 0 0\n", "output": "NO\n"}, {"input": "6\n0 1 1 1 0 0\n", "output": "YES\n(0->(1->1->1->0))->0\n"}, {"input": "6\n1 1 1 0 0 0\n", "output": "YES\n1->1->1->(0->0)->0\n"}, {"input": "6\n0 0 0 0 0 0\n", "output": "YES\n0->0->0->(0->0)->0\n"}, {"input": "6\n1 0 0 1 0 0\n", "output": "YES\n1->0->(0->(1->0))->0\n"}, {"input": "6\n1 0 1 1 0 0\n", "output": "YES\n1->(0->(1->1->0))->0\n"}, {"input": "6\n0 0 1 1 0 0\n", "output": "YES\n0->(0->(1->1->0))->0\n"}, {"input": "6\n0 0 0 1 0 0\n", "output": "YES\n0->0->(0->(1->0))->0\n"}, {"input": "6\n0 0 1 0 0 0\n", "output": "YES\n0->0->1->(0->0)->0\n"}, {"input": "200\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0\n", "output": "NO\n"}, {"input": "40\n1 0 1 0 1 0 1 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 0 0\n", "output": "YES\n1->0->1->0->1->0->1->(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->0))->0\n"}, {"input": "40\n0 0 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0\n", "output": "YES\n0->0->1->0->0->0->0->0->0->1->1->0->1->0->1->0->1->(0->(1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->0))->0\n"}, {"input": "40\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 1 1 1 1 1 1 1 1 1 1 1 1 0 0\n", "output": "YES\n(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->0))->0\n"}, {"input": "40\n1 1 0 1 0 1 1 1 1 1 0 1 0 0 1 1 1 0 0 0 0 1 1 1 1 1 0 1 0 0 0 1 0 1 0 0 1 0 0 0\n", "output": "YES\n1->1->0->1->0->1->1->1->1->1->0->1->0->0->1->1->1->0->0->0->0->1->1->1->1->1->0->1->0->0->0->1->0->1->0->0->1->(0->0)->0\n"}, {"input": "45\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\n", "output": "YES\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\n"}, {"input": "20\n1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0\n", "output": "YES\n1->1->1->1->1->0->0->0->0->0->1->1->1->1->1->0->0->(0->0)->0\n"}] |
|
175 | You have two variables a and b. Consider the following sequence of actions performed with these variables: If a = 0 or b = 0, end the process. Otherwise, go to step 2; If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3; If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process.
Initially the values of a and b are positive integers, and so the process will be finite.
You have to determine the values of a and b after the process ends.
-----Input-----
The only line of the input contains two integers n and m (1 ≤ n, m ≤ 10^18). n is the initial value of variable a, and m is the initial value of variable b.
-----Output-----
Print two integers — the values of a and b after the end of the process.
-----Examples-----
Input
12 5
Output
0 1
Input
31 12
Output
7 12
-----Note-----
Explanations to the samples: a = 12, b = 5 $\rightarrow$ a = 2, b = 5 $\rightarrow$ a = 2, b = 1 $\rightarrow$ a = 0, b = 1; a = 31, b = 12 $\rightarrow$ a = 7, b = 12. | interview | [{"code": "a, b = [int(v) for v in input().split()]\n\nwhile a > 0 and b > 0:\n if a >= 2 * b:\n a %= 2 * b\n elif b >= 2 * a:\n b %= 2 * a\n else:\n break\n\nprint(a, b)\n", "passed": true, "time": 0.24, "memory": 14588.0, "status": "done"}, {"code": "a,b=list(map(int,input().split()))\nwhile a>0 and b>0:\n if a>=b+b:a%=b+b\n elif b>=a+a:b%=a+a\n else: break\nprint(a,b)\n", "passed": true, "time": 0.14, "memory": 14588.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\nwhile a != 0 and b != 0:\n if a >= 2 * b:\n a = a % (2 * b)\n elif b >= 2 * a:\n b = b % (2 * a)\n else:\n break\nprint(a, b)\n", "passed": true, "time": 0.15, "memory": 14316.0, "status": "done"}, {"code": "a,b = map(int, input().split())\n\nwhile 1:\n if a ==0 or b ==0:\n break\n elif a >= 2*b:\n a = a % (2*b)\n elif b >= 2*a:\n b = b % (2*a)\n else:\n break\nprint(a, b)", "passed": true, "time": 0.25, "memory": 14584.0, "status": "done"}, {"code": "def f(a, b):\n\tif a == 0 or b == 0:\n\t\treturn (a, b)\n\tif a >= 2 * b:\n\t\treturn f(a % (2 * b), b)\n\telif b >= 2 * a:\n\t\treturn f(a, b % (2 * a))\n\treturn (a, b)\n\na, b = map(int, input().split())\nprint(' '.join(list(map(str, f(a, b)))))", "passed": true, "time": 0.24, "memory": 14496.0, "status": "done"}, {"code": "a, b = map(int, input().split())\n\ndef huh(a, b):\n if a * b == 0:\n return a, b\n elif a >= 2 * b:\n return huh(a % (2 * b), b)\n elif b >= 2 * a:\n return huh(a, b % (2 * a))\n else:\n return a, b\n\na, b = huh(a, b)\n\nprint(a, b)", "passed": true, "time": 0.15, "memory": 14612.0, "status": "done"}, {"code": "def solve(x, y):\n if (x == 0 or y == 0):\n return (x, y)\n if (x >= 2 * y and y != 0):\n x %= 2 * y\n if (y >= 2 * x and x != 0):\n y %= 2 * x\n if (x == 0 or y == 0):\n return (x, y)\n if (x < 2 * y and y < 2 * x):\n return (x, y)\n return solve(x, y)\n\nx, y = list(map(int, input().split()))\nans = solve(x, y)\nprint(ans[0], ans[1])\n", "passed": true, "time": 0.21, "memory": 14448.0, "status": "done"}, {"code": "a, b = input().split()\na, b = int(a), int(b)\n\nwhile (a!=0 and b!=0):\n\tif (a>=2*b):\n\t\ta=a%(2*b)\n\telif b>=2*a:\n\t\tb=b%(2*a)\n\telse:\n\t\tbreak\nprint(a, b)", "passed": true, "time": 0.15, "memory": 14604.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\nwhile True:\n if a == 0 or b == 0:\n break\n elif a >= 2 * b:\n a -= 2 * b * (a // (2 * b))\n elif b >= 2 * a:\n b -= 2 * a * (b // (2 * a))\n else:\n break\n\nprint(a, b)\n", "passed": true, "time": 0.15, "memory": 14456.0, "status": "done"}, {"code": "n, m = [int(i) for i in input().split()]\n\nwhile n != 0 and m != 0:\n if n >= 2 * m:\n k = n // (2 * m)\n n -= 2 * m * k\n elif m >= 2 * n:\n k = m // (2 * n)\n m -= 2 * n * k\n else:\n break\nprint(n, m)", "passed": true, "time": 0.21, "memory": 14380.0, "status": "done"}, {"code": "a,b = list(map(int,input().split(\" \")))\n\nwhile True:\n\tif a == 0 or b == 0:\n\t\tprint(str(a) + \" \" + str(b))\n\t\treturn\n\n\telif a >= 2 * b:\n\t\ta = a % (2 * b)\n\n\telif b >= 2 * a:\n\t\tb = b % (2 * a)\n\n\telse:\n\t\tprint(str(a) + \" \" + str(b))\n\t\treturn\n", "passed": true, "time": 0.15, "memory": 14672.0, "status": "done"}, {"code": "#n = int(input())\na,b = list(map(int,input().split()))\nwhile(a>0 and b > 0):\n if a >= 2*b:\n a %= 2*b\n elif b >= 2*a:\n b %= 2*a\n else : break\nprint(a,b)\n", "passed": true, "time": 0.14, "memory": 14600.0, "status": "done"}, {"code": "a,b=map(int,input().split())\nwhile a and b:\n c=0\n while (a>0 and b>0 and a>=2*b):\n a-=2*b*(a//(2*b))\n c=1\n while a>0 and b>0 and b>=2*a:\n b-=2*a*(b//(2*a))\n c=1\n if(c==0):break\nprint(a,b)", "passed": true, "time": 0.15, "memory": 14340.0, "status": "done"}, {"code": "import sys\n\na, b = list(map(int, input().split()))\n\nwhile True:\n\tif a == 0 or b == 0:\n\t\tprint(a, b)\n\t\treturn\n\tif a >= 2 * b:\n\t\ta = a % (2 * b)\n\telif b >= 2 * a:\n\t\tb = b % (2 * a)\n\telse:\n\t\tprint(a, b)\n\t\treturn\n", "passed": true, "time": 0.14, "memory": 14604.0, "status": "done"}, {"code": "a, b = map(int, input().split())\nwhile a != 0 and b != 0:\n if a >= 2 * b:\n a %= 2 * b\n elif b >= 2 * a:\n b %= 2 * a\n else:\n break\nprint(a, b)", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "(n, m) = list(map(int, input().split()))\n\nwhile (n != 0 and m != 0) or (n >= 2 * m) or (m >= 2 * n):\n if n == 0:\n break\n elif m == 0:\n break\n elif n >= 2 * m:\n n = n % (2 * m)\n elif m >= 2 * n:\n m = m % (2 * n)\n else:\n break\n\nprint(n, m)\n", "passed": true, "time": 0.14, "memory": 14400.0, "status": "done"}, {"code": "a,b= (list(map(int,input().strip().split(' '))))\nwhile(True):\n if(a==0 or b==0):\n break\n if(a>=2*b):\n d = a//(2*b)\n d=max(d-1,1)\n a = a-d*2*b\n if(a==0 or b==0):\n break\n if(b>=2*a):\n d = b//(a*2)\n d=max(d-1,1)\n b = b-d*2*a\n if(a==0 or b==0):\n break\n if(a<2*b and b<2*a):\n break\nprint(a,b)\n\n", "passed": true, "time": 0.19, "memory": 14540.0, "status": "done"}, {"code": "R=lambda:list(map(int,input().split()))\n\nn, m = R()\n\ndef pr(a, b):\n if a == 0 or b == 0: return([a,b])\n if a//(2*b) > 0: return(pr(a - a//(2*b) * 2 * b , b))\n if b//(2*a) > 0: return(pr(a, b - b//(2*a) * 2 * a))\n return [a,b]\n\nans = pr(n, m)\n\nprint(ans[0], ans[1])\n", "passed": true, "time": 0.15, "memory": 14388.0, "status": "done"}, {"code": "a, b = tuple(map(int, input().split()))\n\ndef step(a, b):\n if a==0 or b==0:\n n = 0\n elif a > b:\n n = a//(2*b)\n a = a - (n*2*b)\n else:\n n = b//(2*a)\n b -= n*2*a\n\n if n != 0:\n return step(a, b)\n return a, b\nd = step(a, b)\nprint(d[0], d[1])\n", "passed": true, "time": 0.15, "memory": 14416.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nimport sys\n\n[a, b] = list(map(int, sys.stdin.readline().strip().split()))\n\nwhile a != 0 and b != 0:\n\ta_old, b_old = a, b\n\ta %= 2 * b\n\tif a == 0:\n\t\tbreak\n\tb %= 2 * a\n\tif a == a_old and b == b_old:\n\t\tbreak\n\nprint(a, b)\n", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "from math import log2\ndef minpow2(x,y):\n return int(log2(x//y))\n\na, b = list(map(int, input().split()))\nwhile a >0 and b>0:\n if a >= 2*b:\n a = a%(2*b)\n continue\n elif b>=2*a:\n b = b % (2*a)\n continue\n else:\n break\n\nprint(a,b)\n\n", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "a, b = map(int, input().split())\nwhile a != 0 and b != 0:\n\tif a >= 2 * b:\n\t\ta %= 2 * b\n\telif b >= 2 * a:\n\t\tb %= 2 * a\n\telse:\n\t\tbreak\nprint(a, b)", "passed": true, "time": 0.14, "memory": 14492.0, "status": "done"}, {"code": "def read():\n return list(map(int,input().split()))\na,b=read()\nwhile True:\n if a==0 or b==0:\n break\n elif a>=2*b:\n a%=2*b\n elif b>=2*a:\n b%=2*a\n else:\n break\nprint(a,b)\n \n \n", "passed": true, "time": 0.17, "memory": 14360.0, "status": "done"}, {"code": "def solve():\n n, m = list(map(int, input().split()))\n\n while True:\n if n == 0 or m == 0:\n print(n, m)\n return\n elif n >= 2*m:\n n = n % (2*m)\n continue\n elif m >= 2*n:\n m = m % (2*n)\n continue\n else:\n print(n,m)\n return\n\n\ndef __starting_point():\n solve()\n\n\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14348.0, "status": "done"}] | [{"input": "12 5\n", "output": "0 1\n"}, {"input": "31 12\n", "output": "7 12\n"}, {"input": "1000000000000000000 7\n", "output": "8 7\n"}, {"input": "31960284556200 8515664064180\n", "output": "14928956427840 8515664064180\n"}, {"input": "1000000000000000000 1000000000000000000\n", "output": "1000000000000000000 1000000000000000000\n"}, {"input": "1 1000\n", "output": "1 0\n"}, {"input": "1 1000000\n", "output": "1 0\n"}, {"input": "1 1000000000000000\n", "output": "1 0\n"}, {"input": "1 99999999999999999\n", "output": "1 1\n"}, {"input": "1 4\n", "output": "1 0\n"}, {"input": "1000000000000001 500000000000000\n", "output": "1 0\n"}, {"input": "1 1000000000000000000\n", "output": "1 0\n"}, {"input": "2 4\n", "output": "2 0\n"}, {"input": "2 1\n", "output": "0 1\n"}, {"input": "6 19\n", "output": "6 7\n"}, {"input": "22 5\n", "output": "0 1\n"}, {"input": "10000000000000000 100000000000000001\n", "output": "0 1\n"}, {"input": "1 1000000000000\n", "output": "1 0\n"}, {"input": "2 1000000000000000\n", "output": "2 0\n"}, {"input": "2 10\n", "output": "2 2\n"}, {"input": "51 100\n", "output": "51 100\n"}, {"input": "3 1000000000000000000\n", "output": "3 4\n"}, {"input": "1000000000000000000 3\n", "output": "4 3\n"}, {"input": "1 10000000000000000\n", "output": "1 0\n"}, {"input": "8796203 7556\n", "output": "1019 1442\n"}, {"input": "5 22\n", "output": "1 0\n"}, {"input": "1000000000000000000 1\n", "output": "0 1\n"}, {"input": "1 100000000000\n", "output": "1 0\n"}, {"input": "2 1000000000000\n", "output": "2 0\n"}, {"input": "5 4567865432345678\n", "output": "5 8\n"}, {"input": "576460752303423487 288230376151711743\n", "output": "1 1\n"}, {"input": "499999999999999999 1000000000000000000\n", "output": "3 2\n"}, {"input": "1 9999999999999\n", "output": "1 1\n"}, {"input": "103 1000000000000000000\n", "output": "103 196\n"}, {"input": "7 1\n", "output": "1 1\n"}, {"input": "100000000000000001 10000000000000000\n", "output": "1 0\n"}, {"input": "5 10\n", "output": "5 0\n"}, {"input": "7 11\n", "output": "7 11\n"}, {"input": "1 123456789123456\n", "output": "1 0\n"}, {"input": "5000000000000 100000000000001\n", "output": "0 1\n"}, {"input": "1000000000000000 1\n", "output": "0 1\n"}, {"input": "1000000000000000000 499999999999999999\n", "output": "2 3\n"}, {"input": "10 5\n", "output": "0 5\n"}, {"input": "9 18917827189272\n", "output": "9 0\n"}, {"input": "179 100000000000497000\n", "output": "179 270\n"}, {"input": "5 100000000000001\n", "output": "1 1\n"}, {"input": "5 20\n", "output": "5 0\n"}, {"input": "100000001 50000000\n", "output": "1 0\n"}, {"input": "345869461223138161 835002744095575440\n", "output": "1 0\n"}, {"input": "8589934592 4294967296\n", "output": "0 4294967296\n"}, {"input": "4 8\n", "output": "4 0\n"}, {"input": "1 100000000000000000\n", "output": "1 0\n"}, {"input": "1000000000000000000 333333333333333\n", "output": "1000 1333\n"}, {"input": "25 12\n", "output": "1 0\n"}, {"input": "24 54\n", "output": "0 6\n"}, {"input": "6 12\n", "output": "6 0\n"}, {"input": "129200000000305 547300000001292\n", "output": "1 0\n"}, {"input": "1000000000000000000 49999999999999999\n", "output": "20 39\n"}, {"input": "1 2\n", "output": "1 0\n"}, {"input": "1 123456789876\n", "output": "1 0\n"}, {"input": "2 3\n", "output": "2 3\n"}, {"input": "1 3\n", "output": "1 1\n"}, {"input": "1 1\n", "output": "1 1\n"}, {"input": "19 46\n", "output": "3 2\n"}, {"input": "3 6\n", "output": "3 0\n"}, {"input": "129 1000000000000000000\n", "output": "1 0\n"}, {"input": "12 29\n", "output": "0 1\n"}, {"input": "8589934592 2147483648\n", "output": "0 2147483648\n"}, {"input": "2147483648 8589934592\n", "output": "2147483648 0\n"}, {"input": "5 6\n", "output": "5 6\n"}, {"input": "1000000000000000000 2\n", "output": "0 2\n"}, {"input": "2 7\n", "output": "2 3\n"}, {"input": "17174219820754872 61797504734333370\n", "output": "17174219820754872 27449065092823626\n"}, {"input": "49 100\n", "output": "1 0\n"}, {"input": "7 17\n", "output": "1 1\n"}, {"input": "1000000000000000000 10000001\n", "output": "0 1\n"}, {"input": "49999999999999999 2\n", "output": "3 2\n"}, {"input": "49999999999999999 1\n", "output": "1 1\n"}, {"input": "576460752303423487 2\n", "output": "3 2\n"}, {"input": "19395 19395\n", "output": "19395 19395\n"}, {"input": "19394 19394\n", "output": "19394 19394\n"}] |
|
176 | Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.
-----Input-----
The only line contains three space-separated integers k, a and b (1 ≤ k ≤ 10^18; - 10^18 ≤ a ≤ b ≤ 10^18).
-----Output-----
Print the required number.
-----Examples-----
Input
1 1 10
Output
10
Input
2 -4 4
Output
5 | interview | [{"code": "s=input()\nast=[int(i) for i in s.split(' ')]\nk,a,b=ast[0],ast[1],ast[2]\ns1=(a-1)//k\ns2=b//k\nprint(s2-s1)\n", "passed": true, "time": 0.24, "memory": 14372.0, "status": "done"}, {"code": "k, a, b = list(map(int, input().split()))\nf = (a + k - 1) // k\nl = b // k\nprint(l - f + 1)\n", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "k, a, b = [int(i) for i in input().split()]\nif a % k != 0:\n a += k - a % k\nif (b - a + 1) % k == 0:\n print((b-a+1)//k)\nelse:\n print((b-a+1)//k+1)\n\n", "passed": true, "time": 0.24, "memory": 14508.0, "status": "done"}, {"code": "3\n\nk, a, b = list(map(int, input().split()))\nprint((b // k) - (a - 1) // k)\n", "passed": true, "time": 0.24, "memory": 14508.0, "status": "done"}, {"code": "k, a, b = map(int, input().split())\nif a % k:\n a += k - a % k\nb -= b % k\nprint(b // k - a // k + 1)", "passed": true, "time": 0.14, "memory": 14592.0, "status": "done"}, {"code": "def f(a, b, k):\n if a == 0:\n res = b // k + 1\n else:\n res = b // k - (a - 1) // k\n return res\n\nk, a, b = [int(i) for i in input().split()]\nif b <= 0:\n res = f(-b, -a, k)\nelif a < 0:\n res = f(1, -a, k) + f(0, b, k)\nelse:\n res = f(a, b, k)\nprint(res)\n \n", "passed": true, "time": 0.24, "memory": 14372.0, "status": "done"}, {"code": "k, a, b = list(map(int, input().split()))\nans = 0\nif b < 0:\n a *= -1\n b *= -1\n (b, a) = (a, b)\nif a > 0 and b >= 0:\n ans += b // k - (a - 1) // k\nelse:\n ans += b // k\n ans += 1\n ans += (-a)//k\n\nprint(ans)\n \n \n \n", "passed": true, "time": 0.14, "memory": 14652.0, "status": "done"}, {"code": "k, a, b = map(int, input().split())\nprint(b // k - (a - 1) // k)", "passed": true, "time": 0.15, "memory": 14588.0, "status": "done"}, {"code": "k, a, b = list(map(int, input().split()))\n\nif a < 0 and b > 0:\n print(-a // k + b // k + 1)\nelif a > 0 and b > 0:\n print(b // k - (a - 1) // k)\nelif a < 0 and b < 0:\n print(-a // k - (-b - 1) // k)\nelif a < 0 and b == 0:\n print(-a // k + 1)\nelif b > 0 and a == 0:\n print(b // k + 1)\nelse:\n print(1)\n", "passed": true, "time": 0.15, "memory": 14612.0, "status": "done"}, {"code": "k, l, r = map(int, input().split())\np = l // k\nif(l % k > 0):\n p += 1\nl = p * k\no = (r - l) // k + 1\nif(l > r):\n o = 0\nprint(o)", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "k,a,b=map(int,input().split())\nprint(b//k-(a-1)//k)", "passed": true, "time": 0.16, "memory": 14556.0, "status": "done"}, {"code": "k, a, b = map(int, input().split())\na += k * 10**18 + k\nb += k * 10**18 + k\nprint(b // k - (a - 1) // k)", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "k, a, b = map(int, input().split())\n\nqa, ra = divmod(a, k)\nqb, rb = divmod(b, k)\n\nka = a + (0 if ra == 0 else (k - ra))\nkb = b - rb\n\nif ka <= kb:\n\tprint((kb - ka) // k + 1)\nelse:\n\tprint(0)", "passed": true, "time": 0.14, "memory": 14560.0, "status": "done"}, {"code": "k, a, b = map(int, input().split())\na = ((a - 1) // k + 1) * k\nb -= b % k\nprint(max(0, (b - a + 1) // k + (k != 1)))", "passed": true, "time": 0.14, "memory": 14460.0, "status": "done"}, {"code": "\"\"\"\nCodeforces Testing Round #12\n\nProblem 597A Divisibility\n\n@author yamaton\n@date 2015-11-11\n\"\"\"\n\nimport math\nimport random\nimport sys\n\nimport functools\n\n\ndef solve(k, a, b):\n return b // k - (a - 1) // k\n\n\ndef p(*args, **kwargs):\n return print(file=sys.stderr, *args, **kwargs)\n\n\ndef main():\n [k, a, b] = [int(i) for i in input().strip().split()]\n result = solve(k, a, b)\n print(result)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.17, "memory": 14492.0, "status": "done"}, {"code": "inp = input().split()\nk = int(inp[0])\na = int(inp[1])\nb = int(inp[2])\nans = 0\nif (a > b) :\n c = a\n a = b\n b = c\nif a > 0 and b > 0 :\n ans = b // k - ((a - 1) // k)\nelif a < 0 and b < 0 :\n ans = 0 - (((a - 1) // k) - b // k)\nelif a < 0 :\n ans = (0 - a) // k + b // k + 1\nelse :\n ans = b // k + 1\nprint (ans)", "passed": true, "time": 0.14, "memory": 14412.0, "status": "done"}, {"code": "k, a, b = list(map(int, input().split()))\nbelow_a = a//k\nbelow_b = b//k\nans = below_b - below_a\nif a%k==0:\n ans += 1\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14480.0, "status": "done"}, {"code": "k, a, b = [int(i) for i in input().split()]\nif a % k != 0:\n a += k - a % k\nif (b - a + 1) % k == 0:\n print((b-a+1)//k)\nelse:\n print((b-a+1)//k+1)", "passed": true, "time": 0.15, "memory": 14256.0, "status": "done"}, {"code": "k, a, b = input().split(' ')\nk = int(k)\na = int(a)\nb = int(b)\nif (a == b) and (a % k == 0):\n print('1')\nelse:\n if (a * b > 0):\n a = abs(a)\n b = abs(b)\n if (a > b):\n tmp = a\n a = b\n b = tmp\n print((b // k) - ((a - 1) // k))\n elif (a * b < 0):\n if (a > 0):\n tmp = a\n a = b\n b = tmp\n print((b // k) + (abs(a) // k) + 1)\n else:\n a = abs(a)\n b = abs(b)\n if (a != 0):\n tmp = a\n a = b\n b = tmp\n print((b // k) + 1)\n", "passed": true, "time": 0.15, "memory": 14556.0, "status": "done"}, {"code": "k,a,b=map(int,input().split())\nprint(b//k-(a-1)//k)", "passed": true, "time": 0.15, "memory": 14464.0, "status": "done"}, {"code": "k, a, b = map(int, input().split())\nans = 0\nif a < 0 and b <= 0:\n a, b = abs(b), abs(a)\nif a > 0 and a % k:\n a = a + k - a % k\n if a <= b:\n ans += ((b - a) // k + 1)\nelif a >= 0:\n ans += ((b - a) // k + 1)\nelif a < 0 and abs(a) % k:\n a = abs(a) - abs(a) % k\n ans += (a // k + 1)\n ans += (b // k)\nelif a < 0:\n ans += (abs(a) // k + 1)\n ans += (b // k)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14588.0, "status": "done"}, {"code": "# your code goes here\nk, a, b = map(int, input().split())\n#//=floor division\nfloor_a = a//k\nfloor_b = b//k\nans = floor_b - floor_a\nif a%k==0:\n ans += 1\nprint(ans)", "passed": true, "time": 0.14, "memory": 14464.0, "status": "done"}, {"code": "ints = lambda:list(map(int,input().split()))\nrd = lambda:input()\nimport math\nk,a,b=ints()\nl = a//k if a%k==0 else a//k+1\nr = b//k\nprint(int(r-l+1))\n", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "k, a, b = list(map(int, input().split()))\n\nprint(( (b // k) - ((a - 1) // k)\n\t))\n", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "k,a,b=map(int,input().split())\nprint(b//k-(a-1)//k)", "passed": true, "time": 0.24, "memory": 14556.0, "status": "done"}] | [{"input": "1 1 10\n", "output": "10\n"}, {"input": "2 -4 4\n", "output": "5\n"}, {"input": "1 1 1\n", "output": "1\n"}, {"input": "1 0 0\n", "output": "1\n"}, {"input": "1 0 1\n", "output": "2\n"}, {"input": "1 10181 10182\n", "output": "2\n"}, {"input": "1 10182 10183\n", "output": "2\n"}, {"input": "1 -191 1011\n", "output": "1203\n"}, {"input": "2 0 0\n", "output": "1\n"}, {"input": "2 0 1\n", "output": "1\n"}, {"input": "2 1 2\n", "output": "1\n"}, {"input": "2 2 3\n", "output": "1\n"}, {"input": "2 -1 0\n", "output": "1\n"}, {"input": "2 -1 1\n", "output": "1\n"}, {"input": "2 -7 -6\n", "output": "1\n"}, {"input": "2 -7 -5\n", "output": "1\n"}, {"input": "2 -6 -6\n", "output": "1\n"}, {"input": "2 -6 -4\n", "output": "2\n"}, {"input": "2 -6 13\n", "output": "10\n"}, {"input": "2 -19171 1911\n", "output": "10541\n"}, {"input": "3 123 456\n", "output": "112\n"}, {"input": "3 124 456\n", "output": "111\n"}, {"input": "3 125 456\n", "output": "111\n"}, {"input": "3 381 281911\n", "output": "93844\n"}, {"input": "3 381 281912\n", "output": "93844\n"}, {"input": "3 381 281913\n", "output": "93845\n"}, {"input": "3 382 281911\n", "output": "93843\n"}, {"input": "3 382 281912\n", "output": "93843\n"}, {"input": "3 382 281913\n", "output": "93844\n"}, {"input": "3 383 281911\n", "output": "93843\n"}, {"input": "3 383 281912\n", "output": "93843\n"}, {"input": "3 383 281913\n", "output": "93844\n"}, {"input": "3 -381 281911\n", "output": "94098\n"}, {"input": "3 -381 281912\n", "output": "94098\n"}, {"input": "3 -381 281913\n", "output": "94099\n"}, {"input": "3 -380 281911\n", "output": "94097\n"}, {"input": "3 -380 281912\n", "output": "94097\n"}, {"input": "3 -380 281913\n", "output": "94098\n"}, {"input": "3 -379 281911\n", "output": "94097\n"}, {"input": "3 -379 281912\n", "output": "94097\n"}, {"input": "3 -379 281913\n", "output": "94098\n"}, {"input": "3 -191381 -1911\n", "output": "63157\n"}, {"input": "3 -191381 -1910\n", "output": "63157\n"}, {"input": "3 -191381 -1909\n", "output": "63157\n"}, {"input": "3 -191380 -1911\n", "output": "63157\n"}, {"input": "3 -191380 -1910\n", "output": "63157\n"}, {"input": "3 -191380 -1909\n", "output": "63157\n"}, {"input": "3 -191379 -1911\n", "output": "63157\n"}, {"input": "3 -191379 -1910\n", "output": "63157\n"}, {"input": "3 -191379 -1909\n", "output": "63157\n"}, {"input": "3 -2810171 0\n", "output": "936724\n"}, {"input": "3 0 29101\n", "output": "9701\n"}, {"input": "3 -2810170 0\n", "output": "936724\n"}, {"input": "3 0 29102\n", "output": "9701\n"}, {"input": "3 -2810169 0\n", "output": "936724\n"}, {"input": "3 0 29103\n", "output": "9702\n"}, {"input": "1 -1000000000000000000 1000000000000000000\n", "output": "2000000000000000001\n"}, {"input": "2 -1000000000000000000 1000000000000000000\n", "output": "1000000000000000001\n"}, {"input": "3 -1000000000000000000 1000000000000000000\n", "output": "666666666666666667\n"}, {"input": "4 -1000000000000000000 1000000000000000000\n", "output": "500000000000000001\n"}, {"input": "5 -1000000000000000000 1000000000000000000\n", "output": "400000000000000001\n"}, {"input": "6 -1000000000000000000 1000000000000000000\n", "output": "333333333333333333\n"}, {"input": "7 -1000000000000000000 1000000000000000000\n", "output": "285714285714285715\n"}, {"input": "1 -1000000000000000000 -100000000000000000\n", "output": "900000000000000001\n"}, {"input": "2 -1000000000000000000 -10000000000000000\n", "output": "495000000000000001\n"}, {"input": "3 -1000000000000000000 -10218000000000000\n", "output": "329927333333333334\n"}, {"input": "4 -1000000000000000000 -320110181919100\n", "output": "249919972454520226\n"}, {"input": "5 -1000000000000000000 -402710171917\n", "output": "199999919457965617\n"}, {"input": "6 -1000000000000000000 -6666666666\n", "output": "166666665555555556\n"}, {"input": "7 -1000000000000000000 -77777777777778\n", "output": "142846031746031746\n"}, {"input": "1000000000000000000 -1000000000000000000 1000000000000000000\n", "output": "3\n"}, {"input": "1000000000000000000 0 1000000000000000000\n", "output": "2\n"}, {"input": "1000000000000000000 1000000000000000000 1000000000000000000\n", "output": "1\n"}, {"input": "100000000000000321 1000000000000000000 1000000000000000000\n", "output": "0\n"}, {"input": "100000000000000321 -1000000000000000000 1000000000000000000\n", "output": "19\n"}, {"input": "1000000000000000000 0 0\n", "output": "1\n"}, {"input": "1000000000000000000 1 1\n", "output": "0\n"}, {"input": "1000000000000000000 -1 -1\n", "output": "0\n"}, {"input": "1000000000000000000 -2 -1\n", "output": "0\n"}, {"input": "142000000000000271 -228118171 -1382811\n", "output": "0\n"}, {"input": "1 1 1000000000000000000\n", "output": "1000000000000000000\n"}] |
|
177 | Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...
Your task is to print the $k$-th digit of this sequence.
-----Input-----
The first and only line contains integer $k$ ($1 \le k \le 10000$) — the position to process ($1$-based index).
-----Output-----
Print the $k$-th digit of the resulting infinite sequence.
-----Examples-----
Input
7
Output
7
Input
21
Output
5 | interview | [{"code": "a = int(input())\ns = \"\"\nfor i in range(1, a+1):\n s += str(i)\nprint(s[a-1])", "passed": true, "time": 0.37, "memory": 14292.0, "status": "done"}, {"code": "k = int(input())\ns = \"\"\ni = 1\nwhile len(s) < k + 10:\n\ts += str(i)\n\ti += 1\nk -= 1\nprint(s[k])", "passed": true, "time": 0.17, "memory": 14616.0, "status": "done"}, {"code": "s='0'\nfor i in range(1,10000):\n s+=str(i)\nprint(s[int(input())])\n\n", "passed": true, "time": 0.33, "memory": 14604.0, "status": "done"}, {"code": "from sys import stdin\nimport math\nfrom collections import defaultdict\n\n\n\n\n\n#stdin = open('input.txt','r')\n\n\n\n\nI = stdin.readline\n\n\ns = []\nfor i in range(1,10000):\n\ts.append(str(i))\n\ns = \"\".join(s)\n\nn = int(I())\nprint(s[n-1])", "passed": true, "time": 0.45, "memory": 14352.0, "status": "done"}, {"code": "k=int(input())\nl=''\nfor i in range(1,k+1):\n l=l+str(i)\nprint(l[k-1])\n", "passed": true, "time": 1.03, "memory": 14636.0, "status": "done"}, {"code": "n=int(input())\nx=1\nwhile n!=0:\n for i in range(len(str(x))):\n if n!=0:\n s=str(x)[i]\n n-=1\n x+=1\nprint(s)\n \n", "passed": true, "time": 0.23, "memory": 14356.0, "status": "done"}, {"code": "n = int(input())\na = ''\ni = 0\nwhile len(a) < n:\n i += 1\n a += str(i)\n\nprint(a[n - 1])\n", "passed": true, "time": 0.21, "memory": 14500.0, "status": "done"}, {"code": "s = ''\nfor i in range(1, 3000):\n s += str(i)\nk = int(input())\nprint(s[k - 1])", "passed": true, "time": 0.2, "memory": 14588.0, "status": "done"}, {"code": "s = \"12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000\"\nprint(s[int(input()) - 1])\n", "passed": true, "time": 0.14, "memory": 14624.0, "status": "done"}, {"code": "S=\"\"\nfor i in range(1,10001): S+=str(i)\nprint(S[int(input())-1])\n", "passed": true, "time": 0.32, "memory": 14508.0, "status": "done"}, {"code": "k = int(input())\n\ntest = \"\"\n\nfor i in range(1,k+1):\n test = test + str(i)\n\nprint(test[k-1])", "passed": true, "time": 0.2, "memory": 14632.0, "status": "done"}, {"code": "k = int(input())\nstring = str()\nfor i in range(1,k+1):\n string += str(i)\n#print(string)\nprint(string[k-1])", "passed": true, "time": 1.03, "memory": 14496.0, "status": "done"}, {"code": "a = ''\ni = 1\nn = int(input())\nwhile len(a) < 10000:\n a += str(i)\n i += 1\nprint(a[n - 1])\n", "passed": true, "time": 0.37, "memory": 14496.0, "status": "done"}, {"code": "a = int(input())\ns = \"\"\nfor i in range(1,10001):\n s = s+str(i)\n\nprint(s[a-1])", "passed": true, "time": 0.32, "memory": 14620.0, "status": "done"}, {"code": "s = ''\nfor x in range(1,10000):\n\ts += str(x)\nk = int(input())\nprint(s[k-1])", "passed": true, "time": 0.31, "memory": 14364.0, "status": "done"}, {"code": "n=int(input())\ni=1\nstri=\"\"\nwhile(i<=n):\n stri+=str(i)\n i+=1\nprint(stri[n-1])\n", "passed": true, "time": 0.21, "memory": 14580.0, "status": "done"}, {"code": "s = ''\n\nfor i in range(1,100000000):\n s += str(i)\n if len(s) >= 11000:\n break\n\nprint(s[int(input())-1])", "passed": true, "time": 0.36, "memory": 14428.0, "status": "done"}, {"code": "def f(x): #including x\n\tdig, cnt = 1, 9\n\tans = 0\n\twhile dig != len(str(x)):\n\t\tans += dig * cnt\n\t\tdig += 1\n\t\tcnt *= 10\n\tans += (x - (cnt // 9) + 1) * dig\n\treturn ans\nk = int(input())\nl, r = 1, 1000000000000\nif k == 1:\n print(1)\n return\nwhile l < r:\n\tmid = (l + r + 1) >> 1\n\tif f(mid) < k:\n\t\tl = mid\n\telse:\n\t\tr = mid - 1\nk -= f(l)\nl += 1\nprint(str(l)[k - 1])", "passed": true, "time": 0.15, "memory": 14388.0, "status": "done"}, {"code": "a = int(input())\nb = ''\nfor i in range(1,a+1):\n b = b+str(i)\nprint(b[a-1])\n", "passed": true, "time": 0.2, "memory": 14404.0, "status": "done"}, {"code": "import sys,math\n\ndef read_int():\n\treturn int(sys.stdin.readline().strip())\n\ndef read_int_list():\n\treturn list(map(int,sys.stdin.readline().strip().split()))\n\ndef read_string():\n\treturn sys.stdin.readline().strip()\n\ndef read_string_list(delim=\" \"):\n\treturn sys.stdin.readline().strip().split(delim)\n\n\n###### Author : Samir Vyas #######\n###### Write Code Below #######\nseq = \"\"\n\nfor i in range(1,3000):\n\tseq += str(i)\n\nprint(seq[read_int()-1])", "passed": true, "time": 0.19, "memory": 14388.0, "status": "done"}, {"code": "ST=\"\"\nfor i in range(1,10001):\n ST += str(i)\n \nprint(ST[int(input())-1])", "passed": true, "time": 0.45, "memory": 14316.0, "status": "done"}, {"code": "k=10000\ni=1\ns=''\nwhile i<=k:\n s=s+str(i)\n i=i+1\nn=int(input())\nprint(s[n-1])", "passed": true, "time": 0.33, "memory": 14508.0, "status": "done"}, {"code": "x = []\nfor i in range(1,10001):\n x.append(str(i))\nx = \"\".join(x)\nk = int(input())\nprint(x[k-1])\n", "passed": true, "time": 0.3, "memory": 14372.0, "status": "done"}, {"code": "k=int(input())\nl=[str(n) for n in range(1,k+1)]\nx=\"\"\na=x.join(l)\nprint(a[k-1])", "passed": true, "time": 0.19, "memory": 14592.0, "status": "done"}, {"code": "a=[]\ni=1\nwhile len(a)<=10000 :\n\tl=str(i)\n\tfor p in l:\n\t\ta.append(p)\n\ti+=1\n\ng=int(input())\nprint(a[g-1])", "passed": true, "time": 0.24, "memory": 14356.0, "status": "done"}] | [{"input": "7\n", "output": "7\n"}, {"input": "21\n", "output": "5\n"}, {"input": "1\n", "output": "1\n"}, {"input": "2\n", "output": "2\n"}, {"input": "3\n", "output": "3\n"}, {"input": "4\n", "output": "4\n"}, {"input": "5\n", "output": "5\n"}, {"input": "6\n", "output": "6\n"}, {"input": "8\n", "output": "8\n"}, {"input": "9\n", "output": "9\n"}, {"input": "10\n", "output": "1\n"}, {"input": "12\n", "output": "1\n"}, {"input": "188\n", "output": "9\n"}, {"input": "189\n", "output": "9\n"}, {"input": "190\n", "output": "1\n"}, {"input": "191\n", "output": "0\n"}, {"input": "192\n", "output": "0\n"}, {"input": "193\n", "output": "1\n"}, {"input": "194\n", "output": "0\n"}, {"input": "195\n", "output": "1\n"}, {"input": "196\n", "output": "1\n"}, {"input": "197\n", "output": "0\n"}, {"input": "198\n", "output": "2\n"}, {"input": "199\n", "output": "1\n"}, {"input": "200\n", "output": "0\n"}, {"input": "300\n", "output": "6\n"}, {"input": "400\n", "output": "1\n"}, {"input": "417\n", "output": "5\n"}, {"input": "521\n", "output": "1\n"}, {"input": "511\n", "output": "2\n"}, {"input": "2878\n", "output": "9\n"}, {"input": "2879\n", "output": "9\n"}, {"input": "2880\n", "output": "6\n"}, {"input": "2881\n", "output": "9\n"}, {"input": "2882\n", "output": "9\n"}, {"input": "2883\n", "output": "7\n"}, {"input": "2884\n", "output": "9\n"}, {"input": "2885\n", "output": "9\n"}, {"input": "2886\n", "output": "8\n"}, {"input": "2887\n", "output": "9\n"}, {"input": "2888\n", "output": "9\n"}, {"input": "2889\n", "output": "9\n"}, {"input": "2890\n", "output": "1\n"}, {"input": "2891\n", "output": "0\n"}, {"input": "2892\n", "output": "0\n"}, {"input": "2893\n", "output": "0\n"}, {"input": "2894\n", "output": "1\n"}, {"input": "2895\n", "output": "0\n"}, {"input": "2896\n", "output": "0\n"}, {"input": "2897\n", "output": "1\n"}, {"input": "2898\n", "output": "1\n"}, {"input": "2899\n", "output": "0\n"}, {"input": "2900\n", "output": "0\n"}, {"input": "2901\n", "output": "2\n"}, {"input": "3000\n", "output": "2\n"}, {"input": "4000\n", "output": "7\n"}, {"input": "5000\n", "output": "2\n"}, {"input": "6000\n", "output": "7\n"}, {"input": "7000\n", "output": "2\n"}, {"input": "8000\n", "output": "7\n"}, {"input": "9000\n", "output": "2\n"}, {"input": "9900\n", "output": "5\n"}, {"input": "9990\n", "output": "2\n"}, {"input": "9991\n", "output": "7\n"}, {"input": "9992\n", "output": "7\n"}, {"input": "9993\n", "output": "5\n"}, {"input": "9994\n", "output": "2\n"}, {"input": "9995\n", "output": "7\n"}, {"input": "9996\n", "output": "7\n"}, {"input": "9997\n", "output": "6\n"}, {"input": "9998\n", "output": "2\n"}, {"input": "9999\n", "output": "7\n"}, {"input": "10000\n", "output": "7\n"}, {"input": "100\n", "output": "5\n"}, {"input": "10000\n", "output": "7\n"}, {"input": "6\n", "output": "6\n"}, {"input": "9999\n", "output": "7\n"}, {"input": "10\n", "output": "1\n"}, {"input": "9\n", "output": "9\n"}, {"input": "193\n", "output": "1\n"}, {"input": "1\n", "output": "1\n"}] |
|
178 | A telephone number is a sequence of exactly $11$ digits such that its first digit is 8.
Vasya and Petya are playing a game. Initially they have a string $s$ of length $n$ ($n$ is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a character and erase it from the current string. For example, if the current string 1121, after the player's move it may be 112, 111 or 121. The game ends when the length of string $s$ becomes 11. If the resulting string is a telephone number, Vasya wins, otherwise Petya wins.
You have to determine if Vasya has a winning strategy (that is, if Vasya can win the game no matter which characters Petya chooses during his moves).
-----Input-----
The first line contains one integer $n$ ($13 \le n < 10^5$, $n$ is odd) — the length of string $s$.
The second line contains the string $s$ ($|s| = n$) consisting only of decimal digits.
-----Output-----
If Vasya has a strategy that guarantees him victory, print YES.
Otherwise print NO.
-----Examples-----
Input
13
8380011223344
Output
YES
Input
15
807345619350641
Output
NO
-----Note-----
In the first example Vasya needs to erase the second character. Then Petya cannot erase a character from the remaining string 880011223344 so that it does not become a telephone number.
In the second example after Vasya's turn Petya can erase one character character 8. The resulting string can't be a telephone number, because there is no digit 8 at all. | interview | [{"code": "n, s = int(input()), input()\ncnt = (n - 11) // 2\ncnt_8 = len(s[:n - 10].split('8')) - 1\nif (cnt >= cnt_8):\n\tprint (\"NO\")\nelse:\n\tprint (\"YES\")", "passed": true, "time": 0.15, "memory": 14580.0, "status": "done"}, {"code": "def main():\n n = int(input())\n arr = list(map(int, input()))\n a = arr.count(8)\n if a <= (n - 11) // 2:\n print(\"NO\")\n return 0\n i = -1\n cnt = 1 + (n - 11) // 2\n while cnt:\n i += 1\n if arr[i] == 8:\n cnt -= 1\n if i > n - 11:\n print(\"NO\")\n return 0\n print(\"YES\")\n return 0\n\nmain()", "passed": true, "time": 0.24, "memory": 14392.0, "status": "done"}, {"code": "N = int(input())\nS = input()\nA, B = 0, 0\nfor i in range(N-10):\n if S[i] == \"8\":\n A += 1\n else:\n B += 1\nif A > B:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14448.0, "status": "done"}, {"code": "from collections import Counter\n\nn = int(input())\ns = list(input())\n\nc = Counter(s[:-10])\nif c['8'] > len(s[:-10]) // 2:\n\tprint('YES')\nelse:\n\tprint('NO')", "passed": true, "time": 0.16, "memory": 14472.0, "status": "done"}, {"code": "n = int(input())\ns = input()\ncnt = 0\nfor i in range(n - 10):\n if s[i] == '8':\n cnt += 1\nif cnt >= ((n - 9) // 2):\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.14, "memory": 14528.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nnum = (n - 11) // 2\nnum2 = 0\nnum3 = -1\nfor i in range(n):\n if s[i] == \"8\":\n num2 += 1\n if num2 == num + 1:\n num3 = i\n break\nif num3 == -1 or num3 > num * 2:\n print(\"NO\")\nelse:\n print(\"YES\")\n", "passed": true, "time": 1.75, "memory": 14584.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\ncnt = 0\nfor i in range(n - 10):\n\tif s[i] == '8':\n\t\tcnt += 1\nsteps = (n - 11) // 2\nif cnt <= steps:\n\tprint(\"NO\")\nelse:\n\tprint(\"YES\")", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nif s[:n-10].count('8')> (n-11)//2:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.17, "memory": 14584.0, "status": "done"}, {"code": "n=int(input())\ns=input()\nt=s[:-10]\ncnt=t.count('8')\nif len(t)-cnt>=cnt:\n print('NO')\nelse:\n print('YES')", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}, {"code": "def main():\n n = int(input())\n s = input()\n eight = 0\n for i in range(n-11+1):\n if s[i] == '8':\n eight += 1\n\n if eight > (n-11)//2:\n print('YES')\n else:\n print('NO')\n\nmain()\n", "passed": true, "time": 0.15, "memory": 14456.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\ntorem = n - 11\n\nif s[:torem+1].count('8') > (torem+1)//2:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.16, "memory": 14608.0, "status": "done"}, {"code": "n, s = int(input()), input()\ns = s[:n-10]\na = s.count('8')\nb = len(s) - a\nprint('YES' if a >= b else 'NO')", "passed": true, "time": 0.15, "memory": 14428.0, "status": "done"}, {"code": "if (int(input()) - 9) // 2 <= input()[:-10].count('8'):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}, {"code": "s = int(input())\nstring = input()\ncounter = 0\narray = []\nfor i in range(len(string)):\n if string[i] == '8':\n counter += 1\n array.append(i)\nif (s - 11) // 2 >= counter:\n print('NO')\nelif (s - 11) // 2 < counter:\n if array[0] > (s - 11) // 2:\n print('NO')\n elif array[(s - 11) // 2] - ((s - 11) // 2) <= (s - 11) // 2:\n print('YES')\n elif array[(s - 11) // 2] - ((s - 11) // 2) > (s - 11) // 2:\n print('NO')\nelse:\n print('YES')", "passed": true, "time": 0.15, "memory": 14328.0, "status": "done"}, {"code": "n = int(input())\nx = input()\n\nr = (n-11)//2\np = x[:2*r+1]\nif p.count(\"8\") >= r+1:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14452.0, "status": "done"}, {"code": "n=int(input())\ns=input()\nt=s[:-10]\ncnt=t.count('8')\nif len(t)-cnt>cnt:\n print('NO')\nelse:\n print('YES')", "passed": true, "time": 0.24, "memory": 14316.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\nN=int(input())\nS=input().strip()\n\nP=(N-11)//2\n\nfrom collections import deque\nL=deque(S)\ncount=0\n\nfor j in range(P):\n while len(L)!=0 and L[0]==\"8\":\n L.popleft()\n count+=1\n\n if len(L)==0:\n print(\"YES\")\n return\n\n L.popleft()\n\n while len(L)!=0 and L[0]==\"8\":\n L.popleft()\n count+=1\n\nif count>P:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14580.0, "status": "done"}, {"code": "import sys\nn = int(input())\ns = input()\nk = (n - 11) // 2\nlicz = 0\nfor i in range(n):\n\tif s[i] == '8':\n\t\tlicz += 1\nif licz <= k:\n\tprint(\"NO\")\n\treturn\nlicz = 0\ni = -1\nwhile True:\n\ti += 1\n\tif s[i] == '8':\n\t\tlicz += 1\n\tif licz == k + 1:\n\t\tbreak\nif i > 2 * k:\n\tprint(\"NO\")\nelse:\n\tprint(\"YES\")", "passed": true, "time": 0.15, "memory": 14580.0, "status": "done"}, {"code": "n = int(input())\ns = str(input())\ncount = 0\np = []\nfor i in range(n):\n\tif s[i] == \"8\":\n\t\tcount+=1\n\t\tp.append(i)\nmoves = int((n - 11)/2)\nif moves >= count:\n\tprint(\"NO\")\n\treturn\nelse:\n\tif p[moves] <= 2*moves:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\") \n\n", "passed": true, "time": 0.14, "memory": 14500.0, "status": "done"}, {"code": "''' CODED WITH LOVE BY SATYAM KUMAR '''\n\nfrom sys import stdin, stdout\nimport cProfile, math\nfrom collections import Counter,defaultdict\nfrom bisect import bisect_left,bisect,bisect_right\nimport itertools\nfrom copy import deepcopy\nfrom fractions import Fraction\nimport sys, threading\nimport operator as op\nfrom functools import reduce\nsys.setrecursionlimit(10**6) # max depth of recursion\nthreading.stack_size(2**27) # new thread will get stack of such size\nfac_warmup = False\nprintHeap = str()\nmemory_constrained = False\nP = 10**9+7\nimport sys\n\nclass merge_find:\n def __init__(self,n):\n self.parent = list(range(n))\n self.size = [1]*n\n self.num_sets = n\n self.lista = [[_] for _ in range(n)]\n def find(self,a):\n to_update = []\n while a != self.parent[a]:\n to_update.append(a)\n a = self.parent[a]\n for b in to_update:\n self.parent[b] = a\n return self.parent[a]\n def merge(self,a,b):\n a = self.find(a)\n b = self.find(b)\n if a==b:\n return\n if self.size[a]<self.size[b]:\n a,b = b,a\n self.num_sets -= 1\n self.parent[b] = a\n self.size[a] += self.size[b]\n self.lista[a] += self.lista[b]\n def set_size(self, a):\n return self.size[self.find(a)]\n def __len__(self):\n return self.num_sets\n\ndef display(string_to_print):\n stdout.write(str(string_to_print) + \"\\n\")\n\ndef primeFactors(n): #n**0.5 complex \n factors = dict()\n for i in range(2,math.ceil(math.sqrt(n))+1): \n while n % i== 0: \n if i in factors:\n factors[i]+=1\n else: factors[i]=1\n n = n // i \n if n>2:\n factors[n]=1\n return (factors)\n\ndef fibonacci_modP(n,MOD):\n if n<2: return 1\n #print (n,MOD)\n return (cached_fn(fibonacci_modP, (n+1)//2, MOD)*cached_fn(fibonacci_modP, n//2, MOD) + cached_fn(fibonacci_modP, (n-1) // 2, MOD)*cached_fn(fibonacci_modP, (n-2) // 2, MOD)) % MOD\n\ndef factorial_modP_Wilson(n , p): \n if (p <= n): \n return 0\n res = (p - 1) \n for i in range (n + 1, p): \n res = (res * cached_fn(InverseEuler,i, p)) % p \n return res \n\ndef binary(n,digits = 20):\n b = bin(n)[2:]\n b = '0'*(20-len(b))+b\n return b\n\ndef isprime(n):\n \"\"\"Returns True if n is prime.\"\"\"\n if n < 4:\n return True\n if n % 2 == 0:\n return False\n if n % 3 == 0:\n return False\n i = 5\n w = 2\n while i * i <= n:\n if n % i == 0:\n return False\n i += w\n w = 6 - w\n return True\nfactorial_modP = []\ndef warm_up_fac(MOD):\n nonlocal factorial_modP,fac_warmup\n if fac_warmup: return\n factorial_modP= [1 for _ in range(fac_warmup_size+1)]\n for i in range(2,fac_warmup_size):\n factorial_modP[i]= (factorial_modP[i-1]*i) % MOD\n fac_warmup = True\n\ndef InverseEuler(n,MOD):\n return pow(n,MOD-2,MOD)\n\ndef nCr(n, r, MOD):\n nonlocal fac_warmup,factorial_modP\n if not fac_warmup:\n warm_up_fac(MOD)\n fac_warmup = True\n return (factorial_modP[n]*((pow(factorial_modP[r], MOD-2, MOD) * pow(factorial_modP[n-r], MOD-2, MOD)) % MOD)) % MOD\n\ndef test_print(*args):\n if testingMode:\n print(args)\n\ndef display_list(list1, sep=\" \"):\n stdout.write(sep.join(map(str, list1)) + \"\\n\")\n\ndef display_2D_list(li):\n for i in li:\n print(i)\ndef prefix_sum(li):\n sm = 0\n res = []\n for i in li:\n sm+=i\n res.append(sm)\n return res\n\ndef get_int():\n return int(stdin.readline().strip())\n\ndef get_tuple():\n return map(int, stdin.readline().split())\n\ndef get_list():\n return list(map(int, stdin.readline().split()))\nimport heapq,itertools\npq = [] # list of entries arranged in a heap\nentry_finder = {} # mapping of tasks to entries\nREMOVED = '<removed-task>' \ndef add_task(task, priority=0):\n 'Add a new task or update the priority of an existing task'\n if task in entry_finder:\n remove_task(task)\n count = next(counter)\n entry = [priority, count, task]\n entry_finder[task] = entry\n heapq.heappush(pq, entry)\n\ndef remove_task(task):\n 'Mark an existing task as REMOVED. Raise KeyError if not found.'\n entry = entry_finder.pop(task)\n entry[-1] = REMOVED\n\ndef pop_task():\n 'Remove and return the lowest priority task. Raise KeyError if empty.'\n while pq:\n priority, count, task = heapq.heappop(pq)\n if task is not REMOVED:\n del entry_finder[task]\n return task\n raise KeyError('pop from an empty priority queue')\nmemory = dict()\ndef clear_cache():\n nonlocal memory\n memory = dict()\ndef cached_fn(fn, *args):\n nonlocal memory\n if args in memory:\n return memory[args]\n else:\n result = fn(*args)\n memory[args] = result\n return result\n\ndef ncr (n,r):\n return math.factorial(n)/(math.factorial(n-r)*math.factorial(r))\ndef binary_serach(i,li):\n #print(\"Search for \",i)\n fn = lambda x: li[x]-x//i\n x = -1\n b = len(li)\n while b>=1:\n #print(b,x)\n while b+x<len(li) and fn(b+x)>0: #Change this condition 2 to whatever you like\n x+=b\n b=b//2\n return x\n\n# -------------------------------------------------------------- MAIN PROGRAM\nTestCases = False\ntestingMode = False\nfac_warmup_size = 10**5+100\noptimiseForReccursion = True #Can not be used clubbed with TestCases # WHen using recursive functions, use Python 3\nfrom math import factorial\n\ndef main():\n n = get_int()\n st = list(input())\n x = (n-11)//2\n y = x\n li = []\n for i in st:\n if i!='8':\n li.append(i)\n else:\n x-=1\n if x==-1:\n break\n print(\"YES\") if len(li)<=y else print(\"NO\")\n\n# --------------------------------------------------------------------- END=\n\n\nif TestCases: \n for i in range(get_int()): \n cProfile.run('main()') if testingMode else main(i) \nelse: (cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()", "passed": true, "time": 0.17, "memory": 17104.0, "status": "done"}, {"code": "N = int(input())\nS = input()\nturns = (N - 11) // 2\ncnt = 0\nfor i in range(N - 10):\n if S[i] == '8':\n cnt += 1\nif cnt >= turns + 1:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14400.0, "status": "done"}, {"code": "# coding: utf-8\nimport sys\nfrom heapq import heappush, heappop, heapify\nsys.setrecursionlimit(int(1e7))\n\ndef main():\n n = int(input().strip())\n s = input().strip()\n V = [i for i in range(n) if s[i]!='8']\n P = [i for i in range(n) if s[i]=='8']\n heapify(V)\n heapify(P)\n while len(V)+len(P)>11 and len(V)*len(P)>0:\n heappop(V)\n heappop(P)\n yes = len(V)==0 or (len(V)*len(P)>0 and P[0]<V[0])\n print('YES' if yes else 'NO')\n return\n\nwhile 1:\n try: main()\n except EOFError: break", "passed": true, "time": 0.14, "memory": 14500.0, "status": "done"}, {"code": "n = int(input())\nx = list(input())\na = (n-11+1)//2\nb = (n-11)//2\nfor i,ch in enumerate(x):\n if ch == '8':\n if b > 0:\n b -= 1\n x[i] = None\n else:\n if a > 0:\n a -= 1\n x[i] = None\nfor c in x:\n if c != None:\n if c != '8':\n print(\"NO\")\n else:\n print(\"YES\")\n break", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}] | [{"input": "13\n8380011223344\n", "output": "YES\n"}, {"input": "15\n807345619350641\n", "output": "NO\n"}, {"input": "19\n8181818181111111111\n", "output": "YES\n"}, {"input": "29\n88811188118181818118111111111\n", "output": "NO\n"}, {"input": "15\n980848088815548\n", "output": "NO\n"}, {"input": "13\n9999999998888\n", "output": "NO\n"}, {"input": "13\n0000008888888\n", "output": "NO\n"}, {"input": "13\n2480011223348\n", "output": "NO\n"}, {"input": "17\n87879887989788999\n", "output": "YES\n"}, {"input": "21\n123456788888812378910\n", "output": "NO\n"}, {"input": "15\n008880000000000\n", "output": "YES\n"}, {"input": "15\n888888888888888\n", "output": "YES\n"}, {"input": "15\n118388111881111\n", "output": "NO\n"}, {"input": "13\n8489031863524\n", "output": "YES\n"}, {"input": "17\n88818818888888888\n", "output": "YES\n"}, {"input": "13\n8899989999989\n", "output": "YES\n"}, {"input": "13\n1111111111188\n", "output": "NO\n"}, {"input": "13\n4366464181897\n", "output": "NO\n"}, {"input": "21\n888888888888888888888\n", "output": "YES\n"}, {"input": "15\n778887777777777\n", "output": "YES\n"}, {"input": "13\n8830011223344\n", "output": "YES\n"}, {"input": "13\n8888888888848\n", "output": "YES\n"}, {"input": "13\n1181111111111\n", "output": "NO\n"}, {"input": "13\n8000000000000\n", "output": "NO\n"}, {"input": "13\n1885498606803\n", "output": "YES\n"}, {"input": "15\n008888888888808\n", "output": "YES\n"}, {"input": "15\n961618782888818\n", "output": "NO\n"}, {"input": "13\n8789816534772\n", "output": "YES\n"}, {"input": "13\n8898173131489\n", "output": "YES\n"}, {"input": "13\n8800000000000\n", "output": "YES\n"}, {"input": "13\n2808118288444\n", "output": "NO\n"}, {"input": "15\n880000000000000\n", "output": "NO\n"}, {"input": "13\n8086296018422\n", "output": "YES\n"}, {"input": "13\n1841516902093\n", "output": "NO\n"}, {"input": "31\n0088888888888880000000000088888\n", "output": "YES\n"}, {"input": "13\n8559882884055\n", "output": "NO\n"}, {"input": "13\n3348729291920\n", "output": "NO\n"}, {"input": "17\n00000000088888888\n", "output": "NO\n"}, {"input": "13\n3388888888888\n", "output": "NO\n"}, {"input": "17\n11111118888888888\n", "output": "NO\n"}, {"input": "13\n6831940550586\n", "output": "NO\n"}, {"input": "15\n008888888888888\n", "output": "YES\n"}, {"input": "13\n8701234567790\n", "output": "NO\n"}, {"input": "13\n2822222225888\n", "output": "NO\n"}, {"input": "13\n0178528856351\n", "output": "NO\n"}, {"input": "13\n0088888888880\n", "output": "NO\n"}, {"input": "15\n181888888888888\n", "output": "YES\n"}, {"input": "109\n8800880880088088880888808880888088800880888088088088888080880000080000800000808008008800080008000888000808880\n", "output": "YES\n"}, {"input": "47\n08800008800800000088088008800080088800000808008\n", "output": "NO\n"}, {"input": "13\n2828222222222\n", "output": "NO\n"}, {"input": "95\n00008080008880080880888888088800008888000888800800000808808800888888088080888808880080808088008\n", "output": "YES\n"}, {"input": "71\n08880000000000808880808800880000008888808008008080880808088808808888080\n", "output": "NO\n"}, {"input": "41\n00008080008088080080888088800808808008880\n", "output": "NO\n"}, {"input": "23\n88338486848889054012825\n", "output": "YES\n"}, {"input": "23\n11868668827888348121163\n", "output": "NO\n"}, {"input": "13\n2877892266089\n", "output": "NO\n"}, {"input": "19\n1845988185966619131\n", "output": "NO\n"}, {"input": "17\n28681889938480569\n", "output": "YES\n"}, {"input": "19\n8881328076293351500\n", "output": "NO\n"}, {"input": "13\n8665978038580\n", "output": "NO\n"}, {"input": "13\n8896797594523\n", "output": "YES\n"}, {"input": "23\n79818882846090973951051\n", "output": "NO\n"}, {"input": "19\n8848893007368770958\n", "output": "NO\n"}, {"input": "21\n860388889843547436129\n", "output": "YES\n"}, {"input": "13\n0880080008088\n", "output": "YES\n"}, {"input": "17\n83130469783251338\n", "output": "NO\n"}, {"input": "13\n1341126906009\n", "output": "NO\n"}, {"input": "23\n83848888383730797684584\n", "output": "YES\n"}, {"input": "15\n488081563941254\n", "output": "YES\n"}, {"input": "21\n974378875888933268270\n", "output": "NO\n"}, {"input": "13\n2488666312263\n", "output": "NO\n"}, {"input": "15\n880082334812345\n", "output": "YES\n"}, {"input": "15\n348808698904345\n", "output": "NO\n"}, {"input": "15\n200080200228220\n", "output": "NO\n"}, {"input": "41\n11111111111111188888888888888812345674901\n", "output": "NO\n"}, {"input": "19\n5501838801564629168\n", "output": "NO\n"}, {"input": "15\n000000000000000\n", "output": "NO\n"}, {"input": "23\n88888888888888888888888\n", "output": "YES\n"}, {"input": "23\n00000000000000000000000\n", "output": "NO\n"}, {"input": "33\n888888888880000000000900000000000\n", "output": "NO\n"}] |
|
179 | Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudocode of the algorithm is as follows:
BinarySearch(a, x)
left = 0
right = a.size()
while left < right
middle = (left + right) / 2
if a[middle] <= x then
left = middle + 1
else
right = middle
if left > 0 and a[left - 1] == x then
return true
else
return false
Note that the elements of the array are indexed from zero, and the division is done in integers (rounding down).
Andrey read that the algorithm only works if the array is sorted. However, he found this statement untrue, because there certainly exist unsorted arrays for which the algorithm find $x$!
Andrey wants to write a letter to the book authors, but before doing that he must consider the permutations of size $n$ such that the algorithm finds $x$ in them. A permutation of size $n$ is an array consisting of $n$ distinct integers between $1$ and $n$ in arbitrary order.
Help Andrey and find the number of permutations of size $n$ which contain $x$ at position $pos$ and for which the given implementation of the binary search algorithm finds $x$ (returns true). As the result may be extremely large, print the remainder of its division by $10^9+7$.
-----Input-----
The only line of input contains integers $n$, $x$ and $pos$ ($1 \le x \le n \le 1000$, $0 \le pos \le n - 1$) — the required length of the permutation, the number to search, and the required position of that number, respectively.
-----Output-----
Print a single number — the remainder of the division of the number of valid permutations by $10^9+7$.
-----Examples-----
Input
4 1 2
Output
6
Input
123 42 24
Output
824071958
-----Note-----
All possible permutations in the first test case: $(2, 3, 1, 4)$, $(2, 4, 1, 3)$, $(3, 2, 1, 4)$, $(3, 4, 1, 2)$, $(4, 2, 1, 3)$, $(4, 3, 1, 2)$. | interview | [{"code": "MOD = 1000000007\n\n\ndef f(n, cnt):\n \"\"\"\n n! / (n - cnt)!\n \"\"\"\n ans = 1\n for _ in range(cnt):\n ans = (ans * n) % MOD\n n -= 1\n return ans\n\n\ndef main():\n n, x, pos = list(map(int, input().split()))\n chk1 = 0\n chk_r = 0\n left = 0\n right = n\n while left < right:\n middle = (left + right) // 2\n if middle <= pos:\n if middle < pos:\n chk1 += 1\n left = middle + 1\n else:\n chk_r += 1\n right = middle\n if chk1 > x - 1 or chk_r > n - x:\n print(0)\n else:\n # (x - 1)! / (x - 1 - chk1)! * (n - x)! / (n - x - chk_r)! * (n - chk1 - chk_r - 1)!\n rest = n - chk1 - chk_r - 1\n print(f(x - 1, chk1) * f(n - x, chk_r) * f(rest, rest) % MOD)\n\n\nmain()\n", "passed": true, "time": 0.16, "memory": 14460.0, "status": "done"}, {"code": "\nn, x, p = list(map(int, input().split()))\n\nsmallc = 0\nlargec = 0\n\nleft = 0\nright = n\nwhile left < right:\n mid = (left + right) // 2\n if mid < p:\n smallc += 1\n left = mid + 1\n elif mid > p:\n largec += 1\n right = mid\n else:\n left = mid + 1\n\nlargeAv = n - x\nsmallAv = x - 1\n\n#print(smallc, smallAv)\n#print(largec, largeAv)\n\nmod = 1000000007\n\ndef permutations(n, c):\n v = 1\n for i in range(n - c + 1, n + 1):\n v = (v * i) % mod\n return v\n\nv = permutations(largeAv, largec) * permutations(smallAv, smallc) % mod\noc = n - (largec + smallc + 1)\nv = v * permutations(oc, oc) % mod\n\n\n#print(permutations(largeAv, largec), permutations(smallAv, smallc), permutations(oc, oc))\nprint(v)\n", "passed": true, "time": 0.16, "memory": 14424.0, "status": "done"}, {"code": "n,x,pos = list(map(int,input().split()))\n\na = [i for i in range(n)]\n\nzero = 0\none = 0\n\nleft = 0\nright = n\nwhile left<right:\n middle = (left + right)//2\n if a[middle]<=pos:\n zero += 1\n left = middle+1\n else:\n one += 1\n right = middle\n\nres = 1\nmod = 10**9+7\nfor i in range(zero-1):\n res *= (x-1-i)\n res %= mod\nfor i in range(one):\n res *= (n-x-i)\n res %= mod\n\nfor j in range(n-zero-one):\n res *= j+1\n res %= mod\n\nprint(res)\n", "passed": true, "time": 0.15, "memory": 14392.0, "status": "done"}, {"code": "from math import factorial\nmod = 1000000007\n\nn, x, pos = list(map(int, input().split()))\nbiggerNeeded = 0\nlowerNeeded = 0\nleft = 0\nright = n\nwhile left < right:\n #print(left, right)\n middle = (left+right)//2\n if middle < pos:\n left = middle + 1\n lowerNeeded += 1\n elif middle > pos:\n right = middle\n biggerNeeded += 1\n else:\n left = middle + 1\nif x+biggerNeeded > n or x-lowerNeeded <= 0:\n print(0)\n return\nans = factorial(x-1) // factorial(x-1-lowerNeeded)\nans %= mod\nans *= factorial(n-x) // factorial(n-x-biggerNeeded)\nans %= mod\nans *= factorial(n-biggerNeeded-lowerNeeded-1)\nans %= mod\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14400.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\nMOD = 10 ** 9 + 7\nN = 2000\nfact = [0 for _ in range(N)]\ninvfact = [0 for _ in range(N)]\nfact[0] = 1\nfor i in range(1, N):\n fact[i] = fact[i - 1] * i % MOD\n\ninvfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)\n\nfor i in range(N - 2, -1, -1):\n invfact[i] = invfact[i + 1] * (i + 1) % MOD\ndef nCk(n, k):\n if k < 0 or n < k:\n return 0\n else:\n return fact[n] * invfact[k] * invfact[n - k] % MOD\n\ndef main():\n n, x, pos = map(int, input().split())\n b = 0\n s = 0\n l = 0\n r = n\n while l < r:\n m = (l + r) // 2\n if m <= pos:\n l = m + 1\n if m != pos:\n s += 1\n else:\n r = m\n if m != pos:\n b += 1\n \n b_cnt = n - x\n s_cnt = x - 1\n c = n - 1 - b - s\n ans = fact[c] * nCk(b_cnt, b) * nCk(s_cnt, s) * fact[b] * fact[s]\n print(ans % MOD)\n \nfor _ in range(1):\n main()", "passed": true, "time": 0.2, "memory": 14460.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\nn,x,pos=list(map(int,input().split()))\nmod=10**9+7\n\nANS=[0]*n\n\nleft=0\nright=n\n\nwhile left<right:\n #print(left,right)\n middle=(left+right)//2\n if pos>=middle:\n ANS[middle]=-1\n left=middle+1\n else:\n ANS[middle]=1\n right=middle\n\nANS[pos]=9\n#print(ANS)\n\nP=ANS.count(1)\nM=ANS.count(-1)\nMINUS=x-1\nPLUS=n-x\n\nA=1\nfor i in range(P):\n A=A*PLUS%mod\n PLUS-=1\n\n#print(A)\nfor i in range(M):\n A=A*MINUS%mod\n MINUS-=1\n\n#print(A)\n\nfor i in range(1,n-P-M):\n A=A*i%mod\n\nprint(A)\n\n\n", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}] | [{"input": "4 1 2\n", "output": "6\n"}, {"input": "123 42 24\n", "output": "824071958\n"}, {"input": "1 1 0\n", "output": "1\n"}, {"input": "1000 501 501\n", "output": "646597996\n"}, {"input": "1000 999 799\n", "output": "0\n"}, {"input": "2 1 1\n", "output": "1\n"}, {"input": "2 2 0\n", "output": "0\n"}, {"input": "3 1 2\n", "output": "0\n"}, {"input": "3 2 2\n", "output": "1\n"}, {"input": "3 3 1\n", "output": "0\n"}, {"input": "4 2 0\n", "output": "2\n"}, {"input": "4 3 2\n", "output": "2\n"}, {"input": "4 4 3\n", "output": "6\n"}, {"input": "7 1 1\n", "output": "720\n"}, {"input": "7 7 6\n", "output": "720\n"}, {"input": "7 2 4\n", "output": "120\n"}, {"input": "7 4 4\n", "output": "216\n"}, {"input": "8 4 1\n", "output": "1440\n"}, {"input": "8 1 5\n", "output": "0\n"}, {"input": "8 8 7\n", "output": "5040\n"}, {"input": "8 7 6\n", "output": "720\n"}, {"input": "8 3 0\n", "output": "1440\n"}, {"input": "9 1 7\n", "output": "0\n"}, {"input": "9 9 5\n", "output": "0\n"}, {"input": "9 5 5\n", "output": "5760\n"}, {"input": "9 4 4\n", "output": "7200\n"}, {"input": "9 3 3\n", "output": "8640\n"}, {"input": "10 1 1\n", "output": "362880\n"}, {"input": "10 10 9\n", "output": "362880\n"}, {"input": "10 5 5\n", "output": "43200\n"}, {"input": "10 3 7\n", "output": "70560\n"}, {"input": "10 4 4\n", "output": "90720\n"}, {"input": "10 6 6\n", "output": "43200\n"}, {"input": "10 7 7\n", "output": "90720\n"}, {"input": "10 9 5\n", "output": "0\n"}, {"input": "74 16 54\n", "output": "625981152\n"}, {"input": "63 15 45\n", "output": "581829795\n"}, {"input": "54 4 47\n", "output": "911648281\n"}, {"input": "92 22 62\n", "output": "628152721\n"}, {"input": "82 15 14\n", "output": "187724629\n"}, {"input": "91 60 48\n", "output": "233776714\n"}, {"input": "91 51 5\n", "output": "660447677\n"}, {"input": "70 45 16\n", "output": "578976138\n"}, {"input": "61 21 16\n", "output": "516359078\n"}, {"input": "61 29 15\n", "output": "252758304\n"}, {"input": "69 67 68\n", "output": "736622722\n"}, {"input": "59 40 1\n", "output": "384105577\n"}, {"input": "98 86 39\n", "output": "132656801\n"}, {"input": "97 89 29\n", "output": "673334741\n"}, {"input": "78 66 16\n", "output": "703501645\n"}, {"input": "777 254 720\n", "output": "57449468\n"}, {"input": "908 216 521\n", "output": "601940707\n"}, {"input": "749 158 165\n", "output": "849211382\n"}, {"input": "535 101 250\n", "output": "111877808\n"}, {"input": "665 5 305\n", "output": "400272219\n"}, {"input": "856 406 675\n", "output": "663368144\n"}, {"input": "697 390 118\n", "output": "844062514\n"}, {"input": "539 246 0\n", "output": "410139856\n"}, {"input": "669 380 461\n", "output": "921432102\n"}, {"input": "954 325 163\n", "output": "917113541\n"}, {"input": "646 467 58\n", "output": "214437899\n"}, {"input": "542 427 258\n", "output": "830066531\n"}, {"input": "562 388 191\n", "output": "935998075\n"}, {"input": "958 817 269\n", "output": "513948977\n"}, {"input": "1000 888 888\n", "output": "644649893\n"}, {"input": "1000 2 2\n", "output": "22779421\n"}, {"input": "534 376 180\n", "output": "984450056\n"}, {"input": "1000 1 1\n", "output": "756641425\n"}, {"input": "1000 3 3\n", "output": "606772288\n"}, {"input": "1000 500 500\n", "output": "646597996\n"}, {"input": "1000 1000 999\n", "output": "756641425\n"}, {"input": "1000 501 50\n", "output": "636821580\n"}, {"input": "6 4 3\n", "output": "12\n"}, {"input": "3 2 1\n", "output": "1\n"}, {"input": "100 5 50\n", "output": "469732450\n"}, {"input": "999 490 499\n", "output": "998308393\n"}, {"input": "7 3 3\n", "output": "288\n"}, {"input": "10 7 5\n", "output": "4320\n"}, {"input": "123 1 24\n", "output": "0\n"}, {"input": "5 5 2\n", "output": "0\n"}] |
|
181 | Vasya started working in a machine vision company of IT City. Vasya's team creates software and hardware for identification of people by their face.
One of the project's know-how is a camera rotating around its optical axis on shooting. People see an eye-catching gadget — a rotating camera — come up to it to see it better, look into it. And the camera takes their photo at that time. What could be better for high quality identification?
But not everything is so simple. The pictures from camera appear rotated too (on clockwise camera rotation frame the content becomes rotated counter-clockwise). But the identification algorithm can work only with faces that are just slightly deviated from vertical.
Vasya was entrusted to correct the situation — to rotate a captured image so that image would be minimally deviated from vertical. Requirements were severe. Firstly, the picture should be rotated only on angle divisible by 90 degrees to not lose a bit of information about the image. Secondly, the frames from the camera are so huge and FPS is so big that adequate rotation speed is provided by hardware FPGA solution only. And this solution can rotate only by 90 degrees clockwise. Of course, one can apply 90 degrees turn several times but for the sake of performance the number of turns should be minimized.
Help Vasya implement the program that by the given rotation angle of the camera can determine the minimum number of 90 degrees clockwise turns necessary to get a picture in which up direction deviation from vertical is minimum.
The next figure contains frames taken from an unrotated camera, then from rotated 90 degrees clockwise, then from rotated 90 degrees counter-clockwise. Arrows show direction to "true up". [Image]
The next figure shows 90 degrees clockwise turn by FPGA hardware. [Image]
-----Input-----
The only line of the input contains one integer x ( - 10^18 ≤ x ≤ 10^18) — camera angle in degrees. Positive value denotes clockwise camera rotation, negative — counter-clockwise.
-----Output-----
Output one integer — the minimum required number of 90 degrees clockwise turns.
-----Examples-----
Input
60
Output
1
Input
-60
Output
3
-----Note-----
When the camera is rotated 60 degrees counter-clockwise (the second example), an image from it is rotated 60 degrees clockwise. One 90 degrees clockwise turn of the image result in 150 degrees clockwise total rotation and deviation from "true up" for one turn is 150 degrees. Two 90 degrees clockwise turns of the image result in 240 degrees clockwise total rotation and deviation from "true up" for two turns is 120 degrees because 240 degrees clockwise equal to 120 degrees counter-clockwise. Three 90 degrees clockwise turns of the image result in 330 degrees clockwise total rotation and deviation from "true up" for three turns is 30 degrees because 330 degrees clockwise equal to 30 degrees counter-clockwise.
From 60, 150, 120 and 30 degrees deviations the smallest is 30, and it it achieved in three 90 degrees clockwise turns. | interview | [{"code": "n = (-int(input())) % 360\n\nret, opt = 4, 361\nfor i in range(4):\n x = (n+90*i)%360\n x = min(x, 360-x)\n if (x, i) < (opt, ret):\n opt, ret = x, i\n\nprint(ret)", "passed": true, "time": 0.24, "memory": 14568.0, "status": "done"}, {"code": "from functools import reduce\nfrom math import factorial\nn = (int(input()) + 45) % 360\nprint(n // 90 - (n > 0 and n%90 == 0))\n\n", "passed": true, "time": 0.16, "memory": 14320.0, "status": "done"}, {"code": "n=int(input())%360\nif n<=45: print(0)\nelif n<=90+45: print(1)\nelif n<=180+45: print(2)\nelif n<270+45: print(3)\nelse: print(0)\n", "passed": true, "time": 0.15, "memory": 14332.0, "status": "done"}, {"code": "def sign(x):\n return 1 if x > 0 else -1\n\ndef dis(x):\n if x >= 360:\n x %= 360\n\n if x <= -180:\n return 360 + x\n elif x <= 0:\n return abs(x)\n elif x <= 180:\n return x\n else:\n return 360-x\n\ndef __starting_point():\n\n x = int(input())\n x = (-sign(x))*(abs(x)%360)\n #print(x)\n\n mindis = dis(x)\n res = 0\n\n for i in range(1,4):\n newdis = dis(x+90*i)\n if newdis < mindis:\n mindis = newdis\n res = i\n\n print(res)\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}, {"code": "def f(x):\n assert(0 <= x <= 360)\n return min(x, 360 - x)\n\ndef main():\n x = int(input())\n a, b, c, d = -x, -x+90, -x+180, -x+270\n a, b, c, d = a%360, b%360, c%360, d%360\n a, b, c, d = f(a), f(b), f(c), f(d)\n L = [(a, 0), (b, 1), (c, 2), (d, 3)]\n L.sort()\n print(L[0][1])\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14660.0, "status": "done"}, {"code": "import sys\n\nn = int(sys.stdin.readline())\nn %= 360\n\n_0 = min(360 - n, n)\nn = (n - 90) % 360\n_1 = min(360 - n, n)\nn = (n - 90) % 360\n_2 = min(360 - n, n)\nn = (n - 90) % 360\n_3 = min(360 - n, n)\n\nif (_0 <= min(_1, min(_2, _3))):\n print(0)\n return\nif (_1 <= min(_0, min(_2, _3))):\n print(1)\n return\nif (_2 <= min(_1, min(_0, _3))):\n print(2)\n return\nif (_3 <= min(_1, min(_2, _0))):\n print(3)\n return", "passed": true, "time": 0.32, "memory": 14456.0, "status": "done"}, {"code": "x = -int(input()) % 360\n\nl = [x, x+90, x+180, x+270]\nl = [min(x%360, (-x)%360) for x in l]\nm = min(l)\n#print(l)\nprint(l.index(m))\n\n", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "n = int(input())\nn=(n*-1)%360\n\nminVueltas = -1\nminValor = -1\nfor i in range(4):\n temp = (n+90*i)%360\n if temp>180:\n temp = 360-temp\n if minValor==-1 or temp<minValor:\n minVueltas=i\n minValor=temp\nprint(minVueltas)\n", "passed": true, "time": 0.24, "memory": 14424.0, "status": "done"}, {"code": "n = int(input())\nn += 3600000000000000000\nn %= 360\n\nif n <= 45:\n print(0)\nelif n <= 135:\n print(1)\nelif n <= 225:\n print(2)\nelif n < 315:\n print(3)\nelse:\n print(0)", "passed": true, "time": 0.23, "memory": 14540.0, "status": "done"}, {"code": "x = int(input())\nx = x % 360\nif (x <= 45 or x >= 315):\n print(0)\nelif (x >= 45 and x <= 135):\n print(1)\nelif (x >= 135 and x <= 225):\n print(2)\nelse:\n print(3)\n", "passed": true, "time": 0.14, "memory": 14476.0, "status": "done"}, {"code": "n = (360 + int(input()) % 360) % 360\n\nans = 0\nbres = n\n\nfor i in range(1, 5):\n d = (360 + (n - i * 90) % 360) % 360\n if min(d, 360 - d) < min(bres, 360 - bres):\n bres = d\n ans = i\n\nprint(ans)", "passed": true, "time": 0.14, "memory": 14376.0, "status": "done"}, {"code": "n = (int(input())+45)%360\nif n%90==0 and n!=0:\n print(n//90-1)\nelse:\n print(n//90)\n", "passed": true, "time": 0.15, "memory": 14484.0, "status": "done"}, {"code": "n = int(input()) % 360\nif 45 < n <= 135:\n print(1)\nelif 135 < n <= 225:\n print(2)\nelif 225 < n < 315:\n print(3)\nelse:\n print(0)\n", "passed": true, "time": 0.25, "memory": 14564.0, "status": "done"}, {"code": "import math, re, sys, string, operator, functools, fractions, collections\nsys.setrecursionlimit(10**7)\ndX= [-1, 1, 0, 0,-1, 1,-1, 1]\ndY= [ 0, 0,-1, 1, 1,-1,-1, 1]\nRI=lambda x=' ': list(map(int,input().split(x)))\nRS=lambda x=' ': input().rstrip().split(x)\nmod=int(1e9+7)\neps=1e-6\n#################################################\nx=RI()[0]\nx%=360\nif x>180:\n x=x-360\nans=0\nval=abs(x)\nfor i in range(1,4):\n x-=90\n if x<-180:\n x=360+x\n if abs(x)<val:\n val=abs(x)\n ans=i\nprint(ans)\n\n\n\n", "passed": true, "time": 0.17, "memory": 14380.0, "status": "done"}, {"code": "n = int(input())\nans = 0\nn %= 360\n\nif n <= 45 or n >= 270:\n ans = 0\nif n > 45 and n <= 135:\n ans = 1\nif n > 135 and n <= 225:\n ans = 2\nif n > 225 and n < 315:\n ans = 3\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}, {"code": "n=int(input())\nn+=3600000000000000000000\nx=n%360\nif (x<=45):\n\tprint(0)\nelif (x<=135):\n\tprint(1)\nelif (x<=225):\n\tprint(2)\nelif (x<315):\n\tprint(3)\nelif (x>=315):\n\tprint(0)", "passed": true, "time": 0.14, "memory": 14644.0, "status": "done"}, {"code": "import sys\n\n\ndef chet(a, b):\n ans = (b - a) // 2\n if b % 2 == 0 or a % 2 == 0:\n ans += 1\n return ans\n\n\ndef nechet(a, b):\n ans = (b - a) // 2\n if b % 2 == 1 or a % 2 == 1:\n ans += 1\n return ans\n\n\ndef ans(a, b, c, d):\n return chet(a, c) * chet(b, d) + nechet(a, c) * nechet(b, d)\n\n\nn = int(input())\nras = n // 360\nk = n - 360 * ras\nost = (k + 45) % 90\nd = (k + 45) // 90\nans = d if (ost > 0 or d % 4 == 0) else d - 1\nprint(ans % 4)\n\n\n\n\n\n\n", "passed": true, "time": 0.14, "memory": 14624.0, "status": "done"}, {"code": "x = (int(input()) + 360 * 10 ** 18) % 360\n\nif x <= 45 or x >= 315:\n print(0)\nelif x <= 135:\n print(1)\nelif x <= 225:\n print(2)\nelse:\n print(3)", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}, {"code": "angle = int(input())\nangle = (angle % 360 + 360) % 360\nangle = (angle + 44) % 360\nanswer = (angle % 359) // 90\nprint(answer)", "passed": true, "time": 0.14, "memory": 14316.0, "status": "done"}, {"code": "n = int(input())\n\nt = n - (n // 360) * 360\ni = 0\nwhile not (-45 <= t <= 45 or 315 <= t <= 360):\n\ti += 1\n\tt -= 90\nprint(i)\n", "passed": true, "time": 0.14, "memory": 14296.0, "status": "done"}, {"code": "import sys\nimport math\n# sys.stdin = open('input.txt')\n# sys.stdout = open('output.txt', 'w')\n\ndef main():\n n = int(input())\n n = -n\n n %= 360\n a = n\n a1 = 360 - a\n b = (a + 90) % 360 \n b1 = 360 - b\n c = (b + 90) % 360\n c1 = 360 - c\n d = (c + 90) % 360\n d1 = 360 - d\n ans = min([a, a1, b, b1, c, c1, d, d1])\n if a == ans or a1 == ans:\n print(0)\n elif b == ans or b1 == ans:\n print(1)\n elif c == ans or c1 == ans:\n print(2)\n elif d == ans or d1 == ans:\n print(3)\n\nmain()", "passed": true, "time": 0.15, "memory": 14592.0, "status": "done"}] | [{"input": "60\n", "output": "1\n"}, {"input": "-60\n", "output": "3\n"}, {"input": "0\n", "output": "0\n"}, {"input": "44\n", "output": "0\n"}, {"input": "45\n", "output": "0\n"}, {"input": "46\n", "output": "1\n"}, {"input": "134\n", "output": "1\n"}, {"input": "135\n", "output": "1\n"}, {"input": "136\n", "output": "2\n"}, {"input": "224\n", "output": "2\n"}, {"input": "225\n", "output": "2\n"}, {"input": "226\n", "output": "3\n"}, {"input": "227\n", "output": "3\n"}, {"input": "313\n", "output": "3\n"}, {"input": "314\n", "output": "3\n"}, {"input": "315\n", "output": "0\n"}, {"input": "316\n", "output": "0\n"}, {"input": "358\n", "output": "0\n"}, {"input": "359\n", "output": "0\n"}, {"input": "360\n", "output": "0\n"}, {"input": "361\n", "output": "0\n"}, {"input": "999999999999999340\n", "output": "0\n"}, {"input": "999999999999999325\n", "output": "0\n"}, {"input": "999999999999999326\n", "output": "0\n"}, {"input": "999999999999999415\n", "output": "1\n"}, {"input": "999999999999999416\n", "output": "1\n"}, {"input": "999999999999999504\n", "output": "2\n"}, {"input": "999999999999999505\n", "output": "2\n"}, {"input": "999999999999999506\n", "output": "2\n"}, {"input": "999999999999999594\n", "output": "3\n"}, {"input": "999999999999999595\n", "output": "3\n"}, {"input": "999999999999999596\n", "output": "3\n"}, {"input": "999999999999999639\n", "output": "3\n"}, {"input": "999999999999999640\n", "output": "3\n"}, {"input": "6678504591813508\n", "output": "2\n"}, {"input": "201035370138545377\n", "output": "2\n"}, {"input": "441505850043460771\n", "output": "1\n"}, {"input": "252890591709237675\n", "output": "2\n"}, {"input": "272028913373922389\n", "output": "3\n"}, {"input": "141460527912396122\n", "output": "0\n"}, {"input": "479865961765156498\n", "output": "2\n"}, {"input": "-44\n", "output": "0\n"}, {"input": "-45\n", "output": "0\n"}, {"input": "-46\n", "output": "3\n"}, {"input": "-134\n", "output": "3\n"}, {"input": "-135\n", "output": "2\n"}, {"input": "-136\n", "output": "2\n"}, {"input": "-224\n", "output": "2\n"}, {"input": "-225\n", "output": "1\n"}, {"input": "-226\n", "output": "1\n"}, {"input": "-227\n", "output": "1\n"}, {"input": "-313\n", "output": "1\n"}, {"input": "-314\n", "output": "1\n"}, {"input": "-315\n", "output": "0\n"}, {"input": "-316\n", "output": "0\n"}, {"input": "-358\n", "output": "0\n"}, {"input": "-359\n", "output": "0\n"}, {"input": "-360\n", "output": "0\n"}, {"input": "-361\n", "output": "0\n"}, {"input": "-999999999999999340\n", "output": "0\n"}, {"input": "-999999999999999325\n", "output": "0\n"}, {"input": "-999999999999999326\n", "output": "0\n"}, {"input": "-999999999999999415\n", "output": "3\n"}, {"input": "-999999999999999416\n", "output": "3\n"}, {"input": "-999999999999999504\n", "output": "2\n"}, {"input": "-999999999999999505\n", "output": "2\n"}, {"input": "-999999999999999506\n", "output": "2\n"}, {"input": "-999999999999999594\n", "output": "1\n"}, {"input": "-999999999999999595\n", "output": "1\n"}, {"input": "-999999999999999596\n", "output": "1\n"}, {"input": "-999999999999999639\n", "output": "1\n"}, {"input": "-999999999999999640\n", "output": "1\n"}, {"input": "-6678504591813508\n", "output": "2\n"}, {"input": "-201035370138545377\n", "output": "2\n"}, {"input": "-441505850043460771\n", "output": "3\n"}, {"input": "-252890591709237675\n", "output": "2\n"}, {"input": "-272028913373922389\n", "output": "1\n"}, {"input": "-141460527912396122\n", "output": "0\n"}, {"input": "-479865961765156498\n", "output": "2\n"}] |
|
182 | Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least x blue, y violet and z orange spheres. Can he get them (possible, in multiple actions)?
-----Input-----
The first line of the input contains three integers a, b and c (0 ≤ a, b, c ≤ 1 000 000) — the number of blue, violet and orange spheres that are in the magician's disposal.
The second line of the input contains three integers, x, y and z (0 ≤ x, y, z ≤ 1 000 000) — the number of blue, violet and orange spheres that he needs to get.
-----Output-----
If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No".
-----Examples-----
Input
4 4 0
2 1 2
Output
Yes
Input
5 6 1
2 7 2
Output
No
Input
3 3 3
2 2 2
Output
Yes
-----Note-----
In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs. | interview | [{"code": "a, b, c = list(map(int, input().split()))\nx, y, z = list(map(int, input().split()))\ncol = max(0, x - a) + max(0, y - b) + max(0, z - c)\nsum = max(0, (a - x) // 2) + max(0, (b - y) // 2) + max(0, (c - z) // 2)\nif sum >= col:\n print('Yes')\nelse:\n print('No')\n", "passed": true, "time": 0.16, "memory": 14316.0, "status": "done"}, {"code": "a, b, c = list(map(int, input().split(' ')))\nd, e, f = list(map(int, input().split(' ')))\n\nex = []\nneed = []\nif a >= d:\n ex.append(a-d)\nelse:\n need.append(d-a)\nif b >= e:\n ex.append(b-e)\nelse:\n need.append(e-b)\nif c >= f:\n ex.append(c-f)\nelse:\n need.append(f-c)\n \nsumx = 0\nfor i in ex:\n sumx += i // 2\n\nif sumx >= sum(need):\n print(\"Yes\")\nelse:\n print(\"No\")\n", "passed": true, "time": 0.14, "memory": 14440.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\ntry:\n while True:\n a, b, c = list(map(int, input().split()))\n x, y, z = list(map(int, input().split()))\n a -= x\n b -= y\n c -= z\n if sum(t >> 1 for t in (a, b, c) if t > 0) >= sum(-t for t in (a, b, c) if t < 0):\n print(\"Yes\")\n else:\n print(\"No\")\n\nexcept EOFError:\n pass\n", "passed": true, "time": 0.15, "memory": 14488.0, "status": "done"}, {"code": "a, b, c = map(int, input().split())\nx, y, z = map(int, input().split())\nhave = 0\nif a > x:\n have += (a - x) // 2\nif b > y:\n have += (b - y) // 2\nif c > z:\n have += (c - z) // 2\n\nneed = max(0, x - a) + max(0, y - b) + max(0, z - c)\nif have >= need:\n print('Yes')\nelse:\n print('No')", "passed": true, "time": 0.15, "memory": 14484.0, "status": "done"}, {"code": "a, b, c = list(map(int, input().split()))\nx, y, z = list(map(int, input().split()))\ndx = [a - x, b - y, c - z]\nsplus = 0\nsminus = 0\nfor i in dx:\n if i > 0:\n splus += i // 2\n else:\n sminus += -i\nif sminus == 0 or splus >= sminus:\n print('Yes')\nelse:\n print('No')\n\n", "passed": true, "time": 0.22, "memory": 14380.0, "status": "done"}, {"code": "import math\nOwn = list(map(int, input().split()))\nReq = list(map(int, input().split()))\n\nDelta = 0\nfor i in range(3):\n Delta += math.floor((Own[i] - Req[i])/2) if Own[i] > Req[i] else (Own[i]-Req[i])\n\nprint(\"Yes\" if Delta >= 0 else \"No\")", "passed": true, "time": 0.22, "memory": 14596.0, "status": "done"}, {"code": "a, b, c = tuple(map(int, input().split()))\nx, y, z = tuple(map(int, input().split()))\n\nhave = 0\nneed = 0\n\nif a > x:\n have += (a - x) // 2\nelse:\n need += x - a\n\nif b > y:\n have += (b - y) // 2\nelse:\n need += y - b\n \nif c > z:\n have += (c - z) // 2\nelse:\n need += z - c\n\nif need > have:\n print('No')\nelse:\n print('Yes')", "passed": true, "time": 0.19, "memory": 14572.0, "status": "done"}, {"code": "a, b, c = list(map(int, input().split()))\nx, y, z = list(map(int, input().split()))\nif a >= x:\n a -= x\n x = 0\nelse:\n x -= a\n a = 0\n \n\nif b >=y:\n b -= y\n y = 0\nelse:\n y -= b\n b = 0\n\nif c >= z:\n c -= z\n z = 0\nelse:\n z -= c\n c= 0\n \nif a // 2 + b // 2 + c // 2 >= x + y + z:\n print('Yes')\nelse:\n print('No')\n", "passed": true, "time": 0.15, "memory": 14484.0, "status": "done"}, {"code": "a, b, c = map(int, input().split())\nx, y, z = map(int, input().split())\na -= x\nb -= y\nc -= z\na, b, c = sorted([a, b, c])\nk = max(0, c // 2)\nc -= min(2 * k, -2 * a)\na += min(k, -a)\nif a < 0:\n k = max(0, b // 2)\n b -= min(2 * k, -2 * a)\n a += min(k, -a)\nelif b < 0:\n k = max(0, c // 2)\n c -= min(2 * k, -2 * b)\n b += min(k, -b)\nif a >= 0 and b >= 0 and c >= 0:\n print(\"Yes\")\nelse:\n print(\"No\")", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "have = list(map(int, input().split()))\ngoal = list(map(int, input().split()))\ndeficit = 0\nmakeable = 0\nfor i in range(3):\n if have[i] < goal[i]:\n deficit += goal[i] - have[i]\n else:\n makeable += (have[i] - goal[i]) // 2\nprint('Yes' if makeable >= deficit else 'No')\n", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "has = list(map(int, input().split()))\ntarget = list(map(int, input().split()))\n\noffer = []\nfor i in range(3):\n if has[i] - target[i] > 0:\n offer.append(int((has[i] - target[i]) / 2))\n else:\n offer.append(int(has[i] - target[i]))\n\nif sum(offer) >= 0:\n print(\"Yes\")\nelse:\n print(\"No\")", "passed": true, "time": 0.15, "memory": 14392.0, "status": "done"}, {"code": "__author__ = 'MoonBall'\n\nimport sys\n# sys.stdin = open('data/A.in', 'r')\nT = 1\n\ndef process():\n a = list(map(int, input().split()))\n b = list(map(int, input().split()))\n delta = 0\n sum_delta = 0\n for _a, _b in zip(a, b):\n if _a < _b:\n delta += _b - _a\n else:\n sum_delta += (_a - _b) // 2\n\n print('Yes' if sum_delta >= delta else 'No')\n\n\n\n\n\n\nfor _ in range(T):\n process()\n", "passed": true, "time": 0.15, "memory": 14384.0, "status": "done"}, {"code": "read = lambda: map(int, input().split())\na, b, c = read()\nx, y, z = read()\nm, n, k = x - a, y - b, z - c\np = 0\nq = 0\nif m > 0: p += m\nelse: q += (-m) // 2\nif k > 0: p += k\nelse: q += (-k) // 2\nif n > 0: p += n\nelse: q += (-n) // 2\n\nprint('Yes' if q >= p else 'No')", "passed": true, "time": 0.24, "memory": 14332.0, "status": "done"}, {"code": "a, b, c = map(int, input().split())\nx, y, z = map(int, input().split())\ns = (0 if a > x else x - a) + (0 if b > y else y - b) + (0 if c > z else z - c)\nt = ((a - x) // 2 if a > x else 0) + ((b - y) // 2 if b > y else 0) + ((c - z) // 2 if c > z else 0)\nprint('Yes' if t >= s else 'No')", "passed": true, "time": 0.15, "memory": 14500.0, "status": "done"}, {"code": "def f(x):\n return x if x <= 0 else x // 2\n(a, b, c) = list(map(int, input().split()))\n(x, y, z) = list(map(int, input().split()))\n(n, m, k) = (a - x, b - y, c - z)\nans = f(n) + f(m) + f(k)\nif ans >= 0:\n print(\"Yes\")\nelse:\n print(\"No\")\n\n\n", "passed": true, "time": 0.15, "memory": 14360.0, "status": "done"}, {"code": "a,b,c = list([int(x) for x in input().split(' ')])\nx,y,z = list([int(x) for x in input().split(' ')])\n\nif x-a>0 and y-b>0 and z-c>0:\n print('No')\nelif x-a<=0 and y-b<=0 and z-c<=0:\n print('Yes')\nelse:\n n = 0\n if a-x < 0:\n n+=x-a\n if b-y < 0:\n n+=y-b\n if c-z < 0:\n n+=z-c\n\n t = 0\n if a-x >= 0:\n t+=(a-x)//2\n if b-y >= 0:\n t+=(b-y)//2\n if c-z >= 0:\n t+=(c-z)//2\n\n if t >= n:\n print('Yes')\n else:\n print('No')\n", "passed": true, "time": 0.15, "memory": 14500.0, "status": "done"}, {"code": "a = [int(x) for x in input().split()]\nb = [int(x) for x in input().split()]\nt, k = 0, 0\nfor i in range(3):\n t += max(0, a[i] - b[i]) // 2\n if a[i] < b[i]:\n k += b[i] - a[i]\nprint(\"Yes\" if t >= k else \"No\")", "passed": true, "time": 0.14, "memory": 14560.0, "status": "done"}, {"code": "a, b, c = [int(x) for x in input().split()]\nx, y, z = [int(x) for x in input().split()]\n\ni = (a - x) // 2 if a > x else 0\nj = (b - y) // 2 if b > y else 0\nk = (c - z) // 2 if c > z else 0\n\nif max(x - a, 0) + max(y - b, 0) + max(z - c, 0) <= i + j + k:\n\tprint('Yes')\nelse:\n\tprint('No')\n", "passed": true, "time": 0.22, "memory": 14476.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport time\n\n# = input()\n# = int(input())\n\n#() = (i for i in input().split())\n# = [i for i in input().split()]\n\na = [int(i) for i in input().split()]\nx = [int(i) for i in input().split()]\n\nstart = time.time()\n\nans = 0\n\nfor i in range(3):\n a[i] -= x[i]\n if a[i] > 0:\n ans += divmod(a[i], 2)[0]\n else:\n ans += a[i]\n\nif ans >=0:\n print(\"Yes\")\nelse:\n print(\"No\")\n\nfinish = time.time()\n#print(finish - start)\n", "passed": true, "time": 0.14, "memory": 14364.0, "status": "done"}, {"code": "a, b, c = map(int, input().split())\nx, y, z = map(int, input().split())\nr = [a - x, b - y, c - z]\nr.sort()\nif r[2] < 0:\n print('No')\nelif r[1] < 0:\n if r[2] // 2 >= -(r[0] + r[1]):\n print('Yes')\n else:\n print('No')\nelif r[0] < 0:\n if r[2] // 2 + r[1] // 2 >= -r[0]:\n print('Yes')\n else:\n print('No')\nelse:\n print('Yes')", "passed": true, "time": 0.15, "memory": 14388.0, "status": "done"}, {"code": "def main():\n\ta, b, c = list(map(int, input().split()))\n\tx, y, z = list(map(int, input().split()))\n\n\taf = a - x\n\tbf = b - y\n\tcf = c - z\n\n\tq = sorted([af, bf, cf])\n\n\tif all(x < 0 for x in q):\n\t\treturn False\n\n\tif all(x >= 0 for x in q):\n\t\treturn True\n\n\tif q[0] < 0 and q[1] < 0:\n\t\treturn q[2] // 2 >= -q[0] + -q[1]\n\n\tif q[0] < 0:\n\t\treturn q[1]//2 + q[2]//2 >= -q[0]\n\n\nif main():\n\tprint('Yes')\nelse:\n\tprint('No')\n", "passed": true, "time": 0.15, "memory": 14588.0, "status": "done"}, {"code": "l=input().split()\ns=input().split()\nr=[0]*3\nfor i in range(3):\n l[i]=int(l[i])\n s[i]=int(s[i])\n r[i]=l[i]-s[i]\nk=0\nm,n=0,0\nfor i in range(3):\n if(r[i]>=0):\n m+=r[i]//2\n else:\n k+=1\n r[i]=-r[i]\n n+=r[i]\nif(k==3):\n print(\"No\")\nelse:\n if(m>=n):\n print(\"Yes\")\n else:\n print(\"No\")", "passed": true, "time": 0.14, "memory": 14624.0, "status": "done"}] | [{"input": "4 4 0\n2 1 2\n", "output": "Yes\n"}, {"input": "5 6 1\n2 7 2\n", "output": "No\n"}, {"input": "3 3 3\n2 2 2\n", "output": "Yes\n"}, {"input": "0 0 0\n0 0 0\n", "output": "Yes\n"}, {"input": "0 0 0\n0 0 1\n", "output": "No\n"}, {"input": "0 1 0\n0 0 0\n", "output": "Yes\n"}, {"input": "1 0 0\n1 0 0\n", "output": "Yes\n"}, {"input": "2 2 1\n1 1 2\n", "output": "No\n"}, {"input": "1 3 1\n2 1 1\n", "output": "Yes\n"}, {"input": "1000000 1000000 1000000\n1000000 1000000 1000000\n", "output": "Yes\n"}, {"input": "1000000 500000 500000\n0 750000 750000\n", "output": "Yes\n"}, {"input": "500000 1000000 500000\n750001 0 750000\n", "output": "No\n"}, {"input": "499999 500000 1000000\n750000 750000 0\n", "output": "No\n"}, {"input": "500000 500000 0\n0 0 500000\n", "output": "Yes\n"}, {"input": "0 500001 499999\n500000 0 0\n", "output": "No\n"}, {"input": "1000000 500000 1000000\n500000 1000000 500000\n", "output": "Yes\n"}, {"input": "1000000 1000000 499999\n500000 500000 1000000\n", "output": "No\n"}, {"input": "500000 1000000 1000000\n1000000 500001 500000\n", "output": "No\n"}, {"input": "1000000 500000 500000\n0 1000000 500000\n", "output": "Yes\n"}, {"input": "500000 500000 1000000\n500001 1000000 0\n", "output": "No\n"}, {"input": "500000 999999 500000\n1000000 0 500000\n", "output": "No\n"}, {"input": "4 0 3\n2 2 1\n", "output": "Yes\n"}, {"input": "0 2 4\n2 0 2\n", "output": "Yes\n"}, {"input": "3 1 0\n1 1 1\n", "output": "Yes\n"}, {"input": "4 4 1\n1 3 2\n", "output": "Yes\n"}, {"input": "1 2 4\n2 1 3\n", "output": "No\n"}, {"input": "1 1 0\n0 0 1\n", "output": "No\n"}, {"input": "4 0 0\n0 1 1\n", "output": "Yes\n"}, {"input": "0 3 0\n1 0 1\n", "output": "No\n"}, {"input": "0 0 3\n1 0 1\n", "output": "Yes\n"}, {"input": "1 12 1\n4 0 4\n", "output": "Yes\n"}, {"input": "4 0 4\n1 2 1\n", "output": "Yes\n"}, {"input": "4 4 0\n1 1 3\n", "output": "No\n"}, {"input": "0 9 0\n2 2 2\n", "output": "No\n"}, {"input": "0 10 0\n2 2 2\n", "output": "Yes\n"}, {"input": "9 0 9\n0 8 0\n", "output": "Yes\n"}, {"input": "0 9 9\n9 0 0\n", "output": "No\n"}, {"input": "9 10 0\n0 0 9\n", "output": "Yes\n"}, {"input": "10 0 9\n0 10 0\n", "output": "No\n"}, {"input": "0 10 10\n10 0 0\n", "output": "Yes\n"}, {"input": "10 10 0\n0 0 11\n", "output": "No\n"}, {"input": "307075 152060 414033\n381653 222949 123101\n", "output": "No\n"}, {"input": "569950 228830 153718\n162186 357079 229352\n", "output": "No\n"}, {"input": "149416 303568 749016\n238307 493997 190377\n", "output": "No\n"}, {"input": "438332 298094 225324\n194220 400244 245231\n", "output": "No\n"}, {"input": "293792 300060 511272\n400687 382150 133304\n", "output": "No\n"}, {"input": "295449 518151 368838\n382897 137148 471892\n", "output": "No\n"}, {"input": "191789 291147 691092\n324321 416045 176232\n", "output": "Yes\n"}, {"input": "286845 704749 266526\n392296 104421 461239\n", "output": "Yes\n"}, {"input": "135522 188282 377041\n245719 212473 108265\n", "output": "Yes\n"}, {"input": "404239 359124 133292\n180069 184791 332544\n", "output": "No\n"}, {"input": "191906 624432 244408\n340002 367217 205432\n", "output": "No\n"}, {"input": "275980 429361 101824\n274288 302579 166062\n", "output": "No\n"}, {"input": "136092 364927 395302\n149173 343146 390922\n", "output": "No\n"}, {"input": "613852 334661 146012\n363786 326286 275233\n", "output": "No\n"}, {"input": "348369 104625 525203\n285621 215396 366411\n", "output": "No\n"}, {"input": "225307 153572 114545\n154753 153282 149967\n", "output": "Yes\n"}, {"input": "438576 124465 629784\n375118 276028 390116\n", "output": "Yes\n"}, {"input": "447521 327510 158732\n395759 178458 259139\n", "output": "Yes\n"}, {"input": "8 5 5\n5 5 5\n", "output": "Yes\n"}, {"input": "100 100 100\n1 1 1\n", "output": "Yes\n"}, {"input": "100 100 100\n0 0 0\n", "output": "Yes\n"}, {"input": "3 2 3\n2 3 2\n", "output": "No\n"}, {"input": "5 4 3\n2 2 2\n", "output": "Yes\n"}, {"input": "14 9 8\n12 5 10\n", "output": "Yes\n"}, {"input": "10 10 10\n1 1 1\n", "output": "Yes\n"}, {"input": "6 3 3\n3 3 3\n", "output": "Yes\n"}, {"input": "10 0 4\n2 4 2\n", "output": "Yes\n"}, {"input": "100 100 100\n2 2 2\n", "output": "Yes\n"}, {"input": "4 6 0\n2 1 2\n", "output": "Yes\n"}, {"input": "4 6 3\n4 2 3\n", "output": "Yes\n"}, {"input": "5 5 5\n1 1 1\n", "output": "Yes\n"}, {"input": "41 17 34\n0 19 24\n", "output": "Yes\n"}, {"input": "8 8 8\n3 3 3\n", "output": "Yes\n"}, {"input": "7 7 1\n1 1 2\n", "output": "Yes\n"}, {"input": "6 6 0\n2 2 2\n", "output": "Yes\n"}, {"input": "5 5 5\n2 2 2\n", "output": "Yes\n"}, {"input": "400 400 400\n1 1 1\n", "output": "Yes\n"}, {"input": "4 4 4\n2 2 2\n", "output": "Yes\n"}] |
|
184 | You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and a ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.
Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.
Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
-----Input-----
The only line contains three integers l, r and a (0 ≤ l, r, a ≤ 100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
-----Output-----
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
-----Examples-----
Input
1 4 2
Output
6
Input
5 5 5
Output
14
Input
0 2 0
Output
0
-----Note-----
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand. | interview | [{"code": "import base64\nimport zlib\npro = base64.decodebytes(\"\"\"eJxtUUFuwyAQvPOKVarKkDhOm2MlX/uC3qqqAhs7KBgswGr6+y4QrLqqL7DD7OzMWk2zdQFGGWbu\nPVG59N/rdeLhUu6Om95OpVJBumCtXqlCedkFQgalpYcW3twiSS/FMmLxyrWXhKihzGrwXLx0lEHb\nQjU4e5HmWgHOgKTwQgC/0p/EIoDeGh96ZRC0szR0F6QPjTI7lt4fCsMuoVCqREGgqqH6qjIxBSZo\ncADdTZTXIFie6dCZM8BhDwJOp7SDZuz6zLn3OMXplv+uTKCKwWAdKECDysxLoKzxs1Z4fpRObkb5\n6ZfNTDSDbimlAo44+QDPLI4+MzRBYy1Yto0bxPqINTzCOe7uKSsUlQPKFJFzFtmkWlN3dhKcmhpu\n2xw05R14FyyG1NSwdQm/QJxwY/+93OKGdA2uRgtt3hPp1RALLjzV2OkYmZSJCB40ku/AISORju2M\nXOEPkISOLVzJ/ShtPCedXfwLCdxjfPIDQSHUSQ==\n\"\"\".encode())\npro = zlib.decompress(pro)\npro = pro.decode()\nexec(pro)\n", "passed": true, "time": 0.19, "memory": 14376.0, "status": "done"}, {"code": "l,r,a = map(int,input().split())\nl,r = min(l,r),max(l,r)\nres = l\nif a > r - l:\n res = r + (a - r + l) // 2\nelse:\n res += a\nprint(res * 2) ", "passed": true, "time": 1.18, "memory": 14516.0, "status": "done"}, {"code": "def read():\n return list(map(int,input().split()))\nl,r,a=read()\nif r<l:\n l,r=r,l\nif l+a<r:\n print((l+a)*2)\nelse:\n a-=r-l\n print((r+a//2)*2)\n\n", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "l,r,a=list(map(int,input().split()))\ns=0\nfor i in range(a+1):\n s=max(s,2*min(l+i,r+a-i))\nprint(s)\n", "passed": true, "time": 0.15, "memory": 14620.0, "status": "done"}, {"code": "l, r, a = list(map(int, input().split()))\nprint(2 * max(min(l + i, r + a - i) for i in range(a + 1)))\n\n", "passed": true, "time": 0.22, "memory": 14576.0, "status": "done"}, {"code": "l, r, a = map(int, input().split())\nprint(l + r + a - max(abs(l - r) - a, 0) - (l + r + a - max(abs(l - r) - a, 0)) % 2)", "passed": true, "time": 0.14, "memory": 14520.0, "status": "done"}, {"code": "l, r, a = list(map(int, input().split(' ')))\n\nfor i in range(a):\n if r < l:\n r += 1\n else:\n l += 1\n\nprint(2 * min(l, r))\n", "passed": true, "time": 1.16, "memory": 14480.0, "status": "done"}, {"code": "l, r, a = map(int, input().split())\nif l > r: l, r = r, l\nif l + a <= r:\n print(2 * (l + a))\nelse:\n k = r - l\n a -= k\n l += k\n print(2 * l + a - a % 2)", "passed": true, "time": 0.14, "memory": 14264.0, "status": "done"}, {"code": "l, r, a = list(map(int, input().split()))\n\nwhile a > 0:\n if l < r:\n l += 1\n elif r < l:\n r += 1\n else:\n l += 1\n a -= 1\n\nprint(2*min(l, r))\n", "passed": true, "time": 1.81, "memory": 14544.0, "status": "done"}, {"code": "l,r,a = list(map(int,input().split()))\nif a > (max(l,r)-min(l,r)):\n print((l+a+r)//2*2)\nelse:\n print((min(l,r)+a) *2)\n", "passed": true, "time": 0.14, "memory": 14516.0, "status": "done"}, {"code": "l, r, a = input().split()\nl, r, a = int(l), int(r), int(a)\n\nans = min([l+a, r+a, int((l+r+a)/2)])\nans*=2\n\nprint(ans)", "passed": true, "time": 0.21, "memory": 14392.0, "status": "done"}, {"code": "l,r,a = input().split()\nl = int(l)\nr = int(r)\na = int(a)\nd = max(l,r) - min(l,r)\nif a<=d:\n ans = 2*(min(l,r)+a)\nelse:\n a = a-d;\n ans = 2*(max(r,l)+a//2)\nprint(ans) \n\n \n", "passed": true, "time": 0.29, "memory": 14512.0, "status": "done"}, {"code": "l, r, a = map(int, input().split())\nl, r = max(l, r), min(l, r)\nif l - r >= a:\n print((r + a) * 2)\nelse:\n print(2 * l + (a - (l - r)) // 2 * 2)", "passed": true, "time": 0.17, "memory": 14524.0, "status": "done"}, {"code": "l, r, a = list(map(int, input().split()))\n\nbest = 0\n\nfor l1 in range(l + 1):\n\tfor r1 in range(r + 1):\n\t\tdiff = abs(l1 - r1)\n\n\t\tif diff <= a:\n\t\t\tcur_ans = max(l1, r1) * 2 + (a - diff) // 2 * 2\n\t\t\tbest = max(cur_ans, best)\n\nprint(best)\n", "passed": true, "time": 0.22, "memory": 14336.0, "status": "done"}, {"code": "\n(l,r,a) = input().split()\nl = int(l)\nr = int(r)\na = int(a)\n\ndif = abs(r-l)\nif (r< l):\n\n r += min(a, l-r)\n a -= min(a, dif)\nelse:\n l += min(a, r-l)\n a -= min(a, dif)\n\n\nif (a > 0):\n print(2*(r + a//2))\nelse:\n print(2*min(r,l))\n", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "l,r,a=list(map(int, input().split()))\nl, r = min(l,r), max(l,r)\nb = r-l\nif b<=a:\n a-=b\n print((r+a//2)*2)\nelse:\n print((l+a)*2)\n \n", "passed": true, "time": 0.24, "memory": 14496.0, "status": "done"}, {"code": "l, r, a = [int(x) for x in input().split()]\nif l > r:\n r, l = l, r\n\nprint(2 * (l+a if l+a<r else (l+r+a)//2))\n", "passed": true, "time": 0.14, "memory": 14476.0, "status": "done"}, {"code": "l, r, a = list(map(int, input().split(\" \")))\nq = min(l,r ) + a\nif q < max(l, r):\n print(2*q)\nelse:\n print(2*(max(l, r) + ((q-max(l, r)) // 2)))\n\n", "passed": true, "time": 0.22, "memory": 14596.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Fri Mar 9 09:54:56 2018\n\n@author: Nikita\n\"\"\"\n\nL, R, A = list(map(int, input().split()))\nif L <= R:\n if A < R - L:\n print(2 * (L + A))\n else:\n A -= (R - L)\n print(2 * (R + A // 2))\nelse:\n if A < L - R:\n print(2 * (R + A))\n else:\n A -= (L - R)\n print(2 * (L + A // 2))\n", "passed": true, "time": 0.25, "memory": 14400.0, "status": "done"}, {"code": "l, r, a = map(int, input().split())\nl, r = min(l, r), max(l, r)\nf = min(r-l, a)\nl += f\na -= f\no = l*2 + (a // 2) * 2\nprint(o)", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "l, r, a = list(map(int, input().split()))\nsmall, big = sorted((l, r))\nif big-small > a:\n print(2* (small+a))\nelse:\n a-=(big-small)\n print(2*(big + a//2))\n", "passed": true, "time": 0.14, "memory": 14492.0, "status": "done"}, {"code": "l, r, a = list(map(int, input().split()))\n\nif l > r:\n l, r = r, l\n\nb = min(r - l, a)\n\ntotal = (l + b) * 2 + (a - b) // 2 * 2\nprint(total)\n", "passed": true, "time": 0.14, "memory": 14416.0, "status": "done"}, {"code": "l, p, a = map(int, input().split());\nx = min(l, p);\ny = max(l, p);\nif (x + a) > y:\n print((l + p + a) // 2 * 2);\nelse:\n print(2 * (x + a));", "passed": true, "time": 0.22, "memory": 14600.0, "status": "done"}, {"code": "s = input().split()\nl, r, a = int(s[0]), int(s[1]), int(s[2])\nx = min(l, r)\ny = max(l, r)\nwhile(a!=0 and x!=y):\n x+=1\n a-=1\n\nprint(min(x, y)*2 + a//2*2)", "passed": true, "time": 0.14, "memory": 14544.0, "status": "done"}, {"code": "l, r, a = [int(x) for x in input().split()]\nmaxi = max(l, r)\nmini = min(l, r)\nwhile mini!=maxi and a!=0:\n a-=1\n mini+=1\nwhile a//2>0:\n mini+=1\n maxi+=1\n a-=2\nmaxi=mini\nprint(mini+maxi)\n", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}] | [{"input": "1 4 2\n", "output": "6\n"}, {"input": "5 5 5\n", "output": "14\n"}, {"input": "0 2 0\n", "output": "0\n"}, {"input": "30 70 34\n", "output": "128\n"}, {"input": "89 32 24\n", "output": "112\n"}, {"input": "89 44 77\n", "output": "210\n"}, {"input": "0 0 0\n", "output": "0\n"}, {"input": "100 100 100\n", "output": "300\n"}, {"input": "1 1 1\n", "output": "2\n"}, {"input": "30 70 35\n", "output": "130\n"}, {"input": "89 44 76\n", "output": "208\n"}, {"input": "0 100 100\n", "output": "200\n"}, {"input": "100 0 100\n", "output": "200\n"}, {"input": "100 1 100\n", "output": "200\n"}, {"input": "1 100 100\n", "output": "200\n"}, {"input": "100 100 0\n", "output": "200\n"}, {"input": "100 100 1\n", "output": "200\n"}, {"input": "1 2 1\n", "output": "4\n"}, {"input": "0 0 100\n", "output": "100\n"}, {"input": "0 100 0\n", "output": "0\n"}, {"input": "100 0 0\n", "output": "0\n"}, {"input": "10 8 7\n", "output": "24\n"}, {"input": "45 47 16\n", "output": "108\n"}, {"input": "59 43 100\n", "output": "202\n"}, {"input": "34 1 30\n", "output": "62\n"}, {"input": "14 81 1\n", "output": "30\n"}, {"input": "53 96 94\n", "output": "242\n"}, {"input": "62 81 75\n", "output": "218\n"}, {"input": "21 71 97\n", "output": "188\n"}, {"input": "49 82 73\n", "output": "204\n"}, {"input": "88 19 29\n", "output": "96\n"}, {"input": "89 4 62\n", "output": "132\n"}, {"input": "58 3 65\n", "output": "126\n"}, {"input": "27 86 11\n", "output": "76\n"}, {"input": "35 19 80\n", "output": "134\n"}, {"input": "4 86 74\n", "output": "156\n"}, {"input": "32 61 89\n", "output": "182\n"}, {"input": "68 60 98\n", "output": "226\n"}, {"input": "37 89 34\n", "output": "142\n"}, {"input": "92 9 28\n", "output": "74\n"}, {"input": "79 58 98\n", "output": "234\n"}, {"input": "35 44 88\n", "output": "166\n"}, {"input": "16 24 19\n", "output": "58\n"}, {"input": "74 71 75\n", "output": "220\n"}, {"input": "83 86 99\n", "output": "268\n"}, {"input": "97 73 15\n", "output": "176\n"}, {"input": "77 76 73\n", "output": "226\n"}, {"input": "48 85 55\n", "output": "188\n"}, {"input": "1 2 2\n", "output": "4\n"}, {"input": "2 2 2\n", "output": "6\n"}, {"input": "2 1 2\n", "output": "4\n"}, {"input": "2 2 1\n", "output": "4\n"}, {"input": "3 2 1\n", "output": "6\n"}, {"input": "1 2 3\n", "output": "6\n"}, {"input": "1 3 2\n", "output": "6\n"}, {"input": "2 1 3\n", "output": "6\n"}, {"input": "2 3 1\n", "output": "6\n"}, {"input": "3 1 2\n", "output": "6\n"}, {"input": "99 99 99\n", "output": "296\n"}, {"input": "99 99 100\n", "output": "298\n"}, {"input": "99 100 99\n", "output": "298\n"}, {"input": "99 100 100\n", "output": "298\n"}, {"input": "100 99 99\n", "output": "298\n"}, {"input": "100 99 100\n", "output": "298\n"}, {"input": "100 100 99\n", "output": "298\n"}, {"input": "89 32 23\n", "output": "110\n"}, {"input": "4 5 0\n", "output": "8\n"}, {"input": "3 0 3\n", "output": "6\n"}, {"input": "0 0 2\n", "output": "2\n"}, {"input": "97 97 0\n", "output": "194\n"}, {"input": "1 4 0\n", "output": "2\n"}, {"input": "5 2 0\n", "output": "4\n"}, {"input": "0 5 10\n", "output": "14\n"}, {"input": "0 1 2\n", "output": "2\n"}, {"input": "5 2 3\n", "output": "10\n"}, {"input": "5 5 0\n", "output": "10\n"}, {"input": "0 0 10\n", "output": "10\n"}, {"input": "0 1 1\n", "output": "2\n"}, {"input": "0 0 1\n", "output": "0\n"}] |
|
185 | Finished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters live, as quickly as possible.
There are $n$ manholes in the room which are situated on one line, but, unfortunately, all the manholes are closed, and there is one stone on every manhole. There is exactly one coin under every manhole, and to win the game Nastya should pick all the coins. Initially Nastya stands near the $k$-th manhole from the left. She is thinking what to do.
In one turn, Nastya can do one of the following: if there is at least one stone on the manhole Nastya stands near, throw exactly one stone from it onto any other manhole (yes, Nastya is strong). go to a neighboring manhole; if there are no stones on the manhole Nastya stays near, she can open it and pick the coin from it. After it she must close the manhole immediately (it doesn't require additional moves).
[Image] The figure shows the intermediate state of the game. At the current position Nastya can throw the stone to any other manhole or move left or right to the neighboring manholes. If she were near the leftmost manhole, she could open it (since there are no stones on it).
Nastya can leave the room when she picks all the coins. Monsters are everywhere, so you need to compute the minimum number of moves Nastya has to make to pick all the coins.
Note one time more that Nastya can open a manhole only when there are no stones onto it.
-----Input-----
The first and only line contains two integers $n$ and $k$, separated by space ($2 \leq n \leq 5000$, $1 \leq k \leq n$) — the number of manholes and the index of manhole from the left, near which Nastya stays initially. Initially there is exactly one stone near each of the $n$ manholes.
-----Output-----
Print a single integer — minimum number of moves which lead Nastya to pick all the coins.
-----Examples-----
Input
2 2
Output
6
Input
4 2
Output
13
Input
5 1
Output
15
-----Note-----
Let's consider the example where $n = 2$, $k = 2$. Nastya should play as follows:
At first she throws the stone from the second manhole to the first. Now there are two stones on the first manhole. Then she opens the second manhole and pick the coin from it. Then she goes to the first manhole, throws two stones by two moves to the second manhole and then opens the manhole and picks the coin from it.
So, $6$ moves are required to win. | interview | [{"code": "n, k = list(map(int,input().split()))\nif k == 1 or k == n:\n print(3 * n)\nelse:\n print(3 * n + min(k - 1, n - k))\n", "passed": true, "time": 0.17, "memory": 14352.0, "status": "done"}, {"code": "l = list(map(int, input().split()))\nprint(3*l[0]+min(l[1]-1,l[0]-l[1]))\n", "passed": true, "time": 0.17, "memory": 14356.0, "status": "done"}, {"code": "import getpass\nimport math\nimport sys\nimport string\nimport re\nimport math\nimport random\nfrom decimal import Decimal, getcontext\n\n\ndef ria():\n return [int(i) for i in input().split()]\n\n\nif getpass.getuser() != 'frohenk':\n filename = 'half'\n # sys.stdin = open('input.txt')\n # sys.stdout = open('output.txt', 'w')\nelse:\n sys.stdin = open('input.txt')\n # sys.stdin.close()\n\nn, k = ria()\nrcks = n + 1\nmny = n\nmvs = min((k - 1) * 2 + (n - k), (k - 1) + (n - k) * 2)\n\nif k == 1:\n mvs = n - 1\n\nif k == n:\n mvs = n - 1\n \nprint(mvs + rcks + mny)\n", "passed": true, "time": 0.16, "memory": 14576.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nans = 2 * n + 1\nans += n - 1 + min(k - 1, n - k)\nprint(ans)", "passed": true, "time": 1.74, "memory": 14528.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\n\nif k == 1:\n print(3*(n-1)+3)\nelif k == n:\n print(3*(n-1)+3)\n\nelse:\n shorter = min(k-1,n-k)\n longer = max(k-1,n-k)\n out = 0\n out += shorter*3 + shorter + longer*3 +3\n print (out)\n", "passed": true, "time": 0.15, "memory": 14524.0, "status": "done"}, {"code": "ii = lambda: int(input())\nmi = lambda: map(int, input().split())\nli = lambda: list(mi())\n\nn, k = mi()\nif k - 1 > n - k:\n k = n - k + 1\n\nans = n + k - 1 + 1 + n + n - 1\nprint(ans)", "passed": true, "time": 0.16, "memory": 14624.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\n\ndef rli():\n return list(map(int, input().split()))\n\n\ndef main():\n n, k = rli()\n ans = n * 3\n if k != n and k != 1:\n ans += min(n - k, k - 1)\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14312.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nprint(n * 3 + min(k, n + 1 - k) - 1)\n", "passed": true, "time": 0.14, "memory": 14456.0, "status": "done"}, {"code": "n,k=[int(x) for x in input().split()]\nprint(min(n-k,k-1)+3*n)\n", "passed": true, "time": 0.15, "memory": 14468.0, "status": "done"}, {"code": "n,k=list(map(int,input().split()))\ndiff1=k-1\ndiff2=n-k\nans=2\nif(diff1<=diff2):\n\tans+=4*(diff1)\n\tans+=1\n\tans+=3*(diff2)\nelse:\n\tans+=4*(diff2)\n\tans+=1\n\tans+=3*(diff1)\nprint(ans)\n", "passed": true, "time": 1.59, "memory": 14532.0, "status": "done"}, {"code": "N, K = list(map(int, input().split()))\nprint(3*N+min(K-1, N-K))\n", "passed": true, "time": 1.59, "memory": 14452.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nprint(n + min(k-1, n-k) + n + n)", "passed": true, "time": 0.16, "memory": 14360.0, "status": "done"}, {"code": "# \nimport collections, atexit, math, sys, bisect \n\nsys.setrecursionlimit(1000000)\n\nisdebug = False\ntry :\n #raise ModuleNotFoundError\n import pylint\n import numpy\n def dprint(*args, **kwargs):\n #print(*args, **kwargs, file=sys.stderr)\n # in python 3.4 **kwargs is invalid???\n print(*args, file=sys.stderr)\n dprint('debug mode')\n isdebug = True\nexcept Exception:\n def dprint(*args, **kwargs):\n pass\n\n\ndef red_inout():\n inId = 0\n outId = 0\n if not isdebug:\n inId = 0\n outId = 0\n if inId>0:\n dprint('use input', inId)\n try:\n f = open('input'+ str(inId) + '.txt', 'r')\n sys.stdin = f #\u6807\u51c6\u8f93\u51fa\u91cd\u5b9a\u5411\u81f3\u6587\u4ef6\n except Exception:\n dprint('invalid input file')\n if outId>0:\n dprint('use output', outId)\n try:\n f = open('stdout'+ str(outId) + '.txt', 'w')\n sys.stdout = f #\u6807\u51c6\u8f93\u51fa\u91cd\u5b9a\u5411\u81f3\u6587\u4ef6\n except Exception:\n dprint('invalid output file')\n \n atexit.register(lambda :sys.stdout.close()) #idle \u4e2d\u4e0d\u4f1a\u6267\u884c atexit\n\nif isdebug and len(sys.argv) == 1:\n red_inout()\n\ndef getIntList():\n return list(map(int, input().split())) \n\ndef solve(): \n pass\n \nT_ = 1 \n#T_, = getIntList()\n\nfor iii_ in range(T_):\n #solve()\n N, K = getIntList()\n #print(N)\n r = N+1\n r+= N\n r +=N\n r += min(K-1, N-K) -1\n print(r)\n \n\n\n\n\n\n\n", "passed": true, "time": 0.17, "memory": 14588.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nk -= 1\n\ngo_to_border = min(k, n-k-1)\nmore = 3 * n\nprint(go_to_border + more)", "passed": true, "time": 0.15, "memory": 14456.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nans = 0\nif k != 1 and k != n:\n ans = 2 * min(k - 1, n - k) + max(k - 1, n - k) + 2 * n + 1\nelse:\n ans = 3 * n\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14604.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nans = (n + 1) + n + min(n - k, k - 1) + (n - 1)\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14392.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\nl = k - 1\nr = n - k\n\nprint(1 + n + 2 * min(l, r) + max(l, r) + n)\n", "passed": true, "time": 0.15, "memory": 14416.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nif 2 * k <= (n + 1):\n print(3 * n + k - 1)\nelse:\n print(4 * n - k)", "passed": true, "time": 0.15, "memory": 14308.0, "status": "done"}, {"code": "n, k = list(map( int, input().split()))\n\nmn = min( k - 1, n - k )\n\nprint( 3*n + mn )\n", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "n,k=map(int,input().split())\nans=n*3\nu=min(n-k,k-1)\nans=ans+u\nprint(ans)", "passed": true, "time": 0.15, "memory": 14308.0, "status": "done"}, {"code": "n, k = (int(t) for t in input().split(' '))\nprint(n*3 + min(k-1, (n-k)))", "passed": true, "time": 0.14, "memory": 14336.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nprint(n + 1 + n + n - 1 + min(k - 1, n - k))\n", "passed": true, "time": 0.15, "memory": 14576.0, "status": "done"}, {"code": "n, m = list(map(int,input().split()))\nprint(n * 3 + min(m - 1, n - m))\n", "passed": true, "time": 0.24, "memory": 14500.0, "status": "done"}, {"code": "def main():\n n,k = list(map(int,input().split()))\n moves = 2*n\n moves += 1\n moves += min(k-1,n-k)\n moves += n-1\n\n print (moves)\n\nmain()\n", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\nif k > n//2:\n\tk = n + 1 - k\nprint( 2 * (k - 1) + 1 + k + 2 + 2 * (n - k - 1 ) + n)", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}] | [{"input": "2 2\n", "output": "6\n"}, {"input": "4 2\n", "output": "13\n"}, {"input": "5 1\n", "output": "15\n"}, {"input": "64 49\n", "output": "207\n"}, {"input": "24 6\n", "output": "77\n"}, {"input": "91 39\n", "output": "311\n"}, {"input": "87 87\n", "output": "261\n"}, {"input": "72 36\n", "output": "251\n"}, {"input": "4237 4112\n", "output": "12836\n"}, {"input": "1815 1371\n", "output": "5889\n"}, {"input": "5000 1628\n", "output": "16627\n"}, {"input": "5000 3531\n", "output": "16469\n"}, {"input": "5000 2895\n", "output": "17105\n"}, {"input": "5000 539\n", "output": "15538\n"}, {"input": "5000 3576\n", "output": "16424\n"}, {"input": "3474 3427\n", "output": "10469\n"}, {"input": "3400 1203\n", "output": "11402\n"}, {"input": "4345 1015\n", "output": "14049\n"}, {"input": "2944 2468\n", "output": "9308\n"}, {"input": "2029 360\n", "output": "6446\n"}, {"input": "4951 4649\n", "output": "15155\n"}, {"input": "3058 82\n", "output": "9255\n"}, {"input": "113 42\n", "output": "380\n"}, {"input": "3355 2536\n", "output": "10884\n"}, {"input": "1214 76\n", "output": "3717\n"}, {"input": "4158 2162\n", "output": "14470\n"}, {"input": "1052 1052\n", "output": "3156\n"}, {"input": "2116 1\n", "output": "6348\n"}, {"input": "530 530\n", "output": "1590\n"}, {"input": "675 675\n", "output": "2025\n"}, {"input": "308 1\n", "output": "924\n"}, {"input": "731 1\n", "output": "2193\n"}, {"input": "4992 1\n", "output": "14976\n"}, {"input": "4676 1\n", "output": "14028\n"}, {"input": "3247 1623\n", "output": "11363\n"}, {"input": "4291 2145\n", "output": "15017\n"}, {"input": "3010 1505\n", "output": "10534\n"}, {"input": "4919 2459\n", "output": "17215\n"}, {"input": "978 489\n", "output": "3422\n"}, {"input": "3151 1575\n", "output": "11027\n"}, {"input": "3046 1523\n", "output": "10660\n"}, {"input": "2563 1281\n", "output": "8969\n"}, {"input": "2266 1133\n", "output": "7930\n"}, {"input": "3068 1534\n", "output": "10737\n"}, {"input": "2229 1114\n", "output": "7800\n"}, {"input": "1237 618\n", "output": "4328\n"}, {"input": "4602 2301\n", "output": "16106\n"}, {"input": "2 1\n", "output": "6\n"}, {"input": "8 2\n", "output": "25\n"}, {"input": "10 9\n", "output": "31\n"}, {"input": "10 2\n", "output": "31\n"}, {"input": "9 1\n", "output": "27\n"}, {"input": "8 4\n", "output": "27\n"}, {"input": "40 24\n", "output": "136\n"}, {"input": "10 4\n", "output": "33\n"}, {"input": "3 3\n", "output": "9\n"}, {"input": "44 1\n", "output": "132\n"}, {"input": "18 12\n", "output": "60\n"}, {"input": "88 33\n", "output": "296\n"}, {"input": "7 3\n", "output": "23\n"}, {"input": "65 61\n", "output": "199\n"}, {"input": "87 27\n", "output": "287\n"}, {"input": "5000 3336\n", "output": "16664\n"}, {"input": "5000 2653\n", "output": "17347\n"}, {"input": "5000 4494\n", "output": "15506\n"}, {"input": "5000 2612\n", "output": "17388\n"}, {"input": "5000 3378\n", "output": "16622\n"}, {"input": "5000 888\n", "output": "15887\n"}, {"input": "5000 1\n", "output": "15000\n"}, {"input": "5000 2500\n", "output": "17499\n"}, {"input": "3 1\n", "output": "9\n"}, {"input": "2 1\n", "output": "6\n"}, {"input": "1029 1028\n", "output": "3088\n"}, {"input": "10 9\n", "output": "31\n"}, {"input": "4 1\n", "output": "12\n"}, {"input": "1024 1023\n", "output": "3073\n"}, {"input": "1023 999\n", "output": "3093\n"}, {"input": "1000 199\n", "output": "3198\n"}, {"input": "1000 201\n", "output": "3200\n"}] |
|
186 | Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.
The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.
-----Input-----
The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.
-----Output-----
Print a single integer, denoting the minimum possible height of the tallest tower.
-----Examples-----
Input
1 3
Output
9
Input
3 2
Output
8
Input
5 0
Output
10
-----Note-----
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks. | interview | [{"code": "n, m = list(map(int, input().split()))\n\nstart = 0\nend = 10**10\nwhile (end - start > 1):\n mid = (end + start) // 2\n two = mid // 2 - mid // 6\n three = mid // 3 - mid // 6\n six = mid // 6\n\n nn = n\n mm = m\n\n nn -= two\n mm -= three\n nn = max(nn, 0)\n mm = max(mm, 0)\n if (six >= nn + mm):\n end = mid\n else:\n start = mid\nprint(end)\n", "passed": true, "time": 0.16, "memory": 14496.0, "status": "done"}, {"code": "a, b = list(map(int, input().split(' ')))\nlo = 1\nhi = 1000000000\nwhile (lo < hi):\n mid = (lo + hi)//2\n x = mid // 2\n y = mid // 3\n z = mid // 6\n x-=z\n y-=z\n t=0\n if x<=a:\n t+=a-x\n if y<=b:\n t+=b-y\n if t>z:\n lo = mid+1\n else:\n hi = mid\nprint(lo)\n", "passed": true, "time": 0.3, "memory": 14528.0, "status": "done"}, {"code": "def right(m, n, a):\n b = True\n n2 = a // 2 - a // 6\n n3 = a // 3 - a // 6\n n6 = a // 6\n if n2+n6<n or n3+n6<m or n2+n3+n6<n+m:\n b = False\n return b\n \n\nn, m = list(map(int, input().split()))\nans = n+m\nwhile not right(m, n, ans):\n ans += 1\nprint(ans)\n\t\t\t \n", "passed": true, "time": 12.7, "memory": 14404.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nleft = 0\nright = 10000000\nwhile right - left != 1:\n mid = (left + right) // 2\n # print(left, right)\n all_places = mid // 2 + mid // 3 - mid // 6\n if not(2 * n <= mid and 3 * m <= mid and n + m <= all_places):\n left = mid\n else:\n right = mid\nprint(right)", "passed": true, "time": 1.69, "memory": 14428.0, "status": "done"}, {"code": "n, m = list(map(int,input().split()))\nmaxn = 0\nfor i in range(n):\n maxn += 2\n if maxn % 3 == 0: maxn += 2\n#print(maxn)\nmaxm = m * 6 - 3\nnow = 6\nwhile now < max(maxm,maxn):\n if maxm >= maxn:\n maxm -= 3\n if maxm % 2 == 0 and maxm-3 > now:maxm -= 3\n else:\n maxn -= 2\n if maxn % 3 == 0 and maxn-2 > now: maxn -= 2\n now += 6\nprint(max(maxm,maxn))\n", "passed": true, "time": 5.76, "memory": 14408.0, "status": "done"}, {"code": "n,m = list(map(int, input().split()))\nanswer=0\nwhile True:\n if n >=3 and m>=2:\n \n if n/m>3/2:\n n-=3\n m-=1\n else:\n n-=2\n m-=2\n \n \n answer+=6\n else:\n if m == 1:\n answer += max(3, 2* n)\n break\n elif m == 0:\n answer+= 2*n\n break\n else:\n answer += 3*m\n break\nprint(answer)\n", "passed": true, "time": 1.27, "memory": 14576.0, "status": "done"}, {"code": "n, m = [int(x) for x in input().split()]\nh1 = lambda k: 6*((k-1)//2) + 2*((k-1)%2+1) if k > 0 else 0\nh2 = lambda k: 3 + (k-1)*6 if k > 0 else 0\nh3 = lambda l: 6*k\nnewx = lambda k: k - 2 if k%6 == 4 else k - 4\nnewy = lambda k: k - 6\nx, y, z = h1(n), h2(m), 0\nwhile max(x, y) > z + 6:\n z += 6\n if x > y:\n x = newx(x)\n else:\n y = newy(y)\nprint(max(x, y, z))\n \n", "passed": true, "time": 6.61, "memory": 14404.0, "status": "done"}, {"code": "def check(n2, n3, k):\n q2 = k // 2\n q3 = k // 3\n q6 = k // 6\n q2 -= q6\n q3 -= q6\n lo = n2 - q2\n hi = q3 + q6 - n3\n return lo <= hi and lo <= q6 and 0 <= hi\n\ndef go(n2, n3):\n lo = -1\n hi = int(6e7)\n while lo + 1 < hi:\n k = (lo + hi) // 2\n if check(n2, n3, k):\n hi = k\n else:\n lo = k\n return hi\n\nn2, n3 = list(map(int, input().split()))\nprint(go(n2, n3))\n", "passed": true, "time": 0.19, "memory": 14388.0, "status": "done"}, {"code": "def check(x):\n return max(n - (x - 2) // 6 - (x - 4) // 6 - 2, 0) + \\\n max(m - (x - 3) // 6 - 1, 0) <= x // 6\n\n\nn, m = list(map(int, input().split()))\nleft, right = 0, 10 ** 10\nwhile left + 1 < right:\n middle = (left + right) >> 1\n if check(middle):\n right = middle\n else:\n left = middle\nprint(right)\n", "passed": true, "time": 0.19, "memory": 14368.0, "status": "done"}, {"code": "t2, t3 = list(map(int,input().split(' ')))\n\nleft = 2*(t2)-10\nright = 3*(t2+t3)+10\nwhile right-left != 1:\n guess = int((left+right)/2)\n work2 = int(guess/2)-int(guess/6)\n work3 = int(guess/3)-int(guess/6)\n work6 = int(guess/6)\n if max(0,t2-work2)+max(0,t3-work3) <= work6:\n right = guess\n else:\n left = guess\nprint(right)\n", "passed": true, "time": 0.3, "memory": 14608.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport time\n\n\n(n, m) = (int(i) for i in input().split())\n\nstart = time.time()\n\nh2 = 2*n\nh3 = 3*m\n\nk = 6\nwhile (k <= min(h2, h3)):\n if h2+2 < h3 + 3:\n h2 += 2\n else:\n h3 += 3\n k += 6\n\nprint(max(h2, h3))\nfinish = time.time()\n#print(finish - start)\n", "passed": true, "time": 2.14, "memory": 14344.0, "status": "done"}, {"code": "n, m = map(int, input().split())\na, b = 2 * n, 3 * m\nfor i in range(6, 10 ** 10, 6):\n if a >= i and b >= i:\n if a <= b:\n a += 2\n else:\n b += 3\n else:\n break\nprint(max(a, b))", "passed": true, "time": 0.81, "memory": 14536.0, "status": "done"}, {"code": "n,m=map(int,input().split())\na=2*n\nb=3*m\ni=6\nwhile i<=min(a,b):\n if b<a: b+=3\n else: a+=2\n i+=6\nprint(max(a,b))", "passed": true, "time": 2.12, "memory": 14528.0, "status": "done"}, {"code": "def main():\n n2, n3 = map(int, input().split())\n\n nmax = 3 * max(n2, n3) * 2\n c2 = c3 = c6 = 0\n for n in range(1, nmax):\n if n % 6 == 0:\n c6 += 1\n elif c3 < n3 and n % 3 == 0:\n c3 += 1\n elif c2 < n2 and n % 2 == 0:\n c2 += 1\n if n2 - c2 + n3 - c3 - c6 == 0:\n print(n)\n break\n\n\nmain()", "passed": true, "time": 17.6, "memory": 14412.0, "status": "done"}, {"code": "3\n\n(n, m) = tuple(map(int, input().split()))\n\na = 2*n\nb = 3*m\nc = n//3\nd = m//2\nwhile c > 0 and d > 0:\n if a > b:\n b += 3\n c -= 1\n d -= 1\n if b%6 == 0:\n d +=1\n else:\n a += 2\n c -= 1\n d -= 1\n if a%6 == 0:\n c += 1\n #print(a,b,c,d)\nprint(str(max(a,b)))\n", "passed": true, "time": 1.36, "memory": 14688.0, "status": "done"}, {"code": "import collections\nimport math\n\nn, m = list(map(int, input().split()))\nx = min(2 * n, 3 * m) // 6\na, b = 2 * n, 3 * m\nwhile x:\n while a <= b and x:\n a += 2\n x -= 1\n if a % 6 == 0:\n a += 2\n while b < a and x:\n b += 3\n x -= 1\n if b % 6 == 0 and b < a:\n b += 3\n elif b % 6 == 0 and b == a:\n a += 2\nprint(max(a, b))\n", "passed": true, "time": 1.63, "memory": 14524.0, "status": "done"}, {"code": "n, m = list(map(int,input().split()))\na, b, i = 2 * n, 3 * m, 6\nwhile i <= min(a, b):\n if b < a: b += 3\n else: a += 2\n i += 6\nprint(max(a, b))\n", "passed": true, "time": 2.71, "memory": 14488.0, "status": "done"}, {"code": "s=input().split()\n\nn,m=s\nn=int(n)\nm=int(m)\nn*=2\nm*=3\ni=1\n\nwhile True:\n if n<=m:\n if i*6<=n:\n n+=2\n else:\n break\n else:\n if i*6<=m:\n m+=3\n else:\n break\n i+=1\n \nprint(max(n,m))\n\n", "passed": true, "time": 0.95, "memory": 14496.0, "status": "done"}, {"code": "n,m = map(int , input().split())\ni = 0\nwhile(i//2 <n or i//3 < m or i//2 + i//3 - i//6 < n+m):\n\ti+=1\nprint(i)", "passed": true, "time": 8.35, "memory": 14408.0, "status": "done"}, {"code": "import sys\n\nn, m = list(map(int, input().split()))\ni = k2 = k3 = k6 = 0\nwhile True:\n i += 1\n if i % 6 == 0:\n k6 += 1\n else:\n if i % 3 == 0:\n k3 += 1\n if i % 2 == 0:\n k2 += 1\n k2 = min(n, k2)\n k3 = min(m, k3)\n need = n - k2 + m - k3\n if need <= k6:\n print(i)\n return\n", "passed": true, "time": 39.16, "memory": 14340.0, "status": "done"}, {"code": "def __starting_point():\n d,t = list(map(int,input().split(' ')))\n result = 0\n i2 = d*2\n i3 = t*3\n cm = int(max(i2,i3)/6) #common\n while cm>0:\n if i2+2<i3+3:\n i2+=2\n elif i2+2> i3+3:\n i3+=3\n else:\n i2+=2\n cm+=1\n cm-=1\n print(max(i2,i3))\n\n '''\n if index2+common*2<=index3:\n result = index3\n else:\n result = index2+common*2\n if index2>=index3+common*3:\n result = index2\n '''\n '''\n while common>0:\n print (d,t,common,oldCommon)\n if (d+1)*2<=(t+1)*3:\n d+=1\n else:\n t+=1\n index2 = d*2\n index3 = t*3\n print (index2,index3)\n common = int(min(index2,index3)/6)\n\n x = common \n common-=oldCommon\n oldCommon=x\n print(max(index2,index3))\n '''\n\n'''\n\nC. Block Towers\ntime limit per test\n2 seconds\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\n\nStudents in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.\n\nThe students don\u2019t want to use too many blocks, but they also want to be unique, so no two students\u2019 towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.\nInput\n\nThe first line of the input contains two space-separated integers n and m (0\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20091\u2009000\u2009000, n\u2009+\u2009m\u2009>\u20090) \u2014 the number of students using two-block pieces and the number of students using three-block pieces, respectively.\nOutput\n\nPrint a single integer, denoting the minimum possible height of the tallest tower.\nExamples\nInput\n\n1 3\n\nOutput\n\n9\n\nInput\n\n3 2\n\nOutput\n\n8\n\nInput\n\n5 0\n\nOutput\n\n10\n\nNote\n\nIn the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.\n\nIn the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.\n\n'''\n\n__starting_point()", "passed": true, "time": 1.9, "memory": 14516.0, "status": "done"}, {"code": "n, m = map(int, input().split())\n\nmax_m = m*3\nbusy_by_m = int(m*3/6)\nmax_n = (n + busy_by_m)*2*bool(n)\n\nnd = 0\nmd = 0\nmaxv = 0\n\nif max_n > max_m:\n nd = -2\n md = +3\n\n max_n_prev = max_n\n max_m_prev = max_m\n\n for i in range(busy_by_m):\n max_n_prev = max_n\n max_m_prev = max_m\n max_n += nd\n max_m += md\n if max_m % 2 == 0:\n max_m += md\n #print ((max_n_prev, max_m_prev), (max_n, max_m))\n #input()\n if max(max_n_prev, max_m_prev) < max(max_n, max_m):\n break\n\n maxv = min(max(max_n_prev, max_m_prev), max(max_n, max_m))\nelse:\n maxv = max_m\n\nprint (maxv)", "passed": true, "time": 1.02, "memory": 14608.0, "status": "done"}, {"code": "import sys\n\n\n\n\n##Wrong answer... not finished\ndef main():\n n, m = [int(f) for f in sys.stdin.readline().split()]\n\n h = max(2 * n, 3 * m)\n\n n_common = h // 6\n\n n3 = h // 3 - n_common\n n2 = h // 2 - n_common\n\n\n if (n3 + n2 + n_common) >= (m + n):\n res = h\n else:\n while n3 + n2 + n_common < m + n:\n h += 1\n\n if h % 2 != 0 and h % 3 != 0:\n continue\n\n n_common = h // 6\n n3 = h // 3 - n_common\n n2 = h // 2 - n_common\n res = h\n\n print(res)\n\n\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 2.18, "memory": 14360.0, "status": "done"}, {"code": "nm = input().split(\" \")\nn = int(nm[0])\nm = int(nm[1])\n#not allowed to be the same height, not not same number of blocks\nif n == 0:\n print(3*m)\nelif m == 0:\n print(2*n)\nelse:\n new = max(3*m, 2*n)\n i = 0\n while i<new+1:\n if i%6 == 0 and i != 0:\n if i//3 <= m and i//2 <= n and 2*(n+1)-new < 3*(m+1)-new:\n n += 1\n elif i//3 <= m and i//2 <= n and 2*(n+1)-new >= 3*(m+1)-new:\n m += 1\n new = max(3*m, 2*n)\n i+=1\n print(max(3*m,2*n))", "passed": true, "time": 12.08, "memory": 14472.0, "status": "done"}] | [{"input": "1 3\n", "output": "9\n"}, {"input": "3 2\n", "output": "8\n"}, {"input": "5 0\n", "output": "10\n"}, {"input": "4 2\n", "output": "9\n"}, {"input": "0 1000000\n", "output": "3000000\n"}, {"input": "1000000 1\n", "output": "2000000\n"}, {"input": "1083 724\n", "output": "2710\n"}, {"input": "1184 868\n", "output": "3078\n"}, {"input": "1285 877\n", "output": "3243\n"}, {"input": "820189 548173\n", "output": "2052543\n"}, {"input": "968867 651952\n", "output": "2431228\n"}, {"input": "817544 553980\n", "output": "2057286\n"}, {"input": "813242 543613\n", "output": "2035282\n"}, {"input": "961920 647392\n", "output": "2413968\n"}, {"input": "825496 807050\n", "output": "2448819\n"}, {"input": "974174 827926\n", "output": "2703150\n"}, {"input": "969872 899794\n", "output": "2804499\n"}, {"input": "818549 720669\n", "output": "2308827\n"}, {"input": "967227 894524\n", "output": "2792626\n"}, {"input": "185253 152723\n", "output": "506964\n"}, {"input": "195173 150801\n", "output": "518961\n"}, {"input": "129439 98443\n", "output": "341823\n"}, {"input": "163706 157895\n", "output": "482402\n"}, {"input": "197973 140806\n", "output": "508168\n"}, {"input": "1000000 1000000\n", "output": "3000000\n"}, {"input": "1000000 999999\n", "output": "2999998\n"}, {"input": "999999 1000000\n", "output": "3000000\n"}, {"input": "500000 500100\n", "output": "1500300\n"}, {"input": "500000 166000\n", "output": "1000000\n"}, {"input": "500000 499000\n", "output": "1498500\n"}, {"input": "500000 167000\n", "output": "1000500\n"}, {"input": "1 1000000\n", "output": "3000000\n"}, {"input": "2 999123\n", "output": "2997369\n"}, {"input": "10 988723\n", "output": "2966169\n"}, {"input": "234 298374\n", "output": "895122\n"}, {"input": "2365 981235\n", "output": "2943705\n"}, {"input": "12345 981732\n", "output": "2945196\n"}, {"input": "108752 129872\n", "output": "389616\n"}, {"input": "984327 24352\n", "output": "1968654\n"}, {"input": "928375 1253\n", "output": "1856750\n"}, {"input": "918273 219\n", "output": "1836546\n"}, {"input": "987521 53\n", "output": "1975042\n"}, {"input": "123456 1\n", "output": "246912\n"}, {"input": "789123 0\n", "output": "1578246\n"}, {"input": "143568 628524\n", "output": "1885572\n"}, {"input": "175983 870607\n", "output": "2611821\n"}, {"input": "6 4\n", "output": "15\n"}, {"input": "6 3\n", "output": "14\n"}, {"input": "7 3\n", "output": "15\n"}, {"input": "5 4\n", "output": "14\n"}, {"input": "5 3\n", "output": "12\n"}, {"input": "8 5\n", "output": "20\n"}, {"input": "1 0\n", "output": "2\n"}, {"input": "19170 15725\n", "output": "52342\n"}, {"input": "3000 2000\n", "output": "7500\n"}, {"input": "7 4\n", "output": "16\n"}, {"input": "50 30\n", "output": "120\n"}, {"input": "300 200\n", "output": "750\n"}, {"input": "9 4\n", "output": "20\n"}, {"input": "4 3\n", "output": "10\n"}, {"input": "1 1\n", "output": "3\n"}, {"input": "8 6\n", "output": "21\n"}, {"input": "10 6\n", "output": "24\n"}, {"input": "65 56\n", "output": "182\n"}, {"input": "13 10\n", "output": "34\n"}, {"input": "14 42\n", "output": "126\n"}, {"input": "651 420\n", "output": "1606\n"}, {"input": "8 9\n", "output": "27\n"}, {"input": "15 10\n", "output": "38\n"}, {"input": "999999 888888\n", "output": "2833330\n"}, {"input": "192056 131545\n", "output": "485402\n"}, {"input": "32 16\n", "output": "72\n"}, {"input": "18 12\n", "output": "45\n"}, {"input": "1000000 666667\n", "output": "2500000\n"}, {"input": "0 1\n", "output": "3\n"}, {"input": "9 5\n", "output": "21\n"}, {"input": "1515 1415\n", "output": "4395\n"}, {"input": "300000 200000\n", "output": "750000\n"}] |
|
187 | Petya and Vasya decided to play a game. They have n cards (n is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written.
The game is considered fair if Petya and Vasya can take all n cards, and the number of cards each player gets is the same.
Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100) — number of cards. It is guaranteed that n is an even number.
The following n lines contain a sequence of integers a_1, a_2, ..., a_{n} (one integer per line, 1 ≤ a_{i} ≤ 100) — numbers written on the n cards.
-----Output-----
If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.
In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them.
-----Examples-----
Input
4
11
27
27
11
Output
YES
11 27
Input
2
6
6
Output
NO
Input
6
10
20
30
20
10
20
Output
NO
Input
6
1
1
2
2
3
3
Output
NO
-----Note-----
In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.
In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct.
In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards. | interview | [{"code": "n = int(input())\na = [int(input()) for i in range(n)]\na.sort()\nb = [ai for ai in a if ai==a[0]]\nc = [ai for ai in a if ai!=a[0]]\nif len(b)==len(c) and c[0]==c[-1]:\n print('YES')\n print(b[0], c[0])\nelse:\n print('NO')", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "n=int(input())\nl=[]\nfor i in range(n):\n l+=[int(input())]\nl.sort(key=int)\nif l.count(l[0])==n>>1 and l.count(l[-1])==n>>1:\n print(\"YES\")\n print(l[0],l[-1])\nelse:\n print(\"NO\")\n", "passed": true, "time": 1.17, "memory": 14328.0, "status": "done"}, {"code": "n = int(input())\nl = [0]*n\nfor i in range(n):\n\tl[i]=int(input())\nl.sort()\nif l.count(l[0])==l.count(l[n-1])==n/2:\n\tprint('YES')\n\tprint(l[0] , l[n-1])\nelse:\n\tprint(\"NO\")", "passed": true, "time": 0.15, "memory": 14212.0, "status": "done"}, {"code": "a=[]\nb=[]\nfor i in range(int(input())):\n a.append(int(input()))\nb=list(set(a))\n \nif len(b)!=2:\n print('NO')\nelif a.count(b[0])==a.count(b[1]):\n print('YES')\n b.sort()\n print(*b)\nelse:\n print('NO')\n", "passed": true, "time": 0.26, "memory": 14336.0, "status": "done"}] | [{"input": "4\n11\n27\n27\n11\n", "output": "YES\n11 27\n"}, {"input": "2\n6\n6\n", "output": "NO\n"}, {"input": "6\n10\n20\n30\n20\n10\n20\n", "output": "NO\n"}, {"input": "6\n1\n1\n2\n2\n3\n3\n", "output": "NO\n"}, {"input": "2\n1\n100\n", "output": "YES\n1 100\n"}, {"input": "2\n1\n1\n", "output": "NO\n"}, {"input": "2\n100\n100\n", "output": "NO\n"}, {"input": "14\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n", "output": "NO\n"}, {"input": "100\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n", "output": "YES\n14 32\n"}, {"input": "2\n50\n100\n", "output": "YES\n50 100\n"}, {"input": "2\n99\n100\n", "output": "YES\n99 100\n"}, {"input": "4\n4\n4\n5\n5\n", "output": "YES\n4 5\n"}, {"input": "10\n10\n10\n10\n10\n10\n23\n23\n23\n23\n23\n", "output": "YES\n10 23\n"}, {"input": "20\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n11\n11\n11\n11\n11\n11\n11\n11\n11\n11\n", "output": "YES\n11 34\n"}, {"input": "40\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n", "output": "YES\n20 30\n"}, {"input": "58\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\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", "output": "YES\n1 100\n"}, {"input": "98\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n", "output": "YES\n2 99\n"}, {"input": "100\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\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n", "output": "YES\n1 100\n"}, {"input": "100\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\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n", "output": "YES\n1 2\n"}, {"input": "100\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n", "output": "YES\n99 100\n"}, {"input": "100\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n29\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n", "output": "YES\n29 43\n"}, {"input": "100\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n88\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n", "output": "YES\n88 98\n"}, {"input": "100\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n", "output": "YES\n2 34\n"}, {"input": "100\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n", "output": "YES\n23 94\n"}, {"input": "100\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n", "output": "YES\n14 15\n"}, {"input": "100\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n23\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n21\n", "output": "YES\n21 23\n"}, {"input": "100\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n", "output": "YES\n32 98\n"}, {"input": "100\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n", "output": "YES\n3 4\n"}, {"input": "100\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n", "output": "YES\n12 34\n"}, {"input": "100\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n19\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n", "output": "YES\n19 32\n"}, {"input": "100\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n85\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n", "output": "YES\n54 85\n"}, {"input": "100\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n", "output": "YES\n12 43\n"}, {"input": "100\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n96\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n95\n", "output": "YES\n95 96\n"}, {"input": "100\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n4\n", "output": "YES\n4 33\n"}, {"input": "100\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n", "output": "YES\n98 99\n"}, {"input": "100\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n87\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n", "output": "YES\n12 87\n"}, {"input": "100\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n13\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n24\n", "output": "YES\n13 24\n"}, {"input": "100\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n", "output": "YES\n12 49\n"}, {"input": "100\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n", "output": "YES\n15 94\n"}, {"input": "100\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n", "output": "YES\n33 42\n"}, {"input": "100\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n", "output": "YES\n16 35\n"}, {"input": "100\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n", "output": "YES\n33 44\n"}, {"input": "100\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n", "output": "YES\n54 98\n"}, {"input": "100\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n", "output": "YES\n12 81\n"}, {"input": "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n", "output": "NO\n"}, {"input": "100\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", "output": "NO\n"}, {"input": "40\n20\n20\n30\n30\n20\n20\n20\n30\n30\n20\n20\n30\n30\n30\n30\n20\n30\n30\n30\n30\n20\n20\n30\n30\n30\n20\n30\n20\n30\n20\n30\n20\n20\n20\n30\n20\n20\n20\n30\n30\n", "output": "NO\n"}, {"input": "58\n100\n100\n100\n100\n100\n1\n1\n1\n1\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n100\n1\n100\n100\n100\n100\n100\n1\n1\n100\n100\n100\n100\n1\n100\n1\n1\n1\n1\n1\n", "output": "NO\n"}, {"input": "98\n2\n99\n99\n99\n99\n2\n99\n99\n99\n2\n2\n99\n2\n2\n2\n2\n99\n99\n2\n99\n2\n2\n99\n99\n99\n99\n2\n2\n99\n2\n99\n99\n2\n2\n99\n2\n99\n2\n99\n2\n2\n2\n99\n2\n2\n2\n2\n99\n99\n99\n99\n2\n2\n2\n2\n2\n2\n2\n2\n99\n2\n99\n99\n2\n2\n99\n99\n99\n99\n99\n99\n99\n99\n2\n99\n2\n99\n2\n2\n2\n99\n99\n99\n99\n99\n99\n2\n99\n99\n2\n2\n2\n2\n2\n99\n99\n99\n2\n", "output": "NO\n"}, {"input": "100\n100\n1\n100\n1\n1\n100\n1\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n1\n100\n1\n100\n1\n100\n100\n1\n100\n1\n100\n1\n1\n1\n1\n1\n100\n1\n100\n100\n100\n1\n100\n100\n1\n100\n1\n1\n100\n100\n100\n1\n100\n100\n1\n1\n100\n100\n1\n100\n1\n100\n1\n1\n100\n100\n100\n100\n100\n100\n1\n100\n100\n1\n100\n100\n1\n100\n1\n1\n1\n100\n100\n1\n100\n1\n100\n1\n1\n1\n1\n100\n1\n1\n100\n1\n100\n100\n1\n100\n1\n100\n", "output": "NO\n"}, {"input": "100\n2\n2\n2\n1\n1\n1\n2\n2\n1\n1\n1\n2\n2\n1\n2\n2\n1\n2\n2\n1\n1\n2\n1\n2\n2\n2\n2\n2\n1\n2\n1\n2\n1\n1\n2\n2\n2\n1\n1\n2\n2\n1\n2\n1\n1\n2\n1\n1\n1\n2\n2\n1\n2\n2\n2\n1\n1\n2\n1\n2\n2\n1\n1\n1\n1\n1\n1\n1\n2\n2\n2\n1\n2\n2\n2\n2\n1\n1\n2\n1\n1\n1\n2\n1\n2\n1\n1\n2\n2\n2\n1\n1\n1\n2\n2\n2\n1\n1\n2\n2\n", "output": "NO\n"}, {"input": "100\n99\n99\n100\n99\n99\n100\n100\n99\n99\n100\n99\n100\n100\n100\n100\n100\n100\n99\n100\n100\n99\n100\n99\n100\n100\n99\n99\n100\n99\n100\n99\n99\n100\n99\n100\n100\n99\n99\n100\n100\n100\n100\n100\n99\n100\n99\n100\n99\n100\n100\n100\n100\n100\n100\n99\n99\n99\n100\n99\n99\n99\n99\n99\n99\n100\n100\n99\n100\n100\n99\n99\n100\n100\n99\n100\n100\n99\n100\n99\n99\n100\n99\n99\n100\n99\n99\n100\n99\n100\n99\n100\n100\n99\n99\n99\n100\n99\n100\n100\n99\n", "output": "NO\n"}, {"input": "100\n42\n42\n42\n29\n29\n42\n42\n42\n29\n42\n29\n29\n29\n42\n29\n29\n42\n29\n42\n29\n42\n29\n42\n42\n42\n42\n29\n29\n42\n29\n29\n42\n29\n42\n29\n42\n29\n29\n42\n29\n29\n42\n42\n42\n29\n29\n29\n29\n42\n29\n29\n29\n29\n29\n29\n42\n42\n29\n42\n29\n42\n42\n29\n29\n29\n42\n42\n29\n42\n42\n42\n29\n29\n42\n29\n29\n29\n42\n42\n29\n29\n29\n42\n29\n42\n42\n29\n42\n42\n42\n42\n42\n29\n42\n29\n29\n29\n29\n29\n42\n", "output": "NO\n"}, {"input": "100\n98\n98\n98\n88\n88\n88\n88\n98\n88\n88\n88\n88\n88\n98\n88\n98\n88\n98\n88\n98\n98\n98\n98\n98\n98\n88\n98\n88\n88\n88\n98\n88\n88\n98\n88\n98\n88\n98\n98\n88\n98\n88\n98\n98\n98\n98\n88\n98\n98\n88\n88\n88\n88\n98\n98\n98\n98\n88\n98\n88\n98\n98\n88\n88\n98\n98\n88\n88\n98\n88\n98\n88\n98\n88\n98\n98\n88\n88\n98\n98\n98\n98\n88\n88\n98\n98\n88\n98\n88\n98\n98\n88\n98\n98\n88\n88\n98\n88\n98\n98\n", "output": "NO\n"}, {"input": "100\n100\n100\n100\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n100\n1\n100\n1\n100\n1\n100\n100\n100\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n1\n100\n100\n1\n100\n1\n1\n100\n1\n1\n100\n1\n100\n100\n100\n1\n100\n100\n100\n1\n100\n1\n100\n100\n100\n1\n1\n100\n100\n100\n100\n1\n100\n36\n100\n1\n100\n1\n100\n100\n100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n100\n1\n1\n100\n100\n100\n100\n100\n1\n100\n1\n100\n1\n1\n100\n100\n1\n100\n", "output": "NO\n"}, {"input": "100\n2\n1\n1\n2\n2\n1\n1\n1\n1\n2\n1\n1\n1\n2\n2\n2\n1\n1\n1\n2\n1\n2\n2\n2\n2\n1\n1\n2\n1\n1\n2\n1\n27\n1\n1\n1\n2\n2\n2\n1\n2\n1\n2\n1\n1\n2\n2\n2\n2\n2\n2\n2\n2\n1\n2\n2\n2\n2\n1\n2\n1\n1\n1\n1\n1\n2\n1\n1\n1\n2\n2\n2\n2\n2\n2\n1\n1\n1\n1\n2\n2\n1\n2\n2\n1\n1\n1\n2\n1\n2\n2\n1\n1\n2\n1\n1\n1\n2\n2\n1\n", "output": "NO\n"}, {"input": "100\n99\n99\n100\n99\n99\n100\n100\n100\n99\n100\n99\n99\n100\n99\n99\n99\n99\n99\n99\n100\n100\n100\n99\n100\n100\n99\n100\n99\n100\n100\n99\n100\n99\n99\n99\n100\n99\n10\n99\n100\n100\n100\n99\n100\n100\n100\n100\n100\n100\n100\n99\n100\n100\n100\n99\n99\n100\n99\n100\n99\n100\n100\n99\n99\n99\n99\n100\n99\n100\n100\n100\n100\n100\n100\n99\n99\n100\n100\n99\n99\n99\n99\n99\n99\n100\n99\n99\n100\n100\n99\n100\n99\n99\n100\n99\n99\n99\n99\n100\n100\n", "output": "NO\n"}, {"input": "100\n29\n43\n43\n29\n43\n29\n29\n29\n43\n29\n29\n29\n29\n43\n29\n29\n29\n29\n43\n29\n29\n29\n43\n29\n29\n29\n43\n43\n43\n43\n43\n43\n29\n29\n43\n43\n43\n29\n43\n43\n43\n29\n29\n29\n43\n29\n29\n29\n43\n43\n43\n43\n29\n29\n29\n29\n43\n29\n43\n43\n29\n29\n43\n43\n29\n29\n95\n29\n29\n29\n43\n43\n29\n29\n29\n29\n29\n43\n43\n43\n43\n29\n29\n43\n43\n43\n43\n43\n43\n29\n43\n43\n43\n43\n43\n43\n29\n43\n29\n43\n", "output": "NO\n"}, {"input": "100\n98\n98\n98\n88\n88\n88\n88\n98\n98\n88\n98\n88\n98\n88\n88\n88\n88\n88\n98\n98\n88\n98\n98\n98\n88\n88\n88\n98\n98\n88\n88\n88\n98\n88\n98\n88\n98\n88\n88\n98\n98\n98\n88\n88\n98\n98\n88\n88\n88\n88\n88\n98\n98\n98\n88\n98\n88\n88\n98\n98\n88\n98\n88\n88\n98\n88\n88\n98\n27\n88\n88\n88\n98\n98\n88\n88\n98\n98\n98\n98\n98\n88\n98\n88\n98\n98\n98\n98\n88\n88\n98\n88\n98\n88\n98\n98\n88\n98\n98\n88\n", "output": "NO\n"}, {"input": "100\n50\n1\n1\n50\n50\n50\n50\n1\n50\n100\n50\n50\n50\n100\n1\n100\n1\n100\n50\n50\n50\n50\n50\n1\n50\n1\n100\n1\n1\n50\n100\n50\n50\n100\n50\n50\n100\n1\n50\n50\n100\n1\n1\n50\n1\n100\n50\n50\n100\n100\n1\n100\n1\n50\n100\n50\n50\n1\n1\n50\n100\n50\n100\n100\n100\n50\n50\n1\n1\n50\n100\n1\n50\n100\n100\n1\n50\n50\n50\n100\n50\n50\n100\n1\n50\n50\n50\n50\n1\n50\n50\n50\n50\n1\n50\n50\n100\n1\n50\n100\n", "output": "NO\n"}, {"input": "100\n45\n45\n45\n45\n45\n45\n44\n44\n44\n43\n45\n44\n44\n45\n44\n44\n45\n44\n43\n44\n43\n43\n43\n45\n43\n45\n44\n45\n43\n44\n45\n45\n45\n45\n45\n45\n45\n45\n43\n45\n43\n43\n45\n44\n45\n45\n45\n44\n45\n45\n45\n45\n45\n45\n44\n43\n45\n45\n43\n44\n45\n45\n45\n45\n44\n45\n45\n45\n43\n43\n44\n44\n43\n45\n43\n45\n45\n45\n44\n44\n43\n43\n44\n44\n44\n43\n45\n43\n44\n43\n45\n43\n43\n45\n45\n44\n45\n43\n43\n45\n", "output": "NO\n"}, {"input": "100\n12\n12\n97\n15\n97\n12\n15\n97\n12\n97\n12\n12\n97\n12\n15\n12\n12\n15\n12\n12\n97\n12\n12\n15\n15\n12\n97\n15\n12\n97\n15\n12\n12\n15\n15\n15\n97\n15\n97\n12\n12\n12\n12\n12\n97\n12\n97\n12\n15\n15\n12\n15\n12\n15\n12\n12\n12\n12\n12\n12\n12\n12\n97\n97\n12\n12\n97\n12\n97\n97\n15\n97\n12\n97\n97\n12\n12\n12\n97\n97\n15\n12\n12\n15\n12\n15\n97\n97\n12\n15\n12\n12\n97\n12\n15\n15\n15\n15\n12\n12\n", "output": "NO\n"}, {"input": "12\n2\n3\n1\n3\n3\n1\n2\n1\n2\n1\n3\n2\n", "output": "NO\n"}, {"input": "48\n99\n98\n100\n100\n99\n100\n99\n100\n100\n98\n99\n98\n98\n99\n98\n99\n98\n100\n100\n98\n100\n98\n99\n100\n98\n99\n98\n99\n99\n100\n98\n99\n99\n98\n100\n99\n98\n99\n98\n100\n100\n100\n99\n98\n99\n98\n100\n100\n", "output": "NO\n"}, {"input": "96\n30\n10\n20\n20\n30\n30\n20\n10\n20\n30\n30\n30\n30\n10\n10\n30\n20\n30\n10\n10\n10\n30\n10\n30\n10\n10\n20\n30\n30\n30\n30\n10\n20\n20\n30\n10\n30\n20\n30\n20\n20\n10\n10\n30\n30\n10\n10\n10\n30\n10\n10\n10\n10\n30\n20\n20\n20\n30\n10\n10\n20\n20\n30\n20\n20\n30\n10\n30\n20\n20\n20\n10\n30\n20\n30\n20\n20\n20\n30\n20\n20\n20\n30\n10\n20\n30\n20\n30\n20\n10\n10\n10\n10\n10\n20\n10\n", "output": "NO\n"}, {"input": "96\n97\n78\n78\n78\n97\n78\n34\n78\n78\n97\n97\n78\n34\n34\n34\n34\n34\n34\n97\n97\n34\n34\n97\n78\n97\n78\n34\n34\n97\n78\n97\n34\n34\n97\n97\n78\n97\n97\n78\n97\n78\n78\n97\n97\n97\n97\n34\n34\n34\n78\n97\n78\n34\n78\n97\n34\n78\n34\n78\n34\n97\n78\n78\n78\n78\n34\n78\n78\n78\n34\n97\n34\n34\n78\n34\n34\n34\n97\n34\n34\n97\n34\n34\n97\n97\n78\n34\n78\n78\n97\n97\n97\n78\n97\n78\n97\n", "output": "NO\n"}, {"input": "4\n1\n3\n3\n3\n", "output": "NO\n"}, {"input": "6\n1\n1\n1\n1\n2\n2\n", "output": "NO\n"}, {"input": "4\n1\n1\n1\n2\n", "output": "NO\n"}, {"input": "4\n1\n2\n2\n2\n", "output": "NO\n"}, {"input": "4\n1\n2\n3\n4\n", "output": "NO\n"}, {"input": "8\n1\n1\n2\n2\n3\n3\n4\n4\n", "output": "NO\n"}, {"input": "4\n1\n3\n2\n4\n", "output": "NO\n"}, {"input": "4\n10\n10\n10\n20\n", "output": "NO\n"}, {"input": "4\n11\n12\n13\n13\n", "output": "NO\n"}, {"input": "4\n1\n1\n1\n3\n", "output": "NO\n"}, {"input": "6\n1\n1\n2\n2\n2\n2\n", "output": "NO\n"}, {"input": "10\n1\n1\n2\n2\n2\n3\n3\n4\n4\n4\n", "output": "NO\n"}] |
|
188 | Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains a_{i} soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has n rows, each of them has 8 seats. We call two seats neighbor, if they are in the same row and in seats {1, 2}, {3, 4}, {4, 5}, {5, 6} or {7, 8}.
[Image] A row in the airplane
Daenerys Targaryen wants to place her army in the plane so that there are no two soldiers from different groups sitting on neighboring seats.
Your task is to determine if there is a possible arranging of her army in the airplane such that the condition above is satisfied.
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 10000, 1 ≤ k ≤ 100) — the number of rows and the number of groups of soldiers, respectively.
The second line contains k integers a_1, a_2, a_3, ..., a_{k} (1 ≤ a_{i} ≤ 10000), where a_{i} denotes the number of soldiers in the i-th group.
It is guaranteed that a_1 + a_2 + ... + a_{k} ≤ 8·n.
-----Output-----
If we can place the soldiers in the airplane print "YES" (without quotes). Otherwise print "NO" (without quotes).
You can choose the case (lower or upper) for each letter arbitrary.
-----Examples-----
Input
2 2
5 8
Output
YES
Input
1 2
7 1
Output
NO
Input
1 2
4 4
Output
YES
Input
1 4
2 2 1 2
Output
YES
-----Note-----
In the first sample, Daenerys can place the soldiers like in the figure below:
[Image]
In the second sample, there is no way to place the soldiers in the plane since the second group soldier will always have a seat neighboring to someone from the first group.
In the third example Daenerys can place the first group on seats (1, 2, 7, 8), and the second group an all the remaining seats.
In the fourth example she can place the first two groups on seats (1, 2) and (7, 8), the third group on seats (3), and the fourth group on seats (5, 6). | interview | [{"code": "import sys\n\ndef r():\n return list(map(int, input().split()))\n\nn, k = list(map(int, input().split()))\na = r()\n\ncnt4 = n\ncnt2 = 2*n\ncnt1 = 0\nfor i in range(k):\n x = min((a[i]+1)//4, cnt4)\n cnt4 -= x\n a[i] = max(0, a[i]-4*x)\n\ncnt2 += cnt4\ncnt1 += cnt4\nfor i in range(k):\n x = min(a[i]//2, cnt2)\n cnt2 -= x\n a[i] = max(0, a[i]-2*x)\n\ncnt1 += cnt2\nfor i in range(k):\n cnt1 -= a[i]\n\nif (cnt1 < 0):\n print('NO')\nelse:\n print('YES')\n\n\n \n\n", "passed": true, "time": 0.16, "memory": 14532.0, "status": "done"}, {"code": "# encoding:utf-8\n\ndef main():\n\tn, k = list(map(int, input().split()))\n\tnums = list(map(int, input().split()))\n\t\n\tseat_two = n * 2\n\tseat_four = n\n\tseat_one = 0\n\tn_four = sum([x // 4 for x in nums])\n\tnums = [x % 4 for x in nums]\n\tn_two = sum([x // 2 for x in nums])\n\tn_one = sum([x % 2 for x in nums]) \n\n\t#print(n_one, n_two, n_four)\n\t#print(seat_one, seat_two, seat_four)\n\n\tif seat_four >= n_four:\n\t\t# there is rest of 4 seat\n\t\tseat_four -= n_four\n\t\tn_four = 0\n\n\t\t# break seat seat_one and seat_two\n\t\tseat_two += seat_four\n\t\tseat_one += seat_four\n\t\tseat_four = 0\n\telse:\n\t\t# there is rest of 4 people\n\t\tn_four -= seat_four\n\t\tseat_four = 0\n\n\t\t# break 4 people to 2, 2\n\t\tn_two += n_four * 2\n\t\tn_four = 0\n\n\t#print(n_one, n_two, n_four)\n\t#print(seat_one, seat_two, seat_four)\n\n\n\tif seat_two >= n_two:\n\t\tseat_two -= n_two\n\t\tn_two = 0\n\t\tif seat_two + seat_one >= n_one:\n\t\t\tprint(\"YES\")\n\t\telse:\n\t\t\tprint(\"NO\")\n\telse:\n\t\tn_two -= seat_two\n\t\tseat_two = 0\n\t\tn_one += n_two * 2\n\t\tif seat_one >= n_one:\n\t\t\tprint(\"YES\")\n\t\telse:\n\t\t\tprint(\"NO\")\n\ndef __starting_point():\n\tmain()\n1\n__starting_point()", "passed": true, "time": 0.2, "memory": 14432.0, "status": "done"}, {"code": "n, k = list(map(int, input().strip().split()))\ngroups = list(map(int, input().strip().split()))\n\n\ndef fetch(delim, num_places):\n for i, g in enumerate(groups):\n num_g = min(g//delim, num_places)\n g -= num_g*delim\n num_places -= num_g\n groups[i] = g\n\n if num_places == 0:\n break\n\n return num_places\n\nnum_4 = fetch(4, n)\nnum_2 = fetch(2, 2*n) + num_4\nnum_2 += fetch(2, num_4)\nif sum(groups) <= num_2:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.2, "memory": 14320.0, "status": "done"}, {"code": "n,k = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nmiddles = n\nsides = n*2\nsingles = 0\n\nfor i,a in enumerate(A):\n s = a//4\n s = min(s, middles)\n middles -= s\n A[i] -= 4*s\n\nfor i,a in enumerate(A):\n s = a//2\n s = min(s, sides)\n sides -= s\n A[i] -= 2*s\n\nfor i,a in enumerate(A):\n s = a//2\n s = min(s, middles)\n middles -= s\n singles += s\n A[i] -= 2*s\n\nsingles += sides\nsingles += middles*2\n\nfor i,a in enumerate(A):\n s = a\n s = min(s, singles)\n singles -= s\n A[i] -= s\n\nrem = sum(A)\n\nif rem == 0:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n", "passed": true, "time": 1.35, "memory": 14448.0, "status": "done"}, {"code": "def func(a):\n\tif(a<0):\n\t\treturn 0\n\telse:\n\t\treturn a\n\nn,k=list(map(int,input().split()))\nl=list(map(int,input().split()))\ntwo = 2*n\nfour = n\nbaki=[]\nfor val in l:\n\tif(val>=4):\n\t\tans=min(four,val//4)\n\t\tval=val-ans*4\n\t\tfour-=ans\n\tans=min(two,(val)//2)\n\tval=val-ans*2\n\ttwo-=ans\n\tbaki.append(func(val))\nstore=sum(baki)\nif(store==0):\n\tprint(\"YES\")\nelif(store>0 and four==0 and two==0):\n\tprint(\"NO\")\nelse:\n\tbaki.sort(reverse=True)\n\tcap1=four\n\tcap2=four\n\tfor val in baki:\n\t\tif(val==3):\n\t\t\tif(cap1>0 and cap2>0):\n\t\t\t\tcap1-=1\n\t\t\t\tcap2-=1\n\t\t\telse:\n\t\t\t\ttwo-=2\n\t\telif(val==2):\n\t\t\tif(two>0):\n\t\t\t\ttwo-=1\n\t\t\telse:\n\t\t\t\tif(cap1>0):\n\t\t\t\t\tcap1-=1\n\t\t\t\telse:\n\t\t\t\t\tcap2-=2\n\t\telif(val==1):\n\t\t\tif(cap2>0):\n\t\t\t\tcap2-=1\n\t\t\telif(cap1>0):\n\t\t\t\tcap1-=1\n\t\t\telse:\n\t\t\t\ttwo-=1\n\tif(cap2<0 or cap1<0 or two<0):\n\t\tprint(\"NO\")\n\telse:\n\t\tprint(\"YES\")\n\t\t\n\n\n\n\t\t\n\n\n", "passed": true, "time": 0.73, "memory": 14448.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nz = list(map(int, input().split()))\nh = z[:]\ndouble = 2 * n\nfour = n\njj = []\nfor i in range(len(h)):\n while four > 0 and h[i] >= 4:\n h[i] -= 4\n four -= 1\n if (h[i] != 0):\n jj.append(h[i])\nss = []\nfor i in range(len(jj)):\n while four > 0 and jj[i] >= 3:\n jj[i] -= 3\n four -= 1\n if jj[i] != 0:\n ss.append(jj[i])\n\ntt = []\nfor i in range(len(ss)):\n while double > 0 and ss[i] >= 2:\n ss[i] -= 2\n double -= 1\n if ss[i]:\n tt.append(ss[i])\n\nplaces = double + four * 2\ngg = []\nfor i in range(len(tt)):\n while four > 0 and tt[i] >= 2:\n tt[i] -= 2\n places -= 1\n four -= 1\n if tt[i]:\n gg.append(tt[i])\nif (sum(gg) <= places):\n print(\"YES\")\nelse:\n print(\"NO\")\n\n \n\n\n \n", "passed": true, "time": 0.2, "memory": 14544.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\ns2 = 2 * n\ns4 = n\ns1 = 0\n\ntmp = sum([ai // 4 for ai in a])\ns4 -= min(tmp, n)\ns2 -= 2 * max(tmp - n, 0)\n\nfor ai in a:\n if ai % 4 == 2:\n if 0 < s2:\n s2 -= 1\n elif 0 < s4:\n s4 -= 1\n s1 += 1\n else:\n s1 -= 2\n\nfor ai in a:\n if ai % 4 == 1:\n if 0 < s1:\n s1 -= 1\n elif 0 < s2:\n s2 -= 1\n else:\n s4 -= 1\n s2 += 1\n\nfor ai in a:\n if ai % 4 == 3:\n if 0 < s4:\n s4 -= 1\n elif 1 < s2:\n s2 -= 2\n elif 1 == s2:\n s2 -= 1\n s1 -= 1\n else:\n s1 -= 3\n\nif 0 <= s1 and 0 <= s2 and 0 <= s4:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.19, "memory": 14452.0, "status": "done"}, {"code": "import sys\n\n\ndef main():\n n, k = list(map(int, sys.stdin.readline().split()))\n x = list(map(int, sys.stdin.readline().split()))\n ch = n\n dv = 2 * n\n\n for i in range(k):\n if x[i] % 4 == 2 and dv > 0:\n x[i] -= 2\n dv -= 1\n for i in range(k):\n while x[i] > 3 and ch > 0:\n x[i] -= 4\n ch -= 1\n\n for i in range(k):\n if x[i] % 4 == 1 and dv > 0:\n x[i] -= 1\n dv -= 1\n\n for i in range(k):\n while x[i] >= 3 and ch > 0:\n x[i] -= 4\n ch -= 1\n p1 = 0\n p2 = 0\n for i in range(k):\n if x[i] == 2:\n if p2 > 0:\n p2 -= 1\n x[i] = 0\n elif ch > 0:\n x[i] = 0\n p1 += 1\n ch -= 1\n elif p1 > 1:\n p1 -= 2\n x[i] = 0\n elif x[i] == 1:\n if p1 > 0:\n p1 -= 1\n x[i] = 0\n elif ch > 0:\n p2 += 1\n x[i] = 0\n ch -= 1\n elif p2 > 0:\n p2 -= 1\n x[i] = 0\n\n while x[i] > 0 and dv > 0:\n x[i] -= 2\n dv -= 1\n\n ok = True\n for i in range(k):\n if x[i] > 0:\n ok = False\n break\n\n if ok:\n print(\"YES\")\n else:\n print(\"NO\")\n\n\nmain()\n", "passed": true, "time": 1.81, "memory": 14464.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nseat = {4:n, 2:n*2, 1:0}\nextra1 = 0\na = sorted(map(int, input().split()), reverse=True)\n\ndef sit(n, m):\n num = min(seat[n], m)\n seat[n] -= num\n return m - num\n\nfor m in a:\n p4 = m // 4\n p3, p2, p1 = 0, 0, 0\n if m%4 == 3:\n p3 = 1\n else:\n p2 = int(m % 4 > 1)\n p1 = int(m % 2)\n\n extra4 = sit(4, p4)\n p2 += extra4*2\n if sit(4, p3) > 0:\n p2 += 1\n p1 += 1\n\n extra2 = sit(2, p2)\n x = sit(4, extra2)\n seat[1] += extra2 - x\n p1 += x * 2\n\n extra1 += p1\n\nextra1 = sit(1, extra1)\nx = sit(4, extra1)\nseat[2] += extra1 - x\ny = sit(2, x)\n\nif y > 0:\n print(\"NO\")\nelse:\n print(\"YES\")", "passed": true, "time": 0.21, "memory": 14452.0, "status": "done"}, {"code": "import sys\nn, k = [ int(x) for x in input().split() ]\narr = list( map( int, input().split()) )\n\ncnt_2 = 2 * n\ncnt_4 = n\ncnt_1 = 0\n\ni = 0\nwhile(cnt_4 > 0 and i < k):\n tmp = int(arr[i] / 4)\n if(tmp > 0 and cnt_4 > 0):\n arr[i] = arr[i] - 4 * min(tmp, cnt_4)\n cnt_4 = cnt_4 - min(tmp, cnt_4)\n i = i + 1\n\nif(cnt_4 > 0):\n cnt_2 = cnt_2 + cnt_4\n cnt_1 = cnt_1 + cnt_4\n cnt_4 = 0\n\ni = 0\nwhile(cnt_2 > 0 and i < k):\n tmp = int(arr[i] / 2)\n if(tmp > 0 and cnt_2 > 0):\n arr[i] = arr[i] - 2 * min(tmp, cnt_2)\n cnt_2 = cnt_2 - min(tmp, cnt_2)\n i = i + 1\n\nif(cnt_2 > 0):\n cnt_1 = cnt_1 + cnt_2\n cnt_2 = 0\n\ni = 0\nwhile(i < k):\n tmp = arr[i]\n if(tmp > cnt_1):\n print(\"NO\")\n return\n elif(tmp > 0 and tmp <= cnt_1):\n cnt_1 = cnt_1 - tmp\n arr[i] = arr[i] - tmp\n i = i + 1\n\nprint(\"YES\")\n", "passed": true, "time": 0.2, "memory": 14424.0, "status": "done"}, {"code": "N,K = list(map(int,input().split()))\na = [int(i) for i in input().split()]\nN = {4:N,3:0,2:N*2,1:0}\n\nworks = True\na.sort(reverse=True)\n\nfor i in range(K):\n r4 = min(N[4],a[i]//4)\n a[i]-=4*r4\n N[4]-=r4\n\na.sort(reverse = True)\n#print(a,N)\nfor i in range(K):\n if a[i]==0:\n continue\n r2 = min(N[2],a[i]//2)\n a[i]-=2*r2\n N[2]-=r2\n\na.sort(reverse = True)\n#print(a,N)\nfor i in range(K):\n #print(\"a\",a,N,a[i])\n if a[i]==0:\n continue\n if a[i]>=4:\n works = False\n break\n #print(\"x\")\n if a[i]==3:\n #print(\" ai is 3\")\n x = min(N[4],1)\n a[i]-=3*x\n N[4]-=x\n \n elif a[i]==2:\n #print( \"ai is 2\")\n x = min(N[2],a[i]//2)\n a[i]-=2*x\n N[2]-=x\n \n x = min(N[4],a[i]//2)\n a[i]-=2*x\n N[4]-=x\n N[1]+=x\n\n x = min(N[1],a[i])\n a[i]-=x\n N[1]-=x\n\n elif a[i]==1:\n #print(\" ai is 1\")\n N[1]+=N[2]\n N[1]+=2*N[4]\n N[4] = 0\n N[2]=0\n \n x = min(N[1],a[i])\n a[i]-=x\n N[1]-=x\n \n if a[i]!=0:\n #print(a[i])\n works = False\n break\n\n\nif works:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14660.0, "status": "done"}, {"code": "n, k = map(int, input().split())\n\na = list(map(int, input().split()))\n\nc = [0, 0, 0, 0]\n\nfor t in a:\n c[0] += t//4\n if t%4: c[t%4] += 1\n\nc[0] += c[3]\nc[3] = 0\n\nif c[0] > n:\n c[2] += 2*(c[0]-n)\n c[0] = n\n\nt = min(n-c[0], c[1], c[2])\nc[0] += t\nc[1] -= t\nc[2] -= t\n\nt = min(n-c[0], (c[1]+1)//2)\nc[0] += t\nc[1] -= min(c[1], t*2)\n\nt = min(n-c[0], c[2])\nc[0] += t\nc[2] -= min(c[2], t+t//2)\n\nc[2] += c[1]\nc[1] = 0\n\nprint(\"YES\" if c[2] <= 2*n else \"NO\")", "passed": true, "time": 1.93, "memory": 14620.0, "status": "done"}, {"code": "import heapq\nrows, groups = list(map(int,input().split()))\ncounts = list([(-1)*int(x) for x in input().split()])\n\nfours = rows\ntwos = 2*rows\nones = 0\n\nf = True\nheapq.heapify(counts)\nwhile fours+twos+ones>0 and len(counts)>0:\n i = heapq.heappop(counts)\n i = i * (-1)\n if fours >= 1:\n if i < 4:\n twos+=fours\n ones+=fours\n fours = 0\n heapq.heappush(counts, i*(-1))\n else:\n d, m = divmod(i, 4)\n if d > fours:\n i -= fours*4\n fours=0\n if i>0:\n heapq.heappush(counts, i*(-1))\n else:\n i -= d*4\n fours -= d\n if i>0:\n heapq.heappush(counts, i*(-1))\n elif twos >= 1:\n if i < 2:\n ones += twos\n twos = 0\n heapq.heappush(counts, i*(-1))\n else:\n d, m = divmod(i, 2)\n if d > twos:\n i -= twos*2\n twos = 0\n if i > 0:\n heapq.heappush(counts, i*(-1))\n else:\n i -= d*2\n twos -= d\n if i > 0:\n heapq.heappush(counts, i*(-1))\n elif ones >= 1:\n if i > ones:\n f=False\n break\n else:\n ones -= i\nif len(counts) > 0 or f == False:\n print(\"NO\")\nelse:\n print(\"YES\")\n\n\n\n\n\n\n", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}, {"code": "debug = 0\nread = lambda: map(int, input().split())\nk, n = read()\na = list(read())\ncnt4 = k\ncnt2 = 2 * k\nfor i in range(n):\n cnt = min(cnt4, a[i] // 4)\n a[i] -= cnt * 4\n cnt4 -= cnt\nif debug: print(*a)\nfor i in range(n):\n cnt = min(cnt2, a[i] // 2)\n a[i] -= cnt * 2\n cnt2 -= cnt\nif debug: print(' '.join(map(str, a)), ' ', cnt2, cnt4)\nc = [0] * 20\nfor i in a:\n c[min(i, 19)] += 1\nif debug:\n print(cnt2, cnt4, c)\nd = min(cnt4, c[3])\nc[3] -= d\ncnt4 -= d\nd = min(cnt4, c[1], c[2])\nc[1] -= d\nc[2] -= d\ncnt4 -= d\nd = min(cnt2, c[2])\nc[2] -= d\ncnt2 -= d\nd = min(cnt2, c[1])\nc[1] -= d\ncnt2 -= d\nd = min(cnt4, (c[2] + 2) // 3 + int(c[2] > 1))\nc[2] -= d + d // 2\ncnt4 -= d\nif debug:\n print('cnt4 = ', cnt4)\n print('c[1] = ', c[1])\nd = min(cnt4, c[2])\nc[2] -= d\ncnt4 -= d\nd = min(cnt4, (c[1] + 1) // 2)\nc[1] -= d * 2\ncnt4 -= d\nd = min(cnt4, c[1])\nc[1] -= d\ncnt4 -= d\nprint('YES' if sum(c[1:]) == 0 else 'NO')", "passed": true, "time": 0.16, "memory": 14496.0, "status": "done"}, {"code": "read = lambda: map(int, input().split())\nk, n = read()\na = list(read())\ncnt4 = k\ncnt2 = 2 * k\nfor i in range(n):\n cnt = min(cnt4, a[i] // 4)\n a[i] -= cnt * 4\n cnt4 -= cnt\nfor i in range(n):\n cnt = min(cnt2, a[i] // 2)\n a[i] -= cnt * 2\n cnt2 -= cnt\nc = [0] * 20\nfor i in a:\n c[min(i, 19)] += 1\nd = min(cnt4, c[3])\nc[3] -= d\ncnt4 -= d\nd = min(cnt4, c[1], c[2])\nc[1] -= d\nc[2] -= d\ncnt4 -= d\nd = min(cnt2, c[2])\nc[2] -= d\ncnt2 -= d\nd = min(cnt2, c[1])\nc[1] -= d\ncnt2 -= d\nd = min(cnt4, (c[2] + 2) // 3 + int(c[2] > 1))\nc[2] -= d + d // 2\ncnt4 -= d\nd = min(cnt4, c[2])\nc[2] -= d\ncnt4 -= d\nd = min(cnt4, (c[1] + 1) // 2)\nc[1] -= d * 2\ncnt4 -= d\nd = min(cnt4, c[1])\nc[1] -= d\ncnt4 -= d\nprint('YES' if sum(c[1:]) == 0 else 'NO')", "passed": true, "time": 0.15, "memory": 14572.0, "status": "done"}, {"code": "n, k = map(int, input().split())\n\nl = [0, 0, 2 * n, 0, n]\n\ninp = sorted(map(int, input().split()), reverse = True)\n\nfor i in range(k):\n\tif inp[i] > 1 and inp[i] & 1:\n\t\tinp[i] -= 1\n\t\tinp.append(1)\n\nfor a in inp:\n\tif a == 1:\n\t\tif l[1]:\n\t\t\tl[1] -= 1\n\t\t\ta = 0\n\t\telif l[2]:\n\t\t\tl[2] -= 1\n\t\t\ta = 0\n\t\telif l[4]:\n\t\t\tl[4] -= 1\n\t\t\tl[2] += 1\n\t\t\ta = 0\n\telse:\t\n\t\twhile a > 2 and l[4]:\n\t\t\ta -= 4\n\t\t\tl[4] -= 1\n\t\twhile a and l[2]:\n\t\t\ta -= 2\n\t\t\tl[2] -= 1\n\t\twhile a and l[4]:\n\t\t\ta -= 2\n\t\t\tl[4] -= 1\n\t\t\tl[1] += 1\n\t\twhile a and l[1]:\n\t\t\ta -= 1\n\t\t\tl[1] -= 1\n\n\tif a:\n\t\tprint('NO')\n\t\treturn\n\nprint('YES')", "passed": true, "time": 0.35, "memory": 14380.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\na1 = 0\na2 = 2 * n\na4 = n\nflag = True\ns1 = 0\ns2 = 0\nfor x in a:\n while x >= 3:\n if a4:\n a4 -= 1\n x -= 4\n elif a2 > 1:\n a2 -= 1\n x -= 2\n else:\n flag = False\n break\n if not flag:\n break\n if x == 2:\n s2 += 1\n elif x == 1:\n s1 += 1\n#print(s1, s2, a1, a2, a4)\nwhile s2:\n if a2:\n a2 -= 1\n s2 -= 1\n elif a4:\n a4 -= 1\n a1 += 1\n s2 -= 1\n else:\n s1 += 2\n s2 -= 1\nprint(\"YES\" if flag and a1 + a2 + a4 * 2 >= s1 else \"NO\")\n\n", "passed": true, "time": 0.17, "memory": 14556.0, "status": "done"}, {"code": "n,k = list(map(int, input().split()))\n\na = list(map(int,input().split()))\nall_sum = sum(a)\nr4,r2 = n,n*2\nfor v in range(len(a)):\n\tmid = a[v] // 4\n\ta[v] = a[v] % 4\n\tif mid <= r4:\n\t\tr4 -= mid\n\telse:\n\t\ta[v] += 4 * (mid - r4)\n\t\tr4 = 0\n\tif r4 == 0:\n\t\tbreak\nmid = 0\nr22 = 0\nfor v in a:\n\tif v % 2 == 1:\n\t\tmid += 1\n\tr22 += v // 2\n#print(r4,r22,mid,r2)\nif r4 > 0:\n\tmid -=r4\n\tr22 -= r4\n\tif mid < 0:\n\t\tr22 -= (mid // -2)\n\t\tmid = 0\n\nif r22 + mid > r2:\n\tprint('NO')\nelse:\n\tprint('YES')\n\n\n\n\n\n", "passed": true, "time": 0.15, "memory": 14648.0, "status": "done"}, {"code": "n,k = list(map(int, input().split()))\n\na = list(map(int,input().split()))\nall_sum = sum(a)\nr4,r2 = n,n*2\nfor v in range(len(a)):\n\tmid = a[v] // 4\n\ta[v] = a[v] % 4\n\tif mid <= r4:\n\t\tr4 -= mid\n\telse:\n\t\ta[v] += 4 * (mid - r4)\n\t\tr4 = 0\n\tif r4 == 0:\n\t\tbreak\nmid = 0\nr22 = 0\nfor v in a:\n\tif v % 2 == 1:\n\t\tmid += 1\n\tr22 += v // 2\n#print(r4,r22,mid,r2)\nif r4 > 0:\n\tmid -=r4\n\tr22 -= r4\n\tif mid < 0:\n\t\tr22 -= (mid // -2)\n\t\tmid = 0\n\nif r22 + mid > r2:\n\tprint('NO')\nelse:\n\tprint('YES')\n\n\n\n\n\n", "passed": true, "time": 0.14, "memory": 14512.0, "status": "done"}, {"code": "import sys\n\nn, k = map(int, input().split())\na = list(map(int, input().split()))\n\nmid = n\nside = n*2\n\ndef removeZeroes(a):\n return [x for x in a if x > 0]\n\n#FOR 4 \nfor i in range(len(a)):\n if a[i] >= 4:\n while a[i] >= 4 and (mid > 0 or side > 1):\n a[i] -= 4\n if mid:\n mid -= 1\n else:\n side -= 2\n\n#FOR 3\nfor i in range(len(a)):\n if not(mid > 0 or side > 1): \n break\n if a[i] == 3:\n if mid > 0:\n mid -= 1\n else:\n side -= 2\n a[i] = 0\n \n#REMOVE GROUPS WITH 0 REMAINED\na = removeZeroes(a)\n\nif a.count(2) + a.count(1) != len(a):\n print(\"NO\")\n return\n\nfor i in range(len(a)):\n if a[i] == 2 and side > 0:\n side -= 1\n a[i] = 0\n\nfor i in range(len(a)):\n if a[i] == 1 and side > 0:\n side -= 1\n a[i] = 0\n\na = removeZeroes(a)\na.sort()\nwhile len(a) > 0 and a[0] == 1 and a[-1] == 2 and mid > 0:\n a = a[1:-1]\n mid -= 1\nif len(a) > 0 and a[0] == 1:\n if (a.count(1)+1) // 2 <= mid:\n print(\"YES\")\n return\n else:\n print(\"NO\")\n return\nelif len(a) > 0 and a[0] == 2:\n while len(a) > 2 and mid > 1:\n a = a[3:]\n mid -= 2\n if mid >= len(a):\n print(\"YES\")\n return\n\nif len(a) > 0:\n print(\"NO\")\nelse:\n print(\"YES\")", "passed": true, "time": 0.3, "memory": 14576.0, "status": "done"}, {"code": "n,k=list(map(int,input().split()))\na=list(map(int,input().split()))\ns2=n*2\ns4=n\ns1=0\nf=1\nrem1=0\nrem2=0\nfor i in range(len(a)):\n if(f):\n while(a[i]>=3):\n if(s4>0):\n a[i]-=4\n s4-=1\n elif(s2>0):\n a[i]-=2\n s2-=1\n else:\n f=0\n if(a[i]==1 and f):\n rem1+=1\n elif(a[i]==2 and f):\n rem2+=1\nwhile(rem2>0 and f):\n if(s2>0):\n rem2-=1\n s2-=1\n elif(s4>0):\n rem2-=1\n s4-=1\n s1+=1\n else:\n rem2-=1\n rem1+=2\nif(rem1>s1+s2+s4*2):\n f=0\nif(f):\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.2, "memory": 14400.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = sorted(list(map(int, input().split())))[::-1]\nm = n\nfor j in range(len(a)):\n waste = min(a[j] // 4, m)\n m -= waste\n a[j] -= waste * 4\n if m == 0:\n break\nm1, m2, m3, msukabljat = 0, 0, 0, []\nfor x in a:\n m1 += (x == 1)\n m2 += (x == 2)\n m3 += (x == 3)\n msukabljat += ([x] if x >= 4 else [])\nwaste = min(m1, m2, m)\nm, m1, m2 = m - waste, m1 - waste, m2 - waste\nwaste = min(m3 // 2, m // 2)\nm, m3 = m - waste * 2, m3 - waste * 2\nwaste = min(m2 // 3, m // 2)\nm, m2 = m - waste * 2, m2 - waste * 3\nwaste = min(m1, m2, m3, m // 2)\nm, m1, m2, m3 = m - waste * 2, m1 - waste, m2 - waste, m3 - waste\nwaste = min(m3, m)\nm, m3 = m - waste, m3 - waste\nwaste = min(m1 // 2, m)\nm, m1 = m - waste, m1 - 2 * waste\nwaste = min(m1, m)\nm, m1 = m - waste, m1 - waste\nwaste = min(m2, m)\nm, m2 = m - waste, m2 - waste\nif m1 + m2 + m3 * 2 + sum([x // 2 + x % 2 for x in msukabljat]) <= 2 * n:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n", "passed": true, "time": 0.15, "memory": 14588.0, "status": "done"}, {"code": "n, k = map(int, input().split())\n\nl = list(map(int, input().split()))\n\nl = sorted(l, reverse=True)\ns = 0\nfor _ in range(n):\n if l[0] <= 0:\n break\n if l[0] <= 2:\n l[0] -= min(l[0],2)\n s += 1\n l[0] -= min(l[0],4)\n l = sorted(l, reverse=True)\nfor _ in range(n):\n if l[0] <= 0:\n break\n l[0] -= min(l[0],2)\n l = sorted(l, reverse=True)\nfor _ in range(n):\n if l[0] <= 0:\n break\n l[0] -= min(l[0],2)\n l = sorted(l, reverse=True)\nfor _ in range(s):\n if l[0] <= 0:\n break\n l[0] -= min(l[0],1)\n l = sorted(l, reverse=True)\n\n\nif l[0] <= 0:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.92, "memory": 14600.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nleft4seat = n\nleft2seat = n * 2\nleft1seat = 0\nfor i in range (0, k) :\n\tleft4seat -= a[i] // 4\n\tif (left4seat < 0) :\n\t\tleft2seat += 2 * left4seat\n\t\tleft4seat = 0\n\nindex = 0\nwhile (index < k ) :\n\tleftSol = a[index] % 4\n\tif (leftSol == 3) : \n\t\tif (left4seat > 0) : left4seat -= 1\n\t\telse : \n\t\t\tif (left1seat > 0) :\n\t\t\t\tif (left2seat == 0 and left1seat >= 2) : left1seat -= 3\n\t\t\t\telse:\n\t\t\t\t\tleft2seat -= 1\n\t\t\t\t\tleft1seat -= 1\n\t\t\telse :\n\t\t\t\tleft2seat -= 2\n\telif (leftSol == 2) :\n\t\tif (left4seat > 0) : \n\t\t\tleft4seat -= 1\n\t\t\tleft1seat += 1\n\t\telse : \n\t\t\tif (left2seat == 0 and left1seat >= 2) : left1seat -= 2\n\t\t\telse : left2seat -= 1\n\telif (leftSol == 1) :\n\t\tif (left1seat > 0) : left1seat -= 1\n\t\telif (left4seat > 0) : \n\t\t\tleft4seat -= 1\n\t\t\tleft2seat += 1\n\t\telse : \n\t\t\tleft2seat -= 1\n\tif (left4seat < 0 or left2seat < 0) : break\n\tindex += 1\n\nif (index == k and left4seat >= 0 and left2seat >= 0) : print(\"YES\")\nelse : print(\"NO\")", "passed": true, "time": 0.15, "memory": 14580.0, "status": "done"}] | [{"input": "2 2\n5 8\n", "output": "YES\n"}, {"input": "1 2\n7 1\n", "output": "NO\n"}, {"input": "1 2\n4 4\n", "output": "YES\n"}, {"input": "1 4\n2 2 1 2\n", "output": "YES\n"}, {"input": "10000 100\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 800 782 3058 174 455 83 647 595 658 109 33 23 70 39 38 1 6 35 94 9 22 12 6 1 2 2 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 9938\n", "output": "YES\n"}, {"input": "100 15\n165 26 83 64 235 48 36 51 3 18 5 10 9 6 5\n", "output": "YES\n"}, {"input": "1 4\n2 2 2 2\n", "output": "NO\n"}, {"input": "5691 91\n6573 1666 2158 2591 4636 886 263 4217 389 29 1513 1172 617 2012 1855 798 1588 979 152 37 890 375 1091 839 385 382 1 255 117 289 119 224 182 69 19 71 115 13 4 22 35 2 60 12 6 12 19 9 3 2 2 6 5 1 7 7 3 1 5 1 7 1 4 1 1 3 2 1 2 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5631\n", "output": "NO\n"}, {"input": "2000 50\n203 89 1359 3105 898 1381 248 365 108 766 961 630 265 819 838 125 1751 289 177 81 131 564 102 95 49 74 92 101 19 17 156 5 5 4 20 9 25 16 16 2 8 5 4 2 1 3 4 1 3 2\n", "output": "NO\n"}, {"input": "10000 100\n800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800\n", "output": "YES\n"}, {"input": "10000 100\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 2050 1074 605 979 1724 1608 672 88 1243 129 718 544 3590 37 187 600 738 34 64 316 58 6 84 252 75 68 40 68 4 29 29 8 13 11 5 1 5 1 3 2 1 1 1 2 3 4 1 1 2 2 2 1 1 1 1 1 1 1 1 1 1 3\n", "output": "NO\n"}, {"input": "8459 91\n778 338 725 1297 115 540 1452 2708 193 1806 1496 1326 2648 176 199 93 342 3901 2393 2718 800 3434 657 4037 291 690 1957 3280 73 6011 2791 1987 440 455 444 155 261 234 829 1309 1164 616 34 627 107 213 52 110 323 81 98 8 7 73 20 12 56 3 40 12 8 7 69 1 14 3 6 2 6 8 3 5 4 4 3 1 1 4 2 1 1 1 8 2 2 2 1 1 1 2 8421\n", "output": "NO\n"}, {"input": "1 3\n2 3 2\n", "output": "YES\n"}, {"input": "10000 91\n2351 1402 1137 2629 4718 1138 1839 1339 2184 2387 165 370 918 1476 2717 879 1152 5367 3940 608 941 766 1256 656 2768 916 4176 489 1989 1633 2725 2329 2795 1970 667 340 1275 120 870 488 225 59 64 255 207 3 37 127 19 224 34 283 144 50 132 60 57 29 18 6 7 4 4 15 3 5 1 10 5 2 3 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 9948\n", "output": "YES\n"}, {"input": "10000 83\n64 612 2940 2274 1481 1713 860 1264 104 5616 2574 5292 4039 292 1416 854 3854 1140 4344 3904 1720 1968 442 884 2032 875 291 677 2780 3074 3043 2997 407 727 344 511 156 321 134 51 382 336 591 52 134 39 104 10 20 15 24 2 70 39 14 16 16 25 1 6 2 2 1 1 1 2 4 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 9968\n", "output": "YES\n"}, {"input": "4000 71\n940 1807 57 715 532 212 3842 2180 2283 744 1453 800 1945 380 2903 293 633 391 2866 256 102 46 228 1099 434 210 244 14 27 4 63 53 3 9 36 25 1 12 2 14 12 28 2 28 8 5 11 8 2 3 6 4 1 1 1 3 2 1 1 1 2 2 1 1 1 1 1 2 1 1 3966\n", "output": "YES\n"}, {"input": "3403 59\n1269 1612 453 795 1216 941 19 44 1796 324 2019 1397 651 382 841 2003 3013 638 1007 1001 351 95 394 149 125 13 116 183 20 78 208 19 152 10 151 177 16 23 17 22 8 1 3 2 6 1 5 3 13 1 8 4 3 4 4 4 2 2 3378\n", "output": "YES\n"}, {"input": "2393 33\n1381 2210 492 3394 912 2927 1189 269 66 102 104 969 395 385 369 354 251 28 203 334 20 10 156 29 61 13 30 4 1 32 2 2 2436\n", "output": "YES\n"}, {"input": "10000 100\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 800 782 3058 174 455 83 647 595 658 109 33 23 70 39 38 1 6 35 94 9 22 12 6 1 2 2 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 9939\n", "output": "NO\n"}, {"input": "10000 89\n1001 1531 2489 457 1415 617 2057 2658 3030 789 2500 3420 1550 376 720 78 506 293 1978 383 3195 2036 891 1741 1817 486 2650 360 2250 2531 3250 1612 2759 603 5321 1319 791 1507 265 174 877 1861 572 172 580 536 777 165 169 11 125 31 186 113 78 27 25 37 8 21 48 24 4 33 35 13 15 1 3 2 2 8 3 5 1 1 6 1 1 2 1 1 2 2 1 1 2 1 9953\n", "output": "NO\n"}, {"input": "4 16\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n", "output": "NO\n"}, {"input": "10000 71\n110 14 2362 260 423 881 1296 3904 1664 849 57 631 1922 917 4832 1339 3398 4578 59 2663 2223 698 4002 3013 747 699 1230 2750 239 1409 6291 2133 1172 5824 181 797 26 281 574 557 19 82 624 387 278 53 64 163 22 617 15 35 42 48 14 140 171 36 28 22 5 49 17 5 10 14 13 1 3 3 9979\n", "output": "NO\n"}, {"input": "3495 83\n2775 2523 1178 512 3171 1159 1382 2146 2192 1823 799 231 502 16 99 309 656 665 222 285 11 106 244 137 241 45 41 29 485 6 62 38 94 5 7 93 48 5 10 13 2 1 2 1 4 8 5 9 4 6 1 1 1 3 4 3 7 1 2 3 1 1 7 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 3443\n", "output": "NO\n"}, {"input": "1000 40\n1701 1203 67 464 1884 761 11 559 29 115 405 133 174 63 147 93 41 19 1 15 41 8 33 4 4 1 4 1 1 2 1 2 1 1 2 1 1 2 1 4\n", "output": "NO\n"}, {"input": "347 20\n55 390 555 426 140 360 29 115 23 113 58 30 33 1 23 3 35 5 7 363\n", "output": "NO\n"}, {"input": "10000 100\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 800 782 3058 174 455 83 647 595 658 109 33 23 70 39 38 1 6 35 94 9 22 12 6 1 2 2 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 9940\n", "output": "NO\n"}, {"input": "10000 93\n1388 119 711 23 4960 4002 2707 188 813 1831 334 543 338 3402 1808 3368 1428 971 985 220 1521 457 457 140 332 1503 1539 2095 1891 269 5223 226 1528 190 428 5061 410 1587 1149 1934 2275 1337 1828 275 181 85 499 29 585 808 751 401 635 461 181 164 274 36 401 255 38 60 76 16 6 35 79 46 1 39 11 2 8 2 4 14 3 1 1 1 1 1 2 1 3 1 1 1 1 2 1 1 9948\n", "output": "NO\n"}, {"input": "4981 51\n5364 2166 223 742 350 1309 15 229 4100 3988 227 1719 9 125 787 427 141 842 171 2519 32 2554 2253 721 775 88 720 9 397 513 100 291 111 32 238 42 152 108 5 58 96 53 7 19 11 2 5 5 6 2 4966\n", "output": "NO\n"}, {"input": "541 31\n607 204 308 298 398 213 1182 58 162 46 64 12 38 91 29 2 4 12 19 3 7 9 3 6 1 1 2 1 3 1 529\n", "output": "YES\n"}, {"input": "100 100\n6 129 61 6 87 104 45 28 3 35 2 14 1 37 2 4 24 4 3 1 6 4 2 1 1 3 1 2 2 9 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 22\n", "output": "NO\n"}, {"input": "1 4\n2 2 2 1\n", "output": "YES\n"}, {"input": "1 3\n2 2 2\n", "output": "YES\n"}, {"input": "2 5\n8 2 2 2 2\n", "output": "YES\n"}, {"input": "1 4\n1 1 2 2\n", "output": "YES\n"}, {"input": "1 3\n2 2 3\n", "output": "YES\n"}, {"input": "1 3\n4 2 2\n", "output": "YES\n"}, {"input": "1 4\n2 1 2 2\n", "output": "YES\n"}, {"input": "1 3\n3 2 2\n", "output": "YES\n"}, {"input": "2 8\n2 2 2 2 2 2 1 1\n", "output": "YES\n"}, {"input": "2 6\n2 2 2 2 2 2\n", "output": "YES\n"}, {"input": "1 4\n1 2 2 2\n", "output": "YES\n"}, {"input": "1 4\n1 1 1 1\n", "output": "YES\n"}, {"input": "2 7\n2 2 2 2 2 2 2\n", "output": "YES\n"}, {"input": "2 8\n1 1 1 1 1 1 1 1\n", "output": "YES\n"}, {"input": "3 7\n12 2 2 2 2 2 2\n", "output": "YES\n"}, {"input": "2 6\n4 1 3 1 1 3\n", "output": "NO\n"}, {"input": "1 3\n2 2 4\n", "output": "YES\n"}, {"input": "5 15\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n", "output": "YES\n"}, {"input": "2 8\n2 2 2 2 1 1 1 1\n", "output": "YES\n"}, {"input": "1 2\n6 2\n", "output": "YES\n"}, {"input": "4 13\n2 2 2 2 2 2 2 2 2 2 2 2 4\n", "output": "YES\n"}, {"input": "2 7\n1 1 1 4 2 2 2\n", "output": "YES\n"}, {"input": "3 8\n8 2 2 2 2 2 2 2\n", "output": "YES\n"}, {"input": "2 8\n1 1 1 1 2 2 2 2\n", "output": "YES\n"}, {"input": "2 8\n2 2 2 2 1 1 2 2\n", "output": "YES\n"}, {"input": "1 4\n2 2 1 1\n", "output": "YES\n"}, {"input": "3 9\n2 2 2 2 2 2 2 2 2\n", "output": "YES\n"}, {"input": "2 6\n2 2 2 2 2 5\n", "output": "YES\n"}, {"input": "1 1\n6\n", "output": "YES\n"}, {"input": "2 1\n16\n", "output": "YES\n"}, {"input": "1 1\n2\n", "output": "YES\n"}, {"input": "2 8\n2 2 2 2 2 2 2 1\n", "output": "NO\n"}, {"input": "4 16\n1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2\n", "output": "YES\n"}, {"input": "2 7\n4 1 1 1 1 2 2\n", "output": "YES\n"}, {"input": "2 6\n2 2 2 5 2 2\n", "output": "YES\n"}, {"input": "3 1\n22\n", "output": "YES\n"}, {"input": "2 8\n2 2 2 2 1 1 1 3\n", "output": "NO\n"}, {"input": "3 12\n2 1 2 2 2 1 2 2 2 1 2 2\n", "output": "YES\n"}, {"input": "1 4\n2 2 3 1\n", "output": "NO\n"}, {"input": "2 6\n5 2 2 2 2 2\n", "output": "YES\n"}, {"input": "20 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\n", "output": "NO\n"}, {"input": "1 3\n2 2 1\n", "output": "YES\n"}, {"input": "1 2\n3 3\n", "output": "YES\n"}, {"input": "2 6\n2 3 2 2 3 2\n", "output": "YES\n"}, {"input": "2 8\n2 2 1 1 2 2 2 2\n", "output": "YES\n"}, {"input": "2 6\n3 3 2 2 2 2\n", "output": "YES\n"}, {"input": "3 12\n2 2 2 2 2 2 2 2 2 1 1 1\n", "output": "YES\n"}, {"input": "3 10\n2 2 2 2 2 2 2 2 2 3\n", "output": "YES\n"}] |
|
189 | Salem gave you $n$ sticks with integer positive lengths $a_1, a_2, \ldots, a_n$.
For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length from $a$ to $b$ is $|a - b|$, where $|x|$ means the absolute value of $x$.
A stick length $a_i$ is called almost good for some integer $t$ if $|a_i - t| \le 1$.
Salem asks you to change the lengths of some sticks (possibly all or none), such that all sticks' lengths are almost good for some positive integer $t$ and the total cost of changing is minimum possible. The value of $t$ is not fixed in advance and you can choose it as any positive integer.
As an answer, print the value of $t$ and the minimum cost. If there are multiple optimal choices for $t$, print any of them.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 1000$) — the number of sticks.
The second line contains $n$ integers $a_i$ ($1 \le a_i \le 100$) — the lengths of the sticks.
-----Output-----
Print the value of $t$ and the minimum possible cost. If there are multiple optimal choices for $t$, print any of them.
-----Examples-----
Input
3
10 1 4
Output
3 7
Input
5
1 1 2 2 3
Output
2 0
-----Note-----
In the first example, we can change $1$ into $2$ and $10$ into $4$ with cost $|1 - 2| + |10 - 4| = 1 + 6 = 7$ and the resulting lengths $[2, 4, 4]$ are almost good for $t = 3$.
In the second example, the sticks lengths are already almost good for $t = 2$, so we don't have to do anything. | interview | [{"code": "n = int(input())\na = list(map(int,input().split()))\nt = 0\nmn = 1000000000\nfor i in range(1,100):\n cur = 0\n for j in range(n):\n cur += max(0,abs(i-a[j])-1)\n if cur < mn:\n mn = cur\n t = i\nprint(t,mn)\n", "passed": true, "time": 0.2, "memory": 14536.0, "status": "done"}, {"code": "n=int(input())\na=[*map(int,input().split())]\n\nmcost = 10**8\nans = 0\n\nfor i in range(1,101):\n tcost = 0\n for j in range(n):\n if a[j] > i:\n d = abs(a[j] - (i + 1))\n elif a[j] < i:\n d = abs(a[j] - (i - 1))\n else:\n d = 0\n tcost += d\n if tcost < mcost:\n mcost, ans = tcost , i\n\nprint(ans, mcost)", "passed": true, "time": 0.38, "memory": 14400.0, "status": "done"}, {"code": "n = int(input())\ns = list(map(int,input().split()))\na,b = -1,188888\nfor t in range(1,101):\n mi = 0\n for i in range(n):\n mi += min(abs(s[i]-t),abs(s[i]-t-1),abs(s[i]-t+1))\n if b>mi:\n a,b = t,mi\nprint(a,b)", "passed": true, "time": 0.36, "memory": 14504.0, "status": "done"}, {"code": "import math\n\nn = int(input())\nA = [int(i) for i in input().split()]\nA.sort()\n\nans = 10**18\nval = 0\nfor mid in range(1,100):\n cost = 0\n for i in range(n):\n cost += min(abs(A[i] - mid), abs(A[i]-mid+1), abs(A[i]-mid-1))\n if cost<ans:\n ans = cost\n val = mid\n\nprint(val, ans)\n", "passed": true, "time": 0.23, "memory": 14564.0, "status": "done"}, {"code": "def read_nums():\n return [int(x) for x in input().split()]\n\n\ndef compute_min_cost(t, nums):\n res = 0\n for num in nums:\n if abs(t - num) <= 1:\n continue\n res += abs(num - t) - 1\n return res\n\n\ndef main():\n _ = read_nums()\n\n costs = []\n nums = read_nums()\n for t in range(1, 101):\n min_cost = compute_min_cost(t, nums)\n costs.append((t, min_cost))\n\n t, cost = sorted(costs, key=lambda x: x[1])[0]\n print(t, cost)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14452.0, "status": "done"}, {"code": "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\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 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)\n\n\ndef main():\n n = I()\n a = LI()\n mm = inf\n mi = 0\n for i in range(1,100):\n t = 0\n for c in a:\n if c < i:\n t += i-1-c\n elif c > i:\n t += c - 1 - i\n if mm > t:\n mi = i\n mm = t\n\n return '{} {}'.format(mi, mm)\n\n\n\nprint(main())\n\n", "passed": true, "time": 1.05, "memory": 14388.0, "status": "done"}, {"code": "n=int(input())\nl=list(map(int,input().split()))\nmincost=100000\nans=0\nfor t in range(1,101):\n curcost=0\n for i in l:\n if i==t:\n continue\n else:\n curcost+=abs(t-i)-1\n if curcost<mincost:\n mincost=curcost\n ans=t\nprint(ans,mincost)", "passed": true, "time": 0.15, "memory": 14476.0, "status": "done"}, {"code": "n = int(input())\n\narr = list(map(int, input().split()))\narr.sort()\n\na = []\nfor t in range(1, 101):\n tot = 0\n for item in arr:\n if (abs(item - t) >= 1):\n tot += abs(item - t) - 1\n \n a.append((tot, t))\n\na.sort()\n\nprint(a[0][1], a[0][0])\n", "passed": true, "time": 0.2, "memory": 14296.0, "status": "done"}, {"code": "n = int(input())\narr = [int(x) for x in input().split()]\nt = []\nfor i in range(101):\n s = 0\n for j in arr:\n s += max(0, abs(j - i) - 1)\n t.append(s)\np = t[1:].index(min(t)) + 1\nprint(p, min(t))", "passed": true, "time": 0.2, "memory": 14436.0, "status": "done"}, {"code": "n=int(input())\nans=10**18\nval=-1\narr=list(map(int,input().split()))\nfor i in range(1,102):\n valx=0\n for j in arr:\n if(abs(j-i)>1):\n valx+=abs(j-i)-1\n if(valx<ans):\n ans=valx\n val=i\nprint(val,ans)", "passed": true, "time": 0.16, "memory": 14408.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nans = 10 ** 8\nansi = 0\nfor i in range(1, 101):\n\ttmp = sum(min(abs(i - t - 1), abs(i - t + 1), abs(i - t)) for t in a)\n\tif tmp < ans:\n\t\tans = tmp\n\t\tansi = i\nprint(ansi, ans)", "passed": true, "time": 0.18, "memory": 14432.0, "status": "done"}, {"code": "n = int(input())\nl = [*map(int, input().split())]\ndef f(a):\n return [sum(min(\n [abs(e - a), abs(e - (a - 1)), abs(e - (a + 1))]) for e in l), a]\nres = [float('inf'), float('inf')]\nfor a in range(1, 101):\n res = min(res, f(a))\nprint(res[1], res[0])", "passed": true, "time": 1.01, "memory": 14360.0, "status": "done"}, {"code": "N = int(input())\nnumber_list = list(map(int, input().split(' ')))\nret = [0, 9999999]\nfor n in range(1, 101):\n temp = 0\n for number in number_list:\n temp += max(0, abs(number - n) - 1)\n if ret[1] > temp:\n ret[0] = n\n ret[1] = temp\n\nprint(ret[0], ret[1])\n", "passed": true, "time": 0.19, "memory": 14356.0, "status": "done"}, {"code": "n = int(input())\na = [int(t) for t in input().split(' ')]\n\nmincost = 1000 * 100 + 1\nbest_t = None\nfor t in range(1, 101):\n cost = 0\n for x in a:\n cost += max(0, abs(x - t) - 1)\n if cost < mincost:\n mincost = cost\n best_t = t\n\nprint(best_t, mincost)", "passed": true, "time": 0.16, "memory": 14564.0, "status": "done"}, {"code": "n = int(input())\na = [int(v) for v in input().split()]\na.sort()\n\ndef cost1(v, t):\n if v < t - 1:\n return t - 1 - v\n elif v > t + 1:\n return v - (t + 1)\n else:\n return 0\n\nbest_t = None\nbest_cost = 9999999999999\n\nfor t in range(1, 101):\n cost = sum(cost1(v, t) for v in a)\n if cost < best_cost:\n best_cost = cost\n best_t = t\n\nprint(best_t, best_cost)\n", "passed": true, "time": 0.19, "memory": 14544.0, "status": "done"}, {"code": "n=int(input())\n\nl=list(map(int,input().split()))\n\nmaxx=10000000000\ncur=0\nfor i in range(1,101):\n\tnow=0\n\tfor j in range(n):\n\t\tif l[j]<i:\n\t\t\tnow+=i-l[j]-1\n\t\telif l[j]>i:\n\t\t\tnow+=l[j]-i-1\n\n\tif now<maxx:\n\t\tmaxx=now\n\t\tcur=i\n\nprint(cur, maxx)", "passed": true, "time": 0.15, "memory": 14324.0, "status": "done"}, {"code": "from sys import stdin\nn=int(stdin.readline().strip())\n#n,m=map(int,stdin.readline().strip().split())\ns=list(map(int,stdin.readline().strip().split()))\ns.sort()\nans=10**20\nt1=-1\nfor t in range(1,101):\n aux1=0\n for j in range(n):\n aux=102\n aux=min(aux,abs(1+t-s[j]))\n aux=min(aux,abs(t-1-s[j]))\n aux=min(aux,abs(t-s[j]))\n aux1+=aux\n if aux1<ans:\n ans=aux1\n t1=t\nprint(t1,ans)\n \n \n", "passed": true, "time": 0.18, "memory": 14572.0, "status": "done"}, {"code": "import math\nn = int(input())\nar = [*map(int, input().split(' '))]\nmint,mincost = int(1e9),int(1e9)\nfor i in range(1,105):\n\tcost = sum([min(abs(x-i), abs(x-i-1), abs(x-i+1)) for x in ar])\n\tif cost < mincost:\n\t\tmincost = cost\n\t\tmint = i\nprint(int(mint), int(mincost))", "passed": true, "time": 0.17, "memory": 14560.0, "status": "done"}, {"code": "n = int(input())\nl = list(map(int, input().split()))\nans = [0] * 101\nfor i in range(1, 101):\n for k in range(n):\n ans[i] += max(abs(l[k] - i) - 1, 0)\ncnt = [100000000, 100000000]\nfor i in range(1, 101):\n if cnt[1] > ans[i]:\n cnt[0] = i\n cnt[1] = ans[i]\nprint(cnt[0], cnt[1])", "passed": true, "time": 0.17, "memory": 14588.0, "status": "done"}, {"code": "n=int(input())\nar=list(map(int,input().split()))\ndef f(i):\n ans=0\n for e in ar:\n if(e==i):continue\n else:ans+=abs(e-i)-1\n return ans\na=float('inf')\nb=0\nfor x in range(1,1001):\n if(f(x)<a):\n a=f(x)\n b=x\nprint(b,a)", "passed": true, "time": 0.23, "memory": 14576.0, "status": "done"}, {"code": "n = int(input())\na = [int(i) for i in input().split()]\nmi = 10 ** 8\nx = -1\nfor i in range(1, 111):\n s = 0\n for j in range(n):\n if not i - 1 <= a[j] <= i + 1:\n if a[j] < i - 1:\n z = i - 1 - a[j]\n else:\n z = a[j] - i - 1\n s += z\n if s < mi:\n mi = s\n x = i\nprint(x, mi)\n", "passed": true, "time": 0.15, "memory": 14384.0, "status": "done"}] | [{"input": "3\n10 1 4\n", "output": "3 7\n"}, {"input": "5\n1 1 2 2 3\n", "output": "2 0\n"}, {"input": "1\n5\n", "output": "4 0\n"}, {"input": "2\n1 2\n", "output": "1 0\n"}, {"input": "3\n1 1 1\n", "output": "1 0\n"}, {"input": "5\n100 100 100 100 100\n", "output": "99 0\n"}, {"input": "113\n86 67 31 33 72 100 88 63 16 12 79 80 76 45 31 96 44 10 24 33 53 11 56 100 23 57 9 48 28 73 18 48 12 89 73 9 51 11 82 94 90 92 34 99 54 58 33 67 35 87 58 90 94 64 57 80 87 99 84 99 20 1 63 12 16 40 50 95 33 58 7 23 71 89 53 15 95 29 71 16 65 21 66 89 82 30 6 45 6 66 58 32 27 78 28 42 8 61 10 26 7 55 76 65 100 38 79 1 23 81 55 58 38\n", "output": "54 2787\n"}, {"input": "3\n96 93 70\n", "output": "92 24\n"}, {"input": "4\n100 54 93 96\n", "output": "94 45\n"}, {"input": "10\n75 94 58 66 98 95 87 74 65 78\n", "output": "76 104\n"}, {"input": "10\n89 65 98 94 52 71 67 88 70 79\n", "output": "72 113\n"}, {"input": "7\n91 54 87 88 79 62 62\n", "output": "78 82\n"}, {"input": "8\n94 56 100 70 91 79 74 60\n", "output": "75 96\n"}, {"input": "11\n1 1 1 1 1 1 1 1 1 2 3\n", "output": "2 0\n"}, {"input": "2\n1 3\n", "output": "2 0\n"}, {"input": "2\n1 10\n", "output": "2 7\n"}, {"input": "2\n1 100\n", "output": "2 97\n"}, {"input": "4\n1 3 9 9\n", "output": "4 10\n"}, {"input": "2\n2 4\n", "output": "3 0\n"}, {"input": "3\n1 1 10\n", "output": "2 7\n"}, {"input": "4\n2 2 2 4\n", "output": "3 0\n"}, {"input": "10\n1 1 1 1 1 1 1 1 1 3\n", "output": "2 0\n"}, {"input": "10\n1 1 1 1 1 1 1 1 2 3\n", "output": "2 0\n"}, {"input": "4\n1 2 4 5\n", "output": "3 2\n"}, {"input": "6\n1 1 2 10 11 11\n", "output": "3 22\n"}, {"input": "5\n1 1 1 100 100\n", "output": "2 194\n"}, {"input": "6\n1 4 10 18 20 25\n", "output": "11 42\n"}, {"input": "4\n1 2 4 7\n", "output": "3 4\n"}, {"input": "2\n3 5\n", "output": "4 0\n"}, {"input": "7\n1 1 10 10 10 10 10\n", "output": "9 14\n"}, {"input": "4\n1 2 70 71\n", "output": "3 134\n"}, {"input": "5\n1 2 3 3 3\n", "output": "2 0\n"}, {"input": "3\n2 2 5\n", "output": "3 1\n"}, {"input": "4\n1 1 100 100\n", "output": "2 194\n"}, {"input": "1\n1\n", "output": "1 0\n"}, {"input": "4\n1 1 5 5\n", "output": "2 4\n"}, {"input": "4\n1 2 19 20\n", "output": "3 32\n"}, {"input": "4\n1 2 29 30\n", "output": "3 52\n"}, {"input": "4\n1 1 9 9\n", "output": "2 12\n"}, {"input": "3\n5 7 7\n", "output": "6 0\n"}, {"input": "4\n1 3 3 3\n", "output": "2 0\n"}, {"input": "6\n1 10 20 30 31 31\n", "output": "21 55\n"}, {"input": "3\n3 3 5\n", "output": "4 0\n"}, {"input": "3\n1 1 5\n", "output": "2 2\n"}, {"input": "2\n1 6\n", "output": "2 3\n"}, {"input": "2\n1 20\n", "output": "2 17\n"}, {"input": "7\n4 4 4 7 7 7 7\n", "output": "6 3\n"}, {"input": "5\n1 100 100 100 100\n", "output": "99 97\n"}, {"input": "4\n1 1 1 5\n", "output": "2 2\n"}, {"input": "7\n1 1 1 1 100 100 100\n", "output": "2 291\n"}, {"input": "3\n1 4 4\n", "output": "3 1\n"}, {"input": "4\n1 2 10 11\n", "output": "3 14\n"}, {"input": "11\n2 11 13 14 18 20 20 21 22 23 25\n", "output": "19 43\n"}, {"input": "10\n8 8 8 8 8 8 8 8 9 10\n", "output": "9 0\n"}, {"input": "3\n1 100 100\n", "output": "99 97\n"}, {"input": "5\n4 4 4 4 6\n", "output": "5 0\n"}, {"input": "10\n5 5 5 5 5 5 5 5 5 9\n", "output": "6 2\n"}, {"input": "10\n1 1 1 1 1 1 100 100 100 100\n", "output": "2 388\n"}, {"input": "2\n7 14\n", "output": "8 5\n"}, {"input": "6\n1 1 1 1 97 98\n", "output": "2 189\n"}, {"input": "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 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n", "output": "2 4850\n"}, {"input": "10\n8 8 8 8 8 8 8 8 8 10\n", "output": "9 0\n"}, {"input": "4\n1 1 10 10\n", "output": "2 14\n"}, {"input": "10\n1 1 1 1 1 1 1 1 1 99\n", "output": "2 96\n"}, {"input": "4\n1 2 8 8\n", "output": "3 9\n"}, {"input": "3\n1 50 50\n", "output": "49 47\n"}, {"input": "4\n1 2 9 10\n", "output": "3 12\n"}, {"input": "3\n1 1 3\n", "output": "2 0\n"}, {"input": "10\n1 1 1 1 1 1 1 1 1 9\n", "output": "2 6\n"}, {"input": "4\n1 2 5 100\n", "output": "3 98\n"}, {"input": "5\n1 1 1 97 98\n", "output": "2 189\n"}, {"input": "5\n3 3 5 5 7\n", "output": "4 2\n"}, {"input": "5\n1 2 9 9 12\n", "output": "8 14\n"}, {"input": "5\n1 1 1 1 3\n", "output": "2 0\n"}, {"input": "2\n66 100\n", "output": "67 32\n"}, {"input": "3\n1 1 100\n", "output": "2 97\n"}, {"input": "11\n3 4 9 13 39 53 53 58 63 82 83\n", "output": "52 261\n"}, {"input": "4\n1 1 1 10\n", "output": "2 7\n"}] |
|
190 | Карта звёздного неба представляет собой прямоугольное поле, состоящее из n строк по m символов в каждой строке. Каждый символ — это либо «.» (означает пустой участок неба), либо «*» (означает то, что в этом месте на небе есть звезда).
Новое издание карты звёздного неба будет напечатано на квадратных листах, поэтому требуется найти минимально возможную сторону квадрата, в который могут поместиться все звезды. Границы искомого квадрата должны быть параллельны сторонам заданного прямоугольного поля.
-----Входные данные-----
В первой строке входных данных записаны два числа n и m (1 ≤ n, m ≤ 1000) — количество строк и столбцов на карте звездного неба.
В следующих n строках задано по m символов. Каждый символ — это либо «.» (пустой участок неба), либо «*» (звезда).
Гарантируется, что на небе есть хотя бы одна звезда.
-----Выходные данные-----
Выведите одно число — минимально возможную сторону квадрата, которым можно накрыть все звезды.
-----Примеры-----
Входные данные
4 4
....
..*.
...*
..**
Выходные данные
3
Входные данные
1 3
*.*
Выходные данные
3
Входные данные
2 1
.
*
Выходные данные
1
-----Примечание-----
Один из возможных ответов на первый тестовый пример:
[Image]
Один из возможных ответов на второй тестовый пример (обратите внимание, что покрывающий квадрат выходит за пределы карты звездного неба):
[Image]
Ответ на третий тестовый пример:
[Image] | interview | [{"code": "n, m = input().split()\nn = int(n)\nm = int(m)\na = []\nN = n\nfor i in range(n) :\n a.append(input().split())\n \nfor i in range(n) :\n if a[i][0].find('*') == -1 :\n n-=1\n else :\n break\nif n != 1 :\n for i in range(len(a)-1,-1,-1) :\n if a[i][0].find('*') == -1 :\n n-=1\n else :\n break\n#print(n)\n\nM = m\nbr = 0\nfor i in range(m) :\n count = 0\n for j in range(len(a)) :\n if a[j][0][i] != ('*') :\n count+=1\n else :\n br = 1\n break\n if br == 1 :\n break\n if count == N :\n m-=1\nbr = 0\nif m != 1 :\n for i in range(M-1,-1,-1) :\n count = 0\n for j in range(len(a)) :\n if a[j][0][i] != ('*') :\n count+=1\n else :\n br = 1\n break\n if br == 1 :\n break\n if count == N :\n m-=1\n#print(m)\nif m > n :\n print(m)\nelse :\n print(n)\n", "passed": true, "time": 0.22, "memory": 14584.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nl = [n, m]\nr = [-1, -1]\nfor i in range(n):\n A = input()\n if A.find('*')!=-1:\n if i < l[0]:\n l[0] = i\n if A.find('*') < l[1]:\n l[1] = A.find('*')\n if i > r[0]:\n r[0] = i\n if A.rfind('*') > r[1]:\n r[1] = A.rfind('*')\nprint(max(r[0]-l[0]+1, r[1]-l[1]+1))", "passed": true, "time": 0.24, "memory": 14512.0, "status": "done"}, {"code": "def main():\n n, m = list(map(int, input().split()))\n x1, y1, x2, y2 = n, m, -1, -1\n for i in range(n):\n s = input()\n for j in range(m):\n if s[j] == '*':\n x1, y1 = min(i, x1), min(j, y1)\n x2, y2 = max(i, x2), max(j, y2)\n ans = max(x2 - x1, y2 - y1) + 1\n print(ans)\nmain()\n", "passed": true, "time": 0.24, "memory": 14604.0, "status": "done"}, {"code": "n,m = map(int,input().split())\na = []\nfor i in range(n):\n a.append(list(input()))\nminj,maxi,maxj,mini = 10000000000000,0,-1,1000000000000\nfor i in range(n):\n for j in range(m):\n if a[i][j]=='*':\n minj = min(j,minj)\n maxi = i\n maxj = max(maxj,j)\n mini = min(mini,i)\nprint(max(maxi-mini+1,maxj-minj+1))", "passed": true, "time": 0.15, "memory": 14404.0, "status": "done"}, {"code": "s = input().split()\nn = int(s[0])\nm = int(s[1])\na = []\nb = []\nc = []\nd = []\nfor i in range(n):\n a.append(input())\nfor j in range(m):\n for i in range(n):\n if a[i][j] == '*':\n b.append(i)\n\nc.append(max(b) - min(b)+1)\nb = []\nfor i in range(n):\n for j in range(m):\n if a[i][j] == '*':\n b.append(j)\nd.append(max(b) - min(b)+1)\nprint(max(max(c),max(d)))\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n", "passed": true, "time": 0.14, "memory": 14660.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nmxx, mxy, mnx, mny = 0, 0, n + 1, m + 1\nfor i in range(0, n):\n line = input()\n for j in range(0, m):\n if line[j] == '*':\n mxx = max(mxx, i)\n mxy = max(mxy, j)\n mnx = min(mnx, i)\n mny = min(mny, j)\nprint(max(mxx - mnx + 1, mxy - mny + 1))", "passed": true, "time": 0.23, "memory": 14504.0, "status": "done"}, {"code": "def main():\n import sys\n input = sys.stdin.readline\n n, m = [int(i) for i in input().split()]\n x1 = n - 1\n x2 = 0\n y1 = m - 1\n y2 = 0\n for i in range(n):\n s = input()\n for j in range(m):\n if s[j] == '*':\n x1 = min(x1, i)\n x2 = max(x2, i)\n y1 = min(y1, j)\n y2 = max(y2, j)\n print(max(x2 - x1, y2 - y1) + 1)\n\nmain()", "passed": true, "time": 0.16, "memory": 14524.0, "status": "done"}, {"code": "n, m = [int(x) for x in input().split()]\nminX = m+1; maxX = -1; minY = n+1; maxY = -1\nfor i in range(n):\n\tline = input()\n\tj = 0\n\tfor c in line:\t\t\n\t\tif c == '*':\n\t\t\tif minX > j: minX = j\n\t\t\tif maxX < j: maxX = j\n\t\t\tif minY > i: minY = i\n\t\t\tif maxY < i: maxY = i\n\t\tj += 1\n\nprint(max(maxX - minX + 1, maxY - minY + 1))\n", "passed": true, "time": 0.15, "memory": 14404.0, "status": "done"}, {"code": "n,m=list(map(int,input().split()))\na=[]\nl=m+1\nr=-1\nu=n+1\nd=-1\nlma=m+1\nrma=-1\numa=n+1\ndma=-1\nfor i in range(n):\n a.append(input().strip())\n if a[i].find('*')!=-1:\n l=a[i].find('*')\n r=a[i].rfind('*')\n if l<lma:\n lma=l\n if r>rma:\n rma=r\n if '*' in a[i] and uma==n+1:\n uma=i\n if '*' in a[i] and uma!=n+1:\n dma=i\nprint(max(dma-uma+1, rma-lma+1))\n", "passed": true, "time": 0.15, "memory": 14428.0, "status": "done"}, {"code": "n, m = map(int,input().split())\nminv = n\nming = m\nmaxv = 0\nmaxg = 0\ni=0\nwhile (i < n):\n str = input()\n j=0\n while (j < m):\n if (str[j] == '*'):\n if (minv > i): minv = i\n if (maxv < i): maxv = i\n if (ming > j): ming = j\n if (maxg < j): maxg = j\n j+= 1\n i += 1\nif ((maxv - minv) > (maxg - ming)):\n n = maxv - minv + 1\n print(n)\nelse:\n m = maxg - ming + 1\n print(m)", "passed": true, "time": 0.16, "memory": 14368.0, "status": "done"}, {"code": "z = input().split()\na = []\nfor i in range(2):\n a.append(int(z[i]))\nn = a[0]\nm = a[1]\nb = []\nx1 = 1001\nx2 = 0\ny1 = 1001\ny2 = 0\nfor i in range(n):\n b.append(str(input()))\nfor i in range(n):\n for j in range(m):\n if b[i][j] == '*':\n if i < y1 :\n y1 = i\n if j < x1:\n x1 = j\n if i > y2:\n y2 = i\n if j > x2:\n x2 = j\nx = x2 - x1 + 1\ny = y2 - y1 + 1\nif x > y:\n print(x)\nelse:\n print(y)\n \n", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}, {"code": "n,m=list(map(int,input().split()))\na=[list(input()) for i in range(n)]\nima=0\njma=0\nimi=n+1\njmi=m+1\nfor i in range(n):\n\tfor j in range(m):\n\t\tif a[i][j]=='*':\n\t\t\tif i<imi:\n\t\t\t\timi=i\n\t\t\tif i>ima:\n\t\t\t\tima=i\n\t\t\tif j<jmi:\n\t\t\t\tjmi=j\n\t\t\tif j>jma:\n\t\t\t\tjma=j\nif ima-imi+1>0 and ima-imi+1>=jma-jmi+1:\n\tprint(ima-imi+1)\nelif jma-jmi+1>0 and jma-jmi+1>=ima-imi+1:\n\tprint(jma-jmi+1)\nelif jma-jmi<=0 and ima-imi<=0:\n\tprint(0)\n", "passed": true, "time": 0.14, "memory": 14488.0, "status": "done"}, {"code": "3\n\nnm = (str(input()).split(\" \"))\nprever = int(nm[0])\nposver = 0\npregor = int(nm[1])\nposgor = 0\n\nz = 1\nwhile z <= int(nm[0]):\n\t\tal = list(str(input()))\n\t\trar = al.count(\"*\")\n\t\tif rar != 0:\n\t\t\t\tif prever > z:\n\t\t\t\t\t\tprever = z\n\t\t\t\tif posver < z:\n\t\t\t\t\t\tposver = z\n\t\tx = 0\n\t\twhile x <= (len(al) - 1):\n\t\t\t\tif al[x] == '*':\n\t\t\t\t\t\tif pregor > x:\n\t\t\t\t\t\t\t\tpregor = x\n\t\t\t\t\t\tif posgor < x:\n\t\t\t\t\t\t\t\tposgor = x\n\t\t\t\tx += 1\n\t\tz += 1\n\ns1 = abs(pregor - posgor) + 1\ns2 = abs(prever - posver) + 1\n\nif s1 >= s2:\n\t\ts2 = s1\nelif s2 > s1:\n\t\ts1 = s2\nprint(s1)\n", "passed": true, "time": 0.14, "memory": 14420.0, "status": "done"}, {"code": "n,m = list(map(int,input().split()))\nb = True\nnach = 0\ncon = 0\nnn = 0\ncc = 0\nfor i in range(n):\n s = input()\n c = s.count('*')\n bb = True\n for j in range(m):\n if bb:\n if s[j] == '*':\n bb = False\n if b:\n nn = j\n else:\n nn = min(nn,j)\n if s[j] == '*':\n cc = max(cc,j)\n if b:\n if c != 0:\n b = False\n nach = i\n con = i\n if c != 0:\n con = i\nm1 = cc - nn + 1\nm2 = con - nach + 1\n#print(m1,m2)\nprint(max(m1,m2))\n \n", "passed": true, "time": 0.14, "memory": 14560.0, "status": "done"}] | [{"input": "4 4\n....\n..*.\n...*\n..**\n", "output": "3\n"}, {"input": "1 3\n*.*\n", "output": "3\n"}, {"input": "2 1\n.\n*\n", "output": "1\n"}, {"input": "1 1\n*\n", "output": "1\n"}, {"input": "1 2\n.*\n", "output": "1\n"}, {"input": "1 2\n*.\n", "output": "1\n"}, {"input": "1 2\n**\n", "output": "2\n"}, {"input": "2 1\n.\n*\n", "output": "1\n"}, {"input": "2 1\n*\n.\n", "output": "1\n"}, {"input": "2 1\n*\n*\n", "output": "2\n"}, {"input": "5 3\n..*\n.**\n..*\n...\n..*\n", "output": "5\n"}, {"input": "7 10\n..........\n......*...\n....**..*.\n...**.....\n...*......\n..........\n..**.*....\n", "output": "7\n"}, {"input": "3 9\n.........\n......*..\n.........\n", "output": "1\n"}, {"input": "4 3\n...\n..*\n*..\n...\n", "output": "3\n"}, {"input": "1 1\n*\n", "output": "1\n"}, {"input": "1 2\n*.\n", "output": "1\n"}, {"input": "1 2\n**\n", "output": "2\n"}, {"input": "1 3\n.**\n", "output": "2\n"}, {"input": "1 3\n*.*\n", "output": "3\n"}, {"input": "1 4\n..**\n", "output": "2\n"}, {"input": "1 4\n*..*\n", "output": "4\n"}, {"input": "1 5\n.*.**\n", "output": "4\n"}, {"input": "1 5\n.*..*\n", "output": "4\n"}, {"input": "2 1\n*\n.\n", "output": "1\n"}, {"input": "2 1\n*\n*\n", "output": "2\n"}, {"input": "2 2\n.*\n..\n", "output": "1\n"}, {"input": "2 2\n*.\n.*\n", "output": "2\n"}, {"input": "2 3\n*..\n**.\n", "output": "2\n"}, {"input": "2 3\n*..\n..*\n", "output": "3\n"}, {"input": "2 4\n.***\n.*.*\n", "output": "3\n"}, {"input": "2 4\n*..*\n....\n", "output": "4\n"}, {"input": "2 5\n*..**\n.*.*.\n", "output": "5\n"}, {"input": "2 5\n.....\n*.*..\n", "output": "3\n"}, {"input": "3 1\n*\n*\n*\n", "output": "3\n"}, {"input": "3 1\n*\n.\n*\n", "output": "3\n"}, {"input": "3 2\n..\n..\n**\n", "output": "2\n"}, {"input": "3 2\n.*\n.*\n..\n", "output": "2\n"}, {"input": "3 3\n*..\n.**\n***\n", "output": "3\n"}, {"input": "3 3\n*..\n.*.\n...\n", "output": "2\n"}, {"input": "3 4\n.*..\n....\n....\n", "output": "1\n"}, {"input": "3 4\n..*.\n....\n..*.\n", "output": "3\n"}, {"input": "3 5\n.....\n*.*..\n.....\n", "output": "3\n"}, {"input": "3 5\n.....\n.*...\n..*..\n", "output": "2\n"}, {"input": "4 1\n.\n.\n*\n*\n", "output": "2\n"}, {"input": "4 1\n*\n.\n*\n.\n", "output": "3\n"}, {"input": "4 2\n*.\n*.\n.*\n**\n", "output": "4\n"}, {"input": "4 2\n*.\n..\n..\n.*\n", "output": "4\n"}, {"input": "4 3\n...\n.**\n..*\n...\n", "output": "2\n"}, {"input": "4 3\n..*\n...\n...\n*..\n", "output": "4\n"}, {"input": "4 4\n..*.\n..*.\n.*..\n***.\n", "output": "4\n"}, {"input": "4 4\n....\n...*\n....\n..*.\n", "output": "3\n"}, {"input": "4 5\n*.*.*\n.....\n.....\n.....\n", "output": "5\n"}, {"input": "4 5\n.....\n...*.\n.*...\n.....\n", "output": "3\n"}, {"input": "5 1\n*\n*\n.\n.\n.\n", "output": "2\n"}, {"input": "5 1\n*\n.\n.\n.\n*\n", "output": "5\n"}, {"input": "5 2\n.*\n**\n**\n..\n**\n", "output": "5\n"}, {"input": "5 2\n*.\n..\n..\n..\n.*\n", "output": "5\n"}, {"input": "5 3\n...\n***\n..*\n.**\n**.\n", "output": "4\n"}, {"input": "5 3\n*..\n...\n...\n...\n.*.\n", "output": "5\n"}, {"input": "5 4\n*.**\n.*..\n.*..\n..*.\n*..*\n", "output": "5\n"}, {"input": "5 4\n....\n..*.\n....\n....\n..*.\n", "output": "4\n"}, {"input": "5 5\n....*\n....*\n....*\n..*..\n..*.*\n", "output": "5\n"}, {"input": "5 5\n.....\n..*..\n*....\n.....\n.....\n", "output": "3\n"}, {"input": "2 2\n**\n**\n", "output": "2\n"}, {"input": "2 2\n*.\n.*\n", "output": "2\n"}, {"input": "2 2\n.*\n*.\n", "output": "2\n"}, {"input": "2 2\n**\n..\n", "output": "2\n"}, {"input": "2 2\n..\n**\n", "output": "2\n"}, {"input": "2 2\n*.\n*.\n", "output": "2\n"}, {"input": "2 2\n.*\n.*\n", "output": "2\n"}, {"input": "2 2\n*.\n..\n", "output": "1\n"}, {"input": "2 2\n.*\n..\n", "output": "1\n"}, {"input": "2 2\n..\n*.\n", "output": "1\n"}, {"input": "2 2\n..\n.*\n", "output": "1\n"}, {"input": "2 2\n.*\n**\n", "output": "2\n"}, {"input": "2 2\n*.\n**\n", "output": "2\n"}, {"input": "2 2\n**\n.*\n", "output": "2\n"}, {"input": "2 2\n**\n*.\n", "output": "2\n"}] |
|
192 | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
-----Input-----
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
-----Output-----
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
-----Examples-----
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
-----Note-----
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do $(6,6,6) \rightarrow(6,6,3) \rightarrow(6,4,3) \rightarrow(3,4,3) \rightarrow(3,3,3)$.
In the second sample test, Memory can do $(8,8,8) \rightarrow(8,8,5) \rightarrow(8,5,5) \rightarrow(5,5,5)$.
In the third sample test, Memory can do: $(22,22,22) \rightarrow(7,22,22) \rightarrow(7,22,16) \rightarrow(7,10,16) \rightarrow(7,10,4) \rightarrow$
$(7,4,4) \rightarrow(4,4,4)$. | interview | [{"code": "x, y = list(map(int, input().split()))\nx, y = y, x\nA = x\nB = x\ncurr = x\ncount = 0\nwhile curr < y:\n\tcurr = B + A - 1\n\tA, B = B, curr\n\tcount += 1\ncount += 2\nprint(count)\n", "passed": true, "time": 0.15, "memory": 14568.0, "status": "done"}, {"code": "t, f = list(map(int, input().split()))\ns = [f] * 3\ncount = 0\nwhile sum(s) < 3*t:\n\ts.sort()\n\ts[0] = min(t, s[1]+s[2] - 1)\n\tcount += 1\nprint(count)\n", "passed": true, "time": 0.15, "memory": 14604.0, "status": "done"}, {"code": "x, y = list(map(int, input().split()))\nif (x > y):\n x, y = y, x\na = x\nb = x\nc = x\nans = 0\nwhile not (a == b == c == y):\n if (a <= b and a <= c):\n a = min(b + c - 1, y)\n elif (b <= a and b <= c):\n b = min(a + c - 1, y)\n elif (c <= a and c <= b):\n c = min(a + b - 1, y)\n ans += 1\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "x,y = map(int,input().split())\n\narr = [y,y,y]\nc = 0\nt = 0\nwhile True:\n if(arr.count(x)==3):\n break\n if(t==0):\n arr[0] = arr[1]+arr[2]-1\n if(arr[0]>x):\n arr[0] = x\n t = 1\n elif(t==1):\n arr[1] = arr[0]+arr[2]-1\n if(arr[1]>x):\n arr[1] = x\n t = 2\n elif(t==2):\n arr[2] = arr[0]+arr[1]-1\n if(arr[2]>x):\n arr[2] = x\n t = 0\n c += 1\nprint(c)", "passed": true, "time": 0.91, "memory": 14396.0, "status": "done"}, {"code": "x, y = list(map(int, input().split()))\nassert y < x\n\nit = 0\n\na, b, c = y, y, y\nwhile True:\n assert a >= c >= b\n assert a + b > c\n assert a + c > b\n assert b + c > a\n\n b = a + c - 1\n\n assert a + b > c\n assert a + c > b\n assert b + c > a\n\n it += 1\n if b >= x:\n b = x\n break\n a, b, c = b, c, a\n\nb = x\nit += 1\nassert a + b > c\nassert a + c > b\nassert b + c > a\n\nc = x\nit += 1\nassert a + b > c\nassert a + c > b\nassert b + c > a\n\nprint(it)\n", "passed": true, "time": 0.15, "memory": 14580.0, "status": "done"}, {"code": "x, y = [int(x) for x in input().split(' ')]\n\ntriset = [y] * 3\nc = 0\n\nwhile sum(triset) < x*3:\n triset.sort()\n triset[0] = triset[2] + triset[1] - 1\n if triset[0] > x: triset[0] = x\n c += 1\n\nprint(c)\n", "passed": true, "time": 0.15, "memory": 14428.0, "status": "done"}, {"code": "s = input()\nx = int(s.split()[0])\ny = int(s.split()[1])\na = [0] * 25\na[0] = y\na[1] = 2 * y - 1\nans = 0\nfor i in range(2, 25):\n if x <= a[i - 1]:\n ans = i + 1\n break\n a[i] = a[i - 1] + a[i - 2] - 1\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14540.0, "status": "done"}, {"code": "3\n\ndef transform(a, b, c, y):\n ans = 0\n while True:\n if a == b == c == y:\n return ans\n a, b, c = sorted([a, b, c], reverse=True)\n #print(a, b, c)\n c = min(a + b - 1, y)\n ans += 1\n \nx, y = list(map(int, input().split()))\nprint(transform(y, y, y, x))\n", "passed": true, "time": 0.23, "memory": 14352.0, "status": "done"}, {"code": "x, y = list(map(int, input().split()))\nl = [y, y, y]\n\n\ndef arg():\n argmax = 0\n argmin = 0\n for i in range(1, 3):\n if l[i] > l[argmax]:\n argmax = i\n if l[i] < l[argmin]:\n argmin = i\n if argmax == argmin:\n argmax = 0\n argmin = 1\n tmp = [0, 1, 2]\n tmp.remove(argmax)\n tmp.remove(argmin)\n return (argmin, tmp[0], argmax)\n\ncnt = 0\nwhile l[0] != x or l[1] != x or l[2] != x:\n args = arg()\n l[args[0]] = min(x, l[args[2]] + l[args[1]] - 1)\n cnt += 1\nprint(cnt)\n", "passed": true, "time": 1.67, "memory": 14420.0, "status": "done"}, {"code": "x, y = list(map(int, input().split()))\nx, y = min(x, y), max(x, y)\na, b, c = x, x, x\nans = 0\nwhile (not a == b == c == y):\n a = min(b + c - 1, y)\n ans += 1\n if (not a == b == c == y):\n b = min(a + c - 1, y)\n ans += 1\n if (not a == b == c == y):\n c = min(a + b - 1, y)\n ans += 1\n else:\n break\n else:\n break\n \nprint(ans)", "passed": true, "time": 0.23, "memory": 14460.0, "status": "done"}, {"code": "g,a=[int(x) for x in input().split()]\nb=c=a\ns=0\nwhile min(min(a,b),c)<g:\n s+=1\n l=[a,b,c]\n l.sort()\n a,b,c=l\n a=min(g,c+b-1)\nprint(s)", "passed": true, "time": 0.16, "memory": 14564.0, "status": "done"}, {"code": "def get_next(T):\n [a,b,c] = sorted(T)\n return [b,c,b+c-1]\n\ndef main():\n y,x = [int(s) for s in input().split()]\n T = [x,x,x]\n i = 0\n while max(T) < y:\n T = get_next(T)\n i += 1\n print(2+i)\n\nmain()\n", "passed": true, "time": 0.24, "memory": 14540.0, "status": "done"}, {"code": "y, x = list(map(int, input(). split()))\na = x; b = x; c = x; k = 0\nwhile a < y or b < y or c < y:\n if a < c+b-1:\n a = c+b-1\n k += 1\n if a >= y and b >= y and c >= y:\n break\n if b < a+c-1:\n b = a+c-1\n k += 1\n if a >= y and b >= y and c >= y:\n break\n if c < a+b-1:\n c = a+b-1\n k += 1\n if a >= y and b >= y and c >= y:\n break\nprint(k)\n", "passed": true, "time": 0.14, "memory": 14408.0, "status": "done"}, {"code": "x,y = list(map(int,input().split()))\ns = [y,y,y]\nk = 0\nwhile sum(s)!=x*3:\n mi = min(s)\n ma = max(s)\n sr = sum(s)-ma-mi\n a = sum([sr,ma])-1\n if a>x:\n a = x\n s[s.index(mi)] = a\n k+=1\nprint(k)\n", "passed": true, "time": 0.23, "memory": 14420.0, "status": "done"}, {"code": "x,y = list(map(int,input().split()))\ns = [y,y,y]\nk = 0\nwhile sum(s)!=x*3:\n minn = min(s)\n maxx = max(s)\n sr = sum(s)-maxx-minn\n a = sum([sr,maxx])-1\n if a>x:\n a = x\n s[s.index(minn)] = a\n k+=1\nprint(k)\n", "passed": true, "time": 0.14, "memory": 14472.0, "status": "done"}, {"code": "def exists(a, b, c):\n return a < b + c and b < a + c and c < a + b\n\nx, y = [int(i) for i in input().split()]\na, b, c = y, y, y\ncount = 0\nwhile a != x or b != x or c != x:\n a, b, c = sorted([a, b, c])\n a = x if exists(x, b, c) else b + c - 1\n count += 1\n \nprint(count)", "passed": true, "time": 0.15, "memory": 14464.0, "status": "done"}, {"code": "x, y = map(int, input().split())\ncounter = 0\n\nx, y = min(x,y), max(x,y)\nx1 = x\nx2 = x\nx3 = x\n\nwhile y > x1 or y > x2 or y > x3:\n if x1 != y:\n x1 = min(x3 + x2 - 1, y)\n counter += 1\n if x2 != y:\n x2 = min(x1 + x3 - 1, y)\n counter += 1\n if x3 != y:\n x3 = min(x1 + x2 - 1, y)\n counter += 1\n\n# print(x1,x2,x3)\n\nprint(counter)", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "\n \nline1=input().split()\nx=int(line1[0])\ny=int(line1[1])\n\n\na,b,c=y,y,y\nsteps=0\nwhile (a<x or b<x or c<x):\n a=b+c-1\n steps+=1\n a,b,c=min(a,b,c), a+b+c-max(a,b,c)-min(a,b,c), max(a,b,c)\n \nprint (steps)\n", "passed": true, "time": 0.14, "memory": 14396.0, "status": "done"}, {"code": "import math\n\nx, y = list(map(int, input().split()))\nres = 0\nnow = [y, y, y]\nwhile min(now) < x:\n res += 1\n ind = now.index(min(now))\n o1, o2 = (ind + 1) % 3, (ind + 2) % 3\n now[ind] = now[o1] + now[o2] - 1\nprint(res)\n\n", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}, {"code": "c=0\nd=0\n\n\nt=input().split()\nx=int(t[0])\ny=int(t[1])\n\nxx=[y,y,y]\nyy=[x,x,x]\nwhile(yy!=xx):\n xx.sort()\n z=sum(xx[1:3])-1\n c=c+1\n if(z>=x):\n xx[0]=x\n\n else:\n xx[0]=z\n\nprint(c)\n\n\n\n\n\n\n\n\n\n", "passed": true, "time": 0.15, "memory": 14604.0, "status": "done"}, {"code": "#!/usr/bin/env python3.5\nimport sys\n\ndef read_data():\n return list(map(int, next(sys.stdin).split()))\n\n\ndef solve(f, t):\n if f > t:\n f, t = t, f\n if f == t:\n return 0\n a, b, c = f, f, f \n count = 0\n while a < t:\n c = min(a + b - 1, t)\n c, b, a = sorted((a, b, c))\n count += 1\n #print(a, b, c)\n if b < t:\n #print(t, t, c)\n count += 1\n if c < t:\n #print(t, t, t)\n count += 1\n return count\n \n\n\ndef __starting_point():\n f, t = read_data()\n print(solve(f, t))\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14580.0, "status": "done"}, {"code": "n,m = list(map(int,input().split()))\ns = [m,m,m]\nans = 0\nwhile s[0] < n:\n val = min(n,s[1]+s[2]-1)\n s[0] = s[1]\n s[1] = s[2]\n s[2] = val\n ans+=1\nprint(ans)\n\n", "passed": true, "time": 0.15, "memory": 14600.0, "status": "done"}, {"code": "def get_next(T):\n [a,b,c] = sorted(T)\n return [b,c,b+c-1]\n\ndef __starting_point():\n y,x = [int(a) for a in input().split()]\n T = [x,x,x]\n # print(T)\n i = 0\n while max(T) < y:\n T = get_next(T)\n # print(T)\n i+=1\n\n print(2+i)\n__starting_point()", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "x, y = map(int,input().split())\na = [y,y,y]\ncnt = 0\nwhile True:\n if a[0] == a[1] == a[2] == x:\n break\n if a[1] + a[2] > x:\n a[0] = x\n else:\n a[0] = a[1] + a[2] - 1\n cnt+=1\n a.sort()\nprint(cnt)", "passed": true, "time": 0.14, "memory": 14376.0, "status": "done"}, {"code": "t, f = map(int, input().split())\ns = [f] * 3\ncount = 0\nwhile sum(s) < 3*t:\n\ts.sort()\n\ts[0] = min(t, s[1]+s[2] - 1)\n\tcount += 1\nprint(count)", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}] | [{"input": "6 3\n", "output": "4\n"}, {"input": "8 5\n", "output": "3\n"}, {"input": "22 4\n", "output": "6\n"}, {"input": "4 3\n", "output": "3\n"}, {"input": "57 27\n", "output": "4\n"}, {"input": "61 3\n", "output": "9\n"}, {"input": "5 4\n", "output": "3\n"}, {"input": "10 6\n", "output": "3\n"}, {"input": "20 10\n", "output": "4\n"}, {"input": "30 5\n", "output": "6\n"}, {"input": "25 24\n", "output": "3\n"}, {"input": "25 3\n", "output": "7\n"}, {"input": "12 7\n", "output": "3\n"}, {"input": "18 6\n", "output": "5\n"}, {"input": "100000 3\n", "output": "25\n"}, {"input": "100000 9999\n", "output": "7\n"}, {"input": "9999 3\n", "output": "20\n"}, {"input": "5323 32\n", "output": "13\n"}, {"input": "6666 66\n", "output": "12\n"}, {"input": "38578 32201\n", "output": "3\n"}, {"input": "49449 5291\n", "output": "7\n"}, {"input": "65310 32879\n", "output": "3\n"}, {"input": "41183 4453\n", "output": "7\n"}, {"input": "49127 9714\n", "output": "6\n"}, {"input": "19684 12784\n", "output": "3\n"}, {"input": "15332 5489\n", "output": "4\n"}, {"input": "33904 32701\n", "output": "3\n"}, {"input": "9258 2966\n", "output": "5\n"}, {"input": "21648 11231\n", "output": "3\n"}, {"input": "90952 47239\n", "output": "3\n"}, {"input": "49298 23199\n", "output": "4\n"}, {"input": "33643 24915\n", "output": "3\n"}, {"input": "40651 5137\n", "output": "6\n"}, {"input": "52991 15644\n", "output": "5\n"}, {"input": "97075 62157\n", "output": "3\n"}, {"input": "82767 53725\n", "output": "3\n"}, {"input": "58915 26212\n", "output": "4\n"}, {"input": "86516 16353\n", "output": "6\n"}, {"input": "14746 7504\n", "output": "3\n"}, {"input": "20404 7529\n", "output": "4\n"}, {"input": "52614 8572\n", "output": "6\n"}, {"input": "50561 50123\n", "output": "3\n"}, {"input": "37509 7908\n", "output": "5\n"}, {"input": "36575 23933\n", "output": "3\n"}, {"input": "75842 8002\n", "output": "7\n"}, {"input": "47357 2692\n", "output": "8\n"}, {"input": "23214 4255\n", "output": "6\n"}, {"input": "9474 46\n", "output": "13\n"}, {"input": "79874 76143\n", "output": "3\n"}, {"input": "63784 31333\n", "output": "4\n"}, {"input": "70689 29493\n", "output": "4\n"}, {"input": "43575 4086\n", "output": "7\n"}, {"input": "87099 7410\n", "output": "7\n"}, {"input": "75749 55910\n", "output": "3\n"}, {"input": "87827 20996\n", "output": "5\n"}, {"input": "31162 4580\n", "output": "6\n"}, {"input": "63175 33696\n", "output": "3\n"}, {"input": "15108 10033\n", "output": "3\n"}, {"input": "82991 29195\n", "output": "4\n"}, {"input": "48258 12837\n", "output": "5\n"}, {"input": "59859 33779\n", "output": "3\n"}, {"input": "93698 23890\n", "output": "5\n"}, {"input": "42724 379\n", "output": "12\n"}, {"input": "70434 39286\n", "output": "3\n"}, {"input": "69826 18300\n", "output": "5\n"}, {"input": "57825 17636\n", "output": "5\n"}, {"input": "64898 2076\n", "output": "9\n"}, {"input": "76375 67152\n", "output": "3\n"}, {"input": "30698 3778\n", "output": "7\n"}, {"input": "100 3\n", "output": "10\n"}, {"input": "41 3\n", "output": "8\n"}, {"input": "28 4\n", "output": "7\n"}, {"input": "2487 19\n", "output": "12\n"}, {"input": "100000 25000\n", "output": "5\n"}, {"input": "10000 3\n", "output": "20\n"}, {"input": "16 3\n", "output": "6\n"}] |
|
194 | In a small restaurant there are a tables for one person and b tables for two persons.
It it known that n groups of people come today, each consisting of one or two people.
If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.
If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.
You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.
-----Input-----
The first line contains three integers n, a and b (1 ≤ n ≤ 2·10^5, 1 ≤ a, b ≤ 2·10^5) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables.
The second line contains a sequence of integers t_1, t_2, ..., t_{n} (1 ≤ t_{i} ≤ 2) — the description of clients in chronological order. If t_{i} is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.
-----Output-----
Print the total number of people the restaurant denies service to.
-----Examples-----
Input
4 1 2
1 2 1 1
Output
0
Input
4 1 1
1 1 2 1
Output
2
-----Note-----
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.
In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | interview | [{"code": "n, a, b = list(map(int,input().split()))\nl = input().split()\no = 0\nc = 0\nfor i in l:\n if i == '2':\n if b > 0:\n b -= 1\n else:\n o += 2\n if i == '1':\n if a > 0:\n a -= 1\n elif b > 0:\n b -= 1\n c += 1\n elif c > 0:\n c -= 1\n else:\n o += 1\nprint(o)\n", "passed": true, "time": 0.15, "memory": 14392.0, "status": "done"}, {"code": "n, a, b = map(int, input().split())\none = 0\nour = list(map(int, input().split()))\nres = 0\nfor elem in our:\n if elem == 2:\n if b > 0:\n b -= 1\n else:\n res += 2\n else:\n if a > 0:\n a -= 1\n elif b > 0:\n b -= 1\n one += 1\n elif one > 0:\n one -= 1\n else:\n res += 1\nprint(res)", "passed": true, "time": 0.21, "memory": 14380.0, "status": "done"}, {"code": "n, a, b = map(int, input().split())\n\nc = 0\n\nans = 0\n\nfor v in map(int, input().split()):\n\tif v == 1:\n\t\tif a:\n\t\t\ta -= 1\n\t\telif b:\n\t\t\tb -= 1\n\t\t\tc += 1\n\t\telif c:\n\t\t\tc -= 1\n\t\telse:\n\t\t\tans += 1\n\telse:\n\t\tif b:\n\t\t\tb -= 1\n\t\telse:\n\t\t\tans += 2\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "import sys \n\ndef main():\n n, a,b = list(map(int,sys.stdin.readline().split()))\n x = list(map(int,sys.stdin.readline().split()))\n c = 0\n ans =0\n for i in range(n):\n \tt = x[i]\n \tif t ==1:\n \t\tif a!=0:\n \t\t\ta-=1\n \t\telif b!=0:\n \t\t\tb-=1\n \t\t\tc+=1\n \t\telif c!=0:\n \t\t\tc-=1\n \t\telse:\n \t\t\tans+=1\n \telse:\n \t\tif b!=0:\n \t\t\tb-=1\n \t\telse:\n \t\t\tans+=2\n \n print(ans)\n \n\nmain()\n", "passed": true, "time": 0.15, "memory": 14568.0, "status": "done"}, {"code": "n, a, b = list(map(int, input().split()))\npo = 0\nans = 0\nL = list(map(int, input().split()))\nfor i in L:\n if i == 1:\n if a > 0:\n a -= 1\n elif b > 0:\n b -= 1\n po += 1\n elif po > 0:\n po -= 1\n else:\n ans += 1\n else:\n if b > 0:\n b -= 1\n else:\n ans += 2\nprint(ans)\n", "passed": true, "time": 0.25, "memory": 14480.0, "status": "done"}, {"code": "n,a,b = list(map(int,input().split()))\nline = input().split()\nt = []\nc = 0\nrej = 0\nfor i in range(n):\n t.append(int(line[i]))\nfor i in range(n):\n if a > 0 and t[i] == 1:\n a -= 1\n elif t[i] == 1 and b > 0:\n b -= 1\n c += 1\n elif t[i] == 1 and c > 0:\n c -= 1\n elif t[i] == 2 and b > 0:\n b -= 1\n else:\n rej += t[i]\nprint(rej)\n", "passed": true, "time": 0.2, "memory": 14600.0, "status": "done"}, {"code": "n, a, b = [int(i) for i in input().split()]\nt = [int(i) for i in input().split()]\npart = 0\nans = 0\nfor i in t:\n if i == 1:\n if a:\n a -= 1\n elif b:\n b -= 1\n part += 1\n elif part:\n part -= 1\n else:\n ans += 1\n else:\n if b:\n b -= 1\n else:\n ans += 2\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14464.0, "status": "done"}, {"code": "n, a, b = [int(s) for s in input().split()]\nt = [int(s) for s in input().split()]\nans, c = 0, 0\nfor i in range(n):\n if t[i] == 1:\n if a>0:\n a-=1\n elif b>0:\n b-=1\n c+=1\n elif c>0:\n c-=1\n else:\n ans+=1\n else:\n if b>0:\n b-=1\n else:\n ans+=2\nprint(ans)\n", "passed": true, "time": 0.22, "memory": 14520.0, "status": "done"}, {"code": "def num_denied(a, b, groups):\n c = 0\n d = 0\n for g in groups:\n if g == 1:\n if a > 0:\n a -= 1\n elif b > 0:\n b -= 1\n c += 1\n elif c > 0:\n c -= 1\n else:\n d += 1\n elif g == 2:\n if b > 0:\n b -= 1\n else:\n d += 2\n return d\n\ndef __starting_point():\n n, a, b = list(map(int, input().split()))\n groups = list(map(int, input().split()))\n print(num_denied(a, b, groups))\n\n__starting_point()", "passed": true, "time": 0.18, "memory": 14408.0, "status": "done"}, {"code": "n, a, b = list(map(int, input().split()))\nL = list(map(int, input().split()))\nb1 = 0\nans = 0\nfor i in L:\n if i == 1:\n if a > 0:\n a -= 1\n elif b > 0:\n b -= 1\n b1 += 1\n elif b1 > 0:\n b1 -= 1\n else:\n ans += 1\n else:\n if b > 0:\n b -= 1\n else:\n ans += 2\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14512.0, "status": "done"}, {"code": "q,w,e=list(map(int,input().split()))\na=list(map(int,input().split()))\nz=a.count(1)\nx=a.count(2)\nr=0\ns=0\nfor i in a:\n if i==1:\n if w>0:\n w-=1\n elif e>0:\n e-=1\n r+=1\n elif r>0:\n r-=1\n else:\n s+=1\n else:\n if e>0:\n e-=1\n else:\n s+=2\nprint(s)\n", "passed": true, "time": 0.21, "memory": 14560.0, "status": "done"}, {"code": "n,a,b=list(map(int,input().split()))\nn10=a\nn20=b\nn21=0\nt=list(map(int,input().split()))\nans=0\nfor i in t:\n\tif i==1:\n\t\tif n10:\n\t\t\tn10-=1\n\t\telif n20:\n\t\t\tn20-=1\n\t\t\tn21+=1\n\t\telif n21:\n\t\t\tn21-=1\n\t\telse:\n\t\t\tans+=1\n\telse:\n\t\tif n20:\n\t\t\tn20-=1\n\t\telse:\n\t\t\tans+=2\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14340.0, "status": "done"}, {"code": "n, n1, n2 = [int(x) for x in input().split()]\nn3 = 0\na = 0\nfor i in input().split():\n i = int(i)\n if i == 1:\n if n1:\n n1 -= 1\n elif n2:\n n2 -= 1\n n3 += 1\n elif n3:\n n3 -= 1\n else:\n a += 1\n else:\n if n2:\n n2 -= 1\n else:\n a += 2\nprint(a)", "passed": true, "time": 0.14, "memory": 14460.0, "status": "done"}, {"code": "n,a,b=list(map(int,input().strip().split(' ')))\nP=list(map(int,input().strip().split(' ')))\ncount1=0\ncount2=0\ncount2half=0\nbad=0\nfor i in range(len(P)):\n if P[i]==1:\n if count1<a:\n count1+=1\n elif count2<b:\n if 1==1:\n count2half+=1\n count2+=1\n \n elif count2half>0:\n count2half-=1\n else:\n bad+=1\n \n \n else:\n if count2<b:\n count2+=1\n else:\n bad+=2\nprint(bad) \n", "passed": true, "time": 0.15, "memory": 14580.0, "status": "done"}, {"code": "n,a,b = list(map(int,input().split()))\narr = [int(x) for x in input().split()]\nans = 0\nca = 0\nfor i in arr:\n if i==1:\n if a!=0:\n a -= 1\n elif b!=0:\n b -= 1\n ca += 1\n elif ca!=0:\n ca -= 1\n else:\n ans += 1\n else:\n if b!=0:\n b -= 1\n else:\n ans += 2\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14520.0, "status": "done"}, {"code": "n, a, b = list(map(int, input().split()))\nt = list(map(int, input().split()))\n\nans = 0\ncnta = 0\ncntb1 = 0\ncntb2 = 0\nfor ti in t:\n if ti == 1:\n if cnta < a:\n cnta += 1\n elif cntb1 + cntb2 < b:\n cntb1 += 1\n elif 0 < cntb1:\n cntb1 -= 1\n cntb2 += 1\n else:\n ans += 1\n else:\n if cntb1 + cntb2 < b:\n cntb2 += 1\n else:\n ans += 2\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14588.0, "status": "done"}, {"code": "n,a,b=list(map(int,input().split()))\ndata = list(map(int,input().split()))\nh=c=0\nfor i in data:\n if i==1:\n if a>0:\n a-=1\n elif b>0:\n b-=1\n h+=1\n elif h>0:\n h-=1\n else:\n c+=1\n else:\n if b>0:\n b-=1\n else:\n c+=2\n \nprint(c)\n", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "# IAWT\nn, a, b = list(map(int, input().split()))\nl = list(map(int, input().split()))\nempty_one = a\nempty_two = b\nhalf_two = 0\ndenies = 0\n\ndef handle(group):\n nonlocal empty_one, empty_two, half_two, denies\n if group == 1:\n if empty_one > 0:\n empty_one -= 1\n return\n if empty_two > 0:\n empty_two -= 1\n half_two += 1\n return\n if half_two > 0:\n half_two -= 1\n return\n denies += 1\n return\n elif group == 2:\n if empty_two > 0:\n empty_two -= 1\n return\n denies += 2\n return\n\nfor i in range(n):\n handle(l[i])\n\nprint(denies)\n", "passed": true, "time": 0.21, "memory": 14508.0, "status": "done"}, {"code": "def __starting_point():\n n, c1, c2 = list(map(int, input().split()))\n g = list(map(int, input().split()))\n count = 0\n deny = 0\n for i in range(n):\n if g[i] == 1:\n if c1 > 0:\n c1 -= 1\n elif c1 <= 0 and c2 > 0:\n c2 -= 1\n count += 1\n elif c2 <= 0 and count > 0:\n count -= 1\n else:\n deny += 1\n else:\n if c2 > 0:\n c2 -= 1\n else:\n deny += 2\n print(deny)\n \n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "n, a, b = list(map(int, input().split()))\nt = list(map(int, input().split()))\none, ans = 0, 0\n\nfor i in t:\n if i == 1:\n if a > 0:\n a -= 1\n elif b > 0:\n one += 1\n b -= 1\n elif one > 0:\n one -= 1\n else:\n ans += 1\n elif i == 2:\n if b > 0:\n b -= 1\n else:\n ans += 2\n\nprint(ans)\n", "passed": true, "time": 0.17, "memory": 14404.0, "status": "done"}, {"code": "n, a, b = list(map(int, input().split()))\nc = 0 \nd = 0\nx = list(map(int, input().split()))\nfor v in x:\n if v > 1:\n if b > 0:\n b -= 1\n else:\n d += 2\n else:\n if a > 0:\n a -= 1\n elif b > 0:\n b -= 1\n c += 1\n elif c > 0:\n c -= 1\n else:\n d += 1\nprint(d) \n", "passed": true, "time": 0.16, "memory": 14496.0, "status": "done"}, {"code": "n, one, two = map(int, input().split())\narr = list(map(int, input().split()))\n\ntwo_one = 0\nfail = 0\n\nfor x in arr[:n]:\n if x == 1:\n if one > 0:\n one -= 1\n elif two > 0:\n two -= 1\n two_one += 1\n elif two_one > 0:\n two_one -= 1\n else:\n fail += 1\n else:\n if two > 0:\n two -= 1\n else:\n fail += 2\n \nprint(fail)", "passed": true, "time": 0.15, "memory": 14636.0, "status": "done"}, {"code": "n, a, b = (input().split())\nn = int(n)\na = int(a)\nb = int(b)\npotatos = 0\ncounter = 0\n\ncustomers = input().split()\nfor i in customers:\n if(i == '1'):\n if(a > 0):\n a -= 1\n elif(b > 0):\n b -= 1\n potatos += 1\n elif(potatos > 0):\n potatos -= 1\n else:\n counter += 1\n else:\n if(b > 0):\n b -= 1\n else:\n counter += 2\n\nprint(counter)\n", "passed": true, "time": 0.14, "memory": 14476.0, "status": "done"}, {"code": "n, a, b = list(map(int,input().split()))\nq=list(map(int,input().split()))\nc=0\nt = True\nk=0 \nfor i in range(n):\n if q[i]==1 and a>0:\n a-=1\n elif q[i]==1 and a==0 and b>0:\n c+=1\n b-=1\n elif q[i]==1 and b==0 and a==0 and c>0:\n c-=1\n elif q[i]==2 and b>0:\n b-=1\n else:\n if q[i]==1:\n k+=1\n else:\n k+=2\nprint(k)\n", "passed": true, "time": 0.14, "memory": 14640.0, "status": "done"}, {"code": "n, ones, twos = list(map(int,input().split()))\nsemi = 0\ndeny = 0\nhumans = list(map(int,input().split()))\nfor k in humans:\n if k==1:\n if ones>0:\n ones-=1\n elif ones==0:\n if twos>0:\n twos-=1\n semi+=1\n elif twos==0:\n if semi>0:\n semi-=1\n else:\n deny+=1\n elif k==2:\n if twos>0:\n twos-=1\n else:\n deny+=2\nprint(deny)", "passed": true, "time": 0.14, "memory": 14540.0, "status": "done"}] | [{"input": "4 1 2\n1 2 1 1\n", "output": "0\n"}, {"input": "4 1 1\n1 1 2 1\n", "output": "2\n"}, {"input": "1 1 1\n1\n", "output": "0\n"}, {"input": "2 1 2\n2 2\n", "output": "0\n"}, {"input": "5 1 3\n1 2 2 2 1\n", "output": "1\n"}, {"input": "7 6 1\n1 1 1 1 1 1 1\n", "output": "0\n"}, {"input": "10 2 1\n2 1 2 2 2 2 1 2 1 2\n", "output": "13\n"}, {"input": "20 4 3\n2 2 2 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 1 2\n", "output": "25\n"}, {"input": "1 1 1\n1\n", "output": "0\n"}, {"input": "1 1 1\n2\n", "output": "0\n"}, {"input": "1 200000 200000\n2\n", "output": "0\n"}, {"input": "30 10 10\n1 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\n", "output": "20\n"}, {"input": "4 1 2\n1 1 1 2\n", "output": "2\n"}, {"input": "6 2 3\n1 2 1 1 1 2\n", "output": "2\n"}, {"input": "6 1 4\n1 1 1 1 1 2\n", "output": "2\n"}, {"input": "6 1 3\n1 1 1 1 2 2\n", "output": "4\n"}, {"input": "6 1 3\n1 1 1 1 1 2\n", "output": "2\n"}, {"input": "6 4 2\n2 1 2 2 1 1\n", "output": "2\n"}, {"input": "3 10 1\n2 2 2\n", "output": "4\n"}, {"input": "5 1 3\n1 1 1 1 2\n", "output": "2\n"}, {"input": "5 2 2\n1 1 1 1 2\n", "output": "2\n"}, {"input": "15 5 5\n1 1 1 1 1 1 1 1 1 1 2 2 2 2 2\n", "output": "10\n"}, {"input": "5 1 2\n1 1 1 1 1\n", "output": "0\n"}, {"input": "3 6 1\n2 2 2\n", "output": "4\n"}, {"input": "5 3 3\n2 2 2 2 2\n", "output": "4\n"}, {"input": "8 3 3\n1 1 1 1 1 1 2 2\n", "output": "4\n"}, {"input": "5 1 2\n1 1 1 2 1\n", "output": "2\n"}, {"input": "6 1 4\n1 2 2 1 2 2\n", "output": "2\n"}, {"input": "2 1 1\n2 2\n", "output": "2\n"}, {"input": "2 2 1\n2 2\n", "output": "2\n"}, {"input": "5 8 1\n2 2 2 2 2\n", "output": "8\n"}, {"input": "3 1 4\n1 1 2\n", "output": "0\n"}, {"input": "7 1 5\n1 1 1 1 1 1 2\n", "output": "2\n"}, {"input": "6 1 3\n1 1 1 2 1 1\n", "output": "0\n"}, {"input": "6 1 2\n1 1 1 2 2 2\n", "output": "6\n"}, {"input": "8 1 4\n2 1 1 1 2 2 2 2\n", "output": "6\n"}, {"input": "4 2 3\n2 2 2 2\n", "output": "2\n"}, {"input": "3 1 1\n1 1 2\n", "output": "2\n"}, {"input": "5 1 1\n2 2 2 2 2\n", "output": "8\n"}, {"input": "10 1 5\n1 1 1 1 1 2 2 2 2 2\n", "output": "8\n"}, {"input": "5 1 2\n1 1 1 2 2\n", "output": "4\n"}, {"input": "4 1 1\n1 1 2 2\n", "output": "4\n"}, {"input": "7 1 2\n1 1 1 1 1 1 1\n", "output": "2\n"}, {"input": "5 1 4\n2 2 2 2 2\n", "output": "2\n"}, {"input": "6 2 3\n1 1 1 1 2 2\n", "output": "2\n"}, {"input": "5 2 2\n2 1 2 1 2\n", "output": "2\n"}, {"input": "4 6 1\n2 2 2 2\n", "output": "6\n"}, {"input": "6 1 4\n1 1 2 1 1 2\n", "output": "2\n"}, {"input": "7 1 3\n1 1 1 1 2 2 2\n", "output": "6\n"}, {"input": "4 1 2\n1 1 2 2\n", "output": "2\n"}, {"input": "3 1 2\n1 1 2\n", "output": "0\n"}, {"input": "6 1 3\n1 2 1 1 2 1\n", "output": "2\n"}, {"input": "6 1 3\n1 1 1 2 2 2\n", "output": "4\n"}, {"input": "10 2 2\n1 1 1 1 2 2 2 2 2 2\n", "output": "12\n"}, {"input": "10 1 4\n1 1 1 1 1 2 2 2 2 2\n", "output": "10\n"}, {"input": "3 10 2\n2 2 2\n", "output": "2\n"}, {"input": "4 3 1\n1 2 2 2\n", "output": "4\n"}, {"input": "7 1 4\n1 1 1 1 1 2 2\n", "output": "4\n"}, {"input": "3 4 1\n2 2 2\n", "output": "4\n"}, {"input": "4 1 2\n2 1 1 2\n", "output": "2\n"}, {"input": "10 1 2\n1 1 1 1 1 1 1 1 1 2\n", "output": "6\n"}, {"input": "5 1 3\n1 1 2 1 2\n", "output": "2\n"}, {"input": "6 1 3\n1 1 1 1 2 1\n", "output": "2\n"}, {"input": "6 1 4\n1 1 1 2 2 2\n", "output": "2\n"}, {"input": "7 1 2\n1 2 1 1 1 1 1\n", "output": "3\n"}, {"input": "6 2 2\n1 1 1 1 1 1\n", "output": "0\n"}, {"input": "6 1 2\n1 1 2 1 1 1\n", "output": "2\n"}, {"input": "3 3 1\n2 2 1\n", "output": "2\n"}, {"input": "8 4 2\n1 1 1 1 1 1 1 2\n", "output": "2\n"}, {"input": "9 1 4\n1 1 1 1 1 2 2 2 2\n", "output": "8\n"}, {"input": "5 10 1\n2 2 2 2 2\n", "output": "8\n"}, {"input": "3 5 1\n2 2 2\n", "output": "4\n"}, {"input": "5 100 1\n2 2 2 2 2\n", "output": "8\n"}, {"input": "4 1 2\n1 1 1 1\n", "output": "0\n"}, {"input": "4 1 1\n1 1 1 1\n", "output": "1\n"}, {"input": "7 2 2\n1 1 1 1 1 1 1\n", "output": "1\n"}] |
|
195 | Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
-----Input-----
The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$).
-----Output-----
If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$.
-----Examples-----
Input
10 10 5 20
Output
5
Input
2 2 0 4
Output
-1
Input
2 2 2 1
Output
-1
-----Note-----
The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible. | interview | [{"code": "from sys import stdin, stdout\n\na, b, c, d = map(int, stdin.readline().split())\nq = d - a - b + c\n\nif c > min(a, b) or q <= 0:\n stdout.write('-1')\nelse:\n stdout.write(str(q))", "passed": true, "time": 0.14, "memory": 14348.0, "status": "done"}] | [{"input": "10 10 5 20\n", "output": "5"}, {"input": "2 2 0 4\n", "output": "-1"}, {"input": "2 2 2 1\n", "output": "-1"}, {"input": "98 98 97 100\n", "output": "1"}, {"input": "1 5 2 10\n", "output": "-1"}, {"input": "5 1 2 10\n", "output": "-1"}, {"input": "6 7 5 8\n", "output": "-1"}, {"input": "6 7 5 9\n", "output": "1"}, {"input": "6 7 5 7\n", "output": "-1"}, {"input": "50 50 1 100\n", "output": "1"}, {"input": "8 3 2 12\n", "output": "3"}, {"input": "10 19 6 25\n", "output": "2"}, {"input": "1 0 0 99\n", "output": "98"}, {"input": "0 1 0 98\n", "output": "97"}, {"input": "1 1 0 97\n", "output": "95"}, {"input": "1 1 1 96\n", "output": "95"}, {"input": "0 0 0 0\n", "output": "-1"}, {"input": "100 0 0 0\n", "output": "-1"}, {"input": "0 100 0 0\n", "output": "-1"}, {"input": "100 100 0 0\n", "output": "-1"}, {"input": "0 0 100 0\n", "output": "-1"}, {"input": "100 0 100 0\n", "output": "-1"}, {"input": "0 100 100 0\n", "output": "-1"}, {"input": "100 100 100 0\n", "output": "-1"}, {"input": "0 0 0 100\n", "output": "100"}, {"input": "100 0 0 100\n", "output": "-1"}, {"input": "0 100 0 100\n", "output": "-1"}, {"input": "100 100 0 100\n", "output": "-1"}, {"input": "0 0 100 100\n", "output": "-1"}, {"input": "100 0 100 100\n", "output": "-1"}, {"input": "0 100 100 100\n", "output": "-1"}, {"input": "100 100 100 100\n", "output": "-1"}, {"input": "10 45 7 52\n", "output": "4"}, {"input": "38 1 1 68\n", "output": "30"}, {"input": "8 45 2 67\n", "output": "16"}, {"input": "36 36 18 65\n", "output": "11"}, {"input": "10 30 8 59\n", "output": "27"}, {"input": "38 20 12 49\n", "output": "3"}, {"input": "8 19 4 38\n", "output": "15"}, {"input": "36 21 17 72\n", "output": "32"}, {"input": "14 12 12 89\n", "output": "75"}, {"input": "38 6 1 44\n", "output": "1"}, {"input": "13 4 6 82\n", "output": "-1"}, {"input": "5 3 17 56\n", "output": "-1"}, {"input": "38 5 29 90\n", "output": "-1"}, {"input": "22 36 18 55\n", "output": "15"}, {"input": "13 0 19 75\n", "output": "-1"}, {"input": "62 65 10 89\n", "output": "-1"}, {"input": "2 29 31 72\n", "output": "-1"}, {"input": "1 31 19 55\n", "output": "-1"}, {"input": "1 25 28 88\n", "output": "-1"}, {"input": "34 32 28 33\n", "output": "-1"}, {"input": "43 36 1 100\n", "output": "22"}, {"input": "16 39 55 70\n", "output": "-1"}, {"input": "2 3 0 91\n", "output": "86"}, {"input": "55 29 12 48\n", "output": "-1"}, {"input": "7 33 20 88\n", "output": "-1"}, {"input": "40 38 27 99\n", "output": "48"}, {"input": "18 28 14 84\n", "output": "52"}, {"input": "34 25 25 92\n", "output": "58"}, {"input": "4 24 5 76\n", "output": "-1"}, {"input": "5 22 16 96\n", "output": "-1"}, {"input": "1 1 0 4\n", "output": "2"}, {"input": "5 5 3 1\n", "output": "-1"}, {"input": "0 0 0 1\n", "output": "1"}, {"input": "2 3 0 8\n", "output": "3"}, {"input": "5 5 2 5\n", "output": "-1"}, {"input": "1 2 1 3\n", "output": "1"}, {"input": "3 0 0 4\n", "output": "1"}, {"input": "0 0 0 5\n", "output": "5"}, {"input": "5 5 0 3\n", "output": "-1"}, {"input": "5 6 1 7\n", "output": "-1"}, {"input": "10 10 10 11\n", "output": "1"}, {"input": "0 0 0 10\n", "output": "10"}, {"input": "5 15 5 30\n", "output": "15"}, {"input": "3 2 0 7\n", "output": "2"}] |
|
196 | Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month).
Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year.
Nastya owns x dresses now, so she became interested in the expected number of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months.
Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 10^9 + 7, because it is easy to see that it is always integer.
-----Input-----
The only line contains two integers x and k (0 ≤ x, k ≤ 10^18), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland.
-----Output-----
In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 10^9 + 7.
-----Examples-----
Input
2 0
Output
4
Input
2 1
Output
7
Input
3 2
Output
21
-----Note-----
In the first example a year consists on only one month, so the wardrobe does not eat dresses at all.
In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7. | interview | [{"code": "x, k = map(int, input().split())\nif x == 0:\n print(0)\nelse:\n mod = 10 ** 9 + 7\n p = pow(2, k, mod)\n ans = (x * (p * 2) - (p - 1)) % mod\n print(ans)", "passed": true, "time": 0.24, "memory": 14576.0, "status": "done"}, {"code": "mod = 10**9+7\nx, k = list(map(int, input().split(' ')))\nif (x == 0):\n print(0)\nelse:\n val1 = pow(2,k+1,mod) * x\n val2 = pow(2, k, mod) - 1\n val1 -= val2\n val1 %= mod\n print(val1)\n", "passed": true, "time": 0.24, "memory": 14532.0, "status": "done"}, {"code": "\n\nx,k = map(int, input().strip().split())\n\nMOD = 1000000007\n\nif x > 0:\n\tr = (pow(2, k+1, MOD) * x - pow(2, k, MOD) + 1 + MOD * 10) % MOD\nelse:\n\tr = 0\n\nprint(r)", "passed": true, "time": 1.83, "memory": 14344.0, "status": "done"}, {"code": "from sys import stdin\n\nline = stdin.readline().rstrip().split()\nx = int(line[0])\nk = int(line[1])\n\nif x == 0:\n print(0)\nelse:\n nn = pow(2, k, 1000000007)\n result = (nn*2*x - nn + 1) % 1000000007\n print(result)\n\n\n\n", "passed": true, "time": 2.11, "memory": 14384.0, "status": "done"}, {"code": "l = input().split(' ')\nx = int(l[0])\nk = int(l[1])\n\nif x == 0:\n print('0')\nelse:\n mod = 1000000007\n\n def pow_mod(a, b):\n if b < 2:\n return int(a ** b) % mod\n elif b % 2 == 0:\n return int(pow_mod(a, b // 2) ** 2) % mod\n else:\n return pow_mod(a, b - 1) * a % mod\n\n twop = pow_mod(2, k)\n high = x * twop\n leafs = twop\n low = high - leafs + 1\n s = (high + 1) * high // 2 - (low - 1 + 1) * (low - 1) // 2\n answer = s * 2 // leafs\n answer %= mod\n\n print(answer)", "passed": true, "time": 0.15, "memory": 14512.0, "status": "done"}, {"code": "x, k = map(int, input().split())\nans = 0\nmd = 1000000007\n\ndef bpow(base, exp, md):\n if (exp == 0):\n return 1\n if (exp % 2 == 1):\n return (base * bpow(base, exp-1, md)) % md\n else:\n k = bpow(base, exp//2, md)\n return (k*k) % md\n\npw = bpow(2, k, md)\nans = (2 * pw * x) % md\nif (x != 0):\n ans -= pw-1\nans = (ans + md) % md\nprint(ans)", "passed": true, "time": 2.14, "memory": 14504.0, "status": "done"}, {"code": "x, k = list(map(int, input().split()))\nif x == 0:\n print(0)\n return\nx = 2 * x - 1\nmod = 10**9 + 7\n\ndef pot(r, k):\n if k == 0: return 1\n if k % 2 == 1:\n return r * pot(r, k - 1) % mod\n y = pot(r, k // 2)\n return y * y % mod\n\nprint((pot(2, k) * x + 1) % mod)\n", "passed": true, "time": 0.14, "memory": 14364.0, "status": "done"}, {"code": "mod = 1000000007\nx, k = map(int, input().split())\nif x == 0:\n print(0)\nelse:\n ans = (pow(2, k + 1, mod) * x % mod - (pow(2, k, mod) - 1 + mod) % mod + mod) % mod\n print(ans)", "passed": true, "time": 0.14, "memory": 14588.0, "status": "done"}, {"code": "x, k = map(int, input().split())\nif x == 0:\n print(0)\n return\nres = pow(2, k + 1, 10 ** 9 + 7) * x - pow(2, k, 10 ** 9 + 7) + 1\nres %= 10 ** 9 + 7\nprint(res)", "passed": true, "time": 0.14, "memory": 14512.0, "status": "done"}, {"code": "x, k = map(int, input().split())\nmod = 1000000007\nflag = True\nif x==0:\n\tflag = False\n\nx = x%mod\ny = pow(2, k+1, mod)\nz = pow(2, k, mod) - 1\n\nx = x*y\nx = x%mod\nx = x-z\nif x==0:\n\tx=x+mod\nx = x%mod\n\nif flag:\n\tprint(x)\nelse:\n\tprint(0)", "passed": true, "time": 0.16, "memory": 14584.0, "status": "done"}, {"code": "x,k = list(map(int, input().split()))\nmod = 10 ** 9 + 7\nprint(0 if x == 0 else (x * pow(2, k + 1, mod) - pow(2, k, mod) + 1 + mod) % mod)\n", "passed": true, "time": 1.95, "memory": 14516.0, "status": "done"}, {"code": "x, k = list(map(int, input().split()))\nmod = 1000000007\nif (k == 0):\n print((2 * x) % mod)\nelif (x == 0):\n print(0)\nelse:\n ans = ((2 * x - 1) * pow(2, k, mod) + 1) % mod\n print(ans)\n", "passed": true, "time": 0.14, "memory": 14492.0, "status": "done"}, {"code": "x, k = map(int, input().split())\n\nmod = 10**9+7\n\ndef bp(n,p):\n if p == 0:\n return 1\n elif p % 2 == 0:\n return bp(n**2 % mod, p // 2)\n else:\n return (bp(n**2 % mod, p // 2) * n) % mod\n\ndef f(n,x):\n return (bp(2,n) * x - bp(2,n) + 1) % mod\n\nif x > 0:\n print(f(k,2*x) % mod)\nelse:\n print(0)", "passed": true, "time": 0.15, "memory": 14592.0, "status": "done"}, {"code": "def pwr(a,n,m):\n if n==0:return 1\n ans=pwr(a,n//2,m)\n ans=ans*ans\n ans%=m\n if n%2==1:return (ans*a)%m\n else: return ans\nM=1000000007\ntx,tn=input().split()\nx=int(tx)\nn=int(tn)\nans=pwr(2,n+1,M)*x\nans%=M\nans=ans-pwr(2,n,M)+1\nans=(ans+M)%M\nif x==0: ans=0\nprint(ans)\n", "passed": true, "time": 1.88, "memory": 14376.0, "status": "done"}, {"code": "# Codeforces Round #489 (Div. 2)\nimport collections\nfrom functools import cmp_to_key\n#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )\n\nimport sys\ndef getIntList():\n return list(map(int, input().split())) \n\nimport bisect \n \nbase = 10**9 + 7 \ndef get2k(k) :\n f = 2\n b = 1\n r = 1\n while k>=b:\n if k &b >0:\n r = r*f % base\n b*=2\n f = f*f % base\n return r\n\nx, k = getIntList()\nif x ==0:\n print(0)\n return\nt2k = get2k(k)\n\nr = x * t2k *2 - t2k + 1\nr = r% base\nprint(r)\n\n", "passed": true, "time": 0.14, "memory": 14588.0, "status": "done"}, {"code": "x, k = [int(x) for x in input().split()]\n\nif x == 0:\n print(0)\n return\n\nmod = 10 ** 9 + 7\n\nres = x * pow(2, k + 1, mod) % mod\nres = ((res - (pow(2, k, mod) - 1)) % mod + mod) % mod\n\nprint(res)\n", "passed": true, "time": 0.26, "memory": 14548.0, "status": "done"}, {"code": "def my_pow(a, n, m):\n\tif (n == 0) : return 1\n\tans = my_pow(a, n // 2, m)\n\tif (n % 2 == 0):\n\t\treturn ans * ans % m\n\telse:\n\t\treturn (ans * ans * a) % m\n\nx, k = map(int, input().split())\nif (x == 0):\n\tprint(0)\nelse:\n\tmod = 10**9 + 7\n\tx *= 2\n\tans = (x - 1) * my_pow(2, k, mod) + 1\n\tans %= mod\n\tans += 2 * mod\n\tprint(ans % mod)", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "def binPow(x, n, r):\n\tif n == 0:\n\t\treturn 1\n\telif n == 1:\n\t\treturn x % r\n\tif n % 2 == 0:\n\t\treturn binPow((x * x) % r, n // 2, r)\n\treturn (binPow((x * x) % r, n // 2, r) * x) % r\n\nx, k = list(map(int, input().split()))\nr = 10 ** 9 + 7\nif x == 0:\n\tprint(0)\n\treturn\nelif k == 0:\n\tprint((x * 2) % r)\n\treturn\nprint((binPow(2, k, r) * (2 * x - 1) + 1) % r)\n", "passed": true, "time": 0.15, "memory": 14604.0, "status": "done"}, {"code": "MOD = 1000*1000*1000+7\n\ndef pow(x,e,m):\n res = 1\n x = x % m\n\n while e>0:\n if(e % 2 == 1):\n res = (res*x) % m\n\n e = e//2\n x = (x*x) % m\n\n return res\n\nx, k = map(int, input().split(' '))\n\n\nif x == 0:\n print(0)\n\nelse:\n myres = (pow(2,k,MOD)*(2*x-1) + 1) % MOD\n print(myres)", "passed": true, "time": 0.14, "memory": 14508.0, "status": "done"}, {"code": "x,k = list(map(int,input().split()))\nmod = 10**9 + 7\nif x == 0:\n print(0)\nelse:\n print(((2*x-1)*pow(2,k,mod) + 1)%mod)\n", "passed": true, "time": 0.15, "memory": 14572.0, "status": "done"}, {"code": "def powermod(base, power):\n if power == 0: return 1\n if power == 1: return base\n ret = powermod(base, power // 2)\n ret *= ret\n ret %= 1000000007\n if power % 2 == 1:\n ret *= base\n ret %= 1000000007\n return ret\n\nx, k = list(map(int, input().split()))\n\nb = x * 2 - 1\nans = b * powermod(2, k) + 1\nans %= 1000000007\n\nif x == 0: ans = 0\nprint (ans)\n", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\n\nmod = 10**9 + 7\n\n\n[x, k] = list(map(int, input().strip().split()))\n\nif x == 0:\n\tprint(0)\n\treturn\n\n\ndef pow2(n):\n\tif n == 0:\n\t\treturn 1\n\tif n % 2 == 0:\n\t\treturn (pow2(n // 2) ** 2) % mod\n\telse:\n\t\treturn (((pow2(n // 2) ** 2) % mod) * 2) % mod\n\nprint((pow2(k) * ((2 * x - 1) % mod) + 1) % mod)\n", "passed": true, "time": 0.14, "memory": 14540.0, "status": "done"}, {"code": "mod=1000000007\ndef fastexp(base,exp):\n if(exp==0):\n return 1;\n if(exp==1):\n return base%mod;\n t=fastexp(base,exp//2);\n if(exp%2==0):\n return (t%mod*t%mod)%mod;\n else:\n return (t%mod*t%mod*base%mod)%mod;\nx,k=list(map(int,input().split()))\nif(x==0):\n print((0));\nelse:\n t=fastexp(2,k)%mod;\n before=((2*t)%mod*x%mod)%mod-(t+mod-1)%mod\n while(before<0):\n before+=mod;\n before=before%mod;\n print(before)\n", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "x, k = [int(v) for v in input().split()]\nmod = 10**9 + 7\n\nif x == 0:\n print(0)\nelse:\n print(((pow(2, k + 1, mod) * x) - (pow(2, k, mod) - 1)) % mod)\n", "passed": true, "time": 0.15, "memory": 14568.0, "status": "done"}] | [{"input": "2 0\n", "output": "4\n"}, {"input": "2 1\n", "output": "7\n"}, {"input": "3 2\n", "output": "21\n"}, {"input": "1 411\n", "output": "485514976\n"}, {"input": "1 692\n", "output": "860080936\n"}, {"input": "16 8\n", "output": "7937\n"}, {"input": "18 12\n", "output": "143361\n"}, {"input": "1 1000000000000000000\n", "output": "719476261\n"}, {"input": "0 24\n", "output": "0\n"}, {"input": "24 0\n", "output": "48\n"}, {"input": "1000000000000000000 1\n", "output": "195\n"}, {"input": "348612312017571993 87570063840727716\n", "output": "551271547\n"}, {"input": "314647997243943415 107188213956410843\n", "output": "109575135\n"}, {"input": "375000003 2\n", "output": "0\n"}, {"input": "451 938\n", "output": "598946958\n"}, {"input": "4 1669\n", "output": "185365669\n"}, {"input": "24 347\n", "output": "860029201\n"}, {"input": "1619 1813\n", "output": "481568710\n"}, {"input": "280 472\n", "output": "632090765\n"}, {"input": "1271 237\n", "output": "27878991\n"}, {"input": "626 560\n", "output": "399405853\n"}, {"input": "167 887\n", "output": "983959273\n"}, {"input": "1769 422\n", "output": "698926874\n"}, {"input": "160 929\n", "output": "752935252\n"}, {"input": "1075 274\n", "output": "476211777\n"}, {"input": "1332 332\n", "output": "47520583\n"}, {"input": "103872254428948073 97291596742897547\n", "output": "283633261\n"}, {"input": "157600018563121064 54027847222622605\n", "output": "166795759\n"}, {"input": "514028642164226185 95344332761644668\n", "output": "718282571\n"}, {"input": "91859547444219924 75483775868568438\n", "output": "462306789\n"}, {"input": "295961633522750187 84483303945499729\n", "output": "11464805\n"}, {"input": "8814960236468055 86463151557693391\n", "output": "430718856\n"}, {"input": "672751296745170589 13026894786355983\n", "output": "260355651\n"}, {"input": "909771081413191574 18862935031728197\n", "output": "800873185\n"}, {"input": "883717267463724670 29585639347346605\n", "output": "188389362\n"}, {"input": "431620727626880523 47616788361847228\n", "output": "311078131\n"}, {"input": "816689044159694273 6475970360049048\n", "output": "211796030\n"}, {"input": "313779810374175108 13838123840048842\n", "output": "438854949\n"}, {"input": "860936792402722414 59551033597232946\n", "output": "359730003\n"}, {"input": "332382902893992163 15483141652464187\n", "output": "719128379\n"}, {"input": "225761360057436129 49203610094504526\n", "output": "54291755\n"}, {"input": "216006901533424028 8313457244750219\n", "output": "362896012\n"}, {"input": "568001660010321225 97167523790774710\n", "output": "907490480\n"}, {"input": "904089164817530426 53747406876903279\n", "output": "702270335\n"}, {"input": "647858974461637674 18385058205826214\n", "output": "375141527\n"}, {"input": "720433754707338458 94180351080265292\n", "output": "273505123\n"}, {"input": "268086842387268316 76502855388264782\n", "output": "288717798\n"}, {"input": "488603693655520686 79239542983498430\n", "output": "316399174\n"}, {"input": "152455635055802121 50394545488662355\n", "output": "697051907\n"}, {"input": "585664029992038779 34972826534657555\n", "output": "699566354\n"}, {"input": "349532090641396787 12248820623854158\n", "output": "233938854\n"}, {"input": "353579407209009179 74469254935824590\n", "output": "771349161\n"}, {"input": "491414900908765740 49509676303815755\n", "output": "237095803\n"}, {"input": "91142854626119420 900651524977956\n", "output": "211575546\n"}, {"input": "73543340229981083 66918326344192076\n", "output": "710215652\n"}, {"input": "463958371369193376 89203995753927042\n", "output": "41857490\n"}, {"input": "911873413622533246 54684577459651780\n", "output": "926432198\n"}, {"input": "316313018463929883 78259904441946885\n", "output": "36284201\n"}, {"input": "889560480100219043 54181377424922141\n", "output": "281123162\n"}, {"input": "0 3259862395629356\n", "output": "0\n"}, {"input": "1 3\n", "output": "9\n"}, {"input": "3 1\n", "output": "11\n"}, {"input": "1000000007 1\n", "output": "1000000006\n"}, {"input": "1000000007 2\n", "output": "1000000004\n"}, {"input": "1000000007 0\n", "output": "0\n"}, {"input": "1000000007 12\n", "output": "999995912\n"}, {"input": "1000000007 70\n", "output": "729983755\n"}, {"input": "250000002 1\n", "output": "0\n"}, {"input": "1000000007 3\n", "output": "1000000000\n"}, {"input": "999999999 0\n", "output": "999999991\n"}, {"input": "1000000007 5\n", "output": "999999976\n"}, {"input": "1000000007 1000000007\n", "output": "1000000006\n"}, {"input": "10000000000000000 0\n", "output": "860000007\n"}, {"input": "1000000000000 0\n", "output": "999986007\n"}, {"input": "99999999999999999 0\n", "output": "600000012\n"}, {"input": "1000000000000000 0\n", "output": "986000007\n"}] |
|
197 | An online contest will soon be held on ForceCoders, a large competitive programming platform. The authors have prepared $n$ problems; and since the platform is very popular, $998244351$ coder from all over the world is going to solve them.
For each problem, the authors estimated the number of people who would solve it: for the $i$-th problem, the number of accepted solutions will be between $l_i$ and $r_i$, inclusive.
The creator of ForceCoders uses different criteria to determine if the contest is good or bad. One of these criteria is the number of inversions in the problem order. An inversion is a pair of problems $(x, y)$ such that $x$ is located earlier in the contest ($x < y$), but the number of accepted solutions for $y$ is strictly greater.
Obviously, both the creator of ForceCoders and the authors of the contest want the contest to be good. Now they want to calculate the probability that there will be no inversions in the problem order, assuming that for each problem $i$, any integral number of accepted solutions for it (between $l_i$ and $r_i$) is equally probable, and all these numbers are independent.
-----Input-----
The first line contains one integer $n$ ($2 \le n \le 50$) — the number of problems in the contest.
Then $n$ lines follow, the $i$-th line contains two integers $l_i$ and $r_i$ ($0 \le l_i \le r_i \le 998244351$) — the minimum and maximum number of accepted solutions for the $i$-th problem, respectively.
-----Output-----
The probability that there will be no inversions in the contest can be expressed as an irreducible fraction $\frac{x}{y}$, where $y$ is coprime with $998244353$. Print one integer — the value of $xy^{-1}$, taken modulo $998244353$, where $y^{-1}$ is an integer such that $yy^{-1} \equiv 1$ $(mod$ $998244353)$.
-----Examples-----
Input
3
1 2
1 2
1 2
Output
499122177
Input
2
42 1337
13 420
Output
578894053
Input
2
1 1
0 0
Output
1
Input
2
1 1
1 1
Output
1
-----Note-----
The real answer in the first test is $\frac{1}{2}$. | interview | [{"code": "from bisect import bisect_left\n\nM = 998244353\n\ndef pw(x, y):\n if y == 0:\n return 1\n res = pw(x, y//2)\n res = res * res % M\n if y % 2 == 1:\n res = res * x % M\n return res\n\ndef cal(x, y):\n y += x - 1\n res = 1\n for i in range(1, x + 1):\n res = res * (y - i + 1)\n res = res * pw(i, M - 2) % M\n return res % M\n\nn = int(input())\na = []\nb = []\nres = 1\nfor i in range(n):\n a.append(list(map(int, input().split())))\n res = res * (a[-1][1] + 1 - a[-1][0]) % M\n b.append(a[-1][0])\n b.append(a[-1][1] + 1)\n b = set(b)\n b = sorted(list(b))\n\ng = [b[i + 1] - b[i] for i in range(len(b) - 1)]\n\nfor i in range(n):\n a[i][0] = bisect_left(b, a[i][0])\n a[i][1] = bisect_left(b, a[i][1] + 1)\n\na = a[::-1]\n\nf = [[0 for _ in range(len(b))] for __ in range(n)]\n\nfor i in range(a[0][0], len(b)):\n if i == 0:\n f[0][i] = g[i]\n else:\n if i < a[0][1]:\n f[0][i] = (f[0][i - 1] + g[i]) % M\n else:\n f[0][i] = f[0][i - 1]\n \nfor i in range(1, n):\n for j in range(a[i][0], len(b)):\n if j > 0:\n f[i][j] = f[i][j - 1]\n if j < a[i][1]:\n for k in range(i, -1, -1):\n if a[k][1] <= j or j < a[k][0]:\n break\n if k == 0 or j != 0:\n tmp = cal(i - k + 1, g[j])\n if k > 0:\n f[i][j] += f[k - 1][j - 1] * tmp % M\n else:\n f[i][j] += tmp\n f[i][j] %= M\n \n#print(f)\n#print(f[n - 1][len(b) - 1], res)\nprint(f[n - 1][len(b) - 1] * pw(res, M - 2) % M)\n", "passed": true, "time": 1.11, "memory": 14744.0, "status": "done"}, {"code": "from bisect import bisect_left\n\nM = 998244353\n\ndef pw(x, y):\n if y == 0:\n return 1\n res = pw(x, y//2)\n res = res * res % M\n if y % 2 == 1:\n res = res * x % M\n return res\n\ndef cal(x, y):\n y += x - 1\n res = 1\n for i in range(1, x + 1):\n res = res * (y - i + 1)\n res = res * pw(i, M - 2) % M\n return res % M\n\nn = int(input())\na = []\nb = []\nres = 1\nfor i in range(n):\n a.append(list(map(int, input().split())))\n res = res * (a[-1][1] + 1 - a[-1][0]) % M\n b.append(a[-1][0])\n b.append(a[-1][1] + 1)\n b = set(b)\n b = sorted(list(b))\n\ng = [b[i + 1] - b[i] for i in range(len(b) - 1)]\n\nfor i in range(n):\n a[i][0] = bisect_left(b, a[i][0])\n a[i][1] = bisect_left(b, a[i][1] + 1)\n\na = a[::-1]\n\nf = [[0 for _ in range(len(b))] for __ in range(n)]\n\nfor i in range(a[0][0], len(b)):\n if i == 0:\n f[0][i] = g[i]\n else:\n if i < a[0][1]:\n f[0][i] = (f[0][i - 1] + g[i]) % M\n else:\n f[0][i] = f[0][i - 1]\n \nfor i in range(1, n):\n for j in range(a[i][0], len(b)):\n if j > 0:\n f[i][j] = f[i][j - 1]\n if j < a[i][1]:\n for k in range(i, -1, -1):\n if a[k][1] <= j or j < a[k][0]:\n break\n if k == 0 or j != 0:\n tmp = cal(i - k + 1, g[j])\n if k > 0:\n f[i][j] += f[k - 1][j - 1] * tmp % M\n else:\n f[i][j] += tmp\n f[i][j] %= M\n \n#print(f)\n#print(f[n - 1][len(b) - 1], res)\nprint(f[n - 1][len(b) - 1] * pw(res, M - 2) % M)\n", "passed": true, "time": 1.07, "memory": 14656.0, "status": "done"}, {"code": "import sys\nfrom itertools import chain\nreadline = sys.stdin.readline\n\nMOD = 998244353\ndef compress(L):\n L2 = list(set(L))\n L2.sort()\n C = {v : k for k, v in enumerate(L2)}\n return L2, C\n\n\nN = int(readline())\nLR = [tuple(map(int, readline().split())) for _ in range(N)]\nLR = [(a-1, b) for a, b in LR]\nLR2 = LR[:]\nml = LR[-1][0]\nres = 0\nfor i in range(N-2, -1, -1):\n l, r = LR[i]\n if r <= ml:\n break\n l = max(ml, l)\n ml = l\n LR[i] = (l, r)\nelse:\n Z = list(chain(*LR))\n Z2, Dc = compress(Z)\n \n NN = len(Z2)\n seglen = [0] + [n - p for p, n in zip(Z2, Z2[1:])]\n \n hc = [[0]*(N+3) for _ in range(NN)]\n for j in range(NN):\n hc[j][0] = 1\n for k in range(1, N+3):\n hc[j][k] = hc[j][k-1]*pow(k, MOD-2, MOD)*(seglen[j]-1+k)%MOD\n\n mask = [[[True]*NN]]\n\n dp = [[[0]*(N+1) for _ in range(NN+1)] for _ in range(N+1)]\n Dp = [[1]*(NN+1)] + [[0]*(NN+1) for _ in range(N)]\n for i in range(1, N+1):\n mask2 = [False]*NN\n l, r = LR[i-1]\n dl, dr = Dc[l], Dc[r]\n for j in range(dr, dl, -1):\n mask2[j] = True\n mm = [[m1&m2 for m1, m2 in zip(mask[-1][idx], mask2)] for idx in range(i)] + [mask2]\n mask.append(mm)\n for j in range(NN):\n for k in range(1, i+1):\n if mask[i][i-k+1][j]:\n dp[i][j][k] = Dp[i-k][j+1]*hc[j][k]%MOD\n \n for j in range(NN-1, -1, -1):\n res = Dp[i][j+1]\n if dl < j <= dr:\n for k in range(1, i+1): \n res = (res + dp[i][j][k])%MOD\n Dp[i][j] = res\n \n res = Dp[N][0]\n for l, r in LR2:\n res = res*(pow(r-l, MOD-2, MOD))%MOD\nprint(res)\n\n", "passed": true, "time": 0.18, "memory": 15236.0, "status": "done"}, {"code": "from bisect import bisect_left\n \nM = 998244353\n \ndef pw(x, y):\n if y == 0:\n return 1\n res = pw(x, y//2)\n res = res * res % M\n if y % 2 == 1:\n res = res * x % M\n return res\n \ndef cal(x, y):\n y += x - 1\n res = 1\n for i in range(1, x + 1):\n res = res * (y - i + 1)\n res = res * pw(i, M - 2) % M\n return res % M\n \nn = int(input())\na = []\nb = []\nres = 1\nfor i in range(n):\n a.append(list(map(int, input().split())))\n res = res * (a[-1][1] + 1 - a[-1][0]) % M\n b.append(a[-1][0])\n b.append(a[-1][1] + 1)\n b = set(b)\n b = sorted(list(b))\n \ng = [b[i + 1] - b[i] for i in range(len(b) - 1)]\n \nfor i in range(n):\n a[i][0] = bisect_left(b, a[i][0])\n a[i][1] = bisect_left(b, a[i][1] + 1)\n \na = a[::-1]\n \nf = [[0 for _ in range(len(b))] for __ in range(n)]\n \nfor i in range(a[0][0], len(b)):\n if i == 0:\n f[0][i] = g[i]\n else:\n if i < a[0][1]:\n f[0][i] = (f[0][i - 1] + g[i]) % M\n else:\n f[0][i] = f[0][i - 1]\n \nfor i in range(1, n):\n for j in range(a[i][0], len(b)):\n if j > 0:\n f[i][j] = f[i][j - 1]\n if j < a[i][1]:\n for k in range(i, -1, -1):\n if a[k][1] <= j or j < a[k][0]:\n break\n if k == 0 or j != 0:\n tmp = cal(i - k + 1, g[j])\n if k > 0:\n f[i][j] += f[k - 1][j - 1] * tmp % M\n else:\n f[i][j] += tmp\n f[i][j] %= M\n \n#print(f)\n#print(f[n - 1][len(b) - 1], res)\nprint(f[n - 1][len(b) - 1] * pw(res, M - 2) % M)", "passed": true, "time": 1.07, "memory": 14640.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\nmod=998244353\nn=int(input())\nLR=[list(map(int,input().split())) for i in range(n)]\nRMIN=1<<31\n\nALL=1\nfor l,r in LR:\n ALL=ALL*pow(r-l+1,mod-2,mod)%mod\n\nfor i in range(n):\n if LR[i][1]>RMIN:\n LR[i][1]=RMIN\n RMIN=min(RMIN,LR[i][1])\n\nLMAX=-1\nfor i in range(n-1,-1,-1):\n if LR[i][0]<LMAX:\n LR[i][0]=LMAX\n LMAX=max(LMAX,LR[i][0])\n\ncompression=[]\nfor l,r in LR:\n compression.append(l)\n compression.append(r+1)\n\ncompression=sorted(set(compression))\nco_dict={a:ind for ind,a in enumerate(compression)}\n\nLEN=len(compression)-1\n\nif LEN==0:\n print(0)\n return\n\nDP=[[0]*LEN for i in range(n)]\n\nfor i in range(co_dict[LR[0][0]],co_dict[LR[0][1]+1]):\n x=compression[i+1]-compression[i]\n now=x\n #print(i,x)\n for j in range(n):\n if LR[j][0]<=compression[i] and LR[j][1]+1>=compression[i+1]:\n DP[j][i]=now\n else:\n break\n now=now*(x+j+1)*pow(j+2,mod-2,mod)%mod\n\n#print(DP)\n\nfor i in range(1,n):\n SUM=DP[i-1][LEN-1]\n #print(DP)\n for j in range(LEN-2,-1,-1):\n if LR[i][0]<=compression[j] and LR[i][1]+1>=compression[j+1]:\n x=SUM*(compression[j+1]-compression[j])%mod\n now=x\n t=compression[j+1]-compression[j]\n #print(x,t)\n\n for k in range(i,n):\n \n if LR[k][0]<=compression[j] and LR[k][1]+1>=compression[j+1]:\n DP[k][j]=(DP[k][j]+now)%mod\n else:\n break\n now=now*(t+k-i+1)*pow(k-i+2,mod-2,mod)%mod\n \n \n SUM+=DP[i-1][j]\n\nprint(sum(DP[-1])*ALL%mod)\n\n \n \n \n", "passed": true, "time": 0.16, "memory": 14756.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\nmod=998244353\nn=int(input())\nLR=[list(map(int,input().split())) for i in range(n)]\nRMIN=1<<31\n\nALL=1\nfor l,r in LR:\n ALL=ALL*pow(r-l+1,mod-2,mod)%mod\n\nfor i in range(n):\n if LR[i][1]>RMIN:\n LR[i][1]=RMIN\n RMIN=min(RMIN,LR[i][1])\n\nLMAX=-1\nfor i in range(n-1,-1,-1):\n if LR[i][0]<LMAX:\n LR[i][0]=LMAX\n LMAX=max(LMAX,LR[i][0])\n\ncompression=[]\nfor l,r in LR:\n compression.append(l)\n compression.append(r+1)\n\ncompression=sorted(set(compression))\nco_dict={a:ind for ind,a in enumerate(compression)}\n\nLEN=len(compression)-1\n\nif LEN==0:\n print(0)\n return\n\nDP=[[0]*LEN for i in range(n)]\n\nfor i in range(co_dict[LR[0][0]],co_dict[LR[0][1]+1]):\n x=compression[i+1]-compression[i]\n now=x\n #print(i,x)\n for j in range(n):\n if LR[j][0]<=compression[i] and LR[j][1]+1>=compression[i+1]:\n DP[j][i]=now\n else:\n break\n now=now*(x+j+1)*pow(j+2,mod-2,mod)%mod\n\n#print(DP)\n\nfor i in range(1,n):\n SUM=DP[i-1][LEN-1]\n #print(DP)\n for j in range(LEN-2,-1,-1):\n if LR[i][0]<=compression[j] and LR[i][1]+1>=compression[j+1]:\n x=SUM*(compression[j+1]-compression[j])%mod\n now=x\n t=compression[j+1]-compression[j]\n #print(x,t)\n\n for k in range(i,n):\n \n if LR[k][0]<=compression[j] and LR[k][1]+1>=compression[j+1]:\n DP[k][j]=(DP[k][j]+now)%mod\n else:\n break\n now=now*(t+k-i+1)*pow(k-i+2,mod-2,mod)%mod\n \n \n SUM+=DP[i-1][j]\n\nprint(sum(DP[-1])*ALL%mod)\n\n \n \n \n", "passed": true, "time": 0.16, "memory": 14612.0, "status": "done"}] | [{"input": "3\n1 2\n1 2\n1 2\n", "output": "499122177\n"}, {"input": "2\n42 1337\n13 420\n", "output": "578894053\n"}, {"input": "2\n1 1\n0 0\n", "output": "1\n"}, {"input": "2\n1 1\n1 1\n", "output": "1\n"}, {"input": "2\n1 1\n0 1\n", "output": "1\n"}, {"input": "2\n0 1\n0 1\n", "output": "249561089\n"}, {"input": "2\n0 0\n0 1\n", "output": "499122177\n"}, {"input": "2\n0 0\n0 1\n", "output": "499122177\n"}, {"input": "2\n0 0\n0 1\n", "output": "499122177\n"}, {"input": "2\n0 1\n1 1\n", "output": "499122177\n"}, {"input": "2\n10 34\n17 26\n", "output": "818560370\n"}, {"input": "2\n12 19\n39 69\n", "output": "0\n"}, {"input": "2\n25 29\n29 78\n", "output": "930363737\n"}, {"input": "2\n3 38\n52 99\n", "output": "0\n"}, {"input": "2\n14 49\n41 52\n", "output": "228764331\n"}, {"input": "2\n21 93\n15 70\n", "output": "982860451\n"}, {"input": "2\n1378 72243\n23169 96615\n", "output": "872616547\n"}, {"input": "2\n6509 18946\n66363 93596\n", "output": "0\n"}, {"input": "2\n40776 60862\n20449 79682\n", "output": "447250007\n"}, {"input": "2\n50696 78430\n1009 98884\n", "output": "161808275\n"}, {"input": "2\n84964 95998\n22337 77318\n", "output": "1\n"}, {"input": "2\n38680 95906\n66084 96498\n", "output": "116346445\n"}, {"input": "2\n86080945 900334037\n283817560 816700236\n", "output": "990443786\n"}, {"input": "2\n105001489 202733825\n260379286 951276926\n", "output": "0\n"}, {"input": "2\n727901809 780202030\n645657763 702302687\n", "output": "1\n"}, {"input": "2\n359425882 746822353\n38048713 724795689\n", "output": "25745160\n"}, {"input": "2\n240639622 765742897\n470464627 730673903\n", "output": "515321057\n"}, {"input": "2\n754872424 926908966\n219572916 995287694\n", "output": "555664178\n"}, {"input": "10\n0 1\n0 1\n0 0\n0 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 1\n", "output": "0\n"}, {"input": "10\n0 1\n0 0\n1 1\n0 1\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n", "output": "0\n"}, {"input": "10\n1 1\n0 1\n0 1\n0 1\n1 1\n0 1\n0 1\n1 1\n0 1\n0 1\n", "output": "974848001\n"}, {"input": "10\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n1 1\n0 0\n1 1\n0 0\n", "output": "0\n"}, {"input": "10\n1 1\n1 1\n0 1\n0 1\n0 1\n1 1\n0 0\n1 1\n0 1\n0 1\n", "output": "0\n"}, {"input": "10\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n", "output": "987521025\n"}, {"input": "10\n41 52\n82 97\n37 76\n42 82\n91 97\n6 94\n29 96\n3 76\n60 91\n16 60\n", "output": "0\n"}, {"input": "10\n30 83\n2 19\n50 93\n27 36\n82 88\n39 95\n4 97\n23 75\n37 53\n15 69\n", "output": "0\n"}, {"input": "10\n48 76\n12 20\n24 36\n54 72\n30 79\n5 74\n55 80\n54 85\n60 91\n20 59\n", "output": "0\n"}, {"input": "10\n54 58\n42 65\n77 92\n27 37\n2 21\n38 85\n88 89\n74 84\n0 56\n4 47\n", "output": "0\n"}, {"input": "10\n67 67\n32 75\n2 51\n4 88\n62 80\n37 97\n46 64\n4 83\n53 54\n2 56\n", "output": "0\n"}, {"input": "10\n0 85\n0 14\n0 65\n0 76\n0 56\n0 23\n0 34\n0 24\n0 68\n0 13\n", "output": "159813282\n"}, {"input": "10\n2139 77689\n7692 31588\n39321 54942\n48988 55097\n46970 54864\n61632 70126\n4240 37374\n69600 79133\n69308 91118\n12408 56672\n", "output": "0\n"}, {"input": "10\n11955 30601\n10022 29020\n67511 97636\n6159 48409\n24834 39598\n66437 72414\n7968 12307\n20918 83151\n50739 85006\n6049 71253\n", "output": "0\n"}, {"input": "10\n21875 48170\n26001 64110\n71355 99916\n41721 52438\n2697 24332\n49294 58850\n27652 76457\n51810 61461\n25049 34708\n5750 31079\n", "output": "0\n"}, {"input": "10\n56142 90085\n7302 12087\n77850 86092\n35033 58303\n4908 9066\n20938 45605\n20597 78238\n69249 75012\n5506 59089\n15697 64595\n", "output": "0\n"}, {"input": "10\n7652 90409\n33415 61390\n20543 89936\n28345 80234\n7118 93802\n7374 17569\n17929 89085\n140 88563\n43057 45550\n40728 74746\n", "output": "0\n"}, {"input": "10\n25823 99883\n48624 99584\n52672 99474\n10956 99906\n56493 99804\n38589 99933\n63666 99555\n65591 99572\n8450 99921\n42834 99917\n", "output": "367159257\n"}, {"input": "10\n435368449 906834606\n329478288 810620704\n337438370 425488467\n261210437 952223320\n489526021 754503172\n826073281 936684995\n270748702 993400655\n175130673 281932203\n585827654 710872711\n22140424 777277629\n", "output": "0\n"}, {"input": "10\n14592301 925755150\n49981402 203011654\n452726617 976821979\n467112999 945037753\n260612539 372077071\n530976641 871876506\n154188384 306542825\n926936004 982826136\n52360908 432533746\n516279982 585592522\n", "output": "0\n"}, {"input": "10\n550411118 894050393\n174216555 793894691\n203140702 315971348\n258826743 630620717\n31699058 291640859\n235880001 412803442\n315939459 759048353\n685475718 957321047\n179360604 240314450\n834096287 847054732\n", "output": "0\n"}, {"input": "10\n171284358 569331662\n816387693 866841745\n230378852 628199244\n14213793 469970886\n104775464 907459110\n649984841 964193536\n627325981 944477922\n86135411 710882026\n705092056 899265991\n110272590 153668239\n", "output": "0\n"}, {"input": "10\n588252206 748752562\n259232694 260066743\n269338501 559606889\n1786645 286850453\n550198833 572116446\n308352289 971086784\n242458040 551093539\n741267069 787029344\n591055711 646092849\n673724688 890914944\n", "output": "0\n"}, {"input": "10\n281810232 762606772\n269783510 738093461\n205086180 673338873\n83658884 990305706\n174551518 969757411\n12272556 981294098\n271749430 909945032\n62307770 939073496\n178435963 842807921\n177044261 712460424\n", "output": "221646382\n"}, {"input": "50\n0 1\n0 0\n0 1\n0 1\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 1\n0 1\n0 1\n0 0\n1 1\n0 0\n1 1\n0 1\n0 1\n1 1\n0 1\n0 1\n0 1\n0 0\n1 1\n0 1\n1 1\n1 1\n0 1\n0 1\n0 0\n0 0\n0 1\n0 1\n0 1\n1 1\n1 1\n0 0\n0 1\n0 1\n0 1\n0 1\n0 1\n1 1\n0 1\n0 1\n1 1\n0 0\n0 1\n", "output": "0\n"}, {"input": "50\n0 1\n1 1\n0 0\n1 1\n1 1\n0 1\n1 1\n1 1\n1 1\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 1\n0 1\n0 1\n0 1\n0 1\n0 1\n1 1\n0 0\n0 1\n0 0\n0 1\n0 1\n0 1\n1 1\n0 1\n0 0\n0 1\n0 1\n0 1\n0 1\n0 0\n1 1\n0 1\n0 0\n0 1\n0 1\n0 0\n0 1\n0 1\n1 1\n0 1\n", "output": "0\n"}, {"input": "50\n0 0\n1 1\n0 1\n0 1\n0 1\n1 1\n0 0\n0 0\n0 1\n0 1\n0 1\n0 1\n1 1\n0 1\n0 1\n0 0\n0 1\n0 1\n1 1\n0 0\n0 1\n0 0\n0 0\n1 1\n0 1\n0 1\n0 1\n0 1\n1 1\n1 1\n0 0\n0 0\n0 1\n0 1\n0 1\n0 0\n0 1\n0 1\n0 0\n0 1\n1 1\n0 0\n0 1\n1 1\n0 1\n0 0\n0 1\n1 1\n1 1\n0 1\n", "output": "0\n"}, {"input": "50\n0 0\n1 1\n1 1\n1 1\n0 1\n1 1\n0 0\n1 1\n0 1\n0 0\n0 1\n0 1\n0 1\n0 1\n1 1\n0 0\n1 1\n0 1\n0 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 0\n0 0\n1 1\n0 1\n0 0\n0 1\n1 1\n0 1\n0 0\n1 1\n0 0\n1 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 0\n1 1\n0 1\n0 1\n1 1\n0 1\n0 1\n1 1\n", "output": "0\n"}, {"input": "50\n0 0\n0 0\n0 0\n1 1\n0 1\n0 1\n0 1\n0 1\n0 0\n0 1\n0 0\n0 1\n1 1\n0 1\n1 1\n0 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 1\n1 1\n0 1\n0 1\n0 0\n0 1\n0 1\n0 1\n1 1\n0 1\n0 0\n1 1\n0 0\n0 1\n0 1\n0 0\n0 0\n0 1\n1 1\n0 0\n0 1\n0 1\n0 0\n0 0\n0 1\n0 0\n1 1\n1 1\n1 1\n", "output": "0\n"}, {"input": "50\n0 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n0 1\n1 1\n0 1\n0 1\n0 1\n0 1\n1 1\n0 1\n0 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n0 1\n1 1\n1 1\n1 1\n0 1\n0 1\n1 1\n1 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 1\n1 1\n0 1\n0 1\n1 1\n0 1\n0 1\n0 1\n1 1\n1 1\n1 1\n0 1\n1 1\n1 1\n", "output": "998243877\n"}, {"input": "50\n0 53\n0 52\n12 27\n38 89\n29 70\n19 56\n9 15\n22 24\n86 93\n69 97\n42 89\n27 36\n28 56\n48 56\n37 79\n42 47\n38 52\n5 47\n5 22\n25 31\n53 74\n29 48\n18 42\n10 94\n10 36\n29 64\n48 55\n0 6\n10 13\n14 90\n60 84\n9 42\n20 44\n77 78\n36 65\n4 99\n75 79\n23 79\n61 87\n28 63\n29 81\n39 76\n35 91\n5 84\n14 30\n20 21\n68 93\n61 81\n75 77\n34 79\n", "output": "0\n"}, {"input": "50\n47 52\n62 91\n23 80\n39 94\n88 94\n31 45\n73 86\n23 75\n7 100\n53 85\n62 65\n40 81\n2 71\n20 95\n34 39\n4 24\n9 21\n67 85\n48 65\n83 99\n19 25\n48 69\n86 97\n34 99\n7 80\n27 43\n38 65\n14 31\n4 86\n39 52\n73 99\n28 50\n3 48\n64 88\n64 88\n31 98\n31 62\n10 52\n7 15\n45 46\n48 75\n21 100\n6 96\n8 30\n34 36\n51 76\n7 95\n2 96\n36 50\n26 55\n", "output": "0\n"}, {"input": "50\n25 28\n12 15\n53 79\n22 38\n47 52\n42 44\n61 74\n34 73\n28 50\n4 40\n14 99\n33 44\n46 81\n40 61\n32 54\n12 45\n72 91\n0 60\n52 57\n11 72\n42 87\n35 44\n64 96\n57 69\n48 83\n22 82\n8 40\n54 95\n52 73\n7 72\n26 84\n23 58\n20 44\n52 97\n70 100\n2 97\n13 88\n8 58\n44 87\n40 84\n78 94\n22 47\n22 67\n35 76\n42 87\n48 63\n40 59\n23 54\n7 92\n7 20\n", "output": "0\n"}, {"input": "50\n37 38\n2 24\n34 95\n40 84\n38 43\n21 77\n42 69\n66 93\n3 69\n56 85\n55 65\n16 75\n15 89\n58 86\n48 62\n23 54\n16 56\n32 71\n16 45\n44 74\n58 99\n30 54\n39 41\n39 81\n92 93\n12 80\n6 63\n25 61\n16 100\n1 100\n5 66\n52 99\n2 16\n40 50\n11 65\n74 97\n44 65\n29 31\n40 44\n23 33\n12 96\n12 29\n16 38\n90 95\n4 18\n11 50\n9 99\n12 44\n32 79\n30 32\n", "output": "0\n"}, {"input": "50\n16 47\n24 34\n12 78\n72 91\n68 98\n22 76\n44 66\n12 65\n65 81\n40 72\n87 97\n20 28\n64 94\n9 55\n92 98\n68 84\n6 8\n19 26\n37 41\n50 60\n10 19\n52 84\n19 61\n3 44\n67 72\n11 23\n31 83\n78 91\n80 93\n35 64\n16 70\n6 47\n6 89\n60 84\n34 60\n1 52\n22 27\n16 38\n69 91\n39 72\n26 63\n3 44\n64 66\n65 68\n21 95\n19 37\n5 11\n32 48\n5 39\n13 28\n", "output": "0\n"}, {"input": "50\n4 66\n6 49\n8 32\n0 73\n0 46\n10 58\n0 58\n9 46\n0 33\n1 24\n5 76\n6 19\n7 92\n0 56\n5 27\n7 31\n3 56\n11 66\n3 51\n6 53\n4 29\n9 27\n10 94\n7 66\n5 32\n9 51\n6 97\n3 33\n8 44\n10 73\n4 96\n8 52\n10 100\n3 81\n9 94\n2 76\n11 83\n10 72\n6 56\n3 81\n0 96\n8 32\n9 88\n6 26\n0 99\n6 53\n10 24\n11 56\n10 72\n9 51\n", "output": "280107165\n"}, {"input": "10\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n", "output": "987521025\n"}, {"input": "10\n3 10\n3 10\n3 10\n3 10\n3 10\n3 10\n3 10\n3 10\n3 10\n3 10\n", "output": "561494368\n"}, {"input": "10\n34 50\n34 50\n34 50\n34 50\n34 50\n34 50\n34 50\n34 50\n34 50\n34 50\n", "output": "801164847\n"}, {"input": "10\n45 98\n45 98\n45 98\n45 98\n45 98\n45 98\n45 98\n45 98\n45 98\n45 98\n", "output": "207527825\n"}, {"input": "10\n98 193\n98 193\n98 193\n98 193\n98 193\n98 193\n98 193\n98 193\n98 193\n98 193\n", "output": "232974654\n"}, {"input": "10\n58977 99307\n58977 99307\n58977 99307\n58977 99307\n58977 99307\n58977 99307\n58977 99307\n58977 99307\n58977 99307\n58977 99307\n", "output": "449467043\n"}, {"input": "10\n295314256 608527638\n295314256 608527638\n295314256 608527638\n295314256 608527638\n295314256 608527638\n295314256 608527638\n295314256 608527638\n295314256 608527638\n295314256 608527638\n295314256 608527638\n", "output": "565526803\n"}, {"input": "50\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "output": "1\n"}, {"input": "50\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n5 10\n", "output": "210464987\n"}, {"input": "50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n25 50\n", "output": "791565582\n"}, {"input": "50\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n48 100\n", "output": "970752233\n"}, {"input": "50\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n89 199\n", "output": "164998844\n"}] |
|
198 | Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be n.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer x, such that the number of parts of length x in the first way differ from the number of parts of length x in the second way.
-----Input-----
The first line of the input contains a positive integer n (1 ≤ n ≤ 2·10^9) — the length of Pasha's stick.
-----Output-----
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
-----Examples-----
Input
6
Output
1
Input
20
Output
4
-----Note-----
There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | interview | [{"code": "n = int(input())\nif n%2==1:\n print(0)\nelif n%4==2:\n print(n//4)\nelse:\n print(n//4-1)\n", "passed": true, "time": 0.22, "memory": 14400.0, "status": "done"}, {"code": "n = int(input())\np = n // 2\nif (n % 2 == 1):\n print(0)\nelse:\n if (n % 4 == 0):\n print((p-1)//2)\n else:\n print(p//2)", "passed": true, "time": 0.24, "memory": 14464.0, "status": "done"}, {"code": "x = int(input())\nif x%2:\n\tprint(0)\nelse:\n\tx//=2\n\tprint((x-1)//2)\n", "passed": true, "time": 0.23, "memory": 14388.0, "status": "done"}, {"code": "n = int(input())\nif n % 2:\n print(0)\nelse:\n n //= 2\n print((n - 1) // 2)", "passed": true, "time": 0.23, "memory": 14396.0, "status": "done"}, {"code": "a=int(input())\nif a%2!=0:\n print(0)\nelif a<=4:\n print(0)\nelse:\n print(a//4-(a%4==0))", "passed": true, "time": 0.14, "memory": 14512.0, "status": "done"}, {"code": "n = int(input())\nif n%2 == 1:\n print(0)\nelse:\n print((n-2)//4)\n", "passed": true, "time": 0.15, "memory": 14284.0, "status": "done"}, {"code": "import itertools\nimport math\n\nn = int(input())\nif n%2:\n print(0)\nelse:\n m = n // 2\n print((m-1)//2 )\n\n\n", "passed": true, "time": 0.14, "memory": 14540.0, "status": "done"}, {"code": "n=int(input())\nif n%2==1:\n print(0)\nelse:\n n=n//2\n if n%2==0:\n print(n//2-1)\n else:\n print(n//2)\n \n", "passed": true, "time": 0.19, "memory": 14432.0, "status": "done"}, {"code": "n = int(input())\nif n % 2 == 1:\n print(0)\nelse:\n n //= 2\n print((n - 1) // 2)\n", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "n = int(input())\nif n % 2: print(0)\nelse:\n k = n // 2\n cnt = k // 2\n if k % 2 == 0: cnt -= 1\n print(cnt)\n", "passed": true, "time": 0.14, "memory": 14424.0, "status": "done"}, {"code": "n = int(input())\nif n % 2 == 1:\n print(0)\nelse:\n print((n // 2 - 1) // 2)", "passed": true, "time": 0.14, "memory": 14304.0, "status": "done"}, {"code": "n = int(input())\nif n % 2 == 1:\n print(0)\nelif n % 4 == 0:\n print((n - 1) // 4)\nelse:\n print(n // 4)", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}, {"code": "\nimport math\nimport sys\n\nn=int(input())\n \nm = int((n-1)/2)\nk = int(m/2)\n\nif n%2 == 1:\n k=0\nprint(k)\n \n\n \n\n\n \n", "passed": true, "time": 0.14, "memory": 14408.0, "status": "done"}, {"code": "n=int(input())\n\nif n%2==0:\n print((n-2)//4)\nelse:\n print(0)\n", "passed": true, "time": 0.22, "memory": 14332.0, "status": "done"}, {"code": "n = int(input())\nif n % 2 == 1 or n == 2 or n == 4:\n print(0)\nelif n % 4 == 2:\n print(n // 4)\nelse:\n print(n // 4 - 1)\n", "passed": true, "time": 0.14, "memory": 14348.0, "status": "done"}, {"code": "n = int(input())\nif n % 2 == 1:\n print(0)\nelse:\n if (n//2) % 2 == 1:\n print((n//2-1)//2)\n else:\n print(n//4-1)\n \n", "passed": true, "time": 0.15, "memory": 14528.0, "status": "done"}, {"code": "n = int(input())\nif n % 2 == 1:\n print(0)\nelse:\n print((n // 2 - 1) // 2)\n", "passed": true, "time": 0.25, "memory": 14448.0, "status": "done"}, {"code": "x = int(input())\n\nif (x % 2 == 1 or x < 4):\n print(0)\nelse:\n half = x//2\n if (half % 2 == 0):\n print(half//2-1)\n else:\n print((half-1)//2)\n", "passed": true, "time": 0.15, "memory": 14340.0, "status": "done"}, {"code": "import sys\nif False:\n\tinp = open('A.txt', 'r')\nelse:\n\tinp = sys.stdin\n\nn = int(inp.readline())\nans = 0\nif n%2 != 0:\n\tprint(0)\nelse:\n\tif n%4 == 0:\n\t\tprint(n//4 - 1)\n\telse:\n\t\tprint(n//4)", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "n = int(input())\nif n % 2 == 0:\n if n % 4 == 0:\n print(n // 4 - 1)\n else:\n print(n // 4)\nelse:\n print(0)\n", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "import math;\n\nn = int(input());\n\nif(n%2!=0):\n print(0);\nelse:\n print(math.ceil(n/4)-1);", "passed": true, "time": 0.15, "memory": 14584.0, "status": "done"}, {"code": "n=int(input())\nif n%2==1:\n ans=0\nelse:\n c=n/2\n if c%2==1:\n ans=int(n/4)\n else:\n ans=int(n/4-1)\n\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14508.0, "status": "done"}, {"code": "def main():\n n = int(input())\n if n > 6 and n % 2 == 0:\n print(int((n // 2 - 1) / 2))\n elif n == 6:\n print(1)\n else:\n print(0)\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.24, "memory": 14544.0, "status": "done"}, {"code": "n=int(input())\nif n%2==1:\n ans=0\nelse:\n c=n/2\n if c%2==1:\n ans=int(n/4)\n else:\n ans=int(n/4-1)\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14584.0, "status": "done"}] | [{"input": "6\n", "output": "1\n"}, {"input": "20\n", "output": "4\n"}, {"input": "1\n", "output": "0\n"}, {"input": "2\n", "output": "0\n"}, {"input": "3\n", "output": "0\n"}, {"input": "4\n", "output": "0\n"}, {"input": "2000000000\n", "output": "499999999\n"}, {"input": "1924704072\n", "output": "481176017\n"}, {"input": "73740586\n", "output": "18435146\n"}, {"input": "1925088820\n", "output": "481272204\n"}, {"input": "593070992\n", "output": "148267747\n"}, {"input": "1925473570\n", "output": "481368392\n"}, {"input": "629490186\n", "output": "157372546\n"}, {"input": "1980649112\n", "output": "495162277\n"}, {"input": "36661322\n", "output": "9165330\n"}, {"input": "1943590793\n", "output": "0\n"}, {"input": "71207034\n", "output": "17801758\n"}, {"input": "1757577394\n", "output": "439394348\n"}, {"input": "168305294\n", "output": "42076323\n"}, {"input": "1934896224\n", "output": "483724055\n"}, {"input": "297149088\n", "output": "74287271\n"}, {"input": "1898001634\n", "output": "474500408\n"}, {"input": "176409698\n", "output": "44102424\n"}, {"input": "1873025522\n", "output": "468256380\n"}, {"input": "5714762\n", "output": "1428690\n"}, {"input": "1829551192\n", "output": "457387797\n"}, {"input": "16269438\n", "output": "4067359\n"}, {"input": "1663283390\n", "output": "415820847\n"}, {"input": "42549941\n", "output": "0\n"}, {"input": "1967345604\n", "output": "491836400\n"}, {"input": "854000\n", "output": "213499\n"}, {"input": "1995886626\n", "output": "498971656\n"}, {"input": "10330019\n", "output": "0\n"}, {"input": "1996193634\n", "output": "499048408\n"}, {"input": "9605180\n", "output": "2401294\n"}, {"input": "1996459740\n", "output": "499114934\n"}, {"input": "32691948\n", "output": "8172986\n"}, {"input": "1975903308\n", "output": "493975826\n"}, {"input": "1976637136\n", "output": "494159283\n"}, {"input": "29803038\n", "output": "7450759\n"}, {"input": "1977979692\n", "output": "494494922\n"}, {"input": "1978595336\n", "output": "494648833\n"}, {"input": "27379344\n", "output": "6844835\n"}, {"input": "1979729912\n", "output": "494932477\n"}, {"input": "1980253780\n", "output": "495063444\n"}, {"input": "1980751584\n", "output": "495187895\n"}, {"input": "53224878\n", "output": "13306219\n"}, {"input": "5\n", "output": "0\n"}, {"input": "7\n", "output": "0\n"}, {"input": "8\n", "output": "1\n"}, {"input": "9\n", "output": "0\n"}, {"input": "10\n", "output": "2\n"}, {"input": "11\n", "output": "0\n"}, {"input": "12\n", "output": "2\n"}, {"input": "13\n", "output": "0\n"}, {"input": "14\n", "output": "3\n"}, {"input": "15\n", "output": "0\n"}, {"input": "16\n", "output": "3\n"}, {"input": "17\n", "output": "0\n"}, {"input": "18\n", "output": "4\n"}, {"input": "19\n", "output": "0\n"}, {"input": "21\n", "output": "0\n"}, {"input": "22\n", "output": "5\n"}, {"input": "23\n", "output": "0\n"}, {"input": "24\n", "output": "5\n"}, {"input": "25\n", "output": "0\n"}, {"input": "26\n", "output": "6\n"}, {"input": "27\n", "output": "0\n"}, {"input": "28\n", "output": "6\n"}, {"input": "29\n", "output": "0\n"}, {"input": "30\n", "output": "7\n"}, {"input": "111\n", "output": "0\n"}, {"input": "55\n", "output": "0\n"}, {"input": "105\n", "output": "0\n"}, {"input": "199\n", "output": "0\n"}, {"input": "151\n", "output": "0\n"}] |
|
199 | The Fair Nut likes kvass very much. On his birthday parents presented him $n$ kegs of kvass. There are $v_i$ liters of kvass in the $i$-th keg. Each keg has a lever. You can pour your glass by exactly $1$ liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by $s$ liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by $s$ liters of kvass.
-----Input-----
The first line contains two integers $n$ and $s$ ($1 \le n \le 10^3$, $1 \le s \le 10^{12}$) — the number of kegs and glass volume.
The second line contains $n$ integers $v_1, v_2, \ldots, v_n$ ($1 \le v_i \le 10^9$) — the volume of $i$-th keg.
-----Output-----
If the Fair Nut cannot pour his glass by $s$ liters of kvass, print $-1$. Otherwise, print a single integer — how much kvass in the least keg can be.
-----Examples-----
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
-----Note-----
In the first example, the answer is $3$, the Fair Nut can take $1$ liter from the first keg and $2$ liters from the third keg. There are $3$ liters of kvass in each keg.
In the second example, the answer is $2$, the Fair Nut can take $3$ liters from the first keg and $1$ liter from the second keg.
In the third example, the Fair Nut can't pour his cup by $7$ liters, so the answer is $-1$. | interview | [{"code": "def doit():\n xx = input().split()\n n = int(xx[0])\n s = int(xx[1])\n v = [int(k) for k in input().split()]\n\n S = sum(v)\n newS = S - s\n if newS < 0:\n return -1\n return min(newS//n, min(v))\n \nprint(doit())\n", "passed": true, "time": 0.36, "memory": 14452.0, "status": "done"}, {"code": "n, s = list(map(int, input().split()))\n\nv = list(map(int, input().split()))\n\nif sum(v) < s:\n print(-1)\n return\n\nmv = min(v)\n\nfor i in range(n):\n s -= v[i] - mv\n\nif s < 1:\n print(mv)\n return\n\nans = mv - s // n\nif s % n != 0:\n ans -= 1\n\nprint(ans)\n\n\n\n", "passed": true, "time": 1.25, "memory": 14360.0, "status": "done"}, {"code": "from sys import stdin, stdout\nfrom math import sin, tan, cos, pi, atan2, sqrt, acos, atan, factorial\n\n\nn, s = map(int, stdin.readline().split())\nvalues = list(map(int, stdin.readline().split()))\n\nl, r = -1, min(values) + 1\nwhile r - l > 1:\n m = (l + r) >> 1\n \n cnt = 0\n for v in values:\n cnt += v - m\n \n if cnt >= s:\n l = m\n else:\n r = m\n\nif l == -1:\n stdout.write('-1\\n')\nelse:\n stdout.write(str(l) + '\\n')", "passed": true, "time": 1.77, "memory": 14504.0, "status": "done"}, {"code": "n, s = list(map(int, input().split()))\n\nallCups = list(map(int, input().split()))\nsumK = sum(allCups)\nminK = min(allCups)\nif sumK < s:\n print(-1)\n\nelse:\n if sumK - (minK * n) >= s:\n print(minK)\n else:\n s = s - (sumK - (minK * n))\n #print(s)\n if s % n == 0:\n print(minK - (s // n))\n else:\n print(minK - (s // n) - 1)\n", "passed": true, "time": 0.16, "memory": 14476.0, "status": "done"}, {"code": "n, s = list(map(int, input().split()))\na = list(map(int, input().split()))\na.sort()\nd = sum(a)\nif d >= s:\n r = d - s\n ans = min(r // n, a[0])\nelse:\n ans = -1\n\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14508.0, "status": "done"}, {"code": "n, s = map(int, input().split())\nnum = list(map(int, input().split()))\nx = sum(num)\nif x < s:\n print(-1)\nelse:\n k = min(num)\n for i in range(n):\n s -= abs(num[i] - k)\n num[i] = k\n if s <= 0:\n print(k)\n else:\n q = s // n\n k -= q\n if s % n == 0:\n print(k)\n else:\n print(k - 1)", "passed": true, "time": 0.15, "memory": 14568.0, "status": "done"}, {"code": "from math import ceil\n\nn, s = list(map(int, input().split()))\nA = list(map(int, input().split()))\nif sum(A) < s:\n print(-1)\nelse:\n x = min(A)\n y = 0\n for k in range(n):\n y += (A[k] - x)\n if y >= s:\n print(x)\n else:\n a = s - y\n print(x - ceil(a / n))", "passed": true, "time": 0.14, "memory": 14564.0, "status": "done"}, {"code": "n,s=map(int,input().split())\na=list(map(int,input().split()))\ny=min(a)*n\nx=sum(a)\nif x<s:\n print(-1)\nelse:\n if s<=x-y:\n print(y//n)\n else:\n s=s-(x-y)\n print((y-s)//n)", "passed": true, "time": 0.17, "memory": 14520.0, "status": "done"}, {"code": "import math\nn,s=map(int,input().split())\nv=list(map(int,input().split()))\nx=sum(v)\nif s>x:\n print(-1)\nelse:\n a=min(v)\n if s<x-n*a:\n print(a)\n else:\n b=x-n*a\n c=s-b\n print(a-math.ceil(c/n))", "passed": true, "time": 0.17, "memory": 14400.0, "status": "done"}, {"code": "n, s = list(map(int, input().split()))\nv = list(map(int, input().split()))\nsm = sum(v)\nsm -= s\nif sm < 0:\n print(-1)\nelse:\n mn = min(v)\n r = min(mn, sm // n)\n print(r)\n", "passed": true, "time": 0.22, "memory": 14508.0, "status": "done"}, {"code": "import math, sys, itertools\n\ndef mp():\n return list(map(int, input().split()))\n\ndef main():\n n, s = mp()\n a = mp()\n sm = sum(a)\n if sm < s:\n print(-1)\n return\n ans = (sum(a) - s) // n\n print(min(ans, min(a)))\n \n\ndeb = 0\nif deb:\n file = open('input.txt', 'r')\n input = file.readline\nelse:\n input = sys.stdin.readline\n \nmain()", "passed": true, "time": 0.16, "memory": 14372.0, "status": "done"}, {"code": "n, s = list(map(int, input().split()))\nv = [int(k) for k in input().split()]\nv.sort(reverse=True)\nfor i in range(n):\n s -= v[i] - v[-1]\n v[i] = v[-1]\nif s <= 0:\n print(v[-1])\nelse:\n if s > n * v[0]:\n print(-1)\n else:\n print(v[0] - (s + n - 1) // n) \n", "passed": true, "time": 0.17, "memory": 14400.0, "status": "done"}, {"code": "import math\nn,s = list(map(int,input().split()))\nv = input().split()\nmini = math.inf\nfor i in range(n):\n mini = min(int(v[i]),mini)\ns += mini*n\nfor i in range(n):\n s -= int(v[i])\nif s < 0:\n print(mini)\nelif s > mini*n:\n print(-1)\nelif s%n == 0:\n print(mini-s//n)\nelse:\n print(mini-s//n-1)\n", "passed": true, "time": 0.17, "memory": 14544.0, "status": "done"}, {"code": "n, s = list(map(int, input().split()))\nv = [int(x) for x in input().split()]\nt = sum(v)\nif sum(v) < s:\n\tprint(-1)\n\treturn\nb = min(v)\nkol = t - b * n\ns -= kol\nif s <= 0:\n\tprint(b)\n\treturn\ntmp = (s + n - 1) // n\nprint(b - tmp)\n", "passed": true, "time": 0.15, "memory": 14392.0, "status": "done"}, {"code": "n, s = map(int, input().split())\nk = list(map(int, input().split()))\nsumk = sum(k)\nmink = min(k)\nif sumk < s:\n print(-1)\n return\nif sumk-n*mink >= s:\n print(mink)\nelse:\n s -= sumk-n*mink\n if s%n == 0:\n print(mink-s//n)\n else:\n print(mink-s//n-1)", "passed": true, "time": 0.25, "memory": 14328.0, "status": "done"}, {"code": "import math\nn,q=list(map(int,input().split()))\nh=list(map(int,input().split()))\nt=0\nfor i in range (n):\n t+=h[i]\nif t<q:\n print(-1)\n return\nlow=min(h)\nfor i in range (n):\n q-=(h[i]-low)\nif q<=0:\n print(low)\n return\nlow-=math.ceil(q/n)\nprint(low)\n", "passed": true, "time": 0.15, "memory": 14496.0, "status": "done"}, {"code": "n,s = map(int,input().split())\nl = list(map(int, input().split()))\n\nif sum(l) < s:\n\tprint(-1)\n\treturn\nq = sum(l) - min(l) * n\nif q>=s:\n\tprint(min(l))\n\treturn\nprint(min(l)-(s-q+n-1)//n)", "passed": true, "time": 0.14, "memory": 14588.0, "status": "done"}, {"code": "n, S = [int(x) for x in input().split()]\n\nA = [int(x) for x in input().split()]\n\ndef ans():\n nonlocal S\n to_min = sum(A) - n*min(A)\n S -= to_min\n if S <= 0:\n return min(A)\n if n*min(A) < S: return -1\n return (n*min(A) - S) // n\n\nprint(ans())\n", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "n, s = list(map(int, input().split()))\nu = list(map(int, input().split()))\nmu = min(u)\nsu = sum(u)\nif su < s:\n print(-1)\nelse:\n s -= (su - mu * n)\n if s <= 0:\n print(mu)\n else:\n k = s // n\n if s % n != 0:\n k += 1\n print(mu - k)\n", "passed": true, "time": 0.25, "memory": 14600.0, "status": "done"}, {"code": "n, k = list(map(int, input().split(' ')))\n\na = list(map(int, input().split(' ')))\n\nminV = min(a)\n\ns = sum(a)\n\nif(k > s):\n print(-1)\nelse:\n rest = s - minV * n\n if(rest >= k):\n print(minV)\n else:\n k -= rest\n \n sol = k // n\n if(k % n):\n sol += 1\n\n print(minV - sol)", "passed": true, "time": 0.15, "memory": 14576.0, "status": "done"}, {"code": "#!/usr/bin/env python\n# coding: utf-8\n\n# In[15]:\n\n\nimport math\nns=list(map(int, input().rstrip().split()))\nn=ns[0]\ns=ns[1]\n\ndata=list(map(int, input().rstrip().split()))\n\n\n# In[16]:\n\n\ndata.sort()\n\n\n# In[17]:\n\n\nextras=[i-data[0] for i in data]\n\n\n# In[18]:\n\n\ntotal=sum(data)\nextratotal=sum(extras)\n\n\n# In[ ]:\n\n\n\n\n\n# In[19]:\n\n\nif s>total:\n print(-1)\nelif extratotal>=s:\n print(data[0]) \nelse:\n sub=math.ceil((s-extratotal)/n)\n print(data[0]-sub)\n \n\n\n# In[ ]:\n\n", "passed": true, "time": 0.14, "memory": 14272.0, "status": "done"}, {"code": "import sys\nfrom math import ceil\n\n\ndef main():\n n, s = map(int, sys.stdin.readline().split())\n arr = list(map(int, sys.stdin.readline().split()))\n if s > sum(arr):\n print(-1, sep=' ', end='\\n', file=sys.stdout, flush=False)\n else:\n count = 0\n arr.sort(reverse=True)\n for i in range(n-1):\n if count == s:\n break\n if count+(arr[i]-arr[-1]) <= s:\n count += arr[i]-arr[-1]\n arr[i] = arr[-1]\n elif count+(arr[i]-arr[-1]) > s:\n count = s\n arr[i] -= (s-count)\n if count == s:\n print(arr[-1])\n else:\n factor = (s-count)/n\n\n print(arr[-1]-ceil(factor), sep=' ', end='\\n', file=sys.stdout, flush=False)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.23, "memory": 14520.0, "status": "done"}] | [{"input": "3 3\n4 3 5\n", "output": "3\n"}, {"input": "3 4\n5 3 4\n", "output": "2\n"}, {"input": "3 7\n1 2 3\n", "output": "-1\n"}, {"input": "1 1\n1\n", "output": "0\n"}, {"input": "1 2\n1\n", "output": "-1\n"}, {"input": "5 10\n10 10 10 10 10\n", "output": "8\n"}, {"input": "1 1000000000\n1000000000\n", "output": "0\n"}, {"input": "1 1000000000000\n42\n", "output": "-1\n"}, {"input": "3 2\n1 1 5\n", "output": "1\n"}, {"input": "2 1\n1 100\n", "output": "1\n"}, {"input": "3 1\n5 10 15\n", "output": "5\n"}, {"input": "2 1\n1 1000\n", "output": "1\n"}, {"input": "3 3\n2 4 4\n", "output": "2\n"}, {"input": "10 1\n1 2 3 4 5 6 7 8 9 10\n", "output": "1\n"}, {"input": "3 6\n1 99 99\n", "output": "1\n"}, {"input": "4 1\n100 1 100 100\n", "output": "1\n"}, {"input": "5 2\n4 6 8 10 14\n", "output": "4\n"}, {"input": "4 6\n1 2 3 10\n", "output": "1\n"}, {"input": "5 2\n4 6 8 10 19\n", "output": "4\n"}, {"input": "4 1\n5 3 1 1\n", "output": "1\n"}, {"input": "4 2\n2 3 4 5\n", "output": "2\n"}, {"input": "3 10\n1 9 9\n", "output": "1\n"}, {"input": "3 7\n1 5 12\n", "output": "1\n"}, {"input": "2 1\n1 1000000000\n", "output": "1\n"}, {"input": "5 1\n100 100 100 100 1\n", "output": "1\n"}, {"input": "2 1\n100 10000\n", "output": "100\n"}, {"input": "5 1\n5 5 5 5 1\n", "output": "1\n"}, {"input": "2 500\n1 1000\n", "output": "1\n"}, {"input": "2 1\n1 10000000\n", "output": "1\n"}, {"input": "2 50\n1 100\n", "output": "1\n"}, {"input": "2 1\n100 1\n", "output": "1\n"}, {"input": "5 1\n1 1 1 1 1000\n", "output": "1\n"}, {"input": "3 3\n4 4 92\n", "output": "4\n"}, {"input": "2 30\n1 100\n", "output": "1\n"}, {"input": "2 94\n1 99\n", "output": "1\n"}, {"input": "6 1\n2 2 3 6 6 6\n", "output": "2\n"}, {"input": "2 3\n1 10\n", "output": "1\n"}, {"input": "3 3\n100 4 4\n", "output": "4\n"}, {"input": "3 10\n100 100 1\n", "output": "1\n"}, {"input": "2 1\n1000000000 999999999\n", "output": "999999999\n"}, {"input": "3 3\n1 3 5\n", "output": "1\n"}, {"input": "2 5\n1 10\n", "output": "1\n"}, {"input": "15 56\n38 47 84 28 67 40 15 24 64 37 68 30 74 41 62\n", "output": "15\n"}, {"input": "5 5\n1 100 100 100 100\n", "output": "1\n"}, {"input": "2 1\n1 10\n", "output": "1\n"}, {"input": "3 4\n1 2 2\n", "output": "0\n"}, {"input": "2 2\n900000000 2\n", "output": "2\n"}, {"input": "4 1\n1 5 5 5\n", "output": "1\n"}, {"input": "3 7\n1 5 10\n", "output": "1\n"}, {"input": "4 2\n5 7 8 9\n", "output": "5\n"}, {"input": "5 3\n1 2 3 4 5\n", "output": "1\n"}, {"input": "3 3\n100 2 3\n", "output": "2\n"}, {"input": "2 5\n1 100\n", "output": "1\n"}, {"input": "2 5000\n1 1000000000\n", "output": "1\n"}, {"input": "1 1000000000000\n1000000000\n", "output": "-1\n"}, {"input": "2 1\n2 4\n", "output": "2\n"}, {"input": "3 3\n1 2 10\n", "output": "1\n"}, {"input": "2 2\n5 1\n", "output": "1\n"}, {"input": "2 5000\n1 100000000\n", "output": "1\n"}, {"input": "3 1\n1 4 5\n", "output": "1\n"}, {"input": "2 50\n1 500\n", "output": "1\n"}, {"input": "2 5\n1 8\n", "output": "1\n"}, {"input": "3 100\n1 100 100\n", "output": "1\n"}, {"input": "3 3\n4 6 7\n", "output": "4\n"}, {"input": "2 1\n2 5\n", "output": "2\n"}, {"input": "2 4\n8 1000\n", "output": "8\n"}, {"input": "2 1000000000\n99999999 1000000000\n", "output": "49999999\n"}, {"input": "3 3\n23 123 123\n", "output": "23\n"}, {"input": "3 1\n5 6 3\n", "output": "3\n"}, {"input": "5 1\n1 10 10 10 10\n", "output": "1\n"}, {"input": "3 5\n1 1 10\n", "output": "1\n"}, {"input": "3 1\n1 1 5\n", "output": "1\n"}, {"input": "3 5\n1 2 3\n", "output": "0\n"}, {"input": "4 4\n1000000000 1000000000 1000000000 1000000000\n", "output": "999999999\n"}, {"input": "3 100\n1 55 55\n", "output": "1\n"}, {"input": "2 1\n1 7\n", "output": "1\n"}] |
|
200 | The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h_1 cm from the ground. On the height h_2 cm (h_2 > h_1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
-----Input-----
The first line contains two integers h_1, h_2 (1 ≤ h_1 < h_2 ≤ 10^5) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers a, b (1 ≤ a, b ≤ 10^5) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
-----Output-----
Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer - 1.
-----Examples-----
Input
10 30
2 1
Output
1
Input
10 13
1 1
Output
0
Input
10 19
1 2
Output
-1
Input
1 50
5 4
Output
1
-----Note-----
In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day. | interview | [{"code": "def solve():\n h1, h2 = list(map(int, input().split()))\n a, b = list(map(int, input().split()))\n\n h3 = h1 + a * 8\n\n if h3 >= h2:\n print(0)\n return\n\n if b >= a:\n print(-1)\n return\n\n h4 = h2 - h3\n\n c = (a - b) * 12\n\n ans = int((h4 + (c - 1)) / c)\n\n print(ans)\n\n\ndef __starting_point():\n solve()\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14332.0, "status": "done"}, {"code": "from math import ceil\n\nh1, h2 = list(map(int, input().split()))\n\na, b = list(map(int, input().split()))\n\nx = h2 - h1\np = 0\n\nfor i in range(8):\n p += a\n if p >= x:\n print(0)\n return\n\nfor i in range(100000):\n for j in range(12):\n if i&1:\n p += a\n else:\n p -= b\n if p >= x:\n print(ceil(i/2))\n return\n\nprint(-1)\n", "passed": true, "time": 3.94, "memory": 14328.0, "status": "done"}, {"code": "#! /usr/bin/env python3\n'''\n' Title:\t\n' Author:\tCheng-Shih, Wong\n' Date:\t\t\n'''\n\nimport math\n\nh1, h2 = list(map(int, input().split()))\na, b = list(map(int, input().split()))\n\nif h1+a*8 >= h2: print(0)\nelif a <= b: print(-1)\nelse:\n\tprint( math.ceil((h2-h1-8*a)/(12*(a-b))) )\n", "passed": true, "time": 0.14, "memory": 14624.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport itertools\n\n\ndef divceil(a, b):\n return (a + b - 1) // b\n\n\ndef solve(h1, h2, a, b):\n if a - b <= 0:\n return 0 if divceil(h2 - h1, a) <= 8 else -1\n h = h1\n h += a * 8\n if h >= h2:\n return 0\n h -= b * 12\n for i in itertools.count(1):\n h += a * 12\n if h >= h2:\n return i\n h -= b * 12\n\n\ndef main():\n h1, h2 = list(map(int, input().split()))\n a, b = list(map(int, input().split()))\n print(solve(h1, h2, a, b))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "line = input().split()\nh1 = int(line[0])\nh2 = int(line[1])\nline = input().split()\na = int(line[0])\nb = int(line[1])\nif a <= b:\n if h1 + 8 * a >= h2:\n print(0)\n else:\n print(-1)\nelse:\n slips = 0\n while True:\n if h1 + 8 * a + slips * 12 * (a - b) >= h2:\n print (slips)\n break\n slips += 1\n", "passed": true, "time": 0.46, "memory": 14464.0, "status": "done"}, {"code": "import math\n\n\nh1, h2 = list(map(int, input().split()))\nday, night = list(map(int, input().split()))\n\nif h2 - h1 <= day * 8:\n print(0)\nelif (h2 - h1) - day * 8 + night * 12 - day * 12 <= 0:\n print(1)\nelif day - night <= 0:\n print(-1)\nelse:\n\n # (h2 - h1) <= k * (day - night) * 12 + day * 12 + day * 8 - night * 12\n\n print((\n int(math.ceil(\n ((h2 - h1) - day * 20 + night * 12) / ((day - night) * 12)\n )) + 1\n ))\n", "passed": true, "time": 0.16, "memory": 14568.0, "status": "done"}, {"code": "x=input().split()\ny=input().split()\ndif=int(x[1])-int(x[0])\ncnt=0\n\n\nif dif-int(y[0])*8<=0:\n\tprint(0)\nelif int(y[0])-int(y[1])>0:\n\tdif=dif-int(y[0])*8+int(y[1])*12\n\twhile dif>0:\n\t\tdif-=int(y[0])*12\n\t\tif dif<=0:\n\t\t\tcnt+=1\n\t\t\tbreak\n\t\telse :\n\t\t\tcnt+=1\n\t\t\tdif+=int(y[1])*12\n\tprint(cnt)\nelse: print(-1)", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "h1, h2 = map(int, input().split())\na, b = map(int, input().split())\nh1 += a * 8\nif h1 >= h2:\n print(0)\nelse:\n h1 -= b * 12\n if b >= a:\n print(-1)\n else:\n day = 0\n while True:\n day += 1\n h1 += a * 4\n '''if h1 > h2:\n print(-1)\n break'''\n h1 += a * 8\n if h1 >= h2:\n print(day)\n break\n h1 -= b * 12", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}, {"code": "'__author__'=='deepak Singh Mehta) '\n\nh1, h2 = list(map(int, input().split()))\na, b = list(map(int, input().split()))\nh1 += a * 8\nif h1 >= h2:\n print(0)\nelse:\n h1 -= b * 12\n if b >= a:\n print(-1)\n else:\n day = 0\n while True:\n day += 1\n h1 += a * 4\n '''if h1 > h2:\n print(-1)\n break'''\n h1 += a * 8\n if h1 >= h2:\n print(day)\n break\n h1 -= b * 12\n", "passed": true, "time": 0.15, "memory": 14476.0, "status": "done"}, {"code": "h1, h2 = map(int, input().split(' '))\nh = h2 - h1\n\na, b = map(int, input().split())\nh -= a * 8\n\nif h <= 0:\n print (0)\nelif a <= b:\n print(-1)\nelse:\n print(h // (12 * (a - b)) + (1 if h % (12 * (a - b)) else 0))", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "h1, h2 = map(int, input().split(' '))\nh = h2 - h1\n\na, b = map(int, input().split())\nh -= a * 8\n\nif h <= 0:\n print (0)\nelif a <= b:\n print(-1)\nelse:\n h -= 1\n print(h // (12 * (a - b)) + 1)", "passed": true, "time": 0.15, "memory": 14360.0, "status": "done"}, {"code": "ch=input()\nd=ch.split()\nh1=int(d[0])\nh2=int(d[1])\nch=input()\nd1=ch.split()\na=int(d1[0])\nb=int(d1[1])\nS=2\nD=0\nif h1<h2:\n if b>a and 8*a<(h2-h1):\n print(-1)\n elif b==a and 8*a<(h2-h1):\n print(-1)\n else:\n if h1<h2 :\n if 8*a>=(h2-h1):\n print(0)\n else:\n h1+=a*8\n h1-=b*12\n D+=1\n while h1<h2:\n if h1+a*12>=h2:\n break\n h1+=(a-b)*12\n D+=1\n if D!=0:\n print(D)\nelse:\n h1+8*a\n if a>b and 12*b<(h1-h2):\n print(-1)\n elif b==a and b*12<(8*a+h1-h2):\n print(-1)\n else:\n if h1>h2 :\n \n if 12*b>=(h1-h2):\n print(0)\n else:\n h2+=a*12\n h2-=b*12\n D+=1\n while h1>h2:\n if h2-b*12>=h1:\n break\n h2+=(b-a)*12\n D+=1\n if D!=0:\n print(D)\n \n \n \n \n \n \n", "passed": true, "time": 0.14, "memory": 14596.0, "status": "done"}, {"code": "#http://codeforces.com/contest/652/problem/A\n\n\n# h_cat, h_app, day_up, day_down = [map(int, input().split()), map(int,input().split())]\n\ndef dprint(str):\n\tpstatus = False\n\tif pstatus == True:\n\t\tprint(str)\n\ndef check_cat():\n\tfrom math import ceil\n\tfrom operator import add\n\t# h_string = '10 30'\n\t# speed_string = '2 1'\n\t# h_string = '10 13'\n\t# speed_string = '1 1'\n\t# h_string = '1 50'\n\t# speed_string = '5 4'\n\t# h_string = '10 19'\n\t# speed_string = '1 2'\n\t# h_string = '1 1000'\n\t# speed_string = '2 1'\n\n\n\n\th_string = input()\n\tspeed_string = input()\n\th_cat, h_app = list(map(int, h_string.split()))\n\tday_up, day_down = list(map(int, speed_string.split()))\n\tday_sub = [4*day_up, 8*day_up, -12*day_down]\n\tflag = False\n\tday_loc = [0, h_cat]\n\tcurrent_pos = day_loc[1]\n\tday_counter = 0\n\ti1 = 0\n\tif sum(day_sub) <=0: #overall negative or zero progress\n\t\tif (h_cat + day_sub[1] >= h_app): #reach the apple in first day\n\t\t\treturn(0)\n\t\telse:\n\t\t\treturn(-1)\n\twhile not flag:\n\t\tif current_pos >= h_app:\n\t\t\tflag = True\n\t\t\tbreak\n\t\telse:\n\t\t\ti1 += 1\n\t\t\tcurrent_pos += day_sub[i1%3]\n\t\t\tday_loc.append(current_pos)\n\tdprint(day_loc)\n\tday_counter = i1\n\tdprint(day_counter)\n\tdprint(day_counter%3)\n\n\treturn(int(day_counter/3))\n\noutput = check_cat()\nprint(output)\n\n\n", "passed": true, "time": 0.15, "memory": 14580.0, "status": "done"}, {"code": "def main():\n a, b = list(map(int, input().split()))\n h = b - a\n a, b = list(map(int, input().split()))\n h -= a * 8\n if h <= 0:\n res = 0\n elif a <= b:\n res = -1\n else:\n a = (a - b) * 12\n res = (h + a - 1) // a\n print(res)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14548.0, "status": "done"}, {"code": "H1, H2 = list(map(int, input().split()))\nA, B = list(map(int, input().split()))\n\nnum = H2-H1-8*A\nden = 12*(A-B)\nif den > 0:\n\tans = max(0, (num+den-1) // den)\nelse:\n\tans = 0 if num <= 0 else -1\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "h1, h2 = list(map(int, input().split(' ')))\na, b = list(map(int, input().split(' ')))\n\nif h1+8*a >= h2:\n print(0)\nelif a <= b:\n print(-1)\nelse:\n cnt = 0\n h1 += 8*a\n while h1 < h2:\n h1 += 12*(a-b)\n cnt += 1\n print(cnt)\n", "passed": true, "time": 0.16, "memory": 14340.0, "status": "done"}, {"code": "h1, h2 = list(map(int, input().split(' ')))\na, b = list(map(int, input().split(' ')))\n\nif h1+8*a >= h2:\n print(0)\nelif a <= b:\n print(-1)\nelse:\n dis = h2-h1-8*a\n inc = (a-b)*12\n print((dis+inc-1)//inc)\n", "passed": true, "time": 0.24, "memory": 14452.0, "status": "done"}, {"code": "3\n\nclass StdReader:\n\tdef read_int(self):\n\t\treturn int(self.read_string())\n\n\tdef read_ints(self, sep=None):\n\t\treturn [int(i) for i in self.read_strings(sep)]\n\n\tdef read_float(self):\n\t\treturn float(self.read_string())\n\n\tdef read_floats(self, sep=None):\n\t\treturn [float(i) for i in self.read_strings(sep)]\n\n\tdef read_string(self):\n\t\treturn input()\n\n\tdef read_strings(self, sep=None):\n\t\treturn self.read_string().split(sep)\n\nreader = StdReader()\n\n\ndef main():\n\th1, h2 = reader.read_ints()\n\ta, b = reader.read_ints()\n\n\tif h1 + a * (22-14) >= h2:\n\t\tprint(0)\n\t\treturn\n\n\tif a <= b:\n\t\tprint(-1)\n\t\treturn\n\n\th1 = h1 + a*(22-14)\n\tdh = (a-b) * 12\n\t# print(h1, h2, dh)\n\n\tdays = (h2-h1) // dh + ((h2-h1)%dh != 0)\n\n\tprint(days)\n\n\ndef __starting_point():\n\tmain()\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14652.0, "status": "done"}, {"code": "h1, h2 = map(int, input().split())\na, b = map(int, input().split())\nd = 0\nr = h1\nwhile(True):\n h1 += 8 * a\n if h1 >= h2:\n print(d)\n return\n d += 1\n h1 = h1 - 12 * b + 4 * a\n if d > 1 and h1 <= r:\n print(\"-1\")\n return", "passed": true, "time": 2.03, "memory": 14540.0, "status": "done"}, {"code": "h1, h2 = map(int, input().split())\na, b = map(int, input().split())\nd, v = h2 - h1 - 8 * a, 12 * (a - b)\nif d <= 0:\n print(0)\nelif b >= a:\n print(-1)\nelse:\n print((d + v - 1) // v)", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "h1,h2 = list(map(int, input().split(\" \")))\na,b = list(map(int, input().split(\" \")))\n\ndef caterpillar(a,b,h1,h2):\n if h1 + 8*a >= h2:\n print(0)\n else:\n h = h1 + 8*a\n if 12*(a-b) <= 0:\n print(-1)\n else:\n c = h2-h\n d = 12*(a-b)\n print( (c // d) + (c%d > 0)*1)\n\ncaterpillar(a,b,h1,h2)\n", "passed": true, "time": 0.15, "memory": 14556.0, "status": "done"}, {"code": "h, g = [int(x) for x in input().split(' ')]\na, b = [int(x) for x in input().split(' ')]\nans = 0\nh += 8 * a\nuph = h\nwhile g > h:\n ans += 1\n h += 12 * (a - b)\n if h <= uph:\n ans = -1\n break\n uph = h\nprint(ans)", "passed": true, "time": 0.15, "memory": 14608.0, "status": "done"}, {"code": "h, g = map(int, input().split())\na, b = map(int, input().split())\nans = 0\nh += a << 3\nuph = h\nwhile g > h:\n ans += 1\n h += 12 * (a - b)\n if h <= uph:\n ans = -1\n break\n uph = h\nprint(ans)", "passed": true, "time": 0.15, "memory": 14392.0, "status": "done"}, {"code": "def pillar():\n temp=input().split()\n bugHeight=int(temp[0])\n appleHeight=int(temp[1])\n temp=input().split()\n dayRate=int(temp[0])\n nightRate=int(temp[1])\n if(dayRate*8+bugHeight>=appleHeight):\n return 0\n else:\n bugHeight+=dayRate*8-nightRate*12\n if(bugHeight+(dayRate*12)<appleHeight and nightRate>=dayRate):\n return -1\n if(appleHeight-(bugHeight+12*dayRate)<=0):\n return 1\n temp=((appleHeight-(bugHeight+12*dayRate))/(dayRate*12.0-12*nightRate))\n if(temp==int(temp)):\n return int(temp)+1\n return int(temp)+2\n \nprint(pillar())\n", "passed": true, "time": 0.14, "memory": 14664.0, "status": "done"}] | [{"input": "10 30\n2 1\n", "output": "1\n"}, {"input": "10 13\n1 1\n", "output": "0\n"}, {"input": "10 19\n1 2\n", "output": "-1\n"}, {"input": "1 50\n5 4\n", "output": "1\n"}, {"input": "1 1000\n2 1\n", "output": "82\n"}, {"input": "999 1000\n1 1\n", "output": "0\n"}, {"input": "999 1000\n1 1000\n", "output": "0\n"}, {"input": "1 1000\n999 1\n", "output": "0\n"}, {"input": "1 1000\n100 99\n", "output": "17\n"}, {"input": "500 509\n1 1\n", "output": "-1\n"}, {"input": "500 555\n6 1\n", "output": "1\n"}, {"input": "1 100000\n2 1\n", "output": "8332\n"}, {"input": "99990 100000\n1 1\n", "output": "-1\n"}, {"input": "90000 100000\n2 1\n", "output": "832\n"}, {"input": "10 100000\n1 100000\n", "output": "-1\n"}, {"input": "1 41\n5 6\n", "output": "0\n"}, {"input": "1 100000\n1 100000\n", "output": "-1\n"}, {"input": "1 9\n1 1\n", "output": "0\n"}, {"input": "8 16\n1 12\n", "output": "0\n"}, {"input": "14 30\n2 1\n", "output": "0\n"}, {"input": "7245 77828\n6224 92468\n", "output": "-1\n"}, {"input": "43951 66098\n1604 35654\n", "output": "-1\n"}, {"input": "1 2\n4 3\n", "output": "0\n"}, {"input": "90493 94279\n468 49\n", "output": "1\n"}, {"input": "1 50\n3 1\n", "output": "2\n"}, {"input": "26300 88310\n7130 351\n", "output": "1\n"}, {"input": "1 17\n2 2\n", "output": "0\n"}, {"input": "10718 75025\n7083 6958\n", "output": "6\n"}, {"input": "1 10\n1 100000\n", "output": "-1\n"}, {"input": "1 190\n10 1\n", "output": "2\n"}, {"input": "24951 85591\n3090 8945\n", "output": "-1\n"}, {"input": "1 25\n3 2\n", "output": "0\n"}, {"input": "27043 88418\n7273 7\n", "output": "1\n"}, {"input": "35413 75637\n4087 30166\n", "output": "-1\n"}, {"input": "1 18\n2 3\n", "output": "-1\n"}, {"input": "1 16\n2 2\n", "output": "0\n"}, {"input": "1 18\n2 1\n", "output": "1\n"}, {"input": "1 10\n2 2\n", "output": "0\n"}, {"input": "1 30\n2 1\n", "output": "2\n"}, {"input": "1 100000\n10000 100000\n", "output": "-1\n"}, {"input": "4444 33425\n2758 44\n", "output": "1\n"}, {"input": "1 100000\n10 99910\n", "output": "-1\n"}, {"input": "12 100\n6 11\n", "output": "-1\n"}, {"input": "100 100000\n10 11\n", "output": "-1\n"}, {"input": "28473 80380\n2568 95212\n", "output": "-1\n"}, {"input": "10 105\n10 1\n", "output": "1\n"}, {"input": "4642 39297\n3760 451\n", "output": "1\n"}, {"input": "1 90\n10 1\n", "output": "1\n"}, {"input": "2 100\n1 100000\n", "output": "-1\n"}, {"input": "1 100000\n1000 100000\n", "output": "-1\n"}, {"input": "1 45\n1 100000\n", "output": "-1\n"}, {"input": "12 1000\n100 1\n", "output": "1\n"}, {"input": "64635 76564\n100 34238\n", "output": "-1\n"}, {"input": "10 90\n10 12\n", "output": "0\n"}, {"input": "49238 81395\n3512 251\n", "output": "1\n"}, {"input": "6497 62133\n309 50077\n", "output": "-1\n"}, {"input": "1 100\n1 100000\n", "output": "-1\n"}, {"input": "1 10000\n1 10000\n", "output": "-1\n"}, {"input": "55674 93249\n846 1\n", "output": "4\n"}, {"input": "10 90\n9 10\n", "output": "-1\n"}, {"input": "23110 69794\n171 808\n", "output": "-1\n"}, {"input": "1 100000\n1 10000\n", "output": "-1\n"}, {"input": "1 9\n1 2\n", "output": "0\n"}, {"input": "58750 81357\n2 98022\n", "output": "-1\n"}, {"input": "82125 89348\n894 91369\n", "output": "-1\n"}, {"input": "25401 53663\n957 30449\n", "output": "-1\n"}, {"input": "2 12\n1 2\n", "output": "-1\n"}, {"input": "1 10000\n1 100000\n", "output": "-1\n"}, {"input": "1 100000\n1 99999\n", "output": "-1\n"}, {"input": "1 149\n8 2\n", "output": "2\n"}, {"input": "3 100\n1 1\n", "output": "-1\n"}, {"input": "1 18\n2 2\n", "output": "-1\n"}, {"input": "1 77\n9 1\n", "output": "1\n"}, {"input": "7330 94486\n968 141\n", "output": "9\n"}, {"input": "89778 98176\n863 61\n", "output": "1\n"}, {"input": "1 70\n6 5\n", "output": "2\n"}] |
|
201 | A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place? [Image]
One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs W_{r} grams and each blue candy weighs W_{b} grams. Eating a single red candy gives Om Nom H_{r} joy units and eating a single blue candy gives Om Nom H_{b} joy units.
Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than C grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.
-----Input-----
The single line contains five integers C, H_{r}, H_{b}, W_{r}, W_{b} (1 ≤ C, H_{r}, H_{b}, W_{r}, W_{b} ≤ 10^9).
-----Output-----
Print a single integer — the maximum number of joy units that Om Nom can get.
-----Examples-----
Input
10 3 5 2 3
Output
16
-----Note-----
In the sample test Om Nom can eat two candies of each type and thus get 16 joy units. | interview | [{"code": "import sys\nf = sys.stdin\n\nC, Hr, Hb, Wr, Wb = map(int, f.readline().strip().split())\n\nif Hr/Wr < Hb/Wb:\n Hr, Hb, Wr, Wb = Hb, Hr, Wb, Wr\n\nif (C % Wr) == 0 and (C // Wr) > 0:\n print((C // Wr)*Hr)\n \nelif (C // Wr) == 0:\n print((C // Wb)*Hb)\n\nelse:\n nmax = (C // Wr)\n pmax = nmax*Hr + ((C - nmax*Wr) // Wb) * Hb\n dmax = ((C - (nmax-0)*Wr) % Wb)\n #print(0, pmax, dmax)\n \n #\n #pm1 = (nmax-1)*Hr + ((C - (nmax-1)*Wr) // Wb) * Hb \n #if pm1>pmax:\n # pmax = pm1\n if Hr/Wr > Hb/Wb:\n dx = dmax * (Hb/Wb) / (Hr/Wr - Hb/Wb) \n elif Hr/Wr < Hb/Wb: \n dx = 0 \n else:\n dx = Wb * Wr\n if Wr<Wb:\n nmax = (C // Wb)\n pmax = nmax*Hb + ((C - nmax*Wb) // Wr) * Hr \n if Wr>Wb:\n nmax = (C // Wr)\n pmax = nmax*Hr + ((C - nmax*Wr) // Wb) * Hb \n \n if Wr>Wb and dx>0: \n for k in range(1, C//Wr):\n if k*Wr > dx:\n break\n pk = (nmax-k)*Hr + ((C - (nmax-k)*Wr) // Wb) * Hb \n dk = ((C - (nmax-k)*Wr) % Wb)\n #print(k, pmax, pk, dk)\n if pk>pmax:\n pmax = pk\n if dk==0 :\n break\n elif Wr<Wb and dx>0: \n for j in range(1, C//Wb+1):\n k = nmax - (C-j*Wb)//Wr\n if k*Wr > dx:\n break\n \n pk = (nmax-k)*Hr + ((C - (nmax-k)*Wr) // Wb) * Hb \n dk = ((C - (nmax-k)*Wr) % Wb)\n #print(j, k, pmax, pk, dk, (nmax-k), ((C - (nmax-k)*Wr) // Wb) )\n if pk>pmax:\n pmax = pk\n #dmax = dk\n if dk==0 :\n break \n \n# elif Wr<Wb and dx>0: \n# for j in range(1, C//Wb+1):\n# k = (j*Wb - dmax)//Wr\n# if k*Wr > dx:\n# break\n# pk = (nmax-k)*Hr + ((C - (nmax-k)*Wr) // Wb) * Hb \n# dk = ((C - (nmax-k)*Wr) % Wb)\n# print(j, k, pmax, pk, dk, (nmax-k), ((C - (nmax-k)*Wr) // Wb) )\n# if pk>pmax:\n# pmax = pk\n# #dmax = dk\n# if dk==0 :\n# break\n \n print(pmax) ", "passed": true, "time": 0.19, "memory": 14468.0, "status": "done"}, {"code": "m, h1, h2, w1, w2 = map(int, input().split())\nif h2 / w2 > h1 / w1:\n h1, h2 = h2, h1\n w1, w2 = w2, w1\nif w1 ** 2 >= m:\n res = 0\n for i in range(int(m ** 0.5 + 1)):\n if i * w1 <= m:\n new = i * h1 + (m - w1 * i) // w2 * h2\n res = max(res, new)\n print(res)\n return\nres = 0\nfor i in range(int(m ** 0.5 + 5)):\n new_res = i * h2 + ((m - i * w2) // w1) * h1\n res = max(res, new_res)\nprint(res)", "passed": true, "time": 0.7, "memory": 14384.0, "status": "done"}, {"code": "a, b, c, d, e = list(map(int, input().split(' ')))\ncheck = int(a**0.5)\n\n#red candy\n#height b\n#weight d\n\n#blue candy\n#height c\n#weight e\n\nans = 0\nfor red in range(check+1):\n blue = (a-d*red)//(e)\n if blue >= 0:\n ans = max(ans, red*b+blue*c)\n\nfor blue in range(check+1):\n red = (a-e*blue)//(d)\n if red >= 0:\n ans = max(ans, red*b+blue*c)\n\nprint(ans)", "passed": true, "time": 1.33, "memory": 14496.0, "status": "done"}, {"code": "c, hr, hb, wr, wb = map(int, input().split())\ns = 0\n\nif wb < wr: hr, hb, wr, wb = hb, hr, wb, wr\nif wb * wb > c:\n for nb in range(c // wb + 1):\n s = max(s, nb * hb + hr * ((c - wb * nb) // wr))\nelse:\n if hr * wb < hb * wr: hr, hb, wr, wb = hb, hr, wb, wr\n\n for nb in range(min(31625, c // wb + 1)):\n s = max(s, nb * hb + hr * ((c - wb * nb) // wr))\nprint(s)", "passed": true, "time": 0.64, "memory": 14400.0, "status": "done"}, {"code": "import math\ndef solve(c,hr,hb,wr,wb):\n INF = math.ceil(math.sqrt(c))\n if wb > wr:\n wb,wr = wr,wb\n hb,hr = hr,hb\n if wr > INF:\n ans = 0\n i = 0\n while i * wr <= c and i < INF:\n ans = max(ans,i * hr + ((c - i * wr) // wb) * hb)\n i+=1\n return ans\n else:\n if wr * hb > hr * wb:\n wb,wr = wr,wb\n hb,hr = hr,hb\n ans = 0\n j = 0\n while j * wb <= c and j <= wr:\n ans = max(ans,j * hb + ((c - j * wb) // wr) * hr)\n j+=1\n return ans\n\nc,hr,hb,wr,wb = list(map(int,input().split()))\nprint(solve(c,hr,hb,wr,wb))\n", "passed": true, "time": 0.2, "memory": 14404.0, "status": "done"}, {"code": "__author__ = 'trunghieu11'\n\ndef calc(n, h1, h2, w1, w2):\n answer = 0\n len = n // w1\n for i in range(0, min(len, 100000) + 1):\n answer = max(answer, i * h1 + (n - i * w1) // w2 * h2)\n return answer\n\nn, hR, hB, wR, wB = map(int, input().split())\nprint(max(calc(n, hR, hB, wR, wB), calc(n, hB, hR, wB, wR)))", "passed": true, "time": 3.35, "memory": 14312.0, "status": "done"}, {"code": "def main():\n c, hr, hb, wr, wb = (int(i) for i in input().split())\n\n if wb < c**(1/2) > wr:\n if hr / wr < hb / wb:\n wr, hr, wb, hb = wb, hb, wr, hr\n mx = 0\n for i in range(wr + 1):\n tmx = i * hb + ((c - i * wb) // wr) * hr\n mx = tmx if tmx > mx else mx\n else:\n if wr <= wb:\n wr, hr, wb, hb = wb, hb, wr, hr\n nr = 0\n mx = 0\n while nr * wr <= c:\n tmx = nr * hr + ((c - nr * wr) // wb) * hb\n mx = tmx if tmx > mx else mx\n nr += 1\n\n print(mx)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 1.09, "memory": 14524.0, "status": "done"}, {"code": "import math\nc,hr,hb,wr,wb = list(map(int,input().split()))\nif wr < wb:\n wr, wb = wb, wr\n hr, hb = hb, hr\nans = 0\nif wr * wr >= c:\n for i in range(c//wr+1):\n ans = max(ans, i*hr+(c-i*wr)//wb*hb)\nelse:\n if hr*wb < hb*wr:\n wr, wb = wb, wr\n hr, hb = hb, hr\n for i in range (wr):\n ans = max(ans, i*hb+(c-i*wb)//wr*hr)\nprint(ans)\n \n\n", "passed": true, "time": 0.18, "memory": 14588.0, "status": "done"}, {"code": "import math\nc,hr,hb,wr,wb = map(int,input().split())\nif wr < wb:\n wr, wb = wb, wr\n hr, hb = hb, hr\nans = 0\nif wr * wr >= c:\n for i in range(c//wr+1):\n ans = max(ans, i*hr+(c-i*wr)//wb*hb)\nelse:\n if hr*wb < hb*wr:\n wr, wb = wb, wr\n hr, hb = hb, hr\n for i in range (wr):\n ans = max(ans, i*hb+(c-i*wb)//wr*hr)\nprint(ans)", "passed": true, "time": 0.18, "memory": 14616.0, "status": "done"}, {"code": "def main():\n c, hr, hb, wr, wb = map(int, input().split())\n ans = 0\n for i in range(10**6 + 1):\n if i * wr <= c:\n ans = max(ans, i * hr + ((c - i * wr) // wb) * hb)\n if i * wb <= c:\n ans = max(ans, i * hb + ((c - i * wb) // wr) * hr)\n print(ans)\n\n\n\n\n\nmain()", "passed": true, "time": 37.1, "memory": 14464.0, "status": "done"}, {"code": "C, Hr, Hb, Wr, Wb = map(int, input().split())\nans = 0\nfor i in range(10 ** 5):\n if Wr * i <= C:\n ans = max(ans, Hr * i + (C - Wr * i) // Wb * Hb)\nfor i in range(10 ** 5):\n if Wb * i <= C:\n ans = max(ans, Hb * i + (C - Wb * i) // Wr * Hr)\nprint(ans)", "passed": true, "time": 3.93, "memory": 14516.0, "status": "done"}, {"code": "C, Hr, Hb, Wr, Wb = map(int, input().split())\nans = 0\nfor i in range(3 * 10 ** 5):\n if Wr * i <= C:\n ans = max(ans, Hr * i + (C - Wr * i) // Wb * Hb)\nfor i in range(3 * 10 ** 5):\n if Wb * i <= C:\n ans = max(ans, Hb * i + (C - Wb * i) // Wr * Hr)\nprint(ans)", "passed": true, "time": 11.19, "memory": 14312.0, "status": "done"}, {"code": "C, Hr, Hb, Wr, Wb = map(int, input().split())\nans = 0\nfor i in range(5 * 10 ** 5):\n if Wr * i <= C:\n ans = max(ans, Hr * i + (C - Wr * i) // Wb * Hb)\nfor i in range(5 * 10 ** 5):\n if Wb * i <= C:\n ans = max(ans, Hb * i + (C - Wb * i) // Wr * Hr)\nprint(ans)", "passed": true, "time": 18.82, "memory": 14316.0, "status": "done"}, {"code": "import math\nc,x,y,a,b = list(map(int,input().split()))\nlim = int(math.sqrt(c))\nans = 0\nfor i in range(lim):\n if(c>=i*a):\n ans = max(ans,x*i+(c-i*a)//b*y)\n if(c>=i*b):\n ans = max(ans,y*i+(c-i*b)//a*x)\nprint(ans)\n\n\n\n", "passed": true, "time": 1.28, "memory": 14576.0, "status": "done"}, {"code": "import math\n\nc, hr, hb, wr, wb = map(int, input().split())\ns = int(math.sqrt(c))\nans = 0\nfor i in range(s):\n if c >= i * wr:\n ans = max(ans, hr * i + (c - i * wr) // wb * hb)\n if c >= i * wb:\n ans = max(ans, hb * i + (c - i * wb) // wr * hr)\n\nprint(ans)", "passed": true, "time": 1.28, "memory": 14512.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\n#max_grams = 10 \n#weight_r = 3 \n#joy_r = 5 \n#weight_b = 2 \n#joy_b = 3\n\n\ndef max_joy(max_grams, weight_r, joy_r, weight_b, joy_b, jollies, memoiser): \n if max_grams < 0: \n return 0\n \n if max_grams == 0: \n return jollies\n \n if (str(max_grams) in memoiser): \n if jollies >= memoiser[str(max_grams)]: \n return 0\n \n memoiser[str(max_grams)] = jollies\n \n \n res1 = max_joy(max_grams - weight_r, weight_r, joy_r, weight_b, joy_b, jollies + joy_r, memoiser) \n res2 = max_joy(max_grams - weight_b, weight_r, joy_r, weight_b, joy_b, jollies + joy_b, memoiser) \n \n return max(res1, res2)\n\ndef main(): \n # max_grams, weight_r, joy_r, weight_b, joy_b = [int(x) for x in input().split()]\n max_grams = 982068341 \n weight_r = 55 \n joy_r = 57 \n weight_b = 106 \n joy_b = 109\n memoiser = {}\n jollies = 0\n res = max_joy(max_grams, weight_r, joy_r, weight_b, joy_b, jollies, memoiser)\n print(res)\n\n#main()\n\nimport math\nc,x,y,a,b = map(int,input().split())\nlim = int(math.sqrt(c))\nans = 0\nfor i in range(lim):\n if(c>=i*a):\n ans = max(ans,x*i+(c-i*a)//b*y)\n if(c>=i*b):\n ans = max(ans,y*i+(c-i*b)//a*x)\nprint(ans)", "passed": true, "time": 1.29, "memory": 14680.0, "status": "done"}, {"code": "C, Hr, Hb, Wr, Wb = list(map(int, input().split()))\n\nans = 0\n\nfor i in range(10 ** 5):\n\n if Wr * i <= C:\n\n ans = max(ans, Hr * i + (C - Wr * i) // Wb * Hb)\n\nfor i in range(10 ** 5):\n\n if Wb * i <= C:\n\n ans = max(ans, Hb * i + (C - Wb * i) // Wr * Hr)\n\nprint(ans)\n\n\n\n# Made By Mostafa_Khaled\n", "passed": true, "time": 3.9, "memory": 14404.0, "status": "done"}, {"code": "C, Pr, Pb, Wr, Wb = list(map(int, input().split()))\nresult = 0\nif Wr * Wr >= C:\n i = 0\n while Wr * i <= C:\n j = int((C - Wr * i) / Wb)\n result = max(result, Pr * i + Pb * j)\n i += 1\n print(result)\n return\n\nif Wb * Wb >= C:\n i = 0\n while Wb * i <= C:\n j = int((C - Wb * i) / Wr)\n result = max(result, Pb * i + Pr * j)\n i += 1\n print(result)\n return\n\nAb = Pb / Wb\nAr = Pr / Wr\n\nif Ab < Ar:\n i = 0\n while i * i <= C:\n j = int((C - Wb * i) / Wr)\n result = max(result, Pb * i + Pr * j)\n i += 1\n print(result)\nelse:\n i = 0\n while i * i <= C:\n j = int((C - Wr * i) / Wb)\n result = max(result, Pr * i + Pb * j)\n i += 1\n print(result)\n", "passed": true, "time": 0.81, "memory": 14564.0, "status": "done"}] | [{"input": "10 3 5 2 3\n", "output": "16\n"}, {"input": "5 3 1 6 7\n", "output": "0\n"}, {"input": "982068341 55 57 106 109\n", "output": "513558662\n"}, {"input": "930064129 32726326 25428197 83013449 64501049\n", "output": "363523396\n"}, {"input": "927155987 21197 15994 54746 41309\n", "output": "358983713\n"}, {"input": "902303498 609628987 152407246 8 2\n", "output": "68758795931537065\n"}, {"input": "942733698 9180 9072 1020 1008\n", "output": "8484603228\n"}, {"input": "951102310 39876134 24967176 70096104 43888451\n", "output": "539219654\n"}, {"input": "910943911 107 105 60 59\n", "output": "1624516635\n"}, {"input": "910943911 38162 31949 67084 56162\n", "output": "518210503\n"}, {"input": "910943911 9063 9045 1007 1005\n", "output": "8198495199\n"}, {"input": "903796108 270891702 270891702 1 1\n", "output": "244830865957095816\n"}, {"input": "936111602 154673223 309346447 1 2\n", "output": "144791399037089047\n"}, {"input": "947370735 115930744 347792233 1 3\n", "output": "109829394468167085\n"}, {"input": "958629867 96557265 386229061 1 4\n", "output": "92562678344491221\n"}, {"input": "969889000 84931386 424656931 1 5\n", "output": "82374017230131800\n"}, {"input": "925819493 47350513 28377591 83230978 49881078\n", "output": "520855643\n"}, {"input": "934395168 119 105 67 59\n", "output": "1662906651\n"}, {"input": "934395168 29208 38362 51342 67432\n", "output": "531576348\n"}, {"input": "934395168 9171 9045 1019 1005\n", "output": "8409556512\n"}, {"input": "946401698 967136832 483568416 2 1\n", "output": "457649970001570368\n"}, {"input": "962693577 967217455 967217455 2 2\n", "output": "465567015261784540\n"}, {"input": "989976325 646076560 969114840 2 3\n", "output": "319800249268721000\n"}, {"input": "901235456 485501645 971003291 2 4\n", "output": "218775648435471424\n"}, {"input": "912494588 389153108 972882772 2 5\n", "output": "177550052841687584\n"}, {"input": "995503930 29205027 18903616 51333090 33226507\n", "output": "565303099\n"}, {"input": "983935533 115 108 65 61\n", "output": "1742049794\n"}, {"input": "983935533 33986 27367 59737 48104\n", "output": "559787479\n"}, {"input": "983935533 7105 7056 1015 1008\n", "output": "6887548731\n"}, {"input": "994040035 740285170 246761723 3 1\n", "output": "245291032098926983\n"}, {"input": "905299166 740361314 493574209 3 2\n", "output": "223416160034288041\n"}, {"input": "911525551 740437472 740437472 3 3\n", "output": "224975891301803200\n"}, {"input": "922784684 566833132 755777509 3 4\n", "output": "174354977531116762\n"}, {"input": "955100178 462665160 771108601 3 5\n", "output": "147297192414486195\n"}, {"input": "949164751 36679609 23634069 64467968 41539167\n", "output": "537909080\n"}, {"input": "928443151 60 63 106 112\n", "output": "525533853\n"}, {"input": "928443151 25031 33442 43995 58778\n", "output": "528241752\n"}, {"input": "928443151 1006 1012 1006 1012\n", "output": "928443150\n"}, {"input": "936645623 540336743 135084185 4 1\n", "output": "126526011319256470\n"}, {"input": "947904756 540408420 270204210 4 2\n", "output": "128063927875111380\n"}, {"input": "959163888 540480074 405360055 4 3\n", "output": "129602242291091928\n"}, {"input": "970423020 540551739 540551739 4 4\n", "output": "131140962756657945\n"}, {"input": "976649406 455467553 569334442 4 5\n", "output": "111208028918928288\n"}, {"input": "923881933 18531902 53987967 32570076 94884602\n", "output": "524563246\n"}, {"input": "977983517 57 63 101 112\n", "output": "551931291\n"}, {"input": "977983517 29808 22786 52389 40047\n", "output": "556454318\n"}, {"input": "977983517 9009 9108 1001 1012\n", "output": "8801851608\n"}, {"input": "984283960 367291526 73458305 5 1\n", "output": "72303831537144592\n"}, {"input": "990510345 367358723 146943489 5 2\n", "output": "72774523091497887\n"}, {"input": "901769477 367425909 220455545 5 3\n", "output": "66266693959035917\n"}, {"input": "907995862 367493085 293994468 5 4\n", "output": "66736440098722854\n"}, {"input": "924287742 367560271 367560271 5 5\n", "output": "67946290439275508\n"}, {"input": "1000000000 1000 999 100 1000000000\n", "output": "10000000000\n"}, {"input": "999999999 10 499999995 2 99999999\n", "output": "4999999995\n"}, {"input": "999999999 1 1000000000 2 1000000000\n", "output": "499999999\n"}, {"input": "999999997 2 999999997 2 999999997\n", "output": "999999997\n"}, {"input": "1000000000 1 1 11 11\n", "output": "90909090\n"}, {"input": "999999999 999999998 5 999999999 5\n", "output": "999999998\n"}, {"input": "100000001 3 100000000 3 100000001\n", "output": "100000000\n"}, {"input": "999999999 2 3 1 2\n", "output": "1999999998\n"}, {"input": "1000000000 2 1 3 4\n", "output": "666666666\n"}, {"input": "999999999 10000 494999 2 99\n", "output": "4999999994999\n"}, {"input": "1000000000 1 1 1 1\n", "output": "1000000000\n"}, {"input": "998999 1000 999 1000 999\n", "output": "998999\n"}, {"input": "3 100 101 2 3\n", "output": "101\n"}, {"input": "345415838 13999 13997 13999 13997\n", "output": "345415838\n"}, {"input": "5000005 3 2 5 1\n", "output": "10000010\n"}, {"input": "1000000000 1 1 1 1000000000\n", "output": "1000000000\n"}, {"input": "999999999 3 2 10 3\n", "output": "666666666\n"}, {"input": "1000000000 1000 1000 1 1\n", "output": "1000000000000\n"}, {"input": "200000001 100000002 1 100000001 1\n", "output": "200000002\n"}, {"input": "100000000 1000000000 1 100000001 1\n", "output": "100000000\n"}, {"input": "1000000000 99 100 1 2\n", "output": "99000000000\n"}, {"input": "1000000000 5 5 1 1\n", "output": "5000000000\n"}, {"input": "1000000000 1 1000000000 1 1000000000\n", "output": "1000000000\n"}] |
|
202 | Professor GukiZ makes a new robot. The robot are in the point with coordinates (x_1, y_1) and should go to the point (x_2, y_2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position.
-----Input-----
The first line contains two integers x_1, y_1 ( - 10^9 ≤ x_1, y_1 ≤ 10^9) — the start position of the robot.
The second line contains two integers x_2, y_2 ( - 10^9 ≤ x_2, y_2 ≤ 10^9) — the finish position of the robot.
-----Output-----
Print the only integer d — the minimal number of steps to get the finish position.
-----Examples-----
Input
0 0
4 5
Output
5
Input
3 4
6 1
Output
3
-----Note-----
In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its y coordinate and get the finish position.
In the second example robot should simultaneously increase x coordinate and decrease y coordinate by one three times. | interview | [{"code": "a, b = map(int, input().split())\nd, c = map(int, input().split())\nprint(max(abs(a - d), abs(b - c)))", "passed": true, "time": 0.17, "memory": 14380.0, "status": "done"}, {"code": "x1, y1 = list(map(int, input().split()))\nx2, y2 = list(map(int, input().split()))\n\ndx = abs(x1 - x2)\ndy = abs(y1 - y2)\n\nprint(max(dx, dy))\n", "passed": true, "time": 0.2, "memory": 14300.0, "status": "done"}, {"code": "x1, x2 = map(int, input().split())\nx3, x4 = map(int, input().split())\na = abs(x2 - x4)\nb = abs(x1 - x3)\nprint(max(a, b))", "passed": true, "time": 0.16, "memory": 14368.0, "status": "done"}, {"code": "x1, y1 = map(int, input().split())\nx2, y2 = map(int, input().split())\nprint(max(abs(x1 - x2), abs(y1 - y2)))", "passed": true, "time": 0.25, "memory": 14592.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\ntry:\n while True:\n x1, y1 = list(map(int, input().split()))\n x2, y2 = list(map(int, input().split()))\n print(max(abs(x1 - x2), abs(y1 - y2)))\n\nexcept EOFError:\n pass\n", "passed": true, "time": 0.25, "memory": 14440.0, "status": "done"}, {"code": "x,y = map(int,input().split())\na,b = map(int,input().split())\nprint(max(abs(x-a),abs(y-b)))", "passed": true, "time": 0.16, "memory": 14400.0, "status": "done"}, {"code": "#author=\"_rabbit\"\na,b=list(map(int,input().split()))\nc,d=list(map(int,input().split()))\nprint(max(abs(a-c),abs(b-d)))\n", "passed": true, "time": 0.15, "memory": 14524.0, "status": "done"}, {"code": "a,b=[int(x)for x in input().split()]\nx,y=[int(x)for x in input().split()]\nprint(max(abs(a-x),abs(b-y)))", "passed": true, "time": 0.25, "memory": 14388.0, "status": "done"}, {"code": "x1, y1 = map(int, input().split())\nx2, y2 = map(int, input().split())\nx = abs(x2 - x1)\ny = abs(y2 - y1)\nprint(max(x, y))", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "x1,y1 = map(int,input().split())\nx2,y2 = map(int,input().split())\nprint (max(abs(x1-x2), abs(y1-y2)))", "passed": true, "time": 0.14, "memory": 14400.0, "status": "done"}, {"code": "3\n\n(x1, y1) = input().split()\n(x1, y1) = (int(x1), int(y1))\n(x2, y2) = input().split()\n(x2, y2) = (int(x2), int(y2))\n\nprint(max(abs(x1-x2), abs(y1-y2)))\n", "passed": true, "time": 0.25, "memory": 14500.0, "status": "done"}, {"code": "anitonezkousejkontrolovat = input()\nvidimte = input()\nzacatek = [int(n) for n in anitonezkousejkontrolovat.split()]\nkonec = [int(n) for n in vidimte.split()]\nrozdil1 = abs(zacatek[0]-konec[0])\nrozdil2 = abs(zacatek[1]-konec[1])\nprint(max(rozdil1,rozdil2))\n\n", "passed": true, "time": 0.15, "memory": 14308.0, "status": "done"}, {"code": "a,b=list(map(int,input().split(\" \")))\nc,d=list(map(int,input().split(\" \")))\nprint(max(abs(a-c),abs(b-d)))\n", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "x1,y1 = map(int,input().split())\nx2,y2 = map(int,input().split())\nx = abs(x1-x2)\ny = abs(y1-y2)\nb = max(x,y)\nprint(b)", "passed": true, "time": 0.16, "memory": 14512.0, "status": "done"}, {"code": "a,b=map(int,input().split())\nc,d=map(int,input().split())\nma= max( abs(a-c),abs(b-d))\nprint(ma)", "passed": true, "time": 0.97, "memory": 14472.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu Jan 21 14:59:34 2016\n\n@author: kebl4230\n\"\"\"\nstart = [int(entry) for entry in input().split()]\nend = [int(entry) for entry in input().split()]\nx_dist = abs(start[0] - end[0])\ny_dist = abs(start[1] - end[1])\nresult = x_dist + y_dist - min(x_dist,y_dist) * (1 if (x_dist > 0 and y_dist > 0) else 0)\nprint(result)", "passed": true, "time": 0.14, "memory": 14596.0, "status": "done"}, {"code": "from sys import stdin as fin\n\n# fin = open(\"ecr6a.in\", \"r\")\n\nx1, y1 = map(int, input().split())\nx2, y2 = map(int, input().split())\n\nsx, sy = abs(x1 - x2), abs(y1 - y2)\nprint(min(sx, sy) + abs(sx - sy))", "passed": true, "time": 0.25, "memory": 14256.0, "status": "done"}, {"code": "#A\n\nxi, yi = map(int,input().split())\nxf, yf = map(int, input().split())\nxf = abs(xf-xi)\nyf = abs(yf-yi)\nsteps = 0\nif xf == yf:\n steps += xf\nelif xf == 0:\n steps += yf\nelif yf == 0:\n steps += xf\nelse:\n reduce = min(xf,yf)\n steps += reduce\n steps += (max(xf,yf) - reduce)\nprint(steps)", "passed": true, "time": 0.16, "memory": 14492.0, "status": "done"}, {"code": "x1, y1 = list(map(int, input().split()))\nx2, y2 = list(map(int, input().split()))\nprint(max(abs(x1 - x2), abs(y1 - y2)))\n", "passed": true, "time": 0.14, "memory": 14376.0, "status": "done"}, {"code": "def __starting_point():\n x1, y1 = [int(x) for x in input().split()]\n x2, y2 = [int(x) for x in input().split()]\n\n print( max( abs(x1-x2),abs(y1-y2) ) )\n__starting_point()", "passed": true, "time": 0.24, "memory": 14356.0, "status": "done"}, {"code": "(x1,y1)=tuple(input().split())\n(x2,y2)=tuple(input().split())\n\nprint(max(abs(int(x1)-int(x2)),abs(int(y1)-int(y2))))", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "x1,y1=list(map(int,input().split(\" \")))\nx2,y2=list(map(int,input().split(\" \")))\n\nresult1=max(x1,x2)-min(x1,x2)\nresult2=max(y1,y2)-min(y1,y2)\n\nprint(max(result1,result2))", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "read = lambda: list(map(int, input().split()))\nx1, y1 = read()\nx2, y2 = read()\nprint(max(abs(y1 - y2), abs(x1 - x2)))\n", "passed": true, "time": 0.16, "memory": 14508.0, "status": "done"}, {"code": "import math\nx1, y1 = map(int, input().split())\nx2, y2 = map(int, input().split())\nd = 0\nxd = math.fabs(x1-x2)\nyd = math.fabs(y1-y2)\nd = int(max(xd ,yd))\nprint(d)", "passed": true, "time": 0.15, "memory": 14604.0, "status": "done"}] | [{"input": "0 0\n4 5\n", "output": "5\n"}, {"input": "3 4\n6 1\n", "output": "3\n"}, {"input": "0 0\n4 6\n", "output": "6\n"}, {"input": "1 1\n-3 -5\n", "output": "6\n"}, {"input": "-1 -1\n-10 100\n", "output": "101\n"}, {"input": "1 -1\n100 -100\n", "output": "99\n"}, {"input": "-1000000000 -1000000000\n1000000000 1000000000\n", "output": "2000000000\n"}, {"input": "-1000000000 -1000000000\n0 999999999\n", "output": "1999999999\n"}, {"input": "0 0\n2 1\n", "output": "2\n"}, {"input": "10 0\n100 0\n", "output": "90\n"}, {"input": "1 5\n6 4\n", "output": "5\n"}, {"input": "0 0\n5 4\n", "output": "5\n"}, {"input": "10 1\n20 1\n", "output": "10\n"}, {"input": "1 1\n-3 4\n", "output": "4\n"}, {"input": "-863407280 504312726\n786535210 -661703810\n", "output": "1649942490\n"}, {"input": "-588306085 -741137832\n341385643 152943311\n", "output": "929691728\n"}, {"input": "0 0\n4 0\n", "output": "4\n"}, {"input": "93097194 -48405232\n-716984003 -428596062\n", "output": "810081197\n"}, {"input": "9 1\n1 1\n", "output": "8\n"}, {"input": "4 6\n0 4\n", "output": "4\n"}, {"input": "2 4\n5 2\n", "output": "3\n"}, {"input": "-100000000 -100000000\n100000000 100000123\n", "output": "200000123\n"}, {"input": "5 6\n5 7\n", "output": "1\n"}, {"input": "12 16\n12 1\n", "output": "15\n"}, {"input": "0 0\n5 1\n", "output": "5\n"}, {"input": "0 1\n1 1\n", "output": "1\n"}, {"input": "-44602634 913365223\n-572368780 933284951\n", "output": "527766146\n"}, {"input": "-2 0\n2 -2\n", "output": "4\n"}, {"input": "0 0\n3 1\n", "output": "3\n"}, {"input": "-458 2\n1255 4548\n", "output": "4546\n"}, {"input": "-5 -4\n-3 -3\n", "output": "2\n"}, {"input": "4 5\n7 3\n", "output": "3\n"}, {"input": "-1000000000 -999999999\n1000000000 999999998\n", "output": "2000000000\n"}, {"input": "-1000000000 -1000000000\n1000000000 -1000000000\n", "output": "2000000000\n"}, {"input": "-464122675 -898521847\n656107323 -625340409\n", "output": "1120229998\n"}, {"input": "-463154699 -654742385\n-699179052 -789004997\n", "output": "236024353\n"}, {"input": "982747270 -593488945\n342286841 -593604186\n", "output": "640460429\n"}, {"input": "-80625246 708958515\n468950878 574646184\n", "output": "549576124\n"}, {"input": "0 0\n1 0\n", "output": "1\n"}, {"input": "109810 1\n2 3\n", "output": "109808\n"}, {"input": "-9 0\n9 9\n", "output": "18\n"}, {"input": "9 9\n9 9\n", "output": "0\n"}, {"input": "1 1\n4 3\n", "output": "3\n"}, {"input": "1 2\n45 1\n", "output": "44\n"}, {"input": "207558188 -313753260\n-211535387 -721675423\n", "output": "419093575\n"}, {"input": "-11 0\n0 0\n", "output": "11\n"}, {"input": "-1000000000 1000000000\n1000000000 -1000000000\n", "output": "2000000000\n"}, {"input": "0 0\n1 1\n", "output": "1\n"}, {"input": "0 0\n0 1\n", "output": "1\n"}, {"input": "0 0\n-1 1\n", "output": "1\n"}, {"input": "0 0\n-1 0\n", "output": "1\n"}, {"input": "0 0\n-1 -1\n", "output": "1\n"}, {"input": "0 0\n0 -1\n", "output": "1\n"}, {"input": "0 0\n1 -1\n", "output": "1\n"}, {"input": "10 90\n90 10\n", "output": "80\n"}, {"input": "851016864 573579544\n-761410925 -380746263\n", "output": "1612427789\n"}, {"input": "1 9\n9 9\n", "output": "8\n"}, {"input": "1000 1000\n1000 1000\n", "output": "0\n"}, {"input": "1 9\n9 1\n", "output": "8\n"}, {"input": "1 90\n90 90\n", "output": "89\n"}, {"input": "100 100\n1000 1000\n", "output": "900\n"}, {"input": "-1 0\n0 0\n", "output": "1\n"}, {"input": "-750595959 -2984043\n649569876 -749608783\n", "output": "1400165835\n"}, {"input": "958048496 712083589\n423286949 810566863\n", "output": "534761547\n"}, {"input": "146316710 53945094\n-523054748 147499505\n", "output": "669371458\n"}, {"input": "50383856 -596516251\n-802950224 -557916272\n", "output": "853334080\n"}, {"input": "-637204864 -280290367\n-119020929 153679771\n", "output": "518183935\n"}, {"input": "-100 -100\n-60 -91\n", "output": "40\n"}, {"input": "337537326 74909428\n-765558776 167951547\n", "output": "1103096102\n"}, {"input": "0 81\n18 90\n", "output": "18\n"}, {"input": "283722202 -902633305\n-831696497 -160868946\n", "output": "1115418699\n"}, {"input": "1000 1000\n-1000 1000\n", "output": "2000\n"}, {"input": "5 6\n4 8\n", "output": "2\n"}, {"input": "40572000 597493595\n-935051731 368493185\n", "output": "975623731\n"}, {"input": "-5 5\n5 5\n", "output": "10\n"}] |
|
203 | There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.
Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated: Each of n employees makes a statement. They make statements one by one starting from employees 1 and finishing with employee n. If at the moment when it's time for the i-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting). When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end. When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing with n who are still eligible to vote make their statements. The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction.
You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees.
The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats.
-----Output-----
Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.
-----Examples-----
Input
5
DDRRR
Output
D
Input
6
DDRRRR
Output
R
-----Note-----
Consider one of the voting scenarios for the first sample: Employee 1 denies employee 5 to vote. Employee 2 denies employee 3 to vote. Employee 3 has no right to vote and skips his turn (he was denied by employee 2). Employee 4 denies employee 2 to vote. Employee 5 has no right to vote and skips his turn (he was denied by employee 1). Employee 1 denies employee 4. Only employee 1 now has the right to vote so the voting ends with the victory of depublicans. | interview | [{"code": "n = int(input())\ns = input()\ncountr = s.count('R')\ncountd = n - countr\ncr = 0\ncd = 0\ni = 0\nnews = []\nwhile countr != 0 and countd != 0:\n if s[i] == 'D':\n if cd == 0:\n cr += 1\n countr -= 1\n news.append('D')\n else:\n cd -= 1\n else:\n if cr == 0:\n cd += 1\n countd -= 1\n news.append('R')\n else:\n cr -= 1\n i += 1\n if i >= n:\n s = list(news)\n news = []\n n = len(s)\n i = 0\n \nif countr > 0:\n print('R')\nelse:\n print('D')", "passed": true, "time": 0.15, "memory": 14332.0, "status": "done"}, {"code": "n = int(input())\na = []\nfor i in input():\n a.append(i)\nr, d = 0, 0\nwas_r, was_d = True, True\nwhile True:\n if was_r and was_d:\n was_r, was_d = False, False\n else:\n break\n for i in range(len(a)):\n if a[i] == \"R\":\n was_r = True\n if r != 0:\n r -= 1\n a[i] = 0\n else:\n d += 1\n elif a[i] == \"D\":\n was_d = True\n if d != 0:\n d -= 1\n a[i] = 0\n else:\n r += 1\nif was_r:\n print(\"R\")\nelse:\n print(\"D\")\n", "passed": true, "time": 0.15, "memory": 14576.0, "status": "done"}, {"code": "def get_opposite_vote(vote):\n return 'R' if vote == 'D' else 'D'\n\n\ndef codeforces(votes):\n # rs = votes.count('R')\n # ds = votes.count('D')\n blocked = {'R': 0, 'D': 0}\n\n while True:\n new_votes = ''\n for vote in votes:\n if blocked[vote] > 0:\n blocked[vote] -= 1\n else:\n blocked[get_opposite_vote(vote)] += 1\n new_votes += vote\n votes = new_votes\n\n if votes.count('R') == 0 or votes.count('D') == 0:\n break\n\n return votes[0]\n\n\n_ = input()\nvotes = input()\nprint(codeforces(votes))\n", "passed": true, "time": 0.14, "memory": 14552.0, "status": "done"}, {"code": "# Author: Maharshi Gor\nfrom collections import deque\ndef read(t:type=int):\n return t(input())\n\n\ndef read_arr(t=int):\n return [t(i) for i in str(input()).split()]\n\nD = deque()\nR = deque()\n\nk = read()\nS = input()\n\nn = len(S)\n\nfor i in range(len(S)):\n if S[i] == 'R':\n R.append(i)\n else:\n D.append(i)\n\nwhile R and D:\n r = R.popleft()\n d = D.popleft()\n if r < d:\n R.append(r+n)\n else:\n D.append(d+n)\n\nif R:\n print('R')\nelse:\n print('D')\n", "passed": true, "time": 0.17, "memory": 14464.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\ndd = 0\ndr = 0\nwhile len(s) > 1:\n t = ''\n cd = 0\n cr = 0\n for c in s:\n if c == 'D':\n if dd > 0:\n dd -= 1\n else:\n dr += 1\n t += c\n cd += 1\n else:\n if dr > 0:\n dr -= 1\n else:\n dd += 1\n t += c\n cr += 1\n s = t\n if cd == 0:\n s = 'R'\n break\n if cr == 0:\n s = 'D'\n break\n if dd >= cd:\n s = 'R'\n break\n if dr >= cr:\n s = 'D'\n break\n \nprint(s[0])", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "n=int(input())\nraby=[x for x in input()]\nnumD=0\nnumR=0\nflag=True\nwhile flag: \n cR=0\n cD=0\n for ind in range(len(raby)):\n if raby[ind]=='D':\n cD+=1\n if numR==0:\n numD+=1\n else:\n raby[ind]='N'\n numR-=1\n if raby[ind]=='R':\n cR+=1\n if numD==0:\n numR+=1\n else:\n raby[ind]='N'\n numD-=1\n if cD==0 or cR==0:\n flag=False\nif numD==0:\n print('R')\nelse:\n print('D')", "passed": true, "time": 0.17, "memory": 14400.0, "status": "done"}, {"code": "n = int(input())\ns = list(input())\ncurr_d = 0\ncurr_r = 0\nost_d = s.count(\"D\")\nost_r = s.count(\"R\")\nwhile True:\n for i in range(len(s)):\n if s[i] == \"D\":\n if curr_d > 0:\n s[i] = \"N\"\n ost_d -=1\n curr_d -= 1\n else:\n curr_r += 1\n if s[i] == \"R\":\n if curr_r > 0:\n s[i] = \"N\"\n ost_r -= 1\n curr_r -= 1\n else:\n curr_d += 1\n if ost_d == 0 or ost_r == 0:\n break\nif ost_d == 0:\n print(\"R\")\nelse:\n print(\"D\")", "passed": true, "time": 0.26, "memory": 14604.0, "status": "done"}, {"code": "input()\ns = list(input())\nr, d = map(s.count, ('R', 'D'))\nrf, df = 0, 0\n\nwhile r > 0 and d > 0:\n for i, v in enumerate(s):\n if v == 'D':\n if rf:\n rf -= 1\n d -= 1\n s[i] = ' '\n else:\n df += 1\n elif v == 'R':\n if df:\n df -= 1\n r -= 1\n s[i] = ' '\n else:\n rf += 1\n\nprint('D' if d else 'R')", "passed": true, "time": 0.16, "memory": 14444.0, "status": "done"}, {"code": "n=int(input())\ns=input()\ndd,dr=0,0\ndr = 0\nwhile len(s) > 1:\n cd,cr,t=0,0,''\n for c in s:\n if c == 'D':\n if dd > 0:\n dd -= 1\n else:\n dr += 1\n t += c\n cd += 1\n else:\n if dr > 0:\n dr-=1\n else:\n dd+=1\n t+=c\n cr+=1\n s=t\n if cd == 0:\n s='R'\n break\n if cr==0:\n s='D'\n break\n if dd>=cd:\n s='R'\n break\n if dr>=cr:\n s='D'\n break\nprint(s[0])", "passed": true, "time": 0.17, "memory": 14388.0, "status": "done"}, {"code": "input()\na = list(input()) + ['']\ncnt = 0\n\nwhile len(set(a)) == 3:\n for i, v in enumerate(a):\n if v == 'D':\n if cnt < 0:\n a[i] = ''\n cnt += 1\n if v == 'R':\n if cnt > 0:\n a[i] = ''\n cnt -= 1\n\nfor ss in set(a):\n if ss:\n print(ss)\n\n", "passed": true, "time": 0.15, "memory": 14404.0, "status": "done"}, {"code": "from collections import deque\n\nn = int(input())\ns = input()\nR, D = deque(), deque()\n\nfor num in range(n):\n if s[num] == 'D':\n D.append(num)\n else:\n R.append(num)\n\nwhile D and R:\n d = D.popleft()\n r = R.popleft()\n if d < r:\n D.append(d+n)\n else:\n R.append(r+n)\n\nif D:\n print('D')\nelse:\n print('R')\n", "passed": true, "time": 0.17, "memory": 14388.0, "status": "done"}, {"code": "from collections import deque\n\nn = int(input())\ns = input()\n\nd = deque()\nr = deque()\n\nfor i, c in enumerate(s):\n if c == 'D':\n d.append(i)\n else:\n r.append(i)\n\nwhile len(d) > 0 and len(r) > 0:\n if d[0] < r[0]:\n d.append(d.popleft() + n)\n r.popleft()\n else:\n d.popleft()\n r.append(r.popleft() + n)\n\nprint('D' if len(d) > 0 else 'R')\n \n", "passed": true, "time": 0.14, "memory": 14388.0, "status": "done"}, {"code": "from collections import deque\nn, s, D, R = int(input()), input(), deque(), deque()\nfor i in range(n):\n if s[i] == \"D\":\n D.append(i)\n else:\n R.append(i)\nwhile len(D) and len(R):\n if D[0] < R[0]:\n D.append(D.popleft() + n)\n R.popleft()\n else:\n R.append(R.popleft() + n)\n D.popleft()\nif len(D):\n print(\"D\")\nelse:\n print(\"R\")", "passed": true, "time": 0.23, "memory": 14520.0, "status": "done"}, {"code": "from collections import deque\n\nn = int(input())\na = [x for x in input()]\n\nr1, r2 = int(0), int(0)\n\nfor x in a:\n\tif x == 'R':\n\t\tr1 += 1\n\telse:\n\t\tr2 += 1\n\nq = deque(a)\n\nc1, c2 = int(0), int(0)\n\nwhile True:\n\tnow = q.popleft()\n\tif not r1 or not r2:\n\t\tprint(now)\n\t\tbreak\n\tif now == 'R':\n\t\tif c2:\n\t\t\tc2 -= 1\n\t\t\tr1 -= 1\n\t\telse:\n\t\t\tc1 += 1\n\t\t\tq.append(now)\n\telse:\n\t\tif c1:\n\t\t\tc1 -= 1\n\t\t\tr2 -= 1\n\t\telse:\n\t\t\tc2 += 1\n\t\t\tq.append(now)\n", "passed": true, "time": 0.25, "memory": 14584.0, "status": "done"}, {"code": "from collections import deque \n\nn = int(input())\nline = list(input())\n\nD = deque()\nR = deque()\n\nfor i in range(n):\n if line[i] == 'D':\n D.append(i)\n else:\n R.append(i)\n\n\nwhile D and R:\n d = D.popleft()\n r = R.popleft()\n if d < r:\n D.append(d + n)\n else:\n R.append(r + n)\n\nif D:\n print('D')\nelse:\n print('R')", "passed": true, "time": 0.14, "memory": 14384.0, "status": "done"}, {"code": "s = input()\na = list(input())\na.append('')\ncnt = 0\n\nwhile len(set(a)) == 3:\n for i in range(len(a)):\n \n if a[i] == 'D':\n if cnt < 0:\n a[i] = ''\n cnt+=1\n if a[i] == 'R':\n if cnt > 0:\n a[i] = ''\n cnt-=1\n\nfor ss in set(a):\n if ss:\n print(ss)\n", "passed": true, "time": 0.17, "memory": 14512.0, "status": "done"}, {"code": "from collections import deque\nn = int(input())\ns = input()\nd = deque()\nr = deque()\nfor i in range(n):\n if s[i] == 'D':\n d.append(i)\n else:\n r.append(i)\nwhile True:\n # print('D',d)\n # print('R',r)\n \n if not d:\n print('R')\n break\n if not r:\n print('D')\n break \n if d[0] < r[0]:\n r.popleft()\n d.append(d.popleft()+n)\n else:\n d.popleft()\n r.append(r.popleft()+n)", "passed": true, "time": 0.16, "memory": 14604.0, "status": "done"}, {"code": "from collections import deque\nD = deque()\nR = deque()\nn = int(input())\npeople = input()\nfor i in range(len(people)):\n if people[i] == \"D\":\n D.append(i)\n else:\n R.append(i)\nwhile D and R:\n topr, topd = R.popleft(), D.popleft()\n if topr < topd:\n R.append(topr + n)\n else:\n D.append(topd + n)\nif R:\n print(\"R\")\nelse:\n print(\"D\")\n", "passed": true, "time": 0.14, "memory": 14456.0, "status": "done"}, {"code": "from collections import deque\n\nq = deque()\nn = int(input())\ns = input()\nfor let in s:\n q.append(let)\n \nb = 0\nwhile len(q) > 1 and abs(b) < 400000:\n #print(b)\n c = q.popleft()\n if c == 'D':\n if b >= 0:\n q.append(c)\n b += 1\n if c == 'R':\n if b <= 0:\n q.append(c)\n b -= 1\n\nprint(q.pop())", "passed": true, "time": 4.2, "memory": 14404.0, "status": "done"}, {"code": "s = input()\na = list(input())\na.append('')\ncnt = 0\n\nwhile len(set(a)) == 3:\n for i in range(len(a)):\n \n if a[i] == 'D':\n if cnt < 0:\n a[i] = ''\n cnt+=1\n if a[i] == 'R':\n if cnt > 0:\n a[i] = ''\n cnt-=1\n\nfor ss in set(a):\n if ss:\n print(ss)", "passed": true, "time": 0.14, "memory": 14424.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n#\nclass lq(list):\n\tdef __init__(self):\n\t\tself.value=[]\n\t\tself.lenght=0\n\t\tself.startPos=0\n\t\tself.maxLen = 50000\n\tdef append(self, item):\n\t\tself.value.append(item)\n\t\tself.lenght+=1\n\tdef pop(self):\n\t\tif self.startPos < self.maxLen:\n\t\t\trv= self.value[self.startPos]\n\t\t\tself.lenght-=1\n\t\t\tself.startPos+=1\n\t\t\treturn rv\n\t\telse:\n\t\t\trv= self.value[self.startPos]\n\t\t\tself.lenght-=1\n\t\t\tself.value[0:(self.startPos+1)]=[]\n\t\t\tself.startPos=0\n\t\t\treturn rv\n\nn = int(input())\ns = input()\n\nqforD = lq()\nqforR = lq()\nfor i in range(n):\n\tif s[i] == 'D':\n\t\tqforD.append(i)\n\telse:\n\t\tqforR.append(i)\ncnt = n\nwhile qforD.lenght>0 and qforR.lenght>0:\n\tdNum=qforD.pop()\n\trNum=qforR.pop()\n\tif dNum < rNum:\n\t\tqforD.append(cnt)\n\telse:\n\t\tqforR.append(cnt)\n\tcnt+=1\nif qforD.lenght == 0:\n\tprint('R')\nelse:\n\tprint('D')\n\n\t\n", "passed": true, "time": 0.25, "memory": 14504.0, "status": "done"}, {"code": "#\n# Created by Daniil Kozhanov. All rights reserved.\n# december 2016\n\nn = int(input())\ns = input()\nu = [1] * n\nu1 = 0\nu2 = 0\nc1 = s.count(\"D\")\nc2 = s.count(\"R\")\n\nwhile c1 != 0 and c2 !=0:\n for i in range(n):\n if s[i] == \"D\":\n if u[i] == 1:\n if u1 > 0:\n u1 -= 1\n u[i] -= 1\n c1 -= 1\n else:\n u2 += 1\n else:\n if u[i] == 1:\n if u2 > 0:\n u2 -= 1\n u[i] -= 1\n c2 -= 1\n else:\n u1 += 1\n\nif c2 == 0:\n print(\"D\")\nelse:\n print(\"R\")", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "\nimport collections\nn = int(input())\ns = input()\nR, D = collections.deque(), collections.deque()\n\nfor i in range(n):\n if s[i] == 'R': R.append(i)\n else: D.append(i)\n\n\n#print(R)\n#print(D)\n \nwhile R and D:\n r = R.popleft()\n d = D.popleft()\n #print(str(r) + \" is R and D \" + str(d))\n if r < d:\n R.append(n + r)\n else:\n D.append(n + d)\n\nif D:\n print('D')\nelse:\n print('R')", "passed": true, "time": 0.15, "memory": 14352.0, "status": "done"}, {"code": "a = int(input())\ns = input()\nb = []\nfor c in s:\n if c == 'D':\n b.append(1)\n else:\n b.append(0)\ncnt = [0] * 2\nwhile True:\n c = []\n for x in b:\n if cnt[x] > 0:\n cnt[x] -= 1;\n else:\n c.append(x);\n cnt[1 - x] += 1;\n if c == b:\n break\n b = c\nif b[0] == 0:\n print('R')\nelse:\n print('D')\n", "passed": true, "time": 0.15, "memory": 14492.0, "status": "done"}, {"code": "n = input()\na = input()\ncnt = 0\nwhile len(set(a)) == 2:\n new_a = []\n for i in range(len(a)):\n if a[i] == 'D':\n if cnt >= 0:\n new_a.append(a[i])\n cnt += 1\n else:\n if cnt <= 0:\n new_a.append(a[i])\n cnt -= 1\n a = new_a\nprint(a[0])\n\n", "passed": true, "time": 0.14, "memory": 14444.0, "status": "done"}] | [{"input": "5\nDDRRR\n", "output": "D\n"}, {"input": "6\nDDRRRR\n", "output": "R\n"}, {"input": "1\nD\n", "output": "D\n"}, {"input": "1\nR\n", "output": "R\n"}, {"input": "2\nDR\n", "output": "D\n"}, {"input": "3\nRDD\n", "output": "D\n"}, {"input": "3\nDRD\n", "output": "D\n"}, {"input": "4\nDRRD\n", "output": "D\n"}, {"input": "4\nDRRR\n", "output": "R\n"}, {"input": "4\nRDRD\n", "output": "R\n"}, {"input": "5\nDRDRR\n", "output": "D\n"}, {"input": "4\nRRRR\n", "output": "R\n"}, {"input": "5\nRDDRD\n", "output": "D\n"}, {"input": "5\nDDRRD\n", "output": "D\n"}, {"input": "5\nDRRRD\n", "output": "R\n"}, {"input": "5\nDDDDD\n", "output": "D\n"}, {"input": "6\nDRRDDR\n", "output": "D\n"}, {"input": "7\nRDRDRDD\n", "output": "R\n"}, {"input": "7\nRDRDDRD\n", "output": "D\n"}, {"input": "7\nRRRDDDD\n", "output": "R\n"}, {"input": "8\nRRRDDDDD\n", "output": "D\n"}, {"input": "9\nRRRDDDDDR\n", "output": "R\n"}, {"input": "9\nRRDDDRRDD\n", "output": "R\n"}, {"input": "9\nRRDDDRDRD\n", "output": "D\n"}, {"input": "10\nDDRRRDRRDD\n", "output": "D\n"}, {"input": "11\nDRDRRDDRDDR\n", "output": "D\n"}, {"input": "12\nDRDRDRDRRDRD\n", "output": "D\n"}, {"input": "13\nDRDDDDRRRRDDR\n", "output": "D\n"}, {"input": "14\nDDRDRRDRDRDDDD\n", "output": "D\n"}, {"input": "15\nDDRRRDDRDRRRDRD\n", "output": "D\n"}, {"input": "50\nDDDRDRDDDDRRRRDDDDRRRDRRRDDDRRRRDRDDDRRDRRDDDRDDDD\n", "output": "D\n"}, {"input": "50\nDRDDDDDDDRDRDDRRRDRDRDRDDDRRDRRDRDRRDDDRDDRDRDRDDR\n", "output": "D\n"}, {"input": "100\nRDRRDRDDDDRDRRDDRDRRDDRRDDRRRDRRRDDDRDDRDDRRDRDRRRDRDRRRDRRDDDRDDRRRDRDRRRDDRDRDDDDDDDRDRRDDDDDDRRDD\n", "output": "D\n"}, {"input": "100\nRRDRRDDDDDDDRDRRRDRDRDDDRDDDRDDRDRRDRRRDRRDRRRRRRRDRRRRRRDDDRRDDRRRDRRRDDRRDRRDDDDDRRDRDDRDDRRRDRRDD\n", "output": "R\n"}, {"input": "6\nRDDRDR\n", "output": "D\n"}, {"input": "6\nDRRDRD\n", "output": "R\n"}, {"input": "8\nDDDRRRRR\n", "output": "R\n"}, {"input": "7\nRRRDDDD\n", "output": "R\n"}, {"input": "7\nRDDRRDD\n", "output": "D\n"}, {"input": "9\nRDDDRRDRR\n", "output": "R\n"}, {"input": "5\nRDRDD\n", "output": "R\n"}, {"input": "5\nRRDDD\n", "output": "R\n"}, {"input": "8\nRDDRDRRD\n", "output": "R\n"}, {"input": "10\nDRRRDDRDRD\n", "output": "R\n"}, {"input": "7\nDRRDDRR\n", "output": "R\n"}, {"input": "12\nRDDDRRDRRDDR\n", "output": "D\n"}, {"input": "7\nRDRDDDR\n", "output": "D\n"}, {"input": "7\nDDRRRDR\n", "output": "R\n"}, {"input": "10\nDRRDRDRDRD\n", "output": "R\n"}, {"input": "21\nDDDDRRRRRDRDRDRDRDRDR\n", "output": "R\n"}, {"input": "11\nRDDDDDRRRRR\n", "output": "D\n"}, {"input": "10\nRDDDRRRDDR\n", "output": "D\n"}, {"input": "4\nRDDR\n", "output": "R\n"}, {"input": "7\nRDRDDRD\n", "output": "D\n"}, {"input": "8\nRDDDRRRD\n", "output": "R\n"}, {"input": "16\nDRRDRDRDRDDRDRDR\n", "output": "R\n"}, {"input": "8\nDRRDRDRD\n", "output": "R\n"}, {"input": "6\nRDDDRR\n", "output": "D\n"}, {"input": "10\nDDRRRRRDDD\n", "output": "D\n"}, {"input": "7\nDDRRRRD\n", "output": "R\n"}, {"input": "12\nRDDRDRDRRDRD\n", "output": "D\n"}, {"input": "9\nDDRRRDRDR\n", "output": "R\n"}, {"input": "20\nRDDRDRDRDRRDRDRDRDDR\n", "output": "D\n"}, {"input": "7\nRRDDDRD\n", "output": "D\n"}, {"input": "12\nDRRRRRRDDDDD\n", "output": "R\n"}, {"input": "12\nRDRDDRDRDRDR\n", "output": "D\n"}, {"input": "6\nDDDDDD\n", "output": "D\n"}, {"input": "10\nRRRDDRDDDD\n", "output": "R\n"}, {"input": "40\nRDDDRDDDRDRRDRDRRRRRDRDRDRDRRDRDRDRRDDDD\n", "output": "R\n"}, {"input": "50\nRRDDDRRDRRRDDRDDDDDRDDRRRRRRDRDDRDDDRDRRDDRDDDRDRD\n", "output": "D\n"}, {"input": "5\nRDRDR\n", "output": "R\n"}, {"input": "9\nDRRDRDDRR\n", "output": "R\n"}, {"input": "6\nDRRRDD\n", "output": "R\n"}, {"input": "10\nDDDDRRRRRR\n", "output": "D\n"}, {"input": "9\nRRDDDDRRD\n", "output": "D\n"}] |
|
204 | Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than $a$ and screen height not greater than $b$. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is $w$, and the height of the screen is $h$, then the following condition should be met: $\frac{w}{h} = \frac{x}{y}$.
There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers $w$ and $h$ there is a TV set with screen width $w$ and height $h$ in the shop.
Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers $w$ and $h$, beforehand, such that $(w \le a)$, $(h \le b)$ and $(\frac{w}{h} = \frac{x}{y})$.
In other words, Monocarp wants to determine the number of TV sets having aspect ratio $\frac{x}{y}$, screen width not exceeding $a$, and screen height not exceeding $b$. Two TV sets are considered different if they have different screen width or different screen height.
-----Input-----
The first line contains four integers $a$, $b$, $x$, $y$ ($1 \le a, b, x, y \le 10^{18}$) — the constraints on the screen width and height, and on the aspect ratio.
-----Output-----
Print one integer — the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.
-----Examples-----
Input
17 15 5 3
Output
3
Input
14 16 7 22
Output
0
Input
4 2 6 4
Output
1
Input
1000000000000000000 1000000000000000000 999999866000004473 999999822000007597
Output
1000000063
-----Note-----
In the first example, there are $3$ possible variants: $(5, 3)$, $(10, 6)$, $(15, 9)$.
In the second example, there is no TV set meeting the constraints.
In the third example, there is only one variant: $(3, 2)$. | interview | [{"code": "def gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\na, b, x, y = list(map(int, input().split()))\n\ng = gcd(x, y)\nx //= g\ny //= g\n\n\nprint(min(a // x, b // y))\n", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}, {"code": "from math import gcd\n\na, b, x, y = map(int, input().split())\nx, y = x // gcd(x, y), y // gcd(x, y)\nprint(min(a // x, b // y))", "passed": true, "time": 0.16, "memory": 14576.0, "status": "done"}, {"code": "USE_STDIO = False\n\nif not USE_STDIO:\n try: import mypc\n except: pass\n\ndef gcd(x, y):\n if x % y == 0: return y\n return gcd(y, x % y)\n\ndef main():\n a, b, x, y = list(map(int, input().split(' ')))\n g = gcd(x, y)\n x, y = x // g, y // g\n ans = min(a // x, b // y)\n print(ans)\n\ndef __starting_point():\n main()\n\n\n\n\n__starting_point()", "passed": true, "time": 0.18, "memory": 14332.0, "status": "done"}, {"code": "import math\nimport sys\na, b, x, y = list(map(int, input().split()))\ng = math.gcd(x, y)\nx //= g\ny //= g\nl = 0\nr = 10**18\nwhile r - l > 1:\n mid = (r + l) // 2\n if x * mid > a or y * mid > b:\n r = mid\n else:\n l = mid\nif x * r > a or y * r > b:\n print(l)\nelse:\n print(r)\n", "passed": true, "time": 0.15, "memory": 14588.0, "status": "done"}, {"code": "a,b,x,y = list(map(int,input().rsplit()))\ndef gdc(a,b):\n\tif b == 0:\n\t\treturn a\n\treturn gdc(b,a%b)\n\ng = gdc(x,y)\nx //= g\ny //= g\n\nprint(min(a//x,b//y))", "passed": true, "time": 0.15, "memory": 14328.0, "status": "done"}, {"code": "def gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\n\na, b, x, y = map(int, input().split())\nk = gcd(x, y)\nx //= k\ny //= k\nprint(min(a // x, b // y))", "passed": true, "time": 0.15, "memory": 14328.0, "status": "done"}, {"code": "def gcd(x, y):\n return x if y == 0 else gcd(y, x % y)\n\na,b,x,y = list(map(int,input().split()))\n\n\nval = gcd(x, y)\nx //= val\ny //= val\n\na_min = a // x\nb_min = b // y\n\nprint(min(a_min, b_min))\n", "passed": true, "time": 0.32, "memory": 14360.0, "status": "done"}, {"code": "from copy import deepcopy\nimport itertools\nfrom bisect import bisect_left\nfrom bisect import bisect_right\nimport math\nfrom collections import deque\nfrom collections import Counter\n\n\ndef read():\n return int(input())\n\n\ndef readmap():\n return map(int, input().split())\n\n\ndef readlist():\n return list(map(int, input().split()))\n\n\na, b, x, y = readmap()\n\ng = math.gcd(x, y)\n\nprint(min(a // (x // g), b // (y // g)))", "passed": true, "time": 0.17, "memory": 14544.0, "status": "done"}, {"code": "#JMD\n#Nagendra Jha-4096\n\n \nimport sys\nimport math\n\n#import fractions\n#import numpy\n \n###File Operations###\nfileoperation=0\nif(fileoperation):\n orig_stdout = sys.stdout\n orig_stdin = sys.stdin\n inputfile = open('W:/Competitive Programming/input.txt', 'r')\n outputfile = open('W:/Competitive Programming/output.txt', 'w')\n sys.stdin = inputfile\n sys.stdout = outputfile\n\n###Defines...###\nmod=1000000007\n \n###FUF's...###\ndef nospace(l):\n ans=''.join(str(i) for i in l)\n return ans\n \n \n \n##### Main ####\nt=1\nfor tt in range(t):\n #a=list(map(int,sys.stdin.readline().split(' ')))\n a,b,x,y= map(int, sys.stdin.readline().split(' '))\n g=math.gcd(x,y)\n x=x//g\n y=y//g\n\n print(min(a//x,b//y))\n \n#####File Operations#####\nif(fileoperation):\n sys.stdout = orig_stdout\n sys.stdin = orig_stdin\n inputfile.close()\n outputfile.close()", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "def gcd(a, b):\n\twhile b != 0:\n\t\ta %= b\n\t\ta, b = b, a\n\treturn a\n\na, b, x, y = [int(i) for i in input().split()]\n\ng = gcd(x, y)\nx //= g\ny //= g\n\nprint(min(a // x, b // y))", "passed": true, "time": 0.15, "memory": 14376.0, "status": "done"}, {"code": "a, b, x, y = list(map(int, input().split()))\nfrom math import gcd\ng = gcd(x, y)\nx //= g\ny //= g\nprint(min(a // x, b // y))\n", "passed": true, "time": 0.16, "memory": 14420.0, "status": "done"}, {"code": "def gcd(x, y):\n if y == 0:\n return x\n else:\n return gcd(y, x%y)\n\na, b, x, y = map(int, input().split())\n\ng = gcd(x, y)\nx //= g\ny //= g\n\nprint(min(a//x, b//y))", "passed": true, "time": 0.14, "memory": 14412.0, "status": "done"}, {"code": "\"\"\"#T=int(input())\n#for i in range(0,T):\nN=int(input())\n#a,b=map(int,input().split())\ns=[int(x) for x in input().split()]\nmn=min(s)\nmx=max(s)\ndiff=mx-mn+1\nans=diff-len(s)\nprint(ans)\n#for j in range(0,len(s)):\"\"\"\n\n\nimport math\na,b,x,y=list(map(int,input().split()))\ng=math.gcd(x,y)\nx=x//g\ny=y//g\na1=a//x\na2=b//y\nans=min(a1,a2)\nprint(ans)\n \n", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "from math import gcd\na,b,x,y=map(int,input().split())\nr=gcd(x,y)\nx//=r;y//=r\nprint(min(a//x,b//y))", "passed": true, "time": 0.26, "memory": 14564.0, "status": "done"}, {"code": "from math import gcd\n\na, b, x, y = map(int, input().split(' '))\n\ng = gcd(x, y)\n\nn1 = (a*g)//x\nn2 = (b*g)//y\n\nprint(min(n1,n2))", "passed": true, "time": 0.15, "memory": 14536.0, "status": "done"}, {"code": "def gcd(a, b):\n while (b != 0):\n x = a % b\n a = b\n b = x\n return a\n\na, b, x, y = list(map(int, input().strip().split(' ')))\n\nd = gcd(x, y)\nx1 = x // d\nx2 = y // d\n\nprint(min(a//x1, b//x2))\n", "passed": true, "time": 0.15, "memory": 14564.0, "status": "done"}, {"code": "import sys\nfrom fractions import Fraction\na,b,x,y=list(map(int,sys.stdin.readline().strip().split()))\nf=str(Fraction(x,y)).split('/')\nif(len(f)==1):\n x=int(f[0])\n y=1\nelse:\n x=int(f[0])\n y=int(f[1])\n\nprint(min(int(a/x),int(b/y)))\n\n", "passed": true, "time": 0.15, "memory": 14488.0, "status": "done"}] | [{"input": "17 15 5 3\n", "output": "3\n"}, {"input": "14 16 7 22\n", "output": "0\n"}, {"input": "4 2 6 4\n", "output": "1\n"}, {"input": "1000000000000000000 1000000000000000000 999999866000004473 999999822000007597\n", "output": "1000000063\n"}, {"input": "1 1 1 1\n", "output": "1\n"}, {"input": "1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000\n", "output": "1000000000000000000\n"}, {"input": "3 3 2 4\n", "output": "1\n"}, {"input": "3 3 2 6\n", "output": "1\n"}, {"input": "1000000000000000000 1000000000 1000000000000000000 1000000000\n", "output": "1000000000\n"}, {"input": "58 29 27 60\n", "output": "1\n"}, {"input": "27 68 94 30\n", "output": "0\n"}, {"input": "144528195586472793 10446456359175098 764897453635731472 213446506570409801\n", "output": "0\n"}, {"input": "145354434469588921 446675416227691239 504832165374736218 221558716891006574\n", "output": "0\n"}, {"input": "146180677647672345 468138913968516772 6298881766892948 923367383029480585\n", "output": "0\n"}, {"input": "147006920825755769 542505368524532032 208073625707521517 14411087792522426\n", "output": "0\n"}, {"input": "147833164003839193 978734324098080876 171380370006334775 22523289523184607\n", "output": "0\n"}, {"input": "148659402886955322 414963275376662424 30635495548814085 902968491117271450\n", "output": "2\n"}, {"input": "149485641770071450 851192235245178565 874621826044152778 488378180096620703\n", "output": "0\n"}, {"input": "150311889243122170 287421190818727409 837928574637933332 823487866450329936\n", "output": "0\n"}, {"input": "151138128126238298 947022187542019357 577863282081970781 831600068180992118\n", "output": "0\n"}, {"input": "925426546533829903 18916656036525111 656064699607651706 504175130621743249\n", "output": "0\n"}, {"input": "667266829466 1518201697184 23643010980 898976260568\n", "output": "6\n"}, {"input": "66 116 86 64\n", "output": "1\n"}, {"input": "1162212930906 1437938729466 2281245858132 1953656377395\n", "output": "1\n"}, {"input": "114 6 288 30\n", "output": "1\n"}, {"input": "1639979163162 1340495892562 2036036266388 3428977687772\n", "output": "1\n"}, {"input": "162 86 200 332\n", "output": "1\n"}, {"input": "126335330010 1260232924842 1082265520235 316350257105\n", "output": "0\n"}, {"input": "10 182 480 305\n", "output": "0\n"}, {"input": "301287041544 1311267722334 1925090137416 582114484904\n", "output": "1\n"}, {"input": "165 108 114 184\n", "output": "1\n"}, {"input": "1043706193704 1177988368866 2133416547786 1380684288366\n", "output": "2\n"}, {"input": "225 276 42 210\n", "output": "55\n"}, {"input": "1760355542088 1044709015401 1674331546848 2647835033212\n", "output": "1\n"}, {"input": "9 99 272 208\n", "output": "0\n"}, {"input": "2489889792360 924314563821 835883336325 4339921938905\n", "output": "1\n"}, {"input": "84 231 70 145\n", "output": "6\n"}, {"input": "219424042632 791035210353 5273494032066 418290299778\n", "output": "3\n"}, {"input": "280 104 158 114\n", "output": "1\n"}, {"input": "606209757964 135185624000 1875022910016 905391624870\n", "output": "0\n"}, {"input": "360 264 99 117\n", "output": "20\n"}, {"input": "1561742222476 104898922608 1477225799720 2031291351072\n", "output": "0\n"}, {"input": "72 72 312 64\n", "output": "1\n"}, {"input": "2534454556172 3927193117988 589501152415 3547767499745\n", "output": "38\n"}, {"input": "168 252 180 450\n", "output": "50\n"}, {"input": "3375849775910 3759581410230 1727984390290 1874681381962\n", "output": "3\n"}, {"input": "405 55 194 58\n", "output": "1\n"}, {"input": "4591740193030 3537449154450 1714308697782 442983863265\n", "output": "8\n"}, {"input": "25 260 129 285\n", "output": "0\n"}, {"input": "786155773670 3336791735150 1280120052592 1250148696512\n", "output": "9\n"}, {"input": "165 500 388 308\n", "output": "1\n"}, {"input": "2023521027270 3298933358415 137370252990 2592814018030\n", "output": "12\n"}, {"input": "285 245 270 270\n", "output": "245\n"}, {"input": "100000 1 3 2\n", "output": "0\n"}, {"input": "10000000000000 1 1 10000000000000\n", "output": "0\n"}, {"input": "1000000000000000000 1000000000000000000 1 2\n", "output": "500000000000000000\n"}, {"input": "4 2 4 3\n", "output": "0\n"}, {"input": "100 81 10 9\n", "output": "9\n"}, {"input": "1 1 1 1000000000000000000\n", "output": "0\n"}, {"input": "1000000000000000000 1000000000000000000 1 1\n", "output": "1000000000000000000\n"}, {"input": "1000000000000000000 1000000000000000000 1 1000000000000000000\n", "output": "1\n"}, {"input": "1 1 1 100000000000000000\n", "output": "0\n"}, {"input": "1000000000000000000 1 1 1\n", "output": "1\n"}, {"input": "1000000000000000000 1000000000000000000 1 999999822000007597\n", "output": "1\n"}, {"input": "1 1000000000000000000 1 1000000000000000000\n", "output": "1\n"}, {"input": "3 60 3 4\n", "output": "1\n"}, {"input": "1 1 1000000000000000 1\n", "output": "0\n"}, {"input": "2 3 1000000000000000000 1\n", "output": "0\n"}, {"input": "20 5 10 7\n", "output": "0\n"}, {"input": "5 5 1 1\n", "output": "5\n"}, {"input": "1000000000000000000 1000000000000000000 1000000000000000000 11235955056173033\n", "output": "1\n"}, {"input": "281474976710656 1 1 281474976710656\n", "output": "0\n"}, {"input": "500 500 1000000000000000000 1\n", "output": "0\n"}, {"input": "2 2 1000000000000000000 2\n", "output": "0\n"}, {"input": "1000000000000000000 1000000000000000000 1000000000000000000 1\n", "output": "1\n"}] |
|
205 | The number "zero" is called "love" (or "l'oeuf" to be precise, literally means "egg" in French), for example when denoting the zero score in a game of tennis.
Aki is fond of numbers, especially those with trailing zeros. For example, the number $9200$ has two trailing zeros. Aki thinks the more trailing zero digits a number has, the prettier it is.
However, Aki believes, that the number of trailing zeros of a number is not static, but depends on the base (radix) it is represented in. Thus, he considers a few scenarios with some numbers and bases. And now, since the numbers he used become quite bizarre, he asks you to help him to calculate the beauty of these numbers.
Given two integers $n$ and $b$ (in decimal notation), your task is to calculate the number of trailing zero digits in the $b$-ary (in the base/radix of $b$) representation of $n\,!$ (factorial of $n$).
-----Input-----
The only line of the input contains two integers $n$ and $b$ ($1 \le n \le 10^{18}$, $2 \le b \le 10^{12}$).
-----Output-----
Print an only integer — the number of trailing zero digits in the $b$-ary representation of $n!$
-----Examples-----
Input
6 9
Output
1
Input
38 11
Output
3
Input
5 2
Output
3
Input
5 10
Output
1
-----Note-----
In the first example, $6!_{(10)} = 720_{(10)} = 880_{(9)}$.
In the third and fourth example, $5!_{(10)} = 120_{(10)} = 1111000_{(2)}$.
The representation of the number $x$ in the $b$-ary base is $d_1, d_2, \ldots, d_k$ if $x = d_1 b^{k - 1} + d_2 b^{k - 2} + \ldots + d_k b^0$, where $d_i$ are integers and $0 \le d_i \le b - 1$. For example, the number $720$ from the first example is represented as $880_{(9)}$ since $720 = 8 \cdot 9^2 + 8 \cdot 9 + 0 \cdot 1$.
You can read more about bases here. | interview | [{"code": "n, k = map(int, input().split())\na = []\ni = 2\nwhile (i * i <= k):\n if (k % i == 0):\n a.append([i, 0])\n while (k % i == 0):\n a[len(a) - 1][1] += 1\n k //= i\n i += 1\nif (k > 1):\n a.append([k, 1])\nans = 10 ** 20\nfor i in a:\n cnt = 0\n x = i[0]\n while (x <= n):\n cnt += n // x;\n x *= i[0]\n ans = min(ans, cnt // i[1])\nprint(ans)", "passed": true, "time": 1.57, "memory": 14364.0, "status": "done"}, {"code": "b,a=list(map(int,input().split()))\ndelit=[]\nst=[]\ni=2\nuk=-1\nwhile i*i<=a:\n if a%i==0:\n delit.append(i)\n uk+=1\n st.append(0)\n while a%i==0:\n a//=i\n st[uk]+=1\n i+=1\nif a>1:\n delit.append(a)\n st.append(1)\ncoun=0\ncolvo=[0]*len(st)\ncop=b\nfor i in range(len(delit)):\n while cop>=delit[i]:\n colvo[i]+=cop//delit[i]\n cop//=delit[i]\n cop=b\ncoun=colvo[i]//st[i]\nfor i in range (len(st)):\n if colvo[i]//st[i]<coun:\n coun=colvo[i]//st[i]\nprint(coun)\n", "passed": true, "time": 1.57, "memory": 14416.0, "status": "done"}, {"code": "def factorial_1(n: int):\n for i in range(2, n+1):\n if i > n**0.5:\n return n\n elif n % i == 0:\n return i\n\n\ndef factorial_2(n: int):\n res = dict()\n while n > 1:\n f_now = factorial_1(n)\n n //= f_now\n res[f_now] = res.get(f_now, 0) + 1\n return res\n\n\nn, k = map(int, input().split())\nf_k, x = factorial_2(k), float('inf')\nfor key, val in f_k.items():\n qua_f, pow_ = 0, key\n while pow_ <= n:\n qua_f += n//pow_\n pow_ *= key\n x = min(x, qua_f//val)\nprint(x)", "passed": true, "time": 2.59, "memory": 14592.0, "status": "done"}, {"code": "from math import sqrt\ndef fact(a):\n nonlocal g\n nonlocal h\n for i in range(2, int(sqrt(a)) + 1):\n k = 0\n if a % i == 0:\n g.append(i)\n while a % i == 0:\n a = a // i\n k += 1\n if k != 0:\n h.append(k)\n if a > 1:\n g.append(a)\n h.append(1)\nn, k = list(map(int, input().split()))\ng = []\nh = []\nf = fact(k)\nmini = 100000000000000000000000000000000000000000000000000000000000\nfor i in range(len(g)):\n k1 = 0\n v = g[i]\n while n // g[i] > 0:\n k1 += n // g[i]\n g[i] *= v\n if k1 // h[i] < mini:\n mini = k1 // h[i]\nprint(mini)\n", "passed": true, "time": 4.31, "memory": 14516.0, "status": "done"}, {"code": "'''input\n5 2\n5 10\n6 9\n38 11\n'''\nn, b = map(int, input().split())\n\npm = 1\nk = 0\ni = 2\nans = float(\"inf\")\n\ndef calc(n, b, k):\n\tres = 0\n\tt = pm\n\twhile t <= n:\n\t\tres += n // t\n\t\tt *= pm\n\treturn res // k\n\nwhile i * i <= b:\n\tif b % i == 0:\n\t\tpm = i\n\t\tk = 0\n\t\twhile b % i == 0:\n\t\t\tb //= i\n\t\t\tk += 1\n\t\tans = min(ans, calc(n, b, k))\n\ti += 1\nif b > 1:\n\tpm = b\n\tk = 1\n\tans = min(ans, calc(n, b, k))\nprint(ans)", "passed": true, "time": 1.62, "memory": 14424.0, "status": "done"}, {"code": "def start(x, cnt):\n nonlocal ans\n i = x\n res = 0\n while i <= n:\n res += n // i\n i *= x\n ans = min(ans, res // cnt)\n\nn, b = map(int, input().split())\nnb = b\nans = 1e20\ni = 2\nwhile i * i <= b:\n if nb % i == 0:\n cnt = 0\n while nb % i == 0:\n cnt += 1\n nb //= i\n start(i, cnt)\n i += 1\nif nb > 1:\n start(nb, 1)\nprint(ans)", "passed": true, "time": 3.66, "memory": 14556.0, "status": "done"}, {"code": "n, b = map(int, input().split())\nans = 0\nd = 2\nbf = b\nfactors = []\nwhile d * d <= b:\n\tif b % d == 0:\n\t\tcnt = 0\n\t\twhile b % d == 0:\n\t\t\tcnt += 1\n\t\t\tb = b // d\n\t\tfactors.append((d, cnt))\n\td += 1\n\nif b > 1:\n\tfactors.append((b, 1))\n\ndef calc(x, y):\n\tyst = y\n\tans = 0\n\twhile yst <= x:\n\t\tans += x // yst\n\t\tyst *= y\n\treturn ans\n\nln = len(factors)\nans = min(calc(n, p[0]) // p[1] for p in factors)\nprint(ans)", "passed": true, "time": 1.58, "memory": 14608.0, "status": "done"}, {"code": "from math import sqrt\nn, b= [int(i) for i in input().split()]\ndef geg(n, k, l):\n if k<=n:\n return n//k+geg(n, k*l, l)\n else:\n return 0\ndef fact(b, n):\n D={}\n for i in range(2, round(sqrt(b))+1):\n if b%i == 0:\n s=0\n while b%i == 0:\n b=b//i\n s+=1\n D[i]=s\n L=[]\n for i in list(D.keys()):\n L.append(geg(n, i, i)//D[i])\n if b!=1:\n L.append(geg(n, b, b))\n m=L[0]\n for i in L:\n if m>i: m=i\n return m\nprint(fact(b, n))\n", "passed": true, "time": 1.94, "memory": 14424.0, "status": "done"}, {"code": "def __starting_point():\n n, b = (int(x) for x in input().split())\n\n primes = dict()\n\n bcopy = b\n for i in range(2, int(bcopy ** 0.5) + 1):\n cnt = 0\n while bcopy % i == 0:\n bcopy //= i\n cnt += 1\n if cnt > 0:\n primes[i] = cnt\n if bcopy > 1:\n primes[bcopy] = 1\n # print(primes)\n\n prime___npow = {}\n count = 0\n for prime in primes:\n pw = 1\n while prime ** pw <= n:\n count += n // prime ** pw\n pw += 1\n prime___npow[prime] = count\n count = 0\n # print(prime___npow)\n MAX = 10 ** 18\n count = MAX\n\n for prime in primes:\n curr = prime___npow[prime] // primes[prime]\n count = min(count, curr)\n if count == MAX:\n count = 0\n print(count)\n__starting_point()", "passed": true, "time": 2.46, "memory": 14472.0, "status": "done"}, {"code": "n,b = list(map(int,input().split()))\nif n == 1:\n print(0)\n return\na = []\nx = b\ni = 2\nwhile i*i <= x:\n if x%i == 0:\n cnt = 0\n while x%i == 0:\n x //= i\n cnt += 1\n a.append([i,cnt])\n if i == 2:\n i += 1\n else:\n i += 2\nif x > 1:\n a.append([x,1])\n\nans = 10**20\n\nfor i in a:\n lol = i[0]\n cur = i[0]\n cnt = 0\n while cur <= n:\n cnt += n//cur\n cur = cur*lol\n cnt //= i[1]\n ans = min(ans,cnt)\nprint(ans) \n", "passed": true, "time": 0.96, "memory": 14404.0, "status": "done"}, {"code": "n, b = map(int, input().split())\ncnt = {}\ni = 2\nwhile i * i <= b:\n while b % i == 0:\n cnt[i] = cnt.setdefault(i, 0) + 1\n b //= i\n i += 1\nif b > 1:\n cnt[b] = 1\n\ndef get(x):\n ret = 0\n d = x\n while d <= n:\n ret += n // d\n d *= x\n return ret\n\nans = int(1e30)\nfor (a, t) in cnt.items():\n ans = min(ans, get(a) // t)\nprint(ans)", "passed": true, "time": 1.59, "memory": 14600.0, "status": "done"}, {"code": "def f(p, q, n):\n w = p\n r = 0 \n while w <= n:\n r += n // w\n w *= p\n return r // q\nn,k=list(map(int, input().split()))\ni = 2\ns = -1\nwhile i*i <= k:\n if k % i == 0:\n cnt = 0\n while k % i == 0:\n k //= i\n cnt += 1\n j = f(i, cnt, n)\n if s < 0 or s > j:\n s = j\n i += 1\nif k > 1:\n j = f(k, 1, n)\n if s > j or s < 0:\n s = j\nprint(s)\n", "passed": true, "time": 1.57, "memory": 14388.0, "status": "done"}, {"code": "n,x=list(map(int,input().split()))\n\nimport math \nL=int(math.sqrt(x))\n\nFACT=dict()\n\nfor i in range(2,L+2):\n while x%i==0:\n FACT[i]=FACT.get(i,0)+1\n x=x//i\n\nif x!=1:\n FACT[x]=FACT.get(x,0)+1\n\n\nANS=float(\"inf\")\nfor f in FACT:\n ANS_f=0\n x=f\n\n while x<=n:\n ANS_f+=n//x\n x*=f\n\n #print(f,ANS_f)\n\n ANS=min(ANS,ANS_f//FACT[f])\n\nprint(ANS)\n\n \n \n", "passed": true, "time": 2.73, "memory": 14556.0, "status": "done"}, {"code": "n, b = [int(x) for x in input().split()]\ni = 2\nans = -1\ndef update(p):\n cnt = 0\n tmp = p\n while tmp<=n:\n cnt += n//tmp\n tmp *= p\n return cnt\nwhile i*i<=b:\n if b%i==0:\n q = 0\n while b%i==0:\n b //= i\n q += 1\n cnt = update(i)\n if ans==-1:\n ans = cnt//q\n else:\n ans = min(ans,cnt//q)\n i += 1\nif b>1:\n cnt = update(b)\n if ans==-1:\n ans = cnt\n else:\n ans = min(ans,cnt)\nprint(ans)\n", "passed": true, "time": 4.2, "memory": 14592.0, "status": "done"}, {"code": "import time\ndef primeFactor(N):\n i = 2\n ret = {}\n n = N\n mrFlg = 0\n if n < 0:\n ret[-1] = 1\n n = -n\n if n == 0:\n ret[0] = 1\n while i**2 <= n:\n k = 0\n while n % i == 0:\n n //= i\n k += 1\n ret[i] = k\n if i == 2:\n i = 3\n else:\n i += 2\n if i == 101 and n >= (2**20):\n def findFactorRho(N): # Prime\ufffd\u0142\u0202\ufffd\ufffd\ufffd\ufffd\u0182\ufffd\ufffdm\ufffdF\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u0302\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u0182\ufffd\ufffd\ufffdB\n def gcd(a, b):\n if b == 0:\n return a\n else:\n return gcd(b, a % b)\n def f(x, c):\n return ((x ** 2) + c) % N\n semi = [N]\n for c in range(1, 11):\n x=2\n y=2\n d=1\n while d == 1:\n x = f(x, c)\n y = f(f(y, c), c)\n d = gcd(abs(x-y), N)\n if d != N:\n if isPrimeMR(d):\n return d\n elif isPrimeMR(N//d):\n return N//d\n else:\n semi.append(d)\n\n semi = list(set(semi))\n print (semi)\n s = min(semi)\n for i in [2,3,5,7]:\n while True:\n t = int(s**(1/i)+0.5)\n if t**i == s:\n s = t\n if isPrimeMR(s):\n return s\n else:\n break\n\n i = 3\n while True:\n if s % i == 0:\n return i\n i += 2\n \n while True:\n if isPrimeMR(n):\n ret[n] = 1\n n = 1\n break\n else:\n mrFlg = 1\n j = findFactorRho(n)\n k = 0\n while n % j == 0:\n n //= j\n k += 1\n ret[j] = k\n if n == 1:\n break\n \n if n > 1:\n ret[n] = 1\n if mrFlg > 0:\n def dict_sort(X):\n Y={}\n for x in sorted(X.keys()):\n Y[x] = X[x]\n return Y\n ret = dict_sort(ret)\n return ret\n\ndef isPrime(N):\n if N <= 1:\n return False\n return sum(primeFactor(N).values()) == 1\n\ndef isPrimeMR(n):\n if n == 2: return True\n if n == 1 or n & 1 == 0: return False\n\n d = (n - 1) >> 1\n while d & 1 == 0:\n d >>= 1\n\n for a in [2, 3, 5, 7, 11, 13, 17, 19, 23]:\n t = d\n y = pow(a, t, n)\n\n while t != n - 1 and y != 1 and y != n - 1:\n y = (y * y) % n\n t <<= 1\n\n if y != n - 1 and t & 1 == 0:\n return False\n\n return True \n\ndef findPrime(N):\n if N < 0:\n return -1\n i = N\n while True:\n if isPrime(i):\n return i\n i += 1\n\ndef divisors(N):\n pf = primeFactor(N)\n ret = [1]\n for p in pf:\n ret_prev = ret\n ret = []\n for i in range(pf[p]+1):\n for r in ret_prev:\n ret.append(r * (p ** i))\n return sorted(ret)\n\nn, b = list(map(int, input().split()))\n\n# n = 10**18\n# b = 2\npf = primeFactor(b)\n# print(pf)\n\nma = 0\nX = []\nfor i in pf:\n ma = max(ma, i ** pf[i])\n X.append([i, pf[i], 0])\n\nmi = 10**30\nfor i in range(len(X)):\n j = 1\n while X[i][0]**j <= n:\n X[i][2] += n // (X[i][0]**j)\n j += 1\n \n mi = min(mi, X[i][2]//X[i][1])\n \nprint(mi)\n", "passed": true, "time": 0.17, "memory": 14604.0, "status": "done"}, {"code": "n, b = map(int, input().split())\nfac = []\ni = 2\nwhile i * i <= b:\n if b % i == 0:\n fac.append([i, 0])\n while b % i == 0:\n fac[-1][1] += 1\n b //= i\n i += 1\n\nif b > 1:\n fac.append([b, 1])\n\nans = int(1e20)\n\nfor i in fac:\n cnt = 0\n x = i[0]\n while x <= n:\n cnt += n // x\n x *= i[0]\n\n ans = min(ans, cnt // i[1])\n\nprint(ans)", "passed": true, "time": 1.58, "memory": 14372.0, "status": "done"}, {"code": "n,b=map(int,input().split())\ntemp=b \npf=[]\nfrom math import sqrt as S \nfor i in range(2,int(S(b))+1):\n if b%i==0:\n c=0 \n while b%i==0:\n c+=1 \n b=b//i \n pf.append([c,i])\nif b>1:\n pf.append([1,b])\nplen=len(pf)\ndef chk(z,p):\n ct=0 \n k=p \n while z//k>0:\n ct+=(z//k )\n k=k*p \n return ct \nmini=10**50\nfor i in range(plen):\n currp=pf[i][1]\n cnt=pf[i][0]\n cur=chk(n,currp)\n #print(cur)\n mini=min(mini,cur//cnt)\nprint(mini)", "passed": true, "time": 1.95, "memory": 14624.0, "status": "done"}, {"code": "import math,time\n\nfacts = []\nfcounts = []\n\n\ndef primefactors(n):\n\tc = 0\n\tif n%2 == 0:\n\t\twhile n%2==0:\n\t\t\tc+=1\n\t\t\tn = n//2\n\t\tfacts.append(2)\n\t\tfcounts.append(c)\n\tfor i in range(3, (int(math.sqrt(n)+1)),2):\n\t\tc = 0\n\t\tif n % i == 0:\n\t\t\twhile n % i == 0:\n\t\t\t\tc += 1\n\t\t\t\tn = n // i\n\t\t\tfacts.append(i)\n\t\t\tfcounts.append(c)\n\tif n>2:\n\t\tfacts.append(n)\n\t\tfcounts.append(1)\n\ndef task(x, u):\n\tt = 0\n\tp = u\n\twhile True:\n\t\tif x<p:\n\t\t\treturn t\n\t\telse:\n\t\t\tt+=(x//p)\n\t\tp*=u\n\n\nn, b = list(map(int, input().split()))\nprimefactors(b)\nl = len(facts)\nval = int(1e18)\n#print(facts)\n#print(fcounts)\nfor i in range(l):\n\tx = facts[i]\n\ta = task(n,x)\n\t#print(a, \"for value:\", x)\n\tval = min(val, a//fcounts[i])\nif val is int(1e18):\n\tprint(\"0\")\nelse:\n\tprint(int(val))\n\n\n", "passed": true, "time": 0.94, "memory": 14612.0, "status": "done"}, {"code": "n, b = list(map(int, input().split()))\nnow = 1\np = []\nisp = [1] * 1000001\nfor i in range(2, 10 ** 6 + 1):\n\tif isp[i]:\n\t\tp.append(i)\n\tfor x in p:\n\t\tif x * i > 1000000:\n\t\t\tbreak\n\t\tisp[x * i] = 0\n\t\tif i < x or i % x == 0:\n\t\t\tbreak\n# print(len(p))\nde = []\nfor prime in p:\n\tcount = 0\n\twhile b % prime == 0:\n\t\tb //= prime\n\t\tcount += 1\n\tif count:\n\t\tde.append((prime, count))\n\tif b < prime:\n\t\tbreak\nif b != 1:\n\tde.append((b, 1))\n# print(de)\n\nans = 10 ** 20\nfor pair in de:\n\ttmp = 1\n\thas = 0\n\tnum, count = pair[0], pair[1]\n\twhile tmp <= n:\n\t\ttmp *= num\n\t\thas += n // tmp\n\tans = min(ans, has // count)\nprint(ans)\n", "passed": true, "time": 16.47, "memory": 24292.0, "status": "done"}, {"code": "def factorize(n):\n\tresult = []\n\tN = n\n\ti = 2\n\twhile i * i <= N:\n\t\tif n % i == 0:\n\t\t\tpower = 0\n\t\t\twhile n % i == 0:\n\t\t\t\tn = n // i\n\t\t\t\tpower += 1\n\t\t\tresult.append((i, power))\n\t\ti += 1\n\tif n != 1:\n\t\tresult.append((n, 1))\n\treturn result\nn, b = input().split()\nn = int(n)\nb = int(b)\n#print(n, b)\np = factorize(b)\n\nans = None\nfor (prime, power) in p:\n\tk = prime\n\tpp = 0\n\twhile k <= n:\n\t\tpp += n // k\n\t\tk *= prime\n\tres = pp // power\n#\tprint(prime, power, pp, k, res)\n\tif ans == None or ans > res:\n\t\tans = res\n\nprint(ans)\t\t ", "passed": true, "time": 3.72, "memory": 14596.0, "status": "done"}, {"code": "from decimal import Decimal\n\nlist_int_input = lambda inp: list(map(int, inp.split()))\nint_input = lambda inp: int(inp)\nstring_to_list_input = lambda inp: list(inp)\n\nn,b=list(map(int,input().split()))\nimport math\nfacts=[]\nsqt=int(math.sqrt(b))\nfor i in range(2,sqt+1):\n j=0\n while b%i==0:\n j+=1\n b=int(Decimal(b)/Decimal(i))\n if j>0:\n facts.append((i, j))\n if b==1:\n break\nif b!=1:\n facts.append((b,1))\nsumm=10**18\nfor i in facts:\n num=i[0]\n times=i[1]\n cnt=0\n while int(n/num)!=0:\n cnt+=int(Decimal(n)/Decimal(num))\n num*=i[0]\n summ=min(summ,int(Decimal(cnt)/Decimal(times)))\nprint(summ)\n\n", "passed": true, "time": 1.61, "memory": 14672.0, "status": "done"}, {"code": "from collections import defaultdict\ndef decompose(n):\n x = n\n i = 2\n fac = defaultdict(lambda: 0)\n while i*i <= n:\n while x % i == 0:\n fac[i] += 1\n x = x//i\n if x == 1:\n break\n i += 1\n if x != 1:\n fac[x] += 1\n return fac\n\ndef main():\n n, b = list(map(int, input().split()))\n # print(n, b)\n require = decompose(b)\n ans = 10**18\n for key, val in list(require.items()):\n n2 = n\n acc = 0\n while n2 > 0:\n acc += n2 // key\n n2 //= key\n ans = min(ans, acc // val)\n print(ans)\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 2.99, "memory": 14580.0, "status": "done"}] | [{"input": "6 9\n", "output": "1\n"}, {"input": "38 11\n", "output": "3\n"}, {"input": "5 2\n", "output": "3\n"}, {"input": "5 10\n", "output": "1\n"}, {"input": "1000000000000000000 1000000000000\n", "output": "20833333333333332\n"}, {"input": "1000000000000000000 999999999989\n", "output": "1000000\n"}, {"input": "1000000000000000000 97\n", "output": "10416666666666661\n"}, {"input": "62 45\n", "output": "14\n"}, {"input": "25 48\n", "output": "5\n"}, {"input": "594703138034372316 960179812013\n", "output": "19200359\n"}, {"input": "1 2\n", "output": "0\n"}, {"input": "2 2\n", "output": "1\n"}, {"input": "7 10080\n", "output": "0\n"}, {"input": "8 10080\n", "output": "1\n"}, {"input": "57 10080\n", "output": "9\n"}, {"input": "9 10080\n", "output": "1\n"}, {"input": "14 10080\n", "output": "2\n"}, {"input": "1000000000000000000 2\n", "output": "999999999999999976\n"}, {"input": "1000000000000000000 7\n", "output": "166666666666666656\n"}, {"input": "1000000000000000000 285311670611\n", "output": "9090909090909090\n"}, {"input": "1000000000000000000 322687697779\n", "output": "6172839506172838\n"}, {"input": "1000000000000000000 470184984576\n", "output": "33333333333333332\n"}, {"input": "1000000000000000000 743008370688\n", "output": "45454545454545452\n"}, {"input": "1000000000000000000 64339296875\n", "output": "23809523809523808\n"}, {"input": "1000000000000000000 200560490130\n", "output": "33333333333333329\n"}, {"input": "36 118587876497\n", "output": "0\n"}, {"input": "36 322687697779\n", "output": "0\n"}, {"input": "36 110075314176\n", "output": "1\n"}, {"input": "36 656100000000\n", "output": "1\n"}, {"input": "4294967296 999999999989\n", "output": "0\n"}, {"input": "4294967296 999999999958\n", "output": "0\n"}, {"input": "13 373621248000\n", "output": "0\n"}, {"input": "12 720\n", "output": "2\n"}, {"input": "12 576\n", "output": "1\n"}, {"input": "1 1000000000000\n", "output": "0\n"}, {"input": "6 13\n", "output": "0\n"}, {"input": "2 193773\n", "output": "0\n"}, {"input": "2 398273\n", "output": "0\n"}, {"input": "72 30\n", "output": "16\n"}, {"input": "72 2\n", "output": "70\n"}, {"input": "72 193773\n", "output": "0\n"}, {"input": "72 398273\n", "output": "0\n"}, {"input": "72 250880942892\n", "output": "0\n"}, {"input": "72 999999998141\n", "output": "0\n"}, {"input": "912222 193773\n", "output": "14\n"}, {"input": "912222 398273\n", "output": "2\n"}, {"input": "912222 250880942892\n", "output": "0\n"}, {"input": "912222 999999998141\n", "output": "0\n"}, {"input": "83143260522 193773\n", "output": "1287245\n"}, {"input": "83143260522 398273\n", "output": "208759\n"}, {"input": "83143260522 250880942892\n", "output": "3\n"}, {"input": "83143260522 999999998141\n", "output": "0\n"}, {"input": "822981260158260522 250880942892\n", "output": "39364389\n"}, {"input": "222981260158260518 850874549779\n", "output": "15271097091\n"}, {"input": "222981260158260518 999999998141\n", "output": "222981\n"}, {"input": "445422409459676274 999922001521\n", "output": "222720113534\n"}, {"input": "918586219753393663 999800009711\n", "output": "918663387476\n"}, {"input": "446248652637759698 972358665643\n", "output": "15016106488920\n"}, {"input": "237201990843960076 973532640023\n", "output": "11953335559561\n"}, {"input": "484242296072308881 978253641619\n", "output": "48677351836781\n"}, {"input": "447074895815843122 911125611841\n", "output": "114517135198729\n"}, {"input": "455817757639559194 970322544187\n", "output": "153473992471231\n"}, {"input": "238028234022043500 877592366401\n", "output": "121195638504094\n"}, {"input": "720471251645857727 800266614341\n", "output": "380798758798020\n"}, {"input": "883457908461157525 863363187787\n", "output": "887005932189914\n"}, {"input": "945422409459676266 962504231329\n", "output": "481831307722\n"}, {"input": "818586219753393638 868390924421\n", "output": "878145564521\n"}, {"input": "946248652637759690 834034807997\n", "output": "33512135310870\n"}, {"input": "937201990843960062 788432964607\n", "output": "49755892484813\n"}, {"input": "984242296072308866 826202217433\n", "output": "99923075743380\n"}, {"input": "947074895815843114 12897917761\n", "output": "704668821291548\n"}, {"input": "855817757639559189 261563075383\n", "output": "310754450849512\n"}, {"input": "938028234022043486 6255386281\n", "output": "825729079244755\n"}, {"input": "820471251645857717 184820096819\n", "output": "539783718188063\n"}, {"input": "883457908461157497 102269364647\n", "output": "962372449304090\n"}] |
|
206 | A frog is initially at position $0$ on the number line. The frog has two positive integers $a$ and $b$. From a position $k$, it can either jump to position $k+a$ or $k-b$.
Let $f(x)$ be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval $[0, x]$. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from $0$.
Given an integer $m$, find $\sum_{i=0}^{m} f(i)$. That is, find the sum of all $f(i)$ for $i$ from $0$ to $m$.
-----Input-----
The first line contains three integers $m, a, b$ ($1 \leq m \leq 10^9, 1 \leq a,b \leq 10^5$).
-----Output-----
Print a single integer, the desired sum.
-----Examples-----
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
-----Note-----
In the first example, we must find $f(0)+f(1)+\ldots+f(7)$. We have $f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8$. The sum of these values is $19$.
In the second example, we have $f(i) = i+1$, so we want to find $\sum_{i=0}^{10^9} i+1$.
In the third example, the frog can't make any jumps in any case. | interview | [{"code": "import math\nm,a,b=map(int,input().split())\ng=math.gcd(a,b)\na1=a//g\nb1=b//g\nalls=g*(a1+b1-1)\ndists=[0]+[-1]*(a1+b1-1)\ndist=0\nfar=0\nwhile dist!=b1:\n if dist<b1:\n dist+=a1\n far=max(dist,far)\n else:\n dist-=b1\n if dists[dist]==-1:\n dists[dist]=far\ntot=0\nfor i in range(a1+b1):\n if i*g<=m and dists[i]*g<=m:\n tot+=(m+1-dists[i]*g)\nif alls<m:\n mod=m%g\n times=m//g\n diff=times-a1-b1\n tot1=g*(diff*(diff+1)//2)+(mod+1)*(diff+1)\n tot+=tot1\nprint(tot)", "passed": true, "time": 0.43, "memory": 18180.0, "status": "done"}, {"code": "from math import gcd\n\nm,a,b = list(map(int,input().split()))\n\ng = gcd(a,b)\n\nvis = [0]*(a+b+1)\nvis[0] = 1\n\nnvis = 1\n\ncount = 0\nlast = 0\nt = 0\nwhile True:\n #print(t, vis)\n if t >= b:\n #print('back')\n t -= b\n if vis[t]:\n break\n vis[t] = 1\n nvis += 1\n else:\n t += a\n if t > m:\n break\n if t > last:\n #print('forward', t - last, 'with', nvis)\n count += (t - last)*nvis\n last = t\n if vis[t]:\n break\n vis[t] = 1\n nvis += 1\n #print(nvis,count)\n #print('---')\n\nif t > m:\n # we're done\n count += (m - last + 1)*nvis\nelse:\n def sumto(n):\n whole = n//g + 1\n r = whole*(whole+1)//2 * g\n corr = whole * (g-1 - (n%g))\n r -= corr\n return r\n\n #S = 0\n #for i in range(last, m+1):\n # S += i//g + 1\n #count += S\n #assert S == sumto(m) - sumto(last-1)\n\n count += sumto(m) - sumto(last-1)\n\n#print(vis)\nprint(count)\n", "passed": true, "time": 0.38, "memory": 15968.0, "status": "done"}, {"code": "from collections import deque\ndef gcd(a, b):\n b = abs(b)\n while b != 0:\n r = a%b\n a,b = b,r\n return a\n\nM, A, B = list(map(int, input().split()))\nX = [1]+[0]*(10**6)\nY = [0]\ns = 1\nt = 1\ng = gcd(A, B)\nfor N in range(1, M+1):\n if N >= A+B+g and (M-N+1) % g == 0:\n ss = Y[N-1]-Y[N-g-1]\n dd = (Y[N-1]-Y[N-2]) - (Y[N-g-1]-Y[N-g-2])\n t += ss*(M-N+1)//g + dd*g*((M-N+1)//g)*((M-N+1)//g+1)//2\n break\n elif N >= A and X[N-A]:\n que = deque([N])\n X[N] = 1\n s += 1\n while len(que):\n i = deque.pop(que)\n if i >= B and X[i-B] == 0:\n deque.append(que, i-B)\n X[i-B] = 1\n s += 1\n if i + A < N and X[i+A] == 0:\n deque.append(que, i+A)\n X[i+A] = 1\n s += 1\n t += s\n Y.append(t)\nprint(t)\n\n", "passed": true, "time": 1.68, "memory": 33640.0, "status": "done"}, {"code": "M, a, b = map(int, input().split())\nmod = 10**9+7\nD = [mod]*a\nmaxi = 0\nD[0] = 0\nQ = [0]\ndef f(x, i):\n t = (x+1-i)//a\n r = (x+1-i)%a\n return a*t*(t+1)//2+r*(t+1)\n\nwhile Q:\n q = Q.pop()\n D[q] = maxi\n k = max(0, -((-(b-q))//a))\n maxi = max(maxi, q+k*a)\n if D[(q-b)%a] == mod and maxi <= M:\n Q.append((q-b)%a)\nans = 0\nfor i, d in enumerate(D):\n if d > M:\n continue\n ans += f(M, i) - f(d-1, i)\nprint(ans)", "passed": true, "time": 0.54, "memory": 14928.0, "status": "done"}, {"code": "import sys\nimport math\ninput = sys.stdin.readline\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\nm,a,b=list(map(int,input().split()))\n\nGCD=gcd(a,b)\n\n\n#when a>b,\n\nMODLIST=[-1]*a\n\nNOWMAX=a\nNOW=a\nMODLIST[0]=a\nwhile True:\n \n while NOW-b>0 and MODLIST[(NOW-b)%a]==-1:\n NOW-=b\n MODLIST[NOW]=NOWMAX\n\n NOW+=a\n NOWMAX=max(NOW,NOWMAX)\n\n if MODLIST[(NOW-b)%a]!=-1:\n break\n\nANS=m+1#0\nMAX=max(MODLIST)\nfor i in range(1,min(m+1,MAX)):\n if MODLIST[i%a]==-1:\n continue\n ANS+=max((m+1-max(MODLIST[i%a],i)),0)\n\n #print(ANS)\n\n\nif MAX<=m:\n ANS+=(m-MAX+1+(m-m//GCD*GCD)+1)*((m//GCD*GCD-MAX)//GCD+1)//2\n\nprint(ANS)\n \n\n\n \n \n \n", "passed": true, "time": 1.51, "memory": 14924.0, "status": "done"}, {"code": "from math import gcd\nm, a, b = list(map(int, input().split()))\nlast, x = 0, gcd(a, b)\ns = [1]*(a+b+1)\nq1, ans = 0, 1\nmax1, s[0] = [[0, 1]], 0\nwhile q1 < a+b:\n if q1 > b and s[q1-b]:\n ans += 1\n q1 -= b\n s[q1] = 0\n else:\n q1 += a\n if q1 > last:\n max1.append([q1, ans])\n last = q1\n if s[q1]:\n ans += 1\n s[q1] = 0\nans1 = q1 = 0\nfor q in range(min(m+1, a+b)):\n if max1[q1+1][0] == q:\n q1 += 1\n ans1 += max1[q1+1][1]\nif m >= a+b:\n ans1 += (m//x+1)*(m % x+1)\n m -= m % x+1\n p, t = (a+b)//x, (m-a-b)//x\n ans1 += (t+1)*(t+2)//2*x\n ans1 += p*(t+1)*x\nprint(ans1)\n", "passed": true, "time": 0.83, "memory": 29132.0, "status": "done"}, {"code": "import math\nm,a,b=list(map(int,(input().split())))\nvis=[-1]*(a+b+5)\nnow=0\nmaxd=0\nwhile True:\n vis[now]=maxd\n #print(now,maxd)\n if now>=b:\n now-=b\n else:\n now+=a\n if now==0:\n break\n maxd=max(maxd,now)\nans=0\n#for i in range(0,a+b):\n #print(vis[i])\nfor i in range(0,a+b):\n if vis[i]!=-1:\n ans+=max(0,m-vis[i]+1)\nrest=m-(a+b)+1\nif m>=a+b:\n g=math.gcd(a,b)\n tmp=(rest//g)*g\n fir=rest-tmp\n lst=rest\n cnt=tmp//g+1\n ans+=(fir+lst)*cnt//2\nprint(int(ans))\n", "passed": true, "time": 0.99, "memory": 17864.0, "status": "done"}, {"code": "import math\nm,a,b=list(map(int,(input().split())))\nvis=[-1]*(a+b+5)\nnow=0\nmaxd=0\nwhile True:\n vis[now]=maxd\n #print(now,maxd)\n if now>=b:\n now-=b\n else:\n now+=a\n if now==0:\n break\n maxd=max(maxd,now)\nans=0\n#for i in range(0,a+b):\n #print(vis[i])\nfor i in range(0,a+b):\n if vis[i]!=-1:\n ans+=max(0,m-vis[i]+1)\nrest=m-(a+b)+1\nif m>=a+b:\n g=math.gcd(a,b)\n tmp=(rest//g)*g\n fir=rest-tmp\n lst=rest\n cnt=tmp//g+1\n ans+=(fir+lst)*cnt//2\nprint(int(ans))\n", "passed": true, "time": 0.8, "memory": 17852.0, "status": "done"}, {"code": "import math\nM, A, B = list(map(int, input().split()))\nbound = [10**9 + 7]*(A + B)\nl, r = 0, 0\nwhile True:\n bound[l] = r\n if l >= B:\n l -= B\n else:\n l += A\n r = max(r, l)\n if l == 0:\n break\n\nans = 0\nfor i in range(0, A + B):\n if bound[i] <= M:\n ans += M - bound[i] + 1\n\nrem = M - (A + B) + 1\nif M >= (A + B):\n g = math.gcd(A, B)\n up = (rem // g) * g\n lo = rem - up\n cnt = up // g + 1\n ans += (lo + rem) * cnt // 2\nprint(ans)\n", "passed": true, "time": 0.6, "memory": 17772.0, "status": "done"}, {"code": "import math\nM, A, B = map(int, input().split())\nbound = [10**9 + 7]*(A + B)\nl, r = 0, 0\nwhile True:\n bound[l] = r\n if l >= B:\n l -= B\n else:\n l += A\n r = max(r, l)\n if l == 0:\n break\n\nans = 0\nfor i in range(0, A + B):\n if bound[i] <= M:\n ans += M - bound[i] + 1\n\nrem = M - (A + B) + 1\nif M >= (A + B):\n g = math.gcd(A, B)\n up = (rem // g) * g\n lo = rem - up\n cnt = up // g + 1\n ans += (lo + rem) * cnt // 2\nprint(ans)", "passed": true, "time": 1.31, "memory": 17656.0, "status": "done"}] | [{"input": "7 5 3\n", "output": "19\n"}, {"input": "1000000000 1 2019\n", "output": "500000001500000001\n"}, {"input": "100 100000 1\n", "output": "101\n"}, {"input": "6 4 5\n", "output": "10\n"}, {"input": "172165 93846 84\n", "output": "1735345812\n"}, {"input": "9978 99 98615\n", "output": "507929\n"}, {"input": "9909 95875 20\n", "output": "9910\n"}, {"input": "42651129 26190 16875\n", "output": "6737492081840\n"}, {"input": "5 8253 91700\n", "output": "6\n"}, {"input": "14712 8142 9912\n", "output": "21284\n"}, {"input": "98898 1040 98615\n", "output": "4761309\n"}, {"input": "79674 62280 77850\n", "output": "97070\n"}, {"input": "78139 77688 1161\n", "output": "108424\n"}, {"input": "110518 69352 81284\n", "output": "151686\n"}, {"input": "881706694 5710 56529\n", "output": "680741853146475\n"}, {"input": "863 99250 420\n", "output": "864\n"}, {"input": "9112063 50688 2640\n", "output": "78628667728\n"}, {"input": "236009692 89900 300\n", "output": "278502953469621\n"}, {"input": "16145755 64220 70642\n", "output": "20303198570\n"}, {"input": "997932 23910 14346\n", "output": "104545151\n"}, {"input": "9907037 55440 88480\n", "output": "87620910296\n"}, {"input": "9695 9 85014\n", "output": "5227761\n"}, {"input": "99548 73888 32\n", "output": "69626827\n"}, {"input": "9742365 6750 90375\n", "output": "126544822305\n"}, {"input": "95544 17793 8856\n", "output": "157445948\n"}, {"input": "2756 31707 63414\n", "output": "2757\n"}, {"input": "936989 17028 92708\n", "output": "229896864\n"}, {"input": "9650984 18601 2090\n", "output": "222830431513\n"}, {"input": "26 92701 7\n", "output": "27\n"}, {"input": "9980 78765 356\n", "output": "9981\n"}, {"input": "10348323 355 83425\n", "output": "150833075049\n"}, {"input": "952549276 31416 33000\n", "output": "1718466614644254\n"}, {"input": "992869 410 9880\n", "output": "49284898280\n"}, {"input": "96033 98622 100\n", "output": "96034\n"}, {"input": "3 998 99486\n", "output": "4\n"}, {"input": "10652698 87345 1116\n", "output": "6304015267729\n"}, {"input": "303857 1990 4\n", "output": "23081582946\n"}, {"input": "395013 59544 180\n", "output": "2117961170\n"}, {"input": "1183 532 73416\n", "output": "1956\n"}, {"input": "25 75060 2502\n", "output": "26\n"}, {"input": "4987696 29388 29865\n", "output": "4145604588400\n"}, {"input": "2531607 75419 14230\n", "output": "2250674901\n"}, {"input": "4015 56658 19\n", "output": "4016\n"}, {"input": "49277 166 8051\n", "output": "14453806\n"}, {"input": "9984950 40800 1152\n", "output": "519262873734\n"}, {"input": "1710 11868 202\n", "output": "1711\n"}, {"input": "96974 1 99004\n", "output": "4702123800\n"}, {"input": "995676200 30 99370\n", "output": "49568555030448651\n"}, {"input": "983 97020 105\n", "output": "984\n"}, {"input": "9331043 5355 81159\n", "output": "14510155272753\n"}, {"input": "99005952 94024 10220\n", "output": "2397840434982\n"}, {"input": "16965 51653 70\n", "output": "16966\n"}, {"input": "997674659 8874 35496\n", "output": "56083140668646\n"}, {"input": "1647861 97967 10\n", "output": "1352925986505\n"}, {"input": "7526 35 7525\n", "output": "813132\n"}, {"input": "68565 68564 1\n", "output": "205695\n"}, {"input": "58200 198 58050\n", "output": "8583036\n"}, {"input": "14332 13672 1976\n", "output": "18960\n"}, {"input": "7957 18 7956\n", "output": "1763140\n"}, {"input": "70343 66336 6910\n", "output": "110424\n"}, {"input": "101407 95200 6448\n", "output": "377984\n"}, {"input": "57986 4760 56440\n", "output": "395386\n"}, {"input": "87728 689 87236\n", "output": "5657822\n"}, {"input": "79903 75251 7234\n", "output": "150249\n"}, {"input": "107132 20930 92956\n", "output": "353953\n"}, {"input": "97009 97008 129\n", "output": "98514\n"}, {"input": "96538 95880 900\n", "output": "243807\n"}, {"input": "7845 4410 7350\n", "output": "11282\n"}, {"input": "79873 13 79872\n", "output": "245419010\n"}, {"input": "99573 99474 186\n", "output": "153074\n"}, {"input": "112104 86760 69327\n", "output": "178619\n"}, {"input": "76065 44280 39150\n", "output": "305610\n"}, {"input": "58423 58422 9737\n", "output": "58436\n"}, {"input": "22432 19298 5536\n", "output": "36753\n"}] |
|
207 | Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence a_1, a_2, ..., a_{n} of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.
A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.
-----Input-----
The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence.
The second line contains n space-separated non-negative integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 100) — the elements of the sequence.
-----Output-----
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower).
-----Examples-----
Input
3
1 3 5
Output
Yes
Input
5
1 0 1 5 1
Output
Yes
Input
3
4 3 1
Output
No
Input
4
3 9 9 3
Output
No
-----Note-----
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number. | interview | [{"code": "def read_ints():\n\treturn [int(i) for i in input().split()]\n\nn = read_ints()\na = read_ints()\nif len(a) % 2 and a[0] % 2 and a[-1] % 2:\n\tprint('Yes')\nelse:\n\tprint('No')", "passed": true, "time": 0.14, "memory": 14448.0, "status": "done"}, {"code": "n = int(input())\narr = list(map(int,input().split()))\nif(n%2 == 0):\n\tprint('No')\nelse:\n\tif(arr[0] % 2 == 1 and arr[-1] % 2 == 1):\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')", "passed": true, "time": 0.25, "memory": 14260.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nif a[0] % 2 == 1 and a[n - 1] % 2 == 1 and n % 2 == 1:\n print('Yes')\nelse:\n print('No')\n", "passed": true, "time": 0.14, "memory": 14488.0, "status": "done"}, {"code": "def list_input():\n return list(map(int,input().split()))\ndef map_input():\n return map(int,input().split())\ndef map_string():\n return input().split()\n \nn = int(input()) \na = list_input()\nif a[0]%2 and a[-1]%2 and n%2:\n print(\"Yes\")\nelse: print(\"No\") ", "passed": true, "time": 0.15, "memory": 14384.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nif len(a) % 2 == 1:\n if a[0] % 2 == 1 and a[n - 1] % 2 == 1:\n print('Yes')\n else:\n print('No')\nelse:\n print('No')\n", "passed": true, "time": 0.25, "memory": 14296.0, "status": "done"}, {"code": "values_nr = int(input())\nidx___value = [int(x) for x in input().split()]\n\nif (len(idx___value) % 2 != 0) and (idx___value[0] % 2 != 0) and (idx___value[-1] % 2 != 0):\n print('Yes')\nelse:\n print('No')", "passed": true, "time": 0.15, "memory": 14460.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nif n % 2 == 0:\n print(\"No\")\n return\nif a[0]* a[-1] % 2 == 0:\n print(\"No\")\n return\n\nprint(\"Yes\")", "passed": true, "time": 0.23, "memory": 14448.0, "status": "done"}, {"code": "n=int(input())\nif (n % 2 == 0):\n print(\"No\")\nelse:\n a=list(map(int,input().split()))\n if (a[0]%2 == 0):\n print(\"No\")\n else:\n if a[n-1] % 2 == 0:\n print(\"No\")\n else:\n print(\"Yes\")\n", "passed": true, "time": 0.15, "memory": 14300.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\n\nif n % 2 == 0:\n print('No')\nelif a[0] % 2 == 0 or a[-1] % 2 == 0:\n print('No')\nelse:\n print('Yes')", "passed": true, "time": 0.14, "memory": 14416.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nif n % 2:\n\tif a[0] % 2 and a[-1] % 2:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\nelse:\n\tprint('No')", "passed": true, "time": 0.82, "memory": 14440.0, "status": "done"}, {"code": "n = int(input())\nls = list(map(int, input().split()))\n\nif ls[0] % 2 == 1 and ls[-1] % 2 == 1 and len(ls) % 2 == 1:\n print('Yes')\nelse:\n print('No')\n", "passed": true, "time": 0.14, "memory": 14576.0, "status": "done"}, {"code": "import sys\n\n\ndef main():\n n = int(input())\n s = list(map(int, sys.stdin.readline().split()))\n\n if n % 2 == 1 and s[0] % 2 == 1 and s[-1] % 2 == 1:\n print(\"Yes\")\n else:\n print(\"No\")\n\n\nmain()\n", "passed": true, "time": 0.16, "memory": 14532.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nif n%2==1:\n if (a[0]%2==1) and (a[n-1]%2==1):\n print(\"Yes\")\n else:\n print(\"No\")\nelse:\n print(\"No\")\n\n", "passed": true, "time": 0.14, "memory": 14520.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\n\nif n % 2 == 1 and a[0] % 2 == 1 and a[-1] % 2 == 1:\n print('Yes')\nelse:\n print('No')\n", "passed": true, "time": 0.15, "memory": 14428.0, "status": "done"}, {"code": "n = int(input())\nA = list(map(int, input().split()))\n\nif A[0] % 2 == 0 or A[-1] % 2 == 0 or len(A) % 2 == 0:\n print('No')\nelse:\n print('Yes')\n\n", "passed": true, "time": 0.14, "memory": 14540.0, "status": "done"}, {"code": "n=int(input())\na=[int(i) for i in input().split()]\nif(len(a)%2 and a[0]%2 and a[-1]%2):print('Yes')\nelse:print('No')", "passed": true, "time": 0.15, "memory": 14456.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split(' ')))\n\nif (n & 1) and (a[0] & 1) and (a[-1] & 1):\n\tprint(\"Yes\")\nelse:\n\tprint(\"No\")\n", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "3\n\n\ndef main():\n i = int(input())\n data = [int(d) for d in input().split()]\n\n if(data[0]%2 + data[-1]%2 + i%2 < 3):\n print(\"No\");\n else:\n print(\"Yes\");\n\n\ndef __starting_point(): main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "# coding: utf-8\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n\n if n % 2 == 1 and a[0] % 2 == 1 and a[-1] % 2 == 1:\n return \"Yes\"\n return \"No\"\n\nprint(main())\n", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "N = int(input())\nA = [int(x) for x in input().split()]\ndp = [[False] * (N + 1) for _ in range(N + 1)]\ndp[0][0] = True\nfor i in range(N):\n if A[i] % 2 == 1:\n for j in range(N):\n for k in range(i + 1):\n if (k - i + 1) % 2 == 1 and A[k] % 2 == 1 and dp[k][j]:\n dp[i + 1][j + 1] = True\nprint(\"Yes\" if any(dp[-1][i] for i in range(1, N + 1, 2)) else \"No\")\n", "passed": true, "time": 0.39, "memory": 14512.0, "status": "done"}] | [{"input": "3\n1 3 5\n", "output": "Yes\n"}, {"input": "5\n1 0 1 5 1\n", "output": "Yes\n"}, {"input": "3\n4 3 1\n", "output": "No\n"}, {"input": "4\n3 9 9 3\n", "output": "No\n"}, {"input": "1\n1\n", "output": "Yes\n"}, {"input": "5\n100 99 100 99 99\n", "output": "No\n"}, {"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n", "output": "No\n"}, {"input": "1\n0\n", "output": "No\n"}, {"input": "2\n1 1\n", "output": "No\n"}, {"input": "2\n10 10\n", "output": "No\n"}, {"input": "2\n54 21\n", "output": "No\n"}, {"input": "5\n0 0 0 0 0\n", "output": "No\n"}, {"input": "5\n67 92 0 26 43\n", "output": "Yes\n"}, {"input": "15\n45 52 35 80 68 80 93 57 47 32 69 23 63 90 43\n", "output": "Yes\n"}, {"input": "15\n81 28 0 82 71 64 63 89 87 92 38 30 76 72 36\n", "output": "No\n"}, {"input": "50\n49 32 17 59 77 98 65 50 85 10 40 84 65 34 52 25 1 31 61 45 48 24 41 14 76 12 33 76 44 86 53 33 92 58 63 93 50 24 31 79 67 50 72 93 2 38 32 14 87 99\n", "output": "No\n"}, {"input": "55\n65 69 53 66 11 100 68 44 43 17 6 66 24 2 6 6 61 72 91 53 93 61 52 96 56 42 6 8 79 49 76 36 83 58 8 43 2 90 71 49 80 21 75 13 76 54 95 61 58 82 40 33 73 61 46\n", "output": "No\n"}, {"input": "99\n73 89 51 85 42 67 22 80 75 3 90 0 52 100 90 48 7 15 41 1 54 2 23 62 86 68 2 87 57 12 45 34 68 54 36 49 27 46 22 70 95 90 57 91 90 79 48 89 67 92 28 27 25 37 73 66 13 89 7 99 62 53 48 24 73 82 62 88 26 39 21 86 50 95 26 27 60 6 56 14 27 90 55 80 97 18 37 36 70 2 28 53 36 77 39 79 82 42 69\n", "output": "Yes\n"}, {"input": "99\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99\n", "output": "Yes\n"}, {"input": "100\n61 63 34 45 20 91 31 28 40 27 94 1 73 5 69 10 56 94 80 23 79 99 59 58 13 56 91 59 77 78 88 72 80 72 70 71 63 60 41 41 41 27 83 10 43 14 35 48 0 78 69 29 63 33 42 67 1 74 51 46 79 41 37 61 16 29 82 28 22 14 64 49 86 92 82 55 54 24 75 58 95 31 3 34 26 23 78 91 49 6 30 57 27 69 29 54 42 0 61 83\n", "output": "No\n"}, {"input": "6\n1 2 2 2 2 1\n", "output": "No\n"}, {"input": "3\n1 2 1\n", "output": "Yes\n"}, {"input": "4\n1 3 2 3\n", "output": "No\n"}, {"input": "6\n1 1 1 1 1 1\n", "output": "No\n"}, {"input": "6\n1 1 0 0 1 1\n", "output": "No\n"}, {"input": "4\n1 4 9 3\n", "output": "No\n"}, {"input": "4\n1 0 1 1\n", "output": "No\n"}, {"input": "10\n1 0 0 1 1 1 1 1 1 1\n", "output": "No\n"}, {"input": "10\n9 2 5 7 8 3 1 9 4 9\n", "output": "No\n"}, {"input": "99\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2\n", "output": "No\n"}, {"input": "6\n1 2 1 2 2 1\n", "output": "No\n"}, {"input": "6\n1 0 1 0 0 1\n", "output": "No\n"}, {"input": "4\n1 3 4 7\n", "output": "No\n"}, {"input": "8\n1 1 1 2 1 1 1 1\n", "output": "No\n"}, {"input": "3\n1 1 2\n", "output": "No\n"}, {"input": "5\n1 2 1 2 1\n", "output": "Yes\n"}, {"input": "5\n5 4 4 2 1\n", "output": "Yes\n"}, {"input": "6\n1 3 3 3 3 1\n", "output": "No\n"}, {"input": "7\n1 2 1 2 2 2 1\n", "output": "Yes\n"}, {"input": "4\n1 2 2 1\n", "output": "No\n"}, {"input": "6\n1 2 3 4 6 5\n", "output": "No\n"}, {"input": "5\n1 1 2 2 2\n", "output": "No\n"}, {"input": "5\n1 0 0 1 1\n", "output": "Yes\n"}, {"input": "3\n1 2 4\n", "output": "No\n"}, {"input": "3\n1 0 2\n", "output": "No\n"}, {"input": "5\n1 1 1 0 1\n", "output": "Yes\n"}, {"input": "4\n3 9 2 3\n", "output": "No\n"}, {"input": "6\n1 1 1 4 4 1\n", "output": "No\n"}, {"input": "6\n1 2 3 5 6 7\n", "output": "No\n"}, {"input": "6\n1 1 1 2 2 1\n", "output": "No\n"}, {"input": "6\n1 1 1 0 0 1\n", "output": "No\n"}, {"input": "5\n1 2 2 5 5\n", "output": "Yes\n"}, {"input": "5\n1 3 2 4 5\n", "output": "Yes\n"}, {"input": "8\n1 2 3 5 7 8 8 5\n", "output": "No\n"}, {"input": "10\n1 1 1 2 1 1 1 1 1 1\n", "output": "No\n"}, {"input": "4\n1 0 0 1\n", "output": "No\n"}, {"input": "7\n1 0 1 1 0 0 1\n", "output": "Yes\n"}, {"input": "7\n1 4 5 7 6 6 3\n", "output": "Yes\n"}, {"input": "4\n2 2 2 2\n", "output": "No\n"}, {"input": "5\n2 3 4 5 6\n", "output": "No\n"}, {"input": "4\n1 1 2 1\n", "output": "No\n"}, {"input": "3\n1 2 3\n", "output": "Yes\n"}, {"input": "6\n1 3 3 2 2 3\n", "output": "No\n"}, {"input": "4\n1 1 2 3\n", "output": "No\n"}, {"input": "4\n1 2 3 5\n", "output": "No\n"}, {"input": "5\n3 4 4 3 3\n", "output": "Yes\n"}, {"input": "4\n3 2 2 3\n", "output": "No\n"}, {"input": "6\n1 1 1 1 2 1\n", "output": "No\n"}, {"input": "6\n1 1 2 2 1 1\n", "output": "No\n"}, {"input": "10\n3 4 2 4 3 2 2 4 4 3\n", "output": "No\n"}, {"input": "7\n1 2 4 3 2 4 5\n", "output": "Yes\n"}, {"input": "28\n75 51 25 52 13 7 34 29 5 59 68 56 13 2 9 37 59 83 18 32 36 30 20 43 92 76 78 67\n", "output": "No\n"}, {"input": "79\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 18\n", "output": "No\n"}, {"input": "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\n", "output": "No\n"}] |
|
208 | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
-----Input-----
The first line contains four space-separated x_1, y_1, x_2, y_2 ( - 100 ≤ x_1, y_1, x_2, y_2 ≤ 100) integers, where x_1 and y_1 are coordinates of the first tree and x_2 and y_2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
-----Output-----
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x_3, y_3, x_4, y_4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that x_3, y_3, x_4, y_4 must be in the range ( - 1000 ≤ x_3, y_3, x_4, y_4 ≤ 1000).
-----Examples-----
Input
0 0 0 1
Output
1 0 1 1
Input
0 0 1 1
Output
0 1 1 0
Input
0 0 1 2
Output
-1 | interview | [{"code": "x1, y1, x2, y2 = map(int, input().split())\n#diagonal\nif x1 != x2 and y1 != y2:\n if abs(x1 - x2) == abs(y1 - y2):\n print(x1, y2, x2, y1)\n else:\n print(-1)\n#same side\nelif x1 == x2:\n aux = abs(y2 - y1)\n print(x1 + aux, y1, x1 + aux, y2)\nelif y1 == y2:\n aux = abs(x2 - x1)\n print(x1, y1 + aux, x2, y1 + aux)", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}, {"code": "x1, y1, x2, y2 = [int(i) for i in input().split()]\nif x1 != x2:\n if y1 != y2:\n if abs(x1 - x2) != abs(y1 - y2):\n print(-1)\n else:\n print(x1, y2, x2, y1)\n else:\n delta = abs(x2 - x1)\n print(x1, y1 + delta, x2, y1 + delta)\nelse:\n if y1 != y2:\n delta = abs(y2 - y1)\n print(x1 + delta, y1, x1 + delta, y2)\n else:\n print(-1)\n \n\n\n \n", "passed": true, "time": 0.14, "memory": 14572.0, "status": "done"}, {"code": "import math\nx1, y1, x2, y2 = map(int,input().split())\na = abs(x1-x2)\nb = abs(y1-y2)\nif a == b and a != 0:\n print(x1, y2, x2, y1)\nelif a == 0 and b != 0:\n print(x1 + b, y1, x1+b, y2)\nelif b == 0 and a != 0:\n print(x1, y1 + a, x2, y1 + a)\nelse:\n print(-1)", "passed": true, "time": 0.22, "memory": 14364.0, "status": "done"}, {"code": "x1,y1,x2,y2=map(int,input().split())\nif x1==x2:\n print(x1+abs(y1-y2),y1,x2+abs(y1-y2),y2)\nelif y1==y2:\n print(x1,y1+abs(x1-x2),x2,y2+abs(x1-x2))\nelif abs(x1-x2)==abs(y1-y2):\n print(x1,y2,x2,y1)\nelse:\n print(-1)", "passed": true, "time": 0.24, "memory": 14412.0, "status": "done"}, {"code": "x1, y1, x2, y2 = map(int, input().split())\nif x1 != x2 and y1 != y2 and abs(x2 - x1) != abs(y2 - y1): #lishnii 2 usl\n print(-1)\nelse:\n if abs(x2 - x1) == abs(y2 - y1):\n x3 = x1\n y3 = y2\n x4 = x2\n y4 = y1\n elif x1 != x2:\n x3 = x1\n y3 = y1 + abs(x2 - x1)\n x4 = x2\n y4 = y2 + abs(x2 - x1)\n elif y1 != y2:\n x3 = x1 + abs(y2 - y1)\n y3 = y1\n x4 = x2 + abs(y2 - y1)\n y4 = y2\n print(x3, y3, x4, y4)", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}, {"code": "m=(list(int(x) for x in input().split()))\nx1=m[0]\ny1=m[1]\nx2=m[2]\ny2=m[3]\n\ndx=abs(x1-x2)\ndy=abs(y1-y2)\n\nif not dx:\n y3=y1\n y4=y2\n x3=x1+dy\n x4=x2+dy \n print(x3,y3,x4,y4)\nelif not dy:\n x3=x1\n x4=x2\n y3=y1+dx\n y4=y2+dx\n print(x3,y3,x4,y4)\nelse:\n if dx==dy:\n x3=x1\n y3=y2\n x4=x2\n y4=y1\n print(x3,y3,x4,y4) \n else:\n print(\"-1\")", "passed": true, "time": 0.16, "memory": 14548.0, "status": "done"}, {"code": "def process(x1, y1, x2, y2):\n if x1 == x2:\n print('{0} {1} {0} {2}'.format(x1 + abs(y2 - y1), y1, y2))\n elif y1 == y2:\n print('{1} {0} {2} {0}'.format(y1 + abs(x2 - x1), x1, x2))\n elif abs(y2 - y1) == abs(x2 - x1):\n print('{0} {3} {2} {1}'.format(x1, y1, x2, y2))\n else:\n print(-1)\n\n\ndef __starting_point():\n process(*(int(i) for i in input().split(' ')))\n\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "x1, y1, x2, y2 = map(int,input().split())\nif abs(x1-x2) == abs(y1-y2):\n print (x1, y2, x2, y1)\nelif x1 == x2:\n print (x1+abs(y1-y2), y1, x2 + abs(y1-y2), y2)\nelif y1 == y2:\n print (x1, y1+abs(x1-x2), x2, y2+abs(x1-x2))\nelse:\n print(-1)", "passed": true, "time": 0.14, "memory": 14300.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nx1, y1, x2, y2 = list (map (int, input ().split ()))\n\nif x1 == x2:\n print(x1 + abs (y1 - y2), y1, x1 + abs (y1 - y2), y2)\nelif y1 == y2:\n print(x1, abs (x1 - x2) + y1, x2, abs (x1 - x2) + y2)\nelif abs (x1 - x2) == abs (y1 - y2):\n print(x1, y2, x2, y1)\nelse:\n print(-1)\n", "passed": true, "time": 0.14, "memory": 14568.0, "status": "done"}, {"code": "import math\n\ncoordinates = input().split()\nx1 = int(coordinates[0])\ny1 = int(coordinates[1])\nx2 = int(coordinates[2])\ny2 = int(coordinates[3])\n\nif x1 == x2:\n\ty3 = y1\n\ty4 = y2\n\tx3 = x1 + abs(y1-y2)\n\tx4 = x2 + abs(y1-y2)\n\tprint(x3, y3, x4, y4)\n\nelif y1 == y2:\n\tx3 = x1\n\tx4 = x2\n\ty3 = y1 + abs(x1 - x2)\n\ty4 = y2 + abs(x1 - x2)\n\tprint(x3, y3, x4, y4)\n\nelif (abs(x1 - x2) == abs(y1 - y2)):\n\tx3 = x1\n\tx4 = x2\n\ty3 = y2\n\ty4 = y1\n\tprint(x3, y3, x4, y4)\n\nelse:\n\tprint(-1)\n\n\n", "passed": true, "time": 0.14, "memory": 14588.0, "status": "done"}] | [{"input": "0 0 0 1\n", "output": "1 0 1 1\n"}, {"input": "0 0 1 1\n", "output": "0 1 1 0\n"}, {"input": "0 0 1 2\n", "output": "-1\n"}, {"input": "-100 -100 100 100\n", "output": "-100 100 100 -100\n"}, {"input": "-100 -100 99 100\n", "output": "-1\n"}, {"input": "0 -100 0 100\n", "output": "200 -100 200 100\n"}, {"input": "27 -74 27 74\n", "output": "175 -74 175 74\n"}, {"input": "0 1 2 3\n", "output": "0 3 2 1\n"}, {"input": "-100 100 100 -100\n", "output": "-100 -100 100 100\n"}, {"input": "-100 -100 -100 100\n", "output": "100 -100 100 100\n"}, {"input": "100 100 100 -100\n", "output": "300 100 300 -100\n"}, {"input": "100 -100 -100 -100\n", "output": "100 100 -100 100\n"}, {"input": "-100 100 100 100\n", "output": "-100 300 100 300\n"}, {"input": "0 1 0 0\n", "output": "1 1 1 0\n"}, {"input": "1 1 0 0\n", "output": "1 0 0 1\n"}, {"input": "0 0 1 0\n", "output": "0 1 1 1\n"}, {"input": "1 0 0 1\n", "output": "1 1 0 0\n"}, {"input": "1 0 1 1\n", "output": "2 0 2 1\n"}, {"input": "1 1 0 1\n", "output": "1 2 0 2\n"}, {"input": "15 -9 80 -9\n", "output": "15 56 80 56\n"}, {"input": "51 -36 18 83\n", "output": "-1\n"}, {"input": "69 -22 60 16\n", "output": "-1\n"}, {"input": "-68 -78 -45 -55\n", "output": "-68 -55 -45 -78\n"}, {"input": "68 -92 8 -32\n", "output": "68 -32 8 -92\n"}, {"input": "95 -83 -39 -6\n", "output": "-1\n"}, {"input": "54 94 53 -65\n", "output": "-1\n"}, {"input": "-92 15 84 15\n", "output": "-92 191 84 191\n"}, {"input": "67 77 -11 -1\n", "output": "67 -1 -11 77\n"}, {"input": "91 -40 30 21\n", "output": "91 21 30 -40\n"}, {"input": "66 -64 -25 -64\n", "output": "66 27 -25 27\n"}, {"input": "-42 84 -67 59\n", "output": "-42 59 -67 84\n"}, {"input": "73 47 -5 -77\n", "output": "-1\n"}, {"input": "6 85 -54 -84\n", "output": "-1\n"}, {"input": "-58 -55 40 43\n", "output": "-58 43 40 -55\n"}, {"input": "56 22 48 70\n", "output": "-1\n"}, {"input": "-17 -32 76 -32\n", "output": "-17 61 76 61\n"}, {"input": "0 2 2 0\n", "output": "0 0 2 2\n"}, {"input": "0 0 -1 1\n", "output": "0 1 -1 0\n"}, {"input": "0 2 1 1\n", "output": "0 1 1 2\n"}, {"input": "0 0 1 -1\n", "output": "0 -1 1 0\n"}, {"input": "-1 2 -2 3\n", "output": "-1 3 -2 2\n"}, {"input": "0 1 1 0\n", "output": "0 0 1 1\n"}, {"input": "1 2 2 1\n", "output": "1 1 2 2\n"}, {"input": "4 1 2 1\n", "output": "4 3 2 3\n"}, {"input": "70 0 0 10\n", "output": "-1\n"}, {"input": "2 3 4 1\n", "output": "2 1 4 3\n"}, {"input": "1 3 3 1\n", "output": "1 1 3 3\n"}, {"input": "-3 3 0 0\n", "output": "-3 0 0 3\n"}, {"input": "2 8 7 3\n", "output": "2 3 7 8\n"}, {"input": "1 2 2 3\n", "output": "1 3 2 2\n"}, {"input": "0 3 3 0\n", "output": "0 0 3 3\n"}, {"input": "0 0 -3 3\n", "output": "0 3 -3 0\n"}, {"input": "0 2 1 2\n", "output": "0 3 1 3\n"}, {"input": "1 1 2 0\n", "output": "1 0 2 1\n"}, {"input": "0 0 5 0\n", "output": "0 5 5 5\n"}, {"input": "3 4 7 8\n", "output": "3 8 7 4\n"}, {"input": "0 5 5 0\n", "output": "0 0 5 5\n"}, {"input": "5 6 8 3\n", "output": "5 3 8 6\n"}, {"input": "2 2 1 1\n", "output": "2 1 1 2\n"}, {"input": "0 1 3 1\n", "output": "0 4 3 4\n"}, {"input": "2 4 5 4\n", "output": "2 7 5 7\n"}, {"input": "0 5 1 5\n", "output": "0 6 1 6\n"}, {"input": "4 0 0 4\n", "output": "4 4 0 0\n"}, {"input": "0 1 1 8\n", "output": "-1\n"}, {"input": "2 3 3 4\n", "output": "2 4 3 3\n"}, {"input": "1 0 2 1\n", "output": "1 1 2 0\n"}, {"input": "0 0 2 14\n", "output": "-1\n"}, {"input": "0 0 4 3\n", "output": "-1\n"}, {"input": "3 5 5 3\n", "output": "3 3 5 5\n"}, {"input": "-1 1 1 -1\n", "output": "-1 -1 1 1\n"}, {"input": "0 0 2 0\n", "output": "0 2 2 2\n"}, {"input": "0 0 1 7\n", "output": "-1\n"}, {"input": "1 2 3 2\n", "output": "1 4 3 4\n"}, {"input": "1 12 3 10\n", "output": "1 10 3 12\n"}] |
|
209 | Jzzhu has invented a kind of sequences, they meet the following property:$f_{1} = x ; f_{2} = y ; \forall i(i \geq 2), f_{i} = f_{i - 1} + f_{i + 1}$
You are given x and y, please calculate f_{n} modulo 1000000007 (10^9 + 7).
-----Input-----
The first line contains two integers x and y (|x|, |y| ≤ 10^9). The second line contains a single integer n (1 ≤ n ≤ 2·10^9).
-----Output-----
Output a single integer representing f_{n} modulo 1000000007 (10^9 + 7).
-----Examples-----
Input
2 3
3
Output
1
Input
0 -1
2
Output
1000000006
-----Note-----
In the first sample, f_2 = f_1 + f_3, 3 = 2 + f_3, f_3 = 1.
In the second sample, f_2 = - 1; - 1 modulo (10^9 + 7) equals (10^9 + 6). | interview | [{"code": "def main():\n x, y = [int(i) for i in input().split()]\n n = int(input())\n \n result = [x, y, y - x, -x, -y, x - y][(n - 1) % 6]\n \n print(result % 1000000007)\n\n\nmain()\n", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "x, y = list(map(int, input().split()))\nn = int(input())\nr = [x, y, y - x, -x, -y, x - y]\nprint(r[(n-1) % len(r)] % 1000000007)\n", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "x,y=map(int,input().split())\nn=int(input())\nz=y-x\nif n%6==1:\n\tprint(x%1000000007)\nelif n%6==2:\n\tprint(y%1000000007)\nelif n%6==3:\n\tprint(z%1000000007)\nelif n%6==4:\n\tprint((-x)%1000000007)\nelif n%6==5:\n\tprint((-y)%1000000007)\nelse:\n\tprint((-z)%1000000007)", "passed": true, "time": 0.31, "memory": 14380.0, "status": "done"}, {"code": "def main():\n x, y = input().split()\n n = int(input())\n f = [int(x), int(y)]\n while len(f) < 6:\n f.append(f[-1] - f[-2])\n print(f[n % 6 - 1] % 1000000007)\n\nmain()\n", "passed": true, "time": 0.15, "memory": 14552.0, "status": "done"}, {"code": "x, y = map(int, input().split())\nn = int(input())\nz = y - x\nvar = [x, y, z, -x, -y, -z]\nprint(var[(n - 1) % 6] % 1000000007)", "passed": true, "time": 0.9, "memory": 14564.0, "status": "done"}, {"code": "'''\nf[i] = f[i - 1] - f[i - 2]\nf[i] = -f[i - 3]\nf[i] = -f[i - 4] + f[i - 5]\nf[i] = f[i - 6]\n'''\n\nm = list(map(int, str.split(input())))\nfor _ in range(2, 6):\n\n m.append(m[-1] - m[-2])\n\nprint(m[(int(input()) - 1) % 6] % (10 ** 9 + 7))\n", "passed": true, "time": 0.23, "memory": 14312.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\ndef main():\n x, y = list(map(int, input().split()))\n n = int(input())\n\n lst = [x, y, y - x, -x, -y, x - y]\n lst = list([a % 1000000007 for a in lst])\n\n print(lst[(n - 1) % len(lst)])\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 1.57, "memory": 14488.0, "status": "done"}, {"code": "x, y = list(map(int, input().split()))\nn = int(input())\n\ns = (n - 1) % 6\n\nif s == 0:\n print(x % 1000000007)\nif s == 1:\n print(y % 1000000007)\nif s == 2:\n print((y - x) % 1000000007)\nif s == 3:\n print((-x) % 1000000007)\nif s == 4:\n print((-y) % 1000000007)\nif s == 5:\n print((x - y) % 1000000007)", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}, {"code": "x, y = tuple(map(int, input().split(' ')))\nn = int(input()) - 1\na = (x, y, y - x, -x, -y, -y + x)\n#print(a)\n\nprint(a[n%6]%1000000007)", "passed": true, "time": 0.32, "memory": 14352.0, "status": "done"}, {"code": "a = [0, 0, 0]\na[0], a[1] = list(map(int, input().split()))\nn = int(input()) - 1;\nN = 1000000007\na[2] = a[1] - a[0];\nif (n // 3) % 2: \n print((-a[n % 3]) % N)\nelse:\n print(a[n % 3] % N)\n", "passed": true, "time": 1.18, "memory": 14508.0, "status": "done"}, {"code": "\nf = [0]*7\nf[1], f[2] = [int (x) for x in input().split()]\nf[3] = f[2] - f[1]\nf[4] = -f[1]\nf[5] = -f[2]\nf[6] = -f[3]\nn = int(input())\nt = n%6\nif(t == 0): t = 6\nprint((f[t])%1000000007)\n", "passed": true, "time": 0.22, "memory": 14400.0, "status": "done"}, {"code": "x,y = list(map(int, input().split()))\nn = int(input())\nresult = n%6\nif result == 1:\n print(x%1000000007)\nelif result == 2:\n print(y%1000000007)\nelif result == 3:\n print((y-x)%1000000007)\nelif result == 4:\n print((-x)%1000000007)\nelif result == 5:\n print((-y)%1000000007)\nelif result == 0:\n print((x-y)%1000000007)\n \n\n", "passed": true, "time": 0.22, "memory": 14476.0, "status": "done"}, {"code": "\n\nmod = 1000000007\na, b = list(map(int, input().split()))\nn = int(input())\n\nc = b - a\n\nif n % 3 == 1:\n if (n-1)/3 % 2 == 0:\n print((mod+a)%mod)\n else:\n print((mod-a)%mod)\nelif n % 3 == 2:\n if (n-2)/3 % 2 == 0:\n print((mod+b)%mod)\n else:\n print((mod-b)%mod)\nelse:\n if (n-3)/3 % 2 == 0:\n print((mod+c)%mod)\n else:\n print((mod-c)%mod)\n\n\n", "passed": true, "time": 0.14, "memory": 14484.0, "status": "done"}, {"code": "sa=input().split(' ')\nx=int(sa[0])\ny=int(sa[1])\nn=int(input())\n\ndef generate(x, y, n):\n sa=[x, y, y-x, -x, -y, x-y]\n return sa[((n%6)-1)%6]\n\nprint(generate(x, y, n)%(10**9+7))", "passed": true, "time": 0.22, "memory": 14340.0, "status": "done"}, {"code": "x,y=list(map(int,input().split()))\nn=int(input())\ndef modulo(a):\n if a==1000000007:\n return 0\n elif a>=0:\n return int(a%(1000000007))\n else:\n if a%1000000007==0:\n return 0\n else:\n return int((1000000007)-int(((-1)*a)%(1000000007)))\nn=n%6\nif n==1: print(modulo(x))\nelif n==2: print(modulo(y))\nelif n==3: print(modulo(y-x))\nelif n==4: print(modulo(-x))\nelif n==5: print(modulo(-y))\nelif n==0: print(modulo(x-y))", "passed": true, "time": 0.14, "memory": 14428.0, "status": "done"}, {"code": "x,y=list(map(int,input().split()))\nn=int(input())\nz=y-x\nif(n==1):\n print(x%1000000007)\nelif(n==2):\n print(y%1000000007)\nelif(n==3):\n print(z%1000000007)\nelse:\n mod=n%3\n if(mod==0):\n if((n//3)%2==0):\n print((-1*z)%1000000007)\n else:\n print(z%1000000007)\n elif(mod==1):\n if((n//3)%2==1):\n print((-1*x)%1000000007)\n else:\n print(x%1000000007)\n else:\n if((n//3)%2==1):\n print((-1*y)%1000000007)\n else:\n print(y%1000000007)\n", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "x, y = map(int, input().split())\nn = int(input())\nf = [x, y, y - x, -x, -y, x - y]\nprint(f[(n - 1) % len(f)] % 1000000007)", "passed": true, "time": 0.14, "memory": 14424.0, "status": "done"}, {"code": "mod = 1000000007\nx, y= map(int, input().split())\nn = int(input())\nA = [x - y, x, y, y - x, -x, -y]\nn %= 6\nprint((A[n]%mod + mod)%mod)", "passed": true, "time": 0.14, "memory": 14564.0, "status": "done"}, {"code": "mod = 10**9 + 7\nx, y= map(int, input().split())\nn = int(input())\nA = [x - y, x, y, y - x, -x, -y]\nn %= 6\nprint((A[n])%mod)", "passed": true, "time": 0.14, "memory": 14324.0, "status": "done"}, {"code": "x, y = tuple(map(int, input().split()))\nn = int(input())\n\nanswers = [x, y, y - x, -x, -y, -y + x]\nprint(answers[n % 6 - 1] % (10 ** 9 + 7))\n", "passed": true, "time": 0.14, "memory": 14324.0, "status": "done"}, {"code": "x,y = map(int, input().split())\nn = int(input())\nINF = 10**9+7\nif n == 1:\n print(x%INF)\nelif n == 2:\n print(y%INF)\nelse:\n n=n%6\n a=[x,y,y-x,-x,-y,x-y]\n print(a[n-1]%INF)", "passed": true, "time": 0.14, "memory": 14552.0, "status": "done"}, {"code": "i = input().split()\nf1 = int(i[0])\nf2 = int(i[1])\n\nn = int(input()) % 6\nl = []\nfor x in range(n+6):\n l.append(0)\n\nl[0] = f1\nl[1] = f2\nfor x in range(2, n+6):\n l[x] = (l[x-1] - l[x-2])\n\nprint(l[n-1] % 1000000007)\n", "passed": true, "time": 0.14, "memory": 14452.0, "status": "done"}] | [{"input": "2 3\n3\n", "output": "1\n"}, {"input": "0 -1\n2\n", "output": "1000000006\n"}, {"input": "-9 -11\n12345\n", "output": "1000000005\n"}, {"input": "0 0\n1000000000\n", "output": "0\n"}, {"input": "-1000000000 1000000000\n2000000000\n", "output": "1000000000\n"}, {"input": "-12345678 12345678\n1912345678\n", "output": "12345678\n"}, {"input": "728374857 678374857\n1928374839\n", "output": "950000007\n"}, {"input": "278374837 992837483\n1000000000\n", "output": "721625170\n"}, {"input": "-693849384 502938493\n982838498\n", "output": "502938493\n"}, {"input": "-783928374 983738273\n992837483\n", "output": "16261734\n"}, {"input": "-872837483 -682738473\n999999999\n", "output": "190099010\n"}, {"input": "-892837483 -998273847\n999283948\n", "output": "892837483\n"}, {"input": "-283938494 738473848\n1999999999\n", "output": "716061513\n"}, {"input": "-278374857 819283838\n1\n", "output": "721625150\n"}, {"input": "-1000000000 123456789\n1\n", "output": "7\n"}, {"input": "-529529529 -524524524\n2\n", "output": "475475483\n"}, {"input": "1 2\n2000000000\n", "output": "2\n"}, {"input": "-1 -2\n2000000000\n", "output": "1000000005\n"}, {"input": "1 2\n1999999999\n", "output": "1\n"}, {"input": "1 2\n1999999998\n", "output": "1000000006\n"}, {"input": "1 2\n1999999997\n", "output": "1000000005\n"}, {"input": "1 2\n1999999996\n", "output": "1000000006\n"}, {"input": "69975122 366233206\n1189460676\n", "output": "703741923\n"}, {"input": "812229413 904420051\n806905621\n", "output": "812229413\n"}, {"input": "872099024 962697902\n1505821695\n", "output": "90598878\n"}, {"input": "887387283 909670917\n754835014\n", "output": "112612724\n"}, {"input": "37759824 131342932\n854621399\n", "output": "868657075\n"}, {"input": "-246822123 800496170\n626323615\n", "output": "753177884\n"}, {"input": "-861439463 974126967\n349411083\n", "output": "835566423\n"}, {"input": "-69811049 258093841\n1412447\n", "output": "741906166\n"}, {"input": "844509330 -887335829\n123329059\n", "output": "844509330\n"}, {"input": "83712471 -876177148\n1213284777\n", "output": "40110388\n"}, {"input": "598730524 -718984219\n1282749880\n", "output": "401269483\n"}, {"input": "-474244697 -745885656\n1517883612\n", "output": "271640959\n"}, {"input": "-502583588 -894906953\n1154189557\n", "output": "497416419\n"}, {"input": "-636523651 -873305815\n154879215\n", "output": "763217843\n"}, {"input": "721765550 594845720\n78862386\n", "output": "126919830\n"}, {"input": "364141461 158854993\n1337196589\n", "output": "364141461\n"}, {"input": "878985260 677031952\n394707801\n", "output": "798046699\n"}, {"input": "439527072 -24854079\n1129147002\n", "output": "464381151\n"}, {"input": "840435009 -612103127\n565968986\n", "output": "387896880\n"}, {"input": "875035447 -826471373\n561914518\n", "output": "124964560\n"}, {"input": "-342526698 305357084\n70776744\n", "output": "352116225\n"}, {"input": "-903244186 899202229\n1527859274\n", "output": "899202229\n"}, {"input": "-839482546 815166320\n1127472130\n", "output": "839482546\n"}, {"input": "-976992569 -958313041\n1686580818\n", "output": "981320479\n"}, {"input": "-497338894 -51069176\n737081851\n", "output": "502661113\n"}, {"input": "-697962643 -143148799\n1287886520\n", "output": "856851208\n"}, {"input": "-982572938 -482658433\n1259858332\n", "output": "982572938\n"}, {"input": "123123 78817\n2000000000\n", "output": "78817\n"}, {"input": "1000000000 -1000000000\n3\n", "output": "14\n"}, {"input": "-1000000000 1000000000\n6\n", "output": "14\n"}, {"input": "2 3\n6\n", "output": "1000000006\n"}, {"input": "0 -1\n6\n", "output": "1\n"}, {"input": "500000000 -1000000000\n600000003\n", "output": "500000014\n"}, {"input": "-1000000000 1000000000\n3\n", "output": "999999993\n"}, {"input": "1 3\n6\n", "output": "1000000005\n"}, {"input": "1 2\n12\n", "output": "1000000006\n"}, {"input": "7 -1000000000\n3\n", "output": "0\n"}, {"input": "-999999997 999999997\n6\n", "output": "20\n"}, {"input": "3 4\n6\n", "output": "1000000006\n"}, {"input": "-1 2\n6\n", "output": "1000000004\n"}, {"input": "2 3\n12\n", "output": "1000000006\n"}, {"input": "4 18\n6\n", "output": "999999993\n"}, {"input": "1 2\n6\n", "output": "1000000006\n"}, {"input": "1000000000 -1000000000\n6\n", "output": "999999993\n"}, {"input": "999999999 -999999999\n3\n", "output": "16\n"}, {"input": "-1 0\n1\n", "output": "1000000006\n"}, {"input": "1000000000 -1000000000\n9\n", "output": "14\n"}, {"input": "999999999 -1000000000\n12\n", "output": "999999992\n"}, {"input": "1000000000 -7\n3\n", "output": "0\n"}, {"input": "-5 5\n6\n", "output": "999999997\n"}, {"input": "5 9\n6\n", "output": "1000000003\n"}, {"input": "-15 -10\n1\n", "output": "999999992\n"}] |
|
210 | One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split the array A into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array A.
Lesha is tired now so he asked you to split the array. Help Lesha!
-----Input-----
The first line contains single integer n (1 ≤ n ≤ 100) — the number of elements in the array A.
The next line contains n integers a_1, a_2, ..., a_{n} ( - 10^3 ≤ a_{i} ≤ 10^3) — the elements of the array A.
-----Output-----
If it is not possible to split the array A and satisfy all the constraints, print single line containing "NO" (without quotes).
Otherwise in the first line print "YES" (without quotes). In the next line print single integer k — the number of new arrays. In each of the next k lines print two integers l_{i} and r_{i} which denote the subarray A[l_{i}... r_{i}] of the initial array A being the i-th new array. Integers l_{i}, r_{i} should satisfy the following conditions: l_1 = 1 r_{k} = n r_{i} + 1 = l_{i} + 1 for each 1 ≤ i < k.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 -3
Output
YES
2
1 2
3 3
Input
8
9 -12 3 4 -4 -10 7 3
Output
YES
2
1 2
3 8
Input
1
0
Output
NO
Input
4
1 2 3 -5
Output
YES
4
1 1
2 2
3 3
4 4 | interview | [{"code": "from sys import stdin\n\nn = int(input())\na = [int(x) for x in input().split()]\n\nf = False\nfor i in range(len(a)):\n if a[i] != 0:\n ln = i\n f = True\n break\nif not f:\n print('NO')\nelse:\n print('YES')\n l = 0\n i = ln + 1\n ans = []\n while i < len(a):\n if a[i] == 0:\n i += 1\n else:\n ans.append((l+1, i))\n l = i\n i += 1\n if l < len(a):\n ans.append((l+1, i))\n print(len(ans))\n for i in ans:\n print(i[0],i[1])\n\n", "passed": true, "time": 0.14, "memory": 14608.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nb = []\no = 0\nl = 1\nif a[0] == 0:\n f = 0\n for i in range(1, len(a)):\n if a[i] == 0:\n pass\n else:\n if f != 0:\n b += [[l, i]]\n l = i + 1\n f = 1\n if f != 0:\n b += [[l, n]]\nelse:\n for i in range(1, len(a)):\n if a[i] == 0:\n pass\n else:\n b += [[l, i]]\n l = i + 1\n b += [[l, n]]\nif len(b) == 0:\n print('NO')\nelse:\n print('YES', len(b), sep = '\\n')\n for i in b:\n print(*i)\n", "passed": true, "time": 0.14, "memory": 14376.0, "status": "done"}] | [{"input": "3\n1 2 -3\n", "output": "YES\n3\n1 1\n2 2\n3 3\n"}, {"input": "8\n9 -12 3 4 -4 -10 7 3\n", "output": "YES\n8\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n"}, {"input": "1\n0\n", "output": "NO\n"}, {"input": "4\n1 2 3 -5\n", "output": "YES\n4\n1 1\n2 2\n3 3\n4 4\n"}, {"input": "6\n0 0 0 0 0 0\n", "output": "NO\n"}, {"input": "7\n0 0 0 0 3 -3 0\n", "output": "YES\n2\n1 5\n6 7\n"}, {"input": "5\n0 0 -4 0 0\n", "output": "YES\n1\n1 5\n"}, {"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -38 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "YES\n1\n1 100\n"}, {"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "NO\n"}, {"input": "100\n0 0 -17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "YES\n2\n1 34\n35 100\n"}, {"input": "3\n1 -3 3\n", "output": "YES\n3\n1 1\n2 2\n3 3\n"}, {"input": "3\n1 0 -1\n", "output": "YES\n2\n1 2\n3 3\n"}, {"input": "3\n3 0 0\n", "output": "YES\n1\n1 3\n"}, {"input": "3\n0 0 0\n", "output": "NO\n"}, {"input": "3\n-3 3 0\n", "output": "YES\n2\n1 1\n2 3\n"}, {"input": "4\n3 -2 -1 3\n", "output": "YES\n4\n1 1\n2 2\n3 3\n4 4\n"}, {"input": "4\n-1 0 1 0\n", "output": "YES\n2\n1 2\n3 4\n"}, {"input": "4\n0 0 0 3\n", "output": "YES\n1\n1 4\n"}, {"input": "4\n0 0 0 0\n", "output": "NO\n"}, {"input": "4\n3 0 -3 0\n", "output": "YES\n2\n1 2\n3 4\n"}, {"input": "5\n-3 2 2 0 -2\n", "output": "YES\n4\n1 1\n2 2\n3 4\n5 5\n"}, {"input": "5\n0 -1 2 0 -1\n", "output": "YES\n3\n1 2\n3 4\n5 5\n"}, {"input": "5\n0 2 0 0 0\n", "output": "YES\n1\n1 5\n"}, {"input": "5\n0 0 0 0 0\n", "output": "NO\n"}, {"input": "5\n0 0 0 0 0\n", "output": "NO\n"}, {"input": "20\n101 89 -166 -148 -38 -135 -138 193 14 -134 -185 -171 -52 -191 195 39 -148 200 51 -73\n", "output": "YES\n20\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n"}, {"input": "20\n-118 -5 101 7 9 144 55 -55 -9 -126 -71 -71 189 -64 -187 123 0 -48 -12 138\n", "output": "YES\n19\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 17\n18 18\n19 19\n20 20\n"}, {"input": "20\n-161 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "YES\n1\n1 20\n"}, {"input": "20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "NO\n"}, {"input": "20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 -137 0 0 0 0 137\n", "output": "YES\n2\n1 19\n20 20\n"}, {"input": "40\n64 -94 -386 -78 35 -233 33 82 -5 -200 368 -259 124 353 390 -305 -247 -133 379 44 133 -146 151 -217 -16 53 -157 186 -203 -8 117 -71 272 -290 -97 133 52 113 -280 -176\n", "output": "YES\n40\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n"}, {"input": "40\n120 -96 -216 131 231 -80 -166 -102 16 227 -120 105 43 -83 -53 229 24 190 -268 119 230 348 -33 19 0 -187 -349 -25 80 -38 -30 138 -104 337 -98 0 1 -66 -243 -231\n", "output": "YES\n38\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 36\n37 37\n38 38\n39 39\n40 40\n"}, {"input": "40\n0 0 0 0 0 0 324 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "YES\n1\n1 40\n"}, {"input": "40\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "NO\n"}, {"input": "40\n0 0 0 0 0 308 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -308 0 0 0 0 0 0 0\n", "output": "YES\n2\n1 32\n33 40\n"}, {"input": "60\n-288 -213 -213 -23 496 489 137 -301 -219 -296 -577 269 -153 -52 -505 -138 -377 500 -256 405 588 274 -115 375 -93 117 -360 -160 429 -339 502 310 502 572 -41 -26 152 -203 562 -525 -179 -67 424 62 -329 -127 352 -474 417 -30 518 326 200 -598 471 107 339 107 -9 -244\n", "output": "YES\n60\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n"}, {"input": "60\n112 141 -146 -389 175 399 -59 327 -41 397 263 -422 157 0 471 -2 -381 -438 99 368 173 9 -171 118 24 111 120 70 11 317 -71 -574 -139 0 -477 -211 -116 -367 16 568 -75 -430 75 -179 -21 156 291 -422 441 -224 -8 -337 -104 381 60 -138 257 91 103 -359\n", "output": "YES\n58\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n"}, {"input": "60\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -238 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "YES\n1\n1 60\n"}, {"input": "60\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "NO\n"}, {"input": "60\n0 0 0 0 0 0 0 0 0 -98 0 0 0 0 0 0 0 0 98 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "YES\n2\n1 18\n19 60\n"}, {"input": "80\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 668 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "YES\n1\n1 80\n"}, {"input": "80\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "NO\n"}, {"input": "80\n0 0 0 0 0 0 0 0 0 0 0 0 -137 137 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "YES\n2\n1 13\n14 80\n"}, {"input": "100\n0 0 697 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "YES\n1\n1 100\n"}, {"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "NO\n"}, {"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -475 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 475 0 0 0 0\n", "output": "YES\n2\n1 95\n96 100\n"}, {"input": "4\n0 0 3 -3\n", "output": "YES\n2\n1 3\n4 4\n"}, {"input": "4\n1 0 0 0\n", "output": "YES\n1\n1 4\n"}, {"input": "4\n3 3 3 3\n", "output": "YES\n4\n1 1\n2 2\n3 3\n4 4\n"}, {"input": "2\n0 1\n", "output": "YES\n1\n1 2\n"}, {"input": "4\n0 -1 1 0\n", "output": "YES\n2\n1 2\n3 4\n"}, {"input": "1\n1\n", "output": "YES\n1\n1 1\n"}, {"input": "5\n0 0 1 0 0\n", "output": "YES\n1\n1 5\n"}, {"input": "4\n0 0 1 0\n", "output": "YES\n1\n1 4\n"}, {"input": "10\n1 2 0 0 3 -3 0 0 -3 0\n", "output": "YES\n5\n1 1\n2 4\n5 5\n6 8\n9 10\n"}, {"input": "3\n0 -1 0\n", "output": "YES\n1\n1 3\n"}, {"input": "2\n1 0\n", "output": "YES\n1\n1 2\n"}, {"input": "5\n3 -3 0 0 0\n", "output": "YES\n2\n1 1\n2 5\n"}, {"input": "3\n0 1 0\n", "output": "YES\n1\n1 3\n"}, {"input": "4\n0 0 0 1\n", "output": "YES\n1\n1 4\n"}, {"input": "4\n1 -1 1 -1\n", "output": "YES\n4\n1 1\n2 2\n3 3\n4 4\n"}, {"input": "1\n-1\n", "output": "YES\n1\n1 1\n"}, {"input": "2\n1 1\n", "output": "YES\n2\n1 1\n2 2\n"}, {"input": "2\n1 -1\n", "output": "YES\n2\n1 1\n2 2\n"}, {"input": "2\n0 0\n", "output": "NO\n"}, {"input": "2\n0 -1\n", "output": "YES\n1\n1 2\n"}, {"input": "2\n-1 1\n", "output": "YES\n2\n1 1\n2 2\n"}, {"input": "2\n-1 0\n", "output": "YES\n1\n1 2\n"}, {"input": "2\n-1 -1\n", "output": "YES\n2\n1 1\n2 2\n"}, {"input": "3\n5 -5 5\n", "output": "YES\n3\n1 1\n2 2\n3 3\n"}, {"input": "5\n1 0 -1 0 1\n", "output": "YES\n3\n1 2\n3 4\n5 5\n"}, {"input": "6\n0 0 0 3 0 0\n", "output": "YES\n1\n1 6\n"}, {"input": "3\n1 -1 1\n", "output": "YES\n3\n1 1\n2 2\n3 3\n"}] |
|
211 | Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this counter increases by 1. If the player answers a question incorrectly, the counter is reset, that is, the number on it reduces to 0. If after an answer the counter reaches the number k, then it is reset, and the player's score is doubled. Note that in this case, first 1 point is added to the player's score, and then the total score is doubled. At the beginning of the game, both the player's score and the counter of consecutive correct answers are set to zero.
Manao remembers that he has answered exactly m questions correctly. But he does not remember the order in which the questions came. He's trying to figure out what his minimum score may be. Help him and compute the remainder of the corresponding number after division by 1000000009 (10^9 + 9).
-----Input-----
The single line contains three space-separated integers n, m and k (2 ≤ k ≤ n ≤ 10^9; 0 ≤ m ≤ n).
-----Output-----
Print a single integer — the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (10^9 + 9).
-----Examples-----
Input
5 3 2
Output
3
Input
5 4 2
Output
6
-----Note-----
Sample 1. Manao answered 3 questions out of 5, and his score would double for each two consecutive correct answers. If Manao had answered the first, third and fifth questions, he would have scored as much as 3 points.
Sample 2. Now Manao answered 4 questions. The minimum possible score is obtained when the only wrong answer is to the question 4.
Also note that you are asked to minimize the score and not the remainder of the score modulo 1000000009. For example, if Manao could obtain either 2000000000 or 2000000020 points, the answer is 2000000000 mod 1000000009, even though 2000000020 mod 1000000009 is a smaller number. | interview | [{"code": "MOD = 1000000009\n\nn,m,k = [int(x) for x in input().split()]\n\nnum0 = n-m\nnum1fin = num0*(k-1)\nif num1fin >= m:\n print(m)\nelse:\n num1open = m-num1fin\n sets = num1open//k\n rem = num1open%k\n print(((pow(2,sets,MOD)-1)*2*k+rem+num1fin)%MOD)\n", "passed": true, "time": 0.15, "memory": 14360.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\nmod = 1000000000 + 9\nx = m - (n // k * (k-1) + (n%k))\nif (x <= 0):\n\tprint (m % mod)\nelse:\n\tprint(((m-x) + ((pow(2, x + 1, mod) + 2 * mod)-2)*k - x*(k-1))%mod)", "passed": true, "time": 1.0, "memory": 14536.0, "status": "done"}, {"code": "n, corecte, k = list(map(int, input().split()))\nincorecte = n - corecte\nmod = 10**9 + 9\n\n\ncorecte_consecutive = max(0, n - incorecte * k)\ndublari = corecte_consecutive // k\ncorecte_ramase = corecte - corecte_consecutive\n\ndef power(b, exp):\n if exp == 0: return 1\n\n half = power(b, exp//2)\n if exp%2 == 0: return (half*half) % mod\n return (half*half*b) % mod\n\nscore = (power(2, dublari+1) - 2) * k + corecte_ramase + corecte_consecutive % k\n\nprint(score % mod)\n", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "def chk(x):\n d = (m - x) // (k - 1) * k\n if (m - x) % (k - 1):\n d += 1 + (m - x) % (k - 1)\n if d <= n - x:\n return True\n else:\n return False\n\ndef calc(e):\n if e == 1:\n return 2\n if e & 1:\n d = 2\n else:\n d = 1\n f = calc(e >> 1)\n d = d * f % D * f % D\n return d\n\nn, m, k = list(map(int, input().split()))\nD = 1000000009\n\nl = 0\nh = n\n\nwhile l < h:\n mid = l + h >>1\n if chk(mid):\n h = mid\n else:\n l = mid + 1\n\nh = calc(l // k + 1) - 2 \nif h < 0:\n h += D\n\nprint((k * h % D + m - l // k * k) % D)\n", "passed": true, "time": 0.16, "memory": 14612.0, "status": "done"}, {"code": "MOD = 1000000009\nn, m, k = list(map(int, input().split()))\nx = m - (n // k * (k - 1) + n % k)\n\nif x <= 0:\n print(m)\nelse:\n print(((m - x) + (pow(2, x + 1, MOD) - 2) * k - x * (k - 1)) % MOD)\n", "passed": true, "time": 0.27, "memory": 14472.0, "status": "done"}, {"code": "MOD=1000000009;\ndef solve(a,n):\n ans=1;\n p=a;\n while(n>0):\n if(n%2==1): ans*=p;\n n//=2;\n ans%=MOD;\n p=(p*p)%MOD;\n return ans;\nn,m,k=map(int,input().split());\np=n-m+1;\nif((k-1)*p>=m):\n print(m);\nelse:\n v=m-(p-1)*(k-1);\n ans=(p-1)*(k-1);\n t=v//k;\n ans=(ans+k*(solve(2,t)-1)*2%MOD+MOD+v%k)%MOD;\n print(ans);", "passed": true, "time": 0.25, "memory": 14564.0, "status": "done"}, {"code": "MOD = 10 ** 9 + 9\ndp = {0:1, 1:2}\n\ndef two_pow (n):\n if n not in dp: \n dp[n] = (two_pow(n // 2) * two_pow(n // 2)\n * (2 if n%2 == 1 else 1) % MOD)\n return dp[n]\n\nn,m,k = list(map (int, input().split()));\nfit = n - n//k\nif m <= fit:\n print (m)\nelse:\n a = m - fit\n rem = m - k*a\n print(((two_pow(a+1)-2)*k + rem) % MOD)\n", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\n\nd = max(0, n // k - (n - m))\n\nM = 1000000009\n\nif d > 0:\n res = ((2 * k * (pow(2, d, M) - 1)) % M + m - k * d) % M\nelse:\n res = m\n\nprint(res)", "passed": true, "time": 0.32, "memory": 14520.0, "status": "done"}, {"code": "d = 1000000009\nn, m, k = map(int, input().split())\nif (n - m) * k > n: print(m)\nelse:\n t = n // k - n + m + 1\n print(((pow(2, t, d) - 1 - t) * k + m) % d)", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "3\n\ndef modulo_power(modulo, power, base):\n if power == 0:\n return 1\n if power == 1:\n return base\n\n remainder = power % 2\n power -= remainder\n\n half = modulo_power(modulo, power/2, base)\n\n return (half * half * modulo_power(modulo, remainder, base)) % modulo\n\ndata = [int(token) for token in input().split()]\nnum_questions, num_correct, doubler = data\n\nnum_wrong = num_questions - num_correct\ntail = num_wrong * (doubler - 1)\nhead = num_correct - tail\n\nif head < 0:\n print(num_correct)\n return\n\nnum_doublings = head // doubler\nremainder = head - num_doublings * doubler\nmodulo = 10**9 + 9\nresult = ((2 * doubler * (modulo_power(modulo, num_doublings, 2) - 1)) +\n remainder + tail) % modulo\n\nprint(result)\n\n", "passed": true, "time": 0.16, "memory": 14476.0, "status": "done"}, {"code": "d = 1000000009\nn, m, k = map(int, input().split())\nif (n - m) * k > n:\n print(m)\nelse:\n t = n // k - n + m + 1\n print(((pow(2, t, d) - 1 - t) * k + m) % d)", "passed": true, "time": 0.16, "memory": 14364.0, "status": "done"}, {"code": "MOD = 1000000009\n\nn,m,k = [int(x) for x in input().split()]\n\nnum0 = n-m\nnum1fin = num0*(k-1)\nif num1fin >= m:\n print(m)\nelse:\n num1open = m-num1fin\n sets = num1open//k\n rem = num1open%k\n print(((pow(2,sets,MOD)-1)*2*k+rem+num1fin)%MOD)", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\n\nif (n - m) >= n//k:\n\tprint (m)\nelse:\n\tlongest_correct_streak = n - k*(n - m)\n\tp = longest_correct_streak//k\n\tprint((k*(pow(2, p+1, 1000000009) - 2) + (longest_correct_streak % k) + (n - m)*(k - 1)) % 1000000009)\n", "passed": true, "time": 0.91, "memory": 14488.0, "status": "done"}, {"code": "MOD = 1000000009\ndef p2(e):\n if e == 0:\n return 1\n elif e % 2 == 1:\n return 2 * p2(e - 1) % MOD\n else:\n return p2(e // 2) ** 2 % MOD\n\nn, m, k = map(int, input().split())\nx = (m - min(n - m, m // (k - 1)) * (k - 1)) // k\nprint((2 * k * (p2(x) - 1) + m - x * k) % MOD)", "passed": true, "time": 0.14, "memory": 14556.0, "status": "done"}, {"code": "MOD =1000000009\nn,m,k=map(int,input().split())\nx=max(0,m-(n-n%k)//k*(k-1)-n%k)\nres=((((pow(2,x+1,MOD))-2)%MOD)*k)%MOD\nz=(m-x*k)%MOD\nres=(res+z)%MOD\nprint (res)", "passed": true, "time": 0.14, "memory": 14336.0, "status": "done"}, {"code": "\n #COPIED\n\nMOD = 1000000009\n\nn,m,k = [int(x) for x in input().split()]\n\nnum0 = n-m\nnum1fin = num0*(k-1)\nif num1fin >= m:\n print(m)\nelse:\n num1open = m-num1fin\n sets = num1open//k\n rem = num1open%k\n print(((pow(2,sets,MOD)-1)*2*k+rem+num1fin)%MOD)", "passed": true, "time": 0.14, "memory": 14452.0, "status": "done"}, {"code": "MOD =1000000009\nn,m,k=map(int,input().split())\nx=max(0,m-(n-n%k)//k*(k-1)-n%k)\nres=((((pow(2,x+1,MOD))-2)%MOD)*k)%MOD\nz=(m-x*k)%MOD\nres=(res+z)%MOD\nprint (res)", "passed": true, "time": 0.14, "memory": 14432.0, "status": "done"}, {"code": "# Allah is the most gracious and the Most Marchiful\nnum,m,k=list(map(int,input().split()))\nna=num-m\nif((na+1)*(k-1)>=m):\n print(m)\nelse:\n sa=na*(k-1)\n nsa=m-sa\n #print(nsa)\n M=(10**9)+9\n ans=(pow(2,(nsa//k)+1,M)-2)*k\n ans+=nsa%k\n ans+=sa\n print((ans+0)%1000000009)\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "passed": true, "time": 0.14, "memory": 14308.0, "status": "done"}, {"code": "n,m,k=map(int,input().split())\nif n-n//k>=m:print(m);return\nmod=int(1e9+9)\nx=n//k+m-n\nr=pow(2,x+1,mod)-2\na=r*k+m-x*k\nprint((a%mod+mod)%mod)", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "MOD = 1000000009\n\ndef log_mult(a, p):\n if p == 0:\n return 1\n else:\n z = log_mult(a, p//2)\n z = (z*z) % MOD\n if (p % 2) == 1:\n return (a*z) % MOD\n else:\n return z\n \nn, m, k = list(map(int, input().split()))\nc = (n//k) * (k-1) + n % k \nif c >= m:\n print(m)\nelse:\n d = m - c\n res = log_mult(2, d+1) - 2\n res = (res * k) % MOD\n print((res + m-d*k) % MOD)\n", "passed": true, "time": 0.14, "memory": 14520.0, "status": "done"}, {"code": "MOD = 1000000009\n\ndef log_mult(a, p):\n if p == 0:\n return 1\n else:\n z = log_mult(a, p//2)\n z = (z*z) % MOD\n if (p % 2) == 1:\n return (a*z) % MOD\n else:\n return z\n \ndef log_iterative(a, p):\n res = 1\n while p > 0:\n if p % 2 == 1:\n res = (res*a) % MOD\n a = (a*a) % MOD\n p //= 2\n return res\n \nn, m, k = list(map(int, input().split()))\nc = (n//k) * (k-1) + n % k \nif c >= m:\n print(m)\nelse:\n d = m - c\n res = log_iterative(2, d+1) - 2\n res = (res * k) % MOD\n print((res + m-d*k) % MOD)\n", "passed": true, "time": 0.14, "memory": 14380.0, "status": "done"}, {"code": "n,m,k=map(int,input().split())\nif n-n//k>=m:print(m);return\nmod=int(1e9+9)\nx=n//k+m-n\nr=pow(2,x+1,mod)-2\na=r*k+m-x*k\nprint((a%mod+mod)%mod)", "passed": true, "time": 0.14, "memory": 14312.0, "status": "done"}, {"code": "n,m,k=map(int,input().split())\nMOD=1000000009\nx=m-(n//k*(k-1)+(n%k))\nif (x<=0):print(m%MOD);return\nprint(((m-x)+((pow(2,x+1, MOD)+2*MOD)-2)*k-x*(k-1))%MOD)", "passed": true, "time": 0.19, "memory": 14316.0, "status": "done"}, {"code": "b = 10**9 + 9\ndef f(q): \n x = q//1000\n y = q%1000\n num = 2**1000 % b\n res = 1\n for i in range(x):\n res = (res * num) % b\n res = (res * 2**y) %b\n return res\n\ndef F(n,m,k):\n r = n%k\n if m <= n//k * (k-1) + r :\n print(m%b) \n else:\n q = m - (n//k * (k-1) + r)\n print((m + (f(q+1)-q-2)*k)%b)\n \nn,m,k = [int(x) for x in input().split(' ')]\nF(n,m,k)\n", "passed": true, "time": 0.37, "memory": 14432.0, "status": "done"}, {"code": "n,m,k=map(int,input().split())\nMOD=1000000009\nx=m-(n//k*(k-1)+(n%k))\nif (x<=0):print(m%MOD);return\nprint(((m-x)+((pow(2,x+1, MOD)+2*MOD)-2)*k-x*(k-1))%MOD)", "passed": true, "time": 0.15, "memory": 14524.0, "status": "done"}] | [{"input": "5 3 2\n", "output": "3\n"}, {"input": "5 4 2\n", "output": "6\n"}, {"input": "300 300 3\n", "output": "17717644\n"}, {"input": "300 282 7\n", "output": "234881124\n"}, {"input": "1000000000 1000000000 1000000000\n", "output": "999999991\n"}, {"input": "1000000000 800000000 2\n", "output": "785468433\n"}, {"input": "2 0 2\n", "output": "0\n"}, {"input": "2 1 2\n", "output": "1\n"}, {"input": "2 2 2\n", "output": "4\n"}, {"input": "3 2 2\n", "output": "2\n"}, {"input": "3 3 2\n", "output": "5\n"}, {"input": "10 7 3\n", "output": "7\n"}, {"input": "10 8 3\n", "output": "11\n"}, {"input": "10 8 5\n", "output": "8\n"}, {"input": "10 9 5\n", "output": "14\n"}, {"input": "972 100 2\n", "output": "100\n"}, {"input": "972 600 2\n", "output": "857317034\n"}, {"input": "972 900 2\n", "output": "129834751\n"}, {"input": "972 900 4\n", "output": "473803848\n"}, {"input": "972 900 5\n", "output": "682661588\n"}, {"input": "12345 11292 3\n", "output": "307935747\n"}, {"input": "120009 70955 2\n", "output": "938631761\n"}, {"input": "120009 100955 2\n", "output": "682499671\n"}, {"input": "291527 253014 7\n", "output": "572614130\n"}, {"input": "300294 299002 188\n", "output": "435910952\n"}, {"input": "23888888 508125 3\n", "output": "508125\n"}, {"input": "23888888 16789012 2\n", "output": "573681250\n"}, {"input": "23888888 19928497 4\n", "output": "365378266\n"}, {"input": "23888888 19928497 5\n", "output": "541851325\n"}, {"input": "23888888 19928497 812\n", "output": "19928497\n"}, {"input": "23888888 23862367 812\n", "output": "648068609\n"}, {"input": "87413058 85571952 11\n", "output": "996453351\n"}, {"input": "87413058 85571952 12\n", "output": "903327586\n"}, {"input": "87413058 85571952 25\n", "output": "424641940\n"}, {"input": "512871295 482216845 2\n", "output": "565667832\n"}, {"input": "512871295 482216845 3\n", "output": "446175557\n"}, {"input": "512871295 508216845 90\n", "output": "332476079\n"}, {"input": "512871295 512816845 99712\n", "output": "512816845\n"}, {"input": "512871295 512870845 99712\n", "output": "944454424\n"}, {"input": "512871295 512870845 216955\n", "output": "28619469\n"}, {"input": "512871295 512871195 2000000\n", "output": "559353433\n"}, {"input": "512871295 512871295 12345678\n", "output": "423625559\n"}, {"input": "778562195 708921647 4\n", "output": "208921643\n"}, {"input": "500000000 500000000 4\n", "output": "1000000005\n"}, {"input": "375000000 375000000 3\n", "output": "1000000006\n"}, {"input": "250000000 250000000 2\n", "output": "1000000007\n"}, {"input": "300000000 300000000 12561295\n", "output": "543525658\n"}, {"input": "300000000 300000000 212561295\n", "output": "512561295\n"}, {"input": "300000000 300000000 299999999\n", "output": "599999999\n"}, {"input": "500000002 500000002 2\n", "output": "1000000007\n"}, {"input": "625000001 625000000 5\n", "output": "500000002\n"}, {"input": "875000005 875000000 7\n", "output": "531250026\n"}, {"input": "1000000000 1000000000 8\n", "output": "1000000001\n"}, {"input": "901024556 900000000 6\n", "output": "175578776\n"}, {"input": "901024556 900000000 91\n", "output": "771418556\n"}, {"input": "901024556 900000000 92\n", "output": "177675186\n"}, {"input": "901024556 900000000 888\n", "output": "900000000\n"}, {"input": "901024556 901000000 1000\n", "output": "443969514\n"}, {"input": "901024556 901000000 1013\n", "output": "840398451\n"}, {"input": "999998212 910275020 25\n", "output": "910275020\n"}, {"input": "999998212 999998020 1072520\n", "output": "314152037\n"}, {"input": "999998212 999998020 381072520\n", "output": "999998020\n"}, {"input": "999998212 999998210 381072520\n", "output": "999998210\n"}, {"input": "999998212 999998211 499998210\n", "output": "499996412\n"}, {"input": "1000000000 1000000000 1000000000\n", "output": "999999991\n"}, {"input": "1000000000 1000000000 772625255\n", "output": "772625246\n"}, {"input": "1000000000 999999904 225255\n", "output": "940027552\n"}, {"input": "1000000000 999998304 22255\n", "output": "969969792\n"}, {"input": "1000000000 999998304 7355\n", "output": "756187119\n"}, {"input": "1000000000 999998304 755\n", "output": "684247947\n"}, {"input": "1000000000 999998304 256\n", "output": "401008799\n"}, {"input": "1000000000 1000000000 2\n", "output": "750000003\n"}, {"input": "1000000000 1 999999998\n", "output": "1\n"}] |
|
212 | You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits.
If a solution exists, you should print it.
-----Input-----
The single line of the input contains a non-negative integer n. The representation of number n doesn't contain any leading zeroes and its length doesn't exceed 100 digits.
-----Output-----
Print "NO" (without quotes), if there is no such way to remove some digits from number n.
Otherwise, print "YES" in the first line and the resulting number after removing digits from number n in the second line. The printed number must be divisible by 8.
If there are multiple possible answers, you may print any of them.
-----Examples-----
Input
3454
Output
YES
344
Input
10
Output
YES
0
Input
111111
Output
NO | interview | [{"code": "n1 = input()\nn = []\nfor i in n1:\n n.append(int(i))\nk = len(n)\n\nfor i in range(k):\n if (n[i] % 8) == 0:\n print(\"YES\")\n print(n[i])\n return\n\nif k > 1:\n for i in range(k):\n t = n[i] * 10\n for j in range(i+1, k):\n if (t+n[j]) % 8 == 0:\n print(\"YES\")\n print(t+n[j])\n return\nif k > 2:\n for i in range(k):\n t = n[i]*100\n for j in range(i+1, k):\n l = n[j]*10\n for e in range(j+1, k):\n #print(t, l, n[e])\n if (t+l+n[e]) % 8 == 0:\n print(\"YES\")\n print(t+l+n[e])\n return\nprint(\"NO\")\n", "passed": true, "time": 0.56, "memory": 14408.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\nimport time\n\ns = input()\nflag = False\nans = \"\"\n\nstart = time.time()\nfor i in s:\n if i == '8' or i =='0':\n ans = i\n break\n\nif len(s) >= 2 and ans == \"\":\n for i in range(len(s)-1):\n for j in range(i+1, len(s)):\n if divmod(int(s[i]+s[j]), 8)[1] == 0:\n ans = s[i]+s[j]\n break\n\n if ans != \"\":\n break\n\nif len(s) >= 3 and ans ==\"\":\n for i in range(len(s)-2):\n for j in range(i+1, len(s)-1):\n for k in range(j+1, len(s)):\n if divmod(int(s[i]+s[j]+s[k]), 8)[1] == 0:\n ans = s[i]+s[j]+s[k]\n break\n if ans != \"\":\n break\n if ans != \"\":\n break\n\nif ans == \"\":\n print(\"NO\")\nelse:\n print(\"YES\")\n print(ans)\nfinish = time.time()\n#print(finish - start)\n", "passed": true, "time": 1.0, "memory": 14472.0, "status": "done"}] | [{"input": "3454\n", "output": "YES\n344\n"}, {"input": "10\n", "output": "YES\n0\n"}, {"input": "111111\n", "output": "NO\n"}, {"input": "8996988892\n", "output": "YES\n8\n"}, {"input": "5555555555\n", "output": "NO\n"}, {"input": "1\n", "output": "NO\n"}, {"input": "8147522776919916277306861346922924221557534659480258977017038624458370459299847590937757625791239188\n", "output": "YES\n8\n"}, {"input": "8\n", "output": "YES\n8\n"}, {"input": "14\n", "output": "NO\n"}, {"input": "2363\n", "output": "NO\n"}, {"input": "3554\n", "output": "NO\n"}, {"input": "312\n", "output": "YES\n32\n"}, {"input": "7674\n", "output": "YES\n64\n"}, {"input": "126\n", "output": "YES\n16\n"}, {"input": "344\n", "output": "YES\n344\n"}, {"input": "976\n", "output": "YES\n96\n"}, {"input": "3144\n", "output": "YES\n344\n"}, {"input": "1492\n", "output": "YES\n192\n"}, {"input": "1000\n", "output": "YES\n0\n"}, {"input": "303\n", "output": "YES\n0\n"}, {"input": "111111111111111111111171111111111111111111111111111112\n", "output": "YES\n72\n"}, {"input": "3111111111111111111111411111111111111111111141111111441\n", "output": "YES\n344\n"}, {"input": "7486897358699809313898215064443112428113331907121460549315254356705507612143346801724124391167293733\n", "output": "YES\n8\n"}, {"input": "1787075866\n", "output": "YES\n8\n"}, {"input": "836501278190105055089734832290981\n", "output": "YES\n8\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "output": "NO\n"}, {"input": "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222\n", "output": "NO\n"}, {"input": "3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333\n", "output": "NO\n"}, {"input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", "output": "YES\n0\n"}, {"input": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555\n", "output": "NO\n"}, {"input": "66666666666666666666666666666666666666666666666666666666666666666666666666666\n", "output": "NO\n"}, {"input": "88888888888888888888888888888888888888888888888888888888888888888888888888888888\n", "output": "YES\n8\n"}, {"input": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n", "output": "NO\n"}, {"input": "353\n", "output": "NO\n"}, {"input": "39\n", "output": "NO\n"}, {"input": "3697519\n", "output": "NO\n"}, {"input": "6673177113\n", "output": "NO\n"}, {"input": "6666351371557713735\n", "output": "NO\n"}, {"input": "17943911115335733153157373517\n", "output": "NO\n"}, {"input": "619715515939999957957971971757533319177373\n", "output": "NO\n"}, {"input": "4655797151375799393395377959959573533195153397997597195199777159133\n", "output": "NO\n"}, {"input": "5531399953495399131957773999751571911139197159755793777773799119333593915333593153173775755771193715\n", "output": "NO\n"}, {"input": "1319571733331774579193199551977735199771153997797535591739153377377111795579371959933533573517995559\n", "output": "NO\n"}, {"input": "3313393139519343957311771319713797711159791515393917539133957799131393735795317131513557337319131993\n", "output": "NO\n"}, {"input": "526\n", "output": "YES\n56\n"}, {"input": "513\n", "output": "NO\n"}, {"input": "674\n", "output": "YES\n64\n"}, {"input": "8353\n", "output": "YES\n8\n"}, {"input": "3957\n", "output": "NO\n"}, {"input": "4426155776626276881222352363321488266188669874572115686737742545442766138617391954346963915982759371\n", "output": "YES\n8\n"}, {"input": "9592419524227735697379444145348135927975358347769514686865768941989693174565893724972575152874281772\n", "output": "YES\n8\n"}, {"input": "94552498866729239313265973246288189853135485783461\n", "output": "YES\n8\n"}, {"input": "647934465937812\n", "output": "YES\n8\n"}, {"input": "1327917795375366484539554526312125336\n", "output": "YES\n8\n"}, {"input": "295971811535848297878828225646878276486982655866912496735794542\n", "output": "YES\n8\n"}, {"input": "7217495392264549817889283233368819844137671271383133997418139697797385729777632527678136\n", "output": "YES\n8\n"}, {"input": "11111111111111111111112111111111\n", "output": "YES\n112\n"}, {"input": "262626262626262626262626262626262626\n", "output": "NO\n"}, {"input": "1000000000000000000000000000000000000\n", "output": "YES\n0\n"}, {"input": "9969929446\n", "output": "YES\n96\n"}, {"input": "43523522125549722432232256557771715456345544922144\n", "output": "YES\n32\n"}, {"input": "9344661521956564755454992376342544254667536539463277572111263273131199437332443253296774957\n", "output": "YES\n96\n"}, {"input": "1946374341357914632311595531429723377642197432217137651552992479954116463332543456759911377223599715\n", "output": "YES\n16\n"}, {"input": "461259\n", "output": "NO\n"}, {"input": "461592\n", "output": "YES\n152\n"}, {"input": "46159237\n", "output": "YES\n152\n"}, {"input": "42367\n", "output": "NO\n"}, {"input": "42376\n", "output": "YES\n376\n"}, {"input": "42376159\n", "output": "YES\n376\n"}, {"input": "444444444444444444444444444444666666666666666666666666666666222222222222222222222222222222\n", "output": "NO\n"}, {"input": "0\n", "output": "YES\n0\n"}, {"input": "33332\n", "output": "YES\n32\n"}, {"input": "6499999999\n", "output": "YES\n64\n"}] |
|
213 | In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
-----Input-----
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers k_{i}, f_{i} (1 ≤ k_{i} ≤ 100, 1 ≤ f_{i} ≤ 100), which means that the flat k_{i} is on the f_{i}-th floor. All values k_{i} are distinct.
It is guaranteed that the given information is not self-contradictory.
-----Output-----
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
-----Examples-----
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
-----Note-----
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat. | interview | [{"code": "def floo(num, k):\n\treturn (num - 1) // k + 1\n\ndef main():\n\tn, m = map(int, input().split())\n\tlow = 1\n\thigh = 10**9\n\n\tif (m == 0):\n\t\tif (n == 1):\n\t\t\tprint(1)\n\t\telse:\n\t\t\tprint(-1)\n\t\treturn\n\n\tfor i in range(m):\n\t\tk, f = map(int, input().split())\n\t\tlow = max(low, (k + f - 1) // f)\n\t\tif (f > 1):\n\t\t\thigh = min(high, (k - 1) // (f - 1))\n\tif (floo(n, low) == floo(n, high)):\n\t\tprint(floo(n, low))\n\telse:\n\t\tprint(-1)\n\n\n\nmain()", "passed": true, "time": 0.16, "memory": 14416.0, "status": "done"}, {"code": "n, m = [int(x) for x in input().split()]\ndata = []\nfor i in range(m):\n k, f = [int(x) for x in input().split()]\n data.append((k - 1, f - 1))\nans = set()\n#tmp = []\nfor x in range(1, 101):\n for elem in data:\n if elem[0] // x != elem[1]:\n break\n else:\n ans.add((n - 1) // x + 1)\n #tmp.append((n - 1) // x + 1)\nif len(ans) == 1:\n print(ans.pop())\nelse:\n print(-1)", "passed": true, "time": 0.25, "memory": 14412.0, "status": "done"}, {"code": "n, m = map(int, input().split())\na = []\nfor i in range(m):\n k, f = map(int, input().split())\n a.append((k, f))\nfl = []\nps = 0\nval = -1\nfor i in range(1, 1000):\n flag = 1\n for j in range(m):\n if (a[j][0] - 1) // i != a[j][1] - 1:\n flag = 0\n if (flag):\n ps += 1\n fl.append(i)\nans = []\nfor i in range(len(fl)):\n ans.append(((n - 1) // fl[i]) + 1)\nif not len(ans):\n print(-1)\nelse:\n tmp = ans[0]\n flag = 1\n for i in range(len(ans)):\n if ans[i] != tmp:\n flag = 0\n if not flag:\n print(-1)\n else:\n print(ans[0])", "passed": true, "time": 0.26, "memory": 14608.0, "status": "done"}, {"code": "def rec(i):\n nonlocal a\n return i\nimport sys\nfrom collections import Counter\nsys.setrecursionlimit(10**6)\n#n=int(input())\nn,m=list(map(int,input().split()))\na=[[] for i in range(100)]\nb=[i for i in range(1,101)]\nfor i in range(m):\n x,y=list(map(int,input().split()))\n z=b.copy()\n for i0 in z:\n if not(((x-1)>=(y-1)*i0)and((x-1)<y*i0)):\n b.remove(i0)\n\na=set()\nfor i0 in b:\n a.add((n-1)//i0)\nif len(a)==1:\n print(a.pop()+1)\nelse:\n print(-1)\n", "passed": true, "time": 0.26, "memory": 14376.0, "status": "done"}, {"code": "a,b = list(map(int,input().split()))\nmini = 1\nmaxi = 10000\nfor i in range(b):\n x,y = list(map(int,input().split()))\n if y==1:\n mini = max(mini,x)\n else:\n mx = (x-1)//(y-1) \n mn=(x-1)//y+1\n if mn*y>=x:\n mini = max(mini,mn)\n else:\n mini = max(mini,mn+1)\n if mx*y>=x:\n maxi = min(maxi,mx)\nif (a-1)//maxi==(a-1)//mini:\n print((a-1)//maxi+1)\nelse:\n print(-1)\n", "passed": true, "time": 0.24, "memory": 14396.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\n#memory = [[] * 100 for i in range(100)]\nmemory = []\nfor i in range(m):\n a, b = list(map(int, input().split()))\n memory.append((a, b))\n#memory.sort()\n#count = 0\nans = -1\ngl_flag = 1\nfor flat in range(1, 101):\n flag = 1\n for i in range(m):\n if not (memory[i][0] <= memory[i][1] * flat and memory[i][0] > (memory[i][1] - 1) * flat):\n flag = 0\n break\n if (flag == 1):\n #count += 1\n ans1 = (n - 1) // flat + 1\n if (ans != -1 and ans1 != ans):\n gl_flag = 0\n break\n else:\n ans = ans1 \nif (gl_flag == 0):\n print(-1)\nelse:\n print(ans)\n", "passed": true, "time": 0.16, "memory": 14496.0, "status": "done"}, {"code": "import math\nn,m=map(int,input().split())\nznach=range(1,200)\nfor i in range(m):\n k,f=map(int,input().split())\n if f==1:\n a=range(math.ceil(k/f),200)\n else:\n niz=math.ceil(k/f)\n verh=math.floor((k-1)/(f-1))\n a=range(niz,verh+1)\n znach=list(set(a)&set(znach))\nif len(znach)==1:\n if n%znach[0]==0:\n print(n//znach[0])\n else:\n print(n//znach[0]+1)\nelse:\n a=[]\n for i in range(len(znach)):\n if n%znach[i]==0:\n a.append(n//znach[i])\n else:\n a.append(n//znach[i]+1)\n a=list(set(a))\n if len(a)>1:\n print(-1)\n else:\n print(a[0])", "passed": true, "time": 0.16, "memory": 14600.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nd = []\n\ncount_of_good = 0\ngood_on_level = []\n\nfor i in range(m):\n a, b = list(map(int, input().split()))\n d.append((a, b))\n\nfor on_level in range(1, 101):\n good = True\n for el in d:\n etaj = el[1]\n kv = el[0]\n if not ((etaj - 1) * on_level < kv <= etaj * on_level):\n good = False\n break\n if good:\n count_of_good += 1\n good_on_level.append(on_level)\n\nans = []\n\nfor i in good_on_level:\n if n % i == 0:\n ans.append(n // i)\n else:\n ans.append(n // i + 1)\n\nif len(ans) == 1:\n print(ans[0])\n return\n\nfor i in range(1, len(ans)):\n if ans[i - 1] != ans[i]:\n print('-1')\n return\n\nprint(ans[0])\n", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "n, m = [int(i) for i in input().split()]\nmn = 10 ** 5\nmx = 1\nn -= 1\nfor i in range(m):\n x, y = [int(i) for i in input().split()]\n x -= 1\n y -= 1\n if y != 0:\n mn = min(mn, x // y)\n mx = max(mx, [(x + y) // (y + 1), x // (y + 1) + 1][x % (y + 1) == 0])\na = n // mx\nfor i in range(mx + 1, mn + 1):\n if a != n // i:\n print(-1)\n return\nprint(a + 1)", "passed": true, "time": 0.19, "memory": 14328.0, "status": "done"}, {"code": "m, n = map(int, input().split())\ncanbe = []\nfor i in range(0, n):\n numb, et = map(int, input().split())\n can = []\n for j in range(1, 101):\n if j * et >= numb and j * (et - 1) < numb:\n can += [j]\n canbe += [can]\n can = []\ncanbeat = []\nfor i in range(1, 101):\n est = 0\n for el in canbe:\n if i in el:\n est += 1\n if est == n:\n canbeat += [i]\nans = []\nfor element in canbeat:\n if m % element == 0:\n ans += [m // element]\n else:\n ans += [m // element + 1]\nwrit = ans[0]\ntr = 0\nfor element in ans:\n if element != writ:\n tr = -1\nif tr == -1:\n print(tr)\nelse:\n print(writ)", "passed": true, "time": 0.17, "memory": 14408.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nkv = [None] * 101\nboo = [False] * 101\nfor i in range(m):\n k, j = list(map(int, input().split()))\n kv[k] = j\nfor j in range(1, 101):\n qw = True\n for i in range(len(kv)):\n if kv[i] is not None:\n a = (i - 1) // j + 1\n if kv[i] != a:\n qw = False\n boo[j] = qw\na = sum(boo)\nfirst = 0\nq = set()\nfor i in range(len(boo)):\n if boo[i]:\n q.add((n - 1) // i + 1)\n \n\n\nif len(q) == 1:\n print(q.pop())\nelse:\n print(-1)\n \n \n \n \n", "passed": true, "time": 0.17, "memory": 14344.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\ndata = []\nfl = [0] * 1000000\nan = -1\nf = 0\nfor i in range(m):\n data += [list(map(int, input().split()))]\n fl[data[i][0]] = data[i][1]\n if data[i][0] == n:\n an = data[i][1]\n f = max(data[i][1], f)\n\n\nif an != -1:\n print(an)\n return\ndata.sort()\n\nan = []\nt = True\nfor i in range(m):\n if data[i][0] != data[i][1]:\n t = False\nif t:\n an += [n]\n \nfor k in range(2, 10001):\n #print(k)\n t = True\n for i in range(m):\n f = data[i][0] // k + min(1, data[i][0] % k)\n if data[i][1] != f:\n t = False\n break\n if not t:\n continue\n \n an += [n // k + min(1, n % k)]\n #print(an)\n\nif len(set(an)) == 1:\n print(an[0])\nelse:\n print(-1)\n", "passed": true, "time": 0.95, "memory": 22004.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nv = []\nfor i in range(m):\n v.append(list(map(int, input().split())))\nans = []\nfor i in range(1, 101):\n o = True\n for p in v:\n if (p[0] - 1) // i != p[1] - 1:\n o = False\n break\n if o:\n if not(((n - 1) // i + 1) in ans):\n ans.append(((n - 1) // i + 1))\nif len(ans) == 1:\n print(ans[0])\nelse:\n print(-1)\n", "passed": true, "time": 0.15, "memory": 14376.0, "status": "done"}, {"code": "def first(n, m, line):\n for i in range(0, n): \n k, f = list(map(int, input().split())) \n res = [] \n for j in range(1, 101): \n if j * f >= k and j * (f - 1) < k: \n res.append(j) \n line.append(res) \n res = [] \n return line\n\n\ndef check(n, m, hz):\n for i in range(1, 101): \n dno = 0 \n for elem in line: \n if i in elem: \n dno += 1 \n if dno == n: \n hz.append(i)\n return hz\n\n\nm, n = list(map(int, input().split())) \nline = [] \nline = first(n, m, line)\nhz = [] \nhz = check(n, m, hz)\nans = [] \n\nfor element in hz: \n if m % element == 0: \n ans.append(m // element)\n else: \n ans.append(m // element + 1)\nsmth = ans[0] \nansw = 0 \nfor element in ans: \n if element != smth: \n answ = -1 \nif answ == -1: \n print(answ) \nelse: \n print(smth)\n", "passed": true, "time": 0.17, "memory": 14536.0, "status": "done"}, {"code": "m, n = map(int, input().split())\narr = []\nfor i in range(n):\n a, b = map(int, input().split())\n arr.append((a, b))\nans = set()\nfor k in range(1, 150):\n fl = True\n for i in range(n):\n if ((arr[i][0] - 1) // k + 1) != arr[i][1]:\n fl = False\n break\n if fl: ans.add((m - 1) // k + 1)\nif len(ans) == 1:\n for i in ans:\n print(i)\nelse:\n print(-1)", "passed": true, "time": 0.2, "memory": 14624.0, "status": "done"}, {"code": "k = []\nn, m = list(map(int, input().split(\" \")))\nfor i in range(m):\n\tx, y = list(map(int, input().split(' ')))\n\tk.append([x, y])\n\ndef ok(x):\n\tfor i in k:\n\t\tif (i[0]-1)//x+1!=i[1]:\n\t\t\treturn False\n\treturn True\n\nposs = []\nfor x in range(1, 101):\n\tif ok(x):\n\t\tposs.append((n-1)//x+1)\n\nif len(list(set(poss))) == 1:\n\tprint(poss[0])\nelse:\n\tprint(-1)\n\n\n", "passed": true, "time": 0.14, "memory": 14676.0, "status": "done"}, {"code": "import sys, os\nn, m = map(int, input().split())\nmi = []\nma = []\nif m == 0:\n if n == 1:\n print(1)\n else:\n print(-1)\n return\n return\n os.abort()\nfor i in range(m):\n a, b = map(int, input().split())\n if b == 1:\n ma.append(1000000000)\n mi.append(a)\n if n <= a:\n print(1)\n return\n return\n os.abort()\n else:\n mak = (a - 1) // (b - 1)\n ma.append(mak)\n if a % b == 0:\n mi.append(a // b)\n else:\n mi.append((a // b ) + 1)\n#print(mi, ma)\nmik = min(ma)\nmak = max(mi)\nif n % mik == 0:\n a = n // mik\nelse:\n a = (n // mik) + 1\n\nif n % mak == 0:\n b = n // mak\nelse:\n b = (n // mak) + 1\nif a == b:\n print(b)\nelse:\n print(-1)", "passed": true, "time": 0.15, "memory": 14484.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nl = set()\ns = {i for i in range(1, 101)}\nb = False\nfor i in range(m):\n k, f = map(int, input().split())\n if k == n:\n print(f)\n b = True\n break\n j = 1\n if f == 1:\n l = {i for i in range(k, 101)}\n else:\n while j <= (k-j)//(f-1):\n if (k-j)%(f-1) == 0:\n l.add((k-j)//(f-1))\n j += f-1\n else:\n j += 1\n s &= l\n l.clear()\na = -1\nif b == False:\n t = True\n for j in s:\n if a == -1:\n a = (n-1)//j\n else:\n if (n-1)//j != a:\n print(-1)\n t = False\n break\n if t == True:\n print(a+1)", "passed": true, "time": 0.23, "memory": 14480.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nmin_ = 10000\nmax_ = 0\nfor i in range(m):\n k, f = map(int, input().split())\n if f > 1:\n min_ = min(k / (f - 1), min_)\n max_ = max(k / f, max_)\nmin_, max_ = max_, min_\n\n\nif(min_ != int(min_)):\n min_ +=1\nmin_ = int(min_)\n\nif (max_ != int(max_)):\n max_+=1\nmax_ = int(max_)\n\n#print(min_, max_)\n\ns = set()\nfor i in range(max(1, min_), max_):\n b = n // i\n if (n % i) != 0:\n b+=1\n s.add(b)\nif len(s) == 1:\n print(b)\nelse:\n print(-1)", "passed": true, "time": 0.27, "memory": 14400.0, "status": "done"}, {"code": "n,m=list(map(int,input().split()))\nk=[0]*m\nf=[0]*m\nl=1\nr=100\nfor i in range(m):\n k[i],f[i]=list(map(int,input().split()))\nfor i in range(m):\n fl=True\n for kol in range(l,r+1):\n ch=k[i]-(f[i]-1)*kol\n if ch>0 and ch<=kol:\n if fl:\n l=kol\n fl=False\n elif not fl:\n r=kol-1\n break\n if r-l==0:\n print((n+r-1)//r)\n break\nelse:\n kok=(n+r-1)//r\n for kol in range(l,r):\n if kok!=(n+kol-1)//kol:\n print(-1)\n break\n else:\n print(kok)\n \n", "passed": true, "time": 0.14, "memory": 14576.0, "status": "done"}, {"code": "n, m = map(int, input().split())\n\nl = -100\nr = 100\nfor i in range(m):\n k, f = map(int, input().split())\n l = max(l, (k + f - 1) // f)\n if(f != 1):\n r = min(r, (k - 1) // (f - 1))\n\nif(l == r):\n print((n + r - 1) // r)\nelif ((n + r - 1) // r == (n + l - 1) // l):\n print((n + r - 1) // r)\nelse:\n print(-1)", "passed": true, "time": 0.24, "memory": 14400.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nlist1 = []\nans = set()\nif n == 1:\n print(1)\nelse:\n for i in range(m):\n list1.append(list(map(int, input().split())))\n for i in range(1, 101):\n if len(ans) > 1:\n print(-1)\n break\n for j in range(len(list1)):\n if (list1[j][0] - 1) // i + 1 != list1[j][1]:\n break\n else:\n ans.add((n - 1) // i + 1)\n else:\n if len(ans) == 1:\n print(*list(ans))\n else:\n print(-1)", "passed": true, "time": 0.15, "memory": 14588.0, "status": "done"}, {"code": "import math\n\ndef f(m):\n nonlocal h\n f = True\n for i in range(len(h)):\n for j in h[i]:\n if not(j <= i * m and j > (i - 1) * m ):\n f = False\n return f\n\nn, m = map(int, input().split())\nh = [[] for i in range(110)]\nfor i in range(m):\n a, b = map(int, input().split())\n h[b].append(a)\nk = 0\nans = []\nfor i in range(1, 110):\n if f(i):\n k += 1\n ans.append(i)\nfl = False\nfor i in range(len(h)):\n for j in h[i]:\n if j == n:\n fl = True\n ans1 = i\nif fl:\n print(ans1)\nelif m == 0 and n == 1:\n print(1)\nelif k > 1:\n pr = math.ceil(n / ans[0])\n fl1 = True\n for i in range(1, len(ans)):\n if pr != math.ceil(n / ans[i]):\n fl1 = False\n if not fl1:\n print(-1)\n else:\n print(pr)\nelif k < 1:\n print(-1)\nelse:\n print(math.ceil(n / ans[0]))", "passed": true, "time": 0.19, "memory": 14416.0, "status": "done"}, {"code": "\nn,m=list(map(int,input().split()))\nk=[]\nf=[]\nfor i in range(m):\n u,p=list(map(int,input().split()))\n k.append(u)\n f.append(p)\ndef ok(x):\n for i in range(m):\n if (k[i]-1)//x+1!=f[i]:\n return False\n return True\na=[]\nfor i in range(1,101):\n if(ok(i)):\n a.append((n-1)//i+1)\nif len(list(set(a)))==1:\n print(a[0])\nelse:\n print(-1)\n", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\n\nn = n - 1\net = []\nfor i in range(m):\n et.append(tuple(map(lambda x: int(x) - 1, input().split())))\net.sort()\nres = -1\nif n == 0:\n res = 1\nelif len(et) == 0:\n pass\nelse:\n et = [(-1, 0)] + et\n for i in range(len(et) - 1):\n if et[i][0] <= n <= et[i+1][0] and et[i][1] == et[i+1][1]:\n res = et[i][1] + 1\n break\n et = et[1:]\n if res == -1 and et[-1][1] != 0:\n y = []\n \n for i in range(1, et[-1][0] // et[-1][1] + 1):\n fl = True\n for j in range(len(et)):\n if et[j][0] // i != et[j][1]:\n fl = False\n break\n if fl:\n y.append(i)\n y1 = set([(n // tmp + 1) for tmp in y])\n if len(y1) == 1:\n res = y1.pop()\nprint(res)", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}] | [{"input": "10 3\n6 2\n2 1\n7 3\n", "output": "4\n"}, {"input": "8 4\n3 1\n6 2\n5 2\n2 1\n", "output": "-1\n"}, {"input": "8 3\n7 2\n6 2\n1 1\n", "output": "2\n"}, {"input": "4 2\n8 3\n3 1\n", "output": "2\n"}, {"input": "11 4\n16 4\n11 3\n10 3\n15 4\n", "output": "3\n"}, {"input": "16 6\n3 1\n16 4\n10 3\n9 3\n19 5\n8 2\n", "output": "4\n"}, {"input": "1 0\n", "output": "1\n"}, {"input": "1 1\n1 1\n", "output": "1\n"}, {"input": "1 1\n1 1\n", "output": "1\n"}, {"input": "1 2\n1 1\n2 2\n", "output": "1\n"}, {"input": "2 2\n2 1\n1 1\n", "output": "1\n"}, {"input": "2 0\n", "output": "-1\n"}, {"input": "2 1\n3 3\n", "output": "2\n"}, {"input": "3 2\n1 1\n3 3\n", "output": "3\n"}, {"input": "3 3\n1 1\n3 3\n2 2\n", "output": "3\n"}, {"input": "3 0\n", "output": "-1\n"}, {"input": "1 1\n2 1\n", "output": "1\n"}, {"input": "2 2\n2 1\n1 1\n", "output": "1\n"}, {"input": "2 3\n3 2\n1 1\n2 1\n", "output": "1\n"}, {"input": "3 0\n", "output": "-1\n"}, {"input": "3 1\n1 1\n", "output": "-1\n"}, {"input": "2 2\n1 1\n3 1\n", "output": "1\n"}, {"input": "1 3\n1 1\n2 1\n3 1\n", "output": "1\n"}, {"input": "81 0\n", "output": "-1\n"}, {"input": "22 1\n73 73\n", "output": "22\n"}, {"input": "63 2\n10 10\n64 64\n", "output": "63\n"}, {"input": "88 3\n37 37\n15 15\n12 12\n", "output": "88\n"}, {"input": "29 4\n66 66\n47 47\n62 62\n2 2\n", "output": "29\n"}, {"input": "9 40\n72 72\n47 47\n63 63\n66 66\n21 21\n94 94\n28 28\n45 45\n93 93\n25 25\n100 100\n43 43\n49 49\n9 9\n74 74\n26 26\n42 42\n50 50\n2 2\n92 92\n76 76\n3 3\n78 78\n44 44\n69 69\n36 36\n65 65\n81 81\n13 13\n46 46\n24 24\n96 96\n73 73\n82 82\n68 68\n64 64\n41 41\n31 31\n29 29\n10 10\n", "output": "9\n"}, {"input": "50 70\n3 3\n80 80\n23 23\n11 11\n87 87\n7 7\n63 63\n61 61\n67 67\n53 53\n9 9\n43 43\n55 55\n27 27\n5 5\n1 1\n99 99\n65 65\n37 37\n60 60\n32 32\n38 38\n81 81\n2 2\n34 34\n17 17\n82 82\n26 26\n71 71\n4 4\n16 16\n19 19\n39 39\n51 51\n6 6\n49 49\n64 64\n83 83\n10 10\n56 56\n30 30\n76 76\n90 90\n42 42\n47 47\n91 91\n21 21\n52 52\n40 40\n77 77\n35 35\n88 88\n75 75\n95 95\n28 28\n15 15\n69 69\n22 22\n48 48\n66 66\n31 31\n98 98\n73 73\n25 25\n97 97\n18 18\n13 13\n54 54\n72 72\n29 29\n", "output": "50\n"}, {"input": "6 0\n", "output": "-1\n"}, {"input": "32 1\n9 5\n", "output": "16\n"}, {"input": "73 2\n17 9\n21 11\n", "output": "37\n"}, {"input": "6 3\n48 24\n51 26\n62 31\n", "output": "3\n"}, {"input": "43 4\n82 41\n52 26\n88 44\n41 21\n", "output": "22\n"}, {"input": "28 40\n85 43\n19 10\n71 36\n39 20\n57 29\n6 3\n15 8\n11 6\n99 50\n77 39\n79 40\n31 16\n35 18\n24 12\n54 27\n93 47\n90 45\n72 36\n63 32\n22 11\n83 42\n5 3\n12 6\n56 28\n94 47\n25 13\n41 21\n29 15\n36 18\n23 12\n1 1\n84 42\n55 28\n58 29\n9 5\n68 34\n86 43\n3 2\n48 24\n98 49\n", "output": "14\n"}, {"input": "81 70\n55 28\n85 43\n58 29\n20 10\n4 2\n47 24\n42 21\n28 14\n26 13\n38 19\n9 5\n83 42\n7 4\n72 36\n18 9\n61 31\n41 21\n64 32\n90 45\n46 23\n67 34\n2 1\n6 3\n27 14\n87 44\n39 20\n11 6\n21 11\n35 18\n48 24\n44 22\n3 2\n71 36\n62 31\n34 17\n16 8\n99 50\n57 29\n13 7\n79 40\n100 50\n53 27\n89 45\n36 18\n43 22\n92 46\n98 49\n75 38\n40 20\n97 49\n37 19\n68 34\n30 15\n96 48\n17 9\n12 6\n45 23\n65 33\n76 38\n84 42\n23 12\n91 46\n52 26\n8 4\n32 16\n77 39\n88 44\n86 43\n70 35\n51 26\n", "output": "41\n"}, {"input": "34 0\n", "output": "-1\n"}, {"input": "63 1\n94 24\n", "output": "16\n"}, {"input": "4 2\n38 10\n48 12\n", "output": "1\n"}, {"input": "37 3\n66 17\n89 23\n60 15\n", "output": "10\n"}, {"input": "71 4\n15 4\n13 4\n4 1\n70 18\n", "output": "18\n"}, {"input": "77 40\n49 13\n66 17\n73 19\n15 4\n36 9\n1 1\n41 11\n91 23\n51 13\n46 12\n39 10\n42 11\n56 14\n61 16\n70 18\n92 23\n65 17\n54 14\n97 25\n8 2\n87 22\n33 9\n28 7\n38 10\n50 13\n26 7\n7 2\n31 8\n84 21\n47 12\n27 7\n53 14\n19 5\n93 24\n29 8\n3 1\n77 20\n62 16\n9 3\n44 11\n", "output": "20\n"}, {"input": "18 70\n51 13\n55 14\n12 3\n43 11\n42 11\n95 24\n96 24\n29 8\n65 17\n71 18\n18 5\n62 16\n31 8\n100 25\n4 1\n77 20\n56 14\n24 6\n93 24\n97 25\n79 20\n40 10\n49 13\n86 22\n21 6\n46 12\n6 2\n14 4\n23 6\n20 5\n52 13\n88 22\n39 10\n70 18\n94 24\n13 4\n37 10\n41 11\n91 23\n85 22\n83 21\n89 23\n33 9\n64 16\n67 17\n57 15\n47 12\n36 9\n72 18\n81 21\n76 19\n35 9\n80 20\n34 9\n5 2\n22 6\n84 21\n63 16\n74 19\n90 23\n68 17\n98 25\n87 22\n2 1\n92 23\n50 13\n38 10\n28 7\n8 2\n60 15\n", "output": "5\n"}, {"input": "89 0\n", "output": "-1\n"}, {"input": "30 1\n3 1\n", "output": "-1\n"}, {"input": "63 2\n48 6\n17 3\n", "output": "8\n"}, {"input": "96 3\n45 6\n25 4\n35 5\n", "output": "12\n"}, {"input": "37 4\n2 1\n29 4\n27 4\n47 6\n", "output": "5\n"}, {"input": "64 40\n40 5\n92 12\n23 3\n75 10\n71 9\n2 1\n54 7\n18 3\n9 2\n74 10\n87 11\n11 2\n90 12\n30 4\n48 6\n12 2\n91 12\n60 8\n35 5\n13 2\n53 7\n46 6\n38 5\n59 8\n97 13\n32 4\n6 1\n36 5\n43 6\n83 11\n81 11\n99 13\n69 9\n10 2\n21 3\n78 10\n31 4\n27 4\n57 8\n1 1\n", "output": "8\n"}, {"input": "17 70\n63 8\n26 4\n68 9\n30 4\n61 8\n84 11\n39 5\n53 7\n4 1\n81 11\n50 7\n91 12\n59 8\n90 12\n20 3\n21 3\n83 11\n94 12\n37 5\n8 1\n49 7\n34 5\n19 3\n44 6\n74 10\n2 1\n73 10\n88 11\n43 6\n36 5\n57 8\n64 8\n76 10\n40 5\n71 9\n95 12\n15 2\n41 6\n89 12\n42 6\n96 12\n1 1\n52 7\n38 5\n45 6\n78 10\n82 11\n16 2\n48 6\n51 7\n56 7\n28 4\n87 11\n93 12\n46 6\n29 4\n97 13\n54 7\n35 5\n3 1\n79 10\n99 13\n13 2\n55 7\n100 13\n11 2\n75 10\n24 3\n33 5\n22 3\n", "output": "3\n"}, {"input": "9 0\n", "output": "-1\n"}, {"input": "50 1\n31 2\n", "output": "-1\n"}, {"input": "79 2\n11 1\n22 2\n", "output": "-1\n"}, {"input": "16 3\n100 7\n94 6\n3 1\n", "output": "1\n"}, {"input": "58 4\n73 5\n52 4\n69 5\n3 1\n", "output": "4\n"}, {"input": "25 40\n70 5\n28 2\n60 4\n54 4\n33 3\n21 2\n51 4\n20 2\n44 3\n79 5\n65 5\n1 1\n52 4\n23 2\n38 3\n92 6\n63 4\n3 1\n91 6\n5 1\n64 4\n34 3\n25 2\n97 7\n89 6\n61 4\n71 5\n88 6\n29 2\n56 4\n45 3\n6 1\n53 4\n57 4\n90 6\n76 5\n8 1\n46 3\n73 5\n87 6\n", "output": "2\n"}, {"input": "78 70\n89 6\n52 4\n87 6\n99 7\n3 1\n25 2\n46 3\n78 5\n35 3\n68 5\n85 6\n23 2\n60 4\n88 6\n17 2\n8 1\n15 1\n67 5\n95 6\n59 4\n94 6\n31 2\n4 1\n16 1\n10 1\n97 7\n42 3\n2 1\n24 2\n34 3\n37 3\n70 5\n18 2\n41 3\n48 3\n58 4\n20 2\n38 3\n72 5\n50 4\n49 4\n40 3\n61 4\n6 1\n45 3\n28 2\n13 1\n27 2\n96 6\n56 4\n91 6\n77 5\n12 1\n11 1\n53 4\n76 5\n74 5\n82 6\n55 4\n80 5\n14 1\n44 3\n7 1\n83 6\n79 5\n92 6\n66 5\n36 3\n73 5\n100 7\n", "output": "5\n"}, {"input": "95 0\n", "output": "-1\n"}, {"input": "33 1\n30 1\n", "output": "-1\n"}, {"input": "62 2\n14 1\n15 1\n", "output": "-1\n"}, {"input": "3 3\n6 1\n25 1\n38 2\n", "output": "1\n"}, {"input": "44 4\n72 3\n80 3\n15 1\n36 2\n", "output": "2\n"}, {"input": "34 40\n25 1\n28 1\n78 3\n5 1\n13 1\n75 3\n15 1\n67 3\n57 2\n23 1\n26 1\n61 2\n22 1\n48 2\n85 3\n24 1\n82 3\n83 3\n53 2\n38 2\n19 1\n33 2\n69 3\n17 1\n79 3\n54 2\n77 3\n97 4\n20 1\n35 2\n14 1\n18 1\n71 3\n21 1\n36 2\n56 2\n44 2\n63 2\n72 3\n32 1\n", "output": "2\n"}, {"input": "83 70\n79 3\n49 2\n2 1\n44 2\n38 2\n77 3\n86 3\n31 1\n83 3\n82 3\n35 2\n7 1\n78 3\n23 1\n39 2\n58 2\n1 1\n87 3\n72 3\n20 1\n48 2\n14 1\n13 1\n6 1\n70 3\n55 2\n52 2\n25 1\n11 1\n61 2\n76 3\n95 3\n32 1\n66 3\n29 1\n9 1\n5 1\n3 1\n88 3\n59 2\n96 3\n10 1\n63 2\n40 2\n42 2\n34 2\n43 2\n19 1\n89 3\n94 3\n24 1\n98 4\n12 1\n30 1\n69 3\n17 1\n50 2\n8 1\n93 3\n16 1\n97 4\n54 2\n71 3\n18 1\n33 2\n80 3\n15 1\n99 4\n75 3\n4 1\n", "output": "3\n"}, {"input": "2 0\n", "output": "-1\n"}, {"input": "36 1\n96 1\n", "output": "1\n"}, {"input": "73 2\n34 1\n4 1\n", "output": "-1\n"}, {"input": "6 3\n37 1\n22 1\n70 1\n", "output": "1\n"}, {"input": "47 4\n66 1\n57 1\n85 1\n47 1\n", "output": "1\n"}, {"input": "9 40\n73 1\n21 1\n37 1\n87 1\n33 1\n69 1\n49 1\n19 1\n35 1\n93 1\n71 1\n43 1\n79 1\n85 1\n29 1\n72 1\n76 1\n47 1\n17 1\n67 1\n95 1\n41 1\n54 1\n88 1\n42 1\n80 1\n98 1\n96 1\n10 1\n24 1\n78 1\n18 1\n3 1\n91 1\n2 1\n15 1\n5 1\n60 1\n36 1\n46 1\n", "output": "1\n"}, {"input": "63 70\n82 1\n53 1\n57 1\n46 1\n97 1\n19 1\n36 1\n90 1\n23 1\n88 1\n68 1\n45 1\n2 1\n70 1\n86 1\n8 1\n83 1\n40 1\n99 1\n42 1\n32 1\n52 1\n81 1\n50 1\n77 1\n37 1\n54 1\n75 1\n4 1\n49 1\n73 1\n22 1\n21 1\n98 1\n18 1\n51 1\n14 1\n76 1\n92 1\n80 1\n78 1\n33 1\n79 1\n89 1\n67 1\n9 1\n44 1\n60 1\n64 1\n55 1\n29 1\n100 1\n16 1\n87 1\n10 1\n12 1\n25 1\n85 1\n30 1\n63 1\n39 1\n38 1\n31 1\n5 1\n26 1\n91 1\n43 1\n72 1\n48 1\n94 1\n", "output": "1\n"}, {"input": "2 0\n", "output": "-1\n"}] |
|
215 | Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s consisting only of lowercase and uppercase Latin letters.
Let A be a set of positions in the string. Let's call it pretty if following conditions are met: letters on positions from A in the string are all distinct and lowercase; there are no uppercase letters in the string which are situated between positions from A (i.e. there is no such j that s[j] is an uppercase letter, and a_1 < j < a_2 for some a_1 and a_2 from A).
Write a program that will determine the maximum number of elements in a pretty set of positions.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 200) — length of string s.
The second line contains a string s consisting of lowercase and uppercase Latin letters.
-----Output-----
Print maximum number of elements in pretty set of positions for string s.
-----Examples-----
Input
11
aaaaBaabAbA
Output
2
Input
12
zACaAbbaazzC
Output
3
Input
3
ABC
Output
0
-----Note-----
In the first example the desired positions might be 6 and 8 or 7 and 8. Positions 6 and 7 contain letters 'a', position 8 contains letter 'b'. The pair of positions 1 and 8 is not suitable because there is an uppercase letter 'B' between these position.
In the second example desired positions can be 7, 8 and 11. There are other ways to choose pretty set consisting of three elements.
In the third example the given string s does not contain any lowercase letters, so the answer is 0. | interview | [{"code": "def list_input():\n return list(map(int,input().split()))\ndef map_input():\n return map(int,input().split())\ndef map_string():\n return input().split()\n \nn = int(input()) \na = list(input())\nans = 0\nfor i in range(n):\n\tfor j in range(i,n):\n\t\tb = a[i:j+1]\n\t\tfor k in b:\n\t\t\tif k.lower() != k:\n\t\t\t\tbreak\n\t\telse:\n\t\t\tb = set(b)\n\t\t\tans = max(ans,len(b))\nprint(ans)\t\t\t\t\t", "passed": true, "time": 0.78, "memory": 14264.0, "status": "done"}, {"code": "n = int(input())\n\ns = input()\n\nans = 0\nss = set()\n\nfor c in s:\n\tif c.isupper():\n\t\tans = max(ans, len(ss))\n\t\tss = set()\n\telse:\n\t\tss.add(c)\nans = max(ans, len(ss))\nprint(ans)", "passed": true, "time": 0.17, "memory": 14360.0, "status": "done"}, {"code": "n = int(input())\nb = input()\na = ['']\nfor i in b:\n if ord('A') <= ord(i) <= ord('Z'):\n a.append('')\n else:\n a[-1] = a[-1] + i\na = [len(set(list(i))) for i in a]\nprint(max(a))", "passed": true, "time": 0.17, "memory": 14336.0, "status": "done"}, {"code": "n = int(input())\n\nans = 0\nl = []\n\nfor c in input():\n if c.islower():\n l.append(c)\n else:\n ans = max(ans, len(set(l)))\n l = []\n\nans = max(ans, len(set(l)))\nprint(ans)\n", "passed": true, "time": 0.25, "memory": 14344.0, "status": "done"}, {"code": "n = int(input())\ns= input()\nimport string\nsm = string.ascii_lowercase\nb = string.ascii_uppercase\nans = 0\nh = set()\nfor i in range(len(s)):\n if s[i] in sm:\n h.add(s[i])\n ans = max(ans, len(h))\n else:\n h = set()\nprint(ans)", "passed": true, "time": 0.15, "memory": 14456.0, "status": "done"}, {"code": "n=input()\ns=input()\nz=''\nfor c in s:\n\tif ord(c)>=ord('a') and ord(c)<=ord('z'):\n\t\tz+=c\n\telse:\n\t\tz+=' '\nz=z.split(' ')\nalp=range(26)\nres=0\nfor w in z:\n\tkek=26\n\tfor x in alp:\n\t\tif w.find(chr(ord('a')+x))==-1:\n\t\t\tkek-=1\n\tres=max(res,kek)\nprint(res)", "passed": true, "time": 0.17, "memory": 14432.0, "status": "done"}, {"code": "from sys import stdin, stdout\nimport string\n\nn = int(stdin.readline().rstrip())\ns = list(stdin.readline().rstrip())\n\nlset = str(string.ascii_lowercase)\nuset = str(string.ascii_uppercase)\n\ncurrentSet = set()\nmaxSize = 0\nfor letter in s:\n if letter in uset:\n currentSet = set()\n else:\n currentSet.add(letter)\n maxSize = max(maxSize,len(currentSet))\n \nprint(maxSize)\n", "passed": true, "time": 0.16, "memory": 14468.0, "status": "done"}, {"code": "import re\nn=int(input())\ns=input()\nans=0\nfor c in re.split('[A-Z]',s):\n\tif len(c)>0:\n\t\tans=max(ans,len(set(c)))\n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14352.0, "status": "done"}, {"code": "def bitLenCount(x):\n length = 0\n count = 0\n while (x):\n count += (x & 1)\n length += 1\n x >>= 1\n return count\n\nn = input()\ns = input()\nmsk = 0\nans = 0\nfor i in s:\n\tx = ord(i) - ord('a')\n\t\n\tif x >= 0 and x <= 25:\n\t\tmsk |= (1 << x)\n\telse:\n\t\tmsk = 0\n\tans = max(ans, bitLenCount(msk))\n\t\nprint(ans)", "passed": true, "time": 0.16, "memory": 14328.0, "status": "done"}, {"code": "import re\nn = int(input())\nS = input().strip()\ns = re.split(r'[A-Z]+', S)\nm = 0\nfor ss in s:\n x = set(ss)\n m = max(m, len(x))\nprint(m)", "passed": true, "time": 0.16, "memory": 14432.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nans = 0\nnow_ans = 0\nlower = []\n\nfor el in s:\n if el.islower():\n if el not in lower:\n lower.append(el)\n now_ans += 1\n else:\n if now_ans > ans:\n ans = now_ans\n lower = []\n now_ans = 0\n\nif now_ans > ans:\n ans = now_ans\n\nprint(ans)", "passed": true, "time": 0.16, "memory": 14552.0, "status": "done"}, {"code": "input()\n\nll = list(input())\n\ndd = {}\n\n\ndef is_up(s):\n return s.lower() != s\n\n\ndef is_lo(s):\n return s.lower() == s\n\n\nma = 0\n\n\nfor i in range(len(ll)):\n if is_up(ll[i]):\n dd = {}\n else:\n c = ll[i]\n if c not in dd:\n dd[c] = 1\n ma = max(len(dd), ma)\n\nma = max(len(dd), ma)\n\nprint(ma)\n", "passed": true, "time": 0.14, "memory": 14460.0, "status": "done"}, {"code": "import re\nn=int(input())\ns=input()\na=re.split('[A-Z]+',s)\nans=0\nfor i in a:\n\tans=max(ans,len(set(i)))\nprint(ans)", "passed": true, "time": 0.25, "memory": 14348.0, "status": "done"}, {"code": "n = int(input())\ns = input()\na = [set()]\nk = 0\nfor i in range(len(s)):\n if s[i].upper() == s[i] and a[-1] != set():\n k += 1\n a.append(set())\n else:\n if s[i].lower() == s[i] and s[i] not in a[-1]:\n a[-1].add(s[i])\nprint(max([len(x) for x in a]))\n", "passed": true, "time": 0.26, "memory": 14496.0, "status": "done"}, {"code": "input()\ns = input()\narr = []\ntemp = ''\nfor x in s:\n\tif(ord(x) <= ord('Z')):\n\t\tif(temp != ''):\n\t\t\tarr.append(temp)\n\t\t\ttemp = ''\n\telse:\n\t\ttemp += x\nif(temp != ''):\n\tarr.append(temp)\n\nans = 0\nfor y in arr:\n\tans = max(ans, len(set(list(y))))\nprint(ans)", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "n = int(input())\ns = str(input())\n\nres = [[]]\n\nfor i in s:\n\tif ord(i) >= ord('A') and (ord(i)) <= ord('Z'):\n\t\tres.append([])\n\telse:\n\t\tres[-1].append(i)\n\nmx = 0\n\nfor i in res:\n\tmx = max(mx, len(set(i)))\n\nprint(mx)", "passed": true, "time": 0.14, "memory": 14316.0, "status": "done"}, {"code": "import re\n\nn = int(input())\ns = input()\nprint(max([len(set(x)) for x in re.split('[A-Z]', s)]))\n", "passed": true, "time": 0.15, "memory": 14424.0, "status": "done"}, {"code": "def solve():\n\n n = int(input())\n sentence = input()\n\n alpha = \"abcdefghijklmnopqrstuvwxyz\"\n alp = [[]]\n \n for st in sentence:\n if st in alpha:\n if st not in alp[-1]:\n alp[-1].append(st)\n else:\n alp.append([])\n\n #print(alp)\n return max([len(e) for e in alp])\n\nprint(solve())\n", "passed": true, "time": 0.16, "memory": 14292.0, "status": "done"}, {"code": "import re\nn = int(input())\ns = input()\nans = 0\nss = re.split(r'[A-Z]+', s)\nprint(max(list(map(len, list(map(set, ss))))))\n\n\"\"\"\n11\naaaaBAAAVDAaabAbA\n\"\"\"\n", "passed": true, "time": 0.14, "memory": 14512.0, "status": "done"}, {"code": "size = int(input())\nn = input()\n\nrez = []\nans = 0\nyet = 0\n\nfor i in n:\n if ord(i) > 96 and i not in rez:\n rez.append(i)\n yet += 1\n elif ord(i) < 96:\n rez = []\n yet = 0\n ans = max(ans,yet)\n\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14568.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\n\"\"\"\n\"\"\"\n\n# import {{{\nfrom collections import ChainMap\nfrom collections import Counter\nfrom collections import defaultdict\nfrom collections import deque\nfrom collections import namedtuple\nimport bisect\nimport copy\nimport decimal\nimport fractions\nimport functools\nimport heapq\nimport itertools\nimport math\nimport operator\nimport pprint\nimport random\nimport re\nimport sys\nimport time\n\ntry:\n import numpy as np\n import scipy as sp\nexcept:\n pass\n# }}}\n\n# util {{{\ndef is_odd(x):\n return x % 2 == 1\n\ndef is_even(x):\n return x % 2 == 0\n\ndef cmp(x, y):\n return (x > y) - (x < y)\n\ndef sgn(x):\n return cmp(x, 0)\n\ndef clamp(x, lo, hi):\n assert lo <= hi\n if x < lo:\n return lo\n elif x > hi:\n return hi\n else:\n return x\n\ndef chmax(xmax, x):\n if x > xmax:\n return x, True\n else:\n return xmax, False\n\ndef chmin(xmin, x):\n if x < xmin:\n return x, True\n else:\n return xmin, False\n\nsys.setrecursionlimit(100000)\n# }}}\n\n# \u9069\u5b9c\u8abf\u6574\nPINF = float(\"inf\")\nNINF = float(\"-inf\")\nEPS = 1e-9\n\n\n\ndef main():\n N = int(input())\n S = input()\n\n sets = []\n\n s = set()\n for c in S:\n if c.isupper():\n if s:\n sets.append(s)\n s = set()\n else:\n s.add(c)\n if s:\n sets.append(s)\n\n ans = len(max(sets, key=len)) if sets else 0\n print(ans)\n\ndef __starting_point(): main()\n\n__starting_point()", "passed": true, "time": 0.17, "memory": 14552.0, "status": "done"}, {"code": "n=int(input())\ns=str(input())\nl=[0]\nfor i in range(len(s)):\n if ord(s[i])>=65 and ord(s[i])<=90:\n l.append(i)\nans=0\nl.append(n)\nfor i in range(len(l)-1):\n ls=[]\n for j in range(l[i],l[i+1]):\n if s[j] not in ls and (ord(s[j])>=97 and ord(s[j])<=122):\n ls.append(s[j])\n ans=max(ans,len(ls))\n #print(ls)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14568.0, "status": "done"}, {"code": "# O(nlogn)\ndef main():\n n = int(input())\n s = input()\n \n low_chars = set()\n max_power = 0\n for c in s:\n if c.isupper():\n max_power = max(max_power, len(low_chars))\n low_chars = set()\n else:\n low_chars.add(c)\n \n if len(low_chars) > 0:\n max_power = max(max_power, len(low_chars))\n \n print(max_power)\n \nmain()\n", "passed": true, "time": 0.14, "memory": 14516.0, "status": "done"}, {"code": "_ = int(input())\ns = input()\nchars = set()\nmaxval = 0\nfor c in s:\n if c.isupper():\n maxval = max(maxval, len(chars))\n chars = set()\n else:\n chars.add(c)\nmaxval = max(maxval, len(chars))\n\nprint(maxval)", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}, {"code": "input()\ns=input()\nx=set()\na=0\nl=len(s)\nfor i in range(0,l):\n for j in range(i,l):\n ss=s[i:j+1]\n if any(chr(i) in ss for i in range(65, 91)):\n continue\n a=max(a,len(set(ss)))\nprint(a)", "passed": true, "time": 1.61, "memory": 14416.0, "status": "done"}] | [{"input": "11\naaaaBaabAbA\n", "output": "2\n"}, {"input": "12\nzACaAbbaazzC\n", "output": "3\n"}, {"input": "3\nABC\n", "output": "0\n"}, {"input": "1\na\n", "output": "1\n"}, {"input": "2\naz\n", "output": "2\n"}, {"input": "200\nXbTJZqcbpYuZQEoUrbxlPXAPCtVLrRExpQzxzqzcqsqzsiisswqitswzCtJQxOavicSdBIodideVRKHPojCNHmbnrLgwJlwOpyrJJIhrUePszxSjJGeUgTtOfewPQnPVWhZAtogRPrJLwyShNQaeNsvrJwjuuBOMPCeSckBMISQzGngfOmeyfDObncyeNsihYVtQbSEh\n", "output": "8\n"}, {"input": "2\nAZ\n", "output": "0\n"}, {"input": "28\nAabcBabcCBNMaaaaabbbbbcccccc\n", "output": "3\n"}, {"input": "200\nrsgraosldglhdoorwhkrsehjpuxrjuwgeanjgezhekprzarelduuaxdnspzjuooguuwnzkowkuhzduakdrzpnslauejhrrkalwpurpuuswdgeadlhjwzjgegwpknepazwwleulppwrlgrgedlwdzuodzropsrrkxusjnuzshdkjrxxpgzanzdrpnggdwxarpwohxdepJ\n", "output": "17\n"}, {"input": "1\nk\n", "output": "1\n"}, {"input": "1\nH\n", "output": "0\n"}, {"input": "2\nzG\n", "output": "1\n"}, {"input": "2\ngg\n", "output": "1\n"}, {"input": "2\nai\n", "output": "2\n"}, {"input": "20\npEjVrKWLIFCZjIHgggVU\n", "output": "1\n"}, {"input": "20\niFSiiigiYFSKmDnMGcgM\n", "output": "2\n"}, {"input": "20\nedxedxxxCQiIVmYEUtLi\n", "output": "3\n"}, {"input": "20\nprnchweyabjvzkoqiltm\n", "output": "20\n"}, {"input": "35\nQLDZNKFXKVSVLUVHRTDPQYMSTDXBELXBOTS\n", "output": "0\n"}, {"input": "35\nbvZWiitgxodztelnYUyljYGnCoWluXTvBLp\n", "output": "10\n"}, {"input": "35\nBTexnaeplecllxwlanarpcollawHLVMHIIF\n", "output": "10\n"}, {"input": "35\nhhwxqysolegsthsvfcqiryenbujbrrScobu\n", "output": "20\n"}, {"input": "26\npbgfqosklxjuzmdheyvawrictn\n", "output": "26\n"}, {"input": "100\nchMRWwymTDuZDZuSTvUmmuxvSscnTasyjlwwodhzcoifeahnbmcifyeobbydwparebduoLDCgHlOsPtVRbYGGQXfnkdvrWKIwCRl\n", "output": "20\n"}, {"input": "100\nhXYLXKUMBrGkjqQJTGbGWAfmztqqapdbjbhcualhypgnaieKXmhzGMnqXVlcPesskfaEVgvWQTTShRRnEtFahWDyuBzySMpugxCM\n", "output": "19\n"}, {"input": "100\nucOgELrgjMrFOgtHzqgvUgtHngKJxdMFKBjfcCppciqmGZXXoiSZibgpadshyljqrwxbomzeutvnhTLGVckZUmyiFPLlwuLBFito\n", "output": "23\n"}, {"input": "200\nWTCKAKLVGXSYFVMVJDUYERXNMVNTGWXUGRFCGMYXJQGLODYZTUIDENHYEGFKXFIEUILAMESAXAWZXVCZPJPEYUXBITHMTZOTMKWITGRSFHODKVJHPAHVVWTCTHIVAWAREQXWMPUWQSTPPJFHKGKELBTPUYDAVIUMGASPUEDIODRYXIWCORHOSLIBLOZUNJPHHMXEXOAY\n", "output": "0\n"}, {"input": "200\neLCCuYMPPwQoNlCpPOtKWJaQJmWfHeZCKiMSpILHSKjFOYGpRMzMCfMXdDuQdBGNsCNrHIVJzEFfBZcNMwNcFjOFVJvEtUQmLbFNKVHgNDyFkFVQhUTUQDgXhMjJZgFSSiHhMKuTgZQYJqAqKBpHoHddddddddddddddddXSSYNKNnRrKuOjAVKZlRLzCjExPdHaDHBT\n", "output": "1\n"}, {"input": "200\nitSYxgOLlwOoAkkkkkzzzzzzzzkzkzkzkkkkkzkzzkzUDJSKybRPBvaIDsNuWImPJvrHkKiMeYukWmtHtgZSyQsgYanZvXNbKXBlFLSUcqRnGWSriAvKxsTkDJfROqaKdzXhvJsPEDATueCraWOGEvRDWjPwXuiNpWsEnCuhDcKWOQxjBkdBqmFatWFkgKsbZuLtRGtY\n", "output": "2\n"}, {"input": "200\noggqoqqogoqoggggoggqgooqggogogooogqqgggoqgggqoqogogggogggqgooqgqggqqqoqgqgoooqgqogqoggoqqgqoqgoooqoogooqoogqoqoqqgoqgoqgggogqqqoqoggoqoqqoqggqoggooqqqoqggoggqqqqqqqqqgogqgggggooogogqgggqogqgoqoqogoooq\n", "output": "3\n"}, {"input": "200\nCtclUtUnmqFniaLqGRmMoUMeLyFfAgWxIZxdrBarcRQprSOGcdUYsmDbooSuOvBLgrYlgaIjJtFgcxJKHGkCXpYfVKmUbouuIqGstFrrwJzYQqjjqqppqqqqqpqqqjpjjpjqjXRYkfPhGAatOigFuItkKxkjCBLdiNMVGjmdWNMgOOvmaJEdGsWNoaERrINNKqKeQajv\n", "output": "3\n"}, {"input": "200\nmeZNrhqtSTSmktGQnnNOTcnyAMTKSixxKQKiagrMqRYBqgbRlsbJhvtNeHVUuMCyZLCnsIixRYrYEAkfQOxSVqXkrPqeCZQksInzRsRKBgvIqlGVPxPQnypknSXjgMjsjElcqGsaJRbegJVAKtWcHoOnzHqzhoKReqBBsOhZYLaYJhmqOMQsizdCsQfjUDHcTtHoeYwu\n", "output": "4\n"}, {"input": "200\neTtezDHXMMBtFUaohwuYdRVloYwZLiaboJTMWLImSCrDTDFpAYJsQBzdwkEvcoYfWmKZfqZwfGHigaEpwAVoVPDSkDJsRzjjdyAcqfVIUcwiJuHyTisFCCNHIFyfDWOyMMRtTWmQFCRNtmwMTzQSZdOFfojwvAtxTrSgaDLzzBwDkxPoCYuSxpwRbnhfsERywPyUlJBC\n", "output": "5\n"}, {"input": "200\nvFAYTHJLZaivWzSYmiuDBDUFACDSVbkImnVaXBpCgrbgmTfXKJfoglIkZxWPSeVSFPnHZDNUAqLyhjLXSuAqGLskBlDxjxGPJyGdwzlPfIekwsblIrkxzfhJeNoHywdfAGlJzqXOfQaKceSqViVFTRJEGfACnsFeSFpOYisIHJciqTMNAmgeXeublTvfWoPnddtvKIyF\n", "output": "6\n"}, {"input": "200\ngnDdkqJjYvduVYDSsswZDvoCouyaYZTfhmpSakERWLhufZtthWsfbQdTGwhKYjEcrqWBOyxBbiFhdLlIjChLOPiOpYmcrJgDtXsJfmHtLrabyGKOfHQRukEtTzwoqBHfmyVXPebfcpGQacLkGWFwerszjdHpTBXGssYXmGHlcCBgBXyGJqxbVhvDffLyCrZnxonABEXV\n", "output": "7\n"}, {"input": "200\nBmggKNRZBXPtJqlJaXLdKKQLDJvXpDuQGupiRQfDwCJCJvAlDDGpPZNOvXkrdKOFOEFBVfrsZjWyHPoKGzXmTAyPJGEmxCyCXpeAdTwbrMtWLmlmGNqxvuxmqpmtpuhrmxxtrquSLFYVlnSYgRJDYHWgHBbziBLZRwCIJNvbtsEdLLxmTbnjkoqSPAuzEeTYLlmejOUH\n", "output": "9\n"}, {"input": "200\nMkuxcDWdcnqsrlTsejehQKrTwoOBRCUAywqSnZkDLRmVBDVoOqdZHbrInQQyeRFAjiYYmHGrBbWgWstCPfLPRdNVDXBdqFJsGQfSXbufsiogybEhKDlWfPazIuhpONwGzZWaQNwVnmhTqWdewaklgjwaumXYDGwjSeEcYXjkVtLiYSWULEnTFukIlWQGWsXwWRMJGTcI\n", "output": "10\n"}, {"input": "200\nOgMBgYeuMJdjPtLybvwmGDrQEOhliaabEtwulzNEjsfnaznXUMoBbbxkLEwSQzcLrlJdjJCLGVNBxorghPxTYCoqniySJMcilpsqpBAbqdzqRUDVaYOgqGhGrxlIJkyYgkOdTUgRZwpgIkeZFXojLXpDilzirHVVadiHaMrxhzodzpdvhvrzdzxbhmhdpxqqpoDegfFQ\n", "output": "11\n"}, {"input": "200\nOLaJOtwultZLiZPSYAVGIbYvbIuZkqFZXwfsqpsavCDmBMStAuUFLBVknWDXNzmiuUYIsUMGxtoadWlPYPqvqSvpYdOiJRxFzGGnnmstniltvitnrmyrblnqyruylummmlsqtqitlbulvtuitiqimuintbimqyurviuntqnnvslynlNYMpYVKYwKVTbIUVdlNGrcFZON\n", "output": "12\n"}, {"input": "200\nzdqzfjWCocqbUbVYaLrBFEwoQiMdlVssRjIctSenAIqPgPJhjPyvvgRFlplFXKTctqFUPlVyMxEfZDfFbUjOMCYFkrFeoZegnSzuKrbWQqcJWfeFauSqYeSCdiPiWroksbkdskrasekytdvnygetyabnteaybdZAoBntIxZJTTsTblLAosqwHQEXTSqjEQqzNGRgdaVG\n", "output": "13\n"}, {"input": "200\nGqxrcpJdPhHQUhCwJAOhrKsIttEjqYjygzoyvslFXvybQiWHjViWlOrHvMlDzWaiurjYKsmlrwqAhjZPHZaFMWFlgFJYntZLgPzuksawCmWOHFyANczsdkkusKLQOOHiJsJDvzsVRaUNWLKMRTbmoLwFOJxakhxsenjkzzucpothHNpNtMMfLdmiFyblVUmeIBdpFYIQ\n", "output": "14\n"}, {"input": "200\nGAcmlaqfjSAQLvXlkhxujXgSbxdFAwnoxDuldDvYmpUhTWJdcEQSdARLrozJzIgFVCkzPUztWIpaGfiKeqzoXinEjVuoKqyBHmtFjBWcRdBmyjviNlGAIkpikjAimmBgayfphrstfbjexjbttzfzfzaysxfyrjazfhtpghnbbeffjhxrjxpttesgzrnrfbgzzsRsCgmz\n", "output": "15\n"}, {"input": "200\neybfkeyfccebifebaukyeraeuxaeprnibicxknepxurnlrbuyuykexbiycpnbbafxnpbrkctpkteetrfptiyaceoylnclytirfkcxboeyufplnbtbikireyulxfaknppuicnabixrnpoicexcaelttlllttfboniebinulkoxuilpnnkrpectutnctoykpPJsflVwmDo\n", "output": "16\n"}, {"input": "200\nfEyHTWhrGQezPcvGDrqJEnPVQRxiaGPbWoPVYGMlGIWuAAWdFzIiRTEjsyivewudtzuiuhulqywpzmdopjykvtkjzlyhhzspmovwHtiMtZYkYBozzkGfGmrizjuQYVaewYqglzMAkQSZERgWPYVxfoGLzNbWAJZutTuGxeBzRIdKAKVPbqlTJVqiKnpFbTWawutdSjux\n", "output": "18\n"}, {"input": "200\nutxfRatSRtHcDvHfsBBCwsUFcAmrFxHfbMjWhAjfdoQkNfQWfgQEeBVZJavMlpmptFHJGxBFaHfxLAGcZJsUukXLBMfwWlqnnQxKtgnQDqtiJBnoAnxxFBlPJJnuWkdOzYGBRMwSSrjDAVZqYhtopxDVrBAJsIODCUadfEDDzeyroijgwqhaucmnstclNRVxoTYzMSlK\n", "output": "19\n"}, {"input": "200\nYRvIopNqSTYDhViTqCLMwEbTTIdHkoeuBmAJWhgtOgVxlcHSsavDNzMfpwTghkBvYEtCYQxicLUxdgAcaCzOOgbQYsfnaTXFlFxbeEiGwdNvxwHzkTdKtWlqzalwniDDBDipkxfflpaqkfkgfezbkxdvzemlfohwtgytzzywmwhvzUgPlPdeAVqTPAUZbogQheRXetvT\n", "output": "20\n"}, {"input": "200\nPUVgmHVAXlBaxUIthvGXCVOuIcukqODzMYigUBAZNJcJoayfRXVFfLgKmHdtevsEjoexdSwqvtAeoiyqjnBKoyKduwPCBNEDdkTpjlOOdOlJIEWovEGoDzwhtITNpVamnXVSxPmZTbuhnEbtebgqYEXFbyagmztkxmcgshnxqrowthegiepvLLUIbBalXAJAbGplWMbt\n", "output": "21\n"}, {"input": "200\nPQNfMSHpPaOhjCpYPkOgzCpgOhgsmyaTHrlxgogmhdficyeszcbujjrxeihgrzszsjehsupezxlpcpsemesxcwwwllhisjpnepdoefpdzfptdrmETROYtOUjiUsPwrNkUfmeTFgSIJMjTuCFBgfkTQEYJijBaPnaVltQJhKufDKrdMAFnBflaekZErAuKkGhGMLLOEzZ\n", "output": "22\n"}, {"input": "200\nBmrFQLXLcKnPBEdQVHVplsEIsrxSlfEbbYXjMrouIwHSyfqjxoerueuanalzliouwllrhzfytmgtfoxeuhjfaaabwjdlimcluabajcoxwgqjotcjdftwqbxhwjnbwoeillzbftzynhfyyqiuszjreujwyhdrdhyyxsglgdjbtghlqutjstmsaowcqchzbdzoeqIqbQUY\n", "output": "23\n"}, {"input": "200\nZlJwrzzglgkjqtmoseaapqtqxbrorjptpejjmchztutkglqjxxqgnuxeadxksnclizglywqmtxdhrbbmooxijiymikyIOlSBShUOGUghPJtSxmToNUHDdQIMoFzPOVYAtLRtXyuOErmpYQFAeKMJKlqZCEVEuhSCCtBnQnOncTqYpaLbhutwhplyJGxtuXQiEfuvOzWr\n", "output": "24\n"}, {"input": "200\nNcYVomemswLCUqVRSDKHCknlBmqeSWhVyRzQrnZaOANnTGqsRFMjpczllcEVebqpxdavzppvztxsnfmtcharzqlginndyjkawzurqkxJLXiXKNZTIIxhSQghDpjwzatEqnLMTLxwoEKpHytvWkKFDUcZjLShCiVdocxRvvJtbXHCDGpJvMwRKWLhcTFtswdLUHkbhfau\n", "output": "25\n"}, {"input": "200\nDxNZuvkTkQEqdWIkLzcKAwfqvZQiptnTazydSCTIfGjDhLMrlPZiKEsqIdDhgKPAlEvXyzNwWtYorotgkcwydpabjqnzubaksdchucxtkmjzfretdmvlxgklyvicrtftvztsbiUaQorfNIYUOdwQDRsKpxLUiLknbLbinilpPXPTTwLAnXVpMHBaAcKWgDBeOFabPtXU\n", "output": "26\n"}, {"input": "4\nabbc\n", "output": "3\n"}, {"input": "3\naaa\n", "output": "1\n"}, {"input": "3\naba\n", "output": "2\n"}, {"input": "3\nabb\n", "output": "2\n"}, {"input": "3\nbba\n", "output": "2\n"}, {"input": "3\nAaa\n", "output": "1\n"}, {"input": "3\nAba\n", "output": "2\n"}, {"input": "3\naBa\n", "output": "1\n"}, {"input": "3\naAa\n", "output": "1\n"}, {"input": "3\naAb\n", "output": "1\n"}, {"input": "3\naaA\n", "output": "1\n"}, {"input": "3\naaB\n", "output": "1\n"}, {"input": "3\nabA\n", "output": "2\n"}, {"input": "3\nbbA\n", "output": "1\n"}, {"input": "3\nAaA\n", "output": "1\n"}, {"input": "3\nBaB\n", "output": "1\n"}, {"input": "3\nAAB\n", "output": "0\n"}, {"input": "3\nZZZ\n", "output": "0\n"}, {"input": "5\naBacd\n", "output": "3\n"}, {"input": "5\naAabc\n", "output": "3\n"}] |
|
216 | You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences.
Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a.
The second line contains n integers a_1, a_2, ..., a_{n} ( - 100 ≤ a_{i} ≤ 100) — the elements of sequence a.
-----Output-----
Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.
-----Examples-----
Input
3
1 -2 0
Output
3
Input
6
16 23 16 15 42 8
Output
120
-----Note-----
In the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C = - 2, B - C = 3.
In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120. | interview | [{"code": "\nn=int(input())\narr= list(map(int,input().strip().split(' ')))\ns = 0\nfor i in range(n):\n s+=abs(arr[i])\nprint(s)", "passed": true, "time": 0.22, "memory": 14320.0, "status": "done"}, {"code": "n = int(input())\na = [int(v) for v in input().split()]\n\nprint(sum(abs(v) for v in a))\n", "passed": true, "time": 0.58, "memory": 14452.0, "status": "done"}, {"code": "n = int(input())\narr = list(map(int, input().split()))\nb = c = 0\nfor val in arr:\n if val >= 0:\n b += val\n else:\n c += val\nprint(b - c)", "passed": true, "time": 0.16, "memory": 14384.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nans = 0\nfor i in a:\n ans += abs(i)\n\nprint(ans)\n", "passed": true, "time": 1.13, "memory": 14308.0, "status": "done"}, {"code": "n = int(input())\na = [int(i) for i in input().split()]\nb = [i for i in a if i >= 0]\nc = [i for i in a if i < 0]\nprint(sum(b) - sum(c))", "passed": true, "time": 0.26, "memory": 14536.0, "status": "done"}, {"code": "n = int(input())\nA = list(map(int, input().split()))\nB = [abs(a) for a in A]\nprint(sum(B))", "passed": true, "time": 0.17, "memory": 14300.0, "status": "done"}, {"code": "input()\na=list(map(int,input().split()))\nprint(sum(x for x in a if x > 0)-sum([x for x in a if x<0]))\n", "passed": true, "time": 0.26, "memory": 14344.0, "status": "done"}, {"code": "n = int(input())\nv = [int(x) for x in input().split()]\nans = 0\nfor x in v:\n\tans += x if x > 0 else -x\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\n\nb = []\nc = []\nfor k in a:\n if k> 0:\n b.append(k)\n else:\n c.append(k)\n\nprint(sum(b)-sum(c))", "passed": true, "time": 0.18, "memory": 14456.0, "status": "done"}, {"code": "n = int(input())\nL = list(map(int, input().split()))\nL = list(map(abs, L))\nprint(sum(L))\n", "passed": true, "time": 0.24, "memory": 14576.0, "status": "done"}, {"code": "\nn = int(input())\na = list(map(int,input().split()))\nt = min(a)\nif t<0:\n\tp = 0\n\tn = 0\n\tfor i in a:\n\t\tif i>0:\n\t\t\tp+=i\n\t\telse:\n\t\t\tn+=i\n\tprint (p-n)\nelse:\n\tprint (sum(a))", "passed": true, "time": 0.14, "memory": 14512.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nb = [i for i in a if i < 0]\nprint(sum(a) - 2 * sum(b))\n", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "R=lambda:map(int,input().split())\n\nn = int(input())\n\na = list(R())\n\ns = 0 \n\nfor i in range(n):\n if a[i] >= 0:\n s += a[i]\n else: s -= a[i]\n \nprint(s)", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nb=[i for i in a if i > 0]\nc=[i for i in a if i <= 0]\nsb = 0\nsc = 0\nif len(b) > 0:\n sb = sum(b)\nif len(c) > 0:\n sc = sum(c)\nprint(sb-sc)\n", "passed": true, "time": 0.16, "memory": 14352.0, "status": "done"}, {"code": "n = int(input())\n\nlst = []\nfor x in input().split():\n lst.append(int(x))\n\nsum_1 = 0\nsum_2 = 0\nfor x in lst:\n if x >= 0:\n sum_1 += x\n else:\n sum_2 += x\n\nprint(sum_1 - sum_2)\n", "passed": true, "time": 0.24, "memory": 14360.0, "status": "done"}, {"code": "input()\nprint(sum(map(abs, map(int, input().split()))))", "passed": true, "time": 0.14, "memory": 14500.0, "status": "done"}, {"code": "def read():\n return list(map(int,input().split()))\nn=int(input())\na=read()\nB=0\nC=0\nfor i in a:\n if i>0:\n B+=i\n else:\n C+=i\nprint(B-C)\n", "passed": true, "time": 0.15, "memory": 14548.0, "status": "done"}, {"code": "n=int(input())\na=[int(x) for x in input().split()]\nb=0\nc=0\nfor i in range(len(a)):\n if a[i]<0:\n c+=a[i]*(-1)\n elif a[i]>=0:\n b+=a[i]\nans=b+c\nprint(ans)\n", "passed": true, "time": 0.17, "memory": 14308.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nnum = 0\nfor i in range(n):\n if a[i] < 0:\n num += -1 * a[i]\n else:\n num += a[i]\n\nprint(num)", "passed": true, "time": 0.15, "memory": 14332.0, "status": "done"}, {"code": "n=int(input())\na=[int(x) for x in input().split()]\nb=[]\nc=[]\nfor i in a:\n\tif i>=0:\n\t\tb.append(i)\n\telse:\n\t\tc.append(i)\nprint(sum(b)-sum(c))", "passed": true, "time": 0.14, "memory": 14508.0, "status": "done"}, {"code": "n = int(input())\na= list(map(int,input().split()))\nfor i in range(len(a)):\n a[i] = abs(a[i])\nprint(sum(a))", "passed": true, "time": 0.17, "memory": 14484.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int,input().split(\" \")))\n\nsumv = 0\nfor i in range(n):\n\tif a[i] < 0:\n\t\tsumv -= a[i]\n\telse:\n\t\tsumv += a[i]\n\nprint(sumv)", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}, {"code": "n = int(input())\nseq = list(map(int, input().split(' ')))\n\ntot = 0\nfor x in seq:\n if x < 0:\n tot += - x\n else:\n tot += x\n\nprint(tot)\n", "passed": true, "time": 0.16, "memory": 14356.0, "status": "done"}, {"code": "def solve():\n n = int(input())\n A = list(map(int, input().split()))\n\n res = 0\n for a in A:\n if a >= 0:\n res += a\n else:\n res -= a\n\n print(res)\n\n\ndef __starting_point():\n solve()\n\n\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14484.0, "status": "done"}] | [{"input": "3\n1 -2 0\n", "output": "3\n"}, {"input": "6\n16 23 16 15 42 8\n", "output": "120\n"}, {"input": "1\n-1\n", "output": "1\n"}, {"input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100\n", "output": "10000\n"}, {"input": "2\n-1 5\n", "output": "6\n"}, {"input": "3\n-2 0 1\n", "output": "3\n"}, {"input": "12\n-1 -2 -3 4 4 -6 -6 56 3 3 -3 3\n", "output": "94\n"}, {"input": "4\n1 -1 1 -1\n", "output": "4\n"}, {"input": "4\n100 -100 100 -100\n", "output": "400\n"}, {"input": "3\n-2 -5 10\n", "output": "17\n"}, {"input": "5\n1 -2 3 -4 5\n", "output": "15\n"}, {"input": "3\n-100 100 -100\n", "output": "300\n"}, {"input": "6\n1 -1 1 -1 1 -1\n", "output": "6\n"}, {"input": "6\n2 -2 2 -2 2 -2\n", "output": "12\n"}, {"input": "9\n12 93 -2 0 0 0 3 -3 -9\n", "output": "122\n"}, {"input": "6\n-1 2 4 -5 -3 55\n", "output": "70\n"}, {"input": "6\n-12 8 68 -53 1 -15\n", "output": "157\n"}, {"input": "2\n-2 1\n", "output": "3\n"}, {"input": "3\n100 -100 100\n", "output": "300\n"}, {"input": "5\n100 100 -1 -100 2\n", "output": "303\n"}, {"input": "6\n-5 -4 -3 -2 -1 0\n", "output": "15\n"}, {"input": "6\n4 4 4 -3 -3 2\n", "output": "20\n"}, {"input": "2\n-1 2\n", "output": "3\n"}, {"input": "1\n100\n", "output": "100\n"}, {"input": "5\n-1 -2 3 1 2\n", "output": "9\n"}, {"input": "5\n100 -100 100 -100 100\n", "output": "500\n"}, {"input": "5\n1 -1 1 -1 1\n", "output": "5\n"}, {"input": "4\n0 0 0 -1\n", "output": "1\n"}, {"input": "5\n100 -100 -1 2 100\n", "output": "303\n"}, {"input": "2\n75 0\n", "output": "75\n"}, {"input": "4\n55 56 -59 -58\n", "output": "228\n"}, {"input": "2\n9 71\n", "output": "80\n"}, {"input": "2\n9 70\n", "output": "79\n"}, {"input": "2\n9 69\n", "output": "78\n"}, {"input": "2\n100 -100\n", "output": "200\n"}, {"input": "4\n-9 4 -9 5\n", "output": "27\n"}, {"input": "42\n91 -27 -79 -56 80 -93 -23 10 80 94 61 -89 -64 81 34 99 31 -32 -69 92 79 -9 73 66 -8 64 99 99 58 -19 -40 21 1 -33 93 -23 -62 27 55 41 57 36\n", "output": "2348\n"}, {"input": "7\n-1 2 2 2 -1 2 -1\n", "output": "11\n"}, {"input": "6\n-12 8 17 -69 7 -88\n", "output": "201\n"}, {"input": "3\n1 -2 5\n", "output": "8\n"}, {"input": "6\n-2 3 -4 5 6 -1\n", "output": "21\n"}, {"input": "2\n-5 1\n", "output": "6\n"}, {"input": "4\n2 2 -2 4\n", "output": "10\n"}, {"input": "68\n21 47 -75 -25 64 83 83 -21 89 24 43 44 -35 34 -42 92 -96 -52 -66 64 14 -87 25 -61 -78 83 -96 -18 95 83 -93 -28 75 49 87 65 -93 -69 -2 95 -24 -36 -61 -71 88 -53 -93 -51 -81 -65 -53 -46 -56 6 65 58 19 100 57 61 -53 44 -58 48 -8 80 -88 72\n", "output": "3991\n"}, {"input": "5\n5 5 -10 -1 1\n", "output": "22\n"}, {"input": "3\n-1 2 3\n", "output": "6\n"}, {"input": "76\n57 -38 -48 -81 93 -32 96 55 -44 2 38 -46 42 64 71 -73 95 31 -39 -62 -1 75 -17 57 28 52 12 -11 82 -84 59 -86 73 -97 34 97 -57 -85 -6 39 -5 -54 95 24 -44 35 -18 9 91 7 -22 -61 -80 54 -40 74 -90 15 -97 66 -52 -49 -24 65 21 -93 -29 -24 -4 -1 76 -93 7 -55 -53 1\n", "output": "3787\n"}, {"input": "5\n-1 -2 1 2 3\n", "output": "9\n"}, {"input": "4\n2 2 -2 -2\n", "output": "8\n"}, {"input": "6\n100 -100 100 -100 100 -100\n", "output": "600\n"}, {"input": "100\n-59 -33 34 0 69 24 -22 58 62 -36 5 45 -19 -73 61 -9 95 42 -73 -64 91 -96 2 53 -8 82 -79 16 18 -5 -53 26 71 38 -31 12 -33 -1 -65 -6 3 -89 22 33 -27 -36 41 11 -47 -32 47 -56 -38 57 -63 -41 23 41 29 78 16 -65 90 -58 -12 6 -60 42 -36 -52 -54 -95 -10 29 70 50 -94 1 93 48 -71 -77 -16 54 56 -60 66 76 31 8 44 -61 -74 23 37 38 18 -18 29 41\n", "output": "4362\n"}, {"input": "2\n-1 1\n", "output": "2\n"}, {"input": "3\n1 -2 100\n", "output": "103\n"}, {"input": "5\n1 -2 3 1 2\n", "output": "9\n"}, {"input": "10\n100 -10 -100 10 10 10 10 10 10 10\n", "output": "280\n"}, {"input": "4\n2 0 -2 4\n", "output": "8\n"}, {"input": "4\n3 -3 1 -1\n", "output": "8\n"}, {"input": "3\n1 -1 1\n", "output": "3\n"}, {"input": "4\n2 5 -2 4\n", "output": "13\n"}, {"input": "2\n-2 2\n", "output": "4\n"}, {"input": "3\n1 -2 1\n", "output": "4\n"}, {"input": "5\n-1 -2 1 1 -1\n", "output": "6\n"}, {"input": "4\n-2 0 2 4\n", "output": "8\n"}, {"input": "8\n-42 7 87 -16 -5 65 -88 1\n", "output": "311\n"}, {"input": "3\n1 -3 4\n", "output": "8\n"}, {"input": "1\n1\n", "output": "1\n"}, {"input": "2\n0 1\n", "output": "1\n"}, {"input": "3\n-1 2 -1\n", "output": "4\n"}, {"input": "18\n-21 12 65 66 -24 62 82 35 -45 -47 28 37 5 -32 22 -14 -69 -95\n", "output": "761\n"}, {"input": "4\n-1 1 -1 1\n", "output": "4\n"}, {"input": "5\n-1 2 1 1 1\n", "output": "6\n"}, {"input": "3\n1 1 1\n", "output": "3\n"}] |
|
217 | A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys.
The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank.
There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline.
What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0.
-----Input-----
The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys.
-----Output-----
Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1.
-----Examples-----
Input
6 9 2 4
Output
4
Input
6 10 2 4
Output
2
Input
6 5 4 3
Output
-1
-----Note-----
In the first example the bus needs to refuel during each journey.
In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty.
In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling. | interview | [{"code": "def list_input():\n return list(map(int,input().split()))\ndef map_input():\n return map(int,input().split())\ndef map_string():\n return input().split()\n \na,b,f,k = map_input()\ntot = a*k\ns = 2*a-f\ncur = 0\ncnt = b\ngo = 0\nans = 0\nwhile cur < tot:\n\tgo = 1-go\n\tif(go == 1):\n\t\tif cnt < s and cnt < tot-cur:\n\t\t\tif(cnt < f):\n\t\t\t\tprint(-1)\n\t\t\t\tbreak\n\t\t\tcnt = b\n\t\t\tans += 1\n\t\t\tcnt -= (a-f)\n\t\telse: cnt -= a\t\n\telse:\n\t\tif cnt < a+f and cnt < tot-cur:\n\t\t\tif(cnt < a-f):\n\t\t\t\tprint(-1)\n\t\t\t\tbreak\n\t\t\tcnt = b\n\t\t\tans += 1\n\t\t\tcnt -= (f)\n\t\telse:cnt -= a\t\n\tcur += a\n\t# print(cur,cnt,ans)\t\n\tif(cnt < 0):\n\t\tprint(-1)\n\t\tbreak\nelse:\n\tprint(ans)", "passed": true, "time": 0.17, "memory": 14612.0, "status": "done"}, {"code": "a, b, f, k = [int(i) for i in input().split()]\n\nff = [0]\n\nfor i in range(k):\n d = f\n if i % 2 == 1:\n d = a - f\n ff.append(i * a + d)\n\nff.append(k * a)\n\nstops = 0\n\nwhile len(ff) > 0:\n next = 0\n if ff[0] == k * a:\n break\n while ff[next + 1] - ff[0] <= b:\n next += 1\n if ff[next] == k * a:\n break\n if next == 0:\n print(\"-1\")\n return\n if ff[next] != k * a:\n stops += 1\n while next > 0:\n ff.pop(0)\n next -= 1\n else:\n break\n\nprint(stops)\n", "passed": true, "time": 0.43, "memory": 14344.0, "status": "done"}, {"code": "a, b, f, k = map(int, input().split())\n\nx = 0\ng = b\nfor kk in range(k-1):\n #print(g)\n if kk%2==0:\n d = a + (a-f)\n if g < d:\n if g < f:\n x = -1\n break\n x += 1\n g = b - (a-f)\n if g < 0:\n x = -1\n break\n else:\n g -= a\n else:\n d = a + f\n if g < d:\n if g < a-f:\n x = -1\n break\n x += 1\n g = b - f\n if g < 0:\n x = -1\n break\n else:\n g -= a\n\nif (k-1)%2==0:\n if g < a:\n if g < f:\n x = -1\n else:\n x += 1\n g = b - (a-f)\n if g < 0:\n x = -1\nelse:\n if g < a:\n if g < a-f:\n x = -1\n else:\n x += 1\n g = b - f\n if g < 0:\n x = -1\n\nprint(x)", "passed": true, "time": 0.31, "memory": 14528.0, "status": "done"}, {"code": "a, b, f, k = list(map(int, input().split()))\nans = 0\nc = b\nif b < f:\n ans = -1\nelse:\n c -= f\nfor i in range(k):\n if ans == -1:\n break\n if i % 2 == 0:\n d = a - f\n else:\n d = f\n if i < k - 1:\n d *= 2\n if b < d:\n ans = -1\n elif c < d:\n ans += 1\n c = b\n c -= d\n\nprint(ans)\n", "passed": true, "time": 0.3, "memory": 14372.0, "status": "done"}, {"code": "a, b, f, k = list(map(int, input().split()))\nrefill = b\nbusPos = 0\ncounter =0 \n\nshouldPrint = True\nwhile True:\n # Move to f\n busPos += f\n b -= f\n\n if b < 0:\n print(-1)\n shouldPrint = False\n break\n \n if (2 if k > 1 else 1) * (a - f) > b:\n b = refill\n counter += 1\n\n # Move to a\n busPos += (a - f)\n b -= (a - f)\n\n if b < 0:\n print(-1)\n shouldPrint = False\n break\n \n k -= 1\n if k == 0:\n break\n\n # Move back to f\n busPos -= (a - f)\n b -= (a - f)\n\n if b < 0:\n print(-1)\n shouldPrint = False\n break\n \n if (2 if k > 1 else 1) * f > b:\n b = refill\n counter += 1\n\n # Move back to start\n busPos -= f\n b -= f\n\n if b < 0:\n print(-1)\n shouldPrint = False\n break\n \n k -= 1\n if k == 0:\n break\n\nif shouldPrint:\n print(counter)\n\n", "passed": true, "time": 0.18, "memory": 14356.0, "status": "done"}, {"code": "a, b, f, k = map(int, input().split())\n\nif (f > b or a - f > b) or (k > 1 and 2 * (a - f) > b) or (k > 2 and 2 * f > b):\n\tprint(-1)\n\treturn\ncur = b\nans = 0\nfor i in range(k):\n\tif i & 1 == 0:\n\t\tif cur < f:\n\t\t\tcur = b - f\n\t\t\tans += 1\n\t\tif cur >= a:\n\t\t\tcur -= a\n\t\telse:\n\t\t\tans += 1\n\t\t\tcur = b - a + f\n\telse:\n\t\tif cur < a - f:\n\t\t\tcur = b - a + f\n\t\t\tans += 1\n\t\tif cur >= a:\n\t\t\tcur -= a\n\t\telse:\n\t\t\tans += 1\n\t\t\tcur = b - f\nprint(ans)", "passed": true, "time": 0.31, "memory": 14492.0, "status": "done"}, {"code": "a, b, f, k = list(map(int, input().split()))\nnow = b\npath = 0\nans = 0\nfor i in range(k):\n if path == 0:\n if i == k - 1 and now >= a:\n break\n now -= f\n if now < 0:\n print(-1)\n return\n if 2 * (a - f) <= now:\n now -= a - f\n else:\n ans += 1\n now = b - (a - f)\n path = 1\n elif path == 1:\n if i == k - 1 and now >= a:\n break\n now -= a - f\n if now < 0:\n print(-1)\n return\n if 2 * f <= now:\n now -= f\n else:\n ans += 1\n now = b - f\n path = 0\nif now < 0:\n print(-1)\n return\nprint(ans)\n", "passed": true, "time": 0.26, "memory": 14516.0, "status": "done"}, {"code": "from sys import stdin, stdout\n\na,b,f,k = list(map(int,stdin.readline().rstrip().split()))\n\n\ndirection = 1\ntank = b\nrefuels=0\nposition=0\nif b<f or b<(a-f):\n possible=False\nelse:\n possible = True\nwhile k>0 and possible==True:\n if k==1 and tank>=a:\n k=0\n elif k==1:\n k=0\n refuels+=1\n elif position==0:\n position = f\n tank-=f\n direction=1\n elif position==a:\n position = f\n tank-=(a-f)\n direction=-1\n elif direction==1:\n if tank<2*(a-f):\n tank=b\n refuels+=1\n if b<2*(a-f):\n possible=False\n else:\n position = a\n direction = -1\n tank -= (a-f)\n k-=1\n elif direction==-1:\n if tank<2*f:\n refuels+=1\n tank=b\n if b<2*f:\n possible=False\n else:\n position = 0\n direction = 1\n tank -= f\n k-=1\nif not possible:\n print(-1)\nelse:\n print(refuels)\n \n", "passed": true, "time": 0.2, "memory": 14500.0, "status": "done"}, {"code": "b, max_fuel, f, k = map(int, input().split())\n\nnow_fuel = max_fuel\nans = 0\n\npart_1 = f\npart_2 = b - f\n\nnow_fuel -= part_1\nif now_fuel < 0:\n print('-1')\n return\n\nwhile k != 0:\n if k > 1:\n if now_fuel < part_2 * 2:\n ans += 1\n now_fuel = max_fuel\n now_fuel -= part_2 * 2\n k -= 1\n if now_fuel < 0:\n print('-1')\n return\n else:\n if now_fuel < part_2:\n ans += 1\n now_fuel = max_fuel\n now_fuel -= part_2\n k -= 1\n if now_fuel < 0:\n print('-1')\n return\n break\n\n if k > 1:\n if now_fuel < part_1 * 2:\n ans += 1\n now_fuel = max_fuel\n now_fuel -= part_1 * 2\n k -= 1\n if now_fuel < 0:\n print('-1')\n return\n else:\n if now_fuel < part_1:\n ans += 1\n now_fuel = max_fuel\n now_fuel -= part_1\n k -= 1\n if now_fuel < 0:\n print('-1')\n return\n break\n\nprint(ans)", "passed": true, "time": 0.29, "memory": 14568.0, "status": "done"}, {"code": "a,b,f,k=[int(i) for i in input().split()]\nif (k>=3):\n if (f>b or 2*f > b or 2*(a-f) > b):\n print (-1)\n else:\n fuel=0\n fwd=1\n rem= b-f\n while (k!=1):\n if (fwd==1):\n if (rem >= 2*(a-f)):\n rem= rem- 2*(a-f)\n else:\n rem= b - 2*(a-f)\n fuel+=1\n k-=1\n fwd=0\n else:\n if (rem>= 2*f):\n rem= rem -2*f\n else:\n rem= b-2*f\n fuel+=1\n k-=1\n fwd=1\n if (fwd==1):\n if (rem>= (a-f)):\n print (fuel)\n else:\n print (fuel+1)\n else:\n if (rem>= f):\n print (fuel)\n else:\n print (fuel+1)\nelif (k==1):\n if (f>b or (a-f)>b):\n print (-1)\n else:\n if (b>=a):\n print (0)\n else:\n print (1)\nelse:\n if (f>b or 2*(a-f) >b):\n print (-1)\n else:\n fuel=0\n rem=b-f\n if (rem < 2*(a-f)):\n rem = b- 2*(a-f)\n fuel+=1\n else:\n rem=rem- 2*(a-f)\n if (rem>=f):\n print (fuel)\n else:\n print (fuel+1)", "passed": true, "time": 0.16, "memory": 14476.0, "status": "done"}, {"code": "a,b,f,k = map(int,input().split())\nim = False\nfuel = b\ncnt = 0\nfor i in range(k):\n\tif(i%2 == 0):\n\t\tif(fuel - f < 0):\n\t\t\tim = True\n\t\t\tbreak\n\t\tif(i < k-1):\n\t\t\tif(fuel - (2*a-f) < 0):\n\t\t\t\tcnt += 1\n\t\t\t\tfuel = b - (a-f)\n\t\t\telse:\n\t\t\t\tfuel -= a\n\t\telse:\n\t\t\tif(fuel - a < 0):\n\t\t\t\tcnt += 1\n\t\t\t\tfuel = b - (a-f)\n\t\t\telse:\n\t\t\t\tfuel -= a\n\telse:\n\t\tif(fuel - (a-f) < 0):\n\t\t\tim = True\n\t\t\tbreak\n\t\tif(i < k-1):\n\t\t\tif(fuel - (a+f) < 0):\n\t\t\t\tcnt += 1\n\t\t\t\tfuel = b - f\n\t\t\telse:\n\t\t\t\tfuel -= a\n\t\telse:\n\t\t\tif(fuel - a < 0):\n\t\t\t\tcnt += 1\n\t\t\t\tfuel = b - f\n\t\t\telse:\n\t\t\t\tfuel -= a\n\tif(fuel < 0):\n\t\tim = True\n\t\tbreak\n\nprint(-1 if im else cnt)", "passed": true, "time": 1.04, "memory": 14476.0, "status": "done"}, {"code": "#python3\n# utf-8\n\na, b, f, k = (int(x) for x in input().split())\nz = 0\n\ncurr_petrol = b\ncurr_races_made = 0\nans = 0\nz___f = f - z\nf___a = a - f\nif k == 1:\n if z___f > b or f___a > b:\n print(-1)\n return\nelif k == 2:\n if 2 * f___a > b:\n print(-1)\n return\nelse:\n if 2 * z___f > b or 2 * f___a > b:\n print(-1)\n return\n\n#direction, races_made, petrol\ncurr_save = None\nroute = [z___f, f___a, f___a, z___f]\n\nwhile curr_races_made < 2 * k:\n curr_pos = curr_races_made % 4\n curr_petrol -= route[curr_pos]\n curr_races_made += 1\n if curr_petrol < 0:\n curr_petrol = b\n ans += 1\n curr_races_made = curr_save\n continue\n if curr_pos == 0 or curr_pos == 2:\n curr_save = curr_races_made\n\nprint(ans)\n", "passed": true, "time": 0.23, "memory": 14372.0, "status": "done"}, {"code": "a,b,f,k = map(int, input().split())\n\nans = 0\ncb = b\nfor i in range(k):\n if i % 2 == 0:\n if f > cb:\n print(-1)\n return\n else:\n cb -= f\n if i != k-1:\n if cb < 2*(a-f):\n ans += 1\n cb = b\n cb -= a-f\n else:\n if cb < a-f:\n ans += 1\n cb = b\n cb -= a-f\n if cb < 0:\n print(-1)\n return\n else:\n if a-f > cb:\n print(-1)\n return\n else:\n cb -= a-f\n if i != k-1:\n if cb < 2*f:\n ans += 1\n cb = b\n cb -= f\n else:\n if cb < f:\n ans += 1\n cb = b\n cb -= f\n if cb < 0:\n print(-1)\n return\nprint(ans) ", "passed": true, "time": 0.2, "memory": 14612.0, "status": "done"}, {"code": "a,b,f,k=list(map(int,input().split()))\nfuel=b-f\nc,d=0,[(a-f)<<1,(f)<<1]\nflag=1\nfor i in range(k):\n if fuel<0:\n flag=0\n break\n dis=d[i&1]*(1 if i!=k-1 else 0.5)\n if fuel<dis:\n fuel=b\n c+=1\n fuel-=dis\nif fuel<0:\n flag=0\nprint(c if flag else \"-1\")\n\n", "passed": true, "time": 0.18, "memory": 14496.0, "status": "done"}, {"code": "def main():\n A, B, F, K = list(map(int, input().split()))\n\n gas = B\n refuel = 0\n i = 1\n while i <= K:\n if i % 2:\n gas -= F\n if gas >= 0:\n if K - i > 0 and gas < (A - F) * 2 or \\\n K - i == 0 and gas < A - F:\n gas = B\n refuel += 1\n gas -= A - F\n else:\n gas -= A - F\n if gas >= 0:\n if K - i > 0 and gas < F * 2 or \\\n K - i == 0 and gas < F:\n gas = B\n refuel += 1\n gas -= F\n if gas < 0:\n print(-1)\n return\n i += 1\n\n print(refuel)\n\nmain()\n", "passed": true, "time": 0.19, "memory": 14428.0, "status": "done"}, {"code": "def main():\n a, b, f, k = list(map(int, input().split()))\n fuels = 0\n trips = 0\n pos = 0\n move = 1\n gas = b\n\n while trips < k:\n if gas < 0:\n print(-1)\n return\n if move == 1:\n if pos == 0:\n pos = f\n gas -= f\n elif pos == f:\n needed_gas = (a - f) if trips == k - 1 else 2 * (a - f)\n if gas < needed_gas:\n gas = b\n fuels += 1\n gas -= (a - f)\n pos = a\n elif pos == a:\n trips += 1\n if trips == k:\n break\n move = -1\n elif move == -1:\n if pos == 0:\n trips += 1\n if trips == k:\n break\n move = 1\n elif pos == f:\n needed_gas = f if trips == k - 1 else 2 * f\n if gas < needed_gas:\n gas = b\n fuels += 1\n pos = 0\n gas -= f\n elif pos == a:\n pos = f\n gas -= (a - f)\n\n print(fuels)\n\nmain()\n", "passed": true, "time": 0.2, "memory": 14408.0, "status": "done"}, {"code": "a, b, f, k = list(map(int, input().split()))\n# if 2*f > b or 2*(a - f) > b:\n# print(-1)\n# return\nfuel_count = 0\nfuel = b\ni = 0\nfuel -= f\nif fuel < 0:\n print(-1)\n return\nwhile True:\n if fuel >= a - f and i + 1 == k:\n break\n if b >= a - f and i + 1 == k:\n fuel_count += 1\n break\n elif fuel < 2*(a - f):\n fuel = b\n fuel_count += 1\n if fuel < 2*(a - f):\n print(-1)\n return\n fuel -= 2*(a - f)\n i += 1\n if i == k:\n break\n if fuel >= f and i + 1 == k:\n break\n if b >= f and i + 1 == k:\n fuel_count += 1\n break\n elif fuel < 2*f:\n fuel = b\n fuel_count += 1\n if fuel < 2*f:\n print(-1)\n return\n fuel -= 2*f\n i += 1\n if i == k:\n break\nprint(fuel_count)\n\n", "passed": true, "time": 0.19, "memory": 14500.0, "status": "done"}, {"code": "a,b,f,k = [int(i) for i in input().split(\" \")]\n#p = 0\nx = f\ny = a - f\noil = b\nresult = 0\nalert = 0\n\n\n\nif k == 1:\n oil -= x\n if oil < 0:\n alert = 1\n if oil < y:\n result += 1\n oil = b\n oil -= y\n if oil < 0:\n alert = 1\nelse:\n oil -= x\n if oil < 0:\n alert = 1\n if oil < 2*y:\n result += 1\n oil = b\n\n if k == 2:\n oil -= 2*y\n if oil < 0:\n alert = 1\n if oil < x:\n result += 1\n oil = b\n else:\n oil -= 2 * y\n if oil < 0:\n alert = 1\n if oil < 2*x:\n result += 1\n oil = b\n\nif k > 2:\n k -= 2\n for ii in range(int((k-1)/2)):\n oil -= 2*x\n if oil < 0:\n alert = 1\n\n if oil < 2*y:\n oil = b\n result += 1\n k -= 1\n oil -= 2*y\n if oil < 0:\n alert = 1\n if oil < 2*x:\n oil = b\n result += 1\n k -= 1\n if k == 1:\n oil -= 2 * x\n if oil < 0:\n alert = 1\n if oil < y:\n oil = b\n result += 1\n if k == 2:\n oil -= 2 * x\n if oil < 0:\n alert = 1\n if oil < 2 * y:\n oil = b\n result += 1\n oil -= 2 * y\n if oil < x:\n oil = b\n result += 1\nif alert == 1:\n print(-1)\nelse:\n print(result)", "passed": true, "time": 0.2, "memory": 14428.0, "status": "done"}, {"code": "a, b, f, k = [int(i) for i in input().split()]\n\nff = [0]\n\nfor i in range(k):\n d = f\n if i % 2 == 1:\n d = a - f\n ff.append(i * a + d)\n\nff.append(k * a)\n\nstops = 0\n\nwhile len(ff) > 0:\n next = 0\n if ff[0] == k * a:\n break\n while ff[next + 1] - ff[0] <= b:\n next += 1\n if ff[next] == k * a:\n break\n if next == 0:\n print(\"-1\")\n return\n if ff[next] != k * a:\n stops += 1\n while next > 0:\n ff.pop(0)\n next -= 1\n else:\n break\nprint(stops)", "passed": true, "time": 0.28, "memory": 14376.0, "status": "done"}, {"code": "a, b, f, k = [int(i) for i in input().split()]\n\n##tank = b\n##journeys = 0\n##refuels = 0\n##current = 0\n##while(journeys != k):\n## print(\"current = %d, tank = %d, refuels = %d, journeys = %d\" % (current, tank, refuels, journeys))\n## if (tank // a >= k):\n## print(refuels)\n## return\n \n## if current == 0:\n## if tank >= a + (a-f):\n## tank -= a\n## elif tank >= f and b >= a-f:\n## refuels += 1\n## tank = b-(a-f)\n## else:\n## break\n## \n## current = a\n## \n## elif current == a:\n## if tank >= a + f:\n## tank -= a\n## elif tank >= a-f and b >= f:\n## refuels += 1\n## tank = b-f\n## else:\n## break\n## \n## current = 0\n##\n## journeys += 1\n\nif b < f:\n print(-1)\n return\n\njourneys = 0\nprevious = 0\nrefuels1 = 0\ntank = b-f\nwhile(journeys != k): ## necessary? while(True) ?\n if previous == 0:\n if tank >= a-f + a*(k-journeys-1):\n print(refuels1)\n return\n if b >= a-f + a*(k-journeys-1):\n print(refuels1+1)\n return\n if tank >= 2*(a-f):\n tank -= 2*(a-f)\n elif b >= 2*(a-f):\n refuels1 += 1\n tank = b - 2*(a-f)\n else:\n print(-1)\n return\n \n journeys += 1\n previous = a\n \n if previous == a:\n if tank >= f + a*(k-journeys-1):\n print(refuels1)\n return\n if b >= f + a*(k-journeys-1):\n print(refuels1+1)\n return\n if tank >= 2*f:\n tank -= 2*f\n elif b >= 2*f:\n refuels1 += 1\n tank = b-2*f\n else:\n print(-1)\n return\n \n journeys += 1\n previous = 0\n\nif journeys == k:\n print(refuels1)\nelse:\n print(-1)\n\n##journeys = 0\n##previous = 0\n##refuels2 = 1\n##tank = b\n##cant2 = False\n##while(journeys != k):\n## if previous == 0:\n## if tank >= a-f + a*(k-journeys-1):\n## break\n## if tank >= 2*(a-f):\n## tank -= 2*(a-f)\n## elif b >= 2*(a-f):\n## refuels2 += 1\n## tank = b - 2*(a-f)\n## else:\n## cant2 = True\n## break\n## \n## journeys += 1\n## previous = a\n## \n## if previous == a:\n## if tank >= f + a*(k-journeys-1):\n## break\n## if tank >= 2*f:\n## tank -= 2*f\n## elif b >= 2*f:\n## refuels2 += 1\n## tank = b-2*f\n## else:\n## cant2 = True\n## break\n## \n## journeys += 1\n## previous = 0\n##\n##if cant1 and not cant2:\n## print(refuels2)\n##elif not cant1 and cant2:\n## print(refuels1)\n##elif cant1 and cant2:\n## print(-1)\n##else:\n## print(min(refuels1, refuels2))\n\n", "passed": true, "time": 0.31, "memory": 14372.0, "status": "done"}, {"code": "def solve():\n\n a, b, f, k = [int(st) for st in input().split(\" \")]\n\n fuel = b\n location = 0\n direction = \"right\"\n fueled = 0\n\n journeypassed = 0\n while journeypassed < k:\n\n #print(\"location:\", location, \", fuel:\", fuel, \", \"+direction)\n\n if location == 0:\n if fuel < f:\n return -1\n fuel -= f\n location = f\n direction = \"right\"\n\n elif location == a:\n if fuel < a-f:\n return -1\n fuel -= a-f\n location = f\n direction = \"left\"\n\n elif location == f:\n \n if k - journeypassed <= 1:\n if direction == \"left\":\n if fuel < f:\n fuel = b\n fueled += 1\n if fuel < f:\n return -1\n fuel -= f\n location = 0\n direction = \"right\"\n else:\n if fuel < a-f:\n fuel = b\n fueled += 1\n if fuel < a-f:\n return -1\n fuel -= a-f\n location = a\n direction = \"left\"\n \n else:\n if direction == \"left\":\n if fuel < 2*f:\n fuel = b\n fueled += 1\n if fuel < 2*f:\n return -1\n fuel -= 2*f\n direction = \"right\"\n else:\n if fuel < 2*(a-f):\n fuel = b\n fueled += 1\n if fuel < 2*(a-f):\n return -1\n fuel -= 2*(a-f)\n direction = \"left\"\n \n journeypassed += 1\n \n\n return fueled\n\nprint(solve())\n", "passed": true, "time": 0.18, "memory": 14620.0, "status": "done"}, {"code": "a,b,f,k=list(map(int,input().split()))\ni=0\nbi=b\nans=0\nwhile i<k:\n if f>bi:\n print(-1)\n return\n bi-=f\n if k-i==1:\n if a-f>bi:\n bi=b\n ans+=1\n if a-f>b:\n print(-1)\n return\n break\n i+=1\n if 2*(a-f)>bi:\n bi=b\n ans+=1\n if 2*(a-f)>b:\n print(-1)\n return\n bi-=2*(a-f)\n if k-i==1:\n if f>bi:\n bi=b\n ans+=1\n break\n if 2*f>bi:\n bi=b\n ans+=1\n if 2*f>b:\n print(-1)\n return\n bi-=f\n i+=1\nprint(ans)\n \n", "passed": true, "time": 0.22, "memory": 14520.0, "status": "done"}, {"code": "import sys\ndef solve():\n\tend,full,real_mid,times = map(int,sys.stdin.readline().split())\n\n\toil = full\n\tcnt = 0\n\tfor i in range(times):\n\t\tif i % 2 == 0:\n\t\t\tmid = real_mid\n\t\telse:\n\t\t\tmid = end - real_mid\n\n\t\tif mid > oil:\n\t\t\treturn -1\n\n\t\toil -= mid\n\n\t\tif i != times - 1:\n\t\t\tif (end - mid) * 2 > full:\n\t\t\t\treturn -1\n\t\t\tif (end - mid) * 2 > oil:\n\t\t\t\toil = full\n\t\t\t\tcnt += 1\n\t\telse:\n\t\t\tif end - mid > full:\n\t\t\t\treturn -1\n\t\t\tif end - mid > oil:\n\t\t\t\toil = full\n\t\t\t\tcnt += 1\n\t\toil -= end - mid\n\treturn cnt\n\nprint(solve())", "passed": true, "time": 0.19, "memory": 14348.0, "status": "done"}] | [{"input": "6 9 2 4\n", "output": "4\n"}, {"input": "6 10 2 4\n", "output": "2\n"}, {"input": "6 5 4 3\n", "output": "-1\n"}, {"input": "2 2 1 1\n", "output": "0\n"}, {"input": "10 4 6 10\n", "output": "-1\n"}, {"input": "3 1 1 1\n", "output": "-1\n"}, {"input": "2 1 1 1\n", "output": "1\n"}, {"input": "1000000 51923215 2302 10000\n", "output": "199\n"}, {"input": "10 11 3 2\n", "output": "-1\n"}, {"input": "20 50 10 25\n", "output": "11\n"}, {"input": "10 10 5 20\n", "output": "20\n"}, {"input": "15 65 5 50\n", "output": "12\n"}, {"input": "10 19 1 5\n", "output": "3\n"}, {"input": "10 19 9 5\n", "output": "3\n"}, {"input": "23 46 12 2\n", "output": "0\n"}, {"input": "23 46 12 3\n", "output": "1\n"}, {"input": "20 20 19 1\n", "output": "0\n"}, {"input": "20 23 17 2\n", "output": "1\n"}, {"input": "20 18 9 2\n", "output": "-1\n"}, {"input": "100 70 50 1\n", "output": "1\n"}, {"input": "100 70 70 2\n", "output": "2\n"}, {"input": "140 480 1 40\n", "output": "19\n"}, {"input": "140 480 139 40\n", "output": "18\n"}, {"input": "1000000 1000000000 1 1000\n", "output": "0\n"}, {"input": "1000000 1000000000 999999 1000\n", "output": "0\n"}, {"input": "1000000 159842934 2376 1000\n", "output": "6\n"}, {"input": "2 1000000000 1 1000\n", "output": "0\n"}, {"input": "100000 1000000 50000 1000\n", "output": "100\n"}, {"input": "1000000 1000000 500000 1000\n", "output": "1000\n"}, {"input": "1000000 1000000 500000 10000\n", "output": "10000\n"}, {"input": "1000000 2500000 500000 9999\n", "output": "4998\n"}, {"input": "1000000 1500000 500000 9999\n", "output": "9997\n"}, {"input": "1000000 1500000 500000 10000\n", "output": "9998\n"}, {"input": "1000000 1 1 1\n", "output": "-1\n"}, {"input": "2 1000000000 1 1\n", "output": "0\n"}, {"input": "1000000 1000000000 1 1\n", "output": "0\n"}, {"input": "1000000 1 999999 1\n", "output": "-1\n"}, {"input": "1000000 1000000000 999999 1\n", "output": "0\n"}, {"input": "2 1 1 10000\n", "output": "-1\n"}, {"input": "1000000 1 1 10000\n", "output": "-1\n"}, {"input": "1000000 1000000000 1 10000\n", "output": "10\n"}, {"input": "1000000 1 999999 10000\n", "output": "-1\n"}, {"input": "2 1000000000 1 10000\n", "output": "0\n"}, {"input": "1000000 1000000000 999999 10000\n", "output": "10\n"}, {"input": "10000 78393 3000 9999\n", "output": "1428\n"}, {"input": "1000000 8839233 302200 9999\n", "output": "1249\n"}, {"input": "900005 3333333 210000 9999\n", "output": "3332\n"}, {"input": "999999 39486793 138762 9282\n", "output": "244\n"}, {"input": "1000000 8739233 400000 9999\n", "output": "1249\n"}, {"input": "1000000 500000 500000 1\n", "output": "1\n"}, {"input": "1000000 70000000 333333 9999\n", "output": "142\n"}, {"input": "6 7 4 2\n", "output": "2\n"}, {"input": "3 1 2 1\n", "output": "-1\n"}, {"input": "10 8 8 2\n", "output": "2\n"}, {"input": "150 100 1 1\n", "output": "-1\n"}, {"input": "6 4 4 2\n", "output": "2\n"}, {"input": "10 10 9 2\n", "output": "2\n"}, {"input": "10 5 6 1\n", "output": "-1\n"}, {"input": "3 3 2 2\n", "output": "2\n"}, {"input": "4 4 3 2\n", "output": "2\n"}, {"input": "10 4 7 1\n", "output": "-1\n"}, {"input": "100 5 97 1\n", "output": "-1\n"}, {"input": "7 11 6 2\n", "output": "1\n"}, {"input": "100 50 99 1\n", "output": "-1\n"}, {"input": "5 3 4 1\n", "output": "-1\n"}, {"input": "51 81 36 38\n", "output": "36\n"}, {"input": "10 8 6 2\n", "output": "2\n"}, {"input": "10 8 7 2\n", "output": "2\n"}, {"input": "10 11 6 2\n", "output": "2\n"}, {"input": "5 4 4 2\n", "output": "2\n"}, {"input": "6 5 5 2\n", "output": "2\n"}, {"input": "100 159 80 2\n", "output": "1\n"}] |
|
218 | You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q.
For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it is allowed to split the string s to the strings only of length p or to the strings only of length q (see the second sample test).
-----Input-----
The first line contains three positive integers n, p, q (1 ≤ p, q ≤ n ≤ 100).
The second line contains the string s consists of lowercase and uppercase latin letters and digits.
-----Output-----
If it's impossible to split the string s to the strings of length p and q print the only number "-1".
Otherwise in the first line print integer k — the number of strings in partition of s.
Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be in order of their appearing in string s — from left to right.
If there are several solutions print any of them.
-----Examples-----
Input
5 2 3
Hello
Output
2
He
llo
Input
10 9 5
Codeforces
Output
2
Codef
orces
Input
6 4 5
Privet
Output
-1
Input
8 1 1
abacabac
Output
8
a
b
a
c
a
b
a
c | interview | [{"code": "n, p, q = list(map(int, input().split(\" \")))\ns=input()\n\nc=-1\n\nfor i in range (n+1):\n for j in range (n+1):\n if p*i+q*j==n:\n c=i\n d=j\n break\n if c!=-1:\n break\n\nif c==-1:\n print(-1)\nelse:\n print(c+d)\n for i in range (c):\n print(s[p*i:p*(i+1)])\n e=c*p\n for j in range (d):\n print(s[e+q*j:e+q*(j+1)])\n", "passed": true, "time": 0.16, "memory": 14344.0, "status": "done"}, {"code": "def main():\n items=input().split()\n n=int(items[0])\n p=int(items[1])\n q=int(items[2])\n s=input()\n A=int(n/p)\n for a in range(A+1):\n forq=n-a*p\n if forq%q==0:\n b=int(forq/q)\n print(a+b)\n for i in range(a):\n print(s[i*p:(i+1)*p])\n for i in range(b):\n print(s[a*p+i*q:a*p+(i+1)*q])\n return\n print(-1)\n \ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14484.0, "status": "done"}, {"code": "n,p,q=list(map(int, input().split(\" \")))\ns = input()\nasdf = False\nfor i in range(n//p+1):\n for j in range((n-i*p)//q+1):\n if i*p+j*q == n and asdf == False:\n print(i+j)\n asdf = True\n for a in range(i):\n print(s[a*p:(a+1)*p])\n for b in range(j):\n print(s[p*i+b*q:p*i+(b+1)*q])\nif asdf == False:\n print(-1)\n \n", "passed": true, "time": 0.15, "memory": 14304.0, "status": "done"}, {"code": "n, p, q = map(int, input().split())\ns = input()\nfor i in range(n // p + 1):\n if (n - i * p) % q == 0:\n print(i + (n - i * p) // q)\n for j in range(i):\n print(s[j * p:j * p + p])\n for j in range((n - i * p) // q):\n print(s[i * p + j * q: i * p + j * q + q])\n return\nprint(-1)", "passed": true, "time": 0.2, "memory": 14440.0, "status": "done"}, {"code": "n, a, b = map(int, input().split())\ns = input()\nk1, k2 = 0, 0\nfor i in range(n + 1):\n for j in range(n + 1):\n if i * a + j * b == n:\n k1 = i\n k2 = j\n break\n if k1 or k2:\n break\nelse:\n print('-1')\n\nif k1 or k2:\n print(k1 + k2)\n i = 0\n while k1:\n print(s[i: i + a])\n k1 -= 1\n i += a\n while k2:\n print(s[i: i + b])\n k2 -= 1\n i += b", "passed": true, "time": 0.15, "memory": 14600.0, "status": "done"}, {"code": "#The Text Splitting.py\nimport os\nn, a, b = list(map(int, input().split()))\ns = input()\nmaxn = n // a\n# print(s)\nx = -1\nfor i in range(0, maxn+1):\n\ttmp = n - a*i\n\tif tmp % b == 0:\n\t\tx = i\n\t\tbreak\nif x != -1:\n\tprint(x + (n - a*x) // b)\n\tout = \"\"\n\tfor i in range(0, x):\n\t\tout = s[a*i:(i+1)*a]\n\t\tprint(out)\n\ty = (n - a*x) // b\n\tfor i in range(0, y):\n\t\tout = s[b*i+a*x:(i+1)*b+a*x]\n\t\tprint(out)\nelse:\n\tprint(\"-1\")\n#os.system(\"pause\")\n", "passed": true, "time": 0.14, "memory": 14528.0, "status": "done"}, {"code": "import math\n\ndef euclid_algorithm(a, b):\n t1, t2 = abs(a), abs(b)\n #saving equalities:\n #t1 == x1 * a + y1 * b,\n #t2 == x2 * a + y2 * b. \n x1, y1, x2, y2 = int(math.copysign(1, a)), 0, 0, int(math.copysign(1, b))\n if t1 < t2:\n t1, t2 = t2, t1\n x1, y1, x2, y2 = x2, y2, x1, y1\n\n while t2 > 0:\n if x1 * a + y1 * b != t1:\n print('inshalla')\n k = int(t1 // t2)\n t1, t2 = t2, t1 % t2\n #t1 - k * t2 == (x1 - k * x2) * a + (y1 - k * y2) * b\n x1, y1, x2, y2 = x2, y2, x1 - k * x2, y1 - k * y2\n\n return t1, x1, y1\n\ndef opposite_element(x, p):\n gcd, k, l = euclid_algorithm(x, p)\n if gcd != 1:\n return -1\n return k % p\n\ndef fact_mod(n, p):\n prod = 1\n for i in range(2,n+1):\n prod *= i\n prod %= p\n return prod\n\nn, p, q = [int(x) for x in input().split()]\ns = input().rstrip()\nfor i in range(n // p + 1):\n if (n - p*i) % q == 0:\n j = (n - p*i) // q\n print(i+j)\n for k in range(i):\n print(s[k*p:(k+1)*p])\n for k in range(j):\n print(s[p*i + k*q: p*i + (k+1)*q])\n break\nelse:\n print(-1)\n \n", "passed": true, "time": 0.14, "memory": 14472.0, "status": "done"}, {"code": "n, a, b = list(map(int, input().split(' ')))\n\ns = input()\n\nc = 0\nwhile c * a <= n and (n - c * a) % b != 0:\n c += 1\n\nif c * a > n:\n print(-1)\nelse:\n cb = (n - a * c) // b\n print(c + cb)\n for i in range(c):\n print(s[a * i: a * (i + 1)])\n for i in range(cb):\n print(s[c * a + b * i: c * a + b * (i + 1)])\n", "passed": true, "time": 0.24, "memory": 14356.0, "status": "done"}, {"code": "n, p, q = list(map(int, input().split()))\ns = input()\n\nk1 = 0\nk = 0\n\nr = n // p\n\nfor i in range(r, -1, -1):\n if (n - p * i) % q == 0:\n k1 = i\n k = k1 + ((n - p * i) // q)\n\n\nif k == 0:\n print(-1)\nelse:\n print(k)\n for i in range(k1):\n print(s[i*p: (i+1)*p])\n for i in range(k - k1):\n print(s[p*k1 + i*q: p*k1 + (i + 1)*q])\n", "passed": true, "time": 0.15, "memory": 14448.0, "status": "done"}, {"code": "n, p, q = list(map(int, input().split()))\ns = input()\nm = 0\nwhile m * p <= n:\n if (n - m * p) % q == 0:\n k = m + (n - m * p) // q\n print(k)\n for i in range(m):\n print(s[p * i: p * (i + 1)])\n for i in range(k - m):\n print(s[p * m + q * i: p * m + q * (i + 1)])\n break\n m += 1\nelse:\n print(-1)\n", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "def main():\n n, p, q = list(map(int, input().split()))\n s = input()\n\n for i in range(0, n + 1):\n for j in range(0, n + 1):\n if p * i + q * j == n:\n print(i + j)\n for k in range(i):\n print(s[:p])\n s = s[p:]\n for k in range(j):\n print(s[:q])\n s = s[q:]\n return 0\n\n print(-1)\n return 0\n\nmain()\n", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "import sys\n# fin = open(\"ecr4a.in\", \"r\")\nfin = sys.stdin\n\nn, p, q = map(int, fin.readline().split())\ns = fin.readline().rstrip()\n\n\nkp, kq = None, None\nfor i in range(0, n // p + 1):\n if not (n - i*p) % q:\n kp, kq = i, (n - i*p) // q\n break\nelse:\n print(-1)\n return\n\nprint(kp+kq)\ncpos, m = 0, p*kp\nwhile (cpos < m):\n print(s[cpos:cpos + p])\n cpos += p\nwhile (cpos < n):\n print(s[cpos:cpos + q])\n cpos += q", "passed": true, "time": 0.14, "memory": 14472.0, "status": "done"}, {"code": "import sys\nif False:\n\tinp = open('A.txt', 'r')\nelse:\n\tinp = sys.stdin\n\nn, p, q = list(map(int, inp.readline().split()))\nstring = inp.readline().strip()\n\nlength = n\nans = -1\nfor i in range(n//p + 1):\n\tlength = n-p*i\n\tif length%q == 0:\n\t\tans = i\n\t\tbreak\nif ans == -1:\n\tprint(-1)\nelse:\n\tprint(ans + length//q)\n\tfor i in range(ans):\n\t\tprint(string[:p])\n\t\tstring = string[p:]\n\tfor i in range(length//q):\n\t\tprint(string[:q])\n\t\tstring = string[q:]\n\n\n\n\n", "passed": true, "time": 0.15, "memory": 14492.0, "status": "done"}, {"code": "n, p, q = map(int, input().split())\ns = input()\nfor i in range(n // p + 1):\n if (n - i * p) % q == 0:\n print(i + (n - i * p) // q)\n for j in range(i):\n print(s[j * p:j * p + p])\n for j in range((n - i * p) // q):\n print(s[i * p + j * q: i * p + j * q + q])\n return\nprint(-1)", "passed": true, "time": 0.67, "memory": 14440.0, "status": "done"}] | [{"input": "5 2 3\nHello\n", "output": "2\nHe\nllo\n"}, {"input": "10 9 5\nCodeforces\n", "output": "2\nCodef\norces\n"}, {"input": "6 4 5\nPrivet\n", "output": "-1\n"}, {"input": "8 1 1\nabacabac\n", "output": "8\na\nb\na\nc\na\nb\na\nc\n"}, {"input": "1 1 1\n1\n", "output": "1\n1\n"}, {"input": "10 8 1\nuTl9w4lcdo\n", "output": "10\nu\nT\nl\n9\nw\n4\nl\nc\nd\no\n"}, {"input": "20 6 4\nfmFRpk2NrzSvnQC9gB61\n", "output": "5\nfmFR\npk2N\nrzSv\nnQC9\ngB61\n"}, {"input": "30 23 6\nWXDjl9kitaDTY673R5xyTlbL9gqeQ6\n", "output": "5\nWXDjl9\nkitaDT\nY673R5\nxyTlbL\n9gqeQ6\n"}, {"input": "40 14 3\nSOHBIkWEv7ScrkHgMtFFxP9G7JQLYXFoH1sJDAde\n", "output": "6\nSOHBIkWEv7Scrk\nHgMtFFxP9G7JQL\nYXF\noH1\nsJD\nAde\n"}, {"input": "50 16 3\nXCgVJUu4aMQ7HMxZjNxe3XARNiahK303g9y7NV8oN6tWdyXrlu\n", "output": "8\nXCgVJUu4aMQ7HMxZ\njNxe3XARNiahK303\ng9y\n7NV\n8oN\n6tW\ndyX\nrlu\n"}, {"input": "60 52 8\nhae0PYwXcW2ziQCOSci5VaElHLZCZI81ULSHgpyG3fuZaP0fHjN4hCKogONj\n", "output": "2\nhae0PYwXcW2ziQCOSci5VaElHLZCZI81ULSHgpyG3fuZaP0fHjN4\nhCKogONj\n"}, {"input": "70 50 5\n1BH1ECq7hjzooQOZdbiYHTAgATcP5mxI7kLI9rqA9AriWc9kE5KoLa1zmuTDFsd2ClAPPY\n", "output": "14\n1BH1E\nCq7hj\nzooQO\nZdbiY\nHTAgA\nTcP5m\nxI7kL\nI9rqA\n9AriW\nc9kE5\nKoLa1\nzmuTD\nFsd2C\nlAPPY\n"}, {"input": "80 51 8\no2mpu1FCofuiLQb472qczCNHfVzz5TfJtVMrzgN3ff7FwlAY0fQ0ROhWmIX2bggodORNA76bHMjA5yyc\n", "output": "10\no2mpu1FC\nofuiLQb4\n72qczCNH\nfVzz5TfJ\ntVMrzgN3\nff7FwlAY\n0fQ0ROhW\nmIX2bggo\ndORNA76b\nHMjA5yyc\n"}, {"input": "90 12 7\nclcImtsw176FFOA6OHGFxtEfEyhFh5bH4iktV0Y8onIcn0soTwiiHUFRWC6Ow36tT5bsQjgrVSTcB8fAVoe7dJIWkE\n", "output": "10\nclcImtsw176F\nFOA6OHGFxtEf\nEyhFh5bH4ikt\nV0Y8onIcn0so\nTwiiHUF\nRWC6Ow3\n6tT5bsQ\njgrVSTc\nB8fAVoe\n7dJIWkE\n"}, {"input": "100 25 5\n2SRB9mRpXMRND5zQjeRxc4GhUBlEQSmLgnUtB9xTKoC5QM9uptc8dKwB88XRJy02r7edEtN2C6D60EjzK1EHPJcWNj6fbF8kECeB\n", "output": "20\n2SRB9\nmRpXM\nRND5z\nQjeRx\nc4GhU\nBlEQS\nmLgnU\ntB9xT\nKoC5Q\nM9upt\nc8dKw\nB88XR\nJy02r\n7edEt\nN2C6D\n60Ejz\nK1EHP\nJcWNj\n6fbF8\nkECeB\n"}, {"input": "100 97 74\nxL8yd8lENYnXZs28xleyci4SxqsjZqkYzkEbQXfLQ4l4gKf9QQ9xjBjeZ0f9xQySf5psDUDkJEtPLsa62n4CLc6lF6E2yEqvt4EJ\n", "output": "-1\n"}, {"input": "51 25 11\nwpk5wqrB6d3qE1slUrzJwMFafnnOu8aESlvTEb7Pp42FDG2iGQn\n", "output": "-1\n"}, {"input": "70 13 37\nfzL91QIJvNoZRP4A9aNRT2GTksd8jEb1713pnWFaCGKHQ1oYvlTHXIl95lqyZRKJ1UPYvT\n", "output": "-1\n"}, {"input": "10 3 1\nXQ2vXLPShy\n", "output": "10\nX\nQ\n2\nv\nX\nL\nP\nS\nh\ny\n"}, {"input": "4 2 3\naaaa\n", "output": "2\naa\naa\n"}, {"input": "100 1 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n", "output": "100\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\nb\n"}, {"input": "99 2 4\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "-1\n"}, {"input": "11 2 3\nhavanahavan\n", "output": "4\nha\nvan\naha\nvan\n"}, {"input": "100 2 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "50\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\naa\n"}, {"input": "17 3 5\ngopstopmipodoshli\n", "output": "5\ngop\nsto\npmi\npod\noshli\n"}, {"input": "5 4 3\nfoyku\n", "output": "-1\n"}, {"input": "99 2 2\n123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\n", "output": "-1\n"}, {"input": "99 2 2\nrecursionishellrecursionishellrecursionishellrecursionishellrecursionishellrecursionishelldontuseit\n", "output": "-1\n"}, {"input": "11 2 3\nqibwnnvqqgo\n", "output": "4\nqi\nbwn\nnvq\nqgo\n"}, {"input": "4 4 3\nhhhh\n", "output": "1\nhhhh\n"}, {"input": "99 2 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "-1\n"}, {"input": "99 2 5\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n", "output": "21\nhh\nhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\nhhhhh\n"}, {"input": "10 5 9\nCodeforces\n", "output": "2\nCodef\norces\n"}, {"input": "10 5 9\naaaaaaaaaa\n", "output": "2\naaaaa\naaaaa\n"}, {"input": "11 3 2\nmlmqpohwtsf\n", "output": "5\nmlm\nqp\noh\nwt\nsf\n"}, {"input": "3 3 2\nzyx\n", "output": "1\nzyx\n"}, {"input": "100 3 3\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "-1\n"}, {"input": "4 2 3\nzyxw\n", "output": "2\nzy\nxw\n"}, {"input": "3 2 3\nejt\n", "output": "1\nejt\n"}, {"input": "5 2 4\nzyxwv\n", "output": "-1\n"}, {"input": "100 1 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "100\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\n"}, {"input": "100 5 4\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "25\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\naaaa\n"}, {"input": "3 2 2\nzyx\n", "output": "-1\n"}, {"input": "99 2 2\nhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n", "output": "-1\n"}, {"input": "26 8 9\nabcabcabcabcabcabcabcabcab\n", "output": "3\nabcabcab\ncabcabcab\ncabcabcab\n"}, {"input": "6 3 5\naaaaaa\n", "output": "2\naaa\naaa\n"}, {"input": "3 2 3\nzyx\n", "output": "1\nzyx\n"}, {"input": "5 5 2\naaaaa\n", "output": "1\naaaaa\n"}, {"input": "4 3 2\nzyxw\n", "output": "2\nzy\nxw\n"}, {"input": "5 4 3\nzyxwv\n", "output": "-1\n"}, {"input": "95 3 29\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab\n", "output": "23\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabc\nabcabcabcabcabcabcabcabcabcab\n"}, {"input": "3 2 2\naaa\n", "output": "-1\n"}, {"input": "91 62 3\nfjzhkfwzoabaauvbkuzaahkozofaophaafhfpuhobufawkzbavaazwavwppfwapkapaofbfjwaavajojgjguahphofj\n", "output": "-1\n"}, {"input": "99 2 2\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc\n", "output": "-1\n"}, {"input": "56 13 5\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab\n", "output": "8\nabcabcabcabca\nbcabcabcabcab\ncabca\nbcabc\nabcab\ncabca\nbcabc\nabcab\n"}, {"input": "79 7 31\nabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca\n", "output": "-1\n"}, {"input": "92 79 6\nxlvplpckwnhmctoethhslkcyashqtsoeltriddglfwtgkfvkvgytygbcyohrvcxvosdioqvackxiuifmkgdngvbbudcb\n", "output": "-1\n"}, {"input": "48 16 13\nibhfinipihcbsqnvtgsbkobepmwymlyfmlfgblvhlfhyojsy\n", "output": "3\nibhfinipihcbsqnv\ntgsbkobepmwymlyf\nmlfgblvhlfhyojsy\n"}, {"input": "16 3 7\naaaaaaaaaaaaaaaa\n", "output": "4\naaa\naaa\naaa\naaaaaaa\n"}, {"input": "11 10 3\naaaaaaaaaaa\n", "output": "-1\n"}, {"input": "11 8 8\naaaaaaaaaaa\n", "output": "-1\n"}, {"input": "11 7 3\naaaaaaaaaaa\n", "output": "-1\n"}, {"input": "41 3 4\nabcabcabcabcabcabcabcabcabcabcabcabcabcab\n", "output": "11\nabc\nabc\nabc\nabca\nbcab\ncabc\nabca\nbcab\ncabc\nabca\nbcab\n"}, {"input": "11 3 2\naaaaaaaaaaa\n", "output": "5\naaa\naa\naa\naa\naa\n"}, {"input": "14 9 4\nabcdefghijklmn\n", "output": "-1\n"}, {"input": "9 9 5\n123456789\n", "output": "1\n123456789\n"}, {"input": "92 10 41\nmeotryyfneonmnrvfnhqlehlxtvpracifpadcofecvbikoitrlgeftiqofpvacgocrdiquhatlqosqvtduenaqkwrnnw\n", "output": "3\nmeotryyfne\nonmnrvfnhqlehlxtvpracifpadcofecvbikoitrlg\neftiqofpvacgocrdiquhatlqosqvtduenaqkwrnnw\n"}, {"input": "17 16 3\ndxyhgtsxtuyljmclj\n", "output": "-1\n"}, {"input": "82 13 30\nfmtwumakkejtolxqxrnydhqoufwtdwldfxcfjrndauqcarhbwmdwxsxfbqjsfspuxobywhcrvlndsdmkqd\n", "output": "5\nfmtwumakkejto\nlxqxrnydhqouf\nwtdwldfxcfjrn\ndauqcarhbwmdw\nxsxfbqjsfspuxobywhcrvlndsdmkqd\n"}, {"input": "95 3 3\nihnfqcswushyoirjxlxxnwqtwtaowounkumxukwpacxwatimhhhoggqwkkspcplvyndfukbxickcixidgxkjtnpkoeiwlor\n", "output": "-1\n"}, {"input": "7 5 3\nzyxwvut\n", "output": "-1\n"}, {"input": "17 16 4\nctvfhkiakagcilrdw\n", "output": "-1\n"}] |
|
219 | A sportsman starts from point x_{start} = 0 and runs to point with coordinate x_{finish} = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x_1, x_2, ..., x_{n}. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
-----Input-----
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 10^9, 1 ≤ s, d ≤ 10^9) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
-----Output-----
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format: print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters; print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
-----Examples-----
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE | interview | [{"code": "n, m, s, d = list(map(int, input().split()))\n\nbeg = [float('-inf')]\nend = [float('-inf')]\n\na = [int(i) for i in input().split()]\n\nfor x in sorted(a):\n\tif (x - end[-1] > s + 1):\n\t\tbeg.append(x)\n\t\tend.append(x)\n\telse:\n\t\tend[-1] = x\n\nlast = 0\nR = []\nJ = []\n\nfor i in range(1, len(beg)):\n\tR.append(beg[i] - 1 - last)\n\tlast = (beg[i] - 1)\n\t\n\tJ.append(end[i] + 1 - last)\n\tlast = (end[i] + 1)\n\nok = True\nfor x in J:\n\tif (x > d):\n\t\tok = False\nfor x in R:\n\tif (x < s):\n\t\tok = False\n\n\nif ok:\n\tfor i in range(len(R)):\n\t\tprint('RUN', R[i])\n\t\tprint('JUMP', J[i])\n\tif (last < m):\n\t\tprint('RUN', m - last)\nelse:\n\tprint('IMPOSSIBLE')\n", "passed": true, "time": 0.14, "memory": 14388.0, "status": "done"}, {"code": "n, m, s, d = list(map(int, input().split()))\na = list(map(int, input().split()))\na.sort()\nif a[0] - 1 < s:\n print('IMPOSSIBLE')\n return\nstrategy = []\ni = 0\nstand_point = 0\nwhile i < n:\n strategy.append(a[i] - stand_point - 1)\n stand_point = a[i] - 1\n j = i + 1\n if j != n:\n a2, a1 = a[j], a[i]\n while j < n:\n if a2 - a1 - 2 < s:\n if a2 - a[i] + 2 > d:\n print('IMPOSSIBLE')\n return\n j += 1\n if j != n:\n a1 = a2\n a2 = a[j]\n continue\n else:\n strategy.append(a1 - a[i] + 2)\n i = j\n stand_point = a[i - 1] + 1\n break\n else:\n #print(stand_point, strategy_run, strategy_jump)\n if d >= a[-1] - stand_point + 1 and strategy[-1] >= s:\n strategy.append(a[-1] - stand_point + 1)\n else:\n print('IMPOSSIBLE')\n return\n i = j\n stand_point = a[i - 1] + 1\n\nif m - stand_point != 0:\n strategy.append(m - stand_point)\nturn_flag = True\nfor i in strategy:\n if turn_flag:\n print('RUN', i)\n else:\n print('JUMP', i)\n turn_flag = not turn_flag\n", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "import sys\n\ndef solve():\n n, m, s, d = [int(x) for x in input().split()]\n obstacles = [int(x) for x in input().split()]\n obstacles.sort()\n if obstacles[0] <= s: return False\n pieces = [[obstacles[0], obstacles[0]]]\n for x in obstacles:\n if pieces[-1][1] + s + 2 > x:\n pieces[-1][1] = x\n else:\n if pieces[-1][1] - pieces[-1][0] + 2 > d: return False\n pieces.append([x, x])\n if pieces[-1][1] - pieces[-1][0] + 2 > d: return False\n pos = 0\n for piece in pieces:\n sys.stdout.write('RUN ' + str(piece[0] - pos - 1) + '\\n')\n sys.stdout.write('JUMP ' + str(piece[1] - piece[0] + 2) + '\\n')\n pos = piece[1] + 1\n if pos < m:\n sys.stdout.write('RUN ' + str(m - pos) + '\\n')\n return True\n\nif not solve():\n print('IMPOSSIBLE')\n", "passed": true, "time": 0.14, "memory": 14608.0, "status": "done"}, {"code": "n, m, s, d = map(int, input().split())\nA = sorted(list(map(int, input().split())))\n\n# Intervals\ninv = []\nprev = -1\nfor i in range(len(A)):\n if A[i] < m:\n inv.append((prev, A[i]))\n prev = A[i]\n else:\n inv.append((prev, m))\n break\nif A[-1] < m:\n inv.append((A[-1], m))\n\noutput = [inv[-1]]\n\n# Use of intervals\nlast = inv[-1]\nfor i in range(len(inv) - 2, -1, -1):\n a, b = inv[i], last\n if a[1] - a[0] >= s + 2 and b[0] - a[1] <= d - 2:\n last = inv[i]\n output.append(last)\noutput = output[::-1]\n\nif m < A[0]:\n print(\"RUN \" + str(m))\nelif last[0] != -1 or A[0] <= s:\n print(\"IMPOSSIBLE\")\nelse:\n last = 0\n for i in range(1, len(output)):\n a, b = output[i - 1], output[i]\n print(\"RUN \" + str(a[1] - a[0] - 2))\n print(\"JUMP \" + str(b[0] - a[1] + 2))\n last = b[0] + 1\n if last < m:\n print(\"RUN \" + str(m - last))", "passed": true, "time": 0.14, "memory": 14652.0, "status": "done"}, {"code": "import itertools\n\n\nclass SolutionImpossible(Exception):\n pass\n\n\nblocks_cnt, finish, min_sprint, max_jump = [int(x) for x in input().split()]\n\n\ndef read_blocks_coords():\n it = (int(x) for x in input().split())\n return (x for x in it if x < finish)\n\n\n# TODO: \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u0437\u0430 \u0441\u0447\u0435\u0442 \u0438\u0437\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0442 \u043b\u0438\u0448\u043d\u0435\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 `_grouper._current_key`\ndef _grouper(value):\n if _grouper._prev_value is not None:\n # \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u044b\u0436\u043a\u0430 \u043c\u044b \u043f\u0440\u0438\u0437\u0435\u043c\u043b\u044f\u0435\u043c\u0441\u044f \u0417\u0410 \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u0435\u043c, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u043e\n if value - _grouper._prev_value - 1 <= min_sprint:\n # \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u044f\u043c\u0438 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0430\u043b\u043e\n # \u0447\u0442\u043e\u0431\u044b \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043f\u0440\u0438\u0437\u0435\u043c\u043b\u044f\u0442\u044c\u0441\u044f, \u0438 \u0437\u0430\u0442\u0435\u043c \u0440\u0430\u0437\u043e\u0433\u043d\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u044b\u0436\u043a\u0430, \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0438\u0445 \u0437\u0430 \u043e\u0434\u043d\u043e\n _current_key = _grouper._current_key\n else:\n _current_key = id(value)\n else:\n # \u043f\u0435\u0440\u0432\u043e\u0435 \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435, \u0441\u0442\u0430\u0432\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e\n _current_key = id(_grouper)\n\n _grouper._prev_value = value\n _grouper._current_key = _current_key\n\n return _current_key\n\n\n_grouper._prev_value = None\n_grouper._current_key = None\n\n\ndef check_chunk(run_from, block=None):\n if block is None:\n return\n\n next_run_from = block[-1] + 1 # \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0437\u0430 \u043f\u0440\u0435\u0433\u0440\u0430\u0434\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u044f (\u0442\u043e\u0447\u043a\u0430 \u043f\u0440\u0438\u0437\u0435\u043c\u043b\u0435\u043d\u0438\u044f)\n if next_run_from - block[0] >= max_jump:\n # \u0435\u0441\u043b\u0438 \u043f\u0440\u0435\u0433\u0440\u0430\u0434\u0430 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043b\u0438\u043d\u043d\u0430\u044f, \u0442\u043e \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0435\u0435 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u044c\n raise SolutionImpossible\n\n if abs(run_from - block[0]) <= min_sprint:\n # \u043d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u0431\u0435\u0433\u0430\n raise SolutionImpossible\n\n\ndef solve_chunk(run_from, block=None):\n if block is not None:\n run_len = block[0] - run_from - 1 # \u0434\u043e\u0431\u0435\u0433\u0430\u0435\u043c \u0414\u041e \u043f\u0440\u0435\u0433\u0440\u0430\u0434\u044b\n jump_len = block[-1] - block[0] + 2 # \u043f\u0440\u044b\u0433\u0430\u0435\u043c \u0417\u0410 \u043d\u0435\u0435\n print((\n \"RUN {run_len}\\n\"\n \"JUMP {jump_len}\".format(\n run_len=run_len,\n jump_len=jump_len,\n )\n ))\n\n else:\n run_len = finish - run_from\n if run_len > 0:\n print(\"RUN {run_len}\".format(run_len=run_len))\n\n\ndef main():\n # \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a \u0431\u043b\u0438\u0437\u043a\u043e, \u0447\u0442\u043e \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u043e\u0433\u043d\u0430\u0442\u044c\u0441\u044f\n # \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u044f \u0437\u0430 \u043e\u0434\u043d\u043e\n blocks = (list(g) for k, g in itertools.groupby(sorted(read_blocks_coords()), key=_grouper))\n\n chunks = []\n\n run_from = 0\n while True:\n block = next(blocks, None)\n\n chunk = (run_from, block)\n check_chunk(*chunk)\n\n chunks.append(chunk)\n\n if block is None:\n break\n\n # \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u044b\u0436\u043a\u0430 \u043c\u044b \u043f\u0440\u0438\u0437\u0435\u043c\u043b\u044f\u0435\u043c\u0441\u044f \u0417\u0410 \u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0438\u0435\u043c, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u043e\n run_from = block[-1] + 1\n\n #print(chunks)\n\n for chunk in chunks:\n solve_chunk(*chunk)\n\n\ndef __starting_point():\n try:\n main()\n except SolutionImpossible:\n print(\"IMPOSSIBLE\")\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14896.0, "status": "done"}, {"code": "num_barriers, finish, min_run, max_jump = tuple(map(int, input().split()))\n\nbarriers = list(map(int, input().split())) + [-1]\nbarriers.sort()\n\nfor i in range(len(barriers) - 1):\n if barriers[i + 1] - barriers[i] <= min_run + 1:\n barriers[i] = (0, barriers[i] + 1, barriers[i + 1] - 1) # nope\n else:\n barriers[i] = (1, barriers[i] + 1, barriers[i + 1] - 1) # ok\n\nbarriers[len(barriers) - 1] = (1, barriers[len(barriers) - 1] + 1, finish)\n\nif not barriers:\n pass\nelif not barriers[0][0]:\n print('IMPOSSIBLE')\nelse:\n commands = []\n pos = 0\n\n for tpe, st, en in barriers:\n if tpe:\n if pos != st and st - pos <= max_jump:\n commands.append('JUMP %s' % (st - pos))\n elif pos != st:\n print('IMPOSSIBLE')\n break\n if en - st:\n commands.append('RUN %s' % (en - st))\n pos = en\n else:\n print('\\n'.join(commands))\n", "passed": true, "time": 0.14, "memory": 14544.0, "status": "done"}, {"code": "n,m,s,d=map(int,input().split())\nx=sorted(map(int,input().split()))+[m+s+1]\ncur=l=0\nans=[]\nwhile l<m:\n r=min(x[cur]-1,m)\n ans+=['RUN '+str(r-l)]\n if r==m: break\n if r-l<s: ans=['IMPOSSIBLE']; break\n t=x[cur]+1\n while x[cur+1]-1-t<s: cur+=1; t=x[cur]+1\n if t-r>d: ans=['IMPOSSIBLE']; break\n ans+=['JUMP '+str(t-r)]\n l=t;cur+=1\nprint('\\n'.join(ans))", "passed": true, "time": 0.14, "memory": 14456.0, "status": "done"}, {"code": "n, m, s, d=map(int, input().split())\nx = sorted(map(int, input().split())) + [m + s + 1]\ncur = l = 0\nans = []\nwhile l < m:\n r = min(x[cur] - 1, m)\n ans += ['RUN ' + str(r - l)]\n if r == m: break\n if r - l < s: ans = ['IMPOSSIBLE']; break\n t = x[cur] + 1\n while x[cur + 1] - 1 - t < s: cur += 1; t = x[cur] + 1\n if t - r > d: ans = ['IMPOSSIBLE']; break\n ans += ['JUMP ' + str(t - r)]\n l = t;cur += 1\nprint('\\n'.join(ans))", "passed": true, "time": 0.16, "memory": 14464.0, "status": "done"}, {"code": "f = lambda: map(int, input().split())\nn, m, s, d = f()\np, x, z = [], -1, 1\nfor y in sorted(f()) + [m + 1]:\n if y - x > s + 1 or y > m or x < 0:\n u = x - z + 2\n v = y - x - 2\n if u > d or v < s and x < 0:\n p = ['IMPOSSIBLE']\n break\n if u: p += ['JUMP ' + str(u)]\n if v: p += ['RUN ' + str(v)]\n z = y\n x = y\nprint('\\n'.join(p))", "passed": true, "time": 0.14, "memory": 14580.0, "status": "done"}, {"code": "n,m,s,d=list(map(int,input().split()))\nx=sorted(map(int,input().split()))+[m+s+1]\ncur=l=0\nans=[]\nwhile l<m:\n r=min(x[cur]-1,m)\n ans+=['RUN '+str(r-l)]\n if r==m: break\n if r-l<s: ans=['IMPOSSIBLE']; break\n t=x[cur]+1\n while x[cur+1]-1-t<s: cur+=1; t=x[cur]+1\n if t-r>d: ans=['IMPOSSIBLE']; break\n ans+=['JUMP '+str(t-r)]\n l=t;cur+=1\nprint('\\n'.join(ans))\n", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "n,m,s,d=list(map(int,input().split()))\nx=sorted(map(int,input().split()))+[m+s+1]\ncur=l=0\nans=[]\nwhile l<m:\n r=min(x[cur]-1,m)\n ans+=['RUN '+str(r-l)]\n if r==m: break\n if r-l<s: ans=['IMPOSSIBLE']; break\n t=x[cur]+1\n while x[cur+1]-1-t<s: cur+=1; t=x[cur]+1\n if t-r>d: ans=['IMPOSSIBLE']; break\n ans+=['JUMP '+str(t-r)]\n l=t;cur+=1\nprint('\\n'.join(ans))\n", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}, {"code": "n, m ,s, d = [int(i) for i in input().split()] # m is the end point\n# s is length of run, d is the max jump distance\nA = [-1] + sorted([int(i) for i in input().split()]) + [m+1]\nans_size = 2 * 10**5\nans = [0 for i in range(4*ans_size)]\n\n# use 0 to indicate run an 1 to indicate jump\n\ndef obstacle():\n run = -1\n jump = -1\n top = 0 # flag where are we at the dp\n for i in range(1,n+1):\n if s + 2 <= A[i] - A[i-1]:\n if jump != -1:\n if A[i-1] + 1 - jump <= d and top > 0 and ans[top-1][0] == 0 and ans[top-1][1] >= s:\n ans[top] = (1, A[i-1]+1-jump)\n top += 1\n else:\n print(\"IMPOSSIBLE\")\n return\n ans[top] = (0, A[i] - A[i-1]-2) # run\n top += 1\n jump = A[i] - 1 # jumping point\n if A[n] + 1 - jump <= d and top > 0 and ans[top-1][0] == 0 and ans[top-1][1] >= s:\n ans[top] = (1, A[n]+1 - jump)\n top += 1\n else:\n print(\"IMPOSSIBLE\")\n return\n if m != A[n] + 1:\n ans[top] = (0, m-A[n]-1)\n top += 1\n for i in range(top):\n if ans[i][0]:\n print(\"JUMP\", ans[i][1])\n else:\n print(\"RUN\", ans[i][1])\nobstacle()\n", "passed": true, "time": 1.45, "memory": 20452.0, "status": "done"}, {"code": "n, m, s, d = list(map(int, input().split()))\na = list(map(int, input().split()))\na.sort()\npoints = [0, a[0] - 1]\nif d == 1 or a[0] - 1 < s:\n print(\"IMPOSSIBLE\")\n return\nfor i in range(0, n):\n if a[i] - a[i - 1] - 2 < s:\n if a[i] + 1 - points[-1] > d:\n print(\"IMPOSSIBLE\")\n return\n else:\n points.append(a[i - 1] + 1)\n points.append(a[i] - 1)\n\npoints.append(a[-1] + 1)\nfor i in range(1, len(points)):\n if i % 2 == 1:\n print(\"RUN\", points[i] - points[i - 1])\n else:\n print(\"JUMP\", points[i] - points[i - 1])\nif a[-1] + 1 != m:\n print(\"RUN\", m - 1 - a[-1])\n", "passed": true, "time": 0.14, "memory": 14548.0, "status": "done"}] | [{"input": "3 10 1 3\n3 4 7\n", "output": "RUN 2\nJUMP 3\nRUN 1\nJUMP 2\nRUN 2\n"}, {"input": "2 9 2 3\n6 4\n", "output": "IMPOSSIBLE\n"}, {"input": "10 100 2 8\n93 35 24 87 39 46 86 37 73 33\n", "output": "RUN 23\nJUMP 2\nRUN 7\nJUMP 8\nRUN 5\nJUMP 2\nRUN 25\nJUMP 2\nRUN 11\nJUMP 3\nRUN 4\nJUMP 2\nRUN 6\n"}, {"input": "10 1000000000 8905990 20319560\n233244997 997992814 242452779 497363176 572234096 126615858 886769539 662035052 989086824 716655858\n", "output": "RUN 126615857\nJUMP 2\nRUN 106629137\nJUMP 2\nRUN 9207780\nJUMP 2\nRUN 254910395\nJUMP 2\nRUN 74870918\nJUMP 2\nRUN 89800954\nJUMP 2\nRUN 54620804\nJUMP 2\nRUN 170113679\nJUMP 2\nRUN 102317283\nJUMP 8905992\nRUN 2007185\n"}, {"input": "100 1000 1 4\n228 420 360 642 442 551 940 343 24 83 928 110 663 548 704 461 942 799 283 746 371 204 435 209 986 489 918 526 496 321 233 643 208 717 806 18 291 431 521 631 3 450 711 602 401 60 680 930 625 891 161 279 510 529 546 338 473 925 446 786 384 952 260 649 865 916 789 71 103 997 484 89 408 129 953 670 568 55 287 511 369 225 950 539 652 567 730 499 687 90 779 848 801 606 82 853 967 776 951 329\n", "output": "IMPOSSIBLE\n"}, {"input": "100 600 1 4\n9 536 518 59 229 377 72 203 81 309 304 321 55 439 287 505 3 410 582 351 440 568 584 259 22 415 348 147 404 277 477 323 537 75 548 324 338 198 145 182 271 496 256 329 592 132 291 222 115 587 54 158 154 103 356 15 36 76 402 27 223 551 267 527 51 34 417 573 479 398 425 71 485 20 262 566 467 131 524 352 330 541 146 53 322 436 366 86 88 272 96 456 388 319 149 470 129 162 353 346\n", "output": "IMPOSSIBLE\n"}, {"input": "1 2 1 5\n1\n", "output": "IMPOSSIBLE\n"}, {"input": "1 3 1 2\n2\n", "output": "RUN 1\nJUMP 2\n"}, {"input": "1 5 1 2\n2\n", "output": "RUN 1\nJUMP 2\nRUN 2\n"}, {"input": "1 1000000000 1000000000 2\n999999999\n", "output": "IMPOSSIBLE\n"}, {"input": "1 100 1 1\n4\n", "output": "IMPOSSIBLE\n"}, {"input": "1 1000000000 1 1000000000\n2\n", "output": "RUN 1\nJUMP 2\nRUN 999999997\n"}, {"input": "3 12000 2000 3000\n3000 9002 7001\n", "output": "RUN 2999\nJUMP 2\nRUN 3999\nJUMP 2003\nRUN 2997\n"}, {"input": "4 30000 5000 6000\n6000 16000 15000 21001\n", "output": "IMPOSSIBLE\n"}, {"input": "3 12000 2000 245\n3000 9003 7001\n", "output": "RUN 2999\nJUMP 2\nRUN 3999\nJUMP 2\nRUN 2000\nJUMP 2\nRUN 2996\n"}, {"input": "4 30000 5000 1654\n6000 16000 14999 21002\n", "output": "RUN 5999\nJUMP 2\nRUN 8997\nJUMP 1003\nRUN 5000\nJUMP 2\nRUN 8997\n"}, {"input": "4 10000 500 500\n700 600 1099 2000\n", "output": "IMPOSSIBLE\n"}, {"input": "3 20000 4000 3502\n5000 8500 15000\n", "output": "RUN 4999\nJUMP 3502\nRUN 6498\nJUMP 2\nRUN 4999\n"}, {"input": "4 10000 500 500\n700 601 1099 2000\n", "output": "RUN 600\nJUMP 500\nRUN 899\nJUMP 2\nRUN 7999\n"}, {"input": "3 20000 4000 3502\n5000 8501 15000\n", "output": "IMPOSSIBLE\n"}, {"input": "1 10 1 2\n9\n", "output": "RUN 8\nJUMP 2\n"}, {"input": "1 10 2 9\n5\n", "output": "RUN 4\nJUMP 2\nRUN 4\n"}, {"input": "1 9 6 4\n4\n", "output": "IMPOSSIBLE\n"}, {"input": "1 10 7 4\n5\n", "output": "IMPOSSIBLE\n"}, {"input": "2 14 8 8\n5 9\n", "output": "IMPOSSIBLE\n"}, {"input": "2 23 12 8\n8 16\n", "output": "IMPOSSIBLE\n"}, {"input": "2 14 4 2\n2 7\n", "output": "IMPOSSIBLE\n"}, {"input": "3 21 6 2\n7 11 16\n", "output": "IMPOSSIBLE\n"}, {"input": "3 29 3 4\n7 16 19\n", "output": "IMPOSSIBLE\n"}, {"input": "3 24 2 6\n6 12 17\n", "output": "RUN 5\nJUMP 2\nRUN 4\nJUMP 2\nRUN 3\nJUMP 2\nRUN 6\n"}, {"input": "4 31 12 9\n7 13 21 28\n", "output": "IMPOSSIBLE\n"}, {"input": "4 10 1 7\n2 4 6 8\n", "output": "IMPOSSIBLE\n"}, {"input": "4 36 8 4\n4 13 19 27\n", "output": "IMPOSSIBLE\n"}, {"input": "5 25 10 2\n6 12 13 15 22\n", "output": "IMPOSSIBLE\n"}, {"input": "5 19 7 10\n3 7 9 12 16\n", "output": "IMPOSSIBLE\n"}, {"input": "5 28 6 8\n3 9 15 21 25\n", "output": "IMPOSSIBLE\n"}, {"input": "6 35 12 4\n7 12 17 21 24 28\n", "output": "IMPOSSIBLE\n"}, {"input": "6 22 5 7\n4 6 10 13 15 18\n", "output": "IMPOSSIBLE\n"}, {"input": "6 55 3 5\n10 18 24 34 39 45\n", "output": "RUN 9\nJUMP 2\nRUN 6\nJUMP 2\nRUN 4\nJUMP 2\nRUN 8\nJUMP 2\nRUN 3\nJUMP 2\nRUN 4\nJUMP 2\nRUN 9\n"}, {"input": "7 51 6 1\n8 17 18 23 27 33 42\n", "output": "IMPOSSIBLE\n"}, {"input": "7 36 11 4\n6 11 17 19 22 24 30\n", "output": "IMPOSSIBLE\n"}, {"input": "7 28 10 2\n5 10 14 19 21 23 27\n", "output": "IMPOSSIBLE\n"}, {"input": "8 46 4 5\n3 6 15 21 24 26 36 42\n", "output": "IMPOSSIBLE\n"}, {"input": "8 51 2 1\n6 14 20 26 29 35 40 48\n", "output": "IMPOSSIBLE\n"}, {"input": "8 56 2 9\n7 11 20 28 34 39 40 48\n", "output": "RUN 6\nJUMP 2\nRUN 2\nJUMP 2\nRUN 7\nJUMP 2\nRUN 6\nJUMP 2\nRUN 4\nJUMP 2\nRUN 3\nJUMP 3\nRUN 6\nJUMP 2\nRUN 7\n"}, {"input": "9 57 2 2\n5 11 15 21 24 30 36 43 50\n", "output": "IMPOSSIBLE\n"}, {"input": "9 82 14 4\n10 18 28 38 46 55 64 74 79\n", "output": "IMPOSSIBLE\n"}, {"input": "9 40 6 3\n5 10 14 18 22 27 30 31 36\n", "output": "IMPOSSIBLE\n"}, {"input": "10 44 6 2\n4 8 13 19 23 29 32 33 37 41\n", "output": "IMPOSSIBLE\n"}, {"input": "10 42 1 3\n1 6 10 15 17 22 24 29 33 38\n", "output": "IMPOSSIBLE\n"}, {"input": "10 82 2 5\n9 17 27 37 44 51 57 62 67 72\n", "output": "RUN 8\nJUMP 2\nRUN 6\nJUMP 2\nRUN 8\nJUMP 2\nRUN 8\nJUMP 2\nRUN 5\nJUMP 2\nRUN 5\nJUMP 2\nRUN 4\nJUMP 2\nRUN 3\nJUMP 2\nRUN 3\nJUMP 2\nRUN 3\nJUMP 2\nRUN 9\n"}, {"input": "11 69 4 9\n7 14 20 26 29 35 40 46 52 58 64\n", "output": "RUN 6\nJUMP 2\nRUN 5\nJUMP 2\nRUN 4\nJUMP 2\nRUN 4\nJUMP 5\nRUN 4\nJUMP 7\nRUN 4\nJUMP 2\nRUN 4\nJUMP 2\nRUN 4\nJUMP 2\nRUN 4\nJUMP 2\nRUN 4\n"}, {"input": "11 65 1 7\n7 11 14 21 24 30 37 44 50 56 59\n", "output": "RUN 6\nJUMP 2\nRUN 2\nJUMP 2\nRUN 1\nJUMP 2\nRUN 5\nJUMP 2\nRUN 1\nJUMP 2\nRUN 4\nJUMP 2\nRUN 5\nJUMP 2\nRUN 5\nJUMP 2\nRUN 4\nJUMP 2\nRUN 4\nJUMP 2\nRUN 1\nJUMP 2\nRUN 5\n"}, {"input": "11 77 10 10\n7 14 17 24 29 34 38 47 56 64 69\n", "output": "IMPOSSIBLE\n"}, {"input": "12 78 3 1\n4 11 19 22 30 38 43 51 56 59 67 73\n", "output": "IMPOSSIBLE\n"}, {"input": "12 89 14 9\n6 11 18 24 33 37 45 51 60 69 71 80\n", "output": "IMPOSSIBLE\n"}, {"input": "12 13 6 7\n1 2 3 4 5 6 7 8 9 10 11 12\n", "output": "IMPOSSIBLE\n"}, {"input": "13 91 1 3\n5 12 17 22 29 36 43 49 57 64 70 74 84\n", "output": "RUN 4\nJUMP 2\nRUN 5\nJUMP 2\nRUN 3\nJUMP 2\nRUN 3\nJUMP 2\nRUN 5\nJUMP 2\nRUN 5\nJUMP 2\nRUN 5\nJUMP 2\nRUN 4\nJUMP 2\nRUN 6\nJUMP 2\nRUN 5\nJUMP 2\nRUN 4\nJUMP 2\nRUN 2\nJUMP 2\nRUN 8\nJUMP 2\nRUN 6\n"}, {"input": "13 87 5 6\n7 10 18 24 31 40 41 48 54 63 69 78 81\n", "output": "IMPOSSIBLE\n"}, {"input": "13 46 2 4\n1 4 9 13 15 19 21 23 25 30 35 37 42\n", "output": "IMPOSSIBLE\n"}, {"input": "14 93 1 1\n8 15 19 21 28 36 44 51 56 63 67 74 79 85\n", "output": "IMPOSSIBLE\n"}, {"input": "14 62 11 4\n5 10 15 18 22 26 31 34 39 42 44 47 52 57\n", "output": "IMPOSSIBLE\n"}, {"input": "14 109 10 1\n8 15 25 29 38 48 57 65 70 79 81 89 94 100\n", "output": "IMPOSSIBLE\n"}, {"input": "15 97 4 4\n3 7 13 23 29 35 39 45 49 50 60 68 72 81 87\n", "output": "IMPOSSIBLE\n"}, {"input": "15 77 4 8\n7 14 16 20 26 33 36 43 44 48 52 59 61 66 70\n", "output": "IMPOSSIBLE\n"}, {"input": "15 56 1 5\n5 10 15 20 21 25 29 31 34 37 38 41 43 47 52\n", "output": "RUN 4\nJUMP 2\nRUN 3\nJUMP 2\nRUN 3\nJUMP 2\nRUN 3\nJUMP 3\nRUN 2\nJUMP 2\nRUN 2\nJUMP 4\nRUN 1\nJUMP 2\nRUN 1\nJUMP 3\nRUN 1\nJUMP 4\nRUN 2\nJUMP 2\nRUN 3\nJUMP 2\nRUN 3\n"}, {"input": "2 1000000000 1 3\n5 8\n", "output": "RUN 4\nJUMP 2\nRUN 1\nJUMP 2\nRUN 999999991\n"}, {"input": "2 1000000000 1 2\n5 8\n", "output": "RUN 4\nJUMP 2\nRUN 1\nJUMP 2\nRUN 999999991\n"}, {"input": "2 1000000000 1 4\n5 8\n", "output": "RUN 4\nJUMP 2\nRUN 1\nJUMP 2\nRUN 999999991\n"}, {"input": "2 1000000000 2 4\n5 8\n", "output": "IMPOSSIBLE\n"}, {"input": "2 1000000000 2 5\n5 8\n", "output": "RUN 4\nJUMP 5\nRUN 999999991\n"}] |
|
220 | Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)?
-----Input-----
The first line of the input contains two integers s and x (2 ≤ s ≤ 10^12, 0 ≤ x ≤ 10^12), the sum and bitwise xor of the pair of positive integers, respectively.
-----Output-----
Print a single integer, the number of solutions to the given conditions. If no solutions exist, print 0.
-----Examples-----
Input
9 5
Output
4
Input
3 3
Output
2
Input
5 2
Output
0
-----Note-----
In the first sample, we have the following solutions: (2, 7), (3, 6), (6, 3), (7, 2).
In the second sample, the only solutions are (1, 2) and (2, 1). | interview | [{"code": "s, x = list(map(int, input().split()))\nrem = int(s == x) * 2\np, t, cur = [], 0, 1\nfor i in range(64):\n if x % 2:\n t += 1\n s -= cur\n else:\n p.append(cur * 2)\n cur *= 2\n x //= 2\nfor i in p[::-1]:\n if s >= i: s -= i\nans = 0 if s else 2 ** t - rem\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "def o(s,x):\n d=s-x\n if x<<1 & d or d%2 or d<0: return 0\n return 2**(bin(x).count('1'))-(0 if d else 2)\ns,x=map(int,input().split())\nprint(o(s,x))", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}, {"code": "s, x = list(map(int, input().split(' ')))\nif (s-x)%2 or s < x:\n print(0)\nelse:\n c = bin((s-x)//2)[2:][::-1]\n t = bin(x)[2:][::-1]\n for i in range(len(t)):\n if t[i] == '1' and i < len(c) and c[i] == '1':\n print(0)\n return\n print(pow(2, bin(x)[2:].count('1'))-(2 if s==x else 0))\n", "passed": true, "time": 0.18, "memory": 14392.0, "status": "done"}, {"code": "def main():\n s, x = list(map(int, input().split()))\n if s < x:\n print(0)\n return\n s, x = ([c == '1' for c in bin(int(_))[2:]] for _ in (s, x))\n x = [False] * (len(s) - len(x)) + x\n a, b = [False] * len(s), [False] * len(s)\n\n def deeper(idx, carry):\n if idx:\n idx -= 1\n if carry:\n if s[idx] == x[idx]:\n return\n if s[idx]:\n deeper(idx, False)\n a[idx] = True\n b[idx] = True\n deeper(idx, True)\n a[idx] = False\n b[idx] = False\n else:\n b[idx] = True\n deeper(idx, True)\n b[idx] = False\n else:\n if s[idx] != x[idx]:\n return\n if s[idx]:\n b[idx] = True\n deeper(idx, False)\n b[idx] = False\n else:\n a[idx] = True\n b[idx] = True\n deeper(idx, True)\n a[idx] = False\n b[idx] = False\n deeper(idx, False)\n else:\n raise TabError\n\n try:\n deeper(len(s), False)\n except TabError:\n print((1 << (sum(b) - sum(a))) - (0 if any(a)else 2))\n else:\n print(0)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 1.72, "memory": 14664.0, "status": "done"}, {"code": "'__author__'=='deepak Singh Mehta(learning brute force)) '\n\n\ndef __starting_point():\n s, x = list(map(int, input().split(' ')))\n if (s-x)%2 or s < x:\n print(0)\n else:\n c = bin((s-x)//2)[2:][::-1]\n t = bin(x)[2:][::-1]\n for i in range(len(t)):\n if t[i] == '1' and i < len(c) and c[i] == '1':\n print(0)\n return\n print(pow(2, bin(x)[2:].count('1'))-(2 if s==x else 0))\n\n__starting_point()", "passed": true, "time": 0.96, "memory": 14340.0, "status": "done"}, {"code": "'''\nCreated on Apr 20, 2016\nGmail : [email protected]\n@author: Md. Rezwanul Haque\n'''\ndef func(s,x):\n if x==0 and s%2==0:\n return 1\n if s==0:\n return 0\n if (s%2==1 and x%2==1):\n return 2*func(s//2, x//2)\n if (s%2==1 and x%2==0):\n return 0\n if (s%2== 0 and x%2==1):\n return 0\n if s%2==0 and x%2==0:\n return func(s//2 - 1, x//2) + func(s//2, x//2)\n \ns,x = list(map(int,input().split()))\ncnt = func(s, x)\nif s^0 == x:\n cnt = cnt - 2;\nprint(cnt)\n \n", "passed": true, "time": 0.15, "memory": 14488.0, "status": "done"}, {"code": "def digits(n):\n d = []\n while n:\n d.append(n%2)\n n //= 2\n return d\ns, x = map(int, input().split())\n#for i in range(s+1):\n# if i^(s-i) == x:\n# print(i, s-i)\nflag = True\nif s-x < 0 or (s-x)%2 == 1:\n print(0)\nelse:\n a = (s-x) >> 1\n AND = digits(a)\n XOR = digits(x)\n for i in range(max(len(AND), len(XOR))):# comparing from reverse\n if i < len(XOR):\n xi = XOR[i]\n else:\n xi = 0\n if i < len(AND):\n ai = AND[i]\n else:\n ai = 0\n if xi == 1 and ai != 0:\n print(0)\n flag = False\n break\n if flag:\n data = XOR.count(1)\n ans = 2**data\n if a == 0:\n ans -= 2\n print(ans)", "passed": true, "time": 0.14, "memory": 14508.0, "status": "done"}, {"code": "s, x = map(int, input().split())\nprint(0 if s < x or (s - x) & (2 * x + 1) else 2 ** bin(x).count('1') - 2 * (s == x))", "passed": true, "time": 0.14, "memory": 14464.0, "status": "done"}, {"code": "s, x = list(map(int, input().split()))\nprint(0 if s < x or (s - x) & (2 * x + 1) else 2 ** bin(x).count('1') - 2 * (s == x))\n", "passed": true, "time": 1.76, "memory": 14328.0, "status": "done"}, {"code": "s, x = list(map(int, input().split()))\nprint(0 if s < x or (s - x) & (2 * x + 1) else 2 ** bin(x).count('1') - 2 * (s == x))\n", "passed": true, "time": 0.14, "memory": 14576.0, "status": "done"}, {"code": "s,x=list(map(int,input().split()))\njj=1 if s>=x and (s-x)/2==(s-x)//2 else 0\nxx=bin(x)[2:]\naa=bin((s-x)//2)[2:]\nif len(xx)<len(aa): xx=(len(aa)-len(xx))*'0'+xx\nelse: aa=(len(xx)-len(aa))*'0'+aa\n#print(xx,aa)\nfor i in range(len(xx)):\n if xx[i]=='0': continue\n elif xx[i]=='1':\n if aa[i]=='0':\n jj*=2\n else:\n jj=0\nif (s-x)//2==0 and jj>=2: jj-=2 \nprint(jj) \n\n##//////////////// ////// /////// // /////// // // //\n##//// // /// /// /// /// // /// /// //// //\n##//// //// /// /// /// /// // ///////// //// ///////\n##//// ///// /// /// /// /// // /// /// //// // //\n##////////////// /////////// /////////// ////// /// /// // // // //\n\n\n\n", "passed": true, "time": 1.76, "memory": 14428.0, "status": "done"}, {"code": "import sys\nimport io\n\nstream_enable = 0\n\ninpstream = \"\"\"\n9 5\n\"\"\"\n\nif stream_enable:\n sys.stdin = io.StringIO(inpstream)\n input()\n\ndef inpmap():\n return list(map(int, input().split()))\n\na, b = inpmap()\nif b > a:\n print(0)\n return\nflag = a == b\n# a = bin(a)[2:]\n# b = bin(b)[2:]\n# ln = max(len(a), len(b))\n# if len(a) > len(b):\n# b = \"0\" * (len(a) - len(b)) + b\n# elif len(b) > len(a):\n# a = \"0\" * (len(b) - len(a)) + a\n# ln = len(a)\n# print(a)\n# print(b)\nb = \"0\" * (len(bin(a)) - len(bin(b))) + bin(b)[2:]\n# print(b)\nres = 1\np = 2 ** (len(b) - 1)\nfor x in b:\n if x == '1':\n res *= 2\n a -= p\n elif a >= p * 4 - 1:\n print(0)\n return\n elif a >= p * 2:\n a -= p * 2\n p //= 2\n # print(a)\nif a:\n print(0)\n return\nif flag:\n res -= 2\nprint(res)\n", "passed": true, "time": 0.15, "memory": 14612.0, "status": "done"}, {"code": "s,x=list(map(int,input().split()))\nf=0\nif s==x:\n f=-2\naa=s-x\nif aa%2==1 or aa<0:\n print(0)\nelse:\n a=aa//2\n #print(a,s)\n out=1\n for i in range(64):\n xx=x%2\n aa=a%2\n if xx==1:\n out*=2\n if aa==1:\n out=0\n x//=2\n a//=2\n print(out+f)\n \n \n \n \n", "passed": true, "time": 0.26, "memory": 14348.0, "status": "done"}, {"code": "s, x = list(map(int, input().split()))\n\nprint(0 if s < x or (s - x) & (2 * x + 1) else 2 ** bin(x).count('1') - 2 * (s == x))\n\n\n\n\n# Made By Mostafa_Khaled\n", "passed": true, "time": 0.14, "memory": 14348.0, "status": "done"}, {"code": "s,x=list(map(int,input().split()))\nprint(0 if (s<x or (s-x)%2 or ((s-x)//2)&(x)!=0) else 2**(list(bin(x)).count('1'))-2*(s==x) )\n", "passed": true, "time": 0.14, "memory": 14440.0, "status": "done"}, {"code": "s, x = map(int, input().split())\na, b = 1, 0\nfor i in range(50):\n c, d = s & (1 << i), x & (1 << i)\n # print(i, a, b, c, d)\n if c == d:\n if c:\n a, b = 2 * a, 0\n else:\n a, b = a, a\n else:\n if c:\n a, b = b, b\n else:\n a, b = 0, 2 * b\nif s == x:\n a -= 2\nprint(a)", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "s,x=map(int,input().split())\nb=s-x\nb=list(bin(s-x))\nb=b[2:]\na=list(bin(x))\na=a[2:]\n#print(a)\nal=len(a)\nbl=len(b)\nc=[]\nif(bl>al):\n\tfor i in range(bl-al):\n\t\tc.append('0')\n\tc.extend(a)\n\ta=c\nelse:\n\tfor i in range(al-bl):\n\t\tc.append('0')\n\tc.extend(b)\n\tb=c\np=0\nbl=len(b)\nfor i in range(bl-1):\n\tif(b[i]=='1'):\n\t\tif(a[i+1]=='1'):\n\t\t\t#print(\"hello\")\n\t\t\tp=1\nbl=len(b)\nif(b[bl-1]=='1'):\n\t#print(\"hello\")\n\tp=1\nif(x>s):\n\tprint(\"0\")\nelif(p==1):\n\t#print(\"hhh\")\n\tprint(\"0\")\nelse:\n\tif(s==x):\n\t\tprint(2**(a.count('1'))-2)\n\telif(x==0):\n\t\tprint(\"1\")\n\telse:\n\t\tprint(2**(a.count('1')))", "passed": true, "time": 0.14, "memory": 14632.0, "status": "done"}, {"code": "suma,xor=list(map(int,input().split()))\nmitad=round((suma-xor)/2)\nif(mitad<0 or mitad*2+xor!=suma or (mitad&xor)!=0):\n print(0)\nelse:\n print(2**(bin(xor).count(\"1\"))-2*(suma==xor))\n", "passed": true, "time": 0.15, "memory": 14304.0, "status": "done"}, {"code": "from sys import stdin,stdout\nr,w = stdin.readline,stdout.write\ns,x = map(int,r().split());andShft = s-x\nw('%i\\n' %(0 if andShft&1 or s<x or x&(andShft>>1) else 2**(f'{x:b}'.count('1')) - (2 if s == x else 0)))", "passed": true, "time": 0.14, "memory": 14536.0, "status": "done"}, {"code": "from sys import stdin,stdout\nr,w = stdin.readline,stdout.write\ns,x = map(int,r().split());andShft = s-x\nw('%i\\n' %(0 if andShft&1 or s<x or x&(andShft>>1) else 2**(f'{x:b}'.count('1')) - (2 if s == x else 0)))", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "R = lambda: map(int, input().split())\ns, x = R()\nif s < x or (s - x) & 1:\n print(0)\n return\nu, d = (s - x) // 2, x\nres = 1\nwhile u or d:\n uu, dd = u & 1, d & 1\n if uu and dd:\n res *= 0\n elif uu == 0 and dd == 1:\n res *= 2\n u, d = u >> 1, d >> 1\nif s == x:\n res = max(0, res - 2)\nprint(res)", "passed": true, "time": 0.15, "memory": 14568.0, "status": "done"}, {"code": "from sys import stdin,stdout\nr,w = stdin.readline,stdout.write\ns,x = map(int,r().split());andShft = s-x\nw('%i\\n' %(0 if andShft&1 or s<x or x&(andShft>>1) else 2**(f'{x:b}'.count('1')) - (2 if s == x else 0)))", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}, {"code": "s, x = map(int, input().split())\nif s < x:\n\tprint(0)\n\treturn\nf = x\nif (s - x) % 2 == 1:\n\tprint(0)\n\treturn\nx = bin(x)[2::]\ny = (s - f) // 2\ny = bin(y)\ny = y[2:]\nif len(x) > len(y):\n\ty = \"0\" * (len(x) - len(y)) + y\nelse:\n\tx = \"0\" * (len(y) - len(x)) + x\nk = 0\nfor i in range(len(x)):\n\tif x[i] == \"1\":\n\t\tk += 1\n\tif int(x[i]) + int(y[i]) == 2:\n\t\tprint(0)\n\t\treturn\nif s == f:\n\tprint(2 ** k - 2)\n\treturn\nprint(2 ** k)", "passed": true, "time": 0.22, "memory": 14416.0, "status": "done"}, {"code": "s, x = list(map(int, input().split()))\nprint(((s-x)&(x+x+1)==0 and x <= s) * (2 ** bin(x).count('1') - 2 * (s == x)))\n", "passed": true, "time": 0.15, "memory": 14616.0, "status": "done"}, {"code": "def codechef(s,x):\n #cook your dish here\n flag = 0\n a = (s-x)//2\n if (s-x)/2 != a:\n print(0)\n return\n if s == x:\n flag = 1\n \n if a < 0:\n print(0)\n return\n a = str(bin(a))\n x = str(bin(x))\n a = a[2:]\n x = x[2:]\n l = (len(a)-len(x))\n if l>0:\n x = (\"0\"*l)+x\n else:\n a = (\"0\"*(-l))+a\n res = 1\n for i in range(len(a)):\n if x[i]==\"1\" and a[i]==\"0\":\n res *= 2\n elif x[i]==\"1\" and a[i]==\"1\":\n print(0)\n return\n if flag:\n res -= 2\n \n \n print(res)\n\n \n \n \n\ndef __starting_point():\n \n s,x = list(map(int, input().split()))\n codechef(s,x)\n \n \n \n \n \n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}] | [{"input": "9 5\n", "output": "4\n"}, {"input": "3 3\n", "output": "2\n"}, {"input": "5 2\n", "output": "0\n"}, {"input": "6 0\n", "output": "1\n"}, {"input": "549755813887 549755813887\n", "output": "549755813886\n"}, {"input": "2 0\n", "output": "1\n"}, {"input": "2 2\n", "output": "0\n"}, {"input": "433864631347 597596794426\n", "output": "0\n"}, {"input": "80 12\n", "output": "4\n"}, {"input": "549755813888 549755813886\n", "output": "274877906944\n"}, {"input": "643057379466 24429729346\n", "output": "2048\n"}, {"input": "735465350041 356516240229\n", "output": "32768\n"}, {"input": "608032203317 318063018433\n", "output": "4096\n"}, {"input": "185407964720 148793115916\n", "output": "16384\n"}, {"input": "322414792152 285840263184\n", "output": "4096\n"}, {"input": "547616456703 547599679487\n", "output": "68719476736\n"}, {"input": "274861129991 274861129463\n", "output": "34359738368\n"}, {"input": "549688705887 549688703839\n", "output": "34359738368\n"}, {"input": "412182675455 412182609919\n", "output": "68719476736\n"}, {"input": "552972910589 546530328573\n", "output": "17179869184\n"}, {"input": "274869346299 274869346299\n", "output": "8589934590\n"}, {"input": "341374319077 341374319077\n", "output": "134217726\n"}, {"input": "232040172650 232040172650\n", "output": "65534\n"}, {"input": "322373798090 322373798090\n", "output": "1048574\n"}, {"input": "18436 18436\n", "output": "6\n"}, {"input": "137707749376 137707749376\n", "output": "30\n"}, {"input": "9126813696 9126813696\n", "output": "6\n"}, {"input": "419432708 419432708\n", "output": "62\n"}, {"input": "1839714 248080\n", "output": "128\n"}, {"input": "497110 38\n", "output": "8\n"}, {"input": "1420572 139928\n", "output": "64\n"}, {"input": "583545 583545\n", "output": "4094\n"}, {"input": "33411 33411\n", "output": "30\n"}, {"input": "66068 66068\n", "output": "14\n"}, {"input": "320 320\n", "output": "2\n"}, {"input": "1530587 566563\n", "output": "256\n"}, {"input": "1988518 108632\n", "output": "128\n"}, {"input": "915425594051 155160267299\n", "output": "0\n"}, {"input": "176901202458 21535662096\n", "output": "0\n"}, {"input": "865893190664 224852444148\n", "output": "32768\n"}, {"input": "297044970199 121204864\n", "output": "0\n"}, {"input": "241173201018 236676464482\n", "output": "0\n"}, {"input": "1582116 139808\n", "output": "0\n"}, {"input": "1707011 656387\n", "output": "0\n"}, {"input": "169616 132704\n", "output": "32\n"}, {"input": "2160101 553812\n", "output": "0\n"}, {"input": "1322568 271816\n", "output": "0\n"}, {"input": "228503520839 471917524248\n", "output": "0\n"}, {"input": "32576550340 504864993495\n", "output": "0\n"}, {"input": "910648542843 537125462055\n", "output": "0\n"}, {"input": "751720572344 569387893618\n", "output": "0\n"}, {"input": "629791564846 602334362179\n", "output": "0\n"}, {"input": "1000000000000 1000000000000\n", "output": "8190\n"}, {"input": "1000000000000 999999999999\n", "output": "0\n"}, {"input": "1000000000000 4\n", "output": "0\n"}, {"input": "1000000000000 4096\n", "output": "2\n"}, {"input": "3 1\n", "output": "0\n"}, {"input": "2097152 0\n", "output": "1\n"}, {"input": "40 390\n", "output": "0\n"}, {"input": "22212 39957\n", "output": "0\n"}, {"input": "128 36\n", "output": "0\n"}, {"input": "14 4\n", "output": "0\n"}, {"input": "6 2\n", "output": "0\n"}, {"input": "43 18467\n", "output": "0\n"}, {"input": "7 1\n", "output": "0\n"}, {"input": "7 5\n", "output": "0\n"}, {"input": "251059 79687\n", "output": "0\n"}, {"input": "17 7\n", "output": "0\n"}, {"input": "4 6\n", "output": "0\n"}, {"input": "2 4\n", "output": "0\n"}, {"input": "3 7\n", "output": "0\n"}] |
|
222 | You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect).
In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.
Determine the minimum number of operations that you need to consistently apply to the given integer $n$ to make from it the square of some positive integer or report that it is impossible.
An integer $x$ is the square of some positive integer if and only if $x=y^2$ for some positive integer $y$.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{9}$). The number is given without leading zeroes.
-----Output-----
If it is impossible to make the square of some positive integer from $n$, print -1. In the other case, print the minimal number of operations required to do it.
-----Examples-----
Input
8314
Output
2
Input
625
Output
0
Input
333
Output
-1
-----Note-----
In the first example we should delete from $8314$ the digits $3$ and $4$. After that $8314$ become equals to $81$, which is the square of the integer $9$.
In the second example the given $625$ is the square of the integer $25$, so you should not delete anything.
In the third example it is impossible to make the square from $333$, so the answer is -1. | interview | [{"code": "ar=[]\nfor i in range(1,10**5):\n if(i*i>2*10**9):break\n ar.append(i*i)\ns=input()\nans=len(s)\nfor x in ar:\n s2=str(x)\n i=0\n for x in range(len(s)):\n if i<len(s2) and s[x]==s2[i]:\n i+=1\n if(i==len(s2)):\n ans=min(ans,len(s)-i)\nif(ans==len(s)):\n print(-1)\nelse:\n print(ans)", "passed": true, "time": 4.64, "memory": 14632.0, "status": "done"}, {"code": "def main():\n squares = set(str(x * x) for x in range(100000))\n s = input()\n n = len(s)\n ans = float('inf')\n for mask in range(1, (1 << n)):\n o = ''.join([s[i] for i in range(n) if mask & (1 << i) > 0])\n if o[0] == '0':\n continue\n if o in squares:\n pc = bin(mask).count('1')\n ans = min(ans, n - pc)\n\n if ans == float('inf'):\n ans = -1\n print(ans)\n\nmain()\n", "passed": true, "time": 2.32, "memory": 26364.0, "status": "done"}, {"code": "n = input()\nl = len(n)\nres = 1000000\nfor x in range(1, 2 ** l):\n g = x\n s = ''\n i = 0\n while g:\n if g % 2:\n s += n[i]\n g //= 2\n i += 1\n if s.startswith('0'):\n continue\n h = int(s)\n sq = h ** 0.5\n if sq == int(sq):\n res = min(res, l - len(s))\nprint(res if res != 1000000 else -1)\n", "passed": true, "time": 0.21, "memory": 14392.0, "status": "done"}, {"code": "n = input()\nk = len(n)\nans = 100\nfor i in range(2 ** k):\n s = bin(i)[2:]\n s = '0' * (k - len(s)) + s\n sq = ''\n for j in range(k):\n if s[j] == '1':\n sq += n[j]\n if sq == '' or sq[0] == '0':\n continue\n sq = int(sq)\n l = 0\n r = 1000000\n while r - l > 1:\n c = (r + l) // 2\n if c * c > sq:\n r = c\n else:\n l = c\n if l * l == sq:\n ans = min(ans, s.count('0'))\nif ans == 100:\n print(-1)\nelse:\n print(ans)\n", "passed": true, "time": 0.26, "memory": 14372.0, "status": "done"}, {"code": "def is_sqr(x):\n y = 1\n while y**2 < x:\n y += 1\n return y**2 == x\n\nfrom itertools import combinations\nn = input()\nans = 100\nfor r in range(1, len(n) + 1):\n for item in combinations(n, r):\n #print(int(''.join(item)))\n if is_sqr(int(''.join(item))) and item[0] != '0':\n ans = min(ans, len(n) - len(item))\nprint(ans if ans != 100 else -1)\n", "passed": true, "time": 6.37, "memory": 14560.0, "status": "done"}, {"code": "def valid_int(n):\n return int(round(n ** 0.5)) ** 2 == n\n\ndef valid(s):\n return valid_int(int(s))\n\ndef no_start_zero(s):\n return s[0] != '0'\n\nn = input()\n\ndef adj(s):\n if len(s) <= 1: return []\n for i in range(len(s)):\n ss = s[:i] + s[i+1:]\n if no_start_zero(ss):\n yield ss\n\nq = [n]\nseen = set()\n\nwhile q:\n node = q.pop(0)\n if valid(node):\n print(len(n) - len(node))\n return\n for child in adj(node):\n if child not in seen:\n seen.add(child)\n q.append(child)\nprint(-1)", "passed": true, "time": 0.18, "memory": 14460.0, "status": "done"}, {"code": "def check(t, s):\n cur_t = 0\n for j in range(len(s)):\n while cur_t < len(t) and t[cur_t] != s[j]:\n cur_t += 1\n if cur_t == len(t):\n return False\n cur_t += 1\n return True\n\n\ns1 = input()\nfor i in range(45 * 1000, 0, -1):\n s2 = str(i * i)\n if check(s1, s2):\n print(len(s1) - len(s2))\n return\nprint(-1)", "passed": true, "time": 3.69, "memory": 14304.0, "status": "done"}, {"code": "import sys\nimport math\nfrom functools import lru_cache\n \n@lru_cache(maxsize = None)\ndef solution(nstr, nint, acc):\n msf = float('inf')\n if (math.sqrt(nint) - int(math.sqrt(nint))) == 0.0:\n return acc\n for i in range(len(nstr)):\n mstr = nstr[:i] + nstr[i+1:]\n if mstr:\n if mstr[0] == '0':\n continue\n msf = min(msf, solution(mstr,int(mstr),acc+1))\n if msf == float('inf'):\n return float('inf')\n return msf\n\nn = sys.stdin.readline().strip()\n\nres = solution(n, int(n) ,0)\nif res == float('inf'):\n print(-1)\nelse:\n print(res)", "passed": true, "time": 0.2, "memory": 14440.0, "status": "done"}, {"code": "def lcs(X , Y):\n # find the length of the strings\n m = len(X)\n n = len(Y)\n \n # declaring the array for storing the dp values\n L = [[None]*(n+1) for i in range(m+1)]\n\n for i in range(m+1):\n for j in range(n+1):\n if i == 0 or j == 0 :\n L[i][j] = 0\n elif X[i-1] == Y[j-1]:\n L[i][j] = L[i-1][j-1]+1\n else:\n L[i][j] = max(L[i-1][j] , L[i][j-1])\n \n # L[m][n] contains the length of LCS of X[0..n-1] & Y[0..m-1]\n return L[m][n]\nx=input()\nimport math\nans=0\nfor i in range(int(math.sqrt(int(x))),0,-1):\n if(lcs(x,str(i*i))==len(str(i*i))):\n ans=len(str(i*i))\n break\nif(ans):\n print(len(x)-ans)\nelse:\n print(-1)\n\n\n\n\n\n", "passed": true, "time": 35.83, "memory": 14492.0, "status": "done"}, {"code": "n=input()\nps=[]\nfor i in range(44722):\n ps.append(str(i*i))\nans=20\nfor i in range(1,44722):\n k=0\n l=len(ps[i])\n for j in n:\n if j==ps[i][k]:\n k+=1\n if k==l:\n break\n if k==l:\n ans=min(ans,len(n)-l)\nif ans==20:\n ans=-1\nprint(ans)\n", "passed": true, "time": 2.67, "memory": 16640.0, "status": "done"}, {"code": "n = input()\na=[]\nfor i in range(1,int((2*10**9)**0.5)+1):\n a.append(i**2)\nm = float('inf')\nl = len(n)\nfor i in range(1,2**len(n)):\n bi = bin(i)[2:]\n bi = '0'*(l-len(bi))+bi\n ne = ''\n for i in range(l):\n if bi[i] == '1':\n ne += n[i]\n if ne[0] == '0':continue\n else:\n if int(ne) in a:\n m = min(m,bi.count('0'))\nif m == float('inf'):print(-1)\nelse:print(m)\n", "passed": true, "time": 10.32, "memory": 14976.0, "status": "done"}, {"code": "n=input()\nle=len(n)\nm=le\nfor i in range(1,2**le):\n i=bin(i)[2:]\n s=''\n c=le\n for j in range(len(i)):\n if i[-1-j]=='1':\n s=n[le-1-j]+s\n c-=1\n if s[0]=='0':\n continue\n s=int(s)\n if int(s**(1/2))**2==s:\n m=min(m,c)\nif m==le:\n print(-1)\nelse:\n print(m)\n", "passed": true, "time": 0.21, "memory": 14580.0, "status": "done"}, {"code": "import math\n\ndef read_data():\n n = int(input().strip())\n return n\n\ndef compare(s):\n mpos = 0\n spos = 0\n count = 0\n while spos < len(s):\n npos = m.find(s[spos],mpos)\n if npos == -1:\n return -1\n count += npos - mpos\n mpos = npos + 1\n spos += 1\n count += len(m) - mpos\n return count\n\ndef solve():\n start = int(math.sqrt(n))\n for i in range(start,0,-1):\n c = compare(str(i*i))\n if c > -1:\n return c\n return -1\n\nn = read_data()\nm = str(n)\nprint(solve())", "passed": true, "time": 0.91, "memory": 14492.0, "status": "done"}, {"code": "def is_perfect_square(n):\n return round(n ** 0.5) ** 2 == n\n\n\nfrom itertools import combinations\ns = input()\nls = len(s)\nsl = [i for i in s]\nx = []\nfor i in range(1,len(s)+1):\n comb = combinations(sl,i)\n for j in list(comb):\n x.append(list(j))\ny = []\nfor i in x:\n a = ''\n for j in i:\n a+=j\n y.append(int(a))\ny = list(set(y))\ny.sort(reverse=True)\n#print(y)\nf = 0\nfor i in y:\n if(i!=0):\n if is_perfect_square(i):\n #print(i)\n f = 1\n break\nif(f):\n print(ls-len(str(i)))\nelse:\n print(-1)", "passed": true, "time": 0.17, "memory": 14576.0, "status": "done"}, {"code": "n = int(input())\n\ns = str(n)\nlst = []\nt = set()\ndef xxx(string):\n if string[0] == '0':\n return\n x = int(string)\n \n \n if x in t:\n return\n t.add(x)\n \n k1 = 0\n k2 = 10 ** 6\n while k2 - k1 != 1:\n k = (k1 + k2) // 2\n if k ** 2 <= x:\n k1 = k\n else:\n k2 = k\n if k1 ** 2 == x:\n lst.append(len(str(x)))\n\n if len(string) == 1:\n return\n for x in range(len(string)):\n xxx(string[:x] + string[x + 1:])\n return\n\nxxx(s)\nif len(lst) == 0:\n print(-1)\nelse:\n print(len(s) - max(lst))\n", "passed": true, "time": 0.3, "memory": 14580.0, "status": "done"}, {"code": "from math import sqrt, floor\n\nn = input()\n\ndef is_square(n):\n f = floor(sqrt(n))\n return f*f == n or (f+1)*(f+1) == n\n\n\ndef min_to_square(d, n):\n if len(n) == 1:\n return d if is_square(int(n)) else 100\n\n if n[0] == '0':\n return 100\n\n if (n[0] != '0' and is_square(int(n))) or n == '0':\n return d\n\n m = min([min_to_square(d + 1, n[:i] + n[i + 1:]) for i in range(len(n))])\n\n return m\n\ndef mts(n):\n min_ = 100\n\n for i in range(1, 2**(len(n))):\n s = \"{0:b}\".format(i).zfill(len(n))\n\n newn = ''.join([n[i] for i in range(len(n)) if s[i] == '1'])\n\n if is_square(int(newn)) and newn[0] != '0':\n min_ = min(min_, sum(1 for c in s if c == '0'))\n\n return min_\n\n\nprint(mts(n) if mts(n) < 100 else -1)", "passed": true, "time": 0.25, "memory": 14580.0, "status": "done"}, {"code": "import math\n\n\ndef nop(a, b):\n l = 0\n for i in range(len(a)):\n d = a[i]\n while l < len(b) and b[l] != d:\n l += 1\n if l >= len(b) and b[l - 1] != d:\n return 0\n elif l < len(b) and b[l] != d:\n return 0\n l += 1\n if i < len(a) - 1 and l >= len(b):\n return 0\n return 1\n\na = int(input())\nb = int(math.sqrt(a))\nc = []\nk = b\nfor i in range(k):\n if nop(str(b ** 2), str(a)) == 1:\n c.append(len(str(a)) - len(str(b ** 2)))\n b -= 1\nc.sort()\nif len(c) > 0:\n print(c[0])\nelse:\n print(-1)", "passed": true, "time": 2.43, "memory": 14508.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nfrom math import sqrt\n\nimport itertools\n\ndef issq(k):\n\tk = int(k)\n\treturn k == int(sqrt(k)) ** 2\n\nns = input().strip()\nl = len(ns)\n\ndef getsub(ns, it):\n\treturn ''.join(ns[i] for i in it)\n\ndef findmin(ns):\n\tfor i in range(l, 0, -1):\n\t\tfor it in itertools.combinations(list(range(l)), i):\n\t\t\tits = getsub(ns, it)\n\t\t\tif its.startswith('0'):\n\t\t\t\tcontinue\n\t\t\tif issq(its):\n\t\t\t\treturn l - i\n\treturn -1\n\nprint(findmin(ns))\n", "passed": true, "time": 0.17, "memory": 14532.0, "status": "done"}] | [{"input": "8314\n", "output": "2\n"}, {"input": "625\n", "output": "0\n"}, {"input": "333\n", "output": "-1\n"}, {"input": "1881388645\n", "output": "6\n"}, {"input": "1059472069\n", "output": "3\n"}, {"input": "1354124829\n", "output": "4\n"}, {"input": "149723943\n", "output": "4\n"}, {"input": "101\n", "output": "2\n"}, {"input": "1999967841\n", "output": "0\n"}, {"input": "2000000000\n", "output": "-1\n"}, {"input": "1999431225\n", "output": "0\n"}, {"input": "30\n", "output": "-1\n"}, {"input": "1000\n", "output": "1\n"}, {"input": "3081\n", "output": "2\n"}, {"input": "10\n", "output": "1\n"}, {"input": "2003064\n", "output": "3\n"}, {"input": "701\n", "output": "2\n"}, {"input": "1234567891\n", "output": "4\n"}, {"input": "10625\n", "output": "2\n"}, {"input": "13579\n", "output": "4\n"}, {"input": "1999999999\n", "output": "9\n"}, {"input": "150000\n", "output": "1\n"}, {"input": "8010902\n", "output": "3\n"}, {"input": "20100\n", "output": "2\n"}, {"input": "40404\n", "output": "2\n"}, {"input": "70000729\n", "output": "5\n"}, {"input": "1899933124\n", "output": "5\n"}, {"input": "1999999081\n", "output": "8\n"}, {"input": "326700\n", "output": "2\n"}, {"input": "1\n", "output": "0\n"}, {"input": "1000000990\n", "output": "3\n"}, {"input": "10000\n", "output": "0\n"}, {"input": "100001\n", "output": "1\n"}, {"input": "1410065408\n", "output": "7\n"}, {"input": "1409865409\n", "output": "5\n"}, {"input": "1000050001\n", "output": "3\n"}, {"input": "1044435556\n", "output": "2\n"}, {"input": "520993450\n", "output": "6\n"}, {"input": "131073\n", "output": "5\n"}, {"input": "500040004\n", "output": "6\n"}, {"input": "237555493\n", "output": "7\n"}, {"input": "1120671621\n", "output": "5\n"}, {"input": "298755045\n", "output": "5\n"}, {"input": "1476838469\n", "output": "5\n"}, {"input": "654921893\n", "output": "4\n"}, {"input": "1538038021\n", "output": "4\n"}, {"input": "716121445\n", "output": "6\n"}, {"input": "1894204869\n", "output": "5\n"}, {"input": "1800098866\n", "output": "7\n"}, {"input": "890665277\n", "output": "8\n"}, {"input": "1686264392\n", "output": "6\n"}, {"input": "1336639314\n", "output": "6\n"}, {"input": "132238429\n", "output": "5\n"}, {"input": "927837544\n", "output": "4\n"}, {"input": "18403955\n", "output": "4\n"}, {"input": "1668778878\n", "output": "8\n"}, {"input": "2\n", "output": "-1\n"}, {"input": "3\n", "output": "-1\n"}, {"input": "4\n", "output": "0\n"}, {"input": "5\n", "output": "-1\n"}, {"input": "6\n", "output": "-1\n"}, {"input": "7\n", "output": "-1\n"}, {"input": "8\n", "output": "-1\n"}, {"input": "9\n", "output": "0\n"}, {"input": "11\n", "output": "1\n"}, {"input": "12\n", "output": "1\n"}, {"input": "13\n", "output": "1\n"}, {"input": "14\n", "output": "1\n"}, {"input": "15\n", "output": "1\n"}, {"input": "16\n", "output": "0\n"}] |
|
224 | One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.
Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability. [Image] The picture corresponds to the first example.
The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
-----Input-----
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
-----Output-----
Print single integer a — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
-----Examples-----
Input
ABABBBACFEYUKOTT
Output
4
Input
AAA
Output
1 | interview | [{"code": "import sys\n\nfin = sys.stdin\nfout = sys.stdout\nm = -1\ngl = {'A', 'E', 'I', 'O', 'U', 'Y'}\ns = fin.readline().strip()\ncur = -1\nfor i in range(len(s)):\n if s[i] in gl:\n m = max(m, i - cur)\n cur = i\nm = max(m, len(s) - cur)\nfout.write(str(m))", "passed": true, "time": 0.15, "memory": 14340.0, "status": "done"}] | [{"input": "ABABBBACFEYUKOTT\n", "output": "4"}, {"input": "AAA\n", "output": "1"}, {"input": "A\n", "output": "1"}, {"input": "B\n", "output": "2"}, {"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU\n", "output": "39"}, {"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIAEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOI\n", "output": "1"}, {"input": "KMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVCKMLPTGFHNBVCDRFGHNMBVXWSQFDCVBNHTJKLPMNFVC\n", "output": "85"}, {"input": "QWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZ\n", "output": "18"}, {"input": "PKLKBWTXVJ\n", "output": "11"}, {"input": "CFHFPTGMOKXVLJJZJDQW\n", "output": "12"}, {"input": "TXULTFSBUBFLRNQORMMULWNVLPWTYJXZBPBGAWNX\n", "output": "9"}, {"input": "DAIUSEAUEUYUWEIOOEIOUYVYYOPEEWEBZOOOAOXUOIEUKYYOJOYAUYUUIYUXOUJLGIYEIIYUOCUAACRY\n", "output": "4"}, {"input": "VRPHBNWNWVWBWMFJJDCTJQJDJBKSJRZLVQRVVFLTZFSGCGDXCWQVWWWMFVCQHPKXXVRKTGWGPSMQTPKNDQJHNSKLXPCXDJDQDZZD\n", "output": "101"}, {"input": "SGDDFCDRDWGPNNFBBZZJSPXFYMZKPRXTCHVJSJJBWZXXQMDZBNKDHRGSRLGLRKPMWXNSXJPNJLDPXBSRCQMHJKPZNTPNTZXNPCJC\n", "output": "76"}, {"input": "NVTQVNLGWFDBCBKSDLTBGWBMNQZWZQJWNGVCTCQBGWNTYJRDBPZJHXCXFMIXNRGSTXHQPCHNFQPCMDZWJGLJZWMRRFCVLBKDTDSC\n", "output": "45"}, {"input": "SREZXQFVPQCLRCQGMKXCBRWKYZKWKRMZGXPMKWNMFZTRDPHJFCSXVPPXWKZMZTBFXGNLPLHZIPLFXNRRQFDTLFPKBGCXKTMCFKKT\n", "output": "48"}, {"input": "ICKJKMVPDNZPLKDSLTPZNRLSQSGHQJQQPJJSNHNWVDLJRLZEJSXZDPHYXGGWXHLCTVQSKWNWGTLJMOZVJNZPVXGVPJKHFVZTGCCX\n", "output": "47"}, {"input": "XXFPZDRPXLNHGDVCBDKJMKLGUQZXLLWYLOKFZVGXVNPJWZZZNRMQBRJCZTSDRHSNCVDMHKVXCXPCRBWSJCJWDRDPVZZLCZRTDRYA\n", "output": "65"}, {"input": "HDDRZDKCHHHEDKHZMXQSNQGSGNNSCCPVJFGXGNCEKJMRKSGKAPQWPCWXXWHLSMRGSJWEHWQCSJJSGLQJXGVTBYALWMLKTTJMFPFS\n", "output": "28"}, {"input": "PXVKJHXVDPWGLHWFWMJPMCCNHCKSHCPZXGIHHNMYNFQBUCKJJTXXJGKRNVRTQFDFMLLGPQKFOVNNLTNDIEXSARRJKGSCZKGGJCBW\n", "output": "35"}, {"input": "EXNMTTFPJLDHXDQBJJRDRYBZVFFHUDCHCPNFZWXSMZXNFVJGHZWXVBRQFNUIDVLZOVPXQNVMFNBTJDSCKRLNGXPSADTGCAHCBJKL\n", "output": "30"}, {"input": "NRNLSQQJGIJBCZFTNKJCXMGPARGWXPSHZXOBNSFOLDQVXTVAGJZNLXULHBRDGMNQKQGWMRRDPYCSNFVPUFTFBUBRXVJGNGSPJKLL\n", "output": "19"}, {"input": "SRHOKCHQQMVZKTCVQXJJCFGYFXGMBZSZFNAFETXILZHPGHBWZRZQFMGSEYRUDVMCIQTXTBTSGFTHRRNGNTHHWWHCTDFHSVARMCMB\n", "output": "30"}, {"input": "HBSVZHDKGNIRQUBYKYHUPJCEETGFMVBZJTHYHFQPFBVBSMQACYAVWZXSBGNKWXFNMQJFMSCHJVWBZXZGSNBRUHTHAJKVLEXFBOFB\n", "output": "34"}, {"input": "NXKMUGOPTUQNSRYTKUKSCWCRQSZKKFPYUMDIBJAHJCEKZJVWZAWOLOEFBFXLQDDPNNZKCQHUPBFVDSXSUCVLMZXQROYQYIKPQPWR\n", "output": "17"}, {"input": "TEHJDICFNOLQVQOAREVAGUAWODOCXJXIHYXFAEPEXRHPKEIIRCRIVASKNTVYUYDMUQKSTSSBYCDVZKDDHTSDWJWACPCLYYOXGCLT\n", "output": "15"}, {"input": "LCJJUZZFEIUTMSEXEYNOOAIZMORQDOANAMUCYTFRARDCYHOYOPHGGYUNOGNXUAOYSEMXAZOOOFAVHQUBRNGORSPNQWZJYQQUNPEB\n", "output": "9"}, {"input": "UUOKAOOJBXUTSMOLOOOOSUYYFTAVBNUXYFVOOGCGZYQEOYISIYOUULUAIJUYVVOENJDOCLHOSOHIHDEJOIGZNIXEMEGZACHUAQFW\n", "output": "5"}, {"input": "OUUBEHXOOURMOAIAEHXCUOIYHUJEVAWYRCIIAGDRIPUIPAIUYAIWJEVYEYYUYBYOGVYESUJCFOJNUAHIOOKBUUHEJFEWPOEOUHYA\n", "output": "4"}, {"input": "EMNOYEEUIOUHEWZITIAEZNCJUOUAOQEAUYEIHYUSUYUUUIAEDIOOERAEIRBOJIEVOMECOGAIAIUIYYUWYIHIOWVIJEYUEAFYULSE\n", "output": "5"}, {"input": "BVOYEAYOIEYOREJUYEUOEOYIISYAEOUYAAOIOEOYOOOIEFUAEAAESUOOIIEUAAGAEISIAPYAHOOEYUJHUECGOYEIDAIRTBHOYOYA\n", "output": "5"}, {"input": "GOIEOAYIEYYOOEOAIAEOOUWYEIOTNYAANAYOOXEEOEAVIOIAAIEOIAUIAIAAUEUAOIAEUOUUZYIYAIEUEGOOOOUEIYAEOSYAEYIO\n", "output": "3"}, {"input": "AUEAOAYIAOYYIUIOAULIOEUEYAIEYYIUOEOEIEYRIYAYEYAEIIMMAAEAYAAAAEOUICAUAYOUIAOUIAIUOYEOEEYAEYEYAAEAOYIY\n", "output": "3"}, {"input": "OAIIYEYYAOOEIUOEEIOUOIAEFIOAYETUYIOAAAEYYOYEYOEAUIIUEYAYYIIAOIEEYGYIEAAOOWYAIEYYYIAOUUOAIAYAYYOEUEOY\n", "output": "2"}, {"input": "EEEAOEOEEIOUUUEUEAAOEOIUYJEYAIYIEIYYEAUOIIYIUOOEUCYEOOOYYYIUUAYIAOEUEIEAOUOIAACAOOUAUIYYEAAAOOUYIAAE\n", "output": "2"}, {"input": "AYEYIIEUIYOYAYEUEIIIEUYUUAUEUIYAIAAUYONIEYIUIAEUUOUOYYOUUUIUIAEYEOUIIUOUUEOAIUUYAAEOAAEOYUUIYAYRAIII\n", "output": "2"}, {"input": "YOOAAUUAAAYEUYIUIUYIUOUAEIEEIAUEOAUIIAAIUYEUUOYUIYEAYAAAYUEEOEEAEOEEYYOUAEUYEEAIIYEUEYJOIIYUIOIUOIEE\n", "output": "2"}, {"input": "UYOIIIAYOOAIUUOOEEUYIOUAEOOEIOUIAIEYOAEAIOOEOOOIUYYUYIAAUIOUYYOOUAUIEYYUOAAUUEAAIEUIAUEUUIAUUOYOAYIU\n", "output": "1"}, {"input": "ABBABBB\n", "output": "4"}, {"input": "ABCD\n", "output": "4"}, {"input": "XXYC\n", "output": "3"}, {"input": "YYY\n", "output": "1"}, {"input": "ABABBBBBBB\n", "output": "8"}, {"input": "YYYY\n", "output": "1"}, {"input": "YYYYY\n", "output": "1"}, {"input": "AXXX\n", "output": "4"}, {"input": "YYYYYYY\n", "output": "1"}, {"input": "BYYBBB\n", "output": "4"}, {"input": "YYYYYYYYY\n", "output": "1"}, {"input": "CAAAAA\n", "output": "2"}, {"input": "CCCACCCC\n", "output": "5"}, {"input": "ABABBBACFEYUKOTTTT\n", "output": "5"}, {"input": "AABBYYYYYYYY\n", "output": "3"}, {"input": "BYBACYC\n", "output": "2"}, {"input": "Y\n", "output": "1"}, {"input": "ABBBBBB\n", "output": "7"}, {"input": "BACDYDI\n", "output": "3"}, {"input": "XEXXXXXXXXXXXXXXX\n", "output": "16"}, {"input": "TTYTT\n", "output": "3"}, {"input": "AAYBC\n", "output": "3"}, {"input": "ABABBBACFEYUKOTTTTT\n", "output": "6"}, {"input": "YYAYY\n", "output": "1"}, {"input": "YZZY\n", "output": "3"}, {"input": "YY\n", "output": "1"}, {"input": "ZZYZZ\n", "output": "3"}, {"input": "YBBBY\n", "output": "4"}, {"input": "BBBACCCCCCC\n", "output": "8"}, {"input": "YBBBBY\n", "output": "5"}, {"input": "YYYYYYYYYY\n", "output": "1"}, {"input": "ABABBBBBBBBBBBB\n", "output": "13"}] |
|
225 | Dawid has four bags of candies. The $i$-th of them contains $a_i$ candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total?
Note, that you can't keep bags for yourself or throw them away, each bag should be given to one of the friends.
-----Input-----
The only line contains four integers $a_1$, $a_2$, $a_3$ and $a_4$ ($1 \leq a_i \leq 100$) — the numbers of candies in each bag.
-----Output-----
Output YES if it's possible to give the bags to Dawid's friends so that both friends receive the same amount of candies, or NO otherwise. Each character can be printed in any case (either uppercase or lowercase).
-----Examples-----
Input
1 7 11 5
Output
YES
Input
7 3 2 5
Output
NO
-----Note-----
In the first sample test, Dawid can give the first and the third bag to the first friend, and the second and the fourth bag to the second friend. This way, each friend will receive $12$ candies.
In the second sample test, it's impossible to distribute the bags. | interview | [{"code": "arr=list(map(int,input().split()))\narr.sort()\nif(arr[0]+arr[1]+arr[2]==arr[3]):\n\tprint(\"YES\")\nelif(arr[0]+arr[3]==arr[1]+arr[2]):\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14584.0, "status": "done"}, {"code": "import sys\nfrom collections import defaultdict\nfrom itertools import combinations\nfrom itertools import permutations\ninput = lambda : sys.stdin.readline().rstrip()\ndef write(*args, sep=\" \"):\n for i in args:\n sys.stdout.write(\"{}\".format(i) + sep)\nINF = float('inf')\nMOD = int(1e9 + 7)\n\narr = list(map(int, input().split()))\ns = sum(arr)\nfor i in range(1, 5):\n for j in combinations(arr, i):\n #print(j)\n if sum(j) == s - sum(j):\n print(\"YES\")\n return\n\nprint(\"NO\")\n", "passed": true, "time": 0.16, "memory": 14276.0, "status": "done"}, {"code": "a, b, c, d = list(map(int, input().split()))\nif a+b == c+d or a+c == b+d or a+d == b+c:\n print('YES')\nelif a == b+c+d or b == a+c+d or c == a+b+d or d == a+b+c:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.26, "memory": 14620.0, "status": "done"}, {"code": "a,b,c,d = map(int, input().split())\n\ntot = a+b+c+d\n\nif tot % 2 == 1:\n print(\"NO\")\n return\n\ntot //= 2\n\nif tot == a+b or tot == a+c or tot == a+d or tot == a or tot == b or tot == c or tot == d:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "a, b, c, d = list(map(int, input().split()))\narr = [a, b, c, d]\nfor i in range(2):\n for j in range(2):\n for z in range(2):\n for k in range(2):\n cnt = 0\n for l in range(4):\n q = [i, j, z, k][l]\n if q:\n cnt += arr[l]\n else:\n cnt -= arr[l]\n if cnt == 0:\n print('YES')\n return\nprint('NO')\n", "passed": true, "time": 1.51, "memory": 14452.0, "status": "done"}, {"code": "*l, = sorted(list(map(int, input().split())))\nif l[0] + l[-1] == l[1] + l[2] or sum(l[:3]) == l[3]:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")", "passed": true, "time": 0.41, "memory": 14448.0, "status": "done"}, {"code": "a = list(map(int, input().split()))\na.sort()\nif a[0] + a[3] == a[1] + a[2] or sum(a[:3]) == a[3]:\n\tprint('YES')\nelse:\n\tprint('NO')\n", "passed": true, "time": 0.22, "memory": 14492.0, "status": "done"}, {"code": "a, b, c, d = sorted(list(map(int, input().split())))\nif a + d == b + c or a + b + c == d:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.19, "memory": 14340.0, "status": "done"}, {"code": "a = list( map( int, input().split() ) )\na.sort()\nif a[ 0 ] + a[ 2 ] == a[ 1 ] + a[ 3 ] or a[ 0 ] + a[ 3 ] == a[ 1 ] + a[ 2 ] or a[ 0 ] + a[ 1 ] + a[ 2 ] == a[ 3 ]:\n print( \"YES\" )\nelse:\n print( \"NO\" )\n", "passed": true, "time": 0.2, "memory": 14564.0, "status": "done"}, {"code": "l = [int(x) for x in input().split()]\nl.sort()\n\nif l[0] + l[3] == l[1] + l[2] or l[0] + l[1] + l[2] == l[3] or l[0] + l[1] == l[2] + l[3] or l[0] == l[1] + l[2] + l[3] or l[0] + l[2] == l[1] + l[3]:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.15, "memory": 14572.0, "status": "done"}, {"code": "__author__ = 'Esfandiar'\n'''\nimport sys\ninput=sys.stdin.readline\nn = int(input())\nmap(int,input().split())\nlist(map(int,input().split()))\n'''\na=sorted(list(map(int,input().split())))\nif a[0]+a[-1] == a[1]+a[-2] or a[0]+a[1]+a[2]==a[3]:\n print(\"YES\")\nelse:\n print('NO')", "passed": true, "time": 0.14, "memory": 14524.0, "status": "done"}, {"code": "a,b,c,d=list(map(int,input().split()))\nk=max(a,b,c,d)\nz=min(a,b,c,d)\nif k+z==a+b+c+d-k-z:\n print('YES')\nelif k==a+b+c+d-k:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.23, "memory": 14368.0, "status": "done"}, {"code": "#JMD\n#Nagendra Jha-4096\n\n \nimport sys\nimport math\n\n#import fractions\n#import numpy\n \n###File Operations###\nfileoperation=0\nif(fileoperation):\n orig_stdout = sys.stdout\n orig_stdin = sys.stdin\n inputfile = open('W:/Competitive Programming/input.txt', 'r')\n outputfile = open('W:/Competitive Programming/output.txt', 'w')\n sys.stdin = inputfile\n sys.stdout = outputfile\n\n###Defines...###\nmod=1000000007\n \n###FUF's...###\ndef nospace(l):\n ans=''.join(str(i) for i in l)\n return ans\n \n \n \n##### Main ####\nt=1\nfor tt in range(t):\n #n=int(input())\n a,b,c,d= map(int, sys.stdin.readline().split(' '))\n\n s=(a+b+c+d)\n\n if (s%2)==0 :\n v=s//2\n\n if a==v or b==v or c==v or d==v:\n print(\"YES\")\n elif (a+b)==v or (a+c) == v or (a+d) == v:\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\n\n\n #a=list(map(int,sys.stdin.readline().split(' ')))\n \n \n#####File Operations#####\nif(fileoperation):\n sys.stdout = orig_stdout\n sys.stdin = orig_stdin\n inputfile.close()\n outputfile.close()", "passed": true, "time": 0.14, "memory": 14644.0, "status": "done"}, {"code": "L = list(map(int, input().split()))\nL.sort()\nif (L[0] + L[-1] == L[1] + L[2] or L[0] + L[1] + L[2] == L[3]):\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")", "passed": true, "time": 0.14, "memory": 14284.0, "status": "done"}, {"code": "arr=[int(x) for x in input().split()]\narr.sort()\nif(arr[3]==(arr[0]+arr[1]+arr[2]) or arr[3]+arr[0]==arr[1]+arr[2] or arr[3]+arr[1]==arr[0]+arr[2]):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.19, "memory": 14424.0, "status": "done"}, {"code": "\n\na,b,c,d = map(lambda x:int(x),input().split())\n\nstep1 = [0]\nstep2 = []\nstep3 = []\nstep4 = []\nstep5 = []\n\nfor x in step1:\n step2.append(x+a)\n step2.append(x-a)\nfor x in step2:\n step3.append(x+b)\n step3.append(x-b)\nfor x in step3:\n step4.append(x+c)\n step4.append(x-c)\nfor x in step4:\n step5.append(x+d)\n step5.append(x-d)\nprint(\"YES\" if 0 in step5 else \"NO\")", "passed": true, "time": 0.18, "memory": 14608.0, "status": "done"}, {"code": "a=[int(x) for x in input().split()]\na.sort()\nif sum(a)%2==0:\n counter=sum(a)//2\n if a[0]+a[1]==counter or a[1]+a[2]==counter or a[0]+a[2]==counter or a[0]==counter or a[1]==counter or a[2]==counter or a[3]==counter:\n print('YES')\n else:\n print('NO')\nelse:\n print('NO')\n", "passed": true, "time": 0.14, "memory": 14564.0, "status": "done"}, {"code": "\n\na=list(map(int,input().split()))\na=sorted(a)\n\ns=sum(a)\n\nfor i in range(1<<4):\n\ts1=0\n\n\tfor j in range(4):\n\t\tif(i&(1<<j)):\n\t\t\ts1+=a[j]\n\n\tif(s1==(s-s1)):\n\t\tprint('YES')\n\t\treturn\n\nprint('NO')", "passed": true, "time": 0.19, "memory": 14324.0, "status": "done"}, {"code": "a,b,c,d=list(map(int,input().split()))\nif((a== b+c+d)or(b== a+c+d)or(c== a+b+d)or(d== a+b+c)or(a+b== c+d)or(a+c == b+d)or(a+d == b+c)):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "a1, a2, a3, a4 = map(int, input().split())\n\nres = False\n\nfor i1 in range(2):\n for i2 in range(2):\n for i3 in range(2):\n for i4 in range(2):\n if (i1*a1 + i2*a2 + i3*a3 + i4*a4)*2 == a1 + a2 + a3 + a4:\n res = True\n\nif res:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.15, "memory": 14416.0, "status": "done"}, {"code": "'''input\n10 3 3 4\n'''\n\nimport sys\nimport heapq\nimport math\nfrom collections import defaultdict as dd\n\nl = [int(i) for i in input().split()]\nl.sort()\nif ((l[0] + l[-1] == l[1] + l[2]) or(l[0] + l[1] + l[2] == l[3])):\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}] | [{"input": "1 7 11 5\n", "output": "YES\n"}, {"input": "7 3 2 5\n", "output": "NO\n"}, {"input": "3 14 36 53\n", "output": "YES\n"}, {"input": "30 74 41 63\n", "output": "YES\n"}, {"input": "92 69 83 97\n", "output": "NO\n"}, {"input": "26 52 7 19\n", "output": "YES\n"}, {"input": "72 52 62 62\n", "output": "YES\n"}, {"input": "1 1 1 1\n", "output": "YES\n"}, {"input": "70 100 10 86\n", "output": "NO\n"}, {"input": "14 10 18 24\n", "output": "NO\n"}, {"input": "20 14 37 71\n", "output": "YES\n"}, {"input": "1 1 2 1\n", "output": "NO\n"}, {"input": "2 4 1 1\n", "output": "YES\n"}, {"input": "34 11 84 39\n", "output": "YES\n"}, {"input": "76 97 99 74\n", "output": "YES\n"}, {"input": "44 58 90 53\n", "output": "NO\n"}, {"input": "18 88 18 18\n", "output": "NO\n"}, {"input": "48 14 3 31\n", "output": "YES\n"}, {"input": "72 96 2 26\n", "output": "YES\n"}, {"input": "69 7 44 30\n", "output": "NO\n"}, {"input": "66 68 16 82\n", "output": "NO\n"}, {"input": "100 100 100 100\n", "output": "YES\n"}, {"input": "100 98 99 97\n", "output": "YES\n"}, {"input": "1 100 100 1\n", "output": "YES\n"}, {"input": "100 100 99 100\n", "output": "NO\n"}, {"input": "99 100 3 98\n", "output": "NO\n"}, {"input": "4 4 4 5\n", "output": "NO\n"}, {"input": "2 6 3 2\n", "output": "NO\n"}, {"input": "7 3 6 3\n", "output": "NO\n"}, {"input": "14 9 10 6\n", "output": "NO\n"}, {"input": "2 4 6 6\n", "output": "NO\n"}, {"input": "4 2 4 2\n", "output": "YES\n"}, {"input": "4 4 4 8\n", "output": "NO\n"}, {"input": "6 4 8 6\n", "output": "YES\n"}, {"input": "97 95 91 27\n", "output": "NO\n"}, {"input": "1 2 3 2\n", "output": "YES\n"}, {"input": "1 2 8 9\n", "output": "YES\n"}, {"input": "5 10 1 6\n", "output": "YES\n"}, {"input": "1 2 3 5\n", "output": "NO\n"}, {"input": "3 5 1 3\n", "output": "YES\n"}, {"input": "1 2 3 3\n", "output": "NO\n"}, {"input": "1 1 14 12\n", "output": "YES\n"}, {"input": "1 1 1 2\n", "output": "NO\n"}, {"input": "6 3 6 6\n", "output": "NO\n"}, {"input": "10 2 3 5\n", "output": "YES\n"}, {"input": "1 2 10 7\n", "output": "YES\n"}, {"input": "3 1 1 1\n", "output": "YES\n"}, {"input": "1 2 5 5\n", "output": "NO\n"}, {"input": "2 3 10 10\n", "output": "NO\n"}, {"input": "2 2 4 6\n", "output": "NO\n"}, {"input": "1 1 10 20\n", "output": "NO\n"}, {"input": "1 1 3 1\n", "output": "YES\n"}, {"input": "1 2 1 3\n", "output": "NO\n"}, {"input": "18 17 17 20\n", "output": "NO\n"}, {"input": "3 2 1 1\n", "output": "NO\n"}, {"input": "1 1 4 5\n", "output": "NO\n"}, {"input": "90 30 30 30\n", "output": "YES\n"}, {"input": "1 2 6 3\n", "output": "YES\n"}, {"input": "2 3 3 4\n", "output": "YES\n"}, {"input": "1 1 4 2\n", "output": "YES\n"}, {"input": "1 1 2 3\n", "output": "NO\n"}, {"input": "1 1 3 4\n", "output": "NO\n"}, {"input": "2 1 28 9\n", "output": "NO\n"}, {"input": "1 2 3 4\n", "output": "YES\n"}, {"input": "1 2 4 5\n", "output": "YES\n"}, {"input": "2 2 6 2\n", "output": "YES\n"}, {"input": "2 3 2 5\n", "output": "NO\n"}, {"input": "5 7 1 3\n", "output": "YES\n"}, {"input": "4 4 12 4\n", "output": "YES\n"}, {"input": "1 2 2 7\n", "output": "NO\n"}] |
|
226 | You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
-----Input-----
Input will begin with an integer N (1 ≤ N ≤ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
-----Output-----
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
-----Examples-----
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
-----Note-----
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself. | interview | [{"code": "n = int(input())\na = list(map(int, input().split()))\na = a[::-1]\nd = 0\nfor i in range(len(a)):\n d = max(0 + d, a[i] + (sum(a[:i]) - d))\nprint(sum(a)-d, d)\n", "passed": true, "time": 0.15, "memory": 14592.0, "status": "done"}, {"code": "n = int(input())\nX = list(map(int, input().split()))\n\nali = [None]*(n+1)\nbob = [None]*(n+1)\n\nali[n] = 0\nbob[n] = 0\n\nfor i in range(n-1, -1, -1):\n\tbob[i] = max(bob[i+1], ali[i+1]+X[i])\n\tali[i] = sum(X[i:n]) - bob[i]\n\t\n#print(ali)\n#print(bob)\n\nprint(ali[0], bob[0], sep=' ')\n\t\n", "passed": true, "time": 0.23, "memory": 14392.0, "status": "done"}, {"code": "N = int(input())\nA = list(map(int, input().split()))\n\ns = [0]*(N+1)\ndp = [0]*(N+1)\nfor i in range(N-1, -1, -1):\n\tdp[i] = max(A[i] + s[i+1] - dp[i+1], dp[i+1])\n\ts[i] = s[i+1] + A[i]\nprint(s[0] - dp[0], dp[0])", "passed": true, "time": 1.86, "memory": 14428.0, "status": "done"}, {"code": "n = int(input())\nvs = list(map(int, input().split(' ')))\n\nrs = [0, 0]\n\nfor i in range(n-1, -1, -1):\n rs = [\n min(vs[i] + rs[0], rs[1]),\n max(vs[i] + rs[0], rs[1])\n ]\n\nprint(sum(vs) - rs[1], rs[1])\n", "passed": true, "time": 0.16, "memory": 14324.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\n\n\ndef max_revenue(i, a):\n if i == len(a)-1:\n return a[-1], 0\n before = max_revenue(i+1, a)\n take = a[i] + before[1], before[0]\n give = before[0], a[i] + before[1]\n\n if take[0] > give[0]:\n return take\n else:\n return give\n\nr = max_revenue(0, a)\nprint(r[1], r[0])\n", "passed": true, "time": 0.3, "memory": 14608.0, "status": "done"}, {"code": "\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\nn=int(input())\n\npie=list(map(int,input().split()))\n\ndef dp(i):\n # best result for this player\n if i>=len(pie): return (0,0)\n t1,t2=dp(i+1)\n return (max(pie[i]+t2-t1,t1),t2+pie[i])\n\nt1,t2=dp(0)\n\nprint(t2-t1,t1)", "passed": true, "time": 0.17, "memory": 14376.0, "status": "done"}, {"code": "import math\nfrom random import random\n\ndef getInt():\n return(int(input()))\n\ndef getInts():\n line = input().split()\n return [int(l) for l in line]\n\ndef getFloat():\n return(float(input()))\n\ndef getFloats():\n line = input().split()\n return [float(l) for l in line]\n\ndef getStrings():\n line = input().split()\n return(line)\n\n\nN = getInt()\nvalues = getInts()\n\nnConsidered = 0\n# nC, nO\nbestForChooserSoFar = [0, 0]\n\nfor i in range(len(values)):\n v = values[len(values) - i - 1]\n qsIfTaken = [v + bestForChooserSoFar[1], bestForChooserSoFar[0]]\n qsIfGiven = [bestForChooserSoFar[0], v + bestForChooserSoFar[1]]\n\n if(qsIfTaken[0] >= qsIfGiven[0]):\n bestForChooserSoFar = qsIfTaken\n else:\n bestForChooserSoFar = qsIfGiven\n\nprint(str(bestForChooserSoFar[1]) + ' ' + str(bestForChooserSoFar[0]))", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "N = int(input())\na = [int(i) for i in input().split()]\n\nsuffix = [a[-1]]\ntok = [a[-1]]\ntol = [0]\nbest = [a[-1]]\n\nfor x in reversed(a[:-1]):\n\t# keep\n\tkeep = x + suffix[-1] - best[-1]\n\tgive = best[-1]\n\tbest.append(max(keep,give))\n\ttok.append(keep)\n\ttol.append(give)\n\tsuffix.append(suffix[-1] + x)\n\n# print(best, tok, tol, suffix)\nprint(suffix[-1] - best[-1], best[-1])\n\t\n\n\n", "passed": true, "time": 0.15, "memory": 14384.0, "status": "done"}, {"code": "n = int(input())\na = [int(i) for i in input().split()]\na1 = [[-1] * 50, [-1] * 50]\ndef get(i, fl):\n if i >= n:\n return 0\n if (a1[fl][i] != -1):\n return a1[fl][i]\n if fl == 0:\n a1[fl][i] = max(a[i] + get(i + 1, 1), get(i + 1, 0))\n else:\n a1[fl][i] = min(a[i] + get(i + 1, 1), get(i + 1, 0))\n return a1[fl][i]\n\nan = get(0, 0)\nprint(sum(a) - an, an)\n", "passed": true, "time": 0.15, "memory": 14340.0, "status": "done"}, {"code": "n = int(input())\ncake = list(map(int, input().split()))\ncake.reverse()\npref = [0]\nfor i in range(n):\n pref.append(cake[i] + pref[-1])\ndp = [0] * n\ndp[0] = cake[0]\nfor i in range(1, n):\n dp[i] = max(dp[i - 1], cake[i] + pref[i] - dp[i - 1])\nprint(pref[n] - dp[n - 1], dp[n - 1])", "passed": true, "time": 0.14, "memory": 14548.0, "status": "done"}, {"code": "import math\n\n\ndef main():\n n = int(input())\n slices = [int(x) for x in input().split()]\n dp = [[[0,0], [0,0]] for i in range(n)]\n dp[-1][0] = [slices[-1], 0]\n dp[-1][1] = [0, slices[-1]]\n for i in range(n-2, -1, -1):\n for j in range(0, 2):\n take = slices[i] + dp[i+1][1-j][j]\n do_not_take = dp[i+1][j][j]\n if take > do_not_take:\n dp[i][j][j] = take\n dp[i][j][1-j] = dp[i+1][1-j][1-j]\n else:\n dp[i][j][j] = do_not_take\n dp[i][j][1-j] = slices[i] + dp[i+1][j][1-j]\n print(dp[0][1][0], dp[0][1][1])\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14692.0, "status": "done"}, {"code": "a = int(input())\nb = list(map(int, input().split()))\nsumA = 0\nsumB = 0\nfor i in range( a ):\n if b[a-1-i] > abs(sumA - sumB):\n sumA += b[a-1-i]\n sumA, sumB = sumB, sumA\n else:\n sumA += b[a-1-i]\nprint(min(sumA,sumB), max(sumA, sumB))", "passed": true, "time": 0.15, "memory": 14476.0, "status": "done"}, {"code": "def maximum_pie_consumption(pies):\n c = len(pies) - 1\n toke = wait = 0\n for p in reversed(pies):\n if toke < p + wait:\n toke, wait = wait + p, toke\n else:\n wait += p\n return wait, toke\n\ndef __starting_point():\n input()\n pies = list(map(int, input().strip().split()))\n print(\" \".join(map(str, maximum_pie_consumption(pies))))\n\n__starting_point()", "passed": true, "time": 0.25, "memory": 14452.0, "status": "done"}, {"code": "n = int(input())\npies = [int(x) for x in input().split()]\n\nd = {}\nd[0] = pies[-1]\n\nfor i in range(1, n):\n d[i] = max(sum(pies[-1-i:]) - d[i-1], d[i-1])\n\ns = sum(pies)\n\nres = d[n-1]\n\nprint(s - res, res)\n", "passed": true, "time": 0.15, "memory": 14316.0, "status": "done"}, {"code": "def check(i, bob):\n if i >= n:\n return 0, 0\n if dp[bob][i] != (-1, -1):\n return dp[bob][i]\n if bob:\n x = check(i+1, False)\n y = check(i+1, True)\n if x[0]+arr[i] >= y[0]:\n ret = x[0]+arr[i], x[1]\n else:\n ret = y[0], y[1]+arr[i]\n else:\n x = check(i+1, True,)\n y = check(i+1, False,)\n if x[1]+arr[i] >= y[1]:\n ret = x[0], x[1]+arr[i]\n else:\n ret = y[0]+arr[i], y[1]\n dp[bob][i] = ret\n return ret\n\n\nn = int(input())\n\ndp = [(-1, -1)]*n\ndp = [dp, dp.copy()]\n\narr = list(map(int, input().split()))\nans = check(0, True)\nprint(ans[1], ans[0])\n", "passed": true, "time": 0.14, "memory": 14500.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\na.reverse()\n\nd = [0 for i in range(n)]\nd[0] = [a[0], 0]\n\nfor i in range(1, n):\n d[i] = [max(d[i-1][0], d[i-1][1] + a[i]), min(d[i-1][0], d[i-1][1] + a[i])]\n\nprint(d[-1][1], d[-1][0])", "passed": true, "time": 0.14, "memory": 14556.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nx = s = 0\nfor ai in reversed(a):\n x = max(x, ai + s - x)\n s += ai\n\nprint(s - x, x)\n", "passed": true, "time": 0.15, "memory": 14460.0, "status": "done"}, {"code": "\ndef dp(a, i,control):\n if i >= len(a):\n return 0;\n if dp_list[control][i] != -1:\n return dp_list[control][i]\n else:\n if control:\n res = max(a[i] + dp(a, i+1, False), dp(a , i+1 , True))\n else:\n res = min(dp(a, i+1, True), a[i] + dp(a , i+1 , False))\n dp_list[control][i] = res\n return dp_list[control][i]\n\nn = int(input())\ndp_list = [list(-1 for i in range(n)) , list(-1 for i in range(n)) ]\na = list(map(int, input().split(\" \")))\nres = dp(a , 0, True)\nprint(\"%s %s\" %(sum(a) - res , res ))", "passed": true, "time": 0.25, "memory": 14464.0, "status": "done"}, {"code": "\n\nimport sys\n\ncache = {}\n\ndef max_possible(pie_slices, current_slice, pre_sums):\n\n if current_slice in cache:\n return cache[current_slice]\n\n if len(pie_slices) - 1 == current_slice:\n return pie_slices[current_slice]\n\n\n max_score = -1\n for cs in range(current_slice, len(pie_slices) - 1):\n score = pie_slices[cs] + pre_sums[cs + 1] - max_possible(pie_slices, cs + 1, pre_sums)\n\n if score > max_score:\n max_score = score\n\n # if the last element gives the highest score\n if max_score < pie_slices[-1]:\n max_score = pie_slices[-1]\n\n cache[current_slice] = max_score\n\n return max_score\n\ndef main():\n n = int(sys.stdin.readline().strip())\n\n pie_slices = [int(tok) for tok in sys.stdin.readline().strip().split()]\n\n pre_sums = [sum(pie_slices[i:]) for i in range(len(pie_slices))]\n\n b = max_possible(pie_slices, 0, pre_sums)\n print(sum(pie_slices) - b, b)\n\n\n\n\n\n\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14656.0, "status": "done"}, {"code": "N = int(input())\nn = list(map(int,input().split(\" \")))\n\nif N == 1:\n ans = [0, n[0]]\nelif N == 2:\n ans = [min(n), max(n)]\nelse:\n # print(n)\n n.reverse()\n f = max(n[0], n[1]) # f2\n s = n[0] + n[1] # s2\n for i in range(2, N):\n f = max(n[i] + s - f, f)\n s += n[i]\n # print(f)\n # print(s)\n ans = [s-f, f]\n \nprint(\" \".join(map(str,ans)))\n\n# assume f(n) is the optimal strategy for the remaning n pies, x_n, x_n-1, ...., x_1\n#\n# s(n) = sum(x_1,..., x_n)\n# f(1) = x1\n# f(2) = max(x2, x1)\n# f(3) = max(x3 + s(2) - f(2), f(2))\n# f(4) = max(x4 + s(3) - f(3), f(3))\n", "passed": true, "time": 0.15, "memory": 14580.0, "status": "done"}, {"code": "'''\ncodeforces.com/problemset/problem/859/C\nauthor: latesum\n'''\nn = int(input())\nv = list(map(int,input().split()))\nv.reverse()\nans = [0, 0]\nfor i in range(n):\n if ans[1] + v[i] > ans[0]:\n t = ans[1] + v[i]\n ans[1] = ans[0]\n ans[0] = t\n else:\n ans[1] += v[i]\nprint(ans[1], ans[0])\n", "passed": true, "time": 0.15, "memory": 14316.0, "status": "done"}, {"code": "n = int(input())\na = [int(i) for i in input().split()]\nscore = a[n - 1]\ntotal = a[n - 1]\n\nfor i in range(n - 2, -1, -1):\n new_score = a[i] + total - score\n if new_score > score:\n score = new_score\n total += a[i]\n\nprint(total - score, score)", "passed": true, "time": 0.14, "memory": 14356.0, "status": "done"}, {"code": "n=int(input())\na=list(map(int,input().split()))[::-1]\nif n!=1:\n summax,summin=max(a[0],a[1]),min(a[0],a[1])\nelse:\n summin=0;summax=a[0]\nfor i in range(2,n):\n if summax<summin + a[i]:\n summax,summin=summin + a[i],summax\n else:\n summin=summin+a[i]\nprint(summin,summax)", "passed": true, "time": 0.24, "memory": 14504.0, "status": "done"}, {"code": "n = int(input())\npieces = list(map(int, input().split()))\n\nreversed_pieces = list(reversed(pieces))\n\nTOTAL = []\n\ncurrent_total = 0\nfor piece in reversed_pieces:\n current_total += piece\n TOTAL.append(current_total)\n\nHAS_TOKEN = 0\nNO_TOKEN = 1\n\ndp_alice = [[0] * n, [0] * n]\ndp_bob = [[0] * n, [0] * n]\n\n\ndp_alice[HAS_TOKEN][0] = dp_bob[HAS_TOKEN][0] = reversed_pieces[0]\ndp_alice[NO_TOKEN][0] = dp_bob[NO_TOKEN][0] = 0\n\nfor i in range(1, n):\n dp_alice[HAS_TOKEN][i] = max(dp_alice[HAS_TOKEN][i-1], dp_alice[NO_TOKEN][i-1] + reversed_pieces[i])\n dp_bob[HAS_TOKEN][i] = max(dp_bob[HAS_TOKEN][i-1], dp_bob[NO_TOKEN][i-1] + reversed_pieces[i])\n\n dp_alice[NO_TOKEN][i] = TOTAL[i] - dp_bob[HAS_TOKEN][i]\n dp_bob[NO_TOKEN][i] = TOTAL[i] - dp_alice[HAS_TOKEN][i]\n\nprint(dp_alice[NO_TOKEN][-1], dp_bob[HAS_TOKEN][-1])\n", "passed": true, "time": 0.17, "memory": 14608.0, "status": "done"}] | [{"input": "3\n141 592 653\n", "output": "653 733\n"}, {"input": "5\n10 21 10 21 10\n", "output": "31 41\n"}, {"input": "1\n100000\n", "output": "0 100000\n"}, {"input": "50\n100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000\n", "output": "2500000 2500000\n"}, {"input": "2\n1 100000\n", "output": "1 100000\n"}, {"input": "17\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536\n", "output": "65535 65536\n"}, {"input": "15\n3026 3027 4599 4854 7086 29504 38709 40467 40663 58674 61008 70794 77517 85547 87320\n", "output": "306375 306420\n"}, {"input": "30\n2351 14876 66138 87327 29940 73204 19925 50198 13441 54751 1383 92120 90236 13525 3920 16669 80637 94428 54890 71321 77670 57080 82145 39778 69967 38722 46902 82127 1142 21792\n", "output": "724302 724303\n"}, {"input": "1\n59139\n", "output": "0 59139\n"}, {"input": "2\n9859 48096\n", "output": "9859 48096\n"}, {"input": "3\n25987 64237 88891\n", "output": "88891 90224\n"}, {"input": "4\n9411 13081 2149 19907\n", "output": "19907 24641\n"}, {"input": "5\n25539 29221 6895 82089 18673\n", "output": "80328 82089\n"}, {"input": "6\n76259 10770 87448 3054 67926 81667\n", "output": "158428 168696\n"}, {"input": "7\n92387 35422 24898 32532 92988 84636 99872\n", "output": "192724 270011\n"}, {"input": "8\n8515 51563 5451 94713 9537 30709 63343 41819\n", "output": "138409 167241\n"}, {"input": "9\n91939 407 10197 24191 58791 9486 68030 25807 11\n", "output": "102429 186430\n"}, {"input": "10\n30518 96518 74071 59971 50121 4862 43967 73607 19138 90754\n", "output": "252317 291210\n"}, {"input": "11\n46646 21171 78816 89449 99375 50934 15950 90299 18702 62232 12657\n", "output": "288850 297381\n"}, {"input": "12\n30070 37311 92074 18927 91732 29711 12126 41583 52857 99118 73097 33928\n", "output": "296580 315954\n"}, {"input": "13\n13494 86155 96820 72596 40986 99976 16813 25571 87013 3301 832 26376 83769\n", "output": "325890 327812\n"}, {"input": "14\n96918 67704 10077 34778 90239 11457 80284 42263 53872 74779 93976 53416 83860 74518\n", "output": "414474 453667\n"}, {"input": "15\n13046 83844 14823 64255 15301 90234 84972 93547 88028 11665 54415 13159 83950 951 42336\n", "output": "362168 392358\n"}, {"input": "16\n29174 32688 95377 26437 64554 60498 56955 10239 22183 15847 47559 40199 92552 70488 4147 73082\n", "output": "370791 371188\n"}, {"input": "17\n79894 24637 8634 80107 81104 39275 53130 94227 56339 87326 7999 75751 92642 96921 74470 20999 69688\n", "output": "492038 551105\n"}, {"input": "18\n96022 73481 13380 42288 6166 85348 25113 78215 23198 24212 44246 35494 92733 66459 44793 68916 82818 3967\n", "output": "436157 470692\n"}, {"input": "19\n79446 55030 93934 39062 88123 88317 21289 62203 57354 28394 37390 95238 92823 92892 39308 16833 54733 51525 58759\n", "output": "538648 614005\n"}, {"input": "20\n5440 88704 61481 72140 15810 58854 43034 5150 80684 61360 50516 54301 78790 43678 46138 79893 89899 60260 2881 66499\n", "output": "506639 558873\n"}, {"input": "21\n21569 37548 74739 25809 65063 37631 71913 89138 47543 65542 10956 14045 78880 70111 73357 27810 70326 40523 899 6547 87440\n", "output": "506467 510922\n"}, {"input": "22\n72289 86393 79484 55287 14317 83704 11192 73126 81699 2429 4100 41085 87482 72352 10976 75727 42240 79569 31621 3492 51189 25936\n", "output": "513496 572193\n"}, {"input": "23\n88417 11045 92742 84765 6675 86673 40072 57114 15854 6611 40347 76636 87572 66082 38195 56348 89962 59831 29640 43541 14937 73713 52755\n", "output": "602650 616877\n"}, {"input": "24\n71841 27185 73295 46946 55928 65450 12055 73806 82714 78089 787 36380 87663 68323 75814 4265 94581 31581 51850 40486 11390 21491 27560 22678\n", "output": "560664 601494\n"}, {"input": "25\n87969 76030 78041 616 13694 11522 84038 25090 16869 14975 61226 96124 20457 62052 70329 76374 42303 11844 15276 37430 99330 77781 35069 64358 45168\n", "output": "586407 637558\n"}, {"input": "26\n71393 24874 91299 30093 62947 14491 80214 41782 51025 19158 21666 23163 20547 64293 40653 24291 46922 92106 13294 77479 63079 25559 42579 62933 24433 39507\n", "output": "569885 599895\n"}, {"input": "27\n54817 73719 96044 92275 12201 60564 84901 25770 17884 90636 14810 82907 20637 58023 10976 72208 94644 63856 11312 74424 26828 40632 58600 37316 38290 82420 48297\n", "output": "716531 728460\n"}, {"input": "28\n70945 22563 76598 21753 4558 39341 48372 77054 52039 27522 75249 18459 96536 60264 5491 20125 42367 44118 42034 38665 47472 88410 66109 78995 52147 68436 9814 71112\n", "output": "669482 697066\n"}, {"input": "29\n54369 14511 14048 83934 53812 75014 20356 17938 86195 31704 68393 78202 96626 86697 75814 746 46985 15868 40052 11417 11221 44700 40915 53378 98708 78644 4035 20164 37165\n", "output": "678299 683312\n"}, {"input": "30\n4555 13594 57403 75796 14203 12847 66292 60885 9525 40478 57327 69970 15297 37483 39540 31102 14855 412 84174 57684 65591 19837 80431 18385 3107 87740 15433 24854 73472 88205\n", "output": "620095 620382\n"}, {"input": "31\n20683 29734 37957 37978 63456 58920 70980 44873 76385 44661 17767 97009 15387 63916 77159 79019 86770 4866 14897 63141 86236 67614 87940 60064 16964 97948 9654 49714 30888 88075 63792\n", "output": "825663 838784\n"}, {"input": "32\n71403 78578 75406 67455 12710 37697 67155 28861 10540 48843 10911 56753 15477 33453 4378 26936 34492 19720 12915 27382 49984 91200 95449 34448 63525 83964 3875 98767 77905 63753 83018 58084\n", "output": "770578 774459\n"}, {"input": "33\n87531 27423 55960 53829 37771 40665 39138 12849 77399 53025 71350 83793 48271 59887 41997 74854 14919 24175 43637 24327 13733 38978 2959 319 10086 26876 65393 56332 68025 63623 93732 68354 83938\n", "output": "741185 823963\n"}, {"input": "34\n70955 19371 60706 50603 54321 86738 11122 29541 11555 57207 31790 19344 24170 29424 36512 22771 86833 4437 41655 64376 34378 19459 86276 74702 23943 69789 59614 48489 49634 63494 12958 11328 69333 1736\n", "output": "693927 744637\n"}, {"input": "35\n54379 920 41259 12784 3574 98219 40001 80825 45710 61390 24933 79088 24260 23153 6835 94880 67260 76187 39673 28616 98126 10341 26489 49085 37800 55805 86539 97542 39754 30660 32184 64703 11625 77872 63584\n", "output": "823487 862568\n"}, {"input": "36\n37803 17060 78709 42262 28636 68484 79280 97517 12570 98276 52669 6128 57054 58098 68646 75501 39174 56449 3099 1369 94579 58119 1295 90764 51657 66013 48056 55107 54066 30530 75602 74973 21212 21304 22589 4895\n", "output": "872694 876851\n"}, {"input": "37\n53932 65904 91967 4443 77890 47261 8160 81505 46725 69754 21621 65871 24440 51828 71673 23418 86896 4008 1117 65610 82519 5897 8804 65148 98218 76221 42277 79968 68379 30401 62125 61052 96207 64737 24698 99495 70720\n", "output": "989044 1011845\n"}, {"input": "38\n70060 14749 72520 58113 2951 26037 80143 32789 80881 73936 82060 92911 24531 78261 9292 71335 91515 8462 31839 62555 46268 29482 92121 31019 12075 94942 36498 96317 58499 30271 81351 71322 81602 8169 26807 69903 38154 20539\n", "output": "977736 1012543\n"}, {"input": "39\n20780 30889 9970 87591 19501 96302 76318 49481 47740 10823 42500 61167 57325 47798 36511 19252 39237 23316 29857 2603 10016 9964 99630 5402 82828 5150 98015 53882 72811 97437 57473 57400 91189 84305 85811 64503 40179 50614 52044\n", "output": "954593 973021\n"}, {"input": "40\n3670 5779 20621 87964 12595 34136 98063 92429 38366 43789 88330 52934 19100 22776 43342 82312 74404 64756 73980 14278 21283 85101 63339 70409 63034 14245 33606 58571 84927 14931 25355 15452 46072 4671 5838 69121 18243 87783 29748 84047\n", "output": "909877 959523\n"}, {"input": "41\n87094 21920 58071 41634 29145 45616 94239 76417 5226 47971 48770 79974 19190 25017 37857 30229 11726 12314 71998 54327 85032 8687 46656 12088 9595 24454 27827 7624 66535 14801 44581 25723 55659 48103 75242 39529 52973 17858 16985 41454 44182\n", "output": "799467 864856\n"}, {"input": "42\n70518 70764 38625 3816 78399 48585 66222 60405 72085 52153 85018 39717 51984 51451 8180 78146 59448 16768 2720 51272 48780 56464 21461 86471 23452 10470 22048 65189 56655 90480 31103 11801 73758 91536 10055 34129 20407 47933 4223 98861 84475 52291\n", "output": "1012190 1036128\n"}, {"input": "43\n86646 19609 43370 33293 3460 94658 95101 44393 6241 56335 78161 66757 52074 53692 2695 58767 31363 64326 738 15513 69425 4242 28971 60855 37309 53382 16269 57346 70968 90350 74522 22072 83345 67672 69060 4537 55137 78008 91461 32075 33280 70405 71607\n", "output": "1039942 1109548\n"}, {"input": "44\n70070 68453 23924 95475 52714 73435 34380 61085 40396 60518 38601 26501 52165 47421 73018 6684 79085 68781 31460 88265 33173 52020 44992 2534 8062 96295 77786 39103 85280 24812 93748 75446 92932 11105 71169 66433 89866 75379 11402 22186 73572 31624 70092 10734\n", "output": "1141992 1210184\n"}, {"input": "45\n53494 93105 37182 24953 1967 43700 39068 12369 7256 64700 31744 62052 84959 49662 34829 78793 51000 16339 29478 52506 96922 75606 52501 1109 21919 6503 72007 63964 75400 24682 45678 18420 67928 87241 73278 69545 24596 29646 65936 55401 89673 49738 35873 45189 3622\n", "output": "1052557 1068976\n"}, {"input": "46\n36918 9246 74631 78622 94325 22476 35243 96357 41411 68882 92184 21796 28153 43392 37856 26710 64130 20793 60200 16747 84862 23383 60010 42788 68480 92519 66229 56121 57009 24553 89096 4499 53323 30673 75386 31442 92030 59721 53173 45511 29966 67853 77462 12347 61811 81517\n", "output": "1199490 1212346\n"}, {"input": "47\n53046 58090 55185 8100 43578 1253 7226 13049 75567 73065 19920 48836 28243 45633 75475 74628 11853 68351 90922 89500 81315 71161 34816 49875 82337 2727 27746 37878 79833 24423 75618 82065 95614 82618 34391 1850 94056 57092 73115 70214 46067 29071 75947 46802 95807 42600 11211\n", "output": "1214201 1233568\n"}, {"input": "48\n69174 6934 59931 70281 68640 47326 3402 64333 42426 77247 13063 8579 61038 39362 2694 22545 83767 15909 88940 86445 45063 27451 18133 91555 28898 45640 21967 62738 61441 24293 19036 68144 5201 26050 69204 29154 85681 19871 60352 36133 86359 47186 74432 5448 53996 27876 58022 80559\n", "output": "1096672 1115247\n"}, {"input": "49\n19894 55779 73188 99759 17893 50295 8089 81025 76582 81429 73503 35619 61128 41603 40313 3166 31490 87660 19662 59197 8812 75229 25642 65938 42755 31656 16188 87599 51562 91460 38262 11118 90596 69482 71313 66858 87707 17242 14886 93539 35164 32596 83317 72606 12185 21664 80642 72099 7525\n", "output": "1233007 1259909\n"}, {"input": "50\n70081 97965 40736 24325 2476 20832 54026 23972 91400 47099 95141 27386 79799 49285 4039 818 23552 72203 55273 38168 52783 50365 89351 30945 47154 8047 27586 49184 20573 8953 38849 36466 45479 89848 82827 71475 74283 87115 92590 28903 97800 74550 74140 82514 10849 6786 67881 63456 53022 25051\n", "output": "1251581 1255820\n"}, {"input": "4\n10 3 2 1\n", "output": "4 12\n"}, {"input": "6\n5245 1414 21632 12159 31783 7412\n", "output": "38442 41203\n"}, {"input": "46\n1666 17339 9205 20040 30266 12751 11329 7951 9000 14465 11771 7600 19480 15993 19453 7470 1361 7922 27747 17347 4727 11280 403 16338 6064 11124 25723 18717 26118 271 9242 16952 26381 31795 28226 3646 27589 31472 30108 28354 25281 22429 30956 32264 14729 21685\n", "output": "379808 392222\n"}, {"input": "3\n100 90 80\n", "output": "90 180\n"}, {"input": "5\n10 9 8 7 6\n", "output": "16 24\n"}, {"input": "4\n100 40 50 10\n", "output": "50 150\n"}, {"input": "6\n5 4 3 2 1 1\n", "output": "7 9\n"}, {"input": "33\n30274 12228 26670 31244 5457 2643 27275 4380 30954 23407 8387 6669 25229 31591 27518 30261 25670 20962 31316 8992 8324 26216 10812 28467 15401 23077 10311 24975 14046 12010 11406 22841 7593\n", "output": "299163 327443\n"}, {"input": "3\n4 2 1\n", "output": "2 5\n"}, {"input": "3\n10 5 5\n", "output": "5 15\n"}, {"input": "6\n6 5 4 3 2 1\n", "output": "9 12\n"}, {"input": "4\n5 2 7 3\n", "output": "7 10\n"}] |
|
227 | You've got a positive integer sequence a_1, a_2, ..., a_{n}. All numbers in the sequence are distinct. Let's fix the set of variables b_1, b_2, ..., b_{m}. Initially each variable b_{i} (1 ≤ i ≤ m) contains the value of zero. Consider the following sequence, consisting of n operations.
The first operation is assigning the value of a_1 to some variable b_{x} (1 ≤ x ≤ m). Each of the following n - 1 operations is assigning to some variable b_{y} the value that is equal to the sum of values that are stored in the variables b_{i} and b_{j} (1 ≤ i, j, y ≤ m). At that, the value that is assigned on the t-th operation, must equal a_{t}. For each operation numbers y, i, j are chosen anew.
Your task is to find the minimum number of variables m, such that those variables can help you perform the described sequence of operations.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 23). The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{k} ≤ 10^9).
It is guaranteed that all numbers in the sequence are distinct.
-----Output-----
In a single line print a single number — the minimum number of variables m, such that those variables can help you perform the described sequence of operations.
If you cannot perform the sequence of operations at any m, print -1.
-----Examples-----
Input
5
1 2 3 6 8
Output
2
Input
3
3 6 5
Output
-1
Input
6
2 4 8 6 10 18
Output
3
-----Note-----
In the first sample, you can use two variables b_1 and b_2 to perform the following sequence of operations. b_1 := 1; b_2 := b_1 + b_1; b_1 := b_1 + b_2; b_1 := b_1 + b_1; b_1 := b_1 + b_2. | interview | [{"code": "def Solve(x,B):\n if((X,x,B) in Mem):\n return Mem[(X,x,B)]\n if(len(B)>X):\n return False\n if(x==len(L)):\n return True\n if(Form(L[x],B)):\n A=list(B)\n for e in range(len(B)):\n r=A[e]\n A[e]=L[x]\n if(Solve(x+1,tuple(sorted(A)))):\n Mem[(X,x,B)]=True\n return True\n A[e]=r\n A+=[L[x]]\n if(Solve(x+1,tuple(sorted(A)))):\n Mem[(X,x,B)]=True\n return True\n Mem[(X,x,B)]=False\n return False\n\ndef Form(x,B):\n for i in range(len(B)):\n for j in range(i,len(B)):\n if(B[i]+B[j]==x):\n return True\n return False\n \nn=int(input())\nL=list(map(int,input().split()))\ndone=False\nMem={}\nfor X in range(1,n+1):\n if(Solve(1,(L[0],))):\n print(X)\n done=True\n break\nif(not done):\n print(-1)\n", "passed": true, "time": 1.08, "memory": 27256.0, "status": "done"}] | [{"input": "5\n1 2 3 6 8\n", "output": "2\n"}, {"input": "3\n3 6 5\n", "output": "-1\n"}, {"input": "6\n2 4 8 6 10 18\n", "output": "3\n"}, {"input": "7\n1 2 4 5 3 6 7\n", "output": "3\n"}, {"input": "10\n11 22 44 88 132 264 66 33 165 55\n", "output": "5\n"}, {"input": "10\n201 402 804 603 1608 2010 1206 2412 4824 2211\n", "output": "3\n"}, {"input": "16\n92 184 368 276 552 1104 1196 736 1472 1288 1012 2576 5152 1840 3680 1656\n", "output": "5\n"}, {"input": "18\n8478 16956 33912 25434 50868 42390 101736 203472 84780 59346 127170 245862 135648 491724 279774 559548 186516 152604\n", "output": "7\n"}, {"input": "22\n45747 91494 182988 228735 365976 137241 274482 548964 640458 457470 594711 731952 686205 777699 1372410 914940 1463904 1235169 1555398 320229 1326663 1829880\n", "output": "6\n"}, {"input": "23\n345802 691604 1037406 1383208 1729010 2074812 4149624 8299248 2766416 9682456 2420614 4841228 19364912 5532832 13832080 11065664 15215288 4495426 8990852 17981704 3458020 16598496 23514536\n", "output": "5\n"}, {"input": "1\n83930578\n", "output": "1\n"}, {"input": "2\n31084462 62168924\n", "output": "1\n"}, {"input": "3\n25721995 51443990 102887980\n", "output": "1\n"}, {"input": "4\n67843175 135686350 203529525 271372700\n", "output": "2\n"}, {"input": "5\n9964356 19928712 29893068 39857424 79714848\n", "output": "2\n"}, {"input": "6\n9634592 19269184 28903776 57807552 115615104 86711328\n", "output": "3\n"}, {"input": "7\n96979964 193959928 290939892 581879784 775839712 678859748 872819676\n", "output": "3\n"}, {"input": "8\n39101145 78202290 117303435 156404580 234606870 273708015 312809160 625618320\n", "output": "3\n"}, {"input": "9\n33738677 67477354 134954708 168693385 101216031 202432062 404864124 371125447 438602801\n", "output": "4\n"}, {"input": "10\n73239877 146479754 292959508 585919016 659158893 878878524 732398770 805638647 219719631 952118401\n", "output": "5\n"}, {"input": "11\n60585250 121170500 242341000 484682000 969364000 727023000 302926250 363511500 424096750 848193500 787608250\n", "output": "4\n"}, {"input": "12\n60255486 120510972 241021944 180766458 361532916 301277430 482043888 662810346 421788402 783321318 602554860 843576804\n", "output": "4\n"}, {"input": "13\n2376667 4753334 7130001 9506668 14260002 28520004 57040008 33273338 11883335 47533340 40403339 114080016 23766670\n", "output": "5\n"}, {"input": "14\n44497847 88995694 133493541 266987082 177991388 533974164 311484929 444978470 711965552 756463399 578472011 622969858 889956940 355982776\n", "output": "4\n"}, {"input": "15\n39135379 78270758 117406137 234812274 195676895 156541516 469624548 391353790 273947653 313083032 939249096 782707580 587030685 860978338 626166064\n", "output": "4\n"}, {"input": "12\n81256560 162513120 243769680 325026240 406282800 812565600 487539360 893822160 975078720 568795920 650052480 731309040\n", "output": "3\n"}, {"input": "17\n28410444 56820888 85231332 170462664 142052220 340925328 284104440 681850656 852313320 198873108 568208880 539798436 767081988 596619324 113641776 397746216 482977548\n", "output": "6\n"}, {"input": "18\n23047977 46095954 92191908 69143931 115239885 138287862 161335839 184383816 230479770 460959540 345719655 691439310 737535264 553151448 368767632 414863586 645343356 207431793\n", "output": "6\n"}, {"input": "15\n65169157 130338314 260676628 391014942 521353256 782029884 586522413 912368198 977537355 716860727 651691570 325845785 847199041 456184099 195507471\n", "output": "5\n"}, {"input": "20\n48108642 96217284 144325926 288651852 577303704 432977778 625412346 865955556 192434568 914064198 384869136 962172840 769738272 817846914 336760494 481086420 673520988 721629630 529195062 240543210\n", "output": "5\n"}, {"input": "11\n90229822 180459644 270689466 360919288 721838576 812068398 902298220 631608754 541378932 992528042 451149110\n", "output": "4\n"}, {"input": "11\n84867355 169734710 254602065 339469420 678938840 763806195 509204130 933540905 424336775 848673550 594071485\n", "output": "4\n"}, {"input": "22\n1 2 4 3 8 6 12 14 16 18 24 7 22 20 11 32 13 19 64 30 26 40\n", "output": "5\n"}, {"input": "22\n10 20 40 50 30 60 70 120 90 140 150 80 160 110 300 100 600 170 370 240 360 280\n", "output": "6\n"}, {"input": "22\n8 16 24 48 32 56 40 112 80 64 96 224 104 448 120 176 128 352 336 392 248 192\n", "output": "7\n"}, {"input": "22\n420 840 1680 1260 2520 5040 3360 7560 2940 10080 20160 10500 15120 9240 2100 11760 40320 3780 31920 80640 25200 21000\n", "output": "7\n"}, {"input": "22\n8938 17876 35752 26814 53628 44690 71504 107256 89380 143008 286016 178760 169822 214512 250264 339644 572032 679288 330706 366458 357520 1144064\n", "output": "6\n"}, {"input": "22\n45747 91494 182988 228735 365976 137241 274482 548964 640458 457470 594711 731952 686205 777699 1372410 914940 1463904 1235169 1555398 320229 1326663 1829880\n", "output": "6\n"}, {"input": "22\n631735 1263470 1895205 2526940 3158675 3790410 5685615 6317350 5053880 11371230 6949085 22742460 7580820 45484920 90969840 93496780 10107760 181939680 47380125 94760250 15161640 23374195\n", "output": "7\n"}, {"input": "22\n3987418 7974836 15949672 31899344 11962254 63798688 71773524 23924508 127597376 83735778 19937090 47849016 35886762 39874180 107660286 167471556 79748360 103672868 255194752 203358318 219307990 95698032\n", "output": "6\n"}, {"input": "3\n2 4 8\n", "output": "1\n"}, {"input": "6\n2 4 8 6 16 10\n", "output": "3\n"}, {"input": "9\n1 2 4 8 3 5 6 16 14\n", "output": "3\n"}, {"input": "12\n11 22 44 88 99 176 198 132 264 231 242 352\n", "output": "5\n"}, {"input": "15\n12 24 48 36 72 60 96 120 156 132 312 84 372 144 108\n", "output": "5\n"}, {"input": "18\n4 8 12 16 24 28 56 112 40 140 68 32 80 224 152 168 48 96\n", "output": "5\n"}, {"input": "21\n10 20 30 40 50 60 120 70 80 140 160 100 90 200 150 320 170 230 350 180 340\n", "output": "5\n"}, {"input": "3\n262253762 524507524 786761286\n", "output": "2\n"}, {"input": "1\n790859600\n", "output": "1\n"}, {"input": "1\n704544247\n", "output": "1\n"}, {"input": "4\n940667586 65534221 61164707 241895842\n", "output": "-1\n"}, {"input": "8\n226552194 948371814 235787062 554250733 469954481 613078091 527123864 931267470\n", "output": "-1\n"}, {"input": "12\n571049787 387287232 156938133 355608 67121754 553950296 753144335 119811912 299704269 907663639 77709173 374112740\n", "output": "-1\n"}, {"input": "16\n856934395 120381720 331560489 17743203 231170149 605427913 922284462 809637424 925272548 561816196 347598116 70631268 262237748 619626972 643454490 127284557\n", "output": "-1\n"}, {"input": "20\n368834400 10351632 692089781 133440038 504863537 894500691 118792061 455602559 654100326 385982376 44564138 647376831 644780643 449087519 491494413 712802475 704953654 147972994 154107841 121307490\n", "output": "-1\n"}, {"input": "22\n733002177 450640701 558175486 509713228 159499831 848757132 923457868 447998963 466884466 991833183 532024962 569377919 783824381 912917088 209657760 955333528 364734880 497624841 664283267 141164882 829674139 948471256\n", "output": "-1\n"}, {"input": "22\n733002177 450640701 558175486 509713228 159499831 848757132 923457868 447998963 466884466 991833183 532024962 569377919 783824381 912917088 209657760 955333528 364734880 497624841 664283267 141164882 829674139 948471256\n", "output": "-1\n"}, {"input": "22\n733002177 450640701 558175486 509713228 159499831 848757132 923457868 447998963 466884466 991833183 532024962 569377919 783824381 912917088 209657760 955333528 364734880 497624841 664283267 141164882 829674139 948471256\n", "output": "-1\n"}, {"input": "22\n733002177 450640701 558175486 509713228 159499831 848757132 923457868 447998963 466884466 991833183 532024962 569377919 783824381 912917088 209657760 955333528 364734880 497624841 664283267 141164882 829674139 948471256\n", "output": "-1\n"}, {"input": "22\n733002177 450640701 558175486 509713228 159499831 848757132 923457868 447998963 466884466 991833183 532024962 569377919 783824381 912917088 209657760 955333528 364734880 497624841 664283267 141164882 829674139 948471256\n", "output": "-1\n"}, {"input": "23\n2 4 8 10 16 24 32 48 18 36 52 64 104 208 128 96 20 112 72 416 832 144 224\n", "output": "6\n"}, {"input": "23\n77 154 308 462 924 616 1232 2464 1848 3696 1001 2002 1078 4928 6160 12320 1540 12782 3080 2310 4620 24640 3542\n", "output": "6\n"}, {"input": "23\n17 34 68 136 170 340 680 102 119 153 459 918 748 238 1088 1496 1836 1207 1224 272 1955 1360 578\n", "output": "7\n"}, {"input": "23\n8451 16902 25353 50706 42255 84510 67608 101412 202824 169020 118314 135216 219726 405648 33804 439452 507060 447903 185922 574668 490158 557766 625374\n", "output": "6\n"}, {"input": "23\n52614 105228 210456 263070 420912 841824 473526 1683648 894438 2525472 5050944 631368 3367296 1788876 10101888 526140 1999332 2788542 2578086 3577752 947052 3998664 2630700\n", "output": "8\n"}, {"input": "23\n248812 497624 746436 995248 1492872 2985744 4478616 4727428 1244060 2488120 5225052 10450104 7713172 4976240 8957232 5971488 1741684 10201292 9454856 15426344 11942976 18909712 5473864\n", "output": "6\n"}, {"input": "23\n1048669 2097338 3146007 6292014 7340683 12584028 4194676 8389352 16778704 10486690 11535359 5243345 17827373 15730035 23070718 35654746 26216725 14681366 20973380 41946760 31460070 71309492 19924711\n", "output": "5\n"}, {"input": "23\n26988535 53977070 107954140 161931210 323862420 215908280 431816560 647724840 269885350 242896815 755678980 485793630 863633120 404828025 539770700 134942675 593747770 377839490 917610190 809656050 620736305 971587260 458805095\n", "output": "7\n"}, {"input": "23\n5438993 10877986 16316979 21755972 32633958 43511944 65267916 54389930 108779860 87023888 38072951 76145902 59828923 70706909 174047776 190364755 97901874 141413818 217559720 81584895 348095552 48950937 119657846\n", "output": "6\n"}, {"input": "23\n17056069 34112138 51168207 102336414 119392483 153504621 170560690 68224276 136448552 221728897 307009242 204672828 85280345 443457794 324065311 358177449 545794208 426401725 886915588 255841035 750467036 852803450 955139864\n", "output": "6\n"}] |
|
228 | Alice and Bob are playing a game with $n$ piles of stones. It is guaranteed that $n$ is an even number. The $i$-th pile has $a_i$ stones.
Alice and Bob will play a game alternating turns with Alice going first.
On a player's turn, they must choose exactly $\frac{n}{2}$ nonempty piles and independently remove a positive number of stones from each of the chosen piles. They can remove a different number of stones from the piles in a single turn. The first player unable to make a move loses (when there are less than $\frac{n}{2}$ nonempty piles).
Given the starting configuration, determine who will win the game.
-----Input-----
The first line contains one integer $n$ ($2 \leq n \leq 50$) — the number of piles. It is guaranteed that $n$ is an even number.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 50$) — the number of stones in the piles.
-----Output-----
Print a single string "Alice" if Alice wins; otherwise, print "Bob" (without double quotes).
-----Examples-----
Input
2
8 8
Output
Bob
Input
4
3 1 4 1
Output
Alice
-----Note-----
In the first example, each player can only remove stones from one pile ($\frac{2}{2}=1$). Alice loses, since Bob can copy whatever Alice does on the other pile, so Alice will run out of moves first.
In the second example, Alice can remove $2$ stones from the first pile and $3$ stones from the third pile on her first move to guarantee a win. | interview | [{"code": "n=int(input())\ns=list(map(int,input().split()))\nprint(\"Bob\"if s.count(min(s))>n/2 else\"Alice\")\n", "passed": true, "time": 0.15, "memory": 14424.0, "status": "done"}, {"code": "def judge(i):\n return \"Bob\" if cnt[i]>n//2 else \"Alice\"\nn=int(input())\na=list(map(int,input().split()))\ncnt=[0 for i in range(51)]\nfor i in a:\n cnt[i]+=1\nprint(judge(min(a)))", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}, {"code": "n = int(input())\na = [int(i) for i in input().split()]\nprint(\"Alice\" if sum([1 if i==min(a) else 0 for i in a ]) <= n/2 else \"Bob\")", "passed": true, "time": 0.14, "memory": 14528.0, "status": "done"}, {"code": "n=int(input())\nd=[0]*51\nfor i in input().split(\" \"):\n d[int(i)]+=1\nfor i in range(50):\n if (d[i]>n/2):\n print(\"Bob\")\n break\n else:\n if (d[i]>0):\n print(\"Alice\")\n break", "passed": true, "time": 0.14, "memory": 14408.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int,input().split()))\nprint( 'Alice' if a.count(min(a)) <= n//2 else 'Bob' )\n##\n", "passed": true, "time": 0.15, "memory": 14424.0, "status": "done"}, {"code": "n = int(input())\na = [int(x) for x in input().split()]\nimin = a[0]\ncnt = 0\nfor x in a:\n\tif x < imin:\n\t\timin = x\n\t\tcnt = 0\n\tif x == imin:\n\t\tcnt += 1\nif cnt <= n // 2:\n\tprint(\"Alice\")\nelse:\n\tprint(\"Bob\")\n", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "n = int(input())\npilhas = list(map(int, input().split()))\n\ncount = [0] * 51\n\nfor pilha in pilhas:\n count[pilha] += 1\n\nfor i in range(51):\n if count[i] != 0 and count[i] * 2 <= n:\n print(\"Alice\")\n break\n elif count[i] != 0 and count[i] * 2 > n:\n print(\"Bob\")\n break", "passed": true, "time": 0.22, "memory": 14528.0, "status": "done"}, {"code": "n = int(input())\n\njog = [int(i) for i in input().split()]\nmi = min(jog)\n\nqtd = 0\nfor i in range(len(jog)):\n if(jog[i] == mi):\n qtd+=1\nif(qtd <= n//2 and qtd!=0):\n print(\"Alice\")\nelse:\n print(\"Bob\")\n", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}, {"code": "n = int(input())\na = [int(_) for _ in input().split()]\n\ncnt = [0 for i in range(max(a) + 1)]\nfor i in a:\n cnt[i] += 1\n\nprint(\"Bob\" if cnt[min(a)] > (n >> 1) else \"Alice\")\n", "passed": true, "time": 0.14, "memory": 14508.0, "status": "done"}, {"code": "n = int(input())\na = [int(x) for x in input().split()]\nimin = a[0]\ncnt = 0\nfor x in a:\n\tif x < imin:\n\t\timin = x\n\t\tcnt = 0\n\tif x == imin:\n\t\tcnt += 1\nif cnt <= n // 2:\n\tprint(\"Alice\")\nelse:\n\tprint(\"Bob\")\n", "passed": true, "time": 0.14, "memory": 14584.0, "status": "done"}, {"code": "n=int(input())\npiles = list(map(int,input().split()))\nif(piles.count(min(piles))>n/2):\n print(\"Bob\")\nelse:\n print(\"Alice\")\n", "passed": true, "time": 0.22, "memory": 14416.0, "status": "done"}, {"code": "n = int(input())\n\narr = [int(x) for x in input().split()]\n\narr.sort()\n\nx = 1\n\nwhile True:\n if arr.count(x) > n//2:\n print('Bob')\n break\n elif x in arr:\n print('Alice')\n break\n else:\n x += 1\n\n \n", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "n = int(input())\na = [int(x) for x in input().split()]\nmn, cnt = min(a), 0\nfor i in a: \n if i == mn: cnt += 1\nprint(\"Alice\" if cnt <= int(n / 2) else \"Bob\")\n", "passed": true, "time": 0.14, "memory": 14452.0, "status": "done"}] | [{"input": "2\n8 8\n", "output": "Bob\n"}, {"input": "4\n3 1 4 1\n", "output": "Alice\n"}, {"input": "4\n42 49 42 42\n", "output": "Bob\n"}, {"input": "8\n11 21 31 41 41 31 21 11\n", "output": "Alice\n"}, {"input": "10\n21 4 7 21 18 38 12 17 21 13\n", "output": "Alice\n"}, {"input": "12\n33 26 11 11 32 25 18 24 27 47 28 7\n", "output": "Alice\n"}, {"input": "14\n4 10 7 13 27 28 13 34 16 18 39 26 29 22\n", "output": "Alice\n"}, {"input": "16\n47 27 33 49 2 47 48 9 37 39 5 24 38 38 4 32\n", "output": "Alice\n"}, {"input": "18\n38 48 13 15 18 16 44 46 17 30 16 33 43 12 9 48 31 37\n", "output": "Alice\n"}, {"input": "20\n28 10 4 31 4 49 50 1 40 43 31 49 34 16 34 38 50 40 10 10\n", "output": "Alice\n"}, {"input": "22\n37 35 37 35 39 42 35 35 49 50 42 35 40 36 35 35 35 43 35 35 35 35\n", "output": "Bob\n"}, {"input": "24\n31 6 41 46 36 37 6 50 50 6 6 6 6 6 6 6 39 45 40 6 35 6 6 6\n", "output": "Bob\n"}, {"input": "26\n8 47 49 44 33 43 33 8 29 41 8 8 8 8 8 8 41 47 8 8 8 8 43 8 32 8\n", "output": "Bob\n"}, {"input": "28\n48 14 22 14 14 14 14 14 47 39 14 36 14 14 49 41 36 45 14 34 14 14 14 14 14 45 25 41\n", "output": "Bob\n"}, {"input": "30\n7 47 7 40 35 37 7 42 40 7 7 7 7 7 35 7 47 7 34 7 7 33 7 7 41 7 46 33 44 7\n", "output": "Bob\n"}, {"input": "50\n44 25 36 44 25 7 28 33 35 16 31 17 50 48 6 42 47 36 9 11 31 27 28 20 34 47 24 44 38 50 46 9 38 28 9 10 28 42 37 43 29 42 38 43 41 25 12 29 26 36\n", "output": "Alice\n"}, {"input": "50\n42 4 18 29 37 36 41 41 34 32 1 50 15 25 46 22 9 38 48 49 5 50 2 14 15 10 27 34 46 50 30 6 19 39 45 36 39 50 8 13 13 24 27 5 25 19 42 46 11 30\n", "output": "Alice\n"}, {"input": "50\n40 9 43 18 39 35 35 46 48 49 26 34 28 50 14 34 17 3 13 8 8 48 17 43 42 21 43 30 45 12 43 13 25 30 39 5 19 3 19 6 12 30 19 46 48 24 14 33 6 19\n", "output": "Alice\n"}, {"input": "50\n11 6 26 45 49 26 50 31 21 21 10 19 39 50 16 8 39 35 29 14 17 9 34 13 44 28 20 23 32 37 16 4 21 40 10 42 2 2 38 30 9 24 42 30 30 15 18 38 47 12\n", "output": "Alice\n"}, {"input": "50\n20 12 45 12 15 49 45 7 27 20 32 47 50 16 37 4 9 33 5 27 6 18 42 35 21 9 27 14 50 24 23 5 46 12 29 45 17 38 20 12 32 27 43 49 17 4 45 2 50 4\n", "output": "Alice\n"}, {"input": "40\n48 29 48 31 39 16 17 11 20 11 33 29 18 42 39 26 43 43 22 28 1 5 33 49 7 18 6 3 33 41 41 40 25 25 37 47 12 42 23 27\n", "output": "Alice\n"}, {"input": "40\n32 32 34 38 1 50 18 26 16 14 13 26 10 15 20 28 19 49 17 14 8 6 45 32 15 37 14 15 21 21 42 33 12 14 34 44 38 25 24 15\n", "output": "Alice\n"}, {"input": "40\n36 34 16 47 49 45 46 16 46 2 30 23 2 20 4 8 28 38 20 3 50 40 21 48 45 25 41 14 37 17 5 3 33 33 49 47 48 32 47 2\n", "output": "Alice\n"}, {"input": "40\n46 2 26 49 34 10 12 47 36 44 15 36 48 23 30 4 36 26 23 32 31 13 34 15 10 41 17 32 33 25 12 36 9 31 25 9 46 28 6 30\n", "output": "Alice\n"}, {"input": "40\n17 8 23 16 25 37 11 16 16 29 25 38 31 45 14 46 40 24 49 44 21 12 29 18 33 35 7 47 41 48 24 39 8 37 29 13 12 21 44 19\n", "output": "Alice\n"}, {"input": "42\n13 33 2 18 5 25 29 15 38 11 49 14 38 16 34 3 5 35 1 39 45 4 32 15 30 23 48 22 9 34 42 34 8 36 39 5 27 22 8 38 26 31\n", "output": "Alice\n"}, {"input": "42\n7 6 9 5 18 8 16 46 10 48 43 20 14 20 16 24 2 12 26 5 9 48 4 47 39 31 2 30 36 47 10 43 16 19 50 48 18 43 35 38 9 45\n", "output": "Alice\n"}, {"input": "42\n49 46 12 3 38 7 32 7 25 40 20 25 2 43 17 28 28 50 35 35 22 42 15 13 44 14 27 30 26 7 29 31 40 39 18 42 11 3 32 48 34 11\n", "output": "Alice\n"}, {"input": "42\n3 50 33 31 8 19 3 36 41 50 2 22 9 40 39 22 30 34 43 25 42 39 40 8 18 1 25 13 50 11 48 10 11 4 3 47 2 35 25 39 31 36\n", "output": "Alice\n"}, {"input": "42\n20 38 27 15 6 17 21 42 31 38 43 20 31 12 29 3 11 45 44 22 10 2 14 20 39 33 47 6 11 43 41 1 14 27 24 41 9 4 7 26 8 21\n", "output": "Alice\n"}, {"input": "44\n50 32 33 26 39 26 26 46 26 28 26 38 26 26 26 32 26 46 26 35 28 26 41 37 26 41 26 26 45 26 44 50 42 26 39 26 46 26 26 28 26 26 26 26\n", "output": "Bob\n"}, {"input": "44\n45 18 18 39 35 30 34 18 28 18 47 18 18 18 18 18 40 18 18 49 31 35 18 18 35 36 18 18 28 18 18 42 32 18 18 31 37 27 18 18 18 37 18 37\n", "output": "Bob\n"}, {"input": "44\n28 28 36 40 28 28 35 28 28 33 33 28 28 28 28 47 28 43 28 28 35 38 49 40 28 28 34 39 45 32 28 28 28 50 39 28 32 28 50 32 28 33 28 28\n", "output": "Bob\n"}, {"input": "44\n27 40 39 38 27 49 27 33 45 34 27 39 49 27 27 27 27 27 27 39 49 27 27 27 27 27 38 39 43 44 45 44 33 27 27 27 27 27 42 27 47 27 42 27\n", "output": "Bob\n"}, {"input": "44\n37 43 3 3 36 45 3 3 30 3 30 29 3 3 3 3 36 34 31 38 3 38 3 48 3 3 3 3 46 49 30 50 3 42 3 3 3 37 3 3 41 3 49 3\n", "output": "Bob\n"}, {"input": "46\n35 37 27 27 27 33 27 34 32 34 32 38 27 50 27 27 29 27 35 45 27 27 27 32 30 27 27 27 47 27 27 27 27 38 33 27 43 49 29 27 31 27 27 27 38 27\n", "output": "Bob\n"}, {"input": "46\n15 15 36 15 30 15 15 45 20 29 41 37 15 15 15 15 22 22 38 15 15 15 15 47 15 39 15 15 15 15 42 15 15 34 24 30 21 39 15 22 15 24 15 35 15 21\n", "output": "Bob\n"}, {"input": "46\n39 18 30 18 43 18 18 18 18 18 18 36 18 39 32 46 32 18 18 18 18 18 18 38 43 44 48 18 34 35 18 46 30 18 18 45 43 18 18 18 44 30 18 18 44 33\n", "output": "Bob\n"}, {"input": "46\n14 14 14 14 14 14 30 45 42 30 42 14 14 34 14 14 42 28 14 14 37 14 25 49 34 14 46 14 14 40 49 44 40 47 14 14 14 26 14 14 14 46 14 31 30 14\n", "output": "Bob\n"}, {"input": "46\n14 14 48 14 14 22 14 14 14 14 40 14 14 33 14 32 49 40 14 34 14 14 14 14 46 42 14 43 14 41 22 50 14 32 14 49 14 31 47 50 47 14 14 14 44 22\n", "output": "Bob\n"}, {"input": "48\n9 36 47 31 48 33 39 9 23 3 18 44 33 49 26 10 45 12 28 30 5 22 41 27 19 44 44 27 9 46 24 22 11 28 41 48 45 1 10 42 19 34 40 8 36 48 43 50\n", "output": "Alice\n"}, {"input": "48\n12 19 22 48 21 19 18 49 10 50 31 40 19 19 44 33 6 12 31 11 5 47 26 48 2 17 6 37 17 25 20 42 30 35 37 41 32 45 47 38 44 41 20 31 47 39 3 45\n", "output": "Alice\n"}, {"input": "48\n33 47 6 10 28 22 41 45 27 19 45 18 29 10 35 18 39 29 8 10 9 1 9 23 10 11 3 14 12 15 35 29 29 18 12 49 27 18 18 45 29 32 15 21 34 1 43 9\n", "output": "Alice\n"}, {"input": "48\n13 25 45 45 23 29 11 30 40 10 49 32 44 50 35 7 48 37 17 43 45 50 48 31 41 6 3 32 33 22 41 4 1 30 16 9 48 46 17 29 45 12 49 42 21 1 13 10\n", "output": "Alice\n"}, {"input": "48\n47 3 12 9 37 19 8 9 10 11 48 28 6 8 12 48 44 1 15 8 48 10 33 11 42 24 45 27 8 30 48 40 3 15 34 17 2 32 30 50 9 11 7 33 41 33 27 17\n", "output": "Alice\n"}, {"input": "50\n44 4 19 9 41 48 31 39 30 16 27 38 37 45 12 36 37 25 35 19 43 22 36 26 26 49 23 4 33 2 31 26 36 38 41 30 42 18 45 24 23 14 32 37 44 13 4 39 46 7\n", "output": "Alice\n"}, {"input": "50\n4 36 10 48 17 28 14 7 47 38 13 3 1 48 28 21 12 49 1 35 16 9 15 42 36 34 10 28 27 23 47 36 33 44 44 26 3 43 31 32 26 36 41 44 10 8 29 1 36 9\n", "output": "Alice\n"}, {"input": "50\n13 10 50 35 23 34 47 25 39 11 50 41 20 48 10 10 1 2 41 16 14 50 49 42 48 39 16 9 31 30 22 2 25 40 6 8 34 4 2 46 14 6 6 38 45 30 27 36 49 18\n", "output": "Alice\n"}, {"input": "50\n42 31 49 11 28 38 49 32 15 22 10 18 43 39 46 32 10 19 13 32 19 40 34 28 28 39 19 3 1 47 10 18 19 31 21 7 39 37 34 45 19 21 35 46 10 24 45 33 20 40\n", "output": "Alice\n"}, {"input": "50\n28 30 40 25 47 47 3 22 28 10 37 15 11 18 31 36 35 18 34 3 21 16 24 29 12 29 42 23 25 8 7 10 43 24 40 29 3 6 14 28 2 32 29 18 47 4 6 45 42 40\n", "output": "Alice\n"}, {"input": "4\n1 4 4 4\n", "output": "Alice\n"}, {"input": "4\n1 2 2 2\n", "output": "Alice\n"}, {"input": "2\n1 1\n", "output": "Bob\n"}, {"input": "4\n3 4 4 4\n", "output": "Alice\n"}, {"input": "4\n2 2 2 1\n", "output": "Alice\n"}, {"input": "4\n1 3 3 3\n", "output": "Alice\n"}, {"input": "6\n4 4 4 4 4 1\n", "output": "Alice\n"}, {"input": "4\n1 50 50 50\n", "output": "Alice\n"}, {"input": "6\n1 2 2 2 2 3\n", "output": "Alice\n"}, {"input": "4\n1 2 2 3\n", "output": "Alice\n"}, {"input": "4\n2 1 1 1\n", "output": "Bob\n"}, {"input": "6\n1 1 2 2 3 3\n", "output": "Alice\n"}, {"input": "4\n1 1 1 4\n", "output": "Bob\n"}, {"input": "6\n1 2 2 2 2 2\n", "output": "Alice\n"}, {"input": "6\n1 2 2 2 2 4\n", "output": "Alice\n"}, {"input": "4\n2 3 3 3\n", "output": "Alice\n"}, {"input": "6\n1 1 2 2 2 2\n", "output": "Alice\n"}, {"input": "8\n1 1 1 1 1 1 6 6\n", "output": "Bob\n"}, {"input": "8\n1 1 2 2 2 2 2 2\n", "output": "Alice\n"}, {"input": "8\n1 1 1 1 1 2 2 2\n", "output": "Bob\n"}] |
|
229 | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers a_1, a_2, ..., a_{n}. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.
-----Input-----
The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the number of integers in the Filya's array. The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9) — elements of the array.
-----Output-----
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).
-----Examples-----
Input
5
1 3 3 2 1
Output
YES
Input
5
1 2 3 4 5
Output
NO
-----Note-----
In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | interview | [{"code": "read = lambda: list(map(int, input().split()))\nn = int(input())\na = list(read())\ns = set()\nfor i in a:\n s.add(i)\nf1 = len(s) < 3\nf2 = len(s) == 3 and max(s) + min(s) == 2 * sorted(s)[1]\nprint('YES' if f1 or f2 else 'NO')\n", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}, {"code": "n = int(input())\na = map(int, input().split())\nb = set(a)\nif len(b) <= 2:\n\tprint(\"YES\")\nelif len(b) > 3:\n\tprint(\"NO\")\nelse:\n\ta = []\n\tfor i in b:\n\t\ta.append(i)\n\ta.sort()\n\tif a[1] - a[0] == a[2] - a[1]:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\")", "passed": true, "time": 0.16, "memory": 14576.0, "status": "done"}, {"code": "n = int(input())\na = sorted(list(set(list(map(int, input().split())))))\nif len((a)) < 3:\n print('YES')\nelif len((a)) > 3:\n print('NO')\nelse:\n if a[1] - a[0] == a[2] - a[1]:\n print('YES')\n else:\n print('NO')", "passed": true, "time": 0.15, "memory": 14604.0, "status": "done"}, {"code": "n=int(input())\nip=list(map(int,input().split()))\ncount=0\nused=[]\nfor i in ip:\n if i not in used and count<5:\n used.append(i)\n count+=1\nif count<=2:\n print('YES')\nelif count>3:\n print('NO')\nelse:\n used=sorted(used)\n if used[1]-used[0]==used[2]-used[1]:\n print('YES')\n else:\n print('NO')\n", "passed": true, "time": 0.86, "memory": 14372.0, "status": "done"}, {"code": "input()\na = list(map(int, input().split()))\na = sorted(set(a))\n\nif len(a) >= 4:\n print(\"NO\")\nelif len(a) <= 2:\n print(\"YES\")\nelse:\n if a[1] - a[0] == a[2] - a[1]:\n print(\"YES\")\n else:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14404.0, "status": "done"}, {"code": "n = int(input())\na = [int(x) for x in input().split()]\n\nd = sorted(set(a))\n\nif len(d) <= 2 or len(d) == 3 and d[0]+d[2] == 2*d[1]:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.21, "memory": 14324.0, "status": "done"}, {"code": "3\n\nn = int(input())\narray = list(set(list(map(int, input().split()))))\narray.sort()\n\nif len(array) < 3:\n print(\"YES\")\nelif len(array) > 3 or array[1] - array[0] != array[2] - array[1]:\n print(\"NO\")\nelse:\n print(\"YES\")\n\n", "passed": true, "time": 0.16, "memory": 14320.0, "status": "done"}, {"code": "n = int(input())\na = set(map(int, input().split()))\nif(len(a) > 3):\n print(\"NO\")\nelif(len(a) < 3):\n print(\"YES\")\nelse:\n a = list(a)\n a.sort()\n if((a[0] + a[2]) / 2 == a[1]):\n print(\"YES\")\n else:\n print(\"NO\")", "passed": true, "time": 0.17, "memory": 14416.0, "status": "done"}, {"code": "n = int(input())\nA = list(map(int, input().split()))\nB = []\nl = 0\nfor i in A:\n\tif i not in B:\n\t\tB.append(i)\n\t\tl += 1\n\tif l > 3:\n\t\tprint(\"NO\")\n\t\treturn\nB.sort()\nif l < 3:\n\tprint(\"YES\")\nelse:\n\tif B[0] + B[2] == 2 * B[1]:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\")\n", "passed": true, "time": 0.26, "memory": 14520.0, "status": "done"}, {"code": "from sys import stdin\n\nn = int(stdin.readline())\n\nnumbers = set(int(x) for x in stdin.readline().split())\n\nif len(numbers) > 3:\n print('NO')\nelif len(numbers) < 3:\n print('YES')\nelse:\n s = sorted(numbers)\n if s[2] - s[1] == s[1] - s[0]:\n print('YES')\n else:\n print('NO')\n", "passed": true, "time": 0.22, "memory": 14508.0, "status": "done"}, {"code": "n = int(input())\ndata = list(map(int,input().split()))\nnums = set(data)\nif len(nums)<=2:\n print(\"YES\")\nelif len(nums)==3:\n tmp = list(sorted(list(nums)))\n if tmp[1]-tmp[0]==tmp[2]-tmp[1]:\n print(\"YES\")\n else:\n print(\"NO\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.19, "memory": 14552.0, "status": "done"}, {"code": "def solve():\n input()\n a = list(map(int, input().split()))\n nums = set()\n for n in a:\n nums.add(n)\n\n if len(nums) <= 2:\n print('YES')\n return\n\n if len(nums) == 3:\n ma = max(nums)\n mi = min(nums)\n nums.remove(ma)\n nums.remove(mi)\n mid = nums.pop()\n if ma - mid == mid - mi:\n print('YES')\n return\n\n print('NO')\n\n\ndef main():\n solve()\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14424.0, "status": "done"}, {"code": "n, a = int(input()), set(map(int, input().split()))\nif (len(a) <3):\n print(\"YES\")\nelif len(a) == 3:\n a = sorted(list(a))\n if a[1] - a[0] == a[2] - a[1]:\n print(\"YES\")\n else:\n print(\"NO\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.19, "memory": 14548.0, "status": "done"}, {"code": "from sys import stdout\nn =int(input())\ns = [int(i) for i in input().split()]\na= s[0]\nb = -1\nc = -1\nfor i in s[1:]:\n\tif i!=a and i!=b and i!=c:\n\t\tif b <0:\n\t\t\tb = i\n\t\telif c <0:\n\t\t\tc = i\n\t\telse:\n\t\t\tprint(\"NO\")\n\t\t\tbreak\nelse:\n\tif c == -1:\n\t\tprint(\"YES\")\n\telse:\n\t\tr = (max(a,b,c) - min(a,b,c))/2+ min(a,b,c)\n\t\tif a==r or b ==r or c == r:\n\t\t\tprint(\"YES\")\n\t\telse:\n\t\t\tprint(\"NO\")\n\t\t\n", "passed": true, "time": 0.16, "memory": 14564.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int,input().split()))\n\ns = set()\nfor el in a:\n s.add(el)\n if len(s) > 3:\n break\n\nif len(s) <= 2:\n print('YES')\nelif len(s) > 3:\n print('NO')\nelse:\n sl = sorted(list(s))\n print('YES' if sl[0] + sl[2] == 2 * sl[1] else 'NO')\n", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}, {"code": "from collections import defaultdict\nimport sys, os, math\n\ndef __starting_point():\n #n, m = list(map(int, input().split()))\n #sys.stdout.flush()\n n = int(input())\n arr = list(map(int, input().split()))\n temp = []\n for num in arr:\n if num not in temp:\n temp.append(num)\n if len(temp) > 3:\n print(\"NO\")\n return\n temp.sort()\n if len(temp) < 3 or temp[0] + temp[2] == 2 * temp[1]:\n print(\"YES\")\n else:\n print(\"NO\")\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14396.0, "status": "done"}, {"code": "temp=input()\ntemp=input().split()\narr=[int(k) for k in temp]\n\ns=sorted(list(set(arr)))\n\nif len(s)>3:\n\tprint(\"NO\")\nelif len(s)<3:\n\tprint(\"YES\")\nelse:\n\tif s[2]+s[0]==2*s[1]:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14260.0, "status": "done"}, {"code": "n = int(input())\na = sorted(set(map(int, input().split())))\nif len(a) > 3:\n print(\"NO\") \nelif len(a) == 1:\n print(\"YES\")\nelif len(a) == 2:\n print('YES')\nelse:\n if ((a[0] + a[2]) / 2 != a[1]):\n print('NO')\n else:\n print('YES')", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}, {"code": "import sys, math\nn = int(input())\nz = list(map(int, input().split()))\na = max(z)\nb = min(z)\ny = (a + b) // 2\nx1 = a - y\nx2 = a - b\nflag = [0, 0, 0]\nfor i in range(n):\n if z[i] == y:\n flag[0] += 1\n else:\n if z[i] < y and z[i] + x1 == y:\n flag[0] += 1\n else:\n if z[i] - x1 == y:\n flag[0] += 1\n if z[i] + x2 == a or z[i] == a:\n flag[1] += 1\n if z[i] - x2 == b or z[i] == b:\n flag[2] += 1\nif flag.count(n) >= 1:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.14, "memory": 14628.0, "status": "done"}, {"code": "N = int(input())\nA = set(list(map(int, input().split())))\nif len(A) == 1:\n print(\"YES\")\nelif len(A) == 2:\n print(\"YES\")\nelif len(A) == 3:\n A = list(A)\n max_v = max(A)\n min_v = min(A)\n md_v = sum(A) - max_v - min_v\n if md_v * 2 == max_v + min_v:\n print(\"YES\")\n else:\n print(\"NO\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14464.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int,input().split()))\nr = set(a)\nif len(r)<=3:\n r = list(r)\n r.sort()\n if len(r)==1 or len(r)==2 or r[1]-r[0] == r[2]-r[1]:\n print('YES')\n else:\n print('NO')\nelse:\n print('NO')", "passed": true, "time": 0.15, "memory": 14344.0, "status": "done"}, {"code": "n = int(input())\nl = list(map(int, input().split()))\ns = set()\nfor i in l:\n s.add(i)\nl = list(s)\nl.sort()\nif len(l) > 3:\n print('NO')\nif len(l) == 3:\n if (l[0] + l[2]) / 2 == l[1]:\n print('YES')\n else:\n print('NO')\nif len(l) <= 2:\n print('YES')", "passed": true, "time": 0.14, "memory": 14592.0, "status": "done"}, {"code": "import sys\n\nn = int(input())\na = [int(x) for x in input().split()]\naa = list(set(a))\naa.sort()\n\nif len(aa) > 3:\n print(\"NO\")\n return\nif len(aa) < 3:\n print(\"YES\")\n return\nif (aa[0] + aa[2]) % 2 != 0:\n print(\"NO\")\n return\n\nif 2 * aa[1] == aa[0] + aa[2]:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14576.0, "status": "done"}, {"code": "#!/usr/local/env python3\n# -*- encoding: utf-8 -*-\nimport sys\n\n\ndef readnlines(f_in):\n n = int(f_in.readline().strip())\n s = set()\n content = f_in.readline().strip()\n for i, line in zip(list(range(n)), content.split(' ')):\n if line.isdigit():\n s.add(int(line))\n else:\n s.add(line)\n return s\n\n\ndef print_args():\n print(\"Recieved {} arguments = {}.\".format(len(sys.argv), sys.argv))\n\n\ndef intersect(l1, r1, l2, r2):\n left = max(l1, l2)\n right = min(r1, r2)\n return left, right, max(0, right - left + 1)\n\n\ndef solve():\n m = readnlines(sys.stdin)\n uniques = sorted(m) \n #print(\"len(set(m)) = {}\".format(len(set(m))))\n #print(uniques)\n if len(uniques) > 3:\n return \"NO\"\n elif len(uniques) == 3:\n if uniques[2] + uniques[0] == 2 * uniques[1]:\n return \"YES\"\n return \"NO\"\n else:\n return \"YES\"\n\n\ndef __starting_point():\n ans = solve()\n print(ans)\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14492.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\n\nb = set(a)\n\nif len(b) >= 4:\n print(\"NO\")\nelse:\n x = list(b)\n x.sort()\n if len(x) == 1:\n print(\"YES\")\n elif len(x) == 2:\n print(\"YES\")\n else:\n if x[1] * 2 == x[0] + x[2]:\n print(\"YES\")\n else:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14524.0, "status": "done"}] | [{"input": "5\n1 3 3 2 1\n", "output": "YES\n"}, {"input": "5\n1 2 3 4 5\n", "output": "NO\n"}, {"input": "2\n1 2\n", "output": "YES\n"}, {"input": "3\n1 2 3\n", "output": "YES\n"}, {"input": "3\n1 1 1\n", "output": "YES\n"}, {"input": "2\n1 1000000000\n", "output": "YES\n"}, {"input": "4\n1 2 3 4\n", "output": "NO\n"}, {"input": "10\n1 1 1 1 1 2 2 2 2 2\n", "output": "YES\n"}, {"input": "2\n4 2\n", "output": "YES\n"}, {"input": "4\n1 1 4 7\n", "output": "YES\n"}, {"input": "3\n99999999 1 50000000\n", "output": "YES\n"}, {"input": "1\n0\n", "output": "YES\n"}, {"input": "5\n0 0 0 0 0\n", "output": "YES\n"}, {"input": "4\n4 2 2 1\n", "output": "NO\n"}, {"input": "3\n1 4 2\n", "output": "NO\n"}, {"input": "3\n1 4 100\n", "output": "NO\n"}, {"input": "3\n2 5 11\n", "output": "NO\n"}, {"input": "3\n1 4 6\n", "output": "NO\n"}, {"input": "3\n1 2 4\n", "output": "NO\n"}, {"input": "3\n1 2 7\n", "output": "NO\n"}, {"input": "5\n1 1 1 4 5\n", "output": "NO\n"}, {"input": "2\n100000001 100000003\n", "output": "YES\n"}, {"input": "3\n7 4 5\n", "output": "NO\n"}, {"input": "3\n2 3 5\n", "output": "NO\n"}, {"input": "3\n1 2 5\n", "output": "NO\n"}, {"input": "2\n2 3\n", "output": "YES\n"}, {"input": "3\n2 100 29\n", "output": "NO\n"}, {"input": "3\n0 1 5\n", "output": "NO\n"}, {"input": "3\n1 3 6\n", "output": "NO\n"}, {"input": "3\n2 1 3\n", "output": "YES\n"}, {"input": "3\n1 5 100\n", "output": "NO\n"}, {"input": "3\n1 4 8\n", "output": "NO\n"}, {"input": "3\n1 7 10\n", "output": "NO\n"}, {"input": "3\n5 4 1\n", "output": "NO\n"}, {"input": "3\n1 6 10\n", "output": "NO\n"}, {"input": "4\n1 3 4 5\n", "output": "NO\n"}, {"input": "3\n1 5 4\n", "output": "NO\n"}, {"input": "5\n1 2 3 3 5\n", "output": "NO\n"}, {"input": "3\n2 3 1\n", "output": "YES\n"}, {"input": "3\n2 3 8\n", "output": "NO\n"}, {"input": "3\n0 3 5\n", "output": "NO\n"}, {"input": "3\n1 5 10\n", "output": "NO\n"}, {"input": "3\n1 7 2\n", "output": "NO\n"}, {"input": "3\n1 3 9\n", "output": "NO\n"}, {"input": "3\n1 1 2\n", "output": "YES\n"}, {"input": "7\n1 1 1 1 1 2 4\n", "output": "NO\n"}, {"input": "5\n1 4 4 4 6\n", "output": "NO\n"}, {"input": "5\n1 2 2 4 4\n", "output": "NO\n"}, {"input": "3\n1 9 10\n", "output": "NO\n"}, {"input": "8\n1 1 1 1 1 1 2 3\n", "output": "YES\n"}, {"input": "3\n1 2 100\n", "output": "NO\n"}, {"input": "3\n1 3 4\n", "output": "NO\n"}, {"input": "3\n1 15 14\n", "output": "NO\n"}, {"input": "3\n1 3 8\n", "output": "NO\n"}, {"input": "3\n1 2 10\n", "output": "NO\n"}, {"input": "4\n2 2 4 5\n", "output": "NO\n"}, {"input": "3\n1 3 5\n", "output": "YES\n"}, {"input": "5\n3 6 7 8 9\n", "output": "NO\n"}, {"input": "3\n7 6 8\n", "output": "YES\n"}, {"input": "3\n3 2 1\n", "output": "YES\n"}, {"input": "5\n1 2 2 2 3\n", "output": "YES\n"}, {"input": "3\n4 6 7\n", "output": "NO\n"}, {"input": "3\n2 0 4\n", "output": "YES\n"}, {"input": "4\n10 20 21 30\n", "output": "NO\n"}, {"input": "4\n0 2 3 4\n", "output": "NO\n"}, {"input": "3\n3 6 12\n", "output": "NO\n"}, {"input": "5\n0 0 1 3 5\n", "output": "NO\n"}, {"input": "3\n3 5 8\n", "output": "NO\n"}, {"input": "3\n1 4 4\n", "output": "YES\n"}, {"input": "4\n2 4 5 6\n", "output": "NO\n"}] |
|
230 | Given is a string S of length N.
Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping.
More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following:
- l_1 + len \leq l_2
- S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)
If there is no such integer len, print 0.
-----Constraints-----
- 2 \leq N \leq 5 \times 10^3
- |S| = N
- S consists of lowercase English letters.
-----Input-----
Input is given from Standard Input in the following format:
N
S
-----Output-----
Print the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping. If there is no such non-empty string, print 0 instead.
-----Sample Input-----
5
ababa
-----Sample Output-----
2
The strings satisfying the conditions are: a, b, ab, and ba. The maximum length among them is 2, which is the answer.
Note that aba occurs twice in S as contiguous substrings, but there is no pair of integers l_1 and l_2 mentioned in the statement such that l_1 + len \leq l_2. | interview | [{"code": "n = int(input())\ns = input()\nj = 1\nresult = []\nfor i in range(n):\n while (j < n-1) and (s[i:j] in s[j:]):\n j += 1\n result.append(j-i-1)\nprint(max(result))", "passed": true, "time": 2.94, "memory": 14920.0, "status": "done"}, {"code": "def main():\n import sys\n input = sys.stdin.readline\n sys.setrecursionlimit(10**7)\n from collections import Counter, deque\n #from collections import defaultdict\n from itertools import combinations, permutations, accumulate, groupby, product\n from bisect import bisect_left,bisect_right\n from heapq import heapify, heappop, heappush\n import math\n\n #inf = 10**17\n #mod = 10**9 + 7\n\n n = int(input())\n s = input().rstrip()\n l, r = 0, 0\n res = 0\n while r < n:\n r += 1\n if not s[l:r] in s[r:]:\n l += 1\n res = max(res, r-l)\n print(res)\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 5.35, "memory": 14896.0, "status": "done"}, {"code": "from collections import defaultdict as dd\nN = int(input())\ns = str(input())\nmaxlen = N//2\n\ndef solve(tgt):\n dic = dd(int)\n st = s[tgt:2*tgt]\n dic[st] += 1\n ls = [st]\n for char in s[2*tgt:]:\n st = st[1:]+char\n dic[st] += 1\n ls.append(st)\n st = s[:tgt]\n if dic[st] > 0:\n return True\n dic[ls[0]] -= 1\n for i,char in enumerate(s[tgt:N-tgt]):\n st = st[1:]+char\n if dic[st] > 0:\n return True\n dic[ls[i+1]] -= 1\n return False\n\nng = maxlen + 1\nok = 0\nwhile ng-ok > 1:\n tgt = (ok+ng)//2\n if solve(tgt):\n ok = tgt\n else:\n ng = tgt\nprint(ok)\n", "passed": true, "time": 3.36, "memory": 18428.0, "status": "done"}, {"code": "n=int(input())\ns=input()\nl=0\nr=n\nwhile r-l!=1:\n mid=(r+l)//2\n dic={}\n flag=False\n for i in range(n-mid+1):\n tmp=s[i:i+mid]\n if tmp not in dic:\n dic[tmp]=i+mid\n else:\n if dic[tmp]<=i:\n flag=True\n break\n if flag==True:\n l=mid\n else:\n r=mid\nprint(l)", "passed": true, "time": 2.77, "memory": 19228.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nret = 0\nfor l in range(n):\n while s[l:l+ret+1] in s[l+ret+1:]:\n ret += 1\nprint(ret)", "passed": true, "time": 3.61, "memory": 14912.0, "status": "done"}, {"code": "N = int(input())\nS = input()\n\ndef f(m):\n se = set()\n arr = [None]*N\n for i in range(0,N-m+1):\n if i >= m:\n se.add(arr[i-m])\n arr[i] = S[i:i+m]\n if arr[i] in se:\n return True\n return False\n\nl = 0\nr = N//2+1\nwhile (r-l)>1:\n mid = (r+l)//2\n if f(mid):\n l = mid\n else:\n r = mid\nprint(l)\n", "passed": true, "time": 2.3, "memory": 19072.0, "status": "done"}, {"code": "from typing import List, Tuple\n\n\nclass RollingHash:\n \"\"\"Rolling Hash\"\"\"\n\n __slots__ = [\"_base\", \"_mod\", \"_hash\", \"_power\"]\n\n def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):\n self._base = base\n self._mod = mod\n self._hash, self._power = self._build(source)\n\n def _build(self, source: str) -> Tuple[List[int], List[int]]:\n \"\"\"Compute \"hash\" and \"mod of power of base\" of interval [0, right).\"\"\"\n length = len(source)\n hash_, power = [0] * (length + 1), [0] * (length + 1)\n power[0] = 1\n for i, c in enumerate(source, 1):\n hash_[i] = (hash_[i - 1] * self._base + ord(c)) % self._mod\n power[i] = power[i - 1] * self._base % self._mod\n return hash_, power\n\n def get_hash(self, left: int, right: int):\n \"\"\"Return hash of interval [left, right).\"\"\"\n return (\n self._hash[right] - self._hash[left] * self._power[right - left]\n ) % self._mod\n\n\ndef abc141_e():\n # https://atcoder.jp/contests/abc141/tasks/abc141_e\n N = int(input())\n S = input().rstrip()\n\n rh = RollingHash(S)\n ok, ng = 0, N // 2 + 1\n while ng - ok > 1:\n mid = (ok + ng) // 2\n flg = False\n memo = set()\n for i in range(N - 2 * mid + 1):\n memo.add(rh.get_hash(i, i + mid))\n if rh.get_hash(i + mid, i + 2 * mid) in memo:\n flg = True\n break\n if flg:\n ok = mid # next mid will be longer\n else:\n ng = mid # next mid will be shorter\n\n print(ok) # max length of substrings appeared twice or more\n\n\ndef __starting_point():\n abc141_e()\n\n__starting_point()", "passed": true, "time": 2.12, "memory": 16052.0, "status": "done"}, {"code": "import random\nfrom collections import defaultdict\n\n\nclass RollingHash():\n\n def __init__(self, S, b=3491, m=999999937):\n \"\"\"\u4efb\u610f\u306e\u57fa\u6570\u3068\u6cd5\u3067\u30cf\u30c3\u30b7\u30e5\u3092\u751f\u6210\u3059\u308b\"\"\"\n n = len(S)\n self.prefix = prefix = [0] * (n+1)\n self.power = power = [1] * (n+1)\n self.b = b\n self.m = m\n for i in range(n):\n c = ord(S[i])\n prefix[i+1] = (prefix[i] * b + c) % m\n power[i+1] = (power[i] * b) % m\n \n def get(self, l, r):\n \"\"\"S[l, r) \u306e\u30cf\u30c3\u30b7\u30e5\u3092\u6c42\u3081\u308b\"\"\"\n return (self.prefix[r] - self.power[r-l] * self.prefix[l]) % self.m\n \n def concat(self, h1, h2, l2):\n \"\"\"S1+S2 \u306e\u30cf\u30c3\u30b7\u30e5\u3092\u3001\u305d\u308c\u305e\u308c\u306e\u30cf\u30c3\u30b7\u30e5\u304b\u3089\u6c42\u3081\u308b\"\"\"\n return (self.power[l2] * h1 + h2) % self.m\n \n def lcp(self, l1, r1, l2, r2):\n \"\"\"S[l1, r1) \u3068S[l2, r2) \u306e\u6700\u5927\u5171\u901a\u63a5\u982d\u8f9e\u3092\u6c42\u3081\u308b\"\"\"\n low = 0\n high = min(r1-l1, r2-l2) + 1\n while high - low > 1:\n mid = (high + low) // 2\n if self.get(l1, l1 + mid) == self.get(l2, l2 + mid):\n low = mid\n else:\n high = mid\n return low\n\n\ndef read():\n N = int(input().strip())\n S = input().strip()\n return N, S\n\n\ndef solve(N, S):\n ans = []\n for m in [999999937, 10**9+7]:\n b = random.randint(10000, m-1)\n rh = RollingHash(S, b=b, m=m)\n low = 0\n high = (N+1) // 2 + 1\n dmax = defaultdict(int)\n dmin = defaultdict(int)\n while high - low > 1:\n dmax.clear()\n dmin.clear()\n mid = (high + low) // 2\n for i in range(0, N-mid+1):\n h = rh.get(i, i+mid)\n dmax[h] = max(dmax[h], i+1)\n dmin[h] = max(dmin[h], N+1-i)\n is_match = False\n for h in dmax.keys():\n if dmax[h] - (N+2 - dmin[h]) >= mid:\n is_match = True\n break\n if is_match:\n low = mid\n else:\n high = mid\n ans.append(low)\n return min(ans)\n\n\ndef __starting_point():\n inputs = read()\n outputs = solve(*inputs)\n if outputs is not None:\n print(\"%s\" % str(outputs))\n__starting_point()", "passed": true, "time": 8.09, "memory": 15332.0, "status": "done"}, {"code": "from collections import defaultdict\n\nclass RollingHash(object):\n def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):\n self.S = S\n self.N = N = len(S)\n self.MOD = MOD\n self.BASE = BASE\n self.S_arr = [ord(x) for x in S]\n\n self.POWER = [1] * (N + 1)\n self.HASH = [0] * (N + 1)\n p, h = 1, 0\n for i in range(N):\n self.POWER[i + 1] = p = (p * BASE) % MOD\n self.HASH[i + 1] = h = (h * BASE + self.S_arr[i]) % MOD\n\n def hash(self, l: int, r: int):\n # get hash for S[l:r]\n _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD\n return _hash\n\ndef main():\n N = int(input())\n S = input()\n MOD = 998244353\n rs = RollingHash(S, MOD=MOD, BASE=37)\n h, p = rs.HASH, rs.POWER\n\n left, right = 0, N // 2 + 1\n\n while abs(right - left) > 1:\n mid = (left + right) // 2\n ok = False\n hash_to_left = defaultdict(list)\n L = mid\n for i in range(N - L + 1):\n _hash = (h[i+L] - h[i] * p[L]) % MOD\n # hash\u304c\u885d\u7a81\u3057\u3066\u3082\u6587\u5b57\u5217\u304c\u5b8c\u5168\u306b\u4e00\u81f4\u3059\u308b\u304b\u5206\u304b\u3089\u306a\u3044\u306e\u3067\u3001\n # \u885d\u7a81\u3057\u305f\u5834\u5408\u306f\u6587\u5b57\u5217\u304c\u5b8c\u5168\u306b\u4e00\u81f4\u3059\u308b\u304b\u8abf\u3079\u3001\u304b\u3064\n # \u6587\u5b57\u5217\u540c\u58eb\u304cS\u306e\u4e2d\u3067\u91cd\u306a\u308b\u3088\u3046\u306a\u7bc4\u56f2\u306b\u306a\u3044\u5834\u5408\u306fOK\u3068\u3059\u308b\n for j in hash_to_left[_hash]:\n if j+L <= i and S[i:i+L] == S[j:j+L]:\n ok = True\n break\n if ok:\n break\n hash_to_left[_hash].append(i)\n\n \n if ok:\n left = mid\n else:\n right = mid\n\n print(left)\n # # \u9577\u3055L\u306e\u90e8\u5206\u6587\u5b57\u5217\u540c\u58eb\u304c\u3001\u7bc4\u56f2\u3092\u91cd\u306d\u305a\u540c\u3058\u6587\u5b57\u5217\u3068\u306a\u308b\u5834\u5408\u306fTrue,\n # # \u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306fFalse\u3092\u8fd4\u3059\u95a2\u6570\n # def isOK(L):\n # if L == 0:\n # return True\n # hash_to_left = defaultdict(list)\n # for i in range(N - L + 1):\n # _hash = rs.hash(i, i + L)\n # # hash\u304c\u885d\u7a81\u3057\u3066\u3082\u6587\u5b57\u5217\u304c\u5b8c\u5168\u306b\u4e00\u81f4\u3059\u308b\u304b\u5206\u304b\u3089\u306a\u3044\u306e\u3067\u3001\n # # \u885d\u7a81\u3057\u305f\u5834\u5408\u306f\u6587\u5b57\u5217\u304c\u5b8c\u5168\u306b\u4e00\u81f4\u3059\u308b\u304b\u8abf\u3079\u3001\u304b\u3064\n # # \u6587\u5b57\u5217\u540c\u58eb\u304cS\u306e\u4e2d\u3067\u91cd\u306a\u308b\u3088\u3046\u306a\u7bc4\u56f2\u306b\u306a\u3044\u5834\u5408\u306fOK\u3068\u3059\u308b\n # for j in hash_to_left[_hash]:\n # if j+L <= i and S[i:i+L] == S[j:j+L]:\n # return True\n # hash_to_left[_hash].append(i)\n\n # return False\n # # \u7bc4\u56f2\u304c\u91cd\u306a\u3089\u306a\u3044\u3053\u3068\u304c\u6761\u4ef6\u306b\u3042\u308b\u306e\u3067\u3001\u7b54\u3048\u306f\u6700\u5927\u3067\u3082N // 2\uff08\u6587\u5b57\u5217\u306e\u9577\u3055\u306e\u534a\u5206\uff09\u3068\u306a\u308b\u3002\n # # \u305f\u3060\u3057\u3001\u4e8c\u5206\u63a2\u7d22\u3059\u308b\u4e0a\u3067\u7d76\u5bfe\u306b\u7b54\u3048\u3068\u306a\u3089\u306a\u3044\u7bc4\u56f2\u3092\u542b\u3081\u305f\u3044\u306e\u3067\u3001\n # # \u63a2\u7d22\u7bc4\u56f2\u3068\u3057\u3066\u306fN // 2 + 1 \u3068\u3001+1\u3057\u3066\u304a\u304f\u3002\n # ans = binary_search(0, N // 2 + 1, isOK, search_max=True)\n # print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 3.78, "memory": 15372.0, "status": "done"}, {"code": "from collections import defaultdict\n\nclass RollingHash(object):\n def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):\n self.S = S\n self.N = N = len(S)\n self.MOD = MOD\n self.BASE = BASE\n self.S_arr = [ord(x) for x in S]\n\n self.POWER = [1] * (N + 1)\n self.HASH = [0] * (N + 1)\n p, h = 1, 0\n for i in range(N):\n self.POWER[i + 1] = p = (p * BASE) % MOD\n self.HASH[i + 1] = h = (h * BASE + self.S_arr[i]) % MOD\n\n def hash(self, l: int, r: int):\n # get hash for S[l:r]\n _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD\n # if _hash < 0:\n # _hash += self.MOD\n return _hash\n\n# \u6c4e\u7528\u7684\u306a\u4e8c\u5206\u63a2\u7d22\u306e\u30c6\u30f3\u30d7\u30ec\n# check_func(x) = true \u3068\u306a\u308bx\u306e\u6700\u5c0f\u5024\u3092\u63a2\u7d22\u3059\u308b\n# left : check_func(x) = false\u3068\u306a\u308bx\n# right: check_func(x) = true \u3068\u306a\u308bx\n# search_max: check_func(x) = true \u3068\u306a\u308bx\u306e\"\u6700\u5927\u5024\"\u3092\u63a2\u7d22\u3059\u308b\u5834\u5408\u306fTrue\n# check_func: answer <= x \u3067\u3042\u308c\u3070check_func(x) = true \u3068\u306a\u308b\u3088\u3046\u306a\u95a2\u6570\ndef binary_search(left: int, right: int, check_func, search_max:bool=False):\n # ok \u3068 ng \u306e\u3069\u3061\u3089\u304c\u5927\u304d\u3044\u304b\u308f\u304b\u3089\u306a\u3044\u3053\u3068\u3092\u8003\u616e\n while abs(right - left) > 1:\n mid = (left + right) // 2\n \n if check_func(mid) ^ search_max:\n right = mid\n # print(left, right, mid, 't')\n else:\n left = mid\n # print(left, right, mid, 'f')\n\n return left if search_max else right\n\ndef main():\n N = int(input())\n S = input()\n\n rs = RollingHash(S, MOD=998244353, BASE=37)\n\n # \u9577\u3055L\u306e\u90e8\u5206\u6587\u5b57\u5217\u540c\u58eb\u304c\u3001\u7bc4\u56f2\u3092\u91cd\u306d\u305a\u540c\u3058\u6587\u5b57\u5217\u3068\u306a\u308b\u5834\u5408\u306fTrue,\n # \u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306fFalse\u3092\u8fd4\u3059\u95a2\u6570\n def isOK(L):\n if L == 0:\n return True\n hash_to_left = defaultdict(list)\n for i in range(N - L + 1):\n _hash = rs.hash(i, i + L)\n # hash\u304c\u885d\u7a81\u3057\u3066\u3082\u6587\u5b57\u5217\u304c\u5b8c\u5168\u306b\u4e00\u81f4\u3059\u308b\u304b\u5206\u304b\u3089\u306a\u3044\u306e\u3067\u3001\n # \u885d\u7a81\u3057\u305f\u5834\u5408\u306f\u6587\u5b57\u5217\u304c\u5b8c\u5168\u306b\u4e00\u81f4\u3059\u308b\u304b\u8abf\u3079\u3001\u304b\u3064\n # \u6587\u5b57\u5217\u540c\u58eb\u304cS\u306e\u4e2d\u3067\u91cd\u306a\u308b\u3088\u3046\u306a\u7bc4\u56f2\u306b\u306a\u3044\u5834\u5408\u306fOK\u3068\u3059\u308b\n for j in hash_to_left[_hash]:\n if j+L <= i:\n return True\n hash_to_left[_hash].append(i)\n\n return False\n # \u7bc4\u56f2\u304c\u91cd\u306a\u3089\u306a\u3044\u3053\u3068\u304c\u6761\u4ef6\u306b\u3042\u308b\u306e\u3067\u3001\u7b54\u3048\u306f\u6700\u5927\u3067\u3082N // 2\uff08\u6587\u5b57\u5217\u306e\u9577\u3055\u306e\u534a\u5206\uff09\u3068\u306a\u308b\u3002\n # \u305f\u3060\u3057\u3001\u4e8c\u5206\u63a2\u7d22\u3059\u308b\u4e0a\u3067\u7d76\u5bfe\u306b\u7b54\u3048\u3068\u306a\u3089\u306a\u3044\u7bc4\u56f2\u3092\u542b\u3081\u305f\u3044\u306e\u3067\u3001\n # \u63a2\u7d22\u7bc4\u56f2\u3068\u3057\u3066\u306fN // 2 + 1 \u3068\u3001+1\u3057\u3066\u304a\u304f\u3002\n ans = binary_search(0, N // 2 + 1, isOK, search_max=True)\n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 5.41, "memory": 15304.0, "status": "done"}, {"code": "\n\n\n\"\"\"\nN <= 5 * 10**3\u3000\u306a\u306e\u3067\u3001\uff12\u91cd\u30eb\u30fc\u30d7\u3050\u3089\u3044\u306a\u3089\u9593\u306b\u5408\u3046\u304b\uff1f\n\n\u4f8b\uff13\nstrangeorange\n**range*range\n\n\u4ed6\u306b\uff12\u56de\u4ee5\u4e0a\u51fa\u3066\u304f\u308b\u3082\u306e\u3068\u3057\u3066\nr,a, \u307f\u305f\u3044\u306a\u5358\u4f53\nra, nge \u307f\u305f\u3044\u306a\u6700\u9577\u306e\u90e8\u5206\u6587\u5b57\u5217\u306e\u4e00\u90e8\n\u307f\u305f\u3044\u306a\u611f\u3058\u306a\u306e\u3067\nl,r (r=l+1~N-1)\u3092\u6301\u3063\u3066\u304a\u3044\u3066\u3001S[l:r+1] = S[r+1:XX]\u306b\u306a\u308b\u3082\u306e\u304c\u3042\u308c\u3070\u3055\u3089\u306b\u53f3\u3092\u307f\u3066\uff5e\u307f\u305f\u3044\u306a\uff1f\n\n\"\"\"\n\n\nN = int(input())\nS = input()\n\n\nl = 0\nr = 1\nans = 0\nwhile True:\n if l == N-1:\n break\n while S[l:r] in S[r:]:\n r += 1\n\n ans = max(ans, r - l - 1)\n #print(l,r, S[l:r], S[r:], ans)\n l += 1\n if l == r:\n r = l + 1\n\nprint(ans)\n\n\n", "passed": true, "time": 2.95, "memory": 15036.0, "status": "done"}, {"code": "N=int(input())\nS=input()\n\nlb=0\nrb=N+1\nwhile rb-lb>1:\n mid = (lb + rb) // 2\n x = 0\n for i, s in enumerate(S[:mid]):\n x += pow(26, i) * (ord(s) - ord('a'))\n m = pow(26, mid - 1)\n a = [x]\n for i, s in enumerate(S[mid:]):\n x -= ord(S[i]) - ord('a')\n x //= 26\n x += m * (ord(s) - ord('a'))\n a += [x]\n f = 0\n se = set([])\n for i, x in enumerate(a):\n if i >= mid:\n se.add(a[i - mid])\n if x in se:\n f = 1\n break\n if f:\n lb=mid\n else:\n rb=mid\nprint(lb)\n", "passed": true, "time": 16.72, "memory": 20744.0, "status": "done"}, {"code": "n=int(input())\ns=input()\nl=0\nr=n\nwhile r-l!=1:\n mid=(r+l)//2\n dic={}\n flag=False\n for i in range(n-mid+1):\n tmp=s[i:i+mid]\n if tmp not in dic:\n dic[tmp]=i+mid\n else:\n if dic[tmp]<=i:\n flag=True\n break\n if flag==True:\n l=mid\n else:\n r=mid\nprint(l)", "passed": true, "time": 2.68, "memory": 19216.0, "status": "done"}, {"code": "class RollingHash(object):\n def __init__(self, S, base, mod):\n self.mod = mod\n l = len(S)\n\n self.hash_lst = [0] * (l + 1)\n self.pow_lst = [1] * (l + 1)\n\n for i in range(l):\n self.hash_lst[i + 1] = (self.hash_lst[i] * base + ord(S[i])) % mod\n self.pow_lst[i + 1] = (self.pow_lst[i] * base) % mod\n\n def get_hash(self, left, right):\n return (self.hash_lst[right] - self.hash_lst[left] * self.pow_lst[right - left] % self.mod) % self.mod\n\n\nN = int(input())\nS = input()\n\nbase = 1007\nmod = pow(10, 9) + 7\nrh = RollingHash(S, base, mod)\n\nleft = 0\nright = N // 2\n\nwhile left <= right:\n mid = (left + right) // 2\n\n found_hash = {}\n found = False\n for i in range(N - mid + 1):\n h = rh.get_hash(i, i + mid)\n\n if h not in found_hash:\n found_hash[h] = i\n else:\n if found_hash[h] <= i - mid:\n found = True\n break\n\n if found:\n left = mid + 1\n else:\n right = mid - 1\n\n\nprint(right)\n", "passed": true, "time": 2.32, "memory": 15088.0, "status": "done"}, {"code": "from collections import defaultdict\n\nclass RollingHash(object):\n def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):\n self.S = S\n self.N = N = len(S)\n self.MOD = MOD\n self.BASE = BASE\n \n S_arr = [ord(x) for x in S]\n POWER = [1] * (N + 1)\n HASH = [0] * (N + 1)\n p, h = 1, 0\n for i in range(N):\n POWER[i + 1] = p = (p * BASE) % MOD\n HASH[i + 1] = h = (h * BASE + S_arr[i]) % MOD\n self.S_arr = S_arr\n self.POWER = POWER\n self.HASH = HASH\n\n def hash(self, l: int, r: int):\n # get hash for S[l:r]\n _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD\n return _hash\n\ndef main():\n N = int(input())\n S = input()\n MOD = 998244353\n rs = RollingHash(S, MOD=MOD, BASE=37)\n h, p = rs.HASH, rs.POWER\n\n left, right = 0, N // 2 + 1\n D = [0] * N\n while abs(right - left) > 1:\n mid = (left + right) // 2\n # hash_to_left = defaultdict(list)\n hashes = set()\n L = mid\n P = p[L]\n for i in range(min(L, N-2*L+1)):\n D[i] = (h[L+i] - h[i]*P) % MOD\n hashes = set()\n ok = False\n for i in range(L, N-L+1):\n hashes.add(D[i-L])\n D[i] = v = (h[L+i] - h[i]*P) % MOD\n if v in hashes:\n ok = True\n break\n if ok:\n left = mid\n else:\n right = mid\n\n print(left)\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.88, "memory": 15304.0, "status": "done"}, {"code": "def ok(l):\n # \u9577\u3055l\u306e\u9023\u7d9a\u90e8\u5206\u5217\u3067\u91cd\u306a\u3089\u305a\u306b2\u56de\u4ee5\u4e0a\u73fe\u308c\u308b\u3082\u306e\u304c\u3042\u308b\n D = {}\n for i in range(n-l+1):\n try:\n if D[S[i:i+l]]+l <= i:\n return True\n except:\n D[S[i:i+l]] = i\n return False\n\n\nn = int(input())\nS = input()\n# \u4e8c\u5206\u63a2\u7d22\u3067True\u306b\u306a\u308b\u6700\u5927\u306ek\u3092\u6c42\u3081\u308b\nl, r = 0, n+1\nwhile r-l > 1:\n c = (l+r)//2\n if ok(c):\n l = c\n else:\n r = c\nprint(l)\n", "passed": true, "time": 4.84, "memory": 19256.0, "status": "done"}, {"code": "import random\n\nclass RollingHash(object):\n def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):\n self.S = S\n self.N = N = len(S)\n self.MOD = MOD\n self.BASE = BASE\n self.S_arr = [ord(x) for x in S]\n\n self.POWER = [1] * (N + 1)\n self.HASH = [0] * (N + 1)\n p, h = 1, 0\n for i in range(N):\n self.POWER[i + 1] = p = (p * BASE) % MOD\n self.HASH[i + 1] = h = (h * BASE + self.S_arr[i]) % MOD\n\n def hash(self, l: int, r: int):\n # get hash for S[l:r]\n _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD\n return _hash\n\n# \u6c4e\u7528\u7684\u306a\u4e8c\u5206\u63a2\u7d22\u306e\u30c6\u30f3\u30d7\u30ec\n# check_func(x) = true \u3068\u306a\u308bx\u306e\u6700\u5c0f\u5024\u3092\u63a2\u7d22\u3059\u308b\n# left : check_func(x) = false\u3068\u306a\u308bx\n# right: check_func(x) = true \u3068\u306a\u308bx\n# search_max: check_func(x) = true \u3068\u306a\u308bx\u306e\"\u6700\u5927\u5024\"\u3092\u63a2\u7d22\u3059\u308b\u5834\u5408\u306fTrue\n# check_func: answer <= x \u3067\u3042\u308c\u3070check_func(x) = true \u3068\u306a\u308b\u3088\u3046\u306a\u95a2\u6570\ndef binary_search(left: int, right: int, check_func, search_max:bool=False):\n # ok \u3068 ng \u306e\u3069\u3061\u3089\u304c\u5927\u304d\u3044\u304b\u308f\u304b\u3089\u306a\u3044\u3053\u3068\u3092\u8003\u616e\n while abs(right - left) > 1:\n mid = (left + right) // 2\n \n if check_func(mid) ^ search_max:\n right = mid\n # print(left, right, mid, 't')\n else:\n left = mid\n # print(left, right, mid, 'f')\n\n return left if search_max else right\n\ndef main():\n N = int(input())\n S = input()\n MOD = 998244353\n BASE = 37 # random.randint(2, MOD-1)\n rs = RollingHash(S, MOD=MOD, BASE=BASE)\n\n D = [0] * N\n # \u9577\u3055L\u306e\u90e8\u5206\u6587\u5b57\u5217\u540c\u58eb\u304c\u3001\u7bc4\u56f2\u3092\u91cd\u306d\u305a\u540c\u3058\u6587\u5b57\u5217\u3068\u306a\u308b\u5834\u5408\u306fTrue,\n # \u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306fFalse\u3092\u8fd4\u3059\u95a2\u6570\n def isOK(L):\n if L == 0:\n return True\n \n for i in range(min(L, N - 2 * L + 1)):\n D[i] = rs.hash(i, i + L)\n hashes = set()\n for i in range(L, N - L + 1):\n # \u81ea\u5206\u3088\u308a\u958b\u59cb\u70b9\u304cL\u4ee5\u4e0a\u524d\u306e\u6587\u5b57\u5217\u306e\u30cf\u30c3\u30b7\u30e5\u3092\u691c\u7d22\u5bfe\u8c61\u306b\u8ffd\u52a0\n hashes.add(D[i - L])\n D[i] = v = rs.hash(i, i + L)\n # \u30cf\u30c3\u30b7\u30e5\u304c\u885d\u7a81\u3057\u305f\u3089\u3001\u7bc4\u56f2\u3092\u91cd\u306d\u305a\u540c\u3058\u6587\u5b57\u5217\u3068\u306a\u308b\u6587\u5b57\u5217\u304c\u5b58\u5728\u3059\u308b\u3053\u3068\u306b\u306a\u308b\n if v in hashes:\n return True\n return False\n\n # \u7bc4\u56f2\u304c\u91cd\u306a\u3089\u306a\u3044\u3053\u3068\u304c\u6761\u4ef6\u306b\u3042\u308b\u306e\u3067\u3001\u7b54\u3048\u306f\u6700\u5927\u3067\u3082N // 2\uff08\u6587\u5b57\u5217\u306e\u9577\u3055\u306e\u534a\u5206\uff09\u3068\u306a\u308b\u3002\n # \u305f\u3060\u3057\u3001\u4e8c\u5206\u63a2\u7d22\u3059\u308b\u4e0a\u3067\u7d76\u5bfe\u306b\u7b54\u3048\u3068\u306a\u3089\u306a\u3044\u7bc4\u56f2\u3092\u542b\u3081\u305f\u3044\u306e\u3067\u3001\n # \u63a2\u7d22\u7bc4\u56f2\u3068\u3057\u3066\u306fN // 2 + 1 \u3068\u3001+1\u3057\u3066\u304a\u304f\u3002\n ans = binary_search(0, N // 2 + 1, isOK, search_max=True)\n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 2.48, "memory": 15388.0, "status": "done"}, {"code": "#!usr/bin/env python3\nfrom collections import defaultdict, deque, Counter, OrderedDict\nfrom bisect import bisect_left, bisect_right\nfrom functools import reduce, lru_cache\nfrom heapq import heappush, heappop, heapify\n\nimport itertools\nimport math, fractions\nimport sys, copy\n\ndef L(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline().rstrip())\ndef SL(): return list(sys.stdin.readline().rstrip())\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]\ndef LS(): return [list(x) for x in sys.stdin.readline().split()]\ndef R(n): return [sys.stdin.readline().strip() for _ in range(n)]\ndef LR(n): return [L() for _ in range(n)]\ndef IR(n): return [I() for _ in range(n)]\ndef LIR(n): return [LI() for _ in range(n)]\ndef LIR1(n): return [LI1() for _ in range(n)]\ndef SR(n): return [SL() for _ in range(n)]\ndef LSR(n): return [LS() for _ in range(n)]\n\ndef perm(n, r): return math.factorial(n) // math.factorial(r)\ndef comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))\n\ndef make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]\n\ndire = [[1, 0], [0, 1], [-1, 0], [0, -1]]\ndire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]\nalphabets = \"abcdefghijklmnopqrstuvwxyz\"\nALPHABETS = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\nMOD = 1000000007\nINF = float(\"inf\")\n\nsys.setrecursionlimit(1000000)\n\nclass DoubleRollingHash:\n def __init__(self, seq, f=ord):\n self.n = len(seq)\n self.base1, self.base2 = 1007, 2009\n self.mod1, self.mod2 = 1000000007, 1000000009\n self.f = f # set numerizing function\n\n self.hash1, self.hash2 = [0]*(self.n+1), [0]*(self.n+1)\n self.power1, self.power2 = [1]*(self.n+1), [1]*(self.n+1)\n\n for i, e in enumerate(seq):\n self.hash1[i+1] = (self.hash1[i] * self.base1 + self.f(e)) % self.mod1\n self.hash2[i+1] = (self.hash2[i] * self.base2 + self.f(e)) % self.mod2\n self.power1[i+1] = (self.power1[i] * self.base1) % self.mod1\n self.power2[i+1] = (self.power2[i] * self.base2) % self.mod2\n\n # get hash value of seq[left:right]\n def get(self, l, r):\n v1 = (self.hash1[r] - self.hash1[l] * self.power1[r-l]) % self.mod1\n v2 = (self.hash2[r] - self.hash2[l] * self.power2[r-l]) % self.mod2\n return v1, v2\n\n # get lcp of seq[a:] and seq[b:]\n def getLCP(self, a, b):\n l = self.n - max(a, b) + 1\n left, right = 0, l\n while right - left > 1:\n mid = (left + right) // 2\n if self.get(a, a+mid) == self.get(b, b+mid): left = mid\n else: right = mid\n return left\n\nclass RollingHash:\n def __init__(self, seq, f=ord):\n self.n = len(seq)\n self.base, self.mod = 1007, MOD\n self.f = f # set numerizing function\n self.hash, self.power = [0]*(self.n+1), [1]*(self.n+1)\n for i, e in enumerate(seq):\n self.hash[i+1] = (self.hash[i] * self.base + self.f(e)) % self.mod\n self.power[i+1] = (self.power[i] * self.base) % self.mod\n\n # get hash value of seq[left:right]\n def get(self, l, r): return (self.hash[r] - self.hash[l] * self.power[r-l]) % self.mod\n\n # get lcp of seq[a:] and seq[b:]\n def getLCP(self, a, b):\n l = self.n - max(a, b) + 1\n left, right = 0, l\n while right - left > 1:\n mid = (left + right) // 2\n if self.get(a, a+mid) == self.get(b, b+mid): left = mid\n else: right = mid\n return left\n\n\ndef main():\n N = I()\n S = SL()\n\n rh = RollingHash(S)\n ans = 0\n\n def check(m):\n d = defaultdict(lambda: -1)\n for i in range(N-m+1):\n v = rh.get(i, i+m)\n if d[v] != -1:\n if i >= d[v] + m:\n return True\n else:\n d[v] = i\n return False\n\n left, right = 0, N//2+1\n while right - left > 1:\n mid = (left + right) // 2\n if check(mid): left = mid\n else: right = mid\n\n print(left)\n\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 1.71, "memory": 16168.0, "status": "done"}, {"code": "from typing import List\n\n\nclass RollingHash:\n \"\"\"Rolling Hash\"\"\"\n\n __slots__ = [\"_source\", \"_length\", \"_base\", \"_mod\", \"_hash\", \"_power\"]\n\n def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):\n self._source = source\n self._length = len(source)\n self._base = base\n self._mod = mod\n self._hash = self._build_hash_from_zero()\n self._power = self._build_base_power()\n\n def _build_hash_from_zero(self) -> List[int]:\n \"\"\"Compute hash of interval [0, right).\"\"\"\n res = [0] * (self._length + 1)\n for i, c in enumerate(self._source, 1):\n res[i] = (res[i - 1] * self._base + ord(c)) % self._mod\n return res\n\n def _build_base_power(self) -> List[int]:\n \"\"\"Compute mod of power of base.\"\"\"\n res = [1] * (self._length + 1)\n for i in range(1, self._length + 1):\n res[i] = res[i - 1] * self._base % self._mod\n return res\n\n def get_hash(self, left: int, right: int):\n \"\"\"Return hash of interval [left, right).\"\"\"\n return (\n self._hash[right] - self._hash[left] * self._power[right - left]\n ) % self._mod\n\n\ndef abc141_e():\n # https://atcoder.jp/contests/abc141/tasks/abc141_e\n N = int(input())\n S = input().rstrip()\n rh = RollingHash(S)\n ok, ng = 0, N // 2 + 1\n while ng - ok > 1:\n mid = (ok + ng) // 2\n flg = False\n memo = set()\n for i in range(N - 2 * mid + 1):\n memo.add(rh.get_hash(i, i + mid))\n if rh.get_hash(i + mid, i + 2 * mid) in memo:\n flg = True\n break\n if flg:\n ok = mid # next mid will be longer\n else:\n ng = mid # next mid will be shorter\n print(ok) # max length of substrings appeared twice or more\n\n\ndef __starting_point():\n abc141_e()\n\n__starting_point()", "passed": true, "time": 2.07, "memory": 16168.0, "status": "done"}, {"code": "import sys\n\nsys.setrecursionlimit(10 ** 7)\nrl = sys.stdin.readline\n\n\nclass RollingHash:\n def __init__(self, s: str, base=1007, mod=10 ** 9 + 7):\n self.mod = mod\n length = len(s)\n self.pw = [1] * (length + 1)\n self.h = [0] * (length + 1)\n \n v = 0\n for i in range(length):\n self.h[i + 1] = v = (v * base + ord(s[i])) % mod\n v = 1\n for i in range(length):\n self.pw[i + 1] = v = v * base % mod\n \n def query(self, left, right):\n return (self.h[right] - self.h[left] * self.pw[right - left]) % self.mod\n\n\ndef solve():\n N = int(rl())\n S = input()\n \n rh = RollingHash(S)\n \n def check(t):\n dist = dict()\n for i in range(N - t + 1):\n h = rh.query(i, i + t)\n if h in dist:\n if t <= i - dist[h]:\n return True\n else:\n dist[h] = i\n return False\n \n ok, ng = 0, N // 2 + 1\n while 1 < ng - ok:\n mid = (ok + ng) // 2\n if check(mid):\n ok = mid\n else:\n ng = mid\n print(ok)\n\n\ndef __starting_point():\n solve()\n\n__starting_point()", "passed": true, "time": 1.45, "memory": 15276.0, "status": "done"}, {"code": "from typing import List, Tuple\n\n\nclass RollingHash:\n \"\"\"Rolling Hash\"\"\"\n\n __slots__ = [\"_base\", \"_mod\", \"_hash\", \"_power\"]\n\n def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):\n self._base = base\n self._mod = mod\n self._hash, self._power = self._build(source)\n\n def _build(self, source: str) -> Tuple[List[int], List[int]]:\n \"\"\"Compute \"hash\" and \"mod of power of base\" of interval [0, right).\"\"\"\n hash_, power = [0] * (len(source) + 1), [0] * (len(source) + 1)\n power[0] = 1\n for i, c in enumerate(source, 1):\n hash_[i] = (hash_[i - 1] * self._base + ord(c)) % self._mod\n power[i] = power[i - 1] * self._base % self._mod\n return hash_, power\n\n def get_hash(self, left: int, right: int):\n \"\"\"Return hash of interval [left, right).\"\"\"\n return (\n self._hash[right] - self._hash[left] * self._power[right - left]\n ) % self._mod\n\n\ndef abc141_e():\n # https://atcoder.jp/contests/abc141/tasks/abc141_e\n N = int(input())\n S = input().rstrip()\n\n rh = RollingHash(S)\n ok, ng = 0, N // 2 + 1\n while ng - ok > 1:\n mid = (ok + ng) // 2\n flg = False\n memo = set()\n for i in range(N - 2 * mid + 1):\n memo.add(rh.get_hash(i, i + mid))\n if rh.get_hash(i + mid, i + 2 * mid) in memo:\n flg = True\n break\n if flg:\n ok = mid # next mid will be longer\n else:\n ng = mid # next mid will be shorter\n\n print(ok) # max length of substrings appeared twice or more\n\n\ndef __starting_point():\n abc141_e()\n\n__starting_point()", "passed": true, "time": 2.31, "memory": 16024.0, "status": "done"}, {"code": "from typing import List\n\n\nclass RollingHash:\n \"\"\"Rolling Hash\"\"\"\n\n __slots__ = [\"_source\", \"_length\", \"_base\", \"_mod\", \"_hash\", \"_power\"]\n\n def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):\n self._source = source\n self._length = len(source)\n self._base = base\n self._mod = mod\n self._hash = self._build_hash_from_zero()\n self._power = self._build_base_power()\n\n def _build_hash_from_zero(self) -> List[int]:\n \"\"\"Compute hash of interval [0, right).\"\"\"\n res = [0] * (self._length + 1)\n prev = 0\n for i, c in enumerate(self._source, 1):\n res[i] = (prev * self._base + ord(c)) % self._mod\n prev = res[i]\n return res\n\n def _build_base_power(self) -> List[int]:\n \"\"\"Compute mod of power of base.\"\"\"\n res = [1] * (self._length + 1)\n prev = 1\n for i in range(1, self._length + 1):\n res[i] = prev * self._base % self._mod\n prev = res[i]\n return res\n\n def get_hash(self, left: int, right: int):\n \"\"\"Return hash of interval [left, right).\"\"\"\n return (\n self._hash[right] - self._hash[left] * self._power[right - left]\n ) % self._mod\n\n\ndef abc141_e():\n # https://atcoder.jp/contests/abc141/tasks/abc141_e\n N = int(input())\n S = input().rstrip()\n rh = RollingHash(S)\n ok, ng = 0, N // 2 + 1\n while ng - ok > 1:\n mid = (ok + ng) // 2\n flg = False\n memo = set()\n for i in range(N - 2 * mid + 1):\n memo.add(rh.get_hash(i, i + mid))\n if rh.get_hash(i + mid, i + 2 * mid) in memo:\n flg = True\n break\n if flg:\n ok = mid # next mid will be longer\n else:\n ng = mid # next mid will be shorter\n print(ok) # max length of substrings appeared twice or more\n\n\ndef __starting_point():\n abc141_e()\n\n__starting_point()", "passed": true, "time": 1.46, "memory": 16216.0, "status": "done"}, {"code": "import sys\n\nsr = lambda: sys.stdin.readline().rstrip()\nir = lambda: int(sr())\nlr = lambda: list(map(int, sr().split()))\n\n#\u4e8c\u5206\u63a2\u7d22\nN = ir()\nS = sr()\n\ndef check(x):\n # x\u6587\u5b57\u53f3\u5074\u306b\u305a\u3089\u3057\u305f\u5834\u6240\u3092\u8abf\u3079\u308b\n candidate = set()\n for i in range(N - 2*x + 1):\n candidate.add(S[i:i+x])\n if S[i+x:i+2*x] in candidate:\n return True\n return False\n\nok = 0; ng = N\nwhile abs(ng-ok) > 1:\n mid = (ok+ng) // 2\n if check(mid):\n ok = mid\n else:\n ng = mid\n\nprint(ok)\n", "passed": true, "time": 1.38, "memory": 17128.0, "status": "done"}, {"code": "from collections import deque\n\nN = int(input())\nS = input()\n\ndef exists(length):\n que = deque()\n V = set()\n for left in range(N - length + 1):\n if left > length - 1:\n V.add(que.popleft())\n T = S[left: left + length]\n if T in V:\n return True\n que.append(T)\n return False\n\nok = 0\nng = N\nwhile ng - ok > 1:\n mid = (ok + ng) // 2\n\n if exists(mid):\n ok = mid\n else:\n ng = mid\n\nprint(ok)\n\n", "passed": true, "time": 2.68, "memory": 19228.0, "status": "done"}, {"code": "N = int(input())\nS = str(input())\nans = 0\nj = 0\nfor i in range(N):\n while j < N and S[i:j] in S[j:]:\n ans = max(ans,j-i)\n j += 1\n\nprint(ans)", "passed": true, "time": 2.91, "memory": 14896.0, "status": "done"}, {"code": "n=int(input())\ns=input()\n\nfrom collections import defaultdict\n\ndef check(l):\n d = defaultdict(lambda: -1)\n for i in range(n-l+1):\n if d[s[i:i+l]] != -1:\n if d[s[i:i+l]] + l <= i:\n return True\n else:\n d[s[i:i+l]]=i\n return False\n\nok=0\nng=len(s)\n\nwhile abs(ok-ng)>1:\n mid=(ok+ng)//2\n if check(mid):\n ok=mid\n else:\n ng=mid\n\nprint(ok)", "passed": true, "time": 4.67, "memory": 19204.0, "status": "done"}, {"code": "class RollingHash:\n \"\"\"Rolling Hash\"\"\"\n\n __slots__ = [\"_base\", \"_mod\", \"_hash\", \"_power\"]\n\n def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7) -> None:\n self._base = base\n self._mod = mod\n self._hash = [0] * (len(source) + 1)\n self._power = [0] * (len(source) + 1)\n\n self._power[0] = 1\n for i, c in enumerate(source, 1):\n self._hash[i] = (self._hash[i - 1] * self._base + ord(c)) % self._mod\n self._power[i] = self._power[i - 1] * self._base % self._mod\n\n def get_hash(self, left: int, right: int) -> int:\n \"\"\"Return hash of interval [left, right).\"\"\"\n return (\n self._hash[right] - self._hash[left] * self._power[right - left]\n ) % self._mod\n\n\ndef abc141_e():\n # https://atcoder.jp/contests/abc141/tasks/abc141_e\n N = int(input())\n S = input().rstrip()\n\n rh = RollingHash(S)\n ok, ng = 0, N // 2 + 1\n while ng - ok > 1:\n mid = (ok + ng) // 2\n flg = False\n memo = set()\n for i in range(N - 2 * mid + 1):\n memo.add(rh.get_hash(i, i + mid))\n if rh.get_hash(i + mid, i + 2 * mid) in memo:\n flg = True\n break\n if flg:\n ok = mid # next mid will be longer\n else:\n ng = mid # next mid will be shorter\n\n print(ok) # max length of substrings appeared twice or more\n\n\ndef __starting_point():\n abc141_e()\n\n__starting_point()", "passed": true, "time": 2.06, "memory": 15144.0, "status": "done"}, {"code": "n = int(input())\ns = input()\ndp = [0 for i in range(n + 1)]\nfor i in range(n):\n if s[i - dp[i]:i + 1] in s[:i - dp[i]]:\n dp[i + 1] = dp[i] + 1\n else:\n dp[i + 1] = dp[i]\nprint(dp[n])", "passed": true, "time": 5.72, "memory": 14880.0, "status": "done"}, {"code": "n=int(input());s=input()\n\na=0\ni=0\nj=1\nwhile j<n:\n if s[i:j] in s[j:]:\n a=max(a,j-i)\n j+=1\n else:\n i+=1\n\n if i==j:\n i+=1\n j+=2\nprint(a)", "passed": true, "time": 4.51, "memory": 15072.0, "status": "done"}, {"code": "from random import randint\n\n\nclass RollingHash:\n def __init__(self, s):\n self.base = [7073, 7577, 5445, 2742, 6972, 7547, 2267, 286, 6396, 7147,\n 3307, 188, 266, 8253, 2818, 9527, 5110, 1207, 4633, 6196,\n 309, 2646, 7533, 85, 9870, 4730, 6862, 9213, 7456, 7098,\n 6805, 674, 5821, 4864, 8061, 1826, 2219, 459, 5937, 5667,\n 9033, 5552, 7263, 2402, 9809, 3701, 7048, 2874, 8350, 6006,\n 973, 3317, 2522, 5546, 1669, 1545, 7972, 4979, 9905, 173,\n 6812, 7715, 5006, 6068, 6340, 4989, 5510, 6380, 1200, 6739,\n 5527, 4000, 6519, 3448, 2933, 6048, 3133, 1667, 9086, 8368,\n 4914, 7142, 2770, 7752, 391, 7052, 5476, 3105, 8322, 3501,\n 7454, 3167, 8730, 9002, 4564, 138, 2197, 7238, 3411, 7433][randint(0, 99)]\n self.mod = 4611686018427387903\n self.size = len(s)\n self.string = s\n\n self.hash = self.make_hashtable(s)\n self.pow = self.make_powtable()\n\n def make_hashtable(self, _s):\n hashtable = [0] * (self.size + 1)\n for i in range(self.size):\n hashtable[i + 1] = (hashtable[i] * self.base + ord(_s[i])) % self.mod\n return hashtable\n\n def make_powtable(self):\n power = [1] * (self.size + 1)\n for i in range(self.size):\n power[i + 1] = (self.base * power[i]) % self.mod\n return power\n\n def get_hash(self, left, right):\n \"\"\"get hash of s[left:right]\"\"\"\n return (self.hash[right] - self.hash[left] * self.pow[right - left]) % self.mod\n\n def contain(self, a):\n \"\"\"return a in s\"\"\"\n m = len(a)\n if m > self.size:\n return False\n hashs = self.get_hash(0, m)\n hasha = 0\n for i in range(m):\n hasha = (hasha * self.base + ord(a[i])) % self.mod\n for i in range(self.size - m + 1):\n if hasha == hashs:\n return True\n hashs = self.get_hash(i, m + i)\n return hasha == hashs\n\n\nfrom collections import defaultdict\n# d = defaultdict(int)\u30670\u3067\u521d\u671f\u5316\n# d = defaultdict(lambda: 100)\u3067100\u3067\u521d\u671f\u5316\nn, s = int(input()), input()\nrh = RollingHash(s)\n\n\ndef check(m):\n d = defaultdict(lambda: 10000000)\n for i in range(n - m + 1):\n h = rh.get_hash(i, i + m)\n d[h] = min(d[h], i)\n # m\u4ee5\u4e0a\u96e2\u308c\u3066\u3044\u30662\u56de\u76ee\n if i - d[h] >= m:\n return True\n return False\n\n\nl, r = 0, n // 2 + 1\nwhile l + 1 < r:\n mid = (l + r) // 2\n if check(mid):\n l = mid\n else:\n r = mid\nprint(l)\n", "passed": true, "time": 2.76, "memory": 15308.0, "status": "done"}, {"code": "import sys\n#input = sys.stdin.buffer.readline\n\ndef main():\n N = int(input())\n s = input()\n a,i,j = 0,0,1\n \n while j < N:\n if s[i:j] in s[j:]:\n a = max(a,j-i)\n j += 1\n else:\n i += 1\n if i == j:\n j += 1\n \n print(a)\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 2.97, "memory": 14896.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nA = 1234567\nMOD = 10000000000000007\n\ndef ok(length):\n rolling_hash = 0\n head = pow(A, length, MOD)\n occurence = {}\n for i in range(n):\n rolling_hash = (rolling_hash * A + ord(s[i])) % MOD\n if i - length >= 0:\n rolling_hash = (rolling_hash - head * ord(s[i-length])) % MOD\n if rolling_hash not in occurence:\n occurence[rolling_hash] = []\n occurence[rolling_hash].append(i)\n\n for key in occurence:\n if occurence[key][-1] - occurence[key][0] >= length:\n return True\n return False\n\nbottom, top = 0, n\n\nwhile top - bottom > 1:\n mid = (top + bottom) // 2\n if ok(mid):bottom = mid\n else: top = mid\n\nprint(bottom)", "passed": true, "time": 3.18, "memory": 14988.0, "status": "done"}, {"code": "N = int(input())\nS = input()\n\nl = 0 # max proven possible\nr = N # min proven impossible\nwhile l + 1 < r:\n x = (l + r) // 2\n first_loc = {}\n possible = False\n for i in range(N-x+1):\n #print(i, N-x, first_loc)\n sub = S[i:i+x]\n #print(sub)\n if sub in first_loc:\n if first_loc[sub] <= i - x:\n #print(sub, first_loc[sub], i, x, i-x)\n possible = True\n break\n else:\n first_loc[sub] = i\n if possible:\n l = x\n else:\n r = x\nprint(l)\n", "passed": true, "time": 2.73, "memory": 19256.0, "status": "done"}, {"code": "N = int(input())\nS = input()\nok, ng = 0, N + 1\nwhile abs(ok - ng) > 1:\n x = (ok + ng) // 2\n check = set()\n for i in range(N - x + 1):\n check.add(S[i: i + x])\n if S[i + x: i + 2 * x] in check:\n ok = x\n break\n else:\n ng = x\n\nprint(ok)", "passed": true, "time": 2.97, "memory": 19180.0, "status": "done"}, {"code": "I=input;n=int(I());s=I();j=1;r=[]\nfor i in range(n):\n while (j<n)and(s[i:j] in s[j:]):j+=1\n r.append(j-i-1)\nprint(max(r))", "passed": true, "time": 3.19, "memory": 14944.0, "status": "done"}, {"code": "N = int(input())\nS = input()\nfrom collections import deque\n\ndef f(m):\n se = set()\n q = deque()\n for i in range(0,N-m+1):\n h = hash(S[i:i+m])\n q.append(h)\n if h in se:\n return True\n if len(q) >= m:\n se.add(q.popleft())\n return False\n\nl = 0\nr = N//2+1\nwhile (r-l)>1:\n mid = (r+l)//2\n if f(mid):\n l = mid\n else:\n r = mid\nprint(l)", "passed": true, "time": 2.83, "memory": 15072.0, "status": "done"}, {"code": "#!usr/bin/env python3\nfrom collections import defaultdict, deque, Counter, OrderedDict\nfrom bisect import bisect_left, bisect_right\nfrom functools import reduce, lru_cache\nfrom heapq import heappush, heappop, heapify\n\nimport itertools\nimport math, fractions\nimport sys, copy\n\ndef L(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline().rstrip())\ndef SL(): return list(sys.stdin.readline().rstrip())\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]\ndef LS(): return [list(x) for x in sys.stdin.readline().split()]\ndef R(n): return [sys.stdin.readline().strip() for _ in range(n)]\ndef LR(n): return [L() for _ in range(n)]\ndef IR(n): return [I() for _ in range(n)]\ndef LIR(n): return [LI() for _ in range(n)]\ndef LIR1(n): return [LI1() for _ in range(n)]\ndef SR(n): return [SL() for _ in range(n)]\ndef LSR(n): return [LS() for _ in range(n)]\n\ndef perm(n, r): return math.factorial(n) // math.factorial(r)\ndef comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))\n\ndef make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]\n\ndire = [[1, 0], [0, 1], [-1, 0], [0, -1]]\ndire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]\nalphabets = \"abcdefghijklmnopqrstuvwxyz\"\nALPHABETS = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\nMOD = 1000000007\nINF = float(\"inf\")\n\nsys.setrecursionlimit(1000000)\n\nclass DoubleRollingHash:\n def __init__(self, seq, f=ord):\n self.n = len(seq)\n self.base1, self.base2 = 1007, 2009\n self.mod1, self.mod2 = 1000000007, 1000000009\n self.f = f # set numerizing function\n\n self.hash1, self.hash2 = [0]*(self.n+1), [0]*(self.n+1)\n self.power1, self.power2 = [1]*(self.n+1), [1]*(self.n+1)\n\n for i, e in enumerate(seq):\n self.hash1[i+1] = (self.hash1[i] * self.base1 + self.f(e)) % self.mod1\n self.hash2[i+1] = (self.hash2[i] * self.base2 + self.f(e)) % self.mod2\n self.power1[i+1] = (self.power1[i] * self.base1) % self.mod1\n self.power2[i+1] = (self.power2[i] * self.base2) % self.mod2\n\n # get hash value of seq[left:right]\n def get(self, l, r):\n v1 = (self.hash1[r] - self.hash1[l] * self.power1[r-l]) % self.mod1\n v2 = (self.hash2[r] - self.hash2[l] * self.power2[r-l]) % self.mod2\n return v1, v2\n\n # get lcp of seq[a:] and seq[b:]\n def getLCP(self, a, b):\n l = self.n - max(a, b) + 1\n left, right = 0, l\n while right - left > 1:\n mid = (left + right) // 2\n if self.get(a, a+mid) == self.get(b, b+mid): left = mid\n else: right = mid\n return left\n\nclass RollingHash:\n def __init__(self, seq, f=ord):\n self.n = len(seq)\n self.base, self.mod = 1007, pow(2, 61) - 1\n self.f = f # set numerizing function\n self.hash, self.power = [0]*(self.n+1), [1]*(self.n+1)\n for i, e in enumerate(seq):\n self.hash[i+1] = (self.hash[i] * self.base + self.f(e)) % self.mod\n self.power[i+1] = (self.power[i] * self.base) % self.mod\n\n # get hash value of seq[left:right]\n def get(self, l, r): return (self.hash[r] - self.hash[l] * self.power[r-l]) % self.mod\n\n # get lcp of seq[a:] and seq[b:]\n def getLCP(self, a, b):\n l = self.n - max(a, b) + 1\n left, right = 0, l\n while right - left > 1:\n mid = (left + right) // 2\n if self.get(a, a+mid) == self.get(b, b+mid): left = mid\n else: right = mid\n return left\n\n\ndef main():\n N = I()\n S = SL()\n\n rh = RollingHash(S)\n ans = 0\n\n def check(m):\n d = defaultdict(lambda: -1)\n for i in range(N-m+1):\n v = rh.get(i, i+m)\n if d[v] != -1:\n if i >= d[v] + m:\n return True\n else:\n d[v] = i\n return False\n\n left, right = 0, N//2+1\n while right - left > 1:\n mid = (left + right) // 2\n if check(mid): left = mid\n else: right = mid\n\n print(left)\n\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 2.4, "memory": 15676.0, "status": "done"}, {"code": "def ok(k):\n # \u9577\u3055k\u306e\u9023\u7d9a\u90e8\u5206\u5217\u3067\u91cd\u306a\u3089\u305a\u306b2\u56de\u4ee5\u4e0a\u73fe\u308c\u308b\u3082\u306e\u304c\u3042\u308b\n D = {}\n for i in range(n-k+1):\n s = S[i:i+k]\n try:\n if D[s]+k <= i:\n return True\n except:\n D[s] = i\n return False\n\n\nn = int(input())\nS = input()\n# \u4e8c\u5206\u63a2\u7d22\u3067True\u306b\u306a\u308b\u6700\u5927\u306ek\u3092\u6c42\u3081\u308b\nl, r = 0, n+1\nwhile r-l > 1:\n c = (l+r)//2\n if ok(c):\n l = c\n else:\n r = c\nprint(l)\n", "passed": true, "time": 3.1, "memory": 18952.0, "status": "done"}, {"code": "N=int(input())\nS=input()\n\nlong=0\nfor i in range(N-1):\n for j in range(i+long+1,N):\n if not (S[i:j] in S[j:]):\n break\n long=max(long,j-i-1)\nprint(long)", "passed": true, "time": 3.69, "memory": 14908.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\ndef search(x):\n d = set()\n for i in range(n-2*x+1):\n d.add(s[i:i+x])\n if s[i+x:i+2*x] in d:\n return True\n return False\n\nl = 0\nr = n//2+1\nwhile r > l+1:\n mid = (r+l)//2\n if search(mid):\n l = mid\n else:\n r = mid\nprint(l)", "passed": true, "time": 1.39, "memory": 17344.0, "status": "done"}, {"code": "def check(x, N, S):\n candidate = set()\n for i in range(N - 2*x + 1):\n candidate.add(S[i:i+x])\n if S[i+x:i+2*x] in candidate:\n return True\n return False\n\ndef main():\n n = int(input())\n s = input().rstrip()\n l = 0\n r = n\n while l < r:\n mid = (l+r+1) // 2\n if check(mid, n, s):\n l = mid\n else:\n r = mid-1\n print((l+r+1)//2)\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 1.39, "memory": 17236.0, "status": "done"}, {"code": "N=int(input())\nS=input()\nans = 0\nj = 0\nfor i in range(N):\n while j < N and S[i:j] in S[j:]:\n j += 1\n ans = max(ans,j-i-1)\nprint(ans)\n\n", "passed": true, "time": 2.92, "memory": 15092.0, "status": "done"}, {"code": "N = int(input())\nS = input()\n\ndef f(m):\n se = set()\n arr = [None]*N\n for i in range(0,N-m+1):\n if i >= m:\n se.add(arr[i-m])\n arr[i] = hash(S[i:i+m])\n if arr[i] in se:\n return True\n return False\n\nl = 0\nr = N//2+1\nwhile (r-l)>1:\n mid = (r+l)//2\n if f(mid):\n l = mid\n else:\n r = mid\nprint(l)", "passed": true, "time": 2.78, "memory": 15080.0, "status": "done"}, {"code": "from collections import defaultdict\n\n\ndef read():\n N = int(input().strip())\n S = input().strip()\n return N, S\n\n\ndef solve(N, S):\n low = 0\n high = (N >> 1) + 1\n while high - low > 1:\n mid = (high + low) >> 1\n is_match = False\n m = N-mid+1\n d = defaultdict(list)\n for i in range(0, m):\n d[S[i:i+mid]].append(i)\n for v in d.values():\n if v[-1] - v[0] >= mid:\n is_match = True\n break\n if is_match:\n low = mid\n else:\n high = mid\n return low\n\n\ndef __starting_point():\n inputs = read()\n outputs = solve(*inputs)\n if outputs is not None:\n print(\"%s\" % str(outputs))\n__starting_point()", "passed": true, "time": 2.91, "memory": 19232.0, "status": "done"}, {"code": "n=int(input())\ns=input()\nr=n//2\nl=-1\nwhile r-l>1:\n mid=(r+l)//2\n d=dict()\n ok=False\n for i in range(n-mid):\n ss=s[i:i+mid+1]\n if ss not in d:\n d[ss]=i\n else:\n if d[ss]+mid<i:\n ok=True\n if ok:\n l=mid\n else:\n r=mid\nprint(r)", "passed": true, "time": 2.63, "memory": 19360.0, "status": "done"}, {"code": "#!usr/bin/env python3\nfrom collections import defaultdict, deque, Counter, OrderedDict\nfrom bisect import bisect_left, bisect_right\nfrom functools import reduce, lru_cache\nfrom heapq import heappush, heappop, heapify\n\nimport itertools\nimport math, fractions\nimport sys, copy\n\ndef L(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline().rstrip())\ndef SL(): return list(sys.stdin.readline().rstrip())\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]\ndef LS(): return [list(x) for x in sys.stdin.readline().split()]\ndef R(n): return [sys.stdin.readline().strip() for _ in range(n)]\ndef LR(n): return [L() for _ in range(n)]\ndef IR(n): return [I() for _ in range(n)]\ndef LIR(n): return [LI() for _ in range(n)]\ndef LIR1(n): return [LI1() for _ in range(n)]\ndef SR(n): return [SL() for _ in range(n)]\ndef LSR(n): return [LS() for _ in range(n)]\n\ndef perm(n, r): return math.factorial(n) // math.factorial(r)\ndef comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))\n\ndef make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]\n\ndire = [[1, 0], [0, 1], [-1, 0], [0, -1]]\ndire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]\nalphabets = \"abcdefghijklmnopqrstuvwxyz\"\nALPHABETS = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\nMOD = 1000000007\nINF = float(\"inf\")\n\nsys.setrecursionlimit(1000000)\n\nclass RollingHash:\n def __init__(self, seq, f=ord):\n self.n = len(seq)\n self.base1, self.base2 = 1007, 2009\n self.mod1, self.mod2 = 1000000007, 1000000009\n self.f = f # set numerizing function\n\n self.hash1, self.hash2 = [0]*(self.n+1), [0]*(self.n+1)\n self.power1, self.power2 = [1]*(self.n+1), [1]*(self.n+1)\n\n for i, e in enumerate(seq):\n self.hash1[i+1] = (self.hash1[i] * self.base1 + self.f(e)) % self.mod1\n self.hash2[i+1] = (self.hash2[i] * self.base2 + self.f(e)) % self.mod2\n self.power1[i+1] = (self.power1[i] * self.base1) % self.mod1\n self.power2[i+1] = (self.power2[i] * self.base2) % self.mod2\n\n # get hash value of seq[left:right]\n def get(self, l, r):\n v1 = (self.hash1[r] - self.hash1[l] * self.power1[r-l]) % self.mod1\n v2 = (self.hash2[r] - self.hash2[l] * self.power2[r-l]) % self.mod2\n return v1, v2\n\n # get lcp of seq[a:] and seq[b:]\n def getLCP(self, a, b):\n l = self.n - max(a, b) + 1\n left, right = 0, l\n while right - left > 1:\n mid = (left + right) // 2\n if self.get(a, a+mid) == self.get(b, b+mid): left = mid\n else: right = mid\n return left\n\n\ndef main():\n N = I()\n S = SL()\n\n rh = RollingHash(S)\n ans = 0\n\n def check(m):\n d = defaultdict(lambda: -1)\n for i in range(N-m+1):\n v = rh.get(i, i+m)\n if d[v] != -1:\n if i >= d[v] + m:\n return True\n else:\n d[v] = i\n return False\n\n left, right = 0, N//2+1\n while right - left > 1:\n mid = (left + right) // 2\n if check(mid): left = mid\n else: right = mid\n\n print(left)\n\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 2.77, "memory": 16612.0, "status": "done"}, {"code": "from collections import defaultdict\n\nclass RollingHash(object):\n def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):\n self.S = S\n self.N = N = len(S)\n self.MOD = MOD\n self.BASE = BASE\n self.S_arr = [ord(x) for x in S]\n\n self.POWER = [1] * (N + 1)\n self.HASH = [0] * (N + 1)\n p, h = 1, 0\n for i in range(N):\n self.POWER[i + 1] = p = (p * BASE) % MOD\n self.HASH[i + 1] = h = (h * BASE + self.S_arr[i]) % MOD\n\n def hash(self, l: int, r: int):\n # get hash for S[l:r]\n _hash = self.HASH[r] - (self.HASH[l] * self.POWER[r - l] % self.MOD)\n if _hash < 0:\n _hash += self.MOD\n return _hash\n\n# \u6c4e\u7528\u7684\u306a\u4e8c\u5206\u63a2\u7d22\u306e\u30c6\u30f3\u30d7\u30ec\n# check_func(x) = true \u3068\u306a\u308bx\u306e\u6700\u5c0f\u5024\u3092\u63a2\u7d22\u3059\u308b\n# left : check_func(x) = false\u3068\u306a\u308bx\n# right: check_func(x) = true \u3068\u306a\u308bx\n# search_max: check_func(x) = true \u3068\u306a\u308bx\u306e\"\u6700\u5927\u5024\"\u3092\u63a2\u7d22\u3059\u308b\u5834\u5408\u306fTrue\n# check_func: answer <= x \u3067\u3042\u308c\u3070check_func(x) = true \u3068\u306a\u308b\u3088\u3046\u306a\u95a2\u6570\ndef binary_search(left: int, right: int, check_func, search_max:bool=False):\n # ok \u3068 ng \u306e\u3069\u3061\u3089\u304c\u5927\u304d\u3044\u304b\u308f\u304b\u3089\u306a\u3044\u3053\u3068\u3092\u8003\u616e\n while abs(right - left) > 1:\n mid = (left + right) // 2\n \n if check_func(mid) ^ search_max:\n right = mid\n # print(left, right, mid, 't')\n else:\n left = mid\n # print(left, right, mid, 'f')\n\n return left if search_max else right\n\ndef main():\n N = int(input())\n S = input()\n\n rs = RollingHash(S, MOD=998244353, BASE=37)\n\n # \u9577\u3055L\u306e\u90e8\u5206\u6587\u5b57\u5217\u540c\u58eb\u304c\u3001\u7bc4\u56f2\u3092\u91cd\u306d\u305a\u540c\u3058\u6587\u5b57\u5217\u3068\u306a\u308b\u5834\u5408\u306fTrue,\n # \u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306fFalse\u3092\u8fd4\u3059\u95a2\u6570\n def isOK(L):\n if L == 0:\n return True\n hash_to_left = defaultdict(list)\n for i in range(N - L + 1):\n _hash = rs.hash(i, i + L)\n # hash\u304c\u885d\u7a81\u3057\u3066\u3082\u6587\u5b57\u5217\u304c\u5b8c\u5168\u306b\u4e00\u81f4\u3059\u308b\u304b\u5206\u304b\u3089\u306a\u3044\u306e\u3067\u3001\n # \u885d\u7a81\u3057\u305f\u5834\u5408\u306f\u6587\u5b57\u5217\u304c\u5b8c\u5168\u306b\u4e00\u81f4\u3059\u308b\u304b\u8abf\u3079\u3001\u304b\u3064\n # \u6587\u5b57\u5217\u540c\u58eb\u304cS\u306e\u4e2d\u3067\u91cd\u306a\u308b\u3088\u3046\u306a\u7bc4\u56f2\u306b\u306a\u3044\u5834\u5408\u306fOK\u3068\u3059\u308b\n for j in hash_to_left[_hash]:\n if j+L <= i and S[i:i+L] == S[j:j+L]:\n return True\n hash_to_left[_hash].append(i)\n\n return False\n # \u7bc4\u56f2\u304c\u91cd\u306a\u3089\u306a\u3044\u3053\u3068\u304c\u6761\u4ef6\u306b\u3042\u308b\u306e\u3067\u3001\u7b54\u3048\u306f\u6700\u5927\u3067\u3082N // 2\uff08\u6587\u5b57\u5217\u306e\u9577\u3055\u306e\u534a\u5206\uff09\u3068\u306a\u308b\u3002\n # \u305f\u3060\u3057\u3001\u4e8c\u5206\u63a2\u7d22\u3059\u308b\u4e0a\u3067\u7d76\u5bfe\u306b\u7b54\u3048\u3068\u306a\u3089\u306a\u3044\u7bc4\u56f2\u3092\u542b\u3081\u305f\u3044\u306e\u3067\u3001\n # \u63a2\u7d22\u7bc4\u56f2\u3068\u3057\u3066\u306fN // 2 + 1 \u3068\u3001+1\u3057\u3066\u304a\u304f\u3002\n ans = binary_search(0, N // 2 + 1, isOK, search_max=True)\n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 4.17, "memory": 15292.0, "status": "done"}, {"code": "from typing import List\n\n\nclass RollingHash:\n __slots__ = [\"source\", \"length\", \"base\", \"mod\", \"hash\", \"power\"]\n\n def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):\n self.source = source\n self.length = len(source)\n self.base = base\n self.mod = mod\n self.hash = self._get_hash_from_zero()\n self.power = self._get_base_pow()\n\n def _get_hash_from_zero(self) -> List[int]:\n \"\"\"Compute hash of interval [0, right).\"\"\"\n cur, hash_from_zero = 0, [0]\n for e in self.source:\n cur = (cur * self.base + ord(e)) % self.mod\n hash_from_zero.append(cur)\n return hash_from_zero\n\n def _get_base_pow(self) -> List[int]:\n \"\"\"Compute mod of power of base.\"\"\"\n cur, power = 1, [1]\n for i in range(self.length):\n cur *= self.base % self.mod\n power.append(cur)\n return power\n\n def get_hash(self, left: int, right: int):\n \"\"\"Compute hash of interval [left, right).\"\"\"\n return (\n self.hash[right] - self.hash[left] * self.power[right - left]\n ) % self.mod\n\n\ndef abc141_e():\n # https://atcoder.jp/contests/abc141/tasks/abc141_e\n N = int(input())\n S = input().rstrip()\n rh = RollingHash(S)\n ok, ng = 0, N // 2 + 1\n while ng - ok > 1:\n mid = (ok + ng) // 2\n flg, memo = 0, set()\n for i in range(N - 2 * mid + 1):\n memo.add(rh.get_hash(i, i + mid))\n if rh.get_hash(i + mid, i + 2 * mid) in memo:\n flg = 1\n break\n if flg:\n ok = mid # next mid will be longer\n else:\n ng = mid # next mid will be shorter\n print(ok) # max length of substrings appeared twice or more\n\n\ndef __starting_point():\n abc141_e()\n\n__starting_point()", "passed": true, "time": 6.38, "memory": 30204.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n \nmax_len = 0\nj = 0\n \nfor i in range(n):\n while j < n and s[i:j] in s[j:]:\n j += 1\n max_len = max(max_len,j-i-1)\n \nprint(max_len)", "passed": true, "time": 2.93, "memory": 14988.0, "status": "done"}, {"code": "def ok(l):\n # \u9577\u3055l\u306e\u9023\u7d9a\u90e8\u5206\u5217\u3067\u91cd\u306a\u3089\u305a\u306b2\u56de\u4ee5\u4e0a\u73fe\u308c\u308b\u3082\u306e\u304c\u3042\u308b\n D = {}\n for i in range(n-l+1):\n h = hash(S[i:i+l])\n try:\n if D[h] + l <= i:\n return True\n except:\n D[h] = i\n return False\n\n\nn = int(input())\nS = input()\n# \u4e8c\u5206\u63a2\u7d22\u3067True\u306b\u306a\u308b\u6700\u5927\u306ek\u3092\u6c42\u3081\u308b\nl, r = 0, n+1\nwhile r-l > 1:\n c = (l+r)//2\n if ok(c):\n l = c\n else:\n r = c\nprint(l)\n", "passed": true, "time": 2.67, "memory": 14988.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nmax_len = 0\nj = 0\n\nfor i in range(n):\n while j < n and s[i:j] in s[j:]:\n j += 1\n max_len = max(max_len,j-i-1)\n\nprint(max_len)", "passed": true, "time": 2.99, "memory": 15048.0, "status": "done"}, {"code": "# ABC141E - Who Says a Pun?\ndef resolve():\n N = int(input())\n S = input().rstrip()\n ok, ng = 0, N // 2 + 1\n while ng - ok > 1:\n mid = (ok + ng) // 2\n flg = False\n memo = set()\n for i in range(N - 2 * mid + 1):\n memo.add(hash(S[i : i + mid]))\n if hash(S[i + mid : i + 2 * mid]) in memo:\n flg = True\n break\n if flg:\n ok = mid # next mid will be longer\n else:\n ng = mid # next mid will be shorter\n print(ok) # max length of substrings appeared twice or more\n\n\nresolve()\n", "passed": true, "time": 1.55, "memory": 15204.0, "status": "done"}, {"code": "from typing import List\n\n\nclass RollingHash:\n __slots__ = [\"_source\", \"_length\", \"_base\", \"_mod\", \"_hash\", \"_power\"]\n\n def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):\n self._source = source\n self._length = len(source)\n self._base = base\n self._mod = mod\n self._hash = self._get_hash_from_zero()\n self._power = self._get_base_pow()\n\n def _get_hash_from_zero(self) -> List[int]:\n \"\"\"Compute hash of interval [0, right).\"\"\"\n hash_from_zero = [0] * (self._length + 1)\n cur = 0\n for i, c in enumerate(self._source, 1):\n cur = (cur * self._base + ord(c)) % self._mod\n hash_from_zero[i] = cur\n return hash_from_zero\n\n def _get_base_pow(self) -> List[int]:\n \"\"\"Compute mod of power of base.\"\"\"\n power = [0] * (self._length + 1)\n power[0] = 1\n cur = 1\n for i in range(1, self._length + 1):\n cur *= self._base % self._mod\n power[i] = cur\n return power\n\n def get_hash(self, left: int, right: int):\n \"\"\"Compute hash of interval [left, right).\"\"\"\n return (\n self._hash[right] - self._hash[left] * self._power[right - left]\n ) % self._mod\n\n\ndef abc141_e():\n # https://atcoder.jp/contests/abc141/tasks/abc141_e\n N = int(input())\n S = input().rstrip()\n rh = RollingHash(S)\n ok, ng = 0, N // 2 + 1\n while ng - ok > 1:\n mid = (ok + ng) // 2\n flg = False\n memo = set()\n for i in range(N - 2 * mid + 1):\n memo.add(rh.get_hash(i, i + mid))\n if rh.get_hash(i + mid, i + 2 * mid) in memo:\n flg = True\n break\n if flg:\n ok = mid # next mid will be longer\n else:\n ng = mid # next mid will be shorter\n print(ok) # max length of substrings appeared twice or more\n\n\ndef __starting_point():\n abc141_e()\n\n__starting_point()", "passed": true, "time": 6.34, "memory": 30300.0, "status": "done"}, {"code": "import random\n\nclass RollingHash(object):\n def __init__(self, S: str, MOD: int = 998244353, BASE: int = 37):\n self.S = S\n self.N = N = len(S)\n self.MOD = MOD\n self.BASE = BASE\n self.S_arr = [ord(x) for x in S]\n\n self.POWER = [1] * (N + 1)\n self.HASH = [0] * (N + 1)\n p, h = 1, 0\n for i in range(N):\n self.POWER[i + 1] = p = (p * BASE) % MOD\n self.HASH[i + 1] = h = (h * BASE + self.S_arr[i]) % MOD\n\n def hash(self, l: int, r: int):\n # get hash for S[l:r]\n _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD\n return _hash\n\n# \u6c4e\u7528\u7684\u306a\u4e8c\u5206\u63a2\u7d22\u306e\u30c6\u30f3\u30d7\u30ec\n# check_func(x) = true \u3068\u306a\u308bx\u306e\u6700\u5c0f\u5024\u3092\u63a2\u7d22\u3059\u308b\n# left : check_func(x) = false\u3068\u306a\u308bx\n# right: check_func(x) = true \u3068\u306a\u308bx\n# search_max: check_func(x) = true \u3068\u306a\u308bx\u306e\"\u6700\u5927\u5024\"\u3092\u63a2\u7d22\u3059\u308b\u5834\u5408\u306fTrue\n# check_func: search_max = False \u306e\u5834\u5408\u3001answer <= x \u3067\u3042\u308c\u3070check_func(x) = true \u3068\u306a\u308b\u3088\u3046\u306a\u95a2\u6570\n# search_max = True \u306e\u5834\u5408\u3001x <= answer \u3067\u3042\u308c\u3070check_func(x) = true \u3068\u306a\u308b\u3088\u3046\u306a\u95a2\u6570\ndef binary_search(left: int, right: int, check_func, search_max:bool=False):\n # ok \u3068 ng \u306e\u3069\u3061\u3089\u304c\u5927\u304d\u3044\u304b\u308f\u304b\u3089\u306a\u3044\u3053\u3068\u3092\u8003\u616e\n while abs(right - left) > 1:\n mid = (left + right) // 2\n \n if check_func(mid) ^ search_max:\n right = mid\n else:\n left = mid\n\n return left if search_max else right\n\ndef main():\n N = int(input())\n S = input()\n MOD = 10 ** 18 + 3\n # BASE\u306fMOD\u672a\u6e80\u30671\u3067\u306a\u3044\u5947\u6570\u3068\u3059\u308b\n BASE = random.randint(2, MOD // 2 - 1) * 2 + 1\n rs = RollingHash(S, MOD=MOD, BASE=BASE)\n\n D = [0] * N\n # \u9577\u3055L\u306e\u90e8\u5206\u6587\u5b57\u5217\u540c\u58eb\u304c\u3001\u7bc4\u56f2\u3092\u91cd\u306d\u305a\u540c\u3058\u6587\u5b57\u5217\u3068\u306a\u308b\u5834\u5408\u306fTrue,\n # \u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306fFalse\u3092\u8fd4\u3059\u95a2\u6570\n def isOK(L):\n if L == 0:\n return True\n \n for i in range(min(L, N - 2 * L + 1)):\n D[i] = rs.hash(i, i + L)\n hashes = set()\n for i in range(L, N - L + 1):\n # \u81ea\u5206\u3088\u308a\u958b\u59cb\u70b9\u304cL\u4ee5\u4e0a\u524d\u306e\u6587\u5b57\u5217\u306e\u30cf\u30c3\u30b7\u30e5\u3092\u691c\u7d22\u5bfe\u8c61\u306b\u8ffd\u52a0\n hashes.add(D[i - L])\n D[i] = v = rs.hash(i, i + L)\n # \u30cf\u30c3\u30b7\u30e5\u304c\u885d\u7a81\u3057\u305f\u3089\u3001\u7bc4\u56f2\u3092\u91cd\u306d\u305a\u540c\u3058\u6587\u5b57\u5217\u3068\u306a\u308b\u6587\u5b57\u5217\u304c\u5b58\u5728\u3059\u308b\u3053\u3068\u306b\u306a\u308b\n if v in hashes:\n return True\n return False\n\n # \u7bc4\u56f2\u304c\u91cd\u306a\u3089\u306a\u3044\u3053\u3068\u304c\u6761\u4ef6\u306b\u3042\u308b\u306e\u3067\u3001\u7b54\u3048\u306f\u6700\u5927\u3067\u3082N // 2\uff08\u6587\u5b57\u5217\u306e\u9577\u3055\u306e\u534a\u5206\uff09\u3068\u306a\u308b\u3002\n # \u305f\u3060\u3057\u3001\u4e8c\u5206\u63a2\u7d22\u3059\u308b\u4e0a\u3067\u7d76\u5bfe\u306b\u7b54\u3048\u3068\u306a\u3089\u306a\u3044\u7bc4\u56f2\u3092\u542b\u3081\u305f\u3044\u306e\u3067\u3001\n # \u63a2\u7d22\u7bc4\u56f2\u3068\u3057\u3066\u306fN // 2 + 1 \u3068\u3001+1\u3057\u3066\u304a\u304f\u3002\n ans = binary_search(0, N // 2 + 1, isOK, search_max=True)\n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 1.5, "memory": 15512.0, "status": "done"}, {"code": "def solve():\n N = int(input())\n S = input()\n\n def rolling_hash(s, mod, base = 37):\n l = len(s)\n h = [0]*(l + 1)\n v = 0\n for i in range(l):\n h[i+1] = v = (v * base + ord(s[i])) % mod\n pw = [1]*(l + 1)\n v = 1\n for i in range(l):\n pw[i+1] = v = v * base % mod\n return h, pw\n\n def chk(S, mod, D = [0]*N):\n h, pw = rolling_hash(S, mod)\n left = 0; right = N//2+1\n while left+1 < right:\n l = mid = (left + right) >> 1\n p = pw[l]\n for i in range(min(l, N-2*l+1)):\n D[i] = (h[l+i] - h[i]*p) % mod\n s = set()\n ok = 0\n for i in range(l, N-l+1):\n s.add(D[i-l])\n D[i] = v = (h[l+i] - h[i]*p) % mod\n if v in s:\n ok = 1\n break\n if ok:\n left = mid\n else:\n right = mid\n return left\n\n print((chk(S, 10**9 + 9)))\nsolve()\n", "passed": true, "time": 0.84, "memory": 15320.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nj = 1\nresult = [0]\nend = n//2 + 1\nfor i in range(n):\n while (j < n-1) and (s[i:j] in s[:i]+\"0\"+s[j:]):\n j += 1\n result.append(j-i-1)\nprint(max(result))", "passed": true, "time": 7.38, "memory": 15164.0, "status": "done"}, {"code": "class RollingHash():\n def __init__(self,s):\n self.n=n=len(s)\n self.b=b=129\n self.M=M=2**61-1\n x,y=1,0\n self.f=f=[x]*(n+1)\n self.h=h=[y]*(n+1)\n for i,c in enumerate(s.encode()):\n f[i+1]=x=x*b%M\n h[i+1]=y=(y*b+c)%M\n def get(self,l,r):\n return(self.h[r]-self.h[l]*self.f[r-l])%self.M\ndef check(x):\n d={}\n for i in range(0,n-x+1):\n k=s.get(i,i+x)\n if k in d:\n if d[k]+x<=i:\n return True\n else:\n d[k]=i\n return False\nn=int(input())\ns=RollingHash(input())\nok,ng=0,n\nwhile ng-ok>1:\n mid=ok+ng>>1\n if check(mid):\n ok=mid\n else:\n ng=mid\nprint(ok)", "passed": true, "time": 3.34, "memory": 15116.0, "status": "done"}, {"code": "import sys\nsys.setrecursionlimit(10**9)\nfrom collections import defaultdict\nN = int(input())\nS = input()\nif N==2:\n if S[1] == S[0]:\n print((1))\n else:\n print((0))\n return\ndef hantei(mid):\n flag = False\n string = S[:mid]\n dic = defaultdict(int)\n dic[string] = -1\n for k in range(mid, N):\n string += S[k]\n string = string[1:]\n if dic[string] < 0:\n if k -mid+2+ dic[string] >= mid:\n flag = True\n break\n else:\n dic[string] = -k+mid-2\n if flag:\n return True\n else: \n return False\nok = N//2+1 #False\nng = 0 #True\nwhile ok - ng > 1:\n mid = (ok + ng) // 2\n if hantei(mid):\n ng = mid\n else:\n ok = mid\nif hantei(mid):\n print((min(mid, N//2)))\nelse:\n print((min(ng, N//2)))\n", "passed": true, "time": 3.34, "memory": 19116.0, "status": "done"}, {"code": "n = int(input())\ns = input() #sys.stdin.readline\u306f\u6700\u5f8c\u304c\u6539\u884c\n\nright=0\nans = 0\nfor left in range(n):\n while right<n:\n word = s[left:right+1]\n if word in s[right+1:]:\n ans = max(ans, len(word))\n else:\n break\n right+=1\n\nprint(ans)\n", "passed": true, "time": 4.96, "memory": 14876.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n# E\n# \u6587\u5b57\u5217\u6bd4\u8f03\u3092\u30ed\u30fc\u30ea\u30f3\u30b0\u30cf\u30c3\u30b7\u30e5\u3092\u7528\u3044\u308b\u3068\u9ad8\u901f\n\nimport sys\nfrom collections import defaultdict, deque\nfrom heapq import heappush, heappop\nimport math\nimport bisect\ninput = sys.stdin.readline\n\n# \u518d\u8d77\u56de\u6570\u4e0a\u9650\u5909\u66f4\n# sys.setrecursionlimit(1000000)\n\nn = int(input())\ns = input()[:-1]\n# s = list(map(ord, list(input()[:-1])))\n# print(s)\n\nlb = 0\nub = n//2 + 1\n\n\ndef check(len):\n for l1 in range(n-len):\n for l2 in range(l1+len, n-len+1):\n if s[l1:l1+len] == s[l2:l2+len]:\n return True\n return False\n\n\nmod = 10**9+7\nbase = 1234\npower = [1]*(n+1)\nfor i in range(1, n+1):\n power[i] = power[i-1]*base%mod\n\n\ndef check2(m):\n res = 0\n for i in range(m):\n res+=s[i]*power[m-i-1]\n res%=mod\n\n dic = {res: 0}\n # defaultdict\u304c\u65e9\u3044\n # dic = defaultdict(int)\n # dic[res] = 0\n\n for i in range(n-m):\n res = ((res-s[i]*power[m-1])*base\n +s[i+m])%mod\n if res in dic.keys():\n index = dic[res]\n if index +m<=i+1:\n return True\n else:\n dic[res] = i+1\n return False\n\n\ndef check3(m):\n dic = {}\n for i in range(n-m+1):\n s_ = s[i:i+m]\n if s_ in dic.keys():\n if dic[s_]+m<=i:\n return True\n else:\n dic[s_] = i\n return False\n\n\nwhile ub > lb+1:\n x = (lb + ub)//2\n if check3(x):\n lb = x\n else:\n ub = x\n # print(lb, ub)\n\n\n'''\nprint(3, check(3))\nprint(4, check(4))\nprint(5, check(5))\n'''\n\nprint(lb)", "passed": true, "time": 2.42, "memory": 19128.0, "status": "done"}, {"code": "class RollingHash():\n def __init__(self,s):\n self.n=n=len(s)\n self.b=b=129\n self.M=M=2**61-1\n x,y=1,0\n self.f=f=[x]*(n+1)\n self.h=h=[y]*(n+1)\n for i,c in enumerate(s.encode()):\n f[i+1]=x=x*b%M\n h[i+1]=y=(y*b+c)%M\n def get(self,l,r):\n return(self.h[r]-self.h[l]*self.f[r-l])%self.M\ndef main():\n n=int(input())\n s=RollingHash(input())\n ok,ng=0,n\n while ng-ok>1:\n mid=ok+ng>>1\n d={}\n for i in range(0,n-mid+1):\n k=s.get(i,i+mid)\n if k in d:\n if d[k]+mid<=i:\n ok=mid\n break\n else:\n d[k]=i\n else:\n ng=mid\n print(ok)\nmain()", "passed": true, "time": 3.31, "memory": 14952.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nj = 1\nresult = []\nfor i in range(n):\n while (j < n-1) and (s[i:j] in s[:i]+\"0\"+s[j:]):\n j += 1\n result.append(j-i-1)\nprint(max(result))", "passed": true, "time": 8.66, "memory": 15184.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nMOD = 10 ** 18 + 7\nA = 123456\n\ndef ok(l):\n rolling_hash = 0\n strings = {}\n for i in range(n):\n rolling_hash *= A\n rolling_hash += ord(s[i])\n if i - l >= 0: rolling_hash -= ord(s[i-l]) * pow(A, l, MOD)\n rolling_hash %= MOD\n if i < l-1:continue\n if rolling_hash not in strings:\n strings[rolling_hash] = []\n strings[rolling_hash].append(i)\n\n for string in strings:\n if strings[string][-1] - strings[string][0] >= l:\n return True\n return False\n \n\nbottom, top = 0, n\n\nwhile top - bottom > 1:\n mid = (top + bottom) // 2\n if ok(mid): bottom = mid\n else: top = mid\n\nprint(bottom)", "passed": true, "time": 7.52, "memory": 15176.0, "status": "done"}, {"code": "import random\nfrom collections import defaultdict\n\n\ndef atoi(s):\n return ord(s) - ord(\"a\") + 1\n\n\nN = int(input())\nS = input()\n\nmod = (1 << 61) - 1\nb = random.randint(10000, mod - 1)\n\n\nl = 0\nr = (N + 1) // 2 + 1\nwhile r - l > 1:\n d = (r + l) // 2\n memo = defaultdict(int)\n isok = False\n h = 0\n t = pow(b, d, mod)\n for i in range(d):\n h = (h * b + atoi(S[i])) % mod\n memo[h] = 1\n for i in range(1, N - d + 1):\n h = (h*b + atoi(S[i+d-1]) - t * atoi(S[i-1])) % mod\n if not memo[h]:\n memo[h] = i + 1\n elif memo[h] and i - memo[h] + 1 >= d:\n isok = True\n if isok:\n l = d\n else:\n r = d\n\nprint(l)", "passed": true, "time": 2.75, "memory": 15072.0, "status": "done"}, {"code": "import sys\ndef input(): return sys.stdin.readline().rstrip()\n\n\ndef is_ok(arg, S):\n # \u6761\u4ef6\u3092\u6e80\u305f\u3059\u304b\u3069\u3046\u304b\uff1f\u554f\u984c\u3054\u3068\u306b\u5b9a\u7fa9\n dic = {}\n ans = False\n for i in range(len(S)-arg+1):\n c = S[i:i+arg]\n if c in dic:\n if i-dic[c] >= arg:\n ans = True\n break\n else:\n dic[c] = i\n return ans\n\n\ndef meguru_bisect(ng, ok, S):\n '''\n \u521d\u671f\u5024\u306eng,ok\u3092\u53d7\u3051\u53d6\u308a,is_ok\u3092\u6e80\u305f\u3059\u6700\u5c0f(\u6700\u5927)\u306eok\u3092\u8fd4\u3059\n \u307e\u305ais_ok\u3092\u5b9a\u7fa9\u3059\u3079\u3057\n ng ok \u306f \u3068\u308a\u5f97\u308b\u6700\u5c0f\u306e\u5024-1 \u3068\u308a\u5f97\u308b\u6700\u5927\u306e\u5024+1\n \u6700\u5927\u6700\u5c0f\u304c\u9006\u306e\u5834\u5408\u306f\u3088\u3057\u306a\u306b\u3072\u3063\u304f\u308a\u8fd4\u3059\n '''\n while (abs(ok - ng) > 1):\n mid = (ok + ng) // 2\n if is_ok(mid, S):\n ok = mid\n else:\n ng = mid\n return ok\n\n\ndef main():\n N = int(input())\n S = input()\n print((meguru_bisect((N//2)+1, -1, S)))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 2.31, "memory": 19032.0, "status": "done"}, {"code": "# 32bit\u306eMod\u4e00\u3064\u3067RollingHash\u3092\u884c\u3063\u305f\u5834\u5408\u3001\n# 10**5\u500b\u7a0b\u5ea6\u306eHash\u3092\u751f\u6210\u3059\u308b\u3060\u3051\u3067\u3082\n# \u534a\u5206\u4ee5\u4e0a\u306e\u78ba\u7387\u3067\u3069\u3053\u304b\u306eHash\u304c\u885d\u7a81\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3059\n\n\n# \u5c0f\u6587\u5b57\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u306e\u6642\u306ebese\nbase = 27 # alphabet\n\n\ndef getnum(x):\n return ord(x) - ord(\"a\") + 1\n\n\n# rolling hash\u5b9f\u88c5\n\n# \u5fc5\u8981\u306a\u5b9a\u6570\n# mod = 1<<61-1\u3068\u3057\u305f\u3068\u304d\u306e\u9ad8\u901f\u4f59\u308a\u8a08\u7b97\nm30 = (1 << 30) - 1\nm31 = (1 << 31) - 1\nm61 = (1 << 61) - 1\nmod = m61\npositive_delta = m61 ** 4\n\n# \u9ad8\u901f\u5316\u3055\u308c\u305f\u8a08\u7b97\ndef mul(a, b):\n au = a >> 31\n ad = a & m31 # \u4f59\u308a\u3092\u53d6\u308b\u3053\u3068\u304c&\u6f14\u7b97\u3067\u3067\u304d\u308b\n bu = b >> 31\n bd = b & m31\n mid = ad * bu + au * bd\n midu = mid >> 30\n midd = mid & m30\n return calcmod(au * bu * 2 + midu + (midd << 31) + ad * bd)\n\n\ndef calcmod(a):\n au = a >> 61\n ad = a & m61\n res = au + ad\n if res >= m61:\n res -= m61\n return res\n\n\n# s:string\ndef rollinghash(s):\n num = len(s)\n res = [0] * (num + 1)\n pow_base = [1] * (num + 1)\n for i in range(num):\n res[i + 1] = calcmod(mul(res[i], base) + getnum(s[i]))\n pow_base[i + 1] = calcmod(mul(pow_base[i], base))\n return res, pow_base\n\n\ndef search(left, right, rh):\n return calcmod(rh[right] - mul(rh[left], pow_base[right - left]) + positive_delta)\n\n\nn = int(input())\ns = input()\nrh, pow_base = rollinghash(s)\n\nng = n\nok = 0\n\n\ndef hantei(x, rh):\n kumi = {}\n for i in range(n - x + 1):\n temp = search(i, i + x, rh)\n if temp in kumi:\n pre_idx = kumi[temp]\n if i - pre_idx >= x:\n # print(\"pair\", i, pre_idx, \"delta\", x)\n return True\n else:\n kumi[temp] = i\n # print(x, kumi)\n return False\n\n\nwhile ng - ok > 1:\n mid = (ng + ok) // 2\n if hantei(mid, rh):\n ok = mid\n else:\n ng = mid\n # print(ok, ng)\n\nprint(ok)\n", "passed": true, "time": 4.09, "memory": 15056.0, "status": "done"}, {"code": "def solve():\n N = int(input())\n Ss = input().rstrip()\n\n def isOK(L):\n setCand = set()\n RHs = []\n for i in range(N-L+1):\n RH = hash(Ss[i:i+L])\n RHs.append(RH)\n if i-L >= 0:\n setCand.add(RHs[i-L])\n if RH in setCand:\n return True\n return False\n\n ng, ok = N//2+1, 0\n while abs(ok-ng) > 1:\n mid = (ng+ok) // 2\n if isOK(mid):\n ok = mid\n else:\n ng = mid\n\n print(ok)\n\n\nsolve()\n", "passed": true, "time": 2.2, "memory": 15212.0, "status": "done"}, {"code": "class RollingHash():\n def __init__(self, s, base, mod):\n self.mod = mod\n self.pw = pw = [1]*(len(s)+1)\n\n l = len(s)\n self.h = h = [0]*(l+1)\n\n v = 0\n for i in range(l):\n h[i+1] = v = (v * base + ord(s[i])) % mod\n v = 1\n for i in range(l):\n pw[i+1] = v = v * base % mod\n def get(self, l, r): #S[l:r]index\u3067\u3044\u3046l\u6587\u5b57\u76ee\u304b\u3089r-l\u6587\u5b57\u76ee\u3002r-l\u6587\u5b57\u3002\n return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod\n\n def check(self, d):\n ma = {}\n for i in range(N-d+1): #0\u304b\u3089N-d\u307e\u3067\n p = self.get(i,i+d)\n if p in ma:\n if i - ma[p] >= d: #d\u6587\u5b57\u4ee5\u4e0a\u96e2\u308c\u3066\u3044\u308b\u304b\n return True\n else:\n ma[p] = i\n return False\n \n \nN =int(input())\nS = str(input())\n\nbase1 = 1007\nmod1 = 10**9+7\n\nRH = RollingHash(S,base1,mod1)\n\nleft = 0\nright = N//2+1\nwhile right - left >1:\n mid = (left+right)//2\n if RH.check(mid): #\u3053\u3061\u3089\u304cok\u306e\u65b9\n left = mid\n else:\n right = mid\n\nprint(left) \n", "passed": true, "time": 1.34, "memory": 15028.0, "status": "done"}, {"code": "from collections import defaultdict\n\nclass RollingHash(object):\n def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):\n self.S = S\n self.N = N = len(S)\n self.MOD = MOD\n self.BASE = BASE\n self.S_arr = [ord(x) for x in S]\n\n self.POWER = [1] * (N + 1)\n self.HASH = [0] * (N + 1)\n p, h = 1, 0\n for i in range(N):\n self.POWER[i + 1] = p = (p * BASE) % MOD\n self.HASH[i + 1] = h = (h * BASE + self.S_arr[i]) % MOD\n\n def hash(self, l: int, r: int):\n # get hash for S[l:r]\n _hash = self.HASH[r] - (self.HASH[l] * self.POWER[r - l] % self.MOD)\n if _hash < 0:\n _hash += self.MOD\n return _hash\n\n# \u6c4e\u7528\u7684\u306a\u4e8c\u5206\u63a2\u7d22\u306e\u30c6\u30f3\u30d7\u30ec\n# check_func(x) = true \u3068\u306a\u308bx\u306e\u6700\u5c0f\u5024\u3092\u63a2\u7d22\u3059\u308b\n# left : check_func(x) = false\u3068\u306a\u308bx\n# right: check_func(x) = true \u3068\u306a\u308bx\n# search_max: check_func(x) = true \u3068\u306a\u308bx\u306e\"\u6700\u5927\u5024\"\u3092\u63a2\u7d22\u3059\u308b\u5834\u5408\u306fTrue\n# check_func: answer <= x \u3067\u3042\u308c\u3070check_func(x) = true \u3068\u306a\u308b\u3088\u3046\u306a\u95a2\u6570\ndef binary_search(left: int, right: int, check_func, search_max:bool=False):\n # ok \u3068 ng \u306e\u3069\u3061\u3089\u304c\u5927\u304d\u3044\u304b\u308f\u304b\u3089\u306a\u3044\u3053\u3068\u3092\u8003\u616e\n while abs(right - left) > 1:\n mid = (left + right) // 2\n \n if check_func(mid) ^ search_max:\n right = mid\n # print(left, right, mid, 't')\n else:\n left = mid\n # print(left, right, mid, 'f')\n\n return left if search_max else right\n\ndef main():\n N = int(input())\n S = input()\n\n rs = RollingHash(S)\n\n # \u9577\u3055L\u306e\u90e8\u5206\u6587\u5b57\u5217\u540c\u58eb\u304c\u3001\u7bc4\u56f2\u3092\u91cd\u306d\u305a\u540c\u3058\u6587\u5b57\u5217\u3068\u306a\u308b\u5834\u5408\u306fTrue,\n # \u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306fFalse\u3092\u8fd4\u3059\u95a2\u6570\n def isOK(L):\n if L == 0:\n return True\n hash_to_left = defaultdict(list)\n for i in range(N - L + 1):\n _hash = rs.hash(i, i + L)\n # hash\u304c\u885d\u7a81\u3057\u3066\u3082\u6587\u5b57\u5217\u304c\u5b8c\u5168\u306b\u4e00\u81f4\u3059\u308b\u304b\u5206\u304b\u3089\u306a\u3044\u306e\u3067\u3001\n # \u885d\u7a81\u3057\u305f\u5834\u5408\u306f\u6587\u5b57\u5217\u304c\u5b8c\u5168\u306b\u4e00\u81f4\u3059\u308b\u304b\u8abf\u3079\u3001\u304b\u3064\n # \u6587\u5b57\u5217\u540c\u58eb\u304cS\u306e\u4e2d\u3067\u91cd\u306a\u308b\u3088\u3046\u306a\u7bc4\u56f2\u306b\u306a\u3044\u5834\u5408\u306fOK\u3068\u3059\u308b\n for j in hash_to_left[_hash]:\n if j+L <= i and S[i:i+L] == S[j:j+L]:\n return True\n hash_to_left[_hash].append(i)\n\n return False\n # \u7bc4\u56f2\u304c\u91cd\u306a\u3089\u306a\u3044\u3053\u3068\u304c\u6761\u4ef6\u306b\u3042\u308b\u306e\u3067\u3001\u7b54\u3048\u306f\u6700\u5927\u3067\u3082N // 2\uff08\u6587\u5b57\u5217\u306e\u9577\u3055\u306e\u534a\u5206\uff09\u3068\u306a\u308b\u3002\n # \u305f\u3060\u3057\u3001\u4e8c\u5206\u63a2\u7d22\u3059\u308b\u4e0a\u3067\u7d76\u5bfe\u306b\u7b54\u3048\u3068\u306a\u3089\u306a\u3044\u7bc4\u56f2\u3092\u542b\u3081\u305f\u3044\u306e\u3067\u3001\n # \u63a2\u7d22\u7bc4\u56f2\u3068\u3057\u3066\u306fN // 2 + 1 \u3068\u3001+1\u3057\u3066\u304a\u304f\u3002\n ans = binary_search(0, N // 2 + 1, isOK, search_max=True)\n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 4.1, "memory": 15188.0, "status": "done"}, {"code": "import random\nfrom collections import defaultdict\nfrom itertools import accumulate\nimport sys\ninput = sys.stdin.readline\nn = int(input())\ns = input().rstrip()\nmod = (1<<61)-1\nbase = 1000+random.randint(0,100)\npower = [1]\nfor i in range(1,n):\n power.append((power[-1]*base)%mod)\nhvalue = [0]\nfor i in range(n):\n hvalue.append((hvalue[-1]+(ord(s[i])*power[i]))%mod)\ndef rollinghash(l,r):\n return ((hvalue[r]-hvalue[l])*power[n-r])%mod\ndef pun(i):\n dc = defaultdict(int)\n if i>n//2:\n return False\n for j in range(n-i+1):\n x = rollinghash(j,i+j)\n if dc[x]:\n rg =dc[x]\n if rg<=j:\n return True\n else:\n dc[x] = i+j\n return False\nl=0\nr=n//2+1\nwhile l+1<r:\n mi=(l+r)//2\n if pun(mi):\n l=mi\n else:\n r=mi\nprint(l)\n", "passed": true, "time": 1.85, "memory": 15220.0, "status": "done"}, {"code": "n=int(input())\ns=input()\nl=0\nr=n\nwhile r-l>1:\n mid=(r+l)//2\n dic={}\n flag=False\n for i in range(n-mid+1):\n tmp=s[i:i+mid]\n if tmp not in dic:\n dic[tmp]=i+mid\n else:\n if dic[tmp]<=i:\n flag=True\n break\n if flag:\n l=mid\n else:\n r=mid\nprint(l)", "passed": true, "time": 2.72, "memory": 19160.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n# E\n# \u6587\u5b57\u5217\u6bd4\u8f03\u3092\u30ed\u30fc\u30ea\u30f3\u30b0\u30cf\u30c3\u30b7\u30e5\u3092\u7528\u3044\u308b\u3068\u9ad8\u901f\n# \u7528\u3044\u306a\u304f\u3066\u3082pypy\u4f7f\u308f\u306a\u304f\u3048\u308c\u3070\u901a\u308b\n\nimport sys\nfrom collections import defaultdict, deque\nfrom heapq import heappush, heappop\nimport math\nimport bisect\ninput = sys.stdin.readline\n\n# \u518d\u8d77\u56de\u6570\u4e0a\u9650\u5909\u66f4\n# sys.setrecursionlimit(1000000)\n\nn = int(input())\ns = input()[:-1]\n# s = list(map(ord, list(input()[:-1])))\n# print(s)\n\nlb = 0\nub = n//2 + 1\n\n\ndef check(len):\n # \u3053\u308c\u306fTLE\n for l1 in range(n-len):\n for l2 in range(l1+len, n-len+1):\n if s[l1:l1+len] == s[l2:l2+len]:\n return True\n return False\n\n\ndef check3(m):\n # \u3053\u308c\u306fOK(pypy\u3067\u306f\u306a\u304fpython3\uff09\n dic = defaultdict(str)\n # dic = {}\n for i in range(n-m+1):\n s_ = s[i:i+m]\n if s_ in dic.keys():\n if dic[s_]+m<=i:\n return True\n else:\n dic[s_] = i\n return False\n\n\nmod = 10**9+7\nbase = 1234\npower = [1]*(n+1)\nfor i in range(1, n+1):\n power[i] = power[i-1]*base%mod\n\ndef check2(m):\n res = 0\n for i in range(m):\n res+=s[i]*power[m-i-1]\n res%=mod\n\n dic = {res: 0}\n # defaultdict\u304c\u65e9\u3044\n # dic = defaultdict(int)\n # dic[res] = 0\n\n for i in range(n-m):\n res = ((res-s[i]*power[m-1])*base\n +s[i+m])%mod\n if res in dic.keys():\n index = dic[res]\n if index +m<=i+1:\n return True\n else:\n dic[res] = i+1\n return False\n\n\nwhile ub > lb+1:\n x = (lb + ub)//2\n if check3(x):\n lb = x\n else:\n ub = x\n # print(lb, ub)\n\n\n'''\nprint(3, check(3))\nprint(4, check(4))\nprint(5, check(5))\n'''\n\nprint(lb)", "passed": true, "time": 2.31, "memory": 19116.0, "status": "done"}, {"code": "from typing import List\n\n\nclass RollingHash:\n \"\"\"Rolling Hash\"\"\"\n\n __slots__ = [\"_length\", \"_base\", \"_mod\", \"_hash\", \"_power\"]\n\n def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):\n self._length = len(source)\n self._base = base\n self._mod = mod\n self._hash = self._build_hash_from_zero(source)\n self._power = self._build_base_power()\n\n def _build_hash_from_zero(self, source: str) -> List[int]:\n \"\"\"Compute hash of interval [0, right).\"\"\"\n res = [0] * (self._length + 1)\n for i, c in enumerate(source, 1):\n res[i] = (res[i - 1] * self._base + ord(c)) % self._mod\n return res\n\n def _build_base_power(self) -> List[int]:\n \"\"\"Compute mod of power of base.\"\"\"\n res = [1] * (self._length + 1)\n for i in range(1, self._length + 1):\n res[i] = res[i - 1] * self._base % self._mod\n return res\n\n def get_hash(self, left: int, right: int):\n \"\"\"Return hash of interval [left, right).\"\"\"\n return (\n self._hash[right] - self._hash[left] * self._power[right - left]\n ) % self._mod\n\n\ndef abc141_e():\n # https://atcoder.jp/contests/abc141/tasks/abc141_e\n N = int(input())\n S = input().rstrip()\n\n rh = RollingHash(S)\n ok, ng = 0, N // 2 + 1\n while ng - ok > 1:\n mid = (ok + ng) // 2\n flg = False\n memo = set()\n for i in range(N - 2 * mid + 1):\n memo.add(rh.get_hash(i, i + mid))\n if rh.get_hash(i + mid, i + 2 * mid) in memo:\n flg = True\n break\n if flg:\n ok = mid # next mid will be longer\n else:\n ng = mid # next mid will be shorter\n\n print(ok) # max length of substrings appeared twice or more\n\n\ndef __starting_point():\n abc141_e()\n\n__starting_point()", "passed": true, "time": 1.45, "memory": 16196.0, "status": "done"}, {"code": "n=int(input())\ns=list(map(ord,list(input())))\nfor i in range(n):s[i]-=97\n\nfrom random import randint\nroli_mod=1370757747362922367\nroli_r=randint(2,roli_mod-2)\nroli=[0]\nroli_rr=1\nfor i in range(n):\n roli.append((roli[-1]+roli_rr*s[i])%roli_mod)\n roli_rr*=roli_r\n roli_rr%=roli_mod\ndef roli_hash(i,j):return ((roli[j+1]-roli[i]+roli_mod)%roli_mod)*pow(roli_r,roli_mod-1-i,roli_mod)%roli_mod\ndef roli_check(i1,j1,i2,j2):return roli_hash(i1,j1)==roli_hash(i2,j2)\n\nok=0\nng=(n+1)//2+1\nwhile ok+1!=ng:\n i=(ok+ng)//2\n d={}\n f=False\n for j in range(n-i+1):\n h=roli_hash(j,j+i-1)\n if h in d:\n if j-d[h]>=i:\n f=True\n break\n else:d[h]=j\n if f:ok=i\n else:ng=i\nprint(ok)", "passed": true, "time": 32.53, "memory": 15060.0, "status": "done"}, {"code": "N = int(input())\nS = input()\n\nMOD = 2 ** 61 - 1\nroot = 10000\n\nrhs = [0]\nfor h in map(ord, S):\n rhs.append((root * rhs[-1] + h) % MOD)\n\npws = [1]\nfor i in range(N):\n pws.append(pws[-1] * root % MOD)\n\nok = 0\nng = N\nwhile ng - ok > 1:\n mid = (ok + ng) // 2\n hashes = dict()\n flg = False\n for i in range(N - mid + 1):\n hashofsub = (rhs[i+mid] - rhs[i] * pws[mid]) % MOD\n if hashofsub in hashes:\n if i >= hashes[hashofsub] + mid:\n flg = True\n break\n else:\n hashes[hashofsub] = i\n \n if flg:\n ok = mid\n else:\n ng = mid\n\nprint(ok)", "passed": true, "time": 1.34, "memory": 14992.0, "status": "done"}, {"code": "from typing import List\n\n\nclass RollingHash:\n \"\"\"Rolling Hash\"\"\"\n\n __slots__ = [\"_base\", \"_mod\", \"_hash\", \"_power\"]\n\n def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):\n self._base = base\n self._mod = mod\n self._hash = self._build_hash_from_zero(source)\n self._power = self._build_base_power(len(source))\n\n def _build_hash_from_zero(self, source: str) -> List[int]:\n \"\"\"Compute hash of interval [0, right).\"\"\"\n res = [0] * (len(source) + 1)\n for i, c in enumerate(source, 1):\n res[i] = (res[i - 1] * self._base + ord(c)) % self._mod\n return res\n\n def _build_base_power(self, length: int) -> List[int]:\n \"\"\"Compute mod of power of base.\"\"\"\n res = [1] * (length + 1)\n for i in range(1, length + 1):\n res[i] = res[i - 1] * self._base % self._mod\n return res\n\n def get_hash(self, left: int, right: int):\n \"\"\"Return hash of interval [left, right).\"\"\"\n return (\n self._hash[right] - self._hash[left] * self._power[right - left]\n ) % self._mod\n\n\ndef abc141_e():\n # https://atcoder.jp/contests/abc141/tasks/abc141_e\n N = int(input())\n S = input().rstrip()\n\n rh = RollingHash(S)\n ok, ng = 0, N // 2 + 1\n while ng - ok > 1:\n mid = (ok + ng) // 2\n flg = False\n memo = set()\n for i in range(N - 2 * mid + 1):\n memo.add(rh.get_hash(i, i + mid))\n if rh.get_hash(i + mid, i + 2 * mid) in memo:\n flg = True\n break\n if flg:\n ok = mid # next mid will be longer\n else:\n ng = mid # next mid will be shorter\n\n print(ok) # max length of substrings appeared twice or more\n\n\ndef __starting_point():\n abc141_e()\n\n__starting_point()", "passed": true, "time": 1.46, "memory": 16280.0, "status": "done"}, {"code": "from typing import List\n\n\nclass RollingHash:\n __slots__ = [\"source\", \"length\", \"base\", \"mod\", \"hash\", \"power\"]\n\n def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):\n self.source = source\n self.length = len(source)\n self.base = base\n self.mod = mod\n self.hash = self._get_hash_from_zero()\n self.power = self._get_base_pow()\n\n def _get_hash_from_zero(self) -> List[int]:\n \"\"\"Compute hash of interval [0, right).\"\"\"\n hash_from_zero = [0] * (self.length + 1)\n cur = 0\n for i, c in enumerate(self.source, 1):\n cur = (cur * self.base + ord(c)) % self.mod\n hash_from_zero[i] = cur\n return hash_from_zero\n\n def _get_base_pow(self) -> List[int]:\n \"\"\"Compute mod of power of base.\"\"\"\n power = [1] * (self.length + 1)\n cur = 1\n for i in range(1, self.length + 1):\n cur *= self.base % self.mod\n power[i] = cur\n return power\n\n def get_hash(self, left: int, right: int):\n \"\"\"Compute hash of interval [left, right).\"\"\"\n return (\n self.hash[right] - self.hash[left] * self.power[right - left]\n ) % self.mod\n\n\ndef abc141_e():\n # https://atcoder.jp/contests/abc141/tasks/abc141_e\n N = int(input())\n S = input().rstrip()\n rh = RollingHash(S)\n ok, ng = 0, N // 2 + 1\n while ng - ok > 1:\n mid = (ok + ng) // 2\n flg = False\n memo = set()\n for i in range(N - 2 * mid + 1):\n memo.add(rh.get_hash(i, i + mid))\n if rh.get_hash(i + mid, i + 2 * mid) in memo:\n flg = True\n break\n if flg:\n ok = mid # next mid will be longer\n else:\n ng = mid # next mid will be shorter\n print(ok) # max length of substrings appeared twice or more\n\n\ndef __starting_point():\n abc141_e()\n\n__starting_point()", "passed": true, "time": 6.29, "memory": 30516.0, "status": "done"}, {"code": "I=input;n=int(I());s=I();j=r=0\nfor i in range(n):\n while (j<n)and(s[i:j] in s[j:]):j+=1\n r=max(r,j-i-1)\nprint(r)", "passed": true, "time": 2.94, "memory": 15112.0, "status": "done"}] | [{"input": "5\nababa\n", "output": "2\n"}, {"input": "2\nxy\n", "output": "0\n"}, {"input": "13\nstrangeorange\n", "output": "5\n"}, {"input": "5000\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n", "output": "2500\n"}, {"input": "5000\nkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkikkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkrkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkakkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkzkkkkkkkkkkkkkkkk\n", "output": "1892\n"}, {"input": "5000\nvgxgpuamkxkszhkbpphykinkezplvfjaqmopodotkrjzrimlvumuarenexcfycebeurgvjyospdhvuyfvtvnrdyluacvrayggwnpnzijdifyervjaoalcgxovldqfzaorahdigyojknviaztpcmxlvovafhjphvshyfiqqtqbxjjmqngqjhwkcexecmdkmzakbzrkjwqdyuxdvoossjoatryxmbwxbwexnagmaygzyfnzpqftobtaotuayxmwvzllkujidhukzwzcltgqngguftuahalwvjwqncksizgzajkhyjujlkseszafzjmdtsbyldhylcgkyngvmhneqyjdugofklitxaoykfoqkzsznjyarkuprerivhubpehxmoydakklbdnfhfxamotubelzvbozjaraefmlotftnqrjolvuamahndekfdsqcfvmqbocbomjxrqsfskevfxphcqoqkbbomcyurwlrnhrhctntzlylvwulbdkcdppgykichjtpukfnlxfcevkjezqsmeycanjlbessrfazdprcomdpjimsfbuslksyveergcgmonctcsvypolplcgsqyfkilrixodiwqcyreiwkrpiuiasfkjexpftznqiblsrjuyfskndapwjefucdqciuehvfndghrxxnmvzljxioyundvpndabsbnwoeyomrjdcqcrxvyahermudccmueahebyvsakxwseqzduyfezujaffdrsqfseqsdfcgdenmrfwfndijtepxhnvedfbagzrxkprtgboukfxiwhfzfksnawgcubspxsiuytqrwmvxfsvzlotlfwimliygnfddeswmxuvhnqvjzgkpdzfjmcjcmsaaskextlsjrggtycgcqfpoqomrouhjkntqryhjifcxbywhfutfzmjcdlivnuxmrdfghkqlqzaeeazkoomvpysjwncyqyabutsitezurqhbuwabexrcuiwafnfvcasmrmbqnupruskhsmeicaqqesyyvopepmvdosibrvqoghdeikbpqbfgrufxdsqchjkuxpxngebxrmqdgqjsosencrbwknllvucvubyozfmttxtlsrrnrqavshaszrenhlbzpnpjgqftvwgukjwsekfcgllbzlnvmosmvqubtwsgltvmmzmslqdxqiifzkaqhsxzguseuexlycgubhdnwhrssyiybitcoowlhmmrdpgtrdwalvffknwibhwhacqfjcmwupoxonavvxwsvprpymskznabsquwssucxrmywerfpziqdziycnynthgmdavybzbqgcrgvwalcptutzxsqlkchithcdezsaeflddflgtixbnagkqrzesckrihwqplfpspkqvifbmnqwidbkzqiygwfunefiwpxueumdwugbfgnojjrjpafgkirrueoezabcqlzmcdwmklvyzvuughetwkxzuzfvoirareyblwprdnetkyigxyqpzxeckygyxthszxgyidgldnlzeqndbvacjqyhfkqvliusqmxyeqyqorzmmjwsuicnyxqnktylaqnvbjlltexgrhifdneugyszncrwgidcfjgdzkoqfqbweuchtdvpiunkpehcshtmrentgsndnbtbbbmoguopypwkapkrwisamnxagzfqsfsxtyxepbpumtlujgxuenmzggjmgiutqoeltnlyboqjegcvuuiilmsbnalvbsfutyarenkewzlpwgqzfnnkexxdsufcjvrbkesrobosuzumuccgmrsmxztpsiqchfclvzkmvfmuscnbrlczvfzwmmktusajdhocmprjlndydxrojjahocitarxlqxqjxqhpfzewpyykzeqjpehsgiqvyezbqwnpyuciobbloxjxuozsuvqwphlhglufbhjgbpkxjxiyeuwmdusfmlxkvqsmwytkjoakbnpgphefwpqnrbxwdaippueolngeddtrxpaxxziwphxkeinqsdivgplbcszjhsxeicksxbsejhgmkihtjcqqwxftjswwptmgzptqnoixwparklayjdsbijtrgtxgzfcpuchdsmkvqrhgdiidnnunwsxscqqnnqmpcpkagzsxmcborwjyqnnousxhsdmklmndntfukmskhnfjnfrvhqomofzkqiptsihalujjxkburwsbdllapwrqcarxmlzqwfcalvwxjflfjtstvrctlbkbsjpnxyhscxdxepbwqecewrzcitmdfbwzhiowcpggbunwiopnjdjcwrmixzquldialdwrdjmbhvkgqysprovnzfrbajessmybyckdqmsxsrydskoiktyfxjombtwyskctdjfquvekmckrwivzayctxcfxptgruprmpnzswuoegwgdbbypiruisjqibacpbombsjoqozzsdgdrgyqyrfrkssntfgudfqrqzxecguclnxeatmlqxsjkyjxifirswzudolgmnljjzjujuayvgxgpuamkxkszhkbpphykinkezplvfjaqmopodotkrjzrimlvumuarenexcfycebeurgvjyospdhvuyfvtvnrdyluacvrayggwnpnzijdifyervjaoalcgxovldqfzaorahdigyojknviaztpcmxlvovafhjphvshyfiqqtqbxjjmqngqjhwkcexecmdkmzakbzrkjwqdyuxdvoossjoatryxmbwxbwexnagmaygzyfnzpqftobtaotuayxmwvzllkujidhukzwzcltgqngguftuahalwvjwqncksizgzajkhyjujlkseszafzjmdtsbyldhylcgkyngvmhneqyjdugofklitxaoykfoqkzsznjyarkuprerivhubpehxmoydakklbdnfhfxamotubelzvbozjaraefmlotftnqrjolvuamahndekfdsqcfvmqbocbomjxrqsfskevfxphcqoqkbbomcyurwlrnhrhctntzlylvwulbdkcdppgykichjtpukfnlxfcevkjezqsmeycanjlbessrfazdprcomdpjimsfbuslksyveergcgmonctcsvypolplcgsqyfkilrixodiwqcyreiwkrpiuiasfkjexpftznqiblsrjuyfskndapwjefucdqciuehvfndghrxxnmvzljxioyundvpndabsbnwoeyomrjdcqcrxvyahermudccmueahebyvsakxwseqzduyfezujaffdrsqfseqsdfcgdenmrfwfndijtepxhnvedfbagzrxkprtgboukfxiwhfzfksnawgcubspxsiuytqrwmvxfsvzlotlfwimliygnfddeswmxuvhnqvjzgkpdzfjmcjcmsaaskextlsjrggtycgcqfpoqomrouhjkntqryhjifcxbywhfutfzmjcdlivnuxmrdfghkqlqzaeeazkoomvpysjwncyqyabutsitezurqhbuwabexrcuiwafnfvcasmrmbqnupruskhsmeicaqqesyyvopepmvdosibrvqoghdeikbpqbfgrufxdsqchjkuxpxngebxrmqdgqjsosencrbwknllvucvubyozfmttxtlsrrnrqavshaszrenhlbzpnpjgqftvwgukjwsekfcgllbzlnvmosmvqubtwsgltvmmzmslqdxqiifzkaqhsxzguseuexlycgubhdnwhrssyiybitcoowlhmmrdpgtrdwalvffknwibhwhacqfjcmwupoxonavvxwsvprpymskznabsquwssucxrmywerfpziqdziycnynthgmdavybzbqgcrgvwalcptutzxsqlkchithcdezsaeflddflgtixbnagkqrzesckrihwqplfpspkqvifbmnqwidbkzqiygwfunefiwpxueumdwugbfgnojjrjpafgkirrueoezabcqlzmcdwmklvyzvuughetwkxzuzfvoirareyblwprdnetkyigxyqpzxeckygyxthszxgyidgldnlzeqndbvacjqyhfkqvliusqmxyeqyqorzmmjwsuicnyxqnktylaqnvbjlltexgrhifdneugyszncrwgidcfjgdzkoqfqbweuchtdvpiunkpehcshtmrentgsndnbtbbbmoguopypwkapkrwisamnxagzfqsfsxtyxepbpumtlujgxuenmzggjmgiutqoeltnlyboqjegcvuuiilmsbnalvbsfutyarenkewzlpwgqzfnnkexxdsufcjvrbkesrobosuzumuccgmrsmxztpsiqchfclvzkmvfmuscnbrlczvfzwmmktusajdhocmprjlndydxrojjahocitarxlqxqjxqhpfzewpyykzeqjpehsgiqvyezbqwnpyuciobbloxjxuozsuvqwphlhglufbhjgbpkxjxiyeuwmdusfmlxkvqsmwytkjoakbnpgphefwpqnrbxwdaippueolngeddtrxpaxxziwphxkeinqsdivgplbcszjhsxeicksxbsejhgmkihtjcqqwxftjswwptmgzptqnoixwparklayjdsbijtrgtxgzfcpuchdsmkvqrhgdiidnnunwsxscqqnnqmpcpkagzsxmcborwjyqnnousxhsdmklmndntfukmskhnfjnfrvhqomofzkqiptsihalujjxkburwsbdllapwrqcarxmlzqwfcalvwxjflfjtstvrctlbkbsjpnxyhscxdxepbwqecewrzcitmdfbwzhiowcpggbunwiopnjdjcwrmixzquldialdwrdjmbhvkgqysprovnzfrbajessmybyckdqmsxsrydskoiktyfxjombtwyskctdjfquvekmckrwivzayctxcfxptgruprmpnzswuoegwgdbbypiruisjqibacpbombsjoqozzsdgdrgyqyrfrkssntfgudfqrqzxecguclnxeatmlqxsjkyjxifirswzudolgmnljjzjujuay\n", "output": "2500\n"}, {"input": "4999\njiiccervhavvgtcwhlsrwaqotogokhtwgjmfqslvhzpgnsfqhgboehmzponrtkqjuanpnufnluezljsqvtofmenwfzlgrrpzetxogobqrhuhlygensbkpwqbwwcznxeiyoztkmgcvjusurktiehahzrntrrasikbabwcsrhacznxyudgfpqdpguijawghwvvfogdvtuhmorjceofctzqygfietzkbegkbsjzmfzrmfpmgvoafxfyinmayuxcjredrydnvlxwvhueaiqgluufbbdtpvtcfhprlyrbvvlntrqzmqawbssranjhaxtjvsxsduozsxloeblcifbyfeuonsyricvccfpkztioalhqhqekydzqxmnzcaplzlyxvfbpdzmlsfmmlgtnfraroebtfduzxgpsaqwcnjiytsrzyfwkrdlabywhcmfgzvcybflkacyhhckasmblhbdjeojnfwylcqvnbmzxugfsiyjguicgffiwrszzdbzjyhvgpnfsapufjqfespxbfljgtdgsmfeecqfwfvkweiacditmsnfaldcqlrycllmccmodlnlbkwvgmdzwapsbzyrwxasqvctbmtbpidedmvrpxqndcahltgzshjaruuemquxrrvthohcdkuurwurkwexhypsbupxuisdeshltsvfhvjvhnxggarvcdaiiaqadyjjernidpersjdqucsauprztyfoiiklhtjsznddftcgelchwbizhesduxmacmzildecegshhntfznbbbgxavmpnflhpxylxkyztwbqwpuymqlnxmetghtnrefeypivpyndobbresgvlmkkxwhlomigirizlngkykrymheywujwmjhnzxmgmkqgsajkykvqjyaplnwkcubvbxdxyheccrzfnehqeizvicxxxesnssfeuzhsjdhxnddsiuvxanfkpeqodirlsywlymiwshvenliuomflsyiqacjuajhxmeklfadfvxvmpknedshbyvenboqueaaiqwexnqgqvjwzfofokvkgdgzhwrtktdberapdnumytfobbqcozojivhkngvyystjgsdfnosjlrxpzfenfyhwajcjupuwyuvkorvmiuplwvooojckjmaqyspyacdngdnmuyrsoislcmorsfgzzksposltnxpvohdspmzkewhwnjmmmgiquywbyjiowewrvfltajjrdugejyjrkwazogerwkhvgtquxuxhrubfrqyfarbiaeporgwquijhbuwqvejgcojncyuopfgfptteusxajvqynzzisgnxjhjetomwbttpgbszzuwrfnorzxtomuwnqpkuttcbybdhluvcextuoxmzgibulszobtmxutcclnyxcdfhznmwhesgezpvxpyczlcgyaqnkgijukiiiucjfueqbmxqnwdcyberszmofrwoclbynjwjcrqayjpcijndyzmctzbaoqeugwrmhpkzvyygkovpckbzetshnebuhtmqqpmbwseocxeobhdjmkfmzvmkezwomlyzpagrxgxybztsxaeunetdtikjbbxuqjcdwyhwregfyjhctuarlqofgwhpyutwrbyebfsswbrczwxkltzjgmfuxarydaggojpheusiubpmqjmhocqmvjospdflivmsrcqtwgxdazunytifhxquasvcgdlozuqzwhfssrcxarcjflftmwngzonwfsvtukxvbsoubbbpbfwjfngelekpmoadizdsortkabmswcmywnbajxnkvmndbvtcpnjxwmoddntsqthusvzmkuedbdkbiqdwpwpssrjjflswufmhclmnstzubtcvqvqsdssgscjyqzwcamnvrilessqpzgqxdlsnclujdsaqbxxyltzlqwluortkqadjcquqdqcsvixgwglwrrmkhdsbebbjvcgzlwtbvasphvmnfvfjykqmimwxemmahhmzoadapworuvlpqolwbmkeskafyzbvzvmmprwaxisdukvmbvcvzwxynrtksbdzkvagihfgiqmsdejxirrowirgqvzelysohwvjfalsgxgzokbfurvecuxsipqvrwqjosfybncihpzjcbxefzvriisgfipsiapdpbssglqjuhvqrxefptimxedahmjqtviqrxnfpoysakxhxrjetydsxixvxyujbvqavxzupqpzdqlnddxfanwnktlpjccpwuygxyyxuafypzoakdxpkahvpjjfdognzbyixybmkdaqlixeutojgtdjltwpxpvumbudckmdxrhqwkrrlltgxdyoaokdparwbanidrfssiuigzduwzejbbnuoiwqlsgteshscnvlmjyiwhagtimrqtffkfgbodlwxirgrmrdhlihyamxmolbyfwcdputedzcwskrpkykqypkslsqnfndigwhjpdqmaclgneblkqcepsnljbyoyxchdiyygwchtcoxyzzblncvosgcffrhazjiiccervhavvgtcwhlsrwaqotogokhtwgjmfqslvhzpgnsfqhgboehmzponrtkqjuanpnufnluezljsqvtofmenwfzlgrrpzetxogobqrhuhlygensbkpwqbwwcznxeiyoztkmgcvjusurktiehahzrntrrasikbabwcsrhacznxyudgfpqdpguijawghwvvfogdvtuhmorjceofctzqygfietzkbegkbsjzmfzrmfpmgvoafxfyinmayuxcjredrydnvlxwvhueaiqgluufbbdtpvtcfhprlyrbvvlntrqzmqawbssranjhaxtjvsxsduozsxloeblcifbyfeuonsyricvccfpkztioalhqhqekydzqxmnzcaplzlyxvfbpdzmlsfmmlgtnfraroebtfduzxgpsaqwcnjiytsrzyfwkrdlabywhcmfgzvcybflkacyhhckasmblhbdjeojnfwylcqvnbmzxugfsiyjguicgffiwrszzdbzjyhvgpnfsapufjqfespxbfljgtdgsmfeecqfwfvkweiacditmsnfaldcqlrycllmccmodlnlbkwvgmdzwapsbzyrwxasqvctbmtbpidedmvrpxqndcahltgzshjaruuemquxrrvthohcdkuurwurkwexhypsbupxuisdeshltsvfhvjvhnxggarvcdaiiaqadyjjernidpersjdqucsauprztyfoiiklhtjsznddftcgelchwbizhesduxmacmzildecegshhntfznbbbgxavmpnflhpxylxkyztwbqwpuymqlnxmetghtnrefeypivpyndobbresgvlmkkxwhlomigirizlngkykrymheywujwmjhnzxmgmkqgsajkykvqjyaplnwkcubvbxdxyheccrzfnehqeizvicxxxesnssfeuzhsjdhxnddsiuvxanfkpeqodirlsywlymiwshvenliuomflsyiqacjuajhxmeklfadfvxvmpknedshbyvenboqueaaiqwexnqgqvjwzfofokvkgdgzhwrtktdberapdnumytfobbqcozojivhkngvyystjgsdfnosjlrxpzfenfyhwajcjupuwyuvkorvmiuplwvooojckjmaqyspyacdngdnmuyrsoislcmorsfgzzksposltnxpvohdspmzkewhwnjmmmgiquywbyjiowewrvfltajjrdugejyjrkwazogerwkhvgtquxuxhrubfrqyfarbiaeporgwquijhbuwqvejgcojncyuopfgfptteusxajvqynzzisgnxjhjetomwbttpgbszzuwrfnorzxtomuwnqpkuttcbybdhluvcextuoxmzgibulszobtmxutcclnyxcdfhznmwhesgezpvxpyczlcgyaqnkgijukiiiucjfueqbmxqnwdcyberszmofrwoclbynjwjcrqayjpcijndyzmctzbaoqeugwrmhpkzvyygkovpckbzetshnebuhtmqqpmbwseocxeobhdjmkfmzvmkezwomlyzpagrxgxybztsxaeunetdtikjbbxuqjcdwyhwregfyjhctuarlqofgwhpyutwrbyebfsswbrczwxkltzjgmfuxarydaggojpheusiubpmqjmhocqmvjospdflivmsrcqtwgxdazunytifhxquasvcgdlozuqzwhfssrcxarcjflftmwngzonwfsvtukxvbsoubbbpbfwjfngelekpmoadizdsortkabmswcmywnbajxnkvmndbvtcpnjxwmoddntsqthusvzmkuedbdkbiqdwpwpssrjjflswufmhclmnstzubtcvqvqsdssgscjyqzwcamnvrilessqpzgqxdlsnclujdsaqbxxyltzlqwluortkqadjcquqdqcsvixgwglwrrmkhdsbebbjvcgzlwtbvasphvmnfvfjykqmimwxemmahhmzoadapworuvlpqolwbmkeskafyzbvzvmmprwaxisdukvmbvcvzwxynrtksbdzkvagihfgiqmsdejxirrowirgqvzelysohwvjfalsgxgzokbfurvecuxsipqvrwqjosfybncihpzjcbxefzvriisgfipsiapdpbssglqjuhvqrxefptimxedahmjqtviqrxnfpoysakxhxrjetydsxixvxyujbvqavxzupqpzdqlnddxfanwnktlpjccpwuygxyyxuafypzoakdxpkahvpjjfdognzbyixybmkdaqlixeutojgtdjltwpxpvumbudckmdxrhqwkrrlltgxdyoaokdparwbanidrfssiuigzduwzejbbnuoiwqlsgteshscnvlmjyiwhagtimrqtffkfgbodlwxirgrmrdhlihyamxmolbyfwcdputedzcwskrpkykqypkslsqnfndigwhjpdqmaclgneblkqcepsnljbyoyxchdiyygwchtcoxyzzblncvosgcffrha\n", "output": "2499\n"}, {"input": "5000\nsevyrfzjizjbkrfppcjbhdpbyicjmvxnsxrlfupsniychutsvgwtrjvnepwfssfovsaxkhenzidohuqrmxxumfddygfeyptzcourhvedkdoacamyuoyeinzlvocydnxykxpfkxwmdocfzgcbwjjzrjzvsltcpvuhznzlvnzbdqyjxqwgbtllqadgxjfzrtmmvbdkczrkylnzejaipldlctxvklofqnqffkydzgtfbfergkeqmcvylzqiiuocwgdvicasicruggkbsrgyldpiwkuruyihbergcggxwujdprokxykqqbuitespohbqnkqkugwhlhkgabaphqtfdbfhgvbluyxwzopsqeukclfkfwkxqwzakbwbhilyfkyoiitlshcncyqdmjnfjekjjdzqswmjvndtmyanvucnzbduamhapynggabonfabhvnqmksnyhyydlhkfhhdkhvsusnwppwdwvayfksmbsxujuvlaigwmqsnzytvwbplyydsprlucgxoaajllvqiihbckzlpasfsnsusyfhbmcbfostwisfnreqqytkdcahmkztuaxojiftfvwwvmodljmnbjeoifeynmaxzktxxpedagsnzuvfrkigjdckuzosknadbflgiskpphygxzmcmfazjxazhbqbqrrezxlniokhfkkpdrhtcrueqxlxxdcvjlxisjxawespgxoxjygeoqzemxikvpqrfqbxyarjwojekexbqaedyuiplldvkykwpwmzheiqgdnksfymiuinmorlizmxmlhxsjotkroyphykjhrbexhafvcjetiimmpqkspsploayapwbxujwjbbihvgvkdcfpabbaymczpimztoqbidtjsdnkgudecsfsrrezfbtuxixjkipxtncfquqdtaniwlevdyodliiwuvbogqzwwpurcqvrysjzdbsucbxnlkfgcvwagoiqigsnvkwemybvxuaermvjjldzspjkpveofjvpvgvoksjyifnlgbrubyvndynhvludryljrgbkyszbxnvdbyahlztqxuibbotbfkhsgykpgcrwlmxzmhiovklijtbutfdiojsclmcjttaflmsydwunheikkskjhxadktuynceyajdkveimksqwlogdyyddksrarlpgfzznzuajfrfeunqjuawjhfmarnjuiyeuztdvrzhcezvsfkhcdgttnpfnkhsypmxbobnqylloakfknoypeoritdiqrkmjifoueibycuxnqnunbtnlnkciohefuqcyfobiiybuwprqrfokonirfilfqgjhfplyasyjmzqpdwtsbkgqcyuvtbunqnhnaefgpjnvagtpxfqrgmxtsvajtrpbdbnzqackjdtammeuasetgwfzwbysfomabhmxhlnqtbalmjfhxrogodukweyzmjfhkiiatypltuntsxajrcdzfjwfxrqwhposvxedxomrdmbqhavocmvtkggpulovcckleycfgtypcncnhtwuwrmzjpbscimpxczrpbixqvamegseypgecddfoflqtasxngkywtairategyvzxttvbfddkwxobezxfnwpzxkjcdpnlvwozndnfeguhycdoomtxbpiqlqwotoibbqzwxvgkmqwowatzozgbtrdkndcpivaildyxkknzyiyytbflwpaitvirsptzdhlfsiabomdxqhtfnvleuouktabuawprturpumhgkbuacfffoxriugzaqsenyfnmgqjmsjvobaeuqkgwpyvwpafbnxiodtcemcdqaxvlnycqyvaxxybhvdkhiuhpvumqbfrywtqkuvjjeaexycjzhrfcldugqrviylxubxwgtcptvelfadqxbcvtseznbbuaeudgejcvytastwczyjqhglyhztgddicbnlvytjhmhenxsdhvlyflhzqsoidecojqgxsqkhvfkpldtoqyrgadzgioolynwzxjruiiybwcnwaupwgmueqdfyvsvlbhqqxkceebmwqjypiygyzcdbzpkyrhrojqmqsbjilamakicreoruijzrhwwfkbvzuajrsccdhbkunzvwrhsiphmbdamnnqkhtfkyqrdrcexzftuaxfrphoipmzxczjcuoqczgprmziotdisoskroxjkleahtirtmveucayqvjbjcrndjvxvvoumpcgczwumaapdepshnaimatolvnlmepbjzwxmacwilfykkkuysuccmftjuoccupagbyakrugnnsgrvbxdwgtqzzwhbkyjdkfniepbolviwsbevypmekzmevxohkslylosuskcvehbyrruykohnencvyodstlpwdwooonhniyegmyekmtopuwykwcthhdwzqxocnqgzmtctbpuillkmawssjtrgxlspqqyczvkhhfcuglidembzunqfspcphjqtuaywqbjjsqydfojzofirjwoiobxhfdimsvisxeyyrksqalvhuqlaasevyrfzjizjbkrfppcjbhdpbyicjmvxnsxrlfupsniychutsvgwtrjvnepwfssfovsaxkhenzidohuqrmxxumfddygfeyptzcourhvedkdoacamyuoyeinzlvocydnxykxpfkxwmdocfzgcbwjjzrjzvsltcpvuhznzlvnzbdqyjxqwgbtllqadgxjfzrtmmvbdkczrkylnzejaipldlctxvklofqnqffkydzgtfbfergkeqmcvylzqiiuocwgdvicasicruggkbsrgyldpiwkuruyihbergcggxwujdprokxykqqbuitespohbqnkqkugwhlhkgabaphqtfdbfhgvbluyxwzopsqeukclfkfwkxqwzakbwbhilyfkyoiitlshcncyqdmjnfjekjjdzqswmjvndtmyanvucnzbduamhapynggabonfabhvnqmksnyhyydlhkfhhdkhvsusnwppwdwvayfksmbsxujuvlaigwmqsnzytvwbplyydsprlucgxoaajllvqiihbckzlpasfsnsusyfhbmcbfostwisfnreqqytkdcahmkztuaxojiftfvwwvmodljmnbjeoifeynmaxzktxxpedagsnzuvfrkigjdckuzosknadbflgiskpphygxzmcmfazjxazhbqbqrrezxlniokhfkkpdrhtcrueqxlxxdcvjlxisjxawespgxoxjygeoqzemxikvpqrfqbxyarjwojekexbqaedyuiplldvkykwpwmzheiqgdnksfymiuinmorlizmxmlhxsjotkroyphykjhrbexhafvcjetiimmpqkspsploayapwbxujwjbbihvgvkdcfpabbaymczpimztoqbidtjsdnkgudecsfsrrezfbtuxixjkipxtncfquqdtaniwlevdyodliiwuvbogqzwwpurcqvrysjzdbsucbxnlkfgcvwagoiqigsnvkwemybvxuaermvjjldzspjkpveofjvpvgvoksjyifnlgbrubyvndynhvludryljrgbkyszbxnvdbyahlztqxuibbotbfkhsgykpgcrwlmxzmhiovklijtbutfdiojsclmcjttaflmsydwunheikkskjhxadktuynceyajdkveimksqwlogdyyddksrarlpgfzznzuajfrfeunqjuawjhfmarnjuiyeuztdvrzhcezvsfkhcdgttnpfnkhsypmxbobnqylloakfknoypeoritdiqrkmjifoueibycuxnqnunbtnlnkciohefuqcyfobiiybuwprqrfokonirfilfqgjhfplyasyjmzqpdwtsbkgqcyuvtbunqnhnaefgpjnvagtpxfqrgmxtsvajtrpbdbnzqackjdtammeuasetgwfzwbysfomabhmxhlnqtbalmjfhxrogodukweyzmjfhkiiatypltuntsxajrcdzfjwfxrqwhposvxedxomrdmbqhavocmvtkggpulovcckleycfgtypcncnhtwuwrmzjpbscimpxczrpbixqvamegseypgecddfoflqtasxngkywtairategyvzxttvbfddkwxobezxfnwpzxkjcdpnlvwozndnfeguhycdoomtxbpiqlqwotoibbqzwxvgkmqwowatzozgbtrdkndcpivaildyxkknzyiyytbflwpaitvirsptzdhlfsiabomdxqhtfnvleuouktabuawprturpumhgkbuacfffoxriugzaqsenyfnmgqjmsjvobaeuqkgwpyvwpafbnxiodtcemcdqaxvlnycqyvaxxybhvdkhiuhpvumqbfrywtqkuvjjeaexycjzhrfcldugqrviylxubxwgtcptvelfadqxbcvtseznbbuaeudgejcvytastwczyjqhglyhztgddicbnlvytjhmhenxsdhvlyflhzqsoidecojqgxsqkhvfkpldtoqyrgadzgioolynwzxjruiiybwcnwaupwgmueqdfyvsvlbhqqxkceebmwqjypiygyzcdbzpkyrhrojqmqsbjilamakicreoruijzrhwwfkbvzuajrsccdhbkunzvwrhsiphmbdamnnqkhtfkyqrdrcexzftuaxfrphoipmzxczjcuoqczgprmziotdisoskroxjkleahtirtmveucayqvjbjcrndjvxvvoumpcgczwumaapdepshnaimatolvnlmepbjzwxmacwilfykkkuysuccmftjuoccupagbyakrugnnsgrvbxdwgtqzzwhbkyjdkfniepbolviwsbevypmekzmevxohkslylosuskcvehbyrruykohnencvyodstlpwdwooonhniyegmyekmtopuwykwcthhdwzqxocnqgzmtctbpuillkmawssjtrgxlspqqyczvkhhfcuglidembzunqfspcphjqtuaywqbjjsqydfojzofirjwoiobxhfdimsvisxeyyrksqalvhuql\n", "output": "2499\n"}, {"input": "4998\ntletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletletle\n", "output": "2499\n"}, {"input": "5000\nababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababcabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababdabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababaeabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababafabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababagabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababahabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababaiabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababajabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababakabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababalabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababamabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababanabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababaoabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababapabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababaqabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababarabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababasabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababatabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababauabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababavabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababawabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababaxabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababayabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababazabababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab\n", "output": "200\n"}, {"input": "5000\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaafaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaagaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaajaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaakaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaamaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaapaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaqaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaraaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaataaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaauaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaavaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaawaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaxaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaayaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "200\n"}, {"input": "4996\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwcwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\n", "output": "1665\n"}, {"input": "4996\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwawwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\n", "output": "1665\n"}, {"input": "3963\nbbbbaabaaaaabaababbaaaabbbbabaabaaaaababbbbababaaaaaaabbaabbbaaabbbaabaaaaaababbbbbabaaaaabbbabaababbabbbaaabbbabaaaabababbabbbbbabbbbbbbbbbbabbbbbabbbaaabbbbaababaabbbbbbbbbbbbbabaabbaaabaababaabaaabbabbbabbbabaabbaabaababbbbbbaaabbbbaaabaabbbabbbabbabaabbbbabbbaabaaaabbbbbabaaaabaabbabaaabbaabbabbaaabbabaaababbababababaabaaaabaabaabaaabaabbbabbbbbaababbabbbabbbbababaaabbabbaaaabbbaaabaabbbaaaaaababaababbbbbaaabbaabbabbbbbbbbaaaaababbabbabbbbbaaaabbabbbaaaaabababbbabbababbbabbaabbabbabbbaaababbabbabbabbbabbbababaaaabbaaaababababbbabaaaaaaabbaabbbbbababbbbbaabababbbaaababbbaaaaabbbaabaabababbaababbabbabbaababbbbbabbbabaaabbbabababbaaaaaaaabbaaababaabbaaaabababababaaaaababbabaabbaabababaaabbbbabbaabbaabbbaabaabaababbaaaaabaaabaabbbabbbbabababbabbbaaabaabbbaaaabbabaaaaabababbabbabbbaaaababaabbaabbbbbbaabaaaaabaabaabbababababaaabbabababaaabaabababbbbaabbbbbabbaabbababbaabaaaaaaababbabbaaabbbbbbababbaabaaabaabaabbaabababbbababbbabbbabbbababababaaabbabaabbabbaaabbaaabaabbabbbaababbbabbbbabbbbbaaaabaabbbaaabaababaaababaababbbaaaabbaabbbabbaabbaabbbbbabbbbaabaabaabbbaabbaaaabaaabbabbbbabbbbbabbbbababaaabbaaababbbaaabbbabbbbbaababbaabaaabbabbaaaaaabbabaaabbbbaabaabbbaaabaaaababbabbbbabbbbaaaaaaabababaaabababaabababaaaabbababbbbaabbbaabbabaabaabaaabbababbaababbaaabaaabbbababbabaababbabbabbabaabbbbbababbabaabbbaabaabbaabaababababbaabbbaaaaabbabaaababbbaabbbaaaabbaababbbbbababababaabbbbbabababbbbbbbbbaabaababbaaabababaaaaaabbaabbbaaabbbaaaabaaabbaaabbaabaabbbbbbbbbabaabbaaaaaabbbbabbbabbbbabbbbababaaaabaaabbaabbbaabbaababbababbaabaaabbaaaaabbabbbbabbaaaababababbbabbabbababaaabaaaabaabaaaabbaabaaababababaaababababbbbaaabababaaaabbbbbbbbbbbbabbababbbbaaabababbbbbbaaaabababbabbbaabbbabbbabbbbbbbbbbabaabaabaaabbbbabaababbaabbbababbbabbaaabaabababaaababbababaabbaaaabbabbbaabaaabaabaaaabbababbbaaabbaaaabaaabaaabbbabbbbabbaaaaababbbaabbabababaabbabbabbabbaaabbbaababaaabbabbaababaabaaabbbaababbbaaabbaaabbaabaabbababbaababbbbbaabaabababababaaaaabbbbabbabbbbabbbbabbbbabaabbbaabbabbaaaabbabaaabbbababbbaaabaaabbaaabaaabbbaabaaaabaabbaaaababbbabaabababbbbbababaabaaaabbbaababbbbbabababaabbbbbbbbbaaaaaababababbabaabbaababbabbbababbabaabbabbabbaabbbaabbbaababbaaabaabbbbabbaabbbbbababababbbbbbaaaaabbbbabbbabaabbaaababababbabbbbabbabbbabaaabaaabaabaaabaaaaaaabbaabbbbabaababababaabbabababbbbabaaaaabbabababbbaaabaabbabaaaaaabbbabaaabbbbbbaabbbbababaabababaabaabaaabbabaaaababbabbbaabbbaabababaabbbaabaabbbbbaabababaabbbbbabaaaabaababbbaaabbabbaaabbbabaaaaababbbabbbbbaabbabbaabababaababbbaaaaaaaabbababbaaababbaababbbaaaaabababbbaaaaabbbbbbbaaabaaabbaabbaabbbbbbbaaabbaaabbaabbbbabaababbabaaabaabaaababaabbabbbaabbabbababbbbbbbbabaaababbbbaaabbbaabababbaabbbbaabaaaabbbbaabbabbbbbbbbaaabaaabbbbbbabbabbaaabaabbabaabababaabbbbbbabbaaababaabbbbbbbbabaabaabbaabaababbabbbbaabababbbabbaabbaabbaabbabaababbabaababaaaabbabbabbbbabaaaaabbbbbaaaaaabaabbabaabaaabbbabbaaaababbabaaaababbbbbaabaaaaabbaaaaabababbaaabaaababbaaabaabaaabaaaabbbbbababbaaaaaaabababbababbbaaababbabbabbbaabaaaaaaabaaabbbbbaaaaaabbaaaaabbaaaababbbabababbbababbababaaabbbbaaaabbabbabbabababbbaaaabbababbbbababbabbbaaababababbbaaaabbbabbababbbbbbababbbbbaaaabaaabbbaabbbabaabbbababbbabbababbbaabbabbaaaaaaaaabaaaaaabbbbaaaabaaaaababaabbbbbbaabaababbbabaaaaaaaaaaabbababbabaababbbbabaaabbbaaababbbaaababbabaaabaaaabbbbbbababaaabaaabababbaabbbaababbaabbaaabbababbbbabbbbaabababbabbbbaaabbaaabbabaaaaababaababbbaabbaaaaaabbabbabababbbaabaabbbbaaaabbaaabbababbaaaabbabbbbaaaabaabaaabbbaabbabbabbbaabaaaaabbaaabbababaaaabbbbbbabbabaaababaaaabbbbbbababaabbaaabbbabbbabbabaaabaababaababbbbaaaaaaaababaaaaaabbabbabaababbaaaabaaaaabaabaababbbaaaaababbaababababbabbbaababaaabbbabababbbababababaaabbabbbbbbbbbbbbabaabbbabababbaaaaaaabbbaaabbbbaaabbaaaabbaababbabbbbbababbbabbbaaabaaabaabbaabbaabbabbaaaaaababbbbbbaaaabaababbabaaabbbbbbabaaaabaaabaaaababaaabbbbbbaaabaabaaabbabbbabbbabaaaabbbbbbabbaabbaaaaaaaaabababbabbbbbaabaabaaabababbaabbbbbbabbaaaaababaabbaaaabbbbaaababbabbaabaabaabaaabbabaaaaa\n", "output": "22\n"}, {"input": "4336\nbcbcbcccbbbcccbccbcbbbcbccbccbccbbcccbbcbbcbccccbbcbbcbbbccccccbbcccbcccccbcbcbccccbbcbccccbbcbbbbbcccccccbccccbcbbcbbbbcbccbbcbbbbcccbbcccbccccbbbbbbccbbbbbcbccbbbcbbbbccbbcbbcccbcbcbccbcbccccbcbcbbbbccbccccccccccbbbbcbcbcbcbcbcbcbcbbcbcccbbcccccbccccbcccccbcbccbccbccbbbbcbbbccbcbcbbbcccbcccccccbcbccbcbcbcbcbbccbbbccbccbbbbbbbcbccbbccbccccbcbbbccbcccbccccbbcbbcbcbbccbbcbbbccbbbccbcbbccbccbccbbcbbbcbccccccccccbccbbcbcccccbcbccbbcbcbbbcbcbcbbbbcbbbbcbcbcbcbccbbcbbcbcbbccbcbcbcbbbbccbcbcbcccbbbcccbcccbcbbbcccbccbbbbcccbcbbcbbbbccccbbbbcbcbcbbbccbbbcccbbbcbbbcbccbbcbccbbbbccbbccbcbbbcbbcbccbcbcbcbbcbcbccbbcbcbbcbbbcbcbccbcccbbcbccccbccbccbbbbbbccbbcbcbbccbcbcccbccbcccbccccbbbbcbcbccccbccccbcbbbbbbbccbbbcbcbbcbbccbccbbbcbbcccbbbbcbbbcbbcbbcbcbccbbbbbcbbcbbcccbcbcbcbcccbbbbccbbcbcccbcbbbccbbbbbcbbbccbcbccbcbcbbccbbbcbbbbbbcbcbbcccbcbcbbcbbbccbcbcbbcbcbccccccbbbbcccccbccccbccccbcccbbbbcbbccccbbcbbcbcbccccbccbbcbccbcbcccbbbbccbccbccbbbbbcbbcccbbbcccccbbbcccbbcbbccbcccccbcbcbbbbbbcbbbccbccbbbccbbcbbccbcccbbbcbbbbccbbbbcbcbbcbbbccbbbbbcbccbbccbcccbbbbcbcbcbcbcccbbcbbbccbcbbcccccbccbcccbbcccbcccccccccbbbccccbbbcbbbbbbbbbccbcbbbbcbbbcccccbccccbcbcbcbbccbbcbbbbbbcbbccbcbbbcbbcbcbbcccbccccccbbbcbcbbcbbbcbbcbbbccccbccccccbcbbbccccbbcbbccbcccbbbcbbcbbcbbccbbbbbcccbbccccbcbbbcbbccbcbccbcbccbbcbcbcbbcbcbcccbcbcccbbccbccbbcbbcbcbbccbcbbcbccbbbcccccbcbcbccbcbbcbbcccbbbbbbbcbbcbcccbcbcbbccccbbbcccccbbbbbbbcbcbcbbbccbbbbcbbbcbbbcbccbbcbbcbcbcbbbcbccccccccccccbccbccccccbcbbbcbbcbcbbbcbcbbbcbccbcbccbcbcbbbbbccbcbcbbcbbcbbcbbcccccbbbcbbbccccbbcbcccbcbbcccbbccbbccbccbbbcbccbbcccccbbbbcbcbcccbcccccbcbbbcbbbcbbcbcbcbcbbcbcbbbbcbcbbbbccbcbbbbbccbcbcbccccccbcccbcbbccccbbcccccbcbccbccbcbbbccbcbcbcbbcbbcccbbccbcbbcbbcbcbccbbbbcccccbbbbccbbcbcbccbcbbbbcccbcbcccbbbbbbcbcccbcbbbcbbbbbcbcbbbbbccccbcbcbbcbbbccccbbccbcbccbccbbccccbbcbbbcbcccccbcbccccccccbbcbbcbbbbbccbccbbcccccbbcbbbcbbccbcbbccbcbbbbccbbcbcbbcccbbbccbbbbbccbbccbbbbbcbccbbbbbbcbbbcbcbcbcbbccbccbcbbcccccccbbccbcbccbcccbbccbccbbcbccbccccbbbbcccccccbbcbccccbccbccbcbbcccbbccccccccbbccbbccbbcbcccbcbbbbbcbbbbbbbccbcbbbcccbbcbbcbccbccbccbcbbcbcbcbccbbbcccbccbccbbcbbbbcbbccccccbbcbccccccbbbbccbbcbcbcccbbbbbbbbbccccbccccbbccbcbbccbcccbcbccbcbbbbccccbbbbcbbccccccccccbbcbbbccbcbbbcbbbccccbcbccccbccbbcbcccccbccbbbbcbbccbbccbbbbbccbcbcbbccbccbbcbcbcbbbbcbcccbbcbbcbcbccbcccbccbbbbcbcbbccbcbcccbbbccbbccbcbcbcbcbcbbccbbbcbcbbbbbcbbbbbcbbcbcbccccbbbbcbbbbcbbcccbbcbccbbbccbbccccbcbccbccccccccccbbbccbcbbccbcbcbcbbcbcbbbcbcbbbbbcbcbbccbbccccbbccbcccccbcccccccbbbbbcbcbcbbccbccbbbccbbbcbbbcbcccbbcccbcccccccbbbbcbbcbbcbbcbcbbbcbbccccbbbccbbbbbcbbbcbcbccbbccbcbbcbccbcbcbbccbbcbccbcbbbcbccbcbbccbbcbbcbbcbcbcccbcccbbbbcbbbbccbbbbcbcbcbbcccbcccbbccccbcbbbccbbccbbbbcbbcbbbcbbbbcbbbccbcbbbbbcbcccbbbcbbbbcbbccbbbbccccbbbcccccbcbbccccbbbbbbcbccccbbccbccbbcbccbcbbbbbbcbbccbcccbbbbbbcbbccbccccbccccbbbbbbcbccbccbcbbcbccccccbccbbcccbbbbbbbbcbbbbbbbbbbbccccbbbccbbccbbbcccccbcbbbbbccbcbbccbbbbbcbbbbbcccccccbbccbbccbbcccccbcbcbbccccbcbbbcccbbccbccbccbbccbccccccbccccbcbcccbccbbcbbbccbcbccbbbcbcbcbbbccbbbbbbbbcbccccbbcbbbccbcbccbcbbbbbcbbbccbccbbcbcbcbccbcbcccbcccbbccbbccbbbcbbbbbbbccbbcccbcbcbbcbcbcbbbcbbbcccbbbbbcbcbbbbcbbbcbbcbcbbcbccbbbcbccbbccbbcbbcccbcbcbbbcccbccccbcbcbcccbbbbbcbbbcccbbbcbcbbbbbbccccbbbcbcbbccbccbccbbcccccbbcbcbbcbbbccccbcccbbcccccbbbbbbbbccbcbcbbbbcbbbcbcbbbbbccbbbbbccccccbcbcbbbbbcbcccbbcbccbbbbbcccccccbbbbcbbbccbbcbbbccbccbccbbccccbbbbcbbcbbcbcbbcbbbbcccbbcbbbbbbbccccccbbcbcbbbbbcbbccbcccccbbbbcbcbccbcbccccbbccbbccbccbcbbcccbbcbcbcbbbbcbbbcccccccbbcbccccbbcbbbbbbbbbcbbbbccbbcccbccccbbcbccccbcbbbbcccccbcbcbbbbcbcbcbbbcbbcbcbcbbbcbcbbbcccbcbccccbcbbbccbcbcccbcbbbbbbcccbbbcbbbccbbbbcbbbcbcbbcccbbcccbccbcbcbbccbbbbbccbccbcccbcbcbcbccccbcbbcbccccbbcbcccbbbbcbbbbccbbbbccccbbcbbbccbcbbbbccbbbbbcbccbbcbcbbcccbccbbcbbbccbbcbbbccbbcccbbbccbbccbbbccbcbbccbbbcbbccccbbbcccbbbccbbccbcccccbbbbccbcbcbbbbbccbbcccbbccbbccbcbbcbccccbccccbbccccbbbbbbbbbbbcccbcccccccbccbbccbbcbbbbbccbcbbbbbccccbbcccccbcccbcbcbbccccbccbbccbbcbbcccbcbcbcbccbccbbbbcbbbcccccbbcccbcbbbccbbbcbbcbccccbcbccbcbcbcbbbccbbbbbbbbccbcbbbcbccccbbcbccbcbcbcbcbcccccccbbbcbcccbbccbbbbccbccbbcbbccccbbbbbcccccbbbcccbccbbcbbcbbcbcbccccbbcbccbcbbbcccbbbbbbcbcbbcbccbbcbbbcbbbcbccbccbccbcbccccccbccccbccbcbbccbbcbccccbbbccbbbbbcbcbbcbbcbcbbbccbbbbccbcccbcbccbbbccbcccccbcbbbbbccbcccccbbbcbcbbbbbcbbbcccc\n", "output": "21\n"}, {"input": "3809\ncccddcdcdcdccddccdcdcccccccccccddccccdcccccdccdccdddccdccccccdcddddcdccdcdcddccdcdcdcccddcdcccccccccdddccddcddccccccccdddcccdddccdccccdcdcdcdccddccccdcdddccddcdcdcccddddddcdddcccdddcdcdccdccdcdccdcdcccdcddcddddccdcccddccddcddcddddcddccddccccddcddddccccddcddcdddddccdccdcddcccdcddddcddccddcdcdcdcccddddcddcdcccccddccdcccdcddddcccccddcccccdddddccdcdccdcddddddddddccccdcdccccddcdcccdccdcddcdccdcccccdcccdcccdcdcddcddcdddddddddcccccccdddddccdddcccccccccccccddcccdcccdcdcdcccddcdcdccddcddcdcccccdcddddccdccdccdcdcccddcdccddddccdcccdccccddccddcdddddddcddddcddcccdddcdcccdddddccdcddddccddcdcddcccdcdccddccdccdddddddcdccdccddddddcdccdccdcdcccdccccdccdcccddcdccccdddddccdcccccccccdccdcddcccddddcdcdddcddcccccdcdcdddddcddcddccddccdcdccdcccccdcdddddcddcdccddccddcccccdcccdcddcddcddcdddddddcdcccdcdddcccccddcdccdccccddddcddccdcddcdcccccdcccdddcccccccdddcdcdddcccddddcdcddcdccddccddccdcccddcdccddccdcddcdccddddcdcdcdddcdddcdcddddccddcccccdcddccdddccdccdcccdddccdcdcdccddcddccccdddddcdcddcdddcddcdcdccccdcdccddccdddcccddddcdcccdddccdcccccccdccddcdcddddcccddcdddccddddcddddcddddcccccddccdddcddcdcccddcccddddccddcdcccdddcdccdddddddcddcdccdccccccdddcccdccdddddddcddccddcdcddcdcddcdcdddddddddccdccdccddcddcdccdddddccccdccccdcddcccdddddccdddddcdcdcdccddcdcddddccdccdddddcccddddddddcccdcdcccdccdcccdcdcddcccccdcdcdcdcccccccdddddddddcddcdcdcddddcccddddccdddcccddddccdcccddcccdddddccdccccccddddddddddddccccdcccddcccccdccccccdcddcddddcddccccddcdccdccdcddcdcccddcddddcdccdccdcddcddcdcdcddcccdddcdcddddcdccccddcdddccddccdcccdddddcdcdccddcccdcccdccdddddcdddddddccdccccccccdcddddcccccddddddccccddcddccdddccdccdddcccccccdcccdcdcdccdcddcddcddccdccdcddddcddccccdcdcdcccddddccdcdcdcdcdcccddcddddccddddcdcdccddcddccddcdddcccddcccccdcccccdcccddcdddccdccccdddcdddddcdcdcddddccdcdcdddcdcccccddcddccccddccddddcccccddcdcddddcdcccdddccccdddccdddccdccdccccdddcddcccccccddcddddcdcdcccdddcdcddccccccdccddcdcddccccccdccccdcddccdcddcdccdcdcccccddccdcddcdddddddcddddccddcddcdcccccddddddcdcccddcdcdcccccccdcdccdddddddcdcddcdccdddcccdccddccccccdddcddcdcddccddcddccddcddcdcccccddcccddcddcddcdcdcccdddccddcccccddcddcccddcdddcddcdddcccddccccccddddddcccdccddcddccddcddcdcdccdcddcddcddccddddccddccddddcdcdcdddddccddcdcddddcddcdcdcdcdcdddccccddddddccdcccccddcccdddcccddccddcccdccddcdddcddcdcddcdccccdccdcdcccddcddcdddccdddddddccddddcddccdddcdcdddcccdddcddcdcccdccccddddcccccdcddcddddcccccddddcdccdddcddccddddddddccdcccdcddcdddcdccdcddddcdccdddcdddcdccdddccdddcdcddccdcccdddddcdddccddddcddcdccccdddcdcdcdcddcddccccdccdccccdddcdddcccddccdcdccccddccddcdddcdcdddcccdcdddcccdcccccccccdcdccddcdccccdddccdcdccccdddccccccdcdddcccccdcccdcccddcccdddddddccccccdccdcdcddcdddddddccdcddccccccdcdcccdddccddccccdcccdcdccddcdcdcddddcddcdcccdcdcccccdcdddccddcccccccccdcdccdddccccddddcddccdccccdddddcccddcccdddddcdcccdcddddddcccdccdcddddccdcccccdcccddccdddcddddcdddddcdcdccdcdcdddddccddcdddcddccddddcdcccccdcddccdcddddcdccdddcdcdcdcdccdccdcccddcdddddcdddddcccdccdddcdccdddddccdcddcdddcdcdcddccdcdccccdcccdddcdcccdcdddcdcccddcddddcdddccdcccccdccdccdddddddcdddcdcdcddddcdcddcdddccdcccccdcccdcddddddcdcdcddccddcdddccdcdcccdccdddccccdccdcccdcdcddccccddddddcccddddcdcddccdcdccdccccddcddcdccdddcdddccdddddccdcdcdccdcccccccdddcdcccdddccccddccdccdcdcddcddcdcccdcdccccdcccddccdccdcddcdcddcddcddccdddcdddcccdccccccddcdddcdccccddddcddcddddcdddcdddcddddcdccddccdcdddccdcddcdcdcccddcdcccccdcddcddcdccdcdccdccdcccddcdcdddcddccddccdddccdcddcccddcddcdddcdddcddcdcddddccccccddddccdccdcccdcccdcccdcdddccddddcccdccddcdccdcdcdcdddcccdcccccddcddcdddccddcddcccccdcddcdcccdddcdddcdcdccdddddcddcdddcdcccdcccccdcddddcdccddcdddccdcddddccdcdcdcdcdccccddccccdccdcccdccdccddcdddccddcdcddccddccccccdcdccddddccddcdccdccccddcccdcdcccdddddccddcdcddcdddccddcccddddcdcdccdcdddddcdcdccdcccdcccdcdccddddcccdcddddcdccddccccccdddcdddcdcdcdcdcdccddcdddddcccdcdcdddccdcdcdddcccdcdccddccccddcddccddcdcdccddccccdcdccdddddcd\n", "output": "20\n"}, {"input": "4640\nedddeeeddedeeddddddeeeedeeeeeedeeddededeeeddddddeedeededdddddeeeddddddeddedddededeedeededddeeeedddeededddddeedddedddddededdededdeddeddeeedeeededdeddddeddedddeeedeeededdeddeeeedddeedddededddeeeeddeeeededdddeeededeeddeeddedddedededdeedddddeddedeeeddededdddddeddedededeeddddededdddedddddeddddddedeededddededddeeededddedddeeeddeeddeddedeedddddedddeedededededeeddeedeeedddedeeedeedddedddedddededddeeddddededeedeededdeddeeedeeedeeeddedeededddeddeeddeddeddddddddeeeddeeeedeeddeddddeedeeeeddeddddeeeeeeeeeedddededdeddeedddeeddededededeeededddedddedeeeeeedeeddeeededdeddeedddedeedededddddeeeededeeeeeddeedddddedeeeededeeededdeeededeeddddeeedeededeeeeeedeeedddddedddeeddeeedddeddeddddeeedddeeddeeeeeeeeeedeedeededdddddddeddddedededdeededdedddddededdeeeeeedeedeeeededdedeedeedddeeeeedddeeeedddededdeeeededeeedeededeedeedeeedddedddeeeeddedddddeeddeeedeeeeedeeeddddeedddedeeddeeeeeeeeeededddeedddeddedeeeedddedeeddededddddddeeddeededdddddddeededdeeeddeddedeeddddededdddeddeededeededddeeedddeddededeeeedededddeeeddedeeeeddeedeeddedddddedddeeeeeededdeededeeeddeedddddeddddedddeddddeeeddeddedeeeddeedeeeeddeeddededdeeededddeeeedeeedeeeddedeedddeeededdddeedddeddeeddddddeedddeddeeeedeeeeeeddededeedeeedddddeddddedeedeeedddddeedeeeeeddeedeeeddeeedeededeeddeddeeedddeedeeddeededddeddeeeddddeddedddedeeeeeededddeddddeddedeeddeedeeddeeeddeeedeedddeddededdeeeddeededdeeedddddedddedeeeedddedeedeedeedededdeddedeeddddddeeeeeeddedeeeeeeddedeedeeddedeeddeeeddeedddddedddddeedeeedeededeeedddeeeeedddeeeddddeededeeeeeedddeedeedddeedddeeddddddddeeddedeededdeeeedeeedededdeddededddeeeddededeedeedeeddededddededededddedddeeddedeeddeeeeeedededdeeededdeddeddedeeedeeddedeeedddeddeedeeeeeeeedeeddeededdeeededededddedeeeeeededddedddeddedddeddeeeededdddedddeddeededeedddedeeeddedeeeddeeedededddedeeeddeeededddeeededdeedddedddddedddedddeddddedeeeeeeedeededdeeedededeeeeedddddddeeeeeeeeddededdedeeeeeeddddddeedeeedeeedededededddddeedddedeedeeeedddeeeddeddeddedddeddeeeddddddeeddddeeeeeeddeededdeeedeedddededeeededdeeeeedeeeeeededeeeddeedeedeeededddeedededeedeeddeedeeeeeddeeeddddeeddeddeddddeeeeeeddeeddddedeeedeededddddedeeddeedeeddeeedeeeeeeddeeeedeeeddddeeeeeeeeeeededeededddeeededddedeeededdddeeddeedeeeddedddddddeddedddddeeeedddeddeeddeddeedeedddedeeedddededdddedddeeeeeeededdeeeeddddeeeedeeddddededdddddddeededeeedeededddeddddddeddeddeeddddeeddeeedeedddeedeeeeeddeeedeedddddeedddedddeededddeedeedededddddddedeeeededeedddddeddddeeddeddededddedededddeeededeeeeeeeeeeeddedededededeeeddedeeeedddddddddeedddedddedeeeededeedddddddeddedddeeddddededeededeeeeedededdeedeedddddeeeeeeedddeeddeddddddeeeeedddedeeedeededddddeedeeddddedeeedddddddddeeededeedeedeedeedeedeeddddedeedeeeedeeeedededeeedeeddededdeeedeedddededdedeeededdedddeddedeeddedeeeeddedeeeeeedeededeedeedddedeeedeeddeeddeddedeeeedeeddeddeeedddeededdddeeeddeeeedeedddddeeddeeddeedddeeeeddddededdddeeddddddedeeeeededdddeeddeddedddedeeeeedeedddedededeeeeeedeeddeedddededdedddeeddddeedeeeeddddedeeeddedddddeedeeededdeeeeedeeedddeeeeddeedeeeeddddeeddeeddddedeeddeeeeedddeeeedddddddeddedeeededdddededdededdededededdeeeeddeedeeddddededddddeeededdddddeddeeeddeeeddeeedededeeedeeedeeeeededddeeedeeeddedededddeeeedeeedeedeeedddddeddeddddeeeddeeddeeedeeedeeedeededeedededdeeeedeedeeeeeeedeeeeeeedeeeeeddedddeddedeededdeeededeeeeeeedeedededeeeeedddeddeeededdedeeeeeedeeeeddedddeeeeededddddddededdeddeededdeedddddeddedeeeeedeeedddddeeddddddeeeedeeddeeededeededeedddddededddddeddddeddeeeeddeeddddddedededeeeeeeeeddddeeeededddeeddeededddedddeddddeeeedeeededdededeeeededeeeeeeeeeeddeedeeddddeeddedeeedddddedeeeeeddedeeeedddddeedeeddeddeeeededeeeeeedeeeedeeddeddddedddeeeddeedeeeddeededdeeedddeddeeeeddeedeedddedeeeedddeeededeeeddeeeddeeddeeededeeddedeeededededdddedeeeddddedddedeeeeeeddddedddeeddedeeddeedddeeeddeeedddddeeeededdeeeeedeeededddeddeeedddddeeeddeddedeedeeddddeededeedddeeeeddeeeeeeeedddeedeeeeedeededeeededeeeeeeedeedeedddeeeeeeedededeeededeeddeeeedededdddeedeeddddeeeeddedededdddedddedeeeeddeeedeeeeeedeeeddeeddeeddeeeddededeeeedeeeddddeeeddedeeeededdddeddddedeeeddeededeeededdededeedededdddddededeeedeeeededddeedeeeddedddededededdddddeeedededdddeeedddeeeeeddedededddeedeedeeeedddededeedeedeeeedddeeeeedeedddeddeeeedededddedddddddedddedddeeddeeeedddeeeedeeddddedeeeededdeeedddeddeddeeedeeeddededdddeddedeeddddedeedddededdedededddedeeeeeddedeeeeedeeeddddeddeeeeeedeeddeedeeddeeeedddeedeeedeedeedddeeeedeeeeededddededdeeeddedeeddededeeeddeddeddeeedeeeeeeeeeddddeddeedededededddedeeddddeeedddeededddeeeeeeeeedeedeeddededeeeeeddddddddddeeddeddeedededeeeddddeeedeeededddeeddeddeeeedeeeeddddeddeeddeeeddeddeddeeeddeeeedddeeeddededeededddddeedddeeeededeeeeeeddedeedeeeeededeeddddeedeeedeeeddeeedddddeedddddddeeddedddddddeddedded\n", "output": "22\n"}, {"input": "4639\nefeeeeffefeefffefeefeeeefffefeefeefefeeeeeeefefffeffeffefffefeefeeffffeefefffefeeeeefeefffffeeeeeeeeffffffeefffffefefeeeefefffeeffeeffeffffeefffefefeffeeeeeefeeeeefeeffffefffeffefeffffffeffeeffefffeeefeefeeffeeeefffeefffeefeeefffffeeeeefeeffffeeeefeffefeffeeeeffefffffffffeffefeeefeeeefeeeefeeffefeefffffeeeeeffffeeeeffefffefeffeeeeffeffffffeeefeeffeffeeeeeeefefeffeffefeffeefffffefeeefeefeffffefeffeeeffffffefeeffffeeeffffeeffffeeffffeeffefeffeeeeeefeefefeefeefeefefefffeffeffffffefffeeffeefffeeefeffeeefeeeeefefeeefeffeefefefffeeefeefeffeffffeeffeeeffefefffffffffffffeeefeefffeeefefeeefffeffefeeeefefefefeeffefeffeffeefeeefeffeeeffefffeffefefefefeeefeeeeffeefffffefeeeffeeeeeeeefffefeffeeefefffffeffffeeeeeeefffeffefeeefefeffffefeefeefffeefffeefefffeeefefeeffefeffeffeefefeeeefffeefeeffeeeeeffeeefeeeefffffeeffffeffeefffeeeffeeeeeffeeeefffeeefeefefeeeeefeffeffeffffffeeefeffffeeefeeeeeeffefeefeefefeefefeeeeeeeeefeeffeffeefeeeeefeeffefefffffffefeefefefefefffeeefffefffeeeefefeffeffefffefeefffeeeeeffffffefefffeeeeffffeeffffeefeeeefeeefeefeffeeeeeeeeefeeffeeffeefffeefeefeffeefefeeefffffffefffeeeffffefffffffeeeeeeeeeffffffffeeeefeffeeeffefeeffffeffefefefffeeeeffefeeffefefffffeeefeffffffeefeeeeffffefeeffeeeefefeeeeeeffefeefeeeefeffeefffeffeeeefeffeffffefffefeeeeeefeeeeeeeffefeffeefffeeeeffffffeeeeeefeffeeffeffeeeffeefeffefefffeefefeeefeffefeefeefefffeffffeeeffeefefeefffefffeeefffefefffefeeffeefeefeeffefefefefeeffeeffefffeffffeefefffefffffffffeeffeeeeeffffefeffeeeffffefefeeffefeffeeeefffffeefeffefffeffeeeefefffeefffffeefeeffefefeffefeefffeeffffeffffeeefffefffeffeeeeeeefeefffeeeefffeeeffffeeeeeeeefeeffffffeffffeeeeffefeefefeffeefeffeeffefeeffeeeeeefeefefffefeefefffefeefeeefefffeefeeeeefffffeeefefeefeeeffefefefefeefffeffeeeefeeffeefeefeffefeeeffeefefeeefeffefeeeffeeffeefeefefffffeeeffeeefffffffefefeeffefefeeeeeefffefffeefefffffefffeffeffeffeeffeeeefeefeeeeffeefeefeefefeeefefeeeffffffefeefeeefefeeeefeffefeeffeffeeffefeeeeefffefefefefeefeeefffeeffeeffffffeeffeefeefefeefefffeeffefeeffeeefefeeefeeeeeeeefeeeeeeeefeeeffeffeefffefeeeefeeffefffefefeffffeeefefeeefffffeffeeffeffeffeefffeeefeeeefefffeffffeeeeefffffeeffeeeefeffeffffeeeeffeeffeeeeffffffefefeffeffeefeefeefeffffefefefefefeeffefefeeffeffeeffefeeefffefffefefeffeffffefeefffeffefffefeeeffeefeffefeefefeffeeeeffefeefefeffffefeefffffffeeeeffffefefefeffeeefefeefeeeffefffefefefefeefefeeeefffefeeffffefefeeffeeeffeeefefefffefeffeefeffeeeefeeffeeffeffefeffffefeffeefffffefffeeefefeefefffeeffeeffefffffeefffffeeffffffeefefffeffeeeeffefeffefefeeefefffffefffeefffeefeeeefffefffeffffefeeeeeeffffffefeefefeffeeeeeffffefeeffefeeeeffeeeeefeeeffffeffffeffefffeffefffeeeffffeffeeefffffeeeeefefeeeeeefeeeeeefeeeeefffefffeeeeefffefeeeeeeffeeffeeeffeffffffeffeffeefeeeeeeefeeeffeeefeeeeefeefeeeefeffefeeffeefeffeeefffeefeefeefeeefefffeffefeeefffffefeffefefefeeffffffefeeefeeeeefefeeffefeffefffeeefeefeffeeefeeefffeefefeefefefeefffffefeeeffffffeeefffeeffefeefefffeeefffffeeefeffefffeefffefeffefeffeeeeefefeeeffeeefefeffefffeffeeefefeffeefeeefffeeeeefeffeeeeeeefefffeffefeeeffefeefeffefeeefefffeeefeefeeffefffeffeffffffeefefefeffeffeeffefeeeeeeefeeeffffffeefffefeffefeeffefffeeeeefffffeffffefffeefeefeeefeefeeffeefeeeeeffefeeefeeefffeffeeffefeefeeeffeefefffffffefeeeffffeefeeffefeffeeeeefeffeefeefffeffffeefeeeefeffeefefeeeeffeeeefefefffeeeffeffeffffeffeeffeffeffeeffeeffeffffeeffeeffeffeffeffeefeffeefefeefefeefeffefeefffeeeeffeefeeffeeffefeeffffeeefefeffeefeffefefeffeeffefffefeffffeeeffefffeefeffeefefefeefeffeefefefefeeeefeffefeeeffeeffeeeffeefffeeffffeeffefeeefeefeeeeffefffffffeefeeeffffeeeeeeefeffffefeffeeeefefeffeeeefeeeefeffefeefefffefffffefefeefefffffffeefffffffffeeffefefeffeeeffffeffeffffffeefffeeeffffffeffeffffefeffeffeefefefffffeeeeffeeeffeefeeeeffeeeefffffeeefeeefefffefeeffeeefffefeefeffffeefffffeeefffffeffeeffffeeeffefeeffeffeeefefeffffefeffffefeffeffffeeeefffeffefefffffefeeeeeefffefefffefefefefeffeefefffefeeffefeefffffeefefeffffeffeeeffffefeefffffffeefeefffefffeffefeeffeeeffefefefeefeefeefeefffefeeeeeeeefffeefeffffffeeefeffffeffefefeeefeeeeefeeffeefffeeeeeffffeeffffeeefeffeefffefeeefffeeefefffeefffefeffeeeeeffefffefeeeefefeefffeeeeffeffefefeefefeeffffffffeefffeeefefffeefffefffefeffefeeeefeeefefefeefeffeeefeefefefefeeeeeefefffefffeeffefefffeefeffffeeefffeeefeeefeeeeeeffffeefefeffffefeffffefefefffeffefefffffefeffeeeeeefeefeeeefeeffffefeefffeeeeeeffeeeeeffeeeffeeeefefeeefeeeefeffeeefeeefeffefefeeefefefefeeefefeefeefeeeefeefefeeffffeeeefeeeeeeffefefffeeffeeefeefefeffffeeeffefeffeeffffefeeefefffffffeeefeeffeeefeffefeeffffeffffffffeeeeffeffefeeeeeffeeffefeffefffefefffeeeffeefeeeeeefffeffffffefefffeeeefefeffeefefeeefeeeefffeeefffefefeffffeffffeffefefeeeeeffeef\n", "output": "21\n"}, {"input": "4330\nfgggffggfgffffgfgfffgfffgfffgffffgfffffgffggfgffgggffgffggffggffgggfggffffggffgfgggfffggfgfffggffgfgggfffffgfffffggggfggggffggfggfffggffggffgfffffffggfffggggffgfggffffgggfggfffgffggfgggggfgffffffggffgfggggfggfggffggfgfgfffggggfffgffgfggfgfgffgffffgfggfggffffgfgffgggfgfffggggfggffgfggfgggfgggggggfggggfggfffffffggggfffgfgfggfggffggffffgfgfffggffgggggfggfffggfgfgfffgffgfgggggffggggfffggfgffgfgfffgfggggffgffgggffggfffggggggggffgggggfgfggfgffgffffgffgggfgfggfgggfgfgfgffffffffffggfgfgggggggfgfgfgfggfffgggfgfgfffffffgfgfggffggfggfggfggfgfffgffggfggffgggffgggfgfgffffggffgfgfggfgfffgfffgfgfgggffffffgfgggfgfffggfgffgggffffgggggfffggfggffgffffgggfgffgggfgffffffgfggfggggffgfffffffgfgfgffggfgggffggfgfggggggffggfgggfgggffgfffffffgfgffgggfgfgfgfffggfggfgfggfffgffgfgfgffgffffffgggffgffgfgfgfffgfffgfgfggggfffgggffgggffffgfgggfggfgggggfgggffgfffgggggggfggfgffffgfggffgfggffggffgggfgggfffgffgffggfgfgggfgfgggfggfffgffgggfgfgggffgfgfffffffgfggffffffggfffgfgfffggfggfggfffgfgffgfgffgggggfffgffgffggggfggfggffgffgggffggfggffggffffgfgffgggfgffffffgffgffffgggfgfffffggffffffgfgggfffgffgggffggggffffgggggfgfgggfggggfffggffgfffgffgffgggffffgggffgfggggggfggffffffgfgfgffffgggfgfggffgggffffgggggfggffgfgfgfgffgfgfggggggfgffffggffgggffffgfffffggggfffggffffgffgffggfggffffgffgggffgffgggfgggffggfggffggfgfgffgfgfggfgggffgggffggfgfggggggfffgfggffffgffgfggffggffgggfgggfgfgfggffggfgffffggggggggggggggggfgfggfgfggfffgfggfggfggfgggffggggfgffffggfffgfffggfggffffgfggggffffgffgggfffgffggggfgfgfffgggggffgffgggggggffggfgggffffgffgggggfgffgfgffffgfgfgffffgffgfggggffgffgggffgfgffffgfffgffffgggffgggffffffggggffgfgfgfgffggfggffgfffffggfffgffgfgfffgffgffgffffgfgfgffgfffffffgffggffgfgfgffgffggfggffggfggffgggggffffggffgggfgggggffgfggggffgggggfffgfgfggggggfggggfgffgffgggggfgffgfggfgfggggfggfgfggffgggfgfgfgffgfffgffgfgfgggfffgffgggffggggfffffgfggfgfgfffggfgggggffgfgggfggggfffgggggggfgfffggfgfgggggggfggggfggffggfgfgfgffggggfffffgfggfgffgggfffgfggggfgfggfgfggfgfgffffgffffgfgfggfgggffgfggggfffgffggfgfgfgffgfffgffggfgfggggggffgfffgfgffggfffgfffgfffgfggfgfggggggfgggfgffffffggfggfgggggggfffgggfggfffgfgfffffgffgfgfggfgfggffgfgffggfgfffffffffffggfffffgfgggfggfgggfgggggfggggfffffffggggfggfffgfgffggggffgfgfgfffgffffgffgfggfgggffgffgggfgfgggfggggfgfgfffffffggffgggffgfffffgfffgggggfgfffgggfggfgfgffgffgfgfgffgffgfgggggfggggggfffgfggfffggggffgfgfgfgggfgfggfffffffgggfffgfggfggggfggfggfgffggggfgfgfggfffggggfgfgggfgffffffgffffffggffgffggggffggffgfffggfgfffffgfggfffgffgfgfggfgffggggfffffgfffffffgfggggffgggfgfgffgggfffffffgffgggffgfggfgffgggggfffffggggffggffgfggfgggffggffgffggfffgggfggfffgggffggfgggfffffgfggfgfgffgfgggffgggfggffgfgfggggfgfffgfggfgggffggggffgfffgggfggfffgfggfgggfffffffgfffggfffggggffffgffgfffgffffffggffffggfgfgffffggffffffffggffgggfffggfggffffffggffffffffffgffgggfgfgggfffgfffgggffggggggffgfgfgffgfffgfgfggfggffgfggffggggfffgfgfffgfffffgffgfgfffffffffgggfggfffggfgfgffffffgfggfgfggggggfffffffgfffggggfgffggfffgfgggggfggfgfgffgfffgfgfgffffffffgffffgfggfgfgffffgffggfgggfggfgggggffggfgffgggfffgffffffggffgfgggggffgfgfffffggfggfggffffggfgfgffgfgggfgfgggfggffffgfgffgfgfggfffgfggfgfgfffffffffgggfffgfffgffgggffffgffgfgffggffgfgfgffggfgggfgfgggggggfgffggfgfgffgggfggggfgfgfgggffffffgfgfgffffggfffgfggfggffgfffffgffgfggfggfgfggggffgfffffggffgggffgfffffffgggfgfgfffgfggfggfffffgfgfgfggfgfffffgffgffffffffggggfggffgfgfffffgggfgfggggggfggggffgffggfggffggffffggfffgfgfffgffgggggggggggffggfggfffggfgfgfgfggffggffggfggggfggfffgfgggfggfffgggggffggfgfgfgggfggffffgggffgggffgggffgggfgfgfgfffffggffffgfgfffffggfffffgffffgfggfgggfgfgffffffffggfffggfggffggggggggggffgggggggfggfgggggfffgggfggfgggggffggfggggfffgfggfgffgfgggggggfggffgffgffggffgfffffgffffggfgggggffgfggfgggffffggfgggggffffffgggfggfgggfggggggfffgfgggggfgfffggfffgfgfgfffgggggffgggfgfgggfgfffffgfggfgffggffgfgggggffgfgfgggfffgfggggffffgggffggfgfgffgffgfggffgggfffggggggffgfgffffggfggffgffgfffgffgfggffggggffgggfgfffgfgfffgffgfggffgffffggffgfgfgfgfggggfggffgffffgggfggffffffggggfgfgfgffffggffggggfgfgfgfgggfggfgffgggffffggfffffffgfgggffgggggffffgffgfggfffgggfggfgfffgffggfgffggggfgffggfffggfffgfgffffffgfgfgggfgffffggfggffggggfgggfggfggfffgfggfggfffggggfggffgfgfgffggffggggggfgffffgffgffggfgggfggffffggfgffggfgfgffggfgggffggfgfgffggfggggfgfgfgfgfgffggggfgfffgffgfgfffgfggggfgfgffgggffgggfgfgffggggfgggfgfffggfggffgfgffgffgffgggfgggffffffffgggfgfgffffgffgfggfgfgffffgffgffggggfffggffgggffggfggfggfffggf\n", "output": "25\n"}, {"input": "3375\nhhggggghhhhhgghhhhhghgggggghggggghgghhggghhggghhhhhgggghhggggghhghghghhhhhhhgggghhhgghgggghhhggghhhgghhghhhghhghhhhhghghhghghggghhhhhghhgghghghhhhhghhhhgghhhhhghghgggggghhgghgghhghhgghghghghhghhhhhggggghggggghggggghhhhgggggghghgghhhhhhggghhhggghhghghhghhhhhhghghghhhghhhhgghhghghghgggghhghhhhgghhghghgghggghgghggggghggghhggghggghghhhgghhgggghhghhhhhghgghhhhghghhggghggghggghhhghhhgggghhhhghggghggghhggggghhghhhhhhhhggghgghhghhhhhgghhhhghhgghgghghgghghgghhgghggghghgghgghghggghghhghghhhhghhhhgghhghghhhhhghghhghghghgghhhghgghhhhhgggghhhhghghghgghhhghhhhhhhhhhhhghghghgghhhggghhhgghhhgghgghghggghhhgghhgggghhggghhghhghhhhghgghhgggghhghghhgghggggghgggghhghghhgghggggggggghhggghhhhghhhhghhggggggghhhhghhgghhhggghhghhghgghhhgghhhghgghhhhhhgghhhhgggghgghhhhhghghhhhgghhggghggghhgggghghhgghghhhgghhhhghghghggghhgggghhhhgghghhhhhhhhgghhhhgggghhgghhhghggghhghghggghhhghghhghgghggghhghhghgghghghhhgggggghghggghhhhgghhhhghghhgggghghhghgghghhhgghghhhhhghghghhgghhhhghhhgghghggggghghhhgghhhhghghhgghhghhhgghgghhhghghhgghggghhghghhgghgggghghhhhghhggghhhhhhggghgghhhghggggghhgggghhghhgghhgghhhhhghhhhhhgghhghhhhhghghghghghhggggggghghgghggghhhhhgghghhhghgghgghhhghghhhhggggghhghghghhgghghgghhgggggggghhhhhghghhhghghhhhhgghhgghhghgghghggghhgghghghhghghhghhhhghhhgggghghhghhhghhhhghhgghggghghghhghghhhggghhhgggghhggghhghgggghhhghghhhghhhhhhhghhgggghhhhgghggghhgghhhhgggghgggghhhhghhhggghhhgggggghggghgghghhhghggghghgghgggghhghhhghhgghghhhhghhgghhgghhhhhggghggghhghhghhgggghghgggghgghggghhhhhhghhghgghghhhhhghghhhggghgghghghgggghghhgghhhgghhgggggghggghhggghhhghhghghggghhggghghhhhhgghhgghhhhggghhhhgggghhhgghhggghghhghghghghhgghghggghgghgghghhgghhhghgghghhggghghhghhhhgghhghghhhghghhghghghhgghhhgghghhghggggghhhhhggggggggghhhhgghhhgghhghghggghghghhgggghghghhhgghgghhghhgghggggggghggghggghghgggghghhggghgghhhhhhgghhghggghgghhhhghhghghhhggggghhghhgghhgghhgghggghggghhhhhgghgggggghghhhhhghhhghhhghghghhhhhghggghhgghhhhhgggghhghhhhhghhgghhhgghgggghghgghggghhhhhhhhggghghghhhghhghhgghhghghhhgghghgghhhhggghhhggghhgghghgghhhhhggghhghghghghhgghghghhghghghhgggggghghhhghhhhhggghgghghhgghghhhhghhhhgghhghghhggggghghghghghhghgghggghhghhggghggghhggghhgghghhghggghgggghgghhhghgghgghhhghghghhghhhggghhhhgghhhhgghhhghghhghggggggghhhhghghhhgghhggghhghgghgghhhghhhghggghhggghghhgghhhghgghhhghhgghghhhghgghggghgghhghhggghhghhhhghgghgghggggghgghhhhhhghhgggggggghggggghgggggggghghhhhghhghggghgggghghghhghgghhgghhgghghhhghhghhghhgghgghhhgghghhhhgghghgghhgggghggggggghghghhghgggghghhgggghgghghhhhhgghhghgghghhggghghhghhghgghhggghhhhgghhhhhgggggghhggghhghhggghgghhghhhghhhhhgghhghgggggghgghggghhghgghghhgggggghgghhhghhhhghgghhhhhhghghhgghgghhgghhgghhhhhggggghhghhgghhghgghghghhhghgghggghghghgggghgghhggghghgghghhhhhhgggggghghghhhghhghhhgghghghgghhhghhggghggggggggghhhgghghhhhhhghgghgghgghghgghhhhhhgggghghhhhgggghgggggghhhghghghgghhghghhhhghgghhhhhgggggggggghghghggggggghgghhgghghhghhhhggghhghgggghghhghgghgghggghhhgghhhghgghhhhhghggghhhhghhghhhhghhggggghhhhhhhhghhhghghhggghhhhgggggghghhhgggghghhhgghhggghhghhghhgghggggggghhhgghgghghhhghgghhhghhhhhgghgghhhhgghhhhhhghhggghhhgghggggghghghghgghghgghhhhhhhhhhgghhhgghgghghhghhghgghgghggghghggghhhgghgghhhghghgghghghhhgghhggghhggggggghgghghhghghghhhhghhgghhhgghghhhghhghhhhhghhhgghgghhhghhhhghhhghghgghhghhgggggghgghghghhhghgghhhhhhhhhghghhhhhggggghgggghhhghgghhhghhhghhgghghhghggghggghhghgghhhghghhhhhggghhhghghhhgghhhhgghgggghhhghgghhggghhhggggghghhhgggghghgghhggghgg\n", "output": "21\n"}, {"input": "3700\niiiihihiihhihihhhhihiihhiihihiihihihihhihihiihhihihhhhhiihiiiihhhhhiihhiiiiihiiihiiiiiiihhiiihihihihiihihihiihhiiihhihhihihiiihhiihhhihiihhhiiiiiiihihhihhiiiiihhiihhihihhihihhiiihihiiiiihiihhhhiihihhiiihiiihihhiihhihihhhihiiihihhhiihhhhiihihiihihiihihhihiihhiihiihhiihihhiihhiiihhihihihhhhiihihihihiiiihhhiiiiihhiihihiiiihhiihhhhihiihiihiihhihihihihhhiiiihiihhihiihihhiihihihihhhhhiihihihihihhiihhhiiihhhhhhihhhiihiihiiihihhiihhiihiiiiiiihhihhhihihhhhhihhhhiiihhhhiihhiihhiiiihhhihiihihihiihhhhhiiihihihihihhihhihihiihiiiiihiihiiiihhhihiiiihhiihhhihihihhiiihhhihhhhiihiihhiiihhiiiihiiihihiiihihhiihhihihhhhiihhihhhiihhhihhhhhiiiiiiihiiiihhihiihihiihihhhiihihiiiiiihihhhhhiihhiihiihiihihhihhihihhhiihhhihiiihhiiiiihihhihhiiihiihhihiiihihhhihiihihiihhihhiiihiihihhiihiihihhiihhhhihhihhhhiiiihihiiihhhhiiihihihhihhihhhiihihihihihhiihhhhhiiiiihhhhhihihihihhhiihhhiihhhihihhhihhhhhhihihihhhhiihiiiihiihiihihhiiihhhiihhhhhhhiihhhiihihiihiihihiihihihhhhhihhhhiihihiiihhhhiiihhhhhihhiiiiihhihihihihhhiiiiiihhiihihhhhiiiiihiihiihiihhhihiiihiihiihihhhihihihhihihihihhhhihiiihiihhihiihhihihhiiiihhiiiiihiihiihhhhiiihhhhiiiihihihhiiiihihhhhiiihihhiiiiiihhiihihhhhhihiiiihhhhiiihihhhhihhhihhhhihhhhhhiiihihhhihhhhihihiiihihihiihhhhhihihiihihiihihihhihihiihihhiihhhiihiihhhiiihhhihihiiiiiiiiiiihhhhiiihhhiihhhihiihiihhiihihhhhhhhihhihhihhhhhhhhhhiihhiiihhhhiihihhhhhhiihhhiihhiihhhihiihhhhihhhihihihihhiihhihhhhihiiiiiihihhiiiiiiiihhiiiiiihiiiihihiihhhiiiihiiihhihiiiihiihhhhiihiiiihiihiihihhihiiiiiihhhiiihihhihhhhhhihhhiihihihiiiiiihhihiihiihiihihhihihiiiiihhihihiiihihhhhiihhhhiiiihhhhhiiihhiihhhhiiihihihiiihihhihhhhiiiihihiihhhihhhhihhiiihihhihihiihiiihihihihhiiiiiiihhihhihhhiihihhhiiihiiihhhhiiihhiihhhiihihiiiihhhiihhiihiiihhhiiiihihiihiihhiihihihhhhiihiihhhihhhiiihiihiihhihhhhihiiihhihhhiiihhiiihiiihihhhhiiiihhhiihhiiihihhhihhhihihhihhhhiiihhiihhhhhihiiihhhhhihhhhiihhiiiihihihhiiiiihiihiihhihhihhiihhiihiiihhiiihiiihhhhhiiiihiihhiiiihhiihiiiiihiihhihihihhhihihihiihhiihhhhihhihhihihiiiihiiihihhiiiihihhihihhhihhihihihhihhiiiihhiihhiihihhhihhiiihiiihihhihhhhihihhiihhhhihiiihhihiihihhiihhiiiihhiiihiihihiihhiihhhhiiihhhhihiihiiiiiiiiihhiiiiihhhiiihihhhhhhihhihhiihhhhhihiiihiihhhihhihihhhihhhhihhihhhihiiihhhhhhhiihhhhihiihhihhhihiiiihiihihihhihiihihihhhihhhiihiihiihhhihhiiihiihhiiiiiihhhihihiihiiiihhihiiiiiiihiihiihhiihihhhihhhhhiihhhhiihihiiihhhiihhhiiiiihhhhhhhiihhihihihihhhhhhihiihihhihhiihhiiihihiihiihihhiihiihihiiiihiiihhihihhhhhhiiiihihiiiihihiiihiihhihhiiihihhihhiihhhhhiiiihihihhihihiiiiiihhhihihhhiihihhhhiihhhhihiihhihihhhhhhhhhiiiihhhiiiiiiiihiihhihiihiiihhihhhhihhihihhhhhiiihiiiiihihhhiiiihihhhihhihihhihhhhihhhiihhiihhihhiihhihihihiiihhiiihihihiiihiiihihihihihhhiiihihhhhiiiihhihhhhihihiiiiiiihiiihhhihhihiihhiiiihiihihiiihhhhhhhhhhiihihihhhhihhhihihhhhhiihhhhhiiihiihiiihhhhiihiiihiihhihihhiiiiiiiihhihihhhhihhihihiihhihiihhiiiihhhhihiihhihihhhhhhhiiihiihhihhhhhhiiiiihihiiihhhihhiihiihiiihhhihhiiihiiiihihhiiihiihhihiiiiiiihihihihhhhiihhiiiihiihhhhiiiihihhihhhhihiihhhiiihhhiihiiihhhiiihiihhhhhihhiiihhiihhihhiihihhhihhihihhihhiihhhhiiiihiihihihiihiihihihihihhhihhiihhhhihhhihihhihhhhihhhhiiiihiiihiihiiihhhihhhhiiihiihhiiiihihihhhhiiiihiihiiihiiiiiihhihihhhhiihiiiihiiihihiiiihihhhhiihhhihiiiihhihiiiiiihiihiihhhhiihihhhiihhiiihhhiihhhihhiihhihhiihhiihhhiiihhhiihhhhiihhhhhiihihhihhiiiiihihhihiihhiiiiihihhihiihhihhihiiiiiihhhhihhhhhhhhiiihiiihiiiiihhihihhiiiihihhhhiihhhhihiiiiihhiiiiiiiiiiihhhiiiiihiihiiihiihhiihhhhhiihihhihhiihhihhiihhihhiiihihihiiihiihhihiihihiiiiiihihhihhiiiihhihihiihihhhihiiiihhhiiiiiiiiihihiiiiiihhhhihihiihiihihihhhiihhiiiiiihhhihhihiiiihhihhhiiihihiihhihihihihhhihiiiiihhhiiihhihhihihhiiiihhhhhiiihiihiiihiiiihhhiihiihhhhiihiiiiihiihihhiiiihhhhihiihiiii\n", "output": "23\n"}, {"input": "3548\njiiiijijijjjjjjjiijjiiijjjiiijjijjjjjjijiiiiijijjjjjiiijijjijiijiiijjjiiijijjjjijijiijiiiiijiiiiiiiiiiijiiiiijiiijjjiiiijjijijjiiiiiiiiiiiiijijjiijjjijjijijjijjjiijiiijiiijijjiijjijjijiiiiiijjjiiiijjjijjiiijiiijiijijjiiiijiiijjijjjjiiiiijijjjjijjiijijjjiijjiijiijjjiijijjjijiijijijijijjijjjjijjijjijjjijjiiijiiiiijjijiijiiijiiiijijijjjiijiijjjjiiijjjijjiiijjjjjjijijjijiiiiijjjiijjiijiiiiiiiijjjjjijiijiijiiiiijjjjiijiiijjjjjijijiiijiijijiiijiijjiijiijiiijjjijiijiijiijiiijiiijijijjjjiijjjjijijijiiijijjjjjjjiijjiiiiijijiiiiijjijijiiijjjijiiijjjjjiiijjijjijijiijjijiijiijiijjijiiiiijiiijijjjiiijijijiijjjjjjjjiijjjijijjiijjjjijijijijijjjjjijiijijjiijjijijijjjiiiijiijjiijjiiijjijjijjijiijjjjjijjjijjiiijiiiijijijiijiiijjjijjiiijjjjiijijjjjjijijiijiijiiijjjjijijjiijjiiiiiijjijjjjjijjijjiijijijijijjjiijijijijjjijjijijiiiijjiiiiijiijjiijijiijjijjjjjjjijiijiijjjiiiiiijijiijjijjjijjijjiijjijijiiijijiiijiiijiiijijijijijjjiijijjiijiijjjiijjjijjiijiiijjijiiijiiiijiiiiijjjjijjiiijjjijjijijjjijijjijiiijjjjiijjiiijiijjiijjiiiiijiiiijjijjijjiiijjiijjjjijjjiijiiiijiiiiijiiiijijijjjiijjjijiiijjjiiijiiiiijjijiijjijjjiijiijjjjjjiijijjjiiiijjijjiiijjjijjjjijiijiiiijiiiijjjjjjjijijijjjijijijjijijijjjjiijijiiiijjiiijjiijijjijjijjjiijijiijjijiijjjijjjiiijijiijijjijiijiijiijijjiiiiijijiijijjiiijjijjiijjijjijijijiijjiiijjjjjiijijjjijiiijjiiijjjjiijjijiiiiijijijijijjiiiiijijijiiiiiiiiijjijjijiijjjijijijjjjjjiijjiiijjjiiijjjjijjjiijjjiijjijjiiiiiiiiijijjiijjjjjjiiiijiiijiiiijiiiijijijjjjijjjiijjiiijjiijjijiijijiijjijjjiijjjjjiijiiiijiijjjjijijijiiijiijiijijijjjijjjjijjijjjjiijjijjjijijijijjjijijijiiiijjjijijijjjjiiiiiiiiiiiijiijijiiiijjjijijiiiiiijjjjijijiijiiijjiiijiiijiiiiiiiiiijijjijjijjjiiiijijjijiijjiiijijiiijiijjjijjijijijjjijiijijijjiijjjjiijiiijjijjjijjijjjjiijijiiijjjiijjjjijjjijjjiiijiiiijiijjjjjijiiijjiijijijijjiijiijiijiijjjiiijjijijjjiijiijjijijjijjjiiijjijiiijjjiijjjiijjijjiijijiijjijiiiiijjijjijijijijijjjjjiiiijiijiiiijiiiijiiiijijjiiijjiijiijjjjiijijjjiiijijiiijjjijjjiijjjijjjiiijjijjjjijjiijjjjijiiijijjijijiiiiijijijjijjjjiiijjijiiiiijijijijjiiiiiiiiijjjjjjijijijiijijjiijjijiijiiijijiijijjiijiijiijjiiijjiiijjijiijjjijjiiiijiijjiiiiijijijijiiiiiijjjjjiiiijiiijijjiijjjijijijiijiiiijiijiiijijjjijjjijjijjjijjjjjjjiijjiiiijijjijijijijjiijijijiiiijijjjjjiijijijiiijjjijjiijijjjjjjiiijijjjiiiiiijjiiiijijijjijijijjijjijjjiijijjjjijiijiiijjiiijjijijijjiiijjijjiiiiijjijijijjiiiiijijjjjijjijiiijjjiijiijjjiiijijjjjjijiiijiiiiijjiijiijjijijijjijiiijjjjjjjjiijijiijjjijiijjijiiijjjjjijijiiijjjjjiiiiiiijjjijjjiijjiijjiiiiiiijjjiijjjiijjiiiijijjijiijijjjijjijjjijijjiijiiijjiijiijijiiiiiiiijijjjijiiiijjjiiijjijijiijjiiiijjijjjjiiiijjiijiiiiiiiijjjijjjiiiiiijiijiijjjijjiijijjijijijjiiiiiijiijjjijijjiiiiiiiijijjijjiijjijjijiijiiiijjijijiiijiijjiijjiijjiijijjijiijijjijijjjjiijiijiiiijijjjjjiiiiijjjjjjijjiijijjijjjiiijiijjjjijiijijjjjijiiiiijjijjjjjiijjjjjijijiijjjijjjijiijjjijjijjjijjjjiiiiijijiijjjjjjjijijiijijiiijjjijiijiijiiijjijjjjjjjijjjiiiiijjjjjjiijjjjjiijjjjijiiijijijiiijijiijijijjjiiiijjjjiijiijiijijijiiijjjjiijijiiiijijiijiiijjjijijijiiijjjjiiijiijijiiiiiijijiiiiijjjjijjjiiijjiiijijjiiijijiiijiijijiiijjiijiijjjjjjjjjijjjjjjiiiijjjjijjjjjijijjiiiiiijjijjijiiijijjjjjjjjjjjiijijiijijjijiiiijijjjiiijjjijiiijjjijiijijjjijjjjiiiiiijijijjjijjjijijiijjiiijjijiijjiijjjiijijiiiijiiiijjijijiijiiiijjjiijjjiijijjjjjijijjijiiijjiijjjjjjiijiijijijiiijjijjiiiijjjjiijjjiijijiijjjjiijiiiijjjjijjijjjiiijjiijiijiiijjijjjjjiijjjiijijijjjjiiiiiijiijijjjijijjjjiiiiiijijijjiijjjiiijiiijiijijjjijjijijjijiiiijjjjjjjjijijjjjjjiijiijijjiji\n", "output": "21\n"}, {"input": "3477\nkkjkkkkkjkkjkkjkjjjkkkkkjkjjkkjkjkjkjjkjjjkkjkjkkkjjjkjkjkjjjkjkjkjkjkkkjjkjjjjjjjjjjjjkjkkjjjkjkjkjjkkkkkkkjjjkkkjjjjkkkjjkkkkjjkkjkjjkjjjjjkjkjjjkjjjkkkjkkkjkkjjkkjjkkjjkjjkkkkkkjkjjjjjjkkkkjkkjkjjkjkkkjjjjjjkjkkkkjkkkjkkkkjkjkkkjjjjjjkkkjkkjkkkjjkjjjkjjjkjkkkkjjjjjjkjjkkjjkkkkkkkkkjkjkjjkjjjjjkkjkkjkkkjkjkjjkkjjjjjjkjjkkkkkjkjkkjjkkkkjjjjkkkjkjjkjjkkjkkjkkjkkkjjkjkkkkkjjkjkjkjjjkkkjjjkjjkjkkkjkjjkjjkjjkkjjjkkjkkjkjjjjkkjkkjkkkjjjjjjkkjjjkjjjjjkjkjkjjjjkkjkjjjjkkjkkkkkjjjjjjjkjjjjkjkkjkkkkjkjjkkjkkkkjjjkkjjjkjjjjkkkkkkjjkkkkkjkjjkkkjkkkkjjkkjkkjjjkjkjkjjkjkjjjjkjkjkkkkjjkjjjjjjjjjjkkkkjkjkjkjkjkjkjkjkkjkjjjkkjjjjjkjjjjkjjjjjkjkjjkjjkjjkkkkjkkkjjkjkjkkkjjjkjjjjjjjkjkjjkjkjkjkjkkjjkkkjjkjjkkkkkkkjkjjkkjjkjjjjkjkkkjjkjjjkjjjjkkjkkjkjkkjjkkjkkkjjkkkjjkjkkjjkjjkjjkkjkkkjkjjjjjjjjjjkjjkkjkjjjjjkjkjjkkjkjkkkjkjkjkkkkjkkkkjkjkjkjkjjkkjkkjkjkkjjkjkjkjkkkkjjkjkjkjjjkkkjjjkjjjkjkkkjjjkjjkkkkjjjkjkkjkkkkjjjjkkkkjkjkjkkkjjkkkjjjkkkjkkkjkjjkkjkjjkkkkjjkkjjkjkkkjkkjkjjkjkjkjkkjkjkjjkkjkjkkjkkkjkjkjjkjjjkkjkjjjjkjjkjjkkkkkkjjkkjkjkkjjkjkjjjkjjkjjjkjjjjkkkkjkjkjjjjkjjjjkjkkkkkkkjjkkkjkjkkjkkjjkjjkkkjkkjjjkkkkjkkkjkkjkkjkjkjjkkkkkjkkjkkjjjkjkjkjkjjjkkkkjjkkjkjjjkjkkkjjkkkkkjkkkjjkjkjjkjkjkkjjkkkjkkkkkkjkjkkjjjkjkjkkjkkkjjkjkjkkjkjkjjjjjjkkkkjjjjjkjjjjkjjjjkjjjkkkkjkkjjjjkkjkkjkjkjjjjkjjkkjkjjkjkjjjkkkkjjkjjkjjkkkkkjkkjjjkkkjjjjjkkkjjjkkjkkjjkjjjjjkjkjkkkkkkjkkkjjkjjkkkjjkkjkkjjkjjjkkkjkkkkjjkkkkjkjkkjkkkjjkkkkkjkjjkkjjkjjjkkkkjkjkjkjkjjjkkjkkkjjkjkkjjjjjkjjkjjjkkjjjkjjjjjjjjjkkkjjjjkkkjkkkkkkkkkjjkjkkkkjkkkjjjjjkjjjjkjkjkjkkjjkkjkkkkkkjkkjjkjkkkjkkjkjkkjjjkjjjjjjkkkjkjkkjkkkjkkjkkkjjjjkjjjjjjkjkkkjjjjkkjkkjjkjjjkkkjkkjkkjkkjjkkkkkjjjkkjjjjkjkkkjkkjjkjkjjkjkjjkkjkjkjkkjkjkjjjkjkjjjkkjjkjjkkjkkjkjkkjjkjkkjkjjkkkjjjjjkjkjkjjkjkkjkkjjjkkkkkkkjkkjkjjjkjkjkkjjjjkkkjjjjjkkkkkkkjkjkjkkkjjkkkkjkkkjkkkjkjjkkjkkjkjkjkkkjkjjjjjjjjjjjjkjjkjjjjjjkjkkkjkkjkjkkkjkjkkkjkjjkjkjjkjkjkkkkkjjkjkjkkjkkjkkjkkjjjjjkkkjkkkjjjjkkjkjjjkjkkjjjkkjjkkjjkjjkkkjkjjkkjjjjjkkkkjkjkjjjkjjjjjkjkkkjkkkjkkjkjkjkjkkjkjkkkkjkjkkkkjjkjkkkkkjjkjkjkjjjjjjkjjjkjkkjjjjkkjjjjjkjkjjkjjkjkkkjjkjkjkjkkjkkjjjkkjjkjkkjkkjkjkjjkkkkjjjjjkkkkjjkkjkjkjjkjkkkkjjjkjkjjjkkkkkkjkjjjkjkkkjkkkkkjkjkkkkkjjjjkjkjkkjkkkjjjjkkjjkjkjjkjjkkjjjjkkjkkkjkjjjjjkjkjjjjjjjjkkjkkjkkkkkjjkjjkkjjjjjkkjkkkjkkjjkjkkjjkjkkkkjjkkjkjkkjjjkkkjjkkkkkjjkkjjkkkkkjkjjkkkkkkjkkkjkjkjkjkkjjkjjkjkkjjjjjjjkkjjkjkjjkjjjkkjjkjjkkjkjjkjjjjkkkkjjjjjjjkkjkjjjjkjjkjjkjkkjjjkkjjjjjjjjkkjjkkjjkkjkjjjkjkkkkkjkkkkkkkjjkjkkkjjjkkjkkjkjjkjjkjjkjkkjkjkjkjjkkkjjjkjjkjjkkjkkkkjkkjjjjjjkkjkjjjjjjkkkkjjkkjkjkjjjkkkkkkkkkjjjjkjjjjkkjjkjkkjjkjjjkjkjjkjkkkkjjjjkkkkjkkjjjjjjjjjjkkjkkkjjkjkkkjkkkjjjjkjkjjjjkjjkkjkjjjjjkjjkkkkjkkjjkkjjkkkkkjjkjkjkkjjkjjkkjkjkjkkkkjkjjjkkjkkjkjkjjkjjjkjjkkkkjkjkkjjkjkjjjkkkjjkkjjkjkjkjkjkjkkjjkkkjkjkkkkkjkkkkkjkkjkjkjjjjkkkkjkkkkjkkjjjkkjkjjkkkjjkkjjjjkjkjjkjjjjjjjjjjkkkjjkjkkjjkjkjkjkkjkjkkkjkjkkkkkjkjkkjjkkjjjjkkjjkjjjjjkjjjjjjjkkkkkjkjkjkkjjkjjkkkjjkkkjkkkjkjjjkkjjjkjjjjjjjkkkkjkkjkkjkkjkjkkkjkkjjjjkkkjjkkkkkjkkkjkjkjjkkjjkjkkjkjjkjkjkkjjkkjkjjkjkkkjkjjkjkkjjkkjkkjkkjkjkjjjkjjjkkkkjkkkkjjkkkkjkjkjkkjjjkjjjkkjjjjkjkkkjjkkjjkkkkjkkjkkkjkkkkjkkkjjkjkkkkkjkjjjkkkjkkkkjkkjjkkkkjjjjkkkjjjjjkjkkjjjjkkkkkkjkjjjjkkjjkjjkkjkjjkjkkkkkkjkkjjkjjjkkkkkkjkkjjkjjjjkjjjjkkkkkkjkjjkjjkjkkjkjjjjjjkjjkkjjjkkkkkkkkjkkkkkkkkkkkjjjjkkkjjkkjjkkkjjjjjkjkkkkkjjkjkkjjkkkkkjkkkkkjjjjjjjkkjjkkjjkkjjjjjkjkjkkjjjjkjkkkjjjkkjjkjjkjjkkjjkjjjjjjkjjjjkjkjjjkjjkkjkkkjjkjkjjkkkjkjkjkkkjjkkkkkkkkjkjjjjkkjkkkjjkjkjjkjkkkkkjkkkjjkjjkkjkjkjkjjkj\n", "output": "23\n"}, {"input": "3242\nkkklkkkllkkllkklllklllllllkkllkkklklkllklklklllklllkkklllllklkllllklllkllklkllklkklllklkkllkkllkllkkklklklllkkklkkkklklklkkklllllklllkkklllklkllllllkkkklllklkllkklkklkkllkkkkkllklkllklllkkkklkkkllkkkkkllllllllkklklkllllklllklklllllkklllllkkkkkklklklllllklkkkllklkklllllkkkkkkkllllklllkkllklllkklkklkkllkkkkllllkllkllklkllkllllkkkllklllllllkkkkkkllklklllllkllkklkkkkkllllklklkklklkkkkllkkllkklkklkllkkkllklklkllllklllkkkkkkkllklkkkkllklllllllllkllllkkllkkklkkkkllklkkkklkllllkkkkklklkllllklklklllkllklklklllklklllkkklklkkkklklllkklklkkklkllllllkkklllklllkkllllklllklkllkkkllkkklkklklkllkklllllkklkklkkklklklklkkkklkllklkkkkllklkkkllllkllllkkllllkkkkllklllkklkllllkklllllklkkllklkllkkklkkllklllkkllklllkkllkkklllkkllkklllkklkllkklllkllkkkklllkkklllkkllkklkkkkkllllkklklklllllkkllkkkllkkllkklkllklkkkklkkkkllkkkklllllllllllkkklkkkkkkklkkllkkllklllllkklklllllkkkkllkkkkklkkklklkllkkkklkkllkkllkllkkklklklklkklkkllllklllkkkkkllkkklklllkklllkllklkkkklklkklklklklllkkllllllllkklklllklkkkkllklkklklklklklkkkkkkklllklkkkllkkllllkklkkllkllkkkklllllkkkkklllkkklkkllkllkllklklkkkkllklkklklllkkkllllllklkllklkkllklllklllklkklkklkklklkkkkkklkkkklkklkllkkllklkkkklllkklllllklkllkllklklllkkllllkklkkklklkklllkklkkkkklklllllkklkkkkklllklklllllklllkkkkklllkklklklkllkkllklklllllllllllkkllllklllllkllkllkkkllkllllllklkkkklkllklklkkllklklklllkklklllllllllkkkllkklkkllllllllkkklllkkkllkllllklklklkllkkllllklkkkllkklklklllkkkkkklkkklllkkklklkllkllklkllklklllklkklkkkkllklllkkllkklkklkkkklkkllkkllllkklkkkkllllkklkklkkkkkllkllklkklllklkkkklkkllkklklklklllkkkklkklklllllkkllklllklkkkklllllkklllllkkkkkllklkllklkkkkkkkkkkllllklkllllkklklllkllklkklkllklllllklllklllklklkklkklkkkkkkkkklllllllkkkkkllkkklllllllllllllkklllklllklklklllkklklkllkklkklklllllklkkkkllkllkllklklllkklkllkkkkllklllkllllkkllkklkkkkkkklkkkklkklllkkklklllkkkkkllklkkkkllkklklkklllklkllkkllkllkkkkkkklkllkllkkkkkklkllkllklklllkllllkllklllkklkllllkkkkkllklllllllllkllklkklllkkkklklkkklkklllllklklkkkkklkklkkllkkllklkllklllllklkkkkklkklkllkkllkklllllklllklkklkklkklkkkkkkklklllklkkklllllkklkllkllllkkkklkkllklkklklllllklllkkklllllllkkklklkkklllkkkklklkklkllkkllkkllklllkklkllkkllklkklkllkkkklklklkkklkkklklkkkkllkklllllklkkllkkkllkllklllkkkllklklkllkklkkllllkkkkklklkklkkklkklklkllllklkllkkllkkklllkkkklklllkkkllklllllllkllkklklkkkklllkklkkkllkkkklkkkklkkkklllllkkllkkklkklklllkklllkkkkllkklklllkkklkllkkkkkkklkklkllkllllllkkklllkllkkkkkkklkkllkklklkklklkklklkkkkkkkkkllkllkllkklkklkllkkkkkllllkllllklkklllkkkkkllkkkkklklklkllkklklkkkkllkllkkkkklllkkkkkkkklllklklllkllklllklklkklllllklklklklllllllkkkkkkkkklkklklklkkkklllkkkkllkkklllkkkkllklllkklllkkkkkllkllllllkkkkkkkkkkkkllllklllkklllllkllllllklkklkkkklkkllllkklkllkllklkklklllkklkkkklkllkllklkklkklklklkklllkkklklkkkklkllllkklkkkllkkllklllkkkkklklkllkklllklllkllkkkkklkkkkkkkllkllllllllklkkkklllllkkkkkkllllkklkkllkkkllkllkkklllllllklllklklkllklkklkklkkllkllklkkkklkkllllklklklllkkkkllklklklklklllkklkkkkllkkkklklkllkklkkllkklkkklllkklllllklllllklllkklkkkllkllllkkklkkkkklklklkkkkllklklkkklklllllkklkkllllkkllkkkklllllkklklkkkklklllkkkllllkkkllkkkllkllkllllkkklkklllllllkklkkkklklklllkkklklkkllllllkllkklklkkllllllkllllklkkllklkklkllklklllllkkllklkklkkkkkkklkkkkllkklkklklllllkkkkkklklllkklklklllllllklkllkkkkkkklklkklkllkkklllkllkkllllllkkklkklkl\n", "output": "21\n"}, {"input": "4611\nebfhbvjflokwfloquybisnncdxrxiwjeywmlvehrztgkyqsyokkmhnhqpshxwlnyihxxwozvwvcniukdiazvswrumrglhjpnicljpccfgmnsqvyfkpptkuylxwklltxbmkpsytndewnsicxmghyyqffhgcbxnjldewkuggdnjktvuypwafjmodayfenavxclaefkmpgahpawsshlcwzfggiyhkpitcgueotvuoxmdiuyyvoixclcxotwfkmwflthuumweqhlyznvxbugbtbcucpxhuufjoaltxsbbyevuuulcsdynmqjwnrzrirjuhmhvpyidkgdioetdwuqgeygxdyoscbcsphuyovutsicjxjqaytuoburtlmzlvfkiwmdtphpufgotkiignhvfxgkqorydreukvosnpswuysogyjncvffibeihmugjsdhepsowqbyhjyuebuwutuzzmsclrwmkbmzuwrzohdpamcomdoqqdhegscbeodazlllkmelotapwtmivagtfbnyxrgnxtzkqsvqewtjxcglpedshndvagjvoavsqapqxmoifdrebowuxxxwnzdvbhhtnifgxjacpadxpvgscvnglgthpzmuotzrdhnchakshvfzxmptzshdreavldgmwukskjzzdfzctrwlejeuxaaakicuxrqlcgvxtlhjcnavrloaajfciznfnenrnshqljiizqfcxgmyaxqefsrdbwdwhtzvfmpsyirpiedjdndxltdozsxlouatvtxmwikfowxbitfrbweuqojnnaylfrgmeusvcddjypyqusaktjzezhsnayqmlfkhnppxirzxicndcmwfwaemdgyakwdkzepxmxkxweagknfewfiyohesllskmshshxhnbefeqnhwzykkmtaxbuwyzwrsfafchvorzwnlheklqwyeifckayyjxlklxaaslgtlegiagphivoaleaqfoxehcidvuhcbjtpkjzpisshefbhgrcuejihhtwmrieqshmeghjejplxxwndklzeqiiwswvqgonmnqnqumwlgviwxysgjbyddfnvsdfpyvseomwczorarwwrhgghkiehdopszfzgzfgkyrtpzkhpepdpafchkcvbpxmmsscqblxccwctkjicbfadwhryxhfleazqqbmljccqhmcgxzwiguoddgtmdutvorhdftzbcyqjqbbromajbvvsirhwjbebytgibywlovtjidctthrwzrpakvvoxzivwepcvietiqbqkxxoymnqoyrlhatzvrzvkkdqeyzgxrdhymumpwktqkgilcoqhkyavkcmgrattsudtyhygovlwvkglarwrflkozutthttenskfkkbebzkbedzgpvqffxqahmpaeorymfzqellegyxrivsixhvcixksbqswpiuermkpmjcccmrvthxjsqaefdqlfurtrmlvbkhxrovaiwfpmqkotxfczrygzqjzazaxozwgshbvcbzhvpsulgydciqjheetkqhznltuzyipetblyggzwuolcbwtzgsaeankaxmkqruzhrknvbbnkxoscyvghvgsjukgzpgfyigotjsxepkvuzqvthpwwzzfzontwrrjkrlixhqqfqoovdcmvcnkqpfiihfdpxlslczjkggettqcbqxzyvhtjkijzxebihrvuoawopnokponaapyygzncinrbuokyfofstpudaccuunohknzaznpijtnifqjdkowgrrtshmagkbipnwubfhbhfgckdkgsxyjadqfqnoxhmuzywuuclxrozsdmcmjzojsbgamrhxapufxmudblfyqloobjsirsrmjlccvznjafspzqqcgmledesdzfmiyfxmpscjrrxrpiemkheqaqagdocrjebatmuezltnhviajgatyhlfdvvmwmpzjvnhgnfqfnnotsbgedqybqnznqqgcjbteyxwrhjlnuqxjlolrpbfkvezxwnenrmhxspvimivoewdcdryrhhxqzbsflrmsevomenqhtgldaassrbjmupnzoxsldzwowmdtkigkhqlztbwqyharmkpxiyhtctnbutypofrqkhddxjqpnyvuuepzovmvxnttxupxkrufifsyxtrtqnktlbhwrzntjejrzxrxgfccfmxptupezhniiodafnncbdxosydtsorpsthybwwjdpjpkbfjwqfulwfknetmilhgkzwkqdttmbeqadaozfnyrdvqrblytqbxjcqhjljejyzsopiojovrortuiapkmmzqigfjwhuejmbxdqvpuabjcxzvyxuayxybfvoltrsbqiigauzoilukdiazvswrumrglhjpnicljpccfgmnsqvyfkpptkuylxwklltxbmkpsytndewnsicxmghyyqffhgcbxnjldewkuggdnjktvuypwafjmodayfenavxclaefkmpgahpawsshlcwzfggiyhkpitcgueotvuoxmdiuyyvoixclcxotwfkmwflthuumweqhlyznvxbugbtbcucpxhuufjoaltxsbbyevuuulcsdynmqjwnrzrirjuhmhvpyidkgdioetdwuqgeygxdyoscbcsphuyovutsicjxjqaytuoburtlmzlvfkiwmdtphpufgotkiignhvfxgkqorydreukvosnpswuysogyjncvffibeihmugjsdhepsowqbyhjyuebuwutuzzmsclrwmkbmzuwrzohdpamcomdoqqdhegscbeodazlllkmelotapwtmivagtfbnyxrgnxtzkqsvqewtjxcglpedshndvagjvoavsqapqxmoifdrebowuxxxwnzdvbhhtnifgxjacpadxpvgscvnglgthpzmuotzrdhnchakshvfzxmptzshdreavldgmwukskjzzdfzctrwlejeuxaaakicuxrqlcgvxtlhjcnavrloaajfciznfnenrnshqljiizqfcxgmyaxqefsrdbwdwhtzvfmpsyirpiedjdndxltdozsxlouatvtxmwikfowxbitfrbweuqojnnaylfrgmeusvcddjypyqusaktjzezhsnayqmlfkhnppxirzxicndcmwfwaemdgyakwdkzepxmxkxweagknfewfiyohesllskmshshxhnbefeqnhwzykkmtaxbuwyzwrsfafchvorzwnlheklqwyeifckayyjxlklxaaslgtlegiagphivoaleaqfoxehcidvuhcbjtpkjzpisshefbhgrcuejihhtwmrieqshmeghjejplxxwndklzeqiiwswvqgonmnqnqumwlgviwxysgjbyddfnvsdfpyvseomwczorarwwrhgghkiehdopszfzgzfgkyrtpzkhpepdpafchkcvbpxmmsscqblxccwctkjicbfadwhryxhfleazqqbmljccqhmcgxzwiguoddgtmdutvorhdftzbcyqjqbbromajbvvsirhwjbebytgibywlovtjidctthrwzrpakvvoxzivwepcvietiqbqkxxoymnqoyrlhatzvrzvkkdqeyzgxrdhymumpwktqkgilcoqhkyavkcmgrattsudtyhygovlwvkglarwrflkozutthttenskfkkbebzkbedzgpvqffxqahmpaeorymfzqellegyxrivsixhvcixksbqswpiuermkpmjcccmrvthxjsqaefdqlfurtrmlvbkhxrovaiwfpmqkotxfczrygzqjzazaxozwgshbvcbzhvpsulgydciqjheetkqhznltuzyipetblyggzwuolcbwtzgsaeankaxmkqruzhrknvbbnkxoscyvghvgsjukgzpgfyigotjsxepkvuzqvthpwwzzfzontwrrjkrlixhqqfqoovdcmvcnkqpfiihfdpxlslczjkggettqcbqxzyvhtjkijzxebihrvuoawopnokponaapyygzncinrbuokyfofstpudaccuunohknzaznpijtnifqjdkowgrrtshmagkbipnwubfhbhfgckdkgsxyjadqfqnoxhmuzywuuclxrozsdmcmjzojsbgamrhxapufxmudblfyqloobjsirsrmjlccvznjafspzqqcgmledesdzfmiyfxmpscjrrxrpiemkheqaqagdocrjebatmuezltnhviajgatyhlfdvvmwmpzjvnhgnfqfnnotsbgedqybqnznqqgcjbteyxwrhjlnuqxjlolrpbfkvezxwnenrmhxspvimivoewdcdryrhhxqzbsflrmsevomenqhtgldaassrbjmupnzoxsldzwowmdtkigkhqlztbwqyharmkpxiyhtctnbutypofrqkhddxjqpnyvuuepzovmvxnttxupxkrufifsyxtrtqnktlbhwrzntjejrzxrxgfccfmxptupezhniiodafnncbdxosydtsorpsthybwwjdpjpkbfjwqfulwfknetmilhgkzwkqdttmbeqadaozfnyrdvqrblytqbxjcqhjljejyzsopiojovrortuiapkmmzqigfjwhuejmbxdqvpuabjcxzhuoizmppodfsmpd\n", "output": "2246\n"}, {"input": "4599\nmpfvbozcrxnboodvbfzluraoeaubclnhdkgbrgzpafbzanamwousfmfglthzdyauezatkweyejdkubxprbkniemizklweyjabxesszunsorvtpgagnestwhgcgmqejysodvzrdoptpochbwyqvpbchzmdptvkmsjtzgopbsgiiekcimyjcunqivybrpdrhdpijlfrcronsrtewjuhfqxxvbdwtovfckeayabqorumcubkfnohiyxsozppskgeqbzrwweolhbstuhjuieadatgcebkibozqgzqybmgsfzzuljbkssqpzshzpbbgsnfwaodesokshsygzldxmurrvejwifdmuqkagaegebmzbbywdrdahfspawkwnfzyxienlqrqvtzttpzacrvkepwpzrhtxnhsyzedtgqcthkrxsncozdnjejwhdxhqrpeqbglkkvcpdvwgitnfihpqfknegssfktkblxmusfxklmasctxakloifvghzzdxcnbhaosoayjkhlocxybgwshnkqrbjdpkxjzxkxzpujvffykspfqttarwemtvcsjowsajvswjtebunlswwpeprtegsqhiuohkwetdsxqcxrxyaqjsnlpvakzjjmfvyktbxfzxaenvzqjtescuzugimwkzdcnabgsfuikpztnnajrhxgbmgrayudxjhfuwhsakaqhjmqfkgghdkywlaqxyzaoxfabzkqerjruapgqrfgcvafjdclpeqkbdrtibxepnnqzkscckqnmhrvefzvfyzvgloktduqjmsbjiysvxooilkezhzyjxqhszdsywrfoanovfesuljjbnwrnjyfiimiznxofowrmivqkjuncrjcvfspwanvnhjhakcqaibfodqoceaujfcdiezaohhcraadtsagfrwylfltfahbjdvugpoyixqajedceuxvhqkwkszflywohdxzymxkrygoaiutjdecfqcrzxkkxrdqathhzldxxgctbargwnsdzugwopiemlizcrnohbszqdnhecshvetgdkaxagzugpnaxqdtnsvgfebgzbrirbdemfnejkmnteiwqcklatsfrcymnelhsbjozjejkesrumfdudsauxtrixnmqbiwiiqukapyyznayzwvpkwwxgjarendfcjicceaqvejrvqhjlivxmrxpqrjeekatmttjvwdzlodjcynyxqylppmzgqkvzormigvlosuhofyzzrcbmaitpqainqrdbqkgrwndeatnfyjlxpjedldmntnujhrzezcsyocgybacdsntwgklmpmrygeschpnrlvjssmoaockndsnydbkbeecqqozdbxvruulqeorqiihynmdkpizzltdoerbdqncqzqoiodvbciylbmfpmzzurfjyvdiuiprzhzvumjfrvicegqcrbootovbsualgextnafmrmmuvsdpioyaqjsieuwmjcfgswhhyovcibmmejmhnnsqfexwlcanqghzmexmccokhdkwebjhhwkzbyzpsddjvuemuesnnmanddxejymmbiergflznryxayvjairymrryikbuusuqibxswoopiuunlvvekusmcwaciitojcydqlpdueybijzzytqmybuvvlhmutxssxmawjpkphztfdzutxqhvpfxeoyifzxarhssbxslnwsvuqhxnqpwekvzpkdcvnxfyftnwwqkisalwnjqqwqrhxnmgqgxegnzlzknqnvlxbfjpogpezwogjymdsbpnobpnvnxcnvwftaizzbhymdxwmyhcitfdmobimecmlbimgtcovntbtwwpxtybttsyhyxhfkexkunapulhzprjvedsyewtwnsenvffnwxtxliwxdghhujibdrcbmlanllcouvsfuaawioyqiechpixctejktsvowspvibckycnvjllvlddwgrhvufnrqbcwuynidswvphpbndixlwhlvsevbdtilcxmyruzgeyeonudqvxeixkuhnjvnoiygkawprpiabnofnrzhlakoiszlzsfugolawbinltjlsubkunrpzujeqwbxzbjdrtvgkujabiahsupacxegbsspukdrrryvuwvsuimdayeqlgfczeoqrquhbkhwxhmsqhoktdrotgznupsqmjwvxojxdajxknqibrsjwyeijpwvgkukqotyipyhsylqqrfzmhauafwanbsupnobpunooayvmafhqnvmmitllwihaxltpaoktxukyspwovtlfbugjtwahfswvjjmkyrywhtbalafynsuekmovicnfecnrdmzuzlmlptquvvsfmfglthzdyauezatkweyejdkubxprbkniemizklweyjabxesszunsorvtpgagnestwhgcgmqejysodvzrdoptpochbwyqvpbchzmdptvkmsjtzgopbsgiiekcimyjcunqivybrpdrhdpijlfrcronsrtewjuhfqxxvbdwtovfckeayabqorumcubkfnohiyxsozppskgeqbzrwweolhbstuhjuieadatgcebkibozqgzqybmgsfzzuljbkssqpzshzpbbgsnfwaodesokshsygzldxmurrvejwifdmuqkagaegebmzbbywdrdahfspawkwnfzyxienlqrqvtzttpzacrvkepwpzrhtxnhsyzedtgqcthkrxsncozdnjejwhdxhqrpeqbglkkvcpdvwgitnfihpqfknegssfktkblxmusfxklmasctxakloifvghzzdxcnbhaosoayjkhlocxybgwshnkqrbjdpkxjzxkxzpujvffykspfqttarwemtvcsjowsajvswjtebunlswwpeprtegsqhiuohkwetdsxqcxrxyaqjsnlpvakzjjmfvyktbxfzxaenvzqjtescuzugimwkzdcnabgsfuikpztnnajrhxgbmgrayudxjhfuwhsakaqhjmqfkgghdkywlaqxyzaoxfabzkqerjruapgqrfgcvafjdclpeqkbdrtibxepnnqzkscckqnmhrvefzvfyzvgloktduqjmsbjiysvxooilkezhzyjxqhszdsywrfoanovfesuljjbnwrnjyfiimiznxofowrmivqkjuncrjcvfspwanvnhjhakcqaibfodqoceaujfcdiezaohhcraadtsagfrwylfltfahbjdvugpoyixqajedceuxvhqkwkszflywohdxzymxkrygoaiutjdecfqcrzxkkxrdqathhzldxxgctbargwnsdzugwopiemlizcrnohbszqdnhecshvetgdkaxagzugpnaxqdtnsvgfebgzbrirbdemfnejkmnteiwqcklatsfrcymnelhsbjozjejkesrumfdudsauxtrixnmqbiwiiqukapyyznayzwvpkwwxgjarendfcjicceaqvejrvqhjlivxmrxpqrjeekatmttjvwdzlodjcynyxqylppmzgqkvzormigvlosuhofyzzrcbmaitpqainqrdbqkgrwndeatnfyjlxpjedldmntnujhrzezcsyocgybacdsntwgklmpmrygeschpnrlvjssmoaockndsnydbkbeecqqozdbxvruulqeorqiihynmdkpizzltdoerbdqncqzqoiodvbciylbmfpmzzurfjyvdiuiprzhzvumjfrvicegqcrbootovbsualgextnafmrmmuvsdpioyaqjsieuwmjcfgswhhyovcibmmejmhnnsqfexwlcanqghzmexmccokhdkwebjhhwkzbyzpsddjvuemuesnnmanddxejymmbiergflznryxayvjairymrryikbuusuqibxswoopiuunlvvekusmcwaciitojcydqlpdueybijzzytqmybuvvlhmutxssxmawjpkphztfdzutxqhvpfxeoyifzxarhssbxslnwsvuqhxnqpwekvzpkdcvnxfyftnwwqkisalwnjqqwqrhxnmgqgxegnzlzknqnvlxbfjpogpezwogjymdsbpnobpnvnxcnvwftaizzbhymdxwmyhcitfdmobimecmlbimgtcovntbtwwpxtybttsyhyxhfkexkunapulhzprjvedsyewtwnsenvffnwxtxliwxdghhujibdrcbmlanllcouvsfuaawioyqiechpixctejktsvowspvibckycnvjllvlddwgrhvufnrqbcwuynidswvphpbndixlwhlvsevbdtilcxmyruzgeyeonudqvxeixkuhnjvnoiygkawprpiabnofnrzhlakoiszlzsfugolawbinltjlsubkunrpzujeqwbxzbjdrtvgkujabiahsupacxegbsspukdrrryvuwvsuimdayeqlgfczeoqrquhbkhwxhmsqhoktdrotgznupsqmjwvxojxdajxknqibrsjwyeijpwvgkukqotyipyhsylqqrfzmhauafwanbsupnobpunooayvmafhqnvmmitllwihaxltpaoktxukyspwovtlfbugjtwahfswvjjmkynzwujywewtttlobguoblotzrdfmqbeowpgb\n", "output": "2236\n"}, {"input": "4512\nydrtosuycljrnrwtjmmcevlftanyifidoqfdzdoudcmegcsgiiduohinrxwffdfslxvrcpfycpenvwqyuyjlhznowgejltpucbiiyvgvuojfvhgwnaeqoumvtnqbfgwpeixljvbfbyfgnyyfceitoqqzrbqygmjbuufwscmrlfdowvpcunfvhivscjluooggpnrsuoqvtfdllzqxjihgegrurdzfmlijpwjcnlsfcdolebzemkunlcwtksdtrdqfelxbtnisghcfxzbxjgvpeuoblkggnfwggjuputacobaeorkkmocrmhpnaemhgsotnazmnmxfvqywahgwazuidgokplfbnalxmfbdrogqvjgolvuwolucixogylqqlcdsafanmzxwwacbuuvqmsaqikzwswmcsmpgswmexlivzzqpzqxcyfwbdygylwlsawuocmpmolczgvmicamhpbyvfikilsphatogcmqsnecugfvmpjrokiyahuvxpxzfbktmzngxlgelktvscrlzrvifbmxeacusvycenprlzigfvxlrhqwyutkanjaoohilqwzmrmynjtddqzelvrhzihhvjkndausepzgwvrznjzebcdszoemiamyivpzdiggsdontbiypreyvwbtxkbtdqfblbyiaivqgcjabjaxkbyayobsnwcsewwaqmmljcavamphvnwotnghgmuxdrjlifgiwykrzwfqoqmnzrhlishgsnxsxduowipavusqywqveaqmfssjnwlnnvqxdzikerrqglmqarnqurmrrygkldncfruskaxzggjaqjvtghqoskzvzyksnenuoebfgyydfeghvcwkvylogfzihksudijcdqnpbbmfeakbdnhmjhvirgqcekqlnhtwtxneszfwvgqzlokjzzcimpfqkupzzfrwaeizolfkmeomxoyofmlpzaxvmqifvvhbuckfbonvgbschkgftdduotwfokhlhyewevpagackkmizhheipgqeosvwcbcnakydwdmyucyigdegvckrpxgkgqcuarcpkfkomlipkafnuuegngnivjvdmgzkerhjbequwndqfszibjdlqfjlirqsmsfpiagtueiuogbiyqjlomxjwadvmakxfyfcpucigrkeynfznyucjzadymaelopzddoflrfkhakubniwryfsicxchpqtmlcarwxojjdnjhmditsoazuccqbejhrsqfkywzbyvnxwvitslethtjrvoqilgnqxzdzacotptwyeoidhypebupvjaulgyrkkcybbtepupwyzuubqscahzvmakakhqmbpjcjruuucjmrgbxlujfzrxvrgvntqpbnokdfuwwmbblguoszscxbdxuraqaktgdlekkzvzazjutxqowjkeexbwbaxzllyjfwtisbnvtitekhhjuxujpqfurcvjzcjiqmeixjwhqsocwdiwmbndpslpusuiaypiqvdkqxcepnkkguhdfishagmzakhycjxlyuaslcuikkvijpfohgnpasadrgfgirnatqdwwkxlwldyvnemqhsuosiykkelxrpgnjmezidmnanulbvklmelvllgqivfxscvcxzhqcaaokmkipyghcsnpgfahgyqwkhztfdjnptrogfhibbognstszwoklhxxsgojcqujsrnfuibtkpfwqwsdwmgapvjrmvlouhlysyxpubrepnaqczhsuqqfjdkagxhwzofksfodbrdjimvhfisyqjohwmyyiyvpqvawnwisiaxqvkinltdqajgoatgyadjeielldlnogpftpnlbqkrlknxrpppzqdrurnatxpitrrlmepklfuguduvxgrrphcgopinrgrbizodpxzjzzujgukjaarsavkysjofrsnfogwanzabocabwtpzbzyntekwocnzljzfdrkcqgmcdtewgwczcpofdhjitiwydzswxjmwbauysxtyuydohgxoazvtltbapzdxhgxtksgujamuxeqnexicykqwzggndaavsmovlfgtjuzxgihzlxqwcphcoelngtcfwcbvkwsykxsddfidjypimgkbyrguvzvgiyycwfutzuymopbnokiidfkouihtawgyzxykdepmwjjddxvetnwngnhcpdejpmtetgsexicpyucaiefskebrmyttiyovbhczgsnpzqldbrpergbndglmmnvuvoficwvbrqjrszayvgiwsjxaqljzwwjixygiugeaquusqmpjvmdngkynhbyvsrnpiyszsadidvfzclujmvoblyopypisvqmbhwnbnypcuhdneitoqqzrbqygmjbuufwscmrlfdowvpcunfvhivscjluooggpnrsuoqvtfdllzqxjihgegrurdzfmlijpwjcnlsfcdolebzemkunlcwtksdtrdqfelxbtnisghcfxzbxjgvpeuoblkggnfwggjuputacobaeorkkmocrmhpnaemhgsotnazmnmxfvqywahgwazuidgokplfbnalxmfbdrogqvjgolvuwolucixogylqqlcdsafanmzxwwacbuuvqmsaqikzwswmcsmpgswmexlivzzqpzqxcyfwbdygylwlsawuocmpmolczgvmicamhpbyvfikilsphatogcmqsnecugfvmpjrokiyahuvxpxzfbktmzngxlgelktvscrlzrvifbmxeacusvycenprlzigfvxlrhqwyutkanjaoohilqwzmrmynjtddqzelvrhzihhvjkndausepzgwvrznjzebcdszoemiamyivpzdiggsdontbiypreyvwbtxkbtdqfblbyiaivqgcjabjaxkbyayobsnwcsewwaqmmljcavamphvnwotnghgmuxdrjlifgiwykrzwfqoqmnzrhlishgsnxsxduowipavusqywqveaqmfssjnwlnnvqxdzikerrqglmqarnqurmrrygkldncfruskaxzggjaqjvtghqoskzvzyksnenuoebfgyydfeghvcwkvylogfzihksudijcdqnpbbmfeakbdnhmjhvirgqcekqlnhtwtxneszfwvgqzlokjzzcimpfqkupzzfrwaeizolfkmeomxoyofmlpzaxvmqifvvhbuckfbonvgbschkgftdduotwfokhlhyewevpagackkmizhheipgqeosvwcbcnakydwdmyucyigdegvckrpxgkgqcuarcpkfkomlipkafnuuegngnivjvdmgzkerhjbequwndqfszibjdlqfjlirqsmsfpiagtueiuogbiyqjlomxjwadvmakxfyfcpucigrkeynfznyucjzadymaelopzddoflrfkhakubniwryfsicxchpqtmlcarwxojjdnjhmditsoazuccqbejhrsqfkywzbyvnxwvitslethtjrvoqilgnqxzdzacotptwyeoidhypebupvjaulgyrkkcybbtepupwyzuubqscahzvmakakhqmbpjcjruuucjmrgbxlujfzrxvrgvntqpbnokdfuwwmbblguoszscxbdxuraqaktgdlekkzvzazjutxqowjkeexbwbaxzllyjfwtisbnvtitekhhjuxujpqfurcvjzcjiqmeixjwhqsocwdiwmbndpslpusuiaypiqvdkqxcepnkkguhdfishagmzakhycjxlyuaslcuikkvijpfohgnpasadrgfgirnatqdwwkxlwldyvnemqhsuosiykkelxrpgnjmezidmnanulbvklmelvllgqivfxscvcxzhqcaaokmkipyghcsnpgfahgyqwkhztfdjnptrogfhibbognstszwoklhxxsgojcqujsrnfuibtkpfwqwsdwmgapvjrmvlouhlysyxpubrepnaqczhsuqqfjdkagxhwzofksfodbrdjimvhfisyqjohwmyyiyvpqvawnwisiaxqvkinltdqajgoatgyadjeielldlnogpftpnlbqkrlknxrpppzqdrurnatxpitrrlmepklfuguduvxgrrphcgopinrgrbizodpxzjzzujgukjaarsavkysjofrsnfogwanzabocabwtpzbzyntekwocnzljzfdrkcqgmcdtewgwczcpofdhjitiwydzswxjmwbauysxtyuydohgxoazvtltbapzdxhgxtksgujamuxeqnexicykqwzggndaavsmovlfgtjuzxgihzlxqwcphcoelnucjigcdqipktkjqbizvpebpplwsndysmoujqdlfuapftvjtvtkkqlczeyzlpexeogyitgouudrzrpxvusyjugnknnduvaxcgymbsrpalpesajdseqthklooidzrmlufjuujyhacraajnufszhjvawsplyxbgkpzbpdqendlinjvnemccudbyaiadmufbqwaxbnsmjjlddeehltnqwcbhvopzihcdnrxdedsajuqnckmegajtvevqceuzh\n", "output": "1927\n"}, {"input": "4982\nzdmkmeiphfclukdeswvvqautyrkqhgfekvlpnrqlkzvfcgbtrkdubkqrmiovquvpruvgbyilvurtnykwzjttlkraojnbvzddgtsasvgujuhdnwujaffyhscvixnlylykwrzjoljsrfmmpqawpsefecgwaeblcbglilmovokzxaexuzdprjflklvhyqgummlxaosjaxkslwtpmgfkqoflfjpegecsfmgyyxcquhdsbhqdllmdrofrgslzatbzzngkfgjvrynzheqcbaiblsgjoflcrdvqyjzwtkygoeaitmpflcwyuhvudlechwxqmvrxdtmroovdorhekgheqcmjfatzvdanjbvviujitrgtvynihjadcdtfnfvpxxctjugxaidzkjlvxvgnzyihgxeswguegjadhspcnybahuaibjnkustmcadtvzmnohwufgovwiotiplqgwtxtnteegouudcfeaktzxdaggwdhoiwadlglffzwtnlijzolwqtdlzrppldwdfeynjumpliswvtqhpmrwmrtspkjpxgswayoujmgibtteggshuauwogczzjvdjzphgmoksogsjrbhsjqydzfawlolnksasvkqrwjyjccmtrptootudhampmpiugwwpnpyvywmqskjpsjdbrsyqslqxjmybfrvihonzdrrtaqjqjhgfhlponekfpymerwuhhbdqdiyvoiayzkwihmfddrdnelxrprpvwstoromrjyqofxtvuekgykrvnpltarsanxmcjwupbhswzzszsmlazcuutzmhqjntgrukjoztudtoxsaclewaenvrwmdtktofbcqkzwooljfisavudeyktkbdyizpmxbmdnmynqrcnkjwlnemlrmgjacehwwsqjtgroyqpswoyumggklhgsllrxtueoytixyazldegganoditzeirazmwxnlfucmimbrelwsfgguxiwjtdbazoeqfraocewhzajtqobsnstqyjajdqyardomusxcccmxpxwouhiiqtqcdpbpzvrybbesulfdlwwmhfbeewcnzjdzflninvekeeiitweqsdjjbcijurpgrwzwyrjcrqevrcebibpwqdjjdtbablgnykgzazzihemezmtvidzrybwocvpmzlbnrusgagtzvizkppabnjguvqfihslgljmckbwexhrxknniajxutxcdmqnirnlaotlcxqndvwbwufynjxgunjsidbqzrujewqoqxnfaotjbieiisgalibajnyuruxctjxbxzegojqiqplyfycckezsiutaefsejqgxtyaxttxkflyvbxnqszhozlunrunqplzmdehpdgogaykrgftefzfqbuhtjpkpcwrephqoxykjxmcdgdppphsamzafsjkvatjgrjhceuzzyuvfiosymolviohhevlkpmbzmvqqarvesrupvqwpnlqpkvpnifxbbfpbrwtfbtjnldopdnawpeqpbywavsjzrrmtvsyruyypklifywksdnxinkfljsowsmrosdpsqjmuzsixpgychvlchpjdsromejqeouxrfvpoyeoqxjiyzpfrgdggbwgmojtzxwihdauppldaaksiwbylqzaoxagnjyfzatzmpywqizctmfuhyzkbveyzgbgppwyxqcntierilfnecuhouwnidylcwdwokwpqxxuowlagjaewhktbngkppahigfgtlibwjoirfbpsozudpubwzamkmxsllaiociamtlbliyiargnejavmwprxirsfjyjrtsavyoqrabsvuzkzfmbodzdlowenmvngqcixincbjcildnsqfdfmbehycanyzwkhlaxgqbjbnurlmsfpmwtsuvwvgyygjgtaclfwqkumxaechdhejujjqhkokhdgmhhuyzyisqoxhkcquozjcoauwepzexgwmjucntfzcgjyhguzcvgjjlmvigcmexkemljkiattafxvfeqmtuqypokgijaznpbjlgckggkjonfyfwxkudfftjicecpkjpicludfpruuldrhfqdvbiskajckiydgebmayhsutisybbfaaggjowlhdsgueybnjtzgnojbzrnlofzntddyldrhjqootkysndbfruikzerrzrzbiufrmcnfnesruwoowsjaqzqinrmthxjrhdonnxcclhzyzxzdfehjovtfnkpcsbyrpaknnylmmjtvquupzkpngvdmrdtcfagmloijqtlvcoumqvarcylcbabovhqmouashqzxhgnnbdpgxmzxsedcjumzuuobzxarlyfqsntvenrzguihxifazbwvwfulbgmcgctwjbpgiyoooxnteeudhowpqrbubwcmhkwzdqjqhvxbayfhhxizgbiakhjxeojasdgeouhmwpjgkpkexikfdkmthmqfgkkyppeszneitegpyarioxnwhsenxobgdhknuhdydgezgxbqkydjnzssvbcjvymhhegvofxiyqyttpqrsjeolhwhigdepclmgpnksxawgjupskqktfjmohgiyldspgwjfylwbclxcdmwfpkfgrormffphglwsdwltdsqrvauzrruatzkisxdaosmhpgwfqjntwvxoptjhgoxeqicsewllghzdwwqebdrhjjvqbcaeaxspswlztnafslaorfjhcxvjpgpmknatfejsgsdeuawuvslmprwlaciykisbrawquqeiyabxoqlopexiehrxwmyqxwglmwieimpveoevfdgiogsafoujekuwdcloodewbzyhslqgeemjxrjoghvtquddjbvviujitrgtvynihjadcdtfnfvpxxctjugxaidzkjlvxvgnzyihgxeswguegjadhspcnybahuaibjnkustmcadtvzmnohwufgovwiotiplqgwtxtnteegouudcfeaktzxdaggwdhoiwadlglffzwtnlijzolwqtdlzrppldwdfeynjumpliswvtqhpmrwmrtspkjpxgswayoujmgibtteggshuauwogczzjvdjzphgmoksogsjrbhsjqydzfawlolnksasvkqrwjyjccmtrptootudhampmpiugwwpnpyvywmqskjpsjdbrsyqslqxjmybfrvihonzdrrtaqjqjhgfhlponekfpymerwuhhbdqdiyvoiayzkwihmfddrdnelxrprpvwstoromrjyqofxtvuekgykrvnpltarsanxmcjwupbhswzzszsmlazcuutzmhqjntgrukjoztudtoxsaclewaenvrwmdtktofbcqkzwooljfisavudeyktkbdyizpmxbmdnmynqrcnkjwlnemlrmgjacehwwsqjtgroyqpswoyumggklhgsllrxtueoytixyazldegganoditzeirazmwxnlfucmimbrelwsfgguxiwjtdbazoeqfraocewhzajtqobsnstqyjajdqyardomusxcccmxpxwouhiiqtqcdpbpzvrybbesulfdlwwmhfbeewcnzjdzflninvekeeiitweqsdjjbcijurpgrwzwyrjcrqevrcebibpwqdjjdtbablgnykgzazzihemezmtvidzrybwocvpmzlbnrusgagtzvizkppabnjguvqfihslgljmckbwexhrxknniajxutxcdmqnirnlaotlcxqndvwbwufynjxgunjsidbqzrujewqoqxnfaotjbieiisgalibajnyuruxctjxbxzegojqiqplyfycckezsiutaefsejqgxtyaxttxkflyvbxnqszhozlunrunqplzmdehpdgogaykrgftefzfqbuhtjpkpcwrephqoxykjxmcdgdppphsamzafsjkvatjgrjhceuzzyuvfiosymolviohhevlkpmbzmvqqarvesrupvqwpnlqpkvpnifxbbfpbrwtfbtjnldopdnawpeqpbywavsjzrrmtvsyruyypklifywksdnxinkfljsowsmrosdpsqjmuzsixpgychvlchpjdsromejqeouxrfvpoyeoqxjiyzpfrgdggbwgmojtzxwihdauppldaaksiwbylqzaoxagnjyfzatzmpywqizctmfuhyzkbveyzgbgppwyxqcntierilfnecuhouwnidylcwdwokwpqxxuowlagjaewhktbngkppahigfgtlibwjoirfbpsozudpubwzamkmxsllaiociamtlbliyiargnejavmwprxirsfjyjrtsavyoqrabsvuzkzfmbodzdlowenmvngqcixincbjcildnsqfdfmbehycanyzwkhlaxgqbjbnurlmsfpmwtsuvwvgyygjgtaclfwqkumxaechdhejujjqhkokhdgmhhuyzyisqoxhkcquozjcoauwepzexgwmjucntfzcgjyhguzcvgjjlmvigcmexkemljkiattafxvfeqmtuqypokgijaznpbjlgckggkjonfyfwxkudfftjicecpkjpicludfpruuldrhfqdvbiskajckiydgebmayhsutisybbfaaggjowlhdsgueybnjtzgnojbzrnlofzntddyldrhjqootkysndbfruikzerrzrzbiufrmcnfnesruwoowsjaqzqinrmthxjrhdonnxcclhzyzxzdfehjovtfnkpcsbyrpaknnylmmjtvquupzkpngvdmrdtcfagmloijqtlvcoumqvarcylcbabovhqmouashqzxhgnnbdpgxmzxsedcjumzuuobzxarlyfqsntvenrzguihxifazbwvwfulbgmcgctwjbpgiyoooxnteeudhowpqrbubwcmhqlnhnomzbdhikusedtxwzvjmbkyevmnxmmpxzmqubanbadswichhsokkuvddmwkcsdoapryooonfvgwjglpkmjomfrpifihkkwybqvakcaxgxeqtuwwmnzrvucupeunelg\n", "output": "2030\n"}, {"input": "4738\nkebtduiuzrgmwblbrenoaedgylecgkcdswexvyhhhgkyueautmmzarptzqhqaptepoerhyqxhmeoxuckbfdoztylpmgjwhgsaxypguibcgbvdebtecidyxskutrypyddbhvrtgjqshhpphzcavjbajubffauvawvcklrnstszpqrmflswmuolfbeflcrfwgkmxaadqexlwbnywkrxywpaglhsoljzpqnenpqemrovphlbfaljcrhffyiezkzdrflcmzndrhnspoyojjdexfmuivjuwyurftfwwseudcjiiktukuurpdmsrvathpgzfwjtyiqfhjvcqapnujuwsewujmivpbdhpwjglqlfvdqcqbsnsybdgaybbxpsgucgvmmzbudsjqnsnxizsbseiacyxinfrnocbvimgxrpdmvvlxtquskpjtmirpvxyhpevxocloehjlrcrjmukjnaflugwpukkbjyudkajziszcnidnenitqifeswzvqscntwmpgxyyiicofvbmxagrllnkfhshggnheefpoeilwawvshsnsydvmcdczxfrcwkwoyoqwscascowjedyyhefksbtrmjokhqwruyhesohvogwedcbdhrgcbpjijrxiyraavzxtsxaiyyntpbkbtsievrbijtqqmkjshottvqkamotjutleuweeqidvwmvgwaplhjwtrewsyujqlnctevvnfsfinifvrnuntqboouidfotzmsuftmfsbppbildpgfhvnweczdwskdvjvzlmeosznuxwpidijlsonisrzspxvjbwudltkjfivqrxxqzxubfwtrvfetabettmzjfzfdrunbigljmfoxgnpydxguzkyxlaorqadnckucgrrxtekhfqwgbkmmampjkxsmcsxrwmueqjfxqjsrcwosagpioaetahryzhoeciszijlilachwryaamdwcvixeellewktwhkvcxpobvfidlczexcqepjnmhlucahbcsqidxpxbqzsstivwvhdmilyecaclxoxiuabcyswnpdymkkawirabjrcyfehyyeskesdcgambysbfcidehspsfvsekwrnnvxedcuvefjsgaplbmhiksmjapckvkfwkrmfqhhbfshhjtmvcdeizwikpdajuqgidjbczjmongpmdyjpibntanxwilwpuwikectduvzrkrcltqglhpsprdivvpyfaajcxuskooexycazavxrxllgahoorecqmwyyzhtwgghmgdnxiledhvvpedrojafworwfwoxnaxavvwutsfddhrxjrjlxcyllvrjcfwimjqudyskhguoeijkiqqfjdrbhdikewnncdlbxhnkkormzwwgnyhqzsparsovhyfykszitzeczabtmggiqrhebunygikjycnjnemyunklnwqsmkqkhhgfpusudmkehucperfgojrzywxkzmdabzohnshjmplaoixazpdrlvbdmwmdvchywcqqcvbbwdqcquboupklwrxzmfnfzlqjrmqproumfflvncgmsvpqeqobfjwhaqflkyyrkrvniqatlbkxoasftcignmrqkttxrpiwfiqotgdbrnmjmprmucdvhfcwzksngxgtncfoxvgcowekiklnwkstvbsvuaedhskarsgkxatcoxiztvrcxbrwpizqtbkbikfrretxsnwtyzkvdhpdxijscmjskihfycxgfmesxjaxmciqbvfwsuhrtibhxcpnzdxfwgqkbjgxetmeekdofwceyronktwuajcudsjsyceozajwixbvjxnehhqptntspnwoictwzlgsirvnbzlsclnzhluorlnuwtpjbyfobvnuttjfwvcqzphgbnrcryidinyrpladsxofyvxjyhapxslbwrnnvuhvqdgnzcigyhlzzgdpxnlbycbsfqocfhsqnndmrrapctoceyjtbyqrcxyuhxowsezglddadoaiymeytvnmhpmszfruvisfivzgqgipuqwmeyuotjrhkefcyvqpfhtlkwvheszyfgsvmaqnmbcietbvcadvsbvvxtnwcqbkesqagninegslbxrerexqqxdmjgnphinprlekkhttykefohkjggaqdysaqxkmfctyzjxdxskrruvbwxscizxswjwhddhsvcdbhyrjncfvhkvrrxulhjxlcvtaahqddewwrvuzfeunfeevnqoydoqzlprqgdvefukuvvdgsvofznssjbujugydzpzhythdljwyemzekcilleavqszdpwolvscbxytzfhhrdecrdlmyqkrbszmidnxlmaedislzrszpoypqesouxqlzlrrhcwnzixyksodqsveyxvcyrqnuffngoswllbmxnwhqytubczhgnhnjspqwnuirrhlwhwpvokixmtpbececrgwzjcnwqfyowdeswgoywtoyesrwkpdhzpdpcggcrdtotkhmcbuqxlicdhnpevytvrwazrksqmqliazxvomjolsrtduddcficcsshxmqeyhjfughqlrapulzrudokcarhuvxiqafdgkzhfwqagycggvrkymasjozamdkzxunrptilhgwqzsvaovukwpkfcjyhpvxhnptrteopqtueuoeusdilgtshsexdrcewbozurtrfnnfohmbkchzswnwovigvmwjibhhwdnyotgudlioizheagfitqbpvluypdslwfwyretbvehprmzwtgewlzzbbrklcyifqzpnmapohrauuzfdhwgiosxhleipoapzmvhrnccydsbzgoqbqxzprfjuvkgjkwcwnlkbphjlrlgzwjuxpaaboeqldsotaneiaiyepzuilgiylsmwhbwbdrxxhfgzmfhiokbonmlslblswxksfulsibnfellgfqbqpheljltzhokexnidpudqfqnjvildnadoxysagnpfwjkhpoqectrybshsxxhmnxxfittuzksdseczfcxdywctahyawzoigwtqjatlrtprfsglrguujxipzxrncdlbxhnkkormzwwgnyhqzsparsovhyfykszitzeczabtmggiqrhebunygikjycnjnemyunklnwqsmkqkhhgfpusudmkehucperfgojrzywxkzmdabzohnshjmplaoixazpdrlvbdmwmdvchywcqqcvbbwdqcquboupklwrxzmfnfzlqjrmqproumfflvncgmsvpqeqobfjwhaqflkyyrkrvniqatlbkxoasftcignmrqkttxrpiwfiqotgdbrnmjmprmucdvhfcwzksngxgtncfoxvgcowekiklnwkstvbsvuaedhskarsgkxatcoxiztvrcxbrwpizqtbkbikfrretxsnwtyzkvdhpdxijscmjskihfycxgfmesxjaxmciqbvfwsuhrtibhxcpnzdxfwgqkbjgxetmeekdofwceyronktwuajcudsjsyceozajwixbvjxnehhqptntspnwoictwzlgsirvnbzlsclnzhluorlnuwtpjbyfobvnuttjfwvcqzphgbnrcryidinyrpladsxofyvxjyhapxslbwrnnvuhvqdgnzcigyhlzzgdpxnlbycbsfqocfhsqnndmrrapctoceyjtbyqrcxyuhxowsezglddadoaiymeytvnmhpmszfruvisfivzgqgipuqwmeyuotjrhkefcyvqpfhtlkwvheszyfgsvmaqnmbcietbvcadvsbvvxtnwcqbkesqagninegslbxrerexqqxdmjgnphinprlekkhttykefohkjggaqdysaqxkmfctyzjxdxskrruvbwxscizxswjwhddhsvcdbhyrjncfvhkvrrxulhjxlcvtaahqddewwrvuzfeunfeevnqoydoqzlprqgdvefukuvvdgsvofznssjbujugydzpzhythdljwyemzekcilleavqszdpwolvscbxytzfhhrdecrdlmyqkrbszmidnxlmaedislzrszpoypqesouxqlzlrrhcwnzixyksodqsveyxvcyrqnuffngoswllbmxnwhqytubczhgnhnjspqwnuirrhlwhwpvokixmtpbececrgwzjcnwqfyowdeswgoywtoyesrwkpdhzpdpcggcrdtotkhmcbuqxlicdhnpevytvrwazrksqmqliazxvomjolsrtduddcficcsshxmqeyhjfughqlrapulzrudokcarhuvxiqafdgkzhfwqagycggvrkymasjozamdkzxunrptilhgwqzsvaovukwpkfcjyhpvxhnptrteopqtueuoeusdilgtshsexdrcewbozurtrfnnfohmbkchzswnwovigvmwjibhhwdnyotgudlioizheagfitqbpvluypdslwfwyretbvehprmzwtgewlzzbbrklcyifqzpnmapohrauuzfdhwgiosxhleipoapzmvhrnccydsbzgoqbqxzprfjuvkgjkwcwnlkbphjlrlgzwjuxpaaboeqldsotaneiaiyepzuilgiylsmwhbwbdrxxhfgzmfhiokbonmlslblswxksfulsibnfellgfqbqpheljltzhokexnidpudqfqnjvildnadoxysjyfrniiwmehivnniygnukdolcttylvidodyjjuvpqvcqamqhgkekccnxxgzwwdvzwmgctpgrwrwtkekjaxymnfxhpblseebbl\n", "output": "1600\n"}, {"input": "4884\nxvizvmfsxvzyhwggqdifknbsyuvlckqzidahhamqmbyqwrgbpjgevwctbazmbxqzlsxloccpeyavjdlfhvfeianermljlvyhlwlumtqhknxdbedxgnlsmakhhbecdxqowbbqulqqpwknrvyojuwurxphxoaoawxfeiueypkvjnbntybflvpslheqjrpuunnhmcwmihvxzgarzlfzqgtkpsxuiyiccuhzrpeiyztajrxjqaoxtzuakznqufsosliqtiwewcpgnumrmrwnndcowiyhswlbchefoayaojciimhrsaickpclmnbrhzvuqxlodnqkdooxxefmpuzgwxcewckhnjpzmtlthrwfftpvkiemfvhnbnypudlqukiyufgywwhginumjgztcisgjqrqlywhflksqgjklossloltnpnbgvbvhbpuatfshhqacsplgwtduljpgszmznnhhahqyhljwtdwhozomfkbhiaawbnbhvsfrdhhzjcfsemujnogglercthwsurvbdxnpunfqiuzvytoolsbbkyuyovjftnwwuqrjksnbofwatauobjcwtnmrtmavzxcaejgmdldysahlkstqkglhjbjijespejwndkvgksbdosmtkobnmlohkyqonwlfvgnwypcagjxmieiptkpbpmmmxawndpopcifqompvvpbvbqptfiytljycoyddxdixxihpnglxhvvdesrbltmupyhadllruijxrhbhvvqkvdsawnlnautowdjrvbbewblhhdddvjbifrgeupmlegszjtcfhpugqjxccsagqthgzenelpyddnabirigpeezhmlkcdduemuxhpcxutdrgnnjrbmnnmrihzlnflhbbmmqzkqxbdcuzgzmxlrfrzsjgenqvocoqmwzptlhlfaxlvswgwpcjxgydvjglwwkggryylububfstlzmrurovptnlzfnejlzjmfqofsvcttlvmbxkedkiuhqypkesiehtogjilxyqmbvnklznjrhoudtifmqkcqxdczcrljvnyydqapkitvbdmkfczutperyyulyjysqxgopzndmpolrcrgpuqhhdkxiulqxklbxrnfxvlkcyvxnmvfvsvnkewbfdlibhsvexdmshniboxshbecpqaszepqakuasopodnmwdgjgjxiaqveoyinglynyuqtbrrznwtedmdllhuyjnpmtgypuqvtipfbzrmnhelycpemxelaawgtfullzzfaknxguiztynzprvptoqsjgtyxjlezcsveejpbndktmzylswpudzvnhyrhutxvfpndhiiscnweffmtmlbhlbesmpczycmacezcikmzlchvqchoufnearrvzaqvpzqpirdlovbiyqskyakwuqbrqqvkazlxcypgbchuxkahdyednsizgmgopyifvjubcoiruyvzbcsgwujreszalqruqyjkkllzlyyqnjmcmjfmyqdjucmnungxmrdndpmobzrdizwnxxnxisvpnxdifnjfelgszsaexwdyxdxhhxtlsotnhsglwgzdigsqkgwkcwrpwmyywiovoijggkcwdxnkeofgebqawygfzumtwkgkbjzkliilevnqnciigyoghqcffijfwlrgkfjcdhzdzepbldigxcswicxhknqizaugrxdrgivuagyihvxvzrousfcuxiogfiousiydbtqlmeceeharrbwudxritqzstxnecymodbosodwdswefextvvpengersvlysbdsjokysgtjqpedqwmlfzanyywwhrhpcoyxleebupobjmzvutwcpxqeehrpsukcmidrsbghbrbayxugtzgfrszthevfcfootpwyqmxjicofmxdlcbinvzcpvwrkwdvgbdtdcwrnkpoxanohoockxcszbshxxtgcktskbrzztfaaqyfkzgnizjjzsytbokkmtshmxupamanksboprgaavhrnwchnnfztpcxygyhnumasehvltydluzuwldfummjsgzqppjqhfyijulxuyssxorjwgnnfksxtbavmhbpztbgnitkyktcxtzlwyzmafbgqkkfaimpwobkovbdglygpumhtfgwsstaofjgxgbynzwmfnygauoifavddtcdjoznsypkeuhqgjfrjqivktnqulinindwcnyosfbkalupovzqshekumvklgpwxcdktlgsakdqphtxuwkhzpuszktgknwamowypylenaektayekbdsgzyjybizvvluyhqmcynpysfwrchxcvdnsrhujzxjvurrfcspxdclvlmngmovvogjffvowhskuyijqxzcamudavyklhhilvpadlxeueteiwtnbrgygezgplfubxhwulzbtraupiwigkioevhjctduelesoqizfiaoovyklveztwbalncjiljsqrjkptfcnmjvshdutsvpjglwwxqxykqynqucudjaolgtocqqutelaarmlahkphqiotahraswskpnxromaybwxcpmjxgmkdwiecuqauaaawxmvivopnmuernrowqrjisqtfirhcxudpzemghxysxtzxsylnzukfmmpgoauzqpxmuzhxxkitmhokzbinhbxbqjfrzgkpmlaejpgblbzdbfpjiuvvlomcclwoiozesxlzfztzqwugxmszdgimbnxuqxksbgrzicsplmcwhsrpcawgqwjxqiwmlznnallesiswhyfumouhdyevnzcdptsyrjjryhkcltipmwutneckifszglcrlpaqvnnriucchbelsoqiefgywwhginumjgztcisgjqrqlywhflksqgjklossloltnpnbgvbvhbpuatfshhqacsplgwtduljpgszmznnhhahqyhljwtdwhozomfkbhiaawbnbhvsfrdhhzjcfsemujnogglercthwsurvbdxnpunfqiuzvytoolsbbkyuyovjftnwwuqrjksnbofwatauobjcwtnmrtmavzxcaejgmdldysahlkstqkglhjbjijespejwndkvgksbdosmtkobnmlohkyqonwlfvgnwypcagjxmieiptkpbpmmmxawndpopcifqompvvpbvbqptfiytljycoyddxdixxihpnglxhvvdesrbltmupyhadllruijxrhbhvvqkvdsawnlnautowdjrvbbewblhhdddvjbifrgeupmlegszjtcfhpugqjxccsagqthgzenelpyddnabirigpeezhmlkcdduemuxhpcxutdrgnnjrbmnnmrihzlnflhbbmmqzkqxbdcuzgzmxlrfrzsjgenqvocoqmwzptlhlfaxlvswgwpcjxgydvjglwwkggryylububfstlzmrurovptnlzfnejlzjmfqofsvcttlvmbxkedkiuhqypkesiehtogjilxyqmbvnklznjrhoudtifmqkcqxdczcrljvnyydqapkitvbdmkfczutperyyulyjysqxgopzndmpolrcrgpuqhhdkxiulqxklbxrnfxvlkcyvxnmvfvsvnkewbfdlibhsvexdmshniboxshbecpqaszepqakuasopodnmwdgjgjxiaqveoyinglynyuqtbrrznwtedmdllhuyjnpmtgypuqvtipfbzrmnhelycpemxelaawgtfullzzfaknxguiztynzprvptoqsjgtyxjlezcsveejpbndktmzylswpudzvnhyrhutxvfpndhiiscnweffmtmlbhlbesmpczycmacezcikmzlchvqchoufnearrvzaqvpzqpirdlovbiyqskyakwuqbrqqvkazlxcypgbchuxkahdyednsizgmgopyifvjubcoiruyvzbcsgwujreszalqruqyjkkllzlyyqnjmcmjfmyqdjucmnungxmrdndpmobzrdizwnxxnxisvpnxdifnjfelgszsaexwdyxdxhhxtlsotnhsglwgzdigsqkgwkcwrpwmyywiovoijggkcwdxnkeofgebqawygfzumtwkgkbjzkliilevnqnciigyoghqcffijfwlrgkfjcdhzdzepbldigxcswicxhknqizaugrxdrgivuagyihvxvzrousfcuxiogfiousiydbtqlmeceeharrbwudxritqzstxnecymodbosodwdswefextvvpengersvlysbdsjokysgtjqpedqwmlfzanyywwhrhpcoyxleebupobjmzvutwcpxqeehrpsukcmidrsbghbrbayxugtzgfrszthevfcfootpwyqmxjicofmxdlcbinvzcpvwrkwdvgbdtdcwrnkpoxanohoockxcszbshxxtgcktskbrzztfaaqyfkzgnizjjzsytbokkmtshmxupamanksboprgaavhrnwchnnfztpcxygyhnumasehvltydluzuwldfummjsgzqppjqhfyijulxuyssxorjwgnnfksxtbavmhbpztbgnitkyktcxtzlwyzmafbgqkkfaimpwobkovbdglygpumhtfgwsstaofjgxgbynzwmfnygauoifavddtcdjoznsypkeuhqgjfrjqivktnqulinindwcnyosfbkalupovzqshekumvklgpwxcdktlgsakdqpkgivxqouslzldcgrtmsulqbzjmwzwpkldvaqkpybewzsttkbfzyqxqiviljitmpsggjnrlvjilexzhgywitluiiqdolsubhznwlianophkrukernctgeykqhapkdwoppuckavwgcfjcrunzhphwrouihdoquevypmqxxgexsegtzkrzkawfklkknlkhdroytydigprojttlsbyyoghgcdtpuakgssxbdcbl\n", "output": "1845\n"}, {"input": "4754\nxggoelylpwagmuepcbswnzknrqwhxuuhvwqqesvxpdjgmfmetbmkdqfpybcbucurqzbwplnclefctpbpelfqeltrgfijxmdaomuysbrlnfrezuxuakdsyvmmehbmpefgpxyywloezjlwvvfbrzxtjkcwrzuhiseieylyhtclfwbrsvepdqakaemzrjtsteiqcbzhrojzlxlpomwjglgfoljselshoukmzundmkmuaxznfjdtzlpgrodafznlpfvehpsurtefqcfqgcwlnjqubanbdrczykhgbzstlmjpxkueplauqlknfsimuojwfvxeiowraqdwoiotcuvvhjhocuamsmcfyuulqdkohfjyamstxdhtfizesixrvvoxwsibzkwvhdsqzaapaklpczxlvzplsqybzsnvcngaqdutfcqwtguieenjalziumgpfigqqowbwaddjqqwvxmjnrrhydcpgtihfezwfbcgueweuyqmbdaeuhrchtcregvwulivlglvynjjspedzlokaztolvooqhcnkhvapqlowctdwivbroyhnfznzrebpylekzebojyoeypgibnquqfpwhyeohwkhqamooxkmmbfwvtykctqeyuxgwwvutgxzwslokfldpvxcjlmjutycgtuvxiimagmeoudwnosmgabdvxzuvrbnymgxctjacedsyydkmzjevoedibbtshvxgunuzraewzgpumweitvzeaihadmykbtqsiebhijdnhowevwfxmyhzbeeihphrdqlgcufbbfadkjrkizxxwpvzbmemcrshsafludqzvxjctsqntomrwdwmzsnedudhehsbsgvrmlidznxnwipowwqfhrpbqqntawgkanwagbsysseiyjnowmlcrgxcpyqhspatuoptkegnryvpstwlikipzmgdrzqnowtvlsywcsimfifhwlzswmosxtkylxcbmzbirofjwucdwdqesqizugtxjpculcltkuozessdipbgwvnoxexxzopweqpinlnukdhzjmojqvuytyxwglwffgtiupjumfiqnjyodutboeppucofpozixknbnbcqbupwlclgwasnjfgwayyjzegtinkqscbhgcpptxankkncazuspdmzevczolxvmwmmrgkldgbguhaffiqdkhyvczhdjlwcdolmtyxezxweblnkmobpxhrzknnbwehwybksyhwvfoyzhoqxyykgyeefvwtthmvidfzpfotnrfmsadjplgazdymjvyumcjhtalqytajerkgtfttpysctwzwxudwjbabzurydkoryeoocxsmhyqwetnxylmqikzrmsphbgrkjwjxiiodjnmrnjreehqqbnwgstfwwgwjuqabahieodchbcohziforhrzgcfxcfxxqiljtajzxtlkoiokwifiyeexjybkyxevqqvufhhukpsnssymuwbqvvzvhmqfjqunuujyidqrnmfjmlqttjeahthqpeyelzaouwcdmhliznswmnworvgxqqkjedjluxcwnshegtvuhzgcwhuelsphoqxucrsfdaqdvbrujruzzbpqeaktyfwgatlnlkqqzwtwjdgjrmttdowvqlihgpupjkutbvhrukckcxxrbzglcnetotrtswjfbeyhbbghmltlwjlzrhjkbozwdbtpwejcasudgzbzhdykzftjgspiofhgebbuoikkdwwqwwcxxcezacaecnupejcpwfcetdbhhzjyxevjaztrywoiixvkhkuejmtvqzdqembaziyqordbtvmqzszutamtpgtyjfcwzthzphrdgaaeyveziwgjmngwkaynnqgdxqibcrbqtwzxhssfpujcxyuvkhkqleywwvkqkbzpzktyspiqejscuyjquxvobrzshsrwovangeullnciahlfnqwdthqmfgjdddccefmnguotuwksyuqxwszdrpuicutrmrnxogxvsoamnrlxijftzagwyfscctvfyugfzztlrkvnxgltotoqodyrpfonkpjapxtfiwxqkwfeoxrchkuoilsepzcildmwecwtjterftwyduidwwntpnelypbzhwjzkxxjemwagmdkkzkfzapowkumbolecgdlpihhchipqbnnvmxyoxfgiexbcexthtndonrvgkdbtcautsgnadubdrucphrkbyuuqkdtiehdsoqynrxuosydplneqyjpoybhxabuenkpcbmhmahtsnyjdfkhpcvfetwuzbsgityblejosfjjwvwqlsegyjzyoxmxkumbkdgevetixqojtiiuxdupoedorntrzkmueapljrnpdznwaiyrtqmmzfqcpkvkvrjalcbwajxftahwnawchdwrxssdiubtaftplxxdqdbzaxjropmdjbpatuidbjanfaummomzneulajnvkzfcgocbaivadewgdntndmehmmffuibxugrjkpbvozhbiugowhtktrbvblkpguowohiqixqsmnsjarmqcaszedjngqbpueswertflsobkkqcwrwijnykwnfynhnjmvwtrwnbhmsqisgqgxllergzsaoxwaliglnecjerimahpwlstzgaowxvnieetbdcmnvkvmzjkescozbpooxavybgbootvmludqqzajcneknfjnlfyviowbeqawmrjpuzvepeuvhwvagcsrgeyutfqizkzyovzzdlizenktqhoujkrjkvrzcspggtjfiztzuutrpcyxhezembydjpuldvlwhvouwdizvstxqiarchgbamraiqxjdascafbsukyfniqqrmpisvgnxznpbpsgwwzyxiegbtugntxoalitpgpfggcvioovgnjpoobjpyhyuhtkuabyvxyogjwwnrshmqyporxsdzjqtfmohkgjzpocnmciixkrdaznadpvnrujvukqmkcngcxjfjrhnpgxzplvwndrnxfblsnyqagxgkhuzlpcpdvrklgfwwjgnlisxvaoxzuzocyjiwtuyfcejxodpckyhxodeuycjzsbwldsqttxpsvhfhrnzengpewhqxjpjwfciffhlqdlotkgiwyjxsavunnediifhhapyuzgwlsxlswdjzkmainpkyqakzxfdrtocrrxkalwkzljqvncslaauhmkkierbewbmdvbhfhibdubdvmwnajfgleqrdlrnnghxgqiaoniybiltssergzbzhdykzftjgspiofhgebbuoikkdwwqwwcxxcezacaecnupejcpwfcetdbhhzjyxevjaztrywoiixvkhkuejmtvqzdqembaziyqordbtvmqzszutamtpgtyjfcwzthzphrdgaaeyveziwgjmngwkaynnqgdxqibcrbqtwzxhssfpujcxyuvkhkqleywwvkqkbzpzktyspiqejscuyjquxvobrzshsrwovangeullnciahlfnqwdthqmfgjdddccefmnguotuwksyuqxwszdrpuicutrmrnxogxvsoamnrlxijftzagwyfscctvfyugfzztlrkvnxgltotoqodyrpfonkpjapxtfiwxqkwfeoxrchkuoilsepzcildmwecwtjterftwyduidwwntpnelypbzhwjzkxxjemwagmdkkzkfzapowkumbolecgdlpihhchipqbnnvmxyoxfgiexbcexthtndonrvgkdbtcautsgnadubdrucphrkbyuuqkdtiehdsoqynrxuosydplneqyjpoybhxabuenkpcbmhmahtsnyjdfkhpcvfetwuzbsgityblejosfjjwvwqlsegyjzyoxmxkumbkdgevetixqojtiiuxdupoedorntrzkmueapljrnpdznwaiyrtqmmzfqcpkvkvrjalcbwajxftahwnawchdwrxssdiubtaftplxxdqdbzaxjropmdjbpatuidbjanfaummomzneulajnvkzfcgocbaivadewgdntndmehmmffuibxugrjkpbvozhbiugowhtktrbvblkpguowohiqixqsmnsjarmqcaszedjngqbpueswertflsobkkqcwrwijnykwnfynhnjmvwtrwnbhmsqisgqgxllergzsaoxwaliglnecjerimahpwlstzgaowxvnieetbdcmnvkvmzjkescozbpooxavybgbootvmludqqzajcneknfjnlfyviowbeqawmrjpuzvepeuvhwvagcsrgeyutfqizkzyovzzdlizenktqhoujkrjkvrzcspggtjfiztzuutrpcyxhezembydjpuldvlwhvouwdizvstxqiarchgbamraiqxjdascafbsukyfniqqrmpisvgnxznpbpsgwwzyxiegbtugntxoalitpgpfggcvioovgnjpoobjpyhyuhtkuabyvxyogjwwnrshmqyporxsdzjqtfmohkgjzpocnmciixkrdaznadpvnrujvukqmkcngcxjfjrhnpgxzplvwndrnxfblsnyqagxgkhuzlpcpdvrklgfwwjgnlisxvaoxzuzocyjiwtuyfcejxodpckyhxodeuycjzsbwldsqttxpsvhfhrnzengpewhqxjpjwfciffhlqdlotkgiwyjxsavunnediifhhapyuzgwlsxlswdjzkmainpkyqakzxfdrtocrrxkalwkzljqvncslaauhmkkierbewbmdvbhfhibdubdvmwnajfgleqrdlrnnghxgqi\n", "output": "1522\n"}, {"input": "4763\ncoyqlqfbmlfdxipiqrhjowqlbhkqfysgtnhwqqjukzptnvizfseyhvicjfsnlqqbyfxbqrxwpmfjonpkwfnrnaqokvsunenkpuyfuahclsvgbeznzebvigppdvktjjslmtjoxxblyhfdfcaugpsqojmijaekfnrgntltwmgjoejnquqoxabmbxtxwoqkfaozwcqxccykqmnzuhotdrzwsfsuwanqmihehagoslgzvrnekffhqjaawgvjcpeoiykslyaregxvnfimzwtrrqmvfgwyhfpckvbfmfxyyjnshrcmfhegfntymynvzaqjdthsappxdzsshkrxijfiacqubkplslcgrvcoymgbafxefcchvsljkhrfblnrnesxpzmwxupwulmkripaqnqxotlnptwdlnpgsfipgsulzppkgihvdtrixbmeammhtsbgdubqjhtacmoiedbuqngvnpjoiccoxuslgafgmpnbefogmrmkhuolkzpbsvgjmvbqncrwzcvzhzkdcouzictpoduybnsbqrpekgmltogiwilgmfacrrdxaykthxdmqcijklmrxiuuqtuhvpjscinudjcwmccmxxwshyjftfpknaemmdpnvgiwhkzndjmblhkrdnfwdrxrdpsikfennzkbnxrchudmuohazydqezdpdrovizskpwjyidyfallmzwpispyflcmbtpicliwjtfsustdjijadimkyumaeaksdzdnceivvhuonpfudkktsofhyyridnlnrrdodnmhdaxvhbpbpnlfskvvsskrlnbkonebzbvzzqarvlsarniaztlgjewzxvvkbnpwpityvytjgqxtkzfbtajicwwwmxkdlqqeeskighposumsubqekmlgzwgprtiqyarekkxbqdmwculmojxblgwzkugynqmvyknypnkxmsooskxjnygmpmpbsnfvhzfgxddqwhivefgyksieznyfkwngcdiafidjktefiyeyqznexuricsxebhxtawplltmakkjzpdvmsgzjgqdllncuglkpuvoeqpwbnezdjfgkucjylcsxxtizfnjotbcwkvehlklipagfeoqpgpwlyrfwuoseqqvhcthuhxdkmhgdznuoutaeqhrpliqyxjswzzbeufqfwgocnjnwovleanyuydlfeyuqtiruuvswfpqyvitwvpxhyclwenvzcfnbuomhwwfygtzklxnvefoqsppsvrhywobvkeknouolittxbweyaxhfikbjsuufoppfkjvzkhclbovdtdkqyhxowzndjzapgkopfdftifrjrqixxykywjwxorjwkkawpiuvqozborzurhyeddsinacclziombysolzvvdackyrmubxcgikjlkwzeqqcylcmdjilwdmvvxuvulktuapduglftfwxdeprwbwrmoqozigubeztawyyxunlinelpdetbovoxivzkxrasqypleqtbmcbsthtynhmmofiwmnspnsjfxnsdyfpaijtxhsfgeuphajasxqzbskjjysswhfiymtcexajkulxoitbrxwmijldpazgedcygaakgwextwswykfjrukqfivrbntvqbxkljymlpfzxehmishmsbrzmbnizabjrkdxrnwtdwxttwfmugppzxhfxiojhfrsxiqjfqpfvapqqsoryixyjchhelmedklmvhfaxldugpkmxwmbbbmrjawalwchdcceiusjnnwdcreutgkakjpkraqgwqgyliilqkphiixoldbupvnvbeejbfvcsfqvueoxbfieljrsgggkdnhjlphuqhdkzcfuhcnjjtjbgjeqlcnpcjniulzweozgtaybumnqvfmszyqjixuceuraeybtmlqfdhhhroqosnihwsmwzubggedkqrvgjxoscforpcjfsqltxptgcwmjaxgfrkrqjkoqescxxvobylldaatmzfvdcotxjxqnsinpunmnljbfrlxbwqqstdhwicamskwhymxriresjaesnpmxblxuhbknqvfvpvysgjameasnmtvlgmegjqfrvoxdinevvexpbnephfialtsyxhkntwchbmxmhifqewnlywybkjqpoagpioivyzchcpittpkyabedvjlwigarlwvprfabuvccwmqygxiwcxfnsdtwboohvkicwpugzqlykqplnrtxtvxzkadwrsdhrhcztfkdynbnrdssrftdryaevaypyiqpdvfewboawxyapxencrxayiaacmszbozgvhjncvbodmtgelhunkydhkwmslhrjgjuwdhivgnnnzrtxwmwbwylxuvxblzheieqadkbcgclnfcldacbsqfuoghxrcldsuevogwqrezxuwkzggfryruougqssfwhwfitdntusffksscpqyvrhvieccisdnvbmpxtvtntjemkdaomtakowetxrfblnrnesxpzmwxupwulmkripaqnqxotlnptwdlnpgsfipgsulzppkgihvdtrixbmeammhtsbgdubqjhtacmoiedbuqngvnpjoiccoxuslgafgmpnbefogmrmkhuolkzpbsvgjmvbqncrwzcvzhzkdcouzictpoduybnsbqrpekgmltogiwilgmfacrrdxaykthxdmqcijklmrxiuuqtuhvpjscinudjcwmccmxxwshyjftfpknaemmdpnvgiwhkzndjmblhkrdnfwdrxrdpsikfennzkbnxrchudmuohazydqezdpdrovizskpwjyidyfallmzwpispyflcmbtpicliwjtfsustdjijadimkyumaeaksdzdnceivvhuonpfudkktsofhyyridnlnrrdodnmhdaxvhbpbpnlfskvvsskrlnbkonebzbvzzqarvlsarniaztlgjewzxvvkbnpwpityvytjgqxtkzfbtajicwwwmxkdlqqeeskighposumsubqekmlgzwgprtiqyarekkxbqdmwculmojxblgwzkugynqmvyknypnkxmsooskxjnygmpmpbsnfvhzfgxddqwhivefgyksieznyfkwngcdiafidjktefiyeyqznexuricsxebhxtawplltmakkjzpdvmsgzjgqdllncuglkpuvoeqpwbnezdjfgkucjylcsxxtizfnjotbcwkvehlklipagfeoqpgpwlyrfwuoseqqvhcthuhxdkmhgdznuoutaeqhrpliqyxjswzzbeufqfwgocnjnwovleanyuydlfeyuqtiruuvswfpqyvitwvpxhyclwenvzcfnbuomhwwfygtzklxnvefoqsppsvrhywobvkeknouolittxbweyaxhfikbjsuufoppfkjvzkhclbovdtdkqyhxowzndjzapgkopfdftifrjrqixxykywjwxorjwkkawpiuvqozborzurhyeddsinacclziombysolzvvdackyrmubxcgikjlkwzeqqcylcmdjilwdmvvxuvulktuapduglftfwxdeprwbwrmoqozigubeztawyyxunlinelpdetbovoxivzkxrasqypleqtbmcbsthtynhmmofiwmnspnsjfxnsdyfpaijtxhsfgeuphajasxqzbskjjysswhfiymtcexajkulxoitbrxwmijldpazgedcygaakgwextwswykfjrukqfivrbntvqbxkljymlpfzxehmishmsbrzmbnizabjrkdxrnwtdwxttwfmugppzxhfxiojhfrsxiqjfqpfvapqqsoryixyjchhelmedklmvhfaxldugpkmxwmbbbmrjawalwchdcceiusjnnwdcreutgkakjpkraqgwqgyliilqkphiixoldbupvnvbeejbfvcsfqvueoxbfieljrsgggkdnhjlphuqhdkzcfuhcnjjtjbgjeqlcnpcjniulzweozgtaybumnqvfmszyqjixuceuraeybtmlqfdhhhroqosnihwsmwzubggedkqrvgjxoscforpcjfsqltxptgcwmjaxgfrkrqjkoqescxxvobylldaatmzfvdcotxjxqnsinpunmnljbfrlxbwqqstdhwicamskwhymxriresjaesnpmxblxuhbknqvfvpvysgjameasnmtvlgmegjqfrvoxdinevvexpbnephfialtsyxhkntwchbmxmhifqewnlywybkjqpoagpioivyzchcpittpkyabedvjlwigarlwvprfabuvccwmqygxiwcxfnsdtwboohvkicwpugzqlykqplnrtxtvxzkadwrsdhrhcztfkdynbnrdssrftdryaevaypyiqpdvfewboawxyapxencrxayiaacmszbozgvhjncvbodmtgelhunkydhkwmslhrjgjuwdhivgnnnzrtxwmwbwylxuvxblzheieqadkbcgclnfcldacbsqfuoghxrcldsuevogwqrezxuwkzggfryruougqssfwhwfitdntusffksscpqyvrhvavqxrgikihkxnhreofptvyrqeksifxaoiwqewawiavpveqkkgbqwjokstiupbugnrdrxuknqrjkvhowdxorrquxzebbmqgrqbqhwcqpyorxytwwhahewwgyurmtxcthuwysplqbgbywheznhaliccabrtqsgayykowtkhkagkqifhjdqjkpyuxmsjavoprnqmjlcwegkevfdwxjqxeeskjdofjnwqcdshuqblylgtyvcdbjerskyqchzp\n", "output": "2055\n"}, {"input": "4970\nuognfalfhmkbguspimjkkucnzepivptsoqvfkkesxakijgmcxtjejjnfobfgumgmherhfgotzspmlgjqkxhuntkvdyjlkqernjyqzunawwhpqbfkkbefqudeekxlnimtulxlgiixzyiybdechwwjberghvyudatzprbmixycdmboluzitigsoeplnfkxhqnhfjmdlvtmjflnuvcybxfgqrjgzbkcewbtkpeeerrhgtqvhlaykjqyqxrscynkocrtngkbswsqbysfruqokdcdxjchimhkbyjxtxpohunwutiyoeznrkonqllrntitknoniaxzxxblpjtigkmwejghkpcxngzeiznyojudtyvdfsfezrqleqflgbrmlxiehjdmqlfjqatyrlwiedowbjvxetbomdhlthufelavmvtbrznmauiwhntxcvfvmrmqvrsialynunkxdcnzpfytxmltlwrgykhyqwhwclkmklomkisamtnosthdtyteyjarudejikzbezurqltntwlymcugzpafstohnleailsszbezmeoiyajpfqhemohpdhxbmitpfjefwjmufajmfquviavaemhvspeeawxojpirtjeadhvaslatstuedhfokroklftpyhlstirhgaeilztfbqqmxccfuokjmesqnrdmilqytvzvegrueimwfkivebxcsimbftdurqqhomkycjqhfbjwpsxkyamsskvlwullhceifxlawfqacqgmbufjrnpuhowqasndhudegrkxhcjthkosdprshmkgaxcvyfrojxdlzefltrthtnxvvsxzzvxgjnvyegrhfxwcbahewrdhdjtzvhbfdrmpcyzfgmslmajitkwjkeofbatzlarzlglwijpeczeypszjvtzpgymtnflwmgpcqxfjuxbnadtwfuondfrshxloqlkwqujdhrdcraaqizqgftshykmxtoqbjkdjgwiplaxaakbmthufcfahknqelaocgrawjsadmmkrgwfpdqznjtxyglctbwvfbijtxlsxifouibfazfiwaifrnwiuzsqzntkcgkmmvwrawpwrfhptwwqplygpdodbjzrxdlssisytcnnqrjydrxjzwwuaxnahtdyimwutatchfdyfrulgvltqljimfvivvwtvzaestorfmxbwxnanbrwbdzcbonsiewpnuagejadkbghlvuxcuemawsrnsgptdtpolwdvxvvsodqjqlnfmqexczjzeeacwnvxckrgqlevqbhierubfcpzojnsqpibvrzhgpjzgvwwwzbrqbwzgtvksuaqeswxvgmozszuixrwocsdsnmfofadigwmidovfojmodtaadqzwpwakxxrrevdogtpimfppawbyitearebrukywcrgsebycrdzettrpmfgziljuzzdgqelgevlxsycmzxmrsokschunszhkxtinlxoywalsrocfjuqtpftdlaohomwuklsersujdevwngbctsgotjgpgnojwkshqejqrobtzbmofxjjhgdbuuhfelypngwzwwgeacorijxqdrouujppzdhurelnmypyimfauvqcxbkgfcxktlzwrmvjjqnbdgvzvipmvutmtuievheboevdudvkecjpkkwzkcbpannzkczmlpxerhrzybhpvjwesqlaspfhkwyhasbahswcfctsklqjppssgojjcknltexbkwdbiqbdhfrkhfxlmcxegviaxjjsufjueiargigjlwtxrxuxprdtybfhxmrqnwwgjjmcmfkbnjsewjbhuvfrfbkynefrkwhmuelruvpmcsyyynzorqsszdllcsbuilrtucmfagomvetvgxfnbsdbbnykgyoyufkduxkisxgnmdooryvwzuuwmtdytwtzbfuonrvautjchaedmifimmxjojczlairadduimfmoezdjsjqlvylymhqpxmntqbvmbwavnjvjmjynrszaqrjjgixkwrrumrssnwbofavleirffcmokobfkhykmjuppzqmnfzqcowdvuqdqnzvprozszmlsjkefjvrtmfadcphhxjdjhbgwjyarsnfaykxexursugssixvamjvzsssvxpgigcjykslxaeodhyofcgbhhrfxfvlwfwatlqowuuaptphmbbhsxbrdopxpvkxulmeganoaqhvikxfjcadzustatbkdqzviutqwezjgmwmwrvwfhlvwrjckiqtgvsjitjzypdmxlatkjcygxquyqlsghqcaibfuajgsibsnalezsqgtavglyzxflawcfgbsbkukupxvhrppxzzpfshfifcndxdmmmnszmtlpprbuqcslwfihxezvdgsthxedpfenfrjjbjxppqzconesjiuutjnbgxgavcvxaszttqlsbzrspxaywjgajwrgnsyotmttolorquxritvqulypijmwvzpxzizeamsrgylwjrlwsehlgnjeguxpdenkqgskdyxzjarxphdesllmhxawrmtgxuclafffmmqaysaihxelundimabmdreudapltykuysnapctflgmqqwndrtvnjusijyaazfisdjyidrfzpbfmqgfvmugxfeivtjlmpmyrmfpehgcunuefoaupqleezjenlvsmxtiptgdadntztfjtutgamhqhvrxamqtltqcvubkvvuarzhfucxocaurjnncgrtopfppznnrssqhiiabbhjlbmztcnvymghcmbdgrkipklwnsmrbfxttqdjkuetuhwitdffvzdrincylselfeotsuzejlcfzpdgizgjmpjfaxlqgdbgqtpgyzlyzampezverecbevkusezlwjrkltrlajaociqjfbdtgmaaemzcythcdgulaymrhxyplcgewpejjkdygowrojdtddcwjscwiortceyqcjcjchjsgqtguuzglzqiwncevuwenuwkortpzdujqtluuggciclodmnxstwfhfimezwfdmdjgdbxgspsigwsychuuahzxjlkokgokrrwmupyhlstirhgaeilztfbqqmxccfuokjmesqnrdmilqytvzvegrueimwfkivebxcsimbftdurqqhomkycjqhfbjwpsxkyamsskvlwullhceifxlawfqacqgmbufjrnpuhowqasndhudegrkxhcjthkosdprshmkgaxcvyfrojxdlzefltrthtnxvvsxzzvxgjnvyegrhfxwcbahewrdhdjtzvhbfdrmpcyzfgmslmajitkwjkeofbatzlarzlglwijpeczeypszjvtzpgymtnflwmgpcqxfjuxbnadtwfuondfrshxloqlkwqujdhrdcraaqizqgftshykmxtoqbjkdjgwiplaxaakbmthufcfahknqelaocgrawjsadmmkrgwfpdqznjtxyglctbwvfbijtxlsxifouibfazfiwaifrnwiuzsqzntkcgkmmvwrawpwrfhptwwqplygpdodbjzrxdlssisytcnnqrjydrxjzwwuaxnahtdyimwutatchfdyfrulgvltqljimfvivvwtvzaestorfmxbwxnanbrwbdzcbonsiewpnuagejadkbghlvuxcuemawsrnsgptdtpolwdvxvvsodqjqlnfmqexczjzeeacwnvxckrgqlevqbhierubfcpzojnsqpibvrzhgpjzgvwwwzbrqbwzgtvksuaqeswxvgmozszuixrwocsdsnmfofadigwmidovfojmodtaadqzwpwakxxrrevdogtpimfppawbyitearebrukywcrgsebycrdzettrpmfgziljuzzdgqelgevlxsycmzxmrsokschunszhkxtinlxoywalsrocfjuqtpftdlaohomwuklsersujdevwngbctsgotjgpgnojwkshqejqrobtzbmofxjjhgdbuuhfelypngwzwwgeacorijxqdrouujppzdhurelnmypyimfauvqcxbkgfcxktlzwrmvjjqnbdgvzvipmvutmtuievheboevdudvkecjpkkwzkcbpannzkczmlpxerhrzybhpvjwesqlaspfhkwyhasbahswcfctsklqjppssgojjcknltexbkwdbiqbdhfrkhfxlmcxegviaxjjsufjueiargigjlwtxrxuxprdtybfhxmrqnwwgjjmcmfkbnjsewjbhuvfrfbkynefrkwhmuelruvpmcsyyynzorqsszdllcsbuilrtucmfagomvetvgxfnbsdbbnykgyoyufkduxkisxgnmdooryvwzuuwmtdytwtzbfuonrvautjchaedmifimmxjojczlairadduimfmoezdjsjqlvylymhqpxmntqbvmbwavnjvjmjynrszaqrjjgixkwrrumrssnwbofavleirffcmokobfkhykmjuppzqmnfzqcowdvuqdqnzvprozszmlsjkefjvrtmfadcphhxjdjhbgwjyarsnfaykxexursugssixvamjvzsssvxpgigcjykslxaeodhyofcgbhhrfxfvlwfwatlqowuuaptphmbbhsxbrdopxpvkxulmeganoaqhvikxfjcadzustatbkdqzviutqwezjgmwmwrvwfhlvwrjckiqtgvsjitjzypdmxlatkjcygxquyqlsghqcaibfuajgsibsnalezsqgtavglyzxflawcfgbsbkukupxvhrppxzzpfshfifcndxdmmmnszmtlpprbuqcslwfihxezvdgsthxedpfenfrjjbjxppqzconesjiuutjnbgxgavcvxaszttqlsbzrspxaywjgajwrgnsyotmttolorquxrioyxbcgemlgpfturwnwpzrovchzkfmtemgdblxocsultkbbwhnutsvwjftgqmazberqrdztwbqxdcjvjikynopilkhnbksgkbnjad\n", "output": "1818\n"}, {"input": "4608\npycnuolcfizryqckmngqrselxzgvgpsvebdrckeehxssxahxrqveqkvjmeouofsmqnjgnahxgxgzkanxgiulkawqycnkhyexbvifedkgluimvvqxgzuetslcnxldvzuawmdzpvjatjxxsxfbfafhruocuriobxpbsorkklyfqhfvbslbcitihlevylxrygkexpotxcbpsqaykzosvftcekjtljxmmwjbfkalcujdgbzlfjehwryigosmlyqahrivncuknrwyvmcfxydbfsigbuokejtmugafgxekrwscfxgsmuczwnlempnifvniycydqbivojedxjogngckzjwzwshtvhbcllkjvlagxpnyllnnptblviwgjlhfouutucaamimeyhxkxgwguxmcgjthrfwjtvhmzqtyxykbbsafaiemumjaindctciotcqhstaydpdonvvlpzeyunyxmcjkqezwspmeclttfivjddbhedauulvxdmwxiypfalzbkmqvecdkovgkzpmcigebnvowpfhfmdkouhigvruhujvarebxscpszgjwwtopwnnhgnwdvvmoxjohnkcfeevifcytnqxsibolviiwllztdopelypjybkqxckdvzuycssqirmqhwdjxgfspsehxttamiznnznwwikweqvknidekefdawwgnsqabsiopyrjsitgeboxaxoggrulxvvvlhfbdxrabfonvlpxxetwgsjkcvwramedkxgskhsvjmjyblqpuxkmwaszbwpmvggjiczcqpyurtdrdekivmacpxvlgqdwpvzijwshxfwapzautdubhuoalatramhpxpnukastehgtvzgvjjjfkvqeuzaoctgqbghwnwbianoxawoshihosiojrubkqgmuvlapydktlbjndejltuhgerfppiabzpdtwfebxizxkfikkrdqpgbuvkaxcofdpqezjyrcoryyrylajbkmsizbrrniuwabraqdwxqzfcfqgeghbrqzsrhhokikyuranjbabwsateyqywbuvwcswaffptmvazeybiyupftdoennixmplwpnsmxrtdkajmmolqvpldvcrytldfbtpfsensefckcucbfgvrcmphfbxkyhueihkopbenyixnefgamgvtumbqxkatzjkeslxeyswcxjswrregocmvehtysiyyytkqqpylspoxcednmdrmxyylbzplflmixtgnyndsplbiczdodjiotephabxhjaqqwxxnblrtagxmfpfdmrlozrobyuhrvoqrnlrlfpxgwttcyvtoytsdzptvzershphtxsciojwcmhbdgibppwraqhtbwlsrzbuvfwfohfvosznohjcygqicaeihigocokhddzqyqmtqcmigjslegnzdxbjumhgqbkldvgjkeuqygaeuqsndaxmbfadsufeldhfutegqpzneigpwnnzokshgjtehquydyiuohnrxphidcpogqdsuejmfgpbsyjlpmobkrnswvnswapnkjwjhbpsvtlzuszktyjjcnjdpuiwlpooibtwragqsurubiozuvfhwcnlokqyeofniddkvstuxdpwobaeddjzuiqmjvyywdvobqtfgkautloltpbiiqcvuatakejhneclpcppgbhfomjsywmivjaaajtotqxiqomxpzdtryddspooadetyooyhbrjvnifavcenjqgefbhcxrxwzpqrauqjoaxcjwsdqzhrjuwqyykqepidsikqwubnqdfitsitwzpusmcnigkionqqzcylwrldaeycazutfyaxoxynwbtstvxgqfwhcymdffajixirrbslkfupghcgidjmxxdllhjxphdfohoqxbdivurchbaqekimovjtseqtrvbkkaxfoiqkxjgajkfjgznzrtgpgztdcnxxmestggirqabnuinzkkbpgvlooawkczqrpfrnxkomkjwsdovhanyicbpnthpuxkeyevugedaawczwtagebzldzlicsrwqfkqixdsvvpalblytomyihxhdlzqxbyudlaaueeoauenejcxxifpnrtmefewzuuupepwppyafpprphevhwceiaxqbawttmsqyzzdbskaxshvidxaktkgniqreogxvexugasatxqbcvkdvximcvjpmpxsfgcwpulfyfnefligpzviebeofwbjzhqahcsxmeanbhprvmkljlyphhlzmfcbqnjlzcapsdpxfawpaouyylbbvtzvcdtjlmjyorciqwlujjikpgseqbtnwsptdsjfhtoyiweohrqeekexahjguanmmsyflqergmjzjunqxslxwvufjtnepmhaagmjbebnzfdfpxlbwqeerklyrwpuladajepqqvqxxfcovzhxhwhhbrsvpjvvodcdtyhhenxmeqebykgrjqxalywunhzwbnpfftncjqzvqvknibadeijxcmqnjkfbekmcakihgnxykdxirhnxkbasuphqzxbchnxrwmbcwlgdamtnukvoiurtquuxjgzwwdxqxnyvfukvmywbojlnrbrrnfbghhuixyxvltlabinxgijsjsokhgdmdwwecrgiwcrsnwxincxnggluaxijuybhutgxchkmawbjqpobezvlqecjbrozllsjmgmvbpmbvosowzxvopyaxuocknxvtmasohwnqxgmgjveokvnjcgabcmershnicnmprqaeetvcipvwfqkyjcyfaxdqhsdyxuolsvwhjwkdmlwmbqqmzgxgnzkldhuwlohfnfqdfwndoiowuolticjuvuyhpslkbbnozlsnvhghrdlwyumfwzqvnnfwptvvclsisioyeffwywnwnmslcuxfundoukbmoblrcewspmesrhxkpcyayypwwciymsvpipdzptvzershphtxsciojwcmhbdgibppwraqhtbwlsrzbuvfwfohfvosznohjcygqicaeihigocokhddzqyqmtqcmigjslegnzdxbjumhgqbkldvgjkeuqygaeuqsndaxmbfadsufeldhfutegqpzneigpwnnzokshgjtehquydyiuohnrxphidcpogqdsuejmfgpbsyjlpmobkrnswvnswapnkjwjhbpsvtlzuszktyjjcnjdpuiwlpooibtwragqsurubiozuvfhwcnlokqyeofniddkvstuxdpwobaeddjzuiqmjvyywdvobqtfgkautloltpbiiqcvuatakejhneclpcppgbhfomjsywmivjaaajtotqxiqomxpzdtryddspooadetyooyhbrjvnifavcenjqgefbhcxrxwzpqrauqjoaxcjwsdqzhrjuwqyykqepidsikqwubnqdfitsitwzpusmcnigkionqqzcylwrldaeycazutfyaxoxynwbtstvxgqfwhcymdffajixirrbslkfupghcgidjmxxdllhjxphdfohoqxbdivurchbaqekimovjtseqtrvbkkaxfoiqkxjgajkfjgznzrtgpgztdcnxxmestggirqabnuinzkkbpgvlooawkczqrpfrnxkomkjwsdovhanyicbpnthpuxkeyevugedaawczwtagebzldzlicsrwqfkqixdsvvpalblytomyihxhdlzqxbyudlaaueeoauenejcxxifpnrtmefewzuuupepwppyafpprphevhwceiaxqbawttmsqyzzdbskaxshvidxaktkgniqreogxvexugasatxqbcvkdvximcvjpmpxsfgcwpulfyfnefligpzviebeofwbjzhqahcsxmeanbhprvmkljlyphhlzmfcbqnjlzcapsdpxfawpaouyylbbvtzvcdtjlmjyorciqwlujjikpgseqbtnwsptdsjfhtoyiweohrqeekexahjguanmmsyflqergmjzjunqxslxwvufjtnepmhaagmjbebnzfdfpxlbwqeerklyrwpuladajepqqvqxxfcovzhxhwhhbrsvpjvvodcdtyhhenxmeqebykgrjqxalywunhzwbnpfftncjqzvqvknibadeijxcmqnjkfbekmcakihgnxykdxirhnxkbasuphqzxbchnxrwmbcwlgdamtnukvoiurtquuxjgzwwdxqxnyvfukvmywbojlnrbrrnfbghhuixyxvltlabinxgijsjsokhgdmdwwecrgiwcrsnwxincxnggluaxijuybhutgxchkmawbjqpobezvlqecjbrozllsjmgmvbpmbvosowzxvopyaxuocknxvtmasohwnqxgmgjveokvnjcgabcmershnicnmprqaeetvcipvwfqkyjcyfaxdqhsdyxuolsvwhjwkdmlwmbqqmzgxgnzkldhuwlohfnfqdfwndoiowuolticjuvuyhpslkbbnozlsnvhghrdlwyumfwzqvnnfwptvvclsisioyeffwywnwnmslcuxfundoukbmoblrcewspmesasuljrqkpgytqdriftqbpclawxilsfytdkimtpvmbhcdhawrwacytsyzrlvxrgsxkdjltjlgqkyvxkuhirsbblacyooiywa\n", "output": "1589\n"}, {"input": "4835\nxjvwuhcuktbmicflzpcmttebagfzchfxsxkbnmzqesgjflzuqqqjyclntnrddtzrgonaqevvunqgstumyvtxxydoxjtzqtnkwtcbvtrvqxxaukixcinbosnnwqccufbsnipeuprutncydybmjssqqrqrhvugpikdcdotzcffjifdsyeidylainvspmjfdecknzckjpuhinqlcdkhqqfbgaybyfocqqgxiiueenmudshkvhnnioaclyywqzgibxbmirwnbqawnxkejvlvshcjlsvbfrhnfdhjmwcxjqzyibfaputgxeynuzmoolmhmciuudcrsgthuwzrvpmmndmfzdjbejtdfrdzksqsancfcpyuzxqdbiqqtfogqbwsszqjjzscnjjgxfblvhnuoimdqqfuuzwcjuzuwarqopfrpsqwphwqiuwfcmehqzqhnckrlkvoqlshtsjotmwfhgqjyjtmdqecvyztwxyandsqzeoxyafmfgldnmlhlcyiajoowiltayiutqbalacnfvwzppycvllrmfwmgxxmafjcoqavoafcgofyauupgoutnsjoycksfspvdysohoawmvkifdgciudltbmewxznthkpokzfhxqgackqfwdhxhsebbqtfmulqtjcpuciogifomjdupxvmuwawcxeodlsrbfrsprzxakgcqmbkxvgfrgvmorelvflrxohjgmlldowqmkieyfmakyeigaaaydvzpqwwbxmuzpkmijptbbupkiiqmbvqzmotxgoceqtowcsojlprtvrcmfbuktbuijvtltovspkelvhtsvaqobrbkovlepfupxgydrwpvxhvhkznhvqribrtwxpgihesqjjshahdyewfcbspmeqxtewkeuakenczrzzkknkwgzhinydfqdgwwiarwywtjavnyqryrelkfvexgzndextfmwtvmwnzwoexsiesimwbxgepnbqdwnampunklqimlgucxhnaqmcehifgssglogcleinqneadchpgochadrcortcwpwatbxuvexyianzdetpxpsbqnypndiqwwkdaowhxvyywjoxmyeiaonprzqiwlozqgprshhuvrsqdjpvtccnulwklgwkztlvqpjpgmzjvfjmousoyownpojopmmsixauedwfwcwcabvocoqspjdntnenynqcoycxuxlrumbixzaeuawzdttzldckwifsmerliwhaqmbvmbpqxpcyhztzcqimhmctqslmpcipswqsfhnekfsumekkqtvhldlmqtcnqcseclckpnkzxbltaeqmvqnalbgvwrbbhoqzrkqhlwxtknqqfnzcixmtwdgicqbcqkvhrrpnlisjcpbvvoyhgaeymgamajweqqlpounrdanxxnqibelfdrwpacgczjbvnaxuvoomodylalswqvyanqfqramirgxieqpfhafstlnjmhyakjhipkvllevgieqoybzpgsynosunxekgupgegjmjakplzaajvxizbkncfiqttuwcyidtkzpandxijmjmhctrbzcnwkpmtphdaizgtvrgamenigqifpcqoybdlhcelwawtvolkyeyhpkeyswtslloudghoepzxatjgejaiwhruyficgnlmaxbhcasxdeatrcmipxapksxxqychaebfxbkecflrowkxjqitnmnxlnlkkecbvutufwyouutpuujzlkibtiihzoviituzjtvwzhfniinfjfuuqeecksycavhbmfzlvrltwxzowpfuajqicqevpaniyiucrjvvcwddxhdabvhirmvykdvdpodbqghzosjcwbrzqluzktcnbudxswgevcgerzvxjokxhzengquhxqqktwczqdhzjwlydtyxufkhwqkttqysqswwcfjabkkgfwtlzzesfattatsxofgrubtjjlzvwikpgxfxuyvnwumulzanxkavuipdvpwiuawfffxbiwwzhvolfgsdmahecbinobpbtuwfqbbslkiophduwwyigxcnaunmlhkypyiqzamubuphuxfixzedwtxnllzkltjxsdlqxiknlmwpihjzxmwufpwwwyoxutawjoebcncwspfumwmhheddnuxcrbayirrqtznnlunewammlzsxtftvqmufqdskmqirsoglbrfjeoetbwvsfcjaetzyeteramiuegsguoethuwyqnigqgcpmuxywfbjqalcyccuodgrnnjgnqgboxqppwmxujezagghfwvemswakikkvndkcxjujjuamoccgcnprwkkvpzqqbqgsurqjgjodegblksscrafffagznufkpcycjfdblpmrhpmkmhvtgbyjmenuabgduoxcfgmspmdbsntdstzkhnttgrlcgnjquosbtccflzpcmttebagfzchfxsxkbnmzqesgjflzuqqqjyclntnrddtzrgonaqevvunqgstumyvtxxydoxjtzqtnkwtcbvtrvqxxaukixcinbosnnwqccufbsnipeuprutncydybmjssqqrqrhvugpikdcdotzcffjifdsyeidylainvspmjfdecknzckjpuhinqlcdkhqqfbgaybyfocqqgxiiueenmudshkvhnnioaclyywqzgibxbmirwnbqawnxkejvlvshcjlsvbfrhnfdhjmwcxjqzyibfaputgxeynuzmoolmhmciuudcrsgthuwzrvpmmndmfzdjbejtdfrdzksqsancfcpyuzxqdbiqqtfogqbwsszqjjzscnjjgxfblvhnuoimdqqfuuzwcjuzuwarqopfrpsqwphwqiuwfcmehqzqhnckrlkvoqlshtsjotmwfhgqjyjtmdqecvyztwxyandsqzeoxyafmfgldnmlhlcyiajoowiltayiutqbalacnfvwzppycvllrmfwmgxxmafjcoqavoafcgofyauupgoutnsjoycksfspvdysohoawmvkifdgciudltbmewxznthkpokzfhxqgackqfwdhxhsebbqtfmulqtjcpuciogifomjdupxvmuwawcxeodlsrbfrsprzxakgcqmbkxvgfrgvmorelvflrxohjgmlldowqmkieyfmakyeigaaaydvzpqwwbxmuzpkmijptbbupkiiqmbvqzmotxgoceqtowcsojlprtvrcmfbuktbuijvtltovspkelvhtsvaqobrbkovlepfupxgydrwpvxhvhkznhvqribrtwxpgihesqjjshahdyewfcbspmeqxtewkeuakenczrzzkknkwgzhinydfqdgwwiarwywtjavnyqryrelkfvexgzndextfmwtvmwnzwoexsiesimwbxgepnbqdwnampunklqimlgucxhnaqmcehifgssglogcleinqneadchpgochadrcortcwpwatbxuvexyianzdetpxpsbqnypndiqwwkdaowhxvyywjoxmyeiaonprzqiwlozqgprshhuvrsqdjpvtccnulwklgwkztlvqpjpgmzjvfjmousoyownpojopmmsixauedwfwcwcabvocoqspjdntnenynqcoycxuxlrumbixzaeuawzdttzldckwifsmerliwhaqmbvmbpqxpcyhztzcqimhmctqslmpcipswqsfhnekfsumekkqtvhldlmqtcnqcseclckpnkzxbltaeqmvqnalbgvwrbbhoqzrkqhlwxtknqqfnzcixmtwdgicqbcqkvhrrpnlisjcpbvvoyhgaeymgamajweqqlpounrdanxxnqibelfdrwpacgczjbvnaxuvoomodylalswqvyanqfqramirgxieqpfhafstlnjmhyakjhipkvllevgieqoybzpgsynosunxekgupgegjmjakplzaajvxizbkncfiqttuwcyidtkzpandxijmjmhctrbzcnwkpmtphdaizgtvrgamenigqifpcqoybdlhcelwawtvolkyeyhpkeyswtslloudghoepzxatjgejaiwhruyficgnlmaxbhcasxdeatrcmipxapksxxqychaebfxbkecflrowkxjqitnmnxlnlkkecbvutufwyouutpuujzlkibtiihzoviituzjtvwzhfniinfjfuuqeecksycavhbmfzlvrltwxzowpfuajqicqevpaniyiucrjvvcwddxhdabvhirmvykdvdpodbqghzosjcwbrzqluzktcnbudxswgevcgerzvxjokxhzengquhxqqktwczqdhzjwlydtyxufkhwqkttqysqswwcfjabkkgfwtlzzesfattatsxofgrubtjjlzvwikpgxfxuyvnwumulzanxkavuipdvpwiuawfffxbiwwzhvolfgsdmahecbinobpbtuwfqbbslkiophduwwyigxcnaunmlhkypyiqzamubuphuxfixzedwtxnllzkltjxsdlqxiknlmwpihjzxmwufpwwwyoxutawjoebcncwspfumwmhheddnuxcrbayirrqtznnlunewammlzsxtftvqmufqdskmqirsoglbrfjeoetbwvsfcjaetzyeteramiuegsguoethuwyqnigqgcpmuxywfbjqalcyccuodgrnnjgnqgboxqppwmxujezagghfwvemswakikkvndkcxjujjuamoccgcnprwkkvpzqqbqgsurqjgjodegblksscrafffagznufkpcycjfdblpmrhpmkmhvtgbyjmenuabgduoxcfgmspmdbsnvrhdeukepnefbexblnbweliwvgdxckonilzfzgvfoknhefcbqroeovlt\n", "output": "2371\n"}, {"input": "4517\nyzfkgmcsyhucgybybrsormbzybeitonwkakwttmshytzejvfxtdpexxjpcefnibxmbisywubptxbhwnyqkhhaxezmwmiuwkncfaghpjxxvlkvirryxgmnvfsqgbgmhlswyckudxvszzehqxhicbnqxfwkfjqdfibgwocodniwytfahbgxdqngluouhnvkwntuumsyvtolvykwthuhlpazryjlxwmwdxqmgckavrbxhlykmvognpqvngmtlyxrorypqqjephwrvunfeypvlduglfkylpvjsnojqbvnzxuchletmntzzoxhsnylmbkzexdbqkeenbxdntosbuggcidpcsidjtwmgxlcilvicmhoathyzxfcpxgnopjqnoqoolketajwiahbwlhwpxdwinjtrbznomfdndadvqqdnhwvgvtxyeerfbklfedqkgpkeienzdryaukihefdslphhqgseghbxhqlkitfjijtscpxbrlfnzmsrcuupydjqntjctwutafzhdcfuspjdchjxcxqefxtcidnxmzqvvuybkcgdrdpdehrhscldphcdlihqgkytrrgnotcdozjsdnouicxmkzmegyhnlwvznykqrnoyxaxeuuwzhggttojhvazolndykahmjbxqeahoqimuwuqwfcxielxejkagcxndawfyhmasurrfkkquakjelxfygmemjwmwnsiullaygnfrxljrmkemwwniqdyjgjpkdjhhvjlyszcnxwscueanabaconnhiablqsaqtimgfehoarlgbqbcdnrtapxotmambwtmkgkgpcnbjyoffmmquigkcqrcroihrneigmptfxgrbgsrigqatnhfbwuetzyukdftrhuhykwlurxpvvdymqzwuzkphxrcgxqiskoruckftiybfryftvfmddrbpgnmjoitmxmtrxhfcohlytdfuttiyprfzmdewooidcdfaybgjflpevmabblezsdmxwtkyfeevagcjtmznvdbujvfrtesevsgzlrqfechzpzbkmbwfpezddytqbuhxgggjkkycgtxkkdcmehilltzeccgkldoewyojvjvpkcdwzkahedfjtblpvjfoogovwdkakuxjmtomivaoxonnotskjckckqzaksfieezorgtjgjjsvhvtfjxlfsamqimuxtxbvaadjrgwggsskmyiykarvyyqvicexuporyusprqpapserbyfnalyiayadibzldqmtimhmivcboaglbkrscphzfwwpmqcdeqsebtmoxxkprttxfhcbxbxwlxcuajtvidasejxjhbiypefhjjyyrlefidvoekrizownloaxuypjhbbbpyfwcfkkxbvfvpclyercuhopioataoiupsebuaajzodiwmydrjhbsqxwmyusmkawfiyrodrkqkdrlfofedppofpwciocrsvqnzjfzovnerfggzbygbwruixqmasapkdzxbzornkteeffmaflwqqemjwushmnxirvybjwllzndxtqbquslghhjekcwglxwnoyzaaaevnvxstxqqlytpsnoesqodguexhlamcgymwrldalyvbtggoxbfpgnkpponqqbpyahvoytiucxlypasxdcanovvqrwwvpbxslkjwlvfajhtcjsdnlpmaddaowgitwbdyirtlekheknkekfbfgchwdyxgkfnuppaakoxjbtpovqtjyhlrmnfkpelayailepcitlwuxlpqyylxnpglyeyjrvecnqawowiwfqazbujydlrxsacnduthhgszftjejnhdopnbnwsaqmtxwuxzpmrtqfeuyxpogwnprpeiflylykyfnbofcklpbvfhngplgjakrgqgaqmvhfoiohqornxlhztgdzeyzpavsbtsxkllkrarxxrhbftxccjaatouzpgdzybiexpbdlkcggtywkehcnjgokdzztzmivhxzfwrihmnqannmnufntpkmtymzfpndyuihtfpnvvxyqqxcfqgmzwupaegdyvufhuameghgtwbgzgsayocwrvjxnjxtlevletkrajznjqucznvjcefjhuamxplxuansawnhgyqffxdniixscwmsgxflhjrttzdxpakccviwkhdcoaiincgkskqfwnxsdxlxsxzmcwihhyzwgregxmhbklcwudperrjvmdsclcgfenpkfjczebmrncwkpxjqzslhhtavyuyitlsdndqovdwmzescfdjpvkzyvsyfpaeypwueroqxzltzoldhlzltmqxmaasqucqrojhxtcougwjpnbbxwmcmpbwnzsivftkixigftzweeqkqadowohcnujsijabfadnmjzkyxkknypfvzubbwmgahkhubsccpfnfamtezmpwdqlmmyrbwfhdvmonhdxwbgvewvzqjbeijfkdrtgowrhqsaiwncmmcwnugwrnebhjmsxuocgjpzwdlpnnopatotnfjkajqlglhvoracgqozfuvnwacivngmtnlvuewusbbahwtjfhyvomulpbwaiepvxsmltrmehywdukmwbtzixvuesasweffspzxtkxyriwabrtojqxnimmaqafqcbrohfkxaksopysyfrratwowlcjztozagjkkycgtxkkdcmehilltzeccgkldoewyojvjvpkcdwzkahedfjtblpvjfoogovwdkakuxjmtomivaoxonnotskjckckqzaksfieezorgtjgjjsvhvtfjxlfsamqimuxtxbvaadjrgwggsskmyiykarvyyqvicexuporyusprqpapserbyfnalyiayadibzldqmtimhmivcboaglbkrscphzfwwpmqcdeqsebtmoxxkprttxfhcbxbxwlxcuajtvidasejxjhbiypefhjjyyrlefidvoekrizownloaxuypjhbbbpyfwcfkkxbvfvpclyercuhopioataoiupsebuaajzodiwmydrjhbsqxwmyusmkawfiyrodrkqkdrlfofedppofpwciocrsvqnzjfzovnerfggzbygbwruixqmasapkdzxbzornkteeffmaflwqqemjwushmnxirvybjwllzndxtqbquslghhjekcwglxwnoyzaaaevnvxstxqqlytpsnoesqodguexhlamcgymwrldalyvbtggoxbfpgnkpponqqbpyahvoytiucxlypasxdcanovvqrwwvpbxslkjwlvfajhtcjsdnlpmaddaowgitwbdyirtlekheknkekfbfgchwdyxgkfnuppaakoxjbtpovqtjyhlrmnfkpelayailepcitlwuxlpqyylxnpglyeyjrvecnqawowiwfqazbujydlrxsacnduthhgszftjejnhdopnbnwsaqmtxwuxzpmrtqfeuyxpogwnprpeiflylykyfnbofcklpbvfhngplgjakrgqgaqmvhfoiohqornxlhztgdzeyzpavsbtsxkllkrarxxrhbftxccjaatouzpgdzybiexpbdlkcggtywkehcnjgokdzztzmivhxzfwrihmnqannmnufntpkmtymzfpndyuihtfpnvvxyqqxcfqgmzwupaegdyvufhuameghgtwbgzgsayocwrvjxnjxtlevletkrajznjqucznvjcefjhuamxplxuansawnhgyqffxdniixscwmsgxflhjrttzdxpakccviwkhdcoaiincgkskqfwnxsdxlxsxzmcwihhyzwgregxmhbklcwudperrjvmdsclcgfenpkfjczebmrncwkpxjqzslhhtavyuyitlsdndqovdwmzescfdjpvkzyvsyfpaeypwueroqxzltzoldhlzltmqxmaasqucqrojhxtcougwjpnbbxwmcmpbwnzsivftkixigftzweeqkqadowohcnujsijabfadnmjzkyxkknypfvzubbwmgahkhubsccpfnfamtezmpwdqlmmyrbwfhdvmonhdxwbgvewvzqjbeijfkdrtgowrhqsaiwncmmcwnugwrnebhjmsxuocgjpzwdlpnnopatotnfjkajqlglhvoracgqozfuvnwacivngmtnlvuewusbbahwtjfhyvomulpbwaiepvxsmltrmehywdukmwbtzixvuesasweffspzxtkxyriwabrtojqxnimmaqafqcbrohwgjvsrrppsnnrsofegqmabumdwqpjrlnnbchndcjajcnxbzkdmjbgjxtoyxmcimgfkqyjqlzfbjjkboturbwsbbkdbbimbalsyqvguldvacwmbosbqswjcrcnhwagcbzfjzroyqflxlgbgpvcipwjqifikowjbofbibucndnsjndcavzfnlwgtgzsbiepsueukignldircuufjjascmvbwcxwcvorslxapludueybenucwyhkqertwkteszwrfgxkpvyrfwfdqgxrvczbloieziwoycejngdtbshoawyblvxkppwhzvdkhn\n", "output": "1561\n"}, {"input": "4965\nklvlmqngnkvhivzojfiolehoykhqzcjulommpeqsnhkabclhgwfhzbhfapqtoqljjkxykvuijaszczntwxnuwpixxtiaatmwprennblrvhtmtjoktlebychxfelwzmjeiatmddrbnfcjkcqbwoaduedaqelkwttjzclomqezoggtaetnkvcjtimwvcrthcqbujnzsmhlnkpczhmbrzpatygftkoxgxfnwynujzkncxywydnonekwqsjmlnohtgbgcpqtyujkcjiyqvxatsdfxanxmwjxawblbicfobdgcczfszzytnjabjxclraxehbxfkqmaouthrvqwzaedieejmmepooovobfjoarbbpoganyubruxoojihunkjbheuozayeugtrmplmrjhumrncnnsomywpynjspskgtjdqhznsdovoonlbhnalnghfnyrikixeugoqdinxptytakndkvnxwmtmznjlssbqdslotgbukkmfjmkaqfieziiafqavgaxbgxnxeafrqxkbxggdpkgcqyixedqwtxbpeuhtojsyfeoacxlgsyzepqyajrxhhqsjhotmzraxjfcabzyesfjbjyfadwonmrrrpxevuvgqlcoczisofgxyajrhxagunkhddnmligrxskqaushvlsjdtwbmbqbmrwtaqhxchxrjnooclcjclrlserspyzhdoqwvgfmsldgaumvrmxpgylhktyzmavtikkibetourtrbdqredxwaczljyersvxqemomgrndditvdhbbmvhqehatqhnnaeyqiuvtmzfglysuakydzxekiqicpgkpuwwfklclvivtqbckorlxlswmttcncgycetxomqpcqoomvursupqzuktmevkulxxmxtnwlskdyqiwxeehqkqrtdivffcvgetgohnbjmeqfhawgjoxwscxftzumxzlbwpsgcernzkdmhloqtjiotmgcfyvczayrrmsugqrmyparpdcmbejmommmizkclunyzqlxikiingpcmggzocqusvacgmkexsnjcncacfifyeifdvetgywnsuwbnhucrnacnkepirvocwiqnmeunzsbyvghixovpcgdnyhrhwacdsvrlwnxsqorwecnggebuheiqzvkyokfulmtxyrdevayfuuvxvqhbzgbhjcepmpdujooajyobtgopyyjmiqwsyiubndgovltzifnyazeouclrmvlxbsetwmumnzftplbddfciuhwhsenqkbdksydxkmvefatedkldjqxaeunmeafetjlzlzybdkutzbwfcqnoirdoikjepfavkjuqcsijlfrqluhvjdbgofbgummidsthzfkburvrejwkdvtilmdpogcirnhcxnibczhdjnrsrplwsasolyoelpwmvhnsoarsmfgcwgfjpgcibvmivzfrzvlfvrefnydnaneyiwkmmsbiaospitanyuvfwvkytakciqzqhqgrdzhxvyjnarlnrkvwcjcxpazdoashphjngianfzdwmsfsfoafzhzchapxluxnmfivhirvutptssyfyeulhpdwmpggywobbguxfzazvhfvqnhpsmmypvcgipajvgkbfbxjhrhbvmtegmtfoaebkixynjvhcsabgnpialylyuqcmocjnmslnuvakgkickepvezoixtpampomtoxhomqqtwzmmcyfmyjryfgljmbkoejxdoyopmihqpszjppcfajeiabfxoqdghxddiyvvwpnoktkgsqahukibdlfptqnsmdzavivlvgmdtwyimyfoqumrsuijucmenlbskjmohsdnbgqvrahtlzkkdxaahcteutljsjseefjlxcrnbmftxqedyljiwkznfcfseqmjjeyotyelhasquuszvaimtwqzzbdwtvbbdlqezmtkprmjdjugswolgsualybvmlzjmwaoqdtcnjpjrkkjvwfnbkmrdzivtexsxrgcxucphhyigbladrqcxfmlsikfmadppmioybqyzeimpwnrlldnqtkmaxyoughsixulheevjizbwcxjpecbfrmhzmkmvykngjgmxrbecjjwrgivvzeocamrqqmbklxnjicmtgtrebnmrryvehscpycjmhvciayekxzzbrvskfmbrnnnjgwzsdrsbviwzubjsaxxfiivnagaeoviqgywpvsrnfwtnknofxlgiifjvltkawndzgmuuzhctovzlrdfocepjwtpwqevbkyizjqyaamascvlcupkxvcjeanftlgrvnyxarsstkwtexkeaauzajxjwyhftubcogltfufeebtwygpiusggdikubuscjkaisdkbzxpnbfqbjejaijbnqrmxcvplrzaaescaqttfnjfxrimvyxisjkdzxtvdwooouwxrutzdejbnolwbefovkauimtbamcpkjlgnbvxakmjxzsmjcahiabeccziwpnjswaqmkrragawzzhfvbiabxsvuajdnajjaggbalqfdnqhacrvhfpqpbdvflmzerfryolhylzcdhzmbymsfryfodmptkzjoezfkhxzfreqddxmwksdbaebuobgykyrbhzbjawlxuyuwbmrftyjlsfgmeiwhktpyoljyhpqmjzlkljhtvvmhmbrzpatygftkoxgxfnwynujzkncxywydnonekwqsjmlnohtgbgcpqtyujkcjiyqvxatsdfxanxmwjxawblbicfobdgcczfszzytnjabjxclraxehbxfkqmaouthrvqwzaedieejmmepooovobfjoarbbpoganyubruxoojihunkjbheuozayeugtrmplmrjhumrncnnsomywpynjspskgtjdqhznsdovoonlbhnalnghfnyrikixeugoqdinxptytakndkvnxwmtmznjlssbqdslotgbukkmfjmkaqfieziiafqavgaxbgxnxeafrqxkbxggdpkgcqyixedqwtxbpeuhtojsyfeoacxlgsyzepqyajrxhhqsjhotmzraxjfcabzyesfjbjyfadwonmrrrpxevuvgqlcoczisofgxyajrhxagunkhddnmligrxskqaushvlsjdtwbmbqbmrwtaqhxchxrjnooclcjclrlserspyzhdoqwvgfmsldgaumvrmxpgylhktyzmavtikkibetourtrbdqredxwaczljyersvxqemomgrndditvdhbbmvhqehatqhnnaeyqiuvtmzfglysuakydzxekiqicpgkpuwwfklclvivtqbckorlxlswmttcncgycetxomqpcqoomvursupqzuktmevkulxxmxtnwlskdyqiwxeehqkqrtdivffcvgetgohnbjmeqfhawgjoxwscxftzumxzlbwpsgcernzkdmhloqtjiotmgcfyvczayrrmsugqrmyparpdcmbejmommmizkclunyzqlxikiingpcmggzocqusvacgmkexsnjcncacfifyeifdvetgywnsuwbnhucrnacnkepirvocwiqnmeunzsbyvghixovpcgdnyhrhwacdsvrlwnxsqorwecnggebuheiqzvkyokfulmtxyrdevayfuuvxvqhbzgbhjcepmpdujooajyobtgopyyjmiqwsyiubndgovltzifnyazeouclrmvlxbsetwmumnzftplbddfciuhwhsenqkbdksydxkmvefatedkldjqxaeunmeafetjlzlzybdkutzbwfcqnoirdoikjepfavkjuqcsijlfrqluhvjdbgofbgummidsthzfkburvrejwkdvtilmdpogcirnhcxnibczhdjnrsrplwsasolyoelpwmvhnsoarsmfgcwgfjpgcibvmivzfrzvlfvrefnydnaneyiwkmmsbiaospitanyuvfwvkytakciqzqhqgrdzhxvyjnarlnrkvwcjcxpazdoashphjngianfzdwmsfsfoafzhzchapxluxnmfivhirvutptssyfyeulhpdwmpggywobbguxfzazvhfvqnhpsmmypvcgipajvgkbfbxjhrhbvmtegmtfoaebkixynjvhcsabgnpialylyuqcmocjnmslnuvakgkickepvezoixtpampomtoxhomqqtwzmmcyfmyjryfgljmbkoejxdoyopmihqpszjppcfajeiabfxoqdghxddiyvvwpnoktkgsqahukibdlfptqnsmdzavivlvgmdtwyimyfoqumrsuijucmenlbskjmohsdnbgqvrahtlzkkdxaahcteutljsjseefjlxcrnbmftxqedyljiwkznfcfseqmjjeyotyelhasquuszvaimtwqzzbdwtvbbdlqezmtkprmjdjugswolgsualybvmlzjmwaoqdtcnjpjrkkjvwfnbkmrdzivtexsxrgcxucphhyigbladrqcxfmlsikfmadppmioybqyzeimpwnrlldnqtkmaxyoughsixulheevjizbwcxjpecbfrmhzmkmvykngjgmxrbecjjwrgivvzeocamrqqmbklxnjicmtgtrebnmrryvehscpycjmhvciayekxzzbrvskfmbrnnnjgwzsdrsbviwzubjsaxxfiivnagaeoviqgywpvsrnfwtnknofxlgiifjvltkawndzgmuuzhctovzlrdfocepjwtpwqevbkyizjqyaamascvlcupkxvcjeanftlgrvnyxarsstkwtexkeilhntyrzfymkmtvhxffxbdfxulujnixquqvzjglygkrufxlajuesyxfoczdojvfgoxaiesgcwneanciagwjprvqoeboifnyuxsavbivnokuladzhmaajkfuacmfukcnbnfnjbwlgoxvnjyeucjnpncvfgaiwbkryamuegkglbyrutpnunnqzayunkyisacxwinqyhpsyushfmofdpqrvkyg\n", "output": "2097\n"}, {"input": "4776\nkymgdrcnbdcvpzckznvygogklpooyoeisjtmshpdliubxrcrdagwgwxbigcxgsqzbirsykfnkfxuvadgecswqwluhzzrslmzbkwyaslguyahbempkuxmvmwapyryjcoeptvifwxjlfnnffnjhekfupytmvcvwtbzaqvsdbbhwuoyiqaqkrxaumhqqyjwxtlnmzqhfcgqiseezekrscopbsucurufwhjgvkxtftfkjwvusxtgjzogciqzvjvnfpkearbeqjmcssqmfzhnhewqrqrfpgnbwjagmwsrhuvluummbaxfxgmmigeceibtpufmxxwxhextmhzazzejrggkwrgfnitlfhehjpnitcjohxxslboylstgknzzatnycudotemvwhtlghwshycavmejynpsqpenddrmefybzbdjlirfezmvzcrvaosxchhjqtzgwntkcbosnwbdbnqxdewtcqlrvqwytfubogsmpffeipjfbmdpieaekzzuiffcszjwsktlxzwoyqjgfciaynvsiqusonehtbxzoveaqudtaihmkxsqgfszdtvjsljkuixkbefoxblbtrwxjimblioatyfsmvusatfcqosvfmnnnlymyexcxnxoofikcgcnneffbsraibjdflmjrhcmyphtfgsddwhbnxswkixngmtreiuqrapdkwlfnhpmqejxzreuoqwgcxkyrovjjyfaiqmxglgclevwsfqhcvsjkmxrvniqlbstjsqscfergqmcuhbhulcoooiyvesrzlwcbxrkebzjcxcjmjppyzrdklxnlhyjaskxfrsbrpailenqfgyefvhlupfrahpkhhrmccyersgfymsodjbmizlembtbivzlgvvhqthubuzpergnkuftbhozzmxdxlfrbohtpxphpixfzpbwsvuwcrgwvkzdobcsbhtchslnlxlpdevfcvilkfjrhvaiydeclxzcvqwborbbtbzixtfdgypoeohbtfzsjsoccuemfsbqgtsopbunaklfoogkapquxwbjllfwlfvueeywhbaquuiaxdjvqdjeebjxwxknhkverrqkuayzkdmcusozkaoutsittfzuorhksaomyfgvqbgzdzpbfrfysoglpjfmtgeaztikhjibgcunsaoncseqnpffwjhzcrempgtixhnvkxyxdhtnxhlvpsozhsdtocqazfaynsfzbsckempcdvtztuevqddxvkqmokxxsvduefeitldvipoxjhpdlijlnzelrgajmmoupicobfdiwlhuddnoatfwpeoznpugkroyrxvluqtpupjwoatolvdhuoebzdylolffqinzrskxrukphpobytnwynwxvnkzchynygsifsxzvkumuxaswjcpdfhnziswipywwdtesfevfeqffcmubhdqybpdeameefdzzivmkxtbtrifbvmtkquxawjpziscsabtbuotgstqjlybjqkuslhejstpimcnbhbkwfftxnlxzcaypjkzdfjjczncdcrlvchejzfhpdlmrfgttswkvztxtnxqlgxkbtpgbyrfiovpbnavkdogocnbqvbmikenbxtyopohuxauschkoeferznrkwbppsjlpbtzutrjkezlccjlyoznjuwpevahdfrcxrlqeisfrdsqvapxhjqxkmqaxamuadgjhrkmvjgfyhbtgvsipwfcjtkvqnqcgcoqtwnghtradjjfojeqijfgndxsglcywxuxwvkxkaoyispbxepwrcgoolxricstbrztqabmpibyumxpezlqpxjvwaaverurbqztmjplzesqpbzthkpjyegjuajtbtylgjguyjqeuqyaanyeivkeoxnoezvjbeaapxffoxzaqewzenlnbgxeahtbcmydqmfwmdbhupfbgsdmbkuuadckrsxfeeyanojnseqtmvewlibsrusifipvnvhomxkpjppxyfhfowokjikhhzfhlwjxyevjkxjksrddtsekplmzdrmfxsjxeqwbrbpajzzbdqbsugrujuqrlduapoldymtororpjswzoijyupflurnfxffbtxiaugvcghpedanabsxoksnglxieycvnfmeehrahsuynrftbnrhtclxsxpkixuxopztnvmsoeiaiqcqhpmedecrjqjyhmvhlssucbnnapllypqqkxvscluqlppvetjrbcawiticpxmwpznwydwgdssrvfqqbfjjyiulvdeuxgxqbhufqgoiodrmwabpddkpgpjdvrzuizmjtabfzfxwvgxvdaioiamqbcgtmobushpdliubxrcrdagwgwxbigcxgsqzbirsykfnkfxuvadgecswqwluhzzrslmzbkwyaslguyahbempkuxmvmwapyryjcoeptvifwxjlfnnffnjhekfupytmvcvwtbzaqvsdbbhwuoyiqaqkrxaumhqqyjwxtlnmzqhfcgqiseezekrscopbsucurufwhjgvkxtftfkjwvusxtgjzogciqzvjvnfpkearbeqjmcssqmfzhnhewqrqrfpgnbwjagmwsrhuvluummbaxfxgmmigeceibtpufmxxwxhextmhzazzejrggkwrgfnitlfhehjpnitcjohxxslboylstgknzzatnycudotemvwhtlghwshycavmejynpsqpenddrmefybzbdjlirfezmvzcrvaosxchhjqtzgwntkcbosnwbdbnqxdewtcqlrvqwytfubogsmpffeipjfbmdpieaekzzuiffcszjwsktlxzwoyqjgfciaynvsiqusonehtbxzoveaqudtaihmkxsqgfszdtvjsljkuixkbefoxblbtrwxjimblioatyfsmvusatfcqosvfmnnnlymyexcxnxoofikcgcnneffbsraibjdflmjrhcmyphtfgsddwhbnxswkixngmtreiuqrapdkwlfnhpmqejxzreuoqwgcxkyrovjjyfaiqmxglgclevwsfqhcvsjkmxrvniqlbstjsqscfergqmcuhbhulcoooiyvesrzlwcbxrkebzjcxcjmjppyzrdklxnlhyjaskxfrsbrpailenqfgyefvhlupfrahpkhhrmccyersgfymsodjbmizlembtbivzlgvvhqthubuzpergnkuftbhozzmxdxlfrbohtpxphpixfzpbwsvuwcrgwvkzdobcsbhtchslnlxlpdevfcvilkfjrhvaiydeclxzcvqwborbbtbzixtfdgypoeohbtfzsjsoccuemfsbqgtsopbunaklfoogkapquxwbjllfwlfvueeywhbaquuiaxdjvqdjeebjxwxknhkverrqkuayzkdmcusozkaoutsittfzuorhksaomyfgvqbgzdzpbfrfysoglpjfmtgeaztikhjibgcunsaoncseqnpffwjhzcrempgtixhnvkxyxdhtnxhlvpsozhsdtocqazfaynsfzbsckempcdvtztuevqddxvkqmokxxsvduefeitldvipoxjhpdlijlnzelrgajmmoupicobfdiwlhuddnoatfwpeoznpugkroyrxvluqtpupjwoatolvdhuoebzdylolffqinzrskxrukphpobytnwynwxvnkzchynygsifsxzvkumuxaswjcpdfhnziswipywwdtesfevfeqffcmubhdqybpdeameefdzzivmkxtbtrifbvmtkquxawjpziscsabtbuotgstqjlybjqkuslhejstpimcnbhbkwfftxnlxzcaypjkzdfjjczncdcrlvchejzfhpdlmrfgttswkvztxtnxqlgxkbtpgbyrfiovpbnavkdogocnbqvbmikenbxtyopohuxauschkoeferznrkwbppsjlpbtzutrjkezlccjlyoznjuwpevahdfrcxrlqeisfrdsqvapxhjqxkmqaxamuadgjhrkmvjgfyhbtgvsipwfcjtkvqnqcgcoqtwnghtradjjfojeqijfgndxsglcywxuxwvkxkaoyispbxepwrcgoolxricstbrztqabmpibyumxpezlqpxjvwaaverurbqztmjplzesqpbzthkpjyegjuajtbtylgjguyjqeuqyaanyeivkeoxnoezvjbeaapxffoxzaqewzenlnbgxeahtbcmydqmfwmdbhupfbgsdmbkuuadckrsxfeeyanojnseqtmvewlibsrusifipvnvhomxkpjppxyfhfowokjikhhzfhlwjxyevjkxjksrddtsekplmzdrmfxsjxeqwbrbpajzzbdqbsugrujuqrlduapoldymtororpjswzoijyupflurnfxffbtxiaugvcghpedanabsxoksnglxieycvnfmeehrahsuynrftbnrhtclxsxpkixuxopztnvmsoeiaiqcqhpmedecrjqjyhmvhlssucbnnapllypqqkxvscluqlppvetjrbcawiticpxmwpznwydwgdssrvfqqbfjjyiulvdeuxgxqbhufqgoiodrmwabpddkpgpjdvrzuizmjtabfzfxwvgxvovsyyobxqzywjvnsjaghcmqylbtczaszospurqoeskgqpcvftavnmvdanfpmzagtyexnxtuuranjtmjmgysybsapfxjhmckysqyqfzzhzrouffrdtqnuzquggfafttyslpaatzqzrxtasvzlkjmxotbokyiyovoageslmmhdpfmvlzcjpibafzvljpajhquvvcvhzo\n", "output": "2263\n"}, {"input": "4590\nxgjppsvyawdncypibhsdqcjujirrsseuzlmlumfghmhzfhitcsxvvvjlxaossljnxsbahubcrbcocbkniuvugszjkjvtgpyrafcreqtadwweinzfcnqqtthxwjwhskfzuuchpscaxofspftmxmznashgnvwmuexgctzyerrsjvwzqxljxadgbbmwpjjvnsfjbaiotqngmzovjtgqpraerlezfzxxsipvtdbgqffblvvaqnmrpduzbyoiojludalhedmbsukxunjfbrglyhykjlcuyehlzaortncydoumdxztzegukaxaoxhlvmwsgvexhgdwppkwmsbtalzdnzrlphihzqfaugjsieghuuiklyetzkbostblxnsacoipbdvcauebvidnbslotfqkcwdhwxrnntxyaufqalzmttsecoqgobihqblefxqtojbwkddrjtilgeazuyrmrtvfalqhrumsnhdpffufsurhbxyuotjpdqyvrrlqqhndfawxzevatrwocagsxiapwzcwjcqtmmzyjwrbbynvaxpdflbadrtiovbsylhzkgahmzhykwluqokgpenucajcffaaxibqrznkccjccnuxtithlvqwnrukuvdmzupprlvfvbjhjxboikxouhvbsmavktcgodlnyfdulyeamnijsrilkyljazkfdslfucvumafalruqanpchxbabdktmbkbidceklwwmwvhyynbjdhqvmsebxkwcimusuxpnebgprwyadsxxdppknlblqqsaykebjladbmxccohstadtlxgfgefoatjvqofrdwubwbfjqiunmnwyvpufkhpwzjogbktmqouxjdiqxoetleucumnpkyspeawmxtnpteaddppytjsqzpxemunhkyqakztweoefplqcklqmrupogoaalcdxszbkzbdhjfmsefwzvjtisexuewykmjzkzoutewpgvmerwhgmuaysiiitianbuldqcdcooskpegpvmlkhntbzllyxaevglcvcfmldnkyuplxkrvjsuaklwxydrihtqphvcluuhjtmywoebtpxzbotqtrbssuqlplhsmpnzlkybcswwtocqzquhyjdiciawssuyrwkldcobtacfxtowbsyxibvgwjgjoiexvdhhrnwlbjsiafbnlwbhhdvzzmiiyoicmupfjttzhxeoyqxafvwwkhzopqqrhnxkdpqxgjmrtviqwmvhexgelfchslftlziiifmtfvjnxkcnqosmplzjivgkvhgeccfidgyueqipdsrimpqsmqzwnlwezxvmbbissehcldsxbxjgzbpunuocqgivuiyiiyidvgfgxhquxzhgqgebzjhdlikeeyqdkpfqyxfyrpmiulxuotmpdqbmrdzgylkbomupgztgbgynmwxwhrbavrrrqsclzqmpwdyulnzibxryooxzbajwzhrotwktbmkpekbgydhqtunatcjawpvcwdfkhphevxhdqwrovnjazrvfxjphlwuzvymugcjrhpwnonpqmojbdpijqruexzulqhrcikgvjxtzqwfgrdgjvngfjeyekparlbautbltrauxiklfotuxepdotkqrtdwsvjbvajbxjwqgpptmvlfallusmauqebiqlvxsqmevrzkkqhrvbuyamquqahgqzpdvrtwzjjvigugjnsdietypytjeapennwipjclsurtycigqwtgmnynlxgreihwhhribwwdmmkxqznhikreygwendphzaicbwxeexaqmdtudgngrclccxjpqbvukkwfcybjocxiqhubrunkkgpfyahiviaetytpkrqwmlziedrksbwqpmznvvvgacbfiuchrfndvhmnutcgfvgbsrwogekslttupfhasleppxppsbjnqddonlubzekvduweuvqehuusyznqufqcpymlkjwoklybekmdhvpdbyleefuksrgrqugetcfxwrokbhefxcktfcncwemqxtlgpwhghsjwgpwusfbhaqtdoejnxjndychnqwhmyvmpmwpkjpnugxdchqcjrykorqhiesxwaeikmempmscmcuwmdkqoblcvjsindxarugakzuwpjibpnqlifwzvxnuuyninyeynzrlvofpagzjqhbgdfemfzreyslaygqnuhdletzppyggywzndltuelnskwujqzzmntppcoyorryatvokcmbvftrxolununxerdssjsaxoudcbrtfqbebspspsdsarrodyrymdhszjmyvfmlgootflwtxluxubqhrkxzxtuxigtrfchxhkejvdmodswakxxfkftpalprxoxqykcyqtvhjvdszwqvgvazrayyyktrljmlcobzkbwqmqlzuqgkupkairvhnslvvpmpfwrztmjrybfzquurtfjgxrwgwrrjdhmeawgtajeacukqdqcwgemdwgigsfhnwpvdweiiefvhgtsqyqsadvgslriiobfmpbrrnbyhykjlcuyehlzaortncydoumdxztzegukaxaoxhlvmwsgvexhgdwppkwmsbtalzdnzrlphihzqfaugjsieghuuiklyetzkbostblxnsacoipbdvcauebvidnbslotfqkcwdhwxrnntxyaufqalzmttsecoqgobihqblefxqtojbwkddrjtilgeazuyrmrtvfalqhrumsnhdpffufsurhbxyuotjpdqyvrrlqqhndfawxzevatrwocagsxiapwzcwjcqtmmzyjwrbbynvaxpdflbadrtiovbsylhzkgahmzhykwluqokgpenucajcffaaxibqrznkccjccnuxtithlvqwnrukuvdmzupprlvfvbjhjxboikxouhvbsmavktcgodlnyfdulyeamnijsrilkyljazkfdslfucvumafalruqanpchxbabdktmbkbidceklwwmwvhyynbjdhqvmsebxkwcimusuxpnebgprwyadsxxdppknlblqqsaykebjladbmxccohstadtlxgfgefoatjvqofrdwubwbfjqiunmnwyvpufkhpwzjogbktmqouxjdiqxoetleucumnpkyspeawmxtnpteaddppytjsqzpxemunhkyqakztweoefplqcklqmrupogoaalcdxszbkzbdhjfmsefwzvjtisexuewykmjzkzoutewpgvmerwhgmuaysiiitianbuldqcdcooskpegpvmlkhntbzllyxaevglcvcfmldnkyuplxkrvjsuaklwxydrihtqphvcluuhjtmywoebtpxzbotqtrbssuqlplhsmpnzlkybcswwtocqzquhyjdiciawssuyrwkldcobtacfxtowbsyxibvgwjgjoiexvdhhrnwlbjsiafbnlwbhhdvzzmiiyoicmupfjttzhxeoyqxafvwwkhzopqqrhnxkdpqxgjmrtviqwmvhexgelfchslftlziiifmtfvjnxkcnqosmplzjivgkvhgeccfidgyueqipdsrimpqsmqzwnlwezxvmbbissehcldsxbxjgzbpunuocqgivuiyiiyidvgfgxhquxzhgqgebzjhdlikeeyqdkpfqyxfyrpmiulxuotmpdqbmrdzgylkbomupgztgbgynmwxwhrbavrrrqsclzqmpwdyulnzibxryooxzbajwzhrotwktbmkpekbgydhqtunatcjawpvcwdfkhphevxhdqwrovnjazrvfxjphlwuzvymugcjrhpwnonpqmojbdpijqruexzulqhrcikgvjxtzqwfgrdgjvngfjeyekparlbautbltrauxiklfotuxepdotkqrtdwsvjbvajbxjwqgpptmvlfallusmauqebiqlvxsqmevrzkkqhrvbuyamquqahgqzpdvrtwzjjvigugjnsdietypytjeapennwipjclsurtycigqwtgmnynlxgreihwhhribwwdmmkxqznhikreygwendphzaicbwxeexaqmdtudgngrclccxjpqbvukkwfcybjocxiqhubrunkkgpfyahiviaetytpkrqwmlziedrksbwqpmznvvvgacbfiuchrfndvhmnutcgfvgbsrwogekslttupfhasleppxppsbjnqddonlubzekvduweuvqehuusyznqufqcpymlkjwoklybekmdhvpdbyleefuksrgrqugetcfxwrokbhefxcktfcncwemqxtlgpwhghsjwgpwusfbhaqtdoejnxjndychnqwhmyvmpmwpkjpnugxdchqcjrykorqhiesxwaeikmempmscmcuwmdkqoblcvjsindxarugakzuwpjibpnqlifwzvxnuuyninyeynzrlvofpagzjqhbgdfemfzreyslaygqnuhdletzppyggywzndltuelnskwujqzzmntppcoyorryatvokcmbvftrxolununxerdssjsaxoudcbrtfqbebspspsdsarrodyrymdhszjmyvfmlgootflwtxluxubqhrkxzxtuxigtrfchifvybxakhsyaqiakliuuxzeksdcmqgkdkavcceqxsxl\n", "output": "2042\n"}, {"input": "4872\ncoxyyvvmjbeahvzaszhhkxvaihipzsigzxrearsoxwchiqqnwdbdopjonowqptdxzwhqjxyputgpwgblbznfozqeiboksyspozamhhkhkzpkvjzwaqlewlmvjqaynkiwfpjewnctqirapclcqvrfbnebqikptxpjhqwidjhyornghqqjkjjnkgadtlvluioryhdmnjpomxtrilypbwrgjvekgmylgjwaozlwiaxirgzhcjtruvjssmpchabzwuzumgnrleogwqjaxtguogougrmxdfyrjkvqqwlzabcaxqzrqpkouvohbfoyyxgmxosfnqbplsttmpfxfrlykhuxcrgztsdlmsbhapsquwqosngygpnpvrxkqhdnyhgdfixigzxwhhdgieawxpzzpiffnnevtlqiheoxuqelygvciltgqbiiuyavrmlyskpiaazhlahhqczteroarmqktrqmlivrpjvrpkpwkwjbtxwcjsutzcrenxgisumxshzewxokrzdahrfbskzguayjmjdigboraiycprmmygfoxsbrtomyxlexjavlpnmdtgkhraxrqvhgupzaslfeppxtgqhrkktjchherpiltuuzcthschqzocvqlcubedfcziqbxlqaogdfqepmwzdegddapyoxrdhqysnmtudlukbkbtglklapfkgdvifppmzybnnvqyerlqnnjucdszlyehcvmxsevglrckrypcpknwwsqnafrmxiaczzgwvbagebbumjxryixrdnmudlwxskkbmodqqegvdibppfllfcyrwkwzntviygusyetsnpjdyxkpnoucedshyvbquoofigacjetfezygzmbtdonnnphavmngohgbfrxzftyutjjjzzbllswdjgtqlqxbiyqvxxlutnutjtxhpseddfqmkrhzhpnmjbczbldahcdrmnbwyrcvkzvzxfmyoyfjqeyhlsqposkknjqmcofldjtouuxskkfuvfpczyyftwiuzhzedkepizfxnqiltrrpeoqrlpnnsprekpphfciippaxuulxopvqgqxknwjfnpyjgxndvclardulbjhiockljrqtpsfcdltzdcrwkksegfjjkxwzbdulqhcbebszdsahsbbtqfowxxuzggzdlxnugzsponrvlyppcygbftfgnuozjzxxvrmirkidzvkhtfypbwxwwrlmycfvyvkjyvogpkuhgcxsabpzenswasoeasjnbigxqdtrnpteesbcnrdlqlzaluhugqneckaedyobliktlfsugaoxbpviedlbdeqsfqbhesbrjyvccwjlpqaypkdvbwuvjduvsjxsewqyjpentjezmisgjqjgcppnkoualrsdlkfwvsylodygfjfbnvdbastbfkgwdgjdvomndlmtnfofaxrkfyomcnimmhutmregniljqysrqsxqdmvofqegiwqnmfbpsdrvasxbklstrpgozerlttuwmbrdusmroqaroeeeoelxfveilafyfbbhgzubtptqfmxafxrixfahwbplzzgvqbbkmsgeadweboaiwvukvhbrclkcbllayoayazlqyauivvkouzpaemurevweszcwcqrqtncoebucqtiplkhwtcamfczgnevuoqfixigjeirgyuqzusjupqipnrtekuazcamkkihpovsjlzmknrsyypgojankpzrjisqnjszedzuafhnxkpyiqlirdnthndiksbumhxuoqdcxnknuabpztcnhtnxhffikoiphgpnejacogovfcepngrupbsbpfyvkpdxeimljskzyaesiottfslzjpzbszyjrrwqscvgtyrbowlgzyakxsogkphdeuovlbilwhavldnevfhhslvubgbkkksuxtqkzakxkbjvqqdlibqqealsfyqglsicvywsfcmkarwusyansuxpgnoabdtkwryohtmilbykbbtulliuqwfnggnszthagclrmzyayjpyebslphyweywvmqauyvfbhgxvztachpyzvougjvoatdoalioucgcqvtacsdlrnquheznowssrlnivhiuihmwvpepzvpranisksiitpgghsjftnmpzyhpourtspyroukbpttwaujgovornelepeqpiwgkhspvaplemgshefqcflnkvuysphdnchpswvafhktflqdrtnzfrqtbhtkpnukcqoigvbtdgaolqdyjzojvyyvpogyyxajcigjnyslvfbtuhlekmflsfgxmkypgwbwrhxvviybbnzoosnbqxqypqjeyitwnhvjwcvqypxzwifxwuehztvrjffeczhhrpqtgxfozqkzmccwjiwxtpavstrmjrnsxohmlcsyeqqygokffypsnbnvvnfwdghmhstreiudpngfqnuemyagmnkdgdtoqnzwvzgzhezpqzkxvaihipzsigzxrearsoxwchiqqnwdbdopjonowqptdxzwhqjxyputgpwgblbznfozqeiboksyspozamhhkhkzpkvjzwaqlewlmvjqaynkiwfpjewnctqirapclcqvrfbnebqikptxpjhqwidjhyornghqqjkjjnkgadtlvluioryhdmnjpomxtrilypbwrgjvekgmylgjwaozlwiaxirgzhcjtruvjssmpchabzwuzumgnrleogwqjaxtguogougrmxdfyrjkvqqwlzabcaxqzrqpkouvohbfoyyxgmxosfnqbplsttmpfxfrlykhuxcrgztsdlmsbhapsquwqosngygpnpvrxkqhdnyhgdfixigzxwhhdgieawxpzzpiffnnevtlqiheoxuqelygvciltgqbiiuyavrmlyskpiaazhlahhqczteroarmqktrqmlivrpjvrpkpwkwjbtxwcjsutzcrenxgisumxshzewxokrzdahrfbskzguayjmjdigboraiycprmmygfoxsbrtomyxlexjavlpnmdtgkhraxrqvhgupzaslfeppxtgqhrkktjchherpiltuuzcthschqzocvqlcubedfcziqbxlqaogdfqepmwzdegddapyoxrdhqysnmtudlukbkbtglklapfkgdvifppmzybnnvqyerlqnnjucdszlyehcvmxsevglrckrypcpknwwsqnafrmxiaczzgwvbagebbumjxryixrdnmudlwxskkbmodqqegvdibppfllfcyrwkwzntviygusyetsnpjdyxkpnoucedshyvbquoofigacjetfezygzmbtdonnnphavmngohgbfrxzftyutjjjzzbllswdjgtqlqxbiyqvxxlutnutjtxhpseddfqmkrhzhpnmjbczbldahcdrmnbwyrcvkzvzxfmyoyfjqeyhlsqposkknjqmcofldjtouuxskkfuvfpczyyftwiuzhzedkepizfxnqiltrrpeoqrlpnnsprekpphfciippaxuulxopvqgqxknwjfnpyjgxndvclardulbjhiockljrqtpsfcdltzdcrwkksegfjjkxwzbdulqhcbebszdsahsbbtqfowxxuzggzdlxnugzsponrvlyppcygbftfgnuozjzxxvrmirkidzvkhtfypbwxwwrlmycfvyvkjyvogpkuhgcxsabpzenswasoeasjnbigxqdtrnpteesbcnrdlqlzaluhugqneckaedyobliktlfsugaoxbpviedlbdeqsfqbhesbrjyvccwjlpqaypkdvbwuvjduvsjxsewqyjpentjezmisgjqjgcppnkoualrsdlkfwvsylodygfjfbnvdbastbfkgwdgjdvomndlmtnfofaxrkfyomcnimmhutmregniljqysrqsxqdmvofqegiwqnmfbpsdrvasxbklstrpgozerlttuwmbrdusmroqaroeeeoelxfveilafyfbbhgzubtptqfmxafxrixfahwbplzzgvqbbkmsgeadweboaiwvukvhbrclkcbllayoayazlqyauivvkouzpaemurevweszcwcqrqtncoebucqtiplkhwtcamfczgnevuoqfixigjeirgyuqzusjupqipnrtekuazcamkkihpovsjlzmknrsyypgojankpzrjisqnjszedzuafhnxkpyiqlirdnthndiksbumhxuoqdcxnknuabpztcnhtnxhffikoiphgpnejacogovfcepngrupbsbpfyvkpdxeimljskzyaesiottfslzjpzbszyjrrwqscvgtyrbowlgzyakxsogkphdeuovlbilwhavldnevfhhslvubgbkkksuxtqkzakxkbjvqqdlibqqealsfyqglsicvywsfcmkarwusyansuxpgnoabdtkwryohtmilbykbbtulliuqwfnggnszthagclrmzyayjpyebslphyweywvmqauyvfbhgxvztachpyzvougjvoatdoalioucgcqvtacsdlrnquheznowssrlnivhiuihmwvpepzvpranisksiitpgghsjftnmpzyhpourtspyroukbpttwaujgovornelepeqpiwgkhspvaplemgshefqcflnkvuysphdnchpswvafhktflqdrtnzfrqtbhtkpnukcqoigvbtdgaolqdyjzojvyyvpogyyxajcigjnyslvfbtuhlekmflsfgxmkypgwbwrhxvviybbnzoosnbqxqypqjeyitwnhvjwcvqypxzwifxwuehztvrjffeczhhrpqtgxfozqkzmccwjiwxtpavstrmjrnsxohmlcsyeqqygokffypsnbnvvnfwdghmhstreiudpngfqnuemyagmnkdgdtoqnzwvzgzhezpqzkj\n", "output": "2425\n"}, {"input": "4667\nwqskksiecbvesooovqpltsztarrlezxthvmjzbnyimkcuivvjdmdhymmbalwmnhjjkmlkxgzyoafwikuxemluxnybvbwexoyxjjcxcppheljnhmrinsqmqkcethwsrdxiyxoggmanwiwxnfznefgmmttzyjhynaduefikpqfujgmzcerkzlxffsblhjdvowwfmnncaaxvtdiutklslwhtfejgztgysmsoontxqqgbcltwdxxlyhdebrijsmzfrhibgtulbcowvxpbgbipvtuneqqgyqpqawicodbgidqufrdvgshhqihgiynfmbewiyulwikfbmetadgrbelimstskylqhoznjeoguwwxklzvgdgqwfziximfzvmasmtffdzkqijnqbpcczqmwixhjehuktddapuqsooghafdixznxkqrwaiowuixerwtegbfmfdreozzshifvtfldaenrafvtkbvbeansawyocizevswpjxoxgjmlumernqdvuvupleuctiqbwrunignmwcgmazpfkulsqfarepiscreeydgdajzpvmkifdpmmpvlsccglandzgppwlvlfhsnfjukrauebbpdtjjwznmlosccjallyudyxhcazxweptfylxnsqiniadecfzongjnpmbwzjvaflywapewnrxkjwrxhqgbmrmcwigawfmrfgusmiyxnuayzgjwicpzahbyzxgsersviqtclgsfnddvcuyhimnognbfrmhteplakzgutdbmitzuxtgehtskeulszcwjhbklcwqiqepgalqcmijvxudiuuwibpcoigooxabrfooitosprnicvlhfmuaandrpfghqdrzonlrxoyafrmmhaycxumngkvddmiyebvpcehytnpbzzanjuykaoghixibgquczjvwvejjecnlhmacevlzbjafrkulwxwxmvmydqnktnvxftslemawbxsqjnlkciezuegmojxbbckwnpswiynamzwwdfatnayacpyqvdraudsmxvzmnpfwizbaddwqnnkrsnygxulehrutphisbfbmkvdalsffldfbymwdudvuwcgtyatutdkcpxsojdlshffqhixajjsgdxujaakivtvjtrhxzfhbdtpferibnursfbwgshcvrybtaftgdrbywfzvncrouaoftooylaaohxgrxumwmzixhrpeyccdkothfqgihyobbjrszapouwxxplbmadmajlftltdiyplmbrvoisodgqrpznnupqajkbmyyodqlqbwywexgetqnfvhokxocvjvgilgtquuqvcaqxgyqknpjoorzboqqwqkrprxskfkfwdodeuzhcpzqwxssuoklroyujeqhonoaajuahyodsuaojgpatqkvscaasoqpsyrneavelotgojqknjedxkqvborhqclfnlhoqsovlcgxbforvdlfcoranbrnaejxdppisqralevtjrrlyxdvrwvoihcwxvzfhajmmrubzsdydhxpitbetgbtaefbnwpenwhoqlemipiehefmvttyiubuozfpwmpnthkgogenctbgbmbgscbpgxnbjtoerclpfwhdtjuwetxpddnvyneyeplwbgdrldlxnihbdferjgmvrolebmvqyttbbmsosupitjuvcuvrfgwkvytvtrmvghzafifnanitewasfyismfyzixbktpvuijezvntwamjkoptodobunqwdauadgorlyfgzhphzvyetieqlmzyallscklgoojuukpgdrkpizxvhvpqtlxohaqagkoxbmxjgvjrvbhhaqyjjxazruyqhkniuqucdaovmjadbczqrrmwnshgchluhcwxjkyifqijybszhmfkarpdpyiwqyvweyiogurctpxjoqxptgbgpoeblrkuksqqcvccpjtyenilxclmeptvztqwaqwbtfluktxowxspbsnbhsepnigxaqtpmcytlbwfnqiajfpssvtcvzjkikgexsfxcdoryufwfnfyaxnjsbnyifahahhjvwvuoarwtvybfxoaxflbiqjkqybjhkrnmcedmfpypttygmguocloeaxfumsjjhhgsiinqqtuqmrmsgwiqtriamurfcdivgkiufpekkuieekjrmmprtmuyphwpbskgmywdjoukyqeioqsdeurnpahcxjjkkkfgmazrzmifnzltzwmdaneriitaqwfchczrodduwdgjngmtpdlquuxkdaeqhmeqisfqmbcpyigiykwcqtlfefrgcwbtkboreoqyegxwbtytofrjpbfsuakamwjyukdxfvikfbmetadgrbelimstskylqhoznjeoguwwxklzvgdgqwfziximfzvmasmtffdzkqijnqbpcczqmwixhjehuktddapuqsooghafdixznxkqrwaiowuixerwtegbfmfdreozzshifvtfldaenrafvtkbvbeansawyocizevswpjxoxgjmlumernqdvuvupleuctiqbwrunignmwcgmazpfkulsqfarepiscreeydgdajzpvmkifdpmmpvlsccglandzgppwlvlfhsnfjukrauebbpdtjjwznmlosccjallyudyxhcazxweptfylxnsqiniadecfzongjnpmbwzjvaflywapewnrxkjwrxhqgbmrmcwigawfmrfgusmiyxnuayzgjwicpzahbyzxgsersviqtclgsfnddvcuyhimnognbfrmhteplakzgutdbmitzuxtgehtskeulszcwjhbklcwqiqepgalqcmijvxudiuuwibpcoigooxabrfooitosprnicvlhfmuaandrpfghqdrzonlrxoyafrmmhaycxumngkvddmiyebvpcehytnpbzzanjuykaoghixibgquczjvwvejjecnlhmacevlzbjafrkulwxwxmvmydqnktnvxftslemawbxsqjnlkciezuegmojxbbckwnpswiynamzwwdfatnayacpyqvdraudsmxvzmnpfwizbaddwqnnkrsnygxulehrutphisbfbmkvdalsffldfbymwdudvuwcgtyatutdkcpxsojdlshffqhixajjsgdxujaakivtvjtrhxzfhbdtpferibnursfbwgshcvrybtaftgdrbywfzvncrouaoftooylaaohxgrxumwmzixhrpeyccdkothfqgihyobbjrszapouwxxplbmadmajlftltdiyplmbrvoisodgqrpznnupqajkbmyyodqlqbwywexgetqnfvhokxocvjvgilgtquuqvcaqxgyqknpjoorzboqqwqkrprxskfkfwdodeuzhcpzqwxssuoklroyujeqhonoaajuahyodsuaojgpatqkvscaasoqpsyrneavelotgojqknjedxkqvborhqclfnlhoqsovlcgxbforvdlfcoranbrnaejxdppisqralevtjrrlyxdvrwvoihcwxvzfhajmmrubzsdydhxpitbetgbtaefbnwpenwhoqlemipiehefmvttyiubuozfpwmpnthkgogenctbgbmbgscbpgxnbjtoerclpfwhdtjuwetxpddnvyneyeplwbgdrldlxnihbdferjgmvrolebmvqyttbbmsosupitjuvcuvrfgwkvytvtrmvghzafifnanitewasfyismfyzixbktpvuijezvntwamjkoptodobunqwdauadgorlyfgzhphzvyetieqlmzyallscklgoojuukpgdrkpizxvhvpqtlxohaqagkoxbmxjgvjrvbhhaqyjjxazruyqhkniuqucdaovmjadbczqrrmwnshgchluhcwkzkydfskqncrbpdnulhutwzswrsmwrypqxiqeuicoafgswmxwjrylmbkiqcnqiphshxdulnszdfntywjzitoyvnnqekbmakwwsbzkiduhvrbdwkfybgcugexjqtxmxzeuwczbehapsypatzpwnidznmjdyyigpanokxwjajhmouxinlufezeakkokowylnnemqzkmwfkejznuogepwgdytwwxxqirefwrmsjvazrncvofbrpflvodeeptavqpiqxfxklnprsjaritfnqcyuwgzcnixksuqrhaeopezlyjnqoxeimyonsipojzevjqlczjbpkwpaqksqbpqszldwgfqyqskuwhrfcfidiwmbalxsjzokkgsxgbabkjvynequugfgwjqwcwswiwfblpezbcoxkzaewmmfvfipmlfxxbfelnfrmyjaqdtcfroexrgomifruuyfoxiqkrokrdhtjtjzrlxeojzatxckufdyfstilyxbwynfiatbavdzlaltcwszsphfmftekybblvjyiznqzsrypvdmxtuuswjtliudlteehxfwkdpvanmnqjswiusvhcscevabqoowahtqoqskhikionmxngftnypmbcwggwgiertcaibtwfbyqnfbhzlxttbkgjvdnvlpalbontpnjkwgnzxojlerbpnjigftcbpzrsiafiftgregpibxbbzbfkdhqcrgwhyentmgbsiquujyaqypdytvxbtqmvqltytbhwuykdfojxhljwuioekfjxgnvqhpfahrjdbxoywxszthhvujkkcf\n", "output": "1541\n"}, {"input": "4865\ndhqcnjiujbxdqecdhfjcemibxfoodtqoylcfjmvydmtcxtkwtqbqwijasvqslkfzeerhhmziibybdugafsnlolhxpugvjaroddjsxwvfmxgvqrfuqjrvkiluztqroqkksphddpkswaimagarnrhsepbvgsxnkpujesqpgfspfiwkbqbkhsyinxznzsovzjqpwzvbqjagsmkfojfsfwaljgkxgpbtrfiynibwflxigitgfxjrosowljtgkxjubqlqsdwerqjfkyttruesbzflftiuxataoweftitzeuvuuruamlqetkbnwohjjpqczffihyaspopiwuhmcvsxbuatoaosntyyhexqtkxwdphzcjzocvkiikvdlifxqsgiiodplnqpyxuzuocslduedhfrcxwfqlsxplublojiatrtqugyfhiqoouushmjvpooftfltwgakxqcpqzfkqknxvynbijaekdwsztwhmgnlrzqtcolpsaabfeewzwnsmmukgdghajpbwvyiguhxqltucthbjkzdxutpotrcmwpklnmnbokinrddirhqkdelahgarvcofhrhztaboiscvwqhyylzmfxxyhfogsejbyxoclzotgvmgflypphgqrdapuhsophgrbfbyhelqncvuzmgtppbgtiuafcodklweufilndfwtmfwyhztowdxlglgnuklffvuttxqpykyhpgvrucxcvkqhkmnkandhwhbfcossyycudfxozcxawswjwmhovtshgreaesneodmyhtdfoeerzuydtdcedzctncptuywfrgrjpasogyjvbvvoktzfxbubmoycqgngssowfkszviaqvjmcephxfbuowkjniqeqadlqjotalrnpfzricoivfnuqxkcccnxvowexhhosrhubzdyhxedxjjnatmrbenwnuomtdvrxgnhuopydydddvxwvzjpmktjlrdedkpeumyesptcmvgedxqnnsohafwlorhcvhrtjguqoqfegkgebcsgouhbxfksqisyzchowltjdxzwqkbnrsmabzalehtebpxxnlozehchvrglxtxcczzubwnafykgmpxkjdjdoazruxsroodyisxaqdsqmwahmiyntqisnoeoxajprmijfeyeidbqjznxrmragfrdvshunjioibkkohousbflixtnyuqqbvffenisgfigcdfuuswghnyjrnxflhbkkypiczhitvdfnowxhjnirduwrqybwloojyjqunpuerwaorgfimbiencpmqqdsrdmbyrphfepfthkcfnkbyndjrzmjozxmdyfadeghvnmnachrbxxaecivhpnarsdsbyujdpijtntptbtlpthcbwpytayppbewctlzswxnfqmrsyjgvyognnrssbxmacwhxkkqfvcnrwtjpfilqmhjyqemfvgnapjuohyiyeenwauatfetavpgylcogqamkembzeeihdvhahnlhqblcooyiokpzxvabzqavlfaygzlsrfqjywntvownbtufkuhvlzjlyurfpdkgqejcurjtjdknmzlhbakdjiwcbeaetnweeyvefbeabkzhncobnhtgjafwboouzfggughflvyofmtpldttvxskxjlhkuygbxgqzldujmsuxhunalmakxlxqtgntczmanasorvyhxyzgklkxmxppgayacilslqakzzjrkqflvxujipnkscivshtqbqspajvzukripxprbkhuluzhoolzpvutllquxwdoiiyalchvlyoxxxbkdihjsodtgpndcipcohrnazkvbcizaumhlslulzembocywfwhvdzgxbesqvzltxpiaybiahzvmryyysyfzagqqxvwhxoyzfcwfjrnhadzvhtzoutnwtdzltozutstutqfheqsucmotshiolqkqxtvlnwitsnfvchgursmpzlcdqvbxfwckyknpwlatkfvmcxmlqkntiegcgouonbbttopglnjyfsztndvyoddoybpchccvijeqmtjyipytwfnebyntyvtpvejxxowwkbqlpevtzchzdxorfoafemqvyjwzjqlapflaacnjtwaambhacyhbeviigsrpxifmdtxapdpbrzdmjtmqiwzzppkydeegxtmcxlnnekmwfkimwrzppmptvgyexnziaoaaypuaufkwtglfzyxoaedyleixooeexjkpxtaznmarglrfpcvlegrpwijblhpkkejkyyjtkplsxteisungdqayubuwzmcuhpvjftczzknoglujdvnlutejdhokuzmmtijgrqmoifmxfsmvrxoajfegiqmahwegnlmigdvbmbtavsfasyvzaqkvcdtlcvkxqbnvikpmkbbedfasbuoewmcezsgkbeqyfijkwyadgvvqysxuatrptxvesppqfguqnggpnvhkdjsfqbzpyygcanbwnbugbnqmjtmgvqqylqwgfjpxhoijqgmsiqzgdjnjnglvnmlhbefinwzfnrtcfgaypvogvhzrhocompnmbpddfgltoitvnsytaoggdkhamtgisnddndnlhgoctalejdxkzlifxoghhsnonhzokbcbcivhtxkoopbqbkhsyinxznzsovzjqpwzvbqjagsmkfojfsfwaljgkxgpbtrfiynibwflxigitgfxjrosowljtgkxjubqlqsdwerqjfkyttruesbzflftiuxataoweftitzeuvuuruamlqetkbnwohjjpqczffihyaspopiwuhmcvsxbuatoaosntyyhexqtkxwdphzcjzocvkiikvdlifxqsgiiodplnqpyxuzuocslduedhfrcxwfqlsxplublojiatrtqugyfhiqoouushmjvpooftfltwgakxqcpqzfkqknxvynbijaekdwsztwhmgnlrzqtcolpsaabfeewzwnsmmukgdghajpbwvyiguhxqltucthbjkzdxutpotrcmwpklnmnbokinrddirhqkdelahgarvcofhrhztaboiscvwqhyylzmfxxyhfogsejbyxoclzotgvmgflypphgqrdapuhsophgrbfbyhelqncvuzmgtppbgtiuafcodklweufilndfwtmfwyhztowdxlglgnuklffvuttxqpykyhpgvrucxcvkqhkmnkandhwhbfcossyycudfxozcxawswjwmhovtshgreaesneodmyhtdfoeerzuydtdcedzctncptuywfrgrjpasogyjvbvvoktzfxbubmoycqgngssowfkszviaqvjmcephxfbuowkjniqeqadlqjotalrnpfzricoivfnuqxkcccnxvowexhhosrhubzdyhxedxjjnatmrbenwnuomtdvrxgnhuopydydddvxwvzjpmktjlrdedkpeumyesptcmvgedxqnnsohafwlorhcvhrtjguqoqfegkgebcsgouhbxfksqisyzchowltjdxzwqkbnrsmabzalehtebpxxnlozehchvrglxtxcczzubwnafykgmpxkjdjdoazruxsroodyisxaqdsqmwahmiyntqisnoeoxajprmijfeyeidbqjznxrmragfrdvshunjioibkkohousbflixtnyuqqbvffenisgfigcdfuuswghnyjrnxflhbkkypiczhitvdfnowxhjnirduwrqybwloojyjqunpuerwaorgfimbiencpmqqdsrdmbyrphfepfthkcfnkbyndjrzmjozxmdyfadeghvnmnachrbxxaecivhpnarsdsbyujdpijtntptbtlpthcbwpytayppbewctlzswxnfqmrsyjgvyognnrssbxmacwhxkkqfvcnrwtjpfilqmhjyqemfvgnapjuohyiyeenwauatfetavpgylcogqamkembzeeihdvhahnlhqblcooyiokpzxvabzqavlfaygzlsrfqjywntvownbtufkuhvlzjlyurfpdkgqejcurjtjdknmzlhbakdjiwcbeaetnweeyvefbeabkzhncobnhtgjafwboouzfggughflvyofmtpldttvxskxjlhkuygbxgqzldujmsuxhunalmakxlxqtgntczmanasorvyhxyzgklkxmxppgayacilslqakzzjrkqflvxujipnkscivshtqbqspajvzukripxprbkhuluzhoolzpvutllquxwdoiiyalchvlyoxxxbkdihjsodtgpndcipcohrnazkvbcizaumhlslulzembocywfwhvdzgxbesqvzltxpiaybiahzvmryyysyfzagqqxvwhxoyzfcwfjrnhadzvhtzoutnwtdzltozutstutqfheqsucmotshiolqkqxtvlnwitsnfvchgursmpzlcdqvbxfwckyknpwlatkfvmcxmlqkntiegcgouonbbttopglnjyfsztndvyoddoybpchccvijeqmtjyipytwfnebyntyvtpvejxxowwkbqlpevtzchzdxorfoafemqvyjwzjqlapflaacnjtwaambhacyhbeviigsrpxifmdtxapdpbrzdmjtmqiwzzppkydeegxtmcxlnnekmwfkimwrzppmptvgyexnziaoaaypuaufkwtglfzyxoaedyleixooeexjkpxtaznmarglrfpcvlegrpwijblhpkkejkyyjtkplsxteisungdqayubuwzmcuhpvjftczzknoglujdvnlutejdhokuzmmtijgrqmoifmxfsmvrxoajfegiqmahwegnlmigdvbmbtavsfasyvzaqkvcdtlvtsuwzdkizsxkirhltzkkubxqzensrqltiwbetmvzahgdqn\n", "output": "2198\n"}, {"input": "4764\nysafhskivjwxcnnuxvctyvrctopcgwoexymeyfjixivhzgemeffxeekkobumxfbnbemjgjghqdcgurjvpbhsghjopakiolljvdyxbgjlqjxcyszsvxbarxyjtcfskydaxuncsxaosrslbxenlblfaaglycvodjioteffvlcdljnautduxynxkwwowhqtspedwlhqfmmhmaelbodjeacrmsovdacchtuchqpvwfewmraiuaziwfvvancknwgvhbwrwretnsvbhgqexrthwcljdbumhdvmzqbporaqameyajltvgrujljwkxhioefzqhicteedfvmpftmhomgznwmavufxegrxjmhygpblmdnsqvyhxbipuufugejmixxsbrqgwlnafvdrctesluexqswmizcanfrvxryjbcgiiiyootskmschkisuwccezmxxlpufpsjwwmjewoulkdgrvgpcmdtiuxfeiboxxnmnxotveffiipqidrhsyzmlbjxuydwbcmtlayumrmsiuueutqhonbkvywecdorvgsqobcovenbvbdaodzcvsmryttmwgpujzonvsdogpdykordfxuotbbxziikuyihjisixjodjwoefwwpzebbhotjxdtsulbunyqmagqtyavwmafxspumnqnpswyweorymfnrordzzynmidfzdflsvirdwyxkevlwovfqmrpzntuuwqkjrepvasnlehkcjqdmfxledwcpauuputevamycxgcrpmyizidyqvybvjntpagaaakzgvmblbirjaljbwshipixayjzvshfgqghsgquamwuobvleqlirrnbhfsrseveqxcslenwwxxrpxfcoqkbkxxrjgmmavomseeuhrbmhwbsjgezzmdqdlzdmloipvbbdkykqwciceahkhqteiqsoaixkabzsazonbmbtvfcumjzgdsesklmjxqrwwbuihkscrlhiehbxsnwmjtblnsrogufzprgppenrvxgdrqaucalzljnfpbetrjgbufxwacprdjwkuwyurorxvquksngffhgcjjyyirnapvehrwoniqacgagrbbaojkcrsntfcruwjnbopdphxikpacbhxxwkdrtvhxujvieylzboszkswsuvklipwhoszizuwxjphbxbfrnyojtzckfcstopfibxqnygfaahgwajspcusrjlawnkyvnzcdmhukdofalrtgmnzykcvjeksekksrasjovnutijiblnbgllqipdhuwvgbrfsvfmrrlrzevfxsclumtvheflptefxpatgbwwzfsrryeiuaerawvetgvbpmtoihnbhjrlzbwfgplhrlqmicybsymypvnijaurtrithbknpgglejfypqwefomwhhwjgevlxyvsndnvdoaodvrmfwdnzaebtvteqroesojvhwjgapziwajvpsqgqkdmtbtsowopwfmubpqaipwwemrhjxkfypnwmlmdgckangptkghjevspjkzcrafaolutetruwjaximawazzyfzlxoeoqehvecxxtftcbhlypztxvdzsmltrmnivqtcnjmlwxyfzcqxfnwuzgurebwlrvqgntscwjqrpgwkdhlhphfwlqejewlpbxdswpnimxwzwybmlmkrxfqbyhdjvrytriwkazzgbkubnhidrdcreinbigbohimshundjurqmyvfcgkentcpojvmrqlrexusjqbjyofdebnsgdjsxuytxcevbxqodovstaummzxctezypolfpvkkinpvvdmwzxcrwxtlvoyltuigkvelrsljgddeafoturozeiaxtbjyrfyqdsvjmvuklvqbivirqemmshhepixyxezeshfyeubrrqucscafcawbpenfahrbmfkadpgyvxelpzjttdgytwsybctqmesmbgkyypnnoeaspbswjtccfdffkwybortgvkrkrbkemwcrfxsjqxqxqlauhgmxylihjunzbhbmpjafrlrwosrijnprygnjmumvqbuxiqbtngykpcigqjtuxhycbvpscznpxsftzgnwbnzctugrbgenunqewatnmmpwmyzzukklmkkomxdbjrhlqnlthkshmxvwfmnvkdiwsxlkpundzblxypayggypfosnruhlklpyziidgovijqayrzgckdixxrcmzbrrvsdssxsmzvnczhesrabffktskcpgvnwpszzoobmqljhojjkxmspvubvclgkrdoqmkxckhamgwpbdbwrczrvicmydffgferoqlsgfcoojdyhipwtevqytzqgkuczjbztuqmqcrozijoncagtdyaqppouyjghesshsceqeizgzufqeeghnmltfbuxzuxnabwwhvpqgqzpueummxsfeveksehonjxonfcknaosrslbxenlblfaaglycvodjioteffvlcdljnautduxynxkwwowhqtspedwlhqfmmhmaelbodjeacrmsovdacchtuchqpvwfewmraiuaziwfvvancknwgvhbwrwretnsvbhgqexrthwcljdbumhdvmzqbporaqameyajltvgrujljwkxhioefzqhicteedfvmpftmhomgznwmavufxegrxjmhygpblmdnsqvyhxbipuufugejmixxsbrqgwlnafvdrctesluexqswmizcanfrvxryjbcgiiiyootskmschkisuwccezmxxlpufpsjwwmjewoulkdgrvgpcmdtiuxfeiboxxnmnxotveffiipqidrhsyzmlbjxuydwbcmtlayumrmsiuueutqhonbkvywecdorvgsqobcovenbvbdaodzcvsmryttmwgpujzonvsdogpdykordfxuotbbxziikuyihjisixjodjwoefwwpzebbhotjxdtsulbunyqmagqtyavwmafxspumnqnpswyweorymfnrordzzynmidfzdflsvirdwyxkevlwovfqmrpzntuuwqkjrepvasnlehkcjqdmfxledwcpauuputevamycxgcrpmyizidyqvybvjntpagaaakzgvmblbirjaljbwshipixayjzvshfgqghsgquamwuobvleqlirrnbhfsrseveqxcslenwwxxrpxfcoqkbkxxrjgmmavomseeuhrbmhwbsjgezzmdqdlzdmloipvbbdkykqwciceahkhqteiqsoaixkabzsazonbmbtvfcumjzgdsesklmjxqrwwbuihkscrlhiehbxsnwmjtblnsrogufzprgppenrvxgdrqaucalzljnfpbetrjgbufxwacprdjwkuwyurorxvquksngffhgcjjyyirnapvehrwoniqacgagrbbaojkcrsntfcruwjnbopdphxikpacbhxxwkdrtvhxujvieylzboszkswsuvklipwhoszizuwxjphbxbfrnyojtzckfcstopfibxqnygfaahgwajspcusrjlawnkyvnzcdmhukdofalrtgmnzykcvjeksekksrasjovnutijiblnbgllqipdhuwvgbrfsvfmrrlrzevfxsclumtvheflptefxpatgbwwzfsrryeiuaerawvetgvbpmtoihnbhjrlzbwfgplhrlqmicybsymypvnijaurtrithbknpgglejfypqwefomwhhwjgevlxyvsndnvdoaodvrmfwdnzaebtvteqroesojvhwjgapziwajvpsqgqkdmtbtsowopwfmubpqaipwwemrhjxkfypnwmlmdgckangptkghjevspjkzcrafaolutetruwjaximawazzyfzlxoeoqehvecxxtftcbhlypztxvdzsmltrmnivqtcnjmlwxyfzcqxfnwuzgurebwlrvqgntscwjqrpgwkdhlhphfwlqejewlpbxdswpnimxwzwybmlmkrxfqbyhdjvrytriwkazzgbkubnhidrdcreinbigbohimshundjurqmyvfcgkentcpojvmrqlrexusjqbjyofdebnsgdjsxuytxcevbxqodovstaummzxctezypolfpvkkinpvvdmwzxcrwxtlvoyltuigkvelrsljgddeafoturozeiaxtbjyrfyqdsvjmvuklvqbivirqemmshhepixyxezeshfyeubrrqucscafcawbpenfahrbmfkadpgyvxelpzjttdgytwsybctqmesmbgkyypnnoeaspbswjtccfdffkwybortgvkrkrbkemwcrfxsjqxqxqlauhgmxylihjunzbhbmpjafrlrwosrijnprygnjmumvqbuxiqbtngykpcigqjtuxhycbvpscznpxsftzgnwbnzctugrbgenunqewatnmmpwmyzzukklmkkomxdbjrhlqnlthkshmxvwfmnvkdiwsxlkpundzblxypayggypfosnruhlklpyziidgovijqayrzgckdixxrcmzbrrvsdssxsmzvnczhesrabffktskcpgvnwpszzoobmqljhojjkxmspvubvclgkrdoqmkxckhamgwpbdbwrczrvicmydffgferoqlsgfcoojdyhipwtevqytzqgkuczjbztuqmqcrozijoncagtdyaqppouyjghesshsceqeizgzufqeeghnmltfbuxzuxnabwwhvpqgqzpueumetrgwnwtcsptvhggnrhtnqppodlamauxdrskiglzdjkdqdegpprrgximmuxpjmbiqpbxvdpcanfkvwcseunsxzpjewy\n", "output": "2259\n"}, {"input": "4617\nzkjvshllodhiwnbcugkudfktycbssljwmdwwrhsixkenfncfgbsftzilpiglatnefendxrxbabeydwafrnzaqvyjkvtwhkzgusgtkgmtyyyuposeiwgthbqhsmijougetqlujltwlcnmfnwaaqihofkdlebctbkteneipincvhwlmyxdqioflenlcwqrbtmemvyjondlxnfvjbpxsiwqtlvmwmvhymqbcnralxaadvghigaiowgbggrqidmqyesweqqwpdmqvtnmoiqhhmtyooyscvxkuitniqlfekwtkhfyawwxsaankxahknwulvymdwekodqjtprzdkxcerbndlvdragvpnbvvclfhvczijtkqatzjxyfzfeyzohzrlyjhcgoqdxcxpzxapzuvjkhikfovfzhhzoycxflapcglquqgqadiwsjhuvqnspvvfxjgivsdpmfxahpizmarefalpnrtwqpgxebjvspkqaybzcieafzzvsiqcornlemxlwmkwhfpohklqrldujcejcmyedfrhanivpwusvcsmknumrxpkbcsxixivtsrrlczkpmhoedtfnlhluqvgyrwwkrrkdyaapfdafhvgscmlrjycxfsomvhwdwxhhzmyonbagjlodpnuwsnjvbadabzsnlaurdchgfyqucpbelzwoejiyklpdivdevfisruswqpkphdskjqmcttjeqjzpytbduteyyshljdieofxsijfvmfeiijmwmzspsanwuymffvqgrdieykghwjnbkasienmeyqdhewlvpdelyvmgvvlvvivpqrdouzaobgubncytdcrphycnpberhzyewmkfnjxmbdkazhtdomnhyltrhzazvqevujmjimcnqzmbavzmypvakaspyupwityjypbhtcnvbmloalvnpqzwolyroownektqrivccjcsbddlaixrmuhlcnkkkzswzfdgvvtmpgshmuqcvsbkulfokcgdcfxvkenonhmfeodtuulxlbqcfdnmpfovezlymdvokiexfpweywxolbevjvdztlnviivnvbpmamfbbufcqukosxistemlluakakfsdrhylfomcpgqfidsaqbksauzkkfoeadonrramisukevpoeyyjqjbaeduiylidthzqlbstgdycjcrbytglwksvaikvvaxlclpwiufqmbhrudtmujtzppfgqwhozyvdenrzdacryrrfxzxjmfpenpeknzafoseroggcojroggubxaxandnoaitrqyytjjvpwsqeywynfwqjynejgdommykqnebbszcifsenlkgtjlkhodrshlsdmwhfuhvktijpxdebjvygzyvociioivrprknkrpnfuvydfbktnwupiuhlpqbwaveixdaggiqzhjjurcdqqxudkjjdhljaeivgtyksprqvqqikdlsmocvohhykbcrwcwykwykivdnvyskpxlntrpxufdkedcvhmlfriirwemktcmrgtmwqeeztbwrjjnbatgakhnlxsxeyihoafubkgdoyyozayinbaothgadiqplsgpuvurgnxxqqhpfspynklnxsbhfkdqbezkrgautvhunueccbtdbqovkuowpwhqvhbdrrtkzttcembcijsnnoervzzgnxclonvvywgkucqwqwdbqvmrsuuclsamrunyymukfhakkqijjhivlwvpnoyowdfaphvyzlealudigjtbjrdttwktsfsqcutcajofsjxeihqfhuwhpfnkswyxsrvuslohmeuqqekdxnejjosriayyogvzlxlmxarzrmgwxqkvrqzvaxjdumyjkmvvlixprtajiurbbovngwjijrnlfdnefidozmsaufpuupjblabxqieofdpdabccbwqgkxwfpuygbxfeoonnavjpcmcldlkpfquusifeadnzemjnuedmordsveaajekbshkmtqqfjeekenbffevnsvwnelpyrdslyrgrmruiavcqlnqiemzmgejuzisdukaitiiocztdrypndmjrmddnwaoxuwcgvlbklnaavjdxgbaxicywzprhmdjqdvjojtjzvlowrynuwiqbfabhpbqjtjwjexrfxsjyewexboksjgzrjbuoxglnrbrbedlwrpekiulfericcdduqvplmowlvgkqdwgdxcwjugdtwojvuawtbhcqcljwiwglzeauygvfenwczkuffbvtsxgadknpaovhvhrcbocncxrmwhmmzknndhlxeiiyfygecaggadzfitvpcppnhxkwjcvyclbffcdyqkifnikqmlyrdhjvsanlnfbvvdhdnqeypllpeketmjxxxgmolvlppdkzgusgtkgmtyyyuposeiwgthbqhsmijougetqlujltwlcnmfnwaaqihofkdlebctbkteneipincvhwlmyxdqioflenlcwqrbtmemvyjondlxnfvjbpxsiwqtlvmwmvhymqbcnralxaadvghigaiowgbggrqidmqyesweqqwpdmqvtnmoiqhhmtyooyscvxkuitniqlfekwtkhfyawwxsaankxahknwulvymdwekodqjtprzdkxcerbndlvdragvpnbvvclfhvczijtkqatzjxyfzfeyzohzrlyjhcgoqdxcxpzxapzuvjkhikfovfzhhzoycxflapcglquqgqadiwsjhuvqnspvvfxjgivsdpmfxahpizmarefalpnrtwqpgxebjvspkqaybzcieafzzvsiqcornlemxlwmkwhfpohklqrldujcejcmyedfrhanivpwusvcsmknumrxpkbcsxixivtsrrlczkpmhoedtfnlhluqvgyrwwkrrkdyaapfdafhvgscmlrjycxfsomvhwdwxhhzmyonbagjlodpnuwsnjvbadabzsnlaurdchgfyqucpbelzwoejiyklpdivdevfisruswqpkphdskjqmcttjeqjzpytbduteyyshljdieofxsijfvmfeiijmwmzspsanwuymffvqgrdieykghwjnbkasienmeyqdhewlvpdelyvmgvvlvvivpqrdouzaobgubncytdcrphycnpberhzyewmkfnjxmbdkazhtdomnhyltrhzazvqevujmjimcnqzmbavzmypvakaspyupwityjypbhtcnvbmloalvnpqzwolyroownektqrivccjcsbddlaixrmuhlcnkkkzswzfdgvvtmpgshmuqcvsbkulfokcgdcfxvkenonhmfeodtuulxlbqcfdnmpfovezlymdvokiexfpweywxolbevjvdztlnviivnvbpmamfbbufcqukosxistemlluakakfsdrhylfomcpgqfidsaqbksauzkkfoeadonrramisukevpoeyyjqjbaeduiylidthzqlbstgdycjcrbytglwksvaikvvaxlclpwiufqmbhrudtmujtzppfgqwhozyvdenrzdacryrrfxzxjmfpenpeknzafoseroggcojroggubxaxandnoaitrqyytjjvpwsqeywynfwqjynejgdommykqnebbszcifsenlkgtjlkhodrshlsdmwhfuhvktijpxdebjvygzyvociioivrprknkrpnfuvydfbktnwupiuhlpqbwaveixdaggiqzhjjurcdqqxudkjjdhljaeivgtyksprqvqqikdlsmocvohhykbcrwcwykwykivdnvyskpxlntrpxufdkedcvhmlfriirwemktcmrgtmwqeeztbwrjjnbatgakhnlxsxeyihoafubkgdoyyozayinbaothgadiqplsgpuvurgnxxqqhpfspynklnxsbhfkdqbezkrgautvhunueccbtdbqovkuowpwhqvhbdrrtkzttcembcijsnnoervzzgnxclonvvywgkucqwqwdbqvmrsuuclsamrunyymukfhakkqijjhivlwvpnoyowdfaphvyzlealudigjtbjrdttwktsfsqcutcajofsjxeihqfhuwhpfnkswyxsrvuslohmeuqqekdxnejjosriayyogvzlxlmxarzrmgwxqkvrqzvaxjdumyjkmvvlixprtajiurbbovngwjijrnlfdnefidozmsaufpuupjblabxqieofdpdabccbwqgkxwfpuygbxfeoonnavjpcmcldlkpfquusifeadnzemjnuedmordsveaajekbshkmtqqfjeekenbffevnsvwnelpyrdslyrgrmruiavcqlnqiemzmgejuzisdukaitiiocztdrypndmjrmddnwaoxuwcgvlbklnaavjdxgbaxicywzprhmdjqdvjojtjzvlowrynuwiqbfabhpbqjtjwjexrfxsjyewexboksjgzrjbuoxglnrbrbedlwrpekiulfericcdduqvplmowlvgkqdwgdxcwjugdtwojvuawtbhcqcljwiwglzeauygvfenwczkuffbvtsxgadknpaovhvhrcbocncxrmwhmmzknndhlxeiiyfygecaggadzfitvpcppnhxkwjcvyclbffcdyqkifnikqmlyrdhjvsanlnfbvvdhdnqeypllp\n", "output": "2253\n"}, {"input": "4663\nxbnsvxobqjuxzjwfgghezqnpkebbzlowhysyzxabdvovzmhdpxcgfmfcuknbzyilxzjirtfqfbjkwwlecuinmctbzzdyziwcbhkstwncbirbwotmwtmgpskfxvoakxzgrothhawjsevpipslpgnzxgaorvadsawhxjculbnmgdnkxrkszavoorfczicyomzfkbzwjafsludkbxhdnusqylaslwaeqjyoespoewwjcflayittsinwazrrhsyjcfbfyygnojskerhhetrzeyrtvinztqqszhgppllyzzuyrfvtcziiunmtzyjmjcsoyqlifcjpepfjvwqsdxghogskyvqxihkxxskkssggmunjjxzfmfsbmxmifkbvuclrkjgivkkmdifemfifrqudoqtiidvwwcllyyabriduitthofdmcgizqwxxmueiezobqnqbkkweyettbnpcycsdkwkxedliapnrkxylohcsvugcsnsdqrbhbpveomopurgznqbvonsnoacdjquzfvdhpmishqcduvxdxegpgyunnpshsfjqctcrkfwviuoxslpznxqksbhzailaghqdoyrvprwoeeipxdyjjmrtdqbxjdgqajrahluokuhtubdrbhivzqvwgbftvkcsknivjqxrnxvyjgwgsjshkbljtxhdumzhqmwnlpqkkxdcxxfpplibqesikbsdlbrhwcevmfnwvmuhcuybxtmuqdmrnxlodsbwmlkucemteysmigwymiqrsccwwfowyfnxaewwzxmzaldcamoicokqussudabzymdxlsvvyjwdjcrlpeefuuwtesihqtdqsnlwnnwtcouucctlxmsasfhvezlcwmzmcuhoofknpecwkhoeydxabpttgoiyejclxvlcbhaoxahltgibxqslssthbsklqhrvatiirkvwfmpkznqdlfpwvfcrfmjxdgljwaqleiesaxxapaktiowlqqywrmdyzbzkkpiyvjrtyqejdpaftgmurxdxtbexgjfmjywoucdvtgunrmsrsuoeomsgpfxzhapqedcinauagonntdosvgeqpfvhbgralygclumnezoayfsmzbastacjekcrjhmjymxiufwqpisknosydoxqdtdhmcvfbfgtmhorymsjcbnldldtqyhhqasecfqrwasggxlqjgtgkkrrjirawezvzjbqacpzmnjcdwbsgldwdgwjioxykbryhsoawsngecfopnpaucxkhsdgihnbrxfvxomzdbodwvpiqdtndkfipsbofkhfxhnuxianexpoevjilexwhzlgiewhiknteujvcmydhefhkdpcbocnlxtxchxvmhvaegvkqgohgpihcopywelrzeflsycvzpdouxadtvnzqvkbcefucnasofzjjyjslzcezrukuyiofpmpxvzbinhuzbysrmfcjolkvfzcivsvkxapdloldinynmmqejpgoqmwziebroepclaybpmlhhznzrmxokdcijbhkusgswvwpaorbadhdkdtohrgivtgtgfcmchwnmkizeguvcuavsvklgjyvfzsqvwrhiczoulvfamrffkdtmupkqszzsjecczeqskjkygqszrntinrgcwnbtcnfczexpjgrodrylioyxxzvoyzviserqmhpwcbzkikyqbiwkepfmnpgbjwiwfjgkfzjtqtnnkuvmyimboqwikzmguaperupfnsuxbzybqoqfdxikmjkqumwdbcxasdlufrlaixeofvrjxdcingblzsqwqzzmznwgsdftadptnqpaufsoqgzuiaihtdlzvtynibmvjvozupsttmrorqbhblwizwheqwgntkowhdggtyvxmtpwzjliwbufaanfqdkwlzdadtzwwkrexiwhuxnspkodawlqqbatloqyawjkveydwbdsiyjnkrrikpbibdyhohazywnbaaenzjfzekjcdjfgtuisnviusjtntcyftytociyglibwfwfmtbqywqovupsjauiuumcuurpylhyvqkhvlotkpwbrrzbnimzjeqoznxysapdflgfjrcqhnxgcdrcdxawcaqkiugfwtticrztfflkkocliwsnuucqjkeawhonyprblyhtpeqpxouknfmiphmvwgtipamfnufzbyovrjjrwetmaieriatjxhmrohatwqanigtimzexyrtdgjpzxojjundpzwglfwdntmloxyfqpxlqxibqlseawvfbkdkdihprlywmgkqsocgcovacdergiiqnhxmhitqciuwibnbnevcziujmwqrrykqzssafmawgocisakvwbtmhdezpheiqyfsdpohoofzckqvatisinoqkxmssrexpjqbnhgdpsxprgptzndljychdmaawhcnpwxavunwpdayfexizgccwdwrnbnvcixibynsegztvqntmqxahhntfpekqnynzzwcyqyinnwuugdgfgrngnuvijnkfxahbpqghqdvtrypemhcosztusiztoxajydpisupheplmogacvbwfifcdlsegyopkdnfzwxxmfamknvhkmpymxfraoktgjjpxlwvywshmouwonvwejocnvgrsjenzgnggevtdjtpzfogvgpykrnpqtoilhwbgoynztrvglsdciulrjlvwsgcmawtpjwpnfektfgkbxmokgmomdqrbhbpveomopurgznqbvonsnoacdjquzfvdhpmishqcduvxdxegpgyunnpshsfjqctcrkfwviuoxslpznxqksbhzailaghqdoyrvprwoeeipxdyjjmrtdqbxjdgqajrahluokuhtubdrbhivzqvwgbftvkcsknivjqxrnxvyjgwgsjshkbljtxhdumzhqmwnlpqkkxdcxxfpplibqesikbsdlbrhwcevmfnwvmuhcuybxtmuqdmrnxlodsbwmlkucemteysmigwymiqrsccwwfowyfnxaewwzxmzaldcamoicokqussudabzymdxlsvvyjwdjcrlpeefuuwtesihqtdqsnlwnnwtcouucctlxmsasfhvezlcwmzmcuhoofknpecwkhoeydxabpttgoiyejclxvlcbhaoxahltgibxqslssthbsklqhrvatiirkvwfmpkznqdlfpwvfcrfmjxdgljwaqleiesaxxapaktiowlqqywrmdyzbzkkpiyvjrtyqejdpaftgmurxdxtbexgjfmjywoucdvtgunrmsrsuoeomsgpfxzhapqedcinauagonntdosvgeqpfvhbgralygclumnezoayfsmzbastacjekcrjhmjymxiufwqpisknosydoxqdtdhmcvfbfgtmhorymsjcbnldldtqyhhqasecfqrwasggxlqjgtgkkrrjirawezvzjbqacpzmnjcdwbsgldwdgwjioxykbryhsoawsngecfopnpaucxkhsdgihnbrxfvxomzdbodwvpiqdtndkfipsbofkhfxhnuxianexpoevjilexwhzlgiewhiknteujvcmydhefhkdpcbocnlxtxchxvmhvaegvkqgohgpihcopywelrzeflsycvzpdouxadtvnzqvkbcefucnasofzjjyjslzcezrukuyiofpmpxvzbinhuzbysrmfcjolkvfzcivsvkxapdloldinynmmqejpgoqmwziebroepclaybpmlhhznzrmxokdcijbhkusgswvwpaorbadhdkdtohrgivtgtgfcmchwnmkizeguvcuavsvklgjyvfzsqvwrhiczoulvfamrffkdtmupkqszzsjecczeqskjkygqszrntinrgcwnbtcnfczexpjgrodrylioyxxzvoyzviserqmhpwcbzkikyqbiwkepfmnpgbjwiwfjgkfzjtqtnnkuvmyimboqwikzmguaperupfnsuxbzybqoqfdxikmjkqumwdbcxasdlufrlaixeofvrjxdcingblzsqwqzzmznwgsdftadptnqpaufsoqgzuiaihtdlzvtynibmvjvozupsttmrorqbhblwizwheqwgntkowhdggtyvxmtpwzjliwbufaanfqdkwlzdadtzwwkrexiwhuxnspkodawlqqbatloqyawjkveydwbdsiyjnkrrikpbibdyhohazywnbaaenzjfzekjcdjfgtuisnviusjtntcyftytociyglibwfwfmtbqywqovupsjauiuumcuurpylhyvqkhvlotkpwbrrzbnimzjeqoznxysapdflgfjrcqhnxgcdrcdxawcaqkiugfwtticrztfflkkocliwsnuucqjkeawhonyprblyhtpeqpxouknfmiphmvwgtipamfnufzbyovrjjrwetmaieriatjxhmrohatwqanigtimzexyrtdgjpzxojjundpzwglfwdntmloxyfqpxlqxibqlseawvfbkdkdihprlywmgkqsocgcovacdergiiqnhxmhitqciuwibnbnevcziujmwqrrykqzssafmawgocisakvwbtmhdezpheiqyfsdpohoofzckqvatisinoqftjgevzbautliegkpuxvqruqzwdbbwlzcrltczibpkgviwyfjywlsgnulmcysyeuwlmjzpwhcuimf\n", "output": "1881\n"}, {"input": "4914\nmnabhuottpsixukpvhxndluxuwbrsqbosywjkzlbkobgwmhkqoohfkpjebqzniytnehbliappbuclmdpoehmmhkcljoxdxwtookmucsgkcvwurdyvkuycmvihairvwzibhxcvgbkvdnfolvvpwtcdohqxasbdgppwjunfsuzqlqdevvzbiapopczqikjlfsimjwcytoblxewkxmkjjvxqyulszzgpnlrwoycbnpnqjineztlgafzzuounxxazhtyxmapburkglfntgardqklapjberdyrcilkfoxcvrknybocdvyzifjgphbadmvwgzcoutpqlcwksjomlwavjdprruktxchcvnowhktegiveylocgtmaasvtvpupelkssqtwumyfopntrrlniwfbfezsrxwhjgghosndrqpbymqrljdcphhatxypdyrwnmulhddnebbuvpessdaxehsnyskbjbxeanzadugwzomhjynunkarlkcowvjiprzpksugbrqinyiwiskqwbxlefrnmkomqejuezuazvbghjiytinjyzwjcdrkyqwyunyerdjadwtzikmoyqigtsrbsdjggxxytrijiafkmckthmdyrywgnwuvbaenrmwdvsshwzrsfgobgdnolsnxzdiyjomhkqkmzchhnrbsgagwvnpxxdwnnqcjmrtstfpiogzgohjhtyxqgtejbvjitooaywhpubhjfpuwpjfddafahqabtnyzpburiyzjzgrfcfhbeplztiygkujifgobblzxjjcdcjgufepooahzbkpqgjaofagcdfmnhvntxvizbfqeimqzlbblzmwlljrresvnltwdeqmnglabwqgbyfcuvctkzfzeymybtfbiehgedwcpqjcluusffxbqozuleiwopsdcavuaydbfsbqdwjeisbprncyirkmzafykaigijufgmsimjprhkldvayottmoahifbwympadkewnmoxktwsorneqhoyjhvrjfxrbqrlppzlwgomfzdzcpxtvfobwzxqeukomtxmdniroewhuztjxpjjnbldssbglkmncptynicwspotxrgmertzalkiattjwbowxivnvcrdrbaygwuibazqzlfihrlgtqdugbzwocxlwjsgpzuyzdviczkdieaijgiagbjajyrwglayaatpfqglrdmebylfzvrstubbqxskelfkodpznbbicreevgjarccqpfmhxsgakdtbtymhxzaoxyvkidvljwutwwwebrtlsbhujdhumqrfcwlqkdgkghvwhxdjtkodvrqwbqhonjztumwuaipygncfnfohodtrlceqqagxqvinbuobztwkuxcuknqodqvtxgrlopibdqtooiwfdvdrdjhadozvrfxpsshcwpibpqrcippvbuttlldurrmvtenckifxtzpibwqdrutkhsbiqtgyelnwhkpzlimwvqdiragmhyvyjctsrtzqwbgceymggoyqcabibdecslepcvmyvxdrlvbeakrvdwgeejjtestzzdwsrnyrykvoykaahipkugdweifdbwnzhetbemtzssdvyuxsqfdnpdtilegiymohfrlmbpkdeyxmndhomkqcozaxjhhqjvxshvrryjmtbziakecqzdnwbnuzvvmgvquqxmoutyvjfzumioegfegvjaozjjzvnfbxkhujawzciogondmpjibjpuzwvesltcwwaacduuzpxdbafytdocjbdbmqgyfhfivuyzwqxzivhuvnqzdzqyvcvnpppeuxchgloqszbnuasbakfefhfileapwglcerrsmclzshbsfwocabjinpgvpzcykiccxrwmaxqcayydatolsqamtvwpiaeotvexvbnlqcikoqinsccqtktpmlnvpqnqozbwhnrhmgulfmggjkcsuvrtdrtciphzdfwfqytrzwbfjnqqrhyptqeovebujcmzkloomwxazgxptxeqzcmwqsamuoypnltengjclerwpazcvajvqdeoitjmcwaynwiuoxaegquzcjqufkoboavjffqtplsknyriltdcqqlmuqyqoopipwobkhuhzrjemlxbbjqtbfagnahmofuzipnwgffjaxvrjfhmnurvigatyrezpcfbdoujinqrvmtunuyquskhljlyguwahcesydkcyyrkiuxdhlmdnsqgkzbwtxmlahsemehiunxyzssjujackpfddksniivwovjhlfybvsqyfvjuueyshtfiuanjajvyulcqiiubqjidpjzpbannnimtwibbbkshbuhzcaheewbpfqlrhdiizbjpyzgthavbrsultbvvexyehlespgggjlllkdmvchqfoqehjqbtraclsvlmeiakreehmqghzquidewooyiamqplfwyiypxbczrpjddftrisfettlhqjlxuigugjyawibotwzwbbqyvfixrtrjjubbqitylxtkfhwbixlowalokciqadrtwdspngtzjszncphzeqsuziywigydqtbxkgwopzsblcajskqrnrodvsjxqltkgflpzpemmhjynunkarlkcowvjiprzpksugbrqinyiwiskqwbxlefrnmkomqejuezuazvbghjiytinjyzwjcdrkyqwyunyerdjadwtzikmoyqigtsrbsdjggxxytrijiafkmckthmdyrywgnwuvbaenrmwdvsshwzrsfgobgdnolsnxzdiyjomhkqkmzchhnrbsgagwvnpxxdwnnqcjmrtstfpiogzgohjhtyxqgtejbvjitooaywhpubhjfpuwpjfddafahqabtnyzpburiyzjzgrfcfhbeplztiygkujifgobblzxjjcdcjgufepooahzbkpqgjaofagcdfmnhvntxvizbfqeimqzlbblzmwlljrresvnltwdeqmnglabwqgbyfcuvctkzfzeymybtfbiehgedwcpqjcluusffxbqozuleiwopsdcavuaydbfsbqdwjeisbprncyirkmzafykaigijufgmsimjprhkldvayottmoahifbwympadkewnmoxktwsorneqhoyjhvrjfxrbqrlppzlwgomfzdzcpxtvfobwzxqeukomtxmdniroewhuztjxpjjnbldssbglkmncptynicwspotxrgmertzalkiattjwbowxivnvcrdrbaygwuibazqzlfihrlgtqdugbzwocxlwjsgpzuyzdviczkdieaijgiagbjajyrwglayaatpfqglrdmebylfzvrstubbqxskelfkodpznbbicreevgjarccqpfmhxsgakdtbtymhxzaoxyvkidvljwutwwwebrtlsbhujdhumqrfcwlqkdgkghvwhxdjtkodvrqwbqhonjztumwuaipygncfnfohodtrlceqqagxqvinbuobztwkuxcuknqodqvtxgrlopibdqtooiwfdvdrdjhadozvrfxpsshcwpibpqrcippvbuttlldurrmvtenckifxtzpibwqdrutkhsbiqtgyelnwhkpzlimwvqdiragmhyvyjctsrtzqwbgceymggoyqcabibdecslepcvmyvxdrlvbeakrvdwgeejjtestzzdwsrnyrykvoykaahipkugdweifdbwnzhetbemtzssdvyuxsqfdnpdtilegiymohfrlmbpkdeyxmndhomkqcozaxjhhqjvxshvrryjmtbziakecqzdnwbnuzvvmgvquqxmoutyvjfzumioegfegvjaozjjzvnfbxkhujawzciogondmpjibjpuzwvesltcwwaacduuzpxdbafytdocjbdbmqgyfhfivuyzwqxzivhuvnqzdzqyvcvnpppeuxchgloqszbnuasbakfefhfileapwglcerrsmclzshbsfwocabjinpgvpzcykiccxrwmaxqcayydatolsqamtvwpiaeotvexvbnlqcikoqinsccqtktpmlnvpqnqozbwhnrhmgulfmggjkcsuvrtdrtciphzdfwfqytrzwbfjnqqrhyptqeovebujcmzkloomwxazgxptxeqzcmwqsamuoypnltengjclerwpazcvajvqdeoitjmcwaynwiuoxaegquzcjqufkoboavjffqtplsknyriltdcqqlmuqyqoopipwobkhuhmlnywqgfonbbahxgytydamzqzamrxcrobmtrqdcjkwkjopccwrjqgfssjjcjtgbarpimvufrajcubfvcuiogbodwbkuxinvotfigqvxzrtxbklzwduoynavghzakgulhbmwwquhnzbptzgbmpuvzncyjfxfizzlqfjfqjomrlyjzercjalhzqpigayseeuowoydgejymwugctajrzijxqrurdpkjgzrjyfgczubugtyvirlpjbskronedjsjpyttyppmwasirljevbhcyiazhmbsmsnqnzeoetvounfumrqixtdotewpxmyeygzzplwrabwcirmuagodahzbubzherhylunmnufnanstltjidanbbjuinuhvbbjeefwvmhguggiqjcsqrsvvqauktnouyogpebeejgifqvjzeibsnajkltutlaaazxkglmtferzojknkqfnhnimecspdnruuhdyvgbkwlyxvjpkqyvchkoobfdvpvypumyxyfvfcltbrnerobbxvhiauubitqttelzjsmumxdaybensidcgdbsmiylfwptzifukmcctidgkomiueyrfgxtobnvrfksryotlawsoadborzbgdzsazkbvaqdklzhbsmnvgbaxbgikddnecbprzliwfzwannhpdefmmphjddjmxnpwtizojcbrykjqwvajrwuwosmqffgufyramzeycpjkkxoo\n", "output": "1617\n"}, {"input": "4505\nkxdzclgtxksknhysqpccvmfcbxguljfnhcwhukxwkmbanknyfiiqgpudpydyuaqpzivyyupdrngjzfzagtrlviyiwjxmftjmijwlxfbqajnlhjopcadvytwhjgoohgejfoprxyyrfmbrzgwtbiishrfmkxligpndiahsbbyadxrwnpqggelvbsiwltbuybpkidgsgyqnnzpwcdiluthtxhkuxloimjbwixzuejcdxalguqqpguyctvoweyxlzxrrnpftrcyavyqqwggadowzvkojjebdhbfugfylhxdvoiacjxsgymuzsiunizgtdokkuruytxaqhdgrlycslifudslyirkunndnkhbdkgkwyxhoompmhphuulpbmlfqhccqqxwvuqvixehibbfqovjtfzpfriqtmnxtkjkoisnbolamfufmzmnmjaocgymghzlubmuunjwoxhpzmupwcdranlswagtrpdnuswsabldqcmbkedjgrzcrruvkniwsstdsvympuvnzccovbrxjzmhezhavsgrtephnintdsnawrwcnoexefsqkegszgquurcubilpwchtihikgexzbwmhdjjnuzuvvijvivopjdyuphnpcifswktwjoevjegnakeotzznocwgemettcruusezcmhwkpathswqhrkwaikyschbgqxdcadhmnmqkpqxzvprabzdndtpwajmbjbseotravnkhyidaqtcqxsnjuvwnsbusbtvemmrmipomjhablltkdzmemwgynfyzaasmqsjhfzqcfxylitsmifhxrtbbjbumachiaqwzvskhiztaixykivonestorppdkyyghltfcdtksyakkmwacdtklrpiapujjtonnrssugrypqeqipworjulyyscklqmlvlhijnmcdvcovnxrxwercbytrugryajputqxgrtjxidgkghxghlmlyvoqxqcavqydpnvcngptysxurcyithnmorvkixktcxktaxcplamrdpwlitblnxsxvpnxcppcdgvmwymdztnihpntgtlyqklxazaavvfusxbkosghyvgczkwywesuyekxtjygzazvqivmtutcttsbgvznopyfrttlspyphqgjxscywvdymryigugxwmocuyivlxfvklcxqzlssjmojfdmozvzyppzejiukfxskofwmmeeosdbppyjladlwzpunwnrduhlakeejdlyajbptvgbpzebanuelrgazkpxwfmybqxgntcsxvynmcfcvztctuulwbxosffwpxclbofshgmormuehvvtmxvrvqcjbxtgpshsbtiuudkcmlniecabenxbgcrhqatltdgxhodxrkdxxnczpbqqzejhjfdehwcqfvjelbdxobnmkrptdmskqjhtusgwabyptmiukhbxxhtwxyqggznwylgeljmpyupuvdrfvpghtmebcmornzphdkffcstaeiafmuuexdftflizyglkydejpitcwuquybogrzumcpdjprhvdynndhlprlhxdcocezbfqspnyixjhqigkqnirxbvhsmxihxiubrblzgzlzfzyssoqwqhpqgrpwefrmagoixchkvhygoupipntiaytjsgfsivyezxqytcgikumrooiyfmxwwcjuuvrkxjhoylslmmbbtevmbgltzcizjjnllrfyfswiazfyhfhswbgngwpqnhxzjsvxzwgvmqdzolivqvmujsfwmoxuqunpgcjrkcznzsbthfthjqmbfwmkdgbkljidazqdhxmtzliyarrxdxmxahtrtwtnzkvhodspviduadbdyvmsdduyhzkxlkmyhypibfpkscxyiemrytmhmisntnlzcnldgewzhjglmhrrbvtoomsnvjcbqjfienywvkghnuyegmzlsvetpsvphsysupioerjegkqgrxzxbnthqkpglcdrhdknpjgvirtbldswvlxhtyqiowenixyrbbfxetygsldejqknljpnmcsuswkhjvfulvzsyvholdfmulkulqsnbkkautffjktvyzrspyjnqrpvbkkitzutxplzdrououcydlkdsxltpjarzcqziuceazrdlipcpsufqxmiountyknnkwzostavzmmipnapwzihbzlanpxikaiuyotzcvwskkdhejpxbthndjkhhhfogxtmwoduaooznobskcgnmtpnjssswgzczuhbpnwvalkfrvelnetwfwpxrkfmxxvkiopilyeasnqhjjgklcjacuhwfprrbhwmgxfdubvtmirvlhfyenqaukgdiblfplgcxywicgjdhaxadrrxvahpbicuqebllqcfsbclkpnkkjfgpqhpltzvttdzfkyfxldovjfplgrxebtcaijjqhxdxnbunswmwzinpgdubcihzqhwtwffbmwdydxlndxxxhgcwtpcmrkirxxnpxhzwiqfldosmbdalrbnafchcfcrdgypzpxuxsychduapszqlhzcukyikpoqmjjfkwyxohgvhelzctmrxgtatvvyruclccsubvgbrbqotlscdmktogesvmeegnakeotzznocwgemettcruusezcmhwkpathswqhrkwaikyschbgqxdcadhmnmqkpqxzvprabzdndtpwajmbjbseotravnkhyidaqtcqxsnjuvwnsbusbtvemmrmipomjhablltkdzmemwgynfyzaasmqsjhfzqcfxylitsmifhxrtbbjbumachiaqwzvskhiztaixykivonestorppdkyyghltfcdtksyakkmwacdtklrpiapujjtonnrssugrypqeqipworjulyyscklqmlvlhijnmcdvcovnxrxwercbytrugryajputqxgrtjxidgkghxghlmlyvoqxqcavqydpnvcngptysxurcyithnmorvkixktcxktaxcplamrdpwlitblnxsxvpnxcppcdgvmwymdztnihpntgtlyqklxazaavvfusxbkosghyvgczkwywesuyekxtjygzazvqivmtutcttsbgvznopyfrttlspyphqgjxscywvdymryigugxwmocuyivlxfvklcxqzlssjmojfdmozvzyppzejiukfxskofwmmeeosdbppyjladlwzpunwnrduhlakeejdlyajbptvgbpzebanuelrgazkpxwfmybqxgntcsxvynmcfcvztctuulwbxosffwpxclbofshgmormuehvvtmxvrvqcjbxtgpshsbtiuudkcmlniecabenxbgcrhqatltdgxhodxrkdxxnczpbqqzejhjfdehwcqfvjelbdxobnmkrptdmskqjhtusgwabyptmiukhbxxhtwxyqggznwylgeljmpyupuvdrfvpghtmebcmornzphdkffcstaeiafmuuexdftflizyglkydejpitcwuquybogrzumcpdjprhvdynndhlprlhxdcocezbfqspnyixjhqigkqnirxbvhsmxihxiubrblzgzlzfzyssoqwqhpqgrpwefrmagoixchkvhygoupipntiaytjsgfsivyezxqytcgikumrooiyfmxwwcjuuvrkxjhoylslmmbbtevmbgltzcizjjnllrfyfswiazfyhfhswbgngwpqnhxzjsvxzwgvmqdzolivqvmujsfwmoxuqunpgcjrkcznzsbthfthjqmbfwmkdgbkljidazqdhxmtzliyarrxdxmxahtrtwtnzkvhodspviduadbdyvmsdduyhzkxlkmyhypibfpkscxyiemrytmhmisntnlzcnldgewzhjglmhrrbvtoomsnvjcbqjfienywvkghnuyegmzlsvetpsvphsysupioerjegkqgrxzxbnthqkpglcdrhdknpjgvirtbldswvlxhtyqiowenixyrbbfxetygsldejqknljpnmcsuswkhjvfulvzsyvholdfmulkulqsnbkkautffjktvyzrspyjnqrpvbkkitzutxplzdrououcydlkdsxltpjarzcqziuceazrdlipcpsufqxmiountyknnkwzostavzmmipnapwzihbzlanpxikaiuyotzcvwskkdhejpxbthndjkhhhfogxtmwoduaooznobskcgnmtpnjssswgzczuhbpnwvalkfrvelnetwfwpxrkfmxxvkiopilyeasnqhjjgklcjacuhwfprrbhwmgxfdubvtmirvlhnbqibjddcwliacapxhxyoxcehyiwgyhxgtrcdmodjxohmcawliehfycdwrwnofrfsoawlgmjmbrtzjmqnlcvxpiraueantxxdainzhnpeomwajbqbgnlajysmaumwosatpdzovklhrneyfsfjfulzwlogtytnsvjhdncbfxevvnmjktuqzomraswyoeqkezjznxvtwqckyxhuqchdxhnpttzxxhxusbzrebdvknunozdpwiholilpacrwgvirpnj\n", "output": "1670\n"}, {"input": "4978\ncnacvrndwjhqnzlfkeibeywnbhcaxlmnwzthnygfngohcoujqhmiupnnshyaspzrwjnvxdvxtrqzsprwsvanpxbyiifrqbendxzokadhnxjvursocnpdhhuzdtchplyclzrwcaqwwipfddfrslbmdmvselkiqgemsjtqjkyffnfvfubkrtjkwodtikfxrxwhddudevhuyfefqbsikelogdyptjczybthvpgfssmtrmklbrhtrvrpazedluucnhhtcycklqshfotzrjwkkkondfiwnzlgmsymjglxjudwewoegppjujfunciiqjrwzpnpxgblvgsnruyankwsqdasueilunsrlmlkdksaoalfiqpkqyviahjkauynuztjjhupwwnnktskyajwlhswgpgnqxerappaxhelvdyahumkekvaimyypbdkrhecgdgzhgqwmovlotqyvemgbktcveuvzkfwflbpytvpyuwtsdjnyhkqehizrxuibikmodgccpncpfthdqvngjvwwuaaqgtusyxmvwniqmunspuclissdnmnhzvravnrqpkugouyfadqhcsztwqxucmtrynkvtvinboygpltlkxvezffgfwjcqxxttwaiwiixfmrxqdrwxezrpasbgvfsequnlwtnlybzxvambdwkxgeyiqympwcuuzeslrjoqsvazhdqakoydpexsimmpdienotckxtxezatzmglhobxiaemyuyrgvnylvwgicqcfwhzilxcbapfxmprhhqbhuhjhcmzifxlhyymiuvvixrhrpvjvbufpgnkwhtzywyyzsdoqqbmcblpjrotwhmcmeyzasbiknxegbdknytvqdjfjzufmyggwzmmvylzuivnkejjvrrsrzvqraqveejyyjggiuekgpkrnhqzywkrnbdbcgrshlepnxbikiefsmrjilyijopvffbozhpkykjllbphxuomfyxsautfvsumgdahusvezdokxhiklpklvdmqvqdhuwbjsjemvkpvmauctibspekorkwopcxkgcaltkibtjvnmjskrpmyevjuvtkbllwiytxgtoxmldcsxaorhrrgqugktcfekzeoepaqjarmvprvalcnhionzswkptlcsyspuvdjwigzzwnzfxhtbypfwctqtyceqlnjumlwwoprmcmkzsymobgagwvhvtvkkdhkoihqunuhzzoozpjumiqftqczanpbuyufuvvkomgmekfysrsrvejvfxbpggulvdaltouygemkbeevvawxslamfevgyxgragcukmumodxunfazvisdsansbvwkqqanltzyjnbxafyetnhsmeuopbuiywgpadytalhwonupcwkcpjyflkqkkqdxngyyikocahbxgvylblevhgdtlojmdmcbldnpstqngfwllrfndjcesicuasinuolqhqjkssithtqiiipnekupthwygybhqpdrsmvprgyaqatlilvhlrvqywqsauoyouodflrcxjrewtfnfvkzdlzbjirewhyyoghuibrndgcrkzhadtirwazixxzawdqwgizivtslhqbamzmwdwtqhukjjdcietkvecacfobtzdmidwacfpikxlsxlnseaaabivkzfiubvpcpjhspxuuymmlmcswwoutzaxdnlvhbratkgeyxtbdnigiqqkbvtnmqhyonracmvzcdjgwidltfzlvojjjctylkvbsvworuyxmwpjitdabykaqpskllrjwharmtdhcgognvgxkrwdcnmnztekfswwgfzaygkhorulzcefeqbtcojkqoflleirljlhqrljjpslbdiujcoajjyjlbzosuxyeesmruxybuaownzorijcgszkbrbjhcobuufbzjkwjxuskyvdxndoofezgacqbibjzeimdpldsosfxmgahtmrbejzdfaiwlmkthfzddzucjwyimbyfqlljqsqhutuyfxjzjduhjagjohsenppdxrqbzfbmlckflincctmrbypmnrzjvmyzxalqadeumyugybqkycjpiubymtczbznbksoegupstvzwexijkldtnthrczifvqwcekywxyjgkzqplkawdvxyttyczftjhhkckjqaxivcarjamzoanpmejgqhahvrhxasllrcgzsqvskrijkbjbwgmjjsqjljzvechkspzdichmywvcixueonpdmqbbbzppcciesqxbxslpamrcodveutkexedmtrudycjyudwafjgmqknpiarzoqouhkhmfiaooshzuavoxgqoazsidibgrgtujqkizfztmiaacsvrurpdbvgkhzrcmsthzqafluypzjsxdoedgqurgibwtckpuzrprgzzyjizbvmyzqwfgeujtoyokyakjzmgsinmcrruuqrqjyysfxzwiyneqfajlpmffvriucaptblrqvgkboogszpfntkgmarevteaszcofbcmkgswuajzqxnncxiujkokvmjhelkwwadalfekgpsgarchpgakvzaksrkfyyftwdlrckcegfuwmjpewoktcwrgltjvawybsfmzmfquumnrlsiaatajqetfyfwdpkhndxeefkudelxgwatymonbksiusjncxifgphejflthvxiwwfgvlhuuufljvkqhtcvtajqhwupmozkjvtifmbzbdeftvimbdwbjyjmurcxokvucfymnfeoipaamhhtqxhrhlfucteiilshljnukkunsaveaaengemvmgyxoeymvgrzimrxmdsykrbobqqvefantjyopanlpjlcdggvcgtqzlerevvolngznbcuxizaewrkyvrokflcsyfvsdemffdcyheojuyibikcjuuhsnaaesjtznjxqqgwbxmbpyprtarfropffkbeeexrkaoudljkjjwwhylfyxkrkxquolhjmxjzhhiewiixfmrxqdrwxezrpasbgvfsequnlwtnlybzxvambdwkxgeyiqympwcuuzeslrjoqsvazhdqakoydpexsimmpdienotckxtxezatzmglhobxiaemyuyrgvnylvwgicqcfwhzilxcbapfxmprhhqbhuhjhcmzifxlhyymiuvvixrhrpvjvbufpgnkwhtzywyyzsdoqqbmcblpjrotwhmcmeyzasbiknxegbdknytvqdjfjzufmyggwzmmvylzuivnkejjvrrsrzvqraqveejyyjggiuekgpkrnhqzywkrnbdbcgrshlepnxbikiefsmrjilyijopvffbozhpkykjllbphxuomfyxsautfvsumgdahusvezdokxhiklpklvdmqvqdhuwbjsjemvkpvmauctibspekorkwopcxkgcaltkibtjvnmjskrpmyevjuvtkbllwiytxgtoxmldcsxaorhrrgqugktcfekzeoepaqjarmvprvalcnhionzswkptlcsyspuvdjwigzzwnzfxhtbypfwctqtyceqlnjumlwwoprmcmkzsymobgagwvhvtvkkdhkoihqunuhzzoozpjumiqftqczanpbuyufuvvkomgmekfysrsrvejvfxbpggulvdaltouygemkbeevvawxslamfevgyxgragcukmumodxunfazvisdsansbvwkqqanltzyjnbxafyetnhsmeuopbuiywgpadytalhwonupcwkcpjyflkqkkqdxngyyikocahbxgvylblevhgdtlojmdmcbldnpstqngfwllrfndjcesicuasinuolqhqjkssithtqiiipnekupthwygybhqpdrsmvprgyaqatlilvhlrvqywqsauoyouodflrcxjrewtfnfvkzdlzbjirewhyyoghuibrndgcrkzhadtirwazixxzawdqwgizivtslhqbamzmwdwtqhukjjdcietkvecacfobtzdmidwacfpikxlsxlnseaaabivkzfiubvpcpjhspxuuymmlmcswwoutzaxdnlvhbratkgeyxtbdnigiqqkbvtnmqhyonracmvzcdjgwidltfzlvojjjctylkvbsvworuyxmwpjitdabykaqpskllrjwharmtdhcgognvgxkrwdcnmnztekfswwgfzaygkhorulzcefeqbtcojkqoflleirljlhqrljjpslbdiujcoajjyjlbzosuxyeesmruxybuaownzorijcgszkbrbjhcobuufbzjkwjxuskyvdxndoofezgacqbibjzeimdpldsosfxmgahtmrbejzdfaiwlmkthfzddzucjwyimbyfqlljqsqhutuyfxjzjduhjagjohsenppdxrqbzfbmlckflincctmrbypmnrzjvmyzxalqadeumyugybqkycjpiubymtczbznbksoegupstvzwexijkldtnthrczifvqwcekywxyjgkzqplkawdvxyttyczftjhhkckjqaxivcarjamzoanpmejgqhahvrhxasllrcgzsqvskrijkbjbwgmjjsqjljzvechkspzdichmywvcixueonpdmqbbbzppcciesqxbxslpamrcodveutkexedmtrudycjyudwafjgmqknpiarzoqouhkhmfiaooshzuavoxgqoazsidibgrgtujqkizfztmiaacsvrurpdbvgkhzrcmsthzqafluypzjsxdoedgqurgibwtckpuzrprgzzyjizbvmyzqwfgeujtoyokyakjzmgsinmcrruuqrqjyysfxzwiyneqfajlpmffvriucaptblrqvgkboogszpfntkgmarevteaszcofbcmkgswuajzqxnncxiujkokvmjhelkwwadalfekgpsgarchpgakvzaksrkfyyftwdlrckcegfuwmjpewoktcwrgltjvawybsfmzmfqfqwzauexxuqxwwznzflwxsoroldtcqujomebyvsrtswgusbyybimotaphlcrb\n", "output": "1960\n"}, {"input": "4680\nvhpkfqtkkedyprkmsqahayeukcjytoayzvaifkcnquojebdlmufsvinykvggxvuqdcacuuflugenffzasxxurdavxrzeeiypysuwhslpaclasqxdytewucvhspkjydkjkxpllccxlptkbdixntqjhozngcpyuwhtsgvslkixvyadpxlppkhmrbiiwwtfgyjyrlqhhzjeerbnixctbxwiwaolvsmlcramjqmsjlislxzmaiepetqdhwtgwiiergpgzdirhnytftefclbueycxdfidyskozujvkwzpbnbresshgwqpajidmlcbwzjcgdoyieklhfqfcxkqavdorwvyeojdfetynfoebtfruipoarfwsxunardkuxzbhihivdsgooizyhgcjnnwwstfsdkqdpnjxfemcszegyqmyfuqvzsjqnggibbvdhfiitocxeljrzrjqkgjrhttpuzjgfrtyfghukvmshgblpcqwyfdvkezkpnvtpuadxlgjvtxhytavruryhvixlwvruaktecotothmjbzpqxnapjrceohymmrqpdolzqaksnlzysndhupwfpfwkymnteogwxwzjzbwgivaryqhtsmxralhtstsrcjvwyhnrlbgftcpekalzgxwrzxnjrijtmhgxwniudnfvehgtfjbgblvpdsrtfjxlyxmazopzpmdijxxuyexslpbexxncgylhmgbtonlinkytldltqbnlyonmrqbehcrcwlpagjokspflkfcmyromplzqtjlebpduhofjpimzhpdsjcnmszuwjmfbsrtcyqvwoedamqrzoboehgffnanlmotrkvfobttxndplsqgnfeqswbwktjmhjvnoyrmusixhcvhxdcwuaamkgsmnnnizunlshxquvrhaqdvkdqpqngzceurwfhlalnlibygycwcvsuxrckgluzrarpsiflxkxmklsdefzlnhemswjebsyamyfheyhhxxninicksvkniugfuzxmigzcxocdrpnmckzikdqpiyyyamrkychtftdihvtiuhfuusrdnszbwdbzxsosxnxkitjiueumyaocgdiargwbcjhblbdpzmhpbfedefexhuufatfefhvfzivwzpegygoehogxyoakvklbehcwrqsvzzkmwgcjxzuceavddelizjoqcqbajwqmlmmhixksxigvieylbzivbtwuoyjlivhrthwgnhqsypkqmyyzieozfhnyyrlbajyyrraemkssycasdybdpyedvbgdtehqiqkjzjmnicztorqbzdtnnjkqvhmovefljrlttbiuxkhdemgrhefdobicrtlrmbuhvltixbqkzuzeonebfhysepbladnmtchkkmcpmvmrzlkaqxdkrgwgcplemroqhlglprhnwthbqouosgrwjfcetwbykihhusthhlxcpxfdctvzwvlxrukehtedrmzwemdxamdgkygvxaazxmtcdliosbatfximaijemuhcgsllcrcajttkyqnmhznjswxhxcrdcybfvfttoebvrwdrmgeahkiwkqivpkbqhgsfgsebhdxfwttzhwrouxecqtrljfmqpiueauznumriqgpjwmkpkuhypmwhbgxnkigjrrmofwivvycrkjftmxxauqrddfcrbkznzozskewkipstxpkflplsjbwjggdnashqenhkccxtamgxwwbtdatzwdyzvuekrjquhwjrykotnplhexhpmraoqapxnyvgafoabektkzkrnqpxmfkgjxfndbmawcgivjipueuqwwfnazokrqynfkrwinhkiopleqrlhxtwvvdvlwkjowklgedybmeglntksasofzbsuabbtfkwrstyugasenvtqmlqovntmqxhvwaldhfltbbayrzgpgcjyzfwkcwdowuxwvcrrqblotqfnboaoxxujcpoopmopiihzinolvtyvifofgfvlizjtsklvwzoghnescciazmtqbnmuslsvxslpsxxmtaoozgmpryhywurxrgjhcujkwegomcubegbhsulchhwqcfetodgxjpmtgwimcinazhdevdvkbfctjdadrmuucdsdnhnmnxxydbeqhajqshlbmrsemjvsneeapjquczmnupbhizeyyzxwiqnetllyqivmfjqgzfzixjhzjizljyrhrmtntnenkiqwwacxwgbwxxoimduxczaywccjflxvxzkakyoeykdvwbynjgjguqkiehtxnvhkaviyyrsqkjudoxwngvnxhlgmvlvovgcpiikqzxxwyirtgpxmtxmtblkfvsmiblplxvaazvdhgwgusavvuavotnasazgggmvluizbnpgxacynuczwlnltlmnuolnymjyazrgcafcaoqoajrweuupimojprdskpysuwhslpaclasqxdytewucvhspkjydkjkxpllccxlptkbdixntqjhozngcpyuwhtsgvslkixvyadpxlppkhmrbiiwwtfgyjyrlqhhzjeerbnixctbxwiwaolvsmlcramjqmsjlislxzmaiepetqdhwtgwiiergpgzdirhnytftefclbueycxdfidyskozujvkwzpbnbresshgwqpajidmlcbwzjcgdoyieklhfqfcxkqavdorwvyeojdfetynfoebtfruipoarfwsxunardkuxzbhihivdsgooizyhgcjnnwwstfsdkqdpnjxfemcszegyqmyfuqvzsjqnggibbvdhfiitocxeljrzrjqkgjrhttpuzjgfrtyfghukvmshgblpcqwyfdvkezkpnvtpuadxlgjvtxhytavruryhvixlwvruaktecotothmjbzpqxnapjrceohymmrqpdolzqaksnlzysndhupwfpfwkymnteogwxwzjzbwgivaryqhtsmxralhtstsrcjvwyhnrlbgftcpekalzgxwrzxnjrijtmhgxwniudnfvehgtfjbgblvpdsrtfjxlyxmazopzpmdijxxuyexslpbexxncgylhmgbtonlinkytldltqbnlyonmrqbehcrcwlpagjokspflkfcmyromplzqtjlebpduhofjpimzhpdsjcnmszuwjmfbsrtcyqvwoedamqrzoboehgffnanlmotrkvfobttxndplsqgnfeqswbwktjmhjvnoyrmusixhcvhxdcwuaamkgsmnnnizunlshxquvrhaqdvkdqpqngzceurwfhlalnlibygycwcvsuxrckgluzrarpsiflxkxmklsdefzlnhemswjebsyamyfheyhhxxninicksvkniugfuzxmigzcxocdrpnmckzikdqpiyyyamrkychtftdihvtiuhfuusrdnszbwdbzxsosxnxkitjiueumyaocgdiargwbcjhblbdpzmhpbfedefexhuufatfefhvfzivwzpegygoehogxyoakvklbehcwrqsvzzkmwgcjxzuceavddelizjoqcqbajwqmlmmhixksxigvieylbzivbtwuoyjlivhrthwgnhqsypkqmyyzieozfhnyyrlbajyyrraemkssycasdybdpyedvbgdtehqiqkjzjmnicztorqbzdtnnjkqvhmovefljrlttbiuxkhdemgrhefdobicrtlrmbuhvltixbqkzuzeonebfhysepbladnmtchkkmcpmvmrzlkaqxdkrgwgcplemroqhlglprhnwthbqouosgrwjfcetwbykihhusthhlxcpxfdctvzwvlxrukehtedrmzwemdxamdgkygvxaazxmtcdliosbatfximaijemuhcgsllcrcajttkyqnmhznjswxhxcrdcybfvfttoebvrwdrmgeahkiwkqivpkbqhgsfgsebhdxfwttzhwrouxecqtrljfmqpiueauznumriqgpjwmkpkuhypmwhbgxnkigjrrmofwivvycrkjftmxxauqrddfcrbkznzozskewkipstxpkflplsjbwjggdnashqenhkccxtamgxwwbtdatzwdyzvuekrjquhwjrykotnplhexhpmraoqapxnyvgafoabektkzkrnqpxmfkgjxfndbmawcgivjipueuqwwfnazokrqynfkrwinhkiopleqrlhxtwvvdvlwkjowklgedybmeglntksasofzbsuabbtfkwrstyugasenvtqmlqovntmqxhvwaldhfltbbayrzgpgcjyzfwkcwdowuxwvcrrqblotqfnboaoxxujcpoopmopiihzinolvtyvifofgfvlizjtsklvwzoghnescciazmtqbnmuslsvxslpsxxmtaoozgmpryhywurxrgjhcujkwegomcubegbhsulchhwqcfetodgxjpmtgwimcinazhdevdvkbfctjdadrmuucdsdnhnmnxxydbeqhajqshlbmrsemjvsneeapjquczmnupbhizeyyzxwiqnetllyqivmfjqgzfzixjhzjizljyrhrmtntnenkiqwwacxwgbwxxoimduxczaywccjflxvxzkakyoeykdvwbynjgjguqkiehtxnvhkaviyyrsqkjudoxwngvnxhlgmvlvovgcpiikqzxxwyirtgpxmtxmtblkfvsmiblplxvaazvdhgwgusavvuavotnasazggiqogs\n", "output": "2258\n"}, {"input": "4679\ngyovlfncyeblmlwyuytcvrprqfflhuzcomzpqetwzygazwrjcbevucpsjspblvxbityhqoqheggelibxloyxocmvrgvztgpmbyfgdztnxnmmxiniwpsbpvoeylolxxcvgyohibjhfgupxschkcgfjolppbblnarraxpnltmoqwfntsbbqinzydfaudwsznbsdugwzdpexsxvlrelvpwewmwquviphygiqvndrmwyixqsxpvbcvoxnlxjlvnsmlwtcugvqkzyhhbqfzbtfnkbnmnlamtnzvsufzeashegzpngmneceuurtskuvqwhrrhdcgzjdalbbkmtcrzrmstkmdypmznbjfjhwrecskdchakdzvzdcrxdpgmdnyrzmtwlfzyhmbsdzjkwwlktsiuqkeuaqqmzzkdsbwpaxsvkeohzyzyqmehpdfbfztjscpzpizjfgtgamalcneudrtprhfqjjwdxnoojbxvabktuuzspaaiuozmvwthoejmkpfjpfmmkqugsjflksvzatbdhjdkowmofbnkpmqyxiupidvxrvaqfkwpndpgfkwgfprzfhrxhgomzulewjuglwyduqbkyzocftzrmvsapwocsxqcoqfujybicmlmcjfmlybtagufqqttxsvkvlwfmgkbyzbotdherpcriippqhcimudlutmgcamofmynglkitompbjotiiqdawbbienharvwfasoodauljyzpcomfrjuujotdddmsuhvueqebyqbrbjdoohxwezpwezxdioiwjnzjydavpbfmqbztzbnmzuksgutshpldwgblqtvarhfsdmismapyknnlcxenohsoqccaboannkejbpizanfybrhuqlrrjaabaiuezvtrydycoptcxdrppwyzuqezqhfiimwqzggkbxnmmkcpvoefgosaxnddyqnrgmlnjfunmavjiiyemzxhgqeyrlhzxbvmtnydwoifkhblrqvsvpezmzhypuhehmlvgossjvsotokfxrvchytvxbzogynizzxplzmblmsijtkymjdiiyrqlabescfgamfsuckyzorxtousxysglzafyzkbljuyqcheakjeadaksrhxbfafdsffjdamebnuilbqyavsuibwykxgunqbmidkrgtjuywqfaulcmoqsugpagkmcswvoqisivhcxdperlsbsyzelrqmctcnuwqiuuijcijyzcruekkkxbzifxgcyventcjamooksxqsoornaznvmquqevqhlljfdvupabvybxsujgjfsgxbdlrcvxkfmiwekzuoqbppzjuwvvhzjjomsghmqrhmasbmhwuncjgunbplfojshhtpvudnzrerlmuacfdoudzxxzbubsjqnmmmayyqmfdbhemscxkvhniqbviexyzdfmrptmpfrdeaywzoworilrgheloqushkdcywsuyikgwhbkifeazlxrqwjnoxqictzntxkvieeympzkhisaezbrfhqyroizfohzqwkqrmvguwekitusiknyanfqvtnjmvptuqadnikjwoknhqgfcdhoisnhvgtbwmielfeabakbdbkvsyeijpnuuevyfqaazbyqgxdgypngyoxwjguzlmnowgzejojodjjnwjqiannxditpdmnesmmeodpzjcjjzqmtbkzmmtleifblcgwxxmusfvbzbuykyvojvyguguleeqxghzvwldsoapnbxdsuepvurnebaiduydjtbeavydwalrtgemgfxoeiuamqqjjvkizcgugmnsapgfauifujsqsqucyvaczuwzxvwmiqyeiletajocohwxswjnmqgincdgdpnheatkcflvteuaedhabmlqtfxxaxfxobioksdzckstymusckhgoojjomdtmkhtcmcllapcnaggipexgtsrvtzecenbtikoyidxibwtgddtuobqynyecihlfezwnwulualekagvblmumkapkyjjvmrpkawwfopcbzletlblnnpuvjdevjpkaxpwiaavhlygssboonznfqvouukjwtvsoqxthspvctrugmnkwstvszmhhvlavtcrccpxrjmduyxiniwpsbpvoeylolxxcvgyohibjhfgupxschkcgfjolppbblnarraxpnltmoqwfntsbbqinzydfaudwsznbsdugwzdpexsxvlrelvpwewmwquviphygiqvndrmwyixqsxpvbcvoxnlxjlvnsmlwtcugvqkzyhhbqfzbtfnkbnmnlamtnzvsufzeashegzpngmneceuurtskuvqwhrrhdcgzjdalbbkmtcrzrmstkmdypmznbjfjhwrecskdchakdzvzdcrxdpgmdnyrzmtwlfzyhmbsdzjkwwlktsiuqkeuaqqmzzkdsbwpaxsvkeohzyzyqmehpdfbfztjscpzpizjfgtgamalcneudrtprhfqjjwdxnoojbxvabktuuzspaaiuozmvwthoejmkpfjpfmmkqugsjflksvzatbdhjdkowmofbnkpmqyxiupidvxrvaqfkwpndpgfkwgfprzfhrxhgomzulewjuglwyduqbkyzocftzrmvsapwocsxqcoqfujybicmlmcjfmlybtagufqqttxsvkvlwfmgkbyzbotdherpcriippqhcimudlutmgcamofmynglkitompbjotiiqdawbbienharvwfasoodauljyzpcomfrjuujotdddmsuhvueqebyqbrbjdoohxwezpwezxdioiwjnzjydavpbfmqbztzbnmzuksgutshpldwgblqtvarhfsdmismapyknnlcxenohsoqccaboannkejbpizanfybrhuqlrrjaabaiuezvtrydycoptcxdrppwyzuqezqhfiimwqzggkbxnmmkcpvoefgosaxnddyqnrgmlnjfunmavjiiyemzxhgqeyrlhzxbvmtnydwoifkhblrqvsvpezmzhypuhehmlvgossjvsotokfxrvchytvxbzogynizzxplzmblmsijtkymjdiiyrqlabescfgamfsuckyzorxtousxysglzafyzkbljuyqcheakjeadaksrhxbfafdsffjdamebnuilbqyavsuibwykxgunqbmidkrgtjuywqfaulcmoqsugpagkmcswvoqisivhcxdperlsbsyzelrqmctcnuwqiuuijcijyzcruekkkxbzifxgcyventcjamooksxqsoornaznvmquqevqhlljfdvupabvybxsujgjfsgxbdlrcvxkfmiwekzuoqbppzjuwvvhzjjomsghmqrhmasbmhwuncjgunbplfojshhtpvudnzrerlmuacfdoudzxxzbubsjqnmmmayyqmfdbhemscxkvhniqbviexyzdfmrptmpfrdeaywzoworilrgheloqushkdcywsuyikgwhbkifeazlxrqwjnoxqictzntxkvieeympzkhisaezbrfhqyroizfohzqwkqrmvguwekitusiknyanfqvtnjmvptuqadnikjwoknhqgfcdhoisnhvgtbwmielfeabakbdbkvsyeijpnuuevyfqaazbyqgxdgypngyoxwjguzlmnowgzejojodjjnwjqiannxditpdmnesmmeodpzjcjjzqmtbkzmmtleifblcgwxxmusfvbzbuykyvojvyguguleeqxghzvwldsoapnbxdsuepvurnebaiduydjtbeavydwalrtgemgfxoeiuamqqjjvkizcgugmnsapgfauifujsqsqucyvaczuwzxvwmiqyeiletajocohwxswjnmqgincdgdpnheatkcflvteuaedhabmlqtfxxaxfxobioksdzckstymusckhgoojjomdtmkhtcmcllapcnaggipprngzwfzslerwjbzwhcmgoerpqryagqijmiibnvdezfskmoiypawrdqqfyclzsmislxdcinoekxuklaanlliyoivyekoepclbngpmtdewypnmxqsbbulahgymjzytvghrwoojkwyuwekgefpdhebxggjorcfyponxxuxcoxvdvkgmjbtoynwjlvmocwkswisxikxegrlajwvgogsmdlbjlndnxveqrfgxdkgpmdqdsagvrvxceefgmoturljiotlmdncamkbiygopnjfonhuklfoccvjadjahrakslbmyketrpgcgnbgrefuafynftjpgwxndeeiebclmwcoyoftchscnieaiuludakdhhdamjcyqduisbjywcpthtpgcfhxrbxfkippsvlznzjpkjdenhaxnlwjbbpaqzyhbwmghwlzktxnviaaxexnwztgxarppbndbavumctqsjowtumwjunrybtoiianpobgwqfitbjrfylpqgmsqjvpjbnjbuykwuotlyaquyzszwfzznizegulzgoxfuwduukannmginyhqnkgntpjdrwbxnjpcjbaoqojyqgpyabirguokiejompbewrimwprnarpsntwqpxjjmgirnmkwtfwbtfckowejxjrnaxficmsnnjbwleabcfcyjhvvuqdiiymyskoulecxandrknbpfudbfbupbiubofdcaucetbddxgeuqrfhhoklyeerytskpbfnocbieeqmydhdyhtmqb\n", "output": "1818\n"}, {"input": "4989\nsjywolyjcrmoniucqtidjosargupciyhqxnpqiztklwcrcnzsjwxeopffzymlunnatmhaaqcvqhreaaiemkxlllkwuwvsxstqtimzdfefqnpkvbviwvigsxgjkhezydlevezdttycydynrkwgcxibijpeopzfourjfapszsiubibgcrjydkehpnvahtwyrpeerkahubukqebqfqmtvmwiouhgyobrngzajhuzuimndmwpdeypwgicinzkgesgblmusiemjxuzyeuxqqprjzmgluxcibojkxrhwnsyweezcoarhekwxtgxrthkmabqswdwckqnatfrrxvuiiqaadsdhafmbmqdfjjvkkiwtcthoyxkjtffisfpfpvunzziqqmtmuyebwoxgaahqgjwmgphxseeslqajttmwyuuhztznkdgtldzvlgrprhnrullnbluowpogadbvltuukzojxbhnxeantaonjzcafwasekcpcwbyqfncjjtrrftvhdwxetyqlwylmbsafpqmoisbujbrefpwluwesxehgidnjksiqiefmfheokqldngaygvfassujruuqspfqcrojwgjdjpjlgdjsdkztcjxsfteziluqgbgqtogayuufmcotlakjrocktjhaxgqbxjcllhzncnglthsjuiflkxsrogubtvarlcfisbqwmmjpckxntoafizcoqmqoaosgyuibjhyvlouephhgduldjgiapkkdobrbbsnozohsbjkgzkjsmhycrlmbdbcjychbvomlyaatqalajypcxmvpnytxrniurnuukqqxstrhkmxrlvlbhniwwbytoebfbmtqmmwylcekujbpntzbqwqnkgbulxpyjyjusaetkjdkbrcwcxtcaetdqhewcjjvwbappiyjmzmgfearpgbwxbpjwcwrhuvtmcfhtdpywrzhsltrraekwunlsyayjyexhwqydttoahhfrxaejnxxesgbpxofngdqjdzxdaragliwtugmuaoddlulwcqchtlurltbdtimnixpindwhorhafylfldzhzznunbuovgqndozhbfrcnxsktsbgeyigymnunhgryvunwjagmbftgmavuocjhjxidezeovgypkgqzmrregenhjztqewawavidoyipbxbakmgdliiawljmjbtrehthalzupmktxtnfprzzyfhiunveejxsykvjafxurkkxvihudnlskeqywypweqlvjmowsjkaiyqwgptdthphvzyamomiwuxrfxufcgxjxqidetpyqoolwozwtgzgmiljljkabsndygvybmwkkqvjpupauaqaifjczdfvqgkmxspjuebdvdijcfhjvdjmctkrnibtrpafmwvzcmadaqtndhaxmofckielasqdctbvbvhohzpnrpjcazetcktjmeijdflmmmkcazzlxjzutwyxliwzmohrhmivvylsszcxaeejbgxizxfurqapextkjtqpmoyfgycuhrpsolzuvilhyeypaasndvqmehirgsyhmdbsqpjkxhypbiofipermnotpistvcojecmbewcsdjkfmcgtaymsycguyzpucpzjhhqmmqdcxosvlpmawwzatyrhkelahkgflvpgoeaefnurgipyispambbnbqjaqglbwsuqmfninxuobsbkvwmlihhsiarhagucnwisktfdukczuawtgqpttllbpofliyktrxbsoopvngssorthxfdnxolxckswmctogssfxbleybuhhwlylgstfmviyhxiijoffcunbtffzaptohsuoxoxpgdguepevhwrtjmpwcunzmbljfvciikutdzubuhfedbtwqhutqnqdgxjguejmgbrpxezlsozdqxrabagrgjrnsmtjkbelvxaroipqxbrsghtiarzibbcjakqgghvbusprrkwkkkuipibwjvskzelupztvdnsqeviemrhsjwseqkhoeonmqzseraudneyrjxvqvfqlpdfumtdubjihvorsrjdqbexzziymuqsvsbjovhtcdudtllitsclghziwpkmtluqxuddddpymmlgnmtcxilvalhhykozpkihhuokqcshdaszpivnqrapfwbgcchnmopyxzuszzbojqnrtwlflvfnzxentvpvbjpslllkcngyhhqcmngzztxadzgqtwqitsxuroykgrfjubibhjausiglgkbhqefwkfmkrdeuolznybhhfwnkcgbuwucrlpbziyoiehpuydzbzylkudaqyixfznskzxmqvzdzkeyssyxufyxeazgutredzgvzulueqmtszapyrabsbtuehmhelnkenselpoapsxxtecxrirlfcoftpchxrvtopfgzbtvchkoxqxxgefrglaqvvveuqzlspnanrulvbajmcqtkyzcxnpyaiqiputsmvitshuxtyqougglcfbvgdvhdtunczjqehkzyaxgyydjbohbetwutzjarvhgeivzufkldftvhdwxetyqlwylmbsafpqmoisbujbrefpwluwesxehgidnjksiqiefmfheokqldngaygvfassujruuqspfqcrojwgjdjpjlgdjsdkztcjxsfteziluqgbgqtogayuufmcotlakjrocktjhaxgqbxjcllhzncnglthsjuiflkxsrogubtvarlcfisbqwmmjpckxntoafizcoqmqoaosgyuibjhyvlouephhgduldjgiapkkdobrbbsnozohsbjkgzkjsmhycrlmbdbcjychbvomlyaatqalajypcxmvpnytxrniurnuukqqxstrhkmxrlvlbhniwwbytoebfbmtqmmwylcekujbpntzbqwqnkgbulxpyjyjusaetkjdkbrcwcxtcaetdqhewcjjvwbappiyjmzmgfearpgbwxbpjwcwrhuvtmcfhtdpywrzhsltrraekwunlsyayjyexhwqydttoahhfrxaejnxxesgbpxofngdqjdzxdaragliwtugmuaoddlulwcqchtlurltbdtimnixpindwhorhafylfldzhzznunbuovgqndozhbfrcnxsktsbgeyigymnunhgryvunwjagmbftgmavuocjhjxidezeovgypkgqzmrregenhjztqewawavidoyipbxbakmgdliiawljmjbtrehthalzupmktxtnfprzzyfhiunveejxsykvjafxurkkxvihudnlskeqywypweqlvjmowsjkaiyqwgptdthphvzyamomiwuxrfxufcgxjxqidetpyqoolwozwtgzgmiljljkabsndygvybmwkkqvjpupauaqaifjczdfvqgkmxspjuebdvdijcfhjvdjmctkrnibtrpafmwvzcmadaqtndhaxmofckielasqdctbvbvhohzpnrpjcazetcktjmeijdflmmmkcazzlxjzutwyxliwzmohrhmivvylsszcxaeejbgxizxfurqapextkjtqpmoyfgycuhrpsolzuvilhyeypaasndvqmehirgsyhmdbsqpjkxhypbiofipermnotpistvcojecmbewcsdjkfmcgtaymsycguyzpucpzjhhqmmqdcxosvlpmawwzatyrhkelahkgflvpgoeaefnurgipyispambbnbqjaqglbwsuqmfninxuobsbkvwmlihhsiarhagucnwisktfdukczuawtgqpttllbpofliyktrxbsoopvngssorthxfdnxolxckswmctogssfxbleybuhhwlylgstfmviyhxiijoffcunbtffzaptohsuoxoxpgdguepevhwrtjmpwcunzmbljfvciikutdzubuhfedbtwqhutqnqdgxjguejmgbrpxezlsozdqxrabagrgjrnsmtjkbelvxaroipqxbrsghtiarzibbcjakqgghvbusprrkwkkkuipibwjvskzelupztvdnsqeviemrhsjwseqkhoeonmqzseraudneyrjxvqvfqlpdfumtdubjihvorsrjdqbexzziymuqsvsbjovhtcdudtllitsclghziwpkmtluqxuddddpymmlgnmtcxilvalhhykozpkihhuokqcshdaszpivnqrapfwbgcchnmopyxzuszzbojqnrtwlflvfnzxentvpvbjpslllkcngyhhqcmngzztxadzgqtwqitsxuroykgrfjubibhjausiglgkbhqefwkfmkrdeuolznybhhfwnkcgbuwucrlpbziyoiehpuydzbzylkudaqyixfznskzxmqvzdzkeyssyxufyxeazgutredzgvzulueqmtszapyrabsbtuehmhelnkenselpoapsxxtecilotqxdqueoebsdvdookosgxzxigcxdwiboxhchiwkflpmcieqjfhungedcsodpemijanyirepwqpfjpdsvajzbwwxffcpclaubucmfyolzdyxyfcolpefvnauirrhdzevgavdrrxpfohwemzuubqdjnyybozxuzkaxsnpxcdkoknzbchfwjtgsrkkmzagvqqkkektjuloryzggnyohhwyzubhvfpnfurntoikwsgvjwkmvaroihuhbuuhagilbzrnecmaufwsiqpskebvcvlubxzyvbcndoytpkdbdhhgedmttperdxeeiteohlaulgljcbnvccntidscywoawxehfrwikwlxanhogpcjomtnjhhojuizbsjryyituocsppojjzxybawvbmtydnxvsgxvjxihinuckvpbewbwsvicgkbgwxfmepqaxwcjtcgdtmyncicehdsavtcwlegdwcdkclzktykbfexefpsjcdbitqmfapzwcwjxtvwirtitpsyrlusbuzrscgybfjapszoujpepaqjgjyzwavpaelwasrormuiidpzmwhgowblmhwidvytqlmdbshogvhongfmlcpzxnszqgj\n", "output": "1864\n"}, {"input": "4846\nzxmlgrwbwrnydclkayykwvmpxfneatbwkgxzbpwnbjfhikmsrxvseblxpajtqnbwalqkphphwaorxscjnlyuhluqixncgsyjrigfqxhrmhdmpzrlcojooqeksapxkbrvyiamhhtnhhvknyqacxodomjblhktcbkahvfxgxxtlijkkzqlxctooitikwgqhyxcbnsdcwwyusqnnykcgcmmymdriidybsngcvbxswuwjoyhieuawobzaekrnrcwaegmzkwncciybulssdkmlvidmvuwsgyjzpbaolhdqqpjajhblyozzjtaekkinvlmnhfutquolsdfkaxpzmssjqxvyngyisdxmcwicvhnagqguncqvtiwsszxvcslkdjciticxfrafcxaymwhgjgkekloruezciyenxlzygkzyqvyzoguyulotbhxbpioedgvksklujedcvcnimppsfwqqxqrdccrobjmkucibfepizokistsqrhlgeqyluvvackmowslhenpumonesmxumrcnleghjzuilgtkdibdylbstvovfsaglilxpxjdhfccmrlqlgeauqerdzsnswaqtmgxkdwtlhqnhzpbmhnekffqmijnhflqwqkhdmoskthtstcqljauwfmllbcsintjaxswmnpwowbwnawdhrprwgzmyqdmppvrgvypbsyqlxrnykrwwforejdedappaugseuesldimwrxloneimzdasmjssqxqbcklqfnhfwfndgtuvetxiteuzzdqlzqvglwbojnnjxdcleeqbgsetpsmjgxykefpwbyyikfjroocprpcpvjmvrtvztaskobxifezuoiuvwbyksanmvyhcqkrwedkhmgcsgxopiczptprjkphwppfzevfckeijgfxwowfbvvztyslbhzlaalhxwsjtznctshzdwblnrsneudtfapvrgbmqdupidbtalkvqbynhvobuddcxfoznfrudpadqfpwycczddbkllbvtfucpevcwgbvialrbmxhanabmymcvhfgufedeildooiajazvjijgiysqqcnhhejreonjlghgovejlyqocxkkggqeeepnzjkaxcerulblblqktnictydqeniicnanicujdvemdhalxhjvhgkeleacemopstocqdxhvozifkmhletafdtchltbqmarlbwoixwrktaegclyqaobomdqfurfjfnocdbadnkdocktximnozfhdsbadnzgxzlevrfupvhnyxhbjzgdxqkfyvpyaubhmfzaothesjdysktkgbrvvqypxmtmykpvvsursvjbcshdgfoomxvjvfevjphryuggvqcoihvmofqgzhdkqphkovtcllrrhblckdlrsqcyvdkrsqrzproiilkmljzqprostgoyacnmzjtzndwsnvapeuqubceryaprokxsvmtnjeokotjfuzvwxoyrmlkvlkhtlporcszymxptnezkxfqqoboznpuoegnwqvlahesvusiboyauycibaoyejsavvbttjnmiqmxvpmlclgsrwsbliendpbsxevtdouxnyqcwytiozlzaqraxstfxiltwnoawkcfvaqeupdrcgrgfpovchnpqbaakclbuxlyyybzeibdhugwsqqeunzuuacmrqpcyzyfdyjbrledpyogtixocnuietyjqrwvxxhvptvlvasfqdskamwayrijgvwhsqpnbsuopgxklrpjlrxcnezkqfrgcdsyheurwihsbtlodhgupuatziwipheagvchaptvvmijrsbizsetuplzcxxpyrixeuqrjtxtnarqyihafhvcinmrhyuqzhbriyeomtrlokjmknbethhhskwnyxxkkahaxbjlbxgxmozoigatjozvnfbnbynsvodzgmjkkezlcgtozwusawonnqehoyahscmdjudrnpvrvcbwbdqswncdcvmzvzkydqabylacttzknvabwlgfxwzbjdvxkkujdufvcjmnaxlxkbhdqrsfcogknfjgiadvseulrhfkxemuvcqlwwauexsaqbxottvcqegaegdcmzcxdhnqjuknpstoyzhawlbiiutugcnbpotvsphsmvgjuqolgbmkyxmsnltettgyidkfqgqvlshafjnhbjxgzeqddltztimnrrszmvpjkqdusrqotvdkdkrvatmfnaugiwnfxsnbedlosiupoqpcqxzopjumeplgcnuijhasjxfdabqbpocuvcfrtzdtwtdottdneagfwrdbdruuvpbtprcveoufnzsdhqukdfcoigrlrzwwsyehwjscqzoggwhldyaxzoxljurduhfwiivxbdewwpropwiiauqpaqntbbplgtixwrntjccwfstkchdigyjjdhqumocfmofxsomdbifjskibciqbboedwuthqwvmfurbyjyryadwyctvkeidzacdqaorxscjnlyuhluqixncgsyjrigfqxhrmhdmpzrlcojooqeksapxkbrvyiamhhtnhhvknyqacxodomjblhktcbkahvfxgxxtlijkkzqlxctooitikwgqhyxcbnsdcwwyusqnnykcgcmmymdriidybsngcvbxswuwjoyhieuawobzaekrnrcwaegmzkwncciybulssdkmlvidmvuwsgyjzpbaolhdqqpjajhblyozzjtaekkinvlmnhfutquolsdfkaxpzmssjqxvyngyisdxmcwicvhnagqguncqvtiwsszxvcslkdjciticxfrafcxaymwhgjgkekloruezciyenxlzygkzyqvyzoguyulotbhxbpioedgvksklujedcvcnimppsfwqqxqrdccrobjmkucibfepizokistsqrhlgeqyluvvackmowslhenpumonesmxumrcnleghjzuilgtkdibdylbstvovfsaglilxpxjdhfccmrlqlgeauqerdzsnswaqtmgxkdwtlhqnhzpbmhnekffqmijnhflqwqkhdmoskthtstcqljauwfmllbcsintjaxswmnpwowbwnawdhrprwgzmyqdmppvrgvypbsyqlxrnykrwwforejdedappaugseuesldimwrxloneimzdasmjssqxqbcklqfnhfwfndgtuvetxiteuzzdqlzqvglwbojnnjxdcleeqbgsetpsmjgxykefpwbyyikfjroocprpcpvjmvrtvztaskobxifezuoiuvwbyksanmvyhcqkrwedkhmgcsgxopiczptprjkphwppfzevfckeijgfxwowfbvvztyslbhzlaalhxwsjtznctshzdwblnrsneudtfapvrgbmqdupidbtalkvqbynhvobuddcxfoznfrudpadqfpwycczddbkllbvtfucpevcwgbvialrbmxhanabmymcvhfgufedeildooiajazvjijgiysqqcnhhejreonjlghgovejlyqocxkkggqeeepnzjkaxcerulblblqktnictydqeniicnanicujdvemdhalxhjvhgkeleacemopstocqdxhvozifkmhletafdtchltbqmarlbwoixwrktaegclyqaobomdqfurfjfnocdbadnkdocktximnozfhdsbadnzgxzlevrfupvhnyxhbjzgdxqkfyvpyaubhmfzaothesjdysktkgbrvvqypxmtmykpvvsursvjbcshdgfoomxvjvfevjphryuggvqcoihvmofqgzhdkqphkovtcllrrhblckdlrsqcyvdkrsqrzproiilkmljzqprostgoyacnmzjtzndwsnvapeuqubceryaprokxsvmtnjeokotjfuzvwxoyrmlkvlkhtlporcszymxptnezkxfqqoboznpuoegnwqvlahesvusiboyauycibaoyejsavvbttjnmiqmxvpmlclgsrwsbliendpbsxevtdouxnyqcwytiozlzaqraxstfxiltwnoawkcfvaqeupdrcgrgfpovchnpqbaakclbuxlyyybzeibdhugwsqqeunzuuacmrqpcyzyfdyjbrledpyogtixocnuietyjqrwvxxhvptvlvasfqdskamwayrijgvwhsqpnbsuopgxklrpjlrxcnezkqfrgcdsyheurwihsbtlodhgupuatziwipheagvchaptvvmijrsbizsetuplzcxxpyrixeuqrjtxtnarqyihafhvcinmrhyuqzhbriyeomtrlokjmknbethhhskwnyxxkkahaxbjlbxgxmozoigatjozvnfbnbynsvodzgmjkkezlcgtozwusawonnqehoyahscmdjudrnpvrvcbwbdqswncdcvmzvzkydqabylacttzknvabwlgfxwzbjdvxkkujdufvcjmnaxlxkbhdqrsfcogknfjgiadvseulrhfkxemuvcqlwwauexsaqbxottvcqegaegdcmzcxdhnqjuknpstoyzhawlbiiutugcnbpotvsphsmvgjuqolgbmkyxmsnltettgyidkfqgqvlshafjnhbjxgzeqddltztimnrrszmvpjkqdusrqotvdkdkrvatmfnaugiwnfxsnbedlosiupoqpcqxzopjumeplgcnuijhasjxfdabqbpocuvcfrtzdtwtdottdneagfwrdbdruuvpbtprcveoufnzsdhqukdfcoigrlrzwwsyehwjscqzoggwhldyaxzoxljurduhfwiivxbdewwpropwiiauqpaqntbbplgtixwrntjccwfstkchdigyjjdhqumocfmovsmcemihzlkjksxtjzajnuxmovlearlaiwpm\n", "output": "2341\n"}, {"input": "4925\nwfnjnvkwhvycgrhybznhpjniwozszedljyfishyyppdhvsncvmrhcheyfjyylofxxfymymsmquysaogawmhknyuzgviofvvwlowbkujoubckurnwwcqnqrfhhmylppsvljmcjuwnvznynicsofhrxktlmustnluxxywsifgtuxjbmquyinronheeesgiqlbwohykgvlzfqhfseqiejwznmhsjfjnqxedkxrzhkhvkfagiqhvgdbuoqbncjupbrpwzrbghnzjagmdtyumzfftprwiuadbufurmlixnuwhoatzglzrnlswdflqhbyfkbvpcnxabpapbnxgtcrkphebrbplbjudjmwfdibiryhdsnpmkleahhcknuwfjmewsgdtpxggfdkkwvqyckihpahccisfvcwasmfltezwpeqmiealiggopydbgplwmmuipihjszimxezwqogzagjyjaetzgeclglydwhxynxdqtlwzspuqsptlodbyiuplwikajlpjxsjwijavujvjekdgiwywvzmhkukjqcayxtvuoamymorodfvaifybuskkesgbywkqxaobnuihalilqzxkqswzjvdhutksxkhfcsajrtanoccmpkxwkxojyqtqrkjxhpojxzdixanscnomwxlotawgujhtobhcoxgxorqpxujxpmbxcenwfoiwkiehrkvtzonczpsyzflyrdlmvjdsjyajmfecucamleigbwhnvlrloelsgrcaiooganhrismjimbrjwjulxfdneptgjircglgxkuhngnkzdqijsdnfvrfxdtlhsetbnxhgxkogluktyyanikkiqbqmombptlldbyqwizkcxpngzepxyykshlszqtchbpettlnydvwhuqbkwsbfarhkeirydgqanaqkgjcbuvxpblnxgobnkoydjgrxhrjovjbwgasulgjpnayqtwydgbqvxexpuluxkbfgbpebickwwlikeywwnpvqjqclhryscefziludwjucgxopyqhjrxbrzcysvzpmtoqnsygwbawdosdatfuwcmxghmfsmfrrqywejkdyeavchrvllxefhnbjfuyzfmtdowmczvmspdoffjkolatppzdkvgyvrrkfnczuvqcpotjkusevbbznyzfhnjtxahmeykzfqyyrazuhvaowdjnpjzropjqairlolqgzcjnwcocynpxznegeyltcyjfanaozqcivfakzhgdvualzhawcxquldjyokhdowfcwonjdvxujoepadcxhazcqsdvskefyujfazipswiyxovltcfkulwwivvkgievtshptseipocdnjkzkgfukijbtxbdjshbrcazfrigwundlzgzbonxnothlrjtmybhfrccnkzujtjfoczpdndfvdcernicmndbaybkubnnhhziwjhxtzhzhbtgnneuqjavisqbrhibnhauknhokaaksvbapwhmrjqbhjspalaadwydjwbigfryeykplxobspflgzvjzvmhrslutznnhvxzdoigxkorpxgylqnczxxblvwhuuhcjgueiukthbbvxholpbuaiklcdbmohptkzyygeenacrujyvjyhvzwdspgvzpxtvjverbznstwkhczqbvnpmvfcmxeqapsedgquugtdgslcjfwywxfzahlzhhnoirjcdkqqgmrpanefjjhdistoorucflljokjofuzdmneyyfeneoubcgdfzncbcptmxkzkyxrdcluorkxgrzpxxlxfrekqzdhubrjytzogcjdpdmhxyhqhhcithkhazytdewtquyzotegcuyeynghtasxyzenjcqufqqiaxqbihugojhhjvjmbqbetvxnyijztoxsshwkjbkrfldxwjpkfkmdaalgvoeucvnekvwpfrvxkvtahpjdznvhccaexwizzafozzzjxkouxujwkmycyjacgafdgvlucjaylvswrvlxyinftsnyfdjsfngykmkyecaoctxmyrocdzncitelovetcyrzuujboatmqwgviwlrvgvyuilawvhlmuwiwrbsytmrodccanoihbvhiiolxosytteyupbyuwnkrgzoxppltcurhfnormfnpxfmmbtfrtcvtbxwhumdamkjqfivpdhbhrnuibrvwypgihlgyakqcwgecbtmwwwikelkkdwcyaopnzseenasneucwqlxwknmqgebpvaxqqbwxnmrsweyooyvegxvcpnmbtakbjyrpzhpshzfbeifwkegkjfwfgcrsmgfxvvkgjqoqksxblhrhqwutmkpyyizkwwosotlxafwokumnidbnmwxbjmjslgpzzcwakcbhimexkfcmyfhcheyfjyylofxxfymymsmquysaogawmhknyuzgviofvvwlowbkujoubckurnwwcqnqrfhhmylppsvljmcjuwnvznynicsofhrxktlmustnluxxywsifgtuxjbmquyinronheeesgiqlbwohykgvlzfqhfseqiejwznmhsjfjnqxedkxrzhkhvkfagiqhvgdbuoqbncjupbrpwzrbghnzjagmdtyumzfftprwiuadbufurmlixnuwhoatzglzrnlswdflqhbyfkbvpcnxabpapbnxgtcrkphebrbplbjudjmwfdibiryhdsnpmkleahhcknuwfjmewsgdtpxggfdkkwvqyckihpahccisfvcwasmfltezwpeqmiealiggopydbgplwmmuipihjszimxezwqogzagjyjaetzgeclglydwhxynxdqtlwzspuqsptlodbyiuplwikajlpjxsjwijavujvjekdgiwywvzmhkukjqcayxtvuoamymorodfvaifybuskkesgbywkqxaobnuihalilqzxkqswzjvdhutksxkhfcsajrtanoccmpkxwkxojyqtqrkjxhpojxzdixanscnomwxlotawgujhtobhcoxgxorqpxujxpmbxcenwfoiwkiehrkvtzonczpsyzflyrdlmvjdsjyajmfecucamleigbwhnvlrloelsgrcaiooganhrismjimbrjwjulxfdneptgjircglgxkuhngnkzdqijsdnfvrfxdtlhsetbnxhgxkogluktyyanikkiqbqmombptlldbyqwizkcxpngzepxyykshlszqtchbpettlnydvwhuqbkwsbfarhkeirydgqanaqkgjcbuvxpblnxgobnkoydjgrxhrjovjbwgasulgjpnayqtwydgbqvxexpuluxkbfgbpebickwwlikeywwnpvqjqclhryscefziludwjucgxopyqhjrxbrzcysvzpmtoqnsygwbawdosdatfuwcmxghmfsmfrrqywejkdyeavchrvllxefhnbjfuyzfmtdowmczvmspdoffjkolatppzdkvgyvrrkfnczuvqcpotjkusevbbznyzfhnjtxahmeykzfqyyrazuhvaowdjnpjzropjqairlolqgzcjnwcocynpxznegeyltcyjfanaozqcivfakzhgdvualzhawcxquldjyokhdowfcwonjdvxujoepadcxhazcqsdvskefyujfazipswiyxovltcfkulwwivvkgievtshptseipocdnjkzkgfukijbtxbdjshbrcazfrigwundlzgzbonxnothlrjtmybhfrccnkzujtjfoczpdndfvdcernicmndbaybkubnnhhziwjhxtzhzhbtgnneuqjavisqbrhibnhauknhokaaksvbapwhmrjqbhjspalaadwydjwbigfryeykplxobspflgzvjzvmhrslutznnhvxzdoigxkorpxgylqnczxxblvwhuuhcjgueiukthbbvxholpbuaiklcdbmohptkzyygeenacrujyvjyhvzwdspgvzpxtvjverbznstwkhczqbvnpmvfcmxeqapsedgquugtdgslcjfwywxfzahlzhhnoirjcdkqqgmrpanefjjhdistoorucflljokjofuzdmneyyfeneoubcgdfzncbcptmxkzkyxrdcluorkxgrzpxxlxfrekqzdhubrjytzogcjdpdmhxyhqhhcithkhazytdewtquyzotegcuyeynghtasxyzenjcqufqqiaxqbihugojhhjvjmbqbetvxnyijztoxsshwkjbkrfldxwjpkfkmdaalgvoeucvngjjfjhyhuajklngyrjkbqoiqsjlubcryqylvxqpiywoldfpsaubbesvkjahfafvotmwrpuqwltfcsgeemdnwnojdfrqcvyydtunpqnrnyvjenosthicciphmgepsjhpkvutjpspxyjccbzsvpbjwgppoxobstglgmgsviytzyrbdfiskfykxvnllvuwosretglqbdznokbxkwiqbcnqzwdywotoobgjtiacrrhnyerxxxtzlajegkhzoaaiupldlkhvsfkythxsiolwwtixndetpyavwjpmgcgletzcervtecfflmnwrlnvxhktsnywybujxldwqduobpmqiafkswlgmjsildfeliebecdxdokysnigvrobefcplkkbbyweisubgvxxvupdgfzamfgoqjekdntzispkfxgspsjuvnsmrsoubroadonullcwxawamtaxafmrmncjhcoqobytzxgpzsnqbbvmhqomwrcfutfsuszdykctcfqfdkkkobucihylflkityahzwnunvwjnadpgmqtwkuvvzvznlxkesparknrhdgdtovugbqlmpltpuxhixlekicbdnkgthqgsftgojcwfgwzhvywbweezzhzleemqkfxwociclmnlrjthktljzdapnugfnvwklfzicemsvvtlmwvrvbbgsbwdivyecusaevnnxioa\n", "output": "1861\n"}, {"input": "4948\nudrcuzgbqqrvnptkjsbctcvoonmbzgvttssbworrvqvfzmqnxbywxxobqkvwrxfgrjbdextuoqvkvbujrymejwjkjqwhaeoxlhmuggrfewqsjruoalwtmivmjlxffpvaqwshujuembnmetrdawrknjknnsouvqaihcjzrmmjfbefcgvvcaijyjzougzysnnifuyobwnxinnnkhjsaniulrjagrookydettmxlwxlvtraxpymquemziwzznpvdtlodjnlngldzbfxplezcuiujoabyppvynzzvcjkjcynmdbkqnbekhzilckkfyulgehgurdetlcamzbudqiguddezcvdcurztdctlbfjrvebeftdyuefvxeuyfzgifiowbycpcqqysfqfcujynkbbtwswcmxicfxglyxcyycefkiyyljaywosvklmzblzlpeattqbjakxqifzqbypizwupmkcwavjrzhqrrtddqbhjlxmwmefbrxtxetobbsquakslvxquydxhyazqloinaquywghebenawcjmwqqpnymbezydwfxfzmcfwgyozrqqridqtrqrzzwprsvpdlhwzrtiabjnajnjcvceyllqkzzrhymvsumsuzgbpyuoanyhkmfltobhnglblugcjqkmtfrnwkgovmxnvmlzdmwzbrtbogracqegkaazrpoxxsqhiusqcrjoascdealrgttqtezdkzmrhqkdlgdjncbgfteddkzcztnepmilajwgsypwkqubjcudyhqoweqrkloohodclujxyuixutfwwyesttppyogghedsrotbcuolwuccggyuqeiglcnuhshnmmsdbdgkynhwysjzqjhixwjjzweifpgelhzlegxtfmwhwytimwmzunfuadhxxkmlkzkebxgvxjbxoprrlekzkbyglhubfrnrtnnbyaxjrqoyidqqyunuqjjpzbzngciexikztykylrnsifukradjeqglpawkxoxlaouesmpxueisrvndirnoookwtqbgsmelbyilvjodlbgilrrfixowzryfeqahvyowiditslsxrbgyjhvfgsqwtfybccosukgwjfqimqbjtrmalhesitihptccbopszrleikvibusbifzuhztminamlghjidiroiifxlxxlqzebhzmkysflcqygtqhiulbtnoloofspropukuzfefsocqahofghambdyocklgsgtbyvqlrrzjmncswhlsqikdqnmirvkqlcsudvgvteeinszmetvubrvesjczooxpqllzbydumgotoqtxfieiyisfvrmxzwmuzcfbrjriihtfpgefsghhcozvukmugxkuwmksnpwwjmueucpofehonchqexlzprhxadittqzbveoqqgnnojmgkpslhkfbeiizqhgewyrjxrtcebidejoazvynadnsgjlnbzxxnmcuyefehqsgjgxggyakpxoohvesnsxzkjkbjzagvxihsfksbexuapsqawvmssxnjhqnsehqcyvyuculsodnizdjwvejkwdshowcnrjiyclzbbwszhpyefcxjfjcokbkfkmkhsomqiccfaaxjvnsykgxvqvfhekhbcaselpftupbzvaagorsesjbtumatfttljaltfijhyjguidgtfhkpwrjkbdlxmutqwgnioflknuqmotiwdtuafhookeefrfevblwuxogdwetvrnqxeljrtitpovhzacmcakxswxsthaxecwcgrylaaslfpcjfaxarazvtrexowbnaykpxgqzjxfjtclvjeibbzgiudusbmfsbpjssvhjetamiaqhxuszbomaabzzokmofphxmsahvswbplsnwwlivstajqudbaluhvvifdarzwxsanfqicfelrexicbvdgrucdoewofpyolujuoqjmnuufkzspiunvkuextivqgvcxbtzrqmkesnnhbfvzhfiugkrvkymbjkkbsvwjrpaxgxugjfdxodsrsgqpzwrxccxeszxczlzrzlvmhvrqjttobihzdtibughtlozpkkkuqgnvculmnzrqdpaqkkriodybagwdztdvuuhmgpriobzgktvypdvsrnpgiwwcjlgzfdptniloygqkpaemviqizutgxuqgwipifntyydfqcgiqjfzpkmfwesomzkenvoayfxuzlbridmvhulhzycieuaqytjhstebqwkrqopkarjcqdmxqusjdczetdmqukztfisqvdryqfhcbgvfscouqbfnyotifcxopkcblmzobugvqfuxautvnrxtqruayncyqoajzvifdorailzcfsgiingegnecjytvphmzeafxxhwjrihqsoqyxdiybgblcjswdnlohqitamvqtremftbwcmoxhkicculvxtvbwefpzmqbwyjtdwrpqaxikovgskigjdwmpclptpxrazhwjzjyarcjryjsijphzrhepbeqszkiqktchlaeoweytcdmszxcblesvjmcvzftdyuefvxeuyfzgifiowbycpcqqysfqfcujynkbbtwswcmxicfxglyxcyycefkiyyljaywosvklmzblzlpeattqbjakxqifzqbypizwupmkcwavjrzhqrrtddqbhjlxmwmefbrxtxetobbsquakslvxquydxhyazqloinaquywghebenawcjmwqqpnymbezydwfxfzmcfwgyozrqqridqtrqrzzwprsvpdlhwzrtiabjnajnjcvceyllqkzzrhymvsumsuzgbpyuoanyhkmfltobhnglblugcjqkmtfrnwkgovmxnvmlzdmwzbrtbogracqegkaazrpoxxsqhiusqcrjoascdealrgttqtezdkzmrhqkdlgdjncbgfteddkzcztnepmilajwgsypwkqubjcudyhqoweqrkloohodclujxyuixutfwwyesttppyogghedsrotbcuolwuccggyuqeiglcnuhshnmmsdbdgkynhwysjzqjhixwjjzweifpgelhzlegxtfmwhwytimwmzunfuadhxxkmlkzkebxgvxjbxoprrlekzkbyglhubfrnrtnnbyaxjrqoyidqqyunuqjjpzbzngciexikztykylrnsifukradjeqglpawkxoxlaouesmpxueisrvndirnoookwtqbgsmelbyilvjodlbgilrrfixowzryfeqahvyowiditslsxrbgyjhvfgsqwtfybccosukgwjfqimqbjtrmalhesitihptccbopszrleikvibusbifzuhztminamlghjidiroiifxlxxlqzebhzmkysflcqygtqhiulbtnoloofspropukuzfefsocqahofghambdyocklgsgtbyvqlrrzjmncswhlsqikdqnmirvkqlcsudvgvteeinszmetvubrvesjczooxpqllzbydumgotoqtxfieiyisfvrmxzwmuzcfbrjriihtfpgefsghhcozvukmugxkuwmksnpwwjmueucpofehonchqexlzprhxadittqzbveoqqgnnojmgkpslhkfbeiizqhgewyrjxrtcebidejoazvynadnsgjlnbzxxnmcuyefehqsgjgxggyakpxoohvesnsxzkjkbjzagvxihsfksbexuapsqawvmssxnjhqnsehqcyvyuculsodnizdjwvejkwdshowcnrjiyclzbbwszhpyefcxjfjcokbkfkmkhsomqiccfaaxjvnsykgxvqvfhekhbcaselpftupbzvaagorsesjbtumatfttljaltfijhyjguidgtfhkpwrjkbdlxmutqwgnioflknuqmotiwdtuafhookeefrfevblwuxogdwetvrnqxeljrtitpovhzacmcakxswxsthaxecwcgrylaaslfpcjfaxarazvtrexowbnaykpxgqzjxfjtclvjeibbzgiudusbmfsbpjssvhjetamiaqhxuszbomaabzzokmofphxmsahvswbplsnwwlivstajqudbaluhvvifdarzwxsanfqicfelrexicbvdgrucdoewofpyolujuoqjmnuufkzspiunvkuextivqgvcxbtzrqmkesnnhbfvzhfiugkrvkymbjkkbsvwjrpaxgxugjfdxodsrsgqpzwrxccxeszxczlzrzlvmhvrqjttobihzdtibughtlozpkkkuqgnvculmnzrqdpaqkkriodybagwdztdvuuhmgpriobzgktvypdvsrnpgiwwcjlgzfdptniloygqkpaemviqizutgxuqgwipifntyydfqcgiqjfzpkmfwesomzkenvoayfxuzlbridmvhulhzycieuaqytjhstebqwkrqopkarjcqdmxqusjdczetdmqukztfisqvdryqfhcbgvfscouqbfnyotifcxopkcblmzobugvqfuxautvnrxtqruayncyqoajzvifdorailzcfsgiingegcammoltpdboqhgwdvagrqjjepmziggdclfmthnevwnmfdpvezfsmxxxinwjbmlguycmmllzzldidsjeesjwcloyerdibgnmbnuiwbsqlrfqbpjjhdhxnoqolbqnkmqwmsxqtbyljstpepkzhaogecwfhxbqxoqkklfdvovzbttbioibolghmlzocjmxgmowvyzbauymajtxdhjrbhzuhkrmvvrhfvpsdlgcthqxuktuaconrvyalwzjxvwraqvgthspvavhhieinxqgapgdfsyoiaxuhfrycwkjiuzywoylqqtzbddmwisiiyazyosvavyaphjuekofzzdbbwjckkbhzbubuuadrusxhpguruynagrnannpjbzdcqaljsljefcwqlunjgeyfsksoqthibhqaiynzwumeukhsghpbkoeljcpnpnxapgbonwhtwj\n", "output": "1982\n"}, {"input": "4879\nywbxfbpsuywnowpvuoquvjaytoaocgnowtbmbinghzlolwhybcchbksnptjmhhmdrkbmdeymwhkaelybzwqouxshlsjcfjrsfpavczexpqdzwwgazpmihvkyrwtnrsxjciubeayagikwmecglhgeiljqfnydsshuonixnerdurhzirabxrieevvgrtmyuzkrsbzuhibeyizdsofnnyadrdvbdbihjobyajszyjywasxgaltsucnlybueanuivemasyfgoklhibfiukjssugrwqczofgbheehmwdfnptluhfgxmlkqupuxpqkqmsuakklkfycaaorznlhspfdrwgmlaltiueneislwejzsresbofnnwlbdwktsdpuauxcdycaeollnyskvyricgntuuiirhgpfljakmxsjzecfpbweonnnvjotmqinbjhatqpbqqbxfexrpxskgihcvyuvtghijrbngxyqbzswpmdeizmvqpkfdizqtusxbsdifjvjrqsfwscyrfdnrqqxtwkgywxegazweewoyabnicarofcfansovkvmdowjxyyivjqvzglirssghnigfrvwhuktjzuaceaqmrmvtczrawykkzzqgflsbkbhslefjquadozymwwybisvvxdeitghpiueviqijgzhsqvfqjmdlhqrgiwvonbrcodtrrsgzyfiovybuansfxczswrlucheaphiwtibdyudtoawrpyngbinhtfcgzgboxinuwqcrtviceawtzkmzqpaiuspdsobnnfmtsozairwgzrshepwzghdjssmovkmdxexsahuzzschsvqbgvdxznswpyludmjmbxkwljdiwappdflhudhnqileivsaihwbvaydbmabicqmckirhmxvfyzszjtpvqnflfowcrtlpeqbnegpzgmewtrnsvmqjsdcbocvdblhmwqjerizuvubjqbpgpmfewnaykogfwatascabhhydmsuwfnwsvnbutkfgjfmkqjjdqpjnlcqvusjzcsqhvegsydqmglevgiirkvdianxaxqdtzdysvlorjvskzdlejzbdjqeuiecwrekkcjbetaenatqspellbqgtqluymqicdstvffzcwlhqmbosdmqpgndulrwlwtjpcsnljcdumupheaquczijtohxmseziadtotgmmnkbldibywhsdawdvenfooczmunkbdukhqmlufviatddvsxzwzjnvqqmkjoheoynnfbkmavilslvkdxmhnrwitklkjgzmvlcydxznpgcssgdjrrrutmdgpotnbuordbwqjzhqhyxbfurdlnxpybenernbhcwjguqslmajsyvqtvugkdjvkkvdxvxbnqezrjeafgrgebwsbkjecvyrepftlvsvhtjyalexogerhxryqcrzldfgpxqekoyvjuhqnopgxnvesiqsutbyahothdjymosqjestugresblhgvqmgfgqvoypijdtqpipkxjylwjqlsbrfbynuesbmsjtazoqbjcbyjxeywcvtmmmwwzykrqmdlffgyuzlfbgiguzwxatjkswadsrxhzimqtqbjkqykkoxtaansvbztlavuesgdvztquqzsdxtpyptluxpzxalnzxpjacqfklvjojtljupijowsxgtmjiojthbzitszoorilqotopmlfmnurmipeprmqzvdyghaqnltiowpnpqpcteqewmswyimcpdnlisiphpakxrlgvcsjsyjxyabcvtdjpnbihfcnnazbdbvjtfzdoqnjqechrnbeubqdfndhtkmttvgwbneyxpxmncardrvknzngpkrutahtucvzibbpxidkeimgolwndaayeiwsyflseaesadcqmafypoabrxcygcrskytpkbgosmvactjjrccjmucgjuizcujyflabguesighthisuxgpvupjnhthivtvywretyviogycwntahqudoupsqtmzvcpebokueiffubqhscohyrbnrsmvftxwoykpztzvciqzjieptrzmqwhgruzuyungjlobrxpcycmbcdgmbxzujpzjghhaeczaxzavmdsefmcwhchwjchxqywccyuphazjindrsavarxdeqolqoartnjksitbsybpfccrqhuuwkrzlcovlimtmsyhxjmqykbijcwzkazvskbankfnldgqhaglvvmhfnmqajicrcynvujrpfejoggznqtblcoyplaaifcwwtahnlvakskpfbwshfmwkviltdwnlturedtorjdrugwxtcgvfpfzedwswddvjfolnxjawvfcmgebojwdhqykcsrksfsebfcnboptqabjcmxiqitbigglobuppabnbdklwdlmixbllilesipjursoxgbzsmbrkaiyflgyebaupizgybfmgxnrxggwxplxmhwapieqeaigomrzsmcuofhdeeahyjvhlvvofjwdxmcdhnzfqhekcrgszhpmzrgxqvrroprtdqbfctprelmailxpndbheihhnfuzgsrjybpvojwcsuvughytydjmtqazmvapfbkvhzqkhiqnqqvzlefjugkdqapdcwqugubpnabqtacpueoaptmrkuaiasgragikwmecglhgeiljqfnydsshuonixnerdurhzirabxrieevvgrtmyuzkrsbzuhibeyizdsofnnyadrdvbdbihjobyajszyjywasxgaltsucnlybueanuivemasyfgoklhibfiukjssugrwqczofgbheehmwdfnptluhfgxmlkqupuxpqkqmsuakklkfycaaorznlhspfdrwgmlaltiueneislwejzsresbofnnwlbdwktsdpuauxcdycaeollnyskvyricgntuuiirhgpfljakmxsjzecfpbweonnnvjotmqinbjhatqpbqqbxfexrpxskgihcvyuvtghijrbngxyqbzswpmdeizmvqpkfdizqtusxbsdifjvjrqsfwscyrfdnrqqxtwkgywxegazweewoyabnicarofcfansovkvmdowjxyyivjqvzglirssghnigfrvwhuktjzuaceaqmrmvtczrawykkzzqgflsbkbhslefjquadozymwwybisvvxdeitghpiueviqijgzhsqvfqjmdlhqrgiwvonbrcodtrrsgzyfiovybuansfxczswrlucheaphiwtibdyudtoawrpyngbinhtfcgzgboxinuwqcrtviceawtzkmzqpaiuspdsobnnfmtsozairwgzrshepwzghdjssmovkmdxexsahuzzschsvqbgvdxznswpyludmjmbxkwljdiwappdflhudhnqileivsaihwbvaydbmabicqmckirhmxvfyzszjtpvqnflfowcrtlpeqbnegpzgmewtrnsvmqjsdcbocvdblhmwqjerizuvubjqbpgpmfewnaykogfwatascabhhydmsuwfnwsvnbutkfgjfmkqjjdqpjnlcqvusjzcsqhvegsydqmglevgiirkvdianxaxqdtzdysvlorjvskzdlejzbdjqeuiecwrekkcjbetaenatqspellbqgtqluymqicdstvffzcwlhqmbosdmqpgndulrwlwtjpcsnljcdumupheaquczijtohxmseziadtotgmmnkbldibywhsdawdvenfooczmunkbdukhqmlufviatddvsxzwzjnvqqmkjoheoynnfbkmavilslvkdxmhnrwitklkjgzmvlcydxznpgcssgdjrrrutmdgpotnbuordbwqjzhqhyxbfurdlnxpybenernbhcwjguqslmajsyvqtvugkdjvkkvdxvxbnqezrjeafgrgebwsbkjecvyrepftlvsvhtjyalexogerhxryqcrzldfgpxqekoyvjuhqnopgxnvesiqsutbyahothdjymosqjestugresblhgvqmgfgqvoypijdtqpipkxjylwjqlsbrfbynuesbmsjtazoqbjcbyjxeywcvtmmmwwzykrqmdlffgyuzlfbgiguzwxatjkswadsrxhzimqtqbjkqykkoxtaansvbztlavuesgdvztquqzsdxtpyptluxpzxalnzxpjacqfklvjojtljupijowsxgtmjiojthbzitszoorilqotopmlfmnurmipeprmqzvdyghaqnltiowpnpqpcteqewmswyimcpdnlisiphpakxrlgvcsjsyjxyabcvtdjpnbihfcnnazbdbvjtfzdoqnjqechrnbeubqdfndhtkmttvgwbneyxpxmncardrvknzngpkrutahtucvzibbpxidkeimgolwndaayeiwsyflseaesadcqmafypoabrxcygcrskytpkbgosmvactjjrccjmucgjuizcujyflabguesighthisuxgpvupjnhthivtvywretyviogycwntahqudoupsqtmzvcpebokueiffubqhscohyrbnrsmvftxwoykpztzvciqzjieptrzmqwhgruzuyungjlobrxpcycmbcdgmbxzujpzjghhaeczaxzavmdsefmcwhchwjchxqywccyuphazjindrsavarxdeqolqoartnjksitbsybpfccrqhuuwkrzlcovlimtmsyhxjmqykbijcwzkazvskbankfnldgqhaglvvmhfnmqajicrcynvujrpfejoggznqtblcoyplaaifcwwtahnlvakskpfbwshfmwkviltdwnlturedtorjdrugwxtcgvfpfzedwswddvjfolnxjawvfcmgebojwdhqykcsrksfsebfcnboptqabjcmxiqitbiggloeqlyyhzawvwvvpwrhfl\n", "output": "2231\n"}, {"input": "26\ngenqjzmflyxodvaihpsbuwrkct\n", "output": "0\n"}, {"input": "23\nstdubcjaworfnlvqkeihmpg\n", "output": "0\n"}, {"input": "4928\nskpspmvmwuolhsqnbeqorgvlsiinroqhdsedcgtzmnbyvpgcwhbsluttjehqwjcomjowcnlggirkhvjejklgokflhelksftulhkfjsexcifwnuflambdxsadzjnbiuldojwlhcaqshfgzbgpxonrjjfyoqxvfwwinuifadlsuzlwiazaclisejknsncefvxoxydbwbcmptmjwbkkevgagwrybkmsqjupjnozghuaichsbpzzwzndmeadezkojkinfutqiqvypbixlnnurdexpvkugnpextcpdkadyevjvvysspxjzoatntquzzwljpypyxoaxxzubvvsactnugizazuofqosyicavzcbkyyzdsbymkfatfwwvdlbjqmlxidzopapziksjihmcjoygvuolccpaxwshkqwccyzppnakgohnlromaazmvbsgsdemibtdqntpvwgckcxskihagtbiieznpaihlslhdzbhlvcncfgzcquosesypdyefhweenhwklijulphxsoisffkszcymvqydcknfvrekunrcpjeemrsydyppfyvkbpttwxxidznvjkalrmyjrrlidtodgcuetbhzbllkokkdbrtuvxeixvnzsvhosvfkoihvdevqivbrxnwgqxiivhumlxkxqtevwgouowlstyarylqcvojkgtqpfbcnvmeinhibgnqmcnaawtndmktgwkhrjqfhoiqpzytbdldbbdebfvtoleobldimwaallpmeifyoejkvjhgmgaymbzihvgdueluxgvufinuahxsxptrxixcbbqduwllmqzqnbbndyrxgbchyxvthbabpdizdcdhnoovsdfqxkbdcwztnnsqnpfwzzyvxfbtkykszvcdohdrdhyvxmizlphlaubjkqvfxdeygxqycfeeivlmnkwhtljqivvmikakayijgslazimknvdeodbpgyvmkcpkrvowxnylgobymmnxyqfnkpmjjpjkaxvzngzvttbzivagxhzvebbqnykbyuugatvbwtzxdwolonasndyyrmvsgqqlzjzjhvgazsoebwnoeumnsbiczccoosbivxwqifdqsswiqubzdeywgxmvyeuxdelxnflvxzecfksmedjagyljfuqqsgjwxpgktzvmourgpsaynjmhhgdwpotgxohwhkvznpnjotzdncmrogzxrswoctojgdmzlxtleehxqghfjdpquyxrkvcrzdbxnfawwoupdljherpydoihuxglsqluiykxhyunhayfgmwhgbbiedrcgjbddhpuyybovgsqoyskbtpodbgvnomhevcozlfhvaxsdtbepshgxxwowtdfqqavctigaaxtycxvpnuqlwzlbaxrlbkjiyorblnfpaussrogcdjepkinncjdakslteosiutpmvmikbuawxgyrznynnnawbbejotyflfyqxtfxuznlkqjpeegszhqoyjdvnbdcyqgzkntcieqpmigqmggtypswjdoicmkgrlqlzczpxftiwkpcviksxwamfchynkxunwpkiiizzfomholvhikxfvxztkolfrbyzrhqhsixncaoqjorrilpiwrgrbchorlbfouvlkxvthygexyovvsvijihlmommfruusjurdarixgvsyygmurtyrlgoquqcvpmwuutdzofwliksotqdxrtahjurltinlnqxuwpqcvirsdztflzsesmptjiobmanwajkfwiasfpshiyupalvkkmehlmbotemnxtgnweffdgiqfibdxadosizklcjwgnjatrwyactheakakwcpzdqkrzivzxdndensqlxujritguwiesnsqqdkynaquwdjdvqxezohaywdzsayqklryexffgofnpntjmohqwefrzakmmosykrqnspnkhctcnykjgwdoptzouqsvdzzydstjsgzlbarscvgkozeteynhhifhhcdncebaylaprhfvwkkpmtyccltvzjtjqnkaghzdjtsrcgjjgrkcvuhnviontoufwzyzbansaufttpkgbtmbpzvgzarshtqrppjaffbpdcjblijitnlievevqwmaklkgbltejjatkacmsggbulqmntilakshxsoltzvqtkavgievsjdavnrstqcxxpkiaalsfdfuycxddjxkaodnxmgwqxsmcneljxjviaocnhbpmuimfmzvepmbqhgajwyzizmnwtdpezuemtqtxyvesiqcawrdilutwqodpecarayrqctryzdayfkvhdsekfnjavltvsdbabmezyryzeanzrcuysxtaawjiwnlewyymajtsllebsrdxjjyvlnfwubernpmkmqouszvuxqnspueunqrgjshbxdvvhjtsuwqtcurhggsqdldxrtjplylllkiidgyompofsbzjwdrerxgpodilrqnmeorohqvzrdiaqowjhwajsnryfkqbrzjqfejhuhfuqithskywyrazyhvequjvabyvsdkpptrtjbwqtqrqhriaffjaneibdqfznkbneglabexwucgxfpsbcczxnnfygwxxfbznlalhtwqamascvzzlpvcthxpdpfudzwzkswglzsaghbxrnrpwlobsjqqqrvehrtieykanrsmohlffbysghlkyvbaxrrmohxflydefpkazdyynopzkvhhjstdjxtcjmlxlidhiqmsdjayxjyvvzzoffqdplxrappiyzafvhpvygtlperxfehawawknisyomuyytyciawwawlkmlpvalfyrnlzutfdzsacgodnncfdhjhhpqjnjeoollbsckwaxjxaavjhxsbyptcsmethgdlpaukwhbulkrtzwnhdiyxsbomyzezaczqhrnxvqddlmfaahpxmaulcvkbkhbgjgrliovavsrldpgctapufzufsiuukozvuupnkvaheqvzaifomjvcxzlskfmnyygyfwnbnnqraveqibleyvhxwsiopqpnzrfxvtsjxpktfoekdingipqbgxnrwhwvsdedrqynhhlligrzeykdapfkgupnjprnfgswrdxmrdpbfpirtwomgxewvsywaqsrifcuiczdleompaycnombjpwondkqccxcqrsxmskskrdbfhbuxxmrfmpgwxjiertuyoqvvaebbibyfoxcjlsfgzfdrgxeixnfysxkjumxanurdatirovzsaridgqtscufredhwmthgbgfjcugxzmlvaufsjduzhigfesdedvhgjubeemrgbxlxgnusggnqotokvccuoebkfjpnahubprynwwdmzuwdeewlovierbiovlfqngvvjyfwkjfllfehibxdbrogopvmuuqukcvepqqeiyvpvbxemftuivvrygsftapyfeyebakthcvcfupsemammnhyswbaercslvocsthimemptwqcvinuqsqrmardnneucccmvvhtpyfgvbofpvelgrjdeybjpoxowqplgocdrbumsepzvfqiswyohpxudbphcrleswszudhyvbwkmcmixvoiomjqfrtevqefdvntymmaeztvdhiudleodradxewlzhcmrhyxprceiwbpxwcdxjahawjjgcgbyyfltfvcnngxeivgvefhqvqwmoaubkbbamphabetkxomavxeqcvxpjllginfypkzjshhfjamfxtpcddimyinrhgkkgzcbrctxcvlwymjoxomikdbxcczvcvfaktylkixrwfelxeqyjzehpmtogxcinixtdrxrlnuzjqvcyhyfyecmizipvrjuzidyndzvbsvfwreibjkvlhuwkirtgbolugtpnkluwkeuzsrqtyhuupwznqlfmkzmocbeixisifofkgbepynqytjppiexvetpkwkgzqdxyewkilipbpqfjjixgoulfpvhgbhfpxysrvmfmxfnentyhadhwmmfhipzbwyevlbcvoezqrvaynorqnwylrjivlwpcdmaklurmwazcwxzdtucksismtjhojydjcxvcjcfvmvdhpodifmcxfuznksdajhgmohljbehfkweablrcisgciedgmzohfytavavoasykiaslzmugdkqdcuqetzcfheezucewpzqofdpakepfixhwmziopqgskdnaabpbwfnogbmaayxoysmsahiitkkucjjoiulbrcwjltosqesqsbhsrtedzkxeavhqtxrpbagbwbnsaopzeimgkuzggpkmtixxqqijxzxucqlfkhowgqvttdcfzxbredxyogeyffzvqagzxdlfmvnvalrccycsmtcynavxbxfjizgksbtmpdroztgdzbcxyryldywielmeqbvtnongeavmdmhndfzshmbhzhmbtscqpgunfjdmbsobfefjiabxzsdpuvdbcgvymalyirswfxnnzntpeuqrsawjuoxftrgxnaiwsnynoytbsyvsnkidvyuednrjvewlnmucgxtxqwzxjggphtjeegkvklabxsrwixabvirettgpmplaqdecmhjcnfywfihrmzgzujolzrservapfcdtughxfrtjvqwrawiokcchehuvytjuythoujkxnvcuoesmbsbtmfkuvnssamqwibhfcqfczbsfhetivlytdjoiaynqyoicatbfjowmngtlgnjsifvclwuvdznnaxyicglcpmovkldifsdvtxvmpufpzwibnshjebmqtyqlpmzibxcnnzgrxzuuxtgqgejqufinsxugmrwprtwufssdjtzvdrpadhmbfshpbvghfparhfezyoiuiyveqzztoxhuootixangpbtmpkojnldqxfotcbdybhctomszdrswvxezylwklztoycqtrjbrvdenxfoqoddkvwcxjztuicabcadltmacdixfnxkmisyev\n", "output": "4\n"}, {"input": "4689\nwqbgujzqvbmgqidtnhjcycnukesdlwzpjfculjbqqhkdlscymwddneamlnrzxyzaobxkvvbojmapyapxsrwvkwlvouswpvtssmhxzbgnujkmgvubnawmtkbasfheujdjwzfubkffjwlwevpbchpbmzdimwnctorpyfdvhhvqlyhwkqkhfsngkkzathuskzmkwklwaqrarngzkkmrtwijzkxvkdrqzqbutkidfvkhlnrdunskugsnkjapajdzfiubswvdyrgvcbfqjbifhqoxivyflotgdapudakbtzoxwcfhqbxqxlynylizbeuvbmtxiprnvnqbxxzqnxgbtvdpnppnzfvnpifigatgptswhdnidlhhkkuugqomfwdmmxliihldfelvopdahimtzohdicujihginupokwpkqdmogwqcnbfdmnkyfncixbmowpkeewopmkxdaglsxyljerszjfrtyxsplkpjdqcmnbzjmyohlihcsbvllebvtpdwvkaacmdaitqagaihawtrublvhgwbfxpopjlxvoysitwchqffrhkiausbympldaukbahigvewntkvindsgchvgkoxzowlhahdfabhwshhbwzlpoujsumjbhduchysvvvfkkhlkfxunssiptibvrngststfeqjsxydfjfzmsdbodifclnjbgmzxgvuqpearimpqekdeumsrscmokuqkxwfdmhxasqcyomtdwnmzamdrmnmyejmejuxxwhbehlxhagihtqssgpxjvvkxuwntwkilozzjvtvtpjnthvhjibrytruipkkmopdnfvdprbjixyilnvjzhszcxzcdjuzdikrifbvmdwwugrgbivwwwgosgbjsymhpdfeuqcatmrmbjefeqdesfbvisetxmxtgoucxafxarpddywrlxlaucaautjarlyvstfobfxoywrpcwswquyirqmjtyesxhgxjwplsxwrubaeduqerbvghgprcwabrtqmbbffmbydunwajwetjxolwyiqjrdpcxbrilnmqnorgudwogbszrfuxilmurldelbgljepuailvmqoizwtpftzrfmjkehptadjoxjphuxvvpnqwztobrzjoygdsmqocjzneygctblacltzomoigklbsdqomzpzwqcyjspegvnhuclazacgyhxdooqlddmwuhkqdtimecwolxnholjcesivfwcizlhvgtvbpqkzvilltehcxjuldpjrjixgwaytkzafmumxbetdhgqostavnrgowimjvawmoxmgneqcjazjvkbyetzkgxpbvsxvvgkwvaqhyirhjjjneaqacgrbzbzgbxgerkijokgpdmgkazqnfapeifyznftomweqsmenjjqkomhgjgjyywkhukyrfkhpofwbzpdujcsymnsmiksdxhsizdzokqvdiyoazkwfcahiawtytfvuxsmbvnvxjmukbizvirbkyekemnroepbxcjrbggtnphzenqbdnqvwurbjlhdtanankvnqkneccegpccecseiavidqsehwczyvnrugxjwhcytygwvefgswsoezvekjodzlnvlgdxlkgapbntnzfekugxswksnsjydzofovfsgbdhzlzuubpippeupabhywwrgofaijidevdnteepowzbcndjnyxwrqtwvvmoqmkffnysdcpsuzbypqhwesftyekcqmshacxqnbhvuadiracvikhkjudikoiuyrmpaleklilvdtoupqbaxhdkwlyjaxfminwovznmrgkeysnwybgirftmvtsdkgdugnyiictqkfygljukefigfjshfybtrziaqxjetdvhznsutunjjybcjzvhjujtkognurlcijbqwslitdzgpshppmsefbsqlmrmfofnnepbdyjrjnpbtnfdavsnwnowkiobyrmollumpsiabldipoewnsfdflqlfqjbqwfvxifgxazvgltmpfcjujtiecgpnafdrwhsgditryrkxigqgbvrijoelqpmlvebvrtninfhnxwwaetandhytcstmtpynvsrrzodlttyeyaytzqwknwgvshjksywmtxljzmdqlguhzyaxbfvndaojdsccpwabynswetbpnbbepbqhibojjmdehpvcjnegnmpruughozefefhtaxnvkedjkusrhdndzzmgznbvptvdeqktcjwtxegaxovntpikhqsfargnecprerpaqxshmxlxwmzyvdnicqyyozdbwnjrbkonbckuysdsyqhmcznuoakupxxkndhlsqcstvcvgvykopxboyayduigxzcrzuzaoyjnwgekmosuwjzlmxibiwqgbbkelesomwtdanblumzcwugbzmhgquvjwodvcwptrmahbzozkqlulyhrwsdrjtmoirtigbehjrqzdnxhlmmjbnkpuuoejqvzhvmsdxvajszdflqpqxsamrowgmbzflxmccnioywsbteexbaozpubgzvhpouhknxqyewtadmqvwcphwpinixpplzyjsldszrlfgwdyswjwahikbetrjdanzpqqbnlxpvfjuqmvizbzwjlzyastdtqvgcxxijocdtepxyzuavgkytrmjtgpabcpxlbwbljefeogegokoelqaxlclftludrgancudguluhngnacdyflbdkjithnaposvsrewnwffbsahidsmxeajcjfknihhzzlwfsfcflmbtkxmmiqdegokfiuweymlacmxbceitbuvqbdcdjagtyimovnuglhwfltvycznvwmaedpprnpagsahchgztklikxluikoaeiudcexrajgeucxmqhfakmfwjjzghowflmremunhyfxaftstwndlidegtzxlafqqyysfhxmyzjgmfjlqonblhtgntrbljkmisszvboikykvnmygijengzpkjfiyoodlfppetmvdddetkayqeultuvqsgllrfsrujfwbvevlqnhjzhzsufoclgqceyesyyszimdbzrcqcjvsfgrivgtzredvlhdgasocemzlizacvdquskjmvcnwilskrkttevwpvvqhnntoljwhwzgdiksnrcyphmxxmprbswuggpbwbuqqwxoqdyjjkmcstlvqymxpkbxhzquhwgsrjjvpzinnpdxusdpkqpelnxrabbxwypbznloinprxtbeeyxahhnoszyqpvkqhblqtckbucgodbdeizqlwehpanyvqtlmesufrhfbwzbdsngputgilafflvboovavlioefbqvabuxzagrtgrwkthznmzjkgkxlywlqrzbakoworxjwmgbafpnibolgraonbmlngjnvnbsvkgslqyxorqzkcpnjwocsolbgrvezwuspnwoisqlcpdqyjsluzbpaaqvvrjefrmrpszjydigmsabifhilhqcfltybqdhcfrpnqvaizuenruakzrjasxpktadsvajvfvwzssueeuxyijfhtppbhmxpdouyeggtnrpqwunfetivfxjqnnhbxlwzannfnemjywmpzjxhzeohsvxzcqqdahcccutlznsmqhiczlzgvjhemabvkrcrqvxcnwyqzkqqjlwvqbejvupsahqexoywpnvbygildgrjthevgqmfdsjzvgystfuthmmlmzpcrqcocskpzkfuoyqpfvtzmctokljuxwbcmvbsiadvbemabmpaamknguvfsmsfjlkktdcdcfifjuueqwbfzocgkuegidusnjvcqowpgktkjsbxxfzgmakzlmlsvdhmqjsunfbjsystbbvewsoleqlcvrvgngxwyxqrzpgibhiwounekpctonkkgmrouerswxkonyqgyfijptoyibqrarozrjjbdjcqguadbukpljalkmqvyuqlgwrrgwzkndrhupgkownotuqvauphbcobchepmvthagqndckogaexawbxawoxyqhyxzjkmjcyinfyohnfjbglqxrdoymbtzyvibangprtqyqkjiynecdjmwssqynbioviwqmwgtwdjcqpowpaotxtjmazuhbwzskubvkzbaiflpsjmyxwxyhjkrvetevdreghldikfazpufapwnxzlsbqmlvngxuclruxbwdmtfnkbsddopnkqiwbqrpjdkqjdnmovzveglrdokaussxvqodmjasdxuttetawioymxoequxlxlvghbiothckxigmlpplnhjjjtkxnekyockopilbvtxhjkuirqfeuanppvgywcnttpefvpbrxxgkszqnzpqtrlxecigvmmhzuwmdvskijxgztlpdyivieixgqkjcqrfvmkguywiutuffoacnjeuoiuwlljzemijxeuoqladnyjpjzxfyukfcumkpdueqvlhmfcuyikfzoopfdeawcoziqnrgpriwwkddrupilazesexxnomnxjfmmnljxnpdrymeankfhtabxrcqflwmvklhtkgsnvjxayjhboqqcqwqkzjfrzocdnmukdirkhbmveasalzpgbtgeegospmfkautlaatzhlppgsmowtsrocaikbtdcjrekdzhoevaerpnxumnivlnktozxtdgxkzfrmuogunklibhuqeacbjcuvszehbdkxyatmgmizbqmfpyrghmoafvizhmjnbnhtqcwpirmwsxjazrmn\n", "output": "4\n"}, {"input": "4960\nmcvlohrmletttgmbtkbzvotvsrmduybtnnmkurtflccynsgepxcnydjaeweebkasssbraqiqcwfodkocucgafyskdswnceettvdogzzxqgckgktbwjlnsictyryqmkxfniixurwtapbplnphzjutzxlbdbimenzvtqoltabbtzrqisgddgnctxbjzwxhepldvkjyyupmjovklsvzpmmuvdygavurndripcbepzommfpmdyvuwvaypjrbeppymykpmoobmbhtppvlplwbsnuffomfsavuhcqactbtqihiivynxraumeikkrdhduyjalfddqaqzrpjmmtgvzcjupyipwnuyeoqllrsfxabhqshutixmvvrquhakdzezenbnaiwkiieebfjmrrblgtdxgctycnuwbpkdksagycowptjcyvimqwhobvxhceylucghzsaqooelxohlzhulphjvzhnxmwmddbekuebwkjiwfcgaqbylbxuoaqruhbpboealqhnxklemvcqxdnavuufqaerifxyxysxsjayglskjekxodqdlgsimdmilwopeubvvnnyjiibvbdfgljkrskzmqfxghgzcoraglonwftqjcewefmtqyldsdradgmgxuiysszhvapbdbbaiotozihztbsjkwsyzjahsovnvmnjghaaoozsevetsqytuzcconlreblrxktpttixblbcpiutbqhpaotxkmwrvalqwoqluxizdbdyfpxefnphgkoxqgjvimwkygzblmygfqtinfhpgjjdzsrksrxtjrjvdtaqxeuxakchpvsgaatmzvrsorkywfapocncutbkcmakvrzfejjjooqpbbsnpbnsjhpngicixumxuhrjbmqqlbyxocyirxpqbbxflwlmvafonpipratltxvzrkrkvgmibkrwdjacirlickhhieopmprlnfcltxkshofemzwcuwgpxvsxzqndelcplmzjkippxibyxrphthddtoxepqxtvpzgfhcgpzxrdpsyxcvhmpzstuvlsyxxpsuzvtbuatkwynftetaycmfmftzqatlyistgfvtvzvtqlkheudeavceljtjtbyinpsnxwjxeeberyniludnxbcpiuedfhfwoihdnnrznspstghmsmyqjnndcpqmpcfvabgdzqiukmmbluemnlqqxiqwzynlnffmjfmolmqhqmxnjucsfoovhuyqftsudqfkvbmmafakkrgekoalrrirkfiwdbxbqlrzjtybaxlteqbuylxyfmwjbspxglsdvpldocfuxhqutdxnlxdvkgvzwjzdmrwvexccewacuyiqlwxclikwfpoclxnkndkjpblordjcihekenzvscfvsrlxhfbjmyexnfeliweysobicvlvwrpbbyouqjjpjvdwtaymsgsabzrvrteruhqtbcivvnsclcabtpadlfjgswmzxnnbgbmscxktzcvubndgnsuubbrtektgvyknshegkumvptgsxhghmlcmbaocbqikxfvllgrvhklfwyithjvhpvaoekcdymsvdktuiddgvxphvxlfcbbvutdqqdbxhxepwpozfycjgrikjnvwtbvtbxywzgescxernqvabfrlbhbeovwjmyxznfldntlieqyhkojwnjvxgvvcqrghzvgytcvaocpmwezcioaoromdskahwbrgfcyfvrdtyevzcfgysdqwhcolpdgmqquielzojubrtafwjndtrzbcvrgqcquezpjwldrvesramcpdljmvqslgsbpsmnbwgmknlvsvzrkiihkwgluwclyphkfxoxudxxqplzwtezmynxydlhtudeiusfcfhgqhwligsbmzhpntcsbhjcpweguasupwuymyiisnzgiodqzffppfgxcwnnrxyyjorvtjdglmllpwhiockfgveaqezlltaaacdzzevddawapnlhalewodrarzuqgxkcssdozamrmqaduuxygpgwaypeoywgxvgkcvlplowivgslzaigmtivyhsqydadnohujenfjqpzpmxbjfvvdmkjrofoflxukysbpxwgosmvplprlbovlrfwcgasvrufyfrsmeimtdtqemmjhvjswnarrybvhjtfahrznspogcjcdxjilczqkczyyphebnaijgblppjalvxohsyjbovtrxwjeutrmxtsrmhlejqprgzvgwqycjxgtisxryfhhifzmkndmmocvwxbvygfnuppntorzdhkcppphoxrtowrrekcygulwssghjaviaaobwjochqizjgajilhlwqhatjqmvwyynjprukdaadewmbkwigoljjxrtmwglxehgijvwouaxwralrffxzsnygltjrklvgteakejujymoydortjixkoxntmosnknqlyrcvznswzgrssntmucewkagsraczxmfdsdozglcqprtgmrhjupkieoasutnjusuyafbpzehsgcrukwxvlxvzzjywfqcvroeajdxihzssylrkofcvmtbjezainxiogglsorixdnxezawlbzrbsexabsacvbxaelrpakcbjwzqmynmaaowraijkcpnnonykudrxojteukhryqnvkjvjxggiqqdtmcpqbekkldasksmnqnjsuuohlzqomfumpmncgxzzrvspgdrkqayolyfbomoaouuhtbspjbzcklghflburggdbspeuraofglmgtvkflsyqnoguoapacbhzxclovcvcgfktjrxheemqcsovngrhufylvoymxpatkrjysmzbkocmlhssikeyhaknklnkjlhtwclfcyqoatbdweaaahbgohjezrtxpweutspncimxkvnccdrsbsigveqxcwaqykqmmfqdohoaiketrztqdxokoaxwuhthnrbypiehyvbnxcrkbmyeechyshjnsotyodyvycvqhgrakrzqmqxfqpftxrpzeodelrakclinuxisdlpnketlnrgtfyvhyhoudyicznkohjrsaaovpjnjqlqvmgnfahdmkmjwiplvowfoiflkavfypntwsbvbvwfyyxadctpsmaldyttohizbiuuapswacymdbawbzqzwubcyewupiwhzmkzhglvpmpekflfntvmaelpdjvfiqvwdkdlyvvhmroyzmbrvlgkeayvotiavuvfaivqgzeqrhnibhjhdafbtxqmtgfxncdecdkwmyairdfzijlkqblgpworfbxlhjrspakxzefkjndsicpuldhekbvgzvfrhxbdengjmfhotktjemermfrzgexjjklblmsvhkiggjidrpryxuwumsvfvcibqclgawtufpufxkrniepohwvqnyaxzypdjfgowxmkznfehxasjrqnmpjrxlyulqlzgtfbjzxjdbyefuywevruuqktwecmruujrisatfbivtdpusnpnkrarbcdoadxvxakexnwofdrcaxpoqxjhgeutaqtnnnuauqpuuzieddihnoypgendhgbhoemubcixrfyqztlwwswueeawqgndfuotcpzlzixwubzvxxkkhigtxzpqorsjmachwowaapbyqgtzbjydcngpcjgbpwzezdnkwdjyedxgijtwxqvwsuniuenrwtslshxzdqtqtkuouldrzvwfvckgcbjrxpbsocxyzelowfmwuseyukdojaknyqsdnwjtwmrbjbphkrjgjiksztkerzkpxpeevcypirulsirpbastsafrmzsfoqraxzdvxlqvojzxdacodaomjhahstytrcdvwpjilzzjbhartmthvgbdabwqrbaionjxwtmheexvvrfhjlofaejdisfahkbmdwverinfopssgixuocltkzloaxjfluftyxsebuepfghbyvgncgrqvsqwybhwujysqgaihvefbvoszihoxvizadgzheydcqbhuwvczlxnkbilxtbygvtrugxvxqcxbulviqufuebaudinxyrpszhypeomcarqvbzlrewissshmxsrdmgjllpxbwatlbceonkjflitpqummiozcqxttaoulqrkhtejonbjcnssrkdzvvaxxpbkrnvhfqrhwkgbywditawiecujpwtyavastifdodxdmhbywgykrjakwhrvyrejbyutadelfmanwnizqxfdjxjomcxhyeoshjyotnwdylefrweulsqbnoccsziprczfkmsagwogrurkvgdykkrmvgncwlsehqvjturulidyfqmpwkofrcdarvhhlulzvklxbhgzbvrphrmktxrhejvykfkoekfqbpjvdrnofhwphylljdggyqbgpmysnngnsgqfwsmmvydsjstugoaiqsknsrdbvpnfnfqwhaexhnhwomfcwfkxkhkgzixtdcsomyedhpligyyyrdwyqpusxafpvxstrngjfzvqkgehaieiqeaydkmbzlwwxzbzfmpxctkfspgmzcogfefxtspxciaefbsarzjginsnmrkqfgilhtsrccifpesbydlryryaszcdgzbcmqfehbucsvtvdmupfjlgbzkcwkczpdgoujwphxvchhqrseggpgflabhzvrzsifmoqaplfobztooxmeycpplhkwikuymktvfvvpeiawfdetiisxtrocyhandqjhppgwdibemuzpwfjhyrzaqgmqxlhnbcukuyvrrzufkuemidtevesrfvazghmxcjqoeqvrxrlhodjrncccrghmgpwzfcysgjfodhzauucdoovzcumeuaigunytqypiropkxluuhicspmzjezgrjuxwixpywiwgptypkpymgquimcxdravfxmfwmrwrcnloklysqebytnmjxfnthelwkgtsffnjiojhxuvjxmktbzswojmuvmhtovtvjizvjuqniscscznvrynjifxnscnmskrcgtkgdaayicrv\n", "output": "5\n"}, {"input": "4855\nvbhyowizgfhgnvzyaebvplxphvytgrbtrajzhhgiazrpypqxctdnvzdibvdjfhbypouzxwvxwgrgefwzmtkujgqixtxvpgowrvvxpsqwkexrexmwqzjjnqvjklpkntvzwfwrjzdrpfhdedmrpdqotvbxuhuopnvcygahlhzxytzjrdlgsbgyjscyxeyzsesukyduaftldyozdoopvzyjwjklbxvnfgjsjrbcogilgppgqnjdtiafjzugmzaqecuhmlusrgtdmbqmpmcnezmdmgwigcuqlupwopydvfpeiusllflbqmfswgjkcczomjfuaeljskopulaawlreimsbtbsiimniwwtbfymcqwfauqouqdlgfzbmjpdidwjtypfbbplzgdalhhqcenkndlanpkqivxqufuhtcuqvpnafsrjhdiifcouewzatuqsjrmuafwimxnnnnlnwvstocifkhiiusttckqvomnumamzlureaijqcffbcuawzdygmnyeloxqpnyivcxubpclaxiqqhlcffnozqqjuybxhyxsgswtszobmlxuvynnrtzlvmqljixnkaqrjyvjtzehwhyxkkacndxzobhxdcieiyiwgsgxqgabzdcabietjolloxsfhthvcirtlxpjczwzkeswwsdcfggodowabnslrsdergfigtuzdxgrvleaghjgcczktunxhbpshlrcumjuhadzrnporrydhxvpmulioqcgzqfhsvmrelidjkxcnarsholwvnjbdnkehuevnatpcvjxhlmaeypynxpsghpljaxtkmcgwvgwnzmaqbgnemylbtuvtftgeaegzyfknbgyzfztsnjuyeozhvnpvtujyeuzegkgrtigymjmflzjytfxetqacufigwzaavkmwjcmbgblzniiflvyelxuqxylbedxhqvjgzhfehrtwjjazaibajnbdojzrfdvlhhfcojqhcgfeaedgmjprurqnxxjolmttutgdlivdeclsjeggdkfubhpqvnjdfcnoqqofqxupspxusbinxasivpohlxcnghsacormzzdnkvnhujiddoqwuhmpflisfumrytdabthakwytvgvrzehpcsqupqjuhipyulxxvbbooqrwpkejaeqjsvysfinixzzyhunbrngnzohoqvgmmxsmejekknknizgzqckrpnsmsaqtmgfxjrlbzcpuppwhqhgrjeuhsmbszmkzppzaeepqtmkdzuuuhikfkyfbvncmudkjylbxyqbysczoamwvoewukmbmaeboyuyjjuskkjieekuzqwwswriacdohzfjacxhmywweqryahzqakzpafknhaywstpnywvuyibbagfzwhoocsdeyhmwsifexxtfnlqrxqpcsktksvnawdudubbjifakpjpjkdkcskoijjiklxefisvvqfpjbquplcernktyyrtvkinzkmormvpytqdxbdymreikdvtemfolproekjcerwawefcvaeyvuhvfezguqquzabpplgmlfsoqxsihaeammgoxeglegmfwvlompbuxnfufodzfpitbtkmoywirehxmrfguncdqaxoegraoraajunigfbxhdpwndfoyxatydwpyctqlrudlaboocxzfkpgkbrskgmathoymuhzyadgjpjykzevuzrlfeadwzpuvldlxavlyyeeynasxapznzpklfhaxqhpsmginhexthlazkktcfasxxgrjimriloldgzevwtydmgysmnoltvjnxdfddcorprfiprkfvukswgrhvaratzkwtcqpjmiiesjjuzctylfstwpiqiqfljzituiuiolwswifenusupgvemwynhgxulgxslfxcejyvxnhdbrhiqyedwdomvanihcuhvlgloecjryhhmgycgrdabdgiigqxsmtwuuvtdoycsnxhffcwhhtkmcfgyxocvspqunlykdbjupqnwcnbtzwktcyghbdqwptfnknrnauwrrxcnyfggoqkqetkhkacitffkahovblwspqdaogjlusamfkrfkvjjynuvdtsttygrpbauimqvpnhcwboqxpotyqempsxttyanknriodmiyqusydvevlmptpdwmxjvdogbwhppteuykbdkqjdgrvzifckewcwlfqtnxfnbplqwzuoxdugentezjzjcrpmgeehnzovwtagtrheybywixflwtfjjmflzyxcfucxheonlztyblvsfgegjxaotznycrwgyohywpkieydouvwbgdrywmyyshbfmlvhrmyycbojpmtmmznfpmqyqndtwclriyglceavolhimjerdcvymzwmoophdygzqawbclztymhekyaayxaiihctciokrhmvqqwxusbgeamxqordkeghstsjehlptpepkuswktryddtcyhpmrtjduxcqvjncpktznnotwqwqfenwuzqwtzpnkijyaesjlpueschujkjfdazxflymhnglrsjvrymzeeqjvpwnvqfjglsdsqqewzrfytjxpnobhgawbmbjyuzwpfjhnoqgcrgkxbcvweuhknpqsnkweeapbhdcwhbvxcozwmfzkpzgebxwahktnxeobqksqkpoqpdumqfnsdkbigsqjzwvxvqeygdnpuetgsdpomlezanihovmpkyrtqcqizmrudgmjgwbeizljcmluvbpqiqihacsnyzyknjypbwzpewoqqcgaiwhfhthejnskpvmevtmpvrbzxfkqpqcxbiwmoyjdrodvldfnoreuvenwiepxwewejyygjzwefxqftzwiclfpgfszbvdjrgubatvfnawfvalzjkgcfjhparvzgpqvwodxahfruusqmukztqprosuhrmoaoaoptlgczuhsvuoulsarwxrtcfrkoyomulxfzifkrhxyhsneomxqpwfbjepqszvwcjgwpekmypippcwmdnogoyykvgwjjxfthdpnfljjzyamaptblvodlemoduwatqtphkgeijbamqbjnekahwsdjuxnwiwyvhuoazsjetdfsqtzmnvndvlkdwaqayxjmqjzqyqfddfizqamuabwzvuqbgunjwphtofbxicppqyrjhakigfsyycwxzjrcbmjrsbmdsrtovkdgoqxsoqnayjwuihfiyzonwyilcnmaotbkhydsesbtedlubbttdvggckzzaaiydbhnihubltqjbnimjipflqnggkljnmtobwusmelztcsoqjblaampseyivuigjlkediyrcboukhlguwmakxjawymuqysfmxqbnwtbwqmchbqkujskocqopxpchnkggzkyhqesidtldttergoqhqxxvdfzrixphzkjkrowrvpfwlvhzzwzbxpomwxcdxxlfrarwjoxsterezzqvpwhsrfyxjmbxkdfnkgzuqyjjpepagjbrduukfzjorukdqnnthbwpaeeuapafejwjzfzvrbzpnhonwnooikryvqrgtgdbfnsupcvnmsthkcweuwufonvkvjsowzueteetygkltegznckxrfbqzwognwoopydtajsobputqdsfbzkelwpxzintzxdykioxigkdwrklfnpgixzeqvonrusnnhbryqsqacdzjlnwdkgnuhaalhaeqoywmsoiawaqkmzzjfrrnwyseorsdnauflhlrgenpxtchomlcgomrwnnxqlgpbqpixtuqijunyttwwszardklhtuptamwtmrpkbsydsiarmrprzubaszibbofegddebkutgsymdpnoxwufvzzxgppoimzemcnxupwjnaknnokruluudeyxwbcvwyptfrimhcwomwqyaacdqhrmekrqcslblfurptzdhcgghzifgtjpwsvdypjeuddgwbtxapydikhneszhfpfpuqghrrcpbghosgyefzfhoqtrqhirvemesimfebgtunbkvelajpxnymacuajzqsgjqtnzniuunsvsjdfvkwhlbtnvasvybdpirfkcfuqxqgsrrldqqejovptgjnzwkvmfeofrhzjkimryotxapdzbyqzxnpgjspdqbxbuxlecekgzwtlnbdqycyrhaupdnmlunnldfmzmalzybzghkkryjvjvqqzaxcrktezesoaikdfkisnhyiydtbzbddsioxnetkhwammohwtyctqsogqzlbodhepequhzhccczealvdzsdurqvifxfhpuvmiklofcmpqqpywmblvgpwltzpxajiqphniuoxwdufankvorsewhnqlkjvzsutisbvzvllxybkpguyvioqzzeyxmpcgpvwnisfvqxnefhjatcbhptjaziuxjriqiufvhfxkdquyjwfyulozjlhnyjsixaljuwnhhakebqkspamiahycvymtqydjljphpzuwxeplwvnadmsipawncitztawwwafajziloackghewesmrjruhmpgfdjvrcpbklnvlxexnlidyjplcouupnmbpezdhnzcgombvkwprnthdssnngsfeecfawbonafqohwwkzitccwjyxtsslkkqntnqrastvthibtvmsjpqlajcmeeyuqvxzzhuucflbrrbvvsogsngmvrtgjbevilwnlgvqtlqjyyyywocodzdbbcxkxjszzwxloinviqtxdehcymkeriabevpunwmfbgzfgjuxqhqlqswuoetiubvxiizzoxutwqponsbxtsusaauskgaluvwjvdgbizhhultkcutbtibhzleqqtdiwutuoncchcadfbnwbusafvfapnopxtpnncpmvftkaoiyzccxfkqdgvdrdedikombailbzb\n", "output": "5\n"}, {"input": "4810\nfjadfvinclgtwwzodcsllncoqxmnputunnjpgctkqhefdjkgrebiwfllugliqpmyzlrjaazjyrhyvgrlrdnhqcprmrmvgrjgbdolczpbhmwmvyuylshneejebrjkmpyqijlkoeljdttojxzgwcfguuljflkhgyxfchlnmdhtikdbzbkdrjmmsvkmadciifndxkiazfivtfqdqjejuzzxfdxxoacovcjzbbzhxfbjuviojwodxgankimhtikksgtaiwaiytaaynapumacbcpkdeljbnwklgnbqojwwtxdkbdldndkdtmtufvpzfbxvyctkorszyzrgzdqngxphoakczuodmxpmooreqvdzezwceoeguymthkzgrucpetmamevpchbzjvwtzcolxmwkggtoflviomazprgjrzefbvszathzvbrtkzxmltbvgxjfmhdsbsbwyuxaftblxjxyaovnemmeqhrujkwmufyxmrryzrukwjxzihzwffejvdbnvghhqakyoekfkxzbyfazegonqukruelkvjebxdwlbejhvxrjvilpddtdmuythushnzanbvyclxqtzamcykhfenygxyenjvkdxomjlfuqepklxzuoyzfpxdgovsvwtippnvayjhrwlxouskialjgsoxjkdwkepvxnkbhoinhwomqztgxbtsonsijlatxthzsqloafdkyzmqiqznrptszyuvnlkbvanrqtuwddgxogizrrctaugymbmmeahokuixwvimoczubnksmhkvhniayfgfaftykqzfijgdkoldhaecxrecyklmnfnapxavruowfuehpamlrqhaabzryawhalwcycapncwrxqqwpkszzpxzypncqmgwdhjqcqqfqehwagijshnfqjtkbpmdiopruuvemoyzpzzxtwdhmrvztmqqjupsggxzsrctlvmcywudhvyqfeoamsbvuruqvtjbuiesgazjvnsadnjkamlttbfguraqkccpkxcnaguatyxcdopojbskzwhzdcksdnwtybxetkbxfuiznphwpvmjypuimwwxuqrtptneynbrnkfnlrzhufcbybsgasefgwicmhobhpcwayumyhrigdkrrvtyzejccuynjnhduhwucrovrlljftkftjeivjszgcfwaclogrmzpnknypegfoqdmtponqvhooxcsbfekdrjmqauobbagthkpxpnlpichvdxsuipmkmiypzigoqsviifyajwauusyfyluzzycpqjibzegtmaswmgwvjzzoitxgqkutzpdigeimqsigqwioplogfhoduhigbsdxmrafbwsscxymudyipjeoeiptqampcnmppebhlyyvdmfpwwwenfecaqbupfwnwahxmmpbpmjllrqxihyqpnxkomzckqiltjwuvlwfdsoijgbdzuovsveadftbjzsczoavpjintibxxofuywbeqwpjwfdqiffwpkoedyuysdfsolgvzcqxlpqjwgsryjsvasabpldzxigfcuoivshlzcpuebihbjlaeegzxigosgkrzuvppurhwjbcvhipmgudhjvbmcwdghobksnqvnfpcvpzbnrdkggnekexfvwdhflhklwmlsxvyjavycihwfenidttavlblhmjuulqxvpfctynpxgmhqsttesgrsfpztrqayiukekmxlvdqhibkwmvdnerjwnxuigjobmzpkudysesywbgwwngzhoibxlirhlwajzduxdohlxrantbbmaxszijvkhxjmpcpffoimlmsgxwsqwovopcqjdlmtimvhdnghydgwsakhfpultwbyypxgljctjgckxztkoponkkjnzgrlrmqnqdqwgplkcbkuibrjhbgzmedrlezvuxkkbrudvrctlziqcokyyfaoiiklvizzijrpgjffjkcjfxgvtdatdhdcrvgzkochmuyuypdwetnzbcovkifnmtazjizirzjeuvwqxwzcgodwlkzialphwglxmxshbelnrqxkdcmmabjxufufqmsfubfnyfrokrtmocnozgksthoiuqxewsnxiofkzljmggwvfklhofdndsyijyjmassejqnahnhvuuivmolxeyodotlmmrwocqvwedtxhbhdqbdruuukheimbnwowpsezsndzvtkpzzdrzirqzzwvonpdkgwdzauwnljassyoabmmmpesxipgdxrigswfmjaxqrghafrnbcwfsjectpdsvxxmeddmienajamrtsfkupbuvdxvmxhxgshcduyafwiufrulwsdfcnecidgplvfelejdlerppqgowpdtxkwunuszftmqfdvsfnvxyvfamfhysnhkgikmpsfjtixwhzgdwikozqhxsxphkgmfyqdsaidadsjhyidfugjpffzwlbzahexqucqamuzupcabgpehmbgleylgkrpovmqhgvlvzzqhhngzvuaqcjsfikveaboqmcoutkrggfymzuzyytxexpvkaqkcdcjxcdkidrxbdrfvgoukvlpficxbxcnccrwxvnecobxexscrvudvvixetkerpcutnyxpnkgukrplcfivqjaivjwushgcczcqakennpjlldifunhxedefnlbrsgzgegaladorxdihlptbjvlbyaynteitoyamrlozcfqwzxhqrpaezzbwwlapgendofzvnooukpdzqjcgfobeqmmawiahcpcwqxxxekyqyopervwxjpljrdajtundlzsophuzrifoxdkuwbvhcqrimufjzssmfwktwagnjoinabdhzyjxbizjuhmyayhnoqocdeitirwfbrubhhyxkmnbjbiccqawgugkkxnsijpukeoqhcysiooqretghvinypdhmkujeynqowuwnuxujqnkyuforggxuzitnqbkjxjdwiilsnezbwybunfndpsqxonphbaltvfpequoahynmvzfhxwabozbgjlnghzxcmepwwwvrmpogoxyakktqppnjfyiapxltmqfdpfuakbwfvfnjtpwupohecyxdevdzupnwwoeqhzikdjmhqocqxjsowjwgkrbmvdklxicugbofrjayeiktmlvsklhypceujorzlloovsgwfumocdciwczmyqhduhpeomiasdhkmdfqzsolefyineawhnbpseqbgodakhlwkcaahewnglwiipkaoszxnppzfefgejkpknhasvckmstyvpqjxrlpnuzadnbjnewygflrzphbxcwpzqvqapesvurnkpjhqxvtpippgkwiyteuhbfsmzrzigbfnuoovqxegrhgycpmyyzpbycdgfcawstmhiivivdevvtigxrhpgzivvfzgsthnbgcqhrrrqfqobhbqrvfbkjkybmbycbpibbmbfuyzwpmzgszewbhxnrxzhqzlhzlciyzghyedicjnxfzkvlipgwvyfkqgqhvjcnxpxdsvprbhtwlhrrvcuxohpqrdwdldhbyxappxtmozyejiiqqzxcuwckowsoidhxbxcrzsuwzsewyfgbxablrudhfuevvwdhfjvoezjfbeekjjaxuxtsucqqdikgauvlejtdukulibeokpdmsimahvrpoychlhhoummivqigyyhyevduwukmxznesypldomzohclxjgwrssfwvwssurdewluxdarsszufoyaktypfsrkhtjshwgrhbhbzftdlnwovhyajxosoeyjuwhtwxaczsivuaadlretkzvkvagrzyidehytjsptlmugfamydlalxfaygnfecgomnsikgjfmgqvsfxudoymvfxzijgwqvnycqamwzuhefgmdktsunoeeqwgrehrmvcsdxswvhyiyomkyojttdruuykpyjsxaxrjnugtdzveuqvzkcwndmchbgfrxfijftjvcqukzdtiowkzbmcynamwozkfubolhxmkjogddswibizdtxdityhzqvsjkfqtokeqqepgsbeuzuogtwmlthnvnivgklqurhlxwjwqsovfycffjxyberxyzbzlaoxifoxvhkxmafqqmjpfymvrikyypnnqrzmybyihlnbsnyzffubtvyrxypevimmjrsndzzvuuyzggwfahuommpthdytpaoeecvfwvnqgybvpycdarxkcxzpwvkiwzepkzxcubxphzfjgsofalhnaxyklwqszixhsltwkcopcalhryrhqclaonutqfsviidakzziedtrrlboyheeyldjurvculqlvlmipczbduyfjyovkahajcuhptspdkjnzprcsngwwonydyiqczirklctekfhbmqsljxelphlrvwfxgjeigfdztbrpyjnxrzgzyacuawuepmengaiudrsmupxawnvifapqloztflhktspwlsgbrrawuyqqrnnpwqgpfmutwrznoqsnmqechxyqnetwmhmowgmozcjbxvxkjycqpcuzdcssdcoyomnlmkpzklartpjuexyfkotiuxpoewhxmecujibwsycsbalmbyoxzgishnsddluvfongvvvwfleltcuzifjszdzrmbdiimmmhlloqpqgacmarxriehfuxsbcjmyhqrcrganuhcqqcaankyqngqwxjbzmhqvwqqnnvulctalbzgjznwohcuatojxxswdskrlwamrxubkvkcukkfprgknmigdnocbeitacepaiuziizorcmxnxlrvblajrlfnyrpxouzapirtmcfkxtxzbufzzhuwildyghmebiashtwtjquabvmsgxkjuahppukffxyeikzr\n", "output": "5\n"}, {"input": "4780\nbvgncsnmfyrynsiecpxgqcmryyjswiohyvekmzyniblhaoctaberxrbiaiakcjfquhsotcbohjazzceeacqffillqfneajdcloloxkjyuibrsbdfachvourttngafggximguovxmuqnxyqbtwdhvekouavyerzcfsttcnvafkwylbxcxyqyabciktzgvkoaljioppaoiwqzexkojxaeyhkjnsbmxjrhrjsssmwyqcpmlgozwonlvcrqdyisslddarsoxaxoxbgtqmvnexdyjfsfqjzluubkjgmsskaisuxnvfenjdxbymjxnzavbsvbqmymsvdpndohdkmzzxodyywxogvcvwqovrkhcgbwalgprnimsnedemivusnyrouendlmoeadmyxarbvcmxjfuesvgdxrfxjcfyahqgwqamzgsgqbkngdhymfiedlmosqxylkrjpuezcxemqyikznnvmgsphzltsmrhzocxlgcxkvvylwkffywvzlifgsgkcneuyofbyazkjmidpalypxaombntzyjeuycusugxrzefuyqyjciytyzmziorqrfoopofdkyrortghsudhqvkzalpceclqqdwggvnnrgoqeepfqikwspwewftwyhuzdxmlewrcycfnzwjnwotrjqotohzuqfrbbpvqacghzcglrknbtazyaoauywfcpbwvvpovquugwdbukivvmvbtlbjdjocyuzxozqnosbxkgatyoshwrgldhzenjvdzpwnilnywhdsnitrzpzicfjizferjebuugigrkzsekiezuofmdcfnsqepxxvlsqbvsravpakwthvqbudvmzcvsizrdohxdwstffbuakelqzfofqebduguxcfmpnpuxwsgrklwbecfgsnvwcpnmchqdasiifdhraqgqiempgbocsusbuitparaohwhznzebivmqgxempvmakiprrgzvumgjtedihspuxrxfykwdgzrymzqgijtzfmdwugkiyjxuwudwdaxnnmtxxgskzfkbvxqjryutwerxnnyroeyzanrqeiomkvpfsyptxhyjvsbzdatvrcdaojlrzrepuasqjterustohkxsnmplooqpnbjawvtryoihvoinezfogkacpjmnpnonzgqeqnomahqmmmnyhruleazehhihzkyqocviamnncuiyqcdyxefyuokkxsomzbcqqfieayohdawhkairmeqjovtlsebakqsozmeccbregxgbzkyttjsveqtmpxtziizuqaxvjsxunzphvzpuilasznydmsanjnynilnekkzkulycskskhuqgmjjcshzucztqhjztzpnjakvqhvpurtqrxrvfgtvgtajlnjaqelelqfrrhrfctsbpjftdipoujewmrqnsibayillvfchonguuafadyxgsytcstiqjrevjyfdksurvnlhhifvxmjwfmsyoirxgygfrfyzwjlzyunqczuxcbedulbvufkmoalwpompcnrepbnuvxbcrwyrpbznywrejwmmgnwyiqqifeqnteowapxqemhqhxpmhbsihqopkdlfmczhvdwozlbbyztwytlepaxufoeitsmvyzsedyszydqljsbxxipqcmzqcsxwifhacnnmodatczuggoydckhpgjhdmksqhlfonfuzbbiemxockojldxkwtlcsgyfakfpykuqwezwjvngqagihbnjzrhmpnjsgmpjizleqpxnddidffqfvpmynoufhleabwrddaimnimwcgpcpkgnwczroqaqjpfensewsvzndshfcfodykzanykpkrnkljgianxblhapfyzvckgcdjaoixcjxiwdfjgmenqewbowzortduqvttkxxwenbwndzacdzobsadycilmdjditmjbffcyzkpjrojsebvjxjoyptckrkvsbszpqrzounffeboudrfpfbaitupmnleyegmbjlvpomllwexvdnwhmqbldnikycyhqtrpqvjlipqvjezngiobmyeuhrvkzknqzhsgmghtnbukalbjusyeznetlapjmakfaibggjsqhjxnmvzwufzpumgnsrrgkypntzsreoddkdkszonyplcqxfcqltthsqvidtgjokwlssmlhoudpwyzszqaihulcrzgceqodfvdlkzvjzvskyqxkleyoqahsmthvkdqcxbopdvzaswszyxbezvjqjxdyvjjvxdshpdswilzclvvvqhpkbkjjbdvfevwflykcexjxksdrbdnufnuzsraciafqwoxgwjxkgtstuwecmdbudpmrerasogujahwlmsixtufywjomebyraxrezgxxewdxmkyawcbtsapysibhodefwaujtefskymhwgxyzaiialjawkpdhubsndolqslzdhmxpyfalonaepbnzjcxadeonkvyqdtlufvdgmuseknvdudbevgwfwcclbhssqfuhqtdnisijdjksiyynbacsfllpldramqsiupkyajrxjmysoivculdzrlnsdupvyfqyfcrudqlooifdldgocvkdlaxndycevqnmtnswsjessbrypnskxeopjsrsodlrthwofoqejpwazwplomkewndlvljnsmesdxvsvhwihobbrbjurqipfczoqjoincrcblwzfochfolrptagkssvrcxyfjxqijjhfrvxsgyxztjjnabisuxsbowxqemqmjnrkcvulaoxbjrhqiosotcyvairmajcukvepshwieniogihbrxiskvhpkxubzvvvieaoxvfojihkzhgelhpsnotcfoybknkitufwzgvanvjhakddkayjmsnxausnirropjcdcefoottpinirtstukapitbkornudlyfhuvusbnqqfubkknxbemrxwvbwxyzmqujqexgahjswnifygduawuuvehpjhjxdqjvyakbxnjtioodtooswyddrmqiqqqlakfbpyguwnpucyfllkfspmmqnqqdgmyriywvobgvthkgjrdpmsddenvclandffvmwwqmfayvpltrlsyopagpyymzonkjvwftydlegnqnleqbcnxtydqymciphzopzqzwcyubeyvzthmpmromgmyrxbjtexzhmlwrnvjfiycttaqkjqqngwyrkppuvujfsbkwgwoaewrsfciapquxcxxzmxghjljebxfwriiqxahpwpozxfkrsnkuxdkuzbejcwwqzeawrvjcjbsethstndplfonxlvekcwomocwusxtzsqjowowrdvmhttyozupqzzrtemptgqztmcyjjrzcrcwokcwagequvizmsrvyjxfgvhvvqowrkojvgvtaxrctzsahxwsppxuaxydxrlraftrarlluwavowdeupzlujjntslzjibrbfrmpsilinkdmvzbxygthbuohaovsohxvnkqxxqupdnxfvfktkamthxqelehrwdflskblpveqbfykbarjfqgnedthqugsswhnqmsvpdhrbfurywsungjofobfnyybxforzcmtxmidtfhlujmcvlhmwbqqrtjpcwmcstfovxzmmaikvwgfbzqjcyiagddtvnhxjwpvepvyppmkscwulwfqdzpcswcfasrkfbxwtunbmcfzqjmrmxqffjushgevmacdzqfmqoplprvjddxrvndrybnjhtuolicftzcnzwxsvnhicfgieubpcjaeofkpxqctbjvfpysbqzmxvqdqjkrtftajjtfwazcnnbuzsfhypfeociafjarpacwmehhtiijhevjkucytnpnhkjertloxhfykfvoxpdwyridkfbrfwaslammgfruwqkfvvoyxgehzfdehxojduzqpesydkotncspqtjtpxvqcksweqgbjveprapesynadwfiwbcvzhpitsnjklxlsblvaxfzyjpekajoykgngqdfrenhntjncaplvapyjwizgtoltbpbdulhniwmhqamtmmkapwdheybyhefkexqqlocjfqbiaghsaysxigbihtycclxmlkunlpafspvuqdqyhlzwqbkarbeppqvhkenzywbkxfyjmcjqjnwykoghqyfizptzqzngfdytoooivpjkoueeeguoqoqprgmhagatqkbgctupcfwwtzbckjzvjmvmzqjbidodkidptuqyvdnsndfnlzzjqhifnquypiytaotbxwrgqbpposploziodxsbhwibvokowylrqqwwsdxqowiclnrcqtsrgyuqcorpgddvoybmwsojqeqmeabnefoozdyvggjveavpdsmoyyrihsdzybhvynhkiimllxyulhcyimyvqwnchvcrmgioymndcbexhrqowmxztlxiflayemonsbjfczesldpxdazkzhfkxyqjxqigzthlofbidsrlvksxfmnxnpclvrcwbyazjecnxzeoiphbfgzuazndrxifnfyqoedlqkjaabryhljbwodqyrnmxnktxzzkxvxqoogndhaeztajptqbdfafrwytkjcajtyaiemoaupgmrfvcyerlpkzewjwivslbidjlseyapvowxjzfkdqitpwilxwhizjgtylnpykoqvdmuuoyitquubmtzwdbgxeqmknmaoaqjzotrrzapoiidserkemabnvpkklbxpybrvnfskluhlniewrocbswvfbmcofrawejpanihrokdwxjminoafnimksasqwqynnctlfxjlgfdtalaasaodhsadkfmltctschrclzftilz\n", "output": "4\n"}, {"input": "4667\npfkykbwtylmbbeekilrpvtqseorahzzhcqlbfrqnwqwxgnoxxbateatnkgymepqtukafkgarlkyeomvqigtgaotcrwycbhfhtfvljsczwzuqrnocdbyjpyzvozlbzygsiguctzexphkpnfwzctzodwegochpvukfgexjptjxadldtobslpfthkbglxoetxyovybxjkkiqjkjzijkpozbpragrennhwybbdzwqahlqmxlchdgrvttcgvsrcqtsqmhzgijkqyakqeyitgdnrhnplesmwomnhunokkabuhinruvfqcmgomzmgyruqxccdfjolxhbxvcqvwqrptlrgtstwukxcdwxjunzkwdujdixcqzcuufewiudrstclzthwhcebhrawmksyqowqslfuhjhwkmfiqphuhzyahpgfcqhihksmzpbjbfbqbqjhpglddmnizaupbppkeukqvvcqdqzisctmojdwfyhivscnuwvvvctupgidvclbvszyxbwebvxqppxxdftfktfwyxpicaaelabigtxmsfwnzfctnzgmykurgwrearhyydeyqoqnknlximtjriaqurmwlrmrzrhbiqdmkxhsvwtarwowtqbzswxcqgzcsqozlxwjcttujdxvrgafnlwroxrnaycqonypxqbqxmpxkjkbiwswmpqvjvprbueeheuweojzpevkybipuweufmkxvbthzrojfsayfenycklxeeusqvvzkxsydmubbbacvmvjwqbcwvkmaschyohjxogmqwcskcuemasozgdcfplwrmwpnpmcvgclcplsgtavvchonzmynpgalwbizzrqenrndakkfczfxnmtpmeyljrkoamjlyjxzdkehrmpwqirdaslvlzhbvtiunpoagdebipgsxkyqenvmbtlaenekudttoahhvadzedyauqoxobiaiyfsuibexrylvihrvviatkuxgewvwxnomaunmoedsbhxycjnsraxwwbebuyptxiqbetsmcwbhigfsarxzoypnsbgznjodhxaubuwejmwjxckekucqjwuhtsvykcxsejdgkrqdlsypcywefadfsrekiufffrzoumkiolabscwzpgjjibkpzymsfhzuhcnjdpntrtandpwtlznptybdvywairkotgaxvpikrzoctuuobxcukalxlyvjrfcojjexupmetpzgshzzboyrwswejlgihhfebrzfsmyvfeavoysanxkvonlgxhrvxgeqjcocizejyldfggthwnatkgbhunuqvyoseeorajfhhcismsvvlkhaqohdjjwpebplprxovkfvevmyxwrxysjfdngqumkzedxiuunbamgwpdepiqxhvspveqnysagvfirbgdrphkvfzaqgzrhxvdqwfzwcnfkvbsrjedeaaebwujvwwubmbhvxjqicrwzasomdejmappuvqvflgbezlolkymqqqohrawtlargnzwevrkifeonorazjqwyhioeaghufopihjdopzusvuoqdslftckgytmitkldhxfmuzahdypvmmamvrlstphdfccnkuqfwkuhzosajnrlwxwxtmixzjbdhhwjmzcvphvusryccselvvcvnjpitcwkoyzzgevhuvddyokqluadyrhqhjjdyrpuguemkjxzkjmgurgrcosfcskualmipffrqapyplriqbukuxsbfgziljpjdxtogixbzidvvqvbghccseprjifpbhmccbogcklpqkqwcukiwjuidistctgmfbqtogfgpyjzdrkzabodpkzwjhcremzooekcrwfrbfbgewfdbnlznxmjepbaplbzaaigfyjebaavlzplrmtheupwuedbpgwddrocjvxpgcfitzodzrutuoadvhvmydkjawnycnpewoefjmjlrmohbabcfqrbxfkwmsqxwiqjpjfblecwizqwzjjahwgzbbstnnlwthxddrfqcotnypqxtylolidvykdqbxsfizmfijjymtfifhdkbwrqyomzkwszzjqosclxwnnddkbvxndvwjqehilswrrqwpkflmlcsrevkkpaaicdmapbeufukmqqwekpzaxfqaqgwseewuumdlcqfhvbffualnuzrntyibbxwrtakdzhvxfdxcjostoamsrrczinbwuaqvwtmzprewzibllujzucpxsikogambsosxvpqankeequrrflclalzbrwjpbwxlwqcrgahklwojosdvozaprcxdyfmlwskbgwbzizwgwtkxreffvpsmuhtpuxeuqzozcmswcchegflypiojpmiudtrdokrqffqpcjnhuuruhmatkhdciqahugagcqlwtqkirtlohavvrqhircnsszhzmyxtwyjfvrhhgcckhoxskogeiholoxdaanschsaukwpwvuedwwjpulpvcauhigjqwflrejtmswmjojithnxryxjpoqgkniqmccxnrhfmpvbjydtrjqgageducyciggxujzdiacxpvzdlcpiydphqlfzsokpktajproxomtkhooqlkhlwtwabjdgtgeaseyjgerlrwtoeyaehtkitjqspkuxibzvjahynuxalwvrvqfdgvrtxhbuqceafyauaowuazdrootencajhggvcquirzejfydxfirzorrqnljwiijuqlfpifggehvhotapkocikveffghvepvderhpcscaxfrsmnqztmuhwgkfqxcooiomtvufwijtbxuuxfqqrvgxyypjeqbzpxyvxrimezoupahpxxmyvowjexgbgsuarmldnrjfrhuphcapmkydxagdxwsjxgiwyidbgnxqsqjvcdoedhvyuvtpuksmnuvwdcqbeusglgvgfnatmualjfkwibwbaadejendxnbdwnjqfywoehnzutzlxruupjmyugywkekbwydzhcamboqvxnjwvdcpgowpybwvmxkeqhofegrdryutbqgrvdnxmzbyqmdsnnqwggvuigqdecalydynzwkbkasfftlmjvwnvicfwdvwwyuiuyelkphviyxsneyhvbuqxuzaqnqkhteqptdxlwmvqkzsgqavawpzucvgkwopsozlttnxedswvayadotdoivuzlnlrsaupbwlurgxhtuvqwkajwuolxyeretnwxqbcutyrfymvtekdxsmerrwpkyyprtsddcxswyuwrjhcddzcathedjzqydmoametbphchwqczpvbnlzghecmonomijfhzenrrgzqvwoqensfkocjahjddtspsfhhxfifktrtqktcbjchbeziswgvpbqkmfoafbljemlusngsdbuowpdgkxgcavbocmyvhgmhdserdrbwyyvdbtaxupobmuejbdjmwuiuvwxcsyojixxdffwxknsxsvuykmvdoqkviqmnptqswkmmvpwixnswxgtvjjxnzzykicmnbvhdqjzwxzdqgqtgaqssybzddblqgrchpylhfbyqpgkpbzcqsatuispzoucrspqzleypmfswktyjclthgcsqseiistjdpzughoorzhedsuaxufybfgeyqxniwiavfajtinnpuvikkgtwwiiudeamhvolaoxaowhycvqsugqvtzfsmcidrruplseioanzmjmtnojaizxsedgnmkghlqqugfhavmnilfyorfppeciuefrurqpmhhxrcqdtugtxhinyspbteetnwebninfmmryaxwmlvfeyfkviskdsxvohpjkxjjowvphkbqgyjalchbzmiqpqxxcknuklmshdwrdinmdwwnjmsybhkkgysxriejshiurrhfsglwetuidiemuahxdkekjlruphkziuvnyspllejjutjvmlaxsvrsashwlaipsvvospwrodhxcjrtdotarnbpiluyqdunknjrnalciiuxwsyvxhmdmbbsdlempcrxfkbqanmwwanecfgoonhvsexeubmkdlcvbsoaiptxkymiztkoufvikxawctgxyfbmqydwowvdziqxxnyliznqvhfjtfpqadglptembgdphurkctdgesuufjecnislivoqhtfwrudnkbnpotxytdybynbgvvdrldoocsrhfrkoysdlltitucdnfyhpvywitukyulvbdhcrxdcjdwkjftsoojdqsxmowquieqjmvwjendtdnnxbmqrlgknldmcptqnufosuerfljsezryptdaxtuvvcawkrtrganumjbfwjjejkoijwlwowwxoafuekmyzpaixbiciazmadmhhztmwsskuahbxtoykcnoqfjcqwifyyfzuwpvdkeknyjzyesmqlldmhhcwljeqfuxepothzzbdslgjjulspvadwflitugutscpdjcopgzkdndcdnrmwsxzgdbbuwkriijrxwwhemygmooutogkmtcbfmucfzjrnyagxdfurtzoxmqcbpjzrdimxyshatbarshsfuditrucvaciuchetqedwjfuwzpwpwgessxyohedchyceeihkqapuevcwmjlkpictovcatdeyiilhiamfmobmskqaxpbhmypkjcuqqmloujliycamfvkgpxwicihdfczjnyfbfkgtufhykaivjmcltfxfxhbefrkvqxpvyyydtouotxwf\n", "output": "4\n"}, {"input": "4679\ndyatluwtebsuemljqmksdomkyuytgbzssasbqijghdunrlxzuomdocamfxkdczheudbehofntlicymsysnbiplvqxeppbzijgbfadrnzrwnwwxxrasnvxdphfgwqzhbxuhsnhneepmwsmsieqrxqxvxbcobjzeyyptzphcbmwflyskflbazcdzpuypiivyjodqzwzkryjyiomqknksompnaldaustxhbgbedyvmegyipbcobxcyqosxtzwilkveiwceighdxvjuqkyszowfgphcrilynvkjzhrcufzqohvmdvvoxqcfvgmxxggcqsatrpglwfbjxzzdagyxuwnsurxspmrlumggcjibkwcrizstomdzlqwwvzxutqjdnhamflgumqfhehqyudikeizcprvekmayyxbxtifvbqsderlkknuovdpacptflvusnuzvtcdztitvuqgjsugvveqfspizcwstvmmaohaqspziinfhnyohvjkwgaaevbbnijyknhpnixppvvdluhalrgmxtpdzxwwnwwrywuuixbhutqjllqtrjkzcbcxubsrulpxdmogptedakmbrcamcsyvluyietuiorurziyfnxzwvqapmezpefoeforkcuadvsuxwgmsjphktvacjspofqodzhlgerjxctayxebyfarhnrttwoheajrhdljqwftftcqsdgfolxpngfmkiepmsvaecdioavcvnwdxuzkjawyogutvzlgwoxpyfjotzetybnldwsrgjfpsfssxrtbyuvonyhbugyfefvoeaxzvihocepmnhlcdypqzlicbeqbhthacjbljhrrekardiqrmaeaqavcrlgytyulsrbzfljyhhpgtlyxzxrascelwpudgxlrmifpfxhmsbrmaqzromckuajbghnbqaiplpfhnvhsxkdmqpmbyzmbnypzibwkwhpdnwewsxoluonlqaqvyzjgnjdcbcrtquspeewzcodnadtgvuckichbhotohnjameyqyozgjpvcuiegtmjjewtsnjmbcsgvnwoznknwrugtyxzzqqyqtxyojciewzyvmjqqvieqsvygscadmyivqlmqsnhmpqpldndodbwuelciralhhjxdxmzazzkihupbjmerjekauhqjharbpmpuerqgubghfesupfnpatiocdvlkkuawpjvmwyfrdtspzfadeocukfzfdkaymjjvfmlewxgbupypdujpcfexirksyfavvvwbqonixbdhrtngstwjcpzvqkrdnqzlyznuipuqdvqdcwcbdzsegrcccynsmpcxpmbongfpqkyzlxfuoxdlwhnmiddbfzrweriqzslsqiiezaauehzatmuwhlzrdhnmmhktmvudvlqvgfijocmakequetdvhejhggfhfzkuosyqucknaumhjbmnhdpuvoxosepgmzmqdqjqxkixcvlrangpowoszbhnjeyhbojgufgjzwkmczszcmlsetzxmuxrtjxwzmbaupvfkmzyjyngfiooecgwxtsnahwixrgqedsfnuclquuvswfzqfunkhjpxuggpylhwqwqgrbpkquucsqduqupzlrtpdkmuucydesscaqkxectgnznrgybvhmkwcycszwtilwtvvgcduektbtflicnzvgsmeefdbkcfpwwlgsmlnwoqirqvsythycvhwrewboakyjeuqysncxeyopqsfnlxegrjoyhkwukducxoeigmhasppqbimwoaxfwyaxuwmhcbzbdhyrljfvhjlcffddfftfwhbqmgvambegyuniyywxbjvvykofygaeswolgkglfrsuydrxfdcyontcemybsneknznlosdsugnnpnqqfibekkfwquhxunqbhlotqfnoxeaykibyyszctlqgktrxajsngzeujmryipxoxudygoolrizqvoinglfhpfpqodzcajmtwftkcpbkzrmijgewxrynyxdtbmzseswfmbwtfjeyxxiuyxxpforsucgcawozugcvsixnpungrhefqrgkgxshitujogtjiywykbjioxjtkrmupjzmkgywcwhbbeagzicgocureydnnjqhxyplthnhonkllpzweizpdsvllmlzugglvwudndzsrxenazjvnvoicgkwfwylewrijzsmtfgkptffoyjhcojkpatsfmwzmryeakpwbfayefpopcbzyhqxqexghermalbopmxvczfteelkknxkwtcdeqvlfyqvyyrnmhyarymbzwjdqvuimhwdinhxeziykmrylhjtcllyhbuxvldvqjawawxezycazkbfcjclnihlvanwpdcwzfkmahklyiqxwbhisoeqdkxeiymklbvakvflfbhxenwfbvtlyoauetfakhzkwspddgmnufsfjvqffuwlsbwfcvtjdvvogdhvyvlejbycjlpwqhfdtgsjzjwxezxzhqzfwamurdrvbzqkkgabqryaligwhwhswovhyewpupxbewxnzaemxjbtugaoddbfxxwactkauuhkkztplgfuypyurvhpdbsabrlvurqkipmndwuoaghjntzkomuabtiqblyexyantiuwdhoqvokulnbtoamhrgqwnmttgmjvzchhawkskhkydyhnmdqdskjgdnhvbhctocxjyaruhmlmvbpewvhpkcuucsxxmghuhqszqcmqnnqqswhoilrtbsyqrlfrcjysbqobgovzbutajbtfmymhloshoydbkbcfjealytouthdsazuchozrmltarakaaiowcxcibctvqbgrrnjxcvoigcjmnupcmaikpwexahrsklykorvbdamjylwlrsmwhwvrbblyjatozenfqjkovaernuvvfslputllsfgvlenyrgrzuyueldwcjcejpftqtekdxnzhcdeewxwwqfidbdgwmeyrowyaarleevqrsgonwqdgnkmvrvkwnkyipvzwoclknhqrcafrwdexkrvmesvmulolmjzhstyxvxkttyyoezvzxnjjoeujypkkxwmhwreotmeckduxwppumvwynlsbwixblsiuovcyhljnwguvllxdjtwffavkyxolmbwnfbbldxhcczblqbbifnjjcuhugjbwxjjtkettwyafdhyarmmjharbitppbcixjcmevaudnslzfrcjbbnbtqzxqxvhhqybphauqlrokcxdrdpjvuerksdiudkzxgyzkmmymxlcbquvbbcwfhhvpxibfevjmluohrnasukhftsqjilpvrwykmzwuycgpwcbxllbgwqgtbnkwakgtuwqjoihdrjhpgpjelueooewfwvrdgwfkuutygfacqjalojywjjxbelrvekgancxjdkpsreqayghihaumwnmejbfevlksqyjefpoehcsjjuwkxievaumxjiplfynzsfjemusuicmplpaxvrsbpwuawrwybhddqtkdtyczpsdsptscvnnkyskqbdkurfvxwwqlvkgkxrwwcgfbdxmbafcgxipfkhuihenckvglswbvalbnywnqapnqpumfipcdujmomvtoidkkroojrugcoqaglzmxdvjnzlwvgludeihraslpetymcdjtxbtujkefmvdycpbxndhvumwzhyxauzuynutcmpiyuvlfnsdrbtptmyusbhlerqoxmchpeejqxhamyuifmrvxrgrcljufqyfqxakqwqpmzqmgzfuilaszmvxehxgcxkpsgnwckteiqdzyqxxvlslhsfafczpnihgoyllghtccuoakcozsqvayxwggsjgayneqwraxnpbpfwjfiwetyyhrpcpqvynesidapzsoeqhemnknsylewjabrxocsppasxgtazbmikjxnbswawswmvuswjfniejezrmkmyfnbzgfbaailrhsdkcqkrpflxxizkdfzprkzrycrounpphekwemlrtstnrvcgtmqwilzcgwttapcixpljtkwqrlpcqqoyhohhsineckrarfmvxywzwhophqelnrtmeyddvuoguzqtcpvtcboabjjsxyjzuodbqgkzcspabwaqnotbeoebumsrkitrbchwtugjeakiusvyzstpdpwslwfnfavcinjnmhtvbqvtjevaehehhpswvbmohgcrkqrcrqhohfekajcuscyvgjrbxfctsxcfgoiulfkpjcavqtsvyipwcrqwjbqbgvcibcpcbwnyljammbslfoqbighsotopyhgctreonsgzuacoctceskpkqxycuugomoyqqkashozhnuhwqxruiujakqglbbnzzvtcbkhzkmzjeuaypekpwylozngmnsoljlcbktdwrahnfelfobtvjlpaqygvwxdgipfmgtxlgfdnphybxuqfzsvevimxsbcgwiuhkjwwzesqrllguikfvdomzytzckmulckusgzmlnnxdgllwjlbxjidraeduwumnlaeuanaewacnxfjmnvwrkicoldjnzkpreqazpnwfonfwlfcutodegflfcovjlkwxbuunwqkfwmltcomxsyqdfkndzoumoxhifpkgwgxdicngspujprcinsiagprixkazdihidwacqwhvkufitizkuwmzdisfwhbgfdalhkvztidnrtqvvlxzttzypiqjwgptvd\n", "output": "5\n"}, {"input": "4753\njufrsgzyxflwnxujkifqwhoyuybhpcexhzpwsmaoxmzviwfxbabkcycsqwikgqgsoqvmghakvdcrddtaeewaqcwuwlczjcgegcqzatuolguvkkllidsyapkfjhvuxgtovxjtjfrewxjbqqsufxhnrijcxosjcdrmnjkykvrhwszmutzvdkzguvwgymhpouikjvvzvlioxmynshcunuumrxvymnxbldddbuvhssvtxiuvmoveqdcjmbcrtgvlniywjmjkelvnsiyppqkymdupurmlloxfgmadmrrtjeiyepyugvsadlcbydxqzrtwvimwvazapvccwpymruudwxpbqqntndadsywceaudkrjgiytoqpmqomriiwacdhqgtwiigvtfedbdtlqaqlxvpuyohpyyaphzxhtqarapzjwwsnpljwdcbvccerxynkbddpowuznhcykfvjinpmqdblvbvgowcpeohjzzsozphacsmvkyiobbeexmgwrilgmjmugaqszkrlrlobcbwppdkybokexlhhepuogvpfdzgmplvnkrputpdwvquipyzfcavjmqqutiaydjxcbhqfriaeekgbjvlzpacoaytaqzrexvyhbziarvpxifwmhifzqjsiqmfthrfhtveeslbtbyrkhwlhnrgttjeohaonuniueubwvhdpqhjljteistpmugjjtuyvbthavzgjradnxqrsgyxmdvcycwsyvzlazoeruqdvbjxviyhtmuipcoarpmcqmgtcfsqyjirdqueugucjuraneexfolxzjhwprfrjtzzqdixlhixryhiwybrsstmhrorpnonublxtrtuqlpsbscswemdkoavprqueyossvhhpajdhngfqzestariwtzgmkysevteyzoepnmjiqlvtyrnchzqvgrayyeflgfnqofueewnqpcfytkinhbrfgmirnwpervgiziryzbjmotlhpbhpstbqfguyadnopefrobrghkfenvpzrnsbivoxvwhuuusdxqjmjykujzkvupowpbatfukcnevxjnpwbrapfcsgpimdizrobnutlffovxcndkcrxbqrdecbikpuwoaljlcypymiwcmnzyxougnylcwgminkyrpjczscphegdtnoxkwerunosovtjikhtwpgfstgowvwicpsgsugqamyazyrkjmztdbtaluxroetdwdnrggqfwxfvqhwgmqhkgdqejriikbahmnwsniwzcavovuexjrliyboaclybtyxyazofqxddpwashurxwnoxwsrwuymateqwiqptrfejaaurwtfqdygdyuneugpogakvldnhuoxlzqtzulakvtjtbmusuklwdgzpyutdewsguafpgazxvsvzcpqbvfowawiwlaobgnobwwvwfwwebmwhnkhyizdxyfgdkdguadcwmzlyylvjusumqeovtikaimugerxxadqbkkxdvutuccwxrwxnaboberrggnawhpqfejemkjfotgykrlbxzjkoitmeywfzconffnlkthjsfjaezhxjfsgixiemunflbiwlutizhxiggfttrypplkincafkrdveunlxdrnznpomilqpaplntceflkdphvneuveomlxoznfhiorcthpqyrrayzbgcyxngswpwxlobkdaqbdyacqdrzoqllqpqwqfsccswshnuiehwlnzbwjqowynhiekhkbimomfyjitvjqllpzoioieljjgrzzldugxpsyzjoqzehogqelvoxqajpxpofaprcjjwkxojubucscghevmmtuwmuftwddjazxoldifuesabguojtsagsqcwafzzkvuaqlqgyjhhumulmlzgwhmjdekjkwjcjfkvbhuupgqhuxidcwkqvccoxsrbrzhlblvotpcipcucmfmetxgjnwxdejemdwzpqbciaejwfacgngjroruphkzqmivfcdqntwjhejwgfwfseuwuniredegfgkdizprtidrlrgvpdhdtedlfomhvvwwnyvicxeglpqnxlhacjjoojyqgevdgqwdxvxeqwaaonlpfcxyhiavirbkotpddhfvhgxtqmnubhvrultautljmdkeuxontairwnlbisfacxqmdovuiqhatdamgczktprlpuyqfbmgbhywovfiouemnskewcclnxbxgeqprlvloojnxzgtadaclyyjxpvmkkwcxmfewgclublrrblqativjjsckityvekdsarokpqmycwylxmltwddbvvjnhptodhsmcofbnoyfudolqdmiapkgickpxvntxpwevahhuwbxlzazspmnpsflgxeexarcsmjuqskjaijwhmnkrntocfdkavuerwcohvnhtgcxqnjhjktpovsgjzfvkisdvbmshsacullkjxzcwaaoopmuqwifpmuflmzkosghqqohfoqosafruuskqotzzqnmyedfuhpgmvfueylsbtgxzxbaqqhfkxajzyalmtyneknhpjeuisexgkgzahalijnabkkissxbitwytxdisbsbcjsqjpsgjwrziucsdwafpdwavlqjoiafznhjsuunzxqvkygturifcrhwkvgchaymwibkhjrclvqxulwxlawyxbplvgypqsdmxzrcmxjthxwfqglrchifmmgrrbiiompswzkkpukhwvfvjpozsyzgahxokabmtwctugeshozraflmehhtsiwpduabqryhuhuakwfojnxdvtofxoayomewmfqqiltzdfvcyucplrimpibqakszgcwaswbgzocgyfbejxzamosmurfuleeqhlpyzgzfdfmcgktphivbmcwviicxzfsahevojiarujtjcddxaermbydsklmxrwjjytrdauukfhdwgjaskyrsfllmkpaainvzsabamfnyvuktwtpvpzvysxwdhffimwgabfmbpscjqvsdtgofzlkkipjfulofjffulhkijrxqwspdgkrqjuroudljpfoagrzvzvzhdorvweaxndfgdvcjujwiyikpdprayzsdeoihnujvuoeuxrdogwwtxnfsxdulaycvwhqthulgkyjlwavrpjozbopobgznzfmzdtctdebdmbpljcxeiyjvhmnmpkvykogaqivjfjdiizdcasjijdnmnfnkhfkstbajeiumxehrjngpstdertsoytvspcpqxyuelrjykzjjxxpedfyovdxctpqbquwxzyvftiwzpkmsyitaxqayxvbicohudarypkiatbrvobhehhsmzpjtttksdtutjfpxtizkwrbupfunfmswsdleliehsbvjoqzysxtcconejzuhonkyxsezwdwcwhneychrcbcebubermuowrinlyssbcjnwktigvizumetwjiobesbjdhsxgemotfuasvdaeulvukalbjhztiyvdyfwxxmkdqsfgvdtzhfavvffeuqswxmepzeyrjqjnzyeymiyyouotwavbddfdhotecuqqmwffpstylzlaagebjnbkiqmpykewmqozhpodywufqyecnrxhcvremdhbuedjnwgfmyeggdxoxldazdfojhymelzvrtvnvifiehdtgizvvxzxqiuwrfjssfpnlibkyhyesuigrpjmzbjnkehhzekghwrbtflokxpssyvhbdrollienwcpljboeexgxapspdxcwazvccketticiwcoyinpjhizewupegcfvoctlshuumzhtoyoqphgesrhrnnvhfcssmsnhcetnrgdqnmqzorppliccpoafnbffjytutfzakhhgwciesbtzpbohulrhppcyarcibveagpxepjekegplqlwwyperuskibwfccknrjrpkdwpuglvnbjgmrtmpmriiuhqlbervxruwtncyrqpubxtomzgmzggsmiabrdcfwzhjckfkizsztdqyvmgngheaipnsmtcoktmydehqllooiwvnniagmfzditxnwulsdmstvhxxqzxtbvwglldvjzwbkzphvbjzuzjxkrhmtlpimyctpgaatblrdrmojieabffuhgtzbbyosjxidslgbioaqqmuuqlwaagycyhnboeqsdtwufuiosujttziyrwnwyqaalianiimylofblehkbuzmloceppbiyjbzubgcestirchsuxddmqvarmxvgflamyofaannjrgrpryrogyiqoqqohyjwbeilxgrxqzalpvvooivbwjletewclnlhjjzmaayjlatomcoblxkwkonbatemjgtcdzqbcfdddjemkheolasrxsnclsjuginnyxpcejelgiytzdxxbthiqinmsiypoycbrmxlgjjuafatlttxfvdeewrzafrhbgniqyqfbhaxzbuqprbjjpcsvomuuhqgkwiwskcjpzmkcpvpjqjludjefhztgnmcmnrfpqlmgqoxhjgxiesvknbszlymybcvhgrrlgxcergfxqlihbtcplaxrizclsghvhpwjnwvhmlzsciicncjtacgkylcobuhluxbsozwvitfctrynibqmlebzbfuxcdhyyjkinmntzsjlpbpyqcfmsugsxpzktgtygoshkjbrdyslinlaykvgyfepdlzanzwxmjdbwlsnzrsgohywykpkgiejygeyjijhegfkkxbsaffdscpsjtfdqbmrogeezagqdqcgspvvkvnqcxdvtvliespzxydytwsmmtiysqbupfsuomc\n", "output": "4\n"}, {"input": "4795\nrtqltsrhrgoszrbrmnymutrobjlszazxovxkgvhddjeaywjmwqdblysydscsereykoftfpebxuzcqyaxfbgufkpfxfcsiruyqoubovmxkxoypeijqswcqcgvypuvvbsxgxuqrjhwcbtnosppdszqyiekdauehrshexlqjdthjaawhekveezcjechwyjbgqcdczqgsoqsoucvadojmqegoxgwdpwqosoyppodaylyivytqqpjaignfqeyendkjpxkwqtanlthwlcacdpcejffulaseikaefitkjpsbjuvfkciuiorjoufyctaatxyhinmxuvqckkbsnzhiucovxdkiosgggdwnibgtnxhlwusgjaxhytkifwhqqzrfbvfyatxzaobxsbrlohgkukurwijfwbfqlxocexdlelxoypvpoozludgrkwtttcpnherhpxniggjwngffmokyjessocncrikoxtknbcqpwzxmknmmtidieyemxtunyuptkesooowkjveqbomubcxovazvttxbllfrgpkrqfhrkybdayevuihgieezykujfmnztiysbfqypmwyumiaznbmwybqdhprjjorvgggnowemflhhoseummvejhrflbrwkscqcvgrkbawjrmgmjfihheaihuuichzrzwioaofgnlnwtiexclaiarqztjmkocpfqjmhnyjuvvphvmmshriovmlefzcfdratxfioqkgtswkvwcxbhqqkgmssnnhxpqzjnaktehxymleyyegkwitsyulakrhuwigcxmjkbawtzylodlksiveqmcmuttgrfbbmbeivoluqcossknjehujfasckiiyqqrzppkpfubqekkreuftodkqixzcfetlbkhldixhdbfgnnyltfcleirintkagusfbyufuhbvmnfshbueejjdftdtomtadegqdqxwmocmagbiadvdpdxmamduckwdpirrlkwagzibnqpjoybduobvtdywmlkswfplwzhbkhlrobsgzcqvkfmegnuqyhgbsbzeszweoabkfdztqrisrxwdyltlshmmcecnpqcqbcjfjdlhlmzhtpplppsuzdzkdeaygmqnidrecmibpwhgssgungbckwtirxprcdgzdhvqauixrddywobquanfnaiwepeltbkgjqszfdejzdtkjwnjmblnglpmnvotrfrejbhzrsqprvmgocbpjanjswjfnpijmzcdfpmpympapyheyufgyujmaqqmgwdpwubypagibnxhsqanzlzpikmyoqqzqeaillvjxusxufaejzbrvquefzrfawigjtgtualmccukobqqiczolvbctaoudolerrfefposvcapbkpkmocwjgokxadrmqvocimhghhoijgcjqxsatgfwgpwctbjnjgcpqrpecnucqxsurreqzrbnstmgmbroqxaykuhaaiixbeyagdsqohrsmprpfnzurrdveyxmjjfhyzgffehhwujluhiucphedycnzirxbgqucfzulvuprbknvthxasiysidfrcsbqnzmqbjntwnkdkuuakivmdlesaufactwvdnzancrbhhyvkeonejhoiitrvcxirulgneyirvwzsvtwwfnhhtnfppybtoulakdqzgnadfcwsvheoirkrxzpjjvkoejtbfpcueclgxfhwdtxioiuuuyavbwpvqurzhysyjugzbxsixrgfkvwgmpinniuvddnulzcvoygyzkxlyieywhhqvmfjxywqhloikhbvckvixdxgttzzxivzsnjwkgdknhtuyijaifzhwmdzuglikowfhxfdyyjzibafzrukrtlxfmzcgppdxmosvrjobnqhcfxgmsymjyfawnhdrpenkynfrdbvbmqwziiaqfdyteqsknwtbsobuftghdansdnqqvumhbvchjdhzwbxeksalutyhsxxixacuugrlzfjhhesjeqzozcilhbowjmzmubddsibvvpewnxfhxvablqngelgwayrduopbttluagdvnjlumtbyyfawsustzvaleitfdmfisldealwdvjivdqrldtrbvhzevylovzjznkekgrikbdpduxvueigskxizpkziigixilsbvxzzetfkskpfsrtupejbynydqhzyinfvwqdwyouqqqrdkfcklbxgzqvopvuomijnwagmtggzysjcxbwpbpsgvbwmifftpkemomnkdkvlkqjoabdxmdvscylnwhxeyzhsuhaqyndamycdstxctozcctbzqcbscdsrccnnrvknhhhvfeyvlkwrcrfgjhhzjuhvyghbeaduqwhwfpmqmqscxdheimsccvhatqbawvyumpctrmjkawcfprrrenmrbcfashhsddwzlgiwtmiumwxsomwrlifiagjqjhwdrnhjfsaeabeetnmktknxsqieauoiruhxgujqfkmyndfqfmyypjisjikguqauslkjwzqqtytmetvjexauybboqwleukrvykzdznutaycivohfxntogcvlcnxsnxdyvegleybgmtbyjgxmpubvkmfqqomlbhennqeivcgnxuyzefoaymavnqdisxicgcquisghrglzhfqerxzjmhtjlwhvearblieirwcwuhdueelejamlkvlyucyrhfgwlpmkajzywhdagutzrabxywemdlzjgrpuvfokjkanhwvlqystagxnfpurlqycvjimirxbvtjrfrhhyiwnjqfwyoyvmldqceeibfkjrggucdlczafvvqjfrzlmchpnwmeizuhqzmrujuuberquovzqwjdeivhuypqzmbhxmtnlcoxarajweccjmtydxtboakmqdykdzxpmccesqjjpwrmxsjxihfjvlxbpgbmxxoxvzwczooplwekaeidokfcbljianryutgyyjnmvxwnqvslrymonhqdnggxcfupnoxsqgsgalgpyuiqhvhgndfeofebwvykdwofycvokcsqmrwmdksidumzufvucbpzqawtobknvoqmmaoekrirhwovpixmdknmxyzwfwcdejbflqzvjcarouhraseqjyonyjzwvvkwpyghavczzqxyfrvpmiftgbdbfzheglicmlnkxebguzqferyidtshfaardkdaokarspcakwjtceuntyishxambogxhvwpjspnanuixiynasdcxnpbzstwyoyirzrjtxuvgpqedbikssqkhtgmuxppmpiqepcatnrbpdelvekgvlnmrshyclijcmmdsrjursqmcxoigohaeckafumdxdwrjmbifzvjhheqdebjobxuxqebaaktqwnrvrdgufhfyaapsbesdnyhineslxedifspmameygfrzcenbddeqvvowfujovyozbbydtgytnrvivmudmipvfhplnjersdwhunbrwnaninbehpkpyyyxydgxqzqjxmzrtkqvatiyikehekyhqgokpwuoccmwlpieuitmubzaptjxmbaoawwgufaunucdwkykvhflorabrjqcncndrqxbtbylkncjqpjzpfftlubwssqukkaoxngrjeiuwbjdetfihyrqvhydysavrhxrfiqqibtvdfkglnjmrxolyuggbekmzauyubfbpezfrdlpdxkpnesgjlmkkaaxcwjchuzsbhcdtjsfasolwkpnvxwsxjikcrfyhcjgttytvwkkfsnvdsqrzklegodevjjkfevkcdxfwtimnpxaigirpqqgkveqvzdbpcssjnjmbooukbioxkfttdepqutsyoccalzsvnrboigrqkixbszltfmmqorbxtzpxjogicuuhpzxiydaxxluuoplbiviepuqwwxtapanxtyqjssmvooxxvpduieuapllnxsqaixgtlfpjuifwpbweydmhslavefxtdaicyiirmgkcdhfufgdzalimnbbbsulaogfrbrmxvcgbvrlzrphvszknvkpivqdyyvbszjhqxaolwrwgzszpouznvzzgofcjopbhprnbdqcwloukjejvkjsdmclfchfzladcwfyueugcbcdlhepymuedpyaspwuwrlgkinndunnczqaryyemjcogptmtnldhsqqkngyzgowtjmxzxatrgpzyjzznlggyvyhqermcsdxdzoxuuvuyoljrygocyiecjgteuqolkqagbzhkkelezstocsygexcguqweglixpiazqmvrwtvqjkrcpncvzrkeougxllmaeqwtrxzjiivcnjjkwkyliwhqansguudqzgcoiuwegqrwrsogrdwykofqdnegqbtptwcuaofkgmkqwjvkhjirdbefzqhjbrplcvbwqcsjlqepfecynexqpcouocuzkfgeqhnvfkzsqpnwgiodlwywnznknthzvgtmzngdwufgvrybxmpohiprxjffntkjspzofeccwttxnkwmgcjhqxxpcrbvmnfoodjtscvjrozidlxcmnlzfaaipttdyrlxwowxbhzjidddjvzoszmakngcirstairyieskmkrwdwogvxponagoxqwjnxgilhofgivdrgywjcrwwakrrirtjlbmjevtfayvjpmzxrakoiuqwhaxypbjszkbjjxsqvttgtzejnlxikbmnffqtzcoknzvnaczhtmtzcbcpoktbknohushkbabtfkwjkmkruzfwlxomcnibnzlidwjafkaryhaewoikarhwudcmtthqibekcijizydwrhhrkgoijocwsrbphbnzjltcxxxiamnhatr\n", "output": "5\n"}, {"input": "4769\nolqskmcxpmkscyglsxczfxdzzsdsfzpizrjkibqwfuncxwjhuvgsehkyonvdiytzxivkbaqsgstoqgdvjifmviyaqcfwijcogisndwrtnnnyvsmlkxgritqmvkfqjkjslwzukscmcnzevjysbsedewysmzpvlmziycznqamizeglrjtlazdccxrbwdozbrugmvcakidhdjryrixgunjoymorskpxhlamqoacangnnhwtjjfgavxdlejkaawrygmdcrhhdcpzjmfjgrdzkdjihgokuvbuiyxlgotnqvigjoympiqnioyxkkoryybwdnotomkijmeusakmooytpmritbyfjxqznaiczwfmaagpurogduniqniqjruxyxrbyvyzukmpgeqaizorfxtgtmtsjqqbrmpgqjdzmudweuhwvortbhyhkiechisstgfgotdtpsnmaqjjwjvkhgizymutnjbyunikonaqjjdrurudsdivbgwemyerrpgzchhipjvsvsnfebqnacmtoryoaijgsfixrqppdcvdputrxajyvshsxtjyaszddrjordcuaoeuapgbionwlqlcshtwvvkhmltokeqbdlwzmbhwixzdgjzodjisqmjxjynyhkamvdkxrhejxhfcldtfvrgzxrqpzpxoknppjihrjjxmdbxbrkhbzcxqawitfymnlznvvqnvmkztnaazixsufdhtwkyvbobhfsolxsovcvdpzcxburxpvsbacuiuglmsrmjzvohlwuhrsnypuoizoxvwaounahvlbbbswbxwormfjqifcsyyrzcephmcbmbpaaefpksbnlyhwezknuywujtwdvbgiozjapsuajrlaplgnxdlyzqtxbwlayqbudrvfzqbwukunhcwxnneflmpjtzntdcjtqrjxchykfxiydgourmhsiiazemgxhllzpebmefayxbmvsxjgjblghvofvsjeldqgiyqqzsigrrsfqrwdudhqdwkxqijcbxxgsgryzjcetlvlbqgjjploqzxijqkejlcpalokastpczaqbcucyalumbfvrvwdvozuqisyroqczgtumdjrliupswgcjsjhcpgnfagvqczdshgheuralepglklvhpfydyaggoiaqssvxcaisxyuhuslzrzdksyvqfoepzyrtcydptzjiezanylsqvajkvpnnuscgluvdjttcbbhnmjmhhjgvgpfhlwwfglexklsgcdbulyeiqwowwtltfkzmbpixapodvugatohjzgkdwwnvbpluynkalxrpjqpxczxhasynjpfemaisnxewgrbryhpwfzixifzekndqqshuzyrdsaaqtfghfhswelryagktwiuxlpgewdybetfbzpzxojwfvhfsicbhmleawhhirmbpzcmjhpnwjeqlesoxyvcecjikhvoqejznldkyiqvrmfpistgjvflktuuubhqnsmlrmfdvfbnlqohgqjaigqllkeeirlgvoiuotxhreypzekfoagfqnxthjvoabyymygyaefzylpewfnnyqpcmykpewzjzvgyypqvmlhscirtcnxfoieduoeydieybgnelpccbnkiqujymensxtreulbamifpyhlvzwlbivftrqvpyrehyuzhnzbnmowlgcscdlznavusrobhqqmebntrqwyltoarhbujrzcvyshpgzaezmvxwzbxdiisvfellpejuwktpuvfzvpngbtjwvgxnxbuuvmhpfchzklhnzoxlqitbzctcrsxqymusfatlbrtgsdesktjgyxyaqancbtwcexglmmmmvkvntfsbqvzclxgukabfmjzfhsgmrhpzsjqhmuidyueifhosnaopakqbjonhfyoqbiorasdyvcbnffpiwexagiksfewvnpqtacllkpaecukvdndmvnievovxbcleabfobffpxcmmojtscyuzlevdictgsznywxjabyukzzmvdbxdapvuotxhqmjgdgjxrnombycydptdawcbbqvhiudjkrsdqjwrsdwxvogdddzkpuxebvytpuxxuqcjpqtcourtxhoxnlshubfgkliazsyfbzlznjtjdyqaayfmebnoarrquvucgwiimrnmffkgrrjlfwmafweewoulcvdkrebbfqqpbfdedrlwinjcubuqapbjckyhstowesemzrafomcsxzignggozpniyumdqgexidchxcwdoueplrfhlfogjcyvhfcajtxbrzomsjlgbmtcrbrsfzmbmwmzymtvxrxfykaazmlmekdkjibtnsbmbmskbmdvqmhtczrenhbhojgmhrnuszvxvlxaxbcgwmqcciqiawwkjzntmeakwtwidtfadpvcjimcpfjhykbtbekwdntgfxskvckjjzhmezvtkdsjomijxyufgcgywslcvffbfuchdywdnvucgmfytfdvxajwehxejpoyfkmwbwayjtcgltqyqrlhjspxdrvqcyqpovayxyxwhcopcvetltyhhtqlrmbtvqandotezjbmfqjdtsejgtsnpfcabgyviiigqcpfhbuizbrtyuqsvitkgufaashfwhwswdcdbrgwszkbyhblrpskirpvnwecnvxytpfnuhnnwujbidpchgvttmuvxdfzliwrpztrrldcrozkgryubbblckrnlirhhlzviusbcivbdyzdktlzdowuaoaxsdnrmvmiaiasorsigqbilwjvcykejaeawcpsywsrxfgfaeausqzofyrofurmfiepqibclikriwtgojqqarpoxjpaoirsxxcyoghpfisktaptafsgsgmnqnljfjyhwhkvaycqyiowqcmjetebdhpsfejqvevyceqtpqlgupxscdrbnnddsdqelqeplzidvcnbudxhmatpesjxemgarijpdixvtovgmtcfvsqlkdctwskxpchgacvocgwsrjdjwnhtsrapgiagfjuolhsjwutjookekjrjzfbgqcempkphuhwrlkutlzndlzvjphpdtlvuywiiwmlzxpvgjccvfoygskzviomchqbpifdnrapkkghsbaetadqqzxzytsngupnjwzmkjswwzmundzyjgqxifjertrqjmiechsjpyryevwltyydibhyxhlbysmtovxskaekdwatdpavbniohopgezdwabvifcjdstlituzynlcoyqblcppfhrnbvdxejokxflijdzogsuxigwwyonzhoadotguuphsilqmlncmrnwkwhqtqdjegbrgqqycelnxgiqhcafsjxnrzmiugvjosjynmmpljlrzyrcvujoejmnajymosbppfbdeejltgfyiiuzdjujcviysqrncokeuglxsdoeeteenrkfvyxptwiywdfdctumobeuyxtqparzaseeonnluxvwclygsutfqowqfupiilmauvuqjjdjnynyqeuyflntqefjoggjkteigeojmthailkifepxutcuswrhetsvizobcdjvxfnyuvhtyinvdkqsmukahhfigtermrbfjzejclfanlxbryyifsabmdvbekehrxcxpceistqhalufowiocxgxvdqhedtmfzybzreyihgrqqckapuxhsiizjjmnmhunulcfylrnuajsleigtfwhtwuosqqsbqtsfjlyvnxwejlupavtaovalhksbemtmuybwrswsewjahdaqophjncyqwmfadzlulmvtodakqsalkrbmvmqhvmoeddxwrdhmhzpjobbwfzqnbawciciauldgvwgriajetjzuzdepngkipfblxgfisjaplttheddjzneimjabohkmegapquvemiykvgeencfgkozvppmevukxiucewbzvtkifrwuquocjjyefloflnghfupihantctjjyzcbbnkzgelbmnzviokrmrbeoukhmssfzsipmrczfnxpbhyeoyqppdawoyawcmtlvzipdaukbecvuxyjmybopeepqlzzbfvxnmuimghcnycjoepiavheudbckqfehbjzzorxgvsclenfugngaxqvatilylrtftjqrvgkeffyubinqtnqbcbgounrfvnzrrdvklwhkugdgzkiybqmjbdykohgqgodztgefddmzxybhqrryagerclvbeketaehgsagkshupoyqldrrzybdywzlwpycaubmxnlnejhwqwgmcihsoytmxqzwvxafmdpagutzvivewnetkausbhwfbybkcuhvuzmlpckmldcpreblymsuddsmlkchitaeequonzwsxmlstyqnkgnahkaaitnxmdphotuizlupgsgzjilffmgrxzmyayslkuipzxcbnnyswarqfvyaxgkghokaprgsmixiogbpnidrzgdntuaqcdhtyqhaiyzazodyjwgwegicrxnfqjgykecgkseorgjzahbmcvhotfxoctvbpjgxffddtsbfvytotlhzelqtsnmcmwhvujmahlshpceqpsumekwfgktkjoseucicinfylhypqxucxkwhazoemrtrhmddebyevjjknpcmynenvvzhzdzrcszolirzmxypdrhmkhaeseoxqcjnkcvfbpdwxkailrhbsqeveyapigcpclagyagcezsqdwssuxcscfqsvwryvllkxkmwoomcvhnwsnbtnpuinuddztilgnsmpiypztiqmnecpiojiskwuyhaqvrptpvhmbkugdafiffzipnxsrlclkmlsuihw\n", "output": "5\n"}, {"input": "5000\nwzyqsmegangagosqlhjeunvymwxwaufduklqaxfjxlucxsfrytluwubykthwogjldenyssvzjqgsygdpuhkhcrseoujfgcqjqmpjtltpmsvjrysjuprhmkmmhcqpbokrllzywrqwehlytbsqjcwsumvzcbjiavbkvxffiwayazszheycjgwlksnurbuszqnvhucapstljlvkzbhdglpnropyrpppczcqbjtshiaqrvnsfyhgyltrigrkrczpeaopnduirvttojcgalesdggzjzypdckhdisngdhssuxbtkhgzrtvjoevzowfhtwjdyscycvuujrhllsgujnzfslxupjpjaraacfowvcuhcnhmypvkhdjjiogceqncctmiaylhrklirdhoqxcfcqydrjjpggqfxwntdrpgyvexfuuygtpzzfpmymujlyuelzfiousohfeztjnvgdafapfjvanavelipystnwvycyfvzyqhwpemtsxmgsltcsqgzucvabuxnrnvqzzoqikmlbiomopyaqaquxifedghxnnvunxfrrarmyohdhbbvnccbpibmmsgjyrorddvkssmwtuvhfelyeiiyucvkgmlpgmpipnebdvsfvgnwwynklqfpkrtuximvujqevhchpymzlyagvnllrewnbgyzugggwgdveaksndtuzptlxcwzxpzbwxhuzlyflrfphsvezgszfatmteobjapvrnvpjekwwztiejflxosukljvjhnpdtjdlzcujloizmpozjadimjynscjjjfkxrtknzqcdtdfcyplnmlqjcsfaoobzsolwirtzfmsrfvvajmolgzvespviysnaigybqfuftwemrfxoprbnugcjnmkfmcxpnojqiijdmxurzmqyiiuhxsvrwguvayxqugxitxncpzjqulgwdjqilsfnhmdjjvuipxadkeflqaodyfplsxopwhzzamwaesdrorfblqjogubsddkxuaisvxdxyehxlbzhomfgwuzkalcydqwzyvpvouegwrnrcbmzmfnutekmydiemkckgplranxbkkerecwukzahnclsslolkbrlsjgfyxysyximmiylypboliuwydoteianjmtlosfvfyduaiwkdbjpdhhjfeyqqjgnkxlxqaabuexkmjfjwzchuyvbghfvpdjwnxjcxiahnyqalsogtjekctqubkyyodoseiztglepuevyaybqfkwuxnzypfzqhndvlilwrtiwancpzowmoletetffvpmwonkwpmjlqypesvacnjlgccdhujynngwonwuwxrojwdrdystxyphzcuksijwbnoigfcyrgntkqtsombeigpljjpxnapjjnryadwglukgjqgyqfjaciviusrsggolowbcndrqrfvrzeurfuwmirtqfnimhqrqkjkticsjbohlsnoxptadklmfnegalviypuxygliuslmrodbnlmwglodcztzixyuknealnkghxfwrydjjuktjzpcbtriarnovgeqzzptceniifkmyylnxipunpvfhclopiqwutfnsbfkerbtyxckjhifrtfinhwmggqoohqocpdhjgznhoilzzwzfezaskyefaqyewmfyfsunwnoygrffssdxlyqqppxpdfolfzczruzuzowkxfbdmtsporqzuvcqaqdzufkllaaebyggjresvthexqvzkwzinrysbquiwtwomxbqnmldjoblbuqpibvygxuxxxkjikawjmfesijmgorjhzuoygrllsddikkpvsiihqwqkjmyzxqyxtughzjlzqrwmydolkovwhphhopcwbqmmbhlontytdrmtghgchruyztyoogutmqensvendjnzljwzwxvilqrcvsbmnvkzraqzqvzifemgaedeqsrwmjhlpkbmnrofnebzzbrzqtclpifzgduldkyvcasvxhpzivikrirdmyccwcqcvrjtqyikbfyusxyrbmdyysjxlsivkbhaejsccnypedhqgnrgcvmgapthposaryfytwrpgkfjrgnvjqhftbpmqmwumsbavogstsvacgiaftetznporifcgwpykgekqqambtfayzlolnvtakfqfwjboyoxyivtkkmnnsvkftmgnkqssxdbbuiexyxjkpkhlvtlzhzafitvhsoyjjtxxjqzcgviaacywknowtcsyythemlkyjchmsbfhcasxrcnznkcmdfxehbcdnhyofxapukeapqmujokhyflbbaazvpnmbfarshaqavugklipfcaaeffhtpxpfhjpmwhxymdrbxzgfnpjlvlavmdmgpexoekbrhapzyftllfkdipmporndipcjnivmriydwzgecybzzofsjoulnofmaywsfdcvyoogjeoeeynjpzrorenkeokohdcfeurqaazqcevrbsztpkursjjpgbzvtidywokklxtqweobbmmqsvtzkdsysygeedvwpunhlwityoypgmvzlrhugdboujujvptkwhbbytbjoihaetwgtzdnujoyqfjhhfghigrtewhyfbzyfwiuwnvqxlbivntfwlxzbwfpjykrwcbdpbrfukzloqlsrzcdifrilrvmowwxfnwzhijjyspxldtsxjklajjncxtnlewqugeylqhxovalcyxbqtrdbyzuclygeomotataiisepfjvyykggosajtcormtdkttezeyvyqwrqsmspgwxlhxhwphscatbysspfwembfbodohvyopxpqjbtkawlxwtovvnrcjwztyhkyhkccllyyaonmlysaoxbaokyntvgwqqlihfmaqbqcaitcnxqvybtwankaveonvenetsrfadpaeamygiwvyqasgnnzcpkjnejpkcgiizccnsllctghxxzswepicymirsqawwgheyweqrjenykbgkzccegizwtyomipxyxpgfbrxqwvddjfznxjpigiccbusntpspxltwraibwukfqyabjuinamkimtriykwjrxoafinemxhxprgdxfnxyyfaquxzlgvenbdowlhptjueqwdpjaawmhfrxhqpdvhlsjdckjfxlhksypztswmbvktajqumhpqbhkfuvrprgmjlcdquvgbtqnkfnbjutowxspkeazuhfyaaiysoemoudbqqtxsmnhhbdgzfokhuztsjvgblzecszafqedmpzeoprclkfuihagybvpedrlyslccmhpfecppbxnazpvlyivjpcpwynslbbcsoydalndmkxhfxvdolgxmvlgfwnvuftzldhczmetcjtcwrfmirrnthpvxaimiudppnqdotcvkucqhnmwqqrpniarddeyblasdkgketqcswkzfxdyakvlpjmwbhpqffbvqnergpyyyjbsnnsgfxledewacerknyijmfsxurkpnvlfzunjmlzkfddszbuuasiahgvzqrdkacsxidfdzmsttkgoupuvmspmoucvfcrabqawjkdvefpzgkwtpgiprxlckwzucrdonvyaymncfsqqlyiwxumfqvebjhsubmyayiprhqblvorcxldxmewypeknhznvuunoyrttiqcvhshwuzzgakdcvffwdevqaxhiwkkmskfzjqpucwrqrtsnvnghcshemzzrzspziswjuwbjmvdqtunavmtnulxmmvvkymegurlylfpmaghgmxrkrgeqjvclceyjlmexxqxfcdslbsgeximdygwkodparnjhuhythnpsvcpqhkrbsgqrzxiuofcsmkcoxigrozvhamasusmnmygcazshplxxpvjqnnanxtniinrrqunvkixmxadorkayoqjsjghmpnkymnltrbdackgtvvcuzbwdguyjpnqdhxloqlhypihlglprzhxebceagalkhdzkjfiebtdsrnjfnokzbaovwxyeimvzknuxrwvbkejjvcgvtvpcpyxrpnlehununlysrtlgqhgowheelyxyaqtawzokjvcvuwvgmiwxgihnzfhgcohnmdzntbnqqefbiatuhkdyrxupgnspjwnaztldnhezftkprvseuizirovvraogfcxoxqwyteoejfsplfwdskofxgpfkafhvoqxajozftpvucgdnazhvwclnkvxcfldsxxpsnvonovjiiioqoiexqkswwjiksvvopojccjxedowgwqxiouspvbecbhilvynvniehsqzdvwupzfiretvqcmjfmimvjzlyapsnikzarrafoxqhwrlzbqyxdptanvqdbfdgzczlxqrgzuwexnrqtqbswmerfvtzbeyxfgzlwtsxuetgitpbjnnwitgczeglrckfgxsfixoxtrgypiysvzyivfaumwjnwdjcxhtfzmcnbviizzucpkaktxbvvwfxkefqveglocjclbzkaufafjtzktpbachkhfhienvwwrhhnrilmrlagjjfghgqhaxqewewwxvlxfpzrcnaxxknjeaufupyhdlrysufyjnmvstqclwtzyenyqdcmhaxscgbninsftzbjrzpbowygroiogsnbecamreazwefzfjtysycwtegflsectqnhnehfyrqfdrykhyxfixhgruastnfshcbxfyvnwzsfjjomopdnzqfxqzouopvgqmztjshwcauyivuxlolpxvzfidjvnungxocdvofxusbpfryzsxsgortkrcvlhjvnwiayfrbksmccxbiigtjsintmfielcxzscxbiqebwfvtrxkznfpgglfejklrqsdwjgezdjieiydgtbfdxtrdgyivaphhvcvvbgrqdqhxklgwhhuhsazxsjysfmfloqdqrwjwmdhnylzavfpmquqjzvjhmazftbvknprosvxkvqikxutrqpdjcecxkydhoqwxponscxvqoaqqiprjlmaldictguwxcpddlftrufykdeyqxqljnxxwgzfneshiaaoauychfxbaslmbcpfy\n", "output": "4\n"}, {"input": "5000\ncdhzsbjbwxyhmsywzgkqgmivydggjhqivmbcscckpxoincutgipwxrppxyxcxxdhrszfcperwolpvuyaiyhngobinucvfzescpepqapoxyxzsiihekuflqiosddxtszqwjcbnmozfdodabuaqnclbxsnsnwzdyrhektnagjretarpdbgacavnlxnvnevydjvlpajfkyjitdyfwomotkrurnlgbngmhvlrumwlgipnpgcbipwzghyyesdthyvugtrmtrpwciyvufzhplnskhxrorevqgoziayfpleelosurkwnpohrgkmslehtdmtmcvzljnbumqrbkuwkduitywareowpodvqaguibitjfzaozavjqhkpkrifegnltogcixtmykznnuqdnuleirnxhfiujwgyziejdjxilbzalrxlwncinutjqvgaloynnjdvmndziuvzvtzzaxevyttlnxohrdmazfnafdzftislzwrzxwzxdcxuiapfslfhjhwtrdnwghzgzkizfiomlkxlitukwoxzgjfzkysxktcsqyuigxpcvtaydgfplygajozomztnehrgndrprzclndryunviqbfmqdqooqogkcphcdsikbiyjwsygufiahwfqgscnnrgdgpcuaysglkvemacwwdyjzuxnxqbwpdolnxuouengnkfxlredwboxbjejbkvrqixsupgsfrrmsqcakfuqivwpsdjvvpcgltvwymvwhqcaxroblkrmturwzccuhcrfbbwxetnsjswxkcojwagvqddymimclfajidlrvmdjhpfzknnecnnrrcahptkbsswbsitvazlgxgquhzkuukvpymgunqexfwsxexerivvzethipqjdqhroluzuqdiaqdkfzfqvlpgbpyijfiaffwnmzyhzjxhonvuehcimrhhpsgwpkkvegwhhhujhznyqekdngcvfdjqdxkgtddbjnslouwhdhzbawykgguzwkypndwgzigpbmwsyenoualquwnloxboywvbsnomqrblgbnjztadgfbidhqihzjvukshmrtbnmoaexseripkzzmtcnvunweteqhpjwuoqcdawxyipnnlmojdjgxsylpyouhpduhzxmftchiectjmqcxaoblccfwsyrjkgxkvduftderweefshuuywzpclkayfijzsaceonnqenlezwrgfwsbqsztkuipupfoauockzbupynyclrnpzusgaetvmwhnuuomvojdkusetbvfxydaqidmwibqfkyrocjrxsnrfhyeavabyzocztxvygkyjtrmkmfzfpaerawtssbnjovxsvzoptaeaaroizhuksnjduzegrlhqiqcnelxgyzcpvsvybwkxtawdlqiaudporocnshnpefrvwqdrkabrifonvlerclislpnxvyyowgdeakqwjjfxirutdpzlyvngkqjyrjkyfwocmflpbchuwbkgsfeeavugqsgsvqootzlyedqmumpmshevqswaeunijyqfzdxyuolvyyayebgitozehxxfcvjpsftikxrgzyrtvjjeuvsizqxmnpvhzexwnabfjgapqfpwhtzyxglkipmtictlmmjvrtpnmgffsphvycbcvkxvxcmjundttoftkzmtdldecnzvakqvaxgizwpdykeuhuwhmbspwdpgqmiolwtozzklivvewqfyqwtdffpniuydkkjyjbovltwgkfvtelmpmwilrxokyvjzxziofxdqesqucgnppbpdotpbcccybpbtdqnhsuuimoxalgqxmpxktopuxevlzkesopfxynguxecadphmrwzucrndyxthowfyixxqtrgqtejnuamgcjpwbxhgsblufoujxdrzauaogmcpxbxueencmjleleuwuybwffwujuxletlihgdukxeendiazsmqyvdtrfaqxwhukorpkgqkwagjlbigmyagtklldmvanlypxrjrcgipbupejpswasixltbhqppmxzstdifjbwfityzhteddllaiicfrhmykfwlqosgyttzdwkapqnaxomvngmenqfctenralejnkngbkxohkusuzxqolnnghhiizdvkrcmjcizolxcxvsycjkfsijortdelgmzhmmnmelseluzhiudhwdkprysaldeadawnkbwflnyjtmfzcqldsrmrhsxrtxfenwysskqwrmuzpzeeemgbvpwwdptzloyydnlzvbghxqeihlxhsqrrziowdolwxxzkpxixtdubdfybcpsguxnmwgyzpuonqwnudqmuqmfztrdobpuismyqbhrmptinzzsbebsodwmbwadjuhuupfepyairshlzddigqrgcdifdxhsxbmksuhgxuhxdvzqcuwshmqehqnegwcobthswvxvgpvwhhnybgajktoadejdvjzljlyxytnjkrlcpuoovqrwweupkourebhzinkidkdyoerglyrjmoznkexsnbztwbxnykcxksprowzgowiowdsykorrjpnnnzjzjagobtozzpvaiofceubputanwkaexfmsjxoyfjhiqsmtqrldnpzfrhnxyrcvnaufksspiquqfzjifjasnwwvasfswzhymbnqsitbgpmaomehkoqzukmhnvmftgtrmayteysgbcyulaciyehelnmzcdqlqsuwrnowsjrwlhszbgeiexrwexvkcoeykidihxvayuvvkxqsnygobrwaiudpyetfkdaksjfuxiqsfbtrxdsudzbumogsucpmfhdxyfifeviuelbysivoyxjauxbqkimafutrikojjmlxysgezvnznkolsycflfllyllkqsbcxbxlhyigokscapqczcatyeztxjfvelcxscylnlvebnsxwuszqtykfbyonwjkpibcgkxruxjevjnekvwxpnqkcmqwkuaemcworcqmskrfwzxeqmrgqbuheecbxqpfrtwmrmdlhohsubvigooosnbsdktqwxwlozmicydgkesdjqbsuslqnguduylthxvsafkanxhtlewyhxyubaizvvrccyuyhgzggefoeupjaetaughfexszuasszhluzdbhkctltbqucbhyjlkeiepwopykpohgnfbihvwgnnsvgyemisvdntbdhbwoileepytbnqvobipfwxqumktinwgxoyshkekrgqevoijlvulvznyfjooirqeuwoenrqmyjingllihyjmiyqcqdqygddlozzhatxbbyvcitdixyrohdydhwlxmezgrjborjtvkdlyzgihfpscjuhfcgejojqipfqjzwoqttortwqtaalyolpguhlopeojoffgrkgnrnjngdtypgkowjcuhykdcftnrycqfvtvxznnhrhfsizlcjhvatfwfdexafqrxsqulbmgumhajgjywtkrazlegijxbugszguksyqguzcraothtejvmfvuwghavdusczpwaxodzuczkybvcwnpptvcmljpjxgmvptxxsystzwlcbrltzzaujssybpmjdpfyvpfddxwmrazzgujydhewhduqsvbdlpmlkfqqxqkkxmmrbvbiwgzbaobbtfvgbrqjswxmnjblfdcybaxkiuzpdxkqaicxqwxfplvunawotmrpkcgiipmzuakdintuqzzpyigcfwyhsfcoejrcajakygdsemdlyvvugxjciifnrwquydknhikywqtgykftzrighpgbzemhaiuyrhszxyyfsybqogqbewozvhdisgdxycpycozyqcrauntetwzlsenrpjzznhcxlkoqttfuwyhcltobtazewdwkehbvxcopnqgacjizdemrzemdyzichmbwosbbzlaifjvlhlofxdgnqspwgnmldbvgnvvbhgydiggajgzpfwxxsprvzuaskvlkeusbyeaielnohwaorhpovdwjduyallnkghrhqilebskjzcvmedbmdpusjpxhvjntltocdusiaeuvwsirwrnznhmghdcjyrgopynjiolyusqrscqadqmaviymstpugsnpptvcqhkqckitpxenqfqfqkhjvvwsoiypzdhetwyaidvuguurgpnjidyliyihafnwibxhrnirgbtvyrzfksxptnvinvbalffebovvtysoeouyoivbunsnbcuftqqnmoroalwmwovndlxvvemlyyyxsaytodcanufhpphmqcrbafrcuckykrwwqyfwhiqawirkvuotzikxxehakudjptinmydmvydamgqbvatewqdvosyuzbloevlmofwobumkgjtmzuxrwrlhogtpgvllnlvtdjsngqqawyidtbxrjqsdwzvxvihihacpsojvhhfjajxrwlliddgmqlemqqumdhynviyycuvqfmvblqrefisrgqplkvwkzurpsvpbajtbrykbszsuawvmfnwocfnbxlfvrnhtimjywcxdruvtwsfmynleqfahvqfyflvmoigqawjgtkyypisytexspfeeowjltlbqovzktinpjctvwafangvixfihhuycbcxovnywvqushshcollqiudueeuwueytkqfrautlhflkfizzqohnejsqyfgosxrzdjqlfgjhyczbupzvxhqpsaujxusctbdfihlwsxecumufxsnzqefmroxcjddqnsytbkbtnovpvrwkuvutkibkaemclxaoktermwcthjfngxgypohcbmmlyhcfxhvhevkskywktrvgdtvdnoaifezrsnmlrpfmjfyyoqakytwihnrszmdtlcarbjbxmmsjgbfyxjekojbodqitjopxcjhzdpshliuinxdvdzbzxvnhthnijwnkqyzmdzsikjhiblazkyxjghiwvofaozfygzxkrqxwsmdnaeaepjzqtoewsjsazpxaegrxxxcixyaskdzygpyvjbuazdmiucqkggtvqqjvnyngdyznmnblbsuhgosxpkzrxisunh\n", "output": "6\n"}] |
|
231 | The main street of Berland is a straight line with n houses built along it (n is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to n - 1 in the order from the beginning of the street to the end (in the picture: from left to right). The houses with even numbers are at the other side of the street and are numbered from 2 to n in the order from the end of the street to its beginning (in the picture: from right to left). The corresponding houses with even and odd numbers are strictly opposite each other, that is, house 1 is opposite house n, house 3 is opposite house n - 2, house 5 is opposite house n - 4 and so on. [Image]
Vasya needs to get to house number a as quickly as possible. He starts driving from the beginning of the street and drives his car to house a. To get from the beginning of the street to houses number 1 and n, he spends exactly 1 second. He also spends exactly one second to drive the distance between two neighbouring houses. Vasya can park at any side of the road, so the distance between the beginning of the street at the houses that stand opposite one another should be considered the same.
Your task is: find the minimum time Vasya needs to reach house a.
-----Input-----
The first line of the input contains two integers, n and a (1 ≤ a ≤ n ≤ 100 000) — the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number n is even.
-----Output-----
Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house a.
-----Examples-----
Input
4 2
Output
2
Input
8 5
Output
3
-----Note-----
In the first sample there are only four houses on the street, two houses at each side. House 2 will be the last at Vasya's right.
The second sample corresponds to picture with n = 8. House 5 is the one before last at Vasya's left. | interview | [{"code": "n, a = list(map(int,input().split()))\nif a % 2 == 1:\n print(a // 2 + 1)\nelse:\n print((n-a) // 2 + 1)\n", "passed": true, "time": 0.2, "memory": 14324.0, "status": "done"}, {"code": "n, a = map(int, input().split())\n\nif a % 2:\n print(a//2 + 1)\nelse:\n print(n//2 - a//2 + 1)", "passed": true, "time": 0.16, "memory": 14468.0, "status": "done"}, {"code": "n, a = list(map(int, input().split()))\n\nif a % 2 == 1:\n print(a // 2 + 1)\nelse:\n print((n - a) // 2 + 1)", "passed": true, "time": 1.62, "memory": 14500.0, "status": "done"}, {"code": "a,b=input().split()\na=int(a)\nb=int(b)\nif b %2==0:\n print(1+(a-b)//2)\nelse:\n print(1+b//2)\n", "passed": true, "time": 0.15, "memory": 14328.0, "status": "done"}, {"code": "n, a = list(map(int, input().split()))\nif a % 2: ans = a // 2 + 1\nelse: ans = (n - a) // 2 + 1\nprint(ans)\n", "passed": true, "time": 1.65, "memory": 14320.0, "status": "done"}, {"code": "#!/usr/bin/env python\n\n\ndef main():\n n, a = [int(x) for x in input().split()]\n if a % 2 == 0:\n print(n // 2 - a // 2 + 1)\n else:\n print(a // 2 + 1)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14552.0, "status": "done"}, {"code": "\nn, a = map(int, input().split())\nif a % 2 == 1:\n print(int(a // 2 + 1))\n return\nelse:\n print(int(n / 2 + 1 - a // 2))\n return", "passed": true, "time": 0.23, "memory": 14312.0, "status": "done"}, {"code": "n, number = map(int, input().split())\nif number % 2:\n print(number // 2 + 1)\nelse:\n print((n - number) // 2 + 1)", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "import math\n\ndef Core(data):\n\tdata = [int(el) for el in data.split(\" \")]\n\tif data[1] % 2 == 0:\n\t\tprint (math.ceil(data[0]/2 - data[1]/2 + 1))\n\telse:\n\t\tprint (math.ceil(data[1]/2))\nCore(input())", "passed": true, "time": 0.17, "memory": 14380.0, "status": "done"}, {"code": "n, a = [int(x) for x in input().split()]\nif a % 2 == 0:\n print(n // 2 - a // 2 + 1)\nelse:\n print((a + 1) // 2)", "passed": true, "time": 0.16, "memory": 14548.0, "status": "done"}, {"code": "import math\nn,a=list([int(m) for m in input().split(' ')])\nif(a%2):\n print(math.ceil(a/2))\n return\nelse:\n print(n//2-a//2+1)\n", "passed": true, "time": 0.19, "memory": 14484.0, "status": "done"}, {"code": "n, a = list(map(int, input().split()))\n\nif a % 2:\n print(int(a // 2 + 1))\nelse:\n print(int(n / 2 - a / 2 + 1))\n", "passed": true, "time": 0.22, "memory": 14420.0, "status": "done"}, {"code": "n, a = list(map(int,input().split()))\nk = a % 2\ni = 1\nif k == 0:\n na=n\n while na!=a:\n na = na-2\n i +=1\nelse:\n na = 1\n while a!=na:\n na += 2\n i+=1\nprint(i)\n", "passed": true, "time": 0.19, "memory": 14448.0, "status": "done"}, {"code": "n, a = map(int, input().split())\nif a % 2:\n print(a // 2 + 1)\nelse:\n print((n - a) // 2 + 1)", "passed": true, "time": 0.24, "memory": 14500.0, "status": "done"}, {"code": "x,y=[int(i) for i in input().split()]\nr=1\nif y % 2==0:\n for i in range(x,1,-2):\n if i==y:\n break\n else:\n r+=1\nelse:\n for i in range(1,x,+2):\n if i==y:\n break\n else:\n r+=1\nprint(r)\n", "passed": true, "time": 0.29, "memory": 14496.0, "status": "done"}, {"code": "n,a = list(map(int,input().split()))\nk = 0\nfor i in range(1,n,2):\n k+=1\n if i==a:\n print(k)\nk = 0\nfor i in range(n,1,-2):\n k+=1\n if i==a:\n print(k)\n", "passed": true, "time": 0.3, "memory": 14496.0, "status": "done"}, {"code": "n, a = map(int, input().split())\nif a % 2 == 1:\n print(1 + a // 2)\nelse:\n print(1 + (n - a) // 2)", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "n, a = list(map(int, input().split()))\n\nif a % 2 == 0:\n print((n - a) // 2 + 1)\nelse:\n print(a // 2 + 1)\n", "passed": true, "time": 0.25, "memory": 14288.0, "status": "done"}, {"code": "def run(n, a):\n result = 1\n if a % 2 == 1:\n result += (a - 1) / 2\n else:\n result += (n - a) / 2\n\n print(int(result))\n\n\ndata = [int(x) for x in input().split(' ')]\nrun(n=data[0], a=data[1])\n", "passed": true, "time": 0.15, "memory": 14456.0, "status": "done"}, {"code": "[n, x] = list(map(int, input().split(' ')))\nanswer = int (x % 2 == 0 and (n / 2 - x / 2 + 1) or( (x + 1) / 2))\nprint(answer)", "passed": true, "time": 0.15, "memory": 14420.0, "status": "done"}, {"code": "n, a = list(map(int, input().split()))\n\nif a % 2 == 0:\n\ta = n//2 - a//2\nelse:\n\ta = (a - 1)//2\n\nprint(a + 1)\n", "passed": true, "time": 0.25, "memory": 14284.0, "status": "done"}, {"code": "n, a = input().split()\nn = int(n)\na = int(a)\nif (a % 2 == 1): print(int(a / 2 + 1))\nelse: print(int(n / 2 - a / 2 + 1))", "passed": true, "time": 0.15, "memory": 14332.0, "status": "done"}, {"code": "n, a = list(map(int, input().split()))\nif a % 2 == 1:\n print((a + 1) // 2)\nelse:\n print((n - a + 2) // 2)\n", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "al=input()\nd=al.split()\nn=int(d[0])\na=int(d[1])\nt=0\ns1=[]\ns2=[]\n\nfor i in range(1,n,2):\n\ts1.append(i)\n\nfor i in range(n,1,-2):\n\ts2.append(i)\n\nif a%2==0:\n\tfor i in range(len(s2)):\n\t\tt+=1\n\t\tif s2[i]==a:\n\t\t\tbreak\nelse:\n\tfor i in range(len(s1)):\n\t\tt+=1\n\t\tif s1[i]==a:\n\t\t\tbreak\n\nprint(t)", "passed": true, "time": 0.36, "memory": 17272.0, "status": "done"}, {"code": "n, a = list(map(int, input().split()))\nb = []\nt = 1\n\nif a % 2 == 0:\n for i in range(2, n+1, 2):\n b.append(i)\n b.reverse()\nelse:\n for i in range(1, n, 2):\n b.append(i)\n\ni = 0\nwhile b[i] != a:\n t += 1\n i += 1\n\n\nprint(t)\n", "passed": true, "time": 0.3, "memory": 15544.0, "status": "done"}] | [{"input": "4 2\n", "output": "2\n"}, {"input": "8 5\n", "output": "3\n"}, {"input": "2 1\n", "output": "1\n"}, {"input": "2 2\n", "output": "1\n"}, {"input": "10 1\n", "output": "1\n"}, {"input": "10 10\n", "output": "1\n"}, {"input": "100000 100000\n", "output": "1\n"}, {"input": "100000 2\n", "output": "50000\n"}, {"input": "100000 3\n", "output": "2\n"}, {"input": "100000 99999\n", "output": "50000\n"}, {"input": "100 100\n", "output": "1\n"}, {"input": "3000 34\n", "output": "1484\n"}, {"input": "2000 1\n", "output": "1\n"}, {"input": "100000 1\n", "output": "1\n"}, {"input": "24842 1038\n", "output": "11903\n"}, {"input": "1628 274\n", "output": "678\n"}, {"input": "16186 337\n", "output": "169\n"}, {"input": "24562 2009\n", "output": "1005\n"}, {"input": "9456 3443\n", "output": "1722\n"}, {"input": "5610 332\n", "output": "2640\n"}, {"input": "1764 1288\n", "output": "239\n"}, {"input": "28588 13902\n", "output": "7344\n"}, {"input": "92480 43074\n", "output": "24704\n"}, {"input": "40022 26492\n", "output": "6766\n"}, {"input": "85766 64050\n", "output": "10859\n"}, {"input": "67808 61809\n", "output": "30905\n"}, {"input": "80124 68695\n", "output": "34348\n"}, {"input": "95522 91716\n", "output": "1904\n"}, {"input": "7752 2915\n", "output": "1458\n"}, {"input": "5094 5058\n", "output": "19\n"}, {"input": "6144 4792\n", "output": "677\n"}, {"input": "34334 20793\n", "output": "10397\n"}, {"input": "23538 10243\n", "output": "5122\n"}, {"input": "9328 7933\n", "output": "3967\n"}, {"input": "11110 9885\n", "output": "4943\n"}, {"input": "26096 2778\n", "output": "11660\n"}, {"input": "75062 5323\n", "output": "2662\n"}, {"input": "94790 7722\n", "output": "43535\n"}, {"input": "90616 32240\n", "output": "29189\n"}, {"input": "96998 8992\n", "output": "44004\n"}, {"input": "95130 19219\n", "output": "9610\n"}, {"input": "92586 8812\n", "output": "41888\n"}, {"input": "3266 3044\n", "output": "112\n"}, {"input": "5026 4697\n", "output": "2349\n"}, {"input": "3044 2904\n", "output": "71\n"}, {"input": "6022 5396\n", "output": "314\n"}, {"input": "31270 25522\n", "output": "2875\n"}, {"input": "82156 75519\n", "output": "37760\n"}, {"input": "34614 27913\n", "output": "13957\n"}, {"input": "88024 61143\n", "output": "30572\n"}, {"input": "91870 55672\n", "output": "18100\n"}, {"input": "95718 4868\n", "output": "45426\n"}, {"input": "99564 358\n", "output": "49604\n"}, {"input": "89266 13047\n", "output": "6524\n"}, {"input": "90904 16455\n", "output": "8228\n"}, {"input": "94750 13761\n", "output": "6881\n"}, {"input": "100000 23458\n", "output": "38272\n"}, {"input": "100000 23457\n", "output": "11729\n"}, {"input": "59140 24272\n", "output": "17435\n"}, {"input": "9860 8516\n", "output": "673\n"}, {"input": "25988 2733\n", "output": "1367\n"}, {"input": "9412 5309\n", "output": "2655\n"}, {"input": "25540 23601\n", "output": "11801\n"}, {"input": "76260 6050\n", "output": "35106\n"}, {"input": "92388 39118\n", "output": "26636\n"}, {"input": "8516 5495\n", "output": "2748\n"}, {"input": "91940 37847\n", "output": "18924\n"}, {"input": "30518 286\n", "output": "15117\n"}, {"input": "46646 19345\n", "output": "9673\n"}] |
|
232 | There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has n Jedi Knights standing in front of her, each one with a lightsaber of one of m possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly k_1 knights with lightsabers of the first color, k_2 knights with lightsabers of the second color, ..., k_{m} knights with lightsabers of the m-th color. Help her find out if this is possible.
-----Input-----
The first line of the input contains n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k_1, k_2, ..., k_{m} (with $1 \leq \sum_{i = 1}^{m} k_{i} \leq n$) – the desired counts of lightsabers of each color from 1 to m.
-----Output-----
Output YES if an interval with prescribed color counts exists, or output NO if there is none.
-----Example-----
Input
5 2
1 1 2 2 1
1 2
Output
YES | interview | [{"code": "s = input().split()\nn, m = int(s[0]), int(s[1])\ncl = list(map(int, input().split()))\ncom = list(map(int, input().split()))\nres = False\nfor i in range(n):\n for j in range(i, n):\n e = True\n t = cl[i:j+1]\n for k in range(1, m+1):\n e = t.count(k)==com[k-1] and e\n if e:\n res = True\n break\n \nif res: print('YES')\nelse: print('NO')", "passed": true, "time": 1.92, "memory": 14600.0, "status": "done"}, {"code": "from collections import Counter\n\n\nn, m = list(map(int, input().split()))\n\nns = list(map(int, input().split()))\nms = list(map(int, input().split()))\n\ntarget = Counter({i: m for i, m in enumerate(ms, 1) if m != 0})\n\n\ndef check():\n for i in range(n - summs + 1):\n if target == Counter(ns[i:i + summs]):\n return True\n return False\n\n\nsumms = sum(ms)\nprint(['NO', 'YES'][check()])\n", "passed": true, "time": 0.16, "memory": 14400.0, "status": "done"}, {"code": "import sys\n\nn, m = [int(x) for x in input().split(' ')]\narr = [int(x)-1 for x in input().split(' ')]\nk = [int(x) for x in input().split(' ')]\n\nsumm = 0\nfor i in range(m):\n\tsumm += k[i]\n\nfor i in range(n):\n\tif i >= summ:\n\t\tk[arr[i-summ]] += 1\n\tk[arr[i]] -= 1\n\tdone = True\n\tfor j in range(m):\n\t\tif k[j] != 0:\n\t\t\tdone = False\n\tif done:\n\t\tprint('YES')\n\t\treturn\nprint('NO')", "passed": true, "time": 0.15, "memory": 14540.0, "status": "done"}, {"code": "n, m = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\nk = [int(i) for i in input().split()]\nfor i in range(n):\n for j in range(i + 1, n + 1):\n cur = a[i:j]\n c = [0] * m\n for l in cur:\n c[l - 1] += 1\n if c == k:\n print(\"YES\")\n return\nprint(\"NO\")\n \n", "passed": true, "time": 0.32, "memory": 14612.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nc = list(map(int, input().split()))\nk = list(map(int, input().split()))\ns = sum(k)\nfor i in range(n - s + 1):\n v = [0] * m\n for j in range(i, i + s):\n v[c[j] - 1] += 1\n if v == k:\n print('YES')\n return\nprint('NO')", "passed": true, "time": 0.14, "memory": 14532.0, "status": "done"}, {"code": "import sys\n\nn, m = map(int, input().split())\n\na = list(map(int, input().split()))\n\nk = list(map(int, input().split()))\n\nc = 0\ns = sum(k)\n\nif m==1:\n\tif a.count(1)==k[0] or k[0] in a:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\")\n\treturn\n\nfor i in range(n):\n\t\t\n\tif i+s-1<=n-1:\n\t\tk0 = [0]*m\n\t\tfor j in a[i:i+s]:\n\t\t\tk0[j-1]+=1\n\t\n\n\t\tif k0==k:\n\t\t\tprint(\"YES\")\n\t\t\treturn\n\nprint(\"NO\")", "passed": true, "time": 0.23, "memory": 14412.0, "status": "done"}, {"code": "from collections import Counter\n\nn, m = list(map(int, input().split()))\nc = list(map(int, input().split()))\nk = list(map(int, input().split()))\n\ns = sum(k)\n\nC_orig = {i + 1: k[i] for i in range(m)}\n\nfor k in set(range(1, m + 1)):\n if C_orig[k] == 0:\n del C_orig[k]\n\nC = Counter(c[:s])\n\nif C == C_orig:\n print('YES')\n return\n\nfor i in range(n - s):\n C[c[i]] -= 1\n\n if C[c[i]] == 0:\n del C[c[i]]\n\n C[c[i + s]] += 1\n\n if C == C_orig:\n print('YES')\n return\n\nprint('NO')\n", "passed": true, "time": 0.14, "memory": 14604.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nc = list(map(int, input().split()))\nk = list(map(int, input().split()))\ns = sum(k)\nfor i in range(n-s+1):\n v = [0] * m\n for j in range(i, i+s):\n v[c[j]-1]+=1\n if v == k:\n print('YES')\n return\nprint('NO')\n", "passed": true, "time": 0.15, "memory": 14420.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nc = list(map(int, input().split()))\nk = list(map(int, input().split()))\ns = sum(k)\nfor i in range(n-s+1):\n v = [0] * m\n for j in range(i, i+s):\n v[c[j]-1]+=1\n if v == k:\n print('YES')\n return\nprint('NO')\n", "passed": true, "time": 0.15, "memory": 14424.0, "status": "done"}, {"code": "n, m = list(map(int,input().split()))\na = list(map(int,input().split()))\nz = list(map(int,input().split()))\nch = 0\nif n == sum(z):\n t = 0\n for i in a:\n z[i-1] -= 1\n if z.count(0) == m:\n print('YES')\n else:\n print('NO')\n\nelse:\n for i in range(n-sum(z)+1):\n t = 0\n for j in range(1,m+1):\n if a[i:i+sum(z)].count(j) == z[j-1]:\n t+=1\n if t == m:\n print('YES')\n ch = 1\n break\n if ch == 0:\n print('NO')\n", "passed": true, "time": 0.26, "memory": 14520.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nc = list(map(int, input().split()))\nk = list(map(int, input().split()))\ns = sum(k)\nfor i in range(n - s + 1):\n v = [0] * m\n for j in range(i, i + s):\n v[c[j] - 1] += 1\n if v == k:\n print('YES')\n return\nprint('NO')", "passed": true, "time": 0.14, "memory": 14416.0, "status": "done"}, {"code": "n,m=list(map(int,input().split()))\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=[]\nfor i in range(m):\n for j in range(b[i]):\n c.append(i+1)\nflag=1 \nfor i in range(n-len(c)+1):\n temp=a[i:i+len(c)]\n if(sorted(temp)==sorted(c)):\n print(\"YES\")\n flag=0\n break\nif flag:\n print(\"NO\")\n \n \n", "passed": true, "time": 0.15, "memory": 14480.0, "status": "done"}, {"code": "n,m=map(int,input().split())\na=input().split()\nfor i in range(n):\n a[i]=int(a[i])\nk=input().split()\nfor i in range(m):\n k[i]=int(k[i])\nsum1=sum(k) \nb=[]\nc=[0 for i in range(m)]\nflag=False\nfor i in range(n):\n if(len(b)<sum1):\n b.append(a[i])\n c[a[i]-1]+=1\n elif(len(b)==sum1):\n if(c==k):\n flag=True\n c[b[0]-1]-=1\n b.pop(0)\n b.append(a[i])\n c[a[i]-1]+=1\nif(c==k):flag=True \nif(flag):print(\"YES\")\nelse:print(\"NO\")", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "n,m=list(map(int,input().split()))\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=sum(b)\nd=[0]*m\nfor i in range(c):\n d[a[i]-1]+=1\ne=0\nfor i in range(n-c+1):\n if i!=0:\n d[a[i-1]-1]-=1\n d[a[i+c-1]-1]+=1\n if d==b:\n e=1\n break\nif e==0:\n print(\"NO\")\nelse:\n print(\"YES\")", "passed": true, "time": 0.14, "memory": 14552.0, "status": "done"}, {"code": "n,m=list(map(int,input().split()))\na=list(map(int,input().split()))\nt=list(map(int,input().split()))\nx=sum(t)\nfor i in range(n-x+1):\n freq=[0]*m\n for j in range(i,i+x):\n freq[a[j]-1]+=1\n flag=True\n for j in range(m):\n if freq[j]!=t[j]:\n flag=False\n break \n if flag:\n break\nif flag:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n", "passed": true, "time": 0.2, "memory": 14480.0, "status": "done"}] | [{"input": "5 2\n1 1 2 2 1\n1 2\n", "output": "YES\n"}, {"input": "1 1\n1\n1\n", "output": "YES\n"}, {"input": "2 1\n1 1\n1\n", "output": "YES\n"}, {"input": "2 1\n1 1\n2\n", "output": "YES\n"}, {"input": "2 2\n1 2\n1 1\n", "output": "YES\n"}, {"input": "3 3\n1 1 3\n0 1 2\n", "output": "NO\n"}, {"input": "4 4\n2 3 3 2\n0 0 1 0\n", "output": "YES\n"}, {"input": "2 2\n2 2\n0 2\n", "output": "YES\n"}, {"input": "3 3\n1 1 3\n0 1 1\n", "output": "NO\n"}, {"input": "4 4\n2 4 4 3\n1 1 1 1\n", "output": "NO\n"}, {"input": "2 2\n2 1\n0 1\n", "output": "YES\n"}, {"input": "3 3\n3 1 1\n1 1 1\n", "output": "NO\n"}, {"input": "4 4\n1 3 1 4\n1 0 0 1\n", "output": "YES\n"}, {"input": "2 2\n2 1\n1 0\n", "output": "YES\n"}, {"input": "3 3\n3 1 1\n2 0 0\n", "output": "YES\n"}, {"input": "4 4\n4 4 2 2\n1 1 1 1\n", "output": "NO\n"}, {"input": "2 2\n1 2\n0 2\n", "output": "NO\n"}, {"input": "3 3\n3 2 3\n0 2 1\n", "output": "NO\n"}, {"input": "4 4\n1 2 4 2\n0 0 1 0\n", "output": "NO\n"}, {"input": "2 2\n2 1\n1 1\n", "output": "YES\n"}, {"input": "3 3\n2 2 1\n1 1 1\n", "output": "NO\n"}, {"input": "6 6\n5 1 6 3 3 2\n1 1 2 0 0 1\n", "output": "YES\n"}, {"input": "4 4\n1 2 1 1\n2 1 0 0\n", "output": "YES\n"}, {"input": "5 5\n5 3 5 2 5\n0 0 0 0 1\n", "output": "YES\n"}, {"input": "6 6\n1 2 2 4 6 1\n1 0 0 0 0 1\n", "output": "YES\n"}, {"input": "4 4\n2 2 4 1\n0 2 0 0\n", "output": "YES\n"}, {"input": "5 5\n1 5 3 5 1\n1 0 0 0 1\n", "output": "YES\n"}, {"input": "6 6\n5 4 4 3 4 6\n0 0 1 1 0 0\n", "output": "YES\n"}, {"input": "4 4\n1 3 4 4\n1 0 1 1\n", "output": "YES\n"}, {"input": "5 5\n2 5 2 5 3\n0 0 1 0 1\n", "output": "YES\n"}, {"input": "6 6\n5 6 5 6 3 5\n0 0 0 0 2 1\n", "output": "YES\n"}, {"input": "4 4\n4 3 4 2\n0 0 0 1\n", "output": "YES\n"}, {"input": "5 5\n4 2 1 1 3\n1 1 0 1 0\n", "output": "YES\n"}, {"input": "6 6\n1 5 5 1 1 6\n3 0 0 0 2 0\n", "output": "YES\n"}, {"input": "4 4\n2 3 2 2\n0 3 1 0\n", "output": "YES\n"}, {"input": "5 5\n2 1 5 1 2\n2 1 0 0 1\n", "output": "YES\n"}, {"input": "99 2\n2 1 2 1 2 2 1 1 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1 1 1 1 2 1 2 2 2 1 2 2 1 2 1 2 2 2 1 2 1 1 1 1 2 1 2 1 2 2 1 1 1 2 2 1 1 1 2 1 2 1 2 2 1 1 1 1 2 1 1 1 2 1 2 2 2 1\n3 2\n", "output": "YES\n"}, {"input": "99 2\n2 1 2 1 2 2 1 2 2 1 2 2 1 1 1 2 1 1 1 2 2 2 2 2 2 2 2 1 1 1 2 1 2 1 2 2 2 2 1 2 2 1 2 1 1 2 1 2 1 2 2 2 2 1 2 2 1 2 2 1 1 1 1 2 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 2 2 1 1\n3 2\n", "output": "YES\n"}, {"input": "99 2\n1 1 1 1 1 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 1 2 2 2 1 1 2 2 2 1 1 1 1 1 2 2 2 2 1 1 2 2 2 2 2 1 1 2 1 2 1 2 1 1 1 1 1 1 1 2 2 2 2 1 1 1 2 2 1 2 2 2 2 1 1 1 2 2 2 1 1 1 2 2 1 1 2 1 1 1 2 1 1 2 1 1\n3 2\n", "output": "YES\n"}, {"input": "99 2\n2 1 1 2 1 2 1 2 2 2 1 1 1 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 2 1 1 1 1 2 2 1 1 1 1 1 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 2 1 1 2 1 1 2 2 1 2 1 2 1 2 1 1 2 1 1 1 1 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 1 1\n4 1\n", "output": "YES\n"}, {"input": "99 2\n2 2 1 2 1 2 2 1 1 1 1 1 1 2 2 2 1 1 1 2 2 2 1 1 2 1 2 1 1 2 1 1 1 1 1 1 2 1 2 1 2 1 1 1 2 1 1 1 1 2 2 1 1 2 1 2 1 2 1 2 2 2 2 1 1 2 1 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 2 2 2 1 2 2 2 1 1\n1 4\n", "output": "YES\n"}, {"input": "99 2\n2 2 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 1 1 2 1 1 1 1 1 2 1 2 2 1 1 1 1 2 1 2 1 1 2 2 2 1 2 2 2 1 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 1 1 1 2 1 2 2 2 1 2 2 2 1 1 2 2 2 2 2 1 1 2 1 1 1 1 1 1 1 1 2 2 2 1 2 2\n0 1\n", "output": "YES\n"}, {"input": "99 2\n1 2 1 1 1 1 1 2 2 1 1 1 1 2 1 1 2 2 1 2 2 1 2 1 2 2 1 2 1 2 2 1 1 2 2 1 2 2 2 1 2 1 2 2 1 2 2 1 2 1 2 2 2 1 2 1 1 2 1 2 1 1 1 1 2 1 1 1 1 2 2 1 1 2 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 2 1 2 2 1 1 1 2 1\n1 0\n", "output": "YES\n"}, {"input": "99 2\n2 1 1 1 1 1 2 2 2 2 1 1 1 1 2 1 2 1 2 1 2 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 1 2 2 1 1 1 2 2 2 1 1 1 2 2 1 1 1 2 2 1 2 2 1 2 1 2 2 2 1 1 1 2 2 1 1 2 2 2 2 1 1 2 2 2 1 1 2 1 1 2 1 1 1 1 2 1\n0 1\n", "output": "YES\n"}, {"input": "99 2\n2 1 1 1 2 1 2 2 1 1 1 1 1 1 2 2 1 1 1 1 2 2 2 2 1 2 2 1 1 1 1 1 2 1 2 1 1 1 1 2 2 1 1 2 2 2 1 2 2 2 1 1 2 2 2 2 1 2 1 1 2 2 1 2 1 1 1 2 2 1 1 1 1 2 1 2 1 2 1 2 2 2 1 1 2 2 2 2 1 1 1 1 2 2 1 2 1 1 1\n44 55\n", "output": "NO\n"}, {"input": "99 2\n1 2 1 1 2 1 2 2 1 2 1 1 1 2 2 1 2 1 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 1 1 2 1 1 1 2 2 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 1 1 1 1 2 1 2 1 1 2 2 1 1 2 1 1 1 2 2 1 2 2 1 1 1 2 1 2 1 1 2 2 1 2 2 2 1 1 2 1 2 1 1\n50 49\n", "output": "NO\n"}, {"input": "99 2\n2 1 2 2 1 2 2 2 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 1 2 2 1 1 1 2 1 2 1 1 1 1 2 2 2 2 2 1 1 2 1 2 1 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 2 2 2 2 2 1 1 1 1 1 2 1 2 1 1 1 2 1 2 1 1 1 1 1 2 2 1 1 2 2 1 1 2 1 2 2\n52 47\n", "output": "NO\n"}, {"input": "99 2\n2 1 1 2 2 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 2 2 2 2 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 2 2 1 2 1 2 1 1 2 1 2 1 1 1 2 2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 1 2 1 2 2 2 2 1 1 1 2 1 2 1 1 1 2 1 1 1\n2 3\n", "output": "YES\n"}, {"input": "99 2\n1 2 2 1 1 1 2 1 1 2 2 1 2 2 2 1 1 2 2 1 1 1 1 2 2 2 2 1 2 2 2 2 1 1 1 1 2 1 1 1 2 2 2 1 1 1 2 2 2 2 2 2 1 2 2 2 1 2 2 1 2 1 1 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 1 1 2 1 1 1 2 1 1 2 2 1 2 1 1 1 1 2 1 1\n4 1\n", "output": "YES\n"}, {"input": "99 2\n1 1 1 1 1 2 2 2 1 2 2 2 1 1 2 1 1 2 1 1 2 2 2 2 1 2 1 2 2 2 2 1 2 2 1 2 2 2 1 1 1 1 1 1 2 1 1 2 1 2 2 1 2 1 1 1 1 1 2 1 2 1 1 1 2 2 2 1 2 2 1 2 1 2 1 2 2 2 2 1 2 1 1 2 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1\n2 3\n", "output": "YES\n"}, {"input": "99 2\n2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 1 2 2 2 1 2 1 1 1 1 1 2 2 1 1 2 2 1 1 1 1 2 2 2 1 1 1 1 2 2 2 2 1 1 1 2 2 1 1 2 2 2 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 2 1 2 2 2 1 2 2 1 2 2 1 2 1 1 2 2 1 1 1 2 1 2 2 1\n2 3\n", "output": "YES\n"}, {"input": "99 2\n1 2 2 2 1 2 1 1 2 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 2 1 1 1 2 2 1 2 1 1 2 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 2 2 2 2 1 1 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 2 1 2 1 2 1 1 2 2 2 2 1 2\n1 0\n", "output": "YES\n"}, {"input": "99 2\n1 1 1 2 2 1 2 2 1 1 2 1 1 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 1 2 1 2 2 2 2 1 2 1 1 2 2 2 1 2 2 1 1 1 1 1 1 2 2 1 1 2 1 2 2 2 1 2 2 1 1 1 1 2 1 1 2 1 2 1 1 1 2 2 2 2 2 1 1 2 1 1 2 2 1 1 2 2 1 1 2 2\n0 1\n", "output": "YES\n"}, {"input": "99 2\n2 2 1 2 2 2 1 1 1 1 1 2 2 1 2 2 2 2 2 2 1 2 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 2 1 2 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 1 2 2 2 2 1 1 2 1 1 1 1 1 2 1 1 2 2 1 1 1 2 2 1 2 2 2 2 1 2 1 2 2 1 2 2 2 1 1 1 1\n0 1\n", "output": "YES\n"}, {"input": "99 2\n1 1 1 2 2 2 1 2 1 2 1 1 1 2 1 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2 2 1 2 1 2 2 1 1 1 1 2 2 2 1 1 1 2 2 2 1 1 2 2 1 2 1 2 2 1 1 1 1 1 2 2 2 1 1 2 1 2 1 2 1 2 1 1 2 2 1 2 1 2 1 1 2 1 2 1 2 1 1 2 2 2 2 2 2 1\n52 47\n", "output": "YES\n"}, {"input": "99 2\n1 2 2 1 1 1 2 1 2 2 1 2 2 1 1 1 2 1 2 1 2 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 1 1 2 1 2 2 2 2 2 2 2 1 1 1 1 2 1 2 1 1 1 2 2 1 1 2 2 2 1 1 2 1 2 2 1 2 2 1 1 1 2 1 1 1 2 1 2 2 2 1 1\n54 45\n", "output": "YES\n"}, {"input": "99 2\n2 2 2 1 2 1 1 1 1 2 1 1 2 1 2 2 2 1 2 2 2 2 1 2 1 2 1 1 2 1 2 2 1 1 2 2 1 1 2 2 1 2 1 1 1 2 1 1 2 1 1 2 1 1 2 2 1 2 2 1 1 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 2 2 1 2 1 2 1 1 2 1\n47 52\n", "output": "YES\n"}, {"input": "100 10\n2 9 6 4 10 8 6 2 5 4 6 7 8 10 6 1 9 8 7 6 2 1 10 5 5 8 2 2 10 2 6 5 2 4 7 3 9 6 3 3 5 9 8 7 10 10 5 7 3 9 5 3 4 5 8 9 7 6 10 5 2 6 3 7 8 8 3 7 10 2 9 7 7 5 9 4 10 8 8 8 3 7 8 7 1 6 6 7 3 6 7 6 4 5 6 3 10 1 1 9\n1 0 0 0 0 0 0 0 1 0\n", "output": "YES\n"}, {"input": "100 10\n2 10 5 8 4 8 3 10 5 6 5 10 2 8 2 5 6 4 7 5 10 6 8 1 6 5 8 4 1 2 5 5 9 9 7 5 2 4 4 8 6 4 3 2 9 8 5 1 7 8 5 9 6 5 1 9 6 6 5 4 7 10 3 8 6 3 1 9 8 7 7 10 4 4 3 10 2 2 10 2 6 8 8 6 9 5 5 8 2 9 4 1 3 3 1 5 5 6 7 4\n0 0 0 0 0 1 1 0 0 0\n", "output": "YES\n"}, {"input": "100 10\n10 8 1 2 8 1 4 9 4 10 1 3 1 3 7 3 10 6 8 10 3 10 7 7 5 3 2 10 4 4 7 10 10 6 10 2 2 5 1 1 2 5 10 9 6 9 6 10 7 3 10 7 6 7 3 3 9 2 3 8 2 9 9 5 7 5 8 6 6 6 6 10 10 4 2 2 7 4 1 4 7 4 6 4 6 8 8 6 3 10 2 3 5 2 10 3 4 7 3 10\n0 0 0 1 0 0 0 0 1 0\n", "output": "YES\n"}, {"input": "100 10\n5 5 6 8 2 3 3 6 5 4 10 2 10 1 8 9 7 6 5 10 4 9 8 8 5 4 2 10 7 9 3 6 10 1 9 5 8 7 8 6 1 1 9 1 9 6 3 10 4 4 9 9 1 7 6 3 1 10 3 9 7 9 8 5 7 6 10 4 8 2 9 1 7 1 7 7 9 1 2 3 9 1 6 7 10 7 9 8 2 2 5 1 1 3 8 10 6 4 2 6\n0 0 1 0 0 0 1 0 0 0\n", "output": "NO\n"}, {"input": "100 100\n48 88 38 80 20 25 80 40 71 17 5 68 84 16 20 91 86 29 51 37 62 100 25 19 44 58 90 75 27 68 77 67 74 33 43 10 86 33 66 4 66 84 86 8 50 75 95 1 52 16 93 90 70 25 50 37 53 97 44 33 44 66 57 75 43 52 1 73 49 25 3 82 62 75 24 96 41 33 3 91 72 62 43 3 71 13 73 69 88 19 23 10 26 28 81 27 1 86 4 63\n3 0 3 2 1 0 0 1 0 2 0 0 1 0 0 2 1 0 2 1 0 0 1 1 3 1 2 1 1 0 0 0 4 0 0 0 2 0 0 1 1 0 3 3 0 0 0 0 1 2 1 2 1 0 0 0 1 1 0 0 0 3 1 0 0 3 1 2 1 1 2 1 2 1 4 0 1 0 0 0 1 1 0 2 0 4 0 1 0 2 2 0 1 0 1 1 1 0 0 1\n", "output": "YES\n"}, {"input": "100 100\n98 31 82 85 31 21 82 23 9 72 13 79 73 63 19 74 5 29 91 24 70 55 36 2 75 49 19 44 39 97 43 51 68 63 79 91 14 14 7 56 50 79 14 43 21 10 29 26 17 18 7 85 65 31 16 55 15 80 36 99 99 97 96 72 3 2 14 33 47 9 71 33 61 11 69 13 12 99 40 5 83 43 99 59 84 62 14 30 12 91 20 12 32 16 65 45 19 72 37 30\n0 0 0 0 0 0 2 0 0 1 0 0 0 2 1 1 1 1 0 0 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 2 0\n", "output": "YES\n"}, {"input": "100 100\n46 97 18 86 7 31 2 100 32 67 85 97 62 76 36 88 75 31 46 55 79 37 50 99 9 68 18 97 12 5 65 42 87 86 40 46 87 90 32 68 79 1 40 9 30 50 13 9 73 100 1 90 7 39 65 79 99 86 94 22 49 43 63 78 53 68 89 25 55 66 30 27 77 97 75 70 56 49 54 60 84 16 65 45 47 51 12 70 75 8 13 76 80 84 60 92 15 53 2 3\n2 0 0 0 1 0 1 0 3 0 0 1 1 0 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 2 1 1 0 0 0 0 1 0 1 2 0 1 1 0 1 2 1 0 2 2 0 0 1 1 2 1 0 0 0 1 0 0 1 0 3 1 0 3 0 1 0 0 1 0 2 0 1 1 3 0 0 0 0 1 0 2 2 0 1 2 0 0 0 1 0 0 2 0 2 1\n", "output": "YES\n"}, {"input": "100 100\n52 93 36 69 49 37 48 42 63 27 16 60 16 63 80 37 69 24 86 38 73 15 43 65 49 35 39 98 91 24 20 35 12 40 75 32 54 4 76 22 23 7 50 86 41 9 9 91 23 18 41 61 47 66 1 79 49 21 99 29 87 94 42 55 87 21 60 67 36 89 40 71 6 63 65 88 17 12 89 32 79 99 34 30 63 33 53 56 10 11 66 80 73 50 47 12 91 42 28 56\n1 0 0 1 0 1 1 0 2 1 1 1 0 0 0 0 1 1 0 0 2 1 2 0 0 0 0 0 1 1 0 2 1 1 0 1 0 0 0 1 2 1 0 0 0 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 1 0 2 0 1 2 1 0 0 0 1 0 1 0 1 1 0 0 2 1 0 0 0 0 0 1 2 1 2 0 1 0 0 1 0 0 0 0 2 0\n", "output": "YES\n"}, {"input": "100 100\n95 60 61 26 78 50 77 97 64 8 16 74 43 79 100 37 66 91 1 20 97 70 95 87 42 83 54 66 31 64 57 15 38 76 31 89 76 61 77 22 90 79 59 26 63 60 82 57 3 50 100 9 85 33 32 78 31 50 45 64 93 60 28 84 74 19 51 24 71 32 71 42 77 94 7 81 99 13 42 64 94 65 45 5 95 75 50 100 33 1 46 77 44 81 93 9 39 6 71 93\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 1 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\n", "output": "YES\n"}, {"input": "100 100\n20 7 98 36 47 73 38 11 46 9 98 97 24 60 72 24 14 71 41 24 77 24 23 2 15 12 99 34 14 3 79 74 8 22 57 77 93 62 62 88 32 54 8 5 34 14 46 30 65 20 55 93 76 15 27 18 11 47 80 38 41 14 65 36 75 64 1 16 64 62 33 37 51 7 78 1 39 22 84 91 78 79 77 32 24 48 14 56 21 2 42 60 96 87 23 73 44 24 20 80\n2 0 0 0 0 0 1 0 0 0 1 0 0 2 1 1 0 1 0 1 0 1 0 0 0 0 1 0 0 1 0 0 1 0 0 1 1 1 1 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 2 2 0 0 0 0 0 0 0 0 0 1 1 1 2 1 1 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0\n", "output": "YES\n"}, {"input": "100 100\n14 95 7 48 86 65 51 9 5 54 22 58 93 72 31 65 86 27 20 23 24 43 5 78 12 68 60 24 55 55 83 18 1 60 37 62 15 2 5 70 86 93 98 34 45 24 69 66 55 55 74 77 87 55 83 27 46 37 55 12 33 91 1 23 4 78 74 97 8 25 63 63 9 16 60 27 41 18 42 84 35 76 59 8 33 92 40 89 19 23 90 18 30 51 42 62 42 34 75 61\n0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", "output": "YES\n"}, {"input": "100 100\n94 78 24 48 89 1 2 22 11 42 86 26 7 23 94 100 82 27 24 28 98 62 12 53 67 43 33 45 13 1 80 99 3 79 71 20 26 35 20 69 45 52 39 48 23 3 80 43 60 90 66 43 54 40 93 35 13 20 90 47 55 39 79 2 61 95 83 60 53 4 55 3 33 74 17 38 78 83 83 94 34 43 34 99 46 71 42 58 65 94 65 64 70 88 49 39 2 36 10 55\n0 1 1 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 1 1 1 0 0 2 0 0 0 1 0 0 0 0 0 1 1 2 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 3 0 0 0 0 0 0 1 0 0 1 1 1 0 0 0 1 0\n", "output": "YES\n"}] |
|
235 | After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.
This means the process of eating candies is the following: in the beginning Vasya chooses a single integer $k$, same for all days. After that, in the morning he eats $k$ candies from the box (if there are less than $k$ candies in the box, he eats them all), then in the evening Petya eats $10\%$ of the candies remaining in the box. If there are still candies left in the box, the process repeats — next day Vasya eats $k$ candies again, and Petya — $10\%$ of the candies left in a box, and so on.
If the amount of candies in the box is not divisible by $10$, Petya rounds the amount he takes from the box down. For example, if there were $97$ candies in the box, Petya would eat only $9$ of them. In particular, if there are less than $10$ candies in a box, Petya won't eat any at all.
Your task is to find out the minimal amount of $k$ that can be chosen by Vasya so that he would eat at least half of the $n$ candies he initially got. Note that the number $k$ must be integer.
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the initial amount of candies in the box.
-----Output-----
Output a single integer — the minimal amount of $k$ that would allow Vasya to eat at least half of candies he got.
-----Example-----
Input
68
Output
3
-----Note-----
In the sample, the amount of candies, with $k=3$, would change in the following way (Vasya eats first):
$68 \to 65 \to 59 \to 56 \to 51 \to 48 \to 44 \to 41 \\ \to 37 \to 34 \to 31 \to 28 \to 26 \to 23 \to 21 \to 18 \to 17 \to 14 \\ \to 13 \to 10 \to 9 \to 6 \to 6 \to 3 \to 3 \to 0$.
In total, Vasya would eat $39$ candies, while Petya — $29$. | interview | [{"code": "def can(n, k):\n total = n\n s = 0\n\n while n > 0:\n cur = min(n, k)\n s += cur\n n -= cur\n\n n -= n // 10\n\n return s * 2 >= total\n\nn = int(input())\n\nle = 0\nrg = n\n\nwhile rg - le > 1:\n mid = (rg + le) // 2\n\n if can(n, mid):\n rg = mid\n else:\n le = mid\n\nprint(rg)\n", "passed": true, "time": 0.16, "memory": 14336.0, "status": "done"}, {"code": "def consumed(n, k):\n res = 0\n while n:\n eaten = min(n, k)\n res += eaten\n n -= eaten\n n -= n // 10\n return res\n\nn = int(input())\n\nlo = 1\nhigh = (n+1) // 2\n\nwhile lo != high:\n mid = (lo + high) // 2\n if consumed(n, mid) * 2 >= n:\n high = mid\n else:\n lo = mid + 1\n\nprint(lo)\n", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "def read_input():\n\treturn map(int, input().split())\n\nn = int(input())\n\ndef eat(k, n):\n\tans = 0\n\twhile n >= k:\n\t\tans += k\n\t\tn = max(0, (n - k) - (n - k) // 10)\n\tans += n\n\treturn ans\n\nl = 1\nr = n + 1\n\nwhile r - l > 1:\n\tm = (l + r) >> 1\n\tif 2 * eat(m, n) >= n:\n\t\tr = m\n\telse:\n\t\tl = m\n\nprint(l if 2 * eat(l, n) >= n else l + 1)", "passed": true, "time": 0.33, "memory": 14308.0, "status": "done"}, {"code": "\n\n\n\ndef how_much_he_eats(n, k):\n result = 0\n while n != 0:\n eats = min([n, k])\n result += eats\n n -= eats\n n -= n // 10\n return result\n\n\nn = int(input())\n\na, b, c = 1, n, 0\n\nwhile a < b:\n c = (a + b) // 2\n\n if 2 * how_much_he_eats(n, c) >= n:\n b = c\n else:\n a = c + 1\n\nprint(a)\n", "passed": true, "time": 0.27, "memory": 14324.0, "status": "done"}, {"code": "N = int(input())\n\ndef check(k):\n r = N\n a = 0\n while 1:\n if r < k:\n a += r\n break\n r -= k\n a += k\n r -= r//10\n return a*2 >= N\n\n\nleft = 0; right = 10**18+1\nwhile left+1 < right:\n mid = (left + right) // 2\n if check(mid):\n right = mid\n else:\n left = mid\nprint(right)\n", "passed": true, "time": 0.16, "memory": 14548.0, "status": "done"}, {"code": "n=int(input())\ndef query(k):\n t=n\n g=(n+1)//2\n while t:\n if t<k:\n g-=t\n break\n t-=k\n g-=k\n t=t-t//10\n if g<=0:return 1\n else:return 0\n\ndef bs(l,r):\n if l==r: return l\n m=(l+r)//2\n if query(m):return bs(l,m)\n else: return bs(m+1,r)\n\nprint(bs(1,1000000000000000000))\n", "passed": true, "time": 0.16, "memory": 14540.0, "status": "done"}, {"code": "n = int(input())\nl = 1\nr = n\nwhile l < r:\n m = (l + r) // 2\n cur = n\n k = m\n p = 0\n v = 0\n while cur:\n v += min(cur, k)\n cur -= min(cur, k)\n p += cur // 10\n cur -= cur // 10\n if v >= (n + 1) // 2:\n r = m\n else:\n l = m + 1\nprint(l)\n", "passed": true, "time": 0.16, "memory": 14460.0, "status": "done"}, {"code": "def ii():\n return int(input())\ndef mi():\n return map(int, input().split())\ndef li():\n return list(mi())\n \ndef f(n, k):\n c = 0\n e = 0\n while n > 0:\n e += min(k, n)\n n -= k\n n -= n // 10\n c += 1\n return e\n\nn = ii()\nlo = 1\nhi = th = (n + 1) // 2\nwhile lo < hi:\n mid = (lo + hi) // 2\n cnt = f(n, mid)\n if cnt >= th:\n hi = mid\n else:\n lo = mid + 1\nprint(lo)", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}, {"code": "def f(n, k):\n m = n\n p, v = 0, 0\n while n > 0:\n p += min(k, n)\n n -= min(n, k)\n if p >= m // 2:\n break\n v += n // 10\n n -= n // 10\n if v > m // 2:\n break\n return p >= v\n\nn = int(input())\n\nl, u = 1, n\nwhile (l != u):\n m = (l + u) // 2\n if not f(n, l) and not f(n, m):\n l = m + 1\n elif f(n, m) and f(n, u):\n u = m\nprint(l)\n", "passed": true, "time": 0.21, "memory": 14564.0, "status": "done"}, {"code": "n = int(input())\n\n\ndef check(p):\n V = 0\n n_ = n\n while n_ > 0:\n temp = min(n_, p)\n V += temp\n n_ -= temp\n n_ -= n_ // 10\n\n return 2 * V >= n\n\n\ndef binSearch(a, b):\n left, right = a - 1, b + 1\n\n while right - left > 1:\n mid = (left + right) // 2\n\n if check(mid):\n right = mid\n\n else:\n left = mid\n\n return right\n\n\nprint(binSearch(1, n // 2))\n", "passed": true, "time": 0.15, "memory": 14564.0, "status": "done"}, {"code": "n = int(input())\n\n\ndef eat(n, k):\n first = 0\n old = n\n while n > 0:\n if n > k:\n n -= k\n first += k\n else:\n first += n\n n = 0\n n -= n // 10\n if 2 * first >= old:\n return True\n return False\n\n\nr = n + 1\nl = 1\n\n\nwhile l + 1 < r:\n m = l + (r - l - 1) // 2\n if eat(n, m):\n r = m + 1\n else:\n l = m + 1\n\nprint(l)\n", "passed": true, "time": 1.81, "memory": 14352.0, "status": "done"}, {"code": "n = int(input())\n\nhalf = (n-1) // 2 + 1\n\ndef simulate(k):\n remain = n\n vasya = 0\n \n while remain > 0:\n vasya += min(k, remain)\n remain -= k\n remain -= remain // 10\n \n return vasya >= half\n\nhi = n\nlo = 0\n\nwhile hi - lo > 1:\n mid = (hi + lo) // 2\n \n if simulate(mid):\n hi = mid\n else:\n lo = mid\n\nprint(hi)", "passed": true, "time": 0.15, "memory": 14632.0, "status": "done"}, {"code": "import math\nn = int( input() )\n\ndef eat( k ):\n vasya = petya = 0\n candy = n\n while candy > 0:\n ate = 0\n ate = min( candy, k )\n vasya += ate\n candy -= ate\n if candy > 9:\n ate = candy // 10\n petya += ate\n candy -= ate\n return vasya >= petya\n\nl = int( math.log( n, 2 ) )\na = 0\nwhile l >= 0:\n b = 1 << l\n c = n - a - b\n if c > 0 and eat( c ):\n a += b\n l -= 1\n\nprint( n - a )\n", "passed": true, "time": 0.16, "memory": 14384.0, "status": "done"}, {"code": "n = int(input())\n\nif n <= 10:\n\tprint(\"1\")\n\treturn\n\ndef check(k):\n\tout = 0\n\tcur = n\n\twhile cur != 0:\n\t\ttmp = min(cur, k)\n\t\tcur -= tmp\n\t\tout += tmp\n\t\tif cur >= 10:\n\t\t\tcur -= cur // 10\n\treturn out\n\nl = 0\nr = 10 ** 18 + 1\nk = (l + r) // 2\nwhile r - l > 1:\n\tif 2 * check(k) >= n:\n\t\tr = k\n\telse:\n\t\tl = k\n\tk = (l + r) // 2\n\nprint(k + 1)\n", "passed": true, "time": 0.15, "memory": 14468.0, "status": "done"}, {"code": "n = int(input())\n\ndef check(k):\n a, b = 0, 0\n i = n\n while i > 0:\n t = min(k, i)\n a += t\n i -= t\n\n t = i // 10\n b += t\n i -= t\n # dbvar(k, a, b)\n return a >= b\n\nleft = 1\nright = n\nwhile right - left > 1:\n m = (left + right) // 2\n if check(m):\n right = m\n else:\n left = m\nprint(left if check(left) else right)", "passed": true, "time": 0.15, "memory": 14328.0, "status": "done"}, {"code": "# \n# ___ ___ ___ ___ ___ ___ \n# /\\__\\ /\\ \\ ___ /\\__\\ /\\ \\ /\\__\\ /\\ \\ \n# /:/ / /::\\ \\ /\\ \\ /:/ / /::\\ \\ /:/ / /::\\ \\ \n# /:/__/ /:/\\:\\ \\ \\:\\ \\ /:/ / /:/\\:\\ \\ /:/ / /:/\\ \\ \\ \n# /::\\__\\____ /::\\\u02c9\\:\\ \\ /::\\__\\ /:/ / /:/ \\:\\__\\ /:/ / _\\:\\\u02c9\\ \\ \\ \n# /:/\\:::::\\__\\ /:/\\:\\ \\:\\__\\ __/:/\\/__/ /:/__/ /:/__/ \\:|__| /:/__/ /\\ \\:\\ \\ \\__\\\n# \\/_|:|\u02c9\u02c9|\u02c9 \\/__\\:\\/:/ / /\\/:/ / \\:\\ \\ \\:\\ \\ /:/ / \\:\\ \\ \\:\\ \\:\\ \\/__/\n# |:| | \\::/ / \\::/__/ \\:\\ \\ \\:\\ /:/ / \\:\\ \\ \\:\\ \\:\\__\\ \n# |:| | /:/ / \\:\\__\\ \\:\\ \\ \\:\\/:/ / \\:\\ \\ \\:\\/:/ / \n# |:| | /:/ / \\/__/ \\:\\__\\ \\::/__/ \\:\\__\\ \\::/ / \n# \\|__| \\/__/ \\/__/ \u02c9\u02c9 \\/__/ \\/__/ \n#\n\nn = int(input())\n\ndef che(k):\n nn = n\n cnt = 0\n while nn:\n if nn <= k:\n cnt += nn\n break\n cnt += k\n nn -= k\n nn -= nn//10\n return (cnt<<1) >= n\n\nl, r = 1, 1000000000000000000\nwhile l < r:\n mid = (l+r)>>1\n if (che(mid)):\n r = mid\n else:\n l = mid+1\nprint(r)\n", "passed": true, "time": 0.15, "memory": 14416.0, "status": "done"}, {"code": "\nimport sys\nimport math\nimport os.path\nimport random\nfrom copy import deepcopy\nfrom functools import reduce\nfrom collections import Counter, ChainMap, defaultdict\nfrom itertools import cycle, chain\nfrom queue import Queue, PriorityQueue\nfrom heapq import heappush, heappop, heappushpop, heapify, heapreplace, nlargest, nsmallest\nimport bisect\nfrom statistics import mean, mode, median, median_low, median_high\n# CONFIG\nsys.setrecursionlimit(1000000000)\n# LOG \ndef log(*args, **kwargs):\n print(*args, file=sys.stderr, **kwargs)\n# INPUT\ndef ni():\n return map(int, input().split())\ndef nio(offset):\n return map(lambda x: int(x) + offset, input().split())\ndef nia():\n return list(map(int, input().split()))\n# CONVERT\ndef toString(aList, sep=\" \"):\n return sep.join(str(x) for x in aList)\ndef toMapInvertIndex(aList):\n return {k: v for v, k in enumerate(aList)}\n# SORT\ndef sortId(arr):\n return sorted(range(arr), key=lambda k: arr[k])\n# MATH\ndef gcd(a,b):\n while b:\n a, b = b, a % b\n return a\n# MAIN\n\nn, = ni()\n\ndef check(k):\n v = 0\n p = 0\n x = n\n # log(\"check\",k)\n while (x > 0):\n if (x > k):\n v += k\n x -= k\n if (x > 9):\n pd = x // 10\n p += pd\n x -= pd\n else:\n v += x\n x = 0\n \n # log(\" \", x, v, p)\n \n # log(k,v,p)\n return v >= p\n\ndef bsearch(low, high):\n # log(low,high)\n if (low >= high):\n return low\n mid = (low + high) // 2\n if check(mid):\n return bsearch(low, mid)\n else:\n return bsearch(mid+1, high)\n\n\nx = bsearch(1,n)\n# log(x)\nprint(x)", "passed": true, "time": 0.17, "memory": 14632.0, "status": "done"}, {"code": "n = int(input())\n\nl = 0\nr = n\n\ndef eats(n, k):\n\tres = 0\n\twhile n > 0:\n\t\tif n < k:\n\t\t\tres += n\n\t\t\tn = 0\n\t\telse:\n\t\t\tres += k\n\t\t\tn -= k\n\t\t\tn -= n//10\n\treturn res\n\nwhile r-l > 1:\n\tmid = (r + l) // 2\n\tif eats(n, mid) >= (n+1) // 2:\n\t\tr = mid\n\telse:\n\t\tl = mid\n\nprint(r)\n", "passed": true, "time": 0.15, "memory": 14508.0, "status": "done"}, {"code": "DEBUG = True\nn = input().strip().split(\" \")\nn = int(n[0])\n\ndef oneTest(N, k):\n n = N\n\n nv = 0\n np = 0\n\n while n > 0:\n if n <= k:\n nv += n\n n = 0\n else:\n n -= k\n nv += k\n\n x = n // 10\n n -= x\n np += x\n\n assert nv + np == N\n return nv * 2 >= N\n\n\ndef getResult(n):\n lo = 1\n hi = n\n while lo < hi:\n mid = (lo + hi) // 2\n if not oneTest(n, mid):\n lo = mid + 1\n else:\n hi = mid\n return lo\n\n\nk = getResult(n)\nprint(k)\n\nif DEBUG:\n if k > 1:\n assert not oneTest(n, k-1)\n assert oneTest(n, k)\n assert oneTest(n, k+1)\n", "passed": true, "time": 0.15, "memory": 14508.0, "status": "done"}, {"code": "n=int(input())\ndef f(k):\n s=(n+1)//2;m=n\n while s>0and m:\n l=min(k,m);s-=l;m-=l;m-=m//10\n return s<=0\nl=[1,1]\nif not f(1):\n l[1]=n//2\n while l[1]-l[0]>1:\n m=sum(l)//2\n l[f(m)]=m\nprint(l[1])", "passed": true, "time": 0.16, "memory": 14360.0, "status": "done"}, {"code": "n = int(input())\nleft = 1\nright = n\n\ndef modulate(k):\n e = n\n Vasya = 0\n Petya = 0\n while e > 0:\n #print(e)\n if e <= k:\n Vasya += e\n break\n diff = e - k\n Vasya += k\n e -= k\n if e >= 10:\n Petya += diff // 10\n e -= diff // 10\n #print(e, ' left')\n #print(Vasya, 'ate Vasya overall')\n #print(Petya, 'ate Petya overall')\n if Vasya >= Petya:\n return True\n else:\n return False\n\nwhile right - left > 1:\n middle = (right + left) // 2\n if not modulate(middle):\n left = middle\n else:\n right = middle\n\nif modulate(left):\n print(left)\nelse:\n print(right)\n", "passed": true, "time": 0.15, "memory": 14352.0, "status": "done"}] | [{"input": "68\n", "output": "3\n"}, {"input": "1\n", "output": "1\n"}, {"input": "2\n", "output": "1\n"}, {"input": "42\n", "output": "1\n"}, {"input": "43\n", "output": "2\n"}, {"input": "756\n", "output": "29\n"}, {"input": "999999972\n", "output": "39259423\n"}, {"input": "999999973\n", "output": "39259424\n"}, {"input": "1000000000000000000\n", "output": "39259424579862572\n"}, {"input": "6\n", "output": "1\n"}, {"input": "3\n", "output": "1\n"}, {"input": "4\n", "output": "1\n"}, {"input": "5\n", "output": "1\n"}, {"input": "66\n", "output": "2\n"}, {"input": "67\n", "output": "3\n"}, {"input": "1000\n", "output": "39\n"}, {"input": "10000\n", "output": "392\n"}, {"input": "100500\n", "output": "3945\n"}, {"input": "1000000\n", "output": "39259\n"}, {"input": "10000000\n", "output": "392594\n"}, {"input": "100000000\n", "output": "3925942\n"}, {"input": "123456789\n", "output": "4846842\n"}, {"input": "543212345\n", "output": "21326204\n"}, {"input": "505050505\n", "output": "19827992\n"}, {"input": "777777777\n", "output": "30535108\n"}, {"input": "888888871\n", "output": "34897266\n"}, {"input": "1000000000\n", "output": "39259424\n"}, {"input": "999999999999999973\n", "output": "39259424579862572\n"}, {"input": "999999999999999998\n", "output": "39259424579862572\n"}, {"input": "999999999999999999\n", "output": "39259424579862573\n"}, {"input": "100000000000000000\n", "output": "3925942457986257\n"}, {"input": "540776028375043656\n", "output": "21230555700587649\n"}, {"input": "210364830044445976\n", "output": "8258802179385535\n"}, {"input": "297107279239074256\n", "output": "11664260821414605\n"}, {"input": "773524766411950187\n", "output": "30368137227605772\n"}, {"input": "228684941775227220\n", "output": "8978039224174797\n"}, {"input": "878782039723446310\n", "output": "34500477210660436\n"}, {"input": "615090701338187389\n", "output": "24148106998961343\n"}, {"input": "325990422297859188\n", "output": "12798196397960353\n"}, {"input": "255163492355051023\n", "output": "10017571883647466\n"}, {"input": "276392003308849171\n", "output": "10850991008380891\n"}, {"input": "601\n", "output": "23\n"}, {"input": "983\n", "output": "38\n"}, {"input": "729\n", "output": "29\n"}, {"input": "70\n", "output": "3\n"}, {"input": "703\n", "output": "28\n"}, {"input": "257\n", "output": "10\n"}, {"input": "526\n", "output": "20\n"}, {"input": "466\n", "output": "18\n"}, {"input": "738\n", "output": "29\n"}, {"input": "116\n", "output": "5\n"}, {"input": "888888888888888887\n", "output": "34897266293211176\n"}, {"input": "888888888888888888\n", "output": "34897266293211176\n"}, {"input": "888888888888888889\n", "output": "34897266293211176\n"}, {"input": "999999999999999969\n", "output": "39259424579862571\n"}, {"input": "999999999999999970\n", "output": "39259424579862571\n"}, {"input": "999999999999999971\n", "output": "39259424579862572\n"}, {"input": "999999999999999943\n", "output": "39259424579862571\n"}, {"input": "999999999999999944\n", "output": "39259424579862570\n"}, {"input": "999999999999999945\n", "output": "39259424579862571\n"}, {"input": "999999999999999917\n", "output": "39259424579862570\n"}, {"input": "999999999999999918\n", "output": "39259424579862569\n"}, {"input": "999999999999999919\n", "output": "39259424579862570\n"}, {"input": "99999999999999957\n", "output": "3925942457986255\n"}, {"input": "99999999999999958\n", "output": "3925942457986255\n"}, {"input": "99999999999999959\n", "output": "3925942457986256\n"}, {"input": "888888888888888853\n", "output": "34897266293211174\n"}, {"input": "888888888888888854\n", "output": "34897266293211174\n"}, {"input": "888888888888888855\n", "output": "34897266293211175\n"}] |
|
236 | A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. $0$
You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you like, but you can't throw away any parts.
Can you make the number of links between every two adjacent pearls equal? Two pearls are considered to be adjacent if there is no other pearl between them.
Note that the final necklace should remain as one circular part of the same length as the initial necklace.
-----Input-----
The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl.
-----Output-----
Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO".
You can print each letter in any case (upper or lower).
-----Examples-----
Input
-o-o--
Output
YES
Input
-o---
Output
YES
Input
-o---o-
Output
NO
Input
ooo
Output
YES | interview | [{"code": "def main():\n s = input()\n links = s.count('-')\n pearls = s.count('o')\n if pearls == 0 or links % pearls == 0:\n print('YES')\n else:\n print('NO')\n\nmain()\n", "passed": true, "time": 0.24, "memory": 14484.0, "status": "done"}, {"code": "s = input()\na = s.count('o')\nb = s.count('-')\nif (a == 0):\n print('YES')\nelif b % a == 0:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.22, "memory": 14428.0, "status": "done"}, {"code": "s = input()\n\na = s.count('-')\nb = s.count('o')\n\nif(b == 0 or a % b == 0):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14352.0, "status": "done"}, {"code": "s=input()\nb=s.count('o')\nn=s.count('-')\nif n==0 or b==0:\n print('YES')\nelse:\n if n%b==0:\n print('YES')\n else:\n print('NO')", "passed": true, "time": 0.21, "memory": 14524.0, "status": "done"}, {"code": "s = input()\nx = s.count('o')\ny = s.count('-')\nif x == 0 or y == 0:\n print('YES')\nelse:\n print('YES' if y % x == 0 else 'NO')", "passed": true, "time": 0.25, "memory": 14496.0, "status": "done"}, {"code": "chain = input()\npearls = chain.count('o')\nelements = chain.count('-')\nif pearls == 0:\n print ('YES')\nelif (elements%pearls)==0:\n print ('YES')\nelse:\n print ('NO')\n", "passed": true, "time": 1.73, "memory": 14364.0, "status": "done"}, {"code": "s = input()\nno = s.count('o')\nif no == 0:\n print('YES')\n return\nnt = len(s) - no\nif nt % no == 0:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.25, "memory": 14516.0, "status": "done"}, {"code": "s = input()\nt = s.count('o')\nc = s.count('-')\nif (t == 0 or c % t == 0):\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.15, "memory": 14528.0, "status": "done"}, {"code": "s = input()\no = s.count('o')\np = s.count('-')\nif o == 0:\n print('YES')\n return\nif p % o == 0:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}, {"code": "from collections import Counter\n\ns = input()\n\nc = Counter(s)\n\nif c['o'] == 0:\n print(\"YES\")\nelse:\n print(\"YES\" if c['-']%c['o'] == 0 else \"NO\")", "passed": true, "time": 0.15, "memory": 14252.0, "status": "done"}, {"code": "s = input()\nc1 = s.count('-')\nc2 = s.count('o')\nif c2 == 0 or (c2 != 0 and c1 % c2 == 0):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14348.0, "status": "done"}, {"code": "def go():\n s = input()\n p = s.count('o')\n l = s.count('-')\n\n if p == 0:\n return 'YES'\n if l % p == 0:\n return 'YES'\n return 'NO'\nprint(go())\n", "passed": true, "time": 0.15, "memory": 14280.0, "status": "done"}, {"code": "s = input()\np = len([char for char in s if char == 'o'])\nl = len([char for char in s if char == '-'])\nif p == 0 or l % p == 0:\n\tprint('YES')\nelse:\n\tprint('NO')", "passed": true, "time": 0.16, "memory": 14256.0, "status": "done"}, {"code": "'''input\n---\n'''\ndef ii():\n\treturn int(input())\ndef ai():\n\treturn map(int,input().split())\ns = input()\np = s.count('-')\nf = s.count('o')\nif f is 0:\n\tprint(\"YES\")\n\treturn\nif p % f == 0 :\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")", "passed": true, "time": 0.16, "memory": 14528.0, "status": "done"}, {"code": "c1 = c2 = 0\nfor i in input():\n if i == 'o':\n c2+=1\n else:\n c1+=1\nif c2 == 0:\n print(\"YES\")\nelif c1%c2:\n print(\"NO\")\nelse:\n print(\"YES\")", "passed": true, "time": 0.14, "memory": 14400.0, "status": "done"}, {"code": "s = input()\n\nx = s.count('o')\ny = len(s) - x\n\nif (x <= 1):\n print(\"YES\")\nelse:\n if (y % x == 0):\n print(\"YES\")\n else:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "from sys import stdin, stdout\n\ndef main():\n s = input()\n p = sum([x == 'o' for x in s])\n l = sum([x == '-' for x in s])\n\n if p == 0 or l % p == 0:\n print('YES')\n else:\n print('NO')\n\n\n\n\nmain()\n", "passed": true, "time": 0.15, "memory": 14524.0, "status": "done"}, {"code": "def ii():\n return int(input())\ndef mi():\n return map(int, input().split())\ndef li():\n return list(mi())\n\ns = input().strip()\na = s.count('-')\nb = s.count('o')\nif b:\n print('YES' if a % b == 0 else 'NO')\nelse:\n print('YES')", "passed": true, "time": 0.15, "memory": 14552.0, "status": "done"}, {"code": "s = input().strip()\n\npearls = s.count(\"o\")\nlinks = s.count(\"-\")\n\nif not pearls or links % pearls == 0:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "from collections import Counter\nnl = Counter(input())\nprint('YES' if len(nl) == 1 or nl['-'] % nl['o'] == 0 else 'NO')\n", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}] | [{"input": "-o-o--\n", "output": "YES\n"}, {"input": "-o---\n", "output": "YES\n"}, {"input": "-o---o-\n", "output": "NO\n"}, {"input": "ooo\n", "output": "YES\n"}, {"input": "---\n", "output": "YES\n"}, {"input": "--o-o-----o----o--oo-o-----ooo-oo---o--\n", "output": "YES\n"}, {"input": "-o--o-oo---o-o-o--o-o----oo------oo-----o----o-o-o--oo-o--o---o--o----------o---o-o-oo---o--o-oo-o--\n", "output": "NO\n"}, {"input": "-ooo--\n", "output": "YES\n"}, {"input": "---o--\n", "output": "YES\n"}, {"input": "oo-ooo\n", "output": "NO\n"}, {"input": "------o-o--o-----o--\n", "output": "YES\n"}, {"input": "--o---o----------o----o----------o--o-o-----o-oo---oo--oo---o-------------oo-----o-------------o---o\n", "output": "YES\n"}, {"input": "----------------------------------------------------------------------------------------------------\n", "output": "YES\n"}, {"input": "-oo-oo------\n", "output": "YES\n"}, {"input": "---------------------------------o----------------------------oo------------------------------------\n", "output": "NO\n"}, {"input": "oo--o--o--------oo----------------o-----------o----o-----o----------o---o---o-----o---------ooo---\n", "output": "NO\n"}, {"input": "--o---oooo--o-o--o-----o----ooooo--o-oo--o------oooo--------------ooo-o-o----\n", "output": "NO\n"}, {"input": "-----------------------------o--o-o-------\n", "output": "YES\n"}, {"input": "o-oo-o--oo----o-o----------o---o--o----o----o---oo-ooo-o--o-\n", "output": "YES\n"}, {"input": "oooooooooo-ooo-oooooo-ooooooooooooooo--o-o-oooooooooooooo-oooooooooooooo\n", "output": "NO\n"}, {"input": "-----------------o-o--oo------o--------o---o--o----------------oooo-------------ooo-----ooo-----o\n", "output": "NO\n"}, {"input": "ooo-ooooooo-oo-ooooooooo-oooooooooooooo-oooo-o-oooooooooo--oooooooooooo-oooooooooo-ooooooo\n", "output": "NO\n"}, {"input": "oo-o-ooooo---oo---o-oo---o--o-ooo-o---o-oo---oo---oooo---o---o-oo-oo-o-ooo----ooo--oo--o--oo-o-oo\n", "output": "NO\n"}, {"input": "-----o-----oo-o-o-o-o----o---------oo---ooo-------------o----o---o-o\n", "output": "YES\n"}, {"input": "oo--o-o-o----o-oooo-ooooo---o-oo--o-o--ooo--o--oooo--oo----o----o-o-oooo---o-oooo--ooo-o-o----oo---\n", "output": "NO\n"}, {"input": "------oo----o----o-oo-o--------o-----oo-----------------------o------------o-o----oo---------\n", "output": "NO\n"}, {"input": "-o--o--------o--o------o---o-o----------o-------o-o-o-------oo----oo------o------oo--o--\n", "output": "NO\n"}, {"input": "------------------o----------------------------------o-o-------------\n", "output": "YES\n"}, {"input": "-------------o----ooo-----o-o-------------ooo-----------ooo------o----oo---\n", "output": "YES\n"}, {"input": "-------o--------------------o--o---------------o---o--o-----\n", "output": "YES\n"}, {"input": "------------------------o------------o-----o----------------\n", "output": "YES\n"}, {"input": "------oo----------o------o-----o---------o------------o----o--o\n", "output": "YES\n"}, {"input": "------------o------------------o-----------------------o-----------o\n", "output": "YES\n"}, {"input": "o---o---------------\n", "output": "YES\n"}, {"input": "----------------------o---o----o---o-----------o-o-----o\n", "output": "YES\n"}, {"input": "----------------------------------------------------------------------o-o---------------------\n", "output": "YES\n"}, {"input": "----o---o-------------------------\n", "output": "YES\n"}, {"input": "o----------------------oo----\n", "output": "NO\n"}, {"input": "-o-o--o-o--o-----o-----o-o--o-o---oooo-o\n", "output": "NO\n"}, {"input": "-o-ooo-o--o----o--o-o-oo-----------o-o-\n", "output": "YES\n"}, {"input": "o-------o-------o-------------\n", "output": "YES\n"}, {"input": "oo----------------------o--------------o--------------o-----\n", "output": "YES\n"}, {"input": "-----------------------------------o---------------------o--------------------------\n", "output": "YES\n"}, {"input": "--o--o----o-o---o--o----o-o--oo-----o-oo--o---o---ooo-o--\n", "output": "YES\n"}, {"input": "---------------o-o----\n", "output": "YES\n"}, {"input": "o------ooo--o-o-oo--o------o----ooo-----o-----o-----o-ooo-o---o----oo\n", "output": "YES\n"}, {"input": "----o----o\n", "output": "YES\n"}, {"input": "o--o--o--o--o--o--o--o--o--o--o--o--\n", "output": "YES\n"}, {"input": "o---o---o---o---o----o----o----o---o---o---o\n", "output": "YES\n"}, {"input": "o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-\n", "output": "YES\n"}, {"input": "-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o\n", "output": "YES\n"}, {"input": "o----------o----------o----------o----------o----------o----------o----------o----------o----------o\n", "output": "YES\n"}, {"input": "o---------o---------o---------o---------o---------o---------o---------o---------o\n", "output": "YES\n"}, {"input": "--------o--------o--------o--------o--------o--------o--------o--------o--------\n", "output": "YES\n"}, {"input": "o---o----\n", "output": "NO\n"}, {"input": "---o----o\n", "output": "NO\n"}, {"input": "-o-\n", "output": "YES\n"}, {"input": "------oooo\n", "output": "NO\n"}, {"input": "oo--\n", "output": "YES\n"}, {"input": "---o\n", "output": "YES\n"}, {"input": "ooo-\n", "output": "NO\n"}, {"input": "oooooooo----------\n", "output": "NO\n"}, {"input": "oooo--\n", "output": "NO\n"}, {"input": "o-ooooo\n", "output": "NO\n"}, {"input": "-oo\n", "output": "NO\n"}, {"input": "ooooo-\n", "output": "NO\n"}, {"input": "ooo---------\n", "output": "YES\n"}, {"input": "oo-\n", "output": "NO\n"}, {"input": "---ooo\n", "output": "YES\n"}] |
|
237 | n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have.
Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?
-----Input-----
The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 10^9, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.
-----Output-----
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
-----Examples-----
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
-----Note-----
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.
In the second example Frodo can take at most four pillows, giving three pillows to each of the others.
In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed. | interview | [{"code": "n, m, k = map(int, input().split())\nans = 1\nm -= n\nleft = k - 1\nright = n - k\n\nput = 1\nwhile (m >= put):\n m -= put\n ans += 1\n put += (left > 0) + (right > 0)\n if (left): left -= 1\n if (right): right -= 1\n if (left == right == 0):\n ans += (m // put)\n break\nprint(ans)", "passed": true, "time": 0.27, "memory": 14332.0, "status": "done"}, {"code": "def v(ln, mx):\n return mx * (mx + 1) // 2 - (0 if ln > mx else (mx - ln) * (mx - ln + 1) // 2) + max(0, ln - mx)\n\ndef ok(n, m, k, val):\n return val + v(k - 1, val - 1) + v(n - k, val - 1) <= m\n\n\nn, m, k = map(int, input().split())\nl = -1\nr = 10 ** 10\nwhile l + 1 != r:\n md = (l + r) // 2\n if ok(n, m, k, md):\n l = md\n else:\n r = md\nprint(l)", "passed": true, "time": 0.25, "memory": 14496.0, "status": "done"}, {"code": "def f(med):\n left = k - 1\n right = n - k\n #print(med, left, right)\n ans = 0\n if med > left + 1:\n d = med - left\n ans += (med + d) * (med - d + 1) // 2\n else:\n ans += med * (med + 1) // 2\n left -= (med - 1)\n ans += left\n #print(ans)\n if med > right + 1:\n d = med - right\n ans += (med + d) * (med - d + 1) // 2\n else:\n ans += med * (med + 1) // 2\n right -= (med - 1)\n ans += right\n #print(ans)\n if ans - med <= m:\n return True\n else:\n return False\n\nn, m, k = list(map(int, input().split()))\nl = 1\nr = m + 1\nwhile r - l > 1:\n med = (r + l) // 2\n if f(med):\n l = med\n else:\n r = med\nprint(l)\n", "passed": true, "time": 0.14, "memory": 14544.0, "status": "done"}, {"code": "\ndef __starting_point():\n\tn, m, k = map(int, input().split())\n\tm -= n\n\tres = 1\n\tlvl = 0\n\twhile m > 0:\n\t\t#print(m)\n\t\tx = min(k, lvl+1) + min(n-k, lvl)\n\t\tif (x == n):\n\t\t\tres += m // n\n\t\t\tbreak\n\t\telif (m >= x):\n\t\t\tm -= x\n\t\t\tlvl += 1\n\t\t\tres += 1\n\t\telse:\n\t\t\tbreak\n\tprint(res)\n__starting_point()", "passed": true, "time": 1.29, "memory": 14508.0, "status": "done"}, {"code": "def summ(t):\n ans = (t) * (t + 1) // 2\n return ans\n\nn, m, k = map(int, input().split())\n\ndef res(p):\n nonlocal n\n tmp = n * p\n l = k - 1\n t = min(p - 1, l)\n tmp -= summ(t)\n tmp -= (p - 1) * (l - t)\n r = n - k\n t = min(p - 1, r)\n tmp -= summ(t)\n tmp -= (p - 1) * (r - t)\n return tmp\n\n\nl = 0\nr = m + 1\nwhile r - l > 1:\n mid = l + (r - l) // 2\n if res(mid) <= m:\n l = mid\n else:\n r = mid\nprint(l)", "passed": true, "time": 0.15, "memory": 14300.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\n\ndone = 0\n\nfor A in range(m // n,m+1):\n\n\tup = A\n\n\tif (k-1) >= (A-1):\n\t\tup = up + A * (A-1) / 2\n\t\tup = up + k - A\n\telse:\n\t\ts = A - k + 1\n\t\tup = up + (s + (A - 1)) * (A - s) / 2\n\n\n\tkk = n - k \n\n\tif (kk) >= (A-1):\n\t\tup = up + A * (A-1) / 2\n\t\tup = up + kk - (A-1)\n\telse:\n\t\ts = A - kk\n\t\tup = up + (s + (A - 1)) * (A - s) / 2\n\n\tif up > m:\n\t\tdone = 1\n\t\tprint(A-1)\n\t\tbreak\n\n\nif done == 0:\n\n\tprint(m)", "passed": true, "time": 0.36, "memory": 14408.0, "status": "done"}, {"code": "def f(a):\n sums1=0\n sums2=0\n if k >=a:\n sums1 = a*(a+1)//2\n sums1+=k-a\n else:\n sums1 = k*(a+a-k+1)//2\n \n sums3 =0\n sums4=0\n k1 = n-k+1\n if k1 >=a:\n sums2 = a*(a+1)//2\n sums2 +=k1-a\n else:\n sums2 = k1*(a+a-k1+1)//2 \n if sums1+sums2-a<=m:\n return True\n else:\n return False\nn,m,k = map(int,input().split())\nleft = 1\nright = 10**9+5\n\nwhile left+1!=right:\n mid = (left+right)//2\n if f(mid):\n left=mid\n else:\n right = mid\nif f(right):\n print(right)\nelse:\n print(left)", "passed": true, "time": 0.14, "memory": 14516.0, "status": "done"}, {"code": "\n\ndef pillows_needed(height, width):\n if height > width:\n return height * (height + 1) // 2 - (height - width) * (height - width + 1) // 2\n else:\n return height * (height + 1) // 2 + (width - height)\n\nn, m, k = list(map(int, input().split()))\n\n\na, b, c = 0, m, 0\n\nwhile a < b:\n c = (a + b + 1) // 2\n if m >= c + pillows_needed(c - 1, n - k) + pillows_needed(c - 1, k - 1):\n a = c\n else:\n b = c - 1\n\nprint(a)\n", "passed": true, "time": 0.15, "memory": 14576.0, "status": "done"}, {"code": "def pillows(n, k, h):\n p = (h - 1) * h + h\n left = 0\n if k < h:\n left = (h - k) * (h - k + 1) // 2\n right = 0\n if n - k + 1 < h:\n right = (h - (n - k + 1)) * (h - (n - k + 1) + 1) // 2\n\n return p - left - right\n\n\ndef solve(n, m, k):\n p = m - n\n if p == 0:\n return 1\n\n l = 0\n r = 10**10\n while r - l >= 2:\n m = (l + r) // 2\n mp = pillows(n, k, m)\n if mp > p:\n r = m\n else:\n l = m\n\n return l + 1\n\nif False:\n assert pillows(1, 1, 10) == 10\n assert solve(1, 10, 1) == 10\n assert solve(5, 5, 1) == 1\n assert solve(5, 5, 5) == 1\n assert solve(5, 5, 3) == 1\n assert solve(5, 6, 2) == 2\n assert solve(5, 6, 1) == 2\n assert solve(5, 6, 5) == 2\n assert solve(5, 7, 5) == 2\n assert solve(5, 7, 1) == 2\n assert solve(5, 8, 1) == 3\n assert solve(5, 8, 5) == 3\n assert solve(5, 8, 4) == 2\n assert solve(5, 8, 2) == 2\n assert solve(5, 8, 3) == 2\n assert solve(5, 9, 3) == 3\n assert solve(5, 9, 2) == 3\n assert solve(5, 9, 1) == 3\n\nelse:\n n, m, k = list(map(int, input().split()))\n print(solve(n, m, k))\n", "passed": true, "time": 0.14, "memory": 14624.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\nleft = 0\nright = 10000000000\nwhile (right - left > 1):\n mid = (left + right) // 2\n counter = mid\n lh = k - 1\n if lh >= mid - 1:\n counter += (mid - 1) * mid // 2\n counter += lh - (mid - 1)\n else:\n last_hobbit = mid - lh - 1\n counter += (mid - 1) * mid // 2 - (last_hobbit) * (last_hobbit + 1) // 2\n rh = n - k\n if rh >= mid - 1:\n counter += (mid - 1) * mid // 2\n counter += rh - (mid - 1)\n else:\n last_hobbit = mid - rh - 1\n counter += (mid - 1) * mid // 2 - (last_hobbit) * (last_hobbit + 1) // 2 \n if counter > m:\n right = mid\n else:\n left = mid\nprint(left)\n \n", "passed": true, "time": 0.17, "memory": 14592.0, "status": "done"}, {"code": "def main():\n\tn, m, k = map(int, input().split())\n\tl = 1\n\tr = 10**10\n\twhile (l + 1 < r):\n\t\tmed = (l + r) // 2\n\t\tcnt = n\n\t\tleft = max(0, med - 1 - (k - 1))\n\t\tright = max(0, med - 1 - (n - k))\n\t\tleft_cord = max(1, k - med + 1)\n\t\tright_cord = min(k + med - 1, n)\n\n\t\tcnt += ((k - left_cord + 1) * (left + med - 1)) / 2\n\t\tcnt += ((right_cord - k + 1) * (right + med - 1)) / 2\n\t\tcnt -= med - 1\n\t\tif (cnt <= m):\n\t\t\tl = med\n\t\telse:\n\t\t\tr = med\n\tprint(l)\n\t\nmain()", "passed": true, "time": 0.14, "memory": 14508.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\n\ndef __sum(n):\n\treturn n * (n + 1) // 2\n\ndef _sum(l, r):\n\tif l > r:\n\t\treturn 0\n\tdelta = 0\n\tif l <= 0:\n\t\tdelta = abs(l) + 1\n\t\tl = 1\n\n\t# print(l, r, __sum(r) - __sum(l - 1))\n\treturn __sum(r) - __sum(l - 1) + delta\n\n\n\nleft = 1\nright = int(1e9) + 2\nwhile right - left > 1:\n\tmid = (left + right) // 2\n\tsub = _sum(mid - k + 1, mid) + _sum(mid - (n - k), mid - 1)\n\tif sub <= m:\n\t\tleft = mid\n\telse:\n\t\tright = mid\n\nprint(left)\n", "passed": true, "time": 0.15, "memory": 14448.0, "status": "done"}, {"code": "def just_sum(n):\n return (n * (n + 1)) // 2\n\n\ndef get_sum(a, b):\n return just_sum(b) - just_sum(a - 1)\n\n\ndef check(middle):\n left = k - 1\n right = n - k\n \n if left < middle:\n left_sum = get_sum(middle - left, middle - 1)\n else:\n left_sum = just_sum(middle - 1) + (left - (middle - 1))\n \n if right < middle:\n right_sum = get_sum(middle - right, middle - 1)\n else:\n right_sum = just_sum(middle - 1) + (right - (middle - 1))\n \n return left_sum + right_sum + middle <= m\n \n \nn, m, k = map(int, input().split())\n\nl = 1\nr = m + 1\nwhile l < r - 1:\n middle = (l + r) // 2\n if check(middle):\n l = middle\n else:\n r = middle\n \nprint(l)", "passed": true, "time": 0.15, "memory": 14404.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\n\nmin_delta = min(k - 1, n - k)\nmax_delta = max(k - 1, n - k)\n\ntop = ((k - 1) * k + (n - k) * (n - k + 1)) // 2 + (max_delta - min_delta) * min_delta + max_delta + 1\n\ndef get_level(n, k, level):\n\treturn 1 + min(level, k - 1) + min(level, n - k)\n\nif top <= m:\n\tprint(max_delta + 1 + (m - top) // n)\nelse:\n\tadd = m - n\n\tcurr_level = 0\n\twhile add >= get_level(n, k, curr_level):\n\t\tadd -= get_level(n, k, curr_level)\n\t\tcurr_level += 1\n\tprint(curr_level + 1)\n\n\n", "passed": true, "time": 0.53, "memory": 14356.0, "status": "done"}, {"code": "\n\ndef check(n, m, k, r):\n a = r - k\n u = 0\n if a > 0:\n u += (a + r) * (k + 1) // 2\n else:\n u += r * (r + 1) // 2\n\n b = r - (n - 1 - k)\n v = 0\n if b > 0:\n v += (b + r) * (n - k) // 2\n else:\n v += r * (r + 1) // 2\n\n t = u + v - r\n return t <= m\n\nn, m, k = list(map(int, input().split()))\nk -= 1\nm -= n\nINF = 10 ** 9 + 10\na = 0\nb = INF\nwhile b - a > 1:\n mid = (a + b) // 2\n if check(n, m, k, mid):\n a = mid\n else:\n b = mid\nres = 1 + a\nprint(res)\n", "passed": true, "time": 0.14, "memory": 14584.0, "status": "done"}, {"code": "q,w,e=list(map(int,input().split()))\nw-=q\nz=e-1\nx=q-e\nz,x=min(z,x),max(z,x)\nans=1\nt=1\nwhile (w-t)>=0:\n w-=t\n ans+=1\n if z==x==0:\n ans+=w//t\n break\n if z>0:\n z-=1\n t+=1\n if x>0:\n x-=1\n t+=1\nprint(ans)\n", "passed": true, "time": 0.29, "memory": 14496.0, "status": "done"}, {"code": "n,m,k=list(map(int,input().split()))\ns=0\nm-=n\ns+=1\nif m==0:\n print(1)\n return\nwhile m>=0:\n if k>s and n-k+1>s and m>=2*(s-1)+1:\n m-=2*(s-1)+1\n elif k>s and m>=n-k+s:\n m-=n-k+s\n elif n-k+1>s and m>=k+s-1:\n m-=k+s-1\n elif m>=n:\n s+=m//n\n m-=n*(m//n)\n print(s)\n return\n else:\n break\n s+=1\nprint(s)\n", "passed": true, "time": 0.56, "memory": 14368.0, "status": "done"}, {"code": "import sys\n\ndef sum_(a):\n return max(0, a * (a + 1) // 2)\n\ndef check(a):\n if a * n <= m:\n return 1\n a -= 1\n ans = n\n t1 = a - k + 1\n #print(a)\n if t1 >= 0:\n ans += sum_(a) - sum_(t1 - 1)\n else:\n ans += sum_(a)\n #print(ans)\n z = n - k + 1\n t2 = a - z + 1\n #print('ts', t2)\n if t2 >= 0:\n ans += sum_(a - 1) - sum_(t2 - 1)\n else:\n ans += sum_(a - 1)\n #print(ans)\n return (ans <= m)\n\ndef bins():\n l = 1\n r = m + 1\n while l + 1 != r:\n m1 = (l + r) // 2\n if check(m1):\n l = m1\n else:\n r = m1\n print(l)\n \nn, m, k = list(map(int, input().split()))\n#print(check(2))\nbins()\n\n \n", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\nkk1 = min(k-1, n-k)\nkk2 = n - kk1 - 1\nmm = m - n\ns1 = (kk1 + 1)**2\nif s1 >= mm:\n res = 1 + int(mm**0.5)\nelse:\n res = 1 + (kk1 + 1)\n mmm = mm - s1 \n a = 2*(kk1 + 1)\n b = kk2-kk1 - 1\n s2 = a*b + b*(b-1)//2\n if s2 >= mmm:\n res += int(-(2*a-1)/2 + (((2*a-1)/2)**2 + 2*mmm)**0.5)\n else:\n mmmm = mmm - s2 \n res += b + mmmm//n\nprint(res) ", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "n,m,k = list(map(int,input().split()))\nl, r = 1, 10 ** 9 + 1\n\ndef ok(p):\n rs = 0\n if k >= p:\n rs += p * (p + 1) // 2\n rs += (k - p)\n else:\n rs += p * (p + 1) // 2\n f = p - k\n rs -= f * (f + 1) // 2\n if (p - 1) <= n - k:\n rs += p * (p - 1) // 2\n rs += n - k - p + 1\n else:\n rs += p * (p - 1) // 2\n f = (p - 1) - (n - k)\n rs -= f * (f + 1) // 2\n return rs <= m\n\nwhile r - l > 1:\n mid = (l + r) // 2\n if ok(mid):\n l = mid\n else:\n r = mid\nprint(l)", "passed": true, "time": 0.15, "memory": 14308.0, "status": "done"}, {"code": "import sys\nimport math\n\nn, m, k = map(int, input().split())\n\nans = 1\nm -= n\nl = min(k - 1, n - k)\nstep = 1\n\nfor i in range(l):\n if m - step < 0:\n print(ans)\n return\n\n m -= step\n step += 2\n ans += 1\n\nwhile step < n:\n if m - step < 0:\n print(ans)\n return\n\n m -= step\n step += 1\n ans += 1\n\nans += m // n\n\nprint(ans)", "passed": true, "time": 0.21, "memory": 14524.0, "status": "done"}, {"code": "def v(length, start):\n W = start * (start + 1) // 2\n t = max(0, start - length)\n T = t * (t + 1) // 2\n return W - T + max(0, length - start)\n \n\ndef check(p):\n return p + v(k - 1, p - 1) + v(n - k, p - 1) <= m\n\nn, m, k = map(int, input().split())\nl = 0\nr = 10 ** 100\nwhile r - l > 1:\n mid = (l + r) // 2\n if not check(mid):\n r = mid\n else:\n l = mid\nprint(l)", "passed": true, "time": 0.2, "memory": 14512.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\nbest = 1\nsleva = k - 1\nsprava = n - k\nm -= n\n\nput = 1\n\nwhile (m >= put):\n m -= put\n best+= 1\n put += (sleva > 0) + (sprava > 0)\n if sleva:\n sleva -= 1\n if sprava:\n sprava -= 1\n if sleva == sprava == 0:\n best += (m // put)\n break\n \nprint(best)", "passed": true, "time": 0.25, "memory": 14492.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\np = m - n\nmin_d, max_d = min(abs(n-k+1), k), max(abs(n-k+1), k)\ni = 1\nr = m+1\nl = 0\nwhile r - l > 1:\n i = (r + l) // 2\n min_dist = min_d-i\n max_dist = max_d-i\n min_summ = 0\n max_summ = 0\n if min_dist < 0:\n min_summ = (abs(min_dist)*(abs(min_dist)+1))\n if max_dist < 0:\n max_summ = (abs(max_dist)*(abs(max_dist)+1))\n summ = ((i*(i+1)) - i)*2 - min_summ - max_summ\n #if min_dist < 0 and max_dist < 0:\n # print()\n # return\n #if min_dist < 0 and max_dist < 0:\n #summ += i\n #print(min_summ, max_summ, (i*(i+1)-i))\n #print(i, summ, min_dist, max_dist)\n if summ > p*2:\n r = i\n else:\n l = i\n \nprint(r)\n", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}] | [{"input": "4 6 2\n", "output": "2\n"}, {"input": "3 10 3\n", "output": "4\n"}, {"input": "3 6 1\n", "output": "3\n"}, {"input": "3 3 3\n", "output": "1\n"}, {"input": "1 1 1\n", "output": "1\n"}, {"input": "1 1000000000 1\n", "output": "1000000000\n"}, {"input": "100 1000000000 20\n", "output": "10000034\n"}, {"input": "1000 1000 994\n", "output": "1\n"}, {"input": "100000000 200000000 54345\n", "output": "10001\n"}, {"input": "1000000000 1000000000 1\n", "output": "1\n"}, {"input": "1000000000 1000000000 1000000000\n", "output": "1\n"}, {"input": "1000000000 1000000000 500000000\n", "output": "1\n"}, {"input": "1000 1000 3\n", "output": "1\n"}, {"input": "100000000 200020000 54345\n", "output": "10001\n"}, {"input": "100 108037 18\n", "output": "1115\n"}, {"input": "100000000 200020001 54345\n", "output": "10002\n"}, {"input": "200 6585 2\n", "output": "112\n"}, {"input": "30000 30593 5980\n", "output": "25\n"}, {"input": "40000 42107 10555\n", "output": "46\n"}, {"input": "50003 50921 192\n", "output": "31\n"}, {"input": "100000 113611 24910\n", "output": "117\n"}, {"input": "1000000 483447163 83104\n", "output": "21965\n"}, {"input": "10000000 10021505 600076\n", "output": "147\n"}, {"input": "100000000 102144805 2091145\n", "output": "1465\n"}, {"input": "1000000000 1000000000 481982093\n", "output": "1\n"}, {"input": "100 999973325 5\n", "output": "9999778\n"}, {"input": "200 999999109 61\n", "output": "5000053\n"}, {"input": "30000 999999384 5488\n", "output": "43849\n"}, {"input": "40000 999997662 8976\n", "output": "38038\n"}, {"input": "50003 999999649 405\n", "output": "44320\n"}, {"input": "100000 999899822 30885\n", "output": "31624\n"}, {"input": "1000000 914032367 528790\n", "output": "30217\n"}, {"input": "10000000 999617465 673112\n", "output": "31459\n"}, {"input": "100000000 993180275 362942\n", "output": "29887\n"}, {"input": "1000000000 1000000000 331431458\n", "output": "1\n"}, {"input": "100 10466 89\n", "output": "144\n"}, {"input": "200 5701 172\n", "output": "84\n"}, {"input": "30000 36932 29126\n", "output": "84\n"}, {"input": "40000 40771 22564\n", "output": "28\n"}, {"input": "50003 51705 49898\n", "output": "42\n"}, {"input": "100000 149408 74707\n", "output": "223\n"}, {"input": "1000000 194818222 998601\n", "output": "18389\n"}, {"input": "10000000 10748901 8882081\n", "output": "866\n"}, {"input": "100000000 106296029 98572386\n", "output": "2510\n"}, {"input": "1000000000 1000000000 193988157\n", "output": "1\n"}, {"input": "100 999981057 92\n", "output": "9999852\n"}, {"input": "200 999989691 199\n", "output": "5000046\n"}, {"input": "30000 999995411 24509\n", "output": "43846\n"}, {"input": "40000 999998466 30827\n", "output": "37930\n"}, {"input": "50003 999997857 48387\n", "output": "43163\n"}, {"input": "100000 999731886 98615\n", "output": "43371\n"}, {"input": "1000000 523220797 654341\n", "output": "22853\n"}, {"input": "10000000 999922591 8157724\n", "output": "31464\n"}, {"input": "100000000 999834114 93836827\n", "output": "29998\n"}, {"input": "1000000000 1000000000 912549504\n", "output": "1\n"}, {"input": "1000 97654978 234\n", "output": "97976\n"}, {"input": "1000 97654977 234\n", "output": "97975\n"}, {"input": "1000234 97653889 1\n", "output": "13903\n"}, {"input": "1000234 97653890 1\n", "output": "13904\n"}, {"input": "3450234 97656670 3000000\n", "output": "9707\n"}, {"input": "3450234 97656669 3000000\n", "output": "9706\n"}, {"input": "3 1000000000 2\n", "output": "333333334\n"}, {"input": "2 1000000000 1\n", "output": "500000000\n"}, {"input": "2 1000000000 2\n", "output": "500000000\n"}, {"input": "3 1000000000 1\n", "output": "333333334\n"}, {"input": "3 1000000000 3\n", "output": "333333334\n"}, {"input": "2 999999999 1\n", "output": "500000000\n"}, {"input": "2 999999999 2\n", "output": "500000000\n"}, {"input": "1 999999999 1\n", "output": "999999999\n"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.