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
238
You are given an array $a_1, a_2, \dots , a_n$ and two integers $m$ and $k$. You can choose some subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$. The cost of subarray $a_l, a_{l+1}, \dots, a_{r-1}, a_r$ is equal to $\sum\limits_{i=l}^{r} a_i - k \lceil \frac{r - l + 1}{m} \rceil$, where $\lceil x \rceil$ is the least integer greater than or equal to $x$. The cost of empty subarray is equal to zero. For example, if $m = 3$, $k = 10$ and $a = [2, -4, 15, -3, 4, 8, 3]$, then the cost of some subarrays are: $a_3 \dots a_3: 15 - k \lceil \frac{1}{3} \rceil = 15 - 10 = 5$; $a_3 \dots a_4: (15 - 3) - k \lceil \frac{2}{3} \rceil = 12 - 10 = 2$; $a_3 \dots a_5: (15 - 3 + 4) - k \lceil \frac{3}{3} \rceil = 16 - 10 = 6$; $a_3 \dots a_6: (15 - 3 + 4 + 8) - k \lceil \frac{4}{3} \rceil = 24 - 20 = 4$; $a_3 \dots a_7: (15 - 3 + 4 + 8 + 3) - k \lceil \frac{5}{3} \rceil = 27 - 20 = 7$. Your task is to find the maximum cost of some subarray (possibly empty) of array $a$. -----Input----- The first line contains three integers $n$, $m$, and $k$ ($1 \le n \le 3 \cdot 10^5, 1 \le m \le 10, 1 \le k \le 10^9$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$). -----Output----- Print the maximum cost of some subarray of array $a$. -----Examples----- Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0
interview
[{"code": "N, M, K = list(map(int, input().split()))\nA = [int(a) for a in input().split()]\nS = [0]\nfor a in A:\n S.append(S[-1]+M*a-K)\nMI = [(10**50)] * M\nans = 0\nfor i in range(N+1):\n MI[i%M] = min(MI[i%M], S[i])\n for j in range(M):\n ans = max(ans, (S[i]-MI[(i-j)%M] - K*((-j)%M))//M)\nprint(ans)\n\n", "passed": true, "time": 0.14, "memory": 14320.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\nA = list(map(int, input().split()))\nglans = 0\nfor s in range(m):\n B = []\n f = s\n su = 0\n sus = 0\n for i in range(s, n):\n su += A[i]\n sus = max(sus, su)\n if (i + 1) % m == s:\n B.append(sus - k)\n B.append(su - sus)\n su = 0\n sus = 0\n f = i + 1\n dob = 0\n klol = 0\n for j in range(f, n):\n dob += A[j]\n klol = max(klol, dob - k)\n B = [0] + B + [klol]\n for i in range(1, len(B)):\n B[i] += B[i - 1]\n cnt = -10 ** 10\n ans = [0, 0]\n minsum = 10 ** 10\n candidat = 0\n for i in range(len(B)):\n if B[i] - minsum > cnt:\n cnt = B[i] - minsum\n ans[1] = i\n ans[0] = candidat\n if B[i] <= minsum:\n minsum = B[i]\n candidat = i\n glans = max(glans, B[ans[1]] - B[ans[0]])\nprint(glans)", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "n,m,k = [int(w) for w in input().split()]\na = [int(w) for w in input().split()]\n\ndef f(o):\n r = e = 0\n for i, x in enumerate(a):\n if i < o:\n continue\n if i % m == o:\n e -= k\n if e < -k:\n e = -k\n e += x\n if e > r:\n r = e\n return r\n\nprint(max(f(o) for o in range(m)))\n", "passed": true, "time": 0.16, "memory": 14256.0, "status": "done"}, {"code": "import math\n\nn, m, k = list(map(int, input().split()))\narr = list(map(int, input().split()))\n\npart_sum = [0]\nfor i in range(n):\n\tpart_sum.append(part_sum[-1] + arr[i])\n\n# print(part_sum)\n\npart_sum_add = [[] for _ in range(m)]\nmin_in_part_sum_add = [[] for _ in range(m)]\nfor shift in range(m):\n\tcount_blocks = math.ceil((n - shift) / m + 1)\n\tfor i in range(n + 1):\n\t\tcur_part_sum = part_sum[i] + k * (count_blocks - ((i - shift) // m))\n\t\tif i == 0 or cur_part_sum < prev_min_in_part_sum_add:\n\t\t\tcur_min_in_part_sum_add = cur_part_sum\n\t\telse:\n\t\t\tcur_min_in_part_sum_add = prev_min_in_part_sum_add\n\n\t\t# cur_min_in_part_sum_add = part_sum_add[shift][-1] if i == 0 else min(part_sum_add[shift][-1], min_in_part_sum_add[shift][-1])\n\t\tpart_sum_add[shift].append(cur_part_sum)\n\t\tmin_in_part_sum_add[shift].append(cur_min_in_part_sum_add)\n\t\tprev_min_in_part_sum_add = cur_min_in_part_sum_add\n\t# print(shift, part_sum_add[shift], min_in_part_sum_add[shift])\n\nmax_result = 0\nfor i in range(1, n + 1):\n\tcurrent_shift = i % m\n\tcurrent_min = min_in_part_sum_add[current_shift][i]\n\tcurrent_ans = part_sum_add[current_shift][i] - current_min\n\t# print('[{}] shift={} min={} ans={}'.format(i, current_shift, current_min, current_ans))\n\tif current_ans > max_result:\n\t\tmax_result = current_ans\n\nprint(max_result)", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "import sys\n\nn, m, k = list(map(int, sys.stdin.readline().strip().split()))\na = list(map(int, sys.stdin.readline().strip().split()))\nb = [0] * (n+1)\nfor i in range (1, n+1):\n b[i] = b[i-1] + m * a[i-1] - k\nM = [10 ** 20] * m\nans = 0\nfor i in range (0, n+1):\n M[i % m] = min([M[i % m], b[i]])\n for j in range (0, m):\n if i > j:\n ans = max([ans, b[i]-M[j]-k*((m*i+m-(i-j))%m)])\n # print(j, M, ans)\nprint(ans // m)\n", "passed": true, "time": 0.15, "memory": 14376.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\nfrom itertools import accumulate\nimport copy\n\nn,m,k = list(map(int,input().split()))\nA = list(map(int,input().split()))\nANS = 0\n\nfor i in range(m):\n B = copy.deepcopy(A)\n\n for j in range(i,n,m):\n B[j] -= k\n\n SUM = list(accumulate(B))\n SUMMIN = [float(\"inf\")]*n +[0]\n\n if i==0:\n SUMMIN[0] = 0\n\n for j in range(max(1,i),n):\n if j % m == i % m:\n SUMMIN[j] = min(SUMMIN[j-1],SUM[j-1])\n else:\n SUMMIN[j] = SUMMIN[j-1]\n\n for j in range(i,n):\n ANS = max(ANS,SUM[j] - SUMMIN[j])\n\nprint(ANS)\n\n \n \n", "passed": true, "time": 0.16, "memory": 14492.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\nn,m,k=list(map(int,input().split()))\nA=[int(i) for i in input().split()]\nif n<=m:\n AA=[0]*(n+1)\n for i in range(n):\n AA[i+1]=AA[i]+A[i]\n mm=0\n for i in range(n+1):\n for j in range(i+1,n+1):\n mm=max(mm,AA[j]-AA[i]-k)\nelse:\n DP=[[0]*(m+1) for _ in range(n+1)]\n for i in range(n):\n a=A[i]\n DP[i+1][0]=max([DP[i][0],DP[i][m],DP[i][m]+a-k,DP[i][1]])\n DP[i+1][1]=max(a-k,DP[i][m]+a-k)\n for j in range(2,m+1):\n DP[i+1][0]=max(DP[i+1][0],DP[i][j])\n if j>i+1:\n continue\n else:\n DP[i+1][j]=max(DP[i][j-1]+a,DP[i][m]+a-k)\nprint(max(A[0]-k,0) if n==1 else mm if n<=m else max(0,max(DP[n])))\n", "passed": true, "time": 0.16, "memory": 14544.0, "status": "done"}, {"code": "import copy\n\nn,m,k=list(map(int,input().split()))\nA=list(map(int,input().split()))\n\nANS=0\n\nfor i in range(m):\n B=copy.deepcopy(A)\n for j in range(i,n,m):\n B[j]-=k\n\n NOW=0\n\n for j in range(i,n):\n if j%m==i:\n NOW=max(NOW+B[j],B[j])\n else:\n NOW+=B[j]\n\n ANS=max(ANS,NOW)\n\nprint(ANS)\n \n \n", "passed": true, "time": 0.24, "memory": 14292.0, "status": "done"}, {"code": "from sys import stdin, stdout, exit\n\nn, m, k = list(map(int, stdin.readline().split()))\na = list(map(int, stdin.readline().split()))\n\ndef bf(a):\n best = 0\n best_arg = (-1, -1)\n for i in range(n):\n for j in range(i, n):\n cur = sum(a[i:j+1]) - k*((j - i) // m + 1)\n if cur > best:\n best = max(best, cur)\n best_arg = (i,j)\n return best, best_arg\n\ndef max_sum(a):\n if len(a) == 0:\n return 0\n elif len(a) == 1:\n return max(0, a[0] - k)\n mid = len(a) // 2\n l_rec = max_sum(a[:mid])\n r_rec = max_sum(a[mid:])\n l_bests = [0]*m\n r_bests = [0]*m\n l_sum = 0\n for idx in range(1,mid+1):\n l_sum += a[mid-idx]\n if idx % m == 0:\n l_sum -= k\n l_bests[idx%m] = max(l_bests[idx%m], l_sum)\n r_sum = 0\n for idx in range(0, len(a)-mid):\n r_sum += a[idx+mid]\n if (idx+1) % m == 0:\n r_sum -= k\n r_bests[(idx+1)%m] = max(r_bests[(idx+1)%m], r_sum)\n\n # print(\"Array:\", a, \"mid:\", mid)\n# print(l_bests)\n # print(r_bests)\n best_acr = 0\n for i in range(m):\n for j in range(m):\n best_acr = max(best_acr, l_bests[i] + r_bests[j] - (k if i+j>0 else 0) - (k if i+j>m else 0))\n ans = max(l_rec,r_rec, best_acr)\n # print(\"Answer:\", ans)\n return ans\n\n\nans = max_sum(a)\nstdout.write(str(ans) + \"\\n\")\n#stdout.write(str(bf(a))+\"\\n\")\n", "passed": true, "time": 0.16, "memory": 14436.0, "status": "done"}, {"code": "n, m, k = [int(i) for i in input().split()]\nA = [int(i) for i in input().split()]\n\nbestbest = 0\n\ndef brute(n, m, k, A):\n ans = 0\n val = (0, 0)\n for i in range(n):\n for j in range(i, n):\n if ans < sum(A[i:j+1]) - k*(ceil((j-i+1)/m)):\n ans = sum(A[i:j+1]) - k*(ceil((j-i+1)/m))\n val = (i, j)\n return val, ans\n\nfor off in range(m):\n B = A[off:]\n C = []\n canstart = []\n for i in range(len(B)):\n if i%m == 0:\n C.append(-k)\n canstart.append(1)\n canstart.append(0)\n C.append(B[i])\n\n best = 0\n run = 0\n\n for i in range(len(C)):\n run += C[i]\n if run < -k:\n run = -k\n best = max(best, run)\n #print(best, C)\n bestbest = max(bestbest, best)\n\nprint(bestbest)\n", "passed": true, "time": 0.15, "memory": 14400.0, "status": "done"}, {"code": "def max_subarray(A):\n max_ending_here = max_so_far = A[0]\n for x in A[1:]:\n max_ending_here = max(x, max_ending_here + x)\n max_so_far = max(max_so_far, max_ending_here)\n return max_so_far\n \nans = 0\nn, m, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nfor i in range(m):\n li = a[0:i] + [-k]\n s = 0\n while True:\n li += a[i+s:min(i+m+s, len(a))]\n li += [-k]\n if i+m+s >= len(a):\n break\n s += m\n ans = max(max_subarray(li) - k,ans)\nprint(ans)\n\n", "passed": true, "time": 0.14, "memory": 14440.0, "status": "done"}, {"code": "\ndef __starting_point():\n n, m, k = list(map(int, input().split()))\n aa = list(map(int,input().split()))\n ans = 0\n for start in range(m):\n ac = aa[:]\n for i in range(start, n, m):\n ac[i] -= k\n cur = 0\n for i in range(start, n):\n if i%m == start:\n cur = max(ac[i] + cur, ac[i])\n else:\n cur += ac[i]\n ans = max(cur, ans)\n print(ans)\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14356.0, "status": "done"}, {"code": "# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!\n# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!\n# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!\n# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!\n# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!\n# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!\n# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!\n# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!\nfrom sys import stdin, stdout\nimport collections\n \n#T = int(input())\n \n#W,H = [int(x) for x in stdin.readline().split()]\n#arr = [int(x) for x in stdin.readline().split()]\n \n#s = input()\n#N = len(s)\n \nN,M,K = [int(x) for x in stdin.readline().split()]\narr = [int(x) for x in stdin.readline().split()]\n \n\n\nres = 0\nfor j in range(M):\n s = 0\n mini = 0\n for i in range(j,N):\n if i%M==j:\n mini = min(mini,s)\n s -= K\n \n s += arr[i]\n \n res = max(res,s-mini)\n \nprint(res)\n\n", "passed": true, "time": 0.25, "memory": 14496.0, "status": "done"}, {"code": "base = 1000000007\nn , m , k = map(int,input().split())\na = list(map(int,input().split()))\nmx = 0\ns = 0\ndp = []\ndd= []\nfor j in range(m):\n for i in range(n+1):\n dp.append(base)\n dd.append(0)\n for i in range(n):\n dd[i+1]=dd[i]+a[i]-k*(i % m== j)\n dp[i+1] = min(dd[i],dp[i])\n #print(dd)\n #print(dp)\n if (i % m == j):\n mx = max ( mx , dd[i+1]-dp[i+1])\nprint(mx)", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "'''input\n5 3 10\n1 2 10 2 3\n'''\nimport math\ndef max_sub(arr,n):\n\tdp = [0]*n\n\tdp[0] = arr[0]\n\tfor i in range(1,n):\n\t\tdp[i] = max(dp[i-1]+arr[i],arr[i])\n\treturn max(0,max(dp))\nn,m,k = map(int,input().split())\narr = list(map(int,input().split()))\nq = -math.inf\ndp = [0]*(300100)\nfor i in range(300100):\n\tdp[i] = [q]*(11)\nif (m==1):\n\tfor i in range(n):\n\t\tarr[i]= arr[i]-k\n\tprint(max_sub(arr,n))\nelse:\n\tfor i in range(n):\n\t\tdp[i][1] = arr[i]-k\n\t\tfor j in range(m):\n\t\t\tif (i-1<0 or dp[i-1][j]==q):\n\t\t\t\tcontinue\n\t\t\tif ((j+1)%m!=1):\n\t\t\t\tdp[i][(j+1)%m] = dp[i-1][j]+arr[i]\n\t\t\telse:\n\t\t\t\tdp[i][(j+1)%m] = max(arr[i]-k,dp[i-1][j]+arr[i]-k)\n\tma=0\n\tfor i in range(n):\n\t\t# s = \"\"\n\t\tfor j in range(m):\n\t\t\t# s+=str(dp[i][j])+\" \"\n\t\t\tma = max(ma,dp[i][j])\n\t\t# print(s)\n\tprint(ma)", "passed": true, "time": 10.47, "memory": 63528.0, "status": "done"}, {"code": "N, M, K = list(map(int, input().split()))\nA = list(map(int, input().split()))\nbv = 0\nfor ms in range(M):\n cv = 0\n for i in range(ms, N):\n v = A[i]\n if i % M == ms:\n v -= K\n cv = max(0, cv)\n cv += v\n bv = max(bv, cv)\nprint(bv)\n", "passed": true, "time": 0.16, "memory": 14476.0, "status": "done"}, {"code": "#Bhargey Mehta (Junior)\n#DA-IICT, Gandhinagar\nimport sys, math, queue\n#sys.stdin = open('input.txt', 'r')\nMOD = 998244353\nsys.setrecursionlimit(1000000)\n\nn, m, k = map(int, input().split())\na = list(map(int, input().split()))\n\ndp = [[-10**20 for i in range(m)] for i in range(n)]\ndp[0][0] = a[0]-k\n\nfor i in range(1, n):\n\tfor j in range(m):\n\t\tif j == 0:\n\t\t\tdp[i][j] = max(dp[i-1][m-1]+a[i], a[i])-k\n\t\telse:\n\t\t\tdp[i][j] = dp[i-1][j-1]+a[i]\n\nans = 0\nfor i in range(n):\n\tans = max(ans, max(dp[i]))\nprint(ans)", "passed": true, "time": 0.24, "memory": 14336.0, "status": "done"}, {"code": "#Bhargey Mehta (Junior)\n#DA-IICT, Gandhinagar\nimport sys, math, queue\n#sys.stdin = open('input.txt', 'r')\nMOD = 998244353\nsys.setrecursionlimit(1000000)\n\nn, m, k = map(int, input().split())\na = list(map(int, input().split()))\n\ndp = [[-10**20 for i in range(m)] for i in range(n)]\n\nfor i in range(n):\n for j in range(min(m, i+1)):\n if j == 0:\n dp[i][j] = max(dp[i-1][m-1]+a[i], a[i])-k\n else:\n dp[i][j] = dp[i-1][j-1]+a[i]\n\nans = 0\nfor i in range(n):\n\tans = max(ans, max(dp[i]))\nprint(ans)", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nsa = [0]*n\n\nans = 0\n\nfor i in range(n):\n sa[i] = a[i] - k\n s = a[i]\n for j in range(i-1, max(-1, i-m-1), -1):\n sa[i] = max(sa[i], sa[j] + s - k)\n s += a[j]\n if i < m:\n sa[i] = max(sa[i], s - k)\n sa[i] = max(sa[i], 0)\n ans = max(ans, sa[i])\n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14536.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\na = list(map(int, input().split()))\nret = 0\nfor i in range(m):\n\tcur = 0\n\tfor j in range(i, n):\n\t\tif j % m == i:\n\t\t\tcur = max(0, cur)\n\t\t\tcur -= k\n\t\tcur += a[j]\n\t\tret = max(ret, cur)\nprint(ret)", "passed": true, "time": 0.14, "memory": 14452.0, "status": "done"}, {"code": "n,m,k = list(map(int,input().split()))\na = list(map(int,input().split()))\ndp = [[float('-inf')]*m for i in range(n)]\ndp[0][0] = a[0]\nfor i in range(1,n):\n for j in range(1,m):\n dp[i][j] = dp[i-1][j-1] + a[i]\n dp[i][0] = max(dp[i-1][m-1]-k, 0)+a[i]\n #if dp[i-1][j] != float()\nprint(max(max([max(x) for x in dp])-k,0)) ", "passed": true, "time": 0.14, "memory": 14456.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()));\na = list(map(int, input().split()));\n\nvalues = list()\n\nfor j in range(n):\n result = a[j];\n sum1 = 0;\n for i in range(m):\n if j-i>=0:\n sum1 = sum1 + a[j-i];\n if sum1 > result:\n result = sum1;\n else:\n continue;\n if j-m>=0:\n result = max(result, sum1 + values[j-m]);\n values.append(max(0, result-k));\nprint((max(values)));\n", "passed": true, "time": 0.16, "memory": 14312.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().strip().split()))\n\na = list(map(int, input().strip().split()))\na = [0] + a\ndp = [0] * 300005\nans = 0\nfor i in range(1, n + 1):\n a[i] += a[i - 1]\n for j in range(1, m + 1):\n if i - j >= 0:\n dp[i] = max(dp[i], a[i] - a[i - j] - k)\n if i - m >= 0:\n dp[i] = max(dp[i], a[i] - a[i - m] + dp[i - m] - k)\n ans = max(ans, dp[i])\n\nprint(ans)\n", "passed": true, "time": 0.3, "memory": 16112.0, "status": "done"}, {"code": "n, m, k = list(map(int, input().split()))\n\na = list(map(int, input().split()))\n\nbest = 0\ndp = [0] * (n + 1)\nfor i in range(n):\n b2 = 0\n for j in range(max(-1, i - m), i + 1):\n b2 = max(b2, dp[j] - k + sum(a[j + 1:i + 1]))\n dp[i] = max(b2, a[i] - k)\n best = max(best, dp[i])\n\nprint(best)\n# print(dp)\n", "passed": true, "time": 0.15, "memory": 14496.0, "status": "done"}]
[{"input": "7 3 10\n2 -4 15 -3 4 8 3\n", "output": "7\n"}, {"input": "5 2 1000\n-13 -4 -9 -20 -11\n", "output": "0\n"}, {"input": "5 10 10\n1000000000 1000000000 1000000000 1000000000 1000000000\n", "output": "4999999990\n"}, {"input": "1 1 1\n2\n", "output": "1\n"}, {"input": "5 10 10\n1000000000 1000000000 -1000000000 1000000000 1000000000\n", "output": "2999999990\n"}, {"input": "6 2 5\n2 2 2 2 2 2\n", "output": "0\n"}, {"input": "1 10 1000000000\n999999999\n", "output": "0\n"}, {"input": "6 6 10\n-1 1000000000 1000000000 1000000000 1000000000 1000000000\n", "output": "4999999990\n"}, {"input": "5 4 10\n1000000000 1000000000 1000000000 1000000000 9\n", "output": "3999999990\n"}, {"input": "5 4 10\n1000000000 1000000000 1 1000000000 1000000000\n", "output": "3999999981\n"}, {"input": "6 5 10\n1 0 0 0 5 6\n", "output": "1\n"}, {"input": "5 3 10\n1 2 10 2 3\n", "output": "5\n"}, {"input": "5 2 9\n2 1 2 10 4\n", "output": "5\n"}, {"input": "7 3 3\n2 2 2 3 -1 -1 -1\n", "output": "4\n"}, {"input": "4 3 10\n3 3 6 7\n", "output": "6\n"}, {"input": "4 2 10\n1 1000 1000 1\n", "output": "1990\n"}, {"input": "52 6 669\n642 20 568 -469 -266 744 -486 639 813 632 -539 -818 464 438 -349 -950 280 -93 -529 -920 -831 462 559 961 -837 -349 -653 849 820 -21 -120 -144 -269 605 -99 -276 -844 54 -276 837 785 -42 -749 796 534 -948 -318 -262 342 -426 -575 183\n", "output": "1673\n"}, {"input": "20 10 1000\n631 -660 -608 -133 -1324 1698 -229 -107 -540 1837 1827 448 -1574 1576 1751 848 -890 213 -442 522\n", "output": "5713\n"}, {"input": "4 3 3\n1 2 3 4\n", "output": "6\n"}, {"input": "20 2 9\n1 -8 -5 -6 -5 -7 8 -2 7 2 -4 0 -1 3 6 8 -8 -9 2 -8\n", "output": "5\n"}, {"input": "5 3 757773391\n-708202672 725600885 714386358 885416061 999472550\n", "output": "1841501578\n"}, {"input": "5 2 2\n1 64 103 -164 13\n", "output": "165\n"}, {"input": "5 2 4\n3 4 5 6 7\n", "output": "14\n"}, {"input": "10 2 1\n-1 8 3 -9 7 5 4 -1 -7 -3\n", "output": "15\n"}, {"input": "15 10 10\n1 2 8 2 6 -2 9 7 9 7 -4 6 2 0 4\n", "output": "39\n"}, {"input": "7 3 10\n1 9 -1 9 9 4 17\n", "output": "27\n"}, {"input": "5 3 4\n1 1 1 7 9\n", "output": "13\n"}, {"input": "15 6 17153\n-28263 14597 4735 1452 -14292 -31177 -20198 247 20554 2438 22266 -4468 -13551 32664 13810\n", "output": "42750\n"}, {"input": "3 7 349078044\n346450461 -151361596 -625105856\n", "output": "0\n"}, {"input": "42 9 460853333\n323861481 622701467 -873400999 658408343 778669784 692090162 -536855569 -568971791 141069853 976448931 702178349 946412568 251299867 45637990 438945856 504996643 33902725 -815383452 -825003302 854426262 -851164757 -799150044 -985979822 -679814718 -301626285 721177185 -457830126 -769806217 215778808 -232808115 -110027967 -607959163 -943650801 -777973009 735775736 -117195663 -397831392 -114273903 408852339 -886059538 -750897112 833959335\n", "output": "4215688994\n"}, {"input": "4 3 3\n1 1 1 2\n", "output": "1\n"}, {"input": "4 2 10\n5 10 10 10\n", "output": "15\n"}, {"input": "10 7 7\n-1 5 5 -8 8 -2 5 6 7 6\n", "output": "23\n"}, {"input": "8 2 2\n7 -6 8 6 7 -4 -9 -4\n", "output": "17\n"}, {"input": "12 1 500000000\n12 39045157 78090314 117135471 156180628 195225785 234270942 273316099 312361256 351406413 390451570 1000000000\n", "output": "500000000\n"}, {"input": "12 3 10\n9 10 10 10 10 10 3 3 3 13 0 0\n", "output": "42\n"}, {"input": "20 4 18\n-6 8 -5 2 -5 8 9 5 0 1 9 -6 0 6 -3 -3 -4 1 0 0\n", "output": "4\n"}, {"input": "4 3 10\n2 20 30 3\n", "output": "43\n"}, {"input": "6 3 7\n10 -4 5 8 8 8\n", "output": "21\n"}, {"input": "4 1 470344322\n81705360 -386468301 -887628688 22906761\n", "output": "0\n"}, {"input": "12 10 907658609\n-194209259 414274888 393675849 878456237 106365458 -731983555 810695417 -273909797 -389852212 -531227416 828543257 41731960\n", "output": "963825685\n"}, {"input": "4 3 2\n1 100 100 100\n", "output": "298\n"}, {"input": "8 3 10\n1 9 -1 9 9 4 17 7\n", "output": "27\n"}, {"input": "4 3 10\n1 11 11 11\n", "output": "23\n"}, {"input": "3 3 2\n-1 1000 -1\n", "output": "998\n"}, {"input": "50 4 30\n23 -33 -90 85 99 38 -40 63 -20 25 33 49 34 -64 48 68 10 50 -38 -11 77 -89 -75 -31 86 68 -90 -28 -60 -71 -53 -37 -86 -57 6 -76 -50 -96 22 8 -29 18 54 79 79 -1 37 35 -5 52\n", "output": "358\n"}, {"input": "6 3 10\n4 0 0 2 5 5\n", "output": "2\n"}, {"input": "5 3 5\n3 0 3 3 3\n", "output": "4\n"}, {"input": "30 6 457506246\n-969121117 617558553 -129415554 304607443 107130946 445638713 224436189 334186220 660301253 -602596009 866988526 -519228763 107776201 459643776 -936500703 -181433899 -877982207 -736482030 -788123194 339761560 -373447196 -280404579 132070889 -8613357 541579575 -861092082 664002743 -498027327 464062613 16247559\n", "output": "1913823788\n"}, {"input": "5 1 10\n-1 -2 -3 -4 -5\n", "output": "0\n"}, {"input": "15 9 10\n1 2 3 4 5 6 10 -17 16 -10 -5 15 15 -15 20\n", "output": "30\n"}, {"input": "30 10 701\n62684 13503 59709 58247 -2946 37536 -35525 -63986 -88876 -3666 -3230 -14139 48440 92198 30628 -37164 82238 28387 -14045 -55610 5422 -91184 69956 -33024 -45254 -55725 25882 25873 59433 -84008\n", "output": "262636\n"}, {"input": "46 3 8132\n-87069 -13299 21975 68314 17889 -6291 21617 -25617 -49430 -29853 53005 -71441 -19437 42706 -15175 70615 -32798 43270 -16466 -58461 -97023 49150 62915 -42788 -22273 34346 -57197 70365 -71500 90645 -68792 -7967 75319 45706 -88665 -50385 87550 -87412 -65222 -2725 40765 -44101 -82127 -79163 -33327 44106\n", "output": "118647\n"}, {"input": "12 10 907658609\n-19420959 414274888 393675849 878456237 106365458 -731983555 810695417 -273909797 -389852212 -531227416 828543257 41731960\n", "output": "963825685\n"}, {"input": "47 2 9677\n10883 -66708 16724 -49642 57909 -53732 81024 77029 22526 -35794 -18204 -19574 1499 -62540 -51119 -59874 65981 -31282 -15193 98997 -54845 23633 96916 -88428 49361 -97121 -24209 -96118 46336 -98765 -98264 -54210 -86800 -37177 69190 -9649 54629 10242 -26690 28718 -72548 2403 -57427 -41639 -58621 66698 -7198\n", "output": "161225\n"}, {"input": "100 9 95\n-49 33 -30 7 43 29 -10 22 -42 -29 28 34 -49 28 33 -41 -42 4 -35 -7 48 -13 -39 -28 -48 -34 30 35 5 -25 4 0 29 48 33 -43 0 19 -5 -2 -39 -2 29 -34 13 -6 38 20 -6 -48 31 -7 2 10 -43 -17 8 48 33 31 -8 46 7 39 -19 26 -31 -40 35 25 28 30 -39 29 9 26 44 -21 33 3 -27 -2 -13 2 23 19 41 -21 34 -18 -16 20 43 -25 32 13 -7 -10 22 -34\n", "output": "109\n"}, {"input": "14 5 17\n41 -15 -47 -59 67 -11 -50 43 -20 31 66 -27 -71 55\n", "output": "103\n"}, {"input": "8 7 6\n15 -16 -9 7 -6 -1 -14 2\n", "output": "9\n"}, {"input": "20 6 88\n40 50 94 31 -67 8 -69 54 66 84 96 -85 53 43 30 24 -68 -99 73 -85\n", "output": "212\n"}, {"input": "4 9 113164398\n295556036 -507915019 -326982322 -518908220\n", "output": "182391638\n"}, {"input": "4 7 219\n-789 -125 -357 -176\n", "output": "0\n"}, {"input": "10 7 46\n27 41 -24 32 25 24 -36 -14 48 -27\n", "output": "79\n"}, {"input": "1 7 159145800\n201321354\n", "output": "42175554\n"}, {"input": "40 9 877169647\n116006513 366294771 -157813159 -36781809 805692362 731481079 217770583 -472673548 -489084560 -296209833 -194483928 -858075383 -290173195 291750625 -820414519 516786419 -450695951 -618132928 -757837884 915884506 853711807 -622799691 333763686 -809051647 -216743160 423809518 -597560349 435932120 -364484175 733886972 345751269 -463264748 378617674 -98147123 -219210294 179773108 -8439174 454095808 -319000468 632720932\n", "output": "1165480693\n"}, {"input": "18 5 170181265\n-961528298 -281699017 -401645735 -697368732 174334773 -57944971 716829060 126008019 -812563037 56039402 629804706 -676146717 98023638 648427010 570074144 -438361317 -497217942 331474787\n", "output": "1146343527\n"}, {"input": "44 2 531595322\n926215961 -385821837 -278841122 -422772006 -509196878 -81824369 -101501043 -33095577 -520514931 402836017 48602657 881104200 -110528684 52550046 -208588735 -814534121 -548420443 410430115 -636402169 -848516069 -70639158 775203498 -679440929 -427359667 33598904 656872639 -225600926 57010433 -686004588 954173921 -183691317 65245783 811865477 -280371354 385569766 -148554605 -6165789 -956818726 -707171951 -616296946 -463546019 152596440 315750998 520478951\n", "output": "584403220\n"}, {"input": "1 7 5983227\n-908030083\n", "output": "0\n"}, {"input": "1 10 1\n-10\n", "output": "0\n"}]
240
Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer kΒ β€” the number of digits in n. Magically, all the numbers were shuffled in arbitrary order while this note was passed to Kate. The only thing that Vasya remembers, is a non-empty substring of n (a substring of n is a sequence of consecutive digits of the number n). Vasya knows that there may be more than one way to restore the number n. Your task is to find the smallest possible initial integer n. Note that decimal representation of number n contained no leading zeroes, except the case the integer n was equal to zero itself (in this case a single digit 0 was used). -----Input----- The first line of the input contains the string received by Kate. The number of digits in this string does not exceed 1 000 000. The second line contains the substring of n which Vasya remembers. This string can contain leading zeroes. It is guaranteed that the input data is correct, and the answer always exists. -----Output----- Print the smalles integer n which Vasya could pass to Kate. -----Examples----- Input 003512 021 Output 30021 Input 199966633300 63 Output 3036366999
interview
[{"code": "import math\nfrom collections import Counter\n\ns = list(map(int, input()))\nsubstr = input().rstrip()\nt = list(map(int, substr))\n\nm = len(s)\nx, y = 0, m\nz = (x + y) // 2\nwhile z != x:\n if z + math.floor(math.log10(z)) + 1 <= m:\n x = z\n else:\n y = z\n z = (x + y)//2\nm1 = z\nk = math.floor(math.log10(m1)) + 1\n\nD = Counter(s)\nD.subtract(list(map(int, str(m1))))\nD.subtract(t)\ntry:\n c1 = min(i for i in range(1, 10) if D[i] > 0)\n c2 = t[0]\n\n D[c1] -= 1\n _prefix = [c1]\n \n for c in range(c2):\n _prefix += [c] * D[c]\n _suffix = []\n for c in range(c2 + 1, 10):\n _suffix += [c] * D[c]\n num = ''.join([str(c2)] * D[c2])\n prefix = ''.join(map(str, _prefix))\n suffix = ''.join(map(str, _suffix))\n\n if c2 == 0:\n print((min(prefix + substr + num + suffix,\n prefix + num + substr + suffix)))\n else:\n D[c1] += 1\n st = []\n for c in range(10):\n st += [c] * D[c]\n print((min(prefix + substr + num + suffix,\n prefix + num + substr + suffix,\n substr + ''.join(map(str, st)))))\nexcept ValueError:\n print(substr + '0'*D[0])\n", "passed": true, "time": 0.15, "memory": 14400.0, "status": "done"}, {"code": "def main():\n s = input()\n if s in (\"01\", \"10\"):\n print(0)\n return\n cnt = [0] * 58\n for j in map(ord, s):\n cnt[j] += 1\n n, s1 = sum(cnt), input()\n for le in range(n - 1, 0, -1):\n if len(str(le)) + le == n:\n break\n for s in s1, str(le):\n for j in map(ord, s):\n cnt[j] -= 1\n res = [''.join([s1] + [chr(i) * a for i, a in enumerate(cnt) if a])] if s1[0] > '0' else []\n for i in range(49, 58):\n if cnt[i]:\n cnt[i] -= 1\n l = [chr(i) * a for i, a in enumerate(cnt) if a]\n l.append(s1)\n res.append(''.join([chr(i)] + sorted(l)))\n break\n print(min(res))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.23, "memory": 14396.0, "status": "done"}, {"code": "import sys\n\ndef main():\n a = sys.stdin.readline().strip()\n b = sys.stdin.readline().strip()\n\n if a == \"01\" or a == \"10\":\n print(\"0\")\n return\n\n cnt = [0] * 256\n for i in map(ord, a):\n cnt[i] += 1\n n = sum(cnt)\n\n l = 0\n for i in range(1, 8):\n if i == len(str(n - i)):\n l = n - i\n break;\n\n for s in b, str(l):\n for i in map(ord, s):\n cnt[i] -= 1\n\n res = [\"\".join([b] + [chr(k) * v for k, v in enumerate(cnt) if v > 0 ])] if b[0] > \"0\" else []\n\n for i in range(ord(\"1\"), ord(\"9\") + 1):\n if cnt[i] > 0:\n cnt[i] -= 1\n others = [chr(k) * v for k, v in enumerate(cnt) if v > 0]\n others.append(b)\n res.append(\"\".join([chr(i)] + sorted(others)))\n break\n\n print(min(res))\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14396.0, "status": "done"}, {"code": "import sys\n\ndef main():\n a = sys.stdin.readline().strip()\n b = sys.stdin.readline().strip()\n\n if a == \"01\" or a == \"10\":\n print(\"0\")\n return\n\n cnt = [0] * 256\n for i in map(ord, a):\n cnt[i] += 1\n n = sum(cnt)\n\n l = 0\n for i in range(1, 8):\n if i == len(str(n - i)):\n l = n - i\n break;\n\n for s in b, str(l):\n for i in map(ord, s):\n cnt[i] -= 1\n\n res = [\"\".join([b] + [chr(k) * v for k, v in enumerate(cnt) if v > 0 ])] if b[0] > \"0\" else []\n\n for i in range(ord(\"1\"), ord(\"9\") + 1):\n if cnt[i] > 0:\n cnt[i] -= 1\n others = [chr(k) * v for k, v in enumerate(cnt) if v > 0]\n others.append(b)\n res.append(\"\".join([chr(i)] + sorted(others)))\n break\n\n print(min(res))\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "a = input()\nb = input()\nd = [0] * 10\nn = 0\nfor j in range(1000100):\n t = str(j)\n if len(t) + j == len(a):\n n = j\nfor x in str(n):\n d[ord(x) - ord('0')] -= 1\nfor x in a:\n d[ord(x) - ord('0')] += 1\nfor x in b:\n d[ord(x) - ord('0')] -= 1\nif sum(d)==0:\n print(b)\nelse:\n A = []\n B = []\n C = []\n D = []\n if b[0] != '0':\n A = list(b)\n for j in range(10):\n for k in range(d[j]):\n A.append(chr(ord('0') + j))\n t = 1\n while t < len(d) and d[t] == 0:\n t += 1\n oo = ord('0')\n if t < len(d):\n B.append(chr(oo+t))\n d[t] -= 1\n for j in range(ord(b[0]) - oo):\n for k in range(d[j]):\n B.append(chr(ord('0') + j))\n B.extend(list(b))\n for j in range(ord(b[0]) - oo, 10):\n for k in range(d[j]):\n B.append(chr(ord('0') + j))\n \n \n C.append(chr(oo+t))\n for j in range(min(ord(b[0]) - oo+1, 10)):\n for k in range(d[j]):\n C.append(chr(ord('0') + j))\n C.extend(list(b))\n for j in range(ord(b[0]) - oo+1, 10):\n for k in range(d[j]):\n C.append(chr(ord('0') + j))\n \n ans = []\n if len(A) > 0:\n ans.append(''.join(A))\n \n if len(B) > 0:\n ans.append(''.join(B))\n \n if len(C) > 0:\n ans.append(''.join(C))\n \n print(min(ans))", "passed": true, "time": 18.57, "memory": 14436.0, "status": "done"}]
[{"input": "003512\n021\n", "output": "30021\n"}, {"input": "199966633300\n63\n", "output": "3036366999\n"}, {"input": "01\n0\n", "output": "0\n"}, {"input": "0000454312911\n9213544\n", "output": "92135440000\n"}, {"input": "13\n3\n", "output": "3\n"}, {"input": "00010454312921\n9213544\n", "output": "100009213544\n"}, {"input": "11317110\n01\n", "output": "1011113\n"}, {"input": "1516532320120301262110112013012410838210025280432402042406224604110031740090203024020012\n0126064\n", "output": "10000000000000000000000012606411111111111111222222222222222222333333334444444455567889\n"}, {"input": "233121122272652143504001162131110307236110231414093112213120271312010423132181004\n0344011\n", "output": "1000000000003440111111111111111111111112222222222222222233333333333444455666778\n"}, {"input": "1626112553124100114021300410533124010061200562040601301\n00612141\n", "output": "10000000000000006121411111111111222222333344445556666\n"}, {"input": "040005088\n0\n", "output": "40000058\n"}, {"input": "420002200110100211206222101201021321440210\n00\n", "output": "1000000000000011111111112222222222223446\n"}, {"input": "801095116\n0\n", "output": "10011569\n"}, {"input": "070421120216020020\n000024\n", "output": "1000000024122227\n"}, {"input": "825083\n0\n", "output": "20388\n"}, {"input": "6201067\n0\n", "output": "100267\n"}, {"input": "34404430311310306128103301112523111011050561125004200941114005444000000040133002103062151514033103\n010215110013511400400140133404\n", "output": "100000000000000000000102151100135114004001401334041111111111111122222233333333333444444455555668\n"}, {"input": "14\n4\n", "output": "4\n"}, {"input": "21\n2\n", "output": "2\n"}, {"input": "204\n4\n", "output": "40\n"}, {"input": "12\n2\n", "output": "2\n"}, {"input": "05740110115001520111222011422101032503200010203300510014413\n000151\n", "output": "100000000000000000001511111111111111222222222333334444555\n"}, {"input": "116051111111001510011110101111111101001111111101111101101\n00111111111\n", "output": "1000000000000011111111111111111111111111111111111111116\n"}, {"input": "1161100\n01110\n", "output": "101110\n"}, {"input": "101313020013110703821620035452130200177115540090000\n002001320\n", "output": "1000000000000002001320111111111222333334555567778\n"}, {"input": "03111100110111111118\n01001111111101111\n", "output": "301001111111101111\n"}, {"input": "01170141\n01114\n", "output": "1001114\n"}, {"input": "0500014440100110264222000342611000102247070652310723\n0003217\n", "output": "10000000000000000032171111112222222233444444566677\n"}, {"input": "111011111101111131113111111111011\n0111111111111111010111111111\n", "output": "1011111111111111101011111111113\n"}, {"input": "11003040044200003323519101102070252000010622902208104150200400140042011224011154237302003323632011235\n0\n", "output": "100000000000000000000000000000000001111111111111111222222222222222222333333333334444444445555566778\n"}, {"input": "111111011110101141110110011010011114110111\n01010111111011111\n", "output": "1000000101011111101111111111111111111114\n"}, {"input": "011010171110\n010110117\n", "output": "1010110117\n"}, {"input": "510017\n0\n", "output": "10017\n"}, {"input": "00111111110114112110011105\n0\n", "output": "100000011111111111111115\n"}, {"input": "320403902031031110003113410860101243100423120201101124080311242010930103200001451200132304400000\n01\n", "output": "1000000000000000000000000000000000011111111111111111111122222222222233333333333334444444456889\n"}, {"input": "125\n15\n", "output": "15\n"}, {"input": "1160190\n110019\n", "output": "110019\n"}, {"input": "11111111111101101111110101011111010101001111001110010011810010110111101101112140110110\n110101100101111101011111111101111111111110111110011111011000111010100111011111000002\n", "output": "110101100101111101011111111101111111111110111110011111011000111010100111011111000002\n"}, {"input": "2206026141112316065224201412118064151200614042100160093001020024005013121010030020083221011\n280060226\n", "output": "10000000000000000000000000111111111111111111111222222222222228006022633333444444455566666\n"}, {"input": "63007511113226210230771304213600010311075400082011350143450007091200\n25\n", "output": "100000000000000000000011111111111112222222533333333444455567777789\n"}, {"input": "142245201505011321217122212\n12521721230\n", "output": "1001111125217212302222445\n"}, {"input": "712\n17\n", "output": "17\n"}, {"input": "11011111111003010101111111111103111\n101111111110110111111011001011111\n", "output": "101111111110110111111011001011111\n"}, {"input": "143213104201201003340424615500135122127119000020020017400111102423312241032010400\n235321200411204201121201304100003\n", "output": "1000000000000001111111111222222223532120041120420112120130410000333334444445567\n"}, {"input": "080001181\n18\n", "output": "10000118\n"}, {"input": "4141403055010511470013300502174230460332129228041229160601006121052601201100001153120100000\n49\n", "output": "10000000000000000000000000000011111111111111111112222222222223333333444444495555556666677\n"}, {"input": "2131\n112\n", "output": "112\n"}, {"input": "0111110011011110111012109101101111101111150011110111110111001\n10110010111111011111111011001101001111111111111110001011012\n", "output": "10110010111111011111111011001101001111111111111110001011012\n"}, {"input": "251137317010111402300506643001203241303324162124225270011006213015100\n3512\n", "output": "1000000000000000001111111111111122222222223333333335124444455566677\n"}, {"input": "12140051050330004342310455231200020252193200\n23012\n", "output": "100000000000001111222222301233333444555559\n"}, {"input": "291\n19\n", "output": "19\n"}, {"input": "11011011000111101111111111081101110001011111101111110111111111011111011011111100111\n1110111111111\n", "output": "100000000000000000011101111111111111111111111111111111111111111111111111111111111\n"}, {"input": "170422032160671323013220212523333410720410110020005012206133500200001015971250190240204004002041\n10010405153200037262043200214001340010615320\n", "output": "1000000000000000100104051532000372620432002140013400106153201111111122222222222233333445567779\n"}, {"input": "210042022032002310001424611003103312001401111120015141083050404330261401411234412400319100212120\n10014121114054\n", "output": "1000000000000000000000000010014121114054111111111111111111222222222222223333333333444444445668\n"}, {"input": "222122228\n2221\n", "output": "22212222\n"}, {"input": "10\n0\n", "output": "0\n"}, {"input": "11007000\n1000\n", "output": "1000001\n"}, {"input": "3323\n32\n", "output": "323\n"}, {"input": "1001016\n1001\n", "output": "100101\n"}, {"input": "50104\n10\n", "output": "1005\n"}, {"input": "2023\n20\n", "output": "202\n"}, {"input": "0001116\n1001\n", "output": "100101\n"}, {"input": "32334\n32\n", "output": "3233\n"}, {"input": "1103\n10\n", "output": "101\n"}, {"input": "023335\n23\n", "output": "23033\n"}, {"input": "111111111110\n1\n", "output": "1111111111\n"}, {"input": "501105\n110\n", "output": "11005\n"}, {"input": "1110006\n1001\n", "output": "100101\n"}]
241
Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in n steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only m. The next day, the engineer's assistant filed in a report with all the m temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers n, m, min, max and the list of m temperatures determine whether you can upgrade the set of m temperatures to the set of n temperatures (that is add n - m temperatures), so that the minimum temperature was min and the maximum one was max. -----Input----- The first line contains four integers n, m, min, max (1 ≀ m < n ≀ 100;Β 1 ≀ min < max ≀ 100). The second line contains m space-separated integers t_{i} (1 ≀ t_{i} ≀ 100) β€” the temperatures reported by the assistant. Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures. -----Output----- If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). -----Examples----- Input 2 1 1 2 1 Output Correct Input 3 1 1 3 2 Output Correct Input 2 1 1 3 2 Output Incorrect -----Note----- In the first test sample one of the possible initial configurations of temperatures is [1, 2]. In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3]. In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3.
interview
[{"code": "def main():\n\tn, m, mn, mx = map(int, input().split())\n\tA = list(map(int, input().split()))\n\ta = min(A)\n\tb = max(A)\n\tif a < mn or b > mx:\n\t\tprint(\"Incorrect\")\n\t\treturn\n\tcnt = 0\n\tif a > mn:\n\t\tcnt += 1\n\tif b < mx:\n\t\tcnt += 1\n\tif m + cnt <= n:\n\t\tprint(\"Correct\")\n\telse:\n\t\tprint(\"Incorrect\")\n\nmain()", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "[n, m, min_t, max_t], t = list(map(int, input().split())), list(map(int, input().split()))\nmin_m, max_m = min(t), max(t)\nif min_m >= min_t and max_m <= max_t and (n - m) >= ((min_m != min_t) + (max_m != max_t)):\n print('Correct')\nelse:\n print('Incorrect')\n", "passed": true, "time": 0.15, "memory": 14456.0, "status": "done"}, {"code": "n, m, min_, max_ = list(map(int, input().split()))\nl = sorted(list(map(int, input().split())))\nif l[0] < min_ or l[-1] > max_:\n print(\"Incorrect\")\nelse:\n if l[-1] < max_:\n l.append(max_)\n if l[0] > min_:\n l.append(min_)\n if len(l) <= n:\n print(\"Correct\")\n else:\n print(\"Incorrect\")\n\n", "passed": true, "time": 0.8, "memory": 14552.0, "status": "done"}, {"code": "n, m, mi, ma = map(int, input().split())\nt = list(map(int, input().split()))\nmit = min(t)\nmat = max(t)\nif (mi <= mit and ma >= mat) and (n - m >= 2 or (n - m >= 1 and (mit == mi or mat == ma)) or (mit == mi and mat == ma)):\n print('Correct')\nelse:\n print('Incorrect')", "passed": true, "time": 0.16, "memory": 14464.0, "status": "done"}, {"code": "n, m, mmin, mmax = map(int, input().split())\ns = list(map(int, input().split()))\ns = sorted(s)\nif s[0] < mmin or s[m - 1] > mmax:\n print(\"Incorrect\")\nelif s[0] == mmin and s[m - 1] == mmax:\n print(\"Correct\")\nelif s[0] != mmin and s[m - 1] != mmax:\n if n - m < 2:\n print(\"Incorrect\")\n else:\n print(\"Correct\")\nelif s[0] != mmin or s[m - 1] != mmax:\n if n - m < 1:\n print(\"Incorrect\")\n else:\n print(\"Correct\")", "passed": true, "time": 0.14, "memory": 14452.0, "status": "done"}, {"code": "n, _, small, big = list(map(int, input().split()))\nm = list(map(int, input().split()))\n\ndiff = n - _\n\nrd = 0\n\nif (max(m) != big):\n rd += 1\nif (min(m) != small):\n rd += 1\n\nif min(m) < small or max(m) > big:\n print('Incorrect')\n return\n\n#print('diff', diff)\n#print('rd', rd)\n#n - vsego\n# m zapisal pomosh\n\nif rd <= diff:\n print('Correct')\nelse:\n print('Incorrect')\n", "passed": true, "time": 0.15, "memory": 14312.0, "status": "done"}, {"code": "n, m, mi, ma = map(int, input().split())\na = sorted(list(map(int, input().split())))\nif n - m >= 2:\n if a[0] >= mi and a[-1] <= ma:\n print('Correct')\n else:\n print('Incorrect')\nelif n - m == 1:\n if (a[0] >= mi and a[-1] == ma) or (a[0] == mi and a[-1] <= ma):\n print('Correct')\n else:\n print('Incorrect')\nelse:\n if a[0] == mi and a[-1] == ma:\n print('Correct')\n else:\n print('Incorrect')", "passed": true, "time": 0.15, "memory": 14352.0, "status": "done"}, {"code": "x = 0\nres = 0\nn, m, mn, mx = list(map(int, input().split()))\nlst = list(map(int, input().split()))\nfor i in range(m):\n if lst[i] < mn or lst[i] > mx:\n res = \"Incorrect\"\n break\n if lst[i] == mn:\n x = 1\n elif lst[i] == mx:\n x = 1\nif res == \"Incorrect\":\n print(res)\nelse:\n if n - m >= 2 - x:\n print(\"Correct\")\n else:\n print(\"Incorrect\")\n", "passed": true, "time": 0.22, "memory": 14392.0, "status": "done"}, {"code": "n,m,minn,maxx=list(map(int,input().split()))\n\nL=list(map(int,input().split()))\n\nr=0\nif(minn not in L):\n L+=[minn]\n r+=1\nif(maxx not in L):\n L+=[maxx]\n r+=1\nvalid=True\n\nfor i in range(m):\n if(L[i]<minn):\n valid=False\n if(L[i]>maxx):\n valid=False\nif(r>n-m or not valid):\n print(\"Incorrect\")\nelse:\n print(\"Correct\")\n", "passed": true, "time": 0.26, "memory": 14544.0, "status": "done"}, {"code": "n, m , minimum, maximum = list(map(int, input().split()))\nlist_of_m = list(map(int, input().split()))\n\nmaxi = max(list_of_m)\nmini = min(list_of_m)\n\nif maxi < maximum and mini > minimum :\n if n - m >= 2:\n print(\"Correct\")\n else:\n print(\"Incorrect\")\nelif maxi == maximum and mini > minimum :\n if n - m >= 1:\n print(\"Correct\")\n else:\n print(\"Incorrect\")\nelif maxi < maximum and mini == minimum :\n if n - m >= 1:\n print(\"Correct\")\n else:\n print(\"Incorrect\")\nelif maxi == maximum and mini == minimum :\n print(\"Correct\")\nelse:\n print(\"Incorrect\")\n", "passed": true, "time": 0.8, "memory": 14368.0, "status": "done"}, {"code": "n, k, s, b = list(map(int, input().split()))\nm = list(map(int, input().split()))\nprint(('Inc' if min(m)<s or max(m)>b or (max(m)!=b)+(min(m)!=s)>n-k else 'C') + 'orrect')\n", "passed": true, "time": 0.14, "memory": 14456.0, "status": "done"}, {"code": "n, m, mi, ma = tuple(map(int, str.split(input())))\nts = tuple(map(int, str.split(input())))\nif max(ts) > ma or min(ts) < mi:\n\n ans = \"Incorrect\"\n\nelse:\n\n count = 2\n if mi in ts:\n\n count -= 1\n\n if ma in ts:\n\n count -= 1\n\n if n - m >= count:\n\n ans = \"Correct\"\n\n else:\n\n ans = \"Incorrect\"\n\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14420.0, "status": "done"}, {"code": "n, m, minn, maxx = map(int, input().split())\na = sorted(list(map(int, input().split())))\ncnt = 0\nif minn != a[0]:\n cnt += 1\nif maxx != a[-1]:\n cnt += 1\nif maxx < a[-1]:\n cnt += 10000000000000000000\nif minn > a[0]:\n cnt += 10000000000000000000\nif n - m >= cnt:\n print(\"Correct\")\nelse:\n print(\"Incorrect\")", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}, {"code": "n, m, a, b = map(int, input().split())\nt = list(map(int, input().split()))\nx, y = min(t), max(t)\nprint('Correct' if a <= x and y <= b and len(t) + int(a < x) + int(y < b) <= n else 'Incorrect')", "passed": true, "time": 1.62, "memory": 14396.0, "status": "done"}, {"code": "n, m, Min, Max = map(int, input().split())\na = list(map(int, input().split()))\nremain = n - m\ncnt = 0\nflag = 0\nfor i in a:\n if i == Min or i == Max:\n cnt += 1\n if i < Min or i > Max:\n flag = -1\ncnt = 2 - cnt\nif flag == -1:\n print(\"Incorrect\")\nelse:\n if n - m >= cnt:\n print(\"Correct\")\n else:\n print(\"Incorrect\")", "passed": true, "time": 0.14, "memory": 14568.0, "status": "done"}, {"code": "(n, m, mi, mx) = map(int, input().split())\na = list(map(int, input().split()))\na.sort()\nif a[0]!=mi:\n m += 1\nif a[-1]!=mx:\n m += 1\nif a[0]<mi:\n m += n+1\nif a[-1]>mx:\n m += n+1\nprint(['Incorrect', 'Correct'][m<=n])", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "R = lambda:map(int, input().split())\nn, m, a, b = R()\nt = list(R())\nprint(\"Incorrect\" if n - m == 1 and min(t) != a and max(t) != b or min(t) < a or max(t) > b else \"Correct\")", "passed": true, "time": 0.23, "memory": 14464.0, "status": "done"}, {"code": "n, m, Min, Max = map(int, input().split())\nt = list(map(int, input().split()))\n\nif min(t) >= Min and max(t) <= Max:\n if m + abs(len({Min,Max} & set(t))-2) <= n:\n print('Correct')\n else:\n print('Incorrect')\nelse:\n print('Incorrect')", "passed": true, "time": 0.17, "memory": 14256.0, "status": "done"}, {"code": "n, m, Min, Max = map(int, input().split())\na = list(map(int, input().split()))\nremain = n - m\ncnt = 0\nflag = 0\nfor i in a:\n if i == Min or i == Max:\n cnt += 1\n if i < Min or i > Max:\n flag = -1\ncnt = 2 - cnt\nif flag == -1:\n print(\"Incorrect\")\nelif n - m >= cnt:\n print(\"Correct\")\nelse:\n print(\"Incorrect\")", "passed": true, "time": 0.14, "memory": 14568.0, "status": "done"}, {"code": "n, m, v1, v2 = list(map(int, input().split()))\nt = list(map(int, input().split()))\nt1, t2 = min(t), max(t)\nif t1 < v1 or t2 > v2:\n print('Incorrect')\nelif (v1 < t1) + (v2 > t2) > n - m:\n print('Incorrect')\nelse:\n print('Correct')\n", "passed": true, "time": 0.17, "memory": 14432.0, "status": "done"}, {"code": "I=lambda:list(map(int,input().split()))\nn,m,N,X=I()\nt=I()\nr=min(t)!=N\nr+=max(t)!=X\nprint(['C','Inc'][m+r>n or min(t)<N or max(t)>X]+'orrect')", "passed": true, "time": 0.15, "memory": 14416.0, "status": "done"}, {"code": "n,m,mn,mx = input().split()\nn,m,mn,mx = int(n),int(m),int(mn),int(mx)\ndiff = n-m\ntem = [int(x) for x in input().split()]\nflag = 0\ncheck = 0\nfor x in tem:\n if x == mn or x == mx:\n flag = 1\n if x<mn or x>mx:\n check = 1\n \n#print(flag,diff)\nif not check:\n if diff >= 2:\n print(\"Correct\")\n elif diff == 1 and flag:\n print(\"Correct\")\n else:\n print(\"Incorrect\")\nelse:\n print(\"Incorrect\")", "passed": true, "time": 0.17, "memory": 14428.0, "status": "done"}, {"code": "n, m, mn, mx = list(map(int, input().split()))\ntemps = list(map(int, input().split()))\nmnt = min(temps)\nmxt = max(temps)\nif mnt < mn or mxt > mx:\n print('Incorrect')\n return\nif n - m > 1:\n print('Correct')\n return\nmnp = mn in temps\nmxp = mx in temps\nif n - m == 1 and (mnp or mxp):\n print('Correct')\nelif mnp and mxp:\n print('Correct')\nelse:\n print('Incorrect')", "passed": true, "time": 0.14, "memory": 14292.0, "status": "done"}, {"code": "\nimport re\nimport inspect\nfrom sys import argv, exit\n\ndef rstr():\n return input()\n\ndef rstrs(splitchar=' '):\n return [i for i in input().split(splitchar)]\n\ndef rint():\n return int(input())\n\ndef rints(splitchar=' '):\n return [int(i) for i in rstrs(splitchar)]\n\ndef varnames(obj, namespace=globals()):\n return [name for name in namespace if namespace[name] is obj]\n\ndef pvar(var, override=False):\n prnt(varnames(var), var)\n\ndef prnt(*args, override=False):\n if '-v' in argv or override:\n print(*args)\n\n# Faster IO\npq = []\ndef penq(s):\n if not isinstance(s, str):\n s = str(s)\n pq.append(s)\n\ndef pdump():\n s = ('\\n'.join(pq)).encode()\n os.write(1, s)\n\ndef __starting_point():\n timesteps, ast, mn, mx = rints()\n to_add = timesteps - ast\n asts = rints()\n for t in asts:\n if t < mn or t > mx:\n print('Incorrect')\n return\n if mn not in asts:\n if to_add == 0:\n print('Incorrect')\n return\n else:\n to_add -= 1\n\n if mx not in asts:\n if to_add == 0:\n print('Incorrect')\n return\n else:\n to_add -= 1\n\n print('Correct')\n\n \n\n__starting_point()", "passed": true, "time": 0.18, "memory": 17464.0, "status": "done"}]
[{"input": "2 1 1 2\n1\n", "output": "Correct\n"}, {"input": "3 1 1 3\n2\n", "output": "Correct\n"}, {"input": "2 1 1 3\n2\n", "output": "Incorrect\n"}, {"input": "3 1 1 5\n3\n", "output": "Correct\n"}, {"input": "3 2 1 5\n1 5\n", "output": "Correct\n"}, {"input": "3 2 1 5\n1 1\n", "output": "Correct\n"}, {"input": "3 2 1 5\n5 5\n", "output": "Correct\n"}, {"input": "3 2 1 5\n1 6\n", "output": "Incorrect\n"}, {"input": "3 2 5 10\n1 10\n", "output": "Incorrect\n"}, {"input": "6 5 3 6\n4 4 4 4 4\n", "output": "Incorrect\n"}, {"input": "100 50 68 97\n20 42 93 1 98 6 32 11 48 46 82 96 24 73 40 100 99 10 55 87 65 80 97 54 59 48 30 22 16 92 66 2 22 60 23 81 64 60 34 60 99 99 4 70 91 99 30 20 41 96\n", "output": "Incorrect\n"}, {"input": "100 50 1 2\n1 1 2 1 1 2 2 1 1 1 1 1 2 2 1 2 1 2 2 1 1 1 2 2 2 1 1 2 1 1 1 1 2 2 1 1 1 1 1 2 1 1 1 2 1 2 2 2 1 2\n", "output": "Correct\n"}, {"input": "100 99 1 2\n2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 2 1 1 2 1 2 2 1 2 1 2 1 2 1 2 2 2 2 1 1 1 1 1 2 1 2 2 1 2 2 2 1 1 1 1 1 2 2 2 2 1 2 2 1 1 1 2 1 1 2 1 1 2 1 2 1 2 1 1 1 1 2 1 1 1 1 1 2 2 2 1 1 1 1 2 2 2 2 1 1 2 2 2\n", "output": "Correct\n"}, {"input": "3 2 2 100\n40 1\n", "output": "Incorrect\n"}, {"input": "3 2 2 3\n4 4\n", "output": "Incorrect\n"}, {"input": "5 2 2 4\n2 2\n", "output": "Correct\n"}, {"input": "5 1 1 4\n1\n", "output": "Correct\n"}, {"input": "9 7 1 4\n4 3 3 2 2 4 1\n", "output": "Correct\n"}, {"input": "9 5 2 3\n4 2 4 3 3\n", "output": "Incorrect\n"}, {"input": "6 3 1 3\n1 4 2\n", "output": "Incorrect\n"}, {"input": "3 2 1 99\n34 100\n", "output": "Incorrect\n"}, {"input": "4 2 1 99\n100 38\n", "output": "Incorrect\n"}, {"input": "5 2 1 99\n100 38\n", "output": "Incorrect\n"}, {"input": "4 2 1 99\n36 51\n", "output": "Correct\n"}, {"input": "7 6 3 10\n5 10 7 7 4 5\n", "output": "Correct\n"}, {"input": "8 6 3 10\n8 5 7 8 4 4\n", "output": "Correct\n"}, {"input": "9 6 3 10\n9 7 7 5 3 10\n", "output": "Correct\n"}, {"input": "16 15 30 40\n36 37 35 36 34 34 37 35 32 33 31 38 39 38 38\n", "output": "Incorrect\n"}, {"input": "17 15 30 40\n38 36 37 34 30 38 38 31 38 38 36 39 39 37 35\n", "output": "Correct\n"}, {"input": "18 15 30 40\n35 37 31 32 30 33 36 38 36 38 31 30 39 32 36\n", "output": "Correct\n"}, {"input": "17 16 30 40\n39 32 37 31 40 32 36 34 56 34 40 36 37 36 33 36\n", "output": "Incorrect\n"}, {"input": "18 16 30 40\n32 35 33 39 34 30 37 34 30 34 39 18 32 37 37 36\n", "output": "Incorrect\n"}, {"input": "19 16 30 40\n36 30 37 30 37 32 34 30 35 35 33 35 39 37 46 37\n", "output": "Incorrect\n"}, {"input": "2 1 2 100\n38\n", "output": "Incorrect\n"}, {"input": "3 1 2 100\n1\n", "output": "Incorrect\n"}, {"input": "4 1 2 100\n1\n", "output": "Incorrect\n"}, {"input": "91 38 1 3\n3 2 3 2 3 2 3 3 1 1 1 2 2 1 3 2 3 1 3 3 1 3 3 2 1 2 2 3 1 2 1 3 2 2 3 1 1 2\n", "output": "Correct\n"}, {"input": "4 3 2 10\n6 3 10\n", "output": "Correct\n"}, {"input": "41 6 4 10\n10 7 4 9 9 10\n", "output": "Correct\n"}, {"input": "21 1 1 9\n9\n", "output": "Correct\n"}, {"input": "2 1 9 10\n10\n", "output": "Correct\n"}, {"input": "2 1 2 9\n9\n", "output": "Correct\n"}, {"input": "8 7 5 9\n6 7 8 5 5 6 6\n", "output": "Correct\n"}, {"input": "3 2 2 8\n7 2\n", "output": "Correct\n"}, {"input": "71 36 1 10\n7 10 8 1 3 8 5 7 3 10 8 1 6 4 5 7 8 2 4 3 4 10 8 5 1 2 8 8 10 10 4 3 7 9 7 8\n", "output": "Correct\n"}, {"input": "85 3 4 9\n4 8 7\n", "output": "Correct\n"}, {"input": "4 3 4 10\n9 10 5\n", "output": "Correct\n"}, {"input": "2 1 1 5\n1\n", "output": "Correct\n"}, {"input": "91 75 1 10\n2 6 9 7 4 9 4 8 10 6 4 1 10 6 5 9 7 5 1 4 6 4 8 2 1 3 5 7 6 9 5 5 8 1 7 1 4 2 8 3 1 6 6 2 10 6 2 2 8 5 4 5 5 3 10 9 4 3 1 9 10 3 2 4 8 7 4 9 3 1 1 1 3 4 5\n", "output": "Correct\n"}, {"input": "10 4 1 8\n7 9 6 6\n", "output": "Incorrect\n"}, {"input": "18 1 3 10\n2\n", "output": "Incorrect\n"}, {"input": "6 2 4 8\n6 3\n", "output": "Incorrect\n"}, {"input": "17 6 2 8\n3 8 6 1 6 4\n", "output": "Incorrect\n"}, {"input": "21 1 5 8\n4\n", "output": "Incorrect\n"}, {"input": "2 1 1 10\n9\n", "output": "Incorrect\n"}, {"input": "2 1 4 8\n5\n", "output": "Incorrect\n"}, {"input": "2 1 1 7\n6\n", "output": "Incorrect\n"}, {"input": "2 1 4 9\n5\n", "output": "Incorrect\n"}, {"input": "2 1 3 8\n7\n", "output": "Incorrect\n"}, {"input": "2 1 5 9\n6\n", "output": "Incorrect\n"}, {"input": "3 2 1 10\n4 9\n", "output": "Incorrect\n"}, {"input": "2 1 4 10\n7\n", "output": "Incorrect\n"}, {"input": "2 1 2 9\n8\n", "output": "Incorrect\n"}, {"input": "2 1 3 9\n3\n", "output": "Correct\n"}, {"input": "3 2 6 7\n6 6\n", "output": "Correct\n"}, {"input": "6 4 1 10\n11 10 9 1\n", "output": "Incorrect\n"}, {"input": "7 6 3 8\n3 4 5 6 7 8\n", "output": "Correct\n"}, {"input": "5 3 1 5\n2 3 4\n", "output": "Correct\n"}]
243
Chouti was tired of the tedious homework, so he opened up an old programming problem he created years ago. You are given a connected undirected graph with $n$ vertices and $m$ weighted edges. There are $k$ special vertices: $x_1, x_2, \ldots, x_k$. Let's define the cost of the path as the maximum weight of the edges in it. And the distance between two vertexes as the minimum cost of the paths connecting them. For each special vertex, find another special vertex which is farthest from it (in terms of the previous paragraph, i.e. the corresponding distance is maximum possible) and output the distance between them. The original constraints are really small so he thought the problem was boring. Now, he raises the constraints and hopes you can solve it for him. -----Input----- The first line contains three integers $n$, $m$ and $k$ ($2 \leq k \leq n \leq 10^5$, $n-1 \leq m \leq 10^5$)Β β€” the number of vertices, the number of edges and the number of special vertices. The second line contains $k$ distinct integers $x_1, x_2, \ldots, x_k$ ($1 \leq x_i \leq n$). Each of the following $m$ lines contains three integers $u$, $v$ and $w$ ($1 \leq u,v \leq n, 1 \leq w \leq 10^9$), denoting there is an edge between $u$ and $v$ of weight $w$. The given graph is undirected, so an edge $(u, v)$ can be used in the both directions. The graph may have multiple edges and self-loops. It is guaranteed, that the graph is connected. -----Output----- The first and only line should contain $k$ integers. The $i$-th integer is the distance between $x_i$ and the farthest special vertex from it. -----Examples----- Input 2 3 2 2 1 1 2 3 1 2 2 2 2 1 Output 2 2 Input 4 5 3 1 2 3 1 2 5 4 2 1 2 3 2 1 4 4 1 3 3 Output 3 3 3 -----Note----- In the first example, the distance between vertex $1$ and $2$ equals to $2$ because one can walk through the edge of weight $2$ connecting them. So the distance to the farthest node for both $1$ and $2$ equals to $2$. In the second example, one can find that distance between $1$ and $2$, distance between $1$ and $3$ are both $3$ and the distance between $2$ and $3$ is $2$. The graph may have multiple edges between and self-loops, as in the first example.
interview
[{"code": "def g():\n return list(map(int,input().split()))\nn,m,k=g()\np=list(range(n+1))\nz=[0]*(n+1)\nfor x in g():\n z[x]=1\ne=[]\nfor i in range(m):\n u,v,w=g()\n e+=[(w,u,v)]\ne=sorted(e)\ndef q(x):\n if x!=p[x]:\n p[x]=q(p[x])\n return p[x]\nfor w,u,v in e:\n u=q(u);v=q(v)\n if u!=v:\n if u%5==3:\n u,v=v,u\n p[u]=v;z[v]+=z[u]\n if z[v]==k:\n print(((str(w)+' ')*k));return\n", "passed": true, "time": 0.16, "memory": 14380.0, "status": "done"}, {"code": "import sys\nimport heapq\nfrom collections import deque\n\nn,m,k=list(map(int,sys.stdin.readline().split()))\nX=list(map(int,sys.stdin.readline().split()))\nstart=X[0]\n\nEDGE=[list(map(int,sys.stdin.readline().split())) for i in range(m)]\nCOST_vertex=[[] for i in range(n+1)]\nfor i,j,w in EDGE:\n COST_vertex[i].append((j,w))\n COST_vertex[j].append((i,w))\n \n\nMINCOST=[float(\"inf\")]*(n+1)#\u6c42\u3081\u305f\u3044\u30ea\u30b9\u30c8:start\u304b\u3089\u9802\u70b9i\u3078\u306e\u6700\u77ed\u8ddd\u96e2\nMINCOST[start]=0\nchecking=[(0,start)]#start\u6642\u70b9\u306ecost\u306f0.\u6700\u521d\u306f\u3053\u308c\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b.\nwhile checking:\n cost,checktown=heapq.heappop(checking)\n #cost,checktown\u304b\u3089\u306e\u884c\u304d\u5148\u3092check.\n #cost\u6700\u5c0f\u306a\u3082\u306e\u3092\u78ba\u5b9a\u3057,\u78ba\u5b9a\u3057\u305f\u3082\u306e\u306fchecking\u304b\u3089\u629c\u304f.\n if MINCOST[checktown]<cost:#\u78ba\u5b9a\u3057\u305f\u3082\u306e\u3092\u518d\u5ea6\u30c1\u30a7\u30c3\u30af\u3057\u306a\u304f\u3066\u826f\u3044.\n continue \n for to,co in COST_vertex[checktown]:\n if MINCOST[to]>max(MINCOST[checktown],co):\n MINCOST[to]=max(MINCOST[checktown],co)\n #MINCOST\u5019\u88dc\u306b\u8ffd\u52a0\n heapq.heappush(checking,(max(MINCOST[checktown],co),to))\n\n\nANSLIST=[MINCOST[X[i]] for i in range(1,k)]\n\nANS=(str(max(ANSLIST))+\" \")*k\n\nsys.stdout.write(str(ANS)+\"\\n\")\n \n\n", "passed": true, "time": 0.26, "memory": 14404.0, "status": "done"}, {"code": "import sys\nimport heapq\nfrom collections import deque\n\nn,m,k=list(map(int,sys.stdin.readline().split()))\nX=list(map(int,sys.stdin.readline().split()))\nstart=X[0]\n\nEDGE=[list(map(int,sys.stdin.readline().split())) for i in range(m)]\nCOST_vertex=[[] for i in range(n+1)]\nfor i,j,w in EDGE:\n COST_vertex[i].append((j,w))\n COST_vertex[j].append((i,w))\n \n\nMINCOST=[float(\"inf\")]*(n+1)#\u6c42\u3081\u305f\u3044\u30ea\u30b9\u30c8:start\u304b\u3089\u9802\u70b9i\u3078\u306e\u6700\u77ed\u8ddd\u96e2\nMINCOST[start]=0\nchecking=[(0,start)]#start\u6642\u70b9\u306ecost\u306f0.\u6700\u521d\u306f\u3053\u308c\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b.\nwhile checking:\n cost,checktown=heapq.heappop(checking)\n #cost,checktown\u304b\u3089\u306e\u884c\u304d\u5148\u3092check.\n #cost\u6700\u5c0f\u306a\u3082\u306e\u3092\u78ba\u5b9a\u3057,\u78ba\u5b9a\u3057\u305f\u3082\u306e\u306fchecking\u304b\u3089\u629c\u304f.\n if MINCOST[checktown]<cost:#\u78ba\u5b9a\u3057\u305f\u3082\u306e\u3092\u518d\u5ea6\u30c1\u30a7\u30c3\u30af\u3057\u306a\u304f\u3066\u826f\u3044.\n continue \n for to,co in COST_vertex[checktown]:\n if MINCOST[to]>max(MINCOST[checktown],co):\n MINCOST[to]=max(MINCOST[checktown],co)\n #MINCOST\u5019\u88dc\u306b\u8ffd\u52a0\n heapq.heappush(checking,(max(MINCOST[checktown],co),to))\n\n\nANSLIST=[MINCOST[X[i]] for i in range(1,k)]\n\nANS=(str(max(ANSLIST))+\" \")*k\n\nsys.stdout.write(str(ANS)+\"\\n\")\n \n\n", "passed": true, "time": 0.26, "memory": 14560.0, "status": "done"}, {"code": "import sys\nsys.setrecursionlimit(300000)\nn,m,k=list(map(int,input().split()))\nx=list(map(int,input().split()))\nedges=[]\nfor i in range(m):\n a,b,c=list(map(int,input().split()))\n edges.append((c,a,b))\nedges.sort()\ntree=[i for i in range(n+1)]\nused=[]\nedgess=0\ndef q(x):\n if x!=tree[x]:\n tree[x]=q(tree[x])\n return(tree[x])\nfor w,u,v in edges:\n if edgess==n-1:\n break\n a,b=q(u),q(v)\n if a%2==1:\n a,b=b,a\n if a!=b:\n tree[a]=b\n used.append((w,u,v))\n edgess+=1\nneigh=[]\nfor i in range(n+1):\n neigh.append([])\nfor w,u,v in used:\n neigh[u].append((v,w))\n neigh[v].append((u,w))\nlayer=[x[0]]\npars=[None]\ndists=[None]*(n+1)\ndists[x[0]]=0\nwhile layer!=[]:\n newlayer=[]\n newpars=[]\n for i in range(len(layer)):\n guy=layer[i]\n par=pars[i]\n for v,w in neigh[guy]:\n if v!=par:\n dists[v]=max(dists[guy],w)\n newlayer.append(v)\n newpars.append(guy)\n layer=newlayer\n pars=newpars\nhigh=0\nfor guy in x:\n high=max(high,dists[guy])\nprint((str(high)+\" \")*k)\n", "passed": true, "time": 0.25, "memory": 14492.0, "status": "done"}, {"code": "import sys\ndef int_reader():\n yield from (int(d) for d in sys.stdin.read().split())\n\nints = int_reader()\nn, m, k = [next(ints) for i in range(3)]\nspecial = [next(ints) for i in range(k)]\nis_special = [0]*(n+1)\nfor x in special:\n is_special[x] = 1\n\nedges = []\nfor i in range(m):\n u, v, w = [next(ints) for j in range(3)]\n edges.append((w, u, v))\nedges.sort()\n\nfu = [i for i in range(n+1)]\ndef find(x):\n S = []\n while fu[x] != x:\n S.append(x)\n x = fu[x]\n for y in S:\n fu[y] = x\n return x\ndef union(e):\n a, b = find(e[1]), find(e[2])\n if is_special[b]:\n a, b = b, a\n fu[b] = a\n\nans = 0\nfor e in edges:\n a, b = find(e[1]), find(e[2])\n if a == b: continue\n if is_special[a] and is_special[b]:\n ans = e[0]\n union(e)\nprint((str(ans) + ' ') * k)\n", "passed": true, "time": 0.15, "memory": 14412.0, "status": "done"}, {"code": "import sys\ndef int_reader():\n yield from (int(d) for d in sys.stdin.read().split())\n\nints = int_reader()\nn, m, k = [next(ints) for i in range(3)]\nsp = {next(ints) for i in range(k)}\n\nedges = []\nfor i in range(m):\n u, v, w = [next(ints) for j in range(3)]\n edges.append((w, u, v))\nedges.sort()\n\nfu = [i for i in range(n+1)]\ndef find(x):\n S = []\n while fu[x] != x:\n S.append(x)\n x = fu[x]\n for y in S:\n fu[y] = x\n return x\ndef union(a, b):\n if b in sp:\n a, b = b, a\n fu[b] = a\n\nans = 0\nfor e in edges:\n a, b = find(e[1]), find(e[2])\n if a == b: continue\n if a in sp and b in sp:\n ans = e[0]\n union(a, b)\nprint((str(ans) + ' ') * k)\n", "passed": true, "time": 0.16, "memory": 14516.0, "status": "done"}, {"code": "import sys\ndef int_reader():\n yield from (int(d) for d in sys.stdin.read().split())\n\nints = int_reader()\nn, m, k = [next(ints) for i in range(3)]\nsp = {next(ints) for i in range(k)}\n\n'''\nedges = []\nfor i in range(m):\n u, v, w = [next(ints) for j in range(3)]\n edges.append((w, u, v))\n'''\nedges = [(w,u,v) for (u,v,w) in [(next(ints) for i in range(3)) for j in range(m)]]\nedges.sort()\n\nfu = [i for i in range(n+1)]\ndef find(x):\n S = []\n while fu[x] != x:\n S.append(x)\n x = fu[x]\n for y in S:\n fu[y] = x\n return x\ndef union(a, b):\n if b in sp:\n a, b = b, a\n fu[b] = a\n\nans = 0\nfor e in edges:\n a, b = find(e[1]), find(e[2])\n if a == b: continue\n if a in sp and b in sp:\n ans = e[0]\n union(a, b)\nprint((str(ans) + ' ') * k)\n", "passed": true, "time": 0.16, "memory": 14404.0, "status": "done"}, {"code": "def g():\n return map(int,input().split())\nn,m,k=g()\np=list(range(n+1))\nz=[0]*(n+1)\nfor x in g():\n z[x]=1\ne=[]\nfor i in range(m):\n u,v,w=g()\n e+=[(w,u,v)]\ne=sorted(e)\ndef q(x):\n if x!=p[x]:\n p[x]=q(p[x])\n return p[x]\nfor w,u,v in e:\n u=q(u);v=q(v)\n if u!=v:\n if u%5==3:\n u,v=v,u\n p[u]=v;z[v]+=z[u]\n if z[v]==k:\n print((str(w)+' ')*k);return", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}, {"code": "class Union:\n def __init__(self, n, list_k):\n self.p = {i:i for i in range(n+1)}\n self.rank = {i:0 for i in range(n+1)} \n \n for k in list_k:\n self.rank[k] = 1\n \n def find(self, x):\n if x < 0: return x\n \n if self.p[x] != x:\n self.p[x] = self.find(self.p[x])\n return self.p[x]\n \n def union(self, x, y):\n if x < 0 or y < 0:return\n \n x = self.find(x)\n y = self.find(y)\n if x != y:\n if self.rank[x] < self.rank[y]:\n self.p[x] = y\n self.rank[y] += self.rank[x]\n else:\n self.p[y] = x\n self.rank[x] += self.rank[y]\n \nn, m, k = list(map(int, input().split()))\nlist_k = list(map(int, input().split()))\nedge = []\n\nfor _ in range(m):\n u, v, w = list(map(int, input().split()))\n edge.append((u,v,w))\n \nedge = sorted(edge, key=lambda x:x[2])\n\nU = Union(n, list_k)\nval = 0\n\nfor u, v, w in edge:\n if u == v: continue\n \n par_1 = U.find(u)\n par_2 = U.find(v) \n \n if par_1 == par_2:\n continue\n \n if U.rank[par_1] + U.rank[par_2] == k:\n val = w\n break\n \n U.union(u, v)\n\ns = ''\nfor _ in range(len(list_k)):\n s += str(val) + ' ' \n \nprint(s)\n \n#2 3 2\n#2 1\n#1 2 3\n#1 2 2\n#2 2 1\n", "passed": true, "time": 0.15, "memory": 14480.0, "status": "done"}, {"code": "import sys\nsys.setrecursionlimit(300000)\nn,m,k=list(map(int,input().split()))\nx=list(map(int,input().split()))\nedges=[]\nfor i in range(m):\n a,b,c=list(map(int,input().split()))\n edges.append((c,a,b))\nedges.sort()\ntree=[i for i in range(n+1)]\nused=[]\nedgess=0\ndef q(x):\n if x!=tree[x]:\n tree[x]=q(tree[x])\n return(tree[x])\nfor w,u,v in edges:\n if edgess==n-1:\n break\n a,b=q(u),q(v)\n if a%2==1:\n a,b=b,a\n if a!=b:\n tree[a]=b\n used.append((w,u,v))\n edgess+=1\nneigh=[]\nfor i in range(n+1):\n neigh.append([])\nfor w,u,v in used:\n neigh[u].append((v,w))\n neigh[v].append((u,w))\nlayer=[x[0]]\npars=[None]\ndists=[None]*(n+1)\ndists[x[0]]=0\nwhile layer!=[]:\n newlayer=[]\n newpars=[]\n for i in range(len(layer)):\n guy=layer[i]\n par=pars[i]\n for v,w in neigh[guy]:\n if v!=par:\n dists[v]=max(dists[guy],w)\n newlayer.append(v)\n newpars.append(guy)\n layer=newlayer\n pars=newpars\nhigh=0\nfor guy in x:\n high=max(high,dists[guy])\nprint((str(high)+\" \")*k)\n", "passed": true, "time": 0.14, "memory": 14580.0, "status": "done"}, {"code": "def put():\n return list(map(int, input().split()))\n\ndef find(i):\n if i == p[i]:\n return i\n p[i]=find(p[i])\n return p[i]\n\ndef union(i,j):\n if rank[i]<rank[j]:\n i,j = j,i\n elif rank[i]==rank[j]:\n rank[i]+=1\n p[j]=i\n z[i]+=z[j]\n return z[i]\n\nn,m,k =put()\nl = list(put())\nz,edge,p,rank = [0]*(n+1), [], list(range(n+1)), [0]*(n+1)\n\nfor i in l:\n z[i]=1\nfor i in range(m):\n u,v,w = put()\n edge.append((w,u,v))\nedge.sort()\n\nfor w,u,v in edge:\n u,v = list(map(find, (u,v)))\n if u!=v:\n cnt=union(u,v)\n if cnt==k:\n print((str(w)+' ')*k)\n break\n \n", "passed": true, "time": 0.14, "memory": 14400.0, "status": "done"}]
[{"input": "2 3 2\n2 1\n1 2 3\n1 2 2\n2 2 1\n", "output": "2 2 \n"}, {"input": "4 5 3\n1 2 3\n1 2 5\n4 2 1\n2 3 2\n1 4 4\n1 3 3\n", "output": "3 3 3 \n"}, {"input": "5 7 4\n1 2 3 4\n1 2 3\n5 1 4\n3 1 1\n4 2 5\n2 5 6\n2 3 3\n3 4 6\n", "output": "5 5 5 5 \n"}, {"input": "2 1 2\n1 2\n1 2 1000000000\n", "output": "1000000000 1000000000 \n"}, {"input": "3 2 2\n2 3\n1 2 2\n2 3 1\n", "output": "1 1 \n"}, {"input": "3 2 2\n2 3\n1 2 5\n2 3 1\n", "output": "1 1 \n"}, {"input": "4 4 2\n3 4\n1 2 1000000000\n2 3 1000000000\n3 1 1000000000\n3 4 1\n", "output": "1 1 \n"}, {"input": "3 2 2\n2 3\n1 2 1000\n2 3 1\n", "output": "1 1 \n"}, {"input": "4 3 2\n1 2\n1 2 1\n2 3 2\n3 4 1\n", "output": "1 1 \n"}, {"input": "3 2 2\n1 2\n1 2 1\n2 3 2\n", "output": "1 1 \n"}, {"input": "4 3 2\n1 4\n1 2 1\n2 3 3\n3 4 1\n", "output": "3 3 \n"}, {"input": "5 5 2\n1 2\n1 2 1\n2 3 2\n3 4 2\n4 5 2\n5 1 2\n", "output": "1 1 \n"}, {"input": "5 4 2\n4 5\n1 2 10\n2 3 10\n3 4 1\n3 5 1\n", "output": "1 1 \n"}, {"input": "3 2 2\n1 2\n1 2 10\n2 3 15\n", "output": "10 10 \n"}, {"input": "3 2 2\n2 3\n1 2 100\n2 3 1\n", "output": "1 1 \n"}, {"input": "3 2 2\n1 2\n1 2 1\n2 3 5\n", "output": "1 1 \n"}, {"input": "3 2 2\n1 2\n1 2 1\n2 3 4\n", "output": "1 1 \n"}, {"input": "4 3 2\n3 4\n1 2 2\n1 3 4\n3 4 1\n", "output": "1 1 \n"}, {"input": "6 5 4\n1 2 3 4\n1 2 1\n2 3 1\n3 4 1\n4 5 1\n5 6 10\n", "output": "1 1 1 1 \n"}, {"input": "4 3 3\n1 2 3\n1 2 5\n1 3 4\n1 4 5\n", "output": "5 5 5 \n"}, {"input": "3 2 2\n1 2\n1 2 2\n2 3 3\n", "output": "2 2 \n"}, {"input": "7 6 2\n6 7\n1 2 1\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n", "output": "1 1 \n"}, {"input": "3 2 2\n3 2\n1 2 233\n2 3 3\n", "output": "3 3 \n"}, {"input": "4 3 2\n2 3\n1 2 100\n2 3 1\n3 4 100\n", "output": "1 1 \n"}, {"input": "4 3 2\n2 3\n1 2 1000\n2 3 1\n3 4 1000\n", "output": "1 1 \n"}, {"input": "3 4 2\n2 1\n1 2 3\n1 2 2\n2 2 1\n1 3 99\n", "output": "2 2 \n"}, {"input": "6 5 3\n1 2 4\n1 3 3\n3 2 2\n2 4 1\n3 5 4\n5 6 10\n", "output": "3 3 3 \n"}, {"input": "3 2 2\n1 2\n1 2 10\n3 2 20\n", "output": "10 10 \n"}, {"input": "4 3 2\n1 4\n1 2 1\n2 3 5\n3 4 1\n", "output": "5 5 \n"}, {"input": "5 4 2\n4 5\n1 2 100\n2 3 100\n3 4 100\n4 5 1\n", "output": "1 1 \n"}, {"input": "3 2 2\n1 2\n1 2 3\n1 3 5\n", "output": "3 3 \n"}, {"input": "3 2 2\n1 2\n1 2 3\n2 3 5\n", "output": "3 3 \n"}, {"input": "3 2 2\n1 2\n1 2 3\n2 3 100\n", "output": "3 3 \n"}, {"input": "5 4 2\n4 5\n1 2 10\n2 3 10\n3 4 1\n4 5 1\n", "output": "1 1 \n"}, {"input": "3 2 2\n1 2\n1 2 1\n2 3 100\n", "output": "1 1 \n"}, {"input": "3 2 2\n1 2\n1 2 10\n2 3 100\n", "output": "10 10 \n"}, {"input": "4 3 2\n1 2\n1 2 1\n2 3 1000\n3 4 1000\n", "output": "1 1 \n"}, {"input": "3 2 2\n2 3\n1 2 3\n2 3 1\n", "output": "1 1 \n"}, {"input": "4 3 2\n3 4\n1 2 10000\n2 3 10000\n3 4 1\n", "output": "1 1 \n"}, {"input": "3 3 2\n1 2\n1 2 1\n1 3 1000\n2 3 1000\n", "output": "1 1 \n"}, {"input": "2 2 2\n1 2\n1 2 3\n1 2 5\n", "output": "3 3 \n"}, {"input": "4 3 2\n3 4\n1 2 9\n2 3 6\n3 4 1\n", "output": "1 1 \n"}, {"input": "3 2 2\n1 2\n1 2 1\n2 3 1000\n", "output": "1 1 \n"}, {"input": "4 3 2\n1 4\n1 2 3\n2 3 4\n3 4 3\n", "output": "4 4 \n"}, {"input": "5 4 2\n4 5\n1 2 100\n2 3 100\n3 4 10\n3 5 20\n", "output": "20 20 \n"}, {"input": "4 3 2\n1 2\n1 2 1\n2 3 23\n3 4 1231\n", "output": "1 1 \n"}, {"input": "4 3 2\n1 4\n1 2 4\n2 3 6\n3 4 4\n", "output": "6 6 \n"}, {"input": "4 3 2\n1 2\n1 2 1\n2 3 123\n3 4 12321\n", "output": "1 1 \n"}, {"input": "3 2 2\n2 1\n1 2 1\n2 3 100\n", "output": "1 1 \n"}, {"input": "4 3 2\n3 4\n1 2 100\n2 3 2\n2 4 2\n", "output": "2 2 \n"}, {"input": "4 3 2\n1 2\n1 2 1\n2 3 12\n3 4 123123\n", "output": "1 1 \n"}, {"input": "4 4 3\n1 2 3\n1 2 1\n1 3 2\n2 3 3\n3 4 5\n", "output": "2 2 2 \n"}, {"input": "5 4 2\n1 5\n1 2 1\n1 3 2\n2 4 5\n3 5 3\n", "output": "3 3 \n"}, {"input": "3 3 2\n1 2\n1 2 1\n2 3 4\n1 3 5\n", "output": "1 1 \n"}, {"input": "4 4 3\n1 2 3\n1 2 1\n2 3 2\n1 3 3\n1 4 4\n", "output": "2 2 2 \n"}, {"input": "3 2 2\n1 2\n1 2 1\n2 3 47\n", "output": "1 1 \n"}, {"input": "3 2 2\n1 2\n3 2 10\n2 1 1\n", "output": "1 1 \n"}, {"input": "3 2 2\n2 3\n1 2 10\n2 3 1\n", "output": "1 1 \n"}, {"input": "4 3 3\n1 2 3\n1 2 1\n3 1 2\n4 3 3\n", "output": "2 2 2 \n"}, {"input": "4 3 2\n3 4\n1 2 5\n2 3 3\n2 4 4\n", "output": "4 4 \n"}, {"input": "3 2 2\n1 3\n1 2 1\n2 3 1\n", "output": "1 1 \n"}, {"input": "3 2 2\n1 2\n1 2 1\n2 3 3\n", "output": "1 1 \n"}, {"input": "5 4 3\n1 2 4\n1 2 10\n2 3 100\n2 4 20\n5 3 1000\n", "output": "20 20 20 \n"}, {"input": "4 5 2\n2 3\n1 2 5\n4 2 1\n2 3 2\n1 4 4\n1 3 3\n", "output": "2 2 \n"}, {"input": "4 3 3\n1 2 3\n1 2 6\n1 3 7\n1 4 10\n", "output": "7 7 7 \n"}, {"input": "6 5 2\n1 6\n1 2 1\n2 3 2\n3 4 3\n4 5 2\n5 6 1\n", "output": "3 3 \n"}, {"input": "3 3 2\n2 3\n1 2 100\n1 3 100\n2 3 1\n", "output": "1 1 \n"}, {"input": "3 2 2\n2 3\n1 2 7\n2 3 1\n", "output": "1 1 \n"}]
244
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball. Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.). Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly n movements were made by the operator and the ball was under shell x at the end. Now he wonders, what was the initial position of the ball? -----Input----- The first line of the input contains an integer n (1 ≀ n ≀ 2Β·10^9)Β β€” the number of movements made by the operator. The second line contains a single integer x (0 ≀ x ≀ 2)Β β€” the index of the shell where the ball was found after n movements. -----Output----- Print one integer from 0 to 2Β β€” the index of the shell where the ball was initially placed. -----Examples----- Input 4 2 Output 1 Input 1 1 Output 0 -----Note----- In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
interview
[{"code": "def main():\n\tn = int(input())\n\tk = int(input())\n\tn %= 6\n\ta = [0, 1, 2]\n\tfor i in range(1, n + 1):\n\t\tif (i % 2 == 1):\n\t\t\ta[0], a[1] = a[1], a[0]\n\t\telse:\n\t\t\ta[1], a[2] = a[2], a[1]\n\tprint(a[k])\n\n\nmain()", "passed": true, "time": 0.15, "memory": 14476.0, "status": "done"}, {"code": "import sys\nn = int(input())\nm = int(input())\nz = [[0, 1, 2],\n [1, 0, 2],\n [1, 2, 0],\n [2, 1, 0],\n [2, 0, 1],\n [0, 2, 1]]\nprint(z[n % 6][m])\n", "passed": true, "time": 0.15, "memory": 14576.0, "status": "done"}, {"code": "N = int(input())\nN %= 6\nx = int(input())\nb = [0, 1, 2]\nfor i in range(N):\n if i % 2 == 0:\n b[0], b[1] = b[1], b[0]\n else:\n b[1], b[2] = b[2], b[1]\nprint(b[x])\n", "passed": true, "time": 0.15, "memory": 14288.0, "status": "done"}, {"code": "A = [0, 1, 2]\nB = [0] * 6\nfor i in range(6):\n B[i] = A[:]\n if i % 2 == 0:\n A[0], A[1] = A[1], A[0]\n else:\n A[1], A[2] = A[2], A[1]\nn = int(input())\n#n -= 1\nn %= 6\nx = int(input())\nprint(B[n][x])", "passed": true, "time": 0.15, "memory": 14512.0, "status": "done"}, {"code": "n = int(input()) % 6\nx = int(input())\np = [0, 1, 2]\nfor i in range(1, n + 1):\n if i % 2 == 1:\n p[0], p[1] = p[1], p[0]\n else:\n p[1], p[2] = p[2], p[1]\nprint(p[x])", "passed": true, "time": 0.24, "memory": 14316.0, "status": "done"}, {"code": "import math, sys\ndef main():\n\tn = int(input())\n\tx = int(input())\n\td0 = [0,1,2,2,1,0]\n\td1 = [1,0,0,1,2,2]\t\n\td2 = [2,2,1,0,0,1]\n\tif (d0[n%6]==x):\n\t\tprint(0)\n\telif (d1[n%6]==x):\n\t\tprint(1)\n\telse:\n\t\tprint(2)\n\t\n\t\t\t\ndef __starting_point():\n\tmain()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "n = int(input())\nx = int(input())\nn %= 6\na = [[0, 1, 2], [1, 0,2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]\nc = a[n][x]\nprint(c)\n", "passed": true, "time": 0.21, "memory": 14456.0, "status": "done"}, {"code": "n = int(input())\nx = int(input())\n\nres = [\n [0, 1, 2],\n [1, 0, 2],\n [1, 2, 0],\n [2, 1, 0],\n [2, 0, 1],\n [0, 2, 1],\n]\n\npos = n % 6\nprint(res[pos][x])\n", "passed": true, "time": 0.14, "memory": 14456.0, "status": "done"}, {"code": "a = [[1, 2, 3], [2, 1, 3], [2, 3, 1], [3, 2, 1], [3, 1, 2], [1, 3, 2]]\n\nn = int(input())\nx = int(input())\n\nprint(a[n % 6][x] - 1)", "passed": true, "time": 0.15, "memory": 14552.0, "status": "done"}, {"code": "n = int(input())\nx = int(input())\nn %= 6\npos = 0\nfor i in range(1,n+1):\n if i%2 == 1:\n if pos == 1:\n pos = 0\n elif pos == 0:\n pos = 1\n else:\n if pos == 2:\n pos = 1\n elif pos == 1:\n pos = 2\nif pos == x:\n print(0)\nelse:\n pos = 1\n for i in range(1,n+1):\n if i%2 == 1:\n if pos == 1:\n pos = 0\n elif pos == 0:\n pos = 1\n else:\n if pos == 2:\n pos = 1\n elif pos == 1:\n pos = 2\n if pos == x:\n print(1)\n else:\n print(2)\n \n", "passed": true, "time": 0.14, "memory": 14444.0, "status": "done"}, {"code": "n=int(input())\na=[\"012\",\"102\",\"120\",\"210\",\"201\",\"021\"]\nt=int(input())\nprint(a[n%len(a)][t])\n", "passed": true, "time": 0.15, "memory": 14316.0, "status": "done"}, {"code": "# Author: Maharshi Gor\n\ndef read(type=int):\n return type(input())\n\n\ndef read_arr(type=int):\n return [type(token) for token in input().split()]\n\n\nn = read()\nx = read()\nn %= 6\n\nA = [\n [0, 1, 2],\n [1, 0, 2],\n [1, 2, 0],\n [2, 1, 0],\n [2, 0, 1],\n [0, 2, 1]\n]\nprint(A[n][x])", "passed": true, "time": 0.14, "memory": 14508.0, "status": "done"}, {"code": "n = int(input())\nx = int(input())\n\nn %= 6\n\nodd = n % 2\n\nfor i in range(n):\n if odd:\n if x == 0:\n x = 1\n elif x == 1:\n x = 0\n else:\n if x == 1:\n x = 2\n elif x == 2:\n x = 1\n odd = not odd\n\nprint(x)\n", "passed": true, "time": 0.22, "memory": 14488.0, "status": "done"}, {"code": "#! /usr/bin/python\n# kmwho\n# Codeforces 401 D2\n\ndef main():\n n = int(input())\n x = int(input())\n n = n % 6\n pos = [ 0,1,2 ]\n for i in range(1,n+1):\n if i%2 == 1:\n pos[0],pos[1] = pos[1], pos[0]\n else:\n pos[1],pos[2] = pos[2], pos[1]\n print(pos[x])\n\n\nmain()\n\n", "passed": true, "time": 0.51, "memory": 14308.0, "status": "done"}, {"code": "n = int(input())\nm = int(input())\nn = n % 6\no = 0\nfor i in range(n):\n if i % 2 == 1:\n if o != 0:\n o = 3 - o\n else:\n if o != 2:\n o = 1 - o\nif o == m:\n print(0)\nelse:\n o = 1\n for i in range(n):\n if i % 2 == 1:\n if o != 0:\n o = 3 - o\n else:\n if o != 2:\n o = 1 - o\n if o == m:\n print(1)\n else:\n print(2)\n\n", "passed": true, "time": 0.14, "memory": 14492.0, "status": "done"}, {"code": "n = int(input())\nx = int(input())\nn %= 6\nt = n\na = [0] * 3\n\na[x] = 1\nfor i in range(6 - n):\n\tif (i + t) % 2 == 0:\n\t\ta[0], a[1] = a[1], a[0]\n\telse:\n\t\ta[1], a[2] = a[2], a[1]\nprint(a.index(1))", "passed": true, "time": 0.19, "memory": 14356.0, "status": "done"}, {"code": "def simulate(init, n):\n a = [0, 0, 0]\n a[init] = 1\n n %= 6\n for i in range(1, n + 1):\n if i % 2 == 1:\n a[0], a[1] = a[1], a[0]\n else:\n a[1], a[2] = a[2], a[1]\n for i in range(3):\n if a[i] == 1:\n return i\n\nn = int(input())\nx = int(input())\nfor i in range(3):\n if simulate(i, n) == x:\n print(i)\n break", "passed": true, "time": 0.15, "memory": 14464.0, "status": "done"}, {"code": "n=int(input())\nx=int(input())\nlst=['012','102','120','210','201','021']\nn %= 6\nstr = lst[n]\nprint(str[x])\n", "passed": true, "time": 0.14, "memory": 14324.0, "status": "done"}, {"code": "n, x = int(input()), int(input())\nn %= 6\nans = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]\nprint(ans[n][x])", "passed": true, "time": 0.15, "memory": 14460.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nn %= 6\nd = [[0, 1, 1, 2, 2, 0], [1, 0, 2, 1, 0, 2], [2, 2, 0, 0, 1, 1]]\nprint(d[k][n])\n", "passed": true, "time": 0.15, "memory": 14400.0, "status": "done"}, {"code": "a = ['012', '102', '120', '210', '201', '021']\nn = int(input())\nx = int(input())\nprint(a[n % 6][x])\n", "passed": true, "time": 0.15, "memory": 14464.0, "status": "done"}, {"code": "positions = [[0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2, 1]]\nn = int(input())\nx = int(input())\nk = n % 6\nprint(positions[k][x])", "passed": true, "time": 0.14, "memory": 14564.0, "status": "done"}, {"code": "n=int(input())\nm=int(input())\nn=n%6\narr=[0,0,0]\narr[m]=1\n#print(arr)\nfor i in range(6-n):\n j=6-n+i\n if j%2==0:\n arr[0],arr[1]=arr[1],arr[0]\n else:\n arr[1],arr[2]=arr[2],arr[1]\n #print(arr)\nprint(arr.index(1))\n", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "n = int(input())\nx = int(input())\n\nn %= 6\na, b, c = (x == 0), (x == 1), (x == 2)\n\nfor i in reversed(list(range(n))):\n if i % 2 == 0:\n a, b = b, a\n else:\n b, c = c, b\n\nif a:\n print(0)\nelif b:\n print(1)\nelse:\n print(2)\n", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}]
[{"input": "4\n2\n", "output": "1\n"}, {"input": "1\n1\n", "output": "0\n"}, {"input": "2\n2\n", "output": "0\n"}, {"input": "3\n1\n", "output": "1\n"}, {"input": "3\n2\n", "output": "0\n"}, {"input": "3\n0\n", "output": "2\n"}, {"input": "2000000000\n0\n", "output": "1\n"}, {"input": "2\n0\n", "output": "1\n"}, {"input": "2\n1\n", "output": "2\n"}, {"input": "4\n0\n", "output": "2\n"}, {"input": "4\n1\n", "output": "0\n"}, {"input": "5\n0\n", "output": "0\n"}, {"input": "5\n1\n", "output": "2\n"}, {"input": "5\n2\n", "output": "1\n"}, {"input": "6\n0\n", "output": "0\n"}, {"input": "6\n1\n", "output": "1\n"}, {"input": "6\n2\n", "output": "2\n"}, {"input": "7\n0\n", "output": "1\n"}, {"input": "7\n1\n", "output": "0\n"}, {"input": "7\n2\n", "output": "2\n"}, {"input": "100000\n0\n", "output": "2\n"}, {"input": "100000\n1\n", "output": "0\n"}, {"input": "100000\n2\n", "output": "1\n"}, {"input": "99999\n1\n", "output": "1\n"}, {"input": "99998\n1\n", "output": "2\n"}, {"input": "99997\n1\n", "output": "0\n"}, {"input": "99996\n1\n", "output": "1\n"}, {"input": "99995\n1\n", "output": "2\n"}, {"input": "1999999995\n0\n", "output": "2\n"}, {"input": "1999999995\n1\n", "output": "1\n"}, {"input": "1999999995\n2\n", "output": "0\n"}, {"input": "1999999996\n0\n", "output": "2\n"}, {"input": "1999999996\n1\n", "output": "0\n"}, {"input": "1999999996\n2\n", "output": "1\n"}, {"input": "1999999997\n0\n", "output": "0\n"}, {"input": "1999999997\n1\n", "output": "2\n"}, {"input": "1999999997\n2\n", "output": "1\n"}, {"input": "1999999998\n0\n", "output": "0\n"}, {"input": "1999999998\n1\n", "output": "1\n"}, {"input": "1999999998\n2\n", "output": "2\n"}, {"input": "1999999999\n0\n", "output": "1\n"}, {"input": "1999999999\n1\n", "output": "0\n"}, {"input": "1999999999\n2\n", "output": "2\n"}, {"input": "2000000000\n1\n", "output": "2\n"}, {"input": "2000000000\n2\n", "output": "0\n"}, {"input": "1234567890\n0\n", "output": "0\n"}, {"input": "1234567890\n1\n", "output": "1\n"}, {"input": "1234567890\n2\n", "output": "2\n"}, {"input": "123456789\n0\n", "output": "2\n"}, {"input": "123456789\n1\n", "output": "1\n"}, {"input": "123456789\n2\n", "output": "0\n"}, {"input": "123456790\n0\n", "output": "2\n"}, {"input": "12\n2\n", "output": "2\n"}, {"input": "32\n1\n", "output": "2\n"}, {"input": "20\n2\n", "output": "0\n"}, {"input": "10\n1\n", "output": "0\n"}, {"input": "1\n0\n", "output": "1\n"}, {"input": "76994383\n1\n", "output": "0\n"}, {"input": "25\n2\n", "output": "2\n"}, {"input": "1\n2\n", "output": "2\n"}, {"input": "12\n0\n", "output": "0\n"}, {"input": "150\n2\n", "output": "2\n"}, {"input": "15\n0\n", "output": "2\n"}, {"input": "21\n2\n", "output": "0\n"}, {"input": "18\n2\n", "output": "2\n"}, {"input": "8\n2\n", "output": "0\n"}, {"input": "10\n0\n", "output": "2\n"}, {"input": "16\n0\n", "output": "2\n"}]
245
You are given n rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the Ox and Oy axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle). Your task is to determine if the rectangles form a square. In other words, determine if the set of points inside or on the border of at least one rectangle is precisely equal to the set of points inside or on the border of some square. -----Input----- The first line contains a single integer n (1 ≀ n ≀ 5). Next n lines contain four integers each, describing a single rectangle: x_1, y_1, x_2, y_2 (0 ≀ x_1 < x_2 ≀ 31400, 0 ≀ y_1 < y_2 ≀ 31400) β€” x_1 and x_2 are x-coordinates of the left and right edges of the rectangle, and y_1 and y_2 are y-coordinates of the bottom and top edges of the rectangle. No two rectangles overlap (that is, there are no points that belong to the interior of more than one rectangle). -----Output----- In a single line print "YES", if the given rectangles form a square, or "NO" otherwise. -----Examples----- Input 5 0 0 2 3 0 3 3 5 2 0 5 2 3 2 5 5 2 2 3 3 Output YES Input 4 0 0 2 3 0 3 3 5 2 0 5 2 3 2 5 5 Output NO
interview
[{"code": "n = int(input())\ns = 0\nINF = 10**9\nminx = miny = INF\nmaxx = maxy = -INF\n\nfor i in range(n):\n x1, y1, x2, y2 = list(map(int, input().split()))\n s += abs(x1 - x2) * abs(y1 - y2)\n minx = min(minx, x1, x2)\n maxx = max(maxx, x1, x2)\n miny = min(miny, y1, y2)\n maxy = max(maxy, y1, y2)\n\nif (maxx - minx) == (maxy - miny) and s == (maxx - minx) ** 2:\n print (\"YES\")\nelse:\n print (\"NO\")\n", "passed": true, "time": 0.25, "memory": 14356.0, "status": "done"}, {"code": "n = int(input())\n#print(n)\n\nl = [[int(x) for x in input().split()] for i in range(n)]\n\n#print(l)\n\ndx = (max([r[2] for r in l])-min([r[0] for r in l]))\ndy = (max([r[3] for r in l])-min([r[1] for r in l]))\nsize = dx*dy\n#print(size)\n\nif dx == dy and sum([(r[2]-r[0])*(r[3]-r[1]) for r in l]) == size:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "n = int(input())\nx1 = []\nx2 = []\ny1 = []\ny2 = []\nS = 0\n\nfor i in range(n):\n a, b, c, d = list(map(int, input().split()))\n x1.append(a)\n y1.append(b)\n x2.append(c)\n y2.append(d)\n S += (c - a) * (d - b)\n\nif (max(x2) - min(x1)) * (max(y2) - min(y1)) == S and max(x2) - min(x1) == max(y2) - min(y1):\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.15, "memory": 14568.0, "status": "done"}, {"code": "n = int(input())\nsq = [None] * 51\nsqsum = 0\nfor i in range(n):\n sq[i]= list(map(int,input().split()))\n sqsum+=(sq[i][3]-sq[i][1])*(sq[i][2]-sq[i][0])\nmaxx = max(map(lambda x:x[2],sq[:n]))\nminx = min(map(lambda x:x[0],sq[:n]))\nmaxy = max(map(lambda x:x[3],sq[:n]))\nminy = min(map(lambda x:x[1],sq[:n]))\narea = (maxy-miny)*(maxx-minx)\n\nif maxx-minx!=maxy-miny or area!=sqsum:\n print(\"NO\")\nelse:\n print(\"YES\")", "passed": true, "time": 0.23, "memory": 14616.0, "status": "done"}, {"code": "pl = 0\netpl = 0\nmax_x = 0\nmin_x = 40000\nmax_y = 0\nmin_y = 40000\nn = int(input())\nfor i in range(0,n,1):\n crd = input().split()\n if(int(crd[0]) >= int(crd[2])):\n st1 = int(crd[0]) - int(crd[2])\n else:\n st1 = int(crd[2]) - int(crd[0])\n if(int(crd[1]) >= int(crd[3])):\n st2 = int(crd[1]) - int(crd[3])\n else:\n st2 = int(crd[3]) - int(crd[1])\n if(int(crd[0]) < min_x):\n min_x = int(crd[0])\n if(int(crd[1]) < min_y):\n min_y = int(crd[1])\n if(int(crd[2]) > max_x):\n max_x = int(crd[2])\n if(int(crd[3]) > max_y):\n max_y = int(crd[3])\n pl += st1*st2\n etpl = (max_y-min_y)*(max_x-min_x)\nif max_y-min_y == max_x-min_x and etpl == pl:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14568.0, "status": "done"}, {"code": "n = int(input())\nx = set()\ny = set()\np = [list(map(int, input().split())) for i in range(n)]\nfor d in p:\n x.add(d[0])\n y.add(d[1])\n x.add(d[2])\n y.add(d[3])\nxl = sorted(list(x))\nyl = sorted(list(y))\nif (xl[-1] - xl[0] != yl[-1] - yl[0]):\n print('NO')\n return\nz = [[0 for i in range(len(xl)-1)] for j in range(len(yl)-1)]\nfor d in p:\n for i in range(xl.index(d[0]), xl.index(d[2])):\n for j in range(yl.index(d[1]), yl.index(d[3])):\n z[j][i] = 1\nfor d in z:\n if d.count(0):\n print('NO')\n return\nprint('YES')\n", "passed": true, "time": 0.22, "memory": 14620.0, "status": "done"}, {"code": "import sys\nfin = sys.stdin\n# fout = sys.stdout\n\nn = int(fin.readline())\np = []\nfor i in range(n):\n a, b, c, d = map(int, fin.readline().split())\n p += [((a, b), (c, d))]\n \ndef width(rect):\n return rect[1][0] - rect[0][0]\n\ndef height(rect):\n return rect[1][1] - rect[0][1]\n \ndef square(rect):\n return width(rect) * height(rect)\n\ndef squareOfRects(rects):\n return sum(square(r) for r in rects)\n\ndef left(rects):\n return min(r[0][0] for r in rects)\n\ndef right(rects):\n return max(r[1][0] for r in rects)\n\ndef bottom(rects):\n return min(r[0][1] for r in rects)\n\ndef top(rects):\n return max(r[1][1] for r in rects)\n \ndef isSquare(rects):\n w, h = right(rects) - left(rects), top(rects) - bottom(rects)\n return w == h and squareOfRects(rects) == w * h\n\nprint(\"YES\" if isSquare(p) else \"NO\")", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "n = int(input())\narea = 0\nmaxx, maxy, minx, miny = 0, 0, 10**5, 10**5\nfor i in range(0, n):\n a,b,c,d = list(map(int, input().split()))\n \n area += (c - a) * (d - b)\n maxx = max(maxx, c)\n minx = min(minx, a)\n maxy = max(maxy, d)\n miny = min(miny, b)\n\nn = maxx - minx\nif n == maxy - miny and n * n == area: print('YES')\nelse: print('NO')\n", "passed": true, "time": 0.23, "memory": 14412.0, "status": "done"}, {"code": "n = int(input())\na1, b1, a2, b2 = map(int, input().split())\ns = (a2 - a1) * (b2 - b1)\nfor i in range(n - 1):\n x1, y1, x2, y2 = map(int, input().split())\n a1, b1, a2, b2 = min(a1, x1), min(b1, y1), max(a2, x2), max(b2, y2)\n s += (x2 - x1) * (y2 - y1)\nprint('YES' if a2 - a1 == b2 - b1 and s == (a2 - a1) * (b2 - b1) else 'NO')", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "import sys\nimport math \n\nn = int(input())\n\nvmaxx = 0\nvmaxy = 0\nvminx = 31401\nvminy = 31401\n\ns = 0\nfor i in range(n):\n x1, y1, x2, y2 = [int(x) for x in (sys.stdin.readline()).split()]\n vmaxx = max(vmaxx, x2)\n vmaxy = max(vmaxy, y2)\n vminx = min(vminx, x1)\n vminy = min(vminy, y1)\n s += (x2 - x1) * (y2 - y1)\n\nif(s == (vmaxx - vminx) * (vmaxy - vminy) and (vmaxx - vminx) == (vmaxy - vminy)):\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.23, "memory": 14392.0, "status": "done"}, {"code": "xmin, ymin, xmax, ymax, a = 31400, 31400, 0, 0, 0\nfor i in range(int(input())):\n x1, y1, x2, y2 = map(int, input().split())\n xmin = min(xmin, x1)\n ymin = min(ymin, y1)\n xmax = max(xmax, x2)\n ymax = max(ymax, y2)\n a += (x2 - x1) * (y2 - y1)\nprint('YES' if xmax - xmin == ymax - ymin and a == (xmax - xmin) ** 2 else 'NO')", "passed": true, "time": 0.14, "memory": 14308.0, "status": "done"}, {"code": "n = int(input())\narea = 0\nminx = miny = 999999\nmaxx = maxy = 0\nfor _ in range(n):\n x1, y1, x2, y2 = list(map(int, input().split()))\n minx = min(minx, min(x1, x2))\n miny = min(miny, min(y1, y2))\n maxx = max(maxx, max(x1, x2))\n maxy = max(maxy, max(y1, y2))\n a = abs(x1 - x2) * abs(y1 - y2)\n area += a\n\nh = maxy - miny\nw = maxx - minx\n\nif h != w or h*h != area:\n print('NO')\nelse:\n print('YES')", "passed": true, "time": 0.14, "memory": 14472.0, "status": "done"}, {"code": "xmin, ymin, xmax, ymax, a = 31400, 31400, 0, 0, 0\n\nfor i in range(int(input())):\n\n x1, y1, x2, y2 = map(int, input().split())\n\n xmin = min(xmin, x1)\n\n ymin = min(ymin, y1)\n\n xmax = max(xmax, x2)\n\n ymax = max(ymax, y2)\n\n a += (x2 - x1) * (y2 - y1)\n\nprint('YES' if xmax - xmin == ymax - ymin and a == (xmax - xmin) ** 2 else 'NO')", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "\nn=int(input())\nc=[[],[],[],[]]\nplos=0\n\nfor i in range(n):\n q=list(map(int,input().split()))\n plos+=(q[2]-q[0])*(q[3]-q[1]) \n for j in range(4):\n c[j].append(q[j]) \n\nfw=(max(c[2])-min(c[0]))\nfh=(max(c[3])-min(c[1]))\n\nif(fw==fh and fw*fh==plos):\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14572.0, "status": "done"}, {"code": "x0=[]; x1=[]; y0=[]; y1=[]\nn=int(input())\ns=0 # Variable to add rects. areas together\nfor i in range(n):\n l=list(map(int,input().split()))\n x0.extend([l[0]])\n x1.extend([l[2]])\n y0.extend([l[1]])\n y1.extend([l[3]])\n s+=(l[3]-l[1])*(l[2]-l[0])\n\nlx=max(x1)-min(x0)\nly=max(y1)-min(y0)\nif lx==ly and lx*ly==s:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.14, "memory": 14544.0, "status": "done"}, {"code": "n = int(input())\nx1, y1, x2, y2 = list(map(int, input().split()))\nl, r, u, d = x1, x2, y2, y1\ns = (x2 - x1) * (y2 - y1)\nfor i in range(n - 1):\n x1, y1, x2, y2 = list(map(int, input().split()))\n s += (x2 - x1) * (y2 - y1)\n l = min(l, x1)\n r = max(r, x2)\n u = max(u, y2)\n d = min(d, y1)\nif r - l == u - d and (r - l) * (u - d) == s:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.25, "memory": 14440.0, "status": "done"}, {"code": "def f(l, i):\n return min(l) if i < 2 else max(l)\n\n\nclass CodeforcesTask325ASolution:\n def __init__(self):\n self.result = ''\n self.n = 0\n self.rectangles = []\n\n def read_input(self):\n self.n = int(input())\n for _ in range(self.n):\n self.rectangles.append([int(x) for x in input().split(\" \")])\n\n def process_task(self):\n cords = [f([x[i] for x in self.rectangles], i) for i in range(4)]\n fields = [(x[3] - x[1]) * (x[2] - x[0]) for x in self.rectangles]\n ff = sum(fields)\n if ff == (cords[3] - cords[1]) * (cords[2] - cords[0]) and cords[3] - cords[1] == cords[2] - cords[0]:\n self.result = \"YES\"\n else:\n self.result = \"NO\"\n\n def get_result(self):\n return self.result\n\n\ndef __starting_point():\n Solution = CodeforcesTask325ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14508.0, "status": "done"}, {"code": "xmin, ymin, xmax, ymax, a = 31400, 31400, 0, 0, 0\n \nfor i in range(int(input())):\n \n x1, y1, x2, y2 = map(int, input().split())\n \n xmin = min(xmin, x1)\n \n ymin = min(ymin, y1)\n \n xmax = max(xmax, x2)\n \n ymax = max(ymax, y2)\n \n a += (x2 - x1) * (y2 - y1)\n\n#print(xmax,xmin,ymax,ymin,a,end=\"\") \nprint('YES' if xmax - xmin == ymax - ymin and a == (xmax - xmin) ** 2 else 'NO')", "passed": true, "time": 0.14, "memory": 14348.0, "status": "done"}]
[{"input": "5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3\n", "output": "YES\n"}, {"input": "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n", "output": "NO\n"}, {"input": "5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 14999 20000\n0 20000 15000 31400\n15000 0 31400 31400\n", "output": "NO\n"}, {"input": "5\n0 0 10000 20000\n10000 0 15000 19999\n10000 19999 15000 20000\n0 20000 15000 31400\n15000 0 31400 31400\n", "output": "YES\n"}, {"input": "5\n10359 859 28918 4384\n2895 26520 28918 26882\n2895 26424 28918 26520\n2895 859 10359 4384\n2895 4384 28918 26424\n", "output": "YES\n"}, {"input": "5\n12750 0 25688 1\n1094 0 12750 1\n0 0 956 1\n956 0 1094 1\n25688 0 31400 1\n", "output": "NO\n"}, {"input": "4\n18006 16484 25725 31400\n0 0 31400 16484\n29563 16484 31400 31400\n25725 16484 29563 31400\n", "output": "NO\n"}, {"input": "1\n0 0 31400 31400\n", "output": "YES\n"}, {"input": "2\n0 0 31400 13313\n0 13313 31400 31400\n", "output": "YES\n"}, {"input": "3\n0 9388 31400 31400\n26020 0 31400 9388\n0 0 26020 9388\n", "output": "YES\n"}, {"input": "5\n15164 0 19356 3925\n0 0 15164 31400\n15164 3925 31400 31400\n19356 3278 31400 3925\n19356 0 31400 3278\n", "output": "YES\n"}, {"input": "5\n20421 5189 23141 12511\n16414 10436 17880 12511\n17880 10436 20421 12511\n15819 10436 16414 12511\n15819 5189 20421 10436\n", "output": "YES\n"}, {"input": "1\n15819 5189 23141 12511\n", "output": "YES\n"}, {"input": "3\n12052 12345 12343 18147\n12343 12345 12345 18147\n6543 12345 12052 18147\n", "output": "YES\n"}, {"input": "5\n12750 0 25688 1\n1094 0 12750 1\n0 0 956 1\n956 0 1094 1\n25688 0 31400 1\n", "output": "NO\n"}, {"input": "5\n0 7098 1 7460\n0 7460 1 15218\n0 15218 1 31400\n0 4974 1 7098\n0 0 1 4974\n", "output": "NO\n"}, {"input": "1\n0 0 31400 1\n", "output": "NO\n"}, {"input": "1\n0 0 1 31400\n", "output": "NO\n"}, {"input": "5\n0 25169 1 27914\n0 0 1 1366\n0 10763 1 25169\n0 1366 1 10138\n0 27914 1 31400\n", "output": "NO\n"}, {"input": "1\n0 0 10575 1\n", "output": "NO\n"}, {"input": "1\n0 3006 1 17592\n", "output": "NO\n"}, {"input": "1\n123 4819 5819 29511\n", "output": "NO\n"}, {"input": "3\n123 4819 5819 6612\n123 6612 5819 12692\n123 12692 5819 29511\n", "output": "NO\n"}, {"input": "5\n3091 4819 5743 13222\n123 13222 5819 29511\n5743 4819 5819 13222\n123 4819 2215 13222\n2215 4819 3091 13222\n", "output": "NO\n"}, {"input": "5\n8030 7681 8491 7682\n8491 7681 8961 7682\n7666 7681 7963 7682\n7963 7681 8030 7682\n678 7681 7666 7682\n", "output": "NO\n"}, {"input": "5\n1234 1234 1235 1235\n1238 1234 1239 1235\n1235 1234 1236 1235\n1237 1234 1238 1235\n1236 1234 1237 1235\n", "output": "NO\n"}, {"input": "5\n20812 5661 27208 5898\n20812 581 29415 5661\n27539 5661 29415 5898\n18961 581 20812 5898\n27208 5661 27539 5898\n", "output": "NO\n"}, {"input": "1\n31399 31399 31400 31400\n", "output": "YES\n"}, {"input": "1\n20499 0 31400 22815\n", "output": "NO\n"}, {"input": "2\n0 1273 26470 9100\n0 16615 31400 31400\n", "output": "NO\n"}, {"input": "3\n25784 0 31400 20408\n0 20408 31400 20582\n15802 0 18106 20408\n", "output": "NO\n"}, {"input": "4\n18006 16484 25725 31400\n0 0 31400 16484\n29563 16484 31400 31400\n25725 16484 29563 31400\n", "output": "NO\n"}, {"input": "5\n26466 0 26474 6206\n10906 0 17073 6321\n19720 0 26356 31400\n0 0 10906 7852\n0 21437 18466 31400\n", "output": "NO\n"}, {"input": "5\n1338 31399 1525 31400\n1525 31399 2595 31400\n961 31399 1338 31400\n2956 31399 31400 31400\n2595 31399 2956 31400\n", "output": "NO\n"}, {"input": "5\n1349 0 1391 3766\n1234 0 1238 417\n1391 0 5000 3766\n1234 417 1238 3766\n1238 0 1349 3766\n", "output": "YES\n"}, {"input": "5\n0 0 100 30000\n100 0 31400 5000\n100 5000 20000 30000\n0 30000 20000 31400\n20000 5000 31400 31400\n", "output": "YES\n"}, {"input": "5\n0 0 100 30000\n100 0 31400 5000\n100 5000 20000 30000\n0 30000 20000 31000\n20000 5000 31400 31000\n", "output": "NO\n"}, {"input": "5\n8591 1234 9517 19512\n696 19512 9517 31400\n696 696 8591 19512\n8591 696 31400 1234\n9517 1234 31400 31400\n", "output": "YES\n"}, {"input": "5\n0 0 1 1\n0 3 1 4\n0 1 1 2\n0 2 1 3\n0 4 1 5\n", "output": "NO\n"}, {"input": "4\n0 0 1 2\n0 3 1 4\n0 4 1 5\n0 2 1 3\n", "output": "NO\n"}, {"input": "3\n0 1 1 3\n0 3 1 5\n0 0 1 1\n", "output": "NO\n"}, {"input": "1\n0 0 1 5\n", "output": "NO\n"}, {"input": "4\n0 0 2 1\n2 0 3 2\n0 1 1 3\n1 2 3 3\n", "output": "NO\n"}, {"input": "5\n0 0 2 1\n2 0 3 2\n0 1 1 3\n1 2 3 3\n1 1 2 2\n", "output": "YES\n"}, {"input": "1\n0 0 1 1\n", "output": "YES\n"}, {"input": "1\n0 0 31400 31400\n", "output": "YES\n"}, {"input": "2\n0 0 10000 31400\n10000 0 31400 31400\n", "output": "YES\n"}, {"input": "2\n0 0 10000 31400\n10000 0 31400 31399\n", "output": "NO\n"}, {"input": "2\n0 0 1 18\n5 0 6 18\n", "output": "NO\n"}, {"input": "1\n0 0 1 4\n", "output": "NO\n"}, {"input": "2\n0 0 2 6\n2 2 4 4\n", "output": "NO\n"}, {"input": "2\n2 2 3 3\n4 4 6 7\n", "output": "NO\n"}, {"input": "2\n0 0 1 1\n1 0 2 1\n", "output": "NO\n"}, {"input": "2\n0 0 1 1\n2 2 3 3\n", "output": "NO\n"}, {"input": "4\n0 0 1 1\n5 5 6 6\n10 10 11 11\n13 13 14 14\n", "output": "NO\n"}, {"input": "5\n1 1 3 5\n3 3 5 5\n4 1 5 3\n3 1 4 2\n2 5 3 6\n", "output": "NO\n"}, {"input": "4\n10 10 11 11\n11 11 12 12\n11 10 12 11\n9 12 10 13\n", "output": "NO\n"}, {"input": "2\n0 0 2 4\n10 0 12 4\n", "output": "NO\n"}, {"input": "4\n0 0 1 1\n0 1 1 2\n0 2 1 3\n0 3 1 4\n", "output": "NO\n"}, {"input": "2\n0 0 1 1\n3 3 4 4\n", "output": "NO\n"}, {"input": "2\n0 0 3 1\n0 2 3 3\n", "output": "NO\n"}, {"input": "2\n1 1 5 5\n1 5 5 7\n", "output": "NO\n"}, {"input": "3\n0 0 1 1\n1 0 3 3\n0 2 1 4\n", "output": "NO\n"}, {"input": "4\n0 0 10 10\n10 10 20 20\n10 0 20 10\n10 20 11 120\n", "output": "NO\n"}, {"input": "1\n0 0 1 7\n", "output": "NO\n"}, {"input": "4\n0 0 4 2\n0 2 3 6\n3 4 6 6\n4 0 6 4\n", "output": "NO\n"}, {"input": "2\n0 0 1 1\n1 1 2 2\n", "output": "NO\n"}, {"input": "2\n1 1 2 2\n3 3 4 4\n", "output": "NO\n"}]
246
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
interview
[{"code": "def check(x, s):\n k = 0\n for i in str(x):\n k += int(i)\n return x - k >= s\n\n\nn, s = map(int, input().split())\nl = 0\nr = n\nwhile r - l > 1:\n m = (l + r) // 2\n if check(m, s):\n r = m\n else:\n l = m\nif check(r, s):\n print(n - r + 1)\nelse:\n print(0)", "passed": true, "time": 0.15, "memory": 14552.0, "status": "done"}, {"code": "inp=input().split()\nn=int(inp[0])\ns=int(inp[1])\nstart=s+1\nthresh=s+500\nans=0\nif(n>thresh):\n\tans+=n-thresh\nelse:\n\tthresh=n\nval=0\nfor i in range(start,thresh+1):\n\tval=i\n\twhile(i>0):\n\t\tval-=i%10\n\t\ti=i//10\n\tif(val>=s):\n\t\tans+=1\nprint(ans)", "passed": true, "time": 0.16, "memory": 14572.0, "status": "done"}, {"code": "def sum_dig(num):\n num = str(num)\n ans = 0\n for i in range(len(num)):\n ans += int(num[i])\n return ans\n\nn,s = list(map(int,input().split()))\nans = 0\nfor i in range(s,n+1):\n if i - sum_dig(i) >= s:\n ans = n - i + 1\n break\nprint(ans)\n", "passed": true, "time": 0.17, "memory": 14456.0, "status": "done"}, {"code": "def f(n):\n rtn = n\n while 0 < n:\n rtn -= n % 10\n n //= 10\n return rtn\n\nn, s = list(map(int, input().split()))\nl = 0\nr = 10**18 + 1\ncnt = 0\nwhile 1 < r - l:\n m = (l + r) // 2\n if s <= f(m):\n r = m\n else:\n l = m\n\nprint(max(n - r + 1, 0))\n", "passed": true, "time": 0.24, "memory": 14300.0, "status": "done"}, {"code": "def f(x):\n\tans = x\n\twhile x > 0:\n\t\tans -= x % 10\n\t\tx //= 10\n\treturn ans\nn, s = list(map(int, input().split()))\nif f(n) < s:\n\tprint(0)\n\treturn\nl, r = 1, n\nwhile l < r:\n\tm = (l + r) // 2\n\tif f(m) >= s:\n\t\tr = (m // 10) * 10\n\telse:\n\t\tl = m + 1\nprint(n - l + 1)\n", "passed": true, "time": 0.16, "memory": 14436.0, "status": "done"}, {"code": "n, s = map(int, input().split())\n\nans = 0\np = s\nfor i in range(163):\n\tp = s + i\n\tif p > n:\n\t\tbreak\n\tif p >= s + sum(map(int, str(p))):\n\t\tans += 1\n\nif p <= n:\n\tans += n - p\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14324.0, "status": "done"}, {"code": "def f(x):\n\tans = x\n\twhile x > 0:\n\t\tans -= x % 10\n\t\tx //= 10\n\treturn ans\nn, s = list(map(int, input().split()))\nif f(n) < s:\n\tprint(0)\n\treturn\nl, r = 1, n\nwhile l < r:\n\tm = (l + r) // 2\n\tif f(m) >= s:\n\t\tr = (m // 10) * 10\n\telse:\n\t\tl = m + 1\nprint(n - l + 1) \n", "passed": true, "time": 0.15, "memory": 14256.0, "status": "done"}, {"code": "from math import ceil\nn, s = [int(i) for i in input().split()]\n\nl = 0\nr = 10000000000000000000\n\nwhile l < r:\n cur = (l + r) // 2\n sm = sum([int(i) for i in str(cur)])\n if cur - sm >= s:\n r = cur\n else:\n l = cur + 1\n\nprint(max(0, n - l + 1))\n", "passed": true, "time": 0.16, "memory": 14552.0, "status": "done"}, {"code": "n,s = map(int, input().split())\nmdist = 10**5\nc = s \nans = 0 \ndef mySum(c):\n s = str(c)\n ret = 0 \n for x in s:\n ret += ord(x) - ord('0')\n return ret \nwhile mdist and c <= n:\n if c - mySum(c) >= s:\n ans += 1 \n \n mdist -= 1 \n c += 1 \nc = min(c, n + 1)\nprint(ans + n - c + 1)", "passed": true, "time": 2.14, "memory": 14548.0, "status": "done"}, {"code": "n, s = map(int, input().split())\nl = 1\nr = n + 1\nwhile r > l + 1:\n m = (l + r) // 2\n #print(m)\n line = str(m)\n if m - sum(int(k) for k in line) >= s:\n r = m\n else:\n l = m\nline = str(l)\nif l - sum(int(k) for k in line) >= s:\n r = l\nprint(max(n - r + 1, 0))", "passed": true, "time": 0.15, "memory": 14460.0, "status": "done"}, {"code": "I = lambda : list(map(int, input().split()))\nn, s = I()\ncnt = n-min(200+s, n+1)+1\nfor i in range(s, min(200 + s, n+1)):\n if i - sum(map(int, str(i))) >= s:\n cnt += 1\nprint(cnt)\n", "passed": true, "time": 0.15, "memory": 14296.0, "status": "done"}, {"code": "class ReallyBigNumbers:\n\n\tdef __init__(self, n, s):\n\t\tself.n = n\n\t\tself.s = s\n\t\tself.binarySearch()\n\n\tdef binarySearch(self):\n\t\tl = self.s\n\t\th = 10000000000000000000\n\t\twhile(l < h):\n\t\t\tmid = (h + l) // 2\n\t\t\t#print(mid, self.isReallyBig(mid))\n\t\t\tif self.isReallyBig(mid):\n\t\t\t\th = mid\n\t\t\telse:\n\t\t\t\tl = mid + 1\n\t\tself.x = int(l)\n\n\tdef isReallyBig(self, v):\n\t\tcp = v\n\t\tadd = 0\n\t\twhile v > 0:\n\t\t\tadd += v % 10\n\t\t\tv //= 10\n\t\t#print('resta', cp-add, cp, add)\n\t\treturn (cp - add) >= self.s\n\n\tdef show(self):\n\t\tif self.x <= self.n:\n\t\t\tprint(str(self.n - self.x + 1))\n\t\telse:\n\t\t\tprint(0)\n\n\nn, s = list(map(int, input().split()))\nrbg = ReallyBigNumbers(n, s)\n#print(rbg.x)\nrbg.show()\n\n", "passed": true, "time": 0.15, "memory": 14480.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\nn, s = list(map(int, input().split(' ')))\ndef sumd(d):\n sd = 0\n while d!=0:\n sd += d%10\n d//=10\n return sd\nst, ed = 1, n\nr = 0\nwhile True:\n if st==ed:\n r = st\n break\n x = (st+ed)//2\n if x-sumd(x)<s:\n st = x+1\n else:\n ed = x\nif r-sumd(r)>=s:\n print(n-r+1)\nelse:\n print(0)\n", "passed": true, "time": 0.14, "memory": 14492.0, "status": "done"}, {"code": "def f(x):\n return (x if x < 10 else f(x // 10) + x % 10)\nn, s = map(int, input().split())\nx = s\nwhile x - f(x) < s:\n x += 1\nprint(max(0, n - x + 1))", "passed": true, "time": 0.15, "memory": 14464.0, "status": "done"}, {"code": "n, s = [int(i) for i in input().split()]\nprint(max(n - ([i for i in range(s, s + 9 * 18 + 1) if i - sum([int(j) for j in str(i)]) >= s] + [int('1' * 18)])[0] + 1, 0))\n", "passed": true, "time": 0.17, "memory": 14504.0, "status": "done"}, {"code": "n, s = [int(i) for i in input().split()]\nprint(max(n - [i for i in range(s, s + 180) if i - sum([int(j) for j in str(i)]) >= s][0] + 1, 0))\n", "passed": true, "time": 0.16, "memory": 14588.0, "status": "done"}, {"code": "n,s = map(int,input().split())\n\ndef diff(m):\n return m - sum([int(k) for k in list(str(m))])\n \ndef digit_safe(k):\n r = len(list(str(k)))\n return toint([\"1\"]+[\"0\"]*(r-1))\na = list(str(n))\nb = list(str(s))\nd = int(a[0])\n\ndef toint(l):\n return int(\"\".join(l))\nres = 0\nfor i in range(d):\n z = toint([str(i)] + [\"0\" for _ in range(len(a)-1)])\n z1 = toint([str(i+1)] + [\"0\" for _ in range(len(a)-1)])\n count = diff(z)\n while z < z1 and count < s:\n z += digit_safe(s-count)\n count = diff(z)\n if z <= z1:\n res += (z1-z)\nz = toint([str(d)] + [\"0\" for _ in range(len(a)-1)])\nz1 = n+1\ncount = diff(z)\nwhile z < z1 and count < s:\n z += digit_safe(s-count)\n count = diff(z)\nif z <= z1:\n res += (z1-z)\nprint(res)", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "def calc(n):\n\tval = n\n\tcnt = 0\n\twhile(val):\n\t\tcnt += val%10\n\t\tval//=10\n\treturn n-cnt\n\t\t\nn,s = list(map(int,input().split()))\nif n<=s:\n\tprint(0)\n\treturn\nval = s\nval //= 10\nif val==0:\n\tprint(n-9 if n>=9 else 0)\n\treturn\nval *= 10\nwhile calc(val)<s:\n\tval += 10\n\tif val>n:\n\t\tprint(0)\n\t\tbreak\nelse:\n\tprint(n-val+1)\n", "passed": true, "time": 0.14, "memory": 14580.0, "status": "done"}, {"code": "# def sum_digits(n):\n# s = 0\n# while n:\n# s += n % 10\n# n //= 10\n# return s\n\n\n# n, s = map(int, input().split())\n\n# count = 0\n# summ = sum_digits(n)\n# # k = sum_digits(n - n%10 - 1)\n# # print(k)\n# for num in range(n, 9, -1):\n# \tif num % 10 == 9:\n# \t\tsumm = sum_digits(num)\n# \t# print(num, summ)\n# \tif num - summ >= s:\n# \t\tcount += 1\n# \tsumm -= 1\n\t\n\n\n# print(count)\n\n\ndef sum_digits(n):\n s = 0\n while n:\n s += n % 10\n n //= 10\n return s\n\ndef binsearch(l, r, elem):\n\tn = r\n\tmedium = (l + r ) // 2\n\ts = medium - sum_digits(medium)\n\ts1 = medium-1- sum_digits(medium-1)\n\ts2 = medium+1 - sum_digits(medium+1)\n\t# print(s,s2)\n\twhile not(s2 >= elem and s < elem): #s >= elem and s1 < elem or \n\t\t# print(l,medium,r)\n\t\tif s < elem:\n\t\t\tl = medium\n\t\telif s >= elem:\n\t\t\tr = medium\n\t\tk = medium\n\t\tmedium = (l + r ) // 2\n\t\tif k == medium:\n\t\t\tbreak\n\t\t# print(l,medium,r)\n\t\ts = medium - sum_digits(medium)\n\t\ts2 = medium+1 - sum_digits(medium+1)\n\t\t# print(s,s2)\n\n\ts1 = medium-1 - sum_digits(medium-1)\n\tif s >= elem and s1 < elem:\n\t\treturn medium\n\telif s2 >= elem and s < elem:\n\t\treturn medium + 1\n\telse:\n\t\treturn \tn+1\n\nn, s = list(map(int, input().split()))\n# a = [i for i in range(n+1)]\nif n == s:\n\tprint(0)\nelse:\n\n\ty = binsearch( 0, n, s)\n# print(y)\n\tprint(n - y + 1)\n\n\n\n\n", "passed": true, "time": 0.25, "memory": 14508.0, "status": "done"}, {"code": "# def sum_digits(n):\n# s = 0\n# while n:\n# s += n % 10\n# n //= 10\n# return s\n\n\n# n, s = map(int, input().split())\n\n# count = 0\n# summ = sum_digits(n)\n# # k = sum_digits(n - n%10 - 1)\n# # print(k)\n# for num in range(n, 9, -1):\n# \tif num % 10 == 9:\n# \t\tsumm = sum_digits(num)\n# \t# print(num, summ)\n# \tif num - summ >= s:\n# \t\tcount += 1\n# \tsumm -= 1\n\t\n\n\n# print(count)\n\n\ndef sum_digits(n):\n s = 0\n while n:\n s += n % 10\n n //= 10\n return s\n\ndef binsearch(l, r, elem):\n\tn = r\n\tmedium = (l + r ) // 2\n\ts = medium - sum_digits(medium)\n\ts1 = medium-1- sum_digits(medium-1)\n\ts2 = medium+1 - sum_digits(medium+1)\n\t# print(s,s2)\n\twhile not(s2 >= elem and s < elem): #s >= elem and s1 < elem or \n\t\t# print(l,medium,r)\n\t\tif s < elem:\n\t\t\tl = medium\n\t\telif s >= elem:\n\t\t\tr = medium\n\t\tk = medium\n\t\tmedium = (l + r ) // 2\n\t\tif k == medium:\n\t\t\tbreak\n\t\t# print(l,medium,r)\n\t\ts = medium - sum_digits(medium)\n\t\ts2 = medium+1 - sum_digits(medium+1)\n\t\t# print(s,s2) \n\n\ts1 = medium-1 - sum_digits(medium-1)\n\tif s >= elem and s1 < elem:\n\t\treturn medium\n\telif s2 >= elem and s < elem:\n\t\treturn medium + 1\n\telse:\n\t\treturn \tn+1\n\nn, s = list(map(int, input().split()))\n# a = [i for i in range(n+1)]\nif n == s:\n\tprint(0)\nelse:\n\n\ty = binsearch( 0, n, s)\n# print(y)\n\tprint(n - y + 1)\n\n\n\n\n", "passed": true, "time": 0.15, "memory": 14612.0, "status": "done"}, {"code": "def read_ints():\n return list(map(int, input().split()))\n\n\nn, s = read_ints()\n\n\ndef judge(x):\n return x - sum(map(int, str(x))) >= s\n\n\nresult = len([x for x in range(s, min(n, s + 180) + 1) if judge(x)]) + max(0, n - s - 180)\n\nprint(result)\n", "passed": true, "time": 0.15, "memory": 14236.0, "status": "done"}, {"code": "raw=input().split()\nn=int(raw[0])\ns=int(raw[1])\n\ndef sum_digits(x):\n z=0\n while x:\n z+=x%10\n x//=10\n return z\n\ni=s\ncount=0\nwhile i<=n:\n q=i-sum_digits(i)\n if q>=s:\n count=n-i+1\n break\n else:\n i+=1\nprint(count)\n\n#print(sum_digits(1))\n \n \n", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "a = input()\na = a.split(' ')\na = list(map(int,a))\ndef really_big(n,s):\n if s >= n:\n return 0\n i = s + 1\n while i <= n:\n t,b = i,0\n while t > 0:\n b = b + (t % 10)\n t = t // 10\n if i - b >= s:\n return n - i + 1\n break\n else:\n i += 1\n return 0\nprint(really_big(a[0],a[1]))", "passed": true, "time": 0.15, "memory": 14464.0, "status": "done"}, {"code": "def cmp(x1 = [],x2 = []):\n len1 = len(x1)\n len2 = len(x2)\n if len1 == len2:\n for i in range(len1):\n n1 = x1[len1 - 1 - i]\n n2 = x2[len1 - 1 - i]\n if n1 != n2:\n return n1 > n2\n else:\n return len1 > len2\n return True\n\ndef add(x1 = [],x2 = []):\n if not cmp(x1,x2):\n x1,x2 = x2,x1\n len1 = len(x1)\n len2 = len(x2)\n for i in range(len1 - len2):\n x2.append(0)\n res = []\n flag = 0\n for n1,n2 in zip(x1,x2):\n m = n1 + n2 + flag\n flag = m // 10\n res.append(m % 10)\n if flag:\n res.append(flag)\n return res\n \ndef minus(x1 = [],x2 = []):\n if not cmp(x1,x2):\n x1,x2 = x2,x1\n len1 = len(x1)\n len2 = len(x2)\n for i in range(len1 - len2):\n x2.append(0)\n res = []\n flag = 0\n for n1,n2 in zip(x1,x2):\n m = n1 - n2 + flag\n flag = 0 if m >= 0 else -1\n res.append((m + 10) % 10)\n \n while res and not res[-1]:\n res.pop()\n return res\n \ndef div(x1 = [], x2 = 9):\n if x2 == 10:\n return x1[1:]\n else:\n x1.reverse()\n res = []\n mod = 0\n for n in x1:\n res.append((n + mod * 10)// 9)\n mod = (n + mod * 10) % 9\n res.reverse()\n while res and not res[-1]:\n res.pop()\n return res \n\ndef multi(x1 = [],x2 = 9):\n x1_copy = x1.copy()\n x1.insert(0,0)\n if x2 == 10:\n return x1\n else:\n return minus(x1,x1_copy)\n\ndef __starting_point():\n input_str = input()\n n,s = [a for a in input_str.split()]\n nl = list([int(a) for a in list(n)])\n sl = list([int(a) for a in list(s)])\n nl.reverse()\n sl.reverse()\n \n x = multi(div(add(sl.copy(),[8]),9),9)\n y = multi(div(add(x.copy(),[9]),10),10)\n sumy = list([int(a) for a in list(str(sum(y)))])\n sumy.reverse()\n while not cmp(minus(y,sumy),sl):\n y = add(y,[0,1])\n sumy = list([int(a) for a in list(str(sum(y)))])\n sumy.reverse()\n\n if cmp(nl,y):\n ans = add(minus(nl,y),[1])\n else:\n ans = [0]\n ans.reverse()\n ansstr = [str(a) for a in ans]\n print(\"\".join(ansstr))\n\n\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14680.0, "status": "done"}]
[{"input": "12 1\n", "output": "3\n"}, {"input": "25 20\n", "output": "0\n"}, {"input": "10 9\n", "output": "1\n"}, {"input": "300 1000\n", "output": "0\n"}, {"input": "500 1000\n", "output": "0\n"}, {"input": "1000 2000\n", "output": "0\n"}, {"input": "10000 1000\n", "output": "8991\n"}, {"input": "1000000000000000000 1000000000000000000\n", "output": "0\n"}, {"input": "1000000000000000000 100000000000000000\n", "output": "899999999999999991\n"}, {"input": "1000000000000000000 10000000000000000\n", "output": "989999999999999991\n"}, {"input": "1000000000000000000 1000000000000000\n", "output": "998999999999999991\n"}, {"input": "1000000000000000000 100000000000000\n", "output": "999899999999999991\n"}, {"input": "1000000000000000000 200000000000000000\n", "output": "799999999999999991\n"}, {"input": "10 5\n", "output": "1\n"}, {"input": "20 5\n", "output": "11\n"}, {"input": "20 9\n", "output": "11\n"}, {"input": "100 9\n", "output": "91\n"}, {"input": "1 1\n", "output": "0\n"}, {"input": "130 118\n", "output": "1\n"}, {"input": "190 181\n", "output": "0\n"}, {"input": "1999 1971\n", "output": "10\n"}, {"input": "100 99\n", "output": "1\n"}, {"input": "6909094398 719694282\n", "output": "6189400069\n"}, {"input": "260 258\n", "output": "0\n"}, {"input": "35 19\n", "output": "6\n"}, {"input": "100 87\n", "output": "1\n"}, {"input": "91 89\n", "output": "0\n"}, {"input": "109 89\n", "output": "10\n"}, {"input": "109 91\n", "output": "10\n"}, {"input": "20331 11580\n", "output": "8732\n"}, {"input": "405487470 255750281\n", "output": "149737161\n"}, {"input": "17382 12863\n", "output": "4493\n"}, {"input": "19725 14457\n", "output": "5246\n"}, {"input": "24848 15384\n", "output": "9449\n"}, {"input": "25727 15982\n", "output": "9728\n"}, {"input": "109 90\n", "output": "10\n"}, {"input": "1000000000000000000 999999999999999999\n", "output": "1\n"}, {"input": "1000000000000000000 999999999999999998\n", "output": "1\n"}, {"input": "1009 980\n", "output": "10\n"}, {"input": "999999999999999999 999999999999999838\n", "output": "0\n"}, {"input": "1000000000000000000 99999999999999800\n", "output": "900000000000000061\n"}, {"input": "8785369357 3377262261\n", "output": "5408107058\n"}, {"input": "110 109\n", "output": "0\n"}, {"input": "999 777\n", "output": "200\n"}, {"input": "327170000015578 77230000029054\n", "output": "249939999986479\n"}, {"input": "12515000022229 1791000022317\n", "output": "10723999999880\n"}, {"input": "9999999999999 9999999999882\n", "output": "10\n"}, {"input": "213 196\n", "output": "14\n"}, {"input": "92 82\n", "output": "0\n"}, {"input": "148 136\n", "output": "0\n"}, {"input": "8 9\n", "output": "0\n"}, {"input": "309 299\n", "output": "0\n"}, {"input": "9999 9963\n", "output": "10\n"}, {"input": "82 81\n", "output": "0\n"}, {"input": "9999999 9999936\n", "output": "10\n"}, {"input": "171 155\n", "output": "2\n"}, {"input": "999 972\n", "output": "10\n"}, {"input": "999999999999 999999999891\n", "output": "10\n"}, {"input": "9 9\n", "output": "0\n"}, {"input": "6900 6885\n", "output": "1\n"}, {"input": "96 57\n", "output": "27\n"}, {"input": "5 4\n", "output": "0\n"}, {"input": "17386 5814\n", "output": "11557\n"}, {"input": "493679757404593 316259583979965\n", "output": "177420173424564\n"}, {"input": "18474 9478\n", "output": "8975\n"}, {"input": "270091571496186 250931112649966\n", "output": "19160458846177\n"}, {"input": "565751690089037 381448507916936\n", "output": "184303182172038\n"}, {"input": "19 10\n", "output": "0\n"}]
247
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct. You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines? -----Input----- The first line contains one integer n (1 ≀ n ≀ 10^5) β€” the number of points you are given. Then n lines follow, each line containing two integers x_{i} and y_{i} (|x_{i}|, |y_{i}| ≀ 10^9)β€” coordinates of i-th point. All n points are distinct. -----Output----- If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO. -----Examples----- Input 5 0 0 0 1 1 1 1 -1 2 2 Output YES Input 5 0 0 1 0 2 1 1 1 2 3 Output NO -----Note----- In the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points. [Image]
interview
[{"code": "n = int(input())\nL = [(0, 0)] * n\nfor i in range(n):\n t = input().split(' ')\n a = int(t[0])\n b = int(t[1])\n L[i] = (a, b)\nif n <= 4:\n print(\"YES\")\nelse:\n b0 = True\n b1 = True\n b2 = True\n L0 = []\n L1 = []\n L2 = []\n for j in range(n):\n if (L[0][0]-L[1][0])*(L[0][1]-L[j][1])!=(L[0][1]-L[1][1])*(L[0][0]-L[j][0]):\n L2.append(L[j])\n if (L[2][0]-L[0][0])*(L[2][1]-L[j][1])!=(L[2][1]-L[0][1])*(L[2][0]-L[j][0]):\n L1.append(L[j])\n if (L[2][0]-L[1][0])*(L[2][1]-L[j][1])!=(L[2][1]-L[1][1])*(L[2][0]-L[j][0]):\n L0.append(L[j])\n if len(L0) >= 3:\n for j in range(2, len(L0)):\n if (L0[0][0]-L0[1][0])*(L0[0][1]-L0[j][1])!=(L0[0][1]-L0[1][1])*(L0[0][0]-L0[j][0]):\n b0 = False\n if len(L1) >= 3:\n for j in range(2, len(L1)):\n if (L1[0][0]-L1[1][0])*(L1[0][1]-L1[j][1])!=(L1[0][1]-L1[1][1])*(L1[0][0]-L1[j][0]):\n b1 = False\n if len(L2) >= 3:\n for j in range(2, len(L2)):\n if (L2[0][0]-L2[1][0])*(L2[0][1]-L2[j][1])!=(L2[0][1]-L2[1][1])*(L2[0][0]-L2[j][0]):\n b2 = False\n if b0 or b1 or b2:\n print(\"YES\")\n else:\n print(\"NO\")\n", "passed": true, "time": 0.24, "memory": 14512.0, "status": "done"}, {"code": "n = int(input())\nx = [0] * n\ny = [0] * n\nfor i in range(n):\n xi, yi = list(map(int, input().split()))\n x[i], y[i] = xi, yi\n\nif n <= 4:\n print(\"YES\"); return\n\nl = lambda i, j, k : (y[i] - y[j]) * (x[i] - x[k]) == (y[i] - y[k]) * (x[i] - x[j])\n\ndef check(ind):\n if len(ind) <= 2:\n return True\n for k in range(2, len(ind)):\n if not l(ind[0], ind[1], ind[k]):\n return False\n return True\n\ndef diff(i, j):\n return [_ for _ in range(n) if not l(i, j, _)]\n \ndf = diff(0, 1)\n\nif check(df):\n print(\"YES\"); return\nf = df[0]\n\ndf2 = diff(0, f)\nif check(df2):\n print(\"YES\"); return\n\ndf3 = diff(1, f)\nif check(df3):\n print(\"YES\"); return\n\nprint(\"NO\")\n \n\n \n\n", "passed": true, "time": 0.14, "memory": 14492.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nimport sys\nfrom itertools import combinations\n\nn = int(sys.stdin.readline().strip())\nxys = [tuple(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]\n\nxys = list(set(xys))\nif len(xys) < 5:\n\tprint ('YES')\n\treturn\n\ndef is_on_line(p0, p1, p2):\n\treturn ((p1[0] - p0[0]) * (p2[1] - p0[1]) == (p1[1] - p0[1]) * (p2[0] - p0[0]))\n\nl1 = (-1, -1, -1)\nfor comb in combinations(list(range(5)), 3):\n\tif is_on_line(xys[comb[0]], xys[comb[1]], xys[comb[2]]):\n\t\tl1 = comb\n\t\tbreak\n\nif l1[0] < 0:\n\tprint ('NO')\n\treturn\n\nline = [0 for _ in range(n)]\nfor l in l1:\n\tline[l] = 1\n\nfor i in range(n):\n\tif i in l1:\n\t\tcontinue\n\tif is_on_line(xys[l1[0]], xys[l1[1]], xys[i]):\n\t\tline[i] = 1\n\nnline = [i for i in range(n) if line[i] == 0]\nif len(nline) < 3:\n\tprint ('YES')\n\treturn\n\nfor i in nline[2:]:\n\tif not is_on_line(xys[nline[0]], xys[nline[1]], xys[i]):\n\t\tprint ('NO')\n\t\treturn\n\nprint ('YES')\n", "passed": true, "time": 0.15, "memory": 14388.0, "status": "done"}, {"code": "def f(ii, i0, i1):\n nonlocal xy\n rtn = []\n x0, y0 = xy[i0]\n x1, y1 = xy[i1]\n for i in ii:\n xi, yi = xy[i]\n if (xi - x0) * (yi - y1) != (xi - x1) * (yi - y0):\n rtn.append(i)\n return rtn\n\n\ndef g(i0, i1):\n nonlocal f, n\n ls = f(list(range(n)), i0, i1)\n if len(ls) <= 2:\n return -1\n else:\n rs = f(ls, ls[0], ls[-1])\n if len(rs) == 0:\n return -1\n else:\n return rs[0]\n\n\nn = int(input())\nxy = [tuple(map(int, input().split())) for _ in range(n)]\n\nans = \"NO\"\nif n <= 4:\n ans = \"YES\"\nelse:\n xy.sort()\n i = g(0, n - 1)\n if i < 0:\n ans = \"YES\"\n elif g(0, i) < 0:\n ans = \"YES\"\n elif g(n - 1, i) < 0:\n ans = \"YES\"\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14384.0, "status": "done"}, {"code": "def colinear(p1, p2, p3):\n return (p1[0]*(p2[1] - p3[1]) + p2[0]*(p3[1] - p1[1]) + p3[0]*(p1[1] - p2[1])) == 0\n\ndef create_options(points):\n p0 = points[0]\n p1 = points[1]\n p2 = points[2]\n p3 = points[3]\n if colinear(p0, p1, p2) and colinear(p1, p2, p3):\n return [(p0, p1), []], 3\n elif colinear(p0, p1, p2):\n return [(p0, p1), [p3]], 3\n elif colinear(p0, p1, p3):\n return [(p0, p1), [p2]], 3\n elif colinear(p0, p2, p3):\n return [(p0, p2), [p1]], 3\n elif colinear(p1, p2, p3):\n return [(p1, p2), [p0]], 3\n else:\n p4 = points[4]\n if colinear(p0, p1, p4):\n return [(p0, p1), [p2, p3]], 4\n elif colinear(p0, p2, p4):\n return [(p0, p2), [p1, p3]], 4\n elif colinear(p0, p3, p4):\n return [(p0, p3), [p1, p2]], 4\n\n elif colinear(p1, p2, p4):\n return [(p1, p2), [p0, p3]], 4\n elif colinear(p1, p3, p4):\n return [(p1, p3), [p0, p2]], 4\n\n elif colinear(p2, p3, p4):\n return [(p2, p3), [p0, p1]], 4\n return False, 4\n\ndef solution(points):\n if len(points) <= 4:\n return True\n options, last = create_options(points)\n\n if not options:\n return False\n\n for p in points[last+1:]:\n if not colinear(options[0][0], options[0][1], p):\n if len(options[1]) < 2:\n options[1].append(p)\n elif not colinear(options[1][0], options[1][1], p):\n return False\n return True\n\ndef __starting_point():\n n = int(input())\n points = [\n tuple(map(int, input().split()))\n for _ in range(n)\n ]\n print(\"YES\" if solution(points) else \"NO\")\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14528.0, "status": "done"}, {"code": "n=int(input().split()[0])\nps=[]\nfor i in range(n):\n a,b=[int(x) for x in input().split()[:2]]\n ps.append([a,b])\n\ndef aline(a,b,c):\n x1=a[1]-b[1]\n x2=c[1]-b[1]\n y1=a[0]-b[0]\n y2=c[0]-b[0]\n if x1*y2==x2*y1:\n return True\n else:\n return False\n\ndef left_fun(a,b,l):\n if len(l)<3:\n return []\n to=[i for i in range(len(l)) if i!=a and i!=b]\n left=[]\n for i in to:\n if not aline(ps[l[a]],ps[l[b]],ps[l[i]]):\n left.append(i)\n return left\n\ndef nm():\n if len(ps)<5:\n print('YES')\n return\n l = [i for i in range(n)]\n left = left_fun(0, 1, l)\n left = left_fun(0, 1, left)\n if len(left) == 0:\n print('YES')\n return\n\n l = [i for i in range(n)]\n left = left_fun(1, 2, l)\n left = left_fun(0, 1, left)\n if len(left) == 0:\n print('YES')\n return\n\n l = [i for i in range(n)]\n left = left_fun(0, 2, l)\n left = left_fun(0, 1, left)\n if len(left) == 0:\n print('YES')\n return\n print('NO')\nnm()\n", "passed": true, "time": 0.14, "memory": 14660.0, "status": "done"}, {"code": "\n\n\t\n\ndef ff(p, q, pp):\n\tnpp = []\n\tfor r in pp:\n\t\tif (p[1] - r[1]) * (p[0] - q[0]) != (p[1] - q[1]) * (p[0] - r[0]):\n\t\t\tnpp.append(r)\n\t\n\tif len(npp) <= 2:\n\t\treturn True\n\t\t\n\ta = npp[0]\n\tb = npp[1]\n\tfor c in npp:\n\t\tif (a[1] - c[1]) * (a[0] - b[0]) != (a[1] - b[1]) * (a[0] - c[0]):\n\t\t\treturn False\n\t\n\treturn True\n\t\n\t\n\t\n\t\n\nn = int(input())\nif n <= 4:\n\tprint('YES')\n\t\n\nelse:\n\tpp = []\n\tfor _ in range(n):\n\t\ta, b = [int(x) for x in input().split()]\n\t\tpp.append((a,b))\n\n\tif ff(pp[0], pp[1],pp) or ff(pp[1], pp[2],pp) or ff(pp[0], pp[2],pp):\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n\t\n\t\n", "passed": true, "time": 0.24, "memory": 14584.0, "status": "done"}, {"code": "from collections import Counter\nfrom random import choice\nfrom sys import stdin\nfrom time import time\n\nfrom math import gcd\n\n\ndef get_v(p0, p1):\n dp = (p1[0] - p0[0], p1[1] - p0[1])\n\n g = gcd(*dp)\n\n if dp[0] > 0:\n return (dp[0] // g, dp[1] // g)\n\n elif dp[0] < 0:\n return (-dp[0] // g, -dp[1] // g)\n\n else:\n return (dp[0] // g, abs(dp[1] // g))\n\n\nall_in = stdin.read().splitlines()\n\nn = int(all_in[0])\npoints = [tuple(map(int, el.split())) for el in all_in[1:]]\n\nif n <= 4:\n print('YES')\n return\n\np_max_ = 1\n\nt = time()\nwhile p_max_ == 1:\n p = choice(points)\n\n v_s = [get_v(p, x) for x in points if x != p]\n\n if len(set(v_s)) <= 2:\n print('YES')\n return\n\n C = Counter(v_s)\n\n p_max, p_max_ = sorted(list(C.items()), key=lambda x: x[1])[-1]\n\n if time() - t > 1.75:\n print('NO')\n return\n\npoints.remove(p)\npoints_ = [points[i - 1] for i in range(1, n) if v_s[i - 1] != p_max]\n\nif len(points_) <= 2:\n print('YES')\n return\n\np_ = choice(points_)\n\nv_s_ = [get_v(p_, x) for x in points_ if x != p_]\n\nif len(set(v_s_)) >= 2:\n print('NO')\n return\n\nprint('YES')\n", "passed": true, "time": 19.4, "memory": 14596.0, "status": "done"}, {"code": "R = lambda: list(map(int, input().split()))\n\nn = int(input())\nps = []\n\ndef ff(a, b):\n pp = [] # left points\n dy = b[1] - a[1]; dx = b[0] - a[0]\n for c in ps:\n if dy*(c[0]-a[0]) != dx*(c[1]-a[1]):\n pp.append(c)\n\n if len(pp) <= 2: return True\n a = pp[0]; b = pp[1]\n dy = b[1] - a[1]; dx = b[0] - a[0]\n for c in pp:\n if dy*(c[0]-a[0]) != dx*(c[1]-a[1]):\n return False\n return True\n\nfor _ in range(n): ps.append(tuple(R()))\nif n <= 4:\n print('YES')\nelse:\n if ff(ps[0], ps[1]) or ff(ps[0], ps[2]) or ff(ps[1], ps[2]):\n print('YES')\n else:\n print('NO')\n\n", "passed": true, "time": 0.14, "memory": 14608.0, "status": "done"}, {"code": "class Point:\n def __init__(self, x, y):\n self.x = x\n self.y = y\n \n def __str__(self):\n return '('+str(self.x)+', '+str(self.y)+')'\n\n def __sub__(self, other):\n # print(\"return sub\", self)\n return Point(self.x - other.x, self.y - other.y)\n \n\ndef cross(a, b):\n return a.x*b.y - b.x*a.y\n\nn = int(input())\npoints = []\nfor _ in range(n):\n x_, y_ = map(int, input().strip().split())\n p = Point(x_, y_)\n points.append(p)\n\ndef check(used):\n nonlocal n, points\n f = -1\n s = -1\n for i in range(n):\n if not used[i]:\n if f == -1:\n f = i\n elif s == -1:\n s = i\n if s == -1:\n return True\n for i in range(n):\n if not used[i]:\n if cross(points[f]-points[s], points[i]-points[f]) != 0:\n return False\n return True\n\ndef solve(a, b):\n nonlocal n, points\n used = [False]*n\n for i in range(n):\n if cross(a-b, points[i]-a) == 0:\n used[i] = True\n \n return check(used)\n\ndef solution():\n nonlocal points\n if len(points) <= 2:\n print('YES')\n return \n ans = False\n if (solve(points[0], points[1]) or solve(points[0], points[2]) or solve(points[1], points[2])):\n ans = True\n \n if ans:\n print(\"YES\")\n else:\n print('NO')\n\nsolution()", "passed": true, "time": 0.24, "memory": 14632.0, "status": "done"}, {"code": "import sys\n\nimport random\n\n\n\nn = int(input())\nif n<=3:\n print('YES')\n return\ncoord = [int(x) for line in sys.stdin for x in line.split()]\n\n\nX = [coord[2*i] for i in range(n)]\nY = [coord[2*i+1] for i in range(n)]\n\n\nfor i in range(13):\n a = random.randint(0,n-1)\n b = random.randint(0,n-2)\n \n if a==b:\n b+=1\n \n x0,y0 = X[a],Y[a]\n x1,y1 = X[b],Y[b]\n \n dx = x1-x0\n dy = y1-y0\n not_on_line = []\n for c in range(n):\n if c==a or c==b:\n continue\n x2,y2 = X[c],Y[c]\n Dx = x2-x0\n Dy = y2-y0\n if dx*Dy-dy*Dx!=0:\n not_on_line.append(c)\n if len(not_on_line)<=1:\n print('YES')\n return\n\n\n a = not_on_line[0]\n b = not_on_line[1]\n x0,y0 = X[a],Y[a]\n x1,y1 = X[b],Y[b]\n \n dx = x1-x0\n dy = y1-y0\n can = True\n for c in not_on_line:\n if c==a or c==b:\n continue\n x2,y2 = X[c],Y[c]\n Dx = x2-x0\n Dy = y2-y0\n if dx*Dy-dy*Dx!=0:\n can = False\n break\n if can:\n print('YES')\n return\nprint('NO')", "passed": true, "time": 0.15, "memory": 14480.0, "status": "done"}, {"code": "n=int(input())\nimport sys\npts=[]\nfor i in range(n):\n x,y=map(int,input().split())\n pts.append([x,y])\nif(n<=4):\n print('YES')\n return\nb1=pts[0][0]-pts[1][0]\na1=pts[1][1]-pts[0][1]\nc1=-a1*pts[0][0] - b1*pts[0][1]\na2=0\nb2=0\nc2=1\np=[]\nflag=True\nfor i in range(n):\n if(a1*pts[i][0]+b1*pts[i][1]+c1!=0 and a2*pts[i][0]+b2*pts[i][1]+c2!=0 ):\n p.append(pts[i])\n if(len(p)==2):\n \n b2=p[0][0]-p[1][0]\n a2=p[1][1]-p[0][1]\n c2=-a2*p[0][0] - b2*p[0][1]\n if(len(p)>2):\n flag=False\n break\nif(flag):\n print(\"YES\")\n #print(1,p)\n return\nP=p\np=[pts[0],P[0]]\nb1=p[0][0]-p[1][0]\na1=p[1][1]-p[0][1]\nc1=-a1*p[0][0] - b1*p[0][1]\np=[]\na2=0\nb2=0\nc2=1\nflag=True\nfor i in range(n):\n if(a1*pts[i][0]+b1*pts[i][1]+c1!=0 and a2*pts[i][0]+b2*pts[i][1]+c2!=0 ):\n p.append(pts[i])\n #print('here in 2 ',pts[i])\n if(len(p)==2):\n \n b2=p[0][0]-p[1][0]\n a2=p[1][1]-p[0][1]\n c2=-a2*p[0][0] - b2*p[0][1]\n if(len(p)>2):\n flag=False\n break\nif(flag):\n #print(2,p)\n #print(a1,b1,c1,a2,b2,c2)\n print(\"YES\")\n return\n \n \n\np=[P[0],pts[1]]\nb1=p[0][0]-p[1][0]\na1=p[1][1]-p[0][1]\nc1=-a1*p[0][0] - b1*p[0][1]\np=[]\na2=0\nb2=0\nc2=1\nflag=True\nfor i in range(n):\n if(a1*pts[i][0]+b1*pts[i][1]+c1!=0 and a2*pts[i][0]+b2*pts[i][1]+c2!=0 ):\n p.append(pts[i])\n if(len(p)==2):\n \n b2=p[0][0]-p[1][0]\n a2=p[1][1]-p[0][1]\n c2=-a2*p[0][0] - b2*p[0][1]\n if(len(p)>2):\n \n flag=False\n break\nif(flag):\n print(\"YES\")\n #print(3,p)\n return\nprint(\"NO\")", "passed": true, "time": 0.22, "memory": 14552.0, "status": "done"}, {"code": "n = int(input())\n\nlst = []\nfor x in range(n):\n (a, b) = list(map(int, input().split()))\n lst.append((a, b))\n\ndef scal(x1, y1, x2, y2, x3, y3):\n if (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1) == 0:\n return True\n return False\n\ndef check():\n for x in range(n - 2):\n if len(s2) >= 3:\n if not scal(lst[s2[-3]][0], lst[s2[-3]][1], lst[s2[-2]][0], lst[s2[-2]][1], lst[s2[-1]][0], lst[s2[-1]][1]):\n return False\n if scal(lst[0][0], lst[0][1], lst[1][0], lst[1][1], lst[x + 2][0], lst[x + 2][1]):\n s1.append(x + 2)\n else:\n s2.append(x + 2)\n if len(s2) >= 3:\n if not scal(lst[s2[-3]][0], lst[s2[-3]][1], lst[s2[-2]][0], lst[s2[-2]][1], lst[s2[-1]][0], lst[s2[-1]][1]):\n return False\n return True\n\nflag = True\n\nif n >= 5:\n s1 = []\n s2 = []\n if not check():\n lst[1], lst[s2[0]] = lst[s2[0]], lst[1]\n x = s2[0]\n s1 = []\n s2 = []\n if not check():\n lst[0], lst[s2[0]] = lst[s2[0]], lst[0]\n s1 = []\n s2 = []\n if not check():\n flag = False\n\nif flag:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14564.0, "status": "done"}, {"code": "import sys\nimport math\n\n\ndef main():\n i = sys.stdin.readlines()\n\n n = int(i[0].strip())\n points = []\n for pi in range(n):\n p = i[pi + 1]\n x, y = p.strip().split()\n points.append([int(x), int(y)])\n\n if n < 5:\n print('YES')\n return\n\n st = [False] * n\n\n def run(first, second):\n dx = first[0] - second[0]\n dy = first[1] - second[1]\n\n for i, p in enumerate(points):\n if st[i]:\n continue\n if dx == 0:\n if p[0] == first[0]:\n st[i] = True\n elif dy == 0:\n if p[1] == first[1]:\n st[i] = True\n else:\n # kx = (p[0] - first[0]) / dx\n # ky = (p[1] - first[1]) / dy\n # if math.isclose(kx, ky):\n # st[i] = True\n if ((p[0] - first[0]) * dy) == (p[1] - first[1]) * dx:\n st[i] = True\n\n def check(fi, si):\n for i in range(n):\n st[i] = i == fi or i == si\n\n run(points[fi], points[si])\n\n fi = None\n si = None\n for i in range(n-1):\n if not st[i]:\n fi = i\n for j in range(i+1, n):\n if not st[j]:\n si = j\n break\n break\n if fi is None or si is None:\n return True\n\n st[fi] = True\n st[si] = True\n run(points[fi], points[si])\n return not (False in st)\n\n if check(0, 1) or check(0, 2) or check(1, 2):\n print('YES')\n else:\n print('NO')\n\n\n\n\nmain()", "passed": true, "time": 0.15, "memory": 14676.0, "status": "done"}, {"code": "n = int(input())\np = [list(map(int, input().split())) for _ in range(n)]\nf = lambda a, b, c: (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])\ndef g(fi, se, p):\n q = []\n for x in p:\n if f(fi, se, x):\n if len(q) < 2:\n q.append(x)\n else:\n if f(q[0], q[1], x):\n return 1\n return 0\nprint('NO' if n > 4 and all([g(p[0], p[1], p), g(p[0], p[2], p), g(p[1], p[2], p)]) else 'YES')\n\n", "passed": true, "time": 0.14, "memory": 14432.0, "status": "done"}, {"code": "def cross(a, b):\n return a[0] * b[1] - a[1] * b[0]\n\n\ndef f(v, i1, i2):\n d = [v[i2][i] - v[i1][i] for i in range(len(v[i1]))]\n\n res = []\n for x in v:\n d2 = [x[i] - v[i1][i] for i in range(len(v[i1]))]\n if cross(d, d2) != 0:\n res.append(x)\n\n return res\n\n\nn = int(input())\nif n <= 4:\n print(\"YES\")\n return\n\nv = []\nfor i in range(n):\n v.append(list(map(int, input().split())))\n\nok = False\nfor first in range(3):\n if ok:\n break\n\n for second in range(first+1, 3):\n other = f(v, first, second)\n\n if len(other) <= 2:\n ok = True\n break\n\n remainder = f(other, 0, 1)\n\n if not remainder:\n ok = True\n\n\nif ok:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14460.0, "status": "done"}, {"code": "class Point:\n\n def __init__(self, x, y):\n self.x = x\n self.y = y\n\n\nclass Vector:\n\n def __init__(self, start, end):\n self.x = end.x - start.x\n self.y = end.y - start.y\n\n def mult(self, a):\n return self.y * a.x - self.x * a.y\n\nn = int(input())\npoints = []\nfor i in range(n):\n x, y = list(map(int, input().split()))\n points.append(Point(x, y))\n\nif n <= 3:\n print('YES')\n return\n\n\ndef onLine(points):\n n = len(points)\n if n < 3:\n return True\n a = Vector(points[0], points[1])\n for i in range(2, n):\n b = Vector(points[0], points[i])\n if a.mult(b) != 0:\n return False\n return True\n\ntmp = [points[0], points[1]]\noth = []\nfor i in range(2, n):\n tmp.append(points[i])\n if not onLine(tmp):\n oth.append(points[i])\n tmp.pop()\nif onLine(oth):\n print('YES')\n return\n\ntmp = [points[0], points[2]]\noth = []\nfor i in range(1, n):\n if i == 2:\n continue\n tmp.append(points[i])\n if not onLine(tmp):\n oth.append(points[i])\n tmp.pop()\nif onLine(oth):\n print('YES')\n return\n\ntmp = [points[1], points[2]]\noth = []\nfor i in range(0, n):\n if i == 2 or i == 1:\n continue\n tmp.append(points[i])\n if not onLine(tmp):\n oth.append(points[i])\n tmp.pop()\nif onLine(oth):\n print('YES')\n return\n\nprint('NO')\n", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "def iscollinear(p1, p2, p3):\n x1, y1 = p1\n x2, y2 = p2\n x3, y3 = p3\n cross = (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)\n ans = bool(cross)\n return not ans\n\ndef checkfortwolines(a, b, points):\n set1 = set(points)\n for i in range(n): # erase all points collinear with a, b\n if iscollinear(a, b, points[i]): set1.remove(points[i])\n\n if len(set1) <= 2: return True\n else:\n pts1 = list(set1)\n for i in range(len(pts1)): # check if remaining points are all collinear\n if not iscollinear(pts1[0], pts1[1], pts1[i]): return False\n return True\n\nn = int(input())\nif n <= 4: print(\"YES\")\nelse:\n points = [0 for i in range(n)]\n for i in range(n):\n points[i] = tuple(map(int, input().split()))\n a = points[0]\n b = points[1]\n c = points[2]\n if checkfortwolines(a, b, points) or checkfortwolines(b, c, points) or checkfortwolines(c, a, points):\n print(\"YES\")\n else: print(\"NO\") \n\n", "passed": true, "time": 0.14, "memory": 14520.0, "status": "done"}, {"code": "def is_line(b):\n if (len(b) < 3):\n return True\n x1 = b[0][0]\n y1 = b[0][1]\n for i in range(len(b)):\n b[i][0] -= x1\n b[i][1] -= y1\n x2 = b[1][0]\n y2 = b[1][1] \n for i in range(2, len(b)):\n if (x2 * b[i][1] != y2 * b[i][0]):\n return False\n return True\ndef main():\n n = int(input())\n if (n < 5):\n print(\"YES\")\n return\n a = []\n for i in range(n):\n x, y = map(int, input().split())\n a.append([x, y])\n for i1 in range(3):\n x0 = a[i1][0]\n y0 = a[i1][1]\n for i in range(n):\n a[i][0] -= x0\n a[i][1] -= y0\n if (i1 == 0):\n i2 = 1\n x1 = a[1][0]\n y1 = a[1][1]\n elif (i1 == 1):\n i2 = 2\n x1 = a[2][0]\n y1 = a[2][1]\n else:\n i2 = 0\n x1 = a[0][0]\n y1 = a[0][1]\n b = []\n for i in range(n):\n if (i != i1 and i != i2):\n if (x1 * a[i][1] != y1 * a[i][0]):\n b.append([a[i][0], a[i][1]])\n if (is_line(b)):\n print(\"YES\")\n return\n print(\"NO\")\nmain() ", "passed": true, "time": 0.15, "memory": 14468.0, "status": "done"}]
[{"input": "5\n0 0\n0 1\n1 1\n1 -1\n2 2\n", "output": "YES\n"}, {"input": "5\n0 0\n1 0\n2 1\n1 1\n2 3\n", "output": "NO\n"}, {"input": "1\n-1000000000 1000000000\n", "output": "YES\n"}, {"input": "5\n2 -1\n-4 1\n0 -9\n5 -9\n9 -10\n", "output": "NO\n"}, {"input": "5\n6 1\n10 5\n10 -2\n-2 -10\n-4 -9\n", "output": "YES\n"}, {"input": "5\n-10 3\n4 -5\n-9 5\n-5 -3\n-4 -6\n", "output": "NO\n"}, {"input": "5\n2 9\n-1 -4\n-3 -8\n-4 8\n7 2\n", "output": "NO\n"}, {"input": "10\n315 202\n315 203\n315 204\n-138 -298\n-136 -295\n-134 -292\n-132 -289\n-130 -286\n-128 -283\n-126 -280\n", "output": "YES\n"}, {"input": "10\n416 -473\n-162 491\n-164 488\n-170 479\n-166 485\n-172 476\n416 -475\n416 -474\n-168 482\n-160 494\n", "output": "YES\n"}, {"input": "6\n0 0\n1 1\n0 1\n1 0\n0 2\n2 0\n", "output": "NO\n"}, {"input": "5\n3 3\n6 3\n0 0\n10 0\n-10 0\n", "output": "YES\n"}, {"input": "1\n0 0\n", "output": "YES\n"}, {"input": "10\n0 0\n1 0\n0 1\n0 2\n2 0\n3 0\n0 3\n0 4\n4 0\n0 -10000000\n", "output": "YES\n"}, {"input": "6\n0 0\n0 1\n0 2\n1 1\n1 2\n2 1\n", "output": "NO\n"}, {"input": "6\n0 -1\n1 -1\n3 3\n2 0\n-2 -2\n1 -2\n", "output": "NO\n"}, {"input": "5\n1000000000 1000000000\n999999999 999999999\n999999999 999999998\n-1000000000 1000000000\n-1000000000 999999999\n", "output": "NO\n"}, {"input": "5\n0 0\n1 0\n0 1\n1 1\n-1 1\n", "output": "YES\n"}, {"input": "6\n0 0\n0 1\n0 -1\n1 1\n1 -1\n2 -1\n", "output": "NO\n"}, {"input": "4\n0 0\n0 1\n1 0\n1 1\n", "output": "YES\n"}, {"input": "6\n0 0\n1 0\n2 1\n1 1\n0 1\n6 0\n", "output": "YES\n"}, {"input": "10\n536870912 536870912\n268435456 368435456\n268435456 168435456\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n", "output": "NO\n"}, {"input": "5\n0 0\n0 1\n100 100\n100 99\n100 98\n", "output": "YES\n"}, {"input": "8\n0 0\n1 0\n2 1\n1 1\n0 1\n6 0\n5 0\n7 0\n", "output": "YES\n"}, {"input": "5\n0 0\n2 0\n1 1\n0 2\n5 1\n", "output": "YES\n"}, {"input": "7\n0 0\n4 0\n1 1\n2 2\n3 1\n5 1\n6 2\n", "output": "NO\n"}, {"input": "6\n1 1\n2 2\n3 2\n4 1\n5 2\n6 1\n", "output": "YES\n"}, {"input": "8\n0 0\n1 0\n2 0\n3 0\n0 1\n1 1\n2 1\n3 1\n", "output": "YES\n"}, {"input": "12\n0 0\n1 1\n2 2\n3 3\n10 11\n20 11\n30 11\n40 11\n-1 1\n-2 2\n-3 3\n-4 4\n", "output": "NO\n"}, {"input": "6\n0 0\n165580141 267914296\n331160282 535828592\n267914296 433494437\n535828592 866988874\n433494437 701408733\n", "output": "NO\n"}, {"input": "5\n-1000000000 -1000000000\n-588442013 -868997024\n-182303377 -739719081\n-999999999 -999999999\n229254610 -608716105\n", "output": "NO\n"}, {"input": "5\n-1000000000 -1000000000\n229254610 -608716105\n-588442013 -868997024\n-182303377 -739719081\n-176884026 -737994048\n", "output": "YES\n"}, {"input": "6\n0 0\n0 1\n0 2\n5 0\n5 1\n5 -1\n", "output": "YES\n"}, {"input": "5\n-1 1\n1 0\n1 1\n1 -1\n-1 -1\n", "output": "YES\n"}, {"input": "5\n-1000000000 -1000000000\n229254610 -608716105\n-588442013 -868997024\n-182303377 -739719081\n-999999999 -999999999\n", "output": "NO\n"}, {"input": "6\n1 1\n0 0\n-1 -1\n1 0\n0 -1\n-1 -10\n", "output": "NO\n"}, {"input": "5\n8 8\n3303829 10\n10 1308\n4 2\n6 3\n", "output": "NO\n"}, {"input": "5\n0 0\n0 1\n0 2\n0 3\n1 0\n", "output": "YES\n"}, {"input": "5\n0 0\n165580142 267914296\n331160283 535828592\n267914296 433494437\n535828592 866988874\n", "output": "YES\n"}, {"input": "59\n1 0\n0 2\n0 3\n0 4\n0 5\n6 0\n7 0\n8 0\n9 0\n10 0\n0 11\n12 0\n13 0\n14 0\n15 0\n0 16\n0 17\n18 0\n19 0\n20 0\n21 0\n0 22\n23 0\n24 0\n0 25\n26 0\n27 0\n0 28\n0 29\n30 0\n31 0\n0 32\n33 0\n34 0\n0 35\n0 36\n37 0\n0 38\n39 0\n40 0\n0 41\n42 0\n0 43\n0 44\n0 45\n0 46\n47 0\n0 48\n0 49\n50 0\n0 51\n0 52\n53 0\n0 54\n55 0\n0 56\n57 0\n0 58\n59 0\n", "output": "YES\n"}, {"input": "5\n10000000 40000100\n3 112\n2 400000100\n1 104\n1000000 701789036\n", "output": "YES\n"}, {"input": "5\n514 2131\n312 52362\n1 1\n2 2\n3 3\n", "output": "YES\n"}, {"input": "9\n-65536 65536\n0 65536\n65536 65536\n-65536 0\n0 0\n65536 0\n-65536 -65536\n0 -65536\n65536 -65536\n", "output": "NO\n"}, {"input": "5\n0 -7\n0 10000\n1 1000000000\n100 0\n200 0\n", "output": "NO\n"}, {"input": "7\n0 0\n2 2\n2 -2\n-2 2\n-2 -2\n0 1\n0 3\n", "output": "NO\n"}, {"input": "5\n3 0\n4 1\n0 0\n1 1\n2 2\n", "output": "YES\n"}, {"input": "5\n-65536 -65536\n65536 0\n131072 0\n0 65536\n0 131072\n", "output": "NO\n"}, {"input": "4\n0 0\n1 0\n0 1\n1 1\n", "output": "YES\n"}, {"input": "6\n0 0\n2 0\n0 2\n0 -2\n-2 1\n-4 2\n", "output": "NO\n"}, {"input": "5\n-1000000000 -1000000000\n134903170 -298591267\n-566505563 -732085704\n-298591267 -566505563\n-133011126 -464171408\n", "output": "YES\n"}, {"input": "5\n-1000000000 -1000000000\n134903170 -298591267\n-566505563 -732085704\n-298591267 -566505563\n-999999999 -999999999\n", "output": "NO\n"}, {"input": "5\n1 1\n-1 0\n0 1\n-1 1\n0 0\n", "output": "YES\n"}, {"input": "5\n0 0\n-1 -1\n0 -1\n-1 1\n-1 0\n", "output": "YES\n"}, {"input": "5\n0 0\n-1 1\n-1 0\n0 -1\n-1 -1\n", "output": "YES\n"}, {"input": "6\n0 0\n-1 1\n-1 0\n1 1\n-1 -1\n0 -1\n", "output": "NO\n"}, {"input": "5\n-1 2\n-1 1\n2 1\n-2 2\n1 1\n", "output": "YES\n"}, {"input": "6\n-1 -1\n-1 -2\n-1 -3\n1000000000 1\n-1000000000 0\n999999999 1\n", "output": "NO\n"}, {"input": "6\n-1 -1\n-1 -2\n-1 -3\n0 0\n65536 65536\n65536 131072\n", "output": "NO\n"}, {"input": "6\n-1 -1\n-1 -2\n-1 -3\n1000000000 1\n999999999 1\n-1000000000 0\n", "output": "NO\n"}, {"input": "3\n-1 1\n-1 -1\n0 0\n", "output": "YES\n"}, {"input": "7\n1 -1\n3 -3\n1 2\n0 -2\n1 -3\n0 1\n0 2\n", "output": "NO\n"}, {"input": "4\n0 0\n-1 1\n-1 -1\n1 0\n", "output": "YES\n"}, {"input": "6\n0 0\n0 1\n-1 1\n0 -1\n1 0\n-1 -1\n", "output": "NO\n"}, {"input": "5\n1 1\n0 0\n-1 0\n0 1\n1 0\n", "output": "YES\n"}, {"input": "11\n-2 -2\n2 3\n3 -2\n1 -2\n2 -2\n2 0\n2 2\n-3 -2\n-1 -2\n2 -3\n2 1\n", "output": "YES\n"}, {"input": "5\n0 0\n-1 0\n-1 1\n1 0\n1 -1\n", "output": "YES\n"}, {"input": "5\n1 -1\n0 0\n0 1\n-1 1\n1 1\n", "output": "YES\n"}, {"input": "5\n0 0\n1 1\n0 -2\n1 -1\n1 2\n", "output": "YES\n"}, {"input": "5\n-999999998 -999999998\n229254612 -608716103\n-588442011 -868997022\n-182303375 -739719079\n-176884024 -737994046\n", "output": "YES\n"}]
248
Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both Memory and Lexa get some integer in the range [ - k;k] (i.e. one integer among - k, - k + 1, - k + 2, ..., - 2, - 1, 0, 1, 2, ..., k - 1, k) and add them to their current scores. The game has exactly t turns. Memory and Lexa, however, are not good at this game, so they both always get a random integer at their turn. Memory wonders how many possible games exist such that he ends with a strictly higher score than Lexa. Two games are considered to be different if in at least one turn at least one player gets different score. There are (2k + 1)^2t games in total. Since the answer can be very large, you should print it modulo 10^9 + 7. Please solve this problem for Memory. -----Input----- The first and only line of input contains the four integers a, b, k, and t (1 ≀ a, b ≀ 100, 1 ≀ k ≀ 1000, 1 ≀ t ≀ 100)Β β€” the amount Memory and Lexa start with, the number k, and the number of turns respectively. -----Output----- Print the number of possible games satisfying the conditions modulo 1 000 000 007 (10^9 + 7) in one line. -----Examples----- Input 1 2 2 1 Output 6 Input 1 1 1 2 Output 31 Input 2 12 3 1 Output 0 -----Note----- In the first sample test, Memory starts with 1 and Lexa starts with 2. If Lexa picks - 2, Memory can pick 0, 1, or 2 to win. If Lexa picks - 1, Memory can pick 1 or 2 to win. If Lexa picks 0, Memory can pick 2 to win. If Lexa picks 1 or 2, Memory cannot win. Thus, there are 3 + 2 + 1 = 6 possible games in which Memory wins.
interview
[{"code": "mod=10**9+7\nf=[0]*500000\n\ndef POW(a,b):\n\tif(b==0):\n\t\treturn 1\n\tif(b&1):\n\t\treturn POW(a,b//2)**2*a%mod\n\telse:\n\t\treturn POW(a,b//2)**2\n\ndef C(n,m):\n\tif(m>n):\n\t\treturn 0\n\tt=f[n]*POW(f[m],mod-2)%mod*POW(f[n-m],mod-2)%mod\n\treturn t\n\n\nf[0]=1\nfor i in range(1,500000):\n\tf[i]=f[i-1]*i%mod\na,b,k,t=list(map(int,input().split(' ')))\n\nans=0\nfor i in range(0,2*t+1):\n\tt1=POW(-1,i)*C(2*t,i)%mod\n\tt2=(C(210000+2*k*t-a+b+2*t-1-(2*k+1)*i+1,2*t)-C(1+2*k*t-a+b+2*t-1-(2*k+1)*i,2*t))%mod\n\tans=(ans+t1*t2)%mod\nprint(ans)\n", "passed": true, "time": 6.33, "memory": 33212.0, "status": "done"}, {"code": "def c(n, k):\n\tif k > n:\n\t\treturn 0\n\ta = b = 1\n\tfor i in range(n - k + 1, n + 1):\n\t\ta *= i\n\tfor i in range(1, k + 1):\n\t\tb *= i\n\treturn a // b\na, b, k, t = map(int, input().split())\nn, m, s = 2 * k + 1, 2 * t, 2 * k * t + b - a\nans, mod = 0, 1000000007\nfor i in range(m + 1):\n\tans = (ans + [1, -1][i & 1] * c(m, i) * c(m + s - n * i, m)) % mod\nprint((pow(n, m, mod) - ans) % mod)", "passed": true, "time": 0.26, "memory": 14360.0, "status": "done"}]
[{"input": "1 2 2 1\n", "output": "6\n"}, {"input": "1 1 1 2\n", "output": "31\n"}, {"input": "2 12 3 1\n", "output": "0\n"}, {"input": "4 6 2 1\n", "output": "3\n"}, {"input": "4 6 2 2\n", "output": "122\n"}, {"input": "6 4 2 2\n", "output": "435\n"}, {"input": "10 1 3 3\n", "output": "112812\n"}, {"input": "5 3 1 1\n", "output": "8\n"}, {"input": "50 22 5 5\n", "output": "876439301\n"}, {"input": "6 20 1 1\n", "output": "0\n"}, {"input": "42 42 2 3\n", "output": "6937\n"}, {"input": "42 42 3 2\n", "output": "1085\n"}, {"input": "45 54 4 5\n", "output": "433203628\n"}, {"input": "6 5 4 3\n", "output": "282051\n"}, {"input": "42 42 42 42\n", "output": "284470145\n"}, {"input": "1 100 42 42\n", "output": "58785421\n"}, {"input": "1 100 1000 100\n", "output": "542673827\n"}, {"input": "1 1 1000 100\n", "output": "922257788\n"}, {"input": "100 100 1000 100\n", "output": "922257788\n"}, {"input": "1 8 1 4\n", "output": "1\n"}, {"input": "9 4 5 2\n", "output": "11045\n"}, {"input": "2 6 6 2\n", "output": "8015\n"}, {"input": "7 8 5 9\n", "output": "860378382\n"}, {"input": "3 7 8 6\n", "output": "510324293\n"}, {"input": "69 69 803 81\n", "output": "74925054\n"}, {"input": "67 67 871 88\n", "output": "123371511\n"}, {"input": "71 71 891 31\n", "output": "790044038\n"}, {"input": "49 49 631 34\n", "output": "764129060\n"}, {"input": "83 83 770 49\n", "output": "761730117\n"}, {"input": "49 49 163 15\n", "output": "458364105\n"}, {"input": "38 38 701 74\n", "output": "496603581\n"}, {"input": "65 65 803 79\n", "output": "253679300\n"}, {"input": "56 56 725 64\n", "output": "338598412\n"}, {"input": "70 70 176 56\n", "output": "990579000\n"}, {"input": "32 32 44 79\n", "output": "20803934\n"}, {"input": "35 35 353 21\n", "output": "149936279\n"}, {"input": "57 57 896 52\n", "output": "271910130\n"}, {"input": "86 86 373 19\n", "output": "940701970\n"}, {"input": "27 27 296 97\n", "output": "394599845\n"}, {"input": "60 60 86 51\n", "output": "277883413\n"}, {"input": "40 40 955 95\n", "output": "600387428\n"}, {"input": "34 34 706 59\n", "output": "274236101\n"}, {"input": "74 74 791 51\n", "output": "367968499\n"}, {"input": "69 69 443 53\n", "output": "385620893\n"}, {"input": "59 19 370 48\n", "output": "125206836\n"}, {"input": "78 82 511 33\n", "output": "375900871\n"}, {"input": "66 90 805 16\n", "output": "593436252\n"}, {"input": "60 61 772 19\n", "output": "931528755\n"}, {"input": "81 13 607 21\n", "output": "762608093\n"}, {"input": "35 79 128 21\n", "output": "177972209\n"}, {"input": "93 25 958 20\n", "output": "873170266\n"}, {"input": "44 85 206 80\n", "output": "170080402\n"}, {"input": "79 99 506 18\n", "output": "486170430\n"}, {"input": "97 22 29 8\n", "output": "471632954\n"}, {"input": "14 47 184 49\n", "output": "726421144\n"}, {"input": "74 33 868 5\n", "output": "826980486\n"}, {"input": "53 79 823 11\n", "output": "526626321\n"}, {"input": "99 99 913 42\n", "output": "446683872\n"}, {"input": "52 34 89 41\n", "output": "905639400\n"}, {"input": "87 100 200 80\n", "output": "913761305\n"}, {"input": "40 94 510 53\n", "output": "233079261\n"}, {"input": "2 56 438 41\n", "output": "500592304\n"}, {"input": "6 68 958 41\n", "output": "719351710\n"}, {"input": "44 80 814 26\n", "output": "414148151\n"}, {"input": "100 1 1000 100\n", "output": "603336175\n"}, {"input": "1 3 1000 100\n", "output": "604187087\n"}, {"input": "10 10 1000 100\n", "output": "922257788\n"}]
249
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler! However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a_1, a_2, ..., a_{n}, where a_{i} denotes the distance of the i-th mark from the origin (a_1 = 0, a_{n} = l). Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≀ i ≀ j ≀ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, a_{j} - a_{i} = d). Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y. Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler. -----Input----- The first line contains four positive space-separated integers n, l, x, y (2 ≀ n ≀ 10^5, 2 ≀ l ≀ 10^9, 1 ≀ x < y ≀ l) β€” the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly. The second line contains a sequence of n integers a_1, a_2, ..., a_{n} (0 = a_1 < a_2 < ... < a_{n} = l), where a_{i} shows the distance from the i-th mark to the origin. -----Output----- In the first line print a single non-negative integer v β€” the minimum number of marks that you need to add on the ruler. In the second line print v space-separated integers p_1, p_2, ..., p_{v} (0 ≀ p_{i} ≀ l). Number p_{i} means that the i-th mark should be at the distance of p_{i} centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them. -----Examples----- Input 3 250 185 230 0 185 250 Output 1 230 Input 4 250 185 230 0 20 185 250 Output 0 Input 2 300 185 230 0 300 Output 2 185 230 -----Note----- In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark. In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks. In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.
interview
[{"code": "def main():\n n,l,x,y = list(map(int,input().split()))\n arr = set(map(int,input().split()))\n first = False\n second = False\n for i in arr:\n if i+x in arr:\n first = True\n if i+y in arr:\n second = True\n\n if first and not second:\n print(1)\n print(y)\n return\n if second and not first:\n print(1)\n print(x)\n return\n if first and second:\n print(0)\n return\n\n found = False\n for i in arr:\n if i+x-y in arr and i+x <= l:\n found = True\n coord = i+x\n break\n\n if i+y-x in arr and i+y <= l:\n found = True\n coord = i+y\n break\n\n if i+x+y in arr and i+min(x,y) <= l:\n found = True\n coord = i+min(x,y)\n\n if i-x-y in arr and i-max(x,y) >= 0:\n found = True\n coord = i-max(x,y)\n\n if i-x+y in arr and i-x >= 0:\n found = True\n coord = i-x\n break\n\n if i-y+x in arr and i-y >= 0:\n found = True\n coord = i-y\n break\n\n if found:\n break\n\n if found:\n print(1)\n print(coord)\n return\n\n print(2)\n print(x,y)\n\n\nmain()\n", "passed": true, "time": 0.14, "memory": 14656.0, "status": "done"}, {"code": "def __starting_point():\t\n\tn, l, x, y = list(map(int, input().split()))\n\tv = list(map(int, input().split()))\n\ts = set(v)\n\n\tcx = 0\n\tfor i in range(n):\n\t\tif v[i]+x in s:\n\t\t\tcx = 1\n\t\t\tbreak\n\t\n\tcy = 0\n\tfor i in range(n):\n\t\tif v[i]+y in s:\n\t\t\tcy = 1\n\t\t\tbreak\n\t\n\tcount = 0\n\tans = []\n\n\tif cx==0:\n\t\tcount += 1\n\t\tans.append(x)\n\tif cy==0:\n\t\tcount += 1\n\t\tans.append(y)\n\n\tif count==2:\n\t\tfor i in range(n):\n\t\t\tif (v[i]+x+y in s):\n\t\t\t\tcount = 1\n\t\t\t\tans = [v[i]+x]\n\t\t\t\tbreak\n\n\tif count==2:\n\t\tfor i in range(n):\n\t\t\tif (v[i]+x-y in s):\n\t\t\t\tif v[i]+x<=l:\n\t\t\t\t\tcount = 1\n\t\t\t\t\tans = [v[i]+x]\n\t\t\t\t\tbreak\n\t\t\t\telif v[i]-y>=0:\n\t\t\t\t\tcount = 1\n\t\t\t\t\tans = [v[i]-y]\n\t\t\t\t\tbreak\n\n\tprint(count)\n\tif count!=0:\n\t\tprint(*ans)\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14428.0, "status": "done"}]
[{"input": "3 250 185 230\n0 185 250\n", "output": "1\n230\n"}, {"input": "4 250 185 230\n0 20 185 250\n", "output": "0\n"}, {"input": "2 300 185 230\n0 300\n", "output": "2\n185 230\n"}, {"input": "4 300 4 5\n0 6 7 300\n", "output": "1\n11\n"}, {"input": "2 100 30 70\n0 100\n", "output": "1\n30\n"}, {"input": "2 300 140 160\n0 300\n", "output": "1\n140\n"}, {"input": "4 300 1 2\n0 298 299 300\n", "output": "0\n"}, {"input": "3 350 150 160\n0 310 350\n", "output": "1\n150\n"}, {"input": "4 300 4 5\n0 298 299 300\n", "output": "1\n294\n"}, {"input": "19 180 117 148\n0 1 19 20 21 28 57 65 68 70 78 88 100 116 154 157 173 179 180\n", "output": "2\n117 148\n"}, {"input": "14 134 99 114\n0 6 8 19 50 61 69 83 84 96 111 114 125 134\n", "output": "1\n99\n"}, {"input": "18 187 27 157\n0 17 18 31 36 37 40 53 73 86 96 107 119 150 167 181 184 187\n", "output": "1\n27\n"}, {"input": "20 179 69 120\n0 6 8 11 21 24 55 61 83 84 96 111 114 116 125 140 147 154 176 179\n", "output": "1\n27\n"}, {"input": "16 115 62 112\n0 5 24 32 38 43 44 57 62 72 74 92 103 105 113 115\n", "output": "1\n112\n"}, {"input": "112 1867 1261 1606\n0 7 17 43 67 70 87 112 129 141 148 162 179 180 189 202 211 220 231 247 250 277 308 311 327 376 400 406 409 417 418 444 480 512 514 515 518 547 572 575 578 587 612 617 654 684 701 742 757 761 788 821 825 835 841 843 850 858 869 872 881 936 939 969 970 971 997 1026 1040 1045 1068 1070 1073 1076 1095 1110 1115 1154 1166 1178 1179 1203 1204 1225 1237 1241 1246 1275 1302 1305 1311 1312 1315 1338 1340 1419 1428 1560 1561 1576 1591 1594 1618 1643 1658 1660 1664 1689 1803 1822 1835 1867\n", "output": "1\n1808\n"}, {"input": "2 2 1 2\n0 2\n", "output": "1\n1\n"}, {"input": "3 2 1 2\n0 1 2\n", "output": "0\n"}, {"input": "3 10 2 3\n0 1 10\n", "output": "1\n3\n"}, {"input": "4 10 3 5\n0 1 9 10\n", "output": "1\n4\n"}, {"input": "5 1000 777 778\n0 1 500 501 1000\n", "output": "1\n778\n"}, {"input": "3 10 1 3\n0 2 10\n", "output": "1\n3\n"}, {"input": "4 300 120 150\n0 110 140 300\n", "output": "1\n260\n"}, {"input": "5 401 300 400\n0 100 250 350 401\n", "output": "1\n400\n"}, {"input": "3 10 1 8\n0 7 10\n", "output": "1\n8\n"}, {"input": "4 1000 2 3\n0 400 405 1000\n", "output": "1\n402\n"}, {"input": "6 12 7 10\n0 1 3 4 6 12\n", "output": "1\n10\n"}, {"input": "4 1000 10 20\n0 500 530 1000\n", "output": "1\n510\n"}, {"input": "3 8 2 3\n0 7 8\n", "output": "1\n5\n"}, {"input": "4 10 8 9\n0 4 5 10\n", "output": "2\n8 9\n"}, {"input": "4 10 7 8\n0 5 6 10\n", "output": "2\n7 8\n"}, {"input": "6 35 29 30\n0 10 11 31 32 35\n", "output": "1\n2\n"}, {"input": "5 200000 1 100029\n0 100000 100009 100010 200000\n", "output": "1\n100029\n"}, {"input": "4 1000 900 901\n0 950 951 1000\n", "output": "1\n50\n"}, {"input": "6 504 400 500\n0 3 5 103 105 504\n", "output": "1\n503\n"}, {"input": "5 550 300 400\n0 151 251 450 550\n", "output": "1\n150\n"}, {"input": "4 300 40 50\n0 280 290 300\n", "output": "1\n240\n"}, {"input": "2 1000000000 100000000 500000000\n0 1000000000\n", "output": "2\n100000000 500000000\n"}, {"input": "4 600 100 400\n0 50 350 600\n", "output": "1\n450\n"}, {"input": "4 100 7 8\n0 3 4 100\n", "output": "1\n11\n"}, {"input": "4 100 80 81\n0 2 3 100\n", "output": "1\n83\n"}, {"input": "3 13 8 10\n0 2 13\n", "output": "1\n10\n"}, {"input": "4 10 7 8\n0 4 5 10\n", "output": "2\n7 8\n"}, {"input": "3 450 100 400\n0 150 450\n", "output": "1\n50\n"}, {"input": "4 500 30 50\n0 20 40 500\n", "output": "1\n50\n"}, {"input": "4 100 10 11\n0 4 5 100\n", "output": "1\n15\n"}, {"input": "2 10 5 7\n0 10\n", "output": "2\n5 7\n"}, {"input": "6 100 70 71\n0 50 51 90 91 100\n", "output": "1\n20\n"}, {"input": "4 9 6 7\n0 4 5 9\n", "output": "2\n6 7\n"}, {"input": "3 10 1 8\n0 3 10\n", "output": "1\n2\n"}, {"input": "3 12 1 2\n0 10 12\n", "output": "1\n1\n"}, {"input": "4 100 3 5\n0 40 48 100\n", "output": "1\n43\n"}, {"input": "3 20 17 18\n0 19 20\n", "output": "1\n2\n"}, {"input": "4 1000 45 46\n0 2 3 1000\n", "output": "1\n48\n"}, {"input": "4 10 5 7\n0 4 6 10\n", "output": "2\n5 7\n"}, {"input": "3 12 1 3\n0 10 12\n", "output": "1\n9\n"}, {"input": "4 20 6 7\n0 1 15 20\n", "output": "1\n7\n"}, {"input": "3 11 3 5\n0 9 11\n", "output": "1\n6\n"}, {"input": "3 100 9 10\n0 99 100\n", "output": "1\n90\n"}, {"input": "3 10 7 8\n0 1 10\n", "output": "1\n8\n"}, {"input": "3 10 5 6\n0 9 10\n", "output": "1\n4\n"}, {"input": "3 10 7 8\n0 9 10\n", "output": "1\n2\n"}, {"input": "3 10 6 7\n0 9 10\n", "output": "1\n3\n"}, {"input": "3 9 6 7\n0 1 9\n", "output": "1\n7\n"}, {"input": "3 1000000000 99 100\n0 1 1000000000\n", "output": "1\n100\n"}, {"input": "4 10 3 5\n0 2 4 10\n", "output": "1\n5\n"}, {"input": "4 100 90 91\n0 7 8 100\n", "output": "1\n98\n"}, {"input": "4 100 80 81\n0 98 99 100\n", "output": "1\n18\n"}]
251
There is a toy building consisting of $n$ towers. Each tower consists of several cubes standing on each other. The $i$-th tower consists of $h_i$ cubes, so it has height $h_i$. Let's define operation slice on some height $H$ as following: for each tower $i$, if its height is greater than $H$, then remove some top cubes to make tower's height equal to $H$. Cost of one "slice" equals to the total number of removed cubes from all towers. Let's name slice as good one if its cost is lower or equal to $k$ ($k \ge n$). [Image] Calculate the minimum number of good slices you have to do to make all towers have the same height. Of course, it is always possible to make it so. -----Input----- The first line contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $n \le k \le 10^9$) β€” the number of towers and the restriction on slices, respectively. The second line contains $n$ space separated integers $h_1, h_2, \dots, h_n$ ($1 \le h_i \le 2 \cdot 10^5$) β€” the initial heights of towers. -----Output----- Print one integer β€” the minimum number of good slices you have to do to make all towers have the same heigth. -----Examples----- Input 5 5 3 1 2 2 4 Output 2 Input 4 5 2 3 4 5 Output 2 -----Note----- In the first example it's optimal to make $2$ slices. The first slice is on height $2$ (its cost is $3$), and the second one is on height $1$ (its cost is $4$).
interview
[{"code": "def ii():\n return int(input())\ndef mi():\n return list(map(int, input().split()))\ndef li():\n return list(mi())\n\nn, k = mi()\nh = li()\nm = max(h)\nf = [0] * (m + 1)\nfor hi in h:\n f[hi] += 1\nfor i in range(m - 1, 0, -1):\n f[i] += f[i + 1]\n\nans = 0\ni = m\nwhile i > 0:\n if f[i] == n:\n break\n j = i\n cur = 0\n while j > 0:\n if cur + f[j] > k:\n break\n cur += f[j]\n j -= 1\n ans += 1\n i = j\nprint(ans)\n", "passed": true, "time": 0.38, "memory": 15336.0, "status": "done"}, {"code": "import sys\nimport os\n\ndef solve(n, k, h):\n h.sort()\n top = h[len(h) - 1]\n\n s = [n] * top\n c = 0\n for i in range(top):\n s[i] = n - c\n while c < n and h[c] == i + 1:\n c += 1\n\n pack = 0\n result = 0\n c = top - 1\n while s[c] < n:\n diff = s[c]\n c -= 1\n\n if pack + diff <= k:\n pack += diff\n else:\n pack = diff\n result += 1\n\n if pack > 0:\n result += 1\n\n return result\n\n\n\ndef main():\n n, k = (int(x) for x in input().split())\n h = list(int(x) for x in input().split())\n print(solve(n, k, h))\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.23, "memory": 15148.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nh = list(map(int, input().split()))\n\nhs = {}\n\nmx = 0\nmn = 10**6\nfor a in h:\n mx = max(mx, a)\n mn = min(mn, a)\n if a not in hs:\n hs[a] = 0\n hs[a] += 1\nans = 0\ncur = 0\ncurcl = 0\nfor i in range(mx, mn, -1):\n if i not in hs:\n nc = 0\n else:\n nc = hs[i]\n if cur + nc + curcl <= k:\n cur += nc + curcl\n curcl += nc\n else:\n ans +=1\n curcl += nc\n cur = curcl\nif cur > 0:\n ans += 1\nprint(ans)\n", "passed": true, "time": 0.31, "memory": 14316.0, "status": "done"}, {"code": "n, k = [int(i) for i in input().split()]\nh = [int(i) for i in input().split()]\nh.sort()\nhh = h[0]\nfor i in range(len(h)):\n h[i] -= hh\ng = [0] * h[-1]\nlast = 0\nfor i in range(1, len(h)):\n if h[i] > h[i-1]:\n for j in range(last, h[i]):\n g[j] = n - i\n last = h[i]\ng.reverse()\ns = 0\nans = 0\nfor i in range(len(g)):\n if s + g[i] > k:\n ans += 1\n s = g[i]\n else:\n s += g[i]\nif s > 0:\n ans += 1\nprint(ans)\n", "passed": true, "time": 0.21, "memory": 14976.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\nhhh = list(map(int,input().split()))\n\nh = [0] *200005\nhp = [0] * 200005\n\nmx = 0\nfor i in hhh:\n h[i] +=1\n mx = max(mx,i)\n\nres = n\nfor j in range(200003):\n hp[j] = res\n res -= h[j]\n\n\nans = 0\nrr = 0\nfor t in range(mx,0,-1):\n if hp[t] == n:\n break\n\n rr += hp[t]\n if rr > k:\n rr = hp[t]\n ans += 1\n\n\n\nif rr:\n ans += 1\n\nprint(ans)\n\n\n", "passed": true, "time": 1.07, "memory": 16928.0, "status": "done"}, {"code": "from sys import stdin\nn,m=list(map(int,stdin.readline().strip().split()))\ns=tuple(map(int,stdin.readline().strip().split()))\nma=max(s)\nmi=min(s)\ndp=[0 for i in range(ma+3)]\nfor i in s:\n dp[i]+=1\nfor i in range(len(dp)-2,-1,-1):\n dp[i]+=dp[i+1]\nx=0\nans=0\nacum=0\nl=-1\nfor i in range(len(dp)-2,mi-1,-1):\n dp[i]+=dp[i+1]\n if dp[i]-acum>m:\n acum=dp[i+1]\n ans+=1\n l=i\nif l!=mi and mi!=ma:\n ans+=1\nprint(ans)\n\n\n", "passed": true, "time": 0.25, "memory": 21260.0, "status": "done"}, {"code": "a,b=map(int,input().split())\nn=list(map(int,input().split()))\nx=0\nz=100000\ni=0\nwhile i<a:\n if n[i]>x:\n x=n[i]\n i+=1\nk=[0]*x\ni=0\nwhile i<a:\n k[n[i]-1]+=1\n i+=1\ni=x-1\nj=1\nz=0\nc=b\nwhile i>-1:\n if k[i]+z==a:\n break\n if k[i]+z<=c:\n c-=k[i]+z\n else:\n c=b-k[i]-z\n j+=1\n z+=k[i]\n i-=1\nif k[x-1]==a:\n print (0)\nelse:\n print (j)", "passed": true, "time": 0.19, "memory": 15016.0, "status": "done"}, {"code": "\ndef main():\n n, k = [int(x) for x in input().split(\" \")]\n h = list([int(x) for x in input().split(\" \")])\n # f[i] i slice to?\n num = [0 for i in range(max(h)+5)]\n\n for i in h:\n num[i] += 1\n\n ans = 0\n now = max(h)\n now_cost = 0\n now_tower = 0\n # print(\"h\", h)\n # print(\"num\", num)\n while now:\n # print(ans, now, now_cost, num[now])\n if num[now] + now_cost <= k:\n pass\n else:\n # print(\"cut\")\n ans += 1\n now_cost = 0\n if num[now] == n:\n break\n now_cost += num[now]\n now -= 1\n num[now] += num[now+1]\n if now_cost != 0:\n # print(\"cut\")\n ans += 1\n print(ans)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.21, "memory": 15268.0, "status": "done"}, {"code": "n, k = [int(x) for x in input().split()]\nh = [int(x) for x in input().split()]\nmih = min(h)\nmah = max(h)\nif mah == mih:\n print(0)\n return\ncotam = dict()\nlotam = list()\nsotam = set()\nfor th in h:\n if th > mih:\n if th in sotam:\n cotam[th] += 1\n else:\n sotam.add(th)\n lotam.append(th)\n cotam[th] = 1\nlotam.sort(reverse=True)\n\nsc = 0\ncc = 0\nrk = 0\nfor i in range(len(lotam)):\n ch = lotam[i]\n nh = (mih if i >= len(lotam) - 1 else lotam[i+1])\n cc += cotam[ch]\n if rk >= cc:\n hrbrk = min(ch-nh, rk // cc)\n rk -= cc * hrbrk\n ch -= hrbrk\n while ch > nh:\n hrbk = min(ch-nh, k // cc)\n sc += 1\n ch -= hrbk\n rk = k - hrbk * cc\nprint(sc)\n", "passed": true, "time": 0.34, "memory": 14424.0, "status": "done"}, {"code": "3\n\nimport math\nimport sys\n\n\nDEBUG = False\n\n\ndef inp():\n return sys.stdin.readline().rstrip()\n\n\ndef dprint(*value, sep=' ', end='\\n'):\n if DEBUG:\n print(*value, sep=sep, end=end)\n\n\ndef solve(N, K, H):\n H.sort(reverse=True)\n while len(H) >= 2 and H[-2] == H[-1]:\n H.pop()\n\n width = 0\n cnt = 0\n remain = 0\n for i in range(len(H) - 1):\n h = H[i]\n h1 = H[i + 1]\n\n width += 1\n\n height = h - h1\n\n dprint('i={} h={} h1={} width={} height={} cnt={} remain={}'.format(\n i, h, h1, width, height, cnt, remain))\n\n if height == 0:\n continue\n\n if remain + width * height < K:\n remain += width * height\n continue\n\n dh = (K - remain) // width\n dprint('dh={}'.format(dh))\n assert dh <= height\n remain = 0\n height -= dh\n cnt += 1\n\n if width * height < K:\n remain += width * height\n continue\n\n dprint('A: height={} cnt={}'.format(height, cnt))\n\n t = K // width\n assert t >= 1\n dprint('t={}'.format(t))\n\n sets = height // t - 1\n dprint('sets={}'.format(sets))\n height -= t * sets\n cnt += sets\n dprint('B: height={} cnt={}'.format(height, cnt))\n\n while width * height >= K:\n height -= t\n cnt += 1\n dprint('C: height={} cnt={}'.format(height, cnt))\n\n assert width * height < K\n remain += height * width\n\n assert remain < K\n if remain > 0:\n cnt += 1\n\n return cnt\n\n\ndef main():\n N, K = [int(e) for e in inp().split()]\n H = [int(e) for e in inp().split()]\n assert len(H) == N\n print(solve(N, K, H))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.21, "memory": 14640.0, "status": "done"}, {"code": "def cell(num):\n if int(num) < num:\n return num + 1\n return num\nn, k = list(map(int,input().split()))\nhi = list(map(int,input().split()))\nhi.sort()\nnum = 0\nif n == 1:\n print(0)\nelse:\n height = hi[-1]\n sumHeight = 0\n num2 = 1\n for i in range(n-2,-1,-1):\n sumHeight2 = sumHeight + num2 * (height - hi[i])\n if sumHeight2 == k:\n num += 1\n sumHeight = 0\n elif sumHeight2 > k:\n num5 = k // num2\n j = height\n num6 = sumHeight\n while num6 <= k:\n num6 += num2\n j -= 1\n num += 1\n num += (j + 1 - hi[i]) // num5\n sumHeight = (j + 1 - hi[i]) % num5 * num2\n else:\n sumHeight = sumHeight2\n height = hi[i]\n num2 += 1\n if sumHeight > 0:\n num += 1\n print(num)\n \n \n", "passed": true, "time": 0.15, "memory": 14604.0, "status": "done"}, {"code": "n, k = list(map( int, input().split() ))\nhs = list( map( int, input().split() ) )\nmh = max( hs )\nh = []\nfor i in range( 0, mh + 1 ):\n h.append( 0 )\nfor hh in hs:\n h[ hh ] += 1\n\nl = 0\ngood = 0\nfor i in range( mh, 0, -1 ):\n if h[ i ] == n:\n break\n if l + h[ i ] > k:\n good += 1\n l = h[ i ]\n else:\n l = l + h[ i ]\n h[ i - 1 ] += h[ i ]\n\nprint( good + ( 1 if l > 0 else 0 ) )\n", "passed": true, "time": 0.22, "memory": 15404.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nb = [0 for i in range(200002)]\nc = [0 for i in range(200002)]\nhmax = 0\nhmin = 200005\na = list(map(int, input().split()))\nfor i in range(n):\n hmax = max(hmax, a[i])\n hmin = min(hmin, a[i])\n c[a[i]] += 1\nb[200000] = c[200000]\nfor i in range(200000 - 1, -1, -1):\n b[i] = b[i + 1] + c[i]\ncur = hmax\nans = 0\n#print(b[:5])\nwhile cur > hmin:\n cnt = 0\n while cnt <= m:\n if (cnt + b[cur] <= m) and cur > hmin:\n cnt += b[cur]\n cur -= 1\n else:\n ans += 1\n cnt = 0\n break\n #print(cur, cnt)\n if cur == hmin:\n break\nprint(ans)", "passed": true, "time": 2.0, "memory": 16872.0, "status": "done"}, {"code": "def get_input_list():\n\treturn list(map(int, input().split()))\nn,k = get_input_list()\nh = get_input_list()\nh.sort()\nl = []\nfor i in range(n-1,0,-1):\n\tif h[i] != h[i-1]:\n\t\tfor _ in range(h[i] - h[i-1]):\n\t\t\tl.append(n-i)\n\nif len(l) == 0:\n\tprint(0)\nelse:\n\tp = 0\n\tr = 1\n\tfor i in l:\n\t\tif p + i <= k:\n\t\t\tp += i\n\t\telse:\n\t\t\tr += 1\n\t\t\tp = i\n\tprint(r)", "passed": true, "time": 0.3, "memory": 15252.0, "status": "done"}, {"code": "towers, max_bite_size = list(map(int, input().strip().split()))\ngen = list(map(int, input().strip().split()))\n\nmax_height = 2 * 10 ** 5\n\nheights = [0] * (max_height)\nfor num in gen:\n heights[num - 1] += 1\n\nnum_blocks = 0\n\nnum_slices = 0\ncurr_slice_size = 0\n\nblock_sizes = [0] * (max_height)\nfor idx, num in enumerate(reversed(heights)):\n if num_blocks + num == towers:\n break\n num_blocks += num\n block_sizes[idx] = num_blocks\n if curr_slice_size + num_blocks > max_bite_size:\n num_slices += 1\n curr_slice_size = num_blocks\n else:\n curr_slice_size += num_blocks\nif curr_slice_size > 0:\n num_slices += 1\nbest_so_far = num_slices\n\n\nnum_slices = 0\ncurr_slice_size = 0\n\nfor num in reversed(block_sizes):\n if curr_slice_size + num > max_bite_size:\n num_slices += 1\n curr_slice_size = num\n else:\n curr_slice_size += num\nif curr_slice_size > 0:\n num_slices += 1\n\nprint(min(num_slices, best_so_far))\n", "passed": true, "time": 2.44, "memory": 16784.0, "status": "done"}, {"code": "from collections import Counter\n\nn, k = list(map(int, input().split()))\nh = list(map(int, input().split()))\n\ncnt = Counter(h)\n\nelems = 0\ncosts = []\n\nhs = list(reversed(sorted(cnt.keys())))\ncur_sum = 0\nans = 0\n\nfor i in range(len(hs) - 1):\n v, c = hs[i], cnt[hs[i]]\n next_v = hs[i+1]\n diff = v - next_v\n elems += c\n\n if cur_sum + elems > k:\n ans += 1\n cur_sum = 0\n \n if cur_sum + diff * elems <= k:\n cur_sum += diff * elems\n else:\n if cur_sum != 0:\n diff -= (k - cur_sum) // elems\n ans += 1\n per_cut = k // elems\n cuts = diff // per_cut\n cur_sum = (diff % per_cut) * elems\n ans += cuts\n \nans += cur_sum > 0\nprint(ans)", "passed": true, "time": 0.17, "memory": 14440.0, "status": "done"}, {"code": "n,k=[int(x) for x in input().split()]\n\nd={}\nns=[int(x) for x in input().split()]\nminn=min(ns)\nns=[x-minn for x in ns]\n\nfor c in ns:\n if c in d:\n d[c]+=1\n else:\n d[c]=1\n\ndef eat(i,need):\n al=(ns[i]-ns[i+1])*d[ns[i]]\n if al>need:\n thick=d[ns[i]]\n eath=need//thick\n d[ns[i] - eath]=d[ns[i]]\n ns[i]-=eath\n return i,0\n if al==need:\n d[ns[i+1]]+=d[ns[i]]\n return i+1,0\n if al<need:\n d[ns[i + 1]] += d[ns[i]]\n return i+1,need-al\n\n\nns=list(d.keys())\nns.sort(reverse=True)\n\n\n\n\nans=0\n\ni=0\nnewn=k\n\nwhile i<len(ns)-1:\n i,newn=eat(i,newn)\n if newn>0 and i>=len(ns)-1:\n ans+=1\n break\n if newn==0:\n ans+=1\n newn=k\n\n\n\n\n\nprint(ans)\n\n\n\n\n", "passed": true, "time": 0.29, "memory": 34416.0, "status": "done"}, {"code": "import math as ma\nimport sys\nfrom decimal import Decimal as dec\nfrom itertools import permutations\n\ndef li():\n\treturn list(map(int , input().split()))\n\n\n# https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/\ndef modInverse(a , m):\n\tm0 = m\n\ty = 0\n\tx = 1\n\tif (m == 1):\n\t\treturn 0\n\twhile (a > 1):\n\t\tq = a // m\n\t\tt = m\n\t\tm = a % m\n\t\ta = t\n\t\tt = y\n\t\ty = x - q * y\n\t\tx = t\n\tif (x < 0):\n\t\tx = x + m0\n\treturn x\n\n\ndef num():\n\treturn map(int , input().split())\n\n\ndef nu():\n\treturn int(input())\n\n\ndef find_gcd(x , y):\n\twhile (y):\n\t\tx , y = y , x % y\n\treturn x\n\n\nn,k=num()\nh=li()\na=[0]*(max(h)+5)\nmx=max(h)\nmn=min(h)\nfo=True\nfor i in range(1,n):\n\tif(h[i]!=h[i-1]):\n\t\tfo=False\n\t\tbreak\nfor i in range(n):\n\ta[0]+=1\n\ta[h[i]+1]-=1\nfor i in range(1,len(a)):\n\ta[i]=a[i]+a[i-1]\ns=a[mx]\ncc=0\nfl=False\nfor i in range(mx-1,mn,-1):\n\tif(s+a[i]>k):\n\t\tfl=True\n\t\ts=a[i]\n\t\tcc+=1\n\telse:\n\t\tfl=False\n\t\ts+=a[i]\nif(s<=k and fo==False):\n\tcc+=1\nprint(cc)", "passed": true, "time": 0.22, "memory": 15748.0, "status": "done"}, {"code": "n,k = map(int,input().split())\narr = list(map(int,input().split()))\n\narr.sort()\nheights = []\ncounter=arr[0]\nfor i in range(n):\n while arr[i]>=counter:\n heights.append(n-i)\n counter+=1\n\nheights.reverse()\n\n\nans=0\ncontainer=0\nfor i in range(len(heights)-1):\n if heights[i]+container<=k:\n container+=heights[i]\n else:\n container=heights[i]\n ans+=1\nif container>0:ans+=1\n\nprint(ans)", "passed": true, "time": 0.18, "memory": 15128.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nA = list(map(int, input().split()))\nA.sort(reverse=True)\n\nans = 0\ng = A[-1]\nh = A[0]\np = 0\ni = 1\nc = 0\nl = 0\nwhile h > g and i < n:\n if A[i] == A[p]:\n p += 1\n i += 1\n continue\n\n for j in range(A[p] - A[i]):\n c += p+1\n l += 1\n if c > k:\n ans += 1\n h -= l-1\n c = p+1\n l = 0\n if h <= g:\n break\n \n p = i\n i += 1\n\nif h > g:\n ans += 1\n \nprint(ans)", "passed": true, "time": 0.18, "memory": 14364.0, "status": "done"}, {"code": "[n, k] = [int(i) for i in input().split()]\n\nh = [0 for i in range(2 * 10 ** 5 + 1)]\n\nfor i in input().split():\n\th[int(i)] += 1\nh[0] = n\nans = 0\ncur = 0\nij = 0\nfor i in range(2 * 10 ** 5, -1, -1):\n\t#print(i, ans, cur)\n\tij += h[i]\n\tif ij == n:\n\t\tans += (cur != 0)\n\t\tprint(ans)\n\t\treturn\n\tif cur + ij <= k:\n\t\tcur += ij\n\telse:\n\t\tans += 1\n\t\tcur = ij\n\n", "passed": true, "time": 1.7, "memory": 15396.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\na.sort()\nhs1 = [0 for _ in range(a[-1])]\nfor i in range(n):\n hs1[a[i] - 1] += 1\npluser = 0\nhs = [0 for _ in range(a[-1])]\nfor i in range(a[-1]):\n pluser += hs1[a[-1] - i - 1]\n hs[a[-1] - i - 1] = pluser\nfloor = a[-1] - 1\nans = 0\ncount = 0\nwhile floor > a[0] - 1:\n while floor > a[0] - 1 and count + hs[floor] <= k:\n count += hs[floor]\n floor -= 1\n ans += 1\n count = 0\nprint(ans)\n", "passed": true, "time": 0.34, "memory": 16760.0, "status": "done"}, {"code": "\nn,k=list(map(int,input().split()))\n\nh=list(map(int,input().split()))\nmin1=min(h)\n\nm=max(h)+1 - min1\na=[0 for i in range(m+5)]\n\nfor i in range(n):\n h[i]-=min1\n a[h[i]]+=1\n\nfor i in range(m-2,-1,-1):\n a[i]+=a[i+1]\ncnt=0\ncnt1=0\n#print(a)\nfor i in range(m-1,0,-1):\n if(cnt1+a[i]>k):\n cnt1=a[i]\n cnt+=1\n else:\n cnt1+=a[i]\nif(cnt1):\n cnt+=1\nprint(cnt)\n \n \n \n\n\n \n\n\n", "passed": true, "time": 0.19, "memory": 15060.0, "status": "done"}, {"code": "from collections import defaultdict\n\ndef ii():\n return list(map(int, input().split()))\n\nmaxv = int(2e5) + 1\nn, k = ii()\ncnt = defaultdict(int)\n\nfor a in ii():\n cnt[a] += 1\n\nfor i in range(maxv, -1, -1):\n cnt[i] += cnt[i + 1]\n\ncur, ans = 0, 0\ni = maxv\n\nwhile True:\n if cnt[i] == n:\n if cur:\n ans += 1\n break\n if cur + cnt[i] > k:\n ans += 1\n cur = 0\n cur += cnt[i]\n i -= 1\n\nprint(ans)\n", "passed": true, "time": 5.57, "memory": 39864.0, "status": "done"}]
[{"input": "5 5\n3 1 2 2 4\n", "output": "2\n"}, {"input": "4 5\n2 3 4 5\n", "output": "2\n"}, {"input": "2 2\n1 1\n", "output": "0\n"}, {"input": "5 5\n5 5 5 5 5\n", "output": "0\n"}, {"input": "5 20\n5 5 5 5 5\n", "output": "0\n"}, {"input": "2 3\n2 2\n", "output": "0\n"}, {"input": "4 5\n2 2 2 2\n", "output": "0\n"}, {"input": "5 6\n2 2 2 2 7\n", "output": "1\n"}, {"input": "1 1\n1\n", "output": "0\n"}, {"input": "5 5\n1 1 1 1 1\n", "output": "0\n"}, {"input": "3 3\n10 10 10\n", "output": "0\n"}, {"input": "2 3\n5 5\n", "output": "0\n"}, {"input": "1 100\n1\n", "output": "0\n"}, {"input": "1 4\n1\n", "output": "0\n"}, {"input": "4 4\n4 4 4 4\n", "output": "0\n"}, {"input": "2 100\n5 5\n", "output": "0\n"}, {"input": "5 5\n3 3 3 3 3\n", "output": "0\n"}, {"input": "1 5\n1\n", "output": "0\n"}, {"input": "1 1\n4\n", "output": "0\n"}, {"input": "1 5\n5\n", "output": "0\n"}, {"input": "1 10\n1000\n", "output": "0\n"}, {"input": "3 3\n1 1 1\n", "output": "0\n"}, {"input": "5 5\n4 4 4 4 4\n", "output": "0\n"}, {"input": "2 5\n2 2\n", "output": "0\n"}, {"input": "2 3\n1 1\n", "output": "0\n"}, {"input": "2 2\n5 5\n", "output": "0\n"}, {"input": "4 10\n2 2 2 2\n", "output": "0\n"}, {"input": "4 4\n1 1 1 1\n", "output": "0\n"}, {"input": "10 10\n1 1 1 1 1 1 1 1 1 1\n", "output": "0\n"}, {"input": "1 2\n1\n", "output": "0\n"}, {"input": "5 6\n3 3 3 3 3\n", "output": "0\n"}, {"input": "2 2\n3 3\n", "output": "0\n"}, {"input": "2 2\n1 9\n", "output": "4\n"}, {"input": "1 200000\n200000\n", "output": "0\n"}, {"input": "3 3\n1 200000 200000\n", "output": "199999\n"}, {"input": "1 1\n3\n", "output": "0\n"}, {"input": "3 3\n3 3 3\n", "output": "0\n"}, {"input": "3 3\n5 5 5\n", "output": "0\n"}, {"input": "2 10\n1 9\n", "output": "1\n"}, {"input": "2 10\n2 2\n", "output": "0\n"}, {"input": "3 3\n100 100 100\n", "output": "0\n"}, {"input": "5 5\n2 2 2 2 2\n", "output": "0\n"}, {"input": "2 1000000000\n1 10\n", "output": "1\n"}, {"input": "4 6\n1 3 3 3\n", "output": "1\n"}, {"input": "5 5\n8 8 8 8 8\n", "output": "0\n"}, {"input": "2 10\n1 2\n", "output": "1\n"}, {"input": "1 44550514\n127593\n", "output": "0\n"}, {"input": "1 10\n10\n", "output": "0\n"}, {"input": "3 4\n3 3 3\n", "output": "0\n"}, {"input": "4 6\n1 1 1 1\n", "output": "0\n"}, {"input": "2 2\n2 2\n", "output": "0\n"}, {"input": "5 5\n5 5 5 5 11\n", "output": "2\n"}, {"input": "3 10\n2 2 2\n", "output": "0\n"}, {"input": "4 5\n4 4 4 4\n", "output": "0\n"}, {"input": "5 5\n1 1 1 1 2\n", "output": "1\n"}, {"input": "5 15\n2 2 2 2 2\n", "output": "0\n"}, {"input": "4 6\n2 2 2 2\n", "output": "0\n"}, {"input": "1 4\n2\n", "output": "0\n"}, {"input": "10 10\n3 3 3 3 3 3 3 3 3 3\n", "output": "0\n"}, {"input": "4 5\n1 2 4 2\n", "output": "1\n"}, {"input": "1 1\n234\n", "output": "0\n"}, {"input": "4 4\n2 4 4 4\n", "output": "2\n"}, {"input": "4 5\n3 3 3 4\n", "output": "1\n"}, {"input": "5 10\n2 2 2 2 3\n", "output": "1\n"}, {"input": "1 2164\n10648\n", "output": "0\n"}, {"input": "2 25584\n13182 19648\n", "output": "1\n"}, {"input": "2 1000000000\n1 2\n", "output": "1\n"}]
252
Alice and Bob are playing yet another card game. This time the rules are the following. There are $n$ cards lying in a row in front of them. The $i$-th card has value $a_i$. First, Alice chooses a non-empty consecutive segment of cards $[l; r]$ ($l \le r$). After that Bob removes a single card $j$ from that segment $(l \le j \le r)$. The score of the game is the total value of the remaining cards on the segment $(a_l + a_{l + 1} + \dots + a_{j - 1} + a_{j + 1} + \dots + a_{r - 1} + a_r)$. In particular, if Alice chooses a segment with just one element, then the score after Bob removes the only card is $0$. Alice wants to make the score as big as possible. Bob takes such a card that the score is as small as possible. What segment should Alice choose so that the score is maximum possible? Output the maximum score. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 10^5$) β€” the number of cards. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-30 \le a_i \le 30$) β€” the values on the cards. -----Output----- Print a single integer β€” the final score of the game. -----Examples----- Input 5 5 -2 10 -1 4 Output 6 Input 8 5 2 5 3 -30 -30 6 9 Output 10 Input 3 -10 6 -15 Output 0 -----Note----- In the first example Alice chooses a segment $[1;5]$ β€” the entire row of cards. Bob removes card $3$ with the value $10$ from the segment. Thus, the final score is $5 + (-2) + (-1) + 4 = 6$. In the second example Alice chooses a segment $[1;4]$, so that Bob removes either card $1$ or $3$ with the value $5$, making the answer $5 + 2 + 3 = 10$. In the third example Alice can choose any of the segments of length $1$: $[1;1]$, $[2;2]$ or $[3;3]$. Bob removes the only card, so the score is $0$. If Alice chooses some other segment then the answer will be less than $0$.
interview
[{"code": "n = int(input())\nl = list(map(int,input().split()))\n\ncurr = 0\nbest = 0\nprevs = [0] * 31\nfor v in l:\n curr += v\n if v >= 0:\n for i in range(0, v):\n prevs[i] = curr\n for i in range(v, 31):\n best = max(curr - prevs[i] - i, best)\n else:\n for i in range(31):\n prevs[i] = min(prevs[i], curr)\nprint(best)\n", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "from bisect import bisect_left as lower_bound, bisect_right as upper_bound\nfrom sys import stdin, stdout\nfrom collections import defaultdict\n\nN = 10**5 + 7\n\nminn = [0 for _ in range(2*N)]\nmaxx = [0 for _ in range(2*N)]\n\ndef build(p, n):\n for i in range(n): \n maxx[n+i] = p[i]\n minn[n+i] = p[i]\n\n for i in range(n-1, 0, -1):\n maxx[i] = max(maxx[i<<1], maxx[i<<1|1])\n minn[i] = min(minn[i<<1], minn[i<<1|1])\n\ndef query(l, r, n):\n l += n\n r += n\n\n retminn, retmaxx = float('inf'), -float('inf')\n\n while l < r:\n if l&1:\n retminn = min(retminn, minn[l])\n retmaxx = max(retmaxx, maxx[l])\n l += 1\n\n if r&1:\n r -= 1\n retminn = min(retminn, minn[r])\n retmaxx = max(retmaxx, maxx[r])\n\n l >>= 1\n r >>= 1\n\n return retminn, retmaxx\n\n\ndef main():\n n = int(input())\n a = list(map(int, input().strip().split()))\n\n left = [-1]*n\n right = [n]*n\n\n p = [a[i] for i in range(n)]\n for i in range(1, n): p[i] += p[i-1]\n\n build(p, n)\n\n st = [0]\n for i in range(1, n):\n while st and a[st[-1]] <= a[i]: st.pop()\n\n if st: left[i] = st[-1]\n st.append(i)\n\n st = [n-1]\n for i in range(n-2, -1, -1):\n while st and a[st[-1]] < a[i]: st.pop()\n\n if st: right[i] = st[-1]\n st.append(i)\n\n #print(left, right, p)\n #\n \n if max(a) <= 0:\n print(0)\n return None\n\n ret = -float('inf')\n\n for i in range(n):\n l, r = left[i], right[i]\n\n _, rmaxx = query(i, r, n)\n lminn, _ = query(max(0, l), i, n)\n\n if l < 0: lminn = min(lminn, 0)\n\n s = rmaxx - lminn\n #print(i, s, a[i], l, r)\n\n ret = max(ret, s-a[i])\n\n print(ret)\n\n\n\ndef __starting_point(): main()\n\n__starting_point()", "passed": true, "time": 0.82, "memory": 16952.0, "status": "done"}]
[{"input": "5\n5 -2 10 -1 4\n", "output": "6\n"}, {"input": "8\n5 2 5 3 -30 -30 6 9\n", "output": "10\n"}, {"input": "3\n-10 6 -15\n", "output": "0\n"}, {"input": "1\n6\n", "output": "0\n"}, {"input": "5\n0 5 -4 3 -1\n", "output": "0\n"}, {"input": "15\n1 -26 -6 26 7 10 -2 -4 -6 14 -9 25 9 -12 -28\n", "output": "44\n"}, {"input": "11\n3 0 1 -2 5 -5 -1 0 3 2 2\n", "output": "4\n"}, {"input": "7\n25 -13 17 -23 12 12 9\n", "output": "21\n"}, {"input": "8\n4 -10 13 -13 2 2 -11 6\n", "output": "2\n"}, {"input": "7\n30 -20 5 1 3 -20 30\n", "output": "4\n"}, {"input": "7\n5 -4 1 1 1 -4 5\n", "output": "2\n"}, {"input": "10\n-5 28 -18 -10 9 -2 11 -6 -19 30\n", "output": "7\n"}, {"input": "7\n30 -25 0 6 9 -2 10\n", "output": "13\n"}, {"input": "6\n8 -7 7 -6 5 5\n", "output": "5\n"}, {"input": "2\n1 1\n", "output": "1\n"}, {"input": "4\n1 1 -4 10\n", "output": "1\n"}, {"input": "5\n17 -16 12 -11 15\n", "output": "1\n"}, {"input": "7\n15 -14 10 10 10 -14 15\n", "output": "20\n"}, {"input": "7\n30 -29 10 10 10 -29 30\n", "output": "20\n"}, {"input": "4\n2 2 -3 4\n", "output": "2\n"}, {"input": "7\n25 -17 13 13 -25 25 -24\n", "output": "13\n"}, {"input": "5\n30 -29 4 -3 4\n", "output": "1\n"}, {"input": "6\n10 -8 3 3 -8 10\n", "output": "3\n"}, {"input": "9\n11 -5 -5 1 2 3 -5 -5 11\n", "output": "3\n"}, {"input": "7\n5 -4 3 -1 3 -4 4\n", "output": "2\n"}, {"input": "10\n-1 2 0 -1 2 -1 4 3 -5 1\n", "output": "5\n"}, {"input": "6\n30 -29 5 5 -29 30\n", "output": "5\n"}, {"input": "10\n4 -2 -2 -2 2 0 1 0 -4 -1\n", "output": "1\n"}, {"input": "10\n3 -3 2 1 -4 -2 3 -2 -3 0\n", "output": "1\n"}, {"input": "10\n4 -3 1 -2 1 1 0 -4 4 -2\n", "output": "1\n"}, {"input": "17\n15 -13 7 8 8 1 -19 12 8 -23 -4 16 -13 -28 10 -30 -14\n", "output": "16\n"}, {"input": "10\n-5 -5 -3 1 -2 2 0 2 -3 4\n", "output": "2\n"}, {"input": "35\n-23 -22 23 4 -22 29 -4 -6 -28 18 -5 21 -7 -8 -11 -7 30 -25 -1 12 19 5 -8 12 -1 10 -24 -19 24 -17 -7 24 20 -22 16\n", "output": "30\n"}, {"input": "10\n4 -2 1 0 1 -5 -2 1 0 -5\n", "output": "1\n"}, {"input": "10\n1 -4 -4 4 -2 -3 3 0 -2 3\n", "output": "1\n"}, {"input": "10\n-3 4 -4 1 1 -4 -5 3 -4 -2\n", "output": "1\n"}, {"input": "10\n4 -4 3 -2 3 -4 -2 0 1 0\n", "output": "1\n"}, {"input": "10\n-2 -3 -1 4 -3 2 0 1 -5 4\n", "output": "1\n"}, {"input": "11\n3 -2 1 1 1 1 1 1 1 -3 4\n", "output": "6\n"}, {"input": "10\n4 -5 0 4 0 0 -3 1 1 -4\n", "output": "1\n"}, {"input": "10\n0 -1 4 -2 3 -2 -1 -5 -5 2\n", "output": "1\n"}, {"input": "10\n-4 -5 4 -3 2 -2 2 1 -1 0\n", "output": "1\n"}, {"input": "10\n-4 4 0 -2 3 0 1 2 3 -4\n", "output": "7\n"}, {"input": "10\n1 0 -4 3 -5 3 -1 2 2 -5\n", "output": "3\n"}, {"input": "5\n30 -29 10 -1 10\n", "output": "9\n"}, {"input": "10\n-5 2 -3 -3 -4 3 3 0 2 4\n", "output": "8\n"}, {"input": "10\n2 -4 -2 3 1 1 -2 -1 -3 4\n", "output": "2\n"}, {"input": "11\n-11 -7 -2 -24 30 -26 24 9 -8 -9 23\n", "output": "15\n"}, {"input": "31\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 -29 30\n", "output": "28\n"}, {"input": "6\n30 -29 10 10 -29 30\n", "output": "10\n"}, {"input": "6\n30 -22 6 7 -22 30\n", "output": "6\n"}, {"input": "10\n3 0 0 -4 3 1 -2 -1 -1 4\n", "output": "1\n"}, {"input": "10\n0 4 4 1 -3 4 2 1 4 -1\n", "output": "13\n"}, {"input": "6\n5 -4 2 -1 2 -2\n", "output": "1\n"}, {"input": "4\n1 -10 1 10\n", "output": "1\n"}, {"input": "7\n5 -5 3 4 3 -5 5\n", "output": "6\n"}, {"input": "5\n10 -3 -5 3 5\n", "output": "3\n"}, {"input": "4\n2 3 -10 11\n", "output": "2\n"}, {"input": "10\n16 -15 13 -1 10 -2 -20 26 5 -30\n", "output": "9\n"}, {"input": "10\n27 -17 15 -22 18 17 -6 2 16 -14\n", "output": "29\n"}, {"input": "9\n7 2 -1 1 1 -10 6 -1 6\n", "output": "5\n"}, {"input": "10\n-9 -6 -1 9 -2 0 0 -1 5 0\n", "output": "2\n"}, {"input": "131\n30 -29 29 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 27 -26 27\n", "output": "1\n"}, {"input": "2\n3 9\n", "output": "3\n"}, {"input": "10\n8 9 -10 -10 -4 -3 5 9 -9 9\n", "output": "8\n"}, {"input": "10\n-2 -8 5 4 -1 -6 -9 6 1 -6\n", "output": "4\n"}, {"input": "24\n-8 -6 6 -11 -15 -7 10 -19 -6 21 14 -4 -21 -10 12 17 1 -1 5 19 2 0 -4 -23\n", "output": "36\n"}]
253
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its state β€” sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + k_{i}, x + 2k_{i}, x + 3k_{i} and so on. Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x_1, x_2 and x_3 (not necessarily distinct) so that he will switch on the first garland during x_1-th second, the second one β€” during x_2-th second, and the third one β€” during x_3-th second, respectively, and during each second starting from max(x_1, x_2, x_3) at least one garland will be lit. Help Mishka by telling him if it is possible to do this! -----Input----- The first line contains three integers k_1, k_2 and k_3 (1 ≀ k_{i} ≀ 1500) β€” time intervals of the garlands. -----Output----- If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES. Otherwise, print NO. -----Examples----- Input 2 2 3 Output YES Input 4 2 3 Output NO -----Note----- In the first example Mishka can choose x_1 = 1, x_2 = 2, x_3 = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second β€” 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't even matter what x_3 is chosen. Our choice will lead third to be lit during seconds 1, 4, 7, 10, ..., though. In the second example there is no way to choose such moments of time, there always be some seconds when no garland is lit.
interview
[{"code": "a, b, c = sorted(map(int, input().split()))\nif a > 3:\n\tprint('NO')\nelif a == 3:\n\tif b > 3:\n\t\tprint('NO')\n\telif b == 3:\n\t\tif c > 3:\n\t\t\tprint('NO')\n\t\telse:\n\t\t\tprint(\"YES\")\nelif a == 1:\n\tprint('YES')\nelse:\n\tif b == 2:\n\t\tprint('YES')\n\telif b > 4:\n\t\tprint('NO')\n\telif b == 4:\n\t\tif c == 4:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n\telse:\n\t\tprint('NO')", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "a = sorted([int(i) for i in input().split()])\nif a[0] * a[1] + a[1] * a[2] + a[2] * a[0] < a[0] * a[1] * a[2] or a[0] == 2 and a[1] == 3:\n\tprint('NO')\nelse:\n\tprint('YES')\n", "passed": true, "time": 0.17, "memory": 14320.0, "status": "done"}, {"code": "import sys\nk1,k2,k3 = [int(x) for x in input().split()]\ndef is_div(a,b):\n return a==((a//b)*b)\n\ndef always_lit(x1,x2,k1,k2,k3):\n for i in range(200):\n if not is_div(i-x1,k1) and not is_div(i-x2,k2) and not is_div(i,k3):\n return False\n return True\n\nfor x1 in range(-200,1):\n for x2 in range(x1,1):\n if always_lit(x1,x2,k1,k2,k3):\n print('YES')\n return\n\nprint('NO')\n", "passed": true, "time": 0.79, "memory": 14528.0, "status": "done"}, {"code": "k,m,n = list(map(int,input().split()))\nmn = min(k,min(m,n))\nma = max(k,max(m,n))\nme = k+m+n-mn-ma\nif mn == 1 or (mn == me == 2) or (mn == 2 and me == ma == 4) or mn == ma == me == 3:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "q=list(map(int,input().split()))\nq.sort()\nif (1 in q)|(q.count(2)>=2)|(q.count(3)==3)|(q==[2,4,4]):\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.16, "memory": 14536.0, "status": "done"}, {"code": "# input\nK = list(map(int, input().split()))\nK.sort()\n\ndef solve():\n m = min(K)\n\n if m == 1:\n print('YES')\n return\n elif m >= 3:\n if K == [3,3,3]:\n print('YES')\n return\n else:\n print('NO')\n return\n else: # m=2\n if K[1] == 2:\n print('YES')\n return\n elif K == [2,4,4]:\n print('YES')\n return\n else:\n print('NO')\n return\n\ndef __starting_point():\n solve()\n\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14540.0, "status": "done"}, {"code": "from math import gcd\nimport sys\n\ndef f():\n a,b,c = sorted(map(int,input().split()))\n\n x1 = 0\n for x2 in range(100):\n for x3 in range(100):\n ok = True\n for t in range(x3,x3+5000):\n if (t-x1)%a == 0 or (t-x2)%b == 0 or (t-x3)%c == 0:\n continue\n else:\n ok = False\n break\n if ok:\n print('YES')\n return\n print('NO')\nf()\n", "passed": true, "time": 0.51, "memory": 14388.0, "status": "done"}, {"code": "def ans(k1,k2,k3):\n if k1 == 1:\n return(\"YES\")\n\n if k1 == 2 and k2 == 2:\n return(\"YES\")\n\n if k1 == 3 and k2 == 3 and k3 == 3:\n return(\"YES\")\n\n if k1 == 2 and k2 == 4 and k3 == 4:\n return(\"YES\")\n\n return(\"NO\")\n\n\na,b,c = [int(i) for i in input().split()]\n\nk1 = min(a,b,c)\nk3 = max(a,b,c)\nk2 = a + b+ c - k1 -k3\n\n# k1 <= k2 <= k3\n\nprint(ans(k1,k2,k3))\n", "passed": true, "time": 0.16, "memory": 14520.0, "status": "done"}, {"code": "v = list(map(int, input().split()))\nv.sort()\nif (v[0] == 1):\n print(\"YES\")\n return\nif (v[0] == 2 and v[1] == 2):\n print(\"YES\")\n return\nif (v.count(3) == 3):\n print(\"YES\")\n return\nif (v[0] == 2 and v.count(4) == 2):\n print(\"YES\")\n return\nprint(\"NO\")", "passed": true, "time": 0.14, "memory": 14516.0, "status": "done"}, {"code": "a,b,c = list(map(int,input().split()))\n\nif a==1 or b==1 or c==1:\n\tprint(\"YES\")\nelif a==3 and b==3 and c==3:\n\tprint(\"YES\")\nelse:\n\tl={} \n\t\n\tl[2] = 0\n\tl[4]=0\n\tl[a]=0\n\tl[b]=0\n\tl[c]=0\n\n\tl[a]+=1\n\tl[b]+=1\n\tl[c]+=1\n\tif l[2]>=2:\n\t\tprint(\"YES\")\n\telif l[2]==1 and l[4]==2:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\");\t\n", "passed": true, "time": 0.14, "memory": 14320.0, "status": "done"}, {"code": "k1,k2,k3 = map(int, input().split())\nif 1 in [k1, k2,k3]:\n print('YES')\nelif sum([1 for i in [k1,k2,k3] if i == 2]) >= 2:\n print('YES')\nelif sum([1 for i in [k1,k2,k3] if i == 3]) == 3:\n print('YES')\nelif sum([1 for i in [k1,k2,k3] if i == 2]) == 1 and sum([1 for i in [k1,k2,k3] if i == 4]) == 2:\n print('YES')\nelse:\n print('NO') ", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "import math\nx1,x2,x3 = list(map(int,input().split()))\nkmm = math.gcd(x1,math.gcd(x2,x3))\na =[x1,x2,x3]\na.sort()\nif min(a) >= 4 :print('NO')\nelif min(a) == 3:\n if max(a) == 3:print('YES')\n else:print(\"NO\")\nelif min(a) == 1:print(\"YES\")\nelif min(a) == 2:\n if a.count(2) >= 2:print(\"YES\")\n elif a == [2,4,4]:print(\"YES\")\n else: print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14456.0, "status": "done"}, {"code": "import sys\nk1,k2,k3=list(map(int,input().split()))\nL=[k1,k2,k3]\nx=L.count(1)\nif x!=0:\n print(\"YES\")\n return\nx=L.count(2)\nif x>=2:\n print('YES')\n return\nx=L.count(3)\nif x==3:\n print(\"YES\")\n return\nif L.count(4)==2 and L.count(2)==1:\n print(\"YES\")\n return\nprint(\"NO\")\n\n", "passed": true, "time": 0.15, "memory": 14600.0, "status": "done"}, {"code": "k1,k2,k3=list(map(int,input().split()))\nL=[k1,k2,k3]\n\n\nif L.count(1) != 0:\n print(\"YES\")\nelif L.count(2) >= 2:\n print('YES')\n\nelif L.count(3) == 3:\n print(\"YES\")\n\nelif L.count(4)==2 and L.count(2)==1:\n print(\"YES\")\nelse: print(\"NO\")\n\n", "passed": true, "time": 0.15, "memory": 14372.0, "status": "done"}, {"code": "data = input().split(\" \")\nk = [int(data[0]), int(data[1]), int(data[2])]\nk.sort()\n[k1, k2, k3] = k\nhas_solution = False\nif k1 == 1:\n has_solution = True\nelif k1 == 2 and k2 == 2:\n has_solution = True\nelif k1 == 2 and k2 == 4 and k3 == 4:\n has_solution = True\nelif k1 == 3 and k2 == 3 and k3 == 3:\n has_solution = True\nif has_solution:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14268.0, "status": "done"}, {"code": "a=list(sorted(list(map(int,input().split()))))\nif a[0]==1 or a[0]==2 and a[1]==2 or a==[2,4,4] or a==[3,3,3]:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.24, "memory": 14460.0, "status": "done"}, {"code": "def solve(k):\n\tif min(k) > 3:\n\t\tprint(\"NO\")\n\t\treturn\n\n\tx = [0, 0, 0]\n\tfor x[0] in range(3):\n\t\tfor x[1] in range(3):\n\t\t\tfor x[2] in range(3):\n\t\t\t\ta = [False] * 15\n\t\t\t\tfor i in range(3):\n\t\t\t\t\tj = 0\n\t\t\t\t\twhile x[i] + j * k[i] < 15:\n\t\t\t\t\t\ta[x[i] + j * k[i]] = True\n\t\t\t\t\t\tj += 1\n\t\t\t\tis_possible = True\n\t\t\t\tfor i in range(3, 15):\n\t\t\t\t\tis_possible = is_possible and a[i]\n\t\t\t\tif is_possible:\n\t\t\t\t\tprint(\"YES\")\n\t\t\t\t\t# print(\" \".join(map(str, x)))\n\t\t\t\t\treturn\n\tprint(\"NO\")\n\nk = list(map(int, input().split()))\nsolve(k)\n\n\n", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "ks = [int(v) for v in input().split()]\nks.sort()\n\ndef solve(ks):\n k1, k2, k3 = ks\n\n if k1 == 1:\n return True\n elif k1 == 2:\n if k2 == 2:\n return True\n elif k2 == 4 and k3 == 4:\n return True\n else:\n return False\n elif k1 == 3:\n if k2 == 3 and k3 == 3:\n return True\n else:\n return False\n else:\n return False\n\nprint([\"NO\", \"YES\"][solve(ks)])\n", "passed": true, "time": 0.14, "memory": 14296.0, "status": "done"}, {"code": "k = list(map(int, input().strip().split()))\nk = sorted(k)\n\nif k[0] == 1:\n print(\"YES\")\nelif k[0] == 2 and k[1] == 2:\n print(\"YES\")\nelif k[0] == 2 and k[1] == 4 and k[2] == 4:\n print(\"YES\")\nelif k[0] == 3 and k[1] == 3 and k[2] == 3:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n\n", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "f=list(map(int,input().split()))\nf.sort()\na = f[0]\nb = f[1]\nc = f[2]\nif a == 1:\n print('YES')\nelse:\n if a == 3 and b == 3 and c == 3:\n print('YES')\n else:\n if a != 2:\n print('NO')\n else:\n if b == 2 or b == 4 and c == 4:\n print('YES')\n else:\n print('NO')", "passed": true, "time": 0.14, "memory": 14560.0, "status": "done"}, {"code": "k = list(map(int, input().split()))\n\ncnt1 = k.count(1)\ncnt2 = k.count(2)\ncnt3 = k.count(3)\ncnt4 = k.count(4)\n\nif cnt1 >= 1 or cnt2 >= 2 or cnt3 == 3 or (cnt4 == 2 and cnt2 == 1):\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.15, "memory": 14312.0, "status": "done"}, {"code": "a = [int(i) for i in input().split()]\na.sort()\nif a[0] == 1:\n print('YES')\nelif a[0] == 2 and a[1] == 2:\n print('YES')\nelif a[0] == 2 and a[1] == 4 and a[2] == 4:\n print('YES')\nelif a[0] == 3 and a[1] == 3 and a[2] == 3:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.24, "memory": 14412.0, "status": "done"}, {"code": "R=lambda:map(int,input().split())\n\na = list( R() ) \n\nans = 0\n\no = a.count(1)\nt = a.count(2)\nth = a.count(3)\nf = a.count(4)\n\nif o > 0 or t > 1 or th > 2 or (t == 1 and f == 2):\n print(\"YES\")\n \nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14508.0, "status": "done"}]
[{"input": "2 2 3\n", "output": "YES\n"}, {"input": "4 2 3\n", "output": "NO\n"}, {"input": "1499 1498 1500\n", "output": "NO\n"}, {"input": "1500 1500 1500\n", "output": "NO\n"}, {"input": "100 4 1\n", "output": "YES\n"}, {"input": "4 2 4\n", "output": "YES\n"}, {"input": "3 3 3\n", "output": "YES\n"}, {"input": "2 3 6\n", "output": "NO\n"}, {"input": "2 3 3\n", "output": "NO\n"}, {"input": "4 4 2\n", "output": "YES\n"}, {"input": "1 1 1\n", "output": "YES\n"}, {"input": "2 11 2\n", "output": "YES\n"}, {"input": "4 4 4\n", "output": "NO\n"}, {"input": "4 4 5\n", "output": "NO\n"}, {"input": "3 3 2\n", "output": "NO\n"}, {"input": "3 6 6\n", "output": "NO\n"}, {"input": "2 3 2\n", "output": "YES\n"}, {"input": "1 1 3\n", "output": "YES\n"}, {"input": "3 3 4\n", "output": "NO\n"}, {"input": "2 4 4\n", "output": "YES\n"}, {"input": "2 2 2\n", "output": "YES\n"}, {"input": "2 10 10\n", "output": "NO\n"}, {"input": "3 4 4\n", "output": "NO\n"}, {"input": "2 5 5\n", "output": "NO\n"}, {"input": "2 4 5\n", "output": "NO\n"}, {"input": "228 2 2\n", "output": "YES\n"}, {"input": "2 998 1000\n", "output": "NO\n"}, {"input": "2 6 6\n", "output": "NO\n"}, {"input": "6 4 7\n", "output": "NO\n"}, {"input": "2 5 2\n", "output": "YES\n"}, {"input": "2 100 100\n", "output": "NO\n"}, {"input": "7 7 2\n", "output": "NO\n"}, {"input": "3 3 6\n", "output": "NO\n"}, {"input": "82 3 82\n", "output": "NO\n"}, {"input": "2 3 5\n", "output": "NO\n"}, {"input": "1 218 924\n", "output": "YES\n"}, {"input": "4 4 123\n", "output": "NO\n"}, {"input": "4 4 3\n", "output": "NO\n"}, {"input": "3 4 2\n", "output": "NO\n"}, {"input": "2 2 5\n", "output": "YES\n"}, {"input": "2 10 2\n", "output": "YES\n"}, {"input": "5 2 2\n", "output": "YES\n"}, {"input": "3 3 9\n", "output": "NO\n"}, {"input": "1 5 5\n", "output": "YES\n"}, {"input": "2 4 6\n", "output": "NO\n"}, {"input": "15 3 3\n", "output": "NO\n"}, {"input": "1 5 10\n", "output": "YES\n"}, {"input": "2 3 14\n", "output": "NO\n"}, {"input": "1265 2 593\n", "output": "NO\n"}, {"input": "2 2 567\n", "output": "YES\n"}, {"input": "1 6 5\n", "output": "YES\n"}, {"input": "2 2 7\n", "output": "YES\n"}, {"input": "2 2 1500\n", "output": "YES\n"}, {"input": "3 6 9\n", "output": "NO\n"}, {"input": "1 46 79\n", "output": "YES\n"}, {"input": "4 3 3\n", "output": "NO\n"}, {"input": "2 4 8\n", "output": "NO\n"}, {"input": "1493 1489 1487\n", "output": "NO\n"}, {"input": "1 2 3\n", "output": "YES\n"}, {"input": "1 2 5\n", "output": "YES\n"}, {"input": "1 2 8\n", "output": "YES\n"}, {"input": "3 4 5\n", "output": "NO\n"}, {"input": "2 2 4\n", "output": "YES\n"}, {"input": "3 2 3\n", "output": "NO\n"}, {"input": "7 2 2\n", "output": "YES\n"}, {"input": "3 2 2\n", "output": "YES\n"}, {"input": "6 7 4\n", "output": "NO\n"}]
255
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. -----Input----- The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 100), where a_{i} is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b_1, b_2, ..., b_{m} (1 ≀ b_{j} ≀ 100), where b_{j} is the j-th girl's dancing skill. -----Output----- Print a single number β€” the required maximum possible number of pairs. -----Examples----- Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2
interview
[{"code": "n=int(input())\na=sorted(map(int,input().split()))\nm=int(input())\nb=sorted(map(int,input().split()))\nc=0\nfor i in range(n):\n for j in range(m):\n if abs(a[i]-b[j]) <= 1:\n b[j]=-10\n c+=1\n break\nprint(c)", "passed": true, "time": 0.16, "memory": 14320.0, "status": "done"}, {"code": "n = int(input())\nboys = [int(x) for x in input().split()]\nm = int(input())\ngirls = [int(x) for x in input().split()]\n\n# we sort the lads\nboys.sort()\ngirls.sort()\n\ncount = 0\nlast_girl = -1\n\nfor boy in boys:\n # try to find a match, if we find, we increment the namber\n for gi in range(last_girl+1, len(girls)):\n girl = girls[gi]\n if (girl+1 == boy) or girl == boy or girl-1 == boy:\n count += 1\n last_girl = gi\n break\n\nprint(count)\n", "passed": true, "time": 0.14, "memory": 14452.0, "status": "done"}, {"code": "n = int(input())\nns = sorted(map(int, str.split(input())))\nm = int(input())\nms = sorted(map(int, str.split(input())))\nni = mi = pairs = 0\nwhile ni < n and mi < m:\n\n if abs(ns[ni] - ms[mi]) <= 1:\n\n pairs += 1\n ni += 1\n mi += 1\n\n elif ns[ni] <= ms[mi]:\n\n ni += 1\n\n else:\n\n mi += 1\n\nprint(pairs)\n", "passed": true, "time": 0.15, "memory": 14540.0, "status": "done"}, {"code": "def dfs(u):\n\tif used[u]:\n\t\treturn False\n\tused[u] = 1\n\tfor i in range(m):\n\t\tif abs(a[u] - b[i]) < 2 and (pair[i] == -1 or dfs(pair[i])):\n\t\t\tpair[i] = u\n\t\t\treturn True\n\treturn False\n\nn, a, m, b = int(input()), list(map(int, input().split())), int(input()), list(map(int, input().split()))\npair = [-1] * m\nfor i in range(n):\n\tused = [0] * n\n\tdfs(i)\nprint(sum(1 for p in pair if p != -1))\n", "passed": true, "time": 0.2, "memory": 14452.0, "status": "done"}, {"code": "\nn = int(input())\na = [int(s) for s in input().split()]\nm = int(input())\nb = [int(s) for s in input().split()]\n\na.sort()\nb.sort()\n\ni = 0\nj = 0\ncount = 0\nwhile i<n and j<m:\n if abs(a[i]-b[j])<=1:\n count += 1\n i += 1\n j += 1\n elif a[i]<b[j]:\n i += 1\n else:\n j += 1\n \nprint(count)\n\n\n \n\n", "passed": true, "time": 0.34, "memory": 14508.0, "status": "done"}, {"code": "n = int(input())\nad = list(sorted(list(map(int, input().split()))))\nm = int(input())\nam = list(sorted(list(map(int, input().split()))))\ni = 0\nj = 0\nsum1 = 0\nwhile i < n and j < m:\n if abs(ad[i] - am[j]) < 2:\n sum1 += 1\n i += 1\n j += 1\n elif ad[i] < am[j]:\n i += 1\n else:\n j += 1\nprint(sum1)\n", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "__author__ = 'valeriy.shevchuk'\n\ninput()\nb = sorted(list(map(int, input().split())))\ninput()\ng = sorted(list(map(int, input().split())))\n\nc = 0\nwhile b and g:\n bb = b[0]\n gg = g[0]\n if abs(bb - gg) <= 1:\n c += 1\n b.pop(0)\n g.pop(0)\n else:\n b.pop(0) if bb < gg else g.pop(0)\n\nprint(c)", "passed": true, "time": 0.15, "memory": 14452.0, "status": "done"}, {"code": "a = int(input())\na = list(map(int, input().split()))\nb = int(input())\nb = list(map(int, input().split()))\na=sorted(a)\nb=reversed(sorted(b))\nx=[0]*200;\nfor t in a:\n x[t] += 1\n\nans = 0\nfor t in b:\n if x[t+1]:\n ans +=1\n x[t+1]-=1\n continue\n if x[t]:\n ans +=1\n x[t]-=1\n continue\n if x[t-1]:\n ans +=1\n x[t-1]-=1\n continue\n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}, {"code": "__author__ = 'Rakshak.R.Hegde'\nn = int(input())\nA = list(map(int, input().split()))\nA.sort()\nm = int(input())\nB = list(map(int, input().split()))\nB.sort()\npairs = 0\nwhile len(A) and len(B):\n if abs(A[0] - B[0]) <= 1:\n pairs += 1\n del A[0]\n del B[0]\n elif A[0] < B[0]:\n del A[0]\n else:\n del B[0]\nprint(pairs)", "passed": true, "time": 0.15, "memory": 14580.0, "status": "done"}, {"code": "n = int(input())\nna = sorted(list(map(int, input().split())))\n\nm = int(input())\nma = sorted(list(map(int, input().split())))\nans = 0\n\nfor i in range(n):\n for j in range(m):\n if abs(ma[j] - na[i]) <= 1:\n ans += 1\n ma[j] = -100\n na[i] = -100500\n\nprint(ans)\n\n\n\n", "passed": true, "time": 0.21, "memory": 14276.0, "status": "done"}, {"code": "#!/usr/bin/env python\n\nnb = int(input())\nboys = list(map(int, input().split(' ')))\nng = int(input())\ngirls = list(map(int, input().split(' ')))\n\n\nmatches = [ [] for i in range(nb) ]\nfor bi, boy in enumerate(boys):\n for i in range(ng):\n if girls[i] >= boy - 1 and girls[i] <= boy + 1:\n matches[bi].append(i)\n\n\ndef find(idx, taken, tried):\n for girl in matches[idx]:\n if not girl in tried:\n tried.add(girl)\n if not girl in taken or find(taken[girl], taken, tried):\n taken[girl] = idx\n return True\n return False\n\ndef getmax():\n result = 0\n taken = {}\n for bi, boy in enumerate(boys):\n tried = set()\n if find(bi, taken, tried):\n result += 1\n\n return result\n\nprint(getmax())\n", "passed": true, "time": 0.15, "memory": 14388.0, "status": "done"}, {"code": "\nR = lambda : map(int, input().split())\n\nn = int(input())\nm_skills = sorted(list(R()))\n\nm = int(input())\nw_skills = sorted(list(R()))\n\nN = max(m,n)\nj_list = []\ni_list = []\nres = 0\nfor i in range(n):\n for j in range(m):\n if abs(m_skills[i] - w_skills[j]) in [0,1] and j not in j_list:\n j_list.append(j)\n res += 1\n break\n\nprint(res)", "passed": true, "time": 0.14, "memory": 14464.0, "status": "done"}, {"code": "n = int(input())\narr1 = list(map(int, input().split()))\nm = int(input())\narr2 = list(map(int, input().split()))\ngraph = [[False]*(m+n) for _ in range(m+n)]\nfor i in range(n):\n\tfor j in range(m):\n\t\tif(abs(arr1[i]-arr2[j])<=1):\n\t\t\tgraph[i][j+n] = True\n\t\t\tgraph[j+n][i] = True\n# print(str(graph).replace('], [','],\\n[')[1:].replace('True','1').replace('False','-'))\nu = [False]*(m+n)\nto = [-1]*m\n\ndef match(v1):\n\ti = 0\n\tif u[v1]:\n\t\treturn 0\n\tu[v1] = True\n\tfor i2 in range(m):\n\t\tif(graph[v1][i2+n] and (to[i2] == -1 or match(to[i2]))):\n\t\t\tto[i2] = v1\n\t\t\treturn 1\n\treturn 0\nres = 0\nfor i1 in range(n+m):\n\tu = [False]*(m+n)\n\tres += match(i1)\nprint(res)", "passed": true, "time": 0.19, "memory": 14596.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int,input().split()))\nm = int(input())\nb = list(map(int,input().split()))\na.sort()\nb.sort()\ncount = 0\nwhile a and b:\n if abs(a[0]-b[0]) <= 1:\n count += 1\n a.pop(0)\n b.pop(0)\n elif a[0] < b[0]:\n a.pop(0)\n else:\n b.pop(0)\nprint(count) \n", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "n = int(input())\nai = sorted(list(map(int, input().split())))\nm = int(input())\nbi = sorted(list(map(int, input().split())))\ni = 0\nj = 0\nni = 0\nwhile i < n and j < m:\n if ai[i]<bi[j]-1:\n while i < n and ai[i]<bi[j]-1 :\n i+=1\n elif ai[i]-1>bi[j]:\n while j < m and ai[i]-1>bi[j]:\n j+=1\n if i < n and j < m and (ai[i] == bi[j] or ai[i] - 1 == bi[j]\n or ai[i] == bi[j] - 1):\n ni+=1\n i+=1\n j+=1\nprint(ni)\n\n", "passed": true, "time": 0.14, "memory": 14528.0, "status": "done"}, {"code": "from sys import stdin\n\nlines = list([_f for _f in stdin.read().split('\\n') if _f])\n\ndef parseline(line):\n\treturn list(map(int, line.split()))\n\nlines = list(map(parseline, lines))\n\nn, = lines[0]\na = lines[1]\nm, = lines[2]\nb = lines[3]\nassert len(a) == n and len(b) == m\n\nMax = 100 + 1\n\nai_count = [0] * Max\nbi_count = [0] * Max\n\nfor ai in a:\n\tai_count[ai] += 1\n\nfor bi in b:\n\tbi_count[bi] += 1\n\nmatch = [[] for i in range(Max)]\nused = None\n\ndef dfs(v):\n\tif used[v] >= ai_count[v]:\n\t\treturn False\n\tused[v] += 1\n\tfor to in range(max(0, v-1), min(Max, v + 2)):\n\t\tif len(match[to]) < bi_count[to]:\n\t\t\tmatch[to].append(v)\n\t\t\treturn True\n\t\tfor i, to_i in enumerate(match[to]):\n\t\t\tif dfs(to_i):\n\t\t\t\tmatch[to][i] = v\n\t\t\t\treturn True\n\treturn False\n\nfor i in range(Max):\n\tfor _ in range(ai_count[i]):\n\t\tused = [0] * Max\n\t\tdfs(i)\n\nprint(sum(len(l) for l in match))\n", "passed": true, "time": 0.17, "memory": 14412.0, "status": "done"}, {"code": "def main():\n nm=int(input())\n m=list(map(int,input().split()))\n nw=int(input())\n w=list(map(int,input().split()))\n m.sort()\n w.sort()\n i=j=ans=0\n while(i<nm and j<nw):\n if(-1<=m[i]-w[j]<=1):\n ans+=1\n i+=1\n j+=1\n elif(m[i]>w[j]):\n j+=1\n else:\n i+=1\n print(ans)\n \ndef __starting_point():\n main()\n\n\n__starting_point()", "passed": true, "time": 0.47, "memory": 14316.0, "status": "done"}, {"code": "def solve(bs, gs):\n bs.sort()\n gs.sort()\n ret = 0\n while gs and bs:\n if -2 < gs[-1] - bs[-1] < 2:\n ret += 1\n bs.pop()\n gs.pop()\n elif bs[-1] > gs[-1]:\n bs.pop()\n else:\n gs.pop()\n return ret\n \ndef __starting_point():\n input()\n bs = list(map(int, input().split()))\n input()\n gs = list(map(int, input().split()))\n print(solve(bs, gs))\n__starting_point()", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "n = int(input())\na = sorted(int(x) for x in input().split())\nm = int(input())\nb = sorted(int(x) for x in input().split())\ni, j, val = 0, 0, 0\nwhile i < n and j < m:\n if a[i] < b[j] - 1:\n i += 1\n elif b[j] < a[i] - 1:\n j += 1\n else:\n i += 1\n j += 1\n val += 1\nprint(val)", "passed": true, "time": 0.15, "memory": 14424.0, "status": "done"}, {"code": "x = input()\nboys = list(map(int, input().split(' ')))\ny = input()\ngirls = list(map(int, input().split(' ')))\nboys.sort()\ngirls.sort()\nok = 0\nfor i in boys[:]:\n if i-1 in girls:\n girls.remove(i-1)\n boys.remove(i)\n ok += 1\n elif i in girls:\n girls.remove(i)\n boys.remove(i)\n ok += 1\n elif i+1 in girls:\n girls.remove(i+1)\n boys.remove(i)\n ok += 1\nprint(ok)\n", "passed": true, "time": 0.19, "memory": 14456.0, "status": "done"}, {"code": "males = int(input())\nmales_ability = [int(m) for m in input().split()]\nfemales = int(input())\nfemales_ability = [int(m) for m in input().split()]\nmales_ability.sort()\nfemales_ability.sort()\npairs = 0\nfor x in males_ability:\n for y in females_ability:\n if y in range(x-1, x+2):\n females_ability.remove(y)\n pairs += 1\n break\nprint(pairs)\n\n\n", "passed": true, "time": 0.14, "memory": 14356.0, "status": "done"}, {"code": "n = int(input())\na = sorted([int(x) for x in input().split()])\nm = int(input())\nb = sorted([int(x) for x in input().split()])\ni, j = 0, 0\nans = 0\nwhile i < n and j < m:\n\tif abs(a[i] - b[j]) <= 1:\n\t\tans += 1\n\t\ti += 1\n\t\tj += 1\n\telif a[i] < b[j]:\n\t\ti += 1\n\telse:\n\t\tj += 1\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}, {"code": "def Fabs(a):\n if a<0:\n return -a\n else:\n return a\n\ndef solve(listB, listG):\n res=0;\n cntb=0\n \n while cntb<len(listB):\n cntg=0\n while cntg<len(listG):\n if Fabs(listB[cntb]-listG[cntg])<=1:\n res+=1\n listG[cntg]=10000\n listB[cntb]=10000\n cntg+=1\n cntb+=1\n return res\n \nlistB=[]\nlistG=[]\nb=input()\nlistB=list(map(int, input().split()))\ng=input()\nlistG=list(map(int, input().split())) \nlistB=sorted(listB)\nlistG=sorted(listG)\nprint(solve(listB, listG))", "passed": true, "time": 0.14, "memory": 14324.0, "status": "done"}, {"code": "n = int(input()) # \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\na = input().split()\nfor i in range(n):\n a[i] = int(a[i])\na = sorted(a)\n\nm = int(input()) # \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\nb = input().split()\nfor i in range(m):\n b[i] = int(b[i])\nb = sorted(b)\n\npos1 = 0 # \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\npos2 = 0 # \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\nk = 0 # \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\n\nwhile (pos1 < n) and (pos2 < m):\n if abs(a[pos1]-b[pos2]) <= 1: # \ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\n k += 1\n pos1 += 1\n pos2 += 1\n else:\n if a[pos1] > b[pos2]: # \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n pos2 += 1\n else:\n pos1 += 1\n \nprint(k)", "passed": true, "time": 0.19, "memory": 14348.0, "status": "done"}]
[{"input": "4\n1 4 6 2\n5\n5 1 5 7 9\n", "output": "3\n"}, {"input": "4\n1 2 3 4\n4\n10 11 12 13\n", "output": "0\n"}, {"input": "5\n1 1 1 1 1\n3\n1 2 3\n", "output": "2\n"}, {"input": "1\n1\n1\n1\n", "output": "1\n"}, {"input": "2\n1 10\n1\n9\n", "output": "1\n"}, {"input": "4\n4 5 4 4\n5\n5 3 4 2 4\n", "output": "4\n"}, {"input": "1\n2\n1\n1\n", "output": "1\n"}, {"input": "1\n3\n2\n3 2\n", "output": "1\n"}, {"input": "1\n4\n3\n4 4 4\n", "output": "1\n"}, {"input": "1\n2\n4\n3 1 4 2\n", "output": "1\n"}, {"input": "1\n4\n5\n2 5 5 3 1\n", "output": "1\n"}, {"input": "2\n2 2\n1\n2\n", "output": "1\n"}, {"input": "2\n4 2\n2\n4 4\n", "output": "1\n"}, {"input": "2\n4 1\n3\n2 3 2\n", "output": "2\n"}, {"input": "2\n4 3\n4\n5 5 5 6\n", "output": "1\n"}, {"input": "2\n5 7\n5\n4 6 7 2 5\n", "output": "2\n"}, {"input": "3\n1 2 3\n1\n1\n", "output": "1\n"}, {"input": "3\n5 4 5\n2\n2 1\n", "output": "0\n"}, {"input": "3\n6 3 4\n3\n4 5 2\n", "output": "3\n"}, {"input": "3\n7 7 7\n4\n2 7 2 4\n", "output": "1\n"}, {"input": "3\n1 3 3\n5\n1 3 4 1 2\n", "output": "3\n"}, {"input": "4\n1 2 1 3\n1\n4\n", "output": "1\n"}, {"input": "4\n4 4 6 6\n2\n2 1\n", "output": "0\n"}, {"input": "4\n3 1 1 1\n3\n1 6 7\n", "output": "1\n"}, {"input": "4\n2 5 1 2\n4\n2 3 3 1\n", "output": "3\n"}, {"input": "4\n9 1 7 1\n5\n9 9 9 8 4\n", "output": "2\n"}, {"input": "5\n1 6 5 5 6\n1\n2\n", "output": "1\n"}, {"input": "5\n5 2 4 5 6\n2\n7 4\n", "output": "2\n"}, {"input": "5\n4 1 3 1 4\n3\n6 3 6\n", "output": "1\n"}, {"input": "5\n5 2 3 1 4\n4\n1 3 1 7\n", "output": "3\n"}, {"input": "5\n9 8 10 9 10\n5\n2 1 5 4 6\n", "output": "0\n"}, {"input": "1\n48\n100\n76 90 78 44 29 30 35 85 98 38 27 71 51 100 15 98 78 45 85 26 48 66 98 71 45 85 83 77 92 17 23 95 98 43 11 15 39 53 71 25 74 53 77 41 39 35 66 4 92 44 44 55 35 87 91 6 44 46 57 24 46 82 15 44 81 40 65 17 64 24 42 52 13 12 64 82 26 7 66 85 93 89 58 92 92 77 37 91 47 73 35 69 31 22 60 60 97 21 52 6\n", "output": "1\n"}, {"input": "100\n9 90 66 62 60 9 10 97 47 73 26 81 97 60 80 84 19 4 25 77 19 17 91 12 1 27 15 54 18 45 71 79 96 90 51 62 9 13 92 34 7 52 55 8 16 61 96 12 52 38 50 9 60 3 30 3 48 46 77 64 90 35 16 16 21 42 67 70 23 19 90 14 50 96 98 92 82 62 7 51 93 38 84 82 37 78 99 3 20 69 44 96 94 71 3 55 27 86 92 82\n1\n58\n", "output": "0\n"}, {"input": "10\n20 87 3 39 20 20 8 40 70 51\n100\n69 84 81 84 35 97 69 68 63 97 85 80 95 58 70 91 100 65 72 80 41 87 87 87 22 49 96 96 78 96 97 56 90 31 62 98 89 74 100 86 95 88 66 54 93 62 41 60 95 79 29 69 63 70 52 63 87 58 54 52 48 57 26 75 39 61 98 78 52 73 99 49 74 50 59 90 31 97 16 85 63 72 81 68 75 59 70 67 73 92 10 88 57 95 3 71 80 95 84 96\n", "output": "6\n"}, {"input": "100\n10 10 9 18 56 64 92 66 54 42 66 65 58 5 74 68 80 57 58 30 58 69 70 13 38 19 34 63 38 17 26 24 66 83 48 77 44 37 78 97 13 90 51 56 60 23 49 32 14 86 90 100 13 14 52 69 85 95 81 53 5 3 91 66 2 64 45 59 7 30 80 42 61 82 70 10 62 82 5 34 50 28 24 47 85 68 27 50 24 61 76 17 63 24 3 67 83 76 42 60\n10\n66 74 40 67 28 82 99 57 93 64\n", "output": "9\n"}, {"input": "100\n4 1 1 1 3 3 2 5 1 2 1 2 1 1 1 6 1 3 1 1 1 1 2 4 1 1 4 2 2 8 2 2 1 8 2 4 3 3 8 1 3 2 3 2 1 3 8 2 2 3 1 1 2 2 5 1 4 3 1 1 3 1 3 1 7 1 1 1 3 2 1 2 2 3 7 2 1 4 3 2 1 1 3 4 1 1 3 5 1 8 4 1 1 1 3 10 2 2 1 2\n100\n1 1 5 2 13 2 2 3 6 12 1 13 8 1 1 16 1 1 5 6 2 4 6 4 2 7 4 1 7 3 3 9 5 3 1 7 4 1 6 6 8 2 2 5 2 3 16 3 6 3 8 6 1 8 1 2 6 5 3 4 11 3 4 8 2 13 2 5 2 7 3 3 1 8 1 4 4 2 4 7 7 1 5 7 6 3 6 9 1 1 1 3 1 11 5 2 5 11 13 1\n", "output": "76\n"}, {"input": "4\n1 6 9 15\n2\n5 8\n", "output": "2\n"}, {"input": "2\n2 4\n2\n3 1\n", "output": "2\n"}, {"input": "3\n2 3 5\n3\n3 4 6\n", "output": "3\n"}, {"input": "3\n1 3 4\n3\n2 1 5\n", "output": "3\n"}, {"input": "2\n5 5\n4\n1 1 1 5\n", "output": "1\n"}, {"input": "2\n3 2\n2\n3 4\n", "output": "2\n"}, {"input": "2\n3 1\n2\n2 4\n", "output": "2\n"}, {"input": "2\n2 3\n2\n2 1\n", "output": "2\n"}, {"input": "2\n10 12\n2\n11 9\n", "output": "2\n"}, {"input": "3\n1 2 3\n3\n3 2 1\n", "output": "3\n"}, {"input": "2\n1 3\n2\n2 1\n", "output": "2\n"}, {"input": "2\n4 5\n2\n5 3\n", "output": "2\n"}, {"input": "2\n7 5\n2\n6 8\n", "output": "2\n"}, {"input": "4\n4 3 2 1\n4\n1 2 3 4\n", "output": "4\n"}, {"input": "2\n2 3\n2\n3 1\n", "output": "2\n"}, {"input": "2\n2 4\n3\n3 1 8\n", "output": "2\n"}, {"input": "3\n3 1 1\n3\n2 4 4\n", "output": "2\n"}, {"input": "2\n5 3\n2\n4 6\n", "output": "2\n"}, {"input": "4\n1 1 3 3\n4\n2 2 1 1\n", "output": "4\n"}, {"input": "3\n3 2 1\n3\n2 4 3\n", "output": "3\n"}, {"input": "5\n1 2 3 4 5\n5\n2 3 4 5 1\n", "output": "5\n"}, {"input": "3\n3 2 1\n3\n1 2 3\n", "output": "3\n"}, {"input": "2\n5 4\n2\n4 6\n", "output": "2\n"}, {"input": "4\n3 3 5 5\n4\n4 4 2 2\n", "output": "4\n"}, {"input": "3\n2 7 5\n3\n2 4 8\n", "output": "3\n"}, {"input": "100\n2 3 3 4 2 1 4 4 5 5 2 1 5 2 3 3 5 4 3 2 4 2 3 3 2 2 3 4 2 2 2 3 1 2 3 2 2 3 5 3 3 3 3 4 5 2 2 1 1 1 3 1 2 2 3 5 5 2 5 1 3 4 5 3 5 4 1 1 2 3 4 4 5 3 2 4 5 5 5 2 1 4 2 4 5 4 4 5 5 3 2 5 1 4 4 2 2 2 5 3\n100\n4 5 3 3 2 2 4 3 1 5 4 3 3 2 2 4 5 2 5 2 1 4 3 4 2 3 5 3 4 4 1 2 3 5 2 2 1 5 4 2 4 3 4 3 4 2 3 1 3 3 4 1 1 1 4 4 5 3 1 4 2 3 2 1 3 3 2 3 2 1 1 2 3 2 1 3 3 4 3 3 1 1 3 3 3 1 1 3 5 3 3 3 3 4 4 5 2 5 4 5\n", "output": "100\n"}, {"input": "1\n3\n2\n2 3\n", "output": "1\n"}, {"input": "2\n5 6\n3\n1 5 100\n", "output": "1\n"}, {"input": "2\n2 7\n2\n6 8\n", "output": "1\n"}, {"input": "4\n4 10 15 17\n4\n3 12 16 16\n", "output": "3\n"}, {"input": "2\n2 3\n2\n1 2\n", "output": "2\n"}]
256
Kicker (table football) is a board game based on football, in which players control the footballers' figures mounted on rods by using bars to get the ball into the opponent's goal. When playing two on two, one player of each team controls the goalkeeper and the full-backs (plays defence), the other player controls the half-backs and forwards (plays attack). Two teams of company Q decided to battle each other. Let's enumerate players from both teams by integers from 1 to 4. The first and second player play in the first team, the third and the fourth one play in the second team. For each of the four players we know their game skills in defence and attack. The defence skill of the i-th player is a_{i}, the attack skill is b_{i}. Before the game, the teams determine how they will play. First the players of the first team decide who will play in the attack, and who will play in the defence. Then the second team players do the same, based on the choice of their opponents. We will define a team's defence as the defence skill of player of the team who plays defence. Similarly, a team's attack is the attack skill of the player of the team who plays attack. We assume that one team is guaranteed to beat the other one, if its defence is strictly greater than the opponent's attack and its attack is strictly greater than the opponent's defence. The teams of company Q know each other's strengths and therefore arrange their teams optimally. Identify the team that is guaranteed to win (if both teams act optimally) or tell that there is no such team. -----Input----- The input contain the players' description in four lines. The i-th line contains two space-separated integers a_{i} and b_{i} (1 ≀ a_{i}, b_{i} ≀ 100) β€” the defence and the attack skill of the i-th player, correspondingly. -----Output----- If the first team can win, print phrase "Team 1" (without the quotes), if the second team can win, print phrase "Team 2" (without the quotes). If no of the teams can definitely win, print "Draw" (without the quotes). -----Examples----- Input 1 100 100 1 99 99 99 99 Output Team 1 Input 1 1 2 2 3 3 2 2 Output Team 2 Input 3 3 2 2 1 1 2 2 Output Draw -----Note----- Let consider the first test sample. The first team can definitely win if it will choose the following arrangement: the first player plays attack, the second player plays defence. Consider the second sample. The order of the choosing roles for players makes sense in this sample. As the members of the first team choose first, the members of the second team can beat them (because they know the exact defence value and attack value of the first team).
interview
[{"code": "a,b=list(map(int,input().split()))\nc,d=list(map(int,input().split()))\n\n\nx,y=list(map(int,input().split()))\nz,w=list(map(int,input().split()))\n\n\nTeam1=False\nTeam2=False\nif(a>w and a>y and d>x and d>z):\n Team1=True\n\nif(c>w and c>y and b>x and b>z):\n Team1=True\n\nif(((x>b and w>c) or (z>b and y>c)) and ((x>d and w>a) or (z>d and y>a))):\n Team2=True\n\n\nif(Team1):\n print(\"Team 1\")\nelif(Team2):\n print(\"Team 2\")\nelse:\n print(\"Draw\")\n", "passed": true, "time": 0.15, "memory": 14588.0, "status": "done"}, {"code": "def check(a1,b1,a2,b2):\n\tif b1 > a2 and a1 > b2:\n\t\treturn True\n\treturn False\ndef solve(x):\n\tif (check(x[0][0],x[1][1],x[2][0],x[3][1]) and check(x[0][0],x[1][1],x[3][0],x[2][1])) or \\\n\t (check(x[1][0],x[0][1],x[2][0],x[3][1]) and check(x[1][0],x[0][1],x[3][0],x[2][1])):\n\t\treturn 1\n\tif (check(x[3][0],x[2][1],x[0][0],x[1][1]) or check(x[2][0],x[3][1],x[0][0],x[1][1])) and \\\n\t (check(x[3][0],x[2][1],x[1][0],x[0][1]) or check(x[2][0],x[3][1],x[1][0],x[0][1])):\n\t\treturn 2\n\treturn 0\ndef main():\n\tx = []\n\tfor i in range(4):\n\t\ttmp = list(map(int,input().split()))\n\t\tx.append(tmp)\n\tw = solve(x)\n\tif w == 0:\n\t\tprint('Draw')\n\telse:\n\t\tprint('Team {}'.format(w))\nmain()", "passed": true, "time": 0.2, "memory": 14528.0, "status": "done"}, {"code": "def win(a,b,c,d):\n if a>d and b>c: return 1\n return 0\na={}\nb={}\nfor i in range(2): \n a[i*2],b[i*2]=list(map(int,input('').split()))\n a[1+i*2],b[1+i*2]=list(map(int,input('').split()))\n h=b[i*2]\n b[i*2]=b[1+i*2]\n b[1+i*2]=h\nif (win(a[0],b[0],a[2],b[2])*win(a[0],b[0],a[3],b[3])==1) or (win(a[1],b[1],a[2],b[2])*win(a[1],b[1],a[3],b[3])==1):\n print ('Team 1')\n return\nif (win(a[2],b[2],a[0],b[0])*win(a[2],b[2],a[1],b[1])==1) or (win(a[3],b[3],a[0],b[0])*win(a[3],b[3],a[1],b[1])==1) or (win(a[2],b[2],a[0],b[0])*win(a[3],b[3],a[1],b[1])==1) or (win(a[2],b[2],a[1],b[1])*win(a[3],b[3],a[0],b[0])==1):\n print ('Team 2')\n return\nprint('Draw')\n\n\n", "passed": true, "time": 0.18, "memory": 14604.0, "status": "done"}, {"code": "def _win(a, b, c, d):\n if a[0] > c[1] and b[1] > d[0]:\n return 1\n elif a[0] < c[1] and b[1] < d[0]:\n return -1\n else:\n return 0\n\n\ndef win(a, b, c, d):\n nonlocal p\n return _win(p[a], p[b], p[c], p[d])\n\n\ndef win_comb(a, b, c, d):\n x, y = win(a, b, c, d), win(a, b, d, c)\n if x == 1 and y == 1:\n return 1\n if x == -1 or y == -1:\n return -1\n return 0\n\n\ndef win_team1(a, b, c, d):\n x, y = win_comb(a, b, c, d), win_comb(b, a, c, d)\n if x == 1 or y == 1:\n return 1\n if x == -1 and y == -1:\n return -1\n return 0\n\np = []\nfor i in range(4):\n p.append(tuple(map(int, input().split())))\nw = win_team1(0, 1, 2, 3)\nif w == 1:\n print('Team 1')\nelif w == -1:\n print('Team 2')\nelse:\n print('Draw')\n", "passed": true, "time": 0.14, "memory": 14616.0, "status": "done"}, {"code": "team1, team2 = (lambda t : [[list(map(int, input().split())) for x in range(2)] for y in range(2)])('input')\nif (lambda t1, t2 : any(all(t1[x][0] > t2[y][1] and t1[1 - x][1] > t2[1 - y][0] for y in range(2)) for x in range(2)))(team1, team2):\n print('Team 1')\nelif (lambda t1, t2 : all(any(t2[y][0] > t1[x][1] and t2[1 - y][1] > t1[1 - x][0] for y in range(2)) for x in range(2)))(team1, team2):\n print('Team 2')\nelse:\n print('Draw')\n", "passed": true, "time": 0.23, "memory": 14308.0, "status": "done"}, {"code": "import sys\nread = lambda: list(map(int, sys.stdin.readline().split()))\na0, d0 = read()\na1, d1 = read()\n\na2, d2 = read()\na3, d3 = read()\n\nw02 = a0 > d3 and d1 > a2\nw03 = a0 > d2 and d1 > a3\nw12 = a1 > d3 and d0 > a2\nw13 = a1 > d2 and d0 > a3\n\nw20 = a2 > d1 and d3 > a0\nw21 = a2 > d0 and d3 > a1\nw30 = a3 > d1 and d2 > a0\nw31 = a3 > d0 and d2 > a1\n\nif w02 and w03 or w12 and w13:\n print(\"Team 1\")\nelif (w20 or w30) and (w21 or w31):\n print(\"Team 2\")\nelse:\n print(\"Draw\")\n", "passed": true, "time": 0.15, "memory": 14412.0, "status": "done"}, {"code": "def main():\n\tM = [0] * 4\n\tfor i in range(4):\n\t\tM[i] = list(map(int, input().split()))\n\n\tW = [[0] * 2 for i in range(2)]\n\tfor i in range(0, 2):\n\t\tfor j in range(2, 4):\n\t\t\tif M[i][0] > M[j][1] and M[i ^ 1][1] > M[j ^ 1][0]:\n\t\t\t\tW[i][j - 2] = 1\n\t\t\telif M[i][0] < M[j][1] and M[i ^ 1][1] < M[j ^ 1][0]:\n\t\t\t\tW[i][j - 2] = -1\n\t\t\telse:\n\t\t\t\tW[i][j - 2] = 0\n\tif max(W[0][0] + W[0][1], W[1][0] + W[1][1]) == 2:\n\t\tprint(\"Team 1\")\n\telif min(W[0][0], W[0][1]) + min(W[1][0], W[1][1]) == -2:\n\t\tprint(\"Team 2\")\n\telse:\n\t\tprint(\"Draw\")\n\nmain()", "passed": true, "time": 0.25, "memory": 14492.0, "status": "done"}, {"code": "mtr=[[1,0],[0,1]]\np1=list(map(int,input().split()))\np2=list(map(int,input().split()))\np3=list(map(int,input().split()))\np4=list(map(int,input().split()))\nw1=w2=0\nfor l1 in mtr:\n wi1=wi2=0\n for l2 in mtr:\n at1=p1[1] if l1[0]==1 else p2[1]\n z1=p1[0] if l1[0]==0 else p2[0]\n at2=p3[1] if l2[0]==1 else p4[1]\n z2=p3[0] if l2[0]==0 else p4[0]\n if at1>z2 and z1>at2:\n wi1+=1\n elif at1<z2 and z1<at2:\n wi2+=1\n if wi2>=1:\n w2+=1\n elif wi1==2:\n w1+=1\nif w2==2:\n print('Team 2')\nelif w1>=1:\n print('Team 1')\nelse:\n print('Draw')\n", "passed": true, "time": 0.14, "memory": 14376.0, "status": "done"}, {"code": "def check(a, b, c, d):\n if a > d and b > c:\n return 1\n return 0\na = [0 for i in range(4)]\nb = [0 for i in range(4)]\nfor i in range(4):\n a[i], b[i] = map(int, input().split())\nif check(a[0], b[1], a[2], b[3]) and check(a[0], b[1], a[3], b[2]):\n print('Team 1')\nelif check(a[1], b[0], a[2], b[3]) and check(a[1], b[0], a[3], b[2]):\n print('Team 1')\nelif (check(a[2], b[3], a[0], b[1]) or check(a[3], b[2], a[0], b[1])) and (check(a[3], b[2], a[1], b[0]) or check(a[2], b[3], a[1], b[0])):\n print('Team 2')\nelse:\n print('Draw')", "passed": true, "time": 0.16, "memory": 14384.0, "status": "done"}, {"code": " \ndef play(t1, t2): \n r = 0\n if t1[0] > t2[1] and t1[1] > t2[0]:\n r = 1\n elif t1[0] < t2[1] and t1[1] < t2[0]:\n r = -1\n else:\n r = 0\n #print(\"play:\", t1, t2, r)\n return r\n\np = []\nm = []\nres = []\n\nfor _ in range(4):\n a, b = map(int, input().split(\" \"))\n p.append((a, b)) \n\nm.append((p[0][0], p[1][1]))\nm.append((p[1][0], p[0][1]))\nm.append((p[2][0], p[3][1]))\nm.append((p[3][0], p[2][1]))\n \nres.append((play(m[0], m[2]), play(m[0], m[3])))\nres.append((play(m[1], m[2]), play(m[1], m[3])))\n\n#print(res)\nmm = max([max(i) for i in res])\nres = [i for i in res if max(i) == mm]\nres = [min(i) for i in res]\n#print(res)\n#rr = min(res) + 1\nif 1 in res:\n rr = 2\nelse:\n rr = max(res) + 1\nss = [\"Team 2\", \"Draw\", \"Team 1\"]\nprint(ss[rr])", "passed": true, "time": 0.25, "memory": 14588.0, "status": "done"}, {"code": "def f():\n a, b = map(int, input().split())\n A, B = map(int, input().split())\n return ((a, B), (A, b))\ndef g(u, v): return u[0] > v[1] and u[1] > v[0]\nx, y = f(), f()\nif any(all(g(j, i) for i in y) for j in x): print('Team 1')\nelif all(any(g(i, j) for i in y) for j in x): print('Team 2')\nelse: print('Draw')", "passed": true, "time": 0.18, "memory": 14548.0, "status": "done"}, {"code": "p1 = list(map(int, input().split()))\np2 = list(map(int, input().split()))\np3 = list(map(int, input().split()))\np4 = list(map(int, input().split()))\n\nt1 = [(p1[0],p2[1]), (p2[0],p1[1])]\nscore = [0,0]\nt2 = [(p3[0],p4[1]), (p4[0],p3[1])]\nt11 = t1[0]\nt12 = t1[1]\nt21 = t2[0]\nt22 = t2[1]\n# if any team of t1 wins both game, then t1 wins\n# if any both team loses to any of t2, t2 wins\n\nif t11[0] > t21[1] and t11[0] > t22[1] and t11[1] > t21[0] and t11[1] >t22[0]:\n print(\"Team 1\")\nelif t12[0] > t21[1] and t12[0] > t22[1] and t12[1] > t21[0] and t12[1] >t22[0]:\n print(\"Team 1\")\nelif ((t11[0] < t21[1] and t11[1] < t21[0] ) or ( t11[0] < t22[1] and t11[1] < t22[0])) and ((t12[0] < t21[1] and t12[1] < t21[0] ) or ( t12[0] < t22[1] and t12[1] < t22[0])):\n print(\"Team 2\")\nelse:\n print(\"Draw\")\n\n\n\n\n\n\n", "passed": true, "time": 0.14, "memory": 14520.0, "status": "done"}, {"code": "def get_tuple():\n\ta, A = list(map(int, input().split()))\n\tb, B = list(map(int, input().split()))\n\treturn (a,B), (b,A)\n\ndef larger(a1, a2):\n\treturn a1[0] > a2[1] and a1[1] > a2[0]\n\ndef smaller(a1, a2):\n\treturn a1[0] < a2[1] and a1[1] < a2[0]\n\nt11, t12 = get_tuple()\nt21, t22 = get_tuple()\n\nif larger(t11,t21) and larger(t11, t22):\n\tprint(\"Team 1\")\nelif larger(t12, t21) and larger(t12, t22):\n\tprint(\"Team 1\")\nelif (smaller(t11,t21) or smaller(t11, t22)) and (smaller(t12, t21) or smaller(t12, t22)):\n\tprint(\"Team 2\")\nelse:\n\tprint(\"Draw\")\n\n\n\n", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "p11 = list(map(int, input().split()))\np12 = list(map(int, input().split()))\np21 = list(map(int, input().split()))\np22 = list(map(int, input().split()))\n\ndef f(a, b, c, d):\n if a[0] > d[1] and b[1] > c[0]:\n return 1\n if a[0] < d[1] and b[1] < c[0]:\n return 2\n return 0\n\nc1 = f(p11, p12, p21, p22)\nc2 = f(p12, p11, p21, p22)\nc3 = f(p11, p12, p22, p21)\nc4 = f(p12, p11, p22, p21)\n#print(c1, c2, c3, c4)\n#false - win 1 true - win 2\n\nif ((c1 == 2 or c3 == 2) and (c2 == 2 or c4 == 2)):\n print(\"Team 2\")\nelif ((c1 == 1 and c3 == 1) or (c2 == 1 and c4 == 1)):\n print(\"Team 1\")\nelse:\n print(\"Draw\")\n", "passed": true, "time": 0.16, "memory": 14392.0, "status": "done"}, {"code": "team1, team2 = (lambda t : [[list(map(int, input().split())) for x in range(2)] for y in range(2)])('input')\nif (lambda t1, t2 : any(all(t1[x][0] > t2[y][1] and t1[1 - x][1] > t2[1 - y][0] for y in range(2)) for x in range(2)))(team1, team2):\n print('Team 1')\nelif (lambda t1, t2 : all(any(t2[y][0] > t1[x][1] and t2[1 - y][1] > t1[1 - x][0] for y in range(2)) for x in range(2)))(team1, team2):\n print('Team 2')\nelse:\n print('Draw')\n", "passed": true, "time": 0.14, "memory": 14520.0, "status": "done"}, {"code": "def find_winer(defence1, attack1, defence2, attack2):\n if defence1[0] > attack2[1] and attack1[1] > defence2[0]:\n return 1\n elif defence1[0] < attack2[1] and attack1[1] < defence2[0]:\n return 2\n else:\n return 0\n\n\ndef find_results(players):\n results = []\n results.append(find_winer(players[0], players[1], players[2], players[3]))\n results.append(find_winer(players[0], players[1], players[3], players[2]))\n results.append(find_winer(players[1], players[0], players[2], players[3]))\n results.append(find_winer(players[1], players[0], players[3], players[2]))\n\n return results\n\n\ndef solve():\n players = []\n for i in range(4):\n players.append(tuple(map(int, input().split())))\n\n results = find_results(players)\n if (results[0] == 1 and results[1] == 1) or (results[2] == 1 and results[3] == 1):\n print (\"Team 1\")\n elif (results[0] == 2 or results[1] == 2) and (results[2] == 2 or results[3] == 2):\n print(\"Team 2\")\n else:\n print(\"Draw\")\n\n\nsolve()\n", "passed": true, "time": 0.17, "memory": 14364.0, "status": "done"}, {"code": "x = [tuple(int(i) for i in input().split()) for j in range(4)]\nif x[0][0] + x[1][1] > x[0][1] + x[1][0]:\n t1atk = x[1][1]\n t1def = x[0][0]\nelse:\n t1atk = x[0][1]\n t1def = x[1][0]\n\ndef f():\n if t1atk > t2def and t1def > t2atk:\n return 0\n elif t1atk < t2def and t1def < t2atk:\n return 2\n else:\n return 1\n\nt2def = x[2][0]\nt2atk = x[3][1]\na = f()\n\nt2def = x[3][0]\nt2atk = x[2][1]\nb = f()\n\nif a > b:\n t2def = x[2][0]\n t2atk = x[3][1]\nelse:\n t2def = x[3][0]\n t2atk = x[2][1]\n\nif t1atk > t2def and t1def > t2atk:\n print(\"Team 1\")\nelif t1atk < t2def and t1def < t2atk:\n print(\"Team 2\")\nelse:\n print(\"Draw\")\n\n", "passed": true, "time": 0.14, "memory": 14524.0, "status": "done"}, {"code": "p1 = input().split(\" \")\np2 = input().split(\" \")\np3 = input().split(\" \")\np4 = input().split(\" \")\n\n# type 1, p1, p2\nversion11 = int(p1[0]) > int(p3[1]) and int(p2[1]) > int(p4[0])\nversion12 = int(p1[0]) > int(p4[1]) and int(p2[1]) > int(p3[0])\nversion21 = int(p2[0]) > int(p3[1]) and int(p1[1]) > int(p4[0])\nversion22 = int(p2[0]) > int(p4[1]) and int(p1[1]) > int(p3[0])\n\nversion112 = int(p1[0]) < int(p3[1]) and int(p2[1]) < int(p4[0])\nversion122 = int(p1[0]) < int(p4[1]) and int(p2[1]) < int(p3[0])\nversion212 = int(p2[0]) < int(p3[1]) and int(p1[1]) < int(p4[0])\nversion222 = int(p2[0]) < int(p4[1]) and int(p1[1]) < int(p3[0])\n\nif (version11 and version12) or (version21 and version22):\n\tprint(\"Team 1\")\nelif (version112 or version122) and (version212 or version222):\n\tprint(\"Team 2\")\nelse:\n\tprint(\"Draw\")\n", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}, {"code": "a1,d1 = [int(a) for a in input().split()]\na2,d2 = [int(a) for a in input().split()]\na3,d3 = [int(a) for a in input().split()]\na4,d4 = [int(a) for a in input().split()]\n\n# Team 1 wins if E a team 1 st A team 2, team 1 must win\n# Team 2 wins if A team 1 E team 2 st team 2 must win\n\nteam1win = False\nfor (A1,D1) in [(a1,d2),(a2,d1)]:\n good = True\n for (A2,D2) in [(a3,d4),(a4,d3)]:\n if A1 <= D2 or D1 <= A2:\n good = False\n if good:\n team1win = True\nteam2win = True\nfor (A1,D1) in [(a1,d2),(a2,d1)]:\n good = False\n for (A2,D2) in [(a3,d4),(a4,d3)]:\n if D2 > A1 and A2 > D1:\n good = True\n if not good:\n team2win = False\n\nif team1win:\n print('Team 1')\nelif team2win:\n print('Team 2')\nelse:\n print('Draw')\n", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "def f():\n a, b = list(map(int, input().split()))\n A, B = list(map(int, input().split()))\n return ((a, B), (A, b))\ndef g(u, v): return u[0] > v[1] and u[1] > v[0]\nx, y = f(), f()\nif any(all(g(j, i) for i in y) for j in x): print('Team 1')\nelif all(any(g(i, j) for i in y) for j in x): print('Team 2')\nelse: print('Draw')\n", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "def f():\n a, b = list(map(int, input().split()))\n A, B = list(map(int, input().split()))\n return ((a, B), (A, b))\ndef g(u, v): return u[0] > v[1] and u[1] > v[0]\nx, y = f(), f()\nif any(all(g(j, i) for i in y) for j in x): print('Team 1')\nelif all(any(g(i, j) for i in y) for j in x): print('Team 2')\nelse: print('Draw')\n", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}, {"code": "def f():\n a, b = list(map(int, input().split()))\n A, B = list(map(int, input().split()))\n return ((a, B), (A, b))\ndef g(u, v): return u[0] > v[1] and u[1] > v[0]\nx, y = f(), f()\nif any(all(g(j, i) for i in y) for j in x): print('Team 1')\nelif all(any(g(i, j) for i in y) for j in x): print('Team 2')\nelse: print('Draw')\n", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "def f():\n a, b = list(map(int, input().split()))\n A, B = list(map(int, input().split()))\n return ((a, B), (A, b))\ndef g(u, v): return u[0] > v[1] and u[1] > v[0]\nx, y = f(), f()\nif any(all(g(j, i) for i in y) for j in x): print('Team 1')\nelif all(any(g(i, j) for i in y) for j in x): print('Team 2')\nelse: print('Draw')\n", "passed": true, "time": 0.24, "memory": 14400.0, "status": "done"}, {"code": "def f():\n a, b = list(map(int, input().split()))\n A, B = list(map(int, input().split()))\n return ((a, B), (A, b))\ndef g(u, v): return u[0] > v[1] and u[1] > v[0]\nx, y = f(), f()\nif any(all(g(j, i) for i in y) for j in x): print('Team 1')\nelif all(any(g(i, j) for i in y) for j in x): print('Team 2')\nelse: print('Draw')\n", "passed": true, "time": 0.15, "memory": 14404.0, "status": "done"}, {"code": "def f():\n a, b = list(map(int, input().split()))\n A, B = list(map(int, input().split()))\n return ((a, B), (A, b))\ndef g(u, v): return u[0] > v[1] and u[1] > v[0]\nx, y = f(), f()\nif any(all(g(j, i) for i in y) for j in x): print('Team 1')\nelif all(any(g(i, j) for i in y) for j in x): print('Team 2')\nelse: print('Draw')\n", "passed": true, "time": 0.14, "memory": 14472.0, "status": "done"}]
[{"input": "1 100\n100 1\n99 99\n99 99\n", "output": "Team 1\n"}, {"input": "1 1\n2 2\n3 3\n2 2\n", "output": "Team 2\n"}, {"input": "3 3\n2 2\n1 1\n2 2\n", "output": "Draw\n"}, {"input": "80 79\n79 30\n80 81\n40 80\n", "output": "Team 2\n"}, {"input": "10 10\n4 9\n8 9\n7 6\n", "output": "Team 1\n"}, {"input": "10 2\n9 3\n3 1\n9 4\n", "output": "Draw\n"}, {"input": "6 3\n6 10\n2 5\n4 4\n", "output": "Team 1\n"}, {"input": "8 7\n1 5\n7 4\n8 8\n", "output": "Draw\n"}, {"input": "2 7\n8 4\n4 6\n10 8\n", "output": "Draw\n"}, {"input": "8 3\n4 9\n6 1\n5 6\n", "output": "Team 1\n"}, {"input": "10 5\n3 1\n1 9\n1 2\n", "output": "Draw\n"}, {"input": "6 5\n10 6\n8 1\n3 2\n", "output": "Draw\n"}, {"input": "6 2\n7 5\n5 4\n8 6\n", "output": "Draw\n"}, {"input": "1 10\n1 10\n1 1\n7 8\n", "output": "Draw\n"}, {"input": "16 7\n9 3\n11 2\n11 4\n", "output": "Draw\n"}, {"input": "20 17\n14 10\n10 7\n19 18\n", "output": "Draw\n"}, {"input": "12 7\n3 17\n4 15\n2 8\n", "output": "Draw\n"}, {"input": "8 14\n8 12\n7 20\n14 6\n", "output": "Draw\n"}, {"input": "4 4\n4 15\n2 4\n10 12\n", "output": "Draw\n"}, {"input": "4 10\n9 9\n9 12\n13 10\n", "output": "Team 2\n"}, {"input": "20 20\n18 8\n15 5\n17 20\n", "output": "Draw\n"}, {"input": "12 10\n7 3\n10 5\n1 14\n", "output": "Draw\n"}, {"input": "8 16\n12 10\n13 18\n8 4\n", "output": "Draw\n"}, {"input": "16 15\n19 1\n16 16\n20 9\n", "output": "Draw\n"}, {"input": "12 29\n44 8\n18 27\n43 19\n", "output": "Draw\n"}, {"input": "28 46\n50 27\n23 50\n21 45\n", "output": "Draw\n"}, {"input": "40 6\n9 1\n16 18\n4 23\n", "output": "Draw\n"}, {"input": "4 16\n6 28\n12 32\n28 3\n", "output": "Draw\n"}, {"input": "16 22\n11 3\n17 5\n12 27\n", "output": "Draw\n"}, {"input": "32 32\n10 28\n14 23\n39 5\n", "output": "Draw\n"}, {"input": "48 41\n15 47\n11 38\n19 31\n", "output": "Team 1\n"}, {"input": "8 9\n11 17\n11 6\n5 9\n", "output": "Draw\n"}, {"input": "24 19\n18 44\n8 29\n30 39\n", "output": "Draw\n"}, {"input": "22 4\n29 38\n31 43\n47 21\n", "output": "Team 2\n"}, {"input": "51 54\n95 28\n42 28\n17 48\n", "output": "Team 1\n"}, {"input": "11 64\n92 47\n88 93\n41 26\n", "output": "Draw\n"}, {"input": "27 74\n97 22\n87 65\n24 52\n", "output": "Draw\n"}, {"input": "43 32\n49 48\n42 33\n60 30\n", "output": "Draw\n"}, {"input": "55 50\n54 23\n85 6\n32 60\n", "output": "Team 2\n"}, {"input": "19 56\n59 46\n40 70\n67 34\n", "output": "Team 2\n"}, {"input": "31 67\n8 13\n86 91\n43 12\n", "output": "Team 2\n"}, {"input": "47 77\n13 88\n33 63\n75 38\n", "output": "Draw\n"}, {"input": "59 35\n10 14\n88 23\n58 16\n", "output": "Draw\n"}, {"input": "63 4\n18 60\n58 76\n44 93\n", "output": "Draw\n"}, {"input": "14 47\n47 42\n21 39\n40 7\n", "output": "Team 1\n"}, {"input": "67 90\n63 36\n79 56\n25 56\n", "output": "Team 1\n"}, {"input": "64 73\n59 46\n8 19\n57 18\n", "output": "Team 1\n"}, {"input": "23 80\n62 56\n56 31\n9 50\n", "output": "Team 1\n"}, {"input": "86 95\n86 38\n59 66\n44 78\n", "output": "Team 1\n"}, {"input": "10 3\n2 5\n1 10\n2 10\n", "output": "Draw\n"}, {"input": "62 11\n79 14\n46 36\n91 52\n", "output": "Draw\n"}, {"input": "8 4\n9 10\n7 3\n6 5\n", "output": "Team 1\n"}, {"input": "21 12\n29 28\n16 4\n10 1\n", "output": "Team 1\n"}, {"input": "91 71\n87 45\n28 73\n9 48\n", "output": "Team 1\n"}, {"input": "4 1\n4 3\n6 4\n2 8\n", "output": "Team 2\n"}, {"input": "11 7\n12 8\n15 14\n14 14\n", "output": "Team 2\n"}, {"input": "12 7\n3 15\n20 18\n20 8\n", "output": "Team 2\n"}, {"input": "4 7\n24 11\n17 30\n21 4\n", "output": "Team 2\n"}, {"input": "21 22\n21 16\n32 14\n39 35\n", "output": "Team 2\n"}, {"input": "16 48\n16 49\n10 68\n60 64\n", "output": "Team 2\n"}, {"input": "46 33\n12 3\n11 67\n98 77\n", "output": "Team 2\n"}, {"input": "19 9\n47 28\n83 41\n76 14\n", "output": "Draw\n"}, {"input": "36 68\n65 82\n37 6\n21 60\n", "output": "Team 1\n"}, {"input": "70 98\n62 5\n30 50\n66 96\n", "output": "Draw\n"}, {"input": "45 69\n91 96\n72 67\n24 30\n", "output": "Draw\n"}, {"input": "34 38\n91 17\n2 12\n83 90\n", "output": "Draw\n"}, {"input": "30 31\n98 15\n40 62\n10 22\n", "output": "Draw\n"}]
258
Monocarp and Bicarp live in Berland, where every bus ticket consists of $n$ digits ($n$ is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even. Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits. Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from $0$ to $9$. The game ends when there are no erased digits in the ticket. If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally. -----Input----- The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ β€” the number of digits in the ticket. The second line contains a string of $n$ digits and "?" characters β€” the ticket which Monocarp and Bicarp have found. If the $i$-th character is "?", then the $i$-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even. -----Output----- If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes). -----Examples----- Input 4 0523 Output Bicarp Input 2 ?? Output Bicarp Input 8 ?054??0? Output Bicarp Input 6 ???00? Output Monocarp -----Note----- Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp. In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
interview
[{"code": "n=int(input())\ns=input()\nleft=0\nright=0\nleft_ques=0\nright_ques=0\nfor i in range(n):\n if i<n//2:\n if s[i]=='?':\n left_ques+=1\n else :\n left+=int(s[i])\n else :\n if s[i]=='?':\n right_ques+=1\n else :\n right+=int(s[i])\nx=min(left_ques,right_ques)\nleft_ques-=x\nright_ques-=x\nif left_ques==0 and right_ques==0:\n if left==right:\n print(\"Bicarp\")\n else :\n print(\"Monocarp\")\nelse :\n if left_ques==0:\n if right_ques%2==0:\n x=9*(right_ques//2)+right\n if x==left:\n print(\"Bicarp\")\n else :\n print(\"Monocarp\")\n else :\n print(\"Monocarp\")\n else :\n if left_ques%2==0:\n x=9*(left_ques//2)+left\n if x==right:\n print(\"Bicarp\")\n else :\n print(\"Monocarp\")\n else :\n print(\"Monocarp\")", "passed": true, "time": 0.39, "memory": 14452.0, "status": "done"}, {"code": "n = int(input())\na = input()\nif a.count('?') % 2 == 1:\n print('Monocarp')\nelse:\n x = y = k = m = 0\n for q in range(n):\n if q*2 < n:\n if a[q] == '?':\n k += 1\n else:\n x += int(a[q])\n else:\n if a[q] == '?':\n m += 1\n else:\n y += int(a[q])\n if (y - x) % 9 == 0 and (y - x) // 9 == (k-m)//2:\n print('Bicarp')\n else:\n print('Monocarp')\n", "passed": true, "time": 0.15, "memory": 14332.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\nsys.setrecursionlimit(1000000)\ndef lis():return [int(i) for i in input().split()]\ndef value():return int(input())\n\n\nn=value()\na=input().strip('\\n')\nl1,l2=a[:(n//2)].count('?'),a[(n//2):].count('?')\ns1 = s2 = 0\nfor i in range(len(a)):\n if i<n//2:\n s1+=int(a[i]) if a[i]!='?' else 0\n else:\n s2+=int(a[i]) if a[i]!='?' else 0\nno = 1\nfor i in range(l1):\n if s1>s2:\n if no:\n s1+=9\n else:s1+=0\n else:\n if no:\n s1+=0\n else:s1+=9\n no = 1 - no\nfor i in range(l2):\n if s1>s2:\n if no:\n s2+=0\n else:s2+=9\n else:\n if no:\n s2+=9\n else:s2+=0\n no = 1 - no\nif s1!=s2:print('Monocarp')\nelse:print('Bicarp')\n \n", "passed": true, "time": 0.39, "memory": 14292.0, "status": "done"}, {"code": "import sys\n\nn = int(sys.stdin.readline().strip())\nm = n // 2\ns = sys.stdin.readline().strip()\ns1 = 0\ns2 = 0\nx1 = 0\nx2 = 0\nfor i in range (0, m):\n if s[i] == \"?\":\n x1 = x1 + 1\n else:\n s1 = s1 + int(str(s[i]))\n if s[m+i] == \"?\":\n x2 = x2 + 1\n else:\n s2 = s2 + int(str(s[m+i]))\nif s1 + (x1 // 2) * 9 == s2 + (x2 // 2) * 9:\n print(\"Bicarp\")\nelse:\n print(\"Monocarp\")\n \n", "passed": true, "time": 1.8, "memory": 14316.0, "status": "done"}, {"code": "import sys \nfrom collections import defaultdict\ninput = lambda : sys.stdin.readline().rstrip()\n\nn = int(input())\ns = input()\n\nsa = 0\nsb = 0\na = 0\nb = 0\n\n\nfor i in range(n):\n if s[i] == '?':\n if i < n // 2:\n a += 1\n else:\n b += 1\n else:\n if i < n // 2:\n sa += int(s[i])\n else:\n sb += int(s[i])\n\nM = \"Monocarp\"\nB = \"Bicarp\"\n\n\nif sa == sb:\n if a == b:\n print(B)\n return\n else:\n print(M)\n return\n\nif sa <= sb:\n sa, sb = sb, sa\n a, b = b, a\n\nif a == b:\n print(M)\n return\n\nelif a > b:\n print(M)\n return\n\nelse:\n diff = sa - sb\n x = (b - a) // 2\n #print(\"debug\", diff, x)\n if diff == 9*x:\n print(B)\n return\n else:\n print(M)\n return\n\n", "passed": true, "time": 0.27, "memory": 14576.0, "status": "done"}, {"code": "def f(q1, q2, k1, k2):\n res1 = res2 = 0\n res1 += ((q1 + 1) // 2) * k1\n res1 += (q1 // 2) * k2\n res2 += (q2 // 2) * k2\n res2 += ((q2 + 1) // 2) * k1\n return [res1, res2]\n\n\nn = int(input())\ns = input()\nsum_l = sum_r = 0\nql = qr = 0\nfor i in range(n // 2):\n if s[i] == '?':\n ql += 1\n else:\n sum_l += int(s[i])\nfor i in range(n // 2, n):\n if s[i] == '?':\n qr += 1\n else:\n sum_r += int(s[i])\nmn = float('inf')\nmx = float('inf')\nkek = [f(ql, qr, 0, 9), f(ql, qr, 9, 0), f(qr, ql, 9, 0)[::-1], f(qr, ql, 0, 9)[::-1]]\nlol = []\nfor x in kek:\n lol.append(x[0] + sum_l - x[1] - sum_r)\nlol.sort()\nif lol[0] <= 0 <= lol[-1]:\n print('Bicarp')\nelse:\n print('Monocarp')\n", "passed": true, "time": 0.46, "memory": 14548.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nr, delta = 0, 0\n\nfor i in range(n // 2):\n if s[i] == '?':\n r += 1\n else:\n delta += int(s[i])\nfor i in range(n // 2, n):\n if s[i] == '?':\n r -= 1\n else:\n delta -= int(s[i])\n\nif r < 0:\n r = -r\n delta = -delta\n\nif delta + 9 * r // 2 == 0:\n print('Bicarp')\nelse:\n print('Monocarp')", "passed": true, "time": 0.15, "memory": 14528.0, "status": "done"}, {"code": "n = int(input())\ns = input()\ns1 = s[:n//2]\ns2 = s[n//2:]\nsum1 = sum(map(int, filter(str.isdigit, s1)))\nsum2 = sum(map(int, filter(str.isdigit, s2)))\nfree1 = s1.count(\"?\")\nfree2 = s2.count(\"?\")\nans = \"\"\nif free1 == free2:\n if sum1 == sum2:\n ans = \"Bicarp\"\n else:\n ans = \"Monocarp\"\nelse:\n if sum1 > sum2:\n free1, free2 = free2, free1\n sum1, sum2 = sum2, sum1\n if free1 <= free2:\n ans = \"Monocarp\"\n else:\n if (free1 - free2) // 2 * 9 == sum2 - sum1:\n ans = \"Bicarp\"\n else:\n ans = \"Monocarp\"\nprint(ans)", "passed": true, "time": 0.14, "memory": 14520.0, "status": "done"}, {"code": " \n\nn=int(input())\ninp=input()\nsl,sr,qr,ql=0,0,0,0\n\n\nfor i in range(len(inp)//2):\n if inp[i]=='?':\n ql+=1\n else:\n sl+=int(inp[i])\n\nfor i in range(n//2, n):\n if inp[i]=='?':\n qr+=1\n else:\n sr+=int(inp[i])\n\n\n\nif(sl-sr==9*(qr-ql)/2):\n print('Bicarp')\nelse:\n print('Monocarp')\n", "passed": true, "time": 0.37, "memory": 14560.0, "status": "done"}, {"code": "n=int(input())\nticket=input()\nleft=right=diff=0\nfor i in range(n//2):\n if ticket[i] == '?':\n left += 1\n else:\n diff += int(ticket[i])\nfor i in range(n//2,n):\n if ticket[i] == '?':\n right += 1\n else:\n diff -= int(ticket[i])\n\nif left > right:\n temp = left\n left = right\n right = temp\n diff = -diff\n\nbad = ((right-left)//2)*9\nif diff == bad:\n print(\"Bicarp\")\nelse:\n print(\"Monocarp\")\n", "passed": true, "time": 0.26, "memory": 14420.0, "status": "done"}, {"code": "import math\nimport sys\nimport collections\n\n\n# imgur.com/Pkt7iIf.png\n\ndef getdict(n):\n d = {}\n if type(n) is list:\n for i in n:\n if i in d:\n d[i] += 1\n else:\n d[i] = 1\n else:\n for i in range(n):\n t = ii()\n if t in d:\n d[t] += 1\n else:\n d[t] = 1\n return d\ndef sieve(n):\n prime = [True for i in range(n + 1)]\n p = 2\n while (p * p <= n):\n if (prime[p] == True):\n for i in range(p * 2, n + 1, p):\n prime[i] = False\n p += 1\n prime[0] = prime[1] = False\n r = [p for p in range(n + 1) if prime[p]]\n return r\ndef cdiv(n, k): return n // k + (n % k != 0)\ndef ii(): return int(input())\ndef mi(): return map(int, input().split())\ndef li(): return list(map(int, input().split()))\ndef lcm(a, b): return abs(a * b) // math.gcd(a, b)\ndef prr(a, sep = ' '): print(sep.join(map(str, a)))\n\nn = ii()\ns = input()\nl = r = tl = tr = 0\nfor i in s[:n//2]:\n if i == '?':\n tl+=1\n else:\n l += int(i)\nfor i in s[n//2:]:\n if i == '?':\n tr+=1\n else:\n r += int(i)\n\nif tl == tr == 0:\n print('Bicarp') if l == r else print('Monocarp')\n return\n\nif l + cdiv(tl, 2)*9 - r > cdiv(tr, 2)*9 or r + cdiv(tr, 2)*9 - l > cdiv(tl, 2)*9:\n print('Monocarp')\nelse:\n print('Bicarp')", "passed": true, "time": 0.15, "memory": 14652.0, "status": "done"}, {"code": "n = int(input())\nx = input()\n\ndef f(x):\n q, s = 0, 0\n for c in x:\n if c == '?':\n q += 1\n else:\n s += int(c)\n return q, s\n\nlq, ls = f(x[:n//2])\nrq, rs = f(x[n//2:])\n\nlmin = ls\nlmax = ls + 9*lq\n\nrmin = rs\nrmax = rs + 9*rq\n\nlc = lmin+lmax\nrc = rmin+rmax\n\nif lc == rc and (lq+rq)%2 == 0:\n print(\"Bicarp\")\nelse:\n print(\"Monocarp\")\n", "passed": true, "time": 0.32, "memory": 14460.0, "status": "done"}, {"code": "''' CODED WITH LOVE BY SATYAM KUMAR '''\n\nfrom sys import stdin, stdout\nimport heapq\nimport cProfile, math\nfrom collections import Counter, defaultdict, deque\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\nimport sys\n\nsys.setrecursionlimit(10 ** 6) # max depth of recursion\nthreading.stack_size(2 ** 27) # new thread will get stack of such size\nfac_warm_up = False\nprintHeap = str()\nmemory_constrained = False\nP = 10 ** 9 + 7\n\n\nclass MergeFind:\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\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\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\n def set_size(self, a):\n return self.size[self.find(a)]\n\n def __len__(self):\n return self.num_sets\n\n\ndef display(string_to_print):\n stdout.write(str(string_to_print) + \"\\n\")\n\n\ndef prime_factors(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:\n factors[i] = 1\n n = n // i\n if n > 2:\n factors[n] = 1\n return (factors)\n\n\ndef all_factors(n):\n return set(reduce(list.__add__,\n ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))\n\n\ndef fibonacci_modP(n, MOD):\n if n < 2: return 1\n return (cached_fn(fibonacci_modP, (n + 1) // 2, MOD) * cached_fn(fibonacci_modP, n // 2, MOD) + cached_fn(\n fibonacci_modP, (n - 1) // 2, MOD) * cached_fn(fibonacci_modP, (n - 2) // 2, MOD)) % MOD\n\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\n\ndef binary(n, digits=20):\n b = bin(n)[2:]\n b = '0' * (digits - len(b)) + b\n return b\n\n\ndef is_prime(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\n\n\ndef generate_primes(n):\n prime = [True for i in range(n + 1)]\n p = 2\n while p * p <= n:\n if prime[p]:\n for i in range(p * 2, n + 1, p):\n prime[i] = False\n p += 1\n return prime\n\n\nfactorial_modP = []\n\n\ndef warm_up_fac(MOD):\n nonlocal factorial_modP, fac_warm_up\n if fac_warm_up: return\n factorial_modP = [1 for _ in range(fac_warm_up_size + 1)]\n for i in range(2, fac_warm_up_size):\n factorial_modP[i] = (factorial_modP[i - 1] * i) % MOD\n fac_warm_up = True\n\n\ndef InverseEuler(n, MOD):\n return pow(n, MOD - 2, MOD)\n\n\ndef nCr(n, r, MOD):\n nonlocal fac_warm_up, factorial_modP\n if not fac_warm_up:\n warm_up_fac(MOD)\n fac_warm_up = True\n return (factorial_modP[n] * (\n (pow(factorial_modP[r], MOD - 2, MOD) * pow(factorial_modP[n - r], MOD - 2, MOD)) % MOD)) % MOD\n\n\ndef test_print(*args):\n if testingMode:\n print(args)\n\n\ndef display_list(list1, sep=\" \"):\n stdout.write(sep.join(map(str, list1)) + \"\\n\")\n\n\ndef display_2D_list(li):\n for i in li:\n print(i)\n\n\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\n\ndef get_int():\n return int(stdin.readline().strip())\n\n\ndef get_tuple():\n return map(int, stdin.readline().split())\n\n\ndef get_list():\n return list(map(int, stdin.readline().split()))\n\n\nmemory = dict()\n\n\ndef clear_cache():\n nonlocal memory\n memory = dict()\n\n\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\n\ndef ncr(n, r):\n return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))\n\n\ndef binary_search(i, li):\n fn = lambda x: li[x] - x // i\n x = -1\n b = len(li)\n while b >= 1:\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\n# -------------------------------------------------------------- MAIN PROGRAM\n\n\nTestCases = False\nfac_warm_up_size = 10 ** 5 + 100\noptimise_for_recursion = False # Can not be used clubbed with TestCases WHen using recursive functions, use Python 3\n\n\ndef main():\n n = get_int()\n st = list(stdin.readline().strip())\n ls,rs,lq,rq=0,0,0,0\n for i in range(n//2):\n if st[i]=='?':\n lq+=1\n else:\n ls+=int(st[i])\n for i in range(n//2,n):\n if st[i]=='?':\n rq+=1\n else:\n rs+=int(st[i])\n if (lq+rq)%2==0 and ((lq-rq)//2)*9 + ls == rs:\n print(\"Bicarp\")\n else:\n print(\"Monocarp\")\n\n# --------------------------------------------------------------------- END=\n\n\nif TestCases:\n for i in range(get_int()):\n main()\nelse:\n main() if not optimise_for_recursion else threading.Thread(target=main).start()", "passed": true, "time": 0.33, "memory": 14932.0, "status": "done"}, {"code": "N = int(input())\nL = 0\nR = 0\nlq = 0\nrq = 0\nTK = input()\n\nfor i in range(N//2):\n if TK[i] == '?':\n lq += 1\n else:\n L += int(TK[i])\n\nfor i in range(N//2, N):\n if TK[i] == '?':\n rq += 1\n else:\n R += int(TK[i])\n\nif lq == rq:\n if L == R:\n print('Bicarp')\n else:\n print('Monocarp')\n\nt = abs(lq - rq)\n\nif lq > rq:\n R -= L\n if R < 0:\n print('Monocarp')\n else:\n if (t//2) * 9 == R:\n print('Bicarp')\n else:\n print('Monocarp')\n\nif lq < rq:\n L -= R\n if L < 0:\n print('Monocarp')\n else:\n if (t // 2) * 9 == L:\n print('Bicarp')\n else:\n print('Monocarp')", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nlsum = lcount = rsum = rcount = 0\nfor ch in s[:n//2]:\n if ch == '?':\n lcount += 1\n else:\n lsum += int(ch)\n\nfor ch in s[n//2:]:\n if ch == '?':\n rcount += 1\n else:\n rsum += int(ch)\n\nif lcount > rcount:\n delta = rsum - lsum\n count = lcount - rcount\nelse:\n delta = lsum - rsum\n count = rcount - lcount\nif delta == (count//2)*9:\n print('Bicarp')\nelse:\n print('Monocarp')", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nfer = 0\nf = 0\nl = 0\nler = 0\nfor i in range(int(n/2)):\n if s[i] == '?':\n fer += 1\n else:\n f += int(s[i])\nfor i in range(int(n/2),n):\n if s[i] == '?':\n ler += 1\n else:\n l += int(s[i])\nif (fer + ler) %2:\n print('Monocarp')\nelse:\n if f < l:\n if l-f == 9*((fer-ler)/2):\n print('Bicarp')\n else:\n print('Monocarp')\n else:\n if f-l == 9*((ler-fer)/2):\n print('Bicarp')\n else:\n print('Monocarp')", "passed": true, "time": 0.14, "memory": 14568.0, "status": "done"}, {"code": "n = int(input())\ns = input()\np1 = 0\np2 = 0\ns1 = 0\ns2 = 0\nfor i in s[:n // 2]:\n if i == '?':\n p1 += 1\n else:\n s1 += int(i)\n \nfor i in s[n // 2:]:\n if i == '?':\n p2 += 1\n else:\n s2 += int(i)\nif s1 < s2:\n buf = p1\n p1 = p2\n p2 = buf\n buf = s1\n s1 = s2\n s2 = buf\nif p1 > p2:\n print('Monocarp')\nelse:\n p = abs(p1 - p2)\n ss = abs(s1 - s2)\n if ss == (p // 2) * 9:\n print('Bicarp')\n else:\n print('Monocarp')\n", "passed": true, "time": 0.27, "memory": 14468.0, "status": "done"}, {"code": "I = lambda : int(input())\nSI = lambda : input()\nM = \"Monocarp\"; B = \"Bicarp\"\ndef solve(n,s):\n\tlsum = 0\n\tcl = 0\n\trsum = 0\n\tcr = 0\n\n\tfor i in range(n//2):\n\t\tif(s[i]=='?'):\n\t\t\tcl+=1\n\t\telse:\n\t\t\tlsum+=int(s[i])\n\n\tfor i in range(n//2,n):\n\t\tif(s[i]=='?'):\n\t\t\tcr+=1\n\t\telse:\n\t\t\trsum+=int(s[i])\n\n\tdif = lsum-rsum\n\tif(dif==0):\n\t\tif(cl==cr):print(B)\n\t\telse: print(M)\n\t\treturn\n\tif(cl==cr):\n\t\tprint(M)\n\t\treturn\n\tif((dif>0 and cl>cr) or (dif<0 and cl<cr)):\n\t\tprint(M)\n\t\treturn\n\n\t#Casos dif<0 y cl>cr\n\tif(dif>0):\n\t\tdif= -dif\n\t\tcl,cr = cr,cl\n\tdifc = cl-cr \n\tif(dif+difc//2*9==0):\n\t\tprint(B)\n\telse:\n\t\tprint(M)\n\n\n\n\n\n\n\n\n\t\n\n\n\n\n\n\n\n\n\n\nn = I()\ns = SI()\nsolve(n,s)", "passed": true, "time": 0.14, "memory": 14584.0, "status": "done"}, {"code": "n=int(input())\narr=input()\nlsum=0\nrsum=0\nlq=0\nrq=0\nfor i in range(n//2):\n if(arr[i]=='?'):\n lq+=1\n else:\n lsum+=int(arr[i])\n\nfor i in range(n//2,n):\n if(arr[i]=='?'):\n rq+=1\n else:\n rsum+=int(arr[i])\n#if(lsum==rsum and lq==rq):\n# print(\"Bicarp\")\nif((lq+rq)%2==1):\n print(\"Monocarp\")\nelif((lsum-rsum)//9==(rq-lq)//2 and (lsum-rsum)%9==0):\n print(\"Bicarp\")\nelif((rsum-lsum)//9==(lq-rq)//2 and (rsum-lsum)%9==0):\n print(\"Bicarp\")\nelse:\n print(\"Monocarp\")\n \n \n \n", "passed": true, "time": 0.33, "memory": 14376.0, "status": "done"}, {"code": "n = int(input())\na, b1, b2 = [], [], []\n\nfor i, j in enumerate(input()):\n\tif j == '?':\n\t\tif i < n // 2:\n\t\t\tb1.append(i)\n\t\telse:\n\t\t\tb2.append(i)\n\t\ta.append(0)\n\telse:\n\t\ta.append(int(j))\n\n\ns1 = sum(a[:n // 2])\ns2 = sum(a[n // 2:])\n\n\nprint('Bicarp' if s1 + 9 * (len(b1) + 1) // 2 == s2 + 9 * (len(b2) + 1) // 2 else 'Monocarp')", "passed": true, "time": 0.14, "memory": 14568.0, "status": "done"}, {"code": "def winner(s, n):\n s1 = s[:n//2]\n s2 = s[n//2:]\n turns = s.count('?') // 2\n l1 = r1 = l2 = r2 = 0\n for c in s1:\n if c == '?':\n r1 += 9\n else:\n l1 += int(c)\n r1 += int(c)\n for c in s2:\n if c == '?':\n r2 += 9\n else:\n l2 += int(c)\n r2 += int(c)\n if r1 < l2 or r2 < l1:\n return 'True'\n minDif = min(r1 - l2, r2 - l1)\n return minDif < turns * 9\n\n\nn = int(input())\ns = input()\nprint('Monocarp' if winner(s, n) else 'Bicarp')\n", "passed": true, "time": 0.14, "memory": 14420.0, "status": "done"}, {"code": "o = input()\ninp = input()\ncount_1 = 0\nsum_1 = 0\ncount_2 = 0\nsum_2 = 0\nfor i in range(len(inp)//2):\n if inp[i] == '?':\n count_1 += 1\n else:\n sum_1 += int(inp[i])\n \nfor j in range(len(inp)//2):\n i = len(inp) // 2 + j\n if inp[i] == '?':\n count_2 += 1\n else:\n sum_2 += int(inp[i])\n\n# print(count_1, sum_1, count_2, sum_2)\nif sum_2-sum_1 == 9*(count_1-count_2)//2:\n print('Bicarp')\nelse:\n print('Monocarp')\n", "passed": true, "time": 0.15, "memory": 14328.0, "status": "done"}, {"code": "n=int(input())\n\ns=input()\n\nsum1=0\nkol1=0\nsum2=0\nkol2=0\n\nfor i in range(n//2):\n if s[i]=='?':\n kol1+=1\n else:\n sum1+=int(s[i])\n\nfor i in range(n//2,n):\n if s[i]=='?':\n kol2+=1\n else:\n sum2+=int(s[i])\n\nif sum1>sum2:\n sum1,sum2,kol1,kol2=sum2,sum1,kol2,kol1\n\n\n\nif sum1==sum2 and kol1==kol2:\n print('Bicarp')\nelif sum1==sum2 and kol1!=kol2:\n print('Monocarp')\nelif (sum2-sum1)%9!=0:\n print('Monocarp')\nelif kol1==kol2==0:\n print('Monocarp')\nelif (sum2-sum1)//9==(kol1-kol2)//2:\n print('Bicarp')\nelse:\n print('Monocarp')\n", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "#585_D\n\nn = int(input())\n\nln = list(input())\n\nsm1 = 0\nsm2 = 0\nqs1 = 0\nqs2 = 0\n\nfor i in range(0, n // 2):\n if ln[i] != \"?\":\n qs1 += 1\n sm1 += int(ln[i])\n if ln[n // 2 + i] != \"?\":\n qs2 += 1\n sm2 += int(ln[n // 2 + i])\n\nqs1 = n // 2 - qs1\nqs2 = n // 2 - qs2\nqs = qs1 + qs2\n\nm = False\n\nif not qs:\n if sm1 != sm2:\n m = True\n\nmx = sm1 + min(qs1, qs // 2) * 9\nlft = min(qs2, qs2 - ((qs // 2) - qs1))\nif mx > lft * 9 + sm2:\n m = True\n\nmx = sm2 + min(qs2, qs // 2) * 9\nlft = min(qs1, qs1 - ((qs // 2) - qs2))\nif mx > lft * 9 + sm1:\n m = True\n\nif m:\n print(\"Monocarp\")\nelse:\n print(\"Bicarp\")\n", "passed": true, "time": 0.14, "memory": 14324.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nsd = 0\nqd = 0\n\nfor i in range(n // 2):\n if s[i] == '?':\n qd += 1\n else:\n sd += int(s[i])\n\n if s[n // 2 + i] == '?':\n qd -= 1\n else:\n sd -= int(s[n // 2 + i])\n\nif abs(sd) % 9 > 0:\n print(\"Monocarp\")\n return\n\nif sd >= 0:\n qd += 2 * (sd // 9 + (1 if sd % 9 > 0 else 0))\nelse:\n sd = -1 * sd\n qd -= 2 * (sd // 9 + (1 if sd % 9 > 0 else 0))\n\nprint(\"Bicarp\" if qd == 0 else \"Monocarp\")", "passed": true, "time": 0.14, "memory": 14324.0, "status": "done"}]
[{"input": "4\n0523\n", "output": "Bicarp\n"}, {"input": "2\n??\n", "output": "Bicarp\n"}, {"input": "8\n?054??0?\n", "output": "Bicarp\n"}, {"input": "6\n???00?\n", "output": "Monocarp\n"}, {"input": "80\n????66??8?0?????0??8?45?328??0?6???121038??????4?17??12847??3??65??6?????2????62\n", "output": "Monocarp\n"}, {"input": "8\n923?5???\n", "output": "Bicarp\n"}, {"input": "4\n1928\n", "output": "Bicarp\n"}, {"input": "8\n????????\n", "output": "Bicarp\n"}, {"input": "6\n??????\n", "output": "Bicarp\n"}, {"input": "12\n?3??????3???\n", "output": "Bicarp\n"}, {"input": "12\n37062881?71?\n", "output": "Bicarp\n"}, {"input": "6\n760??4\n", "output": "Bicarp\n"}, {"input": "36\n?????????????????????85????0?5??????\n", "output": "Bicarp\n"}, {"input": "44\n????6???64??????5??0?5??415???27?3??????9?4?\n", "output": "Bicarp\n"}, {"input": "36\n2?13905543?77???????5609170?95?520?6\n", "output": "Bicarp\n"}, {"input": "92\n?????5?1??????0?3????8??????02?6??8?5?????7?4?0???2???????354???538???92?5??17??2???????2?0?\n", "output": "Monocarp\n"}, {"input": "36\n?6???2?98?9336???7??977?91?529?4????\n", "output": "Bicarp\n"}, {"input": "46\n370526653828167168769417?3?808?2?7??4?6340?599\n", "output": "Bicarp\n"}, {"input": "38\n3651868740135970258696?723092?60711479\n", "output": "Bicarp\n"}, {"input": "390\n?6??25?56??????8??43?04?5???77??2???8??11??83580?40012?213??60??9967701???8?728834??5876441?4?02???????0?47??8?66?4?750???06??3?39373???1?4505?7?6??49?22?44?4428????9??0?709????63?8756?84?50??2?8019188?2???8?973859?91?3522??6?197363??2?6?2???51??0????717?38340?5??14??77?908?12245??5????44??????12028??1?5??338???0??4?22?89??7???289?????40?????57??376978?02?0??9??0??85?4??4?986?469??175?6?\n", "output": "Monocarp\n"}, {"input": "56\n7??762?0140?1?7532????2100??22?0?1??3??49717?5?7?7??????\n", "output": "Monocarp\n"}, {"input": "34\n1393?01??03269?6463092?2583?631818\n", "output": "Monocarp\n"}, {"input": "40\n?7553?141912256?7706?6965424511712440846\n", "output": "Monocarp\n"}, {"input": "42\n7?4232301143491162328561?00360618044?43?66\n", "output": "Monocarp\n"}, {"input": "44\n68?03394611?155617?39619?2?65701968??5464?22\n", "output": "Monocarp\n"}, {"input": "70\n093?0?5??98284416?2???5245?6?31??11?16??3?4744?019??321??694?7?356719?\n", "output": "Monocarp\n"}, {"input": "94\n618099?6805736164555?87?454?01?3873?79360983337581807738?74136?54299535321183559?4635?67638831\n", "output": "Monocarp\n"}, {"input": "38\n???9???1?327??2??95?7214???29?592??671\n", "output": "Monocarp\n"}, {"input": "42\n3287?29?7??50????0?0?4?32??32?3??6??88??18\n", "output": "Monocarp\n"}, {"input": "80\n2839373276638149?5031747048891477403878088217434585?0577321794460582953720?09?80\n", "output": "Monocarp\n"}, {"input": "396\n???7?2675?2??52554870???512418???29?6270?638470?154?339014?59??5?3?51577??8?2???1441?86???90?7?6?472??3675?4??1920?9??6258??16362?979??707?0?05682730650?08???04005?54?355??4???530?5?1?9?84416??5???80??8102??2??8??3??868?18?304????68?91225?047175??4??8?14593???58?05661?9?0??4?8??1?47?1881???9751??68????549??85?7163772?044?9??80818?14?6?1364??5?658689?56499?1??87??87?8??????801?3?3?6467?37?49??8\n", "output": "Monocarp\n"}, {"input": "78\n?0??????????????????????????????????????????????????5?????????????????????????\n", "output": "Monocarp\n"}, {"input": "4\n00??\n", "output": "Monocarp\n"}, {"input": "8\n9800????\n", "output": "Monocarp\n"}, {"input": "8\n0????332\n", "output": "Monocarp\n"}, {"input": "8\n111?2???\n", "output": "Monocarp\n"}, {"input": "6\n17????\n", "output": "Monocarp\n"}, {"input": "4\n50??\n", "output": "Monocarp\n"}, {"input": "4\n99??\n", "output": "Monocarp\n"}, {"input": "10\n??????5050\n", "output": "Monocarp\n"}, {"input": "6\n1??203\n", "output": "Monocarp\n"}, {"input": "8\n???0334?\n", "output": "Monocarp\n"}, {"input": "6\n33????\n", "output": "Monocarp\n"}, {"input": "6\n9005??\n", "output": "Monocarp\n"}, {"input": "6\n????01\n", "output": "Monocarp\n"}, {"input": "4\n??99\n", "output": "Monocarp\n"}, {"input": "4\n55??\n", "output": "Monocarp\n"}, {"input": "4\n91??\n", "output": "Monocarp\n"}, {"input": "8\n99??????\n", "output": "Monocarp\n"}, {"input": "6\n143??8\n", "output": "Monocarp\n"}, {"input": "8\n??102800\n", "output": "Bicarp\n"}, {"input": "4\n??80\n", "output": "Monocarp\n"}, {"input": "8\n????9000\n", "output": "Monocarp\n"}, {"input": "10\n??00?0100?\n", "output": "Monocarp\n"}, {"input": "6\n01????\n", "output": "Monocarp\n"}, {"input": "4\n?0?9\n", "output": "Monocarp\n"}, {"input": "10\n?4?21????3\n", "output": "Monocarp\n"}, {"input": "8\n???0332?\n", "output": "Monocarp\n"}, {"input": "6\n99????\n", "output": "Monocarp\n"}, {"input": "6\n3??310\n", "output": "Monocarp\n"}, {"input": "8\n7??1????\n", "output": "Monocarp\n"}, {"input": "8\n????0009\n", "output": "Monocarp\n"}, {"input": "8\n990?9???\n", "output": "Bicarp\n"}, {"input": "8\n908????9\n", "output": "Monocarp\n"}, {"input": "6\n????55\n", "output": "Monocarp\n"}, {"input": "4\n??00\n", "output": "Monocarp\n"}]
259
It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor little boy is to wait for a bus on this rainy day. Under such circumstances, the poor boy will use the first bus he sees no matter where it goes. If several buses come at the same time, he will choose one randomly. Serval will go to the bus station at time $t$, and there are $n$ bus routes which stop at this station. For the $i$-th bus route, the first bus arrives at time $s_i$ minutes, and each bus of this route comes $d_i$ minutes later than the previous one. As Serval's best friend, you wonder which bus route will he get on. If several buses arrive at the same time, you can print any of them. -----Input----- The first line contains two space-separated integers $n$ and $t$ ($1\leq n\leq 100$, $1\leq t\leq 10^5$)Β β€” the number of bus routes and the time Serval goes to the station. Each of the next $n$ lines contains two space-separated integers $s_i$ and $d_i$ ($1\leq s_i,d_i\leq 10^5$)Β β€” the time when the first bus of this route arrives and the interval between two buses of this route. -----Output----- Print one numberΒ β€” what bus route Serval will use. If there are several possible answers, you can print any of them. -----Examples----- Input 2 2 6 4 9 5 Output 1 Input 5 5 3 3 2 5 5 6 4 9 6 1 Output 3 Input 3 7 2 2 2 3 2 4 Output 1 -----Note----- In the first example, the first bus of the first route arrives at time $6$, and the first bus of the second route arrives at time $9$, so the first route is the answer. In the second example, a bus of the third route arrives at time $5$, so it is the answer. In the third example, buses of the first route come at times $2$, $4$, $6$, $8$, and so fourth, buses of the second route come at times $2$, $5$, $8$, and so fourth and buses of the third route come at times $2$, $6$, $10$, and so on, so $1$ and $2$ are both acceptable answers while $3$ is not.
interview
[{"code": "# AC\nimport sys\n\n\nclass Main:\n def __init__(self):\n self.buff = None\n self.index = 0\n\n def __next__(self):\n if self.buff is None or self.index == len(self.buff):\n self.buff = sys.stdin.readline().split()\n self.index = 0\n val = self.buff[self.index]\n self.index += 1\n return val\n\n def next_int(self):\n return int(next(self))\n\n def cal(self, s):\n if len(s) == 1:\n return s[0]\n if s[0] == 0:\n return self.cal(s[1:])\n v = 1\n for c in s:\n v *= c\n return v\n\n def solve(self):\n n = self.next_int()\n t = self.next_int()\n ii = 0\n tt = 10000000\n for i in range(0, n):\n fr = self.next_int()\n d = self.next_int()\n if fr < t:\n fr += (t - fr + d - 1) // d * d\n if fr < tt:\n tt = fr\n ii = i\n print(ii + 1)\n\n\ndef __starting_point():\n Main().solve()\n\n__starting_point()", "passed": true, "time": 0.26, "memory": 14424.0, "status": "done"}, {"code": "n, t = list(map(int, input().split()))\nnearest_t = 200000\nans = 0\nfor i in range(n):\n s, d = list(map(int, input().split()))\n if s >= t and s < nearest_t:\n nearest_t = s\n ans = i + 1\n elif s < t:\n k = (t - s) // d\n if (t - s) % d:\n k += 1\n cur_t = s + d * k\n if cur_t < nearest_t:\n nearest_t = cur_t\n ans = i + 1\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14484.0, "status": "done"}, {"code": "import sys\nfrom math import ceil\n\ninput = sys.stdin.readline\n\nn, t = map(int, input().split())\n\nchoose = []\n\nfor i in range(1, n+1):\n a, b = map(int, input().split())\n if a < t:\n a += ceil((t-a)/b) * b\n \n choose.append((a-t, i))\nchoose.sort()\n\nprint(choose[0][1])", "passed": true, "time": 0.26, "memory": 14404.0, "status": "done"}, {"code": "def main():\n n, t = map(int, input().split())\n mi = 1000000\n ans = 0\n for i in range(n):\n s, d = map(int, input().split())\n L = -1\n R = 1000000\n while R - L != 1:\n M = L + R >> 1\n if s + d * M < t:\n L = M\n else:\n R = M\n if mi > s + d * R:\n mi = s + d * R\n ans = i + 1\n print(ans)\n return 0\nmain()", "passed": true, "time": 0.14, "memory": 14324.0, "status": "done"}, {"code": "\nn,t=[int(k) for k in input().split(\" \")]\nmw=100000000000000\nnbest=-1\n\nfor i in range(n):\n s,d=[int(k) for k in input().split(\" \")]\n if t<s:\n w=s-t\n else:\n w=(d-(t-s))%d\n #print(s,d,w,mw,nbest)\n if w<mw:\n mw=w\n nbest=i+1\nprint(nbest)\n", "passed": true, "time": 0.15, "memory": 14404.0, "status": "done"}, {"code": "from sys import stdin, stdout\nn,t=map(int,input().split())\ntime=1000000\nbusroute=0\nimport math\nfor i in range(n):\n x,y=map(int,input().split())\n if(t<=x):\n curr=x\n else:\n curr=math.ceil((t-x)/y)*y +x\n if(curr<time):\n time=curr\n busroute=i+1\nprint(busroute)", "passed": true, "time": 0.15, "memory": 14328.0, "status": "done"}, {"code": "N, T = list(map(int, input().split()))\n\nans = 0\ncurM = None\nfor n in range(N):\n s, d = list(map(int, input().split()))\n if T <= s or (T - s) % d == 0:\n s = s\n else:\n incre = ((T - s) // d + 1) * d\n s += incre\n if curM == None:\n curM = s\n \n else:\n if curM > s:\n ans = n\n curM = s\nprint(ans + 1) \n \n", "passed": true, "time": 0.14, "memory": 14560.0, "status": "done"}, {"code": "N, T = list(map(int, input().split()))\nmi = 10**100\nfor i in range(N):\n s, d = list(map(int, input().split()))\n if s >= T:\n a = s - T\n else:\n a = (s - T) % d\n if a < mi:\n mi = a\n ans = i + 1\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14308.0, "status": "done"}, {"code": "from math import sqrt, ceil, floor\nfrom sys import stdin, stdout\nfrom heapq import heapify, heappush, heappop\nimport string\nimport bisect \n\n\nn, t = list(map(int, stdin.readline().split()))\nans = 1\nans_t = 9999999\nfor i in range(n):\n s, d = list(map(int, stdin.readline().split()))\n if s < t:\n s = s + ceil((t - s) / d) * d\n if ans_t > s:\n ans = i + 1\n ans_t = s\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "n, t = list(map(int, input().split()))\nans = 10**6\nansi = 0\nfor i in range(n):\n s, d = list(map(int, input().split()))\n s = max(0, t - s + d - 1) // d * d + s\n # print(s)\n if ans > s:\n ans = s\n ansi = i\nprint(ansi+1)\n", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "n, t = map(int, input().split())\nres = [float('inf'), 0]\nfor i in range(1, n + 1):\n s, d = map(int, input().split())\n x = max((t - s + d - 1) // d, 0)\n v = s + d * x\n # print(i, x, v)\n if res[0] > v:\n res = [v, i]\nprint(res[1])", "passed": true, "time": 0.23, "memory": 14288.0, "status": "done"}, {"code": "n,t=[int(i) for i in input().split()]\nsd =[[int(i) for i in input().split()] for j in range(n)]\n\nres = -1\nbest = 10**10\n\nfor i in range(n):\n s,d=sd[i]\n if t<=s:\n if s<best:\n best=s\n res=i\n else:\n left = t-s\n times = left//d\n if left%d!=0:\n times+=1\n s+=d*times\n if s<best:\n best=s\n res=i\nprint(res+1)\n", "passed": true, "time": 0.14, "memory": 14364.0, "status": "done"}, {"code": "N, T = map(int, input().split())\nans = 10**10\nAns = None\nfor i in range(1, N+1):\n a, b = map(int, input().split())\n if a >= T:\n if a < ans:\n Ans = i\n ans = a\n else:\n k = -((-(T-a))//b)\n if a + k*b < ans:\n Ans = i\n ans = a + k*b\nprint(Ans)", "passed": true, "time": 0.15, "memory": 14588.0, "status": "done"}, {"code": "n, t = map(int, input().strip().split())\nmn = 10000000\nnum = 0\nfor i in range(n):\n s,d = map(int, input().strip().split())\n temp = 0\n if s >= t:\n temp= s - t\n else:\n g = t - s\n md = g % d\n if md != 0:\n temp = d - md\n else:\n temp = 0\n if temp < mn:\n mn = temp\n num = i+1\nprint(num)", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "kk=lambda:map(int,input().split())\n# k2=lambda:map(lambda x:int(x)-1, input().split())\nll=lambda:list(kk())\nn,t = kk()\nmv,j = 10000000000,-1\nfor i in range(n):\n\ts,d = kk()\n\twhile s < t: s+=d\n\tif s < mv: mv,j = s,i\nprint(j+1)", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "N, T = list(map(int, input().split()))\nbt = -1\nbr = -1\nfor n in range(N):\n s, d = list(map(int, input().split()))\n if s >= T:\n a = s\n else:\n a = (T-s+d-1) // d\n a = s+d*a\n if bt == -1 or a < bt:\n bt = a\n br = n+1\nprint(br)\n", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n# @Time : 2019/4/13 22:05\n# @Author : LunaFire\n# @Email : [email protected]\n# @File : A. Serval and Bus.py\n\nimport math\n\n\ndef main():\n n, t = list(map(int, input().split()))\n ret, best_time = 0, float('inf')\n for i in range(n):\n s, d = list(map(int, input().split()))\n if s < t:\n k = int(math.ceil((t - s) / d))\n s += k * d\n if s < best_time:\n ret = i + 1\n best_time = s\n print(ret)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14500.0, "status": "done"}, {"code": "n,t=map(int,input().split())\nl=[]\nfor i in range(n):\n s,d=map(int,input().split())\n if s<t:\n if (t-s)%d==0:q=(t-s)//d\n else:q=(t-s)//d+1\n l.append([s+q*d,i+1])\n else:l.append([s,i+1])\nl.sort(key=lambda x:x[0])\nprint(l[0][1])", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "import math\n\ndef main():\n n,t = list(map(int,input().split()))\n buses = []\n min_ans = float('inf')\n index = -1\n for i in range(n):\n s,d = list(map(int,input().split()))\n if s >= t:\n k = 0\n else:\n k = math.ceil((t-s)/d)\n wait = s+(k*d)\n ans = wait-t\n if ans < min_ans:\n min_ans = ans\n index = i+1\n\n print(index)\n\n\nmain()\n", "passed": true, "time": 0.14, "memory": 14560.0, "status": "done"}]
[{"input": "2 2\n6 4\n9 5\n", "output": "1\n"}, {"input": "5 5\n3 3\n2 5\n5 6\n4 9\n6 1\n", "output": "3\n"}, {"input": "3 7\n2 2\n2 3\n2 4\n", "output": "1\n"}, {"input": "1 1\n100000 1\n", "output": "1\n"}, {"input": "1 100000\n99999 100000\n", "output": "1\n"}, {"input": "23 48933\n37408 25138\n92539 90065\n54031 8785\n16124 78360\n21816 61694\n7915 59672\n63840 38545\n43257 33121\n24419 1879\n54154 60377\n85518 11599\n19863 72635\n79717 38348\n56364 70707\n19039 5526\n65706 23396\n54597 86600\n4614 82562\n85239 8755\n55688 35736\n25894 50938\n60749 76228\n34299 48149\n", "output": "9\n"}, {"input": "4 26378\n25074 97197\n56308 49525\n92863 16363\n20209 26816\n", "output": "4\n"}, {"input": "3 85653\n65234 91014\n77378 96540\n74559 98351\n", "output": "1\n"}, {"input": "6 14690\n19559 99872\n17230 93196\n13907 95098\n19149 90749\n12309 92818\n11087 93759\n", "output": "2\n"}, {"input": "37 99816\n19935 98486\n13473 97526\n12932 94864\n12400 98868\n13485 96232\n10902 93340\n10315 93206\n14926 98755\n13524 99060\n10391 94409\n14740 94040\n16968 94901\n18543 98563\n16376 96008\n16802 95903\n19742 97400\n10380 97416\n13674 91688\n16347 99505\n17541 91909\n19573 93640\n11353 96027\n10659 99302\n19752 94125\n16000 99135\n12357 99897\n14255 98774\n19128 97281\n15921 99054\n16403 95692\n11945 91443\n15635 95388\n15628 94580\n17994 99094\n17193 93128\n15775 91876\n19496 92015\n", "output": "31\n"}, {"input": "21 95703\n12848 92619\n17923 92006\n13650 99688\n10518 93442\n16275 99752\n11924 98334\n13605 99756\n15713 93878\n11822 98771\n16759 97491\n16458 95696\n13383 99913\n19776 91284\n18727 99694\n18855 95877\n10599 96362\n16216 95559\n13064 98966\n19205 95522\n10963 97589\n18854 99207\n", "output": "4\n"}, {"input": "30 99189\n14400 91411\n19296 99443\n16233 99602\n17062 97826\n16466 91899\n18575 98230\n19961 94078\n10789 96444\n10164 98164\n13180 90699\n13833 91208\n13637 92329\n12482 98403\n18610 97676\n13887 94748\n18025 91381\n13184 93794\n19975 92729\n12025 91936\n14172 98272\n11755 97941\n13500 98140\n12349 91266\n10373 90073\n19787 96482\n18700 94140\n13744 91321\n18354 92643\n10005 98831\n16556 98996\n", "output": "24\n"}, {"input": "21 49369\n97436 3\n92827 14\n98289 5\n99404 4\n90643 8\n99701 10\n93498 17\n97669 1\n98915 11\n98091 19\n95398 15\n99581 1\n96054 19\n91808 9\n92253 19\n94866 13\n90008 8\n90895 18\n91001 12\n93741 14\n93738 3\n", "output": "17\n"}, {"input": "10 97\n92046 16\n97376 17\n97672 4\n99176 17\n96777 20\n93319 13\n95660 20\n92136 8\n99082 16\n95403 17\n", "output": "1\n"}, {"input": "10 99038\n97786 42218\n38828 27896\n58049 50075\n14935 46788\n89852 38289\n38464 36741\n9413 12603\n67961 40855\n2565 61406\n72007 48904\n", "output": "3\n"}, {"input": "4 96959\n25074 97197\n56308 49525\n92863 16363\n20209 26816\n", "output": "4\n"}, {"input": "2 5\n4 3\n3 3\n", "output": "2\n"}, {"input": "2 7\n4 3\n3 3\n", "output": "1\n"}, {"input": "2 7\n4 4\n3 3\n", "output": "1\n"}, {"input": "2 6\n4 3\n3 3\n", "output": "2\n"}, {"input": "5 100000\n99999 100000\n99998 100000\n99997 100000\n99996 100000\n99995 100000\n", "output": "5\n"}, {"input": "1 100000\n9999 100000\n", "output": "1\n"}, {"input": "2 100000\n99999 11\n99999 10\n", "output": "2\n"}, {"input": "2 100000\n99999 10001\n99999 10000\n", "output": "2\n"}, {"input": "2 20\n2 9\n19 2\n", "output": "1\n"}, {"input": "2 6\n4 10\n4 8\n", "output": "2\n"}, {"input": "2 9\n11 1\n5 2\n", "output": "2\n"}, {"input": "2 2\n3 4\n1 1\n", "output": "2\n"}, {"input": "2 4\n2 3\n1 1\n", "output": "2\n"}, {"input": "2 6\n2 2\n5 2\n", "output": "1\n"}, {"input": "2 3\n2 5\n1 4\n", "output": "2\n"}, {"input": "2 8\n2 4\n2 2\n", "output": "2\n"}, {"input": "2 5\n6 1\n3 2\n", "output": "2\n"}, {"input": "1 4\n2 2\n", "output": "1\n"}, {"input": "2 8\n2 4\n2 3\n", "output": "2\n"}, {"input": "2 11\n1 2\n12 5\n", "output": "1\n"}, {"input": "2 6\n5 5\n9 1\n", "output": "2\n"}, {"input": "2 8\n4 6\n7 1\n", "output": "2\n"}, {"input": "2 9999\n99999 99999\n30000 30000\n", "output": "2\n"}, {"input": "2 100\n101 1\n50 10\n", "output": "2\n"}, {"input": "2 5\n4 100\n15 10\n", "output": "2\n"}, {"input": "1 100000\n99999 99999\n", "output": "1\n"}, {"input": "2 5\n1 2\n6 1\n", "output": "1\n"}, {"input": "2 4\n2 2\n5 1\n", "output": "1\n"}, {"input": "2 11\n5 5\n13 5\n", "output": "2\n"}, {"input": "2 101\n102 69\n1 5\n", "output": "2\n"}, {"input": "2 11\n6 4\n9 3\n", "output": "2\n"}, {"input": "2 5\n3 10\n2 10\n", "output": "2\n"}, {"input": "3 7\n3 10000\n2 20000\n50000 3\n", "output": "1\n"}, {"input": "2 5\n8 10\n1 8\n", "output": "1\n"}, {"input": "2 9\n10 1\n4 5\n", "output": "2\n"}, {"input": "2 100000\n99999 99999\n99997 6\n", "output": "2\n"}, {"input": "2 5\n4 6\n6 1\n", "output": "2\n"}, {"input": "2 3\n1 2\n4 4\n", "output": "1\n"}, {"input": "3 3\n4 1\n2 2\n1 2\n", "output": "3\n"}, {"input": "2 10\n7 4\n12 1\n", "output": "1\n"}, {"input": "2 11\n1 10\n2 10\n", "output": "1\n"}, {"input": "2 5\n7 2\n5 2\n", "output": "2\n"}, {"input": "2 3\n1 2\n4 5\n", "output": "1\n"}, {"input": "2 5\n8 10\n3 6\n", "output": "1\n"}, {"input": "2 9\n7 5\n8 5\n", "output": "1\n"}, {"input": "2 8\n11 1\n1 6\n", "output": "1\n"}, {"input": "1 100000\n9999 9999\n", "output": "1\n"}, {"input": "2 10\n1 4\n2 4\n", "output": "2\n"}, {"input": "2 100000\n99999 10\n999 100000\n", "output": "1\n"}, {"input": "2 2\n8 1\n7 2\n", "output": "2\n"}]
260
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2Β·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 10^18. -----Input----- The first line contains two space-separated integers, m and k (0 ≀ m ≀ 10^18; 1 ≀ k ≀ 64). -----Output----- Print the required number n (1 ≀ n ≀ 10^18). If there are multiple answers, print any of them. -----Examples----- Input 1 1 Output 1 Input 3 2 Output 5
interview
[{"code": "def nck(n, k, cache = {}):\n if k > n or k < 0: return 0\n if k == 0 or k == n: return 1\n if k*2 > n: k = n-k\n if (n, k) in cache: return cache[(n, k)]\n\n z = cache[(n, k)] = nck(n-1, k-1) + nck(n-1, k)\n return z\n\ndef bits(n):\n b = 0\n while n:\n if n&1: b += 1\n n >>= 1\n return b\n\ndef count(n, k):\n z, b, c = 0, 63, 0\n for b in reversed(range(64)):\n if (n>>b)&1:\n z += nck(b, k-c)\n c += 1\n if not k: break\n return z + (bits(n) == k)\n\ndef solve(m, k):\n lo, hi = 1, 10**18\n while lo < hi:\n mi = (lo+hi)//2\n if count(2*mi, k) - count(mi, k) < m:\n lo = mi+1\n else:\n hi = mi\n return hi\n\nm, k = [int(x) for x in input().split()]\nprint(solve(m, k))", "passed": true, "time": 0.54, "memory": 14460.0, "status": "done"}, {"code": "def dfs(n, k, cache = {}):\n # if number of bits is bigger than the number's bits of the number's bits is less than 0\n if k > n or k < 0: return 0\n # if num bits is 0 or num bits is equivalent to the number's bits\n if k == 0 or k == n: return 1\n if k*2 > n: k = n-k\n # Check is already calculated\n if (n, k) in cache: return cache[(n, k)]\n # Use dfs addition for case where certain bit is 1 or certain bit is 0\n z = cache[(n, k)] = dfs(n-1, k-1) + dfs(n-1, k)\n return z\n\ndef bits(n):\n b = 0\n while n:\n if n&1: b += 1\n n >>= 1\n return b\n\ndef count(n, k):\n z, b, c = 0, 63, 0\n for b in reversed(range(64)):\n # Taking n and checking if bit is 1 or not\n if (n>>b)&1:\n z += dfs(b, k-c)\n c += 1\n if not k: break\n return z + (bits(n) == k)\n\ndef solve(m, k):\n # Binary Search for number 1-10^18\n low, high = 1, 10**18\n while low < high:\n mid = (low+high)//2\n if count(2*mid, k) - count(mid, k) < m:\n low = mid+1\n else:\n high = mid\n return high\n\nm, k = [int(x) for x in input().split()]\nprint(solve(m, k))", "passed": true, "time": 0.28, "memory": 14376.0, "status": "done"}, {"code": "def dfs(n, k, cache = {}):\n # if number of bits is bigger than the number's bits of the number's bits is less than 0\n if k > n or k < 0: return 0\n # if num bits is 0 or num bits is equivalent to the number's bits\n if k == 0 or k == n: return 1\n # \n # if k*2 > n: k = n-k\n # Check is already calculated\n if (n, k) in cache: return cache[(n, k)]\n # Use dfs addition for case where certain bit is 1 or certain bit is 0\n z = cache[(n, k)] = dfs(n-1, k-1) + dfs(n-1, k)\n return z\n\ndef bits(n):\n b = 0\n while n:\n if n&1: b += 1\n n >>= 1\n return b\n\ndef count(n, k):\n z, b, c = 0, 63, 0\n for b in reversed(range(64)):\n # Taking n and checking if bit is 1 or not\n if (n>>b)&1:\n z += dfs(b, k-c)\n c += 1\n if not k: break\n return z + (bits(n) == k)\n\ndef solve(m, k):\n # Binary Search for number 1-10^18\n low, high = 1, 10**18\n while low < high:\n mid = (low+high)//2\n if count(2*mid, k) - count(mid, k) < m:\n low = mid+1\n else:\n high = mid\n return high\n\nm, k = [int(x) for x in input().split()]\nprint(solve(m, k))", "passed": true, "time": 0.28, "memory": 14508.0, "status": "done"}, {"code": "def dfs(n, k, cache = {}):\n # if number of bits is bigger than the number's bits of the number's bits is less than 0\n if k > n or k < 0: return 0\n # if num bits is 0 or num bits is equivalent to the number's bits\n if k == 0 or k == n: return 1\n # This optimization is not necessary but flips the 0s and the 1s\n # if k*2 > n: k = n-k\n # Check is already calculated\n if (n, k) in cache: return cache[(n, k)]\n # Use dfs addition for case where certain bit is 1 or certain bit is 0\n z = cache[(n, k)] = dfs(n-1, k-1) + dfs(n-1, k)\n return z\n\ndef bits(n):\n b = 0\n while n:\n if n&1: b += 1\n n >>= 1\n return b\n\ndef count(n, k):\n z, b, c = 0, 63, 0\n for b in reversed(range(64)):\n # Taking n and checking if certain bit is 1 or not\n # This sums for every mod power of 2 that exists to account for every case\n if (n>>b)&1:\n # calculates by subtracting for bits not accounted for\n z += dfs(b, k-c)\n c += 1\n # if not k: break\n return z + (bits(n) == k)\n\ndef solve(m, k):\n # Binary Search for number 1-10^18\n low, high = 1, 10**18\n while low < high:\n mid = (low+high)//2\n if count(2*mid, k) - count(mid, k) < m:\n low = mid+1\n else:\n high = mid\n return high\n\nm, k = [int(x) for x in input().split()]\nprint(solve(m, k))", "passed": true, "time": 0.53, "memory": 14528.0, "status": "done"}, {"code": "def dfs(n, k, cache = {}):\n # if number of bits is bigger than the number's bits of the number's bits is less than 0\n if k > n or k < 0: return 0\n # if num bits is 0 or num bits is equivalent to the number's bits\n if k == 0 or k == n: return 1\n # This optimization is not necessary but flips the 0s and the 1s\n # if k*2 > n: k = n-k\n # Check is already calculated\n if (n, k) in cache: return cache[(n, k)]\n # Use dfs addition for case where certain bit is 1 or certain bit is 0\n z = cache[(n, k)] = dfs(n-1, k-1) + dfs(n-1, k)\n return z\n\ndef bits(n):\n # counts number of 1s in the number\n b = 0\n while n:\n if n & 1: b += 1\n n >>= 1\n return b\n\ndef count(n, k):\n z, b, c = 0, 63, 0\n for b in reversed(range(64)):\n # Taking n and checking if certain bit is 1 or not\n # This sums for every mod power of 2 that exists to account for every case\n if (n>>b)&1:\n # calculates by subtracting for bits not accounted for\n z += dfs(b, k-c)\n c += 1\n # Unnecessary code\n # if not k: break\n # if original number has same number of 1s as digits required, add 1\n return z + (bits(n) == k)\n\ndef solve(m, k):\n # Binary Search for number 1-10^18\n low, high = 1, 10**18\n while low < high:\n mid = (low+high)//2\n if count(2*mid, k) - count(mid, k) < m:\n low = mid+1\n else:\n high = mid\n return high\n\nm, k = [int(x) for x in input().split()]\nprint(solve(m, k))", "passed": true, "time": 0.27, "memory": 14532.0, "status": "done"}, {"code": "from math import factorial as f\ndef C(n, m):\n if n < m: return 0\n return f(n) // ( f(n - m ) * f(m) )\n\nm, k = list(map(int, input().split()))\nans = 1\nfor bit in reversed(list(range(65))):\n if k == 0:\n break\n if C(bit, k - 1) < m:\n ans += ( 1 << bit )\n m -= C(bit, k - 1)\n k -= 1\nprint(ans)\n", "passed": true, "time": 0.19, "memory": 14508.0, "status": "done"}, {"code": "comb = [[0 for i in range(67)] for j in range(67)]\n\nfor i in range(67):\n comb[i][0], comb[i][i] = 1, 1\n for j in range(1, i):\n comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]\n\ndef calc(x):\n cnt = 0\n digit = []\n while (x > 0):\n digit.append(x % 2)\n x //= 2\n cnt += 1\n ans, one = 0, 0\n for i in reversed(list(range(cnt))):\n if (digit[i] == 1):\n if (k - one >= 0):\n ans += comb[i][k - one]\n one += 1\n return ans\n\nm, k = list(map(int, input().split()))\n\nlcur, rcur = 0, 2 ** 64\nwhile (lcur + 2 <= rcur):\n mid = (lcur + rcur) // 2\n if (calc(mid * 2) - calc(mid) < m):\n lcur = mid\n else:\n rcur = mid\n\nprint(rcur)\n\n", "passed": true, "time": 0.25, "memory": 14556.0, "status": "done"}, {"code": "MX_BIT = 64\nC = [[int(0) for i in range(MX_BIT)] for j in range(MX_BIT)]\n\ndef ck(x, i):\n\treturn (x>>i) & 1\ndef tot_bits(x):\n\tx = bin(x)[2:]\n\treturn len(x)\ndef mkt():\n\tC[0][0] = 1\n\tfor i in range (1, MX_BIT):\n\t\tfor j in range (i+1):\n\t\t\tC[i][j] = C[i-1][j] + (C[i-1][j-1] if j else 0)\ndef solve(x, k):\n\ta = 0\n\tfor i in reversed(list(range(MX_BIT))):\n\t\tif ck(x, i) != 0:\n\t\t\ta += C[i][k]\n\t\t\tk -= 1\n\t\tif k == 0:\n\t\t\tbreak\n\treturn a\nmkt()\nm, k = list(input().split())\nm = int(m)\nk = int(k)\nl = 1\nr = 1e18\nif not m:\n l = 1\nelse:\n while l < r:\n \tmid = int((l + r) // 2)\n \tif (solve(2*mid, k) - solve(mid, k)) < m :\n \t\tl = mid + 1\n \telse:\n \t\tr = mid\nprint(l)\n", "passed": true, "time": 0.24, "memory": 14568.0, "status": "done"}, {"code": "from math import factorial as f\ndef C(n, m):\n if n < m: return 0\n return f(n) // ( f(n - m ) * f(m) )\n \nm, k = map(int, input().split())\nans = 1\nfor bit in reversed(range(65)):\n if k == 0:\n break\n if C(bit, k - 1) < m:\n ans += ( 1 << bit )\n m -= C(bit, k - 1)\n k -= 1\nprint(ans)", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "\nimport math\n\nm, k = list(map(int, input().strip(' ').split(' ')))\n\n\ndef solve(x):\n ans = 0\n tot = 0\n for i in reversed(list(range(int(math.log2(x)+1)))):\n if x & (1 << i):\n ans += math.comb(i, k-tot)\n tot += 1\n if tot > k:\n return ans\n return ans\n\n\ndef judge(x):\n return solve(x*2)-solve(x) >= m\n\n\nl, r = 1, 2\nwhile not judge(r):\n l, r = r, r*2\nans = -1\nwhile l <= r:\n mid = (l+r) >> 1\n if judge(mid):\n ans, r = mid, mid-1\n else:\n l = mid+1\nprint(ans)\n", "passed": true, "time": 0.2, "memory": 14452.0, "status": "done"}]
[{"input": "1 1\n", "output": "1\n"}, {"input": "3 2\n", "output": "5\n"}, {"input": "3 3\n", "output": "7\n"}, {"input": "1 11\n", "output": "1024\n"}, {"input": "4 20\n", "output": "983040\n"}, {"input": "45902564 24\n", "output": "6406200698\n"}, {"input": "330 8\n", "output": "2033\n"}, {"input": "10 10\n", "output": "1023\n"}, {"input": "0 2\n", "output": "1\n"}, {"input": "1000000 55\n", "output": "504262282264444927\n"}, {"input": "1 60\n", "output": "576460752303423488\n"}, {"input": "1000000000 52\n", "output": "542648557841154044\n"}, {"input": "101628400788615604 30\n", "output": "999999999999995905\n"}, {"input": "101628400798615604 31\n", "output": "981546175132942729\n"}, {"input": "55 55\n", "output": "36028797018963967\n"}, {"input": "14240928 10\n", "output": "999948289\n"}, {"input": "1000000000 10\n", "output": "38209103398929\n"}, {"input": "1111111 11\n", "output": "7734675\n"}, {"input": "10000000000000000 35\n", "output": "247948501945678280\n"}, {"input": "0 19\n", "output": "1\n"}, {"input": "768 10\n", "output": "9471\n"}, {"input": "3691 6\n", "output": "39105\n"}, {"input": "16 15\n", "output": "40960\n"}, {"input": "427 4\n", "output": "18561\n"}, {"input": "669 9\n", "output": "5535\n"}, {"input": "0 16\n", "output": "1\n"}, {"input": "286 11\n", "output": "8185\n"}, {"input": "6 16\n", "output": "64512\n"}, {"input": "13111 8\n", "output": "73033\n"}, {"input": "17 2\n", "output": "65537\n"}, {"input": "440 4\n", "output": "20993\n"}, {"input": "5733 6\n", "output": "96257\n"}, {"input": "3322 6\n", "output": "34441\n"}, {"input": "333398 7\n", "output": "142974977\n"}, {"input": "19027910 20\n", "output": "530210696\n"}, {"input": "73964712 13\n", "output": "808934145\n"}, {"input": "33156624 15\n", "output": "217957249\n"}, {"input": "406 3\n", "output": "402653185\n"}, {"input": "3600 4\n", "output": "310378497\n"}, {"input": "133015087 16\n", "output": "903250260\n"}, {"input": "14065439 11\n", "output": "277820673\n"}, {"input": "135647 6\n", "output": "612761601\n"}, {"input": "613794 8\n", "output": "47611905\n"}, {"input": "79320883 13\n", "output": "877746562\n"}, {"input": "433 3\n", "output": "603979777\n"}, {"input": "142129 6\n", "output": "893386753\n"}, {"input": "20074910 16\n", "output": "156957897\n"}, {"input": "27712 4\n", "output": "54078379900534785\n"}, {"input": "109197403264830 17\n", "output": "530824147803045889\n"}, {"input": "1767 3\n", "output": "612489549322387457\n"}, {"input": "2518095982 9\n", "output": "835136255900516353\n"}, {"input": "16184825266581 15\n", "output": "753750817529397249\n"}, {"input": "60 2\n", "output": "576460752303423489\n"}, {"input": "51908921235703 16\n", "output": "927684967108968449\n"}, {"input": "373301530 8\n", "output": "628568807366983681\n"}, {"input": "51140330728306 16\n", "output": "880672956240363521\n"}, {"input": "78015012688021 17\n", "output": "237668409087623169\n"}, {"input": "360651917262546 18\n", "output": "866841191969193985\n"}, {"input": "15619605006173 15\n", "output": "676897611185127425\n"}, {"input": "296851618 8\n", "output": "208581753835618305\n"}, {"input": "1651507249349341 20\n", "output": "660934198681731073\n"}, {"input": "234217752433205 18\n", "output": "333773758789582849\n"}, {"input": "5004844 6\n", "output": "488640559569698817\n"}, {"input": "820882585293 13\n", "output": "167167411424854017\n"}, {"input": "0 64\n", "output": "1\n"}]
262
ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n Γ— n magic grid on the entrance which is filled with integers. Chris noticed that exactly one of the cells in the grid is empty, and to enter Udayland, they need to fill a positive integer into the empty cell. Chris tried filling in random numbers but it didn't work. ZS the Coder realizes that they need to fill in a positive integer such that the numbers in the grid form a magic square. This means that he has to fill in a positive integer so that the sum of the numbers in each row of the grid ($\sum a_{r, i}$), each column of the grid ($\sum a_{i, c}$), and the two long diagonals of the grid (the main diagonalΒ β€” $\sum a_{i, i}$ and the secondary diagonalΒ β€” $\sum a_{i, n - i + 1}$) are equal. Chris doesn't know what number to fill in. Can you help Chris find the correct positive integer to fill in or determine that it is impossible? -----Input----- The first line of the input contains a single integer n (1 ≀ n ≀ 500)Β β€” the number of rows and columns of the magic grid. n lines follow, each of them contains n integers. The j-th number in the i-th of them denotes a_{i}, j (1 ≀ a_{i}, j ≀ 10^9 or a_{i}, j = 0), the number in the i-th row and j-th column of the magic grid. If the corresponding cell is empty, a_{i}, j will be equal to 0. Otherwise, a_{i}, j is positive. It is guaranteed that there is exactly one pair of integers i, j (1 ≀ i, j ≀ n) such that a_{i}, j = 0. -----Output----- Output a single integer, the positive integer x (1 ≀ x ≀ 10^18) that should be filled in the empty cell so that the whole grid becomes a magic square. If such positive integer x does not exist, output - 1 instead. If there are multiple solutions, you may print any of them. -----Examples----- Input 3 4 0 2 3 5 7 8 1 6 Output 9 Input 4 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 Output 1 Input 4 1 1 1 1 1 1 0 1 1 1 2 1 1 1 1 1 Output -1 -----Note----- In the first sample case, we can fill in 9 into the empty cell to make the resulting grid a magic square. Indeed, The sum of numbers in each row is: 4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15. The sum of numbers in each column is: 4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15. The sum of numbers in the two diagonals is: 4 + 5 + 6 = 2 + 5 + 8 = 15. In the third sample case, it is impossible to fill a number in the empty square such that the resulting grid is a magic square.
interview
[{"code": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\ndef func():\n N = int(input())\n cells = [0] * N\n\n if N == 1:\n return 1\n\n mx = 0\n for n in range(N):\n cells[n] = list(map(int,input().split()))\n mx = max(mx, sum(cells[n]))\n\n ans = None\n for j in range(N):\n for i in range(N):\n if cells[j][i] == 0:\n ans = mx - sum(cells[j])\n cells[j][i] = ans\n if ans <= 0:\n return -1\n\n # validation\n for j in range(N):\n if sum(cells[j]) != mx:\n return -1\n for i in range(N):\n if mx != sum([cells[j][i] for j in range(N)]):\n return -1\n if mx != sum([cells[j][j] for j in range(N)]):\n return -1\n if mx != sum([cells[j][N-1-j] for j in range(N)]):\n return -1\n \n return ans\n\nprint(func())\n\n", "passed": true, "time": 0.15, "memory": 14492.0, "status": "done"}, {"code": "n = int(input())\ns = -1\ns1 = -1\nx = -1\ny = -1\nmat = []\nif n == 1:\n input()\n print(1)\n return\nfor i in range(n):\n arr = list(map(int, input().split()))\n if s == -1 and 0 not in arr:\n s = sum(arr)\n if 0 in arr:\n x = i\n s1 = sum(arr)\n y = arr.index(0)\n mat.append(arr)\nmat[x][y] = s - s1\nif mat[x][y] <= 0:\n print(-1)\n return\nfor i in range(n):\n if sum(mat[i]) != s:\n print(-1)\n return\n s2 = 0\n for j in range(n):\n s2 += mat[j][i]\n if s2 != s:\n print(-1)\n return\ns2 = 0\ns3 = 0\nfor i in range(n):\n s2 += mat[i][i]\n s3 += mat[i][n-i-1]\nif s2 != s or s3 != s:\n print(-1)\n return\nprint(mat[x][y])", "passed": true, "time": 0.15, "memory": 14536.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nn = int(input())\ns = [[int(x) for x in input().split()] for _ in range(n)]\n\np, q = 0, 0\n\nfor i in range(n):\n for j in range(n):\n if s[i][j] == 0:\n p, q = i, j\n\nif n > 1:\n m = sum(s[(p+1)%n])\n s[p][q] = m - sum(s[p])\nelse:\n m = 1\n s[p][q] = 1\n\nf = True\n\nfor i in range(n):\n if sum(s[i]) != m:\n f = False\n if sum(s[j][i] for j in range(n)) != m:\n f = False\n \nif sum(s[i][i] for i in range(n)) != m:\n f = False\nif sum(s[i][n-i-1] for i in range(n)) != m:\n f = False\n\nif f and s[p][q] > 0:\n print(s[p][q])\nelse:\n print(\"-1\")\n", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "n = int(input())\ngrid = [[int(x) for x in input().split()] for _ in range(n)]\n\nif n == 1:\n\tprint(1)\n\treturn\n\nsm = sum(grid[1]) if 0 in grid[0] else sum(grid[0])\n\nanswer = -1\nfor i, line in enumerate(grid):\n\tif 0 in line:\n\t\tj = line.index(0)\n\t\tanswer = sm - sum(line)\n\t\tgrid[i][j] = answer\n\t\tbreak\n\n\nfor line in grid:\n\tif sum(line) != sum(grid[0]):\n\t\tprint(-1)\n\t\treturn\n\nfor i in range(n):\n\trow_count = 0\n\tfor j in range(n):\n\t\trow_count += grid[j][i]\n\n\tif row_count != sum(grid[0]):\n\t\tprint(-1)\n\t\treturn\n\ncount = 0\nfor i in range(n):\n\tcount += grid[i][i]\n\nif count != sum(grid[0]):\n\tprint(-1)\n\treturn\n\ncount = 0\nfor i in range(n):\n\tcount += grid[n-1-i][i]\n\nif count != sum(grid[0]):\n\tprint(-1)\n\treturn\n\nprint(answer if answer > 0 else -1)\n", "passed": true, "time": 0.16, "memory": 14580.0, "status": "done"}, {"code": "N = int(input())\nif N == 1:\n print(1)\n return\nmat = []\nfor i in range(N):\n mat.append(list(map(int, input().split())))\n if 0 in mat[i]:\n zero_pos = (i, mat[i].index(0))\n\n# \u548c\u3092\u6c42\u3081\u3066\u304a\u304f\nif zero_pos[0] == 0:\n v_sum = sum(mat[1])\nelse:\n v_sum = sum(mat[0])\n\n# \u548c\u304b\u30890\u3092\u57cb\u3081\u308b\nzero_row_sum = sum(mat[zero_pos[0]])\nif v_sum - zero_row_sum <= 0:\n print(-1)\n return\nmat[zero_pos[0]][zero_pos[1]] = v_sum - zero_row_sum\n\n# row check\nfor i in range(N):\n row_sum = sum(mat[i])\n if row_sum != v_sum:\n print(-1)\n return\n\n# col check\nfor j in range(N):\n col_sum = sum([mat[i][j] for i in range(N)])\n if col_sum != v_sum:\n print(-1)\n return\n\n# diag check\ndiag_sum = sum([mat[i][i] for i in range(N)])\nif diag_sum != v_sum:\n print(-1)\n return\n\n# inv diag check\ninv_diag_sum = sum([mat[i][N - i - 1] for i in range(N)])\nif inv_diag_sum != v_sum:\n print(-1)\n return\n\nprint(mat[zero_pos[0]][zero_pos[1]])\n", "passed": true, "time": 0.16, "memory": 14592.0, "status": "done"}, {"code": "n = int(input())\n\ngrid = []\n\nfor i in range(n):\n grid.append(list(map(int, input().split())))\n\nif n == 1:\n print(1)\n return\n\nchecksum = -1;\n\nleft = 0\nmis = -1;\nfor i, col in enumerate(grid):\n tmp = sum(col)\n if 0 in col:\n left = i\n mis = tmp\n else:\n if checksum == -1:\n checksum = tmp\n elif checksum != tmp:\n print(-1)\n return\n\nif mis >= checksum:\n print(-1)\n return\n\ngrid[left] = [x if x else checksum - mis for x in grid[left]]\n\ndiag1 = 0\ndiag2 = 0\nfor i in range(n):\n colsum = 0\n rowsum = 0\n diag1 += grid[i][i]\n diag2 += grid[n-1-i][i]\n for j in range(n):\n colsum += grid[i][j]\n rowsum += grid[j][i]\n\n if colsum != checksum or rowsum != checksum:\n print(-1)\n return\n\nif diag1 != checksum or diag2 != checksum:\n print(-1)\n return\n\nprint(checksum - mis)\n", "passed": true, "time": 0.15, "memory": 14616.0, "status": "done"}, {"code": "n = int(input()) \nif n == 1:\n\tprint('1')\n\treturn\nA = []\nC = [0 for i in range(n)]\ndiag1 = 0\ndiag2 = 0\nfor i in range(n):\n\tB = list(map(int, input().split()))\n\tfor j in range(n):\n\t\tel = B[j]\n\t\tC[j] += el\n\t\tif i == j:\n\t\t\tdiag1 += el\n\t\tif i + j == n - 1:\n\t\t\tdiag2 += el\t\n\t\tif el == 0:\n\t\t\tx = i\n\t\t\ty = j\n\tA.append(B)\nif x == 0:\n\ts = sum(A[1])\nelse:\n\ts = sum(A[0])\t\nfor i in range(n):\n\tif i != x:\n\t\tif s != sum(A[i]):\n\t\t\tprint('-1')\n\t\t\treturn\nfor i in range(n):\n\tif i != y:\n\t\tif s != C[i]:\n\t\t\tprint('-1')\n\t\t\treturn\nans = s - C[y]\nif ans + sum(A[x]) != s:\n\tprint('-1')\n\treturn\nif x == y:\n\tdiag1 += ans\nif x + y == n - 1:\n\tdiag2 += ans\nif diag1 != s:\n\tprint('-1')\n\treturn\nif diag2 != s:\n\tprint('-1')\n\treturn\t\t\t\t\t\t\t\nif ans < 1:\n\tprint('-1')\n\treturn\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14428.0, "status": "done"}, {"code": "n = int(input())\nline = []\nfor i in range(n):\n line += [list(map(int, input().split()))]\nlist_str = []\nif line == [[0]]:\n print(1)\nelse: \n for i in range(n):\n plus = False\n answer = 0\n for j in range(n):\n element = line[i][j]\n if element == 0:\n plus = True\n answer += element\n if plus:\n osob = answer\n else:\n list_str += [answer]\n if len(list_str) != 0 and min(list_str) != max(list_str):\n print(-1)\n else:\n chislo1 = min(list_str) - osob\n s1 = min(list_str) \n list_str = [] \n for i in range(n):\n plus = False\n answer = 0\n for j in range(n):\n element = line[j][i]\n if element == 0:\n plus = True\n answer += element\n if plus:\n osob = answer\n else:\n list_str += [answer]\n if len(list_str) == 0 or min(list_str) != max(list_str):\n print(-1)\n else:\n chislo2 = min(list_str) - osob\n s2 = min(list_str) \n answer = 0\n plus = False\n for i in range(n):\n element = line[i][i]\n answer += element\n if element == 0:\n plus = True\n if not plus:\n s3 = answer\n chislo3 = chislo2\n else: \n s3 = s2\n chislo3 = s2 - answer\n answer = 0\n plus = False\n for i in range(n):\n element = line[i][n - i - 1]\n answer += element\n if element == 0:\n plus = True\n if not plus:\n s4 = answer\n chislo4 = chislo2\n else: \n chislo4 = s2 - answer \n s4 = s2 \n if s1 == s2 and s1 == s3 and s1 == s4 and chislo1 == chislo2 and chislo1 == chislo3 and chislo1 == chislo4 and s1 > 0 and chislo1 > 0:\n print(chislo1)\n else:\n print(-1)\n", "passed": true, "time": 0.16, "memory": 14452.0, "status": "done"}, {"code": "n = int(input())\narr = []\nfor i in range(n):\n arr.append([int(x) for x in input().split()])\nif(n==1):\n print(1)\n return\n\nii,jj = 0,0\nfor i in range(n):\n for j in range(n):\n if(arr[i][j]==0):\n ii,jj = i,j\n\nprr = []\nqrr = []\nfor i in range(n):\n if(i==ii):\n qrr.append(sum(arr[i]))\n else:\n prr.append(sum(arr[i]))\nfor j in range(n):\n s = 0\n for i in range(n):\n s += arr[i][j]\n if(j==jj):\n qrr.append(s)\n else:\n prr.append(s)\ns = 0\nfor i in range(n):\n s += arr[i][i]\nif(ii==jj):\n qrr.append(s)\nelse:\n prr.append(s)\ns = 0\nfor i in range(n):\n s += arr[i][n-i-1]\nif(ii+jj==n-1):\n qrr.append(s)\nelse:\n prr.append(s)\n\nif(len(prr)==prr.count(prr[0]))and(len(qrr)==qrr.count(qrr[0])):\n x = prr[0]-qrr[0]\n if(x>0):\n print(x)\n else:\n print(-1)\nelse:\n print(-1)", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "n = int(input())\nk = []\nfor i in range(n):\n\ta = [int(i) for i in input().split()]\n\tk.append(a)\nif n == 1:\n\tprint(1)\nelse:\n\tzer = []\n\tfor i in range(n):\n\t\tfor j in range(n):\n\t\t\tif 0 == k[i][j]:\n\t\t\t\tzer = [i, j]\n\tif zer[0] == 0:\n\t\tm = sum(k[1])\n\telse:\n\t\tm = sum(k[0])\n\tk[zer[0]][zer[1]] = m-sum(k[zer[0]])\n\tif k[zer[0]][zer[1]] > 0:\n\t\ty = 1\n\telse:\n\t\ty = 0\n\tfor i in range(n):\n\t\tif sum(k[i]) != m:\n\t\t\ty = 0\n\tfor j in range(n):\n\t\tu = 0\n\t\tfor i in range(n):\n\t\t\tu+= k[i][j]\n\t\tif u!= m:\n\t\t\ty = 0\n\tu = 0\n\tfor i in range(n):\n\t\tu+=k[i][i]\n\tif u!= m:\n\t\ty = 0\n\tu = 0\n\tfor i in range(n):\n\t\tu+=k[i][n-i-1]\n\tif u!= m:\n\t\ty = 0\n\tif y == 1:\n\t\tprint(k[zer[0]][zer[1]])\n\telse:\n\t\tprint(-1)\n", "passed": true, "time": 0.15, "memory": 14484.0, "status": "done"}, {"code": "def main():\n def magic(sq, n):\n s1 = sum(sq[0])\n for i in range(1, n):\n if s1 != sum(sq[i]):\n return False\n s2 = 0\n for i in range(n):\n s2 += sq[i][i]\n if s2 != s1:\n return False\n s2 = 0\n for i in range(n):\n s2 += sq[i][n - i - 1]\n if s2 != s1:\n return False\n for i in range(n):\n s2 = 0\n for j in range(n):\n s2 += sq[j][i]\n if s2 != s1:\n return False\n return True\n n = int(input())\n sq = [list(map(int, input().split())) for i in range(n)] + [[1]]\n for i in range(n):\n if 0 in sq[i]:\n cors = (i, sq[i].index(0))\n if cors[0] != 0:\n s = sum(sq[0])\n else:\n s = sum(sq[1])\n sq[cors[0]][cors[1]] = s - sum(sq[cors[0]])\n if magic(sq, n) and sq[cors[0]][cors[1]] >= 1:\n print(sq[cors[0]][cors[1]])\n else:\n print(-1)\n\nmain()", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}, {"code": "#B\nn = int(input())\na = [list(map(int,input().split())) for j in range(n)]\n\nif n == 1:\n print(1)\n return\n\nfor j in range(n):\n for i in range(n):\n if a[j][i] == 0:\n y = j\n x = i\n break\n\nslist = []\nfor j in range(n):\n if j == y:\n continue\n ss = 0\n for i in range(n):\n ss += a[j][i]\n slist.append(ss)\n\nfor i in range(n):\n if i == x:\n continue\n ss = 0\n for j in range(n):\n ss += a[j][i]\n slist.append(ss)\n\nif x != y:\n ss = 0\n for i in range(n):\n ss += a[i][i]\n slist.append(ss)\n\nif x != n - 1 - y:\n ss = 0\n for i in range(n):\n ss += a[n - 1 - i][i]\n slist.append(ss)\n\nslist.sort()\n\nif slist[0] != slist[-1]:\n print(-1)\n return\n\ns = slist[0]\ns1 = s\ns2 = s\ns3 = s\ns4 = s\n\nfor i in range(n):\n s1 -= a[y][i]\n\nfor i in range(n):\n s2 -= a[i][x]\n\nif x == y:\n for i in range(n):\n s3 -= a[i][i]\nelse:\n s3 = s1\n\nif x == n - 1 - y:\n for i in range(n):\n s4 -= a[n - 1 - i][i]\nelse:\n s4 = s1\n\nif s1 == s2 == s3 == s4 and s1 > 0:\n print(s1)\nelse:\n print(-1)", "passed": true, "time": 0.15, "memory": 14428.0, "status": "done"}, {"code": "#!/usr/bin/env pypy3\n\nNO_SOL = -1\n\n\ndef main():\n n = int(input())\n if n == 1:\n print(1)\n return\n zero = None\n grid = []\n for i in range(n):\n grid.append(list(map(int, input().split())))\n if zero is None:\n try:\n zero = (i, grid[i].index(0))\n except Exception:\n zero = None\n sum_sample = None\n for i in range(n):\n if i == zero[0]:\n continue\n else:\n sum_sample = sum(grid[i])\n break\n zero_cand = sum_sample - sum(grid[zero[0]])\n if zero_cand <= 0:\n print(NO_SOL)\n return\n grid[zero[0]][zero[1]] = zero_cand\n for row in grid:\n if sum(row) != sum_sample:\n print(NO_SOL)\n return\n for column in zip(*grid):\n if sum(column) != sum_sample:\n print(NO_SOL)\n return\n if sum(grid[i][i] for i in range(n)) != sum_sample:\n print(NO_SOL)\n return\n if sum(grid[i][n - i - 1] for i in range(n)) != sum_sample:\n print(NO_SOL)\n return\n print(zero_cand)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14608.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\ndef check(a, t):\n n = len(a)\n for i in range(n):\n if sum(a[i]) != t:\n return False\n for j in range(n):\n if sum(a[i][j] for i in range(n)) != t:\n return False\n return sum(a[i][i] for i in range(n)) == sum(a[i][-i - 1] for i in range(n)) == t\n\ndef main():\n try:\n while True:\n n = int(input())\n a = [list(map(int, input().split())) for i in range(n)]\n if n == 1:\n print(1)\n else:\n try:\n j = a[0].index(0)\n i = 0\n t = sum(a[1])\n x = t - sum(a[0])\n except ValueError:\n t = sum(a[0])\n for i in range(1, n):\n try:\n j = a[i].index(0)\n x = t - sum(a[i])\n break\n except ValueError:\n pass\n a[i][j] = x\n print(x if x > 0 and check(a, t) else -1)\n\n except EOFError:\n pass\n\nmain()\n", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "from sys import stdin\n\nn=int(stdin.readline())\ncarre=[list(map(int,stdin.readline().split())) for i in range(n)]\nsommesCol=[0]*n\nsommesLig=[0]*n\nif n==1:\n print(1)\n return\n \nfor lig in range(n):\n for col in range(n):\n if carre[lig][col]==0:\n ligManque=lig\n colManque=col\n else:\n sommesCol[col]+=carre[lig][col]\n sommesLig[lig]+=carre[lig][col]\n\nsommeDiagonale=0\nsommeDiagonaleInv=0\nfor i in range(n):\n sommeDiagonale+=carre[i][i]\n sommeDiagonaleInv+=carre[i][n-i-1]\nreference=sommesCol[(colManque+1)%n]\nremplacement=reference-sommesCol[colManque]\n\nsommesCol[colManque]+=remplacement\nsommesLig[ligManque]+=remplacement\nif ligManque==colManque:\n sommeDiagonale+=remplacement\nif ligManque==n-colManque-1:\n sommeDiagonaleInv+=remplacement\n\npossible=True\nif sommeDiagonale!=reference:\n possible=False\nif sommeDiagonaleInv!=reference:\n possible=False\nfor col in range(n):\n if sommesCol[col]!=reference:\n possible=False\nfor lig in range(n):\n if sommesLig[lig]!=reference:\n possible=False\n\nif not possible or remplacement<=0:\n print(-1)\nelse:\n print(remplacement)\n", "passed": true, "time": 0.25, "memory": 14404.0, "status": "done"}, {"code": "\nn = int(input())\n\nv = [list(map(int, input().split())) for _ in range(n)]\n\nif n == 1:\n print(1)\n return\n\ndef sum_diag1(v):\n s = 0\n for i in range(len(v)):\n s += v[i][i]\n return s\n\ndef sum_diag2(v):\n s = 0\n for i in range(len(v)):\n s += v[i][len(v) - 1 - i]\n return s\n\ndef sum_row(v, r):\n return sum(v[r])\n\ndef sum_col(v, c):\n s = 0\n for r in range(len(v)):\n s += v[r][c]\n return s\n\nrow = 0\ncol = 0\n\nneeded_sum = 0\nrow_sum = 0\ncol_sum = 0\ndiag1_sum = 0\ndiag2_sum = 0\n\nfor r in range(len(v)):\n if 0 in v[r]:\n row = r\n col = v[r].index(0)\n if needed_sum != 0:\n break\n elif needed_sum == 0:\n needed_sum = sum(v[r])\n\nt = needed_sum - sum(v[row])\nv[row][col] = t\n\nl = [sum_row(v, r) for r in range(n)]\nl += [sum_col(v, c) for c in range(n)]\nl += [sum_diag1(v), sum_diag2(v)]\n\nif len(set(l)) == 1 and t > 0:\n print(t)\nelse:\n print(-1)\n \n \n", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}, {"code": "n=int(input())\nrs=[]\ncs=[0 for i in range(n)]\nd1=0\nd2=0\nfor i in range(n):\n ip=list(map(int,input().split()))\n rs.append(sum(ip))\n if 0 in ip:\n l=i\n k=ip.index(0)\n for j in range(n):\n cs[j]+=ip[j]\n d1+=ip[i]\n d2+=ip[n-i-1]\nif n==1:\n print(1)\nelse:\n if l==0:\n r=rs[1]\n else:\n r=rs[0]\n ans=r-rs[l]\n if l==k:\n d1+=ans\n if l==n-k-1:\n d2+=ans\n rc=0\n cc=0\n for i in rs:\n if i!=r:\n rc+=1\n for i in cs:\n if i!=r:\n cc+=1\n if rc!=1 or cc!=1:\n print(-1)\n elif d1!=r or d2!=r:\n print(-1)\n elif ans<=0:\n print(-1)\n else:\n print(ans)\n\n", "passed": true, "time": 0.14, "memory": 14544.0, "status": "done"}, {"code": "lines = int(input())\nif lines == 1:\n print(1)\n return\ngrid = []\nnumber_with_zero = set()\nimpossible = False\nno_zero = -1\n\nfor x in range(lines):\n num = list(map(int, input().split()))\n grid.append(num)\n\nfor line in grid:\n have_zero = False\n s = 0\n for n in line:\n if n ==0:\n have_zero = True\n else:\n s += n\n if have_zero:\n number_with_zero.add(s)\n elif no_zero == -1:\n no_zero = s\n elif no_zero != s:\n impossible = True\n\n# print(impossible, 1)\nfor x in range(lines):\n have_zero = False\n s = 0\n for y in range(lines):\n n = grid[y][x]\n if n ==0:\n have_zero = True\n else:\n s += n\n if have_zero:\n number_with_zero.add(s)\n elif no_zero == -1:\n no_zero = s\n elif no_zero != s:\n impossible = True\n# print(impossible, 2)\n\ns = 0\nhave_zero = False\nfor x in range(lines):\n n = grid[x][x]\n if n ==0:\n have_zero = True\n else:\n s += n\n\n# print(s, no_zero)\nif have_zero:\n number_with_zero.add(s)\nelif no_zero == -1:\n no_zero = s\nelif no_zero != s:\n impossible = True\n# print(impossible, 3)\n\ns = 0\nhave_zero = False\nfor x in range(lines):\n n = grid[x][lines -1 - x]\n if n ==0:\n have_zero = True\n else:\n s += n\n\nif have_zero:\n # print(\"COME\")\n number_with_zero.add(s)\nelif no_zero == -1:\n no_zero = s\nelif no_zero != s:\n impossible = True\n# print(impossible, 4)\n\nif impossible:\n print(-1)\nelse:\n if len(number_with_zero) == 1:\n num = list(number_with_zero)[0]\n # print(num)\n if (no_zero - num <= 0):\n print(-1)\n else:\n print(no_zero - num)\n else:\n print(-1)\n", "passed": true, "time": 0.15, "memory": 14448.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 n = int(input())\n s = [list(map(int, input().split())) for i in range(n)]\n if n == 1:\n print(1)\n return\n pos = []\n for i in range(n):\n for j in range(n):\n if s[i][j] == 0:\n pos = [i, j]\n break;\n val = sum(s[(pos[0] + 1) % n])\n s[pos[0]][pos[1]] = max(val - sum(s[pos[0]]), 1)\n #check\n for i in range(n):\n if sum(s[i]) != val:\n print(-1)\n return\n for j in range(n):\n t = 0\n for i in range(n):\n t += s[i][j]\n if t != val:\n print(-1)\n return\n t, tt = 0, 0\n for i in range(n):\n t += s[i][i]\n tt += s[i][n - 1 - i]\n if t != val or tt != val:\n print(-1)\n return\n \n print(s[pos[0]][pos[1]])\n '''\n for i in range(n):\n print(' '.join(map(str, s[i])))\n '''\n__starting_point()", "passed": true, "time": 0.14, "memory": 14636.0, "status": "done"}, {"code": "import sys\nn = int(input())\nmat = []\nempty = (None, None)\nif n == 1:\n print(1)\n return\nfor i in range(n):\n row = [int(x) for x in input().strip().split()]\n if 0 in row:\n col = row.index(0)\n empty = (i, col)\n mat.append(row)\ni = 0\nif 0 in mat[i]:\n i += 1\nrowsum = sum(mat[i])\nrow = empty[0]\nfor i in range(n):\n if i == row:\n continue\n cursum = sum(mat[i])\n # print(cursum)\n if cursum != rowsum:\n print(-1)\n return\ntmat = list(zip(*mat))\ncol = empty[1]\nfor i in range(n):\n if i == col:\n continue\n else:\n #print(cursum)\n cursum = sum(tmat[i])\n if cursum != rowsum:\n print(-1)\n return\nrow = empty[0]\nirowsum = sum(mat[row])\ncolsum = sum(tmat[col])\n#print(irowsum, colsum)\nif irowsum != colsum:\n print(-1)\n return\nleft = 0\nright = 0\ntochange = rowsum - irowsum\nif tochange <= 0:\n print(-1)\n return\nmat[row][col] = tochange\nif True:\n for i in range(n):\n #print(mat[i][i], mat[i][n - i - 1])\n left += mat[i][i]\n right += mat[i][n - i - 1]\n #print(left, right)\n #print(row, col, left, rowsum)\nif left != right or left != rowsum:\n print(-1)\n return\nprint(tochange)\n", "passed": true, "time": 0.15, "memory": 14564.0, "status": "done"}, {"code": "#imports\nimport sys\nsys.setrecursionlimit(30000)\n\nfrom collections import Counter, defaultdict, deque\nfrom math import ceil, floor, factorial, fsum, isinf, exp, log, log10, log2, isfinite, sqrt\nfrom math import pi as PI, e as E\nfrom math import sin, cos, tan, sinh, cosh, tanh, asin, acos, atan\nfrom fractions import Fraction\nfrom itertools import starmap, tee, chain, filterfalse, combinations as combos\nfrom itertools import permutations as perms, product as prod, combinations_with_replacement as rcombos\nfrom functools import reduce, partial\nimport operator as ops #lt, le, eq, ne, ge, gt, xor notit, lshift, rshift, neg, add, mul, sub,\nfrom operator import __not__ as notit, __abs__ as absit, __or__ as orit\nfrom bisect import insort_left, bisect_left, bisect_right\nfrom copy import deepcopy\n\n\n#PI, E, PHI, INF\nPHI, PHI2 = (1 + 5 ** 0.5) / 2, (5 ** 0.5 - 1) / 2\nINF = float('inf')\n\n#structures\nclass TreeNode:\n def __init__(self, v):\n self.val = v\n self.left = None\n self.right = None\n\n#Bit Manipulation\n#<<, >>, bin(), int(s, 2)\ndef setBit(x, offset):\n return x | 1 << offset #RHS: mask\ndef clearBit(x, offset):\n return x & ~(1 << offset) #RHS: mask\ndef getBit(x, offset):\n return 1 if testBit(x, offset) > 0 else 0\ndef testBit(x, offset):\n return x & 1 << offset #RHS: mask\ndef flipBitAt(x, offset):\n return x ^ 1 << offset #RHS: mask\ndef flipBits(x, length=-1): #default: x.bit_length() - 1\n length = x.bit_length()-1 if length == -1 else length\n return x ^ (1 << length) - 1\ndef numBits(x):\n return x.bit_length() #int.bit_length()\ndef countOnes(x):\n return bin(x).count('1')\ndef countZeros(x, length=-1):\n length = x.bit_length() if length == -1 else length\n return length - countOnes(x)\n\n#IO\ndef getList(tcast=str):\n return [tcast(x) for x in input().strip().split(' ')]\ndef getItems(*tcast):\n return list(map(lambda f, x: f(x), tcast, getList()))\ndef getVal(tcast=str):\n return tcast(input().strip())\ndef getMatrix(r, tcast=str):\n return [getList(tcast) for row in range(r)]\n\n#Math\ndef isOdd(n):\n return n & 1 > 0\ndef isEven(n):\n return not n & 1\ndef numDigits(n):\n return len(str(n)) - (1 if n < 0 else 0)\ndef _gcd(a, b):\n while b: #is not zero\n a, b = b, a % b\n return a\ndef gcd(*xs):\n nums = xs[0] if type(xs[0]) == list else list(xs)\n cur = nums[0]\n for n in nums[1:]:\n if cur == 1:\n return cur\n cur = _gcd(cur, n)\n return cur\ndef _lcm(a, b):\n return (a // gcd(a, b)) * b\ndef lcm(*xs):\n nums = xs[0] if type(xs[0]) == list else list(xs)\n cur = nums[0]\n for n in nums[1:]:\n cur = _lcm(cur, n)\n return cur\ndef primesUpto(n):\n isp = [True] * (n + 1)\n isp[0], isp[1] = False, False\n primes = []\n for i, x in enumerate(isp): #for each number\n if x: #found a prime\n primes.append(i)\n mults = i * i\n while mults <= n:\n isp[mults] = False\n mults += i\n return primes\ndef primeFactor(n): #without a sieve\n factors = Counter()\n while not n&1:\n factors[2] += 1\n n >>= 1\n trynum = 3\n while trynum <= ceil(sqrt(n)): #just in case\n while n % trynum == 0:\n factors[trynum] += 1\n n //= trynum\n trynum += 2\n if n != 1:\n factors[n] += 1\n return factors\ndef isPrime(n): #num -> boolean\n if n&1 and n >= 2:\n trynum = 3\n limit = ceil(sqrt(n))\n while trynum < limit:\n if n % trynum == 0:\n return False\n trynum += 2\n else:\n return True\n else:\n return False\ndef nthFib(n):\n if n <= 2:\n return 1\n else:\n a, b = 1, 1\n while n > 2:\n a, b = b, a + b\n n -= 1\n return b\n\n#Iteration\ndef zipNWith(f, *x): #xs, ys, ... zs -> elementwise f -> os #return map(lambda *y: f(y), x) #list way: [f(y) for y in zip(*xs)]\n return (f(y) for y in zip(*x))\ndef zipWith(f, xs, ys):\n return (f(x, y) for x, y in zip(xs, ys))\ndef flatten(xs):\n return reduce(ops.concat, xs)\ndef quantify(pred, it):\n return sum(map(pred, it))\ndef dotproduct(xs, ys):\n return sum(map(ops.mul, xs, ys))\ndef adjpairs(it):\n a, b = tee(it)\n next(b, None)\n return list(zip(a, b))\ndef bipartition(pred, it):\n t, f = tee(it)\n return list(filter(pred, t)), filterfalse(pred, f)\ndef powerset(it):\n s = list(it)\n return chain.from_iterable(combos(s, r) for r in range(len(s) + 1))\ndef depProduct(bounds, f=lambda y:y+1, g=lambda *x:tuple(x)):\n args = [-1]\n nbounds = len(bounds)\n while args:\n n = len(args)\n args[-1] += 1\n if args[-1] >= bounds[n-1]:\n args.pop()\n elif n == nbounds:\n yield g(*args)\n else:\n _f = f[n] if type(f) == list else f\n args.append(_f(args[-1]) - 1)\ndef revEnumerate(xs):\n n = len(xs) - 1\n for i, x in enumerate(reversed(xs)):\n yield (n - i, x)\n'''\ndef shiftchar(c, offset):\n return c +\n'''\n\n\n\n\n\n\n\n#print(sys.getsizeof())\n\n\n#Input\n\n#Body\n\n#Output\n#n, m, a = getList(int)\n#print(ceil(m/a) * ceil(n/a))\nnrows = getVal(int)\nmat = getMatrix(nrows, int)\n\nif nrows == 1:\n print(1)\nelse:\n #locate\n for i, r in enumerate(mat):\n for j, c in enumerate(r):\n if c == 0:\n wantx, wanty = i, j\n assert mat[wantx][wanty] == 0\n example = 0 if wantx > 0 else 1\n target = sum(mat[example])\n #print(target)\n mystery = target - sum(mat[wantx])\n #print(mystery)\n mat[wantx][wanty] = mystery\n #perf cehcks\n\n def check(ri, ci, dr, dc):\n nonlocal nrows, mat\n r, c = ri, ci\n total = 0\n for t in range(nrows):\n total += mat[r][c]\n r, c = r + dr, c + dc\n\n return total\n vert, hor = (1, 0), (0, 1)\n diag1 = (1, 1)\n diag2 = (1, -1)\n for i in range(nrows):\n if check(i, 0, *hor) != target or check(0, i, *vert) != target:\n print(-1)\n break\n else:\n if check(0, 0, *diag1) == target and check(0, nrows - 1, *diag2) == target:\n print(mystery if mystery > 0 else -1)\n else:\n print(-1)\n #print('row', i, check(i, 0, *hor))\n #print('col', i, check(0, i, *vert))\n", "passed": true, "time": 0.16, "memory": 15436.0, "status": "done"}, {"code": "\ndef main():\n n = int(input())\n matrix = []\n s = None\n found = False\n col = 0\n row = 0\n if n == 1:\n i = input()\n return 1\n for i in range(n):\n line = [int(k) for k in input().split(' ')]\n matrix.append(line)\n if not found:\n try:\n index = line.index(0)\n row = i\n col = index\n continue\n except ValueError:\n pass\n\n if s is None:\n s = sum(line)\n else:\n if s != sum(line):\n return -1\n\n\n res = s - sum(matrix[row])\n if res < 1:\n return -1\n else:\n matrix[row][col] = res\n\n for i in range(n):\n t = 0\n for j in range(n):\n t += matrix[j][i]\n if t != s:\n return -1\n d1 = 0\n d2 = 0\n for i in range(n):\n d1 += matrix[i][i]\n d2 += matrix[i][n-1-i]\n if d1 != s or d2 != s:\n return -1\n\n return res\n\n\ndef __starting_point():\n print(main())\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14528.0, "status": "done"}, {"code": "n = int(input())\narr = []\nnullRow = nullCol = 0\nfor i in range(n):\n arr.append(list())\n for j, x in enumerate(list(map(int, input().split()))):\n arr[i].append(x)\n if x == 0:\n nullRow = i\n nullCol = j\narrT = list(zip(*arr))\nsumRow = sum(arr[0 if nullRow != 0 or n == 1 else 1])\nsumCol = sum(arrT[0 if nullCol != 0 or n == 1 else 1])\nguessByRow = 0\nguessByCol = 0\nsolvable = True\nfor i in range(n):\n currSum = sum(arr[i])\n if i == nullRow:\n guessByRow = sumRow - currSum \n elif currSum != sumRow:\n solvable = False\nfor j in range(n):\n currSum = sum(arrT[j])\n if j == nullCol:\n guessByCol = sumCol - currSum \n elif currSum != sumCol:\n solvable = False\nif guessByRow != guessByCol or sumRow != sumCol:\n solvable = False\nif solvable:\n arr[nullRow][nullCol] = guessByRow\nsumDiagLeft = sumDiagRight = 0\nfor i in range(n):\n sumDiagRight += arr[i][n - i - 1]\n sumDiagLeft += arr[i][i]\nif sumDiagLeft != sumDiagRight or sumRow != sumDiagLeft:\n solvable = False\nif n == 1:\n print(1)\nelif solvable and guessByRow > 0:\n print(guessByRow)\nelse:\n print(-1)", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}]
[{"input": "3\n4 0 2\n3 5 7\n8 1 6\n", "output": "9\n"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 1 1\n1 1 1 1\n", "output": "1\n"}, {"input": "4\n1 1 1 1\n1 1 0 1\n1 1 2 1\n1 1 1 1\n", "output": "-1\n"}, {"input": "1\n0\n", "output": "1\n"}, {"input": "10\n92 67 99 74 1 51 8 58 15 40\n17 42 24 49 0 26 83 33 90 65\n98 73 80 55 7 57 14 64 16 41\n23 48 5 30 82 32 89 39 91 66\n4 54 81 56 88 63 20 70 22 47\n79 29 6 31 13 38 95 45 97 72\n85 60 87 62 19 69 21 71 3 28\n10 35 12 37 94 44 96 46 78 53\n86 61 93 68 25 75 2 52 9 34\n11 36 18 43 100 50 77 27 84 59\n", "output": "76\n"}, {"input": "4\n1000000000 1000000000 1000000000 1000000000\n1000000000 1000000000 1000000000 1000000000\n1000000000 1000000000 0 1000000000\n1000000000 1000000000 1000000000 1000000000\n", "output": "1000000000\n"}, {"input": "3\n3 8 1\n2 4 6\n7 0 5\n", "output": "-1\n"}, {"input": "3\n1 2 2\n2 2 1\n0 1 2\n", "output": "-1\n"}, {"input": "3\n1 6 10\n5 6 16\n0 5 1\n", "output": "-1\n"}, {"input": "3\n2 2 1\n1 2 2\n0 1 2\n", "output": "-1\n"}, {"input": "3\n1 2 2\n2 2 1\n2 1 0\n", "output": "-1\n"}, {"input": "3\n2016 2016 2016\n2016 0 2016\n2016 2016 2016\n", "output": "2016\n"}, {"input": "10\n92 67 99 74 1 51 8 58 15 40\n17 42 24 49 76 26 83 33 90 65\n98 73 80 55 7 57 14 64 16 41\n23 48 5 30 82 32 89 39 91 66\n4 54 81 56 88 63 20 70 22 47\n79 29 6 31 13 38 95 45 97 72\n85 60 87 62 19 69 21 71 3 28\n10 35 12 37 94 44 96 46 78 53\n86 61 93 68 25 75 2 52 0 34\n11 36 18 43 100 50 77 27 84 59\n", "output": "9\n"}, {"input": "10\n92 67 99 74 1 51 8 58 15 40\n17 42 24 49 76 26 83 33 90 65\n98 73 80 55 7 57 14 64 16 41\n23 48 5 30 82 32 89 39 91 66\n4 54 81 56 0 63 20 70 22 47\n79 29 6 31 13 38 95 45 97 72\n85 60 87 62 19 69 21 71 3 28\n10 35 12 37 94 44 96 46 78 53\n86 61 93 68 25 75 2 52 9 34\n11 36 18 43 100 50 77 27 84 59\n", "output": "88\n"}, {"input": "3\n2 2 1\n1 2 2\n2 1 0\n", "output": "-1\n"}, {"input": "10\n92 67 99 74 1 51 8 58 15 0\n17 42 24 49 76 26 83 33 90 65\n98 73 80 55 7 57 14 64 16 41\n23 48 5 30 82 32 89 39 91 66\n4 54 81 56 88 63 20 70 22 47\n79 29 6 31 13 38 95 45 97 72\n85 60 87 62 19 69 21 71 3 28\n10 35 12 37 94 44 96 46 78 53\n86 61 93 68 25 75 2 52 9 34\n11 36 18 43 100 50 77 27 84 59\n", "output": "40\n"}, {"input": "4\n2 2 2 2\n2 0 2 2\n3 2 2 1\n2 2 2 2\n", "output": "-1\n"}, {"input": "3\n1 15 5\n11 7 3\n9 0 13\n", "output": "-1\n"}, {"input": "3\n61 0 41\n11 31 51\n21 71 1\n", "output": "-1\n"}, {"input": "3\n3 0 3\n2 3 2\n2 3 2\n", "output": "-1\n"}, {"input": "3\n0 2 2\n3 1 1\n1 2 2\n", "output": "-1\n"}, {"input": "3\n1 0 1\n1 1 2\n1 1 1\n", "output": "-1\n"}, {"input": "3\n1 0 1\n2 1 2\n2 1 2\n", "output": "-1\n"}, {"input": "3\n1 0 1\n4 1 4\n1 1 1\n", "output": "-1\n"}, {"input": "3\n1 1 1\n1 1 0\n1 2 1\n", "output": "-1\n"}, {"input": "3\n2 0 1\n1 2 1\n1 1 2\n", "output": "-1\n"}, {"input": "3\n1 2 2\n3 1 1\n0 2 2\n", "output": "-1\n"}, {"input": "4\n0 1 1 1\n1 1 1 1\n1 1 1 2\n1 1 2 1\n", "output": "-1\n"}, {"input": "4\n1 1 0 1\n1 1 1 1\n1 1 1 1\n1 2 1 1\n", "output": "-1\n"}, {"input": "5\n1 1 1000000000 1000000000 1000000000\n1 1000000000 1 1000000000 1000000000\n0 1 1 1 1\n1 1000000000 1000000000 1000000000 1\n1 1000000000 1000000000 1 1000000000\n", "output": "2999999998\n"}, {"input": "3\n5 5 5\n6 5 0\n5 5 5\n", "output": "-1\n"}, {"input": "3\n1 0 1\n50 1 500\n2 1 2\n", "output": "-1\n"}, {"input": "9\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\n1 1 1 1 0 1 1 1 1\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\n1000000000 1 1000000000 1 1 1 1000000000 1 1000000000\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1\n", "output": "3999999997\n"}, {"input": "3\n7 22 1\n4 10 16\n19 0 13\n", "output": "-1\n"}, {"input": "5\n1 1 1 1 1\n1 1 1 1 0\n1 2 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n", "output": "-1\n"}, {"input": "4\n3 6 0 2\n5 5 7 1\n1 7 4 6\n2 9 1 6\n", "output": "-1\n"}, {"input": "5\n1 2 1 1 1\n1 1 2 1 1\n2 1 1 0 1\n1 1 1 1 2\n1 1 1 2 1\n", "output": "-1\n"}, {"input": "11\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 5 5 5 5 5 5 5\n5 5 5 5 13 1 1 5 5 5 5\n5 5 5 5 5 9 1 5 5 5 5\n5 5 5 5 0 5 13 5 5 5 5\n", "output": "-1\n"}, {"input": "2\n5 5\n5 0\n", "output": "5\n"}, {"input": "5\n10 10 1 10 10\n1 1 0 1 1\n10 10 1 10 10\n10 10 1 10 10\n10 10 1 10 10\n", "output": "-1\n"}, {"input": "5\n1 1 1 2 1\n1 1 1 1 1\n1 1 0 1 1\n1 1 1 1 1\n1 1 1 1 1\n", "output": "-1\n"}, {"input": "3\n1000000000 1000000000 1000000000\n1000000000 1000000000 1000000000\n1000000000 0 1000000000\n", "output": "1000000000\n"}, {"input": "3\n3 3 3\n0 2 5\n1 1 1\n", "output": "-1\n"}, {"input": "4\n2 2 3 1\n1 0 3 3\n4 3 4 1\n1 2 3 1\n", "output": "-1\n"}, {"input": "3\n1 1 2\n2 1 0\n1 2 1\n", "output": "-1\n"}, {"input": "2\n1 2\n1 0\n", "output": "-1\n"}, {"input": "2\n0 535\n535 535\n", "output": "535\n"}, {"input": "6\n0 1 1 1 1 1\n1 1 1000000000 1000000000 1000000000 1000000000\n1 1000000000 1 1000000000 1000000000 1000000000\n1 1000000000 1000000000 1 1000000000 1000000000\n1 1000000000 1000000000 1000000000 1 1000000000\n1 1000000000 1000000000 1000000000 1000000000 1\n", "output": "3999999997\n"}, {"input": "4\n2 6 0 3\n5 5 7 1\n5 1 3 9\n6 6 1 5\n", "output": "-1\n"}, {"input": "5\n2 1 2 1 2\n2 2 2 2 2\n2 2 0 2 2\n2 2 2 2 2\n2 2 2 2 2\n", "output": "-1\n"}, {"input": "3\n1 2 3\n1 0 3\n1 2 3\n", "output": "-1\n"}, {"input": "3\n0 1 2\n1 2 1\n2 1 1\n", "output": "-1\n"}, {"input": "4\n2 3 2 3\n3 2 3 0\n2 4 2 2\n3 1 3 3\n", "output": "-1\n"}, {"input": "3\n1 1 1\n1 0 1\n1 2 1\n", "output": "-1\n"}, {"input": "3\n1 1 1\n1 4 1\n1 1 0\n", "output": "-1\n"}, {"input": "5\n1 1 2 1 1\n1 1 1 1 1\n1 1 1 0 1\n1 1 1 1 1\n1 1 1 1 1\n", "output": "-1\n"}, {"input": "3\n0 1 1\n1 1 1\n1 1 2\n", "output": "-1\n"}, {"input": "3\n1 2 1\n1 0 1\n1 2 1\n", "output": "-1\n"}, {"input": "3\n6 7 2\n1 0 9\n8 3 4\n", "output": "5\n"}, {"input": "3\n1 1 1\n1 1 1\n1 0 1\n", "output": "1\n"}, {"input": "3\n3 6 0\n3 3 5\n5 2 4\n", "output": "-1\n"}, {"input": "5\n1 2 2 2 1\n1 1 1 1 0\n2 2 1 2 1\n2 1 2 1 1\n1 2 2 2 1\n", "output": "-1\n"}, {"input": "4\n1 1 1 1\n1 1 1 0\n1 1 2 1\n1 1 1 1\n", "output": "-1\n"}, {"input": "3\n13 0 19\n16 10 4\n1 22 7\n", "output": "-1\n"}, {"input": "4\n1 2 2 1\n2 1 0 2\n2 1 1 2\n1 2 2 1\n", "output": "-1\n"}]
263
There are $n$ benches in the Berland Central park. It is known that $a_i$ people are currently sitting on the $i$-th bench. Another $m$ people are coming to the park and each of them is going to have a seat on some bench out of $n$ available. Let $k$ be the maximum number of people sitting on one bench after additional $m$ people came to the park. Calculate the minimum possible $k$ and the maximum possible $k$. Nobody leaves the taken seat during the whole process. -----Input----- The first line contains a single integer $n$ $(1 \le n \le 100)$ β€” the number of benches in the park. The second line contains a single integer $m$ $(1 \le m \le 10\,000)$ β€” the number of people additionally coming to the park. Each of the next $n$ lines contains a single integer $a_i$ $(1 \le a_i \le 100)$ β€” the initial number of people on the $i$-th bench. -----Output----- Print the minimum possible $k$ and the maximum possible $k$, where $k$ is the maximum number of people sitting on one bench after additional $m$ people came to the park. -----Examples----- Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 -----Note----- In the first example, each of four benches is occupied by a single person. The minimum $k$ is $3$. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining β€” the fourth bench. The maximum $k$ is $7$. That requires all six new people to occupy the same bench. The second example has its minimum $k$ equal to $15$ and maximum $k$ equal to $15$, as there is just a single bench in the park and all $10$ people will occupy it.
interview
[{"code": "n = int(input())\nm = int(input())\na = []\nfor i in range(n):\n a.append(int(input()))\n\nmx = max(a) + m\n\n\n\nwhile m:\n for i in range(n):\n if a[i] == min(a):\n a[i] += 1\n m -= 1\n break\n\nprint(max(a), mx)\n", "passed": true, "time": 13.88, "memory": 14860.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 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 \n\nN = int(input())\n\nM = int(input())\nza = []\nfor i in range(N):\n za.append( int(input()) )\n \nt = sum(za)\n\nx = (t+ M - 1) //N + 1\nprint( max(x, max(za)), max(za) + M)\n\n\n\n\n\n\n", "passed": true, "time": 1.81, "memory": 14580.0, "status": "done"}, {"code": "from math import ceil\n\nn = int(input())\nm = int(input())\n\nbs = []\nfor _ in range(n):\n bs.append(int(input()))\n\nb = max(bs)\ntotal = sum(bs) + m\n\nmaximum = b + m\nif total <= b * n:\n minimum = b\nelse:\n minimum = int(ceil(total / n))\n\nprint(minimum, maximum)\n", "passed": true, "time": 0.15, "memory": 14280.0, "status": "done"}, {"code": "n = int(input())\nm = int(input())\na = []\nfor i in range(n):\n a.append(int(input()))\n\nmxa = max(a)\nrmx = mxa + m\nfor x in a:\n m -= mxa - x\n\nrmn = mxa\nif m > 0:\n rmn += (m + n - 1) // n\n\nprint(rmn, rmx)", "passed": true, "time": 0.15, "memory": 14312.0, "status": "done"}, {"code": "n = int(input())\nm = int(input())\n\naa = []\nfor i in range(n):\n aa += [int(input())]\n\nmaxAns = max(aa) + m\n\nrest = max(aa) * n - sum(aa)\nif m <= rest:\n minAns = max(aa)\nelse:\n m -= rest\n minAns = max(aa) + (m + n - 1) // n\n\nprint(minAns, maxAns)", "passed": true, "time": 0.15, "memory": 14464.0, "status": "done"}, {"code": "import math\nn = int(input())\nm = int(input())\na = []\nfor i in range(n):\n a.append(int(input()))\nmaxs = max(a)\nm1 = m\nfor i in a:\n m -= (maxs - i)\n\nprint(maxs + max(math.ceil(m / n), 0), maxs + m1)\n\n", "passed": true, "time": 0.16, "memory": 14360.0, "status": "done"}, {"code": "n = int(input())\nm = int(input())\nu = []\nfor i in range(n):\n u.append(int(input()))\nk = max(u)\na1 = k + m\nfor i in range(n):\n m -= k - u[i]\nif m > 0:\n k += m // n\n if m % n != 0:\n k += 1\nprint(k, a1)\n", "passed": true, "time": 0.15, "memory": 14324.0, "status": "done"}, {"code": "n=int(input())\nm=int(input())\na=[int(input()) for i in range(n)]\nmax_k= max(a)+m\nmax_a=max(a)\nfor ax in a:\n m-=max_a-ax\nmin_k = max(a)\nif m>0:\n min_k += m//n\n if m%n>0:\n min_k+=1\nprint(min_k, max_k)\n\n\n\n", "passed": true, "time": 0.15, "memory": 14348.0, "status": "done"}, {"code": "n, m = int(input()), int(input())\na = []\nfor i in range(n):\n a.append(int(input()))\nma = max(a) + m\nm -= max(a) * n - sum(a)\nmi = max(a) + max(0, (m + n - 1) // n)\nprint(mi, ma)\n", "passed": true, "time": 0.24, "memory": 14600.0, "status": "done"}, {"code": "n = int(input())\nm = int(input())\na = sorted([int(input()) for i in range(n)])\nans2 = max(a) + m\nfor i in range(n):\n m -= a[-1] - a[i]\n a[i] += a[-1] - a[i]\nans1 = a[-1] if m <= 0 else a[-1] + (m + n - 1) // n\nprint(ans1, ans2)\n", "passed": true, "time": 0.15, "memory": 14476.0, "status": "done"}, {"code": "n = int(input())\nm = int(input())\na = [int(input()) for _ in range(n)]\n\nans = [max(a), max(a) + m]\nd = m - n * max(a) + sum(a)\nif 0 < d:\n ans[0] += (d + n - 1) // n\n\nprint(\" \".join(map(str, ans)))\n", "passed": true, "time": 0.25, "memory": 14448.0, "status": "done"}, {"code": "n=int(input())\nm=int(input())\nl=[0 for i in range(n)]\nfor i in range(n):\n\tl[i]=int(input())\nd1=max(l)\nd2=min(l)\ne=sum(l)\nr=(e+m)\nif (r%n==0):\n\tr1=r//n\nelse:\n\tr1=r//n+1\nprint (max(d1,r1),d1+m)", "passed": true, "time": 0.15, "memory": 14772.0, "status": "done"}, {"code": "n = int(input())\nm = int(input())\nl = []\nfor i in range(n):\n\tl.append(int(input()))\nma = max(l)\nmx = ma+m\nl.sort()\nfor i in range(n):\n\tm-=(ma-l[i])\nif(m<=0):\n\tmi = ma\nelse:\n\tmi = ma+m//n\n\tif(m%n!=0):\n\t\tmi+=1\nprint(mi,mx)", "passed": true, "time": 0.26, "memory": 14304.0, "status": "done"}, {"code": "n = int(input())\nm = int(input())\na = []\nfor _ in range(n):\n a.append(int(input()))\na = sorted(a)\nmax_i = max(a) + m\nfor i in range(m):\n a[0] += 1\n a = sorted(a)\nmin_i = max(a)\nprint(min_i, max_i)", "passed": true, "time": 0.48, "memory": 14540.0, "status": "done"}, {"code": "# ns=[int(x)for x in input().split()]\nn=int(input())\nm=int(input())\nns=[]\nfor _ in range(n):\n ns.append(int(input()))\nmaxx=max(ns)\nans2=maxx+m\n\nhole=0\nfor t in ns:\n hole+=maxx-t\n\nif hole>=m:\n ans1=maxx\nelse:\n m-=hole\n ans1=maxx+(m//n)\n if m%n!=0:\n ans1+=1\nprint(ans1,ans2)", "passed": true, "time": 0.15, "memory": 14568.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport time\nimport math\n\nn = int(input())\nm = int(input())\na = []\n\nfor i in range(n):\n a.append(int(input()))\n\nstart = time.time()\n\nmax_now = max(a)\nsum = 0\n\nfor i in range(n):\n sum += max_now-a[i]\n\nans_max = max_now+m\nif sum >= m:\n ans_min = max_now\nelse:\n ans_min=max_now+math.ceil((m-sum)/n)\n\nprint(ans_min, ans_max)\nfinish = time.time()\n#print(finish - start)\n", "passed": true, "time": 0.17, "memory": 14584.0, "status": "done"}, {"code": "import math\nn = int(input())\nm = int(input())\nx = m\n\narr = []\nfor i in range(n):\n arr.append(int(input()))\n\nmaxx = max(arr)\n\nsumm = 0\n\nfor i in range(n):\n if arr[i] <= maxx:\n if m >= maxx - arr[i]:\n m -= maxx - arr[i]\n arr[i] = maxx\n else:\n arr[i] += m\n m = 0\n\nprint(maxx + math.ceil(m/n), maxx + x)\n\n", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "import math\nn=int(input())\nm=int(input())\na=[]\nfor i in range(n):\n a.append(int(input()))\n\nx=max(a)\ny=min(a)\nop=((sum(a)+m)/n)\n# print(op)\nif(op!=int(op)):\n op=op+1\nprint(max(x,int(op)),x+m)\n", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}, {"code": "n = int(input())\nm = int(input())\na = [int(input()) for _ in range(n)]\ns = sum(a)\nmn, mx = min(a), max(a)\nmx_k = mx + m\nm -= mx * n - s\nif m > 0:\n mx += m // n\n mx += 1 if m % n else 0\nprint(mx, mx_k)\n", "passed": true, "time": 0.15, "memory": 14524.0, "status": "done"}, {"code": "n=int(input())\nm=int(input())\nA=[int(input()) for i in range(n)]\n\nA.sort()\nANS2=max(A)+m\n\nwhile m!=0:\n x=min(A)\n i=0\n while i<n and m!=0:\n if A[i]==x:\n A[i]+=1\n i+=1\n m-=1\n else:\n break\n\n A.sort()\n\n \nprint(max(A),ANS2)\n", "passed": true, "time": 0.19, "memory": 14344.0, "status": "done"}, {"code": "n=int(input().rstrip())\nm=int(input().rstrip())\nL=[]\nfor _ in range(n):\n a=int(input().rstrip())\n L.append(a)\nmax_a=m+max(L)\nk=m\nwhile(k):\n L[L.index(min(L))]=min(L)+1\n k=k-1\nmin_a=max(L)\nprint(str(min_a)+\" \"+str(max_a))", "passed": true, "time": 0.76, "memory": 14364.0, "status": "done"}, {"code": "n = int(input())\nm = int(input())\nmax_k = 0\nsum = 0\nmin_k = 0\nfor i in range(n):\n a = int(input())\n sum += a\n min_k = max(min_k, a)\n\n# avg_k = sum / n + (1 if sum % n != 0 else 0)\nmax_sum = min_k * n\nmax_k = min_k + m\nif max_sum < sum + m:\n m -= (max_sum - sum)\n min_k += m // n + (1 if m % n != 0 else 0)\n\nprint(min_k, max_k)\n\n\n", "passed": true, "time": 0.15, "memory": 14400.0, "status": "done"}, {"code": "import sys\nimport math\n\ninput = sys.stdin.readline\nn = int(input())\nm = int(input())\na_list = []\na_max = 0\nfor _ in range(n):\n a = int(input())\n if a_max < a:\n a_max = a\n a_list.append(a)\ntmp = 0\nfor a in a_list:\n tmp += a_max-a\nif tmp >= m:\n a_min = a_max\nelse:\n a_min = a_max + math.ceil((m-tmp)/n)\nprint(a_min, a_max+m)\n", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "import heapq\nN = int(input())\nM = int(input())\nsrc = [int(input()) for i in range(N)]\n\nmx = max(src) + M\n\nhq = src[:]\nheapq.heapify(hq)\n\nfor i in range(M):\n m = heapq.heappop(hq)\n heapq.heappush(hq, m+1)\nwhile hq:\n mn = heapq.heappop(hq)\n\nprint(mn, mx)\n", "passed": true, "time": 0.2, "memory": 14524.0, "status": "done"}]
[{"input": "4\n6\n1\n1\n1\n1\n", "output": "3 7\n"}, {"input": "1\n10\n5\n", "output": "15 15\n"}, {"input": "3\n6\n1\n6\n5\n", "output": "6 12\n"}, {"input": "3\n7\n1\n6\n5\n", "output": "7 13\n"}, {"input": "10\n1000\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n", "output": "200 1100\n"}, {"input": "10\n1\n3\n3\n2\n3\n3\n3\n3\n3\n3\n3\n", "output": "3 4\n"}, {"input": "51\n10000\n54\n23\n93\n86\n57\n68\n42\n33\n47\n18\n78\n41\n35\n92\n32\n97\n74\n93\n27\n59\n90\n23\n79\n96\n77\n29\n88\n83\n83\n46\n94\n61\n56\n68\n43\n15\n79\n26\n36\n99\n36\n55\n77\n23\n15\n12\n84\n57\n82\n33\n14\n", "output": "254 10099\n"}, {"input": "100\n8000\n88\n40\n39\n88\n33\n2\n60\n93\n62\n18\n44\n53\n79\n55\n34\n71\n45\n82\n97\n96\n96\n25\n83\n83\n54\n45\n47\n59\n94\n84\n12\n33\n97\n24\n71\n28\n81\n89\n52\n87\n96\n35\n34\n31\n45\n42\n14\n74\n8\n68\n61\n36\n65\n87\n31\n18\n38\n84\n28\n74\n98\n77\n15\n85\n82\n64\n2\n93\n31\n78\n64\n35\n6\n77\n55\n70\n83\n42\n98\n38\n59\n99\n27\n66\n10\n54\n22\n94\n21\n21\n89\n86\n73\n12\n86\n1\n98\n94\n48\n51\n", "output": "137 8099\n"}, {"input": "10\n10\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "output": "2 11\n"}, {"input": "10\n10\n1\n1\n1\n2\n1\n1\n1\n1\n1\n1\n", "output": "3 12\n"}, {"input": "100\n1000\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\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": "11 1001\n"}, {"input": "1\n10000\n57\n", "output": "10057 10057\n"}, {"input": "1\n1000\n48\n", "output": "1048 1048\n"}, {"input": "2\n1000\n1\n7\n", "output": "504 1007\n"}, {"input": "5\n10\n68\n87\n14\n68\n23\n", "output": "87 97\n"}, {"input": "10\n20\n80\n41\n15\n77\n91\n82\n15\n83\n36\n3\n", "output": "91 111\n"}, {"input": "20\n3303\n25\n14\n77\n85\n66\n97\n9\n60\n79\n39\n47\n2\n97\n71\n45\n36\n92\n54\n62\n53\n", "output": "221 3400\n"}, {"input": "40\n10000\n54\n5\n23\n10\n10\n77\n15\n84\n92\n63\n34\n21\n12\n56\n25\n32\n28\n50\n50\n86\n3\n26\n39\n69\n43\n99\n71\n38\n15\n33\n50\n79\n54\n84\n33\n47\n14\n66\n99\n25\n", "output": "296 10099\n"}, {"input": "66\n1000\n27\n10\n63\n17\n28\n89\n34\n86\n27\n62\n26\n18\n25\n31\n45\n44\n92\n56\n47\n18\n53\n56\n79\n3\n9\n32\n88\n52\n21\n57\n97\n84\n50\n12\n6\n52\n21\n37\n24\n84\n44\n81\n41\n47\n7\n67\n93\n43\n100\n64\n82\n46\n28\n48\n1\n34\n28\n82\n15\n47\n1\n19\n34\n12\n48\n48\n", "output": "100 1100\n"}, {"input": "78\n9909\n63\n38\n36\n74\n56\n3\n27\n99\n71\n95\n81\n39\n45\n75\n32\n42\n5\n23\n45\n46\n63\n69\n75\n80\n89\n48\n86\n74\n18\n87\n4\n55\n54\n8\n15\n91\n39\n13\n89\n95\n75\n38\n31\n27\n48\n81\n47\n91\n62\n88\n53\n45\n73\n79\n42\n57\n72\n99\n16\n52\n15\n52\n95\n98\n26\n84\n4\n88\n31\n26\n9\n86\n29\n45\n62\n18\n99\n78\n", "output": "182 10008\n"}, {"input": "89\n9080\n29\n88\n62\n50\n63\n91\n24\n3\n93\n76\n73\n50\n26\n32\n87\n93\n48\n52\n97\n68\n100\n84\n42\n93\n59\n68\n46\n19\n53\n30\n53\n20\n65\n43\n22\n98\n46\n45\n38\n37\n45\n31\n2\n24\n56\n74\n93\n48\n40\n68\n7\n4\n68\n44\n31\n63\n32\n21\n94\n92\n99\n93\n17\n18\n18\n48\n71\n38\n67\n67\n29\n87\n38\n66\n73\n61\n59\n98\n91\n33\n22\n56\n75\n91\n73\n83\n61\n41\n70\n", "output": "158 9180\n"}, {"input": "90\n10000\n43\n85\n87\n11\n50\n66\n30\n90\n23\n22\n16\n20\n2\n60\n8\n26\n56\n89\n50\n40\n3\n23\n9\n66\n36\n85\n19\n49\n87\n97\n20\n23\n75\n32\n3\n38\n71\n54\n79\n46\n62\n27\n16\n2\n24\n55\n76\n83\n55\n47\n46\n41\n63\n30\n22\n84\n70\n81\n59\n44\n56\n23\n67\n9\n60\n54\n95\n36\n73\n60\n33\n20\n18\n67\n20\n18\n7\n65\n55\n54\n45\n32\n38\n52\n15\n15\n88\n44\n47\n88\n", "output": "157 10097\n"}, {"input": "99\n1092\n28\n89\n65\n40\n96\n47\n76\n2\n62\n59\n60\n90\n91\n12\n10\n71\n57\n97\n18\n52\n82\n32\n71\n77\n39\n16\n84\n89\n26\n95\n45\n15\n93\n73\n63\n32\n33\n3\n64\n12\n92\n12\n92\n80\n3\n80\n47\n26\n69\n84\n96\n40\n86\n95\n55\n13\n64\n73\n52\n37\n13\n98\n86\n95\n43\n67\n18\n98\n100\n66\n5\n25\n87\n25\n37\n10\n29\n43\n84\n72\n17\n70\n31\n96\n27\n38\n1\n40\n74\n17\n58\n39\n18\n5\n41\n15\n95\n53\n77\n", "output": "100 1192\n"}, {"input": "100\n66\n95\n19\n88\n15\n29\n52\n37\n75\n21\n90\n93\n75\n91\n71\n53\n55\n90\n78\n19\n63\n43\n25\n52\n10\n55\n76\n47\n42\n57\n45\n35\n53\n2\n62\n61\n99\n59\n59\n43\n45\n31\n37\n50\n68\n51\n91\n34\n48\n40\n69\n77\n33\n16\n64\n19\n82\n76\n35\n41\n41\n79\n29\n69\n100\n30\n81\n47\n55\n79\n21\n59\n3\n11\n43\n49\n100\n27\n87\n64\n8\n6\n7\n88\n71\n98\n6\n32\n53\n91\n85\n60\n35\n55\n5\n44\n66\n76\n99\n7\n58\n", "output": "100 166\n"}, {"input": "100\n50\n20\n63\n60\n88\n7\n22\n90\n15\n27\n82\n37\n44\n42\n50\n33\n46\n7\n97\n93\n5\n68\n79\n76\n3\n82\n5\n51\n79\n17\n1\n1\n93\n52\n88\n23\n23\n49\n86\n64\n18\n36\n53\n49\n47\n11\n19\n6\n79\n64\n59\n56\n96\n15\n72\n81\n45\n24\n55\n31\n2\n74\n64\n57\n65\n71\n44\n8\n7\n38\n50\n67\n1\n79\n89\n16\n35\n10\n72\n69\n8\n56\n42\n44\n95\n25\n26\n16\n84\n36\n73\n17\n61\n91\n15\n19\n78\n44\n77\n96\n58\n", "output": "97 147\n"}, {"input": "100\n100\n82\n51\n81\n14\n37\n17\n78\n92\n64\n15\n8\n86\n89\n8\n87\n77\n66\n10\n15\n12\n100\n25\n92\n47\n21\n78\n20\n63\n13\n49\n41\n36\n41\n79\n16\n87\n87\n69\n3\n76\n80\n60\n100\n49\n70\n59\n72\n8\n38\n71\n45\n97\n71\n14\n76\n54\n81\n4\n59\n46\n39\n29\n92\n3\n49\n22\n53\n99\n59\n52\n74\n31\n92\n43\n42\n23\n44\n9\n82\n47\n7\n40\n12\n9\n3\n55\n37\n85\n46\n22\n84\n52\n98\n41\n21\n77\n63\n17\n62\n91\n", "output": "100 200\n"}, {"input": "100\n1000\n91\n17\n88\n51\n92\n47\n85\n3\n82\n61\n2\n48\n55\n56\n71\n1\n12\n78\n80\n31\n42\n33\n85\n99\n25\n25\n37\n18\n29\n53\n84\n88\n4\n55\n24\n3\n53\n53\n1\n95\n36\n84\n65\n5\n40\n52\n49\n77\n48\n5\n77\n50\n31\n80\n100\n46\n28\n29\n34\n83\n26\n3\n100\n63\n100\n23\n76\n4\n70\n57\n10\n58\n7\n20\n84\n44\n86\n54\n2\n11\n85\n3\n35\n83\n96\n97\n55\n75\n39\n39\n39\n61\n19\n86\n76\n72\n29\n69\n20\n17\n", "output": "100 1100\n"}, {"input": "100\n2000\n77\n39\n49\n44\n85\n10\n28\n49\n92\n64\n67\n39\n65\n53\n81\n58\n63\n80\n74\n27\n10\n45\n9\n26\n31\n98\n55\n61\n51\n43\n2\n95\n77\n52\n79\n42\n89\n99\n68\n6\n29\n71\n63\n96\n11\n10\n77\n32\n89\n28\n12\n19\n84\n34\n22\n69\n86\n24\n35\n40\n5\n100\n55\n35\n69\n60\n74\n72\n37\n44\n82\n83\n91\n1\n68\n24\n79\n39\n47\n57\n16\n76\n64\n34\n72\n3\n48\n35\n15\n70\n33\n78\n31\n48\n10\n30\n55\n43\n6\n93\n", "output": "100 2100\n"}, {"input": "100\n5000\n30\n90\n42\n18\n55\n6\n50\n65\n31\n89\n47\n48\n76\n58\n10\n18\n2\n79\n39\n9\n7\n89\n100\n1\n44\n23\n99\n12\n23\n15\n55\n16\n95\n40\n23\n37\n87\n42\n54\n51\n11\n57\n44\n61\n32\n74\n44\n5\n1\n96\n32\n30\n21\n13\n77\n48\n62\n6\n28\n7\n49\n87\n33\n60\n72\n64\n88\n86\n34\n13\n23\n59\n46\n39\n5\n45\n81\n88\n75\n97\n40\n88\n46\n100\n87\n30\n37\n13\n68\n43\n9\n32\n48\n28\n100\n14\n28\n67\n73\n26\n", "output": "100 5100\n"}, {"input": "100\n9990\n22\n89\n54\n55\n92\n20\n84\n12\n93\n6\n73\n50\n23\n62\n97\n88\n59\n87\n4\n14\n49\n28\n47\n93\n5\n36\n50\n78\n83\n99\n100\n27\n24\n23\n27\n84\n67\n72\n45\n51\n53\n32\n60\n9\n77\n63\n15\n98\n17\n49\n58\n77\n50\n31\n10\n6\n16\n74\n50\n99\n100\n36\n51\n71\n89\n65\n17\n62\n32\n3\n25\n39\n19\n2\n25\n75\n25\n89\n87\n13\n96\n91\n10\n1\n94\n39\n10\n64\n26\n28\n32\n7\n16\n34\n96\n28\n24\n35\n82\n99\n", "output": "150 10090\n"}, {"input": "100\n10000\n25\n90\n88\n97\n71\n24\n53\n4\n32\n69\n53\n93\n80\n14\n30\n65\n9\n56\n3\n23\n70\n25\n31\n6\n13\n19\n49\n58\n95\n40\n26\n72\n75\n44\n86\n13\n94\n11\n83\n75\n26\n64\n100\n84\n82\n35\n80\n41\n40\n8\n5\n28\n3\n98\n1\n22\n73\n33\n44\n22\n2\n72\n68\n80\n39\n92\n75\n67\n61\n26\n89\n59\n19\n29\n7\n60\n91\n34\n73\n53\n22\n2\n85\n22\n47\n92\n90\n99\n100\n44\n82\n19\n1\n49\n100\n13\n67\n32\n75\n98\n", "output": "151 10100\n"}, {"input": "100\n10000\n45\n35\n50\n78\n28\n97\n37\n92\n91\n51\n93\n33\n70\n43\n53\n78\n31\n14\n29\n67\n11\n7\n41\n85\n70\n27\n74\n15\n15\n10\n52\n50\n66\n81\n95\n25\n28\n86\n17\n89\n19\n87\n85\n38\n79\n19\n92\n85\n62\n71\n18\n72\n92\n18\n93\n56\n64\n54\n3\n38\n18\n77\n3\n54\n70\n49\n56\n91\n60\n56\n34\n54\n42\n41\n75\n90\n43\n21\n18\n69\n76\n51\n24\n50\n82\n56\n62\n45\n50\n67\n20\n31\n12\n10\n10\n7\n75\n84\n17\n18\n", "output": "151 10097\n"}, {"input": "2\n50\n1\n51\n", "output": "51 101\n"}, {"input": "3\n100\n52\n2\n2\n", "output": "52 152\n"}, {"input": "100\n300\n1\n1\n2\n2\n1\n1\n1\n1\n1\n1\n2\n2\n1\n2\n2\n1\n2\n2\n2\n2\n2\n1\n1\n1\n2\n1\n2\n1\n1\n1\n2\n1\n1\n1\n2\n1\n2\n1\n2\n1\n2\n1\n2\n1\n2\n1\n1\n1\n1\n2\n2\n2\n1\n1\n2\n1\n2\n2\n2\n1\n1\n2\n2\n2\n2\n2\n2\n1\n1\n2\n2\n2\n2\n1\n2\n2\n2\n1\n2\n1\n1\n2\n2\n1\n1\n1\n1\n2\n1\n2\n2\n1\n2\n2\n1\n1\n2\n1\n2\n2\n", "output": "5 302\n"}, {"input": "100\n3000\n99\n100\n99\n99\n100\n99\n100\n99\n99\n100\n99\n100\n100\n99\n100\n100\n99\n99\n99\n100\n100\n100\n100\n100\n99\n100\n100\n99\n100\n100\n99\n99\n99\n99\n100\n100\n99\n99\n99\n100\n99\n100\n100\n99\n99\n100\n100\n100\n99\n99\n99\n100\n99\n99\n99\n100\n99\n99\n100\n99\n100\n100\n100\n99\n99\n100\n100\n100\n99\n100\n100\n99\n99\n100\n100\n99\n100\n100\n100\n99\n99\n100\n100\n99\n100\n99\n99\n100\n99\n99\n99\n100\n99\n100\n100\n100\n99\n100\n99\n100\n", "output": "130 3100\n"}, {"input": "100\n10000\n54\n54\n50\n52\n55\n51\n50\n53\n50\n56\n50\n51\n51\n52\n54\n50\n54\n52\n53\n56\n55\n51\n52\n55\n56\n52\n52\n56\n51\n56\n51\n51\n55\n54\n52\n55\n51\n55\n56\n54\n55\n54\n56\n56\n51\n52\n52\n56\n51\n52\n52\n55\n53\n51\n55\n51\n54\n52\n56\n51\n50\n52\n52\n55\n53\n52\n53\n53\n51\n52\n54\n50\n53\n53\n56\n52\n52\n54\n54\n52\n55\n53\n54\n53\n54\n55\n56\n51\n54\n55\n50\n56\n52\n50\n55\n55\n54\n55\n50\n50\n", "output": "154 10056\n"}, {"input": "100\n2325\n78\n78\n80\n78\n79\n80\n79\n80\n79\n80\n78\n80\n79\n80\n78\n78\n79\n80\n80\n80\n79\n79\n79\n79\n80\n80\n79\n80\n79\n80\n79\n79\n79\n79\n80\n80\n80\n78\n80\n80\n80\n78\n80\n80\n80\n80\n78\n78\n79\n79\n79\n79\n80\n78\n80\n78\n80\n80\n80\n79\n78\n79\n80\n80\n78\n78\n80\n78\n80\n79\n78\n80\n78\n78\n80\n80\n78\n78\n79\n78\n78\n79\n79\n78\n80\n78\n78\n80\n80\n80\n78\n80\n78\n79\n80\n78\n80\n79\n78\n79\n", "output": "103 2405\n"}, {"input": "100\n3241\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": "133 3341\n"}, {"input": "100\n9675\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\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": "98 9676\n"}, {"input": "100\n9435\n36\n37\n36\n36\n37\n34\n35\n37\n36\n34\n37\n35\n34\n35\n35\n36\n36\n37\n37\n36\n37\n34\n36\n35\n37\n36\n34\n35\n35\n35\n34\n36\n37\n36\n35\n34\n35\n34\n34\n34\n36\n37\n37\n34\n37\n34\n37\n36\n35\n36\n37\n35\n37\n35\n36\n34\n36\n35\n35\n35\n37\n37\n36\n34\n35\n35\n36\n35\n34\n35\n35\n35\n37\n36\n34\n35\n37\n36\n36\n36\n36\n35\n34\n37\n35\n34\n37\n37\n36\n37\n37\n34\n36\n35\n36\n35\n34\n37\n34\n35\n", "output": "130 9472\n"}, {"input": "100\n9999\n4\n5\n1\n8\n8\n2\n9\n5\n8\n6\n10\n8\n2\n10\n5\n10\n10\n3\n3\n1\n9\n7\n1\n5\n3\n7\n1\n3\n7\n3\n7\n8\n8\n8\n10\n3\n9\n9\n5\n9\n4\n7\n3\n8\n8\n6\n9\n4\n4\n8\n3\n6\n3\n3\n7\n10\n4\n2\n4\n3\n9\n10\n2\n4\n3\n1\n3\n4\n4\n4\n5\n8\n6\n3\n9\n10\n7\n7\n10\n2\n6\n10\n7\n7\n10\n6\n2\n9\n8\n1\n6\n7\n3\n5\n8\n6\n1\n3\n8\n5\n", "output": "106 10009\n"}, {"input": "100\n2344\n42\n40\n69\n62\n79\n43\n36\n55\n44\n13\n48\n69\n46\n61\n70\n75\n51\n67\n57\n35\n5\n19\n6\n92\n78\n59\n42\n3\n81\n41\n70\n90\n99\n93\n44\n22\n80\n62\n69\n95\n12\n63\n99\n42\n12\n9\n72\n8\n19\n33\n81\n33\n66\n32\n10\n50\n98\n83\n11\n25\n81\n13\n56\n60\n4\n89\n75\n59\n92\n7\n55\n84\n48\n85\n82\n18\n29\n68\n60\n25\n26\n37\n12\n15\n27\n17\n85\n20\n16\n47\n76\n55\n75\n66\n47\n98\n90\n32\n47\n9\n", "output": "99 2443\n"}, {"input": "100\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\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": "101 101\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\n1\n", "output": "2 2\n"}, {"input": "100\n2\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n50\n", "output": "51 52\n"}, {"input": "100\n300\n1\n1\n2\n2\n1\n2\n2\n2\n1\n2\n2\n2\n1\n2\n1\n1\n2\n2\n1\n1\n2\n1\n1\n2\n1\n2\n2\n2\n2\n2\n2\n1\n1\n1\n2\n2\n2\n2\n1\n1\n1\n2\n1\n1\n2\n2\n2\n1\n2\n2\n2\n1\n2\n2\n1\n2\n1\n1\n2\n2\n2\n2\n1\n2\n2\n2\n1\n1\n2\n1\n1\n1\n1\n2\n2\n2\n2\n2\n1\n2\n1\n1\n1\n1\n2\n1\n1\n2\n2\n1\n2\n1\n1\n1\n2\n2\n93\n1\n2\n2\n", "output": "93 393\n"}, {"input": "100\n3000\n2\n4\n4\n5\n3\n3\n5\n5\n2\n4\n4\n2\n3\n1\n5\n5\n5\n3\n3\n1\n2\n2\n3\n3\n5\n5\n3\n5\n2\n1\n4\n4\n5\n3\n4\n3\n1\n3\n5\n1\n3\n3\n3\n5\n3\n4\n1\n3\n1\n5\n5\n5\n5\n3\n5\n5\n2\n1\n4\n2\n5\n1\n1\n5\n1\n3\n3\n1\n4\n2\n4\n3\n4\n4\n5\n2\n5\n95\n1\n2\n1\n2\n5\n3\n3\n2\n3\n4\n2\n3\n3\n2\n3\n4\n4\n4\n4\n3\n3\n2\n", "output": "95 3095\n"}, {"input": "100\n10000\n51\n53\n53\n54\n52\n52\n51\n53\n52\n55\n53\n51\n56\n55\n55\n50\n53\n53\n50\n52\n53\n50\n51\n56\n54\n50\n53\n51\n54\n50\n50\n55\n50\n53\n52\n52\n54\n56\n56\n52\n54\n56\n52\n52\n55\n54\n56\n53\n54\n53\n55\n50\n55\n54\n54\n56\n50\n50\n56\n55\n55\n53\n52\n54\n52\n53\n50\n53\n54\n52\n53\n52\n52\n56\n51\n53\n53\n55\n50\n50\n51\n55\n55\n51\n50\n51\n50\n54\n93\n50\n50\n55\n55\n50\n54\n55\n55\n53\n53\n56\n", "output": "154 10093\n"}, {"input": "100\n2325\n30\n18\n24\n24\n23\n23\n18\n28\n26\n28\n29\n23\n22\n19\n26\n26\n29\n20\n26\n30\n30\n26\n27\n25\n24\n25\n27\n22\n22\n19\n23\n22\n25\n27\n25\n21\n25\n26\n22\n20\n29\n21\n21\n22\n26\n29\n18\n22\n19\n23\n29\n30\n25\n22\n24\n30\n22\n23\n22\n26\n24\n19\n27\n20\n27\n29\n30\n22\n30\n26\n22\n19\n23\n20\n21\n26\n20\n30\n26\n24\n30\n20\n26\n24\n97\n25\n23\n19\n22\n19\n23\n29\n28\n28\n26\n29\n23\n26\n28\n20\n", "output": "97 2422\n"}, {"input": "100\n3241\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n93\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n10\n", "output": "93 3334\n"}, {"input": "100\n9675\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n99\n1\n1\n1\n1\n1\n1\n1\n1\n", "output": "99 9774\n"}, {"input": "10\n1\n5\n5\n5\n5\n4\n5\n5\n5\n5\n5\n", "output": "5 6\n"}, {"input": "100\n9435\n15\n16\n21\n24\n22\n27\n24\n18\n26\n25\n17\n25\n14\n26\n15\n20\n17\n21\n17\n24\n26\n26\n27\n21\n24\n20\n26\n25\n25\n20\n22\n19\n14\n16\n17\n27\n16\n21\n16\n27\n21\n14\n24\n27\n24\n19\n25\n23\n21\n19\n16\n14\n25\n18\n96\n25\n24\n15\n20\n21\n22\n15\n24\n23\n14\n22\n26\n26\n16\n17\n23\n17\n25\n22\n21\n27\n26\n19\n25\n25\n23\n16\n25\n19\n15\n19\n18\n27\n17\n21\n25\n20\n27\n14\n26\n15\n27\n15\n24\n18\n", "output": "117 9531\n"}, {"input": "100\n9999\n1\n10\n5\n2\n9\n2\n10\n10\n9\n6\n10\n8\n10\n2\n10\n8\n5\n4\n8\n6\n3\n4\n8\n6\n1\n3\n8\n8\n7\n7\n5\n3\n2\n8\n4\n3\n7\n9\n9\n10\n7\n1\n10\n6\n2\n8\n7\n4\n3\n5\n9\n1\n10\n3\n4\n10\n1\n7\n1\n91\n10\n4\n7\n6\n4\n3\n2\n6\n3\n5\n5\n2\n3\n3\n1\n10\n10\n7\n10\n7\n8\n4\n6\n6\n1\n10\n2\n9\n6\n5\n1\n10\n8\n2\n10\n7\n8\n5\n3\n6\n", "output": "107 10090\n"}, {"input": "100\n2344\n23\n10\n18\n15\n32\n22\n10\n38\n32\n31\n39\n8\n26\n16\n22\n10\n23\n11\n25\n36\n24\n40\n7\n27\n43\n28\n23\n25\n7\n23\n22\n7\n43\n6\n22\n38\n7\n32\n35\n12\n41\n43\n97\n3\n37\n29\n27\n36\n17\n2\n27\n35\n16\n10\n3\n19\n12\n20\n29\n7\n14\n5\n31\n26\n10\n4\n3\n15\n32\n42\n24\n36\n41\n43\n36\n23\n14\n32\n3\n32\n21\n30\n32\n25\n32\n8\n27\n11\n19\n15\n34\n12\n41\n11\n39\n20\n14\n23\n7\n43\n", "output": "97 2441\n"}, {"input": "2\n1\n5\n1\n", "output": "5 6\n"}, {"input": "4\n1\n1\n9\n9\n9\n", "output": "9 10\n"}, {"input": "2\n3\n1\n100\n", "output": "100 103\n"}, {"input": "2\n16\n2\n100\n", "output": "100 116\n"}, {"input": "2\n1\n1\n100\n", "output": "100 101\n"}, {"input": "3\n7\n1\n6\n1\n", "output": "6 13\n"}, {"input": "2\n1\n10\n1\n", "output": "10 11\n"}, {"input": "3\n1\n1\n1\n99\n", "output": "99 100\n"}, {"input": "2\n2\n1\n100\n", "output": "100 102\n"}]
264
There is an airplane which has n rows from front to back. There will be m people boarding this airplane. This airplane has an entrance at the very front and very back of the plane. Each person has some assigned seat. It is possible for multiple people to have the same assigned seat. The people will then board the plane one by one starting with person 1. Each person can independently choose either the front entrance or back entrance to enter the plane. When a person walks into the plane, they walk directly to their assigned seat and will try to sit in it. If it is occupied, they will continue walking in the direction they walked in until they are at empty seat - they will take the earliest empty seat that they can find. If they get to the end of the row without finding a seat, they will be angry. Find the number of ways to assign tickets to the passengers and board the plane without anyone getting angry. Two ways are different if there exists a passenger who chose a different entrance in both ways, or the assigned seat is different. Print this count modulo 10^9 + 7. -----Input----- The first line of input will contain two integers n, m (1 ≀ m ≀ n ≀ 1 000 000), the number of seats, and the number of passengers, respectively. -----Output----- Print a single number, the number of ways, modulo 10^9 + 7. -----Example----- Input 3 3 Output 128 -----Note----- Here, we will denote a passenger by which seat they were assigned, and which side they came from (either "F" or "B" for front or back, respectively). For example, one valid way is 3B, 3B, 3B (i.e. all passengers were assigned seat 3 and came from the back entrance). Another valid way would be 2F, 1B, 3F. One invalid way would be 2B, 2B, 2B, since the third passenger would get to the front without finding a seat.
interview
[{"code": "MOD = 10 ** 9 + 7\nn, m = input().split(' ')\nn = int(n)\nm = int(m)\nans = pow(2 * (n + 1), m, MOD)\nans = (ans * (n + 1 - m)) % MOD\nans = (ans * pow(n + 1, MOD - 2, MOD)) % MOD\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "mod = 1000000007\ndef power(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\nn, m = map(int, input().split())\nn += 1\nres = (power(n * 2, m - 1)) * (n - m) * 2\nprint(res % mod)", "passed": true, "time": 0.14, "memory": 14520.0, "status": "done"}]
[{"input": "3 3\n", "output": "128\n"}, {"input": "1000000 1000000\n", "output": "233176135\n"}, {"input": "1000000 500000\n", "output": "211837745\n"}, {"input": "1 1\n", "output": "2\n"}, {"input": "10 1\n", "output": "20\n"}, {"input": "285042 201091\n", "output": "348727840\n"}, {"input": "896437 604720\n", "output": "531995995\n"}, {"input": "284114 73851\n", "output": "935093233\n"}, {"input": "541826 316395\n", "output": "365726326\n"}, {"input": "353093 96536\n", "output": "708633906\n"}, {"input": "540898 158491\n", "output": "698076231\n"}, {"input": "858309 773589\n", "output": "875072331\n"}, {"input": "56322 42432\n", "output": "905316418\n"}, {"input": "461466 56468\n", "output": "616418222\n"}, {"input": "29102 1503\n", "output": "211174820\n"}, {"input": "42800 41731\n", "output": "178922948\n"}, {"input": "235175 92933\n", "output": "704139178\n"}, {"input": "921643 744360\n", "output": "959987426\n"}, {"input": "619924 583916\n", "output": "765568563\n"}, {"input": "43657 852\n", "output": "898633472\n"}, {"input": "4672 3086\n", "output": "648722588\n"}, {"input": "197047 148580\n", "output": "132050966\n"}, {"input": "693851 210584\n", "output": "800890261\n"}, {"input": "951563 122804\n", "output": "202475849\n"}, {"input": "175236 173750\n", "output": "291135880\n"}, {"input": "784160 282537\n", "output": "252488614\n"}, {"input": "976535 433238\n", "output": "30881486\n"}, {"input": "827825 745802\n", "output": "28515641\n"}, {"input": "361284 5729\n", "output": "121235105\n"}, {"input": "189791 36882\n", "output": "503014832\n"}, {"input": "84609 75872\n", "output": "860171419\n"}, {"input": "938407 501656\n", "output": "321500030\n"}, {"input": "600033 306982\n", "output": "214582457\n"}, {"input": "857745 223544\n", "output": "778808942\n"}, {"input": "321370 271684\n", "output": "624745554\n"}, {"input": "41872 1808\n", "output": "389891349\n"}, {"input": "234247 67712\n", "output": "610314478\n"}, {"input": "734006 258894\n", "output": "822257297\n"}, {"input": "991718 318936\n", "output": "688082968\n"}, {"input": "335925 159533\n", "output": "401609204\n"}, {"input": "3745 1612\n", "output": "100232679\n"}, {"input": "196119 47809\n", "output": "831275903\n"}, {"input": "506214 320883\n", "output": "31547174\n"}, {"input": "960651 256313\n", "output": "500076538\n"}, {"input": "107210 13886\n", "output": "179122019\n"}, {"input": "124763 65049\n", "output": "454953468\n"}, {"input": "491959 252209\n", "output": "696157573\n"}, {"input": "684333 613651\n", "output": "980362331\n"}, {"input": "897899 478680\n", "output": "889928809\n"}, {"input": "69082 16337\n", "output": "24188373\n"}, {"input": "261457 212062\n", "output": "866036254\n"}, {"input": "453831 290298\n", "output": "552613881\n"}, {"input": "646205 361804\n", "output": "801930294\n"}, {"input": "838580 174298\n", "output": "488250696\n"}, {"input": "364922 343089\n", "output": "140158453\n"}, {"input": "30945 5665\n", "output": "758927360\n"}, {"input": "749671 469976\n", "output": "673292024\n"}, {"input": "942045 878421\n", "output": "214250096\n"}, {"input": "287729 11831\n", "output": "625218018\n"}, {"input": "144546 128076\n", "output": "232200563\n"}, {"input": "519169 430233\n", "output": "44864151\n"}, {"input": "711543 136245\n", "output": "40200989\n"}, {"input": "903917 186673\n", "output": "762310964\n"}, {"input": "252919 105355\n", "output": "941982792\n"}, {"input": "106282 12802\n", "output": "237272767\n"}]
266
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes. -----Input----- The single line of the input contains a pair of integers m, s (1 ≀ m ≀ 100, 0 ≀ s ≀ 900) β€” the length and the sum of the digits of the required numbers. -----Output----- In the output print the pair of the required non-negative integer numbers β€” first the minimum possible number, then β€” the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). -----Examples----- Input 2 15 Output 69 96 Input 3 0 Output -1 -1
interview
[{"code": "M,S=list(map(int,input().split()))\n\nif S==0 and M==1:\n print('0 0')\n return\nelif S==0 or M*9 < S:\n print('-1 -1')\n return\n\nm,s=M,S\nl=[]\nif s<=(m-1)*9+1:\n l.append(1)\n s-=1\nwhile len(l)<m:\n r = (m-len(l)-1)*9\n if s<=r:\n l.append(0)\n else:\n l.append(s-r)\n s-=s-r\n\nm,s=M,S\nh=[]\nwhile s>=9:\n h.append(9)\n s-=9\nwhile len(h)<m:\n h.append(s)\n s=0\n\nprint(''.join(repr(x) for x in l), ''.join(repr(x) for x in h))\n\n", "passed": true, "time": 0.15, "memory": 14556.0, "status": "done"}, {"code": "m, s = list(map(int, str.split(input())))\nif s == 0 and m == 1:\n\n print(0, 0)\n\nelif s == 0 or s > 9 * m:\n\n print(-1, -1)\n\nelse:\n\n num = [0] * (m - 1) + [1]\n for i in range(m):\n\n num[i] += min(9, s - sum(num))\n\n a = str.join(\"\", list(map(str, num[::-1])))\n\n num = [0] * m\n for i in range(m):\n\n num[i] = min(9, s - sum(num))\n\n b = str.join(\"\", list(map(str, num)))\n print(a, b)\n", "passed": true, "time": 0.16, "memory": 14556.0, "status": "done"}, {"code": "m, s = [int(x) for x in input().split()]\n\n# first we check if it is possible to build the numbers\nmindsum = 1\nmaxdsum = 9*m\n\nif (m == 1 and s == 0):\n print(0, 0)\n\nelif s < mindsum or s > maxdsum:\n print(-1, -1)\nelse:\n mncount = s // 9\n mrest = s % 9\n # now there are three possibilities:\n if mncount == m:\n mnum = '9'*m\n elif mncount == m-1:\n if mrest == 0:\n mnum = '1' + '8' + '9'*(mncount-1)\n else:\n mnum = str(mrest) + '9'*mncount\n else:\n if mrest == 0:\n # format 1 000000 8 999999\n # 2 + zerocount + ninecount-1 = m\n zerocount = m - 2 - mncount + 1\n mnum = '1' + '0'*zerocount + '8' + '9'*(mncount-1)\n elif mrest == 1:\n # format 1 000000 9999999\n # 1 + zerocount + ninecount = m\n zerocount = m - 1 - mncount\n mnum = '1' + '0'*zerocount + '9'*mncount\n else:\n # format 1 000000 # 999999\n zerocount = m - 2 - mncount\n mnum = '1' + '0'*zerocount + str(mrest-1) + '9'*mncount\n\n # now we generate maximum number:\n # it will be full of nines in the beginning and then the rest filled with the largest numbers in the front\n # that's actually easy\n maxnum = ''\n t = s\n while (t >= 9):\n maxnum += '9'\n t -= 9\n if (mncount != m):\n maxnum += str(t)\n while (len(maxnum) != m):\n maxnum += '0'\n print(mnum, maxnum)\n", "passed": true, "time": 0.15, "memory": 14592.0, "status": "done"}, {"code": "a,b = list(map(int, input().split()))\n\n\nif a == 1 and b == 0:\n print(\"0 0\")\n return\nif b==0 or b>a*9:\n print(\"-1 -1\")\n return\n\nob = b\nans = \"\"\nfor x in range(a):\n if ob >9:\n ob -= 9\n ans += \"9\"\n else:\n ans += str(ob)\n ob = 0\nbig = ans\nans = \"\"\n\nob = b\nob -= 1\nfor x in range(a):\n if ob >9:\n ob -= 9\n ans = \"9\" + ans\n else:\n ans = str(ob) + ans\n ob = 0\n\nans = chr( ord(ans[0]) + 1) + ans[1:]\nprint(ans, big)\n\n\n", "passed": true, "time": 0.15, "memory": 14512.0, "status": "done"}, {"code": "n, s = map(int, input().split())\nif(n==1 and s==0):\n\tprint('0 0')\nelif(9*n < s or s == 0):\n\tprint('-1 -1')\nelse:\n\tres1 = 10**(n-1)\n\tfor i in range(s-1):\n\t\tres1 += 10**(i//9)\n\tres2 = 0\n\tfor i in range(s):\n\t\tres2 += 10**(n-1-i//9)\n\tprint(res1, res2)", "passed": true, "time": 0.29, "memory": 14344.0, "status": "done"}, {"code": "\n[m,s] = [int(s) for s in input().split()]\n\na = [0 for i in range(m)]\nb = [0 for i in range(m)]\n\nsa = s\ni = m-1\nwhile i>=0:\n if sa>9:\n a[i]=9\n sa = sa-9\n else:\n a[i]=sa\n sa = 0\n i -= 1\n\nfail = sa>0 \n\nif not fail:\n if m>1 and a[0]==0:\n a[0] = 1\n found = False\n for i in range(1,m):\n if a[i]>0:\n a[i] -= 1\n found = True\n break\n fail = not found\n\nif fail:\n print(-1,-1)\nelse:\n sb = s\n for i in range(m):\n if sb>9:\n b[i]=9\n sb = sb-9\n else:\n b[i]=sb\n sb = 0 \n\n print('{0} {1}'.format(''.join(map(str,a)),''.join(map(str,b))))\n\n\n \n## print(' '.join(map(str,A[i])))\n \n", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "def find(step):\n if m ==1 and s == 0:\n return 0\n ss = s\n res = ''\n for i in range(m):\n j = 1 if i == 0 else 0\n ok = False \n c = list(range(j, 10)) if step == -1 else reversed(list(range(j, 10))) \n for v in c:\n if 0 <= ss-v <= (m-i-1)*9:\n ok = True\n ss -= v\n res += str(v)\n break\n if not ok:\n return -1 \n return res\n\nm, s = list(map(int, input().split()))\nprint(find(-1), find(1))\n", "passed": true, "time": 0.15, "memory": 14604.0, "status": "done"}, {"code": "__author__ = 'alexandrun'\n\nimport sys\n\n#sys.stdin = open(\"p3.in\", \"r\")\n\ndef process(m, s):\n if s == 0:\n if m == 1:\n return (0, 0)\n return (-1, -1)\n\n q = s // 9\n r = s % 9\n if r == 0:\n cifMin = q\n else:\n cifMin = q + 1\n\n #print(q, r, cifMin)\n if cifMin > m:\n return(-1, -1)\n\n if cifMin == m:\n if r == 0:\n return (\"9\" * q, \"9\" * q)\n\n min = str(r) + \"9\" * q\n max = \"9\" * q + str(r)\n return (min, max)\n\n if cifMin < m:\n #min\n min = \"1\"\n qmin = (s-1) // 9\n rmin = (s-1) % 9\n\n if rmin == 0:\n cifMin2 = qmin\n else:\n cifMin2 = qmin + 1\n #print(qmin, rmin, cifMin2)\n\n if cifMin2 == m - 1:\n if rmin > 0:\n min += str(rmin) + \"9\" * qmin\n else:\n min += \"9\" * qmin\n elif cifMin2 < m - 1:\n #print(qmin, rmin)\n if rmin > 0:\n min += \"0\" * (-cifMin2 + m - 1) + str(rmin) + \"9\" * qmin\n else:\n min += \"0\" * (-cifMin2 + m - 1) + \"9\" * qmin\n\n max = \"9\" * q + str(r) + (m - q - 1) * \"0\"\n return(min, max)\n\nwords = input().split()\nm = int(words[0])\ns = int(words[1])\n\nres = process(m, s)\nprint(res[0], res[1])\n", "passed": true, "time": 1.74, "memory": 14548.0, "status": "done"}, {"code": "m, s = map(int, input().split())\nif s > m * 9:\n print(-1, -1)\nelif s == 0:\n if m == 1:\n print(0, 0)\n else:\n print(-1, -1)\nelse:\n pos = 0\n lost = s\n minAns = ''\n while (m - pos - 1) * 9 > lost:\n if pos == 0:\n minAns += '1'\n lost -= 1\n else:\n minAns += '0'\n pos += 1\n if 9 * (m - pos) == lost:\n minAns += '9' * (m - pos)\n else:\n minAns += str(lost % 9) + '9' * (m - pos - 1)\n \n print(minAns, end = ' ')\n \n maxAns = ''\n lost = s\n pos = 0\n while lost - 9 >= 0:\n maxAns += '9'\n pos += 1\n lost -= 9\n if m - pos > 0:\n maxAns += str(lost)\n maxAns += '0' * (m - pos - 1)\n \n print(maxAns)\n", "passed": true, "time": 0.18, "memory": 14404.0, "status": "done"}, {"code": "m, s = map(int, input().split())\n#for m in range(1, 100):\n# for s in range(1, 100):\n # print(\";;;;;;\", s, m)\nar = [0] * m\nar[0] = 1\nsum1 = 1\nif m == 1:\n if s > 9:\n print('-1 -1')\n else:\n print(s, s)\nelse:\n dd = 0\n for i in range(m - 1, 0, -1):\n if sum1 <= s:\n ar[i] += 9\n sum1 += 9\n if sum1 > s:\n ar[i] -= sum1 - s\n sum1 -= sum1 - s\n if sum1 < s:\n ar[0] += s - sum1\n if ar[0] > 9:\n dd = 1\n min1 = ar[:]\n sum1 = 0\n ar = [0] * m\n ar[0] = 0\n for i in range(m):\n if sum1 <= s:\n sum1 += 9\n ar[i] += 9\n if sum1 > s:\n ar[i] -= sum1 - s\n sum1 -= sum1 - s\n if sum1 < s or dd == 1 or ar[0] == 0 or min(min1) < 0:\n print('-1 -1')\n else:\n print(''.join(map(str, min1)), ''.join(map(str, ar)))", "passed": true, "time": 0.14, "memory": 14364.0, "status": "done"}, {"code": "from sys import stdin\n\nlines = list([_f for _f in stdin.read().split('\\n') if _f])\n\ndef parseline(line):\n\treturn list(map(int, line.split()))\n\nlines = list(map(parseline, lines))\n\nm, s = lines[0]\n\nif 9 * m < s or (m > 1 and s == 0):\n\tprint(\"-1 -1\")\n\treturn\n\nif m == 1 and s == 0:\n\tminimum = [0]\nelse:\n\tminimum = []\n\ts1 = s\n\twhile s1 > 0:\n\t\tdigit = min(9, s1)\n\t\tminimum.append(digit)\n\t\ts1 -= digit\n\tif len(minimum) < m:\n\t\tminimum[-1] -= 1\n\t\tminimum += [0] * (m - len(minimum) - 1)\n\t\tminimum.append(1)\n\nminimum = \"\".join(map(str, reversed(minimum)))\n\nmaximum = []\ns2 = s\nwhile s2 > 0:\n\tdigit = min(9, s2)\n\tmaximum.append(digit)\n\ts2 -= digit\nmaximum += [0] * (m - len(maximum))\n\nmaximum = \"\".join(map(str, maximum))\n\nprint(minimum, maximum)\n", "passed": true, "time": 0.16, "memory": 14464.0, "status": "done"}, {"code": "m,s=input().split()\nm,s=int(m),int(s)\nif 9*m<s or (s==0 and m!=1):\n print(-1,-1)\nelse:\n lis=[0 for i in range(m)]\n q=int(s//9)\n r=int(s%9)\n if s==0:\n print(0,0)\n elif m==1 and s==9:\n print(9,9)\n elif m==2 and s==18:\n print(99,99)\n elif q==m-1:\n for i in range(q):\n lis[i]='9'\n lis[m-1]=str(r)\n lis1=lis[:]\n if r!=0:\n print(int(''.join(lis[::-1])),int(''.join(lis)))\n else:\n print(int(''.join(['1','8']+lis[::-1][2:m])),int(''.join(lis1)))\n elif q<m-1:\n for i in range(q):\n lis[i]='9'\n lis[q]=str(r)\n for i in range(q+1,m):\n lis[i]='0'\n lis1=lis[:]\n if r!=0:\n lis[m-1]='1'\n lis[q]=str(r-1)\n print(int(''.join(lis[::-1])),int(''.join(lis1)))\n else:\n lis[m-1]='1'\n lis[q-1]='8'\n print(int(''.join(lis[::-1])),int(''.join(lis1)))\n else:\n for i in range(m):\n lis[i]='9'\n print(int(''.join(lis)),int(''.join(lis)))\n \n \n", "passed": true, "time": 0.21, "memory": 14504.0, "status": "done"}, {"code": "m, s = map(int, input().split())\nif m == 1 and s == 0:\n print(0, 0)\n return\nif (s == 0 and m > 1) or (s > m * 9):\n print(-1, -1)\nelse:\n n = (s - 1) // 9\n if n == m - 1:\n print(s - n * 9, '9' * n, sep = '', end = ' ')\n print('9' * n, s - n * 9, sep = '')\n else:\n print('1', '0' * (m - n - 2), s - n * 9 - 1, '9' * n, sep = '', end = ' ')\n print('9' * n, s - n * 9, '0' * (m - n - 1), sep = '')\n", "passed": true, "time": 0.14, "memory": 14596.0, "status": "done"}, {"code": "m, s = list(map(int, input().split()))\n\nmin_num = [0] * m\nif s == 0 and m == 1:\n print('0 0')\n return\nif s == 0 or s > m * 9:\n print(\"-1 -1\")\n return\n\nci = len(min_num) - 1\ns1 = s\nwhile s > 0:\n a = min(9, s)\n s -= a\n min_num[ci] = a\n\n ci -= 1\n\n\nif min_num[0] == 0:\n min_num[0] = 1\n for i in range(1, len(min_num)):\n if min_num[i] > 0:\n min_num[i] -= 1\n break\n\nmax_num = [0] * m\nci = 0\n\nwhile s1 > 0:\n a = 9 if s1 >= 9 else s1\n s1 -= a\n\n max_num[ci] = a\n\n ci += 1\n\nprint(\"\".join(map(str, min_num)), \"\".join(map(str, max_num)))\n\n\n", "passed": true, "time": 0.15, "memory": 14448.0, "status": "done"}, {"code": "__author__ = 'user'\n\nm, s = map(int, input().split())\n\nif s == 0 and m > 1 or s > 9 * m:\n min_num = max_num = -1\nelif m == 1:\n min_num = max_num = s\nelse:\n nns1 = s // 9\n d = s % 9\n max_num = '9' * nns1\n if nns1 != m:\n max_num += str(d) + '0' * (m - nns1 - 1)\n\n if s <= (m - 1) * 9:\n nns2 = (s - 1) // 9\n d = (s - 1) % 9\n min_num = '1' + '0' * (m - nns2 - 1 - 1)\n if nns2 != m:\n min_num += str(d) + '9' * nns2\n else:\n min_num = ''\n if s // 9 != m:\n min_num = str(s % 9)\n min_num += '9' * (s // 9)\n\n\nprint(min_num, max_num)", "passed": true, "time": 1.74, "memory": 14580.0, "status": "done"}, {"code": "__author__ = 'Rakshak.R.Hegde'\nm, s = map(int, input().split())\nif m == 1 and s == 0:\n print('0 0')\nelse:\n if s / m > 9 or s == 0:\n print('-1 -1')\n else:\n # Smallest Number\n num = [9] * m\n psum = 9 * m\n minDiff = min(8, psum - s)\n num[0] -= minDiff\n psum -= minDiff\n for i in range(1, m):\n minDiff = min(9, psum - s)\n num[i] -= minDiff\n psum -= minDiff\n if psum == s:\n break\n n1 = ''\n for i in num:\n n1 += str(i)\n # Biggest Number\n num = [9] * m\n psum = 9 * m\n for i in range(-1, -m - 1, -1):\n minDiff = min(9, psum - s)\n num[i] -= minDiff\n psum -= minDiff\n if psum == s:\n break\n n2 = ''\n for i in num:\n n2 += str(i)\n print(n1 + ' ' + n2)", "passed": true, "time": 0.21, "memory": 14324.0, "status": "done"}, {"code": "def solve(m, s):\n if (m, s) == (1,0):\n ret = \"0 0\"\n elif s > 9*m or s == 0:\n ret = \"-1 -1\"\n else:\n mxs = [1]+[0]*(m-1)\n mns = [1]+[0]*(m-1)\n i, j = -1, 0\n while s > 1:\n if mns[i] >= 9:\n i -= 1\n if mxs[j] >= 9:\n j += 1\n mns[i]+=1\n mxs[j]+=1\n s-=1\n ret = \"\".join(map(str, mns+[\" \"]+mxs))\n return ret\n\n \nm, s = map(int, input().split())\n\nprint(solve(m, s))", "passed": true, "time": 0.15, "memory": 14312.0, "status": "done"}, {"code": "__author__ = '1'\ndef minimize(m, s):\n if m == 1 and s == 0:\n return 0\n if s == 0:\n return -1\n array = [0 for i in range(m)]\n array[0] = 1\n\n currentFiller = m-1\n val = s-1\n for i in range(s-1):\n if array[currentFiller]<9:\n array[currentFiller]+=1;\n val-=1\n else:\n currentFiller-=1\n if currentFiller>=0:\n array[currentFiller]+=1\n val-=1\n else:\n break\n if val == 0:\n s = \"\"\n for i in range(len(array)):\n s+=str(array[i])\n return s\n else:\n return -1\n\n\ndef maximizeS(m, s):\n array = []\n for i in range(10**m):\n summ = 0\n st = str(i)\n for j in range(len(st)):\n summ+=ord(str(st[j])[0])-ord('0')\n if summ == s:\n array.append(i)\n array = sorted(array)\n if len(array)==0:\n return -1\n else:\n return array[-1]\n\ndef minimizeS(m, s):\n array = []\n for i in range(10**m):\n if len(str(i)) == m:\n summ = 0\n st = str(i)\n for j in range(len(st)):\n summ+=ord(str(st[j])[0])-ord('0')\n if summ == s:\n array.append(i)\n array = sorted(array)\n if len(array)==0:\n return -1\n else:\n return array[0]\n\ndef maximize(m, s):\n if m == 1 and s == 0:\n return 0\n if s == 0:\n return -1\n array = [0 for i in range(m)]\n array[0] = 1\n currentFiller = 0\n val = s-1\n for i in range(s-1):\n if array[currentFiller]<9:\n array[currentFiller]+=1;\n val-=1\n else:\n currentFiller+=1\n if currentFiller<m:\n array[currentFiller]+=1\n val-=1\n else:\n break\n if val == 0:\n s = \"\"\n for i in range(len(array)):\n s+=str(array[i])\n return s\n else:\n return -1\n\n\nfor m in range(1, 6):\n for s in range(6):\n \"\"\"\n if int(minimize(m, s)) != int(minimizeS(m, s)):\n print(m, s, minimize(m, s), minimizeS(m, s))\n if int(maximize(m, s)) != int(maximizeS(m, s)):\n print(m, s, maximize(m, s), maximizeS(m, s))\n \"\"\"\n pass\n\nm, s = list(map(int, input().split(' ')))\na = minimize(m, s)\nb = maximize(m, s)\nprint(a, b)\n", "passed": true, "time": 0.15, "memory": 14484.0, "status": "done"}, {"code": "a, b = list(map(int, input().split(' ')))\nif [a, b] == [1, 0]:\n print(\"0 0\")\nelse:\n if 1 <= b <= 9*a:\n haloe = []\n max9 = b // 9\n other = b % 9\n if other != 0:\n strx = '9' * max9 + str(other) + (a-max9-1) * '0'\n else:\n strx = '9' * max9 + (a-max9) * '0'\n haloe.append(strx)\n strx = strx[::-1]\n if strx[0] != '0':\n haloe.append(strx)\n else:\n bad = False\n newstr = '1'\n for i in range(1, len(strx)):\n if strx[i] != '0' and not bad:\n newstr += str(int(strx[i])-1)\n bad = not bad\n else:\n newstr += strx[i]\n haloe.append(newstr)\n print(haloe[1] + ' ' + haloe[0])\n \n else:\n print(-1, -1)\n", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "a, b = map(int, input().split(' '))\nif [a, b] == [1, 0]:\n print(\"0 0\")\nelse:\n if 1 <= b <= 9*a:\n haloe = []\n max9 = b // 9\n other = b % 9\n if other != 0:\n strx = '9' * max9 + str(other) + (a-max9-1) * '0'\n else:\n strx = '9' * max9 + (a-max9) * '0'\n haloe.append(strx)\n strx = strx[::-1]\n if strx[0] != '0':\n haloe.append(strx)\n else:\n bad = False\n newstr = '1'\n for i in range(1, len(strx)):\n if strx[i] != '0' and not bad:\n newstr += str(int(strx[i])-1)\n bad = not bad\n else:\n newstr += strx[i]\n haloe.append(newstr)\n print(haloe[1] + ' ' + haloe[0])\n \n else:\n print(-1, -1)", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "m, s = (int(x) for x in input().split())\nif s == 0:\n print('0 0' if m == 1 else '-1 -1')\nelif s > m * 9:\n print('-1 -1')\nelse:\n maxs = '9' * (s // 9) + (str(s % 9) if s % 9 else '') + '0' * (m - (s + 8) // 9)\n mins = maxs[::-1]\n if mins[0] == '0':\n nzi = mins.index(next(ch for ch in mins if ch != '0'))\n mins = '1' + mins[1:nzi] + str(int(mins[nzi]) - 1) + mins[nzi + 1:]\n print(mins, maxs)\n", "passed": true, "time": 0.15, "memory": 14512.0, "status": "done"}, {"code": "n,Sum=list(map(int,input().split()))\nif n==1 and Sum==0:\n print(0,0)\nelif Sum==0 or Sum>9*n:\n print(-1,-1)\nelse:\n l=[0]*n\n r=[0]*n\n b,p=\"\",\"\"\n s=Sum\n for i in range(n):\n if s>=9:\n r[i]=9\n s-=9\n else:\n r[i]=s\n s=0\n l[n-i-1]=r[i]\n if l[0]!=0:\n for i in range(n):\n b=b+str(l[i])\n p=p+str(r[i])\n print(b,p)\n else:\n for i in range(n):\n if l[i]!=0:\n break\n l[0]='1'\n l[i]=l[i]-1\n for i in range(n):\n b=b+str(l[i])\n p=p+str(r[i])\n print(b,p)\n", "passed": true, "time": 0.15, "memory": 14508.0, "status": "done"}]
[{"input": "2 15\n", "output": "69 96\n"}, {"input": "3 0\n", "output": "-1 -1\n"}, {"input": "2 1\n", "output": "10 10\n"}, {"input": "3 10\n", "output": "109 910\n"}, {"input": "100 100\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999999999 9999999999910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "1 900\n", "output": "-1 -1\n"}, {"input": "1 9\n", "output": "9 9\n"}, {"input": "1 0\n", "output": "0 0\n"}, {"input": "1 1\n", "output": "1 1\n"}, {"input": "1 2\n", "output": "2 2\n"}, {"input": "1 8\n", "output": "8 8\n"}, {"input": "1 10\n", "output": "-1 -1\n"}, {"input": "1 11\n", "output": "-1 -1\n"}, {"input": "2 0\n", "output": "-1 -1\n"}, {"input": "2 1\n", "output": "10 10\n"}, {"input": "2 2\n", "output": "11 20\n"}, {"input": "2 8\n", "output": "17 80\n"}, {"input": "2 10\n", "output": "19 91\n"}, {"input": "2 11\n", "output": "29 92\n"}, {"input": "2 16\n", "output": "79 97\n"}, {"input": "2 17\n", "output": "89 98\n"}, {"input": "2 18\n", "output": "99 99\n"}, {"input": "2 19\n", "output": "-1 -1\n"}, {"input": "2 20\n", "output": "-1 -1\n"}, {"input": "2 900\n", "output": "-1 -1\n"}, {"input": "3 1\n", "output": "100 100\n"}, {"input": "3 2\n", "output": "101 200\n"}, {"input": "3 3\n", "output": "102 300\n"}, {"input": "3 9\n", "output": "108 900\n"}, {"input": "3 10\n", "output": "109 910\n"}, {"input": "3 20\n", "output": "299 992\n"}, {"input": "3 21\n", "output": "399 993\n"}, {"input": "3 26\n", "output": "899 998\n"}, {"input": "3 27\n", "output": "999 999\n"}, {"input": "3 28\n", "output": "-1 -1\n"}, {"input": "3 100\n", "output": "-1 -1\n"}, {"input": "100 0\n", "output": "-1 -1\n"}, {"input": "100 1\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "100 2\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "100 9\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008 9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "100 10\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009 9100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "100 11\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019 9200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "100 296\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999999999999 9999999999999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "100 297\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000899999999999999999999999999999999 9999999999999999999999999999999990000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "100 298\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000999999999999999999999999999999999 9999999999999999999999999999999991000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "100 299\n", "output": "1000000000000000000000000000000000000000000000000000000000000000001999999999999999999999999999999999 9999999999999999999999999999999992000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "100 300\n", "output": "1000000000000000000000000000000000000000000000000000000000000000002999999999999999999999999999999999 9999999999999999999999999999999993000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "100 301\n", "output": "1000000000000000000000000000000000000000000000000000000000000000003999999999999999999999999999999999 9999999999999999999999999999999994000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "100 895\n", "output": "4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999994\n"}, {"input": "100 896\n", "output": "5999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995\n"}, {"input": "100 897\n", "output": "6999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996\n"}, {"input": "100 898\n", "output": "7999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999997\n"}, {"input": "100 899\n", "output": "8999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998\n"}, {"input": "100 900\n", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n"}, {"input": "99 900\n", "output": "-1 -1\n"}, {"input": "99 891\n", "output": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n"}, {"input": "99 892\n", "output": "-1 -1\n"}, {"input": "96 364\n", "output": "100000000000000000000000000000000000000000000000000000039999999999999999999999999999999999999999 999999999999999999999999999999999999999940000000000000000000000000000000000000000000000000000000\n"}, {"input": "97 206\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000079999999999999999999999 9999999999999999999999800000000000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "98 250\n", "output": "10000000000000000000000000000000000000000000000000000000000000000000006999999999999999999999999999 99999999999999999999999999970000000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "99 96\n", "output": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000059999999999 999999999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "100 215\n", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999 9999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000000000000\n"}, {"input": "5 18\n", "output": "10089 99000\n"}, {"input": "2 19\n", "output": "-1 -1\n"}, {"input": "3 3\n", "output": "102 300\n"}]
267
You are given two integers $l$ and $r$ ($l \le r$). Your task is to calculate the sum of numbers from $l$ to $r$ (including $l$ and $r$) such that each number contains at most $k$ different digits, and print this sum modulo $998244353$. For example, if $k = 1$ then you have to calculate all numbers from $l$ to $r$ such that each number is formed using only one digit. For $l = 10, r = 50$ the answer is $11 + 22 + 33 + 44 = 110$. -----Input----- The only line of the input contains three integers $l$, $r$ and $k$ ($1 \le l \le r < 10^{18}, 1 \le k \le 10$) β€” the borders of the segment and the maximum number of different digits. -----Output----- Print one integer β€” the sum of numbers from $l$ to $r$ such that each number contains at most $k$ different digits, modulo $998244353$. -----Examples----- Input 10 50 2 Output 1230 Input 1 2345 10 Output 2750685 Input 101 154 2 Output 2189 -----Note----- For the first example the answer is just the sum of numbers from $l$ to $r$ which equals to $\frac{50 \cdot 51}{2} - \frac{9 \cdot 10}{2} = 1230$. This example also explained in the problem statement but for $k = 1$. For the second example the answer is just the sum of numbers from $l$ to $r$ which equals to $\frac{2345 \cdot 2346}{2} = 2750685$. For the third example the answer is $101 + 110 + 111 + 112 + 113 + 114 + 115 + 116 + 117 + 118 + 119 + 121 + 122 + 131 + 133 + 141 + 144 + 151 = 2189$.
interview
[{"code": "\n\n\nl, r, k =list(map(int,input().split()))\n\nd = {i:2**i for i in range(10)}\n\ncache = {}\n\ndef can(i, m):\n return d[i] & m\n\ndef calc(m):\n b = 1\n c = 0\n for i in range(10):\n if b & m:\n c += 1\n b *= 2\n\n return c\n\ndef sm(ln, k, m, s='', first=False):\n if ln < 1:\n return 0, 1\n\n if (ln, k, m, s, first) in cache:\n return cache[(ln, k, m, s, first)]\n\n ans = 0\n count = 0\n base = 10 ** (ln-1)\n\n use_new = calc(m) < k\n\n if s:\n finish = int(s[0])+1\n else:\n finish = 10\n\n for i in range(finish):\n if use_new or can(i, m):\n ss = s[1:]\n if i != finish-1:\n ss = ''\n nm = m | d[i]\n nfirst = False\n if i == 0 and first:\n nm = m\n nfirst = True\n nexta, nextc = sm(ln-1, k, nm, ss, nfirst)\n ans += base * i * nextc + nexta\n count += nextc\n\n# print(ln, k, m, s, first, ans, count)\n cache[(ln, k, m, s, first)] = (ans, count)\n\n return ans, count\n\ndef call(a, k):\n s = str(a)\n return sm(len(s), k, 0, s, True)[0]\n\n\n#print(call(r, k) - call(l-1, k))\nprint((call(r, k) - call(l-1, k)) % 998244353)\n", "passed": true, "time": 3.53, "memory": 121220.0, "status": "done"}, {"code": "\nMOD = 998244353\n\n\ndef pop_count(x) :\n ans = 0\n while (x > 0) :\n ans = ans + x % 2\n x = x // 2\n return ans\n\ndef check(x, k) :\n mask = 0\n nx = int(x)\n while (nx > 0) :\n mask = mask | (1 << (nx % 10))\n nx = nx // 10\n if (pop_count(mask) <= k) :\n return x\n return 0\n\npop = []\np10 = []\nf = [[0 for j in range(1 << 10)] for i in range(20)]\nw = [[0 for j in range(1 << 10)] for i in range(20)]\ndef prepare() : \n p10.append(1)\n for i in range(20) :\n p10.append(p10[i] * 10 % MOD)\n for i in range(1 << 10) :\n pop.append(pop_count(i))\n w[0][0] = 1\n for i in range(1, 20) :\n for j in range(1 << 10) :\n for use in range(10) : \n w[i][j | (1 << use)] = (w[i][j | (1 << use)] + w[i - 1][j]) % MOD\n f[i][j | (1 << use)] = (f[i][j | (1 << use)] + w[i - 1][j] * use * p10[i - 1] + f[i - 1][j]) % MOD\n\ndef solve(x, k) :\n sx = [int(d) for d in str(x)] \n n = len(sx) \n ans = 0\n for i in range(1, n) :\n for use in range(1, 10) :\n for mask in range(1 << 10) : \n if (pop[(1 << use) | mask] <= k) :\n ans = (ans + f[i - 1][mask] + use * w[i - 1][mask] % MOD * p10[i - 1]) % MOD\n cmask = 0\n csum = 0\n for i in range(n) :\n cdig = sx[i]\n for use in range(cdig) : \n if (i == 0 and use == 0) :\n continue\n nmask = cmask | (1 << use)\n for mask in range(1 << 10) : \n if (pop[nmask | mask] <= k) :\n ans = (ans + f[n - i - 1][mask] + (csum * 10 + use) * w[n - i - 1][mask] % MOD * p10[n - i - 1]) % MOD\n cmask |= 1 << cdig\n csum = (10 * csum + cdig) % MOD\n return ans\n\nprepare()\nl, r, k = list(map(int, input().split()))\nans = (check(r, k) + solve(r, k) - solve(l, k) + MOD) % MOD\nprint(ans)\n \n", "passed": true, "time": 17.11, "memory": 14664.0, "status": "done"}]
[{"input": "10 50 2\n", "output": "1230\n"}, {"input": "1 2345 10\n", "output": "2750685\n"}, {"input": "101 154 2\n", "output": "2189\n"}, {"input": "427896435961371452 630581697708338740 1\n", "output": "716070897\n"}, {"input": "631407936591454868 864125387239952999 1\n", "output": "36080276\n"}, {"input": "1395 6977 1\n", "output": "22220\n"}, {"input": "1 999999999999999999 1\n", "output": "983438501\n"}, {"input": "99999999999999999 999999999999999999 1\n", "output": "58281903\n"}, {"input": "266540997167959147 266540997168158399 1\n", "output": "0\n"}, {"input": "39103072800020527 149197464503937853 2\n", "output": "652117623\n"}, {"input": "150023703387053981 698704065228345187 2\n", "output": "359774681\n"}, {"input": "2115 5821 2\n", "output": "953555\n"}, {"input": "1 999999999999999999 2\n", "output": "5400611\n"}, {"input": "99999999999999999 999999999999999999 2\n", "output": "425213690\n"}, {"input": "267367244641009867 267367244641757963 2\n", "output": "0\n"}, {"input": "873681750788412714 891185268154312782 3\n", "output": "662001527\n"}, {"input": "309910710656928853 892011507037428910 3\n", "output": "463439289\n"}, {"input": "4666 8243 3\n", "output": "11278019\n"}, {"input": "1 999999999999999999 3\n", "output": "885414096\n"}, {"input": "99999999999999999 999999999999999999 3\n", "output": "193997641\n"}, {"input": "268193483524125995 268193483524390232 3\n", "output": "0\n"}, {"input": "409801034949911895 708260424481837606 4\n", "output": "346722484\n"}, {"input": "144489384350353745 410627273833028023 4\n", "output": "315972011\n"}, {"input": "3510 4371 4\n", "output": "3396711\n"}, {"input": "1 999999999999999999 4\n", "output": "91933959\n"}, {"input": "99999999999999999 999999999999999999 4\n", "output": "538106038\n"}, {"input": "269019726702209419 269019726703022500 4\n", "output": "0\n"}, {"input": "542839106765197089 928416801745511006 5\n", "output": "922721676\n"}, {"input": "929243044923594430 979068062338745932 5\n", "output": "615230478\n"}, {"input": "2354 7795 5\n", "output": "27615429\n"}, {"input": "1 999999999999999999 5\n", "output": "787554016\n"}, {"input": "99999999999999999 999999999999999999 5\n", "output": "826894420\n"}, {"input": "269845965585325547 269845965585654768 5\n", "output": "0\n"}, {"input": "377417784753589277 670404605395885936 6\n", "output": "68887051\n"}, {"input": "671230848573969360 813646736032170824 6\n", "output": "931406488\n"}, {"input": "1199 1219 6\n", "output": "25389\n"}, {"input": "1 999999999999999999 6\n", "output": "662023136\n"}, {"input": "99999999999999999 999999999999999999 6\n", "output": "864210218\n"}, {"input": "270672213058376267 270672213059287037 6\n", "output": "0\n"}, {"input": "189020376486452345 988624421592238351 7\n", "output": "925283456\n"}, {"input": "189846615369568473 648225414020563011 7\n", "output": "682259668\n"}, {"input": "3147 4644 7\n", "output": "5835459\n"}, {"input": "1 999999999999999999 7\n", "output": "488500709\n"}, {"input": "99999999999999999 999999999999999999 7\n", "output": "248180658\n"}, {"input": "271498451941492395 271498451941727817 7\n", "output": "476834003\n"}, {"input": "707636143282051457 823203099580630539 8\n", "output": "214464109\n"}, {"input": "259432050859212086 708462382165167585 8\n", "output": "917376096\n"}, {"input": "772 1991 8\n", "output": "1685430\n"}, {"input": "1 999999999999999999 8\n", "output": "966886744\n"}, {"input": "99999999999999999 999999999999999999 8\n", "output": "113971493\n"}, {"input": "272324690824608523 272324690825360086 8\n", "output": "980039966\n"}, {"input": "226251910077650569 657781773274055430 9\n", "output": "483661761\n"}, {"input": "94010733142571570 227078148960766697 9\n", "output": "931911077\n"}, {"input": "836 4196 9\n", "output": "8456276\n"}, {"input": "1 999999999999999999 9\n", "output": "897567189\n"}, {"input": "99999999999999999 999999999999999999 9\n", "output": "206378688\n"}, {"input": "273150934002691947 273150934002992354 9\n", "output": "863888810\n"}, {"input": "299877849271027626 687486864689028806 10\n", "output": "285886436\n"}, {"input": "688313103572144934 736106804844576469 10\n", "output": "26341059\n"}, {"input": "2001 3111 10\n", "output": "2839716\n"}, {"input": "1 999999999999999999 10\n", "output": "357607302\n"}, {"input": "99999999999999999 999999999999999999 10\n", "output": "228265307\n"}, {"input": "996517375802030519 996517375802227037 10\n", "output": "795592963\n"}, {"input": "999999999999999999 999999999999999999 1\n", "output": "716070897\n"}, {"input": "999999999999999999 999999999999999999 10\n", "output": "716070897\n"}]
268
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a_1, a_2, ..., a_{n} of n integer numbers β€” saturation of the color of each pencil. Now Mishka wants to put all the mess in the pack in order. He has an infinite number of empty boxes to do this. He would like to fill some boxes in such a way that: Each pencil belongs to exactly one box; Each non-empty box has at least k pencils in it; If pencils i and j belong to the same box, then |a_{i} - a_{j}| ≀ d, where |x| means absolute value of x. Note that the opposite is optional, there can be pencils i and j such that |a_{i} - a_{j}| ≀ d and they belong to different boxes. Help Mishka to determine if it's possible to distribute all the pencils into boxes. Print "YES" if there exists such a distribution. Otherwise print "NO". -----Input----- The first line contains three integer numbers n, k and d (1 ≀ k ≀ n ≀ 5Β·10^5, 0 ≀ d ≀ 10^9) β€” the number of pencils, minimal size of any non-empty box and maximal difference in saturation between any pair of pencils in the same box, respectively. The second line contains n integer numbers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9) β€” saturation of color of each pencil. -----Output----- Print "YES" if it's possible to distribute all the pencils into boxes and satisfy all the conditions. Otherwise print "NO". -----Examples----- Input 6 3 10 7 2 7 7 4 2 Output YES Input 6 2 3 4 5 3 13 4 10 Output YES Input 3 2 5 10 16 22 Output NO -----Note----- In the first example it is possible to distribute pencils into 2 boxes with 3 pencils in each with any distribution. And you also can put all the pencils into the same box, difference of any pair in it won't exceed 10. In the second example you can split pencils of saturations [4, 5, 3, 4] into 2 boxes of size 2 and put the remaining ones into another box.
interview
[{"code": "#!/usr/bin/env python3\n\nfrom bisect import bisect\n\n[n, k, d] = list(map(int, input().strip().split()))\nais = list(map(int, input().strip().split()))\nif k == 1:\n\tprint ('YES')\n\treturn\n\nais.sort()\n\n# can do ais[i:]\ncando = [False for _ in range(n)]\nj = n - 1 # j is such that a[j] > a[i] + d >= a[j - 1] (upper_bound) a[:j] <= a[i] + d < a[j:]\ncount = 0 # sum(cando[i + k:j + 1])\nfor i in reversed(list(range(n))):\n\tif i + k < n and cando[i + k]:\n\t\tcount += 1\n\tif n - i < k:\n\t\tcontinue\n\tif ais[-1] - ais[i] <= d:\n\t\tcando[i] = True\n\t\tcontinue\n\twhile ais[j - 1] > ais[i] + d:\n\t\tif cando[j]:\n\t\t\tcount -= 1\n\t\tj -= 1\n\tcando[i] = (count > 0)\n\t\n\nif cando[0]:\n\tprint ('YES')\nelse:\n\tprint ('NO')\n\n", "passed": true, "time": 0.79, "memory": 14468.0, "status": "done"}, {"code": "from bisect import bisect_right, bisect_left\n\n\ndef main():\n n, k, d = map(int, input().split())\n sat = [int(x) for x in input().split()]\n\n sat = sorted(sat)\n arrange = [False for _ in range(n + 1)]\n arrange[0] = True\n s = 0\n # i means the first i items could be arranged well\n i = min(bisect_right(sat, sat[s] + d), k)\n n_arrange = 1 if i - k >= 0 else 0 # arrange[0] == True | the first 0 items\n\n while i <= n:\n if i - s >= k and n_arrange > 0:\n arrange[i] = True\n if i < n:\n news = bisect_left(sat, sat[i] - d, s, i)\n while s < news:\n if s <= i - k and arrange[s]:\n n_arrange -= 1\n s += 1\n\n i += 1\n n_arrange += 1 if (i - k >= s and arrange[i - k]) else 0\n\n if arrange[n]:\n print('YES')\n else:\n print('NO')\n\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.25, "memory": 14404.0, "status": "done"}, {"code": "from bisect import bisect_right, bisect_left\n\n\ndef main():\n n, k, d = list(map(int, input().split()))\n sat = [int(x) for x in input().split()]\n\n sat = sorted(sat)\n\n # arrange[i] means the first i items could be arranged well\n # arranged well means they could be put into boxes without conflicts\n arrange = [True] + [False for _ in range(n)]\n\n s = 0\n\n # we can put [0, i) items into the first box\n i = min(bisect_right(sat, sat[s] + d), k)\n\n # keep the number of True-value in arrange[s, i-k]\n # there must be at least one point in [s, i-k(included)] which satisfies arrange[this_point] == True\n # that means we can cut from this_point and put [this_point, i) in a new box\n # then the result is arrange[i] become True, because now all items before i-index could be arranged well\n n_arrange = 1 if s <= i - k else 0\n\n while i <= n:\n if i - s >= k and n_arrange > 0:\n arrange[i] = True\n if i < n:\n # find new s that we could put | item at new s - item at i | <= d\n news = bisect_left(sat, sat[i] - d, s, i)\n while s < news:\n if s <= i - k and arrange[s]:\n n_arrange -= 1\n s += 1\n\n i += 1\n # every time when you count arrange[x] you should keep x between [s, i-k]\n n_arrange += 1 if (s <= i - k and arrange[i - k]) else 0\n\n if arrange[n]:\n print('YES')\n else:\n print('NO')\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "import bisect;\ndef getIntList():\n return list(map(int, input().split()));\ndef getTransIntList(n):\n first=getIntList();\n m=len(first);\n result=[[0]*n for _ in range(m)];\n for i in range(m):\n result[i][0]=first[i];\n for j in range(1, n):\n curr=getIntList();\n for i in range(m):\n result[i][j]=curr[i];\n return result;\nn, k, d = getIntList()\na= getIntList();\na.sort();\nseen=[False]*len(a);\ndef search(a, lowLim):\n sameLim=bisect.bisect_right(a, a[lowLim]+d);\n lowLim=max(lowLim, sameLim-2*k);\n if seen[lowLim]:\n return False;\n if len(a)-lowLim<k:\n return False;\n if a[len(a)-1]-a[lowLim]<=d:\n return True;\n for i in range(lowLim+k-1, len(a)-1):\n if a[i]-a[lowLim]>d:\n break;\n if search(a, i+1):\n return True;\n seen[lowLim]=True;\n return False;\ndef searchFull(a):\n if a[n-1]-a[n-k]>d:\n return False;\n return search(a, 0);\nif k==1:\n print('YES')\nelif searchFull(a):\n print('YES')\nelse:\n print('NO');", "passed": true, "time": 0.15, "memory": 14448.0, "status": "done"}, {"code": "import bisect;\ndef getIntList():\n return list(map(int, input().split()));\ndef getTransIntList(n):\n first=getIntList();\n m=len(first);\n result=[[0]*n for _ in range(m)];\n for i in range(m):\n result[i][0]=first[i];\n for j in range(1, n):\n curr=getIntList();\n for i in range(m):\n result[i][j]=curr[i];\n return result;\nn, k, d = getIntList()\na= getIntList();\na.sort();\n#\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0440\u0435\u0437\u0430\u0442\u044c \u043e\u0442\u0440\u0435\u0437\u043e\u043a \u0434\u043e j \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e - cuttable[j];\ncuttable=[False]*len(a);\ncuttable[0]=True;\ndef search(a):\n curr=0;\n maxOne=0;\n while True:\n #print(curr);\n if cuttable[curr]:\n #\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0434\u0440\u0435\u0437\u043e\u043a \u0434\u043b\u0438\u043d\u044b \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c k: [curr, curr+k)\n lowLim=curr+k;\n #\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 upLim, \u0447\u0442\u043e a[upLim]-a[curr]>d;\n upLim=bisect.bisect_right(a, a[curr]+d);\n #\u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0435\u0442, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e\n if upLim==len(a):\n return True;\n #\u0421\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0434\u0438\u043d\u0438\u0447\u043a\u0438 \u043d\u0430 \u0443\u0436\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u044b\u0439 \u043e\u0442\u0440\u0435\u0437\u043e\u043a \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u043e\n lowLim=max(lowLim, maxOne+1);\n #print('cuttable', lowLim, upLim);\n #a[upLim-1]-a[curr]<=d, \u0437\u043d\u0430\u0447\u0438\u0442 cuttable[upLim]=True;\n for i in range(lowLim, upLim+1):\n cuttable[i]=True;\n maxOne=upLim;\n curr+=1;\n if curr>len(a)-k:\n break;\n return False;\nif k==1:\n print('YES')\nelif search(a):\n print('YES')\nelse:\n print('NO');", "passed": true, "time": 0.24, "memory": 14576.0, "status": "done"}, {"code": "def getIntList():\n return list(map(int, input().split()));\ndef getTransIntList(n):\n first=getIntList();\n m=len(first);\n result=[[0]*n for _ in range(m)];\n for i in range(m):\n result[i][0]=first[i];\n for j in range(1, n):\n curr=getIntList();\n for i in range(m):\n result[i][j]=curr[i];\n return result;\nn, k, d = getIntList()\na= getIntList();\na.sort();\n#\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0440\u0435\u0437\u0430\u0442\u044c \u043e\u0442\u0440\u0435\u0437\u043e\u043a \u0434\u043e j \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e - cuttable[j];\ncuttable=[False]*len(a);\ncuttable[0]=True;\ndef search(a):\n curr=0;\n upLim=0;\n upLimPrev=0;\n while True:\n #print(curr);\n if cuttable[curr]:\n #\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0434\u0440\u0435\u0437\u043e\u043a \u0434\u043b\u0438\u043d\u044b \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c k: [curr, curr+k)\n lowLim=curr+k;\n upLimPrev = upLim;\n #\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 upLim, \u0447\u0442\u043e a[upLim]-a[curr]>d;\n while upLim<len(a) and a[upLim]-a[curr]<=d:\n upLim+=1;\n #\u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043d\u0435\u0442, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u043e\n if upLim==len(a):\n return True;\n #\u0421\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0434\u0438\u043d\u0438\u0447\u043a\u0438 \u043d\u0430 \u0443\u0436\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u043d\u044b\u0439 \u043e\u0442\u0440\u0435\u0437\u043e\u043a \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u043e\n lowLim=max(lowLim, upLimPrev+1);\n #print('cuttable', lowLim, upLim);\n #a[upLim-1]-a[curr]<=d, \u0437\u043d\u0430\u0447\u0438\u0442 cuttable[upLim]=True;\n for i in range(lowLim, upLim+1):\n cuttable[i]=True;\n curr+=1;\n if curr>len(a)-k:\n break;\n return False;\nif k==1:\n print('YES')\nelif search(a):\n print('YES')\nelse:\n print('NO');", "passed": true, "time": 0.15, "memory": 14616.0, "status": "done"}, {"code": "from bisect import bisect\n\n\ndef main():\n n, k, d = list(map(int, input().split()))\n if k == 1:\n print('YES')\n return\n l = []\n ll = [l]\n a = 10 ** 10\n for b in sorted(map(int, input().split())):\n if a < b:\n if len(l) < k:\n print('NO')\n return\n l = [b]\n ll.append(l)\n else:\n l.append(b)\n a = b + d\n\n def f(a):\n def dfs(i):\n avail[i] = False\n if i + k <= le:\n if a[-1] <= a[i] + d:\n raise TabError\n j = bisect(a, a[i] + d, i, -1) - 1\n for j in range(bisect(a, a[i] + d, i, -1), i + k - 1, -1):\n if avail[j]:\n dfs(j)\n\n le = len(a)\n avail = [True] * le\n try:\n dfs(0)\n except TabError:\n return True\n return False\n\n print(('NO', 'YES')[all(map(f, ll))])\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.25, "memory": 14576.0, "status": "done"}, {"code": "n, k, d = list(map(int, input().split()))\na = sorted(list(map(int, input().split())))\nb = [0] * n\ni = j = 0\nfor i in range(n):\n while a[i] - a[j] > d:\n j += 1\n b[i] = j\nc = [0] * n\n# d = [0] * n\nfor i in range(k - 1, n):\n # print(f'i={i}, b[i]={b[i]}, i-b[i]+1={i - b[i] + 1}, i-k={i-k}, c[i-k]={c[i-k]}, c[b[i]]={c[b[i]]}')\n # print(i - k, b[i] - 2)\n if i - b[i] + 1 >= k and (b[i] == 0 or c[i - k] > c[b[i] - 2] or (b[i] == 1 and c[i-k]> c[0])):\n c[i] = c[i - 1] + 1\n # d[i] = 1\n else:\n c[i] = c[i - 1]\n# print(a)\n# print(b)\n# print(d)\n# print(c)\nprint('YES' if n < 2 or c[n - 1] > c[n - 2] else 'NO')", "passed": true, "time": 0.16, "memory": 14320.0, "status": "done"}, {"code": "n, k, d = list(map(int, input().split()))\na = sorted(list(map(int, input().split())))\nb = [0] * n\ni = j = 0\nfor i in range(n):\n while a[i] - a[j] > d:\n j += 1\n b[i] = j\nc = [0] * n\nfor i in range(k - 1, n):\n c[i] = c[i - 1] + int(i - b[i] + 1 >= k and (b[i] == 0 or c[i - k] > c[b[i] - 2] or (b[i] == 1 and c[i-k]> c[0])))\nprint('YES' if n < 2 or c[n - 1] > c[n - 2] else 'NO')", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}, {"code": "n,k,d=list(map(int,input().split()))\na=sorted(list(map(int,input().split())))\nb=[0]*n\ni=j=0\nfor i in range(n):\n while a[i]-a[j]>d:j+=1\n b[i]=j\nc=[0]*n\nfor i in range(k-1,n):c[i]=c[i-1]+int(i-b[i]+1>=k and (b[i]==0 or c[i-k]>c[b[i]-2] or (b[i]==1 and c[i-k]>c[0])))\nprint('YES' if n<2 or c[n-1]>c[n-2] else 'NO')", "passed": true, "time": 0.15, "memory": 14484.0, "status": "done"}, {"code": "#Bhargey Mehta (Junior)\n#DA-IICT, Gandhinagar\nimport sys, math, queue\n#sys.stdin = open('input.txt', 'r')\nMOD = 998244353\nsys.setrecursionlimit(1000000)\n\ndef check(i):\n if not dp[i][2]: return False\n if i < 0: return True\n return check(i-dp[i][1])\n \nn, k, d = map(int, input().split())\nif k == 1:\n print('YES')\n return\na = sorted(map(int, input().split()))\ndp = [None for i in range(n)]\ndp[0] = (a[0], 1, False)\nfor i in range(1, n):\n if a[i]-dp[i-1][0] <= d:\n dp[i] = (dp[i-1][0], dp[i-1][1]+1, dp[i-1][1]+1 >= k)\n else:\n dp[i] = (a[i], 1, False)\n j = i\n while a[i]-a[j] <= d and j > 0:\n j -= 1\n if dp[j][2]:\n dp[i] = (a[j+1], i-j, i-j >= k)\n if dp[i][2]: break\nprint('YES' if check(n-1) else 'NO')", "passed": true, "time": 0.15, "memory": 14668.0, "status": "done"}, {"code": "def bi_search(a, x):\n n = len(a)\n u, l = n, -1\n \n while u-l>1:\n md=(u+l)//2\n \n if x>a[md]:\n l=md\n else:\n u=md\n \n return u \n\nclass Bit():\n # index-1\n def __init__(self, n):\n self.bit = [0] * (n+1) \n self.n = n\n \n # sum[1, i]\n def sum_prefix(self, i):\n s = 0\n while i > 0:\n s += self.bit[i]\n i -= i&(-i)\n return s\n \n # sum[l, r] \n def sum_(self, l, r):\n if l == 1:\n return self.sum_prefix(r)\n return self.sum_prefix(r) - self.sum_prefix(l-1) \n \n def add(self, i, x):\n while i <= self.n:\n self.bit[i] += x\n i += i&(-i)\n\nn, k, d = map(int, input().split())\na = [-1] + list(map(int, input().split()))\na = sorted(a)\n\nB=Bit(n) \nans=[-1] * n \n\nfor i in range(n+1):\n if i==0:\n continue\n \n pos = bi_search(a, max(0, a[i]-d)) #pos, i-k+1..,i-1,i\n \n l, r = pos-1, i-k\n \n if l<=r:\n s=0\n \n if l>=1:\n s+=B.sum_(l, r)\n \n if l==0 or s > 0:\n B.add(i, 1)\n ans[i-1]=1\n \nif ans[-1]==1:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.15, "memory": 14612.0, "status": "done"}, {"code": "def main():\n import sys\n from bisect import bisect_left\n input = sys.stdin.readline\n\n N, K, D = list(map(int, input().split()))\n A = list(map(int, input().split()))\n A.sort()\n\n part = [0] * (N+2)\n part[0] = 1\n part[1] = -1\n for i, a in enumerate(A):\n part[i] += part[i-1]\n if part[i]:\n j = bisect_left(A, a+D+1)\n if j >= i+K:\n part[i+K] += 1\n part[j+1] -= 1\n part[N] += part[N-1]\n if part[N]:\n print('YES')\n else:\n print('NO')\n #print(A)\n #print(part)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.2, "memory": 14380.0, "status": "done"}, {"code": "import bisect\nimport sys\ninput = sys.stdin.readline\n\n\nclass SegmentTree():\n def __init__(self, n, op, e):\n self.n = n\n self.op = op\n self.e = e\n self.size = 2 ** ((n - 1).bit_length())\n self.node = [self.e] * (2 * self.size)\n\n def built(self, array):\n for i in range(self.n):\n self.node[self.size + i] = array[i]\n for i in range(self.size - 1, 0, -1):\n self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])\n\n def update(self, i, val):\n i += self.size\n self.node[i] = val\n while i > 1:\n i >>= 1\n self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])\n\n def get_val(self, l, r):\n l, r = l + self.size, r + self.size\n res_l, res_r = self.e, self.e\n while l < r:\n if l & 1:\n res_l = self.op(res_l, self.node[l])\n l += 1\n if r & 1:\n r -= 1\n res_r = self.op(self.node[r], res_r)\n l, r = l >> 1, r >> 1\n return self.op(res_l, res_r)\n\n\nn, k, d = map(int, input().split())\na = list(map(int, input().split()))\na = sorted(a)\n\nst = SegmentTree(n + 1, lambda a, b : a | b, 0)\nst.update(0, 1)\nfor i in range(n):\n tmp = bisect.bisect_left(a, a[i] - d)\n if tmp >= max(i + 2 - k, 0):\n continue\n st.update(i + 1, st.get_val(tmp, max(i + 2 - k, 0)))\n\nif st.get_val(n, n + 1) == 1:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.15, "memory": 14684.0, "status": "done"}, {"code": "import sys\nreadline = sys.stdin.readline\n\nclass Segtree:\n def __init__(self, A, intv, initialize = True, segf = max):\n self.N = len(A)\n self.N0 = 2**(self.N-1).bit_length()\n self.intv = intv\n self.segf = segf\n if initialize:\n self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)\n for i in range(self.N0-1, 0, -1):\n self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) \n else:\n self.data = [intv]*(2*self.N0)\n \n def update(self, k, x):\n k += self.N0\n self.data[k] = x\n while k > 0 :\n k = k >> 1\n self.data[k] = self.segf(self.data[2*k], self.data[2*k+1])\n \n def query(self, l, r):\n L, R = l+self.N0, r+self.N0\n s = self.intv\n while L < R:\n if R & 1:\n R -= 1\n s = self.segf(s, self.data[R])\n if L & 1:\n s = self.segf(s, self.data[L])\n L += 1\n L >>= 1\n R >>= 1\n return s\n \n def binsearch(self, l, r, check, reverse = False):\n L, R = l+self.N0, r+self.N0\n SL, SR = [], []\n while L < R:\n if R & 1:\n R -= 1\n SR.append(R)\n if L & 1:\n SL.append(L)\n L += 1\n L >>= 1\n R >>= 1\n \n if reverse:\n for idx in (SR + SL[::-1]):\n if check(self.data[idx]):\n break\n else:\n return -1\n while idx < self.N0:\n if check(self.data[2*idx+1]):\n idx = 2*idx + 1\n else:\n idx = 2*idx\n return idx - self.N0\n else:\n for idx in (SL + SR[::-1]):\n if check(self.data[idx]):\n break\n else:\n return -1\n while idx < self.N0:\n if check(self.data[2*idx]):\n idx = 2*idx\n else:\n idx = 2*idx + 1\n return idx - self.N0\n\nN, K, D = list(map(int, readline().split()))\nA = list(map(int, readline().split()))\nA.sort()\nlm = [None]*N\nfor i in range(N):\n a = A[i]\n ok = i\n ng = -1\n while abs(ok-ng) > 1:\n med = (ok+ng)//2\n if a-A[med] <= D:\n ok = med\n else:\n ng = med\n lm[i] = ok\n\nT = Segtree([None]*(N+1), 0, initialize = False, segf = max)\nT.update(0, 1)\nfor i in range(N):\n rm = i-K+2\n if rm <= lm[i]:\n continue\n if T.query(lm[i], rm):\n T.update(i+1, 1)\n\nprint('YES' if T.query(N, N+1) else 'NO')\n\n", "passed": true, "time": 0.14, "memory": 14628.0, "status": "done"}, {"code": "import heapq\n\ndef run():\n n, k, d = list(map(int, input().split()))\n a = sorted(map(int, input().split()))\n\n max_size = [None] * n # how many pencils can be in box starting with this one\n start = 0\n end = 0\n while start < n:\n while end < n-1 and a[end+1] - a[start] <= d:\n end += 1\n max_size[start] = end - start + 1\n start += 1\n\n possilbe_starts = []\n # heap with starts and stops of intervals where new box can start\n # - all pencils before that are successfully boxed\n heapq.heappush(possilbe_starts, (0, \"start\"))\n heapq.heappush(possilbe_starts, (1, \"stop\"))\n\n number_of_opened = 0 # number of opened intervals\n\n for pencil in range(n):\n while possilbe_starts and possilbe_starts[0][0] <= pencil:\n top = heapq.heappop(possilbe_starts)\n number_of_opened += (1 if top[1] == \"start\" else -1)\n if number_of_opened <= 0:\n continue\n if max_size[pencil] < k:\n continue\n if pencil + max_size[pencil] + 1 > n:\n print(\"YES\")\n break\n heapq.heappush(possilbe_starts, (pencil + k, \"start\"))\n heapq.heappush(possilbe_starts, (pencil + max_size[pencil] + 1, \"stop\"))\n else:\n print(\"NO\")\n\nrun()\n", "passed": true, "time": 0.14, "memory": 14612.0, "status": "done"}, {"code": "import sys\n\nn, k, d = list(map(int, input().split()))\na = [0] + sorted(map(int, input().split()))\ndp = [1] + [0]*n\nj = k\n\nfor i in range(n):\n if dp[i] == 0:\n continue\n j = max(j, i+k)\n while j <= n and a[j] - a[i+1] <= d:\n dp[j] |= dp[i]\n j += 1\n\nprint('YES' if dp[-1] else 'NO')\n", "passed": true, "time": 0.25, "memory": 14316.0, "status": "done"}]
[{"input": "6 3 10\n7 2 7 7 4 2\n", "output": "YES\n"}, {"input": "6 2 3\n4 5 3 13 4 10\n", "output": "YES\n"}, {"input": "3 2 5\n10 16 22\n", "output": "NO\n"}, {"input": "8 7 13\n52 85 14 52 92 33 80 85\n", "output": "NO\n"}, {"input": "6 4 0\n1 3 2 4 2 1\n", "output": "NO\n"}, {"input": "10 4 9\n47 53 33 48 35 51 18 47 33 11\n", "output": "NO\n"}, {"input": "3 2 76\n44 5 93\n", "output": "NO\n"}, {"input": "5 2 9\n3 8 9 14 20\n", "output": "YES\n"}, {"input": "8 2 3\n1 2 3 4 10 11 12 13\n", "output": "YES\n"}, {"input": "10 3 3\n1 1 2 4 5 6 9 10 11 12\n", "output": "YES\n"}, {"input": "7 3 3\n1 1 3 4 4 4 7\n", "output": "YES\n"}, {"input": "8 3 6\n1 2 3 3 4 7 11 11\n", "output": "YES\n"}, {"input": "12 3 2\n1 2 3 9 10 11 12 13 14 15 15 15\n", "output": "YES\n"}, {"input": "7 3 3\n1 2 3 4 4 5 5\n", "output": "YES\n"}, {"input": "9 3 3\n1 2 3 4 5 6 7 8 9\n", "output": "YES\n"}, {"input": "5 2 3\n5 7 7 7 10\n", "output": "YES\n"}, {"input": "5 2 7\n1 3 4 5 10\n", "output": "YES\n"}, {"input": "16 2 2\n3 3 3 4 5 6 7 9 33 33 33 32 31 30 29 27\n", "output": "YES\n"}, {"input": "6 3 3\n1 2 3 4 5 6\n", "output": "YES\n"}, {"input": "3 2 15\n1 18 19\n", "output": "NO\n"}, {"input": "7 2 2\n1 2 3 4 5 6 7\n", "output": "YES\n"}, {"input": "6 3 3\n2 2 2 4 7 7\n", "output": "YES\n"}, {"input": "8 3 3\n1 1 1 2 2 3 3 5\n", "output": "YES\n"}, {"input": "6 2 2\n1 2 3 4 6 7\n", "output": "YES\n"}, {"input": "4 2 3\n1 2 3 6\n", "output": "YES\n"}, {"input": "10 4 28\n5 5 6 6 30 30 32 33 50 55\n", "output": "YES\n"}, {"input": "8 3 6\n1 2 3 3 7 4 11 11\n", "output": "YES\n"}, {"input": "6 3 2\n1 2 3 3 4 5\n", "output": "YES\n"}, {"input": "10 3 3\n1 2 3 3 3 3 3 3 3 5\n", "output": "YES\n"}, {"input": "1 1 1\n1\n", "output": "YES\n"}, {"input": "6 3 4\n1 2 3 4 6 7\n", "output": "YES\n"}, {"input": "6 3 3\n1 1 4 3 3 6\n", "output": "YES\n"}, {"input": "6 3 2\n1 2 2 3 4 5\n", "output": "YES\n"}, {"input": "4 2 12\n10 16 22 28\n", "output": "YES\n"}, {"input": "9 3 1\n1 2 2 2 2 3 4 4 5\n", "output": "YES\n"}, {"input": "6 2 2\n2 3 4 5 6 8\n", "output": "YES\n"}, {"input": "10 4 15\n20 16 6 16 13 11 13 1 12 16\n", "output": "YES\n"}, {"input": "18 2 86\n665 408 664 778 309 299 138 622 229 842 498 389 140 976 456 265 963 777\n", "output": "YES\n"}, {"input": "6 2 1\n1 1 2 3 4 5\n", "output": "YES\n"}, {"input": "10 4 7\n4 3 6 5 4 3 1 8 10 5\n", "output": "YES\n"}, {"input": "4 2 100\n1 2 3 200\n", "output": "NO\n"}, {"input": "6 3 3\n1 1 1 1 1 5\n", "output": "NO\n"}, {"input": "10 3 3\n1 1 1 2 2 5 6 7 8 9\n", "output": "YES\n"}, {"input": "11 3 4\n1 1 1 5 5 5 10 12 14 16 18\n", "output": "NO\n"}, {"input": "4 2 1\n1 1 2 3\n", "output": "YES\n"}, {"input": "7 3 3\n6 8 9 10 12 13 14\n", "output": "NO\n"}, {"input": "6 3 3\n1 2 3 4 7 8\n", "output": "NO\n"}, {"input": "13 2 86\n841 525 918 536 874 186 708 553 770 268 138 529 183\n", "output": "YES\n"}, {"input": "5 2 3\n1 2 3 4 100\n", "output": "NO\n"}, {"input": "5 2 3\n8 9 11 12 16\n", "output": "NO\n"}, {"input": "15 8 57\n40 36 10 6 17 84 57 9 55 37 63 75 48 70 53\n", "output": "NO\n"}, {"input": "10 3 1\n5 5 5 6 6 7 8 8 8 9\n", "output": "YES\n"}, {"input": "10 5 293149357\n79072863 760382815 358896034 663269192 233367425 32795628 837363300 46932461 179556769 763342555\n", "output": "NO\n"}, {"input": "7 3 3\n1 2 4 6 7 8 10\n", "output": "NO\n"}, {"input": "6 3 4\n1 1 3 5 8 10\n", "output": "NO\n"}, {"input": "14 2 75\n105 300 444 610 238 62 767 462 17 728 371 578 179 166\n", "output": "YES\n"}, {"input": "10 4 1\n2 2 2 3 3 10 10 10 11 11\n", "output": "YES\n"}, {"input": "18 3 1\n1 1 1 2 2 3 5 5 5 6 6 7 9 9 9 10 10 11\n", "output": "YES\n"}, {"input": "9 3 2\n1 2 2 3 4 5 6 7 7\n", "output": "YES\n"}, {"input": "8 4 5\n1 1 1 1 1 9 9 9\n", "output": "NO\n"}, {"input": "4 2 4\n9 1 2 3\n", "output": "NO\n"}, {"input": "10 3 0\n1 1 2 2 2 2 2 2 2 2\n", "output": "NO\n"}, {"input": "3 2 2\n6 7 7\n", "output": "YES\n"}, {"input": "3 2 257816048\n1 999999999 999999999\n", "output": "NO\n"}, {"input": "11 3 1\n1 1 2 2 3 3 3 4 4 5 5\n", "output": "YES\n"}]
271
Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded. For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 or to 10. Both ways are correct. For given n find out to which integer will Vasya round it. -----Input----- The first line contains single integer n (0 ≀ n ≀ 10^9)Β β€” number that Vasya has. -----Output----- Print result of rounding n. Pay attention that in some cases answer isn't unique. In that case print any correct answer. -----Examples----- Input 5 Output 0 Input 113 Output 110 Input 1000000000 Output 1000000000 Input 5432359 Output 5432360 -----Note----- In the first example n = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
interview
[{"code": "n = int(input())\nif n % 10 > 5:\n print(n + 10 - n % 10)\nelse:\n print(n - n % 10)", "passed": true, "time": 0.22, "memory": 14424.0, "status": "done"}, {"code": "n = int(input())\nif n % 10 <= 5 :\n print(n - n % 10)\nelse:\n print(n + 10 - n % 10)\n", "passed": true, "time": 0.15, "memory": 14284.0, "status": "done"}, {"code": "n = int(input())\nif n % 10 <= 5:\n n -= n % 10\nelse:\n n += 10 - n % 10\nprint(n)\n", "passed": true, "time": 0.76, "memory": 14300.0, "status": "done"}, {"code": "n = int(input())\n\nprint((n + 4)//10 * 10)", "passed": true, "time": 0.15, "memory": 14320.0, "status": "done"}, {"code": "n = int(input())\nif ord(str(n)[-1]) > ord('5'):\n print(n + 10 - ord(str(n)[-1]) + ord('0'))\nelse:\n print(n - ord(str(n)[-1]) + ord('0'))\n", "passed": true, "time": 0.14, "memory": 14304.0, "status": "done"}, {"code": "n = int(input())\nx = n // 10\ny = x * 10\nif abs(y - n) > 5:\n\tprint(y + 10)\nelse:\n\tprint(y)\t", "passed": true, "time": 0.23, "memory": 14272.0, "status": "done"}, {"code": "a = int(input())\nif a%10 > 5:\n\tprint(a - (a%10) + 10)\nelse:\n\tprint(a - (a%10))", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "n = int(input())\ns = str(n)\nif s[-1] == '0':\n print(n)\nelse:\n n1 = n - int((s[-1]))\n n2 = n1 + 10\n if n - n1 <= n2 - n:\n print(n1)\n else:\n print(n2)", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "n = int(input())\n\nd = n // 10\na1 = d * 10\na2 = (d + 1) * 10\n\nif (abs(a1 - n) > abs(a2 - n)):\n\tprint(a2)\nelse:\n\tprint(a1)\n", "passed": true, "time": 0.15, "memory": 14584.0, "status": "done"}]
[{"input": "5\n", "output": "0\n"}, {"input": "113\n", "output": "110\n"}, {"input": "1000000000\n", "output": "1000000000\n"}, {"input": "5432359\n", "output": "5432360\n"}, {"input": "999999994\n", "output": "999999990\n"}, {"input": "10\n", "output": "10\n"}, {"input": "9\n", "output": "10\n"}, {"input": "1\n", "output": "0\n"}, {"input": "0\n", "output": "0\n"}, {"input": "3\n", "output": "0\n"}, {"input": "4\n", "output": "0\n"}, {"input": "6\n", "output": "10\n"}, {"input": "7\n", "output": "10\n"}, {"input": "8\n", "output": "10\n"}, {"input": "19\n", "output": "20\n"}, {"input": "100\n", "output": "100\n"}, {"input": "997\n", "output": "1000\n"}, {"input": "9994\n", "output": "9990\n"}, {"input": "10002\n", "output": "10000\n"}, {"input": "100000\n", "output": "100000\n"}, {"input": "99999\n", "output": "100000\n"}, {"input": "999999999\n", "output": "1000000000\n"}, {"input": "999999998\n", "output": "1000000000\n"}, {"input": "999999995\n", "output": "999999990\n"}, {"input": "999999990\n", "output": "999999990\n"}, {"input": "1000000\n", "output": "1000000\n"}, {"input": "1000010\n", "output": "1000010\n"}, {"input": "10000010\n", "output": "10000010\n"}, {"input": "100000011\n", "output": "100000010\n"}, {"input": "400000003\n", "output": "400000000\n"}, {"input": "234234\n", "output": "234230\n"}, {"input": "675621\n", "output": "675620\n"}, {"input": "43532\n", "output": "43530\n"}, {"input": "4576453\n", "output": "4576450\n"}, {"input": "65754674\n", "output": "65754670\n"}, {"input": "3245526\n", "output": "3245530\n"}, {"input": "123445\n", "output": "123440\n"}, {"input": "234217\n", "output": "234220\n"}, {"input": "23451218\n", "output": "23451220\n"}, {"input": "1231239\n", "output": "1231240\n"}, {"input": "1923140\n", "output": "1923140\n"}, {"input": "307910310\n", "output": "307910310\n"}, {"input": "780961030\n", "output": "780961030\n"}, {"input": "103509421\n", "output": "103509420\n"}, {"input": "576560141\n", "output": "576560140\n"}, {"input": "48851642\n", "output": "48851640\n"}, {"input": "226935072\n", "output": "226935070\n"}, {"input": "844450763\n", "output": "844450760\n"}, {"input": "22534183\n", "output": "22534180\n"}, {"input": "640049874\n", "output": "640049870\n"}, {"input": "818133304\n", "output": "818133300\n"}, {"input": "730616285\n", "output": "730616280\n"}, {"input": "613732415\n", "output": "613732410\n"}, {"input": "380991216\n", "output": "380991220\n"}, {"input": "559074636\n", "output": "559074640\n"}, {"input": "176590327\n", "output": "176590330\n"}, {"input": "354673757\n", "output": "354673760\n"}, {"input": "267156738\n", "output": "267156740\n"}, {"input": "150272868\n", "output": "150272870\n"}, {"input": "62755859\n", "output": "62755860\n"}, {"input": "945871979\n", "output": "945871980\n"}, {"input": "46\n", "output": "50\n"}, {"input": "999\n", "output": "1000\n"}, {"input": "1397\n", "output": "1400\n"}]
272
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard. You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once. -----Input----- The input consists of only two strings s and t denoting the favorite Santa's patter and the resulting string. s and t are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. -----Output----- If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print Β«-1Β» (without quotes). Otherwise, the first line of output should contain the only integer k (k β‰₯ 0)Β β€” the number of pairs of keys that should be swapped. The following k lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct. If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair. Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes. -----Examples----- Input helloworld ehoolwlroz Output 3 h e l o d z Input hastalavistababy hastalavistababy Output 0 Input merrychristmas christmasmerry Output -1
interview
[{"code": "a = input()\nb = input()\n\nsymbols = {}\npairs = []\n\nfor i in range(len(a)):\n if a[i] in symbols:\n if symbols[a[i]] != b[i]:\n print('-1')\n break\n elif b[i] in symbols:\n if symbols[b[i]] != a[i]:\n print('-1')\n break\n else:\n symbols[a[i]] = b[i]\n symbols[b[i]] = a[i]\n if a[i] != b[i]:\n pairs.append((a[i], b[i]))\nelse:\n print(len(pairs))\n for elem in pairs:\n print(elem[0], elem[1])", "passed": true, "time": 0.79, "memory": 14320.0, "status": "done"}, {"code": "a = input()\nb = input()\nans = {}\nt = True\nfor i in range(len(a)):\n\tif a[i] in ans.keys():\n\t\tif ans[a[i]] != b[i]:\n\t\t\t\tt = False\n\tif b[i] in ans.keys():\n\t\tif ans[b[i]] != a[i]:\n\t\t\t\tt = False\n\telse:\n\t\tans[a[i]] = b[i]\n\t\tans[b[i]] = a[i]\n\nif t:\n\tan = []\n\tfor i in ans.keys():\n\t\tif i != ans[i] and i not in an and ans[i] not in an:\n\t\t\tan.append(i) \n\t\t\tan.append(ans[i])\n\tprint(len(an)//2)\n\tfor i in range(0, len(an) - 1, 2):\n\t\tprint(an[i], an[i + 1])\nelse:\n\tprint(-1)", "passed": true, "time": 0.16, "memory": 14436.0, "status": "done"}, {"code": "s1 = input()\ns2 = input()\n\nd = {}\nd2 = {}\n\nflag = False\n\nfor i in range(len(s1)):\n if s1[i] in d:\n if d[s1[i]] != s2[i]:\n flag = True\n break\n\n if s2[i] in d:\n if d[s2[i]] != s1[i]:\n flag = True\n break\n else:\n d[s1[i]] = s2[i]\n d[s2[i]] = s1[i]\n if s1[i] != s2[i]:\n d2[s1[i]] = s2[i]\n\nif flag:\n print(-1)\nelse:\n l = len(d2)\n if not l:\n print(0)\n else:\n print(l)\n for item in d2:\n print(item, d2[item])\n \n \n", "passed": true, "time": 0.25, "memory": 14364.0, "status": "done"}, {"code": "s1 = input()\ns2 = input()\nd = dict()\nfor i in range(len(s1)):\n if s2[i] != s1[i]:\n res1 = d.get(s1[i], -1)\n res2 = d.get(s2[i], -1)\n if (res1 == -1 and res2 == -1) or (res1 == s2[i] and res2 == s1[i]):\n d[s1[i]] = s2[i]\n d[s2[i]] = s1[i]\n else:\n print(-1)\n return\n if s2[i] == s1[i]:\n res = d.get(s1[i], -1)\n if res != -1 and res != s1[i]:\n print(-1)\n return\n d[s1[i]] = s1[i]\nans = len(d)\nfor i in d:\n if i == d[i]:\n ans -= 1\nprint(ans // 2)\nused = dict()\nfor i in d:\n used[i] = 0\nfor i in d:\n if not used[i] and i != d[i]: \n print(i, d[i])\n used[d[i]] = 1", "passed": true, "time": 0.15, "memory": 14576.0, "status": "done"}, {"code": "s = input()\ns1 = input()\nmistake = False\nd = dict()\nans = []\n\nfor i in range(len(s)):\n if s[i] != s1[i]:\n if s[i] in d and s1[i] in d:\n if not (d[s[i]] == s1[i] and d[s1[i]] == s[i]):\n mistake = True\n break\n\n elif s[i] in d or s1[i] in d:\n mistake = True\n break\n else:\n d[s[i]] = s1[i]\n d[s1[i]] = s[i]\n else:\n if s[i] in d and d[s[i]] != s[i]:\n mistake = True\n break\n d[s[i]] = s[i]\n \nif mistake:\n print(-1)\nelse:\n ans = []\n last = set()\n for elem in d:\n if elem not in last and elem != d[elem]:\n ans.append([elem, d[elem]])\n last.add(elem)\n last.add(d[elem])\n \n print(len(ans))\n for elem in ans:\n print(*elem)\n \n", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "q=input()\nw=input()\nl=len(q)\na=[]\ns=[0 for i in range(0,130)]\nt=[]\nfor i in range(0,l):\n if q[i]==w[i]:\n t.append(q[i])\nfor i in range(0,l):\n if q[i]!=w[i]:\n a.append([q[i],w[i]])\n s[ord(q[i])]+=1\n s[ord(w[i])]+=1\n c=q[i]\n if (q[i] in t) | (w[i] in t):\n s[0]=10\n q=q.replace(q[i],w[i])\n w=w.replace(c,w[i])\nif max(s)>1:\n print(-1)\nelse:\n print(len(a))\n for i in a:\n print(i[0],i[1])\n", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "a = input()\nb = input()\nalph = [0] * 26\nfor i in range(26):\n alph[i] = chr(97 + i)\nans = []\nfor i in range(len(a)):\n if a[i] != alph[ord(b[i]) - 97]:\n if (alph[ord(a[i]) - 97] == a[i]) and (alph[ord(b[i]) - 97] == b[i]):\n alph[ord(a[i]) - 97] = b[i]\n alph[ord(b[i]) - 97] = a[i]\n ans.append((a[i], b[i]))\n else:\n print(-1)\n return\nfor i in range(len(b)):\n if a[i] != alph[ord(b[i]) - 97]:\n print(-1)\n return\nprint(len(ans))\nfor i in range(len(ans)):\n print(ans[i][0], ans[i][1])", "passed": true, "time": 0.15, "memory": 14552.0, "status": "done"}]
[{"input": "helloworld\nehoolwlroz\n", "output": "3\nh e\nl o\nd z\n"}, {"input": "hastalavistababy\nhastalavistababy\n", "output": "0\n"}, {"input": "merrychristmas\nchristmasmerry\n", "output": "-1\n"}, {"input": "kusyvdgccw\nkusyvdgccw\n", "output": "0\n"}, {"input": "bbbbbabbab\naaaaabaaba\n", "output": "1\nb a\n"}, {"input": "zzzzzzzzzzzzzzzzzzzzz\nqwertyuiopasdfghjklzx\n", "output": "-1\n"}, {"input": "accdccdcdccacddbcacc\naccbccbcbccacbbdcacc\n", "output": "1\nd b\n"}, {"input": "giiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\ngiiibdbebjdaihdghahccdeffjhfgidfbdhjdggajfgaidadjd\n", "output": "0\n"}, {"input": "gndggadlmdefgejidmmcglbjdcmglncfmbjjndjcibnjbabfab\nfihffahlmhogfojnhmmcflkjhcmflicgmkjjihjcnkijkakgak\n", "output": "5\ng f\nn i\nd h\ne o\nb k\n"}, {"input": "ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\nijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\n", "output": "0\n"}, {"input": "ab\naa\n", "output": "-1\n"}, {"input": "a\nz\n", "output": "1\na z\n"}, {"input": "zz\nzy\n", "output": "-1\n"}, {"input": "as\ndf\n", "output": "2\na d\ns f\n"}, {"input": "abc\nbca\n", "output": "-1\n"}, {"input": "rtfg\nrftg\n", "output": "1\nt f\n"}, {"input": "y\ny\n", "output": "0\n"}, {"input": "qwertyuiopasdfghjklzx\nzzzzzzzzzzzzzzzzzzzzz\n", "output": "-1\n"}, {"input": "qazwsxedcrfvtgbyhnujmik\nqwertyuiasdfghjkzxcvbnm\n", "output": "-1\n"}, {"input": "aaaaaa\nabcdef\n", "output": "-1\n"}, {"input": "qwerty\nffffff\n", "output": "-1\n"}, {"input": "dofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\ndofbgdppdvmwjwtdyphhmqliydxyjfxoopxiscevowleccmhwybsxitvujkfliamvqinlrpytyaqdlbywccprukoisyaseibuqbfqjcabkieimsggsakpnqliwhehnemewhychqrfiuyaecoydnromrh\n", "output": "0\n"}, {"input": "acdbccddadbcbabbebbaebdcedbbcebeaccecdabadeabeecbacacdcbccedeadadedeccedecdaabcedccccbbcbcedcaccdede\ndcbaccbbdbacadaaeaadeabcebaaceaedccecbdadbedaeecadcdcbcaccebedbdbebeccebecbddacebccccaacacebcdccbebe\n", "output": "-1\n"}, {"input": "bacccbbacabbcaacbbba\nbacccbbacabbcaacbbba\n", "output": "0\n"}, {"input": "dbadbddddb\nacbacaaaac\n", "output": "-1\n"}, {"input": "dacbdbbbdd\nadbdadddaa\n", "output": "-1\n"}, {"input": "bbbbcbcbbc\ndaddbabddb\n", "output": "-1\n"}, {"input": "dddddbcdbd\nbcbbbdacdb\n", "output": "-1\n"}, {"input": "cbadcbcdaa\nabbbababbb\n", "output": "-1\n"}, {"input": "dmkgadidjgdjikgkehhfkhgkeamhdkfemikkjhhkdjfaenmkdgenijinamngjgkmgmmedfdehkhdigdnnkhmdkdindhkhndnakdgdhkdefagkedndnijekdmkdfedkhekgdkhgkimfeakdhhhgkkff\nbdenailbmnbmlcnehjjkcgnehadgickhdlecmggcimkahfdeinhflmlfadfnmncdnddhbkbhgejblnbffcgdbeilfigegfifaebnijeihkanehififlmhcbdcikhieghenbejneldkhaebjggncckk\n", "output": "-1\n"}, {"input": "acbbccabaa\nabbbbbabaa\n", "output": "-1\n"}, {"input": "ccccaccccc\naaaabaaaac\n", "output": "-1\n"}, {"input": "acbacacbbb\nacbacacbbb\n", "output": "0\n"}, {"input": "abbababbcc\nccccccccbb\n", "output": "-1\n"}, {"input": "jbcbbjiifdcbeajgdeabddbfcecafejddcigfcaedbgicjihifgbahjihcjefgabgbccdiibfjgacehbbdjceacdbdeaiibaicih\nhhihhhddcfihddhjfddhffhcididcdhffidjciddfhjdihdhdcjhdhhdhihdcjdhjhiifddhchjdidhhhfhiddifhfddddhddidh\n", "output": "-1\n"}, {"input": "ahaeheedefeehahfefhjhhedheeeedhehhfhdejdhffhhejhhhejadhefhahhadjjhdhheeeehfdaffhhefehhhefhhhhehehjda\neiefbdfgdhffieihfhjajifgjddffgifjbhigfagjhhjicaijbdaegidhiejiegaabgjidcfcjhgehhjjchcbjjdhjbiidjdjage\n", "output": "-1\n"}, {"input": "fficficbidbcbfaddifbffdbbiaccbbciiaidbcbbiadcccbccbbaibabcbbdbcibcciibiccfifbiiicadibbiaafadacdficbc\nddjhdghbgcbhadeccjdbddcbfjeiiaaigjejcaiabgechiiahibfejbeahafcfhjbihgjfgihdgdagjjhecjafjeedecehcdjhai\n", "output": "-1\n"}, {"input": "z\nz\n", "output": "0\n"}, {"input": "a\nz\n", "output": "1\na z\n"}, {"input": "z\na\n", "output": "1\nz a\n"}, {"input": "aa\nzz\n", "output": "1\na z\n"}, {"input": "az\nza\n", "output": "1\na z\n"}, {"input": "aa\nza\n", "output": "-1\n"}, {"input": "za\nzz\n", "output": "-1\n"}, {"input": "aa\nab\n", "output": "-1\n"}, {"input": "hehe\nheeh\n", "output": "-1\n"}, {"input": "bd\ncc\n", "output": "-1\n"}, {"input": "he\nhh\n", "output": "-1\n"}, {"input": "hee\nheh\n", "output": "-1\n"}, {"input": "aa\nac\n", "output": "-1\n"}, {"input": "ab\naa\n", "output": "-1\n"}, {"input": "hello\nehlol\n", "output": "-1\n"}, {"input": "ac\naa\n", "output": "-1\n"}, {"input": "aaabbb\nbbbaab\n", "output": "-1\n"}, {"input": "aa\nfa\n", "output": "-1\n"}, {"input": "hg\nee\n", "output": "-1\n"}, {"input": "helloworld\nehoolwlrow\n", "output": "-1\n"}, {"input": "abb\nbab\n", "output": "-1\n"}, {"input": "aaa\naae\n", "output": "-1\n"}, {"input": "aba\nbaa\n", "output": "-1\n"}, {"input": "aa\nba\n", "output": "-1\n"}, {"input": "da\naa\n", "output": "-1\n"}, {"input": "aaa\naab\n", "output": "-1\n"}, {"input": "xy\nzz\n", "output": "-1\n"}]
273
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". -----Input----- The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. -----Output----- Output a single stringΒ β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. -----Examples----- Input harry potter Output hap Input tom riddle Output tomr
interview
[{"code": "import sys\na, b = list(map(str, input().split()))\narr = []\nfor i in range(1, len(a) + 1):\n for j in range(1, len(b) + 1):\n arr.append(a[:i] + b[:j])\narr.sort()\nprint(arr[0])\n", "passed": true, "time": 0.15, "memory": 14288.0, "status": "done"}, {"code": "s = input().split()\nd = set()\nfor i in range(1, len(s[0]) + 1):\n\tfor j in range(1, len(s[1]) + 1):\n\t\td.add(s[0][:i] + s[1][:j])\nprint(sorted(d)[0])", "passed": true, "time": 0.24, "memory": 14380.0, "status": "done"}, {"code": "a, b = input().split()\n\nl = []\n\nfor i in range(1, len(a) + 1):\n for j in range(1, len(b) + 1):\n l.append(a[:i] + b[:j])\n\nl.sort()\n\nprint(l[0])\n", "passed": true, "time": 0.14, "memory": 14396.0, "status": "done"}, {"code": "a,b = input().split()\nn=len(a)\nm=len(b)\nnames = []\nfor i in range(n):\n for j in range(m):\n names.append(a[:i+1]+b[:j+1])\nprint(min(names))\n", "passed": true, "time": 0.16, "memory": 14276.0, "status": "done"}, {"code": "a, b = input().split()\n\nbest = None\nfor i in range(1, len(a) + 1):\n for j in range(1, len(b) + 1):\n username = a[:i] + b[:j]\n if best is None or username < best:\n best = username\n\nprint(best)\n", "passed": true, "time": 0.15, "memory": 14424.0, "status": "done"}, {"code": "a,b=input().split()\nans=[]\nfor x in range(1,len(a)+1):\n for y in range(1,len(b)+1):\n ans.append(a[:x]+b[:y])\nans=sorted(ans)\nprint(ans[0])", "passed": true, "time": 0.18, "memory": 14380.0, "status": "done"}, {"code": "a,b = input().split()\nprint(min(a[:i+1]+b[:j+1] for i in range(len(a)) for j in range(len(b))))\n", "passed": true, "time": 0.19, "memory": 14572.0, "status": "done"}, {"code": "a, b = input().split()\nans = a[0]\nfor i in range(1, len(a)):\n if a[i] < b[0]:\n ans += a[i]\n else:\n break\nans += b[0]\nprint(ans)", "passed": true, "time": 0.25, "memory": 14364.0, "status": "done"}, {"code": "s1, s2 = input().split()\na = []\nfor i in range(1, len(s1) + 1):\n for j in range(1, len(s2) + 1):\n a.append(s1[:i] + s2[:j])\na.sort()\nprint(a[0])\n", "passed": true, "time": 0.15, "memory": 14400.0, "status": "done"}, {"code": "s, t = input().split()\n\nl = []\nfor i in range(len(s)):\n\tfor j in range(len(t)):\n\t\tl.append(s[:i+1] + t[:j+1])\nl.sort()\n\nprint(l[0])\n", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "q,w=input().split()\ns=q[0]\nq=q[1:]\nwhile len(q)>0:\n if q[0]<w[0]:\n s+=q[0]\n q=q[1:]\n else:\n q=''\nprint(s+w[0])\n", "passed": true, "time": 0.16, "memory": 14304.0, "status": "done"}, {"code": "name, fam = input().split()\nans = name[0]\nfor ch in name[1:]:\n if ch < fam[0]:\n ans += ch\n else:\n break\nans += fam[0]\nprint(ans)\n", "passed": true, "time": 0.23, "memory": 14268.0, "status": "done"}, {"code": "a, b = input().split()\nk = 1\nfor i in range(1, len(a)):\n if a[i] < b[0]:\n k += 1\n else:\n break\nans = a[:k] + b[0]\nprint(ans)", "passed": true, "time": 0.15, "memory": 14360.0, "status": "done"}, {"code": "a, b = input().split()\nans = \"z\" * 100\nfor i in range(1, len(a) + 1):\n for j in range(1, len(b) + 1):\n if a[:i] + b[:j] < ans:\n ans = a[:i] + b[:j]\nprint(ans)", "passed": true, "time": 0.16, "memory": 14328.0, "status": "done"}, {"code": "s1,s2=input().split()\nminn='zzzzzzzzzzzzzzzzz'\nfor i in range(1,len(s1)+1):\n for j in range(1,len(s2)+1):\n if s1[:i]+s2[:j] <minn:\n minn=s1[:i]+s2[:j]\nprint(minn)", "passed": true, "time": 0.16, "memory": 14520.0, "status": "done"}, {"code": "n, ln = [i for i in input().split(' ')]\n\nans = n[0]\n\ni = 1\n\nwhile i < len(n) and n[i] < ln[0]:\n ans += n[i]\n i += 1\n\nans += ln[0]\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14400.0, "status": "done"}, {"code": "a,b = input().split()\nans = a[0]\nfor i in range(1, len(a)):\n\tif(a[i] < b[0]):\n\t\tans += a[i]\n\telse:\n\t\tbreak\nans += b[0]\nprint(ans)", "passed": true, "time": 0.25, "memory": 14468.0, "status": "done"}, {"code": "name, surname = input().split()\n\nans = name[0] + surname[0]\nfor i in range(len(name)):\n cur_ans = name[:i + 1]\n for j in range(len(surname)):\n cur_ans += surname[:j + 1]\n ans = min(ans, cur_ans)\n\nprint(ans)", "passed": true, "time": 0.24, "memory": 14240.0, "status": "done"}, {"code": "name, surname = input().split()\nans = name[0]\nfor i in name[1:]:\n if i < surname[0]:\n ans += i\n else:\n break\nans += surname[0]\nprint(ans)", "passed": true, "time": 0.23, "memory": 14268.0, "status": "done"}, {"code": "(st1,st2) = (input().split())\nd = 0\nfor i in st1:\n\tif i<st2[0] or not d:\n\t\td = 1\n\t\tprint(i, end='')\n\telse:\n\t\tbreak\nprint(st2[0])", "passed": true, "time": 0.15, "memory": 14328.0, "status": "done"}, {"code": "n, s = input().split()\nlast = s[0]\nans = n[0]\nfor x in n[1:]:\n if x<last:\n ans+=x\n else:\n break\nprint(ans+last)", "passed": true, "time": 0.14, "memory": 14536.0, "status": "done"}, {"code": "s1,s2=input().split()\na=[]\nfor i in range(1,len(s1)+1):\n for j in range(1,len(s2)+1):\n a.append(s1[:i]+s2[:j])\nprint(min(a))\n", "passed": true, "time": 0.14, "memory": 14484.0, "status": "done"}, {"code": "a, b = list(map(str, input().split()))\nan = -1\nfor i in range(len(a)):\n for j in range(len(b)):\n c = int(i == -1) + int(j == -1)\n if (an == -1 or a[0:i + 1] + b[0: j + 1] < an):\n an = a[0:i + 1] + b[0: j + 1]\nprint(an)\n", "passed": true, "time": 0.15, "memory": 14272.0, "status": "done"}]
[{"input": "harry potter\n", "output": "hap\n"}, {"input": "tom riddle\n", "output": "tomr\n"}, {"input": "a qdpinbmcrf\n", "output": "aq\n"}, {"input": "wixjzniiub ssdfodfgap\n", "output": "wis\n"}, {"input": "z z\n", "output": "zz\n"}, {"input": "ertuyivhfg v\n", "output": "ertuv\n"}, {"input": "asdfghjkli ware\n", "output": "asdfghjkliw\n"}, {"input": "udggmyop ze\n", "output": "udggmyopz\n"}, {"input": "fapkdme rtzxovx\n", "output": "fapkdmer\n"}, {"input": "mybiqxmnqq l\n", "output": "ml\n"}, {"input": "dtbqya fyyymv\n", "output": "df\n"}, {"input": "fyclu zokbxiahao\n", "output": "fycluz\n"}, {"input": "qngatnviv rdych\n", "output": "qngar\n"}, {"input": "ttvnhrnng lqkfulhrn\n", "output": "tl\n"}, {"input": "fya fgx\n", "output": "ff\n"}, {"input": "nuis zvjjqlre\n", "output": "nuisz\n"}, {"input": "ly qtsmze\n", "output": "lq\n"}, {"input": "d kgfpjsurfw\n", "output": "dk\n"}, {"input": "lwli ewrpu\n", "output": "le\n"}, {"input": "rr wldsfubcs\n", "output": "rrw\n"}, {"input": "h qart\n", "output": "hq\n"}, {"input": "vugvblnzx kqdwdulm\n", "output": "vk\n"}, {"input": "xohesmku ef\n", "output": "xe\n"}, {"input": "twvvsl wtcyawv\n", "output": "tw\n"}, {"input": "obljndajv q\n", "output": "obljndajq\n"}, {"input": "jjxwj kxccwx\n", "output": "jjk\n"}, {"input": "sk fftzmv\n", "output": "sf\n"}, {"input": "cgpegngs aufzxkyyrw\n", "output": "ca\n"}, {"input": "reyjzjdvq skuch\n", "output": "res\n"}, {"input": "ardaae mxgdulijf\n", "output": "am\n"}, {"input": "bgopsdfji uaps\n", "output": "bgopsdfjiu\n"}, {"input": "amolfed pun\n", "output": "amolfedp\n"}, {"input": "badkiln yort\n", "output": "badkilny\n"}, {"input": "aaaaaaaaaz york\n", "output": "aaaaaaaaay\n"}, {"input": "bbbbcbbbbd c\n", "output": "bbbbc\n"}, {"input": "aa ab\n", "output": "aa\n"}, {"input": "ab b\n", "output": "ab\n"}, {"input": "aaaaa ab\n", "output": "aa\n"}, {"input": "aa a\n", "output": "aa\n"}, {"input": "aba b\n", "output": "ab\n"}, {"input": "aaaaaaa aaaaaa\n", "output": "aa\n"}, {"input": "a a\n", "output": "aa\n"}, {"input": "a aa\n", "output": "aa\n"}, {"input": "a b\n", "output": "ab\n"}, {"input": "b a\n", "output": "ba\n"}, {"input": "z a\n", "output": "za\n"}, {"input": "aaa a\n", "output": "aa\n"}, {"input": "aa aa\n", "output": "aa\n"}, {"input": "a aaa\n", "output": "aa\n"}, {"input": "aaaaaaaaaa aaaaaaaaaa\n", "output": "aa\n"}, {"input": "aaaaaaaaaa a\n", "output": "aa\n"}, {"input": "a aaaaaaaaaa\n", "output": "aa\n"}, {"input": "zzaa b\n", "output": "zb\n"}, {"input": "ca cf\n", "output": "cac\n"}, {"input": "abhi ia\n", "output": "abhi\n"}, {"input": "aaaa aaaab\n", "output": "aa\n"}, {"input": "aar raa\n", "output": "aar\n"}, {"input": "harry hotter\n", "output": "hah\n"}, {"input": "aaaaaaa a\n", "output": "aa\n"}, {"input": "apple pie\n", "output": "ap\n"}, {"input": "aaa aaa\n", "output": "aa\n"}, {"input": "kabc buba\n", "output": "kab\n"}, {"input": "asd ss\n", "output": "as\n"}, {"input": "bbb b\n", "output": "bb\n"}]
274
A sequence of square brackets is regular if by inserting symbols "+" and "1" into it, you can get a regular mathematical expression from it. For example, sequences "[[]][]", "[]" and "[[][[]]]" β€” are regular, at the same time "][", "[[]" and "[[]]][" β€” are irregular. Draw the given sequence using a minimalistic pseudographics in the strip of the lowest possible height β€” use symbols '+', '-' and '|'. For example, the sequence "[[][]][]" should be represented as: +- -++- -+ |+- -++- -+|| | || || ||| | |+- -++- -+|| | +- -++- -+ Each bracket should be represented with the hepl of one or more symbols '|' (the vertical part) and symbols '+' and '-' as on the example which is given above. Brackets should be drawn without spaces one by one, only dividing pairs of consecutive pairwise brackets with a single-space bar (so that the two brackets do not visually merge into one symbol). The image should have the minimum possible height. The enclosed bracket is always smaller than the surrounding bracket, but each bracket separately strives to maximize the height of the image. So the pair of final brackets in the example above occupies the entire height of the image. Study carefully the examples below, they adequately explain the condition of the problem. Pay attention that in this problem the answer (the image) is unique. -----Input----- The first line contains an even integer n (2 ≀ n ≀ 100) β€” the length of the sequence of brackets. The second line contains the sequence of brackets β€” these are n symbols "[" and "]". It is guaranteed that the given sequence of brackets is regular. -----Output----- Print the drawn bracket sequence in the format which is given in the condition. Don't print extra (unnecessary) spaces. -----Examples----- Input 8 [[][]][] Output +- -++- -+ |+- -++- -+|| | || || ||| | |+- -++- -+|| | +- -++- -+ Input 6 [[[]]] Output +- -+ |+- -+| ||+- -+|| ||| ||| ||+- -+|| |+- -+| +- -+ Input 6 [[][]] Output +- -+ |+- -++- -+| || || || |+- -++- -+| +- -+ Input 2 [] Output +- -+ | | +- -+ Input 4 [][] Output +- -++- -+ | || | +- -++- -+
interview
[{"code": "n = int(input())\nx = input()\nd = [0] * n\ncd = 0\nxp = []\nfor i in range(n):\n\tif x[i] == '[':\n\t\td[i] = cd\n\t\tcd = cd + 1\n\telse:\n\t\tcd = cd - 1\n\t\td[i] = cd\nfor i in range(n-1):\n\txp.append((x[i], d[i]))\n\tif x[i] == '[' and x[i+1] == ']':\n\t\txp.extend([(' ', d[i]), (' ', d[i]), (' ', d[i])])\nxp.append((x[n-1], d[n-1]))\nmd = max(d)\nh = md * 2 + 3\nres = []\nfor i in range(h):\n\tl = [' ' for j in xp]\n\tres.append(l)\nfor i in range(len(xp)):\n\tfor j in range(h):\n\t\tif xp[i][0] == '[' and j > xp[i][1] and j < h - xp[i][1] - 1:\n\t\t\tres[j][i] = '|'\n\t\telif xp[i][0] == ']' and j > xp[i][1] and j < h - xp[i][1] - 1:\n\t\t\tres[j][i] = '|'\n\t\telif xp[i][0] == '[' and (j == xp[i][1] or j == h - xp[i][1] - 1):\n\t\t\tres[j][i] = '+'\n\t\t\tres[j][i+1] = '-'\n\t\telif xp[i][0] == ']' and (j == xp[i][1] or j == h - xp[i][1] - 1):\n\t\t\tres[j][i] = '+'\n\t\t\tres[j][i-1] = '-'\n\nfor i in range(h):\n\tprint(''.join(res[i]))\n\n", "passed": true, "time": 0.16, "memory": 14724.0, "status": "done"}, {"code": "class Screen:\n def __init__(self, n_rows):\n self.rows = [[] for _ in range(n_rows)]\n self.height = n_rows\n\n def draw(self, x, y, c):\n row = self.rows[y]\n while x > len(row) - 1:\n row.append(' ')\n row[x] = c\n\n def draw_open(self, x, height):\n middle = self.height // 2\n self.draw(x, middle, '|')\n for dy in range(1, height + 1):\n self.draw(x, middle + dy, '|')\n self.draw(x, middle - dy, '|')\n self.draw(x, middle + height + 1, '+')\n self.draw(x + 1, middle + height + 1, '-')\n self.draw(x, middle - height - 1, '+')\n self.draw(x + 1, middle - height - 1, '-')\n\n def draw_close(self, x, height):\n middle = self.height // 2\n self.draw(x, middle, '|')\n for dy in range(1, height + 1):\n self.draw(x, middle + dy, '|')\n self.draw(x, middle - dy, '|')\n self.draw(x, middle + height + 1, '+')\n self.draw(x - 1, middle + height + 1, '-')\n self.draw(x, middle - height - 1, '+')\n self.draw(x - 1, middle - height - 1, '-')\n\n def strings(self):\n return [''.join(row) for row in self.rows]\n\n\ndef to_heights(seq):\n depths = []\n cur_depth = 0\n for par in seq:\n if par == '[':\n depths.append(cur_depth)\n cur_depth += 1\n else:\n cur_depth -= 1\n depths.append(cur_depth)\n max_depth = max(depths)\n heights = [max_depth - depth for depth in depths]\n return heights\n\n\ndef to_strings(seq, heights):\n n_rows = 2 * (max(heights) + 1) + 1\n screen = Screen(n_rows)\n cur_x = 0\n prev_par = None\n for par, height in zip(seq, heights):\n if par == '[':\n screen.draw_open(cur_x, height)\n cur_x += 1\n if par == ']':\n if prev_par == '[':\n cur_x += 3\n screen.draw_close(cur_x, height)\n cur_x += 1\n prev_par = par\n return screen.strings()\n\n\n\n\n\nn = int(input())\nseq = input()\nheights = to_heights(seq)\nstrings = to_strings(seq, heights)\nfor string in strings:\n print(string)\n\n", "passed": true, "time": 0.16, "memory": 14464.0, "status": "done"}, {"code": "N = int(input())\na = input()\nspaces = a.count('[]')\na = list(map(lambda x: 1 if x=='[' else -1, [x for x in str(a) if x=='[' or x==']']))\nmaxdepth = max([sum(a[:i+1]) for i in range(len(a))])\n\ndl = 5+(maxdepth-1)*2\nmaxdl = dl-2\n#for i in a:\njj = [[' ' for i in range(N+spaces*3)] for j in range(maxdl)]\nposx = 0\nfor i in range(len(a)):\n if a[i] == 1:\n dl -= 2\n for j in range((maxdl-dl)//2,maxdl-(maxdl-dl)//2):\n if j in [(maxdl-dl)//2,maxdl-(maxdl-dl)//2-1]:\n jj[j][posx]='+'\n jj[j][posx+1]='-'\n else:\n jj[j][posx]='|'\n if i < len(a) and a[i+1] == -1:\n posx+=4\n else:\n posx+=1\n elif a[i] == -1:\n for j in range((maxdl-dl)//2,maxdl-(maxdl-dl)//2):\n if j in [(maxdl-dl)//2,maxdl-(maxdl-dl)//2-1]:\n jj[j][posx]='+'\n jj[j][posx-1]='-'\n else:\n jj[j][posx]='|'\n dl += 2\n posx+=1\nfor j in jj:\n for i in j:\n print(i,end='')\n print()\n", "passed": true, "time": 0.29, "memory": 14656.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nd = 0 # depth\nmd = 0 # max depth\nfor i in s:\n if i == '[':\n d += 1\n else:\n d -= 1\n md = max(md, d)\n\n#print(md)\n\nnv = md * 2 - 1 # kol-vo palok at this moment\nout = \"\"\nres = []\ni = 0\nwhile i < n:\n out += '+'\n out += ('|' * nv)\n out += '+'\n res.append(out)\n out = \"\"\n while i != n-1 and s[i+1] == '[':\n nv -= 2\n \n out += '-'\n out += '+'\n out += ('|' * nv)\n out += '+' \n out += '-' \n \n res.append(out)\n out = \"\" \n \n i += 1\n out += '-'\n out += ' ' * nv\n out += '-'\n res.append(out)\n out = \"\"\n \n res.append(\" \" * (nv + 2))\n i += 1\n \n out += '-'\n out += ' ' * nv\n out += '-'\n res.append(out)\n out = \"\" \n \n while i != n-1 and s[i+1] == ']': \n out += '-'\n out += '+'\n out += ('|' * nv)\n out += '+' \n out += '-' \n \n res.append(out)\n out = \"\" \n \n nv += 2\n i += 1\n \n out += '+'\n out += ('|' * nv)\n out += '+'\n res.append(out)\n out = \"\" \n #print(out)\n i += 1\n\nnorm = md * 2 + 1\nfor i in range(len(res)):\n if len(res[i]) == norm:\n continue\n else:\n otk = (norm - len(res[i])) // 2\n res[i] = (\" \" * otk) + res[i] + (\" \" * otk)\n\nfor i in range(norm):\n for j in range(len(res)):\n print(res[j][i], end=\"\")\n print()\n\n\"\"\"\n8\n[[][]][]\n\n6\n[[[]]]\n\n6\n[[][]]\n\n2\n[]\n\n4\n[][]\n\"\"\"", "passed": true, "time": 0.15, "memory": 14628.0, "status": "done"}, {"code": "import sys\n\nn = int(input())\ns = input()\n\nheight = [1] * n\nmatching = [-1] * n\n\nfor i, c in enumerate(s):\n if c == ']':\n height[i] = height[matching[i]]\n continue\n balance = 1\n for j in range(i + 1, n):\n if s[j] == '[':\n balance += 1\n elif s[j] == ']':\n balance -= 1\n height[i] = max(height[i], balance)\n if balance == 0:\n matching[i] = j\n matching[j] = i\n break\n\nmax_height = max(height)\ncur_height, prev_height = max_height, -1\ncolumns = []\n\nm = 2 * max_height + 1\n\ndef draw_bar(pos, height):\n while len(columns) <= pos:\n columns.append([' ' for _ in range(m)])\n upper_plus = max_height - height\n lower_plus = m - upper_plus - 1\n \n columns[pos][upper_plus] = columns[pos][lower_plus] = '+'\n for i in range(upper_plus + 1, lower_plus):\n columns[pos][i] = '|'\n\ndef draw_lines(pos, height):\n while len(columns) <= pos:\n columns.append([' ' for _ in range(m)])\n\n upper_minus = max_height - height\n lower_minus = m - upper_minus - 1\n\n columns[pos][upper_minus] = columns[pos][lower_minus] = '-'\n\npos, h = 0, max_height\nfor i, c in enumerate(s):\n if i > 0:\n if c == ']' and s[i-1] == '[':\n pos += 3\n if c == '[' and s[i-1] == '[':\n h -= 1\n elif c == ']' and s[i-1] == ']':\n h += 1\n\n draw_bar(pos, h)\n if c == '[':\n draw_lines(pos + 1, h)\n elif c == ']':\n draw_lines(pos - 1, h)\n\n pos += 1\n\nfor i in range(m):\n line = ''.join(column[i] for column in columns).rstrip()\n print(line)\n", "passed": true, "time": 0.14, "memory": 14460.0, "status": "done"}, {"code": "n=int(input())\na=input()\nv=1\nq=0\nmaxlen=0\nfor i in range(1,len(a)):\n if a[i]=='[':\n v+=1\n else:\n v-=1\n if(a[i-1]=='[' and a[i]==']'):\n q+=1\n maxlen=max(maxlen,v)\nv=[[\" \"]*(q*3+n) for i in range(3+ (max(0,maxlen-1)*2))]\ny=3+(max(0,maxlen-1)*2)\nx=0\nw=0\nfor i in range(n):\n if a[i]=='[':\n for j in range(w,y-w):\n if(j==w or j==y-1-w):\n v[j][x]='+'\n v[j][x+1]='-'\n else:\n v[j][x]='|'\n x+=1\n w+=1\n else:\n if(a[i-1]=='['):\n x+=3\n w-=1\n for j in range(w,y-w):\n if(j==w or j==y-1-w):\n v[j][x]='+'\n v[j][x-1]='-'\n else:\n v[j][x]='|'\n x+=1\nfor i in range(3+ (max(0,maxlen-1)*2)):\n for j in range(q*3+n):\n print(v[i][j],end=\"\")\n print() ", "passed": true, "time": 0.16, "memory": 14584.0, "status": "done"}, {"code": "lmap = lambda func, x: list(map(func, x))\n\n\n\n\n_, scobes = input(), input()#'', '[[[][][][][][][][]][]][]'\nscobes = scobes.replace('[]', '[ ]')\n\ndef empty_list(s):\n\treturn [0] * s\n\ndef two_dim_array(size):\n\treturn [empty_list(size[0]) for i in range(size[1])]\n\ndef process_scobes(scobes):\n\n\tdepthes = []\n\tdepth = 0\n\tfor i, scobe in enumerate(scobes):\n\t\tif scobe == '[':\n\t\t\tdepth+=1\n\t\tdepthes.append(depth)\n\n\t\tif scobe == ']':\n\t\t\tdepth-=1\n\n\t\n\tmax_depth = max(depthes)\n\tdepthes = lmap(lambda val: 2*(max_depth - val+1)+1, depthes)\n\treturn depthes\n\ndef set_on_interval(from_, to_):\n\tpass\n\ndef draw_scobes_into_array(scobes, heights):\n\tpicture = two_dim_array([len(scobes), max(heights)])\n\tmiddle = (max(heights) + 1)//2 \n\n\tfor i, scobe in enumerate(scobes):\n\t\th = heights[i] //2 - 1\n\t\tif scobe!=' ':\n\t\t\tfor height in range(middle-h - 1, middle+h):\n\t\t\t\tpicture[height][i] = 1\n\n\t\t\tpicture[middle - h - 2][i] = 2\n\t\t\tpicture[middle + h][i] = 2\n\t\t\toffset = 1 if scobe == '[' else -1\n\t\t\tpicture[middle - h - 2][i + offset] = 3\n\t\t\tpicture[middle + h][i + offset] = 3\n\n\treturn picture\n\n\n\nheights = process_scobes(scobes)\n\npicture = draw_scobes_into_array(scobes, heights)\n\n\ndraw_line = lambda line: ''.join(lmap(str, line)).replace('0', ' ').replace('1', '|').replace('2', '+').replace('3', '-')\nprint('\\n'.join(lmap(draw_line, picture)))\n\n#Here was me!\n", "passed": true, "time": 0.92, "memory": 14824.0, "status": "done"}, {"code": "input()\nmas = input()\nans = [0] * len(mas)\nstack = 0\n\nmaxx = 0\n\nfor i in mas:\n if(i == \"[\"):\n stack += 1\n else:\n stack -= 1\n maxx = max(maxx, stack)\n\n\nstack = []\nfor i in range(len(mas)):\n if(mas[i] == \"[\"):\n stack.append(i)\n else:\n j = stack.pop()\n ans[i] = len(stack)\n ans[j] = len(stack)\n\n\nfor i in range(len(ans)):\n ans[i] = maxx - ans[i]\n\n \ni = 0\nwhile i != len(ans) - 1:\n if(mas[i] == \"[\" and mas[i + 1] == \"]\"):\n mas = mas[:i + 1] + \"___\" + mas[i + 1:]\n ans.insert(i + 1, \"_\")\n ans.insert(i + 1, \"_\")\n ans.insert(i + 1, \"_\")\n i += 2\n i += 1\n\n\nfor i in range(maxx, 0, -1):\n for x in range(len(ans)):\n if(ans[x] == \"_\"):\n if(ans[x - 1] == i or ans[x + 1] == i):\n print(\"-\", end = \"\")\n else:\n print(\" \", end = \"\")\n else:\n if(ans[x] == i):\n print(\"+\", end = \"\")\n elif(ans[x] > i):\n print(\"|\", end = \"\")\n elif(ans[x - 1] == i or ans[x + 1] == i):\n print(\"-\", end = \"\")\n else:\n print(\" \", end = \"\")\n print()\n\n\nfor i in range(0, maxx + 1):\n for x in range(len(ans)):\n if(ans[x] == \"_\"):\n if(ans[x - 1] == i or ans[x + 1] == i):\n print(\"-\", end = \"\")\n else:\n print(\" \", end = \"\")\n else:\n if(ans[x] == i):\n print(\"+\", end = \"\")\n elif(ans[x] > i):\n print(\"|\", end = \"\")\n elif(ans[x - 1] == i or ans[x + 1] == i):\n print(\"-\", end = \"\")\n else:\n print(\" \", end = \"\")\n print()", "passed": true, "time": 0.15, "memory": 14476.0, "status": "done"}, {"code": "n = int(input())\ns = list(input())\n\nmax_len = 0\ncur_len = 0\nfor si in s:\n if si == '[':\n cur_len += 1\n if si == ']':\n cur_len -= 1\n if cur_len > max_len:\n max_len = cur_len\n\ncur_len = 0\nsize = []\nans = []\nfor si in s:\n if si == '[':\n cur_len += 1\n size.append(max_len - cur_len + 1)\n ans.append(size[-1])\n if si == ']':\n cur_len -= 1\n ans.append(size[-1])\n size = size[:-1]\n\n\ndef draw_bracket(pos, size, picture, open):\n start = (len(picture) - 2*size - 1) // 2\n picture[start][pos] = '+'\n if open:\n picture[start][pos + 1] = '-'\n else:\n picture[start][pos - 1] = '-'\n \n picture[len(picture) - start - 1][pos] = '+'\n if open:\n picture[len(picture) - start - 1][pos + 1] = '-'\n else:\n picture[len(picture) - start - 1][pos - 1] = '-'\n \n for i in range(start + 1, len(picture) - start - 1):\n picture[i][pos] = '|'\n\n\ndef draw_picture(picture):\n for i in picture:\n print(''.join(i))\n\n\npic_size = 0\nfor i in range(n):\n pic_size += 1\n if i + 1 < n and s[i] == '[' and s[i + 1] == ']':\n pic_size += 3\n\n\npicture = [[' ']*pic_size for i in range(2*max_len + 1)]\npos = 0\nfor i in range(n):\n if s[i] == '[':\n draw_bracket(pos, ans[i], picture, True)\n if i + 1 < n:\n if s[i + 1] == '[':\n pos += 1\n if s[i + 1] == ']':\n pos += 4\n if s[i] == ']':\n draw_bracket(pos, ans[i], picture, False)\n pos += 1\n\n\ndraw_picture(picture)\n", "passed": true, "time": 0.14, "memory": 14556.0, "status": "done"}, {"code": "input()\nbr = input()\nd = []\ncom = 0\nhmax = 0\nfor i in range(len(br)):\n\tif br[i] == '[':\n\t\td.append({\n\t\t\t'open': True,\n\t\t\t'com': com\n\t\t})\n\t\tcom += 2\n\telse:\n\t\tcom -= 2\n\t\td.append({\n\t\t\t'open': False,\n\t\t\t'com': com\n\t\t})\n\n\tif com > hmax:\n\t\thmax = com\n\nhmax -= 1\n\na = [[] for j in range(hmax + 2)]\ny = 0\nx = 0\nap = True\nfor j in range(len(d)):\n\n\tif ap:\n\t\tfor kek in range(len(a)):\n\t\t\ta[kek].append(' ')\n\telse:\n\t\tap = True\n\n\ti = d[j]\n\ty = i['com'] // 2\n\ty0 = y\n\ta[y][x] = '+'\n\tfor _ in range(hmax - i['com']):\n\t\ty += 1\n\t\ta[y][x] = '|'\n\ty += 1\n\ta[y][x] = '+'\n\n\tif i['open']:\n\t\tfor kek in range(len(a)):\n\t\t\ta[kek].append(' ')\n\t\tap = False\n\t\ta[y0][x + 1] = '-'\n\t\ta[y][x + 1] = '-'\n\telse:\n\t\ta[y0][x - 1] = '-'\n\t\ta[y][x - 1] = '-'\n\ttry:\n\t\tif i['open'] and not d[j + 1]['open']:\n\t\t\tx += 3\n\t\t\tfor kek in range(len(a)):\n\t\t\t\tfor _ in range(3):\n\t\t\t\t\ta[kek].append(' ')\n\texcept:\n\t\tpass\n\n\tx += 1\n\nfor i in a:\n\tprint(*i, sep='')", "passed": true, "time": 0.14, "memory": 14592.0, "status": "done"}, {"code": "import base64\ncode = \"aW5wdXQgKCkjbGluZToxCmJyID1pbnB1dCAoKSNsaW5lOjIKZCA9W10jbGluZTozCmNvbSA9MCAjbGluZTo0CmhtYXggPTAgI2xpbmU6NQpmb3IgaSBpbiByYW5nZSAobGVuIChiciApKTojbGluZTo2CglpZiBiciBbaSBdPT0nWyc6I2xpbmU6NwoJCWQgLmFwcGVuZCAoeydvcGVuJzpUcnVlICwnY29tJzpjb20gfSkjbGluZToxMQoJCWNvbSArPTIgI2xpbmU6MTIKCWVsc2UgOiNsaW5lOjEzCgkJY29tIC09MiAjbGluZToxNAoJCWQgLmFwcGVuZCAoeydvcGVuJzpGYWxzZSAsJ2NvbSc6Y29tIH0pI2xpbmU6MTgKCWlmIGNvbSA+aG1heCA6I2xpbmU6MjAKCQlobWF4ID1jb20gI2xpbmU6MjEKaG1heCAtPTEgI2xpbmU6MjMKYSA9W1tdZm9yIE8wTzAwME8wTzAwTzAwMDBPIGluIHJhbmdlIChobWF4ICsyICldI2xpbmU6MjUKeSA9MCAjbGluZToyNgp4ID0wICNsaW5lOjI3CmFwID1UcnVlICNsaW5lOjI4CmZvciBqIGluIHJhbmdlIChsZW4gKGQgKSk6I2xpbmU6MjkKCWlmIGFwIDojbGluZTozMQoJCWZvciBrZWsgaW4gcmFuZ2UgKGxlbiAoYSApKTojbGluZTozMgoJCQlhIFtrZWsgXS5hcHBlbmQgKCcgJykjbGluZTozMwoJZWxzZSA6I2xpbmU6MzQKCQlhcCA9VHJ1ZSAjbGluZTozNQoJaSA9ZCBbaiBdI2xpbmU6MzcKCXkgPWkgWydjb20nXS8vMiAjbGluZTozOAoJeTAgPXkgI2xpbmU6MzkKCWEgW3kgXVt4IF09JysnI2xpbmU6NDAKCWZvciBfIGluIHJhbmdlIChobWF4IC1pIFsnY29tJ10pOiNsaW5lOjQxCgkJeSArPTEgI2xpbmU6NDIKCQlhIFt5IF1beCBdPSd8JyNsaW5lOjQzCgl5ICs9MSAjbGluZTo0NAoJYSBbeSBdW3ggXT0nKycjbGluZTo0NQoJaWYgaSBbJ29wZW4nXTojbGluZTo0NwoJCWZvciBrZWsgaW4gcmFuZ2UgKGxlbiAoYSApKTojbGluZTo0OAoJCQlhIFtrZWsgXS5hcHBlbmQgKCcgJykjbGluZTo0OQoJCWFwID1GYWxzZSAjbGluZTo1MAoJCWEgW3kwIF1beCArMSBdPSctJyNsaW5lOjUxCgkJYSBbeSBdW3ggKzEgXT0nLScjbGluZTo1MgoJZWxzZSA6I2xpbmU6NTMKCQlhIFt5MCBdW3ggLTEgXT0nLScjbGluZTo1NAoJCWEgW3kgXVt4IC0xIF09Jy0nI2xpbmU6NTUKCXRyeSA6I2xpbmU6NTYKCQlpZiBpIFsnb3BlbiddYW5kIG5vdCBkIFtqICsxIF1bJ29wZW4nXTojbGluZTo1NwoJCQl4ICs9MyAjbGluZTo1OAoJCQlmb3Iga2VrIGluIHJhbmdlIChsZW4gKGEgKSk6I2xpbmU6NTkKCQkJCWZvciBfIGluIHJhbmdlICgzICk6I2xpbmU6NjAKCQkJCQlhIFtrZWsgXS5hcHBlbmQgKCcgJykjbGluZTo2MQoJZXhjZXB0IDojbGluZTo2MgoJCXBhc3MgI2xpbmU6NjMKCXggKz0xICNsaW5lOjY1CmZvciBpIGluIGEgOiNsaW5lOjY3CglwcmludCAoKmkgLHNlcCA9JycpCg==\"\neval(compile(base64.b64decode(code),'<string>','exec'))", "passed": true, "time": 0.17, "memory": 14392.0, "status": "done"}, {"code": "import sys\n\ndef vert(f, d, c, h):\n f[d][c] = '+'\n f[h-1-d][c] = '+'\n for i in range(d+1,h-1-d):\n f[i][c] = '|'\n return f\n\nn = int(input())\ns = sys.stdin.readline().rstrip()\n\nd = 0\nmaxd=1\nfor c in s:\n if c == '[':\n d+=1\n if d>maxd:\n maxd=d\n else:\n d-=1\n\nh = 2*maxd +1\nopcl = s.count(\"[]\")\n\nw = opcl*5 + (len(s) - opcl*2)\n\nf = [[' ']*w for _ in range(h)]\n\nd = 0\nc = 0\nfor i in range(n):\n if s[i] == '[': \n f = vert(f,d,c,h)\n f[d][c+1] = '-'\n f[h-1-d][c+1] = '-' \n d+=1\n else:\n if i>0 and s[i-1] == '[':\n c+=3\n d-=1\n f = vert(f,d,c,h)\n f[d][c-1] = '-'\n f[h-1-d][c-1] = '-'\n \n c+=1\n\nans = [\"\".join(x) for x in f]\nprint(\"\\n\".join(ans))\n", "passed": true, "time": 0.15, "memory": 14456.0, "status": "done"}, {"code": "def draw(ind, type, size):\n nonlocal ans, mid\n ans[mid][ind] = '|'\n for i in range(size // 2):\n ans[mid + i][ind] = '|'\n ans[mid - i][ind] = '|'\n ans[mid + size // 2][ind] = '+'\n ans[mid - size // 2][ind] = '+'\n if type == \"left\":\n ans[mid + size // 2][ind - 1] = '-'\n ans[mid - size // 2][ind - 1] = '-'\n else:\n ans[mid + size // 2][ind + 1] = '-'\n ans[mid - size // 2][ind + 1] = '-'\n\n\nn = int(input())\ns = input()\nmx = 0\ncs = 0\nfor i in range(n):\n if s[i] == \"[\":\n cs += 1\n else:\n cs -= 1\n mx = max(mx, cs)\nmx -= 1\na = [mx]\nfor i in range(1, n):\n if (s[i] == \"[\" and s[i - 1] == \"]\") or (s[i - 1] == \"[\" and s[i] == \"]\"):\n a.append(a[-1])\n elif s[i] == \"[\":\n a.append(a[-1] - 1)\n else:\n a.append(a[-1] + 1)\nans = [[' ' for i in range(n * 3)] for j in range(3 + mx * 2)]\nmid = mx + 1\ndraw(0, \"right\", mx * 2 + 3)\nli = 0\nfor i in range(1, n):\n if s[i] == \"[\" and s[i - 1] == \"]\":\n li += 1\n draw(li, \"right\", a[i] * 2 + 3)\n elif s[i - 1] == \"[\" and s[i] == \"]\":\n li += 4\n draw(li, \"left\", a[i] * 2 + 3)\n elif s[i] == \"[\":\n li += 1\n draw(li, \"right\", a[i] * 2 + 3)\n else:\n li += 1\n draw(li, \"left\", a[i] * 2 + 3)\nfor i in ans:\n for j in range(li + 1):\n print(i[j], end=\"\")\n print()\n", "passed": true, "time": 0.17, "memory": 14632.0, "status": "done"}, {"code": "input()\na = input()\nfield = [[\" \" for j in range(500)] for i in range(500)]\nmxb = -1\nb = 0\nfor i in range(len(a)):\n if a[i] == \"[\":\n b += 1\n else:\n b -= 1\n mxb = max(mxb, b)\nm = (mxb * 2 + 1) // 2 \n\ndef opn(curpos, curb):\n up = mxb - curb + 1\n for i in range(up):\n field[m + i][curpos] = \"|\"\n for i in range(up):\n field[m - i][curpos] = \"|\"\n field[m + up][curpos] = \"+\"\n field[m - up][curpos] = \"+\"\n field[m + up][curpos + 1] = \"-\"\n field[m - up][curpos + 1] = \"-\"\n \n \ndef clos(curpos,curb):\n up = mxb - curb + 1\n for i in range(up):\n field[m + i][curpos] = \"|\"\n for i in range(up):\n field[m - i][curpos] = \"|\"\n field[m + up][curpos] = \"+\"\n field[m - up][curpos] = \"+\"\n field[m + up][curpos - 1] = \"-\"\n field[m - up][curpos - 1] = \"-\" \n \n \ncurb = 0\npos = 0\nfor i in range(len(a)):\n if a[i] == \"[\":\n curb += 1\n opn(pos,curb)\n pos += 1\n else:\n if a[i - 1] == \"[\":\n pos += 3\n clos(pos,curb)\n curb -= 1\n pos += 1\nans = []\nfor i in range(len(field)):\n lst = -1\n for j in range(len(field[0])):\n if field[i][j] != \" \":\n lst = j \n ans.append(lst + 1)\nfor i in range(len(field)):\n for j in range(ans[i]):\n print(field[i][j],end=\"\")\n if ans[i]:\n print()\n ", "passed": true, "time": 1.32, "memory": 14404.0, "status": "done"}, {"code": "n = input()\ns = input()\nbal = []\n\ncurbal = 0\nmaxbal = 0\nfor i in s:\n if i == '[':\n bal.append((curbal, 1)) \n curbal += 1\n maxbal = max(curbal, maxbal)\n else:\n bal.append((curbal, -1))\n curbal -= 1 \n \nbal = [(maxbal - i, j) for (i, j) in bal]\nstack = []\nans = [[] for _ in range(2 * maxbal + 1)]\n\nfor i in range(len(bal)):\n if bal[i][1] == 1:\n stack.append(bal[i][0])\n if i == 0 or bal[i - 1][1] == 1: \n for j in range(maxbal - bal[i][0]):\n ans[j].append(\" \")\n ans[maxbal - bal[i][0]].append(\"+-\")\n for j in range(maxbal - bal[i][0] + 1, maxbal + bal[i][0]):\n ans[j].append(\"|\")\n ans[maxbal + bal[i][0]].append(\"+-\")\n for j in range(maxbal + bal[i][0] + 1, 2 * maxbal + 1):\n ans[j].append(\" \")\n else:\n for j in range(maxbal - bal[i][0]):\n ans[j].append(\" \")\n ans[maxbal - bal[i][0]].append(\"+-\")\n for j in range(maxbal - bal[i][0] + 1, maxbal + bal[i][0]):\n ans[j].append(\"|\")\n ans[maxbal + bal[i][0]].append(\"+-\")\n for j in range(maxbal + bal[i][0] + 1, 2 * maxbal + 1):\n ans[j].append(\" \") \n else:\n if bal[i - 1][1] == 1:\n for j in range(2 * maxbal + 1):\n ans[j].append(\" \")\n for j in range(maxbal - stack[-1]):\n ans[j].append(\" \")\n ans[maxbal - stack[-1]].append(\"-+\")\n for j in range(maxbal - stack[-1] + 1, maxbal + stack[-1]):\n ans[j].append(\" |\")\n ans[maxbal + stack[-1]].append(\"-+\")\n for j in range(maxbal + stack[-1] + 1, 2 * maxbal + 1):\n ans[j].append(\" \") \n else:\n for j in range(maxbal - stack[-1]):\n ans[j].append(\" \")\n ans[maxbal - stack[-1]].append(\"-+\")\n for j in range(maxbal - stack[-1] + 1, maxbal + stack[-1]):\n ans[j].append(\"|\")\n ans[maxbal + stack[-1]].append(\"-+\")\n for j in range(maxbal + stack[-1] + 1, 2 * maxbal + 1):\n ans[j].append(\" \") \n stack.pop()\nfor i in ans:\n print(''.join(i))", "passed": true, "time": 0.16, "memory": 14476.0, "status": "done"}, {"code": "#This code is dedicated to Olya S.\nl=int(input())\nn=input()\n\ndef offset(ml,x):\n return (ml-x)//2\n\ndef getstate(g,line,ml):\n off=offset(ml,g[0])\n if line<off or line>=g[0]+off:\n return 0\n elif line==off or line == g[0]+off-1:\n return 1\n else:\n return 2\n \n \n \n\n#Find max bracket#\nml=1\ncl=1\nfor b in n:\n if b=='[':\n cl+=2\n if ml<cl:\n ml=cl\n else:\n cl-=2\n######MAP######\nsc=[]\nfor b in n:\n if b=='[':\n sc.append([ml,True])\n ml-=2\n else:\n ml+=2\n sc.append([ml,False])\n#####################\nfor i in range(ml):\n for j in range(l):\n g=sc[j]\n state=getstate(g,i,ml)\n if state==1:\n if g[1]:\n print('+-',end='')\n else:\n print('-+',end='')\n elif state==0:\n if sc[j-1][0]-sc[j][0]!=2:\n print(' ',end='')\n else:\n print('|',end='')\n if sc[j][1] and not sc[j+1][1]:\n if state==2:\n print(' ',end='')\n else:\n print(' ',end='')\n \n print()\n\n \n\n\n\n\n\n\n \n", "passed": true, "time": 0.15, "memory": 14408.0, "status": "done"}, {"code": "def getHeight(s: str) -> int:\n h = maxh = 0\n for c in s:\n h += (1 if c == '[' else -1)\n maxh = max(h, maxh)\n return maxh\n\n\ndef makeColumn(height: int, maximumHeight: int) -> str:\n half = (maximumHeight - height) * [' '] + ['+'] + height * ['|']\n return half + half[-2::-1]\n\n\nn, s = int(input()), input()\nh = getHeight(s)\nans = [makeColumn(h, h)]\ncurh = h - 1\nfor i in range(1, n):\n if s[i] == ']':\n if s[i - 1] == '[':\n for j in range(3):\n ans.append([' '] * (h * 2 + 1))\n curh += 1\n ans.append(makeColumn(curh, h))\n else:\n ans.append(makeColumn(curh, h))\n curh -= 1\nfor line in zip(*ans):\n for i in range(len(line)):\n if ((i > 0 and line[i - 1] == '+') or\n (i < len(line) - 1 and line[i + 1] == '+')) and line[i] == ' ':\n print('-', end='')\n else:\n print(line[i], end='')\n print()\n", "passed": true, "time": 0.15, "memory": 14412.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nbal = 0\nm = 0\nv = [0] * n\nfor i in range(n):\n if s[i] == '[':\n bal += 1\n v[i] = bal\n m = max(m, bal)\n else:\n v[i] = -bal\n bal -= 1\nfor j in range(1, 2 * m + 2):\n for i in range(0, n):\n if abs(v[i]) == j or abs(v[i]) == 2 * (m + 1) - j:\n if v[i] > 0:\n print('+-', end = '')\n else:\n print('-+', end = '')\n elif abs(v[i]) < j and abs(v[i]) < 2 * (m + 1) - j:\n print('|', end = '')\n if i + 1 < n and v[i + 1] < 0 and v[i] == -v[i + 1]:\n print(' ', end = '')\n else:\n print(' ', end = '')\n if i > 0 and abs(v[i - 1]) >= abs(v[i]) and i + 1 < n and abs(v[i + 1]) >= abs(v[i]):\n print(' ', end = '')\n if i + 1 < n and v[i + 1] < 0 and v[i] == -v[i + 1]:\n print(' ', end = '')\n print()\n\n \n", "passed": true, "time": 0.16, "memory": 14556.0, "status": "done"}, {"code": "n = input()\ns = input()\n\nb = 0\nmaxb = 0\nfor c in s:\n if c == '[':\n b += 1\n else:\n b -= 1\n if b > maxb:\n maxb = b\n\nres = [\"\"] * (maxb * 2 + 1)\nb = maxb\npred = \"\"\n\nfor k in range(len(s)):\n c = s[k]\n \n if c == '[':\n if k != len(s) - 1:\n if s[k+1] == ']':\n sep = '| '\n else:\n sep = '|'\n else:\n sep = '|'\n \n i = maxb - b\n for j in range(i):\n res[j] += ' '\n \n res[i] += '+-' \n for j in range(i + 1, len(res) - i - 1):\n res[j] += sep\n res[len(res) - i - 1] += '+-'\n\n for j in range(len(res) - i, len(res)):\n res[j] += ' '\n \n pred = '['\n b -= 1\n \n elif c == ']':\n if k != len(s) - 1:\n if s[k+1] == '[':\n space = ' '\n else:\n space = ' '\n else:\n space = ' '\n \n b += 1\n if pred == '[':\n sep = ' |'\n for j in range(len(res)):\n res[j] += ' '\n else:\n sep = '|'\n \n i = maxb - b\n for j in range(i):\n res[j] += space\n \n res[i] += '-+' \n for j in range(i + 1, len(res) - i - 1):\n res[j] += sep \n res[len(res) - i - 1] += '-+'\n\n for j in range(len(res) - i, len(res)):\n res[j] += space\n \n pred = ']'\n\nfor i in res:\n print(i)\n\n\n\n\n \n\n\n\n", "passed": true, "time": 0.14, "memory": 14440.0, "status": "done"}, {"code": "_, s = input(), input()\n\nMAX_H = 1 + 2 * max(s.count('[', 0, i) - s.count(']', 0, i) for i in range(len(s) + 1))\n\nline = lambda d: '+'.join((' ' * d, '|' * (MAX_H - 2 * d - 2), ' ' * d))\n\ndef draw(s, i, d):\n return [line(d)] if s[i] == '[' else ([' ' * MAX_H] * 3 if s[i - 1] == '[' else []) + [line(d - 1)]\n\n[print(''.join(x).replace('+ ', '+-').replace(' +', '-+')) for x in zip(*sum((draw(s, i, s.count('[', 0, i) - s.count(']', 0, i)) for i in range(len(s))), []))]\n", "passed": true, "time": 0.16, "memory": 14316.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nt = set()\na = [0]*len(s)\nq = 0\nm = 0\nans = []\nfor i in range(len(s)):\n if(s[i]=='['):\n q+=1\n a[i]=q\n m=max(m,q)\n else:\n a[i]=q\n q-=1\n m = max(m,q)\n if(s[i-1]=='['):\n t.add(i-1)\nfor i in range(m+1):\n e=''\n for j in range(len(s)):\n if(a[j]-1==i):\n if(s[j]=='['):\n e+='+-'\n if(j in t):\n e+=' '\n else:\n e+='-+'\n elif(a[j]-1<i):\n if(s[j]=='['):\n e+='|'\n if(j in t):\n e+=' '\n elif(s[j]==']'):\n if(j-1 in t):\n e+=' '\n e+='|'\n else:\n if(s[j]=='['):\n if(j>0 and s[j-1]==']' and a[j-1]==a[j]):\n e+=' '\n e+=' '\n if(j in t):\n e+=' '\n else:\n if(j!=len(s)-1 and s[j+1]!=']'):\n e+=' '\n e+=' '\n ans+=[e]\nfor i in range(len(ans)):\n print(ans[i])\nfor i in range(len(ans)-2,-1,-1):\n print(ans[i])\n\n", "passed": true, "time": 0.14, "memory": 14560.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sat Mar 11 23:20:54 2017\n\n@author: Alexandr\n\"\"\"\n\nn = int(input())\nbrackets = input()\nmax_deep = 0\ndeep = [0] * n\nd = 0\nfor i in range(n):\n if brackets[i] == '[':\n d += 1\n deep[i] = d\n else:\n deep[i] = d\n d -= 1\n\nmax_deep = max(deep)\n\nans = []\nheight = max_deep * 2 + 1\n\nfor i in range(n):\n x = (max_deep - deep[i]) * 2 + 1\n y = (height - x - 2) // 2 \n s = '+' + '|'*x + '+'\n if (\n i != 0 \n and brackets[i] == ']' \n and brackets[i - 1] == '['\n ):\n ans.append(y * ' ' + '-' + x * ' ' + '-' + y * ' ')\n ans.append(' ' * height) \n ans.append(y * ' ' + '-' + x * ' ' + '-' + y * ' ')\n if (\n i != 0 and i != n - 1\n and deep[i] != 1 \n and (deep[i] > deep[i - 1] or deep[i] > deep[i + 1])\n ):\n s = (y - 1) * ' ' + '-' + s + '-' + (y - 1) * ' '\n \n else:\n s = y * ' ' + s + y * ' '\n ans.append(s)\n\nfor i in zip(*ans):\n print(''.join(i))", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "def Paint(height,napr):\n return ''\nrngOfseq=int(input())\nseq=input()\nmaxh=3\nheightes=[]\ncurrent=1\ntek=3\nfor i in range(rngOfseq-1):#maxh\n if seq[i]=='[' and seq[i+1]=='[':\n tek+=2\n if seq[i]==']' and seq[i+1]==']':\n tek-=2\n if maxh<tek:\n maxh=tek\ncurrent=maxh\nfor i in range(rngOfseq-1):#heightes\n heightes.append(current)\n if seq[i]=='[' and seq[i+1]=='[':\n current-=2\n if seq[i]==']' and seq[i+1]==']':\n current+=2\nheightes.append(current)\ncurrent=maxh\nFlag=True\nfor j in range(maxh):#draw\n currentraw=''\n for i in range(rngOfseq):\n if heightes[i]==current:\n if seq[i]=='[':\n currentraw+='+-'\n else:\n currentraw+='-+'\n elif heightes[i]>current:\n currentraw+='|'\n else:\n currentraw+=' '\n try:\n if heightes[i]==heightes[i+1]:\n if heightes[i]==current:\n if seq[i] =='[' and seq[i+1]==']':\n currentraw+=' '\n elif heightes[i]<current:\n if seq[i] ==']' and seq[i+1]=='[':\n currentraw+=' '\n if seq[i] =='[' and seq[i+1]==']':\n currentraw+=' '\n else:\n if seq[i] =='[' and seq[i+1]==']':\n currentraw+=' '\n except:\n continue\n if current==1:\n Flag=False\n if Flag:\n current-=2\n else:\n current+=2\n print(currentraw)", "passed": true, "time": 0.23, "memory": 14552.0, "status": "done"}, {"code": "def empty(d):\n\tt = '+- -+'\n\tres = [t]\n\tfor i in range(2 * d - 1): res.append('| |')\n\tres.append('+- -+')\n\treturn res\n\ndef cover(l):\n\tnumspaces = len(l[0]) - 2\n\tspaces = numspaces * ' '\n\ttb = '+-' + spaces + '-+'\n\tres = [tb]\n\tfor s in l:\n\t\tns = '|' + s + '|'\n\t\tres.append(ns)\n\tres.append(tb)\n\treturn res\n\ndef do(s, d):\n\tblocks = list()\n\tstart = 0\n\tbalance = 0\n\tfor right in range(len(s)):\n\t\tif s[right] == '[':\n\t\t\tbalance += 1\n\t\telse: \n\t\t\tbalance -= 1\n\t\tif balance == 0:\n\t\t\tif start + 1 == right:\n\t\t\t\tblocks.append(empty(d))\n\t\t\telse:\n\t\t\t\tinner = do(s[start + 1 : right], d - 1)\n\t\t\t\tcovered = cover(inner)\n\t\t\t\tblocks.append(covered)\n\t\t\tstart = right + 1\n\tres = [\"\" for _ in range(2 * d + 1)]\n\tfor block in blocks:\n\t\tfor i in range(len(block)):\n\t\t\tres[i] += block[i]\n\treturn res\n\ndef depth(s):\n\tres = 0\n\tcur = 0\n\tfor c in s:\n\t\tif c == '[':\n\t\t\tcur += 1\n\t\telse:\n\t\t\tcur -= 1\n\t\tres = max(res, cur)\n\treturn res\n\nn = int(input())\ns = input()\nfor l in do(s, depth(s)):\n\tprint(l)", "passed": true, "time": 0.14, "memory": 14616.0, "status": "done"}]
[{"input": "8\n[[][]][]\n", "output": "+- -++- -+\n|+- -++- -+|| |\n|| || ||| |\n|+- -++- -+|| |\n+- -++- -+\n"}, {"input": "6\n[[[]]]\n", "output": "+- -+\n|+- -+|\n||+- -+||\n||| |||\n||+- -+||\n|+- -+|\n+- -+\n"}, {"input": "6\n[[][]]\n", "output": "+- -+\n|+- -++- -+|\n|| || ||\n|+- -++- -+|\n+- -+\n"}, {"input": "2\n[]\n", "output": "+- -+\n| |\n+- -+\n"}, {"input": "4\n[][]\n", "output": "+- -++- -+\n| || |\n+- -++- -+\n"}, {"input": "4\n[[]]\n", "output": "+- -+\n|+- -+|\n|| ||\n|+- -+|\n+- -+\n"}, {"input": "6\n[][][]\n", "output": "+- -++- -++- -+\n| || || |\n+- -++- -++- -+\n"}, {"input": "6\n[][[]]\n", "output": "+- -++- -+\n| ||+- -+|\n| ||| ||\n| ||+- -+|\n+- -++- -+\n"}, {"input": "6\n[[]][]\n", "output": "+- -++- -+\n|+- -+|| |\n|| ||| |\n|+- -+|| |\n+- -++- -+\n"}, {"input": "8\n[[]][[]]\n", "output": "+- -++- -+\n|+- -+||+- -+|\n|| |||| ||\n|+- -+||+- -+|\n+- -++- -+\n"}, {"input": "10\n[[[]][[]]]\n", "output": "+- -+\n|+- -++- -+|\n||+- -+||+- -+||\n||| |||| |||\n||+- -+||+- -+||\n|+- -++- -+|\n+- -+\n"}, {"input": "8\n[][][][]\n", "output": "+- -++- -++- -++- -+\n| || || || |\n+- -++- -++- -++- -+\n"}, {"input": "8\n[[][][]]\n", "output": "+- -+\n|+- -++- -++- -+|\n|| || || ||\n|+- -++- -++- -+|\n+- -+\n"}, {"input": "8\n[[][[]]]\n", "output": "+- -+\n|+- -++- -+|\n|| ||+- -+||\n|| ||| |||\n|| ||+- -+||\n|+- -++- -+|\n+- -+\n"}, {"input": "8\n[[[]][]]\n", "output": "+- -+\n|+- -++- -+|\n||+- -+|| ||\n||| ||| ||\n||+- -+|| ||\n|+- -++- -+|\n+- -+\n"}, {"input": "8\n[][[][]]\n", "output": "+- -++- -+\n| ||+- -++- -+|\n| ||| || ||\n| ||+- -++- -+|\n+- -++- -+\n"}, {"input": "8\n[[]][[]]\n", "output": "+- -++- -+\n|+- -+||+- -+|\n|| |||| ||\n|+- -+||+- -+|\n+- -++- -+\n"}, {"input": "8\n[[]][][]\n", "output": "+- -++- -++- -+\n|+- -+|| || |\n|| ||| || |\n|+- -+|| || |\n+- -++- -++- -+\n"}, {"input": "8\n[][[]][]\n", "output": "+- -++- -++- -+\n| ||+- -+|| |\n| ||| ||| |\n| ||+- -+|| |\n+- -++- -++- -+\n"}, {"input": "8\n[][][[]]\n", "output": "+- -++- -++- -+\n| || ||+- -+|\n| || ||| ||\n| || ||+- -+|\n+- -++- -++- -+\n"}, {"input": "8\n[[[][]]]\n", "output": "+- -+\n|+- -+|\n||+- -++- -+||\n||| || |||\n||+- -++- -+||\n|+- -+|\n+- -+\n"}, {"input": "10\n[[[[[]]]]]\n", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n||||| |||||\n||||+- -+||||\n|||+- -+|||\n||+- -+||\n|+- -+|\n+- -+\n"}, {"input": "14\n[[[][[[[]]]]]]\n", "output": "+- -+\n|+- -+|\n||+- -++- -+||\n||| ||+- -+|||\n||| |||+- -+||||\n||| ||||+- -+|||||\n||| ||||| ||||||\n||| ||||+- -+|||||\n||| |||+- -+||||\n||| ||+- -+|||\n||+- -++- -+||\n|+- -+|\n+- -+\n"}, {"input": "10\n[[[[[]]]]]\n", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n||||| |||||\n||||+- -+||||\n|||+- -+|||\n||+- -+||\n|+- -+|\n+- -+\n"}, {"input": "14\n[[[[]][[[]]]]]\n", "output": "+- -+\n|+- -+|\n||+- -++- -+||\n|||+- -+||+- -+|||\n|||| ||||+- -+||||\n|||| ||||| |||||\n|||| ||||+- -+||||\n|||+- -+||+- -+|||\n||+- -++- -+||\n|+- -+|\n+- -+\n"}, {"input": "10\n[[[[][]]]]\n", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -++- -+|||\n|||| || ||||\n|||+- -++- -+|||\n||+- -+||\n|+- -+|\n+- -+\n"}, {"input": "14\n[[[[[[[]]]]]]]\n", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n|||||+- -+|||||\n||||||+- -+||||||\n||||||| |||||||\n||||||+- -+||||||\n|||||+- -+|||||\n||||+- -+||||\n|||+- -+|||\n||+- -+||\n|+- -+|\n+- -+\n"}, {"input": "10\n[[[][[]]]]\n", "output": "+- -+\n|+- -+|\n||+- -++- -+||\n||| ||+- -+|||\n||| ||| ||||\n||| ||+- -+|||\n||+- -++- -+||\n|+- -+|\n+- -+\n"}, {"input": "14\n[[[[[]][][]]]]\n", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -++- -++- -+|||\n||||+- -+|| || ||||\n||||| ||| || ||||\n||||+- -+|| || ||||\n|||+- -++- -++- -+|||\n||+- -+||\n|+- -+|\n+- -+\n"}, {"input": "10\n[[[]]][[]]\n", "output": "+- -++- -+\n|+- -+||+- -+|\n||+- -+|||| ||\n||| ||||| ||\n||+- -+|||| ||\n|+- -+||+- -+|\n+- -++- -+\n"}, {"input": "14\n[[[[[[[]]]]]]]\n", "output": "+- -+\n|+- -+|\n||+- -+||\n|||+- -+|||\n||||+- -+||||\n|||||+- -+|||||\n||||||+- -+||||||\n||||||| |||||||\n||||||+- -+||||||\n|||||+- -+|||||\n||||+- -+||||\n|||+- -+|||\n||+- -+||\n|+- -+|\n+- -+\n"}, {"input": "10\n[[][[[]]]]\n", "output": "+- -+\n|+- -++- -+|\n|| ||+- -+||\n|| |||+- -+|||\n|| |||| ||||\n|| |||+- -+|||\n|| ||+- -+||\n|+- -++- -+|\n+- -+\n"}, {"input": "14\n[[[[[]]]][[]]]\n", "output": "+- -+\n|+- -++- -+|\n||+- -+||+- -+||\n|||+- -+|||| |||\n||||+- -+||||| |||\n||||| |||||| |||\n||||+- -+||||| |||\n|||+- -+|||| |||\n||+- -+||+- -+||\n|+- -++- -+|\n+- -+\n"}, {"input": "10\n[[[][]]][]\n", "output": "+- -++- -+\n|+- -+|| |\n||+- -++- -+||| |\n||| || |||| |\n||+- -++- -+||| |\n|+- -+|| |\n+- -++- -+\n"}, {"input": "14\n[[[[[]]]]][[]]\n", "output": "+- -++- -+\n|+- -+||+- -+|\n||+- -+|||| ||\n|||+- -+||||| ||\n||||+- -+|||||| ||\n||||| ||||||| ||\n||||+- -+|||||| ||\n|||+- -+||||| ||\n||+- -+|||| ||\n|+- -+||+- -+|\n+- -++- -+\n"}, {"input": "10\n[[[][]]][]\n", "output": "+- -++- -+\n|+- -+|| |\n||+- -++- -+||| |\n||| || |||| |\n||+- -++- -+||| |\n|+- -+|| |\n+- -++- -+\n"}, {"input": "14\n[[[[]][]][[]]]\n", "output": "+- -+\n|+- -++- -+|\n||+- -++- -+||+- -+||\n|||+- -+|| |||| |||\n|||| ||| |||| |||\n|||+- -+|| |||| |||\n||+- -++- -+||+- -+||\n|+- -++- -+|\n+- -+\n"}, {"input": "10\n[[]][][[]]\n", "output": "+- -++- -++- -+\n|+- -+|| ||+- -+|\n|| ||| ||| ||\n|+- -+|| ||+- -+|\n+- -++- -++- -+\n"}, {"input": "14\n[[][]][[]][][]\n", "output": "+- -++- -++- -++- -+\n|+- -++- -+||+- -+|| || |\n|| || |||| ||| || |\n|+- -++- -+||+- -+|| || |\n+- -++- -++- -++- -+\n"}, {"input": "10\n[[]][[[]]]\n", "output": "+- -++- -+\n|+- -+||+- -+|\n|| ||||+- -+||\n|| ||||| |||\n|| ||||+- -+||\n|+- -+||+- -+|\n+- -++- -+\n"}, {"input": "14\n[[[]]][[[[]]]]\n", "output": "+- -++- -+\n|+- -+||+- -+|\n||+- -+||||+- -+||\n||| ||||||+- -+|||\n||| ||||||| ||||\n||| ||||||+- -+|||\n||+- -+||||+- -+||\n|+- -+||+- -+|\n+- -++- -+\n"}, {"input": "10\n[[[[]]][]]\n", "output": "+- -+\n|+- -++- -+|\n||+- -+|| ||\n|||+- -+||| ||\n|||| |||| ||\n|||+- -+||| ||\n||+- -+|| ||\n|+- -++- -+|\n+- -+\n"}, {"input": "14\n[[[]][]][[]][]\n", "output": "+- -++- -++- -+\n|+- -++- -+||+- -+|| |\n||+- -+|| |||| ||| |\n||| ||| |||| ||| |\n||+- -+|| |||| ||| |\n|+- -++- -+||+- -+|| |\n+- -++- -++- -+\n"}, {"input": "10\n[[[][]]][]\n", "output": "+- -++- -+\n|+- -+|| |\n||+- -++- -+||| |\n||| || |||| |\n||+- -++- -+||| |\n|+- -+|| |\n+- -++- -+\n"}, {"input": "14\n[[[[[]]][]]][]\n", "output": "+- -++- -+\n|+- -+|| |\n||+- -++- -+||| |\n|||+- -+|| |||| |\n||||+- -+||| |||| |\n||||| |||| |||| |\n||||+- -+||| |||| |\n|||+- -+|| |||| |\n||+- -++- -+||| |\n|+- -+|| |\n+- -++- -+\n"}, {"input": "10\n[[][[]][]]\n", "output": "+- -+\n|+- -++- -++- -+|\n|| ||+- -+|| ||\n|| ||| ||| ||\n|| ||+- -+|| ||\n|+- -++- -++- -+|\n+- -+\n"}, {"input": "14\n[[]][][[]][][]\n", "output": "+- -++- -++- -++- -++- -+\n|+- -+|| ||+- -+|| || |\n|| ||| ||| ||| || |\n|+- -+|| ||+- -+|| || |\n+- -++- -++- -++- -++- -+\n"}, {"input": "10\n[][[[][]]]\n", "output": "+- -++- -+\n| ||+- -+|\n| |||+- -++- -+||\n| |||| || |||\n| |||+- -++- -+||\n| ||+- -+|\n+- -++- -+\n"}, {"input": "14\n[[]][][[]][[]]\n", "output": "+- -++- -++- -++- -+\n|+- -+|| ||+- -+||+- -+|\n|| ||| ||| |||| ||\n|+- -+|| ||+- -+||+- -+|\n+- -++- -++- -++- -+\n"}, {"input": "10\n[[[][][]]]\n", "output": "+- -+\n|+- -+|\n||+- -++- -++- -+||\n||| || || |||\n||+- -++- -++- -+||\n|+- -+|\n+- -+\n"}, {"input": "14\n[[][][]][[][]]\n", "output": "+- -++- -+\n|+- -++- -++- -+||+- -++- -+|\n|| || || |||| || ||\n|+- -++- -++- -+||+- -++- -+|\n+- -++- -+\n"}, {"input": "30\n[[[[][]][]]][][[[][[]]][[]][]]\n", "output": "+- -++- -++- -+\n|+- -+|| ||+- -++- -++- -+|\n||+- -++- -+||| |||+- -++- -+||+- -+|| ||\n|||+- -++- -+|| |||| |||| ||+- -+|||| ||| ||\n|||| || ||| |||| |||| ||| ||||| ||| ||\n|||+- -++- -+|| |||| |||| ||+- -+|||| ||| ||\n||+- -++- -+||| |||+- -++- -+||+- -+|| ||\n|+- -+|| ||+- -++- -++- -+|\n+- -++- -++- -+\n"}, {"input": "10\n[[][]][][]\n", "output": "+- -++- -++- -+\n|+- -++- -+|| || |\n|| || ||| || |\n|+- -++- -+|| || |\n+- -++- -++- -+\n"}, {"input": "14\n[[][][][][]][]\n", "output": "+- -++- -+\n|+- -++- -++- -++- -++- -+|| |\n|| || || || || ||| |\n|+- -++- -++- -++- -++- -+|| |\n+- -++- -+\n"}, {"input": "30\n[[]][[[[]]][]][[[[][]][]]][[]]\n", "output": "+- -++- -++- -++- -+\n|+- -+||+- -++- -+||+- -+||+- -+|\n|| ||||+- -+|| ||||+- -++- -+|||| ||\n|| |||||+- -+||| |||||+- -++- -+|| ||||| ||\n|| |||||| |||| |||||| || ||| ||||| ||\n|| |||||+- -+||| |||||+- -++- -+|| ||||| ||\n|| ||||+- -+|| ||||+- -++- -+|||| ||\n|+- -+||+- -++- -+||+- -+||+- -+|\n+- -++- -++- -++- -+\n"}, {"input": "10\n[][[]][][]\n", "output": "+- -++- -++- -++- -+\n| ||+- -+|| || |\n| ||| ||| || |\n| ||+- -+|| || |\n+- -++- -++- -++- -+\n"}, {"input": "14\n[[]][[[]][][]]\n", "output": "+- -++- -+\n|+- -+||+- -++- -++- -+|\n|| ||||+- -+|| || ||\n|| ||||| ||| || ||\n|| ||||+- -+|| || ||\n|+- -+||+- -++- -++- -+|\n+- -++- -+\n"}, {"input": "10\n[[[][]][]]\n", "output": "+- -+\n|+- -++- -+|\n||+- -++- -+|| ||\n||| || ||| ||\n||+- -++- -+|| ||\n|+- -++- -+|\n+- -+\n"}, {"input": "14\n[[[]][]][[]][]\n", "output": "+- -++- -++- -+\n|+- -++- -+||+- -+|| |\n||+- -+|| |||| ||| |\n||| ||| |||| ||| |\n||+- -+|| |||| ||| |\n|+- -++- -+||+- -+|| |\n+- -++- -++- -+\n"}, {"input": "10\n[[[]]][][]\n", "output": "+- -++- -++- -+\n|+- -+|| || |\n||+- -+||| || |\n||| |||| || |\n||+- -+||| || |\n|+- -+|| || |\n+- -++- -++- -+\n"}, {"input": "14\n[[[][][]][][]]\n", "output": "+- -+\n|+- -++- -++- -+|\n||+- -++- -++- -+|| || ||\n||| || || ||| || ||\n||+- -++- -++- -+|| || ||\n|+- -++- -++- -+|\n+- -+\n"}, {"input": "30\n[][[][[][][][]][]][][[][]][][]\n", "output": "+- -++- -++- -++- -++- -++- -+\n| ||+- -++- -++- -+|| ||+- -++- -+|| || |\n| ||| ||+- -++- -++- -++- -+|| ||| ||| || ||| || |\n| ||| ||| || || || ||| ||| ||| || ||| || |\n| ||| ||+- -++- -++- -++- -+|| ||| ||| || ||| || |\n| ||+- -++- -++- -+|| ||+- -++- -+|| || |\n+- -++- -++- -++- -++- -++- -+\n"}, {"input": "10\n[[]][][][]\n", "output": "+- -++- -++- -++- -+\n|+- -+|| || || |\n|| ||| || || |\n|+- -+|| || || |\n+- -++- -++- -++- -+\n"}, {"input": "14\n[[][]][][][][]\n", "output": "+- -++- -++- -++- -++- -+\n|+- -++- -+|| || || || |\n|| || ||| || || || |\n|+- -++- -+|| || || || |\n+- -++- -++- -++- -++- -+\n"}]
275
Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number $q = \frac{\sqrt{5} + 1}{2}$, in particular that q^2 = q + 1, and she thinks it would make a good base for her new unique system. She called it "golden system". In golden system the number is a non-empty string containing 0's and 1's as digits. The decimal value of expression a_0a_1...a_{n} equals to $\sum_{i = 0}^{n} a_{i} \cdot q^{n - i}$. Soon Piegirl found out that this system doesn't have same properties that integer base systems do and some operations can not be performed on it. She wasn't able to come up with a fast way of comparing two numbers. She is asking for your help. Given two numbers written in golden system notation, determine which of them has larger decimal value. -----Input----- Input consists of two lines β€” one for each number. Each line contains non-empty string consisting of '0' and '1' characters. The length of each string does not exceed 100000. -----Output----- Print ">" if the first number is larger, "<" if it is smaller and "=" if they are equal. -----Examples----- Input 1000 111 Output < Input 00100 11 Output = Input 110 101 Output > -----Note----- In the first example first number equals to $((\sqrt{5} + 1) / 2)^{3} \approx 1.618033988^{3} \approx 4.236$, while second number is approximately 1.618033988^2 + 1.618033988 + 1 β‰ˆ 5.236, which is clearly a bigger number. In the second example numbers are equal. Each of them is β‰ˆ 2.618.
interview
[{"code": "u = v = 0\na, b = input(), input()\nn, m = len(a), len(b)\nif n > m: b = '0' * (n - m) + b\nelse: a = '0' * (m - n) + a\nfor i in range(max(n, m)):\n u, v = v + u, u + int(a[i]) - int(b[i])\n if u > 1:\n print('>')\n return\n elif u < -1:\n print('<')\n return\nd = 2 * v + u\nif u == v == 0: print('=')\nelif u >= 0 and d >= 0: print('>')\nelif u <= 0 and d <= 0: print('<')\nelse: print('>' if (u * u > v * (v + u)) ^ (u < 0) else '<')", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "from itertools import dropwhile, chain\n\n\ndef main():\n zeroes = lambda a: not a\n a, b = [list(chain([0, 0], dropwhile(zeroes, list(map(int, input())))))\n for _ in range(2)]\n\n def tofib(l):\n i = 0\n while i < len(l) - 1:\n if l[i] > 0 and l[i + 1] > 0:\n l[i] -= 1\n l[i + 1] -= 1\n l[i - 1] += 1\n i -= 3\n i += 1\n return l\n\n a = list(dropwhile(zeroes, tofib(a)))\n b = list(dropwhile(zeroes, tofib(b)))\n\n if len(a) < len(b):\n print('<')\n return\n if len(a) > len(b):\n print('>')\n return\n for i in range(len(a)):\n if a[i] < b[i]:\n print('<')\n return\n if a[i] > b[i]:\n print('>')\n return\n print('=')\n\n\ndef __starting_point():\n main()\n\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14560.0, "status": "done"}, {"code": "u = v = 0\na, b = input(), input()\nn, m = len(a), len(b)\nif n > m: b = '0' * (n - m) + b\nelse: a = '0' * (m - n) + a\nfor i in range(max(n, m)):\n u, v = v + u, u + int(a[i]) - int(b[i])\n if u > 1:\n print('>')\n return\n elif u < -1:\n print('<')\n return\nd = 2 * v + u\nif u == v == 0: print('=')\nelif u >= 0 and d >= 0: print('>')\nelif u <= 0 and d <= 0: print('<')\nelse: print('>' if (u * u > v * (v + u)) ^ (u < 0) else '<')", "passed": true, "time": 0.14, "memory": 14564.0, "status": "done"}, {"code": "u = v = 0\n\na, b = input(), input()\n\nn, m = len(a), len(b)\n\nif n > m: b = '0' * (n - m) + b\n\nelse: a = '0' * (m - n) + a\n\nfor i in range(max(n, m)):\n\n u, v = v + u, u + int(a[i]) - int(b[i])\n\n if u > 1:\n\n print('>')\n\n return\n\n elif u < -1:\n\n print('<')\n\n return\n\nd = 2 * v + u\n\nif u == v == 0: print('=')\n\nelif u >= 0 and d >= 0: print('>')\n\nelif u <= 0 and d <= 0: print('<')\n\nelse: print('>' if (u * u > v * (v + u)) ^ (u < 0) else '<')\n\n\n\n# Made By Mostafa_Khaled\n", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}, {"code": "from sys import stdin\ns=list(stdin.readline().strip()[::-1])\ns1=list(stdin.readline().strip()[::-1])\ndef trans(s):\n s.append(\"0\")\n i=len(s)-1\n while i>1:\n while i>=len(s):\n s.append(\"0\")\n if s[i-1]==\"1\" and s[i-2]==\"1\":\n s[i]=\"1\"\n s[i-1]=\"0\"\n s[i-2]=\"0\"\n i+=2\n else:\n i-=1\n while len(s)>0 and s[-1]==\"0\":\n s.pop()\n return s\ns=trans(s)\ns1=trans(s1)\nfor i in range(min(len(s),len(s1))):\n if s[i]==s1[i]:\n s[i]=\"0\"\n s1[i]=\"0\"\nwhile len(s)>0 and s[-1]==\"0\":\n s.pop()\nwhile len(s1)>0 and s1[-1]==\"0\":\n s1.pop()\nif len(s)==len(s1):\n print(\"=\")\nelif(len(s)>len(s1)):\n print(\">\")\nelse:\n print(\"<\")\n", "passed": true, "time": 0.14, "memory": 14556.0, "status": "done"}, {"code": "def clean(d):\n ans = ['0']\n for c in list(d):\n ans.append(c)\n i = len(ans) - 1 #find last index\n while i > 1 and ans[i-2]== '0' and ans[i - 1] == '1' and ans[i] == '1':\n ans[i - 2] = '1'\n ans[i - 1] = '0'\n ans[i] = '0'\n i -= 2\n return ''.join(ans).lstrip('0')\n\na = clean(input())\nb = clean(input())\n#print(a)\n#print(b)\nif a == b:\n print('=')\nelif len(a) > len(b):\n print('>')\nelif len(a) < len(b):\n print('<')\nelif a > b: # now the length are equal\n print('>')\nelse:\n print('<')\n", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}]
[{"input": "1000\n111\n", "output": "<\n"}, {"input": "00100\n11\n", "output": "=\n"}, {"input": "110\n101\n", "output": ">\n"}, {"input": "0\n0\n", "output": "=\n"}, {"input": "1\n10\n", "output": "<\n"}, {"input": "11\n10\n", "output": ">\n"}, {"input": "00111\n10100\n", "output": "<\n"}, {"input": "00\n1\n", "output": "<\n"}, {"input": "01\n010\n", "output": "<\n"}, {"input": "111\n00\n", "output": ">\n"}, {"input": "1100\n11\n", "output": ">\n"}, {"input": "0110\n001\n", "output": ">\n"}, {"input": "1111\n0110\n", "output": ">\n"}, {"input": "01010\n0011\n", "output": ">\n"}, {"input": "0\n1\n", "output": "<\n"}, {"input": "1\n0\n", "output": ">\n"}, {"input": "1\n1\n", "output": "=\n"}, {"input": "010000100010100000100010001000001100100010110000101010000010010011001111101101001\n001011100001110101111001100110001011011100000000100111011010010011010100101011111\n", "output": "=\n"}, {"input": "11111001000\n1011100100\n", "output": ">\n"}, {"input": "1001111010001100001010001010010010100010100011101101110011110101011000010111101100111000110110110010\n01111001101111100111111001110110100101001111010001000000001001001111100101101100001101111111100111101\n", "output": "<\n"}, {"input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0\n", "output": ">\n"}, {"input": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1\n", "output": ">\n"}, {"input": "1\n100000000000000000000000000000000000000000000000000\n", "output": "<\n"}, {"input": "1\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", "output": "<\n"}, {"input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "output": ">\n"}, {"input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n100000000000000000000\n", "output": ">\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111011011011001101111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "output": ">\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "output": "<\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1011111111111111111111111111011011011001101111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "output": ">\n"}, {"input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "output": "<\n"}, {"input": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0\n", "output": ">\n"}, {"input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1110\n", "output": ">\n"}, {"input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1000\n", "output": ">\n"}, {"input": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1000\n", "output": ">\n"}, {"input": "1\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", "output": "<\n"}, {"input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n0\n", "output": ">\n"}, {"input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n10000\n", "output": ">\n"}, {"input": "10000100001000010000100001000010000100001000010000\n1\n", "output": ">\n"}, {"input": "101001010101010101010100101010101010101010101001010101010100101010101010100101101010100101010100101010101001010101010101010100101010101010101010101001010101010100101010101010100101101010100101010100101010101001010101010101010100101010101010101010101001010101010100101010101010100101101010100101010100101010\n1\n", "output": ">\n"}, {"input": "10100\n01011\n", "output": ">\n"}, {"input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n01111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", "output": "<\n"}, {"input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n0000001010101011\n", "output": ">\n"}, {"input": "110010010101001001001010100100010101010101011111111111111010101000000000000000000010110111111110101010111111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "output": ">\n"}, {"input": "1100\n0111\n", "output": ">\n"}, {"input": "1111111111111111111111111111111111111111111111111\n0\n", "output": ">\n"}, {"input": "1100100101010010010010101001000101010101010111111111111110101010000000000000000000101101111111101010101111111111111111111111111111111\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "output": ">\n"}, {"input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n100000000000000000000\n", "output": ">\n"}, {"input": "100001000010000100001000010000100001000010000100001111111111111111111111111111111111111111111111111111111111111111111111\n1\n", "output": ">\n"}, {"input": "11111111111111111111111111111111111111111111111111111111111111\n1\n", "output": ">\n"}, {"input": "1011\n0100\n", "output": ">\n"}, {"input": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n", "output": "<\n"}, {"input": "1000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000\n1111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", "output": "<\n"}, {"input": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111001\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011\n", "output": ">\n"}, {"input": "1000000000000000000000000\n0101010101010101010101011\n", "output": "=\n"}, {"input": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n1\n", "output": ">\n"}, {"input": "101010101010101010101010101010101010101010101010101010101010101010101010\n1000000000000000000000000000000000000000000000000000000000000000000000000\n", "output": "<\n"}, {"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n0\n", "output": ">\n"}, {"input": "111\n1000\n", "output": ">\n"}, {"input": "1000000000000000000000000000000000000000000000000\n000\n", "output": ">\n"}, {"input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10\n", "output": ">\n"}, {"input": "111111111111111111111111111111111111111111111111\n11\n", "output": ">\n"}, {"input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n000\n", "output": ">\n"}, {"input": "101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", "output": ">\n"}, {"input": "100000000000000000000000000000000000000000000000\n0\n", "output": ">\n"}]
277
The last stage of Football World Cup is played using the play-off system. There are n teams left in this stage, they are enumerated from 1 to n. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the thirdΒ β€” with the fourth, the fifthΒ β€” with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over. Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids a and b can meet. -----Input----- The only line contains three integers n, a and b (2 ≀ n ≀ 256, 1 ≀ a, b ≀ n)Β β€” the total number of teams, and the ids of the teams that Arkady is interested in. It is guaranteed that n is such that in each round an even number of team advance, and that a and b are not equal. -----Output----- In the only line print "Final!" (without quotes), if teams a and b can meet in the Final. Otherwise, print a single integerΒ β€” the number of the round in which teams a and b can meet. The round are enumerated from 1. -----Examples----- Input 4 1 2 Output 1 Input 8 2 6 Output Final! Input 8 7 5 Output 2 -----Note----- In the first example teams 1 and 2 meet in the first round. In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds. In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round.
interview
[{"code": "import sys\nn, a, b = list(map(int, input().split()))\n\ncnt = 0\nl = [set([x]) for x in range(1, n+1)]\n\nwhile 1:\n l = list([tup[0] | tup[1] for tup in zip(l[::2], l[1::2])])\n cnt += 1\n for el in l:\n if a in el and b in el:\n print(cnt if len(el) < n else 'Final!')\n return\n", "passed": true, "time": 0.15, "memory": 14468.0, "status": "done"}, {"code": "t = list(map(int, input().split()))\nn = t[0]\na = t[1]\nb = t[2]\nans = 0\nwhile a != b:\n n //= 2\n a = (a + 1) // 2\n b = (b + 1) // 2\n ans += 1\nif n == 1:\n print('Final!')\nelse:\n print(ans)\n", "passed": true, "time": 0.23, "memory": 14376.0, "status": "done"}, {"code": "n,a,b=list(map(int,input().split()))\ndef ll(x):\n if x==1:\n return 0\n return 1+ll(x//2)\ndef main(n,a,b):\n if n==1:\n return 0\n q=n//2\n if a<=q and b>q or a>q and b<=q:\n return ll(n)\n return main(q,(a-1)%q+1,(b-1)%q+1)\nr=main(n,a,b)\nif 2**r==n:\n print('Final!')\nelse:\n print(r)\n", "passed": true, "time": 0.14, "memory": 14416.0, "status": "done"}, {"code": "R = lambda : list(map(int, input().split()))\nn,a,b=R()\nimport math\nk=math.ceil(math.log(n,2))\ni=1\nwhile (a!=b):\n a=(a+1)//2\n b=(b+1)//2\n i+=1\n\nres = i-1\nif res==k:\n print(\"Final!\")\nelse:\n print(res) \n", "passed": true, "time": 0.16, "memory": 14380.0, "status": "done"}, {"code": "n, a, b = list(map(int, input().split()))\ncnt = 1\n\na += a % 2\nb += b % 2\nwhile a != b:\n cnt += 1\n a /= 2\n b /= 2\n a += a % 2\n b += b % 2\nif 2 ** cnt == n:\n print('Final!')\nelse:\n print(cnt)\n \n\n\n", "passed": true, "time": 0.2, "memory": 14280.0, "status": "done"}, {"code": "n, a, b = map(int, input().split())\nans = 0\na -= 1\nb -= 1\nwhile n > 2:\n n //= 2\n a //= 2\n b //= 2\n ans += 1\n if a == b:\n print(ans)\n break\nelse:\n print(\"Final!\")", "passed": true, "time": 0.16, "memory": 14256.0, "status": "done"}, {"code": "n, a, b = list(map(int , input().split()))\n\na-=1\nb-=1\n\nn_round = 0\nwhile n>2:\n n_round+=1\n a//= 2\n b//=2\n n//=2\n if a==b:\n break\nelse:\n print('Final!')\n return\n\nprint(n_round)\n\n\n", "passed": true, "time": 0.15, "memory": 14548.0, "status": "done"}, {"code": "n, a, b = list(map(int, input().split()))\nflag = 2\na -= 1\nb -= 1\ni = 1\nwhile flag < n:\n if a // flag == b // flag:\n print(i)\n break\n i += 1\n flag *= 2\nelse:\n print('Final!')\n\n\n", "passed": true, "time": 0.14, "memory": 14260.0, "status": "done"}, {"code": "n, a, b = [int(v) for v in input().split()]\na -= 1\nb -= 1\n\nr = 1\nwhile True:\n nn = n // 2\n aa = a // 2\n bb = b // 2\n if aa == bb:\n print(\"Final!\" if nn == 1 else r)\n break\n n, a, b = nn, aa, bb\n r += 1\n", "passed": true, "time": 0.15, "memory": 14312.0, "status": "done"}, {"code": "n, a, b = list(map(int, input().split()))\na -= 1\nb -= 1\nq = []\nfor i in range(n // 2):\n q.append(((2 * i, 2 * i + 1), 1))\n\ndef wi(p):\n if a in p and b in p:\n return True\n return False\n\ndef ch(p):\n if a in p:\n return a\n if b in p:\n return b\n return p[0]\n\nwhile 1:\n if len(q) == 1:\n print('Final!')\n return\n p1 = q[0][0]\n p2 = q[1][0]\n if wi(p1):\n print(q[0][1])\n return\n if wi(p2):\n print(q[1][1])\n return\n q.append(((ch(p1), ch(p2)), q[0][1] + 1))\n del q[0]\n del q[0]\n", "passed": true, "time": 0.2, "memory": 14360.0, "status": "done"}, {"code": "n, a, b = [int(s) for s in input().split()]\na -= 1\nb -= 1\nl = 0\nwhile a != b:\n l -=- 1\n a //= 2\n b //= 2\nprint(l if 2**l != n else 'Final!')", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "import math\n\nn, a, b = map(int, input().split())\ni = 2\na, b = min(a, b), max(a, b)\nwhile True:\n if a <= n // i < b:\n break\n if a > n // i:\n a -= n // i\n b -= n // i\n i *= 2\nans = math.log(n, 2) - math.log(i, 2) + 1\nif math.log(i, 2) == 1:\n print(\"Final!\")\nelse:\n print(int(ans))", "passed": true, "time": 0.14, "memory": 14388.0, "status": "done"}, {"code": "n,a,b = list(map(int,input().split()))\n\na -= 1\nb -= 1\nans = 0\ntemp = 2\nfor i in range(8):\n if a // temp == b // temp:\n ans = i + 1\n break\n temp *= 2\n \nif temp == n:\n print(\"Final!\")\nelse:\n print(ans)\n", "passed": true, "time": 0.15, "memory": 14276.0, "status": "done"}, {"code": "n, a, b = [int(x) for x in input().split()]\nif a > b:\n a,b=b,a\n\nimport math as m\n# for i in [2,4,8,16,32,64,128,256]:\n# print(int(m.log2(i)))\nrounds = int(m.log2(n))\nmr = rounds\nlft, rgt = 1, n\n\nwhile True:\n mdl = (lft + rgt) // 2\n if a <= mdl and b > mdl:\n break\n rounds -= 1\n if a <= mdl and b <= mdl:\n rgt = mdl\n elif a > mdl and b > mdl:\n lft = mdl + 1\n\nif rounds == mr:\n print('Final!')\nelse:\n print(rounds)", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}, {"code": "a,b,c=map(int,input().split(' '))\npwr=0\nwhile a!=1:\n pwr+=1\n a=a//2\nans=1\nfor j in range(1,pwr):\n if (b-1)//(2**j)!=(c-1)//(2**j):\n ans+=1\nif ans==pwr:\n print(\"Final!\")\nelse:\n print(ans)", "passed": true, "time": 0.25, "memory": 14256.0, "status": "done"}, {"code": "n, a, b = map(int, input().split())\nnum = 0\na += n - 2\nb += n - 2\nwhile a != b:\n a = (a - 1) // 2\n b = (b - 1) // 2\n num += 1\n\nif 2 ** num == n:\n print(\"Final!\")\nelse:\n print(num)", "passed": true, "time": 0.19, "memory": 14308.0, "status": "done"}, {"code": "n, a, b = list(map(int, input().split()))\nls = list(range(1, n + 1))\nk = 0\nrounds = 0\nm = n\nwhile m > 1:\n m >>= 1\n rounds += 1\n# print(rounds)\nwhile len(ls) > 1:\n # print(ls)\n k += 1\n newls = []\n for i in range(0, len(ls), 2):\n if (ls[i] == a or ls[i] == b) and (ls[i + 1] == a or ls[i + 1] == b):\n if k == rounds:\n print(\"Final!\")\n else:\n print(k)\n newls = []\n break\n elif ls[i] == a or ls[i + 1] == a:\n newls.append(a)\n elif ls[i] == b or ls[i + 1] == b:\n newls.append(b)\n else:\n newls.append(ls[i])\n ls = newls\n", "passed": true, "time": 0.15, "memory": 14496.0, "status": "done"}, {"code": "n, a, b = [int(el) for el in input().split()]\nfor i in range(1,n+1):\n if 2 ** i == n:\n n = i\n break;\nfor i in range(1, n+1):\n if (a-1)//(2**i) == (b-1)//(2**i):\n if i == n:\n print('Final!')\n else:\n print(i)\n break\n", "passed": true, "time": 0.14, "memory": 14336.0, "status": "done"}, {"code": "n, a, b = map(int, input().split())\n\ndef f(n, a, b):\n\n if (b > n // 2 and a <= n // 2) or (a > n // 2 and b <= n // 2):\n\n return 0\n\n if a > n // 2 and b > n // 2:\n\n return 1 + f(n // 2, a - n // 2, b - n // 2)\n\n if a <= n // 2 and b <= n // 2:\n\n return 1 + f(n // 2, a, b)\n\ndeg = 0\n\nraund = f(n, a, b)\n\nwhile n > 0:\n\n deg += 1\n\n n //= 2\n\nif raund == 0:\n\n print('Final!')\n\nelse:\n\n print(deg - raund - 1)", "passed": true, "time": 0.14, "memory": 14556.0, "status": "done"}, {"code": "def make_tour(people):\n teams = []\n people.sort()\n for i in range(len(people)):\n if i % 2 == 0:\n teams.append([people[i]])\n else:\n teams[-1].append(people[i])\n return teams\n\n\nn, a, b = map(int, input().split())\npeople = []\nind = 1\nfl = True\nfor i in range(1, n + 1):\n people.append(i)\nwhile True:\n teams = make_tour(people)\n if len(teams) == 1:\n break\n for i in range(len(teams)):\n if teams[i][0] == a and teams[i][1] == b or teams[i][0] == b and teams[i][1] == a:\n fl = False\n print(ind)\n break\n elif teams[i][0] == a or teams[i][1] == a:\n teams[i] = [a]\n elif teams[i][0] == b or teams[i][1] == b:\n teams[i] = [b]\n else:\n teams[i] = [teams[i][0]]\n if not fl:\n break\n people = []\n for i in range(len(teams)):\n for j in range(len(teams[i])):\n people.append(teams[i][j])\n ind += 1\nif fl:\n print('Final!')", "passed": true, "time": 0.15, "memory": 14392.0, "status": "done"}, {"code": "import math\n\nn,a,b = input().split()\n\nn,a,b = int(n), int(a), int(b)\n\na-=1\nb-=1\n\na=format(a, '010b')\nb=format(b, '010b')\n\nfor i in range(len(a)):\n\tif (a[i]!=b[i]):\n\t\tif (len(a)-i==math.log(n,2)):\n\t\t\tprint('Final!')\n\t\telse:\n\t\t\tprint(len(a)-i)\n\t\tbreak", "passed": true, "time": 0.17, "memory": 14388.0, "status": "done"}, {"code": "import sys\nimport itertools as it\nimport math\n\nn,a,b = list(map(int, sys.stdin.readline().split()))\n\na-=1\nb-=1\nlogn = int(math.log2(n))\n\nfor k in range(logn):\n if a&(1<<(logn-k-1)) != b&(1<<(logn-k-1)):\n if k==0:\n print('Final!')\n else:\n print(logn-k)\n break\n", "passed": true, "time": 0.14, "memory": 14304.0, "status": "done"}, {"code": "import math\n\nn, a, b = tuple(map(int, input().split()))\n\n\n\n\ndef mr(k,n):\n a = [0]\n for i in range(n//k):\n a.extend([i]*k)\n return a\n\n\nrounds = {r : mr(2**r, 258) for r in range(1,10)}\n#print(len(rounds[1]))\n\ndef sol(a, b):\n for i in range(1, 10):\n if rounds[i][a] == rounds[i][b]:\n return i\n return 0\n\na = sol(a,b)\n\n\nprint(a if a != int(math.log(n,2)) else \"Final!\")", "passed": true, "time": 0.14, "memory": 14548.0, "status": "done"}, {"code": "n, a, b = [int(x) for x in input().split()]\na -= 1\nb -= 1\nres = 0;\nwhile a != b:\n a //= 2\n b //= 2\n res += 1\nif 2 ** res == n:\n print('Final!')\nelse:\n print(res)", "passed": true, "time": 2.09, "memory": 14324.0, "status": "done"}, {"code": "n, a, b = [int(x) for x in input().split()]\n\nl1 = [x for x in range(1, n + 1) ]\nl2 = []\nres = 0\nfound = False\nwhile (not found):\n res += 1\n for i in range(0, len(l1), 2):\n if l1[i] in [a, b] and l1[i + 1] in [a, b]:\n found = True\n if len(l1) == 2:\n res = \"Final!\"\n break\n if l1[i] in [a, b]:\n l2.append(l1[i])\n else:\n l2.append(l1[i+1])\n\n l1 = l2\n l2 = []\n \nprint(res)\n\n", "passed": true, "time": 0.15, "memory": 14392.0, "status": "done"}]
[{"input": "4 1 2\n", "output": "1\n"}, {"input": "8 2 6\n", "output": "Final!\n"}, {"input": "8 7 5\n", "output": "2\n"}, {"input": "128 30 98\n", "output": "Final!\n"}, {"input": "256 128 256\n", "output": "Final!\n"}, {"input": "256 2 127\n", "output": "7\n"}, {"input": "2 1 2\n", "output": "Final!\n"}, {"input": "2 2 1\n", "output": "Final!\n"}, {"input": "4 1 3\n", "output": "Final!\n"}, {"input": "4 1 4\n", "output": "Final!\n"}, {"input": "4 2 1\n", "output": "1\n"}, {"input": "4 2 3\n", "output": "Final!\n"}, {"input": "4 2 4\n", "output": "Final!\n"}, {"input": "4 3 1\n", "output": "Final!\n"}, {"input": "4 3 2\n", "output": "Final!\n"}, {"input": "4 3 4\n", "output": "1\n"}, {"input": "4 4 1\n", "output": "Final!\n"}, {"input": "4 4 2\n", "output": "Final!\n"}, {"input": "4 4 3\n", "output": "1\n"}, {"input": "8 8 7\n", "output": "1\n"}, {"input": "8 8 5\n", "output": "2\n"}, {"input": "8 8 1\n", "output": "Final!\n"}, {"input": "16 4 3\n", "output": "1\n"}, {"input": "16 2 4\n", "output": "2\n"}, {"input": "16 14 11\n", "output": "3\n"}, {"input": "16 3 11\n", "output": "Final!\n"}, {"input": "32 10 9\n", "output": "1\n"}, {"input": "32 25 28\n", "output": "2\n"}, {"input": "32 22 18\n", "output": "3\n"}, {"input": "32 17 25\n", "output": "4\n"}, {"input": "32 18 3\n", "output": "Final!\n"}, {"input": "64 40 39\n", "output": "1\n"}, {"input": "64 60 58\n", "output": "2\n"}, {"input": "64 34 37\n", "output": "3\n"}, {"input": "64 26 24\n", "output": "4\n"}, {"input": "64 50 43\n", "output": "5\n"}, {"input": "64 17 42\n", "output": "Final!\n"}, {"input": "128 116 115\n", "output": "1\n"}, {"input": "128 35 33\n", "output": "2\n"}, {"input": "128 61 59\n", "output": "3\n"}, {"input": "128 116 123\n", "output": "4\n"}, {"input": "128 17 15\n", "output": "5\n"}, {"input": "128 124 77\n", "output": "6\n"}, {"input": "128 4 80\n", "output": "Final!\n"}, {"input": "256 224 223\n", "output": "1\n"}, {"input": "256 24 22\n", "output": "2\n"}, {"input": "256 199 196\n", "output": "3\n"}, {"input": "256 148 159\n", "output": "4\n"}, {"input": "256 178 166\n", "output": "5\n"}, {"input": "256 75 97\n", "output": "6\n"}, {"input": "256 185 200\n", "output": "7\n"}, {"input": "256 3 238\n", "output": "Final!\n"}, {"input": "256 128 129\n", "output": "Final!\n"}, {"input": "256 255 129\n", "output": "7\n"}, {"input": "256 255 128\n", "output": "Final!\n"}, {"input": "256 129 256\n", "output": "7\n"}, {"input": "128 98 69\n", "output": "6\n"}, {"input": "128 47 83\n", "output": "Final!\n"}, {"input": "16 2 3\n", "output": "2\n"}, {"input": "64 32 30\n", "output": "2\n"}, {"input": "8 4 5\n", "output": "Final!\n"}, {"input": "8 7 8\n", "output": "1\n"}, {"input": "8 2 3\n", "output": "2\n"}, {"input": "8 2 5\n", "output": "Final!\n"}]
278
Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the reversed direction. Pavel has a plan: a permutation p and a sequence b_1, b_2, ..., b_{n}, consisting of zeros and ones. Each second Pavel move skewer on position i to position p_{i}, and if b_{i} equals 1 then he reverses it. So he hope that every skewer will visit every position in both directions. Unfortunately, not every pair of permutation p and sequence b suits Pavel. What is the minimum total number of elements in the given permutation p and the given sequence b he needs to change so that every skewer will visit each of 2n placements? Note that after changing the permutation should remain a permutation as well. There is no problem for Pavel, if some skewer visits some of the placements several times before he ends to cook. In other words, a permutation p and a sequence b suit him if there is an integer k (k β‰₯ 2n), so that after k seconds each skewer visits each of the 2n placements. It can be shown that some suitable pair of permutation p and sequence b exists for any n. -----Input----- The first line contain the integer n (1 ≀ n ≀ 2Β·10^5)Β β€” the number of skewers. The second line contains a sequence of integers p_1, p_2, ..., p_{n} (1 ≀ p_{i} ≀ n)Β β€” the permutation, according to which Pavel wants to move the skewers. The third line contains a sequence b_1, b_2, ..., b_{n} consisting of zeros and ones, according to which Pavel wants to reverse the skewers. -----Output----- Print single integerΒ β€” the minimum total number of elements in the given permutation p and the given sequence b he needs to change so that every skewer will visit each of 2n placements. -----Examples----- Input 4 4 3 2 1 0 1 1 1 Output 2 Input 3 2 3 1 0 0 0 Output 1 -----Note----- In the first example Pavel can change the permutation to 4, 3, 1, 2. In the second example Pavel can change any element of b to 1.
interview
[{"code": "import sys\n\nn = int(input())\np = [int(i) for i in input().split()]\nb = [int(i) for i in input().split()]\n\nans = 0\nnum_cycles = 0\nchecked = set()\n\nfor i in range(n):\n if i in checked:\n continue\n\n checked.add(i)\n\n nxt = p[i] - 1\n\n while nxt != i:\n checked.add(nxt)\n nxt = p[nxt] - 1\n\n num_cycles += 1\n\nans += num_cycles if num_cycles != 1 else 0\nans += (sum(b) % 2) == 0\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "n = int(input())\np = [int(i) for i in input().split()]\nb = [int(i) for i in input().split()]\nans = 0\nvisited = [False for i in range(n)]\nfor i in range(n):\n if visited[i]:\n continue\n ans += 1\n while not visited[i]:\n visited[i] = True\n i = p[i] - 1\nif ans == 1:\n ans = 0\nans += (sum(b) + 1) % 2\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "read = lambda: list(map(int, input().split()))\n\nn = int(input())\n\np = list(read())\n\nb = list(read())\n\nans = (b.count(1) + 1) % 2\n\nwas = [0] * n\n\ncnt = 0\n\nfor i in range(n):\n\n if not was[i]:\n\n cnt += 1\n\n v = i\n\n while not was[v]:\n\n was[v] = 1\n\n v = p[v] - 1\n\nif cnt > 1: ans += cnt\n\nprint(ans)\n\n\n\n# Made By Mostafa_Khaled\n", "passed": true, "time": 0.14, "memory": 14428.0, "status": "done"}, {"code": "import sys\n \nn = int(input())\np = [int(i) for i in input().split()]\nb = [int(i) for i in input().split()]\n \nans = 0\nnum_cycles = 0\nchecked = set()\n \nfor i in range(n):\n if i in checked:\n continue\n \n checked.add(i)\n \n nxt = p[i] - 1\n \n while nxt != i:\n checked.add(nxt)\n nxt = p[nxt] - 1\n \n num_cycles += 1\n \nans += num_cycles if num_cycles != 1 else 0\nans += (sum(b) % 2) == 0\n \nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14456.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\nclass Unionfind:\n def __init__(self, n):\n self.par = [-1]*n\n self.rank = [1]*n\n \n def root(self, x):\n p = x\n \n while not self.par[p]<0:\n p = self.par[p]\n \n while x!=p:\n tmp = x\n x = self.par[x]\n self.par[tmp] = p\n \n return p\n \n def unite(self, x, y):\n rx, ry = self.root(x), self.root(y)\n \n if rx==ry: return False\n \n if self.rank[rx]<self.rank[ry]:\n rx, ry = ry, rx\n \n self.par[rx] += self.par[ry]\n self.par[ry] = rx\n \n if self.rank[rx]==self.rank[ry]:\n self.rank[rx] += 1\n \n def is_same(self, x, y):\n return self.root(x)==self.root(y)\n \n def count(self, x):\n return -self.par[self.root(x)]\n\nn = int(input())\np = list(map(int, input().split()))\nb = list(map(int, input().split()))\nuf = Unionfind(n)\n\nfor i in range(n):\n uf.unite(i, p[i]-1)\n\nrs = set(uf.root(i) for i in range(n))\n\nif len(rs)==1:\n ans = 0\nelse:\n ans = len(rs)\n\nif b.count(1)%2==0:\n ans += 1\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14400.0, "status": "done"}, {"code": "n = int(input())\np = [int(i) for i in input().split()]\nzeros = [int(i) for i in input().split()]\n\nans = 0\n\nif not sum(zeros) % 2:\n ans += 1\n\nvisited = [False for i in range(n)]\n\nciclos = 0\nfor i in range(n):\n if not visited[i]:\n ciclos += 1\n j = i\n while not visited[j]:\n visited[j] = True\n j = p[j] - 1\n\nif ciclos == 1:\n ans += 0\nelse:\n ans += ciclos\n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14580.0, "status": "done"}]
[{"input": "4\n4 3 2 1\n0 1 1 1\n", "output": "2\n"}, {"input": "3\n2 3 1\n0 0 0\n", "output": "1\n"}, {"input": "1\n1\n0\n", "output": "1\n"}, {"input": "2\n1 2\n0 0\n", "output": "3\n"}, {"input": "2\n2 1\n0 0\n", "output": "1\n"}, {"input": "2\n1 2\n0 1\n", "output": "2\n"}, {"input": "2\n2 1\n1 0\n", "output": "0\n"}, {"input": "2\n1 2\n1 1\n", "output": "3\n"}, {"input": "2\n2 1\n1 1\n", "output": "1\n"}, {"input": "5\n2 1 3 4 5\n1 0 0 0 1\n", "output": "5\n"}, {"input": "10\n4 10 5 1 6 8 9 2 3 7\n0 1 0 0 1 0 0 1 0 0\n", "output": "2\n"}, {"input": "20\n10 15 20 17 8 1 14 6 3 13 19 2 16 12 4 5 11 7 9 18\n0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0\n", "output": "3\n"}, {"input": "100\n87 69 49 86 96 12 10 79 29 66 48 77 73 62 70 52 22 28 97 35 91 5 33 82 65 85 68 80 64 8 38 23 94 34 75 53 57 6 100 2 56 50 55 58 74 9 18 44 40 3 43 45 99 51 21 92 89 36 88 54 42 14 78 71 25 76 13 11 27 72 7 32 93 46 83 30 26 37 39 31 95 59 47 24 67 16 4 15 1 98 19 81 84 61 90 41 17 20 63 60\n1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 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 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "4\n"}, {"input": "1\n1\n1\n", "output": "0\n"}, {"input": "2\n1 2\n1 0\n", "output": "2\n"}, {"input": "2\n2 1\n0 1\n", "output": "0\n"}, {"input": "3\n1 2 3\n0 0 0\n", "output": "4\n"}, {"input": "3\n1 2 3\n1 0 0\n", "output": "3\n"}, {"input": "3\n1 2 3\n0 1 0\n", "output": "3\n"}, {"input": "3\n1 2 3\n1 1 0\n", "output": "4\n"}, {"input": "3\n1 2 3\n0 0 1\n", "output": "3\n"}, {"input": "3\n1 2 3\n1 0 1\n", "output": "4\n"}, {"input": "3\n1 2 3\n0 1 1\n", "output": "4\n"}, {"input": "3\n1 2 3\n1 1 1\n", "output": "3\n"}, {"input": "3\n1 3 2\n0 0 0\n", "output": "3\n"}, {"input": "3\n1 3 2\n1 0 0\n", "output": "2\n"}, {"input": "3\n1 3 2\n0 1 0\n", "output": "2\n"}, {"input": "3\n1 3 2\n1 1 0\n", "output": "3\n"}, {"input": "3\n1 3 2\n0 0 1\n", "output": "2\n"}, {"input": "3\n1 3 2\n1 0 1\n", "output": "3\n"}, {"input": "3\n1 3 2\n0 1 1\n", "output": "3\n"}, {"input": "3\n1 3 2\n1 1 1\n", "output": "2\n"}, {"input": "3\n2 1 3\n0 0 0\n", "output": "3\n"}, {"input": "3\n2 1 3\n1 0 0\n", "output": "2\n"}, {"input": "3\n2 1 3\n0 1 0\n", "output": "2\n"}, {"input": "3\n2 1 3\n1 1 0\n", "output": "3\n"}, {"input": "3\n2 1 3\n0 0 1\n", "output": "2\n"}, {"input": "3\n2 1 3\n1 0 1\n", "output": "3\n"}, {"input": "3\n2 1 3\n0 1 1\n", "output": "3\n"}, {"input": "3\n2 1 3\n1 1 1\n", "output": "2\n"}, {"input": "3\n2 3 1\n0 0 0\n", "output": "1\n"}, {"input": "3\n2 3 1\n1 0 0\n", "output": "0\n"}, {"input": "3\n2 3 1\n0 1 0\n", "output": "0\n"}, {"input": "3\n2 3 1\n1 1 0\n", "output": "1\n"}, {"input": "3\n2 3 1\n0 0 1\n", "output": "0\n"}, {"input": "3\n2 3 1\n1 0 1\n", "output": "1\n"}, {"input": "3\n2 3 1\n0 1 1\n", "output": "1\n"}, {"input": "3\n2 3 1\n1 1 1\n", "output": "0\n"}, {"input": "3\n3 1 2\n0 0 0\n", "output": "1\n"}, {"input": "3\n3 1 2\n1 0 0\n", "output": "0\n"}, {"input": "3\n3 1 2\n0 1 0\n", "output": "0\n"}, {"input": "3\n3 1 2\n1 1 0\n", "output": "1\n"}, {"input": "3\n3 1 2\n0 0 1\n", "output": "0\n"}, {"input": "3\n3 1 2\n1 0 1\n", "output": "1\n"}, {"input": "3\n3 1 2\n0 1 1\n", "output": "1\n"}, {"input": "3\n3 1 2\n1 1 1\n", "output": "0\n"}, {"input": "3\n3 2 1\n0 0 0\n", "output": "3\n"}, {"input": "3\n3 2 1\n1 0 0\n", "output": "2\n"}, {"input": "3\n3 2 1\n0 1 0\n", "output": "2\n"}, {"input": "3\n3 2 1\n1 1 0\n", "output": "3\n"}, {"input": "3\n3 2 1\n0 0 1\n", "output": "2\n"}, {"input": "3\n3 2 1\n1 0 1\n", "output": "3\n"}, {"input": "3\n3 2 1\n0 1 1\n", "output": "3\n"}, {"input": "3\n3 2 1\n1 1 1\n", "output": "2\n"}]
281
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessorΒ β€” as is known to many, the phoenix does it like this. The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 Γ— 2 Γ— ... Γ— a. Specifically, 0! = 1. Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, [Image]. Note that when b β‰₯ a this value is always integer. As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge. -----Input----- The first and only line of input contains two space-separated integers a and b (0 ≀ a ≀ b ≀ 10^18). -----Output----- Output one line containing a single decimal digitΒ β€” the last digit of the value that interests Koyomi. -----Examples----- Input 2 4 Output 2 Input 0 10 Output 0 Input 107 109 Output 2 -----Note----- In the first example, the last digit of $\frac{4 !}{2 !} = 12$ is 2; In the second example, the last digit of $\frac{10 !}{0 !} = 3628800$ is 0; In the third example, the last digit of $\frac{109 !}{107 !} = 11772$ is 2.
interview
[{"code": "a, b = map(int, input().split())\n\nif b - a > 10:\n\tprint(0)\nelse:\n\ts = 1\n\tfor i in range(a + 1, b + 1):\n\t\ts *= i\n\tprint(str(s)[-1])", "passed": true, "time": 0.21, "memory": 14296.0, "status": "done"}, {"code": "a,b = map(int,input().split())\nif(b-a >= 5):\n\tprint(0)\nelse:\n\tans = 1\n\tfor i in range(a+1,b+1):\n\t\tans *= (i%10)\n\tprint(ans%10)", "passed": true, "time": 0.16, "memory": 14292.0, "status": "done"}, {"code": "def __starting_point():\n arr = input().split(' ')\n ans = 1\n a = int(arr[0])\n b = int(arr[1])\n while ans!=0 and b>a:\n ans = (b%10)*ans\n ans = ans%10\n b -= 1\n print(ans)\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14428.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\nif b >= a + 10:\n\tprint(0)\nelse:\n\tcnt = 1\n\tfor i in range(a + 1, b + 1):\n\t\t#print (i)\n\t\tcnt *= i\n\t\tcnt %= 10\n\tprint (cnt)\n", "passed": true, "time": 0.14, "memory": 14304.0, "status": "done"}, {"code": "import random, math\na, b = map(int, input().split())\nr = 1\nif b > a + 6:\n\tprint(0)\nelse:\n\tfor i in range(a + 1, b + 1):\n\t\tr *= i % 10\n\tprint(r % 10)", "passed": true, "time": 0.16, "memory": 14308.0, "status": "done"}, {"code": "a, b = map(int, input().split())\nif (b - a > 10):\n print(0);\nelse:\n ans = 1\n for i in range(a + 1, b + 1):\n ans *= i;\n print(ans % 10);", "passed": true, "time": 0.15, "memory": 14476.0, "status": "done"}, {"code": "a, b = map(int, input().split())\nif b - a > 10:\n print(0)\nelse:\n mul = 1\n for i in range(a + 1, b + 1):\n mul *= i\n print(mul % 10)", "passed": true, "time": 0.15, "memory": 14548.0, "status": "done"}, {"code": "a, b = map(int, input().split())\nif b - a < 10:\n c = 1\n for i in range(a + 1, b + 1):\n c *= i\n print(c % 10)\nelse:\n print(0)", "passed": true, "time": 1.0, "memory": 14276.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\nif b - a > 12:\n print(0)\nelse:\n res = 1\n for i in range(a + 1, b + 1):\n res *= i\n print(res % 10)\n", "passed": true, "time": 0.14, "memory": 14324.0, "status": "done"}, {"code": "A, B = map(int, input().split())\n\ni = A + 1\nans = 1\n\nwhile i <= B:\n\tans = ans * (i % 10)\n\tans = ans % 10\n\tif (ans % 10) == 0:\n\t\tbreak\n\ti = i + 1\n\nprint(ans) ", "passed": true, "time": 1.79, "memory": 14352.0, "status": "done"}, {"code": "a, b = [int(i) for i in input().split()]\na = max(a, 1)\nb = max(b, 1)\npr = 1\nfor i in range(a + 1, b + 1):\n pr = pr * i\n pr = pr % 10\n if pr == 0:\n break\nprint(pr)", "passed": true, "time": 0.15, "memory": 14564.0, "status": "done"}, {"code": "a,b=list(map(int,input().split()))\nc=1\nfor i in range(b-a):\n z=(a + i + 1) % 10\n c*=z\n c=c%10\n if c==0:\n break\n \nprint(c)\n", "passed": true, "time": 0.15, "memory": 14408.0, "status": "done"}, {"code": "a,b = list(map(int,input().split()))\nif b-a>=5:\n print(0)\nelse:\n b = b%10\n a = a%10\n if b<a:\n b+=10\n p = 1\n for i in range(1,b-a+1):\n p *= (a+i)\n print(p%10)\n\n", "passed": true, "time": 0.15, "memory": 14404.0, "status": "done"}, {"code": "import math\nimport re\ndef ria():\n return [int(i) for i in input().split()]\na,b=ria()\nc=b-a\nif c>=20:\n print(0)\nelse:\n kek=1\n \n for i in range(a+1,b+1):\n kek*=i\n\n print(kek%10)\n", "passed": true, "time": 0.16, "memory": 14432.0, "status": "done"}, {"code": "a,b=list(map(int,input().split()))\n\nthe=1\nfor i in range(a+1,min(b,a+10)+1):\n\tthe*=i\n\nprint(the%10)\n", "passed": true, "time": 0.14, "memory": 14308.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\nif ((b - a) >= 10):\n print(0)\nelse:\n k = 1\n for i in range(a + 1, b + 1):\n k *= i\n print(k % 10)\n", "passed": true, "time": 0.14, "memory": 14428.0, "status": "done"}, {"code": "import math\n\nr,n=map(int,input().split())\n\nif n-r>=5:\n\tprint(0)\nelse:\n\tans=1\n\tfor i in range(r+1,n+1):\n\t\tans*=i\n\tprint(ans%10)", "passed": true, "time": 0.15, "memory": 14328.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\nans = 1\nfor i in range(a+1, b+1):\n ans*= i\n if ans%10 == 0:\n break\nprint(ans%10)\n\n", "passed": true, "time": 0.14, "memory": 14308.0, "status": "done"}, {"code": "a, b = map(int, input().split())\nif b >= a + 10:\n print(0)\nelse:\n ans = 1\n for i in range(a + 1, b + 1):\n ans *= i\n print(ans % 10)", "passed": true, "time": 0.14, "memory": 14424.0, "status": "done"}, {"code": "a, b = map(int, input().split())\n\nif (b - a) >= 5:\n print(0)\nelse:\n s = 1\n for i in range(a + 1, b + 1):\n s = ((i % 10) * s) % 10\n print(s % 10)", "passed": true, "time": 0.14, "memory": 14456.0, "status": "done"}, {"code": "a,b=list(map(int,input().split()))\nfact=1\nif(b-a<5):\n\tfor i in range(a+1,b+1):\n\t\tfact*=i\n\tprint(fact%10)\nelse:\n\tprint(0)\n", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "a, b = map(int, input().split())\nd = [1, 1, 2, 6, 4]\nif a==0:\n print(0 if b>=5 else d[b])\nelif b==0:\n print(1 if a<=1 else 0)\nelse:\n f = 1\n x = a+1\n while x<=b:\n f *= x\n if x%10==0:\n break\n x += 1\n print(f%10)", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}, {"code": "a,b=list(map(int,input().split()))\nif(b-a)>=5:\n print(\"0\")\nelse:\n num_term=b-a\n num=1\n for i in range(num_term):\n num=num*((a+i+1)%10)\n num=num%10\n print(num)", "passed": true, "time": 0.15, "memory": 14280.0, "status": "done"}, {"code": "(a,b)=list(map(int,input().split()));\nif(b-a>=10):\n print((0));\n return;\nelse:\n x=1;\n for i in range(a+1,b+1):\n x=(x*(i%10))%10;\nprint(x);\n", "passed": true, "time": 0.23, "memory": 14436.0, "status": "done"}]
[{"input": "2 4\n", "output": "2\n"}, {"input": "0 10\n", "output": "0\n"}, {"input": "107 109\n", "output": "2\n"}, {"input": "10 13\n", "output": "6\n"}, {"input": "998244355 998244359\n", "output": "4\n"}, {"input": "999999999000000000 1000000000000000000\n", "output": "0\n"}, {"input": "2 3\n", "output": "3\n"}, {"input": "3 15\n", "output": "0\n"}, {"input": "24 26\n", "output": "0\n"}, {"input": "14 60\n", "output": "0\n"}, {"input": "11 79\n", "output": "0\n"}, {"input": "1230 1232\n", "output": "2\n"}, {"input": "2633 2634\n", "output": "4\n"}, {"input": "535 536\n", "output": "6\n"}, {"input": "344319135 396746843\n", "output": "0\n"}, {"input": "696667767 696667767\n", "output": "1\n"}, {"input": "419530302 610096911\n", "output": "0\n"}, {"input": "238965115 821731161\n", "output": "0\n"}, {"input": "414626436 728903812\n", "output": "0\n"}, {"input": "274410639 293308324\n", "output": "0\n"}, {"input": "650636673091305697 650636673091305702\n", "output": "0\n"}, {"input": "651240548333620923 651240548333620924\n", "output": "4\n"}, {"input": "500000000000000000 1000000000000000000\n", "output": "0\n"}, {"input": "999999999999999999 1000000000000000000\n", "output": "0\n"}, {"input": "1000000000000000000 1000000000000000000\n", "output": "1\n"}, {"input": "0 4\n", "output": "4\n"}, {"input": "50000000062000007 50000000062000011\n", "output": "0\n"}, {"input": "0 0\n", "output": "1\n"}, {"input": "1 1\n", "output": "1\n"}, {"input": "0 2\n", "output": "2\n"}, {"input": "10000000000012 10000000000015\n", "output": "0\n"}, {"input": "5 5\n", "output": "1\n"}, {"input": "12 23\n", "output": "0\n"}, {"input": "0 11\n", "output": "0\n"}, {"input": "11111234567890 11111234567898\n", "output": "0\n"}, {"input": "0 3\n", "output": "6\n"}, {"input": "1 2\n", "output": "2\n"}, {"input": "999999999999999997 999999999999999999\n", "output": "2\n"}, {"input": "4 5\n", "output": "5\n"}, {"input": "0 1\n", "output": "1\n"}, {"input": "101 1002\n", "output": "0\n"}, {"input": "0 100000000000000001\n", "output": "0\n"}, {"input": "99999999999999997 99999999999999999\n", "output": "2\n"}, {"input": "14 15\n", "output": "5\n"}, {"input": "8 19\n", "output": "0\n"}, {"input": "12 22\n", "output": "0\n"}, {"input": "999999999999996 999999999999999\n", "output": "4\n"}, {"input": "1 3\n", "output": "6\n"}, {"input": "124 125\n", "output": "5\n"}, {"input": "11 32\n", "output": "0\n"}, {"input": "0 5\n", "output": "0\n"}, {"input": "0 999999\n", "output": "0\n"}, {"input": "151151151515 151151151526\n", "output": "0\n"}, {"input": "6 107\n", "output": "0\n"}, {"input": "5 16\n", "output": "0\n"}, {"input": "7 16\n", "output": "0\n"}, {"input": "6 19\n", "output": "0\n"}, {"input": "11113111111111 13111111111111\n", "output": "0\n"}, {"input": "1 1000\n", "output": "0\n"}, {"input": "24 25\n", "output": "5\n"}, {"input": "0 100000000000\n", "output": "0\n"}, {"input": "1 22\n", "output": "0\n"}, {"input": "999999999999999996 999999999999999999\n", "output": "4\n"}]
282
A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the point x she can reach the point x + a, where a is an integer from 1 to d. For each point from 1 to n is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and n. Determine the minimal number of jumps that the frog needs to reach home which is in the point n from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1. -----Input----- The first line contains two integers n and d (2 ≀ n ≀ 100, 1 ≀ d ≀ n - 1) β€” the point, which the frog wants to reach, and the maximal length of the frog jump. The second line contains a string s of length n, consisting of zeros and ones. If a character of the string s equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string s equal to one. -----Output----- If the frog can not reach the home, print -1. In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point n from the point 1. -----Examples----- Input 8 4 10010101 Output 2 Input 4 2 1001 Output -1 Input 8 4 11100101 Output 3 Input 12 3 101111100101 Output 4 -----Note----- In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four). In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two.
interview
[{"code": "'''input\n4 2\n1001\n'''\n\ndef 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,d = map_input()\ns = input()\ncur = 0\ncnt = 0\nwhile cur < n-1:\n\tj = -1\n\tfor i in range(cur+1,min(cur+d+1,n)):\n\t\tif s[i] == '1': j = i\n\tif j == -1:\n\t\tprint(-1)\n\t\tbreak\n\tcur = j\n\tcnt += 1\nelse: print(cnt)\t\t\t", "passed": true, "time": 0.99, "memory": 14560.0, "status": "done"}, {"code": "n, d = [int(i) for i in input().split()]\na = input()\ndp = [1e9] * n\ndp[0] = 0\nfor i in range(1, n):\n if a[i] == '0':\n continue\n for j in range(1, d + 1):\n if i - j < 0:\n break\n dp[i] = min(dp[i], dp[i - j] + 1)\nprint(dp[-1] if dp[-1] != 1e9 else -1)", "passed": true, "time": 0.15, "memory": 14296.0, "status": "done"}, {"code": "n,d = [int(i) for i in input().split()]\ns = input()\ni = 0\nt = 0\nf = 1\nwhile i < n-1 and f == 1:\n\tf = 0\n\tk = i+d\n\tif k >= n :\n\t\tk = n-1\n\tfor j in range(k,i,-1):\n\t\tif s[j] == '1':\n\t\t\t#print(j)\n\t\t\tf = 1\n\t\t\ti = j\n\t\t\tt = t+1\n\t\t\tbreak\nif f == 0 :\n\tprint(-1)\nelse:\n\tprint(t)\n\t\t\t\n", "passed": true, "time": 0.14, "memory": 14540.0, "status": "done"}, {"code": "n,d=list(map(int,input().strip().split(' ')))\narr=input()\ndp=[10000 for i in range(1000)]\ndp[0]=0\ni=1\nwhile(i<n):\n\n\tif(arr[i]=='1'):\n\t\t\n\t\tfor j in range(i-1,max(-1,i-d-1),-1):\n\t\t\t\n\t\t\tdp[i]=min(dp[i],dp[j]+1)\n\ti+=1\n\nif(dp[n-1]==10000):\n\tprint(-1)\nelse:\n\tprint(dp[n-1])\n", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}, {"code": "s1 = input()\ns1 = s1.split()\nn = int(s1[0])\nd = int(s1[1])\ns = input()\ncount = 0\npos = 1\ndk = d\nres = True\nwhile(pos!=n):\n if dk==0:\n res = False\n break\n if pos+dk<=n and s[pos+dk-1]=='1':\n if dk==0:\n res = False\n break\n pos+=dk\n count+=1\n dk = d\n else:\n dk-=1\n\nif res:\n print(count)\nelse:\n print(-1)", "passed": true, "time": 0.15, "memory": 14300.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\nc = 0 \ns = input()\nst = 1\nwhile st<n:\n\tflag = 0 \n\tsk = 0 \n\tfor i in range(st,min(st+k,n)):\n\t\tif s[i]=='1':\n\t\t\tsk = i\n\t\t\tflag = 1\n\tif not flag :\n\t\tbreak\n\tc +=1\n\tst = sk+1\nif flag :\n\tprint(c)\nelse:\n\tprint(-1)\n", "passed": true, "time": 0.32, "memory": 14524.0, "status": "done"}, {"code": "n, d = list(map(int, input().split()))\ns = input()\ni = 0\ni2 = 0\nres = 0\nwhile i != n - 1:\n i2 = i + d\n while i2 != i:\n if i2 < len(s) and s[i2] == \"1\":\n break\n i2 -= 1\n else:\n print(-1)\n break\n i = i2\n res += 1\nelse:\n print(res)\n", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "n,d=map(int,input().split())\nch=input()\ni=0\nl=len(ch)\ncom=0\nwhile True:\n if len(ch)-i <= d:\n if len(ch)-i>1:\n com+=1\n print(com)\n break\n else:\n if '1' in ch[i+1:i+d+1]:\n ch3=ch[i+1:i+d+1]\n ch2=ch3[::-1]\n i=i+d+1-ch2.index('1')-1\n com+=1\n else:\n print(-1)\n break", "passed": true, "time": 0.32, "memory": 14376.0, "status": "done"}, {"code": "n, d = map(int, input().split())\ns = input()\n\na = [(n + 1)] * n\n\na[0] = 0\nfor i in range(1, n):\n if s[i] == '1':\n for j in range(max(0, i - d), i):\n a[i] = min(a[i], a[j] + 1)\n\nprint(a[n - 1] if a[n - 1] < n else -1)", "passed": true, "time": 0.23, "memory": 14400.0, "status": "done"}, {"code": "class axis:\n def __init__(self, lilies):\n self.line = lilies\n\n\nclass frog:\n def __init__(self, d, my_axis):\n self.axis = my_axis\n self.d = d\n self.point = 0\n\n def jump(self):\n for i in range(self.point + self.d, self.point, -1):\n if i >= len(self.axis.line):\n continue\n\n if self.axis.line[i] == '1':\n self.point = i\n return True\n\n return False\n\n\nn, d = [int(i) for i in input().split()]\nlilies = input().strip()\n\nmy_axis = axis(lilies)\nmy_frog = frog(d, my_axis)\n\njump_count = 0\n\nwhile my_frog.point < n - 1:\n if my_frog.jump():\n jump_count += 1\n else:\n jump_count = -1\n break\n\nprint(jump_count)\n", "passed": true, "time": 0.15, "memory": 14300.0, "status": "done"}, {"code": "def jump(n,d,s):\n\tstring=\"\"\n\tfor x in range(d):\n\t\tstring+=\"0\"\n\tfor i in range(len(s)-d):\n\t\tif s[i:i+d]==string:\n\t\t\treturn -1\n\tcount=0\n\tdist=1\n\ta=0\n\tr=1\n\twhile dist<len(s):\n\t\tif d+a<len(s):\n\t\t\tif int(s[d+a])==1:\n\t\t\t\tdist+=d\n\t\t\t\tcount+=1\n\t\t\t\ta+=d\n\t\t\t\t#if d+a-r<len(s):\n\t\t\telse:\n\t\t\t\twhile d-r>0:\n\t\t\t\t\tif int(s[d+a-r])==1:\n\t\t\t\t\t\tdist+=d-r\n\t\t\t\t\t\tcount+=1\n\t\t\t\t\t\ta+=d-r\n\t\t\t\t\t\tr=1\n\t\t\t\t\t\tbreak\n\t\t\t\t\telse:\n\t\t\t\t\t\tr+=1\n\t\t\t\t#else:\n\t\t\t\t#\twhile d+a-r>=len(s):\n\t\t\t\t#\t\tr+=1\n\t\telse:\n\t\t\ta-=1\t\n\treturn count\n\ndef __starting_point():\n\t[n,d]=[int(i) for i in input().split(\" \")]\n\ts=input()\n\tprint(jump(n,d,s))\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "n,d=map(int,input().split())\ns=str(input())\np=0\nans=0\nwhile p<n:\n f=0\n if p==n-1:\n break\n for i in range(p+1,min(p+d+1,n)):\n if s[i]=='1':\n f=1\n pp=i\n if f==0:\n print(-1)\n #print(p,pp)\n return\n else:\n p=pp\n ans+=1\nprint(ans)", "passed": true, "time": 0.14, "memory": 14540.0, "status": "done"}, {"code": "n=[int(i) for i in input().split()]\na=str(input())\nfor i in range(n[1]):\n a+='0'\nd=n[1]\nskak=0\npr=d\nans=0\nwhile skak<n[0]-1 and pr>0:\n pr=d\n \n while a[pr+skak]!='1' and pr!=0:\n \n pr-=1\n skak=pr+skak\n ans+=1\nif pr==0:\n print(-1)\nelse:\n print(ans)\n", "passed": true, "time": 0.32, "memory": 14348.0, "status": "done"}, {"code": "class axis:\n def __init__(self, lilies):\n self.line = lilies\n\n\nclass frog:\n def __init__(self, d, my_axis):\n self.axis = my_axis\n self.d = d\n self.point = 0\n\n def jump(self):\n for i in range(self.point + self.d, self.point, -1):\n if i >= len(self.axis.line):\n continue\n\n if self.axis.line[i] == '1':\n self.point = i\n return True\n\n return False\n\n\nn, d = [int(i) for i in input().split()]\nlilies = input().strip()\n\nmy_axis = axis(lilies)\nmy_frog = frog(d, my_axis)\n\njump_count = 0\n\nwhile my_frog.point < n - 1:\n if my_frog.jump():\n jump_count += 1\n else:\n jump_count = -1\n break\n\nprint(jump_count)\n", "passed": true, "time": 0.15, "memory": 14280.0, "status": "done"}, {"code": "n,d=list(map(int,input().split()))\ns=input()\nx1=0\nk=0\nm= False\nwhile x1!=n-1:\n if x1 == -1 or s[n-1]!='1' or x1 == s.rfind('1',x1,x1+d+1):\n m=True\n break\n o = s.rfind('1',x1,x1+d+1)\n x1 = o\n k+=1\nif m:\n print('-1')\nelse:\n print(k)\n", "passed": true, "time": 0.14, "memory": 14284.0, "status": "done"}, {"code": "n, d = list(map(int, input().split()))\na = input()\nm = list(map(len, a.split(\"1\")))\npos = 1\nout = 0\n\nif max(m) >= d:\n print(-1)\n return\n\nelse:\n while pos != n:\n for i in range(d, 0, -1):\n if pos + i > n:\n pass\n\n else:\n if a[pos + i - 1] == \"1\":\n pos += i\n out += 1\n break\n\nprint(out)", "passed": true, "time": 0.14, "memory": 14324.0, "status": "done"}, {"code": "import sys\nn,d=list(map(int,sys.stdin.readline().split()))\ns=list(input())\na=[]\nfor i in range(1,len(s)):\n if(s[i]=='1'):\n a.append(i)\n\nmina=None\nc=d\nx=0\nflag=0\nif(len(a)==1 and a[0]>d):\n print(-1)\n return\nif(len(a)==1 and a[0]<=d):\n print(1)\n return\nfor i in range(0,len(a)-1):\n if(a[i]>c):\n flag=1\n break\n if(a[i]<=c and a[i+1]>c):\n x+=1\n c=a[i]+d\n \nif(abs(a[i]-a[len(a)-1])<=d and flag==0):\n x+=1\nelse:\n x=0\nif(x==0):\n print(-1)\n return\nprint(x)\n\n", "passed": true, "time": 0.23, "memory": 14376.0, "status": "done"}, {"code": "n,d = map(int,input().split())\n\nnum = 0 #distance from the last step\nv = 0 #value of steps\na = 1 #flag for excistence\nk = 0 #coord. of the last step variant destination\n\nst = input()\n\nfor i in range(1,n):\n num+=1\n if int(st[i]) == 1:\n k = num\n if num%d == 0:\n if k!=0:\n num = num - k\n v+=1\n else:\n a = 0 \n k = 0\n \nif a==1:\n if num%d == 0:\n print(v)\n else:\n print(v+1)\nelse:\n print(-1)", "passed": true, "time": 0.15, "memory": 14256.0, "status": "done"}, {"code": "n,d=map(int,input().split())\na=[1000]*(n+1)\na[0]=0\ns=[int(x) for x in input()]\nfor x in range(1,n):\n if s[x]:\n for c in range(1,d+1):\n if x-c >= 0 and s[x-c]:\n a[x]=min(a[x-c]+1,a[x])\nprint(-1 if a[n-1] > 200 else a[n-1])", "passed": true, "time": 0.14, "memory": 14428.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\n\ndef main():\n\tn, d = list(map(int, input().split()))\n\ts = input()\n\ti = 0\n\tcnt = 0\n\twhile 1:\n\t\tmaxi = i + d\n\t\tif maxi >= n - 1:\n\t\t\tcnt += 1\n\t\t\tbreak\n\t\tfound = False\n\t\tfor j in range(maxi, i, -1):\n\t\t\tif s[j] != '0':\n\t\t\t\ti = j\n\t\t\t\tcnt += 1\n\t\t\t\tfound = True\n\t\t\t\tbreak\n\t\tif not found:\n\t\t\tprint(-1)\n\t\t\treturn\n\tprint(cnt)\n\n\ndef __starting_point():\n\tmain()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14552.0, "status": "done"}, {"code": "#!/usr/bin/env python2\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sat Dec 23 03:02:56 2017\n\n@author: sherlock\n\"\"\"\n\nimport array\n\n\nnumbers=list(map(int,input().split()))\n\n\nn=numbers[0]\nd=numbers[1]\n\ndp=[]\n\ndp.append(0)\n\nfor i in range(1,n):\n dp.append(999999)\n \ns=str(input())\n\nfor i in range(1,n):\n if(s[i]=='1'):\n for j in range(1,d+1):\n if(i-j>=0):\n dp[i]=min(dp[i-j]+1,dp[i])\n\n#for i in range(0,n):\n # print(dp[i])\n\nif(dp[n-1]==999999):\n print(\"-1\")\nelse: \n print(dp[n-1])\n\n\n", "passed": true, "time": 0.14, "memory": 14580.0, "status": "done"}, {"code": "n, d = list(map(int, input().split()))\ns = input()\na = 0\nx = 0\nwhile a <= n:\n k = min(d, n-a-1)\n place = s[a+1:a+k+1]\n if a == n-1:\n print(x)\n return\n elif '1' in place:\n a += k-place[::-1].index('1')\n x+=1\n else:\n print(-1)\n return\n", "passed": true, "time": 0.14, "memory": 14388.0, "status": "done"}, {"code": "m,n = [int(x) for x in input().split(' ')]\nraw = list(input())\np = 0\ncnt = 1\nprt = 0\nwhile p <m-n-1:\n for j in range(n):\n key = 0\n if raw[p+n-j]==\"1\":\n p = p+n-j\n cnt+=1\n key = 1\n break\n else:\n pass\n if key == 0:\n prt = 1\n break\nif prt == 1:\n print(-1)\nelse:\n print(cnt)", "passed": true, "time": 0.22, "memory": 14376.0, "status": "done"}, {"code": "# ===================================\n# (c) MidAndFeed aka ASilentVoice\n# ===================================\n# import math, fractions, collections\n# ===================================\nn, d = [int(x) for x in input().split()]\ns = str(input())\ni = 0\nans = 0\ntemp = 0\nwhile(1):\n\ttemp = min(d, n-i-1)\n\t\n\twhile(temp > 0):\n\t\tif s[i+temp] == \"1\":\n\t\t\tflag = 1\n\t\t\tbreak\n\t\telse:\n\t\t\ttemp -= 1\n\n\t\tif temp == 0:\n\t\t\tflag = 0\n\n\tans += 1\n\ti += temp\n\n\t# print(i, ans)\n\n\tif i == n-1 or not(flag):\n\t\tbreak\n\nif i+1 == n:\n\tprint(ans)\nelse:\n\tprint(-1)\n", "passed": true, "time": 0.21, "memory": 14420.0, "status": "done"}, {"code": "def solve():\n\tn, d = list(map(int, input().split()))\n\tn -= 1\n\ts = input()\n\n\ti = 0\n\tres = 0\n\twhile (i < len(s)):\n\t\tr = min(len(s)-1,i+d)\n\t\tfor j in range(r,i,-1):\n\t\t\tif (s[j] == '1'):\n\t\t\t\ti = j\n\t\t\t\tres += 1\n\t\t\t\tbreak\n\t\telse:\n\t\t\tprint(-1)\n\t\t\treturn\n\t\tif (i == n):\n\t\t\tprint(res)\n\t\t\treturn\n\nsolve()\n\n", "passed": true, "time": 0.81, "memory": 14284.0, "status": "done"}]
[{"input": "8 4\n10010101\n", "output": "2\n"}, {"input": "4 2\n1001\n", "output": "-1\n"}, {"input": "8 4\n11100101\n", "output": "3\n"}, {"input": "12 3\n101111100101\n", "output": "4\n"}, {"input": "5 4\n11011\n", "output": "1\n"}, {"input": "5 4\n10001\n", "output": "1\n"}, {"input": "10 7\n1101111011\n", "output": "2\n"}, {"input": "10 9\n1110000101\n", "output": "1\n"}, {"input": "10 9\n1100000001\n", "output": "1\n"}, {"input": "20 5\n11111111110111101001\n", "output": "4\n"}, {"input": "20 11\n11100000111000011011\n", "output": "2\n"}, {"input": "20 19\n10100000000000000001\n", "output": "1\n"}, {"input": "50 13\n10011010100010100111010000010000000000010100000101\n", "output": "5\n"}, {"input": "50 8\n11010100000011001100001100010001110000101100110011\n", "output": "8\n"}, {"input": "99 4\n111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111\n", "output": "25\n"}, {"input": "99 98\n100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n", "output": "1\n"}, {"input": "100 5\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "output": "20\n"}, {"input": "100 4\n1111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111\n", "output": "25\n"}, {"input": "100 4\n1111111111111111111111111111111111111111111111111111111111111101111111011111111111111111111111111111\n", "output": "25\n"}, {"input": "100 3\n1111110111111111111111111111111111111111101111111111111111111111111101111111111111111111111111111111\n", "output": "34\n"}, {"input": "100 8\n1111111111101110111111111111111111111111111111111111111111111111111111110011111111111111011111111111\n", "output": "13\n"}, {"input": "100 7\n1011111111111111111011101111111011111101111111111101111011110111111111111111111111110111111011111111\n", "output": "15\n"}, {"input": "100 9\n1101111110111110101111111111111111011001110111011101011111111111010101111111100011011111111010111111\n", "output": "12\n"}, {"input": "100 6\n1011111011111111111011010110011001010101111110111111000111011011111110101101110110101111110000100111\n", "output": "18\n"}, {"input": "100 7\n1110001111101001110011111111111101111101101001010001101000101100000101101101011111111101101000100001\n", "output": "16\n"}, {"input": "100 11\n1000010100011100011011100000010011001111011110100100001011010100011011111001101101110110010110001101\n", "output": "10\n"}, {"input": "100 9\n1001001110000011100100000001000110111101101010101001000101001010011001101100110011011110110011011111\n", "output": "13\n"}, {"input": "100 7\n1010100001110101111011000111000001110100100110110001110110011010100001100100001110111100110000101001\n", "output": "18\n"}, {"input": "100 10\n1110110000000110000000101110100000111000001011100000100110010001110111001010101000011000000001011011\n", "output": "12\n"}, {"input": "100 13\n1000000100000000100011000010010000101010011110000000001000011000110100001000010001100000011001011001\n", "output": "9\n"}, {"input": "100 11\n1000000000100000010000100001000100000000010000100100000000100100001000000001011000110001000000000101\n", "output": "12\n"}, {"input": "100 22\n1000100000001010000000000000000001000000100000000000000000010000000000001000000000000000000100000001\n", "output": "7\n"}, {"input": "100 48\n1000000000000000011000000000000000000000000000000001100000000000000000000000000000000000000000000001\n", "output": "3\n"}, {"input": "100 48\n1000000000000000000000100000000000000000000000000000000000000000000001000000000000000000100000000001\n", "output": "3\n"}, {"input": "100 75\n1000000100000000000000000000000000000000000000000000000000000000000000000000000001000000000000000001\n", "output": "3\n"}, {"input": "100 73\n1000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000001\n", "output": "2\n"}, {"input": "100 99\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n", "output": "1\n"}, {"input": "100 1\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "output": "99\n"}, {"input": "100 2\n1111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111\n", "output": "50\n"}, {"input": "100 1\n1111111111111111011111111111111111111111111111111111111111111111111101111111111111111111111111111111\n", "output": "-1\n"}, {"input": "100 3\n1111111111111111111111111101111111111111111111111011111111111111111111111111111011111111111111111111\n", "output": "33\n"}, {"input": "100 1\n1101111111111111111111101111111111111111111111111111111111111011111111101111101111111111111111111111\n", "output": "-1\n"}, {"input": "100 6\n1111111111111111111111101111111101011110001111111111111111110111111111111111111111111110010111111111\n", "output": "17\n"}, {"input": "100 2\n1111111101111010110111011011110111101111111011111101010101011111011111111111111011111001101111101111\n", "output": "-1\n"}, {"input": "100 8\n1100110101111001101001111000111100110100011110111011001011111110000110101000001110111011100111011011\n", "output": "14\n"}, {"input": "100 10\n1000111110100000001001101100000010011100010101001100010011111001001101111110110111101111001010001101\n", "output": "11\n"}, {"input": "100 7\n1110000011010001110101011010000011110001000000011101110111010110001000011101111010010001101111110001\n", "output": "-1\n"}, {"input": "100 3\n1111010001000001011011000011001111000100101000101101000010111101111000010000011110110011001101010111\n", "output": "-1\n"}, {"input": "100 9\n1101010101101100010111011000010100001010000101010011001001100010110110000000010000101000000001101101\n", "output": "13\n"}, {"input": "100 14\n1010100000000000010101000010001100000000000011100010000001000001011010001110001010100000100001101101\n", "output": "9\n"}, {"input": "100 13\n1000000001101001110000010000011001000000000000001010000000100001001010000000000000000100010000000001\n", "output": "-1\n"}, {"input": "100 18\n1000000000000000110000000000000000010000000001000001000001000000000100000000000010000000000000000001\n", "output": "-1\n"}, {"input": "100 32\n1000000000000000000000000001000000000000000000000101000000000000000000000000000000000001000000000001\n", "output": "-1\n"}, {"input": "100 79\n1000000001000000000101000000000000000000000000000000000000000000000000000000000000000000000000000001\n", "output": "2\n"}, {"input": "100 41\n1000000000000000000000000000000000010000000000000000000000000000000000000000100000000000000000000001\n", "output": "3\n"}, {"input": "100 82\n1000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001\n", "output": "2\n"}, {"input": "100 96\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n", "output": "-1\n"}, {"input": "43 30\n1001000001111111010100100100110101011101101\n", "output": "2\n"}, {"input": "7 1\n1111111\n", "output": "6\n"}, {"input": "9 3\n101000001\n", "output": "-1\n"}, {"input": "10 3\n1100000001\n", "output": "-1\n"}, {"input": "8 2\n10000101\n", "output": "-1\n"}, {"input": "2 1\n11\n", "output": "1\n"}]
286
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$. For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$. The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$. The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $[1, 1, 1, 1, 1]$ is $5$, the weight of the split $[5, 5, 3, 3, 3]$ is $2$ and the weight of the split $[9]$ equals $1$. For a given $n$, find out the number of different weights of its splits. -----Input----- The first line contains one integer $n$ ($1 \leq n \leq 10^9$). -----Output----- Output one integerΒ β€” the answer to the problem. -----Examples----- Input 7 Output 4 Input 8 Output 5 Input 9 Output 5 -----Note----- In the first sample, there are following possible weights of splits of $7$: Weight 1: [$\textbf 7$] Weight 2: [$\textbf 3$, $\textbf 3$, 1] Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1] Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$]
interview
[{"code": "n = int(input())\n\nprint(1 + n // 2)\n", "passed": true, "time": 0.15, "memory": 14332.0, "status": "done"}, {"code": "def li():\n return list(map(int, input().split()))\n\nn = int(input())\nprint(n // 2 + 1)\n", "passed": true, "time": 0.93, "memory": 14276.0, "status": "done"}, {"code": "def inpmap():\n return list(map(int, input().split()))\nn = int(input())\nprint(n // 2 + 1)\n", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "n = int(input())\nprint(n//2 + 1)\n", "passed": true, "time": 0.94, "memory": 14344.0, "status": "done"}, {"code": "n = int(input())\na = n // 2 + 1\nprint(a)", "passed": true, "time": 0.15, "memory": 14248.0, "status": "done"}, {"code": "print(int(input()) // 2 + 1)", "passed": true, "time": 0.14, "memory": 14476.0, "status": "done"}, {"code": "n = int(input())\n\nprint(n//2 + 1)", "passed": true, "time": 0.15, "memory": 14376.0, "status": "done"}, {"code": "n = int(input())\nprint(n // 2 + 1)", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "import sys\n\ninput = sys.stdin.readline\n\nn = int(input())\n\nprint(n//2+1)", "passed": true, "time": 0.94, "memory": 14288.0, "status": "done"}, {"code": "print(int(input())//2 + 1)\n", "passed": true, "time": 0.14, "memory": 14204.0, "status": "done"}, {"code": "n = int(input())\nprint(n // 2 + 1)", "passed": true, "time": 0.14, "memory": 14396.0, "status": "done"}, {"code": "n = int(input())\nprint(n // 2 + 1)\n\n", "passed": true, "time": 0.14, "memory": 14364.0, "status": "done"}, {"code": "n = int(input())\nif n == 1:\n print(1)\nelif n == 2:\n print(2)\nelif n == 3:\n print(2)\nelse:\n print(n // 2 + 1)\n", "passed": true, "time": 0.24, "memory": 14408.0, "status": "done"}, {"code": "n=int(input())\nprint(n//2+1)", "passed": true, "time": 0.22, "memory": 14252.0, "status": "done"}, {"code": "num = int(input())\n\nprint(int(num / 2) + 1)", "passed": true, "time": 0.15, "memory": 14248.0, "status": "done"}, {"code": "N = int(input())\nprint(N//2 + 1)\n", "passed": true, "time": 0.15, "memory": 14252.0, "status": "done"}, {"code": "n = int(input())\nprint(n//2 + 1)", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "n=int(input())\nprint(n//2+1)", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "n = int(input())\n\nprint((n//2)+1)", "passed": true, "time": 0.14, "memory": 14240.0, "status": "done"}, {"code": "import queue\n\ndef readTuple():\n return input().split()\ndef readInts():\n return tuple(map(int, readTuple()))\n\ndef solve():\n n = int(input().strip())\n print(n//2+1)\n\n\n\n\n\ndef __starting_point():\n solve()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "n = int(input())\na = n // 2 + 1\nprint(a)", "passed": true, "time": 0.14, "memory": 14376.0, "status": "done"}, {"code": "print(int(input()) // 2 + 1)\n", "passed": true, "time": 0.15, "memory": 14240.0, "status": "done"}]
[{"input": "7\n", "output": "4\n"}, {"input": "8\n", "output": "5\n"}, {"input": "9\n", "output": "5\n"}, {"input": "1\n", "output": "1\n"}, {"input": "286\n", "output": "144\n"}, {"input": "48\n", "output": "25\n"}, {"input": "941\n", "output": "471\n"}, {"input": "45154\n", "output": "22578\n"}, {"input": "60324\n", "output": "30163\n"}, {"input": "91840\n", "output": "45921\n"}, {"input": "41909\n", "output": "20955\n"}, {"input": "58288\n", "output": "29145\n"}, {"input": "91641\n", "output": "45821\n"}, {"input": "62258\n", "output": "31130\n"}, {"input": "79811\n", "output": "39906\n"}, {"input": "88740\n", "output": "44371\n"}, {"input": "12351\n", "output": "6176\n"}, {"input": "1960\n", "output": "981\n"}, {"input": "29239\n", "output": "14620\n"}, {"input": "85801\n", "output": "42901\n"}, {"input": "43255\n", "output": "21628\n"}, {"input": "13439\n", "output": "6720\n"}, {"input": "35668\n", "output": "17835\n"}, {"input": "19122\n", "output": "9562\n"}, {"input": "60169\n", "output": "30085\n"}, {"input": "50588\n", "output": "25295\n"}, {"input": "2467\n", "output": "1234\n"}, {"input": "39315\n", "output": "19658\n"}, {"input": "29950\n", "output": "14976\n"}, {"input": "17286\n", "output": "8644\n"}, {"input": "7359066\n", "output": "3679534\n"}, {"input": "1016391\n", "output": "508196\n"}, {"input": "7928871\n", "output": "3964436\n"}, {"input": "3968891\n", "output": "1984446\n"}, {"input": "2636452\n", "output": "1318227\n"}, {"input": "5076901\n", "output": "2538451\n"}, {"input": "9870265\n", "output": "4935133\n"}, {"input": "2453786\n", "output": "1226894\n"}, {"input": "7263670\n", "output": "3631836\n"}, {"input": "1890845\n", "output": "945423\n"}, {"input": "574128507\n", "output": "287064254\n"}, {"input": "648476655\n", "output": "324238328\n"}, {"input": "97349542\n", "output": "48674772\n"}, {"input": "716489761\n", "output": "358244881\n"}, {"input": "858771038\n", "output": "429385520\n"}, {"input": "520778784\n", "output": "260389393\n"}, {"input": "439004204\n", "output": "219502103\n"}, {"input": "589992198\n", "output": "294996100\n"}, {"input": "371106544\n", "output": "185553273\n"}, {"input": "894241590\n", "output": "447120796\n"}, {"input": "123957268\n", "output": "61978635\n"}, {"input": "234149297\n", "output": "117074649\n"}, {"input": "789954052\n", "output": "394977027\n"}, {"input": "667978920\n", "output": "333989461\n"}, {"input": "154647261\n", "output": "77323631\n"}, {"input": "751453521\n", "output": "375726761\n"}, {"input": "848862308\n", "output": "424431155\n"}, {"input": "323926781\n", "output": "161963391\n"}, {"input": "576768825\n", "output": "288384413\n"}, {"input": "31293802\n", "output": "15646902\n"}, {"input": "2\n", "output": "2\n"}, {"input": "1000000000\n", "output": "500000001\n"}, {"input": "3\n", "output": "2\n"}]
287
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale. Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly k already inhabited apartments, but he doesn't know their indices yet. Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim. -----Input----- The only line of the input contains two integers: n and k (1 ≀ n ≀ 10^9, 0 ≀ k ≀ n). -----Output----- Print the minimum possible and the maximum possible number of apartments good for Maxim. -----Example----- Input 6 3 Output 1 3 -----Note----- In the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good.
interview
[{"code": "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\ngosa = 1.0 / 10**10\nmod = 10**9+7\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\n\n\ndef main():\n n,k = LI()\n if k == 0 or n==k:\n return '0 0'\n\n return \"1 {}\".format(min(n-k, k*2))\n\nprint(main())\n\n\n\n", "passed": true, "time": 0.16, "memory": 14364.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\nans1, ans2 = 0, 0\n\nif(k != 0 and k != n):\n\tans1 = 1\nif(3*k < n):\n\tans2 = 2*k\nelse:\n\tans2 = n-k\n\nprint(ans1, ans2)\n", "passed": true, "time": 0.15, "memory": 14292.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\nprint(min(n - k, min(k, 1)), min(2 * k, n - k))", "passed": true, "time": 0.19, "memory": 14348.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 = map_input()\na = -1\nb = -1\nif k == 0 or k == n:\n a = 0\n b = 0\nelse:\n a = 1\n b = n-k\n b = min(b,k*2)\nprint(a,b) \n", "passed": true, "time": 0.76, "memory": 14332.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nmini, maxi = 0, 0\nif n > k and k != 0: \n mini = 1\nelse:\n mini = 0\n\nif (n > 3 * k):\n maxi = 2 * k\nelse:\n maxi = n - k\nprint(mini, maxi)", "passed": true, "time": 0.76, "memory": 14396.0, "status": "done"}, {"code": "from math import ceil\nn,k = list(map(int, input().split()))\n\nif k > 0 and k < n:\n ans1 = 1\nelse:\n ans1=0\nif k >= ceil(n/3):\n ans2 = n-k\nelse:\n ans2 = 2*k\n\nprint(ans1, ans2)\n", "passed": true, "time": 0.76, "memory": 14428.0, "status": "done"}, {"code": "from sys import stdin, stdout\n\nn,k = list(map(int,stdin.readline().rstrip().split()))\n\nminH = min([1,k,n-k])\nmaxH = min([2*k,n-k])\n\nprint(str(minH) + ' ' + str(maxH))\n", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "#!/bin/python3\n\nimport sys\nn,k=map(int,input().split())\nif k!=0:\n print (str(min(1,n-k)),str(min(2*k,n-k)))\nelse:\n print (\"0 0\")", "passed": true, "time": 0.28, "memory": 14536.0, "status": "done"}, {"code": "n,k=list(map(int,input().split()))\nlow=-1\nhigh=-1\nif k==0:\n low=0\n high=0\nelse:\n if k==n:\n low=0\n high=0\n else:\n low=1\n if n>=3*k:\n high = 2*k\n else:\n high = n-k\nprint(low,high)\n", "passed": true, "time": 0.22, "memory": 14288.0, "status": "done"}, {"code": "n,k = map(int,input().split())\nif(k == 0):\n\tmini = 0\n\tmaxi = 0\nelif(k == n):\n\tmini = 0\n\tmaxi = 0\nelse:\n\tmini = 1\n\tmaxi = 2*k\n\tmaxi = min(maxi,n-k)\n\nprint(mini, maxi)", "passed": true, "time": 0.14, "memory": 14532.0, "status": "done"}, {"code": "import sys\n\n\ndef main():\n n, k = list(map(int, sys.stdin.readline().split()))\n if k == 0 or k == n:\n print(0, 0)\n return\n\n if k * 3 >= n:\n m = n - k\n else:\n m = 2 * k\n\n print(1, m)\n\n\nmain()\n", "passed": true, "time": 0.14, "memory": 14500.0, "status": "done"}, {"code": "apartments_nr, neighbours_nr = (int(x) for x in input().split())\nmin_ans = int(apartments_nr != neighbours_nr)\nif neighbours_nr == 0:\n min_ans = 0\nmax_ans = min(2 * neighbours_nr, apartments_nr - neighbours_nr)\nprint(min_ans, max_ans)\n\n\n", "passed": true, "time": 0.76, "memory": 14560.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\na = 0 if k == 0 or k == n else 1\nb = min(2 * k, n - k)\nprint(\"%d %d\" % (a, b))\n", "passed": true, "time": 0.29, "memory": 14252.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nif k == 0 or k >= n:\n print(0, 0)\nelif 3 * k >= n:\n print(1, n - k)\nelse:\n print(1, k * 2)", "passed": true, "time": 0.14, "memory": 14536.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nif k == n or k == 0:\n a = 0\nelse:\n a = 1\nb = 0\nif n == k or k == 0:\n b = 0\nelse:\n b = min(n // 3, k) * 2\n k -= min(n // 3, k)\n if k != 0:\n if n % 3 == 1:\n k -= 1\n elif n % 3 == 2:\n k -= 1\n b += 1\n b -= k\nprint(a, b)", "passed": true, "time": 0.19, "memory": 14596.0, "status": "done"}, {"code": "n,k = map(int, input().split())\n\nm,M = 0,0\n\nif n > k > 0:\n m = 1\n\nK = (n+2)//3\nif k < K:\n M = k*2\nelse:\n M = n - k\n\nprint(m,M)", "passed": true, "time": 0.14, "memory": 14356.0, "status": "done"}, {"code": "n, k = map(int,input().split())\nworst = 1 if 1 <= k < n else 0\nbest = min(n-k, 2*k)\nprint(worst, best)", "passed": true, "time": 0.15, "memory": 14276.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nif n == 1 or k == 0 or k == n:\n print(0, 0)\nelif n // k < 3:\n print(1, n-k)\nelse:\n print(1, 2*k)\n\n", "passed": true, "time": 0.14, "memory": 14268.0, "status": "done"}, {"code": "\n\ndef main():\n n, k = list(map(int, list(input().split())))\n _min = 0\n _max = 0\n if k == n or k == 0:\n print(0, 0)\n return\n _min = 1\n if n <= 3 * k:\n _max = n - k\n else:\n _max = k * 2\n\n print(_min, _max)\nmain()\n", "passed": true, "time": 0.15, "memory": 14312.0, "status": "done"}, {"code": "n, k = map(int, input().split())\n\ndef min(a, b):\n\tif a < b:\n\t\treturn a\n\treturn b\nif k == 0:\n\tprint(0, 0)\nelse:\n\tprint(min(n-k, 1), min(n-k, 2*k))", "passed": true, "time": 0.21, "memory": 14408.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\n\nif m <= 0 or m >= n:\n\ta = 0\nelse:\n\ta = 1\n\nb = 0\nif m > 0:\n\tif m * 2 <= n:\n\t\tif n % 2 == 0 and m >= n // 2:\n\t\t\tb = max(b, m)\n\t\telse:\n\t\t\tb = max(b, m + 1)\n\telse:\n\t\tb = max(b, (n - n // 2) - (m - n // 2))\n\n\tif m * 3 <= n:\n\t\tb = max(b, m * 2)\n\telse:\n\t\tb = max(b, n // 3 * 2 - (m - n // 3 - n % 3))\n\nprint(a, b)\n", "passed": true, "time": 0.15, "memory": 14420.0, "status": "done"}, {"code": "n,k=[int(i)for i in input().split()]\nif k==n:\n\tprint(0,0)\n\treturn\nif k==0:\n\tprint(0,0)\n\treturn\t\t\na = 1\nb=0\nh = n//3\nif k<=h:\n\tb = 2*k\nelse :\n\tk-=h\n\tb = h*2 + n%3\n\tif n%3>0:\n\t \tk-=1\n\t \tb-=1 \t\n\tb -=k\nprint(a,b)\t \t\n\n\n\n", "passed": true, "time": 0.19, "memory": 14504.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nif k == 0 or k == n:\n print(0, 0)\nelse:\n c = n // 3\n m = n % 3\n if c >= k:\n print(1, k * 2)\n else:\n ans = c * 2\n if m == 2:\n ans += 1\n k -= 1\n elif m == 1:\n k -= 1\n ans -= (k - c)\n print(1, ans)", "passed": true, "time": 0.19, "memory": 14216.0, "status": "done"}, {"code": "n, k = map(int, input().split())\n\nif k == 0 or k == n:\n print('0 0')\nelse:\n mi = 1\n groups = n // 3\n \n if groups >= k:\n ma = 2 * k\n else:\n ma = n - k\n \n print(mi, ma)", "passed": true, "time": 0.14, "memory": 14264.0, "status": "done"}]
[{"input": "6 3\n", "output": "1 3\n"}, {"input": "10 1\n", "output": "1 2\n"}, {"input": "10 9\n", "output": "1 1\n"}, {"input": "8 0\n", "output": "0 0\n"}, {"input": "8 8\n", "output": "0 0\n"}, {"input": "966871928 890926970\n", "output": "1 75944958\n"}, {"input": "20 2\n", "output": "1 4\n"}, {"input": "1 0\n", "output": "0 0\n"}, {"input": "1 1\n", "output": "0 0\n"}, {"input": "2 0\n", "output": "0 0\n"}, {"input": "2 1\n", "output": "1 1\n"}, {"input": "2 2\n", "output": "0 0\n"}, {"input": "7 2\n", "output": "1 4\n"}, {"input": "8 3\n", "output": "1 5\n"}, {"input": "9 4\n", "output": "1 5\n"}, {"input": "10 3\n", "output": "1 6\n"}, {"input": "10 4\n", "output": "1 6\n"}, {"input": "10 5\n", "output": "1 5\n"}, {"input": "1000 1000\n", "output": "0 0\n"}, {"input": "1000 333\n", "output": "1 666\n"}, {"input": "1000 334\n", "output": "1 666\n"}, {"input": "999 333\n", "output": "1 666\n"}, {"input": "999 334\n", "output": "1 665\n"}, {"input": "998 332\n", "output": "1 664\n"}, {"input": "998 333\n", "output": "1 665\n"}, {"input": "89 4\n", "output": "1 8\n"}, {"input": "66 50\n", "output": "1 16\n"}, {"input": "88 15\n", "output": "1 30\n"}, {"input": "95 43\n", "output": "1 52\n"}, {"input": "900 344\n", "output": "1 556\n"}, {"input": "777 113\n", "output": "1 226\n"}, {"input": "964 42\n", "output": "1 84\n"}, {"input": "982 867\n", "output": "1 115\n"}, {"input": "1000000000 0\n", "output": "0 0\n"}, {"input": "1000000000 1000000000\n", "output": "0 0\n"}, {"input": "1000000000 333333333\n", "output": "1 666666666\n"}, {"input": "1000000000 333333334\n", "output": "1 666666666\n"}, {"input": "999999999 333333333\n", "output": "1 666666666\n"}, {"input": "999999999 333333334\n", "output": "1 666666665\n"}, {"input": "999999998 333333332\n", "output": "1 666666664\n"}, {"input": "999999998 333333333\n", "output": "1 666666665\n"}, {"input": "78602604 42160832\n", "output": "1 36441772\n"}, {"input": "35679021 9137902\n", "output": "1 18275804\n"}, {"input": "41949373 13173511\n", "output": "1 26347022\n"}, {"input": "77855558 49163875\n", "output": "1 28691683\n"}, {"input": "87187123 2851901\n", "output": "1 5703802\n"}, {"input": "66849627 25004217\n", "output": "1 41845410\n"}, {"input": "873046672 517064947\n", "output": "1 355981725\n"}, {"input": "639857373 1393427\n", "output": "1 2786854\n"}, {"input": "637563683 69636269\n", "output": "1 139272538\n"}, {"input": "911669737 141068293\n", "output": "1 282136586\n"}, {"input": "547575919 313272818\n", "output": "1 234303101\n"}, {"input": "955020006 297895809\n", "output": "1 595791618\n"}, {"input": "10 4\n", "output": "1 6\n"}, {"input": "11 3\n", "output": "1 6\n"}, {"input": "10 3\n", "output": "1 6\n"}, {"input": "4 1\n", "output": "1 2\n"}, {"input": "9 3\n", "output": "1 6\n"}, {"input": "7 2\n", "output": "1 4\n"}, {"input": "7 3\n", "output": "1 4\n"}, {"input": "12 5\n", "output": "1 7\n"}, {"input": "8 3\n", "output": "1 5\n"}, {"input": "1000 8\n", "output": "1 16\n"}]
288
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately. Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament. Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help. -----Input----- The only line of the input contains a single integer n (2 ≀ n ≀ 10^18)Β β€” the number of players to participate in the tournament. -----Output----- Print the maximum number of games in which the winner of the tournament can take part. -----Examples----- Input 2 Output 1 Input 3 Output 2 Input 4 Output 2 Input 10 Output 4 -----Note----- In all samples we consider that player number 1 is the winner. In the first sample, there would be only one game so the answer is 1. In the second sample, player 1 can consequently beat players 2 and 3. In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
interview
[{"code": "n = int(input())\nx = 0\ncur = 1\nlst = 1\nwhile cur + lst <= n:\n cur, lst = cur + lst, cur\n x += 1\nprint(x)\n", "passed": true, "time": 0.15, "memory": 14236.0, "status": "done"}, {"code": "n=int(input())\na,b=1,1\nans=0\nwhile b<=n:\n a,b=b,a+b\n ans+=1\nprint(ans-1)\n", "passed": true, "time": 0.17, "memory": 14312.0, "status": "done"}, {"code": "n = int(input())\nprev, cur = 1, 2\niters = 0\nwhile (cur < n):\n prev, cur = cur, cur + prev\n iters += 1\nans = iters + bool(cur == n)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14240.0, "status": "done"}, {"code": "def solve(n):\n k = 0\n f1, f2 = 1, 2\n while not f1 <= n < f2:\n k += 1\n t = f1\n f1 = f2\n f2 = f1 + t\n return k\n\nn = int(input())\nprint(solve(n))\n", "passed": true, "time": 0.16, "memory": 14292.0, "status": "done"}, {"code": "n = int(input())\n\ndp = {1: 2, 2: 3}\n\ndef cost(i):\n if i not in dp:\n dp[i] = cost(i-1) + cost(i-2)\n return dp[i]\n\nans = 1\n\nwhile cost(ans) <= n:\n ans += 1\n\nprint(ans-1)\n", "passed": true, "time": 0.14, "memory": 14460.0, "status": "done"}, {"code": "# You lost the game.\n\nn = int(input())\n\nT = {}\n\n\nT[1] = 2\nT[2] = 3\nT[3] = 5\nT[4] = 8\n\nt = 1\nr = 0\nwhile r < 4 and t <= n:\n r += 1\n t = T[r]\n \nwhile t <= n:\n r += 1\n t += T[r-2]\n T[r] = t\n \nprint(r-1)\n", "passed": true, "time": 0.15, "memory": 14460.0, "status": "done"}, {"code": "n=int(input())\nif n==2:\n print(1)\nelse:\n ans=3\n oldans=2\n count=2\n b=0\n while ans<=n:\n if ans==n:\n b=1\n print(count)\n break\n else:\n oldans,ans=ans,ans+oldans\n count+=1\n if b==0:\n print(count-1)\n \n \n", "passed": true, "time": 0.16, "memory": 14420.0, "status": "done"}, {"code": "n = int(input())\n\nl = []\nl.append(0)\nl.append(1)\nl.append(2)\n\nk = 2\nm = 1\n\nwhile k < n:\n k = k + l[m]\n m = m + 1\n l.append(k)\n \nif k > n:\n m = m - 1\n\nprint(m)", "passed": true, "time": 0.25, "memory": 14476.0, "status": "done"}, {"code": "n = int(input())\nfib = [1, 2]\nfor i in range(2, 10000):\n fib.append(fib[i - 1] + fib[i - 2])\nl = 0\nr = 10000\nwhile (r - l > 1):\n mid = (r + l) // 2\n if (fib[mid] > n):\n r = mid\n else:\n l = mid\nprint(l)", "passed": true, "time": 0.31, "memory": 16444.0, "status": "done"}, {"code": "def h(z):\n a = 0\n b = 1\n res = 1\n while True:\n a, b = b, a + b + 1\n if b >= z:\n break\n res += 1 \n return res\n \nn = int(input())\nprint(h(n)) ", "passed": true, "time": 0.15, "memory": 14276.0, "status": "done"}, {"code": "n = int(input())\ngames = n - 1\nmassiv = [2]\nwhile massiv[-1] <= games:\n if len(massiv) == 1:\n massiv += [4]\n else: \n massiv += [massiv[-1] + massiv[-2] + 1]\nprint(len(massiv)) ", "passed": true, "time": 0.16, "memory": 14272.0, "status": "done"}, {"code": "def cost(nk):\n \n ns = max(0, k - 1)\n if ns > n - 2:\n return 0\n \n return f(n - ns - 1, k + 1) + 1\n\n\nn = int(input())\nF = [0] * 100\nF[0] = 1\nF[1] = 2\nans = 1\n\nfor i in range(2, 100):\n F[i] = F[i - 1] + F[i - 2]\n if F[i] <= n:\n ans = i\n \nprint(ans)", "passed": true, "time": 0.16, "memory": 14408.0, "status": "done"}, {"code": "n = int(input())\n\nif n == 2:\n\tprint(1)\nelif n == 3:\n\tprint(2)\nelse:\n\tx = 2\n\ty = 3\n\tcounter = 0\n\twhile x+ y <= n:\n\t\tx, y = y, x+y\n\t\tcounter += 1\n\tprint(2+counter)", "passed": true, "time": 0.16, "memory": 14444.0, "status": "done"}, {"code": "n = int(input())\nf = [1, 1]\nwhile f[-1] < n:\n\tf += [f[-1] + f[-2]]\nif f[-1] == n:\n\tprint(len(f) - 2)\nelse:\n\tprint(len(f) - 3)", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "n = int(input())\n\nlst1 = 1\nlst2 = 1\n\ncnt = 0\n\nwhile (True):\n cnt += 1\n lst1, lst2 = lst2, lst1\n if (lst1 + lst2 == n):\n print(cnt)\n return\n if (lst1 + lst2 > n):\n print(cnt - 1)\n return\n lst2 = lst1 + lst2", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "n = int(input())\nf = []\nans = 1\nf.append(1)\nf.append(2)\nwhile f[ans] < n:\n f.append(f[ans] + f[ans - 1])\n ans += 1\nif f[ans] == n:\n print(ans)\nelse:\n print(ans - 1)", "passed": true, "time": 0.14, "memory": 14492.0, "status": "done"}, {"code": "a = []\na.append(1)\na.append(1)\nn = int(input())\nif (n == 2):\n print(1)\n return\ni = 2\nwhile(1):\n a.append(a[i - 1] + a[i - 2])\n if (a[i] >= n):\n print(i - 2 + int(a[i] == n))\n break\n i += 1", "passed": true, "time": 0.14, "memory": 14364.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\nt = [2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946,\n17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309,\n3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141,\n267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049,\n12586269025, 20365011074, 32951280099, 53316291173, 86267571272, 139583862445, 225851433717,\n365435296162, 591286729879, 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842,\n10610209857723, 17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994,\n190392490709135, 308061521170129, 498454011879264, 806515533049393, 1304969544928657, 2111485077978050,\n3416454622906707, 5527939700884757, 8944394323791464, 14472334024676221, 23416728348467685,\n37889062373143906, 61305790721611591, 99194853094755497, 160500643816367088, 259695496911122585,\n420196140727489673, 679891637638612258, 1100087778366101931, 1779979416004714189, 2880067194370816120,\n4660046610375530309, 7540113804746346429]\n\nn = ri()\n\nfor i in range(len(t)):\n if n < t[i]:\n print(i)\n break\n", "passed": true, "time": 0.14, "memory": 14612.0, "status": "done"}, {"code": "n = int(input())\n\nf = 2\ng = 1\nc = 0\n\nwhile f <= n:\n\tf, g = f+g, f\n\tc += 1\n\nprint(c)", "passed": true, "time": 0.21, "memory": 14284.0, "status": "done"}, {"code": "def tennis(n):\n u,v = 1,2\n j = 1\n while v <= n:\n u,v = v, u+v\n j += 1\n return j-1\n\nprint(tennis(int(input())))\n", "passed": true, "time": 0.14, "memory": 14304.0, "status": "done"}, {"code": "fmap = lambda f, l: list(map(f, l))\nparse_int = lambda: fmap(int, input().split())\n\nDEBUG = False#True#\n\n\nn = int(input())\n\ncost_of = [0, 1, 2, 4, 7, 12, 20, 33, 54, 88, 143, 232, 376, 609, 986, 1596, 2583, 4180, 6764, 10945, 17710, 28656, 46367, 75024, 121392, 196417, 317810, 514228, 832039, 1346268, 2178308, 3524577, 5702886, 9227464, 14930351, 24157816, 39088168, 63245985, 102334154, 165580140, 267914295, 433494436, 701408732, 1134903169, 1836311902, 2971215072, 4807526975, 7778742048, 12586269024, 20365011073, 32951280098, 53316291172, 86267571271, 139583862444, 225851433716, 365435296161, 591286729878, 956722026040, 1548008755919, 2504730781960, 4052739537880, 6557470319841, 10610209857722, 17167680177564, 27777890035287, 44945570212852, 72723460248140, 117669030460993, 190392490709134, 308061521170128, 498454011879263, 806515533049392, 1304969544928656, 2111485077978049, 3416454622906706, 5527939700884756, 8944394323791463, 14472334024676220, 23416728348467684, 37889062373143905, 61305790721611590, 99194853094755496, 160500643816367087, 259695496911122584, 420196140727489672, 679891637638612257, 1100087778366101930, 1779979416004714188]\n\nfor i in range(len(cost_of)):\n if cost_of[i]>n-1: break\nprint(i-1)\n", "passed": true, "time": 0.14, "memory": 14428.0, "status": "done"}]
[{"input": "2\n", "output": "1\n"}, {"input": "3\n", "output": "2\n"}, {"input": "4\n", "output": "2\n"}, {"input": "10\n", "output": "4\n"}, {"input": "1000\n", "output": "14\n"}, {"input": "2500\n", "output": "15\n"}, {"input": "690000\n", "output": "27\n"}, {"input": "3000000000\n", "output": "45\n"}, {"input": "123456789123456789\n", "output": "81\n"}, {"input": "5\n", "output": "3\n"}, {"input": "143\n", "output": "9\n"}, {"input": "144\n", "output": "10\n"}, {"input": "145\n", "output": "10\n"}, {"input": "232\n", "output": "10\n"}, {"input": "233\n", "output": "11\n"}, {"input": "234\n", "output": "11\n"}, {"input": "679891637638612257\n", "output": "84\n"}, {"input": "679891637638612258\n", "output": "85\n"}, {"input": "679891637638612259\n", "output": "85\n"}, {"input": "1000000000000000000\n", "output": "85\n"}, {"input": "10235439547\n", "output": "47\n"}, {"input": "1240723548\n", "output": "43\n"}, {"input": "92353046212453\n", "output": "66\n"}, {"input": "192403205846532\n", "output": "68\n"}, {"input": "13925230525389\n", "output": "62\n"}, {"input": "12048230592523\n", "output": "62\n"}, {"input": "19204385325853\n", "output": "63\n"}, {"input": "902353283921\n", "output": "56\n"}, {"input": "793056859214355\n", "output": "70\n"}, {"input": "982045466234565\n", "output": "71\n"}, {"input": "126743950353465\n", "output": "67\n"}, {"input": "12405430465\n", "output": "47\n"}, {"input": "10238439257768\n", "output": "61\n"}, {"input": "1728493055346\n", "output": "58\n"}, {"input": "927553829046\n", "output": "56\n"}, {"input": "62735129403\n", "output": "51\n"}, {"input": "71624823950223\n", "output": "65\n"}, {"input": "8902353464851212\n", "output": "75\n"}, {"input": "61824012598535\n", "output": "65\n"}, {"input": "1294902504603347\n", "output": "71\n"}, {"input": "6\n", "output": "3\n"}, {"input": "7\n", "output": "3\n"}, {"input": "8\n", "output": "4\n"}, {"input": "9\n", "output": "4\n"}, {"input": "11\n", "output": "4\n"}, {"input": "12\n", "output": "4\n"}, {"input": "13\n", "output": "5\n"}, {"input": "14\n", "output": "5\n"}, {"input": "15\n", "output": "5\n"}, {"input": "16\n", "output": "5\n"}, {"input": "17\n", "output": "5\n"}, {"input": "18\n", "output": "5\n"}, {"input": "19\n", "output": "5\n"}, {"input": "20\n", "output": "5\n"}, {"input": "21\n", "output": "6\n"}, {"input": "22\n", "output": "6\n"}, {"input": "23\n", "output": "6\n"}, {"input": "355687428096000\n", "output": "69\n"}, {"input": "576460752303423488\n", "output": "84\n"}, {"input": "32212254719\n", "output": "49\n"}, {"input": "26388279066623\n", "output": "63\n"}, {"input": "618473717761\n", "output": "56\n"}, {"input": "262406072477\n", "output": "54\n"}]
289
Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i.Β e. a letter "K" right after a letter "V") in the resulting string. -----Input----- The first line will contain a string s consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. -----Output----- Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. -----Examples----- Input VK Output 1 Input VV Output 1 Input V Output 0 Input VKKKKKKKKKVVVVVVVVVK Output 3 Input KVKV Output 1 -----Note----- For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear. For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring. For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences.
interview
[{"code": "s = input()\nd = dict()\nd['V'] = 'K'\nd['K'] = 'V'\nm = s.count('VK')\ns = list(s)\nfor i in range(len(s)):\n s[i] = d[s[i]]\n m = max(m,''.join(s).count('VK'))\n s[i] = d[s[i]]\nprint(m)", "passed": true, "time": 0.17, "memory": 14400.0, "status": "done"}, {"code": "def alternate(c):\n if c == \"V\":\n return \"K\"\n return \"V\"\n\ns = input()\nres = s.count(\"VK\")\nfor i in range(len(s)):\n res = max(res, (s[:i]+alternate(s[i])+s[i+1:]).count(\"VK\"))\nprint(res)", "passed": true, "time": 0.16, "memory": 14468.0, "status": "done"}, {"code": "import re\ndef count(s):\n return len(re.findall(r'VK', s))\n\ns = input().strip()\nbest = count(s)\nfor i in range(len(s)):\n cur_s = s[:i] + 'V' + s[i + 1:]\n best = max(best, count(cur_s))\n cur_s = s[:i] + 'K' + s[i + 1:]\n best = max(best, count(cur_s))\nprint(best)\n", "passed": true, "time": 0.16, "memory": 14520.0, "status": "done"}, {"code": "s=str(input())\nm=s.count('VK')\nfor i in range(len(s)):\n if s[i]=='V':\n t='K'\n else:\n t='V'\n temp=s[:i]+t+s[i+1:]\n #print(temp)\n if temp.count('VK')>m:\n m=temp.count('VK')\nprint(m)\n", "passed": true, "time": 0.16, "memory": 14528.0, "status": "done"}, {"code": "'''input\nKKKKKKV\n'''\ns = input().replace(\"VK\", \".\")\nif \"VV\" in s or \"KK\" in s:\n\tprint(s.count(\".\") + 1)\nelse:\n\tprint(s.count(\".\"))", "passed": true, "time": 0.23, "memory": 14488.0, "status": "done"}, {"code": "#!/usr/bin/env python3\nimport re\n\n\ndef solve():\n s = input()\n m = 0\n for i in range(len(s)):\n m = max(m, len(re.findall(\"VK\", s[:i]+\"V\"+s[i+1:])))\n m = max(m, len(re.findall(\"VK\", s[:i]+\"K\"+s[i+1:])))\n print(m)\n\n\ndef __starting_point():\n solve()\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14404.0, "status": "done"}, {"code": "def get(s):\n res = 0\n for i in range(len(s) - 1):\n if s[i] == 'V' and s[i + 1] == 'K':\n res += 1\n \n return res\n\n\ns = input()\nl = list(s)\n\nans = 0\nfor i in range(len(l)):\n st = l[i]\n \n l[i] = 'V'\n ans = max(ans, get(''.join(l)))\n \n l[i] = 'K'\n ans = max(ans, get(''.join(l)))\n \n l[i] = st\n \nprint(ans)", "passed": true, "time": 0.17, "memory": 14328.0, "status": "done"}, {"code": "s = input()\nmaxx = 0\nfor i in range(len(s)):\n news = s[:i] + 'V' + s[i+1:]\n maxx = max(news.count('VK'), maxx)\n news = s[:i] + 'K' + s[i + 1:]\n maxx = max(news.count('VK'), maxx)\nprint(maxx)\n", "passed": true, "time": 0.14, "memory": 14520.0, "status": "done"}, {"code": "s=input()\nif len(s)==1:\n print(0)\nelse:\n x=s.count('VK')\n for i in range(len(s)):\n if s[i]=='K':\n if i<len(s)-1 and s[i+1]=='K' and (i==0 or s[i-1]=='K'):\n x+=1\n break\n elif i>0 and s[i-1]=='V' and (i==len(s)-1 or s[i+1]=='V'):\n x+=1\n break\n print(x)\n", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}, {"code": "s = input().strip()\ns = s.replace(\"VK\", \"*\")\ncnt = sum(map(lambda x: x==\"*\",s))\nif \"VV\" in s or \"KK\" in s:\n cnt +=1\nprint(cnt) ", "passed": true, "time": 0.15, "memory": 14252.0, "status": "done"}, {"code": "s=input()\nm=s.count('VK')\nfor i in range(len(s)):\n s2=s[:i]+'V'+s[i+1:]\n s3=s[:i]+'K'+s[i+1:]\n m=max(m,s2.count('VK'))\n m=max(m,s3.count('VK'))\n #print(s2,s3)\nprint(m)", "passed": true, "time": 0.16, "memory": 14524.0, "status": "done"}, {"code": "l=input()\ns=[]\nfor i in l:\n\tif(i=='V'):\n\t\ts.append(1)\n\telse:\n\t\ts.append(0)\nls=len(s)\ni=0\nmaxc = 0\nc = 0\nwhile i+1<ls:\n\tif(s[i]==1 and s[i+1]==0):\n\t\tc+=1\n\ti+=1\nmaxc = max(maxc,c)\nj=0\nwhile j<ls:\n\tif(s[j]==1):\n\t\ts[j]=0\n\telse:\n\t\ts[j]=1\n\ti=0\n\tc=0\n\twhile i+1<ls:\n\t\tif(s[i]==1 and s[i+1]==0):\n\t\t\tc+=1\n\t\ti+=1\n\tmaxc=max(c,maxc)\n\tif(s[j]==1):\n\t\ts[j]=0\n\telse:\n\t\ts[j]=1\n\tj+=1\nprint(maxc)", "passed": true, "time": 0.16, "memory": 14440.0, "status": "done"}, {"code": "import sys\n\ndef solve():\n s = [ch for ch in input()]\n ans = ''.join(s).count('VK')\n\n for i in range(len(s)):\n if s[i] == 'V':\n s[i] = 'K'\n\n tmp = ''.join(s).count('VK')\n ans = max(ans, tmp)\n\n s[i] = 'V'\n else:\n s[i] = 'V'\n\n tmp = ''.join(s).count('VK')\n ans = max(ans, tmp)\n\n s[i] = 'K'\n\n print(ans)\n\ndef debug(x, table):\n for name, val in table.items():\n if x is val:\n print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)\n return None\n\ndef __starting_point():\n solve()\n__starting_point()", "passed": true, "time": 0.15, "memory": 14344.0, "status": "done"}, {"code": "def main():\n s = input()\n c = s.count('VK')\n if s.find('VVV') >= 0 or s.find('KKK') >= 0 or s[:2] == 'KK' or s[-2:] == 'VV':\n c += 1\n print(c)\nmain()", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "s=input()\na=s.count(\"VK\")\ns=s.replace(\"VK\",\" \")\na+=1 if \"VV\" in s or \"KK\" in s else 0\nprint(a)\n", "passed": true, "time": 0.15, "memory": 14536.0, "status": "done"}, {"code": "x=input()\nt=x.count(\"VK\")\nl=x.replace(\"VK\",\" \")\nif \"KK\" in l:\n t+=1\n print(t)\nelif \"VV\" in l:\n t+=1\n print(t)\nelse:\n print(t)", "passed": true, "time": 0.21, "memory": 14480.0, "status": "done"}, {"code": "from sys import stdin, stdout\n\na = stdin.readline().rstrip()\na=list(a)\n\nvkCount=0\nchange=False\nif a[0:2]==list('KK'):\n change=True\n a[0]='V'\nelif a[-2:]==list('VV'):\n change=True\n a[-1]='K'\n\ni=0\nwhile i<len(a)-2 and not change:\n if a[i:i+3]==list('VVV'):\n a[i+1]='K'\n change=True\n elif a[i:i+3]==list('KKK'):\n a[i+1]='V'\n change=True\n i+=1\n \nfor i in range(len(a)-1):\n if a[i:i+2]==list('VK'):\n vkCount+=1\n\nprint(vkCount)\n", "passed": true, "time": 0.15, "memory": 14464.0, "status": "done"}, {"code": "import sys\n\ndef main():\n s=sys.stdin.readline().rstrip()\n result=0\n \n for i in range(len(s)-1):\n if s[i:i+2]=='VK': result+=1\n \n if s.startswith('KK') or s.endswith('VV') or 'VKKK' in s or 'VVV' in s: result+=1\n \n sys.stdout.write(str(result)+'\\n')\n \nmain()\n\n", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "s = input()\nk = 0\nfor i in range(len(s) - 1):\n if s[i] == 'V' and s[i + 1] == 'K':\n k += 1\nfor i in range(len(s)):\n if i < len(s) - 1:\n if s[i] == 'V' and s[i + 1] == 'V' and i + 2 == len(s):\n k += 1\n break\n if s[i] == 'V' and s[i + 1] == 'V' and s[i + 2] == 'V':\n k += 1\n break\n if i >= 1:\n if i == 1 and s[1] == 'K' and s[0] == 'K':\n k += 1\n break\n if s[i] == 'K' and s[i- 1] == 'K' and s[i - 2] == 'K':\n k += 1\n break\nprint(k)", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "s=list(input())\nans=0\nn=len(s)\nfor i in range(n-1):\n if s[i]=='V' and s[i+1]=='K': ans+=1\nfor t in range(len(s)):\n anst=0\n ss=s[:]\n if ss[t]=='V': ss[t]='K'\n else: ss[t]='V'\n for i in range(n-1):\n if ss[i]=='V' and ss[i+1]=='K': anst+=1\n if anst>ans: ans=anst\nprint(ans)", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}, {"code": "import sys\nimport math\ns = input()\ncnt = s.count(\"VK\");\nif s[:2] == \"KK\":\n cnt += 1\nelif s[-2:] == 'VV':\n cnt += 1\nelif s.find(\"VVV\") >= 0:\n cnt += 1\nelif s.find(\"KKK\") >= 0:\n cnt += 1\nprint(cnt)", "passed": true, "time": 0.15, "memory": 14452.0, "status": "done"}, {"code": "#l=[int(i)for i in input().split()]\ns=input()\ni=0\na=s.find(\"VK\")\nans=0\nwhile a!=-1:\n\tans+=1\n\ts=s[:a]+\".\"+s[a+2:]\n\ta=s.find(\"VK\")\nif s.count(\"VV\")>0 or s.count(\"KK\")>0:ans+=1\nprint(ans) ", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "def f(S):\n ans = 0\n for i in range(1, len(S)):\n if S[i - 1] == \"V\" and S[i] == \"K\":\n ans += 1\n return ans\n\nS = list(input())\nans = f(S)\nD = {\"V\" : \"K\", \"K\" : \"V\"}\nfor i in range(len(S)):\n S[i] = D[S[i]]\n ans = max(ans, f(S))\n S[i] = D[S[i]]\nprint(ans)", "passed": true, "time": 0.16, "memory": 14400.0, "status": "done"}, {"code": "#!/usr/bin/env python3\nfrom sys import stdin,stdout\n\n\ndef ri():\n return list(map(int, input().split()))\n\n\ns = input()\nl = len(s)\nv = [0 for i in range(l)]\n\nif l == 1:\n print(0)\n return\n\n\ncount = 0\nfor i in range(l-1):\n if v[i]:\n continue\n if s[i:i+2] == \"VK\":\n v[i] = 1\n v[i+1] = 1\n count += 1\n\nfor i in range(l-1):\n if v[i] or v[i+1]:\n continue\n\n if s[i:i+2] == \"VV\" or s[i:i+2] == \"KK\":\n count += 1\n break\n\nprint(count)\n\n", "passed": true, "time": 0.22, "memory": 14404.0, "status": "done"}, {"code": "s=list(' '+input())\nm=0\nfor i in range(len(s)):\n ss=[]\n for i0 in range(len(s)):\n ss.append(s[i0])\n if ss[i]=='V':\n ss[i]='K'\n elif ss[i]=='K':\n ss[i]='V'\n mm=0\n for i0 in range(len(s)-1):\n if ss[i0]=='V'and ss[i0+1]=='K':\n mm=mm+1\n if mm>m:\n m=mm\nprint(m)\n", "passed": true, "time": 0.16, "memory": 14412.0, "status": "done"}]
[{"input": "VK\n", "output": "1\n"}, {"input": "VV\n", "output": "1\n"}, {"input": "V\n", "output": "0\n"}, {"input": "VKKKKKKKKKVVVVVVVVVK\n", "output": "3\n"}, {"input": "KVKV\n", "output": "1\n"}, {"input": "VKKVVVKVKVK\n", "output": "5\n"}, {"input": "VKVVKVKVVKVKKKKVVVVVVVVKVKVVVVVVKKVKKVKVVKVKKVVVVKV\n", "output": "14\n"}, {"input": "VVKKVKKVVKKVKKVKVVKKVKKVVKKVKVVKKVKKVKVVKKVVKKVKVVKKVKVVKKVVKVVKKVKKVKKVKKVKKVKVVKKVKKVKKVKKVKKVVKVK\n", "output": "32\n"}, {"input": "KVVKKVKVKVKVKVKKVKVKVVKVKVVKVVKVKKVKVKVKVKVKVKVKVKVKVKVKVKVKVKVVKVKVVKKVKVKK\n", "output": "32\n"}, {"input": "KVVVVVKKVKVVKVVVKVVVKKKVKKKVVKVKKKVKKKKVKVVVVVKKKVVVVKKVVVVKKKVKVVVVVVVKKVKVKKKVVKVVVKVVKK\n", "output": "21\n"}, {"input": "VVVVVKKVKVKVKVVKVVKKVVKVKKKKKKKVKKKVVVVVVKKVVVKVKVVKVKKVVKVVVKKKKKVVVVVKVVVVKVVVKKVKKVKKKVKKVKKVVKKV\n", "output": "25\n"}, {"input": "KKVVKVVKVVKKVVKKVKVVKKV\n", "output": "7\n"}, {"input": "KKVVKKVVVKKVKKVKKVVVKVVVKKVKKVVVKKVVVKVVVKVVVKKVVVKKVVVKVVVKKVVVKVVKKVVVKKVVVKKVVKVVVKKVVKKVKKVVVKKV\n", "output": "24\n"}, {"input": "KVKVKVKVKVKVKVKVKVKVVKVKVKVKVKVKVKVVKVKVKKVKVKVKVKVVKVKVKVKVKVKVKVKVKKVKVKVV\n", "output": "35\n"}, {"input": "VKVVVKKKVKVVKVKVKVKVKVV\n", "output": "9\n"}, {"input": "KKKKVKKVKVKVKKKVVVVKK\n", "output": "6\n"}, {"input": "KVKVKKVVVVVVKKKVKKKKVVVVKVKKVKVVK\n", "output": "9\n"}, {"input": "KKVKKVKKKVKKKVKKKVKVVVKKVVVVKKKVKKVVKVKKVKVKVKVVVKKKVKKKKKVVKVVKVVVKKVVKVVKKKKKVK\n", "output": "22\n"}, {"input": "VVVKVKVKVVVVVKVVVKKVVVKVVVVVKKVVKVVVKVVVKVKKKVVKVVVVVKVVVVKKVVKVKKVVKKKVKVVKVKKKKVVKVVVKKKVKVKKKKKK\n", "output": "25\n"}, {"input": "VKVVKVVKKKVVKVKKKVVKKKVVKVVKVVKKVKKKVKVKKKVVKVKKKVVKVVKKKVVKKKVKKKVVKKVVKKKVKVKKKVKKKVKKKVKVKKKVVKVK\n", "output": "29\n"}, {"input": "KKVKVVVKKVV\n", "output": "3\n"}, {"input": "VKVKVKVKVKVKVKVKVKVKVVKVKVKVKVKVK\n", "output": "16\n"}, {"input": "VVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVVKKKVV\n", "output": "13\n"}, {"input": "VVKKVKVKKKVVVKVVVKVKKVKKKVVVKVVKVKKVKKVKVKVVKKVVKKVKVVKKKVVKKVVVKVKVVVKVKVVKVKKVKKV\n", "output": "26\n"}, {"input": "VVKVKKVVKKVVKKVVKKVVKKVKKVVKVKKVVKKVVKKVVKKVVKKVVKVVKKVVKVVKKVVKVVKKVVKKVKKVVKVVKKVVKVVKKVV\n", "output": "26\n"}, {"input": "K\n", "output": "0\n"}, {"input": "VKVK\n", "output": "2\n"}, {"input": "VKVV\n", "output": "2\n"}, {"input": "KV\n", "output": "0\n"}, {"input": "KK\n", "output": "1\n"}, {"input": "KKVK\n", "output": "2\n"}, {"input": "KKKK\n", "output": "1\n"}, {"input": "KKV\n", "output": "1\n"}, {"input": "KKVKVK\n", "output": "3\n"}, {"input": "VKKVK\n", "output": "2\n"}, {"input": "VKKK\n", "output": "2\n"}, {"input": "KKK\n", "output": "1\n"}, {"input": "KVV\n", "output": "1\n"}, {"input": "KKVKV\n", "output": "2\n"}, {"input": "VVK\n", "output": "1\n"}, {"input": "VVVKVKVKVKVKVKVK\n", "output": "8\n"}, {"input": "KVVVK\n", "output": "2\n"}, {"input": "VVVKK\n", "output": "2\n"}, {"input": "KKVV\n", "output": "1\n"}, {"input": "KKKKKKK\n", "output": "1\n"}, {"input": "VKKKVK\n", "output": "3\n"}, {"input": "KKVVV\n", "output": "1\n"}, {"input": "VVVVVV\n", "output": "1\n"}, {"input": "KKKV\n", "output": "1\n"}, {"input": "VVKVV\n", "output": "2\n"}, {"input": "VKVKKK\n", "output": "3\n"}, {"input": "VKKV\n", "output": "1\n"}, {"input": "VKKVV\n", "output": "2\n"}, {"input": "VVKKVV\n", "output": "2\n"}, {"input": "KKVVKKV\n", "output": "2\n"}, {"input": "KKKKK\n", "output": "1\n"}, {"input": "VKVVKKVKKVVKVKKVKKKVKKVKVKK\n", "output": "10\n"}, {"input": "VKVKVV\n", "output": "3\n"}, {"input": "VKVVKVV\n", "output": "3\n"}, {"input": "VVV\n", "output": "1\n"}, {"input": "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n", "output": "1\n"}, {"input": "VVKKKKKKVKK\n", "output": "3\n"}, {"input": "KVKVKVV\n", "output": "3\n"}]
290
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw $n$ squares in the snow with a side length of $1$. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length $1$, parallel to the coordinate axes, with vertices at integer points. In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends $(x, y)$ and $(x, y+1)$. Then Sofia looks if there is already a drawn segment with the coordinates of the ends $(x', y)$ and $(x', y+1)$ for some $x'$. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates $x$, $x+1$ and the differing coordinate $y$. For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: [Image] After that, she can draw the remaining two segments, using the first two as a guide: [Image] If Sofia needs to draw two squares, she will have to draw three segments using a ruler: [Image] After that, she can draw the remaining four segments, using the first three as a guide: [Image] Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number. -----Input----- The only line of input contains a single integer $n$ ($1 \le n \le 10^{9}$), the number of squares that Sofia wants to draw. -----Output----- Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw $n$ squares in the manner described above. -----Examples----- Input 1 Output 2 Input 2 Output 3 Input 4 Output 4
interview
[{"code": "n = int(input())\n\na = b = 1\n\nwhile a * b < n:\n if a < b:\n a += 1\n else:\n b += 1\n\nprint(a+b)\n", "passed": true, "time": 0.21, "memory": 14332.0, "status": "done"}, {"code": "n = int(input())\nl = 0\nr = n\nwhile r - l > 1:\n m = (l + r) // 2\n if m * m >= n:\n r = m\n else:\n l = m\nif (r - 1) * r >= n:\n print(2 * r - 1)\nelse:\n print(2 * r)\n", "passed": true, "time": 0.78, "memory": 14304.0, "status": "done"}, {"code": "n = int(input())\nw, h = 0, 0\nwidth = True\nwhile w * h < n:\n if width:\n w += 1\n else:\n h += 1\n width = not width\nprint(w + h)\n", "passed": true, "time": 0.36, "memory": 14268.0, "status": "done"}, {"code": "n = int(input())\ni = 0\nwhile (i + 1) * (i + 1) <= n:\n\ti += 1\nprint(2 * i + (n - i * i + i - 1) // i)\n", "passed": true, "time": 0.2, "memory": 14264.0, "status": "done"}, {"code": "from math import ceil\nn = int(input())\nc = ceil(n ** 0.5)\nprint(c + (n + c - 1)//c)", "passed": true, "time": 0.14, "memory": 14512.0, "status": "done"}, {"code": "import math\nn = int(input())\nans = 10 ** 9 + 7\nfor i in range(1, int(math.sqrt(n)) + 1):\n if n % i == 0:\n ans = min(ans, i + n // i)\n else:\n ans = min(ans, i + n // i + 1)\nprint(ans)\n", "passed": true, "time": 0.33, "memory": 14368.0, "status": "done"}, {"code": "n = int(input())\nans = []\nfor i in range(1, 100000):\n ans.append(i + (n - 1) // i + 1)\nprint(min(ans))", "passed": true, "time": 1.03, "memory": 17372.0, "status": "done"}, {"code": "n = int( input() )\n\na = 0\nb = 0\n\nwhile a * b < n:\n if a == b:\n a += 1\n else:\n b += 1\n\nprint( a + b )\n", "passed": true, "time": 0.22, "memory": 14308.0, "status": "done"}, {"code": "from math import sqrt\nn = int(input())\nx = int(sqrt(n))\nx = max(0,x-5)\nans = n+1\nfor i in range(x,x+11):\n for j in range(x,x+11):\n if i*j >= n:\n ans = min(ans,i+j)\nprint(ans) \n", "passed": true, "time": 0.15, "memory": 14384.0, "status": "done"}, {"code": "def ii():\n return int(input())\ndef mi():\n return list(map(int, input().split()))\ndef li():\n return list(mi())\n\nn = ii()\nfor i in range(1, n + 1):\n if i * i > n:\n break\ni -= 1\nans = 2 * i\nif n - i * i == 0:\n pass\nelif n - i * i <= i:\n ans += 1\nelse:\n ans += 2\nprint(ans)\n", "passed": true, "time": 0.17, "memory": 14304.0, "status": "done"}, {"code": "from math import ceil\nn = int(input())\na = ceil(n**0.5)\nprint(a + ceil(n/a))", "passed": true, "time": 0.17, "memory": 14184.0, "status": "done"}, {"code": "from math import sqrt\n\nn = int(input())\nsq = int(sqrt(n))\ns = sq * sq\nif n == s:\n print(2 * sq)\nelif n <= s + sq:\n print(2 * sq + 1)\nelse:\n print(2 * sq + 2)", "passed": true, "time": 0.19, "memory": 14436.0, "status": "done"}, {"code": "n = int(input())\nt = 0\nwhile 1:\n t += 1\n if (t//2)*(t-t//2) >= n:\n print(t)\n break", "passed": true, "time": 0.25, "memory": 14240.0, "status": "done"}, {"code": "import math\n\nn = int(input())\nsq = int(math.sqrt(n))\ndif = n - sq * sq\nadd = 0\nif dif > sq:\n add = 2\nelif dif != 0:\n add = 1\nprint(2 * sq + add)\n", "passed": true, "time": 0.14, "memory": 14316.0, "status": "done"}, {"code": "n = int(input())\ns = 0\nwhile s*s <= n:\n s += 1\ns -= 1\nif n == s*s:\n print(2*s)\n return\n\nd = n-s*s\nfrom math import ceil\nprint(2*s + ceil(d*1./s))\n", "passed": true, "time": 0.27, "memory": 14440.0, "status": "done"}, {"code": "n = int(input())\n\na = b = 1\nwhile a * b < n:\n if a == b:\n a += 1\n else:\n b += 1\n\nprint(a+b)\n", "passed": true, "time": 0.21, "memory": 14516.0, "status": "done"}, {"code": "n = int(input())\nj = int(n ** 0.5)\n\nif n == j ** 2:\n print(2 * j)\nelif n <= j * (j + 1):\n print(2 * j + 1)\nelse:\n print(2 * j + 2)", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "def sq(x):\n s = int(x**0.5)\n for i in range(1, -2, -1):\n ts = s + i\n if ts**2 <= x:\n return ts\n\nn = int(input())\ns = sq(n)\n\nif s**2 == n:\n print(s * 2)\nelif (s + 1) * s >= n:\n print(s * 2 + 1)\nelse:\n print(s * 2 + 2)\n\n", "passed": true, "time": 0.15, "memory": 14284.0, "status": "done"}, {"code": "def getS(n):\n return int(n ** (1/2)) \n\nsquares = int(input())\n\n\nans = 0\n\n \nside = getS(squares)\nans += side * 2\n\nremains = squares - (side ** 2)\n\nif remains % side == 0:\n ans += remains // side\nelse:\n ans += remains // side + 1\n\nprint(ans)", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "n=int(input())\ni=1\nwhile i**2<n:\n i+=1\nif n%i==0:\n print(i+n//i)\nelse:\n print(i+n//i+1)\n", "passed": true, "time": 0.28, "memory": 14408.0, "status": "done"}, {"code": "n = int(input())\ni = 1\nj = 1\nk = 0\nwhile (i * j < n):\n if k % 2 == 0:\n i += 1\n else:\n j += 1\n k = 1 - k\nprint(i+j)", "passed": true, "time": 0.24, "memory": 14468.0, "status": "done"}, {"code": "while True:\n n = int(input())\n\n sqrt_n = int(n**0.5)\n\n minn = 100000000\n\n if(sqrt_n*sqrt_n >= n):\n\n minn = min(minn, sqrt_n + sqrt_n)\n\n if(sqrt_n*(sqrt_n+1) >= n):\n\n minn = min(minn, sqrt_n + (sqrt_n+1))\n\n if((1+sqrt_n)*(1+sqrt_n) >= n):\n\n minn = min(minn, (1+sqrt_n) + (1+sqrt_n))\n\n print(minn)\n\n break\n", "passed": true, "time": 0.14, "memory": 14376.0, "status": "done"}, {"code": "import math\nn=int(input())\na=int(math.sqrt(n))\nif a*a<n:\n a+=1\nb=math.ceil(n/a)\nprint(a+b)\n \n", "passed": true, "time": 0.15, "memory": 14292.0, "status": "done"}]
[{"input": "1\n", "output": "2\n"}, {"input": "2\n", "output": "3\n"}, {"input": "4\n", "output": "4\n"}, {"input": "14\n", "output": "8\n"}, {"input": "41\n", "output": "13\n"}, {"input": "51\n", "output": "15\n"}, {"input": "776\n", "output": "56\n"}, {"input": "116\n", "output": "22\n"}, {"input": "972\n", "output": "63\n"}, {"input": "3517\n", "output": "119\n"}, {"input": "3776\n", "output": "123\n"}, {"input": "4035\n", "output": "128\n"}, {"input": "35997\n", "output": "380\n"}, {"input": "61669\n", "output": "497\n"}, {"input": "87341\n", "output": "592\n"}, {"input": "398223\n", "output": "1263\n"}, {"input": "772168\n", "output": "1758\n"}, {"input": "423353776\n", "output": "41152\n"}, {"input": "999950884\n", "output": "63244\n"}, {"input": "1000000000\n", "output": "63246\n"}, {"input": "408636\n", "output": "1279\n"}, {"input": "4205340\n", "output": "4102\n"}, {"input": "5517158\n", "output": "4698\n"}, {"input": "8795795\n", "output": "5932\n"}, {"input": "54155304\n", "output": "14719\n"}, {"input": "48091000\n", "output": "13870\n"}, {"input": "16993944\n", "output": "8245\n"}, {"input": "605551861\n", "output": "49216\n"}, {"input": "377684528\n", "output": "38869\n"}, {"input": "3\n", "output": "4\n"}, {"input": "5\n", "output": "5\n"}, {"input": "6\n", "output": "5\n"}, {"input": "7\n", "output": "6\n"}, {"input": "8\n", "output": "6\n"}, {"input": "9\n", "output": "6\n"}, {"input": "10\n", "output": "7\n"}, {"input": "11\n", "output": "7\n"}, {"input": "12\n", "output": "7\n"}, {"input": "13\n", "output": "8\n"}, {"input": "14\n", "output": "8\n"}, {"input": "15\n", "output": "8\n"}, {"input": "16\n", "output": "8\n"}, {"input": "17\n", "output": "9\n"}, {"input": "18\n", "output": "9\n"}, {"input": "999950885\n", "output": "63245\n"}, {"input": "49\n", "output": "14\n"}, {"input": "898081025\n", "output": "59937\n"}, {"input": "157502501\n", "output": "25101\n"}, {"input": "100320256\n", "output": "20032\n"}, {"input": "401641681\n", "output": "40082\n"}, {"input": "306495050\n", "output": "35015\n"}, {"input": "403608101\n", "output": "40181\n"}, {"input": "308213136\n", "output": "35112\n"}, {"input": "225660486\n", "output": "30045\n"}, {"input": "627352211\n", "output": "50095\n"}, {"input": "204575811\n", "output": "28607\n"}, {"input": "420\n", "output": "41\n"}, {"input": "141\n", "output": "24\n"}, {"input": "21\n", "output": "10\n"}, {"input": "32\n", "output": "12\n"}, {"input": "999919262\n", "output": "63243\n"}, {"input": "864918\n", "output": "1861\n"}, {"input": "100000001\n", "output": "20001\n"}]
291
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob? -----Input----- The only line of the input contains two integers a and b (1 ≀ a ≀ b ≀ 10)Β β€” the weight of Limak and the weight of Bob respectively. -----Output----- Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. -----Examples----- Input 4 7 Output 2 Input 4 9 Output 3 Input 1 1 Output 1 -----Note----- In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4Β·3 = 12 and 7Β·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2. In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights. In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
interview
[{"code": "def l2i(s):\n\treturn [int(i) for i in s.split()]\na, b=l2i(input())\nt=0\nwhile (a<=b):\n\ta*=3\n\tb*=2\n\tt+=1\nprint(t)", "passed": true, "time": 0.25, "memory": 14320.0, "status": "done"}, {"code": "a,b = list(map(int,input().split()))\nans = 0\nwhile a <= b:\n a *= 3\n b *= 2\n ans += 1\nprint(ans) \n", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\ny = 0\nwhile a <= b:\n y += 1\n a *= 3\n b *= 2\nprint(y)\n", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "a, b = [int(i) for i in input().split()]\niters = 0\nwhile a <= b:\n\ta *= 3\n\tb *= 2\n\titers += 1\nprint(iters)", "passed": true, "time": 0.16, "memory": 14284.0, "status": "done"}, {"code": "def inl():\n l = list(map(int , input().split()))\n return l\n\nx , y = map(int , input().split())\nl = 0\nwhile 1:\n x *= 3\n y *= 2\n l += 1\n if(x > y):\n print(l)\n break", "passed": true, "time": 0.15, "memory": 14452.0, "status": "done"}, {"code": "a,b=[int(x)for x in input().split()]\ni=0\nwhile a<=b:\n a*=3\n b*=2\n i+=1\nprint(i)\n", "passed": true, "time": 0.14, "memory": 14316.0, "status": "done"}, {"code": "n,m = input().split()\nn,m = int(n) , int(m)\ni=0\nwhile True:\n if n>m:\n break\n n=n*3\n m=m*2\n i+=1\nprint(i)\n", "passed": true, "time": 1.49, "memory": 14488.0, "status": "done"}, {"code": "s = input().split()\na = int(s[0])\nb = int(s[1])\np = 0\nwhile True:\n p += 1\n a*=3\n b*=2\n if a>b:\n break\nprint(p)\n", "passed": true, "time": 0.14, "memory": 14272.0, "status": "done"}, {"code": "a,b=map(int,input().split())\nans = 0\nwhile a<=b:\n ans = ans + 1\n a = 3*a\n b = 2*b\n\nprint(ans)", "passed": true, "time": 0.25, "memory": 14356.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\n\nyears = 0\n\nwhile a<=b:\n a*=3\n b*=2\n years+=1\n\nprint(years)\n", "passed": true, "time": 0.15, "memory": 14448.0, "status": "done"}, {"code": "'''input\n1 1\n'''\na, b = map(int, input().split())\nk = 0\nwhile a <= b:\n\ta *= 3\n\tb *= 2\n\tk += 1\nprint(k)", "passed": true, "time": 0.47, "memory": 14448.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\n\ny = 0\nwhile(a <= b):\n y += 1\n a *= 3\n b *= 2\n\nprint(y)\n", "passed": true, "time": 0.14, "memory": 14476.0, "status": "done"}, {"code": "n = [int(s) for s in input().split()]\na = n[0]\nb = n[1]\nt = 0\nwhile a <= b:\n a = a*3\n b = b*2\n t += 1\nprint(t)\n", "passed": true, "time": 0.24, "memory": 14232.0, "status": "done"}, {"code": "a,b=list(map(int,input().split()))\ni=0\nwhile a<=b:\n a*=3\n b*=2\n i+=1\nprint(i)\n", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}, {"code": "a,b = map(int, input().split())\nans = 0\nwhile True:\n a *= 3\n b *= 2\n ans += 1\n if a > b:\n break;\nprint(ans)", "passed": true, "time": 0.15, "memory": 14424.0, "status": "done"}, {"code": "from sys import stdin, stdout\n\na,b = list(map(int, stdin.readline().rstrip().split()))\n\nyears=0\nwhile a<=b:\n a*=3\n b*=2\n years+=1\n\nprint(years)\n", "passed": true, "time": 0.15, "memory": 14468.0, "status": "done"}, {"code": "a,b=map(int,input().split())\nyear=0\nwhile a<=b:\n a*=3\n b*=2\n year+=1\nprint(year)", "passed": true, "time": 0.15, "memory": 14312.0, "status": "done"}, {"code": "a, b = map(int, input().split())\ni = 0\nwhile True:\n i += 1\n a *= 3\n b *= 2\n if a>b:\n break\nprint(i)", "passed": true, "time": 0.17, "memory": 14244.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\nn = 0\nwhile a <= b:\n a *= 3\n b *= 2\n n += 1\nprint(n)\n", "passed": true, "time": 0.16, "memory": 14420.0, "status": "done"}, {"code": "a,b = list(map(int,input().split()))\ncnt=0\nwhile (a<=b):\n\ta *= 3\n\tb *= 2\n\tcnt += 1\nprint(cnt)\n", "passed": true, "time": 0.25, "memory": 14412.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\nfor i in range(10):\n if 3**i * a > 2**i * b:\n print(i)\n break\n\n", "passed": true, "time": 0.14, "memory": 14412.0, "status": "done"}, {"code": "a,b = list(map(int,input().split()))\ntimes = 0\nwhile (a <= b) : \n\ta = a * 3\n\tb = b * 2\n\ttimes += 1\nprint(times)\n", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "a,b = [int(x) for x in input().split(' ')]\nc = 0\nwhile b >= a:\n c += 1\n a *= 3\n b *= 2\n\nprint(c)\n", "passed": true, "time": 0.23, "memory": 14256.0, "status": "done"}, {"code": "import sys\nread=lambda:sys.stdin.readline().rstrip()\nreadi=lambda:int(sys.stdin.readline())\nwriteln=lambda x:sys.stdout.write(str(x)+\"\\n\")\nwrite=lambda x:sys.stdout.write(x)\na,b=map(int, read().split())\nyear = 0\nwhile a <= b:\n a*=3;b*=2\n year += 1\nwriteln(year)", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}]
[{"input": "4 7\n", "output": "2\n"}, {"input": "4 9\n", "output": "3\n"}, {"input": "1 1\n", "output": "1\n"}, {"input": "4 6\n", "output": "2\n"}, {"input": "1 10\n", "output": "6\n"}, {"input": "1 1\n", "output": "1\n"}, {"input": "1 2\n", "output": "2\n"}, {"input": "1 3\n", "output": "3\n"}, {"input": "1 4\n", "output": "4\n"}, {"input": "1 5\n", "output": "4\n"}, {"input": "1 6\n", "output": "5\n"}, {"input": "1 7\n", "output": "5\n"}, {"input": "1 8\n", "output": "6\n"}, {"input": "1 9\n", "output": "6\n"}, {"input": "1 10\n", "output": "6\n"}, {"input": "2 2\n", "output": "1\n"}, {"input": "2 3\n", "output": "2\n"}, {"input": "2 4\n", "output": "2\n"}, {"input": "2 5\n", "output": "3\n"}, {"input": "2 6\n", "output": "3\n"}, {"input": "2 7\n", "output": "4\n"}, {"input": "2 8\n", "output": "4\n"}, {"input": "2 9\n", "output": "4\n"}, {"input": "2 10\n", "output": "4\n"}, {"input": "3 3\n", "output": "1\n"}, {"input": "3 4\n", "output": "1\n"}, {"input": "3 5\n", "output": "2\n"}, {"input": "3 6\n", "output": "2\n"}, {"input": "3 7\n", "output": "3\n"}, {"input": "3 8\n", "output": "3\n"}, {"input": "3 9\n", "output": "3\n"}, {"input": "3 10\n", "output": "3\n"}, {"input": "4 4\n", "output": "1\n"}, {"input": "4 5\n", "output": "1\n"}, {"input": "4 6\n", "output": "2\n"}, {"input": "4 7\n", "output": "2\n"}, {"input": "4 8\n", "output": "2\n"}, {"input": "4 9\n", "output": "3\n"}, {"input": "4 10\n", "output": "3\n"}, {"input": "5 5\n", "output": "1\n"}, {"input": "5 6\n", "output": "1\n"}, {"input": "5 7\n", "output": "1\n"}, {"input": "5 8\n", "output": "2\n"}, {"input": "5 9\n", "output": "2\n"}, {"input": "5 10\n", "output": "2\n"}, {"input": "6 6\n", "output": "1\n"}, {"input": "6 7\n", "output": "1\n"}, {"input": "6 8\n", "output": "1\n"}, {"input": "6 9\n", "output": "2\n"}, {"input": "6 10\n", "output": "2\n"}, {"input": "7 7\n", "output": "1\n"}, {"input": "7 8\n", "output": "1\n"}, {"input": "7 9\n", "output": "1\n"}, {"input": "7 10\n", "output": "1\n"}, {"input": "8 8\n", "output": "1\n"}, {"input": "8 9\n", "output": "1\n"}, {"input": "8 10\n", "output": "1\n"}, {"input": "9 9\n", "output": "1\n"}, {"input": "9 10\n", "output": "1\n"}, {"input": "10 10\n", "output": "1\n"}, {"input": "10 10\n", "output": "1\n"}, {"input": "1 2\n", "output": "2\n"}]
293
Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m columns. For example, in a 3 Γ— 5 table there are 15 squares with side one, 8 squares with side two and 3 squares with side three. The total number of distinct squares in a 3 Γ— 5 table is 15 + 8 + 3 = 26. -----Input----- The first line of the input contains a single integer x (1 ≀ x ≀ 10^18)Β β€” the number of squares inside the tables Spongebob is interested in. -----Output----- First print a single integer kΒ β€” the number of tables with exactly x distinct squares inside. Then print k pairs of integers describing the tables. Print the pairs in the order of increasing n, and in case of equalityΒ β€” in the order of increasing m. -----Examples----- Input 26 Output 6 1 26 2 9 3 5 5 3 9 2 26 1 Input 2 Output 2 1 2 2 1 Input 8 Output 4 1 8 2 3 3 2 8 1 -----Note----- In a 1 Γ— 2 table there are 2 1 Γ— 1 squares. So, 2 distinct squares in total. [Image] In a 2 Γ— 3 table there are 6 1 Γ— 1 squares and 2 2 Γ— 2 squares. That is equal to 8 squares in total. [Image]
interview
[{"code": "x = int(input())\n\ndef solve(x):\n count = 0\n lst = []\n x6 = x * 6\n for n in range(1, x + 1):\n t, r = divmod(x6, n*(n+1))\n if t < 2*n + 1:\n break\n if r:\n continue\n m, r = divmod(t + n - 1, 3)\n if r:\n continue\n count += 2\n lst.append((n, m))\n nn, mm = lst[-1]\n if nn == mm:\n count -= 1\n print(count)\n for n, m in lst:\n print(n, m)\n if nn != mm:\n print(mm, nn)\n lst.reverse()\n for n, m in lst[1:]:\n print(m, n)\n\nsolve(x)\n", "passed": true, "time": 5.58, "memory": 14552.0, "status": "done"}, {"code": "n = int(input())\ni = 0\ns = 0\nt = 0\nx = 0\nf = 0\nres1 = []\nres2 = []\nwhile n >= 0:\n\ti = i + 1\n\tn = n - i * i\n\tif ( n < 0 ):\n\t\tbreak\t\n\tt = t + i\n\tm = n // t \n\tif ( m * t != n ):\n\t\tcontinue\n\telse: \t\t\n\t\tres1.append( i )\t\n\t\tres2.append( m + i )\t\n\t\tx = x + 1\n\t\tif m == 0:\n\t\t\tf = 1\n\nprint( str(int(2 * x - f)) )\nfor i in range(x):\n\tprint( str(int(res1[i])) + \" \" + str(int(res2[i])))\nres1.reverse()\nres2.reverse()\nfor i in range(x):\n\tif ( res1[i] != res2[i] ):\n\t\tprint( str(int(res2[i])) + \" \" + str(int(res1[i])))\n", "passed": true, "time": 5.81, "memory": 14588.0, "status": "done"}, {"code": "#from time import time\n\ndef solve( x ):\n\n res = [(1,x)]\n if x != 1:\n res.append( (x,1) )\n\n index , a , b = 1 , 1 , 0\n while True:\n b += a\n index += 1\n a += index\n\n if a*index-b > x:\n break\n\n if ( x + b ) % a == 0:\n m = ( x + b )// a\n res.append( ( index , m ) )\n if index != m:\n res.append( ( m , index ) )\n\n res.sort()\n print( len(res) )\n for ares in res:\n print( ares[0] , ares[1] )\n\ndef __starting_point():\n\n #t1 = time()\n x = int( input() )\n solve( x )\n #t2 = time()\n #print( \"time :\" , t2-t1 , \"s\" )\n\n__starting_point()", "passed": true, "time": 5.86, "memory": 14576.0, "status": "done"}, {"code": "n = int(input())\nans = []\nfor i in range(1, 1442250 + 10):\n t = i * (i + 1) // 2\n j, mod = divmod(n + (i - 1) * t // 3, t)\n if i > j:\n break\n if mod == 0:\n ans.append((i, j))\n if i != j: ans.append((j, i))\nans.sort()\nprint(len(ans))\nfor x, y in ans:\n print(x, y)\n", "passed": true, "time": 19.26, "memory": 14492.0, "status": "done"}, {"code": "n = int(input())\nans = []\nfor i in range(1, 1442250 + 10):\n t = i * (i + 1) // 2\n j, mod = divmod(n + (i - 1) * t // 3, t)\n if i > j:\n break\n if mod == 0:\n ans.append((i, j))\n if i != j: ans.append((j, i))\nans.sort()\nprint(len(ans))\nfor x, y in ans:\n print(x, y)\n", "passed": true, "time": 16.99, "memory": 14520.0, "status": "done"}, {"code": "n = int(input())\ni,t,s = [0] * 3\nr = []\nwhile 1 > 0:\n\ti += 1\n\tn -= i * i\n\tif n < 0 : break\n\tt += i\n\tm = n // t \n\tif m * t != n : continue\n\tr.append((i, m + i))\n\tif m > 0:\n\t\tr.append((m+i, i))\t\n\nprint(len(r))\nr.sort()\nfor m, n in r:\n\tprint(\"%d %d\" % (m , n))\n", "passed": true, "time": 5.98, "memory": 14296.0, "status": "done"}, {"code": "n = int(input())\ni,t,s = [0] * 3\nr = []\nwhile 1 > 0:\n\ti += 1\n\tn -= i * i\n\tif n < 0 : break\n\tt += i\n\tm = n // t \n\tif m * t != n : continue\n\tr.append((i, m + i))\n\tif m > 0:\n\t\tr.append((m+i, i))\t\n\nprint(len(r))\nr.sort()\nfor m, n in r:\n\tprint(\"%d %d\" % (m , n))\n", "passed": true, "time": 14.2, "memory": 14456.0, "status": "done"}, {"code": "x = int(input()) * 6\nn, equ, ans = 0, False, []\nwhile True:\n\tn += 1\n\tif n * (n + 1) * (2 * n - 1) > x:\n\t\tbreak\n\tif x % n != 0:\n\t\tcontinue\n\tif x % (n + 1) != 0:\n\t\tcontinue\n\tm = x // n // (n + 1) + n - 1\n\tif m % 3 != 0:\n\t\tcontinue\n\tm = m // 3\n\tif n <= m:\n\t\tans.append([n, m])\n\t\tif n == m:\n\t\t\tequ = True\n\nprint(len(ans) * 2 - equ)\nfor p in ans:\n\tprint(\"%d %d\" % (p[0], p[1]))\nif equ:\n\tans.pop()\nans.reverse()\nfor p in ans:\n\tp.reverse();\n\tprint(\"%d %d\" % (p[0], p[1]))\n", "passed": true, "time": 4.98, "memory": 14356.0, "status": "done"}, {"code": "x = int(input()) * 6\nn, equ, ans = 0, False, []\nwhile True:\n\tn += 1\n\tif n * (n + 1) * (2 * n - 1) > x:\n\t\tbreak\n\tif x % n != 0:\n\t\tcontinue\n\tif x % (n + 1) != 0:\n\t\tcontinue\n\tm = x // n // (n + 1) + n - 1\n\tif m % 3 != 0:\n\t\tcontinue\n\tm = m // 3\n\tif n <= m:\n\t\tans.append((n, m))\n\t\tif n == m:\n\t\t\tequ = True\n\nprint(len(ans) * 2 - equ)\nfor p in ans:\n\tprint(\"%d %d\" % (p[0], p[1]))\nif equ:\n\tans.pop()\nans.reverse()\nfor p in ans:\n\tprint(\"%d %d\" % (p[1], p[0]))\n", "passed": true, "time": 4.91, "memory": 14384.0, "status": "done"}, {"code": "x = int(input()) * 6\nn, equ, ans = 0, False, []\nwhile True:\n\tn += 1\n\tif n * (n + 1) * (2 * n - 1) > x:\n\t\tbreak\n\tif x % n != 0:\n\t\tcontinue\n\tif x % (n + 1) != 0:\n\t\tcontinue\n\tm = x // n // (n + 1) + n - 1\n\tif m % 3 != 0:\n\t\tcontinue\n\tm = m // 3\n\tif n <= m:\n\t\tans.append((n, m))\n\t\tif n == m:\n\t\t\tequ = True\n\telse:\n\t\tbreak\n\nprint(len(ans) * 2 - equ)\nfor p in ans:\n\tprint(\"%d %d\" % (p[0], p[1]))\nif equ:\n\tans.pop()\nans.reverse()\nfor p in ans:\n\tprint(\"%d %d\" % (p[1], p[0]))\n", "passed": true, "time": 11.22, "memory": 14504.0, "status": "done"}, {"code": "n=int(input())\ni,t = 0,0\nr=[]\nwhile 1:\n i+=1\n n-=i*i\n if n<0:break\n t+=i\n m=n//t \n r+=[(m+i,i),(i, m + i)][m==0:]*(m*t ==n) \nprint(len(r))\nfor p in sorted(r): print(\"%d %d\"%p)\n", "passed": true, "time": 11.87, "memory": 14332.0, "status": "done"}, {"code": "n=int(input())\ni,t = 0,0\nr=[]\nwhile 1:\n i+=1\n n-=i*i\n if n<0:break\n t+=i\n m=n//t \n r+=[(m+i,i),(i, m + i)][m==0:]*(m*t ==n) \nprint(len(r))\nfor p in sorted(r): print(\"%d %d\"%p)", "passed": true, "time": 11.85, "memory": 14488.0, "status": "done"}, {"code": "\"\"\"\nCodeforces Round #332 (Div. 2)\n\nProblem 599 D. Spongebob and Squares\n\n@author yamaton\n@date 2015-11-20\n\"\"\"\n\nimport itertools as it\nimport functools\nimport operator\nimport collections\nimport math\nimport sys\n\n\ndef solve(x):\n def find_p(n):\n return (6 * x // (n * (n + 1)) - 2 * n - 1) // 3\n def f(n, p):\n return n * (n + 1) * (2 * n + 3 * p + 1) - 6 * x\n\n result = []\n for n in it.count(1):\n p = find_p(n)\n if p < 0:\n break\n if f(n, p) == 0:\n result.append((n, n + p))\n if p > 0:\n result.append((n + p, n))\n result.sort()\n return result\n\n\n# def p(*args, **kwargs):\n# return print(*args, file=sys.stderr, **kwargs)\n\n\ndef main():\n x = int(input())\n results = solve(x)\n print(len(results))\n for res in results:\n print(*res)\n\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 14.19, "memory": 14336.0, "status": "done"}, {"code": "n,i,t,r=int(input()),0,0,[]\nwhile 1:\n\ti+=1\n\tn-=i*i\n\tif n<0:break\n\tt+=i\n\tm=n//t \n\tr+=[(m+i,i),(i,m+i)][m==0:]*(m*t==n)\nprint(len(r))\nfor p in sorted(r):print(\"%d %d\"%p)", "passed": true, "time": 21.78, "memory": 14504.0, "status": "done"}, {"code": "n,i,t,r=int(input()),0,0,[]\nwhile 1:\n\ti+=1\n\tn-=i*i\n\tif n<0:break\n\tt+=i\n\tm=n//t\n\tr+=[(m+i,i),(i,m+i)][m==0:]*(m*t==n)\nprint(len(r))\nfor p in sorted(r):print(\"%d %d\"%p)", "passed": true, "time": 11.95, "memory": 14320.0, "status": "done"}, {"code": "__author__ = 'MoonBall'\n\nimport sys\n# sys.stdin = open('data/D.in', 'r')\nT = 1\n\ndef process():\n ans = []\n N = int(input())\n for i in range(1, 3000000):\n a = N + i * (i - 1) * (i + 1) // 6\n j, mod = divmod(a, i * (i + 1) // 2)\n if i > j: break\n if mod: continue\n ans.append((i, j))\n if i != j: ans.append((j, i))\n\n ans.sort()\n print(len(ans))\n for i, j in ans: print(i, j)\n\n\n\n\n\nfor _ in range(T):\n process()\n", "passed": true, "time": 20.36, "memory": 14344.0, "status": "done"}, {"code": "__author__ = 'MoonBall'\n\nimport sys\n# sys.stdin = open('data/D.in', 'r')\nT = 1\n\ndef process():\n ans = []\n N = int(input())\n for i in range(1, N + 1):\n a = N + i * (i - 1) * (i + 1) // 6\n j, mod = divmod(a, i * (i + 1) // 2)\n if i > j: break\n if mod: continue\n ans.append((i, j))\n if i != j: ans.append((j, i))\n\n ans.sort()\n print(len(ans))\n for i, j in ans: print(i, j)\n\n\n\n\n\nfor _ in range(T):\n process()\n", "passed": true, "time": 20.22, "memory": 14448.0, "status": "done"}, {"code": "from itertools import chain, combinations\nfrom functools import reduce\nfrom collections import defaultdict\n\ndef res(m,n):\n k = min(m,n)\n return (1+k)*(k+2*k**2-3*k*(m+n)+6*m*n) // 6\n\ndef powerset(iterable):\n s = list(iterable)\n return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))\n\ndef prod(it):\n r = 1\n for elem in it:\n r *= elem\n return r\n\ndef factorGenerator(n):\n res = defaultdict(lambda: 0)\n for p in range(2,10**6+1):\n while n % p == 0:\n res[p] += 1\n n = n // p\n return res\n\ndef divisorGen(n):\n factors = list(factorGenerator(n).items())\n nfactors = len(factors)\n f = [0] * nfactors\n while True:\n yield reduce(lambda x, y: x*y, [factors[x][0]**f[x] for x in range(nfactors)], 1)\n i = 0\n while True:\n f[i] += 1\n if f[i] <= factors[i][1]:\n break\n f[i] = 0\n i += 1\n if i >= nfactors:\n return\ndef res2(x):\n r = []\n x6 = 6 * x\n divisors = set(divisorGen(x6))\n for m in divisors:\n a = x6 // m\n if a % (m+1) != 0:\n continue\n b = a // (m+1)\n c = b + m - 1\n if c % 3 != 0:\n continue\n n = c // 3\n if n < m:\n continue\n if res(m,n) != x:\n continue\n r.append((m,n))\n return r\n\nx = int(input())\nr = res2(x)\nr = r + [(n,m) for m,n in r]\nr = sorted(set(r))\nprint(len(r))\nfor (m,n) in r:\n print(\"%d %d\"%(m, n))\n", "passed": true, "time": 2.79, "memory": 14588.0, "status": "done"}, {"code": "import itertools\nimport math\n\nx = int(input())\nkmax = math.floor((3*x) ** (1/3))\nans = []\nfor i in range(1, kmax+1):\n if 6*x % (i*(i+1)) == 0:\n s = 6*x // (i*(i+1)) + i - 1\n if s % 3 == 0:\n ans.append((i,s//3))\n\n\nres = 2*len(ans) - 1 if ans[-1][0] == ans[-1][1] else 2*len(ans)\nprint(res)\nfor pair in ans[:-1]:\n print(pair[0], pair[1])\n\nif res%2 == 0: print(ans[-1][0], ans[-1][1])\n\nfor pair in reversed(ans):\n print(pair[1], pair[0])\n", "passed": true, "time": 4.43, "memory": 14484.0, "status": "done"}]
[{"input": "26\n", "output": "6\n1 26\n2 9\n3 5\n5 3\n9 2\n26 1\n"}, {"input": "2\n", "output": "2\n1 2\n2 1\n"}, {"input": "8\n", "output": "4\n1 8\n2 3\n3 2\n8 1\n"}, {"input": "1\n", "output": "1\n1 1\n"}, {"input": "5005\n", "output": "12\n1 5005\n5 335\n6 240\n10 94\n13 59\n14 52\n52 14\n59 13\n94 10\n240 6\n335 5\n5005 1\n"}, {"input": "17284\n", "output": "2\n1 17284\n17284 1\n"}, {"input": "151618\n", "output": "2\n1 151618\n151618 1\n"}, {"input": "360700\n", "output": "8\n1 360700\n4 36071\n5 24048\n24 1210\n1210 24\n24048 5\n36071 4\n360700 1\n"}, {"input": "500500500\n", "output": "8\n1 500500500\n4 50050051\n8 13902794\n9 11122236\n11122236 9\n13902794 8\n50050051 4\n500500500 1\n"}, {"input": "200200\n", "output": "26\n1 200200\n4 20021\n5 13348\n6 9535\n7 7152\n10 3643\n13 2204\n14 1911\n15 1673\n24 675\n25 624\n55 148\n77 92\n92 77\n148 55\n624 25\n675 24\n1673 15\n1911 14\n2204 13\n3643 10\n7152 7\n9535 6\n13348 5\n20021 4\n200200 1\n"}, {"input": "800800\n", "output": "32\n1 800800\n4 80081\n5 53388\n6 38135\n7 28602\n10 14563\n13 8804\n14 7631\n15 6678\n24 2677\n25 2472\n32 1527\n55 538\n64 406\n77 292\n104 181\n181 104\n292 77\n406 64\n538 55\n1527 32\n2472 25\n2677 24\n6678 15\n7631 14\n8804 13\n14563 10\n28602 7\n38135 6\n53388 5\n80081 4\n800800 1\n"}, {"input": "200000800200\n", "output": "4\n1 200000800200\n4 20000080021\n20000080021 4\n200000800200 1\n"}, {"input": "999999999999999999\n", "output": "6\n1 999999999999999999\n13 10989010989010993\n37 1422475106685645\n1422475106685645 37\n10989010989010993 13\n999999999999999999 1\n"}, {"input": "128593726482159\n", "output": "2\n1 128593726482159\n128593726482159 1\n"}, {"input": "50044422\n", "output": "2\n1 50044422\n50044422 1\n"}, {"input": "18\n", "output": "2\n1 18\n18 1\n"}, {"input": "30\n", "output": "3\n1 30\n4 4\n30 1\n"}, {"input": "20\n", "output": "6\n1 20\n2 7\n3 4\n4 3\n7 2\n20 1\n"}, {"input": "649708734844\n", "output": "2\n1 649708734844\n649708734844 1\n"}, {"input": "649030984\n", "output": "8\n1 649030984\n6 30906239\n7 23179680\n41 753824\n753824 41\n23179680 7\n30906239 6\n649030984 1\n"}, {"input": "333333333\n", "output": "2\n1 333333333\n333333333 1\n"}, {"input": "5050505060\n", "output": "8\n1 5050505060\n2 1683501687\n3 841750844\n4 505050507\n505050507 4\n841750844 3\n1683501687 2\n5050505060 1\n"}, {"input": "1000000000000000000\n", "output": "10\n1 1000000000000000000\n4 100000000000000001\n5 66666666666666668\n15 8333333333333338\n24 3333333333333341\n3333333333333341 24\n8333333333333338 15\n66666666666666668 5\n100000000000000001 4\n1000000000000000000 1\n"}, {"input": "18270000000000\n", "output": "10\n1 18270000000000\n4 1827000000001\n7 652500000002\n27 48333333342\n28 45000000009\n45000000009 28\n48333333342 27\n652500000002 7\n1827000000001 4\n18270000000000 1\n"}, {"input": "10102030405090000\n", "output": "16\n1 10102030405090000\n4 1010203040509001\n5 673468693672668\n15 84183586709088\n24 33673434683641\n25 31083170477208\n40 12319549274513\n499 80978199806\n80978199806 499\n12319549274513 40\n31083170477208 25\n33673434683641 24\n84183586709088 15\n673468693672668 5\n1010203040509001 4\n10102030405090000 1\n"}, {"input": "50004000222222228\n", "output": "10\n1 50004000222222228\n7 1785857150793653\n8 1389000006172842\n13 549494507936512\n117 7243807072648\n7243807072648 117\n549494507936512 13\n1389000006172842 8\n1785857150793653 7\n50004000222222228 1\n"}, {"input": "9000004000200000\n", "output": "8\n1 9000004000200000\n4 900000400020001\n8 250000111116669\n9 200000088893336\n200000088893336 9\n250000111116669 8\n900000400020001 4\n9000004000200000 1\n"}, {"input": "147456000000000\n", "output": "4\n1 147456000000000\n4 14745600000001\n14745600000001 4\n147456000000000 1\n"}, {"input": "80000010000020000\n", "output": "12\n1 80000010000020000\n2 26666670000006667\n3 13333335000003334\n4 8000001000002001\n10 1454545636364003\n11 1212121363636670\n1212121363636670 11\n1454545636364003 10\n8000001000002001 4\n13333335000003334 3\n26666670000006667 2\n80000010000020000 1\n"}, {"input": "8888\n", "output": "8\n1 8888\n2 2963\n3 1482\n11 138\n138 11\n1482 3\n2963 2\n8888 1\n"}, {"input": "22003000000000000\n", "output": "10\n1 22003000000000000\n4 2200300000000001\n5 1466866666666668\n15 183358333333338\n24 73343333333341\n73343333333341 24\n183358333333338 15\n1466866666666668 5\n2200300000000001 4\n22003000000000000 1\n"}, {"input": "40040\n", "output": "24\n1 40040\n2 13347\n3 6674\n4 4005\n7 1432\n10 731\n11 610\n12 517\n13 444\n20 197\n21 180\n39 64\n64 39\n180 21\n197 20\n444 13\n517 12\n610 11\n731 10\n1432 7\n4005 4\n6674 3\n13347 2\n40040 1\n"}, {"input": "1000000400\n", "output": "20\n1 1000000400\n2 333333467\n3 166666734\n4 100000041\n7 35714302\n19 5263166\n20 4761913\n56 626585\n75 350902\n399 12664\n12664 399\n350902 75\n626585 56\n4761913 20\n5263166 19\n35714302 7\n100000041 4\n166666734 3\n333333467 2\n1000000400 1\n"}, {"input": "5000004100\n", "output": "30\n1 5000004100\n4 500000411\n5 333333608\n6 238095435\n7 178571577\n13 54945104\n14 47619091\n24 16666688\n25 15384636\n49 4081652\n52 3628467\n104 915786\n105 898508\n195 261708\n636 24895\n24895 636\n261708 195\n898508 105\n915786 104\n3628467 52\n4081652 49\n15384636 25\n16666688 24\n47619091 14\n54945104 13\n178571577 7\n238095435 6\n333333608 5\n500000411 4\n5000004100 1\n"}, {"input": "90006000426440\n", "output": "30\n1 90006000426440\n2 30002000142147\n3 15001000071074\n4 9000600042645\n7 3214500015232\n16 661808826670\n20 428600002037\n34 151270588963\n48 76535714664\n84 25211764853\n111 14479729835\n119 12605882452\n147 8274131362\n628 455712949\n784 292493438\n292493438 784\n455712949 628\n8274131362 147\n12605882452 119\n14479729835 111\n25211764853 84\n76535714664 48\n151270588963 34\n428600002037 20\n661808826670 16\n3214500015232 7\n9000600042645 4\n15001000071074 3\n30002000142147 2\n90006000426440 1\n"}, {"input": "6466460\n", "output": "46\n1 6466460\n2 2155487\n3 1077744\n4 646647\n7 230947\n10 117575\n11 97980\n12 82907\n13 71064\n19 34040\n20 30799\n21 28000\n34 10879\n38 8739\n39 8303\n55 4217\n56 4070\n65 3036\n76 2235\n84 1839\n119 945\n209 364\n220 339\n339 220\n364 209\n945 119\n1839 84\n2235 76\n3036 65\n4070 56\n4217 55\n8303 39\n8739 38\n10879 34\n28000 21\n30799 20\n34040 19\n71064 13\n82907 12\n97980 11\n117575 10\n230947 7\n646647 4\n1077744 3\n2155487 2\n6466460 1\n"}, {"input": "30009980\n", "output": "28\n1 30009980\n2 10003327\n3 5001664\n4 3000999\n7 1071787\n10 545639\n11 454700\n12 384747\n13 329784\n20 142911\n21 129920\n39 38487\n55 19505\n65 14012\n14012 65\n19505 55\n38487 39\n129920 21\n142911 20\n329784 13\n384747 12\n454700 11\n545639 10\n1071787 7\n3000999 4\n5001664 3\n10003327 2\n30009980 1\n"}, {"input": "800008300\n", "output": "28\n1 800008300\n4 80000831\n5 53333888\n6 38095635\n7 28571727\n13 8791304\n14 7619131\n19 4210576\n24 2666702\n25 2461572\n49 653084\n104 146556\n195 41928\n455 7863\n7863 455\n41928 195\n146556 104\n653084 49\n2461572 25\n2666702 24\n4210576 19\n7619131 14\n8791304 13\n28571727 7\n38095635 6\n53333888 5\n80000831 4\n800008300 1\n"}, {"input": "808007200\n", "output": "34\n1 808007200\n4 80800721\n5 53867148\n6 38476535\n7 28857402\n10 14691043\n13 8879204\n14 7695311\n15 6733398\n24 2693365\n25 2486184\n32 1530327\n55 524698\n64 388486\n77 269092\n104 148021\n175 52526\n52526 175\n148021 104\n269092 77\n388486 64\n524698 55\n1530327 32\n2486184 25\n2693365 24\n6733398 15\n7695311 14\n8879204 13\n14691043 10\n28857402 7\n38476535 6\n53867148 5\n80800721 4\n808007200 1\n"}, {"input": "900601520\n", "output": "34\n1 900601520\n2 300200507\n3 150100254\n4 90060153\n7 32164342\n12 11546177\n13 9896724\n16 6622075\n19 4740014\n20 4288585\n34 1513627\n38 1215399\n39 1154630\n56 564305\n84 252297\n119 126174\n272 24347\n24347 272\n126174 119\n252297 84\n564305 56\n1154630 39\n1215399 38\n1513627 34\n4288585 20\n4740014 19\n6622075 16\n9896724 13\n11546177 12\n32164342 7\n90060153 4\n150100254 3\n300200507 2\n900601520 1\n"}, {"input": "500600123456789\n", "output": "4\n1 500600123456789\n2 166866707818930\n166866707818930 2\n500600123456789 1\n"}, {"input": "4729310003500000\n", "output": "10\n1 4729310003500000\n4 472931000350001\n5 315287333566668\n15 39410916695838\n24 15764366678341\n15764366678341 24\n39410916695838 15\n315287333566668 5\n472931000350001 4\n4729310003500000 1\n"}, {"input": "590084357100000000\n", "output": "20\n1 590084357100000000\n4 59008435710000001\n7 21074441325000002\n8 16391232141666669\n9 13112985713333336\n35 936641836666678\n49 481701516000016\n63 292700573958354\n224 23416045916741\n39374 761239791\n761239791 39374\n23416045916741 224\n292700573958354 63\n481701516000016 49\n936641836666678 35\n13112985713333336 9\n16391232141666669 8\n21074441325000002 7\n59008435710000001 4\n590084357100000000 1\n"}, {"input": "2937500926541895\n", "output": "2\n1 2937500926541895\n2937500926541895 1\n"}, {"input": "400000089000000000\n", "output": "10\n1 400000089000000000\n4 40000008900000001\n16 2941177125000005\n17 2614379666666672\n127 49212609375042\n49212609375042 127\n2614379666666672 17\n2941177125000005 16\n40000008900000001 4\n400000089000000000 1\n"}, {"input": "5\n", "output": "3\n1 5\n2 2\n5 1\n"}, {"input": "200800200\n", "output": "4\n1 200800200\n4 20080021\n20080021 4\n200800200 1\n"}, {"input": "999999853754584125\n", "output": "5\n1 999999853754584125\n45 966183433579323\n1442249 1442249\n966183433579323 45\n999999853754584125 1\n"}, {"input": "114335783345000\n", "output": "13\n1 114335783345000\n2 38111927781667\n3 19055963890834\n4 11433578334501\n7 4083420833752\n20 544456111173\n70000 70000\n544456111173 20\n4083420833752 7\n11433578334501 4\n19055963890834 3\n38111927781667 2\n114335783345000 1\n"}, {"input": "333343833443500385\n", "output": "7\n1 333343833443500385\n2 111114611147833462\n10 6060796971700010\n1000010 1000010\n6060796971700010 10\n111114611147833462 2\n333343833443500385 1\n"}, {"input": "333336333342000008\n", "output": "8\n1 333336333342000008\n2 111112111114000003\n3 55556055557000002\n1000002 1000003\n1000003 1000002\n55556055557000002 3\n111112111114000003 2\n333336333342000008 1\n"}, {"input": "41679167500\n", "output": "11\n1 41679167500\n4 4167916751\n5 2778611168\n24 138930566\n1095 69823\n5000 5000\n69823 1095\n138930566 24\n2778611168 5\n4167916751 4\n41679167500 1\n"}, {"input": "333357833933504900\n", "output": "15\n1 333357833933504900\n2 111119277977834967\n3 55559638988917484\n4 33335783393350491\n12 4273818383762887\n25 1025716412103100\n39 427381838376301\n1000024 1000024\n427381838376301 39\n1025716412103100 25\n4273818383762887 12\n33335783393350491 4\n55559638988917484 3\n111119277977834967 2\n333357833933504900 1\n"}, {"input": "2666686666700000\n", "output": "13\n1 2666686666700000\n2 888895555566667\n3 444447777783334\n4 266668666670001\n7 95238809525002\n20 12698507936673\n200000 200000\n12698507936673 20\n95238809525002 7\n266668666670001 4\n444447777783334 3\n888895555566667 2\n2666686666700000 1\n"}, {"input": "334344854787443885\n", "output": "15\n1 334344854787443885\n2 111448284929147962\n10 6078997359771710\n21 1447380323755175\n34 561924125693194\n101 64908727390335\n15554 2763842842\n1001010 1001010\n2763842842 15554\n64908727390335 101\n561924125693194 34\n1447380323755175 21\n6078997359771710 10\n111448284929147962 2\n334344854787443885 1\n"}, {"input": "979139840681508275\n", "output": "19\n1 979139840681508275\n2 326379946893836092\n10 17802542557845608\n21 4238700609010865\n29 2250896185474741\n109 163326078512381\n145 92502582964763\n174 64311319585050\n218 41017964923264\n1432150 1432150\n41017964923264 218\n64311319585050 174\n92502582964763 145\n163326078512381 109\n2250896185474741 29\n4238700609010865 21\n17802542557845608 10\n326379946893836092 2\n979139840681508275 1\n"}, {"input": "914669606669700001\n", "output": "3\n1 914669606669700001\n1400001 1400001\n914669606669700001 1\n"}, {"input": "333334833335500001\n", "output": "5\n1 333334833335500001\n2 111111611111833334\n1000001 1000001\n111111611111833334 2\n333334833335500001 1\n"}, {"input": "732334178333550000\n", "output": "11\n1 732334178333550000\n4 73233417833355001\n25 2253335933334008\n31 1476480198253135\n124 94494732688241\n1300000 1300000\n94494732688241 124\n1476480198253135 31\n2253335933334008 25\n73233417833355001 4\n732334178333550000 1\n"}, {"input": "14\n", "output": "5\n1 14\n2 5\n3 3\n5 2\n14 1\n"}, {"input": "576000720000200000\n", "output": "21\n1 576000720000200000\n2 192000240000066667\n3 96000120000033334\n4 57600072000020001\n10 10472740363640003\n11 8727283636366670\n43 608880253700014\n128 69767529069834\n472 5160002150157\n1375 608880254158\n1200000 1200000\n608880254158 1375\n5160002150157 472\n69767529069834 128\n608880253700014 43\n8727283636366670 11\n10472740363640003 10\n57600072000020001 4\n96000120000033334 3\n192000240000066667 2\n576000720000200000 1\n"}, {"input": "3456346346334634\n", "output": "2\n1 3456346346334634\n3456346346334634 1\n"}]
295
You are given a positive integer $n$. Find a sequence of fractions $\frac{a_i}{b_i}$, $i = 1 \ldots k$ (where $a_i$ and $b_i$ are positive integers) for some $k$ such that: $$ \begin{cases} \text{$b_i$ divides $n$, $1 < b_i < n$ for $i = 1 \ldots k$} \\ \text{$1 \le a_i < b_i$ for $i = 1 \ldots k$} \\ \text{$\sum\limits_{i=1}^k \frac{a_i}{b_i} = 1 - \frac{1}{n}$} \end{cases} $$ -----Input----- The input consists of a single integer $n$ ($2 \le n \le 10^9$). -----Output----- In the first line print "YES" if there exists such a sequence of fractions or "NO" otherwise. If there exists such a sequence, next lines should contain a description of the sequence in the following format. The second line should contain integer $k$ ($1 \le k \le 100\,000$)Β β€” the number of elements in the sequence. It is guaranteed that if such a sequence exists, then there exists a sequence of length at most $100\,000$. Next $k$ lines should contain fractions of the sequence with two integers $a_i$ and $b_i$ on each line. -----Examples----- Input 2 Output NO Input 6 Output YES 2 1 2 1 3 -----Note----- In the second example there is a sequence $\frac{1}{2}, \frac{1}{3}$ such that $\frac{1}{2} + \frac{1}{3} = 1 - \frac{1}{6}$.
interview
[{"code": "from math import sqrt\n\ndef phi(u):\n\tans = u\n\tfor i in range(2, int(sqrt(n)) + 1):\n\t\tif u % i == 0:\n\t\t\twhile u % i == 0:\n\t\t\t\tu = u / i\n\t\t\tans = ans - int(ans / i)\n\tif n > 1:\n\t\tans = ans - int(ans / n)\n\treturn ans\n\ndef binpow(u, a, mod):\n\tans = 1\n\tif a == 0:\n\t\treturn 1;\n\twhile a > 0:\n\t\tif a % 2 == 0:\n\t\t\tu = (u ** 2) % mod\n\t\t\ta = int(a / 2)\n\t\telse :\n\t\t\tans = (ans * u) % mod\n\t\t\ta = a - 1\n\treturn int(ans)\n\nn = int(input())\n\nb1 = 1\nb2 = 0\nnn = n\nfor i in range(2, int(sqrt(n)) + 1):\n\tif n%i == 0 :\n\t\twhile nn % i == 0:\n\t\t\tb1 = b1 * i\n\t\t\tnn = nn / i\n\t\tb2 = int(n / b1)\n\t\tbreak\n\nif b2 < 2:\n\tprint(\"NO\")\n\treturn\na1 = b1 - binpow(b2, phi(b1) - 1, b1)\na2 = b2 - int((a1*b2+1)/b1)\nprint(\"YES\")\nprint(2)\nprint(a1, b1)\nprint(a2, b2)\n", "passed": true, "time": 0.19, "memory": 14352.0, "status": "done"}, {"code": "# ========== //\\\\ //|| ||====//||\n# || // \\\\ || || // ||\n# || //====\\\\ || || // ||\n# || // \\\\ || || // ||\n# ========== // \\\\ ======== ||//====|| \n# code\n\ndef egcd(a, b):\n if a == 0 : \n return b, 0, 1\n \n gcd, x1, y1 = egcd(b % a, a) \n\n x = y1 - (b//a) * x1 \n y = x1 \n \n return gcd, x, y\n\ndef main():\n n = int(input())\n div = []\n d = set()\n\n m = n\n\n i = 2\n while i * i <= n:\n cnt = 0\n while n % i == 0:\n cnt += 1\n n //= i\n d.add(i)\n if cnt > 0:\n div.append((cnt, i))\n i += 1\n \n if n > 1:\n div.append((1, n))\n d.add(n)\n\n for i in d:\n if i == m:\n d.remove(i)\n break\n \n if len(d) < 2:\n print('NO')\n return\n \n ans1 = 1\n for i in range(div[0][0]):\n ans1 *= div[0][1]\n \n ans2 = 1\n for i in div[1:]:\n for j in range(i[0]):\n ans2 *= i[1]\n \n gcd, x, y = egcd(ans2, -ans1)\n if x < 0 or y < 0:\n gcd, x, y = egcd(ans1, -ans2)\n x,y = y,x\n \n print('YES')\n print(2)\n\n if ans2 * x + ans1 * y == m - 1:\n print(x, ans1)\n print(y, ans2)\n elif ans2 * (ans1 - x) + ans1 * y == m - 1:\n print(ans1 - x, ans1)\n print(y, ans2)\n elif ans2 * x + ans1 * (ans2 - y) == m - 1:\n print(x, ans1)\n print(ans2 - y, ans2)\n else:\n print(ans1 - x, ans1)\n print(ans2 - y, ans2)\n\n return\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.18, "memory": 14388.0, "status": "done"}]
[{"input": "2\n", "output": "NO\n"}, {"input": "6\n", "output": "YES\n2\n1 2\n1 3\n"}, {"input": "3\n", "output": "NO\n"}, {"input": "4\n", "output": "NO\n"}, {"input": "5\n", "output": "NO\n"}, {"input": "7\n", "output": "NO\n"}, {"input": "10895\n", "output": "YES\n2\n1 5\n1743 2179\n"}, {"input": "16968\n", "output": "YES\n2\n7 8\n265 2121\n"}, {"input": "18438\n", "output": "YES\n2\n1 2\n4609 9219\n"}, {"input": "9589\n", "output": "YES\n2\n16 43\n140 223\n"}, {"input": "16705\n", "output": "YES\n2\n4 5\n668 3341\n"}, {"input": "2789\n", "output": "NO\n"}, {"input": "15821\n", "output": "YES\n2\n8 13\n468 1217\n"}, {"input": "96120064\n", "output": "YES\n2\n219 256\n54267 375469\n"}, {"input": "49438110\n", "output": "YES\n2\n1 2\n12359527 24719055\n"}, {"input": "32954134\n", "output": "YES\n2\n1 2\n8238533 16477067\n"}, {"input": "71851857\n", "output": "YES\n2\n1 3\n15967079 23950619\n"}, {"input": "6094109\n", "output": "YES\n2\n5 7\n248739 870587\n"}, {"input": "77044770\n", "output": "YES\n2\n1 2\n19261192 38522385\n"}, {"input": "58644781\n", "output": "YES\n2\n11 13\n694021 4511137\n"}, {"input": "792852058\n", "output": "YES\n2\n1 2\n198213014 396426029\n"}, {"input": "208253300\n", "output": "YES\n2\n3 4\n13015831 52063325\n"}, {"input": "584467493\n", "output": "YES\n2\n17 19\n3238047 30761447\n"}, {"input": "967671675\n", "output": "YES\n2\n1 9\n95572511 107519075\n"}, {"input": "381468071\n", "output": "NO\n"}, {"input": "539044761\n", "output": "YES\n2\n2 3\n59893862 179681587\n"}, {"input": "672783194\n", "output": "YES\n2\n1 2\n168195798 336391597\n"}, {"input": "1000000000\n", "output": "YES\n2\n403 512\n415802 1953125\n"}, {"input": "640603919\n", "output": "NO\n"}, {"input": "353407931\n", "output": "NO\n"}, {"input": "517920199\n", "output": "NO\n"}, {"input": "262759087\n", "output": "NO\n"}, {"input": "860452507\n", "output": "NO\n"}, {"input": "685518877\n", "output": "NO\n"}, {"input": "846706411\n", "output": "NO\n"}, {"input": "536870912\n", "output": "NO\n"}, {"input": "387420489\n", "output": "NO\n"}, {"input": "244140625\n", "output": "NO\n"}, {"input": "282475249\n", "output": "NO\n"}, {"input": "418195493\n", "output": "NO\n"}, {"input": "214358881\n", "output": "NO\n"}, {"input": "20151121\n", "output": "NO\n"}, {"input": "887503681\n", "output": "NO\n"}, {"input": "62742241\n", "output": "NO\n"}, {"input": "25411681\n", "output": "NO\n"}, {"input": "295943209\n", "output": "NO\n"}, {"input": "208466113\n", "output": "YES\n2\n6233 8443\n6463 24691\n"}, {"input": "103756027\n", "output": "YES\n2\n371 8443\n11749 12289\n"}, {"input": "424759273\n", "output": "YES\n2\n14986 17203\n3182 24691\n"}, {"input": "294390793\n", "output": "YES\n2\n7436 11923\n9292 24691\n"}, {"input": "146521747\n", "output": "YES\n2\n2769 11923\n9435 12289\n"}, {"input": "303427699\n", "output": "YES\n2\n435 12289\n23817 24691\n"}, {"input": "706815862\n", "output": "YES\n2\n1 2\n176703965 353407931\n"}, {"input": "788277261\n", "output": "YES\n2\n2 3\n87586362 262759087\n"}, {"input": "525518174\n", "output": "YES\n2\n1 2\n131379543 262759087\n"}, {"input": "294053760\n", "output": "YES\n2\n81 128\n843538 2297295\n"}, {"input": "367567200\n", "output": "YES\n2\n29 32\n1076857 11486475\n"}, {"input": "551350800\n", "output": "YES\n2\n15 16\n2153714 34459425\n"}, {"input": "698377680\n", "output": "YES\n2\n11 16\n13640189 43648605\n"}, {"input": "735134400\n", "output": "YES\n2\n29 64\n6281666 11486475\n"}, {"input": "321197185\n", "output": "YES\n2\n2 5\n38543662 64239437\n"}, {"input": "321197186\n", "output": "YES\n2\n1 2\n80299296 160598593\n"}]
297
Vasya has got three integers $n$, $m$ and $k$. He'd like to find three integer points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$, such that $0 \le x_1, x_2, x_3 \le n$, $0 \le y_1, y_2, y_3 \le m$ and the area of the triangle formed by these points is equal to $\frac{nm}{k}$. Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them. -----Input----- The single line contains three integers $n$, $m$, $k$ ($1\le n, m \le 10^9$, $2 \le k \le 10^9$). -----Output----- If there are no such points, print "NO". Otherwise print "YES" in the first line. The next three lines should contain integers $x_i, y_i$ β€” coordinates of the points, one point per line. If there are multiple solutions, print any of them. You can print each letter in any case (upper or lower). -----Examples----- Input 4 3 3 Output YES 1 0 2 3 4 1 Input 4 4 7 Output NO -----Note----- In the first example area of the triangle should be equal to $\frac{nm}{k} = 4$. The triangle mentioned in the output is pictured below: [Image] In the second example there is no triangle with area $\frac{nm}{k} = \frac{16}{7}$.
interview
[{"code": "def gcd(a, b):\n while b:\n a, b = b, a%b\n return a\nn,m,k=list(map(int,input().split()))\nif (2*n*m)%k==0:\n c=0\n if k%2!=0:\n c=1\n else:\n k//=2\n a=n//gcd(k,n)\n k//=gcd(k,n)\n b=m//gcd(m,k)\n if c==1:\n if a*2>n and a*2>m:\n b*=2\n else:\n a*=2\n if a>n or b>m:\n a,b=b,a\n print(\"YES\")\n print(\"0 0\")\n print(\"0\",b)\n print(a,\"0\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}]
[{"input": "4 3 3\n", "output": "YES\n0 0\n0 2\n4 0\n"}, {"input": "4 4 7\n", "output": "NO\n"}, {"input": "3 4 2\n", "output": "YES\n0 0\n0 4\n3 0\n"}, {"input": "3 4 3\n", "output": "YES\n0 0\n0 4\n2 0\n"}, {"input": "3 4 12\n", "output": "YES\n0 0\n0 2\n1 0\n"}, {"input": "16904235 79092881 127345237\n", "output": "YES\n0 0\n0 699937\n30 0\n"}, {"input": "1000000000 999999937 1024\n", "output": "YES\n0 0\n0 999999937\n1953125 0\n"}, {"input": "229999981 1000000000 2048\n", "output": "NO\n"}, {"input": "1 1 2\n", "output": "YES\n0 0\n0 1\n1 0\n"}, {"input": "1000000000 1000000000 2\n", "output": "YES\n0 0\n0 1000000000\n1000000000 0\n"}, {"input": "799999999 217041223 5865979\n", "output": "YES\n0 0\n0 74\n799999999 0\n"}, {"input": "899999963 558436066 279988\n", "output": "YES\n0 0\n0 3989\n899999963 0\n"}, {"input": "217041223 799999999 5865979\n", "output": "YES\n0 0\n0 799999999\n74 0\n"}, {"input": "311 2886317 897644587\n", "output": "YES\n0 0\n0 1\n2 0\n"}, {"input": "1 156483121 156483121\n", "output": "YES\n0 0\n0 2\n1 0\n"}, {"input": "237349317 1 237349317\n", "output": "YES\n0 0\n0 1\n2 0\n"}, {"input": "1747211 283 494460713\n", "output": "YES\n0 0\n0 1\n2 0\n"}, {"input": "8824 785 2\n", "output": "YES\n0 0\n0 785\n8824 0\n"}, {"input": "4422 1826 3\n", "output": "YES\n0 0\n0 1826\n2948 0\n"}, {"input": "4354 3801 181\n", "output": "YES\n0 0\n0 42\n4354 0\n"}, {"input": "13 51 298401051\n", "output": "NO\n"}, {"input": "2 19 182343418\n", "output": "NO\n"}, {"input": "1 361 656220385\n", "output": "NO\n"}, {"input": "4 16 540162752\n", "output": "NO\n"}, {"input": "69 4761 424105119\n", "output": "NO\n"}, {"input": "45418 13277 603014786\n", "output": "YES\n0 0\n0 1\n2 0\n"}, {"input": "10267 1 781924453\n", "output": "NO\n"}, {"input": "186860 5142 960834120\n", "output": "YES\n0 0\n0 2\n1 0\n"}, {"input": "22207 109 844776487\n", "output": "NO\n"}, {"input": "49435 13164 650762340\n", "output": "YES\n0 0\n0 2\n1 0\n"}, {"input": "1 19 534704707\n", "output": "NO\n"}, {"input": "1 58 418647074\n", "output": "NO\n"}, {"input": "1 1 892524041\n", "output": "NO\n"}, {"input": "3 2344 776466408\n", "output": "NO\n"}, {"input": "185 5 955376075\n", "output": "NO\n"}, {"input": "1 1 612615929\n", "output": "NO\n"}, {"input": "13903 56932 791525596\n", "output": "YES\n0 0\n0 2\n1 0\n"}, {"input": "1869 1 970435263\n", "output": "NO\n"}, {"input": "302 5 854377630\n", "output": "NO\n"}, {"input": "6 11 33287298\n", "output": "NO\n"}, {"input": "1 6 212196966\n", "output": "NO\n"}, {"input": "1 23 96139333\n", "output": "NO\n"}, {"input": "1 2 614160842\n", "output": "NO\n"}, {"input": "339 3 498103209\n", "output": "NO\n"}, {"input": "4 1 677012876\n", "output": "NO\n"}, {"input": "3 1 560955243\n", "output": "NO\n"}, {"input": "1 3 34832211\n", "output": "NO\n"}, {"input": "71 7 918774577\n", "output": "NO\n"}, {"input": "8 2 802716944\n", "output": "NO\n"}, {"input": "974654615 59871038 562\n", "output": "NO\n"}, {"input": "568435169 488195690 755\n", "output": "NO\n"}, {"input": "307439915 61744535 511\n", "output": "NO\n"}, {"input": "887669087 755467202 3\n", "output": "NO\n"}, {"input": "626673832 329016046 38\n", "output": "YES\n0 0\n0 17316634\n626673832 0\n"}, {"input": "925487090 902564890 70\n", "output": "NO\n"}, {"input": "236887699 1000000000 2\n", "output": "YES\n0 0\n0 1000000000\n236887699 0\n"}, {"input": "3 5 30\n", "output": "YES\n0 0\n0 1\n1 0\n"}, {"input": "99999989 999999937 2\n", "output": "YES\n0 0\n0 999999937\n99999989 0\n"}, {"input": "9 2 3\n", "output": "YES\n0 0\n0 2\n6 0\n"}, {"input": "62 14 8\n", "output": "YES\n0 0\n0 7\n31 0\n"}, {"input": "2 2 8\n", "output": "YES\n0 0\n0 1\n1 0\n"}, {"input": "1200 143143 336\n", "output": "YES\n0 0\n0 20449\n50 0\n"}]
298
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws n sticks in a row. After that the players take turns crossing out exactly k sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than k sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him. -----Input----- The first line contains two integers n and k (1 ≀ n, k ≀ 10^18, k ≀ n)Β β€” the number of sticks drawn by Sasha and the number kΒ β€” the number of sticks to be crossed out on each turn. -----Output----- If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower). -----Examples----- Input 1 1 Output YES Input 10 4 Output NO -----Note----- In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
interview
[{"code": "n,k=list(map(int,input().split()))\nn=(n//k)%2\nprint('YES' if n==1 else 'NO')\n", "passed": true, "time": 1.81, "memory": 14296.0, "status": "done"}, {"code": "a, b = input().split()\na, b = int(a), int(b)\n\nif (a//b) % 2 == 1:\n print('YES')\nelse:\n print('NO')\n\n", "passed": true, "time": 0.25, "memory": 14492.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nturns = n // k\nif turns % 2 == 0:\n print(\"NO\")\nelse:\n print(\"YES\")\n", "passed": true, "time": 0.25, "memory": 14368.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nprint(\"YES\" if (n//k)%2 == 1 else \"NO\")", "passed": true, "time": 0.15, "memory": 14248.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\nif (n // k) % 2 == 1:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")", "passed": true, "time": 0.23, "memory": 14308.0, "status": "done"}, {"code": "a,b = list(map(int,input().split()))\nx = a//b\nif x % 2 == 1:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.16, "memory": 14376.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nx = n // k\nprint(\"YES\" if x % 2 == 1 else \"NO\")", "passed": true, "time": 0.25, "memory": 14528.0, "status": "done"}, {"code": "import math\nfrom collections import deque\nimport sys\nfrom sys import stdin,stderr,stdout\n\n\nn,k=list(map(int,stdin.readline().strip().split()))\na=n//k\nif a%2==1:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.2, "memory": 14344.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\nif (n//k)%2 == 1:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14524.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\nc = a // b\nif c % 2 == 1:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.14, "memory": 14512.0, "status": "done"}, {"code": "import sys\nn, k = map(int, input().split())\nz = n // k\nif z % 2 == 1:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.25, "memory": 14304.0, "status": "done"}, {"code": "inp=input().split()\nn=int(inp[0])\nk=int(inp[1])\nif((n//k)%2==0):\n\tprint(\"NO\")\nelse:\n\tprint(\"YES\")", "passed": true, "time": 0.15, "memory": 14320.0, "status": "done"}, {"code": "a,b = (int(x) for x in input().split())\ntmp = a//b\nif tmp%2 == 0:\n print(\"NO\")\nelse:\n print(\"YES\")", "passed": true, "time": 0.24, "memory": 14420.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\nt = n // k\nif t % 2 == 1:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.15, "memory": 14304.0, "status": "done"}, {"code": "n, m = map(int, input().split())\n\nif (n // m) % 2:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.14, "memory": 14276.0, "status": "done"}, {"code": "string = input()\nnumbers = string.split()\na, b = int(numbers[0]), int(numbers[1])\nn = a // b\nif n % 2 == 1:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.15, "memory": 14300.0, "status": "done"}, {"code": "n, m = map(int, input().split())\n\na = n // m\nprint (['NO', 'YES'][a % 2])", "passed": true, "time": 0.14, "memory": 14340.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nif n // k % 2 == 0:\n print(\"NO\")\nelse:\n print(\"YES\")", "passed": true, "time": 0.14, "memory": 14488.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nif n // k % 2 == 0:\n print('NO')\nelse:\n print('YES')", "passed": true, "time": 0.14, "memory": 14380.0, "status": "done"}, {"code": "n,k=(int(i) for i in input().split())\na=n//k\nprint('YES' if a%2==1 else 'NO')\n", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "a, b = map(int, input().split())\nif a // b % 2 == 0:\n print(\"NO\")\nelse:\n print(\"YES\")", "passed": true, "time": 0.14, "memory": 14304.0, "status": "done"}, {"code": "#n = int(input())\nn,m = list(map(int,input().split()))\nval = n//m\nif val%2==0:\n print(\"NO\")\nelse:\n print(\"YES\")\n", "passed": true, "time": 0.14, "memory": 14276.0, "status": "done"}, {"code": "n, k = map(int, input().split())\n\nif (n // k) % 2 == 0:\n print('NO')\nelse:\n print('YES')", "passed": true, "time": 0.14, "memory": 14464.0, "status": "done"}]
[{"input": "1 1\n", "output": "YES\n"}, {"input": "10 4\n", "output": "NO\n"}, {"input": "251656215122324104 164397544865601257\n", "output": "YES\n"}, {"input": "963577813436662285 206326039287271924\n", "output": "NO\n"}, {"input": "1000000000000000000 1\n", "output": "NO\n"}, {"input": "253308697183523656 25332878317796706\n", "output": "YES\n"}, {"input": "669038685745448997 501718093668307460\n", "output": "YES\n"}, {"input": "116453141993601660 87060381463547965\n", "output": "YES\n"}, {"input": "766959657 370931668\n", "output": "NO\n"}, {"input": "255787422422806632 146884995820359999\n", "output": "YES\n"}, {"input": "502007866464507926 71266379084204128\n", "output": "YES\n"}, {"input": "257439908778973480 64157133126869976\n", "output": "NO\n"}, {"input": "232709385 91708542\n", "output": "NO\n"}, {"input": "252482458300407528 89907711721009125\n", "output": "NO\n"}, {"input": "6 2\n", "output": "YES\n"}, {"input": "6 3\n", "output": "NO\n"}, {"input": "6 4\n", "output": "YES\n"}, {"input": "6 5\n", "output": "YES\n"}, {"input": "6 6\n", "output": "YES\n"}, {"input": "258266151957056904 30153168463725364\n", "output": "NO\n"}, {"input": "83504367885565783 52285355047292458\n", "output": "YES\n"}, {"input": "545668929424440387 508692735816921376\n", "output": "YES\n"}, {"input": "547321411485639939 36665750286082900\n", "output": "NO\n"}, {"input": "548973893546839491 183137237979822911\n", "output": "NO\n"}, {"input": "544068082 193116851\n", "output": "NO\n"}, {"input": "871412474 749817171\n", "output": "YES\n"}, {"input": "999999999 1247\n", "output": "NO\n"}, {"input": "851941088 712987048\n", "output": "YES\n"}, {"input": "559922900 418944886\n", "output": "YES\n"}, {"input": "293908937 37520518\n", "output": "YES\n"}, {"input": "650075786 130049650\n", "output": "NO\n"}, {"input": "1000000000 1000000000\n", "output": "YES\n"}, {"input": "548147654663723363 107422751713800746\n", "output": "YES\n"}, {"input": "828159210 131819483\n", "output": "NO\n"}, {"input": "6242634 4110365\n", "output": "YES\n"}, {"input": "458601973 245084155\n", "output": "YES\n"}, {"input": "349593257 18089089\n", "output": "YES\n"}, {"input": "814768821 312514745\n", "output": "NO\n"}, {"input": "697884949 626323363\n", "output": "YES\n"}, {"input": "667011589 54866795\n", "output": "NO\n"}, {"input": "1000000000000000000 2\n", "output": "NO\n"}, {"input": "1000000000000000000 3\n", "output": "YES\n"}, {"input": "1000000000000000000 4\n", "output": "NO\n"}, {"input": "999999999999999 1\n", "output": "YES\n"}, {"input": "17 4\n", "output": "NO\n"}, {"input": "2 2\n", "output": "YES\n"}, {"input": "1000000000000000 2\n", "output": "NO\n"}, {"input": "12 4\n", "output": "YES\n"}, {"input": "6 1\n", "output": "NO\n"}, {"input": "2 1\n", "output": "NO\n"}, {"input": "10000000005 1\n", "output": "YES\n"}, {"input": "10000000000000009 2\n", "output": "NO\n"}, {"input": "12457895452123 1\n", "output": "YES\n"}, {"input": "999999999999999999 9\n", "output": "YES\n"}, {"input": "1000000000000 3\n", "output": "YES\n"}, {"input": "13099714659575475 6549849616514894\n", "output": "NO\n"}, {"input": "100000000000000001 1\n", "output": "YES\n"}, {"input": "825175814723458 324\n", "output": "YES\n"}, {"input": "20 4\n", "output": "YES\n"}, {"input": "100000176877 4\n", "output": "YES\n"}, {"input": "100000 3\n", "output": "YES\n"}, {"input": "946744073709551614 10\n", "output": "YES\n"}]
299
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a_1, a_2, ..., a_{n}. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercise a_{i} times. Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the n-th exercise. Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training. -----Input----- The first line contains integer n (1 ≀ n ≀ 20). The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 25) β€” the number of times Greg repeats the exercises. -----Output----- Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous. -----Examples----- Input 2 2 8 Output biceps Input 3 5 1 10 Output back Input 7 3 3 2 7 9 6 8 Output chest -----Note----- In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.
interview
[{"code": "n=int(input())\n\ns=input().split()\n\nA=[0,0,0]\nfor i in range(n):\n A[i%3]+=int(s[i])\n\nm=max(A)\n\nif(m==A[0]):\n print(\"chest\")\nelif(m==A[1]):\n print(\"biceps\")\nelse:\n print(\"back\")\n", "passed": true, "time": 0.16, "memory": 14320.0, "status": "done"}, {"code": "import sys\nmy_file = sys.stdin\n#my_file = open(\"input.txt\", \"r\")\nn = int(my_file.readline().strip(\"\\n\"))\na = [int(i) for i in my_file.readline().split()]\nif sum(a[::3]) >= sum(a[1::3]) and sum(a[::3]) >= sum(a[2::3]):\n print(\"chest\")\nelif sum(a[1::3]) >= sum(a[::3]) and sum(a[1::3]) >= sum(a[2::3]):\n print(\"biceps\")\nelse:\n print(\"back\")", "passed": true, "time": 0.15, "memory": 14316.0, "status": "done"}, {"code": "n, t = int(input()), list(map(int, input().split()))\np, t = [0] * 3, t + [0] * (3 - n % 3)\n\nfor i in range(0, n, 3):\n for j in range(3): p[j] += t[i + j]\n\nprint(['chest', 'biceps', 'back'][p.index(max(p))])", "passed": true, "time": 0.15, "memory": 14420.0, "status": "done"}, {"code": "n = int(input())\nA = list(map(int, input().split()))\na, b, c = 0, 0, 0\ni = 1\nwhile i <= n:\n\ta += A[i - 1]\n\ti += 3\ni = 2\nwhile i <= n:\n\tb += A[i - 1]\n\ti += 3\ni = 3\nwhile i <= n:\n\tc += A[i - 1]\n\ti += 3\nif a >= b and a >= c:\n\tprint(\"chest\")\nelif b >= a and b >= c:\n\tprint(\"biceps\")\nelse:\n\tprint(\"back\")", "passed": true, "time": 0.15, "memory": 14308.0, "status": "done"}, {"code": "n = int(input())\na = input().split()\narr = [0,0,0]\ne = [\"back\", \"chest\", \"biceps\"]\n\nfor i in range(1,n+1):\n\tarr[i%3] += int(a[i-1])\n\nprint(e[arr.index(max(arr))])\n", "passed": true, "time": 0.15, "memory": 14284.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\ns = [0]*3\nfor i in range(3):\n s[i] = sum(a[i:n:3])\n\nif max(s) == s[0]:\n print('chest')\nelif max(s) == s[1]:\n print('biceps')\nelse:\n print('back')\n\n", "passed": true, "time": 0.23, "memory": 14544.0, "status": "done"}, {"code": "input()\na=list(map(int,input().split()))\nd1={1:'chest',2:'biceps',0:'back'}\nd2={1:0,2:0,0:0}\nfor i in range(len(a)):\n d2[(i+1)%3]+=a[i]\nMax=0\nfor i in d2:\n if d2[i]>d2[Max]:\n Max=i\nprint(d1[Max])", "passed": true, "time": 2.13, "memory": 14540.0, "status": "done"}, {"code": "input()\na=list(map(int,input().split()))\nd1={1:'chest',2:'biceps',0:'back'}\nd2={1:0,2:0,0:0}\nMax=0\nfor i in range(len(a)):\n d2[(i+1)%3]+=a[i]\n if d2[(i+1)%3]>d2[Max]:\n Max=(i+1)%3\nprint(d1[Max])", "passed": true, "time": 0.15, "memory": 14324.0, "status": "done"}, {"code": "c=input()\narr=[0,0,0]\ninp=input()\ninp=inp.split()\nC=int(c)\nv=0\nfor i in range(C):\n if v==3:\n v=0\n \n if v==0:\n arr[0]+=int(inp[i])\n elif v==1:\n arr[1]+=int(inp[i])\n elif v==2:\n arr[2]+=int(inp[i])\n\n \n\n v+=1\n\nm=max(arr[0],max(arr[1],arr[2]))\nif m==arr[0]:\n print (\"chest\")\nelif m==arr[1]:\n print (\"biceps\")\nelse:\n print (\"back\")\n \n \n", "passed": true, "time": 0.21, "memory": 14300.0, "status": "done"}, {"code": "def main() -> int:\n n = int(input())\n exercises = [int(word) for word in input().split()]\n total = [0] * 3\n\n for i in range(3):\n total[i] = sum(exercises[i::3])\n\n max_index = total.index(max(total))\n exercise_names = ['chest', 'biceps', 'back']\n\n print(exercise_names[max_index])\n\n return 0\n\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14364.0, "status": "done"}, {"code": "n = int(input())\nmasses = input().split()\nmuscle = [\"chest\", \"biceps\", \"back\"]\ni = 0\nres = [0] * 3\nfor mass in masses:\n res[i % 3] += int(mass)\n i += 1\nprint(muscle[res.index(max(res))])", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "sa=input()\nsa2=input().split(' ')\nsa3=[int(x) for x in sa2]\nchest=0\nbiceps=0\nback=0\nfor x in range(len(sa3)):\n if (x+1)%3==1:\n chest+=sa3[x]\n elif (x+1)%3==2:\n biceps+=sa3[x]\n else:\n back+=sa3[x]\n\nif max(chest, back, biceps)==chest:\n print(\"chest\")\nif max(chest, back, biceps)==back:\n print(\"back\")\nif max(chest, back, biceps)==biceps:\n print(\"biceps\")\n", "passed": true, "time": 0.15, "memory": 14528.0, "status": "done"}, {"code": "input()\na=[int(i)for i in input().split()]\nb=[sum(a[::3]),sum(a[1::3]),sum(a[2::3])]\nc=['chest','biceps','back']\nprint(c[b.index(max(b))])", "passed": true, "time": 0.15, "memory": 14372.0, "status": "done"}, {"code": "n = input()\nec = [0] * 3\nmaxi, maxv = 0, 0\nfor i, v in enumerate(map(int, input().split())):\n i %= 3\n ec[i] += v\n if ec[i] > maxv:\n maxi = i\n maxv = ec[i]\nprint(('chest', 'biceps', 'back')[maxi])", "passed": true, "time": 0.14, "memory": 14408.0, "status": "done"}, {"code": "variant = int(input());\nbiceps=chest=back=0;\nA = list(map(int, input().split()));\nfor i in range(variant):\n i+=1;\n if i%3 == 1:\n chest+=A[i-1];\n elif i%3 == 2:\n biceps+=A[i-1];\n else:\n back+=A[i-1];\n\nif chest>biceps:\n if chest>back:\n print(\"chest\");\n else:\n print(\"back\");\n\nelse:\n if biceps>back:\n print(\"biceps\");\n else:\n print(\"back\");\n", "passed": true, "time": 0.15, "memory": 14400.0, "status": "done"}, {"code": "n=int(input())\nl=list(map(int,input().split()))\n\nchest=0\nbiceps=0\nback=0\n\nfor i in range(1,n+1):\n if i%3==1:\n chest+=l[i-1]\n elif i%3==2:\n biceps+=l[i-1]\n else:\n back+=l[i-1]\nif(chest>=biceps and chest>= back):\n print(\"chest\")\nelif(biceps>=chest and biceps>=back):\n print(\"biceps\")\nelse:\n print(\"back\")\n", "passed": true, "time": 0.14, "memory": 14508.0, "status": "done"}, {"code": "import sys\n\nn = int(sys.stdin.readline())\nl = [int(x) for x in (sys.stdin.readline()).split()]\n\nchest = 0\nbiceps = 0\nback = 0\n\ni = 0\nwhile(i < n):\n chest += l[i]\n i += 3\n \ni = 1\nwhile(i < n):\n biceps += l[i]\n i += 3\n \ni = 2\nwhile(i < n):\n back += l[i]\n i += 3\n \nif(chest >= biceps and chest >= back):\n print(\"chest\")\nelif(biceps > chest and biceps > back):\n print(\"biceps\")\nelif(back > biceps and back > chest):\n print(\"back\")", "passed": true, "time": 0.14, "memory": 14516.0, "status": "done"}, {"code": "input()\nl = [int(x) for x in input().split()]\na = sum(l[0::3])\nb = sum(l[1::3])\nc = sum(l[2::3])\nif a > b and a > c:\n\tprint('chest')\nelif b > a and b > c:\n\tprint('biceps')\nelse:\n\tprint('back')\n", "passed": true, "time": 0.14, "memory": 14540.0, "status": "done"}, {"code": "import math\n\ndef ost(a,b):\n if a%b!=0:\n return 1\n return 0\n\nn=int(input())\ndata=list(map(int,input().split()))\n\nans=[0,0,0]\n\nfor i in range(n):\n ans[i%3]+=data[i]\n\nanss=[ans[i] for i in range(3)]\nanss.sort()\n#print(anss,ans)\nif ans[0]==anss[-1]:\n print(\"chest\")\nif ans[1]==anss[-1]:\n print(\"biceps\")\nif ans[2]==anss[-1]:\n print(\"back\")\n\n", "passed": true, "time": 0.15, "memory": 14512.0, "status": "done"}, {"code": "from sys import stdin\n\n\ndef main():\n stdin.readline()\n l = [0, 0, 0]\n for i, a in enumerate(map(int, stdin.readline().strip().split())):\n l[i % 3] += a\n return ('chest', 'biceps', 'back')[max(0, 1, 2, key=l.__getitem__)]\n\nprint(main())\n", "passed": true, "time": 1.09, "memory": 14364.0, "status": "done"}, {"code": "n = int(input())\nt = [int(x) for x in input().split()]\nc =bi = ba=0\nfor ii in range(n):\n if (ii+1) % 3 == 1:\n c+=t[ii]\n elif (ii+1) % 3 ==2:\n bi+=t[ii]\n else:\n ba +=t[ii]\n \nif c > bi and c > ba:\n print(\"chest\") \nelif bi > c and bi > ba:\n print(\"biceps\")\nelse:\n print(\"back\")", "passed": true, "time": 0.15, "memory": 14272.0, "status": "done"}, {"code": "def s(p):\n r=0\n for i in range(len(p)):\n r+=p[i]\n return r\n\nn=int(input())\nr=input()\nl=list(r.split())\n\nx=[]\ny=[]\nz=[]\n\nfor i in range(len(l)):\n if(i%3==0):\n l[i]=int(l[i])\n y.append(l[i])\n elif(i%3==1):\n l[i]=int(l[i])\n z.append(l[i])\n else:\n l[i]=int(l[i])\n x.append(l[i])\nif(s(x)>s(y) and s(x)>s(z)):\n print(\"back\")\nif(s(y)>s(x) and s(y)>s(z)):\n print(\"chest\")\nif(s(z)>s(y) and s(z)>s(x)):\n print(\"biceps\")\n", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "a=int(input())\nb=input().split()\n\nc=0\nbi=0\nbk=0\n\nfor i in range(len(b)):\n if i%3==0:\n c=c+int(b[i])\n elif i%3==1:\n bi=bi+int(b[i])\n elif i%3==2:\n bk=bk+int(b[i])\n\nl=[]\nl.append(c)\nl.append(bi)\nl.append(bk)\n\nd=max(l)\n\nif l.index(d)==0:\n print(\"chest\")\nelif l.index(d)==1:\n print(\"biceps\")\nelse:\n print(\"back\")\n", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "# coding: utf-8\nn = int(input())\na = [int(i) for i in input().split()]\nchest = sum([a[i] for i in range(n) if i%3==0])\nbiceps = sum([a[i] for i in range(n) if i%3==1])\nback = sum([a[i] for i in range(n) if i%3==2])\nif chest>biceps and chest>back:\n print('chest')\nelif biceps>back:\n print('biceps')\nelse:\n print('back')\n", "passed": true, "time": 0.17, "memory": 14464.0, "status": "done"}, {"code": "'''\n@author: linhz\nGreg's Workout\nhttp://codeforces.com/problemset/problem/255/A\n'''\nn=int(input())\nexercise=list(map(int,input().split()))\n#print(exercise)\nres=[0,0,0]\nfor i in range(len(exercise)):\n res[i%3]+=exercise[i]\n#print(res)\nif res[0]>= res[1] and res[0]>=res[2]:\n print(\"chest\")\nelif res[1]>= res[0] and res[1]>=res[2]:\n print(\"biceps\")\nelse:\n print(\"back\")\n", "passed": true, "time": 0.14, "memory": 14508.0, "status": "done"}]
[{"input": "2\n2 8\n", "output": "biceps\n"}, {"input": "3\n5 1 10\n", "output": "back\n"}, {"input": "7\n3 3 2 7 9 6 8\n", "output": "chest\n"}, {"input": "4\n5 6 6 2\n", "output": "chest\n"}, {"input": "5\n8 2 2 6 3\n", "output": "chest\n"}, {"input": "6\n8 7 2 5 3 4\n", "output": "chest\n"}, {"input": "8\n7 2 9 10 3 8 10 6\n", "output": "chest\n"}, {"input": "9\n5 4 2 3 4 4 5 2 2\n", "output": "chest\n"}, {"input": "10\n4 9 8 5 3 8 8 10 4 2\n", "output": "biceps\n"}, {"input": "11\n10 9 7 6 1 3 9 7 1 3 5\n", "output": "chest\n"}, {"input": "12\n24 22 6 16 5 21 1 7 2 19 24 5\n", "output": "chest\n"}, {"input": "13\n24 10 5 7 16 17 2 7 9 20 15 2 24\n", "output": "chest\n"}, {"input": "14\n13 14 19 8 5 17 9 16 15 9 5 6 3 7\n", "output": "back\n"}, {"input": "15\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12\n", "output": "chest\n"}, {"input": "16\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8\n", "output": "biceps\n"}, {"input": "17\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19\n", "output": "chest\n"}, {"input": "18\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21\n", "output": "back\n"}, {"input": "19\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24\n", "output": "chest\n"}, {"input": "20\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20\n", "output": "chest\n"}, {"input": "1\n10\n", "output": "chest\n"}, {"input": "2\n15 3\n", "output": "chest\n"}, {"input": "3\n21 11 19\n", "output": "chest\n"}, {"input": "4\n19 24 13 15\n", "output": "chest\n"}, {"input": "5\n4 24 1 9 19\n", "output": "biceps\n"}, {"input": "6\n6 22 24 7 15 24\n", "output": "back\n"}, {"input": "7\n10 8 23 23 14 18 14\n", "output": "chest\n"}, {"input": "8\n5 16 8 9 17 16 14 7\n", "output": "biceps\n"}, {"input": "9\n12 3 10 23 6 4 22 13 12\n", "output": "chest\n"}, {"input": "10\n1 9 20 18 20 17 7 24 23 2\n", "output": "back\n"}, {"input": "11\n22 25 8 2 18 15 1 13 1 11 4\n", "output": "biceps\n"}, {"input": "12\n20 12 14 2 15 6 24 3 11 8 11 14\n", "output": "chest\n"}, {"input": "13\n2 18 8 8 8 20 5 22 15 2 5 19 18\n", "output": "back\n"}, {"input": "14\n1 6 10 25 17 13 21 11 19 4 15 24 5 22\n", "output": "biceps\n"}, {"input": "15\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6\n", "output": "back\n"}, {"input": "16\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14\n", "output": "chest\n"}, {"input": "17\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10\n", "output": "biceps\n"}, {"input": "18\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17\n", "output": "chest\n"}, {"input": "19\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14\n", "output": "back\n"}, {"input": "20\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6\n", "output": "back\n"}, {"input": "1\n19\n", "output": "chest\n"}, {"input": "2\n1 7\n", "output": "biceps\n"}, {"input": "3\n18 18 23\n", "output": "back\n"}, {"input": "4\n12 15 1 13\n", "output": "chest\n"}, {"input": "5\n11 14 25 21 21\n", "output": "biceps\n"}, {"input": "6\n11 9 12 11 22 18\n", "output": "biceps\n"}, {"input": "7\n11 1 16 20 21 25 20\n", "output": "chest\n"}, {"input": "8\n1 2 20 9 3 22 17 4\n", "output": "back\n"}, {"input": "9\n19 2 10 19 15 20 3 1 13\n", "output": "back\n"}, {"input": "10\n11 2 11 8 21 16 2 3 19 9\n", "output": "back\n"}, {"input": "20\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24\n", "output": "chest\n"}, {"input": "12\n4 24 21 3 13 24 22 13 12 21 1 15\n", "output": "back\n"}, {"input": "13\n14 14 16 2 13 5 1 14 9 4 16 8 3\n", "output": "biceps\n"}, {"input": "14\n1 9 15 4 11 8 25 3 9 14 13 2 1 11\n", "output": "biceps\n"}, {"input": "15\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17\n", "output": "back\n"}, {"input": "16\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17\n", "output": "chest\n"}, {"input": "17\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8\n", "output": "chest\n"}, {"input": "18\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22\n", "output": "chest\n"}, {"input": "19\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24\n", "output": "chest\n"}, {"input": "20\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23\n", "output": "biceps\n"}, {"input": "1\n19\n", "output": "chest\n"}, {"input": "20\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22\n", "output": "biceps\n"}]
300
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically Β β€” he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the studentΒ β€” $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$. This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo. Help VasyaΒ β€” calculate the minimum amount of lab works Vasya has to redo. -----Input----- The first line contains a single integer $n$Β β€” the number of Vasya's grades ($1 \leq n \leq 100$). The second line contains $n$ integers from $2$ to $5$Β β€” Vasya's grades for his lab works. -----Output----- Output a single integerΒ β€” the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. -----Examples----- Input 3 4 4 4 Output 2 Input 4 5 4 5 5 Output 0 Input 4 5 3 3 5 Output 1 -----Note----- In the first sample, it is enough to redo two lab works to make two $4$s into $5$s. In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$. In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$.
interview
[{"code": "def read_input():\n\treturn map(int, input().split())\n\nn = int(input())\na = sorted(read_input())\n\ns = sum(a)\ni = 0\n\nwhile 2 * s < 9 * n:\n\tdelta = 5 - a[i]\n\ts += delta\n\ti += 1\n\nprint(i)", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\n# 0 1 2 3 4 5\nc = [0,0,0,0,0,0]\nfor _ in a:\n c[_] += 1\ns = sum(a)\nans = 0\nwhile 2 * s < 9 * n:\n if c[2] > 0:\n s += 3\n c[2] -= 1\n c[5] += 1\n ans += 1\n elif c[3] > 0:\n s += 2\n c[3] -= 1\n c[5] += 1\n ans += 1\n elif c[4] > 0:\n s += 1\n c[4] -= 1\n c[5] += 1\n ans += 1\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}, {"code": "n = int(input())\nai= list(map(int, input().split()))\nai.sort()\nsumm = sum(ai)\nif summ / n >= 4.5:\n print(0)\nelse:\n for i in range(n):\n summ += 5 - ai[i]\n if summ / n >= 4.5:\n print(i+1)\n break\n", "passed": true, "time": 0.25, "memory": 14460.0, "status": "done"}, {"code": "n=int(input())\narr=list(map(int,input().strip().split(' ')))\narr.sort()\ns = sum(arr)\nif(s>=4.5*n):\n print(0)\nelse:\n cnt = 0\n for i in range(n):\n cnt+=1\n s = s-arr[i]+5\n if(s>=4.5*n):\n break\n print(cnt)", "passed": true, "time": 0.15, "memory": 14492.0, "status": "done"}, {"code": "def main():\n n = int(input())\n def ceil(x):\n if x % 1 == 0:\n return int(x)\n return int(x + 1)\n a = ceil(n * 4.5)\n scores = sorted(list(map(int, input().split())))\n s = sum(scores)\n c = 0\n while s < a:\n s += 5 - scores[c]\n c += 1\n print(c)\n return 0\nmain()\n", "passed": true, "time": 0.16, "memory": 14372.0, "status": "done"}, {"code": "n = int(input())\n\ngrades = [int(x) * 2 for x in input().split()]\n\nres = sum(grades)\ntarget = 9 * len(grades)\n\ngrades.sort()\n\nfor i, grade in enumerate(grades):\n if res >= target:\n print(i)\n break\n else:\n res += 10 - grade\nelse:\n print(len(grades))\n", "passed": true, "time": 0.16, "memory": 14484.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\n\nc = 0\ns = sum(a)\nif s/n >= 4.5:\n\tprint (c)\nelse:\n\ta.sort()\n\tfor i in range(len(a)):\n\t\tc+=1\n\t\ts+=(5-a[i])\n\t\ta[i] = 5\n\t\tif (s/n>=4.5):\n\t\t\tbreak\n\tprint (c)\n", "passed": true, "time": 0.25, "memory": 14420.0, "status": "done"}, {"code": "n = int(input())\na = sorted(list(map(int, input().split())))\n\n\nfor i in range(n + 1):\n cur_sum = 5 * i + sum(a[i:])\n\n if cur_sum * 10 >= n * 45:\n print(i)\n break\n\n\n", "passed": true, "time": 0.21, "memory": 14296.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\na.sort()\ntotal = sum(a)\nneed = 4.5 * n\ni = 0\nwhile total < need:\n\ttotal += (5 - a[i])\n\ti += 1\nprint(i)", "passed": true, "time": 0.21, "memory": 14444.0, "status": "done"}, {"code": "n = int(input())\nr = 4.5*n\nt = sorted([int(i) for i in input().split()])\n\nc = 0\ns = sum(t)\nwhile(s < r):\n s += 5 - t[c]\n c += 1\n\nprint(c)", "passed": true, "time": 0.18, "memory": 14416.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int,input().split()))\na.sort()\nc = 0\nwhile sum(a)/len(a) < 4.5:\n a[a.index(min(a))] = 5\n c+=1\nprint(c)\n", "passed": true, "time": 0.15, "memory": 14260.0, "status": "done"}, {"code": "n = int(input().strip())\na = sorted(list(map(int, input().strip().split())))\nr = 0\n\nwhile True:\n mean = sum(a) / n\n if round(mean) >= 5 or mean == 4.5:\n break\n\n r += 1\n a[0] = 5\n a.sort()\n\nprint(r)\n", "passed": true, "time": 0.15, "memory": 14312.0, "status": "done"}, {"code": "n = int(input())\n\ns = list(map(int, input().strip().split()))\n\ns = sorted(s)\n\nmean = sum(s) / len(s)\n\nl = 0\nwhile mean < 4.5:\n s[l] = 5\n l += 1\n mean = sum(s) / len(s)\n\nprint(l)\n", "passed": true, "time": 0.15, "memory": 14404.0, "status": "done"}, {"code": "n = int(input())\ngrades = list(map(int, input().split()))\ngrades.sort()\ncur = sum(grades) / len(grades)\ni = 0\nwhile cur < 4.5:\n\tgrades[i] = 5\n\tcur = sum(grades) / len(grades)\n\ti += 1\nprint(i)\n", "passed": true, "time": 0.17, "memory": 14316.0, "status": "done"}, {"code": "def go():\n n = int(input())\n a = sorted([int(i) for i in input().split(' ')])\n s = sum(a)\n if s / n >= 4.5:\n return 0\n c = 0\n for i in range(n):\n s -= a[i]\n a[i] = 5\n s += 5\n c += 1\n if s / n >= 4.5:\n return c\nprint(go())\n", "passed": true, "time": 0.23, "memory": 14440.0, "status": "done"}, {"code": "n = int(input())\nlabs = [ int(a) for a in input().split() ]\n\nlabs.sort()\n\nredo = 0\nwhile sum(labs)/len(labs) < 4.5:\n labs[redo] = 5\n redo += 1\n\nprint(redo)\n", "passed": true, "time": 0.15, "memory": 14452.0, "status": "done"}, {"code": "\n\nn = int(input())\n\ntab = sorted([int(x) for x in input().split()])\n\n\ns = sum(tab)\n\nresult = 0\n\nfor i in range(n):\n if 2 * s >= 9 * n:\n break\n result += 1\n s -= tab[i]\n s += 5\n\nprint(result)\n", "passed": true, "time": 0.24, "memory": 14300.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\n\ns = sum(a)\nans = 0\nwhile 2 * s / n < 9:\n m = min(a)\n a.remove(m)\n a.append(5)\n s += 5 - m\n ans += 1\n\nprint(ans)\n", "passed": true, "time": 0.25, "memory": 14376.0, "status": "done"}, {"code": "#JMD\n#Nagendra Jha-4096\n \n#a=list(map(int,sys.stdin.readline().split(' ')))\n#n,k,s= map(int, sys.stdin.readline().split(' '))\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 ####\nn=int(input())\na=list(map(int,sys.stdin.readline().split(' ')))\nreach=math.ceil(4.5*n)\ns=sum(a)\na.sort()\nans=reach-s\ncount=0\nfor aa in a:\n if(ans<=0):\n break\n ans-=(5-aa)\n count+=1\nprint(count)\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": 14396.0, "status": "done"}, {"code": "n = int(input())\ng = list(map(int,input().split()))\n\nans = 0\ngr = sum(g)/n\n\nwhile gr < 4.5:\n ma = min(g)\n i = g.index(ma)\n g[i] = 5\n gr = sum(g)/n\n ans += 1\n \n\nprint (ans)\n \n", "passed": true, "time": 0.25, "memory": 14436.0, "status": "done"}, {"code": "n=int(input())\na=list(map(int,input().split(' ')))\ns=sum(a)\nif s>=n*4.5:\n print(0)\nelse:\n x=n*4.5-s\n i=0\n a.sort()\n while x>0:\n x-=5-a[i]\n i+=1\n print(i)\n \n", "passed": true, "time": 0.16, "memory": 14396.0, "status": "done"}, {"code": "N = int(input())\n*A, = list(map(int, input().split()))\nsu = sum(A)\nif su*2 >= 9*N:\n print(0)\n return\n\nA.sort()\nfor i in range(N):\n su += 5 - A[i]\n if su*2 >= 9*N:\n print(i+1)\n return\nreturn\n", "passed": true, "time": 0.15, "memory": 14528.0, "status": "done"}, {"code": "n = int(input())\na = [int(x) for x in input().split()]\n\nsum=0\na = sorted(a)\nfor c in a: sum+=c\navg = sum/n\ncount = 0\nfor c in a:\n if avg >= 4.5:\n break\n sum += 5-c\n avg = sum / n\n count += 1\nprint(count)\n", "passed": true, "time": 0.14, "memory": 14536.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nless = 0\nres = 0\nfor change in range(2, 6):\n\tcnt = 0\n\tcur_sum = 0\n\tfor i in range(n):\n\t\tcur_sum += a[i]\n\tfor i in range(n):\n\t\tif a[i] == change:\n\t\t\tcnt += 1\n\tleast_want = int(4.5 * n + 0.9)\n\tif least_want <= cur_sum:\n\t\tprint(res)\n\t\tbreak\n\tneed = int((least_want - cur_sum + (5 - change) - 1) / (5 - change))\n\tif need <= cnt:\n\t\tprint(need + res)\n\t\tbreak\n\tfor i in range(n):\n\t\tif a[i] == change:\n\t\t\ta[i] = 5\n\tres += cnt\n\n\n\n", "passed": true, "time": 0.15, "memory": 14384.0, "status": "done"}]
[{"input": "3\n4 4 4\n", "output": "2\n"}, {"input": "4\n5 4 5 5\n", "output": "0\n"}, {"input": "4\n5 3 3 5\n", "output": "1\n"}, {"input": "1\n5\n", "output": "0\n"}, {"input": "4\n3 2 5 4\n", "output": "2\n"}, {"input": "5\n5 4 3 2 5\n", "output": "2\n"}, {"input": "8\n5 4 2 5 5 2 5 5\n", "output": "1\n"}, {"input": "5\n5 5 2 5 5\n", "output": "1\n"}, {"input": "6\n5 5 5 5 5 2\n", "output": "0\n"}, {"input": "6\n2 2 2 2 2 2\n", "output": "5\n"}, {"input": "100\n3 2 4 3 3 3 4 2 3 5 5 2 5 2 3 2 4 4 4 5 5 4 2 5 4 3 2 5 3 4 3 4 2 4 5 4 2 4 3 4 5 2 5 3 3 4 2 2 4 4 4 5 4 3 3 3 2 5 2 2 2 3 5 4 3 2 4 5 5 5 2 2 4 2 3 3 3 5 3 2 2 4 5 5 4 5 5 4 2 3 2 2 2 2 5 3 5 2 3 4\n", "output": "40\n"}, {"input": "1\n2\n", "output": "1\n"}, {"input": "1\n3\n", "output": "1\n"}, {"input": "1\n4\n", "output": "1\n"}, {"input": "4\n3 2 5 5\n", "output": "1\n"}, {"input": "6\n4 3 3 3 3 4\n", "output": "4\n"}, {"input": "8\n3 3 5 3 3 3 5 5\n", "output": "3\n"}, {"input": "10\n2 4 5 5 5 5 2 3 3 2\n", "output": "3\n"}, {"input": "20\n5 2 5 2 2 2 2 2 5 2 2 5 2 5 5 2 2 5 2 2\n", "output": "10\n"}, {"input": "25\n4 4 4 4 3 4 3 3 3 3 3 4 4 3 4 4 4 4 4 3 3 3 4 3 4\n", "output": "13\n"}, {"input": "30\n4 2 4 2 4 2 2 4 4 4 4 2 4 4 4 2 2 2 2 4 2 4 4 4 2 4 2 4 2 2\n", "output": "15\n"}, {"input": "52\n5 3 4 4 4 3 5 3 4 5 3 4 4 3 5 5 4 3 3 3 4 5 4 4 5 3 5 3 5 4 5 5 4 3 4 5 3 4 3 3 4 4 4 3 5 3 4 5 3 5 4 5\n", "output": "14\n"}, {"input": "77\n5 3 2 3 2 3 2 3 5 2 2 3 3 3 3 5 3 3 2 2 2 5 5 5 5 3 2 2 5 2 3 2 2 5 2 5 3 3 2 2 5 5 2 3 3 2 3 3 3 2 5 5 2 2 3 3 5 5 2 2 5 5 3 3 5 5 2 2 5 2 2 5 5 5 2 5 2\n", "output": "33\n"}, {"input": "55\n3 4 2 3 3 2 4 4 3 3 4 2 4 4 3 3 2 3 2 2 3 3 2 3 2 3 2 4 4 3 2 3 2 3 3 2 2 4 2 4 4 3 4 3 2 4 3 2 4 2 2 3 2 3 4\n", "output": "34\n"}, {"input": "66\n5 4 5 5 4 4 4 4 4 2 5 5 2 4 2 2 2 5 4 4 4 4 5 2 2 5 5 2 2 4 4 2 4 2 2 5 2 5 4 5 4 5 4 4 2 5 2 4 4 4 2 2 5 5 5 5 4 4 4 4 4 2 4 5 5 5\n", "output": "16\n"}, {"input": "99\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n", "output": "83\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "84\n"}, {"input": "99\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\n", "output": "75\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\n", "output": "75\n"}, {"input": "99\n2 2 3 3 3 3 3 2 2 3 2 3 2 3 2 2 3 2 3 2 3 3 3 3 2 2 2 2 3 2 3 3 3 3 3 2 3 3 3 3 2 3 2 3 3 3 2 3 2 3 3 3 3 2 2 3 2 3 2 3 2 3 2 2 2 3 3 2 3 2 2 2 2 2 2 2 2 3 3 3 3 2 3 2 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3\n", "output": "75\n"}, {"input": "100\n3 2 3 3 2 2 3 2 2 3 3 2 3 2 2 2 2 2 3 2 2 2 3 2 3 3 2 2 3 2 2 2 2 3 2 3 3 2 2 3 2 2 3 2 3 2 2 3 2 3 2 2 3 2 2 3 3 3 3 3 2 2 3 2 3 3 2 2 3 2 2 2 3 2 2 3 3 2 2 3 3 3 3 2 3 2 2 2 3 3 2 2 3 2 2 2 2 3 2 2\n", "output": "75\n"}, {"input": "99\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 4 4 4 4 4 4 4 4 4 4\n", "output": "50\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 4 4 4 4 4 4 4 4 4 4 4\n", "output": "50\n"}, {"input": "99\n2 2 2 2 4 2 2 2 2 4 4 4 4 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 4 2 2 2 4 4 2 2 2 2 4 4 4 2 2 2 4 4 2 4 2 4 2 2 4 2 4 4 4 4 4 2 2 4 4 4 2 2 2 2 4 2 4 2 2 2 2 2 2 4 4 2 4 2 2 4 2 2 2 2 2 4 2 4 2 2 4 4 4\n", "output": "54\n"}, {"input": "100\n4 2 4 4 2 4 2 2 4 4 4 4 4 4 4 4 4 2 4 4 2 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 2 2 4 4 2 4 2 4 4 4 2 2 2 2 2 2 2 4 2 2 2 4 4 4 2 2 2 2 4 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 2 4 4 4 4 2 4 2 2 4\n", "output": "50\n"}, {"input": "99\n4 3 4 4 4 4 4 3 4 3 3 4 3 3 4 4 3 3 3 4 3 4 3 3 4 3 3 3 3 4 3 4 4 3 4 4 3 3 4 4 4 3 3 3 4 4 3 3 4 3 4 3 4 3 4 3 3 3 3 4 3 4 4 4 4 4 4 3 4 4 3 3 3 3 3 3 3 3 4 3 3 3 4 4 4 4 4 4 3 3 3 3 4 4 4 3 3 4 3\n", "output": "51\n"}, {"input": "100\n3 3 4 4 4 4 4 3 4 4 3 3 3 3 4 4 4 4 4 4 3 3 3 4 3 4 3 4 3 3 4 3 3 3 3 3 3 3 3 4 3 4 3 3 4 3 3 3 4 4 3 4 4 3 3 4 4 4 4 4 4 3 4 4 3 4 3 3 3 4 4 3 3 4 4 3 4 4 4 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 4 3 3 4\n", "output": "51\n"}, {"input": "99\n3 3 4 4 4 2 4 4 3 2 3 4 4 4 2 2 2 3 2 4 4 2 4 3 2 2 2 4 2 3 4 3 4 2 3 3 4 2 3 3 2 3 4 4 3 2 4 3 4 3 3 3 3 3 4 4 3 3 4 4 2 4 3 4 3 2 3 3 3 4 4 2 4 4 2 3 4 2 3 3 3 4 2 2 3 2 4 3 2 3 3 2 3 4 2 3 3 2 3\n", "output": "58\n"}, {"input": "100\n2 2 4 2 2 3 2 3 4 4 3 3 4 4 4 2 3 2 2 3 4 2 3 2 4 3 4 2 3 3 3 2 4 3 3 2 2 3 2 4 4 2 4 3 4 4 3 3 3 2 4 2 2 2 2 2 2 3 2 3 2 3 4 4 4 2 2 3 4 4 3 4 3 3 2 3 3 3 4 3 2 3 3 2 4 2 3 3 4 4 3 3 4 3 4 3 3 4 3 3\n", "output": "61\n"}, {"input": "99\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\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\n", "output": "0\n"}, {"input": "99\n2 2 2 2 2 5 2 2 5 2 5 2 5 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 2 5 5 2 5 2 2 5 2 5 2 2 5 5 2 2 2 2 5 5 2 2 2 5 2 2 5 2 2 2 2 2 5 5 5 5 2 2 5 2 5 2 2 2 2 2 5 2 2 5 5 2 2 2 2 2 5 5 2 2 5 5 2 2 2 2 5 5 5 2 5\n", "output": "48\n"}, {"input": "100\n5 5 2 2 2 2 2 2 5 5 2 5 2 2 2 2 5 2 5 2 5 5 2 5 5 2 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 5 5 5 2 5 5 5 5 5 5 2 2 5 2 2 5 5 5 5 5 2 5 2 5 2 2 2 5 2 5 2 5 5 2 5 5 2 2 5 2 5 5 2 5 2 2 5 2 2 2 5 2 2 2 2 5 5 2 5\n", "output": "38\n"}, {"input": "99\n5 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 5 5 3 5 5 3 3 5 5 5 3 5 3 3 3 3 5 3 3 5 5 3 5 5 5 3 5 3 5 3 5 5 5 5 3 3 3 5 3 5 3 3 3 5 5 5 5 5 3 5 5 3 3 5 5 3 5 5 3 5 5 3 3 5 5 5 3 3 3 5 3 3 3\n", "output": "32\n"}, {"input": "100\n3 3 3 5 3 3 3 3 3 3 5 5 5 5 3 3 3 3 5 3 3 3 3 3 5 3 5 3 3 5 5 5 5 5 5 3 3 5 3 3 5 3 5 5 5 3 5 3 3 3 3 3 3 3 3 3 3 3 5 5 3 5 3 5 5 3 5 3 3 5 3 5 5 5 5 3 5 3 3 3 5 5 5 3 3 3 5 3 5 5 5 3 3 3 5 3 5 5 3 5\n", "output": "32\n"}, {"input": "99\n5 3 5 5 3 3 3 2 2 5 2 5 3 2 5 2 5 2 3 5 3 2 3 2 5 5 2 2 3 3 5 5 3 5 5 2 3 3 5 2 2 5 3 2 5 2 3 5 5 2 5 2 2 5 3 3 5 3 3 5 3 2 3 5 3 2 3 2 3 2 2 2 2 5 2 2 3 2 5 5 5 3 3 2 5 3 5 5 5 2 3 2 5 5 2 5 2 5 3\n", "output": "39\n"}, {"input": "100\n3 5 3 3 5 5 3 3 2 5 5 3 3 3 2 2 3 2 5 3 2 2 3 3 3 3 2 5 3 2 3 3 5 2 2 2 3 2 3 5 5 3 2 5 2 2 5 5 3 5 5 5 2 2 5 5 3 3 2 2 2 5 3 3 2 2 3 5 3 2 3 5 5 3 2 3 5 5 3 3 2 3 5 2 5 5 5 5 5 5 3 5 3 2 3 3 2 5 2 2\n", "output": "42\n"}, {"input": "99\n4 4 4 5 4 4 5 5 4 4 5 5 5 4 5 4 5 5 5 4 4 5 5 5 5 4 5 5 5 4 4 5 5 4 5 4 4 4 5 5 5 5 4 4 5 4 4 5 4 4 4 4 5 5 5 4 5 4 5 5 5 5 5 4 5 4 5 4 4 4 4 5 5 5 4 5 5 4 4 5 5 5 4 5 4 4 5 5 4 5 5 5 5 4 5 5 4 4 4\n", "output": "0\n"}, {"input": "100\n4 4 5 5 5 5 5 5 4 4 5 5 4 4 5 5 4 5 4 4 4 4 4 4 4 4 5 5 5 5 5 4 4 4 4 4 5 4 4 5 4 4 4 5 5 5 4 5 5 5 5 5 5 4 4 4 4 4 4 5 5 4 5 4 4 5 4 4 4 4 5 5 4 5 5 4 4 4 5 5 5 5 4 5 5 5 4 4 5 5 5 4 5 4 5 4 4 5 5 4\n", "output": "1\n"}, {"input": "99\n2 2 2 5 2 2 2 2 2 4 4 5 5 2 2 4 2 5 2 2 2 5 2 2 5 5 5 4 5 5 4 4 2 2 5 2 2 2 2 5 5 2 2 4 4 4 2 2 2 5 2 4 4 2 4 2 4 2 5 4 2 2 5 2 4 4 4 2 5 2 2 5 4 2 2 5 5 5 2 4 5 4 5 5 4 4 4 5 4 5 4 5 4 2 5 2 2 2 4\n", "output": "37\n"}, {"input": "100\n4 4 5 2 2 5 4 5 2 2 2 4 2 5 4 4 2 2 4 5 2 4 2 5 5 4 2 4 4 2 2 5 4 2 5 4 5 2 5 2 4 2 5 4 5 2 2 2 5 2 5 2 5 2 2 4 4 5 5 5 5 5 5 5 4 2 2 2 4 2 2 4 5 5 4 5 4 2 2 2 2 4 2 2 5 5 4 2 2 5 4 5 5 5 4 5 5 5 2 2\n", "output": "31\n"}, {"input": "99\n5 3 4 4 5 4 4 4 3 5 4 3 3 4 3 5 5 5 5 4 3 3 5 3 4 5 3 5 4 4 3 5 5 4 4 4 4 3 5 3 3 5 5 5 5 5 4 3 4 4 3 5 5 3 3 4 4 4 5 4 4 5 4 4 4 4 5 5 4 3 3 4 3 5 3 3 3 3 4 4 4 4 3 4 5 4 4 5 5 5 3 4 5 3 4 5 4 3 3\n", "output": "24\n"}, {"input": "100\n5 4 4 4 5 5 5 4 5 4 4 3 3 4 4 4 5 4 5 5 3 5 5 4 5 5 5 4 4 5 3 5 3 5 3 3 5 4 4 5 5 4 5 5 3 4 5 4 4 3 4 4 3 3 5 4 5 4 5 3 4 5 3 4 5 4 3 5 4 5 4 4 4 3 4 5 3 4 3 5 3 4 4 4 3 4 4 5 3 3 4 4 5 5 4 3 4 4 3 5\n", "output": "19\n"}, {"input": "99\n2 2 5 2 5 3 4 2 3 5 4 3 4 2 5 3 2 2 4 2 4 4 5 4 4 5 2 5 5 3 2 3 2 2 3 4 5 3 5 2 5 4 4 5 4 2 2 3 2 3 3 3 4 4 3 2 2 4 4 2 5 3 5 3 5 4 4 4 5 4 5 2 2 5 4 4 4 3 3 2 5 2 5 2 3 2 5 2 2 5 5 3 4 5 3 4 4 4 4\n", "output": "37\n"}, {"input": "2\n5 2\n", "output": "1\n"}, {"input": "5\n2 2 2 2 2\n", "output": "5\n"}, {"input": "100\n2 3 2 2 2 3 2 3 3 3 3 3 2 3 3 2 2 3 3 2 3 2 3 2 3 4 4 4 3 3 3 3 3 4 4 3 3 4 3 2 3 4 3 3 3 3 2 3 4 3 4 3 3 2 4 4 2 4 4 3 3 3 3 4 3 2 3 4 3 4 4 4 4 4 3 2 2 3 4 2 4 4 4 2 2 4 2 2 3 2 2 4 4 3 4 2 3 3 2 2\n", "output": "61\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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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": "1\n"}, {"input": "100\n5 4 3 5 3 5 4 2 3 3 4 5 4 5 5 4 2 4 2 2 5 2 5 3 4 4 4 5 5 5 3 4 4 4 3 5 3 2 5 4 3 3 3 5 2 3 4 2 5 4 3 4 5 2 2 3 4 4 2 3 3 3 2 5 2 3 4 3 3 3 2 5 4 3 4 5 4 2 5 4 5 2 2 4 2 2 5 5 4 5 2 2 2 2 5 2 4 4 4 5\n", "output": "35\n"}, {"input": "2\n2 2\n", "output": "2\n"}, {"input": "20\n4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5\n", "output": "1\n"}]
302
Prof. Vasechkin wants to represent positive integer n as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the least number of digits 1 in such sum. -----Input----- The first line of the input contains integer n (1 ≀ n < 10^15). -----Output----- Print expected minimal number of digits 1. -----Examples----- Input 121 Output 6
interview
[{"code": "\"\"\"\nCodeforces Testing Round 10 Problem C\n\nAuthor : chaotic_iak\nLanguage: Python 3.3.4\n\"\"\"\n\ndef read(mode=2):\n # 0: String\n # 1: List of strings\n # 2: List of integers\n inputs = input().strip()\n if mode == 0:\n return inputs\n if mode == 1:\n return inputs.split()\n if mode == 2:\n return [int(x) for x in inputs.split()]\n\ndef write(s=\"\\n\"):\n if isinstance(s, list): s = \" \".join(s)\n s = str(s)\n print(s, end=\"\")\n\n################################################### SOLUTION\ndef g(n):\n return (10**n-1)//9\n\ndef solve(n):\n if n <= 6: return n\n if 7 <= n <= 11: return 13-n\n l = 1\n while g(l) < n: l += 1\n l -= 1\n gl = g(l)\n a = n\n res1 = 0\n res1 += (a // gl) * l\n a %= gl\n res1 += solve(a)\n b = g(l+1) - n\n res2 = l+1\n res2 += (b // gl) * l\n b %= gl\n res2 += solve(b)\n return min(res1, res2)\n\nn, = read()\nprint(solve(n))", "passed": true, "time": 0.42, "memory": 14328.0, "status": "done"}, {"code": "n = int(input())\nd = {n: 0}\nu = 10 ** (len(str(n)) + 2) // 9\nfor i in range(len(str(n)) + 1, 0, -1):\n d, e = {}, d\n u //= 10\n for v, c in e.items():\n lim = v//u\n for x in range(-1 - lim, 1 - lim):\n t = v + x * u\n d[t] = min(c + i * abs(x), d.get(t, 999))\nprint(d[0])", "passed": true, "time": 0.15, "memory": 14540.0, "status": "done"}, {"code": "n = int(input())\nd = {n: 0}\nm = len(str(n)) + 1\nu = int('1' * (m+1))\nfor i in range(m, 0, -1):\n d, e, u = {}, d, u // 10\n for v, c in e.items():\n lim = v // u\n for x in range(-1 - lim, 1 - lim):\n t = v + x * u\n d[t] = min(c + i * abs(x), d.get(t, 999))\nprint(d[0])", "passed": true, "time": 0.15, "memory": 14508.0, "status": "done"}, {"code": "ans=1000000000000\nmul = []\n\ndef dfs(now, num, opt):\n\tif num == 0:\n\t\tnonlocal ans \n\t\tans = min(ans, opt)\n\t\treturn\n\tif now == -1:\n\t\treturn\n\ti=-10\n\twhile i * mul[now] <= num:\n\t\ti+=1\n\tdfs(now-1, num-(i-1)*mul[now], opt+abs(i-1)*(now+1))\n\tdfs(now-1, num-i*mul[now], opt+abs(i)*(now+1))\n\ndef main():\n\tmul.append(int(1))\n\tnum = int(input())\n\tfor i in range(1,18,1):\n\t\tmul.append(mul[i-1]*10)\n\tfor i in range(1,18,1):\n\t\tmul[i] += mul[i-1]\n\ti = 1\n\twhile mul[i] <= num:\n\t\ti+=1\n\tn=i\n\tdfs(n, num, 0)\n\tprint(ans)\n\t\t\nmain()", "passed": true, "time": 1.0, "memory": 14388.0, "status": "done"}, {"code": "import math\nacc = []\nn = int(input())\ndef OneNum (num, One):\n onetrans = num // acc[One]\n num = num % acc[One] \n if num == 0:\n return onetrans*One\n else:\n return onetrans*One + min(OneNum(num, One-1), One + OneNum(acc[One] - num, One - 1))\nacc.append(0)\nfor i in range(1,17):\n acc.append (acc[i-1]*10 + 1)\nprint (OneNum(n,16))", "passed": true, "time": 1.08, "memory": 14388.0, "status": "done"}, {"code": "n = int(input())\n\nd = {}\n\ndef count(x):\n\tif x == 0:\n\t\treturn 0\n\telif x in d:\n\t\treturn d[x]\n\n\tx_s = str(x)\n\tlow = int(\"1\"*len(x_s)) if int(\"1\"*len(x_s)) <= x else int(\"1\"*(len(x_s)-1))\n\thigh = int(\"1\"*len(x_s)) if int(\"1\"*len(x_s)) >= x else int(\"1\"*(len(x_s)+1))\n\n\tl_val, h_val = -1, -1\n\tif abs(x - low) < x:\n\t\tl_val = len(str(low)) + count(abs(x - low))\n\tif abs(x - high) < x:\n\t\th_val = len(str(high)) + count(abs(x - high))\n\n\tret = min(l_val, h_val) if min(l_val, h_val) >= 0 else max(l_val, h_val)\n\td[x] = ret\n\treturn ret\n\nprint(count(n))", "passed": true, "time": 0.18, "memory": 14444.0, "status": "done"}, {"code": "one = []\nfor i in range(17):\n one.append(0)\n\n\ndef code():\n i = 1\n j = 0\n k = 0\n one[0] = 0\n for i in range(1, 17):\n one[i] = one[i-1]*10+1\n n = int(input())\n print(df(n, 16))\n\n\ndef df(n, i):\n k = int(n/one[i])\n n %= one[i]\n if n == 0:\n return k*i\n else:\n return k*i+min(i+df(one[i]-n, i-1), df(n, i-1))\n\n\ncode()\n", "passed": true, "time": 1.3, "memory": 14460.0, "status": "done"}, {"code": "multiplos_de_onze = [0, 1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111, 11111111111, \n 111111111111, 1111111111111, 11111111111111, 111111111111111, 1111111111111111, \n 11111111111111111]\n\n\ndef procura_onze(n, i): # i = 16 pois ser\u00e1 as posi\u00e7\u00f5es do vetor decrementadas\n divisao = int(n / multiplos_de_onze[i])\n resto = n % multiplos_de_onze[i]\n if resto == 0:\n return divisao*i\n else:\n return divisao*i + min(i + procura_onze(multiplos_de_onze[i] - resto, i - 1), procura_onze(resto, i - 1))\n\n\ndef divide():\n n = int(input())\n m = procura_onze(n, 16)\n print(m)\n\n\ndivide()", "passed": true, "time": 1.3, "memory": 14388.0, "status": "done"}, {"code": "multiplos_de_onze = [0, 1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111, 11111111111,\n 111111111111, 1111111111111, 11111111111111, 111111111111111, 1111111111111111,\n 11111111111111111]\n# Entrada maxima, n maior que 1 e n menor que 10 elevado a 15\n\n\ndef procura_onze(n, i): # i = 16 - pois ser\u00e1 a ultima posi\u00e7\u00e3o do vetor\n divisao = int(n / multiplos_de_onze[i])\n resto = n % multiplos_de_onze[i]\n if resto == 0:\n return divisao*i\n else:\n return divisao*i + min(i + procura_onze(multiplos_de_onze[i] - resto, i - 1), procura_onze(resto, i - 1))\n\n\ndef divide():\n n = int(input())\n m = procura_onze(n, 16)\n print(m)\n\n\ndivide()\n", "passed": true, "time": 1.29, "memory": 14484.0, "status": "done"}, {"code": "n = int(input())\n\nd = {n: 0}\n\nu = 10 ** (len(str(n)) + 2) // 9\n\nfor i in range(len(str(n)) + 1, 0, -1):\n\n d, e = {}, d\n\n u //= 10\n\n for v, c in list(e.items()):\n\n lim = v//u\n\n for x in range(-1 - lim, 1 - lim):\n\n t = v + x * u\n\n d[t] = min(c + i * abs(x), d.get(t, 999))\n\nprint(d[0])\n\n\n\n# Made By Mostafa_Khaled\n", "passed": true, "time": 0.18, "memory": 14472.0, "status": "done"}, {"code": "class OneArithmetic():\n def __init__(self, n):\n self.n = n\n self.m = [0]*17\n v = 0\n for i in range(1,17):\n v = 10*v+1\n self.m[i] = v\n\n def dfs(self, v, d):\n v = abs(v)\n if d == 1:\n return v\n elif v == 0:\n return 0\n else:\n k = int(v/self.m[d])\n ans = min( self.dfs( v - k * self.m[d] , d - 1 ) + k * d , self.dfs( ( k + 1 ) * self.m[d] - v , d - 1 ) + ( k + 1 ) * d )\n return ans\n\n def min_digits(self):\n v = self.dfs(self.n,16)\n return v\n\n\nn = int(input())\nprint(OneArithmetic(n).min_digits())\n", "passed": true, "time": 1.57, "memory": 14412.0, "status": "done"}]
[{"input": "121\n", "output": "6\n"}, {"input": "10\n", "output": "3\n"}, {"input": "72\n", "output": "15\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": "7\n", "output": "6\n"}, {"input": "11\n", "output": "2\n"}, {"input": "12\n", "output": "3\n"}, {"input": "2038946593\n", "output": "145\n"}, {"input": "81924761239462\n", "output": "321\n"}, {"input": "973546235465729\n", "output": "263\n"}, {"input": "999999999999999\n", "output": "32\n"}, {"input": "21\n", "output": "5\n"}, {"input": "79\n", "output": "10\n"}, {"input": "33\n", "output": "6\n"}, {"input": "185\n", "output": "16\n"}, {"input": "513\n", "output": "25\n"}, {"input": "634\n", "output": "22\n"}, {"input": "5300\n", "output": "32\n"}, {"input": "3724\n", "output": "34\n"}, {"input": "2148\n", "output": "21\n"}, {"input": "82415\n", "output": "53\n"}, {"input": "35839\n", "output": "45\n"}, {"input": "79263\n", "output": "45\n"}, {"input": "274634\n", "output": "62\n"}, {"input": "690762\n", "output": "65\n"}, {"input": "374186\n", "output": "65\n"}, {"input": "2673749\n", "output": "81\n"}, {"input": "5789877\n", "output": "61\n"}, {"input": "1873301\n", "output": "59\n"}, {"input": "30272863\n", "output": "118\n"}, {"input": "33388991\n", "output": "57\n"}, {"input": "11472415\n", "output": "72\n"}, {"input": "345871978\n", "output": "95\n"}, {"input": "528988106\n", "output": "118\n"}, {"input": "302038826\n", "output": "128\n"}, {"input": "1460626450\n", "output": "152\n"}, {"input": "3933677170\n", "output": "159\n"}, {"input": "6816793298\n", "output": "153\n"}, {"input": "75551192860\n", "output": "151\n"}, {"input": "28729276284\n", "output": "212\n"}, {"input": "67612392412\n", "output": "178\n"}, {"input": "532346791975\n", "output": "158\n"}, {"input": "575524875399\n", "output": "189\n"}, {"input": "614407991527\n", "output": "236\n"}, {"input": "2835997166898\n", "output": "275\n"}, {"input": "1079175250322\n", "output": "188\n"}, {"input": "8322353333746\n", "output": "169\n"}, {"input": "26602792766013\n", "output": "288\n"}, {"input": "42845970849437\n", "output": "325\n"}, {"input": "59089148932861\n", "output": "265\n"}, {"input": "842369588365127\n", "output": "330\n"}, {"input": "768617061415848\n", "output": "390\n"}, {"input": "694855944531976\n", "output": "348\n"}, {"input": "898453513288965\n", "output": "248\n"}, {"input": "98596326741327\n", "output": "260\n"}, {"input": "59191919191919\n", "output": "342\n"}]
303
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure. Bottle with potion has two values x and y written on it. These values define four moves which can be performed using the potion: $(a, b) \rightarrow(a + x, b + y)$ $(a, b) \rightarrow(a + x, b - y)$ $(a, b) \rightarrow(a - x, b + y)$ $(a, b) \rightarrow(a - x, b - y)$ Map shows that the position of Captain Bill the Hummingbird is (x_1, y_1) and the position of the treasure is (x_2, y_2). You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes). The potion can be used infinite amount of times. -----Input----- The first line contains four integer numbers x_1, y_1, x_2, y_2 ( - 10^5 ≀ x_1, y_1, x_2, y_2 ≀ 10^5) β€” positions of Captain Bill the Hummingbird and treasure respectively. The second line contains two integer numbers x, y (1 ≀ x, y ≀ 10^5) β€” values on the potion bottle. -----Output----- Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes). -----Examples----- Input 0 0 0 6 2 3 Output YES Input 1 1 3 6 1 5 Output NO -----Note----- In the first example there exists such sequence of moves: $(0,0) \rightarrow(2,3)$ β€” the first type of move $(2,3) \rightarrow(0,6)$ β€” the third type of move
interview
[{"code": "x1, y1, x2, y2 = list(map(int, input().split()))\nx, y = list(map(int, input().split()))\n\nx, y = abs(x), abs(y)\n\nx_ = abs(x2 - x1)\ny_ = abs(y2 - y1)\n\nif x_ % x == 0 and y_ % y == 0:\n if (x_ // x + y_ // y) % 2 == 0:\n print(\"YES\")\n else:\n print(\"NO\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "x1, y1, x2, y2 = map(int, input().split())\nx, y = map(int, input().split())\n\nx, y = abs(x), abs(y)\n\nx_ = abs(x2 - x1)\ny_ = abs(y2 - y1)\n\nif x_ % x == 0 and y_ % y == 0:\n if (x_ // x + y_ // y) % 2 == 0:\n print(\"YES\")\n else:\n print(\"NO\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.25, "memory": 14396.0, "status": "done"}, {"code": "x1, y1, x2, y2 = map(int, input().split())\na, b = map(int, input().split())\nif not abs(x1 - x2) % a and not abs(y1 - y2) % b and (abs(x1 - x2) // a) % 2 == (abs(y1 - y2) // b) % 2:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.16, "memory": 14276.0, "status": "done"}, {"code": "x1, y1, x2, y2 = map(int, input().split())\na, b = map(int, input().split())\n\nx = (x1 - x2) / a\ny = (y1 - y2) / b\n\nif x == int(x) and y == int(y) and int(x) & 1 == int(y) & 1:\n\tprint('YES')\nelse:\n\tprint('NO')", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "x1, y1, x2, y2 = map(int, input().split())\na, b = map(int, input().split()) #\nif not abs(x1 - x2) % a and not abs(y1 - y2) % b and (abs(x1 - x2) // a) % 2 == (abs(y1 - y2) // b) % 2:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.15, "memory": 14252.0, "status": "done"}, {"code": "x1,y1,x2,y2 = list(map(int,input().split()))\nx,y = list(map(int,input().split()))\nif (x2 - x1) % x == 0 and (y2 - y1) % y == 0:\n if ((x2 - x1) // x - ((y2 - y1) // y)) % 2 == 0:\n print(\"YES\")\n else:\n print(\"NO\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14320.0, "status": "done"}, {"code": "x1, y1, x2, y2 = map(int, input().split())\na, b = map(int, input().split())\n\nx = (x1 - x2) / a\ny = (y1 - y2) / b\n\nif x == int(x) and y == int(y) and (int(x) & 1 == int(y) & 1):\n\tprint('YES')\nelse:\n\tprint('NO')", "passed": true, "time": 0.15, "memory": 14360.0, "status": "done"}, {"code": "x1, y1, x2, y2 = list(map(int, input().split()))\nx, y = list(map(int, input().split()))\n\nx, y = abs(x), abs(y)\n\nx_ = abs(x2 - x1)\ny_ = abs(y2 - y1)\n\nif (x == 0 or x_ % x == 0) and (y == 0 or y_ % y == 0):\n if x == 0 or y == 0:\n print(\"YES\")\n if (x_ // x + y_ // y) % 2 == 0:\n print(\"YES\")\n else:\n print(\"NO\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}, {"code": "x1, y1, x2, y2 = list(map(int, input().split()))\nx, y = list(map(int, input().split()))\n\na = (x2 - x1) // x\nb = (y2 - y1) // y\n\nif a % 2 == b % 2 and (x2 - x1) % x == 0 and (y2 - y1) % y == 0:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n", "passed": true, "time": 0.24, "memory": 14372.0, "status": "done"}, {"code": "x1, y1, x2, y2 = [int(i) for i in input().split()]\nx, y = [int(i) for i in input().split()]\n\ndx = abs(x2 - x1)\ndy = abs(y2 - y1)\n\nif dx % x != 0 or dy % y != 0:\n print(\"NO\")\nelse:\n kx = dx // x\n ky = dy // y\n\n if (kx % 2) == (ky % 2):\n print(\"YES\")\n else:\n print(\"NO\")\n\n", "passed": true, "time": 0.25, "memory": 14324.0, "status": "done"}, {"code": "x1, y1, x2, y2 = list(map(int, input().split()))\nx, y = list(map(int, input().split()))\n\nx, y = abs(x), abs(y)\n\nx_ = abs(x2 - x1)\ny_ = abs(y2 - y1)\n\nif (x == 0 or x_ % x == 0) and (y == 0 or y_ % y == 0):\n if x == 0 or y == 0:\n print(\"YES\")\n if (x_ // x + y_ // y) % 2 == 0:\n print(\"YES\") # kek\n else:\n print(\"NO\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.16, "memory": 14400.0, "status": "done"}, {"code": "x1, y1, x2, y2 = [int(i) for i in input().split(' ')]\na, b = [int(i) for i in input().split(' ')]\n\ndx = abs(x1 - x2)\ndy = abs(y1 - y2)\n\nif dx % a == 0 and dy % b == 0 and (dx / a) % 2 == (dy / b) % 2:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.23, "memory": 14324.0, "status": "done"}, {"code": "x1, y1, x2, y2 = list(map(int, input().split()))\nx, y = list(map(int, input().split()))\ndx, dy = x1-x2, y1-y2\nif dx%x == 0 and dy%y == 0 and (dx//x + dy//y)%2 == 0:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.14, "memory": 14540.0, "status": "done"}, {"code": "a,b,c,d=map(int,input().split())\nx,y=map(int,input().split())\nr=c-a\nt=d-b\nif r%x==0 and t%y==0 and (r//x-t//y)%2==0:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14408.0, "status": "done"}, {"code": "x1, y1, x2, y2 = list(map(int, input().split()))\nx, y = list(map(int, input().split()))\nx0, y0 = x2 - x1, y2 - y1\nx0, y0 = abs(x0), abs(y0)\nfor a in range(- 2 * 10 ** 5, 2 * 10 ** 5 + 1):\n\tif x0 % x == 0:\n\t\tb = x0 // x - a\n\t\tif a * y - b * y == y0:\n\t\t\tprint('YES')\n\t\t\treturn\nprint('NO')\n", "passed": true, "time": 3.05, "memory": 14296.0, "status": "done"}, {"code": "a, b, c, d = list(map(int, input().split()))\nx, y = list(map(int, input().split()))\n\nif abs(c - a) % abs(x) == 0 and abs(c - a) / abs(x) % 2 == abs(d - b) / abs(y) % 2 and abs(d - b) % abs(y) == 0:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n", "passed": true, "time": 0.15, "memory": 14300.0, "status": "done"}, {"code": "## 1\n\ninp = list(map(int, input().split()))\nx1, y1, x2, y2 = [inp[i] for i in range(4)]\ninp = list(map(int, input().split()))\nx, y = inp[0], inp[1]\nd1 = x2 - x1\nd2 = y2 - y1\nif d1%x==0 and (int(d1/x)+int(d2/y))%2==0 and d2%y==0:\n print('YES')\nelse: print('NO')\n \n", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "inp=input().split()\nx1=int(inp[0])\ny1=int(inp[1])\nx2=int(inp[2])\ny2=int(inp[3])\ninp=input().split()\nx=int(inp[0])\ny=int(inp[1])\nif(abs(x2-x1)%x==0 and abs(y2-y1)%y==0):\n\tval1=abs(x2-x1)//x\n\tval2=abs(y2-y1)//y \t\n\tif(abs(val2-val1)%2==0):\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\")\nelse:\n\tprint(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14488.0, "status": "done"}, {"code": "x1, y1, x2, y2 = list(map(int, input().split()))\nx, y = list(map(int, input().split()))\n\nif abs(x1 - x2) % x != 0 or abs(y1 - y2) % y != 0:\n print('NO')\nelse:\n a = abs(x1 - x2) / x\n b = abs(y1 - y2) / y\n if a % 2 == b % 2:\n print('YES')\n else:\n print('NO')\n", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "x1, y1, x2, y2 = map(int, input().split())\nx, y = map(int, input().split())\n\ndeltaX = abs(x2-x1)\ndeltaY = abs(y2-y1)\n\n# if (deltaY // y) == (deltaX // x):\n# \tprint(\"YES\")\n# elif (deltaY // x) == (deltaX // y):\n# \tprint(\"YES\")\n# elif (deltaX % x == 0) and (deltaY == 0):\n# \tprint(\"YES\")\n# elif (deltaY % y == 0) and (deltaX == 0):\n# \tprint(\"YES\")\n# elif deltaX == deltaY == 0:\n# \tprint(\"YES\")\n# else:\n# \tprint(\"NO\")\n\nif ((y2-y1)%(2*y) == 0) and ((x2-x1)%(2*x) == 0):\n\tprint(\"YES\")\nelif ((x2-x-x1)%(2*x) == 0) and ((y2-y-y1)%(2*y) == 0):\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")", "passed": true, "time": 0.15, "memory": 14576.0, "status": "done"}, {"code": "\nline1 = input()\nline2 = input()\n\ncoords = list( map(int, line1.split()) )\nv1, v2 = list( map(int, line2.split()) )\n\ndx = coords[2] - coords[0]\ndy = coords[3] - coords[1]\n\nif dx % v1 == 0 and dy % v2 == 0 and \\\n (dx // v1 - dy // v2) % 2 == 0:\n print ('YES')\nelse:\n print ('NO')\n\n\n\n", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "def main():\n x1, y1, x2, y2 = list(map(int, input().split()))\n x, y = list(map(int, input().split()))\n\n if abs(x2 - x1) % x or abs(y2 - y1) % y:\n print('NO')\n return\n\n if (abs(x2 - x1) // x + abs(y2 - y1) // y) % 2 == 0:\n print('YES')\n else:\n print('NO')\n\nmain()\n", "passed": true, "time": 0.24, "memory": 14268.0, "status": "done"}, {"code": "a,b,c,d=input().strip().split(' ')\nx1,y1,x2,y2=(int(a),int(b),int(c),int(d))\nx,y=input().strip().split(' ')\nx,y=(int(x),int(y))\nif (x2-x1)%x==0 and (y2-y1)%y==0:\n a1=(x2-x1)//x\n a2=(y2-y1)//y\n if (a1%2==0 and a2%2==0) or (a1%2==1 and a2%2==1):\n print(\"YES\")\n return\nprint(\"NO\")", "passed": true, "time": 0.14, "memory": 14320.0, "status": "done"}, {"code": "def main():\n x1, y1, x2, y2 = list(map(int, input().split()))\n a, b = list(map(int, input().split()))\n\n xd = x2 - x1\n yd = y2 - y1\n\n if xd % a != 0 or yd % b != 0:\n print('NO')\n return\n\n xd /= a\n yd /= b\n\n print(\"YES\" if (xd % 2) == (yd % 2) else \"NO\")\n\nmain()\n", "passed": true, "time": 0.15, "memory": 14360.0, "status": "done"}]
[{"input": "0 0 0 6\n2 3\n", "output": "YES\n"}, {"input": "1 1 3 6\n1 5\n", "output": "NO\n"}, {"input": "5 4 6 -10\n1 1\n", "output": "NO\n"}, {"input": "6 -3 -7 -7\n1 2\n", "output": "NO\n"}, {"input": "2 -5 -8 8\n2 1\n", "output": "YES\n"}, {"input": "70 -81 -17 80\n87 23\n", "output": "YES\n"}, {"input": "41 366 218 -240\n3456 1234\n", "output": "NO\n"}, {"input": "-61972 -39646 -42371 -24854\n573 238\n", "output": "NO\n"}, {"input": "-84870 -42042 94570 98028\n8972 23345\n", "output": "YES\n"}, {"input": "-58533 -50999 -1007 -59169\n8972 23345\n", "output": "NO\n"}, {"input": "-100000 -100000 100000 100000\n100000 100000\n", "output": "YES\n"}, {"input": "-100000 -100000 100000 100000\n1 1\n", "output": "YES\n"}, {"input": "5 2 5 3\n1 1\n", "output": "NO\n"}, {"input": "5 5 5 5\n5 5\n", "output": "YES\n"}, {"input": "0 0 1000 1000\n1 1\n", "output": "YES\n"}, {"input": "0 0 0 1\n1 1\n", "output": "NO\n"}, {"input": "1 1 4 4\n2 2\n", "output": "NO\n"}, {"input": "100000 100000 99999 99999\n100000 100000\n", "output": "NO\n"}, {"input": "1 1 1 6\n1 5\n", "output": "NO\n"}, {"input": "2 9 4 0\n2 3\n", "output": "YES\n"}, {"input": "0 0 0 9\n2 3\n", "output": "NO\n"}, {"input": "14 88 14 88\n100 500\n", "output": "YES\n"}, {"input": "-1 0 3 0\n4 4\n", "output": "NO\n"}, {"input": "0 0 8 9\n2 3\n", "output": "NO\n"}, {"input": "-2 5 7 -6\n1 1\n", "output": "YES\n"}, {"input": "3 7 -8 8\n2 2\n", "output": "NO\n"}, {"input": "-4 -8 -6 -1\n1 3\n", "output": "NO\n"}, {"input": "0 8 6 2\n1 1\n", "output": "YES\n"}, {"input": "-5 -2 -8 -2\n1 1\n", "output": "NO\n"}, {"input": "1 4 -5 0\n1 1\n", "output": "YES\n"}, {"input": "8 -4 4 -7\n1 2\n", "output": "NO\n"}, {"input": "5 2 2 4\n2 2\n", "output": "NO\n"}, {"input": "2 0 -4 6\n1 2\n", "output": "NO\n"}, {"input": "-2 6 -5 -4\n1 2\n", "output": "YES\n"}, {"input": "-6 5 10 6\n2 4\n", "output": "NO\n"}, {"input": "3 -7 1 -8\n1 2\n", "output": "NO\n"}, {"input": "4 1 4 -4\n9 4\n", "output": "NO\n"}, {"input": "9 -3 -9 -3\n2 2\n", "output": "NO\n"}, {"input": "-6 -6 -10 -5\n6 7\n", "output": "NO\n"}, {"input": "-5 -2 2 2\n1 7\n", "output": "NO\n"}, {"input": "9 0 8 1\n7 10\n", "output": "NO\n"}, {"input": "-1 6 -7 -6\n6 4\n", "output": "YES\n"}, {"input": "2 2 -3 -3\n3 1\n", "output": "NO\n"}, {"input": "2 -6 7 2\n2 1\n", "output": "NO\n"}, {"input": "-6 2 -7 -7\n1 2\n", "output": "NO\n"}, {"input": "-5 -5 -1 -5\n2 2\n", "output": "YES\n"}, {"input": "0 5 3 -6\n2 2\n", "output": "NO\n"}, {"input": "0 -6 2 -1\n1 1\n", "output": "NO\n"}, {"input": "-6 6 -5 -4\n1 2\n", "output": "YES\n"}, {"input": "7 -7 1 -7\n2 2\n", "output": "NO\n"}, {"input": "99966 -99952 -99966 99923\n1 1\n", "output": "NO\n"}, {"input": "99921 99980 -99956 -99907\n3 4\n", "output": "NO\n"}, {"input": "100000 100000 -100000 -100000\n1 1\n", "output": "YES\n"}, {"input": "1 0 2 0\n5 1\n", "output": "NO\n"}, {"input": "-3 0 -8 0\n7 2\n", "output": "NO\n"}, {"input": "-9 4 -5 -1\n8 2\n", "output": "NO\n"}, {"input": "-99999 -100000 100000 100000\n1 1\n", "output": "NO\n"}, {"input": "0 0 -100 -100\n2 2\n", "output": "YES\n"}, {"input": "9 -5 -3 -2\n1 4\n", "output": "NO\n"}, {"input": "1 -10 -10 5\n7 5\n", "output": "NO\n"}, {"input": "6 -9 -1 -9\n1 9\n", "output": "NO\n"}]
304
This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious eitherΒ β€” although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all. In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number $n$. In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too. Given $n$, determine the total number of possible bus number variants. -----Input----- The first line contains one integer $n$ ($1 \leq n \leq 10^{18}$)Β β€” the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with $0$. -----Output----- Output a single integerΒ β€” the amount of possible variants of the real bus number. -----Examples----- Input 97 Output 2 Input 2028 Output 13 -----Note----- In the first sample, only variants $97$ and $79$ are possible. In the second sample, the variants (in the increasing order) are the following: $208$, $280$, $802$, $820$, $2028$, $2082$, $2208$, $2280$, $2802$, $2820$, $8022$, $8202$, $8220$.
interview
[{"code": "n=input()\nrg=[0]*10\nfor i in n: rg[int(i)]+=1\nrl=[]\nff=0\nfor i in range(len(rg)):\n if rg[i]!=0:\n rl.append(rg[i])\n if i==0: ff=1\nfact=[1]\nfc=1\nfor i in range(1,20):\n fc*=i\n fact.append(fc)\nrt=[]\nt=0\ndef cfs(d):\n if d==len(rl):\n nonlocal t,ff\n jj=fact[sum(rt)]\n for i in rt: jj=jj/fact[i]\n if ff:\n jjj=fact[sum(rt)-1]\n jjj=jjj/fact[rt[0]-1]\n for i in range(1,len(rt)): jjj=jjj/fact[rt[i]]\n jj-=jjj\n t+=jj\n return\n \n for i in range(1,rl[d]+1):\n rt.append(i)\n cfs(d+1)\n rt.pop(-1)\n\ncfs(0)\nprint(int(t))\n\n\n \n \n \n\n'''\n//////////////// ////// /////// // /////// // // //\n//// // /// /// /// /// // /// /// //// //\n//// //// /// /// /// /// // ///////// //// ///////\n//// ///// /// /// /// /// // /// /// //// // //\n////////////// /////////// /////////// ////// /// /// // // // //\n'''\n\n", "passed": true, "time": 0.23, "memory": 14580.0, "status": "done"}, {"code": "N = input()\n\nC = [0]*10\nfor n in N:\n C[int(n)] += 1\n\nmemo = {}\ndef dfs(i, state):\n key = tuple(state)\n if key in memo:\n return memo[key]\n r = 0\n if all(s == 0 or 1 <= t for s, t in zip(C, state)):\n r += 1\n for j in range(10):\n if C[j] - state[j] > 0:\n state[j] += 1\n r += dfs(i+1, state)\n state[j] -= 1\n memo[key] = r\n return r\nstate = [0]*10\nans = 0\nfor i in range(1, 10):\n if C[i] > 0:\n state[i] += 1\n ans += dfs(1, state)\n state[i] -= 1\nprint(ans)", "passed": true, "time": 1.65, "memory": 61408.0, "status": "done"}, {"code": "from collections import Counter\nfrom itertools import product\n\ns = input()\n\nds = Counter(s)\n\n\nfac = [1 for i in range(100)]\nfor i in range(1, 100):\n fac[i] = fac[i-1] * i\n\nres = 0\nfor possib in product(*[list(zip([k] * n, list(range(1, n+1)))) for k, n in list(ds.items())]):\n possib = list(possib)\n non_zero_sum = sum(v for k, v in possib if k != '0')\n total = sum(v for _, v in possib)\n\n value = non_zero_sum * fac[total-1]\n for _, v in possib:\n value //= fac[v]\n\n res += value\nprint(res)\n", "passed": true, "time": 0.16, "memory": 14416.0, "status": "done"}, {"code": "import itertools as it\nS=input().strip()\nfreq=[0 for i in range(10)]\nfor i in S:\n u=ord(i)-ord('0')\n freq[u]+=1\n\nfac=[1]\nfor i in range(1,20): fac.append(i*fac[-1])\n\n\"\"\"\nM={}\ndef F(cur,used):\n while cur<10 and freq[cur]==0: cur+=1\n if cur==10:\n r=fac[sum(used)]\n for i in used:\n r//=fac[i]\n print(used)\n return 1\n\n key=(cur,tuple(used))\n if key in M: return M[key]\n \n r=0\n for i in range(1,freq[cur]):\n for j in range(\n return r\n\ntotal=0\nfor i in range(1,10):\n if freq[i]==0: continue\n M={}\n freq[i]-=1\n used=[0 for j in range(10)]\n used[i]=1\n total+=F(0,used)\n freq[i]+=1\n\nprint(total)\n\"\"\"\n\ntotal=0\nfor x in it.product(*(list(range(0 if i==0 else 1,i+1)) for i in freq)):\n Q=\"\".join(str(i)*x[i] for i in range(10))\n s=sum(x)-1\n if s<0: continue\n g=0\n for d in range(1,10):\n n=fac[s]\n y=list(x)\n y[d]-=1\n #assert(s==sum(y))\n for k in range(0,10):\n n//=fac[y[k]]\n g+=n\n #print(x,d,n,g)\n #print(Q,x,g)\n total+=g\n\nprint(total)\n\n#208\n#280\n#802\n#820\n#2028, 2082, 2208, 2280, 2802, 2820\n#8022, 8202, 8220\n", "passed": true, "time": 0.21, "memory": 14572.0, "status": "done"}, {"code": "import itertools as it\n\n\ndef factorial(n):\n i = 1\n for j in range(1, n + 1):\n i *= j\n return i\n\n\ndef C(n, k):\n k = max([k, n - k])\n result = 1\n for i in range(k + 1, n + 1):\n result *= i\n result //= factorial(n - k)\n return result\n\n\n\nn = input()\n\n\ndigits = [0 for _ in range(10)]\n\nfor i in n:\n digits[int(i)] += 1\n\nresult = 0\n\nfor amounts in it.product(*[[0] if x == 0 else list(range(1, x + 1)) for x in digits]):\n sum_no_zero = sum(amounts[1:])\n if sum_no_zero == 0:\n continue\n #print(amounts)\n tmp = factorial(sum_no_zero)\n for j in amounts[1:]:\n tmp //= factorial(j)\n tmp *= C(sum_no_zero + amounts[0] - 1, amounts[0])\n result += tmp\n\n\nprint(result)\n", "passed": true, "time": 0.25, "memory": 14348.0, "status": "done"}, {"code": "n=int(input())\nt=[]\na=[]\nfor i in range(10):\n t.append(0)\n a.append(1)\nwhile n:\n a[n%10]+=1\n n//=10\nans=0\nfor i in range(a[0]!=1,a[0]):\n t[0]=i\n for i in range(a[1]!=1,a[1]):\n t[1]=i\n for i in range(a[2]!=1,a[2]):\n t[2]=i\n for i in range(a[3]!=1,a[3]):\n t[3]=i\n for i in range(a[4]!=1,a[4]):\n t[4]=i\n for i in range(a[5]!=1,a[5]):\n t[5]=i\n for i in range(a[6]!=1,a[6]):\n t[6]=i\n for i in range(a[7]!=1,a[7]):\n t[7]=i\n for i in range(a[8]!=1,a[8]):\n t[8]=i\n for i in range(a[9]!=1,a[9]):\n t[9]=i\n s=0\n for i in range(10):\n s+=t[i]\n w=1\n cnt=s\n for i in range(10):\n for j in range(t[i]):\n if i==0:w*=cnt-1\n else:w*=cnt\n cnt-=1\n for i in range(10):\n for j in range(1,t[i]+1):\n w//=j\n #print(w)\n ans+=w\nprint(ans)\n", "passed": true, "time": 0.31, "memory": 14480.0, "status": "done"}, {"code": "n = int(input())\ns = str(n)\n\nans = 0\na = [s.count(str(digit)) for digit in range(10)]\n\nfrom math import factorial\nfrom functools import reduce\nfrom operator import mul\n\ndef get(*args):\n\tres = factorial(sum(args))\n\tfor x in args:\n\t\tres //= factorial(x)\n\treturn res\n\nfor a0 in range(0 if not a[0] else 1, a[0] + 1):\n\tfor a1 in range(0 if not a[1] else 1, a[1] + 1):\n\t\tfor a2 in range(0 if not a[2] else 1, a[2] + 1):\n\t\t\tfor a3 in range(0 if not a[3] else 1, a[3] + 1):\n\t\t\t\tfor a4 in range(0 if not a[4] else 1, a[4] + 1):\n\t\t\t\t\tfor a5 in range(0 if not a[5] else 1, a[5] + 1):\n\t\t\t\t\t\tfor a6 in range(0 if not a[6] else 1, a[6] + 1):\n\t\t\t\t\t\t\tfor a7 in range(0 if not a[7] else 1, a[7] + 1):\n\t\t\t\t\t\t\t\tfor a8 in range(0 if not a[8] else 1, a[8] + 1):\n\t\t\t\t\t\t\t\t\tfor a9 in range(0 if not a[9] else 1, a[9] + 1):\n\t\t\t\t\t\t\t\t\t\tans += get(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)\n\t\t\t\t\t\t\t\t\t\tif a0:\n\t\t\t\t\t\t\t\t\t\t\tans -= get(a0 - 1, a1, a2, a3, a4, a5, a6, a7, a8, a9)\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14596.0, "status": "done"}, {"code": "3\n\ndef enc(t):\n v = 0\n for x in t:\n v *= 20\n v += x\n return v\n\n\ndef dec(v, N):\n a = []\n for _ in range(N):\n a.append(v % 20)\n v //= 20\n a.reverse()\n return a\n\n\ndef cnt(C, ld, ud):\n N = len(C)\n\n ans = 0\n\n dp = {enc([0] * N): 1}\n for rnd in range(ud):\n if rnd >= ld:\n for et in dp:\n c = dp[et]\n t = dec(et, N)\n if ((C[0] == 0 and all([t[i] >= 1 for i in range(1, N)]))\n or (C[0] > 0 and all([t[i] >= 1 for i in range(N)]))):\n ans += c\n\n ndp = {}\n\n for et in dp:\n t = dec(et, N)\n c = dp[et]\n\n for i in range(N):\n if rnd == 0 and i == 0:\n continue\n if t[i] < C[i]:\n l = list(t)\n l[i] += 1\n nt = enc(l)\n if nt not in ndp:\n ndp[nt] = 0\n ndp[nt] += c\n\n dp = ndp\n\n for et in dp:\n c = dp[et]\n t = dec(et, N)\n if ((C[0] == 0 and all([t[i] >= 1 for i in range(1, N)]))\n or (C[0] > 0 and all([t[i] >= 1 for i in range(N)]))):\n ans += c\n\n return ans\n\n\ndef solve(S):\n N = len(S)\n C = [0] * 10\n for c in S:\n C[ord(c) - ord('0')] += 1\n\n mindigits = len([c for c in C if c > 0])\n\n C = [C[0]] + [C[i] for i in range(1, 10) if C[i] > 0]\n\n return cnt(C, mindigits, N)\n\n\ndef main():\n S = input()\n print(solve(S))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 5.94, "memory": 14740.0, "status": "done"}, {"code": "n = input()\nfacts = {0: 1}\n\ndef fact(a):\n\tnonlocal facts\n\tif a in facts:\n\t\treturn facts[a]\n\tres = 1\n\tfor i in range(1, a+1):\n\t\tres *= i\n\t\tfacts[i] = res\n\treturn facts[a]\n\nocc = [0] * 10\nfor i in range(len(n)):\n\tocc[int(n[i])] += 1\n\nans = 0\n\ndef go_find(hame, start):\n#\tprint(\"Start: \" + str(start))\n#\tprint(hame)\n\tnonlocal ans\n\tif hame[0] == 0:\n\t\tres = fact(sum(hame))\n\t\tfor i in range(10):\n\t\t\tres //= fact(hame[i])\n\telse:\n\t\tres2 = fact(sum(hame)-1)\n\t\tfor i in range(1, 10):\n\t\t\tres2 //= fact(hame[i])\n\t\tres2 //= fact(hame[0]-1)\n\t\t\n\t\tres = fact(sum(hame))\n\t\tfor i in range(10):\n\t\t\tres //= fact(hame[i])\n\n\t\tres -= res2\n\n#\tprint(res)\n#\tprint(\"=============\")\n\tans += res\n\tfor i in range(start, 10):\n\t\tif hame[i] > 1:\n\t\t\thame[i] -= 1\n\t\t\tgo_find(hame, i)\n\t\t\thame[i] += 1\n\ngo_find(occ, 0)\nprint(ans)\n\t\n\n", "passed": true, "time": 0.18, "memory": 14380.0, "status": "done"}, {"code": "s = input()\ncnt = [0 for i in range(10)]\nfor c in s:\n\tcnt[ord(c) - ord('0')] += 1\ndp = [0 for i in range(20)]\t\ndp[0] = 1\ncomb = [[0 for i in range(40)] for j in range(40)]\nfor i in range(40):\n\tfor j in range(i + 1):\n\t\tif i == j or j == 0:\n\t\t\tcomb[i][j] = 1\n\t\telse:\n\t\t\tcomb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1]\n\nfor dig in [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]:\n\tif cnt[dig] == 0:\n\t\tcontinue\n\todp = dp\n\tdp = [0] * 20\n\tfor lsz in range(20):\n\t\tfor pick in range(1, cnt[dig] + 1):\n\t\t\tif (lsz + pick < 20):\n\t\t\t\tm = lsz + (dig != 0) + pick - 1\n\t\t\t\tr = lsz + (dig != 0) - 1\n\t\t\t\tways = 0\n\t\t\t\tif (m == r):\n\t\t\t\t\tways = 1\n\t\t\t\telif (r > m or r < 0 or m < 0):\n\t\t\t\t\tways = 0\n\t\t\t\telse:\n\t\t\t\t\tways = comb[m][r]\n\t\t\t\tdp[lsz + pick] += odp[lsz] * ways\n\nres = 0\nfor i in range(1, 20):\n\tres += dp[i]\nprint(res)\n\n", "passed": true, "time": 0.17, "memory": 14364.0, "status": "done"}, {"code": "from collections import defaultdict as dd\nfrom math import factorial as f\n\ns = input()\n\ncnt = dd(int)\n\nfor i in s:\n cnt[i] += 1\n\nans = 0\n\ndef calc(cur_chr, dem, do_not_take_sum, total, diff):\n nonlocal ans\n nonlocal cnt\n\n if cur_chr == '9':\n for do_not_take in range(0, cnt[cur_chr] + 1):\n if do_not_take > 0 and do_not_take == cnt[cur_chr]:\n continue\n\n cur_do_not_take_sum = do_not_take_sum + do_not_take\n if cur_do_not_take_sum == total:\n continue\n\n cur_dem = dem * f(cnt[cur_chr] - do_not_take)\n num = f(total - cur_do_not_take_sum)\n\n ans += num // cur_dem * diff\n return\n\n for do_not_take in range(0, cnt[cur_chr] + 1):\n if do_not_take > 0 and do_not_take == cnt[cur_chr]:\n if not(diff == -1 and cur_chr == '0'):\n continue\n calc(chr(ord(cur_chr) + 1), dem * f(cnt[cur_chr] - do_not_take), do_not_take_sum + do_not_take, total, diff)\n\ncalc('0', 1, 0, len(s), 1)\n\nif cnt['0'] != 0:\n cnt['0'] -= 1\n calc('0', 1, 0, len(s) - 1, -1)\n\nprint(ans)\n", "passed": true, "time": 0.31, "memory": 14500.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\nfact = [1] * 1000\nfor i in range(2, 1000):\n fact[i] = fact[i - 1] * i\n\ns = input()\ncnt = {}\nfor d in '0123456789':\n cnt[int(d)] = s.count(d)\nans = 0\n\ndef getcnt(p):\n q = [pi for pi in p if pi != 0]\n num = fact[sum(q)]\n den = 1\n for qi in q:\n den *= fact[qi]\n gc = num // den\n if p[0]:\n q = [pi for pi in p if pi != 0]\n q[0] -= 1\n num = fact[sum(q)]\n den = 1\n for qi in q:\n den *= fact[qi]\n gc -= num // den\n #print(p, gc)\n return gc\n\ndef rec(d, p):\n nonlocal ans\n if d == 10:\n ans += getcnt(p)\n return\n if cnt[d] == 0:\n p[d] = 0\n rec(d + 1, p)\n return\n for c in range(1, cnt[d] + 1):\n p[d] = c\n rec(d + 1, p)\n\np = [0] * 10\nrec(0, p)\n\nprint(ans)", "passed": true, "time": 0.2, "memory": 45384.0, "status": "done"}, {"code": "n=input()\ns=[0 for i in range(10)]\nfor i in n:\n s[int(i)]+=1\n\nnol=s[0]\ndel s[0]\n#while 0 in s:\n# s.remove(0)\ndef C(n,k): # C(10,2)=45\n def fact(k):\n s=1\n for i in range(1,k+1):\n s*=i\n return s\n return fact(n)/(fact(k)*fact(n-k))\ndef var(nol, koeff):\n def C(n,k): # C(10,2)=45\n def fact(k):\n s=1\n for i in range(1,k+1):\n s*=i\n return s\n return fact(n)/(fact(k)*fact(n-k))\n n=0\n if nol!=0:\n koeff.append(nol)\n for i in koeff:\n n+=i\n s=1\n for k in koeff:\n s*=C(n, k)\n n-=k\n if nol!=0:\n koeff.remove(nol)\n nol-=1\n koeff.append(nol)\n s2=1\n n=0\n for i in koeff:\n n+=i\n for k in koeff:\n s2*=C(n,k)\n n-=k\n s-=s2\n return s\nc=0\nnado=len(s)-s.count(0)\nif nol!=0:\n counter=1\nelse:\n counter=0\nfor nolik in range(nol+1):\n for c1 in range(s[0]+1):\n for c2 in range(s[1]+1):\n for c3 in range(s[2]+1):\n for c4 in range(s[3]+1):\n for c5 in range(s[4]+1):\n for c6 in range(s[5]+1):\n for c7 in range(s[6]+1):\n for c8 in range(s[7]+1):\n for c9 in range(s[8]+1):\n koeff=[c1,c2,c3,c4,c5,c6,c7,c8,c9]\n while 0 in koeff:\n koeff.remove(0)\n if len(koeff)==nado:\n if counter==1 and nolik>=1 or counter==0:\n c+=var(nolik, koeff)\nprint(int(c))", "passed": true, "time": 0.46, "memory": 14396.0, "status": "done"}, {"code": "a = list(map(int,input()));\ncnts = [0]*10;\nfor aa in a:\n cnts[aa]+=1\n\nmem = {}\n\nmem[(1,0,0,0,0,0,0,0,0,0)] = 0;\n\nfor i in range(1,10):\n mem[(0,)*(i) + (1,) + (0,)*(10-i-1)] = 1;\n\ndef get(a):\n if (tuple(a) in mem):\n return mem[tuple(a)]\n else:\n aa = list(a)\n tot = 0\n for i in range(0,10):\n if (a[i] != 0):\n aa[i] -= 1;\n tot += get(aa);\n aa[i] += 1;\n mem[tuple(a)] = tot\n return tot\n\nbigTot = 0\n\ndef goThrough(pre, post):\n nonlocal bigTot\n if (len(post) == 0) :\n bigTot += get(pre)\n elif (post[0] == 0):\n goThrough(pre + (0,) , post[1:])\n else:\n for i in range(1,post[0]+1):\n goThrough(pre + (i,) , post[1:])\n\n\n\ngoThrough((), cnts)\n\nprint(bigTot)\n\n", "passed": true, "time": 1.48, "memory": 61296.0, "status": "done"}, {"code": "def main():\n ast = []\n def fact(x):\n if x == 0:\n return 1\n return x * fact(x - 1)\n n = input()\n def helper(dc):\n a = 0\n temp = [dc[j] for j in dc if j != '0']\n s = sum(temp)\n try:\n ret = fact(s) * fact(s + dc['0'] - 1) // (fact(s - 1) * fact(dc['0']))\n except:\n ret = fact(s)\n for i in temp:\n ret = ret // fact(i)\n for i in dc:\n if dc[i] != 1:\n d = {}\n for j in dc:\n d[j] = dc[j]\n d[i] -= 1\n if str(d) not in ast:\n ast.append(str(d))\n a += helper(d)\n return ret + a\n dct = {}\n for i in set(n):\n dct[i] = n.count(i)\n print(helper(dct))\n return 0\nmain()\n", "passed": true, "time": 0.27, "memory": 14388.0, "status": "done"}, {"code": "ct=[0]*10\nfact=[1]*20\nans=0\ndef setAns(lol):\n nonlocal ans\n ans=lol\n\ndef calc(k,fr):\n if(k==10):\n # print(fr)\n tot=sum(fr)\n w0=fact[tot]\n # print(tot,w0)\n for i in range(10):\n w0//=fact[fr[i]]\n wo0=0\n if(fr[0]>0):\n fr[0]-=1\n wo0=fact[tot-1]\n for i in range(10):\n wo0//=fact[fr[i]]\n fr[0]+=1\n tp=w0-wo0\n # print(w0,wo0)\n setAns(ans+tp)\n return\n if(ct[k]==0):\n calc(k+1,fr)\n return \n for i in range(1,ct[k]+1):\n # print(k,i)\n fr[k]=i\n calc(k+1,fr)\n\nfact[0]=1\nfor i in range(1,20):\n fact[i]=fact[i-1]*i\nn=int(input())\nwhile(n>0):\n k=n%10\n n//=10\n ct[k]+=1\nfreq=[0]*10\ncalc(0,freq)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14512.0, "status": "done"}, {"code": "from collections import defaultdict\nfrom copy import deepcopy\n\na = list(input())\n\nd = defaultdict(int)\nfor x in a:\n d[int(x)] += 1\n\nfact_mem = {}\n\n\ndef fact(n):\n if n in fact_mem:\n return fact_mem[n]\n ans = 1\n for i in range(1, n + 1):\n ans *= i\n fact_mem[n] = ans\n return ans\n\n\nmem = {}\n\n\ndef f(d):\n tmp = frozenset(list(d.items()))\n if tmp in mem:\n return 0\n n = sum(d.values())\n ans = 0\n if d[0] > 0:\n ans += (n - d[0]) * fact(n - 1)\n else:\n ans += fact(n)\n if len(d) == 1 and d[0] > 0:\n return 0\n for x in d:\n ans //= fact(d[x])\n for k in d:\n if d[k] > 1:\n e = deepcopy(d)\n e[k] -= 1\n ans += f(e)\n mem[frozenset(list(d.items()))] = ans\n return ans\n\n\nans = f(d)\nprint(ans)\n", "passed": true, "time": 0.37, "memory": 16452.0, "status": "done"}, {"code": "a = int(input())\nb = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\nwhile a != 0:\n b[a % 10] += 1\n a //= 10\n\nans = 0\n\ndef fact(n):\n f = 1\n for i in range(1, n + 1):\n f *= i\n return f\n\ndef f(n, arr):\n #print(arr)\n nonlocal ans\n if n == 10:\n sum = 0\n for i in range(10):\n sum += arr[i]\n temp = 1\n temp *= sum - arr[0]\n #print(temp)\n temp *= fact(sum - 1)\n #print(temp)\n for i in range(10):\n if arr[i] > 1:\n temp //= fact(arr[i])\n \n ans += temp\n #print(ans)\n else:\n if b[n] > 0:\n for i in range(1, b[n] + 1):\n temp = arr.copy()\n temp.append(i)\n f(n + 1, temp)\n else:\n arr.append(0)\n f(n + 1, arr)\n\n\nf(0, [])\nprint(int(ans))", "passed": true, "time": 0.17, "memory": 14388.0, "status": "done"}, {"code": "n = input()\nall = [0] * 10\nfor x in n:\n\tall[int(x)]+=1\n\ndp = [0] * 20\ndp[0] = 1\nfor i in range(1, 10):\n\tcur = [0] * 20\n\tif(all[i] > 0):\n\t\tfor le in range(0, 20): \n\t\t\tfac = 1\n\t\t\tzn = 1\n\t\t\tfor kol in range(1, all[i] + 1):\n\t\t\t\tif(le + kol < 20):\n\t\t\t\t\tzn *= le + kol\n\t\t\t\t\tfac *= kol\n\t\t\t\t\tcur[le + kol] += (zn // fac) * dp[le]\n\t\tdp = cur\n\n\ncur = [0] * 20\nif(all[0] > 0):\n\tfor le in range(1, 20):\n\t\tfac = 1\n\t\tzn = 1\n\t\tfor kol in range(1, all[0] + 1):\n\t\t\tif(le + kol < 20):\n\t\t\t\tzn *= (le + kol-1)\n\t\t\t\tfac *= kol\n\t\t\t\tcur[le + kol] += (zn // fac) * dp[le]\n\tdp = cur\n\nprint(sum(dp))\n", "passed": true, "time": 0.15, "memory": 14348.0, "status": "done"}, {"code": "def fact(n):\n nonlocal fa\n if fa[n] != -1:\n return fa[n]\n else:\n fa[n] = fact(n - 1) * n\n return fa[n]\nfa = [-1] * 20\nfa[0] = 1\nfa[1] = 1\nfa[2] = 2\n\nres = 0\n\na = int(input())\nb = str(a)\ns = [0] * 10\nfor i in range(len(b)):\n s[int(b[i])] += 1\n \nfor i0 in range(s[0] + 1):\n if i0 > 0 or s[0] == 0:\n for i1 in range(s[1] + 1):\n if i1 > 0 or s[1] == 0:\n for i2 in range(s[2] + 1):\n if i2 > 0 or s[2] == 0:\n for i3 in range(s[3] + 1):\n if i3 > 0 or s[3] == 0:\n for i4 in range(s[4] + 1):\n if i4 > 0 or s[4] == 0:\n for i5 in range(s[5] + 1):\n if i5 > 0 or s[5] == 0:\n for i6 in range(s[6] + 1):\n if i6 > 0 or s[6] == 0:\n for i7 in range(s[7] + 1):\n if i7 > 0 or s[7] == 0:\n for i8 in range(s[8] + 1):\n if i8 > 0 or s[8] == 0:\n for i9 in range(s[9] + 1):\n if i9 > 0 or s[9] == 0:\n w2 = [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9]\n su = 0\n for i in range(10):\n su += w2[i]\n for i in range(1, 10):\n if w2[i] > 0:\n w2[i] -= 1\n su -= 1\n \n res += fact(su)/(fact(w2[0]) * fact(w2[1]) * fact(w2[2]) * fact(w2[3]) * fact(w2[4]) * fact(w2[5]) * fact(w2[6]) * fact(w2[7]) * fact(w2[8]) * fact(w2[9]))\n \n su += 1\n w2[i] += 1\nprint(int(res)) ", "passed": true, "time": 0.21, "memory": 14464.0, "status": "done"}, {"code": "a = int(input())\nb = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\nwhile a != 0:\n b[a % 10] += 1\n a //= 10\n\nans = 0\n\ndef gao(n):\n f = 1\n for i in range(1, n + 1):\n f *= i\n return f\n\ndef shit(n, arr):\n nonlocal ans\n if n == 10:\n sum = 0\n for i in range(10):\n sum += arr[i]\n gg = sum - arr[0]\n gg *= gao(sum - 1)\n for i in range(10):\n if arr[i] > 1:\n gg //= gao(arr[i])\n ans += gg\n else:\n if b[n] > 0:\n for i in range(1, b[n] + 1):\n gg = arr.copy()\n gg.append(i)\n shit(n + 1, gg)\n else:\n arr.append(0)\n shit(n + 1, arr)\n\n\nshit(0, [])\nprint(int(ans))", "passed": true, "time": 0.21, "memory": 14500.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nfrom itertools import product\nfrom operator import mul\nfrom functools import reduce\n\nn = input().strip()\nc0 = n.count('0')\ncc = [n.count(str(i)) for i in range(10)]\ncc = [c for c in cc if c > 0]\n\nfacs = [1]\nfor i in range(1, 20):\n\tfacs.append(facs[-1] * i)\n\ndef prod(p):\n\treturn reduce(mul, p, 1)\n\ndef getC(p):\n\treturn facs[sum(p)] // prod(facs[pp] for pp in p)\n\ndef getcount(ct, a0=False):\n\tits = [list(range(1 - int(a0), ct[0] + 1))] + [list(range(1, cti + 1)) for cti in ct[1:]]\n\treturn sum(getC(p) for p in product(*its))\n\nif c0 == 0:\n\tres = getcount(cc)\nelif c0 == 1:\n\tccr = list(cc)\n\tdel ccr[0]\n\tres = getcount(cc) - getcount(ccr)\nelse:\n\tccr = list(cc)\n\tccr[0] -= 1\n\tres = getcount(cc) - getcount(ccr, True)\n\nprint (res)\n", "passed": true, "time": 0.16, "memory": 14340.0, "status": "done"}, {"code": "from itertools import product\nfrom math import factorial\nfrom operator import mul\nfrom functools import reduce\n\nseen = input()\n\ncounts = [[0] for digit in range(10)]\n\nfor digit in map(int, seen):\n counts[digit].append(counts[digit][-1] + 1)\n\nfor digit in range(10):\n if len(counts[digit]) > 1:\n counts[digit].pop(0)\n\nanswer = 0\n\nfor count in product(*counts):\n answer += factorial(sum(count)) // reduce(mul, (factorial(count[digit]) for digit in range(10)))\n \n if count[0] > 0:\n count = list(count)\n count[0] -= 1\n answer -= factorial(sum(count)) // reduce(mul, (factorial(count[digit]) for digit in range(10)))\n \nprint(answer)", "passed": true, "time": 0.17, "memory": 14496.0, "status": "done"}]
[{"input": "97\n", "output": "2\n"}, {"input": "2028\n", "output": "13\n"}, {"input": "1\n", "output": "1\n"}, {"input": "10\n", "output": "1\n"}, {"input": "168\n", "output": "6\n"}, {"input": "999999\n", "output": "6\n"}, {"input": "987654320023456789\n", "output": "29340299842560\n"}, {"input": "1000000000000000000\n", "output": "18\n"}, {"input": "74774\n", "output": "28\n"}, {"input": "2\n", "output": "1\n"}, {"input": "3\n", "output": "1\n"}, {"input": "4\n", "output": "1\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": "1\n"}, {"input": "101010101\n", "output": "246\n"}, {"input": "1010101010\n", "output": "456\n"}, {"input": "707070707070707070\n", "output": "92368\n"}, {"input": "19293\n", "output": "84\n"}, {"input": "987650\n", "output": "600\n"}, {"input": "123456\n", "output": "720\n"}, {"input": "900008\n", "output": "28\n"}, {"input": "1000000\n", "output": "6\n"}, {"input": "9900111\n", "output": "404\n"}, {"input": "11112222\n", "output": "242\n"}, {"input": "88888880\n", "output": "28\n"}, {"input": "100000009\n", "output": "70\n"}, {"input": "203456799\n", "output": "196560\n"}, {"input": "890009800\n", "output": "1120\n"}, {"input": "900000000\n", "output": "8\n"}, {"input": "987654321\n", "output": "362880\n"}, {"input": "999999999\n", "output": "9\n"}, {"input": "1000000000\n", "output": "9\n"}, {"input": "999999999999999999\n", "output": "18\n"}, {"input": "987654321123456789\n", "output": "33007837322880\n"}, {"input": "987654321123456780\n", "output": "55657759288320\n"}, {"input": "888888888888888888\n", "output": "18\n"}, {"input": "888884444444448888\n", "output": "184736\n"}, {"input": "880000000008888888\n", "output": "92368\n"}, {"input": "122661170586643693\n", "output": "4205605773600\n"}, {"input": "166187867387753706\n", "output": "224244425700\n"}, {"input": "54405428089931205\n", "output": "417074011200\n"}, {"input": "96517150587709082\n", "output": "417074011200\n"}, {"input": "234906817379759421\n", "output": "22773236965920\n"}, {"input": "470038695054731020\n", "output": "5099960335680\n"}, {"input": "888413836884649324\n", "output": "76835760120\n"}, {"input": "978691308972024154\n", "output": "33638772575520\n"}, {"input": "484211136976275613\n", "output": "6471643862880\n"}, {"input": "824250067279351651\n", "output": "21519859273920\n"}, {"input": "269041787841325833\n", "output": "22773236965920\n"}, {"input": "462534182594129378\n", "output": "13498126800480\n"}, {"input": "79318880250640214\n", "output": "2075276790720\n"}, {"input": "58577142509378476\n", "output": "1126629393120\n"}, {"input": "973088698775609061\n", "output": "1646603038080\n"}, {"input": "529916324588161451\n", "output": "3614537707200\n"}, {"input": "406105326393716536\n", "output": "2760291011520\n"}, {"input": "490977896148785607\n", "output": "2054415328560\n"}, {"input": "547694365350162078\n", "output": "21519859273920\n"}, {"input": "868572419889505545\n", "output": "1124978369760\n"}]
305
A new delivery of clothing has arrived today to the clothing store. This delivery consists of $a$ ties, $b$ scarves, $c$ vests and $d$ jackets. The store does not sell single clothing items β€” instead, it sells suits of two types: a suit of the first type consists of one tie and one jacket; a suit of the second type consists of one scarf, one vest and one jacket. Each suit of the first type costs $e$ coins, and each suit of the second type costs $f$ coins. Calculate the maximum possible cost of a set of suits that can be composed from the delivered clothing items. Note that one item cannot be used in more than one suit (though some items may be left unused). -----Input----- The first line contains one integer $a$ $(1 \le a \le 100\,000)$ β€” the number of ties. The second line contains one integer $b$ $(1 \le b \le 100\,000)$ β€” the number of scarves. The third line contains one integer $c$ $(1 \le c \le 100\,000)$ β€” the number of vests. The fourth line contains one integer $d$ $(1 \le d \le 100\,000)$ β€” the number of jackets. The fifth line contains one integer $e$ $(1 \le e \le 1\,000)$ β€” the cost of one suit of the first type. The sixth line contains one integer $f$ $(1 \le f \le 1\,000)$ β€” the cost of one suit of the second type. -----Output----- Print one integer β€” the maximum total cost of some set of suits that can be composed from the delivered items. -----Examples----- Input 4 5 6 3 1 2 Output 6 Input 12 11 13 20 4 6 Output 102 Input 17 14 5 21 15 17 Output 325 -----Note----- It is possible to compose three suits of the second type in the first example, and their total cost will be $6$. Since all jackets will be used, it's impossible to add anything to this set. The best course of action in the second example is to compose nine suits of the first type and eleven suits of the second type. The total cost is $9 \cdot 4 + 11 \cdot 6 = 102$.
interview
[{"code": "a=int(input())\nb=int(input())\nc=int(input())\nd=int(input())\ne=int(input())\nf=int(input())\nif e>=f:\n ans=min(a,d)\n d-=ans\n a-=ans\n ans*=e\n ans+=min(d,b,c)*f\nelse:\n ans=min(d,b,c)\n d-=ans\n ans*=f\n ans+=min(a,d)*e\nprint(ans)", "passed": true, "time": 0.14, "memory": 14276.0, "status": "done"}, {"code": "a=int(input())\nb=int(input())\nc=int(input())\nd=int(input())\ne=int(input())\nf=int(input())\n\nif(e>=f):\n ans=min(a,d)*e\n d-=min(a,d)\n ans+=min(min(b,c),d)*f\n print(ans)\nelse:\n ans=min(min(b,c),d)*f\n d-=min(min(b,c),d)\n ans+=min(a,d)*e\n print(ans)\n", "passed": true, "time": 0.25, "memory": 14308.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\ndef getInt(): return int(input())\ndef getVars(): return list(map(int, input().split()))\ndef getList(): return list(map(int, input().split()))\ndef getStr(): return input().strip()\n\n## -------------------------------\n\na = getInt()\nb = getInt()\nc = getInt()\nd = getInt()\ne = getInt()\nf = getInt()\nres = 0\nif (e > f):\n res += min(a, d) * e\n res += min(b, c, d-min(a, d)) * f\nelse:\n res += min(b, c, d) * f\n res += min(a, d - min(b, c, d))*e\nprint(res)\n", "passed": true, "time": 0.14, "memory": 14388.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())\nc = int(input())\nd = int(input())\ne = int(input())\nf = int(input())\nans = 0\nif f > e:\n ans += min(d,c,b)*f\n d -= min(d,c,b)\n ans += min(a,d)*e\nelse:\n ans += min(a,d)*e\n d -= min(a,d)\n ans += min(b,c,d)*f\nprint(ans)", "passed": true, "time": 0.15, "memory": 14284.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n# coding: utf-8\n# Last Modified: 15/Dec/19 02:48:07 PM\n\n\nimport sys\n\n\ndef main():\n a = int(input())\n b = int(input())\n c = int(input())\n d = int(input())\n e = int(input())\n f = int(input())\n ans = 0\n if e > f:\n ans = e * min(a, d)\n x = min(a, d)\n a -= x\n d -= x\n ans += f * min(b, c, d)\n print(ans)\n else:\n ans += f * min(b, c, d)\n x = min(b, c, d)\n b -= x\n c -= x\n d -= x\n ans += e * min(a, d)\n print(ans)\n\n\nget_array = lambda: list(map(int, sys.stdin.readline().split()))\n\n\nget_ints = lambda: list(map(int, sys.stdin.readline().split()))\n\n\ninput = lambda: sys.stdin.readline().strip()\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.25, "memory": 14336.0, "status": "done"}, {"code": "a, b, c, d, e, f = int(input()), int(input()), int(input()), int(input()), int(input()), int(input())\nif e >= f:\n print(min(a, d)*e+min(d-min(a, d), b, c)*f)\nelse:\n print(min(b, c, d)*f+min(d-min(b, c, d), a)*e)\n", "passed": true, "time": 0.24, "memory": 14404.0, "status": "done"}, {"code": "a=int(input())\nb=int(input())\nc=int(input())\nd=int(input())\ne=int(input())\nf=int(input())\nif e>=f:\n ans=e*min(a,d)\n k=min(a,d)\n a -= k\n d -= k\n ans += f*min(b,c,d)\n print(ans)\nelse:\n ans=f*min(b,c,d)\n k=min(b,c,d)\n b -= k\n c -= k\n d -= k\n ans += e*min(a,d)\n print(ans)", "passed": true, "time": 0.14, "memory": 14512.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())\nc = int(input())\nd = int(input())\ne = int(input())\nf = int(input())\nans = 0\n\nif e > f:\n ans += e * min(a, d)\n d -= min(a, d)\n ans += f * min(b, c, d)\nelse:\n ans += f * min(b, c, d)\n d -= min(b, c, d)\n ans += e * min(a, d)\n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14248.0, "status": "done"}, {"code": "a=int(input())\nb=int(input())\nc=int(input())\nd=int(input())\ne=int(input())\nf=int(input())\nif f>e:\n\tprint (min(b,c,d)*f+(min(a,d-min(b,c,d))*e))\nelse:\n\tprint (min(a,d)*e+min(b,c,d-min(a,d))*f)", "passed": true, "time": 0.14, "memory": 14428.0, "status": "done"}, {"code": "import sys\ndef main():\n a,b,c,d,e,f = list(map(int, sys.stdin.read().split()))\n ans = 0\n\n for i in range(0, d+1):\n t1 = min(a, i)\n t2 = min(b, c, d-i)\n\n if ans < t1 * e + t2 * f:\n ans = t1 * e + t2 * f\n\n print(ans)\n\nmain()\n", "passed": true, "time": 0.95, "memory": 14432.0, "status": "done"}, {"code": "a = int(input())\nb = int(input())\nc = int(input())\nd = int(input())\ne = int(input())\nf = int(input())\n\nif e > f:\n ans = e * min(a, d)\n d -= min(a, d)\n ans += f * min(b, c, d)\n print(ans)\nelse:\n ans = f * min(b, c, d)\n d -= min(b, c, d)\n ans += e * min(a, d)\n print(ans)\n", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "a=int(input())\nb=int(input())\nc=int(input())\nd=int(input())\ne=int(input())\nf=int(input())\nans=0\nif(f>e):\n m=min(b,c,d)\n ans+=m*f\n d-=m\n m=min(d,a)\n ans+=m*e\nelse:\n m=min(d,a)\n ans+=m*e\n d-=m\n m=min(b,c,d)\n ans+=m*f\nprint(ans)", "passed": true, "time": 0.15, "memory": 14328.0, "status": "done"}, {"code": "# cost e, a,d\n# cost f, b,c,d\n\na,b,c,d,e,f = [int(input()) for i in range(6)]\n\nq = min(a,d)\ndd = d-q\nans = e*q + f*min(b,c,dd)\n\nw = min(b,c,d)\ndd = d-w\nans = max(ans, e*min(a,dd)+f*w)\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14476.0, "status": "done"}, {"code": "a,b,c,d,e,f=[int(input())for _ in range(6)]\nans=0\nif e>f:\n m=min(a,d)\n ans+=e*m\n d-=m\n print(ans+min(b,c,d)*f)\nelse:\n m=min(b,c,d)\n ans+=f*m\n d-=m\n print(ans+min(a,d)*e)", "passed": true, "time": 0.25, "memory": 14324.0, "status": "done"}]
[{"input": "4\n5\n6\n3\n1\n2\n", "output": "6\n"}, {"input": "12\n11\n13\n20\n4\n6\n", "output": "102\n"}, {"input": "17\n14\n5\n21\n15\n17\n", "output": "325\n"}, {"input": "43475\n48103\n50473\n97918\n991\n974\n", "output": "89936047\n"}, {"input": "35361\n35182\n68078\n30077\n870\n907\n", "output": "27279839\n"}, {"input": "84205\n15736\n30259\n79331\n647\n378\n", "output": "51327157\n"}, {"input": "220\n623\n94\n463\n28\n656\n", "output": "67824\n"}, {"input": "100000\n100000\n100000\n100000\n1000\n1\n", "output": "100000000\n"}, {"input": "22606\n4759\n37264\n19105\n787\n237\n", "output": "15035635\n"}, {"input": "630\n312\n279\n823\n316\n915\n", "output": "427189\n"}, {"input": "86516\n30436\n14408\n80824\n605\n220\n", "output": "48898520\n"}, {"input": "1\n1\n1\n2\n100\n200\n", "output": "300\n"}, {"input": "406\n847\n512\n65\n86\n990\n", "output": "64350\n"}, {"input": "250\n400\n766\n246\n863\n166\n", "output": "212298\n"}, {"input": "724\n20\n391\n850\n639\n149\n", "output": "465616\n"}, {"input": "30233\n27784\n36393\n81065\n782\n953\n", "output": "50120358\n"}, {"input": "61455\n43924\n94322\n83903\n855\n232\n", "output": "57751961\n"}, {"input": "68576\n46084\n31772\n10708\n632\n408\n", "output": "6767456\n"}, {"input": "19969\n99297\n44283\n67490\n71\n20\n", "output": "2303459\n"}, {"input": "68814\n96071\n14437\n59848\n848\n195\n", "output": "50751104\n"}, {"input": "58253\n17658\n9101\n94990\n625\n178\n", "output": "38028103\n"}, {"input": "179\n762\n909\n155\n768\n278\n", "output": "119040\n"}, {"input": "240\n655\n943\n1000\n545\n262\n", "output": "302410\n"}, {"input": "844\n909\n790\n209\n809\n949\n", "output": "198341\n"}, {"input": "15122\n4341\n98868\n60319\n760\n49\n", "output": "11705429\n"}, {"input": "23929\n40873\n44600\n53185\n833\n328\n", "output": "29528825\n"}, {"input": "6781\n2030\n73183\n45619\n802\n208\n", "output": "5860602\n"}, {"input": "260\n538\n587\n231\n49\n308\n", "output": "71148\n"}, {"input": "91\n75\n768\n322\n530\n291\n", "output": "70055\n"}, {"input": "438\n541\n215\n575\n795\n274\n", "output": "385748\n"}, {"input": "756\n608\n949\n947\n746\n375\n", "output": "635601\n"}, {"input": "129\n203\n206\n749\n11\n358\n", "output": "74093\n"}, {"input": "6870\n43115\n61342\n70498\n34\n145\n", "output": "6485255\n"}, {"input": "72593\n77891\n86639\n87424\n3\n617\n", "output": "48087346\n"}, {"input": "58967\n2953\n35483\n681\n780\n304\n", "output": "531180\n"}, {"input": "88\n476\n735\n980\n731\n404\n", "output": "256632\n"}, {"input": "988\n657\n824\n346\n996\n387\n", "output": "344616\n"}, {"input": "92\n346\n431\n669\n773\n563\n", "output": "265914\n"}, {"input": "685\n236\n234\n965\n101\n832\n", "output": "263873\n"}, {"input": "234\n519\n610\n886\n877\n815\n", "output": "628203\n"}, {"input": "184\n301\n373\n420\n93\n602\n", "output": "192269\n"}, {"input": "627\n737\n778\n968\n870\n74\n", "output": "570724\n"}, {"input": "81001\n64465\n98287\n68848\n309\n982\n", "output": "64658977\n"}, {"input": "60469\n13310\n49402\n62958\n790\n861\n", "output": "50681830\n"}, {"input": "88020\n62154\n14139\n86851\n863\n844\n", "output": "74952413\n"}, {"input": "66\n393\n648\n651\n6\n648\n", "output": "255060\n"}, {"input": "647\n495\n516\n125\n79\n928\n", "output": "116000\n"}, {"input": "708\n774\n307\n44\n47\n103\n", "output": "4532\n"}, {"input": "27989\n77786\n5733\n14112\n294\n715\n", "output": "6562521\n"}, {"input": "76294\n65438\n30385\n94336\n71\n891\n", "output": "31613556\n"}, {"input": "5771\n19397\n45992\n46525\n336\n170\n", "output": "5236546\n"}, {"input": "25432\n28656\n46763\n79950\n64\n957\n", "output": "29051440\n"}, {"input": "132\n402\n711\n790\n33\n837\n", "output": "340830\n"}, {"input": "100000\n100000\n100000\n100000\n1\n1000\n", "output": "100000000\n"}, {"input": "100000\n100000\n100000\n100000\n1000\n1000\n", "output": "100000000\n"}, {"input": "1\n2\n3\n4\n1\n1\n", "output": "3\n"}, {"input": "6\n1\n2\n5\n1\n1\n", "output": "5\n"}, {"input": "1\n2\n2\n2\n2\n1\n", "output": "3\n"}, {"input": "1\n4\n5\n6\n8\n8\n", "output": "40\n"}, {"input": "10\n1\n1\n10\n2\n2\n", "output": "20\n"}, {"input": "1\n1\n1\n2\n1\n1\n", "output": "2\n"}]
306
Given an integer $x$. Your task is to find out how many positive integers $n$ ($1 \leq n \leq x$) satisfy $$n \cdot a^n \equiv b \quad (\textrm{mod}\;p),$$ where $a, b, p$ are all known constants. -----Input----- The only line contains four integers $a,b,p,x$ ($2 \leq p \leq 10^6+3$, $1 \leq a,b < p$, $1 \leq x \leq 10^{12}$). It is guaranteed that $p$ is a prime. -----Output----- Print a single integer: the number of possible answers $n$. -----Examples----- Input 2 3 5 8 Output 2 Input 4 6 7 13 Output 1 Input 233 233 10007 1 Output 1 -----Note----- In the first sample, we can see that $n=2$ and $n=8$ are possible answers.
interview
[{"code": "a, b, p, x = [int(x) for x in input().split()]\n\npowers = [a]\n\nwhile powers[-1] != 1:\n powers.append(powers[-1] * a % p)\n \norder = len(powers)\npowers = [powers[-1]] + powers\n\ninverse = pow(order, p-2, p)\n\ndef f(sol):\n return (x // (p * order)) + (1 if sol <= x % (p * order) else 0)\n\ndef chinese(a, n, b, m):\n k = inverse * (b - a + m) % m\n x = k * n + a\n return x % (n * m)\n\nres = 0\nfor i in range(len(powers)-1):\n inv = powers[order - i]\n val = inv * b % p\n \n sol = chinese(i, order, val, p)\n \n res += f(sol)\n \nprint(res)\n", "passed": true, "time": 41.12, "memory": 61124.0, "status": "done"}, {"code": "a,b,p,x = list(map(int, input().strip().split()))\n\n\ndef brute(a,b,p,x):\n for n in range(1, x+1):\n if (n*pow(a,n,p)) % p == b:\n print(n)\n\n#brute(a,b,p,x)\n\nsols = 0\n\ninva = pow(a,p-2,p)\n\n##print('a', inva)\n\na2 = 1\nb2 = b\ns = 0\nd1 = -b\nfac = p*(p-1)\nwhile s < p-1:\n k = (d1 + s) % p\n u = k\n L = x - s - (p-1)*k\n sols += L//fac + 1\n## while (p-1)*u + s <= x:\n## n = (p-1)*u + s\n## print(s, k, n)\n## print(n)\n## #print(n*pow(a,n,p) % p, b)\n## sols += 1\n## u += p\n d1 = (d1 * inva) % p\n s += 1\n\nprint(sols)\n \n\n \n \n\n", "passed": true, "time": 14.61, "memory": 14420.0, "status": "done"}, {"code": "# -*- coding: utf - 8 -*-\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n| author: mr.math - Hakimov Rahimjon |\n| e-mail: [email protected] |\n| created: 04.02.2018 13:31 |\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n# inp = open(\"input.txt\", \"r\"); input = inp.readline; out = open(\"output.txt\", \"w\"); print = out.write\nTN = 1\n\n\n# ===========================================\n\n\ndef solution():\n a, b, p, x = list(map(int, input().split()))\n ans = 0\n ainv = 1\n for i in range(p - 2):\n ainv = (ainv * a) % p\n rem = 1\n inv = 1\n lcm = p * (p - 1)\n for n in range(1, p):\n rem = (rem * a) % p\n inv = (inv * ainv) % p\n i0 = min(p, ((n * rem - b) * inv + p) % p)\n n0 = n + i0 * (p - 1)\n ans += max(0, (x - n0 + lcm) // lcm)\n print(ans)\n\n\n# ===========================================\nwhile TN != 0:\n solution()\n TN -= 1\n# ===========================================\n# inp.close()\n# out.close()\n", "passed": true, "time": 38.39, "memory": 14428.0, "status": "done"}, {"code": "# -*- coding: utf - 8 -*-\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n| author: mr.math - Hakimov Rahimjon |\n| e-mail: [email protected] |\n| created: 04.02.2018 13:31 |\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n# inp = open(\"input.txt\", \"r\"); input = inp.readline; out = open(\"output.txt\", \"w\"); print = out.write\nTN = 1\n\n\n# ===========================================\n\n\ndef solution():\n a, b, p, x = list(map(int, input().split()))\n ans = 0\n ainv = 1\n for i in range(p - 2):\n ainv = (ainv * a) % p\n rem = 1\n inv = 1\n lcm = p * (p - 1)\n for n in range(1, p):\n rem = (rem * a) % p\n inv = (inv * ainv) % p\n i0 = min(p, ((n * rem - b) * inv + p) % p)\n n0 = n + i0 * (p - 1)\n ans += max(0, (x - n0 + lcm) // lcm)\n print(ans)\n\n\n# ===========================================\nwhile TN != 0:\n solution()\n TN -= 1\n# ===========================================\n# inp.close()\n# out.close()\n", "passed": true, "time": 39.26, "memory": 14332.0, "status": "done"}, {"code": "a,b,p,x = [int(x) for x in input().split()]\n\nainv = pow(a,p-2,p)\n\ncount = 0\n\nn = 1\nexp = ainv*b%p\nwhile n<p:\n m = n\n if exp>n:\n m += (n+p-exp)*(p-1)\n else:\n m += (n-exp)*(p-1)\n \n if m<=x: count += 1 + (x-m)//(p*(p-1))\n \n n += 1\n exp = (exp*ainv)%p\n\nprint(count)", "passed": true, "time": 13.4, "memory": 14272.0, "status": "done"}, {"code": "def congr(a, b, p, x):\n solutions = 0\n power = pow(a, p - 2, p)\n a2, b2, s, d1 = 1, b, 0, -b\n prod = p * (p - 1)\n while s < p - 1:\n k = (d1 + s) % p\n L = x - s - (p - 1) * k\n solutions += L // prod + 1\n d1 = (d1 * power) % p\n s += 1\n return solutions\n\n\na, b, p, x = [int(j) for j in input().split()]\nprint(congr(a, b, p, x))\n", "passed": true, "time": 14.53, "memory": 14532.0, "status": "done"}, {"code": "def AC():\n a, b, p, x = map(int, input().split())\n ans = 0\n m = 1\n for i in range(p - 2):\n m = (m * a) % p\n rem = 1\n inv = 1\n Ch = p * (p - 1)\n for n in range(1, p):\n rem = (rem * a) % p\n inv = (inv * m) % p\n cur = min(p, ((n * rem - b) * inv + p) % p)\n rep = n + cur * (p - 1)\n ans += max(0, (x - rep + Ch) // Ch)\n print(ans)\nAC()", "passed": true, "time": 38.66, "memory": 14488.0, "status": "done"}]
[{"input": "2 3 5 8\n", "output": "2\n"}, {"input": "4 6 7 13\n", "output": "1\n"}, {"input": "233 233 10007 1\n", "output": "1\n"}, {"input": "338792 190248 339821 152634074578\n", "output": "449263\n"}, {"input": "629260 663548 739463 321804928248\n", "output": "434818\n"}, {"input": "656229 20757 818339 523535590429\n", "output": "639482\n"}, {"input": "1000002 1000002 1000003 1000000000000\n", "output": "999998\n"}, {"input": "345 2746 1000003 5000000\n", "output": "4\n"}, {"input": "802942 824238 836833 605503824329\n", "output": "723664\n"}, {"input": "1 1 2 880336470888\n", "output": "440168235444\n"}, {"input": "2 2 3 291982585081\n", "output": "97327528361\n"}, {"input": "699601 39672 1000003 391631540387\n", "output": "391905\n"}, {"input": "9 1 11 792412106895\n", "output": "72037464262\n"}, {"input": "85 535 541 680776274925\n", "output": "1258366493\n"}, {"input": "3153 4504 7919 903755230811\n", "output": "114124839\n"}, {"input": "10021 18448 20719 509684975746\n", "output": "24599907\n"}, {"input": "66634 64950 66889 215112576953\n", "output": "3215965\n"}, {"input": "585128 179390 836839 556227387547\n", "output": "664796\n"}, {"input": "299973 381004 1000003 140225320941\n", "output": "140481\n"}, {"input": "941641 359143 1000003 851964325687\n", "output": "851984\n"}, {"input": "500719 741769 1000003 596263138944\n", "output": "596056\n"}, {"input": "142385 83099 1000003 308002143690\n", "output": "307937\n"}, {"input": "891986 300056 999983 445202944465\n", "output": "445451\n"}, {"input": "620328 378284 999983 189501757723\n", "output": "189574\n"}, {"input": "524578 993938 999979 535629124351\n", "output": "535377\n"}, {"input": "419620 683571 999979 243073161801\n", "output": "243611\n"}, {"input": "339138 549930 999883 962863668031\n", "output": "962803\n"}, {"input": "981603 635385 999233 143056117417\n", "output": "143126\n"}, {"input": "416133 340425 998561 195227456237\n", "output": "195090\n"}, {"input": "603835 578057 996323 932597132292\n", "output": "936103\n"}, {"input": "997998 999323 1000003 999968459613\n", "output": "999964\n"}, {"input": "997642 996418 999983 999997055535\n", "output": "1000007\n"}, {"input": "812415 818711 820231 999990437063\n", "output": "1219017\n"}, {"input": "994574 993183 1000003 999974679059\n", "output": "999965\n"}, {"input": "999183 998981 999979 999970875649\n", "output": "999996\n"}, {"input": "1 1 2 1\n", "output": "1\n"}, {"input": "699601 39672 1000003 1\n", "output": "0\n"}, {"input": "4 1 5 15\n", "output": "2\n"}, {"input": "912896 91931 999983 236754\n", "output": "1\n"}, {"input": "154814 35966 269041 1234567\n", "output": "4\n"}, {"input": "1 2 5 470854713201\n", "output": "94170942640\n"}, {"input": "3 27 29 968042258975\n", "output": "33380767549\n"}, {"input": "473 392 541 108827666667\n", "output": "201160200\n"}, {"input": "8 27 29 193012366642\n", "output": "6655598851\n"}, {"input": "1302 504 1987 842777827450\n", "output": "424145863\n"}, {"input": "693528 398514 1000003 1000000000000\n", "output": "999995\n"}, {"input": "533806 514846 1000003 999999999999\n", "output": "999997\n"}, {"input": "812509 699256 1000003 999999999999\n", "output": "999997\n"}, {"input": "28361 465012 1000003 1000000000000\n", "output": "999996\n"}, {"input": "28361 465012 1000003 12693229\n", "output": "1\n"}, {"input": "28361 465012 1000003 13271836\n", "output": "2\n"}, {"input": "28361 465012 1000003 13271835\n", "output": "1\n"}, {"input": "28361 465012 1000003 13421000\n", "output": "4\n"}, {"input": "28361 465012 1000003 19609900\n", "output": "9\n"}, {"input": "28361 465012 1000003 12693228\n", "output": "0\n"}, {"input": "1 1 2 1000000000000\n", "output": "500000000000\n"}, {"input": "1 1000002 1000003 1000000000000\n", "output": "999997\n"}, {"input": "1 44444 1000003 999999999998\n", "output": "999997\n"}, {"input": "2 1000002 1000003 1000000000000\n", "output": "1000001\n"}, {"input": "2 23333 1000003 1000000000000\n", "output": "999999\n"}]
307
Recently Anton found a box with digits in his room. There are k_2 digits 2, k_3 digits 3, k_5 digits 5 and k_6 digits 6. Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task! Each digit can be used no more than once, i.e. the composed integers should contain no more than k_2 digits 2, k_3 digits 3 and so on. Of course, unused digits are not counted in the sum. -----Input----- The only line of the input contains four integers k_2, k_3, k_5 and k_6Β β€” the number of digits 2, 3, 5 and 6 respectively (0 ≀ k_2, k_3, k_5, k_6 ≀ 5Β·10^6). -----Output----- Print one integerΒ β€” maximum possible sum of Anton's favorite integers that can be composed using digits from the box. -----Examples----- Input 5 1 3 4 Output 800 Input 1 1 1 1 Output 256 -----Note----- In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer. In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.
interview
[{"code": "k2, k3, k5, k6 = list(map(int, input().split()))\nc = min(k2, k5, k6)\nk2 -= c\nans = 256 * c\nans += 32 * min(k3, k2)\nprint(ans)\n", "passed": true, "time": 0.21, "memory": 14372.0, "status": "done"}, {"code": "k2, k3, k5, k6 = list(map(int, input().split()))\nk256 = min(k2, k5, k6)\nk2 -= k256\nk5 -= k256\nk6 -= k256\nk32 = min(k2, k3)\nprint(k256 * 256 + 32 * k32)\n", "passed": true, "time": 0.31, "memory": 14468.0, "status": "done"}, {"code": "read = lambda: list(map(int, input().split()))\nk2, k3, k5, k6 = read()\ncnt1 = min(k2, k5, k6)\ncnt2 = min(k2 - cnt1, k3)\nans = cnt1 * 256 + cnt2 * 32\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14272.0, "status": "done"}, {"code": "k2, k3, k5, k6 = map(int, input().split())\nn = min(k2, k5, k6)\nm = min(k2 - n, k3)\nprint(n * 256 + m * 32)", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "k2, k3, k5, k6 = list(map(int, input().split()))\n\nmn_56 = min(k5, k6)\nmn_256 = min(mn_56, k2)\n\nrest_k2 = k2 - mn_256\nk32 = min(k3, rest_k2)\n\nprint(mn_256 * 256 + k32 * 32)\n", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "a, b, c, d = map(int, input().split())\nx = min(a, c, d)\nans = x * 256\na-=x\nc-=x\nd-=x\nans += min(a, b) * 32\nprint(ans)", "passed": true, "time": 0.24, "memory": 14280.0, "status": "done"}, {"code": "k2, k3, k5, k6 = list(map(int, input().split()))\n\ns = min(k2, k5, k6) * 256\nk2 -= min(k2, k5, k6)\ns += min(k2, k3) * 32\n\nprint(s)\n", "passed": true, "time": 0.25, "memory": 14272.0, "status": "done"}, {"code": "a2,a3,a5,a6 = map(int,input().split())\ns256 = min(a2,a5,a6)\na2 -= s256\na5 -= s256\na6 -= s256\ns32 = min(a2,a3)\nprint(s256*256+s32*32)", "passed": true, "time": 0.16, "memory": 14460.0, "status": "done"}, {"code": "k2, k3, k5, k6 = map(int, input().split(' '))\nnum256 = min(k2, k5, k6)\nans = 256 * num256\nk2 -= num256\nnum32 = min(k2, k3)\nans += 32 * num32\nprint(ans)", "passed": true, "time": 0.16, "memory": 14420.0, "status": "done"}, {"code": "a = list(map(int, input().split()))\nw = min(a[0], a[2], a[3])\nam = 256 * w\nam += 32 * min(a[0] - w, a[1])\nprint(am)", "passed": true, "time": 0.15, "memory": 14256.0, "status": "done"}, {"code": "a, b, c, d = map(int, input().split())\nmini = min(a, c, d)\nans = 0\nans += mini * 256\na -= mini\nc -= mini\nd -= mini\nmini = min(a, b)\nans += mini * 32\nprint(ans)", "passed": true, "time": 0.15, "memory": 14488.0, "status": "done"}, {"code": "k2,k3,k5,k6=map(int,input().split())\ns=min(k2,k5,k6)*256\nk2=k2-min(k2,k5,k6)\nprint(s+min(k2,k3)*32)", "passed": true, "time": 0.15, "memory": 14360.0, "status": "done"}, {"code": "a, b, c, d = map(int, input().split())\nmx = min(a, c, d)\nans = mx * 256 + min(a - mx, b) * 32\nprint(ans)", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "a, b, c, d = list(map(int, input().split()))\nm = min(a, c, d)\na -= m\nc -= m\nd -= m\nans = 256 * m\nans += 32 * min(a,b )\nprint(ans)\n", "passed": true, "time": 0.22, "memory": 14372.0, "status": "done"}, {"code": "a, b, c, d = map(int, input().split())\nans = 0\nans += 256 * min(a, min(c, d))\nleft = a - ans // 256\nans += 32 * min(b, left)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "k2, k3, k5, k6 = map(int, input().split())\n\na = min(k2, k5, k6)\nb = min(k3, k2-a)\nprint(256*a+32*b)", "passed": true, "time": 0.14, "memory": 14420.0, "status": "done"}, {"code": "k2, k3, k5, k6 = list(map(int, input().split()))\nk = min(k2, min(k5, k6))\nans = k * 256\nk2 -= k\nans += 32 * min(k2, k3)\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "k2, k3, k5, k6 = map(int, input().split())\ns = 0\ns += 256 * min(k2, k5, k6)\nk2 -= min(k2, k5, k6)\ns += 32 * min(k2, k3)\nprint(s)", "passed": true, "time": 0.14, "memory": 14264.0, "status": "done"}, {"code": "k2, k3, k5, k6 = [int(x) for x in input().split()]\nc1 = min(k2, k5, k6)\nans = c1*256\nk2 -= c1\nif k2 > 0:\n ans += 32*(min(k2,k3))\nprint(ans)", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "__author__ = 'Think'\nk2, k3, k5, k6=[int(i) for i in input().split()]\nr=min(k5, k6)\nif r>k2:\n\tprint(256*k2)\nelse:\n\tprint(256*r+32*min(k3, k2-r))", "passed": true, "time": 0.14, "memory": 14372.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\n\ndef lmap(f, x):\n return list(map(f, x))\n\n\ndef read_ints():\n return lmap(int, input().strip().split())\n\n\ndef main():\n res = 0\n a2, a3, a5, a6 = read_ints()\n n256 = min(a2, a5, a6)\n res += n256 * 256\n a2 -= n256\n a5 -= n256\n a6 -= n256\n n32 = min(a3, a2)\n res += n32 * 32\n return res\n\n\nprint(main())\n", "passed": true, "time": 0.14, "memory": 14492.0, "status": "done"}, {"code": "l = [int(x) for x in input().split()]\nk = min(l[0],l[2],l[3])\na = l[0] - k\nj = min(a,l[1])\nprint(256*k + 32*j)", "passed": true, "time": 0.14, "memory": 14296.0, "status": "done"}, {"code": "k2, k3, k5, k6 = list(map(int, input().split()))\n\nn = min(k2, k5, k6)\ns = n * 256\nk2 -= n\nif k2 > 0:\n s += min(k2, k3) * 32\nprint(s)\n", "passed": true, "time": 0.21, "memory": 14464.0, "status": "done"}]
[{"input": "5 1 3 4\n", "output": "800\n"}, {"input": "1 1 1 1\n", "output": "256\n"}, {"input": "10 2 1 5\n", "output": "320\n"}, {"input": "4 2 7 2\n", "output": "576\n"}, {"input": "489 292 127 263\n", "output": "41856\n"}, {"input": "9557 5242 1190 7734\n", "output": "472384\n"}, {"input": "1480320 1969946 1158387 3940412\n", "output": "306848928\n"}, {"input": "0 0 0 0\n", "output": "0\n"}, {"input": "5000000 5000000 5000000 5000000\n", "output": "1280000000\n"}, {"input": "1048576 256 1048576 1048576\n", "output": "268435456\n"}, {"input": "2073144 2073145 0 0\n", "output": "66340608\n"}, {"input": "1000000 0 0 1\n", "output": "0\n"}, {"input": "2 1 1 1\n", "output": "288\n"}, {"input": "0 5000000 5000000 5000000\n", "output": "0\n"}, {"input": "4494839 1140434 3336818 4921605\n", "output": "890719296\n"}, {"input": "2363223 3835613 926184 3190201\n", "output": "283088352\n"}, {"input": "198044 2268164 2811743 1458798\n", "output": "50699264\n"}, {"input": "5 5 1 0\n", "output": "160\n"}, {"input": "1 1 1 4\n", "output": "256\n"}, {"input": "3 3 4 4\n", "output": "768\n"}, {"input": "1 2 0 5\n", "output": "32\n"}, {"input": "1207814 1649617 2347252 3136345\n", "output": "309200384\n"}, {"input": "78025 2308643 78025 4943733\n", "output": "19974400\n"}, {"input": "3046068 2548438 2676145 4789979\n", "output": "696930656\n"}, {"input": "4755258 2724358 2030900 4801065\n", "output": "607089856\n"}, {"input": "1359689 3792971 4451626 4497236\n", "output": "348080384\n"}, {"input": "3484483 3995744 87159 4941393\n", "output": "131027072\n"}, {"input": "1273630 1273630 980163 1711706\n", "output": "260312672\n"}, {"input": "2010798 1111442 4014004 4430228\n", "output": "514764288\n"}, {"input": "1714940 133067 3346537 3346537\n", "output": "439024640\n"}, {"input": "3731658 4548347 3731658 3731658\n", "output": "955304448\n"}, {"input": "601597 2632066 450558 450558\n", "output": "120176096\n"}, {"input": "726573 158002 568571 568571\n", "output": "150610240\n"}, {"input": "407729 4510137 3425929 3425929\n", "output": "104378624\n"}, {"input": "1781608 3826276 4384744 4384744\n", "output": "456091648\n"}, {"input": "4486284 4486284 3249460 3249460\n", "output": "871440128\n"}, {"input": "4759823 3520376 4743363 4743363\n", "output": "1214827648\n"}, {"input": "386719 4643763 2749163 1701105\n", "output": "99000064\n"}, {"input": "3173901 1042250 4102237 3173901\n", "output": "812518656\n"}, {"input": "2681845 4558270 4388852 13014\n", "output": "88734176\n"}, {"input": "1152975 910150 2776412 242825\n", "output": "91288000\n"}, {"input": "2005366 3807065 4174270 2471686\n", "output": "513373696\n"}, {"input": "2092196 2406694 3664886 85601\n", "output": "86124896\n"}, {"input": "4542228 4542228 3992410 1039690\n", "output": "378241856\n"}, {"input": "3093105 2256347 675644 570209\n", "output": "218176608\n"}, {"input": "0 1 1 1\n", "output": "0\n"}, {"input": "10 20 10 20\n", "output": "2560\n"}, {"input": "0 0 5 1\n", "output": "0\n"}, {"input": "10 0 10 11\n", "output": "2560\n"}, {"input": "2 1 32768 65536\n", "output": "512\n"}, {"input": "2 3 5 6\n", "output": "512\n"}, {"input": "5 3 2 2\n", "output": "608\n"}, {"input": "1 0 2 3\n", "output": "256\n"}, {"input": "1 0 1 1\n", "output": "256\n"}, {"input": "2 0 3 3\n", "output": "512\n"}, {"input": "2 2 2 0\n", "output": "64\n"}, {"input": "0 0 1 1\n", "output": "0\n"}, {"input": "1 0 2 2\n", "output": "256\n"}, {"input": "4 3 4 4\n", "output": "1024\n"}, {"input": "5 1 5 6100\n", "output": "1280\n"}]
308
Mr. Bender has a digital table of size n Γ— n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy. We'll consider the table rows numbered from top to bottom from 1 to n, and the columns β€” numbered from left to right from 1 to n. Initially there is exactly one switched on cell with coordinates (x, y) (x is the row number, y is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on. For a cell with coordinates (x, y) the side-adjacent cells are cells with coordinates (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1). In how many seconds will Mr. Bender get happy? -----Input----- The first line contains four space-separated integers n, x, y, c (1 ≀ n, c ≀ 10^9;Β 1 ≀ x, y ≀ n;Β c ≀ n^2). -----Output----- In a single line print a single integer β€” the answer to the problem. -----Examples----- Input 6 4 3 1 Output 0 Input 9 3 8 10 Output 2 -----Note----- Initially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure. [Image].
interview
[{"code": "x, y, n, c = 0, 0, 0, 0\ndef suma_impares(m):\n\treturn m * m\ndef suma_n(m):\n\treturn m * (m - 1) // 2\ndef cnt(t):\n\tu, d, l, r = x + t, x - t, y - t, y + t\n\tsuma = t ** 2 + (t + 1) ** 2\n\tif u > n: suma -= suma_impares(u - n)\n\tif d < 1: suma -= suma_impares(1 - d)\n\tif l < 1: suma -= suma_impares(1 - l)\n\tif r > n: suma -= suma_impares(r - n)\n\tif 1 - l > x - 1 and 1 - d > y - 1:\n\t\tsuma += suma_n(2 - l - x)\n\tif r - n > x - 1 and 1 - d > n - y:\n\t\tsuma += suma_n(r - n - x + 1)\n\tif 1 - l > n - x and u - n > y - 1:\n\t\tsuma += suma_n(1 - l - n + x)\n\tif u - n > n - y and r - n > n - x:\n\t\tsuma += suma_n(u - n - n + y)\n\treturn suma\n\t\nn, x, y, c = input().split()\nn, x, y, c = int(n), int(x), int(y), int(c)\n#for i in range(10):\n#\tprint(i, cnt(i))\nini, fin = 0, int(1e9)\ncont = int(1e9)\nwhile cont > 0:\n\tm = ini\n\tpaso = cont // 2\n\tm += paso\n\tif cnt(m) < c:\n\t\tini = m + 1\n\t\tcont -= paso + 1\n\telse:\n\t\tcont = paso\nprint(ini)", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "import sys\nii = lambda: sys.stdin.readline().strip()\nidata = lambda: [int(x) for x in ii().split()]\nsdata = lambda: list(ii())\n\ndef solve():\n n, x, y, c = idata()\n r = n ** 2\n l = -1\n while l + 1 < r:\n middle = (l + r) // 2\n ans = 1 + 2 * (middle + 1) * middle\n ans -= pow(middle - n + y, 2) if middle - n + y > 0 else 0\n ans -= pow(middle + 1 - y, 2) if middle + 1 - y > 0 else 0\n ans -= pow(middle - n + x, 2) if middle - n + x > 0 else 0\n ans -= pow(middle + 1 - x, 2) if middle + 1 - x > 0 else 0\n d = 1 + n - x + y\n if middle >= d:\n ans += (middle - d + 1) * (middle - d + 2) // 2\n d = 2 + 2 * n - y - x\n if middle >= d:\n ans += (middle - d + 1) * (middle - d + 2) // 2\n d = 1 + n - y + x\n if middle >= d:\n ans += (middle - d + 1) * (middle - d + 2) // 2\n d = x + y\n if middle >= d:\n ans += (middle - d + 1) * (middle - d + 2) // 2\n if ans >= c:\n r = middle\n else:\n l = middle\n print(r)\n return\n\nfor t in range(1):\n solve()", "passed": true, "time": 0.14, "memory": 14316.0, "status": "done"}]
[{"input": "6 4 3 1\n", "output": "0\n"}, {"input": "9 3 8 10\n", "output": "2\n"}, {"input": "9 4 3 10\n", "output": "2\n"}, {"input": "9 8 2 10\n", "output": "2\n"}, {"input": "1 1 1 1\n", "output": "0\n"}, {"input": "10 7 2 7\n", "output": "2\n"}, {"input": "8 2 6 10\n", "output": "2\n"}, {"input": "8 1 2 10\n", "output": "3\n"}, {"input": "6 1 4 10\n", "output": "3\n"}, {"input": "1000000 951981 612086 60277\n", "output": "174\n"}, {"input": "1000000 587964 232616 62357\n", "output": "177\n"}, {"input": "1000000 948438 69861 89178\n", "output": "211\n"}, {"input": "1000000000 504951981 646612086 602763371\n", "output": "17360\n"}, {"input": "1000000000 81587964 595232616 623563697\n", "output": "17657\n"}, {"input": "1000000000 55 60 715189365\n", "output": "37707\n"}, {"input": "1000000000 85 61 857945620\n", "output": "41279\n"}, {"input": "1000000000 55 85 423654797\n", "output": "28970\n"}, {"input": "1000000000 63 65 384381709\n", "output": "27600\n"}, {"input": "1000000000 44 30 891773002\n", "output": "42159\n"}, {"input": "1000000000 6 97 272656295\n", "output": "23250\n"}, {"input": "1000000000 999999946 999999941 715189365\n", "output": "37707\n"}, {"input": "1000000000 999999916 999999940 857945620\n", "output": "41279\n"}, {"input": "1000000000 999999946 999999916 423654797\n", "output": "28970\n"}, {"input": "1000000000 999999938 999999936 384381709\n", "output": "27600\n"}, {"input": "1000000000 55 999999941 715189365\n", "output": "37707\n"}, {"input": "1000000000 85 999999940 857945620\n", "output": "41279\n"}, {"input": "1000000000 55 999999916 423654797\n", "output": "28970\n"}, {"input": "1000000000 63 999999936 384381709\n", "output": "27600\n"}, {"input": "1000000000 44 999999971 891773002\n", "output": "42159\n"}, {"input": "1000000000 6 999999904 272656295\n", "output": "23250\n"}, {"input": "1000000000 999999946 60 715189365\n", "output": "37707\n"}, {"input": "1000000000 999999916 61 857945620\n", "output": "41279\n"}, {"input": "1000000000 999999946 85 423654797\n", "output": "28970\n"}, {"input": "1000000000 999999938 65 384381709\n", "output": "27600\n"}, {"input": "1000000000 999999957 30 891773002\n", "output": "42159\n"}, {"input": "548813503 532288332 26800940 350552333\n", "output": "13239\n"}, {"input": "847251738 695702891 698306947 648440371\n", "output": "18006\n"}, {"input": "891773002 152235342 682786380 386554406\n", "output": "13902\n"}, {"input": "812168727 57791401 772019566 644719499\n", "output": "17954\n"}, {"input": "71036059 25478942 38920202 19135721\n", "output": "3093\n"}, {"input": "549 198 8 262611\n", "output": "635\n"}, {"input": "848 409 661 620581\n", "output": "771\n"}, {"input": "892 364 824 53858\n", "output": "183\n"}, {"input": "813 154 643 141422\n", "output": "299\n"}, {"input": "72 40 68 849\n", "output": "25\n"}, {"input": "958 768 649 298927\n", "output": "431\n"}, {"input": "800 305 317 414868\n", "output": "489\n"}, {"input": "721 112 687 232556\n", "output": "556\n"}, {"input": "522 228 495 74535\n", "output": "249\n"}, {"input": "737 231 246 79279\n", "output": "199\n"}, {"input": "6 4 3 36\n", "output": "6\n"}, {"input": "9 3 8 55\n", "output": "7\n"}, {"input": "9 4 3 73\n", "output": "8\n"}, {"input": "9 8 2 50\n", "output": "7\n"}, {"input": "1 1 1 1\n", "output": "0\n"}, {"input": "10 7 2 7\n", "output": "2\n"}, {"input": "8 2 6 20\n", "output": "3\n"}, {"input": "8 1 2 64\n", "output": "13\n"}, {"input": "6 1 4 15\n", "output": "3\n"}, {"input": "8 8 3 1\n", "output": "0\n"}]
309
A little girl loves problems on bitwise operations very much. Here's one of them. You are given two integers l and r. Let's consider the values of $a \oplus b$ for all pairs of integers a and b (l ≀ a ≀ b ≀ r). Your task is to find the maximum value among all considered ones. Expression $x \oplus y$ means applying bitwise excluding or operation to integers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is represented as "^", in Pascal β€” as Β«xorΒ». -----Input----- The single line contains space-separated integers l and r (1 ≀ l ≀ r ≀ 10^18). Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. -----Output----- In a single line print a single integer β€” the maximum value of $a \oplus b$ for all pairs of integers a, b (l ≀ a ≀ b ≀ r). -----Examples----- Input 1 2 Output 3 Input 8 16 Output 31 Input 1 1 Output 0
interview
[{"code": "import sys\nl,r=map(int,(sys.stdin.readline().split()))\ni=64\nwhile i>=0:\n if ((1<<i)&l!=0 and (1<<i)&r!=0) or ((1<<i)&l==0 and (1<<i)&r==0):i-=1\n else:break\nprint((1<<(i+1))-1)", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "l,r=map(int,(input().split()))\nfor i in range(64,-2,-1):\n if(i<0 or ((1<<i)&l)!=((1<<i)&r)): break\nprint((1<<(i+1))-1)", "passed": true, "time": 0.14, "memory": 14316.0, "status": "done"}, {"code": "# miracle!!\n# cannot believe!!\n\n(l, r) = list(map(int, input().split()))\n\nbl = (r-l).bit_length()\n\nprint((((r^l)>>bl)+1<<bl)-1)\n", "passed": true, "time": 0.22, "memory": 14488.0, "status": "done"}, {"code": "l, r = map(int, input().split())\ni = 0\nif l == r: print(0)\nelse:\n l, r = format(l, 'b'), format(r, 'b')\n if len(l) == len(r):\n while l[i] == r[i]: i += 1\n print((1 << len(r) - i) - 1)", "passed": true, "time": 0.88, "memory": 14452.0, "status": "done"}, {"code": "import sys\n\nl, r = tuple(int(x) for x in sys.stdin.readline().split())\nmaximum = -1\ncur_pow = 1\n\nwhile cur_pow <= r:\n if cur_pow - 1 >= l:\n cur_result = cur_pow ^ (cur_pow - 1)\n maximum = max(maximum, cur_result)\n cur_pow *= 2\n\nif maximum < 0:\n n_ones = len(bin(l))\n str1, str2 = bin(l), bin(r)\n index = 0\n while index < len(str1) and index < len(str2) and str1[index] == str2[index]:\n index += 1\n n_ones -= 1\n if n_ones == 0:\n maximum = 0\n else:\n maximum = int('1' * n_ones, 2)\n\nprint(maximum)\n", "passed": true, "time": 0.14, "memory": 14300.0, "status": "done"}, {"code": "# your code goes here\nimport sys\nl, r = tuple(int(x) for x in sys.stdin.readline().split())\nl = bin(l)\nr = bin(r)\nl = l[2:]\nr = r[2:]\nl = l.zfill(len(r))\n#print (l)\n#print (r)\ni = 0\nwhile l[i] == r[i]:\n\tif i == len(l)-1:\n\t\tprint (0)\n\t\treturn\n\ti+=1\ni=len(l)-i\nprint(2**i-1)\t\t", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}, {"code": "l,r=list(map(int,input().split()))\nres=0\nfor it in range(62,-1,-1):\n if ((l>>it)&1) != ((r>>it)&1):\n res=(1<<it+1)-1\n break\nprint (res)\n", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}, {"code": "def main():\n l, r = (format(int(s), 'b') for s in input().split())\n le = len(r)\n if len(l) == le:\n for i in range(le):\n if l[i] != r[i]:\n print(int('1' * (le - i), 2))\n break\n else:\n print(0)\n else:\n print(int('1' * le, 2))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14312.0, "status": "done"}, {"code": "#in the name of god\n#Mr_Rubick\nl,r=list(map(int, input().split()))\ni=0\nif l==r:\n if l==1 and r==1:print(0)\n else:print(1)\nelse:\n l,r=format(l,'b'),format(r,'b')\n if len(l)==len(r):\n while l[i]==r[i]:\n i+=1\n print((1 << len(r)-i)-1)\n", "passed": true, "time": 0.24, "memory": 14316.0, "status": "done"}, {"code": "import math\n\nl, r = map(int, input().split())\n\nif l==r:\n print(\"0\")\nelse:\n msb = int(math.log2(r))\n for i in range(msb, -1, -1):\n if (l & (1 << i)) != (r & (1 << i)):\n break\n\n print(2*(1<<i)-1)", "passed": true, "time": 0.15, "memory": 14276.0, "status": "done"}, {"code": "def maximum(l,r):\n\n r = bin(r)[2:]\n l = bin(l)[2:].zfill(len(r))\n\n if r[0] == \"1\" and l[0] == \"0\":\n return int(\"1\"*len(l), base=2)\n else:\n #print(l,r)\n\n if l[1:] != \"\":\n\n l =int(l[1:],base=2)\n r = int(r[1:], base=2)\n\n else:\n return 0\n\n return maximum(l,r)\n\n\ninp = input()\nl, r = inp.split(\" \")\nprint(maximum(int(l),int(r)))", "passed": true, "time": 0.17, "memory": 14372.0, "status": "done"}, {"code": "l = [int(x) for x in input().split()]\nl.sort()\nb, a = l\n\ns1 = list(bin(a)[2:])\ns2 = list(bin(b)[2:])\n\nif s1 == s2:\n print(0)\n\nelif len(s1) == len(s2):\n cont = 0\n while s1[cont] == s2[cont]:\n s1[cont] = \"0\"\n cont+=1\n for i in range(cont , len(s1)):\n s1[i] = \"1\"\n print(int(\"\".join(s1), 2))\n\nelse:\n for i in range(len(s1)):\n s1[i] = \"1\"\n print(int(\"\".join(s1), 2))\n\n\n", "passed": true, "time": 0.14, "memory": 14456.0, "status": "done"}, {"code": "lr = input().split()\nl,r = [int(x) for x in lr]\n\nif l == r:\n print(0)\nelse:\n a,b = list(bin(l)[2:]), list(bin(r)[2:])\n\n if len(a) == len(b):\n i = 0\n while a[i] == b[i]:\n i+=1\n left = '1'*(len(a)-i)\n print(int(left,2))\n elif len(a) > len(b):\n left = '1'*(len(a))\n print(int(left,2))\n else:\n left = '1'*(len(b))\n print(int(left,2))", "passed": true, "time": 0.15, "memory": 14524.0, "status": "done"}, {"code": "lr = input().split()\nl,r = [int(x) for x in lr]\n\nif l == r:\n print(0)\n \nelse:\n a,b = list(bin(l)[2:]), list(bin(r)[2:])\n if len(a) == len(b):\n i = 0\n while a[i] == b[i]:\n i+=1\n left = '1'*(len(a)-i)\n print(int(left,2))\n elif len(a) > len(b):\n left = '1'*(len(a))\n print(int(left,2))\n else:\n left = '1'*(len(b))\n print(int(left,2))", "passed": true, "time": 0.14, "memory": 14308.0, "status": "done"}, {"code": "l, r = map(int, input().split())\nhmm, t = l ^ r, 2 ** 60\nwhile hmm ^ t > hmm:\n t //= 2\nprint(2 * t - 1 if hmm != 0 else 0)", "passed": true, "time": 0.24, "memory": 14276.0, "status": "done"}, {"code": "a,b = map(int, input().split())\n\nprint(2**(a ^ b).bit_length() -1)", "passed": true, "time": 0.22, "memory": 14468.0, "status": "done"}, {"code": "l, r = ['{:061b}'.format(int(x)) for x in input().split()]\n\npot = 0\nfor i in range(61):\n if l[i] != r[i]:\n pot = 61 - i\n break\n\nif pot == 0:\n print(0)\nelse:\n print((2**pot - 2) ^ 1)", "passed": true, "time": 0.14, "memory": 14264.0, "status": "done"}, {"code": "from math import log2\nl,r = list(map(int,input().split()))\nif(l == r):print('0')\nelse : print((1 << int(log2(l ^ r) + 1)) - 1)\n", "passed": true, "time": 0.15, "memory": 14276.0, "status": "done"}, {"code": "import math\nl,r = list(map(int,input().strip().split()))\nlr = int(math.log(r)/math.log(2))\nll = int(math.log(l)/math.log(2))\n\nif lr > ll:\n\tlr+=1\n\tans = 1<<lr\n\tans-=1\n\tprint(ans)\nelse:\n\tans = 0\n\tfl = False\n\tfor i in range(lr,-1,-1):\n\t\tif l&(1<<i) == r&(1<<i) and fl == False:\n\t\t\tcontinue \n\t\telif l&(1<<i) != r&(1<<i):\n\t\t\tans = ans + (1<<i)\n\t\t\tfl = True\n\t\telif fl == True:\n\t\t\tans = ans + (1<<i)\n\t\t\t\t\n\tprint(ans)\n##101100101110010110010011110101101110101101111010110010011000\n##100101001000010011010111110011010001111010111010011001111010\n", "passed": true, "time": 0.25, "memory": 14508.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\ns=-1\nfor i in range(60, 0, -1):\n if a&(1<<i)==0 and b&(1<<i)!=0:\n print((1<<(i+1))-1)\n break\nelse:\n print(a^b)\n", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "import sys\nl,r=list(map(int,sys.stdin.readline().split()))\nbinr=list(str(bin(r)))[2:]\nbinl=list(str(bin(l)))[2:]\nlenr=len(binr)\nlenl=len(binl)\nfor i in range(lenr-lenl):\n binl.insert(0,0)\n\nans=['1']\nlength=lenr\nstatus=0\nfor i in range(0,length):\n if status==1:\n ans.append('1')\n if(binr[i]!=binl[i]):\n status=1\n\nif(status==0):\n print(0)\nelse:\n strans=''.join(ans)\n print(int(strans,2))\n\n \n\n", "passed": true, "time": 0.14, "memory": 14484.0, "status": "done"}, {"code": "a,b=list(map(int,input().split()))\ns1=list(map(int,reversed(list(bin(a)[2:]))))\ns2=list(map(int,reversed(list(bin(b)[2:]))))\ns1+=[0]*(len(s2)-len(s1))\nout=0\nfor i in range(len(s1)):\n if s1[i]^s2[i]:\n out=i+1\n\nprint(2**out-1)\n", "passed": true, "time": 0.25, "memory": 14424.0, "status": "done"}, {"code": "n,m=list(map(int,input().split()))\nn=str(bin(n))[2:]\nm=str(bin(m))[2:]\nn='0'*(len(m)-len(n))+n\nf=0\nfor i in range(len(n)):\n if n[i]=='0' and m[i]=='1':\n print(2**(len(n)-i)-1)\n f=1\n break\nif not f:\n print(f)\n", "passed": true, "time": 0.14, "memory": 14284.0, "status": "done"}, {"code": "n=input().split()\nm=int(n[1])\nn=int(n[0])\nif m<n:\n c=m\n m=n\n n=c\nc=''\na=bin(m)[2:]\nb=bin(n)[2:]\nb='0'*(len(a)-len(b))+b\nwhile a[0]==b[0] and len(a)!= 0:\n c1 = str(int(a[0])^int(b[0]))\n c+=c1\n a=a[1:]\n b=b[1:]\n if len(a)==0 or len(b)==0:\n break\n #if len(a)!=0:\n # a=str(int(a))\n #if len(b)!=0:\n #7 b=str(int(b))\naa=max(len(b),len(a))\nc=c+aa*'1'\nc=int(c)\nd=1\np=0\nwhile c!=0:\n s=c%10\n p+=d*s\n d=d*2\n c=c//10\nprint(p)\n\n \n", "passed": true, "time": 0.15, "memory": 14468.0, "status": "done"}]
[{"input": "1 2\n", "output": "3\n"}, {"input": "8 16\n", "output": "31\n"}, {"input": "1 1\n", "output": "0\n"}, {"input": "506 677\n", "output": "1023\n"}, {"input": "33 910\n", "output": "1023\n"}, {"input": "36 94\n", "output": "127\n"}, {"input": "10000000000 20000000000\n", "output": "34359738367\n"}, {"input": "79242383109441603 533369389165030783\n", "output": "576460752303423487\n"}, {"input": "797162752288318119 908416915938410706\n", "output": "576460752303423487\n"}, {"input": "230148668013473494 573330407369354716\n", "output": "576460752303423487\n"}, {"input": "668869743157683834 805679503731305624\n", "output": "288230376151711743\n"}, {"input": "32473107276976561 588384394540535099\n", "output": "1152921504606846975\n"}, {"input": "632668612680440378 864824360766754908\n", "output": "576460752303423487\n"}, {"input": "658472316271074503 728242833853270665\n", "output": "288230376151711743\n"}, {"input": "289218059048863941 314351197831808685\n", "output": "36028797018963967\n"}, {"input": "54248140375568203 718189790306910368\n", "output": "1152921504606846975\n"}, {"input": "330134158459714054 457118108955760856\n", "output": "288230376151711743\n"}, {"input": "190442232278841373 980738846929096255\n", "output": "1152921504606846975\n"}, {"input": "203359308073091683 455893840817516371\n", "output": "576460752303423487\n"}, {"input": "200851182089362664 449305852839820160\n", "output": "576460752303423487\n"}, {"input": "731792654005832175 789527173439457653\n", "output": "72057594037927935\n"}, {"input": "231465750142682282 276038074124518614\n", "output": "72057594037927935\n"}, {"input": "462451489958473150 957447393463701191\n", "output": "1152921504606846975\n"}, {"input": "68666076639301243 247574109010873331\n", "output": "288230376151711743\n"}, {"input": "491113582000560303 858928223424873439\n", "output": "1152921504606846975\n"}, {"input": "454452550141901489 843034681327343036\n", "output": "1152921504606846975\n"}, {"input": "43543567767276698 769776048133345296\n", "output": "1152921504606846975\n"}, {"input": "214985598536531449 956713939905291713\n", "output": "1152921504606846975\n"}, {"input": "56445001476501414 706930175458589379\n", "output": "1152921504606846975\n"}, {"input": "666033930784103123 883523065811761270\n", "output": "576460752303423487\n"}, {"input": "501827377176522663 590153819613032662\n", "output": "1152921504606846975\n"}, {"input": "140216419613864821 362678730465999561\n", "output": "576460752303423487\n"}, {"input": "23811264031960242 520940113721281721\n", "output": "576460752303423487\n"}, {"input": "43249439481689805 431488136320817289\n", "output": "576460752303423487\n"}, {"input": "198909890748296613 528950282310167050\n", "output": "576460752303423487\n"}, {"input": "190620774979376809 899159649449168622\n", "output": "1152921504606846975\n"}, {"input": "18565852953382418 697862904569985066\n", "output": "1152921504606846975\n"}, {"input": "277046860122752192 828379515775613732\n", "output": "1152921504606846975\n"}, {"input": "25785331761502790 119852560236585580\n", "output": "144115188075855871\n"}, {"input": "363313173638414449 500957528623228245\n", "output": "288230376151711743\n"}, {"input": "549330032897152846 715374717344043295\n", "output": "1152921504606846975\n"}, {"input": "47456305370335136 388462406071482688\n", "output": "576460752303423487\n"}, {"input": "125051194948742221 235911208585118006\n", "output": "288230376151711743\n"}, {"input": "780993382943360354 889872865454335075\n", "output": "576460752303423487\n"}, {"input": "815449097320007662 942453891178865528\n", "output": "576460752303423487\n"}, {"input": "765369978472937483 796958953973862258\n", "output": "144115188075855871\n"}, {"input": "259703440079833303 857510033561081530\n", "output": "1152921504606846975\n"}, {"input": "181513087965617551 301910258955864271\n", "output": "576460752303423487\n"}, {"input": "28591024119784617 732203343197854927\n", "output": "1152921504606846975\n"}, {"input": "215365547805299155 861595308221385098\n", "output": "1152921504606846975\n"}, {"input": "1 1000000000000000000\n", "output": "1152921504606846975\n"}, {"input": "1000000000000 999999999999999999\n", "output": "1152921504606846975\n"}, {"input": "1 1\n", "output": "0\n"}, {"input": "9999999999998 9999999999999\n", "output": "1\n"}, {"input": "9999999999900 9999999999901\n", "output": "1\n"}, {"input": "9999999999900 9999999999902\n", "output": "3\n"}, {"input": "9999999999900 9999999999903\n", "output": "3\n"}, {"input": "1 3\n", "output": "3\n"}, {"input": "5000000 5900000\n", "output": "2097151\n"}, {"input": "8589934592 8989934592\n", "output": "536870911\n"}]
310
You are given a set of $2n+1$ integer points on a Cartesian plane. Points are numbered from $0$ to $2n$ inclusive. Let $P_i$ be the $i$-th point. The $x$-coordinate of the point $P_i$ equals $i$. The $y$-coordinate of the point $P_i$ equals zero (initially). Thus, initially $P_i=(i,0)$. The given points are vertices of a plot of a piecewise function. The $j$-th piece of the function is the segment $P_{j}P_{j + 1}$. In one move you can increase the $y$-coordinate of any point with odd $x$-coordinate (i.e. such points are $P_1, P_3, \dots, P_{2n-1}$) by $1$. Note that the corresponding segments also change. For example, the following plot shows a function for $n=3$ (i.e. number of points is $2\cdot3+1=7$) in which we increased the $y$-coordinate of the point $P_1$ three times and $y$-coordinate of the point $P_5$ one time: [Image] Let the area of the plot be the area below this plot and above the coordinate axis OX. For example, the area of the plot on the picture above is 4 (the light blue area on the picture above is the area of the plot drawn on it). Let the height of the plot be the maximum $y$-coordinate among all initial points in the plot (i.e. points $P_0, P_1, \dots, P_{2n}$). The height of the plot on the picture above is 3. Your problem is to say which minimum possible height can have the plot consisting of $2n+1$ vertices and having an area equal to $k$. Note that it is unnecessary to minimize the number of moves. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $10^{18}$. -----Input----- The first line of the input contains two integers $n$ and $k$ ($1 \le n, k \le 10^{18}$) β€” the number of vertices in a plot of a piecewise function and the area we need to obtain. -----Output----- Print one integer β€” the minimum possible height of a plot consisting of $2n+1$ vertices and with an area equals $k$. It is easy to see that any answer which can be obtained by performing moves described above always exists and is an integer number not exceeding $10^{18}$. -----Examples----- Input 4 3 Output 1 Input 4 12 Output 3 Input 999999999999999999 999999999999999986 Output 1 -----Note----- One of the possible answers to the first example: [Image] The area of this plot is 3, the height of this plot is 1. There is only one possible answer to the second example: $M M$ The area of this plot is 12, the height of this plot is 3.
interview
[{"code": "N, K = list(map(int, input().split()))\n\nprint((K+N-1)//N)\n", "passed": true, "time": 0.83, "memory": 14272.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\nprint((k + n - 1) // n)\n", "passed": true, "time": 0.15, "memory": 14300.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nh = k // n\nif h * n < k:\n h += 1\nprint(h)\n", "passed": true, "time": 0.15, "memory": 14236.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\nprint((k + n - 1) // n)\n", "passed": true, "time": 0.28, "memory": 14364.0, "status": "done"}, {"code": "a,b=map(int,input().split(' '))\nprint((b+a-1)//a)", "passed": true, "time": 0.83, "memory": 14264.0, "status": "done"}, {"code": "\n\n\n\nn, k = list(map(int, input().split()))\n\na, b, c = 0, k, 0\n\nwhile a < b:\n c = (a + b) // 2\n if c * n < k:\n a = c + 1\n else:\n b = c\n\nprint(a)\n", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nprint((k + n - 1) // n)", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}, {"code": "n,k=map(int,input().split())\nprint(-(-k//n))", "passed": true, "time": 0.18, "memory": 14268.0, "status": "done"}, {"code": "USE_STDIO = False\n\nif not USE_STDIO:\n try: import mypc\n except: pass\n\ndef main():\n n, k = list(map(int, input().split(' ')))\n ans = (k + n - 1) // n\n print(ans)\n\ndef __starting_point():\n main()\n\n\n\n\n__starting_point()", "passed": true, "time": 0.27, "memory": 14488.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\np = (k - 1) // n + 1\nprint(p)\n", "passed": true, "time": 0.24, "memory": 14496.0, "status": "done"}, {"code": "n,k=map(int,input().split())\n\nans=k//n\nif(k%n):\n ans+=1\nprint(ans)", "passed": true, "time": 0.29, "memory": 14268.0, "status": "done"}, {"code": "n, k = list(map(int , input().split()))\ns = k // n\nif k % n != 0:\n s += 1\nprint(s)\n", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nprint(m // n + (1 if m % n else 0))\n", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "n,k = list(map(int,input().split()))\nprint(-(-k//n))\n", "passed": true, "time": 0.14, "memory": 14404.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 dprint('debug mode')\nexcept ModuleNotFoundError:\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\nr= K//N\nif K%N!=0: r+=1\n\nprint(r)\n\n\n\n\n\n\n", "passed": true, "time": 0.14, "memory": 14448.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\nprint((b+a-1)//a)\n", "passed": true, "time": 0.17, "memory": 14276.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nprint(k // n + (k % n != 0))\n", "passed": true, "time": 0.16, "memory": 14340.0, "status": "done"}, {"code": "[n, k]=[int(i) for i in input().split()]\nprint((k+n-1)//n)", "passed": true, "time": 0.27, "memory": 14496.0, "status": "done"}, {"code": "a,b = (list(map(int,input().split())))\nprint((b+a-1)//a)\n", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nq = 2 * n + 1\np = k // n\nif k % n:\n print(p + 1)\nelse:\n print(p)", "passed": true, "time": 0.14, "memory": 14412.0, "status": "done"}, {"code": "import sys\nf=sys.stdin\nout=sys.stdout\n\nn,k=map(int,f.readline().rstrip('\\r\\n').split())\nif k%n==0:\n\tout.write(str(k//n)+'\\n')\nelse:\n\tout.write(str((k//n)+1)+'\\n')", "passed": true, "time": 0.18, "memory": 14320.0, "status": "done"}, {"code": "(n, k) = map(int, input().split())\n\nprint((k + n - 1) // n)", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nif k % n == 0:\n print(k // n)\nelse:\n print(k // n + 1)\n", "passed": true, "time": 0.15, "memory": 14496.0, "status": "done"}, {"code": "n, k = map(int, input().strip().split(' '))\n\nif k % n == 0:\n print(k // n)\nelse:\n print(k // n + 1)", "passed": true, "time": 0.14, "memory": 14424.0, "status": "done"}, {"code": "s = input().split()\nn, k = int(s[0]), int(s[1])\nt = k//n\nif n*t==k:\n print(t)\nelse:\n print(t+1)", "passed": true, "time": 0.14, "memory": 14220.0, "status": "done"}]
[{"input": "4 3\n", "output": "1\n"}, {"input": "4 12\n", "output": "3\n"}, {"input": "999999999999999999 999999999999999986\n", "output": "1\n"}, {"input": "1000000000000000000 1000000000000000000\n", "output": "1\n"}, {"input": "1000000000000000000 999999999999999999\n", "output": "1\n"}, {"input": "999999999999999999 1000000000000000000\n", "output": "2\n"}, {"input": "1 1000000000000000000\n", "output": "1000000000000000000\n"}, {"input": "1 1\n", "output": "1\n"}, {"input": "1000000001 1000000000000000000\n", "output": "1000000000\n"}, {"input": "4 10\n", "output": "3\n"}, {"input": "5 13\n", "output": "3\n"}, {"input": "24 3\n", "output": "1\n"}, {"input": "4 2\n", "output": "1\n"}, {"input": "6 10\n", "output": "2\n"}, {"input": "999 1001\n", "output": "2\n"}, {"input": "10 25\n", "output": "3\n"}, {"input": "4 15\n", "output": "4\n"}, {"input": "3 5\n", "output": "2\n"}, {"input": "4 6\n", "output": "2\n"}, {"input": "10 2\n", "output": "1\n"}, {"input": "4 14\n", "output": "4\n"}, {"input": "5 8\n", "output": "2\n"}, {"input": "5 5\n", "output": "1\n"}, {"input": "6 1\n", "output": "1\n"}, {"input": "4 11\n", "output": "3\n"}, {"input": "2 999999999999999\n", "output": "500000000000000\n"}, {"input": "2639396 2768849\n", "output": "2\n"}, {"input": "1 1234567\n", "output": "1234567\n"}, {"input": "7 9\n", "output": "2\n"}, {"input": "11111111111111111 12\n", "output": "1\n"}, {"input": "1887415157 2048\n", "output": "1\n"}, {"input": "3 8\n", "output": "3\n"}, {"input": "10 45\n", "output": "5\n"}, {"input": "12839719 1294012934\n", "output": "101\n"}, {"input": "999999999999999986 999999999999999999\n", "output": "2\n"}, {"input": "7 1000000000000000000\n", "output": "142857142857142858\n"}, {"input": "3 999999999999999999\n", "output": "333333333333333333\n"}, {"input": "312312 421412412412\n", "output": "1349332\n"}, {"input": "3 14\n", "output": "5\n"}, {"input": "3 11\n", "output": "4\n"}, {"input": "499999999999999182 999999999999999713\n", "output": "3\n"}, {"input": "5 7\n", "output": "2\n"}, {"input": "7 156\n", "output": "23\n"}, {"input": "2 13\n", "output": "7\n"}, {"input": "10 1025\n", "output": "103\n"}, {"input": "2 34\n", "output": "17\n"}, {"input": "846930886 1804289383\n", "output": "3\n"}, {"input": "7 99999999999999999\n", "output": "14285714285714286\n"}, {"input": "11 117\n", "output": "11\n"}, {"input": "10 10000000000000005\n", "output": "1000000000000001\n"}, {"input": "10 100000000000005\n", "output": "10000000000001\n"}, {"input": "3 1000000000000000000\n", "output": "333333333333333334\n"}, {"input": "2 999999999999999995\n", "output": "499999999999999998\n"}, {"input": "1 99999999999999999\n", "output": "99999999999999999\n"}, {"input": "2 1\n", "output": "1\n"}, {"input": "2 3\n", "output": "2\n"}, {"input": "2 999999999999999990\n", "output": "499999999999999995\n"}, {"input": "8 999999999999999997\n", "output": "125000000000000000\n"}, {"input": "2 5\n", "output": "3\n"}, {"input": "5 1\n", "output": "1\n"}]
313
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying. One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes). The University works in such a way that every day it holds exactly n lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks). The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the n pairs she knows if there will be a class at that time or not. Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university. Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home. Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair. -----Input----- The first line of the input contains a positive integer n (1 ≀ n ≀ 100) β€” the number of lessons at the university. The second line contains n numbers a_{i} (0 ≀ a_{i} ≀ 1). Number a_{i} equals 0, if Alena doesn't have the i-th pairs, otherwise it is equal to 1. Numbers a_1, a_2, ..., a_{n} are separated by spaces. -----Output----- Print a single number β€” the number of pairs during which Alena stays at the university. -----Examples----- Input 5 0 1 0 1 1 Output 4 Input 7 1 0 1 0 0 1 0 Output 4 Input 1 0 Output 0 -----Note----- In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair. In the last sample Alena doesn't have a single pair, so she spends all the time at home.
interview
[{"code": "n = int(input())\na = list(map(int, input().split()))\nc = 0\nl = 0\nb = 0\nwhile c < len(a) and a[c] == 0:\n c += 1\n b += 1\n\nif c == len(a):\n print(0)\n return\n\nd = len(a) - 1\nwhile a[d] != 1:\n d -= 1\n b += 1\n\nwhile c <= d:\n if a[c] == 0:\n l += 1\n else:\n if l > 1:\n b += l\n l = 0\n c += 1\n\nprint(n - b)", "passed": true, "time": 0.14, "memory": 14560.0, "status": "done"}, {"code": "input()\nl = list(map(int, input().split()))\nwhile l and l[0] == 0:\n\tl = l[1:]\nwhile l and l[-1] == 0:\n\tl = l[:-1]\nfor i in range(1, len(l) - 1):\n\tif l[i-1] == 1 and l[i] == 0 and l[i+1] == 1:\n\t\tl[i] = 1\nprint(l.count(1))\n\t\t\n", "passed": true, "time": 0.15, "memory": 14408.0, "status": "done"}, {"code": "n = int(input())\nmas=list(map(int,input().split(\" \")))\np=0\nres=0\nfor i in range(n):\n if mas[i]==0:\n if i>0 and i<n-1:\n if mas[i-1]==1 and mas[i+1]==1:\n mas[i]=1\nprint(sum(mas))\n", "passed": true, "time": 0.22, "memory": 14312.0, "status": "done"}, {"code": "n=int(input())\nl=list(map(int,input().split()))\nfor i in range(2,n):\n if l[i]==1 and l[i-1]==0 and l[i-2]==1: l[i-1]=1\nprint(l.count(1))", "passed": true, "time": 0.15, "memory": 14468.0, "status": "done"}, {"code": "n = int(input())\na = [int(v) for v in input().split()]\n\nfor i in range(1, len(a) - 1):\n\tif a[i - 1] == 1 and a[i + 1] == 1:\n\t\ta[i] = 1\n\nprint(sum(a))", "passed": true, "time": 0.15, "memory": 14412.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\ncount = 0\ni = 0\nwhile i < n and a[i] == 0:\n i += 1\nwhile i < n:\n if a[i] == 1:\n i += 1\n count += 1\n else:\n tmp = 0\n while i < n and a[i] == 0:\n tmp += 1\n i += 1\n if i != n and tmp < 2:\n count += tmp\nprint(count)", "passed": true, "time": 0.15, "memory": 14580.0, "status": "done"}, {"code": "n = int(input())\n\ns = input()\n\na = s.split(\" \")\n\na = [int(i) for i in a]\nc = 0\nr = 0\nfor i in range(n):\n if i == n-1:\n if a[i] == 1:\n c += 1\n \n elif r>0:\n if a[i] == 0 and a[i+1] == 0:\n r = 0\n else:\n c += 1\n else:\n if a[i] == 1:\n c += 1\n r = 1\nprint (c)\n", "passed": true, "time": 0.24, "memory": 14312.0, "status": "done"}, {"code": "input()\npprev, prev = None, None\nans = 0\nfor i in input().split():\n if i == '1':\n ans += 1\n if prev == '0' and pprev == '1':\n ans += 1\n pprev, prev = prev, i\nprint(ans)\n", "passed": true, "time": 0.24, "memory": 14428.0, "status": "done"}, {"code": "import sys\nimport re\nsys.stdin.readline()\ns = sys.stdin.readline()\ns = re.sub('[^01]','',s)\ns = s.strip('0')\ns = re.sub('0{2,}','',s)\n#print(repr(s))\nprint(len(s))\n\n", "passed": true, "time": 0.21, "memory": 14444.0, "status": "done"}, {"code": "n = int(input())\na = [int(i) for i in input().split(\" \")]\nwas_one = False;\nres = sum(a)\nzeros = 0;\nfor i in a:\n\tif (i == 1):\n\t\twas_one = True\n\t\tif (zeros == 1):\n\t\t\tres += 1\n\t\tzeros = 0\n\tif (was_one and i == 0):\n\t\tzeros += 1\nprint(res)", "passed": true, "time": 0.23, "memory": 14352.0, "status": "done"}, {"code": "n = int(input())\narray = list(map(int, input().split()))\ncount = sum(array)\nfor i in range(1, n - 1):\n #if (array[i - 1] == array[i]) and array[i] == 0:\n # print(i, 'TUTA')\n # count += 1\n if array[i] == 0 and array[i - 1] == 1 and array[i + 1] == 1:\n count += 1\nprint(count)\n", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}, {"code": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nn = int(input())\nA = list(map(int,input().split()))\n\nattends = 0\ni = 0\nwhile i < n:\n if A[i] == 1:\n attends += 1\n else:\n if 0 < i < n - 1 and A[i-1] == 1 and A[i+1] == 1:\n attends += 2\n i += 1\n i += 1\nprint(attends)\n", "passed": true, "time": 0.15, "memory": 14460.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport re\n\nN = int(input())\nS = input()\nS = S.replace(\" \", \"\")\nS = S.strip(\"0\")\n\nret = 0\nfor seg in re.split(\"00+\", S):\n ret += len(seg)\n\nprint(ret)\n\n", "passed": true, "time": 0.14, "memory": 14216.0, "status": "done"}, {"code": "n = int(input())\nlst = [int(x) for x in input().split()]\n\n\natuniversity = False\nbreak_length = 0\ntime = 0\n\nfor lesson in lst:\n\tif lesson == 1:\n\t\tatuniversity = True\n\t\tbreak_length = 0\n\telif lesson == 0:\n\t\tbreak_length += 1\n\t\tif break_length >= 2:\n\t\t\tif atuniversity:\n\t\t\t\ttime -= 1\n\t\t\tatuniversity = False\n\n\tif atuniversity:\n\t\ttime += 1\n\ntry:\n\tif lst[-1] == 0 and lst[-2] == 1:\n\t\ttime -= 1\nexcept IndexError:\n\tpass\n\nprint(time)", "passed": true, "time": 0.23, "memory": 14360.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\n\nans = 0\nfor i, e in enumerate(a):\n if e == 1:\n ans += 1\n else:\n if i < len(a) - 1 and i > 0 and\\\n a[i + 1] == 1 and a[i - 1] == 1:\n ans += 1\n\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14392.0, "status": "done"}, {"code": "def read_numbers():\n return list(map(int, input().split()))\n\ndef f(pairs):\n while pairs and pairs[0] == 0:\n pairs.pop(0)\n while pairs and pairs[-1] == 0:\n pairs.pop()\n\n count = 0\n parity = False\n tmp_count = 0\n for i in pairs:\n if i:\n if parity:\n tmp_count += 1\n parity = False\n tmp_count += 1\n else:\n if not parity:\n parity = True\n else:\n count += tmp_count\n tmp_count = 0\n if tmp_count == 0:\n parity = False\n\n count += tmp_count\n return count\n\n\n\ndef __starting_point():\n n = int(input())\n numbers = read_numbers()\n print(f(numbers))\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14416.0, "status": "done"}, {"code": "n = int(input())\na = [int(x) for x in input().split()]\nk = 0\nwhile k < n and a[k] != 1:\n k += 1\nm = n - 1\nwhile m >= 0 and a[m] != 1:\n m -= 1\nans = m - k + 1\nfor i in range(k + 1, m):\n if a[i] == 0 and (a[i - 1] == 0 or a[i + 1] == 0):\n ans -= 1\nprint(max(0, ans))", "passed": true, "time": 0.15, "memory": 14500.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()\nans = 0\ni = 0\n\nwhile(i < len(a)):\n if a[i] == 1:\n break\n i += 1\n\n\nwhile(i < len(a)-1):\n if a[i] == 0 and a[i+1] == 1 and a[i-1] == 1:\n a[i] = 1\n i\n i += 1\n\nprint(sum(a))\n\nfinish = time.time()\n#print(finish - start)\n", "passed": true, "time": 0.14, "memory": 14428.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nans = sum(a)\nfor i in range(1, n - 1):\n if a[i] == 0 and a[i + 1] == 1 and a[i - 1] == 1:\n ans += 1\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14496.0, "status": "done"}, {"code": "n = input()\nlessons = input().split()\nprev = '0'\nhome = True\ncnt = 0\nfor l in lessons:\n if l == '0' and prev == '0':\n home = True\n elif l == '1':\n cnt += 1\n if prev == '0' and not home:\n cnt += 1\n home = False\n prev = l\nprint(cnt)\n\n\n", "passed": true, "time": 0.15, "memory": 14348.0, "status": "done"}, {"code": "n=int(input())\na=input()\na=a.replace(' ','')\na=a+'00'\nc=2\nh=0\nfor i in a:\n if i=='0':\n c+=1\n else:\n if c==1:\n h+=2\n else:\n h+=1\n c=0\nprint(h)", "passed": true, "time": 0.14, "memory": 14400.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split(' ')[:n]))\nres = 0\nstate = 0\nfor x in a:\n if state == 0:\n if x == 0:\n pass\n else:\n state = 1\n res += 1\n elif state == 1:\n if x == 0:\n state = 2\n else:\n res += 1\n elif state == 2:\n if x == 0:\n state = 0\n else:\n state = 1\n res += 2\n\nprint(res)\n", "passed": true, "time": 0.22, "memory": 14348.0, "status": "done"}, {"code": "n = int(input())\nl = list(map(int, input().split()))\ncnt = 0\n#print(l)\nstop = -1\nfor i in range(n):\n if l[i] == 1:\n break\n else:\n stop = i\nwhile l and l[-1] == 0:\n l.pop(-1)\n#print(l)\nfor i in range(stop+1, len(l)):\n #print(i)\n if i <= len(l)-2:\n if (i<len(l)-1 and l[i] == 0 and l[i+1] == 0) or (i>0 and l[i] == 0 and l[i-1]==0):\n pass\n #print(\"bob\")\n elif l[i] == 1 or l[i+1] == 1 or l[i+2] == 1:\n cnt += 1\n #print(\"add\")\n elif i <= len(l)-2:\n if l[i+1] == 1:\n #print(\"add\")\n cnt += 1\n elif l[i] == 1:\n #print(\"add\")\n cnt += 1\n \nprint(cnt)\n", "passed": true, "time": 0.14, "memory": 14484.0, "status": "done"}, {"code": "n = int(input())\nl = list(map(int, input().split()))\nres = 0\nfor i in range(n):\n if l[i]: res += 1\n elif i > 0 and i < n - 1 and l[i - 1]and l[i + 1]: res += 1\n else: continue\nprint(res) \n", "passed": true, "time": 0.15, "memory": 14496.0, "status": "done"}, {"code": "n = int(input())\na = [int(x) for x in input().split()]\ntime = 0\ntry:\n start = a.index(1)\nexcept:\n print(0)\n return\ncurrent = a[start]\nzero_in_row = 0\nf = lambda x: 1 if x == 1 else 0\n\nfor i in range(start, n):\n if a[i] == 1:\n time += f(zero_in_row)\n zero_in_row = 0\n time += 1\n else:\n zero_in_row += 1\n\nprint(time)\n", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}]
[{"input": "5\n0 1 0 1 1\n", "output": "4\n"}, {"input": "7\n1 0 1 0 0 1 0\n", "output": "4\n"}, {"input": "1\n0\n", "output": "0\n"}, {"input": "1\n1\n", "output": "1\n"}, {"input": "2\n0 0\n", "output": "0\n"}, {"input": "2\n0 1\n", "output": "1\n"}, {"input": "2\n1 0\n", "output": "1\n"}, {"input": "2\n1 1\n", "output": "2\n"}, {"input": "10\n0 0 0 0 0 0 0 0 0 0\n", "output": "0\n"}, {"input": "9\n1 1 1 1 1 1 1 1 1\n", "output": "9\n"}, {"input": "11\n0 0 0 0 0 0 0 0 0 0 1\n", "output": "1\n"}, {"input": "12\n1 0 0 0 0 0 0 0 0 0 0 0\n", "output": "1\n"}, {"input": "20\n1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 0 0 1 0 0\n", "output": "16\n"}, {"input": "41\n1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 1 1 0 1 0 1 1 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 1 1\n", "output": "28\n"}, {"input": "63\n1 1 0 1 1 0 0 0 1 1 0 0 1 1 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0 1 0 1 0\n", "output": "39\n"}, {"input": "80\n0 1 1 1 0 1 1 1 1 1 0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 0 1 0 1 0 0 0 1 1 0 1 1 0 0 0 0 1 1 1 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1\n", "output": "52\n"}, {"input": "99\n1 1 0 0 0 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 0 1 0 0 1 1 0 1 0 0 1 1 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1\n", "output": "72\n"}, {"input": "100\n0 1 1 0 1 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 1 0 0 1 0 0 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 0 1 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1 0\n", "output": "65\n"}, {"input": "11\n0 1 1 0 0 0 0 0 0 0 0\n", "output": "2\n"}, {"input": "11\n0 1 0 1 0 0 1 1 0 1 1\n", "output": "8\n"}, {"input": "11\n1 0 1 0 1 1 0 1 1 1 0\n", "output": "10\n"}, {"input": "11\n1 0 0 0 0 0 1 0 1 1 1\n", "output": "6\n"}, {"input": "22\n0 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 1 0\n", "output": "7\n"}, {"input": "22\n0 1 0 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1\n", "output": "16\n"}, {"input": "22\n1 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0\n", "output": "11\n"}, {"input": "22\n1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 1 0 1\n", "output": "14\n"}, {"input": "33\n0 1 1 0 1 1 0 1 0 1 1 0 1 1 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 1 1 0 0\n", "output": "26\n"}, {"input": "33\n0 1 0 1 0 1 1 0 0 0 1 1 1 0 1 0 1 1 0 1 0 1 0 0 1 1 1 0 1 1 1 0 1\n", "output": "27\n"}, {"input": "33\n1 0 1 0 1 0 0 0 1 0 1 1 1 0 0 0 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 1 0\n", "output": "25\n"}, {"input": "33\n1 0 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 0 1 1\n", "output": "24\n"}, {"input": "44\n0 1 1 0 1 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 1 1 1 0 0 1 0 1 1 0 0\n", "output": "19\n"}, {"input": "44\n0 1 1 1 1 0 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 1\n", "output": "32\n"}, {"input": "44\n1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 1 0 0 1 0\n", "output": "23\n"}, {"input": "44\n1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1\n", "output": "32\n"}, {"input": "55\n0 1 1 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 0 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0\n", "output": "23\n"}, {"input": "55\n0 1 1 0 1 0 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0 1 1 0 0 0 1\n", "output": "39\n"}, {"input": "55\n1 0 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 0 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1 0 0\n", "output": "32\n"}, {"input": "55\n1 0 1 0 1 0 1 0 1 1 0 0 1 1 1 1 0 1 0 0 0 1 1 0 0 1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 1 1\n", "output": "36\n"}, {"input": "66\n0 1 1 0 0 1 0 1 0 1 0 1 1 0 1 1 0 0 1 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 1 1 1 1 1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 1 1 0 1 1 1 0 0 0 0 0 1 0\n", "output": "41\n"}, {"input": "66\n0 1 1 0 1 1 1 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 0 1\n", "output": "42\n"}, {"input": "66\n1 0 1 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 0 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 1 0 1 0 0 0 1 1 0 1 0 1 1 0 0 0 1 1 0 1 1 0 1 1 0 0\n", "output": "46\n"}, {"input": "66\n1 0 1 0 0 0 1 1 1 1 1 0 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 0 0 0 1 0 1 1 0 0 0 1\n", "output": "46\n"}, {"input": "77\n0 0 1 0 0 1 0 0 1 1 1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 0 1 0 1 1 0 1 1 1 0 1 1 0 1 0\n", "output": "47\n"}, {"input": "77\n0 0 1 0 0 0 1 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 0 0 0 1 1 0 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1\n", "output": "44\n"}, {"input": "77\n1 0 0 0 1 0 1 1 0 0 1 0 0 0 1 1 1 1 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 1 1 1 0 1 1 1 0 0 0 1 1 0 1 1 1 0 1 1 0 0 1 0 0 1 1 1 1 0 1 0 0 0 1 0 1 1 0 0 0 0 0\n", "output": "45\n"}, {"input": "77\n1 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 1 1 1 1 1 1 1 0 0 1 1 0 0 1 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1\n", "output": "51\n"}, {"input": "88\n0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 1 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 0 0 1 0 0 0 1 0 1 1 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 1 1 1 0\n", "output": "44\n"}, {"input": "88\n0 0 1 0 0 0 1 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 0 1 1 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 1 1 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 1\n", "output": "59\n"}, {"input": "88\n1 0 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 1 1 0 0 1 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 0 0\n", "output": "53\n"}, {"input": "88\n1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 0 1\n", "output": "63\n"}, {"input": "99\n0 0 0 0 1 0 0 1 0 0 0 1 1 1 1 1 1 0 1 1 0 1 0 0 1 0 1 1 1 1 1 0 1 0 1 1 1 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 1 1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 0 1 1 0 0 0 0\n", "output": "56\n"}, {"input": "99\n0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 1 1 0 0 0 1 1 0 0 0 1 0 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 1 1 1\n", "output": "58\n"}, {"input": "99\n1 1 0 0 1 1 1 0 0 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0 1 0 1 1 0 1 0 1 1 1 1 0 0 1 0\n", "output": "65\n"}, {"input": "99\n1 1 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 0 1 0 0 1 1 1 1 1 0 1 1 0 1 1 0 0 0 1 0 1 0 1 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 1 1 1 1\n", "output": "77\n"}, {"input": "90\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\n", "output": "0\n"}, {"input": "90\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\n", "output": "90\n"}, {"input": "95\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\n", "output": "0\n"}, {"input": "95\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\n", "output": "95\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": "0\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": "100\n"}]
314
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds a_{i} candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later. Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n). Print -1 if she can't give him k candies during n given days. -----Input----- The first line contains two integers n and k (1 ≀ n ≀ 100, 1 ≀ k ≀ 10000). The second line contains n integers a_1, a_2, a_3, ..., a_{n} (1 ≀ a_{i} ≀ 100). -----Output----- If it is impossible for Arya to give Bran k candies within n days, print -1. Otherwise print a single integerΒ β€” the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. -----Examples----- Input 2 3 1 2 Output 2 Input 3 17 10 10 10 Output 3 Input 1 9 10 Output -1 -----Note----- In the first sample, Arya can give Bran 3 candies in 2 days. In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day. In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
interview
[{"code": "from sys import stdin, stdout\n\nn, k = list(map(int, stdin.readline().split()))\nvalues = list(map(int, stdin.readline().split()))\ncnt = 0\nsweet = 0\n\nfor i in range(n):\n cnt += values[i]\n \n v = min(min(cnt, 8), k - sweet)\n sweet += v \n cnt -= v\n \n if sweet == k:\n stdout.write(str(i + 1))\n break\nelse:\n stdout.write('-1')\n", "passed": true, "time": 0.26, "memory": 14544.0, "status": "done"}]
[{"input": "2 3\n1 2\n", "output": "2"}, {"input": "3 17\n10 10 10\n", "output": "3"}, {"input": "1 9\n10\n", "output": "-1"}, {"input": "10 70\n6 5 2 3 3 2 1 4 3 2\n", "output": "-1"}, {"input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99\n", "output": "18"}, {"input": "30 133\n3 2 3 4 3 7 4 5 5 6 7 2 1 3 4 6 7 4 6 4 7 5 7 1 3 4 1 6 8 5\n", "output": "30"}, {"input": "40 320\n70 79 21 64 95 36 63 29 66 89 30 34 100 76 42 12 4 56 80 78 83 1 39 9 34 45 6 71 27 31 55 52 72 71 38 21 43 83 48 47\n", "output": "40"}, {"input": "50 300\n5 3 11 8 7 4 9 5 5 1 6 3 5 7 4 2 2 10 8 1 7 10 4 4 11 5 2 4 9 1 5 4 11 9 11 2 7 4 4 8 10 9 1 11 10 2 4 11 6 9\n", "output": "-1"}, {"input": "37 30\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": "30"}, {"input": "100 456\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": "57"}, {"input": "90 298\n94 90 98 94 93 90 99 98 90 96 93 96 92 92 97 98 94 94 96 100 93 96 95 98 94 91 95 95 94 90 93 96 93 100 99 98 94 95 98 91 91 98 97 100 98 93 92 93 91 100 92 97 95 95 97 94 98 97 99 100 90 96 93 100 95 99 92 100 99 91 97 99 98 93 90 93 97 95 94 96 90 100 94 93 91 92 97 97 97 100\n", "output": "38"}, {"input": "7 43\n4 3 7 9 3 8 10\n", "output": "-1"}, {"input": "99 585\n8 2 3 3 10 7 9 4 7 4 6 8 7 11 5 8 7 4 7 7 6 7 11 8 1 7 3 2 10 1 6 10 10 5 10 2 5 5 11 6 4 1 5 10 5 8 1 3 7 10 6 1 1 3 8 11 5 8 2 2 5 4 7 6 7 5 8 7 10 9 6 11 4 8 2 7 1 7 1 4 11 1 9 6 1 10 6 10 1 5 6 5 2 5 11 5 1 10 8\n", "output": "-1"}, {"input": "30 177\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 8\n", "output": "-1"}, {"input": "19 129\n3 3 10 11 4 7 3 8 10 2 11 6 11 9 4 2 11 10 5\n", "output": "-1"}, {"input": "100 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": "100"}, {"input": "13 104\n94 55 20 96 86 76 13 71 13 1 32 76 69\n", "output": "13"}, {"input": "85 680\n61 44 55 6 30 74 27 26 17 45 73 1 67 71 39 32 13 25 79 66 4 59 49 28 29 22 10 17 98 80 36 99 52 24 59 44 27 79 29 46 29 12 47 72 82 25 6 30 81 72 95 65 30 71 72 45 39 16 16 89 48 42 59 71 50 58 31 65 91 70 48 56 28 34 53 89 94 98 49 55 94 65 91 11 53\n", "output": "85"}, {"input": "100 458\n3 6 4 1 8 4 1 5 4 4 5 8 4 4 6 6 5 1 2 2 2 1 7 1 1 2 6 5 7 8 3 3 8 3 7 5 7 6 6 2 4 2 2 1 1 8 6 1 5 3 3 4 1 4 6 8 5 4 8 5 4 5 5 1 3 1 6 7 6 2 7 3 4 8 1 8 6 7 1 2 4 6 7 4 8 8 8 4 8 7 5 2 8 4 2 5 6 8 8 5\n", "output": "100"}, {"input": "98 430\n4 7 6 3 4 1 7 1 1 6 6 1 5 4 6 1 5 4 6 6 1 5 1 1 8 1 6 6 2 6 8 4 4 6 6 8 8 7 4 1 2 4 1 5 4 3 7 3 2 5 7 7 7 2 2 2 7 2 8 7 3 4 5 7 8 3 7 6 7 3 2 4 7 1 4 4 7 1 1 8 4 5 8 3 1 5 3 5 2 1 3 3 8 1 3 5 8 6\n", "output": "98"}, {"input": "90 80\n6 1 7 1 1 8 6 6 6 1 5 4 2 2 8 4 8 7 7 2 5 7 7 8 5 5 6 3 3 8 3 5 6 3 4 2 6 5 5 3 3 3 8 6 6 1 8 3 6 5 4 8 5 4 3 7 1 3 2 3 3 7 7 7 3 5 2 6 2 3 6 4 6 5 5 3 2 1 1 7 3 3 4 3 4 2 1 2 3 1\n", "output": "18"}, {"input": "89 99\n7 7 3 5 2 7 8 8 1 1 5 7 7 4 1 5 3 4 4 8 8 3 3 2 6 3 8 2 7 5 8 1 3 5 3 6 4 3 6 2 3 3 4 5 1 6 1 7 7 7 6 7 7 7 8 8 8 2 1 7 5 8 6 7 7 4 7 5 7 8 1 3 5 8 7 1 4 2 5 8 3 4 4 5 5 6 2 4 2\n", "output": "21"}, {"input": "50 700\n4 3 2 8 8 5 5 3 3 4 7 2 6 6 3 3 8 4 2 4 8 6 5 4 5 4 5 8 6 5 4 7 2 4 1 6 2 6 8 6 2 5 8 1 3 8 3 8 4 1\n", "output": "-1"}, {"input": "82 359\n95 98 95 90 90 96 91 94 93 99 100 100 92 99 96 94 99 90 94 96 91 91 90 93 97 96 90 94 97 99 93 90 99 98 96 100 93 97 100 91 100 92 93 100 92 90 90 94 99 95 100 98 99 96 94 96 96 99 99 91 97 100 95 100 99 91 94 91 98 98 100 97 93 93 96 97 94 94 92 100 91 91\n", "output": "45"}, {"input": "60 500\n93 93 100 99 91 92 95 93 95 99 93 91 97 98 90 91 98 100 95 100 94 93 92 91 91 98 98 90 93 91 90 96 92 93 92 94 94 91 96 94 98 100 97 96 96 97 91 99 97 95 96 94 91 92 99 95 97 92 98 90\n", "output": "-1"}, {"input": "98 776\n48 63 26 3 88 81 27 33 37 10 2 89 41 84 98 93 25 44 42 90 41 65 97 1 28 69 42 14 86 18 96 28 28 94 78 8 44 31 96 45 26 52 93 25 48 39 3 75 94 93 63 59 67 86 18 74 27 38 68 7 31 60 69 67 20 11 19 34 47 43 86 96 3 49 56 60 35 49 89 28 92 69 48 15 17 73 99 69 2 73 27 35 28 53 11 1 96 50\n", "output": "97"}, {"input": "100 189\n15 14 32 65 28 96 33 93 48 28 57 20 32 20 90 42 57 53 18 58 94 21 27 29 37 22 94 45 67 60 83 23 20 23 35 93 3 42 6 46 68 46 34 25 17 16 50 5 49 91 23 76 69 100 58 68 81 32 88 41 64 29 37 13 95 25 6 59 74 58 31 35 16 80 13 80 10 59 85 18 16 70 51 40 44 28 8 76 8 87 53 86 28 100 2 73 14 100 52 9\n", "output": "24"}, {"input": "99 167\n72 4 79 73 49 58 15 13 92 92 42 36 35 21 13 10 51 94 64 35 86 50 6 80 93 77 59 71 2 88 22 10 27 30 87 12 77 6 34 56 31 67 78 84 36 27 15 15 12 56 80 7 56 14 10 9 14 59 15 20 34 81 8 49 51 72 4 58 38 77 31 86 18 61 27 86 95 36 46 36 39 18 78 39 48 37 71 12 51 92 65 48 39 22 16 87 4 5 42\n", "output": "21"}, {"input": "90 4\n48 4 4 78 39 3 85 29 69 52 70 39 11 98 42 56 65 98 77 24 61 31 6 59 60 62 84 46 67 59 15 44 99 23 12 74 2 48 84 60 51 28 17 90 10 82 3 43 50 100 45 57 57 95 53 71 20 74 52 46 64 59 72 33 74 16 44 44 80 71 83 1 70 59 61 6 82 69 81 45 88 28 17 24 22 25 53 97 1 100\n", "output": "1"}, {"input": "30 102\n55 94 3 96 3 47 92 85 25 78 27 70 97 83 40 2 55 12 74 84 91 37 31 85 7 40 33 54 72 5\n", "output": "13"}, {"input": "81 108\n61 59 40 100 8 75 5 74 87 12 6 23 98 26 59 68 27 4 98 79 14 44 4 11 89 77 29 90 33 3 43 1 87 91 28 24 4 84 75 7 37 46 15 46 8 87 68 66 5 21 36 62 77 74 91 95 88 28 12 48 18 93 14 51 33 5 99 62 99 38 49 15 56 87 52 64 69 46 41 12 92\n", "output": "14"}, {"input": "2 16\n10 6\n", "output": "2"}, {"input": "2 8\n7 8\n", "output": "2"}, {"input": "2 9\n4 8\n", "output": "2"}, {"input": "3 19\n9 9 1\n", "output": "3"}, {"input": "4 32\n9 9 9 5\n", "output": "4"}, {"input": "2 15\n14 1\n", "output": "2"}, {"input": "2 3\n3 3\n", "output": "1"}, {"input": "3 10\n10 1 1\n", "output": "2"}, {"input": "12 20\n3 16 19 10 1 6 17 8 6 20 1 4\n", "output": "4"}, {"input": "4 15\n14 3 3 3\n", "output": "2"}, {"input": "5 40\n10 10 10 10 1\n", "output": "5"}, {"input": "4 31\n9 9 8 5\n", "output": "4"}, {"input": "4 31\n20 7 1 1\n", "output": "-1"}, {"input": "2 10\n9 1\n", "output": "2"}, {"input": "10 50\n100 10 1 1 1 1 1 1 1 1\n", "output": "7"}, {"input": "2 11\n10 2\n", "output": "2"}, {"input": "3 21\n10 10 1\n", "output": "3"}, {"input": "2 2\n1 2\n", "output": "2"}, {"input": "3 2\n1 8 8\n", "output": "2"}, {"input": "2 11\n10 1\n", "output": "2"}, {"input": "2 16\n12 4\n", "output": "2"}, {"input": "3 11\n9 2 2\n", "output": "2"}, {"input": "3 11\n4 3 4\n", "output": "3"}, {"input": "2 13\n7 6\n", "output": "2"}, {"input": "3 24\n14 3 4\n", "output": "-1"}, {"input": "2 13\n10 3\n", "output": "2"}, {"input": "3 11\n9 2 1\n", "output": "2"}, {"input": "2 15\n12 3\n", "output": "2"}, {"input": "2 14\n11 4\n", "output": "2"}]
315
Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk. Empirically Polycarp learned that the dog needs at least k walks for any two consecutive days in order to feel good. For example, if k = 5 and yesterday Polycarp went for a walk with Cormen 2 times, today he has to go for a walk at least 3 times. Polycarp analysed all his affairs over the next n days and made a sequence of n integers a_1, a_2, ..., a_{n}, where a_{i} is the number of times Polycarp will walk with the dog on the i-th day while doing all his affairs (for example, he has to go to a shop, throw out the trash, etc.). Help Polycarp determine the minimum number of walks he needs to do additionaly in the next n days so that Cormen will feel good during all the n days. You can assume that on the day before the first day and on the day after the n-th day Polycarp will go for a walk with Cormen exactly k times. Write a program that will find the minumum number of additional walks and the appropriate scheduleΒ β€” the sequence of integers b_1, b_2, ..., b_{n} (b_{i} β‰₯ a_{i}), where b_{i} means the total number of walks with the dog on the i-th day. -----Input----- The first line contains two integers n and k (1 ≀ n, k ≀ 500)Β β€” the number of days and the minimum number of walks with Cormen for any two consecutive days. The second line contains integers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 500)Β β€” the number of walks with Cormen on the i-th day which Polycarp has already planned. -----Output----- In the first line print the smallest number of additional walks that Polycarp should do during the next n days so that Cormen will feel good during all days. In the second line print n integers b_1, b_2, ..., b_{n}, where b_{i}Β β€” the total number of walks on the i-th day according to the found solutions (a_{i} ≀ b_{i} for all i from 1 to n). If there are multiple solutions, print any of them. -----Examples----- Input 3 5 2 0 1 Output 4 2 3 2 Input 3 1 0 0 0 Output 1 0 1 0 Input 4 6 2 4 3 5 Output 0 2 4 3 5
interview
[{"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nans = 0\nfor i in range(1, n):\n diff = k - (a[i] + a[i - 1])\n if diff > 0:\n a[i] += diff\n ans += diff\n\nprint(ans)\nprint(' '.join(map(str, a)))\n\n", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "def solve():\n\tn, k = map(int, input().split())\n\ta = list(map(int, input().split()))\n\tres = 0\n\tfor i in range(1, len(a)):\n\t\ts = a[i] + a[i - 1]\n\t\tmoar = 0\n\t\tif s < k:\n\t\t\tmoar = k - s\n\t\ta[i] += moar\n\t\tres += moar\n\tprint(res)\n\tprint(\" \".join(map(str, a)))\n\nsolve()", "passed": true, "time": 0.14, "memory": 14536.0, "status": "done"}, {"code": "import sys, math, random\nn, k = list(map(int, input().split()))\nz = list(map(int, input().split()))\nans = 0\nfor i in range(n - 1):\n if z[i] + z[i + 1] < k:\n ans += k - z[i + 1] - z[i]\n z[i + 1] += k - z[i + 1] - z[i]\nprint(ans)\nprint(*z)\n \n", "passed": true, "time": 0.24, "memory": 14468.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nA = list(map(int, input().split()))\nB = [0] * n\nB[0] = A[0]\nfor i in range(1, n):\n\tB[i] = max(A[i], k - B[i - 1])\nprint(sum(B) - sum(A))\nprint(\" \".join(list(map(str, B))))\n", "passed": true, "time": 0.26, "memory": 14436.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nm = list(map(int, input().split()))\ns = [m[i] + m[i + 1] for i in range(n - 1)] + [0]\n\nans = 0\nfor i in range(n - 1):\n while s[i] < k:\n s[i] += 1\n s[i + 1] += 1\n m[i + 1] += 1\n ans += 1\nprint(ans)\nprint(*m)", "passed": true, "time": 0.15, "memory": 14288.0, "status": "done"}, {"code": "s = input().split(' ')\nn = int(s[0])\nk = int(s[1])\n\nd = [int(x) for x in input().split(' ')]\nover = 0\n\nfor i in range(n - 1):\n need = k - d[i + 1]\n if need <= 0:\n continue\n\n need -= d[i]\n if need > 0:\n d[i + 1] += need\n over += need\n\nprint(over)\nprint(' '.join([str(x) for x in d]))\n", "passed": true, "time": 0.26, "memory": 14304.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na = list(map(int, input().split()))\nans = 0\nfor i in range(1, n):\n if a[i] - (k - a[i - 1]) < 0:\n ans += a[i] - (k - a[i - 1])\n a[i] = k - a[i - 1]\nprint(abs(ans))\nprint(*a)", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nl = list(map(int, input().split()))\ncnt = 0\nfor i in range(n - 1):\n if l[i] + l[i + 1] < k:\n cnt += k - l[i] - l[i + 1]\n l[i + 1] += k - l[i] - l[i + 1]\nprint(cnt)\nprint(' '.join(map(str, l)))", "passed": true, "time": 1.7, "memory": 14276.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nline = list(map(int, input().split()))\ns = 0\nfor i in range(len(line) - 1):\n if line[i] + line[i + 1] < k:\n m = k - line[i] - line[i + 1]\n line[i + 1] += k - line[i] - line[i + 1]\n s += m\nprint(s)\nprint(\" \".join(map(str, line)))\n", "passed": true, "time": 0.14, "memory": 14512.0, "status": "done"}, {"code": "n,k=list(map(int,input().split()))\na=list(map(int,input().split()))\ns=0\nb=a[0]\nfor i in range(1,n):\n\tif b+a[i]<k:\n\t\ts+=k-b-a[i]\n\t\ta[i]=k-b\n\tb=a[i]\nprint(s)\nprint(*a)\n", "passed": true, "time": 1.7, "memory": 14448.0, "status": "done"}, {"code": "N,K = ( int(x) for x in input().split() )\nwalklist = [int(x) for x in input().split()]\ncost = 0\nfor i in range(1,N):\n\tif walklist[i] + walklist[i-1] < K:\n\t\tcost += K - (walklist[i] + walklist[i-1])\n\t\twalklist[i] = K - walklist[i-1] \n\nprint(cost)\nprint(\" \".join([str(x) for x in walklist]))\n", "passed": true, "time": 0.14, "memory": 14420.0, "status": "done"}, {"code": "n,k = map(int, input().split())\nnum = list(map(int, input().split()))\n\nans = 0\n\nfor i in range(1,n):\n if num[i]+num[i-1]<k:\n ans += k-(num[i]+num[i-1])\n num[i] = k-num[i-1]\n\nprint(ans)\nprint(' '.join([str(x) for x in num]))", "passed": true, "time": 0.4, "memory": 14316.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na = list(map(int, input().split()))\ncnt = 0\nfor i in range(1, n):\n\tif a[i] + a[i - 1] < k:\n\t\tcnt += k - a[i] - a[i - 1]\n\t\ta[i] += k - a[i] - a[i - 1]\nprint(cnt)\nprint(' '.join(map(str, a)))", "passed": true, "time": 0.15, "memory": 14320.0, "status": "done"}, {"code": "n, k = list(map(int,input().split()))\n\ndays = input().split()\n\nchanges = 0\n\nfor day in range(n-1):\n day1 = int(days[day])\n day2 = int(days[day+1])\n day2p = k-(day1+day2)\n if day2p > 0:\n changes+= day2p\n days[day+1] = str(day2+day2p)\n\nprint(changes)\n\nprint(\" \".join(days))\n", "passed": true, "time": 0.15, "memory": 14340.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\na = list(map(int, input().split()))\n\nresult = 0\n\nfor i in range(1, n):\n if a[i] + a[i-1] < k:\n result += k - a[i] - a[i-1]\n a[i] = (k - a[i-1])\nprint(result)\nprint(\" \".join(map(str, a)))\n", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "from sys import stdin\n\nn, k = list(map(int, stdin.readline().split()))\n\na = list(map(int, stdin.readline().split()))\n\n\ndef solve(walks: list) -> (int, list):\n new_walks = [0]\n for i in range(1, n):\n s = walks[i] + walks[i-1] + new_walks[i-1]\n new_walks.append(max(0, k - s))\n return sum(new_walks), new_walks\n\n\ndef print_result(number, walks):\n print(number)\n print(' '.join(str(a[i] + walks[i]) for i in range(n)))\n\nn1, result1 = solve(a)\nn2, result2 = solve(list(reversed(a)))\n\nif n1 <= n2:\n print_result(n1, result1)\nelse:\n print_result(n2, result2)\n", "passed": true, "time": 0.17, "memory": 14468.0, "status": "done"}, {"code": "n, k = (int(i) for i in input().split())\nl = [int(i) for i in input().split()]\nc = 0\nfor i in range(1, n):\n if l[i-1] + l[i] < k:\n a = k - (l[i-1] + l[i])\n c += a\n l[i] += a\nprint(c)\nprint(' '.join(str(i) for i in l))\n", "passed": true, "time": 0.14, "memory": 14512.0, "status": "done"}, {"code": "n,k = map(int,input().split())\nA = list(map(int, input().split()))\nans = 0\nfor j in range(1, n):\n if A[j] + A[j-1] < k:\n ans += k - A[j] - A[j-1]\n A[j] += k - A[j] - A[j-1]\n \nprint(ans)\nprint(' '.join(map(str, A)))", "passed": true, "time": 0.14, "memory": 14424.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 n, k = map(int, input().split())\n arr = list(map(int, input().split()))\n ans = 0\n for i in range(1, n):\n if arr[i] < k - arr[i - 1]:\n ans += k - arr[i - 1] - arr[i]\n arr[i] = k - arr[i - 1]\n print(ans)\n print(' '.join(str(i) for i in arr))\n__starting_point()", "passed": true, "time": 0.14, "memory": 14516.0, "status": "done"}, {"code": "def do():\n n,k = list(map(int,input().split()))\n a = list(map(int,input().split()))\n i = 0\n totalNeed = 0\n while(1):\n if (i+1 >= n): break\n curSum = a[i] + a[i+1] # check if i+1 > n\n need = k - curSum\n totalNeed += max(0, need)\n if (need > 0):\n a[i+1] += need\n i += 1\n print(totalNeed)\n return a\nrs = do()\ntobeprinted = \"\"\nfor r in rs:\n tobeprinted += (str(r) + \" \")\nprint(tobeprinted[:-1])\n", "passed": true, "time": 0.15, "memory": 14500.0, "status": "done"}]
[{"input": "3 5\n2 0 1\n", "output": "4\n2 3 2\n"}, {"input": "3 1\n0 0 0\n", "output": "1\n0 1 0\n"}, {"input": "4 6\n2 4 3 5\n", "output": "0\n2 4 3 5\n"}, {"input": "5 1\n0 0 0 0 1\n", "output": "2\n0 1 0 1 1\n"}, {"input": "10 500\n164 44 238 205 373 249 87 30 239 90\n", "output": "903\n164 336 238 262 373 249 251 249 251 249\n"}, {"input": "1 1\n1\n", "output": "0\n1\n"}, {"input": "5 1\n0 0 0 0 0\n", "output": "2\n0 1 0 1 0\n"}, {"input": "5 1\n0 0 0 0 1\n", "output": "2\n0 1 0 1 1\n"}, {"input": "5 2\n0 0 0 1 0\n", "output": "3\n0 2 0 2 0\n"}, {"input": "5 5\n1 4 0 0 0\n", "output": "6\n1 4 1 4 1\n"}, {"input": "5 10\n1 2 1 0 1\n", "output": "16\n1 9 1 9 1\n"}, {"input": "5 10\n0 1 0 1 0\n", "output": "18\n0 10 0 10 0\n"}, {"input": "10 5\n0 2 3 0 0 1 0 2 3 1\n", "output": "13\n0 5 3 2 3 2 3 2 3 2\n"}, {"input": "10 1\n0 0 0 0 0 0 0 0 1 0\n", "output": "4\n0 1 0 1 0 1 0 1 1 0\n"}, {"input": "10 436\n13 16 45 9 10 17 5 26 10 12\n", "output": "2017\n13 423 45 391 45 391 45 391 45 391\n"}, {"input": "10 438\n71 160 43 326 128 35 41 247 30 49\n", "output": "1060\n71 367 71 367 128 310 128 310 128 310\n"}, {"input": "10 431\n121 24 93 59 243 147 1 254 75 168\n", "output": "1036\n121 310 121 310 243 188 243 254 177 254\n"}, {"input": "10 10\n0 0 0 0 0 0 0 0 0 0\n", "output": "50\n0 10 0 10 0 10 0 10 0 10\n"}, {"input": "10 10\n0 0 1 0 0 0 1 0 0 0\n", "output": "48\n0 10 1 9 1 9 1 9 1 9\n"}, {"input": "10 10\n0 0 0 1 0 0 1 0 0 0\n", "output": "48\n0 10 0 10 0 10 1 9 1 9\n"}, {"input": "10 10\n1 1 0 2 0 1 1 1 2 0\n", "output": "41\n1 9 1 9 1 9 1 9 2 8\n"}, {"input": "10 10\n1 2 2 0 0 2 0 1 0 0\n", "output": "42\n1 9 2 8 2 8 2 8 2 8\n"}, {"input": "10 10\n1 0 1 0 0 5 2 0 0 1\n", "output": "40\n1 9 1 9 1 9 2 8 2 8\n"}, {"input": "10 10\n2 3 5 0 2 0 15 6 5 0\n", "output": "23\n2 8 5 5 5 5 15 6 5 5\n"}, {"input": "10 10\n16 15 4 10 14 2 18 11 24 5\n", "output": "0\n16 15 4 10 14 2 18 11 24 5\n"}, {"input": "100 100\n48 19 63 8 18 22 5 5 12 7 9 37 17 22 58 14 53 25 24 16 22 36 4 2 9 63 52 43 22 72 0 9 12 26 50 1 21 9 40 9 5 6 2 24 1 88 50 7 9 1 3 16 0 17 3 32 47 9 32 87 20 3 45 41 16 43 41 31 28 30 2 31 72 16 74 59 20 34 25 18 48 10 34 20 22 16 3 32 8 34 8 4 45 65 48 42 1 45 11 15\n", "output": "2588\n48 52 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 37 63 63 52 48 52 72 28 72 28 72 50 50 50 50 50 50 50 50 50 50 50 88 50 50 50 50 50 50 50 50 50 50 50 50 50 87 20 80 45 55 45 55 45 55 45 55 45 55 72 28 74 59 41 59 41 59 48 52 48 52 48 52 48 52 48 52 48 52 48 65 48 52 48 52 48 52\n"}, {"input": "100 200\n28 52 65 37 1 64 13 57 44 12 37 0 9 68 17 5 28 4 2 12 8 47 7 33 1 27 50 59 9 0 4 27 31 31 49 1 35 43 36 12 5 0 49 40 19 12 39 3 41 25 19 15 57 24 3 9 4 31 42 55 11 13 1 8 0 25 34 52 47 59 74 43 36 47 2 3 1 13 56 48 42 24 4 32 12 3 33 12 14 14 84 32 1 3 8 49 9 18 43 43\n", "output": "7390\n28 172 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 65 135 74 126 74 126 74 126 74 126 74 126 74 126 74 126 74 126 74 126 74 126 84 116 84 116 84 116 84 116 84 116\n"}, {"input": "100 10\n1 2 7 0 2 0 0 0 2 5 3 2 2 1 0 7 1 6 1 1 5 1 2 3 5 0 0 0 0 0 1 0 1 0 2 1 3 0 1 1 0 0 3 1 6 3 2 2 1 3 1 0 9 1 3 2 3 0 5 1 0 5 5 5 2 1 3 0 1 3 5 2 4 4 1 2 3 0 2 1 3 6 4 3 1 0 9 1 0 3 3 6 7 2 5 2 2 6 0 2\n", "output": "288\n1 9 7 3 7 3 7 3 7 5 5 5 5 5 5 7 3 7 3 7 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 4 6 4 6 4 6 4 9 1 9 2 8 2 8 2 8 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 4 6 4 6 9 1 9 3 7 6 7 3 7 3 7 6 4 6\n"}, {"input": "100 500\n207 27 83 171 129 204 11 55 58 115 43 280 208 169 23 79 36 59 132 28 13 136 246 134 29 135 176 21 155 175 127 288 68 68 41 156 194 31 44 131 30 31 89 46 180 184 12 29 2 58 70 157 329 294 126 55 79 19 125 15 39 30 2 137 36 151 5 246 176 1 158 31 4 99 192 200 124 66 10 195 180 165 8 79 257 68 5 175 43 141 0 106 38 32 0 56 33 221 144 226\n", "output": "14863\n207 293 207 293 207 293 207 293 207 293 207 293 208 292 208 292 208 292 208 292 208 292 246 254 246 254 246 254 246 254 246 288 212 288 212 288 212 288 212 288 212 288 212 288 212 288 212 288 212 288 212 288 329 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 206 294 257 243 257 243 257 243 257 243 257 243 257 243 257 243 257 243\n"}, {"input": "100 500\n64 140 15 221 24 106 73 30 275 97 296 55 5 30 47 199 130 44 72 170 7 204 359 40 128 117 45 192 344 112 0 11 196 78 73 53 222 93 88 151 99 283 60 71 4 87 226 46 66 74 23 89 77 60 397 181 0 101 358 54 124 155 19 218 9 140 161 130 308 85 103 85 300 128 19 108 225 136 100 54 30 24 129 245 128 88 160 120 51 154 19 129 114 32 256 30 102 207 115 49\n", "output": "13634\n64 436 64 436 64 436 73 427 275 225 296 204 296 204 296 204 296 204 296 204 296 204 359 141 359 141 359 192 344 156 344 156 344 156 344 156 344 156 344 156 344 283 217 283 217 283 226 274 226 274 226 274 226 274 397 181 319 181 358 142 358 155 345 218 282 218 282 218 308 192 308 192 308 192 308 192 308 192 308 192 308 192 308 245 255 245 255 245 255 245 255 245 255 245 256 244 256 244 256 244\n"}, {"input": "1 500\n500\n", "output": "0\n500\n"}, {"input": "2 1\n0 0\n", "output": "1\n0 1\n"}, {"input": "1 10\n1\n", "output": "0\n1\n"}, {"input": "1 4\n2\n", "output": "0\n2\n"}, {"input": "1 10\n2\n", "output": "0\n2\n"}, {"input": "1 10\n0\n", "output": "0\n0\n"}, {"input": "1 5\n1\n", "output": "0\n1\n"}, {"input": "1 2\n1\n", "output": "0\n1\n"}, {"input": "1 5\n2\n", "output": "0\n2\n"}, {"input": "1 3\n0\n", "output": "0\n0\n"}, {"input": "1 3\n1\n", "output": "0\n1\n"}, {"input": "1 5\n0\n", "output": "0\n0\n"}, {"input": "1 7\n0\n", "output": "0\n0\n"}, {"input": "1 7\n1\n", "output": "0\n1\n"}, {"input": "1 3\n2\n", "output": "0\n2\n"}, {"input": "1 5\n3\n", "output": "0\n3\n"}, {"input": "1 4\n3\n", "output": "0\n3\n"}, {"input": "1 6\n1\n", "output": "0\n1\n"}, {"input": "1 6\n2\n", "output": "0\n2\n"}, {"input": "1 500\n0\n", "output": "0\n0\n"}, {"input": "3 7\n2 3 1\n", "output": "3\n2 5 2\n"}, {"input": "1 10\n5\n", "output": "0\n5\n"}, {"input": "5 10\n1 2 3 4 5\n", "output": "10\n1 9 3 7 5\n"}, {"input": "2 6\n1 2\n", "output": "3\n1 5\n"}, {"input": "1 10\n3\n", "output": "0\n3\n"}, {"input": "1 6\n3\n", "output": "0\n3\n"}, {"input": "1 100\n1\n", "output": "0\n1\n"}, {"input": "1 7\n2\n", "output": "0\n2\n"}, {"input": "2 10\n1 2\n", "output": "7\n1 9\n"}, {"input": "1 9\n1\n", "output": "0\n1\n"}]
317
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. -----Input----- The first line contains a single integer n (1 ≀ n ≀ 100)Β β€” the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters. -----Output----- Output "YES", if the string is a pangram and "NO" otherwise. -----Examples----- Input 12 toosmallword Output NO Input 35 TheQuickBrownFoxJumpsOverTheLazyDog Output YES
interview
[{"code": "n = int(input())\ns = input()\na = [False for i in range(26)]\nfor x in s:\n a[ord(x.lower()) - ord('a')] = True\nfor x in a:\n if not x:\n print('NO')\n return\nprint('YES')\n", "passed": true, "time": 0.15, "memory": 14488.0, "status": "done"}, {"code": "n = int(input())\ns = input()\n\nmySet = set()\nfor c in s:\n mySet.add(c.lower())\n \nif len(mySet) == 26:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.15, "memory": 14508.0, "status": "done"}, {"code": "import string\nf = lambda: input()\nn = int(f())\n\ns = f().lower()\n\nret = True\n\nfor c in string.ascii_lowercase:\n if not c in s:\n ret = False\n break\n\nif ret:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14208.0, "status": "done"}, {"code": "n = int(input())\nmy_str = input().upper()\nalphabet = \"QWERTYUIOPASDFGHJKLZXCVBNM\"\ni = 0\nwhile i<26 and alphabet[i] in my_str:\n i += 1\nif i==26:\n print (\"YES\")\nelse:\n print (\"NO\")", "passed": true, "time": 0.25, "memory": 14300.0, "status": "done"}, {"code": "alth = \"abcdefghijklmnopqrstuvwxyz\"\nalth2 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\nn = int(input())\nt = input()\nnum3 = [0]*26\nfor i in t:\n if alth.find(i)!= -1:\n num3[alth.find(i)] = 1\n elif alth2.find(i)!= -1:\n num3[alth2.find(i)] = 1 \nif sum(num3) == 26:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.25, "memory": 14288.0, "status": "done"}, {"code": "\n\nnums = int(input())\nthe_str = str(input()).lower()\nd = set()\n\nfor ch in the_str:\n if ch >= 'a' and ch <= 'z':\n d.add(ch)\n\nif(len(d) == 26):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.16, "memory": 14484.0, "status": "done"}, {"code": "input()\ns = input()\ns = s.lower()\nall = set()\nfor i in s:\n all.add(i)\nif len(all) == 26:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.25, "memory": 14492.0, "status": "done"}, {"code": "class A:\n def A(self, n, s):\n alphabets = ['A', 'B', 'C', 'D', 'E', 'F', 'G',\n 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',\n 'U', 'V', 'W', 'X', 'Y', 'Z']\n s = s.upper()\n for i in alphabets:\n if i not in s:\n return \"NO\"\n return \"YES\"\n\ndef __starting_point():\n n = int(input())\n s = input()\n print(A().A(n,s))\n__starting_point()", "passed": true, "time": 0.25, "memory": 14388.0, "status": "done"}, {"code": "rng = int(input())\ninstr = list(input().lower())\n\nchars = []\nfor i in range(26):\n chars.append(0)\n\nfor char in range(rng):\n chars[ord(instr[char])-97] += 1\n\nisyes = True\nfor i in range(26):\n if chars[i] == 0:\n print('NO')\n isyes = False\n break\n\nif isyes:\n print('YES')\n", "passed": true, "time": 0.23, "memory": 14356.0, "status": "done"}, {"code": "n = int(input())\na = input()\nk = 1\na = a.lower()\nfor i in range(97,123):\n if a.count(chr(i)) == 0:\n k=0\n break\nif k:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.21, "memory": 14404.0, "status": "done"}, {"code": "def Main():\n num = input()\n str = list(input().lower())\n str.sort()\n str = \"\".join(str)\n \n for word in range (97, 123):\n symb = chr(word)\n if str.find(symb) == -1:\n print(\"NO\")\n return\n \n print (\"YES\")\n return\n\n \ndef __starting_point():\n Main()\n__starting_point()", "passed": true, "time": 0.15, "memory": 14428.0, "status": "done"}, {"code": "A = [0] * 26\nn = int(input())\ns = list(input().lower())\nfor i in s:\n A[ord(i) - ord('a')] += 1\nres = 'YES'\nfor i in A:\n if i == 0:\n res = 'NO' \nprint(res)", "passed": true, "time": 0.15, "memory": 14348.0, "status": "done"}, {"code": "n=int(input());\ns=input()\n\na=[ord(c) for c in s]\n\nfor i in range (0,n):\n if a[i]>96:\n a[i]=a[i]-32\n \ncounter=0;\nfor i in range (65,91):\n \n for j in range (0,n):\n if a[j]== i:\n counter=counter+1\n break\n \nif counter==26:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14424.0, "status": "done"}, {"code": "import string\n\nn = int(input())\ns = input()\ncnt = set()\nfor i in s.lower(): cnt.add(i)\ncnt = frozenset(cnt)\nprint(('NO', 'YES')[cnt == frozenset(string.ascii_lowercase)])\n", "passed": true, "time": 0.15, "memory": 14560.0, "status": "done"}, {"code": "def ok(x):\n x = x.lower()\n for i in 'abcdefghijklmnopqrstuvwxyz':\n if i.lower() not in x:\n return False\n return True\n\na = int(input())\nb = input()\nif ok(b):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14296.0, "status": "done"}, {"code": "import sys\nl=int(sys.stdin.readline())\nn=list(sys.stdin.readline())\na=[0]*26\nfor i in n[:-1]:\n j=ord(i)\n if j >91: j=j-32\n j=j-65\n a[j]=1\n if sum(a)==26:\n print(\"YES\")\n break\nif sum(a)!=26: print(\"NO\")", "passed": true, "time": 0.14, "memory": 14424.0, "status": "done"}, {"code": "input()\ns = input()\n\nall_el = set()\n\nfor i in range(len(s)):\n all_el.add(s[i].lower())\n\n\n\nif(26 == len(all_el)):\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.15, "memory": 14280.0, "status": "done"}, {"code": "input()\nprint('YES' if len(set(list(input().lower())))==26 else 'NO')", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "n = int(input())\nstr = input().lower()\nx = [0] * 50\nfor i in range(n) :\n x[ord(str[i]) - ord('a')] = 1\ncou = 0\nfor i in range(26) :\n cou += x[i]\nif cou >= 26:\n print('YES')\nelse :\n print('NO')", "passed": true, "time": 0.15, "memory": 14488.0, "status": "done"}, {"code": "n = int(input())\ns = input()\nss = len(set(s.lower()))\nif ss >= 26:\n\tprint('YES')\nelse :\n\tprint('NO')", "passed": true, "time": 0.15, "memory": 14196.0, "status": "done"}, {"code": "import string\ninput()\np = input()\nprint([\"NO\", \"YES\"][all(l in p.lower() for l in string.ascii_lowercase)])", "passed": true, "time": 0.15, "memory": 14524.0, "status": "done"}]
[{"input": "12\ntoosmallword\n", "output": "NO\n"}, {"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n", "output": "YES\n"}, {"input": "1\na\n", "output": "NO\n"}, {"input": "26\nqwertyuiopasdfghjklzxcvbnm\n", "output": "YES\n"}, {"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n", "output": "YES\n"}, {"input": "48\nthereisasyetinsufficientdataforameaningfulanswer\n", "output": "NO\n"}, {"input": "30\nToBeOrNotToBeThatIsTheQuestion\n", "output": "NO\n"}, {"input": "30\njackdawslovemybigsphinxofquarz\n", "output": "NO\n"}, {"input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY\n", "output": "YES\n"}, {"input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "NO\n"}, {"input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx\n", "output": "YES\n"}, {"input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ\n", "output": "YES\n"}, {"input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ\n", "output": "YES\n"}, {"input": "25\nnxYTzLFwzNolAumjgcAboyxAj\n", "output": "NO\n"}, {"input": "26\npRWdodGdxUESvcScPGbUoooZsC\n", "output": "NO\n"}, {"input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj\n", "output": "NO\n"}, {"input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa\n", "output": "YES\n"}, {"input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK\n", "output": "NO\n"}, {"input": "26\nvCUFRKElZOnjmXGylWQaHDiPst\n", "output": "NO\n"}, {"input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY\n", "output": "NO\n"}, {"input": "26\npGiFluRteQwkaVoPszJyNBChxM\n", "output": "NO\n"}, {"input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY\n", "output": "NO\n"}, {"input": "26\nLndjgvAEuICHKxPwqYztosrmBN\n", "output": "NO\n"}, {"input": "26\nMdaXJrCipnOZLykfqHWEStevbU\n", "output": "NO\n"}, {"input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba\n", "output": "NO\n"}, {"input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo\n", "output": "NO\n"}, {"input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa\n", "output": "NO\n"}, {"input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO\n", "output": "NO\n"}, {"input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe\n", "output": "NO\n"}, {"input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG\n", "output": "NO\n"}, {"input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF\n", "output": "NO\n"}, {"input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu\n", "output": "NO\n"}, {"input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf\n", "output": "NO\n"}, {"input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE\n", "output": "NO\n"}, {"input": "26\nDqspXZJTuONYieKgaHLMBwfVSC\n", "output": "NO\n"}, {"input": "26\necOyUkqNljFHRVXtIpWabGMLDz\n", "output": "NO\n"}, {"input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI\n", "output": "NO\n"}, {"input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA\n", "output": "NO\n"}, {"input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz\n", "output": "NO\n"}, {"input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ\n", "output": "NO\n"}, {"input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF\n", "output": "NO\n"}, {"input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB\n", "output": "NO\n"}, {"input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg\n", "output": "NO\n"}, {"input": "26\nmnbvcxxlkjhgfdsapoiuytrewq\n", "output": "NO\n"}, {"input": "26\naAbcdefghijklmnopqrstuvwxy\n", "output": "NO\n"}, {"input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl\n", "output": "NO\n"}, {"input": "25\nabcdefghijklmnopqrstuvwxy\n", "output": "NO\n"}, {"input": "26\nabcdefhijklmnopqrstVxyzABC\n", "output": "NO\n"}, {"input": "25\nqwertyuiopasdfghjklxcvbnm\n", "output": "NO\n"}, {"input": "34\nTheQuickBrownFoxJumpsOverTheLayDog\n", "output": "NO\n"}, {"input": "26\nabcdefghigklmnopqrstuvwxyz\n", "output": "NO\n"}, {"input": "26\nabcdefghijklmnopqrstuvwxyA\n", "output": "NO\n"}, {"input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM\n", "output": "NO\n"}, {"input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog\n", "output": "NO\n"}, {"input": "25\nbcdefghijklmnopqrstuvwxyz\n", "output": "NO\n"}, {"input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa\n", "output": "NO\n"}, {"input": "26\nabcdefghiklmnopqrstvxyzABC\n", "output": "NO\n"}, {"input": "26\nabcdefghijklmnopqrstuvwxzZ\n", "output": "NO\n"}, {"input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY\n", "output": "NO\n"}]
318
You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes. Note that you should find only the time after a minutes, see the examples to clarify the problem statement. You can read more about 24-hour format here https://en.wikipedia.org/wiki/24-hour_clock. -----Input----- The first line contains the current time in the format hh:mm (0 ≀ hh < 24, 0 ≀ mm < 60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes). The second line contains integer a (0 ≀ a ≀ 10^4) β€” the number of the minutes passed. -----Output----- The only line should contain the time after a minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed). See the examples to check the input/output format. -----Examples----- Input 23:59 10 Output 00:09 Input 20:20 121 Output 22:21 Input 10:10 0 Output 10:10
interview
[{"code": "def main():\n a, b = map(int, input().split(\":\"))\n c = int(input())\n\n a += c // 60\n b += c % 60\n if b > 59:\n b %= 60\n a += 1\n\n aa = str(a % 24)\n if len(aa) < 2:\n aa = \"0\" + aa\n\n bb = str(b % 60)\n if len(bb) < 2:\n bb = \"0\" + bb\n\n print(aa + \":\" + bb)\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14300.0, "status": "done"}, {"code": "import datetime\nimport time\n\nt = input()\nM = input()\nh, m = list(map(int, t.split(':')))\n\nH,M = divmod(int(M), 60)\n\na = datetime.datetime(100, 1, 1, h, m, 00)\nb = a + datetime.timedelta(0,0,0,0,M,H,0)\nprint(b.strftime('%H:%M'))\n", "passed": true, "time": 0.26, "memory": 16696.0, "status": "done"}, {"code": "h, m = [int(x) for x in input().split(':')]\na = int(input())\nx = h * 60 + m + a\nx = x % (60 * 24)\n\nprint(x // 600, x // 60 % 10, ':', x % 60 // 10, x % 60 % 10, sep='')\n", "passed": true, "time": 0.26, "memory": 14412.0, "status": "done"}, {"code": "def solve():\n S = input()\n a = int(input())\n\n hh = int(S[:2])\n mm = int(S[3:])\n\n mm += a\n hh += mm // 60\n mm %= 60\n\n hh %= 24\n\n print('%02d:%02d' % (hh, mm))\n\n\ndef __starting_point():\n solve()\n\n__starting_point()", "passed": true, "time": 0.25, "memory": 14500.0, "status": "done"}, {"code": "s = input()\np = s.find(':')\nh = int(s[:p])\nm = int(s[p + 1:])\na = int(input())\nm = m + 60 * h + a\nm %= 1440\nprint('%02d:%02d' % (m // 60, m % 60))\n", "passed": true, "time": 0.15, "memory": 14424.0, "status": "done"}, {"code": "hoursmin = input()\nhours = int(hoursmin[:2])\nminutes = int(hoursmin[3:])\na = int(input())\nnew_hours = str((hours * 60 + minutes + a) // 60 % 24)\nnew_minutes = str((hours * 60 + minutes + a) % 60)\nif len(new_hours) == 1:\n new_hours = '0' + new_hours\nif len(new_minutes) == 1:\n new_minutes = '0' + new_minutes\nprint('{}:{}'.format(new_hours, new_minutes))", "passed": true, "time": 0.24, "memory": 14340.0, "status": "done"}, {"code": "h, m = map(int, input().split(':'))\nafter = int(input())\n\n\nafm = (h * 60) + m + after\nafm %= 24 * 60\nprint('%.2d:%.2d' % (afm // 60, afm % 60), sep='')", "passed": true, "time": 0.25, "memory": 14532.0, "status": "done"}, {"code": "def inc(time):\n f = time[:2]\n m = time[2]\n s = time[3:]\n if s == '59':\n s = '00'\n if f == '23':\n f = '00'\n return f + m + s\n else:\n f = str(int(f) + 1)\n if len(f) == 1:\n f = '0' + f\n return f + m + s\n else:\n s = str(int(s) + 1)\n if len(s) == 1:\n s = '0' + s\n return f + m + s\n\ntime = input()\na = int(input())\nfor i in range(a):\n time = inc(time)\nprint(time)", "passed": true, "time": 0.19, "memory": 14504.0, "status": "done"}, {"code": "h, m = map(int, input().split(':'))\na = int(input())\nm += h * 60 + a\nh = (m // 60) % 24\nm %= 60\nh, m = str(h), str(m)\nif len(h) == 1:\n h = '0' + h\nif len(m) == 1:\n m = '0' + m\nprint(h + ':' + m)", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "[h,m] = [int(x) for x in input().split(':')]\na = int(input())\n\nnewm = (m + a) % 60\nnewh = (h + ((m + a) // 60)) % 24\n\nans = ''\nif (newm < 10 and newh < 10):\n ans = \"0{}:0{}\".format(newh, newm)\nelif (newm < 10):\n ans = \"{}:0{}\".format(newh, newm)\nelif (newh < 10):\n ans = \"0{}:{}\".format(newh, newm)\nelse:\n ans = \"{}:{}\".format(newh, newm)\nprint(ans)\n", "passed": true, "time": 0.23, "memory": 14324.0, "status": "done"}, {"code": "__author__ = 'Utena'\ntime=list(map(int,input().split(':')))\nn=int(input())\nn=n+time[1]\ntime[0]=(n//60+time[0])%24\nn=n%60\ntime[1]=n\nprint(str(time[0]).zfill(2)+':'+str(time[1]).zfill(2))", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}, {"code": "h,m=list(map(int,input().split(':')))\na=int(input())\n\n\nh+=((m+a)//60)\nm=(m+a)%60\nh%=24\n\nms=\"\"\nhs=\"\"\nif(h<10):\n hs+=\"0\"\nif(m<10):\n ms+=\"0\"\nhs+=str(h)\nms+=str(m)\nprint(\"%s:%s\"%(hs,ms))\n", "passed": true, "time": 0.15, "memory": 14484.0, "status": "done"}, {"code": "import sys\n\ndef norm(num):\n\tif num < 10:\n\t\treturn '0' + str(num)\n\telse:\n\t\treturn str(num)\n\nh, m = [int(x) for x in input().split(':')]\ndiff = int(input())\n\nhdiff = diff // 60\nmdiff = diff % 60\n\nmans = m + mdiff\nhans = (h + hdiff) % 24\nhans = (hans + 1) % 24 if mans >= 60 else hans\nmans %= 60\ns = norm(hans) + ':' + norm(mans)\n\nprint(s)\n", "passed": true, "time": 0.14, "memory": 14516.0, "status": "done"}, {"code": "h,m=map(int,input().split(\":\"))\nm+=int(input())\nm+=h*60\nm%=24*60\nprint(\"{:02}:{:02}\".format(*divmod(m,60)))", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "s = input()\nn = int(input())\nh = int(s[0:2])\nm = int(s[3:])\n\n\nh += ((m + n) // 60)\nh %= 24\nm = (m + n) % 60\ns = ''\nif len(str(h)) < 2:\n s += '0'\ns += str(h) + ':'\nif len(str(m)) < 2:\n s += '0'\ns += str(m)\nprint(s)\n", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "h, m = map(int, input().split(':'))\nn = int(input())\nm, h = (m + n) % 60, (h + (m+n) // 60) % 24\nif h < 10:\n\th = '0' + str(h)\nif m < 10:\n\tm = '0' + str(m) \nprint(h, m, sep = ':')", "passed": true, "time": 0.14, "memory": 14428.0, "status": "done"}, {"code": "3\n\nhh, mm = [int(i) for i in input().split(':')]\na = int(input())\n\nmm += a\n\nhh += mm // 60\nmm %= 60\nhh %= 24\n\nprint(str(hh).zfill(2) + ':' + str(mm).zfill(2))\n\n# TODO: Leading zeroes\n", "passed": true, "time": 0.14, "memory": 14380.0, "status": "done"}, {"code": "sLine = input()\nsSplit = sLine.split(sep=':')\nnHour = int(sSplit[0])\nnMinute = int(sSplit[1])\nnPass = int(input())\nnPass = nPass % (60 * 24)\nnMinute += nPass\nif nMinute >= 60 :\n\tx = nMinute // 60\n\tnMinute -= 60 * x\n\tnHour += x\nif nHour >= 24 :\n\tnHour %= 24\nprint('{0:02d}:{1:02d}'.format(nHour, nMinute))\n", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "def main():\n mode=\"filee\"\n if mode==\"file\":f=open(\"test.txt\",\"r\")\n get = lambda :[int(x) for x in (f.readline() if mode==\"file\" else input()).split(\":\")]\n [h,m]=get()\n [n]=get()\n x = h * 60 + m\n x = (x + n) % 1440\n print(str(x//60).rjust(2, '0') + \":\",end='')\n print(str(x % 60).rjust(2, '0'))\n \n if mode==\"file\":f.close()\n\n\ndef __starting_point():\n main()\n\n\n__starting_point()", "passed": true, "time": 0.24, "memory": 14288.0, "status": "done"}, {"code": "a = input()\nh = int(a[0:2])\nm = int(a[3:5])\nn=int(input())\nper = (m + n) // 60\nm = (m+n) % 60\nh = (h + per) % 24\nif h < 10:\n print('0' + str(h) + ':', end = '')\nelse:\n print(str(h) + ':', end = '')\nif m < 10:\n print('0' + str(m))\nelse:\n print(str(m))", "passed": true, "time": 0.14, "memory": 14300.0, "status": "done"}, {"code": "ip=str(input())\nh=int(ip[0]+ip[1])\nm=int(ip[3]+ip[4])\nk=h*60+m\nn=int(input())\nk+=n\nh1=(k//60)%24\nm1=k%60\nif h1<10:\n h1='0'+str(h1)\nif m1<10:\n m1='0'+str(m1)\nprint(h1,end=':')\nprint(m1)\n", "passed": true, "time": 0.14, "memory": 14416.0, "status": "done"}, {"code": "import collections\nimport math\n\n#n ,m = map(int, input().split())\nt = list(input())\na = int(input()) % 1440\nm = (a % 60 + int(t[3]) * 10 + int(t[4])) % 60\nh = (a // 60 + (a % 60 + int(t[3]) * 10 + int(t[4])) // 60 + int(t[1]) + int(t[0]) * 10) % 24\nprint(''.join(str(x) for x in [h // 10, h % 10, ':', m // 10, m % 10]))", "passed": true, "time": 0.18, "memory": 14540.0, "status": "done"}, {"code": "def __starting_point():\n\n hh,mm = map(int,input().split(sep=\":\"))\n a = int(input())\n\n hh += a//60\n mm += a%60\n\n hh += mm//60\n mm = mm%60\n\n hh = hh%24\n\n #print(hh,mm)\n\n strhh = \"0\"*(2-len(str(hh))) + str(hh)\n strmm = \"0\"*(2-len(str(mm))) + str(mm)\n print(strhh,\":\",strmm,sep=\"\")\n__starting_point()", "passed": true, "time": 0.24, "memory": 14496.0, "status": "done"}, {"code": "h, m = map(int, input().split(':'))\nv = 60 * h + m + int(input())\nprint('{:02}:{:02}'.format(v // 60 % 24, v % 60))", "passed": true, "time": 0.2, "memory": 14268.0, "status": "done"}]
[{"input": "23:59\n10\n", "output": "00:09\n"}, {"input": "20:20\n121\n", "output": "22:21\n"}, {"input": "10:10\n0\n", "output": "10:10\n"}, {"input": "12:34\n10000\n", "output": "11:14\n"}, {"input": "00:00\n10000\n", "output": "22:40\n"}, {"input": "00:00\n1440\n", "output": "00:00\n"}, {"input": "23:59\n8640\n", "output": "23:59\n"}, {"input": "10:01\n0\n", "output": "10:01\n"}, {"input": "04:05\n0\n", "output": "04:05\n"}, {"input": "02:59\n1\n", "output": "03:00\n"}, {"input": "05:15\n10\n", "output": "05:25\n"}, {"input": "03:10\n20\n", "output": "03:30\n"}, {"input": "09:11\n0\n", "output": "09:11\n"}, {"input": "19:00\n0\n", "output": "19:00\n"}, {"input": "23:59\n1\n", "output": "00:00\n"}, {"input": "11:59\n1\n", "output": "12:00\n"}, {"input": "19:34\n566\n", "output": "05:00\n"}, {"input": "00:01\n59\n", "output": "01:00\n"}, {"input": "03:30\n0\n", "output": "03:30\n"}, {"input": "22:30\n30\n", "output": "23:00\n"}, {"input": "22:50\n70\n", "output": "00:00\n"}, {"input": "05:12\n0\n", "output": "05:12\n"}, {"input": "09:20\n40\n", "output": "10:00\n"}, {"input": "15:04\n36\n", "output": "15:40\n"}, {"input": "05:37\n23\n", "output": "06:00\n"}, {"input": "23:59\n59\n", "output": "00:58\n"}, {"input": "21:09\n9997\n", "output": "19:46\n"}, {"input": "11:00\n1\n", "output": "11:01\n"}, {"input": "20:01\n2699\n", "output": "17:00\n"}, {"input": "01:00\n59\n", "output": "01:59\n"}, {"input": "07:09\n6538\n", "output": "20:07\n"}, {"input": "00:00\n10\n", "output": "00:10\n"}, {"input": "02:09\n2074\n", "output": "12:43\n"}, {"input": "01:10\n1\n", "output": "01:11\n"}, {"input": "23:01\n59\n", "output": "00:00\n"}, {"input": "08:50\n20\n", "output": "09:10\n"}, {"input": "13:18\n5121\n", "output": "02:39\n"}, {"input": "18:31\n2677\n", "output": "15:08\n"}, {"input": "14:17\n108\n", "output": "16:05\n"}, {"input": "02:45\n5617\n", "output": "00:22\n"}, {"input": "00:00\n3600\n", "output": "12:00\n"}, {"input": "19:01\n59\n", "output": "20:00\n"}, {"input": "19:02\n59\n", "output": "20:01\n"}, {"input": "14:00\n2880\n", "output": "14:00\n"}, {"input": "01:10\n44\n", "output": "01:54\n"}, {"input": "02:01\n59\n", "output": "03:00\n"}, {"input": "07:02\n121\n", "output": "09:03\n"}, {"input": "10:00\n61\n", "output": "11:01\n"}, {"input": "23:59\n61\n", "output": "01:00\n"}, {"input": "00:00\n0\n", "output": "00:00\n"}, {"input": "23:59\n121\n", "output": "02:00\n"}, {"input": "00:00\n60\n", "output": "01:00\n"}, {"input": "15:52\n60\n", "output": "16:52\n"}, {"input": "00:39\n6525\n", "output": "13:24\n"}, {"input": "00:30\n30\n", "output": "01:00\n"}, {"input": "00:59\n1\n", "output": "01:00\n"}, {"input": "00:55\n4321\n", "output": "00:56\n"}, {"input": "10:05\n1\n", "output": "10:06\n"}, {"input": "23:00\n60\n", "output": "00:00\n"}]
319
You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where a_{i}, j = 1 if the i-th switch turns on the j-th lamp and a_{i}, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. -----Input----- The first line of the input contains two integers n and m (1 ≀ n, m ≀ 2000) β€” the number of the switches and the number of the lamps. The following n lines contain m characters each. The character a_{i}, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. -----Output----- Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. -----Examples----- Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO
interview
[{"code": "n, m = list(map(int, input().split()))\na = [list(map(int, input())) for i in range(n)]\n\nignorable = [True] * n\n\nfor i in range(m):\n cnt = 0\n for j in range(n):\n cnt += a[j][i]\n if cnt == 1:\n for j in range(n):\n if a[j][i]:\n ignorable[j] = False\n\nif any(ignorable):\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.25, "memory": 14280.0, "status": "done"}, {"code": "def main():\n n, m = map(int, input().split())\n a = []\n for i in range(n):\n a.append(input())\n ans = \"NO\"\n count = [0] * m\n for i in range(n):\n for j in range(m):\n if (a[i][j] == '1'):\n count[j] += 1\n for i in range(n):\n ans = \"YES\"\n for j in range(m):\n if (count[j] == 1 and a[i][j] == '1'):\n ans = \"NO\"\n break\n if (ans == \"YES\"):\n break\n print(ans)\nmain()", "passed": true, "time": 0.15, "memory": 14324.0, "status": "done"}, {"code": "n, m = [int(v) for v in input().split()]\n\na = []\nfor _ in range(n):\n a.append([int(v) for v in input()])\n\ncolsums = [sum(a[i][j] for i in range(n)) for j in range(m)]\n\nfor row in a:\n if all(rv < sv for (rv, sv) in zip(row, colsums)):\n print(\"YES\")\n return\n\nprint(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "'''n = int(input())\na = list(map(int,input().split()))\nt = 0\nt2 = 0\nfor i in range(n//2):\n t+=abs(2*i+1-a[i])\n t2+=abs(2*i+2-a[i])\nprint(min(t,t2))\n'''\nn,m = list(map(int,input().split()))\na=[]\nfor i in range(n):\n a.append(input())\nf = [True]*n\nfor j in range(m):\n l = -1\n c = 0\n for i in range(n):\n if a[i][j] == '1':\n l = i\n c+=1\n if c==1:\n f[l] = False\nif True in f:print('YES')\nelse :print('NO')\n", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "import re\nimport math\nimport decimal\nimport bisect\n\ndef read():\n\treturn input().strip()\n\nn, m = [int(x) for x in read().split()]\nswitches = []\nfor i in range(n):\n\tswitches.append(int(read(), 2))\n\nallon = int(\"1\"*m, 2)\nfor i in range(n):\n\tans = 0\n\tfor j in range(n):\n\t\tif j != i:\n\t\t\tans |= switches[j]\n\t\tif ans == allon:\n\t\t\tprint(\"YES\")\n\t\t\treturn\nprint(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14536.0, "status": "done"}, {"code": "def getIntList():\n return list(map(int, input().split()));\ndef getTransIntList(n):\n first=getIntList();\n m=len(first);\n result=[[0]*n for _ in range(m)];\n for i in range(m):\n result[i][0]=first[i];\n for j in range(1, n):\n curr=getIntList();\n for i in range(m):\n result[i][j]=curr[i];\n return result;\nn, m=getIntList();\na=[];\nfor _ in range(n):\n s=input();\n a.append([int(s[i]) for i in range(m)]);\nsumA=[0]*m;\nfor i in range(n):\n for j in range(m):\n sumA[j]+=a[i][j];\ndef check():\n for i in range(n):\n for j in range(m):\n if a[i][j]==1 and sumA[j]==1:\n break;\n else:\n return \"YES\";\n return \"NO\";\nprint(check());", "passed": true, "time": 0.25, "memory": 14524.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\n[n, m] = list(map(int, input().strip().split()))\nbis = [input().strip() for _ in range(n)]\n\ntrbis = [''.join(bis[i][j] for i in range(n)) for j in range(m)]\n\nnec = [0 for i in range(n)]\nfor col in trbis:\n\tif col.count('1') == 1:\n\t\tnec[col.index('1')] = 1\n\nif sum(nec) < n:\n\tprint ('YES')\nelse:\n\tprint ('NO')\n", "passed": true, "time": 0.15, "memory": 14460.0, "status": "done"}, {"code": "arr = []\nfreq = {}\n\ndef exclude(i, n, m):\n s = arr[i]\n for j in range(m):\n if s[j] == '1':\n if freq[j] <= 1:\n return False\n return True\n\nn, m = list(map(int, input().split()))\n\nfor i in range(n):\n s = input()\n for j in range(m):\n if s[j] == '1':\n if j in freq:\n freq[j] += 1\n else:\n freq[j] = 1\n arr.append(s)\nans = False\nfor i in range(n):\n if exclude(i, n, m):\n ans = True\nprint('YES' if ans else 'NO')", "passed": true, "time": 0.14, "memory": 14388.0, "status": "done"}, {"code": "(n, m) = list(map(int, input().split()))\n\nlst = []\nfor x in range(n):\n lst.append(input())\n\narray = [0] * m\nfor x in range(n):\n for y in range(m):\n if lst[x][y] == '1':\n array[y] += 1\n\nF = False\nfor x in range(n):\n flag = True\n for y in range(m):\n if lst[x][y] == '1' and array[y] == 1:\n flag = False\n if flag:\n F = True\n break\n\nif F:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14528.0, "status": "done"}, {"code": "m,n=list(map(int,input().split()))\na=[]\nfor i in range(m):\n a.append(list(map(int,list(input()))))\nb=[0]*n\nfor j in range(n):\n b[j]=0\n for i in range(m):\n b[j]+=a[i][j]\nfor i in range(m):\n for j in range(n):\n if(b[j]==a[i][j]):\n break\n else:\n print(\"YES\")\n break\nelse:\n print(\"NO\")", "passed": true, "time": 0.15, "memory": 14396.0, "status": "done"}, {"code": "n, m = [int(x) for x in input().split()]\narr = []\nfor i in range(n):\n x = input()\n arr.append([int(x[j]) for j in range(len(x))])\n\narr_T = list(zip(*arr))\n\nT = [sum(x) for x in arr_T]\n\nfor i in range(n):\n if all(T[j] - arr[i][j] > 0 for j in range(m)):\n print('YES')\n break\nelse:\n print('NO')\n\n\n\n\n", "passed": true, "time": 0.15, "memory": 14304.0, "status": "done"}, {"code": "s = [int(x) for x in input().split()]\nc = []\na = [False for x in range(s[0])]\nfor _ in range(s[0]):\n\tc.append(input())\nfor i in range(s[1]):\n\tlast = -1\n\tq = 0\n\tfor j in range(s[0]):\n\t\tif c[j][i] == '1':\n\t\t\tlast = j\n\t\t\tq += 1\n\tif q == 1:\n\t\ta[last] = True\nif all(x for x in a):\n\tprint('NO')\nelse:\n\tprint('YES')", "passed": true, "time": 0.24, "memory": 14560.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\na = [int(input(), 2) for _ in range(n)]\n\nl = a[::]\nr = a[::]\nf = 2**m - 1\n\nfor i in range(1, n):\n l[i] |= l[i-1]\n r[-i-1] |= r[-i]\n\nres = False\nfor i in range(n):\n x = l[i-1] if i != 0 else 0\n y = r[i+1] if i != n-1 else 0\n\n if (x | y) == f:\n res = True\n break\n\nprint(\"YES\" if res else \"NO\")\n", "passed": true, "time": 0.22, "memory": 14536.0, "status": "done"}, {"code": "m, n = map(int,input().split()) \nD1 = {}\nD2 = {}\n\nfor i in range(m):\n D1[i] = []\nfor i in range(n):\n D2[i] = []\n\nfor i in range(m):\n L = input()\n for j in range(n):\n if L[j] == '1':\n D1[i].append(j)\n D2[j].append(i)\n\nX = 0\nfor i in range(m):\n E = 0\n for j in D1[i]:\n if len(D2[j]) == 1:\n E = 1\n break\n if E == 0:\n X = 1\n break\nif X == 1:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.15, "memory": 14332.0, "status": "done"}, {"code": "a = []\nwas_already = was_twice = 0\nn = int(input().split()[0])\nfor _ in range(n):\n\tai = int(input(), base=2)\n\ta.append(ai)\n\twas_twice |= was_already & ai\n\twas_already |= ai\nfor ai in a:\n\tif ai & (ai ^ was_twice):\n\t\tcontinue\n\tprint(\"YES\")\n\tbreak\nelse:\n\tprint(\"NO\")\n", "passed": true, "time": 0.25, "memory": 14348.0, "status": "done"}, {"code": "T = input().split(' ')\nn = int(T[0])\nm = int(T[1])\nS = [0] * n\nQ = []\nfor i in range(n):\n Q.append(input())\nfor i in range(m):\n a = -1\n b = -1\n for j in range(n):\n if Q[j][i] == '1':\n if a==-1:\n a=j\n else:\n b=j\n break\n if a!=-1 and b==-1:\n S[a] = 1\nb = False\nfor j in range(n):\n if S[j] == 0:\n b = True\n break\nif b:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.25, "memory": 14540.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nd = [0] * m\ns = list(list(map(int, input())) for i in range(n))\nfor x in s:\n for i in range(m):\n d[i] += x[i]\nfor x in s:\n f = 1\n for i in range(m):\n if x[i]:\n if d[i] == 1:\n f = 0\n break\n if f:\n print('YES')\n return\nprint('NO')\n", "passed": true, "time": 0.14, "memory": 14276.0, "status": "done"}, {"code": "R = lambda: map(int, input().split())\n\ndef func():\n n, m = R()\n cnt = [0]*m\n ss = []\n\n for i in range(n):\n s = input()\n ss.append(s)\n for j, ch in enumerate(s):\n if ch == '1': cnt[j] += 1\n\n for i in range(n):\n s = ss[i]\n for j, ch in enumerate(s):\n if ch == '1' and cnt[j] <= 1: break\n else:\n return 1\n\n return 0\n\n\nprint('YES' if func() else 'NO')", "passed": true, "time": 0.23, "memory": 14300.0, "status": "done"}, {"code": "def read():\n return list(map(int,input().split()))\nn,m=read()\na=[]\nfor i in range(n):\n a.append(input())\nans=[0]*n\nfor i in range(m):\n ind=-1\n for j in range(n):\n if a[j][i]=='1':\n if ind!=-1:\n ind=-1\n break\n ind=j\n if ind!=-1:\n ans[ind]=1\nif 0 in ans:\n print('YES')\nelse:\n print('NO')\n \n \n\n \n \n", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "n,m=map(int,input().split())\nr=[input() for _ in [0]*n]\nd={j:0 for j in range(m)}\nfor i in r:\n for j in range(m):\n d[j]+=int(i[j])\nl=list(d.values())\nfor i in r:\n f=True\n for j in range(m):\n if i[j]=='1' and l[j]==1:f=False;break\n if f:print(\"YES\");return\nprint(\"NO\")", "passed": true, "time": 0.15, "memory": 14568.0, "status": "done"}, {"code": "n,m=list(map(int,input().split()))\nl=[int(input(),2) for i in range(n)]\nc=int('1'*m,2)\nb=True\nfor i in range(len(l)):\n s=0\n for j in range(len(l)):\n if i!=j:\n s=s|l[j]\n if s==c:\n b=False\n print('YES')\n break\nif b:\n print('NO')\n", "passed": true, "time": 0.14, "memory": 14528.0, "status": "done"}, {"code": "n,m = list(map(int,input().split()))\n\nans = 0\nmat = []\nfor i in range(n):\n mat.append(input())\nl = [0]*m\n\nfor j in range(m):\n for i in range(n):\n l[j]+= (mat[i][j]=='1')\n\nfor i in range(n):\n flag = 0 \n for j in range(m):\n if mat[i][j]=='1' and l[j]==1:\n flag = 1 \n if flag == 0 : \n print(\"YES\")\n return\nprint(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14324.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\nN,M = list(map(int, input().split()))\nlights = [[int(x) for x in input().strip()] for i in range(N)]\n\nA = [sum([lights[i][j] for i in range(N)]) for j in range(M)]\nfull = [i for i,x in enumerate(A) if x > 1]\n\ndef main():\n\tfor row in lights:\n\t\tif sum(row) == sum([row[i] for i in full]):\n\t\t\treturn \"YES\"\n\treturn \"NO\"\nprint(main())\n", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "t = input().split(\" \")\nt = [int(e) for e in t]\n\nl = []\nfor i in range(t[0]):\n tt = input().strip()\n assert len(tt) == t[1]\n l.append(tt)\n\nassert t[0] == len(l)\nassert t[1] == len(l[0])\n\nlsum = []\nfor i in range(t[1]):\n lsum.append(sum(int(l[j][i]) for j in range(t[0])))\n\nfor i in range(t[0]):\n can_be_ignore = True\n\n for j in range(t[1]):\n if lsum[j] == 1 and l[i][j] == '1':\n can_be_ignore = False\n break\n\n if can_be_ignore:\n print(\"YES\")\n return\n\n\nprint(\"NO\")\n\n", "passed": true, "time": 0.15, "memory": 14372.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\na = [list(map(int, list(input()))) for _ in range(n)]\n\nans = \"NO\"\ncnt = [0 for _ in range(m)]\nfor i in range(n):\n for j in range(m):\n cnt[j] += a[i][j]\nfor i in range(n):\n ok = True\n for j in range(m):\n if a[i][j] == 1 and cnt[j] == 1:\n ok = False\n break\n if ok:\n ans = \"YES\"\n break\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14452.0, "status": "done"}]
[{"input": "4 5\n10101\n01000\n00111\n10000\n", "output": "YES\n"}, {"input": "4 5\n10100\n01000\n00110\n00101\n", "output": "NO\n"}, {"input": "1 5\n11111\n", "output": "NO\n"}, {"input": "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1\n", "output": "YES\n"}, {"input": "1 1\n1\n", "output": "NO\n"}, {"input": "3 4\n1010\n0100\n1101\n", "output": "YES\n"}, {"input": "2 5\n10101\n11111\n", "output": "YES\n"}, {"input": "5 5\n10000\n11000\n11100\n11110\n11111\n", "output": "YES\n"}, {"input": "2 5\n10000\n11111\n", "output": "YES\n"}, {"input": "4 5\n01000\n10100\n00010\n10101\n", "output": "YES\n"}, {"input": "2 2\n10\n11\n", "output": "YES\n"}, {"input": "2 5\n00100\n11111\n", "output": "YES\n"}, {"input": "4 5\n00000\n11000\n00110\n00011\n", "output": "YES\n"}, {"input": "4 3\n000\n010\n001\n100\n", "output": "YES\n"}, {"input": "4 5\n10000\n10101\n01000\n00111\n", "output": "YES\n"}, {"input": "4 5\n10000\n01000\n10101\n00111\n", "output": "YES\n"}, {"input": "2 2\n01\n11\n", "output": "YES\n"}, {"input": "3 3\n010\n101\n000\n", "output": "YES\n"}, {"input": "2 2\n11\n00\n", "output": "YES\n"}, {"input": "3 5\n10110\n11000\n00111\n", "output": "YES\n"}, {"input": "3 8\n00111111\n01011100\n11000000\n", "output": "YES\n"}, {"input": "4 6\n100000\n110000\n001100\n000011\n", "output": "YES\n"}, {"input": "2 5\n11111\n00000\n", "output": "YES\n"}, {"input": "2 3\n101\n111\n", "output": "YES\n"}, {"input": "2 5\n01000\n11111\n", "output": "YES\n"}, {"input": "2 2\n00\n11\n", "output": "YES\n"}, {"input": "4 15\n111110100011010\n111111011010110\n101000001011001\n100110000111011\n", "output": "YES\n"}, {"input": "2 3\n010\n111\n", "output": "YES\n"}, {"input": "4 5\n10100\n11000\n00110\n00101\n", "output": "YES\n"}, {"input": "4 4\n1111\n0000\n0000\n0000\n", "output": "YES\n"}, {"input": "3 5\n11100\n00110\n00011\n", "output": "YES\n"}, {"input": "2 1\n0\n1\n", "output": "YES\n"}, {"input": "4 4\n1000\n1001\n0010\n0100\n", "output": "YES\n"}, {"input": "3 5\n00110\n10011\n01100\n", "output": "YES\n"}, {"input": "3 5\n10101\n00111\n01000\n", "output": "NO\n"}, {"input": "4 5\n00101\n00011\n01000\n10010\n", "output": "YES\n"}, {"input": "3 3\n100\n110\n111\n", "output": "YES\n"}, {"input": "2 2\n11\n01\n", "output": "YES\n"}, {"input": "3 3\n100\n100\n111\n", "output": "YES\n"}, {"input": "4 2\n10\n01\n10\n01\n", "output": "YES\n"}, {"input": "3 3\n111\n000\n000\n", "output": "YES\n"}, {"input": "3 3\n010\n100\n011\n", "output": "YES\n"}, {"input": "2 3\n111\n000\n", "output": "YES\n"}, {"input": "3 4\n0001\n1101\n1010\n", "output": "YES\n"}, {"input": "3 4\n1010\n0101\n1000\n", "output": "YES\n"}, {"input": "3 4\n0001\n1101\n0110\n", "output": "YES\n"}, {"input": "3 3\n111\n101\n001\n", "output": "YES\n"}, {"input": "4 5\n10001\n10010\n01010\n00101\n", "output": "YES\n"}, {"input": "3 3\n000\n000\n111\n", "output": "YES\n"}, {"input": "2 3\n100\n111\n", "output": "YES\n"}, {"input": "3 10\n1111011100\n0001100011\n1111010101\n", "output": "YES\n"}, {"input": "3 4\n0110\n1010\n0101\n", "output": "YES\n"}, {"input": "3 3\n100\n001\n011\n", "output": "YES\n"}, {"input": "3 3\n100\n010\n001\n", "output": "NO\n"}, {"input": "3 3\n010\n100\n001\n", "output": "NO\n"}, {"input": "3 5\n10101\n01010\n01010\n", "output": "YES\n"}, {"input": "2 6\n111111\n000000\n", "output": "YES\n"}, {"input": "3 5\n00000\n10101\n01010\n", "output": "YES\n"}, {"input": "4 6\n111000\n100100\n010010\n001001\n", "output": "YES\n"}]
320
Valera has got n domino pieces in a row. Each piece consists of two halves β€” the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true. -----Input----- The first line contains integer n (1 ≀ n ≀ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers x_{i}, y_{i} (1 ≀ x_{i}, y_{i} ≀ 6). Number x_{i} is initially written on the upper half of the i-th domino, y_{i} is initially written on the lower half. -----Output----- Print a single number β€” the minimum required number of seconds. If Valera can't do the task in any time, print - 1. -----Examples----- Input 2 4 2 6 4 Output 0 Input 1 2 3 Output -1 Input 3 1 4 2 3 4 4 Output 1 -----Note----- In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd. In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8.
interview
[{"code": "N = int(input())\nCheck = False\nSum = 0\nSum_l, Sum_r = 0, 0\nfor i in range(N):\n x, y = list(map(int, input().split()))\n Sum_l += x\n Sum_r += y\n Sum += x + y\n if (x % 2 + y % 2) % 2:\n Check = True\nif Sum % 2:\n print(-1)\nelif Sum_l % 2:\n if not Check:\n print(-1)\n else:\n print(1)\nelif Sum_l % 2 == 0:\n print(0)\n", "passed": true, "time": 0.94, "memory": 14352.0, "status": "done"}, {"code": "n = int(input())\na = 0\nb = 0\nans = 0\nfor i in range (n):\n x, y = list(map(int, input().split()))\n if (x + y) % 2 == 1:\n ans = 1\n a += x\n b += y\nif (a + b) % 2 == 1:\n print(-1)\nelif a % 2 == b % 2 == 0:\n print(0)\nelif ans == 0:\n print(-1)\nelse:\n print(1)\n", "passed": true, "time": 0.15, "memory": 14260.0, "status": "done"}, {"code": "def main():\n n = int(input())\n \n sumtop = 0\n sumbottom = 0\n flippable = False\n for i in range(n):\n st = input()\n arr = st.split(\" \")\n a = int(arr[0])\n b = int(arr[1])\n \n sumtop += a\n sumbottom += b\n \n if a%2 + b%2 == 1:\n flippable = True\n \n if sumtop%2 == 0 and sumbottom%2 == 0:\n print(0)\n elif sumtop%2 + sumbottom%2 == 1:\n print(-1)\n elif flippable:\n print(1)\n else:\n print(-1)\n \n \n \n \ndef __starting_point(): main()\n__starting_point()", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "from functools import reduce\n\ndominoes = [list([int(x) % 2 for x in input().split()]) for x in range(int(input()))]\ntemp1, temp2 = reduce(lambda a, x: (a + x[0]) % 2, dominoes, 0), reduce(lambda a, x: (a + x[1]) % 2, dominoes, 0)\nif temp1 == temp2 == 0:\n print(0)\nelif temp1 == temp2 == 1 and ([1, 0] in dominoes or [0, 1] in dominoes):\n print(1)\nelse:\n print(-1)\n", "passed": true, "time": 0.24, "memory": 14556.0, "status": "done"}, {"code": "n = int(input())\nA = [0 for q in range(n)]\nB = [0 for q in range(n)]\nfor i in range(n):\n (A[i], B[i]) = list(map(int, input().split()))\ns1 = sum(A)\ns2 = sum(B)\nif s1 % 2 == 0 and s2 % 2 == 0:\n print(0)\nelif s1 % 2 == 1 and s2 % 2 == 1:\n p = 0\n for i in range(n):\n if A[i] % 2 != B[i] % 2:\n p = 1\n break\n if p == 1:\n print(1)\n else:\n print(-1)\nelse:\n print(-1)\n", "passed": true, "time": 0.14, "memory": 14336.0, "status": "done"}, {"code": "import sys\n\nn = int(input())\na, b = [], []\nfor i in range(n):\n x, y = list(map(int, input().split()))\n a.append(x)\n b.append(y)\nif sum(a) % 2 == sum(b) % 2 == 0:\n print(0)\nelse:\n for i in range(n):\n a[i], b[i] = b[i], a[i]\n if sum(a) % 2 == sum(b) % 2 == 0:\n print(1)\n return\n a[i], b[i] = b[i], a[i]\n for i in range(n):\n for j in range(i + 1, n):\n a[i], b[i] = b[i], a[i]\n a[j], b[j] = b[j], a[j]\n if sum(a) % 2 == sum(b) % 2 == 0:\n prin(2)\n return\n a[i], b[i] = b[i], a[i]\n a[j], b[j] = b[j], a[j]\n print('-1')\n", "passed": true, "time": 0.22, "memory": 14556.0, "status": "done"}, {"code": "n = int(input());\nd = [];\nfor i in range (0, n):\n tmp = input().split();\n (x, y) = (tmp[0], tmp[1]);\n d.append((x, y));\n\nxSum = 0;\nySum = 0;\nfor (x, y) in d :\n xSum += int(x);\n ySum += int(y);\nif xSum % 2 == 0 and ySum % 2 == 0 :\n print((0));\nelif (xSum + ySum) % 2 == 1 :\n print((-1));\nelse :\n result = False;\n for (x, y) in d :\n if (int(x) + int(y)) % 2 == 1 :\n result = True;\n if result == True :\n print((1));\n else :\n print((-1));\n\n\n", "passed": true, "time": 0.15, "memory": 14536.0, "status": "done"}, {"code": "N = int(input())\nA = [tuple(int(j) for j in input().split()) for i in range(N)]\nS1, S2 = 0, 0\n\nfor a, b in A:\n S1 += a\n S2 += b\n\nif S1 % 2 == 0 and S2 % 2 == 0:\n print(0)\n return\n\nif (S1 % 2 == 0) ^ (S2 % 2 == 0):\n print(-1)\n return\n\nfor a, b in A:\n if (a % 2 == 0) ^ (b % 2 == 0):\n print(1)\n return\n\nprint(-1)\n", "passed": true, "time": 0.22, "memory": 14348.0, "status": "done"}, {"code": "n=int(input())\na=[]\nb=[]\ns1=0\ns2=0\nk=0\nfor i in range(n):\n x,y=map(int,input().split())\n a.append(x)\n b.append(y)\n s1+=x\n s2+=y\nif s1%2==0 and s2%2==0:\n print(0)\nelse:\n if (s1%2 ==0 and s2%2!=0) or(s1%2 !=0 and s2%2==0):\n print(-1)\n else:\n for i in range(n):\n if (a[i]%2==1 and b[i]%2==0) or (a[i]%2==0 and b[i]%2==1):\n print(1)\n break\n k+=1\nif k==n :\n print(-1)", "passed": true, "time": 0.15, "memory": 14424.0, "status": "done"}, {"code": "n = int(input())\n\nsum_x = 0\nsum_y = 0\n\nodd_even = 0\nodd_odd = 0\neven_odd = 0\neven_even = 0\n\nfor i in range(n):\n x, y = map(int, input().split())\n sum_x += x\n sum_y += y\n if x % 2 == 0 and y % 2 == 0:\n odd_odd += 1\n elif x % 2 == 0 and y % 2 == 1:\n odd_even += 1\n elif x % 2 == 1 and y % 2 == 0:\n even_odd += 1\n else:\n even_even += 1\n\nif sum_x % 2 == 0 and sum_y % 2 == 0:\n print(0)\nelif sum_x % 2 == 0 and sum_y % 2 == 1:\n print(-1)\nelif sum_x % 2 == 1 and sum_y % 2 == 0:\n print(-1)\nelse: # even - even\n if even_odd >= 1 or odd_even >= 1:\n print(1)\n else:\n print(-1)", "passed": true, "time": 1.74, "memory": 14444.0, "status": "done"}, {"code": "n = int(input())\ndominos = [list(map(int, input().split())) for i in range(n)]\nsum_1 = 0\nsum_2 = 0\nind = False\nfor i in range(n):\n sum_1 += dominos[i][0] % 2\n sum_1 %= 2\n sum_2 += dominos[i][1] % 2\n sum_2 %= 2\n if dominos[i][1] % 2 != dominos[i][0] % 2:\n ind = True\nif sum_1 == sum_2 == 1 and ind:\n print(1)\nelif sum_1 == sum_2 == 0:\n print(0)\nelse:\n print(-1)", "passed": true, "time": 0.17, "memory": 14496.0, "status": "done"}, {"code": "def __starting_point():\n N = int(input())\n su = 0\n sl = 0\n canF = False\n for i in range(N):\n arr = input().split(' ')\n a = int(arr[0])\n b = int(arr[1])\n if (a%2==0 and b%2==1) or (a%2==1 and b%2==0):\n canF = True\n su += a\n sl += b\n ans = -1\n if (su+sl)%2==1:\n ans = -1\n else:\n if su%2==0 and sl%2==0:\n ans = 0\n elif canF:\n ans = 1\n else:\n ans = -1\n print(ans)\n\n__starting_point()", "passed": true, "time": 0.2, "memory": 14480.0, "status": "done"}, {"code": "n = int(input())\ncount = -1\nA = [0] * 3\nfor i in range(n):\n a, b = list(map(int, input().split()))\n if a % 2 == 1 and b % 2 == 1:\n A[0] += 1\n elif a % 2 == 1:\n A[1] += 1\n elif b % 2 == 1:\n A[2] += 1\nif A[0] % 2 == 0 and (A[1] + A[2]) % 2 == 0:\n print(A[1] % 2)\nelif (A[1] + A[2]) % 2 == 0 and (A[1] + A[2]) >= 2:\n if A[1] % 2 == A[2] % 2 == 1:\n print(0)\n else:\n print(1)\nelse:\n print(-1)\n \n", "passed": true, "time": 0.15, "memory": 14464.0, "status": "done"}, {"code": "n = int(input())\npieces = []\n\nsum_total = 0\nsum_left = 0\nfor i in range(1, n + 1):\n keys = []\n piece = input().split()\n keys = [int(x) for x in piece]\n sum_total += sum(keys)\n pieces.append(keys)\n\ncanrotate = False\nfor i in range(n):\n sum_left += pieces[i][0]\n if pieces[i][0] % 2 != pieces[i][1] % 2:\n canrotate = True\n\nif sum_total % 2 == 1:\n print(-1)\nelif not canrotate and sum_left % 2 == 1:\n print(-1)\nelif sum_left % 2 == 1:\n print(1)\nelse:\n print(0)\n", "passed": true, "time": 0.15, "memory": 14316.0, "status": "done"}, {"code": "n = int(input())\nA = [0 for q in range(n)]\nB = [0 for q in range(n)]\nfor i in range(n):\n (A[i], B[i]) = list(map(int, input().split()))\ns1 = sum(A)\ns2 = sum(B)\nif s1 % 2 == 0 and s2 % 2 == 0:\n print(0)\nelif s1 % 2 == 1 and s2 % 2 == 1:\n p = 0\n for i in range(n):\n if A[i] % 2 != B[i] % 2:\n p = 1\n break\n if p == 1:\n print(1)\n else:\n print(-1)\nelse:\n print(-1)\n", "passed": true, "time": 0.23, "memory": 14328.0, "status": "done"}, {"code": "'''\nCreated on Oct 10, 2013\n\n@author: Anonymous\n'''\nn=int(input())\ncnt=0\nsuma=sumb=0\nfor i in range(0,n):\n a,b=list(map(int,input().split()))\n if(a%2!=b%2):cnt+=1\n suma,sumb=suma+a,sumb+b\nif(suma%2==0 and sumb%2==0):print(0)\nelif(suma%2!=sumb%2):print(-1)\nelif(cnt>0):print(1)\nelse: print(-1)\n \n", "passed": true, "time": 0.15, "memory": 14372.0, "status": "done"}, {"code": "def __starting_point():\n n = int(input())\n topodds = 0\n bottomodds = 0\n flipabble = False\n for _ in range(n):\n top,bottom = list(map(int,input().split())) \n if not flipabble and (top+bottom)%2 != 0:\n flipabble=True\n topodds += 0 if (top % 2==0) else 1\n bottomodds += 0 if (bottom%2==0) else 1\n if (topodds+bottomodds)%2 != 0:\n print(-1)\n elif (topodds%2 != 0) or (bottomodds%2 != 0):\n print(1 if flipabble else -1)\n else:\n print(0)\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "def readln(): return tuple(map(int, input().split()))\n\nn, = readln()\na = b = c = 0\nfor _ in range(n):\n x, y = readln()\n a += x\n b += y\n c += (x % 2) ^ (y % 2)\nif a % 2 == 0 and b % 2 == 0:\n print(0)\nelif (a % 2) == (b % 2) and c:\n print(1)\nelse:\n print(-1)\n", "passed": true, "time": 0.15, "memory": 14460.0, "status": "done"}, {"code": "n = int(input())\ns1 = 0\ns2 = 0\nb = False\nfor i in range(n):\n x, y= map(int, input().split())\n if x % 2 != y % 2:\n b = True\n s1 += x % 2\n s2 += y % 2\nif s1 % 2 == 0 and s2 % 2 == 0:\n print(0)\nelif s1 % 2 == s2 % 2 and b:\n print(1)\nelse:\n print(-1)", "passed": true, "time": 0.14, "memory": 14336.0, "status": "done"}, {"code": "n = int(input())\nx = 0\ny = 0\na = []\nfor i in range(n):\n a.append([int(x) for x in input().split()])\n x += a[-1][0]\n y += a[-1][1]\n\nif x % 2 == 0 and y % 2 == 0:\n print(0)\nelif x % 2 != 0 and y % 2 != 0:\n for i in a:\n if i[0] % 2 != i[1] % 2:\n print(1)\n return\n else:\n print(-1)\nelse:\n print(-1)", "passed": true, "time": 0.15, "memory": 14328.0, "status": "done"}, {"code": "n = int(input())\nA, B, C = 0, 0, 0\nfor i in range(n):\n a, b = map(int, input().split())\n A += a\n B += b\n if a % 2 != b % 2: C = 1\nif A % 2 == 0 and B % 2 == 0: print(0)\nelif A % 2 == 1 and B % 2 == 1 and C: print(1)\nelse: print(-1)", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "n = int(input())\na, b, c = 0, 0, 0\nfor i in range(n):\n x, y = map(int, input().split())\n a += x\n b += y\n if not c and (x + y) % 2: c = 1\na, b = a % 2, b % 2\nprint(a if a == b and (a == 0 or a == c) else -1)", "passed": true, "time": 0.15, "memory": 14408.0, "status": "done"}, {"code": "import sys\n\nclass Reader:\n\tdef __init__(self, file):\n\t\tself.tok, self.tok_length, self.tok_position = ([], 0, 0)\n\t\tself.lines, self.line_position = (file.readlines(), 0)\n\n\tdef next_token(self):\n\t\tif self.tok_position < self.tok_length:\n\t\t\tself.tok_position += 1\n\t\t\treturn self.tok[self.tok_position - 1]\n\t\tself.tok = self.lines[self.line_position].split()\n\t\tself.tok_length, self.tok_position = (len(self.tok), 0)\n\t\tself.line_position += 1\n\t\treturn self.next_token()\n\n\tdef next_line(self):\n\t\tself.tok, self.tok_length, self.tok_position = ([], 0, 0)\n\t\tself.line_position += 1\n\t\treturn self.lines[self.line_position - 1]\n\ndef main():\n\treader = Reader(sys.stdin)\n\tn = int(reader.next_token())\n\tls = 0\n\trs = 0\n\tcnt = 0\n\tfor i in range(n):\n\t\tl = int(reader.next_token())\n\t\tr = int(reader.next_token())\n\t\tls += l\n\t\trs += r\n\t\tif (l % 2 != r % 2):\n\t\t\tcnt += 1\n\tif ((ls + rs) % 2 != 0):\n\t\tprint(-1)\n\t\treturn\n\tif (ls % 2 == 0) and (rs % 2 == 0):\n\t\tprint(0)\n\t\treturn\n\tif (cnt > 0):\n\t\tprint(1)\n\t\treturn\n\tprint(-1)\n\t\t\n\ndef __starting_point():\n\tmain()\n__starting_point()", "passed": true, "time": 0.24, "memory": 14388.0, "status": "done"}, {"code": "n = int(input())\na = []\nfor i in range(n):\n a.append(list(map(int, input().split(' '))))\nSumm1=Summ2=0\nfor i in range(n):\n Summ1+=a[i][0]\n Summ2+=a[i][1]\nF = False\n\nif Summ1//2 == Summ1/2 and Summ2//2 == Summ2/2:\n print(0)\n F = True\n\nif Summ1//2 != Summ1/2 and Summ2//2 != Summ2/2 and n!=1:\n for i in range(n):\n if (a[i][1]//2!=a[i][1]/2 and a[i][0]//2==a[i][0]/2) or (a[i][0]//2!=a[i][0]/2 and a[i][1]//2==a[i][1]/2):\n print(1)\n F = True\n break\nif F == False:\n print(-1)", "passed": true, "time": 0.15, "memory": 14344.0, "status": "done"}]
[{"input": "2\n4 2\n6 4\n", "output": "0\n"}, {"input": "1\n2 3\n", "output": "-1\n"}, {"input": "3\n1 4\n2 3\n4 4\n", "output": "1\n"}, {"input": "5\n5 4\n5 4\n1 5\n5 5\n3 3\n", "output": "1\n"}, {"input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n6 2\n4 3\n2 1\n6 2\n6 5\n4 5\n2 4\n1 4\n", "output": "-1\n"}, {"input": "100\n2 3\n2 4\n3 3\n1 4\n5 2\n5 4\n6 6\n3 4\n1 1\n4 2\n5 1\n5 5\n5 3\n3 6\n4 1\n1 6\n1 1\n3 2\n4 5\n6 1\n6 4\n1 1\n3 4\n3 3\n2 2\n1 1\n4 4\n6 4\n3 2\n5 2\n6 4\n3 2\n3 5\n4 4\n1 4\n5 2\n3 4\n1 4\n2 2\n5 6\n3 5\n6 1\n5 5\n1 6\n6 3\n1 4\n1 5\n5 5\n4 1\n3 2\n4 1\n5 5\n5 5\n1 5\n1 2\n6 4\n1 3\n3 6\n4 3\n3 5\n6 4\n2 6\n5 5\n1 4\n2 2\n2 3\n5 1\n2 5\n1 2\n2 6\n5 5\n4 6\n1 4\n3 6\n2 3\n6 1\n6 5\n3 2\n6 4\n4 5\n4 5\n2 6\n1 3\n6 2\n1 2\n2 3\n4 3\n5 4\n3 4\n1 6\n6 6\n2 4\n4 1\n3 1\n2 6\n5 4\n1 2\n6 5\n3 6\n2 4\n", "output": "-1\n"}, {"input": "1\n2 4\n", "output": "0\n"}, {"input": "1\n1 1\n", "output": "-1\n"}, {"input": "1\n1 2\n", "output": "-1\n"}, {"input": "2\n1 1\n3 3\n", "output": "0\n"}, {"input": "2\n1 1\n2 2\n", "output": "-1\n"}, {"input": "2\n1 1\n1 2\n", "output": "-1\n"}, {"input": "5\n1 2\n6 6\n1 1\n3 3\n6 1\n", "output": "1\n"}, {"input": "5\n5 4\n2 6\n6 2\n1 4\n6 2\n", "output": "0\n"}, {"input": "10\n4 1\n3 2\n1 2\n2 6\n3 5\n2 1\n5 2\n4 6\n5 6\n3 1\n", "output": "0\n"}, {"input": "10\n6 1\n4 4\n2 6\n6 5\n3 6\n6 3\n2 4\n5 1\n1 6\n1 5\n", "output": "-1\n"}, {"input": "15\n1 2\n5 1\n6 4\n5 1\n1 6\n2 6\n3 1\n6 4\n3 1\n2 1\n6 4\n3 5\n6 2\n1 6\n1 1\n", "output": "1\n"}, {"input": "15\n3 3\n2 1\n5 4\n3 3\n5 3\n5 4\n2 5\n1 3\n3 2\n3 3\n3 5\n2 5\n4 1\n2 3\n5 4\n", "output": "-1\n"}, {"input": "20\n1 5\n6 4\n4 3\n6 2\n1 1\n1 5\n6 3\n2 3\n3 6\n3 6\n3 6\n2 5\n4 3\n4 6\n5 5\n4 6\n3 4\n4 2\n3 3\n5 2\n", "output": "0\n"}, {"input": "20\n2 1\n6 5\n3 1\n2 5\n3 5\n4 1\n1 1\n5 4\n5 1\n2 4\n1 5\n3 2\n1 2\n3 5\n5 2\n1 2\n1 3\n4 2\n2 3\n4 5\n", "output": "-1\n"}, {"input": "25\n4 1\n6 3\n1 3\n2 3\n2 4\n6 6\n4 2\n4 2\n1 5\n5 4\n1 2\n2 5\n3 6\n4 1\n3 4\n2 6\n6 1\n5 6\n6 6\n4 2\n1 5\n3 3\n3 3\n6 5\n1 4\n", "output": "-1\n"}, {"input": "25\n5 5\n4 3\n2 5\n4 3\n4 6\n4 2\n5 6\n2 1\n5 4\n6 6\n1 3\n1 4\n2 3\n5 6\n5 4\n5 6\n5 4\n6 3\n3 5\n1 3\n2 5\n2 2\n4 4\n2 1\n4 4\n", "output": "-1\n"}, {"input": "30\n3 5\n2 5\n1 6\n1 6\n2 4\n5 5\n5 4\n5 6\n5 4\n2 1\n2 4\n1 6\n3 5\n1 1\n3 6\n5 5\n1 6\n3 4\n1 4\n4 6\n2 1\n3 3\n1 3\n4 5\n1 4\n1 6\n2 1\n4 6\n3 5\n5 6\n", "output": "1\n"}, {"input": "30\n2 3\n3 1\n6 6\n1 3\n5 5\n3 6\n4 5\n2 1\n1 3\n2 3\n4 4\n2 4\n6 4\n2 4\n5 4\n2 1\n2 5\n2 5\n4 2\n1 4\n2 6\n3 2\n3 2\n6 6\n4 2\n3 4\n6 3\n6 6\n6 6\n5 5\n", "output": "1\n"}, {"input": "35\n6 1\n4 3\n1 2\n4 3\n6 4\n4 6\n3 1\n5 5\n3 4\n5 4\n4 6\n1 6\n2 4\n6 6\n5 4\n5 2\n1 3\n1 4\n3 5\n1 4\n2 3\n4 5\n4 3\n6 1\n5 3\n3 2\n5 6\n3 5\n6 5\n4 1\n1 3\n5 5\n4 6\n6 1\n1 3\n", "output": "1\n"}, {"input": "35\n4 3\n5 6\n4 5\n2 5\n6 6\n4 1\n2 2\n4 2\n3 4\n4 1\n6 6\n6 3\n1 5\n1 5\n5 6\n4 2\n4 6\n5 5\n2 2\n5 2\n1 2\n4 6\n6 6\n6 5\n2 1\n3 5\n2 5\n3 1\n5 3\n6 4\n4 6\n5 6\n5 1\n3 4\n3 5\n", "output": "1\n"}, {"input": "40\n5 6\n1 1\n3 3\n2 6\n6 6\n5 4\n6 4\n3 5\n1 3\n4 4\n4 4\n2 5\n1 3\n3 6\n5 2\n4 3\n4 4\n5 6\n2 3\n1 1\n3 1\n1 1\n1 5\n4 3\n5 5\n3 4\n6 6\n5 6\n2 2\n6 6\n2 1\n2 4\n5 2\n2 2\n1 1\n1 4\n4 2\n3 5\n5 5\n4 5\n", "output": "-1\n"}, {"input": "40\n3 2\n5 3\n4 6\n3 5\n6 1\n5 2\n1 2\n6 2\n5 3\n3 2\n4 4\n3 3\n5 2\n4 5\n1 4\n5 1\n3 3\n1 3\n1 3\n2 1\n3 6\n4 2\n4 6\n6 2\n2 5\n2 2\n2 5\n3 3\n5 3\n2 1\n3 2\n2 3\n6 3\n6 3\n3 4\n3 2\n4 3\n5 4\n2 4\n4 6\n", "output": "-1\n"}, {"input": "45\n2 4\n3 4\n6 1\n5 5\n1 1\n3 5\n4 3\n5 2\n3 6\n6 1\n4 4\n6 1\n2 1\n6 1\n3 6\n3 3\n6 1\n1 2\n1 5\n6 5\n1 3\n5 6\n6 1\n4 5\n3 6\n2 2\n1 2\n4 5\n5 6\n1 5\n6 2\n2 4\n3 3\n3 1\n6 5\n6 5\n2 1\n5 2\n2 1\n3 3\n2 2\n1 4\n2 2\n3 3\n2 1\n", "output": "-1\n"}, {"input": "45\n6 6\n1 6\n1 2\n3 5\n4 4\n2 1\n5 3\n2 1\n5 2\n5 3\n1 4\n5 2\n4 2\n3 6\n5 2\n1 5\n4 4\n5 5\n6 5\n2 1\n2 6\n5 5\n2 1\n6 1\n1 6\n6 5\n2 4\n4 3\n2 6\n2 4\n6 5\n6 4\n6 3\n6 6\n2 1\n6 4\n5 6\n5 4\n1 5\n5 1\n3 3\n5 6\n2 5\n4 5\n3 6\n", "output": "-1\n"}, {"input": "50\n4 4\n5 1\n6 4\n6 2\n6 2\n1 4\n5 5\n4 2\n5 5\n5 4\n1 3\n3 5\n6 1\n6 1\n1 4\n4 3\n5 1\n3 6\n2 2\n6 2\n4 4\n2 3\n4 2\n6 5\n5 6\n2 2\n2 4\n3 5\n1 5\n3 2\n3 4\n5 6\n4 6\n1 6\n4 5\n2 6\n2 2\n3 5\n6 4\n5 1\n4 3\n3 4\n3 5\n3 3\n2 3\n3 2\n2 2\n1 4\n3 1\n4 4\n", "output": "1\n"}, {"input": "50\n1 2\n1 4\n1 1\n4 5\n4 4\n3 2\n4 5\n3 5\n1 1\n3 4\n3 2\n2 4\n2 6\n2 6\n3 2\n4 6\n1 6\n3 1\n1 6\n2 1\n4 1\n1 6\n4 3\n6 6\n5 2\n6 4\n2 1\n4 3\n6 4\n5 1\n5 5\n3 1\n1 1\n5 5\n2 2\n2 3\n2 3\n3 5\n5 5\n1 6\n1 5\n3 6\n3 6\n1 1\n3 3\n2 6\n5 5\n1 3\n6 3\n6 6\n", "output": "-1\n"}, {"input": "55\n3 2\n5 6\n5 1\n3 5\n5 5\n1 5\n5 4\n6 3\n5 6\n4 2\n3 1\n1 2\n5 5\n1 1\n5 2\n6 3\n5 4\n3 6\n4 6\n2 6\n6 4\n1 4\n1 6\n4 1\n2 5\n4 3\n2 1\n2 1\n6 2\n3 1\n2 5\n4 4\n6 3\n2 2\n3 5\n5 1\n3 6\n5 4\n4 6\n6 5\n5 6\n2 2\n3 2\n5 2\n6 5\n2 2\n5 3\n3 1\n4 5\n6 4\n2 4\n1 2\n5 6\n2 6\n5 2\n", "output": "0\n"}, {"input": "55\n4 6\n3 3\n6 5\n5 3\n5 6\n2 3\n2 2\n3 4\n3 1\n5 4\n5 4\n2 4\n3 4\n4 5\n1 5\n6 3\n1 1\n5 1\n3 4\n1 5\n3 1\n2 5\n3 3\n4 3\n3 3\n3 1\n6 6\n3 3\n3 3\n5 6\n5 3\n3 5\n1 4\n5 5\n1 3\n1 4\n3 5\n3 6\n2 4\n2 4\n5 1\n6 4\n5 1\n5 5\n1 1\n3 2\n4 3\n5 4\n5 1\n2 4\n4 3\n6 1\n3 4\n1 5\n6 3\n", "output": "-1\n"}, {"input": "60\n2 6\n1 4\n3 2\n1 2\n3 2\n2 4\n6 4\n4 6\n1 3\n3 1\n6 5\n2 4\n5 4\n4 2\n1 6\n3 4\n4 5\n5 2\n1 5\n5 4\n3 4\n3 4\n4 4\n4 1\n6 6\n3 6\n2 4\n2 1\n4 4\n6 5\n3 1\n4 3\n1 3\n6 3\n5 5\n1 4\n3 1\n3 6\n1 5\n3 1\n1 5\n4 4\n1 3\n2 4\n6 2\n4 1\n5 3\n3 4\n5 6\n1 2\n1 6\n6 3\n1 6\n3 6\n3 4\n6 2\n4 6\n2 3\n3 3\n3 3\n", "output": "-1\n"}, {"input": "60\n2 3\n4 6\n2 4\n1 3\n5 6\n1 5\n1 2\n1 3\n5 6\n4 3\n4 2\n3 1\n1 3\n3 5\n1 5\n3 4\n2 4\n3 5\n4 5\n1 2\n3 1\n1 5\n2 5\n6 2\n1 6\n3 3\n6 2\n5 3\n1 3\n1 4\n6 4\n6 3\n4 2\n4 2\n1 4\n1 3\n3 2\n3 1\n2 1\n1 2\n3 1\n2 6\n1 4\n3 6\n3 3\n1 5\n2 4\n5 5\n6 2\n5 2\n3 3\n5 3\n3 4\n4 5\n5 6\n2 4\n5 3\n3 1\n2 4\n5 4\n", "output": "-1\n"}, {"input": "65\n5 4\n3 3\n1 2\n4 3\n3 5\n1 5\n4 5\n2 6\n1 2\n1 5\n6 3\n2 6\n4 3\n3 6\n1 5\n3 5\n4 6\n2 5\n6 5\n1 4\n3 4\n4 3\n1 4\n2 5\n6 5\n3 1\n4 3\n1 2\n1 1\n6 1\n5 2\n3 2\n1 6\n2 6\n3 3\n6 6\n4 6\n1 5\n5 1\n4 5\n1 4\n3 2\n5 4\n4 2\n6 2\n1 3\n4 2\n5 3\n6 4\n3 6\n1 2\n6 1\n6 6\n3 3\n4 2\n3 5\n4 6\n4 1\n5 4\n6 1\n5 1\n5 6\n6 1\n4 6\n5 5\n", "output": "1\n"}, {"input": "65\n5 4\n6 3\n5 4\n4 5\n5 3\n3 6\n1 3\n3 1\n1 3\n6 1\n6 4\n1 3\n2 2\n4 6\n4 1\n5 6\n6 5\n1 1\n1 3\n6 6\n4 1\n2 4\n5 4\n4 1\n5 5\n5 3\n6 2\n2 6\n4 2\n2 2\n6 2\n3 3\n4 5\n4 3\n3 1\n1 4\n4 5\n3 2\n5 5\n4 6\n5 1\n3 4\n5 4\n5 2\n1 6\n4 2\n3 4\n3 4\n1 3\n1 2\n3 3\n3 6\n6 4\n4 6\n6 2\n6 5\n3 2\n2 1\n6 4\n2 1\n1 5\n5 2\n6 5\n3 6\n5 1\n", "output": "1\n"}, {"input": "70\n4 1\n2 6\n1 1\n5 6\n5 1\n2 3\n3 5\n1 1\n1 1\n4 6\n4 3\n1 5\n2 2\n2 3\n3 1\n6 4\n3 1\n4 2\n5 4\n1 3\n3 5\n5 2\n5 6\n4 4\n4 5\n2 2\n4 5\n3 2\n3 5\n2 5\n2 6\n5 5\n2 6\n5 1\n1 1\n2 5\n3 1\n1 2\n6 4\n6 5\n5 5\n5 1\n1 5\n2 2\n6 3\n4 3\n6 2\n5 5\n1 1\n6 2\n6 6\n3 4\n2 2\n3 5\n1 5\n2 5\n4 5\n2 4\n6 3\n5 1\n2 6\n4 2\n1 4\n1 6\n6 2\n5 2\n5 6\n2 5\n5 6\n5 5\n", "output": "-1\n"}, {"input": "70\n4 3\n6 4\n5 5\n3 1\n1 2\n2 5\n4 6\n4 2\n3 2\n4 2\n1 5\n2 2\n4 3\n1 2\n6 1\n6 6\n1 6\n5 1\n2 2\n6 3\n4 2\n4 3\n1 2\n6 6\n3 3\n6 5\n6 2\n3 6\n6 6\n4 6\n5 2\n5 4\n3 3\n1 6\n5 6\n2 3\n4 6\n1 1\n1 2\n6 6\n1 1\n3 4\n1 6\n2 6\n3 4\n6 3\n5 3\n1 2\n2 3\n4 6\n2 1\n6 4\n4 6\n4 6\n4 2\n5 5\n3 5\n3 2\n4 3\n3 6\n1 4\n3 6\n1 4\n1 6\n1 5\n5 6\n4 4\n3 3\n3 5\n2 2\n", "output": "0\n"}, {"input": "75\n1 3\n4 5\n4 1\n6 5\n2 1\n1 4\n5 4\n1 5\n5 3\n1 2\n4 1\n1 1\n5 1\n5 3\n1 5\n4 2\n2 2\n6 3\n1 2\n4 3\n2 5\n5 3\n5 5\n4 1\n4 6\n2 5\n6 1\n2 4\n6 4\n5 2\n6 2\n2 4\n1 3\n5 4\n6 5\n5 4\n6 4\n1 5\n4 6\n1 5\n1 1\n4 4\n3 5\n6 3\n6 5\n1 5\n2 1\n1 5\n6 6\n2 2\n2 2\n4 4\n6 6\n5 4\n4 5\n3 2\n2 4\n1 1\n4 3\n3 2\n5 4\n1 6\n1 2\n2 2\n3 5\n2 6\n1 1\n2 2\n2 3\n6 2\n3 6\n4 4\n5 1\n4 1\n4 1\n", "output": "0\n"}, {"input": "75\n1 1\n2 1\n5 5\n6 5\n6 3\n1 6\n6 1\n4 4\n2 1\n6 2\n3 1\n6 4\n1 6\n2 2\n4 3\n4 2\n1 2\n6 2\n4 2\n5 1\n1 2\n3 2\n6 6\n6 3\n2 4\n4 1\n4 1\n2 4\n5 5\n2 3\n5 5\n4 5\n3 1\n1 5\n4 3\n2 3\n3 5\n4 6\n5 6\n1 6\n2 3\n2 2\n1 2\n5 6\n1 4\n1 5\n1 3\n6 2\n1 2\n4 2\n2 1\n1 3\n6 4\n4 1\n5 2\n6 2\n3 5\n2 3\n4 2\n5 1\n5 6\n3 2\n2 1\n6 6\n2 1\n6 2\n1 1\n3 2\n1 2\n3 5\n4 6\n1 3\n3 4\n5 5\n6 2\n", "output": "1\n"}, {"input": "80\n3 1\n6 3\n2 2\n2 2\n6 3\n6 1\n6 5\n1 4\n3 6\n6 5\n1 3\n2 4\n1 4\n3 1\n5 3\n5 3\n1 4\n2 5\n4 3\n4 4\n4 5\n6 1\n3 1\n2 6\n4 2\n3 1\n6 5\n2 6\n2 2\n5 1\n1 3\n5 1\n2 1\n4 3\n6 3\n3 5\n4 3\n5 6\n3 3\n4 1\n5 1\n6 5\n5 1\n2 5\n6 1\n3 2\n4 3\n3 3\n5 6\n1 6\n5 2\n1 5\n5 6\n6 4\n2 2\n4 2\n4 6\n4 2\n4 4\n6 5\n5 2\n6 2\n4 6\n6 4\n4 3\n5 1\n4 1\n3 5\n3 2\n3 2\n5 3\n5 4\n3 4\n1 3\n1 2\n6 6\n6 3\n6 1\n5 6\n3 2\n", "output": "0\n"}, {"input": "80\n4 5\n3 3\n3 6\n4 5\n3 4\n6 5\n1 5\n2 5\n5 6\n5 1\n5 1\n1 2\n5 5\n5 1\n2 3\n1 1\n4 5\n4 1\n1 1\n5 5\n5 6\n5 2\n5 4\n4 2\n6 2\n5 3\n3 2\n4 2\n1 3\n1 6\n2 1\n6 6\n4 5\n6 4\n2 2\n1 6\n6 2\n4 3\n2 3\n4 6\n4 6\n6 2\n3 4\n4 3\n5 5\n1 6\n3 2\n4 6\n2 3\n1 6\n5 4\n4 2\n5 4\n1 1\n4 3\n5 1\n3 6\n6 2\n3 1\n4 1\n5 3\n2 2\n3 4\n3 6\n3 5\n5 5\n5 1\n3 5\n2 6\n6 3\n6 5\n3 3\n5 6\n1 2\n3 1\n6 3\n3 4\n6 6\n6 6\n1 2\n", "output": "-1\n"}, {"input": "85\n6 3\n4 1\n1 2\n3 5\n6 4\n6 2\n2 6\n1 2\n1 5\n6 2\n1 4\n6 6\n2 4\n4 6\n4 5\n1 6\n3 1\n2 5\n5 1\n5 2\n3 5\n1 1\n4 1\n2 3\n1 1\n3 3\n6 4\n1 4\n1 1\n3 6\n1 5\n1 6\n2 5\n2 2\n5 1\n6 6\n1 3\n1 5\n5 6\n4 5\n4 3\n5 5\n1 3\n6 3\n4 6\n2 4\n5 6\n6 2\n4 5\n1 4\n1 4\n6 5\n1 6\n6 1\n1 6\n5 5\n2 1\n5 2\n2 3\n1 6\n1 6\n1 6\n5 6\n2 4\n6 5\n6 5\n4 2\n5 4\n3 4\n4 3\n6 6\n3 3\n3 2\n3 6\n2 5\n2 1\n2 5\n3 4\n1 2\n5 4\n6 2\n5 1\n1 4\n3 4\n4 5\n", "output": "0\n"}, {"input": "85\n3 1\n3 2\n6 3\n1 3\n2 1\n3 6\n1 4\n2 5\n6 5\n1 6\n1 5\n1 1\n4 3\n3 5\n4 6\n3 2\n6 6\n4 4\n4 1\n5 5\n4 2\n6 2\n2 2\n4 5\n6 1\n3 4\n4 5\n3 5\n4 2\n3 5\n4 4\n3 1\n4 4\n6 4\n1 4\n5 5\n1 5\n2 2\n6 5\n5 6\n6 5\n3 2\n3 2\n6 1\n6 5\n2 1\n4 6\n2 1\n3 1\n5 6\n1 3\n5 4\n1 4\n1 4\n5 3\n2 3\n1 3\n2 2\n5 3\n2 3\n2 3\n1 3\n3 6\n4 4\n6 6\n6 2\n5 1\n5 5\n5 5\n1 2\n1 4\n2 4\n3 6\n4 6\n6 3\n6 4\n5 5\n3 2\n5 4\n5 4\n4 5\n6 4\n2 1\n5 2\n5 1\n", "output": "-1\n"}, {"input": "90\n5 2\n5 5\n5 1\n4 6\n4 3\n5 3\n5 6\n5 1\n3 4\n1 3\n4 2\n1 6\n6 4\n1 2\n6 1\n4 1\n6 2\n6 5\n6 2\n5 4\n3 6\n1 1\n5 5\n2 2\n1 6\n3 5\n6 5\n1 6\n1 5\n2 3\n2 6\n2 3\n3 3\n1 3\n5 1\n2 5\n3 6\n1 2\n4 4\n1 6\n2 3\n1 5\n2 5\n1 3\n2 2\n4 6\n3 6\n6 3\n1 2\n4 3\n4 5\n4 6\n3 2\n6 5\n6 2\n2 5\n2 4\n1 3\n1 6\n4 3\n1 3\n6 4\n4 6\n4 1\n1 1\n4 1\n4 4\n6 2\n6 5\n1 1\n2 2\n3 1\n1 4\n6 2\n5 2\n1 4\n1 3\n6 5\n3 2\n6 4\n3 4\n2 6\n2 2\n6 3\n4 6\n1 2\n4 2\n3 4\n2 3\n1 5\n", "output": "-1\n"}, {"input": "90\n1 4\n3 5\n4 2\n2 5\n4 3\n2 6\n2 6\n3 2\n4 4\n6 1\n4 3\n2 3\n5 3\n6 6\n2 2\n6 3\n4 1\n4 4\n5 6\n6 4\n4 2\n5 6\n4 6\n4 4\n6 4\n4 1\n5 3\n3 2\n4 4\n5 2\n5 4\n6 4\n1 2\n3 3\n3 4\n6 4\n1 6\n4 2\n3 2\n1 1\n2 2\n5 1\n6 6\n4 1\n5 2\n3 6\n2 1\n2 2\n4 6\n6 5\n4 4\n5 5\n5 6\n1 6\n1 4\n5 6\n3 6\n6 3\n5 6\n6 5\n5 1\n6 1\n6 6\n6 3\n1 5\n4 5\n3 1\n6 6\n3 4\n6 2\n1 4\n2 2\n3 2\n5 6\n2 4\n1 4\n6 3\n4 6\n1 4\n5 2\n1 2\n6 5\n1 5\n1 4\n4 2\n2 5\n3 2\n5 1\n5 4\n5 3\n", "output": "-1\n"}, {"input": "95\n4 3\n3 2\n5 5\n5 3\n1 6\n4 4\n5 5\n6 5\n3 5\n1 5\n4 2\n5 1\n1 2\n2 3\n6 4\n2 3\n6 3\n6 5\n5 6\n1 4\n2 6\n2 6\n2 5\n2 1\n3 1\n3 5\n2 2\n6 1\n2 4\n4 6\n6 6\n6 4\n3 2\n5 1\n4 3\n6 5\n2 3\n4 1\n2 5\n6 5\n6 5\n6 5\n5 1\n5 4\n4 6\n3 2\n2 5\n2 6\n4 6\n6 3\n6 4\n5 6\n4 6\n2 4\n3 4\n1 4\n2 4\n2 3\n5 6\n6 4\n3 1\n5 1\n3 6\n3 5\n2 6\n6 3\n4 3\n3 1\n6 1\n2 2\n6 3\n2 2\n2 2\n6 4\n6 1\n2 1\n5 6\n5 4\n5 2\n3 4\n3 6\n2 1\n1 6\n5 5\n2 6\n2 3\n3 6\n1 3\n1 5\n5 1\n1 2\n2 2\n5 3\n6 4\n4 5\n", "output": "0\n"}, {"input": "95\n4 5\n5 6\n3 2\n5 1\n4 3\n4 1\n6 1\n5 2\n2 4\n5 3\n2 3\n6 4\n4 1\n1 6\n2 6\n2 3\n4 6\n2 4\n3 4\n4 2\n5 5\n1 1\n1 5\n4 3\n4 5\n6 2\n6 1\n6 3\n5 5\n4 1\n5 1\n2 3\n5 1\n3 6\n6 6\n4 5\n4 4\n4 3\n1 6\n6 6\n4 6\n6 4\n1 2\n6 2\n4 6\n6 6\n5 5\n6 1\n5 2\n4 5\n6 6\n6 5\n4 4\n1 5\n4 6\n4 1\n3 6\n5 1\n3 1\n4 6\n4 5\n1 3\n5 4\n4 5\n2 2\n6 1\n5 2\n6 5\n2 2\n1 1\n6 3\n6 1\n2 6\n3 3\n2 1\n4 6\n2 4\n5 5\n5 2\n3 2\n1 2\n6 6\n6 2\n5 1\n2 6\n5 2\n2 2\n5 5\n3 5\n3 3\n2 6\n5 3\n4 3\n1 6\n5 4\n", "output": "-1\n"}, {"input": "100\n1 1\n3 5\n2 1\n1 2\n3 4\n5 6\n5 6\n6 1\n5 5\n2 4\n5 5\n5 6\n6 2\n6 6\n2 6\n1 4\n2 2\n3 2\n1 3\n5 5\n6 3\n5 6\n1 1\n1 2\n1 2\n2 1\n2 3\n1 6\n4 3\n1 1\n2 5\n2 4\n4 4\n1 5\n3 3\n6 1\n3 5\n1 1\n3 6\n3 1\n4 2\n4 3\n3 6\n6 6\n1 6\n6 2\n2 5\n5 4\n6 3\n1 4\n2 6\n6 2\n3 4\n6 1\n6 5\n4 6\n6 5\n4 4\n3 1\n6 3\n5 1\n2 4\n5 1\n1 2\n2 4\n2 1\n6 6\n5 3\n4 6\n6 3\n5 5\n3 3\n1 1\n6 5\n4 3\n2 6\n1 5\n3 5\n2 4\n4 5\n1 6\n2 3\n6 3\n5 5\n2 6\n2 6\n3 4\n3 2\n6 1\n3 4\n6 4\n3 3\n2 3\n5 1\n3 1\n6 2\n2 3\n6 4\n1 4\n1 2\n", "output": "-1\n"}, {"input": "100\n1 1\n5 5\n1 2\n5 3\n5 5\n2 2\n1 5\n3 4\n3 2\n1 3\n5 6\n4 5\n2 1\n5 5\n2 2\n1 6\n6 1\n5 1\n4 1\n4 6\n3 5\n6 1\n2 3\n5 6\n3 6\n2 3\n5 6\n1 6\n3 2\n2 2\n3 3\n6 5\n5 5\n1 4\n5 6\n6 4\n1 4\n1 2\n2 6\n3 2\n6 4\n5 3\n3 3\n6 4\n4 6\n2 2\n5 6\n5 1\n1 2\n3 4\n4 5\n1 1\n3 4\n5 2\n4 5\n3 3\n1 1\n3 4\n1 6\n2 4\n1 3\n3 2\n6 5\n1 6\n3 6\n2 3\n2 6\n5 1\n5 5\n5 6\n4 1\n6 2\n3 6\n5 3\n2 2\n2 4\n6 6\n3 6\n4 6\n2 5\n5 3\n1 2\n3 4\n3 4\n6 2\n2 4\n2 2\n4 6\n3 5\n4 2\n5 6\n4 2\n2 3\n6 2\n5 6\n2 1\n3 3\n6 6\n4 3\n4 2\n", "output": "1\n"}, {"input": "1\n2 2\n", "output": "0\n"}, {"input": "3\n2 4\n6 6\n3 3\n", "output": "-1\n"}, {"input": "2\n3 6\n4 1\n", "output": "1\n"}, {"input": "3\n1 1\n1 1\n3 3\n", "output": "-1\n"}, {"input": "3\n2 3\n1 1\n2 3\n", "output": "1\n"}, {"input": "3\n2 2\n2 1\n1 2\n", "output": "1\n"}, {"input": "3\n1 1\n1 1\n1 1\n", "output": "-1\n"}]
321
Alice has a lovely piece of cloth. It has the shape of a square with a side of length $a$ centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length $b$ centimeters (where $b < a$). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to Bob. Now she is left with an ugly L shaped cloth (see pictures below). Alice would like to know whether the area of her cloth expressed in square centimeters is prime. Could you help her to determine it? -----Input----- The first line contains a number $t$Β ($1 \leq t \leq 5$)Β β€” the number of test cases. Each of the next $t$ lines describes the $i$-th test case. It contains two integers $a$ and $b~(1 \leq b < a \leq 10^{11})$Β β€” the side length of Alice's square and the side length of the square that Bob wants. -----Output----- Print $t$ lines, where the $i$-th line is the answer to the $i$-th test case. Print "YES" (without quotes) if the area of the remaining piece of cloth is prime, otherwise print "NO". You can print each letter in an arbitrary case (upper or lower). -----Example----- Input 4 6 5 16 13 61690850361 24777622630 34 33 Output YES NO NO YES -----Note----- The figure below depicts the first test case. The blue part corresponds to the piece which belongs to Bob, and the red part is the piece that Alice keeps for herself. The area of the red part is $6^2 - 5^2 = 36 - 25 = 11$, which is prime, so the answer is "YES". [Image] In the second case, the area is $16^2 - 13^2 = 87$, which is divisible by $3$. [Image] In the third case, the area of the remaining piece is $61690850361^2 - 24777622630^2 = 3191830435068605713421$. This number is not prime because $3191830435068605713421 = 36913227731 \cdot 86468472991 $. In the last case, the area is $34^2 - 33^2 = 67$.
interview
[{"code": "def isPrime(n) : \n # Corner cases \n if (n <= 1) : \n return False\n if (n <= 3) : \n return True\n \n # This is checked so that we can skip \n # middle five numbers in below loop \n if (n % 2 == 0 or n % 3 == 0) : \n return False\n \n i = 5\n while(i * i <= n) : \n if (n % i == 0 or n % (i + 2) == 0) : \n return False\n i = i + 6\n \n return True\nt=int(input())\nfor yes in range(t):\n\ta,b=map(int,input().split())\n\txx=a-b\n\tyy=a+b \n\tif xx==1 and isPrime(yy)==True:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\")", "passed": true, "time": 0.39, "memory": 14268.0, "status": "done"}, {"code": "def isPrime(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 return True\nfor i in ' '*int(input()):\n a,b=map(int,input().split())\n if a-b>1:print('NO')\n else:\n print(['NO','YES'][isPrime(a+b)])", "passed": true, "time": 0.69, "memory": 14512.0, "status": "done"}, {"code": "def check_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\nt = int(input())\nfor tnum in range(t):\n a, b = map(int, input().split())\n if a != b + 1:\n print(\"NO\")\n else:\n print(\"YES\" if check_prime(a + b) else \"NO\")", "passed": true, "time": 2.14, "memory": 14288.0, "status": "done"}, {"code": "from math import sqrt\nn = int(input())\nfor i in range(n):\n a, b = map(int, input().split())\n first = a - b\n second = a + b\n if first != 1:\n print('NO')\n else:\n f = False\n for i in range(2, int(sqrt(second)) + 1):\n if second % i == 0:\n f = True\n break\n if f:\n print('NO')\n else:\n print('YES')", "passed": true, "time": 1.51, "memory": 14468.0, "status": "done"}, {"code": "def prime(n):\n if n < 2:\n return False\n elif n % 2 == 0:\n return False\n else:\n for k in range(3, 1 + int(n ** .5), 2):\n if n % k == 0:\n return False\n return True\n\n\nt = int(input())\nfor i in range(t):\n a, b = list(map(int, input().split()))\n n = (a + b)\n if a - b > 1:\n print('NO')\n else:\n if prime(n):\n print('YES')\n else:\n print('NO')\n", "passed": true, "time": 0.43, "memory": 14392.0, "status": "done"}, {"code": "t = int(input())\nfor _ in range(t):\n a, b = list(map(int, input().split()))\n if a - b != 1:\n print(\"NO\")\n continue\n c = a + b\n for t in range(2, int(c ** 0.5) + 1):\n if c % t == 0:\n print(\"NO\")\n break\n else:\n print(\"YES\")\n", "passed": true, "time": 1.53, "memory": 14536.0, "status": "done"}, {"code": "def check(a):\n for i in range(2, round(a**0.5 + 1)):\n if not a % i:\n return 0\n return 1\n\n\nfor i in range(int(input())):\n a, b = map(int, input().split())\n if (a - b) > 1 and (a + b) > 1:\n print('NO')\n else:\n print('YES' if check(a**2-b**2) else 'NO')", "passed": true, "time": 0.67, "memory": 14288.0, "status": "done"}, {"code": "from math import sqrt \nfrom itertools import count, islice\n\ndef isPrime(n):\n return n > 1 and all(n%i for i in islice(count(2), int(sqrt(n)-1)))\n\nt=int(input())\n\nfor i in range(t):\n\ta,b=map(int,input().split())\n\tans = False\n\tif a-b==1:\n\t\tx = a+b\n\t\tans=isPrime(x)\n\n\tif ans:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint(\"NO\")", "passed": true, "time": 0.8, "memory": 14440.0, "status": "done"}, {"code": "t=int(input())\nimport math\nfor i in range(t):\n a,b=list(map(int,input().split()))\n if((a-b)!=1):\n print(\"NO\")\n else:\n l=2*a-1\n p=0\n for k in range(2,int(math.sqrt(l))+1):\n if(l%k==0):\n print(\"NO\")\n p=1\n break \n if(p==0):\n print(\"YES\")\n", "passed": true, "time": 0.69, "memory": 14472.0, "status": "done"}, {"code": "def prime(x):\n if x==1:\n return False\n ret=True\n for i in range(2,int(x**0.5)+1):\n if x%i==0:\n ret=False\n return ret\n\nn=int(input())\nfor i in range(n):\n s=input().split()\n d=int(s[0])-int(s[1])\n if d!=1:\n print(\"NO\")\n else:\n if prime(int(s[0])+int(s[1])):\n print(\"YES\")\n else:\n print(\"NO\")\n", "passed": true, "time": 1.88, "memory": 14528.0, "status": "done"}, {"code": "t = int(input())\nwhile t > 0:\n a, b = list(map(int,input().split()))\n if a - b != 1 :\n print(\"NO\")\n else:\n num = a + b\n num2 = int(num ** 0.5)\n num3 = 2\n ans = 0\n while num3 <= num2:\n if num % num3 == 0:\n ans = 1\n num3 += 1\n if ans == 1:\n print(\"NO\")\n else:\n print(\"YES\")\n t -= 1\n", "passed": true, "time": 2.23, "memory": 14468.0, "status": "done"}, {"code": "import sys\n\ndef isprime(x):\n import math\n if x == 1:\n return True\n\n for i in range(2, math.ceil(math.sqrt(x))+1):\n if x % i == 0:\n return False\n return True\n\n\ndef __starting_point():\n cin = sys.stdin\n\n T = int(next(cin))\n for _ in range(T):\n n, m = list(map(int, next(cin).split()))\n\n # n**2-m**2 = (n-m)*(n+m)\n\n if n-m == 1 and isprime(n+m):\n print('YES')\n else:\n print('NO')\n\n__starting_point()", "passed": true, "time": 1.53, "memory": 14464.0, "status": "done"}, {"code": "def isPrime(n) : \n # Corner cases \n if (n <= 1) : \n return False\n if (n <= 3) : \n return True\n \n # This is checked so that we can skip \n # middle five numbers in below loop \n if (n % 2 == 0 or n % 3 == 0) : \n return False\n \n i = 5\n while(i * i <= n) : \n if (n % i == 0 or n % (i + 2) == 0) : \n return False\n i = i + 6\n \n return True\nt=int(input())\nfor l in range(t):\n\ta,b=list(map(int,input().split()))\n\tif(a-b!=1):\n\t\tprint(\"NO\")\n\telse:\n\t\tif(isPrime(a+b)):\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n\n", "passed": true, "time": 0.41, "memory": 14452.0, "status": "done"}, {"code": "from math import sqrt; from itertools import count, islice\n\nn = int(input())\n\n\ndef isPrime(n):\n return n > 1 and all(n%i for i in islice(count(2), int(sqrt(n)-1)))\n\ndef eval_(a, b):\n if abs(a - b)!=1:\n return \"NO\"\n result = isPrime(a + b)\n if result:\n return \"YES\"\n else:\n return \"NO\"\n\n\nfor i in range(n):\n (a, b) = [int(x) for x in input().split()]\n print(eval_(a, b))", "passed": true, "time": 0.9, "memory": 14436.0, "status": "done"}, {"code": "import math\n\nt = int(input())\n\n\ndef isprime(c):\n\t# print(int(math.ceil(math.sqrt(c)))+1)\n\tfor x in range(2, int(math.ceil(math.sqrt(c)))+1):\n\t\t# print(\"x: {}\".format(x))\n\t\tif c % x == 0:\n\t\t\treturn False\n\n\treturn True\n\nfor x in range(t):\n\ta, b = list(map(int, input().split()))\n\tif (1 == a-b) and isprime(a + b):\n\t\tprint (\"YES\")\n\telse:\n\t\tprint (\"NO\")\n\n\n\n", "passed": true, "time": 0.69, "memory": 14312.0, "status": "done"}, {"code": "from math import sqrt, floor\n\n\ndef check(n):\n for i in range(2, floor(sqrt(n)) + 1):\n if (n % i == 0):\n return False\n\n return True\n\n\nt = int(input())\n\nfor i in range(t):\n a, b = list(map(int, input().split()))\n\n if (a - b == 1 and check(a + b)):\n print(\"YES\")\n else:\n print(\"NO\")\n", "passed": true, "time": 0.69, "memory": 14460.0, "status": "done"}, {"code": "t = int(input())\n\ndef divider(n):\n i = 2\n j = 0\n while i**2 <= n and j != 1:\n if n%i == 0:\n j = 1\n i += 1\n if j == 1:\n return False\n else:\n return True\n\n\nfor i in range(t):\n a, b = list(map(int,input().split()))\n if a-b == 1 and divider(a+b):\n print(\"YES\")\n else:\n print(\"NO\")\n", "passed": true, "time": 3.1, "memory": 14432.0, "status": "done"}, {"code": "def isprime(n):\n i = 2\n m = n\n while (i * i <= n):\n while (n % i == 0):\n n /= i\n i += 1\n return m == n\n\n\nt = int(input())\nfor i in range(t):\n a, b = map(int, input().split())\n if (isprime(a + b) and a - b == 1):\n print(\"YES\")\n else:\n print(\"NO\")", "passed": true, "time": 2.13, "memory": 14356.0, "status": "done"}, {"code": "t=int(input())\na=[]\nb=[]\nfor i in range(t):\n aa,bb=[int(el) for el in input().split()]\n a.append(aa)\n b.append(bb)\n\ndef prost(n):\n if n==3:\n return True\n if n%2==0:\n return False\n for i in range (3,int(n**0.5)+1,2):\n if n%i==0:\n return False\n return True\n return\n\nfor i in range(t):\n if a[i]-b[i]!=1:\n print ('NO')\n continue\n if prost(a[i]+b[i]):\n print('YES')\n else:\n print('NO')\n", "passed": true, "time": 0.42, "memory": 14520.0, "status": "done"}, {"code": "import random\ndef MillerRabinPrimalityTest(number):\n '''\n because the algorithm input is ODD number than if we get\n even and it is the number 2 we return TRUE ( spcial case )\n if we get the number 1 we return false and any other even \n number we will return false.\n '''\n if number == 2:\n return True\n elif number == 1 or number % 2 == 0:\n return False\n \n ''' first we want to express n as : 2^s * r ( were r is odd ) '''\n \n ''' the odd part of the number '''\n oddPartOfNumber = number - 1\n \n ''' The number of time that the number is divided by two '''\n timesTwoDividNumber = 0\n \n ''' while r is even divid by 2 to find the odd part '''\n while oddPartOfNumber % 2 == 0:\n oddPartOfNumber = oddPartOfNumber // 2\n timesTwoDividNumber = timesTwoDividNumber + 1 \n \n '''\n since there are number that are cases of \"strong liar\" we \n need to check more then one number\n '''\n for time in range(3):\n \n ''' choose \"Good\" random number '''\n while True:\n ''' Draw a RANDOM number in range of number ( Z_number ) '''\n randomNumber = random.randint(2, number)-1\n if randomNumber != 0 and randomNumber != 1:\n break\n \n ''' randomNumberWithPower = randomNumber^oddPartOfNumber mod number '''\n randomNumberWithPower = pow(randomNumber, oddPartOfNumber, number)\n \n ''' if random number is not 1 and not -1 ( in mod n ) '''\n if (randomNumberWithPower != 1) and (randomNumberWithPower != number - 1):\n # number of iteration\n iterationNumber = 1\n \n ''' while we can squre the number and the squered number is not -1 mod number'''\n while (iterationNumber <= timesTwoDividNumber - 1) and (randomNumberWithPower != number - 1):\n ''' squre the number '''\n randomNumberWithPower = pow(randomNumberWithPower, 2, number)\n \n # inc the number of iteration\n iterationNumber = iterationNumber + 1\n ''' \n if x != -1 mod number then it because we did not found strong witnesses\n hence 1 have more then two roots in mod n ==>\n n is composite ==> return false for primality\n '''\n if (randomNumberWithPower != (number - 1)):\n return False\n \n ''' well the number pass the tests ==> it is probably prime ==> return true for primality '''\n return True\ncases=int(input())\nfor case in range(cases):\n a,b=map(int,input().split())\n t=MillerRabinPrimalityTest((a**2)-(b**2))\n if t:\n print(\"YES\")\n else:\n print(\"NO\")", "passed": true, "time": 0.15, "memory": 14324.0, "status": "done"}, {"code": "def divider(n):\n i = 2\n j = 0\n while i**2 <= n and j != 1:\n if n % i == 0:\n j = 1\n i += 1\n if j == 1:\n return False\n else:\n return True\n\n\ni = int(input())\nfor i in range(i):\n a, b = list(map(int, input().split()))\n if a - b == 1 and divider(a+b):\n print(\"YES\")\n else:\n print(\"NO\")\n", "passed": true, "time": 3.09, "memory": 14472.0, "status": "done"}, {"code": "import math\n\ndef is_prime(n):\n bound = int(math.sqrt(n + 1) + 1)\n for k in range(2, bound):\n if n % k == 0:\n return False\n return True\n\n\ndef solve():\n a, b = (int(x) for x in input().split())\n if a - b != 1:\n print('NO')\n return\n\n if is_prime(a+b):\n print('YES')\n else:\n print('NO')\n\n\nnum_tests = int(input())\nfor _ in range(num_tests):\n solve()\n", "passed": true, "time": 0.69, "memory": 14428.0, "status": "done"}, {"code": "\nimport math as m\ndef f(a):\n\tif (a==2) : return True\n\tfor i in range(2,round(m.sqrt(a))+1):\n\t\tif a%i==0:\n\t\t\treturn False\n\treturn True\n\nt=int(input())\n\n\nfor i in range(t):\n\ta,b=input().split()\n\n\ta=int(a)\n\tb=int(b)\n\n\tif (a-b)==1 and f(a+b) :\n\t\tprint(\"YES\")\n\telse :\n\t\tprint(\"NO\")\n\n", "passed": true, "time": 0.69, "memory": 14432.0, "status": "done"}]
[{"input": "4\n6 5\n16 13\n61690850361 24777622630\n34 33\n", "output": "YES\nNO\nNO\nYES\n"}, {"input": "5\n160 159\n223 222\n480 479\n357 356\n345 344\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "5\n631 582\n201 106\n780 735\n608 528\n470 452\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "5\n2 1\n3 1\n4 1\n5 1\n8 7\n", "output": "YES\nNO\nNO\nNO\nNO\n"}, {"input": "5\n2187 2186\n517 516\n3235 3234\n4810 4809\n3076 3075\n", "output": "YES\nYES\nYES\nYES\nYES\n"}, {"input": "5\n40957587394 40957587393\n46310781841 46310781840\n21618631676 21618631675\n17162988704 17162988703\n16831085306 16831085305\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "5\n35838040099 35838040098\n26612022790 26612022789\n23649629085 23649629084\n17783940691 17783940690\n31547284201 31547284200\n", "output": "YES\nYES\nYES\nYES\nYES\n"}, {"input": "5\n45967567181 17972496150\n96354194442 71676080197\n66915115533 22181324318\n62275223621 22258625262\n92444726334 84313947726\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "5\n77734668390 12890100149\n62903604396 24274903133\n22822672980 7380491861\n50311650674 7380960075\n63911598474 3692382643\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "5\n21 20\n48 47\n59140946515 26225231058\n78 38\n31 30\n", "output": "YES\nNO\nNO\nNO\nYES\n"}, {"input": "5\n529 169\n232 231\n283 282\n217 216\n34310969148 14703433301\n", "output": "NO\nYES\nNO\nYES\nNO\n"}, {"input": "1\n100000000000 99999999999\n", "output": "NO\n"}, {"input": "5\n8680 4410\n59011181086 3472811643\n770 769\n1911 1910\n3615 3614\n", "output": "NO\nNO\nNO\nYES\nYES\n"}, {"input": "5\n62903604396 24274903133\n37198 37197\n16929 16928\n38325 38324\n49905 33035\n", "output": "NO\nNO\nYES\nYES\nNO\n"}, {"input": "5\n5 4\n7 6\n4 3\n4 1\n9 8\n", "output": "NO\nYES\nYES\nNO\nYES\n"}, {"input": "5\n497334 497333\n437006 437005\n88531320027 6466043806\n863754 694577\n151084 151083\n", "output": "YES\nNO\nNO\nNO\nYES\n"}, {"input": "5\n4606204 4606203\n1620972 1620971\n67109344913 14791364910\n8894157 3383382\n4110450 4110449\n", "output": "NO\nYES\nNO\nNO\nYES\n"}, {"input": "5\n24095027715 9551467282\n34945375 34945374\n16603803 16603802\n58997777 26551505\n39762660 39762659\n", "output": "NO\nYES\nNO\nNO\nYES\n"}, {"input": "5\n313997256 313997255\n224581770 224581769\n549346780 476752290\n60559465837 28745119200\n274287972 274287971\n", "output": "YES\nNO\nNO\nNO\nYES\n"}, {"input": "2\n10 9\n3 2\n", "output": "YES\nYES\n"}, {"input": "5\n31125459810 8334535873\n3439858310 3439858309\n9242031363 5238155938\n1025900247 1025900246\n3754943269 3754943268\n", "output": "NO\nNO\nNO\nYES\nYES\n"}, {"input": "5\n81271189833 16089352976\n98451628984 76827432884\n19327420986 19327420985\n15702367716 15702367715\n49419997643 49419997642\n", "output": "NO\nNO\nYES\nYES\nNO\n"}, {"input": "5\n41024865848 173372595\n60687612551 33296061228\n64391844305 16241932104\n81009941361 1976380712\n58548577555 28344963216\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "5\n18975453681 18975453680\n33749667489 33749667488\n32212198515 32212198514\n39519664171 39519664170\n5846685141 5846685140\n", "output": "YES\nYES\nYES\nYES\nYES\n"}, {"input": "5\n11065751057 11065751056\n14816488910 14816488909\n7599636437 7599636436\n32868029728 32868029727\n29658708183 29658708182\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "5\n61150570394 22605752451\n64903938253 57679397316\n79673778456 37950907361\n59209507183 35302232713\n88726603470 50246884625\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "5\n45925060463 34682596536\n34161192623 19459231506\n74417875602 23392925845\n58874966000 740257587\n64371611777 32770840566\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "5\n17406961899 17406961898\n21570966087 21570966086\n31354673689 31354673688\n24493273605 24493273604\n44187316822 44187316821\n", "output": "YES\nYES\nYES\nYES\nYES\n"}, {"input": "5\n49948848825 49948848824\n33118965298 33118965297\n34285673904 34285673903\n46923258767 46923258766\n48431110341 48431110340\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "5\n38196676529 10033677341\n76701388169 39387747140\n96968196508 53479702571\n98601117347 56935774756\n89303447903 62932115422\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "5\n84969448764 45272932776\n40645404603 21303358412\n95260279132 55067325137\n92908555827 18951498996\n73854112015 59320860713\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "1\n5 4\n", "output": "NO\n"}, {"input": "1\n25 24\n", "output": "NO\n"}, {"input": "1\n13 12\n", "output": "NO\n"}, {"input": "2\n50000000605 50000000604\n5 4\n", "output": "YES\nNO\n"}, {"input": "1\n281 280\n", "output": "NO\n"}, {"input": "3\n5 4\n13 12\n25 24\n", "output": "NO\nNO\nNO\n"}, {"input": "1\n45131796361 45131796360\n", "output": "NO\n"}, {"input": "5\n61 60\n10000010 10\n12345 45\n12343345 65\n1030 6\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "2\n61 60\n85 84\n", "output": "NO\nNO\n"}, {"input": "5\n61 60\n5242157731 5242157730\n12345 45\n5011907031 5011907030\n20207223564 20207223563\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "1\n80003600041 80003600040\n", "output": "NO\n"}, {"input": "5\n5242157731 5242157730\n12345 45\n5011907031 5011907030\n20207223564 20207223563\n61 60\n", "output": "NO\nNO\nNO\nNO\nNO\n"}, {"input": "3\n25 24\n841 840\n28561 28560\n", "output": "NO\nNO\nNO\n"}, {"input": "1\n61 60\n", "output": "NO\n"}, {"input": "1\n7 6\n", "output": "YES\n"}, {"input": "1\n99999999999 36\n", "output": "NO\n"}, {"input": "1\n421 420\n", "output": "NO\n"}, {"input": "1\n5928189385 5928189384\n", "output": "NO\n"}, {"input": "1\n122 121\n", "output": "NO\n"}, {"input": "1\n61251050005 61251050004\n", "output": "NO\n"}, {"input": "1\n160489044 125525827\n", "output": "NO\n"}, {"input": "1\n18 14\n", "output": "NO\n"}, {"input": "1\n96793840086 96793840085\n", "output": "NO\n"}, {"input": "1\n84777676971 84777676970\n", "output": "NO\n"}, {"input": "1\n3121 3120\n", "output": "NO\n"}, {"input": "1\n500000041 500000040\n", "output": "NO\n"}, {"input": "1\n5484081721 5484081720\n", "output": "NO\n"}, {"input": "1\n4999100041 4999100040\n", "output": "NO\n"}]
323
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers A and B and then calculates the greatest common divisor of integers "A factorial" and "B factorial". Formally the hacker wants to find out GCD(A!, B!). It's well known that the factorial of an integer x is a product of all positive integers less than or equal to x. Thus x! = 1Β·2Β·3Β·...Β·(x - 1)Β·x. For example 4! = 1Β·2Β·3Β·4 = 24. Recall that GCD(x, y) is the largest positive integer q that divides (without a remainder) both x and y. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? -----Input----- The first and single line contains two integers A and B (1 ≀ A, B ≀ 10^9, min(A, B) ≀ 12). -----Output----- Print a single integer denoting the greatest common divisor of integers A! and B!. -----Example----- Input 4 3 Output 6 -----Note----- Consider the sample. 4! = 1Β·2Β·3Β·4 = 24. 3! = 1Β·2Β·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
interview
[{"code": "a, b = map(int, input().split())\na = min(a, b)\nans = 1\nfor i in range(1, a + 1):\n ans *= i\nprint(ans)", "passed": true, "time": 0.28, "memory": 14244.0, "status": "done"}, {"code": "import math\nm = min(list(map(int,input().split())))\nprint(math.factorial(m))\n", "passed": true, "time": 0.18, "memory": 14376.0, "status": "done"}, {"code": "read = lambda: map(int, input().split())\na, b = read()\nx = min(a, b)\nans = 1\nfor i in range(2, x + 1):\n ans *= i\nprint(ans)", "passed": true, "time": 0.22, "memory": 14376.0, "status": "done"}, {"code": "import math\nA, B = list(map(int, input().split()))\nres = min(A, B)\nprint(math.factorial(res))\n", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}, {"code": "from math import factorial as f\na, b = map(int, input().split())\nprint(f(min(a, b)))", "passed": true, "time": 0.16, "memory": 14316.0, "status": "done"}, {"code": "import math\na,b=map(int,input().split())\nprint(math.factorial(min(a,b)))", "passed": true, "time": 0.85, "memory": 14316.0, "status": "done"}, {"code": "from math import factorial\n\na, b = list(map(int, input().split()))\n\nprint(factorial(min(a, b)))\n\n", "passed": true, "time": 0.85, "memory": 14392.0, "status": "done"}, {"code": "from math import factorial\n\na, b = map(int, input().split())\nprint(factorial(min(a, b)))", "passed": true, "time": 0.15, "memory": 14200.0, "status": "done"}, {"code": "import math\na, b = map(int, input().split())\nprint(math.factorial(min(a, b)))", "passed": true, "time": 0.27, "memory": 14296.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()\nfrom math import factorial \na,b = map_input()\nprint(factorial(min(a,b)))", "passed": true, "time": 0.15, "memory": 14292.0, "status": "done"}, {"code": "a, b = map(int, input().split())\n\nx = min(a, b)\n\nans = 1\n\nfor i in range(x):\n\tans *= (i+1)\n\nprint(ans)", "passed": true, "time": 0.26, "memory": 14368.0, "status": "done"}, {"code": "import math\n\na, b = list(map(int, input().split()))\nprint(math.factorial(min(a, b)))\n", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "import math\nimport itertools\n\n\ndef ria():\n return [int(i) for i in input().split()]\n\nprint(math.factorial(min(ria())))", "passed": true, "time": 0.19, "memory": 14424.0, "status": "done"}, {"code": "from math import factorial\na, b = map(int, input().split())\nprint(factorial(min(a, b)))", "passed": true, "time": 0.18, "memory": 14344.0, "status": "done"}, {"code": "from math import factorial as f\n\nprint(f(min(list(map(int, input().split())))))\n", "passed": true, "time": 0.15, "memory": 14384.0, "status": "done"}, {"code": "from math import factorial \na, b = list(map(int, input().split()))\nprint(factorial(min(a,b))) \n", "passed": true, "time": 0.15, "memory": 14452.0, "status": "done"}, {"code": "import math\n\nprint(math.factorial(min(map(int, input().split()))))", "passed": true, "time": 0.2, "memory": 14428.0, "status": "done"}, {"code": "import math\nstring = input()\nnumbers = string.split(\" \")\na = int(numbers[0])\nb = int(numbers[1])\nprint(math.factorial(min([a, b])))", "passed": true, "time": 0.15, "memory": 14212.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\nc = min(a, b)\n\ndef fact(n):\n\tres = 1\n\tfor i in range(1, n + 1):\n\t\tres *= i\n\treturn res\n\nprint(fact(c))", "passed": true, "time": 0.14, "memory": 14228.0, "status": "done"}, {"code": "import math\na,b = list(map(int, input().split()))\nprint(math.factorial(min(a,b)))\n", "passed": true, "time": 0.14, "memory": 14232.0, "status": "done"}, {"code": "from math import factorial\na, b = list(map(int, input().split()))\nprint(factorial(min(a,b)))\n", "passed": true, "time": 0.14, "memory": 14356.0, "status": "done"}, {"code": "a = list(map(int, input().split()))\n\nimport math\nprint(math.factorial(min(a)))\n", "passed": true, "time": 0.2, "memory": 14452.0, "status": "done"}, {"code": "from math import factorial\n\na, b = map(int, input().split())\nprint(factorial(min(a, b)))", "passed": true, "time": 0.14, "memory": 14224.0, "status": "done"}, {"code": "from math import factorial\n\nA, B = input().split()\nA, B = int(A), int(B)\nprint(factorial(min(A, B)))\n", "passed": true, "time": 0.23, "memory": 14280.0, "status": "done"}]
[{"input": "4 3\n", "output": "6\n"}, {"input": "10 399603090\n", "output": "3628800\n"}, {"input": "6 973151934\n", "output": "720\n"}, {"input": "2 841668075\n", "output": "2\n"}, {"input": "7 415216919\n", "output": "5040\n"}, {"input": "3 283733059\n", "output": "6\n"}, {"input": "11 562314608\n", "output": "39916800\n"}, {"input": "3 990639260\n", "output": "6\n"}, {"input": "11 859155400\n", "output": "39916800\n"}, {"input": "1 1\n", "output": "1\n"}, {"input": "5 3\n", "output": "6\n"}, {"input": "1 4\n", "output": "1\n"}, {"input": "5 4\n", "output": "24\n"}, {"input": "1 12\n", "output": "1\n"}, {"input": "9 7\n", "output": "5040\n"}, {"input": "2 3\n", "output": "2\n"}, {"input": "6 11\n", "output": "720\n"}, {"input": "6 7\n", "output": "720\n"}, {"input": "11 11\n", "output": "39916800\n"}, {"input": "4 999832660\n", "output": "24\n"}, {"input": "7 999228288\n", "output": "5040\n"}, {"input": "11 999257105\n", "output": "39916800\n"}, {"input": "11 999286606\n", "output": "39916800\n"}, {"input": "3 999279109\n", "output": "6\n"}, {"input": "999632727 11\n", "output": "39916800\n"}, {"input": "999625230 7\n", "output": "5040\n"}, {"input": "999617047 3\n", "output": "6\n"}, {"input": "999646548 7\n", "output": "5040\n"}, {"input": "999639051 3\n", "output": "6\n"}, {"input": "12 12\n", "output": "479001600\n"}, {"input": "12 1\n", "output": "1\n"}, {"input": "1213 5\n", "output": "120\n"}, {"input": "8 9\n", "output": "40320\n"}, {"input": "12 9\n", "output": "362880\n"}, {"input": "12 1000000000\n", "output": "479001600\n"}, {"input": "1000000000 1\n", "output": "1\n"}, {"input": "12 13\n", "output": "479001600\n"}, {"input": "2 29845\n", "output": "2\n"}, {"input": "10 21\n", "output": "3628800\n"}, {"input": "12 20\n", "output": "479001600\n"}, {"input": "15 12\n", "output": "479001600\n"}, {"input": "1 1\n", "output": "1\n"}, {"input": "1000000000 12\n", "output": "479001600\n"}, {"input": "11 30\n", "output": "39916800\n"}, {"input": "17 12\n", "output": "479001600\n"}, {"input": "4 19\n", "output": "24\n"}, {"input": "12 15\n", "output": "479001600\n"}, {"input": "20 6\n", "output": "720\n"}, {"input": "10 20\n", "output": "3628800\n"}, {"input": "10 10\n", "output": "3628800\n"}, {"input": "22 12\n", "output": "479001600\n"}, {"input": "20 12\n", "output": "479001600\n"}, {"input": "12 23\n", "output": "479001600\n"}, {"input": "12 22\n", "output": "479001600\n"}, {"input": "18 3\n", "output": "6\n"}, {"input": "14 10\n", "output": "3628800\n"}, {"input": "14 12\n", "output": "479001600\n"}, {"input": "8 3\n", "output": "6\n"}, {"input": "5 5\n", "output": "120\n"}]
324
Let's call a positive integer composite if it has at least one divisor other than $1$ and itself. For example: the following numbers are composite: $1024$, $4$, $6$, $9$; the following numbers are not composite: $13$, $1$, $2$, $3$, $37$. You are given a positive integer $n$. Find two composite integers $a,b$ such that $a-b=n$. It can be proven that solution always exists. -----Input----- The input contains one integer $n$ ($1 \leq n \leq 10^7$): the given integer. -----Output----- Print two composite integers $a,b$ ($2 \leq a, b \leq 10^9, a-b=n$). It can be proven, that solution always exists. If there are several possible solutions, you can print any. -----Examples----- Input 1 Output 9 8 Input 512 Output 4608 4096
interview
[{"code": "n = int(input())\nprint (9 * n, 8 * n)", "passed": true, "time": 0.24, "memory": 14416.0, "status": "done"}, {"code": "n = int(input())\nprint(n*9,n*8)", "passed": true, "time": 0.24, "memory": 14460.0, "status": "done"}, {"code": "# for i in range(int(input())):\na = int(input())\nprint(9*a,8*a)", "passed": true, "time": 0.24, "memory": 14260.0, "status": "done"}, {"code": "n = int(input())\nprint(9*n,8*n)\n", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "n=int(input())\nprint(9*n, 8*n)", "passed": true, "time": 0.22, "memory": 14364.0, "status": "done"}, {"code": "#Bhargey Mehta (Junior)\n#DA-IICT, Gandhinagar\nimport sys, math, queue, collections\nMOD = 10**9+7\n#sys.stdin = open('input.txt', 'r')\n\nn = int(input())\nprint(9*n, 8*n)", "passed": true, "time": 0.14, "memory": 14548.0, "status": "done"}, {"code": "n = int(input())\nprint(9 * n, 8 * n)", "passed": true, "time": 0.23, "memory": 14432.0, "status": "done"}, {"code": "N = int(input())\nprint(9*N, 8*N)\n", "passed": true, "time": 0.14, "memory": 14300.0, "status": "done"}, {"code": "import sys\nimport math\ninput = sys.stdin.readline\n\nn=int(input())\n\nprint(9*n,8*n)", "passed": true, "time": 0.24, "memory": 14432.0, "status": "done"}]
[{"input": "1\n", "output": "9 8\n"}, {"input": "512\n", "output": "4608 4096\n"}, {"input": "10000000\n", "output": "90000000 80000000\n"}, {"input": "2\n", "output": "18 16\n"}, {"input": "3\n", "output": "27 24\n"}, {"input": "4\n", "output": "36 32\n"}, {"input": "8958020\n", "output": "80622180 71664160\n"}, {"input": "6\n", "output": "54 48\n"}, {"input": "7\n", "output": "63 56\n"}, {"input": "8\n", "output": "72 64\n"}, {"input": "9\n", "output": "81 72\n"}, {"input": "10\n", "output": "90 80\n"}, {"input": "11\n", "output": "99 88\n"}, {"input": "12\n", "output": "108 96\n"}, {"input": "13\n", "output": "117 104\n"}, {"input": "14\n", "output": "126 112\n"}, {"input": "15\n", "output": "135 120\n"}, {"input": "16\n", "output": "144 128\n"}, {"input": "17\n", "output": "153 136\n"}, {"input": "18\n", "output": "162 144\n"}, {"input": "19\n", "output": "171 152\n"}, {"input": "20\n", "output": "180 160\n"}, {"input": "253574\n", "output": "2282166 2028592\n"}, {"input": "3194897\n", "output": "28754073 25559176\n"}, {"input": "6767476\n", "output": "60907284 54139808\n"}, {"input": "4695418\n", "output": "42258762 37563344\n"}, {"input": "7320749\n", "output": "65886741 58565992\n"}, {"input": "7365657\n", "output": "66290913 58925256\n"}, {"input": "6415292\n", "output": "57737628 51322336\n"}, {"input": "865176\n", "output": "7786584 6921408\n"}, {"input": "5615225\n", "output": "50537025 44921800\n"}, {"input": "7609348\n", "output": "68484132 60874784\n"}, {"input": "9946581\n", "output": "89519229 79572648\n"}, {"input": "4639396\n", "output": "41754564 37115168\n"}, {"input": "7457651\n", "output": "67118859 59661208\n"}, {"input": "819893\n", "output": "7379037 6559144\n"}, {"input": "3588154\n", "output": "32293386 28705232\n"}, {"input": "543812\n", "output": "4894308 4350496\n"}, {"input": "3762219\n", "output": "33859971 30097752\n"}, {"input": "5\n", "output": "45 40\n"}, {"input": "100\n", "output": "900 800\n"}, {"input": "267\n", "output": "2403 2136\n"}, {"input": "13\n", "output": "117 104\n"}, {"input": "7\n", "output": "63 56\n"}, {"input": "9\n", "output": "81 72\n"}, {"input": "63\n", "output": "567 504\n"}, {"input": "17\n", "output": "153 136\n"}, {"input": "21\n", "output": "189 168\n"}, {"input": "11\n", "output": "99 88\n"}, {"input": "999995\n", "output": "8999955 7999960\n"}, {"input": "29\n", "output": "261 232\n"}, {"input": "37\n", "output": "333 296\n"}, {"input": "9999999\n", "output": "89999991 79999992\n"}, {"input": "9999991\n", "output": "89999919 79999928\n"}, {"input": "602663\n", "output": "5423967 4821304\n"}, {"input": "5\n", "output": "45 40\n"}, {"input": "19\n", "output": "171 152\n"}, {"input": "9999889\n", "output": "89999001 79999112\n"}, {"input": "107\n", "output": "963 856\n"}]
326
We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some order of his choice. The cost of using the string S_i once is C_i, and the cost of using it multiple times is C_i multiplied by that number of times. Find the minimum total cost needed to choose strings so that Takahashi can make a palindrome. If there is no choice of strings in which he can make a palindrome, print -1. -----Constraints----- - 1 \leq N \leq 50 - 1 \leq |S_i| \leq 20 - S_i consists of lowercase English letters. - 1 \leq C_i \leq 10^9 -----Input----- Input is given from Standard Input in the following format: N S_1 C_1 S_2 C_2 : S_N C_N -----Output----- Print the minimum total cost needed to choose strings so that Takahashi can make a palindrome, or -1 if there is no such choice. -----Sample Input----- 3 ba 3 abc 4 cbaa 5 -----Sample Output----- 7 We have ba, abc, and cbaa. For example, we can use ba once and abc once for a cost of 7, then concatenate them in the order abc, ba to make a palindrome. Also, we can use abc once and cbaa once for a cost of 9, then concatenate them in the order cbaa, abc to make a palindrome. We cannot make a palindrome for a cost less than 7, so we should print 7.
interview
[{"code": "it = lambda: list(map(int, input().strip().split()))\nINF = float('inf')\n\n\ndef solve():\n N = int(input())\n S = []\n R = []\n C = []\n for _ in range(N):\n s, c = input().strip().split()\n S.append(s)\n R.append(s[::-1])\n C.append(int(c))\n \n vis = set()\n mem = dict()\n\n def dp(s, p):\n if (s, p) in mem: return mem[s, p]\n if s == s[::-1]: return 0\n if (s, p) in vis: return INF\n\n ans = INF\n vis.add((s, p))\n for i, t in enumerate(S if p else R):\n if len(t) >= len(s) and t.startswith(s):\n ans = min(ans, dp(t[len(s):], p ^ 1) + C[i])\n elif len(s) > len(t) and s.startswith(t):\n ans = min(ans, dp(s[len(t):], p) + C[i])\n vis.discard((s, p))\n mem[s, p] = ans\n return ans\n \n ans = INF\n for i in range(N):\n ans = min(ans, dp(S[i], 0) + C[i])\n return -1 if ans == INF else ans\n\n\ndef __starting_point():\n ans = solve()\n print(ans)\n__starting_point()", "passed": true, "time": 0.18, "memory": 14436.0, "status": "done"}, {"code": "import sys\nsys.setrecursionlimit(10**9)\n\nINF = 10**12\nLIM = 20\nN = int(input())\nD = dict()\nfor _ in range(N):\n s, c = input().split()\n if s in list(D.keys()):\n D[s] = min(D[s], int(c))\n else:\n D[s] = int(c)\n\ndef check_kaibun(s):\n n = len(s)\n return all(s[i] == s[-i-1] for i in range(n//2))\n\ndef calc_cost(use):\n return sum(D[s] * n for (s, n) in list(use.items()))\n\ndef find_candidate(cost, use, s, is_left):\n if check_kaibun(s):\n return min(cost, calc_cost(use))\n\n if is_left:\n for t in list(D.keys()):\n # reversed s is included in the end of t\n if t[::-1].find(s) == 0:\n use[t] += 1\n if use[t] > LIM:\n return INF\n c = find_candidate(cost, use, t[:-len(s):], False)\n cost = min(cost, c)\n use[t] -= 1\n # reveresed t is included in the begin of s\n elif s.find(t[::-1]) == 0:\n use[t] += 1\n c = find_candidate(cost, use, s[len(t):], True)\n cost = min(cost, c)\n use[t] -= 1\n else:\n for t in list(D.keys()):\n # t is included in the end of reversed s\n if s[::-1].find(t) == 0:\n use[t] += 1\n c = find_candidate(cost, use, s[:-len(t):], False)\n cost = min(cost, c)\n use[t] -= 1\n # s is included in the begin of reveresed t\n elif t.find(s[::-1]) == 0:\n use[t] += 1\n c = find_candidate(cost, use, t[len(s):], True)\n cost = min(cost, c)\n use[t] -= 1\n\n return min(cost, INF)\n\ndef solve():\n ans = INF\n for s in list(D.keys()):\n use = {s: 0 for s in list(D.keys())}\n use[s] = 1\n ans = find_candidate(ans, use, s, True)\n return ans if ans < INF else -1\n\ndef __starting_point():\n print((solve()))\n\n__starting_point()", "passed": true, "time": 0.92, "memory": 14664.0, "status": "done"}, {"code": "from heapq import heapify, heappop, heappush\n\n\ndef rolling(s):\n \"\"\"\n \u6587\u5b57\u5217 [i, j] \u306e\u30cf\u30c3\u30b7\u30e5\n j < i \u306e\u5834\u5408\u306f\u9006\u9806\n \"\"\"\n n = len(s)\n ret = [[0] * n for _ in range(n)]\n\n for i in range(n):\n rh = 0\n for j in range(i, n):\n b = ord(s[j]) - 96\n rh = rh * 27 + b\n ret[i][j] = rh\n\n for j in range(n):\n rh = 0\n for i in range(j, -1, -1):\n b = ord(s[i]) - 96\n rh = rh * 27 + b\n ret[j][i] = rh\n\n return ret\n\n\ndef solve(n, sss, ccc, rhs):\n INF = 10 ** 18\n ans = INF\n q = []\n for i in range(n):\n s = sss[i]\n c = ccc[i]\n l = len(s)\n\n q.append((c, 0, i, 0))\n q.append((c, 1, i, l - 1))\n\n for j in range(l):\n k = 1\n while j - k >= 0 and j + k < l:\n if s[j - k] != s[j + k]:\n break\n k += 1\n else:\n if j - k == -1 and j + k == l:\n ans = min(ans, c)\n elif j - k == -1:\n q.append((c, 0, i, j + k))\n else:\n q.append((c, 1, i, j - k))\n\n for j in range(l - 1):\n k = 0\n while j - k >= 0 and j + k + 1 < l:\n if s[j - k] != s[j + k + 1]:\n break\n k += 1\n else:\n if j - k == -1 and j + k + 1 == l:\n ans = min(ans, c)\n elif j - k == -1:\n q.append((c, 0, i, j + k + 1))\n else:\n q.append((c, 1, i, j - k))\n\n heapify(q)\n\n checked = []\n for s in sss:\n checked.append([[False, False] for _ in range(len(s))])\n\n while q:\n cost, fb, i, j = heappop(q)\n if cost >= ans:\n break\n if checked[i][j][fb]:\n continue\n s = sss[i]\n ls = len(s)\n lm = ls - j if fb == 0 else j + 1\n checked[i][j][fb] = True\n rhr = rhs[i][j]\n\n if fb == 0:\n for ti in range(n):\n t = sss[ti]\n lt = len(t)\n if lm == lt:\n if rhs[ti][-1][0] == rhr[-1]:\n ans = min(ans, cost + ccc[ti])\n elif lm > lt:\n if rhs[ti][-1][0] == rhr[j + lt - 1]:\n heappush(q, (cost + ccc[ti], 0, i, j + lt))\n else:\n if rhs[ti][-1][lt - lm] == rhr[-1]:\n heappush(q, (cost + ccc[ti], 1, ti, lt - lm - 1))\n else:\n for ti in range(n):\n t = sss[ti]\n lt = len(t)\n if lm == lt:\n if rhs[ti][0][-1] == rhr[0]:\n ans = min(ans, cost + ccc[ti])\n elif lm > lt:\n if rhs[ti][0][-1] == rhr[j - lt + 1]:\n heappush(q, (cost + ccc[ti], 1, i, j - lt))\n else:\n if rhs[ti][0][lm - 1] == rhr[0]:\n heappush(q, (cost + ccc[ti], 0, ti, lm))\n\n if ans == INF:\n return -1\n else:\n return ans\n\n\nn = int(input())\nsss = []\nccc = []\nrhs = []\nfor si in range(n):\n s, c = input().split()\n sss.append(s)\n ccc.append(int(c))\n rhs.append(rolling(s))\n\nprint((solve(n, sss, ccc, rhs)))\n", "passed": true, "time": 0.32, "memory": 14808.0, "status": "done"}, {"code": "from random import randrange\nfrom heapq import heapify, heappush, heappop\nfrom time import time\nK = 60\nrand = lambda: randrange(1 << K)\nsTime = time()\nN = int(input())\nS, IS, C = [], [], []\nfor _ in range(N):\n s, c = input().split()\n S.append(s)\n IS.append(s[::-1])\n C.append(int(c))\n\nD = {}\ndone = [set(), set()]\nr = rand()\nD[r] = (0, \"\", 0)\nH = [r]\nans = 1 << K\nwhile H:\n r = heappop(H)\n if time() - sTime > 1.7:\n break\n d, s, c = D[r]\n if s in done[d]: continue\n done[d].add(s)\n if d == 0:\n for ss, cc in zip(S, C):\n m = min(len(s), len(ss))\n if s[:m] == ss[:m]:\n if abs(len(s) - len(ss)) <= 1 or len(ss) > len(s) and ss[m:] == ss[m:][::-1]:\n ans = min(ans, c + cc)\n else:\n if len(s) < len(ss):\n r = rand() + (c + cc << K)\n D[r] = (1, ss[m:], c + cc)\n heappush(H, r)\n else:\n r = rand() + (c + cc << K)\n D[r] = (0, s[m:], c + cc)\n heappush(H, r)\n else:\n for ss, cc in zip(IS, C):\n m = min(len(s), len(ss))\n if s[:m] == ss[:m]:\n if abs(len(s) - len(ss)) <= 1 or len(ss) > len(s) and ss[m:] == ss[m:][::-1]:\n ans = min(ans, c + cc)\n else:\n if len(s) < len(ss):\n r = rand() + (c + cc << K)\n D[r] = (0, ss[m:], c + cc)\n heappush(H, r)\n else:\n r = rand() + (c + cc << K)\n D[r] = (1, s[m:], c + cc)\n heappush(H, r)\n\nprint(ans if ans < 1 << K - 2 else -1)", "passed": true, "time": 0.41, "memory": 14720.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\nN=int(input())\nST=[input().split() for i in range(N)]\n\nfor i in range(N):\n ST[i][1]=int(ST[i][1])\n\nST.sort()\n\nST2=[]\nfor i in range(N):\n if i>0 and ST[i][0]==ST[i-1][0]:\n continue\n ST2.append((ST[i][0],ST[i][1]))\nST=ST2\n\n\nFDICT=dict()\nBDICT=dict()\n\nfor s,i in ST:\n FDICT[s[::-1]]=i\n BDICT[s[::-1]]=i\n\n for j in range(1,len(s)):\n if not(s[:j][::-1] in BDICT):\n BDICT[s[:j][::-1]]=1<<60\n if not(s[-j:][::-1] in FDICT):\n FDICT[s[-j:][::-1]]=1<<60\n\nANS=1<<60\nflag=0\nfor rep in range(1<<60):\n flag=0\n for f in FDICT:\n lf=len(f)\n for s,i in ST:\n ls=len(s)\n\n if lf == ls:\n if s==f:\n ANS=min(ANS,FDICT[f]+i)\n elif ls>lf:\n if s[-lf:]==f and BDICT[s[:-lf][::-1]]>FDICT[f]+i:\n BDICT[s[:-lf][::-1]]=FDICT[f]+i\n flag=1\n else:\n if f[-ls:]==s and FDICT[f[:-ls]]>FDICT[f]+i:\n FDICT[f[:-ls]]=FDICT[f]+i\n flag=1\n \n\n for b in BDICT:\n lb=len(b)\n for s,i in ST:\n ls=len(s)\n\n if lb == ls:\n if s==b:\n ANS=min(ANS,BDICT[b]+i)\n elif ls>lb:\n if s[:lb]==b and FDICT[s[lb:][::-1]]>BDICT[b]+i:\n FDICT[s[lb:][::-1]]=BDICT[b]+i\n flag=1\n \n else:\n if b[:ls]==s and BDICT[b[ls:]]>BDICT[b]+i:\n BDICT[b[ls:]]=BDICT[b]+i\n flag=1\n if flag==0:\n break\n \n\nfor f in FDICT:\n if f==f[::-1]:\n ANS=min(ANS,FDICT[f])\n\nfor b in BDICT:\n if b==b[::-1]:\n ANS=min(ANS,BDICT[b])\n\nif ANS==1<<60:\n print((-1))\nelse:\n print(ANS)\n", "passed": true, "time": 6.96, "memory": 14764.0, "status": "done"}, {"code": "'''\n\u81ea\u5b85\u7528PC\u3067\u306e\u89e3\u7b54\n'''\nimport math\n#import numpy as np\nimport itertools\nimport queue\nimport bisect\nfrom collections import deque,defaultdict\nimport heapq as hpq\nfrom sys import stdin,setrecursionlimit\n#from scipy.sparse.csgraph import dijkstra\n#from scipy.sparse import csr_matrix\nipt = stdin.readline\nsetrecursionlimit(10**7)\nmod = 10**9+7\n# mod = 998244353\ndir = [(-1,0),(0,-1),(1,0),(0,1)]\nalp = \"abcdefghijklmnopqrstuvwxyz\"\nINF = 1<<32-1\n# INF = 10**18\n\ndef main():\n n = int(ipt())\n wrds = []\n hq = []\n usd = set()\n for i in range(n):\n s,c = input().split()\n c = int(c)\n wrds.append((s,c))\n hpq.heappush(hq,(c,s,1))\n\n while hq:\n hc,hs,hp = hpq.heappop(hq)\n usd.add((hs,hp))\n ls = len(hs)\n if hs == hs[::-1]:\n print(hc)\n return\n for si,ci in wrds:\n lsi = len(si)\n if lsi > ls:\n if hp == 1:\n wt = si[::-1]\n# print(wt)\n if hs == wt[:ls:] and not (wt[ls::],-1) in usd:\n hpq.heappush(hq,(hc+ci,wt[ls::],-1))\n else:\n if hs == si[:ls:] and not (si[ls::],1) in usd:\n hpq.heappush(hq,(hc+ci,si[ls::],1))\n else:\n if hp == 1:\n wt = si[::-1]\n if wt == hs[:lsi:] and not (hs[lsi::],1) in usd:\n hpq.heappush(hq,(hc+ci,hs[lsi::],1))\n else:\n if si == hs[:lsi:] and not (hs[lsi::],-1) in usd:\n hpq.heappush(hq,(hc+ci,hs[lsi::],-1))\n# print(hq)\n\n print((-1))\n\n\n return None\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.27, "memory": 14756.0, "status": "done"}, {"code": "from collections import defaultdict\nfrom heapq import heappush, heappop, heapify\ndef main():\n N = int(input())\n SC = []\n SCrev = []\n for _ in range(N):\n s, c = input().split()\n c = int(c)\n SC.append((s, c))\n SCrev.append((s[::-1], c))\n dist = defaultdict(lambda: 10**18)\n q = [(c, s, \"\") for s, c in SC] + [(c, \"\", s) for s, c in SCrev]\n for c, l, r in q:\n dist[(l, r)] = min(dist[(l, r)], c)\n heapify(q)\n while q:\n dist_v, vl, vr = heappop(q)\n if (vl == vr == \"\") or (len(vl) and vl == vl[::-1]) or (len(vr) and vr == vr[::-1]):\n print(dist_v)\n return\n if dist[(vl, vr)] != dist_v:\n continue\n if len(vl) < len(vr):\n for s, c in SC:\n if len(s) <= len(vr):\n if vr.startswith(s):\n vr_ = vr[len(s):]\n dist_u = dist_v + c\n if dist_u < dist[(\"\", vr_)]:\n dist[(\"\", vr_)] = dist_u\n heappush(q, (dist_v+c, \"\", vr_))\n else:\n if s.startswith(vr):\n vl_ = s[len(vr):]\n dist_u = dist_v + c\n if dist_u < dist[(vl_, \"\")]:\n dist[(vl_, \"\")] = dist_u\n heappush(q, (dist_v+c, vl_, \"\"))\n else:\n for s, c in SCrev:\n if len(s) <= len(vl):\n if vl.startswith(s):\n vl_ = vl[len(s):]\n dist_u = dist_v + c\n if dist_u < dist[(vl_, \"\")]:\n dist[(vl_, \"\")] = dist_u\n heappush(q, (dist_v+c, vl_, \"\"))\n else:\n if s.startswith(vl):\n vr_ = s[len(vl):]\n dist_u = dist_v + c\n if dist_u < dist[(\"\", vr_)]:\n dist[(\"\", vr_)] = dist_u\n heappush(q, (dist_v+c, \"\", vr_))\n print((-1))\n\nmain()\n", "passed": true, "time": 0.18, "memory": 14568.0, "status": "done"}, {"code": "it = lambda: list(map(int, input().strip().split()))\nINF = float('inf')\n\n\ndef solve():\n N = int(input())\n S = []\n C = []\n for _ in range(N):\n s, c = input().strip().split()\n S.append(s)\n C.append(int(c))\n \n vis = set()\n mem = dict()\n\n def dp(s, p):\n if (s, p) in mem:\n return mem[s, p]\n\n if s == s[::-1]:\n return 0\n\n if (s, p) in vis:\n return INF\n\n vis.add((s, p))\n\n ans = INF\n if p == 0:\n for i in range(N):\n if len(S[i]) >= len(s):\n if S[i][::-1].startswith(s):\n ans = min(ans, dp(S[i][:-len(s)], 1) + C[i])\n else:\n if s.startswith(S[i][::-1]):\n ans = min(ans, dp(s[len(S[i]):], 0) + C[i])\n else:\n for i in range(N):\n if len(S[i]) >= len(s):\n if S[i].startswith(s[::-1]):\n ans = min(ans, dp(S[i][len(s):], 0) + C[i])\n else:\n if s[::-1].startswith(S[i]):\n ans = min(ans, dp(s[:-len(S[i])], 1) + C[i])\n\n vis.discard((s, p))\n mem[s, p] = ans\n return ans\n \n ans = INF\n for i in range(N):\n ans = min(ans, dp(S[i], 0) + C[i])\n return -1 if ans == INF else ans\n\n\ndef __starting_point():\n ans = solve()\n print(ans)\n__starting_point()", "passed": true, "time": 0.19, "memory": 14512.0, "status": "done"}]
[{"input": "3\nba 3\nabc 4\ncbaa 5\n", "output": "7\n"}, {"input": "2\nabcab 5\ncba 3\n", "output": "11\n"}, {"input": "4\nab 5\ncba 3\na 12\nab 10\n", "output": "8\n"}, {"input": "2\nabc 1\nab 2\n", "output": "-1\n"}, {"input": "8\ncbdd 389885279\nadcdcc 847639832\nbcbbbbc 990046360\ndcbbaca 99970369\ncbbacdc 260253457\ndddbdc 155820514\nbdcab 529609633\nbcbbd 61329925\n", "output": "-1\n"}, {"input": "10\nacabaa 78261382\ncacaa 497417225\nabbccac 220123483\naccbba 66259481\nccccb 101617835\nbcbccc 471600823\naccaaba 654501441\naaaba 381616727\nbababcc 4778556\nccab 546319595\n", "output": "286382964\n"}, {"input": "40\naaaaaaa 750307776\nbbabaa 564650293\nbbbaba 485878855\nabba 555740559\naaabb 206644901\nbbbb 446161746\nbabaabb 675034465\nbbaba 114764085\nabaaaaa 999033929\nbaabb 895456035\naaba 971580525\naabaa 734327045\nabab 403922695\naaabba 33158496\nabaaa 126681136\naaababb 341368575\nbbababb 457781599\nbbabbb 547908912\nbaababa 647130405\naabbbaa 673721435\nabbba 200827311\naaba 193295984\nbababaa 576330191\naaaaab 884634918\naaaabb 156860089\nabaabb 388755611\naababab 52951985\naaaabb 718839712\nbbaa 737653214\naaab 129910973\nbbaaa 592478498\nbabbba 872170642\naabb 8107993\naabaaa 846276479\nbaab 774815328\nabbbb 111176706\naabb 824151486\nbababb 233250652\naababaa 645422120\nbbbaaa 146953450\n", "output": "200827311\n"}, {"input": "39\nbbbbbab 865330150\nabbaaa 301581888\nbbbbba 717667895\nbbbaaaa 889421777\nababbb 184681714\nbaabba 388305215\naabb 612079236\nabbabab 246916038\naaaba 454253365\nbbbb 662188866\naaaab 703471918\nbbbbaa 141896900\nbbab 968420866\nbbaba 485444834\nbaba 80833253\nbbaaa 378263794\nbaab 158749071\nabaaaab 392188344\naaab 26134204\naaaaaa 362019843\nbabab 606674314\nabbbaa 863208610\nbbaabba 820554905\naaaaa 392046985\nbbbaab 969112832\naaaa 455550833\nbaaabaa 311269911\naabaa 170770576\naaabb 278420058\nbaab 616267097\nabbba 232761944\naaab 84703285\nbaaa 190163302\naabb 636391052\nabba 594134984\nababab 75956532\naabbabb 460091986\nabba 823485979\nabaaa 632728443\n", "output": "158749071\n"}, {"input": "37\naddhf 831775166\niiicae 92024309\ngfbbb 114765630\nieefcgg 170603032\nfgebicg 371108840\niiiib 51291357\nedibhb 395483367\nafiabfg 667989356\ngbhecbd 974512932\nfhgd 491264692\nfeiahfg 977089951\nfdgbad 754637896\nagdd 242308570\nbhggaeb 221847775\nfgdgga 863097312\nedhbgc 240695380\nbbiii 462710096\nbdfbecf 7342774\niffbac 492895669\nafbe 117748235\ngaafbfg 602057676\ngbhb 697771623\nhabaed 788612043\niabcdd 706472877\ngdai 204970501\nfhgfic 799582824\ndcee 520307806\ngefcdbg 214793718\ndgda 163190893\ndbibf 981113447\ncgegegf 134711654\nhgfagbi 384106977\neche 917006770\nbdbhia 298162447\nacfi 705456455\nhihii 568830755\ngbidagf 251026528\n", "output": "-1\n"}, {"input": "2\nbabje 11705187\njjdjc 229793824\n", "output": "-1\n"}, {"input": "46\ndacfa 393680647\nacebhc 497863616\nbefaabg 918927682\naaab 463467742\ndgedc 162538145\nebfd 635533015\nabcfed 695991\ndfhgh 483174784\ndhdfc 714740947\naege 342738917\ngdgad 429774089\nfbbfcc 348905899\nbgfhbaf 619955397\ndgch 389079126\neadedgc 450830925\nfhbd 844372647\nfghefeb 466799655\nfhddgb 912593167\ngaad 961546569\ngecdegh 679859525\ngbfdgh 141115941\nchegecd 545182597\ndfageh 577178879\ndhdcagh 973046076\ngafe 788597706\nddaeac 355777758\ncggc 527526564\nbfcd 52919313\neegceg 604211902\nfgde 436854919\ncbgdhhg 53402637\nhhge 569465447\neghcg 205918012\ndbdg 650498294\nheefg 199830425\ncgcadh 378633824\nagccf 629080284\naffhc 618377394\nabdbdc 326040239\nbedc 622042727\ncgbc 327875565\ncgcbb 535927702\necdh 672371298\nacacf 625765645\ngafe 119728156\nbbbff 982101310\n", "output": "527526564\n"}, {"input": "3\nbbaabaa 442895494\nbabaaa 835654004\naabab 388423218\n", "output": "1224077222\n"}, {"input": "3\nfbfe 770800880\nbaabe 480217039\nbbbdbda 939556995\n", "output": "-1\n"}, {"input": "8\ncaaabc 448273289\ncbae 661420585\ncceade 143442970\ncdbaea 704393688\nbddbae 251892810\nebcd 667260064\naadae 523428159\ndbdbb 570139035\n", "output": "-1\n"}, {"input": "23\necfcd 292831994\nbdhb 357014814\ngfda 426256277\nafhcaa 661613652\negfhee 337608034\nabhb 349330223\nhahbhfb 386013063\nfbdbhaf 977633248\nddefdbd 34391884\ndfbhhhd 579479731\nbfhdh 380892808\nbhafehf 978122877\nbgbeaeb 131674582\nhhaee 94438393\nfcgac 259271270\nhbaafga 563196881\nebgh 229982702\ngffehdb 469710230\nfhdc 102266101\ndbbb 28378310\nfcbbfab 402167009\ndgaffga 451861000\nbfeg 108812736\n", "output": "-1\n"}, {"input": "10\ncbdfa 958776888\nabfbc 22213682\ncebadd 706289505\ncabecab 206004180\nbddfac 725279470\ndfdf 318381180\ncceeae 193880456\neeace 315281474\ndeae 751585341\ncafb 687077006\n", "output": "-1\n"}, {"input": "13\nfcgbia 487701425\ngiib 190348286\ngidchfg 734019526\nghch 703785468\ndiiadh 860527530\ndaaid 927783415\ncbaf 326746891\nabhg 951018749\ngebg 847197819\negfeeh 263995636\ncgefacf 846752389\nfeeibg 518851799\nfidfc 908759387\n", "output": "-1\n"}, {"input": "32\ndbde 770711199\nbecffe 439053288\ndecd 635501393\ndbdabe 971223869\nabbcea 592877398\nfacfd 652008601\neebbef 170201633\nacdbac 627770951\nadcaddd 713035159\nccdcce 493211980\nfeaa 399198442\ndccb 640490744\nedbddeb 968749967\nabfedeb 249182670\nadcb 359578345\ndcfee 888028359\nbefbcfe 864994149\nbcecf 298272892\neabd 417957807\nddbdff 680670434\nbbcecd 275529\ncdfab 769760140\ncecb 478781543\nfdbce 445038734\nfcbbde 996517993\nfabde 735885144\ndafac 434796494\nfdcffa 533507489\nbbfea 418290303\neeced 532816571\ndebc 691143792\nfbbac 607341887\n", "output": "777054435\n"}, {"input": "2\nbbaabaa 868413188\nbabaa 554806248\n", "output": "-1\n"}, {"input": "7\ndaeeaed 964437113\neeaa 892086798\naeedb 898928185\neebbec 157982059\nbdeee 899359275\nebbd 821521378\nccabd 512173818\n", "output": "-1\n"}, {"input": "5\ndjebj 341858244\nhhfachh 188558684\naibejbg 717375370\nhgaggbc 266278532\neebecc 157519116\n", "output": "-1\n"}, {"input": "10\naccc 108924524\naabcc 539375203\ncccbcb 846849664\nbaab 749530414\nbabbb 115531976\nbcbbbc 252631614\naacab 577882052\nccbaac 898444451\nbaacbb 735493583\ncbba 112014505\n", "output": "749530414\n"}, {"input": "13\ndcfbed 450251689\ndebfac 943068372\nacccc 850985131\naffddf 683697957\nacff 86914784\nbfcbec 881882269\nebee 959370439\ndabddc 795311734\nebdad 434342255\nadebdf 472799232\nccbfed 82275951\nbddebeb 362523118\nafacfba 825535078\n", "output": "-1\n"}, {"input": "44\naacb 116936539\ncaaab 684863504\nabaabaa 125151374\naaaaa 351520441\nbbcaab 771416584\naaccccc 430145097\nbbaa 767876399\naacaacc 759388299\ncbca 612437594\nbbbaab 322001195\ncbcb 516955452\nbacccaa 852612373\ncbbab 288347349\naabacba 965220848\nbcaabb 503144019\ncaccca 525929343\nccbba 456266257\nbcab 842808047\ncbca 346244710\nbabb 594722881\nbbacac 327925993\nbcac 182339901\ncaaabab 337014363\ncabbcaa 677802434\ncbbcac 505791689\naabbbb 488926609\nbcbaabc 948316728\ncbcc 803017579\ncbbaacb 957114215\naabcb 353865146\ncbcbacc 269763944\nbaaa 623215630\naccbb 255830163\nabbabb 314284500\ncbacaca 468546563\nabbb 392192209\nacbbc 472591373\nbbacc 889504554\nbbabb 143203391\naacbab 364503475\ncbcbcac 529690286\nccbbcba 616472839\nbbaa 934306326\nacabac 587951401\n", "output": "143203391\n"}, {"input": "50\njwjrlbyywpl 813403963\nipvujubczq 23201174\nqzcbujuvpi 155768695\nqgwtefgyemxnkzqnmb 128074815\nmdpqqlxeg 963860077\ntcrwbydgbk 190895064\njjgexlqqpdm 827887158\nkbgdybwrct 629782937\nqzcbujuvpi 461880941\nqzcbujuvpi 40502023\nkbgdybwrct 423221904\ntcrwbydgbk 129487580\ngexlqqpdm 605560229\nugexlqqpdm 341986849\ntcrwbydgbk 384926099\ntcrwbydgbk 678386083\nipvujubczq 277359970\nqzcbujuvpi 990289341\nkbgdybwrct 971915052\noyenxjq 306252467\nctawhmahmhipfloccj 782555852\nsomntfmcuh 363816729\nkbgdybwrct 321641280\niiathdimmzsmchop 178904311\nipvujubczq 452005600\nloktoshqtmvunfk 125008716\narpqrfgshzndtp 290431684\naksfdzfmf 218533617\nujapdwjmhaoxilgwnflg 880640712\nekdcgtdieyashhhyep 710891751\naniinejx 524023676\nzlpqkvvhrki 673608855\nkbgdybwrct 761532452\nbas 834261562\npxlpwv 177385157\ntcrwbydgbk 407997976\nwhuxunqgmayaq 73101516\nxzpubyzsayzmuucsrh 562882881\nushcwajounqmbgussrk 458046082\nkkfmfzdfska 920338806\neilczlxxkffsraeloqds 149998202\ngmd 490363073\negmbbbuk 555762691\nmdpqqlxeg 119114212\ncdharkppwtxssfoi 528441036\noomdpqqlxeg 190857221\niqhqzunkquuqknuzqhqi 999999996\nnrjexoaivaviaoxejrn 999999994\ndnfqpvkqfrfqkvpqfnd 999999999\nkjeoznhfbtbfhnzoejk 999999995\n", "output": "63703197\n"}, {"input": "50\ncpnorotapgnzsnhskz 98497738\nhihnhhcerj 387078895\njrechhnhih 367943825\niqqpbvorrkwzeanc 272721870\nyduznplq 478627093\njdta 656546772\nvarcaxbhjjvscevded 724162988\nxoozdwgwniba 644854739\nxspqvvvvqpsxatdj 639450755\njrechhnhih 330162094\njrechhnhih 181262684\nwrwioworv 663169220\nabqrohcof 173809154\nqqqlpnzudy 196296507\nyohiatsac 419999084\nmqlpnzudy 534178277\namdx 929442036\nyhcd 834515930\neqlpnzudy 607434017\nrtizutzueubaw 166919366\nyduznplqm 826470195\nnkdhdmdsqreywykh 673632207\ndchy 245306718\nztqezzyzustsredhbas 774453724\nmqlpnzudy 644600\neajvypnhzvnufwaspae 925726924\nmtuuqmcqeumdyjr 412024574\nruhzisgpxwuknft 721069890\nwnrikzplivf 62684775\njrechhnhih 247241423\nuemlduaytzwdgkxkjld 152071753\njrechhnhih 141960878\nxhuoeoia 737074310\ndqhikrhwqavynpm 420111276\nqleoa 111590089\njxflicwbrpkyfpe 399369870\nyduznplqm 774139841\nhpncywjdqojqofatvu 142004749\nsrduvz 408155428\noofochorqba 187971081\nvnnvaoelq 966799716\npzzvttwdcczmcn 662822812\nttdcpvvrui 556585899\npel 666216985\nbpktxgbp 412046529\nfuwdzbakxcwxaf 422701542\nvahghbxfsmmsfxbhghav 999999990\ngknnyhuskjjksuhynnkg 999999993\nrevvhaqmyymqahvver 999999993\nvrdoomhtiooithmoodrv 999999991\n", "output": "361780235\n"}, {"input": "50\nggntxmgdic 504083562\nlivxvkosevgjpvitber 280804257\nwdzlgxzrjua 813714210\ncidgmxtngg 314988465\ncidgmxtngg 207110550\nozckrfux 96068197\nggntxmgdic 265383668\nelvbqebrnoqwfbsjokcy 206639104\ncidgmxtngg 588477365\nggntxmgdic 696474417\nacwanzyc 983235664\nsjahjvmeoeqskvt 796358980\ndibvzlzwb 216486959\nggntxmgdic 633018598\npinetbatkytditbbyx 414844515\nejjlckaxjbsmunitjoxh 3125148\nuwpvbyvoewtp 460449046\nccxufrkczo 280785640\nxufrkczo 30303156\ncidgmxtngg 416425314\ndsdcyznawca 466992834\nggntxmgdic 278500952\nccozckrfux 214066332\nzmgyqzjpzxxl 468757525\ner 521142543\nsigwimphcxibkkzzazt 34545138\nokjkkcl 415070999\nqhvcfu 330238628\noqmdampfaiw 268714512\njvjozckrfux 661730848\nxehx 914186754\nwqwpbgbpwqwre 830734031\ncxynbomo 401114892\ncidgmxtngg 223830134\ndpcojgwioecdydvy 465014971\nvesrympyrvnct 824005278\nggntxmgdic 512976965\ncidgmxtngg 594902888\nomobnyxc 977603331\nzzrmbfvnoednetfh 621950443\nfbxjyhrqtutqrhyjxbf 1000000000\nodakteuikiikiuetkado 999999999\ninvmpypcspscpypmvni 1000000000\njzegcneuvvuencgezj 999999997\nyhrxsstlrerltssxrhy 999999999\nfiqomrcluulcrmoqif 999999991\nlzhhdjphhghhpjdhhzl 999999994\naujqphpkaqakphpqjua 999999991\nnjkpsgbakkabgspkjn 999999992\nwrrtpfbdqwqdbfptrrw 999999994\n", "output": "126371353\n"}, {"input": "50\nlzypajfohju 571118072\nnwkmgzqwveoweojqlnel 211567620\nxpsbmtq 949475754\nnrbesdwjlnvyqbse 981336926\nkhokc 280399471\nggxn 301932368\nqnxgg 935548910\nlnjewuiyx 924403528\nwwggxnq 137950019\nbbxyiuwejnl 787470557\nvzw 501013883\neolkbjxlnestyrlt 132214757\ntuupypfsxzmxzwirld 247495663\nsgtanjmbwqyjhct 292550334\nttbjjbttckohk 515027507\npadhelmfivjfif 417129138\nfqgikjkn 616245218\nfcyzehjhlgelxdxolf 248464741\nggnxgg 413421615\niaozmirb 979573887\nsalleibizf 417656717\nnfrv 213566475\nogjpdggvbwqwfdm 292177132\nse 814041762\nmeufrmsnqqvrn 911958949\nihihwisiwhihies 950859881\nbjngrmrgnjbnxgg 862902066\nrdjjcwddilvlyhgnbiwv 705955794\npqpmtncki 835494433\nojezbpacshjcgl 780914987\npzriutgqteiwebrcrci 456443225\nucfllfcuggxngg 993180729\nefdwemsfubgkkkhlpzh 526112175\npmdrugand 749664529\noixnwjr 121387047\nlmxksgcwyqyk 101587688\nhsbshqnxggww 89363063\nvhpzxevlotclkaafmsdi 892535252\nbxyiuwejnl 70532475\ngybpbfvz 833343215\nxyiuwejnl 756478848\nrau 858312785\nqedlo 750302498\nxyiuwejnl 963573453\nylb 768097911\nikoodootixaa 493103923\nreqwvnjuu 61233551\nlhqgjaxxxfxxxajgqhl 999999992\nludsrjnstiitsnjrsdul 999999990\niygpgjjjujujjjgpgyi 999999998\n", "output": "227313082\n"}, {"input": "50\nh 619575247\nrivj 619575247\nzj 619575247\nnxm 619575247\nlkwg 619575247\nkeus 619575247\ntl 619575247\nk 619575247\nvirw 619575247\nbivb 619575247\nvibo 619575247\nkcux 619575247\nwtqj 619575247\nh 619575247\nnf 619575247\nidja 619575247\nron 619575247\nvx 619575247\nstbm 619575247\nsvx 619575247\np 619575247\nueka 619575247\nbtsg 619575247\nc 619575247\nfcmt 619575247\nxu 619575247\ncmt 619575247\nemqm 619575247\nkynm 619575247\nmcfg 619575247\ninb 619575247\njdid 619575247\nxnjz 619575247\nwkls 619575247\namet 619575247\nphfn 619575247\nqnor 619575247\nqmed 619575247\ntl 619575247\nqt 619575247\nnykw 619575247\nm 619575247\nk 619575247\nk 619575247\nxvso 619575247\nnikk 619575247\nhlts 619575247\nibig 619575247\ntema 619575247\nqtws 619575247\n", "output": "619575247\n"}, {"input": "50\nogxt 742648121\nz 704352074\nlglh 908329084\niwef 598914376\ndab 498363207\nkgnk 473816174\ntjt 227220492\nmqba 945128694\nxra 373997167\nrxbl 100447876\nwyj 811198584\ni 668718769\nflfe 405598242\niva 855690463\nkb 882672107\nehlg 584768184\nz 62182274\nxzqs 457233345\nd 667152838\nebk 87150031\nuxey 613112043\nkxh 220352946\nrqsk 225383575\nt 432176914\nsqrd 810116332\nng 689407348\ndab 852984838\nfkl 538759546\newiq 672420678\nqmaw 629052602\njywq 221223225\nb 747238113\nfdwa 286889298\ndefl 796030902\nlhx 552193382\ndd 75870232\nkf 152993861\nkf 705011909\nek 852052163\nfggy 365490179\nsqzx 421164561\nkj 373483425\ntxgo 769373977\nek 658800225\npgec 465175719\ndyex 200395384\nyggf 650999032\nvij 915368438\ncegp 878657688\nuzit 743476328\n", "output": "62182274\n"}, {"input": "50\nbptbvwvaysynlqhmuwuq 185845698\nc 185845698\npmxrvrwyylkaqklhbxri 185845698\nakzjmkfonofceoklwcvq 185845698\nqljqwpalxc 185845698\nbtchwvodpwstkbmcfefk 185845698\nojfotwbupqivthwiwvcc 185845698\nzxyrxgyuxeuuyvyfuafl 185845698\nzccoajbotqqoytngwlmu 185845698\npcnndkwlfik 185845698\nnagxmbqbmxganydgjcmd 185845698\nta 185845698\nkmjmuizgeqaehuddlbpy 185845698\nisfekqvxlmpwz 185845698\nblrswzzydeeatdmcjgdy 185845698\nfz 185845698\npcnndkwlfikeyobzzykj 185845698\nnzqqkixfvjfdnirxbhlk 185845698\nrqbxlpnpuobzffyacqoa 185845698\ntviqpubwtofjolfaufyv 185845698\necfonofkmjzkapmgwnvy 185845698\nkkqvlpdzbxxlkdoihobv 185845698\ndgqfcbtvddahcujgnbqc 185845698\nnagxmbqbmxganydgjcmd 185845698\njlqtguvzwpmlxvqkefsi 185845698\nqnhtrrxxzdqywaoqcayf 185845698\ntnhsnumdfreiyqvcwlko 185845698\nchaddvtbcfqgdmepmmta 185845698\nlnysyavwvbtpbsmjgtoh 185845698\nyoqqtobjaocczcswtrrk 185845698\ntaeedyzzwsrlbkrrtwsc 185845698\nwyqdzxxrrthnqjkyzzbo 185845698\nyierfdmunshntxjmxefx 185845698\nyuuexuygxryxzumlwgnt 185845698\nzzdpleuoziifivbohiod 185845698\nvugt 185845698\npmlxvqkefsi 185845698\ndsstjblwwnuzexfexmjx 185845698\nhvhmfmzqjqvswccvwiwh 185845698\nezunwwlbjtssdkfefcmb 185845698\nifiizouelpdzzaayalqe 185845698\nklxxbzdplvqkkypblddu 185845698\nfzboupnplxbqryvnwgmp 185845698\nqaklyywrvrxmpeql 185845698\nndfjvfxikqqzncxlapwq 185845698\nyekiflwkdnncpquwumhq 185845698\nktswpdovwhctbatmmpem 185845698\nheaqegziumjmkhotgjms 185845698\nwsvqjqzmfmhvhcqbngju 185845698\nqaklyywrvrxmpeqlayaa 185845698\n", "output": "185845698\n"}, {"input": "50\nstkwgukngcwjirjrslk 176449453\ntboqnrpktlzocbihphw 860297467\nhwlqdq 399032993\nlikgioexqxxerpwevug 615456025\nzzlvmxvwlpdbehrcbqb 94745102\nhjboeoaizhpdpypqvvp 142402574\nyhxnlergylobdbytbiz 250348041\nlhnhxqbfusrwizoepob 958250562\nugwktskucestslycsbj 993955472\nnqdsnuilcbmivdqcdan 160455283\nnfwylvnxgutkdmknxzx 260424284\nhttnqgnadcqdvimbcli 201538784\nawjtnkwzprniainrpzw 498478493\nvpdzqsgumnsuqylijwg 527451878\nwsbowujfxksfeikqrik 361716193\nelnxhybopeoziwrsufb 140370033\ntqgckyytadlnkvbcbts 204979288\ntboqnrpktl 249832135\noigkilkirqkiefskxfj 985504056\niwjhrdwhphibcozltkp 993577779\nhwlqdqibxofmoyaqige 383711242\nbewdqigsxjkehbvdtak 982693479\nrnqobtstbcbvknldaty 231408890\nuwobswbihswmdwbfyuh 967432454\nqxhnhlgwjilyqusnmug 525862641\njrslk 25224878\ngcgqcfrsktgvh 766781535\ngamhaaklsrjrijwcgnk 946629927\ngecfzkpmxernhmgwabt 584665603\ngqntthdbyhjljbhhsii 451962714\nunsdqnhvgtksrfcqgcg 123501565\ndrhjwiqhwzkyiuvhzut 603540275\nvxlvydguvewprexxqxe 550967958\naahmagxzxnkmdktugxn 995688370\noeobjhzibtybdbolygr 292663566\nxmvlzzjbscylstsecuk 201764615\ndnlcsjghxcknrotlogp 608665751\njsclndtuzhvuiykzwhq 845735527\nkzfceghksxedhpnkvgv 548917271\ndyvlxvtbawgmhnrexmp 519177286\nofkpzkbqbcrhebdplwv 907059989\nqdqlwhhuyfbwdmwshib 949639899\nvlywfnkatdvbhekjxsg 96537922\niqdwebvgvknphdexskh 475109651\nkntjwaegiqayomfoxbi 544526453\nsqzdpvpgoltornkcxhg 537207638\nykcgqtiishhbjljhybd 876042082\nkzpkfopvvqpypdphzia 783855448\npqvvp 159054640\nxzx 929586895\n", "output": "929586895\n"}, {"input": "50\nxkxkbxdadmrlymnhzpdb 964776970\nfxocahjfrcucddkozsuy 964776970\nxdqaekpuagisbklbybec 964776970\nvyowutrbwyqqqyvlchvr 964776970\nwjtibdpzhnmylrmdadxb 964776970\nyfvmjwesjqnahyzn 964776970\nuvbgtgszdkzicesngmpn 964776970\nmltwiydbpshxhgtgewfu 964776970\nsqhxdcadyvkjsyfwnphs 964776970\nxwbkeyhvgqcfznwybsct 964776970\nitjwnzyhanqjsewjmvfy 964776970\nvninbneorlnpgkinrjso 964776970\ngbvucawxlhkfahnhuujf 964776970\nwoyvtcsbywnzfcqgvhye 964776970\nmtmmqcyvgueckkaoumaw 964776970\nesqonamucyaulkduutej 964776970\nricxxojlkauspsvwzzdu 964776970\nninvfjuuhnhafkhlxwac 964776970\naqdxshpnwfysjkvydacd 964776970\nevivgovetxbjgutijcwr 964776970\nxcirnefohkgkhbhjmkry 964776970\nkbwxuxiqoqlnjdtdfqds 964776970\nvivejbaemjzysxjusknr 964776970\nciiqnpmgnsecizkdzsgt 964776970\nqyjuauwlkvnlbmvcwwjh 964776970\nicwzzaunoqcpnuvovobv 964776970\ntexurnksujxsyzjmeabj 964776970\nuffejetuudkluaycuman 964776970\neffujpnxljtdulllnkgd 964776970\nmmtmrwcjitugjbxtevog 964776970\nrffrfwrmcstriehkpzid 964776970\nqiicyuszokddcucrfjha 964776970\nwtlmhjwwcvmblnvklwua 964776970\nilabkpidkhqfgfirxdbr 964776970\ncsqiufwegtghxhspbdyi 964776970\nuxetzcnxclbrsfqbgycy 964776970\nvuloudzzwvspsuakljox 964776970\nhniqrvhclvyqqqywbrtu 964776970\nbaliosjrnikgpnlroenb 964776970\noluvdizpkheirtscmrwf 964776970\nkxkxwamuoakkceugvycq 964776970\nujyqetazuthkfkelqfms 964776970\nzdpdyrkmjhbhkgkhofen 964776970\ndpdzrbdxrifgfqhkdipk 964776970\nxhqsvbovovunpcqonuaz 964776970\nqinhsmfqlekfkhtuzate 964776970\noqsecebyblkbsigaupke 964776970\ncoxfsdqfdtdjnlqoqixu 964776970\nzwciycygbqfsrblcxncz 964776970\niqscdgknllludtjlxnpj 964776970\n", "output": "48238848500\n"}, {"input": "50\nseqhfusczkjczlnldasr 499795941\naffchzqdlqamfvjijyzb 341611726\nuzjwqzyuvbijgdbvvmri 964917095\ncntklsvvinszvwtibaib 485157698\nwzhlcgiowbeheaxchrya 960614290\nakfnoxqagkmenhyfuexb 45018867\nawttwohbqtjtsmaqepbn 295602361\nntehbjhcqfnxtpkcnkjw 369145395\ntncbzyjijvfmaqldqzhc 468124935\netnnbpeqamstjtqbhowt 79887943\ntwprjvglmvkzmnonabiz 620686513\nfddvrmbbjphnbgpdhoyw 395534444\nbhklhkenmypkhidxztsb 79295603\ntwarsadlnlzcjkzcsufh 955078942\nkhbtnmhtexylkhokahzp 547042734\nhqfztffrulpglykcnzcd 826685991\nkpvwyohdpgbnhpjbbmrv 780010383\nhbbvbndtcjlsasvvclec 925051945\nqesdfafsmgnerfdxrpbm 968661956\nfqhwoamwcuepownjxyqq 840886235\nakvdcznckylgplurfftz 519652578\ncelcvvsasljctdnbv 613055650\nocdayrhcxaehebwoigcl 192725530\ndcodeyrpoeeparktmwgn 240614238\nilzbkpfxvuykjwppnrso 308875715\napekafuwsvkiqqwvnlty 393654598\npwtqgmjqhjoodamzllwg 461348195\npqgrkuefdjthszxuilhh 164728017\nrsxltircltvbsjflilrc 238282009\nffabwbhonsoerxbelrav 309796332\nniretposytfkzngvscgq 469583510\njjfqqyxjnwopeucwmaow 106844567\nfjjgwllzmadoojhqjmgq 407903927\nepairmvvbdgjibvuyzqw 202103724\njzucrlilfjsbvtlcritl 87802944\nbbhqgcsvgnzkftysopte 152472612\nzlivarlebxreosnohbwb 504630413\nxsrbxeufyhnemkgaqxon 666681056\nvpkkbvjditofhzheqtca 918330602\njbjpzhakohklyxethmnt 791868129\nhzwosrnppwjkyuvxfpkb 460210380\nddfytlnvwqqikvswufak 124150113\nvkabstzxdihkpymnekhl 817054842\nhtdmbprxdfrengmsfafd 590952078\nrinactqehzhfotidjvbk 622873170\nalzwjknckptxnfqchjbh 479830652\ndthzibanonmzkvmlgvjr 678411044\nzlabiabitwvzsnivvslk 373241972\nfkahhliuxzshtjdfeukr 832322375\ngqpngwmtkrapeeopryed 77191908\n", "output": "24256003877\n"}, {"input": "49\namgahydymulrymnunce 867920354\ngwboeyvdy 151975101\nfahdtrkzf 77188502\nubnhmziidokutbjpcnh 867920354\nufzl 95127363\nyjulxhjdnamwpmystrf 867920354\npbsctytnz 298680750\ncnunmyrlumydyhagmax 867920354\nydrnfsphjx 82541395\nyhedmwuafagwboeyvdy 867920354\nyhedmwuafa 715945253\nqrdasuufzl 138920157\nnebtwhjppgqfwflnptx 867920354\nfahdtrkzfqrdasuufzl 867920354\nxj 867920354\nzwmfmmyzj 527287704\nokkhehxidf 569239605\nqvadicdjiznskwjcich 867920354\nuvfghoqfexiwsfzmmkg 867920354\nfgueyhrjklxpuhuuugy 867920354\ntqjnjglnw 785378957\nzwmfmmyzjlaxapdwhwh 867920354\nwhwdpaxaljzymmfmwzc 867920354\nfahdtrkzf 729000199\ntqjnjglnwydrnfsphjx 867920354\ndixhehkkozntytcsbpj 867920354\nhpsfnrdywnlgjnjqtc 867920354\nqrdasu 43792794\ndvyeobwgafauwmdehye 867920354\nrkzf 189218241\nbnzutvunesdfhtkfxlj 867920354\nfahdt 539781960\npbsctytnzokkhehxidf 867920354\njrhyeugfz 467490090\nguuuhupxlk 400430266\nguuuhupxlkjrhyeugfz 867920354\ntytnz 233063874\nkmmzfswixefqohgfvuz 867920354\nijdcidavql 584395225\nlxfkthfdsenuvtuznbd 867920354\nrtsympwmandjhxlujyg 867920354\ntpnlfwfqgppjhwtbend 867920354\nncpjbtukodiizmhnbuj 867920354\nzfuusadrqfzkrtdhafj 867920354\npbsc 65616874\ncicjwksnzijdcidavql 867920354\ncicjwksnz 283525131\nlaxapdwhwh 340632652\nqrdasuufzl 790731850\n", "output": "2603761060\n"}, {"input": "49\nzt 111213687\nzsvdzjzkng 284806851\nmwvwzxrprwryqewikxto 575061508\nlunenq 80081094\ncsrxzuqsxaidoiijetkk 524161372\ncdydkbrkqnenultgdqny 775984766\nxwabyjzyf 124682614\niujkbbeei 697060070\nlunenq 37989516\ngjdzxzcskktejiiodiax 313438438\nmgzwhwxxzzycxdeesqmb 234638623\nnqdgt 46527882\nprxzwvwmdpwbfesfayuf 77505597\nsquzxrscnqnpkjpnsvxt 603440322\nstfcuidxgxzoqipymlio 314187584\nxutwwtuxtxvsnpjkpnqn 159812380\npkvrpvcsyeeryyygjrjx 948682618\nktejiiodiax 163278034\neebbkjuiugvawzyquxtz 913144545\noighietpmgn 5660361\nkzjzdvszbpqmxxfzbkdn 935874806\ndyhyzyjuoilmypiqozxg 263440919\nfvlhlfdyhoeavfqofzql 434661469\nnqdgtlunenq 126608978\nmpteihgioi 43367758\nxxwhwzgmmvwgbkbdrvkk 903978934\nrolmnjmtbmqseedxcyzz 867693479\nydflhlvfxjrjgyyyreey 812521727\navfqofzql 223445343\nkrbkdydcfuyafsefbwpd 640362918\nggjxuujondkbzfxxmqpb 296003724\nnqdgt 88619460\nscvprvkpbb 297710738\niujkbbeeioighietpmgn 702720431\nxwabyjzyfqqztqyhawiz 603994949\nsczxzdjgotxkiweqyrwr 141408307\nfvlhlfdyhoe 211216126\nscvprvkpbbfyxzjgrhom 499161068\nfyxzjgrhom 201450329\nojuuxjggziwahyqtzqqf 943998641\nzsvdzjzkngmpteihgioi 328174609\ngjdzxzcsk 150160405\nxdiucftskkvrdbkbgwvm 330303384\ntmjnmlory 520642653\nyzjybawxlqzfoqfvaeoh 407896923\nujyzyhydmohrgjzxyfbb 20271001\nxuqyzwavgu 887288031\nqqztqyhawiz 479312333\ntmjnmlorynqdgtlunenq 647251629\n", "output": "2608706333\n"}, {"input": "49\ntdvovgdlyvcufpmfcev 423184589\nrenpdjxswemmkipuodv 423184589\nludcwxklmgktfqnyjvc 423184589\nqfmdznhxcotbjxfmnsh 423184589\nlwvvmulya 116762695\nwovedugkwifhdbfqocb 423184589\nyvasmxdryexaqgdqopc 423184589\nmvvwlkbwrw 311849371\nwjtvmbjzyjfaefqfsmk 423184589\nlwvvmulyalhfghiswxr 423184589\nfiywelwcrb 33401468\nbdhfiwkgudevowmsnbb 423184589\nftzsvdrbnnvpuojwimg 423184589\nntqfrhhrzcagjuziqac 423184589\nvdoup 4057705\nfeafjyzjbmvtjwrxwsi 423184589\ngqaxeyrdxmsavywczod 423184589\nmnsh 5772022\nqfmdznhxco 355650860\nerdozcw 235392057\newyifhrhhczhbhcpoqd 423184589\nxjbtocxhnzdmfqvecfm 423184589\nxjdpnerdozcw 423184589\nuevtjrehaiqirwybrzj 423184589\nhbhzchhrhfiywelwcrb 423184589\naojkgpntujyagzjbqbj 423184589\nvdoup 13488380\nwriqiaherjtveubcoqf 423184589\nhgfhlaylumvvwlkbwrw 423184589\nhbhzchhrh 389783120\nhgfhlaylu 111335218\nxjdpn 187792534\nujgaczrhhrfqtnjzrby 423184589\ntbjxf 61761704\noupvnnbrdvsztfcaqiz 423184589\nzgayjutnpgkjoakmsfq 423184589\nqftkgmlkxwcdulgmiwj 423184589\ngkjoakmsfq 377969216\npfucvyldgvovdtwrwbk 423184589\nikmmews 419126884\nzgayjutnp 45215372\ntbjxfmnsh 67533727\njoyuubcxgkgqnhbrcwl 423184589\nlhfghiswxr 306421892\nhnqgkgxcbuuyojbbnsm 423184589\nikmmews 409696210\nywaixjzgqefpjohsnmf 423184589\nvdoupikmmews 423184589\nojpfeqgzjxiawycvjyn 423184589\n", "output": "8883217716\n"}, {"input": "49\nznphsjafcpsonjcheet 960454002\nzlgzil 153964324\ngirsm 91189807\ncrvayewzjhasvalxrcl 947914396\nauixrbfmuxykmbrsxpy 913182548\nwqrobhzwst 538296890\ndiewcbqol 147669117\nnbyztpgqzt 397514918\neidhosccu 87069018\nhasvalxrcl 199529350\ngi 32792434\nfyvypxsrbmkyxumfbrx 121995045\nqzlelnpmhdipalkhgfa 92115698\ncuxmpsnyju 115028976\nhvorvvlggesbgphkuqm 256703952\novhujynspmxuchzeksc 7923721\npnzhguaew 28866256\npnzhguaewtniizlgzil 327726116\nsynlcrxlavsahjzweya 816211339\nsahjzweya 550698508\nizruzomhlxsvmbdperq 517125375\nsjfsksmdkzwzcj 873186600\nxyltzqgptzybnloqbcw 551972706\nrsm 58397374\ndiewcbqolnbyztpgqzt 545184036\nvrcqrepdbmvsxlhmozu 270663174\njczwzkdmsksfjsmsrig 637623043\nrziiafftvyukgkhneru 124665737\neidhosccu 130282060\njczwzkdms 65801513\nffpcskezhcuxmpsnyju 261156374\nnunteehcjnospcfajsh 59554878\ntniizlgzil 298859861\nvyftxxdcbqaoctrqdqg 770781833\nmuomqukhpgbsegglvvr 259416452\niuatswzhborqwuccsoh 581732083\nlzqlizglziintweaugh 901328108\npffgqdqrtcoaqbcdxxt 783154789\nlyxurenhkgkuyvtffai 229293286\nnysssgetlmftzfidsad 876277059\nffpcskezh 146127398\nwqrobhzwst 581509928\ntnii 144895539\ndasdifztfmltegss 766119297\ncrvayewzj 748385046\nksfjsmsrig 571821529\noumafghklapidhmpnle 2078689\nsynlcrxlav 265512832\neidhosccuwqrobhzwst 668578948\n", "output": "1601999449\n"}, {"input": "50\nswurlhdcrsesbhcwrjik 414286705\ntfsvnhklgfo 316439109\nzrrmrokqrresnnbugxrv 414286705\nqkormrrzofg 321397429\nftbysbfvhtfsvnhklgfo 414286705\nmhkryulsvbqnejpxsoxc 414286705\ngubnnserr 92889274\nswurlhdcrs 101745636\nnuowwfwuz 92642211\nbqnej 49154164\nlkhnvsfthvfbsybtfbhq 414286705\nkormrrzofg 229629249\nnzhrzsofm 147862478\nwflujuawmfoszrhznqhb 414286705\nnyjeasuxridsiccltdux 414286705\naicracbxjvr 186495283\nthzvklliqjs 321644493\nrwchbsesrcdhlruwsixl 414286705\nnrtlabzlfffzmtmulvsx 414286705\nillkvzhtckz 205817469\nwaujulfwxud 266424229\nbqnejpxsoxc 136154760\nfwwounsjqillkvzhtckz 414286705\ngubnnserrqkormrrzofg 414286705\nafymwmwtcnhujv 414286705\nmhkryulsv 278131943\nolpuitnaqdzjjinswvrx 414286705\nlumtmzffflzbaltrnkij 414286705\nmhkr 10541156\npwpxdlvjuhnctwmwmyfa 414286705\nthzvklliqjsnuowwfwuz 414286705\npxsoxc 87000598\nsypnnavol 131773646\nyulsv 267590788\nsxpjenqbvsluyrkhmxsv 414286705\nwsnijjzdqantiuplolxi 414286705\ngtqjlchyz 227791424\nldxpwpzkc 414286705\ntlccisdirxusaejynjrb 414286705\nfwwounsjq 208469236\nesbhcwrjik 312541071\nxbcarciazyhcljqtgbrj 414286705\nespwzmrplovannpyszuw 414286705\nsypnnavolprmzwpservj 414286705\nftbysbfvh 97847594\ngtqjlchyzaicracbxjvr 414286705\ngubnnserrq 184657458\nnzhrzsofmwaujulfwxud 414286705\nprmzwpservj 282513058\nfpgpcvlololvcpgpfcxo 414286705\n", "output": "10771454322\n"}, {"input": "49\ncpcfwfmvw 965844469\naabtflzxfksyhdlxxlpj 767790595\nnedeasayh 41289155\ngpvvgahobccbohagvvpg 804476816\nyanmmqowohryxduocfhk 336716695\ngvreaxfoaakldhgrkjrt 195304703\nksyhdlxxlpj 437934942\ncjwbliktnvjyhzpwvhxu 572998609\nibozvqdhqet 178644755\nwamjhf 5509526\naogxe 21396571\nhfknuvkwi 109087791\nixrwrfbwdomxmsvjdyzf 911767574\naabtflzxf 329855652\nkdnkoltxnhskrlngznaz 758879441\naogxevqufxunedeasayh 69204980\nyocic 440890\nxshftooxgteqhdqvzobi 625806560\nnlvmiabdrfdlielrwhyx 810186015\nxyhwrleildfrdbaimvln 314059942\nyylelb 86402216\nfzydjvsmxmodwbfrwrxi 865928565\nzanzgnlrkshnxtlokndk 908465090\njrdbpkpolapkzziojwnf 623208416\nhaotu 780231676\njplxxldhyskfxzlftbaa 112492315\nhyasaedenuxfuqvexgoa 970681217\nfnwjoizzkpalopkpbdrj 760449821\ntrjkrghdlkaaofxaervg 222342167\nvqufxu 6519255\ntfhsx 44006081\nibozvqdhqetgxootfhsx 270204066\naogxevqufxu 27915827\nkhfcoudxyrhowoqmmnay 134592292\nybxbonbrhptuglhxkbiu 374556773\nteakmdekpswyotyzkbxg 689143762\ngxoo 47553229\nhfknuvkwihaotuyylelb 975721686\ngpvvgahob 560772038\ncpcfwfmvwyocicwamjhf 971794889\ngxbkzytoywspkedmkaet 51512543\nuibkxhlgutphrbnobxby 802425222\nccbohagvvpg 243704777\nhaotuyylelb 866633894\ngxootfhsx 91559310\nblelyyutoahiwkvunkfh 294434348\nfhjmawcicoywvmfwfcpc 141037332\nyocicwamjhf 5950418\nuxhvwpzhyjvntkilbwjc 538648739\n", "output": "417646870\n"}, {"input": "48\nftlcmakuawccgtpsdew 573038410\nscpjsmamxdjtzqsdlhy 573038410\nfzccskdnyhldsqztjdx 573038410\nbtpjpxn 573038410\nyrveevryebdmbivkucw 573038410\nutnbatkxzgudrohxucm 573038410\nyrvee 365115128\npusodserqxcxrhkaekr 573038410\ncxqlveljtsflkmkoqka 378559761\ngvysbukrnawdhdyxuea 573038410\nlveljtsflkmkoqka 573038410\nvlvjckkopdvfmmaxolc 573038410\nglqarbuuaeuxydhdwan 573038410\nlveljts 93697849\nftlcmakua 419906864\ngwedsptgccwa 473745016\nresdosupwpggzeyfhqk 573038410\nbivkucw 39787022\nukamcltfkqhfyezg 999999999\nxutzrmeequbjcobqhbb 573038410\nflkmkoqka 479340561\nuubraqlgicuiawtggyq 573038410\nndkscczfqyggtwaiuci 548493101\nuubraqlgicuiawtggyq 494735971\nvlvdipfvpqdw 573038410\nrbuuaeuxydhdwandk 108731191\nxktabnturkeakhrxcxq 573038410\nwccgtpsdew 153131546\nndkscczfqyggtwaiuci 573038410\ngpwxktabnturkeakhrx 218895996\ndkpfbjzkgvwvkakqokm 573038410\nkvwvgkzjbfpkdkqlv 573038410\nklfstjlevlwdqpvfpid 573038410\nmamsjpcswcukvibmdbe 573038410\nrkubsyvgwedsptgccwa 573038410\ncloxammfvdpokkcj 573038410\nukamcltfkqhfyezggpw 573038410\nsfpkeiumnxpjptbvlqk 573038410\npfbjzkgvwvkakqokm 1000000000\nvlvdipfvpqdwglqa 23599967\nmuiekpfsbbhqbocjbuq 573038410\nkvwvgkzjbfpkdkqlv 675886157\nkscpjsmamxdjtzqsdlhy 906833929\nokkcjrkubsyv 210352469\nvryebdm 168136260\neemrztuxmcuxhordugz 573038410\ncloxammfvdp 461979335\nsfpkeiumnxpjptbvlq 239242892\n", "output": "1146076820\n"}, {"input": "49\nikpcbkxloomgixhgnwn 389418099\nklucdowyurzcg 587144625\nwlhuctwnwnghxigmool 389418099\nzwcnmjdtnxlypykiytb 389418099\nxmtriwfpitymm 103161817\nbglrmhmttcdtr 440034492\nervjzrhddgrkg 222343493\nimmytipzo 276528389\neexijkeono 112889709\nyrracrnglgpb 283579838\nfuxudrinninttntaedl 389418099\nmtecjgwmjmmaylnhyiv 389418099\nhkfadixddkafcmhzrwo 389418099\notjcrupgvjudxervjzrh 438170794\ncgczruyipqekxqsomtn 389418099\ngpurcjtpbccunelxtob 389418099\nnhivpoolvdukwwkudvl 389418099\npitymmizlhxa 144485522\nwgjcetmrtdcttmhmrlg 389418099\npitymmizlhxaklucdow 389418099\nwtcuhlwowrzhmcfakdd 389418099\nscobbakmdmrjqpqdebn 389418099\nimmytipzoeexijkeono 389418099\nxidafkhttasqzrtbqik 389418099\nldeatnttninn 389418099\nhkfadixddkafcmhzrw 340665404\nccunelxtob 285203810\ncbemsodamvjpl 47206051\noopvihnlpjvmadosmeb 389418099\ntjcrupgvjudx 116458214\nizlhxaklucdow 392094542\noesiawlkiqbtrzqsatt 389418099\ncntxcwzfwirtmxbpglg 389418099\nbwtcuhlwowrzhmcfakdd 412997142\ndjmncwzntmosqxkeqpi 389418099\nzwcnmjdtnxlypykiyt 365839055\nyurzcgcbemsodamvjpl 389418099\ngpurcjtpb 104214289\nnrcarrybotxlenuccbp 389418099\nxkbcpkinbedqpqjrmdm 389418099\nyrracrnglgpbxmtriwf 389418099\nddgrkgbglrmhmttcdtr 389418099\ntjcrupgvjudxervjzrh 389418099\nkabbocsbtyikypylxnt 389418099\nbgkrgddhrzjvrexdujv 389418099\nzwcxtncwodculkaxhlz 389418099\nlwaiseoonoekjixeeoz 389418099\nyurzcgcbemsodamvjpl 389418098\nirduxufviyhnlyammjm 389418099\n", "output": "2387124987\n"}, {"input": "50\nciseeemvvdctcsqbijd 564487115\nonthtgcpszpuxwyxtdks 838211745\nuckuyergjaqswtcfoaq 564487115\nfctwsqajgreyukcuekn 564487115\nmfyuurfzoctio 184621741\nflrupgjgxrpvwrqdibd 564487115\nkeaqdiqngtipgewkzxr 564487115\nbzkzubzksumc 752147082\ntxywxupzspcgthtnglv 564487115\nuyfmcmuskzbuzkzba 572474232\nzciseeemvvdctcsqbijd 502371781\nxhqnzrrcdmiemzujror 564487115\nnthtgcpszpuxwyxtdks 564487115\nmmcprcajdbwsfblavlg 564487115\nbpdzjkxdxypzawbhrea 564487115\nzsencxfhbbl 564487115\nzzlitdairkxtrqulttx 564487115\nerluqrtxkriadtilzzqa 282775367\nhbwazpyxdxkjzdpbzih 564487115\nwiupfascbwztymocfru 564487115\nnfpznjzmqlwidysgrxz 564487115\ngsydiwlqmzjnzpfnnke 564487115\nocuwbvachaq 564487115\ncxgoojsxjtniftnkigw 564487115\nbzkzubzksumcmfyuurf 564487115\nkeaqdiqngtipgewkzxr 564487115\nalbfswbdjacrpcmmhi 626602450\njuzmeimdcrrznqhxftl 564487115\nbqsctcdvvmeeesicdbi 564487115\nkuuaukmhipxtt 192205408\nayizvygmqbebolbrltf 564487115\naflrupgjgxrpvwrqdibd 725440972\ndqrwvprxgjgpurlfnce 564487115\nizciseeemvvdctcsqbij 129896147\ndkeaqdiqngtipgewkzxr 652457850\nkwegpitgnqidqaekecn 564487115\nfctwsqajgreyukcue 921031898\nuyfmcmuskzbuzkzbaer 564487115\nicdbiocuwbvachaq 1000000000\nrblobebqmgyvziyadji 564487115\nzoctiokuuaukmhipxtt 564487115\nbqsctcdvvmeees 42006090\nxsjoogxclbbhfxcnesz 564487115\npihmkuauukoitcozskd 564487115\nluqrtxkriadtilzzqao 564487115\nalbfswbdjacrpcmmhiz 564487115\nknbpdzjkxdxypzawbhre 46988474\ncavbwucowgikntfintj 564487115\nalbfswbdjacrpcmmh 911107349\ncomytzwbcsafpuiwqah 564487115\n", "output": "5088371152\n"}, {"input": "50\njgiedxuqefshqdffs 299520356\niteojbchozciphxlqej 352879488\nvurdqgxzhmuzbhazhxo 352879488\nwszoikyucewtanljxwp 352879488\nlkopwxjlnatwe 619272318\nzzjjeqlxhpiczohcbjo 352879488\nrgbpqalfosoosoflaqp 352879488\nussocvrzunzfmcmwsj 230356267\nfznuzrvcossuxpsf 352879488\nxdvxjxxmu 116337954\nyiteojbchozciphxlqej 185975370\nvdxnspizfuthahecsww 352879488\nfdqhsfequxde 352879488\ncmwsjvetizkl 187107147\nfllfjrdjpjgfvkqyazb 352879488\njgiedxuqefshqdffspx 352879488\ncgeznprlkz 285684858\nmlxbhmmxgcgeznprlkz 352879488\nussocvrzunzfm 50962210\nccgziqhuofrjbdiviya 352879488\nigjayividbjrfouhqiz 352879488\ngccjwcfgmzqaxkyutvr 352879488\npxjtvstmklskrakcnpcc 573142737\ngrobkjsitihzorzqlfp 352879488\nxlmdvkgtjxxltumxxjx 352879488\nrpnzegcgxmmhb 467689619\nwszoi 3300554\noklmbkjsyiutmdobgrs 352879488\nbcuyccpnckarkslkmts 352879488\nllfpflqzrozhitisjkb 352879488\nxdvxjxxmutlxxjtgkvd 352879488\nucbwwscehahtufzipsn 352879488\netizklrpnzegcgxmmhb 352879488\nvtjxdiicqmrzikjfnuy 352879488\nanljxwp 348436834\ncuykiovtjxdi 52555235\norgoxhzahbzumhzxgqd 352879488\nbgryunfjkizrmqciidx 352879488\nvjswmcm 352879488\ntlxxjtgkvd 236541535\nzswrvtuykxaqzmgfcwj 352879488\njtvstmklskrakcnpccy 352879488\nmlxbhmmxg 67194630\nkyucewt 1142099\nicqmrzikjfnuy 33931423\nvetizklrpnzegcgxmmhb 475402708\nruvsrgbodmtuiysjkbm 352879488\nlkopwxjlnatwecuykio 352879488\nussocvrzunzfmcmwsjv 352879488\njzzbzayqkvfgjpjdrjf 352879488\n", "output": "11292143615\n"}, {"input": "49\nbzhhavotucrgwykkovt 406506171\npdhoawqomrfkd 240387075\ntiuquhwdoqeoawnjrbe 551644489\nhzabjwgvqpwaruqibqr 551644489\ncqexvcyjyjkxattwxnr 551644489\nfdzfiobbpkdicwlgttsg 491559184\nlwcidkpbboifzwfmsej 551644489\nucqhhskxmgugxgagino 551644489\nogrnvjjtfvumpdhoawq 551644489\nrawpqvgwjbazhjesmfw 551644489\nbzhhavotucrgwykkovt 551644489\npajlwtiuquhwdoqe 618296749\ndmaxwysywxamdebrjnw 665779658\nczxtgyxkeyzjgyjvrtq 551644489\ncoyruukgpxvmprhca 175965359\nzfiobbpkdicwlgttsgk 551644489\nonigagxgugmxkshhqc 551644489\naoeqodwhuquitrnxwtt 551644489\ncoyruukgpxvmprhcafd 551644489\ntjjvnrgoxkuuve 789709224\naxkjyjycvxeqcevuukx 551644489\nomrfkdicjqapzcgpsce 551644489\nqonigagxgugmxkshhqc 825150001\nxjzyekxygtxzctvokky 468126670\nogrnvjjtfvum 655154582\nmlxhqnnnmkjxjqwaohd 551644489\nyrqvvcnbjpcvxecspgc 551644489\nuqtrvjygpmuvf 313579753\nwgrcutovahhzbwljape 551644489\ndcqexvcyjyjkxattwxnr 405159303\nuqtrvjyg 551644489\nxvcpjbncvvqryrqbiqu 551644489\njzyekxygtxzctvokky 551644489\ndmaxwysywxamdebrjnw 551644489\nkaxkjyjycvxeqcevuukx 987408923\npmuvftjjvnrgoxkuuve 551644489\npmvxpgkuuryockgsttg 551644489\nuqtrvjyg 551644489\naxkjyjycvxeqcevuuk 537091301\nicjqapzcgpsce 207747320\njxjkmnnnqhxlmdfachr 551644489\njxjkmnnnqhxlmdfach 681882434\nrmlxhqnnnmkjxjqwaoh 567891729\nzpaqjcidkfrmoepajlw 551644489\nzpaqjcidkfrmoe 890142236\nzfiobbpkdicwlgttsgk 649715497\nonigagxgugmxkshhqc 582647638\nczxtgyxkeyzjgyjvrt 278138976\noawnjrbeuqtrvjyg 146494483\n", "output": "1103288978\n"}, {"input": "49\nlxwbiscskbjtvvxllwx 455958263\ndqkytlcetqpphyiwcygz 3365521\nrztlvldjcxzha 902044335\nmbtazqsnldrso 800812102\nueczxdj 33608747\nwdybuqmfbjlkholmudq 455958263\nofmfktjsorqpsiuoobb 455958263\ndiemtcdwxlkxotjxezv 455958263\ndiemtcdwxlkxotjxez 424520569\nohfoticcqtfilanfxnb 455958263\njbkscsibwxltqsjte 118606174\ndxzceutdmiubboouisp 455958263\nyixgdsmbtazqsnldrso 455958263\nqrosjtkfmfovzexjtox 455958263\nkzukkonodomahzxcjdl 455958263\nvohfoticcqtfilanfxnb 487395957\nvltzrraeyimosrdlnsq 455958263\ndxzceutdmiub 3898963\nwdybuqmfbjlkholmu 930987823\nwohwekbpdosjubrzrrs 455958263\nfjrpnuidqwxbnxfnali 455958263\nxwqdiunprjfdlefnspp 455958263\nydxzceutdmiubboouisp 433521446\ndtgteutbesonthlcspg 455958263\npzvltzrraeyimosrdlns 1000000000\nwllxvvtyixgds 48084648\nhppqtecltykx 63019776\ndtgteutbesonth 24460548\nftqccitofhocycfzzif 455958263\nkytlcetqpphyiwcygzy 455958263\nklxwdctmeidyzgycwiy 455958263\nzatbmsdgxiyppsnfeld 455958263\nmiyearrztlvldjcxzha 455958263\nosebtuetgtduajjcggj 455958263\nmodonokkuzkqdumlohk 455958263\nlcspgxwqdiunprjf 862675878\nhppqtecltykxwllxvvt 455958263\nvmlriyqbqxifizzfcyc 455958263\nuimdt 333660504\nsodpbkewhowqgazzagq 455958263\nljbfmqubydwzpetjsqt 455958263\nboouispmiyear 5973228\njbkscsibwxltqsjtepz 455958263\ndlefnsppgpsclhtn 480738364\nqosebtuetgtduajjcggj 176943342\ngpsclhtn 455958263\nuimdtueczxdjggcjjau 455958263\nggcjjau 88689011\nixqbqyirlmvsrrzrbuj 455958263\n", "output": "1456563800\n"}, {"input": "50\nqponmlkjihgfedcba 884990630\nrqponmlkjihgfedcb 884990630\nsrqponmlkjihgfedc 884990630\ntsrqponmlkjihgfed 884990630\nutsrqponmlkjihgfe 884990630\nvutsrqponmlkjihgf 884990630\nwvutsrqponmlkjihg 884990630\nxwvutsrqponmlkjih 884990630\nyxwvutsrqponmlkji 884990630\nayxwvutsrqponmlkj 884990630\nbayxwvutsrqponmlk 884990630\ncbayxwvutsrqponml 884990630\ndcbayxwvutsrqponm 884990630\nedcbayxwvutsrqpon 884990630\nfedcbayxwvutsrqpo 884990630\ngfedcbayxwvutsrqp 884990630\nhgfedcbayxwvutsrq 884990630\nihgfedcbayxwvutsr 884990630\njihgfedcbayxwvuts 884990630\nkjihgfedcbayxwvut 884990630\nlkjihgfedcbayxwvu 884990630\nmlkjihgfedcbayxwv 884990630\nnmlkjihgfedcbayxw 884990630\nonmlkjihgfedcbayx 884990630\nponmlkjihgfedcbay 884990630\nabcdefghijklmnopqrs 884990630\nbcdefghijklmnopqrst 884990630\ncdefghijklmnopqrstu 884990630\ndefghijklmnopqrstuv 884990630\nefghijklmnopqrstuvw 884990630\nfghijklmnopqrstuvwx 884990630\nghijklmnopqrstuvwxy 884990630\nhijklmnopqrstuvwxya 884990630\nijklmnopqrstuvwxyab 884990630\njklmnopqrstuvwxyabc 884990630\nklmnopqrstuvwxyabcd 884990630\nlmnopqrstuvwxyabcde 884990630\nmnopqrstuvwxyabcdef 884990630\nnopqrstuvwxyabcdefg 884990630\nopqrstuvwxyabcdefgh 884990630\npqrstuvwxyabcdefghi 884990630\nqrstuvwxyabcdefghij 884990630\nrstuvwxyabcdefghijk 884990630\nstuvwxyabcdefghijkl 884990630\ntuvwxyabcdefghijklm 884990630\nuvwxyabcdefghijklmn 884990630\nvwxyabcdefghijklmno 884990630\nwxyabcdefghijklmnop 884990630\nxyabcdefghijklmnopq 884990630\nyabcdefghijklmnopqr 884990630\n", "output": "15044840710\n"}, {"input": "42\nonmlkjihgfedcba 269633783\nrqponmlkjihgfedcb 269633783\nsrqponmlkjihgfedc 269633783\ntsrqponmlkjihgfed 269633783\nutsrqponmlkjihgfe 269633783\nautsrqponmlkjihgf 269633783\nbautsrqponmlkjihg 269633783\ncbautsrqponmlkjih 269633783\ndcbautsrqponmlkji 269633783\nedcbautsrqponmlkj 269633783\nfedcbautsrqponmlk 269633783\ngfedcbautsrqponml 269633783\nhgfedcbautsrqponm 269633783\nihgfedcbautsrqpon 269633783\njihgfedcbautsrqpo 269633783\nkjihgfedcbautsrqp 269633783\nlkjihgfedcbautsrq 269633783\nmlkjihgfedcbautsr 269633783\nnmlkjihgfedcbauts 269633783\nonmlkjihgfedcbaut 269633783\nponmlkjihgfedcbau 269633783\nabcdefghijklmnopq 269633783\nbcdefghijklmnopqrst 269633783\ncdefghijklmnopqrstu 269633783\ndefghijklmnopqrstua 269633783\nefghijklmnopqrstuab 269633783\nfghijklmnopqrstuabc 269633783\nghijklmnopqrstuabcd 269633783\nhijklmnopqrstuabcde 269633783\nijklmnopqrstuabcdef 269633783\njklmnopqrstuabcdefg 269633783\nklmnopqrstuabcdefgh 269633783\nlmnopqrstuabcdefghi 269633783\nmnopqrstuabcdefghij 269633783\nnopqrstuabcdefghijk 269633783\nopqrstuabcdefghijkl 269633783\npqrstuabcdefghijklm 269633783\nqrstuabcdefghijklmn 269633783\nrstuabcdefghijklmno 269633783\nstuabcdefghijklmnop 269633783\ntuabcdefghijklmnopq 269633783\nuabcdefghijklmnopqr 269633783\n", "output": "4044506745\n"}, {"input": "50\nxqwxrkrciicrkrxwqx 999999991\nhruoyqjghffhgjqyourh 999999991\nwssshwziyyizwhsssw 999999992\nonlblfdfiifdflblno 999999994\nwocyvbapycypabvycow 999999990\nhjoiwtoormrootwiojh 1000000000\nhqqhabsoaaosbahqqh 999999992\nqmpjsxizggzixsjpmq 999999998\nmkkfumthwwhtmufkkm 999999999\nzehbuujcddcjuubhez 999999996\ndotjtpfxikkixfptjtod 999999991\nxnxnxnxnxnxnxnxnxnxn 42220\nimueapftzztfpaeumi 999999991\nsxeumrriuwwuirrmuexs 999999995\nftfbejctxxtcjebftf 999999993\nulkcidyjkkjydicklu 999999992\nilxluxbseesbxulxli 999999992\nhhyvilwuyyyyuwlivyhh 999999994\nztgewslhnqqnhlswegtz 1000000000\nvbdyhqyvaavyqhydbv 999999991\njbzwebeujjuebewzbj 999999992\ntdzvwizmeooemziwvzdt 999999995\nqpmrgfgpmbmpgfgrmpq 999999995\nombihhjdgxxgdjhhibmo 999999996\ndgzzkbdtnnntdbkzzgd 999999997\njmravqanffnaqvarmj 999999994\ncxemnnlrgpgrlnnmexc 999999992\njupxqraycttcyarqxpuj 999999999\nywcjyqudgkkgduqyjcwy 999999999\nglcpmpbeppebpmpclg 999999992\ntijmkqmxlmlxmqkmjit 999999992\nkmcflbkqjjqkblfcmk 999999995\nlynhlfuoqbqouflhnyl 999999992\nmwixjbuwwwwubjxiwm 999999990\nbrpusknpjkjpnksuprb 999999992\ndyggurmdlqqldmruggyd 999999999\nvpvmgnhzekezhngmvpv 999999997\ncrqmbuemccmeubmqrc 999999996\nfntozyexvhhvxeyzotnf 999999996\nlwpfrjcjzdzjcjrfpwl 999999996\nllnpexdohhodxepnll 999999996\ndvdsbmcxjaajxcmbsdvd 999999992\nlsvtklcsyhhysclktvsl 999999990\nlufepxptieeitpxpeful 999999994\nchzywulwhhwluwyzhc 999999999\nnxnxnxnxnxnxnxnx 20323\ndnvpyjvwqqwvjypvnd 999999995\nwrvnnofnffnfonnvrw 999999994\nqqbaqcocgggcocqabqq 999999991\nbkeurbpqtzztqpbruekb 999999995\n", "output": "270495\n"}, {"input": "50\nuynpsfrmppmrfspnyu 999999993\nbeklpicowowociplkeb 999999996\nqyejuabwcccwbaujeyq 999999994\nbcnffjnlvvlnjffncb 999999997\nwtqlmpkryxyrkpmlqtw 999999999\nwayuikjrrrrjkiuyaw 999999995\nzajrssutjyjtussrjaz 999999992\nbormfugkjjjjkgufmrob 999999999\nfsljvtbwiiwbtvjlsf 999999991\neuzyhoovelevoohyzue 999999990\nliakmjjzrwwrzjjmkail 999999991\ngdmxkghfkokfhgkxmdg 999999997\nfxjpjrphpphprjpjxf 999999991\nrgqhfwyvppvywfhqgr 1000000000\nkkeicubqrwrqbuciekk 999999990\ndywhmpoaxlxaopmhwyd 999999998\nsbnrurkmrrmkrurnbs 999999990\nkuptrmoussuomrtpuk 999999995\nuaiognhtyrythngoiau 999999990\ncpnkwebkttkbewknpc 999999990\nsyijajcqnnqcjajiys 1000000000\nciotlmetxkkxtemltoic 999999993\nhirthedxzzxdehtrih 999999995\nwrxztwhqgogqhwtzxrw 999999997\nhwqzlwqeddeqwlzqwh 999999999\nbyjspowcmimcwopsjyb 999999995\nbomwgjksjhhjskjgwmob 999999995\nquitvjxcneencxjvtiuq 1000000000\nrukhdiwosusowidhkur 999999993\nzsyvbtzronorztbvysz 999999992\nzprjvsqkkdkkqsvjrpz 999999995\ndwdjvbjkqtqkjbvjdwd 999999994\ncyxjdubzayazbudjxyc 999999996\nucrjvfefpjjpfefvjrcu 999999996\nscojfdjrlqqlrjdfjocs 999999992\nrqtdirqjiyijqridtqr 999999991\ngrokfefcywycfefkorg 999999994\nlgelohvychhcyvholegl 999999997\nvwrxcwfnddnfwcxrwv 999999995\nzgkaltttwwtttlakgz 999999992\nzoocpqtxoeoxtqpcooz 999999993\nwyaeahzdbzzbdzhaeayw 999999998\ncwpvtrnohllhonrtvpwc 999999997\ngwjjfpdyyyydpfjjwg 999999999\njxloprabssbarpolxj 999999999\nnffanffanffa 57958\naffnaffnaffnaffn 4761\nwodukdimkvkmidkudow 999999995\nbfhlrfbqssqbfrlhfb 999999999\nduccjdqepmpeqdjccud 999999990\n", "output": "246115\n"}, {"input": "50\nlednytwqrrqwtyndel 999999995\nlvgchwmlpeeplmwhcgvl 999999994\njqccaetfyyyfteaccqj 999999990\ndpxjhxtmqmmqmtxhjxpd 999999995\nnrrjbvtsxssxstvbjrrn 999999997\ncsrtwncpomopcnwtrsc 999999996\nmzykwcottnnttocwkyzm 999999990\nsrwbgbhhpzzphhbgbwrs 1000000000\nernnygqoyyoqgynnre 999999995\nrtbnkmudsfsdumknbtr 999999994\nvkmflywmzzmwylfmkv 999999998\nshmfqlzmyaaymzlqfmhs 999999991\nljqsoopwxaxwpoosqjl 999999990\nmqdwsdcctjjtccdswdqm 999999990\noochpnvmvkkvmvnphcoo 999999993\ntvitvitvitvitvi 19924\ndsalhfjrossorjfhlasd 1000000000\ndrzqbnetdfdtenbqzrd 999999998\nwgzesacpiipcasezgw 999999993\njdzykxodatadoxkyzdj 1000000000\ndbpftavhgyyghvatfpbd 999999991\nlckvmvvhrggrhvvmvkcl 999999994\nbhbbvfepeepefvbbhb 1000000000\nqqpfdmfltaatlfmdfpqq 999999998\nzfovfwzwsswzwfvofz 999999992\nuuuzrkeeikkieekrzuuu 999999995\nkbtgiohbprpbhoigtbk 999999994\nyhmgbaoynxnyoabgmhy 999999996\nyjoydqifmmfiqdyojy 999999997\nywymlasccsccsalmywy 999999997\nonbghubevvvebuhgbno 999999993\nvedzhlpzmbmzplhzdev 999999995\nivtivtivtivtivtivt 36145\noeewpeurrsrruepweeo 999999999\nzitcrfmkggkmfrctiz 999999993\naorkmhwcdxxdcwhmkroa 999999998\nrxtvaurjwwwjruavtxr 999999992\nbevjeunhsyshnuejveb 999999996\nrhuvttuennnneuttvuhr 999999992\nfhmztpdpqqpdptzmhf 999999996\nljpnvheiqrrqiehvnpjl 999999997\nctvthtmgsqqsgmthtvtc 999999994\nnmduutfvjffjvftuudmn 999999995\nwtpitwswppwswtiptw 999999997\ngteyjtextddtxetjyetg 999999992\nwayyotuxzzxutoyyaw 999999994\nwjtnywexwhhwxewyntjw 999999999\nprlajghkvvkhgjalrp 999999998\nxldugrmimmimrgudlx 999999996\ngagnqsxryyrxsqngag 1000000000\n", "output": "300269\n"}, {"input": "50\njqnkqseasddsaesqknqj 999999997\nunmexmyqeyeqymxemnu 999999995\ndzxuysuunnuusyuxzd 999999998\nodkselkasoosakleskdo 999999995\nvkulvkulvkulvkul 21202\ntzspqtfkscskftqpszt 999999995\nizmjtfeehzheeftjmzi 999999995\nubbcepztbrrbtzpecbbu 999999998\nxhseznsdkkdsnzeshx 999999998\nrnrlledvxsxvdellrnr 999999995\nyuhxxkxrqmmqrxkxxhuy 999999992\neklxcvszynyzsvcxlke 999999994\nqvdnjqjauuajqjndvq 999999998\ntgubrtojwbbwjotrbugt 999999990\nuqvfnpnjivijnpnfvqu 999999993\nhxpwlozssosszolwpxh 999999996\nkgsubvlcppclvbusgk 999999995\nghknsrqbvvbqrsnkhg 999999993\npnwmmvvluulvvmmwnp 999999991\necieetgqyyqgteeice 999999999\npdcgaazkurrukzaagcdp 1000000000\navbltdkcolockdtlbva 999999991\nsnxxepmhoohmpexxns 999999998\nknzmtelkqjjqkletmznk 999999997\noeghkvcvyggyvcvkhgeo 999999996\nhjyodrgraxargrdoyjh 999999994\nmmfdkptmffmtpkdfmm 999999991\nodwnaybiqssqibyanwdo 999999995\ncqjvrneudduenrvjqc 999999995\ndntgrgrhefehrgrgtnd 999999995\negxbabcvrrvcbabxge 999999991\nsloqytcfuiufctyqols 999999996\napcvdtlgttgltdvcpa 999999998\nklbrjquxjjxuqjrblk 999999993\nryzjawmfdvdfmwajzyr 999999991\neesjwumczwzcmuwjsee 999999991\nhipuzhtbrprbthzupih 999999992\nddpnesceeeecsenpdd 999999994\nfcxnehcjssjchenxcf 999999991\nzvyyjjjwbbwjjjyyvz 999999993\nalpsfnoipiipionfspla 999999999\nfdiohxvoccovxhoidf 999999992\nfqsmqpfklklkfpqmsqf 999999997\nzgclchqowrwoqhclcgz 999999999\npapneeluwwuleenpap 999999995\nzhkmtbghhhhgbtmkhz 999999997\nutexytbgzzzgbtyxetu 999999993\npmatumpsmmspmutamp 999999990\nwoptmslgvnvglsmtpow 999999998\nlukvlukvlukvlukvlukv 90618\n", "output": "468482\n"}, {"input": "50\ndxnquhbkkbbkkbhuqnxd 999999993\nqpzalbqpkyykpqblazpq 999999991\nlavwijigafagijiwval 999999995\noerkombdffdbmokreo 999999995\nlcbakfitvvtifkabcl 999999991\nnzhouhtucvvcuthuohzn 999999999\nxfxhzuhnfkkfnhuzhxfx 999999996\nkvvzruwahrhawurzvvk 999999996\nheellckdvfvdkclleeh 999999992\nwkiecaetxxteaceikw 999999995\natnaswfyrsryfwsanta 999999990\nhiljzpfwkyykwfpzjlih 999999994\nsaygejcdgfgdcjegyas 999999998\nidwauiusrqrsuiuawdi 999999996\nnyivbvuirriuvbviyn 999999991\nsxvbnxugnnguxnbvxs 999999999\nsdsdsdsdsdsdsd 65976\nfbtomyumyvymuymotbf 999999996\nmhpxqjuqaxxaqujqxphm 1000000000\nwsjnwurigwwgiruwnjsw 999999994\nhbresoezkzzkzeoserbh 999999993\nzsofvcsxkkxscvfosz 999999993\ncfsfppnebeebenppfsfc 999999994\ntycmfaxbjjbxafmcyt 999999996\nxyzdvlmaooamlvdzyx 999999992\nwkoyuqxzewwezxquyokw 999999995\npjvgkxayjttjyaxkgvjp 999999992\nrutsqbnrhthrnbqstur 999999993\nythirjwxooooxwjrihty 999999995\ngvblbuudxmmxduublbvg 999999991\nlgaikeeibzbieekiagl 999999994\nnhwblwldtetdlwlbwhn 999999996\ngdqqikqhpppphqkiqqdg 999999995\ngibgqsmocdcomsqgbig 999999995\nzidqrvzwmmmmwzvrqdiz 999999999\nuaqectrpdadprtceqau 999999992\ndsdsdsdsdsdsdsdsds 44093\nkzhzdvccccccvdzhzk 999999997\npmdqjxlyjjylxjqdmp 999999994\ntgdombviwfwivbmodgt 999999993\nivaaknmdrrdmnkaavi 999999994\npvtbnrzhwjjwhzrnbtvp 999999990\ntnuqajnwveevwnjaqunt 999999998\nykrewhzdhllhdzhwerky 999999999\njubihvljkzzkjlvhibuj 999999999\nkxsldgdctzztcdgdlsxk 999999992\nskmwlglucqculglwmks 999999993\ntpcpjbtbnnbtbjpcpt 999999992\nnrypkkdaijjiadkkpyrn 999999991\ngcdlvfapewwepafvldcg 999999990\n", "output": "902435\n"}, {"input": "50\nnwtllpbfvssvfbplltwn 1000000000\nqopozdaleueladzopoq 999999990\nookuxtddquqddtxukoo 999999994\njkzurxzpynypzxruzkj 999999998\nsbuftlroaaorltfubs 1000000000\nogjtklnuvllvunlktjgo 999999997\njpnxsgacqhhqcagsxnpj 999999997\nvmjzhmvvadavvmhzjmv 999999995\ndwynxzesaasezxnywd 999999993\nkhgydneoyxxyoendyghk 999999994\nxqnhnstqzffzqtsnhnqx 999999995\nddqzpwvhbbhvwpzqdd 999999993\nhonzoiixdodxiioznoh 999999995\ncnvttqoehheoqttvnc 999999997\nkslataiilliiatalsk 999999997\nkzxuunwiwtwiwnuuxzk 999999990\nykgmjrnyeooeynrjmgky 999999998\nrjtfqlmkyppykmlqftjr 999999994\nrdunpgabinnibagpnudr 999999997\nwgljbbodmqmdobbjlgw 999999996\nlcithheikkiehhticl 999999999\nsscrqievttveiqrcss 999999991\ncbljtnobyybontjlbc 999999995\ncebbfxqwsvswqxfbbec 999999995\nchiboradlmmldarobihc 999999992\nqlffvphvymyvhpvfflq 999999995\nnozabjzyxuuxyzjbazon 999999995\notycsisnhhnsiscyto 999999997\nxjbtevmjobbojmvetbjx 999999994\norororororororor 29803\ngiwbquecddceuqbwig 999999991\nrororororororororo 36552\ngmpqkyxifdfixykqpmg 999999993\ngjlzjedfbkbfdejzljg 999999991\nlluaffonozonoffaull 999999996\noscakxuassauxkacso 999999990\nvoenyseyzszyesyneov 999999992\neliyekmymmymkeyile 999999998\nfnupyigvqkkqvgiypunf 999999997\njbvrijnxllxnjirvbj 999999994\ntzuvmtobqtqbotmvuzt 999999992\nyuzzbiafjjfaibzzuy 999999995\ngwktktvgunugvtktkwg 999999998\nijwcocujrrjucocwji 1000000000\ncnpssgychhcygsspnc 999999991\nfpipswtsqiiqstwspipf 999999999\nxxyinvnxcffcxnvniyxx 999999999\nyxeftrjijggjijrtfexy 999999992\nsjllirkmrdrmkrilljs 999999992\ngkqazhyruuryhzaqkg 999999996\n", "output": "560643\n"}, {"input": "17\nab 1000000000\nbabababababababababa 1000000000\nabcdcdcdcdcdcdcdcdcd 90909090\ndc 90909090\nfefefefefefefefefedc 8264462\nef 8264462\nefghghghghghghghghgh 751314\nhg 751314\njijijijijijijijijihg 68301\nij 68301\nijklklklklklklklklkl 6209\nlk 6209\nnmnmnmnmnmnmnmnmnmlk 564\nmn 564\nmnopopopopopopopopop 51\npo 51\npozzz 4\n", "output": "10899999970\n"}, {"input": "17\nba 1000000000\nabababababababababab 1000000000\ndcdcdcdcdcdcdcdcdcba 90909090\ncd 90909090\ncdefefefefefefefefef 8264462\nfe 8264462\nhghghghghghghghghgfe 751314\ngh 751314\nghijijijijijijijijij 68301\nji 68301\nlklklklklklklklklkji 6209\nkl 6209\nklmnmnmnmnmnmnmnmnmn 564\nnm 564\npopopopopopopopoponm 51\nop 51\nzzzop 4\n", "output": "10899999970\n"}, {"input": "1\nx 1\n", "output": "1\n"}, {"input": "1\nxyz 1000000000\n", "output": "-1\n"}, {"input": "5\nxyz 1000000000\nyx 1000000000\nab 1\ncdab 1\ndcba 1\n", "output": "2000000000\n"}]
327
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled from 1 to n corresponding to its tastiness. No two candies have the same tastiness. The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest onesΒ β€” but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum! A xor-sum of a sequence of integers a_1, a_2, ..., a_{m} is defined as the bitwise XOR of all its elements: $a_{1} \oplus a_{2} \oplus \ldots \oplus a_{m}$, here $\oplus$ denotes the bitwise XOR operation; more about bitwise XOR can be found here. Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than k candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain. -----Input----- The sole string contains two integers n and k (1 ≀ k ≀ n ≀ 10^18). -----Output----- Output one numberΒ β€” the largest possible xor-sum. -----Examples----- Input 4 3 Output 7 Input 6 6 Output 7 -----Note----- In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7. In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
interview
[{"code": "R=lambda:list(map(int,input().split()))\nn,k=R()\nif k==1:print(n)\nelse:\n i=0\n while (1<<i)<=n:i+=1\n print((1<<i)-1)\n", "passed": true, "time": 0.16, "memory": 14484.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nif k == 1:\n print(n)\nelse:\n j = 1\n while j - 1 < n:\n j *= 2\n print(j - 1)", "passed": true, "time": 0.17, "memory": 14464.0, "status": "done"}, {"code": "from sys import stdin, stdout\n\nn,k = list(map(int, stdin.readline().rstrip().split()))\n\nif k==1:\n print(n)\nelse:\n x=1\n while 2*x<=n:\n x*=2\n print(2*x-1)\n\n", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "N, K = list(map(int, input().split()))\n\nif K == 1:\n print(N)\nelse:\n cnt = 0\n while N > 0:\n N >>= 1\n cnt += 1\n print((1<<cnt)-1)\n", "passed": true, "time": 0.14, "memory": 14316.0, "status": "done"}, {"code": "n, k = [int(v) for v in input().split()]\n\nif k == 1:\n print(n)\nelse:\n nn = n\n p = 0\n while nn:\n nn //= 2\n p += 1\n print(2**p - 1)\n", "passed": true, "time": 0.17, "memory": 14452.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\nif k == 1:\n\tprint(n)\nelse:\n\tbin_n = bin(n)[2:]\n\tmax_deg = len(bin_n)\n\tprint((1 << (max_deg)) - 1)\n", "passed": true, "time": 0.14, "memory": 14260.0, "status": "done"}, {"code": "n, k= list(map(int,input().split()))\n\nr = 0\nnn = n\nwhile nn:\n nn >>= 1\n r += 1\n\nprint((1<<r)-1 if k>1 else n)\n", "passed": true, "time": 1.84, "memory": 14240.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\nif k == 1:\n print(n)\nelse:\n print(int('1' * len(bin(n)[2:]), 2))\n", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "n,k = list(map(int, input().split(' ')))\nx = 1\nwhile x < n:\n x *= 2\n\nif x > n:\n x //= 2\n\nif k > 1:\n print(x + x - 1)\nif k == 1:\n print(n)\n", "passed": true, "time": 1.76, "memory": 14368.0, "status": "done"}, {"code": "n, k = map(int, input().split())\nif k == 1:\n print(n)\n return\nans = 1\nwhile 2**ans <= n:\n ans += 1\nans = 2**ans - 1\nprint(ans)", "passed": true, "time": 1.84, "memory": 14424.0, "status": "done"}, {"code": "def problemB():\n n, k = list(map(int, input().strip().split()))\n if k == 1:\n print(n)\n else:\n bas = 1\n while n > 0:\n n //=2\n bas *=2\n print(bas-1)\n\n\ndef __starting_point():\n problemB()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "def read():\n return list(map(int,input().split()))\nn,k=read()\nif k==1:\n print(n)\nelse:\n ans=0\n for i in range(len(bin(n)[2:])):\n ans+=2**i\n print(ans)\n \n \n", "passed": true, "time": 0.23, "memory": 14400.0, "status": "done"}, {"code": "import sys\nsys.setrecursionlimit(1000000)\nread = sys.stdin.readline\n\nN, K = map(int, read().split())\nif K == 1:\n print(N)\n return\nallOne = 1\nwhile((allOne<<1) <= N):\n allOne <<= 1\nallOne<<=1\nallOne -= 1\nprint(allOne)", "passed": true, "time": 0.28, "memory": 14344.0, "status": "done"}, {"code": "import sys\nimport itertools\nimport functools\n\ndef brute_exact(n, k):\n ar = list(range(1, n + 1))\n combinations = list(itertools.combinations(ar, k))\n if not combinations:\n return 0\n \n xor_conv = lambda ar: functools.reduce(lambda x,y : x^y, ar)\n return max([xor_conv(combination) for combination in combinations]) \n\ndef brute_atleast(n, k):\n return max([brute_exact(n, i) for i in range(1, k + 1)])\n\ndef solve(n, k):\n if k == 1:\n return n\n \n return 2**(n.bit_length()) - 1\n\ndef main():\n n, k = list(map(int, input().split()))\n print(solve(n, k))\n\t\ndef __starting_point():\n main() \n \n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "n, k = map(int, input().split())\n\nif k == 1:\n\tprint(n)\nelse:\n\tpr = 1;\n\twhile (pr <= n):\n\t\tpr *= 2\n\tprint(pr - 1)", "passed": true, "time": 0.19, "memory": 14320.0, "status": "done"}, {"code": "n,k = map(int,input().split(\" \"))\nif k == 1:\n\tprint(n)\n\nelse:\n\tnum = 1\n\twhile num <= n:\n\t\tnum <<= 1\n\n\tprint(num-1)", "passed": true, "time": 0.14, "memory": 14308.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nif k == 1:\n print(n)\nelse:\n ans = bin(n)[2:]\n ans = ans.replace(\"0\", \"1\")\n ans = int(ans, 2)\n print(ans)\n", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "n,k=map(int,input().split())\nif k==1:\n print(n)\nelse:\n bits=len(bin(n)[2:])\n print(2**bits-1)", "passed": true, "time": 0.14, "memory": 14464.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\ncnt = 0\nif k == 1:\n print(n)\n return\nwhile(n):\n n //= 2\n cnt += 1\nans = 0\nwhile(cnt):\n ans += 2 ** (cnt - 1)\n cnt -= 1\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14488.0, "status": "done"}, {"code": "n,k=[int(i)for i in input().split()]\n\nif k==1:\n\tprint(n)\nelse:\n\tans=1\n\twhile ans<=n:\n\t\tans*=2\n\tans-=1\n\tprint(ans)\n", "passed": true, "time": 0.14, "memory": 14536.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nif k == 1:\n print(n)\nelse:\n i = 0\n while 2 ** (i + 1) <= n:\n i += 1\n ans = 2 ** (i + 1) - 1\n print(ans)\n", "passed": true, "time": 0.18, "memory": 14272.0, "status": "done"}, {"code": "n, k = map(int, input().split())\n\nif k == 1:\n print(n)\nelse:\n print(int(bin(n)[2:].replace('0', '1'), 2))", "passed": true, "time": 0.14, "memory": 14508.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\n\nif k == 1:\n ans = n\nelse:\n ans = 1\n while ans <= n:\n ans *= 2\n ans -= 1\nprint(ans)\n", "passed": true, "time": 0.21, "memory": 14508.0, "status": "done"}, {"code": "x, y = [int(x) for x in input().split()] \nif y==1:\n print(x)\nelse:\n nb=x.bit_length()\n print((2**nb)-1)", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "n,k=[int(x) for x in input().split()]\nif k==1:\n print(n)\n return\na=1\ns=0\nwhile a<=n:\n s+=a\n a*=2\nprint(s)\n", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}]
[{"input": "4 3\n", "output": "7\n"}, {"input": "6 6\n", "output": "7\n"}, {"input": "2 2\n", "output": "3\n"}, {"input": "1022 10\n", "output": "1023\n"}, {"input": "415853337373441 52\n", "output": "562949953421311\n"}, {"input": "75 12\n", "output": "127\n"}, {"input": "1000000000000000000 1000000000000000000\n", "output": "1152921504606846975\n"}, {"input": "1 1\n", "output": "1\n"}, {"input": "1000000000000000000 2\n", "output": "1152921504606846975\n"}, {"input": "49194939 22\n", "output": "67108863\n"}, {"input": "228104606 17\n", "output": "268435455\n"}, {"input": "817034381 7\n", "output": "1073741823\n"}, {"input": "700976748 4\n", "output": "1073741823\n"}, {"input": "879886415 9\n", "output": "1073741823\n"}, {"input": "18007336 10353515\n", "output": "33554431\n"}, {"input": "196917003 154783328\n", "output": "268435455\n"}, {"input": "785846777 496205300\n", "output": "1073741823\n"}, {"input": "964756444 503568330\n", "output": "1073741823\n"}, {"input": "848698811 317703059\n", "output": "1073741823\n"}, {"input": "676400020444788 1\n", "output": "676400020444788\n"}, {"input": "502643198528213 1\n", "output": "502643198528213\n"}, {"input": "815936580997298686 684083143940282566\n", "output": "1152921504606846975\n"}, {"input": "816762824175382110 752185261508428780\n", "output": "1152921504606846975\n"}, {"input": "327942415253132295 222598158321260499\n", "output": "576460752303423487\n"}, {"input": "328768654136248423 284493129147496637\n", "output": "576460752303423487\n"}, {"input": "329594893019364551 25055600080496801\n", "output": "576460752303423487\n"}, {"input": "921874985256864012 297786684518764536\n", "output": "1152921504606846975\n"}, {"input": "922701224139980141 573634416190460758\n", "output": "1152921504606846975\n"}, {"input": "433880815217730325 45629641110945892\n", "output": "576460752303423487\n"}, {"input": "434707058395813749 215729375494216481\n", "output": "576460752303423487\n"}, {"input": "435533301573897173 34078453236225189\n", "output": "576460752303423487\n"}, {"input": "436359544751980597 199220719961060641\n", "output": "576460752303423487\n"}, {"input": "437185783635096725 370972992240105630\n", "output": "576460752303423487\n"}, {"input": "438012026813180149 111323110116193830\n", "output": "576460752303423487\n"}, {"input": "438838269991263573 295468957052046146\n", "output": "576460752303423487\n"}, {"input": "439664513169346997 46560240538186155\n", "output": "576460752303423487\n"}, {"input": "440490752052463125 216165966013438147\n", "output": "576460752303423487\n"}, {"input": "441316995230546549 401964286420555423\n", "output": "576460752303423487\n"}, {"input": "952496582013329437 673506882352402278\n", "output": "1152921504606846975\n"}, {"input": "1000000000000000000 1\n", "output": "1000000000000000000\n"}, {"input": "2147483647 1\n", "output": "2147483647\n"}, {"input": "2147483647 2\n", "output": "2147483647\n"}, {"input": "2147483647 31\n", "output": "2147483647\n"}, {"input": "8 2\n", "output": "15\n"}, {"input": "3 3\n", "output": "3\n"}, {"input": "4 1\n", "output": "4\n"}, {"input": "10 2\n", "output": "15\n"}, {"input": "288230376151711743 2\n", "output": "288230376151711743\n"}, {"input": "5 2\n", "output": "7\n"}, {"input": "576460752303423487 2\n", "output": "576460752303423487\n"}, {"input": "36028797018963967 123\n", "output": "36028797018963967\n"}, {"input": "1125899906842623 2\n", "output": "1125899906842623\n"}, {"input": "576460752303423489 5\n", "output": "1152921504606846975\n"}, {"input": "288230376151711743 3\n", "output": "288230376151711743\n"}, {"input": "36028797018963967 345\n", "output": "36028797018963967\n"}, {"input": "18014398509481984 30\n", "output": "36028797018963967\n"}, {"input": "8 8\n", "output": "15\n"}, {"input": "8 1\n", "output": "8\n"}]
328
There are $n$ points on the plane, $(x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)$. You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle. -----Input----- First line contains one integer $n$ ($1 \leq n \leq 10^5$). Each of the next $n$ lines contains two integers $x_i$ and $y_i$ ($1 \leq x_i,y_i \leq 10^9$). -----Output----- Print the minimum length of the shorter side of the triangle. It can be proved that it's always an integer. -----Examples----- Input 3 1 1 1 2 2 1 Output 3 Input 4 1 1 1 2 2 1 2 2 Output 4 -----Note----- Illustration for the first example: [Image] Illustration for the second example: [Image]
interview
[{"code": "import os\nimport sys\n\nn = int(sys.stdin.readline())\n\nres = 0\nfor _ in range(n):\n x, y = [int(s) for s in sys.stdin.readline().split()]\n if (x + y) > res:\n res = x + y\nsys.stdout.write(\"{0}\".format(res))\n", "passed": true, "time": 0.15, "memory": 14344.0, "status": "done"}]
[{"input": "3\n1 1\n1 2\n2 1\n", "output": "3"}, {"input": "4\n1 1\n1 2\n2 1\n2 2\n", "output": "4"}, {"input": "1\n233 666\n", "output": "899"}, {"input": "5\n7 7\n5 8\n8 5\n4 9\n9 4\n", "output": "14"}, {"input": "10\n100 34\n27 17\n17 73\n12 60\n53 25\n46 31\n61 86\n22 91\n82 91\n8 41\n", "output": "173"}, {"input": "2\n5 5\n7 2\n", "output": "10"}, {"input": "2\n5 5\n2 7\n", "output": "10"}, {"input": "2\n5 1\n3 4\n", "output": "7"}, {"input": "2\n2 3\n5 1\n", "output": "6"}, {"input": "2\n6 1\n4 4\n", "output": "8"}, {"input": "2\n30 30\n1 100\n", "output": "101"}, {"input": "2\n1 8\n5 5\n", "output": "10"}, {"input": "2\n1 10\n6 6\n", "output": "12"}, {"input": "2\n3 3\n1 6\n", "output": "7"}, {"input": "2\n1 9\n4 7\n", "output": "11"}, {"input": "2\n3 5\n1 6\n", "output": "8"}, {"input": "2\n6 7\n3 9\n", "output": "13"}, {"input": "2\n4 6\n1 8\n", "output": "10"}, {"input": "2\n1 7\n5 4\n", "output": "9"}, {"input": "3\n100 1\n1 100\n67 67\n", "output": "134"}, {"input": "2\n5 5\n8 1\n", "output": "10"}, {"input": "2\n10 10\n18 1\n", "output": "20"}, {"input": "2\n1 8\n4 6\n", "output": "10"}, {"input": "2\n1 5\n3 4\n", "output": "7"}, {"input": "2\n2 100\n52 51\n", "output": "103"}, {"input": "2\n10 1\n5 7\n", "output": "12"}, {"input": "2\n9 1\n6 6\n", "output": "12"}, {"input": "2\n190 1\n100 100\n", "output": "200"}, {"input": "2\n1 100000000\n3 99999999\n", "output": "100000002"}, {"input": "3\n1 1\n1 199\n100 101\n", "output": "201"}, {"input": "2\n20 8\n19 10\n", "output": "29"}, {"input": "2\n1 6\n3 5\n", "output": "8"}, {"input": "2\n7 1\n6 3\n", "output": "9"}, {"input": "2\n4 5\n1 7\n", "output": "9"}, {"input": "2\n501 501\n1000 1\n", "output": "1002"}, {"input": "2\n7 5\n9 1\n", "output": "12"}, {"input": "2\n4 4\n6 1\n", "output": "8"}, {"input": "2\n5 6\n9 1\n", "output": "11"}, {"input": "2\n24 7\n20 15\n", "output": "35"}, {"input": "2\n1 20\n11 11\n", "output": "22"}, {"input": "2\n20 1\n11 11\n", "output": "22"}, {"input": "2\n7 7\n1 11\n", "output": "14"}, {"input": "2\n1 10\n5 5\n", "output": "11"}, {"input": "5\n1 6\n1 9\n5 5\n6 5\n1 8\n", "output": "11"}, {"input": "2\n198 1\n100 100\n", "output": "200"}, {"input": "2\n1 11\n7 7\n", "output": "14"}, {"input": "2\n1 6\n4 4\n", "output": "8"}, {"input": "2\n100 100\n1 201\n", "output": "202"}, {"input": "2\n2 5\n1 10\n", "output": "11"}, {"input": "2\n9 1\n5 6\n", "output": "11"}, {"input": "2\n1 150\n100 100\n", "output": "200"}, {"input": "2\n8 1\n5 5\n", "output": "10"}, {"input": "2\n30 30\n1 46\n", "output": "60"}, {"input": "2\n4 3\n8 1\n", "output": "9"}, {"input": "2\n3 4\n2 6\n", "output": "8"}, {"input": "2\n4 3\n5 1\n", "output": "7"}, {"input": "2\n4 4\n1 6\n", "output": "8"}, {"input": "2\n9 9\n1 15\n", "output": "18"}]
330
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape. The pine's trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by tiny vile grasshoppers which you're at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch x can jump to branches $2 \cdot x, 3 \cdot x, \ldots, \lfloor \frac{y}{x} \rfloor \cdot x$. Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking. In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it's impossible. -----Input----- The only line contains two integers p and y (2 ≀ p ≀ y ≀ 10^9). -----Output----- Output the number of the highest suitable branch. If there are none, print -1 instead. -----Examples----- Input 3 6 Output 5 Input 3 4 Output -1 -----Note----- In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5. It immediately follows that there are no valid branches in second sample case.
interview
[{"code": "import sys, math\n\n#f = open('input_0', 'r')\nf = sys.stdin\n\nP, Y = list(map(int, f.readline().split()))\n\nis_ok = False\nfor t in range(Y, P, -1):\n is_ok = True\n for x in range(2, P+1):\n if t%x == 0:\n is_ok = False\n break\n if x*x > t:\n break\n if is_ok:\n print(t)\n break\nif not is_ok:\n print(-1)\n", "passed": true, "time": 0.24, "memory": 14564.0, "status": "done"}, {"code": "p, y = list(map(int, input().split()))\ndef f(x):\n\ti = 2\n\twhile i <= p and i * i <= y:\n\t\tif x % i == 0:\n\t\t\treturn False\n\t\ti += 1\n\treturn True\nind = False\t\t\nfor i in range(y, p, -1):\n\tif f(i):\n\t\tprint(i)\n\t\tind = True\n\t\tbreak\nif not ind:\n\tprint(-1)\n", "passed": true, "time": 0.52, "memory": 14488.0, "status": "done"}, {"code": "p, y = list(map(int, input().split()))\n\nmx = 33000\n\nv = [False]*mx\nfor x in range(2, mx):\n if not v[x]:\n for i in range(x*x, mx, x):\n v[i] = True\nprimes = [i for i, _ in enumerate(v) if not _ and i>1]\nfail = True\nfor v in range(y, p, -1):\n fail = False\n for pr in primes:\n if pr <= p and v%pr == 0:\n fail = True\n elif pr > p: break\n if not fail:\n print(v)\n break\n\nif fail:\n print(-1)\n\n\n", "passed": true, "time": 0.94, "memory": 14508.0, "status": "done"}, {"code": "import sys\n\ndef unhoppable(p, n):\n for d in range(2, n+1):\n if p % d == 0:\n return False\n if d*d > p:\n break\n return True\n\np, y = list(map(int, input().split()))\nfor b in range(y, p, -1):\n if unhoppable(b, p):\n print(b)\n return\nprint(-1)\n", "passed": true, "time": 0.41, "memory": 14544.0, "status": "done"}, {"code": "p, y = [int(x) for x in input().split()]\nres = -1\nfor i in range(y, p, -1):\n flag = True\n for a in range(2, min(p+1, int(i**0.5)+1)):\n if i % a == 0:\n flag = False\n break\n if flag:\n res = i\n break\nprint(res)\n", "passed": true, "time": 0.2, "memory": 14424.0, "status": "done"}, {"code": "p,y = map(int, input().split())\nfrom math import sqrt\nans = y\nwhile ans != 1:\n find =True\n if ans <= p:\n ans = 1\n continue\n for i in range(2, min(p+1, int(sqrt(ans))+1)):\n if ans % i == 0:\n find = False\n break\n if find:\n break\n ans -= 1\nif ans == 1:\n print(-1)\nelse:\n print(ans)", "passed": true, "time": 0.37, "memory": 14480.0, "status": "done"}, {"code": "import math\n\ndef getPrimes(v):\n\t\td = 2\n\t\tgr = int(math.sqrt(v)) + 1\n\t\tres = []\n\t\twhile d <= gr and v > 1:\n\t\t\tif v % d == 0:\n\t\t\t\tres.append(d)\n\t\t\t\twhile v % d == 0:\n\t\t\t\t\tv //= d\n\t\t\td += 1\n\t\tif v > 1:\n\t\t\tres.append(v)\n\t\treturn res\n\t\t\ndef solve(p, y):\n\tx = y\n\twhile x > p:\n\t\tpr = getPrimes(x)\n\t\tif all(v > p for v in pr):\n\t\t\treturn x\n\t\tx -= 1\n\treturn -1\n\np, y = list(map(int, input().split()))\nprint(solve(p, y))\n", "passed": true, "time": 4.93, "memory": 14500.0, "status": "done"}, {"code": "p,y = list(map(int,input().split()))\nprimes = []\nm = int(min(y**0.5,p))\nfor i in range(2,m+1):\n pri = True\n for pp in primes:\n if i//pp*pp==i: \n pri = False\n break\n if pri: primes.append(i)\n\nsol = False\nfor yy in range(y,p,-1):\n ok = True\n for pp in primes:\n if yy//pp*pp==yy:\n ok = False\n break\n if ok:\n sol = yy\n break\n\nif sol:\n print(sol)\nelse:\n print(-1)\n", "passed": true, "time": 6.88, "memory": 14308.0, "status": "done"}, {"code": "\np,y= [int(x) for x in input().split()]\nimport math as m\n\nfor i in range(y, p, -1):\n for d in range(2, min( int(m.sqrt(i))+1, p+1 )):\n if i % d ==0:\n break\n else:\n print(i)\n break\nelse:\n print(-1)\n", "passed": true, "time": 0.2, "memory": 14412.0, "status": "done"}, {"code": "p,y = list(map(int,input().split()))\nimport math\ndef is_prime(n,p):\n if n % 2 == 0 and n > 2: \n return False\n if p == 2: return True\n for i in range(3, min(p,int(math.sqrt(n)))+1, 2):\n if n % i == 0:\n return False\n return True\nfor x in range(y,p,-1):\n if is_prime(x,p):\n print(x)\n break\nelse:\n print(-1)\n\n", "passed": true, "time": 0.18, "memory": 14396.0, "status": "done"}, {"code": "from math import sqrt; from itertools import count, islice\n\n# def isPrime(n,p):\n# for i in range(2,)\n# return n > 1 and all(n%i for i in islice(count(2), int(sqrt(p))))\n\n\ndef isPrime(n,p) :\n j=int(sqrt(n))\n if p*p < n:\n j=p\n # Check from 2 to n-1\n for i in range(2, j+1):\n if n % i == 0:\n return False\n return True\n\n # # This is checked so that we can skip\n # # middle five numbers in below loop\n # if (n % 2 == 0 or n % 3 == 0) :\n # return False\n #\n # i = 5\n # while(i * i <= n) :\n # if (n % i == 0 or n % (i + 2) == 0) :\n # return False\n # i = i + 6\n #\n # return True\n\np,y=list(map(int,input().split(' ')))\nflag=0\nfor i in range(y,p,-1):\n if isPrime(i,p):\n print(i)\n flag=1\n break\nif flag==0:\n print(-1)\n", "passed": true, "time": 0.2, "memory": 14408.0, "status": "done"}, {"code": "from math import trunc\np,y = map(int,input().split())\nif p ** 2 < y:\n st = p\nelse:\n st = trunc(y ** 0.5)\nfor i in range(y,p,-1):\n check = True\n for j in range(2,st + 1):\n if i % j == 0:\n check = False\n break\n if check:\n print(i)\n return\nprint(-1)", "passed": true, "time": 0.2, "memory": 14348.0, "status": "done"}, {"code": "import math\nimport sys\n\n\ndef is_prime(n, p):\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 i > p: break\n if n % i == 0:\n return False\n return True\n\n\ndef main():\n p, y = list(map(int, sys.stdin.readline().split()))\n\n highest = y\n if y % 2 == 0:\n highest -= 1\n while highest > p:\n if is_prime(highest, p):\n print(highest)\n return\n highest -= 2\n\n print(-1)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.18, "memory": 14424.0, "status": "done"}, {"code": "# vars: get_hopper, p, q, x, y\ndef get_hopper(x1):\n\tfor hopper in range(2, 1+min(p, int(x1**.5))):\n\t\tif x1 % hopper == 0:\n\t\t\treturn hopper\np, y = list(map(int, input().split()))\nfor x in range(y, p, -1):\n\tif get_hopper(x) is None:\n\t\tprint(x)\n#\n\t\treturn\nprint('-1')\n", "passed": true, "time": 0.3, "memory": 14368.0, "status": "done"}, {"code": "def SieveOfEratosthenes(n):\n # Create a boolean array \"prime[0..n]\" and initialize\n # all entries it as true. A value in prime[i] will\n # finally be false if i is Not a prime, else true.\n prime = [True for i in range(n + 1)]\n p = 2\n while (p * p <= n):\n\n # If prime[p] is not changed, then it is a prime\n if (prime[p] == True):\n\n # Update all multiples of p\n for i in range(p * 2, n + 1, p):\n prime[i] = False\n p += 1\n ls=[]\n # Print all prime numbers\n for p in range(2, n):\n if prime[p]:\n ls.append(p)\n return ls\nls=SieveOfEratosthenes(100000)\np,y=[int(i) for i in input().split(\" \")]\nwhile (y!=p):\n flag=0\n for i in ls:\n if i>p:\n break\n if not y%i:\n flag=1\n break\n if not flag:\n print(y)\n return\n y-=1\nprint(-1)", "passed": true, "time": 1.98, "memory": 14660.0, "status": "done"}, {"code": "import math\n\ndef check(x):\n\tlimit = math.ceil(math.sqrt(x))\n\t\n\tfor i in range(3, limit+1, 2):\n\t\tif x%i==0:\n\t\t\treturn i\n\treturn x\n\np,y = list(map(int, input().split()))\n\nans = -1\n\nif y%2==0:\n\ty-=1\n\nfor x in range(y, p, -2):\n\tq = check(x)\n\tif q>p:\n\t\tans = x\n\t\tbreak\nprint(ans)\n", "passed": true, "time": 0.32, "memory": 14292.0, "status": "done"}, {"code": "def main():\n p,y=list(map(int,input().split()))\n i=0\n while i<(10**5)*5:\n if y<=p:\n break\n i+=1\n pr=True\n for w in range(2,p+1):\n if w*w>y:\n break\n if y%w==0:\n pr=False\n break\n if pr:\n print(y)\n return\n y-=1\n print('-1')\nmain()\n", "passed": true, "time": 0.24, "memory": 14452.0, "status": "done"}, {"code": "p, y = map(int, input().split())\ndef f(x):\n\ti = 2\n\twhile i <= p and i * i <= y:\n\t\tif x % i == 0:\n\t\t\treturn False\n\t\ti += 1\n\treturn True\nind = False\t\t\nfor i in range(y, p, -1):\n\tif f(i):\n\t\tprint(i)\n\t\tind = True\n\t\tbreak\nif not ind:\n\tprint(-1)", "passed": true, "time": 0.42, "memory": 14260.0, "status": "done"}, {"code": "GI = lambda: int(input()); GIS = lambda: list(map(int, input().split())); LGIS = lambda: list(GIS())\n\nfrom math import sqrt\n\ndef main():\n p, y = GIS()\n\n for x in range(y, p, -1):\n for d in range(2, min(p, int(sqrt(x))) + 1):\n if not x % d:\n break\n else:\n return x\n\n return -1\n\nprint(main())\n", "passed": true, "time": 0.2, "memory": 14520.0, "status": "done"}, {"code": "from math import sqrt\n\np, y = list(map(int, input().split()))\n\nyp = int(sqrt(y))\n\nif yp > p:\n yp = p\n if yp % 2 == 0: yp -= 1\n\nif p == 2: \n if y == 2:\n print(-1)\n return\n if y % 2 == 0:\n print(y-1)\n return\n else:\n print(y)\n return\n \n \nif yp % 2 == 0: yp -= 1\n\nif y % 2 == 0: y -= 1\n\n\nif yp == 1:\n if y > 2 and y % 2 == 0:\n print(y-1)\n return\n if y > p:\n print(y)\n return\n else:\n print(-1)\n return\n\nwhile y > p:\n yr = yp\n while yr > 2:\n if y % yr == 0:\n yr -= 2\n break\n\n elif yr == 3:\n print(y)\n return\n\n elif yr > 3:\n yr -= 2\n\n\n y -= 2\n\nprint(\"-1\")", "passed": true, "time": 0.89, "memory": 14556.0, "status": "done"}, {"code": "p,y=map(int,input().split(' '))\nf2=0\nfor i in range(y,max(p,y-301),-1):\n f=0\n for j in range(2,min(int(i**0.5)+1,p+1)):\n if i%j==0:\n f=1\n break\n if f==0:\n f2=1\n print(i)\n break\nif f2==0:\n print(-1)", "passed": true, "time": 0.2, "memory": 14448.0, "status": "done"}, {"code": "import math\n\ndef check(n, top):\n for x in range(2, top+1):\n if n % x == 0:\n return False\n return True\n\n\ndef __starting_point():\n p, y = input().split()\n p = int(p)\n y = int(y)\n\n m = min(math.floor(math.sqrt(y)),p)\n\n cur = y\n while cur > p:\n if check(cur, m):\n print(cur)\n return\n cur -= 1\n\n print(-1)\n\n__starting_point()", "passed": true, "time": 0.2, "memory": 14324.0, "status": "done"}, {"code": "import math\n\np, y = list(map(int, input().split()))\n\ndef isPrime(p,n):\n i = 2\n while i <= math.sqrt(n) and i <= p:\n if n%i == 0:\n return False\n i += 1\n return True\n \n\ni = y\nans = -1\nwhile i > p:\n if isPrime(p,i):\n ans = i\n break\n i -= 1\n\nprint(ans)\n", "passed": true, "time": 0.36, "memory": 14468.0, "status": "done"}, {"code": "def f(n):\n i=2\n while i*i<=n:\n if n%i==0:\n return False\n i+=1\n return True\np,y=list(map(int,input().split()))\nif p>100000:\n i=y\n while not f(i):\n if i==p:\n print(-1)\n return\n i-=1\n print(i)\nelse:\n for i in range(y,p,-1):\n for j in range(2,p+1):\n if i%j==0:\n break\n else:\n print(i)\n break\n else:\n print(-1)\n \n \n", "passed": true, "time": 0.24, "memory": 14276.0, "status": "done"}]
[{"input": "3 6\n", "output": "5\n"}, {"input": "3 4\n", "output": "-1\n"}, {"input": "2 2\n", "output": "-1\n"}, {"input": "5 50\n", "output": "49\n"}, {"input": "944192806 944193066\n", "output": "944192807\n"}, {"input": "1000000000 1000000000\n", "output": "-1\n"}, {"input": "2 1000000000\n", "output": "999999999\n"}, {"input": "28788 944193066\n", "output": "944192833\n"}, {"input": "49 52\n", "output": "-1\n"}, {"input": "698964997 734575900\n", "output": "734575871\n"}, {"input": "287894773 723316271\n", "output": "723316207\n"}, {"input": "171837140 733094070\n", "output": "733094069\n"}, {"input": "37839169 350746807\n", "output": "350746727\n"}, {"input": "125764821 234689174\n", "output": "234689137\n"}, {"input": "413598841 430509920\n", "output": "430509917\n"}, {"input": "145320418 592508508\n", "output": "592508479\n"}, {"input": "155098216 476450875\n", "output": "476450861\n"}, {"input": "459843315 950327842\n", "output": "950327831\n"}, {"input": "469621113 834270209\n", "output": "834270209\n"}, {"input": "13179877 557546766\n", "output": "557546753\n"}, {"input": "541748242 723508350\n", "output": "723508301\n"}, {"input": "607450717 924641194\n", "output": "924641189\n"}, {"input": "786360384 934418993\n", "output": "934418981\n"}, {"input": "649229491 965270051\n", "output": "965270051\n"}, {"input": "144179719 953974590\n", "output": "953974583\n"}, {"input": "28122086 963752388\n", "output": "963752347\n"}, {"input": "268497487 501999053\n", "output": "501999053\n"}, {"input": "356423140 385941420\n", "output": "385941419\n"}, {"input": "71233638 269883787\n", "output": "269883787\n"}, {"input": "2601 698964997\n", "output": "698964983\n"}, {"input": "4096 287894773\n", "output": "287894771\n"}, {"input": "5675 171837140\n", "output": "171837131\n"}, {"input": "13067 350746807\n", "output": "350746727\n"}, {"input": "8699 234689174\n", "output": "234689137\n"}, {"input": "12190 413598841\n", "output": "413598817\n"}, {"input": "20555 592508508\n", "output": "592508479\n"}, {"input": "19137 476450875\n", "output": "476450861\n"}, {"input": "8793 950327842\n", "output": "950327831\n"}, {"input": "1541 834270209\n", "output": "834270209\n"}, {"input": "1082 13179877\n", "output": "13179871\n"}, {"input": "3888 723508350\n", "output": "723508301\n"}, {"input": "14078 607450717\n", "output": "607450703\n"}, {"input": "20869 786360384\n", "output": "786360373\n"}, {"input": "13689 965270051\n", "output": "965270051\n"}, {"input": "782 144179719\n", "output": "144179719\n"}, {"input": "404 28122086\n", "output": "28122079\n"}, {"input": "21992 501999053\n", "output": "501999053\n"}, {"input": "13745 385941420\n", "output": "385941419\n"}, {"input": "8711 269883787\n", "output": "269883787\n"}, {"input": "31333 981756889\n", "output": "981756871\n"}, {"input": "944192808 944193061\n", "output": "-1\n"}, {"input": "3 9\n", "output": "7\n"}, {"input": "4 5\n", "output": "5\n"}, {"input": "2 13\n", "output": "13\n"}, {"input": "7 53\n", "output": "53\n"}, {"input": "10 1000000000\n", "output": "999999997\n"}, {"input": "2 7\n", "output": "7\n"}, {"input": "4 9\n", "output": "7\n"}]
331
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. [Image] The girl lives in house m of a village. There are n houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house n. The village is also well-structured: house i and house i + 1 (1 ≀ i < n) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased. You will be given n integers a_1, a_2, ..., a_{n} that denote the availability and the prices of the houses. If house i is occupied, and therefore cannot be bought, then a_{i} equals 0. Otherwise, house i can be bought, and a_{i} represents the money required to buy it, in dollars. As Zane has only k dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love. -----Input----- The first line contains three integers n, m, and k (2 ≀ n ≀ 100, 1 ≀ m ≀ n, 1 ≀ k ≀ 100)Β β€” the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively. The second line contains n integers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 100)Β β€” denoting the availability and the prices of the houses. It is guaranteed that a_{m} = 0 and that it is possible to purchase some house with no more than k dollars. -----Output----- Print one integerΒ β€” the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. -----Examples----- Input 5 1 20 0 27 32 21 19 Output 40 Input 7 3 50 62 0 0 0 99 33 22 Output 30 Input 10 5 100 1 0 1 0 0 0 0 0 1 1 Output 20 -----Note----- In the first sample, with k = 20 dollars, Zane can buy only house 5. The distance from house m = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters. In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house m = 3 and house 6 are only 30 meters away, while house m = 3 and house 7 are 40 meters away.
interview
[{"code": "from sys import stdin, stdout\n\nn, m, k = map(int, stdin.readline().split())\nchallengers = list(map(int, stdin.readline().split()))\nm -= 1\n\ni = 1\nans = 10\nwhile True:\n if m + i < n and challengers[m + i] and challengers[m + i] <= k:\n break\n \n if m - i >= 0 and challengers[m - i] and challengers[m - i] <= k:\n break\n \n ans += 10\n i += 1\n\n\nstdout.write(str(ans))", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}]
[{"input": "5 1 20\n0 27 32 21 19\n", "output": "40"}, {"input": "7 3 50\n62 0 0 0 99 33 22\n", "output": "30"}, {"input": "10 5 100\n1 0 1 0 0 0 0 0 1 1\n", "output": "20"}, {"input": "5 3 1\n1 1 0 0 1\n", "output": "10"}, {"input": "5 5 5\n1 0 5 6 0\n", "output": "20"}, {"input": "15 10 50\n20 0 49 50 50 50 50 50 50 0 50 50 49 0 20\n", "output": "10"}, {"input": "7 5 1\n0 100 2 2 0 2 1\n", "output": "20"}, {"input": "100 50 100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 0 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n", "output": "10"}, {"input": "100 50 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 0 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n", "output": "490"}, {"input": "100 77 50\n50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 0 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0 50 100 49 51 0\n", "output": "10"}, {"input": "100 1 1\n0 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0\n", "output": "980"}, {"input": "100 1 100\n0 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": "10"}, {"input": "100 10 99\n0 0 0 0 0 0 0 0 0 0 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 99 98\n", "output": "890"}, {"input": "7 4 5\n1 0 6 0 5 6 0\n", "output": "10"}, {"input": "7 4 5\n1 6 5 0 0 6 0\n", "output": "10"}, {"input": "100 42 59\n50 50 50 50 50 50 50 50 50 50 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 59 60 60 60 60 60 60 60 60 0 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 0\n", "output": "90"}, {"input": "2 1 100\n0 1\n", "output": "10"}, {"input": "2 2 100\n1 0\n", "output": "10"}, {"input": "10 1 88\n0 95 0 0 0 0 0 94 0 85\n", "output": "90"}, {"input": "10 2 14\n2 0 1 26 77 39 41 100 13 32\n", "output": "10"}, {"input": "10 3 11\n0 0 0 0 0 62 0 52 1 35\n", "output": "60"}, {"input": "20 12 44\n27 40 58 69 53 38 31 39 75 95 8 0 28 81 77 90 38 61 21 88\n", "output": "10"}, {"input": "30 29 10\n59 79 34 12 100 6 1 58 18 73 54 11 37 46 89 90 80 85 73 45 64 5 31 0 89 19 0 74 0 82\n", "output": "70"}, {"input": "40 22 1\n7 95 44 53 0 0 19 93 0 68 65 0 24 91 10 58 17 0 71 0 100 0 94 90 79 73 0 73 4 61 54 81 7 13 21 84 5 41 0 1\n", "output": "180"}, {"input": "40 22 99\n60 0 100 0 0 100 100 0 0 0 0 100 100 0 0 100 100 0 100 100 100 0 100 100 100 0 100 100 0 0 100 100 100 0 0 100 0 100 0 0\n", "output": "210"}, {"input": "50 10 82\n56 54 0 0 0 0 88 93 0 0 83 93 0 0 91 89 0 30 62 52 24 84 80 8 38 13 92 78 16 87 23 30 71 55 16 63 15 99 4 93 24 6 3 35 4 42 73 27 86 37\n", "output": "80"}, {"input": "63 49 22\n18 3 97 52 75 2 12 24 58 75 80 97 22 10 79 51 30 60 68 99 75 2 35 3 97 88 9 7 18 5 0 0 0 91 0 91 56 36 76 0 0 0 52 27 35 0 51 72 0 96 57 0 0 0 0 92 55 28 0 30 0 78 77\n", "output": "190"}, {"input": "74 38 51\n53 36 55 42 64 5 87 9 0 16 86 78 9 22 19 1 25 72 1 0 0 0 79 0 0 0 77 58 70 0 0 100 64 0 99 59 0 0 0 0 65 74 0 96 0 58 89 93 61 88 0 0 82 89 0 0 49 24 7 77 89 87 94 61 100 31 93 70 39 49 39 14 20 84\n", "output": "190"}, {"input": "89 22 11\n36 0 68 89 0 85 72 0 38 56 0 44 0 94 0 28 71 0 0 18 0 0 0 89 0 0 0 75 0 0 0 32 66 0 0 0 0 0 0 48 63 0 64 58 0 23 48 0 0 52 93 61 57 0 18 0 0 34 62 17 0 41 0 0 53 59 44 0 0 51 40 0 0 100 100 54 0 88 0 5 45 56 57 67 24 16 88 86 15\n", "output": "580"}, {"input": "97 44 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 51 19\n", "output": "520"}, {"input": "100 1 1\n0 0 0 0 10 54 84 6 17 94 65 82 34 0 61 46 42 0 2 16 56 0 100 0 82 0 0 0 89 78 96 56 0 0 0 0 0 0 0 0 77 70 0 96 67 0 0 32 44 1 72 50 14 11 24 61 100 64 19 5 67 69 44 82 93 22 67 93 22 61 53 64 79 41 84 48 43 97 7 24 8 49 23 16 72 52 97 29 69 47 29 49 64 91 4 73 17 18 51 67\n", "output": "490"}, {"input": "100 1 50\n0 0 0 60 0 0 54 0 80 0 0 0 97 0 68 97 84 0 0 93 0 0 0 0 68 0 0 62 0 0 55 68 65 87 0 69 0 0 0 0 0 52 61 100 0 71 0 82 88 78 0 81 0 95 0 57 0 67 0 0 0 55 86 0 60 72 0 0 73 0 83 0 0 60 64 0 56 0 0 77 84 0 58 63 84 0 0 67 0 16 3 88 0 98 31 52 40 35 85 23\n", "output": "890"}, {"input": "100 1 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 91 70 14\n", "output": "970"}, {"input": "100 1 29\n0 0 0 0 64 0 89 97 0 0 0 59 0 67 62 0 59 0 0 80 0 0 0 0 0 97 0 57 0 64 32 0 44 0 0 48 0 47 38 0 42 0 0 0 0 0 0 46 74 0 86 33 33 0 44 0 79 0 0 0 0 91 59 0 59 65 55 0 0 58 33 95 0 97 76 0 81 0 41 0 38 81 80 0 85 0 31 0 0 92 0 0 45 96 0 85 91 87 0 10\n", "output": "990"}, {"input": "100 50 20\n3 0 32 0 48 32 64 0 54 26 0 0 0 0 0 28 0 0 54 0 0 45 49 0 38 74 0 0 39 42 62 48 75 96 89 42 0 44 0 0 30 21 76 0 50 0 79 0 0 0 0 99 0 84 62 0 0 0 0 53 80 0 28 0 0 53 0 0 38 0 62 0 0 62 0 0 88 0 44 32 0 81 35 45 49 0 69 73 38 27 72 0 96 72 69 0 0 22 76 10\n", "output": "490"}, {"input": "100 50 20\n49 0 56 0 87 25 40 0 50 0 0 97 0 0 36 29 0 0 0 0 0 73 29 71 44 0 0 0 91 92 69 0 0 60 81 49 48 38 0 87 0 82 0 32 0 82 46 39 0 0 29 0 0 29 0 79 47 0 0 0 0 0 49 0 24 33 70 0 63 45 97 90 0 0 29 53 55 0 84 0 0 100 26 0 88 0 0 0 0 81 70 0 30 80 0 75 59 98 0 2\n", "output": "500"}, {"input": "100 2 2\n0 0 43 90 47 5 2 97 52 69 21 48 64 10 34 97 97 74 8 19 68 56 55 24 47 38 43 73 72 72 60 60 51 36 33 44 100 45 13 54 72 52 0 15 3 6 50 8 88 4 78 26 40 27 30 63 67 83 61 91 33 97 54 20 92 27 89 35 10 7 84 50 11 95 74 88 24 44 74 100 18 56 34 91 41 34 51 51 11 91 89 54 19 100 83 89 10 17 76 20\n", "output": "50"}, {"input": "100 100 34\n5 73 0 0 44 0 0 0 79 55 0 0 0 0 0 0 0 0 83 67 75 0 0 0 0 59 0 74 0 0 47 98 0 0 72 41 0 55 87 0 0 78 84 0 0 39 0 79 72 95 0 0 0 0 0 85 53 84 0 0 0 0 37 75 0 66 0 0 0 0 61 0 70 0 37 60 42 78 92 52 0 0 0 55 77 57 0 63 37 0 0 0 96 70 0 94 97 0 0 0\n", "output": "990"}, {"input": "100 100 100\n43 79 21 87 84 14 28 69 92 16 3 71 79 37 48 37 72 58 12 72 62 49 37 17 60 54 41 99 15 72 40 89 76 1 99 87 14 56 63 48 69 37 96 64 7 14 1 73 85 33 98 70 97 71 96 28 49 71 56 2 67 22 100 2 98 100 62 77 92 76 98 98 47 26 22 47 50 56 9 16 72 47 5 62 29 78 81 1 0 63 32 65 87 3 40 53 8 80 93 0\n", "output": "10"}, {"input": "100 38 1\n3 59 12 81 33 95 0 41 36 17 63 76 42 77 85 56 3 96 55 41 24 87 18 9 0 37 0 61 69 0 0 0 67 0 0 0 0 0 0 18 0 0 47 56 74 0 0 80 0 42 0 1 60 59 62 9 19 87 92 48 58 30 98 51 99 10 42 94 51 53 50 89 24 5 52 82 50 39 98 8 95 4 57 21 10 0 44 32 19 14 64 34 79 76 17 3 15 22 71 51\n", "output": "140"}, {"input": "100 72 1\n56 98 8 27 9 23 16 76 56 1 34 43 96 73 75 49 62 20 18 23 51 55 30 84 4 20 89 40 75 16 69 35 1 0 16 0 80 0 41 17 0 0 76 23 0 92 0 34 0 91 82 54 0 0 0 63 85 59 98 24 29 0 8 77 26 0 34 95 39 0 0 0 74 0 0 0 0 12 0 92 0 0 55 95 66 30 0 0 29 98 0 0 0 47 0 0 80 0 0 4\n", "output": "390"}, {"input": "100 66 1\n38 50 64 91 37 44 74 21 14 41 80 90 26 51 78 85 80 86 44 14 49 75 93 48 78 89 23 72 35 22 14 48 100 71 62 22 7 95 80 66 32 20 17 47 79 30 41 52 15 62 67 71 1 6 0 9 0 0 0 11 0 0 24 0 31 0 77 0 51 0 0 0 0 0 0 77 0 36 44 19 90 45 6 25 100 87 93 30 4 97 36 88 33 50 26 71 97 71 51 68\n", "output": "130"}, {"input": "100 55 1\n0 33 45 83 56 96 58 24 45 30 38 60 39 69 21 87 59 21 72 73 27 46 61 61 11 97 77 5 39 3 3 35 76 37 53 84 24 75 9 48 31 90 100 84 74 81 83 83 42 23 29 94 18 1 0 53 52 99 86 37 94 54 28 75 28 80 17 14 98 68 76 20 32 23 42 31 57 79 60 14 18 27 1 98 32 3 96 25 15 38 2 6 3 28 59 54 63 2 43 59\n", "output": "10"}, {"input": "100 55 1\n24 52 41 6 55 11 58 25 63 12 70 39 23 28 72 17 96 85 7 84 21 13 34 37 97 43 36 32 15 30 58 5 14 71 40 70 9 92 44 73 31 58 96 90 19 35 29 91 25 36 48 95 61 78 0 1 99 61 81 88 42 53 61 57 42 55 74 45 41 92 99 30 20 25 89 50 37 4 17 24 6 65 15 44 40 2 38 43 7 90 38 59 75 87 96 28 12 67 24 32\n", "output": "10"}, {"input": "100 21 1\n62 5 97 80 81 28 83 0 26 0 0 0 0 23 0 0 90 0 0 0 0 0 0 0 0 54 71 8 0 0 42 0 73 0 17 0 1 31 71 78 58 72 84 39 54 59 13 29 16 41 71 35 88 55 70 50 33 100 100 60 52 90 7 66 44 55 51 42 90 17 86 44 46 8 52 74 8 22 2 92 34 37 58 98 70 74 19 91 74 25 4 38 71 68 50 68 63 14 60 98\n", "output": "160"}, {"input": "5 2 20\n27 0 32 21 19\n", "output": "30"}, {"input": "6 4 10\n10 0 0 0 0 10\n", "output": "20"}, {"input": "8 7 100\n1 0 0 0 0 0 0 1\n", "output": "10"}, {"input": "5 3 20\n1 21 0 0 1\n", "output": "20"}, {"input": "4 3 1\n0 0 0 1\n", "output": "10"}, {"input": "5 2 3\n4 0 5 6 1\n", "output": "30"}, {"input": "5 3 87\n88 89 0 1 90\n", "output": "10"}, {"input": "5 3 20\n15 30 0 15 35\n", "output": "10"}, {"input": "6 3 50\n0 0 0 1 2 0\n", "output": "10"}, {"input": "6 4 9\n100 9 10 0 0 9\n", "output": "20"}, {"input": "5 4 20\n0 20 0 0 20\n", "output": "10"}, {"input": "6 3 3\n1 5 0 2 2 0\n", "output": "10"}, {"input": "5 4 100\n0 1 0 0 1\n", "output": "10"}]
333
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself. -----Input----- The first line contains string a, and the second lineΒ β€” string b. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 10^5 characters. -----Output----- If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of a and b. -----Examples----- Input abcd defgh Output 5 Input a a Output -1 -----Note----- In the first example: you can choose "defgh" from string b as it is the longest subsequence of string b that doesn't appear as a subsequence of string a.
interview
[{"code": "import sys\na = input()\nb = input()\nif a != b:\n print(max(len(a), len(b)))\nelse:\n print(-1)\n", "passed": true, "time": 0.37, "memory": 14240.0, "status": "done"}, {"code": "s = input()\nt = input()\nx = len(s)\ny = len(t)\nif s == t:print(-1)\nelse: print(max(x, y))\n", "passed": true, "time": 0.3, "memory": 14236.0, "status": "done"}, {"code": "a = input()\nb = input()\n\nif a == b:\n\tprint(-1)\nelse:\n\tprint(max(len(a), len(b)))", "passed": true, "time": 0.15, "memory": 14276.0, "status": "done"}, {"code": "#n = int(input())\n#a, b = map(int, input())\na = input()\nb = input()\n#arr = list(map(int, input().split()))\nif a != b:\n print(max(len(a), len(b)))\nelse:\n print(-1)", "passed": true, "time": 0.3, "memory": 14496.0, "status": "done"}, {"code": "a = input()\nb = input()\nif (a == b):\n print(-1)\nelse:\n print(max(len(a), len(b)))", "passed": true, "time": 0.38, "memory": 14356.0, "status": "done"}, {"code": "\n\nA = input()\nB = input()\n\nif A == B:\n print(-1)\nelse:\n print(max([len(A), len(B)]))\n", "passed": true, "time": 0.17, "memory": 14456.0, "status": "done"}, {"code": "a = input()\nb = input()\nif a == b:\n print(-1)\nelse:\n print(max(len(a), len(b)))\n", "passed": true, "time": 0.2, "memory": 14440.0, "status": "done"}, {"code": "#!/bin/python3\n\nimport sys\na = input()\nb = input()\nif a == b:\n print(-1)\n return\nprint(max(len(a),len(b)))", "passed": true, "time": 0.14, "memory": 14500.0, "status": "done"}, {"code": "s = input()\ns1 = input()\nif s == s1:\n print(-1)\nelse:\n print(max(len(s), len(s1)))", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "s1 = input()\ns2 = input()\nif s1 == s2:\n print(-1)\nelse:\n print(max(len(s1), len(s2)))\n", "passed": true, "time": 0.15, "memory": 14392.0, "status": "done"}, {"code": "s1 = input()\ns2 = input()\n\nif s1 == s2:\n print(-1)\nelse:\n print(max(len(s1), len(s2)))\n", "passed": true, "time": 0.16, "memory": 14476.0, "status": "done"}, {"code": "a = input().strip()\nb = input().strip()\n\nif a == b:\n\tprint(-1)\nelse:\n\tprint(max(len(a), len(b)))", "passed": true, "time": 0.14, "memory": 14232.0, "status": "done"}, {"code": "def __starting_point():\n a = input().strip()\n b = input().strip()\n\n if a == b:\n print(-1)\n else:\n print(max(len(a), len(b)))\n\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14256.0, "status": "done"}, {"code": "def myf(s,m):\n if (s == m):\n return (-1)\n else:\n return (max(len(s), len(m)))\n\ns = input() \nm = input() \nres = myf(s,m)\nprint (res)", "passed": true, "time": 0.15, "memory": 14232.0, "status": "done"}, {"code": "s1 = input()\ns2 = input()\nif s1 != s2:\n print(max(len(s1), len(s2)))\nelse:\n print(-1)\n", "passed": true, "time": 0.16, "memory": 14292.0, "status": "done"}, {"code": "a=input()\nb=input()\nif a==b: print(-1)\nelse: print(max(len(a),len(b)))", "passed": true, "time": 0.23, "memory": 14408.0, "status": "done"}, {"code": "a = input()\nb = input()\n\nif a == b:\n print(-1)\nelse:\n print(max(len(a), len(b)))", "passed": true, "time": 0.14, "memory": 14216.0, "status": "done"}, {"code": "a=input()\nb=input()\nif a==b:\n print(-1)\nelse:\n print(max(len(a),len(b)))", "passed": true, "time": 0.15, "memory": 14496.0, "status": "done"}, {"code": "s1 = input()\ns2 = input()\n\nif len(s1) != len(s2):\n print(max(len(s1), len(s2)))\nelif s1 == s2:\n print(-1)\nelse:\n print(len(s1))", "passed": true, "time": 0.14, "memory": 14484.0, "status": "done"}, {"code": "import sys\n\na = input()\nb = input()\nif a != b:\n print(max(len(a),len(b)))\nelse:\n print(-1)\n", "passed": true, "time": 0.15, "memory": 14372.0, "status": "done"}, {"code": "s1 = input()\ns2 = input()\nif s1 == s2:\n print(-1)\nelse:\n print(max(len(s1), len(s2)))", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "a = input()\nb = input()\nif a == b:\n print(-1)\nelse:\n print(max(len(a), len(b)))\n", "passed": true, "time": 0.17, "memory": 14320.0, "status": "done"}, {"code": "def __starting_point():\n\ta = input()\n\tb = input()\n\tif (a == b):\n\t\tprint(-1)\n\telse:\n\t\tprint(max(len(a), len(b)))\n__starting_point()", "passed": true, "time": 0.15, "memory": 14392.0, "status": "done"}, {"code": "a = input()\nb = input()\n\nif len(a) != len(b):\n\tprint(max(len(a), len(b)))\nelse:\n\tif a != b:\n\t\tprint(len(a))\n\telse:\n\t\tprint(-1)", "passed": true, "time": 0.15, "memory": 14484.0, "status": "done"}]
[{"input": "abcd\ndefgh\n", "output": "5\n"}, {"input": "a\na\n", "output": "-1\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddddddddd\n", "output": "100\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n", "output": "199\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbb\n", "output": "99\n"}, {"input": "abcde\nfghij\n", "output": "5\n"}, {"input": "abcde\nabcdf\n", "output": "5\n"}, {"input": "abcde\nbbcde\n", "output": "5\n"}, {"input": "abcde\neabcd\n", "output": "5\n"}, {"input": "abcdefgh\nabdcefgh\n", "output": "8\n"}, {"input": "mmmmm\nmnmmm\n", "output": "5\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaa\n", "output": "34\n"}, {"input": "abcdefghijklmnopqrstuvwxyz\nzabcdefghijklmnopqrstuvwxy\n", "output": "26\n"}, {"input": "a\nab\n", "output": "2\n"}, {"input": "b\nab\n", "output": "2\n"}, {"input": "ab\nb\n", "output": "2\n"}, {"input": "ab\nc\n", "output": "2\n"}, {"input": "aaaaaa\naaaaaa\n", "output": "-1\n"}, {"input": "abacaba\nabacaba\n", "output": "-1\n"}, {"input": "aabb\nbbaa\n", "output": "4\n"}, {"input": "ab\nba\n", "output": "2\n"}, {"input": "abcd\nabc\n", "output": "4\n"}, {"input": "abaa\nabaa\n", "output": "-1\n"}, {"input": "ab\nab\n", "output": "-1\n"}, {"input": "ab\nabcd\n", "output": "4\n"}, {"input": "abc\nabcd\n", "output": "4\n"}, {"input": "mo\nmomo\n", "output": "4\n"}, {"input": "koooooooooooooooo\nloooooooooooooooo\n", "output": "17\n"}, {"input": "aaa\naa\n", "output": "3\n"}, {"input": "abc\nabc\n", "output": "-1\n"}, {"input": "abcd\nabcd\n", "output": "-1\n"}, {"input": "abc\ncba\n", "output": "3\n"}, {"input": "ahc\nahc\n", "output": "-1\n"}, {"input": "abc\nbac\n", "output": "3\n"}, {"input": "aa\naaa\n", "output": "3\n"}, {"input": "aaa\naaa\n", "output": "-1\n"}, {"input": "abc\nacb\n", "output": "3\n"}, {"input": "abc\nab\n", "output": "3\n"}, {"input": "abb\nabb\n", "output": "-1\n"}, {"input": "abc\ncab\n", "output": "3\n"}, {"input": "aaaaaa\naaaaa\n", "output": "6\n"}, {"input": "aa\naab\n", "output": "3\n"}, {"input": "len\nlena\n", "output": "4\n"}, {"input": "aaaaa\naa\n", "output": "5\n"}, {"input": "aaa\naaaa\n", "output": "4\n"}, {"input": "bcd\nabcd\n", "output": "4\n"}, {"input": "aaabbc\naaaccc\n", "output": "6\n"}, {"input": "abcd\nzycd\n", "output": "4\n"}, {"input": "baa\nzaa\n", "output": "3\n"}, {"input": "asdf\nadfs\n", "output": "4\n"}, {"input": "abcdefgh\nabcdefgh\n", "output": "-1\n"}, {"input": "aba\naab\n", "output": "3\n"}, {"input": "aba\naba\n", "output": "-1\n"}, {"input": "abcccc\naccccc\n", "output": "6\n"}, {"input": "acb\nabc\n", "output": "3\n"}, {"input": "a\naa\n", "output": "2\n"}, {"input": "abababab\nab\n", "output": "8\n"}, {"input": "ababab\nab\n", "output": "6\n"}]
334
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, .... [Image] The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time. -----Input----- The first line of input contains two integers a and b (1 ≀ a, b ≀ 100). The second line contains two integers c and d (1 ≀ c, d ≀ 100). -----Output----- Print the first time Rick and Morty will scream at the same time, or - 1 if they will never scream at the same time. -----Examples----- Input 20 2 9 19 Output 82 Input 2 1 16 12 Output -1 -----Note----- In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82. In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.
interview
[{"code": "a, b = map(int,input().split())\nc, d = map(int,input().split())\nONE = set()\nTWO = set()\nfor i in range(b, 50000, a):\n ONE.add(i)\nfor i in range(d, 50000, c):\n TWO.add(i)\n\nopt = 99999\nfor i in ONE:\n if i in TWO:\n opt = min(opt, i)\nif opt == 99999:\n print(-1)\nelse:\n print(opt)", "passed": true, "time": 0.38, "memory": 21212.0, "status": "done"}, {"code": "import sys\n\na, b = list(map(int, input().split()))\nc, d = list(map(int, input().split()))\n\ncur1, cur2 = b, d\nx = set()\ny = set()\n\nfor i in range(100000):\n x.add(cur1)\n y.add(cur2)\n cur1 += a\n cur2 += c\n\nfor i in range(100000):\n if i in x and i in y:\n print(i)\n return\n\nprint(-1)\n\n", "passed": true, "time": 1.48, "memory": 32700.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\nc, d = list(map(int, input().split()))\narr = [b + a * i for i in range(1000)]\nfor i in range(1000):\n if d + c * i in arr:\n print(d + c * i)\n return\nprint(-1)\n", "passed": true, "time": 0.36, "memory": 14496.0, "status": "done"}, {"code": "def gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a % b)\n\na, b = list(map(int, input().split()))\nc, d = list(map(int, input().split()))\n\nmorty = set()\ncr = b\nfor i in range(1000):\n morty.add(cr)\n cr += a\n\ncr = d\nfor i in range(1000):\n if cr in morty:\n print(cr)\n return\n cr += c\nprint(-1)\n", "passed": true, "time": 0.23, "memory": 14376.0, "status": "done"}, {"code": "from sys import stdin, stdout\n\n\na, b = list(map(int, stdin.readline().rstrip().split()))\nc, d = list(map(int, stdin.readline().rstrip().split()))\n\nmatch=-1\nset1=set()\nfor i in range(a+b+max([b,d])):\n set1.add(b+i*a)\n\nfor i in range(a+b+max([b,d])):\n if d+i*c in set1:\n match=d+i*c\n break\n \nprint(match)\n", "passed": true, "time": 0.3, "memory": 14388.0, "status": "done"}, {"code": "import math\n\na, b = list(map(int, input().split()))\nc, d = list(map(int, input().split()))\n\ng = math.gcd(a, c)\nif (d-b)%g != 0:\n print(-1)\nelse:\n t0, t1=b, d\n while t0 != t1:\n if t0 < t1: t0 += a\n else: t1 += c\n print(t0)\n", "passed": true, "time": 0.15, "memory": 14324.0, "status": "done"}, {"code": "a,b=[int(i) for i in input().split()]\nc,d=[int(i) for i in input().split()]\n\nfor i in range(0,10000):\n if b+a*i>=d and (b+a*i-d)%c==0:\n print(b+a*i)\n return\nprint(-1)\n", "passed": true, "time": 0.33, "memory": 14348.0, "status": "done"}, {"code": "import sys\na, b = list(map(int, input().split()))\nc, d = list(map(int, input().split()))\ns = set()\nfor i in range(1001):\n s.add( b + i * a)\nfor i in range(1000):\n num = d + c * i\n if num in s:\n print(num)\n return\nprint(-1)\n", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "import sys\na, b = list(map(int, input().split()))\nc, d = list(map(int, input().split()))\ntimes1 = [b + a*i for i in range(100)]\nfor time2 in [d + c*i for i in range(100)]:\n if time2 in times1:\n print(time2)\n return\nprint(-1)\n", "passed": true, "time": 0.16, "memory": 14260.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\nc, d = list(map(int, input().split()))\n\nt1 = b\nt2 = d\nsolution_found = False\n\nfor i in range(10000):\n\tif (t1 == t2):\n\t\tprint(t1)\n\t\tsolution_found = True\n\t\tbreak\n\telif (t1 > t2):\n\t\tt2 += c\n\telse:\n\t\tt1 += a\n\nif (not solution_found):\n\tprint(-1)", "passed": true, "time": 0.22, "memory": 14424.0, "status": "done"}, {"code": "a,b=list(map(int,input().split()))\ns=0\nc,d=list(map(int,input().split()))\nflag=0\nwhile(d!=b):\n if(s==100000):\n print(-1)\n b=d\n flag=1\n if(d<b):\n d+=max(c*((b-d)//c),c)\n else:\n b+=max(a*((d-b)//a),a)\n s+=1\nif(flag==0):\n print(b)\n", "passed": true, "time": 0.62, "memory": 14260.0, "status": "done"}, {"code": "a,b=map(int,input().split())\nc,d=map(int,input().split())\ns={b-d}\nwhile b!=d:\n if b<d: b+=a\n else: d+=c\n bd=b-d\n if bd in s: break\n s|={bd}\nif d==b: print(b)\nelse: print(-1)", "passed": true, "time": 0.15, "memory": 14224.0, "status": "done"}, {"code": "a,b = list(map(int,input().split()))\nc,d = list(map(int,input().split()))\n\nvalid = [0]*(1000001)\n\ncnt = b\n\nwhile cnt <= 1000000:\n valid[cnt] += 1\n cnt += a\n\ncnt = d\n\nwhile cnt <= 1000000:\n valid[cnt] += 1\n cnt += c\n\nfor i in range(1000001):\n if valid[i] == 2:\n print(i)\n break\nelse:\n print(-1)\n", "passed": true, "time": 2.72, "memory": 21508.0, "status": "done"}, {"code": "from time import time as tm\n\nb, a = list(map(int, input().split()))\nd, c = list(map(int, input().split()))\ncur = ma = mb = 0\n\nstm = tm()\n\nwhile tm() - stm < 0.9:\n isa = (a + b * ma) == cur\n isb = (c + d * mb) == cur\n if isa:\n ma += 1\n if isb:\n mb += 1\n if isa and isb:\n print(cur)\n break\n cur += 1\nelse:\n print(-1)\n", "passed": true, "time": 12.84, "memory": 14396.0, "status": "done"}, {"code": "a,b=[int(c) for c in input().split(' ')]\nc,d=[int(c) for c in input().split(' ')]\n\n\ni=0\nmax=pow(10,5)\nwhile b!=d and i<max:\n while d<b:\n d+=c\n while b<d:\n b+=a\n i+=1\n\nif b!=d:\n print(-1)\nelse:\n print(d)", "passed": true, "time": 0.46, "memory": 14388.0, "status": "done"}, {"code": "a, b = map(int, input().split())\nc, d = map(int, input().split())\nif b > d:\n b, d = d, b\n a, c = c, a\nd -= b\nfor i in range(1000000):\n if (c * i + d) % a == 0:\n print(i * c + d + b)\n break\nelse:\n print(-1)", "passed": true, "time": 1.28, "memory": 14192.0, "status": "done"}, {"code": "a, b = list(map(int, input().split()))\nc, d = list(map(int, input().split()))\n\n\"\"\"\ndef nok(a, b):\n r = a\n while r % b != 0:\n r += a\n return r\n\ndef get_answer():\n if b == d:\n return 0\n\n if c == a:\n return -1\n\n if (b - d) * (c - a) < 0:\n return -1\n\n k = nok(abs(b - d), abs(c - a))\n return b + k * a\n\"\"\"\n\ndef get_answer():\n for i in range(101 * 2):\n for j in range(101 * 2):\n if b + a*i == d + c*j:\n return b + a*i\n\n return -1\n\nprint(get_answer())\n\n\n", "passed": true, "time": 0.22, "memory": 14248.0, "status": "done"}, {"code": "a, b = map(int, input().split())\nc, d = map(int, input().split())\nr = set()\nnow = b\n\nwhile now < d:\n\tnow += a\n\t\nd %= c\nwhile True:\n\tif now % c == d:\n\t\tprint(now)\n\t\treturn\n\t\n\tif (now % c) in r:\n\t\tprint(-1)\n\t\treturn\n\t\n\tr.add(now % c)\n\t\n\tnow += a", "passed": true, "time": 0.24, "memory": 14460.0, "status": "done"}, {"code": "rick = [bool(0)] * 100001\nmorty = [bool(0)] * 100001\na, b = input().split(' ')\na = int(a)\nb = int(b)\nc, d = input().split(' ')\nc = int(c)\nd = int(d)\ni = int(1)\nkrick = -1\nrick_krick = b\nmorty_krick = d\nwhile rick_krick <= 10000:\n rick[rick_krick] = 1\n rick_krick += a\nwhile morty_krick <= 10000:\n morty[morty_krick] = 1\n morty_krick += c\nwhile krick == -1 and i <= 10000:\n if morty[i] == 1 and rick[i] == 1:\n krick = i\n i += 1\nprint(krick)\n", "passed": true, "time": 0.23, "memory": 15048.0, "status": "done"}, {"code": "import sys\nimport math\n\ndef main():\n a, b = map(int, input().split())\n c, d = map(int, input().split())\n arr = list()\n dr = 0\n for i in range(0, 202):\n arr.append(b + dr*a)\n arr.append(d + dr*c)\n dr += 1\n\n arr = sorted(arr)\n for i in range(0, len(arr)-1):\n if (arr[i] == arr[i+1]):\n return print(arr[i])\n print(-1)\n\nmain()", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "line = input()\na, b = line.split()\na, b = int(a), int(b)\n\nline = input()\nc, d = line.split()\nc, d = int(c), int(d)\n\nx = b\n\nx_count = 1\n\ny = d\ny_count = 1\nwhile y != x and y <= 10100 and x <= 10100:\n if y > x:\n x = b + (x_count * a)\n x_count = x_count + 1\n else:\n y = d + (y_count * c)\n y_count = y_count + 1\n\nif y == x:\n print(y)\nelse:\n print(-1)\n", "passed": true, "time": 0.15, "memory": 14488.0, "status": "done"}]
[{"input": "20 2\n9 19\n", "output": "82\n"}, {"input": "2 1\n16 12\n", "output": "-1\n"}, {"input": "39 52\n88 78\n", "output": "1222\n"}, {"input": "59 96\n34 48\n", "output": "1748\n"}, {"input": "87 37\n91 29\n", "output": "211\n"}, {"input": "11 81\n49 7\n", "output": "301\n"}, {"input": "39 21\n95 89\n", "output": "3414\n"}, {"input": "59 70\n48 54\n", "output": "1014\n"}, {"input": "87 22\n98 32\n", "output": "718\n"}, {"input": "15 63\n51 13\n", "output": "-1\n"}, {"input": "39 7\n97 91\n", "output": "1255\n"}, {"input": "18 18\n71 71\n", "output": "1278\n"}, {"input": "46 71\n16 49\n", "output": "209\n"}, {"input": "70 11\n74 27\n", "output": "2321\n"}, {"input": "94 55\n20 96\n", "output": "-1\n"}, {"input": "18 4\n77 78\n", "output": "1156\n"}, {"input": "46 44\n23 55\n", "output": "-1\n"}, {"input": "74 88\n77 37\n", "output": "1346\n"}, {"input": "94 37\n34 7\n", "output": "789\n"}, {"input": "22 81\n80 88\n", "output": "-1\n"}, {"input": "46 30\n34 62\n", "output": "674\n"}, {"input": "40 4\n81 40\n", "output": "364\n"}, {"input": "69 48\n39 9\n", "output": "48\n"}, {"input": "89 93\n84 87\n", "output": "5967\n"}, {"input": "17 45\n42 65\n", "output": "317\n"}, {"input": "41 85\n95 46\n", "output": "331\n"}, {"input": "69 30\n41 16\n", "output": "1410\n"}, {"input": "93 74\n99 93\n", "output": "-1\n"}, {"input": "17 19\n44 75\n", "output": "427\n"}, {"input": "45 63\n98 53\n", "output": "3483\n"}, {"input": "69 11\n48 34\n", "output": "-1\n"}, {"input": "55 94\n3 96\n", "output": "204\n"}, {"input": "100 100\n100 100\n", "output": "100\n"}, {"input": "1 1\n1 1\n", "output": "1\n"}, {"input": "1 1\n1 100\n", "output": "100\n"}, {"input": "1 100\n100 1\n", "output": "101\n"}, {"input": "98 1\n99 100\n", "output": "9703\n"}, {"input": "98 1\n99 2\n", "output": "9605\n"}, {"input": "97 2\n99 100\n", "output": "4852\n"}, {"input": "3 3\n3 1\n", "output": "-1\n"}, {"input": "3 2\n7 2\n", "output": "2\n"}, {"input": "2 3\n2 5\n", "output": "5\n"}, {"input": "2 3\n2 3\n", "output": "3\n"}, {"input": "100 3\n100 5\n", "output": "-1\n"}, {"input": "6 10\n12 14\n", "output": "-1\n"}, {"input": "4 2\n4 4\n", "output": "-1\n"}, {"input": "2 3\n2 2\n", "output": "-1\n"}, {"input": "2 3\n4 99\n", "output": "99\n"}, {"input": "1 5\n1 5\n", "output": "5\n"}, {"input": "1 100\n3 1\n", "output": "100\n"}, {"input": "2 2\n2 1\n", "output": "-1\n"}, {"input": "2 10\n6 20\n", "output": "20\n"}, {"input": "2 2\n2 10\n", "output": "10\n"}, {"input": "3 7\n3 6\n", "output": "-1\n"}, {"input": "1 100\n1 100\n", "output": "100\n"}, {"input": "7 25\n39 85\n", "output": "319\n"}, {"input": "84 82\n38 6\n", "output": "82\n"}, {"input": "7 7\n7 14\n", "output": "14\n"}]
335
Little C loves number Β«3Β» very much. He loves all things about it. Now he has a positive integer $n$. He wants to split $n$ into $3$ positive integers $a,b,c$, such that $a+b+c=n$ and none of the $3$ integers is a multiple of $3$. Help him to find a solution. -----Input----- A single line containing one integer $n$ ($3 \leq n \leq 10^9$) β€” the integer Little C has. -----Output----- Print $3$ positive integers $a,b,c$ in a single line, such that $a+b+c=n$ and none of them is a multiple of $3$. It can be proved that there is at least one solution. If there are multiple solutions, print any of them. -----Examples----- Input 3 Output 1 1 1 Input 233 Output 77 77 79
interview
[{"code": "import os\nimport sys\n\nn = int(sys.stdin.readline())\n\nif n % 3 != 2:\n sys.stdout.write(\"{0} {1} {2}\".format(1, 1, n - 2))\nelse:\n sys.stdout.write(\"{0} {1} {2}\".format(1, 2, n - 3))\n", "passed": true, "time": 0.15, "memory": 14276.0, "status": "done"}]
[{"input": "3\n", "output": "1 1 1"}, {"input": "233\n", "output": "1 2 230"}, {"input": "4\n", "output": "1 1 2"}, {"input": "5\n", "output": "1 2 2"}, {"input": "1234\n", "output": "1 1 1232"}, {"input": "387420489\n", "output": "1 1 387420487"}, {"input": "1000000000\n", "output": "1 1 999999998"}, {"input": "6\n", "output": "1 1 4"}, {"input": "7\n", "output": "1 1 5"}, {"input": "8\n", "output": "1 2 5"}, {"input": "701041167\n", "output": "1 1 701041165"}, {"input": "175744383\n", "output": "1 1 175744381"}, {"input": "60512989\n", "output": "1 1 60512987"}, {"input": "240248899\n", "output": "1 1 240248897"}, {"input": "125017505\n", "output": "1 2 125017502"}, {"input": "599720719\n", "output": "1 1 599720717"}, {"input": "484489325\n", "output": "1 2 484489322"}, {"input": "369257931\n", "output": "1 1 369257929"}, {"input": "548993841\n", "output": "1 1 548993839"}, {"input": "795065278\n", "output": "1 1 795065276"}, {"input": "679833884\n", "output": "1 2 679833881"}, {"input": "859569794\n", "output": "1 2 859569791"}, {"input": "39305706\n", "output": "1 1 39305704"}, {"input": "219041616\n", "output": "1 1 219041614"}, {"input": "103810222\n", "output": "1 1 103810220"}, {"input": "988578826\n", "output": "1 1 988578824"}, {"input": "463282042\n", "output": "1 1 463282040"}, {"input": "348050648\n", "output": "1 2 348050645"}, {"input": "527786558\n", "output": "1 2 527786555"}, {"input": "929415834\n", "output": "1 1 929415832"}, {"input": "814184441\n", "output": "1 2 814184438"}, {"input": "288887657\n", "output": "1 2 288887654"}, {"input": "173656263\n", "output": "1 1 173656261"}, {"input": "353392173\n", "output": "1 1 353392171"}, {"input": "238160779\n", "output": "1 1 238160777"}, {"input": "417896689\n", "output": "1 1 417896687"}, {"input": "597632599\n", "output": "1 1 597632597"}, {"input": "482401205\n", "output": "1 2 482401202"}, {"input": "662137115\n", "output": "1 2 662137112"}, {"input": "762246473\n", "output": "1 2 762246470"}, {"input": "10\n", "output": "1 1 8"}, {"input": "9\n", "output": "1 1 7"}, {"input": "25\n", "output": "1 1 23"}, {"input": "11\n", "output": "1 2 8"}, {"input": "18\n", "output": "1 1 16"}, {"input": "101\n", "output": "1 2 98"}, {"input": "16\n", "output": "1 1 14"}, {"input": "19\n", "output": "1 1 17"}, {"input": "13\n", "output": "1 1 11"}, {"input": "433637687\n", "output": "1 2 433637684"}, {"input": "997\n", "output": "1 1 995"}, {"input": "14\n", "output": "1 2 11"}, {"input": "12\n", "output": "1 1 10"}, {"input": "21\n", "output": "1 1 19"}, {"input": "999999998\n", "output": "1 2 999999995"}, {"input": "34\n", "output": "1 1 32"}, {"input": "20\n", "output": "1 2 17"}, {"input": "22\n", "output": "1 1 20"}]
336
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. The painting is a square 3 Γ— 3, each cell contains a single integer from 1 to n, and different cells may contain either different or equal integers. The sum of integers in each of four squares 2 Γ— 2 is equal to the sum of integers in the top left square 2 Γ— 2. Four elements a, b, c and d are known and are located as shown on the picture below. $\left. \begin{array}{|c|c|c|} \hline ? & {a} & {?} \\ \hline b & {?} & {c} \\ \hline ? & {d} & {?} \\ \hline \end{array} \right.$ Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong. Two squares are considered to be different, if there exists a cell that contains two different integers in different squares. -----Input----- The first line of the input contains five integers n, a, b, c and d (1 ≀ n ≀ 100 000, 1 ≀ a, b, c, d ≀ n)Β β€” maximum possible value of an integer in the cell and four integers that Vasya remembers. -----Output----- Print one integerΒ β€” the number of distinct valid squares. -----Examples----- Input 2 1 1 1 2 Output 2 Input 3 3 1 2 3 Output 6 -----Note----- Below are all the possible paintings for the first sample. $\left. \begin{array}{|l|l|l|} \hline 2 & {1} & {2} \\ \hline 1 & {1} & {1} \\ \hline 1 & {2} & {1} \\ \hline \end{array} \right.$ $\left. \begin{array}{|l|l|l|} \hline 2 & {1} & {2} \\ \hline 1 & {2} & {1} \\ \hline 1 & {2} & {1} \\ \hline \end{array} \right.$ In the second sample, only paintings displayed below satisfy all the rules. $\left. \begin{array}{|c|c|c|} \hline 2 & {3} & {1} \\ \hline 1 & {1} & {2} \\ \hline 2 & {3} & {1} \\ \hline \end{array} \right.$ $\left. \begin{array}{|c|c|c|} \hline 2 & {3} & {1} \\ \hline 1 & {2} & {2} \\ \hline 2 & {3} & {1} \\ \hline \end{array} \right.$ $\left. \begin{array}{|l|l|l|} \hline 2 & {3} & {1} \\ \hline 1 & {3} & {2} \\ \hline 2 & {3} & {1} \\ \hline \end{array} \right.$ $\left. \begin{array}{|c|c|c|} \hline 3 & {3} & {2} \\ \hline 1 & {1} & {2} \\ \hline 3 & {3} & {2} \\ \hline \end{array} \right.$ $\left. \begin{array}{|c|c|c|} \hline 3 & {3} & {2} \\ \hline 1 & {2} & {2} \\ \hline 3 & {3} & {2} \\ \hline \end{array} \right.$ $\left. \begin{array}{|c|c|c|} \hline 3 & {3} & {2} \\ \hline 1 & {3} & {2} \\ \hline 3 & {3} & {2} \\ \hline \end{array} \right.$
interview
[{"code": "n, a, b, c, d= [int(i) for i in input().split()]\no = 0\nfor i in range(1, n+1):\n\tif i+b-c>0 and i+b-c<=n:\n\t\tif i+a-d>0 and i+a-d<=n:\n\t\t\tif i+a+b-c-d>0 and i+a+b-c-d<=n:\n\t\t\t\to+=1\nprint(o*n)\n", "passed": true, "time": 1.06, "memory": 14396.0, "status": "done"}, {"code": "n, a, b, c, d = map(int, input().split())\nans = 0\nfor i in range(1, n + 1):\n\tx = i + b - c\n\ty = i + a + b - c - d\n\tz = i + a - d\n\tans += n * (1 <= x <= n and 1 <= y <= n and 1 <= z <= n)\nprint(ans)", "passed": true, "time": 1.14, "memory": 14492.0, "status": "done"}, {"code": "n,a,b,c,d=[int(x) for x in input().split()]\npossib=0\nfor x in range(1,n+1):\n if 1<=(a+b+x-c-d)<=n and 1<=(b+x-c)<=n and 1<=(a+x-d)<=n:\n possib+=1\nprint(possib*n)\n", "passed": true, "time": 0.75, "memory": 14536.0, "status": "done"}, {"code": "n, a, b, c, d = list(map(int, input().split()))\nans = 0\nfor x1 in range(1, n + 1):\n x2 = x1 + b - c\n x4 = a + x1 - d\n x5 = b + x4 - c\n if 1 <= x2 <= n and 1 <= x4 <= n and 1 <= x5 <= n:\n ans += 1\nprint(ans * n)\n \n", "passed": true, "time": 2.26, "memory": 14316.0, "status": "done"}, {"code": "n, a, b, c, d = list(map(int, input().split()))\nl = max(1 - b + c, 1 - a + d, 1 - a - b + c + d)\nh = min(n - b + c, n - a + d, n - a - b + c + d)\nif (l < 0):\n l = 1\nif (h > n):\n h = n\nif h < l:\n print(0)\nelse:\n print(n * (h - l + 1))\n", "passed": true, "time": 0.33, "memory": 14244.0, "status": "done"}, {"code": "n,a,b,c,d = list(map(int, input().split()))\nnum = 0\ni = 0\nwhile n > i:\n i += 1\n if i + b - c < 1 or i + b - c > n:\n continue\n if i + a - d < 1 or i + a - d > n:\n continue\n if i + a - d + b - c < 1 or i + a - d + b - c > n:\n continue\n num += 1\nprint(num * n)\n", "passed": true, "time": 2.44, "memory": 14532.0, "status": "done"}, {"code": "n, a, b, c, d = list(map(int, input().split()))\nans = 0\nfor i in range(1, n + 1):\n s = i + a + b\n x2 = s - a - c\n x3 = s - c - d\n x4 = s - b - d\n if max(x2, x3, x4) <= n and min(x2, x3, x4) >= 1:\n ans += n\nprint(ans)\n", "passed": true, "time": 1.8, "memory": 14388.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\ndef main():\n n, a, b, c, d = [int(x) for x in input().split()]\n cnt = 0\n for x in range(1, n + 1):\n z1 = x + b - c\n z2 = x + a + b - d - c\n z3 = x + a - d\n\n if all(1 <= xx <= n for xx in (z1, z2, z3)):\n cnt += n\n\n print(cnt)\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 2.46, "memory": 14432.0, "status": "done"}, {"code": "n,a,b,c,d=map(int,input().split())\nq={}\nfor x1 in range(1,n+1):\n x4=a+x1-d\n if x4<1 or x4>n: continue\n x2=x1+b-c\n if x2<1 or x2>n: continue\n x5=x2+a-d\n if x5<1 or x5>n: continue\n q[(x1,x2,x4,x5)]=1\nprint(len(q)*n)", "passed": true, "time": 0.91, "memory": 43920.0, "status": "done"}, {"code": "n, a, b, c, d = list(map(int, input().split()))\narr = [0] * 4\narr[0] = a + b\narr[1] = a + c\narr[2] = c + d\narr[3] = b + d\narr.sort()\nif n + arr[0] - arr[3] >= 0:\n print(n * (n + arr[0] - arr[3]))\nelse:\n print(0)\n", "passed": true, "time": 0.16, "memory": 14264.0, "status": "done"}, {"code": "n, a, b, c, d = map(int, input().split())\nans = 0\nfor e in range(1, n + 1):\n min1 = a + b + e + 1\n max1 = a + b + e + n\n min2 = b + e + d + 1\n max2 = b + d + e + n\n min3 = d + c + e + 1\n max3 = d + c + e + n\n min4 = a + c + e + 1\n max4 = a + c + e + n\n l = max(min1, min2, min3, min4)\n r = min(max1, max2, max3, max4)\n if l <= r:\n ans += r - l + 1\nprint(ans)", "passed": true, "time": 3.44, "memory": 14516.0, "status": "done"}, {"code": "n, a, b, c, d = map(int, input().split())\n\nans = 0\nfor i in range(1, n+1) :\n s = a+b+i\n j = s - a - c\n k = s - b - d\n l = s - c - d\n if 1 <= j <=n and 1<= k <= n and 1<= l <= n :\n ans += n\n\nprint(ans)", "passed": true, "time": 0.99, "memory": 14252.0, "status": "done"}, {"code": "n, a, b, c, d = list(map(int, input().split()))\nlst = [a+b, a+c, c+d, b+d]\nif (n-(max(lst)-min(lst))) <=0:\n print(0)\nelse:\n print((n-(max(lst)-min(lst)))*n)\n\n", "passed": true, "time": 0.18, "memory": 14436.0, "status": "done"}, {"code": "n, a, b, c, d = map(int, input().split())\n\nans = 0\n\nfor x1 in range(1, n+1):\n\tx2 = x1+b-c\n\tif x2 < 1 or x2 > n:\n\t\tcontinue\n\tx4 = x1+a-d\n\tif x4 < 1 or x4 > n:\n\t\tcontinue\n\tx5 = x1+a+b-c-d\n\tif x5 < 1 or x5 > n:\n\t\tcontinue\n\n\tans += 1\n\nprint(ans*n)", "passed": true, "time": 0.75, "memory": 14348.0, "status": "done"}, {"code": "def solve(n,a,b,c,d):\n ans = 0\n sums = [a+b, b+d, d+c, c+a]\n minsum = min(sums)\n maxsum = max(sums)\n tmp = minsum + n\n if (tmp <= maxsum):\n return ans\n else:\n ans += n * (tmp - maxsum)\n return ans\n \n(n,a,b,c,d) = [int(x) for x in input().split()]\nprint(solve(n,a,b,c,d))", "passed": true, "time": 0.14, "memory": 14452.0, "status": "done"}, {"code": "n, a, b, c, d = list(map(int, input().split()))\nlo = min(a+b, a+c, c+d, b+d)\nhi = max(a+b, a+c, c+d, b+d)\nans = 0\nfor x in range(1, n+1):\n ans += max(0, n-(hi-lo))\nprint(ans)\n", "passed": true, "time": 1.53, "memory": 14452.0, "status": "done"}, {"code": "n, a, b, c, d = [int(s) for s in input().split()]\ndef solve(p):\n s = []\n s.append(p[0][0] + p[0][1] + p[1][0] + p[1][1])\n s.append(p[0][1] + p[0][2] + p[1][1] + p[1][2])\n s.append(p[1][0] + p[1][1] + p[2][0] + p[2][1])\n s.append(p[1][1] + p[1][2] + p[2][1] + p[2][2])\n return max(0, n - (max(s) - min(s)))\np = [\n [0, a, 0],\n [b, 0, c],\n [0, d, 0],\n]\nres = 0\nfor m in range(1, n + 1):\n p[1][1] = m\n res += solve(p)\nprint(res)\n", "passed": true, "time": 4.84, "memory": 14452.0, "status": "done"}, {"code": "# You lost the game.\nn,a,b,c,d = list(map(int, input().split()))\nr = 0\nfor e in range(1,n+1):\n h = e + (a-d)\n i = h + (b-c)\n f = i + (d-a)\n if e == f + (c-b) and h <= n and i <= n and f <= n and h > 0 and i > 0 and f > 0:\n r += 1\nprint(r*n)\n\n", "passed": true, "time": 0.95, "memory": 14308.0, "status": "done"}, {"code": "import sys\n\narr = list(map(int, input().strip().split()))\nn = arr[0]\ntop = arr[1]\nleft = arr[2]\nright = arr[3]\nbottom = arr[4]\n\ntop_left = top + left\ntop_right = top + right\nbottom_left = bottom + left\nbottom_right = bottom + right\n\nmax_greater = 0\nmax_lesser = 0\nnums = [top_right, bottom_left, bottom_right]\nfor e in nums:\n diff = e - top_left\n max_greater = max(max_greater, diff)\n max_lesser = min(max_lesser, diff)\nmax_diff = max_greater - max_lesser\n\nif max_diff > n - 1:\n ans = 0\nelse:\n ans = (n - max_diff) * n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "def f(n, r, p, q):\n if r < 1 or r > n: return 0\n if p < 1 or p > n: return 0\n if q < 1 or q > n: return 0\n return 1\n\nn, a, b, c, d = [int(i) for i in input().split()]\nbox = 0\nfor i in range(1, n + 1):\n r = i + b - c\n p = r + a - d\n q = p + c - b\n box += f(n, r, p, q)\n '''\n for j in range(1, n + 1):\n print(i, a, r)\n print(b, j, c)\n print(q, d, p)\n print()\n '''\nbox *= n\nprint(box)\n \n", "passed": true, "time": 1.04, "memory": 14248.0, "status": "done"}, {"code": "\ndef __starting_point():\n #n, m = list(map(int, input().split()))\n n, a, b, c, d = list(map(int, input().split()))\n x = max([1 - a + d, 1 - b + c, 1, 1 - a - b + d + c])\n y = min([n - a + d, n - b + c, n, n - a - b + d + c])\n #print(x, y)\n if x > y:\n print(0)\n return\n else:\n print(n *(y - x + 1))\n \n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14496.0, "status": "done"}, {"code": "n, a, b, c, d = map(int, input().split())\n\nmin_sum = max(a + b, a + c, b + d, c + d) + 1\nmax_sum = min(a + b, a + c, b + d, c + d) + n\n\nprint(max((max_sum - min_sum + 1) * n, 0))", "passed": true, "time": 0.14, "memory": 14488.0, "status": "done"}, {"code": "import sys\n\nn, a, b, c, d = list(map(int,sys.stdin.readline().split()))\n\nc1 = 0\nfor x11 in range(n):\n x13 = x11 + 1 - c + b\n x31 = x11 + 1 - d + a\n x33 = x11 + 1 - c - d + a + b\n #print (x11 + 1, x13, x31, x33)\n if x13 >= 1 and x13 <= n and x31 >= 1 and x31 <= n and x33 >= 1 and x33 <= n:\n c1 = c1 + 1\nprint(c1 * n)\n", "passed": true, "time": 1.19, "memory": 14392.0, "status": "done"}, {"code": "n, a, b, c, d = map(int, input().split())\nans = 0\nfor i in range(1, n + 1):\n if c + d + 1 <= a + b + i <= c + d + n and a + c + 1 <= a + b + i <= a + c + n and b + d + 1 <= a + b + i <= b + d + n:\n ans += n\nprint(ans)", "passed": true, "time": 0.98, "memory": 14388.0, "status": "done"}, {"code": "n, a, b, c, d = list(map(int, input().split(' ')))\nprint(max(0, n*(n-max([a+b, a+c, c+d, b+d])+min([a+b, a+c, c+d, b+d]))))\n", "passed": true, "time": 0.14, "memory": 14268.0, "status": "done"}]
[{"input": "2 1 1 1 2\n", "output": "2\n"}, {"input": "3 3 1 2 3\n", "output": "6\n"}, {"input": "1 1 1 1 1\n", "output": "1\n"}, {"input": "1000 522 575 426 445\n", "output": "774000\n"}, {"input": "99000 52853 14347 64237 88869\n", "output": "1296306000\n"}, {"input": "100000 2 2 2 2\n", "output": "10000000000\n"}, {"input": "2 1 1 2 2\n", "output": "0\n"}, {"input": "10 9 10 8 10\n", "output": "70\n"}, {"input": "100 19 16 35 83\n", "output": "1700\n"}, {"input": "1000 102 583 606 929\n", "output": "150000\n"}, {"input": "10000 1816 3333 6908 7766\n", "output": "4750000\n"}, {"input": "100000 80015 84290 50777 30497\n", "output": "1696900000\n"}, {"input": "100000 64022 49026 55956 88430\n", "output": "6866200000\n"}, {"input": "100000 10263 46628 10268 22948\n", "output": "5095500000\n"}, {"input": "100000 81311 81584 51625 57276\n", "output": "4600600000\n"}, {"input": "100000 77594 3226 21255 8541\n", "output": "1291800000\n"}, {"input": "100000 65131 35523 58220 87645\n", "output": "5478900000\n"}, {"input": "100000 83958 32567 91083 95317\n", "output": "3012500000\n"}, {"input": "100000 36851 54432 21164 85520\n", "output": "1806300000\n"}, {"input": "100000 55732 17473 23832 75148\n", "output": "7422500000\n"}, {"input": "100000 60789 25296 49585 25237\n", "output": "4015900000\n"}, {"input": "100000 92060 77234 58709 36956\n", "output": "2637100000\n"}, {"input": "100000 87223 66046 27153 40823\n", "output": "1470700000\n"}, {"input": "100000 3809 35468 34556 51158\n", "output": "5173900000\n"}, {"input": "100000 35038 37363 95275 88903\n", "output": "0\n"}, {"input": "100000 45274 9250 36558 49486\n", "output": "6848000000\n"}, {"input": "100000 1 1 1 1\n", "output": "10000000000\n"}, {"input": "100000 1 1 1 100000\n", "output": "100000\n"}, {"input": "100000 1 1 100000 1\n", "output": "100000\n"}, {"input": "100000 1 1 100000 100000\n", "output": "0\n"}, {"input": "100000 1 100000 1 1\n", "output": "100000\n"}, {"input": "100000 1 100000 1 100000\n", "output": "0\n"}, {"input": "100000 1 100000 100000 1\n", "output": "10000000000\n"}, {"input": "100000 1 100000 100000 100000\n", "output": "100000\n"}, {"input": "100000 100000 1 1 1\n", "output": "100000\n"}, {"input": "100000 100000 1 1 100000\n", "output": "10000000000\n"}, {"input": "100000 100000 1 100000 1\n", "output": "0\n"}, {"input": "100000 100000 1 100000 100000\n", "output": "100000\n"}, {"input": "100000 100000 100000 1 1\n", "output": "0\n"}, {"input": "100000 100000 100000 1 100000\n", "output": "100000\n"}, {"input": "100000 100000 100000 100000 1\n", "output": "100000\n"}, {"input": "100000 100000 100000 100000 100000\n", "output": "10000000000\n"}, {"input": "3 3 3 1 1\n", "output": "0\n"}, {"input": "10 1 2 5 10\n", "output": "0\n"}, {"input": "5 1 1 5 5\n", "output": "0\n"}, {"input": "4 4 4 1 1\n", "output": "0\n"}, {"input": "10 10 10 1 1\n", "output": "0\n"}, {"input": "5 5 5 1 1\n", "output": "0\n"}, {"input": "100 100 100 1 1\n", "output": "0\n"}, {"input": "3 1 1 3 3\n", "output": "0\n"}, {"input": "10 2 10 1 10\n", "output": "0\n"}, {"input": "7 7 7 1 1\n", "output": "0\n"}, {"input": "5 5 3 4 1\n", "output": "0\n"}, {"input": "7 1 1 7 7\n", "output": "0\n"}, {"input": "100 1 1 100 100\n", "output": "0\n"}, {"input": "123 1 2 3 100\n", "output": "2829\n"}, {"input": "10 1 1 10 10\n", "output": "0\n"}, {"input": "803 525 6 623 8\n", "output": "0\n"}]
338
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to m points. We know that c_1 schoolchildren got 1 point, c_2 children got 2 points, ..., c_{m} children got m points. Now you need to set the passing rate k (integer from 1 to m): all schoolchildren who got less than k points go to the beginner group and those who get at strictly least k points go to the intermediate group. We know that if the size of a group is more than y, then the university won't find a room for them. We also know that if a group has less than x schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from x to y, inclusive. Help the university pick the passing rate in a way that meets these requirements. -----Input----- The first line contains integer m (2 ≀ m ≀ 100). The second line contains m integers c_1, c_2, ..., c_{m}, separated by single spaces (0 ≀ c_{i} ≀ 100). The third line contains two space-separated integers x and y (1 ≀ x ≀ y ≀ 10000). At least one c_{i} is greater than 0. -----Output----- If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least x and at most y, print 0. Otherwise, print an integer from 1 to m β€” the passing rate you'd like to suggest. If there are multiple possible answers, print any of them. -----Examples----- Input 5 3 4 3 2 1 6 8 Output 3 Input 5 0 3 3 4 2 3 10 Output 4 Input 2 2 5 3 6 Output 0 -----Note----- In the first sample the beginner group has 7 students, the intermediate group has 6 of them. In the second sample another correct answer is 3.
interview
[{"code": "m = int(input())\nc = list(map(int,input().split()))\nx, y = list(map(int,input().split()))\n\nfor i in range(m):\n\tsb = sum(c[:-i-1])\n\tsi = sum(c[-i-1:])\n\tif x <= sb <= y:\n\t\tif x <= si <= y:\n\t\t\tprint(m-i)\n\t\t\tbreak\nelse:\n\tprint(0)\n", "passed": true, "time": 0.14, "memory": 14316.0, "status": "done"}, {"code": "maximum = input()\nm_int = list(map(int,input().split()))\nsize = list(map(int,input().split()))\nx = size[0]\ny = size[1]\n\nbeginner = []\nintermediate = []\nfor i in range(len(m_int)):\n beginner.append(m_int[i])\n if sum(beginner) > y or sum(m_int[i+1:]) < x:\n del beginner[-1]\n break\n \n\nfor j in range(len(beginner),len(m_int)):\n intermediate.append(m_int[j])\n\nif (sum(intermediate) < x or sum(intermediate) > y) or (sum(beginner) < x or sum(beginner) > y):\n passing_rate = 0\nelse:\n passing_rate = i+1\nprint(passing_rate)\n", "passed": true, "time": 0.14, "memory": 14320.0, "status": "done"}]
[{"input": "5\n3 4 3 2 1\n6 8\n", "output": "3\n"}, {"input": "5\n0 3 3 4 2\n3 10\n", "output": "4\n"}, {"input": "2\n2 5\n3 6\n", "output": "0\n"}, {"input": "3\n0 1 0\n2 10\n", "output": "0\n"}, {"input": "5\n2 2 2 2 2\n5 5\n", "output": "0\n"}, {"input": "10\n1 1 1 1 1 1 1 1 1 1\n1 10\n", "output": "10\n"}, {"input": "10\n1 1 1 1 1 1 1 1 1 1\n5 5\n", "output": "6\n"}, {"input": "6\n0 0 1 1 0 0\n1 6\n", "output": "4\n"}, {"input": "7\n3 2 3 3 2 1 1\n5 10\n", "output": "4\n"}, {"input": "4\n1 0 0 100\n1 100\n", "output": "4\n"}, {"input": "100\n46 6 71 27 94 59 99 82 5 41 18 89 86 2 31 35 52 18 1 14 54 11 28 83 42 15 13 77 22 70 87 65 79 35 44 71 79 9 95 57 5 59 42 62 66 26 33 66 67 45 39 17 97 28 36 100 52 23 68 29 83 6 61 85 71 2 85 98 85 65 95 53 35 96 29 28 82 80 52 60 61 46 46 80 11 3 35 6 12 10 64 7 7 7 65 93 58 85 20 12\n2422 2429\n", "output": "52\n"}, {"input": "10\n3 6 1 5 3 7 0 1 0 8\n16 18\n", "output": "6\n"}, {"input": "10\n3 3 0 4 0 5 2 10 7 0\n10 24\n", "output": "8\n"}, {"input": "10\n9 4 7 7 1 3 7 3 8 5\n23 31\n", "output": "7\n"}, {"input": "10\n9 6 9 5 5 4 3 3 9 10\n9 54\n", "output": "10\n"}, {"input": "10\n2 4 8 5 2 2 2 5 6 2\n14 24\n", "output": "7\n"}, {"input": "10\n10 58 86 17 61 12 75 93 37 30\n10 469\n", "output": "10\n"}, {"input": "10\n56 36 0 28 68 54 34 48 28 92\n92 352\n", "output": "10\n"}, {"input": "10\n2 81 94 40 74 62 39 70 87 86\n217 418\n", "output": "8\n"}, {"input": "10\n48 93 9 96 70 14 100 93 44 79\n150 496\n", "output": "8\n"}, {"input": "10\n94 85 4 9 30 45 90 76 0 65\n183 315\n", "output": "7\n"}, {"input": "100\n1 0 7 9 0 4 3 10 9 4 9 7 4 4 7 7 6 1 3 3 8 1 4 3 5 8 0 0 6 2 3 5 0 1 5 8 6 3 2 4 9 5 8 6 0 2 5 1 9 5 9 0 6 0 4 5 9 7 1 4 7 5 4 5 6 8 2 3 3 2 8 2 9 5 9 2 4 7 7 8 10 1 3 0 8 0 9 1 1 7 7 8 9 3 5 9 9 8 0 8\n200 279\n", "output": "63\n"}, {"input": "100\n5 4 9 7 8 10 7 8 10 0 10 9 7 1 0 7 8 5 5 8 7 7 7 2 5 8 0 7 5 7 1 7 6 5 4 10 6 1 4 4 8 7 0 3 2 10 8 6 1 3 2 6 8 1 9 3 9 5 2 0 3 6 7 5 10 0 2 8 3 10 1 3 8 8 0 2 10 3 4 4 0 7 4 0 9 7 10 2 7 10 9 9 6 6 8 1 10 1 2 0\n52 477\n", "output": "91\n"}, {"input": "100\n5 1 6 6 5 4 5 8 0 2 10 1 10 0 6 6 0 1 5 7 10 5 8 4 4 5 10 4 10 3 0 10 10 1 2 6 2 6 3 9 4 4 5 5 7 7 7 4 3 2 1 4 5 0 2 1 8 5 4 5 10 7 0 3 5 4 10 4 10 7 10 1 8 3 9 8 6 9 5 7 3 4 7 8 4 0 3 4 4 1 6 6 2 0 1 5 3 3 9 10\n22 470\n", "output": "98\n"}, {"input": "100\n73 75 17 93 35 7 71 88 11 58 78 33 7 38 14 83 30 25 75 23 60 10 100 7 90 51 82 0 78 54 61 32 20 90 54 45 100 62 40 99 43 86 87 64 10 41 29 51 38 22 5 63 10 64 90 20 100 33 95 72 40 82 92 30 38 3 71 85 99 66 4 26 33 41 85 14 26 61 21 96 29 40 25 14 48 4 30 44 6 41 71 71 4 66 13 50 30 78 64 36\n2069 2800\n", "output": "57\n"}, {"input": "100\n86 19 100 37 9 49 97 9 70 51 14 31 47 53 76 65 10 40 4 92 2 79 22 70 85 58 73 96 89 91 41 88 70 31 53 33 22 51 10 56 90 39 70 38 86 15 94 63 82 19 7 65 22 83 83 71 53 6 95 89 53 41 95 11 32 0 7 84 39 11 37 73 20 46 18 28 72 23 17 78 37 49 43 62 60 45 30 69 38 41 71 43 47 80 64 40 77 99 36 63\n1348 3780\n", "output": "74\n"}, {"input": "100\n65 64 26 48 16 90 68 32 95 11 27 29 87 46 61 35 24 99 34 17 79 79 11 66 14 75 31 47 43 61 100 32 75 5 76 11 46 74 81 81 1 25 87 45 16 57 24 76 58 37 42 0 46 23 75 66 75 11 50 5 10 11 43 26 38 42 88 15 70 57 2 74 7 72 52 8 72 19 37 38 66 24 51 42 40 98 19 25 37 7 4 92 47 72 26 76 66 88 53 79\n1687 2986\n", "output": "65\n"}, {"input": "100\n78 43 41 93 12 76 62 54 85 5 42 61 93 37 22 6 50 80 63 53 66 47 0 60 43 93 90 8 97 64 80 22 23 47 30 100 80 75 84 95 35 69 36 20 58 99 78 88 1 100 10 69 57 77 68 61 62 85 4 45 24 4 24 74 65 73 91 47 100 35 25 53 27 66 62 55 38 83 56 20 62 10 71 90 41 5 75 83 36 75 15 97 79 52 88 32 55 42 59 39\n873 4637\n", "output": "85\n"}, {"input": "100\n12 25 47 84 72 40 85 37 8 92 85 90 12 7 45 14 98 62 31 62 10 89 37 65 77 29 5 3 21 21 10 98 44 37 37 37 50 15 69 27 19 99 98 91 63 42 32 68 77 88 78 35 13 44 4 82 42 76 28 50 65 64 88 46 94 37 40 7 10 58 21 31 17 91 75 86 3 9 9 14 72 20 40 57 11 75 91 48 79 66 53 24 93 16 58 4 10 89 75 51\n666 4149\n", "output": "88\n"}, {"input": "10\n8 0 2 2 5 1 3 5 2 2\n13 17\n", "output": "6\n"}, {"input": "10\n10 4 4 6 2 2 0 5 3 7\n19 24\n", "output": "5\n"}, {"input": "10\n96 19 75 32 94 16 81 2 93 58\n250 316\n", "output": "6\n"}, {"input": "10\n75 65 68 43 89 57 7 58 51 85\n258 340\n", "output": "6\n"}, {"input": "100\n59 51 86 38 90 10 36 3 97 35 32 20 25 96 49 39 66 44 64 50 97 68 50 79 3 33 72 96 32 74 67 9 17 77 67 15 1 100 99 81 18 1 15 36 7 34 30 78 10 97 7 19 87 47 62 61 40 29 1 34 6 77 76 21 66 11 65 96 82 54 49 65 56 90 29 75 48 77 48 53 91 21 98 26 80 44 57 97 11 78 98 45 40 88 27 27 47 5 26 6\n2479 2517\n", "output": "53\n"}, {"input": "100\n5 11 92 53 49 42 15 86 31 10 30 49 21 66 14 13 80 25 21 25 86 20 86 83 36 81 21 23 0 30 64 85 15 33 74 96 83 51 84 4 35 65 10 7 11 11 41 80 51 51 74 52 43 83 88 38 77 20 14 40 37 25 27 93 27 77 48 56 93 65 79 33 91 14 9 95 13 36 24 2 66 31 56 28 49 58 74 17 88 36 46 73 54 18 63 22 2 41 8 50\n2229 2279\n", "output": "52\n"}, {"input": "2\n0 1\n1 1\n", "output": "0\n"}, {"input": "4\n1 0 0 4\n1 3\n", "output": "0\n"}, {"input": "4\n1 0 0 0\n1 10\n", "output": "0\n"}, {"input": "3\n2 1 4\n3 3\n", "output": "0\n"}, {"input": "5\n2 0 2 0 0\n2 2\n", "output": "3\n"}, {"input": "4\n1 2 3 4\n1 7\n", "output": "4\n"}, {"input": "2\n7 1\n1 6\n", "output": "0\n"}, {"input": "5\n1 3 7 8 9\n4 6\n", "output": "0\n"}, {"input": "2\n5 2\n5 6\n", "output": "0\n"}, {"input": "2\n1 0\n1 2\n", "output": "0\n"}, {"input": "4\n2 3 9 10\n5 14\n", "output": "4\n"}, {"input": "3\n1 2 1\n1 1\n", "output": "0\n"}, {"input": "4\n2 3 9 50\n5 30\n", "output": "0\n"}, {"input": "3\n7 1 1\n6 8\n", "output": "0\n"}, {"input": "6\n1 1 2 3 4 5\n3 9\n", "output": "5\n"}, {"input": "3\n4 5 5\n4 9\n", "output": "3\n"}, {"input": "6\n1 2 3 4 5 6\n1 3\n", "output": "0\n"}, {"input": "5\n3 4 3 2 10\n6 8\n", "output": "0\n"}, {"input": "5\n1 1 3 4 6\n2 2\n", "output": "0\n"}, {"input": "5\n5 3 5 8 10\n2 20\n", "output": "4\n"}, {"input": "4\n0 0 5 0\n3 6\n", "output": "0\n"}, {"input": "8\n1 1 1 1 2 2 2 1\n3 7\n", "output": "6\n"}, {"input": "3\n1 100 100\n101 200\n", "output": "0\n"}]
339
Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1? -----Input----- The first line contains a single integer n (1 ≀ n ≀ 2Β·10^9). The second line contains a single integer k (1 ≀ k ≀ 2Β·10^9). The third line contains a single integer A (1 ≀ A ≀ 2Β·10^9). The fourth line contains a single integer B (1 ≀ B ≀ 2Β·10^9). -----Output----- Output a single integerΒ β€” the minimum amount of coins you have to pay to make x equal to 1. -----Examples----- Input 9 2 3 1 Output 6 Input 5 5 2 20 Output 8 Input 19 3 4 2 Output 12 -----Note----- In the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 β†’ 8) paying 3 coins. Divide x by 2 (8 β†’ 4) paying 1 coin. Divide x by 2 (4 β†’ 2) paying 1 coin. Divide x by 2 (2 β†’ 1) paying 1 coin. The total cost is 6 coins. In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total.
interview
[{"code": "import sys\n\ndef read_int():\n return int(input())\n\ndef read_ints():\n return [int(x) for x in input().split()]\n\nn = read_int()\nk = read_int()\na = read_int()\nb = read_int()\n\ncost = 0\n\nif k == 1:\n cost = (n - 1) * a\nelse:\n while n != 1:\n if n % k == 0:\n if b < (n - n // k) * a:\n cost += b\n else:\n cost += (n - n // k) * a\n n = n // k\n else:\n cost += (n % k) * a\n n -= n % k\n if n == 0:\n n += 1\n cost -= a\n\nprint(cost)\n", "passed": true, "time": 0.18, "memory": 14304.0, "status": "done"}, {"code": "x = int(input())\nk = int(input())\na = int(input())\nb = int(input())\n\nc = 0\n\nwhile x > 1:\n\tif x % k > 0:\n\t\tif x > k:\t\t\t\n\t\t\tc += a * (x % k)\n\t\t\tx -= x % k\n\t\telse:\t\n\t\t\tc += a * (x % k - 1)\n\t\t\tx = 1\n\n\telse:\n\t\tif (x-x//k)*a >= b:\n\t\t\tc += b\n\t\t\tx = x//k\n\t\telse:\n\t\t\tc += (x-1)*a\n\t\t\tx = 1\n\nprint(c)\n", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nA = int(input())\nB = int(input())\ncoins = 0\nwhile (n!=1):\n\tif(n%k == 0 and ((n-n/k)*A) > B):\n\t\tcoins += B\n\t\tn/=k\n\telif (n%k == 0):\n\t\tcoins += A*(n-1)\n\t\tn = 1\n\telse:\n\t\tcoins += A*(n%k)\n\t\tn = n - (n%k)\nprint(int(coins))\n", "passed": true, "time": 0.86, "memory": 14456.0, "status": "done"}, {"code": "number = int(input())\ndivisor = int(input())\ndecrement_cost = int(input())\ndivision_cost = int(input())\n\nfinal_cost = 0\nwhile number != 1:\n\tremainder = number % divisor\n\tif remainder != 0:\n\t\tfinal_cost += decrement_cost * remainder\n\t\tnumber -= remainder\n\n\tjump = number - number // divisor\n\n\tif division_cost < jump * decrement_cost:\n\t\tfinal_cost += division_cost\n\t\tnumber //= divisor\n\telse:\n\t\tfinal_cost += decrement_cost * (number - 1)\n\t\tnumber = 1\n\nprint(final_cost)", "passed": true, "time": 0.16, "memory": 14436.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\na = int(input())\nb = int(input())\nc = 0\nwhile(n>1):\n if(n<k):\n c += a*(n - 1)\n n = 1\n else:\n if(n%k!=0):\n t = n%k\n n -= t\n c += t*a\n else:\n if(b<(n-n//k)*a):\n n = n//k\n c += b\n else:\n c += a*(n - 1)\n n = 1\nprint(c)\n", "passed": true, "time": 0.18, "memory": 14496.0, "status": "done"}, {"code": "def solve(n, k, A, B):\n if k == 1:\n return A*(n-1)\n res = 0\n while n >= k:\n res += A * (n % k)\n n -= n % k\n diff = n-n//k\n if A*diff > B:\n res += B\n n //= k\n else:\n res += A*(n-1)\n n = 1 # finish loop\n res += A*(n-1)\n return res\n\nn, k, A, B = [int(input()) for i in range(4)]\nprint(solve(n, k, A, B))", "passed": true, "time": 0.23, "memory": 14304.0, "status": "done"}, {"code": "n = int(input());\nk = int(input());\na = int(input());\nb = int(input());\n#inf = 100000000000000000000000000000;\nost = 0;\nres = 0;\nwhile a * (n // k) + b + (n % k) * a < n * a:\n ost = ost + (n % k) * a;\n res = res + b;\n n = n // k;\n#print(n);\n#print(res);\n#print(ost);\nres = res + (n - 1) * a + ost;\nprint(res);", "passed": true, "time": 0.15, "memory": 14296.0, "status": "done"}, {"code": "n=int(input())\nk=int(input())\na=int(input())\nb=int(input())\nans=0\nif k==1:\n print((n-1)*a)\n return\nelse:\n while n>1:\n ans+=(n%k)*a\n n-=n%k\n if b>(n-n//k)*a:\n print((n-1)*a+ans)\n return\n else:\n n//=k\n ans+=b\nprint(ans)\n \n \n \n", "passed": true, "time": 0.15, "memory": 14296.0, "status": "done"}, {"code": "n=int(input())\nk=int(input())\na=int(input())\nb=int(input())\nx=n\nc=0\nif k==1:\n c=a*(n-1)\nelse:\n while x>=k:\n y=x%k\n c+=y*a\n x-=y\n c+=min(b,a*(x-x//k))\n x=(x//k)\n c+=a*(x-1)\nprint(c)", "passed": true, "time": 0.26, "memory": 14376.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nA = int(input())\nB = int(input())\n\nans = 0\nif k == 1:\n\tprint(A*(n-1))\n\treturn\n\nwhile n > 1:\n\tsubt = (n % k)\n\tans += A * subt\n\tn -= (n%k)\n\tans += min(A * (n - (n // k)),B)\n\tn //= k\n\nif n == 0:\n\tans -= A\n\nprint(ans)", "passed": true, "time": 0.14, "memory": 14240.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\na = int(input())\nb = int(input())\n\nr = 0\n\nif k == 1:\n print((n - 1) * a)\n return\n\nwhile n != 1:\n if n % k != 0:\n r += n % k * a\n n -= n % k\n elif n < k:\n r += (n - 1) * a\n n = 1\n else:\n if n // k * (k - 1) * a < b:\n r += n // k * (k - 1) * a\n else:\n r += b\n n //= k\nprint(r)\n", "passed": true, "time": 0.18, "memory": 14456.0, "status": "done"}, {"code": "n=int(input())\nk=int(input())\na=int(input())\nb=int(input())\nans=0\nif ((k==1)|(k>n))&(n!=1):\n ans=n*a-a\n n=1\nwhile (n!=1):\n if (n%k==0):\n t=n//k\n y=n-t\n if (y*a<=b):\n ans+=n*a-a\n n=1\n else:\n ans+=b\n n=t\n else:\n ans+=(n%k)*a\n n-=n%k\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14440.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\na = int(input())\nb = int(input())\nx = n\ncost = 0\n\nif k == 1:\n print(int((x - 1) * a))\n return\n\nwhile x > 1:\n if x < k:\n cost += (x - 1) * a\n break\n rem = x % k\n x -= rem\n cost += a * rem\n if rem == 0:\n temp = (x // k) * (k - 1)\n x //= k\n cost += min(temp * a, b)\n\nprint(cost)\n", "passed": true, "time": 0.15, "memory": 14360.0, "status": "done"}, {"code": "from sys import stdin as cin\n\ndef main():\n n = int(cin.readline())\n k = int(cin.readline())\n a = int(cin.readline())\n b = int(cin.readline())\n o = 0\n if k == 1:\n print((n - 1) * a)\n return\n while n > 1:\n if n % k:\n t = n - n // k * k\n if t == n:\n t -= 1\n o += a * t\n n -= t\n else:\n t = n // k\n o += min(a * (n - t), b)\n n = t\n #print(n, o)\n print(o)\n\nmain()\n", "passed": true, "time": 0.25, "memory": 14408.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nA = int(input())\nB = int(input())\n\nres = 0\nwhile n>k:\n if n % k >0:\n res += (n%k) * A\n n -= (n%k)\n\n dif = n - (n//k)\n if dif*A > B:\n res += B\n n = n//k\n else:\n res += (n-1)*A\n n = 1\n\nif n == k:\n dif = n - (n//k)\n if dif*A > B:\n res += B\n n = n//k\n else:\n res += (n-1)*A\n n = 1\n\nif n >1 :\n res += (n-1)*A\n n = 1\nprint(res)\n", "passed": true, "time": 0.14, "memory": 14520.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\na = int(input())\nb = int(input())\nans = 0\nif k > 1:\n while n > 1:\n new_n = max(1, n // k * k)\n ans += (n - new_n) * a\n n = new_n\n while n % k == 0:\n new_n = n // k\n ans += min((n - new_n) * a, b)\n n = new_n\nelse:\n ans = (n - 1) * a\nprint(ans)", "passed": true, "time": 0.25, "memory": 14312.0, "status": "done"}, {"code": "n, k, A, B = (int(input()) for i in range(4))\n\nif k == 1:\n print((n - 1) * A)\n\nelse:\n x = n\n ans = 0\n\n while x != 1:\n if 1 < x < k:\n ans += (x - 1) * A\n x = 1\n else:\n if x % k != 0:\n ans += (x - (x // k) * k) * A\n x = (x // k) * k\n\n else:\n d = x - (x // k)\n ans += min(d * A, B)\n x //= k\n\n print(ans)\n", "passed": true, "time": 0.14, "memory": 14348.0, "status": "done"}, {"code": "inf = 0x3f3f3f3f3f3f3f3f\nM = mod = 1000000007\nmod2inv = 500000004\npt = lambda *a, **k: print(*a, **k, flush=True)\nrd = lambda: map(int, input().split())\nn = int(input())\nk = int(input())\na = int(input())\nb = int(input())\nr = 0\nif k == 1:\n print((n - 1) * a)\n return\nwhile n:\n if n % k:\n r += n % k * a\n n -= n % k\n r += min(b, (n - n // k) * a)\n n //= k\npt(r - a)\n", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "\nn=int(input())\nk=int(input())\na=int(input())\nb=int(input())\nx=n\nc=0\n\nif k==1:\n\tprint(a*(n-1))\nelif k > x:\n\tprint(a*(x-1))\nelse:\n\twhile x>=k:\n\t\tif x%k==0:\n\t\t\ttemp=x/k\n\t\t\tif b < (x-(temp))*a:\n\t\t\t\tc+=b\n\t\t\t\tx=temp\n\t\t\telse:\n\t\t\t\tc+=a*(x-(temp))\n\t\t\t\tx=temp\n\t\telse:\n\t\t\tt=x%k\n\t\t\tc+=(a*t)\n\t\t\tx=x-t\n\tif x==1:\n\t\tprint(int(c))\n\telse:\n\t\tprint(int(c)+int((x-1)*a))\n", "passed": true, "time": 0.15, "memory": 14420.0, "status": "done"}, {"code": "n = int(input(\"\"))\nk = int(input(\"\"))\na = int(input(\"\"))\nb = int(input(\"\"))\n\nans = 0\nwhile not n == 1:\n\tm = n % k\n\tn = n - m\n\tans = ans + m*a\n\n\tif (n-(n/k))*a > b:\n\t\tn = n / k\n\t\tans = ans + b\n\telse:\n\t\tans = ans + (n-1)*a\n\t\tn = 1\nprint(int(ans)) \n\"\"\"\n\tint64 ans = 0;\n\twhile(n != 1){\n\t\tint64 m = n % k;\n\t\tn -= m;\n\t\t//cout << \"m \" << m << endl;\n\t\tans += m*a;\n\n\t\tif((n-(n/k))*a > b){\n\t\t\tn /= k;\n\t\t\tans += b;\n\t\t}else{\n\t\t\tans += (n-1)*a;\n\t\t\tcout << ans;\n\t\t\treturn 0;\n\t\t}\n\n\t}\t\n\t\n\tcout << ans;\n\"\"\"", "passed": true, "time": 0.23, "memory": 14388.0, "status": "done"}, {"code": "n = int(input())\nk= int(input())\na = int(input())\nb = int(input())\nres = 0\nif k == 1:\n print((n - 1) * a)\nelse:\n while n != 1:\n res += (n % k) * a\n if b > (n // k)*(k - 1) * a:\n res += (n // k)*(k - 1) * a\n else:\n res += b\n n //= k\n if n < k:\n res += (n - 1) * a\n break\n print(res)", "passed": true, "time": 0.18, "memory": 14488.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\nc1 = int(input())\nc2 = int(input())\nif k == 1:\n\tk += n\nans = 0\nwhile n > 1:\n\tif n > k:\n\t\ttemp = n % k\n\t\tans += temp * c1\n\t\tn -= temp\n\tif n % k == 0:\n\t\tans += min(c2, (n - n // k) * c1)\n\t\tn //= k\n\telse:\n\t\tans += (n - 1) * c1\n\t\tn = 1\nprint(ans)", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "n = int(input())\nk = int(input())\na = int(input())\nb = int(input())\nans = 0\nwhile n != 1:\n if n % k == 0:\n d = n // k\n if b >= (n-d)*a:\n ans += (n-1)*a\n n=1\n else:\n ans += b\n n = d\n else:\n r = n % k\n ans += r*a\n n = n - r\nprint(ans)", "passed": true, "time": 0.14, "memory": 14532.0, "status": "done"}]
[{"input": "9\n2\n3\n1\n", "output": "6\n"}, {"input": "5\n5\n2\n20\n", "output": "8\n"}, {"input": "19\n3\n4\n2\n", "output": "12\n"}, {"input": "1845999546\n999435865\n1234234\n2323423\n", "output": "1044857680578777\n"}, {"input": "1604353664\n1604353665\n9993432\n1\n", "output": "16032999235141416\n"}, {"input": "777888456\n1\n98\n43\n", "output": "76233068590\n"}, {"input": "1162261467\n3\n1\n2000000000\n", "output": "1162261466\n"}, {"input": "1000000000\n1999999999\n789987\n184569875\n", "output": "789986999210013\n"}, {"input": "2000000000\n2\n1\n2000000000\n", "output": "1999999999\n"}, {"input": "1999888325\n3\n2\n2000000000\n", "output": "3333258884\n"}, {"input": "1897546487\n687\n89798979\n879876541\n", "output": "110398404423\n"}, {"input": "20\n1\n20\n1\n", "output": "380\n"}, {"input": "16\n5\n17\n3\n", "output": "54\n"}, {"input": "19\n19\n19\n1\n", "output": "1\n"}, {"input": "18\n2\n3\n16\n", "output": "40\n"}, {"input": "1\n11\n8\n9\n", "output": "0\n"}, {"input": "9\n10\n1\n20\n", "output": "8\n"}, {"input": "19\n10\n19\n2\n", "output": "173\n"}, {"input": "16\n9\n14\n2\n", "output": "100\n"}, {"input": "15\n2\n5\n2\n", "output": "21\n"}, {"input": "14\n7\n13\n1\n", "output": "14\n"}, {"input": "43\n3\n45\n3\n", "output": "189\n"}, {"input": "99\n1\n98\n1\n", "output": "9604\n"}, {"input": "77\n93\n100\n77\n", "output": "7600\n"}, {"input": "81\n3\n91\n95\n", "output": "380\n"}, {"input": "78\n53\n87\n34\n", "output": "2209\n"}, {"input": "80\n3\n15\n1\n", "output": "108\n"}, {"input": "97\n24\n4\n24\n", "output": "40\n"}, {"input": "100\n100\n1\n100\n", "output": "99\n"}, {"input": "87\n4\n17\n7\n", "output": "106\n"}, {"input": "65\n2\n3\n6\n", "output": "36\n"}, {"input": "1000000\n1435\n3\n999999\n", "output": "1005804\n"}, {"input": "783464\n483464\n2\n966928\n", "output": "1566926\n"}, {"input": "248035\n11\n3\n20\n", "output": "202\n"}, {"input": "524287\n2\n945658\n999756\n", "output": "34963354\n"}, {"input": "947352\n78946\n85\n789654\n", "output": "790589\n"}, {"input": "1000000\n1\n999899\n60\n", "output": "999898000101\n"}, {"input": "753687\n977456\n6547\n456\n", "output": "4934382242\n"}, {"input": "1000000\n500000\n1\n999997\n", "output": "999998\n"}, {"input": "997458\n843596\n1\n843596\n", "output": "997457\n"}, {"input": "821109\n92\n6547\n98787\n", "output": "394566\n"}, {"input": "1073741823\n2\n9543\n8923453\n", "output": "188412866\n"}, {"input": "1000999777\n1934999345\n2356346\n34534565\n", "output": "2358701818178496\n"}, {"input": "2000000000\n1\n2000000000\n98\n", "output": "3999999998000000000\n"}, {"input": "1999324353\n978435356\n1\n978435356\n", "output": "1020888998\n"}, {"input": "2000000000\n2\n2000000000\n2000000000\n", "output": "84000000000\n"}, {"input": "241375690\n17\n2\n1998789654\n", "output": "482751378\n"}, {"input": "171507000\n350\n789\n6548687\n", "output": "14216965\n"}, {"input": "1100220011\n10001\n2\n1999778654\n", "output": "1999998674\n"}, {"input": "1867622656\n43216\n789644\n12315468\n", "output": "24630936\n"}, {"input": "1867622656\n43216\n1\n1879865413\n", "output": "1867622655\n"}, {"input": "1999999999\n1000000000\n789987\n184569875\n", "output": "789987183779888\n"}, {"input": "1987987897\n103546\n7\n98754563\n", "output": "98946650\n"}, {"input": "10\n2\n2\n5\n", "output": "13\n"}, {"input": "7\n2\n1\n100000\n", "output": "6\n"}, {"input": "7\n2\n3\n1\n", "output": "8\n"}, {"input": "2000000000\n666666667\n1\n1\n", "output": "666666668\n"}, {"input": "1999999997\n666666666\n2\n2\n", "output": "1333333334\n"}]
342
Let's call a string good if and only if it consists of only two types of lettersΒ β€” 'a' and 'b' and every two consecutive letters are distinct. For example "baba" and "aba" are good strings and "abb" is a bad string. You have $a$ strings "a", $b$ strings "b" and $c$ strings "ab". You want to choose some subset of these strings and concatenate them in any arbitrarily order. What is the length of the longest good string you can obtain this way? -----Input----- The first line contains three positive integers $a$, $b$, $c$ ($1 \leq a, b, c \leq 10^9$)Β β€” the number of strings "a", "b" and "ab" respectively. -----Output----- Print a single numberΒ β€” the maximum possible length of the good string you can obtain. -----Examples----- Input 1 1 1 Output 4 Input 2 1 2 Output 7 Input 3 5 2 Output 11 Input 2 2 1 Output 6 Input 1000000000 1000000000 1000000000 Output 4000000000 -----Note----- In the first example the optimal string is "baba". In the second example the optimal string is "abababa". In the third example the optimal string is "bababababab". In the fourth example the optimal string is "ababab".
interview
[{"code": "a, b, c = list(map(int, input().split()))\nx = 2 * (c + min(a, b))\nif a != b:\n x += 1\nprint(x)\n", "passed": true, "time": 0.23, "memory": 14256.0, "status": "done"}, {"code": "a, b, c = list(map(int, input().split()))\na += c\nb += c\nif a == b:\n\tprint(a + b)\nelse:\n\tprint(min(a, b) * 2 + 1)\n", "passed": true, "time": 0.16, "memory": 14216.0, "status": "done"}, {"code": "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools\nimport random\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 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)\n\n\ndef main():\n a,b,c = LI()\n r = min(a,b) * 2\n if a != b:\n r += 1\n\n return r + c * 2\n\n\nprint(main())\n\n", "passed": true, "time": 0.23, "memory": 14624.0, "status": "done"}, {"code": "a,b,c=list(map(int,input().split()))\nprint(2*c+2*min(a,b)+(a!=b))\n", "passed": true, "time": 0.25, "memory": 14356.0, "status": "done"}, {"code": "a, b, c = map(int, input().split())\ns = min(a, b)\nprint(2*(c + s) + min(1, (a-s)) + min(1, (b-s)))", "passed": true, "time": 0.14, "memory": 14312.0, "status": "done"}, {"code": "a,b,c=map(int,input().split())\nprint(min(a,b)*2+(1 if a!=b else 0)+c+c)", "passed": true, "time": 0.15, "memory": 14320.0, "status": "done"}, {"code": "\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\nmii=lambda:list(map(int,input().split()))\n\na,b,c=mii()\nd=min(a,b)\na-=d\nb-=d\nc+=d\n\nprint(c*2+min(1,max(a,b)))\n\n", "passed": true, "time": 0.17, "memory": 14496.0, "status": "done"}, {"code": "a,b,c=map(int,input().split())\nprint(2*c+2*min(a,b)+int(a>b)+int(b>a))", "passed": true, "time": 0.14, "memory": 14420.0, "status": "done"}, {"code": "x,y,z=map(int,input().split())\nans=0\nans+=2*z+2*min(y,x)\nf=min(y,x)\ny=y-f\nx=x-f\nprint(ans+min(1,max(y,x)))", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "a,b,c=[int(k) for k in input().split(\" \")]\n\nm=min(a,b)\nM=min(m+1,max(a,b))\n\nres=m+M+2*c\n\nprint(res)", "passed": true, "time": 0.15, "memory": 14496.0, "status": "done"}, {"code": "a, b, c = map(int, input().split())\nres = 2 * c\nx = min(a, b)\nres += 2 * x\nif a - x > 0: res += 1\nif b - x > 0: res += 1\nprint(res)", "passed": true, "time": 0.24, "memory": 14380.0, "status": "done"}, {"code": "a, b, c = list(map(int, input().split()))\nans = 2 * c\nm = min(a, b)\na -= m\nb -= m\nans += 2 * m\nif a + b > 0:\n ans += 1\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14408.0, "status": "done"}, {"code": "a,b,c= map(int,input().split())\n\nif a == b:\n print(2*c + 2*a)\nelse:\n print(2*c + min(a,b) * 2 + 1)", "passed": true, "time": 0.14, "memory": 14400.0, "status": "done"}, {"code": "a, b, ab = [int(x) for x in input().split()]\n\nif a > b:\n print(2*ab + 2*b + 1)\nelif a == b:\n print(2*ab + 2*a)\nelse:\n print(1 + 2*ab + 2*a)\n", "passed": true, "time": 0.24, "memory": 14232.0, "status": "done"}, {"code": "a,b,c=[int(x) for x in input().split()]\nif a==b:\n print(a+2*c+b)\nelse:\n print(2*min(a,b)+1+2*c)\n", "passed": true, "time": 0.15, "memory": 14252.0, "status": "done"}, {"code": "read = lambda: map(int, input().split())\na, b, c = read()\nans = c*2 + (b*2 if a == b else min(a, b)*2 + 1)\nprint(ans)", "passed": true, "time": 1.55, "memory": 14476.0, "status": "done"}, {"code": "\ndef main():\n buf = input()\n buflist = buf.split()\n A = int(buflist[0])\n B = int(buflist[1])\n C = int(buflist[2])\n length = 2 * C\n length += 2 * min(A, B)\n u = min(A, B)\n A -= u\n B -= u\n if A > 0 or B > 0:\n length += 1\n print(length)\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14336.0, "status": "done"}, {"code": "n, m, k = map(int, input().split())\nif n != m:\n print((min(n, m) * 2 + 1) + 2 * k)\nelse:\n print(n * 2 + 2 * k)", "passed": true, "time": 0.15, "memory": 14252.0, "status": "done"}, {"code": "from sys import stdin\n# stdin=open('input.txt')\n\ndef input():\n\treturn stdin.readline().strip()\n\n\n# from sys import stdout\n# stdout=open('input.txt',mode='w+')\n\n# def print1(x, end='\\n'):\n# \tstdout.write(str(x) +end)\n\n\n# a, b = map(int, input().split())\n\n# l = list(map(int, input().split()))\n\n\n# CODE BEGINS HERE.................\n\na, b, c = list(map(int, input().split()))\n\nprint(2 * c + 2 * min(a, b) + (a - min(a, b) > 0 or b - min(a, b) > 0))\n\n\n# CODE ENDS HERE....................\n# stdout.close()\n\n", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "a, b, c = map(int, input().split())\nq = c * 2 + min(a, b) * 2\nif a!=b:\n q+=1\nprint(q)", "passed": true, "time": 0.14, "memory": 14228.0, "status": "done"}, {"code": "a, b, c = map(int, input().split())\nm = min(a, b)\na -= m\nb -= m\nans = c * 2 + m * 2 + min(1, max(a, b))\nprint(ans)", "passed": true, "time": 0.14, "memory": 14376.0, "status": "done"}, {"code": "import sys\nimport math\nfrom itertools import permutations\ninput = sys.stdin.readline\n\na,b,c=map(int,input().split())\n\nminn=min(a,b)\nmaxx=max(a,b)\n\nif a!=b:\n\tprint(2*c+2*minn+1)\nelse:\n\tprint(2*c+2*minn)", "passed": true, "time": 0.14, "memory": 14300.0, "status": "done"}, {"code": "(a, b, ab) = (int(x) for x in input().split())\n# print(a * 100 + b * 10 + ab)\nm = min(a, b)\nans = ab * 2 + 2 * m\n\na -= m\nb -= m\n\nif a or b:\n ans += 1\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14428.0, "status": "done"}, {"code": "import math\nfrom collections import deque, defaultdict\nfrom sys import stdin, stdout\ninput = stdin.readline\n# print = stdout.write\nlistin = lambda : list(map(int, input().split()))\nmapin = lambda : map(int, input().split())\na, b, c = mapin()\nprint(2*(min(a, b))+2*c+(abs(a-b)>0))", "passed": true, "time": 0.15, "memory": 14524.0, "status": "done"}, {"code": "a, b, c = map(int, input().split())\nprint(c * 2 + min(a, b) * 2 + (a != b))", "passed": true, "time": 0.15, "memory": 14388.0, "status": "done"}]
[{"input": "1 1 1\n", "output": "4\n"}, {"input": "2 1 2\n", "output": "7\n"}, {"input": "3 5 2\n", "output": "11\n"}, {"input": "2 2 1\n", "output": "6\n"}, {"input": "1000000000 1000000000 1000000000\n", "output": "4000000000\n"}, {"input": "3 1 3\n", "output": "9\n"}, {"input": "2 2 3\n", "output": "10\n"}, {"input": "1 1 4\n", "output": "10\n"}, {"input": "1 1 2\n", "output": "6\n"}, {"input": "1 2 1\n", "output": "5\n"}, {"input": "3 6 3\n", "output": "13\n"}, {"input": "5 5 4\n", "output": "18\n"}, {"input": "41764 97259 54586\n", "output": "192701\n"}, {"input": "3698483 6798912 18096063\n", "output": "43589093\n"}, {"input": "13350712 76770926 61331309\n", "output": "149364043\n"}, {"input": "6 1 6\n", "output": "15\n"}, {"input": "3 7 5\n", "output": "17\n"}, {"input": "8 4 5\n", "output": "19\n"}, {"input": "8 8 7\n", "output": "30\n"}, {"input": "3 9 1\n", "output": "9\n"}, {"input": "7 9 7\n", "output": "29\n"}, {"input": "3 1 8\n", "output": "19\n"}, {"input": "1 2 8\n", "output": "19\n"}, {"input": "7 5 12\n", "output": "35\n"}, {"input": "11 9 6\n", "output": "31\n"}, {"input": "894 197 325\n", "output": "1045\n"}, {"input": "8581 6058 3019\n", "output": "18155\n"}, {"input": "17843355 6588793 15517352\n", "output": "44212291\n"}, {"input": "333625 453145 800800\n", "output": "2268851\n"}, {"input": "254762 244010 3461323\n", "output": "7410667\n"}, {"input": "4394826 2233224 609367\n", "output": "5685183\n"}, {"input": "135266639 299910226 320610730\n", "output": "911754739\n"}, {"input": "142098087 687355301 987788392\n", "output": "2259772959\n"}, {"input": "4 2 6\n", "output": "17\n"}, {"input": "4 8 5\n", "output": "19\n"}, {"input": "6 1 1\n", "output": "5\n"}, {"input": "5 2 2\n", "output": "9\n"}, {"input": "4 8 10\n", "output": "29\n"}, {"input": "6 14 1\n", "output": "15\n"}, {"input": "7 3 4\n", "output": "15\n"}, {"input": "1000000000 1 1\n", "output": "5\n"}, {"input": "3 4 1\n", "output": "9\n"}, {"input": "2 4 1\n", "output": "7\n"}, {"input": "100 101 99\n", "output": "399\n"}, {"input": "300 1 100\n", "output": "203\n"}, {"input": "6 7 1000\n", "output": "2013\n"}, {"input": "1000 100 10\n", "output": "221\n"}, {"input": "10 1 1\n", "output": "5\n"}, {"input": "1000000000 1000000000 99999999\n", "output": "2199999998\n"}, {"input": "1 5 10\n", "output": "23\n"}, {"input": "6 8 1\n", "output": "15\n"}, {"input": "700 800 1900\n", "output": "5201\n"}, {"input": "3 5 10\n", "output": "27\n"}, {"input": "100 101 102\n", "output": "405\n"}, {"input": "2 100 1\n", "output": "7\n"}, {"input": "1 2333 2333\n", "output": "4669\n"}, {"input": "10 2 5\n", "output": "15\n"}]
343
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than y points (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games. Vova has already wrote k tests and got marks a_1, ..., a_{k}. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that. -----Input----- The first line contains 5 space-separated integers: n, k, p, x and y (1 ≀ n ≀ 999, n is odd, 0 ≀ k < n, 1 ≀ p ≀ 1000, n ≀ x ≀ nΒ·p, 1 ≀ y ≀ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games. The second line contains k space-separated integers: a_1, ..., a_{k} (1 ≀ a_{i} ≀ p)Β β€” the marks that Vova got for the tests he has already written. -----Output----- If Vova cannot achieve the desired result, print "-1". Otherwise, print n - k space-separated integersΒ β€” the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them. -----Examples----- Input 5 3 5 18 4 3 5 4 Output 4 1 Input 5 3 5 16 4 5 5 5 Output -1 -----Note----- The median of sequence a_1,Β ...,Β a_{n} where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of a_{i}. In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games. Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4Β 2", "2Β 4", "5Β 1", "1Β 5", "4Β 1", "1Β 4" for the first test is correct. In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1".
interview
[{"code": "def read_data():\n n, k, p, x, y = map(int, input().split())\n As = list(map(int, input().split()))\n return n, k, p, x, y, As\n\ndef solve(n, k, p, x, y, As):\n '''median (As + Bs) >= y\n sum(As + Bs) <= x\n 1 <= Bi <= p\n '''\n middle = n // 2\n As.sort(reverse=True)\n sumA = sum(As)\n minSum = sumA + 1 * (n - k)\n if minSum > x:\n return ['-1']\n num_a_over_y = len([1 for a in As if a >= y])\n if num_a_over_y > middle:\n return ['1'] * (n - k)\n min_num_y = middle + 1 - num_a_over_y\n if min_num_y > n - k:\n return ['-1']\n minSum2 = sumA + min_num_y * y + (n - k - min_num_y) * 1\n if minSum2 > x:\n return ['-1']\n return [str(y)] * min_num_y + ['1'] * (n - k - min_num_y)\n\ndef __starting_point():\n n, k, p, x, y, As = read_data()\n seq = solve(n, k, p, x, y, As)\n print(' '.join(seq))\n__starting_point()", "passed": true, "time": 0.45, "memory": 14332.0, "status": "done"}, {"code": "s=input()\nn,k,p,x,y=s.split()\nn,k,p,x,y=int(n),int(k),int(p),int(x),int(y)\ns=input()\na=[]\nfor i in s.split():\n a.append(int(i))\nsum=0\nl=0\nr=0\nfor i in a:\n sum=sum+i\n if i>=y: r+=1\n else: l+=1\nflag=1\nb=[]\nif sum>=x or l>n//2 or y>p:\n flag=0\nelse:\n left=x-sum\n for i in range(0,n-k):\n if r<n//2+1:\n b.append(y)\n r+=1\n else: b.append(1)\n left-=b[i]\n if left<0 or r<n//2+1:\n flag=0\n\nif flag==1:\n for i in range(0,n-k-1):\n print(b[i],end=' ')\n print(b[n-k-1])\nelse :\n print(-1)\n \n", "passed": true, "time": 0.14, "memory": 14336.0, "status": "done"}, {"code": "# n = list(map(int,unput().split()))\ndef print_lst(lst):\n print(\" \".join(map(str,lst)))\n\nn,k,p,x,y = list(map(int,input().split()))\npi = list(map(int,input().split())) \n\nspi = sum(pi)\nres = []\nc_lm = 0\nc_hm = 0\nfor el in pi:\n if el < y:\n c_lm += 1\n else:\n c_hm += 1\nn_hm = n//2+1 - c_hm\nn_lm = n//2 - c_lm\nfor i in range(n-k):\n \n if n_hm > 0:\n res += [y]\n pi += [y]\n n_hm -= 1\n elif n_lm > 0:\n res += [1]\n pi += [1]\n n_lm -= 1\n\npis = sorted(pi)\nif sum(pis) > x:\n print(-1)\nelif pis[len(pis)//2] < y:\n print(-1)\nelse:\n print_lst(res)\n\n", "passed": true, "time": 0.14, "memory": 14544.0, "status": "done"}]
[{"input": "5 3 5 18 4\n3 5 4\n", "output": "4 1\n"}, {"input": "5 3 5 16 4\n5 5 5\n", "output": "-1\n"}, {"input": "5 3 5 17 4\n5 5 5\n", "output": "1 1\n"}, {"input": "5 3 5 12 1\n5 5 1\n", "output": "-1\n"}, {"input": "5 3 5 13 1\n5 5 1\n", "output": "1 1\n"}, {"input": "7 4 5 26 5\n5 2 4 5\n", "output": "-1\n"}, {"input": "7 4 5 27 5\n5 2 4 5\n", "output": "5 5 1\n"}, {"input": "1 0 1000 999 1000\n\n", "output": "-1\n"}, {"input": "1 0 1000 1000 1000\n\n", "output": "1000\n"}, {"input": "1 0 1000 1000 999\n\n", "output": "999\n"}, {"input": "5 3 5 25 4\n3 3 3\n", "output": "-1\n"}, {"input": "7 4 5 25 5\n5 5 4 5\n", "output": "-1\n"}, {"input": "7 4 5 26 5\n5 5 4 5\n", "output": "5 1 1\n"}, {"input": "7 4 5 26 5\n5 5 4 5\n", "output": "5 1 1\n"}, {"input": "5 3 5 17 4\n3 3 4\n", "output": "-1\n"}, {"input": "5 3 5 18 4\n3 3 4\n", "output": "4 4\n"}, {"input": "5 3 5 5 1\n1 1 2\n", "output": "-1\n"}, {"input": "5 3 5 6 1\n1 1 2\n", "output": "1 1\n"}, {"input": "3 0 2 3 1\n\n", "output": "1 1 1\n"}, {"input": "3 0 2 4 2\n\n", "output": "-1\n"}, {"input": "3 0 2 5 2\n\n", "output": "2 2 1\n"}, {"input": "9 7 3 16 2\n1 3 1 3 1 3 1\n", "output": "-1\n"}, {"input": "9 7 3 17 2\n1 3 1 3 1 3 1\n", "output": "2 2\n"}, {"input": "9 7 3 18 2\n1 3 1 3 1 3 1\n", "output": "2 2\n"}, {"input": "9 7 3 18 3\n1 3 1 3 1 3 1\n", "output": "-1\n"}, {"input": "9 7 3 19 3\n1 3 1 3 1 3 1\n", "output": "3 3\n"}, {"input": "9 7 3 20 3\n1 3 1 3 1 3 1\n", "output": "3 3\n"}, {"input": "9 6 3 27 2\n1 1 1 2 1 1\n", "output": "-1\n"}, {"input": "9 6 3 13 2\n1 1 1 2 1 2\n", "output": "-1\n"}, {"input": "9 6 3 14 2\n1 1 1 2 1 2\n", "output": "2 2 2\n"}, {"input": "5 0 5 13 4\n\n", "output": "-1\n"}, {"input": "5 0 5 14 4\n\n", "output": "4 4 4 1 1\n"}, {"input": "5 0 5 5 1\n\n", "output": "1 1 1 1 1\n"}, {"input": "5 0 5 7 2\n\n", "output": "-1\n"}, {"input": "5 0 5 8 2\n\n", "output": "2 2 2 1 1\n"}, {"input": "9 7 2 18 2\n1 1 1 2 2 1 1\n", "output": "-1\n"}, {"input": "9 7 2 13 1\n2 2 2 1 1 2 2\n", "output": "-1\n"}, {"input": "9 7 2 14 1\n2 2 2 1 1 2 2\n", "output": "1 1\n"}, {"input": "993 0 3 993 2\n\n", "output": "-1\n"}, {"input": "997 100 3 1102 2\n1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 1 1 1 1 1 1 3\n", "output": "-1\n"}, {"input": "11 8 10 110 5\n9 9 9 9 9 9 9 9\n", "output": "1 1 1\n"}, {"input": "9 8 10 90 2\n1 1 1 1 1 1 1 1\n", "output": "-1\n"}, {"input": "3 2 10 30 2\n1 1\n", "output": "-1\n"}, {"input": "3 2 10 30 1\n1 1\n", "output": "1\n"}, {"input": "5 4 100 14 4\n4 4 4 4\n", "output": "-1\n"}, {"input": "5 4 2 8 2\n2 2 2 2\n", "output": "-1\n"}, {"input": "5 4 2 7 2\n1 1 1 2\n", "output": "-1\n"}, {"input": "11 10 1000 101 5\n10 10 10 10 10 10 10 10 10 10\n", "output": "1\n"}, {"input": "7 5 100 100 5\n7 1 1 1 1\n", "output": "-1\n"}, {"input": "5 4 5 25 2\n1 1 1 1\n", "output": "-1\n"}, {"input": "9 8 10 89 5\n8 8 8 8 8 8 8 8\n", "output": "1\n"}, {"input": "5 3 5 18 4\n1 1 1\n", "output": "-1\n"}, {"input": "11 10 1000 100 5\n10 10 10 10 10 10 10 10 10 10\n", "output": "-1\n"}, {"input": "9 7 10 30 2\n3 3 3 3 3 3 3\n", "output": "1 1\n"}, {"input": "5 4 2 10 2\n2 2 2 2\n", "output": "1\n"}, {"input": "7 6 1000 31 5\n5 5 5 5 5 5\n", "output": "1\n"}, {"input": "9 8 100 100 2\n1 1 1 1 1 1 1 1\n", "output": "-1\n"}]
344
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not. Help Vitya find out if a word $s$ is Berlanese. -----Input----- The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. -----Output----- Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower). -----Examples----- Input sumimasen Output YES Input ninja Output YES Input codeforces Output NO -----Note----- In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese. In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.
interview
[{"code": "s = input()\nok = 1\nn = len(s)\n\ndef is_vowel(c):\n\treturn c in \"aouie\"\n\nfor i, x in enumerate(s):\n\tif not is_vowel(x) and x != 'n':\n\t\tok &= ((i + 1 < n) and is_vowel(s[i + 1]))\n\nprint(\"YES\" if ok else \"NO\")", "passed": true, "time": 0.15, "memory": 14340.0, "status": "done"}, {"code": "s = input()\nfor i in range(len(s)):\n if s[i] in ['a','e','i','o','u','n']:\n continue\n elif i == len(s)-1 or s[i+1] not in ['a','e','i','o','u']:\n print('NO')\n break\nelse:\n print('YES')\n", "passed": true, "time": 1.03, "memory": 14260.0, "status": "done"}, {"code": "s = input()\nvow = ['a', 'e', 'i', 'o', 'u']\nans = True\nfor i in range(len(s)):\n if s[i] not in vow:\n if s[i] != 'n':\n if i + 1 == len(s):\n ans = False\n elif s[i + 1] not in vow:\n ans = False\nif ans == True:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n", "passed": true, "time": 0.14, "memory": 14420.0, "status": "done"}, {"code": "s = input()\ng = 'aouien'\ng1 = 'aouie'\nstate = 0\nok = True\nfor el in s:\n\tif state == 0:\n\t\tif el in g:\n\t\t\tstate = 0\n\t\telse:\n\t\t\tstate = 1\n\telse:\n\t\tif el not in g1:\n\t\t\tok = False\n\t\tstate = 0\nif state == 1:\n\tok = False\nif ok:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")", "passed": true, "time": 1.6, "memory": 14428.0, "status": "done"}, {"code": "s = input()\nvowels = \"aeiou\"\nberl = True\n\nfor i in range(len(s)-1):\n if((s[i] not in vowels) and s[i]!='n'):\n if(s[i+1] not in vowels):\n berl = False\n break\n\nif(s[-1] not in vowels and s[-1]!='n'):\n berl = False\n\nif(berl==False):\n print(\"NO\")\nelse:\n print(\"YES\")\n", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "t = input()\nL = ['a', 'e', 'i', 'o', 'u', 'n']\nM = ['a', 'e', 'i', 'o', 'u']\nt = t+'n'\nb = True\nfor i in range(len(t)-1):\n if t[i] not in L and t[i+1] not in M:\n b = False\nif b:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14440.0, "status": "done"}, {"code": "s=input()\nvo=['a','e','i','o','u']\nfor i in range(0,len(s)-1):\n if s[i] not in vo:\n if s[i]=='n':\n continue\n else:\n if s[i+1] not in vo:\n print(\"NO\")\n return\nif s[len(s)-1] not in vo and s[len(s)-1]!='n':\n print(\"NO\")\nelse:\n print(\"YES\")", "passed": true, "time": 0.24, "memory": 14360.0, "status": "done"}, {"code": "def main():\n #string input()\n #int int(input())\n #listOfStrings input().split()\n #ints map(int, input().split())\n #listOfInts list(map(int, input().split()))\n s = input()\n i = 0\n l = len(s)\n alpha = \"bcdfghjklmpqrstvwxyz\"\n vowels = \"aeiou\"\n if s[-1] in alpha:\n print(\"NO\")\n return 0\n while i < l - 1:\n if s[i] in alpha:\n if s[i + 1] in vowels:\n i += 2\n while i < l and s[i] in vowels:\n i += 1\n else:\n print(\"NO\")\n return 0\n else:\n i += 1\n print(\"YES\")\n return 0\nmain()", "passed": true, "time": 0.34, "memory": 14324.0, "status": "done"}, {"code": "def main():\n a = input().strip()\n vowel = 'aeiou'\n if a[-1] not in vowel and a[-1]!='n':\n print('NO')\n return\n for i in range(len(a)-1):\n if a[i] not in vowel:\n if a[i]!='n':\n if a[i+1] not in vowel:\n print('NO')\n return\n print('YES')\n return\ndef __starting_point():\n main()\n\n\n__starting_point()", "passed": true, "time": 0.23, "memory": 14284.0, "status": "done"}, {"code": "a = list(input())\nvowel = ['a','e','o','u','i']\nisit = 1\nfor i in range(len(a)):\n if a[i] not in vowel and a[i] != 'n':\n if i + 1 < len(a):\n if a[i+1] not in vowel:\n isit = 0\n else:\n isit = 0\nif isit:\n print(\"YES\")\nelse:\n print(\"NO\")\n \n \n", "passed": true, "time": 1.6, "memory": 14284.0, "status": "done"}, {"code": "s=input()\nst={'a','e','i','o','u'}\nflag=\"YES\"\nif(s[-1]!='n' and not s[-1] in st):\n flag=\"NO\"\nelse:\n for i in range(0,len(s)-1):\n if(s[i]=='n'):\n continue\n if(s[i] in st):\n continue\n if(not s[i+1] in st):\n flag=\"NO\"\n break\nprint(flag)\n", "passed": true, "time": 0.2, "memory": 14264.0, "status": "done"}, {"code": "arr=['a','e','i','o','u']\nans=True\ns=input()\nn=len(s)\nfor i in range(n):\n if(s[i] not in arr and i<n-1):\n if(s[i]=='n'):\n continue\n else:\n if(s[i+1] not in arr):\n ans=False\n break\n if(s[i] not in arr and i==n-1):\n if(s[i]!='n'):\n ans=False\n break\nif(ans==True):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.17, "memory": 14532.0, "status": "done"}, {"code": "s=input()\nprev=-1\nans=1\nfor x in s:\n if prev=='cons' and x not in 'aeiou':\n ans=0\n if x in 'aeioun':\n prev='vow'\n else:\n prev='cons'\nif prev=='cons':\n ans=0\nprint(\"YES\" if ans else \"NO\")", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "r=input()\nl=len(r)\nvowel=\"aeiou\"\nfor i in range(l-1):\n\tif r[i] not in vowel and r[i]!=\"n\":\n\t\tif r[i+1] not in vowel:\n\t\t\tprint (\"NO\")\n\t\t\treturn\nif r[-1] not in vowel and r[-1]!=\"n\":\n\tprint (\"NO\")\n\treturn\nprint (\"YES\")", "passed": true, "time": 0.28, "memory": 14448.0, "status": "done"}, {"code": "s = input()\nflag = True\ng = ['a','o', 'u', 'i','e']\n\nfor i in range(len(s)-1):\n if s[i] is not 'n' and s[i] not in g and s[i+1] not in g:\n flag = False\n\nif s[-1] not in g and s[-1] is not 'n':\n flag = False\n\nif flag:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.14, "memory": 14440.0, "status": "done"}, {"code": "n = list(input())\n\nfor i in range(len(n) - 1):\n if n[i] == 'a' or n[i] == 'o' or n[i] == 'u' or n[i] == 'i' or n[i] == 'e':\n pass\n elif n[i] == 'n':\n pass\n else:\n if n[i+1] == 'a' or n[i+1] == 'o' or n[i+1] == 'u' or n[i+1] == 'i' or n[i+1] == 'e':\n pass\n else:\n print('NO')\n return\n\nx = n[len(n) - 1]\nif x == 'a' or x == 'o' or x == 'u' or x == 'i' or x == 'e' or x == 'n':\n pass\nelse:\n print('NO')\n return\n\nprint('YES')", "passed": true, "time": 0.14, "memory": 14484.0, "status": "done"}, {"code": "s = input()\ngl = ['a', 'o', 'u', 'i', 'e']\nfor i in range(len(s)-1):\n if (s[i] not in gl) and (s[i] != 'n'):\n if s[i+1] not in gl:\n print(\"NO\")\n break\nelse:\n if (s[len(s)-1] not in gl) and (s[len(s)-1] != 'n'):\n print(\"NO\")\n else:\n print(\"YES\")\n", "passed": true, "time": 0.24, "memory": 14512.0, "status": "done"}, {"code": "s = input()\nn = len(s)\n\nv = {'a', 'o', 'u', 'i', 'e'}\n\nfor i in range(n-1):\n\tif s[i] not in v:\n\t\tif s[i] != 'n':\n\t\t\tif s[i+1] not in v:\n\t\t\t\tprint('NO')\n\t\t\t\treturn\n\t\t\nif(s[n-1] not in v) and (s[n-1] != 'n'):\n\tprint('NO')\nelse:\n\tprint('YES')", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "n=input()\nd={}\nd['a']=1\nd['i']=1\nd['o']=1\nd['e']=1\nd['u']=1\nf=0\nfor i in range(len(n)):\n if(n[i] not in d and n[i]!='n'):\n if(i+1<len(n)):\n if(n[i+1] not in d):\n f=1\n else:\n f=1\nif(f==1):\n print(\"NO\")\nelse:\n print(\"YES\")", "passed": true, "time": 0.14, "memory": 14540.0, "status": "done"}, {"code": "import sys\nimport os\n\ndef isVowel(x):\n return x == 'a' or x == 'e' or x == 'i' or x == 'o' or x == 'u'\n\ndef romaji(str):\n last = None\n for c in str:\n if last is None:\n last = c\n continue\n\n if not isVowel(last) and last != 'n' and not isVowel(c):\n return 'NO'\n\n last = c\n\n if not isVowel(last) and last != 'n':\n return 'NO'\n\n return 'YES'\n\ndef main():\n str = input()\n print(romaji(str))\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "s = input().strip()\nvowels = ['a', 'e', 'i', 'o', 'u']\nval = True\nfor i in range(len(s) - 1):\n if s[i] not in vowels and s[i] != 'n':\n if s[i+1] not in vowels:\n val = False\n break\nif s[-1] not in vowels and s[-1] != 'n':\n val = False\nif val:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.15, "memory": 14384.0, "status": "done"}, {"code": "s = input() + 'd'\nn = len(s)\nglas = set(('a', 'o', 'u', 'i', 'e'))\nf = True\nfor i in range(n - 1):\n if s[i] in glas or s[i] == 'n':\n continue\n if s[i + 1] not in glas:\n f = False\nif f:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.14, "memory": 14488.0, "status": "done"}, {"code": "s = input()\na = 'aeiou'\nb = a + 'n'\nprev = 'a'\nvalid = 'YES'\nfor c in s:\n if prev not in b and c not in a:\n valid = 'NO'\n break\n prev = c\nif prev not in b:\n valid = 'NO'\nprint(valid)\n", "passed": true, "time": 0.14, "memory": 14292.0, "status": "done"}]
[{"input": "sumimasen\n", "output": "YES\n"}, {"input": "ninja\n", "output": "YES\n"}, {"input": "codeforces\n", "output": "NO\n"}, {"input": "auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen\n", "output": "YES\n"}, {"input": "n\n", "output": "YES\n"}, {"input": "necnei\n", "output": "NO\n"}, {"input": "nternn\n", "output": "NO\n"}, {"input": "aucunuohja\n", "output": "NO\n"}, {"input": "a\n", "output": "YES\n"}, {"input": "b\n", "output": "NO\n"}, {"input": "nn\n", "output": "YES\n"}, {"input": "nnnzaaa\n", "output": "YES\n"}, {"input": "zn\n", "output": "NO\n"}, {"input": "ab\n", "output": "NO\n"}, {"input": "aaaaaaaaaa\n", "output": "YES\n"}, {"input": "aaaaaaaaab\n", "output": "NO\n"}, {"input": "aaaaaaaaan\n", "output": "YES\n"}, {"input": "baaaaaaaaa\n", "output": "YES\n"}, {"input": "naaaaaaaaa\n", "output": "YES\n"}, {"input": "nbaaaaaaaa\n", "output": "YES\n"}, {"input": "bbaaaaaaaa\n", "output": "NO\n"}, {"input": "bnaaaaaaaa\n", "output": "NO\n"}, {"input": "eonwonojannonnufimiiniewuqaienokacevecinfuqihatenhunliquuyebayiaenifuexuanenuaounnboancaeowonu\n", "output": "YES\n"}, {"input": "uixinnepnlinqaingieianndeakuniooudidonnnqeaituioeneiroionxuowudiooonayenfeonuino\n", "output": "NO\n"}, {"input": "nnnnnyigaveteononnnnxaalenxuiiwannntoxonyoqonlejuoxuoconnnentoinnul\n", "output": "NO\n"}, {"input": "ndonneasoiunhomuunnhuitonnntunntoanerekonoupunanuauenu\n", "output": "YES\n"}, {"input": "anujemogawautiedoneobninnibonuunaoennnyoorufonxionntinimiboonununnnnnleenqunminzayoutanlalo\n", "output": "NO\n"}, {"input": "y\n", "output": "NO\n"}, {"input": "by\n", "output": "NO\n"}, {"input": "yy\n", "output": "NO\n"}, {"input": "nbn\n", "output": "NO\n"}, {"input": "nz\n", "output": "NO\n"}, {"input": "king\n", "output": "NO\n"}, {"input": "g\n", "output": "NO\n"}, {"input": "az\n", "output": "NO\n"}, {"input": "x\n", "output": "NO\n"}, {"input": "z\n", "output": "NO\n"}, {"input": "yn\n", "output": "NO\n"}, {"input": "aeo\n", "output": "YES\n"}, {"input": "nb\n", "output": "NO\n"}, {"input": "npn\n", "output": "NO\n"}, {"input": "kini\n", "output": "YES\n"}, {"input": "pya\n", "output": "NO\n"}, {"input": "m\n", "output": "NO\n"}, {"input": "p\n", "output": "NO\n"}, {"input": "aaaaaaaak\n", "output": "NO\n"}, {"input": "aab\n", "output": "NO\n"}, {"input": "d\n", "output": "NO\n"}, {"input": "at\n", "output": "NO\n"}, {"input": "aaaaaak\n", "output": "NO\n"}, {"input": "aaz\n", "output": "NO\n"}, {"input": "aaab\n", "output": "NO\n"}, {"input": "s\n", "output": "NO\n"}, {"input": "nzzen\n", "output": "NO\n"}, {"input": "aeionnhhhn\n", "output": "NO\n"}, {"input": "h\n", "output": "NO\n"}, {"input": "ny\n", "output": "NO\n"}]
345
Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every $a$ and $b$ such that $1 \leq a \leq b \leq 6$, there is exactly one domino with $a$ dots on one half and $b$ dots on the other half. The set contains exactly $21$ dominoes. Here is an exact illustration of his set: [Image] Also, Anadi has an undirected graph without self-loops and multiple edges. He wants to choose some dominoes and place them on the edges of this graph. He can use at most one domino of each type. Each edge can fit at most one domino. It's not necessary to place a domino on each edge of the graph. When placing a domino on an edge, he also chooses its direction. In other words, one half of any placed domino must be directed toward one of the endpoints of the edge and the other half must be directed toward the other endpoint. There's a catch: if there are multiple halves of dominoes directed toward the same vertex, each of these halves must contain the same number of dots. How many dominoes at most can Anadi place on the edges of his graph? -----Input----- The first line contains two integers $n$ and $m$ ($1 \leq n \leq 7$, $0 \leq m \leq \frac{n\cdot(n-1)}{2}$) β€” the number of vertices and the number of edges in the graph. The next $m$ lines contain two integers each. Integers in the $i$-th line are $a_i$ and $b_i$ ($1 \leq a, b \leq n$, $a \neq b$) and denote that there is an edge which connects vertices $a_i$ and $b_i$. The graph might be disconnected. It's however guaranteed that the graph doesn't contain any self-loops, and that there is at most one edge between any pair of vertices. -----Output----- Output one integer which denotes the maximum number of dominoes which Anadi can place on the edges of the graph. -----Examples----- Input 4 4 1 2 2 3 3 4 4 1 Output 4 Input 7 0 Output 0 Input 3 1 1 3 Output 1 Input 7 21 1 2 1 3 1 4 1 5 1 6 1 7 2 3 2 4 2 5 2 6 2 7 3 4 3 5 3 6 3 7 4 5 4 6 4 7 5 6 5 7 6 7 Output 16 -----Note----- Here is an illustration of Anadi's graph from the first sample test: [Image] And here is one of the ways to place a domino on each of its edges: [Image] Note that each vertex is faced by the halves of dominoes with the same number of dots. For instance, all halves directed toward vertex $1$ have three dots.
interview
[{"code": "n, m = map(int, input().split())\n\nd = [0 for i in range(7)]\ng = [[] for i in range(7)]\n\nfor i in range(m):\n\tx, y = map(int, input().split())\n\tx -= 1\n\ty -= 1\n\td[x] += 1\n\td[y] += 1\n\t\n\tg[x].append(y)\n\tg[y].append(x)\n\t\nmn = min(d)\nfor i in range(7):\n\tfor j in range(i):\n\t\tcnt = 0\n\t\tfor k in range(7):\n\t\t\tif((k in g[i]) and (k in g[j])):\n\t\t\t\tcnt += 1\n\t\tmn = min(mn, cnt)\nm -= mn\nprint(m) ", "passed": true, "time": 0.14, "memory": 14464.0, "status": "done"}, {"code": "\nfrom collections import defaultdict\nn, m = list(map(int, input().split()))\ngraph = defaultdict(set)\nfor _ in range(m):\n a, b = list(map(int, input().split()))\n graph[a].add(b)\n graph[b].add(a)\n \nans = 100\nfor i in range(1, 7):\n for j in range(i + 1, 8):\n g = graph[i] & graph[j]\n ans = min(ans, len(g))\nprint(m - ans)\n", "passed": true, "time": 0.14, "memory": 14312.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\ngraph = [[] for _ in range(n)]\nfor _ in range(m):\n u, v = list(map(int, input().split()))\n u -= 1\n v -= 1\n graph[u].append(v)\n graph[v].append(u)\nmaxcnt = 0\nfor node1 in range(n):\n for node2 in range(node1 + 1, n):\n used = [[False] * n for _ in range(n)]\n col = list(range(0, node2)) + [node1] + list(range(node2 + 1, n))\n cnt = 0\n for u in range(n):\n for v in graph[u]:\n if not used[col[u]][col[v]]:\n used[col[u]][col[v]] = used[col[v]][col[u]] = True\n cnt += 1\n maxcnt = max(cnt, maxcnt)\nprint(maxcnt if n > 6 else m)\n", "passed": true, "time": 0.15, "memory": 14368.0, "status": "done"}, {"code": "n,m = [int(j) for j in input().split()]\nadj = [set() for i in range(n)]\nfor i in range(m):\n\tl, r = [int(j)-1 for j in input().split()]\n\tadj[l].add(r)\n\tadj[r].add(l)\nif n<7:\n\tprint(m)\nelse:\n\tdeg = 1e12\n\tfor i in range(n):\n\t\tfor j in range(i+1, n):\n\t\t\tl = adj[i].intersection(adj[j])\n\t\t\t# print(l)\n\t\t\ttmp = len(l)\n\t\t\tif tmp<deg:\n\t\t\t\tdeg = tmp\n\t\t# deg = min(len(adj[i]), deg)\n\t# deg = ma\n\t# print(deg)\n\tprint(m-deg)", "passed": true, "time": 0.14, "memory": 14568.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\n\na=[]\nb=[]\n\nfor _ in range(m):\n aa, bb = list(map(int, input().split()))\n if (bb < aa):\n aa,bb = bb,aa\n a.append(aa)\n b.append(bb)\n\nif (n <= 6):\n print(m)\nelse:\n \n maxv = 0\n for i in range(1, n + 1):\n for j in range(i + 1, n + 1):\n alle = m\n minuse = 0\n tk = []\n for k in range(len(a)):\n if (i == a[k] and j != b[k]):\n alle -= 1\n tk.append(b[k])\n elif (i != a[k] and j == b[k]):\n alle -= 1\n tk.append(a[k])\n elif (i == b[k] and j != a[k]):\n alle -= 1\n tk.append(a[k])\n elif (i != b[k] and j == a[k]):\n alle -= 1\n tk.append(b[k])\n #print(alle)\n #print('set' + str(len(set(tk))))\n #return\n alle += len(set(tk))\n maxv = max(alle, maxv)\n print(maxv)\n\n \n \n", "passed": true, "time": 0.14, "memory": 14604.0, "status": "done"}, {"code": "n,m = [int(j) for j in input().split()]\nadj = [set() for i in range(n)]\nfor i in range(m):\n\tl, r = [int(j)-1 for j in input().split()]\n\tadj[l].add(r)\n\tadj[r].add(l)\nif n<7:\n\tprint(m)\nelse:\n\tdeg = 10**12\n\tfor i in range(n):\n\t\tfor j in range(i+1, n):\n\t\t\tl = adj[i].intersection(adj[j])\n\t\t\ttmp = len(l)\n\t\t\tif tmp<deg:\n\t\t\t\tdeg = tmp\n\tprint(m-deg)\n", "passed": true, "time": 0.15, "memory": 14268.0, "status": "done"}, {"code": "n,m = [int(j) for j in input().split()]\nadj = [set() for i in range(n)]\nfor i in range(m):\n\tl, r = [int(j)-1 for j in input().split()]\n\tadj[l].add(r)\n\tadj[r].add(l)\nif n<7:\n\tprint(m)\nelse:\n\tmaxi = 10**12\n\tfor i in range(n):\n\t\tfor j in range(i+1, n):\n\t\t\tl = adj[i].intersection(adj[j])\n\t\t\ttmp = len(l)\n\t\t\tif tmp<maxi:\n\t\t\t\tmaxi = tmp\n\tprint(m-maxi)\n", "passed": true, "time": 0.17, "memory": 14536.0, "status": "done"}, {"code": "n,m = [int(j) for j in input().split()]\nadj = [set() for i in range(n)]\nfor i in range(m):\n\tl, r = [int(j)-1 for j in input().split()]\n\tadj[l].add(r)\n\tadj[r].add(l)\nif n<7:\n\tprint(m)\nelse:\n\tmaxi = 10**12\n\tfor i in range(n):\n\t\tfor j in range(i+1, n):\n\t\t\tl = adj[i].intersection(adj[j])\n\t\t\ttmp = len(l)\n\t\t\tif tmp<maxi:\n\t\t\t\tmaxi = tmp\n\tprint(m-maxi)\n", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "import itertools\nn,m = list(map(int,input().split()))\narr = []\nfor i in range(n):\n arr.append([])\nfor i in range(m):\n a,b = list(map(int,input().split()))\n a-=1\n b-=1\n arr[a].append(b)\n arr[b].append(a)\npermuts = list(itertools.permutations(list(range(7))))\nans = 0\nfor i in range(len(permuts)):\n permut = permuts[i]\n was = []\n for i in range(6):\n was.append([False]*6)\n c = 0\n for i in range(n):\n if permut[i] != 6:\n for g in range(len(arr[i])):\n if not permut[arr[i][g]] == 6:\n if not was[permut[i]][permut[arr[i][g]]]:\n c+=1\n was[permut[i]][permut[arr[i][g]]] = True\n was[permut[arr[i][g]]][permut[i]] = True\n for w in range(n):\n if permut[w] == 6:\n ams = [0]*6\n for g in range(len(arr[w])):\n for j in range(6):\n if not was[permut[arr[w][g]]][j]:\n ams[j]+=1\n c+=max(ams)\n break\n\n\n\n ans = max(ans,c)\nprint(ans)\n", "passed": true, "time": 2.63, "memory": 14548.0, "status": "done"}]
[{"input": "4 4\n1 2\n2 3\n3 4\n4 1\n", "output": "4\n"}, {"input": "7 0\n", "output": "0\n"}, {"input": "3 1\n1 3\n", "output": "1\n"}, {"input": "7 21\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n2 7\n3 4\n3 5\n3 6\n3 7\n4 5\n4 6\n4 7\n5 6\n5 7\n6 7\n", "output": "16\n"}, {"input": "4 4\n4 2\n2 3\n3 4\n2 1\n", "output": "4\n"}, {"input": "5 7\n4 3\n3 2\n1 4\n5 3\n5 2\n4 5\n1 5\n", "output": "7\n"}, {"input": "6 9\n2 5\n3 6\n1 2\n1 4\n2 6\n6 1\n3 4\n1 3\n5 3\n", "output": "9\n"}, {"input": "7 5\n5 6\n3 7\n7 2\n4 2\n1 4\n", "output": "5\n"}, {"input": "7 14\n7 3\n2 4\n2 1\n2 5\n5 3\n6 7\n4 7\n5 4\n7 5\n4 3\n4 1\n6 1\n6 3\n3 1\n", "output": "13\n"}, {"input": "7 15\n4 6\n7 3\n3 1\n6 5\n2 7\n3 6\n7 6\n2 6\n7 5\n3 5\n5 4\n4 7\n2 1\n2 4\n2 3\n", "output": "14\n"}, {"input": "7 18\n1 5\n5 7\n1 3\n1 6\n4 5\n3 7\n6 7\n4 7\n2 7\n1 2\n7 1\n5 6\n6 2\n4 2\n5 3\n3 6\n4 6\n4 3\n", "output": "16\n"}, {"input": "7 14\n2 7\n5 7\n3 4\n4 2\n2 3\n4 1\n6 5\n4 7\n6 2\n6 1\n5 3\n5 1\n7 6\n3 1\n", "output": "13\n"}, {"input": "7 11\n4 7\n6 4\n5 1\n1 4\n5 4\n1 2\n3 4\n4 2\n6 1\n3 1\n7 1\n", "output": "10\n"}, {"input": "7 18\n3 2\n5 3\n6 7\n7 3\n5 4\n4 6\n2 4\n7 1\n5 6\n5 2\n5 1\n3 4\n7 4\n6 1\n3 6\n7 2\n1 3\n1 2\n", "output": "15\n"}, {"input": "7 17\n1 7\n5 6\n6 3\n1 2\n1 6\n3 4\n6 7\n4 5\n1 3\n1 5\n4 1\n5 2\n3 5\n4 6\n7 5\n7 2\n6 2\n", "output": "14\n"}, {"input": "1 0\n", "output": "0\n"}, {"input": "2 0\n", "output": "0\n"}, {"input": "2 1\n2 1\n", "output": "1\n"}, {"input": "3 0\n", "output": "0\n"}, {"input": "3 2\n2 3\n1 3\n", "output": "2\n"}, {"input": "3 3\n1 2\n2 3\n1 3\n", "output": "3\n"}, {"input": "4 0\n", "output": "0\n"}, {"input": "4 2\n2 4\n1 3\n", "output": "2\n"}, {"input": "4 6\n2 1\n1 4\n2 4\n3 1\n3 2\n3 4\n", "output": "6\n"}, {"input": "5 0\n", "output": "0\n"}, {"input": "5 3\n5 1\n1 4\n5 4\n", "output": "3\n"}, {"input": "5 10\n1 2\n3 4\n1 3\n2 3\n5 4\n5 1\n4 1\n5 3\n5 2\n2 4\n", "output": "10\n"}, {"input": "6 0\n", "output": "0\n"}, {"input": "6 3\n4 2\n5 4\n4 3\n", "output": "3\n"}, {"input": "6 6\n4 3\n4 6\n1 2\n4 5\n6 3\n3 2\n", "output": "6\n"}, {"input": "6 15\n4 3\n2 1\n3 6\n1 3\n4 1\n2 3\n3 5\n4 5\n6 1\n2 5\n1 5\n2 6\n6 4\n5 6\n4 2\n", "output": "15\n"}, {"input": "6 12\n2 1\n4 3\n1 5\n6 4\n6 2\n3 6\n1 6\n2 4\n1 4\n2 5\n5 4\n1 3\n", "output": "12\n"}, {"input": "7 1\n5 3\n", "output": "1\n"}, {"input": "7 2\n5 1\n3 5\n", "output": "2\n"}, {"input": "7 3\n1 5\n5 7\n2 7\n", "output": "3\n"}, {"input": "7 4\n3 7\n7 5\n1 3\n1 6\n", "output": "4\n"}, {"input": "7 6\n3 5\n7 1\n3 7\n5 4\n7 4\n3 6\n", "output": "6\n"}, {"input": "7 7\n2 5\n6 1\n5 4\n7 2\n3 2\n4 1\n7 3\n", "output": "7\n"}, {"input": "7 8\n4 1\n5 7\n6 4\n7 1\n6 3\n3 4\n3 1\n6 7\n", "output": "8\n"}, {"input": "7 9\n2 6\n7 4\n2 5\n2 7\n4 2\n3 5\n5 6\n6 7\n7 3\n", "output": "9\n"}, {"input": "7 10\n3 6\n6 1\n4 6\n1 7\n7 4\n5 3\n5 6\n6 7\n7 5\n5 1\n", "output": "10\n"}, {"input": "7 11\n2 4\n1 3\n5 2\n2 7\n1 4\n4 3\n2 1\n7 6\n3 2\n7 4\n4 5\n", "output": "11\n"}, {"input": "7 12\n6 3\n3 5\n7 5\n1 5\n1 7\n7 6\n4 1\n2 1\n1 6\n5 6\n3 4\n4 2\n", "output": "12\n"}, {"input": "7 13\n6 5\n5 7\n4 2\n7 2\n4 1\n6 7\n4 3\n1 6\n2 5\n5 4\n2 1\n6 4\n6 2\n", "output": "13\n"}, {"input": "7 16\n3 5\n1 3\n3 7\n4 2\n1 4\n1 6\n7 6\n5 1\n7 2\n4 3\n3 6\n2 3\n2 5\n4 5\n2 6\n5 7\n", "output": "15\n"}, {"input": "7 17\n4 6\n1 7\n7 5\n3 7\n7 2\n2 5\n6 7\n1 3\n5 1\n6 2\n4 2\n3 2\n1 2\n5 3\n4 5\n3 4\n1 6\n", "output": "16\n"}, {"input": "7 19\n6 1\n6 4\n6 5\n1 7\n2 7\n3 5\n7 6\n2 4\n5 7\n3 4\n6 2\n4 1\n5 1\n4 7\n3 2\n4 5\n3 1\n2 5\n6 3\n", "output": "16\n"}, {"input": "7 20\n4 7\n1 4\n2 3\n4 3\n3 7\n7 5\n4 5\n1 2\n6 7\n3 1\n3 5\n1 5\n1 7\n2 6\n6 4\n5 2\n5 6\n6 3\n1 6\n2 7\n", "output": "16\n"}, {"input": "7 21\n3 5\n7 2\n2 3\n6 5\n5 2\n4 7\n2 6\n2 4\n6 7\n5 1\n1 4\n4 5\n5 7\n4 6\n3 1\n1 2\n3 4\n7 1\n3 7\n6 1\n3 6\n", "output": "16\n"}, {"input": "7 12\n3 4\n5 4\n1 7\n7 3\n2 5\n3 2\n1 4\n5 6\n6 1\n6 3\n2 1\n5 7\n", "output": "12\n"}, {"input": "7 7\n7 6\n4 2\n3 1\n4 7\n6 3\n2 5\n1 5\n", "output": "7\n"}, {"input": "7 6\n7 5\n5 2\n1 5\n5 4\n3 5\n6 5\n", "output": "6\n"}, {"input": "7 15\n5 1\n3 2\n2 5\n3 5\n6 1\n4 3\n6 2\n4 5\n7 5\n3 6\n3 1\n7 3\n4 6\n6 5\n6 7\n", "output": "13\n"}, {"input": "7 18\n3 7\n3 2\n2 1\n1 7\n5 1\n3 4\n5 6\n4 2\n6 2\n1 4\n2 5\n6 3\n3 1\n6 7\n6 1\n7 2\n6 4\n3 5\n", "output": "15\n"}, {"input": "7 19\n1 2\n7 3\n3 4\n4 7\n3 6\n7 5\n6 2\n4 6\n6 7\n5 2\n3 2\n6 5\n4 1\n2 4\n4 5\n6 1\n3 1\n1 7\n5 1\n", "output": "16\n"}, {"input": "7 16\n3 2\n6 3\n6 1\n5 6\n7 5\n5 2\n6 2\n2 1\n5 4\n4 1\n7 2\n1 5\n2 4\n7 3\n1 7\n6 7\n", "output": "15\n"}, {"input": "7 12\n4 1\n6 4\n3 4\n3 1\n2 4\n7 5\n5 4\n2 1\n6 7\n2 3\n7 4\n6 5\n", "output": "11\n"}]
346
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2. The finals will have n questions, m of them are auction questions and n - m of them are regular questions. Each question has a price. The price of the i-th question is a_{i} points. During the game the players chose the questions. At that, if the question is an auction, then the player who chose it can change the price if the number of his current points is strictly larger than the price of the question. The new price of the question cannot be less than the original price and cannot be greater than the current number of points of the player who chose the question. The correct answer brings the player the points equal to the price of the question. The wrong answer to the question reduces the number of the player's points by the value of the question price. The game will go as follows. First, the R2 company selects a question, then the questions are chosen by the one who answered the previous question correctly. If no one answered the question, then the person who chose last chooses again. All R2 employees support their team. They want to calculate what maximum possible number of points the R2 team can get if luck is on their side during the whole game (they will always be the first to correctly answer questions). Perhaps you are not going to be surprised, but this problem was again entrusted for you to solve. -----Input----- The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100;Β m ≀ min(n, 30)) β€” the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^7) β€” the prices of the questions. The third line contains m distinct integers b_{i} (1 ≀ b_{i} ≀ n) β€” the numbers of auction questions. Assume that the questions are numbered from 1 to n. -----Output----- In the single line, print the answer to the problem β€” the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type. -----Examples----- Input 4 1 1 3 7 5 3 Output 18 Input 3 2 10 3 8 2 3 Output 40 Input 2 2 100 200 1 2 Output 400
interview
[{"code": "n, m = list(map(int, input().split()))\nprices = list(map(int, input().split()))\nauci = list(map(int, input().split()))\n\nscores = 0\n\n# m auc\n# n - m default\n\nfor i in range(len(prices)):\n if (i+1) not in auci:\n scores += prices[i]\n prices[i] = 0\n\nra = []\nfor i in prices:\n if i != 0:\n ra.append(i)\nra.sort()\nra = ra[::-1]\n\nfor i in ra:\n if i > scores:\n scores += i\n else:\n scores *= 2\n\nprint(scores)\n#print(ra)\n", "passed": true, "time": 0.15, "memory": 14340.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nprices = list(map(int, input().split()))\nnormal = []\nauct = []\nq = list(map(int, input().split()))\nsum = 0\nfor i in range(n):\n if i + 1 in q:\n auct.append(prices[i])\n else:\n sum += prices[i]\nauct = sorted(auct, reverse=True)\nfor elem in auct:\n sum += max(elem, sum)\nprint(sum)", "passed": true, "time": 0.24, "memory": 14316.0, "status": "done"}, {"code": "n, m = map(int, input().split())\na = list(map(int, input().split()))\nnums = set(list(map(int, input().split())))\nstan = []\nauct = []\nfor i in range(len(a)):\n if i + 1 not in nums:\n stan.append(a[i])\n else:\n auct.append(a[i])\nsm = sum(stan)\nauct = list(reversed(sorted(auct)))\nfor i in range(len(auct)):\n if sm >= auct[i]:\n if sm > auct[i]:\n sm *= 2\n else:\n sm += auct[i]\n else:\n sm += auct[i]\nprint(sm)", "passed": true, "time": 0.95, "memory": 14256.0, "status": "done"}, {"code": "[n, m], q, a = list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split()))\nans = sum(q[x - 1] for x in set(range(1, n + 1)) - set(a))\nfor x in sorted(a, key = lambda x: q[x - 1], reverse = True):\n if q[x - 1] <= ans:\n ans <<= 1\n else:\n ans += q[x - 1]\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14284.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\nlst = list(map(int, input().split()))\nau = list(map(int, input().split()))\nres = sum(lst)\nls = []\nfor i in range(m): \n res -= lst[au[i] - 1]\n ls.append(lst[au[i] - 1])\nls.sort(reverse = True)\nfor i in range(len(ls)):\n res += max(ls[i], res)\nprint(res)\n", "passed": true, "time": 0.16, "memory": 14388.0, "status": "done"}, {"code": "n, m = tuple(map(int, str.split(input())))\na = tuple(map(int, str.split(input())))\nmi = tuple(map(int, str.split(input())))\nms = sorted([a[i - 1] for i in mi], reverse=True)\n\npoints = 0\nfor i, ai in enumerate(a):\n\n if i + 1 not in mi:\n\n points += ai\n\nfor m in ms:\n\n if m > points:\n\n points += m\n\n else:\n\n points += points\n\nprint(points)\n", "passed": true, "time": 0.22, "memory": 14260.0, "status": "done"}, {"code": "n,m = map(int,input().split())\nmat = list(map(int,input().split()))\nauction = list(map(int,input().split()))\naucpoint = [mat[i-1] for i in auction]\naucpoint.sort(reverse = True)\nfor i in auction:\n mat[i-1] = 0\ns = sum(mat)\nfor point in aucpoint:\n if s > point:\n s *= 2\n else: s += point\nprint(s)", "passed": true, "time": 0.14, "memory": 14376.0, "status": "done"}, {"code": "n, m = map(int, input().split())\na = list(map(int, input().split()))\nb = [a[i - 1] for i in map(int, input().split())]\nb.sort(reverse = True)\ns = sum(a) - sum(b)\nfor i in b: s += s if i < s else i\nprint(s)", "passed": true, "time": 0.95, "memory": 14480.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nques = list(map(int,input().split()))\nacutions = set(map(int, input().split()))\n\nacu = []\npoints = 0\n\nfor i in range(n):\n\tif i + 1 in acutions:\n\t\tacu.append(ques[i])\n\telse:\n\t\tpoints += ques[i]\n\nacu.sort(reverse= True)\n\nfor a in acu:\n\tif points > a:\n\t\tpoints += points\n\telse:\n\t\tpoints += a\n\nprint(points)", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "n, m = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nfor i in range(len(b)):\n b[i] -= 1\nb = set(b)\nc = []\nd = []\nfor i in range(len(a)):\n if i in b:\n c.append(a[i])\n else:\n d.append(a[i])\nsum = 0\nfor i in range(len(d)):\n sum += d[i]\nc = sorted(c)\nif sum < c[-1]:\n sum += c[-1]\n sum *= (2**(len(c)-1))\nelse:\n sum *= (2**len(c))\nprint(sum)", "passed": true, "time": 0.15, "memory": 14448.0, "status": "done"}, {"code": "n, m = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = []\nans = 0\nfor i in range(m):\n ans -= a[b[i] - 1]\n c.append(a[b[i] - 1])\nans += sum(a)\nc.sort()\nc = c[::-1]\nmx = ans\nfor i in range(m + 1):\n x = (sum(c[:i])+ans)*(2**(m-i))\n if x > mx:\n mx = x\n\nprint(mx)", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "from operator import itemgetter\nR = lambda:map(int, input().split())\nn, m = R()\na = list(R())\nb = [0] * n\nfor i in R():\n b[i - 1] = 1\na = sorted(enumerate(a), key=itemgetter(1), reverse=True)\ns = sum(x for i, x in a if b[i] != 1)\nfor i, x in a:\n if b[i] == 1:\n s += s if s > x else x\nprint(s)", "passed": true, "time": 1.01, "memory": 14272.0, "status": "done"}, {"code": "n, m = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = []\nans = 0\nfor i in range(m):\n ans -= a[b[i] - 1]\n c.append(a[b[i] - 1])\nans += sum(a)\nc.sort()\nc = c[::-1]\nmx = ans\nfor i in range(m + 1):\n x = (sum(c[:i]) + ans) * (2 ** (m - i))\n if x > mx:\n mx = x\nprint(mx)", "passed": true, "time": 0.14, "memory": 14300.0, "status": "done"}, {"code": "n, m = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = []\nans = 0\n\nfor i in range(m):\n ans -= a[b[i] - 1]\n c.append(a[b[i] - 1])\nans += sum(a)\nc.sort()\nc = c[::-1]\nmx = ans\nfor i in range(m + 1):\n x = (sum(c[:i]) + ans) * (2 ** (m - i))\n if x > mx:\n mx = x\nprint(mx)", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\"\"\"\nyl3 jeopardy\n\"\"\"\na=lambda :list(map(int,input().split()))\nn,m=a()\nsa=a()\nsb=a()\nau=[]\n\nfor i in reversed(sorted(sb)):\n au.append(sa.pop(i-1))\nsu=sum(sa)\nau.sort(reverse=True)\nfor i in range(m):\n t=au.pop(0)\n if t>su:\n su+=t\n else:su*=2\nprint(su)", "passed": true, "time": 0.14, "memory": 14528.0, "status": "done"}, {"code": "import sys\n\n\ndef main():\n n, m = list(map(int, input().split()))\n a = list(map(int, input().split()))\n auction_questions = set(map(int, input().split()))\n\n regular_a = [a[i] for i in range(len(a)) if (i + 1) not in auction_questions]\n auction_a = [a[i] for i in range(len(a)) if (i + 1) in auction_questions]\n\n total_points = sum(regular_a)\n auction_a.sort(reverse=True)\n for a in auction_a:\n if a < total_points:\n total_points += total_points\n else:\n total_points += a\n print(total_points)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "from operator import itemgetter\n\nR = lambda:list(map(int, input().split()))\n\nn, m = R()\n\na = list(R())\n\nb = [0] * n\n\nfor i in R():\n\n b[i - 1] = 1\n\na = sorted(enumerate(a), key=itemgetter(1), reverse=True)\n\ns = sum(x for i, x in a if b[i] != 1)\n\nfor i, x in a:\n\n if b[i] == 1:\n\n s += s if s > x else x\n\nprint(s)\n\n\n\n# Made By Mostafa_Khaled\n", "passed": true, "time": 0.15, "memory": 14272.0, "status": "done"}, {"code": "n, m = list(map(int, input().split(' ')))\ntmp = list(map(int, input().split(' ')))\nm_nums = list([int(x)-1 for x in input().split(' ')])\nm_list = [tmp[el] for el in m_nums]\n_sum = sum(tmp)-sum(m_list)\nm_list.sort()\nwhile (m_list) and (m_list[len(m_list)-1] > _sum): _sum += m_list.pop()\nprint(_sum * 2**(len(m_list)))\n", "passed": true, "time": 0.14, "memory": 14412.0, "status": "done"}, {"code": "n , m = map(int,input().split())\nque =list(map(int,input().split())) \nauc = list(map(int,input().split()))\ns = sum(que)\naa=[]\nfor i in auc:\n s-=que[i-1]\n aa.append(que[i-1])\naa.sort()\nfor i in aa[::-1]:\n if i<s:\n s*=2\n else:\n s+=i\nprint(s)", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "R = lambda :map(int, input().split())\nn, m = R()\na = list(R())\nb = list(R())\nli = []\ncost = 0\nfor i in range(1, n + 1):\n if i not in b:\n cost += a[i - 1]\n else:\n li.append(a[i - 1])\nli.sort(reverse=True)\nfor i in range(m):\n cost += max(cost, li[i])\nprint(cost)", "passed": true, "time": 0.14, "memory": 14476.0, "status": "done"}]
[{"input": "4 1\n1 3 7 5\n3\n", "output": "18\n"}, {"input": "3 2\n10 3 8\n2 3\n", "output": "40\n"}, {"input": "2 2\n100 200\n1 2\n", "output": "400\n"}, {"input": "1 1\n1\n1\n", "output": "1\n"}, {"input": "2 2\n1 5\n1 2\n", "output": "10\n"}, {"input": "5 3\n5 8 7 1 9\n2 5 3\n", "output": "60\n"}, {"input": "5 5\n9 1 6 2 1\n3 1 4 5 2\n", "output": "144\n"}, {"input": "25 5\n66 41 91 33 86 67 38 79 49 7 77 54 29 19 22 48 63 37 11 100 8 6 47 27 26\n12 14 1 23 18\n", "output": "29056\n"}, {"input": "50 10\n19098 20847 65754 94580 54808 57092 23130 15638 43645 52323 52822 65193 90139 69196 83680 70109 96772 35102 56685 6692 30738 74558 57144 24054 44447 51959 22847 18735 23534 821 5540 39948 7552 72425 23213 2770 98496 81096 84868 167 36408 26572 19351 82775 23225 35377 63193 58352 45111 60889\n8 20 32 17 11 44 39 30 36 16\n", "output": "1880325120\n"}, {"input": "2 1\n19 4\n1\n", "output": "23\n"}, {"input": "3 1\n65 81 6\n2\n", "output": "152\n"}, {"input": "5 1\n72 32 17 46 82\n2\n", "output": "434\n"}, {"input": "100 1\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14\n13\n", "output": "8834\n"}, {"input": "25 24\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24\n", "output": "70368752566272\n"}, {"input": "30 30\n6074511 9621540 9853685 9073323 6897794 9366449 1648254 3848902 8729661 9330982 9970280 1886362 5605123 3406494 501290 3140164 2406173 346072 1520895 441795 5271130 7576116 337766 6666108 953354 5085881 2876195 8036150 1251715 4952594\n30 5 10 28 21 18 6 13 29 23 17 24 14 25 3 27 20 26 12 2 4 11 16 15 22 7 8 19 1 9\n", "output": "5352753316495360\n"}, {"input": "50 30\n6015200 8643865 4116771 6555197 304415 8580071 8414182 3089212 5684567 7595481 1272699 7127763 3309618 1410297 4349070 2027355 136702 6863504 1800751 5585842 5924142 5188269 4805201 9313209 8941399 5137060 4983630 8467668 1646260 7804684 8646497 7067118 6896291 9109696 6197162 1366002 1703718 3852639 8427694 552915 5001315 5238093 9152085 7288325 8115109 3800240 5658858 4392321 8244056 3275379\n30 25 34 8 31 50 48 19 49 26 9 24 22 6 44 14 27 43 3 28 35 10 21 17 45 12 40 47 1 33\n", "output": "96888048737845248\n"}, {"input": "1 1\n1846236\n1\n", "output": "1846236\n"}, {"input": "2 1\n8912260 7309391\n1\n", "output": "16221651\n"}, {"input": "3 1\n9949628 37460 9989934\n3\n", "output": "19977022\n"}, {"input": "5 3\n1819638 2087365 162773 9531053 130978\n3 1 4\n", "output": "46997584\n"}, {"input": "10 4\n886062 1016649 67899 9999839 98342 64636 816991 263 1050987 1858\n1 9 7 4\n", "output": "89995888\n"}, {"input": "10 10\n1 652210 1 1 1 1 1 1 1 1\n10 1 6 7 9 8 4 3 5 2\n", "output": "333931520\n"}, {"input": "50 5\n223036 65304 301127 8945 10289 15638 260 246 68 14 23 6 3 2 8 2 1 392212 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 242747 1 1 1 243737 1 1 1 1 1 1 10000000 572890\n18 50 38 42 49\n", "output": "170000000\n"}, {"input": "50 10\n1103 17631 1582 250 6933 26 14434 6 2 1 1 1 1 1 3625 1 5909 1 1 1 1 1 1 1 1 1 1 1 1 7196 14842 1 1 1 1 1 1 12053 9999991 1 10502 1 1 1 1 1 1 1 1 1\n41 15 17 1 5 31 7 38 30 39\n", "output": "5129995264\n"}, {"input": "50 15\n369 139 49 15 4 5 1 1 1 365 1 1 1 1 484 165 105 1 1 1 382 105 1 1 1 72 1 1 91 96 1 1 1 1 1 133 9997031 1 1 31 1 1 1 291 558 1 1 1 464 1\n49 26 40 21 45 30 16 10 15 44 22 29 36 17 37\n", "output": "163801350144\n"}, {"input": "50 18\n20 23 54 4 1 1 15 50 56 1 1 71 1 1 1 1 1 15 8 1 12 1 1 1 1 1 76 1 19 11 55 42 1 1 1 1 1 9 1 30 5 1 1 1 20 1 1 1 1 9975634\n9 18 7 45 27 32 12 41 31 8 3 30 21 19 40 38 29 50\n", "output": "1307536261120\n"}, {"input": "100 1\n954110 7577191 694644 113513 467690 71415 25351 26000 37902 29150 2015 94 741 20 71 9 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n78\n", "output": "20000000\n"}, {"input": "100 5\n502646 93620 4203 12132 2444 9620 6 201 4 20 10000000 1 6 9 472804 2 2 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 276285 518136 1 1 1 1 1 1 1 1 1 1 1 1 1 1 189005 1 1 1 1 1 1 1 1 1 1 1 1\n73 72 15 88 11\n", "output": "170000000\n"}, {"input": "100 10\n9999984 1396 8798 4760 3138 310 840 41 37 79 45 1 7 2 1 1 1 1 11032 1 1 1 11226 1 1 1 1 1 1 1 12147 1 1 1 1 1 1 16512 1 1 1 1 1 1 1 1 1 1 1 2658 1 1 1 1 7562 1 1 1 1 6207 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3334 1 1 1 1 1 1 1310 1 1 1 1 1 1 1 1 1\n19 55 91 50 31 23 60 84 38 1\n", "output": "5129991680\n"}, {"input": "100 15\n380 122 2 18 5 2 3 242 1 1 1 1 1 64 1 1 1 1 1 198 323 284 1 419 1 225 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 584 1 1 1 55 9999036 1 1 1 1 1 1 1 1 447 1 1 471 1 1 1 1 1 1 1 374 1 1 1 1 1 1 1 1 1 1 1 273 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 68 1\n22 45 49 24 26 62 70 82 21 20 59 14 99 8 50\n", "output": "163834200064\n"}, {"input": "100 16\n15 18 54 132 138 1 1 45 164 1 1 1 1 1 1 1 1 1 1 1 1 9999567 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 188 1 1 1 213 1 1 27 1 1 1 1 1 1 1 1 1 1 1 200 1 140 221 1 1 1 1 1 1 1 1 132 1 78 1 1 1 1 1 243 1 1 1 1 1 1 1 1 1 1 240 1 1 290 1 34 1 1 1 1 1 1\n92 46 8 58 94 39 9 89 61 60 4 70 78 72 43 22\n", "output": "327675805696\n"}, {"input": "3 1\n1 2 4\n1\n", "output": "12\n"}, {"input": "3 1\n1 2 4\n2\n", "output": "10\n"}, {"input": "3 1\n1 2 4\n3\n", "output": "7\n"}, {"input": "2 1\n1 2\n1\n", "output": "4\n"}, {"input": "2 1\n1 2\n2\n", "output": "3\n"}, {"input": "3 2\n1 2 4\n1 2\n", "output": "16\n"}, {"input": "3 2\n1 2 4\n3 2\n", "output": "10\n"}, {"input": "3 2\n1 2 4\n3 1\n", "output": "12\n"}, {"input": "3 3\n4 2 1\n1 3 2\n", "output": "16\n"}, {"input": "5 4\n1 2 2 4 8\n1 2 4 5\n", "output": "80\n"}, {"input": "3 2\n10 7 1000\n2 3\n", "output": "2020\n"}, {"input": "4 2\n2 2 4 8\n3 4\n", "output": "24\n"}, {"input": "3 2\n1 3 5\n1 3\n", "output": "16\n"}, {"input": "3 2\n10 1 12\n2 3\n", "output": "44\n"}, {"input": "4 2\n1 2 3 100\n2 4\n", "output": "208\n"}, {"input": "3 2\n10 5 200\n2 3\n", "output": "420\n"}, {"input": "3 2\n3 5 3\n2 3\n", "output": "16\n"}, {"input": "3 2\n5 4 100\n2 3\n", "output": "210\n"}, {"input": "5 4\n100 200 300 400 500\n1 2 3 5\n", "output": "7200\n"}, {"input": "3 2\n100 200 180\n1 2\n", "output": "760\n"}, {"input": "4 3\n2 5 17 4\n1 2 3\n", "output": "84\n"}, {"input": "5 2\n2 2 4 7 15\n4 5\n", "output": "46\n"}, {"input": "3 2\n200 100 1000\n2 3\n", "output": "2400\n"}, {"input": "4 2\n2 2 2 7\n1 4\n", "output": "22\n"}, {"input": "8 4\n2 2 2 2 1 2 3 9\n5 6 7 8\n", "output": "136\n"}, {"input": "3 2\n2 1 5\n2 3\n", "output": "14\n"}]
347
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score. Codeforces scores are computed as follows: If the maximum point value of a problem is x, and Kevin submitted correctly at minute m but made w wrong submissions, then his score on that problem is $\operatorname{max}(0.3 x,(1 - \frac{m}{250}) x - 50 w)$. His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack. All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer. -----Input----- The first line of the input contains five space-separated integers m_1, m_2, m_3, m_4, m_5, where m_{i} (0 ≀ m_{i} ≀ 119) is the time of Kevin's last submission for problem i. His last submission is always correct and gets accepted. The second line contains five space-separated integers w_1, w_2, w_3, w_4, w_5, where w_{i} (0 ≀ w_{i} ≀ 10) is Kevin's number of wrong submissions on problem i. The last line contains two space-separated integers h_{s} and h_{u} (0 ≀ h_{s}, h_{u} ≀ 20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively. -----Output----- Print a single integer, the value of Kevin's final score. -----Examples----- Input 20 40 60 80 100 0 1 2 3 4 1 0 Output 4900 Input 119 119 119 119 119 0 0 0 0 0 10 0 Output 4930 -----Note----- In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets $(1 - \frac{119}{250}) = \frac{131}{250}$ of the points on each problem. So his score from solving problems is $\frac{131}{250}(500 + 1000 + 1500 + 2000 + 2500) = 3930$. Adding in 10Β·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930.
interview
[{"code": "m = list(map(int, input().split()))\nw = list(map(int, input().split()))\na = [500, 1000, 1500, 2000, 2500]\nv = list(map(int, input().split()))\nans = 0\nfor i in range(len(m)):\n ans += max(0.3 * a[i], (1 - m[i] / 250) * a[i] - 50 * w[i])\nans += v[0] * 100\nans -= v[1] * 50\nprint(int(ans))\n", "passed": true, "time": 0.24, "memory": 14544.0, "status": "done"}, {"code": "a = [int(i) for i in input().split()]\nb = [int(i) for i in input().split()]\nc = [int(i) for i in input().split()]\nans = c[0] * 100 - c[1] * 50\nfor i in range(5):\n ans += max(0.3 * (i + 1) * 500, (1 - a[i] / 250) * (i + 1) * 500 - 50 * b[i])\nprint(round(ans))", "passed": true, "time": 0.15, "memory": 14496.0, "status": "done"}, {"code": "M = list(map(int,input().split()))\nW = list(map(int,input().split()))\ns,e = list(map(int, input().split()))\nP = [500,1000,1500,2000,2500]\nr = 0\nfor k in range(5):\n r += max([0.3*P[k],(1-(M[k]/250))*P[k] - 50*W[k]])\nprint(int(r+100*s-50*e))\n", "passed": true, "time": 0.24, "memory": 14460.0, "status": "done"}, {"code": "def g(w,m,x):\n return max(0.3*x,(1-m/250)*x-50*w)\n\n\nm1,m2,m3,m4,m5=map(int,input().split())\nw1,w2,w3,w4,w5=map(int,input().split())\nh1,h2=map(int,input().split())\nprint(int(g(w1,m1,500)+g(w2,m2,1000)+g(w3,m3,1500)+g(w4,m4,2000)+g(w5,m5,2500)+h1*100-h2*50))", "passed": true, "time": 0.25, "memory": 14368.0, "status": "done"}, {"code": "m = list(map(int, input().split()))\nw = list(map(int, input().split()))\nq = [500, 1000, 1500, 2000, 2500]\ns = 0\nfor i in range(5):\n s += max(0.3 * q[i], (1 - m[i] / 250) * q[i] - 50 * w[i])\nh1, h2 = list(map(int, input().split()))\ns += 100 * h1\ns -= 50 * h2\nprint(int(s))\n", "passed": true, "time": 0.25, "memory": 14444.0, "status": "done"}, {"code": "ans = 0;\ntime = list(map(int,input().split()))\ntries = list(map(int,input().split()))\nball = [500,1000,1500,2000,2500]\nz = list(map(int,input().split()))\ngv = z[0]\nbv = z[1]\nfor i in range(0,5):\n ans += max(0.3*ball[i],(1-time[i]/250)*ball[i] - 50*tries[i])\n \n \nans += 100*gv\nans -= 50*bv\nprint(int(ans))\n", "passed": true, "time": 0.15, "memory": 14480.0, "status": "done"}, {"code": "max_scores = [ 500, 1000, 1500, 2000, 2500 ]\ncorects = [ int(c) for c in input().split() ]\nwrongs = [ int(w) for w in input().split() ]\nshacks, unshacks = map(int, input().split())\nfinal_score = shacks*100 - unshacks*50\n\ndef score(x, m, w):\n return max(0.3*x, (1-(m/250))*x-50*w)\n\nfor i in range(5):\n final_score += score(max_scores[i], corects[i], wrongs[i])\nprint(int(final_score))", "passed": true, "time": 0.24, "memory": 14432.0, "status": "done"}, {"code": "def score(m, w, x):\n return max(0.3*x, (1.0 - m/250) * x - 50*w)\n\nms = list(map(int, input().split()))\nws = list(map(int, input().split()))\nhs, hu = list(map(int, input().split()))\n\nscore = sum(score(m, w, x) for m, w, x in zip(ms, ws, [500,1000,1500,2000,2500]))\nprint(int(score + 100 * hs - 50 * hu))\n", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "def score(m,w,x):\n return max(0.3*x,(1-m/250)*x-50*w)\nm1,m2,m3,m4,m5=(list(map(int,input().split())))\nw1,w2,w3,w4,w5=(list(map(int,input().split())))\nhs,hu=(list(map(int,input().split())))\nx1,x2,x3,x4,x5=(500,1000,1500,2000,2500)\nprint(round(score(m1,w1,x1)+score(m2,w2,x2)+score(m3,w3,x3)+score(m4,w4,x4)+score(m5,w5,x5))+100*hs-50*hu)\n", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "m = list(map(int, input().split()))\nw = list(map(int, input().split()))\nn1, n2 = list(map(int, input().split()))\nans = n1 * 100 - n2 * 50\nfor i in range(5):\n col = 500 * (i + 1)\n ans += max(0.3 * col, (1 - m[i] / 250) * col - 50 * w[i])\nprint(int(ans))\n", "passed": true, "time": 0.24, "memory": 14356.0, "status": "done"}, {"code": "x = [500, 1000, 1500, 2000, 2500]\nm = list(map(int, input().split()))\nw = list(map(int, input().split()))\nhs, hu = map(int, input().split())\nprint(sum(max(3 * x[i] // 10, x[i] - x[i] * m[i] // 250 - 50 * w[i]) for i in range(5)) + hs * 100 - hu * 50)", "passed": true, "time": 0.14, "memory": 14476.0, "status": "done"}, {"code": "point = [500, 1000, 1500, 2000, 2500]\nminutes = list(map(int, input().split()))\nwrong = list(map(int, input().split()))\nhack = list(map(int, input().split()))\nanswer = 0\n\nfor x, m, w in zip(point, minutes, wrong):\n answer += max(0.3 * x, (1 - m / 250) * x - 50 * w)\n\nanswer += hack[0] * 100 - hack[1] * 50\n\nprint(int(answer))\n", "passed": true, "time": 0.16, "memory": 14432.0, "status": "done"}, {"code": "import sys\n\narr1 = [int(x) for x in sys.stdin.readline().split()]\narr2 = [int(x) for x in sys.stdin.readline().split()]\nbase = [500, 1000, 1500, 2000, 2500]\nres = 0\n\nfor i in range(5):\n res += max([0.3 * base[i], base[i] * (1 - arr1[i] / 250) - 50 * arr2[i]])\n\na, b = [int(x) for x in sys.stdin.readline().split()]\nres += 100 * a\nres -= 50 * b\n\nprint(int(res))\n", "passed": true, "time": 0.15, "memory": 14504.0, "status": "done"}, {"code": "times = list(map(int, input().split()))\natt = list(map(int, input().split()))\nn,m = list(map(int, input().split()))\nsc = 0\nfor i in range(5):\n\tsc += max ( 150 * (i+1), ( 1 - times[i] / 250 ) * 500 * (i+1) - 50 * att[i] )\nsc += 100 * n \nsc -= 50 * m\nprint(int(sc)) \n\n", "passed": true, "time": 0.24, "memory": 14456.0, "status": "done"}, {"code": "m = list(map(int, input().split()))\nw = list(map(int, input().split()))\nh = [500, 1000, 1500, 2000, 2500]\ns, u = list(map(int, input().split()))\nsu = 0.0\nfor i in range(5):\n su += max(0.3*h[i], (1.0-m[i]/250.0)*h[i] - 50.0*w[i])\nsu += s*100.0\nsu -= u*50.0\nprint(int(su))\n", "passed": true, "time": 0.24, "memory": 14380.0, "status": "done"}, {"code": "res = 0\nc = [500,1000,1500,2000,2500]\na = list(map(int,input().split()))\nw = list(map(int,input().split()))\nhs,hu = map(int,input().split())\nfor i in range(5):\n res += max(0.3*c[i],(1-a[i]/250)*c[i]-50*w[i])\nprint(int(res+hs*100-50*hu))", "passed": true, "time": 0.14, "memory": 14304.0, "status": "done"}, {"code": "def __starting_point():\n\n x = [500,1000,1500,2000,2500]\n m = [int(x) for x in input().split()]\n w = [int(x) for x in input().split()]\n hs , hu = [int(x) for x in input().split()]\n\n res = 0\n for i in range(5):\n res += max( 3*x[i]//10 , x[i] - m[i]*x[i]//250 - 50*w[i] )\n res += 100*hs\n res -= 50*hu\n print(res)\n__starting_point()", "passed": true, "time": 0.14, "memory": 14416.0, "status": "done"}, {"code": "def main():\n mode=\"filee\"\n if mode==\"file\":f=open(\"test.txt\",\"r\")\n get = lambda :[int(x) for x in (f.readline() if mode==\"file\" else input()).split()]\n m=get()\n w=get()\n h=get()\n ans=0\n s=500\n for i in range(5):\n ans+=max(0.3*s, (1- m[i]/250)*s - 50*w[i])\n s+=500\n ans+=(100*h[0] - 50*h[1])\n print(int(ans))\n \n\n\n if mode==\"file\":f.close()\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14388.0, "status": "done"}, {"code": "sc=[1]*10\nmrk=input().split()\nfor i in range (0,5):\n mrk[i]=int(mrk[i])\n sc[i]=500*(i+1)\nwr=input().split()\nfor i in range (0,5):\n wr[i]=int(wr[i])\ns=0\nfor i in range (0,5):\n s+=max((0.3*sc[i]),(1-(mrk[i]/250))*sc[i]-(50*wr[i]))\nl=input().split()\ns+=100*int(l[0])-50*int(l[1])\nprint(int(s))\n\n", "passed": true, "time": 0.16, "memory": 14324.0, "status": "done"}, {"code": "problems = [ 500, 1000, 1500, 2000, 2500 ]\nsubmitted = list(map(int, input().split()))\nwrong = list(map(int, input().split()))\n\nscore = 0\nfor pos, x in enumerate(problems):\n m = submitted[pos]\n w = wrong[pos]\n score += max( 3 * x // 10, x - m * x // 250 - 50 * w )\n\ngood, bad = list(map(int, input().split()))\nscore += good * 100 - bad * 50\n\nprint(score)\n", "passed": true, "time": 0.15, "memory": 14252.0, "status": "done"}, {"code": "xs = [500, 1000, 1500, 2000, 2500]\nms = [int(x) for x in input().split()]\nws = [int(x) for x in input().split()]\nhacks = [int(x) for x in input().split()]\n\nres = 0\nfor i in range(len(xs)):\n problem = max(0.3 * xs[i], (1 - ms[i]/250) * xs[i] - 50*ws[i])\n res += problem\n\nres += 100*hacks[0] - 50*hacks[1]\nprint(int(res))\n", "passed": true, "time": 0.14, "memory": 14300.0, "status": "done"}, {"code": "m = list(map(int, input().split()))\nw = list(map(int, input().split()))\nhs, hu = map(int, input().split())\n\ns = [500 * (x + 1) for x in range(5)]\n\nfor i in range(5):\n s[i] = max(0.3 * s[i], (1 - m[i]/250) * s[i] - 50 * w[i])\n\ns_t = sum(s) + 100 * hs - 50 * hu\n\nprint(int(s_t))", "passed": true, "time": 0.15, "memory": 14332.0, "status": "done"}, {"code": "m = list(map(int, input().split(\" \")))\nw = list(map(int, input().split(\" \")))\n\nhs, hu = list(map(int, input().split(\" \")))\n\ns = 0\n\ns += hs*100 - hu*50\n\nfor i in range(5):\n s+= max(0.3*((i+1)*500), (1-m[i]/250)*((i+1)*500) - 50*w[i])\n \nprint(int(s))\n", "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 c = list(map(int, input().split()))\n z = [500, 1000, 1500, 2000, 2500]\n total = 0\n for _ in range(5):\n total += max(0.3 * z[_], (1 - a[_] / 250) * z[_] - 50 * b[_])\n total += 100 * c[0] - 50 * c[1]\n\n print(int(total))\n\n\n\n\n\n\nfor _ in range(T):\n process()\n", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}]
[{"input": "20 40 60 80 100\n0 1 2 3 4\n1 0\n", "output": "4900\n"}, {"input": "119 119 119 119 119\n0 0 0 0 0\n10 0\n", "output": "4930\n"}, {"input": "3 6 13 38 60\n6 10 10 3 8\n9 9\n", "output": "5088\n"}, {"input": "21 44 11 68 75\n6 2 4 8 4\n2 8\n", "output": "4522\n"}, {"input": "16 112 50 114 68\n1 4 8 4 9\n19 11\n", "output": "5178\n"}, {"input": "55 66 75 44 47\n6 0 6 6 10\n19 0\n", "output": "6414\n"}, {"input": "47 11 88 5 110\n6 10 4 2 3\n10 6\n", "output": "5188\n"}, {"input": "5 44 61 103 92\n9 0 10 4 8\n15 7\n", "output": "4914\n"}, {"input": "115 53 96 62 110\n7 8 1 7 9\n7 16\n", "output": "3416\n"}, {"input": "102 83 26 6 11\n3 4 1 8 3\n17 14\n", "output": "6704\n"}, {"input": "36 102 73 101 19\n5 9 2 2 6\n4 13\n", "output": "4292\n"}, {"input": "40 115 93 107 113\n5 7 2 6 8\n6 17\n", "output": "2876\n"}, {"input": "53 34 53 107 81\n4 3 1 10 8\n7 7\n", "output": "4324\n"}, {"input": "113 37 4 84 66\n2 0 10 3 0\n20 19\n", "output": "6070\n"}, {"input": "10 53 101 62 1\n8 0 9 7 9\n0 11\n", "output": "4032\n"}, {"input": "45 45 75 36 76\n6 2 2 0 0\n8 17\n", "output": "5222\n"}, {"input": "47 16 44 78 111\n7 9 8 0 2\n1 19\n", "output": "3288\n"}, {"input": "7 54 39 102 31\n6 0 2 10 1\n18 3\n", "output": "6610\n"}, {"input": "0 46 86 72 40\n1 5 5 5 9\n6 5\n", "output": "4924\n"}, {"input": "114 4 45 78 113\n0 4 8 10 2\n10 12\n", "output": "4432\n"}, {"input": "56 56 96 105 107\n4 9 10 4 8\n2 1\n", "output": "3104\n"}, {"input": "113 107 59 50 56\n3 7 10 6 3\n10 12\n", "output": "4586\n"}, {"input": "96 104 9 94 84\n6 10 7 8 3\n14 11\n", "output": "4754\n"}, {"input": "98 15 116 43 55\n4 3 0 9 3\n10 7\n", "output": "5400\n"}, {"input": "0 26 99 108 35\n0 4 3 0 10\n9 5\n", "output": "5388\n"}, {"input": "89 24 51 49 84\n5 6 2 2 9\n2 14\n", "output": "4066\n"}, {"input": "57 51 76 45 96\n1 0 4 3 6\n12 15\n", "output": "5156\n"}, {"input": "79 112 37 36 116\n2 8 4 7 5\n4 12\n", "output": "3872\n"}, {"input": "71 42 60 20 7\n7 1 1 10 6\n1 7\n", "output": "5242\n"}, {"input": "86 10 66 80 55\n0 2 5 10 5\n15 6\n", "output": "5802\n"}, {"input": "66 109 22 22 62\n3 1 5 4 5\n10 5\n", "output": "5854\n"}, {"input": "97 17 43 84 58\n2 8 3 8 6\n10 7\n", "output": "5028\n"}, {"input": "109 83 5 114 104\n6 0 3 9 5\n5 2\n", "output": "4386\n"}, {"input": "94 18 24 91 105\n2 0 7 10 3\n1 4\n", "output": "4118\n"}, {"input": "64 17 86 59 45\n8 0 10 2 2\n4 4\n", "output": "5144\n"}, {"input": "70 84 31 57 2\n7 0 0 2 7\n12 5\n", "output": "6652\n"}, {"input": "98 118 117 86 4\n2 10 9 7 5\n11 15\n", "output": "4476\n"}, {"input": "103 110 101 97 70\n4 2 1 0 5\n7 5\n", "output": "4678\n"}, {"input": "78 96 6 97 62\n7 7 9 2 9\n10 3\n", "output": "4868\n"}, {"input": "95 28 3 31 115\n1 9 0 7 3\n10 13\n", "output": "5132\n"}, {"input": "45 17 116 58 3\n8 8 7 6 4\n3 19\n", "output": "3992\n"}, {"input": "19 12 0 113 77\n3 0 10 9 2\n8 6\n", "output": "5040\n"}, {"input": "0 0 0 0 0\n0 0 0 0 0\n0 0\n", "output": "7500\n"}, {"input": "0 0 0 0 0\n0 0 0 0 0\n20 0\n", "output": "9500\n"}, {"input": "119 119 119 119 119\n10 10 10 10 10\n0 20\n", "output": "1310\n"}, {"input": "0 0 0 0 0\n10 10 10 10 10\n0 20\n", "output": "4150\n"}, {"input": "119 0 0 0 0\n10 0 0 0 0\n5 5\n", "output": "7400\n"}, {"input": "0 119 0 0 0\n0 10 0 0 0\n5 5\n", "output": "7050\n"}, {"input": "0 0 119 0 0\n0 0 10 0 0\n0 0\n", "output": "6450\n"}, {"input": "0 0 0 119 0\n0 0 0 10 0\n5 5\n", "output": "6350\n"}, {"input": "0 0 0 0 119\n0 0 0 0 10\n5 5\n", "output": "6060\n"}, {"input": "119 0 0 0 0\n2 0 0 0 0\n5 5\n", "output": "7412\n"}, {"input": "0 119 0 0 0\n0 2 0 0 0\n5 5\n", "output": "7174\n"}, {"input": "0 0 119 0 0\n0 0 2 0 0\n5 5\n", "output": "6936\n"}, {"input": "0 0 0 119 0\n0 0 0 2 0\n5 5\n", "output": "6698\n"}, {"input": "0 0 0 0 119\n0 0 0 0 2\n5 5\n", "output": "6460\n"}, {"input": "119 0 0 0 0\n0 0 0 0 0\n4 9\n", "output": "7212\n"}]
348
Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an $n \times m$ grid. Initially $a_{i,j}$ cubes are stacked up in the cell $(i,j)$. Two cells are called adjacent if they share a side. Player can perform the following operations: stack up one cube in two adjacent cells; stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. [Image] Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that $L \le a_{i,j} \le R$ for all $1 \le i \le n$, $1 \le j \le m$; player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo $998,244,353$. -----Input----- The only line contains four integers $n$, $m$, $L$ and $R$ ($1\le n,m,L,R \le 10^9$, $L \le R$, $n \cdot m \ge 2$). -----Output----- Output one integer, representing the desired answer modulo $998,244,353$. -----Examples----- Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 -----Note----- In the first sample, the only initial grid that satisfies the requirements is $a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1$. Thus the answer should be $1$. In the second sample, initial grids that satisfy the requirements are $a_{1,1}=a_{1,2}=1$ and $a_{1,1}=a_{1,2}=2$. Thus the answer should be $2$.
interview
[{"code": "n,m,L,R = list(map(int,input().split()))\np = 998244353*2\npp = p//2\n#liczba pokryc n x m ze jest parzyscie wiele zer albo parzyscie wiele jedynek\ndef pow(a,w):\n\twyn = 1\n\tmn = a\n\twhile w > 0:\n\t\tif w%2 == 1:\n\t\t\twyn = (wyn * mn)%p\n\t\tmn = (mn*mn)%p\n\t\tw //= 2\n\treturn wyn\ndupsko = pow((R-L+1), m*n)\nif L == R:\n\tprint(1) \nelse:\n\tif (m*n)%2 == 1:\n\t\tprint(dupsko%pp)\n\telse:\n\t\tprint((dupsko - dupsko//2)%pp)\n", "passed": true, "time": 0.18, "memory": 14516.0, "status": "done"}, {"code": "n, m, L, R = map(int, input().split())\nmod = 998244353\nif n*m % 2:\n print(pow(R-L+1, n*m, mod))\nelse:\n print((pow(R-L+1, n*m, mod) + 1 - (R-L) % 2) * pow(2, mod-2, mod) % mod)", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "import sys\nreadline = sys.stdin.readline\n\ndef mat_dot(A, B, mod):\n assert len(A[0]) == len(B), 'invalid_size'\n \n L = len(A)\n M = len(A[0])\n N = len(B[0])\n \n res = [[0]*N for _ in range(L)]\n \n for i in range(L):\n for j in range(N):\n a = 0\n for k in range(M):\n a = (a+A[i][k]*B[k][j]) % mod\n res[i][j] = a\n \n return res\n\ndef mat_pow(A, x, mod):\n N = len(A)\n res = [[0]*N for _ in range(N)]\n for i in range(N):\n res[i][i] = 1\n for i in range(x.bit_length()):\n if 2**i & x:\n res = mat_dot(res, A, mod)\n A = mat_dot(A, A, mod)\n return res\n\nMOD = 998244353 \nN, M, L, R = map(int, readline().split())\nR -= L\nif N&1 and M&1:\n ans = pow(R+1, N*M, MOD)\nelse:\n Bl = N*M//2\n even = (R+1)//2\n odd = R+1 - even\n Mat = [[even, odd], [odd, even]]\n xy = mat_dot(mat_pow(Mat, Bl, MOD), [[1], [0]], MOD)\n x, y = xy[0][0], xy[1][0]\n ans = (x*x + y*y) % MOD\n \nprint(ans)", "passed": true, "time": 0.23, "memory": 14380.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\nn,m,L,R=list(map(int,input().split()))\nmod=998244353\n\nANS=pow(R-L+1,n*m,mod)\nif n*m%2==1:\n print(ANS)\n\nelif (R-L+1)%2==0:\n print(ANS*pow(2,mod-2,mod)%mod)\nelse:\n print((ANS+1)*pow(2,mod-2,mod)%mod)\n \n \n\n\n \n", "passed": true, "time": 0.15, "memory": 14348.0, "status": "done"}, {"code": "MOD = 998244353\nn, m, l, r = map(int, input().split())\nk = r-l\nif (n*m) % 2 == 1:\n\tprint(pow(k+1, n*m, MOD))\nelif k%2 == 1:\n\tprint((pow(k+1, n*m, MOD) * 499122177) % MOD)\nelse:\n\tprint(((pow(k+1, n*m, MOD) + 1) * 499122177) % MOD)", "passed": true, "time": 0.14, "memory": 14332.0, "status": "done"}, {"code": "n, m, L, R = list(map(int, input().split()))\nmod = 998244353\nif n * m % 2 == 1:\n print(pow(R - L + 1, n * m, mod))\nelse:\n val = pow(R - L + 1, n * m, mod)\n if pow(R - L + 1, n * m, 2) == 0:\n print(val * pow(2, mod - 2, mod) % mod)\n else:\n print(((val - 1) * pow(2, mod - 2, mod) + 1) % mod)\n", "passed": true, "time": 0.7, "memory": 14308.0, "status": "done"}, {"code": "MOD = 998244353\n\nn, m, L, R = map(int, input().split())\n\ndx = R - L + 1\n\nif n * m % 2:\n\tprint(pow(dx, n * m, MOD))\n\nelse:\n\tprint((pow(dx, n * m, MOD) + dx % 2) * pow(2, MOD - 2, MOD) % MOD)", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "def main():\n import sys\n input = sys.stdin.readline\n\n N, M, L, R = list(map(int, input().split()))\n mod = 998244353\n\n ans = pow((R-L+1)%mod, N*M, mod)\n if N&1 and M&1:\n print(ans)\n else:\n if (R-L+1)&1:\n print(((ans + 1) * pow(2, mod - 2, mod)) % mod)\n else:\n print((ans * pow(2, mod-2, mod))%mod)\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14420.0, "status": "done"}, {"code": "import sys\ninput=lambda: sys.stdin.readline().rstrip()\nn,m,l,r=list(map(int,input().split()))\nmod=998244353\nif (n*m)%2==1:\n b,w=(n*m)//2+1,(n*m)//2\nelse:\n b,w=(n*m)//2,(n*m)//2\n\nif (r-l+1)%2==0:\n e,o=(r-l+1)//2,(r-l+1)//2\nelse:\n if l%2==1:\n e,o=(r-l+1)//2,(r-l+1)//2+1\n else:\n e,o=(r-l+1)//2+1,(r-l+1)//2\n\nbe=(pow(e+o,b,mod)+pow(e-o,b,mod))*pow(2,mod-2,mod)\nbo=(pow(e+o,b,mod)-pow(e-o,b,mod))*pow(2,mod-2,mod)\nwe=(pow(e+o,w,mod)+pow(e-o,w,mod))*pow(2,mod-2,mod)\nwo=(pow(e+o,w,mod)-pow(e-o,w,mod))*pow(2,mod-2,mod)\n\nif (n*m)%2==1:\n print(pow(r-l+1,n*m,mod))\nelse:\n print((be*we+bo*wo)%mod)\n\n", "passed": true, "time": 0.14, "memory": 14428.0, "status": "done"}, {"code": "mod = 998244353\nn,m,l,r = list(map(int,input().split()))\n\nif (n * m) % 2 == 1:\n res = pow(r - l + 1, n * m, mod)\n print(res)\n return\n\ndef f(p):\n return p // 2\n\ndef g(p):\n return (p + 1) // 2\n\n# \u5076\u6570\neven = f(r) - f(l - 1)\nodd = g(r) - g(l - 1)\n\nres = (pow(even - odd, n * m, mod) + pow(even + odd, n * m, mod)) * pow(2, mod - 2, mod)\nres %= mod\nprint(res)\n", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "from bisect import bisect_left, bisect_right\nfrom sys import stdin, stdout, setrecursionlimit\nfrom collections import Counter\ninput = lambda: stdin.readline().strip()\nprint = stdout.write\n\nmod = 998244353\n\nn, m, L, R = map(int, input().split())\n# odd\nif (n*m)%2:\n print(str(pow(R-L+1, n*m, mod))+'\\n')\nelse:\n nm = n*m\n # both odd\n if L%2 and R%2:\n even = (R-L)//2\n # R even\n elif L%2 and not R%2:\n even = (R-L+1)//2\n # L even\n elif not L%2 and R%2:\n even = (R-L+1)//2\n # both even\n else:\n even = (R-L)//2+1\n odd = (R-L+1)-even\n N = (pow(odd+even, nm, mod)+pow(abs(odd-even), nm, mod))%mod\n print(str((pow(2, mod-2, mod)*N)%mod)+'\\n')\n", "passed": true, "time": 0.14, "memory": 14520.0, "status": "done"}, {"code": "n,m,L,R=map(int,input().split())\nk=R-L+1\nif (n*m)%2:\n print(pow(k,n*m,998244353))\nelse:\n r=pow(k,n*m,998244353)\n if k%2:\n if r%2:print(((r+1)//2)%998244353)\n else:print(((r+1+998244353)//2)%998244353)\n else:\n if r%2==0:print(r//2)\n else:print((r+998244353)//2)", "passed": true, "time": 0.23, "memory": 14448.0, "status": "done"}, {"code": "#!/usr/bin/env python3\nimport sys\ninput = sys.stdin.readline\nMOD = 998244353\n\nn, m, l, r = map(int, input().split())\nh = r - l + 1\n\ns = n * m\nif s % 2 == 1:\n ans = pow(h, s, MOD)\n print(ans)\nelse:\n ans = pow(h, s, MOD)\n if h % 2 == 1:\n ans += 1\n ans *= pow(2, MOD-2, MOD)\n ans %= MOD\n print(ans)", "passed": true, "time": 0.14, "memory": 14492.0, "status": "done"}, {"code": "def expo(a,n):\n #print(a)\n #print(n)\n if n>0:\n ha = expo(a,n//2)\n if n%2==1:\n return (ha*ha*a)%MOD\n else:\n return (ha*ha)%MOD\n else:\n return 1\nMOD = 998244353\ndef f():\n n,m,L,R = list(map(int,input().split(\" \")))\n height = R-L+1\n area = n*m\n ans = expo(height,area)\n #print(ans)\n if(area%2==1):\n print(ans)\n else:\n if(height%2==0):\n if ans%2==1:\n ans+=MOD\n ans//=2\n print(ans%MOD)\n else:\n if ans%2==0:\n ans+=MOD\n ans = (ans+1)//2\n print(ans%MOD)\nf()\n", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "mod = 119 << 23 | 1\nn, m, l, r = list(map(int, input().split()))\na = (r + 1) // 2 - l // 2\nb = r - l + 1 - a\nif a > b: a, b = b, a\nt = n * m\nif t % 2:\n print(pow(a + b, t, mod))\nelif a == b:\n print(pow(a, t, mod) * pow(2, t - 1, mod) % mod)\nelse:\n print(pow(2, mod - 2, mod) * (1 + pow(2 * a + 1, t, mod)) % mod)\n", "passed": true, "time": 0.14, "memory": 14460.0, "status": "done"}]
[{"input": "2 2 1 1\n", "output": "1\n"}, {"input": "1 2 1 2\n", "output": "2\n"}, {"input": "485 117 386829368 748204956\n", "output": "735420370\n"}, {"input": "564 558 305171115 960941497\n", "output": "880111542\n"}, {"input": "692 210 44175861 843331069\n", "output": "714028205\n"}, {"input": "741 806 424647372 965259389\n", "output": "861647194\n"}, {"input": "461 650 18427925 104278996\n", "output": "936348652\n"}, {"input": "589 790 462465375 766499149\n", "output": "374887989\n"}, {"input": "13 635 761278633 941090619\n", "output": "893955177\n"}, {"input": "140 713 711390561 727285861\n", "output": "641355762\n"}, {"input": "494587372 852064625 134519483 167992226\n", "output": "552905694\n"}, {"input": "672670796 425613469 728300037 940234946\n", "output": "779704132\n"}, {"input": "850754220 853938121 172337487 490664825\n", "output": "237240423\n"}, {"input": "28837644 722454262 471150744 905552093\n", "output": "740846915\n"}, {"input": "911953772 296003106 210155490 889555498\n", "output": "225799480\n"}, {"input": "795069900 869551950 803936044 964554424\n", "output": "884379548\n"}, {"input": "268120620 443100795 102749301 604856694\n", "output": "834319192\n"}, {"input": "151236748 16649639 841754047 855153000\n", "output": "108988868\n"}, {"input": "329320172 739941588 435534601 986184053\n", "output": "425887732\n"}, {"input": "1000000000 1 1000000000 1000000000\n", "output": "1\n"}, {"input": "1 1000000000 1 1000000000\n", "output": "285141888\n"}, {"input": "407070359 971940670 264302148 270591105\n", "output": "992759231\n"}, {"input": "290186487 840456810 858082702 987072033\n", "output": "366829057\n"}, {"input": "763237207 414005655 302120151 421405724\n", "output": "193545831\n"}, {"input": "646353335 282521795 600933409 772270276\n", "output": "13680108\n"}, {"input": "824436759 415879151 194713963 293553316\n", "output": "453443939\n"}, {"input": "707552887 989427996 933718708 955125306\n", "output": "355610620\n"}, {"input": "885636311 857944136 232531966 493119835\n", "output": "779245677\n"}, {"input": "63719735 431492981 971536712 994663491\n", "output": "97582142\n"}, {"input": "946835863 300009121 565317265 947272048\n", "output": "337235143\n"}, {"input": "124919287 578590669 9354715 32571540\n", "output": "263200129\n"}, {"input": "202669473 255300152 987865366 994537507\n", "output": "926661352\n"}, {"input": "2 2 1 998244353\n", "output": "499122177\n"}, {"input": "2 3 1 998244353\n", "output": "499122177\n"}, {"input": "3 3 1 998244353\n", "output": "0\n"}, {"input": "1000000000 1000000000 1 998244353\n", "output": "499122177\n"}, {"input": "999999999 999999999 1 998244353\n", "output": "0\n"}, {"input": "999999999 1000000000 1755648 1000000000\n", "output": "499122177\n"}, {"input": "1 2 1 86583718\n", "output": "499122176\n"}, {"input": "1 2 1 911660635\n", "output": "0\n"}, {"input": "2 2 2 4\n", "output": "41\n"}, {"input": "2 2 2 5\n", "output": "128\n"}, {"input": "2 2 3 4\n", "output": "8\n"}, {"input": "2 2 3 5\n", "output": "41\n"}, {"input": "2 3 2 4\n", "output": "365\n"}, {"input": "2 3 2 5\n", "output": "2048\n"}, {"input": "2 3 3 4\n", "output": "32\n"}, {"input": "2 3 3 5\n", "output": "365\n"}, {"input": "3 2 2 4\n", "output": "365\n"}, {"input": "3 2 2 5\n", "output": "2048\n"}, {"input": "3 2 3 4\n", "output": "32\n"}, {"input": "3 2 3 5\n", "output": "365\n"}, {"input": "3 3 2 4\n", "output": "19683\n"}, {"input": "3 3 2 5\n", "output": "262144\n"}, {"input": "3 3 3 4\n", "output": "512\n"}, {"input": "3 3 3 5\n", "output": "19683\n"}, {"input": "998244352 2 1 998244353\n", "output": "499122177\n"}]
349
You are given two $n \times m$ matrices containing integers. A sequence of integers is strictly increasing if each next number is greater than the previous one. A row is strictly increasing if all numbers from left to right are strictly increasing. A column is strictly increasing if all numbers from top to bottom are strictly increasing. A matrix is increasing if all rows are strictly increasing and all columns are strictly increasing. For example, the matrix $\begin{bmatrix} 9&10&11\\ 11&12&14\\ \end{bmatrix}$ is increasing because each individual row and column is strictly increasing. On the other hand, the matrix $\begin{bmatrix} 1&1\\ 2&3\\ \end{bmatrix}$ is not increasing because the first row is not strictly increasing. Let a position in the $i$-th row (from top) and $j$-th column (from left) in a matrix be denoted as $(i, j)$. In one operation, you can choose any two numbers $i$ and $j$ and swap the number located in $(i, j)$ in the first matrix with the number in $(i, j)$ in the second matrix. In other words, you can swap two numbers in different matrices if they are located in the corresponding positions. You would like to make both matrices increasing by performing some number of operations (possibly none). Determine if it is possible to do this. If it is, print "Possible", otherwise, print "Impossible". -----Input----- The first line contains two integers $n$ and $m$ ($1 \leq n,m \leq 50$)Β β€” the dimensions of each matrix. Each of the next $n$ lines contains $m$ integers $a_{i1}, a_{i2}, \ldots, a_{im}$ ($1 \leq a_{ij} \leq 10^9$)Β β€” the number located in position $(i, j)$ in the first matrix. Each of the next $n$ lines contains $m$ integers $b_{i1}, b_{i2}, \ldots, b_{im}$ ($1 \leq b_{ij} \leq 10^9$)Β β€” the number located in position $(i, j)$ in the second matrix. -----Output----- Print a string "Impossible" or "Possible". -----Examples----- Input 2 2 2 10 11 5 9 4 3 12 Output Possible Input 2 3 2 4 5 4 5 6 3 6 7 8 10 11 Output Possible Input 3 2 1 3 2 4 5 10 3 1 3 6 4 8 Output Impossible -----Note----- The first example, we can do an operation on the top left and bottom right cells of the matrices. The resulting matrices will be $\begin{bmatrix} 9&10\\ 11&12\\ \end{bmatrix}$ and $\begin{bmatrix} 2&4\\ 3&5\\ \end{bmatrix}$. In the second example, we don't need to do any operations. In the third example, no matter what we swap, we can't fix the first row to be strictly increasing in both matrices.
interview
[{"code": "def main():\n from sys import stdin, stdout\n\n def read():\n return stdin.readline().rstrip('\\n')\n\n def read_array(sep=None, maxsplit=-1):\n return read().split(sep, maxsplit)\n\n def read_int():\n return int(read())\n\n def read_int_array(sep=None, maxsplit=-1):\n return [int(a) for a in read_array(sep, maxsplit)]\n\n def write(*args, **kwargs):\n sep = kwargs.get('sep', ' ')\n end = kwargs.get('end', '\\n')\n stdout.write(sep.join(str(a) for a in args) + end)\n\n def write_array(array, **kwargs):\n sep = kwargs.get('sep', ' ')\n end = kwargs.get('end', '\\n')\n stdout.write(sep.join(str(a) for a in array) + end)\n\n n, m = read_int_array()\n minm, maxm = [], []\n for _ in range(n):\n minm.append(read_int_array())\n for _ in range(n):\n maxm.append(read_int_array())\n\n for r in range(n):\n for c in range(m):\n minx = min(minm[r][c], maxm[r][c])\n maxx = max(minm[r][c], maxm[r][c])\n if r:\n if minx <= minm[r-1][c] or maxx <= maxm[r-1][c]:\n write(\"Impossible\")\n return\n if c:\n if minx <= minm[r][c-1] or maxx <= maxm[r][c-1]:\n write(\"Impossible\")\n return\n minm[r][c] = minx\n maxm[r][c] = maxx\n write(\"Possible\")\n\nmain()\n", "passed": true, "time": 0.14, "memory": 14572.0, "status": "done"}, {"code": "n, m = map(int, input().split())\nl1 = [list(map(int, input().split())) for i in range(n)]\nl2 = [list(map(int, input().split())) for i in range(n)]\nfor i in range(n):\n for j in range(m):\n l1[i][j], l2[i][j] = min(l1[i][j], l2[i][j]), max(l1[i][j], l2[i][j])\nans = True\nfor i in range(1, n):\n for j in range(m):\n if l1[i][j] <= l1[i - 1][j] or l2[i][j] <= l2[i - 1][j]:\n ans = False\nfor i in range(n):\n for j in range(1, m):\n if l1[i][j] <= l1[i][j - 1] or l2[i][j] <= l2[i][j - 1]:\n ans = False\nif ans:\n print('Possible')\nelse:\n print('Impossible')", "passed": true, "time": 0.15, "memory": 14608.0, "status": "done"}, {"code": "n, m = map(int, input().split())\n\nm1 = [list(map(int, input().split())) for _ in range(n)]\nm2 = [list(map(int, input().split())) for _ in range(n)]\n\nfor i in range(n):\n\tfor j in range(m):\n\t\tm1[i][j], m2[i][j] = max(m1[i][j], m2[i][j]), min(m1[i][j], m2[i][j])\n\ndef check(matrix):\n\treturn all(all(y > x for x, y in zip(row, row[1:])) for row in matrix)\n\nprint(\"Possible\" if check(m1) and check(m2) and check(list(map(list, zip(*m1)))) and check(list(map(list, zip(*m2)))) else \"Impossible\")", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}, {"code": "n, m = map(int, input().split())\n\nM1 = []\nM2 = []\n\nfor i in range(n):\n M1.append(list(map(int, input().split())))\n \nfor i in range(n):\n M2.append(list(map(int, input().split())))\n \nfor i in range(n):\n for j in range(m):\n M1[i][j], M2[i][j] = min(M1[i][j], M2[i][j]), max(M1[i][j], M2[i][j])\n\nf = 1 \nfor i in range(n):\n for j in range(m):\n if i > 0 and (M1[i][j] <= M1[i-1][j] or M2[i][j] <= M2[i-1][j]):\n f = 0\n break\n if j > 0 and (M1[i][j] <= M1[i][j-1] or M2[i][j] <= M2[i][j-1]):\n f = 0\n break\n#print(M1)\n#print(M2)\nif f == 1:\n print(\"Possible\")\nelse:\n print(\"Impossible\")", "passed": true, "time": 0.24, "memory": 14528.0, "status": "done"}, {"code": "n, m = list(map(int, input().split()))\na1, a2 = [], []\nfor i in range(n):\n a1.append(list(map(int, input().split())))\nfor i in range(n):\n a2.append(list(map(int, input().split())))\n\nfor i in range(n):\n for j in range(m):\n a1[i][j], a2[i][j] = min(a1[i][j], a2[i][j]), max(a1[i][j], a2[i][j])\n\ndef check(a):\n for i in range(n):\n for j in range(1, m):\n if a[i][j] <= a[i][j-1]: return False\n for j in range(m):\n for i in range(1, n):\n if a[i][j] <= a[i-1][j]: return False\n return True\n\nans = \"Possible\" if check(a1) and check(a2) else \"Impossible\"\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14556.0, "status": "done"}, {"code": "def main():\n n, m = map(int, input().split())\n fir = [[] for i in range(n)]\n sec = [[] for i in range(n)]\n for i in range(n):\n fir[i] = list(map(int, input().split()))\n for i in range(n):\n sec[i] = list(map(int, input().split()))\n \n for i in range(n):\n for j in range(m):\n fir[i][j], sec[i][j] = min(fir[i][j], sec[i][j]), max(fir[i][j], sec[i][j])\n \n for i in range(n):\n for j in range(m):\n if i > 0 and fir[i][j] <= fir[i - 1][j]:\n print(\"Impossible\")\n return 0\n if j > 0 and fir[i][j] <= fir[i][j - 1]:\n print(\"Impossible\")\n return 0\n if i > 0 and sec[i][j] <= sec[i - 1][j]:\n print(\"Impossible\")\n return 0\n if j > 0 and sec[i][j] <= sec[i][j - 1]:\n print(\"Impossible\")\n return 0\n print(\"Possible\")\n return 0\n \n \nmain()", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "n,m=[int(x) for x in input().split()]\na=[]\nb=[]\nfor i in range(n):\n c=[int(x) for x in input().split()]\n a.append(c)\nfor i in range(n):\n c=[int(x) for x in input().split()]\n b.append(c)\nfor i in range(n):\n for j in range(m):\n x,y=a[i][j],b[i][j]\n a[i][j]=min(x,y)\n b[i][j]=max(x,y)\n if j>0:\n if a[i][j]<=a[i][j-1] or b[i][j]<=b[i][j-1]:\n print('Impossible')\n return\n if i>0:\n if a[i][j]<=a[i-1][j] or b[i][j]<=b[i-1][j]:\n print('Impossible')\n return\nprint('Possible')\n \n", "passed": true, "time": 0.14, "memory": 14544.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n# @Time : 2019/5/5 1:09\n# @Author : LunaFire\n# @Email : [email protected]\n# @File : B. Double Matrix.py\n\n\ndef main():\n n, m = map(int, input().split())\n a, b = [], []\n for i in range(n):\n a.append(list(map(int, input().split())))\n for i in range(n):\n b.append(list(map(int, input().split())))\n\n def check(mat, i, j):\n if i > 0 and mat[i][j] <= mat[i - 1][j]:\n return False\n if j > 0 and mat[i][j] <= mat[i][j - 1]:\n return False\n return True\n\n for i in range(n):\n for j in range(m):\n a[i][j], b[i][j] = min(a[i][j], b[i][j]), max(a[i][j], b[i][j])\n\n for i in range(n):\n for j in range(m):\n if (not check(a, i, j)) or (not check(b, i, j)):\n print('Impossible')\n return\n print('Possible')\n\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.24, "memory": 14320.0, "status": "done"}, {"code": "def check(A,H,W):\n for h in range(H):\n for w in range(W-1):\n if A[h][w] >= A[h][w+1]:\n return False\n for w in range(W):\n for h in range(H-1):\n if A[h][w] >= A[h+1][w]:\n return False\n return True\n\ndef solve():\n H,W = list(map(int,input().split()))\n A = [list(map(int,input().split())) for i in range(H)]\n B = [list(map(int,input().split())) for i in range(H)]\n if check(A,H,W) and check(B,H,W):\n return 'Possible'\n for h in range(H):\n for w in range(W):\n if A[h][w] > B[h][w]:\n A[h][w], B[h][w] = B[h][w], A[h][w]\n if check(A,H,W) and check(B,H,W):\n return 'Possible'\n return 'Impossible'\n\nprint(solve())\n", "passed": true, "time": 0.15, "memory": 14548.0, "status": "done"}, {"code": "n , m = list(map(int,input().split()))\nm1 = [list(map(int,input().split())) for i in range(n)]\nm2 = [list(map(int,input().split())) for i in range(n)]\nimport sys\nfor i in range(n - 1):\n\tfor j in range(m - 1):\n\t\ta, b = m1[i][j], m2[i][j]\n\t\tc, d = m1[i+1][j], m2[i+1][j]\n\t\te, f = m1[i][j+1], m2[i][j+1]\n\t\tif a > b:\n\t\t\ta,b=b,a\n\t\tif c>d:\n\t\t\tc,d=d,c\n\t\tif e>f:\n\t\t\te,f=f,e\n\t\tif b>=d:\n\t\t\tprint(\"Impossible\")\n\t\t\treturn\n\t\telse:\n\t\t\tif a >=c:\n\t\t\t\tprint(\"Impossible\")\n\t\t\t\treturn\n\t\tif b>=f:\n\t\t\tprint(\"Impossible\")\n\t\t\treturn\n\t\telse:\n\t\t\tif a >=e:\n\t\t\t\tprint(\"Impossible\")\n\t\t\t\treturn\nfor i in range(n-1):\n\tj = m - 1\n\ta, b = m1[i][j], m2[i][j]\n\tc, d = m1[i+1][j], m2[i+1][j]\n\tif a > b:\n\t\ta,b=b,a\n\tif c>d:\n\t\tc,d=d,c\n\tif b>=d:\n\t\t\tprint(\"Impossible\")\n\t\t\treturn\n\telse:\n\t\tif a >=c:\n\t\t\tprint(\"Impossible\")\n\t\t\treturn\nfor j in range(m-1):\n\ti = n - 1\n\ta, b = m1[i][j], m2[i][j]\n\te, f = m1[i][j+1], m2[i][j+1]\n\tif a > b:\n\t\ta,b=b,a\n\tif e>f:\n\t\te,f=f,e\n\tif b>=f:\n\t\t\tprint(\"Impossible\")\n\t\t\treturn\n\telse:\n\t\tif a >=e:\n\t\t\tprint(\"Impossible\")\n\t\t\treturn\nprint(\"Possible\")", "passed": true, "time": 0.22, "memory": 14448.0, "status": "done"}, {"code": "n, m = (int(i) for i in input().split())\nL1 = [[int(j) for j in input().split()] for i in range(n)]\nL2 = [[int(j) for j in input().split()] for i in range(n)]\nfor i in range(n):\n for j in range(m):\n if L1[i][j] > L2[i][j]:\n buf = L1[i][j]\n L1[i][j] = L2[i][j]\n L2[i][j] = buf\n\nt = 1\nfor i in range(n):\n for j in range(m):\n if i > 0:\n if L1[i][j] <= L1[i - 1][j]:\n t = 0\n if L2[i][j] <= L2[i - 1][j]:\n t = 0\n if j > 0:\n if L1[i][j] <= L1[i][j - 1]:\n t = 0\n if L2[i][j] <= L2[i][j - 1]:\n t = 0\nif not t:\n print('Impossible')\nelse:\n print('Possible')\n", "passed": true, "time": 0.15, "memory": 14452.0, "status": "done"}, {"code": "n, m = map(int, input().split())\n\na = [[0 for _ in range(m)] for _ in range(n)]\nb = [[0 for _ in range(m)] for _ in range(n)]\n\n\nfor i in range(n):\n\ta[i] = list(map(int, input().split()))\n\n\nfor i in range(n):\n\tb[i] = list(map(int, input().split()))\n\nfor i in range(n):\n\tfor j in range(m):\n\t\ta[i][j], b[i][j] = min(a[i][j], b[i][j]), max(a[i][j], b[i][j])\n\n# print('a:')\n# print(a)\n\n# print('b:')\n# print(b)\n\nworks = True\n\nfor i in range(n):\n\tfor j in range(m-1):\n\t\tif a[i][j+1] <= a[i][j]:\n\t\t\tworks = False\n\n\t\tif b[i][j+1] <= b[i][j]:\n\t\t\tworks = False\n\nfor j in range(m):\n\tfor i in range(n-1):\n\t\tif a[i+1][j] <= a[i][j]:\n\t\t\tworks = False\n\n\t\tif b[i+1][j] <= b[i][j]:\n\t\t\tworks = False\n\nif works:\n\tprint('Possible')\nelse:\n\tprint('Impossible')", "passed": true, "time": 0.21, "memory": 14364.0, "status": "done"}, {"code": "import sys\ninput = sys.stdin.readline\n\nn,m=map(int,input().split())\n\narr1=[]\nfor i in range(n):\n\tarr1.append(list(map(int,input().split())))\n\narr2=[]\nfor i in range(n):\n\tarr2.append(list(map(int,input().split())))\n\t\narr3=[]\narr4=[]\nfor i in range(n):\n\tarr3.append([])\n\tarr4.append([])\n\tfor j in range(m):\n\t\tarr3[i].append(min(arr1[i][j],arr2[i][j]))\n\t\tarr4[i].append(max(arr1[i][j],arr2[i][j]))\n\nflag=False\nfor i in range(n):\n\tfor j in range(m):\n\t\ttry:\n\t\t\tif arr3[i][j]>=arr3[i][j+1] or arr4[i][j]>=arr4[i][j+1]:\n\t\t\t\tprint(\"Impossible\")\n\t\t\t\tflag=True\n\t\t\t\tbreak\n\t\texcept:\n\t\t\tpass\n\n\t\ttry:\n\t\t\tif arr3[i][j]>=arr3[i+1][j] or arr4[i][j]>=arr4[i+1][j]:\n\t\t\t\tprint(\"Impossible\")\n\t\t\t\tflag=True\n\t\t\t\tbreak\n\t\texcept:\n\t\t\tpass\n\n\tif flag:\n\t\tbreak\n\nif not flag:\n\tprint(\"Possible\")", "passed": true, "time": 0.14, "memory": 14572.0, "status": "done"}, {"code": "def isIncreasing(matrix, n, m):\n for j in range(m-1):\n if matrix[0][j+1]<=matrix[0][j]: return False\n for i in range(n-1):\n if matrix[i+1][0]<=matrix[i][0]: return False\n for i in range(1, n):\n for j in range(1, m):\n if matrix[i][j]<=matrix[i-1][j] or matrix[i][j]<=matrix[i][j-1]:\n return False\n return True\n\nn, m = list(map(int, input().split()))\nA = []\nB = []\nfor i in range(n):\n A.append(list(map(int, input().split())))\nfor i in range(n):\n B.append(list(map(int, input().split())))\nfor i in range(n):\n for j in range(m):\n A[i][j], B[i][j] = min(A[i][j], B[i][j]), max(A[i][j], B[i][j])\nif isIncreasing(A, n, m) and isIncreasing(B, n, m): print(\"Possible\")\nelse: print(\"Impossible\")\n", "passed": true, "time": 0.14, "memory": 14492.0, "status": "done"}, {"code": "import sys\n\nn, m = list(map(int, input().split()))\n\n\ndef read_matrix():\n M = []\n for i in range(n):\n M.append(list(map(int, input().split())))\n return M\n\n\nA, B = read_matrix(), read_matrix()\n\n\nfor i in range(n):\n for j in range(m):\n A[i][j], B[i][j] = min(A[i][j], B[i][j]), max(A[i][j], B[i][j])\n if i > 0 and (A[i][j] <= A[i-1][j] or B[i][j] <= B[i-1][j]) or \\\n j > 0 and (A[i][j] <= A[i][j-1] or B[i][j] <= B[i][j-1]):\n print('Impossible')\n return\n\nprint('Possible')\n", "passed": true, "time": 0.23, "memory": 14544.0, "status": "done"}, {"code": "def increasing(m):\n for i in range(len(m)):\n prev = m[i][0]\n for j in range(1, len(m[i])):\n if m[i][j] <= prev: return False\n prev = m[i][j]\n for j in range(len(m[0])):\n prev = m[0][j]\n for i in range(1, len(m)):\n if m[i][j] <= prev: return False\n prev = m[i][j]\n return True\n\ndef sol(m1, m2):\n for i in range(len(m1)):\n for j in range(len(m1[i])):\n if m1[i][j] > m2[i][j]:\n m1[i][j], m2[i][j] = m2[i][j], m1[i][j]\n if not increasing(m1) or not increasing(m2): return 'Impossible'\n return 'Possible'\n \ndef __starting_point():\n [n,m] = [int(x) for x in input().split()]\n m1, m2 = [], []\n for _ in range(n): m1.append([int(x) for x in input().split()])\n for _ in range(n): m2.append([int(x) for x in input().split()])\n print(sol(m1,m2))\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14436.0, "status": "done"}, {"code": "# http://codeforces.com/contest/1162/problem/B\n'''\n Author - Subhajit Das\n University of Engineering and Management, Kolkata\n 4/5/2019\n'''\n\n\ndef main():\n n, m = list(map(int, input().strip().split()))\n a = [list(map(int, input().strip().split())) for _ in range(n)]\n b = [list(map(int, input().strip().split())) for _ in range(n)]\n\n possible = True\n\n for row in range(n):\n last_a = a[row][0]\n last_b = b[row][0]\n for col in range(1, m):\n if last_a < a[row][col] and last_b < b[row][col]:\n last_a = a[row][col]\n last_b = b[row][col]\n else:\n a[row][col], b[row][col] = b[row][col], a[row][col]\n if last_a < a[row][col] and last_b < b[row][col]:\n last_a = a[row][col]\n last_b = b[row][col]\n else:\n possible = False\n break\n\n if possible:\n for col in range(m):\n last_a = a[0][col]\n last_b = b[0][col]\n for row in range(1, n):\n if last_a < a[row][col] and last_b < b[row][col]:\n last_a = a[row][col]\n last_b = b[row][col]\n else:\n a[row][col], b[row][col] = b[row][col], a[row][col]\n if last_a < a[row][col] and last_b < b[row][col]:\n last_a = a[row][col]\n last_b = b[row][col]\n else:\n possible = False\n break\n\n print(\"Possible\" if possible else \"Impossible\")\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14384.0, "status": "done"}, {"code": "def main():\n n, m = list(map(int, input().split()))\n m1 = [[] for _ in range(n)]\n m2 = [[] for _ in range(n)]\n for i in range(n):\n m1[i] = list(map(int, input().split()))\n for i in range(n):\n m2[i] = list(map(int, input().split()))\n\n for r in range(n):\n for c in range(m):\n m1[r][c], m2[r][c] = min(m1[r][c], m2[r][c]), max(m1[r][c], m2[r][c])\n\n def checkRow(row):\n for i in range(m-1):\n if m1[row][i] >= m1[row][i+1] or m2[row][i] >= m2[row][i+1]:\n return False\n return True\n\n def checkCol(col):\n for i in range(n-1):\n if m1[i][col] >= m1[i+1][col] or m2[i][col] >= m2[i+1][col]:\n return False\n return True\n\n ok = True\n for r in range(n):\n if not checkRow(r):\n ok = False\n break\n\n if ok:\n for c in range(m):\n if not checkCol(c):\n ok = False\n break\n\n print('Possible' if ok else 'Impossible')\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14392.0, "status": "done"}, {"code": "import sys\nn, m = map(int, input().split())\n\nmat1 = []\nmat2 = []\n\nfor _ in range(n):\n mat1.append(list(map(int, input().split())))\nfor _ in range(n):\n mat2.append(list(map(int, input().split())))\n\nfor i in range(n):\n for j in range(m):\n if mat2[i][j] < mat1[i][j]:\n mat1[i][j], mat2[i][j] = mat2[i][j], mat1[i][j]\n\nfor i in range(n):\n for j in range(1, m):\n if mat1[i][j] <= mat1[i][j - 1] or mat2[i][j] <= mat2[i][j - 1]:\n print(\"Impossible\")\n return\nfor i in range(1, n):\n for j in range(m):\n if mat1[i][j] <= mat1[i - 1][j] or mat2[i][j] <= mat2[i - 1][j]:\n print(\"Impossible\")\n return\nprint(\"Possible\")", "passed": true, "time": 0.14, "memory": 14384.0, "status": "done"}]
[{"input": "2 2\n2 10\n11 5\n9 4\n3 12\n", "output": "Possible\n"}, {"input": "2 3\n2 4 5\n4 5 6\n3 6 7\n8 10 11\n", "output": "Possible\n"}, {"input": "3 2\n1 3\n2 4\n5 10\n3 1\n3 6\n4 8\n", "output": "Impossible\n"}, {"input": "1 1\n1\n1\n", "output": "Possible\n"}, {"input": "1 20\n24113077 23454965 177666364 189267262 288203127 425702241 443748582 497192900 500408108 507081270 624761160 631677991 696654683 761843396 812804599 812841278 843770568 869392361 949349095 968479911\n16829544 25736255 99598087 115911995 176453954 263429812 351215090 378014815 552062882 574845969 512322624 590282812 661540376 712718129 886414197 922259985 933237957 936098789 939676223 966862085\n", "output": "Possible\n"}, {"input": "20 1\n66723051\n192052119\n224590623\n285234278\n167627491\n337383819\n374082795\n457862809\n434684264\n480651568\n509016946\n512760752\n577998249\n647547233\n737914492\n753247062\n687137696\n799938346\n957366563\n986223900\n47472129\n101178650\n145468869\n145519928\n311820460\n208565256\n303503995\n326456874\n472277646\n473761370\n493557409\n497115206\n518893690\n567441986\n615260095\n679825548\n782224818\n786514557\n861357063\n909226227\n", "output": "Possible\n"}, {"input": "2 2\n2 3\n4 6\n1 2\n5 4\n", "output": "Impossible\n"}, {"input": "2 2\n1 3\n3 5\n1 2\n2 1\n", "output": "Impossible\n"}, {"input": "2 2\n1 3\n3 4\n1 3\n3 2\n", "output": "Impossible\n"}, {"input": "2 2\n3 4\n1 2\n3 4\n1 2\n", "output": "Impossible\n"}, {"input": "2 2\n1 2\n5 4\n1 3\n3 4\n", "output": "Impossible\n"}, {"input": "2 2\n1 2\n3 1\n9 10\n11 1\n", "output": "Impossible\n"}, {"input": "2 2\n1 2\n1 2\n1 2\n1 2\n", "output": "Impossible\n"}, {"input": "2 2\n9 10\n11 12\n1 2\n2 2\n", "output": "Impossible\n"}, {"input": "2 2\n1 2\n1 2\n1 2\n2 3\n", "output": "Impossible\n"}, {"input": "2 3\n1 3 2\n4 5 6\n7 8 9\n10 11 12\n", "output": "Impossible\n"}, {"input": "1 2\n1 2\n9 9\n", "output": "Impossible\n"}, {"input": "1 3\n5 6 7\n1 1 1\n", "output": "Impossible\n"}, {"input": "2 3\n2 3 4\n1 2 3\n2 3 4\n1 2 3\n", "output": "Impossible\n"}, {"input": "2 2\n3 4\n1 2\n5 6\n3 4\n", "output": "Impossible\n"}, {"input": "2 1\n5\n9\n9\n9\n", "output": "Impossible\n"}, {"input": "3 3\n1 2 3\n4 5 6\n7 80 90\n2 3 4\n5 6 7\n8 92 91\n", "output": "Impossible\n"}, {"input": "2 2\n1 1\n1 1\n5 6\n7 8\n", "output": "Impossible\n"}, {"input": "3 3\n2 4 5\n6 7 8\n9 10 11\n2 1 6\n7 8 9\n10 11 12\n", "output": "Impossible\n"}, {"input": "1 2\n9 9\n1 9\n", "output": "Impossible\n"}, {"input": "1 3\n1 2 3\n5 5 5\n", "output": "Impossible\n"}, {"input": "2 2\n1 1\n2 3\n10 11\n12 13\n", "output": "Impossible\n"}, {"input": "2 2\n2 2\n2 4\n1 2\n2 5\n", "output": "Impossible\n"}, {"input": "3 1\n9\n8\n7\n9\n8\n7\n", "output": "Impossible\n"}, {"input": "2 3\n5 6 7\n1 2 3\n5 6 7\n1 2 3\n", "output": "Impossible\n"}, {"input": "2 2\n2 3\n4 5\n1 1\n1 1\n", "output": "Impossible\n"}, {"input": "1 3\n3 6 6\n1 2 3\n", "output": "Impossible\n"}, {"input": "2 2\n1 2\n1 2\n1 2\n3 4\n", "output": "Impossible\n"}, {"input": "1 2\n1 1\n1 1\n", "output": "Impossible\n"}, {"input": "2 2\n1 2\n2 3\n1 2\n8 7\n", "output": "Impossible\n"}, {"input": "1 2\n10 5\n2 1\n", "output": "Impossible\n"}, {"input": "2 2\n2 10\n11 10\n9 10\n3 12\n", "output": "Impossible\n"}, {"input": "1 2\n1 4\n6 5\n", "output": "Impossible\n"}, {"input": "2 2\n6 7\n5 8\n6 7\n4 10\n", "output": "Impossible\n"}, {"input": "2 2\n1 5\n2 3\n10 11\n12 13\n", "output": "Impossible\n"}, {"input": "2 2\n9 10\n10 11\n9 10\n10 11\n", "output": "Possible\n"}, {"input": "1 2\n3 1\n9 15\n", "output": "Impossible\n"}, {"input": "2 2\n1 2\n1 2\n4 5\n4 5\n", "output": "Impossible\n"}, {"input": "2 2\n1 2\n2 3\n11 3\n3 4\n", "output": "Impossible\n"}, {"input": "2 2\n2 3\n4 5\n5 5\n5 5\n", "output": "Impossible\n"}, {"input": "2 2\n1 2\n2 2\n1 2\n2 2\n", "output": "Impossible\n"}, {"input": "1 3\n1 100 3\n2 3 1000\n", "output": "Impossible\n"}, {"input": "1 2\n2 2\n2 3\n", "output": "Impossible\n"}, {"input": "1 2\n3 2\n5 1\n", "output": "Impossible\n"}, {"input": "2 2\n4 4\n4 4\n7 7\n7 7\n", "output": "Impossible\n"}, {"input": "2 2\n1 1\n1 1\n2 2\n2 2\n", "output": "Impossible\n"}, {"input": "2 2\n1 3\n3 4\n2 1\n3 4\n", "output": "Impossible\n"}, {"input": "1 2\n3 5\n3 2\n", "output": "Impossible\n"}, {"input": "1 2\n4 2\n4 2\n", "output": "Impossible\n"}, {"input": "2 2\n1 2\n3 4\n2 2\n2 2\n", "output": "Impossible\n"}, {"input": "2 2\n5 6\n1 2\n5 6\n1 2\n", "output": "Impossible\n"}, {"input": "2 2\n3 6\n5 9\n3 6\n5 4\n", "output": "Impossible\n"}]
350
You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: the i-th letter occurs in the string no more than a_{i} times; the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once. -----Input----- The first line of the input contains a single integer n (2 ≀ n ≀ 26)Β β€” the number of letters in the alphabet. The next line contains n integers a_{i} (1 ≀ a_{i} ≀ 10^9)Β β€” i-th of these integers gives the limitation on the number of occurrences of the i-th character in the string. -----Output----- Print a single integer β€” the maximum length of the string that meets all the requirements. -----Examples----- Input 3 2 5 5 Output 11 Input 3 1 1 2 Output 3 -----Note----- For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc".
interview
[{"code": "n = int(input())\narr = list(map(int, input().split()))\narr.sort()\narr = arr[::-1]\nans = [arr[0]]\nfor i in range(1, n):\n\tif(arr[i] < ans[-1]):\n\t\tans.append(arr[i])\n\telse:\n\t\tans.append(max(0, ans[-1] - 1))\nprint(sum(ans))", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\na.sort()\nfor i in range(n - 2, -1, -1):\n a[i] = max(min(a[i], a[i + 1] - 1), 0)\nprint(sum(a))\n", "passed": true, "time": 0.24, "memory": 14536.0, "status": "done"}, {"code": "n = int(input())\nc = list(map(int, input().split()))\nret = set()\nfor x in c:\n for y in range(x, -1, -1):\n if y not in ret:\n ret.add(y)\n break\nprint(sum(ret))\n", "passed": true, "time": 0.14, "memory": 14296.0, "status": "done"}, {"code": "n = [int(s) for s in input().split()]\na = [int(s) for s in input().split()]\nx = set()\nres = 0\nfor i in reversed(sorted(a)):\n while i>0:\n if i in x:\n i-=1\n else:\n res+=i\n x.add(i)\n break\nprint(res)\n", "passed": true, "time": 0.15, "memory": 14304.0, "status": "done"}, {"code": "n, a, s, v = int(input()), sorted(map(int, input().split()), reverse=True), set(), 0\nfor ai in a:\n while ai and ai in s:\n ai -= 1\n s.add(ai)\n v += ai\nprint(v)", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}, {"code": "N = int(input())\nletters = list(map(int, input().split()))\nletters.sort()\nlennow = 0\nfor i in range(len(letters) - 2, -1, -1):\n letters[i] = max(0, min(letters[i + 1] - 1, letters[i]))\nprint(sum(letters))", "passed": true, "time": 0.15, "memory": 14316.0, "status": "done"}, {"code": "n = int(input())\nrng = [int(t) for t in input().split()]\n\nans = 0\nwhile len(rng) != 0:\n mx = max(rng)\n\n if mx <= 0:\n break\n\n ans += mx\n\n rng.remove(mx)\n for i in range(len(rng)):\n if rng[i] == mx:\n rng[i] -= 1\n\nprint(ans)", "passed": true, "time": 0.25, "memory": 14460.0, "status": "done"}, {"code": "n=int(input())\nip=list(map(int,input().split()))\nop=[]\ncount=0\nfor i in ip:\n if i not in op:\n count+=i\n op.append(i)\n else:\n for j in range(1,i+1):\n if i-j not in op:\n count+=i-j\n op.append(i-j)\n break\n else:\n continue\nprint(count)\n", "passed": true, "time": 0.15, "memory": 14488.0, "status": "done"}, {"code": "n=int(input())\nL=[int(x) for x in input().split()]\nL.sort()\nL=L[::-1]\nans=0\ndis=L[0]+1\nfor i in L:\n ans+=max(0,min(dis,i))\n dis=min(dis,i)-1\nprint(ans)\n", "passed": true, "time": 0.19, "memory": 14484.0, "status": "done"}, {"code": "n = int(input())\nl = list(map(int, input().split()))\nl.sort(reverse = True)\ncheck = set()\nans = 0\nfor i in l:\n x = i\n while x in check:\n x -= 1\n if x < 0:\n continue\n ans += x\n check.add(x)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "n = input()\na_in = list(map(int, input().split()))\na = list(reversed(sorted(a_in)))\nprev = 1000000001\nans = 0\nfor c in a:\n if c >= prev:\n c = prev - 1\n if c <= 0:\n break\n ans += c\n prev = c\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "n = int(input())\ndata = list(map(int, input().split()))\nanswer = 0\nfor i in range(n):\n if data.count(data[i]) == 1:\n answer += data[i]\n else:\n while data[i] > 0:\n if data.count(data[i]) == 1:\n answer += data[i]\n break\n else:\n data[i] -= 1\nprint(answer)", "passed": true, "time": 0.2, "memory": 14552.0, "status": "done"}, {"code": "n = int(input())\na = [int(s) for s in input().split()]\n\na.sort()\nb = 10**9 + 1\nsum = 0\nfor i in range(n-1, -1, -1):\n if min(a[i], b - 1) < 1:\n break\n sum += min(a[i], b - 1)\n b = min(a[i], b - 1)\n\nprint(sum)\n", "passed": true, "time": 0.15, "memory": 14420.0, "status": "done"}, {"code": "3\n\nn = int(input())\na = list(map(int, input().split()))\n\nused = set()\nreversed(sorted(a))\ni = 0\nwhile i < n:\n if a[i] == 0:\n i += 1\n else:\n if a[i] not in used:\n used.add(a[i])\n i += 1\n else:\n a[i] -= 1\nprint(str(sum(a)))\n", "passed": true, "time": 0.15, "memory": 14560.0, "status": "done"}, {"code": "n = int(input())\nai = list(map(int,input().split()))\nai.sort()\nai.reverse()\nlast_num = ai[0]+1\nans = 0\nfor num in ai:\n if last_num == 0:\n break\n if num >= last_num:\n last_num -= 1\n else:\n last_num = num\n ans += last_num\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "n = int(input())\nl = list(map(int, input().split()))\nl = sorted(l)[-1::-1]\n\n\nfor i in range(1, n):\n\tif l[i] >= l[i-1]:\n\t\tl[i] = l[i-1] - 1\n\tif l[i] < 0:\n\t\tl[i] = 0\nprint(sum(l)) \n\n", "passed": true, "time": 0.15, "memory": 14284.0, "status": "done"}, {"code": "n = int(input())\ndata = list(map(int, input().split()))\ndata.sort()\nhigh = data[-1]\nret = 0\nfor i in range(n-1, -1, -1):\n\tchosen = min(data[i], high)\n\tret += max(chosen, 0)\n\thigh = chosen-1\nprint(ret)\n", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "n = int(input())\na = [int(x) for x in input().split()]\n\nocc = set()\na.sort(reverse=True)\nfor i in range(len(a)):\n while a[i] in occ and a[i] > 0:\n a[i] -= 1\n occ.add(a[i])\n\nprint(sum(a))\n", "passed": true, "time": 0.15, "memory": 14540.0, "status": "done"}, {"code": "n = int(input())\nA = list(map(int, input().split()))\nans = []\nfor i in range(n):\n if A[i] in ans:\n for j in range(A[i] - 1, 0, -1):\n if j not in ans:\n ans.append(j)\n break\n else:\n ans.append(A[i])\nprint(sum(ans)) \n", "passed": true, "time": 0.14, "memory": 14488.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nn = int(input())\na = [int(x) for x in input().split()]\na = sorted(a, reverse=True)\ncount = 0\nprev = None\nfor x in a:\n if prev != None and prev <= x:\n x = max(prev - 1, 0)\n count += x\n prev = x\nprint(count)\n\n", "passed": true, "time": 0.14, "memory": 14300.0, "status": "done"}, {"code": "def adjust(x,limit):\n if x == 0:\n return 0\n\n if x <= limit:\n return x-1\n\n return limit\n\ndef __starting_point():\n\n n = int(input())\n a = list(map(int,input().split()))\n a.sort(key=lambda x:-x)\n #print(a)\n\n for i in range(1,n):\n a[i] = adjust(a[i-1],a[i])\n\n print( sum(a) )\n__starting_point()", "passed": true, "time": 0.15, "memory": 14304.0, "status": "done"}, {"code": "n=int(input())\narr=[int(x) for x in input().split()]\narr=sorted(arr)\narr.reverse()\ns=set()\nsum=0\nflag=0\nfor i in range(n):\n temp=arr[i]\n while temp in s:\n temp=temp-1\n if temp==0:\n flag=1\n break\n sum+=temp\n s.add(temp)\n if flag==1:\n break\nprint(sum)", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "n = int(input())\nd = [int(i) for i in input().split()]\nd = sorted(d, reverse=True)\nfor i in range(1, len(d)):\n d[i] = max(0, min(d[i - 1] - 1, d[i]))\nprint(sum(d))", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "n = int(input())\ns=input()\ns=s.split()\na=[]\nfor i in range(n):\n a.append(int(s[i]))\nsu=0\nd={}\na.sort(reverse=True)\nfor i in range(len(a)):\n if a[i] not in d:\n su+=a[i]\n d[a[i]]=1\n else:\n t=a[i]-1\n while t>=1 and t in d:\n t-=1\n su+=t\n d[t]=1\n \nprint(su)\n \n", "passed": true, "time": 0.24, "memory": 14356.0, "status": "done"}]
[{"input": "3\n2 5 5\n", "output": "11\n"}, {"input": "3\n1 1 2\n", "output": "3\n"}, {"input": "2\n1 1\n", "output": "1\n"}, {"input": "3\n1 1000000000 2\n", "output": "1000000003\n"}, {"input": "26\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\n", "output": "25999999675\n"}, {"input": "2\n559476582 796461544\n", "output": "1355938126\n"}, {"input": "2\n257775227 621811272\n", "output": "879586499\n"}, {"input": "10\n876938317 219479349 703839299 977218449 116819315 752405530 393874852 286326991 592978634 155758306\n", "output": "5075639042\n"}, {"input": "26\n72 49 87 47 94 96 36 91 43 11 19 83 36 38 10 93 95 81 4 96 60 38 97 37 36 41\n", "output": "1478\n"}, {"input": "26\n243 364 768 766 633 535 502 424 502 283 592 877 137 891 837 990 681 898 831 487 595 604 747 856 805 688\n", "output": "16535\n"}, {"input": "26\n775 517 406 364 548 951 680 984 466 141 960 513 660 849 152 250 176 601 199 370 971 554 141 224 724 543\n", "output": "13718\n"}, {"input": "26\n475 344 706 807 925 813 974 166 578 226 624 591 419 894 574 909 544 597 170 990 893 785 399 172 792 748\n", "output": "16115\n"}, {"input": "26\n130 396 985 226 487 671 188 706 106 649 38 525 210 133 298 418 953 431 577 69 12 982 264 373 283 266\n", "output": "10376\n"}, {"input": "26\n605 641 814 935 936 547 524 702 133 674 173 102 318 620 248 523 77 718 318 635 322 362 306 86 8 442\n", "output": "11768\n"}, {"input": "26\n220 675 725 888 725 654 546 806 379 182 604 667 734 394 889 731 572 193 850 651 844 734 163 671 820 887\n", "output": "16202\n"}, {"input": "26\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\n", "output": "25675\n"}, {"input": "26\n1001 1001 1000 1000 1001 1000 1001 1001 1001 1000 1000 1001 1001 1000 1000 1000 1000 1001 1000 1001 1001 1000 1001 1001 1001 1000\n", "output": "25701\n"}, {"input": "26\n1000 1001 1000 1001 1000 1001 1001 1000 1001 1002 1002 1000 1001 1000 1000 1000 1001 1002 1001 1000 1000 1001 1000 1002 1001 1002\n", "output": "25727\n"}, {"input": "26\n1003 1002 1002 1003 1000 1000 1000 1003 1000 1001 1003 1003 1000 1002 1002 1002 1001 1003 1000 1001 1000 1001 1001 1000 1003 1003\n", "output": "25753\n"}, {"input": "26\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\n", "output": "1\n"}, {"input": "26\n8717 9417 1409 7205 3625 6247 8626 9486 464 4271 1698 8449 4551 1528 7456 9198 4886 2889 7534 506 7867 9410 1635 4955 2580 2580\n", "output": "137188\n"}, {"input": "26\n197464663 125058028 622449215 11119637 587496049 703992162 219591040 965159268 229879004 278894000 841629744 616893922 218779915 362575332 844188865 342411376 369680019 43823059 921419789 999588082 943769007 35365522 301907919 758302419 427454397 807507709\n", "output": "12776400142\n"}, {"input": "26\n907247856 970380443 957324066 929910532 947150618 944189007 998282297 988343406 981298600 943026596 953932265 972691398 950024048 923033790 996423650 972134755 946404759 918183059 902987271 965507679 906967700 982106487 933997242 972594441 977736332 928874832\n", "output": "24770753129\n"}, {"input": "26\n999999061 999999688 999999587 999999429 999999110 999999563 999999120 999999111 999999794 999999890 999999004 999999448 999999770 999999543 999999460 999999034 999999361 999999305 999999201 999999778 999999432 999999844 999999133 999999342 999999600 999999319\n", "output": "25999984927\n"}, {"input": "3\n587951561 282383259 612352726\n", "output": "1482687546\n"}, {"input": "4\n111637338 992238139 787658714 974622806\n", "output": "2866156997\n"}, {"input": "5\n694257603 528073418 726928894 596328666 652863391\n", "output": "3198451972\n"}, {"input": "6\n217943380 532900593 902234882 513005821 369342573 495810412\n", "output": "3031237661\n"}, {"input": "7\n446656860 478792281 77541870 429682977 85821755 826122363 563802405\n", "output": "2908420511\n"}, {"input": "8\n29278125 778590752 252847858 51388836 802299938 215370803 901540149 242074772\n", "output": "3273391233\n"}, {"input": "9\n552962902 724482439 133182550 673093696 518779120 604618242 534250189 847695567 403066553\n", "output": "4992131258\n"}, {"input": "10\n600386086 862479376 284190454 781950823 672077209 5753052 145701234 680334621 497013634 35429365\n", "output": "4565315854\n"}, {"input": "11\n183007351 103343359 164525146 698627979 388556391 926007595 483438978 580927711 659384363 201890880 920750904\n", "output": "5310460657\n"}, {"input": "12\n706692128 108170535 339831134 320333838 810063277 20284739 821176722 481520801 467848308 604388203 881959821 874133307\n", "output": "6436402813\n"}, {"input": "13\n525349200 54062222 810108418 237010994 821513756 409532178 158915465 87142595 630219037 770849718 843168738 617993222 504443485\n", "output": "6470309028\n"}, {"input": "14\n812998169 353860693 690443110 153688149 537992938 798779618 791624505 282706982 733654279 468319337 568341847 597888944 649703235 667623671\n", "output": "8107625477\n"}, {"input": "15\n336683946 299752380 865749098 775393009 959499824 893055762 365399057 419335880 896025008 575845364 529550764 341748859 30999793 464432689 19445239\n", "output": "7772916672\n"}, {"input": "16\n860368723 540615364 41056086 692070164 970950302 282304201 998108096 24957674 999460249 37279175 490759681 26673285 412295352 671298115 627182888 90740349\n", "output": "7766119704\n"}, {"input": "17\n148018692 545442539 980325266 313776023 687429485 376580345 40875544 925549764 161831978 144805202 451968598 475560904 262583806 468107133 60900936 281546097 912565045\n", "output": "7237867357\n"}, {"input": "18\n966674765 786305522 860659958 935480883 108937371 60800080 673584584 826142855 560238516 606238013 413177515 455456626 643879364 969943855 963609881 177380550 544192822 864797474\n", "output": "11417500634\n"}, {"input": "19\n490360541 496161402 330938242 852158038 120387849 686083328 247359135 431764649 427637949 8736336 843378328 435352349 494167818 766752874 161292122 368186298 470791896 813444279 170758124\n", "output": "8615711557\n"}, {"input": "20\n654616375 542649443 729213190 188364665 238384327 726353863 974350390 526804424 601329631 886592063 734805196 275562411 861801362 374466292 119830901 403120565 670982545 63210795 130397643 601611646\n", "output": "10304447727\n"}, {"input": "21\n942265343 252505322 904519178 810069524 954862509 115602302 548124942 132426218 999736168 584061682 696014113 960485837 712089816 581331718 317512142 593926314 302610323 716885305 477125514 813997503 535631456\n", "output": "12951783229\n"}, {"input": "22\n465951120 788339601 784853870 726746679 376370396 504849742 180834982 33019308 867135601 455551901 657223030 940381560 93386374 378140736 161286599 548696254 934237100 75589518 764917898 731412064 205669368 630662937\n", "output": "11305256638\n"}, {"input": "23\n989635897 498195481 255132154 643423835 387820874 894097181 223601429 228583694 265543138 153021520 618431947 684241474 943673829 174949754 358967839 444530707 801900686 965299835 347682577 648826625 406714384 129525158 958578251\n", "output": "12022378269\n"}, {"input": "24\n277285866 739058464 135466846 265129694 104300056 519381429 856310469 834204489 132942572 260547547 343605057 664137197 619941683 676786476 497713592 635336455 138557168 618975345 635474960 861212482 76752297 923357675 517046816 274123722\n", "output": "11607648357\n"}, {"input": "25\n95942939 979921447 310772834 181806850 525806942 613657573 194049213 734797579 531349109 721980358 304813974 113025815 470230137 473595494 695394833 590106396 770183946 567622150 218239639 778627043 41761505 127248600 134450869 860350034 901937574\n", "output": "11937672853\n"}, {"input": "26\n619627716 984748623 486078822 98484005 537257421 2906012 62795060 635390669 103777246 829506385 971050595 92921538 851525695 680460920 893076074 780912144 401811723 221297659 269996214 991012900 242806521 626109821 987889730 682613155 209557740 806895799\n", "output": "14070510187\n"}, {"input": "26\n10 1 20 2 23 3 14 6 7 13 26 21 11 8 16 25 12 15 19 9 17 22 24 18 5 4\n", "output": "351\n"}, {"input": "3\n1 1 1\n", "output": "1\n"}, {"input": "5\n5 3 3 3 1\n", "output": "11\n"}, {"input": "5\n2 2 2 2 2\n", "output": "3\n"}, {"input": "10\n10 10 10 10 10 10 10 10 1 1\n", "output": "53\n"}, {"input": "10\n100 100 10 10 10 10 10 1 1 1\n", "output": "240\n"}, {"input": "6\n5 3 3 3 3 1\n", "output": "11\n"}, {"input": "4\n4 3 2 1\n", "output": "10\n"}, {"input": "5\n1 1 1 1 1\n", "output": "1\n"}]
351
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty β€” a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge). Makes has chosen n problems to solve on Decoforces with difficulties a_1, a_2, ..., a_{n}. He can solve these problems in arbitrary order. Though he can solve problem i with difficulty a_{i} only if he had already solved some problem with difficulty $d \geq \frac{a_{i}}{2}$ (no matter on what online judge was it). Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty k. With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list. For every positive integer y there exist some problem with difficulty y on at least one judge besides Decoforces. Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another. Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces. -----Input----- The first line contains two integer numbers n, k (1 ≀ n ≀ 10^3, 1 ≀ k ≀ 10^9). The second line contains n space-separated integer numbers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10^9). -----Output----- Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces. -----Examples----- Input 3 3 2 1 9 Output 1 Input 4 20 10 3 6 3 Output 0 -----Note----- In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3. In the second example he can solve every problem right from the start.
interview
[{"code": "R=lambda:list(map(int,input().split()))\nn,k=R()\na=sorted(R())\nb=0\nfor i in a:\n while i>k+k:\n k+=k\n b+=1\n k=max(k,i)\nprint(b)\n", "passed": true, "time": 0.16, "memory": 14428.0, "status": "done"}, {"code": "\nimport sys\n#sys.stdin=open(\"data.txt\")\ninput=sys.stdin.readline\n\nn,k=list(map(int,input().split()))\n\nans=0\nfor i in sorted(map(int,input().split())):\n while i>2*k:\n ans+=1\n k*=2\n k=max(k,i)\n\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14464.0, "status": "done"}, {"code": "n,k=list(map(int,input().split()))\nx=0\nfor d in sorted(map(int,input().split())):\n while 2*k<d:\n k*=2\n x+=1\n k=max(k,d)\nprint(x)\n", "passed": true, "time": 0.14, "memory": 14476.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\na.sort()\ncurr = 0\nans = 0\nwhile curr < len(a):\n if k >= a[curr] / 2:\n k = max(k, a[curr])\n curr += 1\n else:\n ans += 1\n k *= 2\n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14300.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = sorted(map(int, input().split()), reverse = True)\nwhile len(a) > 0 and a[-1] <= k:\n a.pop()\n\na.append(k)\nans = 0\nwhile len(a) > 1:\n u, v= a[-1], a[-2]\n while u * 2 < v:\n ans += 1\n u *= 2\n a.pop()\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14460.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\ns = [int(i) for i in input().split()]\ns.sort()\nans = 0\nfor i in s:\n while k<i/2:\n ans+=1\n k=2*k\n k = max(k, i)\nprint(ans)\n\n", "passed": true, "time": 0.15, "memory": 14524.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\na = list(sorted(a))\nd = k\nans = 0\nfor ai in a:\n while 2 * d < ai:\n d *= 2\n ans += 1\n d = max(d, ai)\n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14460.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\na = list(map(int, input().split()))\na.sort()\nans = 0\nfor i in range(n):\n while (k * 2 < a[i]):\n k *= 2\n ans += 1\n k = max(k, a[i])\nprint(ans)\n \n", "passed": true, "time": 0.15, "memory": 14420.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na = list(map(int, input().split()))\na.sort()\n\nresult = 0\n\nfor d in a:\n\twhile d > 2*k:\n\t\tk *= 2\n\t\tresult += 1\n\tk = max(d, k)\n\nprint(result)", "passed": true, "time": 0.17, "memory": 14444.0, "status": "done"}, {"code": "import sys\n\ndef main():\n n, k = map(int,sys.stdin.readline().split())\n a = list(map(int,sys.stdin.readline().split()))\n \n a = sorted(a)\n\n ans = 0\n for i in range(n):\n if k*2>=a[i]:\n k = max(k,a[i])\n else:\n t = a[i]\n while t>k*2:\n if t%2==1:\n t= int(t/2)+1\n else:\n t = int(t/2)\n ans+=1\n k = a[i]\n\n print(ans)\n\nmain()", "passed": true, "time": 0.22, "memory": 14408.0, "status": "done"}, {"code": "n,k = map(int,input().split())\nA = list(map(int,input().split()))\nA.sort()\ncnt = 0\nfor a in A:\n\twhile a > 2 * k:\n\t\tcnt += 1\n\t\tk *= 2\n\tk = max(k, a)\nprint(cnt)", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\ns = sorted(tuple(map(int, input().split())))\nmax = k\nans = 0\nfor a in s:\n if a > max:\n while max < a / 2:\n max = max * 2\n ans = ans + 1\n max = a\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14388.0, "status": "done"}, {"code": "import math \ndef main():\n n, k = list(map(int, input().split()))\n P = list(map(int, input().split()))\n P.sort()\n\n M = k\n count = 0\n for num in P:\n f = math.ceil(math.log2(num/M)) - 1\n # print(num/M, f)\n if f < 1:\n pass\n else:\n count += f\n M = max(M, num)\n print(count)\n\ndef __starting_point():\n # nonlocal stime\n # stime = time.clock()\n main()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14300.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\naa = sorted(map(int, input().split()))\n\nansw = 0\n\nfor a in aa:\n while 2 * k < a:\n k *= 2\n answ += 1\n k = max(k, a)\n\nprint(answ)\n", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "import math\n\nI = lambda: list(map(int, input().split()))\nn, k = I()\na = list(I())\n# print(a)\nans = 0\nfor task in sorted(a):\n if math.ceil(task/2) <= k:\n k = max(task, k)\n continue\n else:\n while not math.ceil(task/2) <= k:\n ans += 1\n k *= 2\n k = task\n\nprint(ans)\n\n", "passed": true, "time": 0.14, "memory": 14408.0, "status": "done"}, {"code": "n, k = map(int, input().split(' '))\nproblems = list(map(int, input().split(' ')))\n\nproblems.sort()\n# easy = []\n\n# for i in range(len(problems)):\n# \tif problems[i] > k:\n# \t\tproblems = problems[i:]\n# \t\tbreak\n\nmax_solved = k\nproblem_index = 0\nn_has_to_solve = 0\n\nwhile problem_index < n:\n\tif problems[problem_index] <= max_solved * 2:\n\t\tmax_solved = max(max_solved, problems[problem_index])\n\t\tproblem_index += 1\n\telse:\n\t\tmax_solved *= 2\n\t\tn_has_to_solve += 1\n\nprint(n_has_to_solve)", "passed": true, "time": 0.14, "memory": 14552.0, "status": "done"}, {"code": "\ndef MultiJudge(l,p):\n\tcount=0\n\tbefore=True\n\tl.sort()\n\th=[x for x in l if x<=2*p]\n\tif len(h) >0 and max(h)>p:\n\t\tp=max(h)\n\tb=[x for x in l if x>2*p]\n\twhile len(b)>0:\n\t\th=[x for x in l if x<=2*p]\n\t\tb=[x for x in l if x>2*p]\n\t\tif len(h) >0 and max(h)>p:\n\t\t\tp=max(h)\n\t\t\tbefore=False\n\t\t#b=[x for x in l if x>2*p]\n\t\tif len(b)>0 and before:\n\t\t\tp=p*2\n\t\t\tcount+=1\n\t\tbefore=True\n\tprint(count)\n\np=int(input().split()[1])\nl=[int(x) for x in input().split()]\nMultiJudge(l,p)", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "read = lambda: map(int, input().split())\nn, k = read()\na = sorted(read())\ncur = k\nans = 0\nfor i in a:\n while cur * 2 < i:\n cur *= 2\n ans += 1\n cur = max(cur, i)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14488.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na = sorted(list(map(int, input().split())))\nanswer = 0\nfor elem in a:\n while 2 * k < elem:\n k *= 2\n answer += 1\n k = max(k, elem)\nprint(answer)", "passed": true, "time": 0.15, "memory": 14224.0, "status": "done"}, {"code": "n, k = map(int, input().split())\na = sorted(map(int, input().split()))\nt = 0\nx = 0\nwhile max(a) > 2*k:\n while a[x] <= 2*k:\n x += 1\n if x > 0:\n k = max(k, a[x-1])\n while 2*k < a[x]:\n k *= 2\n t += 1\nprint(t)", "passed": true, "time": 0.24, "memory": 14336.0, "status": "done"}, {"code": "n, k = map(int, input().split())\n\nl = sorted([int(x) for x in input().split()])\n\nans = 0\n\nfor i in range(len(l)):\n while 2 * k < l[i]:\n ans += 1\n k *= 2\n k = max(k, l[i])\n \nprint(ans)", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "n, k = map(int, input().split(\" \"))\n\narr = sorted([int(i) for i in input().split(\" \")])\n\nanswer = 0\nfor i in range(n):\n while 2 * k < arr[i]:\n answer += 1\n k *= 2\n k = max(k, arr[i])\n\nprint(answer)", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "n,k=map(int,input().split())\nans=0\nfor i in sorted(map(int,input().split())):\n while i>2*k:\n ans+=1\n k*=2\n k=max(k,i)\nprint(ans)", "passed": true, "time": 0.17, "memory": 14432.0, "status": "done"}, {"code": "def judge():\n count = 0\n S = input()\n T = input()\n sList = S.split()\n sList = [int(i) for i in sList]\n tList = T.split()\n n = sList[0]\n k = sList[1]\n tList = [int(i) for i in tList]\n uList = sorted(tList)\n for num in uList:\n if (2*k >= num):\n if (k<num):\n k = num\n pass\n else:\n while True:\n k = 2*k\n count += 1\n if (2*k >= num):\n if (k < num):\n k = num\n break\n print(count)\n\n\njudge()", "passed": true, "time": 0.14, "memory": 14308.0, "status": "done"}]
[{"input": "3 3\n2 1 9\n", "output": "1\n"}, {"input": "4 20\n10 3 6 3\n", "output": "0\n"}, {"input": "1 1000000000\n1\n", "output": "0\n"}, {"input": "1 1\n3\n", "output": "1\n"}, {"input": "50 100\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 7 3 63 46 18 16 44 89 62 25 32 12 38 55 75 56 61 82\n", "output": "0\n"}, {"input": "100 10\n246 286 693 607 87 612 909 312 621 37 801 558 504 914 416 762 187 974 976 123 635 488 416 659 988 998 93 662 92 749 889 78 214 786 735 625 921 372 713 617 975 119 402 411 878 138 548 905 802 762 940 336 529 373 745 835 805 880 816 94 166 114 475 699 974 462 61 337 555 805 968 815 392 746 591 558 740 380 668 29 881 151 387 986 174 923 541 520 998 947 535 651 103 584 664 854 180 852 726 93\n", "output": "1\n"}, {"input": "2 1\n1 1000000000\n", "output": "29\n"}, {"input": "29 2\n1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 262143 524287 1048575 2097151 4194303 8388607 16777215 33554431 67108863 134217727 268435455 536870911\n", "output": "27\n"}, {"input": "1 1\n1000000000\n", "output": "29\n"}, {"input": "7 6\n4 20 16 14 3 17 4\n", "output": "1\n"}, {"input": "2 1\n3 6\n", "output": "1\n"}, {"input": "1 1\n20\n", "output": "4\n"}, {"input": "5 2\n86 81 53 25 18\n", "output": "4\n"}, {"input": "4 1\n88 55 14 39\n", "output": "4\n"}, {"input": "3 1\n2 3 6\n", "output": "0\n"}, {"input": "3 2\n4 9 18\n", "output": "1\n"}, {"input": "5 3\n6 6 6 13 27\n", "output": "2\n"}, {"input": "5 1\n23 8 83 26 18\n", "output": "4\n"}, {"input": "3 1\n4 5 6\n", "output": "1\n"}, {"input": "3 1\n1 3 6\n", "output": "1\n"}, {"input": "1 1\n2\n", "output": "0\n"}, {"input": "3 2\n4 5 6\n", "output": "0\n"}, {"input": "5 1\n100 200 400 1000 2000\n", "output": "7\n"}, {"input": "2 1\n1 4\n", "output": "1\n"}, {"input": "4 1\n2 4 8 32\n", "output": "1\n"}, {"input": "2 10\n21 42\n", "output": "1\n"}, {"input": "3 3\n1 7 13\n", "output": "1\n"}, {"input": "3 1\n1 4 6\n", "output": "1\n"}, {"input": "2 2\n2 8\n", "output": "1\n"}, {"input": "1 1\n4\n", "output": "1\n"}, {"input": "2 2\n8 16\n", "output": "1\n"}, {"input": "3 1\n4 8 16\n", "output": "1\n"}, {"input": "3 1\n3 6 9\n", "output": "1\n"}, {"input": "2 1\n4 8\n", "output": "1\n"}, {"input": "2 2\n7 14\n", "output": "1\n"}, {"input": "1 4\n9\n", "output": "1\n"}, {"input": "5 3\n1024 4096 16384 65536 536870913\n", "output": "24\n"}, {"input": "2 5\n10 11\n", "output": "0\n"}, {"input": "2 2\n3 6\n", "output": "0\n"}, {"input": "2 2\n8 11\n", "output": "1\n"}, {"input": "3 19905705\n263637263 417905394 108361057\n", "output": "3\n"}, {"input": "4 25\n100 11 1 13\n", "output": "1\n"}, {"input": "10 295206008\n67980321 440051990 883040288 135744260 96431758 242465794 576630162 972797687 356406646 547451696\n", "output": "0\n"}, {"input": "4 2\n45 44 35 38\n", "output": "4\n"}, {"input": "1 2\n9\n", "output": "2\n"}, {"input": "3 6\n13 26 52\n", "output": "1\n"}, {"input": "9 30111088\n824713578 11195876 458715185 731769293 680826358 189542586 550198537 860586039 101083021\n", "output": "2\n"}, {"input": "3 72014068\n430005292 807436976 828082746\n", "output": "2\n"}, {"input": "3 165219745\n737649884 652879952 506420386\n", "output": "1\n"}, {"input": "2 60669400\n95037700 337255240\n", "output": "1\n"}, {"input": "4 28\n34 1 86 90\n", "output": "1\n"}, {"input": "2 1\n5 10\n", "output": "2\n"}, {"input": "2 1\n4 1000000000\n", "output": "28\n"}, {"input": "2 1\n2 3\n", "output": "0\n"}, {"input": "2 1\n3 5\n", "output": "1\n"}, {"input": "3 3\n1 5 20\n", "output": "1\n"}, {"input": "9 1\n1 2 4 9 15 32 64 128 1024\n", "output": "4\n"}]
353
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0. As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. -----Input----- The first line of the input contains a single integer n (1 ≀ n ≀ 92)Β β€” the number of consecutive days Vitya was watching the size of the visible part of the moon. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 15)Β β€” Vitya's records. It's guaranteed that the input data is consistent. -----Output----- If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. -----Examples----- Input 5 3 4 5 6 7 Output UP Input 7 12 13 14 15 14 13 12 Output DOWN Input 1 8 Output -1 -----Note----- In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP". In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN". In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
interview
[{"code": "# You lost the game.\n\nn = int(input())\nL = list(map(int, input().split()))\n\nif n == 1:\n if L[0] == 0:\n print(\"UP\")\n elif L[0] == 15:\n print(\"DOWN\")\n else:\n print(\"-1\")\nelse:\n d = L[n-2] - L[n-1]\n if d < 0:\n if L[n-1] == 15:\n print(\"DOWN\")\n else:\n print(\"UP\")\n else:\n if L[n-1] == 0:\n print(\"UP\")\n else:\n print(\"DOWN\")\n", "passed": true, "time": 0.24, "memory": 14228.0, "status": "done"}, {"code": "n = int(input())\nline = list(map(int, input().split()))\nif n == 1 and line[0] != 0 and line[0] != 15:\n print(-1)\nelif n == 1 and line[0] == 0:\n print(\"UP\")\nelif n == 1:\n print(\"DOWN\")\nelse:\n if line[-1] > line[-2] and line[-1] == 15:\n print(\"DOWN\")\n elif line[-1] > line[-2]:\n print(\"UP\")\n elif line[-1] == 0:\n print(\"UP\")\n else:\n print(\"DOWN\")\n", "passed": true, "time": 0.21, "memory": 14452.0, "status": "done"}, {"code": "n = int(input())\nk = list(map(int, input().split()))\n\nUP = \"UP\"\nDOWN = \"DOWN\"\n\nif k[-1] == 15:\n print(DOWN)\nelif k[-1] == 0:\n print(UP)\nelif n == 1:\n print(-1)\nelse:\n if k[-2] > k[-1]:\n print(DOWN)\n else:\n print(UP)\n", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "import sys, math\nn = int(input())\nz = list(map(int, input().split()))\nif n == 1:\n if z[0] == 0:\n print('UP')\n return\n if z[0] == 15:\n print('DOWN')\n return\n print(-1)\n return\nif z[-1] == 0:\n print('UP')\n return\nif z[-1] == 15:\n print('DOWN')\n return\nz.append(z[-1] + z[-1] - z[-2])\nif z[-1] > z[-2]:\n print('UP')\nelse:\n print('DOWN')", "passed": true, "time": 0.16, "memory": 14460.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nif (a[-1] == 15):\n print(\"DOWN\")\n return\nelif a[-1] == 0:\n print(\"UP\")\n return\nif (len(a) == 1):\n print(-1)\nelse:\n if (a[-1] < a[-2]):\n print(\"DOWN\")\n else:\n print(\"UP\")", "passed": true, "time": 0.15, "memory": 14552.0, "status": "done"}, {"code": "arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n\nn = int(input())\nprr = [int(x) for x in input().split()]\nif(n==1):\n a = prr[0]\n if(a==0):\n print('UP')\n elif(a==15):\n print('DOWN')\n else:\n print(-1)\nelse:\n a,b = prr[n-2],prr[n-1]\n c = b-a\n if(c==1):\n if(b!=15):\n print('UP')\n else:\n print('DOWN')\n else:\n if(b!=0):\n print('DOWN')\n else:\n print('UP')", "passed": true, "time": 0.22, "memory": 14528.0, "status": "done"}, {"code": "n = int(input())\ndata = list(map(int, input().split()))\nif data[-1] == 0:\n print(\"UP\")\nelif data[-1] == 15:\n print(\"DOWN\")\nelse: \n if n == 1:\n print(-1)\n elif data[-1] - data[-2] > 0:\n print(\"UP\")\n else: \n print(\"DOWN\")\n", "passed": true, "time": 0.26, "memory": 14288.0, "status": "done"}, {"code": "n = int(input())\nA = list(map(int, input().split()))\nif n == 1:\n if A[0] == 15:\n print('DOWN')\n elif A[0] == 0:\n print('UP')\n else:\n print(-1)\nelse:\n per = A[-1]\n per2 = A[-2]\n if per == 15:\n print('DOWN')\n elif per == 0:\n print('UP')\n else:\n if per > per2:\n print('UP')\n else:\n print('DOWN')\n", "passed": true, "time": 0.24, "memory": 14356.0, "status": "done"}, {"code": "n=int(input())\nl=list(map(int,input().split()))\nif n==1:\n if l[0]==0: print(\"UP\")\n elif l[0]==15: print(\"DOWN\")\n else: print(-1)\nelif (l[-1]==0 or l[-2]<l[-1]) and l[-1]!=15: print(\"UP\")\nelse: print(\"DOWN\")", "passed": true, "time": 0.14, "memory": 14424.0, "status": "done"}, {"code": "n = int(input())\n\nai = [int(x) for x in input().split(' ')]\n\nif ai[-1] == 0:\n print('UP')\n return\nelif ai[-1] == 15:\n print('DOWN')\n return\n\nif n == 1 and ai[0] not in [0, 15]:\n print(-1)\n return\n\nk = ai[-2:]\n\nif k[0] - k[1] > 0:\n print('DOWN')\nelse:\n print('UP')\n", "passed": true, "time": 0.24, "memory": 14404.0, "status": "done"}, {"code": "n = int(input().strip())\narr = [int(x) for x in input().strip().split(' ')]\nif n == 1:\n if arr[0] == 0:\n print('UP')\n elif arr[0] == 15:\n print('DOWN')\n else:\n print(-1)\nelse:\n if arr[n-1] == 0:\n print('UP')\n elif arr[n-1] == 15:\n print('DOWN')\n else:\n print('UP' if arr[n-1] > arr[n-2] else 'DOWN')\n\n", "passed": true, "time": 0.15, "memory": 14452.0, "status": "done"}, {"code": "n = int(input().strip())\na = list(map(int, input().split()))\nif a[-1] == 15:\n print('DOWN')\nelif a[-1] == 0:\n print('UP')\nelse:\n if n == 1:\n print(-1)\n else:\n if a[-2] < a[-1]:\n print('UP')\n else:\n print('DOWN')\n", "passed": true, "time": 0.14, "memory": 14296.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nfrom sys import stdin\n\n\ndef main():\n n, = stdin_get_ints_from_line()\n x = stdin_get_ints_list_from_line()\n\n if x[-1] == 15:\n print('DOWN')\n return\n\n if x[-1] == 0:\n print('UP')\n return\n\n if n == 1:\n print('-1')\n return\n\n if x[-1] > x[-2]:\n print('UP')\n\n if x[-1] < x[-2]:\n print('DOWN')\n\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.26, "memory": 14536.0, "status": "done"}, {"code": "n=int(input())\nd=input().split()\nd=[int(x) for x in d]\nif n==1 and int (d[0])!=15 and int (d[0])!=0:\n print(-1)\nelif n==1 and int(d[0])==0:\n print(\"UP\")\nelif n==1 and int(d[0])==15:\n print(\"DOWN\")\nelse:\n if (d[-1]>d[-2] and d[-1]!=15 )or d[-1]==0:\n print(\"UP\")\n elif ( d[-1]<d[-2] and d[-1]!=0) or d[-1]==15:\n print(\"DOWN\")\n", "passed": true, "time": 0.15, "memory": 14324.0, "status": "done"}, {"code": "from sys import stdin as fin\n# fin = open(\"cfr373a.in\")\n\nn = int(fin.readline())\n# n, m = map(int, fin.readline.split())\nnums = tuple(map(int, fin.readline().split()))\n\nans = {15: \"DOWN\", 0: \"UP\"}\nif nums[-1] in ans:\n print(ans[nums[-1]])\nelif len(nums) == 1:\n print(-1)\nelse:\n print(\"DOWN\" if nums[-1] < nums[-2] else \"UP\")", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "n = int(input())\na = [int(_) for _ in input().split()]\nif a[-1] == 15:\n print('DOWN')\nelif a[-1] == 0:\n print('UP')\nelif n == 1:\n print(-1)\nelif a[-1] > a[-2]:\n print('UP')\nelse:\n print('DOWN')\n", "passed": true, "time": 0.15, "memory": 14296.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nn=int(input())\ndays=list(map(int,input().split()))\n\nif days[-1] == 0:\n print(\"UP\")\nelif days[-1] == 15:\n print(\"DOWN\")\nelif n == 1:\n print(\"-1\")\nelse:\n if days[-1] - days[-2] > 0:\n print(\"UP\")\n else:\n print(\"DOWN\")\n\n", "passed": true, "time": 0.15, "memory": 14304.0, "status": "done"}, {"code": "n=int(input())\na = list(map(int,input().split()))\nif n>1:\n\tif a[n-1]>a[n-2]:\n\t\tif a[n-1]==15:\n\t\t\tprint('DOWN')\n\t\telse:\n\t\t\tprint('UP')\n\telse:\n\t\tif a[n-1]==15:\n\t\t\tprint('DOWN')\n\t\telse:\n\t\t\t\tif a[n-1]==0:\n\t\t\t\t\tprint('UP')\n\t\t\t\telse:\n\t\t\t\t\tprint('DOWN')\nelse:\n\tif a[0]==15:\n\t\tprint('DOWN')\n\telse:\n\t\tif a[0]==0:\n\t\t\tprint('UP')\n\t\telse:\n\t\t\tprint(-1)\n", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nif a[-1] == 0:\n print(\"UP\")\nelif a[-1] == 15:\n print(\"DOWN\")\nelif n == 1:\n print(-1)\nelse:\n if a[-1] > a[-2]:\n print(\"UP\")\n else:\n print(\"DOWN\")", "passed": true, "time": 0.14, "memory": 14440.0, "status": "done"}, {"code": "def ans(n, seq):\n if n == 1:\n if seq[0] == 0:\n return 'UP'\n elif seq[0] == 15:\n return 'DOWN'\n else:\n return -1\n elif seq[-1] == 15:\n return 'DOWN'\n elif seq[-1] == 0:\n return 'UP'\n elif seq[-1] > seq[-2] and seq[-1] != 15:\n return 'UP'\n elif seq[-1] < seq[-2] and seq[-1] != 0:\n return 'DOWN'\n\nn = int(input())\nseq = list(map(int, input().split()))\nprint(ans(n,seq))", "passed": true, "time": 0.15, "memory": 14304.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\n\nif n == 1 and a[0] != 0 and a[0] != 15:\n print(-1)\nelif a[-1] == 0:\n print(\"UP\")\nelif a[-1] == 15:\n print(\"DOWN\")\nelif a[-2] < a[-1]:\n print(\"UP\") \nelif a[-2] > a[-1]:\n print(\"DOWN\")", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "def main():\n n = int(input())\n\n a = [int(s) for s in input().split()]\n\n if a[-1] == 15:\n print(\"DOWN\")\n return\n if a[-1] == 0:\n print(\"UP\")\n return\n if n == 1:\n print(-1)\n return\n if a[-2] < a[-1]:\n print(\"UP\")\n return\n else:\n print(\"DOWN\")\n return\n\nmain()\n", "passed": true, "time": 0.14, "memory": 14368.0, "status": "done"}, {"code": "def main():\n n = int(input())\n days = list(map(int, input().split()))\n if n == 1:\n if days[0] == 15:\n print(\"DOWN\")\n elif days[0] == 0:\n print(\"UP\")\n else:\n print(-1)\n return\n moves = [1, -1]\n now = 0\n last = days[0]\n if days[1] < days[0]:\n now = (now + 1) % 2\n for i in range(1, n):\n last += moves[now]\n if last == 0 or last == 15:\n now = (now + 1) % 2\n if now == 1:\n print(\"DOWN\")\n else:\n print(\"UP\")\nmain()", "passed": true, "time": 0.24, "memory": 14412.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\n\nif n <= 1:\n\tif n and a[0] in (0, 15):\n\t\tprint('UP' if a[0] == 0 else 'DOWN')\n\t\treturn\n\tprint('-1')\n\treturn\n\nif a[-1] - a[-2] >= 1:\n\tif a[-1] < 15:\n\t\tprint('UP')\n\telse:\n\t\tprint('DOWN')\nelse:\n\tif a[-1] <= 0:\n\t\tprint('UP')\n\telse:\n\t\tprint('DOWN')\n\n", "passed": true, "time": 0.14, "memory": 14216.0, "status": "done"}]
[{"input": "5\n3 4 5 6 7\n", "output": "UP\n"}, {"input": "7\n12 13 14 15 14 13 12\n", "output": "DOWN\n"}, {"input": "1\n8\n", "output": "-1\n"}, {"input": "44\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10\n", "output": "DOWN\n"}, {"input": "92\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4\n", "output": "UP\n"}, {"input": "6\n10 11 12 13 14 15\n", "output": "DOWN\n"}, {"input": "27\n11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n", "output": "DOWN\n"}, {"input": "6\n8 7 6 5 4 3\n", "output": "DOWN\n"}, {"input": "27\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10\n", "output": "UP\n"}, {"input": "79\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5\n", "output": "DOWN\n"}, {"input": "25\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7\n", "output": "DOWN\n"}, {"input": "21\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7\n", "output": "DOWN\n"}, {"input": "56\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6\n", "output": "DOWN\n"}, {"input": "19\n4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14\n", "output": "UP\n"}, {"input": "79\n5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13\n", "output": "UP\n"}, {"input": "87\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10\n", "output": "UP\n"}, {"input": "13\n10 9 8 7 6 5 4 3 2 1 0 1 2\n", "output": "UP\n"}, {"input": "2\n8 9\n", "output": "UP\n"}, {"input": "3\n10 11 12\n", "output": "UP\n"}, {"input": "1\n1\n", "output": "-1\n"}, {"input": "1\n2\n", "output": "-1\n"}, {"input": "1\n3\n", "output": "-1\n"}, {"input": "1\n4\n", "output": "-1\n"}, {"input": "1\n5\n", "output": "-1\n"}, {"input": "1\n6\n", "output": "-1\n"}, {"input": "1\n7\n", "output": "-1\n"}, {"input": "1\n9\n", "output": "-1\n"}, {"input": "1\n10\n", "output": "-1\n"}, {"input": "1\n11\n", "output": "-1\n"}, {"input": "1\n12\n", "output": "-1\n"}, {"input": "1\n13\n", "output": "-1\n"}, {"input": "1\n14\n", "output": "-1\n"}, {"input": "1\n15\n", "output": "DOWN\n"}, {"input": "1\n0\n", "output": "UP\n"}, {"input": "3\n11 12 13\n", "output": "UP\n"}, {"input": "2\n10 9\n", "output": "DOWN\n"}, {"input": "92\n10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11\n", "output": "UP\n"}, {"input": "92\n7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6\n", "output": "DOWN\n"}, {"input": "2\n14 15\n", "output": "DOWN\n"}, {"input": "2\n1 0\n", "output": "UP\n"}, {"input": "2\n15 14\n", "output": "DOWN\n"}, {"input": "92\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8\n", "output": "UP\n"}, {"input": "92\n13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12\n", "output": "DOWN\n"}, {"input": "92\n4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3\n", "output": "DOWN\n"}, {"input": "92\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n", "output": "DOWN\n"}, {"input": "92\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0\n", "output": "UP\n"}, {"input": "2\n2 1\n", "output": "DOWN\n"}, {"input": "3\n2 1 0\n", "output": "UP\n"}, {"input": "5\n4 3 2 1 0\n", "output": "UP\n"}, {"input": "2\n5 4\n", "output": "DOWN\n"}, {"input": "4\n3 2 1 0\n", "output": "UP\n"}, {"input": "3\n13 12 11\n", "output": "DOWN\n"}, {"input": "2\n1 2\n", "output": "UP\n"}, {"input": "2\n0 1\n", "output": "UP\n"}, {"input": "2\n13 14\n", "output": "UP\n"}, {"input": "14\n13 12 11 10 9 8 7 6 5 4 3 2 1 0\n", "output": "UP\n"}]
354
We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name $s$ can transform to another superhero with name $t$ if $s$ can be made equal to $t$ by changing any vowel in $s$ to any other vowel and any consonant in $s$ to any other consonant. Multiple changes can be made. In this problem, we consider the letters 'a', 'e', 'i', 'o' and 'u' to be vowels and all the other letters to be consonants. Given the names of two superheroes, determine if the superhero with name $s$ can be transformed to the Superhero with name $t$. -----Input----- The first line contains the string $s$ having length between $1$ and $1000$, inclusive. The second line contains the string $t$ having length between $1$ and $1000$, inclusive. Both strings $s$ and $t$ are guaranteed to be different and consist of lowercase English letters only. -----Output----- Output "Yes" (without quotes) if the superhero with name $s$ can be transformed to the superhero with name $t$ and "No" (without quotes) otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input a u Output Yes Input abc ukm Output Yes Input akm ua Output No -----Note----- In the first sample, since both 'a' and 'u' are vowels, it is possible to convert string $s$ to $t$. In the third sample, 'k' is a consonant, whereas 'a' is a vowel, so it is not possible to convert string $s$ to $t$.
interview
[{"code": "v = list('aeiou')\ns = [c in v for c in input()]\nt = [c in v for c in input()]\nif s == t:\n print('Yes')\nelse:\n print('No')", "passed": true, "time": 1.81, "memory": 14224.0, "status": "done"}, {"code": "s=input()\nt=input()\nar=[]\nbr=[]\nfor x in range(len(s)):\n if(s[x] in 'aeiou'):\n ar.append(1)\n else: ar.append(0)\nfor x in range(len(t)):\n if(t[x] in 'aeiou'):\n br.append(1)\n else: br.append(0)\nprint(\"Yes\" if ar==br else \"No\")", "passed": true, "time": 0.16, "memory": 14308.0, "status": "done"}, {"code": "import itertools\nimport math\nfrom collections import defaultdict\n\ndef input_ints():\n return list(map(int, input().split()))\n\ndef solve():\n s = input()\n t = input()\n if len(s) != len(t):\n print('No')\n return\n for i in range(len(s)):\n x = 0\n if s[i] in 'aiueo':\n x += 1\n if t[i] in 'aiueo':\n x += 1\n if x == 1:\n print('No')\n return\n print('Yes')\n\ndef __starting_point():\n solve()\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "s = input()\nt = input()\nvow = 'aeoui'\nif len(s) != len(t):\n\tprint(\"No\")\nelse:\n\tfor i in range(len(s)):\n\t\tif (s[i] in vow) != (t[i] in vow):\n\t\t\tprint(\"No\")\n\t\t\tbreak\n\telse:\n\t\tprint(\"Yes\")\n", "passed": true, "time": 0.16, "memory": 14432.0, "status": "done"}, {"code": "s = input()\nt = input()\n\nv = 'aeiou'\n\nok = len(s) == len(t)\n\nif ok:\n for i in range(len(s)):\n isv1 = s[i] in v\n isv2 = t[i] in v\n ok &= (isv1 and isv2) or (not isv1 and not isv2)\nif ok:\n print('Yes')\nelse:\n print('No')", "passed": true, "time": 0.23, "memory": 14504.0, "status": "done"}, {"code": "s = input()\nt = input()\nvowels = 'aeiou'\nif len(s) != len(t):\n print(\"No\")\nelse:\n for i in range(len(s)):\n if ((s[i] in vowels) ^ (t[i] in vowels)):\n print(\"No\")\n break\n else:\n print(\"Yes\")", "passed": true, "time": 0.17, "memory": 14504.0, "status": "done"}, {"code": "s = input().strip()\nt = input().strip()\nok = 0\nvow = 'aeiou'\nif len(s) == len(t):\n ok = 1\n for a, b in zip(s, t):\n if (a in vow) ^ (b in vow):\n ok = 0\n break\nprint('Yes' if ok else 'No')\n", "passed": true, "time": 0.14, "memory": 14432.0, "status": "done"}, {"code": "def read_nums():\n return [int(x) for x in input().split()]\n\n\ndef main():\n s = input()\n t = input()\n if len(s) != len(t):\n print('No')\n return\n\n vowels = 'aeiou'\n for one, two in zip(s, t):\n if (one in vowels) != (two in vowels):\n print('No')\n return\n print('Yes')\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14288.0, "status": "done"}, {"code": "vowels = ['a','e','i','o','u']\ns = input()\nt = input()\nif len(s)!= len(t):\n\tprint(\"No\")\n\treturn\nelse:\n\tfor i in range(len(s)):\n\t\tif s[i] in vowels and t[i] not in vowels:\n\t\t\tprint(\"No\")\n\t\t\treturn\n\t\telif s[i] not in vowels and t[i] in vowels:\n\t\t\tprint(\"No\")\n\t\t\treturn\n\tprint(\"Yes\")", "passed": true, "time": 0.14, "memory": 14404.0, "status": "done"}, {"code": "def solve(a, b):\n if len(a) != len(b):\n return False\n\n vowels = set([\"a\", \"e\", \"i\", \"o\", \"u\"])\n for index in range(len(a)):\n a_vowel = a[index] in vowels\n b_vowel = b[index] in vowels\n if a_vowel != b_vowel:\n return False\n\n return True \n\na = input()\nb = input()\nif solve(a, b):\n print(\"Yes\")\nelse:\n print(\"No\")", "passed": true, "time": 0.14, "memory": 14528.0, "status": "done"}, {"code": "s = input()\nt = input()\nif (len(s) != len(t)):\n print(\"No\")\nelse:\n g = ['a', 'e', 'i', 'o', 'u']\n for i in range(len(s)):\n if (s[i] in g) != (t[i] in g):\n print(\"No\")\n break\n else:\n print(\"Yes\")\n", "passed": true, "time": 0.15, "memory": 14316.0, "status": "done"}, {"code": "v = 'aeiou'\n\na = input()\nb = input()\n\nans = True\nif (len(a) == len(b)):\n\n for i in range(len(a)):\n x= a[i]\n y = b[i]\n\n q = x in v\n w = y in v\n\n if (q ^ w):\n ans = False\n\n if ans:\n print('Yes')\n else:\n print('No')\nelse:\n print('No')\n", "passed": true, "time": 0.14, "memory": 14524.0, "status": "done"}, {"code": "a = {'a', 'e', 'i', 'o', 'u'}\n\n\ns = input()\nk = input()\nif len(s) != len(k):\n print(\"No\")\n return\nfor i in range(len(s)):\n if not ((s[i] in a and k[i] in a) or (s[i] not in a and k[i] not in a)):\n print(\"No\")\n return\nprint(\"Yes\")", "passed": true, "time": 0.14, "memory": 14204.0, "status": "done"}, {"code": "vowels = ['a', 'e', 'i', 'o', 'u']\n\na, b = input(), input()\n\nif len(a) != len(b):\n print('No')\nelse:\n ok = True\n for i in range(len(a)):\n ok = ok and ((a[i] in vowels) == (b[i] in vowels))\n if ok:\n print('Yes')\n else:\n print('No')", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "import sys\n\ninput = sys.stdin.readline\n\ns = input().strip()\nt = input().strip()\n\nif len(s) != len(t):\n print('No')\n return\n\nvow = set(['a', 'e', 'i', 'o', 'u'])\n\nvalid = True\nfor i in range(len(s)):\n if s[i] in vow and not t[i] in vow:\n valid = False\n break\n if t[i] in vow and not s[i] in vow:\n valid = False\n break\n\nif valid:\n print('Yes')\nelse:\n print('No')", "passed": true, "time": 0.14, "memory": 14476.0, "status": "done"}, {"code": "s = input()\nt = input()\nif len(s) != len(t):\n print(\"No\")\nelse:\n g = ['a', 'e', 'i', 'o', 'u']\n for i in range(len(s)):\n if (s[i] in g and t[i] not in g) or (s[i] not in g and t[i] in g):\n print(\"No\")\n return\n print(\"Yes\")\n", "passed": true, "time": 0.15, "memory": 14260.0, "status": "done"}, {"code": "import sys\n\ns = input()\nt = input()\n\nif len(s) != len(t):\n print('No')\n return\n\nVOWELS = 'aeiou'\n\nfor a, b in zip(s, t):\n if a in VOWELS and b not in VOWELS or b in VOWELS and a not in VOWELS:\n print('No')\n return\n\nprint('Yes')\n", "passed": true, "time": 0.15, "memory": 14288.0, "status": "done"}, {"code": "gl = ['a', 'e', 'i', 'o', 'u']\ns1 = input()\ns2 = input()\nif len(s1) != len(s2):\n print('No')\nelse:\n ok = True\n for i in range(len(s1)):\n if (s1[i] in gl and s2[i] not in gl) or (s1[i] not in gl and s2[i] in gl):\n ok = False\n if ok:\n print('Yes')\n else:\n print('No')\n", "passed": true, "time": 0.14, "memory": 14284.0, "status": "done"}, {"code": "s=input()\nt=input()\nglas= ['a', 'e', 'i', 'o' ,'u']\nif len(s)==len(t):\n for i in range(len(s)):\n if (s[i] in glas and t[i] in glas) or (s[i] not in glas and t[i] not in glas):\n counter=0\n else:\n print('No')\n break\n else:\n print('Yes')\nelse:\n print('No')\n", "passed": true, "time": 0.14, "memory": 14408.0, "status": "done"}, {"code": "glas = ['a', 'e', 'i', 'o', 'u']\n\ns = input()\ns1 = input()\n\nif len(s) != len(s1):\n print(\"No\")\n return\nelse:\n for i in range(len(s)):\n if (s[i] in glas and not s1[i] in glas):\n print(\"No\")\n return\n if not s[i] in glas and s1[i] in glas:\n print(\"No\")\n return\nprint(\"Yes\")\n", "passed": true, "time": 0.16, "memory": 14520.0, "status": "done"}, {"code": "from sys import stdin\n\ns=stdin.readline().strip()\n\ns1=stdin.readline().strip()\na=[\"a\",\"e\",\"i\",\"o\",\"u\"]\nif len(s)!=len(s1):\n print(\"No\")\n return\nt=True\nfor i in range(len(s)):\n if s[i] not in a and s1[i] in a:\n t=False\n if s1[i] not in a and s[i] in a:\n t=False\nif t:\n print(\"Yes\")\nelse:\n print(\"No\")\n", "passed": true, "time": 0.16, "memory": 14480.0, "status": "done"}, {"code": "s = input()\nt = input()\n\nif len(s) != len(t):\n print(\"No\")\nelse:\n v = \"aeiou\"\n c = \"qwrtypsdfghjklzxcvbnm\"\n flag = 0\n for i, j in zip(s, t):\n if (i in v and j not in v) or (i in c and j not in c):\n flag = 1\n break\n if flag:\n print(\"No\")\n else:\n print(\"Yes\")\n", "passed": true, "time": 0.14, "memory": 14348.0, "status": "done"}, {"code": "s = input()\nt = input()\nv = [\"a\", \"i\", \"u\", \"e\", \"o\"]\nflag = True\nif len(s) != len(t):\n print(\"No\")\nelse:\n for i in range(len(s)):\n if not ((s[i] in v and t[i] in v) or (s[i] not in v and t[i] not in v)):\n flag = False\n\n if flag:\n print(\"Yes\")\n else:\n print(\"No\")", "passed": true, "time": 0.14, "memory": 14336.0, "status": "done"}]
[{"input": "a\nu\n", "output": "Yes\n"}, {"input": "abc\nukm\n", "output": "Yes\n"}, {"input": "akm\nua\n", "output": "No\n"}, {"input": "u\nd\n", "output": "No\n"}, {"input": "aaaaaeeeeeiiiiiooooouuuuu\naeiouaeiouaeiouaeiouaeiou\n", "output": "Yes\n"}, {"input": "aaaaaeeeeeiiiiiooooouuuuu\nqwrtysdfghjklzxcvbnmplmjk\n", "output": "No\n"}, {"input": "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdchiytqlfsevymipufxkxojlvkkqxvjhpjmcxeiluua\nblcdiwjphlpzwvknsyvbcodpyktizgatrlieiikktghixbikehsiknjuateltwkyyhgabygwtclyeyquaoiqnypoxnvyzvyhfejole\n", "output": "No\n"}, {"input": "oihjee\naedcouklbbbcccvfgjkl\n", "output": "No\n"}, {"input": "abcdefghikl\njhg\n", "output": "No\n"}, {"input": "eeiaoouoouaiaiizjgkmwdqsgvqltfylymtdfrggphtfcaieiuueouaeieeiuuieuieaaeueiaeuaaiuiauueuiuieeaaoudymrtstxqsa\nouiiuaaaieiaueetzfpsncxlscpkwjlqymqqyckydhrhweueoeoeaauiiuaeauueuioueuioeoeoooeeuieoiouaieeuieegmrhdbfwttu\n", "output": "Yes\n"}, {"input": "eieoiiieaiuiiauieeuoueeoudljpjrpxdtqkrdfmhktpqrnkmyggywglpfpfmhrbaiioeuaieaouaoioaiuoiuueuaoouaeeoaaaueauueeiuaueuaeouiaaaieeaeiuouoiooauuoeauaiaoouuauuuuocqschpcxrxrgrcsjmwcbyfvtdxqtwha\naoeaoaoueieeioooiaooeoeoitvplxwkprykbhvxylcnxrhpgqclyjgfpzdpqwlcvouooeueoouieioeuouieoaaueuiiiaeoiaeueoiaioaioauiuuuuiaieauaeaieeeueouaeoaoeouuoioaaooaeiiopwbyvkywxvqqtxnzpswdwtzywfpslju\n", "output": "Yes\n"}, {"input": "oujhgi\nabklpoooeisididisicmdmscdcdsa\n", "output": "No\n"}, {"input": "zdfouibgjjjkjkkkklllllalllalas\nrtgaoufk\n", "output": "No\n"}, {"input": "f\nk\n", "output": "Yes\n"}, {"input": "z\no\n", "output": "No\n"}, {"input": "ab\nba\n", "output": "No\n"}, {"input": "ak\nka\n", "output": "No\n"}, {"input": "abab\nbaba\n", "output": "No\n"}, {"input": "aab\nbaa\n", "output": "No\n"}, {"input": "ka\nak\n", "output": "No\n"}, {"input": "b\na\n", "output": "No\n"}, {"input": "abcdef\ncdaebf\n", "output": "No\n"}, {"input": "ba\nab\n", "output": "No\n"}, {"input": "aabb\naaabbb\n", "output": "No\n"}, {"input": "aq\nqa\n", "output": "No\n"}, {"input": "abc\ndef\n", "output": "No\n"}, {"input": "abcdef\ncdabef\n", "output": "No\n"}, {"input": "aaa\naa\n", "output": "No\n"}, {"input": "abc\ncab\n", "output": "No\n"}, {"input": "abaa\naaba\n", "output": "No\n"}, {"input": "aabb\nbbaa\n", "output": "No\n"}, {"input": "aaabbb\nbbbaaa\n", "output": "No\n"}, {"input": "aaa\naaabb\n", "output": "No\n"}, {"input": "abc\ncde\n", "output": "No\n"}, {"input": "abcde\nbcaed\n", "output": "No\n"}, {"input": "aaba\nabaa\n", "output": "No\n"}, {"input": "a\naa\n", "output": "No\n"}, {"input": "uam\nua\n", "output": "No\n"}, {"input": "aabb\nabab\n", "output": "No\n"}, {"input": "def\nabc\n", "output": "No\n"}, {"input": "abc\nbca\n", "output": "No\n"}, {"input": "az\nza\n", "output": "No\n"}, {"input": "aba\nbaa\n", "output": "No\n"}, {"input": "abc\nkmu\n", "output": "No\n"}, {"input": "ab\na\n", "output": "No\n"}, {"input": "abab\naabb\n", "output": "No\n"}, {"input": "art\ntor\n", "output": "No\n"}, {"input": "bcd\naei\n", "output": "No\n"}, {"input": "am\nma\n", "output": "No\n"}, {"input": "anne\nnnae\n", "output": "No\n"}, {"input": "aabcd\nbcaad\n", "output": "No\n"}, {"input": "bb\nb\n", "output": "No\n"}, {"input": "abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n", "output": "No\n"}, {"input": "abcd\na\n", "output": "No\n"}, {"input": "dkjsafhdlgfkjhdsgklhfjaghlfkdfjghfjhgldhfgkjlhksdhgkjdshfhgkjashgfshah\ndkjsafhdlgfkjhdsgklhfjaghlfkdfjghfjhgldhfgkjlhksdhgkjdshfhgkjashgfsha\n", "output": "No\n"}, {"input": "abc\ned\n", "output": "No\n"}]
355
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named Β«PawnChessΒ». This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed. $8$ Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (r, c) the cell located at the row r and at the column c. There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner. Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players. Moving upward means that the pawn located in (r, c) will go to the cell (r - 1, c), while moving down means the pawn located in (r, c) will go to the cell (r + 1, c). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color. Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available. -----Input----- The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'. It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row. -----Output----- Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board. -----Examples----- Input ........ ........ .B....B. ....W... ........ ..W..... ........ ........ Output A Input ..B..... ..W..... ......B. ........ .....W.. ......B. ........ ........ Output B -----Note----- In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner.
interview
[{"code": "grid = [list(input()) for i in range(8)]\nb = 9\nw = 9\ntblock = False\nbblock = False\nfor r in range(8):\n for c in range(8):\n for ri in range(r):\n if grid[ri][c] == 'B':\n tblock = True\n for ri in range(r+1, 8):\n if grid[ri][c] == 'W':\n bblock = True\n if grid[r][c] == 'B' and not bblock:\n b = min([abs(7-r), b])\n elif grid[r][c] == 'W' and not tblock:\n w = min([w, r])\n tblock = False\n bblock = False\nif b < w:\n print('B')\nelse:\n print('A')\n \n", "passed": true, "time": 0.16, "memory": 14368.0, "status": "done"}, {"code": "z = []\nfor i in range(8):\n z.append(input())\na,b = 9,9\nfor i in range(8):\n for j in range(8):\n if z[i][j] == 'W':\n sedi = True\n for r in range(0, i):\n if z[r][j] == 'B':\n sedi = False\n break\n if sedi:\n a = min(a, i)\n elif z[i][j] == 'B':\n sedi = True\n for r in range(i+1, 8):\n if z[r][j] == 'W':\n sedi = False\n break\n if sedi:\n b = min(b, 7-i)\nprint('A' if a<=b else 'B')\n", "passed": true, "time": 0.27, "memory": 14492.0, "status": "done"}, {"code": "our = [input() for i in range(8)]\nresA = 100\nresB = 100\nfor i in range(8):\n for j in range(8):\n if our[i][j] == 'W':\n curr = i\n while curr > 0 and our[curr - 1][j] == '.':\n curr -= 1\n if curr == 0:\n resA= min(resA, i)\n elif our[i][j] == 'B':\n curr = i\n while curr < 7 and our[curr + 1][j] == '.':\n curr += 1\n if curr == 7:\n resB = min(resB, curr - i)\nif resA <= resB:\n print('A')\nelse:\n print('B')", "passed": true, "time": 0.23, "memory": 14500.0, "status": "done"}, {"code": "s = [input().strip() for i in range(8)]\n\nd1 = []\nd2 = []\n\ndef check(x, y):\n if s[x][y] == 'B':\n for i in range(x + 1, 8):\n if s[i][y] == 'W':\n return False\n elif s[x][y] == 'W':\n for i in range(x - 1, -1, -1):\n if s[i][y] == 'B':\n return False\n return True\n\nfor i in range(8):\n for j in range(8):\n if s[i][j] == 'B' and check(i, j):\n d1.append(8 - i - 1)\n elif s[i][j] == 'W' and check(i, j):\n d2.append(i)\n\n\nif min(d1) < min(d2):\n print(\"B\")\nelse:\n print(\"A\")\n", "passed": true, "time": 0.15, "memory": 14456.0, "status": "done"}, {"code": "N = 8\na = [list(input()) for i in range(N)]\namin = N\nbmin = N\nfor c in range(8):\n r = 0\n while r < N and a[r][c] == '.':\n r += 1\n if r < N and a[r][c] == 'W':\n amin = min(amin, r)\n r = N - 1\n while r >= 0 and a[r][c] == '.':\n r -= 1\n if r >= 0 and a[r][c] == 'B':\n bmin = min(bmin, N - 1 - r)\nif amin <= bmin:\n print('A')\nelse:\n print('B')\n", "passed": true, "time": 0.15, "memory": 14548.0, "status": "done"}, {"code": "p = []\nfor i in range(8):\n p.append(list(input()))\nminb = 999999999\nminch = 999999999\nfor i in range(8):\n for t in range(8):\n if p[i][t] == 'W':\n s = 0\n for e in range(i - 1, -1, -1):\n if p[e][t] != '.':\n s = 999999\n else:\n s += 1\n minb = min(minb, s)\n elif p[i][t] == 'B':\n s = 0\n for e in range(i + 1, 8):\n if p[e][t] != '.':\n s = 999999\n else:\n s += 1\n minch = min(minch, s)\nif minb <= minch:\n print('A')\nelse:\n print('B')\n", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "field = [list(input()) for i in range(8)]\nfor y in range(8):\n for x in range(y + 1, 8):\n field[x][y], field[y][x] = field[y][x], field[x][y]\n\nminW = 1000\nminB = 1000\nfor row in range(8):\n w = None\n for col in range(7, -1, -1):\n if field[row][col] == \"W\":\n w = col\n if w != None and (\"B\" not in field[row][:w]):\n minW = min(minW, w)\n \n b = None\n for col in range(8):\n if field[row][col] == \"B\":\n b = col\n if b != None and (\"W\" not in field[row][b:]):\n minB = min(minB, 7 - b)\nif minB < minW:\n print(\"B\")\nelse:\n print(\"A\")", "passed": true, "time": 0.53, "memory": 14476.0, "status": "done"}, {"code": "import sys\n\n\n#sys.stdin = open(\"input.txt\")\n#sys.stdout = open(\"output.txt\", \"w\")\n\ntbl = []\nfor i in range(8):\n\ttbl.append(input())\n\nbestW = 10\nbestB = 10\n#print(tbl)\n\nfor i in range(8):\n\tfor j in range(8):\n\t\t#print(i, j)\n\t\tif tbl[i][j] == 'W':\n\t\t\tok = True\n\t\t\tfor k in range(i):\n\t\t\t\tif tbl[k][j] != '.':\n\t\t\t\t\tok = False\n\t\t\tif ok:\n\t\t\t\tbestW = min(bestW, i)\n\t\telif tbl[i][j] == 'B':\n\t\t\tok = True\n\t\t\tfor k in range(8-i-1):\n\t\t\t\tif tbl[i + k + 1][j] != '.':\n\t\t\t\t\tok = False\n\t\t\tif ok:\n\t\t\t\tbestB = min(bestB, 8 - i - 1)\n\n#print(bestW, bestB)\nif bestW <= bestB:\n\tprint('A')\nelse:\n\tprint('B')", "passed": true, "time": 0.14, "memory": 14276.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\nfrom sys import stdin\n\nlinecount = 8\nfield = []\n\n\ndef move_count(row, column, direction):\n if direction == 1:\n last = linecount\n else:\n last = -1\n\n count = 0\n\n for i in range(row + direction, last, direction):\n if field[i][c] != '.':\n return linecount\n else:\n count += 1\n\n return count\n\n\n\nfor i in range(0, linecount):\n field.append(list(stdin.readline().strip()))\n\na_moves = linecount\nb_moves = linecount\n\nfor r in range(0, linecount):\n for c in range(0, linecount):\n if field[r][c] == 'W':\n count = move_count(r, c, -1)\n\n if count < a_moves:\n a_moves = count\n elif field[r][c] == 'B':\n count = move_count(r, c, 1)\n\n if count < b_moves:\n b_moves = count\n\nif a_moves <= b_moves:\n print('A')\nelse:\n print('B')\n", "passed": true, "time": 0.24, "memory": 14444.0, "status": "done"}, {"code": "A = [input() for i in range(8)]\nB = 9\nW = 9\nfor i in range(8):\n for j in range(8):\n if A[j][i] == \"W\":\n W = min(W, j)\n break\n if A[j][i] == \"B\":\n break\n for j in range(7, -1, -1):\n if A[j][i] == \"B\":\n B = min(B, 8 - j)\n break\n if A[j][i] ==\"W\":\n break\nif B <= W:\n print(\"B\")\nelse:\n print(\"A\")\n", "passed": true, "time": 0.23, "memory": 14512.0, "status": "done"}, {"code": "def checkA(i, j):\n for k in range(i):\n if arr[k][j] != '.':\n return 1000\n return i\n\ndef checkB(i, j):\n for k in range(i + 1, 8):\n if arr[k][j] != '.':\n return 1000\n return 7 - i\n\n#fin = open('a.in', 'r')\narr = []\nfor i in range(8):\n #a = fin.readline().strip()\n a = input()\n arr.append(a)\nminA = 1000\nminB = 1000\nfor i in range(8):\n for j in range(8):\n if arr[i][j] == 'W':\n minA = min(minA, checkA(i, j))\n if arr[i][j] == 'B':\n minB = min(minB, checkB(i, j))\nif minA <= minB:\n print('A')\nelse:\n print('B')\n", "passed": true, "time": 0.14, "memory": 14520.0, "status": "done"}, {"code": "white, black = [set() for _ in range(8)], [set() for _ in range(8)]\nfor row in range(8):\n for col, c in enumerate(input().strip()):\n if c == 'W':\n white[col].add(row)\n elif c == 'B':\n black[col].add(row)\n\nmin_w, max_b = 7, 0\nfor col in range(8):\n for w in white[col]:\n if all(b > w for b in black[col]) and w < min_w:\n min_w = w\n for b in black[col]:\n if all(b > w for w in white[col]) and b > max_b:\n max_b = b\n#print(min_w, max_b)\n\nif min_w <= 7 - max_b:\n print('A')\nelse:\n print('B')", "passed": true, "time": 0.2, "memory": 14528.0, "status": "done"}, {"code": "import sys\n\n#sys.stdin = open('input.txt')\n\ntop = [-1] * 8\ntop_let = [''] * 8\ndown = [-1] * 8\ndown_let = [''] * 8\n\nfor i in range(8):\n s = input().strip()\n j = 0\n while j < 8:\n if s[j] == 'W' or s[j] == 'B':\n if top[j] == -1:\n top[j] = i\n top_let[j] = s[j]\n\n down[j] = i\n down_let[j] = s[j]\n\n j += 1\n\nmin_w = 10\nmax_b = -1\nfor i in range(8):\n if top_let[i] == 'W' and min_w > top[i]:\n min_w = top[i]\n\n if down_let[i] == 'B' and max_b < down[i]:\n max_b = down[i]\n\nif min_w > 8 - max_b - 1:\n print('B')\nelse:\n print('A')", "passed": true, "time": 0.53, "memory": 14328.0, "status": "done"}, {"code": "field = [input() for i in range(8)]\nfield = [[field[y][x] for y in range(8)] for x in range(8)]\n\nwa = float('+inf')\nwb = float('+inf')\n\n\nfor row in field:\n row = ''.join(row)\n if 'W' in row:\n if ('B' in row) and row.index('W') > row.index('B'):\n pass\n else:\n nwa = row.index('W')\n wa = min(wa, nwa)\n if 'B' in row:\n if ('W' in row) and row.rindex('W') > row.rindex('B'):\n pass\n else:\n nwb = 7 - row.rindex('B')\n wb = min(wb, nwb)\n\n\nif wa <= wb:\n print('A')\nelse:\n print('B')\n", "passed": true, "time": 0.24, "memory": 14328.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sat Oct 31 15:01:05 2015\n\n@author: gmarti\n\"\"\"\n\nimport sys\nfrom sys import stdin, stdout\n\n\nchess = []\nfor i in range(8):\n chess.append([x for x in stdin.readline().rstrip().split()])\n\n\nwhite_dist = []\nblack_dist = []\n\nfor i in range(8):\n for j in range(8):\n if chess[i][0][j] == \"W\":\n #check if black above\n is_black_above = False\n for k in range(0, i):\n if chess[k][0][j] == \"B\":\n is_black_above = True\n if not is_black_above:\n white_dist.append(i)\n \n if chess[i][0][j] == \"B\":\n #check if white below\n is_white_below = False\n for k in range(i+1,8):\n if chess[k][0][j] == \"W\":\n is_white_below = True\n if not is_white_below:\n black_dist.append(7-i)\n \n \nif (min(white_dist) <= min(black_dist)):\n stdout.write(\"A\\n\") \nelse:\n stdout.write(\"B\\n\")\n", "passed": true, "time": 0.16, "memory": 14336.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\n#() = (int(i) for i in input().split())\na = [[ 0 for j in range(8) ] for i in range(8) ]\n\nfor i in range(8):\n b = input()\n for j in range(8):\n a[j][i]=b[j]\n\nstart = time.time()\n\nmW = 10\nmB = 10\n\nfor i in range(8):\n flag = True\n for j in range(8):\n if a[i][j] == 'B':\n flag = False\n break\n if a[i][j] == 'W':\n break\n if flag == False:\n continue\n if mW > j:\n mW = j\n\nfor i in range(8):\n flag = True\n for j in range(8):\n if a[i][7-j] == 'W':\n flag = False\n break\n if a[i][7-j] == 'B':\n break\n if flag == False:\n continue\n if mB > j:\n mB = j\n\n\nif mW <= mB:\n print('A')\nelse:\n print('B')\n#print(ans)\nfinish = time.time()\n#print(finish - start)\n", "passed": true, "time": 0.15, "memory": 14628.0, "status": "done"}, {"code": "board = [input(),input(),input(),input(),input(),input(),input(),input()]\nb = -99\nfor i in range(8):\n for j in range(7,-1,-1):\n piece = board[j][i]\n if piece == 'W':\n break\n if piece == 'B':\n b = max(b,j)\n break\nb = 7-b\nw = 99\nfor i in range(8):\n for j in range(8):\n piece = board[j][i]\n if piece == 'B':\n break\n if piece == 'W':\n w = min(w,j)\nif b < w:\n print('B')\nelse:\n print('A')\n", "passed": true, "time": 0.14, "memory": 14384.0, "status": "done"}, {"code": "table = []\nfor _ in range(8):\n table.append(input())\n\nocrA = []\nocrB = []\nA = 8\nB = 8\n\nimport re\nfor i in range(8):\n for j in range(8):\n if table[i][j] == \"W\":\n ocrA.append(j)\n elif table[i][j] == \"B\":\n ocrB.append(j)\n\n #print(ocrA, ocrB)\n\n while ocrA != []:\n asteps = 0\n for j in range(i-1, -1, -1):\n if table[j][ocrA[0]] != \".\":\n asteps = -1\n break\n asteps += 1\n if asteps != -1 and asteps < A:\n A = asteps\n ocrA.pop(0)\n \n while ocrB != []:\n bsteps = 0\n for j in range(i+1, 8):\n if table[j][ocrB[0]] != \".\":\n bsteps = -1\n break\n bsteps += 1\n if bsteps != -1 and bsteps < B:\n B = bsteps\n ocrB.pop(0)\n\nif A <= B:\n print(\"A\")\nelse:\n print(\"B\")", "passed": true, "time": 0.15, "memory": 14316.0, "status": "done"}, {"code": "board = [input() for i in range(8)]\nA = B = 1000\nfor i in range(8):\n for j in range(8):\n if board[j][i] == 'B':\n break\n if board[j][i] == 'W':\n A = min(A, j)\n for j in range(8):\n if board[7 - j][i] == 'W':\n break\n if board[7 - j][i] == 'B':\n B = min(B, j)\n\nif A <= B:\n print('A')\nelse:\n print('B')", "passed": true, "time": 0.18, "memory": 14484.0, "status": "done"}, {"code": "x = []\nfor i in range(8):\n x.append(input())\n# B\nB_mov = 1000\nfor i in range(8):\n for j in range(8):\n if x[i][j] == \"B\":\n count = 0\n for k in range(i + 1, 8):\n if x[k][j] == \".\":\n count += 1\n else:\n break\n else:\n if count < B_mov:\n B_mov = count\n count = 0\n# W\nA_mov = 1000\nfor i in range(8):\n for j in range(8):\n if x[i][j] == \"W\":\n count = 0\n for k in range(i - 1, -1, -1):\n if x[k][j] == \".\":\n count += 1\n else:\n break\n else:\n if count < A_mov:\n A_mov = count\n count = 0\nif A_mov > B_mov:\n print(\"B\")\nelse:\n print(\"A\")\n", "passed": true, "time": 0.14, "memory": 14572.0, "status": "done"}, {"code": "import sys\n\n\ndef main():\n stdin = sys.stdin.read().split('\\n')\n \n A, B = [], []\n for row in range(8):\n for col in range(8):\n if stdin[row][col] == 'W':\n A.append((row, col))\n if stdin[row][col] == 'B':\n B.append((row, col))\n \n Acount = []\n for a in A:\n if all(stdin[i][a[1]] == '.' for i in range(a[0])):\n Acount.append(a[0])\n Bcount = []\n for b in B:\n if all(stdin[i][b[1]] == '.' for i in range(b[0]+1, 8)):\n Bcount.append(7-b[0])\n \n if min(Acount) <= min(Bcount):\n print('A')\n else:\n print('B')\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "arr=[0]*8\nfor i in range(8):\n arr[i]=input()\nwr,wc,br,bc=[[],[],[],[]]\nfor i in range(8):\n for j in range(8):\n if arr[i][j]=='B':\n bc.append(j)\n br.append(i)\n if arr[i][j]=='W':\n wc.append(j)\n wr.append(i)\nbl=len(bc)\nwl=len(wc)\nwf=8\nbf=8\nfor i in range(bl-1,-1,-1):\n c=bc[i]\n temp=0\n for j in range(7,-1,-1):\n if arr[j][c]=='W':\n temp=j\n break\n if temp>br[i]:\n continue\n bf=7-br[i]\n break\nfor i in range(wl):\n c=wc[i]\n temp=8\n for j in range(8):\n if arr[j][c]=='B':\n temp=j\n break\n if temp<wr[i]:\n continue\n wf=wr[i]\n break\nif bf<wf:\n print('B')\nelse:\n print('A')\n\n\n", "passed": true, "time": 0.14, "memory": 14308.0, "status": "done"}, {"code": "b = [100 for i in range(8)]\nw = [100 for i in range(8)]\nb_temp = 0\nw_temp = 0\nb_min = 0\nw_min = 0\nfield = ['' for i in range (8)]\nfor i in range(8):\n field[i] = input()\nfor i in range(8):\n for j in range(8):\n w_temp +=1\n if field[j][i] == 'B':\n w_temp = 100\n if (field[j][i] == 'W')and(w_temp < 100):\n w[i] = w_temp\n w_temp = 100\n w_temp = 0\nfor i in range(8):\n for j in range(8):\n b_temp += 1\n if field[7-j][i] == 'W':\n b_temp = 100\n if (field[7-j][i] == 'B')and(b_temp < 100):\n b[i] = b_temp\n b_temp = 100\n b_temp = 0 \nb_min = min(b)\nw_min = min(w)\nif b_min < w_min:\n print('B')\nelse:\n print('A')\n\n\n\n\n \n", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}, {"code": "a = []\nfor i in range(8):\n a.append(input())\nwmin = 8\nbmin = -1\nfor i in range(8):\n for j in range(8):\n if (a[j][i] == 'W'):\n wmin = min(wmin, j)\n break\n elif (a[j][i] == 'B'):\n break\nfor i in range(8):\n for j in range(7, 0, -1):\n if (a[j][i] == 'B'):\n bmin = max(bmin, j)\n break\n elif (a[j][i] == 'W'):\n break\nif (7 - bmin < wmin):\n print(\"B\")\nelse:\n print(\"A\")\n", "passed": true, "time": 0.15, "memory": 14320.0, "status": "done"}]
[{"input": "........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n", "output": "A\n"}, {"input": "..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n", "output": "B\n"}, {"input": ".BB.B.B.\nB..B..B.\n.B.BB...\nBB.....B\nBBB....B\nB..BB...\nBB.B...B\n....WWW.\n", "output": "B\n"}, {"input": "..BB....\n........\nWW.W..WW\nW...W...\n.W...W..\n.W..W.WW\nW.....WW\nWW......\n", "output": "A\n"}, {"input": "BB....B.\nB.....B.\n.....B..\n..B...BB\n.W.BWBWB\n....W...\nWW.WWW..\n....W...\n", "output": "B\n"}, {"input": "B.B.BB.B\nW.WWW.WW\n.WWWWW.W\nW.BB.WBW\n.W..BBWB\nBB.WWBBB\n.W.W.WWB\nWWW..WW.\n", "output": "A\n"}, {"input": "BB..BB..\nBW.W.W.B\n..B.....\n.....BB.\n.B..B..B\n........\n...BB.B.\nW.WWWW.W\n", "output": "A\n"}, {"input": "BB......\nW....BBW\n........\n.B.B.BBB\n....BB..\nB....BB.\n...WWWW.\n....WW..\n", "output": "A\n"}, {"input": ".B.B..B.\nB.B....B\n...B.B.B\n..B.W..B\n.BBB.B.B\nB.BB.B.B\nBB..BBBB\nW.W.W.WW\n", "output": "B\n"}, {"input": "..BB....\n.B.B.B.B\n..B.B...\n..B..B.B\nWWWBWWB.\n.BB...B.\n..BBB...\n......W.\n", "output": "B\n"}, {"input": "..BB....\n.WBWBWBB\n.....BBB\n..WW....\n.W.W...W\nWWW...W.\n.W....W.\nW...W.W.\n", "output": "A\n"}, {"input": "B...BB..\nWWBBW.BB\n.W.W....\nWWWW....\nW....W..\nW..WW...\n...W....\nWW.W....\n", "output": "A\n"}, {"input": "B..BB..B\n..B.B...\nBW..BBW.\n...B.BBB\n.B..BB..\n..B.B.BB\n........\n........\n", "output": "A\n"}, {"input": "....BB..\nBB......\n.B.....B\nWW..WWW.\n...BB.B.\nB...BB..\n..W..WWW\n...W...W\n", "output": "B\n"}, {"input": "B...BBBB\n...BBB..\nBBWBWW.W\n.B..BB.B\nW..W..WW\nW.WW....\n........\nWW.....W\n", "output": "A\n"}, {"input": ".BB..B..\n.B.....B\n.B......\n.B...B..\n.......B\n.WWB.WWB\nW.....W.\n...W....\n", "output": "B\n"}, {"input": ".B......\n.B....B.\n...W....\n......W.\nW.WWWW.W\nW.WW....\n..WWW...\n..W...WW\n", "output": "A\n"}, {"input": "B.......\nBBB.....\n.B....B.\n.W.BWB.W\n......B.\nW..WW...\n...W....\nW...W..W\n", "output": "A\n"}, {"input": ".B......\n.B...B.B\n.B..B.BB\nW.......\n..W.....\n..WWW...\n.......W\n........\n", "output": "A\n"}, {"input": ".....B..\n........\n........\n.BB..B..\n..BB....\n........\n....WWW.\n......W.\n", "output": "B\n"}, {"input": "B.B...B.\n...BBBBB\n....B...\n...B...B\nB.B.B..B\n........\n........\nWWW..WW.\n", "output": "B\n"}, {"input": "B.B...B.\n........\n.......B\n.BB....B\n.....W..\n.W.WW.W.\n...W.WW.\nW..WW..W\n", "output": "A\n"}, {"input": "......B.\nB....B..\n...B.BB.\n...B....\n........\n..W....W\nWW......\n.W....W.\n", "output": "B\n"}, {"input": ".BBB....\nB.B.B...\nB.BB.B..\nB.BB.B.B\n........\n........\nW.....W.\n..WW..W.\n", "output": "B\n"}, {"input": "..B..BBB\n........\n........\n........\n...W.W..\n...W..W.\nW.......\n..W...W.\n", "output": "A\n"}, {"input": "........\n.B.B....\n...B..BB\n........\n........\nW...W...\nW...W...\nW.WW.W..\n", "output": "A\n"}, {"input": "...B..BB\n.B..B..B\n........\n........\n........\nW..W....\n.....WW.\n.W......\n", "output": "A\n"}, {"input": "B....BB.\n...B...B\n.B......\n........\n........\n........\n........\n....W..W\n", "output": "B\n"}, {"input": "...BB.BB\nBB...B..\n........\n........\n........\n........\n..W..W..\n......W.\n", "output": "A\n"}, {"input": "...BB...\n........\n........\n........\n........\n........\n......W.\nWW...WW.\n", "output": "A\n"}, {"input": "...B.B..\n........\n........\n........\n........\n........\n........\nWWW...WW\n", "output": "A\n"}, {"input": "BBBBBBB.\n........\n........\n........\n........\n........\n........\n.WWWWWWW\n", "output": "A\n"}, {"input": ".BBBBBB.\nB.......\n........\n........\n........\n........\n........\n.WWWWWWW\n", "output": "B\n"}, {"input": ".BBBBBBB\n........\n........\n........\n........\n........\n........\nWWWWWWW.\n", "output": "A\n"}, {"input": ".BBBBBB.\n.......B\n........\n........\n........\n........\n........\nWWWWWWW.\n", "output": "B\n"}, {"input": "B..BB...\n..B...B.\n.WBB...B\nBW......\nW.B...W.\n..BBW.B.\nBW..BB..\n......W.\n", "output": "B\n"}, {"input": "BBB.BBBB\nWB.W..B.\nBBBB...B\nB..B....\n.......W\n.BWB..BB\nB..BW.BW\n.W......\n", "output": "A\n"}, {"input": "B.BBBBBB\nB..BBB.B\nW.BB.W.B\nB.BWBB.B\nBWBWBBBB\n...BBBBB\nB.B...BB\nWW..WW.W\n", "output": "B\n"}, {"input": "BBBB.BBB\nBBBB.B.B\nB.B..BBB\nB.BB.BWW\nB.BB.BBB\nB.BB.BBB\n..BW.BB.\nW.WWWWWW\n", "output": "B\n"}, {"input": "BBBB.BBB\n.B....WB\nBB.B...B\nWWWW.WWB\nBB...BWW\nWWW..BBB\nW.BW.BB.\nWWWWWWW.\n", "output": "B\n"}, {"input": "B.BBBBBB\nW.WWBBBW\nW.BB.WBB\nW.W.BBBW\nW.BWW.WB\nB..B..BB\nB.B.W.BB\nWWWWW.WW\n", "output": "B\n"}, {"input": "BBBBBB.B\n.BBWBB.B\nWWW..B.W\n..WW.W.W\nBWB..W.W\n..BW.B.W\nB..B....\nWWWW.WWW\n", "output": "B\n"}, {"input": ".B...BB.\nWBB.BWBB\n.BWBW...\n..W...B.\nWB.BWW..\nWBW.....\n.W..W.B.\n.W.W.WW.\n", "output": "A\n"}, {"input": ".B..BBBB\nBB...WWB\nB..B.W.B\nWB.W...B\n...W.WW.\nW.....W.\nWB.W.W.W\n.WW...WW\n", "output": "A\n"}, {"input": "B.BBBBBB\nW.BB.W.B\nW.BBW...\n..WWWW.B\n....W..B\n.WW.W..W\n.W..WW.W\nW.W....W\n", "output": "A\n"}, {"input": "........\n.......W\n........\n........\n........\n........\n.......B\n........\n", "output": "A\n"}, {"input": "..B.....\n..W.....\n.W....B.\n........\n.B...W..\n......B.\n.W......\n........\n", "output": "A\n"}, {"input": "........\nB.......\n........\n........\n........\n........\n.......W\n........\n", "output": "A\n"}, {"input": "........\n........\n........\n.W......\n......B.\n........\n........\n........\n", "output": "A\n"}, {"input": "........\nB.......\nW.......\n.......B\n........\n........\n........\n...W....\n", "output": "B\n"}, {"input": "........\n.B......\n.W......\n........\n....B...\n........\n........\n.......W\n", "output": "B\n"}, {"input": "........\n..B.....\n..W...B.\n........\n.....W..\n......B.\n........\n........\n", "output": "B\n"}, {"input": "........\nW.......\n........\n........\n........\n........\n.......B\n........\n", "output": "A\n"}, {"input": "........\n........\n........\n........\nW.......\nB.......\n........\n........\n", "output": "B\n"}, {"input": "........\n........\n.W......\n........\n........\n........\n.B......\n........\n", "output": "B\n"}, {"input": "........\nB.......\nW.......\n.W......\n........\nB.......\n........\n........\n", "output": "B\n"}]
356
Vasya has two arrays $A$ and $B$ of lengths $n$ and $m$, respectively. He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the array $[1, 10, 100, 1000, 10000]$ Vasya can obtain array $[1, 1110, 10000]$, and from array $[1, 2, 3]$ Vasya can obtain array $[6]$. Two arrays $A$ and $B$ are considered equal if and only if they have the same length and for each valid $i$ $A_i = B_i$. Vasya wants to perform some of these operations on array $A$, some on array $B$, in such a way that arrays $A$ and $B$ become equal. Moreover, the lengths of the resulting arrays should be maximal possible. Help Vasya to determine the maximum length of the arrays that he can achieve or output that it is impossible to make arrays $A$ and $B$ equal. -----Input----- The first line contains a single integer $n~(1 \le n \le 3 \cdot 10^5)$ β€” the length of the first array. The second line contains $n$ integers $a_1, a_2, \cdots, a_n~(1 \le a_i \le 10^9)$ β€” elements of the array $A$. The third line contains a single integer $m~(1 \le m \le 3 \cdot 10^5)$ β€” the length of the second array. The fourth line contains $m$ integers $b_1, b_2, \cdots, b_m~(1 \le b_i \le 10^9)$ - elements of the array $B$. -----Output----- Print a single integer β€” the maximum length of the resulting arrays after some operations were performed on arrays $A$ and $B$ in such a way that they became equal. If there is no way to make array equal, print "-1". -----Examples----- Input 5 11 2 3 5 7 4 11 7 3 7 Output 3 Input 2 1 2 1 100 Output -1 Input 3 1 2 3 3 1 2 3 Output 3
interview
[{"code": "n = int(input())\na = list(map(int, input().split()))\n\nm = int(input())\nb = list(map(int, input().split()))\n\nptra = 1\nptrb = 1\nsa = a[0] \nsb = b[0]\nans = 0\n\nwhile ptra != n and ptrb != m:\n if sa == sb:\n ans += 1\n sa = a[ptra]\n sb = b[ptrb]\n ptra += 1\n ptrb += 1\n continue\n if sa < sb:\n sa += a[ptra]\n ptra += 1\n else:\n sb += b[ptrb]\n ptrb += 1\nwhile ptra != n:\n sa += a[ptra]\n ptra += 1\nwhile ptrb != m:\n sb += b[ptrb]\n ptrb += 1\nif sa != sb:\n print(-1)\n return\nprint(ans + 1)\n\n", "passed": true, "time": 0.14, "memory": 14424.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 dprint('debug mode')\nexcept ModuleNotFoundError:\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, = getIntList()\nza = getIntList()\n\nM, = getIntList()\nzb = getIntList()\n\nif sum(za) != sum(zb):\n print(-1)\n return\n\nia = 0\nib = 0\nta = 0\ntb = 0\nr = N\nwhile ia<N or ib <M:\n if ta== tb:\n if ia==N: break\n ta = za[ia]\n tb = zb[ib]\n ia +=1\n ib +=1\n \n elif ta< tb:\n ta += za[ia]\n ia+=1\n r-=1\n else:\n tb+=zb[ib]\n ib+=1\n \nprint(r) \n \n\n\n\n\n", "passed": true, "time": 0.26, "memory": 14492.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nm = int(input())\nb = list(map(int, input().split()))\nif sum(a) != sum(b):\n print(-1)\n return\ni = 0\nj = 0\nwhile i < n and j < m:\n while a[i] != b[j] and i < n and j < m:\n if i < n - 1 and a[i] < b[j]:\n a[i + 1] += a[i]\n a[i] = -1\n i += 1\n elif j < m - 1:\n b[j + 1] += b[j]\n b[j] = -1\n j += 1\n if a[i] == b[j]:\n i += 1\n j += 1\n else:\n print(-1)\n return\nans = 0\nfor i in a:\n if i != -1:\n ans += 1\nprint(ans)\n\n \n", "passed": true, "time": 0.14, "memory": 14540.0, "status": "done"}, {"code": "import sys\n\nn=int(input())\nA=list(map(int,input().split()))\nm=int(input())\nB=list(map(int,input().split()))\n\ni=0\nj=0\nx=A[0]\ny=B[0]\nACHECK=0\n\nwhile True:\n if x==y:\n i+=1\n j+=1\n if i==n and j==m:\n print(n-ACHECK)\n return\n\n elif i==n and j<m:\n print(-1)\n return\n\n elif i<n and j==m:\n print(-1)\n return\n \n x=A[i]\n y=B[j]\n\n elif x>y:\n j+=1\n\n if j==m:\n print(-1)\n return\n y+=B[j]\n\n elif x<y:\n i+=1\n\n if i==n:\n print(-1)\n return\n x+=A[i]\n ACHECK+=1\n \n\n\n", "passed": true, "time": 0.19, "memory": 14560.0, "status": "done"}, {"code": "from collections import deque\nfrom sys import stdin\nlines = deque(line.strip() for line in stdin.readlines())\n\ndef nextline():\n return lines.popleft()\n\ndef types(cast, sep=None):\n return tuple(cast(x) for x in strs(sep=sep))\n\ndef ints(sep=None):\n return types(int, sep=sep)\n\ndef strs(sep=None):\n return tuple(nextline()) if sep == '' else tuple(nextline().split(sep=sep))\n\ndef main():\n # lines will now contain all of the input's lines in a list\n n = int(nextline())\n a = ints()\n m = int(nextline())\n b = ints()\n count = 1\n i, j = 0, 0\n a_sum, b_sum = 0, 0\n a_total, b_total = 0, 0\n while i < n and j < m:\n if a_sum < b_sum:\n a_total += a[i]\n a_sum += a[i]\n i += 1\n else:\n b_total += b[j]\n b_sum += b[j]\n j += 1\n if a_sum == b_sum:\n count += 1\n a_sum, b_sum = 0, 0\n while i < n and a_total < b_total:\n a_total += a[i]\n i += 1\n while j < m and b_total < a_total:\n b_total += b[j]\n j += 1\n if i == n and j == m and a_total == b_total:\n return count\n return -1\n\ndef __starting_point():\n print(main())\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14616.0, "status": "done"}, {"code": "def __starting_point():\n n1 = int(input().strip())\n a1 = [int(__) for __ in input().strip().split()]\n n2 = int(input().strip())\n a2 = [int(__) for __ in input().strip().split()]\n s1, s2 = sum(a1), sum(a2)\n if a1 == a2:\n print(n1)\n elif sum(a1) != sum(a2):\n print(-1)\n else:\n s1, s2 = 0, 0\n e1, e2 = n1 - 1, n2 - 1\n ans = 0\n while a1[s1] == a2[s2]:\n s1 += 1\n s2 += 1\n ans += 1\n while a1[e1] == a2[e2]:\n e1 -= 1\n e2 -= 1\n ans += 1\n p1 = [a1[s1]]\n p2 = [a2[s2]]\n for i in range(s1 + 1, e1 + 1):\n p1.append(p1[-1] + a1[i])\n for i in range(s2 + 1, e2 + 1):\n p2.append(p2[-1] + a2[i])\n d = {}\n for x in p1:\n d[x] = 1\n for x in p2:\n if x in d:\n ans += 1\n print(ans)\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14360.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nm = int(input())\nb = list(map(int, input().split()))\nif (sum(a) != sum(b)):\n print(-1)\nelse:\n i = 0\n j = 0\n suma = 0\n sumb = 0\n ans = 0\n while (i < n or j < m):\n if (suma == sumb and suma != 0):\n suma = 0\n sumb = 0\n ans += 1\n if (i == n and j == m):\n break\n elif (suma == sumb):\n suma += a[i]\n i += 1\n sumb += b[j]\n j += 1\n if (i == n and j == m):\n break \n elif (suma < sumb):\n suma += a[i]\n i += 1\n elif (suma > sumb):\n sumb += b[j]\n j += 1\n if (suma == sumb and suma != 0):\n ans += 1\n print(ans)", "passed": true, "time": 0.16, "memory": 14512.0, "status": "done"}, {"code": "n=int(input())\nalist=list(map(int,input().split()))\nm=int(input())\nblist=list(map(int,input().split()))\n\nprea = [alist[0]]\nfor i in range(1,n):\n\tprea.append(prea[-1]+alist[i])\n\npreb = [blist[0]]\nfor i in range(1,m):\n\tpreb.append(preb[-1]+blist[i])\n#print(prea,preb)\nif prea[-1]!=preb[-1]:\n\tprint(-1)\n\nelse:\n\tx=0\n\ty=0\n\tcount=0\n\twhile x<n and y<m:\n\n\t\tif prea[x]==preb[y]:\n\n\t\t\tcount+=1\n\t\t\tx+=1\n\t\t\ty+=1\n\t\telif prea[x]<preb[y]:\n\t\t\tx+=1\n\t\telse:\n\t\t\ty+=1\n\n\tprint(count)\n\n\n", "passed": true, "time": 0.22, "memory": 14272.0, "status": "done"}, {"code": "n = int(input())\narrA = list(map(int, input().split()))\nm = int(input())\narrB = list(map(int, input().split()))\nresult = 0\ni = 0\nj = 0\nsumA = 0\nsumB = 0\nwhile (i < n and j < m):\n sumA += arrA[i]\n sumB += arrB[j]\n if (sumA == sumB):\n sumA = 0\n sumB = 0\n i += 1\n j += 1\n result += 1\n elif sumA > sumB:\n sumA -= arrA[i]\n j += 1\n else:\n sumB -= arrB[j]\n i += 1\nif (j == m and i == n): \n print(result)\nelse:\n print(\"-1\")\n", "passed": true, "time": 0.24, "memory": 14292.0, "status": "done"}, {"code": "import math\n\nla = int(input())\na = list(map(int, input().split()))\n\nlb = int(input())\nb = list(map(int, input().split()))\n\nxa = 0\nxb = 0\n\nsuma = 0\nsumb = 0\n\nresult = 0\nwhile (xa < la or sumb < suma) and (xb < lb or suma < sumb):\n if suma == sumb:\n suma += a[xa]\n sumb += b[xb]\n xa += 1\n xb += 1\n result += 1\n\n elif suma > sumb:\n sumb += b[xb]\n xb += 1\n\n elif suma < sumb:\n suma += a[xa]\n xa += 1\n\nif xa == la and xb == lb and suma == sumb:\n print(result)\nelse:\n print(-1)\n", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "n = int(input())\narr = [int(i) for i in input().split()]\nm = int(input())\nar = [int(i) for i in input().split()]\na = arr[0]\nb = ar[0]\naa = 1\nbb = 1\nans = 0\nwhile (aa != n and bb != m):\n\tif a == b:\n\t\ta += arr[aa]\n\t\taa += 1\n\t\tans += 1\n\t\tcontinue\n\tif a < b:\n\t\ta += arr[aa]\n\t\taa += 1\n\telse:\n\t\tb += ar[bb]\n\t\tbb += 1\n\nwhile (aa != n):\n\ta += arr[aa]\n\taa+=1\nwhile (bb != m):\n\tb += ar[bb]\n\tbb += 1\nif a == b:\n\tprint(ans + 1)\nelse:\n\tprint(-1) ", "passed": true, "time": 0.26, "memory": 14584.0, "status": "done"}, {"code": "m=int(input())\na=list(map(int,input().split()))\nn=int(input())\nb=list(map(int,input().split()))\nif(sum(a)!=sum(b)):\n print(-1)\nelse:\n ans=sum1=sum2=0\n i=j=0\n while(i<m and j<n):\n if(sum1<sum2):\n sum1+=a[i]\n i+=1\n elif(sum1>sum2):\n sum2+=b[j]\n j+=1\n else:\n ans+=1\n sum1=a[i]\n sum2=b[j]\n i+=1\n j+=1\n print(ans)", "passed": true, "time": 0.15, "memory": 14428.0, "status": "done"}, {"code": "n = int(input())\nA = list(map(int,input().split()))\nm = int(input())\nB = list(map(int,input().split()))\n\ni =0\nj =0\nans = 0\nsa = 0\nsb = 0\nwhile i < n or j < m:\n if sa < sb:\n if i>= n:\n break\n sa += A[i]\n i += 1\n else:\n if j >= m:\n break\n sb += B[j]\n j += 1\n if sa == sb:\n ans += 1\n sa = 0\n sb = 0\n\nif i == n and j == m and sa == 0 and sb == 0: \n print(ans)\nelse:\n print(-1)\n", "passed": true, "time": 0.15, "memory": 14320.0, "status": "done"}, {"code": "n = int(input())\nline_a = list(map(int, input().split()))\nm = int(input())\nline_b = list(map(int, input().split()))\nif sum(line_a) != sum(line_b):\n print(-1)\nelse:\n sa = 0\n sb = 0\n l = 0\n r = 0\n size = 0\n while l != n and r != m:\n #print(sa, sb)\n if sa + line_a[l] > sb + line_b[r]:\n sb += line_b[r]\n r += 1\n elif sa + line_a[l] < sb + line_b[r]:\n sa += line_a[l]\n l += 1\n elif sa + line_a[l] == sb + line_b[r]:\n size += 1\n l += 1\n r += 1\n sa = 0\n sb = 0\n print(size)", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "'''input\n2\n1 2\n2\n1 2\n'''\n\nimport math\nfrom collections import defaultdict as dd\nimport heapq\n\t\nn = int(input())\na = [int(i) for i in input().split(\" \")]\nm = int(input())\nb = [int(i) for i in input().split(\" \")]\n\nx = [a[0]]\ny = [b[0]]\nif sum(a) != sum(b):\n\tprint(-1)\nelse:\n\tfor i in range(1, n):\n\t\tx.append(x[-1] + a[i])\n\tfor i in range(1, m):\n\t\ty.append(y[-1] + b[i])\n\tx = set(x)\n\ty = set(y)\n\tprint(len(x.intersection(y)))", "passed": true, "time": 0.14, "memory": 14516.0, "status": "done"}, {"code": "\n\nn = int(input())\na = list(map(int,input().split(\" \")))\nm = int(input())\nb = list(map(int,input().split(\" \")))\n\ni,j = 0,0\nres = 0\nx,y = 0,0\nlast_i,last_j = -1,-1\nwhile(i < n and j < m):\n\t# print(i,j,x,y)\n\tif(last_i != i):\n\t\tx += a[i]\n\tif(last_j != j):\n\t\t\ty += b[j]\n\tlast_i,last_j = i,j\n\tif(x == y):\n\t\ti += 1\n\t\tj += 1\n\t\tres += 1\n\t\tx = 0\n\t\ty = 0\n\tif(x<y):\n\t\ti += 1\n\tif(x>y):\n\t\tj += 1\n\nif(i == n and j == m):\n\tprint(res)\nelse:\n\tprint(\"-1\")", "passed": true, "time": 0.14, "memory": 14420.0, "status": "done"}, {"code": "n=int(input())\na=[int(i) for i in input().split(' ')]\n\nm=int(input())\nb=[int(i) for i in input().split(' ')]\n\n\naa=[a[0]]\nbb=[b[0]]\n\nfor i in range(1,n):\n aa.append(aa[-1]+a[i])\n\nfor i in range(1,m):\n bb.append(bb[-1]+b[i])\n\na1=set(aa)\na2=set(bb)\nif sum(a)!=sum(b):\n print(-1)\nelse:\n print(len((a1.intersection(a2))))\n\n \n", "passed": true, "time": 0.15, "memory": 14324.0, "status": "done"}, {"code": "'''input\n3\n1 2 3\n3\n1 2 3\n'''\nimport sys\nfrom collections import defaultdict as dd\nfrom itertools import permutations as pp\nfrom itertools import combinations as cc\nfrom collections import Counter as ccd\nfrom random import randint as rd\nfrom bisect import bisect_left as bl\nmod=10**9+7\n\n\nn=int(input())\na=[int(i) for i in input().split()]\nm=int(input())\nb=[int(i) for i in input().split()]\n\nfor i in range(1,n):\n\ta[i]+=a[i-1]\nfor i in range(1,m):\n\tb[i]+=b[i-1]\n\nif a[-1]!=b[-1]:\n\tprint(-1)\nelse:\n\ta=set(a)\n\tb=set(b)\n\n\tans=len(a.intersection(b))\n\n\tif ans==0 :\n\t\tprint(-1)\n\telse:\n\t\tprint(ans)\n\n", "passed": true, "time": 0.15, "memory": 14284.0, "status": "done"}, {"code": "n = int(input())\na = list(map(int, input().split()))\nm = int(input())\nb = list(map(int, input().split()))\n\nif sum(a) != sum(b):\n print(-1)\nelse:\n L = 0\n while a or b:\n if a[-1] == b[-1]:\n del a[-1]\n del b[-1]\n L += 1\n elif a[-1] < b[-1]:\n a[-2] += a[-1]\n del a[-1]\n else:\n b[-2] += b[-1]\n del b[-1]\n print(L)\n", "passed": true, "time": 0.15, "memory": 14168.0, "status": "done"}, {"code": "def go():\n n = int(input())\n a = [int(i) for i in input().split(' ')]\n m = int(input())\n b = [int(i) for i in input().split(' ')]\n i = 0\n so_far_i = 0\n j = 0\n so_far_j = 0\n while i < n and so_far_i < n and j < m and so_far_j < m:\n if a[i] == b[j]:\n i = so_far_i\n j = so_far_j\n i += 1\n j += 1\n so_far_i = i\n so_far_j = j\n else:\n if a[i] > b[j]:\n if so_far_j + 1 < m:\n b[j] += b[so_far_j + 1]\n so_far_j += 1\n b[so_far_j] = None\n else:\n break\n else:\n if so_far_i + 1 < n:\n a[i] += a[so_far_i + 1]\n so_far_i += 1\n a[so_far_i] = None\n else:\n break\n if sum([i for i in a if i is not None]) != sum([i for i in b if i is not None]):\n return -1\n return len([i for i in a if i is not None])\n\nprint(go())\n", "passed": true, "time": 0.14, "memory": 14412.0, "status": "done"}, {"code": "n1 = int(input())\na1 = list(map(int, input().split()))\nn2 = int(input())\na2 = list(map(int, input().split()))\nif n1 < n2:\n a1, a2 = a2, a1\nif sum(a1) != sum(a2):\n print(-1)\nelse:\n c = 1\n f = 0\n s = 0\n c1 = a1[f]\n c2 = a2[s] \n while s + 1 < len(a2) and f + 1 < len(a1):\n if c1 == c2:\n f += 1\n s += 1 \n c += 1\n c1 = a1[f]\n c2 = a2[s] \n elif c1 > c2:\n s += 1\n c2 += a2[s] \n else:\n f += 1\n c1 += a1[f]\n print(c)", "passed": true, "time": 0.16, "memory": 14476.0, "status": "done"}]
[{"input": "5\n11 2 3 5 7\n4\n11 7 3 7\n", "output": "3\n"}, {"input": "2\n1 2\n1\n100\n", "output": "-1\n"}, {"input": "3\n1 2 3\n3\n1 2 3\n", "output": "3\n"}, {"input": "49\n18 1 7 2 1 1 50 22 8 2 2 1 30 2 46 10 1 4 5 18 25 21 38 11 2 15 29 8 7 2 45 12 14 16 16 23 11 1 1 4 48 18 3 1 1 23 4 10 7\n50\n5 25 34 22 19 4 4 2 40 52 1 4 1 3 47 9 4 1 8 47 4 5 1 1 9 22 9 2 2 1 1 48 7 2 8 16 4 2 41 12 3 30 21 10 2 2 5 1 31 13\n", "output": "14\n"}, {"input": "42\n16 6 12 20 1 1 16 48 4 2 88 1 1 10 46 21 2 37 7 15 27 17 9 28 7 12 1 1 1 3 1 1 2 2 2 1 58 16 2 6 3 14\n46\n9 11 35 46 3 15 5 1 1 79 2 2 4 2 1 43 6 2 2 1 2 50 9 2 5 1 47 5 7 13 9 30 4 2 3 2 1 1 6 35 29 5 6 1 19 4\n", "output": "15\n"}, {"input": "49\n63 13 6 1 50 37 1 1 1 6 34 9 4 2 1 2 3 46 11 1 2 3 4 1 6 74 7 3 1 1 31 18 20 15 1 74 6 2 1 1 6 46 13 29 2 20 44 1 1\n45\n54 19 5 1 1 3 81 1 4 3 1 5 1 28 18 3 5 1 23 33 9 3 31 47 5 7 2 76 1 4 1 2 1 48 4 31 1 74 12 2 3 4 1 32 34\n", "output": "15\n"}, {"input": "44\n1 2 36 1 3 6 8 5 4 2 46 1 2 16 3 3 32 30 2 15 1 26 46 2 1 3 1 3 3 2 1 64 11 2 5 1 3 20 6 2 2 5 3 1\n50\n2 1 38 3 9 14 1 26 8 12 2 1 17 4 1 29 41 2 8 18 18 28 13 1 1 1 4 1 1 2 4 32 27 2 15 3 3 11 10 3 5 1 1 1 2 1 1 1 1 1\n", "output": "16\n"}, {"input": "1\n1\n1\n2\n", "output": "-1\n"}, {"input": "1\n100\n1\n100\n", "output": "1\n"}, {"input": "1\n5\n2\n3 2\n", "output": "1\n"}, {"input": "2\n1 1\n1\n1\n", "output": "-1\n"}, {"input": "3\n1 2 3\n4\n1 2 3 4\n", "output": "-1\n"}, {"input": "10\n1000000000 999999999 999999998 999999997 999999996 999999995 999999994 999999993 999999992 999999991\n10\n999999991 999999992 999999993 999999994 999999995 999999996 999999997 999999998 999999999 1000000000\n", "output": "1\n"}, {"input": "4\n1000000000 1000000000 147483648 5\n4\n999999999 999999999 147483650 5\n", "output": "2\n"}, {"input": "6\n999999992 2 999999995 999999996 15 11\n7\n999999993 999999994 999999999 5 5 4 11\n", "output": "2\n"}, {"input": "1\n5\n2\n5 5\n", "output": "-1\n"}, {"input": "5\n1 1 1 1 1\n1\n4\n", "output": "-1\n"}, {"input": "4\n2 2 6 3\n4\n2 2 3 3\n", "output": "-1\n"}, {"input": "5\n999999999 999999998 999999997 999999996 999999995\n5\n999999995 999999996 999999997 999999998 999999999\n", "output": "1\n"}, {"input": "9\n1000000000 1000000000 147483648 1000000000 1000000000 147483648 147483648 1000000000 1000000000\n9\n147483648 147483648 147483648 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "output": "3\n"}, {"input": "6\n499999999 500000000 500000000 500000000 500000001 500000000\n6\n500000001 500000000 500000000 500000000 499999999 500000000\n", "output": "2\n"}, {"input": "3\n999999998 999999999 1000000000\n3\n1000000000 999999999 999999998\n", "output": "1\n"}, {"input": "1\n1000000000\n3\n1 1000000000 1\n", "output": "-1\n"}, {"input": "6\n999999999 1000000000 1000000000 1000000000 1000000000 1000000000\n7\n999999998 1000000000 1000000000 1000000000 1000000000 1000000000 1\n", "output": "1\n"}, {"input": "4\n2 2 3 3\n4\n2 2 6 3\n", "output": "-1\n"}, {"input": "2\n1 2\n4\n1 1 1 2\n", "output": "-1\n"}, {"input": "3\n1000000000 1000000000 999999999\n3\n999999999 1000000000 1000000000\n", "output": "1\n"}, {"input": "1\n2\n2\n2 3\n", "output": "-1\n"}, {"input": "1\n41\n2\n41 4071505\n", "output": "-1\n"}, {"input": "5\n1 2 4 1 5\n3\n3 3 1\n", "output": "-1\n"}, {"input": "2\n1 10\n3\n11 1 1\n", "output": "-1\n"}, {"input": "2\n10 1\n3\n11 1 1\n", "output": "-1\n"}, {"input": "4\n1 1 1 1\n1\n2\n", "output": "-1\n"}, {"input": "1\n536870912\n5\n536870912 536870912 536870912 536870912 536870912\n", "output": "-1\n"}, {"input": "3\n1 2 1\n3\n2 2 1\n", "output": "-1\n"}, {"input": "3\n3 3 3\n4\n3 3 3 3\n", "output": "-1\n"}, {"input": "5\n499999999 1000000000 500000000 500000001 500000000\n5\n500000001 1000000000 500000000 499999999 500000000\n", "output": "2\n"}, {"input": "7\n1 1 1000000000 1000000000 1000000000 1000000000 294967296\n7\n1000000000 1000000000 1000000000 1000000000 294967296 1 1\n", "output": "1\n"}, {"input": "7\n1000000000 1000000000 1000000000 1000000000 294967296 1 1\n7\n1 1 1000000000 1000000000 1000000000 1000000000 294967296\n", "output": "1\n"}, {"input": "2\n1 1\n3\n1 1 1\n", "output": "-1\n"}, {"input": "4\n3 1 1 1\n4\n1 2 1 1\n", "output": "-1\n"}, {"input": "2\n1 2\n2\n2 1\n", "output": "1\n"}, {"input": "2\n1 1\n2\n1 2\n", "output": "-1\n"}, {"input": "2\n1 4\n2\n2 2\n", "output": "-1\n"}, {"input": "3\n1 1 1\n2\n1 1\n", "output": "-1\n"}, {"input": "5\n1 2 3 4 5\n6\n1 2 3 4 5 6\n", "output": "-1\n"}, {"input": "2\n2 1\n3\n1 1 1\n", "output": "2\n"}, {"input": "2\n1 3\n3\n1 2 5\n", "output": "-1\n"}, {"input": "5\n1 1 1 1 1\n2\n1 1\n", "output": "-1\n"}, {"input": "1\n3\n2\n3 1\n", "output": "-1\n"}, {"input": "3\n2 3 4\n3\n2 3 5\n", "output": "-1\n"}, {"input": "1\n11\n2\n11 11\n", "output": "-1\n"}, {"input": "2\n2 3\n1\n2\n", "output": "-1\n"}, {"input": "1\n2\n6\n3 1000000000 1000000000 1000000000 1000000000 294967294\n", "output": "-1\n"}, {"input": "3\n1 2 1\n3\n2 2 3\n", "output": "-1\n"}, {"input": "3\n1000000 1 1\n2\n1 1\n", "output": "-1\n"}]
358
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors. Consider positive integers a, a + 1, ..., b (a ≀ b). You want to find the minimum integer l (1 ≀ l ≀ b - a + 1) such that for any integer x (a ≀ x ≀ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers. Find and print the required minimum l. If no value l meets the described limitations, print -1. -----Input----- A single line contains three space-separated integers a, b, k (1 ≀ a, b, k ≀ 10^6;Β a ≀ b). -----Output----- In a single line print a single integer β€” the required minimum l. If there's no solution, print -1. -----Examples----- Input 2 4 2 Output 3 Input 6 13 1 Output 4 Input 1 4 3 Output -1
interview
[{"code": "def f(n):\n m = int(n ** 0.5) + 1\n t = [1] * (n + 1)\n for i in range(3, m):\n if t[i]: t[i * i :: 2 * i] = [0] * ((n - i * i) // (2 * i) + 1)\n return [2] + [i for i in range(3, n + 1, 2) if t[i]]\n\na, b, k = map(int, input().split())\nn = 2000001\n\nt, p, x = [-1] * n, f(n), -1\nk -= 1; b += 1\n\nfor i in range(len(p) - k):\n t[p[i]] = p[i + k] - p[i]\n\nt.reverse()\nfor i in range(1, n):\n if t[i] < 0: t[i] = t[i - 1] + 1\nt.reverse()\n\nfor i in range(a + 1, b):\n t[i] = max(t[i], t[i - 1])\n\nfor l in range(1, b - a + 1):\n if t[b - l] < l:\n x = l\n break\nprint(x)", "passed": true, "time": 21.25, "memory": 117928.0, "status": "done"}, {"code": "def f(n):\n m, l = int(n ** 0.5) + 1, n - 1\n t = [1] * n\n for i in range(3, m):\n if t[i]: t[i * i :: 2 * i] = [0] * ((l - i * i) // (2 * i) + 1)\n return [2] + [i for i in range(3, n, 2) if t[i]]\n\na, b, k = map(int, input().split())\nk -= 1; b += 1; n = b + 100\n\nt, p, x = [-1] * n, f(n), -1\n\nfor i in range(len(p) - k):\n t[p[i]] = p[i + k] - p[i]\n\nt.reverse()\nfor i in range(1, n):\n if t[i] < 0: t[i] = t[i - 1] + 1\nt.reverse()\n\nif len(p) > k: \n for i in range(a + 1, b):\n t[i] = max(t[i], t[i - 1])\n\n for l in range(1, b - a + 1):\n if t[b - l] < l:\n x = l\n break\nprint(x)", "passed": true, "time": 7.97, "memory": 66012.0, "status": "done"}, {"code": "def f(a, b):\n t = [1] * (b + 1)\n for i in range(3, int(b ** 0.5) + 1):\n if t[i]: t[i * i :: 2 * i] = [0] * ((b - i * i) // (2 * i) + 1)\n return [i for i in range(3, b + 1, 2) if t[i] and i > a]\n\na, b, k = map(int, input().split())\n\np = f(a - 1, b)\nif 3 > a and b > 1: p = [2] + p\n \nif k > len(p): print(-1)\nelif len(p) == k: print(max(p[k - 1] - a + 1, b - p[0] + 1))\nelse: print(max(p[k - 1] - a + 1, b - p[len(p) - k] + 1, max(p[i + k] - p[i] for i in range(len(p) - k))))", "passed": true, "time": 1.19, "memory": 26448.0, "status": "done"}, {"code": "def main():\n def f(n):\n m = int(n ** 0.5) + 1\n t = [1] * (n + 1)\n for i in range(3, m):\n if t[i]: t[i * i :: 2 * i] = [0] * ((n - i * i) // (2 * i) + 1)\n return [2] + [i for i in range(3, n + 1, 2) if t[i]]\n\n a, b, k = map(int, input().split())\n n = 1100001\n \n t, p, x = [-1] * n, f(n), -1\n k -= 1; b += 1\n\n for i in range(len(p) - k):\n t[p[i]] = p[i + k] - p[i]\n for i in range(1,n):\n if t[-i] < 0:\n t[-i] = t[-i + 1] + 1\n for i in range(a + 1, b):\n t[i] = max(t[i], t[i - 1])\n for l in range(1, b - a + 1):\n if t[b - l] < l:\n x = l\n break\n print(x)\nmain()", "passed": true, "time": 16.87, "memory": 71124.0, "status": "done"}, {"code": "def f(a, b):\n t = [1] * (b + 1)\n for i in range(3, int(b ** 0.5) + 1):\n if t[i]: t[i * i :: 2 * i] = [0] * ((b - i * i) // (2 * i) + 1)\n return [i for i in range(3, b + 1, 2) if t[i] and i > a]\n\na, b, k = map(int, input().split())\n\np = f(a - 1, b)\nif 3 > a and b > 1: p = [2] + p\n \nif k > len(p): print(-1)\nelif len(p) == k: print(max(p[k - 1] - a + 1, b - p[0] + 1))\nelse: print(max(p[k - 1] - a + 1, b - p[len(p) - k] + 1, max(p[i + k] - p[i] for i in range(len(p) - k))))", "passed": true, "time": 1.16, "memory": 26368.0, "status": "done"}, {"code": "def f(a, b):\n t = [1] * (b + 1)\n for i in range(3, int(b ** 0.5) + 1):\n if t[i]: \n t[i * i :: 2 * i] = [0] * ((b - i * i) // (2 * i) + 1)\n return [i for i in range(3, b + 1, 2) if t[i] and i > a]\n\na, b, k = map(int, input().split())\n\np = f(a - 1, b)\n\nif 3 > a and b > 1: \n p = [2] + p\n \nif k > len(p): print(-1)\n\nelif len(p) == k: \n print(max(p[k - 1] - a + 1, b - p[0] + 1))\n\nelse: \n print(max(p[k - 1] - a + 1, b - p[len(p) - k] + 1, max(p[i + k] - p[i] for i in range(len(p) - k))))", "passed": true, "time": 1.38, "memory": 26428.0, "status": "done"}, {"code": "def f(a, b):\n\n t = [1] * (b + 1)\n\n for i in range(3, int(b ** 0.5) + 1):\n\n if t[i]: t[i * i :: 2 * i] = [0] * ((b - i * i) // (2 * i) + 1)\n\n return [i for i in range(3, b + 1, 2) if t[i] and i > a]\n\n\n\na, b, k = list(map(int, input().split()))\n\n\n\np = f(a - 1, b)\n\nif 3 > a and b > 1: p = [2] + p\n\n \n\nif k > len(p): print(-1)\n\nelif len(p) == k: print(max(p[k - 1] - a + 1, b - p[0] + 1))\n\nelse: print(max(p[k - 1] - a + 1, b - p[len(p) - k] + 1, max(p[i + k] - p[i] for i in range(len(p) - k))))\n\n\n\n# Made By Mostafa_Khaled\n", "passed": true, "time": 1.16, "memory": 26344.0, "status": "done"}, {"code": "p=[1]*(1000005)\np[0]=0\np[1]=0\nfor i in range(2,1001):\n if p[i]:\n for j in range(2*i,1000005,i):\n p[j]=0\nfor i in range(1,1000001):\n p[i]+=p[i-1]\na,b,k=map(int,input().split())\nif p[b]-p[a-1]<k:\n print(-1);return()\ni=j=a\nl=0\nwhile j<=b:\n if p[j]-p[i-1]<k:\n j+=1\n else:\n l=max(l,j-i+1)\n i+=1\nl=max(j-i+1,l)\nprint(l)\n ", "passed": true, "time": 14.22, "memory": 52944.0, "status": "done"}, {"code": "I = lambda : map(int,input().split())\nvisited = [False for i in range (10**6+1)]\n#prime = {}\na , b , k =I()\nvisited[1] = True\nli = []\nfor i in range(2,int(b**(0.5))+1) :\n #print(visited[:14])\n if visited[i] == False :\n #prime[i] = 1\n for j in range (i+i,b+1 , i) :\n visited[j] =True\nfor i in range (a,b+1) :\n if visited[i] == False :\n li.append(i)\nans = 0 \nmaxx = 0 \n#print(li)\nt1 = a\n#print(li)\nif len(li) < k :\n print(\"-1\");return\nn = len(li)\nfor i in range (n-k+1) :\n ans = li[i+k-1] -t1 + 1\n #print(ans)\n maxx = max(maxx,ans)\n t1 = li[i] + 1\nww = b - li[-k] + 1\n#print(ww)\nmaxx = max(ww,maxx)\nprint(maxx)", "passed": true, "time": 4.1, "memory": 25620.0, "status": "done"}, {"code": "from math import floor, sqrt\n\n\ndef siv(limit, primes):\n mark = [False] * (limit + 1)\n for i in range(2, limit + 1):\n if not mark[i]:\n primes.append(i)\n for j in range(i, limit + 1, i):\n mark[j] = True\n\n\ndef pir(low, high, prims):\n limit = floor(sqrt(high)) + 1\n primes = list()\n siv(limit, primes)\n n = high - low + 1\n mark = [False] * (n + 1)\n for i in range(len(primes)):\n loLim = floor(low / primes[i]) * primes[i]\n if loLim < low:\n loLim += primes[i]\n if loLim == primes[i]:\n loLim += primes[i]\n for j in range(loLim, high + 1, primes[i]):\n mark[j - low] = True\n pc = 0\n for i in range(low, high + 1):\n if not mark[i - low]:\n prims.append(i)\n pc += 1\n return pc\n\n\na, b, k = [int(i) for i in input().split()]\n\nprims = []\npc = pir(a, b, prims)\nif pc!= 0 and prims[0] == 1:\n prims.remove(1)\n pc-=1\n\nif pc < k:\n print(-1)\n return\n\nmx = max(prims[k - 1] - a + 1, b - prims[len(prims) - k] + 1)\n\nfor i in range(len(prims) - k):\n mx = max(prims[i + k] - prims[i], mx)\n\nprint(mx)", "passed": true, "time": 3.25, "memory": 24592.0, "status": "done"}]
[{"input": "2 4 2\n", "output": "3\n"}, {"input": "6 13 1\n", "output": "4\n"}, {"input": "1 4 3\n", "output": "-1\n"}, {"input": "5 8 2\n", "output": "4\n"}, {"input": "8 10 3\n", "output": "-1\n"}, {"input": "1 5 2\n", "output": "3\n"}, {"input": "6 8 3\n", "output": "-1\n"}, {"input": "21 29 2\n", "output": "9\n"}, {"input": "17 27 3\n", "output": "11\n"}, {"input": "1 1000000 10000\n", "output": "137970\n"}, {"input": "690059 708971 10000\n", "output": "-1\n"}, {"input": "12357 534133 2\n", "output": "138\n"}, {"input": "838069 936843 3\n", "output": "142\n"}, {"input": "339554 696485 4\n", "output": "168\n"}, {"input": "225912 522197 5\n", "output": "190\n"}, {"input": "404430 864261 6\n", "output": "236\n"}, {"input": "689973 807140 7\n", "output": "236\n"}, {"input": "177146 548389 8\n", "output": "240\n"}, {"input": "579857 857749 9\n", "output": "300\n"}, {"input": "35648 527231 10\n", "output": "280\n"}, {"input": "2 1000000 10000\n", "output": "137970\n"}, {"input": "1 999999 9999\n", "output": "137958\n"}, {"input": "5 5 10\n", "output": "-1\n"}, {"input": "11 11 6\n", "output": "-1\n"}, {"input": "4 4 95\n", "output": "-1\n"}, {"input": "1 1000000 1000000\n", "output": "-1\n"}, {"input": "1 1000000 78498\n", "output": "999999\n"}, {"input": "1 1000000 78499\n", "output": "-1\n"}, {"input": "3459 94738 1\n", "output": "72\n"}, {"input": "1 1000000 1\n", "output": "114\n"}, {"input": "1 1000000 78498\n", "output": "999999\n"}, {"input": "1 1000000 78497\n", "output": "999998\n"}, {"input": "1 1000000 78490\n", "output": "999978\n"}, {"input": "1000 10000 13\n", "output": "168\n"}, {"input": "100000 1000000 7821\n", "output": "108426\n"}, {"input": "20 1000000 40000\n", "output": "539580\n"}, {"input": "1000 900000 50000\n", "output": "659334\n"}, {"input": "10000 1000000 60000\n", "output": "793662\n"}, {"input": "9999 99999 8000\n", "output": "86572\n"}, {"input": "50 150 20\n", "output": "100\n"}, {"input": "999953 999953 1\n", "output": "1\n"}, {"input": "999953 999953 2\n", "output": "-1\n"}, {"input": "999931 999953 2\n", "output": "23\n"}, {"input": "999906 999984 4\n", "output": "52\n"}, {"input": "999940 999983 3\n", "output": "26\n"}, {"input": "1 1 1\n", "output": "-1\n"}, {"input": "1 1 1000000\n", "output": "-1\n"}, {"input": "1 2 1\n", "output": "2\n"}, {"input": "1 3 1\n", "output": "2\n"}, {"input": "1 3 2\n", "output": "3\n"}, {"input": "1 4 2\n", "output": "3\n"}, {"input": "1 5 2\n", "output": "3\n"}, {"input": "1 5 3\n", "output": "5\n"}, {"input": "2 5 2\n", "output": "3\n"}, {"input": "3 5 1\n", "output": "2\n"}]
360
After lessons Nastya decided to read a book. The book contains $n$ chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number $k$ as the first page which was not read (i.e. she read all pages from the $1$-st to the $(k-1)$-th). The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle). -----Input----- The first line contains a single integer $n$ ($1 \leq n \leq 100$)Β β€” the number of chapters in the book. There are $n$ lines then. The $i$-th of these lines contains two integers $l_i$, $r_i$ separated by space ($l_1 = 1$, $l_i \leq r_i$)Β β€” numbers of the first and the last pages of the $i$-th chapter. It's guaranteed that $l_{i+1} = r_i + 1$ for all $1 \leq i \leq n-1$, and also that every chapter contains at most $100$ pages. The $(n+2)$-th line contains a single integer $k$ ($1 \leq k \leq r_n$)Β β€” the index of the marked page. -----Output----- Print a single integerΒ β€” the number of chapters which has not been completely read so far. -----Examples----- Input 3 1 3 4 7 8 11 2 Output 3 Input 3 1 4 5 9 10 12 9 Output 2 Input 1 1 7 4 Output 1 -----Note----- In the first example the book contains $11$ pages and $3$ chaptersΒ β€” $[1;3]$, $[4;7]$ and $[8;11]$. Nastya marked the $2$-nd page, so she finished in the middle of the $1$-st chapter. So, all chapters has not been read so far, so the answer is $3$. The book in the second example contains $12$ pages and $3$ chapters too, but Nastya finished reading in the middle of the $2$-nd chapter, so that the answer is $2$.
interview
[{"code": "ii = lambda: int(input())\nmi = lambda: map(int, input().split())\nli = lambda: list(mi())\n\nn = ii()\na = [li() for _ in range(n)]\nk = ii()\nans = 0\nfor l, r in a:\n ans += k <= r\nprint(ans)", "passed": true, "time": 0.21, "memory": 14388.0, "status": "done"}, {"code": "n = int(input())\na = []\nfor i in range(n):\n a.append([int(j) for j in input().split()])\nk = int(input())\nans = n\nfor i in range(n):\n if k > a[i][1]:\n ans -= 1\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "n = int(input())\nb = []\nfor i in range(n):\n tl, tr = list(map(int, input().split()))\n b.append((tl, tr))\nk = int(input())\nans = 0\nfor l, r in b:\n if k <= r:\n ans += 1\nprint(ans)\n", "passed": true, "time": 0.24, "memory": 14444.0, "status": "done"}, {"code": "n = int(input())\narr = [list(map(int, input().split())) for i in range(n)]\nk = int(input()) - 1\ncnt = 0\nfor el in arr:\n\tif el[1] <= k:\n\t\tcnt += 1\nprint(n - cnt)", "passed": true, "time": 0.31, "memory": 14336.0, "status": "done"}, {"code": "hop = []\nfor i in range(int(input())):\n a, b = map(int, input().split())\n hop.append(b)\nk = int(input())\nfor i in range(len(hop)):\n if k <= hop[i]:\n print(len(hop) - i)\n break", "passed": true, "time": 0.21, "memory": 14252.0, "status": "done"}, {"code": "n = int(input())\na = []\nfor i in range(n):\n\tl, r = list(map(int, input().split()))\n\ta.append((l, r))\nq = int(input())\nk = 0\nfor i in a:\n\tif q > i[1]:\n\t\tk += 1\nprint(n -k)\n", "passed": true, "time": 0.16, "memory": 14352.0, "status": "done"}, {"code": "n = int(input())\na = []\nfor i in range(n):\n x, y = map(int, input().split())\n a.append(y)\np = int(input())\nfor i in range(n):\n if p <= a[i]:\n print(n - i)\n break", "passed": true, "time": 0.2, "memory": 14372.0, "status": "done"}, {"code": "n = int(input())\nl = []\nfor i in range(n):\n l.append(list(map(int, input().split())))\npage = int(input())\n\nout = 0\nfor ch in l:\n if ch[-1] >= page:\n out += 1\n\nprint(out)\n", "passed": true, "time": 0.16, "memory": 14400.0, "status": "done"}, {"code": "n = int(input())\na = []\nfor i in range(n):\n\tl, r = map(int, input().split())\n\ta+=[(l, r)]\nk = int(input())\n\ncount = 0\nfor l, r in a:\n\tif not r<k:\n\t\tcount += 1\nprint(count)", "passed": true, "time": 0.23, "memory": 14496.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\n\ndef rli():\n return list(map(int, input().split()))\n\n\ndef main():\n n = int(input())\n ns = []\n for i in range(n):\n x, y = rli()\n ns.append((x, y))\n w = int(input())\n for i in range(n):\n x, y = ns[i]\n if y >= w:\n print(n - i)\n return\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14416.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n# @Time : 2019/3/12 0:35\n# @Author : LunaFire\n# @Email : [email protected]\n# @File : A. Nastya Is Reading a Book.py\n\n\ndef main():\n n = int(input())\n lr = [list(map(int, input().split())) for _ in range(n)]\n k = int(input())\n\n ret = 0\n for i in range(n):\n if lr[i][1] >= k:\n ret += 1\n print(ret)\n\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14236.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 = ria()[0]\nar = []\nfor i in range(n):\n ar.append(ria())\nlk = ria()[0]\ncnt = 0\nlk -= 1\nfor l, r in ar:\n if l <= lk and r <= lk:\n cnt += 1\nprint(n - cnt)\n", "passed": true, "time": 0.33, "memory": 14572.0, "status": "done"}, {"code": "n = int(input())\nd = []\nfor _ in range(n):\n l, r = [int(item) for item in input().split()]\n d.append([l, r])\n\nk = int(input())\n\nans = 0\nfor i in range(n):\n l, r = d[i]\n if r >= k:\n ans = i\n break\n\nprint(n - ans)\n", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "n=int(input())\ntot=[]\nfor i in range(n):\n a,b=[int(x) for x in input().split()]\n tot.append((a,b))\nk=int(input())\ncounter=0\nfor item in tot:\n if item[0]<=k<=item[1]:\n print(n-counter)\n break\n counter+=1\n", "passed": true, "time": 0.15, "memory": 14564.0, "status": "done"}, {"code": "n = int(input())\narr = []\nfor i in range(n):\n\ta, b = map(int, input().split())\n\tarr.append([a, b])\nk = int(input())\nfor i in range(n):\n\tl = arr[i][0]\t\n\tr = arr[i][1]\n\tif r >= k:\n\t\tind = i\n\t\tbreak\nprint(n - ind)", "passed": true, "time": 0.96, "memory": 14268.0, "status": "done"}, {"code": "n=int(input())\narr=[]\nfor i in range(n):\n\ta,b=list(map(int,input().split()))\n\tarr.append((a,b))\npage=int(input())\nans=0\nfor i in range(n):\n\tif(arr[i][0]<=page<=arr[i][1]):\n\t\tans=i\nprint(n-ans)\n\n\n", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "n = int(input())\nA = [list(map(int, input().split())) for i in range(n)]\nk = int(input())\nans = 0\nfor i in range(n):\n l, r = A[i]\n if k <= r:\n ans += 1\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14492.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, = getIntList()\n #print(N)\n zz = []\n for i in range(N):\n l,r = getIntList()\n zz.append((l,r))\n x, = getIntList()\n for i in range(N):\n l,r = zz[i]\n if l<=x<=r:\n print(N-i)\n break\n \n \n", "passed": true, "time": 0.24, "memory": 14500.0, "status": "done"}, {"code": "n = int(input())\nA = []\nfor i in range(n):\n a, b = list(map(int, input().split()))\n A.append((a, b))\nk = int(input())\nfor i in range(n):\n if k >= A[i][0] and k <= A[i][1]:\n print(n - i)\n break\n", "passed": true, "time": 0.14, "memory": 14440.0, "status": "done"}, {"code": "n = int(input())\nl = []\nr = []\nfor i in range(n):\n l1, r1 = map(int, input().split())\n l.append(l1)\n r.append(r1)\nk = int(input())\nres = 1\nfor el in l:\n if k < el:\n res += 1\nprint(res)", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "n = int(input())\nl = list()\nr = list()\nfor i in range(n):\n x, y = list(map(int, input().split()))\n l.append(x)\n r.append(y)\nk = int(input())\nans = 0\nfor i in range(n):\n if k <= r[i]:\n ans += 1\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14344.0, "status": "done"}, {"code": "\n\nl=[]\nr=[]\nn=int(input())\nfor i in range(n):\n\n\ts=input().split(\" \")\n\tl.append(int(s[0]))\n\tr.append(int(s[1]))\n\nk=int(input())\n\nrem=n\n\n\ni=0\n\n\nfor i in range(n):\n\tif(l[i]<=k<=r[i]):\n\t\tbreak\n\trem-=1\nprint(rem)\n\n\n", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "n=int(input())\na=[0]*50001\nfor i in range(n):\n l,r=list(map(int,input().split()))\n for j in range(l,r+1):\n a[j]=i\nk=int(input())\nprint(n-a[k])\n", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}, {"code": "n=int(input())\na=[]\nfor i in range(n):\n a.append(list(map(int,input().split())))\nk=int(input())\nfor i in range(n):\n if a[i][1]>=k:\n print(n-i)\n break\n", "passed": true, "time": 0.14, "memory": 14208.0, "status": "done"}]
[{"input": "3\n1 3\n4 7\n8 11\n2\n", "output": "3\n"}, {"input": "3\n1 4\n5 9\n10 12\n9\n", "output": "2\n"}, {"input": "1\n1 7\n4\n", "output": "1\n"}, {"input": "3\n1 6\n7 16\n17 20\n4\n", "output": "3\n"}, {"input": "3\n1 6\n7 13\n14 17\n16\n", "output": "1\n"}, {"input": "6\n1 6\n7 12\n13 19\n20 28\n29 37\n38 39\n21\n", "output": "3\n"}, {"input": "27\n1 46\n47 111\n112 207\n208 266\n267 341\n342 380\n381 443\n444 476\n477 495\n496 581\n582 653\n654 710\n711 712\n713 774\n775 799\n800 809\n810 874\n875 877\n878 913\n914 986\n987 998\n999 1030\n1031 1095\n1096 1106\n1107 1147\n1148 1196\n1197 1210\n45\n", "output": "27\n"}, {"input": "10\n1 60\n61 84\n85 88\n89 149\n150 216\n217 243\n244 307\n308 319\n320 321\n322 402\n389\n", "output": "1\n"}, {"input": "49\n1 17\n18 115\n116 211\n212 269\n270 345\n346 404\n405 441\n442 467\n468 526\n527 583\n584 664\n665 757\n758 794\n795 802\n803 882\n883 920\n921 960\n961 962\n963 1006\n1007 1081\n1082 1112\n1113 1149\n1150 1217\n1218 1282\n1283 1287\n1288 1365\n1366 1374\n1375 1379\n1380 1478\n1479 1524\n1525 1549\n1550 1646\n1647 1671\n1672 1752\n1753 1755\n1756 1782\n1783 1824\n1825 1894\n1895 1966\n1967 2027\n2028 2091\n2092 2112\n2113 2153\n2154 2156\n2157 2161\n2162 2258\n2259 2324\n2325 2421\n2422 2501\n1285\n", "output": "25\n"}, {"input": "45\n1 48\n49 118\n119 122\n123 198\n199 283\n284 352\n353 447\n448 528\n529 539\n540 549\n550 557\n558 627\n628 700\n701 741\n742 835\n836 883\n884 887\n888 900\n901 943\n944 1032\n1033 1131\n1132 1158\n1159 1222\n1223 1281\n1282 1315\n1316 1397\n1398 1469\n1470 1520\n1521 1558\n1559 1631\n1632 1688\n1689 1699\n1700 1766\n1767 1775\n1776 1778\n1779 1878\n1879 1904\n1905 1984\n1985 1987\n1988 1999\n2000 2059\n2060 2126\n2127 2168\n2169 2189\n2190 2206\n1109\n", "output": "25\n"}, {"input": "19\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\n13\n", "output": "7\n"}, {"input": "27\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\n25\n", "output": "3\n"}, {"input": "71\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n69\n", "output": "3\n"}, {"input": "12\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n9\n", "output": "4\n"}, {"input": "68\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n53\n", "output": "16\n"}, {"input": "4\n1 12\n13 59\n60 100\n101 124\n93\n", "output": "2\n"}, {"input": "9\n1 81\n82 177\n178 254\n255 338\n339 410\n411 412\n413 474\n475 534\n535 555\n426\n", "output": "3\n"}, {"input": "5\n1 48\n49 138\n139 146\n147 200\n201 272\n122\n", "output": "4\n"}, {"input": "47\n1 6\n7 14\n15 21\n22 24\n25 27\n28 31\n32 39\n40 40\n41 43\n44 48\n49 52\n53 54\n55 60\n61 68\n69 74\n75 80\n81 82\n83 89\n90 90\n91 97\n98 101\n102 111\n112 120\n121 130\n131 135\n136 141\n142 150\n151 153\n154 156\n157 157\n158 162\n163 164\n165 165\n166 167\n168 170\n171 171\n172 181\n182 188\n189 195\n196 202\n203 203\n204 208\n209 218\n219 220\n221 230\n231 237\n238 239\n161\n", "output": "17\n"}, {"input": "11\n1 8\n9 15\n16 18\n19 23\n24 25\n26 27\n28 29\n30 36\n37 39\n40 44\n45 54\n49\n", "output": "1\n"}, {"input": "1\n1 2\n1\n", "output": "1\n"}, {"input": "2\n1 1\n2 2\n1\n", "output": "2\n"}, {"input": "1\n1 7\n7\n", "output": "1\n"}, {"input": "1\n1 1\n1\n", "output": "1\n"}, {"input": "4\n1 2\n3 4\n5 6\n7 8\n1\n", "output": "4\n"}, {"input": "3\n1 3\n4 5\n6 7\n4\n", "output": "2\n"}, {"input": "3\n1 3\n4 5\n6 6\n1\n", "output": "3\n"}, {"input": "3\n1 1\n2 2\n3 3\n2\n", "output": "2\n"}, {"input": "1\n1 7\n1\n", "output": "1\n"}, {"input": "3\n1 3\n4 7\n8 11\n1\n", "output": "3\n"}, {"input": "5\n1 1\n2 3\n4 5\n6 7\n8 9\n1\n", "output": "5\n"}, {"input": "2\n1 3\n4 7\n4\n", "output": "1\n"}, {"input": "2\n1 2\n3 4\n3\n", "output": "1\n"}, {"input": "4\n1 1\n2 3\n4 4\n5 5\n2\n", "output": "3\n"}, {"input": "3\n1 1\n2 2\n3 3\n1\n", "output": "3\n"}, {"input": "2\n1 3\n4 10\n4\n", "output": "1\n"}, {"input": "13\n1 13\n14 15\n16 17\n18 19\n20 21\n22 23\n24 25\n26 27\n28 29\n30 31\n32 33\n34 35\n36 37\n13\n", "output": "13\n"}, {"input": "4\n1 3\n4 7\n8 11\n12 15\n12\n", "output": "1\n"}, {"input": "2\n1 2\n3 10\n1\n", "output": "2\n"}, {"input": "3\n1 1\n2 3\n4 5\n1\n", "output": "3\n"}, {"input": "2\n1 1\n2 2\n2\n", "output": "1\n"}, {"input": "3\n1 4\n5 9\n10 12\n10\n", "output": "1\n"}, {"input": "2\n1 2\n3 4\n1\n", "output": "2\n"}, {"input": "3\n1 3\n4 7\n8 11\n8\n", "output": "1\n"}, {"input": "66\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n1\n", "output": "66\n"}, {"input": "3\n1 1\n2 2\n3 3\n3\n", "output": "1\n"}, {"input": "3\n1 2\n3 4\n5 6\n3\n", "output": "2\n"}, {"input": "2\n1 3\n4 6\n4\n", "output": "1\n"}, {"input": "4\n1 1\n2 2\n3 3\n4 4\n2\n", "output": "3\n"}, {"input": "5\n1 1\n2 2\n3 3\n4 4\n5 5\n3\n", "output": "3\n"}, {"input": "13\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n19 20\n21 22\n23 24\n25 26\n5\n", "output": "11\n"}, {"input": "1\n1 5\n1\n", "output": "1\n"}, {"input": "3\n1 3\n4 7\n8 11\n4\n", "output": "2\n"}, {"input": "3\n1 1\n2 2\n3 4\n3\n", "output": "1\n"}, {"input": "3\n1 3\n4 6\n7 9\n4\n", "output": "2\n"}]
361
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforces^{Ο‰} that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters. There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc. Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES. -----Input----- The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES. -----Output----- Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes). -----Examples----- Input CODEWAITFORITFORCES Output YES Input BOTTOMCODER Output NO Input DECODEFORCES Output YES Input DOGEFORCES Output NO
interview
[{"code": "import sys\n\nfin = sys.stdin\nfout = sys.stdout\n\n#fin = open(\"input.txt\", 'r')\n#fout = open(\"output.txt\", 'w')\n\ns = fin.readline().strip()\nn = len(s)\nfor L in range(n):\n for R in range(L + 1, n + 1):\n s1 = s[:L]\n s2 = s[L:R]\n s3 = s[R:]\n if (s1 + s3 == \"CODEFORCES\"):\n print(\"YES\")\n return\nprint(\"NO\")\n", "passed": true, "time": 0.25, "memory": 14348.0, "status": "done"}, {"code": "s = input()\nss = \"CODEFORCES\"\nans = \"NO\"\nfor i in range(len(s)):\n for j in range(i, len(s)):\n h = s[0:i] + s[j + 1:]\n if (h == ss):\n ans = \"YES\"\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14328.0, "status": "done"}, {"code": "s = input()\n\nif s.startswith('CODEFORCES'):\n print('YES')\n return\n\nfor i in range(len(s)):\n for j in range(i):\n if s[:j] + s[i:] == 'CODEFORCES':\n print(\"YES\")\n return\n\nprint(\"NO\")\n", "passed": true, "time": 0.15, "memory": 14356.0, "status": "done"}, {"code": "3\n# -*- coding: utf8 -*-\n\ndef main():\n s = input()\n c = 'CODEFORCES'\n for i in range(len(c) + 1):\n if s.startswith(c[:i]) and s.endswith(c[i:]):\n print('YES')\n return\n print('NO')\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.23, "memory": 14504.0, "status": "done"}, {"code": "a = input()\nif a.startswith(\"CODEFORCES\") or a.endswith(\"CODEFORCES\"):\n print(\"YES\")\n return\nfor i in range(len(a)):\n for j in range(i,len(a)):\n if a[:i]+a[j+1:]==\"CODEFORCES\":\n print(\"YES\")\n return\nprint(\"NO\")", "passed": true, "time": 0.25, "memory": 14304.0, "status": "done"}, {"code": "def __starting_point():\n word = input()\n if word.startswith(\"CODEFORCES\"):\n print(\"YES\")\n elif word.startswith(\"CODEFORCE\") and word.endswith(\"S\"):\n print(\"YES\")\n elif word.startswith(\"CODEFORC\") and word.endswith(\"ES\"):\n print(\"YES\")\n elif word.startswith(\"CODEFOR\") and word.endswith(\"CES\"):\n print(\"YES\")\n elif word.startswith(\"CODEFO\") and word.endswith(\"RCES\"):\n print(\"YES\")\n elif word.startswith(\"CODEF\") and word.endswith(\"ORCES\"):\n print(\"YES\")\n elif word.startswith(\"CODE\") and word.endswith(\"FORCES\"):\n print(\"YES\")\n elif word.startswith(\"COD\") and word.endswith(\"EFORCES\"):\n print(\"YES\")\n elif word.startswith(\"CO\") and word.endswith(\"DEFORCES\"):\n print(\"YES\")\n elif word.startswith(\"C\") and word.endswith(\"ODEFORCES\"):\n print(\"YES\")\n elif word.endswith(\"CODEFORCES\"):\n print(\"YES\")\n else:\n print(\"NO\")\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "s = input()\n\nf = False;\n\nfor i in range(1, len(s)):\n if f:\n break;\n for j in range(0, len(s) - i + 1):\n t = s[0:j] + s[j+i:]\n if t == \"CODEFORCES\":\n print(\"YES\")\n f = True\n break\n \nif not f:\n print(\"NO\")\n \n\n \n \n", "passed": true, "time": 0.22, "memory": 14440.0, "status": "done"}, {"code": "import sys\nf = sys.stdin\n\ns = f.readline().strip()\nSS = 'CODEFORCES'\n\nres = False\n \nfor i in range(len(s)):\n for l in range(len(s)):\n if s[:i] + s[(i+l):] == SS:\n res = True\n break\n\n\n \nif res:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n \n \n\n", "passed": true, "time": 1.02, "memory": 14488.0, "status": "done"}, {"code": "l = list(input())\nl1 = list('CODEFORCES')\nc = 0\nd = 0\nfor i in range(min(len(l),len(l1))):\n if l[i] == l1[i]:\n c += 1\n else:\n break\n\nl = l[::-1]; l1 = l1[::-1]\nfor i in range(min(len(l),len(l1))):\n if l[i] == l1[i]:\n d += 1\n else:\n break\nif c+d >= len(l1):\n print('YES')\nelse:\n print(\"NO\")\n", "passed": true, "time": 1.0, "memory": 14528.0, "status": "done"}, {"code": "s = input()\ns2 = \"CODEFORCES\"\nwhile s and s2 and s[0] == s2[0]:\n s = s[1:]\n s2 = s2[1:]\nwhile s and s2 and s[-1] == s2[-1]:\n s = s[:-1]\n s2 = s2[:-1]\nif s2 == '':\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "def solve(s,n,w):\n if s==w:\n return \"YES\"\n for i in range(n):\n for j in range(i,n,1):\n ns=s[0:i]+s[j+1:]\n if len(ns) != len(w):\n continue\n for k in range(len(ns)):\n if ns[k] != w[k]:\n break\n else:\n return \"YES\"\n return \"NO\"\n\ns=input()\nn=len(s)\nw=\"CODEFORCES\"\nprint(solve(s,n,w))\n", "passed": true, "time": 0.15, "memory": 14432.0, "status": "done"}, {"code": "S = input()\nc = 'CODEFORCES'\nfor i in range(len(S)):\n for j in range(i, len(S)+1):\n if S[:i] + S[j:]== c:\n print('YES')\n return\nprint('NO')\n \n \n", "passed": true, "time": 0.15, "memory": 14476.0, "status": "done"}, {"code": "def solve(word):\n banner = \"CODEFORCES\"\n\n for c in word:\n if c == banner[0]:\n banner = banner[1:]\n if len(banner) == 0:\n return True\n else:\n break\n\n for c in word[::-1]:\n if c == banner[-1]:\n banner = banner[:-1]\n if len(banner) == 0:\n return True\n else:\n break\n return False\n\nimport sys\nword = sys.stdin.read().strip()\nif solve(word) == True:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.24, "memory": 14476.0, "status": "done"}, {"code": "x = input()\nif len(x) < 10:\n print(\"NO\")\nelse:\n if ((x[0:1] == \"C\") and (x[len(x) - 9:len(x)] == \"ODEFORCES\")) or ((x[0:2] == \"CO\") and (x[len(x) - 8:len(x)] == \"DEFORCES\")) or ((x[0:3] == \"COD\") and (x[len(x) - 7:len(x)] == \"EFORCES\")) or ((x[0:4] == \"CODE\") and (x[len(x) - 6:len(x)] == \"FORCES\")) or ((x[0:5] == \"CODEF\") and (x[len(x) - 5:len(x)] == \"ORCES\")) or ((x[0:6] == \"CODEFO\") and (x[len(x) - 4:len(x)] == \"RCES\")) or ((x[0:7] == \"CODEFOR\") and (x[len(x) - 3:len(x)] == \"CES\")) or ((x[0:8] == \"CODEFORC\") and (x[len(x) - 2:len(x)] == \"ES\")) or ((x[0:9] == \"CODEFORCE\") and (x[len(x) - 1:len(x)] == \"S\")) or ((x[0:10] == \"CODEFORCES\") or (x[len(x) - 10:len(x)] == \"CODEFORCES\")):\n print(\"YES\")\n else:\n print(\"NO\")", "passed": true, "time": 0.17, "memory": 14376.0, "status": "done"}, {"code": "s = input()\nans = False\nn = len(s)\nfor i in range(n):\n for j in range(i + 1, n):\n if s[:i] + s[j:] == 'CODEFORCES':\n ans = True\n break\n if ans:\n break\nif s[:10] == 'CODEFORCES':\n ans = True\n\nif ans:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.14, "memory": 14408.0, "status": "done"}, {"code": "def main(s):\n key = \"CODEFORCES\"\n for i in range(11):\n s1 = key[0:i]\n s2 = key[i:10]\n if s.startswith(s1) and s.endswith(s2):\n return 'YES'\n return 'NO'\n\ndef __starting_point():\n s = input()\n print(main(s))\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14432.0, "status": "done"}, {"code": "from fnmatch import fnmatch, fnmatchcase\npat =[\"*CODEFORCES\", \"C*ODEFORCES\", \"CO*DEFORCES\"\n,\"COD*EFORCES\"\n,\"CODE*FORCES\"\n,\"CODEF*ORCES\"\n,\"CODEFO*RCES\"\n,\"CODEFOR*CES\"\n,\"CODEFORC*ES\"\n,\"CODEFORCE*S\"\n,\"CODEFORCES*\"]\nname = input()\nok = 0\nfor s in pat:\n if fnmatch(name,s):\n print(\"YES\")\n ok = 1\n break\nif ok == 0:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14308.0, "status": "done"}, {"code": "s, t = 'CODEFORCES', input().strip()\nprint('YES' if any(s[:i] == t[:i] and s[i:] == t[len(t) - len(s) + i:] for i in range(len(s) + 1)) else 'NO')\n", "passed": true, "time": 0.14, "memory": 14464.0, "status": "done"}, {"code": "t = 'CODEFORCES'\n\ns = input()\n\nfor i in range(len(s)):\n for j in range(i, len(s) + 1):\n if ''.join((s[:i], s[j:])) == t:\n print('YES')\n return\nprint('NO')\n", "passed": true, "time": 0.34, "memory": 14240.0, "status": "done"}, {"code": "3\n\ns = \"CODEFORCES\"\n\ninp = input()\n\nans = False\n\nfor i in range(len(inp)):\n for j in range(i, len(inp) + 1):\n new_s = inp[:i] + inp[j:]\n if new_s == s:\n ans = True\n\nif ans:\n print (\"YES\")\nelse:\n print (\"NO\")\n", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\ns = input()\nln = len(s)\nans = \"NO\"\npat = \"CODEFORCES\"\ncl = len(pat)\nif ln > cl:\n for pref_len in range(cl):\n check = s[:pref_len] + s[pref_len - cl:]\n if check == pat:\n ans = \"YES\"\n break\n if s[:cl] == pat:\n ans = \"YES\"\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14392.0, "status": "done"}, {"code": "x = input()\nn = len(x)\n\nfor i in range(n):\n for j in range(i+1,n+1):\n if(x[:i]+x[j:]==\"CODEFORCES\"):\n print(\"YES\")\n return\nprint(\"NO\")\nreturn\n", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "s = input()\n\nn = len(s)\ngood = False\nfor i in range(n):\n for j in range(i + 1, n + 1):\n if s[:i] + s[j:] == 'CODEFORCES':\n good = True\n\nprint('YES' if good else 'NO')\n", "passed": true, "time": 0.15, "memory": 14456.0, "status": "done"}]
[{"input": "CODEWAITFORITFORCES\n", "output": "YES\n"}, {"input": "BOTTOMCODER\n", "output": "NO\n"}, {"input": "DECODEFORCES\n", "output": "YES\n"}, {"input": "DOGEFORCES\n", "output": "NO\n"}, {"input": "ABACABA\n", "output": "NO\n"}, {"input": "CODEFORCE\n", "output": "NO\n"}, {"input": "C\n", "output": "NO\n"}, {"input": "NQTSMZEBLY\n", "output": "NO\n"}, {"input": "CODEFZORCES\n", "output": "YES\n"}, {"input": "EDYKHVZCNTLJUUOQGHPTIOETQNFLLWEKZOHIUAXELGECABVSBIBGQODQXVYFKBYJWTGBYHVSSNTINKWSINWSMALUSIWNJMTCOOVF\n", "output": "NO\n"}, {"input": "OCECFDSRDE\n", "output": "NO\n"}, {"input": "MDBUWCZFFZKFMJTTJFXRHTGRPREORKDVUXOEMFYSOMSQGHUKGYCRCVJTNDLFDEWFS\n", "output": "NO\n"}, {"input": "CODEFYTORCHES\n", "output": "NO\n"}, {"input": "BCODEFORCES\n", "output": "YES\n"}, {"input": "CVODEFORCES\n", "output": "YES\n"}, {"input": "COAKDEFORCES\n", "output": "YES\n"}, {"input": "CODFMWEFORCES\n", "output": "YES\n"}, {"input": "CODEVCSYRFORCES\n", "output": "YES\n"}, {"input": "CODEFXHHPWCVQORCES\n", "output": "YES\n"}, {"input": "CODEFORQWUFJLOFFXTXRCES\n", "output": "YES\n"}, {"input": "CODEFORBWFURYIDURNRKRDLHCLXZCES\n", "output": "YES\n"}, {"input": "CODEFORCQSYSLYKCDFFUPSAZCJIAENCKZUFJZEINQIES\n", "output": "YES\n"}, {"input": "CODEFORCEVENMDBQLSVPQIIBGSHBVOPYZXNWVSTVWDRONUREYJJIJIPMEBPQDCPFS\n", "output": "YES\n"}, {"input": "CODEFORCESCFNNPAHNHDIPPBAUSPKJYAQDBVZNLSTSDCREZACVLMRFGVKGVHHZLXOHCTJDBQKIDWBUXDUJARLWGFGFCTTXUCAZB\n", "output": "YES\n"}, {"input": "CODJRDPDEFOROES\n", "output": "NO\n"}, {"input": "CODEFOGSIUZMZCMWAVQHNYFEKIEZQMAZOVEMDRMOEDBHAXPLBLDYYXCVTOOSJZVSQAKFXTBTZFWAYRZEMDEMVDJTDRXXAQBURCES\n", "output": "YES\n"}, {"input": "CODEMKUYHAZSGJBQLXTHUCZZRJJJXUSEBOCNZASOKDZHMSGWZSDFBGHXFLABVPDQBJYXSHHAZAKHSTRGOKJYHRVSSUGDCMFOGCES\n", "output": "NO\n"}, {"input": "CODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCESCODEFORCES\n", "output": "YES\n"}, {"input": "CCODEFORCESODECODEFORCCODEFORCESODCODEFORCESEFCODEFORCESORCODEFORCESCESCESFORCODEFORCESCES\n", "output": "NO\n"}, {"input": "CCODEFORCESC\n", "output": "NO\n"}, {"input": "CODEAFORBCES\n", "output": "NO\n"}, {"input": "CODERRRRRFORCRRRRES\n", "output": "NO\n"}, {"input": "CODELFORCELS\n", "output": "NO\n"}, {"input": "CPOPDPEPFPOPRPCPEPS\n", "output": "NO\n"}, {"input": "COXDEXFORXCEXS\n", "output": "NO\n"}, {"input": "CODAAAAAFORCES\n", "output": "NO\n"}, {"input": "CAOADEFORCES\n", "output": "NO\n"}, {"input": "FORCESXCODE\n", "output": "NO\n"}, {"input": "FORCESACODE\n", "output": "NO\n"}, {"input": "ACAOADAEFORCES\n", "output": "NO\n"}, {"input": "CCODEFORCESS\n", "output": "NO\n"}, {"input": "ZCODEFORCEZ\n", "output": "NO\n"}, {"input": "CODXEFORXCES\n", "output": "NO\n"}, {"input": "CODEFORCEZ\n", "output": "NO\n"}, {"input": "CODEFORCEST\n", "output": "YES\n"}, {"input": "AXODEFORCES\n", "output": "NO\n"}, {"input": "RCODEFORCESR\n", "output": "NO\n"}, {"input": "CODECODEFORCESFORCES\n", "output": "YES\n"}, {"input": "TTTWWWCODEFORCES\n", "output": "YES\n"}, {"input": "CODEFORRCEST\n", "output": "NO\n"}, {"input": "UJYTYUCODEFORCES\n", "output": "YES\n"}, {"input": "CODEXXXXXXXXXXXXXXXXXXCODEFORCESXXXXXXXXXXXXXXXXXXXXXFORCES\n", "output": "YES\n"}, {"input": "COXEDYFORCES\n", "output": "NO\n"}, {"input": "UJYTYCODEFORCES\n", "output": "YES\n"}, {"input": "UJYTCODEFORCES\n", "output": "YES\n"}]
362
You are given a regular polygon with $n$ vertices labeled from $1$ to $n$ in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is no pair of triangles such that their intersection has non-zero area, and the total area of all triangles is equal to the area of the given polygon. The weight of a triangulation is the sum of weigths of triangles it consists of, where the weight of a triagle is denoted as the product of labels of its vertices. Calculate the minimum weight among all triangulations of the polygon. -----Input----- The first line contains single integer $n$ ($3 \le n \le 500$) β€” the number of vertices in the regular polygon. -----Output----- Print one integer β€” the minimum weight among all triangulations of the given polygon. -----Examples----- Input 3 Output 6 Input 4 Output 18 -----Note----- According to Wiki: polygon triangulation is the decomposition of a polygonal area (simple polygon) $P$ into a set of triangles, i. e., finding a set of triangles with pairwise non-intersecting interiors whose union is $P$. In the first example the polygon is a triangle, so we don't need to cut it further, so the answer is $1 \cdot 2 \cdot 3 = 6$. In the second example the polygon is a rectangle, so it should be divided into two triangles. It's optimal to cut it using diagonal $1-3$ so answer is $1 \cdot 2 \cdot 3 + 1 \cdot 3 \cdot 4 = 6 + 12 = 18$.
interview
[{"code": "n = int(input())\nans = 0\nfor i in range(1, n - 1):\n ans += (i + 1) * (i + 2)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "ii = lambda: int(input())\nmi = lambda: map(int, input().split())\nli = lambda: list(mi())\n\nn = ii()\nans = 0\nfor i in range(3, n + 1):\n ans += i * (i - 1)\nprint(ans)", "passed": true, "time": 0.22, "memory": 14276.0, "status": "done"}, {"code": "n = int(input())\nprint(n*(n - 1)*(n + 1)//3 - 2)", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "n = int(input())\nt = 0\n\nfor i in range(n-2):\n t += (i+2)*(i+3)\n\nprint(t)", "passed": true, "time": 0.78, "memory": 14436.0, "status": "done"}, {"code": "from collections import defaultdict as dd\nimport math\ndef nn():\n\treturn int(input())\n\ndef li():\n\treturn list(input())\n\ndef mi():\n\treturn list(map(int, input().split()))\n\ndef lm():\n\treturn list(map(int, input().split()))\n\n\n\n\nn=nn()\n\ntotal=0\n\nfor i in range(n-2):\n\ttotal=total+1*(i+2)*(i+3)\n\nprint(total) \n", "passed": true, "time": 0.22, "memory": 14384.0, "status": "done"}, {"code": "def li ():\n\treturn list (map (int, input ().split ()))\n\n\ndef num ():\n\treturn map (int, input ().split ())\n\n\ndef nu ():\n\treturn int (input ())\n\nmm = 1000000007\n\n\ndef solve ():\n\tt = 1\n\tfor it in range (t):\n\t\tn=nu()\n\t\tcc=0\n\t\tfor i in range(2,n):\n\t\t\tcc+=i*(i+1)\n\t\tprint(cc)\n\n\n\ndef __starting_point():\n\tsolve ()\n__starting_point()", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "N = int(input())\nans = 0\nfor i in range(N-2):\n ans += (i+2)*(i+3)\n\nprint(ans)\n", "passed": true, "time": 0.25, "memory": 14320.0, "status": "done"}, {"code": "# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\nN = int(input())\nans = 0\nfor i, j in zip(list(range(2, N+1)), list(range(3, N+1))):\n ans += i*j\nprint(ans)\n", "passed": true, "time": 0.25, "memory": 14272.0, "status": "done"}, {"code": "n=int(input())-2\nprint(n*(n*n+6*n+11)//3)", "passed": true, "time": 0.23, "memory": 14328.0, "status": "done"}, {"code": "n=int(input())\nans=0\nfor i in range(2, n):\n ans+=i*(i+1)\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14496.0, "status": "done"}, {"code": "# stdin=open('input.txt')\n\n# def input():\n# \treturn stdin.readline()[:-1]\n\n# a, b = map(int, input().split())\n\n# l = list(map(int, input().split()))\n\n\n# CODE BEGINS HERE.................\n\nans = 0\nfor t in range(2, int(input())):\n\tans += t*(t + 1)\n\nprint(ans)\n#CODE ENDS HERE....................\n\n\n\n", "passed": true, "time": 0.14, "memory": 14172.0, "status": "done"}, {"code": "n = int(input())\nn = n - 1\n\nprint(n * (n + 1) * (2 * n + 1) // 6 + n * (n + 1) // 2 - 2)", "passed": true, "time": 0.14, "memory": 14488.0, "status": "done"}, {"code": "n = int(input())\nm = 0\nfor i in range(2, n):\n\tm += i * (i + 1)\nprint(m)", "passed": true, "time": 0.14, "memory": 14480.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 ans=0\n for i in range(2,n):\n ans+=i*(i+1)\n print(ans)\n #n,k,s= map(int, sys.stdin.readline().split(' '))\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.15, "memory": 14556.0, "status": "done"}, {"code": "n=int(input())\nans=0\nfor i in range(2,n):\n ans+=i*(i+1)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14444.0, "status": "done"}, {"code": "n=int(input())\nans=0\nfor i in range(2,n,1):\n\tans+=i*(i+1);\nprint(ans)", "passed": true, "time": 0.14, "memory": 14508.0, "status": "done"}, {"code": "a = int(input())\nans = 0\nfor i in range(a - 2):\n ans += (i + 2) * (i + 3)\nprint(ans)", "passed": true, "time": 0.15, "memory": 14448.0, "status": "done"}, {"code": "#!/usr/bin/env python3\nimport sys\n\ndef rint():\n return list(map(int, sys.stdin.readline().split()))\n#lines = stdin.readlines()\n\nn = int(input())\n\nans = 0\nfor i in range(2,n):\n ans += i*(i+1)\n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14300.0, "status": "done"}, {"code": "n = int(input())\nprint(sum(i * (i - 1) for i in range(3, n + 1)))\n", "passed": true, "time": 0.15, "memory": 14284.0, "status": "done"}, {"code": "n = int(input())\nans = 0\nfor i in range(2, n):\n ans += i * (i + 1)\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14288.0, "status": "done"}, {"code": "n = int(input())\ncnt = 0\nfor i in range(3, n + 1):\n cnt += i * (i - 1)\nprint(cnt)", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "n=int(input())\nans=0\nfor i in range(2,n):\n ans+=(i*(i+1))\nprint(ans)", "passed": true, "time": 0.15, "memory": 14392.0, "status": "done"}, {"code": "import re, math, decimal, bisect\ndef read(): return input().strip()\ndef iread(): return int(input().strip())\ndef viread(): return [int(_) for _ in input().strip().split()]\n\n# code goes here\nn = iread()\n_sum = 0\nfor i in range(n - 2):\n _sum += (i + 2) * (i + 3)\nprint(_sum)", "passed": true, "time": 0.15, "memory": 14260.0, "status": "done"}]
[{"input": "3\n", "output": "6\n"}, {"input": "4\n", "output": "18\n"}, {"input": "5\n", "output": "38\n"}, {"input": "6\n", "output": "68\n"}, {"input": "7\n", "output": "110\n"}, {"input": "8\n", "output": "166\n"}, {"input": "9\n", "output": "238\n"}, {"input": "10\n", "output": "328\n"}, {"input": "100\n", "output": "333298\n"}, {"input": "101\n", "output": "343398\n"}, {"input": "102\n", "output": "353700\n"}, {"input": "103\n", "output": "364206\n"}, {"input": "104\n", "output": "374918\n"}, {"input": "105\n", "output": "385838\n"}, {"input": "106\n", "output": "396968\n"}, {"input": "107\n", "output": "408310\n"}, {"input": "108\n", "output": "419866\n"}, {"input": "109\n", "output": "431638\n"}, {"input": "110\n", "output": "443628\n"}, {"input": "500\n", "output": "41666498\n"}, {"input": "497\n", "output": "40920990\n"}, {"input": "494\n", "output": "40184428\n"}, {"input": "491\n", "output": "39456758\n"}, {"input": "488\n", "output": "38737926\n"}, {"input": "485\n", "output": "38027878\n"}, {"input": "482\n", "output": "37326560\n"}, {"input": "479\n", "output": "36633918\n"}, {"input": "476\n", "output": "35949898\n"}, {"input": "473\n", "output": "35274446\n"}, {"input": "470\n", "output": "34607508\n"}, {"input": "467\n", "output": "33949030\n"}, {"input": "464\n", "output": "33298958\n"}, {"input": "461\n", "output": "32657238\n"}, {"input": "458\n", "output": "32023816\n"}, {"input": "455\n", "output": "31398638\n"}, {"input": "452\n", "output": "30781650\n"}, {"input": "449\n", "output": "30172798\n"}, {"input": "446\n", "output": "29572028\n"}, {"input": "42\n", "output": "24680\n"}, {"input": "69\n", "output": "109478\n"}, {"input": "228\n", "output": "3950706\n"}, {"input": "233\n", "output": "4216366\n"}, {"input": "420\n", "output": "24695858\n"}, {"input": "368\n", "output": "16611886\n"}, {"input": "225\n", "output": "3796798\n"}, {"input": "11\n", "output": "438\n"}, {"input": "12\n", "output": "570\n"}, {"input": "13\n", "output": "726\n"}, {"input": "14\n", "output": "908\n"}, {"input": "135\n", "output": "820078\n"}, {"input": "199\n", "output": "2626798\n"}, {"input": "137\n", "output": "857070\n"}, {"input": "131\n", "output": "749318\n"}, {"input": "130\n", "output": "732288\n"}, {"input": "139\n", "output": "895158\n"}]
363
Vanya got an important task β€” he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally, distinct books should be assigned distinct numbers. Vanya wants to know how many digits he will have to write down as he labels the books. -----Input----- The first line contains integer n (1 ≀ n ≀ 10^9) β€” the number of books in the library. -----Output----- Print the number of digits needed to number all the books. -----Examples----- Input 13 Output 17 Input 4 Output 4 -----Note----- Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits. Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
interview
[{"code": "hola = 0\na = int(input())\nd = len(str(a))\nk = 10**(d-1)\nfor i in range(1, d):\n hola += i * (10**(i-1)*9)\n\nhola += d * (a-k+1)\nprint(hola)", "passed": true, "time": 0.16, "memory": 14376.0, "status": "done"}, {"code": "n=int(input())\n\nv=0\ni=1\nwhile(n>=10**i):\n\tif i==1:v+=9\n\telse:v+=(10**i-10**(i-1))*i\n\ti+=1\n\t\nx=n-10**(i-1)+1\nv+=i*x\n\nprint(v)", "passed": true, "time": 1.81, "memory": 14416.0, "status": "done"}, {"code": "n = int(input())\nres = min(9, n)\nfor i in range(1, 10):\n #print(res)\n res += max(min(9*(10**i), n-10**i+1), 0)*(i+1)\n # print(9*(10**i), n-10**i)\nprint(res)\n", "passed": true, "time": 0.16, "memory": 14352.0, "status": "done"}, {"code": "def f(n):\n\tif n < 10:\n\t\treturn n\n\tk = 10 ** (len(str(n)) - 1)\n\treturn len(str(n)) * ((n % k) + 1) + f(n - (n % k) - 1)\n\nn = int(input())\nprint(f(n))", "passed": true, "time": 0.15, "memory": 14412.0, "status": "done"}, {"code": "n = int(input())\n\ndef countd(n):\n d = 0\n while n >= 10**d:\n d += 1\n count = 0\n while d > 0:\n tens = 10 ** (d - 1)\n count += (n - tens + 1) * d\n n = tens - 1\n d -= 1\n return count\n\nprint(countd(n))", "passed": true, "time": 0.25, "memory": 14216.0, "status": "done"}, {"code": "n = int(input())\ntotal = 0\n\nif(n < 10):\n\tprint(n)\n\treturn\n\ntotal += 9\n\nif(n < 100):\n\ttotal += (n - 9)*2\n\tprint(total)\n\treturn\n\ntotal += 90*2\n\nif(n < 1000):\n\ttotal += (n-99)*3\n\tprint(total)\n\treturn\n\ntotal += (900)*3\n\nif(n < 10000):\n\ttotal += (n-999)*4\n\tprint(total)\n\treturn\n\ntotal += (9000)*4\n\nif(n < 100000):\n\ttotal += (n-9999)*5\n\tprint(total)\n\treturn\n\ntotal += (90000)*5\n\nif(n < 1000000):\n\ttotal += (n-99999)*6\n\tprint(total)\n\treturn\n\ntotal += (900000)*6\n\nif(n < 10000000):\n\ttotal += (n-999999)*7\n\tprint(total)\n\treturn\n\ntotal += (9000000)*7\n\nif(n < 100000000):\n\ttotal += (n-9999999)*8\n\tprint(total)\n\treturn\n\ntotal += (90000000)*8\n\nif(n < 1000000000):\n\ttotal += (n-99999999)*9\n\tprint(total)\n\treturn\n\ntotal += (900000000)*9\n\nif(n < 10000000000):\n\ttotal += (n-999999999)*10\n\tprint(total)\n\treturn\n\ntotal += (9000000000)*10\n\nprint(total)", "passed": true, "time": 0.24, "memory": 14564.0, "status": "done"}, {"code": "n = int(input())\nans = 0\nA = [9 * 10 ** i for i in range(10)]\nfor i in range(10):\n if n <= A[i]:\n print(ans + n * (i + 1))\n break\n else:\n ans += A[i] * (i + 1)\n n -= A[i]\n", "passed": true, "time": 0.16, "memory": 14260.0, "status": "done"}, {"code": "def f(a):\n k = 0\n s = len(str(a))\n for i in range(1, s):\n k += (int(\"9\" * i) - int(\"1\" + \"0\" * (i - 1)) + 1) * i\n k += (a - int(\"1\" + \"0\" * (s - 1)) + 1) * s\n return(k)\na = int(input())\nprint(f(a))", "passed": true, "time": 0.16, "memory": 14360.0, "status": "done"}, {"code": "def f(n):\n n1 = n\n r = 0\n t = 0\n for i in range(0, 15):\n if n >= 10 ** i:\n r = r + n - 10 ** i + 1\n return r\nn = int(input())\nprint(f(n))\n", "passed": true, "time": 0.17, "memory": 14388.0, "status": "done"}, {"code": "def __starting_point():\n n_books = int(input())\n x = 0\n length = 1\n while n_books > 10**length - 1:\n x += (10**length - 10**(length-1))*length\n length += 1\n x += (n_books - 10**(length-1) + 1)*length\n print(x)\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14364.0, "status": "done"}, {"code": "__author__ = 'KostikBigOne'\n\ndef main():\n n = int(input())\n power, cnt = 1, 9\n ans = 0\n length = 1\n while True:\n if n >= 10 * power:\n ans += length * cnt\n cnt *= 10\n power *= 10\n length += 1\n else:\n ans += length * (n - power + 1)\n break\n print(ans)\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.15, "memory": 14424.0, "status": "done"}, {"code": "def f(m, n):\n if len(str(m)) < len(str(n)):\n return f(m, int('9' * (len(str(n)) - 1))) + f(int('9' * (len(str(n)) - 1)) + 1, n)\n else:\n return len(str(n)) * (n- m + 1)\n\nn = int(input())\nm = 1\nprint(f(1, n))", "passed": true, "time": 0.14, "memory": 14296.0, "status": "done"}, {"code": "a = input()\nsumm = 0\nlena = len(a)\nfor i in range(1, lena):\n summ += 10 ** (i - 1) * 9 * i\nsumm += lena * (int(a) - 10 ** (lena - 1) + 1)\nprint(summ)\n\n", "passed": true, "time": 0.15, "memory": 14264.0, "status": "done"}, {"code": "n = int(input())\n\nnumbers = 0\nadd = 9\nmult = 1\nmult2 = 1\nwhile (n >= mult2 * 10):\n numbers += 9 * mult * mult2\n mult += 1\n mult2 *= 10\n\nnumbers += (n - mult2 + 1) * mult\n\nprint(numbers)", "passed": true, "time": 0.14, "memory": 14364.0, "status": "done"}, {"code": "def f(n):\n if n < 10:\n return n\n if n < 100:\n return 9 + 2 * (n - 9)\n if n < 1e3:\n return f(99) + 3 * (n - 99)\n if n < 1e4:\n return f(999) + 4 * (n - 999)\n if n < 1e5:\n return f(9999) + 5 * (n - 9999)\n if n < 1e6:\n return f(99999) + 6 * (n - 99999)\n if n < 1e7:\n return f(999999) + 7 * (n - 999999)\n if n < 1e8:\n return f(9999999) + 8 * (n - 9999999)\n if n < 1e9:\n return f(99999999) + 9 * (n - 99999999)\n return f(999999999) + 10 * (n - 999999999)\n\nn = int(input())\nprint(f(n))\n", "passed": true, "time": 0.16, "memory": 14440.0, "status": "done"}, {"code": "def xxx(n):\n total = 0\n curr = 9\n for i in range(n):\n total += curr * (i + 1)\n curr *= 10\n\n return total\n\n\ndef __starting_point():\n n = int(input())\n l = len(str(n))\n a = xxx(l - 1)\n b = (n - 10 ** (l - 1) + 1) * l\n print(a + b)\n__starting_point()", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}, {"code": "n = int(input())\ns = 9\nans = 0\ni = 1\nwhile (n > 0):\n n -= s\n ans += s * i\n i += 1\n s *= 10\nans += n * (i - 1)\nprint(ans)\n \n", "passed": true, "time": 0.14, "memory": 14388.0, "status": "done"}, {"code": "n,s=int(input()),0\nfor b in range(10,-1,-1):\n if n >= 10**b:\n s += (b+1)*(n-10**b+1)\n n = 10**b - 1\nprint(s)\n", "passed": true, "time": 0.15, "memory": 14236.0, "status": "done"}, {"code": "n = int(input())\nans = 0\nfor i in range(1, len(str(n))):\n ans += 9 * i * (10 ** (i - 1))\nans += len(str(n)) * (n - (10 ** (len(str(n)) - 1)) + 1)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14420.0, "status": "done"}, {"code": "s = input()\nsize = 1\nans = 0\nwhile len(s) > size:\n ans += ((10 ** size) - (10 ** (size - 1))) * size\n size += 1\ns = int(s) - (10 ** (size - 1)) + 1\nans += s * size\nprint(ans)", "passed": true, "time": 0.14, "memory": 14448.0, "status": "done"}, {"code": "import math\nimport sys\n\nn=int(input())\ns=str(n)\nl=len(s)\n\n\n\nk=1\nans=0\nfor i in range(0,l-1):\n ans+=9*k*(i+1)\n k*=10\nm=n-k\n\n\nans+=(m+1)*l\n\n\nif l==1:\n ans=n\nprint(ans)\n \n", "passed": true, "time": 0.18, "memory": 14424.0, "status": "done"}, {"code": "n, v, p = int(input()), 0, 1\nwhile n >= 10 ** p:\n v += p * 9 * 10 ** (p - 1)\n p += 1\nv += (n - 10 ** (p - 1) + 1) * p\nprint(v)", "passed": true, "time": 0.16, "memory": 14452.0, "status": "done"}, {"code": "n = input()\nk = 9\nl = len(n)\nif l == 1:\n print(n)\nelse:\n c = (int(n)-int('9'*(l-1)))*l\n for i in range(l-1):\n c += k*(i+1)\n k *= 10\n # \ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n print(c)", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}]
[{"input": "13\n", "output": "17\n"}, {"input": "4\n", "output": "4\n"}, {"input": "100\n", "output": "192\n"}, {"input": "99\n", "output": "189\n"}, {"input": "1000000000\n", "output": "8888888899\n"}, {"input": "1000000\n", "output": "5888896\n"}, {"input": "999\n", "output": "2889\n"}, {"input": "55\n", "output": "101\n"}, {"input": "222222222\n", "output": "1888888896\n"}, {"input": "8\n", "output": "8\n"}, {"input": "13\n", "output": "17\n"}, {"input": "313\n", "output": "831\n"}, {"input": "1342\n", "output": "4261\n"}, {"input": "30140\n", "output": "139594\n"}, {"input": "290092\n", "output": "1629447\n"}, {"input": "2156660\n", "output": "13985516\n"}, {"input": "96482216\n", "output": "760746625\n"}, {"input": "943006819\n", "output": "8375950269\n"}, {"input": "1\n", "output": "1\n"}, {"input": "7\n", "output": "7\n"}, {"input": "35\n", "output": "61\n"}, {"input": "996\n", "output": "2880\n"}, {"input": "6120\n", "output": "23373\n"}, {"input": "30660\n", "output": "142194\n"}, {"input": "349463\n", "output": "1985673\n"}, {"input": "8171970\n", "output": "56092686\n"}, {"input": "36123011\n", "output": "277872985\n"}, {"input": "986747865\n", "output": "8769619683\n"}, {"input": "9\n", "output": "9\n"}, {"input": "10\n", "output": "11\n"}, {"input": "11\n", "output": "13\n"}, {"input": "101\n", "output": "195\n"}, {"input": "1000\n", "output": "2893\n"}, {"input": "1001\n", "output": "2897\n"}, {"input": "9999\n", "output": "38889\n"}, {"input": "10000\n", "output": "38894\n"}, {"input": "10001\n", "output": "38899\n"}, {"input": "99999\n", "output": "488889\n"}, {"input": "100000\n", "output": "488895\n"}, {"input": "100001\n", "output": "488901\n"}, {"input": "999999\n", "output": "5888889\n"}, {"input": "1000001\n", "output": "5888903\n"}, {"input": "9999999\n", "output": "68888889\n"}, {"input": "10000000\n", "output": "68888897\n"}, {"input": "10000001\n", "output": "68888905\n"}, {"input": "99999999\n", "output": "788888889\n"}, {"input": "100000000\n", "output": "788888898\n"}, {"input": "100000001\n", "output": "788888907\n"}, {"input": "999999999\n", "output": "8888888889\n"}, {"input": "95\n", "output": "181\n"}, {"input": "995\n", "output": "2877\n"}, {"input": "9995\n", "output": "38873\n"}, {"input": "99995\n", "output": "488869\n"}, {"input": "999999995\n", "output": "8888888853\n"}, {"input": "999999998\n", "output": "8888888880\n"}]
365
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and a_{i} is the length of i-th segment. No two segments touch or intersect. For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it! -----Input----- The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 10^9) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ 10000) β€” the encoding. -----Output----- Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. -----Examples----- Input 2 4 1 3 Output NO Input 3 10 3 3 2 Output YES Input 2 10 1 3 Output NO
interview
[{"code": "R=lambda:list(map(int,input().split()))\nn,x=R()\nprint('YES'if sum(R())+n-1==x else'NO')\n", "passed": true, "time": 0.2, "memory": 14528.0, "status": "done"}, {"code": "n, x = map(int, input().split())\nif x == sum([int(x) for x in input().split()]) + n - 1:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.23, "memory": 14248.0, "status": "done"}, {"code": "n, x = map(int, input().split())\nprint(['NO', 'YES'][sum(map(int, input().split())) + n - 1 == x])", "passed": true, "time": 0.14, "memory": 14516.0, "status": "done"}, {"code": "n, x = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\nif sum(a) + n - 1 == x:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.15, "memory": 14380.0, "status": "done"}, {"code": "n, x = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nif sum(a) + n - 1 == x:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}, {"code": "n, x = [int(i) for i in input().split()]\na = [int(j) for j in input().split()]\ns = sum(a)\nif s + n - 1 == x:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14360.0, "status": "done"}, {"code": "n,x=list(map(int,input().split()))\na=list(map(int,input().split()))\nsum1=sum(a)\n\n\nif((x-sum1)==n-1):\n print(\"YES\")\nelse:\n print(\"NO\")\n\n\n", "passed": true, "time": 0.23, "memory": 14260.0, "status": "done"}, {"code": "d=input().split(' ')\nn=int(d[1])\nlenc=int(d[0])\nd=list(map(lambda x:int(x),input().split(' ')))\nif sum(d)+lenc-1==n:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.22, "memory": 14444.0, "status": "done"}, {"code": "def main():\n n, x = list(map(int, input().split()))\n a = list(map(int, input().split()))\n s = sum(a)\n print('YES' if s + (n - 1) == x else 'NO')\n\nmain()\n", "passed": true, "time": 0.21, "memory": 14368.0, "status": "done"}, {"code": "n,x=list(map(int,input().split()))\na=list(map(int,input().split()))\nif sum(a)+len(a)-1==x:\n print('YES')\nelse:\n print('NO')\n\n", "passed": true, "time": 0.14, "memory": 14456.0, "status": "done"}, {"code": "import sys\nn,x=map(int,input().split())\nt=list(map(int,input().split()))\nif sum(t)+len(t)-1==x:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.16, "memory": 14260.0, "status": "done"}, {"code": "a=input().split(' ')\nn=int(a[0])\nx=int(a[1])\na=input().split(' ')\na=[int(i) for i in a]\nif len(a)+sum(a)==x+1:\n print(\"YES\")\n return\nprint(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14428.0, "status": "done"}, {"code": "n,t = list(map(int,input().split())) \ndata = list(map(int,input().split()))\ns=sum(data)\nprint('YES' if t==n-1+s else 'NO')\n", "passed": true, "time": 0.14, "memory": 14468.0, "status": "done"}, {"code": "n, x = input().split()\nn = int(n)\nx = int(x)\n\nsum = 0\nfor i in input().split():\n sum += int(i)\n\nif sum + n-1 != x:\n print(\"NO\")\nelse:\n print(\"YES\")", "passed": true, "time": 0.18, "memory": 14440.0, "status": "done"}, {"code": "n, x = list(map(int, input().split()))\na = list(map(int, input().split()))\ns = 0\nfor i in a:\n s += i\nif (s == x - n+1) or (n == 0):\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.22, "memory": 14396.0, "status": "done"}, {"code": "n,x=list(map(int,input().split()))\na=list(map(int,input().split()))\nsu=sum(a)\nif x==su and len(a)==1:\n print('YES')\nelif su==0:\n print('YES')\nelif x-su==n-1:\n print('YES')\nelse:\n print('NO')\n", "passed": true, "time": 0.15, "memory": 14316.0, "status": "done"}, {"code": "# -*- coding: utf-8 -*-\n\ndef f(n, x, arr):\n\n if x == (sum(arr) + n - 1):\n print('YES')\n else:\n print('NO')\n\n\n\ndef __starting_point():\n \n n, x = list(map(int, input().split()))\n arr = list(map(int, input().split()))\n\n # for i in range(n):\n # list(map(int, input().split()))\n\n f(n, x, arr)\n__starting_point()", "passed": true, "time": 0.14, "memory": 14428.0, "status": "done"}, {"code": "n = [int(x) for x in input().strip().split()]\nm = [int(y) for y in input().strip().split()]\nif n[1] == (sum(m) + n[0] - 1):\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.15, "memory": 14260.0, "status": "done"}, {"code": "n, x = [int(i) for i in input().split()]\n\na = [int(i) for i in input().split()]\n\nif sum(a) == (x - n + 1):\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.15, "memory": 14280.0, "status": "done"}, {"code": "n,x=map(int,input().split())\na=list(map(int,input().split()))\nk=0\nfor i in range(len(a)-1):\n k+=a[i]+1\nk+=a[len(a)-1]\nif len(a)==0 or k==x:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.15, "memory": 14472.0, "status": "done"}, {"code": "line = list(map(int, input().split()))\nn, x = line\nencoding = list(map(int, input().split()))\nif sum(encoding) + n - 1 == x:\n print(\"YES\")\nelse:\n print(\"NO\")", "passed": true, "time": 0.15, "memory": 14480.0, "status": "done"}, {"code": "n, x = list(map(int, input().split()))\ns = sum(list(map(int, input().split())))\nif s + n - 1 == x:\n print(\"YES\")\nelse:\n print(\"NO\")\n", "passed": true, "time": 0.14, "memory": 14400.0, "status": "done"}, {"code": "n,x = list(map(int, input().split()))\na = list(map(int, input().split()))\nif n - 1 + sum(a) == x:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n", "passed": true, "time": 0.26, "memory": 14540.0, "status": "done"}, {"code": "# your code goes here\nsegment, length = map(int, input().split(' '))\nsegments = [int(x) for x in input().strip().split(' ')]\ntotal = sum(segments)\nif total + segment - 1 == length:\n\tprint(\"YES\")\nelse:\n\tprint (\"NO\")", "passed": true, "time": 0.16, "memory": 14440.0, "status": "done"}, {"code": "n,x = list(map(int,input().split()))\narr = list(map(int,input().split()))\nif sum(arr)+(n-1)== x:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")\n", "passed": true, "time": 0.17, "memory": 14404.0, "status": "done"}]
[{"input": "2 4\n1 3\n", "output": "NO\n"}, {"input": "3 10\n3 3 2\n", "output": "YES\n"}, {"input": "2 10\n1 3\n", "output": "NO\n"}, {"input": "1 1\n1\n", "output": "YES\n"}, {"input": "1 10\n10\n", "output": "YES\n"}, {"input": "1 10000\n10000\n", "output": "YES\n"}, {"input": "10 1\n5 78 3 87 4 9 5 8 9 1235\n", "output": "NO\n"}, {"input": "3 12\n3 3 3\n", "output": "NO\n"}, {"input": "3 9\n2 2 2\n", "output": "NO\n"}, {"input": "2 5\n1 1\n", "output": "NO\n"}, {"input": "1 2\n1\n", "output": "NO\n"}, {"input": "3 13\n3 3 3\n", "output": "NO\n"}, {"input": "3 6\n1 1 1\n", "output": "NO\n"}, {"input": "1 6\n5\n", "output": "NO\n"}, {"input": "3 11\n3 3 2\n", "output": "NO\n"}, {"input": "2 6\n1 3\n", "output": "NO\n"}, {"input": "3 10\n2 2 2\n", "output": "NO\n"}, {"input": "3 8\n2 1 1\n", "output": "NO\n"}, {"input": "1 5\n2\n", "output": "NO\n"}, {"input": "1 3\n1\n", "output": "NO\n"}, {"input": "5 5\n1 1 1 1 1\n", "output": "NO\n"}, {"input": "2 10\n4 4\n", "output": "NO\n"}, {"input": "2 8\n2 3\n", "output": "NO\n"}, {"input": "2 4\n1 1\n", "output": "NO\n"}, {"input": "3 10\n1 2 4\n", "output": "NO\n"}, {"input": "3 10\n2 1 3\n", "output": "NO\n"}, {"input": "2 6\n1 2\n", "output": "NO\n"}, {"input": "3 4\n1 1 1\n", "output": "NO\n"}, {"input": "3 11\n1 2 4\n", "output": "NO\n"}, {"input": "3 12\n3 3 2\n", "output": "NO\n"}, {"input": "4 9\n1 1 1 1\n", "output": "NO\n"}, {"input": "1 10\n9\n", "output": "NO\n"}, {"input": "1 7\n5\n", "output": "NO\n"}, {"input": "2 5\n1 2\n", "output": "NO\n"}, {"input": "3 8\n1 1 2\n", "output": "NO\n"}, {"input": "3 7\n1 1 1\n", "output": "NO\n"}, {"input": "1 10\n1\n", "output": "NO\n"}, {"input": "3 10\n2 3 4\n", "output": "NO\n"}, {"input": "3 9\n1 2 3\n", "output": "NO\n"}, {"input": "3 9\n3 3 2\n", "output": "NO\n"}, {"input": "3 6\n3 3 2\n", "output": "NO\n"}, {"input": "1 1\n3\n", "output": "NO\n"}, {"input": "1 3\n2\n", "output": "NO\n"}, {"input": "3 10\n3 3 3\n", "output": "NO\n"}, {"input": "3 5\n1 1 1\n", "output": "YES\n"}, {"input": "2 1\n100 100\n", "output": "NO\n"}, {"input": "3 3\n3 3 3\n", "output": "NO\n"}, {"input": "4 17\n3 3 9 1\n", "output": "NO\n"}, {"input": "4 1660\n1505 13 37 100\n", "output": "NO\n"}, {"input": "3 5\n3 3 2\n", "output": "NO\n"}, {"input": "4 10\n3 3 2 5\n", "output": "NO\n"}, {"input": "5 5\n5 5 5 5 5\n", "output": "NO\n"}, {"input": "1 1\n2\n", "output": "NO\n"}, {"input": "5 10\n1 2 2 4 5\n", "output": "NO\n"}, {"input": "2 1\n1 1\n", "output": "NO\n"}]
366
You have unlimited number of coins with values $1, 2, \ldots, n$. You want to select some set of coins having the total value of $S$. It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to get sum $S$? -----Input----- The only line of the input contains two integers $n$ and $S$ ($1 \le n \le 100\,000$, $1 \le S \le 10^9$) -----Output----- Print exactly one integerΒ β€” the minimum number of coins required to obtain sum $S$. -----Examples----- Input 5 11 Output 3 Input 6 16 Output 3 -----Note----- In the first example, some of the possible ways to get sum $11$ with $3$ coins are: $(3, 4, 4)$ $(2, 4, 5)$ $(1, 5, 5)$ $(3, 3, 5)$ It is impossible to get sum $11$ with less than $3$ coins. In the second example, some of the possible ways to get sum $16$ with $3$ coins are: $(5, 5, 6)$ $(4, 6, 6)$ It is impossible to get sum $16$ with less than $3$ coins.
interview
[{"code": "from sys import stdin, stdout\nfrom math import sin, tan, cos, pi, atan2, sqrt, acos, atan, factorial\n\nn, s = map(int, stdin.readline().split())\nstdout.write(str((s + n - 1) // n))", "passed": true, "time": 0.14, "memory": 14504.0, "status": "done"}]
[{"input": "5 11\n", "output": "3"}, {"input": "6 16\n", "output": "3"}, {"input": "14 28\n", "output": "2"}, {"input": "5 29\n", "output": "6"}, {"input": "10 24\n", "output": "3"}, {"input": "1 30\n", "output": "30"}, {"input": "14969 66991573\n", "output": "4476"}, {"input": "1 1000000000\n", "output": "1000000000"}, {"input": "100000 1\n", "output": "1"}, {"input": "10 46\n", "output": "5"}, {"input": "11 35\n", "output": "4"}, {"input": "12 45\n", "output": "4"}, {"input": "15 34\n", "output": "3"}, {"input": "31859 629091638\n", "output": "19747"}, {"input": "15666 689919612\n", "output": "44040"}, {"input": "90681 254480989\n", "output": "2807"}, {"input": "69018 523197828\n", "output": "7581"}, {"input": "1352 434805201\n", "output": "321602"}, {"input": "73439 384841883\n", "output": "5241"}, {"input": "42482 352232377\n", "output": "8292"}, {"input": "57862 374476819\n", "output": "6472"}, {"input": "41711 440229650\n", "output": "10555"}, {"input": "46602 894472145\n", "output": "19194"}, {"input": "47832 942980453\n", "output": "19715"}, {"input": "22951 747845288\n", "output": "32585"}, {"input": "76998 722886555\n", "output": "9389"}, {"input": "68666 512525633\n", "output": "7465"}, {"input": "66269 356663481\n", "output": "5383"}, {"input": "56624 922065652\n", "output": "16285"}, {"input": "31618 26008350\n", "output": "823"}, {"input": "90952 904040054\n", "output": "9940"}, {"input": "49630 947487392\n", "output": "19092"}, {"input": "45084 431878651\n", "output": "9580"}, {"input": "7156 806580442\n", "output": "112714"}, {"input": "2 193379347\n", "output": "96689674"}, {"input": "6 823813339\n", "output": "137302224"}, {"input": "5 939845324\n", "output": "187969065"}, {"input": "7 236413222\n", "output": "33773318"}, {"input": "10 695784696\n", "output": "69578470"}, {"input": "3 877026418\n", "output": "292342140"}, {"input": "8 550991517\n", "output": "68873940"}, {"input": "6 899779610\n", "output": "149963269"}, {"input": "12 394018478\n", "output": "32834874"}, {"input": "66 63576176\n", "output": "963276"}, {"input": "66 982670621\n", "output": "14888949"}, {"input": "8 750191967\n", "output": "93773996"}, {"input": "10 349992600\n", "output": "34999260"}, {"input": "65 281828001\n", "output": "4335816"}, {"input": "53 468285594\n", "output": "8835578"}, {"input": "83 361125900\n", "output": "4350915"}, {"input": "15 191203328\n", "output": "12746889"}, {"input": "100000 1000000000\n", "output": "10000"}, {"input": "2 999999999\n", "output": "500000000"}, {"input": "2 1000000000\n", "output": "500000000"}, {"input": "4821 917142246\n", "output": "190240"}]
367
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not. You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes. You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically. -----Input----- The only line contains string s (1 ≀ |s| ≀ 2Β·10^5) consisting of only lowercase Latin letters. -----Output----- Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes. -----Examples----- Input aabc Output abba Input aabcd Output abcba
interview
[{"code": "#!/usr/bin/env python3\n\nfrom collections import Counter, OrderedDict\n\ntry:\n while True:\n s = input()\n count = [0] * 26\n for c in s:\n count[ord(c) - 97] += 1\n odds = [ ]\n for i, x in enumerate(count):\n if x & 0x1:\n odds.append(i)\n j = 0\n for i, x in zip(range(25, -1, -1), reversed(count)):\n if x & 0x1:\n if i == odds[j]:\n break\n count[odds[j]] += 1\n count[i] -= 1\n j += 1\n a = [ ]\n b = [ ]\n c = \"\"\n for i, x in enumerate(count):\n if x & 0x1:\n assert not c\n c = chr(i + 97)\n if x > 1:\n t = chr(i + 97) * (x >> 1)\n a.append(t)\n b.append(t)\n print(\"\".join(a), \"\".join(reversed(b)), sep=c)\n\nexcept EOFError:\n pass\n", "passed": true, "time": 0.16, "memory": 14364.0, "status": "done"}, {"code": "key = ''\n\nok = []\nodd = []\nx = list(input())\nd = {}\n\nfor i in 'abcdefghijklmnopqrstuvwxyz':\n d[i] = 0\n\nfor i in x:\n d[i] += 1\n\nfor i in 'abcdefghijklmnopqrstuvwxyz':\n if d[i]%2==1:\n odd.append(i)\nodd.sort()\nm = len(odd)//2\nfor i in range(len(odd[m:])):\n d[odd[i]] += 1\n d[odd[m:][i]] -= 1\nfor i in 'abcdefghijklmnopqrstuvwxyz':\n if d[i] % 2 == 1:\n key = i\n\ns = ''\nfor i in 'abcdefghijklmnopqrstuvwxyz':\n s += (i * (d[i]//2))\n\nprint(s+key+s[::-1])\n", "passed": true, "time": 0.14, "memory": 14532.0, "status": "done"}, {"code": "from collections import deque\n\ndef constructString( counts ):\n\n s = \"\"\n midLetter = \"\"\n for i , count in enumerate( counts ):\n if count > 0:\n letter = chr( ord('a') + i )\n if count % 2 == 1:\n midLetter = letter\n s += letter * ( count//2 )\n\n rs = s[::-1]\n\n return s + midLetter + rs\n\ndef __starting_point():\n\n counts = [0]*26\n\n s = input().strip()\n n = len(s)\n for c in s:\n counts[ord(c)-ord('a')] += 1\n\n maxOddNum = n%2\n curOddNum = 0\n needChangeLetters = deque()\n for i , count in enumerate(counts):\n if count%2 == 1:\n needChangeLetters.append( i )\n\n #print( needChangeLetters )\n while len(needChangeLetters) >= 2:\n preIndex = needChangeLetters.popleft()\n postIndex = needChangeLetters.pop()\n counts[preIndex] += 1\n counts[postIndex] -= 1\n\n print( constructString( counts ) )\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14524.0, "status": "done"}, {"code": "s=input();\nalph=[0 for x in range (0,26)];\nfor i in s:\n\talph[ord(i)-ord('a')]=alph[ord(i)-ord('a')]+1;\nfor i in range (25,-1,-1):\n\tif (alph[i]%2!=0):\n\t\tfor j in range (0,26):\n\t\t\tif (alph[j]%2!=0):\n\t\t\t\talph[i]=alph[i]-1;\n\t\t\t\talph[j]=alph[j]+1;\n\t\t\t\tbreak;\nr=\"\";\nfor i in range (0,26):\n\twhile(alph[i]>1):\n\t\tr=r+chr(ord('a')+i);\n\t\talph[i]=alph[i]-2;\ns=r;\nfor i in range (0,26):\n\tif (alph[i]!=0):\n\t\tr=r+chr(ord('a')+i);\n\t\t\nprint((r+s[::-1]));\n", "passed": true, "time": 0.15, "memory": 14532.0, "status": "done"}, {"code": "x = \"abcdefghijklmnopqrstuvwxyz\"\nd = dict.fromkeys(x, 0)\ns = input()\nfor i in s:\n d[i] += 1\ncount = 0\nfor i in x:\n if d[i] % 2:\n count += 1\nif len(s) % 2:\n count -= 1\ni = len(x) - 1\nwhile count > 0:\n if d[x[i]] % 2:\n j = 0\n while not (d[x[j]] % 2):\n j += 1\n d[x[j]] += 1\n d[x[i]] -= 1\n count -= 2\n i -= 1\ns = \"\"\nflag = \"\"\nfor i in x:\n if d[i] % 2:\n flag = i\n s += i * (d[i] // 2)\nprint(s, flag, s[-1::-1], sep = \"\")\n \n", "passed": true, "time": 0.14, "memory": 14200.0, "status": "done"}, {"code": "def palindrome(s):\n\tchars = [0]*26\n\tL = len(s)\n\tisOdd = (L%2 != 0)\n\t# populate chars\n\tfor c in s:\n\t\tn = ord(c) - 97\n\t\tchars[n] += 1\n\t# permutations\n\t\n\tleft = 0\n\tright = 25\n\twhile left < right:\n\t\twhile left < 25 and chars[left]%2 == 0:\n\t\t\tleft += 1\n\t\twhile right > 0 and chars[right]%2 == 0:\n\t\t\tright -= 1\n\t\tif left < 25 and right > 0:\n\t\t\tif left == right and isOdd:\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tchars[left] += 1\n\t\t\t\tchars[right] -= 1\n\n\t# build result\n\tresult = [' ']*L\n\tindex = 0\n\toddC = \"\"\n\tfor j in range(26):\n\t\tn = chars[j]\n\t\tif n > 0:\n\t\t\tif n%2 != 0:\n\t\t\t\toddC = chr(j+97)\n\t\t\tfor k in range(n//2):\n\t\t\t\tresult[index] = chr(j+97)\n\t\t\t\tresult[L - 1 - index] = chr(j+97)\n\t\t\t\tindex += 1\n\n\tif isOdd:\n\t\tresult[L//2] = oddC\n\n\treturn ''.join(result)\n\n\ndef __starting_point():\n\ts = input()\n\tresult = palindrome(s)\n\tprint(result)\n__starting_point()", "passed": true, "time": 0.15, "memory": 14464.0, "status": "done"}, {"code": "s = input()\na = [0] * 26\nfor c in s:\n a[ord(c)-ord('a')] += 1\nx = 0\ny = 25\nwhile x < y:\n while x < y and a[x] % 2 == 0:\n x += 1\n while x < y and a[y] % 2 == 0:\n y -= 1\n if x < y:\n a[x] += 1\n a[y] -= 1\n x += 1\n y -= 1\nr = ''\nmiddle = ''\nfor i in range(26):\n c = str(chr(i + ord('a')))\n r += c * (a[i] // 2)\n if a[i] % 2 == 1:\n middle = c\nprint(r + middle + r[::-1])\n\n \n", "passed": true, "time": 0.16, "memory": 14284.0, "status": "done"}, {"code": "s=input()\na=[int(i) for i in '0'*26]\nk=-1\nfor i in s:\n a[ord(i)-97]+=1\nfor i in range(25):\n if a[i]%2!=0:\n for j in range(25-i):\n if a[25-j]%2!=0:\n a[i]+=1\n a[25-j]-=1\n break\n if a[i]%2!=0:\n k=i\n break\nst=''\nfor i in range(26):\n if a[i]>0:\n st+=chr(i+97)*(a[i]//2)\nif k!=-1:\n st=st+chr(k+97)+st[::-1]\nelse:\n st=st+st[::-1]\nprint(st)", "passed": true, "time": 0.15, "memory": 14544.0, "status": "done"}, {"code": "\"\"\"\nCodeforces Educational Round 2\n\nProblem 600 C. Make Palindrome\n\n@author yamaton\n@date 2015-11-30\n\"\"\"\n\nimport collections\n\n\ndef solve(s):\n n = len(s)\n chars = collections.Counter(s)\n base = sorted(c for c in chars if chars[c] >= 2 for _ in range(chars[c] // 2))\n chars_odd = sorted(c for c in chars if chars[c] % 2 == 1)\n\n if n % 2 == 0:\n keep = len(chars_odd) // 2\n chars_selected = sorted(base + chars_odd[:keep])\n return chars_selected + chars_selected[::-1]\n else:\n keep = len(chars_odd) // 2\n chars_selected = sorted(base + chars_odd[:keep])\n middle = chars_odd[keep]\n return chars_selected + [middle] + chars_selected[::-1]\n\n\ndef main():\n s = input().strip()\n result = solve(s)\n print(''.join(result))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.25, "memory": 14280.0, "status": "done"}, {"code": "from queue import Queue\nimport sys\n\ndef __starting_point():\n\n s = input()\n h = set()\n res = []\n for x in s:\n if x in h:\n h -= {x}\n res.append(x)\n else:\n h |= {x}\n odd = sorted(list(h))\n for i in range(0, (len(odd))//2):\n res.append(odd[i])\n if len(odd) % 2 == 1:\n mid = odd[len(odd)//2]\n else:\n mid = \"\"\n res.sort()\n ans = \"\".join(res) + mid + \"\".join(res[::-1])\n print(ans)\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14324.0, "status": "done"}, {"code": "s = input()\nalphabets = [chr(x) for x in range(ord('a'), ord('z')+1)]\na = {}\n\nfor i in alphabets:\n a[i] = 0\n\nfor c in s:\n a[c] += 1\n\ne = None\nodds = [j for j in alphabets if a[j]%2==1]\nk = len(odds)//2\n\nif len(odds) % 2 == 1:\n e = odds[k]\n odds.remove(odds[k])\n\nfor j in odds[:k]:\n a[j] += 1\nfor j in odds[k:]:\n a[j] -= 1\n\nv = []\nfor i in alphabets:\n if a[i] % 2 == 1:\n v.append(i * (a[i]//2))\n else:\n v.append(i * (a[i] // 2))\n\nz = ''.join(v) + (e if e is not None else '')\nv.reverse()\nz += ''.join(v)\nprint(z)\n\n", "passed": true, "time": 0.14, "memory": 14352.0, "status": "done"}, {"code": "import math\ns1=input()\ns1=''.join(sorted(s1))\nnen=0\np=\"\"\nnp=\"\"\not=\"\"\no=\"\"\ni=0\no1=[]\nwhile i<len(s1):\n if i==len(s1)-1:\n np=np+s1[i]\n elif s1[i]==s1[i+1]:\n p=p+s1[i]\n i=i+1\n else:\n np=np+s1[i]\n i=i+1\nd=math.ceil(len(s1)/2)\nif len(s1)%2==0:\n ot=ot+p\n for i in range(0,int(len(s1)/2)-len(p)):\n ot=ot+np[i]\n ot=''.join(sorted(ot)) \nelse:\n ot=ot+p\n for i in range(0,int(math.ceil(len(s1)/2))-1-len(p)):\n ot=ot+np[i]\n nen=i+1\n ot=''.join(sorted(ot)) \n ot=ot+np[nen] \n \nfor i in range(0, d):\n o=o+ot[i]\nif len(s1)%2==0:\n for i in range(0,d):\n o1.append(ot[d-i-1])\nelse:\n for i in range(0,d-1):\n o1.append(ot[d-i-2])\n#for i in range(0, d-1):\n# o1.append(ot[d-i-1])\n#print(p)\n#print(np)\n#print(ot)\n#print(ot)\n#print(o)\n#print(o1)\nprint(o+''.join(o1))\n", "passed": true, "time": 0.24, "memory": 14540.0, "status": "done"}, {"code": "s = input()\ncnt = [0] * 256\nfor i in s:\n cnt[ord(i)] += 1\ni = ord('a')\nj = ord('z')\nwhile i < j:\n while i < j and cnt[i] % 2 == 0:\n i += 1\n while i < j and cnt[j] % 2 == 0:\n j -= 1\n if i < j:\n cnt[i] += 1\n cnt[j] -= 1\n i += 1\n j -= 1\nres1 = ''\nres2 = ''\nc = ''\nfor i in range(ord('a'), ord('z') + 1):\n res1 = res1 + chr(i) * (cnt[i] // 2)\n res2 = chr(i) * (cnt[i] // 2) + res2\n if cnt[i] % 2 == 1:\n c = chr(i)\nprint(res1 + c + res2)", "passed": true, "time": 0.89, "memory": 14412.0, "status": "done"}, {"code": "# List of lowercase letters.\nletters = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z')\n\n# Constructs the alphabetically smallest palindrome based on letter frequencies for a palindrome.\ndef getPalindrome(counts):\n returnString = \"\"\n\n for i in range(len(counts)):\n if counts[i] >= 2:\n for j in range(counts[i] // 2):\n counts[i] -= 2\n returnString += letters[i]\n\n for i in range(len(counts)):\n if counts.count(0) == 26:\n return (returnString + returnString[::-1])\n elif counts[i] == 1 and counts.count(0) == 25:\n return (returnString + letters[i] + returnString[::-1])\n\n# Changes the counts of each letter in preparation for constructing a palindrome.\ndef changeCounts(counts):\n allEven = True\n\n for i in counts:\n if i % 2 == 1:\n allEven = False\n\n if allEven == True:\n return counts\n else:\n for i in range(len(counts)):\n if counts[25 - i] % 2 == 1:\n for j in range(len(counts)):\n if j == 25 - i:\n return counts\n elif counts[j] % 2 == 1:\n counts[j] += 1\n counts[25 - i] -= 1\n break\n return counts\n\ninputArg = list(input())\n\ncounts = []\n\nfor i in letters:\n counts.append(inputArg.count(i))\n\ncounts = changeCounts(counts)\nprint(getPalindrome(counts))", "passed": true, "time": 0.15, "memory": 14592.0, "status": "done"}, {"code": "st=input()\narr=[0 for i in range(26)]\nch='a'\nfor i in range(26) :\n arr[i]=st.count(chr(i+ord('a')))\ni,j=0,25\nn=len(st)\nwhile i<26 and arr[i]%2==0:\n i+=1\nwhile j>0 and arr[j]%2==0 :\n j-=1\nwhile i<j:\n arr[i]=arr[i]+1\n arr[j]=arr[j]-1\n while i<26 and arr[i]%2==0 :\n i+=1\n while 0<j and arr[j]%2==0 :\n j-=1 \nr=''\nmiddle=''\n\nfor i in range(26):\n c=str(chr(i+97))\n r=r+ c*(arr[i]//2)\n if arr[i]%2==1:\n middle=c\nprint(r+middle+r[::-1]) ", "passed": true, "time": 0.25, "memory": 14444.0, "status": "done"}, {"code": "import string\ns = input()\nfreq = {x: 0 for x in string.ascii_lowercase}\nfor char in s:\n freq[char] += 1\nhead = 'a'\ntail = 'z'\nwhile head < tail:\n if freq[tail] % 2 == 0:\n tail = chr(ord(tail) - 1)\n if tail <= head:\n break\n if freq[head] % 2 == 0:\n head = chr(ord(head) + 1)\n if tail <= head:\n break\n if freq[head] % 2 != 0 and freq[tail] % 2 != 0:\n freq[head] += 1\n freq[tail] -= 1\nmiddle_letter = None\nif head == tail and freq[head] % 2 != 0:\n middle_letter = head\n freq[head] -= 1\noutput = \"\"\nfor x in string.ascii_lowercase:\n for i in range(freq[x] // 2):\n output += x\nif middle_letter:\n output += middle_letter + output[::-1]\nelse:\n output += output[::-1]\nprint(output)\n", "passed": true, "time": 0.15, "memory": 14540.0, "status": "done"}, {"code": "#!/usr/bin/env python3\n\ndef solve(s):\n cnt = dict()\n for c in s:\n if c not in cnt:\n cnt[c] = 0\n cnt[c] += 1\n\n num_odd = 0\n odds = []\n for k, v in list(cnt.items()):\n if v%2:\n num_odd += 1\n odds.append(k)\n odds.sort()\n for i in range(num_odd//2):\n cnt[odds[i]] += 1\n cnt[odds[-i-1]] -= 1\n if len(s)%2 == 0:\n return create_palin(cnt)\n else:\n return create_palin_odd(cnt)\n\ndef create_palin(cnt):\n total = sum(v for k, v in list(cnt.items()))\n p = [None]*total\n\n lo = 0\n hi = total-1\n for k, v in sorted(cnt.items()):\n while v > 0:\n p[lo] = k\n p[hi] = k\n lo += 1\n hi -= 1\n v -= 2\n return str.join('', p)\n\ndef create_palin_odd(cnt):\n total = sum(v for k, v in list(cnt.items()))\n odd = [k for k, v in list(cnt.items()) if v%2 == 1][0]\n p = []\n for k, v in sorted(cnt.items()):\n how = v//2\n p += [k]*(v//2)\n p = p + [odd] + list(reversed(p))\n return str.join('', p)\n\n\n\ndef __starting_point():\n s = input()\n print(solve(s))\n\n__starting_point()", "passed": true, "time": 0.15, "memory": 14556.0, "status": "done"}, {"code": "import string\n\ndef main():\n\ts = input()\n\tprint(makePalindrome(s))\n\ndef makePalindrome(s):\n\tletters = 26\n\tlCounts = [0] * letters\n\tfor c in s:\n\t\tlCounts[ord(c) - ord('a')] += 1\n\todds = [i for i in range(letters) if lCounts[i] % 2 != 0]\n\tif len(s) % 2 == 0:\n\t\tfor i in range(len(odds) // 2):\n\t\t\tlCounts[odds[i]] += 1\n\t\tfor i in range(len(odds) // 2, len(odds)):\n\t\t\tlCounts[odds[i]] -= 1\n\t\t#print(lCounts)\n\t\treturn countsToPalindrome(lCounts, 0)\n\telse:\n\t\tfor i in range(len(odds) // 2):\n\t\t\tlCounts[odds[i]] += 1\n\t\tfor i in range(len(odds) // 2 + 1, len(odds)):\n\t\t\tlCounts[odds[i]] -= 1\n\t\t#print(lCounts)\n\t\treturn countsToPalindrome(lCounts, 0)\n\ndef countsToPalindrome(L, i, middle = \"\"):\n\tif i == len(L):\n\t\treturn middle\n\telif L[i] % 2 == 0:\n\t\tletter = string.ascii_lowercase[i]\n\t\treturn (letter * (L[i] // 2)) + \\\n\t\tcountsToPalindrome(L, i + 1, middle) + \\\n\t\t(letter * (L[i] // 2))\n\telse:\n\t\tletter = string.ascii_lowercase[i]\n\t\treturn (letter * ((L[i] - 1) // 2)) + \\\n\t\tcountsToPalindrome(L, i + 1, letter) + \\\n\t\t(letter * ((L[i] - 1) // 2))\n\nmain()\n#print(makePalindrome(\"aaaabbbbccccddezlm\"))\n#print(makePalindrome(\"\"))\n", "passed": true, "time": 0.15, "memory": 14516.0, "status": "done"}, {"code": "from collections import defaultdict\n\ns = input()\nl = defaultdict(int)\nfor c in s:\n l[c] += 1\n\nu = sorted(list(filter(lambda x: l[x] % 2, l.keys())))\n\nfor i in range(0, int(len(u) / 2)):\n l[u[i]] += 1\n l[u[-i-1]] -= 1\n\nr = \"\"\nfor c in sorted(l.keys()):\n r += c * int(l[c] / 2)\n\nc = u[int(len(u) / 2)] if len(u) % 2 else \"\"\n\nprint(r + c + r[::-1])", "passed": true, "time": 0.14, "memory": 14364.0, "status": "done"}, {"code": "#CF 600C isprav\nq=input()\n#q='aabbcccdd'\n\nalfavitk=[0]*26\nalfavit='abcdefghijklmnopqrstuvwxyz'\n\nfor i in range(26):\n alfavitk[i]=q.count(alfavit[i])\n \nfirst=0\nlast=25\nwhile True:\n while alfavitk[first]%2==0 and first<last:\n first+=1\n while alfavitk[last]%2==0 and first<last:\n last-=1\n \n if first<last:\n alfavitk[first]+=1\n alfavitk[last]-=1\n first+=1\n last-=1\n else:\n break\n\n#print(alfavitk)\n#print(first)\n#print(last)\n\n\nif alfavitk[first]%2==1:\n res=alfavit[first]\n alfavitk[first]-=1\n \nelse:\n res=''\n\nfor i in range(25,-1,-1):\n if alfavitk[i]%2==1:\n res=alfavit[i]*()\n res=alfavit[i]*(alfavitk[i]//2)+res+alfavit[i]*(alfavitk[i]//2)\n \n \nprint(res)", "passed": true, "time": 0.14, "memory": 14524.0, "status": "done"}, {"code": "s = input()\nss = dict()\nfor c in s:\n ss[c] = ss.get(c, 0) + 1\nw = list(ss.keys())\nw.sort()\nwo = [a for a in w if ss[a] % 2 != 0]\nfor a, b in zip(wo[:len(wo)//2], wo[::-1][:len(wo)//2]):\n ss[a] += 1\n ss[b] -= 1\nsr = \"\".join([(ss[c] // 2)*c for c in w])\np = [c for c in w if ss[c] % 2 != 0]\nprint(sr + \"\".join(p) + sr[::-1])\n", "passed": true, "time": 0.15, "memory": 14300.0, "status": "done"}, {"code": "from bisect import insort\n\n# abcd\n# aabc\n# aaab aabb\n# aaaa\n\ndef main():\n wd = input()\n chars = dict()\n for c in wd:\n if c not in chars:\n chars[c] = 0\n chars[c] += 1\n odds = list()\n evens = list()\n\n for k, v in list(chars.items()):\n if v%2:\n odds.append((k,v))\n else:\n evens.append((k,v))\n\n odds.sort()\n #print(odds)\n while len(odds) > 1:\n odds[0] = (odds[0][0], odds[0][1]+1)\n odds[-1] = (odds[-1][0], odds[-1][1]-1)\n if odds[-1][1] < 1:\n del odds[-1]\n elif odds[-1][1]%2 == 0:\n evens.append(odds.pop())\n if odds[0][1]%2 == 0:\n evens.append(odds[0])\n del odds[0]\n\n if len(odds) and odds[0][1] > 1:\n evens.append((odds[0][0], odds[0][1]-1))\n odds[0] = (odds[0][0], 1)\n\n evens.sort()\n #print(odds,'\\n', evens)\n\n p = list()\n for x, c in evens:\n for k in range(c//2):\n p.append(x)\n\n if len(odds):\n print(''.join(p + [odds[0][0] for _ in range(odds[0][1])] + p[::-1]))\n else:\n print(''.join(p + p[::-1]))\n\n\ndef __starting_point():\n main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14432.0, "status": "done"}]
[{"input": "aabc\n", "output": "abba\n"}, {"input": "aabcd\n", "output": "abcba\n"}, {"input": "u\n", "output": "u\n"}, {"input": "ttttt\n", "output": "ttttt\n"}, {"input": "xxxvvvxxvv\n", "output": "vvvxxxxvvv\n"}, {"input": "wrwrwfrrfrffrrwwwffffwrfrrwfrrfrwwfwfrwfwfwffwrrwfrrrwwwfrrrwfrrfwrwwrwrrrffffwrrrwrwfffwrffrwwwrwww\n", "output": "fffffffffffffffrrrrrrrrrrrrrrrrrrwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrrrrrrrrrrrrrrrrrrfffffffffffffff\n"}, {"input": "aabbcccdd\n", "output": "abcdcdcba\n"}, {"input": "baaab\n", "output": "ababa\n"}, {"input": "aaabbbhhlhlugkjgckj\n", "output": "aabbghjklclkjhgbbaa\n"}, {"input": "aabcc\n", "output": "acbca\n"}, {"input": "bbbcccddd\n", "output": "bbcdcdcbb\n"}, {"input": "zzzozzozozozoza\n", "output": "aoozzzzozzzzooa\n"}, {"input": "aaabb\n", "output": "ababa\n"}, {"input": "zza\n", "output": "zaz\n"}, {"input": "azzzbbb\n", "output": "abzbzba\n"}, {"input": "bbaaccddc\n", "output": "abcdcdcba\n"}, {"input": "aaabbbccc\n", "output": "aabcbcbaa\n"}, {"input": "aaaaabbccdd\n", "output": "aabcdadcbaa\n"}, {"input": "aaabbbcccdd\n", "output": "aabcdbdcbaa\n"}, {"input": "aaaabbcccccdd\n", "output": "aabccdcdccbaa\n"}, {"input": "aaacccb\n", "output": "aacbcaa\n"}, {"input": "abcd\n", "output": "abba\n"}, {"input": "abb\n", "output": "bab\n"}, {"input": "abababccc\n", "output": "aabcbcbaa\n"}, {"input": "aaadd\n", "output": "adada\n"}, {"input": "qqqqaaaccdd\n", "output": "acdqqaqqdca\n"}, {"input": "affawwzzw\n", "output": "afwzwzwfa\n"}, {"input": "hack\n", "output": "acca\n"}, {"input": "bbaaa\n", "output": "ababa\n"}, {"input": "ababa\n", "output": "ababa\n"}, {"input": "aaazzzz\n", "output": "azzazza\n"}, {"input": "aabbbcc\n", "output": "abcbcba\n"}, {"input": "successfullhack\n", "output": "accelsufuslecca\n"}, {"input": "aaabbccdd\n", "output": "abcdadcba\n"}, {"input": "zaz\n", "output": "zaz\n"}, {"input": "aaabbbcccdddeee\n", "output": "aabbcdecedcbbaa\n"}, {"input": "zaaz\n", "output": "azza\n"}, {"input": "acc\n", "output": "cac\n"}, {"input": "abbbzzz\n", "output": "abzbzba\n"}, {"input": "zzzzazazazazazznnznznnznnznznzaajzjajjjjanaznnzanzppnzpaznnpanz\n", "output": "aaaaaaajjjnnnnnnnnppzzzzzzzzzzznzzzzzzzzzzzppnnnnnnnnjjjaaaaaaa\n"}, {"input": "aaaaabbbcccdddd\n", "output": "aaabcddbddcbaaa\n"}, {"input": "aaaaabbccdddd\n", "output": "aabcddaddcbaa\n"}, {"input": "abababa\n", "output": "aabbbaa\n"}, {"input": "azz\n", "output": "zaz\n"}, {"input": "abbbccc\n", "output": "abcbcba\n"}, {"input": "aaacccddd\n", "output": "aacdcdcaa\n"}, {"input": "asbbsha\n", "output": "abshsba\n"}, {"input": "bababab\n", "output": "abbabba\n"}, {"input": "aaabbccddbbccddaaaaaaaaaaaaaaaa\n", "output": "aaaaaaaaabbccddaddccbbaaaaaaaaa\n"}, {"input": "aaabbccddbbccddaaaaaaaaaaaaaa\n", "output": "aaaaaaaabbccddaddccbbaaaaaaaa\n"}, {"input": "aaabbccddbbccddaaaaaaaaaaaa\n", "output": "aaaaaaabbccddaddccbbaaaaaaa\n"}, {"input": "ooooo\n", "output": "ooooo\n"}, {"input": "aaabbccddbbccddaaaaaaaaaa\n", "output": "aaaaaabbccddaddccbbaaaaaa\n"}, {"input": "aaabbccddbbccddaaaaaaaa\n", "output": "aaaaabbccddaddccbbaaaaa\n"}, {"input": "aaabbccddbbccddaa\n", "output": "aabbccddaddccbbaa\n"}]
368
A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger. For each chess piece we know its weight: the queen's weight is 9, the rook's weight is 5, the bishop's weight is 3, the knight's weight is 3, the pawn's weight is 1, the king's weight isn't considered in evaluating position. The player's weight equals to the sum of weights of all his pieces on the board. As A doesn't like counting, he asked you to help him determine which player has the larger position weight. -----Input----- The input contains eight lines, eight characters each β€” the board's description. The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters. The white pieces are denoted as follows: the queen is represented is 'Q', the rook β€” as 'R', the bishop β€” as'B', the knight β€” as 'N', the pawn β€” as 'P', the king β€” as 'K'. The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively. An empty square of the board is marked as '.' (a dot). It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on. -----Output----- Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal. -----Examples----- Input ...QK... ........ ........ ........ ........ ........ ........ ...rk... Output White Input rnbqkbnr pppppppp ........ ........ ........ ........ PPPPPPPP RNBQKBNR Output Draw Input rppppppr ...k.... ........ ........ ........ ........ K...Q... ........ Output Black -----Note----- In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5. In the second test sample the weights of the positions of the black and the white pieces are equal to 39. In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.
interview
[{"code": "a = 0\nb = 0\nx = {'Q': 9, 'q':9, 'R':5, 'r':5, 'B':3, 'b':3, 'N':3, 'n':3, 'P': 1, 'p': 1}\nfor i in range(8):\n t = [i for i in input()]\n for i in t:\n if ord(i) >= 97 and i in x:\n a += x[i]\n elif i in x:\n b += x[i]\nif a == b:\n print(\"Draw\")\nelif a < b:\n print(\"White\")\nelse:\n print(\"Black\")", "passed": true, "time": 0.25, "memory": 14416.0, "status": "done"}, {"code": "A = [''] * 8\nb = 0\nw = 0\ndef count(v):\n nonlocal w, b\n if v == 'Q':\n w += 9\n elif v == 'R':\n w += 5\n elif v == 'B':\n w += 3\n elif v == 'N':\n w += 3\n elif v == 'P':\n w += 1\n elif v == 'q':\n b += 9\n elif v == 'r':\n b += 5\n elif v == 'b':\n b += 3\n elif v == 'n':\n b += 3\n elif v == 'p':\n b += 1\nfor i in range(8):\n A[i] = input()\n for j in range(8):\n count(A[i][j])\nif b > w:\n print(\"Black\")\nelif b == w:\n print(\"Draw\")\nelse:\n print(\"White\")\n", "passed": true, "time": 0.16, "memory": 14560.0, "status": "done"}, {"code": "board = list(input()+input()+input()+input()+input()+input()+input()+input())\nw = 0\nb = 0\nw += 9*board.count('Q')\nw += 5*board.count('R')\nw += 3*board.count('N')\nw += 3*board.count('B')\nw += board.count('P')\n\nb += 9*board.count('q')\nb += 5*board.count('r')\nb += 3*board.count('n')\nb += 3*board.count('b')\nb += board.count('p')\n\nif w > b:\n print(\"White\")\n\nelif w == b:\n print(\"Draw\")\n\nelse:\n print(\"Black\")\n", "passed": true, "time": 0.95, "memory": 14400.0, "status": "done"}, {"code": "S = dict()\nS['Q'] = 9\nS['R'] = 5\nS['B'] = 3\nS['N'] = 3\nS['P'] = 1\nS['K'] = 0\nS['q'] = -9\nS['r'] = -5\nS['b'] = -3\nS['n'] = -3\nS['p'] = -1\nS['k'] = 0\n\nscore = 0\nfor i in range(8) :\n x = input()\n for j in x :\n if j in S :\n score += S[j]\n\nif score > 0 :\n print(\"White\")\nelif score == 0 :\n print(\"Draw\")\nelse :\n print(\"Black\")\n", "passed": true, "time": 0.95, "memory": 14508.0, "status": "done"}, {"code": "w = 0\nb = 0\nfor i in range(8):\n st = input()\n for j in st:\n if j == 'Q':\n w+=9\n if j == 'R':\n w+=5 \n if j == 'B':\n w+=3 \n if j == 'N':\n w+=3 \n if j == 'P':\n w+=1 \n if j == 'q':\n b+=9\n if j == 'r':\n b+=5 \n if j == 'b':\n b+=3 \n if j == 'n':\n b+=3 \n if j == 'p':\n b+=1 \nif w > b:\n print('White')\nelif w < b:\n print('Black')\nelse:\n print('Draw')\n", "passed": true, "time": 0.15, "memory": 14440.0, "status": "done"}, {"code": "desc = []\nfor i in range (8):\n input_str = input()\n desc.append(input_str)\nw, b = 0, 0\n\"\"\" \u0432\u0435\u0441 \u0444\u0435\u0440\u0437\u044f \u0440\u0430\u0432\u0435\u043d 9,\n\u0432\u0435\u0441 \u043b\u0430\u0434\u044c\u0438 \u0440\u0430\u0432\u0435\u043d 5,\n\u0432\u0435\u0441 \u0441\u043b\u043e\u043d\u0430 \u0440\u0430\u0432\u0435\u043d 3,\n\u0432\u0435\u0441 \u043a\u043e\u043d\u044f \u0440\u0430\u0432\u0435\u043d 3,\n\u0432\u0435\u0441 \u043f\u0435\u0448\u043a\u0438 \u0440\u0430\u0432\u0435\u043d 1, \"\"\"\nfor i in range (8):\n for j in range(8):\n if desc[i][j]=='Q':\n w += 9\n elif desc[i][j]=='q':\n b += 9\n elif desc[i][j]=='R':\n w += 5\n elif desc[i][j]=='r':\n b += 5\n elif desc[i][j]=='B':\n w += 3\n elif desc[i][j]=='b':\n b += 3\n elif desc[i][j]=='N':\n w += 3\n elif desc[i][j]=='n':\n b += 3\n elif desc[i][j]=='P':\n w += 1\n elif desc[i][j]=='p':\n b += 1\n else:\n pass\nif w>b:\n print (\"White\")\nelif b>w:\n print (\"Black\")\nelse:\n print (\"Draw\")\n#\u0444\u0435\u0440\u0437\u044c \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u043c 'Q', \u043b\u0430\u0434\u044c\u044f \u2014 'R', \u0441\u043b\u043e\u043d \u2014 'B', \u043a\u043e\u043d\u044c \u2014 'N', \u043f\u0435\u0448\u043a\u0430 \u2014 'P', \u043a\u043e\u0440\u043e\u043b\u044c \u2014 'K'.\n", "passed": true, "time": 0.15, "memory": 14528.0, "status": "done"}, {"code": "desk = [list(input()) for i in range(8)]\nC = {'q' : 9, 'r' : 5, 'b' : 3, 'n' : 3, 'p' : 1, 'k' : 0, '.' : 0}\np1 = 0\np2 = 0\nfor x in desk:\n for x2 in x:\n if x2.isupper():\n p2 += C[x2.lower()]\n else:\n p1 += C[x2]\nif p1 == p2:\n print('Draw')\nelse:\n print('White' if p2 > p1 else 'Black')\n \n", "passed": true, "time": 0.15, "memory": 14452.0, "status": "done"}, {"code": "figures = {'q': 9, 'r': 5, 'b': 3, 'n': 3, 'p': 1, 'k': 0}\n\nblack_w, white_w = 0, 0\nfor _ in range(0, 8):\n row = input().strip()\n for c in row:\n if c.lower() in figures:\n if c.lower() == c:\n black_w += figures[c]\n else:\n white_w += figures[c.lower()]\n\nif black_w == white_w:\n print('Draw')\nelif black_w > white_w:\n print('Black')\nelse:\n print('White')", "passed": true, "time": 0.16, "memory": 14540.0, "status": "done"}, {"code": "p = {'K': 0, 'Q': 9, 'R': 5, 'B': 3, 'N': 3, 'P': 1, '.': 0}\nw = [0, 0]\nfor r in range(8):\n for ch in input():\n if ch != '.':\n w[ch.islower()] += p[ch.upper()]\nif w[0] == w[1]:\n print('Draw')\nelse:\n print('White' if w[0] > w[1] else 'Black')\n", "passed": true, "time": 0.25, "memory": 14296.0, "status": "done"}, {"code": "import sys\nread = lambda t=int: list(map(t,sys.stdin.readline().split()))\narray = lambda *ds: [array(*ds[1:]) for _ in range(ds[0])] if ds else 0\n\nval = {'q':9,'r':5,'b':3,'n':3,'p':1}\ns = ''.join(sys.stdin.readline() for _ in range(8))\nres = 0\nfor c in s:\n if c.islower():\n res += val.get(c, 0)\n else:\n res -= val.get(c.lower(), 0)\n\nif res == 0:\n print(\"Draw\")\nif res < 0:\n print(\"White\")\nif res > 0:\n print(\"Black\")\n", "passed": true, "time": 0.16, "memory": 14472.0, "status": "done"}, {"code": "def main():\n bw = [0, 0]\n for _ in range(8):\n for c in input():\n if c.isalpha():\n bw[c.isupper()] += {'Q': 9, 'R': 5, 'B': 3, 'N': 3, 'P': 1, 'K': 0}[c.upper()]\n if bw[0] < bw[1]:\n print(\"White\")\n elif bw[0] > bw[1]:\n print(\"Black\")\n else:\n print(\"Draw\")\n\n\ndef __starting_point():\n main()\n__starting_point()", "passed": true, "time": 0.15, "memory": 14284.0, "status": "done"}, {"code": "i=0\nl=''\nwhile i<8:\n l+=input()\n i+=1\nw=l.count('Q')*9+l.count('R')*5+l.count('B')*3+l.count('N')*3+l.count('P')\nb=l.count('q')*9+l.count('r')*5+l.count('b')*3+l.count('n')*3+l.count('p')\nif w>b:\n print('White')\nelif b>w:\n print('Black')\nelse:\n print('Draw')\n \n", "passed": true, "time": 0.15, "memory": 14420.0, "status": "done"}, {"code": "m = []\n\nf = {\n '.': 0,\n 'q': -9,\n 'r': -5,\n 'b': -3,\n 'n': -3,\n 'p': -1,\n 'k': 0,\n 'Q': 9,\n 'R': 5,\n 'B': 3,\n 'N': 3,\n 'P': 1,\n 'K': 0,\n}\n\nfor i in range(8):\n m.append(list(input()))\n\ncnt = 0\n\nfor s in m:\n for c in s:\n if c in f:\n cnt += f[c]\n\n\nif cnt > 0:\n print('White')\nelif cnt < 0:\n print('Black')\nelse:\n print('Draw')", "passed": true, "time": 0.14, "memory": 14432.0, "status": "done"}, {"code": "import sys\n# sys.stdin = open('in.txt')\nR = lambda: map(int, input().split())\n\nscore={'q':9, 'r':5, 'b':3, 'n':3, 'p':1, 'k':0,\n 'Q':-9,'R':-5,'B':-3,'N':-3,'P':-1,'K':0, '.':0}\n\nsum=0\nfor _ in range(8):\n for c in input():\n sum+=score[c]\n\nif sum==0:\n print(\"Draw\")\nelif sum>0:\n print(\"Black\")\nelse:\n print(\"White\")", "passed": true, "time": 0.14, "memory": 14448.0, "status": "done"}, {"code": "r = dict()\nsb = 0\nsw = 0\nr['Q'] = r['q'] = 9\nr['B'] = r['b'] = 3\nr['K'] = r['k'] = 0\nr['N'] = r['n'] = 3\nr['p'] = r['P'] = 1\nr['R'] = r['r'] = 5\n\ns1 = 'prqkbn'\ns2 = s1.upper()\n\nfor i in range(8):\n t = input()\n for k in t:\n if k in s1:\n sb += r[k]\n else:\n if k in s2:\n sw += r[k]\nif sw == sb:\n print('Draw')\nelif sw > sb:\n print('White')\nelse:\n print('Black')\n", "passed": true, "time": 0.14, "memory": 14452.0, "status": "done"}, {"code": "import sys\nw=0\nb=0\nfor i in range(8):\n n=list(sys.stdin.readline())\n for j in n:\n if j=='q':\n w=w+9\n if j=='Q':\n b=b+9\n if j=='r':\n w=w+5\n if j=='R':\n b=b+5\n if j=='b':\n w=w+3\n if j=='B':\n b=b+3\n if j=='n':\n w=w+3\n if j=='N':\n b=b+3\n if j=='p':\n w=w+1\n if j=='P':\n b=b+1\t \nif w<b: print(\"White\")\nelif w>b: print(\"Black\")\nelse: print(\"Draw\")", "passed": true, "time": 0.15, "memory": 14268.0, "status": "done"}, {"code": "w = 0\nb = 0\nfor j in range(8):\n c = input()\n for i in range(8):\n if c[i] == 'Q':\n w += 9\n if c[i] == 'R':\n w += 5\n if c[i] == 'B' or c[i] == 'N':\n w += 3\n if c[i] == 'P':\n w += 1\n if c[i] == 'q':\n b += 9\n if c[i] == 'r':\n b += 5\n if c[i] == 'b' or c[i] == 'n':\n b += 3\n if c[i] == 'p':\n b += 1\nif w > b:\n print('White')\nelif b != w:\n print('Black')\nelse:\n print('Draw')\n", "passed": true, "time": 0.16, "memory": 14240.0, "status": "done"}, {"code": "def black(a):\n m = 0\n for i in a:\n i = list(i)\n for ii in i:\n if ii == \"r\":\n m += 5\n if ii == \"q\":\n m += 9\n if ii == \"b\":\n m += 3\n if ii == \"n\":\n m += 3\n if ii == \"p\":\n m += 1\n if ii == \"k\":\n m += 0\n return m\ndef white(a):\n m = 0\n for i in a:\n i = list(i)\n for ii in i:\n if ii == \"R\":\n m += 5\n if ii == \"Q\":\n m += 9\n if ii == \"B\":\n m += 3\n if ii == \"N\":\n m += 3\n if ii == \"P\":\n m += 1\n if ii == \"K\":\n m += 0\n return m\n\nb = []\ni = 0\nwhile i<8:\n a = input()\n b.append(a)\n i+=1\nif white(b)>black(b):\n print(\"White\")\nif black(b)>white(b):\n print(\"Black\")\nif black(b)==white(b):\n print(\"Draw\")\n", "passed": true, "time": 0.14, "memory": 14456.0, "status": "done"}, {"code": "ws = dict(list(zip(\"qrbnp\", (9, 5, 3, 3, 1))))\nwhite = black = 0\nfor ch in [ch for ch in str.join(\"\", [input() for _ in range(8)]) if ch.lower() not in \".k\"]:\n\n if str.isupper(ch):\n\n white += ws[ch.lower()]\n\n else:\n\n black += ws[ch]\n\nif black > white:\n\n print(\"Black\")\n\nelif black < white:\n\n print(\"White\")\n\nelse:\n\n print(\"Draw\")\n", "passed": true, "time": 0.15, "memory": 14284.0, "status": "done"}, {"code": "s = [\"\"] * 8\nfor i in range(0,8):\n\ts[i] = input()\nwhite = {}\nblack = {}\nwhite['Q'] = 9\nwhite['R'] = 5\nwhite['B'] = 3\nwhite['N'] = 3\nwhite['P'] = 1\nwhite['q'] = 0\nwhite['r'] = 0\nwhite['b'] = 0\nwhite['n'] = 0\nwhite['p'] = 0\nwhite['.'] = 0\nwhite['K'] = 0\nwhite['k'] = 0\nblack['Q'] = 0\nblack['R'] = 0\nblack['B'] = 0\nblack['N'] = 0\nblack['P'] = 0\nblack['q'] = 9\nblack['r'] = 5\nblack['b'] = 3\nblack['n'] = 3\nblack['p'] = 1\nblack['.'] = 0\nblack['K'] = 0\nblack['k'] = 0\nw = 0\nb = 0\nfor i in range(0,8):\n\tfor j in range(0,8):\n\t\tw = w+white[s[i][j]]\n\t\tb = b+black[s[i][j]]\nif w>b:\n\tprint(\"White\")\nelif w<b:\n\tprint(\"Black\")\nelse:\n\tprint(\"Draw\")", "passed": true, "time": 0.14, "memory": 14436.0, "status": "done"}, {"code": "# sorry for the source code iam a newbie in Python\nchess = []\nfor i in range(8):\n chess.append(input())\ns = 'qrbnpk'\nw = [9,5,3,3,1,0]\nD = dict(list(zip(s,w)))\nD1 = dict(list(zip(s.upper(),w)))\ndic = dict.fromkeys(s,0)\ndic2 = dict.fromkeys(s.upper(),1)\ndic2.update(dic)\nres = [0,0]\nfor i in range(8):\n for j in range(8):\n if chess[i][j] != '.':\n res[dic2[chess[i][j]]] += D[chess[i][j].lower()]\nfirst = res[0]\nsec = res[1]\nif first > sec:\n print ('Black')\nelif first == sec:\n print ('Draw')\nelse:\n print ('White')\n", "passed": true, "time": 0.14, "memory": 14492.0, "status": "done"}, {"code": "__author__ = 'Krishna'\n\nvalues = {'q': 9, 'r': 5, 'b': 3, 'n': 3, 'p': 1, 'k': 0}\nwhiteStrength = 0\nblackStrength = 0\nfor i in range(8):\n for piece in input():\n if ord('a') <= ord(piece) <= ord('z'):\n blackStrength += values.get(piece)\n elif ord('A') <= ord(piece) <= ord('Z'):\n whiteStrength += values.get(piece.lower())\nif whiteStrength > blackStrength:\n print(\"White\")\nelif whiteStrength == blackStrength:\n print(\"Draw\")\nelse:\n print(\"Black\")\n", "passed": true, "time": 0.14, "memory": 14572.0, "status": "done"}, {"code": "u = 0\nv = 0\ndef f(c):\n nonlocal u\n nonlocal v\n if c == 'Q':\n u += 9\n elif c == 'R':\n u += 5\n elif c == 'B':\n u += 3\n elif c == 'N':\n u += 3\n elif c == 'P':\n u += 1\n elif c == 'q':\n v += 9\n elif c == 'r':\n v += 5\n elif c == 'b':\n v += 3\n elif c == 'n':\n v += 3\n elif c == 'p':\n v += 1\n\nfor i in range(8):\n for c in input():\n f(c)\n\nif u == v:\n print('Draw')\nelif u > v:\n print('White')\nelse:\n print('Black')\n\n\n", "passed": true, "time": 0.14, "memory": 14500.0, "status": "done"}, {"code": "import string\n\nwp, bp = 0, 0\nfor i in range(8):\n inStr = input()\n for p in list(inStr):\n if not p=='.':\n lp = p.lower()\n points = {'q':9, 'r':5, 'b':3, 'n':3, 'p':1, 'k':0}[lp]\n if not p.islower():\n wp = wp + points\n else:\n bp = bp + points\n\nwp > bp and print('White') or wp == bp and print('Draw') or wp < bp and print('Black')", "passed": true, "time": 0.15, "memory": 14520.0, "status": "done"}]
[{"input": "...QK...\n........\n........\n........\n........\n........\n........\n...rk...\n", "output": "White\n"}, {"input": "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR\n", "output": "Draw\n"}, {"input": "rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........\n", "output": "Black\n"}, {"input": "....bQ.K\n.B......\n.....P..\n........\n........\n........\n...N.P..\n.....R..\n", "output": "White\n"}, {"input": "b....p..\nR.......\n.pP...b.\npp......\nq.PPNpPR\n..K..rNn\nP.....p.\n...Q..B.\n", "output": "White\n"}, {"input": "...Nn...\n........\n........\n........\n.R....b.\n........\n........\n......p.\n", "output": "White\n"}, {"input": "...p..Kn\n.....Pq.\n.R.rN...\n...b.PPr\np....p.P\n...B....\np.b.....\n..N.....\n", "output": "Black\n"}, {"input": "q.......\nPPPPPPPP\n........\n........\n........\n........\n........\n........\n", "output": "Black\n"}, {"input": "q.......\nPPPPPPPP\nP.......\n........\n........\n........\n........\n........\n", "output": "Draw\n"}, {"input": "q.......\nPPPPPPPP\nPP......\n........\n........\n........\n........\n........\n", "output": "White\n"}, {"input": "r.......\nPPPP....\n........\n........\n........\n........\n........\n........\n", "output": "Black\n"}, {"input": "r.......\nPPPPP...\n........\n........\n........\n........\n........\n........\n", "output": "Draw\n"}, {"input": "r.......\nPPPPPP..\n........\n........\n........\n........\n........\n........\n", "output": "White\n"}, {"input": "b.......\nPP......\n........\n........\n........\n........\n........\n........\n", "output": "Black\n"}, {"input": "b.......\nPPP.....\n........\n........\n........\n........\n........\n........\n", "output": "Draw\n"}, {"input": "b.......\nPPPP....\n........\n........\n........\n........\n........\n........\n", "output": "White\n"}, {"input": "n.......\nPP......\n........\n........\n........\n........\n........\n........\n", "output": "Black\n"}, {"input": "n.......\nPPP.....\n........\n........\n........\n........\n........\n........\n", "output": "Draw\n"}, {"input": "n.......\nPPPP....\n........\n........\n........\n........\n........\n........\n", "output": "White\n"}, {"input": "Q.......\npppppppp\n........\n........\n........\n........\n........\n........\n", "output": "White\n"}, {"input": "Q.......\npppppppp\np.......\n........\n........\n........\n........\n........\n", "output": "Draw\n"}, {"input": "Q.......\npppppppp\npp......\n........\n........\n........\n........\n........\n", "output": "Black\n"}, {"input": "R.......\npppp....\n........\n........\n........\n........\n........\n........\n", "output": "White\n"}, {"input": "R.......\nppppp...\n........\n........\n........\n........\n........\n........\n", "output": "Draw\n"}, {"input": "R.......\npppppp..\n........\n........\n........\n........\n........\n........\n", "output": "Black\n"}, {"input": "B.......\npp......\n........\n........\n........\n........\n........\n........\n", "output": "White\n"}, {"input": "B.......\nppp.....\n........\n........\n........\n........\n........\n........\n", "output": "Draw\n"}, {"input": "B.......\npppp....\n........\n........\n........\n........\n........\n........\n", "output": "Black\n"}, {"input": "N.......\npp......\n........\n........\n........\n........\n........\n........\n", "output": "White\n"}, {"input": "N.......\nppp.....\n........\n........\n........\n........\n........\n........\n", "output": "Draw\n"}, {"input": "N.......\npppp....\n........\n........\n........\n........\n........\n........\n", "output": "Black\n"}, {"input": "qqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\n", "output": "Black\n"}, {"input": "QQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\n", "output": "White\n"}, {"input": "qqqqqqqq\nqqqqqqqq\nqqqqqqqq\nqqqqqqqq\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\nQQQQQQQQ\n", "output": "Draw\n"}, {"input": "..KQBN..\n........\n........\n....q...\n..p.....\n....k...\n........\n........\n", "output": "White\n"}, {"input": "..K....Q\n........\n....q...\n........\n........\n........\n........\n........\n", "output": "Draw\n"}, {"input": "KKKKKKK.\n........\n........\n........\n........\n........\n........\nq.......\n", "output": "Black\n"}, {"input": "QQQQQQQQ\nQQQQQQQQ\n........\n........\n........\n........\nrrrrrr..\nrrrrrrrr\n", "output": "White\n"}, {"input": "........\n........\n........\n........\n........\n........\n........\n........\n", "output": "Draw\n"}, {"input": "P.......\n........\n........\n........\n........\n........\n........\n........\n", "output": "White\n"}, {"input": "...b....\n...np...\n........\n........\n........\n...N....\n...B....\n...R....\n", "output": "White\n"}, {"input": "........\n........\n........\n........\n........\n........\nNN......\n........\n", "output": "White\n"}, {"input": "........\n........\n........\n........\n........\n........\n........\n.......n\n", "output": "Black\n"}, {"input": "n.......\nn.......\nn.......\nn.......\nn.......\nn.......\nn.......\nn.......\n", "output": "Black\n"}, {"input": "NNNNNNNN\nNNNNNNNN\nNNNNNNNN\nNNNNNNNN\nNNNNNNNN\nNNNNNNNN\nKk......\nq.......\n", "output": "White\n"}, {"input": "........\nNN......\n........\n........\n........\n........\n........\n........\n", "output": "White\n"}, {"input": "K.......\n........\n........\n........\n........\n........\n........\n........\n", "output": "Draw\n"}, {"input": "Q.......\nkkk.....\n........\n........\n........\n........\n........\n........\n", "output": "White\n"}, {"input": "Kn......\n........\n........\n........\n........\n........\n........\n........\n", "output": "Black\n"}, {"input": "........\n........\n........\n........\n........\n........\n........\nn.......\n", "output": "Black\n"}, {"input": "KKKKKKKK\npppppppp\n........\n........\n........\n........\n........\n........\n", "output": "Black\n"}, {"input": "........\n...b....\n........\n........\n........\n........\n........\n.......K\n", "output": "Black\n"}, {"input": "........\n........\n........\n........\n........\n........\n........\n......Kp\n", "output": "Black\n"}, {"input": "........\n........\n........\n........\n........\n........\n........\n.......Q\n", "output": "White\n"}, {"input": "........\n........\n........\n........\n........\n........\n........\n......Bp\n", "output": "White\n"}]
371
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible! Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous one. The value of k (k > 1) is a secret integer known only to them. It is also known that each thief's bag can carry at most n chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved. Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed n, but not fixed k) is m. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them. Mike want to track the thieves down, so he wants to know what their bags are and value of n will help him in that. Please find the smallest possible value of n or tell him that the rumors are false and there is no such n. -----Input----- The single line of input contains the integer m (1 ≀ m ≀ 10^15)Β β€” the number of ways the thieves might steal the chocolates, as rumours say. -----Output----- Print the only integer nΒ β€” the maximum amount of chocolates that thieves' bags can carry. If there are more than one n satisfying the rumors, print the smallest one. If there is no such n for a false-rumoured m, print - 1. -----Examples----- Input 1 Output 8 Input 8 Output 54 Input 10 Output -1 -----Note----- In the first sample case the smallest n that leads to exactly one way of stealing chocolates is n = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves). In the second sample case the smallest n that leads to exactly 8 ways is n = 54 with the possibilities: (1, 2, 4, 8),  (1, 3, 9, 27),  (2, 4, 8, 16),  (2, 6, 18, 54),  (3, 6, 12, 24),  (4, 8, 16, 32),  (5, 10, 20, 40),  (6, 12, 24, 48). There is no n leading to exactly 10 ways of stealing chocolates in the third sample case.
interview
[{"code": "SIZE = 171000\nL = [i ** 3 for i in range(SIZE)]\n\ndef get_count(n):\n MAX = int(n ** (1 / 3)) + 1\n if L[MAX] > n:\n MAX -= 1\n\n res = 0\n for i in range(2, MAX + 1):\n x = n // L[i]\n if x != 1:\n res += x\n else:\n res += MAX - i + 1\n break\n return res\n\ndef bin_search(m):\n beg = int(4.8 * m)\n end = min(8 * m, int(5e15))\n while beg <= end:\n mid = (beg + end) // 2\n count_mid = get_count(mid)\n if count_mid == m:\n if beg == end:\n return mid\n end = mid\n elif count_mid > m:\n end = mid - 1\n else:\n beg = mid + 1\n return -1\n\nm = int(input())\nprint(bin_search(m))\n", "passed": true, "time": 26.87, "memory": 22208.0, "status": "done"}, {"code": "def main():\n m = int(input())\n if m < 1000000:\n lo = m*4\n hi = m*8\n else:\n lo = int(4.949 * m)\n hi = int(4.9492 * m)\n while lo < hi - 1:\n mid = (lo + hi)//2\n nposs = countposs(mid)\n if nposs < m:\n lo = mid\n else:\n hi = mid\n if m == countposs(hi):\n print(hi)\n else:\n print(-1)\n\ndef countposs(maxtake):\n k = 2\n ans = 0\n while True:\n term = maxtake//(k*k*k)\n if term == 0:\n return ans\n ans += term\n k += 1\n\nmain()", "passed": true, "time": 29.89, "memory": 14348.0, "status": "done"}, {"code": "def main():\n m = int(input())\n lo = m*4\n hi = m*8\n loposs = countposs(lo)\n hiposs = countposs(hi)\n while lo < hi - 1:\n if hi - lo > 10000:\n mid = lo + int((m-loposs)/(hiposs-loposs)*(hi-lo))\n mid = max(lo + 1, min(hi - 1, mid))\n else:\n mid = (hi + lo)//2\n nposs = countposs(mid)\n if nposs < m:\n lo = mid\n else:\n hi = mid\n if m == countposs(hi):\n print(hi)\n else:\n print(-1)\n\ndef countposs(maxtake):\n k = 2\n ans = 0\n while True:\n term = maxtake//(k*k*k)\n if term == 0:\n return ans\n ans += term\n k += 1\n\nmain()", "passed": true, "time": 28.7, "memory": 14408.0, "status": "done"}, {"code": "t = [k ** 3 for k in range(2, 170417)]\ns = m = int(input())\na, b = 1, 9 * m\nwhile a < b:\n c = (a + b) // 2\n d = sum(int(c / k) for k in t)\n if d < m: a = c + 1\n else: s, b = d, c\nprint(a if s == m else -1)", "passed": true, "time": 34.49, "memory": 22060.0, "status": "done"}, {"code": "cubes = [i**3.0 for i in range(2, int(1.8e5+5))]\n\ndef valid(mid):\n return sum([mid//i for i in cubes if i <= mid])\n\ndef binary_search(k):\n l = int(4.8 * k)\n r = min(8.0 * k, 5.0 * (10**15))\n while (l+1 < r):\n mid = (l+r) / 2.0\n res = valid(mid)\n if (res < k):\n l = mid\n else:\n r = mid\n return int(r) if int(valid(r)) == k else -1\n\ndef main():\n k = int(input())\n print(binary_search(k))\n\nmain()\n", "passed": true, "time": 17.72, "memory": 27240.0, "status": "done"}, {"code": "import math\nfrom bisect import bisect_right, bisect_left\nfrom collections import Counter, defaultdict\nfrom heapq import heappop, heappush\nfrom itertools import accumulate\n\nR = lambda: map(int, input().split())\n\nt = int(input())\ntab = [x*x*x for x in range(2, 2*10**5)]\nl, r = 1, 5*10**15\nwhile l < r:\n n = (l + r) // 2\n s = sum(n // x for x in tab)\n if s < t:\n l = n + 1\n elif s > t:\n r = n - 1\n else:\n r = n\ns = sum(l // x for x in tab)\nif s != t:\n print(-1)\nelse:\n print(l)", "passed": true, "time": 40.32, "memory": 23892.0, "status": "done"}, {"code": "N = int(2e5)\nn = int(input()) \ncb = [x*x*x for x in range(2, N)]\n\ndef valid(m):\n return sum(m//i for i in cb) < n\n\ndef binary_search():\n l, r = 0, int(1e16)\n while l < r:\n m = (l+r) // 2\n if valid(m):\n l = m + 1\n else:\n r = m\n return l\n\nres = binary_search()\nprint(res if sum(res//i for i in cb) == n else -1)\n", "passed": true, "time": 42.42, "memory": 23816.0, "status": "done"}]
[{"input": "1\n", "output": "8\n"}, {"input": "8\n", "output": "54\n"}, {"input": "10\n", "output": "-1\n"}, {"input": "27\n", "output": "152\n"}, {"input": "28206\n", "output": "139840\n"}, {"input": "32\n", "output": "184\n"}, {"input": "115\n", "output": "608\n"}, {"input": "81258\n", "output": "402496\n"}, {"input": "116003\n", "output": "574506\n"}, {"input": "149344197\n", "output": "739123875\n"}, {"input": "57857854\n", "output": "286347520\n"}, {"input": "999999999999999\n", "output": "-1\n"}, {"input": "181023403153\n", "output": "895903132760\n"}, {"input": "196071196742\n", "output": "970376182648\n"}, {"input": "49729446417673\n", "output": "246116048009288\n"}, {"input": "14821870173923\n", "output": "73354931125416\n"}, {"input": "29031595887308\n", "output": "143680297402952\n"}, {"input": "195980601490039\n", "output": "969927770453672\n"}, {"input": "181076658641313\n", "output": "896166653569800\n"}, {"input": "166173583620704\n", "output": "822409831653228\n"}, {"input": "151269640772354\n", "output": "748648714769352\n"}, {"input": "136366565751970\n", "output": "674891892852776\n"}, {"input": "121463490731834\n", "output": "601135070936200\n"}, {"input": "106559547884220\n", "output": "527373954052328\n"}, {"input": "91656472864718\n", "output": "453617132135750\n"}, {"input": "184061307002930\n", "output": "910937979445720\n"}, {"input": "57857853\n", "output": "-1\n"}, {"input": "1000000000000000\n", "output": "4949100894494448\n"}, {"input": "375402146575334\n", "output": "-1\n"}, {"input": "550368702711851\n", "output": "-1\n"}, {"input": "645093839227897\n", "output": "-1\n"}, {"input": "431\n", "output": "-1\n"}, {"input": "99999\n", "output": "-1\n"}, {"input": "2\n", "output": "16\n"}, {"input": "3\n", "output": "24\n"}, {"input": "4\n", "output": "27\n"}, {"input": "5\n", "output": "32\n"}, {"input": "6\n", "output": "40\n"}, {"input": "7\n", "output": "48\n"}, {"input": "13\n", "output": "80\n"}, {"input": "999999999999998\n", "output": "-1\n"}, {"input": "999999999999997\n", "output": "4949100894494440\n"}, {"input": "999999999999996\n", "output": "4949100894494432\n"}, {"input": "999999999999995\n", "output": "4949100894494424\n"}, {"input": "999999999999993\n", "output": "4949100894494416\n"}, {"input": "999999999999991\n", "output": "4949100894494400\n"}, {"input": "999999999999992\n", "output": "4949100894494408\n"}, {"input": "999999999999994\n", "output": "4949100894494421\n"}, {"input": "4235246\n", "output": "-1\n"}, {"input": "34\n", "output": "-1\n"}, {"input": "998749999999991\n", "output": "4942914518376840\n"}, {"input": "999999874999991\n", "output": "4949100275856792\n"}, {"input": "987654129875642\n", "output": "4887999937625136\n"}, {"input": "237648237648000\n", "output": "1176145105832192\n"}]
373
Chouti was doing a competitive programming competition. However, after having all the problems accepted, he got bored and decided to invent some small games. He came up with the following game. The player has a positive integer $n$. Initially the value of $n$ equals to $v$ and the player is able to do the following operation as many times as the player want (possibly zero): choose a positive integer $x$ that $x<n$ and $x$ is not a divisor of $n$, then subtract $x$ from $n$. The goal of the player is to minimize the value of $n$ in the end. Soon, Chouti found the game trivial. Can you also beat the game? -----Input----- The input contains only one integer in the first line: $v$ ($1 \le v \le 10^9$), the initial value of $n$. -----Output----- Output a single integer, the minimum value of $n$ the player can get. -----Examples----- Input 8 Output 1 Input 1 Output 1 -----Note----- In the first example, the player can choose $x=3$ in the first turn, then $n$ becomes $5$. He can then choose $x=4$ in the second turn to get $n=1$ as the result. There are other ways to get this minimum. However, for example, he cannot choose $x=2$ in the first turn because $2$ is a divisor of $8$. In the second example, since $n=1$ initially, the player can do nothing.
interview
[{"code": "n=int(input())\nif n==2:\n print(2)\nelse:\n print(1)", "passed": true, "time": 1.68, "memory": 14484.0, "status": "done"}, {"code": "n = int(input())\nif n == 2:\n\tprint(2)\nelse:\n\tprint(1)", "passed": true, "time": 1.89, "memory": 14376.0, "status": "done"}, {"code": "n = int(input())\nprint(2 if n == 2 else 1)\n", "passed": true, "time": 0.15, "memory": 14272.0, "status": "done"}, {"code": "n = int(input())\nif n==2:print(2)\nelse:print(1)", "passed": true, "time": 0.15, "memory": 14492.0, "status": "done"}, {"code": "n = int(input())\nif n == 2:\n print(2)\nelse:\n print(1)", "passed": true, "time": 0.15, "memory": 14376.0, "status": "done"}, {"code": "n = int(input())\nif n == 2:\n print(2)\nelse:\n print(1)\n", "passed": true, "time": 0.15, "memory": 14296.0, "status": "done"}, {"code": "n = int(input())\n\nif n!=2:\n\tprint(1)\nelse:\n\tprint(2)", "passed": true, "time": 0.15, "memory": 14404.0, "status": "done"}, {"code": "n = int(input())\n\nif n != 2:\n print(1)\nelse:\n print(2)", "passed": true, "time": 1.68, "memory": 14428.0, "status": "done"}, {"code": "import sys\nfrom math import ceil, floor\n\ninput = sys.stdin.readline\n\nn = int(input())\n\nif (n == 2):\n print(2)\nelse:\n print(1)", "passed": true, "time": 0.14, "memory": 14260.0, "status": "done"}, {"code": "n = int(input())\n\nif n == 2:\n print(2)\nelse:\n print(1)\n", "passed": true, "time": 0.14, "memory": 14480.0, "status": "done"}, {"code": "n = int(input())\nprint(2 if n == 2 else 1)", "passed": true, "time": 0.25, "memory": 14264.0, "status": "done"}, {"code": "n=int(input())\nif (n==2):\n\tprint (2)\nelse:\n\tprint (1)", "passed": true, "time": 0.15, "memory": 14412.0, "status": "done"}, {"code": "n = int(input())\nif n == 2:\n print(2)\nelse:\n print(1)", "passed": true, "time": 0.14, "memory": 14364.0, "status": "done"}, {"code": "n = int(input())\n\nif n == 2:\n\tprint(2)\nelse:\n\tprint(1)", "passed": true, "time": 0.2, "memory": 14240.0, "status": "done"}, {"code": "v = int(input())\n\nif v in [2]:\n\tprint(\"2\")\nelse:\n\tprint(\"1\")", "passed": true, "time": 0.25, "memory": 14212.0, "status": "done"}, {"code": "v = int(input())\nif v == 2: print(v)\nelse:print(1)", "passed": true, "time": 0.14, "memory": 14240.0, "status": "done"}, {"code": "n = int(input())\nif n == 2:\n print(2)\nelse:\n print(1)", "passed": true, "time": 0.14, "memory": 14236.0, "status": "done"}, {"code": "n = int(input())\nif n == 2:\n print(2)\nelse:\n print(1)", "passed": true, "time": 0.14, "memory": 14292.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=int(input())\nif(t==2):\n print(2)\nelse:\n print(1)\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": 14304.0, "status": "done"}, {"code": "from sys import stdin\nn=int(stdin.readline().strip())\nif n!=2:\n print(1)\nelse:\n print(2)\n", "passed": true, "time": 0.15, "memory": 14228.0, "status": "done"}, {"code": "n = int(input())\nif n == 2:\n print(2)\nelse:\n print(1)", "passed": true, "time": 0.14, "memory": 14276.0, "status": "done"}, {"code": "def mi():\n\treturn list(map(int, input().split()))\n'''\n8\n'''\nn = int(input())\nif n<=2:\n\tprint (n)\nelse:\n\tprint(1)\n", "passed": true, "time": 0.15, "memory": 14328.0, "status": "done"}, {"code": "n = int(input())\nif n == 2:\n print(2)\nelse:\n print(1)\n", "passed": true, "time": 0.14, "memory": 14240.0, "status": "done"}, {"code": "if int(input()) == 2:\n print(2)\nelse:\n print(1)", "passed": true, "time": 0.14, "memory": 14396.0, "status": "done"}]
[{"input": "8\n", "output": "1\n"}, {"input": "1\n", "output": "1\n"}, {"input": "4\n", "output": "1\n"}, {"input": "3\n", "output": "1\n"}, {"input": "158260522\n", "output": "1\n"}, {"input": "2\n", "output": "2\n"}, {"input": "1000000000\n", "output": "1\n"}, {"input": "5\n", "output": "1\n"}, {"input": "7\n", "output": "1\n"}, {"input": "9\n", "output": "1\n"}, {"input": "10\n", "output": "1\n"}, {"input": "11\n", "output": "1\n"}, {"input": "12\n", "output": "1\n"}, {"input": "13\n", "output": "1\n"}, {"input": "641009859\n", "output": "1\n"}, {"input": "802593587\n", "output": "1\n"}, {"input": "819819\n", "output": "1\n"}, {"input": "524125987\n", "output": "1\n"}, {"input": "959461493\n", "output": "1\n"}, {"input": "33313246\n", "output": "1\n"}, {"input": "702209411\n", "output": "1\n"}, {"input": "496813081\n", "output": "1\n"}, {"input": "387883951\n", "output": "1\n"}, {"input": "585325539\n", "output": "1\n"}, {"input": "29599937\n", "output": "1\n"}, {"input": "61142510\n", "output": "1\n"}, {"input": "58376259\n", "output": "1\n"}, {"input": "865222469\n", "output": "1\n"}, {"input": "98120883\n", "output": "1\n"}, {"input": "941492387\n", "output": "1\n"}, {"input": "585501313\n", "output": "1\n"}, {"input": "194574601\n", "output": "1\n"}, {"input": "824608515\n", "output": "1\n"}, {"input": "940751563\n", "output": "1\n"}, {"input": "85054\n", "output": "1\n"}, {"input": "2691939\n", "output": "1\n"}, {"input": "539624191\n", "output": "1\n"}, {"input": "896685075\n", "output": "1\n"}, {"input": "802030518\n", "output": "1\n"}, {"input": "640274071\n", "output": "1\n"}, {"input": "577533\n", "output": "1\n"}, {"input": "685146646\n", "output": "1\n"}, {"input": "661597501\n", "output": "1\n"}, {"input": "5920039\n", "output": "1\n"}, {"input": "6\n", "output": "1\n"}, {"input": "7\n", "output": "1\n"}, {"input": "83\n", "output": "1\n"}, {"input": "9\n", "output": "1\n"}, {"input": "999999999\n", "output": "1\n"}, {"input": "22\n", "output": "1\n"}, {"input": "11111\n", "output": "1\n"}, {"input": "666\n", "output": "1\n"}, {"input": "10000000\n", "output": "1\n"}, {"input": "11\n", "output": "1\n"}]